flatten file structure
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import type { ReactNode } from "react"
|
import type { ReactNode } from "react"
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../internal/element.js"
|
||||||
import type { MessageOptions } from "../../internal/message"
|
import type { MessageOptions } from "../../internal/message"
|
||||||
import { Node } from "../../internal/node.js"
|
import { Node } from "../internal/node.js"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Props for an action row
|
* Props for an action row
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
import type { APIMessageComponentButtonInteraction } from "discord.js"
|
import type { APIMessageComponentButtonInteraction } from "discord.js"
|
||||||
import { randomUUID } from "node:crypto"
|
import { randomUUID } from "node:crypto"
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import type { ComponentEvent } from "../core/component-event.js"
|
||||||
import type { ComponentInteraction } from "../../internal/interaction"
|
import { ReacordElement } from "../internal/element.js"
|
||||||
import type { MessageOptions } from "../../internal/message"
|
import { Node } from "../node.js"
|
||||||
import { getNextActionRow } from "../../internal/message"
|
|
||||||
import { Node } from "../../internal/node.js"
|
|
||||||
import type { ComponentEvent } from "../component-event"
|
|
||||||
import type { ButtonSharedProps } from "./button-shared-props"
|
import type { ButtonSharedProps } from "./button-shared-props"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,31 +51,31 @@ export class ButtonNode extends Node<ButtonProps> {
|
|||||||
|
|
||||||
// this has text children, but buttons themselves shouldn't yield text
|
// this has text children, but buttons themselves shouldn't yield text
|
||||||
// eslint-disable-next-line class-methods-use-this
|
// eslint-disable-next-line class-methods-use-this
|
||||||
override get text() {
|
// override get text() {
|
||||||
return ""
|
// return ""
|
||||||
}
|
// }
|
||||||
|
|
||||||
override modifyMessageOptions(options: MessageOptions): void {
|
// override modifyMessageOptions(options: MessageOptions): void {
|
||||||
getNextActionRow(options).push({
|
// getNextActionRow(options).push({
|
||||||
type: "button",
|
// type: "button",
|
||||||
customId: this.customId,
|
// customId: this.customId,
|
||||||
style: this.props.style ?? "secondary",
|
// style: this.props.style ?? "secondary",
|
||||||
disabled: this.props.disabled,
|
// disabled: this.props.disabled,
|
||||||
emoji: this.props.emoji,
|
// emoji: this.props.emoji,
|
||||||
label: this.children.findType(ButtonLabelNode)?.text,
|
// label: this.children.findType(ButtonLabelNode)?.text,
|
||||||
})
|
// })
|
||||||
}
|
// }
|
||||||
|
|
||||||
override handleComponentInteraction(interaction: ComponentInteraction) {
|
// override handleComponentInteraction(interaction: ComponentInteraction) {
|
||||||
if (
|
// if (
|
||||||
interaction.type === "button" &&
|
// interaction.type === "button" &&
|
||||||
interaction.customId === this.customId
|
// interaction.customId === this.customId
|
||||||
) {
|
// ) {
|
||||||
this.props.onClick(interaction.event)
|
// this.props.onClick(interaction.event)
|
||||||
return true
|
// return true
|
||||||
}
|
// }
|
||||||
return false
|
// return false
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
class ButtonLabelNode extends Node<{}> {}
|
class ButtonLabelNode extends Node<{}> {}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { ReactNode } from "react"
|
import type { ReactNode } from "react"
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../internal/element.js"
|
||||||
import { Node } from "../../internal/node.js"
|
import { Node } from "../internal/node.js"
|
||||||
import { EmbedChildNode } from "./embed-child.js"
|
import { EmbedChildNode } from "./embed-child.js"
|
||||||
import type { EmbedOptions } from "./embed-options"
|
import type { EmbedOptions } from "./embed-options"
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Node } from "../../internal/node.js"
|
import { Node } from "../internal/node.js"
|
||||||
import type { EmbedOptions } from "./embed-options"
|
import type { EmbedOptions } from "./embed-options"
|
||||||
|
|
||||||
export abstract class EmbedChildNode<Props> extends Node<Props> {
|
export abstract class EmbedChildNode<Props> extends Node<Props> {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { ReactNode } from "react"
|
import type { ReactNode } from "react"
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../internal/element.js"
|
||||||
import { Node } from "../../internal/node.js"
|
import { Node } from "../internal/node.js"
|
||||||
import { EmbedChildNode } from "./embed-child.js"
|
import { EmbedChildNode } from "./embed-child.js"
|
||||||
import type { EmbedOptions } from "./embed-options"
|
import type { EmbedOptions } from "./embed-options"
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { ReactNode } from "react"
|
import type { ReactNode } from "react"
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../internal/element.js"
|
||||||
import { Node } from "../../internal/node.js"
|
import { Node } from "../internal/node.js"
|
||||||
import { EmbedChildNode } from "./embed-child.js"
|
import { EmbedChildNode } from "./embed-child.js"
|
||||||
import type { EmbedOptions } from "./embed-options"
|
import type { EmbedOptions } from "./embed-options"
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../internal/element.js"
|
||||||
import { EmbedChildNode } from "./embed-child.js"
|
import { EmbedChildNode } from "./embed-child.js"
|
||||||
import type { EmbedOptions } from "./embed-options"
|
import type { EmbedOptions } from "./embed-options"
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../internal/element.js"
|
||||||
import { EmbedChildNode } from "./embed-child.js"
|
import { EmbedChildNode } from "./embed-child.js"
|
||||||
import type { EmbedOptions } from "./embed-options"
|
import type { EmbedOptions } from "./embed-options"
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { ReactNode } from "react"
|
import type { ReactNode } from "react"
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../internal/element.js"
|
||||||
import { Node } from "../../internal/node.js"
|
import { Node } from "../internal/node.js"
|
||||||
import { EmbedChildNode } from "./embed-child.js"
|
import { EmbedChildNode } from "./embed-child.js"
|
||||||
import type { EmbedOptions } from "./embed-options"
|
import type { EmbedOptions } from "./embed-options"
|
||||||
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import { snakeCaseDeep } from "@reacord/helpers/convert-object-property-case.js"
|
import { snakeCaseDeep } from "@reacord/helpers/convert-object-property-case.js"
|
||||||
import { omit } from "@reacord/helpers/omit.js"
|
import { omit } from "@reacord/helpers/omit.js"
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
|
||||||
import type { MessageOptions } from "../../internal/message"
|
import type { MessageOptions } from "../../internal/message"
|
||||||
import { Node } from "../../internal/node.js"
|
import { ReacordElement } from "../internal/element.js"
|
||||||
import { TextNode } from "../../internal/text-node"
|
import { Node } from "../node.js"
|
||||||
|
import { TextNode } from "../text-node"
|
||||||
import { EmbedChildNode } from "./embed-child.js"
|
import { EmbedChildNode } from "./embed-child.js"
|
||||||
import type { EmbedOptions } from "./embed-options"
|
import type { EmbedOptions } from "./embed-options"
|
||||||
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../internal/element.js"
|
||||||
import type { MessageOptions } from "../../internal/message"
|
import type { MessageOptions } from "../../internal/message"
|
||||||
import { getNextActionRow } from "../../internal/message"
|
import { getNextActionRow } from "../internal/message"
|
||||||
import { Node } from "../../internal/node.js"
|
import { Node } from "../internal/node.js"
|
||||||
import type { ButtonSharedProps } from "./button-shared-props"
|
import type { ButtonSharedProps } from "./button-shared-props"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { MessageSelectOptionOptions } from "../../internal/message"
|
import type { MessageSelectOptionOptions } from "../../internal/message"
|
||||||
import { Node } from "../../internal/node"
|
import { Node } from "../node"
|
||||||
import type { OptionProps } from "./option"
|
import type { OptionProps } from "./option"
|
||||||
|
|
||||||
export class OptionNode extends Node<
|
export class OptionNode extends Node<
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { ReactNode } from "react"
|
import type { ReactNode } from "react"
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import { ReacordElement } from "../../internal/element"
|
import { ReacordElement } from "../internal/element"
|
||||||
import {
|
import {
|
||||||
OptionDescriptionNode,
|
OptionDescriptionNode,
|
||||||
OptionLabelNode,
|
OptionLabelNode,
|
||||||
@@ -3,14 +3,14 @@ import type { APIMessageComponentSelectMenuInteraction } from "discord.js"
|
|||||||
import { randomUUID } from "node:crypto"
|
import { randomUUID } from "node:crypto"
|
||||||
import type { ReactNode } from "react"
|
import type { ReactNode } from "react"
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../internal/element.js"
|
||||||
import type { ComponentInteraction } from "../../internal/interaction"
|
import type { ComponentInteraction } from "../../internal/interaction"
|
||||||
import type {
|
import type {
|
||||||
ActionRow,
|
ActionRow,
|
||||||
ActionRowItem,
|
ActionRowItem,
|
||||||
MessageOptions,
|
MessageOptions,
|
||||||
} from "../../internal/message"
|
} from "../../internal/message"
|
||||||
import { Node } from "../../internal/node.js"
|
import { Node } from "../internal/node.js"
|
||||||
import type { ComponentEvent } from "../component-event"
|
import type { ComponentEvent } from "../component-event"
|
||||||
import { OptionNode } from "./option-node"
|
import { OptionNode } from "./option-node"
|
||||||
|
|
||||||
@@ -1,33 +1,29 @@
|
|||||||
export class Node<Props = unknown> {
|
export class Node<Props = unknown> {
|
||||||
private readonly _children: Node[] = []
|
readonly children: Node[] = []
|
||||||
|
|
||||||
constructor(public props: Props) {}
|
constructor(public props: Props) {}
|
||||||
|
|
||||||
get children(): readonly Node[] {
|
|
||||||
return this._children
|
|
||||||
}
|
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
this._children.splice(0)
|
this.children.splice(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
add(...nodes: Node[]) {
|
add(...nodes: Node[]) {
|
||||||
this._children.push(...nodes)
|
this.children.push(...nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
remove(node: Node) {
|
remove(node: Node) {
|
||||||
const index = this._children.indexOf(node)
|
const index = this.children.indexOf(node)
|
||||||
if (index !== -1) this._children.splice(index, 1)
|
if (index !== -1) this.children.splice(index, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
insertBefore(node: Node, beforeNode: Node) {
|
insertBefore(node: Node, beforeNode: Node) {
|
||||||
const index = this._children.indexOf(beforeNode)
|
const index = this.children.indexOf(beforeNode)
|
||||||
if (index !== -1) this._children.splice(index, 0, node)
|
if (index !== -1) this.children.splice(index, 0, node)
|
||||||
}
|
}
|
||||||
|
|
||||||
replace(oldNode: Node, newNode: Node) {
|
replace(oldNode: Node, newNode: Node) {
|
||||||
const index = this._children.indexOf(oldNode)
|
const index = this.children.indexOf(oldNode)
|
||||||
if (index !== -1) this._children[index] = newNode
|
if (index !== -1) this.children[index] = newNode
|
||||||
}
|
}
|
||||||
|
|
||||||
clone(): this {
|
clone(): this {
|
||||||
@@ -4,12 +4,12 @@ import type {
|
|||||||
APIMessageComponentSelectMenuInteraction,
|
APIMessageComponentSelectMenuInteraction,
|
||||||
} from "discord.js"
|
} from "discord.js"
|
||||||
import { ComponentType } from "discord.js"
|
import { ComponentType } from "discord.js"
|
||||||
|
import { ButtonNode } from "./components/button.js"
|
||||||
|
import type { SelectChangeEvent } from "./components/select.js"
|
||||||
|
import { SelectNode } from "./components/select.js"
|
||||||
import type { ComponentEvent } from "./core/component-event.js"
|
import type { ComponentEvent } from "./core/component-event.js"
|
||||||
import { ButtonNode } from "./core/components/button.js"
|
|
||||||
import type { SelectChangeEvent } from "./core/components/select.js"
|
|
||||||
import { SelectNode } from "./core/components/select.js"
|
|
||||||
import { Node } from "./internal/node.js"
|
|
||||||
import { reconciler } from "./internal/reconciler.js"
|
import { reconciler } from "./internal/reconciler.js"
|
||||||
|
import { Node } from "./node.js"
|
||||||
import type { ReacordClient } from "./reacord-client.js"
|
import type { ReacordClient } from "./reacord-client.js"
|
||||||
import type { Renderer } from "./renderer.js"
|
import type { Renderer } from "./renderer.js"
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
import { raise } from "@reacord/helpers/raise.js"
|
import { raise } from "@reacord/helpers/raise.js"
|
||||||
import ReactReconciler from "react-reconciler"
|
import ReactReconciler from "react-reconciler"
|
||||||
import { DefaultEventPriority } from "react-reconciler/constants"
|
import { DefaultEventPriority } from "react-reconciler/constants"
|
||||||
import type { ReacordInstancePrivate } from "../reacord-instance.js"
|
|
||||||
import { Node } from "./node.js"
|
import { Node } from "./node.js"
|
||||||
|
import type { ReacordInstancePrivate } from "./reacord-instance.js"
|
||||||
import { TextNode } from "./text-node.js"
|
import { TextNode } from "./text-node.js"
|
||||||
|
|
||||||
export const reconciler = ReactReconciler<
|
export const reconciler = ReactReconciler<
|
||||||
Reference in New Issue
Block a user