@dressed/react 1.7.4-rc.5 → 1.7.4-rc.6
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.
- package/dist/components/button.d.ts +3 -1
- package/dist/components/button.js +2 -2
- package/dist/components/button.js.map +1 -1
- package/dist/components/select-menu.d.ts +4 -2
- package/dist/components/select-menu.js +2 -2
- package/dist/components/select-menu.js.map +1 -1
- package/dist/react/reconciler.js +2 -2
- package/dist/react/reconciler.js.map +1 -1
- package/dist/rendering/callbacks.d.ts +17 -0
- package/dist/rendering/callbacks.js +33 -0
- package/dist/rendering/callbacks.js.map +1 -0
- package/dist/rendering/index.d.ts +4 -1
- package/dist/rendering/index.js +1 -1
- package/dist/rendering/index.js.map +1 -1
- package/dist/rendering/interaction.d.ts +0 -10
- package/dist/rendering/interaction.js +7 -23
- package/dist/rendering/interaction.js.map +1 -1
- package/package.json +5 -2
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { APIButtonComponentWithCustomId, APIButtonComponentWithSKUId, APIButtonComponentWithURL, ButtonStyle } from "discord-api-types/v10";
|
|
2
2
|
import { type ReactElement } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import type { MessageComponentInteraction } from "../rendering/interaction.ts";
|
|
4
4
|
interface ButtonWithCustomId extends Omit<APIButtonComponentWithCustomId, "type" | "style"> {
|
|
5
5
|
style?: Exclude<keyof typeof ButtonStyle, "Link" | "Premium">;
|
|
6
6
|
}
|
|
7
7
|
interface ButtonWithOnClick extends Omit<ButtonWithCustomId, "custom_id"> {
|
|
8
8
|
/** Create a temporary handler callback, will not work in a serverless environment */
|
|
9
9
|
onClick: (interaction: MessageComponentInteraction<"Button">) => void;
|
|
10
|
+
/** An additional handler identity defined in the callback setup which will run if the `onClick` is no longer registered */
|
|
11
|
+
fallback?: string;
|
|
10
12
|
}
|
|
11
13
|
export declare function Button(props: ButtonWithCustomId): ReactElement<APIButtonComponentWithCustomId>;
|
|
12
14
|
export declare function Button(props: ButtonWithOnClick): ReactElement<APIButtonComponentWithCustomId>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Button as DressedComponent } from "dressed";
|
|
2
2
|
import { createElement } from "react";
|
|
3
|
-
import { registerHandler } from "../rendering/
|
|
3
|
+
import { registerHandler } from "../rendering/callbacks.js";
|
|
4
4
|
export function Button(props) {
|
|
5
5
|
const component = DressedComponent({
|
|
6
6
|
...props,
|
|
7
|
-
...("onClick" in props ? registerHandler(props.onClick) : {}),
|
|
7
|
+
...("onClick" in props ? registerHandler(props.onClick, props.fallback) : {}),
|
|
8
8
|
});
|
|
9
9
|
return createElement("dressed-node", component);
|
|
10
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button.js","sourceRoot":"","sources":["../../src/components/button.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,aAAa,EAAqB,MAAM,OAAO,CAAC;AACzD,OAAO,
|
|
1
|
+
{"version":3,"file":"button.js","sourceRoot":"","sources":["../../src/components/button.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,aAAa,EAAqB,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAuB5D,MAAM,UAAU,MAAM,CACpB,KAIqD;IAErD,MAAM,SAAS,GAAG,gBAAgB,CAAC;QACjC,GAAG,KAAK;QACR,GAAG,CAAC,SAAS,IAAI,KAAK,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,OAAgB,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KAC9E,CAAC,CAAC;IACZ,OAAO,aAAa,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type APISelectMenuComponent, type APISelectMenuOption, ComponentType } from "discord-api-types/v10";
|
|
2
2
|
import { type ReactElement, type ReactNode } from "react";
|
|
3
3
|
import type { Node } from "../react/node.ts";
|
|
4
|
-
import {
|
|
4
|
+
import type { MessageComponentInteraction } from "../rendering/interaction.ts";
|
|
5
5
|
type SelectType = "Channel" | "Mentionable" | "Role" | "String" | "User";
|
|
6
6
|
type SelectMap = {
|
|
7
7
|
[Key in keyof typeof ComponentType]: Extract<APISelectMenuComponent, {
|
|
@@ -15,7 +15,9 @@ type SelectMenuWithCustomId<K extends SelectType> = Omit<SelectMap[`${K}Select`]
|
|
|
15
15
|
} : object);
|
|
16
16
|
type SelectMenuWithOnClick<K extends SelectType> = Omit<SelectMenuWithCustomId<K>, "custom_id"> & {
|
|
17
17
|
/** Create a temporary handler callback, will not work in a serverless environment */
|
|
18
|
-
|
|
18
|
+
onSubmit: (interaction: MessageComponentInteraction<`${K}Select`>) => void;
|
|
19
|
+
/** An additional handler identity defined in the callback setup which will run if the `onSubmit` is no longer registered */
|
|
20
|
+
fallback?: string;
|
|
19
21
|
};
|
|
20
22
|
export declare function SelectMenu<K extends SelectType>(props: SelectMenuWithCustomId<K> & {
|
|
21
23
|
type: K;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ComponentType } from "discord-api-types/v10";
|
|
2
2
|
import { SelectMenu as DressedComponent, SelectMenuOption as DressedOption } from "dressed";
|
|
3
3
|
import { createElement } from "react";
|
|
4
|
-
import { registerHandler } from "../rendering/
|
|
4
|
+
import { registerHandler } from "../rendering/callbacks.js";
|
|
5
5
|
export function SelectMenu(props) {
|
|
6
6
|
const { children, ...rest } = props;
|
|
7
7
|
const component = DressedComponent({
|
|
8
8
|
...rest,
|
|
9
|
-
...("
|
|
9
|
+
...("onSubmit" in props ? registerHandler(props.onSubmit, props.fallback) : {}),
|
|
10
10
|
});
|
|
11
11
|
return createElement("dressed-node", component, children);
|
|
12
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-menu.js","sourceRoot":"","sources":["../../src/components/select-menu.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyD,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC7G,OAAO,EAAE,UAAU,IAAI,gBAAgB,EAAE,gBAAgB,IAAI,aAAa,EAAE,MAAM,SAAS,CAAC;AAC5F,OAAO,EAAE,aAAa,EAAqC,MAAM,OAAO,CAAC;AAEzE,OAAO,
|
|
1
|
+
{"version":3,"file":"select-menu.js","sourceRoot":"","sources":["../../src/components/select-menu.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyD,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC7G,OAAO,EAAE,UAAU,IAAI,gBAAgB,EAAE,gBAAgB,IAAI,aAAa,EAAE,MAAM,SAAS,CAAC;AAC5F,OAAO,EAAE,aAAa,EAAqC,MAAM,OAAO,CAAC;AAEzE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AA2B5D,MAAM,UAAU,UAAU,CACxB,KAA2D;IAE3D,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,KAAgC,CAAC;IAC/D,MAAM,SAAS,GAAG,gBAAgB,CAAC;QACjC,GAAG,IAAI;QACP,GAAG,CAAC,UAAU,IAAI,KAAK,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,QAAiB,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KAChF,CAAC,CAAC;IACZ,OAAO,aAAa,CAAC,cAAc,EAAE,SAAkB,EAAE,QAAqB,CAAC,CAAC;AAClF,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,CAAmC,KAAQ,EAAE,QAAqC;IAC/G,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"}
|
package/dist/react/reconciler.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ReactReconciler from "react-reconciler";
|
|
2
2
|
import { DefaultEventPriority, NoEventPriority } from "react-reconciler/constants.js";
|
|
3
|
-
import { handlers } from "../rendering/
|
|
3
|
+
import { handlers } from "../rendering/callbacks.js";
|
|
4
4
|
import { createNode, isNode, removeChild } from "./node.js";
|
|
5
5
|
import { createTextNode } from "./text-node.js";
|
|
6
6
|
let currentUpdatePriority = NoEventPriority;
|
|
@@ -92,7 +92,7 @@ export const reconciler = ReactReconciler({
|
|
|
92
92
|
suspendInstance() { },
|
|
93
93
|
waitForCommitToBeReady: () => null,
|
|
94
94
|
commitUpdate(node, _type, oldProps, newProps) {
|
|
95
|
-
if (
|
|
95
|
+
if (typeof oldProps.$registeredHandler === "string") {
|
|
96
96
|
handlers.delete(oldProps.$registeredHandler);
|
|
97
97
|
}
|
|
98
98
|
const { children, ...props } = newProps !== null && newProps !== void 0 ? newProps : oldProps;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reconciler.js","sourceRoot":"","sources":["../../src/react/reconciler.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACtF,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"reconciler.js","sourceRoot":"","sources":["../../src/react/reconciler.ts"],"names":[],"mappings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,CAAC;IACxB,gBAAgB,EAAE,GAAG,EAAE,CAAC,IAAI;IAC5B,qBAAqB,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;IAC/B,eAAe,EAAE,GAAG,EAAE,CAAC,KAAK;IAC5B,qBAAqB,KAAI,CAAC;IAC1B,eAAe,KAAI,CAAC;IACpB,sBAAsB,EAAE,GAAG,EAAE,CAAC,IAAI;IAClC,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ;QAC1C,IAAI,OAAO,QAAQ,CAAC,kBAAkB,KAAK,QAAQ,EAAE,CAAC;YACpD,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;QAC/C,CAAC;QACD,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,GAAG,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,QAAQ,CAAC;QACpD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IACD,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC;IACvB,CAAC;IACD,YAAY,CAAC,QAAQ;QACnB,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC;IACzB,CAAC;IACD,cAAc,CAAC,QAAQ;QACrB,QAAQ,CAAC,MAAM,GAAG,KAAK,CAAC;IAC1B,CAAC;IACD,gBAAgB,CAAC,YAAY;QAC3B,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC;IAC7B,CAAC;IACD,kBAAkB,CAAC,YAAY;QAC7B,YAAY,CAAC,MAAM,GAAG,KAAK,CAAC;IAC9B,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type MessageComponentInteraction, type ModalSubmitInteraction } from "./interaction.ts";
|
|
2
|
+
type Handler = ((i: MessageComponentInteraction) => void | Promise<void>) | ((i: ModalSubmitInteraction) => void | Promise<void>);
|
|
3
|
+
export declare const handlers: Map<string, Handler>;
|
|
4
|
+
/** The pattern to export for handling `onClick`/`onSubmit` callbacks */
|
|
5
|
+
export declare const pattern = "@dressed/react-handler-:handlerId{-:fallback}";
|
|
6
|
+
/** Creates a function for handling callback interactions */
|
|
7
|
+
export declare function setupCallbacksHandler<T extends Record<string, Handler> = {}>(fallbacks?: T): ((interaction: MessageComponentInteraction | ModalSubmitInteraction, args: {
|
|
8
|
+
handlerId: string;
|
|
9
|
+
fallback?: string;
|
|
10
|
+
}) => Promise<void>) & {
|
|
11
|
+
fallbacks: { [K in keyof T]: K; };
|
|
12
|
+
};
|
|
13
|
+
export declare function registerHandler(handler: Handler, fallback?: string, id?: string): {
|
|
14
|
+
custom_id: string;
|
|
15
|
+
$registeredHandler: string;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { patchInteraction } from "./interaction.js";
|
|
2
|
+
export const handlers = new Map();
|
|
3
|
+
/** The pattern to export for handling `onClick`/`onSubmit` callbacks */
|
|
4
|
+
export const pattern = "@dressed/react-handler-:handlerId{-:fallback}";
|
|
5
|
+
/** Creates a function for handling callback interactions */
|
|
6
|
+
// biome-ignore lint/complexity/noBannedTypes: Need an empty record
|
|
7
|
+
export function setupCallbacksHandler(fallbacks = {}) {
|
|
8
|
+
for (const key in fallbacks)
|
|
9
|
+
handlers.set(key, fallbacks[key]);
|
|
10
|
+
return Object.assign(async (interaction, args) => {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
const handler = (_a = handlers.get(args.handlerId)) !== null && _a !== void 0 ? _a : handlers.get((_b = args.fallback) !== null && _b !== void 0 ? _b : "default");
|
|
13
|
+
// @ts-expect-error
|
|
14
|
+
interaction = interaction.$patched === Symbol.for("@dressed/react") ? interaction : patchInteraction(interaction);
|
|
15
|
+
if (!handler)
|
|
16
|
+
throw new Error("Unknown handler");
|
|
17
|
+
await handler(interaction);
|
|
18
|
+
if (!interaction.history.length)
|
|
19
|
+
interaction.deferUpdate();
|
|
20
|
+
}, { fallbacks: Object.fromEntries(Object.keys(fallbacks).map((k) => [k, k])) });
|
|
21
|
+
}
|
|
22
|
+
export function registerHandler(handler, fallback, id = randId()) {
|
|
23
|
+
handlers.set(id, handler);
|
|
24
|
+
const fbText = fallback ? `-${fallback}` : "";
|
|
25
|
+
return { custom_id: `@dressed/react-handler-${id}${fbText}`, $registeredHandler: id };
|
|
26
|
+
}
|
|
27
|
+
function randId(length = 16) {
|
|
28
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
29
|
+
const array = new Uint32Array(length);
|
|
30
|
+
crypto.getRandomValues(array);
|
|
31
|
+
return Array.from(array, (x) => chars[x % chars.length]).join("");
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=callbacks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callbacks.js","sourceRoot":"","sources":["../../src/rendering/callbacks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAMnH,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAmB,CAAC;AAEnD,wEAAwE;AACxE,MAAM,CAAC,MAAM,OAAO,GAAG,+CAA+C,CAAC;AAEvE,4DAA4D;AAC5D,mEAAmE;AACnE,MAAM,UAAU,qBAAqB,CAAyC,YAAe,EAAO;IAClG,KAAK,MAAM,GAAG,IAAI,SAAS;QAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/D,OAAO,MAAM,CAAC,MAAM,CAClB,KAAK,EACH,WAAiE,EACjE,IAA8C,EAC9C,EAAE;;QACF,MAAM,OAAO,GAAG,MAAA,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,mCAAI,QAAQ,CAAC,GAAG,CAAC,MAAA,IAAI,CAAC,QAAQ,m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CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
import { type RendererCallback } from "../react/renderer.ts";
|
|
3
|
-
export declare function render(children: ReactNode, callback: RendererCallback):
|
|
3
|
+
export declare function render(children: ReactNode, callback: RendererCallback): {
|
|
4
|
+
renderer: import("../react/renderer.ts").Renderer;
|
|
5
|
+
container: any;
|
|
6
|
+
};
|
package/dist/rendering/index.js
CHANGED
|
@@ -5,6 +5,6 @@ export function render(children, callback) {
|
|
|
5
5
|
const container = reconciler.createContainer(renderer, 0, null, false, null, "dressed", (error) => console.error(error), () => { }, () => { }, () => { }, null);
|
|
6
6
|
if (container !== null)
|
|
7
7
|
reconciler.updateContainer(children, container);
|
|
8
|
-
return renderer;
|
|
8
|
+
return { renderer, container };
|
|
9
9
|
}
|
|
10
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rendering/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAyB,MAAM,sBAAsB,CAAC;AAE7E,MAAM,UAAU,MAAM,CAAC,QAAmB,EAAE,QAA0B;IACpE,MAAM,QAAQ,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAE1C,MAAM,SAAS,GAAG,UAAU,CAAC,eAAe,CAC1C,QAAQ,EACR,CAAC,EACD,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,SAAS,EACT,CAAC,KAAY,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,EACtC,GAAG,EAAE,GAAE,CAAC,EACR,GAAG,EAAE,GAAE,CAAC,EACR,GAAG,EAAE,GAAE,CAAC,EACR,IAAI,CACL,CAAC;IAEF,IAAI,SAAS,KAAK,IAAI;QAAE,UAAU,CAAC,eAAe,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAExE,OAAO,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rendering/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAyB,MAAM,sBAAsB,CAAC;AAE7E,MAAM,UAAU,MAAM,CAAC,QAAmB,EAAE,QAA0B;IACpE,MAAM,QAAQ,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAE1C,MAAM,SAAS,GAAG,UAAU,CAAC,eAAe,CAC1C,QAAQ,EACR,CAAC,EACD,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,SAAS,EACT,CAAC,KAAY,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,EACtC,GAAG,EAAE,GAAE,CAAC,EACR,GAAG,EAAE,GAAE,CAAC,EACR,GAAG,EAAE,GAAE,CAAC,EACR,IAAI,CACL,CAAC;IAEF,IAAI,SAAS,KAAK,IAAI;QAAE,UAAU,CAAC,eAAe,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAExE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;AACjC,CAAC"}
|
|
@@ -2,16 +2,6 @@ import { type ApplicationCommandType } from "discord-api-types/v10";
|
|
|
2
2
|
import { type CommandConfig, type CommandInteraction as DressedCommandInteraction, type MessageComponentInteraction as DressedMessageComponentInteraction, type ModalSubmitInteraction as DressedModalSubmitInteraction } from "dressed";
|
|
3
3
|
import type { createInteraction } from "dressed/server";
|
|
4
4
|
import type { ReactNode } from "react";
|
|
5
|
-
type Handler = ((i: MessageComponentInteraction) => Promise<void>) | ((i: ModalSubmitInteraction) => Promise<void>);
|
|
6
|
-
export declare const handlers: Map<string, Handler>;
|
|
7
|
-
export declare const pattern = "@dressed/react-handler-:handlerId";
|
|
8
|
-
export declare function handleInteraction(interaction: MessageComponentInteraction | ModalSubmitInteraction, args: {
|
|
9
|
-
handlerId: string;
|
|
10
|
-
}): Promise<void>;
|
|
11
|
-
export declare function registerHandler(handler: Handler, id?: string): {
|
|
12
|
-
custom_id: string;
|
|
13
|
-
$registeredHandler: string;
|
|
14
|
-
};
|
|
15
5
|
type ReactivatedInteraction<T> = OverrideMethodParams<T, {
|
|
16
6
|
[K in "reply" | "editReply" | "update" | "followUp" | "showModal"]: [
|
|
17
7
|
components: ReactNode,
|
|
@@ -1,32 +1,13 @@
|
|
|
1
1
|
import { MessageFlags } from "discord-api-types/v10";
|
|
2
2
|
import { editWebhookMessage, } from "dressed";
|
|
3
|
+
import { reconciler } from "../react/reconciler.js";
|
|
3
4
|
import { render } from "./index.js";
|
|
4
|
-
export const handlers = new Map();
|
|
5
|
-
export const pattern = "@dressed/react-handler-:handlerId";
|
|
6
|
-
export async function handleInteraction(interaction, args) {
|
|
7
|
-
const handler = handlers.get(args.handlerId);
|
|
8
|
-
if (!handler)
|
|
9
|
-
throw new Error("Unknown handler");
|
|
10
|
-
// @ts-expect-error
|
|
11
|
-
await handler(interaction.$patched === Symbol.for("@dressed/react") ? interaction : patchInteraction(interaction));
|
|
12
|
-
if (!interaction.history.length)
|
|
13
|
-
interaction.deferUpdate();
|
|
14
|
-
}
|
|
15
|
-
export function registerHandler(handler, id = randId()) {
|
|
16
|
-
handlers.set(id, handler);
|
|
17
|
-
return { custom_id: `@dressed/react-handler-${id}`, $registeredHandler: id };
|
|
18
|
-
}
|
|
19
|
-
function randId(length = 16) {
|
|
20
|
-
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
21
|
-
const array = new Uint32Array(length);
|
|
22
|
-
crypto.getRandomValues(array);
|
|
23
|
-
return Array.from(array, (x) => chars[x % chars.length]).join("");
|
|
24
|
-
}
|
|
25
5
|
export function patchInteraction(interaction) {
|
|
6
|
+
const createdAt = Date.now();
|
|
26
7
|
if (!interaction)
|
|
27
8
|
throw new Error("No interaction");
|
|
28
9
|
// biome-ignore lint/suspicious/noExplicitAny: We're overriding the types
|
|
29
|
-
const newInteraction = {
|
|
10
|
+
const newInteraction = { $patched: Symbol.for("@dressed/react"), ...interaction };
|
|
30
11
|
// @ts-expect-error
|
|
31
12
|
const editReply = interaction.editReply;
|
|
32
13
|
for (const method of ["reply", "editReply", "update", "followUp", "showModal"]) {
|
|
@@ -38,7 +19,10 @@ export function patchInteraction(interaction) {
|
|
|
38
19
|
data.flags = ((_a = data.flags) !== null && _a !== void 0 ? _a : 0) | MessageFlags.IsComponentsV2;
|
|
39
20
|
return new Promise((resolve) => {
|
|
40
21
|
let followUpId;
|
|
41
|
-
render(components, async (c) => {
|
|
22
|
+
const { container } = render(components, async (c) => {
|
|
23
|
+
if (Date.now() > createdAt + 6e4 * 15) {
|
|
24
|
+
return reconciler.updateContainer(null, container);
|
|
25
|
+
}
|
|
42
26
|
// @ts-expect-error
|
|
43
27
|
data.components = c;
|
|
44
28
|
if (followUpId) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interaction.js","sourceRoot":"","sources":["../../src/rendering/interaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAKL,kBAAkB,GACnB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"interaction.js","sourceRoot":"","sources":["../../src/rendering/interaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAKL,kBAAkB,GACnB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAyCpC,MAAM,UAAU,gBAAgB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kBAAkB,CAAC,WAAW,CAAC,cAAc,EAAE,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;oBAC9G,CAAC;oBACD,MAAM,UAAU,GAAG,CAAC,MAAM,KAAK,OAAO,IAAI,MAAM,KAAK,QAAQ,CAAC,IAAI,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;oBACvG,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;oBAClE,IAAI,MAAM,KAAK,UAAU;wBAAE,UAAU,GAAG,GAAG,CAAC,EAAE,CAAC;oBAC/C,OAAO,CAAC,GAAG,CAAC,CAAC;gBACf,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,cAAc,CAAC;AACxB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dressed/react",
|
|
3
|
-
"version": "1.7.4-rc.
|
|
3
|
+
"version": "1.7.4-rc.6",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/Inbestigator/dressed.git",
|
|
@@ -10,7 +10,10 @@
|
|
|
10
10
|
"dressed": "^1.10.1",
|
|
11
11
|
"react": "^19.2.3"
|
|
12
12
|
},
|
|
13
|
-
"exports":
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./dist/index.js",
|
|
15
|
+
"./callbacks": "./dist/callbacks.js"
|
|
16
|
+
},
|
|
14
17
|
"description": "Render Dressed's components using React",
|
|
15
18
|
"files": [
|
|
16
19
|
"dist"
|