@ai-matrx/alchemy 0.6.2 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -0
- package/dist/actions.cjs +374 -0
- package/dist/actions.cjs.map +1 -0
- package/dist/actions.d.cts +773 -0
- package/dist/actions.d.ts +773 -0
- package/dist/actions.js +351 -0
- package/dist/actions.js.map +1 -0
- package/dist/checks.cjs +31 -2
- package/dist/checks.cjs.map +1 -1
- package/dist/checks.d.cts +24 -1
- package/dist/checks.d.ts +24 -1
- package/dist/checks.js +31 -2
- package/dist/checks.js.map +1 -1
- package/dist/core.cjs +1757 -2
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +595 -1
- package/dist/core.d.ts +595 -1
- package/dist/core.js +1749 -2
- package/dist/core.js.map +1 -1
- package/dist/declare.cjs +12 -10
- package/dist/declare.cjs.map +1 -1
- package/dist/declare.d.cts +18 -2
- package/dist/declare.d.ts +18 -2
- package/dist/declare.js +12 -10
- package/dist/declare.js.map +1 -1
- package/dist/index.cjs +1757 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +595 -1
- package/dist/index.d.ts +595 -1
- package/dist/index.js +1749 -2
- package/dist/index.js.map +1 -1
- package/dist/menu.cjs +436 -0
- package/dist/menu.cjs.map +1 -0
- package/dist/menu.d.cts +834 -0
- package/dist/menu.d.ts +834 -0
- package/dist/menu.js +413 -0
- package/dist/menu.js.map +1 -0
- package/dist/operate-document.cjs +163 -0
- package/dist/operate-document.cjs.map +1 -0
- package/dist/operate-document.d.cts +132 -0
- package/dist/operate-document.d.ts +132 -0
- package/dist/operate-document.js +130 -0
- package/dist/operate-document.js.map +1 -0
- package/dist/operate-rich-html.cjs +129 -0
- package/dist/operate-rich-html.cjs.map +1 -0
- package/dist/operate-rich-html.d.cts +136 -0
- package/dist/operate-rich-html.d.ts +136 -0
- package/dist/operate-rich-html.js +96 -0
- package/dist/operate-rich-html.js.map +1 -0
- package/dist/operate-server.cjs +157 -0
- package/dist/operate-server.cjs.map +1 -0
- package/dist/operate-server.d.cts +183 -0
- package/dist/operate-server.d.ts +183 -0
- package/dist/operate-server.js +134 -0
- package/dist/operate-server.js.map +1 -0
- package/dist/operate-xlsx.cjs +248 -0
- package/dist/operate-xlsx.cjs.map +1 -0
- package/dist/operate-xlsx.d.cts +129 -0
- package/dist/operate-xlsx.d.ts +129 -0
- package/dist/operate-xlsx.js +215 -0
- package/dist/operate-xlsx.js.map +1 -0
- package/dist/operate.cjs +1774 -0
- package/dist/operate.cjs.map +1 -0
- package/dist/operate.d.cts +595 -0
- package/dist/operate.d.ts +595 -0
- package/dist/operate.js +1750 -0
- package/dist/operate.js.map +1 -0
- package/dist/ports.cjs.map +1 -1
- package/dist/ports.d.cts +361 -3
- package/dist/ports.d.ts +361 -3
- package/dist/react-bar.cjs +686 -0
- package/dist/react-bar.cjs.map +1 -0
- package/dist/react-bar.d.cts +379 -0
- package/dist/react-bar.d.ts +379 -0
- package/dist/react-bar.js +665 -0
- package/dist/react-bar.js.map +1 -0
- package/dist/react-host.cjs +301 -0
- package/dist/react-host.cjs.map +1 -0
- package/dist/react-host.d.cts +820 -0
- package/dist/react-host.d.ts +820 -0
- package/dist/react-host.js +269 -0
- package/dist/react-host.js.map +1 -0
- package/dist/react-menu.cjs +735 -0
- package/dist/react-menu.cjs.map +1 -0
- package/dist/react-menu.d.cts +370 -0
- package/dist/react-menu.d.ts +370 -0
- package/dist/react-menu.js +722 -0
- package/dist/react-menu.js.map +1 -0
- package/dist/react-overflow.cjs +592 -0
- package/dist/react-overflow.cjs.map +1 -0
- package/dist/react-overflow.d.cts +817 -0
- package/dist/react-overflow.d.ts +817 -0
- package/dist/react-overflow.js +571 -0
- package/dist/react-overflow.js.map +1 -0
- package/dist/react-palette.cjs +489 -0
- package/dist/react-palette.cjs.map +1 -0
- package/dist/react-palette.d.cts +359 -0
- package/dist/react-palette.d.ts +359 -0
- package/dist/react-palette.js +457 -0
- package/dist/react-palette.js.map +1 -0
- package/dist/react-selection.cjs +617 -0
- package/dist/react-selection.cjs.map +1 -0
- package/dist/react-selection.d.cts +357 -0
- package/dist/react-selection.d.ts +357 -0
- package/dist/react-selection.js +596 -0
- package/dist/react-selection.js.map +1 -0
- package/dist/react-sheet.cjs +616 -0
- package/dist/react-sheet.cjs.map +1 -0
- package/dist/react-sheet.d.cts +361 -0
- package/dist/react-sheet.d.ts +361 -0
- package/dist/react-sheet.js +595 -0
- package/dist/react-sheet.js.map +1 -0
- package/package.json +148 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react/bar.tsx","../src/menu/layouts.ts","../src/react/engine.tsx","../src/declare/sensitivity.ts","../src/actions/projection.ts","../src/actions/run.ts","../src/menu/model.ts","../src/react/context.ts","../src/react/dropdown-nodes.tsx"],"sourcesContent":["\"use client\";\n/**\n * `@ai-matrx/alchemy/react/bar` — the action bar layout (CONTRACT §2.5):\n * primary actions inline, everything else under ⋯, one model.\n */\nimport * as React from \"react\";\nimport { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger, TooltipProvider } from \"@ai-matrx/design-system\";\nimport { bar } from \"../menu/layouts\";\nimport type { ClickTarget } from \"../actions/types\";\nimport type { MenuSubmenuNode } from \"../menu/types\";\nimport { useMenuEngine, type MenuEngine, type MenuEngineOptions } from \"./engine\";\nimport { LeafButton, NodeList, SectionList } from \"./dropdown-nodes\";\n\nexport interface ActionBarProps extends MenuEngineOptions {\n target: ClickTarget;\n /** Compact presentation (smaller gaps); membership is identical. */\n mini?: boolean;\n className?: string;\n /** Hide the ⋯ (the host turned the options off); the primaries still render. */\n hideOverflow?: boolean;\n /**\n * Below this viewport width the ⋯ opens the mobile bottom sheet\n * (`/react/sheet`, loaded on first tap) instead of a dropdown. Default 768.\n */\n sheetBelow?: number;\n /** Override the sheet loader (tests, custom bundlers). */\n loadSheet?: () => Promise<{ ActionSheet: React.ComponentType<import(\"./sheet\").ActionSheetProps> }>;\n}\n\nfunction isNarrow(width: number): boolean {\n if (typeof window === \"undefined\") return false;\n return window.matchMedia?.(`(max-width: ${width - 1}px)`).matches ?? false;\n}\n\nconst TRIGGER_CLASS =\n \"inline-flex h-7 min-w-7 items-center justify-center gap-1 rounded-md px-1.5 text-muted-foreground hover:bg-accent hover:text-foreground\";\n\nfunction PrimarySubmenu({ node, engine }: { node: MenuSubmenuNode; engine: MenuEngine }): React.ReactElement {\n return (\n <DropdownMenu\n onOpenChange={(open) => {\n if (open && node.lazy && !node.loading) void engine.expand(node.id);\n }}\n >\n <DropdownMenuTrigger asChild>\n <button type=\"button\" aria-label={node.label} data-alchemy-node={node.id} className={TRIGGER_CLASS}>\n {engine.icon(node.icon) ?? <span className=\"text-sm\">{node.label}</span>}\n </button>\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"start\" className=\"w-64 max-h-[var(--radix-dropdown-menu-content-available-height)] overflow-y-auto\">\n {node.loading ? <div className=\"px-2 py-1.5 text-xs text-muted-foreground\">Loading…</div> : <NodeList nodes={node.children} engine={engine} />}\n </DropdownMenuContent>\n </DropdownMenu>\n );\n}\n\nexport function ActionBar({\n target,\n mini = false,\n className,\n hideOverflow = false,\n sheetBelow = 768,\n loadSheet = () => import(\"@ai-matrx/alchemy/react/sheet\"),\n ...options\n}: ActionBarProps): React.ReactElement | null {\n const engine = useMenuEngine(target, options);\n const [sheetOpen, setSheetOpen] = React.useState(false);\n const [Sheet, setSheet] = React.useState<React.ComponentType<import(\"./sheet\").ActionSheetProps> | null>(null);\n if (!engine.model) return null;\n const arranged = bar(engine.model, { mini });\n if (arranged.primary.length === 0 && arranged.overflow.length === 0) return null;\n return (\n <TooltipProvider>\n <div\n role=\"toolbar\"\n aria-label=\"Actions\"\n data-alchemy-layout=\"bar\"\n className={`flex items-center ${mini ? \"gap-0\" : \"gap-0.5\"} ${className ?? \"\"}`}\n >\n {arranged.primary.map((node) =>\n node.kind === \"submenu\" ? (\n <PrimarySubmenu key={node.id} node={node} engine={engine} />\n ) : (\n <LeafButton key={node.id} node={node} engine={engine} showLabel={false} />\n ),\n )}\n {hideOverflow || arranged.overflow.length === 0 ? null : isNarrow(sheetBelow) ? (\n <>\n <button\n type=\"button\"\n aria-label=\"More actions\"\n data-alchemy-trigger=\"overflow\"\n className={TRIGGER_CLASS}\n onClick={() => {\n setSheetOpen(true);\n if (!Sheet) void loadSheet().then((m) => setSheet(() => m.ActionSheet));\n }}\n >\n <span aria-hidden className=\"text-base leading-none\">⋯</span>\n </button>\n {Sheet ? <Sheet {...options} target={target} open={sheetOpen} onOpenChange={setSheetOpen} /> : null}\n </>\n ) : (\n <DropdownMenu>\n <DropdownMenuTrigger asChild>\n <button type=\"button\" aria-label=\"More actions\" data-alchemy-trigger=\"overflow\" className={TRIGGER_CLASS}>\n <span aria-hidden className=\"text-base leading-none\">⋯</span>\n </button>\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"end\" className=\"w-64 max-h-[var(--radix-dropdown-menu-content-available-height)] overflow-y-auto\">\n <SectionList sections={arranged.overflow} engine={engine} />\n </DropdownMenuContent>\n </DropdownMenu>\n )}\n </div>\n </TooltipProvider>\n );\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 hierarchical = model.sections.some((s) => s.primary);\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 if (hierarchical) sections.push(s);\n else {\n const { label: _label, ...unlabelled } = s;\n sections.push(unlabelled);\n }\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","\"use client\";\n/**\n * The React half of T1e: one hook every renderer uses to resolve the registry\n * at a target, build the model and run a node. Handlers never live in a\n * renderer — they live in providers and run through `runAction`.\n *\n * The context object is shared through globalThis so every per-layout entry\n * (each bundled separately) reads the same provider (module state is banned\n * across dual-loader graphs).\n */\nimport * as React from \"react\";\nimport { runAction, type RunResult } from \"../actions/run\";\nimport type { ProjectionSource } from \"../actions/projection\";\nimport type { Action, ClickTarget, ResolveRestriction, ResolvedAction } from \"../actions/types\";\nimport { actionToNode, buildMenuModel, findNode, withExpandedChildren } from \"../menu/model\";\nimport type { MenuModel, MenuNode } from \"../menu/types\";\nimport { useAlchemyActions } from \"./context\";\n\nexport interface MenuEngineOptions {\n restrict?: ResolveRestriction;\n /** Raw sources for projection (the host's mounted surface / clicked item). */\n source?: ProjectionSource;\n /** Content the menu acts on when nothing is selected (header text). */\n content?: string | null;\n contentFingerprint?: string;\n /** Called after a node ran (close the menu, announce). */\n onRan?: (nodeId: string, result: RunResult) => void;\n /** Resolve only while true (renderers resolve on open). Default true. */\n active?: boolean;\n /**\n * Re-resolve when this changes even if the target object is the same (a\n * host that keeps one target per mount and reads live state through it).\n */\n revision?: string | number;\n}\n\nexport interface MenuEngine {\n model: MenuModel | null;\n resolved: readonly ResolvedAction[];\n run(nodeId: string): Promise<RunResult | null>;\n expand(nodeId: string): Promise<void>;\n /** The host's glyph for a key; `tone` is the action's colour class (iconTone). */\n icon(key: string | undefined, tone?: string): React.ReactNode;\n}\n\nexport function useMenuEngine(target: ClickTarget | null, options: MenuEngineOptions = {}): MenuEngine {\n const { registry, ports } = useAlchemyActions();\n const [resolved, setResolved] = React.useState<readonly ResolvedAction[]>([]);\n const [model, setModel] = React.useState<MenuModel | null>(null);\n const [tick, setTick] = React.useState(0);\n const expanded = React.useRef(new Map<string, Action>());\n const active = options.active ?? true;\n const optionsRef = React.useRef(options);\n optionsRef.current = options;\n\n React.useEffect(() => registry.subscribe(() => setTick((t) => t + 1)), [registry]);\n\n React.useEffect(() => {\n if (!target || !active) return;\n let live = true;\n void registry.resolve(target, optionsRef.current.restrict).then((list) => {\n if (!live) return;\n expanded.current.clear();\n setResolved(list);\n setModel(buildMenuModel(target, list, { ...(ports.i18n ? { i18n: ports.i18n } : {}), content: optionsRef.current.content ?? null }));\n });\n return () => {\n live = false;\n };\n }, [registry, ports, target, active, tick, options.revision]);\n\n // Live toggles (read-aloud, thumbs): re-build when an action's store changes.\n React.useEffect(() => {\n if (!target) return;\n const offs = resolved\n .map((r) => r.action.subscribe?.(() => setTick((t) => t + 1), target))\n .filter((off): off is () => void => typeof off === \"function\");\n return () => offs.forEach((off) => off());\n }, [resolved, target]);\n\n const findAction = React.useCallback(\n (id: string): Action | undefined => resolved.find((r) => r.action.id === id)?.action ?? expanded.current.get(id),\n [resolved],\n );\n\n const run = React.useCallback(\n async (nodeId: string) => {\n if (!target || !model) return null;\n const node = model.sections.map((s) => findNode(s.nodes, nodeId)).find(Boolean) ?? null;\n const action = findAction(node && \"actionId\" in node && node.actionId ? node.actionId : nodeId);\n if (!action) return null;\n const o = optionsRef.current;\n const result = await runAction(action, target, {\n ports,\n ...(o.source ? { source: o.source } : {}),\n ...(o.contentFingerprint ? { contentFingerprint: o.contentFingerprint } : {}),\n });\n o.onRan?.(nodeId, result);\n return result;\n },\n [target, model, findAction, ports],\n );\n\n const expand = React.useCallback(\n async (nodeId: string) => {\n const action = findAction(nodeId);\n if (!target || !action?.expand) return;\n setModel((m) => (m ? withExpandedChildren(m, nodeId, \"loading\") : m));\n try {\n const children = await action.expand(target, new AbortController().signal);\n const nodes: MenuNode[] = children.map((child) => {\n expanded.current.set(child.id, child);\n return actionToNode({ action: child, eligibility: { status: \"available\" } }, target, ports.i18n ? { i18n: ports.i18n } : {});\n });\n setModel((m) => (m ? withExpandedChildren(m, nodeId, nodes) : m));\n } catch (error) {\n ports.diagnostics.capture(error, { area: \"menu\", detail: { nodeId, stage: \"expand\" } });\n setModel((m) => (m ? withExpandedChildren(m, nodeId, []) : m));\n }\n },\n [findAction, target, ports],\n );\n\n const icon = React.useCallback(\n (key: string | undefined, tone?: string): React.ReactNode => {\n if (!key || !ports.icons) return null;\n const Resolved = ports.icons.resolve(key) as React.ComponentType<{ className?: string; \"aria-hidden\"?: boolean }> | null;\n return Resolved ? <Resolved className={`h-4 w-4 shrink-0 ${tone ?? \"\"}`} aria-hidden /> : null;\n },\n [ports.icons],\n );\n\n return { model, resolved, run, expand, icon };\n}\n","/**\n * Sensitivity defaults and resolution (CONTRACT §2.1). Its own module so the\n * lightweight entries (`/actions`, the T0 React host) can project without\n * pulling the declaration registry.\n */\nimport type { DeclaredValue, Sensitivity } from \"./types\";\n\nexport const DEFAULT_SENSITIVITY: Sensitivity = Object.freeze({\n exportable: true,\n classification: \"ordinary\",\n includedByDefault: true,\n});\n\nexport function resolveSensitivity(value: Pick<DeclaredValue, \"sensitivity\">): Sensitivity {\n return {\n exportable: value.sensitivity?.exportable ?? DEFAULT_SENSITIVITY.exportable,\n classification: value.sensitivity?.classification ?? DEFAULT_SENSITIVITY.classification,\n includedByDefault: value.sensitivity?.includedByDefault ?? DEFAULT_SENSITIVITY.includedByDefault,\n };\n}\n","/**\n * PROJECTION BEFORE PROVIDERS (CONTRACT §2.4).\n *\n * The only place a raw read (`MountedSurface.readValues`,\n * `InternalResolvedItem.readValues`) is consumed on behalf of an action.\n * What leaves is projected: a value is kept only when it is DECLARED, its\n * classification is \"ordinary\" and it is exportable. Everything removed is\n * recorded as an omission, so the person and the agent can see what was held\n * back. No caller can relax this.\n */\nimport { resolveSensitivity } from \"../declare/sensitivity\";\nimport type { InternalResolvedItem, MountedSurface } from \"../declare/host\";\nimport type { DeclaredValue, Json, LiveValues, ResolvedSurfaceDeclaration } from \"../declare/types\";\nimport type { ProjectedReads, ReadOmission } from \"./types\";\n\nexport interface ProjectionSource {\n surface: MountedSurface | null;\n declaration: ResolvedSurfaceDeclaration | null;\n item: InternalResolvedItem | null;\n}\n\nfunction toJson(value: unknown): Json | undefined {\n if (value === undefined || typeof value === \"function\" || typeof value === \"symbol\") return undefined;\n if (value === null || typeof value === \"string\" || typeof value === \"boolean\") return value;\n if (typeof value === \"number\") return Number.isFinite(value) ? value : null;\n if (typeof value === \"bigint\") return value.toString();\n if (value instanceof Date) return value.toISOString();\n if (Array.isArray(value)) return value.map((v) => toJson(v) ?? null);\n if (typeof value === \"object\") {\n const out: { [key: string]: Json } = {};\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) {\n const j = toJson(v);\n if (j !== undefined) out[k] = j;\n }\n return out;\n }\n return undefined;\n}\n\n/** Keep declared, ordinary, exportable values; record every removal. */\nexport function projectValues(\n raw: Record<string, unknown>,\n declared: readonly Pick<DeclaredValue, \"name\" | \"sensitivity\">[],\n pathPrefix = \"\",\n): { values: Record<string, Json>; omissions: ReadOmission[] } {\n const byName = new Map(declared.map((d) => [d.name, d]));\n const values: Record<string, Json> = {};\n const omissions: ReadOmission[] = [];\n for (const [name, value] of Object.entries(raw)) {\n const path = pathPrefix ? `${pathPrefix}.${name}` : name;\n const decl = byName.get(name);\n if (!decl) {\n omissions.push({ path, reason: \"filtered\" });\n continue;\n }\n const sensitivity = resolveSensitivity(decl);\n if (sensitivity.classification !== \"ordinary\") {\n omissions.push({ path, reason: \"excluded\", classification: sensitivity.classification });\n continue;\n }\n if (!sensitivity.exportable) {\n omissions.push({ path, reason: \"excluded\" });\n continue;\n }\n const json = toJson(value);\n if (json === undefined) continue;\n values[name] = json;\n }\n return { values, omissions };\n}\n\nexport function createProjectedReads(source: ProjectionSource): ProjectedReads {\n return {\n async values(signal) {\n if (!source.surface || !source.declaration) return { values: {}, omissions: [] };\n const raw = await source.surface.readValues(signal);\n const screenValues = source.declaration.values;\n return projectValues(raw, screenValues);\n },\n async item(signal) {\n const item = source.item;\n if (!item || !source.declaration) return null;\n const type = source.declaration.itemTypes?.find((t) => t.name === item.itemType);\n if (!type) return { values: {}, omissions: [{ path: item.itemType, reason: \"filtered\" }] };\n const raw = await item.readValues(signal);\n return projectValues(raw, type.values, item.itemType);\n },\n async live(signal): Promise<LiveValues> {\n if (!source.surface?.readLive) return {};\n return source.surface.readLive(signal);\n },\n };\n}\n","/**\n * The one run path (T1e). Every layout runs an action through here, so the\n * sign-in-then-resume rule, projection and failure capture live once.\n */\nimport type { TransferOutcome } from \"@ai-matrx/kit/content-transfer\";\nimport type { AlchemyHostPorts } from \"../ports\";\nimport { createProjectedReads, type ProjectionSource } from \"./projection\";\nimport type { Action, ClickTarget } from \"./types\";\n\nexport interface RunActionOptions {\n ports: AlchemyHostPorts;\n /** Raw sources; projected before the action sees them. */\n source?: ProjectionSource;\n /** Stable fingerprint of the content, for sign-in-then-resume. */\n contentFingerprint?: string;\n signal?: AbortSignal;\n}\n\nexport type RunResult =\n | { status: \"ran\"; outcome: TransferOutcome | void }\n | { status: \"auth-pending\" }\n | { status: \"failed\"; error: unknown };\n\nexport async function runAction(action: Action, target: ClickTarget, options: RunActionOptions): Promise<RunResult> {\n const { ports } = options;\n if (action.requiresAuth && !target.auth.authenticated) {\n if (!ports.auth) {\n // Unreachable through resolve (the action is absent without the port); guard direct callers.\n ports.diagnostics.capture(new Error(`requiresAuth action \"${action.id}\" ran signed out with no auth port`), {\n area: \"actions\",\n detail: { actionId: action.id },\n });\n return { status: \"failed\", error: new Error(\"sign-in unavailable\") };\n }\n ports.auth.signInThenResume({ actionId: action.id, contentFingerprint: options.contentFingerprint ?? action.id });\n return { status: \"auth-pending\" };\n }\n const reads = createProjectedReads(options.source ?? { surface: null, declaration: target.declaration, item: null });\n const signal = options.signal ?? new AbortController().signal;\n try {\n const outcome = await action.run(target, { reads, ports, signal });\n return { status: \"ran\", outcome };\n } catch (error) {\n ports.diagnostics.capture(error, { area: \"actions\", detail: { actionId: action.id, stage: \"run\" } });\n const label = typeof action.label === \"string\" ? action.label : action.id;\n ports.notify?.error(`${label} did not finish.`, \"Try again; if it keeps failing, report it from the feedback button.\");\n return { status: \"failed\", error };\n }\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\";\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 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, 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 * The shared React context (T0-safe: imports only React and types). Shared\n * through globalThis so every per-layout bundle reads the same provider.\n */\nimport * as React from \"react\";\nimport type { ActionRegistry } from \"../actions/types\";\nimport type { AlchemyHostPorts } from \"../ports\";\n\nexport interface AlchemyActionsValue {\n registry: ActionRegistry;\n ports: AlchemyHostPorts;\n}\n\nconst KEY = Symbol.for(\"ai-matrx.alchemy.actions-context\");\ntype Holder = { [KEY]?: React.Context<AlchemyActionsValue | null> };\nexport const AlchemyActionsContext: React.Context<AlchemyActionsValue | null> =\n ((globalThis as Holder)[KEY] ??= React.createContext<AlchemyActionsValue | null>(null));\n\nexport function useAlchemyActions(): AlchemyActionsValue {\n const value = React.useContext(AlchemyActionsContext);\n if (!value) throw new Error(\"Alchemy actions: render inside <AlchemyActionsProvider> (@ai-matrx/alchemy/react/host).\");\n return value;\n}\n","\"use client\";\n/**\n * Drawing model nodes inside a Radix dropdown (menu / overflow / bar / selection).\n * Pure presentation: every choice goes back to the engine by node id.\n */\nimport * as React from \"react\";\nimport {\n DropdownMenuCheckboxItem,\n DropdownMenuItem,\n DropdownMenuLabel,\n DropdownMenuSeparator,\n DropdownMenuSub,\n DropdownMenuSubContent,\n DropdownMenuSubTrigger,\n Tooltip,\n TooltipContent,\n TooltipTrigger,\n} from \"@ai-matrx/design-system\";\nimport type { MenuEngine } from \"./engine\";\nimport { sectionLabel } from \"../menu/layouts\";\nimport type { MenuLeafNode, MenuNode, MenuSection } from \"../menu/types\";\n\nexport function NodeList({ nodes, engine }: { nodes: readonly MenuNode[]; engine: MenuEngine }): React.ReactElement {\n return (\n <>\n {nodes.map((node) => (\n <MenuNodeView key={node.id} node={node} engine={engine} />\n ))}\n </>\n );\n}\n\nexport function SectionList({\n sections,\n engine,\n}: {\n sections: readonly MenuSection[];\n engine: MenuEngine;\n}): React.ReactElement {\n return (\n <>\n {sections.map((section, index) => (\n <React.Fragment key={section.id}>\n {index > 0 ? <DropdownMenuSeparator /> : null}\n {sectionLabel(section) ? (\n <DropdownMenuLabel className=\"text-xs font-medium text-muted-foreground\">{sectionLabel(section)}</DropdownMenuLabel>\n ) : null}\n <NodeList nodes={section.nodes} engine={engine} />\n </React.Fragment>\n ))}\n </>\n );\n}\n\nfunction iconOf(node: MenuNode, engine: MenuEngine): React.ReactNode {\n if (node.kind === \"item\" && node.stateIcon) {\n const glyph = engine.icon(node.stateIcon.icon);\n return node.stateIcon.spin ? <span className=\"inline-flex animate-spin\">{glyph}</span> : glyph;\n }\n if (!(\"icon\" in node)) return null;\n return engine.icon(node.icon, node.kind === \"item\" ? node.iconTone : undefined);\n}\n\nexport function MenuNodeView({ node, engine }: { node: MenuNode; engine: MenuEngine }): React.ReactElement | null {\n switch (node.kind) {\n case \"separator\":\n return <DropdownMenuSeparator />;\n case \"label\":\n return <DropdownMenuLabel className=\"text-xs font-medium text-muted-foreground\">{node.label}</DropdownMenuLabel>;\n case \"submenu\":\n return (\n <DropdownMenuSub\n onOpenChange={(open) => {\n if (open && node.lazy && !node.loading) void engine.expand(node.id);\n }}\n >\n <DropdownMenuSubTrigger data-alchemy-node={node.id} className=\"gap-2\">\n {iconOf(node, engine)}\n <span className=\"truncate\">{node.label}</span>\n </DropdownMenuSubTrigger>\n <DropdownMenuSubContent className=\"max-h-[var(--radix-dropdown-menu-content-available-height)] overflow-y-auto\">\n {node.loading ? (\n <DropdownMenuLabel className=\"text-xs text-muted-foreground\">Loading…</DropdownMenuLabel>\n ) : node.children.length === 0 && !node.lazy ? (\n <DropdownMenuLabel className=\"text-xs text-muted-foreground\">{node.emptyLabel ?? \"Nothing here yet\"}</DropdownMenuLabel>\n ) : (\n <NodeList nodes={node.children} engine={engine} />\n )}\n </DropdownMenuSubContent>\n </DropdownMenuSub>\n );\n case \"checkbox\":\n return (\n <DropdownMenuCheckboxItem\n data-alchemy-node={node.id}\n checked={node.checked}\n onSelect={() => void engine.run(node.id)}\n className=\"gap-2\"\n >\n {iconOf(node, engine)}\n <span className=\"truncate\">{node.label}</span>\n </DropdownMenuCheckboxItem>\n );\n case \"link\":\n return (\n <DropdownMenuItem asChild data-alchemy-node={node.id}>\n <a href={node.href} target={node.target} className=\"gap-2\">\n {iconOf(node, engine)}\n <span className=\"truncate\">{node.label}</span>\n </a>\n </DropdownMenuItem>\n );\n case \"item\":\n return <LeafItem node={node} engine={engine} />;\n }\n}\n\nfunction LeafItem({ node, engine }: { node: Extract<MenuLeafNode, { kind: \"item\" }>; engine: MenuEngine }): React.ReactElement {\n const row = (\n <DropdownMenuItem\n data-alchemy-node={node.id}\n aria-disabled={node.unavailable ? true : undefined}\n aria-pressed={node.pressed}\n onSelect={(event) => {\n if (node.unavailable) {\n event.preventDefault();\n return;\n }\n void engine.run(node.id);\n }}\n className={`gap-2 ${node.unavailable ? \"opacity-50\" : \"\"} ${node.destructive ? \"text-destructive\" : \"\"}`}\n >\n {iconOf(node, engine)}\n <span className=\"flex min-w-0 flex-1 flex-col\">\n <span className=\"truncate\">{node.label}</span>\n {node.description ? <span className=\"truncate text-xs text-muted-foreground\">{node.description}</span> : null}\n </span>\n {node.hint ? <span className=\"ml-auto text-xs text-muted-foreground\">{node.hint}</span> : null}\n </DropdownMenuItem>\n );\n if (!node.unavailable) return row;\n return (\n <Tooltip>\n <TooltipTrigger asChild>{row}</TooltipTrigger>\n <TooltipContent>{node.unavailable.sentence}</TooltipContent>\n </Tooltip>\n );\n}\n\n/** An icon button for a strip / bar leaf (greyed verb carries its sentence). */\nexport function LeafButton({\n node,\n engine,\n showLabel,\n}: {\n node: MenuNode;\n engine: MenuEngine;\n showLabel: boolean;\n}): React.ReactElement | null {\n if (node.kind !== \"item\" && node.kind !== \"checkbox\" && node.kind !== \"link\") return null;\n const unavailable = node.kind === \"item\" ? node.unavailable : undefined;\n const pressed = node.kind === \"item\" ? node.pressed : node.kind === \"checkbox\" ? node.checked : undefined;\n const glyph = iconOf(node, engine);\n const button = (\n <button\n type=\"button\"\n data-alchemy-node={node.id}\n aria-label={node.label}\n aria-disabled={unavailable ? true : undefined}\n aria-pressed={pressed}\n onMouseDown={(e) => {\n if (node.kind === \"item\" && node.preserveSelection) e.preventDefault();\n }}\n onClick={() => {\n if (unavailable) return;\n if (node.kind === \"link\") {\n window.location.assign(node.href);\n return;\n }\n void engine.run(node.id);\n }}\n className={`inline-flex h-7 min-w-7 items-center justify-center gap-1.5 rounded-md px-1.5 text-sm text-muted-foreground hover:bg-accent hover:text-foreground ${\n unavailable ? \"cursor-default opacity-50 hover:bg-transparent\" : \"\"\n } ${pressed ? \"text-foreground\" : \"\"}`}\n >\n {glyph}\n {showLabel || !glyph ? <span>{node.label}</span> : null}\n </button>\n );\n return (\n <Tooltip>\n <TooltipTrigger asChild>{button}</TooltipTrigger>\n <TooltipContent>{unavailable ? unavailable.sentence : node.label}</TooltipContent>\n </Tooltip>\n );\n}\n"],"mappings":";;;AAKA,YAAYA,YAAW;AACvB,SAAS,cAAc,qBAAqB,qBAAqB,uBAAuB;;;ACqBjF,IAAM,qBAAqB;AAQ3B,SAAS,aAAa,SAAqC;AAChE,SAAO,QAAQ,SAAS;AAC1B;AAoDA,SAAS,KAAK,SAA2D;AACvE,SAAO;AAAA,IACL,MAAM;AAAA,IACN,IAAI,GAAG,QAAQ,EAAE;AAAA,IACjB,OAAO,QAAQ;AAAA,IACf,GAAI,QAAQ,SAAS,SAAY,EAAE,MAAM,QAAQ,KAAK,IAAI,CAAC;AAAA,IAC3D,UAAU,QAAQ;AAAA,EACpB;AACF;AAEA,SAAS,SAAS,OAAoC;AACpD,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IAAK;AAAA,WACjG,IAEA,gBAAAC,MAAC,gBACC;AAAA,0BAAAD,KAAC,uBAAoB,SAAO,MAC1B,0BAAAA,KAAC,YAAO,MAAK,UAAS,cAAW,gBAAe,wBAAqB,YAAW,WAAW,eACzF,0BAAAA,KAAC,UAAK,eAAW,MAAC,WAAU,0BAAyB,oBAAC,GACxD,GACF;AAAA,UACA,gBAAAA,KAAC,uBAAoB,OAAM,OAAM,WAAU,oFACzC,0BAAAA,KAAC,eAAY,UAAU,SAAS,UAAU,QAAgB,GAC5D;AAAA,WACF;AAAA;AAAA;AAAA,EAEJ,GACF;AAEJ;","names":["React","React","React","Fragment","jsx","Fragment","jsx","jsxs"]}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/react-host.ts
|
|
32
|
+
var react_host_exports = {};
|
|
33
|
+
__export(react_host_exports, {
|
|
34
|
+
ActionMenuTrigger: () => ActionMenuTrigger,
|
|
35
|
+
AlchemyActionsProvider: () => AlchemyActionsProvider,
|
|
36
|
+
useAlchemyActions: () => useAlchemyActions,
|
|
37
|
+
useRegisterActionProvider: () => useRegisterActionProvider
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(react_host_exports);
|
|
40
|
+
|
|
41
|
+
// src/react/host.tsx
|
|
42
|
+
var React2 = __toESM(require("react"), 1);
|
|
43
|
+
|
|
44
|
+
// src/actions/click-target.ts
|
|
45
|
+
var UNIVERSAL_VERBS = ["copy", "cut", "paste", "undo", "redo", "find"];
|
|
46
|
+
|
|
47
|
+
// src/actions/registry.ts
|
|
48
|
+
var DuplicateActionError = class extends Error {
|
|
49
|
+
actionId;
|
|
50
|
+
providers;
|
|
51
|
+
constructor(actionId, first, second) {
|
|
52
|
+
super(
|
|
53
|
+
first === second ? `Action "${actionId}" is yielded twice by provider "${first}". Ids are unique; the second was refused.` : `Action "${actionId}" is registered by provider "${first}" and again by "${second}". Ids are unique; "${second}"'s copy was refused.`
|
|
54
|
+
);
|
|
55
|
+
this.name = "DuplicateActionError";
|
|
56
|
+
this.actionId = actionId;
|
|
57
|
+
this.providers = [first, second];
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var DuplicateProviderError = class extends Error {
|
|
61
|
+
providerId;
|
|
62
|
+
constructor(providerId) {
|
|
63
|
+
super(`Action provider "${providerId}" is already registered. Unregister it first; nothing was overwritten.`);
|
|
64
|
+
this.name = "DuplicateProviderError";
|
|
65
|
+
this.providerId = providerId;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var VERBS = new Set(UNIVERSAL_VERBS);
|
|
69
|
+
function capture(ports, error, detail) {
|
|
70
|
+
try {
|
|
71
|
+
ports.diagnostics.capture(error, { area: "actions", detail });
|
|
72
|
+
} catch {
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function computeEligibility(action, target, options) {
|
|
76
|
+
const restrict = options.restrict;
|
|
77
|
+
if (target.excludedActionIds.has(action.id)) return { status: "absent" };
|
|
78
|
+
if (restrict?.exclude?.includes(action.id)) return { status: "absent" };
|
|
79
|
+
if (restrict?.categories && !restrict.categories.includes(action.category)) return { status: "absent" };
|
|
80
|
+
if (action.writes && action.writes.length > 0) {
|
|
81
|
+
if (target.readOnly) return { status: "absent" };
|
|
82
|
+
const writable = new Set(target.writable.map((w) => w.name));
|
|
83
|
+
if (!action.writes.some((name) => writable.has(name))) return { status: "absent" };
|
|
84
|
+
}
|
|
85
|
+
if (action.requiresAuth && !target.auth.authenticated && !options.authResumable) {
|
|
86
|
+
return { status: "absent" };
|
|
87
|
+
}
|
|
88
|
+
const own = action.eligible(target);
|
|
89
|
+
if (own.status !== "unavailable-verb") return own;
|
|
90
|
+
if (action.category !== "clipboard" || !VERBS.has(own.verb)) {
|
|
91
|
+
return {
|
|
92
|
+
status: "contract-break",
|
|
93
|
+
reason: `Action "${action.id}" answered unavailable-verb but only the six universal verbs (category "clipboard") may grey; it is absent instead.`
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (!own.sentence.trim()) {
|
|
97
|
+
return {
|
|
98
|
+
status: "contract-break",
|
|
99
|
+
reason: `Universal verb "${action.id}" greyed without a sentence; a greyed verb must say why.`
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return own;
|
|
103
|
+
}
|
|
104
|
+
function createActionRegistry(options) {
|
|
105
|
+
const ports = options.ports;
|
|
106
|
+
const entries = /* @__PURE__ */ new Map();
|
|
107
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
108
|
+
const notify = () => {
|
|
109
|
+
for (const l of [...listeners]) l();
|
|
110
|
+
};
|
|
111
|
+
return {
|
|
112
|
+
register(provider) {
|
|
113
|
+
if (entries.has(provider.id)) throw new DuplicateProviderError(provider.id);
|
|
114
|
+
const declared = provider.declaredIds?.() ?? [];
|
|
115
|
+
const own = /* @__PURE__ */ new Set();
|
|
116
|
+
for (const id of declared) {
|
|
117
|
+
if (own.has(id)) throw new DuplicateActionError(id, provider.id, provider.id);
|
|
118
|
+
own.add(id);
|
|
119
|
+
for (const [otherId, other] of entries) {
|
|
120
|
+
if (other.declared.includes(id)) throw new DuplicateActionError(id, otherId, provider.id);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const entry = { provider, declared };
|
|
124
|
+
entries.set(provider.id, entry);
|
|
125
|
+
notify();
|
|
126
|
+
return () => {
|
|
127
|
+
if (entries.get(provider.id) === entry) {
|
|
128
|
+
entries.delete(provider.id);
|
|
129
|
+
notify();
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
},
|
|
133
|
+
async resolve(target, restrict) {
|
|
134
|
+
const authResumable = Boolean(ports.auth);
|
|
135
|
+
const seen = /* @__PURE__ */ new Map();
|
|
136
|
+
const out = [];
|
|
137
|
+
for (const [providerId, { provider }] of [...entries]) {
|
|
138
|
+
let actions;
|
|
139
|
+
try {
|
|
140
|
+
actions = await provider.actions(target);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
capture(ports, error, { providerId, stage: "actions" });
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
for (const raw of actions) {
|
|
146
|
+
const first = seen.get(raw.id);
|
|
147
|
+
if (first !== void 0) {
|
|
148
|
+
capture(ports, new DuplicateActionError(raw.id, first, providerId), { actionId: raw.id });
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
seen.set(raw.id, providerId);
|
|
152
|
+
const action = raw.provider === providerId ? raw : { ...raw, provider: providerId };
|
|
153
|
+
let eligibility;
|
|
154
|
+
try {
|
|
155
|
+
eligibility = computeEligibility(action, target, { restrict: restrict ?? {}, authResumable });
|
|
156
|
+
} catch (error) {
|
|
157
|
+
capture(ports, error, { actionId: action.id, stage: "eligible" });
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (eligibility.status === "contract-break") {
|
|
161
|
+
capture(ports, new Error(eligibility.reason), { actionId: action.id, stage: "eligible" });
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (eligibility.status === "absent") continue;
|
|
165
|
+
out.push({ action, eligibility });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return out;
|
|
169
|
+
},
|
|
170
|
+
providers() {
|
|
171
|
+
return [...entries.keys()];
|
|
172
|
+
},
|
|
173
|
+
subscribe(listener) {
|
|
174
|
+
listeners.add(listener);
|
|
175
|
+
return () => {
|
|
176
|
+
listeners.delete(listener);
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// src/react/context.ts
|
|
183
|
+
var React = __toESM(require("react"), 1);
|
|
184
|
+
var KEY = /* @__PURE__ */ Symbol.for("ai-matrx.alchemy.actions-context");
|
|
185
|
+
var AlchemyActionsContext = globalThis[KEY] ??= React.createContext(null);
|
|
186
|
+
function useAlchemyActions() {
|
|
187
|
+
const value = React.useContext(AlchemyActionsContext);
|
|
188
|
+
if (!value) throw new Error("Alchemy actions: render inside <AlchemyActionsProvider> (@ai-matrx/alchemy/react/host).");
|
|
189
|
+
return value;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// src/react/host.tsx
|
|
193
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
194
|
+
function AlchemyActionsProvider({ ports, registry, children }) {
|
|
195
|
+
const own = React2.useMemo(() => registry ?? createActionRegistry({ ports }), [registry, ports]);
|
|
196
|
+
const value = React2.useMemo(() => ({ registry: own, ports }), [own, ports]);
|
|
197
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlchemyActionsContext.Provider, { value, children });
|
|
198
|
+
}
|
|
199
|
+
function useRegisterActionProvider(provider) {
|
|
200
|
+
const { registry } = useAlchemyActions();
|
|
201
|
+
React2.useEffect(() => provider ? registry.register(provider) : void 0, [registry, provider]);
|
|
202
|
+
}
|
|
203
|
+
var LONG_PRESS_MS = 480;
|
|
204
|
+
function isEditable(el) {
|
|
205
|
+
if (!el) return false;
|
|
206
|
+
if (el instanceof HTMLTextAreaElement) return true;
|
|
207
|
+
if (el instanceof HTMLInputElement) return !["checkbox", "radio", "button", "submit", "range", "color", "file"].includes(el.type);
|
|
208
|
+
return el.isContentEditable === true;
|
|
209
|
+
}
|
|
210
|
+
function mobileViewport() {
|
|
211
|
+
if (typeof window === "undefined") return false;
|
|
212
|
+
return window.matchMedia?.("(max-width: 767px)").matches ?? false;
|
|
213
|
+
}
|
|
214
|
+
function ActionMenuTrigger({
|
|
215
|
+
resolveTarget,
|
|
216
|
+
children,
|
|
217
|
+
arrangement,
|
|
218
|
+
density,
|
|
219
|
+
mobile,
|
|
220
|
+
editable = false,
|
|
221
|
+
loadMenu = () => import("@ai-matrx/alchemy/react/menu"),
|
|
222
|
+
loadSheet = () => import("@ai-matrx/alchemy/react/sheet"),
|
|
223
|
+
...options
|
|
224
|
+
}) {
|
|
225
|
+
const [state, setState] = React2.useState(null);
|
|
226
|
+
const [open, setOpen] = React2.useState(false);
|
|
227
|
+
const [Menu, setMenu] = React2.useState(null);
|
|
228
|
+
const [Sheet, setSheet] = React2.useState(null);
|
|
229
|
+
const press = React2.useRef(null);
|
|
230
|
+
const openAt = React2.useCallback(
|
|
231
|
+
(element, x, y, touch) => {
|
|
232
|
+
const editable2 = isEditable(element) || isEditable(document.activeElement);
|
|
233
|
+
const selectionText = window.getSelection?.()?.toString() ?? "";
|
|
234
|
+
const target = resolveTarget({ element, selectionText, editable: editable2 });
|
|
235
|
+
if (!target) return false;
|
|
236
|
+
const sheet = mobile ?? (touch || mobileViewport());
|
|
237
|
+
setState({ target, point: { x, y }, sheet });
|
|
238
|
+
setOpen(true);
|
|
239
|
+
if (sheet && !Sheet) void loadSheet().then((m) => setSheet(() => m.ActionSheet));
|
|
240
|
+
if (!sheet && !Menu) void loadMenu().then((m) => setMenu(() => m.ContextMenuPanel));
|
|
241
|
+
return true;
|
|
242
|
+
},
|
|
243
|
+
[resolveTarget, mobile, Sheet, Menu, loadSheet, loadMenu]
|
|
244
|
+
);
|
|
245
|
+
const child = React2.Children.only(children);
|
|
246
|
+
const props = child.props;
|
|
247
|
+
const compose = (own, theirs) => (e) => {
|
|
248
|
+
if (typeof theirs === "function") theirs(e);
|
|
249
|
+
own(e);
|
|
250
|
+
};
|
|
251
|
+
const trigger = React2.cloneElement(child, {
|
|
252
|
+
"data-alchemy-trigger": "context",
|
|
253
|
+
onContextMenu: compose((e) => {
|
|
254
|
+
if (e.defaultPrevented) return;
|
|
255
|
+
const el = e.target;
|
|
256
|
+
if (isEditable(el) && !editable) return;
|
|
257
|
+
if (openAt(el, e.clientX, e.clientY, false)) e.preventDefault();
|
|
258
|
+
}, props.onContextMenu),
|
|
259
|
+
onTouchStart: compose((e) => {
|
|
260
|
+
const t = e.touches[0];
|
|
261
|
+
if (!t) return;
|
|
262
|
+
const el = e.target;
|
|
263
|
+
if (isEditable(el) && !editable) return;
|
|
264
|
+
const timer = setTimeout(() => {
|
|
265
|
+
press.current = null;
|
|
266
|
+
openAt(el, t.clientX, t.clientY, true);
|
|
267
|
+
}, LONG_PRESS_MS);
|
|
268
|
+
press.current = { timer, x: t.clientX, y: t.clientY };
|
|
269
|
+
e.stopPropagation();
|
|
270
|
+
}, props.onTouchStart),
|
|
271
|
+
onTouchMove: compose((e) => {
|
|
272
|
+
const t = e.touches[0];
|
|
273
|
+
const p = press.current;
|
|
274
|
+
if (p && t && Math.hypot(t.clientX - p.x, t.clientY - p.y) > 8) {
|
|
275
|
+
clearTimeout(p.timer);
|
|
276
|
+
press.current = null;
|
|
277
|
+
}
|
|
278
|
+
}, props.onTouchMove),
|
|
279
|
+
onTouchEnd: compose(() => {
|
|
280
|
+
if (press.current) clearTimeout(press.current.timer);
|
|
281
|
+
press.current = null;
|
|
282
|
+
}, props.onTouchEnd)
|
|
283
|
+
});
|
|
284
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
285
|
+
trigger,
|
|
286
|
+
state && !state.sheet && Menu ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
287
|
+
Menu,
|
|
288
|
+
{
|
|
289
|
+
...options,
|
|
290
|
+
target: state.target,
|
|
291
|
+
point: state.point,
|
|
292
|
+
open,
|
|
293
|
+
onOpenChange: setOpen,
|
|
294
|
+
...arrangement ? { arrangement } : {},
|
|
295
|
+
...density ? { density } : {}
|
|
296
|
+
}
|
|
297
|
+
) : null,
|
|
298
|
+
state && state.sheet && Sheet ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Sheet, { ...options, target: state.target, open, onOpenChange: setOpen }) : null
|
|
299
|
+
] });
|
|
300
|
+
}
|
|
301
|
+
//# sourceMappingURL=react-host.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react-host.ts","../src/react/host.tsx","../src/actions/click-target.ts","../src/actions/registry.ts","../src/react/context.ts"],"sourcesContent":["/** `@ai-matrx/alchemy/react/host` — T0 shell: provider, provider registration, gesture trigger. */\nexport {\n ActionMenuTrigger,\n AlchemyActionsProvider,\n useAlchemyActions,\n useRegisterActionProvider,\n type ActionMenuTriggerProps,\n type AlchemyActionsProviderProps,\n type AlchemyActionsValue,\n} from \"./react/host\";\n","\"use client\";\n/**\n * `@ai-matrx/alchemy/react/host` — T0, the shell every mount pays for.\n *\n * Provider (registry + ports), provider registration, and the gesture shell\n * (right-click on desktop, long-press on touch). It imports NO model, NO\n * layout, NO renderer: the context menu (`/react/menu`, T1) and the mobile\n * sheet (`/react/sheet`, T1m) load by dynamic import on first open only.\n */\nimport * as React from \"react\";\nimport { createActionRegistry } from \"../actions/registry\";\nimport type { ActionProvider, ActionRegistry, ClickTarget } from \"../actions/types\";\nimport type { AlchemyHostPorts } from \"../ports\";\nimport { AlchemyActionsContext, useAlchemyActions, type AlchemyActionsValue } from \"./context\";\nimport type { MenuEngineOptions } from \"./engine\";\n\nexport { useAlchemyActions, type AlchemyActionsValue };\n\nexport interface AlchemyActionsProviderProps {\n ports: AlchemyHostPorts;\n /** Share one registry across providers; default: one per provider mount. */\n registry?: ActionRegistry;\n children: React.ReactNode;\n}\n\nexport function AlchemyActionsProvider({ ports, registry, children }: AlchemyActionsProviderProps): React.ReactElement {\n const own = React.useMemo(() => registry ?? createActionRegistry({ ports }), [registry, ports]);\n const value = React.useMemo(() => ({ registry: own, ports }), [own, ports]);\n return <AlchemyActionsContext.Provider value={value}>{children}</AlchemyActionsContext.Provider>;\n}\n\n/** Register a provider for the lifetime of the calling component. Duplicate ids throw (refused). */\nexport function useRegisterActionProvider(provider: ActionProvider | null): void {\n const { registry } = useAlchemyActions();\n React.useEffect(() => (provider ? registry.register(provider) : undefined), [registry, provider]);\n}\n\ntype MenuModule = typeof import(\"./menu\");\ntype SheetModule = typeof import(\"./sheet\");\n\nexport interface ActionMenuTriggerProps extends MenuEngineOptions {\n /** Build the target at gesture time (selection captured then). */\n resolveTarget(gesture: { element: Element; selectionText: string; editable: boolean }): ClickTarget | null;\n children: React.ReactElement;\n arrangement?: \"classic\" | \"tiered\" | \"command\";\n density?: \"comfortable\" | \"compact\";\n /** Force a renderer; default: sheet below 768px or on coarse pointers. */\n mobile?: boolean;\n /**\n * The wrapped surface is an editor that wires text mutation into the menu,\n * so the menu takes its right-click. Otherwise a live text field keeps its\n * native menu (Paste, spellcheck, autofill).\n */\n editable?: boolean;\n /** Override the lazy loaders (tests, custom bundlers). */\n loadMenu?: () => Promise<Pick<MenuModule, \"ContextMenuPanel\">>;\n loadSheet?: () => Promise<Pick<SheetModule, \"ActionSheet\">>;\n}\n\nconst LONG_PRESS_MS = 480;\n\nfunction isEditable(el: Element | null): boolean {\n if (!el) return false;\n if (el instanceof HTMLTextAreaElement) return true;\n if (el instanceof HTMLInputElement) return ![\"checkbox\", \"radio\", \"button\", \"submit\", \"range\", \"color\", \"file\"].includes(el.type);\n return (el as HTMLElement).isContentEditable === true;\n}\n\nfunction mobileViewport(): boolean {\n if (typeof window === \"undefined\") return false;\n return window.matchMedia?.(\"(max-width: 767px)\").matches ?? false;\n}\n\nexport function ActionMenuTrigger({\n resolveTarget,\n children,\n arrangement,\n density,\n mobile,\n editable = false,\n loadMenu = () => import(\"@ai-matrx/alchemy/react/menu\"),\n loadSheet = () => import(\"@ai-matrx/alchemy/react/sheet\"),\n ...options\n}: ActionMenuTriggerProps): React.ReactElement {\n const [state, setState] = React.useState<{ target: ClickTarget; point: { x: number; y: number }; sheet: boolean } | null>(null);\n const [open, setOpen] = React.useState(false);\n const [Menu, setMenu] = React.useState<MenuModule[\"ContextMenuPanel\"] | null>(null);\n const [Sheet, setSheet] = React.useState<SheetModule[\"ActionSheet\"] | null>(null);\n const press = React.useRef<{ timer: ReturnType<typeof setTimeout>; x: number; y: number } | null>(null);\n\n const openAt = React.useCallback(\n (element: Element, x: number, y: number, touch: boolean) => {\n const editable = isEditable(element) || isEditable(document.activeElement);\n const selectionText = window.getSelection?.()?.toString() ?? \"\";\n const target = resolveTarget({ element, selectionText, editable });\n if (!target) return false;\n const sheet = mobile ?? (touch || mobileViewport());\n setState({ target, point: { x, y }, sheet });\n setOpen(true);\n if (sheet && !Sheet) void loadSheet().then((m) => setSheet(() => m.ActionSheet));\n if (!sheet && !Menu) void loadMenu().then((m) => setMenu(() => m.ContextMenuPanel));\n return true;\n },\n [resolveTarget, mobile, Sheet, Menu, loadSheet, loadMenu],\n );\n\n const child = React.Children.only(children) as React.ReactElement<Record<string, unknown>>;\n const props = child.props;\n const compose =\n <E,>(own: (e: E) => void, theirs: unknown) =>\n (e: E) => {\n if (typeof theirs === \"function\") (theirs as (e: E) => void)(e);\n own(e);\n };\n\n const trigger = React.cloneElement(child, {\n \"data-alchemy-trigger\": \"context\",\n onContextMenu: compose((e: React.MouseEvent) => {\n if (e.defaultPrevented) return; // an inner menu owns the gesture\n const el = e.target as Element;\n if (isEditable(el) && !editable) return; // never steal a live text field's native menu\n if (openAt(el, e.clientX, e.clientY, false)) e.preventDefault();\n }, props.onContextMenu),\n onTouchStart: compose((e: React.TouchEvent) => {\n const t = e.touches[0];\n if (!t) return;\n const el = e.target as Element;\n if (isEditable(el) && !editable) return;\n const timer = setTimeout(() => {\n press.current = null;\n openAt(el, t.clientX, t.clientY, true);\n }, LONG_PRESS_MS);\n press.current = { timer, x: t.clientX, y: t.clientY };\n e.stopPropagation();\n }, props.onTouchStart),\n onTouchMove: compose((e: React.TouchEvent) => {\n const t = e.touches[0];\n const p = press.current;\n if (p && t && Math.hypot(t.clientX - p.x, t.clientY - p.y) > 8) {\n clearTimeout(p.timer);\n press.current = null;\n }\n }, props.onTouchMove),\n onTouchEnd: compose(() => {\n if (press.current) clearTimeout(press.current.timer);\n press.current = null;\n }, props.onTouchEnd),\n });\n\n return (\n <>\n {trigger}\n {state && !state.sheet && Menu ? (\n <Menu\n {...options}\n target={state.target}\n point={state.point}\n open={open}\n onOpenChange={setOpen}\n {...(arrangement ? { arrangement } : {})}\n {...(density ? { density } : {})}\n />\n ) : null}\n {state && state.sheet && Sheet ? <Sheet {...options} target={state.target} open={open} onOpenChange={setOpen} /> : null}\n </>\n );\n}\n","/**\n * The click target (CONTRACT §2.4) in its own module: `/ports` references it,\n * and `/ports` must stay free of every other package (types only).\n */\nimport type { QualifiedValueKey, ResolvedItem, ResolvedSurfaceDeclaration, WriteTarget } from \"../declare/types\";\n\n/** The six universal verbs — the ONLY rows that may grey (R1 c). */\nexport const UNIVERSAL_VERBS = [\"copy\", \"cut\", \"paste\", \"undo\", \"redo\", \"find\"] as const;\nexport type UniversalVerb = (typeof UNIVERSAL_VERBS)[number];\n\n/** The transfer Payload's kinds (`actions/types.ts` asserts equality at compile time). */\nexport type PayloadKind = \"text\" | \"markdown\" | \"json\" | \"rows\" | \"registered\";\n\n/** What eligibility is computed from: everything declared at the click target. */\nexport interface ClickTarget {\n surface: { instanceId: string; surfaceName: string } | null;\n /** The resolved declaration (inheritance applied). Eligibility decides by KEY existence over it. */\n declaration: ResolvedSurfaceDeclaration | null;\n /** Declared value keys with a read path here (screen names + qualified item keys). Key existence, not population. */\n valueKeys: ReadonlySet<QualifiedValueKey>;\n /** Scope chain, most general first: [\"global\", \"<domain>\", \"<surfaceName>\"]. */\n scopeChain: readonly string[];\n /** The surface's explicit exclusions (the one override). */\n excludedActionIds: ReadonlySet<string>;\n item: ResolvedItem | null;\n level: string | null;\n /** Offsets + the live range handle, editable or not. */\n selection: {\n text: string;\n type: \"editable\" | \"non-editable\";\n start: number;\n end: number;\n /** Opaque host handle (DOM Range / element) used to restore or stream into the selection. */\n handle?: unknown;\n } | null;\n /** Payload kinds a capture of this target would produce (from declared value types/kinds). */\n payloadKinds: readonly PayloadKind[];\n /** Declared targets writable on this target right now. */\n writable: readonly WriteTarget[];\n readOnly: boolean;\n /** True when any declared value here is secret/credential or non-exportable. */\n restricted: boolean;\n organizationId: string | null;\n auth: { authenticated: boolean; admin: boolean; creator: boolean };\n /**\n * Host-owned context a provider reads to act (the rich-document source, the\n * editable field's callbacks). Opaque to the package; never crosses into the\n * model. Providers that need it narrow it themselves.\n */\n host?: unknown;\n}\n\n","/**\n * The one action registry (CONTRACT §2.4).\n *\n * - Duplicate ids are REFUSED, never overwritten (rich-document's registry\n * silently overwrote — R12). A duplicate known at registration throws; one\n * that only appears when a provider yields it is dropped and captured.\n * - Eligibility is one pure pass over the resolved click target, under\n * \"restrict, never relax\": a host may remove ids or categories, never add.\n * - R1: an action that does not apply is ABSENT. Only the six universal verbs\n * (category \"clipboard\") may answer `unavailable-verb`, with a sentence; any\n * other action answering it is a contract break → absent + diagnostics.\n */\nimport type { AlchemyHostPorts, Json } from \"../ports\";\nimport {\n UNIVERSAL_VERBS,\n type Action,\n type ActionProvider,\n type ActionRegistry,\n type ClickTarget,\n type Eligibility,\n type ResolveRestriction,\n type ResolvedAction,\n} from \"./types\";\n\nexport class DuplicateActionError extends Error {\n readonly actionId: string;\n readonly providers: readonly [string, string];\n constructor(actionId: string, first: string, second: string) {\n super(\n first === second\n ? `Action \"${actionId}\" is yielded twice by provider \"${first}\". Ids are unique; the second was refused.`\n : `Action \"${actionId}\" is registered by provider \"${first}\" and again by \"${second}\". Ids are unique; \"${second}\"'s copy was refused.`,\n );\n this.name = \"DuplicateActionError\";\n this.actionId = actionId;\n this.providers = [first, second];\n }\n}\n\nexport class DuplicateProviderError extends Error {\n readonly providerId: string;\n constructor(providerId: string) {\n super(`Action provider \"${providerId}\" is already registered. Unregister it first; nothing was overwritten.`);\n this.name = \"DuplicateProviderError\";\n this.providerId = providerId;\n }\n}\n\nexport interface ActionRegistryOptions {\n /** `diagnostics` is required (nothing fails silently); `auth` decides whether requiresAuth actions reach a signed-out person. */\n ports: Pick<AlchemyHostPorts, \"diagnostics\" | \"auth\">;\n}\n\nconst VERBS = new Set<string>(UNIVERSAL_VERBS);\n\nfunction capture(ports: ActionRegistryOptions[\"ports\"], error: unknown, detail: Json): void {\n try {\n ports.diagnostics.capture(error, { area: \"actions\", detail });\n } catch {\n // A broken diagnostics port must never take the menu down with it.\n }\n}\n\n/**\n * Eligibility of one action at one target — the ONE pure pass (CONTRACT §1.6).\n * Exported for providers' tests; hosts call `registry.resolve`.\n */\nexport function computeEligibility(\n action: Action,\n target: ClickTarget,\n options: { restrict?: ResolveRestriction; authResumable: boolean },\n): Eligibility | { status: \"contract-break\"; reason: string } {\n const restrict = options.restrict;\n if (target.excludedActionIds.has(action.id)) return { status: \"absent\" };\n if (restrict?.exclude?.includes(action.id)) return { status: \"absent\" };\n if (restrict?.categories && !restrict.categories.includes(action.category)) return { status: \"absent\" };\n if (action.writes && action.writes.length > 0) {\n // A read-only target offers nothing that would change the record.\n if (target.readOnly) return { status: \"absent\" };\n const writable = new Set(target.writable.map((w) => w.name));\n if (!action.writes.some((name) => writable.has(name))) return { status: \"absent\" };\n }\n if (action.requiresAuth && !target.auth.authenticated && !options.authResumable) {\n // Sign-in-then-resume is the capability; without the auth port it is absent (N8).\n return { status: \"absent\" };\n }\n const own = action.eligible(target);\n if (own.status !== \"unavailable-verb\") return own;\n if (action.category !== \"clipboard\" || !VERBS.has(own.verb)) {\n return {\n status: \"contract-break\",\n reason: `Action \"${action.id}\" answered unavailable-verb but only the six universal verbs (category \"clipboard\") may grey; it is absent instead.`,\n };\n }\n if (!own.sentence.trim()) {\n return {\n status: \"contract-break\",\n reason: `Universal verb \"${action.id}\" greyed without a sentence; a greyed verb must say why.`,\n };\n }\n return own;\n}\n\ninterface Entry {\n provider: ActionProvider;\n declared: readonly string[];\n}\n\nexport function createActionRegistry(options: ActionRegistryOptions): ActionRegistry {\n const ports = options.ports;\n const entries = new Map<string, Entry>();\n const listeners = new Set<() => void>();\n const notify = () => {\n for (const l of [...listeners]) l();\n };\n\n return {\n register(provider) {\n if (entries.has(provider.id)) throw new DuplicateProviderError(provider.id);\n const declared = provider.declaredIds?.() ?? [];\n const own = new Set<string>();\n for (const id of declared) {\n if (own.has(id)) throw new DuplicateActionError(id, provider.id, provider.id);\n own.add(id);\n for (const [otherId, other] of entries) {\n if (other.declared.includes(id)) throw new DuplicateActionError(id, otherId, provider.id);\n }\n }\n const entry: Entry = { provider, declared };\n entries.set(provider.id, entry);\n notify();\n return () => {\n if (entries.get(provider.id) === entry) {\n entries.delete(provider.id);\n notify();\n }\n };\n },\n\n async resolve(target, restrict) {\n const authResumable = Boolean(ports.auth);\n const seen = new Map<string, string>();\n const out: ResolvedAction[] = [];\n for (const [providerId, { provider }] of [...entries]) {\n let actions: readonly Action[];\n try {\n actions = await provider.actions(target);\n } catch (error) {\n capture(ports, error, { providerId, stage: \"actions\" });\n continue;\n }\n for (const raw of actions) {\n const first = seen.get(raw.id);\n if (first !== undefined) {\n capture(ports, new DuplicateActionError(raw.id, first, providerId), { actionId: raw.id });\n continue;\n }\n seen.set(raw.id, providerId);\n const action: Action = raw.provider === providerId ? raw : { ...raw, provider: providerId };\n let eligibility: ReturnType<typeof computeEligibility>;\n try {\n eligibility = computeEligibility(action, target, { restrict: restrict ?? {}, authResumable });\n } catch (error) {\n capture(ports, error, { actionId: action.id, stage: \"eligible\" });\n continue;\n }\n if (eligibility.status === \"contract-break\") {\n capture(ports, new Error(eligibility.reason), { actionId: action.id, stage: \"eligible\" });\n continue;\n }\n if (eligibility.status === \"absent\") continue;\n out.push({ action, eligibility });\n }\n }\n return out;\n },\n\n providers() {\n return [...entries.keys()];\n },\n\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n };\n}\n\n/** A provider over a fixed list; its ids are declared up front so duplicates fail at registration. */\nexport function staticActionProvider(\n id: string,\n actions: readonly Action[],\n tier: ActionProvider[\"tier\"] = \"T0\",\n): ActionProvider {\n const list = actions.map((a) => (a.provider === id ? a : { ...a, provider: id }));\n return {\n id,\n tier,\n declaredIds: () => list.map((a) => a.id),\n actions: () => list,\n };\n}\n\n/** Always-available eligibility, for actions with no rule of their own. */\nexport const alwaysEligible = (): Eligibility => ({ status: \"available\" });\n","/**\n * The shared React context (T0-safe: imports only React and types). Shared\n * through globalThis so every per-layout bundle reads the same provider.\n */\nimport * as React from \"react\";\nimport type { ActionRegistry } from \"../actions/types\";\nimport type { AlchemyHostPorts } from \"../ports\";\n\nexport interface AlchemyActionsValue {\n registry: ActionRegistry;\n ports: AlchemyHostPorts;\n}\n\nconst KEY = Symbol.for(\"ai-matrx.alchemy.actions-context\");\ntype Holder = { [KEY]?: React.Context<AlchemyActionsValue | null> };\nexport const AlchemyActionsContext: React.Context<AlchemyActionsValue | null> =\n ((globalThis as Holder)[KEY] ??= React.createContext<AlchemyActionsValue | null>(null));\n\nexport function useAlchemyActions(): AlchemyActionsValue {\n const value = React.useContext(AlchemyActionsContext);\n if (!value) throw new Error(\"Alchemy actions: render inside <AlchemyActionsProvider> (@ai-matrx/alchemy/react/host).\");\n return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSA,IAAAA,SAAuB;;;ACFhB,IAAM,kBAAkB,CAAC,QAAQ,OAAO,SAAS,QAAQ,QAAQ,MAAM;;;ACiBvE,IAAM,uBAAN,cAAmC,MAAM;AAAA,EACrC;AAAA,EACA;AAAA,EACT,YAAY,UAAkB,OAAe,QAAgB;AAC3D;AAAA,MACE,UAAU,SACN,WAAW,QAAQ,mCAAmC,KAAK,+CAC3D,WAAW,QAAQ,gCAAgC,KAAK,mBAAmB,MAAM,uBAAuB,MAAM;AAAA,IACpH;AACA,SAAK,OAAO;AACZ,SAAK,WAAW;AAChB,SAAK,YAAY,CAAC,OAAO,MAAM;AAAA,EACjC;AACF;AAEO,IAAM,yBAAN,cAAqC,MAAM;AAAA,EACvC;AAAA,EACT,YAAY,YAAoB;AAC9B,UAAM,oBAAoB,UAAU,wEAAwE;AAC5G,SAAK,OAAO;AACZ,SAAK,aAAa;AAAA,EACpB;AACF;AAOA,IAAM,QAAQ,IAAI,IAAY,eAAe;AAE7C,SAAS,QAAQ,OAAuC,OAAgB,QAAoB;AAC1F,MAAI;AACF,UAAM,YAAY,QAAQ,OAAO,EAAE,MAAM,WAAW,OAAO,CAAC;AAAA,EAC9D,QAAQ;AAAA,EAER;AACF;AAMO,SAAS,mBACd,QACA,QACA,SAC4D;AAC5D,QAAM,WAAW,QAAQ;AACzB,MAAI,OAAO,kBAAkB,IAAI,OAAO,EAAE,EAAG,QAAO,EAAE,QAAQ,SAAS;AACvE,MAAI,UAAU,SAAS,SAAS,OAAO,EAAE,EAAG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