@ai-matrx/summon 0.1.7 → 0.1.8

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/CHANGELOG.md +15 -2
  2. package/dist/gate-DUvE-Cc1.d.cts +399 -0
  3. package/dist/gate-DUvE-Cc1.d.ts +399 -0
  4. package/dist/handles.cjs +1 -0
  5. package/dist/handles.cjs.map +1 -1
  6. package/dist/handles.d.cts +3 -61
  7. package/dist/handles.d.ts +3 -61
  8. package/dist/handles.js +1 -0
  9. package/dist/handles.js.map +1 -1
  10. package/dist/helpers-2NY1ha0V.d.cts +63 -0
  11. package/dist/helpers-2NY1ha0V.d.ts +63 -0
  12. package/dist/index.cjs +194 -159
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +9 -355
  15. package/dist/index.d.ts +9 -355
  16. package/dist/index.js +200 -165
  17. package/dist/index.js.map +1 -1
  18. package/dist/instanceBody-CgZAFnic.d.cts +23 -0
  19. package/dist/instanceBody-CgZAFnic.d.ts +23 -0
  20. package/dist/open.cjs +408 -0
  21. package/dist/open.cjs.map +1 -0
  22. package/dist/open.d.cts +22 -0
  23. package/dist/open.d.ts +22 -0
  24. package/dist/open.js +375 -0
  25. package/dist/open.js.map +1 -0
  26. package/dist/react.cjs +249 -352
  27. package/dist/react.cjs.map +1 -1
  28. package/dist/react.d.cts +11 -151
  29. package/dist/react.d.ts +11 -151
  30. package/dist/react.js +210 -306
  31. package/dist/react.js.map +1 -1
  32. package/dist/root.cjs +277 -0
  33. package/dist/root.cjs.map +1 -0
  34. package/dist/root.d.cts +175 -0
  35. package/dist/root.d.ts +175 -0
  36. package/dist/root.js +254 -0
  37. package/dist/root.js.map +1 -0
  38. package/dist/window-host.cjs +11 -2
  39. package/dist/window-host.cjs.map +1 -1
  40. package/dist/window-host.d.cts +1 -0
  41. package/dist/window-host.d.ts +1 -0
  42. package/dist/window-host.js +11 -2
  43. package/dist/window-host.js.map +1 -1
  44. package/dist/window.cjs +2 -1
  45. package/dist/window.cjs.map +1 -1
  46. package/dist/window.d.cts +3 -2
  47. package/dist/window.d.ts +3 -2
  48. package/dist/window.js +2 -1
  49. package/dist/window.js.map +1 -1
  50. package/package.json +28 -5
package/dist/react.cjs CHANGED
@@ -21,7 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  // src/react.ts
22
22
  var react_exports = {};
23
23
  __export(react_exports, {
24
- CALLBACK_GROUP_KEY: () => CALLBACK_GROUP_KEY,
24
+ CALLBACK_GROUP_KEY: () => import_root9.CALLBACK_GROUP_KEY,
25
25
  DEFAULT_IMPORT_TIMEOUT_MS: () => DEFAULT_IMPORT_TIMEOUT_MS,
26
26
  DEFAULT_KEEP_ALIVE_LIMIT: () => DEFAULT_KEEP_ALIVE_LIMIT,
27
27
  DEFAULT_STALL_WARN_MS: () => DEFAULT_STALL_WARN_MS,
@@ -31,152 +31,50 @@ __export(react_exports, {
31
31
  OverlayLoadingFallback: () => OverlayLoadingFallback,
32
32
  SummonHost: () => SummonHost,
33
33
  SummonProvider: () => SummonProvider,
34
- SummonStoreContext: () => SummonStoreContext,
34
+ SummonRoot: () => import_root10.SummonRoot,
35
+ SummonStoreContext: () => import_root.SummonStoreContext,
35
36
  chunkTimeoutError: () => chunkTimeoutError,
36
- defineOverlay: () => defineOverlay,
37
+ configureSummonHost: () => import_root10.configureSummonHost,
38
+ defineOverlay: () => import_root9.defineOverlay,
39
+ emitOverlayEvent: () => emitOverlayEvent,
37
40
  normalizeOverlayError: () => normalizeOverlayError,
38
41
  useCloseOnNavigation: () => useCloseOnNavigation,
39
42
  useCloseOverlay: () => useCloseOverlay,
40
43
  useIsOverlayOpen: () => useIsOverlayOpen,
41
44
  useOpenOverlay: () => useOpenOverlay,
42
- useOptionalOverlayInstance: () => useOptionalOverlayInstance,
43
- useOptionalSummonPorts: () => useOptionalSummonPorts,
44
- useOptionalSummonStore: () => useOptionalSummonStore,
45
- useOverlayInstance: () => useOverlayInstance,
45
+ useOptionalOverlayInstance: () => import_root6.useOptionalOverlayInstance,
46
+ useOptionalSummonPorts: () => import_root3.useOptionalSummonPorts,
47
+ useOptionalSummonStore: () => import_root3.useOptionalSummonStore,
48
+ useOverlayInstance: () => import_root6.useOverlayInstance,
46
49
  useOverlayLink: () => useOverlayLink,
47
50
  useOverlayState: () => useOverlayState,
48
- useSummonDispatch: () => useSummonDispatch,
49
- useSummonPorts: () => useSummonPorts,
50
- useSummonSelector: () => useSummonSelector,
51
- useSummonStore: () => useSummonStore
51
+ useSummonDispatch: () => import_root3.useSummonDispatch,
52
+ useSummonPorts: () => import_root3.useSummonPorts,
53
+ useSummonSelector: () => import_root3.useSummonSelector,
54
+ useSummonStore: () => import_root3.useSummonStore
52
55
  });
53
56
  module.exports = __toCommonJS(react_exports);
54
57
 
55
58
  // src/react/SummonProvider.tsx
56
59
  var import_react5 = require("react");
57
- var import_react_redux2 = require("react-redux");
60
+ var import_react_redux = require("react-redux");
61
+ var import_summon = require("@ai-matrx/summon");
58
62
  var import_summon2 = require("@ai-matrx/summon");
59
- var import_summon3 = require("@ai-matrx/summon");
60
63
 
61
64
  // src/react/context.ts
62
65
  var import_react = require("react");
63
- var SummonStoreContext = (0, import_react.createContext)(null);
64
- SummonStoreContext.displayName = "SummonStoreContext";
65
- var SummonPortsContext = (0, import_react.createContext)(null);
66
- SummonPortsContext.displayName = "SummonPortsContext";
66
+ var import_root = require("@ai-matrx/summon/root");
67
67
  var SummonConfigContext = (0, import_react.createContext)(null);
68
68
  SummonConfigContext.displayName = "SummonConfigContext";
69
69
 
70
70
  // src/react/fallbacks.tsx
71
- var import_react3 = require("react");
71
+ var import_react4 = require("react");
72
72
  var import_design_system = require("@ai-matrx/design-system");
73
73
 
74
74
  // src/react/storeHooks.ts
75
- var import_react2 = require("react");
76
- var import_react_redux = require("react-redux");
77
- var import_summon = require("@ai-matrx/summon");
78
- var useSummonSelector = (0, import_react_redux.createSelectorHook)(SummonStoreContext).withTypes();
79
- var useSummonDispatch = (0, import_react_redux.createDispatchHook)(SummonStoreContext).withTypes();
80
- var useSummonStore = (0, import_react_redux.createStoreHook)(SummonStoreContext).withTypes();
81
- var MISSING_PROVIDER = "[summon] No <SummonProvider> above this component. Wrap the app (or the part that opens overlays) in <SummonProvider>.";
82
- function useSummonPorts() {
83
- const ports = (0, import_react2.useContext)(SummonPortsContext);
84
- if (!ports) throw new Error(MISSING_PROVIDER);
85
- return ports;
86
- }
87
- function useOptionalSummonPorts() {
88
- return (0, import_react2.useContext)(SummonPortsContext) ?? import_summon.DEFAULT_PORTS;
89
- }
90
- function useOptionalSummonStore() {
91
- const context = (0, import_react2.useContext)(SummonStoreContext);
92
- return context ? context.store : null;
93
- }
94
- function useSummonConfig() {
95
- const config = (0, import_react2.useContext)(SummonConfigContext);
96
- if (!config) throw new Error(MISSING_PROVIDER);
97
- return config;
98
- }
99
-
100
- // src/react/fallbacks.tsx
101
- var import_jsx_runtime = require("react/jsx-runtime");
102
- function normalizeOverlayError(error) {
103
- if (error instanceof Error) {
104
- const isChunkLoadError = error.name === "ChunkLoadError" || /Loading chunk [\w-]+ failed|Failed to fetch dynamically imported module|Importing a module script failed/i.test(
105
- error.message
106
- );
107
- return { name: error.name, message: error.message, stack: error.stack ?? null, isChunkLoadError };
108
- }
109
- return { name: "Error", message: typeof error === "string" ? error : String(error), stack: null, isChunkLoadError: false };
110
- }
111
- function OverlayLoadingFallback({ overlayId, label }) {
112
- const ports = useSummonPorts();
113
- const { stallWarnMs } = useSummonConfig();
114
- (0, import_react3.useEffect)(() => {
115
- const timer = setTimeout(() => {
116
- ports.errors.capture(new Error(`Overlay "${overlayId}" still loading after ${stallWarnMs}ms`), {
117
- stage: "overlay-load-stall",
118
- overlayId,
119
- level: "warning"
120
- });
121
- }, stallWarnMs);
122
- return () => clearTimeout(timer);
123
- }, [ports, overlayId, stallWarnMs]);
124
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pointer-events-none fixed inset-0 z-[2147483000] flex items-center justify-center p-4", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
125
- "div",
126
- {
127
- role: "status",
128
- "aria-label": `Loading ${label}`,
129
- className: "pointer-events-auto flex items-center gap-3 rounded-xl border border-border bg-card px-5 py-4 text-sm text-muted-foreground shadow-[var(--elevation-2)]",
130
- children: [
131
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { "aria-hidden": true, className: "size-4 animate-spin rounded-full border-2 border-border border-t-primary" }),
132
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Loading\u2026" })
133
- ]
134
- }
135
- ) });
136
- }
137
- function OverlayErrorFallback({ label, error, retry, close, extras }) {
138
- const e = normalizeOverlayError(error);
139
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pointer-events-none fixed inset-0 z-[2147483001] flex items-center justify-center p-4", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
140
- "div",
141
- {
142
- role: "alertdialog",
143
- "aria-label": `${label} failed to load`,
144
- className: "pointer-events-auto flex max-h-[85dvh] w-full max-w-lg flex-col overflow-hidden rounded-xl border border-destructive bg-card shadow-[var(--elevation-3)]",
145
- children: [
146
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "border-b border-border px-5 py-4", children: [
147
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("h2", { className: "text-sm font-semibold text-foreground", children: [
148
- label,
149
- " failed to load"
150
- ] }),
151
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "mt-1 text-xs text-muted-foreground", children: e.isChunkLoadError ? "Part of it did not finish loading." : "It hit an error while rendering." })
152
- ] }),
153
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "min-h-0 flex-1 overflow-auto px-5 py-4", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "rounded-lg bg-muted px-3 py-2 font-mono text-xs text-foreground", children: [
154
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-destructive", children: e.name }),
155
- ": ",
156
- e.message
157
- ] }) }),
158
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center justify-between gap-2 border-t border-border px-5 py-3", children: [
159
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: extras }),
160
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center gap-2", children: [
161
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_design_system.Button, { variant: "ghost", size: "sm", onClick: close, children: "Close" }),
162
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_design_system.Button, { variant: "primary", size: "sm", onClick: retry, children: "Try again" }),
163
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
164
- import_design_system.Button,
165
- {
166
- variant: "outline",
167
- size: "sm",
168
- onClick: () => {
169
- if (typeof window !== "undefined") window.location.reload();
170
- },
171
- children: "Reload page"
172
- }
173
- )
174
- ] })
175
- ] })
176
- ]
177
- }
178
- ) });
179
- }
75
+ var import_react3 = require("react");
76
+ var import_root2 = require("@ai-matrx/summon/root");
77
+ var import_global_slot = require("@ai-matrx/kit/global-slot");
180
78
 
181
79
  // src/react/keepAlive.ts
182
80
  var KeepAliveRegistry = class {
@@ -221,7 +119,7 @@ var KeepAliveRegistry = class {
221
119
  };
222
120
 
223
121
  // src/react/loaderCache.ts
224
- var import_react4 = require("react");
122
+ var import_react2 = require("react");
225
123
  function chunkTimeoutError(key, timeoutMs) {
226
124
  const error = new Error(
227
125
  `Overlay "${key}" render module did not load within ${timeoutMs}ms. The import() did not resolve before the recovery timeout.`
@@ -246,7 +144,7 @@ var LoaderCache = class {
246
144
  this.options = options;
247
145
  }
248
146
  create(key, loader, attempt) {
249
- const Component2 = (0, import_react4.lazy)(() => {
147
+ const Component2 = (0, import_react2.lazy)(() => {
250
148
  this.options.onImportStart?.(key, attempt);
251
149
  return raceTimeout(key, loader(), this.options.timeoutMs());
252
150
  });
@@ -269,11 +167,119 @@ var LoaderCache = class {
269
167
  }
270
168
  };
271
169
 
272
- // src/react/SummonProvider.tsx
273
- var import_jsx_runtime2 = require("react/jsx-runtime");
170
+ // src/react/storeHooks.ts
171
+ var import_root3 = require("@ai-matrx/summon/root");
274
172
  var DEFAULT_KEEP_ALIVE_LIMIT = 8;
275
173
  var DEFAULT_IMPORT_TIMEOUT_MS = 12e3;
276
174
  var DEFAULT_STALL_WARN_MS = 1e4;
175
+ var hostConfigSlot = () => (0, import_global_slot.globalSlot)("ai-matrx.summon.hostReactConfig", () => ({ version: -1, config: null, keepAlive: null, loaders: null }));
176
+ function hostReactConfig() {
177
+ const s = hostConfigSlot();
178
+ const version = (0, import_root2.getSummonHostVersion)();
179
+ if (s.config && s.version === version) return s.config;
180
+ const host = (0, import_root2.getSummonHostConfig)();
181
+ s.keepAlive ??= new KeepAliveRegistry(DEFAULT_KEEP_ALIVE_LIMIT);
182
+ s.loaders ??= new LoaderCache({ timeoutMs: () => DEFAULT_IMPORT_TIMEOUT_MS });
183
+ s.config = {
184
+ loadingFallback: OverlayLoadingFallback,
185
+ errorFallback: OverlayErrorFallback,
186
+ errorReportExtras: host.errorReportExtras ?? null,
187
+ renderWrapper: host.renderWrapper ?? null,
188
+ importTimeoutMs: DEFAULT_IMPORT_TIMEOUT_MS,
189
+ stallWarnMs: DEFAULT_STALL_WARN_MS,
190
+ keepAlive: s.keepAlive,
191
+ loaders: s.loaders
192
+ };
193
+ s.version = version;
194
+ return s.config;
195
+ }
196
+ function useSummonConfig() {
197
+ return (0, import_react3.useContext)(SummonConfigContext) ?? hostReactConfig();
198
+ }
199
+
200
+ // src/react/fallbacks.tsx
201
+ var import_jsx_runtime = require("react/jsx-runtime");
202
+ function normalizeOverlayError(error) {
203
+ if (error instanceof Error) {
204
+ const isChunkLoadError = error.name === "ChunkLoadError" || /Loading chunk [\w-]+ failed|Failed to fetch dynamically imported module|Importing a module script failed/i.test(
205
+ error.message
206
+ );
207
+ return { name: error.name, message: error.message, stack: error.stack ?? null, isChunkLoadError };
208
+ }
209
+ return { name: "Error", message: typeof error === "string" ? error : String(error), stack: null, isChunkLoadError: false };
210
+ }
211
+ function OverlayLoadingFallback({ overlayId, label }) {
212
+ const ports = (0, import_root3.useSummonPorts)();
213
+ const { stallWarnMs } = useSummonConfig();
214
+ (0, import_react4.useEffect)(() => {
215
+ const timer = setTimeout(() => {
216
+ ports.errors.capture(new Error(`Overlay "${overlayId}" still loading after ${stallWarnMs}ms`), {
217
+ stage: "overlay-load-stall",
218
+ overlayId,
219
+ level: "warning"
220
+ });
221
+ }, stallWarnMs);
222
+ return () => clearTimeout(timer);
223
+ }, [ports, overlayId, stallWarnMs]);
224
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pointer-events-none fixed inset-0 z-[2147483000] flex items-center justify-center p-4", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
225
+ "div",
226
+ {
227
+ role: "status",
228
+ "aria-label": `Loading ${label}`,
229
+ className: "pointer-events-auto flex items-center gap-3 rounded-xl border border-border bg-card px-5 py-4 text-sm text-muted-foreground shadow-[var(--elevation-2)]",
230
+ children: [
231
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { "aria-hidden": true, className: "size-4 animate-spin rounded-full border-2 border-border border-t-primary" }),
232
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Loading\u2026" })
233
+ ]
234
+ }
235
+ ) });
236
+ }
237
+ function OverlayErrorFallback({ label, error, retry, close, extras }) {
238
+ const e = normalizeOverlayError(error);
239
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pointer-events-none fixed inset-0 z-[2147483001] flex items-center justify-center p-4", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
240
+ "div",
241
+ {
242
+ role: "alertdialog",
243
+ "aria-label": `${label} failed to load`,
244
+ className: "pointer-events-auto flex max-h-[85dvh] w-full max-w-lg flex-col overflow-hidden rounded-xl border border-destructive bg-card shadow-[var(--elevation-3)]",
245
+ children: [
246
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "border-b border-border px-5 py-4", children: [
247
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("h2", { className: "text-sm font-semibold text-foreground", children: [
248
+ label,
249
+ " failed to load"
250
+ ] }),
251
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "mt-1 text-xs text-muted-foreground", children: e.isChunkLoadError ? "Part of it did not finish loading." : "It hit an error while rendering." })
252
+ ] }),
253
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "min-h-0 flex-1 overflow-auto px-5 py-4", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "rounded-lg bg-muted px-3 py-2 font-mono text-xs text-foreground", children: [
254
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-destructive", children: e.name }),
255
+ ": ",
256
+ e.message
257
+ ] }) }),
258
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center justify-between gap-2 border-t border-border px-5 py-3", children: [
259
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: extras }),
260
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center gap-2", children: [
261
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_design_system.Button, { variant: "ghost", size: "sm", onClick: close, children: "Close" }),
262
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_design_system.Button, { variant: "primary", size: "sm", onClick: retry, children: "Try again" }),
263
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
264
+ import_design_system.Button,
265
+ {
266
+ variant: "outline",
267
+ size: "sm",
268
+ onClick: () => {
269
+ if (typeof window !== "undefined") window.location.reload();
270
+ },
271
+ children: "Reload page"
272
+ }
273
+ )
274
+ ] })
275
+ ] })
276
+ ]
277
+ }
278
+ ) });
279
+ }
280
+
281
+ // src/react/SummonProvider.tsx
282
+ var import_jsx_runtime2 = require("react/jsx-runtime");
277
283
  function SummonProvider({
278
284
  store,
279
285
  ports,
@@ -285,8 +291,8 @@ function SummonProvider({
285
291
  stallWarnMs = DEFAULT_STALL_WARN_MS,
286
292
  children
287
293
  }) {
288
- const resolvedPorts = (0, import_react5.useMemo)(() => (0, import_summon2.resolvePorts)(ports), [ports]);
289
- const [privateStore] = (0, import_react5.useState)(() => store ? null : (0, import_summon3.createSummonStore)({ ports: resolvedPorts }));
294
+ const resolvedPorts = (0, import_react5.useMemo)(() => (0, import_summon.resolvePorts)(ports), [ports]);
295
+ const [privateStore] = (0, import_react5.useState)(() => store ? null : (0, import_summon2.createSummonStore)({ ports: resolvedPorts }));
290
296
  const activeStore = store ?? privateStore;
291
297
  const timeoutRef = (0, import_react5.useRef)(importTimeoutMs);
292
298
  timeoutRef.current = importTimeoutMs;
@@ -308,55 +314,58 @@ function SummonProvider({
308
314
  }),
309
315
  [loading, error, errorReportExtras, renderWrapper, importTimeoutMs, stallWarnMs, keepAlive, loaders]
310
316
  );
311
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_redux2.Provider, { store: activeStore, context: SummonStoreContext, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SummonPortsContext.Provider, { value: resolvedPorts, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SummonConfigContext.Provider, { value: config, children }) }) });
317
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_redux.Provider, { store: activeStore, context: import_root.SummonStoreContext, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_root.SummonPortsContext.Provider, { value: resolvedPorts, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SummonConfigContext.Provider, { value: config, children }) }) });
312
318
  }
313
319
 
314
- // src/react/defineOverlay.tsx
315
- var import_react10 = require("react");
316
- var import_summon7 = require("@ai-matrx/summon");
317
- var import_summon8 = require("@ai-matrx/summon");
318
-
319
- // src/react/dispatchers.ts
320
- var import_summon4 = require("@ai-matrx/summon");
321
- var import_summon5 = require("@ai-matrx/summon");
322
- function newInstanceId(overlayId) {
323
- return `${overlayId}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
324
- }
325
- function dispatchOpen(dispatch, overlayId, instanceId, data) {
326
- dispatch(
327
- (0, import_summon4.openOverlay)({
328
- overlayId,
329
- instanceId,
330
- data: data ?? null
331
- })
332
- );
333
- }
334
- function dispatchClose(dispatch, overlayId, instanceId = import_summon5.DEFAULT_INSTANCE_ID) {
335
- dispatch((0, import_summon4.closeOverlay)({ overlayId, instanceId }));
336
- }
320
+ // src/react.ts
321
+ var import_root9 = require("@ai-matrx/summon/root");
337
322
 
338
323
  // src/react/events.ts
339
324
  var import_handles = require("@ai-matrx/summon/handles");
340
- function openOverlayEventChannel(owner, getHandlers) {
341
- const channel = (0, import_handles.createEventChannel)({ owner });
342
- channel.subscribe((message) => {
343
- const handlers = getHandlers();
344
- handlers?.[message.type]?.(message.payload);
345
- });
346
- return channel.id;
347
- }
325
+ var import_open = require("@ai-matrx/summon/open");
326
+ var import_root4 = require("@ai-matrx/summon/root");
348
327
  function emitOverlayEvent(channelId, type, payload) {
328
+ (0, import_open.materializePendingChannels)(import_handles.createEventChannel);
349
329
  (0, import_handles.getEventChannel)(channelId)?.emit({ type, payload });
350
330
  }
331
+ (0, import_root4.registerOverlayEmitter)(emitOverlayEvent);
332
+
333
+ // src/react/SummonHost.tsx
334
+ var import_react10 = require("react");
335
+ var import_summon4 = require("@ai-matrx/summon");
336
+ var import_summon5 = require("@ai-matrx/summon");
337
+ var import_summon6 = require("@ai-matrx/summon");
338
+ var import_summon7 = require("@ai-matrx/summon");
339
+ var import_root7 = require("@ai-matrx/summon/root");
340
+
341
+ // src/react/hostRenders.ts
342
+ var import_react6 = require("react");
343
+ var HostRendersContext = (0, import_react6.createContext)(null);
344
+ var MISSING_RENDER_ERROR = "OverlayRenderMissingError";
345
+ var missing = /* @__PURE__ */ new Map();
346
+ function missingRenderLoader(overlayId) {
347
+ let loader = missing.get(overlayId);
348
+ if (!loader) {
349
+ const message = `Overlay "${overlayId}" is open but has no render module: its definition has no \`render\` and <SummonHost renders> has no "${overlayId}" entry.`;
350
+ loader = () => {
351
+ if (process.env.NODE_ENV !== "production") console.error(`[summon] ${message}`);
352
+ const error = new Error(message);
353
+ error.name = MISSING_RENDER_ERROR;
354
+ return Promise.reject(error);
355
+ };
356
+ missing.set(overlayId, loader);
357
+ }
358
+ return loader;
359
+ }
351
360
 
352
361
  // src/react/instanceBody.tsx
353
362
  var import_react9 = require("react");
354
363
 
355
364
  // src/react/OverlayErrorBoundary.tsx
356
- var import_react6 = require("react");
365
+ var import_react7 = require("react");
357
366
  var import_jsx_runtime3 = require("react/jsx-runtime");
358
367
  var CLEAR = { error: null, hasError: false, componentStack: null };
359
- var OverlayErrorBoundary = class extends import_react6.Component {
368
+ var OverlayErrorBoundary = class extends import_react7.Component {
360
369
  state = CLEAR;
361
370
  static getDerivedStateFromError(error) {
362
371
  return { error, hasError: true };
@@ -401,32 +410,22 @@ var OverlayErrorBoundary = class extends import_react6.Component {
401
410
  };
402
411
 
403
412
  // src/react/instance.tsx
404
- var import_react7 = require("react");
405
- var import_summon6 = require("@ai-matrx/summon");
406
- var OverlayInstanceContext = (0, import_react7.createContext)(null);
407
- OverlayInstanceContext.displayName = "OverlayInstanceContext";
408
- function useOverlayInstance() {
409
- const value = (0, import_react7.useContext)(OverlayInstanceContext);
410
- if (!value) {
411
- throw new Error("[summon] useOverlayInstance() was called outside a rendered overlay.");
412
- }
413
- return value;
414
- }
415
- function useOptionalOverlayInstance() {
416
- return (0, import_react7.useContext)(OverlayInstanceContext);
417
- }
413
+ var import_react8 = require("react");
414
+ var import_summon3 = require("@ai-matrx/summon");
415
+ var import_root5 = require("@ai-matrx/summon/root");
416
+ var import_root6 = require("@ai-matrx/summon/root");
418
417
  function useOverlayState(name, initial) {
419
- const { instanceKey } = useOverlayInstance();
420
- const dispatch = useSummonDispatch();
421
- const store = useSummonStore();
422
- const stored = useSummonSelector((state) => (0, import_summon6.selectOverlayStateValue)(state, instanceKey, name));
418
+ const { instanceKey } = (0, import_root5.useOverlayInstance)();
419
+ const dispatch = (0, import_root3.useSummonDispatch)();
420
+ const store = (0, import_root3.useSummonStore)();
421
+ const stored = (0, import_root3.useSummonSelector)((state) => (0, import_summon3.selectOverlayStateValue)(state, instanceKey, name));
423
422
  const value = stored === void 0 ? initial : stored;
424
- const setValue = (0, import_react7.useCallback)(
423
+ const setValue = (0, import_react8.useCallback)(
425
424
  (next) => {
426
- const current = (0, import_summon6.selectOverlayStateValue)(store.getState(), instanceKey, name);
425
+ const current = (0, import_summon3.selectOverlayStateValue)(store.getState(), instanceKey, name);
427
426
  const previous = current === void 0 ? initial : current;
428
427
  const resolved = typeof next === "function" ? next(previous) : next;
429
- dispatch((0, import_summon6.setOverlayStateValue)({ key: instanceKey, name, value: resolved }));
428
+ dispatch((0, import_summon3.setOverlayStateValue)({ key: instanceKey, name, value: resolved }));
430
429
  },
431
430
  // `initial` is the first-render default, like useState's; its identity never re-binds.
432
431
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -435,26 +434,6 @@ function useOverlayState(name, initial) {
435
434
  return [value, setValue];
436
435
  }
437
436
 
438
- // src/react/hostRenders.ts
439
- var import_react8 = require("react");
440
- var HostRendersContext = (0, import_react8.createContext)(null);
441
- var MISSING_RENDER_ERROR = "OverlayRenderMissingError";
442
- var missing = /* @__PURE__ */ new Map();
443
- function missingRenderLoader(overlayId) {
444
- let loader = missing.get(overlayId);
445
- if (!loader) {
446
- const message = `Overlay "${overlayId}" is open but has no render module: its definition has no \`render\` and <SummonHost renders> has no "${overlayId}" entry.`;
447
- loader = () => {
448
- if (process.env.NODE_ENV !== "production") console.error(`[summon] ${message}`);
449
- const error = new Error(message);
450
- error.name = MISSING_RENDER_ERROR;
451
- return Promise.reject(error);
452
- };
453
- missing.set(overlayId, loader);
454
- }
455
- return loader;
456
- }
457
-
458
437
  // src/react/instanceBody.tsx
459
438
  var import_jsx_runtime4 = require("react/jsx-runtime");
460
439
  function LazyRender({ overlayId, instanceId, data, hidden, close, render, attemptRef }) {
@@ -467,7 +446,7 @@ function LazyRender({ overlayId, instanceId, data, hidden, close, render, attemp
467
446
  function createInstanceBody(overlayId, label, ownRender, parse, refusable) {
468
447
  function OverlayInstanceBody({ instanceId, instanceKey, data, hidden, close }) {
469
448
  const config = useSummonConfig();
470
- const ports = useSummonPorts();
449
+ const ports = (0, import_root3.useSummonPorts)();
471
450
  const hostRenders = (0, import_react9.useContext)(HostRendersContext);
472
451
  const hostRender = ownRender ? void 0 : hostRenders?.[overlayId];
473
452
  const render = ownRender ?? hostRender ?? missingRenderLoader(overlayId);
@@ -515,110 +494,13 @@ function createInstanceBody(overlayId, label, ownRender, parse, refusable) {
515
494
  ) })
516
495
  }
517
496
  );
518
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(OverlayInstanceContext.Provider, { value: instance, children: config.renderWrapper ? config.renderWrapper(body, context) : body });
497
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_root6.OverlayInstanceContext.Provider, { value: instance, children: config.renderWrapper ? config.renderWrapper(body, context) : body });
519
498
  }
520
499
  OverlayInstanceBody.displayName = `Overlay(${overlayId})`;
521
500
  return (0, import_react9.memo)(OverlayInstanceBody);
522
501
  }
523
502
 
524
- // src/react/defineOverlay.tsx
525
- var CALLBACK_GROUP_KEY = "callbackGroupId";
526
- function openWith(dispatch, id, multi, options) {
527
- const instanceId = options?.instanceId ?? (multi ? newInstanceId(id) : import_summon7.DEFAULT_INSTANCE_ID);
528
- const key = (0, import_summon7.instanceKey)(id, instanceId);
529
- const data = {};
530
- const given = options?.data;
531
- if (typeof given === "object" && given !== null) Object.assign(data, given);
532
- const handlers = options?.handlers;
533
- if (handlers) data[CALLBACK_GROUP_KEY] = openOverlayEventChannel(key, () => handlers);
534
- dispatchOpen(dispatch, id, instanceId, data);
535
- return { overlayId: id, instanceId, close: () => dispatchClose(dispatch, id, instanceId) };
536
- }
537
- function dataSignature(data) {
538
- try {
539
- return JSON.stringify(data, (_key, value) => typeof value === "function" ? void 0 : value);
540
- } catch {
541
- return String(Date.now());
542
- }
543
- }
544
- function defineOverlay() {
545
- return function define(spec) {
546
- const id = spec.id;
547
- const multi = spec.instance === "multi";
548
- const parse = spec.parse ?? ((raw) => raw);
549
- const Body = createInstanceBody(id, spec.label, spec.render, parse, spec.parse !== void 0);
550
- const meta = spec;
551
- function useSummon() {
552
- const dispatch = useSummonDispatch();
553
- return (0, import_react10.useCallback)((options) => openWith(dispatch, id, multi, options), [dispatch]);
554
- }
555
- function useIsOpen(instanceId = import_summon7.DEFAULT_INSTANCE_ID) {
556
- return useSummonSelector((state) => (0, import_summon8.selectIsOverlayOpen)(state, id, instanceId));
557
- }
558
- function useClose() {
559
- const dispatch = useSummonDispatch();
560
- return (0, import_react10.useCallback)((instanceId) => dispatchClose(dispatch, id, instanceId ?? import_summon7.DEFAULT_INSTANCE_ID), [dispatch]);
561
- }
562
- function useEmit() {
563
- const instance = useOptionalOverlayInstance();
564
- const channelId = instance?.overlayId === id ? instance.rawData?.[CALLBACK_GROUP_KEY] : void 0;
565
- return (0, import_react10.useCallback)(
566
- (event, payload) => {
567
- if (typeof channelId === "string") emitOverlayEvent(channelId, event, payload);
568
- },
569
- [channelId]
570
- );
571
- }
572
- function Controller(props) {
573
- const dispatch = useSummonDispatch();
574
- const [ownInstanceId] = (0, import_react10.useState)(() => multi ? newInstanceId(id) : import_summon7.DEFAULT_INSTANCE_ID);
575
- const instanceId = props.instanceId ?? ownInstanceId;
576
- const handlersRef = (0, import_react10.useRef)(props.handlers);
577
- handlersRef.current = props.handlers;
578
- const hasHandlers = props.handlers !== void 0;
579
- const data = (0, import_react10.useMemo)(() => {
580
- const out = {};
581
- for (const [key, value] of Object.entries(props)) {
582
- if (key !== "instanceId" && key !== "handlers") out[key] = value;
583
- }
584
- return out;
585
- }, [props]);
586
- const signature = dataSignature(data);
587
- const dataRef = (0, import_react10.useRef)(data);
588
- dataRef.current = data;
589
- (0, import_react10.useEffect)(() => {
590
- const key = (0, import_summon7.instanceKey)(id, instanceId);
591
- const open = { ...dataRef.current };
592
- if (hasHandlers) open[CALLBACK_GROUP_KEY] = openOverlayEventChannel(key, () => handlersRef.current);
593
- dispatchOpen(dispatch, id, instanceId, open);
594
- return () => dispatchClose(dispatch, id, instanceId);
595
- }, [dispatch, instanceId, signature, hasHandlers]);
596
- return null;
597
- }
598
- Controller.displayName = `${id}Controller`;
599
- return {
600
- ...spec,
601
- id,
602
- label: spec.label,
603
- instance: multi ? "multi" : "single",
604
- keepAlive: spec.keepAlive ?? "none",
605
- meta,
606
- Body,
607
- useSummon,
608
- Controller,
609
- useIsOpen,
610
- useClose,
611
- useEmit
612
- };
613
- };
614
- }
615
-
616
503
  // src/react/SummonHost.tsx
617
- var import_react11 = require("react");
618
- var import_summon9 = require("@ai-matrx/summon");
619
- var import_summon10 = require("@ai-matrx/summon");
620
- var import_summon11 = require("@ai-matrx/summon");
621
- var import_summon12 = require("@ai-matrx/summon");
622
504
  var import_jsx_runtime5 = require("react/jsx-runtime");
623
505
  function asRawData(data) {
624
506
  return typeof data === "object" && data !== null && !Array.isArray(data) ? data : null;
@@ -633,35 +515,46 @@ function sameInstances(a, b) {
633
515
  }
634
516
  return true;
635
517
  }
518
+ var bodies = /* @__PURE__ */ new WeakMap();
519
+ function bodyOf(definition) {
520
+ let body = bodies.get(definition);
521
+ if (!body) {
522
+ const parse = definition.parse ?? ((raw) => raw);
523
+ const render = definition.render;
524
+ body = createInstanceBody(definition.id, definition.label, render, parse, definition.parse !== void 0);
525
+ bodies.set(definition, body);
526
+ }
527
+ return body;
528
+ }
636
529
  var NO_RETAINED = /* @__PURE__ */ new Map();
637
530
  function useCloseOnNavigation() {
638
- const ports = useSummonPorts();
639
- const dispatch = useSummonDispatch();
640
- (0, import_react11.useEffect)(() => {
531
+ const ports = (0, import_root3.useSummonPorts)();
532
+ const dispatch = (0, import_root3.useSummonDispatch)();
533
+ (0, import_react10.useEffect)(() => {
641
534
  const router = ports.router;
642
535
  let previous = router.pathname();
643
536
  return router.subscribe(() => {
644
537
  const next = router.pathname();
645
538
  if (next === previous) return;
646
539
  previous = next;
647
- const overlayIds = (0, import_summon11.overlayIdsBoundToPage)();
648
- if (overlayIds.length > 0) dispatch((0, import_summon11.closeOverlaysBoundToPage)({ overlayIds }));
540
+ const overlayIds = (0, import_summon6.overlayIdsBoundToPage)();
541
+ if (overlayIds.length > 0) dispatch((0, import_summon6.closeOverlaysBoundToPage)({ overlayIds }));
649
542
  });
650
543
  }, [ports, dispatch]);
651
544
  }
652
- var InstanceSlot = (0, import_react11.memo)(function InstanceSlot2({ definition, instanceId, data, hidden }) {
653
- const dispatch = useSummonDispatch();
654
- const close = (0, import_react11.useCallback)(() => dispatchClose(dispatch, definition.id, instanceId), [dispatch, definition.id, instanceId]);
655
- const Body = definition.Body;
656
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Body, { instanceId, instanceKey: (0, import_summon12.instanceKey)(definition.id, instanceId), data, hidden, close });
545
+ var InstanceSlot = (0, import_react10.memo)(function InstanceSlot2({ definition, instanceId, data, hidden }) {
546
+ const dispatch = (0, import_root3.useSummonDispatch)();
547
+ const close = (0, import_react10.useCallback)(() => (0, import_root7.dispatchClose)(dispatch, definition.id, instanceId), [dispatch, definition.id, instanceId]);
548
+ const Body = bodyOf(definition);
549
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Body, { instanceId, instanceKey: (0, import_summon7.instanceKey)(definition.id, instanceId), data, hidden, close });
657
550
  });
658
- var DefinitionSlot = (0, import_react11.memo)(function DefinitionSlot2({ definition }) {
551
+ var DefinitionSlot = (0, import_react10.memo)(function DefinitionSlot2({ definition }) {
659
552
  const { keepAlive } = useSummonConfig();
660
- const dispatch = useSummonDispatch();
661
- const open = useSummonSelector((state) => (0, import_summon11.selectOpenInstances)(state, definition.id), sameInstances);
553
+ const dispatch = (0, import_root3.useSummonDispatch)();
554
+ const open = (0, import_root3.useSummonSelector)((state) => (0, import_summon6.selectOpenInstances)(state, definition.id), sameInstances);
662
555
  const keepHidden = definition.keepAlive === "hidden";
663
- const [retained, setRetained] = (0, import_react11.useState)(NO_RETAINED);
664
- const [previousOpen, setPreviousOpen] = (0, import_react11.useState)(open);
556
+ const [retained, setRetained] = (0, import_react10.useState)(NO_RETAINED);
557
+ const [previousOpen, setPreviousOpen] = (0, import_react10.useState)(open);
665
558
  if (previousOpen !== open) {
666
559
  setPreviousOpen(open);
667
560
  if (keepHidden) {
@@ -674,16 +567,16 @@ var DefinitionSlot = (0, import_react11.memo)(function DefinitionSlot2({ definit
674
567
  setRetained(next);
675
568
  }
676
569
  }
677
- const registered = (0, import_react11.useRef)(/* @__PURE__ */ new Set());
678
- (0, import_react11.useEffect)(() => {
570
+ const registered = (0, import_react10.useRef)(/* @__PURE__ */ new Set());
571
+ (0, import_react10.useEffect)(() => {
679
572
  const seen = registered.current;
680
573
  for (const instanceId of retained.keys()) {
681
574
  if (seen.has(instanceId)) continue;
682
575
  seen.add(instanceId);
683
- const key = (0, import_summon12.instanceKey)(definition.id, instanceId);
576
+ const key = (0, import_summon7.instanceKey)(definition.id, instanceId);
684
577
  keepAlive.retain(key, () => {
685
578
  seen.delete(instanceId);
686
- (0, import_summon9.releaseOverlayInstance)(dispatch, key);
579
+ (0, import_summon4.releaseOverlayInstance)(dispatch, key);
687
580
  setRetained((current) => {
688
581
  if (!current.has(instanceId)) return current;
689
582
  const next = new Map(current);
@@ -695,16 +588,16 @@ var DefinitionSlot = (0, import_react11.memo)(function DefinitionSlot2({ definit
695
588
  for (const instanceId of [...seen]) {
696
589
  if (retained.has(instanceId)) continue;
697
590
  seen.delete(instanceId);
698
- keepAlive.release((0, import_summon12.instanceKey)(definition.id, instanceId));
591
+ keepAlive.release((0, import_summon7.instanceKey)(definition.id, instanceId));
699
592
  }
700
593
  }, [retained, keepAlive, definition.id, dispatch]);
701
- (0, import_react11.useEffect)(() => {
594
+ (0, import_react10.useEffect)(() => {
702
595
  const seen = registered.current;
703
596
  return () => {
704
597
  for (const instanceId of seen) {
705
- const key = (0, import_summon12.instanceKey)(definition.id, instanceId);
598
+ const key = (0, import_summon7.instanceKey)(definition.id, instanceId);
706
599
  keepAlive.release(key);
707
- (0, import_summon9.releaseOverlayInstance)(dispatch, key);
600
+ (0, import_summon4.releaseOverlayInstance)(dispatch, key);
708
601
  }
709
602
  seen.clear();
710
603
  };
@@ -714,67 +607,71 @@ var DefinitionSlot = (0, import_react11.memo)(function DefinitionSlot2({ definit
714
607
  for (const instance of open) {
715
608
  const node = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(InstanceSlot, { definition, instanceId: instance.instanceId, data: asRawData(instance.data), hidden: false }, instance.instanceId);
716
609
  nodes.push(
717
- keepHidden ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react11.Activity, { mode: "visible", children: node }, instance.instanceId) : node
610
+ keepHidden ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react10.Activity, { mode: "visible", children: node }, instance.instanceId) : node
718
611
  );
719
612
  }
720
613
  if (keepHidden) {
721
614
  for (const [instanceId, data] of retained) {
722
615
  nodes.push(
723
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react11.Activity, { mode: "hidden", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(InstanceSlot, { definition, instanceId, data, hidden: true }, instanceId) }, instanceId)
616
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react10.Activity, { mode: "hidden", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(InstanceSlot, { definition, instanceId, data, hidden: true }, instanceId) }, instanceId)
724
617
  );
725
618
  }
726
619
  }
727
620
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: nodes });
728
621
  });
729
622
  function SummonHost({ definitions, renders }) {
730
- const registeredFor = (0, import_react11.useRef)(null);
623
+ const registeredFor = (0, import_react10.useRef)(null);
731
624
  if (registeredFor.current !== definitions) {
732
- (0, import_summon10.registerOverlayMeta)(definitions.map((definition) => definition.meta));
625
+ (0, import_summon5.registerOverlayMeta)(definitions.map((definition) => definition.meta));
733
626
  registeredFor.current = definitions;
734
627
  }
735
628
  useCloseOnNavigation();
736
629
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(HostRendersContext.Provider, { value: renders ?? null, children: definitions.map((definition) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(DefinitionSlot, { definition }, definition.id)) });
737
630
  }
738
631
 
632
+ // src/react.ts
633
+ var import_root10 = require("@ai-matrx/summon/root");
634
+
739
635
  // src/react/hooks.ts
740
- var import_react12 = require("react");
741
- var import_summon13 = require("@ai-matrx/summon");
742
- var import_summon14 = require("@ai-matrx/summon");
743
- var import_summon15 = require("@ai-matrx/summon");
744
- function useIsOverlayOpen(overlayId, instanceId = import_summon15.DEFAULT_INSTANCE_ID) {
745
- return useSummonSelector((state) => (0, import_summon14.selectIsOverlayOpen)(state, overlayId, instanceId));
636
+ var import_react11 = require("react");
637
+ var import_summon8 = require("@ai-matrx/summon");
638
+ var import_summon9 = require("@ai-matrx/summon");
639
+ var import_summon10 = require("@ai-matrx/summon");
640
+ var import_root8 = require("@ai-matrx/summon/root");
641
+ function useIsOverlayOpen(overlayId, instanceId = import_summon10.DEFAULT_INSTANCE_ID) {
642
+ return (0, import_root3.useSummonSelector)((state) => (0, import_summon9.selectIsOverlayOpen)(state, overlayId, instanceId));
746
643
  }
747
644
  function useOpenOverlay(overlayId) {
748
- const dispatch = useSummonDispatch();
749
- return (0, import_react12.useCallback)(
645
+ const dispatch = (0, import_root3.useSummonDispatch)();
646
+ return (0, import_react11.useCallback)(
750
647
  (options) => {
751
- const multi = (0, import_summon13.getOverlayMeta)(overlayId)?.instance === "multi";
752
- const instanceId = options?.instanceId ?? (multi ? newInstanceId(overlayId) : import_summon15.DEFAULT_INSTANCE_ID);
753
- dispatchOpen(dispatch, overlayId, instanceId, options?.data ?? null);
754
- return { overlayId, instanceId, close: () => dispatchClose(dispatch, overlayId, instanceId) };
648
+ const multi = (0, import_summon8.getOverlayMeta)(overlayId)?.instance === "multi";
649
+ const instanceId = options?.instanceId ?? (multi ? (0, import_root8.newInstanceId)(overlayId) : import_summon10.DEFAULT_INSTANCE_ID);
650
+ (0, import_root8.dispatchOpen)(dispatch, overlayId, instanceId, options?.data ?? null);
651
+ return { overlayId, instanceId, close: () => (0, import_root8.dispatchClose)(dispatch, overlayId, instanceId) };
755
652
  },
756
653
  [dispatch, overlayId]
757
654
  );
758
655
  }
759
- function useCloseOverlay(overlayId, instanceId = import_summon15.DEFAULT_INSTANCE_ID) {
760
- const dispatch = useSummonDispatch();
761
- return (0, import_react12.useCallback)(() => dispatchClose(dispatch, overlayId, instanceId), [dispatch, overlayId, instanceId]);
656
+ function useCloseOverlay(overlayId, instanceId = import_summon10.DEFAULT_INSTANCE_ID) {
657
+ const dispatch = (0, import_root3.useSummonDispatch)();
658
+ return (0, import_react11.useCallback)(() => (0, import_root8.dispatchClose)(dispatch, overlayId, instanceId), [dispatch, overlayId, instanceId]);
762
659
  }
763
660
 
764
661
  // src/react/useOverlayLink.ts
765
- var import_react13 = require("react");
766
- var import_summon16 = require("@ai-matrx/summon");
662
+ var import_react12 = require("react");
663
+ var import_summon11 = require("@ai-matrx/summon");
767
664
  function useOverlayLink(linkKey, id, args) {
768
- const dispatch = useSummonDispatch();
665
+ const dispatch = (0, import_root3.useSummonDispatch)();
769
666
  const argsKey = args ? JSON.stringify(
770
667
  Object.keys(args).sort().map((k) => [k, args[k]])
771
668
  ) : "";
772
- const stableArgs = (0, import_react13.useMemo)(() => args ? { ...args } : void 0, [argsKey]);
773
- (0, import_react13.useEffect)(() => {
669
+ const stableArgs = (0, import_react12.useMemo)(() => args ? { ...args } : void 0, [argsKey]);
670
+ (0, import_react12.useEffect)(() => {
774
671
  if (!linkKey || !id) return void 0;
775
- dispatch((0, import_summon16.registerSyncEntry)(stableArgs ? { typeKey: linkKey, instanceId: id, args: stableArgs } : { typeKey: linkKey, instanceId: id }));
672
+ dispatch((0, import_summon11.registerSyncEntry)(stableArgs ? { typeKey: linkKey, instanceId: id, args: stableArgs } : { typeKey: linkKey, instanceId: id }));
776
673
  return () => {
777
- dispatch((0, import_summon16.unregisterSyncEntry)({ typeKey: linkKey, instanceId: id }));
674
+ dispatch((0, import_summon11.unregisterSyncEntry)({ typeKey: linkKey, instanceId: id }));
778
675
  };
779
676
  }, [dispatch, linkKey, id, stableArgs]);
780
677
  }