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