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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reifyui",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4",
|
|
4
4
|
"description": "The open-source rendering & interaction layer for agentic applications. Stream and render any agent's output as polished, application-native UI \u2014 model-agnostic, framework-agnostic, design-system-native. The foundation for building generative-UI and agent products.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -68,7 +68,8 @@
|
|
|
68
68
|
"build": "tsup",
|
|
69
69
|
"prepublishOnly": "npm run build",
|
|
70
70
|
"clean": "rm -rf dist",
|
|
71
|
-
"prepare": "npm run build"
|
|
71
|
+
"prepare": "npm run build",
|
|
72
|
+
"test": "node test/run.mjs"
|
|
72
73
|
},
|
|
73
74
|
"peerDependencies": {
|
|
74
75
|
"echarts": "^5 || ^6",
|
package/src/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/src/sheet/SheetGrid.jsx
CHANGED
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
//
|
|
24
24
|
// Editing is optimistic: local edits call onChange with the next sheet; the host persists and
|
|
25
25
|
// hands truth back through `sheet`.
|
|
26
|
+
//
|
|
27
|
+
// Row heights: a row with no `height` fits its tallest cell, up to --shg-row-max (eight lines
|
|
28
|
+
// unless the host sets it); a cell with more than that scrolls inside itself. A row with a
|
|
29
|
+
// `height` (someone dragged it) is exactly that tall, and its cells scroll the same way.
|
|
26
30
|
import { useEffect, useRef, useState } from 'react';
|
|
27
31
|
import { createPortal } from 'react-dom';
|
|
28
32
|
|
|
@@ -68,6 +72,12 @@ const COMPUTE_KINDS = [
|
|
|
68
72
|
const RESOURCE_KINDS = ['image', 'sheet', 'slides', 'workflow', 'graph'];
|
|
69
73
|
const RESOURCE_ICON = { image: '🖼', sheet: '▦', slides: '▤', workflow: '⚙', graph: '◉' };
|
|
70
74
|
|
|
75
|
+
// Select and resource cells edit in a popover, so the cell keeps showing its value under it.
|
|
76
|
+
// Every other editable cell edits in place, and of those only these hold a single line.
|
|
77
|
+
const POPOVER_EDITORS = new Set(['select', 'resource']);
|
|
78
|
+
const SINGLE_LINE_EDITORS = new Set(['number', 'date', 'tags']);
|
|
79
|
+
const isMultiline = (col) => !SINGLE_LINE_EDITORS.has(col.type);
|
|
80
|
+
|
|
71
81
|
// Popovers render through a body portal with FIXED positioning — inside the grid they'd be
|
|
72
82
|
// clipped by the scroll container and out-stacked by the sticky header/row-number cells. anchor
|
|
73
83
|
// is a DOMRect captured at open time; the box clamps to the viewport and flips above the anchor
|
|
@@ -245,6 +255,10 @@ export function SheetGrid({
|
|
|
245
255
|
document.body.style.cursor = '';
|
|
246
256
|
if (!d) return;
|
|
247
257
|
setSizeDraft({});
|
|
258
|
+
// A press that never moved is not a resize. Committing it pinned the row at whatever height
|
|
259
|
+
// it had, and a pinned row stops fitting its content, so a click near a cell's bottom edge
|
|
260
|
+
// quietly froze the row.
|
|
261
|
+
if (d.last === d.start) return;
|
|
248
262
|
mutate((n) => {
|
|
249
263
|
if (d.kind === 'col') { const c = n.columns.find((x) => x.id === d.id); if (c) c.width = Math.round(d.last); }
|
|
250
264
|
else { const r = n.rows.find((x) => x.id === d.id); if (r) r.height = Math.round(d.last); }
|
|
@@ -308,8 +322,29 @@ export function SheetGrid({
|
|
|
308
322
|
const numW = Math.max(48, 30 + String(rows.length || 1).length * 9);
|
|
309
323
|
const numStyle = { width: numW, minWidth: numW, maxWidth: numW };
|
|
310
324
|
const rowHeight = (row) => (sizeDraft.row && sizeDraft.row[row.id]) || row.height || undefined;
|
|
325
|
+
// The table lays an unsized row out to its tallest cell, so a row fits on the first render,
|
|
326
|
+
// after an edit and while a column is dragged, with nothing to measure and nothing to store. A
|
|
327
|
+
// sized row becomes its own cap: its cells never push it past the height it was given.
|
|
328
|
+
const rowStyle = (row) => {
|
|
329
|
+
const h = rowHeight(row);
|
|
330
|
+
return {
|
|
331
|
+
...(h ? { height: h, '--shg-row-max': `${h - 1}px` } : null),
|
|
332
|
+
// The grid's own text wraps and no longer reads this; it stays for host cell bodies that do.
|
|
333
|
+
'--shg-clamp': Math.max(1, Math.floor(((h || 34) - 10) / 18)),
|
|
334
|
+
};
|
|
335
|
+
};
|
|
336
|
+
// Double-clicking a row's edge hands it back to its content, as it does in a spreadsheet.
|
|
337
|
+
const fitRow = (rowId) => mutate((n) => {
|
|
338
|
+
const r = n.rows.find((x) => x.id === rowId); if (r) delete r.height;
|
|
339
|
+
});
|
|
311
340
|
|
|
312
|
-
useEffect(() => {
|
|
341
|
+
useEffect(() => {
|
|
342
|
+
const el = editing && inputRef.current;
|
|
343
|
+
if (!el) return;
|
|
344
|
+
el.focus();
|
|
345
|
+
// Into a cell's text at its end, where an edit to a long value usually goes.
|
|
346
|
+
if (el.tagName === 'TEXTAREA') el.setSelectionRange(el.value.length, el.value.length);
|
|
347
|
+
}, [editing]);
|
|
313
348
|
|
|
314
349
|
const mutate = (fn) => {
|
|
315
350
|
if (readOnly || !onChange) return;
|
|
@@ -426,6 +461,20 @@ export function SheetGrid({
|
|
|
426
461
|
</PopPortal>
|
|
427
462
|
);
|
|
428
463
|
}
|
|
464
|
+
// Text edits in a textarea: an <input> strips line breaks from its value, so opening a
|
|
465
|
+
// multi-line cell and clicking away rewrote it as one line. Enter still commits, as in any
|
|
466
|
+
// spreadsheet; Shift+Enter is a new line inside the cell.
|
|
467
|
+
if (isMultiline(col)) {
|
|
468
|
+
return (
|
|
469
|
+
<textarea ref={inputRef} className="shg-input shg-input-area" value={draft} rows={1}
|
|
470
|
+
onChange={(e) => setDraft(e.target.value)}
|
|
471
|
+
onBlur={commitEdit}
|
|
472
|
+
onKeyDown={(e) => {
|
|
473
|
+
if (e.key === 'Enter' && !e.shiftKey && !e.nativeEvent.isComposing) { e.preventDefault(); commitEdit(); }
|
|
474
|
+
if (e.key === 'Escape') setEditing(null);
|
|
475
|
+
}} />
|
|
476
|
+
);
|
|
477
|
+
}
|
|
429
478
|
const inputType = col.type === 'date' ? 'date' : col.type === 'number' ? 'number' : 'text';
|
|
430
479
|
return (
|
|
431
480
|
<input ref={inputRef} className="shg-input" type={inputType} value={draft}
|
|
@@ -475,17 +524,15 @@ export function SheetGrid({
|
|
|
475
524
|
</thead>
|
|
476
525
|
<tbody>
|
|
477
526
|
{rows.map((row, ri) => (
|
|
478
|
-
<tr key={row.id} data-row-id={row.id}
|
|
479
|
-
style={{
|
|
480
|
-
...(rowHeight(row) ? { height: rowHeight(row) } : null),
|
|
481
|
-
'--shg-clamp': Math.max(1, Math.floor(((rowHeight(row) || 34) - 10) / 18)),
|
|
482
|
-
}}>
|
|
527
|
+
<tr key={row.id} data-row-id={row.id} style={rowStyle(row)}>
|
|
483
528
|
<td className={'shg-rownum' + dndClass('row', row.id)} style={numStyle}
|
|
484
529
|
title="Drag to reorder" {...dndProps('row', row.id)}>
|
|
485
530
|
<span>{ri + 1}</span>
|
|
486
531
|
{!readOnly && <button className="shg-rowdel" onClick={() => deleteRow(row.id)} title="Delete row">×</button>}
|
|
487
532
|
{!readOnly && (
|
|
488
|
-
<span className="shg-resize-row"
|
|
533
|
+
<span className="shg-resize-row" title="Drag to resize, double-click to fit"
|
|
534
|
+
onMouseDown={(e) => startResize(e, 'row', row.id, rowHeight(row) || e.currentTarget.closest('tr').offsetHeight)}
|
|
535
|
+
onDoubleClick={() => fitRow(row.id)} />
|
|
489
536
|
)}
|
|
490
537
|
</td>
|
|
491
538
|
{columns.map((col) => {
|
|
@@ -523,11 +570,21 @@ export function SheetGrid({
|
|
|
523
570
|
<span className="shg-resize-row shg-resize-in-cell"
|
|
524
571
|
onClick={(e) => e.stopPropagation()}
|
|
525
572
|
onMouseDown={(e) => startResize(e, 'row', row.id,
|
|
526
|
-
rowHeight(row) || e.currentTarget.closest('tr').offsetHeight)}
|
|
573
|
+
rowHeight(row) || e.currentTarget.closest('tr').offsetHeight)}
|
|
574
|
+
onDoubleClick={(e) => { e.stopPropagation(); fitRow(row.id); }} />
|
|
527
575
|
</>
|
|
528
576
|
)}
|
|
529
577
|
{peer && <span className="shg-peer-flag" style={{ background: peer.color }}>{peer.name}</span>}
|
|
530
|
-
{isEditing
|
|
578
|
+
{isEditing && renderEditor(col)}
|
|
579
|
+
{isEditing && !POPOVER_EDITORS.has(col.type) ? (
|
|
580
|
+
// The editor lies over the cell; this invisible copy of the draft holds the
|
|
581
|
+
// cell's place, so the row keeps its height while you type and grows with
|
|
582
|
+
// the draft, to the same cap as the value. The trailing zero-width space
|
|
583
|
+
// gives a draft that ends in a line break its last, empty line.
|
|
584
|
+
<div className="shg-val shg-val-mirror" aria-hidden="true">
|
|
585
|
+
<span className="shg-val-txt">{`${typeof draft === 'string' ? draft : ''}\u200b`}</span>
|
|
586
|
+
</div>
|
|
587
|
+
) : (
|
|
531
588
|
<div className="shg-val">
|
|
532
589
|
{custom !== undefined ? custom : (
|
|
533
590
|
<>
|
|
@@ -723,10 +780,10 @@ function ColumnMenu({ col, columns, anchor, columnTypes, renderColumnConfig, onA
|
|
|
723
780
|
/**
|
|
724
781
|
* The height each row would need to show its content in full, measured from what is on screen.
|
|
725
782
|
*
|
|
726
|
-
*
|
|
727
|
-
*
|
|
728
|
-
*
|
|
729
|
-
*
|
|
783
|
+
* Since 0.8.4 the grid fits a row with no stored height by itself, on every render, so a host no
|
|
784
|
+
* longer needs this to show a run's answer. Committing what it returns STORES a height, and a
|
|
785
|
+
* stored height is a row someone sized: it stops refitting when the column or the text changes.
|
|
786
|
+
* Kept for a host that wants exactly that.
|
|
730
787
|
*
|
|
731
788
|
* Measured, not estimated: `scrollHeight` is what the content actually occupies at this width,
|
|
732
789
|
* including the file cards. A formula over character counts would be a number nobody derived.
|
package/styles/sheet.css
CHANGED
|
@@ -14,17 +14,22 @@
|
|
|
14
14
|
border: 1px solid var(--uic-line, #DDDFE6);
|
|
15
15
|
padding: 0; height: 34px; box-sizing: border-box;
|
|
16
16
|
}
|
|
17
|
+
/* 34px is a row's floor; a row is as tall as its tallest cell. Every cell in it reads from the
|
|
18
|
+
top, level with the first line of that tallest one, rather than floating to the middle. */
|
|
19
|
+
.shg-table tbody td { vertical-align: top; }
|
|
17
20
|
.shg-corner, .shg-rownum {
|
|
18
21
|
background: var(--uic-surface-2, #F7F8FA);
|
|
19
22
|
text-align: center; color: var(--uic-mute-2, #8E9199); font-variant-numeric: tabular-nums;
|
|
20
23
|
position: sticky; left: 0; z-index: 3;
|
|
21
24
|
}
|
|
22
25
|
.shg-corner { z-index: 6; }
|
|
23
|
-
|
|
26
|
+
/* The number sits in a band the height of a one-line row, so it lines up with the first line of
|
|
27
|
+
a tall row as well as centering in a short one. */
|
|
28
|
+
.shg-rownum span { font-size: 12.5px; display: block; line-height: 32px; }
|
|
24
29
|
/* A 12x18 target for a destructive action was too small to hit deliberately and too small to
|
|
25
30
|
read. It is a real button now, and the gutter is wide enough to hold it beside the number. */
|
|
26
31
|
.shg-rowdel {
|
|
27
|
-
position: absolute; right: 3px; top:
|
|
32
|
+
position: absolute; right: 3px; top: 6px;
|
|
28
33
|
width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center;
|
|
29
34
|
border: none; border-radius: 5px; background: transparent; color: var(--uic-mute-2, #8E9199);
|
|
30
35
|
cursor: pointer; font-size: 17px; line-height: 1; opacity: 0; padding: 0;
|
|
@@ -64,21 +69,33 @@
|
|
|
64
69
|
.shg-cell:hover { background: var(--uic-surface-2, #F7F8FA); }
|
|
65
70
|
/* The cell is the constraint on its own value. This used to carry an inline max-width of the
|
|
66
71
|
column width minus 20, or 400px where the column had no explicit width — a number nothing
|
|
67
|
-
derived, which ellipsised a value long before its own cell ran out of room.
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
derived, which ellipsised a value long before its own cell ran out of room.
|
|
73
|
+
|
|
74
|
+
The value box is what sizes the row, and it stops at --shg-row-max: eight lines by default, or
|
|
75
|
+
the height of a row someone sized. Past that the value scrolls inside its own cell, so one
|
|
76
|
+
long cell can never turn its row into a page. A host changes the cap by setting the variable
|
|
77
|
+
on the grid or anywhere above it. */
|
|
78
|
+
.shg-val { display: flex; align-items: flex-start; gap: 6px; padding: 6px 10px;
|
|
79
|
+
width: 100%; min-width: 0; box-sizing: border-box;
|
|
80
|
+
max-height: var(--shg-row-max, calc(8 * 18px + 12px));
|
|
81
|
+
overflow-x: hidden; overflow-y: auto; scrollbar-width: thin; }
|
|
70
82
|
.shg-val-txt {
|
|
71
83
|
flex: 1; min-width: 0; color: var(--uic-ink, #111317); align-self: flex-start;
|
|
72
|
-
/*
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
display: -webkit-box; -webkit-box-orient: vertical;
|
|
76
|
-
-webkit-line-clamp: var(--shg-clamp, 1);
|
|
77
|
-
overflow: hidden; white-space: normal; word-break: break-word;
|
|
84
|
+
/* All of the value, as written: its own line breaks kept, and a long word or an address broken
|
|
85
|
+
at the cell's edge, never ellipsised and never pushed past it. */
|
|
86
|
+
white-space: pre-wrap; overflow-wrap: anywhere;
|
|
78
87
|
line-height: 18px;
|
|
79
88
|
}
|
|
80
|
-
.
|
|
81
|
-
|
|
89
|
+
/* The editor lies over its cell. Under it, an invisible copy of the draft (.shg-val-mirror) holds
|
|
90
|
+
the cell's place, so the row keeps its height while you type and grows with the draft. The ring
|
|
91
|
+
is a shadow, not a border, so the textarea wraps at exactly the width the copy does. */
|
|
92
|
+
.shg-val-mirror { visibility: hidden; }
|
|
93
|
+
.shg-input { position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%;
|
|
94
|
+
border: none; box-shadow: inset 0 0 0 2px var(--uic-brand, #285AFF); padding: 0 8px;
|
|
95
|
+
font-size: 13px; font-family: inherit; color: var(--uic-ink, #111317);
|
|
96
|
+
background: var(--uic-surface, #FFFFFF); outline: none; box-sizing: border-box; }
|
|
97
|
+
.shg-input-area { display: block; padding: 6px 10px; line-height: 18px; resize: none;
|
|
98
|
+
white-space: pre-wrap; overflow-wrap: anywhere; scrollbar-width: thin; }
|
|
82
99
|
.shg-runcell {
|
|
83
100
|
border: none; background: transparent; color: var(--uic-brand, #285AFF); cursor: pointer;
|
|
84
101
|
font-size: 10px; opacity: 0; flex-shrink: 0; padding: 2px 4px;
|
|
@@ -104,10 +121,12 @@
|
|
|
104
121
|
.shg-add-row:hover { border-color: var(--uic-brand, #285AFF); color: var(--uic-brand, #285AFF); }
|
|
105
122
|
|
|
106
123
|
/* ── Typed cell values ─────────────────────────────────────────────────── */
|
|
124
|
+
/* A long option wraps inside its pill like any other value. The radius is half a one-line pill's
|
|
125
|
+
height, so one line still reads as a pill and two read as a rounded box, not a lozenge. */
|
|
107
126
|
.shg-pill {
|
|
108
127
|
display: inline-flex; align-items: center; max-width: 100%;
|
|
109
|
-
padding: 1.5px 9px; border-radius:
|
|
110
|
-
color: var(--uic-ink, #1F2937); white-space:
|
|
128
|
+
padding: 1.5px 9px; border-radius: 10px; font-size: 12px; font-weight: 600;
|
|
129
|
+
color: var(--uic-ink, #1F2937); white-space: normal; overflow-wrap: anywhere;
|
|
111
130
|
}
|
|
112
131
|
.shg-pills { display: flex; gap: 4px; overflow: hidden; flex: 1; min-width: 0;
|
|
113
132
|
flex-wrap: wrap; max-height: 100%; align-content: center; }
|
|
@@ -117,8 +136,8 @@
|
|
|
117
136
|
font-size: 12px; font-weight: 700; color: var(--uic-on-brand, #fff); background: var(--uic-surface, #FFFFFF);
|
|
118
137
|
}
|
|
119
138
|
.shg-check.on { background: var(--uic-brand, #285AFF); border-color: var(--uic-brand, #285AFF); }
|
|
120
|
-
.shg-link { color: var(--uic-brand, #285AFF); text-decoration: none;
|
|
121
|
-
|
|
139
|
+
.shg-link { color: var(--uic-brand, #285AFF); text-decoration: none; line-height: 18px;
|
|
140
|
+
overflow-wrap: anywhere; flex: 1; min-width: 0; }
|
|
122
141
|
.shg-link:hover { text-decoration: underline; }
|
|
123
142
|
.shg-num { text-align: right; font-variant-numeric: tabular-nums; }
|
|
124
143
|
|
|
@@ -195,7 +214,8 @@
|
|
|
195
214
|
|
|
196
215
|
/* ── Ghost add-row (Airtable-style, attached to the grid) ───────────────── */
|
|
197
216
|
.shg-ghost-row { cursor: pointer; }
|
|
198
|
-
.shg-ghost-row td { border-color: var(--uic-line, #DDDFE6); background: var(--uic-surface, #FFFFFF);
|
|
217
|
+
.shg-ghost-row td { border-color: var(--uic-line, #DDDFE6); background: var(--uic-surface, #FFFFFF);
|
|
218
|
+
vertical-align: middle; }
|
|
199
219
|
.shg-ghost-num { color: var(--uic-mute-2, #8E9199); font-size: 15px !important; }
|
|
200
220
|
.shg-ghost-cell { color: var(--uic-mute-2, #8E9199); font-size: 12.5px; padding: 0 10px !important; }
|
|
201
221
|
.shg-ghost-row:hover td { background: var(--uic-brand-faint, #EFF3FF); }
|