reifyui 0.8.3 → 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/README.md +6 -0
- package/dist/index.cjs +154 -107
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +154 -107
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/src/index.d.ts +2 -0
- package/src/sheet/SheetGrid.jsx +70 -13
- package/styles/sheet.css +38 -18
package/README.md
CHANGED
|
@@ -257,6 +257,12 @@ const COLUMN_TYPES = [
|
|
|
257
257
|
/>
|
|
258
258
|
```
|
|
259
259
|
|
|
260
|
+
A cell shows all of its value. Text wraps at the cell's edge and keeps its own line breaks, and a
|
|
261
|
+
row grows to fit its tallest cell, up to eight lines; past that the cell scrolls inside itself, so
|
|
262
|
+
one long value never turns its row into a page. Set `--shg-row-max` on the grid or above it to move
|
|
263
|
+
the cap. A row with a `height` (someone dragged it) is exactly that tall, and double-clicking its
|
|
264
|
+
edge hands it back to its content.
|
|
265
|
+
|
|
260
266
|
`sheetToDelimited(sheet, sep, { cellText })` and `sheetToAoA(sheet, { cellText })` export the grid;
|
|
261
267
|
pass `cellText` so a custom column exports as something a person wants rather than as raw JSON.
|
|
262
268
|
|
package/dist/index.cjs
CHANGED
|
@@ -2357,6 +2357,9 @@ var COMPUTE_KINDS = [
|
|
|
2357
2357
|
];
|
|
2358
2358
|
var RESOURCE_KINDS = ["image", "sheet", "slides", "workflow", "graph"];
|
|
2359
2359
|
var RESOURCE_ICON = { image: "\u{1F5BC}", sheet: "\u25A6", slides: "\u25A4", workflow: "\u2699", graph: "\u25C9" };
|
|
2360
|
+
var POPOVER_EDITORS = /* @__PURE__ */ new Set(["select", "resource"]);
|
|
2361
|
+
var SINGLE_LINE_EDITORS = /* @__PURE__ */ new Set(["number", "date", "tags"]);
|
|
2362
|
+
var isMultiline = (col) => !SINGLE_LINE_EDITORS.has(col.type);
|
|
2360
2363
|
function PopPortal({ anchor, width = 250, estHeight = 300, className, children, onClose }) {
|
|
2361
2364
|
const boxRef = (0, import_react15.useRef)(null);
|
|
2362
2365
|
(0, import_react15.useEffect)(() => {
|
|
@@ -2529,6 +2532,7 @@ function SheetGrid({
|
|
|
2529
2532
|
document.body.style.cursor = "";
|
|
2530
2533
|
if (!d) return;
|
|
2531
2534
|
setSizeDraft({});
|
|
2535
|
+
if (d.last === d.start) return;
|
|
2532
2536
|
mutate((n) => {
|
|
2533
2537
|
if (d.kind === "col") {
|
|
2534
2538
|
const c = n.columns.find((x) => x.id === d.id);
|
|
@@ -2601,8 +2605,23 @@ function SheetGrid({
|
|
|
2601
2605
|
const numW = Math.max(48, 30 + String(rows.length || 1).length * 9);
|
|
2602
2606
|
const numStyle = { width: numW, minWidth: numW, maxWidth: numW };
|
|
2603
2607
|
const rowHeight = (row) => sizeDraft.row && sizeDraft.row[row.id] || row.height || void 0;
|
|
2608
|
+
const rowStyle = (row) => {
|
|
2609
|
+
const h = rowHeight(row);
|
|
2610
|
+
return {
|
|
2611
|
+
...h ? { height: h, "--shg-row-max": `${h - 1}px` } : null,
|
|
2612
|
+
// The grid's own text wraps and no longer reads this; it stays for host cell bodies that do.
|
|
2613
|
+
"--shg-clamp": Math.max(1, Math.floor(((h || 34) - 10) / 18))
|
|
2614
|
+
};
|
|
2615
|
+
};
|
|
2616
|
+
const fitRow = (rowId) => mutate((n) => {
|
|
2617
|
+
const r = n.rows.find((x) => x.id === rowId);
|
|
2618
|
+
if (r) delete r.height;
|
|
2619
|
+
});
|
|
2604
2620
|
(0, import_react15.useEffect)(() => {
|
|
2605
|
-
|
|
2621
|
+
const el = editing && inputRef.current;
|
|
2622
|
+
if (!el) return;
|
|
2623
|
+
el.focus();
|
|
2624
|
+
if (el.tagName === "TEXTAREA") el.setSelectionRange(el.value.length, el.value.length);
|
|
2606
2625
|
}, [editing]);
|
|
2607
2626
|
const mutate = (fn) => {
|
|
2608
2627
|
if (readOnly || !onChange) return;
|
|
@@ -2742,6 +2761,26 @@ function SheetGrid({
|
|
|
2742
2761
|
}
|
|
2743
2762
|
);
|
|
2744
2763
|
}
|
|
2764
|
+
if (isMultiline(col)) {
|
|
2765
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2766
|
+
"textarea",
|
|
2767
|
+
{
|
|
2768
|
+
ref: inputRef,
|
|
2769
|
+
className: "shg-input shg-input-area",
|
|
2770
|
+
value: draft,
|
|
2771
|
+
rows: 1,
|
|
2772
|
+
onChange: (e) => setDraft(e.target.value),
|
|
2773
|
+
onBlur: commitEdit,
|
|
2774
|
+
onKeyDown: (e) => {
|
|
2775
|
+
if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) {
|
|
2776
|
+
e.preventDefault();
|
|
2777
|
+
commitEdit();
|
|
2778
|
+
}
|
|
2779
|
+
if (e.key === "Escape") setEditing(null);
|
|
2780
|
+
}
|
|
2781
|
+
}
|
|
2782
|
+
);
|
|
2783
|
+
}
|
|
2745
2784
|
const inputType = col.type === "date" ? "date" : col.type === "number" ? "number" : "text";
|
|
2746
2785
|
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2747
2786
|
"input",
|
|
@@ -2800,114 +2839,122 @@ function SheetGrid({
|
|
|
2800
2839
|
!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: "+" }) })
|
|
2801
2840
|
] }) }),
|
|
2802
2841
|
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("tbody", { children: [
|
|
2803
|
-
rows.map((row, ri) => /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
"
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
style: numStyle,
|
|
2817
|
-
title: "Drag to reorder",
|
|
2818
|
-
...dndProps("row", row.id),
|
|
2819
|
-
children: [
|
|
2820
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: ri + 1 }),
|
|
2821
|
-
!readOnly && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { className: "shg-rowdel", onClick: () => deleteRow(row.id), title: "Delete row", children: "\xD7" }),
|
|
2822
|
-
!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) })
|
|
2823
|
-
]
|
|
2824
|
-
}
|
|
2825
|
-
),
|
|
2826
|
-
columns.map((col) => {
|
|
2827
|
-
const c = cells[cellKey(row.id, col.id)] || {};
|
|
2828
|
-
const computed = isComputed(col);
|
|
2829
|
-
const isEditing = editing && editing.rowId === row.id && editing.colId === col.id;
|
|
2830
|
-
const peer = peerMarks && peerMarks[cellKey(row.id, col.id)];
|
|
2831
|
-
const custom = renderCell && renderCell({
|
|
2832
|
-
cell: c,
|
|
2833
|
-
column: col,
|
|
2834
|
-
row,
|
|
2835
|
-
rowIndex: ri,
|
|
2836
|
-
sheet,
|
|
2837
|
-
computed,
|
|
2838
|
-
width: colWidth(col),
|
|
2839
|
-
height: rowHeight(row),
|
|
2840
|
-
editing: !!isEditing,
|
|
2841
|
-
readOnly,
|
|
2842
|
-
setCell: (v) => setCell(row.id, col.id, v),
|
|
2843
|
-
runCell: onRunCell && !readOnly ? () => onRunCell(row.id, col.id) : null
|
|
2844
|
-
});
|
|
2845
|
-
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
2846
|
-
"td",
|
|
2842
|
+
rows.map((row, ri) => /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("tr", { "data-row-id": row.id, style: rowStyle(row), children: [
|
|
2843
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
2844
|
+
"td",
|
|
2845
|
+
{
|
|
2846
|
+
className: "shg-rownum" + dndClass("row", row.id),
|
|
2847
|
+
style: numStyle,
|
|
2848
|
+
title: "Drag to reorder",
|
|
2849
|
+
...dndProps("row", row.id),
|
|
2850
|
+
children: [
|
|
2851
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: ri + 1 }),
|
|
2852
|
+
!readOnly && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { className: "shg-rowdel", onClick: () => deleteRow(row.id), title: "Delete row", children: "\xD7" }),
|
|
2853
|
+
!readOnly && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2854
|
+
"span",
|
|
2847
2855
|
{
|
|
2848
|
-
"
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
}
|
|
2856
|
+
className: "shg-resize-row",
|
|
2857
|
+
title: "Drag to resize, double-click to fit",
|
|
2858
|
+
onMouseDown: (e) => startResize(e, "row", row.id, rowHeight(row) || e.currentTarget.closest("tr").offsetHeight),
|
|
2859
|
+
onDoubleClick: () => fitRow(row.id)
|
|
2860
|
+
}
|
|
2861
|
+
)
|
|
2862
|
+
]
|
|
2863
|
+
}
|
|
2864
|
+
),
|
|
2865
|
+
columns.map((col) => {
|
|
2866
|
+
const c = cells[cellKey(row.id, col.id)] || {};
|
|
2867
|
+
const computed = isComputed(col);
|
|
2868
|
+
const isEditing = editing && editing.rowId === row.id && editing.colId === col.id;
|
|
2869
|
+
const peer = peerMarks && peerMarks[cellKey(row.id, col.id)];
|
|
2870
|
+
const custom = renderCell && renderCell({
|
|
2871
|
+
cell: c,
|
|
2872
|
+
column: col,
|
|
2873
|
+
row,
|
|
2874
|
+
rowIndex: ri,
|
|
2875
|
+
sheet,
|
|
2876
|
+
computed,
|
|
2877
|
+
width: colWidth(col),
|
|
2878
|
+
height: rowHeight(row),
|
|
2879
|
+
editing: !!isEditing,
|
|
2880
|
+
readOnly,
|
|
2881
|
+
setCell: (v) => setCell(row.id, col.id, v),
|
|
2882
|
+
runCell: onRunCell && !readOnly ? () => onRunCell(row.id, col.id) : null
|
|
2883
|
+
});
|
|
2884
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
2885
|
+
"td",
|
|
2886
|
+
{
|
|
2887
|
+
"data-col-id": col.id,
|
|
2888
|
+
className: "shg-cell" + (computed ? " shg-cell-compute" : "") + (c.status && computed ? ` shg-cell-${c.status}` : "") + (peer ? " shg-cell-peer" : ""),
|
|
2889
|
+
style: peer ? { boxShadow: `inset 0 0 0 2px ${peer.color}` } : void 0,
|
|
2890
|
+
onClick: (e) => {
|
|
2891
|
+
if (!isEditing) openEdit(row.id, col, e.currentTarget);
|
|
2892
|
+
},
|
|
2893
|
+
title: c.error || "",
|
|
2894
|
+
children: [
|
|
2895
|
+
!readOnly && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
|
|
2896
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2897
|
+
"span",
|
|
2898
|
+
{
|
|
2899
|
+
className: "shg-resize-col shg-resize-in-cell",
|
|
2900
|
+
onClick: (e) => e.stopPropagation(),
|
|
2901
|
+
onMouseDown: (e) => startResize(
|
|
2902
|
+
e,
|
|
2903
|
+
"col",
|
|
2904
|
+
col.id,
|
|
2905
|
+
colWidth(col) || e.currentTarget.closest("td").offsetWidth
|
|
2899
2906
|
)
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2907
|
+
}
|
|
2908
|
+
),
|
|
2909
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2910
|
+
"span",
|
|
2911
|
+
{
|
|
2912
|
+
className: "shg-resize-row shg-resize-in-cell",
|
|
2913
|
+
onClick: (e) => e.stopPropagation(),
|
|
2914
|
+
onMouseDown: (e) => startResize(
|
|
2915
|
+
e,
|
|
2916
|
+
"row",
|
|
2917
|
+
row.id,
|
|
2918
|
+
rowHeight(row) || e.currentTarget.closest("tr").offsetHeight
|
|
2919
|
+
),
|
|
2920
|
+
onDoubleClick: (e) => {
|
|
2921
|
+
e.stopPropagation();
|
|
2922
|
+
fitRow(row.id);
|
|
2923
|
+
}
|
|
2924
|
+
}
|
|
2925
|
+
)
|
|
2926
|
+
] }),
|
|
2927
|
+
peer && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "shg-peer-flag", style: { background: peer.color }, children: peer.name }),
|
|
2928
|
+
isEditing && renderEditor(col),
|
|
2929
|
+
isEditing && !POPOVER_EDITORS.has(col.type) ? (
|
|
2930
|
+
// The editor lies over the cell; this invisible copy of the draft holds the
|
|
2931
|
+
// cell's place, so the row keeps its height while you type and grows with
|
|
2932
|
+
// the draft, to the same cap as the value. The trailing zero-width space
|
|
2933
|
+
// gives a draft that ends in a line break its last, empty line.
|
|
2934
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "shg-val shg-val-mirror", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "shg-val-txt", children: `${typeof draft === "string" ? draft : ""}\u200B` }) })
|
|
2935
|
+
) : /* @__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: [
|
|
2936
|
+
computed && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(StatusDot, { status: c.status }),
|
|
2937
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(CellValue, { cell: c, col, fetchBlobUrl, onOpenResource }),
|
|
2938
|
+
computed && !readOnly && onRunCell && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2939
|
+
"button",
|
|
2940
|
+
{
|
|
2941
|
+
className: "shg-runcell",
|
|
2942
|
+
title: "Run this cell",
|
|
2943
|
+
onClick: (e) => {
|
|
2944
|
+
e.stopPropagation();
|
|
2945
|
+
onRunCell(row.id, col.id);
|
|
2946
|
+
},
|
|
2947
|
+
children: "\u25B6"
|
|
2948
|
+
}
|
|
2949
|
+
)
|
|
2950
|
+
] }) })
|
|
2951
|
+
]
|
|
2952
|
+
},
|
|
2953
|
+
col.id
|
|
2954
|
+
);
|
|
2955
|
+
}),
|
|
2956
|
+
!readOnly && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("td", { className: "shg-pad" })
|
|
2957
|
+
] }, row.id)),
|
|
2911
2958
|
!readOnly && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("tr", { className: "shg-ghost-row", onClick: addRow, children: [
|
|
2912
2959
|
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("td", { className: "shg-rownum shg-ghost-num", style: numStyle, children: "+" }),
|
|
2913
2960
|
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("td", { className: "shg-ghost-cell", colSpan: columns.length + 1, children: "New row" })
|