reifyui 0.8.3 → 0.8.5

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
@@ -2126,6 +2126,9 @@ var COMPUTE_KINDS = [
2126
2126
  ];
2127
2127
  var RESOURCE_KINDS = ["image", "sheet", "slides", "workflow", "graph"];
2128
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);
2129
2132
  function PopPortal({ anchor, width = 250, estHeight = 300, className, children, onClose }) {
2130
2133
  const boxRef = useRef7(null);
2131
2134
  useEffect8(() => {
@@ -2298,6 +2301,7 @@ function SheetGrid({
2298
2301
  document.body.style.cursor = "";
2299
2302
  if (!d) return;
2300
2303
  setSizeDraft({});
2304
+ if (d.last === d.start) return;
2301
2305
  mutate((n) => {
2302
2306
  if (d.kind === "col") {
2303
2307
  const c = n.columns.find((x) => x.id === d.id);
@@ -2370,8 +2374,23 @@ function SheetGrid({
2370
2374
  const numW = Math.max(48, 30 + String(rows.length || 1).length * 9);
2371
2375
  const numStyle = { width: numW, minWidth: numW, maxWidth: numW };
2372
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
+ });
2373
2389
  useEffect8(() => {
2374
- 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);
2375
2394
  }, [editing]);
2376
2395
  const mutate = (fn) => {
2377
2396
  if (readOnly || !onChange) return;
@@ -2511,6 +2530,26 @@ function SheetGrid({
2511
2530
  }
2512
2531
  );
2513
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
+ }
2514
2553
  const inputType = col.type === "date" ? "date" : col.type === "number" ? "number" : "text";
2515
2554
  return /* @__PURE__ */ jsx13(
2516
2555
  "input",
@@ -2569,114 +2608,122 @@ function SheetGrid({
2569
2608
  !readOnly && /* @__PURE__ */ jsx13("th", { className: "shg-add-col", children: /* @__PURE__ */ jsx13("button", { className: "shg-add", onClick: addColumn, title: "Add column", children: "+" }) })
2570
2609
  ] }) }),
2571
2610
  /* @__PURE__ */ jsxs12("tbody", { children: [
2572
- rows.map((row, ri) => /* @__PURE__ */ jsxs12(
2573
- "tr",
2574
- {
2575
- "data-row-id": row.id,
2576
- style: {
2577
- ...rowHeight(row) ? { height: rowHeight(row) } : null,
2578
- "--shg-clamp": Math.max(1, Math.floor(((rowHeight(row) || 34) - 10) / 18))
2579
- },
2580
- children: [
2581
- /* @__PURE__ */ jsxs12(
2582
- "td",
2583
- {
2584
- className: "shg-rownum" + dndClass("row", row.id),
2585
- style: numStyle,
2586
- title: "Drag to reorder",
2587
- ...dndProps("row", row.id),
2588
- children: [
2589
- /* @__PURE__ */ jsx13("span", { children: ri + 1 }),
2590
- !readOnly && /* @__PURE__ */ jsx13("button", { className: "shg-rowdel", onClick: () => deleteRow(row.id), title: "Delete row", children: "\xD7" }),
2591
- !readOnly && /* @__PURE__ */ jsx13("span", { className: "shg-resize-row", onMouseDown: (e) => startResize(e, "row", row.id, rowHeight(row) || e.currentTarget.closest("tr").offsetHeight) })
2592
- ]
2593
- }
2594
- ),
2595
- columns.map((col) => {
2596
- const c = cells[cellKey(row.id, col.id)] || {};
2597
- const computed = isComputed(col);
2598
- const isEditing = editing && editing.rowId === row.id && editing.colId === col.id;
2599
- const peer = peerMarks && peerMarks[cellKey(row.id, col.id)];
2600
- const custom = renderCell && renderCell({
2601
- cell: c,
2602
- column: col,
2603
- row,
2604
- rowIndex: ri,
2605
- sheet,
2606
- computed,
2607
- width: colWidth(col),
2608
- height: rowHeight(row),
2609
- editing: !!isEditing,
2610
- readOnly,
2611
- setCell: (v) => setCell(row.id, col.id, v),
2612
- runCell: onRunCell && !readOnly ? () => onRunCell(row.id, col.id) : null
2613
- });
2614
- return /* @__PURE__ */ jsxs12(
2615
- "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",
2616
2624
  {
2617
- "data-col-id": col.id,
2618
- className: "shg-cell" + (computed ? " shg-cell-compute" : "") + (c.status && computed ? ` shg-cell-${c.status}` : "") + (peer ? " shg-cell-peer" : ""),
2619
- style: peer ? { boxShadow: `inset 0 0 0 2px ${peer.color}` } : void 0,
2620
- onClick: (e) => {
2621
- if (!isEditing) openEdit(row.id, col, e.currentTarget);
2622
- },
2623
- title: c.error || "",
2624
- children: [
2625
- !readOnly && /* @__PURE__ */ jsxs12(Fragment8, { children: [
2626
- /* @__PURE__ */ jsx13(
2627
- "span",
2628
- {
2629
- className: "shg-resize-col shg-resize-in-cell",
2630
- onClick: (e) => e.stopPropagation(),
2631
- onMouseDown: (e) => startResize(
2632
- e,
2633
- "col",
2634
- col.id,
2635
- colWidth(col) || e.currentTarget.closest("td").offsetWidth
2636
- )
2637
- }
2638
- ),
2639
- /* @__PURE__ */ jsx13(
2640
- "span",
2641
- {
2642
- className: "shg-resize-row shg-resize-in-cell",
2643
- onClick: (e) => e.stopPropagation(),
2644
- onMouseDown: (e) => startResize(
2645
- e,
2646
- "row",
2647
- row.id,
2648
- rowHeight(row) || e.currentTarget.closest("tr").offsetHeight
2649
- )
2650
- }
2651
- )
2652
- ] }),
2653
- peer && /* @__PURE__ */ jsx13("span", { className: "shg-peer-flag", style: { background: peer.color }, children: peer.name }),
2654
- isEditing ? renderEditor(col) : /* @__PURE__ */ jsx13("div", { className: "shg-val", children: custom !== void 0 ? custom : /* @__PURE__ */ jsxs12(Fragment8, { children: [
2655
- computed && /* @__PURE__ */ jsx13(StatusDot, { status: c.status }),
2656
- /* @__PURE__ */ jsx13(CellValue, { cell: c, col, fetchBlobUrl, onOpenResource }),
2657
- computed && !readOnly && onRunCell && /* @__PURE__ */ jsx13(
2658
- "button",
2659
- {
2660
- className: "shg-runcell",
2661
- title: "Run this cell",
2662
- onClick: (e) => {
2663
- e.stopPropagation();
2664
- onRunCell(row.id, col.id);
2665
- },
2666
- children: "\u25B6"
2667
- }
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
2668
2675
  )
2669
- ] }) })
2670
- ]
2671
- },
2672
- col.id
2673
- );
2674
- }),
2675
- !readOnly && /* @__PURE__ */ jsx13("td", { className: "shg-pad" })
2676
- ]
2677
- },
2678
- row.id
2679
- )),
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)),
2680
2727
  !readOnly && /* @__PURE__ */ jsxs12("tr", { className: "shg-ghost-row", onClick: addRow, children: [
2681
2728
  /* @__PURE__ */ jsx13("td", { className: "shg-rownum shg-ghost-num", style: numStyle, children: "+" }),
2682
2729
  /* @__PURE__ */ jsx13("td", { className: "shg-ghost-cell", colSpan: columns.length + 1, children: "New row" })