@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/dist/menu.cjs CHANGED
@@ -20,17 +20,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/menu.ts
21
21
  var menu_exports = {};
22
22
  __export(menu_exports, {
23
+ APPROVED_HEADINGS: () => APPROVED_HEADINGS,
23
24
  CATEGORY_GROUP: () => CATEGORY_GROUP,
24
25
  GROUP_ORDER: () => GROUP_ORDER,
25
26
  INLINE_SECTION_MAX: () => INLINE_SECTION_MAX,
26
27
  MENU_LAYOUT_SETTING: () => MENU_LAYOUT_SETTING,
27
28
  PLATFORM_MENU_LAYOUT: () => PLATFORM_MENU_LAYOUT,
29
+ UnapprovedHeadingError: () => UnapprovedHeadingError,
28
30
  actionToNode: () => actionToNode,
29
31
  bar: () => bar,
30
32
  buildMenuModel: () => buildMenuModel,
31
33
  context: () => context,
34
+ defaultHeadingPolicy: () => defaultHeadingPolicy,
32
35
  filterPalette: () => filterPalette,
33
36
  findNode: () => findNode,
37
+ isApprovedHeading: () => isApprovedHeading,
34
38
  isContainerWord: () => isContainerWord,
35
39
  layouts: () => layouts,
36
40
  leafIds: () => leafIds,
@@ -46,6 +50,83 @@ __export(menu_exports, {
46
50
  });
47
51
  module.exports = __toCommonJS(menu_exports);
48
52
 
53
+ // src/menu/headings.ts
54
+ var APPROVED_HEADINGS = /* @__PURE__ */ new Set([
55
+ "Save",
56
+ // rich-document menuStructure, e5b8d01229 (2026-05-19)
57
+ "Copy as",
58
+ // rich-document menuStructure, e5b8d01229 (2026-05-19)
59
+ "Export",
60
+ // rich-document menuStructure, e5b8d01229 (2026-05-19)
61
+ "Edit",
62
+ // rich-document menuStructure, e5b8d01229 (2026-05-19)
63
+ "Creator tools",
64
+ // rich-document menuStructure, e5b8d01229 (2026-05-19)
65
+ "Admin",
66
+ // rich-document menuStructure, e5b8d01229 (2026-05-19)
67
+ "App",
68
+ // rich-document menuStructure, e5b8d01229 (2026-05-19)
69
+ "Compare",
70
+ // rich-document menuStructure, 2e3a8a9fdf (2026-06-11)
71
+ "History"
72
+ // context-menu-v3 tiered layout — the one grouping Arman approved, 2026-08-22
73
+ ]);
74
+ var CONTAINER_WORD = /^(more|more…|more\.\.\.|other|others|misc|miscellaneous|additional|extra|extras|actions|options|advanced|stuff|everything else)$/i;
75
+ var TARGET_SHAPE = /^(Cell|Row|Column|Table|Range|Selection|Record) · .+$/;
76
+ function isContainerWord(label) {
77
+ return CONTAINER_WORD.test(label.trim());
78
+ }
79
+ function isApprovedHeading(label, kind = "group", approved = APPROVED_HEADINGS) {
80
+ const l = label.trim();
81
+ if (!l || isContainerWord(l)) return false;
82
+ if (approved.has(l)) return true;
83
+ return kind === "target" || TARGET_SHAPE.test(l);
84
+ }
85
+ function defaultHeadingPolicy() {
86
+ const env = globalThis.process?.env?.NODE_ENV;
87
+ return env === "production" ? "inline" : "throw";
88
+ }
89
+ var UnapprovedHeadingError = class extends Error {
90
+ heading;
91
+ constructor(heading, where) {
92
+ super(
93
+ `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.`
94
+ );
95
+ this.name = "UnapprovedHeadingError";
96
+ this.heading = heading;
97
+ }
98
+ };
99
+ function menuHeadings(model) {
100
+ const out = [];
101
+ const walk = (nodes) => {
102
+ for (const n of nodes) {
103
+ if (n.kind === "submenu") {
104
+ out.push(n.label);
105
+ walk(n.children);
106
+ }
107
+ }
108
+ };
109
+ for (const s of model.sections) {
110
+ if (s.label) out.push(s.label);
111
+ walk(s.nodes);
112
+ }
113
+ return [...new Set(out)];
114
+ }
115
+ function unapprovedHeadings(model, approved = APPROVED_HEADINGS) {
116
+ const out = /* @__PURE__ */ new Set();
117
+ for (const s of model.sections) {
118
+ if (s.label && !isApprovedHeading(s.label, s.primary || s.target ? "target" : "group", approved)) out.add(s.label);
119
+ const walk = (nodes) => {
120
+ for (const n of nodes) if (n.kind === "submenu") {
121
+ if (isContainerWord(n.label)) out.add(n.label);
122
+ walk(n.children);
123
+ }
124
+ };
125
+ walk(s.nodes);
126
+ }
127
+ return [...out];
128
+ }
129
+
49
130
  // src/menu/model.ts
50
131
  var CATEGORY_GROUP = {
51
132
  clipboard: "clipboard",
@@ -158,6 +239,19 @@ function actionToNode(resolved, target, options = {}) {
158
239
  };
159
240
  }
160
241
  function buildMenuModel(target, resolved, options = {}) {
242
+ const policy = options.headingPolicy ?? defaultHeadingPolicy();
243
+ resolved = resolved.map((r) => {
244
+ const sec = r.action.section;
245
+ if (r.action.expand && isContainerWord(typeof r.action.label === "string" ? r.action.label : "") && policy === "throw") {
246
+ throw new UnapprovedHeadingError(r.action.label, `submenu of ${r.action.id}`);
247
+ }
248
+ if (!sec) return r;
249
+ const kind = sec.kind ?? (sec.primary ? "target" : "group");
250
+ if (isApprovedHeading(sec.label, kind)) return r;
251
+ if (policy === "throw") throw new UnapprovedHeadingError(sec.label, `section of ${r.action.id}`);
252
+ const { section: _dropped, ...rest } = r.action;
253
+ return { ...r, action: rest };
254
+ });
161
255
  const ordered = resolved.map((r, index) => ({ r, index })).sort((a, b) => {
162
256
  const ca = CATEGORY_ORDER.indexOf(a.r.action.category);
163
257
  const cb = CATEGORY_ORDER.indexOf(b.r.action.category);
@@ -191,7 +285,8 @@ function buildMenuModel(target, resolved, options = {}) {
191
285
  nodes: [],
192
286
  ...sec ? { label: translate(options.i18n, sec.labelKey ?? `section.${sec.id}`, sec.label) } : {},
193
287
  ...sec?.icon !== void 0 ? { icon: sec.icon } : {},
194
- ...sec?.primary ? { primary: true } : {}
288
+ ...sec?.primary ? { primary: true } : {},
289
+ ...sec && (sec.kind ?? (sec.primary ? "target" : "group")) === "target" ? { target: true } : {}
195
290
  };
196
291
  sections.set(sectionId, section);
197
292
  }
@@ -432,29 +527,4 @@ async function resolveMenuLayout(ports, organizationId) {
432
527
  }
433
528
  return base;
434
529
  }
435
-
436
- // src/menu/headings.ts
437
- var CONTAINER_WORD = /^(more|more…|more\.\.\.|other|others|misc|miscellaneous|additional|extra|extras|actions|options|advanced|stuff|everything else)$/i;
438
- function isContainerWord(label) {
439
- return CONTAINER_WORD.test(label.trim());
440
- }
441
- function menuHeadings(model) {
442
- const out = [];
443
- const walk = (nodes) => {
444
- for (const n of nodes) {
445
- if (n.kind === "submenu") {
446
- out.push(n.label);
447
- walk(n.children);
448
- }
449
- }
450
- };
451
- for (const s of model.sections) {
452
- if (s.label) out.push(s.label);
453
- walk(s.nodes);
454
- }
455
- return [...new Set(out)];
456
- }
457
- function unapprovedHeadings(model, approved) {
458
- return menuHeadings(model).filter((h) => isContainerWord(h) || !approved.has(h));
459
- }
460
530
  //# sourceMappingURL=menu.cjs.map
package/dist/menu.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/menu.ts","../src/menu/model.ts","../src/menu/layouts.ts","../src/menu/knobs.ts","../src/menu/headings.ts"],"sourcesContent":["/**\n * `@ai-matrx/alchemy/menu` — the one menu model and its pure layouts\n * (Matrx Alchemy CONTRACT §2.5). Framework-neutral: icons are keys, no React.\n */\nexport type {\n ArrangedBar,\n ArrangedContext,\n ArrangedPalette,\n ArrangedSelectionToolbar,\n ArrangedSheet,\n ContextArrangement,\n Density,\n LayoutName,\n MenuCheckboxNode,\n MenuGroup,\n MenuItemNode,\n MenuLabelNode,\n MenuLeafNode,\n MenuLinkNode,\n MenuModel,\n MenuNode,\n MenuSection,\n MenuSeparatorNode,\n MenuSubmenuNode,\n} from \"./menu/types\";\nexport {\n CATEGORY_GROUP,\n GROUP_ORDER,\n actionToNode,\n buildMenuModel,\n findNode,\n withExpandedChildren,\n type BuildMenuModelOptions,\n} from \"./menu/model\";\nexport {\n INLINE_SECTION_MAX,\n bar,\n context,\n filterPalette,\n layouts,\n leafIds,\n overflow,\n palette,\n sectionLabel,\n selectionToolbar,\n sheet,\n} from \"./menu/layouts\";\nexport { MENU_LAYOUT_SETTING, PLATFORM_MENU_LAYOUT, resolveMenuLayout } from \"./menu/knobs\";\nexport { isContainerWord, menuHeadings, unapprovedHeadings } from \"./menu/headings\";\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\";\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUO,IAAM,iBAA8D;AAAA,EACzE,WAAW;AAAA,EACX,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AAAA,EACN,SAAS;AAAA,EACT,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,KAAK;AAAA,EACL,UAAU;AAAA,EACV,SAAS;AAAA,EACT,OAAO;AAAA,EACP,gBAAgB;AAClB;AAGO,IAAM,cAAoC;AAAA,EAC/C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAM,iBAA4C;AAAA,EAChD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAQA,SAAS,UAAU,MAA4B,KAAa,UAA0B;AACpF,MAAI,CAAC,KAAM,QAAO;AAClB,MAAI;A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GO,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;AACA,aAAW,KAAK,MAAM,UAAU;AAC9B,QAAI,EAAE,MAAO,KAAI,KAAK,EAAE,KAAK;AAC7B,SAAK,EAAE,KAAK;AAAA,EACd;AACA,SAAO,CAAC,GAAG,IAAI,IAAI,GAAG,CAAC;AACzB;AAGO,SAAS,mBAAmB,OAAoC,UAAyC;AAC9G,SAAO,aAAa,KAAK,EAAE,OAAO,CAAC,MAAM,gBAAgB,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,CAAC;AACjF;","names":[]}
1
+ {"version":3,"sources":["../src/menu.ts","../src/menu/headings.ts","../src/menu/model.ts","../src/menu/layouts.ts","../src/menu/knobs.ts"],"sourcesContent":["/**\n * `@ai-matrx/alchemy/menu` — the one menu model and its pure layouts\n * (Matrx Alchemy CONTRACT §2.5). Framework-neutral: icons are keys, no React.\n */\nexport type {\n ArrangedBar,\n ArrangedContext,\n ArrangedPalette,\n ArrangedSelectionToolbar,\n ArrangedSheet,\n ContextArrangement,\n Density,\n LayoutName,\n MenuCheckboxNode,\n MenuGroup,\n MenuItemNode,\n MenuLabelNode,\n MenuLeafNode,\n MenuLinkNode,\n MenuModel,\n MenuNode,\n MenuSection,\n MenuSeparatorNode,\n MenuSubmenuNode,\n} from \"./menu/types\";\nexport {\n CATEGORY_GROUP,\n GROUP_ORDER,\n actionToNode,\n buildMenuModel,\n findNode,\n withExpandedChildren,\n type BuildMenuModelOptions,\n} from \"./menu/model\";\nexport {\n INLINE_SECTION_MAX,\n bar,\n context,\n filterPalette,\n layouts,\n leafIds,\n overflow,\n palette,\n sectionLabel,\n selectionToolbar,\n sheet,\n} from \"./menu/layouts\";\nexport { MENU_LAYOUT_SETTING, PLATFORM_MENU_LAYOUT, resolveMenuLayout } from \"./menu/knobs\";\nexport {\n APPROVED_HEADINGS,\n UnapprovedHeadingError,\n defaultHeadingPolicy,\n isApprovedHeading,\n isContainerWord,\n menuHeadings,\n unapprovedHeadings,\n type HeadingKind,\n type HeadingPolicy,\n} from \"./menu/headings\";\n","/**\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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACoBO,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;A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,SAAO;AAAA,IACL,QAAQ,SAAS,OAAO,OAAO,CAAC,MAAM;AACpC,YAAM,MAAM,GAAG,EAAE,KAAK,KAAK,IAAI,EAAE,WAAW,KAAK,GAAG,CAAC,GAAG,YAAY;AACpE,aAAO,MAAM,MAAM,CAAC,MAAM,IAAI,SAAS,CAAC,CAAC;AAAA,IAC3C,CAAC;AAAA,EACH;AACF;AAEO,IAAM,UAAU,EAAE,KAAK,UAAU,SAAS,kBAAkB,OAAO,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/menu.d.cts CHANGED
@@ -77,6 +77,8 @@ interface MenuSection {
77
77
  id: string;
78
78
  group: MenuGroup;
79
79
  label?: string;
80
+ /** The label names the clicked target (run-time), not a group. */
81
+ target?: boolean;
80
82
  icon?: string;
81
83
  primary?: boolean;
82
84
  nodes: MenuNode[];
@@ -650,6 +652,12 @@ interface ActionSection {
650
652
  labelKey?: string;
651
653
  icon?: string;
652
654
  primary?: boolean;
655
+ /**
656
+ * "group" (default): a heading over related rows — must be in the package's
657
+ * APPROVED_HEADINGS (@ai-matrx/alchemy/menu). "target": the label of the
658
+ * thing the person clicked, supplied at run time ("Row · Widget A").
659
+ */
660
+ kind?: "group" | "target";
653
661
  }
654
662
  interface Action {
655
663
  /** Globally unique. A duplicate is refused (never overwritten). */
@@ -743,6 +751,42 @@ interface ResolvedAction {
743
751
  }>;
744
752
  }
745
753
 
754
+ /**
755
+ * THE ONE APPROVED-HEADING LIST (ALC-15, chair rulings 7 and D1; the Lossless
756
+ * Law and the vocabulary law). A heading a person sees above or around rows
757
+ * must be a name the classic menus used before agents started coining names.
758
+ *
759
+ * 🚨 ADDING A HEADING TO THIS LIST IS ARMAN'S CALL — never an agent's.
760
+ *
761
+ * Two kinds of section heading exist:
762
+ * - a GROUP heading ("Copy as", "History"): must be in APPROVED_HEADINGS;
763
+ * - a TARGET label, the thing the person clicked, supplied by the surface at
764
+ * run time ("Cell · Visit date", "Row · Widget A", "This finding", the
765
+ * surface's own label): allowed as declared (`section.kind: "target"`, or
766
+ * the "<Target> · <name>" shape), except a generic container word.
767
+ * A generic container word ("More…", "Other", "Actions") is never a heading.
768
+ * An unapproved heading renders its rows INLINE in production; in development
769
+ * and tests `buildMenuModel` throws with the remedy.
770
+ */
771
+
772
+ /** Names with their provenance (the commit where each classic menu used them). */
773
+ declare const APPROVED_HEADINGS: ReadonlySet<string>;
774
+ declare function isContainerWord(label: string): boolean;
775
+ type HeadingKind = "group" | "target";
776
+ /** Is this heading allowed? */
777
+ declare function isApprovedHeading(label: string, kind?: HeadingKind, approved?: ReadonlySet<string>): boolean;
778
+ type HeadingPolicy = "throw" | "inline";
779
+ /** Development and tests throw; production shows the rows inline. */
780
+ declare function defaultHeadingPolicy(): HeadingPolicy;
781
+ declare class UnapprovedHeadingError extends Error {
782
+ readonly heading: string;
783
+ constructor(heading: string, where: string);
784
+ }
785
+ /** Every heading in a model: section labels, folds, and submenu rows at any depth. */
786
+ declare function menuHeadings(model: Pick<MenuModel, "sections">): string[];
787
+ /** Section headings not in the approved set (container words are never approved). */
788
+ declare function unapprovedHeadings(model: Pick<MenuModel, "sections">, approved?: ReadonlySet<string>): string[];
789
+
746
790
  /**
747
791
  * buildMenuModel — WHAT exists at a click target, as one framework-neutral
748
792
  * tree (CONTRACT §2.5). Categories GROUP, never gate: eligibility already ran
@@ -754,6 +798,8 @@ declare const CATEGORY_GROUP: Readonly<Record<ActionCategory, MenuGroup>>;
754
798
  /** Classic order of the groups. `surface-info` is engine-built and always last. */
755
799
  declare const GROUP_ORDER: readonly MenuGroup[];
756
800
  interface BuildMenuModelOptions {
801
+ /** What an unapproved heading does: "throw" (development/tests) or "inline" (production). */
802
+ headingPolicy?: HeadingPolicy;
757
803
  i18n?: I18nPort;
758
804
  /** Content the menu acts on when nothing is selected. */
759
805
  content?: string | null;
@@ -839,19 +885,4 @@ declare function resolveMenuLayout(ports: Pick<AlchemyHostPorts, "persistence" |
839
885
  density: DensityKnob;
840
886
  }>;
841
887
 
842
- /**
843
- * THE LOSSLESS LAW for headings (ALC-15, chair ruling 7). A heading a person
844
- * sees — a named section, a fold, a group submenu — must be a name the classic
845
- * menus already use (the host's approved set: "Save as", "Copy as", "History",
846
- * a surface's own section label…). A generic container word ("More…", "Other",
847
- * "Actions") names no content and is never approved, whatever a host passes:
848
- * rows a lane wants to tidy away stay inline instead.
849
- */
850
-
851
- declare function isContainerWord(label: string): boolean;
852
- /** Every heading in a model: section labels, folds, and submenu rows at any depth. */
853
- declare function menuHeadings(model: Pick<MenuModel, "sections">): string[];
854
- /** Headings that are not in the approved set (container words are never approved). */
855
- declare function unapprovedHeadings(model: Pick<MenuModel, "sections">, approved: ReadonlySet<string>): string[];
856
-
857
- export { type ArrangedBar, type ArrangedContext, type ArrangedPalette, type ArrangedSelectionToolbar, type ArrangedSheet, type BuildMenuModelOptions, CATEGORY_GROUP, type ContextArrangement, type Density, GROUP_ORDER, INLINE_SECTION_MAX, type LayoutName, MENU_LAYOUT_SETTING, type MenuCheckboxNode, type MenuGroup, type MenuItemNode, type MenuLabelNode, type MenuLeafNode, type MenuLinkNode, type MenuModel, type MenuNode, type MenuSection, type MenuSeparatorNode, type MenuSubmenuNode, PLATFORM_MENU_LAYOUT, actionToNode, bar, buildMenuModel, context, filterPalette, findNode, isContainerWord, layouts, leafIds, menuHeadings, overflow, palette, resolveMenuLayout, sectionLabel, selectionToolbar, sheet, unapprovedHeadings, withExpandedChildren };
888
+ export { APPROVED_HEADINGS, type ArrangedBar, type ArrangedContext, type ArrangedPalette, type ArrangedSelectionToolbar, type ArrangedSheet, type BuildMenuModelOptions, CATEGORY_GROUP, type ContextArrangement, type Density, GROUP_ORDER, type HeadingKind, type HeadingPolicy, INLINE_SECTION_MAX, type LayoutName, MENU_LAYOUT_SETTING, type MenuCheckboxNode, type MenuGroup, type MenuItemNode, type MenuLabelNode, type MenuLeafNode, type MenuLinkNode, type MenuModel, type MenuNode, type MenuSection, type MenuSeparatorNode, type MenuSubmenuNode, PLATFORM_MENU_LAYOUT, UnapprovedHeadingError, actionToNode, bar, buildMenuModel, context, defaultHeadingPolicy, filterPalette, findNode, isApprovedHeading, isContainerWord, layouts, leafIds, menuHeadings, overflow, palette, resolveMenuLayout, sectionLabel, selectionToolbar, sheet, unapprovedHeadings, withExpandedChildren };
package/dist/menu.d.ts CHANGED
@@ -77,6 +77,8 @@ interface MenuSection {
77
77
  id: string;
78
78
  group: MenuGroup;
79
79
  label?: string;
80
+ /** The label names the clicked target (run-time), not a group. */
81
+ target?: boolean;
80
82
  icon?: string;
81
83
  primary?: boolean;
82
84
  nodes: MenuNode[];
@@ -650,6 +652,12 @@ interface ActionSection {
650
652
  labelKey?: string;
651
653
  icon?: string;
652
654
  primary?: boolean;
655
+ /**
656
+ * "group" (default): a heading over related rows — must be in the package's
657
+ * APPROVED_HEADINGS (@ai-matrx/alchemy/menu). "target": the label of the
658
+ * thing the person clicked, supplied at run time ("Row · Widget A").
659
+ */
660
+ kind?: "group" | "target";
653
661
  }
654
662
  interface Action {
655
663
  /** Globally unique. A duplicate is refused (never overwritten). */
@@ -743,6 +751,42 @@ interface ResolvedAction {
743
751
  }>;
744
752
  }
745
753
 
754
+ /**
755
+ * THE ONE APPROVED-HEADING LIST (ALC-15, chair rulings 7 and D1; the Lossless
756
+ * Law and the vocabulary law). A heading a person sees above or around rows
757
+ * must be a name the classic menus used before agents started coining names.
758
+ *
759
+ * 🚨 ADDING A HEADING TO THIS LIST IS ARMAN'S CALL — never an agent's.
760
+ *
761
+ * Two kinds of section heading exist:
762
+ * - a GROUP heading ("Copy as", "History"): must be in APPROVED_HEADINGS;
763
+ * - a TARGET label, the thing the person clicked, supplied by the surface at
764
+ * run time ("Cell · Visit date", "Row · Widget A", "This finding", the
765
+ * surface's own label): allowed as declared (`section.kind: "target"`, or
766
+ * the "<Target> · <name>" shape), except a generic container word.
767
+ * A generic container word ("More…", "Other", "Actions") is never a heading.
768
+ * An unapproved heading renders its rows INLINE in production; in development
769
+ * and tests `buildMenuModel` throws with the remedy.
770
+ */
771
+
772
+ /** Names with their provenance (the commit where each classic menu used them). */
773
+ declare const APPROVED_HEADINGS: ReadonlySet<string>;
774
+ declare function isContainerWord(label: string): boolean;
775
+ type HeadingKind = "group" | "target";
776
+ /** Is this heading allowed? */
777
+ declare function isApprovedHeading(label: string, kind?: HeadingKind, approved?: ReadonlySet<string>): boolean;
778
+ type HeadingPolicy = "throw" | "inline";
779
+ /** Development and tests throw; production shows the rows inline. */
780
+ declare function defaultHeadingPolicy(): HeadingPolicy;
781
+ declare class UnapprovedHeadingError extends Error {
782
+ readonly heading: string;
783
+ constructor(heading: string, where: string);
784
+ }
785
+ /** Every heading in a model: section labels, folds, and submenu rows at any depth. */
786
+ declare function menuHeadings(model: Pick<MenuModel, "sections">): string[];
787
+ /** Section headings not in the approved set (container words are never approved). */
788
+ declare function unapprovedHeadings(model: Pick<MenuModel, "sections">, approved?: ReadonlySet<string>): string[];
789
+
746
790
  /**
747
791
  * buildMenuModel — WHAT exists at a click target, as one framework-neutral
748
792
  * tree (CONTRACT §2.5). Categories GROUP, never gate: eligibility already ran
@@ -754,6 +798,8 @@ declare const CATEGORY_GROUP: Readonly<Record<ActionCategory, MenuGroup>>;
754
798
  /** Classic order of the groups. `surface-info` is engine-built and always last. */
755
799
  declare const GROUP_ORDER: readonly MenuGroup[];
756
800
  interface BuildMenuModelOptions {
801
+ /** What an unapproved heading does: "throw" (development/tests) or "inline" (production). */
802
+ headingPolicy?: HeadingPolicy;
757
803
  i18n?: I18nPort;
758
804
  /** Content the menu acts on when nothing is selected. */
759
805
  content?: string | null;
@@ -839,19 +885,4 @@ declare function resolveMenuLayout(ports: Pick<AlchemyHostPorts, "persistence" |
839
885
  density: DensityKnob;
840
886
  }>;
841
887
 
842
- /**
843
- * THE LOSSLESS LAW for headings (ALC-15, chair ruling 7). A heading a person
844
- * sees — a named section, a fold, a group submenu — must be a name the classic
845
- * menus already use (the host's approved set: "Save as", "Copy as", "History",
846
- * a surface's own section label…). A generic container word ("More…", "Other",
847
- * "Actions") names no content and is never approved, whatever a host passes:
848
- * rows a lane wants to tidy away stay inline instead.
849
- */
850
-
851
- declare function isContainerWord(label: string): boolean;
852
- /** Every heading in a model: section labels, folds, and submenu rows at any depth. */
853
- declare function menuHeadings(model: Pick<MenuModel, "sections">): string[];
854
- /** Headings that are not in the approved set (container words are never approved). */
855
- declare function unapprovedHeadings(model: Pick<MenuModel, "sections">, approved: ReadonlySet<string>): string[];
856
-
857
- export { type ArrangedBar, type ArrangedContext, type ArrangedPalette, type ArrangedSelectionToolbar, type ArrangedSheet, type BuildMenuModelOptions, CATEGORY_GROUP, type ContextArrangement, type Density, GROUP_ORDER, INLINE_SECTION_MAX, type LayoutName, MENU_LAYOUT_SETTING, type MenuCheckboxNode, type MenuGroup, type MenuItemNode, type MenuLabelNode, type MenuLeafNode, type MenuLinkNode, type MenuModel, type MenuNode, type MenuSection, type MenuSeparatorNode, type MenuSubmenuNode, PLATFORM_MENU_LAYOUT, actionToNode, bar, buildMenuModel, context, filterPalette, findNode, isContainerWord, layouts, leafIds, menuHeadings, overflow, palette, resolveMenuLayout, sectionLabel, selectionToolbar, sheet, unapprovedHeadings, withExpandedChildren };
888
+ export { APPROVED_HEADINGS, type ArrangedBar, type ArrangedContext, type ArrangedPalette, type ArrangedSelectionToolbar, type ArrangedSheet, type BuildMenuModelOptions, CATEGORY_GROUP, type ContextArrangement, type Density, GROUP_ORDER, type HeadingKind, type HeadingPolicy, INLINE_SECTION_MAX, type LayoutName, MENU_LAYOUT_SETTING, type MenuCheckboxNode, type MenuGroup, type MenuItemNode, type MenuLabelNode, type MenuLeafNode, type MenuLinkNode, type MenuModel, type MenuNode, type MenuSection, type MenuSeparatorNode, type MenuSubmenuNode, PLATFORM_MENU_LAYOUT, UnapprovedHeadingError, actionToNode, bar, buildMenuModel, context, defaultHeadingPolicy, filterPalette, findNode, isApprovedHeading, isContainerWord, layouts, leafIds, menuHeadings, overflow, palette, resolveMenuLayout, sectionLabel, selectionToolbar, sheet, unapprovedHeadings, withExpandedChildren };