reifyui 0.8.2 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -496,6 +496,8 @@ export interface SheetColumn {
496
496
  options?: Array<string | { label?: string; value?: unknown; color?: string }>;
497
497
  [key: string]: unknown;
498
498
  }
499
+ /** With no `height` a row fits its tallest cell, up to --shg-row-max (eight lines by default), and
500
+ * a cell holding more scrolls inside itself. A `height` is a row someone sized: exactly that tall. */
499
501
  export interface SheetRow { id: string; height?: number; [key: string]: unknown }
500
502
  export interface SheetCell { value?: unknown; status?: string; error?: string | null; [key: string]: unknown }
501
503
  export interface Sheet {
package/dist/index.js CHANGED
@@ -697,6 +697,7 @@ function ChatPanel(props) {
697
697
  const [draft, setDraft] = useState2("");
698
698
  const [busy, setBusy] = useState2(false);
699
699
  const [connecting, setConnecting] = useState2(false);
700
+ const [dropped, setDropped] = useState2(false);
700
701
  const [histLoading, setHistLoading] = useState2(true);
701
702
  const [staged, setStaged] = useState2([]);
702
703
  const [attachErr, setAttachErr] = useState2("");
@@ -768,12 +769,18 @@ function ChatPanel(props) {
768
769
  }
769
770
  pendingRef.current = null;
770
771
  setConnecting(false);
772
+ if (out.dropped) {
773
+ setDropped(true);
774
+ return;
775
+ }
771
776
  updateLastAsst((a) => a.status === "running" ? { ...a, status: "done" } : a);
772
777
  api.current.onChanged?.();
773
- } catch {
774
- dropRunningAsst();
775
- pendingRef.current = { text, files };
776
- setConnecting(true);
778
+ } catch (e) {
779
+ updateLastAsst((a) => ({
780
+ ...a,
781
+ blocks: a.blocks.length ? a.blocks : withText([], e && e.message || "The turn could not be started."),
782
+ status: "failed"
783
+ }));
777
784
  } finally {
778
785
  setBusy(false);
779
786
  }
@@ -835,6 +842,26 @@ function ChatPanel(props) {
835
842
  }, RETRY_MS);
836
843
  return () => window.clearInterval(iv);
837
844
  }, [connecting, busy, deliver]);
845
+ useEffect3(() => {
846
+ if (!dropped) return void 0;
847
+ let dead = false;
848
+ const tick = () => Promise.resolve(api.current.loadHistory(sessionId)).then((hist) => {
849
+ if (dead || !hist?.length) return;
850
+ const last = hist[hist.length - 1];
851
+ const settled = !(last.role === "assistant" && last.status === "running") && !externalBusy;
852
+ setMessages(hist);
853
+ if (settled) {
854
+ setDropped(false);
855
+ api.current.onChanged?.();
856
+ }
857
+ }).catch(() => {
858
+ });
859
+ const iv = window.setInterval(tick, POLL_MS);
860
+ return () => {
861
+ dead = true;
862
+ window.clearInterval(iv);
863
+ };
864
+ }, [dropped, externalBusy, sessionId]);
838
865
  useEffect3(() => {
839
866
  let dead = false;
840
867
  let poll;
@@ -946,7 +973,8 @@ function ChatPanel(props) {
946
973
  toggle,
947
974
  title ? /* @__PURE__ */ jsx6("span", { className: "uic-chat-title", title, children: title }) : null,
948
975
  headerRight,
949
- connecting ? /* @__PURE__ */ jsx6("span", { className: "uic-chat-conn", children: connectingLabel }) : null
976
+ connecting ? /* @__PURE__ */ jsx6("span", { className: "uic-chat-conn", children: connectingLabel }) : null,
977
+ dropped ? /* @__PURE__ */ jsx6("span", { className: "uic-chat-conn", children: workingLabel }) : null
950
978
  ] }),
951
979
  /* @__PURE__ */ jsxs6("div", { className: "uic-chat-body", ref: bodyRef, onScroll: onBodyScroll, role: "log", "aria-live": "polite", children: [
952
980
  histLoading ? /* @__PURE__ */ jsx6(ChatMessagesSkeleton, {}) : empty && externalBusy ? busyState === void 0 ? defaultBusyState : busyState : empty ? emptyState : /* @__PURE__ */ jsx6(
@@ -2098,6 +2126,9 @@ var COMPUTE_KINDS = [
2098
2126
  ];
2099
2127
  var RESOURCE_KINDS = ["image", "sheet", "slides", "workflow", "graph"];
2100
2128
  var RESOURCE_ICON = { image: "\u{1F5BC}", sheet: "\u25A6", slides: "\u25A4", workflow: "\u2699", graph: "\u25C9" };
2129
+ var POPOVER_EDITORS = /* @__PURE__ */ new Set(["select", "resource"]);
2130
+ var SINGLE_LINE_EDITORS = /* @__PURE__ */ new Set(["number", "date", "tags"]);
2131
+ var isMultiline = (col) => !SINGLE_LINE_EDITORS.has(col.type);
2101
2132
  function PopPortal({ anchor, width = 250, estHeight = 300, className, children, onClose }) {
2102
2133
  const boxRef = useRef7(null);
2103
2134
  useEffect8(() => {
@@ -2270,6 +2301,7 @@ function SheetGrid({
2270
2301
  document.body.style.cursor = "";
2271
2302
  if (!d) return;
2272
2303
  setSizeDraft({});
2304
+ if (d.last === d.start) return;
2273
2305
  mutate((n) => {
2274
2306
  if (d.kind === "col") {
2275
2307
  const c = n.columns.find((x) => x.id === d.id);
@@ -2342,8 +2374,23 @@ function SheetGrid({
2342
2374
  const numW = Math.max(48, 30 + String(rows.length || 1).length * 9);
2343
2375
  const numStyle = { width: numW, minWidth: numW, maxWidth: numW };
2344
2376
  const rowHeight = (row) => sizeDraft.row && sizeDraft.row[row.id] || row.height || void 0;
2377
+ const rowStyle = (row) => {
2378
+ const h = rowHeight(row);
2379
+ return {
2380
+ ...h ? { height: h, "--shg-row-max": `${h - 1}px` } : null,
2381
+ // The grid's own text wraps and no longer reads this; it stays for host cell bodies that do.
2382
+ "--shg-clamp": Math.max(1, Math.floor(((h || 34) - 10) / 18))
2383
+ };
2384
+ };
2385
+ const fitRow = (rowId) => mutate((n) => {
2386
+ const r = n.rows.find((x) => x.id === rowId);
2387
+ if (r) delete r.height;
2388
+ });
2345
2389
  useEffect8(() => {
2346
- if (editing && inputRef.current) inputRef.current.focus();
2390
+ const el = editing && inputRef.current;
2391
+ if (!el) return;
2392
+ el.focus();
2393
+ if (el.tagName === "TEXTAREA") el.setSelectionRange(el.value.length, el.value.length);
2347
2394
  }, [editing]);
2348
2395
  const mutate = (fn) => {
2349
2396
  if (readOnly || !onChange) return;
@@ -2483,6 +2530,26 @@ function SheetGrid({
2483
2530
  }
2484
2531
  );
2485
2532
  }
2533
+ if (isMultiline(col)) {
2534
+ return /* @__PURE__ */ jsx13(
2535
+ "textarea",
2536
+ {
2537
+ ref: inputRef,
2538
+ className: "shg-input shg-input-area",
2539
+ value: draft,
2540
+ rows: 1,
2541
+ onChange: (e) => setDraft(e.target.value),
2542
+ onBlur: commitEdit,
2543
+ onKeyDown: (e) => {
2544
+ if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) {
2545
+ e.preventDefault();
2546
+ commitEdit();
2547
+ }
2548
+ if (e.key === "Escape") setEditing(null);
2549
+ }
2550
+ }
2551
+ );
2552
+ }
2486
2553
  const inputType = col.type === "date" ? "date" : col.type === "number" ? "number" : "text";
2487
2554
  return /* @__PURE__ */ jsx13(
2488
2555
  "input",
@@ -2541,114 +2608,122 @@ function SheetGrid({
2541
2608
  !readOnly && /* @__PURE__ */ jsx13("th", { className: "shg-add-col", children: /* @__PURE__ */ jsx13("button", { className: "shg-add", onClick: addColumn, title: "Add column", children: "+" }) })
2542
2609
  ] }) }),
2543
2610
  /* @__PURE__ */ jsxs12("tbody", { children: [
2544
- rows.map((row, ri) => /* @__PURE__ */ jsxs12(
2545
- "tr",
2546
- {
2547
- "data-row-id": row.id,
2548
- style: {
2549
- ...rowHeight(row) ? { height: rowHeight(row) } : null,
2550
- "--shg-clamp": Math.max(1, Math.floor(((rowHeight(row) || 34) - 10) / 18))
2551
- },
2552
- children: [
2553
- /* @__PURE__ */ jsxs12(
2554
- "td",
2555
- {
2556
- className: "shg-rownum" + dndClass("row", row.id),
2557
- style: numStyle,
2558
- title: "Drag to reorder",
2559
- ...dndProps("row", row.id),
2560
- children: [
2561
- /* @__PURE__ */ jsx13("span", { children: ri + 1 }),
2562
- !readOnly && /* @__PURE__ */ jsx13("button", { className: "shg-rowdel", onClick: () => deleteRow(row.id), title: "Delete row", children: "\xD7" }),
2563
- !readOnly && /* @__PURE__ */ jsx13("span", { className: "shg-resize-row", onMouseDown: (e) => startResize(e, "row", row.id, rowHeight(row) || e.currentTarget.closest("tr").offsetHeight) })
2564
- ]
2565
- }
2566
- ),
2567
- columns.map((col) => {
2568
- const c = cells[cellKey(row.id, col.id)] || {};
2569
- const computed = isComputed(col);
2570
- const isEditing = editing && editing.rowId === row.id && editing.colId === col.id;
2571
- const peer = peerMarks && peerMarks[cellKey(row.id, col.id)];
2572
- const custom = renderCell && renderCell({
2573
- cell: c,
2574
- column: col,
2575
- row,
2576
- rowIndex: ri,
2577
- sheet,
2578
- computed,
2579
- width: colWidth(col),
2580
- height: rowHeight(row),
2581
- editing: !!isEditing,
2582
- readOnly,
2583
- setCell: (v) => setCell(row.id, col.id, v),
2584
- runCell: onRunCell && !readOnly ? () => onRunCell(row.id, col.id) : null
2585
- });
2586
- return /* @__PURE__ */ jsxs12(
2587
- "td",
2611
+ rows.map((row, ri) => /* @__PURE__ */ jsxs12("tr", { "data-row-id": row.id, style: rowStyle(row), children: [
2612
+ /* @__PURE__ */ jsxs12(
2613
+ "td",
2614
+ {
2615
+ className: "shg-rownum" + dndClass("row", row.id),
2616
+ style: numStyle,
2617
+ title: "Drag to reorder",
2618
+ ...dndProps("row", row.id),
2619
+ children: [
2620
+ /* @__PURE__ */ jsx13("span", { children: ri + 1 }),
2621
+ !readOnly && /* @__PURE__ */ jsx13("button", { className: "shg-rowdel", onClick: () => deleteRow(row.id), title: "Delete row", children: "\xD7" }),
2622
+ !readOnly && /* @__PURE__ */ jsx13(
2623
+ "span",
2588
2624
  {
2589
- "data-col-id": col.id,
2590
- className: "shg-cell" + (computed ? " shg-cell-compute" : "") + (c.status && computed ? ` shg-cell-${c.status}` : "") + (peer ? " shg-cell-peer" : ""),
2591
- style: peer ? { boxShadow: `inset 0 0 0 2px ${peer.color}` } : void 0,
2592
- onClick: (e) => {
2593
- if (!isEditing) openEdit(row.id, col, e.currentTarget);
2594
- },
2595
- title: c.error || "",
2596
- children: [
2597
- !readOnly && /* @__PURE__ */ jsxs12(Fragment8, { children: [
2598
- /* @__PURE__ */ jsx13(
2599
- "span",
2600
- {
2601
- className: "shg-resize-col shg-resize-in-cell",
2602
- onClick: (e) => e.stopPropagation(),
2603
- onMouseDown: (e) => startResize(
2604
- e,
2605
- "col",
2606
- col.id,
2607
- colWidth(col) || e.currentTarget.closest("td").offsetWidth
2608
- )
2609
- }
2610
- ),
2611
- /* @__PURE__ */ jsx13(
2612
- "span",
2613
- {
2614
- className: "shg-resize-row shg-resize-in-cell",
2615
- onClick: (e) => e.stopPropagation(),
2616
- onMouseDown: (e) => startResize(
2617
- e,
2618
- "row",
2619
- row.id,
2620
- rowHeight(row) || e.currentTarget.closest("tr").offsetHeight
2621
- )
2622
- }
2623
- )
2624
- ] }),
2625
- peer && /* @__PURE__ */ jsx13("span", { className: "shg-peer-flag", style: { background: peer.color }, children: peer.name }),
2626
- isEditing ? renderEditor(col) : /* @__PURE__ */ jsx13("div", { className: "shg-val", children: custom !== void 0 ? custom : /* @__PURE__ */ jsxs12(Fragment8, { children: [
2627
- computed && /* @__PURE__ */ jsx13(StatusDot, { status: c.status }),
2628
- /* @__PURE__ */ jsx13(CellValue, { cell: c, col, fetchBlobUrl, onOpenResource }),
2629
- computed && !readOnly && onRunCell && /* @__PURE__ */ jsx13(
2630
- "button",
2631
- {
2632
- className: "shg-runcell",
2633
- title: "Run this cell",
2634
- onClick: (e) => {
2635
- e.stopPropagation();
2636
- onRunCell(row.id, col.id);
2637
- },
2638
- children: "\u25B6"
2639
- }
2625
+ className: "shg-resize-row",
2626
+ title: "Drag to resize, double-click to fit",
2627
+ onMouseDown: (e) => startResize(e, "row", row.id, rowHeight(row) || e.currentTarget.closest("tr").offsetHeight),
2628
+ onDoubleClick: () => fitRow(row.id)
2629
+ }
2630
+ )
2631
+ ]
2632
+ }
2633
+ ),
2634
+ columns.map((col) => {
2635
+ const c = cells[cellKey(row.id, col.id)] || {};
2636
+ const computed = isComputed(col);
2637
+ const isEditing = editing && editing.rowId === row.id && editing.colId === col.id;
2638
+ const peer = peerMarks && peerMarks[cellKey(row.id, col.id)];
2639
+ const custom = renderCell && renderCell({
2640
+ cell: c,
2641
+ column: col,
2642
+ row,
2643
+ rowIndex: ri,
2644
+ sheet,
2645
+ computed,
2646
+ width: colWidth(col),
2647
+ height: rowHeight(row),
2648
+ editing: !!isEditing,
2649
+ readOnly,
2650
+ setCell: (v) => setCell(row.id, col.id, v),
2651
+ runCell: onRunCell && !readOnly ? () => onRunCell(row.id, col.id) : null
2652
+ });
2653
+ return /* @__PURE__ */ jsxs12(
2654
+ "td",
2655
+ {
2656
+ "data-col-id": col.id,
2657
+ className: "shg-cell" + (computed ? " shg-cell-compute" : "") + (c.status && computed ? ` shg-cell-${c.status}` : "") + (peer ? " shg-cell-peer" : ""),
2658
+ style: peer ? { boxShadow: `inset 0 0 0 2px ${peer.color}` } : void 0,
2659
+ onClick: (e) => {
2660
+ if (!isEditing) openEdit(row.id, col, e.currentTarget);
2661
+ },
2662
+ title: c.error || "",
2663
+ children: [
2664
+ !readOnly && /* @__PURE__ */ jsxs12(Fragment8, { children: [
2665
+ /* @__PURE__ */ jsx13(
2666
+ "span",
2667
+ {
2668
+ className: "shg-resize-col shg-resize-in-cell",
2669
+ onClick: (e) => e.stopPropagation(),
2670
+ onMouseDown: (e) => startResize(
2671
+ e,
2672
+ "col",
2673
+ col.id,
2674
+ colWidth(col) || e.currentTarget.closest("td").offsetWidth
2640
2675
  )
2641
- ] }) })
2642
- ]
2643
- },
2644
- col.id
2645
- );
2646
- }),
2647
- !readOnly && /* @__PURE__ */ jsx13("td", { className: "shg-pad" })
2648
- ]
2649
- },
2650
- row.id
2651
- )),
2676
+ }
2677
+ ),
2678
+ /* @__PURE__ */ jsx13(
2679
+ "span",
2680
+ {
2681
+ className: "shg-resize-row shg-resize-in-cell",
2682
+ onClick: (e) => e.stopPropagation(),
2683
+ onMouseDown: (e) => startResize(
2684
+ e,
2685
+ "row",
2686
+ row.id,
2687
+ rowHeight(row) || e.currentTarget.closest("tr").offsetHeight
2688
+ ),
2689
+ onDoubleClick: (e) => {
2690
+ e.stopPropagation();
2691
+ fitRow(row.id);
2692
+ }
2693
+ }
2694
+ )
2695
+ ] }),
2696
+ peer && /* @__PURE__ */ jsx13("span", { className: "shg-peer-flag", style: { background: peer.color }, children: peer.name }),
2697
+ isEditing && renderEditor(col),
2698
+ isEditing && !POPOVER_EDITORS.has(col.type) ? (
2699
+ // The editor lies over the cell; this invisible copy of the draft holds the
2700
+ // cell's place, so the row keeps its height while you type and grows with
2701
+ // the draft, to the same cap as the value. The trailing zero-width space
2702
+ // gives a draft that ends in a line break its last, empty line.
2703
+ /* @__PURE__ */ jsx13("div", { className: "shg-val shg-val-mirror", "aria-hidden": "true", children: /* @__PURE__ */ jsx13("span", { className: "shg-val-txt", children: `${typeof draft === "string" ? draft : ""}\u200B` }) })
2704
+ ) : /* @__PURE__ */ jsx13("div", { className: "shg-val", children: custom !== void 0 ? custom : /* @__PURE__ */ jsxs12(Fragment8, { children: [
2705
+ computed && /* @__PURE__ */ jsx13(StatusDot, { status: c.status }),
2706
+ /* @__PURE__ */ jsx13(CellValue, { cell: c, col, fetchBlobUrl, onOpenResource }),
2707
+ computed && !readOnly && onRunCell && /* @__PURE__ */ jsx13(
2708
+ "button",
2709
+ {
2710
+ className: "shg-runcell",
2711
+ title: "Run this cell",
2712
+ onClick: (e) => {
2713
+ e.stopPropagation();
2714
+ onRunCell(row.id, col.id);
2715
+ },
2716
+ children: "\u25B6"
2717
+ }
2718
+ )
2719
+ ] }) })
2720
+ ]
2721
+ },
2722
+ col.id
2723
+ );
2724
+ }),
2725
+ !readOnly && /* @__PURE__ */ jsx13("td", { className: "shg-pad" })
2726
+ ] }, row.id)),
2652
2727
  !readOnly && /* @__PURE__ */ jsxs12("tr", { className: "shg-ghost-row", onClick: addRow, children: [
2653
2728
  /* @__PURE__ */ jsx13("td", { className: "shg-rownum shg-ghost-num", style: numStyle, children: "+" }),
2654
2729
  /* @__PURE__ */ jsx13("td", { className: "shg-ghost-cell", colSpan: columns.length + 1, children: "New row" })