reifyui 0.11.1 → 0.13.0

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.
Files changed (85) hide show
  1. package/README.md +31 -2
  2. package/dist/chart.js +2 -0
  3. package/dist/chart.js.map +1 -1
  4. package/dist/chunk-EL2DHWOH.js +1710 -0
  5. package/dist/chunk-EL2DHWOH.js.map +1 -0
  6. package/dist/chunk-J633KV57.js +41 -0
  7. package/dist/chunk-J633KV57.js.map +1 -0
  8. package/dist/chunk-J7SECRIG.js +295 -0
  9. package/dist/chunk-J7SECRIG.js.map +1 -0
  10. package/dist/chunk-PIRPLH2Z.js +231 -0
  11. package/dist/chunk-PIRPLH2Z.js.map +1 -0
  12. package/dist/chunk-PZ5AY32C.js +10 -0
  13. package/dist/chunk-PZ5AY32C.js.map +1 -0
  14. package/dist/chunk-UKG4Z6QK.js +130 -0
  15. package/dist/chunk-UKG4Z6QK.js.map +1 -0
  16. package/dist/chunk-ZYWE47EO.js +19 -0
  17. package/dist/chunk-ZYWE47EO.js.map +1 -0
  18. package/dist/collab.cjs +169 -0
  19. package/dist/collab.cjs.map +1 -0
  20. package/dist/collab.d.ts +30 -0
  21. package/dist/collab.js +18 -0
  22. package/dist/collab.js.map +1 -0
  23. package/dist/graph.cjs +2244 -0
  24. package/dist/graph.cjs.map +1 -0
  25. package/dist/graph.d.ts +41 -0
  26. package/dist/graph.js +1870 -0
  27. package/dist/graph.js.map +1 -0
  28. package/dist/harness.js +1 -0
  29. package/dist/harness.js.map +1 -1
  30. package/dist/index.cjs +2044 -867
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.ts +20 -2
  33. package/dist/index.js +892 -1686
  34. package/dist/index.js.map +1 -1
  35. package/dist/sheet-doc.cjs +235 -0
  36. package/dist/sheet-doc.cjs.map +1 -0
  37. package/dist/sheet-doc.d.ts +16 -0
  38. package/dist/sheet-doc.js +20 -0
  39. package/dist/sheet-doc.js.map +1 -0
  40. package/dist/sheet.cjs +2322 -0
  41. package/dist/sheet.cjs.map +1 -0
  42. package/dist/sheet.d.ts +23 -0
  43. package/dist/sheet.js +237 -0
  44. package/dist/sheet.js.map +1 -0
  45. package/dist/slides.js +2 -0
  46. package/dist/slides.js.map +1 -1
  47. package/package.json +35 -3
  48. package/src/auth/client.js +4 -2
  49. package/src/collab/colors.js +18 -0
  50. package/src/collab/index.d.ts +30 -0
  51. package/src/collab/index.js +8 -0
  52. package/src/collab/keepAlive.js +34 -0
  53. package/src/collab/useLiveDoc.js +76 -0
  54. package/src/components/CascadeMenu.jsx +216 -0
  55. package/src/components/ChatMessages.jsx +30 -9
  56. package/src/components/Chip.jsx +37 -10
  57. package/src/components/Composer.jsx +80 -2
  58. package/src/components/resizable.jsx +82 -12
  59. package/src/graph/ConnectPane.jsx +634 -0
  60. package/src/graph/ConnectToolDetail.jsx +565 -0
  61. package/src/graph/LogsPane.jsx +328 -0
  62. package/src/graph/Skeleton.jsx +13 -0
  63. package/src/graph/draft.js +108 -0
  64. package/src/graph/format.js +37 -0
  65. package/src/graph/index.d.ts +41 -0
  66. package/src/graph/index.js +14 -0
  67. package/src/graph/useGraphCollab.js +299 -0
  68. package/src/graph/vgraph.js +215 -0
  69. package/src/index.d.ts +20 -2
  70. package/src/index.js +6 -1
  71. package/src/mention/MentionInput.jsx +420 -0
  72. package/src/mention/mentionModel.js +177 -0
  73. package/src/sheet/RunStrip.jsx +57 -0
  74. package/src/sheet/SheetGrid.jsx +444 -353
  75. package/src/sheet/doc.d.ts +16 -0
  76. package/src/sheet/index.d.ts +23 -0
  77. package/src/sheet/index.js +10 -0
  78. package/src/sheet/sheetDoc.js +203 -0
  79. package/src/sheet/useSheetCollab.js +102 -0
  80. package/src/sheet/useSheetRun.js +80 -0
  81. package/styles/chat.css +47 -5
  82. package/styles/chip.css +36 -0
  83. package/styles/graph.css +395 -0
  84. package/styles/mention.css +79 -0
  85. package/styles/sheet.css +156 -112
package/dist/index.cjs CHANGED
@@ -34,6 +34,7 @@ __export(src_exports, {
34
34
  Button: () => Button,
35
35
  Card: () => Card,
36
36
  Carousel: () => Carousel,
37
+ CascadeMenu: () => CascadeMenu,
37
38
  ChatMessages: () => ChatMessages,
38
39
  ChatMessagesSkeleton: () => ChatMessagesSkeleton,
39
40
  ChatPanel: () => ChatPanel,
@@ -70,6 +71,8 @@ __export(src_exports, {
70
71
  IcTool: () => IcTool,
71
72
  IcX: () => IcX,
72
73
  Input: () => Input,
74
+ MentionInput: () => MentionInput,
75
+ MentionText: () => MentionText,
73
76
  Modal: () => Modal,
74
77
  PaneResizer: () => PaneResizer,
75
78
  Panel: () => Panel,
@@ -102,7 +105,6 @@ __export(src_exports, {
102
105
  createResponsesDispatcher: () => createResponsesDispatcher,
103
106
  extOf: () => extOf,
104
107
  fetchBalance: () => fetchBalance,
105
- fitRowHeights: () => fitRowHeights,
106
108
  getSession: () => getSession,
107
109
  getToken: () => getToken,
108
110
  googleSignIn: () => googleSignIn,
@@ -658,15 +660,22 @@ function ToolRow(props) {
658
660
  var import_react4 = __toESM(require("react"), 1);
659
661
  var import_jsx_runtime3 = require("react/jsx-runtime");
660
662
  var DEFAULT_STATUS_LABELS = {
661
- failed: "\u2715 Failed \u2014 see the output above for the reason",
663
+ failed: "\u2715 Failed. See the output above for the reason",
662
664
  cancelled: "\u25FC Stopped by you",
663
- incomplete: "\u25D4 Hit its step or time limit \u2014 Continue to resume"
665
+ // Claims only what is true of every cause: an incomplete turn may have hit its step or time
666
+ // budget, or been cut mid-flight (a replica restart under a live turn settles as incomplete).
667
+ // Asserting "step or time limit" for all of them sent an operator debugging a limit that was
668
+ // never reached. A host that knows the actual cause says so in its own chrome (statusLabels /
669
+ // assistantFooter).
670
+ incomplete: "\u25D4 Stopped before finishing. Continue to resume"
664
671
  };
665
672
  var defaultMarkdown = (text) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { whiteSpace: "pre-wrap" }, children: text });
673
+ var REDUCED_MOTION = typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
666
674
  var REVEAL_SEC = 3;
667
675
  var MIN_CPS = 10;
668
676
  function TypewriterText(props) {
669
- const { text, active, render } = props;
677
+ const { text, render } = props;
678
+ const active = props.active && !REDUCED_MOTION;
670
679
  const [n, setN] = import_react4.default.useState(() => text ? text.length : 0);
671
680
  const textRef = import_react4.default.useRef(text);
672
681
  textRef.current = text;
@@ -698,11 +707,15 @@ function TypewriterText(props) {
698
707
  return render(shown);
699
708
  }
700
709
  function UserTurn(props) {
701
- const { msg, children } = props;
702
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "wbx-turn user", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "wbx-bubble-user", children: [
710
+ const { msg, children, label } = props;
711
+ const bubble = /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "wbx-bubble-user", children: [
703
712
  children,
704
713
  msg.text && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "wbx-bubble-text", children: msg.text })
705
- ] }) });
714
+ ] });
715
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "wbx-turn user", children: label ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "wbx-turn-body", children: [
716
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "wbx-role", children: label }),
717
+ bubble
718
+ ] }) : bubble });
706
719
  }
707
720
  function AssistantTurn(props) {
708
721
  const {
@@ -713,9 +726,11 @@ function AssistantTurn(props) {
713
726
  statusLabels = DEFAULT_STATUS_LABELS,
714
727
  renderStep,
715
728
  toolLabels,
716
- footer
729
+ footer,
730
+ label
717
731
  } = props;
718
732
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "wbx-turn asst", children: [
733
+ label ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "wbx-role", children: label }) : null,
719
734
  msg.blocks.map((b, bi) => b.kind === "tools" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
720
735
  ToolGroup,
721
736
  {
@@ -768,14 +783,15 @@ function ChatMessages(props) {
768
783
  statusLabels,
769
784
  renderStep,
770
785
  workingLabel,
771
- toolLabels
786
+ toolLabels,
787
+ roleLabel
772
788
  } = props;
773
789
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: messages.map((m, i) => {
774
790
  if (renderMessage) {
775
791
  const el = renderMessage(m, i);
776
792
  if (el !== void 0) return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react4.default.Fragment, { children: el }, i);
777
793
  }
778
- return m.role === "user" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(UserTurn, { msg: m, children: userExtras?.(m, i) }, i) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
794
+ return m.role === "user" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(UserTurn, { msg: m, label: roleLabel?.(m, i), children: userExtras?.(m, i) }, i) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
779
795
  AssistantTurn,
780
796
  {
781
797
  msg: m,
@@ -785,6 +801,7 @@ function ChatMessages(props) {
785
801
  statusLabels,
786
802
  renderStep,
787
803
  toolLabels,
804
+ label: roleLabel?.(m, i),
788
805
  footer: assistantFooter?.(m, i)
789
806
  },
790
807
  i
@@ -805,6 +822,7 @@ function Composer(props) {
805
822
  placeholder,
806
823
  rows = 1,
807
824
  autoGrow = true,
825
+ inline = false,
808
826
  maxRows = 15,
809
827
  autoFocus,
810
828
  // The composer on a landing page often has an ANIMATING placeholder (a typewriter cycling
@@ -812,6 +830,9 @@ function Composer(props) {
812
830
  // one is given — so the field announces a different name every few seconds.
813
831
  inputAriaLabel,
814
832
  attachments,
833
+ tray,
834
+ onFiles,
835
+ dropTargetRef,
815
836
  accessoriesLeft,
816
837
  accessoriesRight,
817
838
  renderSend,
@@ -820,6 +841,50 @@ function Composer(props) {
820
841
  } = props;
821
842
  const ownRef = (0, import_react5.useRef)(null);
822
843
  const taRef = inputRef || ownRef;
844
+ const rootRef = (0, import_react5.useRef)(null);
845
+ const [dropping, setDropping] = (0, import_react5.useState)(false);
846
+ (0, import_react5.useEffect)(() => {
847
+ if (!onFiles || disabled) return void 0;
848
+ const el = dropTargetRef && dropTargetRef.current || rootRef.current;
849
+ if (!el) return void 0;
850
+ let depth = 0;
851
+ const hasFiles = (e) => Array.from(e.dataTransfer && e.dataTransfer.types || []).includes("Files");
852
+ const enter = (e) => {
853
+ if (!hasFiles(e)) return;
854
+ e.preventDefault();
855
+ depth += 1;
856
+ setDropping(true);
857
+ };
858
+ const over = (e) => {
859
+ if (!hasFiles(e)) return;
860
+ e.preventDefault();
861
+ e.dataTransfer.dropEffect = "copy";
862
+ };
863
+ const leave = (e) => {
864
+ if (!hasFiles(e)) return;
865
+ e.preventDefault();
866
+ depth = Math.max(0, depth - 1);
867
+ if (depth === 0) setDropping(false);
868
+ };
869
+ const drop = (e) => {
870
+ if (!hasFiles(e)) return;
871
+ e.preventDefault();
872
+ depth = 0;
873
+ setDropping(false);
874
+ if (e.dataTransfer.files && e.dataTransfer.files.length) onFiles(e.dataTransfer.files);
875
+ };
876
+ el.addEventListener("dragenter", enter);
877
+ el.addEventListener("dragover", over);
878
+ el.addEventListener("dragleave", leave);
879
+ el.addEventListener("drop", drop);
880
+ return () => {
881
+ el.removeEventListener("dragenter", enter);
882
+ el.removeEventListener("dragover", over);
883
+ el.removeEventListener("dragleave", leave);
884
+ el.removeEventListener("drop", drop);
885
+ };
886
+ }, [onFiles, disabled, dropTargetRef]);
887
+ const rootClass = (classNames.root ?? "wbx-composer") + (dropping ? " is-dropping" : "");
823
888
  (0, import_react5.useEffect)(() => {
824
889
  if (!autoGrow) return;
825
890
  const el = taRef.current;
@@ -831,7 +896,39 @@ function Composer(props) {
831
896
  el.style.height = Math.min(el.scrollHeight, max) + "px";
832
897
  el.style.overflowY = el.scrollHeight > max ? "auto" : "hidden";
833
898
  }, [value, autoGrow, maxRows, taRef]);
834
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: classNames.root ?? "wbx-composer", children: [
899
+ const sendEl = renderSend ? renderSend() : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "uic-send", disabled: sendDisabled, onClick: () => onSend(), "aria-label": "Send message", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(IcSend, {}) });
900
+ if (inline) {
901
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { ref: rootRef, className: rootClass, children: [
902
+ attachments,
903
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "uic-composer-line", children: [
904
+ accessoriesLeft,
905
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
906
+ "textarea",
907
+ {
908
+ ref: taRef,
909
+ className: classNames.input ?? "wbx-composer-input",
910
+ rows,
911
+ value,
912
+ placeholder,
913
+ "aria-label": inputAriaLabel || placeholder,
914
+ disabled,
915
+ autoFocus,
916
+ onChange: (e) => onChange(e.target.value),
917
+ onKeyDown: (e) => {
918
+ if (e.key === "Enter" && !e.shiftKey) {
919
+ e.preventDefault();
920
+ onSend();
921
+ }
922
+ }
923
+ }
924
+ ),
925
+ accessoriesRight,
926
+ sendEl
927
+ ] }),
928
+ tray ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "uic-composer-tray", children: tray }) : null
929
+ ] });
930
+ }
931
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { ref: rootRef, className: rootClass, children: [
835
932
  attachments,
836
933
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
837
934
  "textarea",
@@ -857,7 +954,8 @@ function Composer(props) {
857
954
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { flex: 1 } }),
858
955
  accessoriesRight,
859
956
  renderSend ? renderSend() : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "uic-send", disabled: sendDisabled, onClick: () => onSend(), "aria-label": "Send message", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(IcSend, {}) })
860
- ] })
957
+ ] }),
958
+ tray ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "uic-composer-tray", children: tray }) : null
861
959
  ] });
862
960
  }
863
961
 
@@ -867,32 +965,54 @@ var import_react7 = __toESM(require("react"), 1);
867
965
  // src/components/Chip.jsx
868
966
  var import_react6 = __toESM(require("react"), 1);
869
967
  var import_jsx_runtime5 = require("react/jsx-runtime");
870
- function Chip(props) {
871
- const { label, icon, title, selected = false, onClick, onRemove, removeLabel, className } = props;
968
+ var Chip = (0, import_react6.forwardRef)(function Chip2(props, ref) {
969
+ const {
970
+ label,
971
+ icon,
972
+ title,
973
+ selected = false,
974
+ onClick,
975
+ onRemove,
976
+ removeLabel,
977
+ trailing,
978
+ className,
979
+ slot,
980
+ ...rest
981
+ } = props;
982
+ const isSlot = slot ?? (Boolean(onClick) && !selected);
872
983
  const cls = [
873
984
  "uic-chip",
874
985
  selected ? "is-selected" : "",
875
- onClick && !selected ? "is-open" : "",
986
+ isSlot ? "is-open" : "",
876
987
  className || ""
877
988
  ].filter(Boolean).join(" ");
878
989
  const body = /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
879
990
  icon ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "uic-chip-ic", "aria-hidden": "true", children: icon }) : null,
880
991
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "uic-chip-l", children: label })
881
992
  ] });
993
+ const trail = trailing ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "uic-chip-tr", children: trailing }) : null;
882
994
  if (onClick && onRemove) {
883
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: cls, title, children: [
884
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", className: "uic-chip-press", onClick, children: body }),
995
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { ref, className: cls, title, children: [
996
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", className: "uic-chip-press", onClick, ...rest, children: body }),
997
+ trail,
885
998
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", className: "uic-chip-x", "aria-label": removeLabel, onClick: onRemove, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(IcX, { size: 12 }) })
886
999
  ] });
887
1000
  }
888
1001
  if (onClick) {
889
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", className: cls, title, onClick, children: body });
1002
+ if (trailing) {
1003
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { ref, className: cls, title, children: [
1004
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", className: "uic-chip-press", onClick, ...rest, children: body }),
1005
+ trail
1006
+ ] });
1007
+ }
1008
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { ref, type: "button", className: cls, title, onClick, ...rest, children: body });
890
1009
  }
891
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: cls, title, children: [
1010
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { ref, className: cls, title, ...rest, children: [
892
1011
  body,
1012
+ trail,
893
1013
  onRemove ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", className: "uic-chip-x", "aria-label": removeLabel, onClick: onRemove, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(IcX, { size: 12 }) }) : null
894
1014
  ] });
895
- }
1015
+ });
896
1016
 
897
1017
  // src/format.js
898
1018
  function bytesLabel(n) {
@@ -1426,15 +1546,21 @@ function useResizablePane(opts = {}) {
1426
1546
  maxFraction = null,
1427
1547
  // viewport-width fraction cap, e.g. 0.6 for 60vw (null = none)
1428
1548
  fromRight = false,
1429
- // divider sits on the pane's LEFT edge (dragging right shrinks)
1430
- storageKey = null
1431
- // persist the chosen width per user (localStorage)
1549
+ // divider sits on the pane's LEFT/TOP edge (dragging toward it shrinks)
1550
+ storageKey = null,
1551
+ // persist the chosen size per user (localStorage)
1552
+ axis = "x"
1553
+ // 'x' = width (col-resize), 'y' = height (row-resize)
1432
1554
  } = opts;
1555
+ const vertical = axis === "y";
1556
+ const coord = (e) => vertical ? e.clientY : e.clientX;
1557
+ const viewportExtent = () => typeof window === "undefined" ? 0 : vertical ? window.innerHeight : window.innerWidth;
1558
+ const cursor = vertical ? "row-resize" : "col-resize";
1433
1559
  const clamp2 = (0, import_react9.useCallback)((x) => {
1434
1560
  let hi = max ?? Infinity;
1435
- if (maxFraction && typeof window !== "undefined") hi = Math.min(hi, Math.round(window.innerWidth * maxFraction));
1561
+ if (maxFraction && typeof window !== "undefined") hi = Math.min(hi, Math.round(viewportExtent() * maxFraction));
1436
1562
  return Math.min(hi, Math.max(min, x));
1437
- }, [min, max, maxFraction]);
1563
+ }, [min, max, maxFraction, vertical]);
1438
1564
  const [width, setWidth] = (0, import_react9.useState)(() => {
1439
1565
  if (storageKey && typeof window !== "undefined") {
1440
1566
  try {
@@ -1456,9 +1582,9 @@ function useResizablePane(opts = {}) {
1456
1582
  }, [storageKey]);
1457
1583
  const onMouseDown = (0, import_react9.useCallback)((e) => {
1458
1584
  e.preventDefault();
1459
- const sx = e.clientX, base = widthRef.current, dir = fromRight ? -1 : 1;
1585
+ const sx = coord(e), base = widthRef.current, dir = fromRight ? -1 : 1;
1460
1586
  document.body.classList.add("uic-resizing");
1461
- const move = (ev) => setWidth(clamp2(base + dir * (ev.clientX - sx)));
1587
+ const move = (ev) => setWidth(clamp2(base + dir * (coord(ev) - sx)));
1462
1588
  const up = () => {
1463
1589
  window.removeEventListener("mousemove", move);
1464
1590
  window.removeEventListener("mouseup", up);
@@ -1468,8 +1594,35 @@ function useResizablePane(opts = {}) {
1468
1594
  };
1469
1595
  window.addEventListener("mousemove", move);
1470
1596
  window.addEventListener("mouseup", up);
1471
- document.body.style.cursor = "col-resize";
1472
- }, [clamp2, fromRight, persist]);
1597
+ document.body.style.cursor = cursor;
1598
+ }, [clamp2, fromRight, persist, vertical]);
1599
+ const onPointerDown = (0, import_react9.useCallback)((e) => {
1600
+ if (e.pointerType === "mouse") return;
1601
+ e.preventDefault();
1602
+ const sx = coord(e), base = widthRef.current, dir = fromRight ? -1 : 1;
1603
+ const el = e.currentTarget;
1604
+ document.body.classList.add("uic-resizing");
1605
+ try {
1606
+ el.setPointerCapture(e.pointerId);
1607
+ } catch {
1608
+ }
1609
+ const move = (ev) => setWidth(clamp2(base + dir * (coord(ev) - sx)));
1610
+ const up = () => {
1611
+ el.removeEventListener("pointermove", move);
1612
+ el.removeEventListener("pointerup", up);
1613
+ el.removeEventListener("pointercancel", up);
1614
+ document.body.classList.remove("uic-resizing");
1615
+ persist(widthRef.current);
1616
+ };
1617
+ el.addEventListener("pointermove", move);
1618
+ el.addEventListener("pointerup", up);
1619
+ el.addEventListener("pointercancel", up);
1620
+ }, [clamp2, fromRight, persist, vertical]);
1621
+ const nudge = (0, import_react9.useCallback)((delta) => {
1622
+ const w = clamp2(widthRef.current + delta);
1623
+ setWidth(w);
1624
+ persist(w);
1625
+ }, [clamp2, persist]);
1473
1626
  const reset = (0, import_react9.useCallback)(() => {
1474
1627
  setWidth(initial);
1475
1628
  if (storageKey) {
@@ -1479,18 +1632,41 @@ function useResizablePane(opts = {}) {
1479
1632
  }
1480
1633
  }
1481
1634
  }, [initial, storageKey]);
1482
- return { width, onMouseDown, reset };
1635
+ let maxResolved = max ?? null;
1636
+ if (maxFraction && typeof window !== "undefined") {
1637
+ const frac = Math.round(viewportExtent() * maxFraction);
1638
+ maxResolved = maxResolved == null ? frac : Math.min(maxResolved, frac);
1639
+ }
1640
+ return { width, onMouseDown, onPointerDown, nudge, reset, min, max: maxResolved, fromRight, axis };
1483
1641
  }
1484
1642
  function PaneResizer(props) {
1485
1643
  const { pane, className, title = "Drag to resize (double-click to reset)" } = props;
1644
+ const vertical = pane.axis === "y";
1645
+ const onKeyDown = (e) => {
1646
+ const keys = vertical ? ["ArrowUp", "ArrowDown"] : ["ArrowLeft", "ArrowRight"];
1647
+ if (!keys.includes(e.key)) return;
1648
+ if (!pane.nudge) return;
1649
+ e.preventDefault();
1650
+ const step = e.shiftKey ? 96 : 24;
1651
+ const forward = e.key === "ArrowRight" || e.key === "ArrowDown";
1652
+ const dir = (forward ? 1 : -1) * (pane.fromRight ? -1 : 1);
1653
+ pane.nudge(dir * step);
1654
+ };
1486
1655
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1487
1656
  "div",
1488
1657
  {
1489
- className: className ?? "uic-vresize",
1658
+ className: className ?? (vertical ? "uic-hresize" : "uic-vresize"),
1490
1659
  role: "separator",
1491
- "aria-orientation": "vertical",
1660
+ "aria-orientation": vertical ? "horizontal" : "vertical",
1661
+ "aria-label": title,
1662
+ "aria-valuenow": Math.round(pane.width),
1663
+ "aria-valuemin": pane.min != null ? Math.round(pane.min) : void 0,
1664
+ "aria-valuemax": pane.max != null ? Math.round(pane.max) : void 0,
1665
+ tabIndex: 0,
1492
1666
  title,
1493
1667
  onMouseDown: pane.onMouseDown,
1668
+ onPointerDown: pane.onPointerDown,
1669
+ onKeyDown,
1494
1670
  onDoubleClick: pane.reset
1495
1671
  }
1496
1672
  );
@@ -1934,15 +2110,16 @@ function CreateBody({ spec, onClose, t, titleId }) {
1934
2110
 
1935
2111
  // src/auth/client.js
1936
2112
  var _cfg = {
1937
- engine: "",
1938
- // REQUIRED: your auth backend base URL, set via configureAuth
2113
+ // Same-origin. A product that forgets to configure gets the working default rather than the
2114
+ // engine's Azure FQDN, which no browser may call — its ingress admits only the VM that fronts
2115
+ // these apps, so a direct call 403s and reads as "Failed to fetch".
2116
+ engine: "/engine",
1939
2117
  product: "",
1940
2118
  loginHash: "#/login"
1941
2119
  };
1942
2120
  function configureAuth(cfg) {
1943
2121
  Object.assign(_cfg, cfg);
1944
2122
  if (!_cfg.product) throw new Error("configureAuth: product is required");
1945
- if (!_cfg.engine) throw new Error("configureAuth: engine (auth backend base URL) is required");
1946
2123
  }
1947
2124
  function authConfig() {
1948
2125
  return { ..._cfg };
@@ -2307,233 +2484,998 @@ function AuthForm({ onDone, subtitle: subtitle2, brand = null, productName = ""
2307
2484
  }
2308
2485
 
2309
2486
  // src/sheet/SheetGrid.jsx
2310
- var import_react15 = require("react");
2487
+ var import_react17 = require("react");
2488
+
2489
+ // src/mention/MentionInput.jsx
2490
+ var import_react16 = __toESM(require("react"), 1);
2491
+
2492
+ // src/components/Popover.jsx
2493
+ var import_react15 = __toESM(require("react"), 1);
2311
2494
  var import_react_dom2 = require("react-dom");
2312
2495
  var import_jsx_runtime13 = require("react/jsx-runtime");
2313
- var cellKey = (rowId, colId) => `${rowId}:${colId}`;
2314
- var uid = (p) => `${p}_${Math.random().toString(36).slice(2, 10)}`;
2315
- var DEFAULT_COLUMN_TYPES = [
2316
- { type: "text", label: "Text" },
2317
- { type: "number", label: "Number" },
2318
- { type: "select", label: "Select" },
2319
- { type: "tags", label: "Tags" },
2320
- { type: "checkbox", label: "Checkbox" },
2321
- { type: "date", label: "Date" },
2322
- { type: "url", label: "Link" },
2323
- { type: "resource", label: "Resource" },
2324
- {
2325
- type: "compute",
2326
- label: "Computed",
2327
- computed: true,
2328
- configKey: "compute",
2329
- badge: (col) => col.compute?.kind
2330
- }
2331
- ];
2332
- var COMPUTE_KINDS = [
2333
- { kind: "prompt", label: "AI prompt" },
2334
- { kind: "harness", label: "Agent (harness)" },
2335
- { kind: "workflow", label: "Workflow" },
2336
- { kind: "image", label: "Generate image" }
2337
- ];
2338
- var RESOURCE_KINDS = ["image", "sheet", "slides", "workflow", "graph"];
2339
- var RESOURCE_ICON = { image: "\u{1F5BC}", sheet: "\u25A6", slides: "\u25A4", workflow: "\u2699", graph: "\u25C9" };
2340
- function PopPortal({ anchor, width = 250, estHeight = 300, className, children, onClose }) {
2341
- const boxRef = (0, import_react15.useRef)(null);
2496
+ var GAP = 6;
2497
+ var MARGIN = 8;
2498
+ function Popover(props) {
2499
+ const {
2500
+ open,
2501
+ anchorRef,
2502
+ onClose,
2503
+ width = 280,
2504
+ minHeight = 140,
2505
+ placement = "auto",
2506
+ children,
2507
+ className,
2508
+ label
2509
+ } = props;
2510
+ const popRef = (0, import_react15.useRef)(null);
2511
+ const [pos, setPos] = (0, import_react15.useState)(null);
2342
2512
  (0, import_react15.useEffect)(() => {
2343
- if (!onClose) return void 0;
2344
- const close = () => onClose();
2345
- const onDown = (e) => {
2346
- if (boxRef.current && boxRef.current.contains(e.target)) return;
2347
- if (anchor && e.clientX >= anchor.left && e.clientX <= anchor.right && e.clientY >= anchor.top && e.clientY <= anchor.bottom) return;
2348
- onClose();
2513
+ if (!open) {
2514
+ setPos(null);
2515
+ return void 0;
2516
+ }
2517
+ const place = () => {
2518
+ const el = anchorRef?.current;
2519
+ if (!el) return;
2520
+ const r = el.getBoundingClientRect();
2521
+ const vw = window.innerWidth;
2522
+ const vh = window.innerHeight;
2523
+ const w = Math.min(width, vw - MARGIN * 2);
2524
+ const below = vh - r.bottom - GAP - MARGIN;
2525
+ const above = r.top - GAP - MARGIN;
2526
+ const up = placement === "above" || placement === "auto" && below < minHeight && above > below;
2527
+ const maxHeight = Math.max(minHeight, Math.floor(up ? above : below));
2528
+ const left = Math.max(MARGIN, Math.min(r.left, vw - w - MARGIN));
2529
+ setPos(up ? { left, bottom: Math.round(vh - r.top + GAP), width: w, maxHeight } : { left, top: Math.round(r.bottom + GAP), width: w, maxHeight });
2349
2530
  };
2350
- window.addEventListener("mousedown", onDown);
2351
- window.addEventListener("scroll", close, true);
2352
- window.addEventListener("resize", close);
2531
+ place();
2532
+ window.addEventListener("resize", place);
2533
+ window.addEventListener("scroll", place, true);
2353
2534
  return () => {
2354
- window.removeEventListener("mousedown", onDown);
2355
- window.removeEventListener("scroll", close, true);
2356
- window.removeEventListener("resize", close);
2535
+ window.removeEventListener("resize", place);
2536
+ window.removeEventListener("scroll", place, true);
2357
2537
  };
2358
- }, [onClose, anchor]);
2359
- if (!anchor) return null;
2360
- const left = Math.max(8, Math.min(anchor.right - width, window.innerWidth - width - 8));
2361
- let top = anchor.bottom + 6;
2362
- if (top + estHeight > window.innerHeight - 8) top = Math.max(8, anchor.top - estHeight - 6);
2538
+ }, [open, anchorRef, width, minHeight, placement]);
2539
+ (0, import_react15.useEffect)(() => {
2540
+ if (!open) return void 0;
2541
+ const onDown = (e) => {
2542
+ if (popRef.current?.contains(e.target)) return;
2543
+ if (anchorRef?.current?.contains(e.target)) return;
2544
+ onClose?.();
2545
+ };
2546
+ document.addEventListener("pointerdown", onDown);
2547
+ return () => document.removeEventListener("pointerdown", onDown);
2548
+ }, [open, anchorRef, onClose]);
2549
+ const escape = (0, import_react15.useCallback)(() => onClose?.(), [onClose]);
2550
+ useOverlayEscape(open, escape);
2551
+ if (!open || !pos || typeof document === "undefined") return null;
2363
2552
  return (0, import_react_dom2.createPortal)(
2364
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { ref: boxRef, className, style: { position: "fixed", top, left, width, zIndex: 1e3 }, children }),
2553
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
2554
+ "div",
2555
+ {
2556
+ ref: popRef,
2557
+ className: ["uic-pop", className || ""].filter(Boolean).join(" "),
2558
+ style: pos,
2559
+ role: "dialog",
2560
+ "aria-label": label,
2561
+ children
2562
+ }
2563
+ ),
2365
2564
  document.body
2366
2565
  );
2367
2566
  }
2368
- var PILL_FALLBACKS = ["#E0E7FF", "#FCE7F3", "#D1FAE5", "#FEF3C7", "#E0F2FE", "#F3E8FF", "#FFE4E6"];
2369
- function normOptions(options) {
2370
- return (options || []).map((o, i) => {
2371
- if (typeof o === "string") return { label: o, color: PILL_FALLBACKS[i % PILL_FALLBACKS.length] };
2372
- return { label: o.label ?? String(o.value ?? ""), color: o.color || PILL_FALLBACKS[i % PILL_FALLBACKS.length] };
2373
- });
2567
+
2568
+ // src/mention/mentionModel.js
2569
+ var CURLY = Object.freeze({ open: "{{", close: "}}" });
2570
+ var AT = Object.freeze({ open: "@", close: "" });
2571
+ var CHAT_LINK = Object.freeze({
2572
+ write: (item) => `[@${item.name}](#m-${item.id})`,
2573
+ pattern: /\[@(?<name>[^\]\n]+)\]\(#m-(?<id>[^)\s]+)\)/g
2574
+ });
2575
+ function makeResolver(items) {
2576
+ const byName = /* @__PURE__ */ new Map();
2577
+ const byId = /* @__PURE__ */ new Map();
2578
+ for (const it of items || []) {
2579
+ if (!it) continue;
2580
+ if (it.name) byName.set(it.name, it);
2581
+ if (it.id != null) byId.set(String(it.id), it);
2582
+ }
2583
+ const names = [...byName.keys()].sort((a, b) => b.length - a.length);
2584
+ return { get: (name) => byName.get(name) || null, byId: (id) => byId.get(String(id)) || null, names };
2374
2585
  }
2375
- function pillColor(label, options) {
2376
- const opts = normOptions(options);
2377
- const hit = opts.find((o) => o.label === label);
2378
- if (hit) return hit.color;
2379
- let h = 0;
2380
- for (const ch of String(label)) h = h * 31 + ch.charCodeAt(0) >>> 0;
2381
- return PILL_FALLBACKS[h % PILL_FALLBACKS.length];
2586
+ function parsePattern(text, format, resolver) {
2587
+ const out = [];
2588
+ const re = new RegExp(format.pattern.source, format.pattern.flags.includes("g") ? format.pattern.flags : format.pattern.flags + "g");
2589
+ let last = 0;
2590
+ let m;
2591
+ while (m = re.exec(text)) {
2592
+ if (m.index > last) out.push({ type: "text", text: text.slice(last, m.index) });
2593
+ const id = m.groups && m.groups.id != null ? m.groups.id : null;
2594
+ const name = m.groups && m.groups.name || "";
2595
+ const item = id != null && resolver && resolver.byId(id) || resolver && resolver.get(name) || { id: id ?? name, name, kind: null };
2596
+ out.push({ type: "mention", id: item.id, name: item.name || name, kind: item.kind || null, item });
2597
+ last = m.index + m[0].length;
2598
+ }
2599
+ if (last < text.length) out.push({ type: "text", text: text.slice(last) });
2600
+ return out;
2382
2601
  }
2383
- function RefImage({ refVal, fetchBlobUrl }) {
2384
- const [src, setSrc] = (0, import_react15.useState)(/^https?:\/\//i.test(refVal.url || "") ? refVal.url : null);
2385
- (0, import_react15.useEffect)(() => {
2386
- let dead = false;
2387
- let obj = null;
2388
- if (!src && refVal.url && fetchBlobUrl) {
2389
- fetchBlobUrl(refVal.url).then((u) => {
2390
- if (!dead) {
2391
- obj = u;
2392
- setSrc(u);
2602
+ function parseValue(value, format, resolver) {
2603
+ const text = value == null ? "" : String(value);
2604
+ if (format && format.pattern) return parsePattern(text, format, resolver);
2605
+ const { open, close } = format || CURLY;
2606
+ const out = [];
2607
+ let buf = "";
2608
+ let i = 0;
2609
+ const flush = () => {
2610
+ if (buf) {
2611
+ out.push({ type: "text", text: buf });
2612
+ buf = "";
2613
+ }
2614
+ };
2615
+ while (i < text.length) {
2616
+ if (resolver && text.startsWith(open, i)) {
2617
+ const boundary = close ? true : i === 0 || /[\s([{"'>]/.test(text[i - 1]);
2618
+ let hit = null;
2619
+ if (boundary) {
2620
+ for (const name of resolver.names) {
2621
+ const start = i + open.length;
2622
+ if (text.startsWith(name, start)) {
2623
+ const end = start + name.length;
2624
+ if (!close || text.startsWith(close, end)) {
2625
+ if (close || end === text.length || /[\s.,;:!?)\]}"']/.test(text[end])) {
2626
+ hit = { name, end: end + close.length };
2627
+ break;
2628
+ }
2629
+ }
2630
+ }
2393
2631
  }
2394
- });
2632
+ }
2633
+ if (hit) {
2634
+ flush();
2635
+ const item = resolver.get(hit.name);
2636
+ out.push({ type: "mention", id: item.id, name: item.name, kind: item.kind || null, item });
2637
+ i = hit.end;
2638
+ continue;
2639
+ }
2395
2640
  }
2396
- return () => {
2397
- dead = true;
2398
- if (obj) URL.revokeObjectURL(obj);
2399
- };
2400
- }, [refVal.url]);
2401
- if (!src) return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "shg-refchip", children: [
2402
- RESOURCE_ICON.image,
2403
- " ",
2404
- refVal.name || "image"
2405
- ] });
2406
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("img", { className: "shg-refimg", src, alt: refVal.name || "", title: refVal.name || "" });
2641
+ buf += text[i];
2642
+ i += 1;
2643
+ }
2644
+ flush();
2645
+ return out;
2407
2646
  }
2408
- function ResourceChip({ refVal, onOpen }) {
2409
- const icon = RESOURCE_ICON[refVal.kind] || "\u25C7";
2410
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
2411
- "button",
2412
- {
2413
- className: "shg-refchip shg-refchip-btn",
2414
- title: `Open ${refVal.kind}`,
2415
- onClick: (e) => {
2416
- e.stopPropagation();
2417
- onOpen && onOpen(refVal);
2418
- },
2419
- children: [
2420
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "shg-refchip-ic", children: icon }),
2421
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "shg-refchip-name", children: refVal.name || refVal.id || refVal.kind })
2422
- ]
2423
- }
2424
- );
2647
+ function serializeSegments(segments, format) {
2648
+ const f = format || CURLY;
2649
+ if (f.write) return (segments || []).map((s) => s.type === "mention" ? f.write(s.item || s) : s.text).join("");
2650
+ const { open, close } = f;
2651
+ return (segments || []).map((s) => s.type === "mention" ? `${open}${s.name}${close}` : s.text).join("");
2425
2652
  }
2426
- function StatusDot({ status }) {
2427
- if (!status || status === "empty") return null;
2428
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: `shg-dot shg-dot-${status}`, title: status });
2653
+ function mentionsOf(segments) {
2654
+ const seen = /* @__PURE__ */ new Set();
2655
+ const out = [];
2656
+ for (const s of segments || []) {
2657
+ if (s.type !== "mention" || seen.has(s.id)) continue;
2658
+ seen.add(s.id);
2659
+ out.push({ id: s.id, name: s.name, kind: s.kind || null });
2660
+ }
2661
+ return out;
2429
2662
  }
2430
- function CellValue({ cell, col, fetchBlobUrl, onOpenResource }) {
2431
- const v = cell?.value;
2432
- if (v === void 0 || v === null || v === "") return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "shg-val-txt" });
2433
- if (v && typeof v === "object" && !Array.isArray(v) && v.kind) {
2434
- if (v.kind === "image") return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(RefImage, { refVal: v, fetchBlobUrl });
2435
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ResourceChip, { refVal: v, onOpen: onOpenResource });
2663
+ function norm(s) {
2664
+ return String(s || "").toLowerCase();
2665
+ }
2666
+ function subsequence(hay, needle) {
2667
+ let j = 0;
2668
+ for (let i = 0; i < hay.length && j < needle.length; i++) if (hay[i] === needle[j]) j++;
2669
+ return j === needle.length;
2670
+ }
2671
+ function scoreItem(item, query) {
2672
+ const q = norm(query).trim();
2673
+ if (!q) return 1;
2674
+ const name = norm(item.name);
2675
+ if (name === q) return 120;
2676
+ if (name.startsWith(q)) return 100;
2677
+ if (name.split(/[\s_-]+/).some((w) => w.startsWith(q))) return 80;
2678
+ if (name.includes(q)) return 60;
2679
+ const initials = name.split(/[\s_-]+/).map((w) => w[0]).join("");
2680
+ if (initials.startsWith(q)) return 50;
2681
+ if (subsequence(name, q)) return 30;
2682
+ const desc = norm(item.description);
2683
+ if (desc && desc.includes(q)) return 20;
2684
+ const kws = (item.keywords || []).map(norm);
2685
+ if (kws.some((k) => k.includes(q))) return 15;
2686
+ return 0;
2687
+ }
2688
+ function searchItems(items, query) {
2689
+ const scored = (items || []).map((it, i) => ({ it, i, s: scoreItem(it, query) })).filter((x) => x.s > 0);
2690
+ scored.sort((a, b) => b.s - a.s || a.i - b.i);
2691
+ return scored.map((x) => x.it);
2692
+ }
2693
+ function groupItems(items, query) {
2694
+ const groups = /* @__PURE__ */ new Map();
2695
+ for (const it of searchItems(items, query)) {
2696
+ const key = it.section || "";
2697
+ if (!groups.has(key)) groups.set(key, []);
2698
+ groups.get(key).push(it);
2436
2699
  }
2437
- switch (col.type) {
2438
- case "select":
2439
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "shg-pill", style: { background: pillColor(String(v), col.options) }, children: String(v) });
2440
- case "tags": {
2441
- const tags = Array.isArray(v) ? v : String(v).split(",").map((s) => s.trim()).filter(Boolean);
2442
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "shg-pills", children: tags.map((t) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "shg-pill", style: { background: pillColor(t, col.options) }, children: t }, t)) });
2443
- }
2444
- case "checkbox":
2445
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "shg-check" + (v ? " on" : ""), children: v ? "\u2713" : "" });
2446
- case "url": {
2447
- const href = /^https?:\/\//i.test(String(v)) ? String(v) : `https://${v}`;
2448
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("a", { className: "shg-link", href, target: "_blank", rel: "noreferrer", onClick: (e) => e.stopPropagation(), children: String(v) });
2449
- }
2450
- case "number":
2451
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "shg-val-txt shg-num", children: String(v) });
2452
- default:
2453
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "shg-val-txt", children: typeof v === "object" ? JSON.stringify(v) : String(v) });
2700
+ const order = [""];
2701
+ for (const it of items || []) {
2702
+ const k = it.section || "";
2703
+ if (!order.includes(k)) order.push(k);
2454
2704
  }
2705
+ return order.filter((k) => groups.has(k)).map((k) => ({ section: k, items: groups.get(k) }));
2455
2706
  }
2456
- function SheetGrid({
2457
- sheet,
2458
- onChange,
2459
- onRunCell,
2460
- onRunColumn,
2461
- readOnly = false,
2462
- fetchBlobUrl,
2463
- onOpenResource,
2464
- peerMarks,
2465
- onActiveCell,
2466
- columnTypes = DEFAULT_COLUMN_TYPES,
2467
- renderCell,
2468
- renderColumnConfig
2469
- }) {
2470
- const columns = sheet?.columns || [];
2471
- const rows = sheet?.rows || [];
2472
- const cells = sheet?.cells || {};
2473
- const [editing, setEditing] = (0, import_react15.useState)(null);
2474
- const [draft, setDraft] = (0, import_react15.useState)("");
2475
- const [menuCol, setMenuCol] = (0, import_react15.useState)(null);
2476
- const [sizeDraft, setSizeDraft] = (0, import_react15.useState)({});
2477
- const [dnd, setDnd] = (0, import_react15.useState)(null);
2478
- const [dropAt, setDropAt] = (0, import_react15.useState)(null);
2479
- const inputRef = (0, import_react15.useRef)(null);
2480
- const dragRef = (0, import_react15.useRef)(null);
2481
- const descOf = (type) => columnTypes.find((t) => t.type === type) || { type, label: type };
2482
- const isComputed = (col) => !!descOf(col?.type).computed;
2483
- const isEditable = (col) => {
2484
- const d = descOf(col?.type);
2485
- return d.editable ?? !d.computed;
2707
+ function activeTrigger(textBeforeCaret, trigger = "@", maxLen = 48) {
2708
+ const at = textBeforeCaret.lastIndexOf(trigger);
2709
+ if (at < 0) return null;
2710
+ if (at > 0 && !/[\s([{"'>]/.test(textBeforeCaret[at - 1])) return null;
2711
+ const query = textBeforeCaret.slice(at + trigger.length);
2712
+ if (query.length > maxLen || /\n/.test(query)) return null;
2713
+ return { start: at, query };
2714
+ }
2715
+
2716
+ // src/mention/MentionInput.jsx
2717
+ var import_jsx_runtime14 = require("react/jsx-runtime");
2718
+ var MENTION_ATTR = "data-mention-id";
2719
+ function monogram(name) {
2720
+ const parts = String(name || "").trim().split(/\s+/).filter(Boolean);
2721
+ return ((parts[0] || "")[0] || "") + ((parts[1] || "")[0] || "") || "?";
2722
+ }
2723
+ function buildPillNode(item) {
2724
+ const el = document.createElement("span");
2725
+ el.className = "uic-mention";
2726
+ el.setAttribute(MENTION_ATTR, item.id);
2727
+ el.setAttribute("data-name", item.name);
2728
+ if (item.kind) el.setAttribute("data-kind", item.kind);
2729
+ el.setAttribute("contenteditable", "false");
2730
+ if (item.description) el.title = item.description;
2731
+ if (item.color) el.style.setProperty("--uic-mention-color", item.color);
2732
+ const ic = document.createElement("span");
2733
+ ic.className = "uic-mention-ic";
2734
+ if (item.avatar) {
2735
+ const img = document.createElement("img");
2736
+ img.src = item.avatar;
2737
+ img.alt = "";
2738
+ ic.appendChild(img);
2739
+ } else {
2740
+ ic.textContent = typeof item.icon === "string" && item.icon ? item.icon : monogram(item.name);
2741
+ if (!(typeof item.icon === "string" && item.icon)) ic.classList.add("is-mono");
2742
+ }
2743
+ const nm = document.createElement("span");
2744
+ nm.className = "uic-mention-name";
2745
+ nm.textContent = item.name;
2746
+ el.appendChild(ic);
2747
+ el.appendChild(nm);
2748
+ return el;
2749
+ }
2750
+ function readSegments(root, resolver) {
2751
+ const out = [];
2752
+ let buf = "";
2753
+ const flush = () => {
2754
+ if (buf) {
2755
+ out.push({ type: "text", text: buf });
2756
+ buf = "";
2757
+ }
2486
2758
  };
2487
- const startResize = (e, kind, id, start) => {
2488
- if (readOnly) return;
2489
- e.preventDefault();
2490
- e.stopPropagation();
2491
- const origin = kind === "col" ? e.clientX : e.clientY;
2492
- dragRef.current = { kind, id, start, origin, last: start };
2493
- const onMove = (ev) => {
2494
- const d = dragRef.current;
2495
- if (!d) return;
2496
- const delta = (d.kind === "col" ? ev.clientX : ev.clientY) - d.origin;
2497
- const next = Math.max(d.kind === "col" ? 90 : 26, d.start + delta);
2498
- d.last = next;
2499
- setSizeDraft((sd) => ({ ...sd, [d.kind]: { ...sd[d.kind] || {}, [d.id]: next } }));
2500
- };
2501
- const onUp = () => {
2502
- const d = dragRef.current;
2503
- dragRef.current = null;
2504
- window.removeEventListener("mousemove", onMove);
2505
- window.removeEventListener("mouseup", onUp);
2506
- document.body.style.cursor = "";
2507
- if (!d) return;
2508
- setSizeDraft({});
2509
- mutate((n) => {
2510
- if (d.kind === "col") {
2511
- const c = n.columns.find((x) => x.id === d.id);
2512
- if (c) c.width = Math.round(d.last);
2513
- } else {
2514
- const r = n.rows.find((x) => x.id === d.id);
2515
- if (r) r.height = Math.round(d.last);
2516
- }
2517
- });
2518
- };
2519
- window.addEventListener("mousemove", onMove);
2520
- window.addEventListener("mouseup", onUp);
2521
- document.body.style.cursor = kind === "col" ? "col-resize" : "row-resize";
2759
+ const walk = (node, isLastAtRoot) => {
2760
+ const kids = Array.from(node.childNodes);
2761
+ kids.forEach((k, i) => {
2762
+ const last = isLastAtRoot && i === kids.length - 1;
2763
+ if (k.nodeType === 3) {
2764
+ buf += k.data.replace(/\u00a0/g, " ");
2765
+ return;
2766
+ }
2767
+ if (k.nodeType !== 1) return;
2768
+ const tag = k.tagName;
2769
+ if (tag === "BR") {
2770
+ if (!last) buf += "\n";
2771
+ return;
2772
+ }
2773
+ if (k.hasAttribute(MENTION_ATTR)) {
2774
+ flush();
2775
+ const id = k.getAttribute(MENTION_ATTR);
2776
+ const name = k.getAttribute("data-name") || "";
2777
+ const item = resolver.get(name) || { id, name, kind: k.getAttribute("data-kind") || null };
2778
+ out.push({ type: "mention", id: item.id, name: item.name, kind: item.kind || null, item });
2779
+ return;
2780
+ }
2781
+ if (tag === "DIV" || tag === "P") {
2782
+ if (out.length || buf) buf += "\n";
2783
+ walk(k, last);
2784
+ return;
2785
+ }
2786
+ walk(k, last);
2787
+ });
2522
2788
  };
2523
- const colWidth = (col) => sizeDraft.col && sizeDraft.col[col.id] || col.width || void 0;
2524
- const reorder = (kind, fromId, toId, after) => mutate((n) => {
2525
- const arr = kind === "col" ? n.columns : n.rows;
2526
- const i = arr.findIndex((x) => x.id === fromId);
2527
- if (i < 0 || fromId === toId) return;
2528
- const [item] = arr.splice(i, 1);
2529
- let j = arr.findIndex((x) => x.id === toId);
2530
- if (j < 0) {
2531
- arr.splice(i, 0, item);
2789
+ walk(root, true);
2790
+ flush();
2791
+ return out;
2792
+ }
2793
+ function writeSegments(root, segments) {
2794
+ root.textContent = "";
2795
+ for (const s of segments) {
2796
+ if (s.type === "mention") {
2797
+ root.appendChild(buildPillNode(s.item || s));
2798
+ continue;
2799
+ }
2800
+ const lines = String(s.text).split("\n");
2801
+ lines.forEach((line, i) => {
2802
+ if (i > 0) root.appendChild(document.createElement("br"));
2803
+ if (line) root.appendChild(document.createTextNode(line));
2804
+ });
2805
+ }
2806
+ root.appendChild(document.createElement("br"));
2807
+ }
2808
+ function placeCaretAfter(node) {
2809
+ const sel = window.getSelection();
2810
+ if (!sel) return;
2811
+ const r = document.createRange();
2812
+ r.setStartAfter(node);
2813
+ r.collapse(true);
2814
+ sel.removeAllRanges();
2815
+ sel.addRange(r);
2816
+ }
2817
+ function selectionIn(root) {
2818
+ const sel = typeof window !== "undefined" ? window.getSelection() : null;
2819
+ if (!sel || !sel.rangeCount) return null;
2820
+ const r = sel.getRangeAt(0);
2821
+ if (!root.contains(r.startContainer)) return null;
2822
+ return { sel, range: r };
2823
+ }
2824
+ var MentionInput = (0, import_react16.forwardRef)(function MentionInput2(props, ref) {
2825
+ const {
2826
+ value = "",
2827
+ onChange,
2828
+ items = [],
2829
+ format = CURLY,
2830
+ trigger = "@",
2831
+ placeholder,
2832
+ disabled = false,
2833
+ onSubmit,
2834
+ submitOnEnter = false,
2835
+ autoFocus = false,
2836
+ className = "",
2837
+ label,
2838
+ menuWidth = 360,
2839
+ menuTitle,
2840
+ emptyText = "No match",
2841
+ renderIcon,
2842
+ onOpenChange,
2843
+ onFocus,
2844
+ onBlur,
2845
+ onKeyDown,
2846
+ id
2847
+ } = props;
2848
+ const editorRef = (0, import_react16.useRef)(null);
2849
+ const resolver = (0, import_react16.useMemo)(() => makeResolver(items), [items]);
2850
+ const [menu, setMenu] = (0, import_react16.useState)(null);
2851
+ const [active, setActive] = (0, import_react16.useState)(0);
2852
+ const [empty, setEmpty] = (0, import_react16.useState)(!value);
2853
+ const listId = (0, import_react16.useMemo)(() => `uic-mention-${Math.random().toString(36).slice(2, 8)}`, []);
2854
+ const emit = (0, import_react16.useCallback)(() => {
2855
+ const root = editorRef.current;
2856
+ if (!root) return;
2857
+ const segs = readSegments(root, resolver);
2858
+ const next = serializeSegments(segs, format);
2859
+ setEmpty(!next);
2860
+ if (onChange) onChange(next, mentionsOf(segs));
2861
+ }, [resolver, format, onChange]);
2862
+ (0, import_react16.useLayoutEffect)(() => {
2863
+ const root = editorRef.current;
2864
+ if (!root) return;
2865
+ const current = serializeSegments(readSegments(root, resolver), format);
2866
+ if (current === (value || "")) return;
2867
+ writeSegments(root, parseValue(value || "", format, resolver));
2868
+ setEmpty(!value);
2869
+ }, [value, resolver, format]);
2870
+ (0, import_react16.useEffect)(() => {
2871
+ if (autoFocus && editorRef.current) editorRef.current.focus();
2872
+ }, [autoFocus]);
2873
+ const closeMenu = (0, import_react16.useCallback)(() => setMenu(null), []);
2874
+ (0, import_react16.useEffect)(() => {
2875
+ if (onOpenChange) onOpenChange(!!menu);
2876
+ }, [menu, onOpenChange]);
2877
+ const groups = (0, import_react16.useMemo)(() => menu ? groupItems(items, menu.query) : [], [items, menu]);
2878
+ const flat = (0, import_react16.useMemo)(() => groups.flatMap((g) => g.items), [groups]);
2879
+ (0, import_react16.useEffect)(() => {
2880
+ setActive(0);
2881
+ }, [menu && menu.query, groups.length]);
2882
+ const syncMenu = (0, import_react16.useCallback)(() => {
2883
+ const root = editorRef.current;
2884
+ const s = root && selectionIn(root);
2885
+ if (!s || !s.range.collapsed) {
2886
+ setMenu(null);
2532
2887
  return;
2533
2888
  }
2534
- if (after) j += 1;
2535
- arr.splice(j, 0, item);
2889
+ const node = s.range.startContainer;
2890
+ if (node.nodeType !== 3) {
2891
+ setMenu(null);
2892
+ return;
2893
+ }
2894
+ const hit = activeTrigger(node.data.slice(0, s.range.startOffset), trigger);
2895
+ if (!hit) {
2896
+ setMenu(null);
2897
+ return;
2898
+ }
2899
+ const r = document.createRange();
2900
+ r.setStart(node, hit.start);
2901
+ r.setEnd(node, Math.min(node.data.length, hit.start + 1));
2902
+ const rect = r.getBoundingClientRect();
2903
+ setMenu({ node, start: hit.start, query: hit.query, rect: rect.width || rect.height ? rect : root.getBoundingClientRect() });
2904
+ }, [trigger]);
2905
+ const anchorRef = (0, import_react16.useMemo)(() => ({
2906
+ current: {
2907
+ getBoundingClientRect: () => menu ? menu.rect : new DOMRect(),
2908
+ contains: () => false
2909
+ }
2910
+ }), [menu]);
2911
+ const insertPill = (0, import_react16.useCallback)((item, replace) => {
2912
+ const root = editorRef.current;
2913
+ if (!root || !item || item.disabled) return;
2914
+ const pill = buildPillNode(item);
2915
+ const space = document.createTextNode("\xA0");
2916
+ if (replace && replace.node && replace.node.parentNode === root) {
2917
+ const { node, start, query } = replace;
2918
+ node.deleteData(start, trigger.length + query.length);
2919
+ const after = node.splitText(start);
2920
+ root.insertBefore(pill, after);
2921
+ root.insertBefore(space, after);
2922
+ } else {
2923
+ const s = selectionIn(root);
2924
+ if (s) {
2925
+ s.range.deleteContents();
2926
+ s.range.insertNode(space);
2927
+ s.range.insertNode(pill);
2928
+ } else {
2929
+ root.appendChild(pill);
2930
+ root.appendChild(space);
2931
+ }
2932
+ }
2933
+ placeCaretAfter(space);
2934
+ setMenu(null);
2935
+ emit();
2936
+ }, [emit, trigger]);
2937
+ const pick = (0, import_react16.useCallback)((item) => insertPill(item, menu), [insertPill, menu]);
2938
+ const insertText = (0, import_react16.useCallback)((text) => {
2939
+ const root = editorRef.current;
2940
+ if (!root) return;
2941
+ root.focus();
2942
+ let done = false;
2943
+ try {
2944
+ done = document.execCommand("insertText", false, text);
2945
+ } catch {
2946
+ done = false;
2947
+ }
2948
+ if (!done) {
2949
+ const s = selectionIn(root);
2950
+ const tn = document.createTextNode(text);
2951
+ if (s) {
2952
+ s.range.deleteContents();
2953
+ s.range.insertNode(tn);
2954
+ placeCaretAfter(tn);
2955
+ } else root.appendChild(tn);
2956
+ }
2957
+ emit();
2958
+ syncMenu();
2959
+ }, [emit, syncMenu]);
2960
+ const wrapSelection = (0, import_react16.useCallback)((before, after = "") => {
2961
+ const root = editorRef.current;
2962
+ if (!root) return;
2963
+ root.focus();
2964
+ const s = selectionIn(root);
2965
+ const selected = s ? s.range.toString() : "";
2966
+ insertText(before + selected + after);
2967
+ if (!selected && after) {
2968
+ const sel = window.getSelection();
2969
+ for (let i = 0; i < after.length; i++) sel && sel.modify && sel.modify("move", "backward", "character");
2970
+ }
2971
+ }, [insertText]);
2972
+ const prefixLine = (0, import_react16.useCallback)((prefix) => {
2973
+ const root = editorRef.current;
2974
+ if (!root) return;
2975
+ root.focus();
2976
+ const s = selectionIn(root);
2977
+ const node = s && s.range.startContainer;
2978
+ const before = node && node.nodeType === 3 ? node.data.slice(0, s.range.startOffset) : "";
2979
+ const atLineStart = !before || /\n$/.test(before) || node && node.nodeType !== 3;
2980
+ insertText((atLineStart ? "" : "\n") + prefix);
2981
+ }, [insertText]);
2982
+ (0, import_react16.useImperativeHandle)(ref, () => ({
2983
+ focus: () => editorRef.current && editorRef.current.focus(),
2984
+ clear: () => {
2985
+ const root = editorRef.current;
2986
+ if (root) {
2987
+ writeSegments(root, []);
2988
+ emit();
2989
+ }
2990
+ },
2991
+ insertMention: (item) => insertPill(item, null),
2992
+ insertText,
2993
+ wrapSelection,
2994
+ prefixLine,
2995
+ get el() {
2996
+ return editorRef.current;
2997
+ }
2998
+ }), [emit, insertPill, insertText, wrapSelection, prefixLine]);
2999
+ const handleInput = () => {
3000
+ emit();
3001
+ syncMenu();
3002
+ };
3003
+ const handleKeyDown = (e) => {
3004
+ if (onKeyDown) onKeyDown(e);
3005
+ if (e.defaultPrevented) return;
3006
+ if (menu) {
3007
+ if (e.key === "ArrowDown") {
3008
+ e.preventDefault();
3009
+ setActive((a) => flat.length ? (a + 1) % flat.length : 0);
3010
+ return;
3011
+ }
3012
+ if (e.key === "ArrowUp") {
3013
+ e.preventDefault();
3014
+ setActive((a) => flat.length ? (a - 1 + flat.length) % flat.length : 0);
3015
+ return;
3016
+ }
3017
+ if ((e.key === "Enter" || e.key === "Tab") && flat.length) {
3018
+ e.preventDefault();
3019
+ pick(flat[active]);
3020
+ return;
3021
+ }
3022
+ if (e.key === "Escape") {
3023
+ e.preventDefault();
3024
+ setMenu(null);
3025
+ return;
3026
+ }
3027
+ }
3028
+ if (e.key === "Enter") {
3029
+ if (submitOnEnter && !e.shiftKey) {
3030
+ e.preventDefault();
3031
+ if (onSubmit) onSubmit();
3032
+ return;
3033
+ }
3034
+ e.preventDefault();
3035
+ insertText("\n");
3036
+ }
3037
+ };
3038
+ const handlePaste = (e) => {
3039
+ e.preventDefault();
3040
+ const text = e.clipboardData && e.clipboardData.getData("text/plain") || "";
3041
+ if (!text) return;
3042
+ const segs = parseValue(text, format, resolver);
3043
+ if (segs.every((s2) => s2.type === "text")) {
3044
+ insertText(text);
3045
+ return;
3046
+ }
3047
+ const root = editorRef.current;
3048
+ const s = selectionIn(root);
3049
+ if (!s) {
3050
+ insertText(text);
3051
+ return;
3052
+ }
3053
+ s.range.deleteContents();
3054
+ const frag = document.createDocumentFragment();
3055
+ let lastNode = null;
3056
+ for (const seg of segs) {
3057
+ if (seg.type === "mention") {
3058
+ lastNode = buildPillNode(seg.item || seg);
3059
+ frag.appendChild(lastNode);
3060
+ continue;
3061
+ }
3062
+ seg.text.split("\n").forEach((line, i) => {
3063
+ if (i > 0) {
3064
+ lastNode = document.createElement("br");
3065
+ frag.appendChild(lastNode);
3066
+ }
3067
+ if (line) {
3068
+ lastNode = document.createTextNode(line);
3069
+ frag.appendChild(lastNode);
3070
+ }
3071
+ });
3072
+ }
3073
+ s.range.insertNode(frag);
3074
+ if (lastNode) placeCaretAfter(lastNode);
3075
+ emit();
3076
+ syncMenu();
3077
+ };
3078
+ const handleBlur = (e) => {
3079
+ if (onBlur) onBlur(e);
3080
+ };
3081
+ const handleFocus = (e) => {
3082
+ if (onFocus) onFocus(e);
3083
+ };
3084
+ (0, import_react16.useEffect)(() => {
3085
+ if (!menu) return void 0;
3086
+ const onSel = () => syncMenu();
3087
+ document.addEventListener("selectionchange", onSel);
3088
+ return () => document.removeEventListener("selectionchange", onSel);
3089
+ }, [menu, syncMenu]);
3090
+ (0, import_react16.useEffect)(() => {
3091
+ if (!menu) return;
3092
+ const el = document.getElementById(`${listId}-${active}`);
3093
+ const list = el && el.closest(".uic-mention-menu");
3094
+ if (!el || !list) return;
3095
+ const top = el.offsetTop - list.offsetTop;
3096
+ const bottom = top + el.offsetHeight;
3097
+ if (top < list.scrollTop) list.scrollTop = top;
3098
+ else if (bottom > list.scrollTop + list.clientHeight) list.scrollTop = bottom - list.clientHeight;
3099
+ }, [active, menu, listId]);
3100
+ const iconOf = (item) => {
3101
+ if (renderIcon) {
3102
+ const n = renderIcon(item);
3103
+ if (n) return n;
3104
+ }
3105
+ if (item.avatar) return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("img", { src: item.avatar, alt: "" });
3106
+ if (typeof item.icon === "string" && item.icon) return item.icon;
3107
+ if (item.icon) return item.icon;
3108
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "is-mono", children: monogram(item.name) });
3109
+ };
3110
+ let index = -1;
3111
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: ["uic-mention-field", disabled ? "is-disabled" : "", className].filter(Boolean).join(" "), children: [
3112
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
3113
+ "div",
3114
+ {
3115
+ ref: editorRef,
3116
+ id,
3117
+ className: "uic-mention-editor" + (empty ? " is-empty" : ""),
3118
+ contentEditable: !disabled,
3119
+ suppressContentEditableWarning: true,
3120
+ role: "textbox",
3121
+ "aria-multiline": "true",
3122
+ "aria-label": label,
3123
+ "aria-autocomplete": "list",
3124
+ "aria-expanded": !!menu,
3125
+ "aria-controls": menu ? listId : void 0,
3126
+ "aria-activedescendant": menu && flat.length ? `${listId}-${active}` : void 0,
3127
+ "data-placeholder": placeholder || "",
3128
+ spellCheck: "true",
3129
+ onInput: handleInput,
3130
+ onKeyDown: handleKeyDown,
3131
+ onPaste: handlePaste,
3132
+ onFocus: handleFocus,
3133
+ onBlur: handleBlur
3134
+ }
3135
+ ),
3136
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Popover, { open: !!menu, anchorRef, onClose: closeMenu, width: menuWidth, minHeight: 120, className: "uic-mention-pop", label: menuTitle || "Mentions", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "uic-mention-menu", role: "listbox", id: listId, onMouseDown: (e) => e.preventDefault(), children: [
3137
+ menuTitle ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "uic-mention-head", children: menuTitle }) : null,
3138
+ groups.map((g) => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "uic-mention-group", children: [
3139
+ g.section ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "uic-mention-sec", children: g.section }) : null,
3140
+ g.items.map((item) => {
3141
+ index += 1;
3142
+ const i = index;
3143
+ const dis = !!item.disabled;
3144
+ const reason = typeof item.disabled === "string" ? item.disabled : null;
3145
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
3146
+ "button",
3147
+ {
3148
+ type: "button",
3149
+ id: `${listId}-${i}`,
3150
+ role: "option",
3151
+ "aria-selected": i === active,
3152
+ "aria-disabled": dis || void 0,
3153
+ className: "uic-mention-item" + (i === active ? " is-active" : "") + (dis ? " is-disabled" : ""),
3154
+ style: item.color ? { "--uic-mention-color": item.color } : void 0,
3155
+ onMouseEnter: () => setActive(i),
3156
+ onClick: () => {
3157
+ if (!dis) pick(item);
3158
+ },
3159
+ children: [
3160
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "uic-mention-ic", children: iconOf(item) }),
3161
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("span", { className: "uic-mention-text", children: [
3162
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "uic-mention-name", children: item.name }),
3163
+ item.description ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "uic-mention-desc", children: item.description }) : null
3164
+ ] }),
3165
+ reason || item.tag ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "uic-mention-tag", children: reason || item.tag }) : null
3166
+ ]
3167
+ },
3168
+ item.id
3169
+ );
3170
+ })
3171
+ ] }, g.section || "_")),
3172
+ !flat.length ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "uic-mention-empty", children: emptyText }) : null
3173
+ ] }) })
3174
+ ] });
3175
+ });
3176
+ function MentionText({ value, items = [], format = CURLY, className = "", renderIcon }) {
3177
+ const resolver = (0, import_react16.useMemo)(() => makeResolver(items), [items]);
3178
+ const segs = (0, import_react16.useMemo)(() => parseValue(value || "", format, resolver), [value, format, resolver]);
3179
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: ["uic-mention-text-view", className].filter(Boolean).join(" "), children: segs.map((s, i) => {
3180
+ if (s.type === "text") return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react16.default.Fragment, { children: s.text }, i);
3181
+ const item = s.item || s;
3182
+ const icon = renderIcon ? renderIcon(item) : null;
3183
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
3184
+ "span",
3185
+ {
3186
+ className: "uic-mention",
3187
+ "data-kind": s.kind || void 0,
3188
+ title: item.description || void 0,
3189
+ style: item.color ? { "--uic-mention-color": item.color } : void 0,
3190
+ children: [
3191
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "uic-mention-ic" + (icon || typeof item.icon === "string" && item.icon || item.avatar ? "" : " is-mono"), children: icon || (item.avatar ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("img", { src: item.avatar, alt: "" }) : typeof item.icon === "string" && item.icon ? item.icon : monogram(item.name)) }),
3192
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "uic-mention-name", children: s.name })
3193
+ ]
3194
+ },
3195
+ i
3196
+ );
3197
+ }) });
3198
+ }
3199
+
3200
+ // src/sheet/SheetGrid.jsx
3201
+ var import_react_dom3 = require("react-dom");
3202
+
3203
+ // src/collab/colors.js
3204
+ function withAlpha(hex, alpha) {
3205
+ const m = /^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(String(hex || ""));
3206
+ if (!m) return hex;
3207
+ return `rgba(${parseInt(m[1], 16)}, ${parseInt(m[2], 16)}, ${parseInt(m[3], 16)}, ${alpha})`;
3208
+ }
3209
+
3210
+ // src/sheet/SheetGrid.jsx
3211
+ var import_jsx_runtime15 = require("react/jsx-runtime");
3212
+ var cellKey = (rowId, colId) => `${rowId}:${colId}`;
3213
+ var uid = (p) => `${p}_${Math.random().toString(36).slice(2, 10)}`;
3214
+ var TYPE_LABEL = {
3215
+ text: "Text",
3216
+ number: "Number",
3217
+ select: "Select",
3218
+ tags: "Tags",
3219
+ checkbox: "Checkbox",
3220
+ date: "Date",
3221
+ url: "Link",
3222
+ resource: "Resource",
3223
+ compute: "Computed"
3224
+ };
3225
+ var TYPE_GLYPH = { text: "Aa", number: "#", select: "\u25BE", tags: "#", checkbox: "\u2713", date: "\u25A6", url: "\u2197", resource: "\u25EB", compute: "\u2726" };
3226
+ var MANUAL_TYPES = ["text", "number", "select", "tags", "checkbox", "date", "url", "resource"];
3227
+ var COMPUTE_KINDS = [
3228
+ { kind: "prompt", label: "AI prompt" },
3229
+ { kind: "harness", label: "Agent (harness)" },
3230
+ { kind: "workflow", label: "Workflow" },
3231
+ { kind: "image", label: "Generate image" }
3232
+ ];
3233
+ var RESOURCE_KINDS = ["image", "sheet", "slides", "workflow", "graph"];
3234
+ var RESOURCE_ICON = { image: "\u{1F5BC}", sheet: "\u25A6", slides: "\u25A4", workflow: "\u2699", graph: "\u25C9" };
3235
+ function PopPortal({ anchor, width = 250, estHeight = 300, className, children, onClose }) {
3236
+ const boxRef = (0, import_react17.useRef)(null);
3237
+ (0, import_react17.useEffect)(() => {
3238
+ if (!onClose) return void 0;
3239
+ const close = (e) => {
3240
+ if (e?.type === "scroll" && boxRef.current && e.target instanceof Node && boxRef.current.contains(e.target)) return;
3241
+ onClose();
3242
+ };
3243
+ window.addEventListener("scroll", close, true);
3244
+ window.addEventListener("resize", close);
3245
+ return () => {
3246
+ window.removeEventListener("scroll", close, true);
3247
+ window.removeEventListener("resize", close);
3248
+ };
3249
+ }, [onClose]);
3250
+ if (!anchor) return null;
3251
+ const left = Math.max(8, Math.min(anchor.right - width, window.innerWidth - width - 8));
3252
+ let top = anchor.bottom + 6;
3253
+ if (top + estHeight > window.innerHeight - 8) top = Math.max(8, anchor.top - estHeight - 6);
3254
+ return (0, import_react_dom3.createPortal)(
3255
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { ref: boxRef, className, style: { position: "fixed", top, left, width, zIndex: 1e3 }, children }),
3256
+ document.body
3257
+ );
3258
+ }
3259
+ var PILL_PALETTE = [
3260
+ { name: "green", color: "#D1FAE5" },
3261
+ { name: "red", color: "#FEE2E2" },
3262
+ { name: "amber", color: "#FEF3C7" },
3263
+ { name: "blue", color: "#DBEAFE" },
3264
+ { name: "purple", color: "#EDE9FE" },
3265
+ { name: "pink", color: "#FCE7F3" },
3266
+ { name: "teal", color: "#CCFBF1" },
3267
+ { name: "gray", color: "#E5E7EB" }
3268
+ ];
3269
+ var PILL_FALLBACKS = ["#E0E7FF", "#FCE7F3", "#D1FAE5", "#FEF3C7", "#E0F2FE", "#F3E8FF", "#FFE4E6"];
3270
+ function normOptions(options) {
3271
+ return (options || []).map((o, i) => {
3272
+ if (typeof o === "string") return { label: o, color: PILL_FALLBACKS[i % PILL_FALLBACKS.length] };
3273
+ return { label: o.label ?? String(o.value ?? ""), color: o.color || PILL_FALLBACKS[i % PILL_FALLBACKS.length] };
3274
+ });
3275
+ }
3276
+ var sameValue = (a, b) => String(a).trim().toLowerCase() === String(b).trim().toLowerCase();
3277
+ function optionFor(value, options) {
3278
+ if (value === void 0 || value === null || value === "") return null;
3279
+ return normOptions(options).find((o) => sameValue(o.label, value)) || null;
3280
+ }
3281
+ function pillColor(label, options) {
3282
+ const hit = optionFor(label, options);
3283
+ if (hit) return hit.color;
3284
+ let h = 0;
3285
+ for (const ch of String(label)) h = h * 31 + ch.charCodeAt(0) >>> 0;
3286
+ return PILL_FALLBACKS[h % PILL_FALLBACKS.length];
3287
+ }
3288
+ function RefImage({ refVal, fetchBlobUrl }) {
3289
+ const [src, setSrc] = (0, import_react17.useState)(/^https?:\/\//i.test(refVal.url || "") ? refVal.url : null);
3290
+ (0, import_react17.useEffect)(() => {
3291
+ let dead = false;
3292
+ let obj = null;
3293
+ if (!src && refVal.url && fetchBlobUrl) {
3294
+ fetchBlobUrl(refVal.url).then((u) => {
3295
+ if (!dead) {
3296
+ obj = u;
3297
+ setSrc(u);
3298
+ }
3299
+ });
3300
+ }
3301
+ return () => {
3302
+ dead = true;
3303
+ if (obj) URL.revokeObjectURL(obj);
3304
+ };
3305
+ }, [refVal.url]);
3306
+ if (!src) return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("span", { className: "shg-refchip", children: [
3307
+ RESOURCE_ICON.image,
3308
+ " ",
3309
+ refVal.name || "image"
3310
+ ] });
3311
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("img", { className: "shg-refimg", src, alt: refVal.name || "", title: refVal.name || "" });
3312
+ }
3313
+ function ResourceChip({ refVal, onOpen }) {
3314
+ const icon = RESOURCE_ICON[refVal.kind] || "\u25C7";
3315
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
3316
+ "button",
3317
+ {
3318
+ className: "shg-refchip shg-refchip-btn",
3319
+ title: `Open ${refVal.kind}`,
3320
+ onClick: (e) => {
3321
+ e.stopPropagation();
3322
+ onOpen && onOpen(refVal);
3323
+ },
3324
+ children: [
3325
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "shg-refchip-ic", children: icon }),
3326
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "shg-refchip-name", children: refVal.name || refVal.id || refVal.kind })
3327
+ ]
3328
+ }
3329
+ );
3330
+ }
3331
+ function StatusDot({ status }) {
3332
+ if (!status || status === "empty" || status === "done") return null;
3333
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: `shg-dot shg-dot-${status}`, title: status });
3334
+ }
3335
+ function CellValue({ cell, col, fetchBlobUrl, onOpenResource }) {
3336
+ const v = cell?.value;
3337
+ if (v === void 0 || v === null || v === "") return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "shg-val-txt" });
3338
+ if (v && typeof v === "object" && !Array.isArray(v) && v.kind) {
3339
+ if (v.kind === "image") return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(RefImage, { refVal: v, fetchBlobUrl });
3340
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ResourceChip, { refVal: v, onOpen: onOpenResource });
3341
+ }
3342
+ const styled = col.type !== "tags" && optionFor(v, col.options);
3343
+ if (styled) return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "shg-pill", style: { background: styled.color }, children: styled.label });
3344
+ switch (col.type) {
3345
+ case "select":
3346
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "shg-pill", style: { background: pillColor(String(v), col.options) }, children: String(v) });
3347
+ case "tags": {
3348
+ const tags = Array.isArray(v) ? v : String(v).split(",").map((s) => s.trim()).filter(Boolean);
3349
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "shg-pills", children: tags.map((t) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "shg-pill", style: { background: pillColor(t, col.options) }, children: t }, t)) });
3350
+ }
3351
+ case "checkbox":
3352
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "shg-check" + (v ? " on" : ""), children: v ? "\u2713" : "" });
3353
+ case "url": {
3354
+ const href = /^https?:\/\//i.test(String(v)) ? String(v) : `https://${v}`;
3355
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("a", { className: "shg-link", href, target: "_blank", rel: "noreferrer", onClick: (e) => e.stopPropagation(), children: String(v) });
3356
+ }
3357
+ case "number":
3358
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "shg-val-txt shg-num", children: String(v) });
3359
+ default:
3360
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "shg-val-txt", children: typeof v === "object" ? JSON.stringify(v) : String(v) });
3361
+ }
3362
+ }
3363
+ function SheetGrid({ sheet, ops, onRunCell, onRunColumn, readOnly = false, fetchBlobUrl, onOpenResource, peers, onPresence }) {
3364
+ const columns = sheet?.columns || [];
3365
+ const rows = sheet?.rows || [];
3366
+ const cells = sheet?.cells || {};
3367
+ const tabId = sheet?.id;
3368
+ const canEdit = !readOnly && !!ops && !!tabId;
3369
+ const [editing, setEditing] = (0, import_react17.useState)(null);
3370
+ const [draft, setDraft] = (0, import_react17.useState)("");
3371
+ const [menuCol, setMenuCol] = (0, import_react17.useState)(null);
3372
+ const [sizeDraft, setSizeDraft] = (0, import_react17.useState)({});
3373
+ const [dnd, setDnd] = (0, import_react17.useState)(null);
3374
+ const [dropAt, setDropAt] = (0, import_react17.useState)(null);
3375
+ const inputRef = (0, import_react17.useRef)(null);
3376
+ const dragRef = (0, import_react17.useRef)(null);
3377
+ const [sel, setSel] = (0, import_react17.useState)(null);
3378
+ const dragSel = (0, import_react17.useRef)(false);
3379
+ const rootRef = (0, import_react17.useRef)(null);
3380
+ const presenceRef = (0, import_react17.useRef)(onPresence);
3381
+ presenceRef.current = onPresence;
3382
+ const range = sel ? {
3383
+ r0: Math.min(sel.a.r, sel.f.r),
3384
+ r1: Math.max(sel.a.r, sel.f.r),
3385
+ c0: Math.min(sel.a.c, sel.f.c),
3386
+ c1: Math.max(sel.a.c, sel.f.c)
3387
+ } : null;
3388
+ const inSel = (ri, ci) => !!range && ri >= range.r0 && ri <= range.r1 && ci >= range.c0 && ci <= range.c1;
3389
+ const isFocus = (ri, ci) => !!sel && sel.f.r === ri && sel.f.c === ci;
3390
+ const clampSel = (p) => ({ r: Math.max(0, Math.min(p.r, rows.length - 1)), c: Math.max(0, Math.min(p.c, columns.length - 1)) });
3391
+ const moveFocus = (dr, dc, extend) => setSel((cur) => {
3392
+ if (!cur || !rows.length || !columns.length) return cur;
3393
+ const f = clampSel({ r: cur.f.r + dr, c: cur.f.c + dc });
3394
+ return { a: extend ? cur.a : f, f };
2536
3395
  });
3396
+ (0, import_react17.useEffect)(() => {
3397
+ const up = () => {
3398
+ dragSel.current = false;
3399
+ };
3400
+ window.addEventListener("mouseup", up);
3401
+ return () => window.removeEventListener("mouseup", up);
3402
+ }, []);
3403
+ (0, import_react17.useEffect)(() => {
3404
+ const fn = presenceRef.current;
3405
+ if (!fn) return;
3406
+ const ids = (p) => [rows[p.r]?.id, columns[p.c]?.id];
3407
+ fn({
3408
+ sel: sel && rows[sel.f.r] && columns[sel.f.c] ? { a: ids(sel.a), f: ids(sel.f) } : null,
3409
+ typing: editing && typeof draft === "string" ? { key: cellKey(editing.rowId, editing.colId), text: draft } : null
3410
+ });
3411
+ }, [sel, editing, draft, rows, columns]);
3412
+ const peerLayer = (0, import_react17.useMemo)(() => {
3413
+ const focus = {}, tint = {}, typing = {};
3414
+ const rIdx = new Map(rows.map((r, i) => [r.id, i]));
3415
+ const cIdx = new Map(columns.map((c, i) => [c.id, i]));
3416
+ for (const p of peers || []) {
3417
+ if (p.typing && p.typing.key) typing[p.typing.key] = { text: p.typing.text, color: p.color, name: p.name };
3418
+ if (!p.sel || !p.sel.a || !p.sel.f) continue;
3419
+ const a = { r: rIdx.get(p.sel.a[0]), c: cIdx.get(p.sel.a[1]) }, f = { r: rIdx.get(p.sel.f[0]), c: cIdx.get(p.sel.f[1]) };
3420
+ if ([a.r, a.c, f.r, f.c].some((v) => v === void 0)) continue;
3421
+ focus[cellKey(p.sel.f[0], p.sel.f[1])] = p;
3422
+ for (let r = Math.min(a.r, f.r); r <= Math.max(a.r, f.r); r++) {
3423
+ for (let c = Math.min(a.c, f.c); c <= Math.max(a.c, f.c); c++) {
3424
+ const k = cellKey(rows[r].id, columns[c].id);
3425
+ if (!tint[k]) tint[k] = p.color;
3426
+ }
3427
+ }
3428
+ }
3429
+ return { focus, tint, typing };
3430
+ }, [peers, rows, columns]);
3431
+ const startResize = (e, kind, id, start) => {
3432
+ if (readOnly) return;
3433
+ e.preventDefault();
3434
+ e.stopPropagation();
3435
+ const origin = kind === "col" ? e.clientX : e.clientY;
3436
+ dragRef.current = { kind, id, start, origin, last: start };
3437
+ const onMove = (ev) => {
3438
+ const d = dragRef.current;
3439
+ if (!d) return;
3440
+ const delta = (d.kind === "col" ? ev.clientX : ev.clientY) - d.origin;
3441
+ const next = Math.max(d.kind === "col" ? 90 : 26, d.start + delta);
3442
+ d.last = next;
3443
+ setSizeDraft((sd) => ({ ...sd, [d.kind]: { ...sd[d.kind] || {}, [d.id]: next } }));
3444
+ };
3445
+ const onUp = () => {
3446
+ const d = dragRef.current;
3447
+ dragRef.current = null;
3448
+ window.removeEventListener("mousemove", onMove);
3449
+ window.removeEventListener("mouseup", onUp);
3450
+ document.body.style.cursor = "";
3451
+ if (!d) return;
3452
+ setSizeDraft({});
3453
+ if (!canEdit) return;
3454
+ if (d.kind === "col") {
3455
+ const c = columns.find((x) => x.id === d.id);
3456
+ if (c) ops.setColumn(tabId, { ...c, width: Math.round(d.last) });
3457
+ } else {
3458
+ const r = rows.find((x) => x.id === d.id);
3459
+ if (r) ops.setRow(tabId, { ...r, height: Math.round(d.last) });
3460
+ }
3461
+ };
3462
+ window.addEventListener("mousemove", onMove);
3463
+ window.addEventListener("mouseup", onUp);
3464
+ document.body.style.cursor = kind === "col" ? "col-resize" : "row-resize";
3465
+ };
3466
+ const colWidth = (col) => sizeDraft.col && sizeDraft.col[col.id] || col.width || void 0;
3467
+ const reorder = (kind, fromId, toId, after) => {
3468
+ if (!canEdit || fromId === toId) return;
3469
+ const arr = (kind === "col" ? columns : rows).map((x) => x.id);
3470
+ const i = arr.indexOf(fromId);
3471
+ if (i < 0) return;
3472
+ arr.splice(i, 1);
3473
+ let j = arr.indexOf(toId);
3474
+ if (j < 0) return;
3475
+ if (after) j += 1;
3476
+ if (kind === "col") ops.moveColumn(tabId, fromId, j);
3477
+ else ops.moveRow(tabId, fromId, j);
3478
+ };
2537
3479
  const dndProps = (kind, id) => readOnly ? {} : {
2538
3480
  draggable: true,
2539
3481
  onDragStart: (e) => {
@@ -2575,82 +3517,163 @@ function SheetGrid({
2575
3517
  }
2576
3518
  return cls;
2577
3519
  };
2578
- const numW = Math.max(48, 30 + String(rows.length || 1).length * 9);
3520
+ const numW = Math.max(40, 24 + String(rows.length || 1).length * 9);
2579
3521
  const numStyle = { width: numW, minWidth: numW, maxWidth: numW };
2580
3522
  const rowHeight = (row) => sizeDraft.row && sizeDraft.row[row.id] || row.height || void 0;
2581
- (0, import_react15.useEffect)(() => {
3523
+ (0, import_react17.useEffect)(() => {
2582
3524
  if (editing && inputRef.current) inputRef.current.focus();
2583
3525
  }, [editing]);
2584
- const mutate = (fn) => {
2585
- if (readOnly || !onChange) return;
2586
- const next = JSON.parse(JSON.stringify(sheet));
2587
- fn(next);
2588
- onChange(next);
3526
+ const setCell = (rowId, colId, value) => {
3527
+ if (!canEdit) return;
3528
+ ops.setCell(tabId, cellKey(rowId, colId), { value, status: "done", updated_at: Math.floor(Date.now() / 1e3) });
2589
3529
  };
2590
- const setCell = (rowId, colId, value) => mutate((n) => {
2591
- n.cells = n.cells || {};
2592
- const k = cellKey(rowId, colId);
2593
- const col = (n.columns || []).find((c) => c.id === colId);
2594
- const prev = n.cells[k];
2595
- n.cells[k] = isComputed(col) && prev ? { ...prev, value } : { value };
2596
- });
2597
- const openEdit = (rowId, col, anchorEl) => {
2598
- if (readOnly) return;
2599
- if (!isEditable(col)) return;
3530
+ const openEdit = (rowId, col, anchorEl, initial) => {
3531
+ if (!canEdit) return;
3532
+ if (col.type === "compute") return;
2600
3533
  if (col.type === "checkbox") {
2601
3534
  const cur = cells[cellKey(rowId, col.id)];
2602
3535
  setCell(rowId, col.id, !(cur && cur.value));
2603
3536
  return;
2604
3537
  }
2605
- const c = cells[cellKey(rowId, col.id)];
2606
- const v = c?.value;
2607
- if (col.type === "tags") setDraft(Array.isArray(v) ? v.join(", ") : v || "");
2608
- else if (col.type === "resource") setDraft(v && typeof v === "object" ? v : { kind: "sheet", name: "", id: "", url: "" });
2609
- else setDraft(v == null ? "" : String(v));
2610
- setEditing({ rowId, colId: col.id, type: col.type, rect: anchorEl?.getBoundingClientRect?.() || null });
2611
- onActiveCell && onActiveCell(cellKey(rowId, col.id));
2612
- };
2613
- const commitEdit = () => {
2614
- onActiveCell && onActiveCell(null);
2615
- if (!editing) return;
2616
- const { rowId, colId, type } = editing;
2617
- let value = draft;
2618
- if (type === "number") value = draft === "" ? null : Number(draft);
2619
- else if (type === "tags") value = draft ? draft.split(",").map((s) => s.trim()).filter(Boolean) : [];
2620
- setCell(rowId, colId, value);
2621
- setEditing(null);
2622
- };
2623
- const addColumn = () => mutate((n) => {
2624
- n.columns.push({ id: uid("col"), name: `Column ${n.columns.length + 1}`, type: "text" });
2625
- });
2626
- const addRow = () => mutate((n) => {
2627
- n.rows.push({ id: uid("row") });
2628
- });
2629
- const deleteColumn = (colId) => mutate((n) => {
2630
- n.columns = n.columns.filter((c) => c.id !== colId);
2631
- for (const k of Object.keys(n.cells || {})) if (k.endsWith(`:${colId}`)) delete n.cells[k];
2632
- });
2633
- const deleteRow = (rowId) => mutate((n) => {
2634
- n.rows = n.rows.filter((r) => r.id !== rowId);
2635
- for (const k of Object.keys(n.cells || {})) if (k.startsWith(`${rowId}:`)) delete n.cells[k];
2636
- });
2637
- const renameColumn = (colId, name) => mutate((n) => {
2638
- const c = n.columns.find((x) => x.id === colId);
2639
- if (c) c.name = name;
2640
- });
2641
- const configureColumn = (colId, patch) => mutate((n) => {
2642
- const c = n.columns.find((x) => x.id === colId);
2643
- if (!c) return;
2644
- Object.assign(c, patch);
2645
- if (patch.type) {
2646
- for (const d of columnTypes) if (d.configKey && d.type !== patch.type) delete c[d.configKey];
3538
+ const c = cells[cellKey(rowId, col.id)];
3539
+ const v = c?.value;
3540
+ if (col.type === "tags") setDraft(initial ?? (Array.isArray(v) ? v.join(", ") : v || ""));
3541
+ else if (col.type === "resource") setDraft(v && typeof v === "object" ? v : { kind: "sheet", name: "", id: "", url: "" });
3542
+ else setDraft(initial ?? (v == null ? "" : String(v)));
3543
+ setEditing({ rowId, colId: col.id, type: col.type, rect: anchorEl?.getBoundingClientRect?.() || null });
3544
+ };
3545
+ const commitEdit = () => {
3546
+ if (!editing) return;
3547
+ const { rowId, colId, type } = editing;
3548
+ let value = draft;
3549
+ if (type === "number") value = draft === "" ? null : Number(draft);
3550
+ else if (type === "tags") value = draft ? draft.split(",").map((s) => s.trim()).filter(Boolean) : [];
3551
+ setCell(rowId, colId, value);
3552
+ setEditing(null);
3553
+ };
3554
+ const addColumn = () => canEdit && ops.setColumn(tabId, { id: uid("col"), name: `Column ${columns.length + 1}`, type: "text" });
3555
+ const addRow = () => canEdit && ops.setRow(tabId, { id: uid("row") });
3556
+ const deleteColumn = (colId) => canEdit && ops.deleteColumn(tabId, colId);
3557
+ const deleteRow = (rowId) => canEdit && ops.deleteRow(tabId, rowId);
3558
+ const renameColumn = (colId, name) => {
3559
+ const c = columns.find((x) => x.id === colId);
3560
+ if (canEdit && c) ops.setColumn(tabId, { ...c, name });
3561
+ };
3562
+ const configureColumn = (colId, patch) => {
3563
+ const c = columns.find((x) => x.id === colId);
3564
+ if (!canEdit || !c) return;
3565
+ const next = { ...c, ...patch };
3566
+ if (patch.type && patch.type !== "compute") delete next.compute;
3567
+ ops.setColumn(tabId, next);
3568
+ };
3569
+ const cellText = (c) => {
3570
+ const v = c?.value;
3571
+ if (v === void 0 || v === null) return "";
3572
+ if (Array.isArray(v)) return v.join(", ");
3573
+ if (typeof v === "object") return v.name || v.url || v.id || "";
3574
+ return String(v);
3575
+ };
3576
+ const copySelection = (e) => {
3577
+ if (!range || editing) return;
3578
+ const lines = [];
3579
+ for (let r = range.r0; r <= range.r1; r++) {
3580
+ const parts = [];
3581
+ for (let c = range.c0; c <= range.c1; c++) parts.push(cellText(cells[cellKey(rows[r].id, columns[c].id)]));
3582
+ lines.push(parts.join(" "));
3583
+ }
3584
+ e.clipboardData.setData("text/plain", lines.join("\n"));
3585
+ e.preventDefault();
3586
+ };
3587
+ const pasteAt = (e) => {
3588
+ if (!sel || editing || !canEdit) return;
3589
+ const text = e.clipboardData.getData("text/plain");
3590
+ if (!text) return;
3591
+ e.preventDefault();
3592
+ const now = Math.floor(Date.now() / 1e3);
3593
+ const patch = {};
3594
+ const lines = text.replace(/\r/g, "").split("\n");
3595
+ if (lines.length > 1 && lines[lines.length - 1] === "") lines.pop();
3596
+ lines.forEach((line, dr) => line.split(" ").forEach((raw, dc) => {
3597
+ const row = rows[sel.f.r + dr], col = columns[sel.f.c + dc];
3598
+ if (!row || !col || col.type === "compute") return;
3599
+ let value = raw;
3600
+ if (col.type === "number") value = raw === "" ? null : Number(raw);
3601
+ else if (col.type === "checkbox") value = /^(true|yes|1|✓)$/i.test(raw.trim());
3602
+ else if (col.type === "tags") value = raw ? raw.split(",").map((x) => x.trim()).filter(Boolean) : [];
3603
+ patch[cellKey(row.id, col.id)] = value === null || value === "" ? null : { value, status: "done", updated_at: now };
3604
+ }));
3605
+ if (Object.keys(patch).length) ops.setCells(tabId, patch);
3606
+ setSel({ a: sel.f, f: clampSel({ r: sel.f.r + lines.length - 1, c: sel.f.c + Math.max(...lines.map((l) => l.split(" ").length)) - 1 }) });
3607
+ };
3608
+ const clearSelection = () => {
3609
+ if (!range || !canEdit) return;
3610
+ const patch = {};
3611
+ for (let r = range.r0; r <= range.r1; r++) {
3612
+ for (let c = range.c0; c <= range.c1; c++) {
3613
+ if (columns[c].type === "compute") continue;
3614
+ const k = cellKey(rows[r].id, columns[c].id);
3615
+ if (cells[k]) patch[k] = null;
3616
+ }
3617
+ }
3618
+ if (Object.keys(patch).length) ops.setCells(tabId, patch);
3619
+ };
3620
+ const onKeyDown = (e) => {
3621
+ if (editing || menuCol) return;
3622
+ if (!sel) return;
3623
+ const meta = e.metaKey || e.ctrlKey;
3624
+ if (meta && (e.key === "c" || e.key === "v" || e.key === "x")) return;
3625
+ const focusCell = () => ({ row: rows[sel.f.r], col: columns[sel.f.c] });
3626
+ switch (e.key) {
3627
+ case "ArrowUp":
3628
+ e.preventDefault();
3629
+ moveFocus(-1, 0, e.shiftKey);
3630
+ return;
3631
+ case "ArrowDown":
3632
+ e.preventDefault();
3633
+ moveFocus(1, 0, e.shiftKey);
3634
+ return;
3635
+ case "ArrowLeft":
3636
+ e.preventDefault();
3637
+ moveFocus(0, -1, e.shiftKey);
3638
+ return;
3639
+ case "ArrowRight":
3640
+ e.preventDefault();
3641
+ moveFocus(0, 1, e.shiftKey);
3642
+ return;
3643
+ case "Tab":
3644
+ e.preventDefault();
3645
+ moveFocus(0, e.shiftKey ? -1 : 1, false);
3646
+ return;
3647
+ case "Escape":
3648
+ setSel(null);
3649
+ return;
3650
+ case "Enter":
3651
+ case "F2": {
3652
+ e.preventDefault();
3653
+ const { row, col } = focusCell();
3654
+ if (row && col) openEdit(row.id, col, rootRef.current?.querySelector(`[data-cell="${cellKey(row.id, col.id)}"]`));
3655
+ return;
3656
+ }
3657
+ case "Delete":
3658
+ case "Backspace":
3659
+ e.preventDefault();
3660
+ clearSelection();
3661
+ return;
3662
+ default:
3663
+ }
3664
+ if (!meta && !e.altKey && e.key.length === 1) {
3665
+ const { row, col } = focusCell();
3666
+ if (row && col && col.type !== "compute" && col.type !== "checkbox") {
3667
+ e.preventDefault();
3668
+ openEdit(row.id, col, rootRef.current?.querySelector(`[data-cell="${cellKey(row.id, col.id)}"]`), e.key);
3669
+ }
2647
3670
  }
2648
- });
3671
+ };
2649
3672
  const renderEditor = (col) => {
2650
3673
  if (col.type === "resource") {
2651
3674
  const d = typeof draft === "object" && draft ? draft : { kind: "sheet" };
2652
3675
  const set = (k, v) => setDraft({ ...d, [k]: v });
2653
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
3676
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2654
3677
  PopPortal,
2655
3678
  {
2656
3679
  anchor: editing.rect,
@@ -2658,17 +3681,17 @@ function SheetGrid({
2658
3681
  estHeight: 230,
2659
3682
  className: "shg-select-pop shg-ref-pop",
2660
3683
  onClose: () => setEditing(null),
2661
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { onClick: (e) => e.stopPropagation(), children: [
2662
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("select", { className: "shg-menu-input", value: d.kind || "sheet", onChange: (e) => set("kind", e.target.value), children: RESOURCE_KINDS.map((k) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("option", { value: k, children: k }, k)) }),
2663
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("input", { className: "shg-menu-input", placeholder: "Name", value: d.name || "", onChange: (e) => set("name", e.target.value) }),
2664
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("input", { className: "shg-menu-input", placeholder: "Resource id (e.g. sheet.\u2026)", value: d.id || "", onChange: (e) => set("id", e.target.value) }),
2665
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("input", { className: "shg-menu-input", placeholder: "or URL", value: d.url || "", onChange: (e) => set("url", e.target.value) }),
2666
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "shg-menu-actions", children: [
2667
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { className: "shg-pop-clear", onClick: () => {
3684
+ children: /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { onClick: (e) => e.stopPropagation(), children: [
3685
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("select", { className: "shg-menu-input", value: d.kind || "sheet", onChange: (e) => set("kind", e.target.value), children: RESOURCE_KINDS.map((k) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("option", { value: k, children: k }, k)) }),
3686
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("input", { className: "shg-menu-input", placeholder: "Name", value: d.name || "", onChange: (e) => set("name", e.target.value) }),
3687
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("input", { className: "shg-menu-input", placeholder: "Resource id (e.g. sheet.\u2026)", value: d.id || "", onChange: (e) => set("id", e.target.value) }),
3688
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("input", { className: "shg-menu-input", placeholder: "or URL", value: d.url || "", onChange: (e) => set("url", e.target.value) }),
3689
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "shg-menu-actions", children: [
3690
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { className: "shg-pop-clear", onClick: () => {
2668
3691
  setCell(editing.rowId, editing.colId, null);
2669
3692
  setEditing(null);
2670
3693
  }, children: "Clear" }),
2671
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { className: "shg-menu-apply", onClick: () => {
3694
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { className: "shg-menu-apply", onClick: () => {
2672
3695
  setCell(editing.rowId, editing.colId, d);
2673
3696
  setEditing(null);
2674
3697
  }, children: "Set" })
@@ -2679,7 +3702,7 @@ function SheetGrid({
2679
3702
  }
2680
3703
  if (col.type === "select") {
2681
3704
  const opts = normOptions(col.options);
2682
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
3705
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
2683
3706
  PopPortal,
2684
3707
  {
2685
3708
  anchor: editing.rect,
@@ -2688,8 +3711,8 @@ function SheetGrid({
2688
3711
  className: "shg-select-pop",
2689
3712
  onClose: () => setEditing(null),
2690
3713
  children: [
2691
- opts.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "shg-pop-note", children: "No options yet \u2014 add them in the column menu." }),
2692
- opts.map((o) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
3714
+ opts.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "shg-pop-note", children: "No options yet \u2014 add them in the column menu." }),
3715
+ opts.map((o) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2693
3716
  "button",
2694
3717
  {
2695
3718
  className: "shg-pill shg-pill-btn",
@@ -2703,7 +3726,7 @@ function SheetGrid({
2703
3726
  },
2704
3727
  o.label
2705
3728
  )),
2706
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
3729
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2707
3730
  "button",
2708
3731
  {
2709
3732
  className: "shg-pop-clear",
@@ -2720,7 +3743,7 @@ function SheetGrid({
2720
3743
  );
2721
3744
  }
2722
3745
  const inputType = col.type === "date" ? "date" : col.type === "number" ? "number" : "text";
2723
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
3746
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2724
3747
  "input",
2725
3748
  {
2726
3749
  ref: inputRef,
@@ -2731,32 +3754,41 @@ function SheetGrid({
2731
3754
  onChange: (e) => setDraft(e.target.value),
2732
3755
  onBlur: commitEdit,
2733
3756
  onKeyDown: (e) => {
2734
- if (e.key === "Enter") commitEdit();
2735
- if (e.key === "Escape") setEditing(null);
3757
+ if (e.key === "Enter") {
3758
+ e.preventDefault();
3759
+ commitEdit();
3760
+ moveFocus(1, 0, false);
3761
+ rootRef.current?.focus();
3762
+ } else if (e.key === "Tab") {
3763
+ e.preventDefault();
3764
+ commitEdit();
3765
+ moveFocus(0, e.shiftKey ? -1 : 1, false);
3766
+ rootRef.current?.focus();
3767
+ } else if (e.key === "Escape") {
3768
+ setEditing(null);
3769
+ rootRef.current?.focus();
3770
+ }
2736
3771
  }
2737
3772
  }
2738
3773
  );
2739
3774
  };
2740
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "shg", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "shg-scroll", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("table", { className: "shg-table", children: [
2741
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("tr", { children: [
2742
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("th", { className: "shg-corner", style: numStyle }),
2743
- columns.map((col) => /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
3775
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "shg", ref: rootRef, tabIndex: 0, onKeyDown, onCopy: copySelection, onPaste: pasteAt, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "shg-scroll", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("table", { className: "shg-table", children: [
3776
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("tr", { children: [
3777
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("th", { className: "shg-corner", style: numStyle }),
3778
+ columns.map((col) => /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
2744
3779
  "th",
2745
3780
  {
2746
- className: "shg-col" + (isComputed(col) ? " shg-col-compute" : "") + dndClass("col", col.id),
3781
+ className: "shg-col" + (col.type === "compute" ? " shg-col-compute" : "") + dndClass("col", col.id),
2747
3782
  style: colWidth(col) ? { width: colWidth(col), minWidth: colWidth(col), maxWidth: colWidth(col) } : void 0,
2748
3783
  ...dndProps("col", col.id),
2749
3784
  children: [
2750
- !readOnly && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "shg-resize-col", onMouseDown: (e) => startResize(e, "col", col.id, colWidth(col) || e.currentTarget.closest("th").offsetWidth) }),
2751
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "shg-col-h", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
3785
+ !readOnly && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "shg-resize-col", onMouseDown: (e) => startResize(e, "col", col.id, colWidth(col) || e.currentTarget.closest("th").offsetWidth) }),
3786
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "shg-col-h", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2752
3787
  ColumnHeader,
2753
3788
  {
2754
3789
  col,
2755
3790
  columns,
2756
3791
  readOnly,
2757
- desc: descOf(col.type),
2758
- columnTypes,
2759
- renderColumnConfig,
2760
3792
  menuOpen: menuCol?.id === col.id,
2761
3793
  menuAnchor: menuCol?.id === col.id ? menuCol.rect : null,
2762
3794
  onMenu: (e) => setMenuCol(menuCol?.id === col.id ? null : { id: col.id, rect: e.currentTarget.getBoundingClientRect() }),
@@ -2767,26 +3799,26 @@ function SheetGrid({
2767
3799
  setMenuCol(null);
2768
3800
  deleteColumn(col.id);
2769
3801
  },
2770
- onRun: isComputed(col) && onRunColumn ? () => onRunColumn(col.id) : null
3802
+ onRun: col.type === "compute" && onRunColumn ? () => onRunColumn(col.id) : null,
3803
+ width: colWidth(col)
2771
3804
  }
2772
3805
  ) })
2773
3806
  ]
2774
3807
  },
2775
3808
  col.id
2776
3809
  )),
2777
- !readOnly && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("th", { className: "shg-add-col", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { className: "shg-add", onClick: addColumn, title: "Add column", children: "+" }) })
3810
+ !readOnly && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("th", { className: "shg-add-col", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { className: "shg-add", onClick: addColumn, title: "Add column", children: "+" }) })
2778
3811
  ] }) }),
2779
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("tbody", { children: [
2780
- rows.map((row, ri) => /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
3812
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("tbody", { children: [
3813
+ rows.map((row, ri) => /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
2781
3814
  "tr",
2782
3815
  {
2783
- "data-row-id": row.id,
2784
3816
  style: {
2785
3817
  ...rowHeight(row) ? { height: rowHeight(row) } : null,
2786
3818
  "--shg-clamp": Math.max(1, Math.floor(((rowHeight(row) || 34) - 10) / 18))
2787
3819
  },
2788
3820
  children: [
2789
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
3821
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
2790
3822
  "td",
2791
3823
  {
2792
3824
  className: "shg-rownum" + dndClass("row", row.id),
@@ -2794,127 +3826,102 @@ function SheetGrid({
2794
3826
  title: "Drag to reorder",
2795
3827
  ...dndProps("row", row.id),
2796
3828
  children: [
2797
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: ri + 1 }),
2798
- !readOnly && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { className: "shg-rowdel", onClick: () => deleteRow(row.id), title: "Delete row", children: "\xD7" }),
2799
- !readOnly && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "shg-resize-row", onMouseDown: (e) => startResize(e, "row", row.id, rowHeight(row) || e.currentTarget.closest("tr").offsetHeight) })
3829
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { children: ri + 1 }),
3830
+ !readOnly && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { className: "shg-rowdel", onClick: () => deleteRow(row.id), title: "Delete row", children: "\xD7" }),
3831
+ !readOnly && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "shg-resize-row", onMouseDown: (e) => startResize(e, "row", row.id, rowHeight(row) || e.currentTarget.closest("tr").offsetHeight) })
2800
3832
  ]
2801
3833
  }
2802
3834
  ),
2803
- columns.map((col) => {
2804
- const c = cells[cellKey(row.id, col.id)] || {};
2805
- const computed = isComputed(col);
3835
+ columns.map((col, ci) => {
3836
+ const key = cellKey(row.id, col.id);
3837
+ const c = cells[key] || {};
2806
3838
  const isEditing = editing && editing.rowId === row.id && editing.colId === col.id;
2807
- const peer = peerMarks && peerMarks[cellKey(row.id, col.id)];
2808
- const custom = renderCell && renderCell({
2809
- cell: c,
2810
- column: col,
2811
- row,
2812
- rowIndex: ri,
2813
- sheet,
2814
- computed,
2815
- width: colWidth(col),
2816
- height: rowHeight(row),
2817
- editing: !!isEditing,
2818
- readOnly,
2819
- setCell: (v) => setCell(row.id, col.id, v),
2820
- runCell: onRunCell && !readOnly ? () => onRunCell(row.id, col.id) : null
2821
- });
2822
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
3839
+ const peer = peerLayer.focus[key];
3840
+ const ghost = !isEditing && peerLayer.typing[key];
3841
+ const selected = inSel(ri, ci), focused = isFocus(ri, ci);
3842
+ const shadows = [];
3843
+ if (focused) shadows.push("inset 0 0 0 2px var(--brand, #0E7490)");
3844
+ if (peer) shadows.push(`inset 0 0 0 2px ${peer.color}`);
3845
+ const tint = !selected && peerLayer.tint[key];
3846
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
2823
3847
  "td",
2824
3848
  {
2825
- "data-col-id": col.id,
2826
- className: "shg-cell" + (computed ? " shg-cell-compute" : "") + (c.status && computed ? ` shg-cell-${c.status}` : "") + (peer ? " shg-cell-peer" : ""),
2827
- style: peer ? { boxShadow: `inset 0 0 0 2px ${peer.color}` } : void 0,
3849
+ "data-cell": key,
3850
+ className: "shg-cell" + (col.type === "compute" ? " shg-cell-compute" : "") + (c.status && col.type === "compute" ? ` shg-cell-${c.status}` : "") + (selected ? " shg-sel" : "") + (focused ? " shg-focus" : "") + (peer ? " shg-cell-peer" : ""),
3851
+ style: {
3852
+ ...shadows.length ? { boxShadow: shadows.join(", ") } : null,
3853
+ ...tint ? { background: withAlpha(tint, 0.1) } : null
3854
+ },
3855
+ onMouseDown: (e) => {
3856
+ if (e.button !== 0 || isEditing) return;
3857
+ if (editing) commitEdit();
3858
+ const p = { r: ri, c: ci };
3859
+ setSel((cur) => e.shiftKey && cur ? { a: cur.a, f: p } : { a: p, f: p });
3860
+ dragSel.current = true;
3861
+ e.preventDefault();
3862
+ rootRef.current?.focus();
3863
+ },
3864
+ onMouseEnter: () => {
3865
+ if (dragSel.current) setSel((cur) => cur ? { a: cur.a, f: { r: ri, c: ci } } : cur);
3866
+ },
2828
3867
  onClick: (e) => {
3868
+ if (col.type === "checkbox" && !isEditing) openEdit(row.id, col, e.currentTarget);
3869
+ },
3870
+ onDoubleClick: (e) => {
2829
3871
  if (!isEditing) openEdit(row.id, col, e.currentTarget);
2830
3872
  },
2831
3873
  title: c.error || "",
2832
3874
  children: [
2833
- !readOnly && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
2834
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
2835
- "span",
2836
- {
2837
- className: "shg-resize-col shg-resize-in-cell",
2838
- onClick: (e) => e.stopPropagation(),
2839
- onMouseDown: (e) => startResize(
2840
- e,
2841
- "col",
2842
- col.id,
2843
- colWidth(col) || e.currentTarget.closest("td").offsetWidth
2844
- )
2845
- }
2846
- ),
2847
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
2848
- "span",
2849
- {
2850
- className: "shg-resize-row shg-resize-in-cell",
2851
- onClick: (e) => e.stopPropagation(),
2852
- onMouseDown: (e) => startResize(
2853
- e,
2854
- "row",
2855
- row.id,
2856
- rowHeight(row) || e.currentTarget.closest("tr").offsetHeight
3875
+ peer && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "shg-peer-flag", style: { background: peer.color }, children: peer.name }),
3876
+ isEditing ? renderEditor(col) : /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
3877
+ "div",
3878
+ {
3879
+ className: "shg-val",
3880
+ style: { maxWidth: colWidth(col) ? colWidth(col) - 20 : 400 },
3881
+ children: [
3882
+ col.type === "compute" && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(StatusDot, { status: c.status }),
3883
+ ghost ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "shg-ghost", style: { color: ghost.color }, title: `${ghost.name} is typing`, children: ghost.text }) : /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(CellValue, { cell: c, col, fetchBlobUrl, onOpenResource }),
3884
+ col.type === "compute" && !readOnly && onRunCell && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
3885
+ "button",
3886
+ {
3887
+ className: "shg-runcell",
3888
+ title: "Run this cell",
3889
+ onClick: (e) => {
3890
+ e.stopPropagation();
3891
+ onRunCell(row.id, col.id);
3892
+ },
3893
+ children: "\u25B6"
3894
+ }
2857
3895
  )
2858
- }
2859
- )
2860
- ] }),
2861
- peer && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "shg-peer-flag", style: { background: peer.color }, children: peer.name }),
2862
- isEditing ? renderEditor(col) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "shg-val", children: custom !== void 0 ? custom : /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
2863
- computed && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(StatusDot, { status: c.status }),
2864
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(CellValue, { cell: c, col, fetchBlobUrl, onOpenResource }),
2865
- computed && !readOnly && onRunCell && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
2866
- "button",
2867
- {
2868
- className: "shg-runcell",
2869
- title: "Run this cell",
2870
- onClick: (e) => {
2871
- e.stopPropagation();
2872
- onRunCell(row.id, col.id);
2873
- },
2874
- children: "\u25B6"
2875
- }
2876
- )
2877
- ] }) })
3896
+ ]
3897
+ }
3898
+ )
2878
3899
  ]
2879
3900
  },
2880
3901
  col.id
2881
3902
  );
2882
3903
  }),
2883
- !readOnly && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("td", { className: "shg-pad" })
3904
+ !readOnly && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("td", { className: "shg-pad" })
2884
3905
  ]
2885
3906
  },
2886
3907
  row.id
2887
3908
  )),
2888
- !readOnly && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("tr", { className: "shg-ghost-row", onClick: addRow, children: [
2889
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("td", { className: "shg-rownum shg-ghost-num", style: numStyle, children: "+" }),
2890
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("td", { className: "shg-ghost-cell", colSpan: columns.length + 1, children: "New row" })
3909
+ !readOnly && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("tr", { className: "shg-ghost-row", onClick: addRow, children: [
3910
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("td", { className: "shg-rownum shg-ghost-num", style: numStyle, children: "+" }),
3911
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("td", { className: "shg-ghost-cell", colSpan: columns.length + 1, children: "New row" })
2891
3912
  ] })
2892
3913
  ] })
2893
3914
  ] }) }) });
2894
3915
  }
2895
- function ColumnHeader({
2896
- col,
2897
- columns,
2898
- readOnly,
2899
- desc,
2900
- columnTypes,
2901
- renderColumnConfig,
2902
- menuOpen,
2903
- menuAnchor,
2904
- onMenu,
2905
- onCloseMenu,
2906
- onRename,
2907
- onConfigure,
2908
- onDelete,
2909
- onRun
2910
- }) {
2911
- const [editing, setEditing] = (0, import_react15.useState)(false);
2912
- const [name, setName] = (0, import_react15.useState)(col.name);
2913
- (0, import_react15.useEffect)(() => setName(col.name), [col.name]);
2914
- const badge = desc.badge ? desc.badge(col) : void 0;
2915
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "shg-colhdr", children: [
2916
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "shg-colhdr-main", children: [
2917
- editing && !readOnly ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
3916
+ function ColumnHeader({ col, columns, readOnly, menuOpen, menuAnchor, onMenu, onCloseMenu, onRename, onConfigure, onDelete, onRun, width }) {
3917
+ const [editing, setEditing] = (0, import_react17.useState)(false);
3918
+ const [name, setName] = (0, import_react17.useState)(col.name);
3919
+ (0, import_react17.useEffect)(() => setName(col.name), [col.name]);
3920
+ const w = Number(width) || 0;
3921
+ const fit = w && w < 160 ? " tight" : w && w < 200 ? " narrow" : "";
3922
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "shg-colhdr" + fit, children: [
3923
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "shg-colhdr-main", children: [
3924
+ editing && !readOnly ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2918
3925
  "input",
2919
3926
  {
2920
3927
  className: "shg-colname-input",
@@ -2929,24 +3936,25 @@ function ColumnHeader({
2929
3936
  if (e.key === "Enter") e.target.blur();
2930
3937
  }
2931
3938
  }
2932
- ) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "shg-colname", onDoubleClick: () => !readOnly && setEditing(true), title: col.name, children: col.name }),
2933
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "shg-coltype" + (desc.computed ? " compute" : ""), children: [
2934
- desc.label || col.type,
2935
- badge ? ` \xB7 ${badge}` : ""
3939
+ ) : /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "shg-colname", onDoubleClick: () => !readOnly && setEditing(true), title: col.name, children: col.name }),
3940
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("span", { className: "shg-coltype" + (col.type === "compute" ? " compute" : ""), children: [
3941
+ TYPE_LABEL[col.type] || col.type,
3942
+ col.type === "compute" && col.compute?.kind ? ` \xB7 ${col.compute.kind}` : ""
2936
3943
  ] })
2937
3944
  ] }),
2938
- !readOnly && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "shg-colhdr-tools", children: [
2939
- onRun && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { className: "shg-colrun", onClick: onRun, title: "Run this column", children: "\u25B6 Run" }),
2940
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { className: "shg-colmenu-btn", onClick: (e) => onMenu(e), title: "Column settings", children: "\u22EF" })
3945
+ !readOnly && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "shg-colhdr-tools", children: [
3946
+ onRun && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("button", { className: "shg-colrun", onClick: onRun, title: "Run this column", "aria-label": "Run this column", children: [
3947
+ "\u25B6",
3948
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "shg-colrun-label", children: " Run" })
3949
+ ] }),
3950
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { className: "shg-colmenu-btn", onClick: (e) => onMenu(e), title: "Column settings", children: "\u22EF" })
2941
3951
  ] }),
2942
- menuOpen && !readOnly && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
3952
+ menuOpen && !readOnly && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2943
3953
  ColumnMenu,
2944
3954
  {
2945
3955
  col,
2946
3956
  columns,
2947
3957
  anchor: menuAnchor,
2948
- columnTypes,
2949
- renderColumnConfig,
2950
3958
  onApply: (patch) => {
2951
3959
  onConfigure(col.id, patch);
2952
3960
  onCloseMenu();
@@ -2957,30 +3965,130 @@ function ColumnHeader({
2957
3965
  )
2958
3966
  ] });
2959
3967
  }
2960
- function ColumnMenu({ col, columns, anchor, columnTypes, renderColumnConfig, onApply, onDelete, onClose }) {
2961
- const [type, setType] = (0, import_react15.useState)(col.type || "text");
2962
- const [optText, setOptText] = (0, import_react15.useState)(
2963
- normOptions(col.options).map((o) => o.label).join("\n")
2964
- );
3968
+ function ValuePills({ values, onChange }) {
3969
+ const [text, setText] = (0, import_react17.useState)("");
3970
+ const [picking, setPicking] = (0, import_react17.useState)(null);
3971
+ const add = () => {
3972
+ const label = text.trim();
3973
+ if (!label) return;
3974
+ if (!values.some((v) => sameValue(v.label, label))) onChange([...values, { label }]);
3975
+ setText("");
3976
+ };
3977
+ const remove = (i) => {
3978
+ onChange(values.filter((_, j) => j !== i));
3979
+ setPicking(null);
3980
+ };
3981
+ const paint = (i, color) => {
3982
+ onChange(values.map((v, j) => j === i ? { ...v, color } : v));
3983
+ setPicking(null);
3984
+ };
3985
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "shg-values", onClick: (e) => {
3986
+ if (e.target === e.currentTarget) e.currentTarget.querySelector("input")?.focus();
3987
+ }, children: [
3988
+ values.map((v, i) => /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("span", { className: "shg-value", children: [
3989
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
3990
+ "button",
3991
+ {
3992
+ type: "button",
3993
+ className: "shg-pill shg-pill-btn",
3994
+ style: { background: v.color || PILL_FALLBACKS[i % PILL_FALLBACKS.length] },
3995
+ title: "Pick a color",
3996
+ "aria-expanded": picking === i,
3997
+ onClick: (e) => {
3998
+ e.stopPropagation();
3999
+ setPicking(picking === i ? null : i);
4000
+ },
4001
+ children: [
4002
+ v.label,
4003
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
4004
+ "span",
4005
+ {
4006
+ className: "shg-value-x",
4007
+ role: "button",
4008
+ "aria-label": `Remove ${v.label}`,
4009
+ onClick: (e) => {
4010
+ e.stopPropagation();
4011
+ remove(i);
4012
+ },
4013
+ children: "\xD7"
4014
+ }
4015
+ )
4016
+ ]
4017
+ }
4018
+ ),
4019
+ picking === i && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "shg-swatches", role: "listbox", "aria-label": `Color for ${v.label}`, children: PILL_PALETTE.map((p) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
4020
+ "button",
4021
+ {
4022
+ type: "button",
4023
+ role: "option",
4024
+ "aria-selected": v.color === p.color,
4025
+ className: "shg-swatch" + (v.color === p.color ? " on" : ""),
4026
+ style: { background: p.color },
4027
+ title: p.name,
4028
+ onClick: (e) => {
4029
+ e.stopPropagation();
4030
+ paint(i, p.color);
4031
+ }
4032
+ },
4033
+ p.name
4034
+ )) })
4035
+ ] }, v.label)),
4036
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
4037
+ "input",
4038
+ {
4039
+ className: "shg-values-input",
4040
+ value: text,
4041
+ placeholder: values.length ? "" : "Type a value, press Enter",
4042
+ onChange: (e) => setText(e.target.value),
4043
+ onKeyDown: (e) => {
4044
+ if (e.key === "Enter" || e.key === ",") {
4045
+ e.preventDefault();
4046
+ add();
4047
+ } else if (e.key === "Backspace" && !text && values.length) remove(values.length - 1);
4048
+ },
4049
+ onBlur: add
4050
+ }
4051
+ )
4052
+ ] });
4053
+ }
4054
+ function ColumnMenu({ col, columns, anchor, onApply, onDelete, onClose }) {
4055
+ const [type, setType] = (0, import_react17.useState)(col.type || "text");
4056
+ const [values, setValues] = (0, import_react17.useState)(() => (col.options || []).map((o) => typeof o === "string" ? { label: o } : { label: o.label ?? String(o.value ?? ""), ...o.color ? { color: o.color } : {} }));
2965
4057
  const comp = col.compute || {};
2966
- const [kind, setKind] = (0, import_react15.useState)(comp.kind || "prompt");
2967
- const [prompt, setPrompt] = (0, import_react15.useState)(comp.prompt || "");
2968
- const [harnessId, setHarnessId] = (0, import_react15.useState)(comp.harness_id || "");
2969
- const [wfSlug, setWfSlug] = (0, import_react15.useState)(comp.workflow_slug || "");
2970
- const [outKey, setOutKey] = (0, import_react15.useState)(comp.output_key || "");
2971
- const [deps, setDeps] = (0, import_react15.useState)(new Set(comp.deps || []));
2972
- const others = columns.filter((c) => c.id !== col.id);
2973
- const toggleDep = (id) => setDeps((s) => {
2974
- const n = new Set(s);
2975
- if (n.has(id)) n.delete(id);
2976
- else n.add(id);
2977
- return n;
2978
- });
4058
+ const [kind, setKind] = (0, import_react17.useState)(comp.kind || "prompt");
4059
+ const [prompt, setPrompt] = (0, import_react17.useState)(comp.prompt || "");
4060
+ const [harnessId, setHarnessId] = (0, import_react17.useState)(comp.harness_id || "");
4061
+ const [wfSlug, setWfSlug] = (0, import_react17.useState)(comp.workflow_slug || "");
4062
+ const [outKey, setOutKey] = (0, import_react17.useState)(comp.output_key || "");
4063
+ const [deps, setDeps] = (0, import_react17.useState)(new Set(comp.deps || []));
4064
+ const ref = (0, import_react17.useRef)(null);
4065
+ (0, import_react17.useEffect)(() => {
4066
+ const onDown = (e) => {
4067
+ if (ref.current && !ref.current.contains(e.target) && !(e.target.closest && e.target.closest(".uic-pop"))) onClose();
4068
+ };
4069
+ window.addEventListener("mousedown", onDown);
4070
+ return () => window.removeEventListener("mousedown", onDown);
4071
+ }, [onClose]);
4072
+ const promptItems = (0, import_react17.useMemo)(() => {
4073
+ const at = columns.findIndex((c) => c.id === col.id);
4074
+ return columns.filter((c) => c.id !== col.id).map((c) => {
4075
+ const idx = columns.findIndex((x) => x.id === c.id);
4076
+ const right = at >= 0 && idx > at;
4077
+ return {
4078
+ id: c.id,
4079
+ name: c.name,
4080
+ kind: c.type,
4081
+ section: right ? "Fills after this column" : "Columns",
4082
+ icon: TYPE_GLYPH[c.type] || "Aa",
4083
+ description: TYPE_LABEL[c.type] || c.type,
4084
+ color: c.type === "compute" ? "#7C3AED" : void 0,
4085
+ disabled: right ? "to the right" : false
4086
+ };
4087
+ });
4088
+ }, [columns, col.id]);
2979
4089
  const apply = () => {
2980
4090
  const patch = { type };
2981
- if (type === "select" || type === "tags") {
2982
- patch.options = optText.split("\n").map((s) => s.trim()).filter(Boolean);
2983
- }
4091
+ patch.options = values.map((v) => v.color ? { label: v.label, color: v.color } : v.label);
2984
4092
  if (type === "compute") {
2985
4093
  const compute = { kind, deps: [...deps] };
2986
4094
  if (kind === "prompt") compute.prompt = prompt;
@@ -2996,147 +4104,93 @@ function ColumnMenu({ col, columns, anchor, columnTypes, renderColumnConfig, onA
2996
4104
  }
2997
4105
  onApply(patch);
2998
4106
  };
2999
- const custom = renderColumnConfig && renderColumnConfig({
3000
- column: col,
3001
- columns,
3002
- type,
3003
- applyPatch: (patch) => onApply({ type, ...patch }),
3004
- deleteColumn: onDelete,
3005
- close: onClose
3006
- });
3007
- const desc = columnTypes.find((t) => t.type === type) || {};
3008
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
3009
- PopPortal,
3010
- {
3011
- anchor,
3012
- width: desc.configWidth || 250,
3013
- estHeight: desc.configHeight || 340,
3014
- className: "shg-menu",
3015
- onClose,
3016
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { onClick: (e) => e.stopPropagation(), children: [
3017
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("label", { className: "shg-menu-lbl", children: [
3018
- "Type",
3019
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("select", { className: "shg-menu-input", value: type, onChange: (e) => setType(e.target.value), children: columnTypes.map((t) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("option", { value: t.type, children: t.label }, t.type)) })
3020
- ] }),
3021
- (type === "select" || type === "tags") && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("label", { className: "shg-menu-lbl", children: [
3022
- "Options (one per line)",
3023
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
3024
- "textarea",
3025
- {
3026
- className: "shg-menu-input",
3027
- rows: 3,
3028
- value: optText,
3029
- onChange: (e) => setOptText(e.target.value),
3030
- placeholder: "Todo\nDoing\nDone"
3031
- }
3032
- )
4107
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(PopPortal, { anchor, width: 250, estHeight: 340, className: "shg-menu", onClose, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { ref, onClick: (e) => e.stopPropagation(), children: [
4108
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("label", { className: "shg-menu-lbl", children: [
4109
+ "Type",
4110
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("select", { className: "shg-menu-input", value: type, onChange: (e) => setType(e.target.value), children: [
4111
+ MANUAL_TYPES.map((t) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("option", { value: t, children: TYPE_LABEL[t] }, t)),
4112
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("option", { value: "compute", children: "Computed" })
4113
+ ] })
4114
+ ] }),
4115
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "shg-menu-lbl", children: [
4116
+ type === "select" || type === "tags" ? "Options" : "Values",
4117
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ValuePills, { values, onChange: setValues })
4118
+ ] }),
4119
+ type === "compute" && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
4120
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("label", { className: "shg-menu-lbl", children: [
4121
+ "Runs",
4122
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("select", { className: "shg-menu-input", value: kind, onChange: (e) => setKind(e.target.value), children: COMPUTE_KINDS.map((k) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("option", { value: k.kind, children: k.label }, k.kind)) })
4123
+ ] }),
4124
+ (kind === "prompt" || kind === "harness") && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "shg-menu-lbl", children: [
4125
+ "Prompt",
4126
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "shg-menu-input shg-menu-prompt", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
4127
+ MentionInput,
4128
+ {
4129
+ value: prompt,
4130
+ onChange: (v, ms) => {
4131
+ setPrompt(v);
4132
+ setDeps(new Set(ms.map((m) => m.id)));
4133
+ },
4134
+ items: promptItems,
4135
+ placeholder: "Summarize @Company in one line",
4136
+ menuTitle: "Columns this cell can read",
4137
+ emptyText: "No column by that name",
4138
+ label: "Prompt"
4139
+ }
4140
+ ) }),
4141
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "shg-menu-hint", children: "Type @ to add a column from this row. Columns to the left fill first." })
4142
+ ] }),
4143
+ kind === "harness" && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("label", { className: "shg-menu-lbl", children: [
4144
+ "Agent id",
4145
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("input", { className: "shg-menu-input", value: harnessId, onChange: (e) => setHarnessId(e.target.value), placeholder: "chrn_\u2026" })
4146
+ ] }),
4147
+ kind === "workflow" && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
4148
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("label", { className: "shg-menu-lbl", children: [
4149
+ "Workflow id",
4150
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("input", { className: "shg-menu-input", value: wfSlug, onChange: (e) => setWfSlug(e.target.value), placeholder: "my-workflow" })
3033
4151
  ] }),
3034
- custom !== void 0 ? custom : /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
3035
- type === "compute" && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
3036
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("label", { className: "shg-menu-lbl", children: [
3037
- "Runs",
3038
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("select", { className: "shg-menu-input", value: kind, onChange: (e) => setKind(e.target.value), children: COMPUTE_KINDS.map((k) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("option", { value: k.kind, children: k.label }, k.kind)) })
3039
- ] }),
3040
- (kind === "prompt" || kind === "harness") && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("label", { className: "shg-menu-lbl", children: [
3041
- "Prompt \u2014 reference columns as ",
3042
- "{{Name}}",
3043
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
3044
- "textarea",
3045
- {
3046
- className: "shg-menu-input",
3047
- rows: 3,
3048
- value: prompt,
3049
- onChange: (e) => setPrompt(e.target.value),
3050
- placeholder: "Summarize {{Company}} in one line"
3051
- }
3052
- )
3053
- ] }),
3054
- kind === "harness" && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("label", { className: "shg-menu-lbl", children: [
3055
- "Agent id",
3056
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("input", { className: "shg-menu-input", value: harnessId, onChange: (e) => setHarnessId(e.target.value), placeholder: "chrn_\u2026" })
3057
- ] }),
3058
- kind === "workflow" && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
3059
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("label", { className: "shg-menu-lbl", children: [
3060
- "Workflow id",
3061
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("input", { className: "shg-menu-input", value: wfSlug, onChange: (e) => setWfSlug(e.target.value), placeholder: "my-workflow" })
3062
- ] }),
3063
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("label", { className: "shg-menu-lbl", children: [
3064
- "Output key (optional)",
3065
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("input", { className: "shg-menu-input", value: outKey, onChange: (e) => setOutKey(e.target.value), placeholder: "summary" })
3066
- ] })
3067
- ] }),
3068
- others.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "shg-menu-lbl", children: [
3069
- "Reads columns",
3070
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "shg-menu-deps", children: others.map((c) => /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("label", { className: "shg-menu-dep", children: [
3071
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("input", { type: "checkbox", checked: deps.has(c.id), onChange: () => toggleDep(c.id) }),
3072
- " ",
3073
- c.name
3074
- ] }, c.id)) })
3075
- ] })
3076
- ] }),
3077
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "shg-menu-actions", children: [
3078
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { className: "shg-menu-del", onClick: onDelete, children: "Delete column" }),
3079
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { className: "shg-menu-apply", onClick: apply, children: "Apply" })
3080
- ] })
4152
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("label", { className: "shg-menu-lbl", children: [
4153
+ "Output key (optional)",
4154
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("input", { className: "shg-menu-input", value: outKey, onChange: (e) => setOutKey(e.target.value), placeholder: "summary" })
3081
4155
  ] })
3082
4156
  ] })
3083
- }
3084
- );
3085
- }
3086
- function fitRowHeights(container, { rowIds, min = 34, max = 320, padding = 12 } = {}) {
3087
- if (!container) return {};
3088
- const out = {};
3089
- const rows = container.querySelectorAll("tr[data-row-id]");
3090
- for (const tr of rows) {
3091
- const id = tr.getAttribute("data-row-id");
3092
- if (rowIds && !rowIds.includes(id)) continue;
3093
- let tallest = 0;
3094
- for (const cell of tr.querySelectorAll("td[data-col-id] .shg-val")) {
3095
- tallest = Math.max(tallest, cell.scrollHeight);
3096
- }
3097
- if (tallest) out[id] = Math.min(max, Math.max(min, Math.round(tallest + padding)));
3098
- }
3099
- return out;
3100
- }
3101
- function defaultCellText(cell) {
3102
- const v = cell?.value;
3103
- if (v == null) return "";
3104
- if (Array.isArray(v)) return v.join(", ");
3105
- if (typeof v === "object") return JSON.stringify(v);
3106
- return String(v);
4157
+ ] }),
4158
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "shg-menu-actions", children: [
4159
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { className: "shg-menu-del", onClick: onDelete, children: "Delete column" }),
4160
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { className: "shg-menu-apply", onClick: apply, children: "Apply" })
4161
+ ] })
4162
+ ] }) });
3107
4163
  }
3108
- function sheetToDelimited(sheet, sep = ",", { cellText = defaultCellText } = {}) {
4164
+ function sheetToDelimited(sheet, sep = ",") {
3109
4165
  const cols = sheet?.columns || [];
3110
4166
  const rows = sheet?.rows || [];
3111
4167
  const cells = sheet?.cells || {};
3112
- const esc = (s) => {
4168
+ const esc = (v) => {
4169
+ const s = v == null ? "" : Array.isArray(v) ? v.join(", ") : typeof v === "object" ? JSON.stringify(v) : String(v);
3113
4170
  if (sep === "," && /[",\n]/.test(s)) return `"${s.replace(/"/g, '""')}"`;
3114
4171
  return s;
3115
4172
  };
3116
4173
  const header = cols.map((c) => esc(c.name)).join(sep);
3117
- const body = rows.map((r) => cols.map((c) => esc(String(cellText(cells[cellKey(r.id, c.id)], c) ?? ""))).join(sep));
4174
+ const body = rows.map((r) => cols.map((c) => {
4175
+ const cell = cells[cellKey(r.id, c.id)];
4176
+ return esc(cell ? cell.value : "");
4177
+ }).join(sep));
3118
4178
  return [header, ...body].join("\n");
3119
4179
  }
3120
- function defaultCellValue(cell) {
3121
- const v = cell?.value;
3122
- if (v == null) return "";
3123
- if (Array.isArray(v)) return v.join(", ");
3124
- if (typeof v === "object") return JSON.stringify(v);
3125
- return v;
3126
- }
3127
- function sheetToAoA(sheet, { cellText = defaultCellValue } = {}) {
4180
+ function sheetToAoA(sheet) {
3128
4181
  const cols = sheet?.columns || [];
3129
4182
  const rows = sheet?.rows || [];
3130
4183
  const cells = sheet?.cells || {};
4184
+ const val = (v) => v == null ? "" : Array.isArray(v) ? v.join(", ") : typeof v === "object" ? JSON.stringify(v) : v;
3131
4185
  return [
3132
4186
  cols.map((c) => c.name),
3133
- ...rows.map((r) => cols.map((c) => cellText(cells[cellKey(r.id, c.id)], c) ?? ""))
4187
+ ...rows.map((r) => cols.map((c) => val(cells[cellKey(r.id, c.id)]?.value)))
3134
4188
  ];
3135
4189
  }
3136
4190
 
3137
4191
  // src/components/FileTypeIcon.jsx
3138
- var import_react16 = require("react");
3139
- var import_jsx_runtime14 = require("react/jsx-runtime");
4192
+ var import_react18 = require("react");
4193
+ var import_jsx_runtime16 = require("react/jsx-runtime");
3140
4194
  function extOf(name) {
3141
4195
  const m = String(name || "").toLowerCase().match(/\.([a-z0-9]+)$/);
3142
4196
  return m ? m[1] : "";
@@ -3144,9 +4198,9 @@ function extOf(name) {
3144
4198
  var mod = null;
3145
4199
  var tried = false;
3146
4200
  function FileTypeIcon({ name, size = 36 }) {
3147
- const [, force] = (0, import_react16.useState)(0);
4201
+ const [, force] = (0, import_react18.useState)(0);
3148
4202
  const ext = extOf(name);
3149
- (0, import_react16.useEffect)(() => {
4203
+ (0, import_react18.useEffect)(() => {
3150
4204
  if (tried || mod) return;
3151
4205
  tried = true;
3152
4206
  import("react-file-icon").then((m) => {
@@ -3157,15 +4211,15 @@ function FileTypeIcon({ name, size = 36 }) {
3157
4211
  }, []);
3158
4212
  const box = { width: size, height: Math.round(size * 1.16), display: "inline-block", flex: "0 0 auto" };
3159
4213
  if (!mod) {
3160
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "uic-fileglyph", style: box, "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "uic-fileglyph-ext", children: (ext || "file").slice(0, 4) }) });
4214
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "uic-fileglyph", style: box, "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "uic-fileglyph-ext", children: (ext || "file").slice(0, 4) }) });
3161
4215
  }
3162
4216
  const { FileIcon, defaultStyles } = mod;
3163
4217
  const style = defaultStyles?.[ext] || {};
3164
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { style: box, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(FileIcon, { extension: ext || void 0, ...style }) });
4218
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { style: box, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(FileIcon, { extension: ext || void 0, ...style }) });
3165
4219
  }
3166
4220
 
3167
4221
  // src/components/FileCard.jsx
3168
- var import_jsx_runtime15 = require("react/jsx-runtime");
4222
+ var import_jsx_runtime17 = require("react/jsx-runtime");
3169
4223
  function subtitle(name, origin, bytes) {
3170
4224
  const parts = [(extOf(name) || "file").toUpperCase()];
3171
4225
  if (origin) parts.push(origin);
@@ -3183,7 +4237,7 @@ function FileCard({ name, origin = "output", bytes, onPreview, onDownload, class
3183
4237
  e.stopPropagation();
3184
4238
  onPreview();
3185
4239
  } : void 0;
3186
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
4240
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
3187
4241
  "div",
3188
4242
  {
3189
4243
  className: "uic-filecard" + (open ? " is-clickable" : "") + (className ? " " + className : ""),
@@ -3198,12 +4252,12 @@ function FileCard({ name, origin = "output", bytes, onPreview, onDownload, class
3198
4252
  } : void 0,
3199
4253
  title: name,
3200
4254
  children: [
3201
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "uic-filecard-ic", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(FileTypeIcon, { name, size: 32 }) }),
3202
- /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("span", { className: "uic-filecard-meta", children: [
3203
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "uic-filecard-name", children: name }),
3204
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "uic-filecard-sub", children: subtitle(name, origin, bytes) })
4255
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "uic-filecard-ic", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(FileTypeIcon, { name, size: 32 }) }),
4256
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("span", { className: "uic-filecard-meta", children: [
4257
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "uic-filecard-name", children: name }),
4258
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "uic-filecard-sub", children: subtitle(name, origin, bytes) })
3205
4259
  ] }),
3206
- onDownload && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
4260
+ onDownload && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
3207
4261
  "button",
3208
4262
  {
3209
4263
  type: "button",
@@ -3214,18 +4268,18 @@ function FileCard({ name, origin = "output", bytes, onPreview, onDownload, class
3214
4268
  e.stopPropagation();
3215
4269
  onDownload();
3216
4270
  },
3217
- children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(IcDownload, { size: 18 })
4271
+ children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(IcDownload, { size: 18 })
3218
4272
  }
3219
4273
  ),
3220
- onPreview && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { type: "button", className: "uic-filecard-open", "aria-label": `Preview ${name}`, onClick: open, children: "Preview" })
4274
+ onPreview && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("button", { type: "button", className: "uic-filecard-open", "aria-label": `Preview ${name}`, onClick: open, children: "Preview" })
3221
4275
  ]
3222
4276
  }
3223
4277
  );
3224
4278
  }
3225
4279
 
3226
4280
  // src/components/FilePreview.jsx
3227
- var import_react17 = require("react");
3228
- var import_jsx_runtime16 = require("react/jsx-runtime");
4281
+ var import_react19 = require("react");
4282
+ var import_jsx_runtime18 = require("react/jsx-runtime");
3229
4283
  var LANG = {
3230
4284
  js: "javascript",
3231
4285
  mjs: "javascript",
@@ -3301,11 +4355,11 @@ function delimitedToRows(text, sep) {
3301
4355
  });
3302
4356
  }
3303
4357
  function Grid({ rows }) {
3304
- if (!rows?.length) return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "uic-fp-empty", children: "This file is empty." });
4358
+ if (!rows?.length) return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "uic-fp-empty", children: "This file is empty." });
3305
4359
  const [head, ...body] = rows;
3306
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "uic-fp-sheet", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("table", { children: [
3307
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("tr", { children: head.map((c, i) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("th", { children: c }, i)) }) }),
3308
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("tbody", { children: body.map((r, i) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("tr", { children: r.map((c, j) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("td", { children: c }, j)) }, i)) })
4360
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "uic-fp-sheet", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("table", { children: [
4361
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("tr", { children: head.map((c, i) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("th", { children: c }, i)) }) }),
4362
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("tbody", { children: body.map((r, i) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("tr", { children: r.map((c, j) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("td", { children: c }, j)) }, i)) })
3309
4363
  ] }) });
3310
4364
  }
3311
4365
  var defaultDownload = (url, name) => {
@@ -3328,9 +4382,9 @@ function FilePreview({
3328
4382
  title
3329
4383
  }) {
3330
4384
  const { url, name } = file || {};
3331
- const [st, setSt] = (0, import_react17.useState)({ kind: "loading" });
3332
- const [tab, setTab] = (0, import_react17.useState)(0);
3333
- (0, import_react17.useEffect)(() => {
4385
+ const [st, setSt] = (0, import_react19.useState)({ kind: "loading" });
4386
+ const [tab, setTab] = (0, import_react19.useState)(0);
4387
+ (0, import_react19.useEffect)(() => {
3334
4388
  if (!url) return void 0;
3335
4389
  let alive = true;
3336
4390
  let obj;
@@ -3392,11 +4446,11 @@ function FilePreview({
3392
4446
  };
3393
4447
  }, [url, name, fetchFile, officePdfUrl, parseWorkbook]);
3394
4448
  const download = () => onDownload ? onDownload(url, name) : defaultDownload(url, name);
3395
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("aside", { className: "uic-fp", "aria-label": title || `Preview of ${name}`, children: [
3396
- /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("header", { className: "uic-fp-head", children: [
3397
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "uic-fp-ic", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(FileTypeIcon, { name, size: 20 }) }),
3398
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "uic-fp-name", title: name, children: name }),
3399
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
4449
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("aside", { className: "uic-fp", "aria-label": title || `Preview of ${name}`, children: [
4450
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("header", { className: "uic-fp-head", children: [
4451
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "uic-fp-ic", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(FileTypeIcon, { name, size: 20 }) }),
4452
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "uic-fp-name", title: name, children: name }),
4453
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
3400
4454
  "button",
3401
4455
  {
3402
4456
  type: "button",
@@ -3404,10 +4458,10 @@ function FilePreview({
3404
4458
  "aria-label": `Download ${name}`,
3405
4459
  title: "Download",
3406
4460
  onClick: download,
3407
- children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(IcDownload, {})
4461
+ children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(IcDownload, {})
3408
4462
  }
3409
4463
  ),
3410
- onClose && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
4464
+ onClose && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
3411
4465
  "button",
3412
4466
  {
3413
4467
  type: "button",
@@ -3415,22 +4469,22 @@ function FilePreview({
3415
4469
  "aria-label": "Close preview",
3416
4470
  title: "Close",
3417
4471
  onClick: onClose,
3418
- children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(IcX, { size: 18 })
4472
+ children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(IcX, { size: 18 })
3419
4473
  }
3420
4474
  )
3421
4475
  ] }),
3422
- /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "uic-fp-body", children: [
3423
- st.kind === "loading" && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "uic-fp-pad", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "uic-skel uic-fp-skel" }) }),
3424
- st.kind === "image" && st.objUrl && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "uic-fp-center", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("img", { className: "uic-fp-img", src: st.objUrl, alt: name }) }),
3425
- st.kind === "pdf" && st.objUrl && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("iframe", { className: "uic-fp-frame", src: st.objUrl, title: name }),
3426
- st.kind === "video" && st.objUrl && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "uic-fp-center", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("video", { className: "uic-fp-media", src: st.objUrl, controls: true }) }),
3427
- st.kind === "audio" && st.objUrl && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "uic-fp-center", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("audio", { src: st.objUrl, controls: true }) }),
3428
- st.kind === "markdown" && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "uic-fp-doc", children: renderMarkdown ? renderMarkdown(st.text || "") : /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("pre", { className: "uic-fp-pre", children: st.text }) }),
3429
- st.kind === "code" && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(CodeBlock, { code: st.text || "", lang: LANG[extOf(name)] || "plaintext" }),
3430
- st.kind === "csv" && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Grid, { rows: st.rows }),
3431
- st.kind === "sheet" && st.sheets && /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "uic-fp-xlsx", children: [
3432
- st.sheets[tab]?.filled ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Grid, { rows: st.sheets[tab].rows }) : /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "uic-fp-empty", children: "This sheet is empty." }),
3433
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "uic-fp-tabs", children: st.sheets.map((s, i) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
4476
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "uic-fp-body", children: [
4477
+ st.kind === "loading" && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "uic-fp-pad", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "uic-skel uic-fp-skel" }) }),
4478
+ st.kind === "image" && st.objUrl && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "uic-fp-center", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("img", { className: "uic-fp-img", src: st.objUrl, alt: name }) }),
4479
+ st.kind === "pdf" && st.objUrl && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("iframe", { className: "uic-fp-frame", src: st.objUrl, title: name }),
4480
+ st.kind === "video" && st.objUrl && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "uic-fp-center", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("video", { className: "uic-fp-media", src: st.objUrl, controls: true }) }),
4481
+ st.kind === "audio" && st.objUrl && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "uic-fp-center", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("audio", { src: st.objUrl, controls: true }) }),
4482
+ st.kind === "markdown" && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "uic-fp-doc", children: renderMarkdown ? renderMarkdown(st.text || "") : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("pre", { className: "uic-fp-pre", children: st.text }) }),
4483
+ st.kind === "code" && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(CodeBlock, { code: st.text || "", lang: LANG[extOf(name)] || "plaintext" }),
4484
+ st.kind === "csv" && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(Grid, { rows: st.rows }),
4485
+ st.kind === "sheet" && st.sheets && /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "uic-fp-xlsx", children: [
4486
+ st.sheets[tab]?.filled ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(Grid, { rows: st.sheets[tab].rows }) : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "uic-fp-empty", children: "This sheet is empty." }),
4487
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "uic-fp-tabs", children: st.sheets.map((s, i) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
3434
4488
  "button",
3435
4489
  {
3436
4490
  type: "button",
@@ -3442,40 +4496,40 @@ function FilePreview({
3442
4496
  s.name + i
3443
4497
  )) })
3444
4498
  ] }),
3445
- st.kind === "binary" && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "uic-fp-center", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "uic-fp-fallback", children: [
3446
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(FileTypeIcon, { name, size: 56 }),
3447
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("p", { children: st.error || "No inline preview for this file type." }),
3448
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("button", { type: "button", className: "uic-fp-dl", onClick: download, children: "Download" })
4499
+ st.kind === "binary" && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "uic-fp-center", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "uic-fp-fallback", children: [
4500
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(FileTypeIcon, { name, size: 56 }),
4501
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("p", { children: st.error || "No inline preview for this file type." }),
4502
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("button", { type: "button", className: "uic-fp-dl", onClick: download, children: "Download" })
3449
4503
  ] }) })
3450
4504
  ] })
3451
4505
  ] });
3452
4506
  }
3453
4507
 
3454
4508
  // src/components/form.jsx
3455
- var import_react18 = require("react");
3456
- var import_jsx_runtime17 = require("react/jsx-runtime");
4509
+ var import_react20 = require("react");
4510
+ var import_jsx_runtime19 = require("react/jsx-runtime");
3457
4511
  function Field({ label, hint, error, htmlFor, required, children, className = "" }) {
3458
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "uic-field" + (error ? " is-error" : "") + (className ? " " + className : ""), children: [
3459
- label && /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("label", { className: "uic-field-label", htmlFor, children: [
4512
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "uic-field" + (error ? " is-error" : "") + (className ? " " + className : ""), children: [
4513
+ label && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("label", { className: "uic-field-label", htmlFor, children: [
3460
4514
  label,
3461
- required && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "uic-field-req", "aria-hidden": "true", children: "*" })
4515
+ required && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "uic-field-req", "aria-hidden": "true", children: "*" })
3462
4516
  ] }),
3463
4517
  children,
3464
- error ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("p", { className: "uic-field-err", children: error }) : hint ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("p", { className: "uic-field-hint", children: hint }) : null
4518
+ error ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("p", { className: "uic-field-err", children: error }) : hint ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("p", { className: "uic-field-hint", children: hint }) : null
3465
4519
  ] });
3466
4520
  }
3467
4521
  function withField(Control) {
3468
4522
  return function Fielded({ label, hint, error, required, id, className, ...rest }) {
3469
- const auto = (0, import_react18.useId)();
4523
+ const auto = (0, import_react20.useId)();
3470
4524
  const inputId = id || auto;
3471
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Field, { label, hint, error, required, htmlFor: inputId, className, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Control, { id: inputId, invalid: !!error, required, ...rest }) });
4525
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Field, { label, hint, error, required, htmlFor: inputId, className, children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Control, { id: inputId, invalid: !!error, required, ...rest }) });
3472
4526
  };
3473
4527
  }
3474
4528
  function BareInput({ invalid, ...rest }) {
3475
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("input", { className: "uic-input" + (invalid ? " is-error" : ""), "aria-invalid": invalid || void 0, ...rest });
4529
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("input", { className: "uic-input" + (invalid ? " is-error" : ""), "aria-invalid": invalid || void 0, ...rest });
3476
4530
  }
3477
4531
  function BareTextarea({ invalid, rows = 4, ...rest }) {
3478
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
4532
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
3479
4533
  "textarea",
3480
4534
  {
3481
4535
  className: "uic-input uic-textarea" + (invalid ? " is-error" : ""),
@@ -3486,44 +4540,44 @@ function BareTextarea({ invalid, rows = 4, ...rest }) {
3486
4540
  );
3487
4541
  }
3488
4542
  function BareSelect({ invalid, options = [], placeholder, ...rest }) {
3489
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("span", { className: "uic-select-wrap", children: [
3490
- /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
4543
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("span", { className: "uic-select-wrap", children: [
4544
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
3491
4545
  "select",
3492
4546
  {
3493
4547
  className: "uic-input uic-select" + (invalid ? " is-error" : ""),
3494
4548
  "aria-invalid": invalid || void 0,
3495
4549
  ...rest,
3496
4550
  children: [
3497
- placeholder && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("option", { value: "", children: placeholder }),
4551
+ placeholder && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("option", { value: "", children: placeholder }),
3498
4552
  options.map((o) => {
3499
4553
  const opt = typeof o === "string" ? { value: o, label: o } : o;
3500
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("option", { value: opt.value, disabled: opt.disabled, children: opt.label }, opt.value);
4554
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("option", { value: opt.value, disabled: opt.disabled, children: opt.label }, opt.value);
3501
4555
  })
3502
4556
  ]
3503
4557
  }
3504
4558
  ),
3505
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "uic-select-chev", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Chevron, { dir: "down", size: 14 }) })
4559
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "uic-select-chev", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Chevron, { dir: "down", size: 14 }) })
3506
4560
  ] });
3507
4561
  }
3508
4562
  var Input = withField(BareInput);
3509
4563
  var Textarea = withField(BareTextarea);
3510
4564
  var Select = withField(BareSelect);
3511
4565
  function FormActions({ children, align = "end", className = "" }) {
3512
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: `uic-form-actions is-${align}${className ? " " + className : ""}`, children });
4566
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: `uic-form-actions is-${align}${className ? " " + className : ""}`, children });
3513
4567
  }
3514
4568
  function Button({ variant = "default", size = "md", type = "button", className = "", ...rest }) {
3515
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("button", { type, className: `uic-btn is-${variant} is-${size}${className ? " " + className : ""}`, ...rest });
4569
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("button", { type, className: `uic-btn is-${variant} is-${size}${className ? " " + className : ""}`, ...rest });
3516
4570
  }
3517
4571
 
3518
4572
  // src/components/Carousel.jsx
3519
- var import_react19 = __toESM(require("react"), 1);
3520
- var import_jsx_runtime18 = require("react/jsx-runtime");
4573
+ var import_react21 = __toESM(require("react"), 1);
4574
+ var import_jsx_runtime20 = require("react/jsx-runtime");
3521
4575
  var EDGE = 2;
3522
4576
  function Carousel(props) {
3523
4577
  const { label, step, children, classNames = {} } = props;
3524
- const ref = (0, import_react19.useRef)(null);
3525
- const [edges, setEdges] = (0, import_react19.useState)({ start: true, end: true, overflow: false });
3526
- const measure = (0, import_react19.useCallback)(() => {
4578
+ const ref = (0, import_react21.useRef)(null);
4579
+ const [edges, setEdges] = (0, import_react21.useState)({ start: true, end: true, overflow: false });
4580
+ const measure = (0, import_react21.useCallback)(() => {
3527
4581
  const el = ref.current;
3528
4582
  if (!el) return;
3529
4583
  const overflow = el.scrollWidth - el.clientWidth > EDGE;
@@ -3533,7 +4587,7 @@ function Carousel(props) {
3533
4587
  end: el.scrollLeft >= el.scrollWidth - el.clientWidth - EDGE
3534
4588
  });
3535
4589
  }, []);
3536
- (0, import_react19.useEffect)(() => {
4590
+ (0, import_react21.useEffect)(() => {
3537
4591
  const el = ref.current;
3538
4592
  if (!el) return void 0;
3539
4593
  measure();
@@ -3547,8 +4601,8 @@ function Carousel(props) {
3547
4601
  if (!el) return;
3548
4602
  el.scrollBy({ left: dir * (step || Math.round(el.clientWidth * 0.9)), behavior: "smooth" });
3549
4603
  };
3550
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: ["uic-carousel-wrap", classNames.root || ""].filter(Boolean).join(" "), children: [
3551
- edges.overflow ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
4604
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: ["uic-carousel-wrap", classNames.root || ""].filter(Boolean).join(" "), children: [
4605
+ edges.overflow ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3552
4606
  "button",
3553
4607
  {
3554
4608
  type: "button",
@@ -3556,10 +4610,10 @@ function Carousel(props) {
3556
4610
  onClick: () => scroll(-1),
3557
4611
  disabled: edges.start,
3558
4612
  "aria-label": `Scroll ${label} left`,
3559
- children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(Chevron, { dir: "left" })
4613
+ children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Chevron, { dir: "left" })
3560
4614
  }
3561
4615
  ) : null,
3562
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
4616
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3563
4617
  "div",
3564
4618
  {
3565
4619
  className: ["uic-carousel", classNames.viewport || ""].filter(Boolean).join(" "),
@@ -3570,7 +4624,7 @@ function Carousel(props) {
3570
4624
  children
3571
4625
  }
3572
4626
  ),
3573
- edges.overflow ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
4627
+ edges.overflow ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3574
4628
  "button",
3575
4629
  {
3576
4630
  type: "button",
@@ -3578,42 +4632,42 @@ function Carousel(props) {
3578
4632
  onClick: () => scroll(1),
3579
4633
  disabled: edges.end,
3580
4634
  "aria-label": `Scroll ${label} right`,
3581
- children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(Chevron, { dir: "right" })
4635
+ children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Chevron, { dir: "right" })
3582
4636
  }
3583
4637
  ) : null
3584
4638
  ] });
3585
4639
  }
3586
4640
 
3587
4641
  // src/components/Card.jsx
3588
- var import_react20 = __toESM(require("react"), 1);
3589
- var import_jsx_runtime19 = require("react/jsx-runtime");
4642
+ var import_react22 = __toESM(require("react"), 1);
4643
+ var import_jsx_runtime21 = require("react/jsx-runtime");
3590
4644
  function Card(props) {
3591
4645
  const { art, title, subtitle: subtitle2, onClick, selected = false, overlay, actions, classNames = {} } = props;
3592
- const foot = /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("span", { className: "uic-card-foot", children: [
3593
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "uic-card-name", children: title }),
3594
- subtitle2 ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "uic-card-sub", children: subtitle2 }) : null
4646
+ const foot = /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("span", { className: "uic-card-foot", children: [
4647
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: "uic-card-name", children: title }),
4648
+ subtitle2 ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: "uic-card-sub", children: subtitle2 }) : null
3595
4649
  ] });
3596
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: ["uic-card", selected ? "is-selected" : "", classNames.root || ""].filter(Boolean).join(" "), children: [
3597
- onClick ? /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("button", { type: "button", className: "uic-card-main", onClick, "aria-pressed": selected || void 0, children: [
3598
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "uic-card-art", children: art }),
4650
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: ["uic-card", selected ? "is-selected" : "", classNames.root || ""].filter(Boolean).join(" "), children: [
4651
+ onClick ? /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("button", { type: "button", className: "uic-card-main", onClick, "aria-pressed": selected || void 0, children: [
4652
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: "uic-card-art", children: art }),
3599
4653
  foot
3600
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "uic-card-main", children: [
3601
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "uic-card-art", children: art }),
4654
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "uic-card-main", children: [
4655
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: "uic-card-art", children: art }),
3602
4656
  foot
3603
4657
  ] }),
3604
- overlay ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "uic-card-overlay", children: overlay }) : null,
3605
- actions ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "uic-card-actions", children: actions }) : null
4658
+ overlay ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "uic-card-overlay", children: overlay }) : null,
4659
+ actions ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "uic-card-actions", children: actions }) : null
3606
4660
  ] });
3607
4661
  }
3608
4662
 
3609
4663
  // src/components/SearchField.jsx
3610
- var import_react21 = __toESM(require("react"), 1);
3611
- var import_jsx_runtime20 = require("react/jsx-runtime");
4664
+ var import_react23 = __toESM(require("react"), 1);
4665
+ var import_jsx_runtime22 = require("react/jsx-runtime");
3612
4666
  function SearchField(props) {
3613
4667
  const { value, onChange, placeholder, clearLabel = "Clear search", className } = props;
3614
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("label", { className: ["uic-search", className || ""].filter(Boolean).join(" "), children: [
3615
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { className: "uic-search-ic", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(IcSearch, {}) }),
3616
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4668
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("label", { className: ["uic-search", className || ""].filter(Boolean).join(" "), children: [
4669
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("span", { className: "uic-search-ic", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(IcSearch, {}) }),
4670
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
3617
4671
  "input",
3618
4672
  {
3619
4673
  type: "search",
@@ -3623,90 +4677,213 @@ function SearchField(props) {
3623
4677
  onChange: (e) => onChange(e.target.value)
3624
4678
  }
3625
4679
  ),
3626
- value ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("button", { type: "button", className: "uic-search-x", "aria-label": clearLabel, onClick: () => onChange(""), children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(IcX, { size: 12 }) }) : null
4680
+ value ? /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("button", { type: "button", className: "uic-search-x", "aria-label": clearLabel, onClick: () => onChange(""), children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(IcX, { size: 12 }) }) : null
3627
4681
  ] });
3628
4682
  }
3629
4683
 
3630
- // src/components/Popover.jsx
3631
- var import_react22 = __toESM(require("react"), 1);
3632
- var import_react_dom3 = require("react-dom");
3633
- var import_jsx_runtime21 = require("react/jsx-runtime");
3634
- var GAP = 6;
3635
- var MARGIN = 8;
3636
- function Popover(props) {
4684
+ // src/components/CascadeMenu.jsx
4685
+ var import_react24 = __toESM(require("react"), 1);
4686
+ var import_jsx_runtime23 = require("react/jsx-runtime");
4687
+ var Tick = () => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Svg, { s: 14, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("path", { d: "M20 6 9 17l-5-5" }) });
4688
+ var FILTER_PAST = 8;
4689
+ var itemsOf = (groups) => groups.flatMap((g) => g.items);
4690
+ function CascadeMenu(props) {
3637
4691
  const {
3638
4692
  open,
3639
4693
  anchorRef,
3640
4694
  onClose,
3641
- width = 280,
3642
- minHeight = 140,
3643
- placement = "auto",
3644
- children,
4695
+ label,
4696
+ groups = [],
4697
+ optionsOf,
4698
+ onPick,
4699
+ filter = "auto",
4700
+ filterPlaceholder = "Filter",
4701
+ emptyText = "Nothing matches.",
4702
+ noOptionsText = "Nothing to choose here.",
4703
+ optionsLabel = "Options",
4704
+ backLabel = "Back",
4705
+ optionsFooter,
4706
+ width = 520,
4707
+ stackBelow = 560,
3645
4708
  className,
3646
- label
4709
+ value
3647
4710
  } = props;
3648
- const popRef = (0, import_react22.useRef)(null);
3649
- const [pos, setPos] = (0, import_react22.useState)(null);
3650
- (0, import_react22.useEffect)(() => {
3651
- if (!open) {
3652
- setPos(null);
3653
- return void 0;
3654
- }
3655
- const place = () => {
3656
- const el = anchorRef?.current;
3657
- if (!el) return;
3658
- const r = el.getBoundingClientRect();
3659
- const vw = window.innerWidth;
3660
- const vh = window.innerHeight;
3661
- const w = Math.min(width, vw - MARGIN * 2);
3662
- const below = vh - r.bottom - GAP - MARGIN;
3663
- const above = r.top - GAP - MARGIN;
3664
- const up = placement === "above" || placement === "auto" && below < minHeight && above > below;
3665
- const maxHeight = Math.max(minHeight, Math.floor(up ? above : below));
3666
- const left = Math.max(MARGIN, Math.min(r.left, vw - w - MARGIN));
3667
- setPos(up ? { left, bottom: Math.round(vh - r.top + GAP), width: w, maxHeight } : { left, top: Math.round(r.bottom + GAP), width: w, maxHeight });
3668
- };
3669
- place();
3670
- window.addEventListener("resize", place);
3671
- window.addEventListener("scroll", place, true);
3672
- return () => {
3673
- window.removeEventListener("resize", place);
3674
- window.removeEventListener("scroll", place, true);
3675
- };
3676
- }, [open, anchorRef, width, minHeight, placement]);
3677
- (0, import_react22.useEffect)(() => {
4711
+ const rootRef = (0, import_react24.useRef)(null);
4712
+ const [q, setQ] = (0, import_react24.useState)("");
4713
+ const [activeId, setActiveId] = (0, import_react24.useState)(null);
4714
+ const [stage, setStage] = (0, import_react24.useState)("items");
4715
+ const [stacked, setStacked] = (0, import_react24.useState)(false);
4716
+ const visible = (0, import_react24.useMemo)(() => {
4717
+ const needle = q.trim().toLowerCase();
4718
+ if (!needle) return groups.filter((g) => g.items.length > 0);
4719
+ return groups.map((g) => ({ ...g, items: g.items.filter((it) => String(it.label).toLowerCase().includes(needle)) })).filter((g) => g.items.length > 0);
4720
+ }, [groups, q]);
4721
+ const flat = (0, import_react24.useMemo)(() => itemsOf(visible), [visible]);
4722
+ const active = flat.find((it) => it.id === activeId) || flat[0] || null;
4723
+ const options = (0, import_react24.useMemo)(() => active && optionsOf ? optionsOf(active) : [], [active, optionsOf]);
4724
+ const showFilter = filter === true || filter === "auto" && itemsOf(groups).length > FILTER_PAST;
4725
+ (0, import_react24.useEffect)(() => {
3678
4726
  if (!open) return void 0;
3679
- const onDown = (e) => {
3680
- if (popRef.current?.contains(e.target)) return;
3681
- if (anchorRef?.current?.contains(e.target)) return;
3682
- onClose?.();
4727
+ setQ("");
4728
+ setActiveId(value?.item ?? null);
4729
+ setStage("items");
4730
+ const measure = () => setStacked(window.innerWidth < stackBelow);
4731
+ measure();
4732
+ window.addEventListener("resize", measure);
4733
+ const raf = requestAnimationFrame(() => {
4734
+ const first = rootRef.current?.querySelector("input, button:not(:disabled)");
4735
+ first?.focus({ preventScroll: true });
4736
+ });
4737
+ const anchor = anchorRef?.current;
4738
+ return () => {
4739
+ window.removeEventListener("resize", measure);
4740
+ cancelAnimationFrame(raf);
4741
+ anchor?.focus?.({ preventScroll: true });
3683
4742
  };
3684
- document.addEventListener("pointerdown", onDown);
3685
- return () => document.removeEventListener("pointerdown", onDown);
3686
- }, [open, anchorRef, onClose]);
3687
- const escape = (0, import_react22.useCallback)(() => onClose?.(), [onClose]);
3688
- useOverlayEscape(open, escape);
3689
- if (!open || !pos || typeof document === "undefined") return null;
3690
- return (0, import_react_dom3.createPortal)(
3691
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
3692
- "div",
3693
- {
3694
- ref: popRef,
3695
- className: ["uic-pop", className || ""].filter(Boolean).join(" "),
3696
- style: pos,
3697
- role: "dialog",
3698
- "aria-label": label,
3699
- children
4743
+ }, [open, stackBelow]);
4744
+ const focusIn = (0, import_react24.useCallback)((col, index = 0) => {
4745
+ const list = rootRef.current?.querySelectorAll(`.uic-cascade-${col} .uic-pop-item:not(:disabled)`);
4746
+ if (!list || !list.length) return false;
4747
+ const i = Math.max(0, Math.min(index, list.length - 1));
4748
+ list[i].focus({ preventScroll: true });
4749
+ return true;
4750
+ }, []);
4751
+ const enterOptions = (0, import_react24.useCallback)(() => {
4752
+ if (stacked) {
4753
+ setStage("options");
4754
+ requestAnimationFrame(() => focusIn("options"));
4755
+ } else focusIn("options");
4756
+ }, [stacked, focusIn]);
4757
+ const onKey2 = (e) => {
4758
+ const el = document.activeElement;
4759
+ const col = el?.closest?.(".uic-cascade-col");
4760
+ const inItems = col?.classList.contains("uic-cascade-items");
4761
+ const inOptions = col?.classList.contains("uic-cascade-options");
4762
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
4763
+ if (!col) return;
4764
+ const list = Array.from(col.querySelectorAll(".uic-pop-item:not(:disabled)"));
4765
+ const i = list.indexOf(el);
4766
+ const next = i < 0 ? 0 : i + (e.key === "ArrowDown" ? 1 : -1);
4767
+ if (next < 0) {
4768
+ col.querySelector("input")?.focus();
4769
+ e.preventDefault();
4770
+ return;
3700
4771
  }
3701
- ),
3702
- document.body
4772
+ if (next >= list.length) return;
4773
+ e.preventDefault();
4774
+ list[next].focus({ preventScroll: true });
4775
+ } else if (e.key === "ArrowRight" && inItems) {
4776
+ e.preventDefault();
4777
+ enterOptions();
4778
+ } else if (e.key === "ArrowLeft" && inOptions) {
4779
+ e.preventDefault();
4780
+ if (stacked) {
4781
+ setStage("items");
4782
+ requestAnimationFrame(() => focusIn("items", flat.indexOf(active)));
4783
+ } else focusIn("items", flat.indexOf(active));
4784
+ } else if (e.key === "Enter" && el?.tagName === "INPUT") {
4785
+ e.preventDefault();
4786
+ enterOptions();
4787
+ }
4788
+ };
4789
+ const showItems = !stacked || stage === "items";
4790
+ const showOptions = !stacked || stage === "options";
4791
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
4792
+ Popover,
4793
+ {
4794
+ open,
4795
+ anchorRef,
4796
+ onClose,
4797
+ label,
4798
+ width: stacked ? 320 : width,
4799
+ minHeight: 260,
4800
+ className: ["uic-cascade-pop", className || ""].filter(Boolean).join(" "),
4801
+ children: /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { ref: rootRef, className: "uic-cascade" + (stacked ? " is-stacked" : ""), onKeyDown: onKey2, children: [
4802
+ showItems && /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "uic-cascade-col uic-cascade-items", children: [
4803
+ showFilter ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(SearchField, { className: "uic-cascade-filter", value: q, onChange: setQ, placeholder: filterPlaceholder }) : null,
4804
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "uic-pop-list", children: [
4805
+ visible.map((g, gi) => /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(import_react24.Fragment, { children: [
4806
+ g.label ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "uic-cascade-group", children: g.label }) : null,
4807
+ g.items.map((it) => {
4808
+ const on = active?.id === it.id;
4809
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
4810
+ "button",
4811
+ {
4812
+ type: "button",
4813
+ className: "uic-pop-item uic-cascade-item" + (on ? " is-active" : ""),
4814
+ "aria-expanded": on,
4815
+ "aria-haspopup": "true",
4816
+ onFocus: () => setActiveId(it.id),
4817
+ onClick: () => {
4818
+ setActiveId(it.id);
4819
+ enterOptions();
4820
+ },
4821
+ children: [
4822
+ it.icon ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "uic-cascade-ic", "aria-hidden": "true", children: it.icon }) : null,
4823
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "uic-chip-t", children: it.label }),
4824
+ it.note ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "uic-cascade-note", children: it.note }) : null,
4825
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "uic-cascade-chev", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Chevron, { dir: "right", size: 14 }) })
4826
+ ]
4827
+ },
4828
+ it.id
4829
+ );
4830
+ })
4831
+ ] }, g.label || gi)),
4832
+ flat.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "uic-pop-note", children: emptyText }) : null
4833
+ ] })
4834
+ ] }),
4835
+ showOptions && /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "uic-cascade-col uic-cascade-options", role: "group", "aria-label": optionsLabel, children: [
4836
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "uic-cascade-head", children: [
4837
+ stacked ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
4838
+ "button",
4839
+ {
4840
+ type: "button",
4841
+ className: "uic-cascade-back",
4842
+ "aria-label": backLabel,
4843
+ onClick: () => {
4844
+ setStage("items");
4845
+ requestAnimationFrame(() => focusIn("items", flat.indexOf(active)));
4846
+ },
4847
+ children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Chevron, { dir: "left", size: 14 })
4848
+ }
4849
+ ) : null,
4850
+ active?.icon ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "uic-cascade-ic", "aria-hidden": "true", children: active.icon }) : null,
4851
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "uic-chip-t", children: active ? active.label : "" })
4852
+ ] }),
4853
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "uic-pop-list", children: [
4854
+ options.map((o) => {
4855
+ const on = !!value && active?.id === value.item && o.id === value.option;
4856
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
4857
+ "button",
4858
+ {
4859
+ type: "button",
4860
+ className: "uic-pop-item uic-cascade-opt" + (on ? " is-on" : "") + (o.badge ? " has-badge" : ""),
4861
+ "aria-current": on ? "true" : void 0,
4862
+ disabled: !!o.disabled,
4863
+ onClick: () => onPick?.(active, o),
4864
+ children: [
4865
+ value ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "uic-pop-check", "aria-hidden": "true", children: on ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Tick, {}) : null }) : null,
4866
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "uic-chip-t", children: o.label }),
4867
+ o.note ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "uic-cascade-note", children: o.note }) : null,
4868
+ o.badge || null
4869
+ ]
4870
+ },
4871
+ o.id
4872
+ );
4873
+ }),
4874
+ active && options.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "uic-pop-note", children: noOptionsText }) : null
4875
+ ] }),
4876
+ optionsFooter || null
4877
+ ] })
4878
+ ] })
4879
+ }
3703
4880
  );
3704
4881
  }
3705
4882
 
3706
4883
  // src/components/Modal.jsx
3707
- var import_react23 = __toESM(require("react"), 1);
4884
+ var import_react25 = __toESM(require("react"), 1);
3708
4885
  var import_react_dom4 = require("react-dom");
3709
- var import_jsx_runtime22 = require("react/jsx-runtime");
4886
+ var import_jsx_runtime24 = require("react/jsx-runtime");
3710
4887
  function Modal(props) {
3711
4888
  const {
3712
4889
  open,
@@ -3720,10 +4897,10 @@ function Modal(props) {
3720
4897
  children,
3721
4898
  classNames = {}
3722
4899
  } = props;
3723
- const titleId = (0, import_react23.useId)();
3724
- const escape = (0, import_react23.useCallback)(() => onClose?.(), [onClose]);
4900
+ const titleId = (0, import_react25.useId)();
4901
+ const escape = (0, import_react25.useCallback)(() => onClose?.(), [onClose]);
3725
4902
  useOverlayEscape(open, escape);
3726
- (0, import_react23.useEffect)(() => {
4903
+ (0, import_react25.useEffect)(() => {
3727
4904
  if (!open || typeof document === "undefined") return void 0;
3728
4905
  const prev = document.body.style.overflow;
3729
4906
  document.body.style.overflow = "hidden";
@@ -3736,12 +4913,12 @@ function Modal(props) {
3736
4913
  if (e.target === e.currentTarget) onClose?.();
3737
4914
  };
3738
4915
  return (0, import_react_dom4.createPortal)(
3739
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
4916
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
3740
4917
  "div",
3741
4918
  {
3742
4919
  className: ["uic-modal-backdrop", classNames.backdrop || ""].filter(Boolean).join(" "),
3743
4920
  onMouseDown: onBackdrop,
3744
- children: /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(
4921
+ children: /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
3745
4922
  "div",
3746
4923
  {
3747
4924
  className: ["uic-modal", `is-${size}`, classNames.root || ""].filter(Boolean).join(" "),
@@ -3750,15 +4927,15 @@ function Modal(props) {
3750
4927
  "aria-modal": "true",
3751
4928
  "aria-labelledby": labelledBy || (title ? titleId : void 0),
3752
4929
  children: [
3753
- title || actions ? /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: "uic-modal-h", children: [
3754
- /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: "uic-modal-title", children: [
3755
- title ? /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("h3", { id: titleId, children: title }) : null,
3756
- description ? /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("p", { children: description }) : null
4930
+ title || actions ? /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "uic-modal-h", children: [
4931
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "uic-modal-title", children: [
4932
+ title ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("h3", { id: titleId, children: title }) : null,
4933
+ description ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("p", { children: description }) : null
3757
4934
  ] }),
3758
4935
  actions,
3759
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("button", { type: "button", className: "uic-modal-x", "aria-label": "Close", onClick: onClose, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(IcX, { size: 18 }) })
4936
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("button", { type: "button", className: "uic-modal-x", "aria-label": "Close", onClick: onClose, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(IcX, { size: 18 }) })
3760
4937
  ] }) : null,
3761
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: ["uic-modal-b", classNames.body || ""].filter(Boolean).join(" "), children })
4938
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: ["uic-modal-b", classNames.body || ""].filter(Boolean).join(" "), children })
3762
4939
  ]
3763
4940
  }
3764
4941
  )
@@ -3769,15 +4946,15 @@ function Modal(props) {
3769
4946
  }
3770
4947
 
3771
4948
  // src/hooks/useTypewriter.js
3772
- var import_react24 = require("react");
4949
+ var import_react26 = require("react");
3773
4950
  var CHAR_MS = 26;
3774
4951
  var HOLD_MS = 2600;
3775
4952
  function useTypewriter(phrases, { active = true } = {}) {
3776
4953
  const list = phrases && phrases.length ? phrases : [""];
3777
- const [text, setText] = (0, import_react24.useState)(list[0]);
3778
- const listRef = (0, import_react24.useRef)(list);
4954
+ const [text, setText] = (0, import_react26.useState)(list[0]);
4955
+ const listRef = (0, import_react26.useRef)(list);
3779
4956
  listRef.current = list;
3780
- (0, import_react24.useEffect)(() => {
4957
+ (0, import_react26.useEffect)(() => {
3781
4958
  if (!active) return void 0;
3782
4959
  if (typeof window === "undefined") return void 0;
3783
4960
  if (window.matchMedia?.("(prefers-reduced-motion: reduce)")?.matches) {
@@ -3808,7 +4985,7 @@ function useTypewriter(phrases, { active = true } = {}) {
3808
4985
  }
3809
4986
 
3810
4987
  // src/components/Panel.jsx
3811
- var import_jsx_runtime23 = require("react/jsx-runtime");
4988
+ var import_jsx_runtime25 = require("react/jsx-runtime");
3812
4989
  function Panel(props) {
3813
4990
  const {
3814
4991
  title,
@@ -3830,43 +5007,43 @@ function Panel(props) {
3830
5007
  classNames = {},
3831
5008
  children
3832
5009
  } = props;
3833
- const body = loading ? /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "uic-panel-load", children: [
3834
- /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "uic-panel-load-bar" }),
3835
- /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "uic-panel-load-bar" }),
3836
- /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "uic-panel-load-bar" }),
3837
- /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "uic-sr", children: loadingLabel })
3838
- ] }) : error ? /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "uic-panel-fail", children: [
3839
- /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("p", { className: "uic-panel-fail-t", children: errorTitle }),
3840
- /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("pre", { className: "uic-panel-fail-m", children: error }),
3841
- errorDetail ? /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("details", { className: "uic-panel-fail-d", children: [
3842
- /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("summary", { children: detailLabel }),
3843
- /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "uic-panel-fail-dd", children: errorDetail })
5010
+ const body = loading ? /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "uic-panel-load", children: [
5011
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "uic-panel-load-bar" }),
5012
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "uic-panel-load-bar" }),
5013
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "uic-panel-load-bar" }),
5014
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "uic-sr", children: loadingLabel })
5015
+ ] }) : error ? /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "uic-panel-fail", children: [
5016
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("p", { className: "uic-panel-fail-t", children: errorTitle }),
5017
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("pre", { className: "uic-panel-fail-m", children: error }),
5018
+ errorDetail ? /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("details", { className: "uic-panel-fail-d", children: [
5019
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("summary", { children: detailLabel }),
5020
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "uic-panel-fail-dd", children: errorDetail })
3844
5021
  ] }) : null,
3845
- onRetry ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "uic-panel-fail-act", children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Button, { size: "sm", onClick: onRetry, children: retryLabel }) }) : null
5022
+ onRetry ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "uic-panel-fail-act", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Button, { size: "sm", onClick: onRetry, children: retryLabel }) }) : null
3846
5023
  ] }) : children;
3847
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
5024
+ return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
3848
5025
  "section",
3849
5026
  {
3850
5027
  className: ["uic-panel", className, classNames.root || ""].filter(Boolean).join(" "),
3851
5028
  "aria-busy": loading || busy || void 0,
3852
5029
  children: [
3853
- /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("header", { className: ["uic-panel-head", classNames.head || ""].filter(Boolean).join(" "), children: [
3854
- /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "uic-panel-titles", children: [
3855
- title ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Heading, { className: "uic-panel-title", children: title }) : null,
3856
- meta ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("p", { className: "uic-panel-meta", children: meta }) : null
5030
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("header", { className: ["uic-panel-head", classNames.head || ""].filter(Boolean).join(" "), children: [
5031
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "uic-panel-titles", children: [
5032
+ title ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Heading, { className: "uic-panel-title", children: title }) : null,
5033
+ meta ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("p", { className: "uic-panel-meta", children: meta }) : null
3857
5034
  ] }),
3858
- actions ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "uic-panel-acts", children: actions }) : null
5035
+ actions ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "uic-panel-acts", children: actions }) : null
3859
5036
  ] }),
3860
- busy ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "uic-panel-busy", role: "status", "aria-label": busyLabel }) : null,
3861
- /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: ["uic-panel-body", classNames.body || ""].filter(Boolean).join(" "), children: body }),
3862
- footer ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("footer", { className: "uic-panel-foot", children: footer }) : null
5037
+ busy ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "uic-panel-busy", role: "status", "aria-label": busyLabel }) : null,
5038
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: ["uic-panel-body", classNames.body || ""].filter(Boolean).join(" "), children: body }),
5039
+ footer ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("footer", { className: "uic-panel-foot", children: footer }) : null
3863
5040
  ]
3864
5041
  }
3865
5042
  );
3866
5043
  }
3867
5044
 
3868
5045
  // src/grid/PanelGrid.jsx
3869
- var import_react25 = __toESM(require("react"), 1);
5046
+ var import_react27 = __toESM(require("react"), 1);
3870
5047
 
3871
5048
  // src/grid/layout.js
3872
5049
  function sortLayout(layout2) {
@@ -3939,11 +5116,11 @@ function sameLayout(a, b) {
3939
5116
  }
3940
5117
 
3941
5118
  // src/grid/PanelGrid.jsx
3942
- var import_jsx_runtime24 = require("react/jsx-runtime");
5119
+ var import_jsx_runtime26 = require("react/jsx-runtime");
3943
5120
  function useMeasuredWidth() {
3944
- const ref = (0, import_react25.useRef)(null);
3945
- const [width, setWidth] = (0, import_react25.useState)(0);
3946
- (0, import_react25.useLayoutEffect)(() => {
5121
+ const ref = (0, import_react27.useRef)(null);
5122
+ const [width, setWidth] = (0, import_react27.useState)(0);
5123
+ (0, import_react27.useLayoutEffect)(() => {
3947
5124
  const el = ref.current;
3948
5125
  if (!el) return void 0;
3949
5126
  const measure = () => setWidth(el.clientWidth);
@@ -3970,9 +5147,9 @@ function PanelGrid(props) {
3970
5147
  className = ""
3971
5148
  } = props;
3972
5149
  const [wrapRef, width] = useMeasuredWidth();
3973
- const [drag, setDrag] = (0, import_react25.useState)(null);
3974
- const dragRef = (0, import_react25.useRef)(null);
3975
- const swallowClick = (0, import_react25.useRef)(false);
5150
+ const [drag, setDrag] = (0, import_react27.useState)(null);
5151
+ const dragRef = (0, import_react27.useRef)(null);
5152
+ const swallowClick = (0, import_react27.useRef)(false);
3976
5153
  const stacked = width > 0 && width < stackAt;
3977
5154
  const arrangeable = editable && !stacked;
3978
5155
  const live = drag ? drag.preview : layout2;
@@ -3980,7 +5157,7 @@ function PanelGrid(props) {
3980
5157
  const cellW = colW + gap;
3981
5158
  const cellH = rowHeight + gap;
3982
5159
  const rowsToPx = (h) => h * rowHeight + (h - 1) * gap;
3983
- const stack2 = (0, import_react25.useMemo)(() => {
5160
+ const stack2 = (0, import_react27.useMemo)(() => {
3984
5161
  if (!stacked) return null;
3985
5162
  const tops = /* @__PURE__ */ new Map();
3986
5163
  let y = 0;
@@ -3992,11 +5169,11 @@ function PanelGrid(props) {
3992
5169
  }, [stacked, live, rowHeight, gap]);
3993
5170
  const rows = layoutRows(live);
3994
5171
  const height = stacked ? stack2.height : rows ? rowsToPx(rows) : 0;
3995
- const commit = (0, import_react25.useCallback)((next) => {
5172
+ const commit = (0, import_react27.useCallback)((next) => {
3996
5173
  if (onLayoutChange && !sameLayout(next, layout2)) onLayoutChange(next);
3997
5174
  }, [onLayoutChange, layout2]);
3998
- const detach = (0, import_react25.useRef)(null);
3999
- (0, import_react25.useEffect)(() => () => detach.current?.(), []);
5175
+ const detach = (0, import_react27.useRef)(null);
5176
+ (0, import_react27.useEffect)(() => () => detach.current?.(), []);
4000
5177
  const start = (id, mode) => (e) => {
4001
5178
  if (!arrangeable || e.button !== 0) return;
4002
5179
  const item = layout2.find((it) => it.i === id);
@@ -4061,7 +5238,7 @@ function PanelGrid(props) {
4061
5238
  const byId = new Map(live.map((it) => [it.i, it]));
4062
5239
  const ghost = drag && drag.mode === "move" && byId.has(drag.id) ? boxOf(byId.get(drag.id)) : null;
4063
5240
  const cls = ["uic-pg", arrangeable ? "is-editable" : "", stacked ? "is-stacked" : "", className].filter(Boolean).join(" ");
4064
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
5241
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(
4065
5242
  "div",
4066
5243
  {
4067
5244
  ref: wrapRef,
@@ -4072,15 +5249,15 @@ function PanelGrid(props) {
4072
5249
  swallowClick.current = false;
4073
5250
  },
4074
5251
  children: [
4075
- ghost ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "uic-pg-ghost", "aria-hidden": "true", style: ghost }) : null,
4076
- width > 0 && import_react25.default.Children.map(children, (child) => {
4077
- if (!import_react25.default.isValidElement(child) || child.key == null) return null;
5252
+ ghost ? /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: "uic-pg-ghost", "aria-hidden": "true", style: ghost }) : null,
5253
+ width > 0 && import_react27.default.Children.map(children, (child) => {
5254
+ if (!import_react27.default.isValidElement(child) || child.key == null) return null;
4078
5255
  const id = String(child.key).replace(/^\.\$/, "");
4079
5256
  const it = byId.get(id);
4080
5257
  if (!it) return null;
4081
5258
  const moving = drag && drag.id === id;
4082
5259
  const offset = moving && drag.mode === "move" ? { transform: `translate(${drag.dx}px, ${drag.dy}px)` } : null;
4083
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
5260
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(
4084
5261
  "div",
4085
5262
  {
4086
5263
  className: "uic-pg-item" + (moving ? " is-moving" : ""),
@@ -4088,7 +5265,7 @@ function PanelGrid(props) {
4088
5265
  onPointerDown: arrangeable ? start(id, "move") : void 0,
4089
5266
  children: [
4090
5267
  child,
4091
- arrangeable && !it.static ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
5268
+ arrangeable && !it.static ? /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
4092
5269
  "button",
4093
5270
  {
4094
5271
  type: "button",
@@ -4096,7 +5273,7 @@ function PanelGrid(props) {
4096
5273
  "aria-label": resizeLabel ? resizeLabel(id) : "Resize panel. Arrow keys resize it; shift with arrow keys moves it past its neighbours.",
4097
5274
  onPointerDown: start(id, "resize"),
4098
5275
  onKeyDown: onHandleKey(id),
4099
- children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("svg", { width: "10", height: "10", viewBox: "0 0 10 10", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("path", { d: "M9 1v8H1", fill: "none", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" }) })
5276
+ children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("svg", { width: "10", height: "10", viewBox: "0 0 10 10", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("path", { d: "M9 1v8H1", fill: "none", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" }) })
4100
5277
  }
4101
5278
  ) : null
4102
5279
  ]
@@ -4113,8 +5290,8 @@ function packLayout(layout2, cols = 12) {
4113
5290
  }
4114
5291
 
4115
5292
  // src/timeline/Timeline.jsx
4116
- var import_react26 = require("react");
4117
- var import_jsx_runtime25 = require("react/jsx-runtime");
5293
+ var import_react28 = require("react");
5294
+ var import_jsx_runtime27 = require("react/jsx-runtime");
4118
5295
  var TL_MIN_PPS = 4;
4119
5296
  var TL_MAX_PPS = 400;
4120
5297
  var TL_DEFAULT_PPS = 26;
@@ -4203,21 +5380,21 @@ function Timeline({
4203
5380
  emptyLabel = "Nothing here yet.",
4204
5381
  className = ""
4205
5382
  }) {
4206
- const scroller = (0, import_react26.useRef)(null);
4207
- const innerRef = (0, import_react26.useRef)(null);
4208
- const [pps, setPps] = (0, import_react26.useState)(() => {
5383
+ const scroller = (0, import_react28.useRef)(null);
5384
+ const innerRef = (0, import_react28.useRef)(null);
5385
+ const [pps, setPps] = (0, import_react28.useState)(() => {
4209
5386
  if (zoomStorageKey && typeof window !== "undefined") {
4210
5387
  const n = parseFloat(window.localStorage.getItem(zoomStorageKey) || "");
4211
5388
  if (Number.isFinite(n)) return clamp(n, TL_MIN_PPS, TL_MAX_PPS);
4212
5389
  }
4213
5390
  return TL_DEFAULT_PPS;
4214
5391
  });
4215
- const [snapping, setSnapping] = (0, import_react26.useState)(() => snapStorageKey && typeof window !== "undefined" ? window.localStorage.getItem(snapStorageKey) !== "0" : true);
4216
- const gesture = (0, import_react26.useRef)(null);
4217
- const [drag, setDrag] = (0, import_react26.useState)(null);
4218
- const anchor = (0, import_react26.useRef)(null);
4219
- const [dropAt, setDropAt] = (0, import_react26.useState)(null);
4220
- const rows = (0, import_react26.useMemo)(
5392
+ const [snapping, setSnapping] = (0, import_react28.useState)(() => snapStorageKey && typeof window !== "undefined" ? window.localStorage.getItem(snapStorageKey) !== "0" : true);
5393
+ const gesture = (0, import_react28.useRef)(null);
5394
+ const [drag, setDrag] = (0, import_react28.useState)(null);
5395
+ const anchor = (0, import_react28.useRef)(null);
5396
+ const [dropAt, setDropAt] = (0, import_react28.useState)(null);
5397
+ const rows = (0, import_react28.useMemo)(
4221
5398
  () => tracks.map((t) => ({
4222
5399
  ...t,
4223
5400
  sequential: t.sequential !== false,
@@ -4225,12 +5402,12 @@ function Timeline({
4225
5402
  })),
4226
5403
  [tracks, pps]
4227
5404
  );
4228
- const contentSeconds = (0, import_react26.useMemo)(() => {
5405
+ const contentSeconds = (0, import_react28.useMemo)(() => {
4229
5406
  let end = 0;
4230
5407
  for (const t of rows) for (const l of t.laid) end = Math.max(end, l.t0 + l.w / pps);
4231
5408
  return end;
4232
5409
  }, [rows, pps]);
4233
- const snapTimes = (0, import_react26.useMemo)(() => {
5410
+ const snapTimes = (0, import_react28.useMemo)(() => {
4234
5411
  const out = [0, currentTime];
4235
5412
  for (const t of rows) for (const l of t.laid) {
4236
5413
  out.push(l.t0);
@@ -4238,7 +5415,7 @@ function Timeline({
4238
5415
  }
4239
5416
  return out;
4240
5417
  }, [rows, pps, currentTime]);
4241
- const setZoom = (0, import_react26.useCallback)((next, clientX) => {
5418
+ const setZoom = (0, import_react28.useCallback)((next, clientX) => {
4242
5419
  const v = clamp(next, TL_MIN_PPS, TL_MAX_PPS);
4243
5420
  const el = scroller.current;
4244
5421
  if (el) {
@@ -4254,21 +5431,21 @@ function Timeline({
4254
5431
  }
4255
5432
  }
4256
5433
  }, [pps, zoomStorageKey]);
4257
- const fitPps = (0, import_react26.useCallback)((seconds) => {
5434
+ const fitPps = (0, import_react28.useCallback)((seconds) => {
4258
5435
  const el = scroller.current;
4259
5436
  if (!el || !(seconds > 0)) return null;
4260
5437
  const room = el.clientWidth - TL_HEAD_W - 56;
4261
5438
  return room > 0 ? clamp(room / seconds, TL_MIN_PPS, TL_MAX_PPS) : null;
4262
5439
  }, []);
4263
- const fit = (0, import_react26.useCallback)(() => {
5440
+ const fit = (0, import_react28.useCallback)(() => {
4264
5441
  const v = fitPps(contentSeconds);
4265
5442
  if (v !== null) {
4266
5443
  setPps(v);
4267
5444
  if (scroller.current) scroller.current.scrollLeft = 0;
4268
5445
  }
4269
5446
  }, [fitPps, contentSeconds]);
4270
- const fitted = (0, import_react26.useRef)(false);
4271
- (0, import_react26.useLayoutEffect)(() => {
5447
+ const fitted = (0, import_react28.useRef)(false);
5448
+ (0, import_react28.useLayoutEffect)(() => {
4272
5449
  if (fitted.current || !(contentSeconds > 0)) return;
4273
5450
  if (zoomStorageKey && typeof window !== "undefined" && window.localStorage.getItem(zoomStorageKey)) {
4274
5451
  fitted.current = true;
@@ -4280,13 +5457,13 @@ function Timeline({
4280
5457
  setPps(v);
4281
5458
  }
4282
5459
  }, [contentSeconds, fitPps, zoomStorageKey]);
4283
- (0, import_react26.useLayoutEffect)(() => {
5460
+ (0, import_react28.useLayoutEffect)(() => {
4284
5461
  const a = anchor.current;
4285
5462
  if (!a || !scroller.current) return;
4286
5463
  anchor.current = null;
4287
5464
  scroller.current.scrollLeft = Math.max(0, TL_HEAD_W + a.t * pps - a.vx);
4288
5465
  }, [pps]);
4289
- (0, import_react26.useEffect)(() => {
5466
+ (0, import_react28.useEffect)(() => {
4290
5467
  const el = scroller.current;
4291
5468
  if (!el) return void 0;
4292
5469
  const onWheel = (e) => {
@@ -4297,12 +5474,12 @@ function Timeline({
4297
5474
  el.addEventListener("wheel", onWheel, { passive: false });
4298
5475
  return () => el.removeEventListener("wheel", onWheel);
4299
5476
  }, [pps, setZoom]);
4300
- const timeAt = (0, import_react26.useCallback)((clientX) => {
5477
+ const timeAt = (0, import_react28.useCallback)((clientX) => {
4301
5478
  const el = innerRef.current;
4302
5479
  if (!el) return 0;
4303
5480
  return Math.max(0, (clientX - el.getBoundingClientRect().left - TL_HEAD_W) / pps);
4304
5481
  }, [pps]);
4305
- const beginGesture = (0, import_react26.useCallback)((e, spec) => {
5482
+ const beginGesture = (0, import_react28.useCallback)((e, spec) => {
4306
5483
  e.preventDefault();
4307
5484
  e.stopPropagation();
4308
5485
  gesture.current = { ...spec, startX: e.clientX, active: false, value: null };
@@ -4336,12 +5513,12 @@ function Timeline({
4336
5513
  window.addEventListener("pointermove", move);
4337
5514
  window.addEventListener("pointerup", up);
4338
5515
  }, [timeAt, snapping, snapTimes, pps, onSeek]);
4339
- const onScrub = (0, import_react26.useCallback)((e) => {
5516
+ const onScrub = (0, import_react28.useCallback)((e) => {
4340
5517
  if (!onSeek) return;
4341
5518
  onSeek(timeAt(e.clientX));
4342
5519
  beginGesture(e, { kind: "scrub" });
4343
5520
  }, [onSeek, timeAt, beginGesture]);
4344
- const splitTarget = (0, import_react26.useMemo)(() => {
5521
+ const splitTarget = (0, import_react28.useMemo)(() => {
4345
5522
  if (!onSplit) return null;
4346
5523
  for (const track of rows) {
4347
5524
  for (const l of track.laid) {
@@ -4353,17 +5530,17 @@ function Timeline({
4353
5530
  }
4354
5531
  return null;
4355
5532
  }, [rows, currentTime, onSplit]);
4356
- const doSplit = (0, import_react26.useCallback)(() => {
5533
+ const doSplit = (0, import_react28.useCallback)(() => {
4357
5534
  if (!splitTarget) return;
4358
5535
  onSplit(splitTarget.l.clip, currentTime - splitTarget.l.t0, splitTarget.track);
4359
5536
  }, [splitTarget, currentTime, onSplit]);
4360
- const selected = (0, import_react26.useMemo)(() => {
5537
+ const selected = (0, import_react28.useMemo)(() => {
4361
5538
  for (const track of rows) for (const l of track.laid) {
4362
5539
  if (l.clip.id === selectedClipId) return { track, l };
4363
5540
  }
4364
5541
  return null;
4365
5542
  }, [rows, selectedClipId]);
4366
- const onKeyDown = (0, import_react26.useCallback)((e) => {
5543
+ const onKeyDown = (0, import_react28.useCallback)((e) => {
4367
5544
  const tag = e.target?.tagName;
4368
5545
  if (tag === "INPUT" || tag === "TEXTAREA" || e.target?.isContentEditable) return;
4369
5546
  if (e.key === "+" || e.key === "=") {
@@ -4380,7 +5557,7 @@ function Timeline({
4380
5557
  onDeleteClip(selected.l.clip, selected.track);
4381
5558
  }
4382
5559
  }, [pps, setZoom, doSplit, selected, onDeleteClip]);
4383
- const toggleSnap = (0, import_react26.useCallback)(() => {
5560
+ const toggleSnap = (0, import_react28.useCallback)(() => {
4384
5561
  setSnapping((v) => {
4385
5562
  const next = !v;
4386
5563
  if (snapStorageKey && typeof window !== "undefined") {
@@ -4397,9 +5574,9 @@ function Timeline({
4397
5574
  const laneW = Math.max(contentSeconds * pps + 140, 320);
4398
5575
  const ticks = [];
4399
5576
  for (let t = 0; t <= contentSeconds + major; t += major) ticks.push(t);
4400
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: `rui-tl ${className}`, onKeyDown, tabIndex: 0, children: [
4401
- /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "rui-tl-bar", children: [
4402
- onSplit && /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
5577
+ return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: `rui-tl ${className}`, onKeyDown, tabIndex: 0, children: [
5578
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "rui-tl-bar", children: [
5579
+ onSplit && /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(
4403
5580
  "button",
4404
5581
  {
4405
5582
  type: "button",
@@ -4408,7 +5585,7 @@ function Timeline({
4408
5585
  disabled: !splitTarget,
4409
5586
  title: splitTarget ? "Split at the playhead (B)" : "Move the playhead inside a clip to split it",
4410
5587
  children: [
4411
- /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
5588
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(
4412
5589
  "svg",
4413
5590
  {
4414
5591
  width: "13",
@@ -4420,19 +5597,19 @@ function Timeline({
4420
5597
  strokeLinecap: "round",
4421
5598
  "aria-hidden": "true",
4422
5599
  children: [
4423
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("circle", { cx: "6", cy: "6", r: "3" }),
4424
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("circle", { cx: "6", cy: "18", r: "3" }),
4425
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("line", { x1: "20", y1: "4", x2: "8.12", y2: "15.88" }),
4426
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("line", { x1: "14.47", y1: "14.48", x2: "20", y2: "20" }),
4427
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("line", { x1: "8.12", y1: "8.12", x2: "12", y2: "12" })
5600
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("circle", { cx: "6", cy: "6", r: "3" }),
5601
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("circle", { cx: "6", cy: "18", r: "3" }),
5602
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("line", { x1: "20", y1: "4", x2: "8.12", y2: "15.88" }),
5603
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("line", { x1: "14.47", y1: "14.48", x2: "20", y2: "20" }),
5604
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("line", { x1: "8.12", y1: "8.12", x2: "12", y2: "12" })
4428
5605
  ]
4429
5606
  }
4430
5607
  ),
4431
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { children: "Split" })
5608
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { children: "Split" })
4432
5609
  ]
4433
5610
  }
4434
5611
  ),
4435
- onDeleteClip && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
5612
+ onDeleteClip && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
4436
5613
  "button",
4437
5614
  {
4438
5615
  type: "button",
@@ -4443,7 +5620,7 @@ function Timeline({
4443
5620
  children: "Remove"
4444
5621
  }
4445
5622
  ),
4446
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
5623
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
4447
5624
  "button",
4448
5625
  {
4449
5626
  type: "button",
@@ -4454,9 +5631,9 @@ function Timeline({
4454
5631
  children: "Snap"
4455
5632
  }
4456
5633
  ),
4457
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-time", "aria-label": "Playhead position", children: exactLabel(currentTime) }),
4458
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-spacer" }),
4459
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
5634
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "rui-tl-time", "aria-label": "Playhead position", children: exactLabel(currentTime) }),
5635
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "rui-tl-spacer" }),
5636
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
4460
5637
  "button",
4461
5638
  {
4462
5639
  type: "button",
@@ -4468,7 +5645,7 @@ function Timeline({
4468
5645
  children: "\u2212"
4469
5646
  }
4470
5647
  ),
4471
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
5648
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
4472
5649
  "button",
4473
5650
  {
4474
5651
  type: "button",
@@ -4480,7 +5657,7 @@ function Timeline({
4480
5657
  children: "+"
4481
5658
  }
4482
5659
  ),
4483
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
5660
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
4484
5661
  "button",
4485
5662
  {
4486
5663
  type: "button",
@@ -4492,10 +5669,10 @@ function Timeline({
4492
5669
  }
4493
5670
  )
4494
5671
  ] }),
4495
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "rui-tl-scroll", ref: scroller, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "rui-tl-inner", ref: innerRef, style: { width: TL_HEAD_W + laneW }, children: [
4496
- /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "rui-tl-row rui-tl-rulerrow", children: [
4497
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "rui-tl-head rui-tl-rulerhead", "aria-hidden": "true" }),
4498
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
5672
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: "rui-tl-scroll", ref: scroller, children: /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "rui-tl-inner", ref: innerRef, style: { width: TL_HEAD_W + laneW }, children: [
5673
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "rui-tl-row rui-tl-rulerrow", children: [
5674
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: "rui-tl-head rui-tl-rulerhead", "aria-hidden": "true" }),
5675
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
4499
5676
  "div",
4500
5677
  {
4501
5678
  className: "rui-tl-ruler",
@@ -4524,17 +5701,17 @@ function Timeline({
4524
5701
  onSeek(currentTime + step);
4525
5702
  }
4526
5703
  } : void 0,
4527
- children: ticks.map((t) => /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-ticklbl", style: { left: t * pps }, children: tickLabel(t, major) }, t))
5704
+ children: ticks.map((t) => /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "rui-tl-ticklbl", style: { left: t * pps }, children: tickLabel(t, major) }, t))
4528
5705
  }
4529
5706
  )
4530
5707
  ] }),
4531
- rows.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("p", { className: "rui-tl-empty", children: emptyLabel }),
4532
- rows.map((track) => /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "rui-tl-row", children: [
4533
- /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "rui-tl-head", title: track.title || track.label, children: [
5708
+ rows.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("p", { className: "rui-tl-empty", children: emptyLabel }),
5709
+ rows.map((track) => /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "rui-tl-row", children: [
5710
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "rui-tl-head", title: track.title || track.label, children: [
4534
5711
  track.icon,
4535
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-headlbl", children: track.label })
5712
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "rui-tl-headlbl", children: track.label })
4536
5713
  ] }),
4537
- /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
5714
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(
4538
5715
  "div",
4539
5716
  {
4540
5717
  className: "rui-tl-lane" + (dropAt?.trackId === track.id ? " is-dropping" : ""),
@@ -4565,8 +5742,8 @@ function Timeline({
4565
5742
  onDropClip(payload, { trackId: track.id, seconds: t, index });
4566
5743
  } : void 0,
4567
5744
  children: [
4568
- track.laid.length === 0 && track.emptyLabel && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("p", { className: "rui-tl-laneempty", children: track.emptyLabel }),
4569
- track.laid.map((l) => /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
5745
+ track.laid.length === 0 && track.emptyLabel && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("p", { className: "rui-tl-laneempty", children: track.emptyLabel }),
5746
+ track.laid.map((l) => /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
4570
5747
  Clip,
4571
5748
  {
4572
5749
  l,
@@ -4582,7 +5759,7 @@ function Timeline({
4582
5759
  },
4583
5760
  l.clip.id ?? l.i
4584
5761
  )),
4585
- dropAt?.trackId === track.id && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
5762
+ dropAt?.trackId === track.id && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
4586
5763
  "span",
4587
5764
  {
4588
5765
  className: "rui-tl-dropmark",
@@ -4590,7 +5767,7 @@ function Timeline({
4590
5767
  "aria-hidden": "true"
4591
5768
  }
4592
5769
  ),
4593
- laneAppend && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
5770
+ laneAppend && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
4594
5771
  "span",
4595
5772
  {
4596
5773
  className: "rui-tl-append",
@@ -4602,9 +5779,9 @@ function Timeline({
4602
5779
  }
4603
5780
  )
4604
5781
  ] }, track.id)),
4605
- onDropClip && newLaneLabel && /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "rui-tl-row", children: [
4606
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "rui-tl-head rui-tl-newhead", "aria-hidden": "true" }),
4607
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
5782
+ onDropClip && newLaneLabel && /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "rui-tl-row", children: [
5783
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: "rui-tl-head rui-tl-newhead", "aria-hidden": "true" }),
5784
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
4608
5785
  "div",
4609
5786
  {
4610
5787
  className: "rui-tl-newlane" + (dropAt?.trackId === null ? " is-dropping" : ""),
@@ -4626,11 +5803,11 @@ function Timeline({
4626
5803
  e.preventDefault();
4627
5804
  onDropClip(payload, { trackId: null, seconds: timeAt(e.clientX), index: 0 });
4628
5805
  },
4629
- children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-newlbl", children: newLaneLabel })
5806
+ children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "rui-tl-newlbl", children: newLaneLabel })
4630
5807
  }
4631
5808
  )
4632
5809
  ] }),
4633
- drag?.guide != null && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
5810
+ drag?.guide != null && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
4634
5811
  "div",
4635
5812
  {
4636
5813
  className: "rui-tl-guide",
@@ -4638,16 +5815,16 @@ function Timeline({
4638
5815
  "aria-hidden": "true"
4639
5816
  }
4640
5817
  ),
4641
- Number.isFinite(currentTime) && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
5818
+ Number.isFinite(currentTime) && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
4642
5819
  "div",
4643
5820
  {
4644
5821
  className: "rui-tl-playhead",
4645
5822
  style: { left: TL_HEAD_W + currentTime * pps },
4646
5823
  "aria-hidden": "true",
4647
- children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-playhead-grip" })
5824
+ children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "rui-tl-playhead-grip" })
4648
5825
  }
4649
5826
  ),
4650
- drag?.annotation && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "rui-tl-annot", style: { left: TL_HEAD_W + (drag.annotAt || 0) * pps }, children: drag.annotation })
5827
+ drag?.annotation && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: "rui-tl-annot", style: { left: TL_HEAD_W + (drag.annotAt || 0) * pps }, children: drag.annotation })
4651
5828
  ] }) })
4652
5829
  ] });
4653
5830
  }
@@ -4723,7 +5900,7 @@ function Clip({
4723
5900
  click: onSelect
4724
5901
  });
4725
5902
  };
4726
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
5903
+ return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(
4727
5904
  "article",
4728
5905
  {
4729
5906
  className: "rui-tl-clip" + (clip.state ? ` is-${clip.state}` : "") + (known ? "" : " is-unmeasured") + (selected ? " is-selected" : "") + (live ? " is-live" : ""),
@@ -4738,10 +5915,10 @@ function Clip({
4738
5915
  }
4739
5916
  },
4740
5917
  children: [
4741
- clip.poster ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-strip", style: {
5918
+ clip.poster ? /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "rui-tl-strip", style: {
4742
5919
  backgroundImage: `url("${String(clip.poster).replace(/"/g, '\\"')}")`,
4743
5920
  backgroundSize: `${tileW}px 100%`
4744
- } }) : clip.video ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
5921
+ } }) : clip.video ? /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
4745
5922
  "video",
4746
5923
  {
4747
5924
  className: "rui-tl-frame",
@@ -4752,12 +5929,12 @@ function Clip({
4752
5929
  tabIndex: -1,
4753
5930
  "aria-hidden": "true"
4754
5931
  }
4755
- ) : /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-blank", "aria-hidden": "true", children: clip.glyph }),
4756
- clip.badge && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-badge", children: clip.badge }),
4757
- known && width > 46 && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-dur", children: durationLabel(clip.duration) }),
4758
- clip.label && width > 104 && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-name", children: clip.label }),
4759
- onTrim && known && /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_jsx_runtime25.Fragment, { children: [
4760
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
5932
+ ) : /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "rui-tl-blank", "aria-hidden": "true", children: clip.glyph }),
5933
+ clip.badge && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "rui-tl-badge", children: clip.badge }),
5934
+ known && width > 46 && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "rui-tl-dur", children: durationLabel(clip.duration) }),
5935
+ clip.label && width > 104 && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "rui-tl-name", children: clip.label }),
5936
+ onTrim && known && /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(import_jsx_runtime27.Fragment, { children: [
5937
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
4761
5938
  "span",
4762
5939
  {
4763
5940
  className: "rui-tl-trim l",
@@ -4766,7 +5943,7 @@ function Clip({
4766
5943
  "aria-label": `Trim the start of ${clip.label || "this clip"}`
4767
5944
  }
4768
5945
  ),
4769
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
5946
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
4770
5947
  "span",
4771
5948
  {
4772
5949
  className: "rui-tl-trim r",