@ai-matrx/design-system 0.21.6 → 0.21.8

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.
@@ -1369,6 +1369,10 @@ function ContentTransferMenuSession({ references = [], referenceActions = [], so
1369
1369
  const [notice, setNotice] = React9.useState(null);
1370
1370
  const [receiptTarget, setReceiptTarget] = React9.useState();
1371
1371
  const [paletteOpen, setPaletteOpen] = React9.useState(false);
1372
+ const [paletteTarget, setPaletteTarget] = React9.useState(null);
1373
+ const externalPaletteClose = React9.useRef(null);
1374
+ const externalPaletteRestoreFocus = React9.useRef(null);
1375
+ const feedbackDocument = React9.useRef(null);
1372
1376
  const [mode, setMode] = React9.useState("copy");
1373
1377
  const scopes = React9.useMemo(() => table?.availableScopes ?? ["target"], [table]);
1374
1378
  const [requestedScope, setRequestedScope] = React9.useState(table?.initialScope ?? "target");
@@ -1465,6 +1469,40 @@ function ContentTransferMenuSession({ references = [], referenceActions = [], so
1465
1469
  fence.finish(controller);
1466
1470
  }
1467
1471
  }, [captureOne, fence, initialScope, primary]);
1472
+ const closePalette = React9.useCallback(() => {
1473
+ const onClose = externalPaletteClose.current;
1474
+ const restoreFocus = externalPaletteRestoreFocus.current;
1475
+ externalPaletteClose.current = null;
1476
+ externalPaletteRestoreFocus.current = null;
1477
+ onClose?.();
1478
+ restoreFocus?.();
1479
+ setPaletteTarget(null);
1480
+ setPaletteOpen(false);
1481
+ }, []);
1482
+ const mountPalette = React9.useCallback((target, onClose, restoreFocus) => {
1483
+ if (!target) {
1484
+ externalPaletteClose.current = null;
1485
+ externalPaletteRestoreFocus.current = null;
1486
+ setPaletteTarget(null);
1487
+ setPaletteOpen(false);
1488
+ return;
1489
+ }
1490
+ if (!enabled) throw new Error("Alchemy is not enabled for this record.");
1491
+ if (disabled) throw new Error("Alchemy is disabled for this record.");
1492
+ externalPaletteClose.current = onClose ?? null;
1493
+ externalPaletteRestoreFocus.current = restoreFocus ?? null;
1494
+ feedbackDocument.current = target.ownerDocument;
1495
+ restoreFocusRef.current = restoreFocus ?? (() => target.focus());
1496
+ setPaletteTarget(target);
1497
+ setPaletteOpen(true);
1498
+ setMode("copy");
1499
+ void preflight();
1500
+ }, [closePalette, disabled, enabled, preflight]);
1501
+ React9.useEffect(() => {
1502
+ if (!paletteTarget || !paletteOpen) return;
1503
+ const firstControl = paletteTarget.querySelector("button:not([disabled]), select:not([disabled]), input:not([disabled]), textarea:not([disabled]), [href]");
1504
+ firstControl?.focus();
1505
+ }, [paletteOpen, paletteTarget]);
1468
1506
  const transfer = React9.useCallback(async (format, download, alternate) => {
1469
1507
  const { controller, id } = fence.begin();
1470
1508
  try {
@@ -1605,6 +1643,7 @@ function ContentTransferMenuSession({ references = [], referenceActions = [], so
1605
1643
  );
1606
1644
  React9.useImperativeHandle(controllerRef, () => ({
1607
1645
  focusTrigger: () => triggerRef.current?.focus(),
1646
+ mountPalette,
1608
1647
  preparePrimary: async (options) => {
1609
1648
  if (!enabled) throw new Error("Alchemy is not enabled for this record.");
1610
1649
  if (disabled) throw new Error("Alchemy is disabled for this record.");
@@ -1619,7 +1658,7 @@ function ContentTransferMenuSession({ references = [], referenceActions = [], so
1619
1658
  externalWorkspaceKeys.current.add(requestedKey);
1620
1659
  await openWorkspace(requestedKey, { source: requestedSource, label: requestedLabel });
1621
1660
  }
1622
- }), [disabled, enabled, hide, openWorkspace, primary, primaryWorkspaceKey, sourceLabel]);
1661
+ }), [disabled, enabled, hide, mountPalette, openWorkspace, primary, primaryWorkspaceKey, sourceLabel]);
1623
1662
  const runAction = React9.useCallback(async (action) => {
1624
1663
  const { controller, id } = fence.begin();
1625
1664
  try {
@@ -1685,7 +1724,6 @@ function ContentTransferMenuSession({ references = [], referenceActions = [], so
1685
1724
  return (0, import_content_transfer2.sealTransferArtifact)({ snapshotId: draft.snapshotId, draftRevision: draft.revision, format: "ai-context", plainText: (0, import_content_transfer2.buildAgentPayload)({ kind: "matrx_content", location: sourceLabel, description: "Captured content for an assistant", data: JSON.parse(json.plainText), attributes: { source: draft.sourceId } }), omissions: [...json.omissions] });
1686
1725
  }
1687
1726
  };
1688
- const closePalette = () => setPaletteOpen(false);
1689
1727
  const tile = (id, label2, onClick, options = {}) => {
1690
1728
  const presentation = options.action;
1691
1729
  const Icon2 = presentation?.icon;
@@ -1701,122 +1739,125 @@ function ContentTransferMenuSession({ references = [], referenceActions = [], so
1701
1739
  ] })
1702
1740
  ] }, id);
1703
1741
  };
1742
+ const palette = /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
1743
+ menuStatus === "loading" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "matrx-alchemy-palette-status", children: "Inspecting content\u2026" }) : menuStatus !== "idle" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "matrx-alchemy-error", children: menuStatus }) : null,
1744
+ table && scopes.length > 1 ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("label", { className: "matrx-alchemy-scope", children: [
1745
+ "Content scope",
1746
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("select", { "aria-label": "Content scope", value: initialScope, onChange: (event) => {
1747
+ const next = scopes.find((scope) => scope === event.target.value);
1748
+ if (next) {
1749
+ setRequestedScope(next);
1750
+ void preflight(next);
1751
+ }
1752
+ }, children: scopes.map((scope) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("option", { value: scope, children: table.scopeLabels?.[scope] ?? SCOPE_LABEL[scope] }, scope)) })
1753
+ ] }) : null,
1754
+ copyAvailable || downloadAvailable ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("section", { className: "matrx-alchemy-output", children: [
1755
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("h3", { children: resolvedMode === "copy" ? "Copy as" : "Download as" }),
1756
+ copyAvailable && downloadAvailable ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "matrx-alchemy-mode", "aria-label": "Output action", children: [
1757
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", "aria-label": "Copy mode", "aria-pressed": resolvedMode === "copy", onClick: () => setMode("copy"), children: "Copy" }),
1758
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", "aria-label": "Download mode", "aria-pressed": resolvedMode === "download", onClick: () => setMode("download"), children: "Download" })
1759
+ ] }) : null,
1760
+ resolvedMode === "copy" && copyAvailable ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
1761
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "matrx-alchemy-palette-grid", children: [
1762
+ visibleCopies.map((format) => tile(format, { plain: "Text", markdown: "Markdown", html: "Formatted", json: "JSON", "compact-json": "Compact", csv: "CSV", tsv: "Sheets" }[format], () => void transfer(format, false), { ariaLabel: `Copy ${LABEL[format]}` })),
1763
+ visibleAdapters.map((adapter) => tile(adapter.id, adapter.label, () => void transfer(adapter, false), { custom: true }))
1764
+ ] }),
1765
+ quickVariants("copy").length ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PaletteRows, { title: "Quick copy", items: quickVariants("copy"), onRun: (variant) => {
1766
+ closePalette();
1767
+ void transfer("markdown", false, variant);
1768
+ } }) : null
1769
+ ] }) : null,
1770
+ resolvedMode === "download" && downloadAvailable ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_jsx_runtime10.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "matrx-alchemy-palette-grid", children: [
1771
+ visibleDownloads.map((format) => tile(format, { plain: "Text", markdown: "Markdown", html: "Formatted", json: "JSON", "compact-json": "Compact", csv: "CSV", tsv: "Sheets", xlsx: "Excel" }[format], () => void transfer(format, true), { ariaLabel: `Download ${LABEL[format]}` })),
1772
+ visibleAdapters.map((adapter) => tile(adapter.id, adapter.label, () => void transfer(adapter, true), { custom: true })),
1773
+ downloadActions.map((action) => tile(action.id, action.label, () => void runAction(action), { custom: true, action, file: true }))
1774
+ ] }) }) : null
1775
+ ] }) : null,
1776
+ prepareAvailable ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
1777
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PaletteRows, { title: "Copy for AI", ai: true, glyphKind: "ai-copy", fallbackHint: "Copies immediately", extra: sourceFormats ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("button", { type: "button", className: "matrx-alchemy-palette-row", onClick: () => {
1778
+ closePalette();
1779
+ void transfer(nativeAiFormat, false);
1780
+ }, children: [
1781
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PaletteGlyph, { kind: "ai-copy" }),
1782
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { children: [
1783
+ "Copy with AI context",
1784
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("small", { className: "matrx-alchemy-menu-hint", children: "Include source context" })
1785
+ ] })
1786
+ ] }) : null, items: quickVariants("ai"), onRun: (variant) => {
1787
+ closePalette();
1788
+ void transfer("markdown", false, variant);
1789
+ } }),
1790
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PaletteRows, { title: "Edit and prepare", items: [], extra: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("button", { type: "button", className: "matrx-alchemy-palette-row", "aria-label": "Prepare for AI", onClick: () => {
1791
+ closePalette();
1792
+ void openWorkspace();
1793
+ }, children: [
1794
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PaletteGlyph, { kind: "sliders" }),
1795
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { children: [
1796
+ "Prepare for AI",
1797
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("small", { className: "matrx-alchemy-menu-hint", children: "Trim, edit or summarize" })
1798
+ ] })
1799
+ ] }) })
1800
+ ] }) : null,
1801
+ prepareAvailable && (nearestWorkspaceKey || variants.length) ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PaletteRows, { title: "Other sources", items: [], extra: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
1802
+ nearestWorkspaceKey && nearestSurface ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("button", { type: "button", className: "matrx-alchemy-palette-row", onClick: () => {
1803
+ closePalette();
1804
+ void openWorkspace(nearestWorkspaceKey, { source: nearestSurface, label: nearestSurface.surfaceName });
1805
+ }, children: [
1806
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PaletteGlyph, { kind: "surface" }),
1807
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: "Prepare this page" })
1808
+ ] }) : null,
1809
+ variants.map((variant) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", className: "matrx-alchemy-palette-row", "aria-label": variant.ariaLabel, onClick: () => {
1810
+ closePalette();
1811
+ void openWorkspace(variantWorkspaceKeys.get(variant.id), variant);
1812
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(MenuPresentation, { ...variant, label: `Prepare ${variant.label}` }) }, variant.id))
1813
+ ] }) }) : null,
1814
+ references.length || referenceActions.length ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("section", { className: "matrx-alchemy-palette-section", children: [
1815
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("h3", { children: "References" }),
1816
+ referenceActions.map((action) => /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("button", { type: "button", className: "matrx-alchemy-palette-row", onClick: () => void openReference(action), children: [
1817
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PaletteGlyph, { kind: "link" }),
1818
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: action.label }),
1819
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("svg", { className: "matrx-alchemy-disclosure", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.5", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("path", { d: "m6 4 4 4-4 4" }) })
1820
+ ] }, action.id)),
1821
+ references.map((reference) => /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("button", { type: "button", className: "matrx-alchemy-palette-row", title: "Copies a reference to saved data", onClick: () => void copyReference(reference), children: [
1822
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PaletteGlyph, { kind: "link" }),
1823
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: reference.label })
1824
+ ] }, reference.id))
1825
+ ] }) : null,
1826
+ ["save", "chat", "email", "other"].map((group) => {
1827
+ const entries = ordinaryActions.filter((action) => (action.group ?? "other") === group);
1828
+ return entries.length ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("details", { className: "matrx-alchemy-palette-destinations", children: [
1829
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("summary", { children: [
1830
+ group === "save" ? "Save to Matrx" : group === "chat" ? "Continue with AI" : group === "email" ? "Email to me" : "Actions",
1831
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: "matrx-alchemy-disclosure-meta", children: [
1832
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: entries.length }),
1833
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("svg", { className: "matrx-alchemy-disclosure", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.5", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("path", { d: "m6 4 4 4-4 4" }) })
1834
+ ] })
1835
+ ] }),
1836
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { children: entries.map((action) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", className: "matrx-alchemy-palette-row", "aria-label": action.ariaLabel, onClick: () => {
1837
+ closePalette();
1838
+ void runAction(action);
1839
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(DestinationPresentation, { action }) }, action.id)) })
1840
+ ] }, group) : null;
1841
+ })
1842
+ ] });
1843
+ const feedbackOwner = paletteTarget ?? triggerRef.current ?? feedbackDocument.current?.body ?? null;
1704
1844
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: cn("matrx-alchemy", className), onClick: stopPropagation ? (event) => event.stopPropagation() : void 0, children: [
1705
- !triggerHidden ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Popover, { open: paletteOpen, onOpenChange: (open) => {
1706
- setPaletteOpen(open);
1845
+ !triggerHidden && !paletteTarget ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Popover, { open: paletteOpen, onOpenChange: (open) => {
1707
1846
  if (open) {
1847
+ setPaletteOpen(true);
1708
1848
  setMode("copy");
1709
1849
  void preflight();
1710
- }
1850
+ } else closePalette();
1711
1851
  }, children: [
1712
1852
  /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PopoverTrigger, { asChild: true, children: triggerVariant === "outline" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Button, { ref: triggerRef, variant: "outline", size: "icon-sm", "aria-label": `Copy, transform or export ${sourceLabel}`, "data-alchemy-trigger": "outline", disabled, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(AlchemyGlyph, { icon }) }) : triggerVariant === "glass" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(TapTargetButton, { ref: triggerRef, icon: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(AlchemyGlyph, { icon }), tooltip: false, ariaLabel: `Copy, transform or export ${sourceLabel}`, "data-alchemy-trigger": "glass", "data-alchemy-size": triggerSize, disabled }) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(TapTargetButtonTransparent, { ref: triggerRef, icon: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(AlchemyGlyph, { icon }), tooltip: false, ariaLabel: `Copy, transform or export ${sourceLabel}`, "data-alchemy-trigger": "transparent", "data-alchemy-size": triggerSize, disabled }) }),
1713
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(PopoverContent, { align: "end", className: "matrx-alchemy-menu matrx-alchemy-palette", "aria-label": "Alchemy output options", onCloseAutoFocus: () => triggerRef.current?.focus(), children: [
1714
- menuStatus === "loading" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "matrx-alchemy-palette-status", children: "Inspecting content\u2026" }) : menuStatus !== "idle" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "matrx-alchemy-error", children: menuStatus }) : null,
1715
- table && scopes.length > 1 ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("label", { className: "matrx-alchemy-scope", children: [
1716
- "Content scope",
1717
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("select", { "aria-label": "Content scope", value: initialScope, onChange: (event) => {
1718
- const next = scopes.find((scope) => scope === event.target.value);
1719
- if (next) {
1720
- setRequestedScope(next);
1721
- void preflight(next);
1722
- }
1723
- }, children: scopes.map((scope) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("option", { value: scope, children: table.scopeLabels?.[scope] ?? SCOPE_LABEL[scope] }, scope)) })
1724
- ] }) : null,
1725
- copyAvailable || downloadAvailable ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("section", { className: "matrx-alchemy-output", children: [
1726
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("h3", { children: resolvedMode === "copy" ? "Copy as" : "Download as" }),
1727
- copyAvailable && downloadAvailable ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "matrx-alchemy-mode", "aria-label": "Output action", children: [
1728
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", "aria-label": "Copy mode", "aria-pressed": resolvedMode === "copy", onClick: () => setMode("copy"), children: "Copy" }),
1729
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", "aria-label": "Download mode", "aria-pressed": resolvedMode === "download", onClick: () => setMode("download"), children: "Download" })
1730
- ] }) : null,
1731
- resolvedMode === "copy" && copyAvailable ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
1732
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "matrx-alchemy-palette-grid", children: [
1733
- visibleCopies.map((format) => tile(format, { plain: "Text", markdown: "Markdown", html: "Formatted", json: "JSON", "compact-json": "Compact", csv: "CSV", tsv: "Sheets" }[format], () => void transfer(format, false), { ariaLabel: `Copy ${LABEL[format]}` })),
1734
- visibleAdapters.map((adapter) => tile(adapter.id, adapter.label, () => void transfer(adapter, false), { custom: true }))
1735
- ] }),
1736
- quickVariants("copy").length ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PaletteRows, { title: "Quick copy", items: quickVariants("copy"), onRun: (variant) => {
1737
- closePalette();
1738
- void transfer("markdown", false, variant);
1739
- } }) : null
1740
- ] }) : null,
1741
- resolvedMode === "download" && downloadAvailable ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_jsx_runtime10.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "matrx-alchemy-palette-grid", children: [
1742
- visibleDownloads.map((format) => tile(format, { plain: "Text", markdown: "Markdown", html: "Formatted", json: "JSON", "compact-json": "Compact", csv: "CSV", tsv: "Sheets", xlsx: "Excel" }[format], () => void transfer(format, true), { ariaLabel: `Download ${LABEL[format]}` })),
1743
- visibleAdapters.map((adapter) => tile(adapter.id, adapter.label, () => void transfer(adapter, true), { custom: true })),
1744
- downloadActions.map((action) => tile(action.id, action.label, () => void runAction(action), { custom: true, action, file: true }))
1745
- ] }) }) : null
1746
- ] }) : null,
1747
- prepareAvailable ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
1748
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PaletteRows, { title: "Copy for AI", ai: true, glyphKind: "ai-copy", fallbackHint: "Copies immediately", extra: sourceFormats ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("button", { type: "button", className: "matrx-alchemy-palette-row", onClick: () => {
1749
- closePalette();
1750
- void transfer(nativeAiFormat, false);
1751
- }, children: [
1752
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PaletteGlyph, { kind: "ai-copy" }),
1753
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { children: [
1754
- "Copy with AI context",
1755
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("small", { className: "matrx-alchemy-menu-hint", children: "Include source context" })
1756
- ] })
1757
- ] }) : null, items: quickVariants("ai"), onRun: (variant) => {
1758
- closePalette();
1759
- void transfer("markdown", false, variant);
1760
- } }),
1761
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PaletteRows, { title: "Edit and prepare", items: [], extra: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("button", { type: "button", className: "matrx-alchemy-palette-row", "aria-label": "Prepare for AI", onClick: () => {
1762
- closePalette();
1763
- void openWorkspace();
1764
- }, children: [
1765
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PaletteGlyph, { kind: "sliders" }),
1766
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { children: [
1767
- "Prepare for AI",
1768
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("small", { className: "matrx-alchemy-menu-hint", children: "Trim, edit or summarize" })
1769
- ] })
1770
- ] }) })
1771
- ] }) : null,
1772
- prepareAvailable && (nearestWorkspaceKey || variants.length) ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PaletteRows, { title: "Other sources", items: [], extra: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
1773
- nearestWorkspaceKey && nearestSurface ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("button", { type: "button", className: "matrx-alchemy-palette-row", onClick: () => {
1774
- closePalette();
1775
- void openWorkspace(nearestWorkspaceKey, { source: nearestSurface, label: nearestSurface.surfaceName });
1776
- }, children: [
1777
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PaletteGlyph, { kind: "surface" }),
1778
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: "Prepare this page" })
1779
- ] }) : null,
1780
- variants.map((variant) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", className: "matrx-alchemy-palette-row", "aria-label": variant.ariaLabel, onClick: () => {
1781
- closePalette();
1782
- void openWorkspace(variantWorkspaceKeys.get(variant.id), variant);
1783
- }, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(MenuPresentation, { ...variant, label: `Prepare ${variant.label}` }) }, variant.id))
1784
- ] }) }) : null,
1785
- references.length || referenceActions.length ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("section", { className: "matrx-alchemy-palette-section", children: [
1786
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("h3", { children: "References" }),
1787
- referenceActions.map((action) => /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("button", { type: "button", className: "matrx-alchemy-palette-row", onClick: () => void openReference(action), children: [
1788
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PaletteGlyph, { kind: "link" }),
1789
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: action.label }),
1790
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("svg", { className: "matrx-alchemy-disclosure", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.5", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("path", { d: "m6 4 4 4-4 4" }) })
1791
- ] }, action.id)),
1792
- references.map((reference) => /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("button", { type: "button", className: "matrx-alchemy-palette-row", title: "Copies a reference to saved data", onClick: () => void copyReference(reference), children: [
1793
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PaletteGlyph, { kind: "link" }),
1794
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: reference.label })
1795
- ] }, reference.id))
1796
- ] }) : null,
1797
- ["save", "chat", "email", "other"].map((group) => {
1798
- const entries = ordinaryActions.filter((action) => (action.group ?? "other") === group);
1799
- return entries.length ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("details", { className: "matrx-alchemy-palette-destinations", children: [
1800
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("summary", { children: [
1801
- group === "save" ? "Save to Matrx" : group === "chat" ? "Continue with AI" : group === "email" ? "Email to me" : "Actions",
1802
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: "matrx-alchemy-disclosure-meta", children: [
1803
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: entries.length }),
1804
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("svg", { className: "matrx-alchemy-disclosure", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.5", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("path", { d: "m6 4 4 4-4 4" }) })
1805
- ] })
1806
- ] }),
1807
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { children: entries.map((action) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", className: "matrx-alchemy-palette-row", "aria-label": action.ariaLabel, onClick: () => {
1808
- closePalette();
1809
- void runAction(action);
1810
- }, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(DestinationPresentation, { action }) }, action.id)) })
1811
- ] }, group) : null;
1812
- })
1813
- ] })
1853
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PopoverContent, { align: "end", className: "matrx-alchemy-menu matrx-alchemy-palette", "aria-label": "Alchemy output options", onCloseAutoFocus: () => triggerRef.current?.focus(), children: palette })
1814
1854
  ] }) : null,
1815
- notice && triggerRef.current ? (0, import_react_dom.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "matrx-alchemy-feedback", children: [
1855
+ paletteTarget && paletteOpen ? (0, import_react_dom.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "matrx-alchemy-menu matrx-alchemy-palette", role: "dialog", "aria-label": "Alchemy output options", children: palette }), paletteTarget) : null,
1856
+ notice && feedbackOwner ? (0, import_react_dom.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "matrx-alchemy-feedback", children: [
1816
1857
  /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { role: "status", children: notice }),
1817
1858
  /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ReceiptLink, { target: receiptTarget }),
1818
1859
  /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", "aria-label": "Dismiss Alchemy feedback", onClick: () => setNotice(null), children: "\xD7" })
1819
- ] }), triggerRef.current.ownerDocument.body) : null,
1860
+ ] }), feedbackOwner.ownerDocument.body) : null,
1820
1861
  Object.values(workspaces).map((saved) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PreparationWorkspace, { restoreFocus: () => restoreFocusRef.current?.() ?? triggerRef.current?.focus(), open: workspaceOpen && workspaceKey === saved.key, state: saved, scopes, scopeLabels: table?.scopeLabels, onClose: () => setWorkspaceOpen(false), onChange: (next) => setWorkspaces((current) => ({ ...current, [saved.key]: next })), transport, adapters, actions: preparedActions, captureScope: workspaceCaptures.current.get(saved.key) ?? capturePrimary, ...ai ? { ai } : {}, onOutcome: report }, saved.key)),
1821
1862
  emailReview
1822
1863
  ] });