@ai-matrx/alchemy 0.6.2 → 0.8.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.
Files changed (113) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/dist/actions.cjs +374 -0
  3. package/dist/actions.cjs.map +1 -0
  4. package/dist/actions.d.cts +773 -0
  5. package/dist/actions.d.ts +773 -0
  6. package/dist/actions.js +351 -0
  7. package/dist/actions.js.map +1 -0
  8. package/dist/checks.cjs +31 -2
  9. package/dist/checks.cjs.map +1 -1
  10. package/dist/checks.d.cts +24 -1
  11. package/dist/checks.d.ts +24 -1
  12. package/dist/checks.js +31 -2
  13. package/dist/checks.js.map +1 -1
  14. package/dist/core.cjs +1757 -2
  15. package/dist/core.cjs.map +1 -1
  16. package/dist/core.d.cts +595 -1
  17. package/dist/core.d.ts +595 -1
  18. package/dist/core.js +1749 -2
  19. package/dist/core.js.map +1 -1
  20. package/dist/declare.cjs +12 -10
  21. package/dist/declare.cjs.map +1 -1
  22. package/dist/declare.d.cts +18 -2
  23. package/dist/declare.d.ts +18 -2
  24. package/dist/declare.js +12 -10
  25. package/dist/declare.js.map +1 -1
  26. package/dist/index.cjs +1757 -2
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +595 -1
  29. package/dist/index.d.ts +595 -1
  30. package/dist/index.js +1749 -2
  31. package/dist/index.js.map +1 -1
  32. package/dist/menu.cjs +436 -0
  33. package/dist/menu.cjs.map +1 -0
  34. package/dist/menu.d.cts +834 -0
  35. package/dist/menu.d.ts +834 -0
  36. package/dist/menu.js +413 -0
  37. package/dist/menu.js.map +1 -0
  38. package/dist/operate-document.cjs +163 -0
  39. package/dist/operate-document.cjs.map +1 -0
  40. package/dist/operate-document.d.cts +132 -0
  41. package/dist/operate-document.d.ts +132 -0
  42. package/dist/operate-document.js +130 -0
  43. package/dist/operate-document.js.map +1 -0
  44. package/dist/operate-rich-html.cjs +129 -0
  45. package/dist/operate-rich-html.cjs.map +1 -0
  46. package/dist/operate-rich-html.d.cts +136 -0
  47. package/dist/operate-rich-html.d.ts +136 -0
  48. package/dist/operate-rich-html.js +96 -0
  49. package/dist/operate-rich-html.js.map +1 -0
  50. package/dist/operate-server.cjs +157 -0
  51. package/dist/operate-server.cjs.map +1 -0
  52. package/dist/operate-server.d.cts +183 -0
  53. package/dist/operate-server.d.ts +183 -0
  54. package/dist/operate-server.js +134 -0
  55. package/dist/operate-server.js.map +1 -0
  56. package/dist/operate-xlsx.cjs +248 -0
  57. package/dist/operate-xlsx.cjs.map +1 -0
  58. package/dist/operate-xlsx.d.cts +129 -0
  59. package/dist/operate-xlsx.d.ts +129 -0
  60. package/dist/operate-xlsx.js +215 -0
  61. package/dist/operate-xlsx.js.map +1 -0
  62. package/dist/operate.cjs +1774 -0
  63. package/dist/operate.cjs.map +1 -0
  64. package/dist/operate.d.cts +595 -0
  65. package/dist/operate.d.ts +595 -0
  66. package/dist/operate.js +1750 -0
  67. package/dist/operate.js.map +1 -0
  68. package/dist/ports.cjs.map +1 -1
  69. package/dist/ports.d.cts +361 -3
  70. package/dist/ports.d.ts +361 -3
  71. package/dist/react-bar.cjs +686 -0
  72. package/dist/react-bar.cjs.map +1 -0
  73. package/dist/react-bar.d.cts +379 -0
  74. package/dist/react-bar.d.ts +379 -0
  75. package/dist/react-bar.js +665 -0
  76. package/dist/react-bar.js.map +1 -0
  77. package/dist/react-host.cjs +301 -0
  78. package/dist/react-host.cjs.map +1 -0
  79. package/dist/react-host.d.cts +820 -0
  80. package/dist/react-host.d.ts +820 -0
  81. package/dist/react-host.js +269 -0
  82. package/dist/react-host.js.map +1 -0
  83. package/dist/react-menu.cjs +735 -0
  84. package/dist/react-menu.cjs.map +1 -0
  85. package/dist/react-menu.d.cts +370 -0
  86. package/dist/react-menu.d.ts +370 -0
  87. package/dist/react-menu.js +722 -0
  88. package/dist/react-menu.js.map +1 -0
  89. package/dist/react-overflow.cjs +592 -0
  90. package/dist/react-overflow.cjs.map +1 -0
  91. package/dist/react-overflow.d.cts +817 -0
  92. package/dist/react-overflow.d.ts +817 -0
  93. package/dist/react-overflow.js +571 -0
  94. package/dist/react-overflow.js.map +1 -0
  95. package/dist/react-palette.cjs +489 -0
  96. package/dist/react-palette.cjs.map +1 -0
  97. package/dist/react-palette.d.cts +359 -0
  98. package/dist/react-palette.d.ts +359 -0
  99. package/dist/react-palette.js +457 -0
  100. package/dist/react-palette.js.map +1 -0
  101. package/dist/react-selection.cjs +617 -0
  102. package/dist/react-selection.cjs.map +1 -0
  103. package/dist/react-selection.d.cts +357 -0
  104. package/dist/react-selection.d.ts +357 -0
  105. package/dist/react-selection.js +596 -0
  106. package/dist/react-selection.js.map +1 -0
  107. package/dist/react-sheet.cjs +616 -0
  108. package/dist/react-sheet.cjs.map +1 -0
  109. package/dist/react-sheet.d.cts +361 -0
  110. package/dist/react-sheet.d.ts +361 -0
  111. package/dist/react-sheet.js +595 -0
  112. package/dist/react-sheet.js.map +1 -0
  113. package/package.json +148 -5
@@ -0,0 +1,571 @@
1
+ "use client";
2
+
3
+ // src/react/overflow.tsx
4
+ import * as React4 from "react";
5
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger, TooltipProvider } from "@ai-matrx/design-system";
6
+
7
+ // src/menu/layouts.ts
8
+ var INLINE_SECTION_MAX = 3;
9
+ function sectionLabel(section) {
10
+ return section.label ?? null;
11
+ }
12
+ function fold(section) {
13
+ return {
14
+ kind: "submenu",
15
+ id: `${section.id}:fold`,
16
+ label: section.label,
17
+ ...section.icon !== void 0 ? { icon: section.icon } : {},
18
+ children: section.nodes
19
+ };
20
+ }
21
+ function rowCount(nodes) {
22
+ return nodes.filter((n) => n.kind !== "separator" && n.kind !== "label").length;
23
+ }
24
+ function foldNamed(sections) {
25
+ return sections.map(
26
+ (s) => s.label && !s.primary && rowCount(s.nodes) > INLINE_SECTION_MAX ? { id: s.id, group: s.group, nodes: [fold({ ...s, label: s.label })] } : s
27
+ );
28
+ }
29
+ function overflow(model) {
30
+ return foldNamed(model.sections);
31
+ }
32
+
33
+ // src/react/engine.tsx
34
+ import * as React2 from "react";
35
+
36
+ // src/declare/sensitivity.ts
37
+ var DEFAULT_SENSITIVITY = Object.freeze({
38
+ exportable: true,
39
+ classification: "ordinary",
40
+ includedByDefault: true
41
+ });
42
+ function resolveSensitivity(value) {
43
+ return {
44
+ exportable: value.sensitivity?.exportable ?? DEFAULT_SENSITIVITY.exportable,
45
+ classification: value.sensitivity?.classification ?? DEFAULT_SENSITIVITY.classification,
46
+ includedByDefault: value.sensitivity?.includedByDefault ?? DEFAULT_SENSITIVITY.includedByDefault
47
+ };
48
+ }
49
+
50
+ // src/actions/projection.ts
51
+ function toJson(value) {
52
+ if (value === void 0 || typeof value === "function" || typeof value === "symbol") return void 0;
53
+ if (value === null || typeof value === "string" || typeof value === "boolean") return value;
54
+ if (typeof value === "number") return Number.isFinite(value) ? value : null;
55
+ if (typeof value === "bigint") return value.toString();
56
+ if (value instanceof Date) return value.toISOString();
57
+ if (Array.isArray(value)) return value.map((v) => toJson(v) ?? null);
58
+ if (typeof value === "object") {
59
+ const out = {};
60
+ for (const [k, v] of Object.entries(value)) {
61
+ const j = toJson(v);
62
+ if (j !== void 0) out[k] = j;
63
+ }
64
+ return out;
65
+ }
66
+ return void 0;
67
+ }
68
+ function projectValues(raw, declared, pathPrefix = "") {
69
+ const byName = new Map(declared.map((d) => [d.name, d]));
70
+ const values = {};
71
+ const omissions = [];
72
+ for (const [name, value] of Object.entries(raw)) {
73
+ const path = pathPrefix ? `${pathPrefix}.${name}` : name;
74
+ const decl = byName.get(name);
75
+ if (!decl) {
76
+ omissions.push({ path, reason: "filtered" });
77
+ continue;
78
+ }
79
+ const sensitivity = resolveSensitivity(decl);
80
+ if (sensitivity.classification !== "ordinary") {
81
+ omissions.push({ path, reason: "excluded", classification: sensitivity.classification });
82
+ continue;
83
+ }
84
+ if (!sensitivity.exportable) {
85
+ omissions.push({ path, reason: "excluded" });
86
+ continue;
87
+ }
88
+ const json = toJson(value);
89
+ if (json === void 0) continue;
90
+ values[name] = json;
91
+ }
92
+ return { values, omissions };
93
+ }
94
+ function createProjectedReads(source) {
95
+ return {
96
+ async values(signal) {
97
+ if (!source.surface || !source.declaration) return { values: {}, omissions: [] };
98
+ const raw = await source.surface.readValues(signal);
99
+ const screenValues = source.declaration.values;
100
+ return projectValues(raw, screenValues);
101
+ },
102
+ async item(signal) {
103
+ const item = source.item;
104
+ if (!item || !source.declaration) return null;
105
+ const type = source.declaration.itemTypes?.find((t) => t.name === item.itemType);
106
+ if (!type) return { values: {}, omissions: [{ path: item.itemType, reason: "filtered" }] };
107
+ const raw = await item.readValues(signal);
108
+ return projectValues(raw, type.values, item.itemType);
109
+ },
110
+ async live(signal) {
111
+ if (!source.surface?.readLive) return {};
112
+ return source.surface.readLive(signal);
113
+ }
114
+ };
115
+ }
116
+
117
+ // src/actions/run.ts
118
+ async function runAction(action, target, options) {
119
+ const { ports } = options;
120
+ if (action.requiresAuth && !target.auth.authenticated) {
121
+ if (!ports.auth) {
122
+ ports.diagnostics.capture(new Error(`requiresAuth action "${action.id}" ran signed out with no auth port`), {
123
+ area: "actions",
124
+ detail: { actionId: action.id }
125
+ });
126
+ return { status: "failed", error: new Error("sign-in unavailable") };
127
+ }
128
+ ports.auth.signInThenResume({ actionId: action.id, contentFingerprint: options.contentFingerprint ?? action.id });
129
+ return { status: "auth-pending" };
130
+ }
131
+ const reads = createProjectedReads(options.source ?? { surface: null, declaration: target.declaration, item: null });
132
+ const signal = options.signal ?? new AbortController().signal;
133
+ try {
134
+ const outcome = await action.run(target, { reads, ports, signal });
135
+ return { status: "ran", outcome };
136
+ } catch (error) {
137
+ ports.diagnostics.capture(error, { area: "actions", detail: { actionId: action.id, stage: "run" } });
138
+ const label = typeof action.label === "string" ? action.label : action.id;
139
+ ports.notify?.error(`${label} did not finish.`, "Try again; if it keeps failing, report it from the feedback button.");
140
+ return { status: "failed", error };
141
+ }
142
+ }
143
+
144
+ // src/menu/model.ts
145
+ var CATEGORY_GROUP = {
146
+ clipboard: "clipboard",
147
+ copy: "transfer",
148
+ export: "transfer",
149
+ save: "document",
150
+ share: "document",
151
+ edit: "editable",
152
+ history: "history",
153
+ ai: "ai",
154
+ ask: "ai",
155
+ listen: "tools",
156
+ study: "tools",
157
+ app: "tools",
158
+ feedback: "quick",
159
+ creator: "admin",
160
+ admin: "admin",
161
+ "surface-info": "surface-info"
162
+ };
163
+ var GROUP_ORDER = [
164
+ "clipboard",
165
+ "editable",
166
+ "transfer",
167
+ "document",
168
+ "history",
169
+ "ai",
170
+ "tools",
171
+ "quick",
172
+ "surface",
173
+ "admin",
174
+ "surface-info"
175
+ ];
176
+ var CATEGORY_ORDER = [
177
+ "clipboard",
178
+ "edit",
179
+ "copy",
180
+ "export",
181
+ "save",
182
+ "share",
183
+ "history",
184
+ "ask",
185
+ "ai",
186
+ "listen",
187
+ "study",
188
+ "app",
189
+ "feedback",
190
+ "creator",
191
+ "admin",
192
+ "surface-info"
193
+ ];
194
+ function translate(i18n, key, fallback) {
195
+ if (!i18n) return fallback;
196
+ try {
197
+ return i18n.t(key, fallback);
198
+ } catch {
199
+ return fallback;
200
+ }
201
+ }
202
+ function actionToNode(resolved, target, options = {}) {
203
+ const { action, eligibility } = resolved;
204
+ const rawLabel = typeof action.label === "function" ? action.label(target) : action.label;
205
+ const label = translate(options.i18n, action.labelKey ?? action.id, rawLabel);
206
+ const base = {
207
+ id: action.id,
208
+ actionId: action.id,
209
+ ...action.icon !== void 0 ? { icon: action.icon } : {},
210
+ ...action.placement !== void 0 ? { placement: action.placement } : {}
211
+ };
212
+ if (action.expand) {
213
+ const node = {
214
+ ...base,
215
+ kind: "submenu",
216
+ label,
217
+ lazy: true,
218
+ loading: false,
219
+ children: [],
220
+ ...action.emptyLabel !== void 0 ? { emptyLabel: action.emptyLabel } : {}
221
+ };
222
+ return node;
223
+ }
224
+ if (action.href !== void 0) {
225
+ const href = typeof action.href === "function" ? action.href(target) : action.href;
226
+ return { ...base, kind: "link", label, href };
227
+ }
228
+ if (action.toggle) {
229
+ return {
230
+ ...base,
231
+ kind: "checkbox",
232
+ label,
233
+ checked: action.pressed?.(target) ?? false,
234
+ ...action.description !== void 0 ? { description: action.description } : {}
235
+ };
236
+ }
237
+ const state = action.stateIcon?.(target) ?? null;
238
+ const pressed = action.pressed?.(target);
239
+ const hint = action.hint !== void 0 ? translate(options.i18n, action.hintKey ?? `${action.id}.hint`, action.hint) : void 0;
240
+ return {
241
+ ...base,
242
+ kind: "item",
243
+ label,
244
+ ...action.iconTone !== void 0 ? { iconTone: action.iconTone } : {},
245
+ ...state ? { stateIcon: state } : {},
246
+ ...action.description !== void 0 ? { description: action.description } : {},
247
+ ...hint !== void 0 ? { hint } : {},
248
+ ...pressed !== void 0 ? { pressed } : {},
249
+ ...action.destructive ? { destructive: true } : {},
250
+ ...action.preserveSelection ? { preserveSelection: true } : {},
251
+ ...eligibility.status === "unavailable-verb" ? { unavailable: { sentence: eligibility.sentence } } : {}
252
+ };
253
+ }
254
+ function buildMenuModel(target, resolved, options = {}) {
255
+ const ordered = resolved.map((r, index) => ({ r, index })).sort((a, b) => {
256
+ const ca = CATEGORY_ORDER.indexOf(a.r.action.category);
257
+ const cb = CATEGORY_ORDER.indexOf(b.r.action.category);
258
+ if (ca !== cb) return ca - cb;
259
+ const oa = a.r.action.order ?? 0;
260
+ const ob = b.r.action.order ?? 0;
261
+ if (oa !== ob) return oa - ob;
262
+ return a.index - b.index;
263
+ }).map((x) => x.r);
264
+ const sections = /* @__PURE__ */ new Map();
265
+ const roles = {};
266
+ const explicit = /* @__PURE__ */ new Map();
267
+ resolved.forEach((r, index) => {
268
+ const sec = r.action.section;
269
+ if (!sec) return;
270
+ const entry = explicit.get(sec.id) ?? { group: CATEGORY_GROUP[r.action.category], rows: [] };
271
+ entry.rows.push({ r, index });
272
+ explicit.set(sec.id, entry);
273
+ });
274
+ const placed = /* @__PURE__ */ new Set();
275
+ for (const r of ordered) {
276
+ const sec = r.action.section;
277
+ if (sec && placed.has(sec.id)) continue;
278
+ const group = sec ? explicit.get(sec.id)?.group ?? CATEGORY_GROUP[r.action.category] : CATEGORY_GROUP[r.action.category];
279
+ const sectionId = sec ? `section:${sec.id}` : group;
280
+ let section = sections.get(sectionId);
281
+ if (!section) {
282
+ section = {
283
+ id: sectionId,
284
+ group,
285
+ nodes: [],
286
+ ...sec ? { label: translate(options.i18n, sec.labelKey ?? `section.${sec.id}`, sec.label) } : {},
287
+ ...sec?.icon !== void 0 ? { icon: sec.icon } : {},
288
+ ...sec?.primary ? { primary: true } : {}
289
+ };
290
+ sections.set(sectionId, section);
291
+ }
292
+ const rows = sec ? (explicit.get(sec.id)?.rows ?? []).sort((x, y) => (x.r.action.order ?? 0) - (y.r.action.order ?? 0) || x.index - y.index).map((x) => x.r) : [r];
293
+ if (sec) placed.add(sec.id);
294
+ for (const row of rows) {
295
+ section.nodes.push(actionToNode(row, target, options));
296
+ if (row.action.verb) roles[row.action.verb] = row.action.id;
297
+ }
298
+ }
299
+ const list = [...sections.values()].sort((a, b) => {
300
+ if (Boolean(a.primary) !== Boolean(b.primary)) return a.primary ? -1 : 1;
301
+ return GROUP_ORDER.indexOf(a.group) - GROUP_ORDER.indexOf(b.group);
302
+ });
303
+ const selected = target.selection?.text?.trim();
304
+ const content = options.content?.trim();
305
+ const header = selected ? { label: "Selected", text: target.selection?.text ?? "" } : content ? { label: "Content", text: options.content ?? "" } : null;
306
+ return { header, sections: list, roles };
307
+ }
308
+ function withExpandedChildren(model, nodeId, children) {
309
+ const visit = (nodes) => nodes.map((n) => {
310
+ if (n.kind !== "submenu") return n;
311
+ if (n.id === nodeId) {
312
+ return children === "loading" ? { ...n, loading: true } : { ...n, lazy: false, loading: false, children };
313
+ }
314
+ return { ...n, children: visit(n.children) };
315
+ });
316
+ return { ...model, sections: model.sections.map((s) => ({ ...s, nodes: visit(s.nodes) })) };
317
+ }
318
+ function findNode(nodes, id) {
319
+ for (const n of nodes) {
320
+ if (n.id === id) return n;
321
+ if (n.kind === "submenu") {
322
+ const hit = findNode(n.children, id);
323
+ if (hit) return hit;
324
+ }
325
+ }
326
+ return null;
327
+ }
328
+
329
+ // src/react/context.ts
330
+ import * as React from "react";
331
+ var KEY = /* @__PURE__ */ Symbol.for("ai-matrx.alchemy.actions-context");
332
+ var AlchemyActionsContext = globalThis[KEY] ??= React.createContext(null);
333
+ function useAlchemyActions() {
334
+ const value = React.useContext(AlchemyActionsContext);
335
+ if (!value) throw new Error("Alchemy actions: render inside <AlchemyActionsProvider> (@ai-matrx/alchemy/react/host).");
336
+ return value;
337
+ }
338
+
339
+ // src/react/engine.tsx
340
+ import { jsx } from "react/jsx-runtime";
341
+ function useMenuEngine(target, options = {}) {
342
+ const { registry, ports } = useAlchemyActions();
343
+ const [resolved, setResolved] = React2.useState([]);
344
+ const [model, setModel] = React2.useState(null);
345
+ const [tick, setTick] = React2.useState(0);
346
+ const expanded = React2.useRef(/* @__PURE__ */ new Map());
347
+ const active = options.active ?? true;
348
+ const optionsRef = React2.useRef(options);
349
+ optionsRef.current = options;
350
+ React2.useEffect(() => registry.subscribe(() => setTick((t) => t + 1)), [registry]);
351
+ React2.useEffect(() => {
352
+ if (!target || !active) return;
353
+ let live = true;
354
+ void registry.resolve(target, optionsRef.current.restrict).then((list) => {
355
+ if (!live) return;
356
+ expanded.current.clear();
357
+ setResolved(list);
358
+ setModel(buildMenuModel(target, list, { ...ports.i18n ? { i18n: ports.i18n } : {}, content: optionsRef.current.content ?? null }));
359
+ });
360
+ return () => {
361
+ live = false;
362
+ };
363
+ }, [registry, ports, target, active, tick, options.revision]);
364
+ React2.useEffect(() => {
365
+ if (!target) return;
366
+ const offs = resolved.map((r) => r.action.subscribe?.(() => setTick((t) => t + 1), target)).filter((off) => typeof off === "function");
367
+ return () => offs.forEach((off) => off());
368
+ }, [resolved, target]);
369
+ const findAction = React2.useCallback(
370
+ (id) => resolved.find((r) => r.action.id === id)?.action ?? expanded.current.get(id),
371
+ [resolved]
372
+ );
373
+ const run = React2.useCallback(
374
+ async (nodeId) => {
375
+ if (!target || !model) return null;
376
+ const node = model.sections.map((s) => findNode(s.nodes, nodeId)).find(Boolean) ?? null;
377
+ const action = findAction(node && "actionId" in node && node.actionId ? node.actionId : nodeId);
378
+ if (!action) return null;
379
+ const o = optionsRef.current;
380
+ const result = await runAction(action, target, {
381
+ ports,
382
+ ...o.source ? { source: o.source } : {},
383
+ ...o.contentFingerprint ? { contentFingerprint: o.contentFingerprint } : {}
384
+ });
385
+ o.onRan?.(nodeId, result);
386
+ return result;
387
+ },
388
+ [target, model, findAction, ports]
389
+ );
390
+ const expand = React2.useCallback(
391
+ async (nodeId) => {
392
+ const action = findAction(nodeId);
393
+ if (!target || !action?.expand) return;
394
+ setModel((m) => m ? withExpandedChildren(m, nodeId, "loading") : m);
395
+ try {
396
+ const children = await action.expand(target, new AbortController().signal);
397
+ const nodes = children.map((child) => {
398
+ expanded.current.set(child.id, child);
399
+ return actionToNode({ action: child, eligibility: { status: "available" } }, target, ports.i18n ? { i18n: ports.i18n } : {});
400
+ });
401
+ setModel((m) => m ? withExpandedChildren(m, nodeId, nodes) : m);
402
+ } catch (error) {
403
+ ports.diagnostics.capture(error, { area: "menu", detail: { nodeId, stage: "expand" } });
404
+ setModel((m) => m ? withExpandedChildren(m, nodeId, []) : m);
405
+ }
406
+ },
407
+ [findAction, target, ports]
408
+ );
409
+ const icon = React2.useCallback(
410
+ (key, tone) => {
411
+ if (!key || !ports.icons) return null;
412
+ const Resolved = ports.icons.resolve(key);
413
+ return Resolved ? /* @__PURE__ */ jsx(Resolved, { className: `h-4 w-4 shrink-0 ${tone ?? ""}`, "aria-hidden": true }) : null;
414
+ },
415
+ [ports.icons]
416
+ );
417
+ return { model, resolved, run, expand, icon };
418
+ }
419
+
420
+ // src/react/dropdown-nodes.tsx
421
+ import * as React3 from "react";
422
+ import {
423
+ DropdownMenuCheckboxItem,
424
+ DropdownMenuItem,
425
+ DropdownMenuLabel,
426
+ DropdownMenuSeparator,
427
+ DropdownMenuSub,
428
+ DropdownMenuSubContent,
429
+ DropdownMenuSubTrigger,
430
+ Tooltip,
431
+ TooltipContent,
432
+ TooltipTrigger
433
+ } from "@ai-matrx/design-system";
434
+ import { Fragment as Fragment2, jsx as jsx2, jsxs } from "react/jsx-runtime";
435
+ function NodeList({ nodes, engine }) {
436
+ return /* @__PURE__ */ jsx2(Fragment2, { children: nodes.map((node) => /* @__PURE__ */ jsx2(MenuNodeView, { node, engine }, node.id)) });
437
+ }
438
+ function SectionList({
439
+ sections,
440
+ engine
441
+ }) {
442
+ return /* @__PURE__ */ jsx2(Fragment2, { children: sections.map((section, index) => /* @__PURE__ */ jsxs(React3.Fragment, { children: [
443
+ index > 0 ? /* @__PURE__ */ jsx2(DropdownMenuSeparator, {}) : null,
444
+ sectionLabel(section) ? /* @__PURE__ */ jsx2(DropdownMenuLabel, { className: "text-xs font-medium text-muted-foreground", children: sectionLabel(section) }) : null,
445
+ /* @__PURE__ */ jsx2(NodeList, { nodes: section.nodes, engine })
446
+ ] }, section.id)) });
447
+ }
448
+ function iconOf(node, engine) {
449
+ if (node.kind === "item" && node.stateIcon) {
450
+ const glyph = engine.icon(node.stateIcon.icon);
451
+ return node.stateIcon.spin ? /* @__PURE__ */ jsx2("span", { className: "inline-flex animate-spin", children: glyph }) : glyph;
452
+ }
453
+ if (!("icon" in node)) return null;
454
+ return engine.icon(node.icon, node.kind === "item" ? node.iconTone : void 0);
455
+ }
456
+ function MenuNodeView({ node, engine }) {
457
+ switch (node.kind) {
458
+ case "separator":
459
+ return /* @__PURE__ */ jsx2(DropdownMenuSeparator, {});
460
+ case "label":
461
+ return /* @__PURE__ */ jsx2(DropdownMenuLabel, { className: "text-xs font-medium text-muted-foreground", children: node.label });
462
+ case "submenu":
463
+ return /* @__PURE__ */ jsxs(
464
+ DropdownMenuSub,
465
+ {
466
+ onOpenChange: (open) => {
467
+ if (open && node.lazy && !node.loading) void engine.expand(node.id);
468
+ },
469
+ children: [
470
+ /* @__PURE__ */ jsxs(DropdownMenuSubTrigger, { "data-alchemy-node": node.id, className: "gap-2", children: [
471
+ iconOf(node, engine),
472
+ /* @__PURE__ */ jsx2("span", { className: "truncate", children: node.label })
473
+ ] }),
474
+ /* @__PURE__ */ jsx2(DropdownMenuSubContent, { className: "max-h-[var(--radix-dropdown-menu-content-available-height)] overflow-y-auto", children: node.loading ? /* @__PURE__ */ jsx2(DropdownMenuLabel, { className: "text-xs text-muted-foreground", children: "Loading\u2026" }) : node.children.length === 0 && !node.lazy ? /* @__PURE__ */ jsx2(DropdownMenuLabel, { className: "text-xs text-muted-foreground", children: node.emptyLabel ?? "Nothing here yet" }) : /* @__PURE__ */ jsx2(NodeList, { nodes: node.children, engine }) })
475
+ ]
476
+ }
477
+ );
478
+ case "checkbox":
479
+ return /* @__PURE__ */ jsxs(
480
+ DropdownMenuCheckboxItem,
481
+ {
482
+ "data-alchemy-node": node.id,
483
+ checked: node.checked,
484
+ onSelect: () => void engine.run(node.id),
485
+ className: "gap-2",
486
+ children: [
487
+ iconOf(node, engine),
488
+ /* @__PURE__ */ jsx2("span", { className: "truncate", children: node.label })
489
+ ]
490
+ }
491
+ );
492
+ case "link":
493
+ return /* @__PURE__ */ jsx2(DropdownMenuItem, { asChild: true, "data-alchemy-node": node.id, children: /* @__PURE__ */ jsxs("a", { href: node.href, target: node.target, className: "gap-2", children: [
494
+ iconOf(node, engine),
495
+ /* @__PURE__ */ jsx2("span", { className: "truncate", children: node.label })
496
+ ] }) });
497
+ case "item":
498
+ return /* @__PURE__ */ jsx2(LeafItem, { node, engine });
499
+ }
500
+ }
501
+ function LeafItem({ node, engine }) {
502
+ const row = /* @__PURE__ */ jsxs(
503
+ DropdownMenuItem,
504
+ {
505
+ "data-alchemy-node": node.id,
506
+ "aria-disabled": node.unavailable ? true : void 0,
507
+ "aria-pressed": node.pressed,
508
+ onSelect: (event) => {
509
+ if (node.unavailable) {
510
+ event.preventDefault();
511
+ return;
512
+ }
513
+ void engine.run(node.id);
514
+ },
515
+ className: `gap-2 ${node.unavailable ? "opacity-50" : ""} ${node.destructive ? "text-destructive" : ""}`,
516
+ children: [
517
+ iconOf(node, engine),
518
+ /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 flex-1 flex-col", children: [
519
+ /* @__PURE__ */ jsx2("span", { className: "truncate", children: node.label }),
520
+ node.description ? /* @__PURE__ */ jsx2("span", { className: "truncate text-xs text-muted-foreground", children: node.description }) : null
521
+ ] }),
522
+ node.hint ? /* @__PURE__ */ jsx2("span", { className: "ml-auto text-xs text-muted-foreground", children: node.hint }) : null
523
+ ]
524
+ }
525
+ );
526
+ if (!node.unavailable) return row;
527
+ return /* @__PURE__ */ jsxs(Tooltip, { children: [
528
+ /* @__PURE__ */ jsx2(TooltipTrigger, { asChild: true, children: row }),
529
+ /* @__PURE__ */ jsx2(TooltipContent, { children: node.unavailable.sentence })
530
+ ] });
531
+ }
532
+
533
+ // src/react/overflow.tsx
534
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
535
+ function OverflowMenu({ target, trigger, align = "end", eager = false, ...options }) {
536
+ const [open, setOpen] = React4.useState(false);
537
+ const [opened, setOpened] = React4.useState(eager);
538
+ const engine = useMenuEngine(target, { ...options, active: opened || open });
539
+ return /* @__PURE__ */ jsxs2(
540
+ DropdownMenu,
541
+ {
542
+ open,
543
+ onOpenChange: (next) => {
544
+ setOpen(next);
545
+ if (next) setOpened(true);
546
+ },
547
+ children: [
548
+ /* @__PURE__ */ jsx3(DropdownMenuTrigger, { asChild: true, children: trigger ?? /* @__PURE__ */ jsx3(
549
+ "button",
550
+ {
551
+ type: "button",
552
+ "aria-label": "More actions",
553
+ "data-alchemy-trigger": "overflow",
554
+ className: "inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground",
555
+ children: /* @__PURE__ */ jsx3("span", { "aria-hidden": true, className: "text-base leading-none", children: "\u22EF" })
556
+ }
557
+ ) }),
558
+ /* @__PURE__ */ jsx3(DropdownMenuContent, { align, className: "w-64 max-h-[var(--radix-dropdown-menu-content-available-height)] overflow-y-auto", children: /* @__PURE__ */ jsx3(OverflowSections, { engine }) })
559
+ ]
560
+ }
561
+ );
562
+ }
563
+ function OverflowSections({ engine }) {
564
+ if (!engine.model) return /* @__PURE__ */ jsx3("div", { className: "px-2 py-1.5 text-xs text-muted-foreground", children: "Loading\u2026" });
565
+ return /* @__PURE__ */ jsx3(TooltipProvider, { children: /* @__PURE__ */ jsx3(SectionList, { sections: overflow(engine.model), engine }) });
566
+ }
567
+ export {
568
+ OverflowMenu,
569
+ OverflowSections
570
+ };
571
+ //# sourceMappingURL=react-overflow.js.map