@dressed/react 1.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +37 -0
  2. package/dist/components/action-row.d.ts +7 -0
  3. package/dist/components/action-row.jsx +11 -0
  4. package/dist/components/action-row.jsx.map +1 -0
  5. package/dist/components/button.d.ts +9 -0
  6. package/dist/components/button.jsx +8 -0
  7. package/dist/components/button.jsx.map +1 -0
  8. package/dist/components/container.d.ts +9 -0
  9. package/dist/components/container.jsx +11 -0
  10. package/dist/components/container.jsx.map +1 -0
  11. package/dist/components/file.d.ts +6 -0
  12. package/dist/components/file.jsx +7 -0
  13. package/dist/components/file.jsx.map +1 -0
  14. package/dist/components/media-gallery.d.ts +13 -0
  15. package/dist/components/media-gallery.jsx +14 -0
  16. package/dist/components/media-gallery.jsx.map +1 -0
  17. package/dist/components/section.d.ts +10 -0
  18. package/dist/components/section.jsx +21 -0
  19. package/dist/components/section.jsx.map +1 -0
  20. package/dist/components/select-menu.d.ts +25 -0
  21. package/dist/components/select-menu.jsx +19 -0
  22. package/dist/components/select-menu.jsx.map +1 -0
  23. package/dist/components/separator.d.ts +6 -0
  24. package/dist/components/separator.jsx +7 -0
  25. package/dist/components/separator.jsx.map +1 -0
  26. package/dist/components/text-display.d.ts +7 -0
  27. package/dist/components/text-display.jsx +10 -0
  28. package/dist/components/text-display.jsx.map +1 -0
  29. package/dist/components/text-input.d.ts +6 -0
  30. package/dist/components/text-input.jsx +7 -0
  31. package/dist/components/text-input.jsx.map +1 -0
  32. package/dist/components/thumbnail.d.ts +6 -0
  33. package/dist/components/thumbnail.jsx +7 -0
  34. package/dist/components/thumbnail.jsx.map +1 -0
  35. package/dist/index.d.ts +52 -0
  36. package/dist/index.jsx +49 -0
  37. package/dist/index.jsx.map +1 -0
  38. package/dist/react/node.d.ts +7 -0
  39. package/dist/react/node.js +20 -0
  40. package/dist/react/node.js.map +1 -0
  41. package/dist/react/reconciler.d.ts +5 -0
  42. package/dist/react/reconciler.js +77 -0
  43. package/dist/react/reconciler.js.map +1 -0
  44. package/dist/react/renderer.d.ts +10 -0
  45. package/dist/react/renderer.js +61 -0
  46. package/dist/react/renderer.js.map +1 -0
  47. package/dist/react/text-node.d.ts +3 -0
  48. package/dist/react/text-node.js +12 -0
  49. package/dist/react/text-node.js.map +1 -0
  50. package/package.json +41 -0
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # @dressed/react
2
+
3
+ Create messages using React, patched interaction responses require ComponentsV2 and will not accept a content field.
4
+
5
+ If you manually call the render function yourself, you can use the old components.
6
+
7
+ ## 📦 Install
8
+
9
+ ```bash
10
+ bun add dressed react @dressed/react
11
+ ```
12
+
13
+ ## 🚀 Usage
14
+
15
+ ```tsx
16
+ // src/commands/ping.tsx
17
+ import type { CommandInteraction } from "dressed";
18
+ import { patchInteraction, ActionRow, Button } from "@dressed/react";
19
+
20
+ export default async function ping(interaction: CommandInteraction) {
21
+ const patched = patchInteraction(interaction);
22
+
23
+ await patched.reply(
24
+ <>
25
+ Pong!
26
+ <ActionRow>
27
+ <Button custom_id="new-pong" label="Again!" />
28
+ </ActionRow>
29
+ </>,
30
+ { ephemeral: true },
31
+ );
32
+ }
33
+ ```
34
+
35
+ > [!IMPORTANT]
36
+ > In order for Dressed to bundle your tsx/jsx files, the extension must be added to the build config's extensions array\
37
+ > e.g. `dressed build -E tsx,ts`
@@ -0,0 +1,7 @@
1
+ import { type ReactElement } from "react";
2
+ import type { APIActionRowComponent, APIComponentInActionRow } from "discord-api-types/v10";
3
+ import { type ComponentNode } from "../react/renderer.ts";
4
+ export declare function ActionRow({ children, }: {
5
+ children: ReactElement<APIActionRowComponent<APIComponentInActionRow>>;
6
+ }): ReactElement<APIActionRowComponent<APIComponentInActionRow>>;
7
+ export declare function parseActionRow<T extends APIActionRowComponent<APIComponentInActionRow>>(props: T, children: ComponentNode[]): Promise<T>;
@@ -0,0 +1,11 @@
1
+ import { ActionRow as DressedComponent } from "dressed";
2
+ import { createElement } from "react";
3
+ import { renderNode } from "../react/renderer.js";
4
+ export function ActionRow({ children, }) {
5
+ const props = DressedComponent();
6
+ return createElement("dressed-node", props, children);
7
+ }
8
+ export async function parseActionRow(props, children) {
9
+ return { ...props, components: await Promise.all(children.map(renderNode)) };
10
+ }
11
+ //# sourceMappingURL=action-row.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-row.jsx","sourceRoot":"","sources":["../../src/components/action-row.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,aAAa,EAAqB,MAAM,OAAO,CAAC;AAKzD,OAAO,EAAE,UAAU,EAAsB,MAAM,sBAAsB,CAAC;AAEtE,MAAM,UAAU,SAAS,CAAC,EACxB,QAAQ,GAGT;IACC,MAAM,KAAK,GAAG,gBAAgB,EAAE,CAAC;IACjC,OAAO,aAAa,CAAC,cAAc,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAElC,KAAQ,EAAE,QAAyB;IACnC,OAAO,EAAE,GAAG,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { type ReactElement } from "react";
2
+ import { type APIButtonComponentWithCustomId, type APIButtonComponentWithSKUId, type APIButtonComponentWithURL, ButtonStyle } from "discord-api-types/v10";
3
+ interface ButtonWithCustomId extends Omit<APIButtonComponentWithCustomId, "type" | "style"> {
4
+ style?: Exclude<keyof typeof ButtonStyle, "Link" | "Premium">;
5
+ }
6
+ export declare function Button(props: ButtonWithCustomId): ReactElement<APIButtonComponentWithCustomId>;
7
+ export declare function Button(props: Omit<APIButtonComponentWithSKUId, "type" | "style">): ReactElement<APIButtonComponentWithSKUId>;
8
+ export declare function Button(props: Omit<APIButtonComponentWithURL, "type" | "style">): ReactElement<APIButtonComponentWithURL>;
9
+ export {};
@@ -0,0 +1,8 @@
1
+ import { Button as DressedComponent } from "dressed";
2
+ import { createElement } from "react";
3
+ import { ButtonStyle, } from "discord-api-types/v10";
4
+ export function Button(props) {
5
+ const component = DressedComponent(props);
6
+ return createElement("dressed-node", component);
7
+ }
8
+ //# sourceMappingURL=button.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"button.jsx","sourceRoot":"","sources":["../../src/components/button.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,aAAa,EAAqB,MAAM,OAAO,CAAC;AACzD,OAAO,EAKL,WAAW,GACZ,MAAM,uBAAuB,CAAC;AAiB/B,MAAM,UAAU,MAAM,CACpB,KAGqD;IAErD,MAAM,SAAS,GAAG,gBAAgB,CAAC,KAAc,CAAC,CAAC;IACnD,OAAO,aAAa,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { APIContainerComponent } from "discord-api-types/v10";
2
+ import { type ReactNode } from "react";
3
+ import { type ComponentNode } from "../react/renderer.ts";
4
+ type ContainerProps = Omit<APIContainerComponent, "components" | "type"> & {
5
+ children: ReactNode;
6
+ };
7
+ export declare function Container({ children, ...rest }: ContainerProps): import("react").ReactElement<APIContainerComponent, string | import("react").JSXElementConstructor<any>>;
8
+ export declare function parseContainer<T extends APIContainerComponent>(props: T, children: ComponentNode[]): Promise<T>;
9
+ export {};
@@ -0,0 +1,11 @@
1
+ import { Container as DressedComponent } from "dressed";
2
+ import { createElement } from "react";
3
+ import { renderNode } from "../react/renderer.js";
4
+ export function Container({ children, ...rest }) {
5
+ const props = DressedComponent([], rest);
6
+ return createElement("dressed-node", props, children);
7
+ }
8
+ export async function parseContainer(props, children) {
9
+ return { ...props, components: await Promise.all(children.map(renderNode)) };
10
+ }
11
+ //# sourceMappingURL=container.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"container.jsx","sourceRoot":"","sources":["../../src/components/container.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,IAAI,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,aAAa,EAAkB,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,UAAU,EAAsB,MAAM,sBAAsB,CAAC;AAMtE,MAAM,UAAU,SAAS,CAAC,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAkB;IAC7D,MAAM,KAAK,GAAG,gBAAgB,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACzC,OAAO,aAAa,CAAC,cAAc,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,KAAQ,EACR,QAAyB;IAEzB,OAAO,EAAE,GAAG,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { APIFileComponent } from "discord-api-types/v10";
2
+ type FileProps = Omit<APIFileComponent, "file" | "type"> & {
3
+ file: APIFileComponent["file"] | string;
4
+ };
5
+ export declare function File({ file, ...rest }: FileProps): import("react").ReactElement<APIFileComponent, string | import("react").JSXElementConstructor<any>>;
6
+ export {};
@@ -0,0 +1,7 @@
1
+ import { File as DressedComponent } from "dressed";
2
+ import { createElement } from "react";
3
+ export function File({ file, ...rest }) {
4
+ const props = DressedComponent(file, rest);
5
+ return createElement("dressed-node", props);
6
+ }
7
+ //# sourceMappingURL=file.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.jsx","sourceRoot":"","sources":["../../src/components/file.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,IAAI,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAMtC,MAAM,UAAU,IAAI,CAAC,EAAE,IAAI,EAAE,GAAG,IAAI,EAAa;IAC/C,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC3C,OAAO,aAAa,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { APIMediaGalleryItem, APIMediaGalleryComponent } from "discord-api-types/v10";
2
+ import { type ReactNode } from "react";
3
+ import type { Node } from "../react/node.ts";
4
+ type MediaGalleryProps = Omit<APIMediaGalleryComponent, "items" | "type"> & {
5
+ children: ReactNode;
6
+ };
7
+ type ItemProps = Omit<APIMediaGalleryItem, "media" | "type"> & {
8
+ media: APIMediaGalleryItem["media"] | string;
9
+ };
10
+ export declare function MediaGallery({ children, ...rest }: MediaGalleryProps): import("react").ReactElement<APIMediaGalleryComponent, string | import("react").JSXElementConstructor<any>>;
11
+ export declare function MediaGalleryItem({ media, ...rest }: ItemProps): import("react").ReactElement<APIMediaGalleryItem, string | import("react").JSXElementConstructor<any>>;
12
+ export declare function parseMediaGallery<T extends APIMediaGalleryComponent>(props: T, children: Node<APIMediaGalleryItem>[]): T;
13
+ export {};
@@ -0,0 +1,14 @@
1
+ import { MediaGallery as DressedComponent, MediaGalleryItem as DressedItem, } from "dressed";
2
+ import { createElement } from "react";
3
+ export function MediaGallery({ children, ...rest }) {
4
+ const props = DressedComponent([], rest);
5
+ return createElement("dressed-node", props, children);
6
+ }
7
+ export function MediaGalleryItem({ media, ...rest }) {
8
+ const props = DressedItem(media, rest);
9
+ return createElement("dressed-node", props);
10
+ }
11
+ export function parseMediaGallery(props, children) {
12
+ return { ...props, items: children.map((c) => c.props) };
13
+ }
14
+ //# sourceMappingURL=media-gallery.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media-gallery.jsx","sourceRoot":"","sources":["../../src/components/media-gallery.tsx"],"names":[],"mappings":"AAIA,OAAO,EACL,YAAY,IAAI,gBAAgB,EAChC,gBAAgB,IAAI,WAAW,GAChC,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,aAAa,EAAkB,MAAM,OAAO,CAAC;AAStD,MAAM,UAAU,YAAY,CAAC,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAqB;IACnE,MAAM,KAAK,GAAG,gBAAgB,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACzC,OAAO,aAAa,CAAC,cAAc,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,EAAE,KAAK,EAAE,GAAG,IAAI,EAAa;IAC5D,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACvC,OAAO,aAAa,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,KAAQ,EACR,QAAqC;IAErC,OAAO,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { APISectionComponent } from "discord-api-types/v10";
2
+ import { type ReactNode } from "react";
3
+ import { type ComponentNode } from "../react/renderer.ts";
4
+ type SectionProps = Omit<APISectionComponent, "accessory" | "components" | "type"> & {
5
+ children: ReactNode;
6
+ accessory: ReactNode;
7
+ };
8
+ export declare function Section({ children, accessory, ...rest }: SectionProps): import("react").ReactElement<APISectionComponent, string | import("react").JSXElementConstructor<any>>;
9
+ export declare function parseSection<T extends APISectionComponent>(props: T, children: ComponentNode[]): Promise<T>;
10
+ export {};
@@ -0,0 +1,21 @@
1
+ import { Section as DressedComponent } from "dressed";
2
+ import { createElement, isValidElement } from "react";
3
+ import { renderNode } from "../react/renderer.js";
4
+ import {} from "../react/node.js";
5
+ import { render } from "../index.jsx";
6
+ export function Section({ children, accessory, ...rest }) {
7
+ const props = DressedComponent([], accessory, rest);
8
+ return createElement("dressed-node", props, children);
9
+ }
10
+ export async function parseSection(props, children) {
11
+ let accessory = props.accessory;
12
+ if (isValidElement(accessory)) {
13
+ accessory = (await render(accessory)).components[0];
14
+ }
15
+ return {
16
+ ...props,
17
+ accessory,
18
+ components: await Promise.all(children.map(renderNode)),
19
+ };
20
+ }
21
+ //# sourceMappingURL=section.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"section.jsx","sourceRoot":"","sources":["../../src/components/section.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAkB,MAAM,OAAO,CAAC;AACtE,OAAO,EAAE,UAAU,EAAsB,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAa,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAUtC,MAAM,UAAU,OAAO,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,EAAgB;IACpE,MAAM,KAAK,GAAG,gBAAgB,CAAC,EAAE,EAAE,SAAkB,EAAE,IAAI,CAAC,CAAC;IAC7D,OAAO,aAAa,CAAC,cAAc,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,KAAQ,EACR,QAAyB;IAEzB,IAAI,SAAS,GAAuC,KAAK,CAAC,SAAkB,CAAC;IAE7E,IAAI,cAAc,CAAC,SAAS,CAAC,EAAE,CAAC;QAC9B,SAAS,GAAG,CAAC,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAU,CAAC;IAC/D,CAAC;IAED,OAAO;QACL,GAAG,KAAK;QACR,SAAS;QACT,UAAU,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;KACxD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { type APISelectMenuOption, type APISelectMenuComponent, ComponentType } from "discord-api-types/v10";
2
+ import { type ReactNode } from "react";
3
+ import type { Node } from "../react/node.ts";
4
+ type SelectType = {
5
+ Channel: 8;
6
+ Mentionable: 7;
7
+ Role: 6;
8
+ String: 3;
9
+ User: 5;
10
+ };
11
+ type SelectMap = {
12
+ [Key in keyof typeof ComponentType]: Extract<APISelectMenuComponent, {
13
+ type: (typeof ComponentType)[Key];
14
+ }>;
15
+ };
16
+ type MenuProps<K extends keyof SelectType> = Omit<SelectMap[`${K}Select`], "type" | "options"> & ({
17
+ children: ReactNode;
18
+ type: "String";
19
+ } | {
20
+ type: Exclude<K, "String">;
21
+ });
22
+ export declare function SelectMenu<K extends keyof SelectType>(props: MenuProps<K>): import("react").DOMElement<never, Element>;
23
+ export declare function SelectMenuOption(props: APISelectMenuOption): import("react").ReactElement<APISelectMenuOption, string | import("react").JSXElementConstructor<any>>;
24
+ export declare function parseSelectMenu<T extends APISelectMenuComponent>(props: T, children: Node<APISelectMenuOption>[]): T;
25
+ export {};
@@ -0,0 +1,19 @@
1
+ import { ComponentType, } from "discord-api-types/v10";
2
+ import { SelectMenu as DressedComponent, SelectMenuOption as DressedOption, } from "dressed";
3
+ import { createElement } from "react";
4
+ export function SelectMenu(props) {
5
+ const { children, ...rest } = props;
6
+ const component = DressedComponent(rest);
7
+ return createElement("dressed-node", component, children);
8
+ }
9
+ export function SelectMenuOption(props) {
10
+ const component = DressedOption(props.label, props.value, props);
11
+ return createElement("dressed-node", component);
12
+ }
13
+ export function parseSelectMenu(props, children) {
14
+ if (props.type === ComponentType.StringSelect) {
15
+ props.options = children.map((c) => c.props);
16
+ }
17
+ return props;
18
+ }
19
+ //# sourceMappingURL=select-menu.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select-menu.jsx","sourceRoot":"","sources":["../../src/components/select-menu.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,GACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,UAAU,IAAI,gBAAgB,EAC9B,gBAAgB,IAAI,aAAa,GAClC,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,aAAa,EAAkB,MAAM,OAAO,CAAC;AAwBtD,MAAM,UAAU,UAAU,CAA6B,KAAmB;IACxE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,KAAgC,CAAC;IAC/D,MAAM,SAAS,GAAG,gBAAgB,CAAC,IAAa,CAAC,CAAC;IAClD,OAAO,aAAa,CAClB,cAAc,EACd,SAAkB,EAClB,QAAqB,CACtB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAA0B;IACzD,MAAM,SAAS,GAAG,aAAa,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACjE,OAAO,aAAa,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,KAAQ,EACR,QAAqC;IAErC,IAAI,KAAK,CAAC,IAAI,KAAK,aAAa,CAAC,YAAY,EAAE,CAAC;QAC9C,KAAK,CAAC,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { APISeparatorComponent, SeparatorSpacingSize } from "discord-api-types/v10";
2
+ type SeparatorProps = Omit<APISeparatorComponent, "type" | "spacing"> & {
3
+ spacing?: keyof typeof SeparatorSpacingSize;
4
+ };
5
+ export declare function Separator(props: SeparatorProps): import("react").ReactElement<APISeparatorComponent, string | import("react").JSXElementConstructor<any>>;
6
+ export {};
@@ -0,0 +1,7 @@
1
+ import { Separator as DressedComponent } from "dressed";
2
+ import { createElement } from "react";
3
+ export function Separator(props) {
4
+ const component = DressedComponent(props);
5
+ return createElement("dressed-node", component);
6
+ }
7
+ //# sourceMappingURL=separator.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"separator.jsx","sourceRoot":"","sources":["../../src/components/separator.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,IAAI,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAMtC,MAAM,UAAU,SAAS,CAAC,KAAqB;IAC7C,MAAM,SAAS,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAC1C,OAAO,aAAa,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { APITextDisplayComponent } from "discord-api-types/v10";
2
+ type TextDisplayProps = Omit<APITextDisplayComponent, "content" | "type"> & {
3
+ children: string;
4
+ };
5
+ export declare function TextDisplay({ children, ...rest }: TextDisplayProps): import("react").ReactElement<APITextDisplayComponent, string | import("react").JSXElementConstructor<any>>;
6
+ export declare function parseTextDisplay<T extends APITextDisplayComponent>(props: T, children: string): T;
7
+ export {};
@@ -0,0 +1,10 @@
1
+ import { TextDisplay as DressedComponent } from "dressed";
2
+ import { createElement } from "react";
3
+ export function TextDisplay({ children, ...rest }) {
4
+ const props = DressedComponent("", rest);
5
+ return createElement("dressed-node", props, children);
6
+ }
7
+ export function parseTextDisplay(props, children) {
8
+ return { ...props, content: children };
9
+ }
10
+ //# sourceMappingURL=text-display.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-display.jsx","sourceRoot":"","sources":["../../src/components/text-display.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,IAAI,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAMtC,MAAM,UAAU,WAAW,CAAC,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAoB;IACjE,MAAM,KAAK,GAAG,gBAAgB,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACzC,OAAO,aAAa,CAAC,cAAc,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,KAAQ,EACR,QAAgB;IAEhB,OAAO,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AACzC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { APITextInputComponent, TextInputStyle } from "discord-api-types/v10";
2
+ type TextInputProps = Omit<APITextInputComponent, "type" | "style"> & {
3
+ style?: keyof typeof TextInputStyle;
4
+ };
5
+ export declare function TextInput(props: TextInputProps): import("react").ReactElement<APITextInputComponent, string | import("react").JSXElementConstructor<any>>;
6
+ export {};
@@ -0,0 +1,7 @@
1
+ import { TextInput as DressedComponent } from "dressed";
2
+ import { createElement } from "react";
3
+ export function TextInput(props) {
4
+ const component = DressedComponent(props);
5
+ return createElement("dressed-node", component);
6
+ }
7
+ //# sourceMappingURL=text-input.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-input.jsx","sourceRoot":"","sources":["../../src/components/text-input.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,IAAI,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAMtC,MAAM,UAAU,SAAS,CAAC,KAAqB;IAC7C,MAAM,SAAS,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAC1C,OAAO,aAAa,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { APIThumbnailComponent } from "discord-api-types/v10";
2
+ type ThumbnailProps = Omit<APIThumbnailComponent, "media" | "type"> & {
3
+ media: APIThumbnailComponent["media"] | string;
4
+ };
5
+ export declare function Thumbnail({ media, ...rest }: ThumbnailProps): import("react").ReactElement<APIThumbnailComponent, string | import("react").JSXElementConstructor<any>>;
6
+ export {};
@@ -0,0 +1,7 @@
1
+ import { Thumbnail as DressedComponent } from "dressed";
2
+ import { createElement } from "react";
3
+ export function Thumbnail({ media, ...rest }) {
4
+ const props = DressedComponent(media, rest);
5
+ return createElement("dressed-node", props);
6
+ }
7
+ //# sourceMappingURL=thumbnail.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thumbnail.jsx","sourceRoot":"","sources":["../../src/components/thumbnail.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,IAAI,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAMtC,MAAM,UAAU,SAAS,CAAC,EAAE,KAAK,EAAE,GAAG,IAAI,EAAkB;IAC1D,MAAM,KAAK,GAAG,gBAAgB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC5C,OAAO,aAAa,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,52 @@
1
+ import type { ReactNode } from "react";
2
+ import { type APIInteractionResponseCallbackData } from "discord-api-types/v10";
3
+ import { createInteraction, type RawFile } from "dressed/server";
4
+ type ReplyProps = [
5
+ components: ReactNode,
6
+ data?: Omit<APIInteractionResponseCallbackData, "content"> & {
7
+ /** Whether the message is ephemeral */
8
+ ephemeral?: boolean;
9
+ /** The files to send with the message */
10
+ files?: RawFile[];
11
+ /** Whether to return the source message with the response */
12
+ with_response?: boolean;
13
+ }
14
+ ];
15
+ type EditReplyProps = [
16
+ components: ReactNode,
17
+ data?: Omit<APIInteractionResponseCallbackData, "content"> & {
18
+ /** The files to send with the message */
19
+ files?: RawFile[];
20
+ }
21
+ ];
22
+ type FollowUpProps = [
23
+ components: ReactNode,
24
+ data?: Omit<APIInteractionResponseCallbackData, "content"> & {
25
+ /** The files to send with the message */
26
+ files?: RawFile[];
27
+ /** Whether the message is ephemeral */
28
+ ephemeral?: boolean;
29
+ }
30
+ ];
31
+ type ReactivatedInteraction<T extends NonNullable<ReturnType<typeof createInteraction>>> = OverrideMethodParams<T, {
32
+ reply: ReplyProps;
33
+ editReply: EditReplyProps;
34
+ update: EditReplyProps;
35
+ followUp: FollowUpProps;
36
+ }>;
37
+ type OverrideMethodParams<T, Overrides extends Record<string, unknown[]>> = {
38
+ [K in keyof T]: K extends keyof Overrides ? T[K] extends (...args: any) => any ? (...args: Overrides[K]) => ReturnType<T[K]> : T[K] : T[K];
39
+ };
40
+ export declare function render(component: ReactNode): Promise<import("./react/renderer.ts").Renderer>;
41
+ export declare function patchInteraction<T extends NonNullable<ReturnType<typeof createInteraction>>>(interaction: T): ReactivatedInteraction<T>;
42
+ export * from "./components/action-row.tsx";
43
+ export * from "./components/button.tsx";
44
+ export * from "./components/container.tsx";
45
+ export * from "./components/file.tsx";
46
+ export * from "./components/media-gallery.tsx";
47
+ export * from "./components/section.tsx";
48
+ export * from "./components/select-menu.tsx";
49
+ export * from "./components/separator.tsx";
50
+ export * from "./components/text-display.tsx";
51
+ export * from "./components/text-input.tsx";
52
+ export * from "./components/thumbnail.tsx";
package/dist/index.jsx ADDED
@@ -0,0 +1,49 @@
1
+ import { MessageFlags, } from "discord-api-types/v10";
2
+ import { createRenderer } from "./react/renderer.js";
3
+ import { reconciler } from "./react/reconciler.js";
4
+ import { createInteraction } from "dressed/server";
5
+ export async function render(component) {
6
+ const container = createRenderer();
7
+ const root = reconciler.createContainer(container, 0, null, false, null, "dressed", (error) => console.error(error), null);
8
+ if (root !== null) {
9
+ await new Promise((r) => reconciler.updateContainer(component, root, null, r));
10
+ await container.render();
11
+ }
12
+ return container;
13
+ }
14
+ export function patchInteraction(interaction) {
15
+ if (!interaction)
16
+ throw new Error("No interaction");
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ const newInteraction = interaction;
19
+ for (const method of [
20
+ "reply",
21
+ "editReply",
22
+ "update",
23
+ "followUp",
24
+ ]) {
25
+ if (!(method in interaction))
26
+ continue;
27
+ const original = interaction[method];
28
+ newInteraction[method] = async (components, data = {}) => {
29
+ var _a;
30
+ const flags = ((_a = data.flags) !== null && _a !== void 0 ? _a : 0) | MessageFlags.IsComponentsV2;
31
+ data.flags = flags;
32
+ data.components = (await render(components)).components;
33
+ return original(data);
34
+ };
35
+ }
36
+ return newInteraction;
37
+ }
38
+ export * from "./components/action-row.jsx";
39
+ export * from "./components/button.jsx";
40
+ export * from "./components/container.jsx";
41
+ export * from "./components/file.jsx";
42
+ export * from "./components/media-gallery.jsx";
43
+ export * from "./components/section.jsx";
44
+ export * from "./components/select-menu.jsx";
45
+ export * from "./components/separator.jsx";
46
+ export * from "./components/text-display.jsx";
47
+ export * from "./components/text-input.jsx";
48
+ export * from "./components/thumbnail.jsx";
49
+ //# sourceMappingURL=index.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.jsx","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,GAEb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAgB,MAAM,gBAAgB,CAAC;AAmDjE,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,SAAoB;IAC/C,MAAM,SAAS,GAAG,cAAc,EAAE,CAAC;IACnC,MAAM,IAAI,GAAG,UAAU,CAAC,eAAe,CACrC,SAAS,EACT,CAAC,EACD,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,SAAS,EACT,CAAC,KAAY,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,EACtC,IAAI,CACL,CAAC;IAEF,IAAI,IAAI,KAA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,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC"}
@@ -0,0 +1,7 @@
1
+ export interface Node<Props, Children = unknown> {
2
+ props: Props;
3
+ children: Node<Children>[];
4
+ text: () => string;
5
+ }
6
+ export declare function createNode<Props>(props: Props): Node<Props>;
7
+ export declare function isNode(obj: unknown): obj is Node<unknown>;
@@ -0,0 +1,20 @@
1
+ export function createNode(props) {
2
+ const children = [];
3
+ function text() {
4
+ return children.map((c) => c.text()).join("");
5
+ }
6
+ return {
7
+ props,
8
+ children,
9
+ text,
10
+ };
11
+ }
12
+ export function isNode(obj) {
13
+ return (obj !== null &&
14
+ typeof obj === "object" &&
15
+ "props" in obj &&
16
+ "children" in obj &&
17
+ "text" in obj &&
18
+ typeof obj.text === "function");
19
+ }
20
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/react/node.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,UAAU,CAAQ,KAAY;IAC5C,MAAM,QAAQ,GAAoB,EAAE,CAAC;IAErC,SAAS,IAAI;QACX,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAChD,CAAC;IAED,OAAO;QACL,KAAK;QACL,QAAQ;QACR,IAAI;KACL,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,GAAY;IACjC,OAAO,CACL,GAAG,KAAK,IAAI;QACZ,OAAO,GAAG,KAAK,QAAQ;QACvB,OAAO,IAAI,GAAG;QACd,UAAU,IAAI,GAAG;QACjB,MAAM,IAAI,GAAG;QACb,OAAO,GAAG,CAAC,IAAI,KAAK,UAAU,CAC/B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ import ReactReconciler from "react-reconciler";
2
+ import { type Node } from "./node.ts";
3
+ import type { Renderer } from "./renderer.ts";
4
+ import { type TextNode } from "./text-node.ts";
5
+ export declare const reconciler: ReactReconciler.Reconciler<Renderer, Node<unknown, unknown>, TextNode, never, never, never>;
@@ -0,0 +1,77 @@
1
+ import ReactReconciler, {} from "react-reconciler";
2
+ import { DefaultEventPriority, NoEventPriority, } from "react-reconciler/constants.js";
3
+ import { createNode, isNode } from "./node.js";
4
+ import { createTextNode } from "./text-node.js";
5
+ import { createContext } from "react";
6
+ let currentUpdatePriority = NoEventPriority;
7
+ const config = {
8
+ supportsMutation: true,
9
+ supportsPersistence: false,
10
+ supportsHydration: false,
11
+ isPrimaryRenderer: true,
12
+ scheduleTimeout: globalThis.setTimeout,
13
+ cancelTimeout: globalThis.clearTimeout,
14
+ noTimeout: -1,
15
+ getRootHostContext: () => true,
16
+ getChildHostContext: () => true,
17
+ createInstance: (type, props) => {
18
+ if (type !== "dressed-node") {
19
+ throw new Error(`Unknown node type: ${type}`);
20
+ }
21
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
22
+ const { children, ...rest } = props;
23
+ const node = createNode(rest);
24
+ if (!isNode(node)) {
25
+ throw new Error(`createNode function did not return a Node`);
26
+ }
27
+ return node;
28
+ },
29
+ createTextInstance: (text) => createTextNode(text),
30
+ shouldSetTextContent: () => false,
31
+ detachDeletedInstance: () => { },
32
+ beforeActiveInstanceBlur: () => { },
33
+ afterActiveInstanceBlur: () => { },
34
+ getInstanceFromNode: () => null,
35
+ getInstanceFromScope: () => null,
36
+ clearContainer: (renderer) => {
37
+ renderer.nodes.length = 0;
38
+ },
39
+ appendChildToContainer: (renderer, child) => {
40
+ renderer.nodes.push(child);
41
+ },
42
+ appendInitialChild: (parent, child) => {
43
+ parent.children.push(child);
44
+ },
45
+ prepareForCommit: () => null,
46
+ resetAfterCommit: () => null,
47
+ prepareScopeUpdate: () => { },
48
+ preparePortalMount: () => {
49
+ throw new Error("Portals are not supported");
50
+ },
51
+ getPublicInstance: () => {
52
+ throw new Error("Refs are currently not supported");
53
+ },
54
+ finalizeInitialChildren: () => false,
55
+ setCurrentUpdatePriority: (newPriority) => {
56
+ currentUpdatePriority = newPriority;
57
+ },
58
+ getCurrentUpdatePriority: () => currentUpdatePriority,
59
+ resolveUpdatePriority: () => currentUpdatePriority !== NoEventPriority
60
+ ? currentUpdatePriority
61
+ : DefaultEventPriority,
62
+ maySuspendCommit: () => false,
63
+ NotPendingTransition: null,
64
+ HostTransitionContext: createContext(null),
65
+ resetFormInstance: () => { },
66
+ requestPostPaintCallback: () => { },
67
+ shouldAttemptEagerTransition: () => false,
68
+ trackSchedulerEvent: () => { },
69
+ resolveEventType: () => null,
70
+ resolveEventTimeStamp: () => -1,
71
+ preloadInstance: () => false,
72
+ startSuspendingCommit: () => { },
73
+ suspendInstance: () => { },
74
+ waitForCommitToBeReady: () => null,
75
+ };
76
+ export const reconciler = ReactReconciler(config);
77
+ //# sourceMappingURL=reconciler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reconciler.js","sourceRoot":"","sources":["../../src/react/reconciler.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,EAAE,EAGvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,oBAAoB,EACpB,eAAe,GAChB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAa,MAAM,WAAW,CAAC;AAE1D,OAAO,EAAE,cAAc,EAAiB,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,IAAI,qBAAqB,GAAW,eAAe,CAAC;AAEpD,MAAM,MAAM,GAeR;IACF,gBAAgB,EAAE,IAAI;IACtB,mBAAmB,EAAE,KAAK;IAC1B,iBAAiB,EAAE,KAAK;IACxB,iBAAiB,EAAE,IAAI;IACvB,eAAe,EAAE,UAAU,CAAC,UAAU;IACtC,aAAa,EAAE,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AAC;IACzB,sBAAsB,EAAE,GAAG,EAAE,CAAC,IAAI;CACnC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { Node } from "./node.ts";
2
+ import { type APIMessageComponent, type APIModalComponent } from "discord-api-types/v10";
3
+ export interface Renderer {
4
+ nodes: Node<unknown>[];
5
+ render: () => Promise<void>;
6
+ components: (APIMessageComponent | APIModalComponent)[];
7
+ }
8
+ export type ComponentNode = Node<APIMessageComponent | APIModalComponent, APIMessageComponent | APIModalComponent>;
9
+ export declare function createRenderer(): Renderer;
10
+ export declare function renderNode(node: ComponentNode): Promise<APIMessageComponent | APIModalComponent>;
@@ -0,0 +1,61 @@
1
+ import { ComponentType, } from "discord-api-types/v10";
2
+ import { parseActionRow } from "../components/action-row.jsx";
3
+ import { parseContainer } from "../components/container.jsx";
4
+ import { TextDisplay } from "dressed";
5
+ import { parseTextDisplay } from "../components/text-display.jsx";
6
+ import { parseSelectMenu } from "../components/select-menu.jsx";
7
+ import { parseMediaGallery } from "../components/media-gallery.jsx";
8
+ import { parseSection } from "../components/section.jsx";
9
+ export function createRenderer() {
10
+ const components = [];
11
+ const nodes = [];
12
+ return {
13
+ nodes,
14
+ async render() {
15
+ for (const node of nodes) {
16
+ components.push(await renderNode(node));
17
+ }
18
+ },
19
+ components,
20
+ };
21
+ }
22
+ export async function renderNode(node) {
23
+ switch (node.props.type) {
24
+ case ComponentType.ActionRow: {
25
+ return parseActionRow(node.props, node.children);
26
+ }
27
+ case ComponentType.Button:
28
+ case ComponentType.TextInput:
29
+ case ComponentType.Thumbnail:
30
+ case ComponentType.File:
31
+ case ComponentType.Separator: {
32
+ return node.props;
33
+ }
34
+ case ComponentType.StringSelect:
35
+ case ComponentType.UserSelect:
36
+ case ComponentType.RoleSelect:
37
+ case ComponentType.MentionableSelect:
38
+ case ComponentType.ChannelSelect: {
39
+ return parseSelectMenu(node.props, node.children);
40
+ }
41
+ case ComponentType.Section: {
42
+ return parseSection(node.props, node.children);
43
+ }
44
+ case ComponentType.TextDisplay: {
45
+ return parseTextDisplay(node.props, node.text());
46
+ }
47
+ case ComponentType.MediaGallery: {
48
+ return parseMediaGallery(node.props, node.children);
49
+ }
50
+ case ComponentType.Container: {
51
+ return parseContainer(node.props, node.children);
52
+ }
53
+ default: {
54
+ if (typeof node.props === "string") {
55
+ return TextDisplay(node.text());
56
+ }
57
+ throw new Error("Unknown node");
58
+ }
59
+ }
60
+ }
61
+ //# sourceMappingURL=renderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderer.js","sourceRoot":"","sources":["../../src/react/renderer.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,aAAa,GACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAazD,MAAM,UAAU,cAAc;IAC5B,MAAM,UAAU,GAAgD,EAAE,CAAC;IACnE,MAAM,KAAK,GAAoD,EAAE,CAAC;IAElE,OAAO;QACL,KAAK;QACL,KAAK,CAAC,MAAM;YACV,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,UAAU,CAAC,IAAI,CAAC,MAAM,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;YAC1C,CAAC;QACH,CAAC;QACD,UAAU;KACX,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,IAAmB;IAEnB,QAAQ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K,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACnD,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACR,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;gBACnC,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;YAClC,CAAC;YAED,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type Node } from "./node.ts";
2
+ export type TextNode = Node<string>;
3
+ export declare function createTextNode(props: string): TextNode;
@@ -0,0 +1,12 @@
1
+ import { createNode } from "./node.js";
2
+ export function createTextNode(props) {
3
+ const node = createNode(props);
4
+ function text() {
5
+ return node.props;
6
+ }
7
+ return {
8
+ ...node,
9
+ text,
10
+ };
11
+ }
12
+ //# sourceMappingURL=text-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-node.js","sourceRoot":"","sources":["../../src/react/text-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,WAAW,CAAC;AAIlD,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,MAAM,IAAI,GAAG,UAAU,CAAS,KAAK,CAAC,CAAC;IAEvC,SAAS,IAAI;QACX,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,OAAO;QACL,GAAG,IAAI;QACP,IAAI;KACL,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@dressed/react",
3
+ "version": "1.0.0-rc.1",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/Inbestigator/dressed.git",
7
+ "directory": "packages/dressed-react"
8
+ },
9
+ "peerDependencies": {
10
+ "dressed": "^1.8.0-rc",
11
+ "react": "^19.1.0"
12
+ },
13
+ "exports": "./dist/index.js",
14
+ "description": "Render Dressed's components using React",
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "homepage": "https://dressed.vercel.app",
19
+ "keywords": [
20
+ "dressed",
21
+ "react",
22
+ "jsx",
23
+ "discord"
24
+ ],
25
+ "license": "MIT",
26
+ "scripts": {
27
+ "dist": "rm -fr dist && tsc",
28
+ "check-types": "tsc --noEmit",
29
+ "dry-publish": "bun publish --dry-run"
30
+ },
31
+ "type": "module",
32
+ "types": "./dist/index.d.ts",
33
+ "dependencies": {
34
+ "discord-api-types": "^0.38.10",
35
+ "react-reconciler": "^0.32.0"
36
+ },
37
+ "devDependencies": {
38
+ "@types/react": "^19.1.6",
39
+ "@types/react-reconciler": "^0.32.0"
40
+ }
41
+ }