@ai-matrx/alchemy 0.8.11 → 0.8.13
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 +13 -4
- package/dist/actions.cjs.map +1 -1
- package/dist/actions.d.cts +6 -0
- package/dist/actions.d.ts +6 -0
- package/dist/actions.js.map +1 -1
- package/dist/menu.cjs +96 -26
- package/dist/menu.cjs.map +1 -1
- package/dist/menu.d.cts +47 -16
- package/dist/menu.d.ts +47 -16
- package/dist/menu.js +96 -26
- package/dist/menu.js.map +1 -1
- package/dist/react-bar.cjs +98 -15
- package/dist/react-bar.cjs.map +1 -1
- package/dist/react-bar.js +98 -15
- package/dist/react-bar.js.map +1 -1
- package/dist/react-host.d.cts +6 -0
- package/dist/react-host.d.ts +6 -0
- package/dist/react-menu.cjs +98 -15
- package/dist/react-menu.cjs.map +1 -1
- package/dist/react-menu.js +98 -15
- package/dist/react-menu.js.map +1 -1
- package/dist/react-overflow.cjs +98 -15
- package/dist/react-overflow.cjs.map +1 -1
- package/dist/react-overflow.d.cts +8 -0
- package/dist/react-overflow.d.ts +8 -0
- package/dist/react-overflow.js +98 -15
- package/dist/react-overflow.js.map +1 -1
- package/dist/react-palette.cjs +98 -15
- package/dist/react-palette.cjs.map +1 -1
- package/dist/react-palette.js +98 -15
- package/dist/react-palette.js.map +1 -1
- package/dist/react-selection.cjs +98 -15
- package/dist/react-selection.cjs.map +1 -1
- package/dist/react-selection.js +98 -15
- package/dist/react-selection.js.map +1 -1
- package/dist/react-sheet.cjs +106 -19
- package/dist/react-sheet.cjs.map +1 -1
- package/dist/react-sheet.js +106 -19
- package/dist/react-sheet.js.map +1 -1
- package/package.json +3 -3
package/dist/menu.js
CHANGED
|
@@ -1,3 +1,80 @@
|
|
|
1
|
+
// src/menu/headings.ts
|
|
2
|
+
var APPROVED_HEADINGS = /* @__PURE__ */ new Set([
|
|
3
|
+
"Save",
|
|
4
|
+
// rich-document menuStructure, e5b8d01229 (2026-05-19)
|
|
5
|
+
"Copy as",
|
|
6
|
+
// rich-document menuStructure, e5b8d01229 (2026-05-19)
|
|
7
|
+
"Export",
|
|
8
|
+
// rich-document menuStructure, e5b8d01229 (2026-05-19)
|
|
9
|
+
"Edit",
|
|
10
|
+
// rich-document menuStructure, e5b8d01229 (2026-05-19)
|
|
11
|
+
"Creator tools",
|
|
12
|
+
// rich-document menuStructure, e5b8d01229 (2026-05-19)
|
|
13
|
+
"Admin",
|
|
14
|
+
// rich-document menuStructure, e5b8d01229 (2026-05-19)
|
|
15
|
+
"App",
|
|
16
|
+
// rich-document menuStructure, e5b8d01229 (2026-05-19)
|
|
17
|
+
"Compare",
|
|
18
|
+
// rich-document menuStructure, 2e3a8a9fdf (2026-06-11)
|
|
19
|
+
"History"
|
|
20
|
+
// context-menu-v3 tiered layout — the one grouping Arman approved, 2026-08-22
|
|
21
|
+
]);
|
|
22
|
+
var CONTAINER_WORD = /^(more|more…|more\.\.\.|other|others|misc|miscellaneous|additional|extra|extras|actions|options|advanced|stuff|everything else)$/i;
|
|
23
|
+
var TARGET_SHAPE = /^(Cell|Row|Column|Table|Range|Selection|Record) · .+$/;
|
|
24
|
+
function isContainerWord(label) {
|
|
25
|
+
return CONTAINER_WORD.test(label.trim());
|
|
26
|
+
}
|
|
27
|
+
function isApprovedHeading(label, kind = "group", approved = APPROVED_HEADINGS) {
|
|
28
|
+
const l = label.trim();
|
|
29
|
+
if (!l || isContainerWord(l)) return false;
|
|
30
|
+
if (approved.has(l)) return true;
|
|
31
|
+
return kind === "target" || TARGET_SHAPE.test(l);
|
|
32
|
+
}
|
|
33
|
+
function defaultHeadingPolicy() {
|
|
34
|
+
const env = globalThis.process?.env?.NODE_ENV;
|
|
35
|
+
return env === "production" ? "inline" : "throw";
|
|
36
|
+
}
|
|
37
|
+
var UnapprovedHeadingError = class extends Error {
|
|
38
|
+
heading;
|
|
39
|
+
constructor(heading, where) {
|
|
40
|
+
super(
|
|
41
|
+
`Menu heading "${heading}" (${where}) is not an approved heading. Remedy: show these rows inline \u2014 declare no section (or kind "target" for the clicked thing's own label) \u2014 or ask Arman to add the name to APPROVED_HEADINGS in @ai-matrx/alchemy/menu. A generic container word ("More\u2026", "Other") is never approved.`
|
|
42
|
+
);
|
|
43
|
+
this.name = "UnapprovedHeadingError";
|
|
44
|
+
this.heading = heading;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
function menuHeadings(model) {
|
|
48
|
+
const out = [];
|
|
49
|
+
const walk = (nodes) => {
|
|
50
|
+
for (const n of nodes) {
|
|
51
|
+
if (n.kind === "submenu") {
|
|
52
|
+
out.push(n.label);
|
|
53
|
+
walk(n.children);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
for (const s of model.sections) {
|
|
58
|
+
if (s.label) out.push(s.label);
|
|
59
|
+
walk(s.nodes);
|
|
60
|
+
}
|
|
61
|
+
return [...new Set(out)];
|
|
62
|
+
}
|
|
63
|
+
function unapprovedHeadings(model, approved = APPROVED_HEADINGS) {
|
|
64
|
+
const out = /* @__PURE__ */ new Set();
|
|
65
|
+
for (const s of model.sections) {
|
|
66
|
+
if (s.label && !isApprovedHeading(s.label, s.primary || s.target ? "target" : "group", approved)) out.add(s.label);
|
|
67
|
+
const walk = (nodes) => {
|
|
68
|
+
for (const n of nodes) if (n.kind === "submenu") {
|
|
69
|
+
if (isContainerWord(n.label)) out.add(n.label);
|
|
70
|
+
walk(n.children);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
walk(s.nodes);
|
|
74
|
+
}
|
|
75
|
+
return [...out];
|
|
76
|
+
}
|
|
77
|
+
|
|
1
78
|
// src/menu/model.ts
|
|
2
79
|
var CATEGORY_GROUP = {
|
|
3
80
|
clipboard: "clipboard",
|
|
@@ -110,6 +187,19 @@ function actionToNode(resolved, target, options = {}) {
|
|
|
110
187
|
};
|
|
111
188
|
}
|
|
112
189
|
function buildMenuModel(target, resolved, options = {}) {
|
|
190
|
+
const policy = options.headingPolicy ?? defaultHeadingPolicy();
|
|
191
|
+
resolved = resolved.map((r) => {
|
|
192
|
+
const sec = r.action.section;
|
|
193
|
+
if (r.action.expand && isContainerWord(typeof r.action.label === "string" ? r.action.label : "") && policy === "throw") {
|
|
194
|
+
throw new UnapprovedHeadingError(r.action.label, `submenu of ${r.action.id}`);
|
|
195
|
+
}
|
|
196
|
+
if (!sec) return r;
|
|
197
|
+
const kind = sec.kind ?? (sec.primary ? "target" : "group");
|
|
198
|
+
if (isApprovedHeading(sec.label, kind)) return r;
|
|
199
|
+
if (policy === "throw") throw new UnapprovedHeadingError(sec.label, `section of ${r.action.id}`);
|
|
200
|
+
const { section: _dropped, ...rest } = r.action;
|
|
201
|
+
return { ...r, action: rest };
|
|
202
|
+
});
|
|
113
203
|
const ordered = resolved.map((r, index) => ({ r, index })).sort((a, b) => {
|
|
114
204
|
const ca = CATEGORY_ORDER.indexOf(a.r.action.category);
|
|
115
205
|
const cb = CATEGORY_ORDER.indexOf(b.r.action.category);
|
|
@@ -143,7 +233,8 @@ function buildMenuModel(target, resolved, options = {}) {
|
|
|
143
233
|
nodes: [],
|
|
144
234
|
...sec ? { label: translate(options.i18n, sec.labelKey ?? `section.${sec.id}`, sec.label) } : {},
|
|
145
235
|
...sec?.icon !== void 0 ? { icon: sec.icon } : {},
|
|
146
|
-
...sec?.primary ? { primary: true } : {}
|
|
236
|
+
...sec?.primary ? { primary: true } : {},
|
|
237
|
+
...sec && (sec.kind ?? (sec.primary ? "target" : "group")) === "target" ? { target: true } : {}
|
|
147
238
|
};
|
|
148
239
|
sections.set(sectionId, section);
|
|
149
240
|
}
|
|
@@ -384,43 +475,22 @@ async function resolveMenuLayout(ports, organizationId) {
|
|
|
384
475
|
}
|
|
385
476
|
return base;
|
|
386
477
|
}
|
|
387
|
-
|
|
388
|
-
// src/menu/headings.ts
|
|
389
|
-
var CONTAINER_WORD = /^(more|more…|more\.\.\.|other|others|misc|miscellaneous|additional|extra|extras|actions|options|advanced|stuff|everything else)$/i;
|
|
390
|
-
function isContainerWord(label) {
|
|
391
|
-
return CONTAINER_WORD.test(label.trim());
|
|
392
|
-
}
|
|
393
|
-
function menuHeadings(model) {
|
|
394
|
-
const out = [];
|
|
395
|
-
const walk = (nodes) => {
|
|
396
|
-
for (const n of nodes) {
|
|
397
|
-
if (n.kind === "submenu") {
|
|
398
|
-
out.push(n.label);
|
|
399
|
-
walk(n.children);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
};
|
|
403
|
-
for (const s of model.sections) {
|
|
404
|
-
if (s.label) out.push(s.label);
|
|
405
|
-
walk(s.nodes);
|
|
406
|
-
}
|
|
407
|
-
return [...new Set(out)];
|
|
408
|
-
}
|
|
409
|
-
function unapprovedHeadings(model, approved) {
|
|
410
|
-
return menuHeadings(model).filter((h) => isContainerWord(h) || !approved.has(h));
|
|
411
|
-
}
|
|
412
478
|
export {
|
|
479
|
+
APPROVED_HEADINGS,
|
|
413
480
|
CATEGORY_GROUP,
|
|
414
481
|
GROUP_ORDER,
|
|
415
482
|
INLINE_SECTION_MAX,
|
|
416
483
|
MENU_LAYOUT_SETTING,
|
|
417
484
|
PLATFORM_MENU_LAYOUT,
|
|
485
|
+
UnapprovedHeadingError,
|
|
418
486
|
actionToNode,
|
|
419
487
|
bar,
|
|
420
488
|
buildMenuModel,
|
|
421
489
|
context,
|
|
490
|
+
defaultHeadingPolicy,
|
|
422
491
|
filterPalette,
|
|
423
492
|
findNode,
|
|
493
|
+
isApprovedHeading,
|
|
424
494
|
isContainerWord,
|
|
425
495
|
layouts,
|
|
426
496
|
leafIds,
|
package/dist/menu.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/menu/model.ts","../src/menu/layouts.ts","../src/menu/knobs.ts","../src/menu/headings.ts"],"sourcesContent":["/**\n * buildMenuModel — WHAT exists at a click target, as one framework-neutral\n * tree (CONTRACT §2.5). Categories GROUP, never gate: eligibility already ran\n * in the registry; this only arranges the resolved set into sections.\n */\nimport type { ActionCategory, ClickTarget, ResolvedAction } from \"../actions/types\";\nimport type { I18nPort } from \"../ports\";\nimport type { MenuGroup, MenuModel, MenuNode, MenuSection, MenuSubmenuNode } from \"./types\";\n\n/** THE category → menu group table (CONTRACT §2.5). */\nexport const CATEGORY_GROUP: Readonly<Record<ActionCategory, MenuGroup>> = {\n clipboard: \"clipboard\",\n copy: \"transfer\",\n export: \"transfer\",\n save: \"document\",\n share: \"document\",\n edit: \"editable\",\n history: \"history\",\n ai: \"ai\",\n ask: \"ai\",\n listen: \"tools\",\n study: \"tools\",\n app: \"tools\",\n feedback: \"quick\",\n creator: \"admin\",\n admin: \"admin\",\n \"surface-info\": \"surface-info\",\n};\n\n/** Classic order of the groups. `surface-info` is engine-built and always last. */\nexport const GROUP_ORDER: readonly MenuGroup[] = [\n \"clipboard\",\n \"editable\",\n \"transfer\",\n \"document\",\n \"history\",\n \"ai\",\n \"tools\",\n \"quick\",\n \"surface\",\n \"admin\",\n \"surface-info\",\n];\n\nconst CATEGORY_ORDER: readonly ActionCategory[] = [\n \"clipboard\",\n \"edit\",\n \"copy\",\n \"export\",\n \"save\",\n \"share\",\n \"history\",\n \"ask\",\n \"ai\",\n \"listen\",\n \"study\",\n \"app\",\n \"feedback\",\n \"creator\",\n \"admin\",\n \"surface-info\",\n];\n\nexport interface BuildMenuModelOptions {\n i18n?: I18nPort;\n /** Content the menu acts on when nothing is selected. */\n content?: string | null;\n}\n\nfunction translate(i18n: I18nPort | undefined, key: string, fallback: string): string {\n if (!i18n) return fallback;\n try {\n return i18n.t(key, fallback);\n } catch {\n return fallback;\n }\n}\n\n/** One resolved action → one model node (item, checkbox, link or lazy submenu). */\nexport function actionToNode(\n resolved: ResolvedAction,\n target: ClickTarget,\n options: BuildMenuModelOptions = {},\n): MenuNode {\n const { action, eligibility } = resolved;\n const rawLabel = typeof action.label === \"function\" ? action.label(target) : action.label;\n const label = translate(options.i18n, action.labelKey ?? action.id, rawLabel);\n const base = {\n id: action.id,\n actionId: action.id,\n ...(action.icon !== undefined ? { icon: action.icon } : {}),\n ...(action.placement !== undefined ? { placement: action.placement } : {}),\n };\n if (action.expand) {\n const node: MenuSubmenuNode = {\n ...base,\n kind: \"submenu\",\n label,\n lazy: true,\n loading: false,\n ...(action.pending?.(target) ? { pending: true } : {}),\n children: [],\n ...(action.emptyLabel !== undefined ? { emptyLabel: action.emptyLabel } : {}),\n };\n return node;\n }\n if (action.href !== undefined) {\n const href = typeof action.href === \"function\" ? action.href(target) : action.href;\n return { ...base, kind: \"link\", label, href };\n }\n if (action.toggle) {\n return {\n ...base,\n kind: \"checkbox\",\n label,\n checked: action.pressed?.(target) ?? false,\n ...(action.description !== undefined ? { description: action.description } : {}),\n };\n }\n const state = action.stateIcon?.(target) ?? null;\n const pressed = action.pressed?.(target);\n const hint = action.hint !== undefined ? translate(options.i18n, action.hintKey ?? `${action.id}.hint`, action.hint) : undefined;\n return {\n ...base,\n kind: \"item\",\n label,\n ...(action.iconTone !== undefined ? { iconTone: action.iconTone } : {}),\n ...(state ? { stateIcon: state } : {}),\n ...(action.description !== undefined ? { description: action.description } : {}),\n ...(hint !== undefined ? { hint } : {}),\n ...(pressed !== undefined ? { pressed } : {}),\n ...(action.destructive ? { destructive: true } : {}),\n ...(action.preserveSelection ? { preserveSelection: true } : {}),\n ...(eligibility.status === \"unavailable-verb\" ? { unavailable: { sentence: eligibility.sentence } } : {}),\n };\n}\n\nexport function buildMenuModel(\n target: ClickTarget,\n resolved: readonly ResolvedAction[],\n options: BuildMenuModelOptions = {},\n): MenuModel {\n const ordered = resolved\n .map((r, index) => ({ r, index }))\n .sort((a, b) => {\n const ca = CATEGORY_ORDER.indexOf(a.r.action.category);\n const cb = CATEGORY_ORDER.indexOf(b.r.action.category);\n if (ca !== cb) return ca - cb;\n const oa = a.r.action.order ?? 0;\n const ob = b.r.action.order ?? 0;\n if (oa !== ob) return oa - ob;\n return a.index - b.index;\n })\n .map((x) => x.r);\n\n const sections = new Map<string, MenuSection>();\n const roles: Record<string, string> = {};\n // An explicit section sits in the group of its first-registered action and\n // keeps its own row order (order, then registration) across categories.\n const explicit = new Map<string, { group: MenuGroup; rows: { r: ResolvedAction; index: number }[] }>();\n resolved.forEach((r, index) => {\n const sec = r.action.section;\n if (!sec) return;\n const entry = explicit.get(sec.id) ?? { group: CATEGORY_GROUP[r.action.category], rows: [] };\n entry.rows.push({ r, index });\n explicit.set(sec.id, entry);\n });\n const placed = new Set<string>();\n for (const r of ordered) {\n const sec = r.action.section;\n if (sec && placed.has(sec.id)) continue;\n const group = sec ? (explicit.get(sec.id)?.group ?? CATEGORY_GROUP[r.action.category]) : CATEGORY_GROUP[r.action.category];\n const sectionId = sec ? `section:${sec.id}` : group;\n let section = sections.get(sectionId);\n if (!section) {\n section = {\n id: sectionId,\n group,\n nodes: [],\n ...(sec ? { label: translate(options.i18n, sec.labelKey ?? `section.${sec.id}`, sec.label) } : {}),\n ...(sec?.icon !== undefined ? { icon: sec.icon } : {}),\n ...(sec?.primary ? { primary: true } : {}),\n };\n sections.set(sectionId, section);\n }\n const rows = sec\n ? (explicit.get(sec.id)?.rows ?? [])\n .sort((x, y) => (x.r.action.order ?? 0) - (y.r.action.order ?? 0) || x.index - y.index)\n .map((x) => x.r)\n : [r];\n if (sec) placed.add(sec.id);\n for (const row of rows) {\n section.nodes.push(actionToNode(row, target, options));\n if (row.action.verb) roles[row.action.verb] = row.action.id;\n }\n }\n\n const list = [...sections.values()].sort((a, b) => {\n if (Boolean(a.primary) !== Boolean(b.primary)) return a.primary ? -1 : 1;\n return GROUP_ORDER.indexOf(a.group) - GROUP_ORDER.indexOf(b.group);\n });\n\n const selected = target.selection?.text?.trim();\n const content = options.content?.trim();\n const header = selected\n ? { label: \"Selected\" as const, text: target.selection?.text ?? \"\" }\n : content\n ? { label: \"Content\" as const, text: options.content ?? \"\" }\n : null;\n\n return { header, sections: list, roles };\n}\n\n/** Fill a lazy submenu's rows once they load (pure: returns a new model). */\nexport function withExpandedChildren(model: MenuModel, nodeId: string, children: MenuNode[] | \"loading\"): MenuModel {\n const visit = (nodes: MenuNode[]): MenuNode[] =>\n nodes.map((n) => {\n if (n.kind !== \"submenu\") return n;\n if (n.id === nodeId) {\n return children === \"loading\" ? { ...n, loading: true } : { ...n, lazy: false, loading: false, pending: false, children };\n }\n return { ...n, children: visit(n.children) };\n });\n return { ...model, sections: model.sections.map((s) => ({ ...s, nodes: visit(s.nodes) })) };\n}\n\n/** Find a node anywhere in a tree. */\nexport function findNode(nodes: readonly MenuNode[], id: string): MenuNode | null {\n for (const n of nodes) {\n if (n.id === id) return n;\n if (n.kind === \"submenu\") {\n const hit = findNode(n.children, id);\n if (hit) return hit;\n }\n }\n return null;\n}\n","/**\n * Layouts — pure arrangements of one MenuModel (CONTRACT §2.5).\n *\n * Every layout is a function over the SAME model: it decides which nodes sit\n * at the top level, which fold under a named submenu and which go into a\n * strip. None adds, drops or renames a leaf — `leafIds(arranged)` equals\n * `leafIds(model)` for every layout (THE LOSSLESS LAW, proven by test).\n *\n * The clipboard group IS the universal verb strip: in the strip layouts it is\n * drawn icon-only; elsewhere its rows are drawn in place. Unavailable verbs\n * (the only greyed nodes, R1 c) appear in every layout identically.\n */\nimport type {\n ArrangedBar,\n ArrangedContext,\n ArrangedPalette,\n ArrangedSelectionToolbar,\n ArrangedSheet,\n ContextArrangement,\n MenuLeafNode,\n MenuModel,\n MenuNode,\n MenuSection,\n MenuSubmenuNode,\n} from \"./types\";\n\n/** A section with more rows than this folds under its label in tiered/command/sheet. */\nexport const INLINE_SECTION_MAX = 3;\n\n/**\n * A section's heading is ONLY the name its actions declare (an approved\n * heading the classic menu already uses: \"Save as\", \"Copy as\", \"History\").\n * A group with no declared name has no heading and is never folded — its rows\n * show inline. The package never coins a heading (chair ruling, ALC-15).\n */\nexport function sectionLabel(section: MenuSection): string | null {\n return section.label ?? null;\n}\n\nfunction isLeaf(node: MenuNode): node is MenuLeafNode {\n return node.kind === \"item\" || node.kind === \"checkbox\" || node.kind === \"link\";\n}\n\n/** Every actionable id in a node list, depth-first. A lazy submenu counts as one leaf. */\nfunction collect(nodes: readonly MenuNode[], out: string[]): void {\n for (const n of nodes) {\n if (isLeaf(n)) out.push(n.id);\n else if (n.kind === \"submenu\") {\n if (n.lazy) out.push(n.id);\n else collect(n.children, out);\n }\n }\n}\n\ntype Arranged =\n | MenuModel\n | ArrangedBar\n | ArrangedContext\n | ArrangedSheet\n | ArrangedPalette\n | ArrangedSelectionToolbar\n | MenuSection[];\n\n/** Proof obligation for every layout: its leaf set equals the model's (sorted, de-duplicated). */\nexport function leafIds(arranged: Arranged): readonly string[] {\n const out: string[] = [];\n if (Array.isArray(arranged)) {\n for (const s of arranged) collect(s.nodes, out);\n } else if (\"leaves\" in arranged) {\n for (const l of arranged.leaves) out.push(l.node.id);\n } else if (\"primary\" in arranged && \"overflow\" in arranged) {\n collect(arranged.primary, out);\n for (const s of arranged.overflow) collect(s.nodes, out);\n } else if (\"root\" in arranged) {\n collect(arranged.strip, out);\n collect(arranged.root, out);\n } else if (\"more\" in arranged) {\n collect(arranged.strip, out);\n for (const s of arranged.more) collect(s.nodes, out);\n } else if (\"filterable\" in arranged) {\n collect(arranged.strip, out);\n for (const s of arranged.sections) collect(s.nodes, out);\n } else {\n for (const s of arranged.sections) collect(s.nodes, out);\n }\n return [...new Set(out)].sort();\n}\n\n/** Only a NAMED section folds; callers check `section.label` first. */\nfunction fold(section: MenuSection & { label: string }): MenuSubmenuNode {\n return {\n kind: \"submenu\",\n id: `${section.id}:fold`,\n label: section.label,\n ...(section.icon !== undefined ? { icon: section.icon } : {}),\n children: section.nodes,\n };\n}\n\nfunction rowCount(nodes: readonly MenuNode[]): number {\n return nodes.filter((n) => n.kind !== \"separator\" && n.kind !== \"label\").length;\n}\n\nfunction stripOf(model: MenuModel): MenuLeafNode[] {\n const clipboard = model.sections.find((s) => s.group === \"clipboard\" && !s.primary);\n return clipboard ? clipboard.nodes.filter(isLeaf) : [];\n}\n\nfunction clipboardRest(model: MenuModel): MenuNode[] {\n const clipboard = model.sections.find((s) => s.group === \"clipboard\" && !s.primary);\n return clipboard ? clipboard.nodes.filter((n) => !isLeaf(n) && n.kind === \"submenu\") : [];\n}\n\nfunction placementOf(node: MenuNode): \"primary\" | \"overflow\" | \"both\" {\n return \"placement\" in node && node.placement ? node.placement : \"overflow\";\n}\n\n/** The historical flat column: every section top-level. */\nfunction classic(model: MenuModel): ArrangedContext {\n return { strip: [], sections: model.sections, filterable: false };\n}\n\n/**\n * Tiered / command: the universal verbs as an icon strip; every other row by\n * its own name; the clicked target's (primary) section first, inline, heading\n * kept; a long non-primary section folds under ITS OWN label (never a coined\n * heading); History is the one approved grouping and already a group.\n */\nfunction tiered(model: MenuModel, filterable: boolean): ArrangedContext {\n const strip = stripOf(model);\n const sections: MenuSection[] = [];\n const rest = clipboardRest(model);\n for (const s of model.sections) {\n if (s.group === \"clipboard\" && !s.primary) {\n if (rest.length) sections.push({ ...s, nodes: rest });\n continue;\n }\n if (s.primary) {\n sections.push(s);\n continue;\n }\n if (!s.label || s.group === \"surface-info\" || rowCount(s.nodes) <= INLINE_SECTION_MAX) {\n // A section keeps its declared heading in EVERY layout (the Lossless\n // Law covers headings: ⋯, the bar's ⋯ and the phone sheet show it too).\n sections.push(s);\n continue;\n }\n sections.push({ id: s.id, group: s.group, nodes: [fold({ ...s, label: s.label })] });\n }\n return { strip, sections, filterable };\n}\n\nexport function context(model: MenuModel, arrangement: ContextArrangement): ArrangedContext {\n if (arrangement === \"classic\") return classic(model);\n return tiered(model, arrangement === \"command\");\n}\n\n/**\n * A long NAMED section folds under its own name (\"Save as ▸\", \"Copy as ▸\");\n * primary sections and unnamed groups stay inline. Folding moves rows, never\n * renames or drops them, and never under a coined heading.\n */\nfunction foldNamed(sections: readonly MenuSection[]): MenuSection[] {\n return sections.map((s) =>\n s.label && !s.primary && rowCount(s.nodes) > INLINE_SECTION_MAX ? { id: s.id, group: s.group, nodes: [fold({ ...s, label: s.label })] } : s,\n );\n}\n\n/** ⋯ overflow: every section in classic order; long named sections fold under their own name. */\nexport function overflow(model: MenuModel): MenuSection[] {\n return foldNamed(model.sections);\n}\n\n/**\n * The action bar: primary buttons inline, EVERYTHING else under ⋯. A \"both\"\n * action is mirrored in both halves (the leaf set is still the model's).\n * `mini` changes presentation only (icon-only primaries), never membership.\n */\nexport function bar(model: MenuModel, _options: { mini?: boolean } = {}): ArrangedBar {\n const primary: MenuNode[] = [];\n const overflowSections: MenuSection[] = [];\n for (const s of model.sections) {\n const rest: MenuNode[] = [];\n for (const n of s.nodes) {\n if (n.kind === \"separator\" || n.kind === \"label\") {\n rest.push(n);\n continue;\n }\n const p = placementOf(n);\n if (p === \"primary\" || p === \"both\") primary.push(n);\n if (p === \"overflow\" || p === \"both\") rest.push(n);\n }\n if (rowCount(rest) > 0) overflowSections.push({ ...s, nodes: rest });\n }\n return { primary, overflow: foldNamed(overflowSections) };\n}\n\n/** Selection toolbar: the verbs plus primary actions as a strip; the rest under More. */\nexport function selectionToolbar(model: MenuModel): ArrangedSelectionToolbar {\n const strip: MenuNode[] = [];\n const more: MenuSection[] = [];\n for (const s of model.sections) {\n const rest: MenuNode[] = [];\n for (const n of s.nodes) {\n const inStrip = (s.group === \"clipboard\" && !s.primary && isLeaf(n)) || placementOf(n) !== \"overflow\";\n if (inStrip) strip.push(n);\n else rest.push(n);\n }\n if (rowCount(rest) > 0) more.push({ ...s, nodes: rest });\n }\n return { strip, more };\n}\n\n/**\n * Mobile bottom sheet: the verb strip on top; primary and short sections\n * inline; longer sections become one drill-down row named by the section.\n * Consumes the model directly, so it can never drift from desktop.\n */\nexport function sheet(model: MenuModel): ArrangedSheet {\n const strip = stripOf(model);\n const root: MenuNode[] = [];\n const rest = clipboardRest(model);\n for (const s of model.sections) {\n const nodes = s.group === \"clipboard\" && !s.primary ? rest : s.nodes;\n if (rowCount(nodes) === 0) continue;\n if (root.length) root.push({ kind: \"separator\", id: `${s.id}:sep` });\n if (s.primary || !s.label || rowCount(nodes) <= INLINE_SECTION_MAX) {\n if (s.label) root.push({ kind: \"label\", id: `${s.id}:label`, label: s.label });\n root.push(...nodes);\n } else {\n root.push(fold({ ...s, label: s.label, nodes }));\n }\n }\n return { strip, root };\n}\n\n/** Command palette: every leaf flattened with its breadcrumb (Linear). */\nexport function palette(model: MenuModel): ArrangedPalette {\n const leaves: ArrangedPalette[\"leaves\"] = [];\n const walk = (nodes: readonly MenuNode[], trail: string[]) => {\n for (const n of nodes) {\n if (isLeaf(n)) leaves.push({ node: n, breadcrumb: trail });\n else if (n.kind === \"submenu\") {\n if (n.lazy) leaves.push({ node: n, breadcrumb: trail });\n else walk(n.children, [...trail, n.label]);\n }\n }\n };\n for (const s of model.sections) walk(s.nodes, s.label ? [s.label] : []);\n return { leaves };\n}\n\n/** Filter the palette by a query (every word must match label or breadcrumb). */\nexport function filterPalette(arranged: ArrangedPalette, query: string): ArrangedPalette {\n const words = query.toLowerCase().split(/\\s+/).filter(Boolean);\n if (!words.length) return arranged;\n return {\n leaves: arranged.leaves.filter((l) => {\n const hay = `${l.node.label} ${l.breadcrumb.join(\" \")}`.toLowerCase();\n return words.every((w) => hay.includes(w));\n }),\n };\n}\n\nexport const layouts = { bar, overflow, context, selectionToolbar, sheet, palette };\n","/**\n * N9: layout and density are a PERSON's choice layered over the organization\n * default: persistence (\"alchemy.menu.layout\") → knobs.layout(org) → platform\n * default (command / comfortable, Arman 2026-08-22).\n */\nimport type { AlchemyHostPorts, ContextArrangementKnob, DensityKnob } from \"../ports\";\n\nexport const PLATFORM_MENU_LAYOUT: { context: ContextArrangementKnob; density: DensityKnob } = {\n context: \"command\",\n density: \"comfortable\",\n};\n\nexport const MENU_LAYOUT_SETTING = \"alchemy.menu.layout\";\n\nconst ARRANGEMENTS = new Set<string>([\"classic\", \"tiered\", \"command\"]);\nconst DENSITIES = new Set<string>([\"comfortable\", \"compact\"]);\n\nexport async function resolveMenuLayout(\n ports: Pick<AlchemyHostPorts, \"persistence\" | \"knobs\">,\n organizationId: string | null,\n): Promise<{ context: ContextArrangementKnob; density: DensityKnob }> {\n const org = ports.knobs?.layout(organizationId) ?? null;\n const base = { ...PLATFORM_MENU_LAYOUT, ...(org ?? {}) };\n let own: unknown = null;\n try {\n own = (await ports.persistence?.readSetting(MENU_LAYOUT_SETTING)) ?? null;\n } catch {\n own = null;\n }\n if (own && typeof own === \"object\" && !Array.isArray(own)) {\n const o = own as { context?: unknown; density?: unknown };\n return {\n context: typeof o.context === \"string\" && ARRANGEMENTS.has(o.context) ? (o.context as ContextArrangementKnob) : base.context,\n density: typeof o.density === \"string\" && DENSITIES.has(o.density) ? (o.density as DensityKnob) : base.density,\n };\n }\n return base;\n}\n","/**\n * THE LOSSLESS LAW for headings (ALC-15, chair ruling 7). A heading a person\n * sees — a named section, a fold, a group submenu — must be a name the classic\n * menus already use (the host's approved set: \"Save as\", \"Copy as\", \"History\",\n * a surface's own section label…). A generic container word (\"More…\", \"Other\",\n * \"Actions\") names no content and is never approved, whatever a host passes:\n * rows a lane wants to tidy away stay inline instead.\n */\nimport type { MenuModel, MenuNode } from \"./types\";\n\nconst CONTAINER_WORD = /^(more|more…|more\\.\\.\\.|other|others|misc|miscellaneous|additional|extra|extras|actions|options|advanced|stuff|everything else)$/i;\n\nexport function isContainerWord(label: string): boolean {\n return CONTAINER_WORD.test(label.trim());\n}\n\n/** Every heading in a model: section labels, folds, and submenu rows at any depth. */\nexport function menuHeadings(model: Pick<MenuModel, \"sections\">): string[] {\n const out: string[] = [];\n const walk = (nodes: readonly MenuNode[]) => {\n for (const n of nodes) {\n if (n.kind === \"submenu\") {\n out.push(n.label);\n walk(n.children);\n }\n }\n };\n for (const s of model.sections) {\n if (s.label) out.push(s.label);\n walk(s.nodes);\n }\n return [...new Set(out)];\n}\n\n/** Headings that are not in the approved set (container words are never approved). */\nexport function unapprovedHeadings(model: Pick<MenuModel, \"sections\">, approved: ReadonlySet<string>): string[] {\n return menuHeadings(model).filter((h) => isContainerWord(h) || !approved.has(h));\n}\n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AK,CAAC,SAAS,IAAI,CAAC,CAAC;AACjF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/menu/headings.ts","../src/menu/model.ts","../src/menu/layouts.ts","../src/menu/knobs.ts"],"sourcesContent":["/**\n * THE ONE APPROVED-HEADING LIST (ALC-15, chair rulings 7 and D1; the Lossless\n * Law and the vocabulary law). A heading a person sees above or around rows\n * must be a name the classic menus used before agents started coining names.\n *\n * 🚨 ADDING A HEADING TO THIS LIST IS ARMAN'S CALL — never an agent's.\n *\n * Two kinds of section heading exist:\n * - a GROUP heading (\"Copy as\", \"History\"): must be in APPROVED_HEADINGS;\n * - a TARGET label, the thing the person clicked, supplied by the surface at\n * run time (\"Cell · Visit date\", \"Row · Widget A\", \"This finding\", the\n * surface's own label): allowed as declared (`section.kind: \"target\"`, or\n * the \"<Target> · <name>\" shape), except a generic container word.\n * A generic container word (\"More…\", \"Other\", \"Actions\") is never a heading.\n * An unapproved heading renders its rows INLINE in production; in development\n * and tests `buildMenuModel` throws with the remedy.\n */\nimport type { MenuModel, MenuNode } from \"./types\";\n\n/** Names with their provenance (the commit where each classic menu used them). */\nexport const APPROVED_HEADINGS: ReadonlySet<string> = new Set([\n \"Save\", // rich-document menuStructure, e5b8d01229 (2026-05-19)\n \"Copy as\", // rich-document menuStructure, e5b8d01229 (2026-05-19)\n \"Export\", // rich-document menuStructure, e5b8d01229 (2026-05-19)\n \"Edit\", // rich-document menuStructure, e5b8d01229 (2026-05-19)\n \"Creator tools\", // rich-document menuStructure, e5b8d01229 (2026-05-19)\n \"Admin\", // rich-document menuStructure, e5b8d01229 (2026-05-19)\n \"App\", // rich-document menuStructure, e5b8d01229 (2026-05-19)\n \"Compare\", // rich-document menuStructure, 2e3a8a9fdf (2026-06-11)\n \"History\", // context-menu-v3 tiered layout — the one grouping Arman approved, 2026-08-22\n]);\n\nconst CONTAINER_WORD =\n /^(more|more…|more\\.\\.\\.|other|others|misc|miscellaneous|additional|extra|extras|actions|options|advanced|stuff|everything else)$/i;\n\n/** \"Cell · Visit date\", \"Row · Widget A\", \"Column · Price\", \"Table · Route sheet\". */\nconst TARGET_SHAPE = /^(Cell|Row|Column|Table|Range|Selection|Record) · .+$/;\n\nexport function isContainerWord(label: string): boolean {\n return CONTAINER_WORD.test(label.trim());\n}\n\nexport type HeadingKind = \"group\" | \"target\";\n\n/** Is this heading allowed? */\nexport function isApprovedHeading(label: string, kind: HeadingKind = \"group\", approved: ReadonlySet<string> = APPROVED_HEADINGS): boolean {\n const l = label.trim();\n if (!l || isContainerWord(l)) return false;\n if (approved.has(l)) return true;\n return kind === \"target\" || TARGET_SHAPE.test(l);\n}\n\nexport type HeadingPolicy = \"throw\" | \"inline\";\n\n/** Development and tests throw; production shows the rows inline. */\nexport function defaultHeadingPolicy(): HeadingPolicy {\n const env = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env?.NODE_ENV;\n return env === \"production\" ? \"inline\" : \"throw\";\n}\n\nexport class UnapprovedHeadingError extends Error {\n readonly heading: string;\n constructor(heading: string, where: string) {\n super(\n `Menu heading \"${heading}\" (${where}) is not an approved heading. Remedy: show these rows inline — declare no section ` +\n `(or kind \"target\" for the clicked thing's own label) — or ask Arman to add the name to APPROVED_HEADINGS in ` +\n `@ai-matrx/alchemy/menu. A generic container word (\"More…\", \"Other\") is never approved.`,\n );\n this.name = \"UnapprovedHeadingError\";\n this.heading = heading;\n }\n}\n\n/** Every heading in a model: section labels, folds, and submenu rows at any depth. */\nexport function menuHeadings(model: Pick<MenuModel, \"sections\">): string[] {\n const out: string[] = [];\n const walk = (nodes: readonly MenuNode[]) => {\n for (const n of nodes) {\n if (n.kind === \"submenu\") {\n out.push(n.label);\n walk(n.children);\n }\n }\n };\n for (const s of model.sections) {\n if (s.label) out.push(s.label);\n walk(s.nodes);\n }\n return [...new Set(out)];\n}\n\n/** Section headings not in the approved set (container words are never approved). */\nexport function unapprovedHeadings(model: Pick<MenuModel, \"sections\">, approved: ReadonlySet<string> = APPROVED_HEADINGS): string[] {\n const out = new Set<string>();\n for (const s of model.sections) {\n if (s.label && !isApprovedHeading(s.label, s.primary || s.target ? \"target\" : \"group\", approved)) out.add(s.label);\n const walk = (nodes: readonly MenuNode[]) => {\n for (const n of nodes) if (n.kind === \"submenu\") {\n if (isContainerWord(n.label)) out.add(n.label);\n walk(n.children);\n }\n };\n walk(s.nodes);\n }\n return [...out];\n}\n","/**\n * buildMenuModel — WHAT exists at a click target, as one framework-neutral\n * tree (CONTRACT §2.5). Categories GROUP, never gate: eligibility already ran\n * in the registry; this only arranges the resolved set into sections.\n */\nimport type { ActionCategory, ClickTarget, ResolvedAction } from \"../actions/types\";\nimport type { I18nPort } from \"../ports\";\nimport type { MenuGroup, MenuModel, MenuNode, MenuSection, MenuSubmenuNode } from \"./types\";\nimport { UnapprovedHeadingError, defaultHeadingPolicy, isApprovedHeading, isContainerWord, type HeadingPolicy } from \"./headings\";\n\n/** THE category → menu group table (CONTRACT §2.5). */\nexport const CATEGORY_GROUP: Readonly<Record<ActionCategory, MenuGroup>> = {\n clipboard: \"clipboard\",\n copy: \"transfer\",\n export: \"transfer\",\n save: \"document\",\n share: \"document\",\n edit: \"editable\",\n history: \"history\",\n ai: \"ai\",\n ask: \"ai\",\n listen: \"tools\",\n study: \"tools\",\n app: \"tools\",\n feedback: \"quick\",\n creator: \"admin\",\n admin: \"admin\",\n \"surface-info\": \"surface-info\",\n};\n\n/** Classic order of the groups. `surface-info` is engine-built and always last. */\nexport const GROUP_ORDER: readonly MenuGroup[] = [\n \"clipboard\",\n \"editable\",\n \"transfer\",\n \"document\",\n \"history\",\n \"ai\",\n \"tools\",\n \"quick\",\n \"surface\",\n \"admin\",\n \"surface-info\",\n];\n\nconst CATEGORY_ORDER: readonly ActionCategory[] = [\n \"clipboard\",\n \"edit\",\n \"copy\",\n \"export\",\n \"save\",\n \"share\",\n \"history\",\n \"ask\",\n \"ai\",\n \"listen\",\n \"study\",\n \"app\",\n \"feedback\",\n \"creator\",\n \"admin\",\n \"surface-info\",\n];\n\nexport interface BuildMenuModelOptions {\n /** What an unapproved heading does: \"throw\" (development/tests) or \"inline\" (production). */\n headingPolicy?: HeadingPolicy;\n i18n?: I18nPort;\n /** Content the menu acts on when nothing is selected. */\n content?: string | null;\n}\n\nfunction translate(i18n: I18nPort | undefined, key: string, fallback: string): string {\n if (!i18n) return fallback;\n try {\n return i18n.t(key, fallback);\n } catch {\n return fallback;\n }\n}\n\n/** One resolved action → one model node (item, checkbox, link or lazy submenu). */\nexport function actionToNode(\n resolved: ResolvedAction,\n target: ClickTarget,\n options: BuildMenuModelOptions = {},\n): MenuNode {\n const { action, eligibility } = resolved;\n const rawLabel = typeof action.label === \"function\" ? action.label(target) : action.label;\n const label = translate(options.i18n, action.labelKey ?? action.id, rawLabel);\n const base = {\n id: action.id,\n actionId: action.id,\n ...(action.icon !== undefined ? { icon: action.icon } : {}),\n ...(action.placement !== undefined ? { placement: action.placement } : {}),\n };\n if (action.expand) {\n const node: MenuSubmenuNode = {\n ...base,\n kind: \"submenu\",\n label,\n lazy: true,\n loading: false,\n ...(action.pending?.(target) ? { pending: true } : {}),\n children: [],\n ...(action.emptyLabel !== undefined ? { emptyLabel: action.emptyLabel } : {}),\n };\n return node;\n }\n if (action.href !== undefined) {\n const href = typeof action.href === \"function\" ? action.href(target) : action.href;\n return { ...base, kind: \"link\", label, href };\n }\n if (action.toggle) {\n return {\n ...base,\n kind: \"checkbox\",\n label,\n checked: action.pressed?.(target) ?? false,\n ...(action.description !== undefined ? { description: action.description } : {}),\n };\n }\n const state = action.stateIcon?.(target) ?? null;\n const pressed = action.pressed?.(target);\n const hint = action.hint !== undefined ? translate(options.i18n, action.hintKey ?? `${action.id}.hint`, action.hint) : undefined;\n return {\n ...base,\n kind: \"item\",\n label,\n ...(action.iconTone !== undefined ? { iconTone: action.iconTone } : {}),\n ...(state ? { stateIcon: state } : {}),\n ...(action.description !== undefined ? { description: action.description } : {}),\n ...(hint !== undefined ? { hint } : {}),\n ...(pressed !== undefined ? { pressed } : {}),\n ...(action.destructive ? { destructive: true } : {}),\n ...(action.preserveSelection ? { preserveSelection: true } : {}),\n ...(eligibility.status === \"unavailable-verb\" ? { unavailable: { sentence: eligibility.sentence } } : {}),\n };\n}\n\nexport function buildMenuModel(\n target: ClickTarget,\n resolved: readonly ResolvedAction[],\n options: BuildMenuModelOptions = {},\n): MenuModel {\n // THE ONE HEADING CHECK, for every host: an unapproved heading's rows go\n // inline (production) or the build throws with the remedy (dev/tests).\n const policy = options.headingPolicy ?? defaultHeadingPolicy();\n resolved = resolved.map((r) => {\n const sec = r.action.section;\n if (r.action.expand && isContainerWord(typeof r.action.label === \"string\" ? r.action.label : \"\") && policy === \"throw\") {\n throw new UnapprovedHeadingError(r.action.label as string, `submenu of ${r.action.id}`);\n }\n if (!sec) return r;\n const kind = sec.kind ?? (sec.primary ? \"target\" : \"group\");\n if (isApprovedHeading(sec.label, kind)) return r;\n if (policy === \"throw\") throw new UnapprovedHeadingError(sec.label, `section of ${r.action.id}`);\n const { section: _dropped, ...rest } = r.action;\n return { ...r, action: rest };\n });\n const ordered = resolved\n .map((r, index) => ({ r, index }))\n .sort((a, b) => {\n const ca = CATEGORY_ORDER.indexOf(a.r.action.category);\n const cb = CATEGORY_ORDER.indexOf(b.r.action.category);\n if (ca !== cb) return ca - cb;\n const oa = a.r.action.order ?? 0;\n const ob = b.r.action.order ?? 0;\n if (oa !== ob) return oa - ob;\n return a.index - b.index;\n })\n .map((x) => x.r);\n\n const sections = new Map<string, MenuSection>();\n const roles: Record<string, string> = {};\n // An explicit section sits in the group of its first-registered action and\n // keeps its own row order (order, then registration) across categories.\n const explicit = new Map<string, { group: MenuGroup; rows: { r: ResolvedAction; index: number }[] }>();\n resolved.forEach((r, index) => {\n const sec = r.action.section;\n if (!sec) return;\n const entry = explicit.get(sec.id) ?? { group: CATEGORY_GROUP[r.action.category], rows: [] };\n entry.rows.push({ r, index });\n explicit.set(sec.id, entry);\n });\n const placed = new Set<string>();\n for (const r of ordered) {\n const sec = r.action.section;\n if (sec && placed.has(sec.id)) continue;\n const group = sec ? (explicit.get(sec.id)?.group ?? CATEGORY_GROUP[r.action.category]) : CATEGORY_GROUP[r.action.category];\n const sectionId = sec ? `section:${sec.id}` : group;\n let section = sections.get(sectionId);\n if (!section) {\n section = {\n id: sectionId,\n group,\n nodes: [],\n ...(sec ? { label: translate(options.i18n, sec.labelKey ?? `section.${sec.id}`, sec.label) } : {}),\n ...(sec?.icon !== undefined ? { icon: sec.icon } : {}),\n ...(sec?.primary ? { primary: true } : {}),\n ...(sec && (sec.kind ?? (sec.primary ? \"target\" : \"group\")) === \"target\" ? { target: true } : {}),\n };\n sections.set(sectionId, section);\n }\n const rows = sec\n ? (explicit.get(sec.id)?.rows ?? [])\n .sort((x, y) => (x.r.action.order ?? 0) - (y.r.action.order ?? 0) || x.index - y.index)\n .map((x) => x.r)\n : [r];\n if (sec) placed.add(sec.id);\n for (const row of rows) {\n section.nodes.push(actionToNode(row, target, options));\n if (row.action.verb) roles[row.action.verb] = row.action.id;\n }\n }\n\n const list = [...sections.values()].sort((a, b) => {\n if (Boolean(a.primary) !== Boolean(b.primary)) return a.primary ? -1 : 1;\n return GROUP_ORDER.indexOf(a.group) - GROUP_ORDER.indexOf(b.group);\n });\n\n const selected = target.selection?.text?.trim();\n const content = options.content?.trim();\n const header = selected\n ? { label: \"Selected\" as const, text: target.selection?.text ?? \"\" }\n : content\n ? { label: \"Content\" as const, text: options.content ?? \"\" }\n : null;\n\n return { header, sections: list, roles };\n}\n\n/** Fill a lazy submenu's rows once they load (pure: returns a new model). */\nexport function withExpandedChildren(model: MenuModel, nodeId: string, children: MenuNode[] | \"loading\"): MenuModel {\n const visit = (nodes: MenuNode[]): MenuNode[] =>\n nodes.map((n) => {\n if (n.kind !== \"submenu\") return n;\n if (n.id === nodeId) {\n return children === \"loading\" ? { ...n, loading: true } : { ...n, lazy: false, loading: false, pending: false, children };\n }\n return { ...n, children: visit(n.children) };\n });\n return { ...model, sections: model.sections.map((s) => ({ ...s, nodes: visit(s.nodes) })) };\n}\n\n/** Find a node anywhere in a tree. */\nexport function findNode(nodes: readonly MenuNode[], id: string): MenuNode | null {\n for (const n of nodes) {\n if (n.id === id) return n;\n if (n.kind === \"submenu\") {\n const hit = findNode(n.children, id);\n if (hit) return hit;\n }\n }\n return null;\n}\n","/**\n * Layouts — pure arrangements of one MenuModel (CONTRACT §2.5).\n *\n * Every layout is a function over the SAME model: it decides which nodes sit\n * at the top level, which fold under a named submenu and which go into a\n * strip. None adds, drops or renames a leaf — `leafIds(arranged)` equals\n * `leafIds(model)` for every layout (THE LOSSLESS LAW, proven by test).\n *\n * The clipboard group IS the universal verb strip: in the strip layouts it is\n * drawn icon-only; elsewhere its rows are drawn in place. Unavailable verbs\n * (the only greyed nodes, R1 c) appear in every layout identically.\n */\nimport type {\n ArrangedBar,\n ArrangedContext,\n ArrangedPalette,\n ArrangedSelectionToolbar,\n ArrangedSheet,\n ContextArrangement,\n MenuLeafNode,\n MenuModel,\n MenuNode,\n MenuSection,\n MenuSubmenuNode,\n} from \"./types\";\n\n/** A section with more rows than this folds under its label in tiered/command/sheet. */\nexport const INLINE_SECTION_MAX = 3;\n\n/**\n * A section's heading is ONLY the name its actions declare (an approved\n * heading the classic menu already uses: \"Save as\", \"Copy as\", \"History\").\n * A group with no declared name has no heading and is never folded — its rows\n * show inline. The package never coins a heading (chair ruling, ALC-15).\n */\nexport function sectionLabel(section: MenuSection): string | null {\n return section.label ?? null;\n}\n\nfunction isLeaf(node: MenuNode): node is MenuLeafNode {\n return node.kind === \"item\" || node.kind === \"checkbox\" || node.kind === \"link\";\n}\n\n/** Every actionable id in a node list, depth-first. A lazy submenu counts as one leaf. */\nfunction collect(nodes: readonly MenuNode[], out: string[]): void {\n for (const n of nodes) {\n if (isLeaf(n)) out.push(n.id);\n else if (n.kind === \"submenu\") {\n if (n.lazy) out.push(n.id);\n else collect(n.children, out);\n }\n }\n}\n\ntype Arranged =\n | MenuModel\n | ArrangedBar\n | ArrangedContext\n | ArrangedSheet\n | ArrangedPalette\n | ArrangedSelectionToolbar\n | MenuSection[];\n\n/** Proof obligation for every layout: its leaf set equals the model's (sorted, de-duplicated). */\nexport function leafIds(arranged: Arranged): readonly string[] {\n const out: string[] = [];\n if (Array.isArray(arranged)) {\n for (const s of arranged) collect(s.nodes, out);\n } else if (\"leaves\" in arranged) {\n for (const l of arranged.leaves) out.push(l.node.id);\n } else if (\"primary\" in arranged && \"overflow\" in arranged) {\n collect(arranged.primary, out);\n for (const s of arranged.overflow) collect(s.nodes, out);\n } else if (\"root\" in arranged) {\n collect(arranged.strip, out);\n collect(arranged.root, out);\n } else if (\"more\" in arranged) {\n collect(arranged.strip, out);\n for (const s of arranged.more) collect(s.nodes, out);\n } else if (\"filterable\" in arranged) {\n collect(arranged.strip, out);\n for (const s of arranged.sections) collect(s.nodes, out);\n } else {\n for (const s of arranged.sections) collect(s.nodes, out);\n }\n return [...new Set(out)].sort();\n}\n\n/** Only a NAMED section folds; callers check `section.label` first. */\nfunction fold(section: MenuSection & { label: string }): MenuSubmenuNode {\n return {\n kind: \"submenu\",\n id: `${section.id}:fold`,\n label: section.label,\n ...(section.icon !== undefined ? { icon: section.icon } : {}),\n children: section.nodes,\n };\n}\n\nfunction rowCount(nodes: readonly MenuNode[]): number {\n return nodes.filter((n) => n.kind !== \"separator\" && n.kind !== \"label\").length;\n}\n\nfunction stripOf(model: MenuModel): MenuLeafNode[] {\n const clipboard = model.sections.find((s) => s.group === \"clipboard\" && !s.primary);\n return clipboard ? clipboard.nodes.filter(isLeaf) : [];\n}\n\nfunction clipboardRest(model: MenuModel): MenuNode[] {\n const clipboard = model.sections.find((s) => s.group === \"clipboard\" && !s.primary);\n return clipboard ? clipboard.nodes.filter((n) => !isLeaf(n) && n.kind === \"submenu\") : [];\n}\n\nfunction placementOf(node: MenuNode): \"primary\" | \"overflow\" | \"both\" {\n return \"placement\" in node && node.placement ? node.placement : \"overflow\";\n}\n\n/** The historical flat column: every section top-level. */\nfunction classic(model: MenuModel): ArrangedContext {\n return { strip: [], sections: model.sections, filterable: false };\n}\n\n/**\n * Tiered / command: the universal verbs as an icon strip; every other row by\n * its own name; the clicked target's (primary) section first, inline, heading\n * kept; a long non-primary section folds under ITS OWN label (never a coined\n * heading); History is the one approved grouping and already a group.\n */\nfunction tiered(model: MenuModel, filterable: boolean): ArrangedContext {\n const strip = stripOf(model);\n const sections: MenuSection[] = [];\n const rest = clipboardRest(model);\n for (const s of model.sections) {\n if (s.group === \"clipboard\" && !s.primary) {\n if (rest.length) sections.push({ ...s, nodes: rest });\n continue;\n }\n if (s.primary) {\n sections.push(s);\n continue;\n }\n if (!s.label || s.group === \"surface-info\" || rowCount(s.nodes) <= INLINE_SECTION_MAX) {\n // A section keeps its declared heading in EVERY layout (the Lossless\n // Law covers headings: ⋯, the bar's ⋯ and the phone sheet show it too).\n sections.push(s);\n continue;\n }\n sections.push({ id: s.id, group: s.group, nodes: [fold({ ...s, label: s.label })] });\n }\n return { strip, sections, filterable };\n}\n\nexport function context(model: MenuModel, arrangement: ContextArrangement): ArrangedContext {\n if (arrangement === \"classic\") return classic(model);\n return tiered(model, arrangement === \"command\");\n}\n\n/**\n * A long NAMED section folds under its own name (\"Save as ▸\", \"Copy as ▸\");\n * primary sections and unnamed groups stay inline. Folding moves rows, never\n * renames or drops them, and never under a coined heading.\n */\nfunction foldNamed(sections: readonly MenuSection[]): MenuSection[] {\n return sections.map((s) =>\n s.label && !s.primary && rowCount(s.nodes) > INLINE_SECTION_MAX ? { id: s.id, group: s.group, nodes: [fold({ ...s, label: s.label })] } : s,\n );\n}\n\n/** ⋯ overflow: every section in classic order; long named sections fold under their own name. */\nexport function overflow(model: MenuModel): MenuSection[] {\n return foldNamed(model.sections);\n}\n\n/**\n * The action bar: primary buttons inline, EVERYTHING else under ⋯. A \"both\"\n * action is mirrored in both halves (the leaf set is still the model's).\n * `mini` changes presentation only (icon-only primaries), never membership.\n */\nexport function bar(model: MenuModel, _options: { mini?: boolean } = {}): ArrangedBar {\n const primary: MenuNode[] = [];\n const overflowSections: MenuSection[] = [];\n for (const s of model.sections) {\n const rest: MenuNode[] = [];\n for (const n of s.nodes) {\n if (n.kind === \"separator\" || n.kind === \"label\") {\n rest.push(n);\n continue;\n }\n const p = placementOf(n);\n if (p === \"primary\" || p === \"both\") primary.push(n);\n if (p === \"overflow\" || p === \"both\") rest.push(n);\n }\n if (rowCount(rest) > 0) overflowSections.push({ ...s, nodes: rest });\n }\n return { primary, overflow: foldNamed(overflowSections) };\n}\n\n/** Selection toolbar: the verbs plus primary actions as a strip; the rest under More. */\nexport function selectionToolbar(model: MenuModel): ArrangedSelectionToolbar {\n const strip: MenuNode[] = [];\n const more: MenuSection[] = [];\n for (const s of model.sections) {\n const rest: MenuNode[] = [];\n for (const n of s.nodes) {\n const inStrip = (s.group === \"clipboard\" && !s.primary && isLeaf(n)) || placementOf(n) !== \"overflow\";\n if (inStrip) strip.push(n);\n else rest.push(n);\n }\n if (rowCount(rest) > 0) more.push({ ...s, nodes: rest });\n }\n return { strip, more };\n}\n\n/**\n * Mobile bottom sheet: the verb strip on top; primary and short sections\n * inline; longer sections become one drill-down row named by the section.\n * Consumes the model directly, so it can never drift from desktop.\n */\nexport function sheet(model: MenuModel): ArrangedSheet {\n const strip = stripOf(model);\n const root: MenuNode[] = [];\n const rest = clipboardRest(model);\n for (const s of model.sections) {\n const nodes = s.group === \"clipboard\" && !s.primary ? rest : s.nodes;\n if (rowCount(nodes) === 0) continue;\n if (root.length) root.push({ kind: \"separator\", id: `${s.id}:sep` });\n if (s.primary || !s.label || rowCount(nodes) <= INLINE_SECTION_MAX) {\n if (s.label) root.push({ kind: \"label\", id: `${s.id}:label`, label: s.label });\n root.push(...nodes);\n } else {\n root.push(fold({ ...s, label: s.label, nodes }));\n }\n }\n return { strip, root };\n}\n\n/** Command palette: every leaf flattened with its breadcrumb (Linear). */\nexport function palette(model: MenuModel): ArrangedPalette {\n const leaves: ArrangedPalette[\"leaves\"] = [];\n const walk = (nodes: readonly MenuNode[], trail: string[]) => {\n for (const n of nodes) {\n if (isLeaf(n)) leaves.push({ node: n, breadcrumb: trail });\n else if (n.kind === \"submenu\") {\n if (n.lazy) leaves.push({ node: n, breadcrumb: trail });\n else walk(n.children, [...trail, n.label]);\n }\n }\n };\n for (const s of model.sections) walk(s.nodes, s.label ? [s.label] : []);\n return { leaves };\n}\n\n/** Filter the palette by a query (every word must match label or breadcrumb). */\nexport function filterPalette(arranged: ArrangedPalette, query: string): ArrangedPalette {\n const words = query.toLowerCase().split(/\\s+/).filter(Boolean);\n if (!words.length) return arranged;\n return {\n leaves: arranged.leaves.filter((l) => {\n const hay = `${l.node.label} ${l.breadcrumb.join(\" \")}`.toLowerCase();\n return words.every((w) => hay.includes(w));\n }),\n };\n}\n\nexport const layouts = { bar, overflow, context, selectionToolbar, sheet, palette };\n","/**\n * N9: layout and density are a PERSON's choice layered over the organization\n * default: persistence (\"alchemy.menu.layout\") → knobs.layout(org) → platform\n * default (command / comfortable, Arman 2026-08-22).\n */\nimport type { AlchemyHostPorts, ContextArrangementKnob, DensityKnob } from \"../ports\";\n\nexport const PLATFORM_MENU_LAYOUT: { context: ContextArrangementKnob; density: DensityKnob } = {\n context: \"command\",\n density: \"comfortable\",\n};\n\nexport const MENU_LAYOUT_SETTING = \"alchemy.menu.layout\";\n\nconst ARRANGEMENTS = new Set<string>([\"classic\", \"tiered\", \"command\"]);\nconst DENSITIES = new Set<string>([\"comfortable\", \"compact\"]);\n\nexport async function resolveMenuLayout(\n ports: Pick<AlchemyHostPorts, \"persistence\" | \"knobs\">,\n organizationId: string | null,\n): Promise<{ context: ContextArrangementKnob; density: DensityKnob }> {\n const org = ports.knobs?.layout(organizationId) ?? null;\n const base = { ...PLATFORM_MENU_LAYOUT, ...(org ?? {}) };\n let own: unknown = null;\n try {\n own = (await ports.persistence?.readSetting(MENU_LAYOUT_SETTING)) ?? null;\n } catch {\n own = null;\n }\n if (own && typeof own === \"object\" && !Array.isArray(own)) {\n const o = own as { context?: unknown; density?: unknown };\n return {\n context: typeof o.context === \"string\" && ARRANGEMENTS.has(o.context) ? (o.context as ContextArrangementKnob) : base.context,\n density: typeof o.density === \"string\" && DENSITIES.has(o.density) ? (o.density as DensityKnob) : base.density,\n };\n }\n return base;\n}\n"],"mappings":";AAoBO,IAAM,oBAAyC,oBAAI,IAAI;AAAA,EAC5D;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AACF,CAAC;AAED,IAAM,iBACJ;AAGF,IAAM,eAAe;AAEd,SAAS,gBAAgB,OAAwB;AACtD,SAAO,eAAe,KAAK,MAAM,KAAK,CAAC;AACzC;AAKO,SAAS,kBAAkB,OAAe,OAAoB,SAAS,WAAgC,mBAA4B;AACxI,QAAM,IAAI,MAAM,KAAK;AACrB,MAAI,CAAC,KAAK,gBAAgB,CAAC,EAAG,QAAO;AACrC,MAAI,SAAS,IAAI,CAAC,EAAG,QAAO;AAC5B,SAAO,SAAS,YAAY,aAAa,KAAK,CAAC;AACjD;AAKO,SAAS,uBAAsC;AACpD,QAAM,MAAO,WAA0E,SAAS,KAAK;AACrG,SAAO,QAAQ,eAAe,WAAW;AAC3C;AAEO,IAAM,yBAAN,cAAqC,MAAM;AAAA,EACvC;AAAA,EACT,YAAY,SAAiB,OAAe;AAC1C;AAAA,MACE,iBAAiB,OAAO,MAAM,KAAK;AAAA,IAGrC;AACA,SAAK,OAAO;AACZ,SAAK,UAAU;AAAA,EACjB;AACF;AAGO,SAAS,aAAa,OAA8C;AACzE,QAAM,MAAgB,CAAC;AACvB,QAAM,OAAO,CAAC,UAA+B;AAC3C,eAAW,KAAK,OAAO;AACrB,UAAI,EAAE,SAAS,WAAW;AACxB,YAAI,KAAK,EAAE,KAAK;AAChB,aAAK,EAAE,QAAQ;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AAC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AAO,QAAQ;;;ACjQ3E,IAAM,uBAAkF;AAAA,EAC7F,SAAS;AAAA,EACT,SAAS;AACX;AAEO,IAAM,sBAAsB;AAEnC,IAAM,eAAe,oBAAI,IAAY,CAAC,WAAW,UAAU,SAAS,CAAC;AACrE,IAAM,YAAY,oBAAI,IAAY,CAAC,eAAe,SAAS,CAAC;AAE5D,eAAsB,kBACpB,OACA,gBACoE;AACpE,QAAM,MAAM,MAAM,OAAO,OAAO,cAAc,KAAK;AACnD,QAAM,OAAO,EAAE,GAAG,sBAAsB,GAAI,OAAO,CAAC,EAAG;AACvD,MAAI,MAAe;AACnB,MAAI;AACF,UAAO,MAAM,MAAM,aAAa,YAAY,mBAAmB,KAAM;AAAA,EACvE,QAAQ;AACN,UAAM;AAAA,EACR;AACA,MAAI,OAAO,OAAO,QAAQ,YAAY,CAAC,MAAM,QAAQ,GAAG,GAAG;AACzD,UAAM,IAAI;AACV,WAAO;AAAA,MACL,SAAS,OAAO,EAAE,YAAY,YAAY,aAAa,IAAI,EAAE,OAAO,IAAK,EAAE,UAAqC,KAAK;AAAA,MACrH,SAAS,OAAO,EAAE,YAAY,YAAY,UAAU,IAAI,EAAE,OAAO,IAAK,EAAE,UAA0B,KAAK;AAAA,IACzG;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
package/dist/react-bar.cjs
CHANGED
|
@@ -194,6 +194,53 @@ async function runAction(action, target, options) {
|
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
// src/menu/headings.ts
|
|
198
|
+
var APPROVED_HEADINGS = /* @__PURE__ */ new Set([
|
|
199
|
+
"Save",
|
|
200
|
+
// rich-document menuStructure, e5b8d01229 (2026-05-19)
|
|
201
|
+
"Copy as",
|
|
202
|
+
// rich-document menuStructure, e5b8d01229 (2026-05-19)
|
|
203
|
+
"Export",
|
|
204
|
+
// rich-document menuStructure, e5b8d01229 (2026-05-19)
|
|
205
|
+
"Edit",
|
|
206
|
+
// rich-document menuStructure, e5b8d01229 (2026-05-19)
|
|
207
|
+
"Creator tools",
|
|
208
|
+
// rich-document menuStructure, e5b8d01229 (2026-05-19)
|
|
209
|
+
"Admin",
|
|
210
|
+
// rich-document menuStructure, e5b8d01229 (2026-05-19)
|
|
211
|
+
"App",
|
|
212
|
+
// rich-document menuStructure, e5b8d01229 (2026-05-19)
|
|
213
|
+
"Compare",
|
|
214
|
+
// rich-document menuStructure, 2e3a8a9fdf (2026-06-11)
|
|
215
|
+
"History"
|
|
216
|
+
// context-menu-v3 tiered layout — the one grouping Arman approved, 2026-08-22
|
|
217
|
+
]);
|
|
218
|
+
var CONTAINER_WORD = /^(more|more…|more\.\.\.|other|others|misc|miscellaneous|additional|extra|extras|actions|options|advanced|stuff|everything else)$/i;
|
|
219
|
+
var TARGET_SHAPE = /^(Cell|Row|Column|Table|Range|Selection|Record) · .+$/;
|
|
220
|
+
function isContainerWord(label) {
|
|
221
|
+
return CONTAINER_WORD.test(label.trim());
|
|
222
|
+
}
|
|
223
|
+
function isApprovedHeading(label, kind = "group", approved = APPROVED_HEADINGS) {
|
|
224
|
+
const l = label.trim();
|
|
225
|
+
if (!l || isContainerWord(l)) return false;
|
|
226
|
+
if (approved.has(l)) return true;
|
|
227
|
+
return kind === "target" || TARGET_SHAPE.test(l);
|
|
228
|
+
}
|
|
229
|
+
function defaultHeadingPolicy() {
|
|
230
|
+
const env = globalThis.process?.env?.NODE_ENV;
|
|
231
|
+
return env === "production" ? "inline" : "throw";
|
|
232
|
+
}
|
|
233
|
+
var UnapprovedHeadingError = class extends Error {
|
|
234
|
+
heading;
|
|
235
|
+
constructor(heading, where) {
|
|
236
|
+
super(
|
|
237
|
+
`Menu heading "${heading}" (${where}) is not an approved heading. Remedy: show these rows inline \u2014 declare no section (or kind "target" for the clicked thing's own label) \u2014 or ask Arman to add the name to APPROVED_HEADINGS in @ai-matrx/alchemy/menu. A generic container word ("More\u2026", "Other") is never approved.`
|
|
238
|
+
);
|
|
239
|
+
this.name = "UnapprovedHeadingError";
|
|
240
|
+
this.heading = heading;
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
|
|
197
244
|
// src/menu/model.ts
|
|
198
245
|
var CATEGORY_GROUP = {
|
|
199
246
|
clipboard: "clipboard",
|
|
@@ -306,6 +353,19 @@ function actionToNode(resolved, target, options = {}) {
|
|
|
306
353
|
};
|
|
307
354
|
}
|
|
308
355
|
function buildMenuModel(target, resolved, options = {}) {
|
|
356
|
+
const policy = options.headingPolicy ?? defaultHeadingPolicy();
|
|
357
|
+
resolved = resolved.map((r) => {
|
|
358
|
+
const sec = r.action.section;
|
|
359
|
+
if (r.action.expand && isContainerWord(typeof r.action.label === "string" ? r.action.label : "") && policy === "throw") {
|
|
360
|
+
throw new UnapprovedHeadingError(r.action.label, `submenu of ${r.action.id}`);
|
|
361
|
+
}
|
|
362
|
+
if (!sec) return r;
|
|
363
|
+
const kind = sec.kind ?? (sec.primary ? "target" : "group");
|
|
364
|
+
if (isApprovedHeading(sec.label, kind)) return r;
|
|
365
|
+
if (policy === "throw") throw new UnapprovedHeadingError(sec.label, `section of ${r.action.id}`);
|
|
366
|
+
const { section: _dropped, ...rest } = r.action;
|
|
367
|
+
return { ...r, action: rest };
|
|
368
|
+
});
|
|
309
369
|
const ordered = resolved.map((r, index) => ({ r, index })).sort((a, b) => {
|
|
310
370
|
const ca = CATEGORY_ORDER.indexOf(a.r.action.category);
|
|
311
371
|
const cb = CATEGORY_ORDER.indexOf(b.r.action.category);
|
|
@@ -339,7 +399,8 @@ function buildMenuModel(target, resolved, options = {}) {
|
|
|
339
399
|
nodes: [],
|
|
340
400
|
...sec ? { label: translate(options.i18n, sec.labelKey ?? `section.${sec.id}`, sec.label) } : {},
|
|
341
401
|
...sec?.icon !== void 0 ? { icon: sec.icon } : {},
|
|
342
|
-
...sec?.primary ? { primary: true } : {}
|
|
402
|
+
...sec?.primary ? { primary: true } : {},
|
|
403
|
+
...sec && (sec.kind ?? (sec.primary ? "target" : "group")) === "target" ? { target: true } : {}
|
|
343
404
|
};
|
|
344
405
|
sections.set(sectionId, section);
|
|
345
406
|
}
|
|
@@ -398,10 +459,38 @@ function useMenuEngine(target, options = {}) {
|
|
|
398
459
|
const [model, setModel] = React2.useState(null);
|
|
399
460
|
const [tick, setTick] = React2.useState(0);
|
|
400
461
|
const expanded = React2.useRef(/* @__PURE__ */ new Map());
|
|
462
|
+
const opened = React2.useRef(/* @__PURE__ */ new Set());
|
|
463
|
+
const expandSeq = React2.useRef(/* @__PURE__ */ new Map());
|
|
401
464
|
const active = options.active ?? true;
|
|
402
465
|
const optionsRef = React2.useRef(options);
|
|
403
466
|
optionsRef.current = options;
|
|
404
467
|
React2.useEffect(() => registry.subscribe(() => setTick((t) => t + 1)), [registry]);
|
|
468
|
+
const expandAction = React2.useCallback(
|
|
469
|
+
async (action, nodeId) => {
|
|
470
|
+
if (!target || !action.expand) return;
|
|
471
|
+
const seq = (expandSeq.current.get(nodeId) ?? 0) + 1;
|
|
472
|
+
expandSeq.current.set(nodeId, seq);
|
|
473
|
+
const latest = () => expandSeq.current.get(nodeId) === seq;
|
|
474
|
+
setModel((m) => m ? withExpandedChildren(m, nodeId, "loading") : m);
|
|
475
|
+
try {
|
|
476
|
+
const children = await action.expand(target, new AbortController().signal);
|
|
477
|
+
if (!latest()) return;
|
|
478
|
+
const nodes = children.map((child) => {
|
|
479
|
+
expanded.current.set(child.id, child);
|
|
480
|
+
return actionToNode({ action: child, eligibility: { status: "available" } }, target, ports.i18n ? { i18n: ports.i18n } : {});
|
|
481
|
+
});
|
|
482
|
+
setModel((m) => m ? withExpandedChildren(m, nodeId, nodes) : m);
|
|
483
|
+
} catch (error) {
|
|
484
|
+
if (!latest()) return;
|
|
485
|
+
ports.diagnostics.capture(error, { area: "menu", detail: { nodeId, stage: "expand" } });
|
|
486
|
+
setModel((m) => m ? withExpandedChildren(m, nodeId, []) : m);
|
|
487
|
+
}
|
|
488
|
+
},
|
|
489
|
+
[target, ports]
|
|
490
|
+
);
|
|
491
|
+
React2.useEffect(() => {
|
|
492
|
+
opened.current.clear();
|
|
493
|
+
}, [target]);
|
|
405
494
|
React2.useEffect(() => {
|
|
406
495
|
if (!target || !active) return;
|
|
407
496
|
let live = true;
|
|
@@ -410,11 +499,15 @@ function useMenuEngine(target, options = {}) {
|
|
|
410
499
|
expanded.current.clear();
|
|
411
500
|
setResolved(list);
|
|
412
501
|
setModel(buildMenuModel(target, list, { ...ports.i18n ? { i18n: ports.i18n } : {}, content: optionsRef.current.content ?? null }));
|
|
502
|
+
for (const id of opened.current) {
|
|
503
|
+
const action = list.find((r) => r.action.id === id)?.action;
|
|
504
|
+
if (action?.expand) void expandAction(action, id);
|
|
505
|
+
}
|
|
413
506
|
});
|
|
414
507
|
return () => {
|
|
415
508
|
live = false;
|
|
416
509
|
};
|
|
417
|
-
}, [registry, ports, target, active, tick, options.revision]);
|
|
510
|
+
}, [registry, ports, target, active, tick, options.revision, expandAction]);
|
|
418
511
|
const resolvedRef = React2.useRef(resolved);
|
|
419
512
|
resolvedRef.current = resolved;
|
|
420
513
|
const subscribedIds = resolved.map((r) => r.action.id).join("\n");
|
|
@@ -453,20 +546,10 @@ function useMenuEngine(target, options = {}) {
|
|
|
453
546
|
async (nodeId) => {
|
|
454
547
|
const action = findAction(nodeId);
|
|
455
548
|
if (!target || !action?.expand) return;
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
const children = await action.expand(target, new AbortController().signal);
|
|
459
|
-
const nodes = children.map((child) => {
|
|
460
|
-
expanded.current.set(child.id, child);
|
|
461
|
-
return actionToNode({ action: child, eligibility: { status: "available" } }, target, ports.i18n ? { i18n: ports.i18n } : {});
|
|
462
|
-
});
|
|
463
|
-
setModel((m) => m ? withExpandedChildren(m, nodeId, nodes) : m);
|
|
464
|
-
} catch (error) {
|
|
465
|
-
ports.diagnostics.capture(error, { area: "menu", detail: { nodeId, stage: "expand" } });
|
|
466
|
-
setModel((m) => m ? withExpandedChildren(m, nodeId, []) : m);
|
|
467
|
-
}
|
|
549
|
+
opened.current.add(nodeId);
|
|
550
|
+
await expandAction(action, nodeId);
|
|
468
551
|
},
|
|
469
|
-
[findAction, target,
|
|
552
|
+
[findAction, target, expandAction]
|
|
470
553
|
);
|
|
471
554
|
const icon = React2.useCallback(
|
|
472
555
|
(key, tone) => {
|