reifyui 0.4.2 → 0.5.1
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 +38 -1
- package/dist/chunk-2LYV4PIX.js +97 -0
- package/dist/chunk-2LYV4PIX.js.map +1 -0
- package/dist/harness.cjs +310 -0
- package/dist/harness.cjs.map +1 -0
- package/dist/harness.d.ts +88 -0
- package/dist/harness.js +212 -0
- package/dist/harness.js.map +1 -0
- package/dist/index.cjs +205 -113
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +87 -3
- package/dist/index.js +210 -203
- package/dist/index.js.map +1 -1
- package/package.json +6 -1
- package/src/harness/index.d.ts +88 -0
- package/src/harness/index.js +266 -0
- package/src/index.d.ts +87 -3
- package/src/sheet/SheetGrid.jsx +225 -112
- package/styles/sheet.css +76 -71
- package/styles/themes/dark.css +3 -0
- package/styles/themes/light.css +3 -0
package/src/sheet/SheetGrid.jsx
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
// SheetGrid — the reusable AI-spreadsheet grid
|
|
1
|
+
// SheetGrid — the reusable AI-spreadsheet grid.
|
|
2
2
|
//
|
|
3
|
-
// Product-agnostic: it renders a sheet JSON and calls back for edits/runs.
|
|
4
|
-
//
|
|
5
|
-
// mount it via @ui-core, so a Space can nest a sheet-typed element with the
|
|
6
|
-
// same component. All I/O is injected — this file has no product API.
|
|
3
|
+
// Product-agnostic: it renders a sheet JSON and calls back for edits/runs. All I/O is injected —
|
|
4
|
+
// this file has no product API.
|
|
7
5
|
//
|
|
8
|
-
// Sheet shape
|
|
9
|
-
// { meta{title
|
|
10
|
-
// rows[{id}], cells{ "<rowId>:<colId>": {value
|
|
6
|
+
// Sheet shape:
|
|
7
|
+
// { meta{title}, columns[{id,name,type,options?,width?}],
|
|
8
|
+
// rows[{id,height?}], cells{ "<rowId>:<colId>": {value,…} } }
|
|
11
9
|
//
|
|
12
10
|
// Props:
|
|
13
11
|
// sheet — the sheet JSON (required)
|
|
@@ -15,23 +13,52 @@
|
|
|
15
13
|
// onRunCell(rowId, colId) — run one computed cell (optional)
|
|
16
14
|
// onRunColumn(colId) — batch-run a computed column (optional)
|
|
17
15
|
// readOnly — no editing/running (template previews / embedded read views)
|
|
18
|
-
// fetchBlobUrl(path) — async product-authed fetch -> object URL, for
|
|
19
|
-
//
|
|
16
|
+
// fetchBlobUrl(path) — async product-authed fetch -> object URL, for inline images
|
|
17
|
+
// whose url is a product path
|
|
20
18
|
// onOpenResource(ref) — open a referenced artifact (sheet/slides/…)
|
|
19
|
+
// columnTypes — the column vocabulary (see SheetColumnType below). Defaults to
|
|
20
|
+
// this file's own set, so existing hosts need not pass it.
|
|
21
|
+
// renderCell(ctx) — replace a cell's body. Return undefined to fall through.
|
|
22
|
+
// renderColumnConfig(ctx) — replace the column popover's body. Return undefined to fall through.
|
|
21
23
|
//
|
|
22
|
-
// Editing is optimistic: local edits call onChange with the next sheet; the
|
|
23
|
-
//
|
|
24
|
+
// Editing is optimistic: local edits call onChange with the next sheet; the host persists and
|
|
25
|
+
// hands truth back through `sheet`.
|
|
24
26
|
import { useEffect, useRef, useState } from 'react';
|
|
25
27
|
import { createPortal } from 'react-dom';
|
|
26
28
|
|
|
27
29
|
const cellKey = (rowId, colId) => `${rowId}:${colId}`;
|
|
28
30
|
const uid = (p) => `${p}_${Math.random().toString(36).slice(2, 10)}`;
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
// A column type is a descriptor, not a hardcoded literal. This grid used to test
|
|
33
|
+
// `col.type === 'compute'` in twelve places, which meant a host could not add a column kind
|
|
34
|
+
// without forking the file — and a fork is how two copies of one component start.
|
|
35
|
+
//
|
|
36
|
+
// type the value stored in column.type
|
|
37
|
+
// label what the type menu and the header sub-label show
|
|
38
|
+
// computed the app fills these cells, not the person: status dot, tint, run affordances
|
|
39
|
+
// editable defaults to !computed
|
|
40
|
+
// configKey the column's config object for this type; dropped when the type changes
|
|
41
|
+
// badge(col) an extra header sub-label, e.g. which kind of compute this is
|
|
42
|
+
// configWidth / configHeight how much room this type's config popover needs. A type whose
|
|
43
|
+
// config is a prompt editor does not fit in the width a Type select needs.
|
|
44
|
+
const DEFAULT_COLUMN_TYPES = [
|
|
45
|
+
{ type: 'text', label: 'Text' },
|
|
46
|
+
{ type: 'number', label: 'Number' },
|
|
47
|
+
{ type: 'select', label: 'Select' },
|
|
48
|
+
{ type: 'tags', label: 'Tags' },
|
|
49
|
+
{ type: 'checkbox', label: 'Checkbox' },
|
|
50
|
+
{ type: 'date', label: 'Date' },
|
|
51
|
+
{ type: 'url', label: 'Link' },
|
|
52
|
+
{ type: 'resource', label: 'Resource' },
|
|
53
|
+
{
|
|
54
|
+
type: 'compute',
|
|
55
|
+
label: 'Computed',
|
|
56
|
+
computed: true,
|
|
57
|
+
configKey: 'compute',
|
|
58
|
+
badge: (col) => col.compute?.kind,
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
|
|
35
62
|
const COMPUTE_KINDS = [
|
|
36
63
|
{ kind: 'prompt', label: 'AI prompt' },
|
|
37
64
|
{ kind: 'harness', label: 'Agent (harness)' },
|
|
@@ -41,25 +68,40 @@ const COMPUTE_KINDS = [
|
|
|
41
68
|
const RESOURCE_KINDS = ['image', 'sheet', 'slides', 'workflow', 'graph'];
|
|
42
69
|
const RESOURCE_ICON = { image: '🖼', sheet: '▦', slides: '▤', workflow: '⚙', graph: '◉' };
|
|
43
70
|
|
|
44
|
-
// Popovers render through a body portal with FIXED positioning — inside the
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
// the
|
|
48
|
-
// would overflow. Any scroll closes it (the anchor moved).
|
|
71
|
+
// Popovers render through a body portal with FIXED positioning — inside the grid they'd be
|
|
72
|
+
// clipped by the scroll container and out-stacked by the sticky header/row-number cells. anchor
|
|
73
|
+
// is a DOMRect captured at open time; the box clamps to the viewport and flips above the anchor
|
|
74
|
+
// when the bottom would overflow. Any scroll closes it (the anchor moved).
|
|
49
75
|
function PopPortal({ anchor, width = 250, estHeight = 300, className, children, onClose }) {
|
|
76
|
+
const boxRef = useRef(null);
|
|
50
77
|
useEffect(() => {
|
|
51
78
|
if (!onClose) return undefined;
|
|
52
79
|
const close = () => onClose();
|
|
80
|
+
// mousedown, not click: React 18 flushes a listener attached in this effect synchronously
|
|
81
|
+
// during the very discrete event that opened the popover, so a `click` listener closes the
|
|
82
|
+
// box before it paints. A press inside the anchor is also ignored — that is the trigger's
|
|
83
|
+
// own toggle, and closing here would race it into staying open.
|
|
84
|
+
const onDown = (e) => {
|
|
85
|
+
if (boxRef.current && boxRef.current.contains(e.target)) return;
|
|
86
|
+
if (anchor && e.clientX >= anchor.left && e.clientX <= anchor.right
|
|
87
|
+
&& e.clientY >= anchor.top && e.clientY <= anchor.bottom) return;
|
|
88
|
+
onClose();
|
|
89
|
+
};
|
|
90
|
+
window.addEventListener('mousedown', onDown);
|
|
53
91
|
window.addEventListener('scroll', close, true);
|
|
54
92
|
window.addEventListener('resize', close);
|
|
55
|
-
return () => {
|
|
56
|
-
|
|
93
|
+
return () => {
|
|
94
|
+
window.removeEventListener('mousedown', onDown);
|
|
95
|
+
window.removeEventListener('scroll', close, true);
|
|
96
|
+
window.removeEventListener('resize', close);
|
|
97
|
+
};
|
|
98
|
+
}, [onClose, anchor]);
|
|
57
99
|
if (!anchor) return null;
|
|
58
100
|
const left = Math.max(8, Math.min(anchor.right - width, window.innerWidth - width - 8));
|
|
59
101
|
let top = anchor.bottom + 6;
|
|
60
102
|
if (top + estHeight > window.innerHeight - 8) top = Math.max(8, anchor.top - estHeight - 6);
|
|
61
103
|
return createPortal(
|
|
62
|
-
<div className={className} style={{ position: 'fixed', top, left, width, zIndex: 1000 }}>
|
|
104
|
+
<div ref={boxRef} className={className} style={{ position: 'fixed', top, left, width, zIndex: 1000 }}>
|
|
63
105
|
{children}
|
|
64
106
|
</div>,
|
|
65
107
|
document.body,
|
|
@@ -120,8 +162,8 @@ function StatusDot({ status }) {
|
|
|
120
162
|
function CellValue({ cell, col, fetchBlobUrl, onOpenResource }) {
|
|
121
163
|
const v = cell?.value;
|
|
122
164
|
if (v === undefined || v === null || v === '') return <span className="shg-val-txt" />;
|
|
123
|
-
// A typed artifact ref renders the same whether hand-set (resource column)
|
|
124
|
-
//
|
|
165
|
+
// A typed artifact ref renders the same whether hand-set (resource column) or produced by a
|
|
166
|
+
// compute kind (e.g. Generate image).
|
|
125
167
|
if (v && typeof v === 'object' && !Array.isArray(v) && v.kind) {
|
|
126
168
|
if (v.kind === 'image') return <RefImage refVal={v} fetchBlobUrl={fetchBlobUrl} />;
|
|
127
169
|
return <ResourceChip refVal={v} onOpen={onOpenResource} />;
|
|
@@ -152,7 +194,10 @@ function CellValue({ cell, col, fetchBlobUrl, onOpenResource }) {
|
|
|
152
194
|
}
|
|
153
195
|
}
|
|
154
196
|
|
|
155
|
-
export function SheetGrid({
|
|
197
|
+
export function SheetGrid({
|
|
198
|
+
sheet, onChange, onRunCell, onRunColumn, readOnly = false, fetchBlobUrl, onOpenResource,
|
|
199
|
+
peerMarks, onActiveCell, columnTypes = DEFAULT_COLUMN_TYPES, renderCell, renderColumnConfig,
|
|
200
|
+
}) {
|
|
156
201
|
const columns = sheet?.columns || [];
|
|
157
202
|
const rows = sheet?.rows || [];
|
|
158
203
|
const cells = sheet?.cells || {};
|
|
@@ -165,6 +210,15 @@ export function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly =
|
|
|
165
210
|
const inputRef = useRef(null);
|
|
166
211
|
const dragRef = useRef(null);
|
|
167
212
|
|
|
213
|
+
// An unknown type still renders — as plain text, editable. Refusing to draw a column because
|
|
214
|
+
// its type is unfamiliar would hide the person's data from them.
|
|
215
|
+
const descOf = (type) => columnTypes.find((t) => t.type === type) || { type, label: type };
|
|
216
|
+
const isComputed = (col) => !!descOf(col?.type).computed;
|
|
217
|
+
const isEditable = (col) => {
|
|
218
|
+
const d = descOf(col?.type);
|
|
219
|
+
return d.editable ?? !d.computed;
|
|
220
|
+
};
|
|
221
|
+
|
|
168
222
|
// Drag-to-resize: live via sizeDraft, persisted into the sheet on release.
|
|
169
223
|
const startResize = (e, kind, id, start) => {
|
|
170
224
|
if (readOnly) return;
|
|
@@ -242,8 +296,8 @@ export function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly =
|
|
|
242
296
|
}
|
|
243
297
|
return cls;
|
|
244
298
|
};
|
|
245
|
-
// The number gutter is FIXED: sized by the digit count of the row total so
|
|
246
|
-
//
|
|
299
|
+
// The number gutter is FIXED: sized by the digit count of the row total so it never stretches
|
|
300
|
+
// (an empty grid otherwise splits the table width).
|
|
247
301
|
const numW = Math.max(40, 24 + String(rows.length || 1).length * 9);
|
|
248
302
|
const numStyle = { width: numW, minWidth: numW, maxWidth: numW };
|
|
249
303
|
const rowHeight = (row) => (sizeDraft.row && sizeDraft.row[row.id]) || row.height || undefined;
|
|
@@ -257,14 +311,22 @@ export function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly =
|
|
|
257
311
|
onChange(next);
|
|
258
312
|
};
|
|
259
313
|
|
|
314
|
+
// A manual edit writes the value and nothing else. It used to stamp `status:'done'`, which
|
|
315
|
+
// made every hand-typed cell claim to be the output of a run that never happened — and forced
|
|
316
|
+
// status rendering to be gated on the column type rather than on the cell. On a computed
|
|
317
|
+
// column the surrounding run record is kept, because there an override sits on top of a real
|
|
318
|
+
// run and the link to that run is still true.
|
|
260
319
|
const setCell = (rowId, colId, value) => mutate((n) => {
|
|
261
320
|
n.cells = n.cells || {};
|
|
262
|
-
|
|
321
|
+
const k = cellKey(rowId, colId);
|
|
322
|
+
const col = (n.columns || []).find((c) => c.id === colId);
|
|
323
|
+
const prev = n.cells[k];
|
|
324
|
+
n.cells[k] = isComputed(col) && prev ? { ...prev, value } : { value };
|
|
263
325
|
});
|
|
264
326
|
|
|
265
327
|
const openEdit = (rowId, col, anchorEl) => {
|
|
266
328
|
if (readOnly) return;
|
|
267
|
-
if (col
|
|
329
|
+
if (!isEditable(col)) return;
|
|
268
330
|
if (col.type === 'checkbox') { // click toggles directly
|
|
269
331
|
const cur = cells[cellKey(rowId, col.id)];
|
|
270
332
|
setCell(rowId, col.id, !(cur && cur.value));
|
|
@@ -308,7 +370,11 @@ export function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly =
|
|
|
308
370
|
const configureColumn = (colId, patch) => mutate((n) => {
|
|
309
371
|
const c = n.columns.find((x) => x.id === colId); if (!c) return;
|
|
310
372
|
Object.assign(c, patch);
|
|
311
|
-
|
|
373
|
+
// A column carries the config of its own type and no other. Changing the type takes the old
|
|
374
|
+
// config with it, so a harness column that becomes a text column stops carrying a prompt.
|
|
375
|
+
if (patch.type) {
|
|
376
|
+
for (const d of columnTypes) if (d.configKey && d.type !== patch.type) delete c[d.configKey];
|
|
377
|
+
}
|
|
312
378
|
});
|
|
313
379
|
|
|
314
380
|
// The inline editor for the editing cell, by type.
|
|
@@ -372,7 +438,7 @@ export function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly =
|
|
|
372
438
|
<th className="shg-corner" style={numStyle} />
|
|
373
439
|
{columns.map((col) => (
|
|
374
440
|
<th key={col.id}
|
|
375
|
-
className={'shg-col' + (col
|
|
441
|
+
className={'shg-col' + (isComputed(col) ? ' shg-col-compute' : '') + dndClass('col', col.id)}
|
|
376
442
|
style={colWidth(col) ? { width: colWidth(col), minWidth: colWidth(col), maxWidth: colWidth(col) } : undefined}
|
|
377
443
|
{...dndProps('col', col.id)}>
|
|
378
444
|
{!readOnly && (
|
|
@@ -381,6 +447,8 @@ export function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly =
|
|
|
381
447
|
<div className="shg-col-h">
|
|
382
448
|
<ColumnHeader
|
|
383
449
|
col={col} columns={columns} readOnly={readOnly}
|
|
450
|
+
desc={descOf(col.type)} columnTypes={columnTypes}
|
|
451
|
+
renderColumnConfig={renderColumnConfig}
|
|
384
452
|
menuOpen={menuCol?.id === col.id}
|
|
385
453
|
menuAnchor={menuCol?.id === col.id ? menuCol.rect : null}
|
|
386
454
|
onMenu={(e) => setMenuCol(menuCol?.id === col.id ? null
|
|
@@ -389,7 +457,7 @@ export function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly =
|
|
|
389
457
|
onRename={renameColumn}
|
|
390
458
|
onConfigure={configureColumn}
|
|
391
459
|
onDelete={() => { setMenuCol(null); deleteColumn(col.id); }}
|
|
392
|
-
onRun={col
|
|
460
|
+
onRun={isComputed(col) && onRunColumn ? () => onRunColumn(col.id) : null} />
|
|
393
461
|
</div>
|
|
394
462
|
</th>
|
|
395
463
|
))}
|
|
@@ -415,12 +483,22 @@ export function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly =
|
|
|
415
483
|
</td>
|
|
416
484
|
{columns.map((col) => {
|
|
417
485
|
const c = cells[cellKey(row.id, col.id)] || {};
|
|
486
|
+
const computed = isComputed(col);
|
|
418
487
|
const isEditing = editing && editing.rowId === row.id && editing.colId === col.id;
|
|
419
488
|
const peer = peerMarks && peerMarks[cellKey(row.id, col.id)];
|
|
489
|
+
// A host owns the whole cell body when it wants to: a running cell's live text
|
|
490
|
+
// lives in the host's run store, not in the sheet JSON, so only a closure can
|
|
491
|
+
// reach it. Returning undefined falls through to the built-in rendering.
|
|
492
|
+
const custom = renderCell && renderCell({
|
|
493
|
+
cell: c, column: col, row, rowIndex: ri, sheet, computed,
|
|
494
|
+
width: colWidth(col), height: rowHeight(row), editing: !!isEditing, readOnly,
|
|
495
|
+
setCell: (v) => setCell(row.id, col.id, v),
|
|
496
|
+
runCell: onRunCell && !readOnly ? () => onRunCell(row.id, col.id) : null,
|
|
497
|
+
});
|
|
420
498
|
return (
|
|
421
499
|
<td key={col.id}
|
|
422
|
-
className={'shg-cell' + (
|
|
423
|
-
+ (c.status &&
|
|
500
|
+
className={'shg-cell' + (computed ? ' shg-cell-compute' : '')
|
|
501
|
+
+ (c.status && computed ? ` shg-cell-${c.status}` : '')
|
|
424
502
|
+ (peer ? ' shg-cell-peer' : '')}
|
|
425
503
|
style={peer ? { boxShadow: `inset 0 0 0 2px ${peer.color}` } : undefined}
|
|
426
504
|
onClick={(e) => { if (!isEditing) openEdit(row.id, col, e.currentTarget); }}
|
|
@@ -429,11 +507,15 @@ export function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly =
|
|
|
429
507
|
{isEditing ? renderEditor(col) : (
|
|
430
508
|
<div className="shg-val"
|
|
431
509
|
style={{ maxWidth: (colWidth(col) ? colWidth(col) - 20 : 400) }}>
|
|
432
|
-
{
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
510
|
+
{custom !== undefined ? custom : (
|
|
511
|
+
<>
|
|
512
|
+
{computed && <StatusDot status={c.status} />}
|
|
513
|
+
<CellValue cell={c} col={col} fetchBlobUrl={fetchBlobUrl} onOpenResource={onOpenResource} />
|
|
514
|
+
{computed && !readOnly && onRunCell && (
|
|
515
|
+
<button className="shg-runcell" title="Run this cell"
|
|
516
|
+
onClick={(e) => { e.stopPropagation(); onRunCell(row.id, col.id); }}>▶</button>
|
|
517
|
+
)}
|
|
518
|
+
</>
|
|
437
519
|
)}
|
|
438
520
|
</div>
|
|
439
521
|
)}
|
|
@@ -456,10 +538,14 @@ export function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly =
|
|
|
456
538
|
);
|
|
457
539
|
}
|
|
458
540
|
|
|
459
|
-
function ColumnHeader({
|
|
541
|
+
function ColumnHeader({
|
|
542
|
+
col, columns, readOnly, desc, columnTypes, renderColumnConfig,
|
|
543
|
+
menuOpen, menuAnchor, onMenu, onCloseMenu, onRename, onConfigure, onDelete, onRun,
|
|
544
|
+
}) {
|
|
460
545
|
const [editing, setEditing] = useState(false);
|
|
461
546
|
const [name, setName] = useState(col.name);
|
|
462
547
|
useEffect(() => setName(col.name), [col.name]);
|
|
548
|
+
const badge = desc.badge ? desc.badge(col) : undefined;
|
|
463
549
|
return (
|
|
464
550
|
<div className="shg-colhdr">
|
|
465
551
|
<div className="shg-colhdr-main">
|
|
@@ -471,9 +557,9 @@ function ColumnHeader({ col, columns, readOnly, menuOpen, menuAnchor, onMenu, on
|
|
|
471
557
|
) : (
|
|
472
558
|
<span className="shg-colname" onDoubleClick={() => !readOnly && setEditing(true)} title={col.name}>{col.name}</span>
|
|
473
559
|
)}
|
|
474
|
-
<span className={'shg-coltype' + (
|
|
475
|
-
{
|
|
476
|
-
{
|
|
560
|
+
<span className={'shg-coltype' + (desc.computed ? ' compute' : '')}>
|
|
561
|
+
{desc.label || col.type}
|
|
562
|
+
{badge ? ` · ${badge}` : ''}
|
|
477
563
|
</span>
|
|
478
564
|
</div>
|
|
479
565
|
{!readOnly && (
|
|
@@ -484,6 +570,7 @@ function ColumnHeader({ col, columns, readOnly, menuOpen, menuAnchor, onMenu, on
|
|
|
484
570
|
)}
|
|
485
571
|
{menuOpen && !readOnly && (
|
|
486
572
|
<ColumnMenu col={col} columns={columns} anchor={menuAnchor}
|
|
573
|
+
columnTypes={columnTypes} renderColumnConfig={renderColumnConfig}
|
|
487
574
|
onApply={(patch) => { onConfigure(col.id, patch); onCloseMenu(); }}
|
|
488
575
|
onDelete={onDelete} onClose={onCloseMenu} />
|
|
489
576
|
)}
|
|
@@ -491,10 +578,10 @@ function ColumnHeader({ col, columns, readOnly, menuOpen, menuAnchor, onMenu, on
|
|
|
491
578
|
);
|
|
492
579
|
}
|
|
493
580
|
|
|
494
|
-
// The column configuration popover: type, options (select/tags), and the
|
|
495
|
-
//
|
|
496
|
-
//
|
|
497
|
-
function ColumnMenu({ col, columns, anchor, onApply, onDelete, onClose }) {
|
|
581
|
+
// The column configuration popover: type, options (select/tags), and the type's own config body.
|
|
582
|
+
// Product-agnostic — plain controlled inputs, applied as one patch. A host that adds a column
|
|
583
|
+
// type supplies renderColumnConfig and owns the body below the Type select.
|
|
584
|
+
function ColumnMenu({ col, columns, anchor, columnTypes, renderColumnConfig, onApply, onDelete, onClose }) {
|
|
498
585
|
const [type, setType] = useState(col.type || 'text');
|
|
499
586
|
const [optText, setOptText] = useState(
|
|
500
587
|
normOptions(col.options).map((o) => o.label).join('\n'));
|
|
@@ -505,13 +592,6 @@ function ColumnMenu({ col, columns, anchor, onApply, onDelete, onClose }) {
|
|
|
505
592
|
const [wfSlug, setWfSlug] = useState(comp.workflow_slug || '');
|
|
506
593
|
const [outKey, setOutKey] = useState(comp.output_key || '');
|
|
507
594
|
const [deps, setDeps] = useState(new Set(comp.deps || []));
|
|
508
|
-
const ref = useRef(null);
|
|
509
|
-
|
|
510
|
-
useEffect(() => {
|
|
511
|
-
const onDown = (e) => { if (ref.current && !ref.current.contains(e.target)) onClose(); };
|
|
512
|
-
window.addEventListener('mousedown', onDown);
|
|
513
|
-
return () => window.removeEventListener('mousedown', onDown);
|
|
514
|
-
}, [onClose]);
|
|
515
595
|
|
|
516
596
|
const others = columns.filter((c) => c.id !== col.id);
|
|
517
597
|
const toggleDep = (id) => setDeps((s) => {
|
|
@@ -525,6 +605,7 @@ function ColumnMenu({ col, columns, anchor, onApply, onDelete, onClose }) {
|
|
|
525
605
|
if (type === 'select' || type === 'tags') {
|
|
526
606
|
patch.options = optText.split('\n').map((s) => s.trim()).filter(Boolean);
|
|
527
607
|
}
|
|
608
|
+
// The built-in 'compute' type's own editor. Any other type's config comes from the host.
|
|
528
609
|
if (type === 'compute') {
|
|
529
610
|
const compute = { kind, deps: [...deps] };
|
|
530
611
|
if (kind === 'prompt') compute.prompt = prompt;
|
|
@@ -535,13 +616,23 @@ function ColumnMenu({ col, columns, anchor, onApply, onDelete, onClose }) {
|
|
|
535
616
|
onApply(patch);
|
|
536
617
|
};
|
|
537
618
|
|
|
619
|
+
// A custom body owns its own primary action, because only it knows when its config is
|
|
620
|
+
// complete. It gets applyPatch to commit and close in one call.
|
|
621
|
+
const custom = renderColumnConfig && renderColumnConfig({
|
|
622
|
+
column: col, columns, type,
|
|
623
|
+
applyPatch: (patch) => onApply({ type, ...patch }),
|
|
624
|
+
deleteColumn: onDelete,
|
|
625
|
+
close: onClose,
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
const desc = columnTypes.find((t) => t.type === type) || {};
|
|
538
629
|
return (
|
|
539
|
-
<PopPortal anchor={anchor} width={250} estHeight={
|
|
540
|
-
|
|
630
|
+
<PopPortal anchor={anchor} width={desc.configWidth || 250} estHeight={desc.configHeight || 340}
|
|
631
|
+
className="shg-menu" onClose={onClose}>
|
|
632
|
+
<div onClick={(e) => e.stopPropagation()}>
|
|
541
633
|
<label className="shg-menu-lbl">Type
|
|
542
634
|
<select className="shg-menu-input" value={type} onChange={(e) => setType(e.target.value)}>
|
|
543
|
-
{
|
|
544
|
-
<option value="compute">Computed</option>
|
|
635
|
+
{columnTypes.map((t) => <option key={t.type} value={t.type}>{t.label}</option>)}
|
|
545
636
|
</select>
|
|
546
637
|
</label>
|
|
547
638
|
|
|
@@ -552,82 +643,104 @@ function ColumnMenu({ col, columns, anchor, onApply, onDelete, onClose }) {
|
|
|
552
643
|
</label>
|
|
553
644
|
)}
|
|
554
645
|
|
|
555
|
-
{
|
|
646
|
+
{custom !== undefined ? custom : (
|
|
556
647
|
<>
|
|
557
|
-
|
|
558
|
-
<select className="shg-menu-input" value={kind} onChange={(e) => setKind(e.target.value)}>
|
|
559
|
-
{COMPUTE_KINDS.map((k) => <option key={k.kind} value={k.kind}>{k.label}</option>)}
|
|
560
|
-
</select>
|
|
561
|
-
</label>
|
|
562
|
-
{(kind === 'prompt' || kind === 'harness') && (
|
|
563
|
-
<label className="shg-menu-lbl">Prompt — reference columns as {'{{Name}}'}
|
|
564
|
-
<textarea className="shg-menu-input" rows={3} value={prompt}
|
|
565
|
-
onChange={(e) => setPrompt(e.target.value)}
|
|
566
|
-
placeholder="Summarize {{Company}} in one line" />
|
|
567
|
-
</label>
|
|
568
|
-
)}
|
|
569
|
-
{kind === 'harness' && (
|
|
570
|
-
<label className="shg-menu-lbl">Agent id
|
|
571
|
-
<input className="shg-menu-input" value={harnessId} onChange={(e) => setHarnessId(e.target.value)} placeholder="chrn_…" />
|
|
572
|
-
</label>
|
|
573
|
-
)}
|
|
574
|
-
{kind === 'workflow' && (
|
|
648
|
+
{type === 'compute' && (
|
|
575
649
|
<>
|
|
576
|
-
<label className="shg-menu-lbl">
|
|
577
|
-
<
|
|
650
|
+
<label className="shg-menu-lbl">Runs
|
|
651
|
+
<select className="shg-menu-input" value={kind} onChange={(e) => setKind(e.target.value)}>
|
|
652
|
+
{COMPUTE_KINDS.map((k) => <option key={k.kind} value={k.kind}>{k.label}</option>)}
|
|
653
|
+
</select>
|
|
578
654
|
</label>
|
|
579
|
-
|
|
580
|
-
<
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
<
|
|
589
|
-
|
|
655
|
+
{(kind === 'prompt' || kind === 'harness') && (
|
|
656
|
+
<label className="shg-menu-lbl">Prompt — reference columns as {'{{Name}}'}
|
|
657
|
+
<textarea className="shg-menu-input" rows={3} value={prompt}
|
|
658
|
+
onChange={(e) => setPrompt(e.target.value)}
|
|
659
|
+
placeholder="Summarize {{Company}} in one line" />
|
|
660
|
+
</label>
|
|
661
|
+
)}
|
|
662
|
+
{kind === 'harness' && (
|
|
663
|
+
<label className="shg-menu-lbl">Agent id
|
|
664
|
+
<input className="shg-menu-input" value={harnessId} onChange={(e) => setHarnessId(e.target.value)} placeholder="chrn_…" />
|
|
665
|
+
</label>
|
|
666
|
+
)}
|
|
667
|
+
{kind === 'workflow' && (
|
|
668
|
+
<>
|
|
669
|
+
<label className="shg-menu-lbl">Workflow id
|
|
670
|
+
<input className="shg-menu-input" value={wfSlug} onChange={(e) => setWfSlug(e.target.value)} placeholder="my-workflow" />
|
|
590
671
|
</label>
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
672
|
+
<label className="shg-menu-lbl">Output key (optional)
|
|
673
|
+
<input className="shg-menu-input" value={outKey} onChange={(e) => setOutKey(e.target.value)} placeholder="summary" />
|
|
674
|
+
</label>
|
|
675
|
+
</>
|
|
676
|
+
)}
|
|
677
|
+
{others.length > 0 && (
|
|
678
|
+
<div className="shg-menu-lbl">Reads columns
|
|
679
|
+
<div className="shg-menu-deps">
|
|
680
|
+
{others.map((c) => (
|
|
681
|
+
<label key={c.id} className="shg-menu-dep">
|
|
682
|
+
<input type="checkbox" checked={deps.has(c.id)} onChange={() => toggleDep(c.id)} /> {c.name}
|
|
683
|
+
</label>
|
|
684
|
+
))}
|
|
685
|
+
</div>
|
|
686
|
+
</div>
|
|
687
|
+
)}
|
|
688
|
+
</>
|
|
594
689
|
)}
|
|
690
|
+
<div className="shg-menu-actions">
|
|
691
|
+
<button className="shg-menu-del" onClick={onDelete}>Delete column</button>
|
|
692
|
+
<button className="shg-menu-apply" onClick={apply}>Apply</button>
|
|
693
|
+
</div>
|
|
595
694
|
</>
|
|
596
695
|
)}
|
|
597
|
-
|
|
598
|
-
<div className="shg-menu-actions">
|
|
599
|
-
<button className="shg-menu-del" onClick={onDelete}>Delete column</button>
|
|
600
|
-
<button className="shg-menu-apply" onClick={apply}>Apply</button>
|
|
601
|
-
</div>
|
|
602
696
|
</div>
|
|
603
697
|
</PopPortal>
|
|
604
698
|
);
|
|
605
699
|
}
|
|
606
700
|
|
|
607
701
|
// ── Export helpers (CSV / TSV / array-of-arrays) ─────────────────────────────
|
|
608
|
-
|
|
702
|
+
// cellText(cell, column) lets a host say what one of its own column types is worth in a flat
|
|
703
|
+
// file. Without it a cell whose value is an object exports as raw JSON, which is what a
|
|
704
|
+
// spreadsheet export must never be.
|
|
705
|
+
function defaultCellText(cell) {
|
|
706
|
+
const v = cell?.value;
|
|
707
|
+
if (v == null) return '';
|
|
708
|
+
if (Array.isArray(v)) return v.join(', ');
|
|
709
|
+
if (typeof v === 'object') return JSON.stringify(v);
|
|
710
|
+
return String(v);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
export function sheetToDelimited(sheet, sep = ',', { cellText = defaultCellText } = {}) {
|
|
609
714
|
const cols = sheet?.columns || [];
|
|
610
715
|
const rows = sheet?.rows || [];
|
|
611
716
|
const cells = sheet?.cells || {};
|
|
612
|
-
const esc = (
|
|
613
|
-
const s = v == null ? '' : (Array.isArray(v) ? v.join(', ') : (typeof v === 'object' ? JSON.stringify(v) : String(v)));
|
|
717
|
+
const esc = (s) => {
|
|
614
718
|
if (sep === ',' && /[",\n]/.test(s)) return `"${s.replace(/"/g, '""')}"`;
|
|
615
719
|
return s;
|
|
616
720
|
};
|
|
617
721
|
const header = cols.map((c) => esc(c.name)).join(sep);
|
|
618
|
-
const body = rows.map((r) => cols.map((c) =>
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
}).join(sep));
|
|
722
|
+
const body = rows.map((r) => cols.map((c) => (
|
|
723
|
+
esc(String(cellText(cells[cellKey(r.id, c.id)], c) ?? ''))
|
|
724
|
+
)).join(sep));
|
|
622
725
|
return [header, ...body].join('\n');
|
|
623
726
|
}
|
|
624
727
|
|
|
625
|
-
/** Rows as an array-of-arrays (header first) — feed to an xlsx writer.
|
|
626
|
-
|
|
728
|
+
/** Rows as an array-of-arrays (header first) — feed to an xlsx writer.
|
|
729
|
+
*
|
|
730
|
+
* The default keeps numbers and booleans as themselves: a spreadsheet writer stores a JS number
|
|
731
|
+
* as a numeric cell, and stringifying here would hand the person a column they cannot sum. */
|
|
732
|
+
function defaultCellValue(cell) {
|
|
733
|
+
const v = cell?.value;
|
|
734
|
+
if (v == null) return '';
|
|
735
|
+
if (Array.isArray(v)) return v.join(', ');
|
|
736
|
+
if (typeof v === 'object') return JSON.stringify(v);
|
|
737
|
+
return v;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
export function sheetToAoA(sheet, { cellText = defaultCellValue } = {}) {
|
|
627
741
|
const cols = sheet?.columns || [];
|
|
628
742
|
const rows = sheet?.rows || [];
|
|
629
743
|
const cells = sheet?.cells || {};
|
|
630
|
-
const val = (v) => (v == null ? '' : (Array.isArray(v) ? v.join(', ') : (typeof v === 'object' ? JSON.stringify(v) : v)));
|
|
631
744
|
return [cols.map((c) => c.name),
|
|
632
|
-
...rows.map((r) => cols.map((c) =>
|
|
745
|
+
...rows.map((r) => cols.map((c) => cellText(cells[cellKey(r.id, c.id)], c) ?? ''))];
|
|
633
746
|
}
|