@fraxic/ui 0.3.1 → 0.3.2
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/index.d.ts +0 -1
- package/index.js +20 -3
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -164,4 +164,3 @@ export declare function dashboard(handler: (page: Page) => void): void;
|
|
|
164
164
|
export declare function onButtonInteraction(handler: (interaction: ButtonInteraction) => void): void;
|
|
165
165
|
export declare function onModalInteraction(handler: (interaction: ModalInteraction) => void): void;
|
|
166
166
|
export declare function onSelectMenuSearch(handler: (search: SelectMenuSearch) => void): void;
|
|
167
|
-
export declare function __fraxicHandleUiRequest(payload: unknown): unknown;
|
package/index.js
CHANGED
|
@@ -18,6 +18,8 @@ const modalHandlers = [];
|
|
|
18
18
|
const selectMenuSearchHandlers = [];
|
|
19
19
|
const sessions = new Map();
|
|
20
20
|
const modalSchemas = new Map();
|
|
21
|
+
let ipcRegistered = false;
|
|
22
|
+
let ipcRegistrationQueued = false;
|
|
21
23
|
|
|
22
24
|
function requireText(name, value) {
|
|
23
25
|
if (typeof value !== "string") throw new Error(`${name} must be a string`);
|
|
@@ -894,21 +896,25 @@ export class SelectMenuSearch {
|
|
|
894
896
|
|
|
895
897
|
export function dashboard(handler) {
|
|
896
898
|
dashboardHandler = handler;
|
|
899
|
+
ensureIpcRegistered();
|
|
897
900
|
}
|
|
898
901
|
|
|
899
902
|
export function onButtonInteraction(handler) {
|
|
900
903
|
buttonHandlers.push(handler);
|
|
904
|
+
ensureIpcRegistered();
|
|
901
905
|
}
|
|
902
906
|
|
|
903
907
|
export function onModalInteraction(handler) {
|
|
904
908
|
modalHandlers.push(handler);
|
|
909
|
+
ensureIpcRegistered();
|
|
905
910
|
}
|
|
906
911
|
|
|
907
912
|
export function onSelectMenuSearch(handler) {
|
|
908
913
|
selectMenuSearchHandlers.push(handler);
|
|
914
|
+
ensureIpcRegistered();
|
|
909
915
|
}
|
|
910
916
|
|
|
911
|
-
|
|
917
|
+
function handleUiRequest(payload) {
|
|
912
918
|
const request = payload;
|
|
913
919
|
if (request.type === "render") return render(request);
|
|
914
920
|
if (request.type === "button") return handleButton(request);
|
|
@@ -984,8 +990,19 @@ function noResponse() {
|
|
|
984
990
|
return { ok: false, reason: "noResponse" };
|
|
985
991
|
}
|
|
986
992
|
|
|
993
|
+
function ensureIpcRegistered() {
|
|
994
|
+
if (ipcRegistered || ipcRegistrationQueued) return;
|
|
995
|
+
ipcRegistrationQueued = true;
|
|
996
|
+
queueMicrotask(() => {
|
|
997
|
+
ipcRegistrationQueued = false;
|
|
998
|
+
if (ipcRegistered) return;
|
|
999
|
+
const listen = globalThis.__fraxic?.ipc?.listen;
|
|
1000
|
+
if (typeof listen !== "function") return;
|
|
1001
|
+
listen("ui", handleUiRequest);
|
|
1002
|
+
ipcRegistered = true;
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
|
|
987
1006
|
function ensureModalHasComponents(modal) {
|
|
988
1007
|
if (modal.toMap().components.length === 0) throw new Error("modal must have at least 1 component");
|
|
989
1008
|
}
|
|
990
|
-
|
|
991
|
-
globalThis.__fraxic?.ipc?.listen?.("ui", __fraxicHandleUiRequest);
|