reifyui 0.4.1 → 0.5.0

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.
@@ -1,13 +1,11 @@
1
- // SheetGrid — the reusable AI-spreadsheet grid (UI Core).
1
+ // SheetGrid — the reusable AI-spreadsheet grid.
2
2
  //
3
- // Product-agnostic: it renders a sheet JSON and calls back for edits/runs.
4
- // The Sheets product (frontend-sheets) AND agentstudio studio Spaces both
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 (see backend/sheets sheet_model):
9
- // { meta{title,rev}, columns[{id,name,type,options?,compute?}],
10
- // rows[{id}], cells{ "<rowId>:<colId>": {value,status,error} } }
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,50 @@
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
- // inline images whose url is a product path
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
- // host persists + (via realtime) rebroadcasts truth back through `sheet`.
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
- const TYPE_LABEL = {
31
- text: 'Text', number: 'Number', select: 'Select', tags: 'Tags',
32
- checkbox: 'Checkbox', date: 'Date', url: 'Link', resource: 'Resource', compute: 'Computed',
33
- };
34
- const MANUAL_TYPES = ['text', 'number', 'select', 'tags', 'checkbox', 'date', 'url', 'resource'];
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
+ const DEFAULT_COLUMN_TYPES = [
43
+ { type: 'text', label: 'Text' },
44
+ { type: 'number', label: 'Number' },
45
+ { type: 'select', label: 'Select' },
46
+ { type: 'tags', label: 'Tags' },
47
+ { type: 'checkbox', label: 'Checkbox' },
48
+ { type: 'date', label: 'Date' },
49
+ { type: 'url', label: 'Link' },
50
+ { type: 'resource', label: 'Resource' },
51
+ {
52
+ type: 'compute',
53
+ label: 'Computed',
54
+ computed: true,
55
+ configKey: 'compute',
56
+ badge: (col) => col.compute?.kind,
57
+ },
58
+ ];
59
+
35
60
  const COMPUTE_KINDS = [
36
61
  { kind: 'prompt', label: 'AI prompt' },
37
62
  { kind: 'harness', label: 'Agent (harness)' },
@@ -41,25 +66,40 @@ const COMPUTE_KINDS = [
41
66
  const RESOURCE_KINDS = ['image', 'sheet', 'slides', 'workflow', 'graph'];
42
67
  const RESOURCE_ICON = { image: '🖼', sheet: '▦', slides: '▤', workflow: '⚙', graph: '◉' };
43
68
 
44
- // Popovers render through a body portal with FIXED positioning — inside the
45
- // grid they'd be clipped by the scroll container and out-stacked by the
46
- // sticky header/row-number cells. anchor is a DOMRect captured at open time;
47
- // the box clamps to the viewport and flips above the anchor when the bottom
48
- // would overflow. Any scroll closes it (the anchor moved).
69
+ // Popovers render through a body portal with FIXED positioning — inside the grid they'd be
70
+ // clipped by the scroll container and out-stacked by the sticky header/row-number cells. anchor
71
+ // is a DOMRect captured at open time; the box clamps to the viewport and flips above the anchor
72
+ // when the bottom would overflow. Any scroll closes it (the anchor moved).
49
73
  function PopPortal({ anchor, width = 250, estHeight = 300, className, children, onClose }) {
74
+ const boxRef = useRef(null);
50
75
  useEffect(() => {
51
76
  if (!onClose) return undefined;
52
77
  const close = () => onClose();
78
+ // mousedown, not click: React 18 flushes a listener attached in this effect synchronously
79
+ // during the very discrete event that opened the popover, so a `click` listener closes the
80
+ // box before it paints. A press inside the anchor is also ignored — that is the trigger's
81
+ // own toggle, and closing here would race it into staying open.
82
+ const onDown = (e) => {
83
+ if (boxRef.current && boxRef.current.contains(e.target)) return;
84
+ if (anchor && e.clientX >= anchor.left && e.clientX <= anchor.right
85
+ && e.clientY >= anchor.top && e.clientY <= anchor.bottom) return;
86
+ onClose();
87
+ };
88
+ window.addEventListener('mousedown', onDown);
53
89
  window.addEventListener('scroll', close, true);
54
90
  window.addEventListener('resize', close);
55
- return () => { window.removeEventListener('scroll', close, true); window.removeEventListener('resize', close); };
56
- }, [onClose]);
91
+ return () => {
92
+ window.removeEventListener('mousedown', onDown);
93
+ window.removeEventListener('scroll', close, true);
94
+ window.removeEventListener('resize', close);
95
+ };
96
+ }, [onClose, anchor]);
57
97
  if (!anchor) return null;
58
98
  const left = Math.max(8, Math.min(anchor.right - width, window.innerWidth - width - 8));
59
99
  let top = anchor.bottom + 6;
60
100
  if (top + estHeight > window.innerHeight - 8) top = Math.max(8, anchor.top - estHeight - 6);
61
101
  return createPortal(
62
- <div className={className} style={{ position: 'fixed', top, left, width, zIndex: 1000 }}>
102
+ <div ref={boxRef} className={className} style={{ position: 'fixed', top, left, width, zIndex: 1000 }}>
63
103
  {children}
64
104
  </div>,
65
105
  document.body,
@@ -120,8 +160,8 @@ function StatusDot({ status }) {
120
160
  function CellValue({ cell, col, fetchBlobUrl, onOpenResource }) {
121
161
  const v = cell?.value;
122
162
  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
- // or produced by a compute kind (e.g. Generate image).
163
+ // A typed artifact ref renders the same whether hand-set (resource column) or produced by a
164
+ // compute kind (e.g. Generate image).
125
165
  if (v && typeof v === 'object' && !Array.isArray(v) && v.kind) {
126
166
  if (v.kind === 'image') return <RefImage refVal={v} fetchBlobUrl={fetchBlobUrl} />;
127
167
  return <ResourceChip refVal={v} onOpen={onOpenResource} />;
@@ -152,7 +192,10 @@ function CellValue({ cell, col, fetchBlobUrl, onOpenResource }) {
152
192
  }
153
193
  }
154
194
 
155
- export function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly = false, fetchBlobUrl, onOpenResource, peerMarks, onActiveCell }) {
195
+ export function SheetGrid({
196
+ sheet, onChange, onRunCell, onRunColumn, readOnly = false, fetchBlobUrl, onOpenResource,
197
+ peerMarks, onActiveCell, columnTypes = DEFAULT_COLUMN_TYPES, renderCell, renderColumnConfig,
198
+ }) {
156
199
  const columns = sheet?.columns || [];
157
200
  const rows = sheet?.rows || [];
158
201
  const cells = sheet?.cells || {};
@@ -165,6 +208,15 @@ export function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly =
165
208
  const inputRef = useRef(null);
166
209
  const dragRef = useRef(null);
167
210
 
211
+ // An unknown type still renders — as plain text, editable. Refusing to draw a column because
212
+ // its type is unfamiliar would hide the person's data from them.
213
+ const descOf = (type) => columnTypes.find((t) => t.type === type) || { type, label: type };
214
+ const isComputed = (col) => !!descOf(col?.type).computed;
215
+ const isEditable = (col) => {
216
+ const d = descOf(col?.type);
217
+ return d.editable ?? !d.computed;
218
+ };
219
+
168
220
  // Drag-to-resize: live via sizeDraft, persisted into the sheet on release.
169
221
  const startResize = (e, kind, id, start) => {
170
222
  if (readOnly) return;
@@ -242,8 +294,8 @@ export function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly =
242
294
  }
243
295
  return cls;
244
296
  };
245
- // The number gutter is FIXED: sized by the digit count of the row total so
246
- // it never stretches (an empty grid otherwise splits the table width).
297
+ // The number gutter is FIXED: sized by the digit count of the row total so it never stretches
298
+ // (an empty grid otherwise splits the table width).
247
299
  const numW = Math.max(40, 24 + String(rows.length || 1).length * 9);
248
300
  const numStyle = { width: numW, minWidth: numW, maxWidth: numW };
249
301
  const rowHeight = (row) => (sizeDraft.row && sizeDraft.row[row.id]) || row.height || undefined;
@@ -257,14 +309,22 @@ export function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly =
257
309
  onChange(next);
258
310
  };
259
311
 
312
+ // A manual edit writes the value and nothing else. It used to stamp `status:'done'`, which
313
+ // made every hand-typed cell claim to be the output of a run that never happened — and forced
314
+ // status rendering to be gated on the column type rather than on the cell. On a computed
315
+ // column the surrounding run record is kept, because there an override sits on top of a real
316
+ // run and the link to that run is still true.
260
317
  const setCell = (rowId, colId, value) => mutate((n) => {
261
318
  n.cells = n.cells || {};
262
- n.cells[cellKey(rowId, colId)] = { value, status: 'done', updated_at: Math.floor(Date.now() / 1000) };
319
+ const k = cellKey(rowId, colId);
320
+ const col = (n.columns || []).find((c) => c.id === colId);
321
+ const prev = n.cells[k];
322
+ n.cells[k] = isComputed(col) && prev ? { ...prev, value } : { value };
263
323
  });
264
324
 
265
325
  const openEdit = (rowId, col, anchorEl) => {
266
326
  if (readOnly) return;
267
- if (col.type === 'compute') return; // computed cells aren't hand-edited
327
+ if (!isEditable(col)) return;
268
328
  if (col.type === 'checkbox') { // click toggles directly
269
329
  const cur = cells[cellKey(rowId, col.id)];
270
330
  setCell(rowId, col.id, !(cur && cur.value));
@@ -308,7 +368,11 @@ export function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly =
308
368
  const configureColumn = (colId, patch) => mutate((n) => {
309
369
  const c = n.columns.find((x) => x.id === colId); if (!c) return;
310
370
  Object.assign(c, patch);
311
- if (patch.type && patch.type !== 'compute') delete c.compute;
371
+ // A column carries the config of its own type and no other. Changing the type takes the old
372
+ // config with it, so a harness column that becomes a text column stops carrying a prompt.
373
+ if (patch.type) {
374
+ for (const d of columnTypes) if (d.configKey && d.type !== patch.type) delete c[d.configKey];
375
+ }
312
376
  });
313
377
 
314
378
  // The inline editor for the editing cell, by type.
@@ -372,7 +436,7 @@ export function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly =
372
436
  <th className="shg-corner" style={numStyle} />
373
437
  {columns.map((col) => (
374
438
  <th key={col.id}
375
- className={'shg-col' + (col.type === 'compute' ? ' shg-col-compute' : '') + dndClass('col', col.id)}
439
+ className={'shg-col' + (isComputed(col) ? ' shg-col-compute' : '') + dndClass('col', col.id)}
376
440
  style={colWidth(col) ? { width: colWidth(col), minWidth: colWidth(col), maxWidth: colWidth(col) } : undefined}
377
441
  {...dndProps('col', col.id)}>
378
442
  {!readOnly && (
@@ -381,6 +445,8 @@ export function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly =
381
445
  <div className="shg-col-h">
382
446
  <ColumnHeader
383
447
  col={col} columns={columns} readOnly={readOnly}
448
+ desc={descOf(col.type)} columnTypes={columnTypes}
449
+ renderColumnConfig={renderColumnConfig}
384
450
  menuOpen={menuCol?.id === col.id}
385
451
  menuAnchor={menuCol?.id === col.id ? menuCol.rect : null}
386
452
  onMenu={(e) => setMenuCol(menuCol?.id === col.id ? null
@@ -389,7 +455,7 @@ export function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly =
389
455
  onRename={renameColumn}
390
456
  onConfigure={configureColumn}
391
457
  onDelete={() => { setMenuCol(null); deleteColumn(col.id); }}
392
- onRun={col.type === 'compute' && onRunColumn ? () => onRunColumn(col.id) : null} />
458
+ onRun={isComputed(col) && onRunColumn ? () => onRunColumn(col.id) : null} />
393
459
  </div>
394
460
  </th>
395
461
  ))}
@@ -415,12 +481,22 @@ export function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly =
415
481
  </td>
416
482
  {columns.map((col) => {
417
483
  const c = cells[cellKey(row.id, col.id)] || {};
484
+ const computed = isComputed(col);
418
485
  const isEditing = editing && editing.rowId === row.id && editing.colId === col.id;
419
486
  const peer = peerMarks && peerMarks[cellKey(row.id, col.id)];
487
+ // A host owns the whole cell body when it wants to: a running cell's live text
488
+ // lives in the host's run store, not in the sheet JSON, so only a closure can
489
+ // reach it. Returning undefined falls through to the built-in rendering.
490
+ const custom = renderCell && renderCell({
491
+ cell: c, column: col, row, rowIndex: ri, sheet, computed,
492
+ width: colWidth(col), height: rowHeight(row), editing: !!isEditing, readOnly,
493
+ setCell: (v) => setCell(row.id, col.id, v),
494
+ runCell: onRunCell && !readOnly ? () => onRunCell(row.id, col.id) : null,
495
+ });
420
496
  return (
421
497
  <td key={col.id}
422
- className={'shg-cell' + (col.type === 'compute' ? ' shg-cell-compute' : '')
423
- + (c.status && col.type === 'compute' ? ` shg-cell-${c.status}` : '')
498
+ className={'shg-cell' + (computed ? ' shg-cell-compute' : '')
499
+ + (c.status && computed ? ` shg-cell-${c.status}` : '')
424
500
  + (peer ? ' shg-cell-peer' : '')}
425
501
  style={peer ? { boxShadow: `inset 0 0 0 2px ${peer.color}` } : undefined}
426
502
  onClick={(e) => { if (!isEditing) openEdit(row.id, col, e.currentTarget); }}
@@ -429,11 +505,15 @@ export function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly =
429
505
  {isEditing ? renderEditor(col) : (
430
506
  <div className="shg-val"
431
507
  style={{ maxWidth: (colWidth(col) ? colWidth(col) - 20 : 400) }}>
432
- {col.type === 'compute' && <StatusDot status={c.status} />}
433
- <CellValue cell={c} col={col} fetchBlobUrl={fetchBlobUrl} onOpenResource={onOpenResource} />
434
- {col.type === 'compute' && !readOnly && onRunCell && (
435
- <button className="shg-runcell" title="Run this cell"
436
- onClick={(e) => { e.stopPropagation(); onRunCell(row.id, col.id); }}>▶</button>
508
+ {custom !== undefined ? custom : (
509
+ <>
510
+ {computed && <StatusDot status={c.status} />}
511
+ <CellValue cell={c} col={col} fetchBlobUrl={fetchBlobUrl} onOpenResource={onOpenResource} />
512
+ {computed && !readOnly && onRunCell && (
513
+ <button className="shg-runcell" title="Run this cell"
514
+ onClick={(e) => { e.stopPropagation(); onRunCell(row.id, col.id); }}>▶</button>
515
+ )}
516
+ </>
437
517
  )}
438
518
  </div>
439
519
  )}
@@ -456,10 +536,14 @@ export function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly =
456
536
  );
457
537
  }
458
538
 
459
- function ColumnHeader({ col, columns, readOnly, menuOpen, menuAnchor, onMenu, onCloseMenu, onRename, onConfigure, onDelete, onRun }) {
539
+ function ColumnHeader({
540
+ col, columns, readOnly, desc, columnTypes, renderColumnConfig,
541
+ menuOpen, menuAnchor, onMenu, onCloseMenu, onRename, onConfigure, onDelete, onRun,
542
+ }) {
460
543
  const [editing, setEditing] = useState(false);
461
544
  const [name, setName] = useState(col.name);
462
545
  useEffect(() => setName(col.name), [col.name]);
546
+ const badge = desc.badge ? desc.badge(col) : undefined;
463
547
  return (
464
548
  <div className="shg-colhdr">
465
549
  <div className="shg-colhdr-main">
@@ -471,9 +555,9 @@ function ColumnHeader({ col, columns, readOnly, menuOpen, menuAnchor, onMenu, on
471
555
  ) : (
472
556
  <span className="shg-colname" onDoubleClick={() => !readOnly && setEditing(true)} title={col.name}>{col.name}</span>
473
557
  )}
474
- <span className={'shg-coltype' + (col.type === 'compute' ? ' compute' : '')}>
475
- {TYPE_LABEL[col.type] || col.type}
476
- {col.type === 'compute' && col.compute?.kind ? ` · ${col.compute.kind}` : ''}
558
+ <span className={'shg-coltype' + (desc.computed ? ' compute' : '')}>
559
+ {desc.label || col.type}
560
+ {badge ? ` · ${badge}` : ''}
477
561
  </span>
478
562
  </div>
479
563
  {!readOnly && (
@@ -484,6 +568,7 @@ function ColumnHeader({ col, columns, readOnly, menuOpen, menuAnchor, onMenu, on
484
568
  )}
485
569
  {menuOpen && !readOnly && (
486
570
  <ColumnMenu col={col} columns={columns} anchor={menuAnchor}
571
+ columnTypes={columnTypes} renderColumnConfig={renderColumnConfig}
487
572
  onApply={(patch) => { onConfigure(col.id, patch); onCloseMenu(); }}
488
573
  onDelete={onDelete} onClose={onCloseMenu} />
489
574
  )}
@@ -491,10 +576,10 @@ function ColumnHeader({ col, columns, readOnly, menuOpen, menuAnchor, onMenu, on
491
576
  );
492
577
  }
493
578
 
494
- // The column configuration popover: type, options (select/tags), and the
495
- // compute mount (prompt / harness / workflow + deps). Product-agnostic —
496
- // plain controlled inputs, applied as one patch.
497
- function ColumnMenu({ col, columns, anchor, onApply, onDelete, onClose }) {
579
+ // The column configuration popover: type, options (select/tags), and the type's own config body.
580
+ // Product-agnostic — plain controlled inputs, applied as one patch. A host that adds a column
581
+ // type supplies renderColumnConfig and owns the body below the Type select.
582
+ function ColumnMenu({ col, columns, anchor, columnTypes, renderColumnConfig, onApply, onDelete, onClose }) {
498
583
  const [type, setType] = useState(col.type || 'text');
499
584
  const [optText, setOptText] = useState(
500
585
  normOptions(col.options).map((o) => o.label).join('\n'));
@@ -505,13 +590,6 @@ function ColumnMenu({ col, columns, anchor, onApply, onDelete, onClose }) {
505
590
  const [wfSlug, setWfSlug] = useState(comp.workflow_slug || '');
506
591
  const [outKey, setOutKey] = useState(comp.output_key || '');
507
592
  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
593
 
516
594
  const others = columns.filter((c) => c.id !== col.id);
517
595
  const toggleDep = (id) => setDeps((s) => {
@@ -525,6 +603,7 @@ function ColumnMenu({ col, columns, anchor, onApply, onDelete, onClose }) {
525
603
  if (type === 'select' || type === 'tags') {
526
604
  patch.options = optText.split('\n').map((s) => s.trim()).filter(Boolean);
527
605
  }
606
+ // The built-in 'compute' type's own editor. Any other type's config comes from the host.
528
607
  if (type === 'compute') {
529
608
  const compute = { kind, deps: [...deps] };
530
609
  if (kind === 'prompt') compute.prompt = prompt;
@@ -535,13 +614,21 @@ function ColumnMenu({ col, columns, anchor, onApply, onDelete, onClose }) {
535
614
  onApply(patch);
536
615
  };
537
616
 
617
+ // A custom body owns its own primary action, because only it knows when its config is
618
+ // complete. It gets applyPatch to commit and close in one call.
619
+ const custom = renderColumnConfig && renderColumnConfig({
620
+ column: col, columns, type,
621
+ applyPatch: (patch) => onApply({ type, ...patch }),
622
+ deleteColumn: onDelete,
623
+ close: onClose,
624
+ });
625
+
538
626
  return (
539
627
  <PopPortal anchor={anchor} width={250} estHeight={340} className="shg-menu" onClose={onClose}>
540
- <div ref={ref} onClick={(e) => e.stopPropagation()}>
628
+ <div onClick={(e) => e.stopPropagation()}>
541
629
  <label className="shg-menu-lbl">Type
542
630
  <select className="shg-menu-input" value={type} onChange={(e) => setType(e.target.value)}>
543
- {MANUAL_TYPES.map((t) => <option key={t} value={t}>{TYPE_LABEL[t]}</option>)}
544
- <option value="compute">Computed</option>
631
+ {columnTypes.map((t) => <option key={t.type} value={t.type}>{t.label}</option>)}
545
632
  </select>
546
633
  </label>
547
634
 
@@ -552,82 +639,104 @@ function ColumnMenu({ col, columns, anchor, onApply, onDelete, onClose }) {
552
639
  </label>
553
640
  )}
554
641
 
555
- {type === 'compute' && (
642
+ {custom !== undefined ? custom : (
556
643
  <>
557
- <label className="shg-menu-lbl">Runs
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' && (
644
+ {type === 'compute' && (
575
645
  <>
576
- <label className="shg-menu-lbl">Workflow id
577
- <input className="shg-menu-input" value={wfSlug} onChange={(e) => setWfSlug(e.target.value)} placeholder="my-workflow" />
646
+ <label className="shg-menu-lbl">Runs
647
+ <select className="shg-menu-input" value={kind} onChange={(e) => setKind(e.target.value)}>
648
+ {COMPUTE_KINDS.map((k) => <option key={k.kind} value={k.kind}>{k.label}</option>)}
649
+ </select>
578
650
  </label>
579
- <label className="shg-menu-lbl">Output key (optional)
580
- <input className="shg-menu-input" value={outKey} onChange={(e) => setOutKey(e.target.value)} placeholder="summary" />
581
- </label>
582
- </>
583
- )}
584
- {others.length > 0 && (
585
- <div className="shg-menu-lbl">Reads columns
586
- <div className="shg-menu-deps">
587
- {others.map((c) => (
588
- <label key={c.id} className="shg-menu-dep">
589
- <input type="checkbox" checked={deps.has(c.id)} onChange={() => toggleDep(c.id)} /> {c.name}
651
+ {(kind === 'prompt' || kind === 'harness') && (
652
+ <label className="shg-menu-lbl">Prompt — reference columns as {'{{Name}}'}
653
+ <textarea className="shg-menu-input" rows={3} value={prompt}
654
+ onChange={(e) => setPrompt(e.target.value)}
655
+ placeholder="Summarize {{Company}} in one line" />
656
+ </label>
657
+ )}
658
+ {kind === 'harness' && (
659
+ <label className="shg-menu-lbl">Agent id
660
+ <input className="shg-menu-input" value={harnessId} onChange={(e) => setHarnessId(e.target.value)} placeholder="chrn_…" />
661
+ </label>
662
+ )}
663
+ {kind === 'workflow' && (
664
+ <>
665
+ <label className="shg-menu-lbl">Workflow id
666
+ <input className="shg-menu-input" value={wfSlug} onChange={(e) => setWfSlug(e.target.value)} placeholder="my-workflow" />
590
667
  </label>
591
- ))}
592
- </div>
593
- </div>
668
+ <label className="shg-menu-lbl">Output key (optional)
669
+ <input className="shg-menu-input" value={outKey} onChange={(e) => setOutKey(e.target.value)} placeholder="summary" />
670
+ </label>
671
+ </>
672
+ )}
673
+ {others.length > 0 && (
674
+ <div className="shg-menu-lbl">Reads columns
675
+ <div className="shg-menu-deps">
676
+ {others.map((c) => (
677
+ <label key={c.id} className="shg-menu-dep">
678
+ <input type="checkbox" checked={deps.has(c.id)} onChange={() => toggleDep(c.id)} /> {c.name}
679
+ </label>
680
+ ))}
681
+ </div>
682
+ </div>
683
+ )}
684
+ </>
594
685
  )}
686
+ <div className="shg-menu-actions">
687
+ <button className="shg-menu-del" onClick={onDelete}>Delete column</button>
688
+ <button className="shg-menu-apply" onClick={apply}>Apply</button>
689
+ </div>
595
690
  </>
596
691
  )}
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
692
  </div>
603
693
  </PopPortal>
604
694
  );
605
695
  }
606
696
 
607
697
  // ── Export helpers (CSV / TSV / array-of-arrays) ─────────────────────────────
608
- export function sheetToDelimited(sheet, sep = ',') {
698
+ // cellText(cell, column) lets a host say what one of its own column types is worth in a flat
699
+ // file. Without it a cell whose value is an object exports as raw JSON, which is what a
700
+ // spreadsheet export must never be.
701
+ function defaultCellText(cell) {
702
+ const v = cell?.value;
703
+ if (v == null) return '';
704
+ if (Array.isArray(v)) return v.join(', ');
705
+ if (typeof v === 'object') return JSON.stringify(v);
706
+ return String(v);
707
+ }
708
+
709
+ export function sheetToDelimited(sheet, sep = ',', { cellText = defaultCellText } = {}) {
609
710
  const cols = sheet?.columns || [];
610
711
  const rows = sheet?.rows || [];
611
712
  const cells = sheet?.cells || {};
612
- const esc = (v) => {
613
- const s = v == null ? '' : (Array.isArray(v) ? v.join(', ') : (typeof v === 'object' ? JSON.stringify(v) : String(v)));
713
+ const esc = (s) => {
614
714
  if (sep === ',' && /[",\n]/.test(s)) return `"${s.replace(/"/g, '""')}"`;
615
715
  return s;
616
716
  };
617
717
  const header = cols.map((c) => esc(c.name)).join(sep);
618
- const body = rows.map((r) => cols.map((c) => {
619
- const cell = cells[cellKey(r.id, c.id)];
620
- return esc(cell ? cell.value : '');
621
- }).join(sep));
718
+ const body = rows.map((r) => cols.map((c) => (
719
+ esc(String(cellText(cells[cellKey(r.id, c.id)], c) ?? ''))
720
+ )).join(sep));
622
721
  return [header, ...body].join('\n');
623
722
  }
624
723
 
625
- /** Rows as an array-of-arrays (header first) — feed to an xlsx writer. */
626
- export function sheetToAoA(sheet) {
724
+ /** Rows as an array-of-arrays (header first) — feed to an xlsx writer.
725
+ *
726
+ * The default keeps numbers and booleans as themselves: a spreadsheet writer stores a JS number
727
+ * as a numeric cell, and stringifying here would hand the person a column they cannot sum. */
728
+ function defaultCellValue(cell) {
729
+ const v = cell?.value;
730
+ if (v == null) return '';
731
+ if (Array.isArray(v)) return v.join(', ');
732
+ if (typeof v === 'object') return JSON.stringify(v);
733
+ return v;
734
+ }
735
+
736
+ export function sheetToAoA(sheet, { cellText = defaultCellValue } = {}) {
627
737
  const cols = sheet?.columns || [];
628
738
  const rows = sheet?.rows || [];
629
739
  const cells = sheet?.cells || {};
630
- const val = (v) => (v == null ? '' : (Array.isArray(v) ? v.join(', ') : (typeof v === 'object' ? JSON.stringify(v) : v)));
631
740
  return [cols.map((c) => c.name),
632
- ...rows.map((r) => cols.map((c) => val(cells[cellKey(r.id, c.id)]?.value)))];
741
+ ...rows.map((r) => cols.map((c) => cellText(cells[cellKey(r.id, c.id)], c) ?? ''))];
633
742
  }
@@ -8,7 +8,11 @@ import { useEffect, useRef, useState } from 'react';
8
8
 
9
9
  // Rich-text runs → spans with marks. role drives default sizing (the stage is
10
10
  // 1920 wide, so these px sizes read correctly once the stage is scaled).
11
- const ROLE_STYLE = {
11
+ //
12
+ // Exported because anything that RE-RENDERS a deck outside the DOM — a PowerPoint or PDF
13
+ // exporter, a server-side thumbnailer — has to apply the same defaults, and a second copy of this
14
+ // table is a divergence waiting to happen.
15
+ export const ROLE_STYLE = {
12
16
  title: { fontSize: 72, fontWeight: 800, lineHeight: 1.1, fontFamily: 'var(--sl-head)' },
13
17
  subtitle: { fontSize: 36, fontWeight: 500, lineHeight: 1.25, color: 'var(--sl-mute)' },
14
18
  body: { fontSize: 30, fontWeight: 400, lineHeight: 1.4 },
@@ -82,6 +82,12 @@ export interface SlideViewProps extends SlideStageProps {
82
82
  /** A slide scaled to fit its container. The read-only renderer: thumbnails, previews, print. */
83
83
  export const SlideView: ComponentType<SlideViewProps>;
84
84
 
85
+ /** Default text styling per `content.role`, in stage pixels.
86
+ *
87
+ * Exported so anything re-rendering a deck outside the DOM (a PPTX/PDF exporter, a server-side
88
+ * thumbnailer) applies the same defaults the renderer does, instead of keeping a second copy. */
89
+ export const ROLE_STYLE: Record<string, CSSProperties & { fontSize: number }>;
90
+
85
91
  /** A single element, unpositioned. Exported for hosts composing their own stage. */
86
92
  export const ElementView: ComponentType<{ el: SlideElement; resolveSrc?: ResolveSrc }>;
87
93
 
@@ -5,6 +5,6 @@
5
5
  // components, and a root re-export would force every ui-core consumer (CG,
6
6
  // Flowness) to resolve those deps at build time. See docs/slides-architecture.md.
7
7
  export { SlideView, SlideStage, themeVars } from './SlideView.jsx';
8
- export { ElementView } from './elements.jsx';
8
+ export { ElementView, ROLE_STYLE } from './elements.jsx';
9
9
  export { EditorCanvas } from './Editor.jsx';
10
10
  export { Presentation } from './Presentation.jsx';