@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.
- package/CHANGELOG.md +58 -0
- package/dist/actions.cjs +374 -0
- package/dist/actions.cjs.map +1 -0
- package/dist/actions.d.cts +773 -0
- package/dist/actions.d.ts +773 -0
- package/dist/actions.js +351 -0
- package/dist/actions.js.map +1 -0
- package/dist/checks.cjs +31 -2
- package/dist/checks.cjs.map +1 -1
- package/dist/checks.d.cts +24 -1
- package/dist/checks.d.ts +24 -1
- package/dist/checks.js +31 -2
- package/dist/checks.js.map +1 -1
- package/dist/core.cjs +1757 -2
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +595 -1
- package/dist/core.d.ts +595 -1
- package/dist/core.js +1749 -2
- package/dist/core.js.map +1 -1
- package/dist/declare.cjs +12 -10
- package/dist/declare.cjs.map +1 -1
- package/dist/declare.d.cts +18 -2
- package/dist/declare.d.ts +18 -2
- package/dist/declare.js +12 -10
- package/dist/declare.js.map +1 -1
- package/dist/index.cjs +1757 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +595 -1
- package/dist/index.d.ts +595 -1
- package/dist/index.js +1749 -2
- package/dist/index.js.map +1 -1
- package/dist/menu.cjs +436 -0
- package/dist/menu.cjs.map +1 -0
- package/dist/menu.d.cts +834 -0
- package/dist/menu.d.ts +834 -0
- package/dist/menu.js +413 -0
- package/dist/menu.js.map +1 -0
- package/dist/operate-document.cjs +163 -0
- package/dist/operate-document.cjs.map +1 -0
- package/dist/operate-document.d.cts +132 -0
- package/dist/operate-document.d.ts +132 -0
- package/dist/operate-document.js +130 -0
- package/dist/operate-document.js.map +1 -0
- package/dist/operate-rich-html.cjs +129 -0
- package/dist/operate-rich-html.cjs.map +1 -0
- package/dist/operate-rich-html.d.cts +136 -0
- package/dist/operate-rich-html.d.ts +136 -0
- package/dist/operate-rich-html.js +96 -0
- package/dist/operate-rich-html.js.map +1 -0
- package/dist/operate-server.cjs +157 -0
- package/dist/operate-server.cjs.map +1 -0
- package/dist/operate-server.d.cts +183 -0
- package/dist/operate-server.d.ts +183 -0
- package/dist/operate-server.js +134 -0
- package/dist/operate-server.js.map +1 -0
- package/dist/operate-xlsx.cjs +248 -0
- package/dist/operate-xlsx.cjs.map +1 -0
- package/dist/operate-xlsx.d.cts +129 -0
- package/dist/operate-xlsx.d.ts +129 -0
- package/dist/operate-xlsx.js +215 -0
- package/dist/operate-xlsx.js.map +1 -0
- package/dist/operate.cjs +1774 -0
- package/dist/operate.cjs.map +1 -0
- package/dist/operate.d.cts +595 -0
- package/dist/operate.d.ts +595 -0
- package/dist/operate.js +1750 -0
- package/dist/operate.js.map +1 -0
- package/dist/ports.cjs.map +1 -1
- package/dist/ports.d.cts +361 -3
- package/dist/ports.d.ts +361 -3
- package/dist/react-bar.cjs +686 -0
- package/dist/react-bar.cjs.map +1 -0
- package/dist/react-bar.d.cts +379 -0
- package/dist/react-bar.d.ts +379 -0
- package/dist/react-bar.js +665 -0
- package/dist/react-bar.js.map +1 -0
- package/dist/react-host.cjs +301 -0
- package/dist/react-host.cjs.map +1 -0
- package/dist/react-host.d.cts +820 -0
- package/dist/react-host.d.ts +820 -0
- package/dist/react-host.js +269 -0
- package/dist/react-host.js.map +1 -0
- package/dist/react-menu.cjs +735 -0
- package/dist/react-menu.cjs.map +1 -0
- package/dist/react-menu.d.cts +370 -0
- package/dist/react-menu.d.ts +370 -0
- package/dist/react-menu.js +722 -0
- package/dist/react-menu.js.map +1 -0
- package/dist/react-overflow.cjs +592 -0
- package/dist/react-overflow.cjs.map +1 -0
- package/dist/react-overflow.d.cts +817 -0
- package/dist/react-overflow.d.ts +817 -0
- package/dist/react-overflow.js +571 -0
- package/dist/react-overflow.js.map +1 -0
- package/dist/react-palette.cjs +489 -0
- package/dist/react-palette.cjs.map +1 -0
- package/dist/react-palette.d.cts +359 -0
- package/dist/react-palette.d.ts +359 -0
- package/dist/react-palette.js +457 -0
- package/dist/react-palette.js.map +1 -0
- package/dist/react-selection.cjs +617 -0
- package/dist/react-selection.cjs.map +1 -0
- package/dist/react-selection.d.cts +357 -0
- package/dist/react-selection.d.ts +357 -0
- package/dist/react-selection.js +596 -0
- package/dist/react-selection.js.map +1 -0
- package/dist/react-sheet.cjs +616 -0
- package/dist/react-sheet.cjs.map +1 -0
- package/dist/react-sheet.d.cts +361 -0
- package/dist/react-sheet.d.ts +361 -0
- package/dist/react-sheet.js +595 -0
- package/dist/react-sheet.js.map +1 -0
- package/package.json +148 -5
|
@@ -0,0 +1,735 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/react-menu.ts
|
|
32
|
+
var react_menu_exports = {};
|
|
33
|
+
__export(react_menu_exports, {
|
|
34
|
+
ContextMenuPanel: () => ContextMenuPanel
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(react_menu_exports);
|
|
37
|
+
|
|
38
|
+
// src/react/menu.tsx
|
|
39
|
+
var React4 = __toESM(require("react"), 1);
|
|
40
|
+
var import_design_system2 = require("@ai-matrx/design-system");
|
|
41
|
+
|
|
42
|
+
// src/menu/layouts.ts
|
|
43
|
+
var INLINE_SECTION_MAX = 3;
|
|
44
|
+
function sectionLabel(section) {
|
|
45
|
+
return section.label ?? null;
|
|
46
|
+
}
|
|
47
|
+
function isLeaf(node) {
|
|
48
|
+
return node.kind === "item" || node.kind === "checkbox" || node.kind === "link";
|
|
49
|
+
}
|
|
50
|
+
function fold(section) {
|
|
51
|
+
return {
|
|
52
|
+
kind: "submenu",
|
|
53
|
+
id: `${section.id}:fold`,
|
|
54
|
+
label: section.label,
|
|
55
|
+
...section.icon !== void 0 ? { icon: section.icon } : {},
|
|
56
|
+
children: section.nodes
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function rowCount(nodes) {
|
|
60
|
+
return nodes.filter((n) => n.kind !== "separator" && n.kind !== "label").length;
|
|
61
|
+
}
|
|
62
|
+
function stripOf(model) {
|
|
63
|
+
const clipboard = model.sections.find((s) => s.group === "clipboard" && !s.primary);
|
|
64
|
+
return clipboard ? clipboard.nodes.filter(isLeaf) : [];
|
|
65
|
+
}
|
|
66
|
+
function clipboardRest(model) {
|
|
67
|
+
const clipboard = model.sections.find((s) => s.group === "clipboard" && !s.primary);
|
|
68
|
+
return clipboard ? clipboard.nodes.filter((n) => !isLeaf(n) && n.kind === "submenu") : [];
|
|
69
|
+
}
|
|
70
|
+
function classic(model) {
|
|
71
|
+
return { strip: [], sections: model.sections, filterable: false };
|
|
72
|
+
}
|
|
73
|
+
function tiered(model, filterable) {
|
|
74
|
+
const strip = stripOf(model);
|
|
75
|
+
const hierarchical = model.sections.some((s) => s.primary);
|
|
76
|
+
const sections = [];
|
|
77
|
+
const rest = clipboardRest(model);
|
|
78
|
+
for (const s of model.sections) {
|
|
79
|
+
if (s.group === "clipboard" && !s.primary) {
|
|
80
|
+
if (rest.length) sections.push({ ...s, nodes: rest });
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (s.primary) {
|
|
84
|
+
sections.push(s);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (!s.label || s.group === "surface-info" || rowCount(s.nodes) <= INLINE_SECTION_MAX) {
|
|
88
|
+
if (hierarchical) sections.push(s);
|
|
89
|
+
else {
|
|
90
|
+
const { label: _label, ...unlabelled } = s;
|
|
91
|
+
sections.push(unlabelled);
|
|
92
|
+
}
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
sections.push({ id: s.id, group: s.group, nodes: [fold({ ...s, label: s.label })] });
|
|
96
|
+
}
|
|
97
|
+
return { strip, sections, filterable };
|
|
98
|
+
}
|
|
99
|
+
function context(model, arrangement) {
|
|
100
|
+
if (arrangement === "classic") return classic(model);
|
|
101
|
+
return tiered(model, arrangement === "command");
|
|
102
|
+
}
|
|
103
|
+
function palette(model) {
|
|
104
|
+
const leaves = [];
|
|
105
|
+
const walk = (nodes, trail) => {
|
|
106
|
+
for (const n of nodes) {
|
|
107
|
+
if (isLeaf(n)) leaves.push({ node: n, breadcrumb: trail });
|
|
108
|
+
else if (n.kind === "submenu") {
|
|
109
|
+
if (n.lazy) leaves.push({ node: n, breadcrumb: trail });
|
|
110
|
+
else walk(n.children, [...trail, n.label]);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
for (const s of model.sections) walk(s.nodes, s.label ? [s.label] : []);
|
|
115
|
+
return { leaves };
|
|
116
|
+
}
|
|
117
|
+
function filterPalette(arranged, query) {
|
|
118
|
+
const words = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
119
|
+
if (!words.length) return arranged;
|
|
120
|
+
return {
|
|
121
|
+
leaves: arranged.leaves.filter((l) => {
|
|
122
|
+
const hay = `${l.node.label} ${l.breadcrumb.join(" ")}`.toLowerCase();
|
|
123
|
+
return words.every((w) => hay.includes(w));
|
|
124
|
+
})
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// src/react/engine.tsx
|
|
129
|
+
var React2 = __toESM(require("react"), 1);
|
|
130
|
+
|
|
131
|
+
// src/declare/sensitivity.ts
|
|
132
|
+
var DEFAULT_SENSITIVITY = Object.freeze({
|
|
133
|
+
exportable: true,
|
|
134
|
+
classification: "ordinary",
|
|
135
|
+
includedByDefault: true
|
|
136
|
+
});
|
|
137
|
+
function resolveSensitivity(value) {
|
|
138
|
+
return {
|
|
139
|
+
exportable: value.sensitivity?.exportable ?? DEFAULT_SENSITIVITY.exportable,
|
|
140
|
+
classification: value.sensitivity?.classification ?? DEFAULT_SENSITIVITY.classification,
|
|
141
|
+
includedByDefault: value.sensitivity?.includedByDefault ?? DEFAULT_SENSITIVITY.includedByDefault
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/actions/projection.ts
|
|
146
|
+
function toJson(value) {
|
|
147
|
+
if (value === void 0 || typeof value === "function" || typeof value === "symbol") return void 0;
|
|
148
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
149
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : null;
|
|
150
|
+
if (typeof value === "bigint") return value.toString();
|
|
151
|
+
if (value instanceof Date) return value.toISOString();
|
|
152
|
+
if (Array.isArray(value)) return value.map((v) => toJson(v) ?? null);
|
|
153
|
+
if (typeof value === "object") {
|
|
154
|
+
const out = {};
|
|
155
|
+
for (const [k, v] of Object.entries(value)) {
|
|
156
|
+
const j = toJson(v);
|
|
157
|
+
if (j !== void 0) out[k] = j;
|
|
158
|
+
}
|
|
159
|
+
return out;
|
|
160
|
+
}
|
|
161
|
+
return void 0;
|
|
162
|
+
}
|
|
163
|
+
function projectValues(raw, declared, pathPrefix = "") {
|
|
164
|
+
const byName = new Map(declared.map((d) => [d.name, d]));
|
|
165
|
+
const values = {};
|
|
166
|
+
const omissions = [];
|
|
167
|
+
for (const [name, value] of Object.entries(raw)) {
|
|
168
|
+
const path = pathPrefix ? `${pathPrefix}.${name}` : name;
|
|
169
|
+
const decl = byName.get(name);
|
|
170
|
+
if (!decl) {
|
|
171
|
+
omissions.push({ path, reason: "filtered" });
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const sensitivity = resolveSensitivity(decl);
|
|
175
|
+
if (sensitivity.classification !== "ordinary") {
|
|
176
|
+
omissions.push({ path, reason: "excluded", classification: sensitivity.classification });
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (!sensitivity.exportable) {
|
|
180
|
+
omissions.push({ path, reason: "excluded" });
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
const json = toJson(value);
|
|
184
|
+
if (json === void 0) continue;
|
|
185
|
+
values[name] = json;
|
|
186
|
+
}
|
|
187
|
+
return { values, omissions };
|
|
188
|
+
}
|
|
189
|
+
function createProjectedReads(source) {
|
|
190
|
+
return {
|
|
191
|
+
async values(signal) {
|
|
192
|
+
if (!source.surface || !source.declaration) return { values: {}, omissions: [] };
|
|
193
|
+
const raw = await source.surface.readValues(signal);
|
|
194
|
+
const screenValues = source.declaration.values;
|
|
195
|
+
return projectValues(raw, screenValues);
|
|
196
|
+
},
|
|
197
|
+
async item(signal) {
|
|
198
|
+
const item = source.item;
|
|
199
|
+
if (!item || !source.declaration) return null;
|
|
200
|
+
const type = source.declaration.itemTypes?.find((t) => t.name === item.itemType);
|
|
201
|
+
if (!type) return { values: {}, omissions: [{ path: item.itemType, reason: "filtered" }] };
|
|
202
|
+
const raw = await item.readValues(signal);
|
|
203
|
+
return projectValues(raw, type.values, item.itemType);
|
|
204
|
+
},
|
|
205
|
+
async live(signal) {
|
|
206
|
+
if (!source.surface?.readLive) return {};
|
|
207
|
+
return source.surface.readLive(signal);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// src/actions/run.ts
|
|
213
|
+
async function runAction(action, target, options) {
|
|
214
|
+
const { ports } = options;
|
|
215
|
+
if (action.requiresAuth && !target.auth.authenticated) {
|
|
216
|
+
if (!ports.auth) {
|
|
217
|
+
ports.diagnostics.capture(new Error(`requiresAuth action "${action.id}" ran signed out with no auth port`), {
|
|
218
|
+
area: "actions",
|
|
219
|
+
detail: { actionId: action.id }
|
|
220
|
+
});
|
|
221
|
+
return { status: "failed", error: new Error("sign-in unavailable") };
|
|
222
|
+
}
|
|
223
|
+
ports.auth.signInThenResume({ actionId: action.id, contentFingerprint: options.contentFingerprint ?? action.id });
|
|
224
|
+
return { status: "auth-pending" };
|
|
225
|
+
}
|
|
226
|
+
const reads = createProjectedReads(options.source ?? { surface: null, declaration: target.declaration, item: null });
|
|
227
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
228
|
+
try {
|
|
229
|
+
const outcome = await action.run(target, { reads, ports, signal });
|
|
230
|
+
return { status: "ran", outcome };
|
|
231
|
+
} catch (error) {
|
|
232
|
+
ports.diagnostics.capture(error, { area: "actions", detail: { actionId: action.id, stage: "run" } });
|
|
233
|
+
const label = typeof action.label === "string" ? action.label : action.id;
|
|
234
|
+
ports.notify?.error(`${label} did not finish.`, "Try again; if it keeps failing, report it from the feedback button.");
|
|
235
|
+
return { status: "failed", error };
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// src/menu/model.ts
|
|
240
|
+
var CATEGORY_GROUP = {
|
|
241
|
+
clipboard: "clipboard",
|
|
242
|
+
copy: "transfer",
|
|
243
|
+
export: "transfer",
|
|
244
|
+
save: "document",
|
|
245
|
+
share: "document",
|
|
246
|
+
edit: "editable",
|
|
247
|
+
history: "history",
|
|
248
|
+
ai: "ai",
|
|
249
|
+
ask: "ai",
|
|
250
|
+
listen: "tools",
|
|
251
|
+
study: "tools",
|
|
252
|
+
app: "tools",
|
|
253
|
+
feedback: "quick",
|
|
254
|
+
creator: "admin",
|
|
255
|
+
admin: "admin",
|
|
256
|
+
"surface-info": "surface-info"
|
|
257
|
+
};
|
|
258
|
+
var GROUP_ORDER = [
|
|
259
|
+
"clipboard",
|
|
260
|
+
"editable",
|
|
261
|
+
"transfer",
|
|
262
|
+
"document",
|
|
263
|
+
"history",
|
|
264
|
+
"ai",
|
|
265
|
+
"tools",
|
|
266
|
+
"quick",
|
|
267
|
+
"surface",
|
|
268
|
+
"admin",
|
|
269
|
+
"surface-info"
|
|
270
|
+
];
|
|
271
|
+
var CATEGORY_ORDER = [
|
|
272
|
+
"clipboard",
|
|
273
|
+
"edit",
|
|
274
|
+
"copy",
|
|
275
|
+
"export",
|
|
276
|
+
"save",
|
|
277
|
+
"share",
|
|
278
|
+
"history",
|
|
279
|
+
"ask",
|
|
280
|
+
"ai",
|
|
281
|
+
"listen",
|
|
282
|
+
"study",
|
|
283
|
+
"app",
|
|
284
|
+
"feedback",
|
|
285
|
+
"creator",
|
|
286
|
+
"admin",
|
|
287
|
+
"surface-info"
|
|
288
|
+
];
|
|
289
|
+
function translate(i18n, key, fallback) {
|
|
290
|
+
if (!i18n) return fallback;
|
|
291
|
+
try {
|
|
292
|
+
return i18n.t(key, fallback);
|
|
293
|
+
} catch {
|
|
294
|
+
return fallback;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function actionToNode(resolved, target, options = {}) {
|
|
298
|
+
const { action, eligibility } = resolved;
|
|
299
|
+
const rawLabel = typeof action.label === "function" ? action.label(target) : action.label;
|
|
300
|
+
const label = translate(options.i18n, action.labelKey ?? action.id, rawLabel);
|
|
301
|
+
const base = {
|
|
302
|
+
id: action.id,
|
|
303
|
+
actionId: action.id,
|
|
304
|
+
...action.icon !== void 0 ? { icon: action.icon } : {},
|
|
305
|
+
...action.placement !== void 0 ? { placement: action.placement } : {}
|
|
306
|
+
};
|
|
307
|
+
if (action.expand) {
|
|
308
|
+
const node = {
|
|
309
|
+
...base,
|
|
310
|
+
kind: "submenu",
|
|
311
|
+
label,
|
|
312
|
+
lazy: true,
|
|
313
|
+
loading: false,
|
|
314
|
+
children: [],
|
|
315
|
+
...action.emptyLabel !== void 0 ? { emptyLabel: action.emptyLabel } : {}
|
|
316
|
+
};
|
|
317
|
+
return node;
|
|
318
|
+
}
|
|
319
|
+
if (action.href !== void 0) {
|
|
320
|
+
const href = typeof action.href === "function" ? action.href(target) : action.href;
|
|
321
|
+
return { ...base, kind: "link", label, href };
|
|
322
|
+
}
|
|
323
|
+
if (action.toggle) {
|
|
324
|
+
return {
|
|
325
|
+
...base,
|
|
326
|
+
kind: "checkbox",
|
|
327
|
+
label,
|
|
328
|
+
checked: action.pressed?.(target) ?? false,
|
|
329
|
+
...action.description !== void 0 ? { description: action.description } : {}
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
const state = action.stateIcon?.(target) ?? null;
|
|
333
|
+
const pressed = action.pressed?.(target);
|
|
334
|
+
const hint = action.hint !== void 0 ? translate(options.i18n, action.hintKey ?? `${action.id}.hint`, action.hint) : void 0;
|
|
335
|
+
return {
|
|
336
|
+
...base,
|
|
337
|
+
kind: "item",
|
|
338
|
+
label,
|
|
339
|
+
...action.iconTone !== void 0 ? { iconTone: action.iconTone } : {},
|
|
340
|
+
...state ? { stateIcon: state } : {},
|
|
341
|
+
...action.description !== void 0 ? { description: action.description } : {},
|
|
342
|
+
...hint !== void 0 ? { hint } : {},
|
|
343
|
+
...pressed !== void 0 ? { pressed } : {},
|
|
344
|
+
...action.destructive ? { destructive: true } : {},
|
|
345
|
+
...action.preserveSelection ? { preserveSelection: true } : {},
|
|
346
|
+
...eligibility.status === "unavailable-verb" ? { unavailable: { sentence: eligibility.sentence } } : {}
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
function buildMenuModel(target, resolved, options = {}) {
|
|
350
|
+
const ordered = resolved.map((r, index) => ({ r, index })).sort((a, b) => {
|
|
351
|
+
const ca = CATEGORY_ORDER.indexOf(a.r.action.category);
|
|
352
|
+
const cb = CATEGORY_ORDER.indexOf(b.r.action.category);
|
|
353
|
+
if (ca !== cb) return ca - cb;
|
|
354
|
+
const oa = a.r.action.order ?? 0;
|
|
355
|
+
const ob = b.r.action.order ?? 0;
|
|
356
|
+
if (oa !== ob) return oa - ob;
|
|
357
|
+
return a.index - b.index;
|
|
358
|
+
}).map((x) => x.r);
|
|
359
|
+
const sections = /* @__PURE__ */ new Map();
|
|
360
|
+
const roles = {};
|
|
361
|
+
const explicit = /* @__PURE__ */ new Map();
|
|
362
|
+
resolved.forEach((r, index) => {
|
|
363
|
+
const sec = r.action.section;
|
|
364
|
+
if (!sec) return;
|
|
365
|
+
const entry = explicit.get(sec.id) ?? { group: CATEGORY_GROUP[r.action.category], rows: [] };
|
|
366
|
+
entry.rows.push({ r, index });
|
|
367
|
+
explicit.set(sec.id, entry);
|
|
368
|
+
});
|
|
369
|
+
const placed = /* @__PURE__ */ new Set();
|
|
370
|
+
for (const r of ordered) {
|
|
371
|
+
const sec = r.action.section;
|
|
372
|
+
if (sec && placed.has(sec.id)) continue;
|
|
373
|
+
const group = sec ? explicit.get(sec.id)?.group ?? CATEGORY_GROUP[r.action.category] : CATEGORY_GROUP[r.action.category];
|
|
374
|
+
const sectionId = sec ? `section:${sec.id}` : group;
|
|
375
|
+
let section = sections.get(sectionId);
|
|
376
|
+
if (!section) {
|
|
377
|
+
section = {
|
|
378
|
+
id: sectionId,
|
|
379
|
+
group,
|
|
380
|
+
nodes: [],
|
|
381
|
+
...sec ? { label: translate(options.i18n, sec.labelKey ?? `section.${sec.id}`, sec.label) } : {},
|
|
382
|
+
...sec?.icon !== void 0 ? { icon: sec.icon } : {},
|
|
383
|
+
...sec?.primary ? { primary: true } : {}
|
|
384
|
+
};
|
|
385
|
+
sections.set(sectionId, section);
|
|
386
|
+
}
|
|
387
|
+
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];
|
|
388
|
+
if (sec) placed.add(sec.id);
|
|
389
|
+
for (const row of rows) {
|
|
390
|
+
section.nodes.push(actionToNode(row, target, options));
|
|
391
|
+
if (row.action.verb) roles[row.action.verb] = row.action.id;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
const list = [...sections.values()].sort((a, b) => {
|
|
395
|
+
if (Boolean(a.primary) !== Boolean(b.primary)) return a.primary ? -1 : 1;
|
|
396
|
+
return GROUP_ORDER.indexOf(a.group) - GROUP_ORDER.indexOf(b.group);
|
|
397
|
+
});
|
|
398
|
+
const selected = target.selection?.text?.trim();
|
|
399
|
+
const content = options.content?.trim();
|
|
400
|
+
const header = selected ? { label: "Selected", text: target.selection?.text ?? "" } : content ? { label: "Content", text: options.content ?? "" } : null;
|
|
401
|
+
return { header, sections: list, roles };
|
|
402
|
+
}
|
|
403
|
+
function withExpandedChildren(model, nodeId, children) {
|
|
404
|
+
const visit = (nodes) => nodes.map((n) => {
|
|
405
|
+
if (n.kind !== "submenu") return n;
|
|
406
|
+
if (n.id === nodeId) {
|
|
407
|
+
return children === "loading" ? { ...n, loading: true } : { ...n, lazy: false, loading: false, children };
|
|
408
|
+
}
|
|
409
|
+
return { ...n, children: visit(n.children) };
|
|
410
|
+
});
|
|
411
|
+
return { ...model, sections: model.sections.map((s) => ({ ...s, nodes: visit(s.nodes) })) };
|
|
412
|
+
}
|
|
413
|
+
function findNode(nodes, id) {
|
|
414
|
+
for (const n of nodes) {
|
|
415
|
+
if (n.id === id) return n;
|
|
416
|
+
if (n.kind === "submenu") {
|
|
417
|
+
const hit = findNode(n.children, id);
|
|
418
|
+
if (hit) return hit;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// src/react/context.ts
|
|
425
|
+
var React = __toESM(require("react"), 1);
|
|
426
|
+
var KEY = /* @__PURE__ */ Symbol.for("ai-matrx.alchemy.actions-context");
|
|
427
|
+
var AlchemyActionsContext = globalThis[KEY] ??= React.createContext(null);
|
|
428
|
+
function useAlchemyActions() {
|
|
429
|
+
const value = React.useContext(AlchemyActionsContext);
|
|
430
|
+
if (!value) throw new Error("Alchemy actions: render inside <AlchemyActionsProvider> (@ai-matrx/alchemy/react/host).");
|
|
431
|
+
return value;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// src/react/engine.tsx
|
|
435
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
436
|
+
function useMenuEngine(target, options = {}) {
|
|
437
|
+
const { registry, ports } = useAlchemyActions();
|
|
438
|
+
const [resolved, setResolved] = React2.useState([]);
|
|
439
|
+
const [model, setModel] = React2.useState(null);
|
|
440
|
+
const [tick, setTick] = React2.useState(0);
|
|
441
|
+
const expanded = React2.useRef(/* @__PURE__ */ new Map());
|
|
442
|
+
const active = options.active ?? true;
|
|
443
|
+
const optionsRef = React2.useRef(options);
|
|
444
|
+
optionsRef.current = options;
|
|
445
|
+
React2.useEffect(() => registry.subscribe(() => setTick((t) => t + 1)), [registry]);
|
|
446
|
+
React2.useEffect(() => {
|
|
447
|
+
if (!target || !active) return;
|
|
448
|
+
let live = true;
|
|
449
|
+
void registry.resolve(target, optionsRef.current.restrict).then((list) => {
|
|
450
|
+
if (!live) return;
|
|
451
|
+
expanded.current.clear();
|
|
452
|
+
setResolved(list);
|
|
453
|
+
setModel(buildMenuModel(target, list, { ...ports.i18n ? { i18n: ports.i18n } : {}, content: optionsRef.current.content ?? null }));
|
|
454
|
+
});
|
|
455
|
+
return () => {
|
|
456
|
+
live = false;
|
|
457
|
+
};
|
|
458
|
+
}, [registry, ports, target, active, tick, options.revision]);
|
|
459
|
+
React2.useEffect(() => {
|
|
460
|
+
if (!target) return;
|
|
461
|
+
const offs = resolved.map((r) => r.action.subscribe?.(() => setTick((t) => t + 1), target)).filter((off) => typeof off === "function");
|
|
462
|
+
return () => offs.forEach((off) => off());
|
|
463
|
+
}, [resolved, target]);
|
|
464
|
+
const findAction = React2.useCallback(
|
|
465
|
+
(id) => resolved.find((r) => r.action.id === id)?.action ?? expanded.current.get(id),
|
|
466
|
+
[resolved]
|
|
467
|
+
);
|
|
468
|
+
const run = React2.useCallback(
|
|
469
|
+
async (nodeId) => {
|
|
470
|
+
if (!target || !model) return null;
|
|
471
|
+
const node = model.sections.map((s) => findNode(s.nodes, nodeId)).find(Boolean) ?? null;
|
|
472
|
+
const action = findAction(node && "actionId" in node && node.actionId ? node.actionId : nodeId);
|
|
473
|
+
if (!action) return null;
|
|
474
|
+
const o = optionsRef.current;
|
|
475
|
+
const result = await runAction(action, target, {
|
|
476
|
+
ports,
|
|
477
|
+
...o.source ? { source: o.source } : {},
|
|
478
|
+
...o.contentFingerprint ? { contentFingerprint: o.contentFingerprint } : {}
|
|
479
|
+
});
|
|
480
|
+
o.onRan?.(nodeId, result);
|
|
481
|
+
return result;
|
|
482
|
+
},
|
|
483
|
+
[target, model, findAction, ports]
|
|
484
|
+
);
|
|
485
|
+
const expand = React2.useCallback(
|
|
486
|
+
async (nodeId) => {
|
|
487
|
+
const action = findAction(nodeId);
|
|
488
|
+
if (!target || !action?.expand) return;
|
|
489
|
+
setModel((m) => m ? withExpandedChildren(m, nodeId, "loading") : m);
|
|
490
|
+
try {
|
|
491
|
+
const children = await action.expand(target, new AbortController().signal);
|
|
492
|
+
const nodes = children.map((child) => {
|
|
493
|
+
expanded.current.set(child.id, child);
|
|
494
|
+
return actionToNode({ action: child, eligibility: { status: "available" } }, target, ports.i18n ? { i18n: ports.i18n } : {});
|
|
495
|
+
});
|
|
496
|
+
setModel((m) => m ? withExpandedChildren(m, nodeId, nodes) : m);
|
|
497
|
+
} catch (error) {
|
|
498
|
+
ports.diagnostics.capture(error, { area: "menu", detail: { nodeId, stage: "expand" } });
|
|
499
|
+
setModel((m) => m ? withExpandedChildren(m, nodeId, []) : m);
|
|
500
|
+
}
|
|
501
|
+
},
|
|
502
|
+
[findAction, target, ports]
|
|
503
|
+
);
|
|
504
|
+
const icon = React2.useCallback(
|
|
505
|
+
(key, tone) => {
|
|
506
|
+
if (!key || !ports.icons) return null;
|
|
507
|
+
const Resolved = ports.icons.resolve(key);
|
|
508
|
+
return Resolved ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Resolved, { className: `h-4 w-4 shrink-0 ${tone ?? ""}`, "aria-hidden": true }) : null;
|
|
509
|
+
},
|
|
510
|
+
[ports.icons]
|
|
511
|
+
);
|
|
512
|
+
return { model, resolved, run, expand, icon };
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// src/react/dropdown-nodes.tsx
|
|
516
|
+
var React3 = __toESM(require("react"), 1);
|
|
517
|
+
var import_design_system = require("@ai-matrx/design-system");
|
|
518
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
519
|
+
function NodeList({ nodes, engine }) {
|
|
520
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: nodes.map((node) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MenuNodeView, { node, engine }, node.id)) });
|
|
521
|
+
}
|
|
522
|
+
function SectionList({
|
|
523
|
+
sections,
|
|
524
|
+
engine
|
|
525
|
+
}) {
|
|
526
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: sections.map((section, index) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(React3.Fragment, { children: [
|
|
527
|
+
index > 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_design_system.DropdownMenuSeparator, {}) : null,
|
|
528
|
+
sectionLabel(section) ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_design_system.DropdownMenuLabel, { className: "text-xs font-medium text-muted-foreground", children: sectionLabel(section) }) : null,
|
|
529
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NodeList, { nodes: section.nodes, engine })
|
|
530
|
+
] }, section.id)) });
|
|
531
|
+
}
|
|
532
|
+
function iconOf(node, engine) {
|
|
533
|
+
if (node.kind === "item" && node.stateIcon) {
|
|
534
|
+
const glyph = engine.icon(node.stateIcon.icon);
|
|
535
|
+
return node.stateIcon.spin ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "inline-flex animate-spin", children: glyph }) : glyph;
|
|
536
|
+
}
|
|
537
|
+
if (!("icon" in node)) return null;
|
|
538
|
+
return engine.icon(node.icon, node.kind === "item" ? node.iconTone : void 0);
|
|
539
|
+
}
|
|
540
|
+
function MenuNodeView({ node, engine }) {
|
|
541
|
+
switch (node.kind) {
|
|
542
|
+
case "separator":
|
|
543
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_design_system.DropdownMenuSeparator, {});
|
|
544
|
+
case "label":
|
|
545
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_design_system.DropdownMenuLabel, { className: "text-xs font-medium text-muted-foreground", children: node.label });
|
|
546
|
+
case "submenu":
|
|
547
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
548
|
+
import_design_system.DropdownMenuSub,
|
|
549
|
+
{
|
|
550
|
+
onOpenChange: (open) => {
|
|
551
|
+
if (open && node.lazy && !node.loading) void engine.expand(node.id);
|
|
552
|
+
},
|
|
553
|
+
children: [
|
|
554
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_design_system.DropdownMenuSubTrigger, { "data-alchemy-node": node.id, className: "gap-2", children: [
|
|
555
|
+
iconOf(node, engine),
|
|
556
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "truncate", children: node.label })
|
|
557
|
+
] }),
|
|
558
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_design_system.DropdownMenuSubContent, { className: "max-h-[var(--radix-dropdown-menu-content-available-height)] overflow-y-auto", children: node.loading ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_design_system.DropdownMenuLabel, { className: "text-xs text-muted-foreground", children: "Loading\u2026" }) : node.children.length === 0 && !node.lazy ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_design_system.DropdownMenuLabel, { className: "text-xs text-muted-foreground", children: node.emptyLabel ?? "Nothing here yet" }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NodeList, { nodes: node.children, engine }) })
|
|
559
|
+
]
|
|
560
|
+
}
|
|
561
|
+
);
|
|
562
|
+
case "checkbox":
|
|
563
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
564
|
+
import_design_system.DropdownMenuCheckboxItem,
|
|
565
|
+
{
|
|
566
|
+
"data-alchemy-node": node.id,
|
|
567
|
+
checked: node.checked,
|
|
568
|
+
onSelect: () => void engine.run(node.id),
|
|
569
|
+
className: "gap-2",
|
|
570
|
+
children: [
|
|
571
|
+
iconOf(node, engine),
|
|
572
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "truncate", children: node.label })
|
|
573
|
+
]
|
|
574
|
+
}
|
|
575
|
+
);
|
|
576
|
+
case "link":
|
|
577
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_design_system.DropdownMenuItem, { asChild: true, "data-alchemy-node": node.id, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("a", { href: node.href, target: node.target, className: "gap-2", children: [
|
|
578
|
+
iconOf(node, engine),
|
|
579
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "truncate", children: node.label })
|
|
580
|
+
] }) });
|
|
581
|
+
case "item":
|
|
582
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(LeafItem, { node, engine });
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
function LeafItem({ node, engine }) {
|
|
586
|
+
const row = /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
587
|
+
import_design_system.DropdownMenuItem,
|
|
588
|
+
{
|
|
589
|
+
"data-alchemy-node": node.id,
|
|
590
|
+
"aria-disabled": node.unavailable ? true : void 0,
|
|
591
|
+
"aria-pressed": node.pressed,
|
|
592
|
+
onSelect: (event) => {
|
|
593
|
+
if (node.unavailable) {
|
|
594
|
+
event.preventDefault();
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
void engine.run(node.id);
|
|
598
|
+
},
|
|
599
|
+
className: `gap-2 ${node.unavailable ? "opacity-50" : ""} ${node.destructive ? "text-destructive" : ""}`,
|
|
600
|
+
children: [
|
|
601
|
+
iconOf(node, engine),
|
|
602
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "flex min-w-0 flex-1 flex-col", children: [
|
|
603
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "truncate", children: node.label }),
|
|
604
|
+
node.description ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "truncate text-xs text-muted-foreground", children: node.description }) : null
|
|
605
|
+
] }),
|
|
606
|
+
node.hint ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "ml-auto text-xs text-muted-foreground", children: node.hint }) : null
|
|
607
|
+
]
|
|
608
|
+
}
|
|
609
|
+
);
|
|
610
|
+
if (!node.unavailable) return row;
|
|
611
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_design_system.Tooltip, { children: [
|
|
612
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_design_system.TooltipTrigger, { asChild: true, children: row }),
|
|
613
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_design_system.TooltipContent, { children: node.unavailable.sentence })
|
|
614
|
+
] });
|
|
615
|
+
}
|
|
616
|
+
function LeafButton({
|
|
617
|
+
node,
|
|
618
|
+
engine,
|
|
619
|
+
showLabel
|
|
620
|
+
}) {
|
|
621
|
+
if (node.kind !== "item" && node.kind !== "checkbox" && node.kind !== "link") return null;
|
|
622
|
+
const unavailable = node.kind === "item" ? node.unavailable : void 0;
|
|
623
|
+
const pressed = node.kind === "item" ? node.pressed : node.kind === "checkbox" ? node.checked : void 0;
|
|
624
|
+
const glyph = iconOf(node, engine);
|
|
625
|
+
const button = /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
626
|
+
"button",
|
|
627
|
+
{
|
|
628
|
+
type: "button",
|
|
629
|
+
"data-alchemy-node": node.id,
|
|
630
|
+
"aria-label": node.label,
|
|
631
|
+
"aria-disabled": unavailable ? true : void 0,
|
|
632
|
+
"aria-pressed": pressed,
|
|
633
|
+
onMouseDown: (e) => {
|
|
634
|
+
if (node.kind === "item" && node.preserveSelection) e.preventDefault();
|
|
635
|
+
},
|
|
636
|
+
onClick: () => {
|
|
637
|
+
if (unavailable) return;
|
|
638
|
+
if (node.kind === "link") {
|
|
639
|
+
window.location.assign(node.href);
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
void engine.run(node.id);
|
|
643
|
+
},
|
|
644
|
+
className: `inline-flex h-7 min-w-7 items-center justify-center gap-1.5 rounded-md px-1.5 text-sm text-muted-foreground hover:bg-accent hover:text-foreground ${unavailable ? "cursor-default opacity-50 hover:bg-transparent" : ""} ${pressed ? "text-foreground" : ""}`,
|
|
645
|
+
children: [
|
|
646
|
+
glyph,
|
|
647
|
+
showLabel || !glyph ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: node.label }) : null
|
|
648
|
+
]
|
|
649
|
+
}
|
|
650
|
+
);
|
|
651
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_design_system.Tooltip, { children: [
|
|
652
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_design_system.TooltipTrigger, { asChild: true, children: button }),
|
|
653
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_design_system.TooltipContent, { children: unavailable ? unavailable.sentence : node.label })
|
|
654
|
+
] });
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// src/react/menu.tsx
|
|
658
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
659
|
+
function ContextMenuPanel({
|
|
660
|
+
target,
|
|
661
|
+
point,
|
|
662
|
+
open,
|
|
663
|
+
onOpenChange,
|
|
664
|
+
arrangement = "command",
|
|
665
|
+
density = "comfortable",
|
|
666
|
+
...options
|
|
667
|
+
}) {
|
|
668
|
+
const engine = useMenuEngine(target, { ...options, onRan: (id, r) => {
|
|
669
|
+
options.onRan?.(id, r);
|
|
670
|
+
onOpenChange(false);
|
|
671
|
+
} });
|
|
672
|
+
const [query, setQuery] = React4.useState("");
|
|
673
|
+
const arranged = engine.model ? context(engine.model, arrangement) : null;
|
|
674
|
+
const filtered = engine.model && query.trim() ? filterPalette(palette(engine.model), query) : null;
|
|
675
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_design_system2.DropdownMenu, { open, onOpenChange, modal: false, children: [
|
|
676
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_design_system2.DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "aria-hidden": true, style: { position: "fixed", left: point.x, top: point.y, width: 0, height: 0 } }) }),
|
|
677
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
678
|
+
import_design_system2.DropdownMenuContent,
|
|
679
|
+
{
|
|
680
|
+
align: "start",
|
|
681
|
+
"data-alchemy-layout": `context-${arrangement}`,
|
|
682
|
+
onPointerUpCapture: (event) => {
|
|
683
|
+
if (event.button === 2) event.preventDefault();
|
|
684
|
+
},
|
|
685
|
+
className: `w-72 max-h-[var(--radix-dropdown-menu-content-available-height)] overflow-y-auto ${density === "compact" ? "text-xs" : ""}`,
|
|
686
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_design_system2.TooltipProvider, { children: [
|
|
687
|
+
engine.model?.header ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_design_system2.DropdownMenuLabel, { className: "truncate text-xs font-normal text-muted-foreground", title: engine.model.header.text, children: [
|
|
688
|
+
engine.model.header.label,
|
|
689
|
+
": ",
|
|
690
|
+
engine.model.header.text
|
|
691
|
+
] }) : null,
|
|
692
|
+
!arranged ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "px-2 py-1.5 text-xs text-muted-foreground", children: "Loading\u2026" }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
693
|
+
arranged.strip.length ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { role: "toolbar", "aria-label": "Clipboard", className: "flex items-center gap-0.5 px-1 py-1", children: arranged.strip.map((node) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(LeafButton, { node, engine, showLabel: false }, node.id)) }) : null,
|
|
694
|
+
arranged.filterable ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "px-1 pb-1", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
695
|
+
"input",
|
|
696
|
+
{
|
|
697
|
+
"aria-label": "Filter actions",
|
|
698
|
+
placeholder: "Type to filter\u2026",
|
|
699
|
+
value: query,
|
|
700
|
+
onChange: (e) => setQuery(e.target.value),
|
|
701
|
+
onKeyDown: (e) => {
|
|
702
|
+
e.stopPropagation();
|
|
703
|
+
if (e.key === "Enter" && filtered?.leaves[0]) void engine.run(filtered.leaves[0].node.id);
|
|
704
|
+
},
|
|
705
|
+
className: "h-7 w-full rounded-md border border-border bg-transparent px-2 text-sm outline-none"
|
|
706
|
+
}
|
|
707
|
+
) }) : null,
|
|
708
|
+
(arranged.strip.length || arranged.filterable) && arranged.sections.length ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_design_system2.DropdownMenuSeparator, {}) : null,
|
|
709
|
+
filtered ? filtered.leaves.length ? filtered.leaves.map(({ node, breadcrumb }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
710
|
+
import_design_system2.DropdownMenuItem,
|
|
711
|
+
{
|
|
712
|
+
"data-alchemy-node": node.id,
|
|
713
|
+
onSelect: () => {
|
|
714
|
+
if (node.kind === "submenu") void engine.expand(node.id);
|
|
715
|
+
else void engine.run(node.id);
|
|
716
|
+
},
|
|
717
|
+
className: "flex-col items-start gap-0",
|
|
718
|
+
children: [
|
|
719
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: node.label }),
|
|
720
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "text-xs text-muted-foreground", children: breadcrumb.join(" \u203A ") })
|
|
721
|
+
]
|
|
722
|
+
},
|
|
723
|
+
node.id
|
|
724
|
+
)) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "px-2 py-1.5 text-xs text-muted-foreground", children: [
|
|
725
|
+
"No action matches \u201C",
|
|
726
|
+
query,
|
|
727
|
+
"\u201D."
|
|
728
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SectionList, { sections: arranged.sections, engine })
|
|
729
|
+
] })
|
|
730
|
+
] })
|
|
731
|
+
}
|
|
732
|
+
)
|
|
733
|
+
] });
|
|
734
|
+
}
|
|
735
|
+
//# sourceMappingURL=react-menu.cjs.map
|