reifyui 0.11.1 → 0.13.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.
Files changed (85) hide show
  1. package/README.md +31 -2
  2. package/dist/chart.js +2 -0
  3. package/dist/chart.js.map +1 -1
  4. package/dist/chunk-EL2DHWOH.js +1710 -0
  5. package/dist/chunk-EL2DHWOH.js.map +1 -0
  6. package/dist/chunk-J633KV57.js +41 -0
  7. package/dist/chunk-J633KV57.js.map +1 -0
  8. package/dist/chunk-J7SECRIG.js +295 -0
  9. package/dist/chunk-J7SECRIG.js.map +1 -0
  10. package/dist/chunk-PIRPLH2Z.js +231 -0
  11. package/dist/chunk-PIRPLH2Z.js.map +1 -0
  12. package/dist/chunk-PZ5AY32C.js +10 -0
  13. package/dist/chunk-PZ5AY32C.js.map +1 -0
  14. package/dist/chunk-UKG4Z6QK.js +130 -0
  15. package/dist/chunk-UKG4Z6QK.js.map +1 -0
  16. package/dist/chunk-ZYWE47EO.js +19 -0
  17. package/dist/chunk-ZYWE47EO.js.map +1 -0
  18. package/dist/collab.cjs +169 -0
  19. package/dist/collab.cjs.map +1 -0
  20. package/dist/collab.d.ts +30 -0
  21. package/dist/collab.js +18 -0
  22. package/dist/collab.js.map +1 -0
  23. package/dist/graph.cjs +2244 -0
  24. package/dist/graph.cjs.map +1 -0
  25. package/dist/graph.d.ts +41 -0
  26. package/dist/graph.js +1870 -0
  27. package/dist/graph.js.map +1 -0
  28. package/dist/harness.js +1 -0
  29. package/dist/harness.js.map +1 -1
  30. package/dist/index.cjs +2044 -867
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.ts +20 -2
  33. package/dist/index.js +892 -1686
  34. package/dist/index.js.map +1 -1
  35. package/dist/sheet-doc.cjs +235 -0
  36. package/dist/sheet-doc.cjs.map +1 -0
  37. package/dist/sheet-doc.d.ts +16 -0
  38. package/dist/sheet-doc.js +20 -0
  39. package/dist/sheet-doc.js.map +1 -0
  40. package/dist/sheet.cjs +2322 -0
  41. package/dist/sheet.cjs.map +1 -0
  42. package/dist/sheet.d.ts +23 -0
  43. package/dist/sheet.js +237 -0
  44. package/dist/sheet.js.map +1 -0
  45. package/dist/slides.js +2 -0
  46. package/dist/slides.js.map +1 -1
  47. package/package.json +35 -3
  48. package/src/auth/client.js +4 -2
  49. package/src/collab/colors.js +18 -0
  50. package/src/collab/index.d.ts +30 -0
  51. package/src/collab/index.js +8 -0
  52. package/src/collab/keepAlive.js +34 -0
  53. package/src/collab/useLiveDoc.js +76 -0
  54. package/src/components/CascadeMenu.jsx +216 -0
  55. package/src/components/ChatMessages.jsx +30 -9
  56. package/src/components/Chip.jsx +37 -10
  57. package/src/components/Composer.jsx +80 -2
  58. package/src/components/resizable.jsx +82 -12
  59. package/src/graph/ConnectPane.jsx +634 -0
  60. package/src/graph/ConnectToolDetail.jsx +565 -0
  61. package/src/graph/LogsPane.jsx +328 -0
  62. package/src/graph/Skeleton.jsx +13 -0
  63. package/src/graph/draft.js +108 -0
  64. package/src/graph/format.js +37 -0
  65. package/src/graph/index.d.ts +41 -0
  66. package/src/graph/index.js +14 -0
  67. package/src/graph/useGraphCollab.js +299 -0
  68. package/src/graph/vgraph.js +215 -0
  69. package/src/index.d.ts +20 -2
  70. package/src/index.js +6 -1
  71. package/src/mention/MentionInput.jsx +420 -0
  72. package/src/mention/mentionModel.js +177 -0
  73. package/src/sheet/RunStrip.jsx +57 -0
  74. package/src/sheet/SheetGrid.jsx +444 -353
  75. package/src/sheet/doc.d.ts +16 -0
  76. package/src/sheet/index.d.ts +23 -0
  77. package/src/sheet/index.js +10 -0
  78. package/src/sheet/sheetDoc.js +203 -0
  79. package/src/sheet/useSheetCollab.js +102 -0
  80. package/src/sheet/useSheetRun.js +80 -0
  81. package/styles/chat.css +47 -5
  82. package/styles/chip.css +36 -0
  83. package/styles/graph.css +395 -0
  84. package/styles/mention.css +79 -0
  85. package/styles/sheet.css +156 -112
@@ -0,0 +1,16 @@
1
+ // reifyui/sheet-doc — the sheet document family, React-free: a sidecar service applies the
2
+ // same ops the browsers apply, so one module is the truth of what a sheet document holds.
3
+ import type * as Y from 'yjs';
4
+
5
+ export interface SheetOp { op: string; [k: string]: unknown; }
6
+ /** Collaboration document names of sheets carry this prefix. */
7
+ export const SHEET_PREFIX: string;
8
+ export function isSheetDoc(name: unknown): boolean;
9
+ export function sheetIdOf(name: string): string;
10
+ export function orderOf(order: unknown, map: unknown): string[];
11
+ /** Seed an empty document from the owner's stored sheet. */
12
+ export function seed(doc: Y.Doc, sheet: Record<string, unknown>, origin?: string): void;
13
+ /** The sheet as plain data. */
14
+ export function toJSON(doc: Y.Doc): Record<string, unknown>;
15
+ /** Apply content ops (set_cell, set_column, move_row, set_tab, replace, ...) to the live document. */
16
+ export function apply(doc: Y.Doc, ops: SheetOp[], origin?: string): void;
@@ -0,0 +1,23 @@
1
+ // reifyui/sheet — public type surface (hand-authored; the source is plain-ESM React).
2
+ import type { ComponentType } from 'react';
3
+ import type * as doc from './doc';
4
+
5
+ export { SheetGrid, sheetToDelimited, sheetToAoA } from '../index';
6
+ export type SheetOp = doc.SheetOp;
7
+ export interface SheetCollab {
8
+ /** The sheet as plain data, re-derived on every remote change. */
9
+ sheet: Record<string, unknown> | null;
10
+ /** Apply ops to the live document (the only way anyone writes). */
11
+ ops(ops: SheetOp[]): void;
12
+ peers: Array<Record<string, unknown>>;
13
+ setPresence(presence: Record<string, unknown> | null): void;
14
+ [k: string]: unknown;
15
+ }
16
+ export function useSheetCollab(options: Record<string, unknown>): SheetCollab;
17
+ export const sheetOps: Record<string, (...args: any[]) => SheetOp>;
18
+ export function useSheetRun(options: Record<string, unknown>): Record<string, unknown>;
19
+ export function withQueuedCells(sheet: Record<string, unknown>, run: Record<string, unknown>): Record<string, unknown>;
20
+ export function runProgress(run: Record<string, unknown>): { done: number; total: number; [k: string]: unknown };
21
+ export function isRunActive(run: Record<string, unknown> | null | undefined): boolean;
22
+ export const RunStrip: ComponentType<Record<string, unknown>>;
23
+ export const sheetDoc: typeof doc;
@@ -0,0 +1,10 @@
1
+ // reifyui/sheet — the collaborative spreadsheet: the grid, the document family the sidecar and
2
+ // the browsers share, the collab hook that binds them, and the batch-run strip.
3
+ //
4
+ // A separate entry because the collab hook pulls in yjs (through reifyui/collab). The grid
5
+ // alone is also exported from the root for hosts that render a sheet without live editing.
6
+ export { SheetGrid, sheetToDelimited, sheetToAoA } from './SheetGrid.jsx';
7
+ export { useSheetCollab, sheetOps } from './useSheetCollab.js';
8
+ export { useSheetRun, withQueuedCells, runProgress, isRunActive } from './useSheetRun.js';
9
+ export { RunStrip } from './RunStrip.jsx';
10
+ export * as sheetDoc from './sheetDoc.js';
@@ -0,0 +1,203 @@
1
+ // sheetDoc — the Sheet document family ("cg-sheet:<sheetId>"), ONE module
2
+ // for the collab sidecar (backend/company_brain, which imports it by relative
3
+ // path) and the browsers (ui-core). It takes no dependency of its own: the
4
+ // functions work on Yjs shared types the caller hands in, so the same code
5
+ // runs wherever a Y.Doc exists.
6
+ //
7
+ // The Yjs document IS the sheet while people edit it; the Sheets service's
8
+ // JSON (sheets/<id>/sheet.json) is its materialization, written through the
9
+ // store hook the way brain docs materialize markdown. Every writer, browser
10
+ // grid, copilot tool or batch run, changes the document: browsers through
11
+ // Yjs transactions, services through ops on /v1/cg/publish. Reads that must
12
+ // be current (a run deciding a cell's dependencies) come from the document.
13
+ //
14
+ // Layout, all top-level shared types so a client subscribes to what it draws:
15
+ // meta Y.Map service keys: title, run, copilot
16
+ // taborder Y.Array tab ids in order
17
+ // tabs Y.Map tabId -> {id, name}
18
+ // cols:<tab> Y.Map colId -> column colorder:<tab> Y.Array colId
19
+ // rows:<tab> Y.Map rowId -> row roworder:<tab> Y.Array rowId
20
+ // cells:<tab> Y.Map "rowId:colId" -> cell
21
+ // Maps hold the objects, arrays hold the order: two people inserting rows at
22
+ // once both land, and a cell edit touches one key. Order arrays are read
23
+ // through orderOf(), which drops ids no longer in the map and appends ids
24
+ // the map holds but the order lost, so a concurrent move and delete can
25
+ // never lose an item.
26
+ export const SHEET_PREFIX = 'cg-sheet:';
27
+ export const isSheetDoc = (name) => typeof name === 'string' && name.startsWith(SHEET_PREFIX);
28
+ export const sheetIdOf = (name) => name.slice(SHEET_PREFIX.length);
29
+
30
+ const map = (doc, name) => doc.getMap(name);
31
+ const arr = (doc, name) => doc.getArray(name);
32
+
33
+ /** Ids in array order, deduplicated, only those the map holds, plus the
34
+ * map's strays at the end (in insertion order). */
35
+ export function orderOf(order, m) {
36
+ const seen = new Set();
37
+ const out = [];
38
+ for (const id of order.toArray()) {
39
+ if (m.has(id) && !seen.has(id)) { seen.add(id); out.push(id); }
40
+ }
41
+ for (const id of m.keys()) if (!seen.has(id)) { seen.add(id); out.push(id); }
42
+ return out;
43
+ }
44
+
45
+ function clearMap(m) { for (const k of [...m.keys()]) m.delete(k); }
46
+ function clearArray(a) { if (a.length) a.delete(0, a.length); }
47
+ function removeFromOrder(order, id) {
48
+ const items = order.toArray();
49
+ for (let i = items.length - 1; i >= 0; i--) if (items[i] === id) order.delete(i, 1);
50
+ }
51
+ function placeInOrder(order, id, at) {
52
+ removeFromOrder(order, id);
53
+ const n = order.length;
54
+ const i = Number.isInteger(at) ? Math.max(0, Math.min(at, n)) : n;
55
+ order.insert(i, [id]);
56
+ }
57
+
58
+ function tabIds(doc) {
59
+ return orderOf(arr(doc, 'taborder'), map(doc, 'tabs'));
60
+ }
61
+
62
+ function clearTab(doc, tabId) {
63
+ clearMap(map(doc, `cols:${tabId}`)); clearArray(arr(doc, `colorder:${tabId}`));
64
+ clearMap(map(doc, `rows:${tabId}`)); clearArray(arr(doc, `roworder:${tabId}`));
65
+ clearMap(map(doc, `cells:${tabId}`));
66
+ }
67
+
68
+ function fillTab(doc, tab) {
69
+ const cols = map(doc, `cols:${tab.id}`), colorder = arr(doc, `colorder:${tab.id}`);
70
+ const rows = map(doc, `rows:${tab.id}`), roworder = arr(doc, `roworder:${tab.id}`);
71
+ const cells = map(doc, `cells:${tab.id}`);
72
+ for (const c of tab.columns || []) { cols.set(c.id, c); colorder.push([c.id]); }
73
+ for (const r of tab.rows || []) { rows.set(r.id, r); roworder.push([r.id]); }
74
+ for (const [k, v] of Object.entries(tab.cells || {})) if (v !== null && v !== undefined) cells.set(k, v);
75
+ }
76
+
77
+ /** Replace the document's content with a sheet JSON (fresh open, or an
78
+ * explicit replace). Runs inside one transaction. */
79
+ export function seed(doc, sheet, origin = 'seed') {
80
+ doc.transact(() => {
81
+ for (const id of tabIds(doc)) clearTab(doc, id);
82
+ clearMap(map(doc, 'tabs')); clearArray(arr(doc, 'taborder'));
83
+ const meta = map(doc, 'meta');
84
+ meta.set('title', String((sheet.meta || {}).title || ''));
85
+ for (const tab of sheet.tabs || []) {
86
+ map(doc, 'tabs').set(tab.id, { id: tab.id, name: tab.name });
87
+ arr(doc, 'taborder').push([tab.id]);
88
+ fillTab(doc, tab);
89
+ }
90
+ }, origin);
91
+ }
92
+
93
+ /** The sheet JSON the document currently describes. */
94
+ export function toJSON(doc) {
95
+ const meta = map(doc, 'meta');
96
+ const tabs = tabIds(doc).map((id) => {
97
+ const t = map(doc, 'tabs').get(id) || { id, name: 'Sheet' };
98
+ const cols = map(doc, `cols:${id}`), rows = map(doc, `rows:${id}`), cells = map(doc, `cells:${id}`);
99
+ const columns = orderOf(arr(doc, `colorder:${id}`), cols).map((cid) => cols.get(cid));
100
+ const rowList = orderOf(arr(doc, `roworder:${id}`), rows).map((rid) => rows.get(rid));
101
+ const present = new Set([...columns.map((c) => c.id)]);
102
+ const rowSet = new Set(rowList.map((r) => r.id));
103
+ const out = {};
104
+ for (const [k, v] of cells.entries()) {
105
+ const i = k.indexOf(':');
106
+ if (i > 0 && rowSet.has(k.slice(0, i)) && present.has(k.slice(i + 1))) out[k] = v;
107
+ }
108
+ return { id, name: t.name, columns, rows: rowList, cells: out };
109
+ });
110
+ return { meta: { title: meta.get('title') || '' }, tabs };
111
+ }
112
+
113
+ /** Apply service ops in one transaction. Unknown ops throw; nothing is
114
+ * applied then. */
115
+ export function apply(doc, ops, origin = 'service') {
116
+ if (!Array.isArray(ops)) throw new Error('ops must be a list');
117
+ for (const op of ops) validateOp(op);
118
+ doc.transact(() => {
119
+ for (const op of ops) applyOne(doc, op);
120
+ }, origin);
121
+ }
122
+
123
+ const OPS = new Set(['set_cell', 'set_cells', 'set_column', 'delete_column', 'move_column',
124
+ 'set_row', 'delete_row', 'move_row', 'set_tab', 'delete_tab', 'move_tab', 'set_meta', 'replace']);
125
+
126
+ function validateOp(op) {
127
+ if (!op || typeof op !== 'object' || !OPS.has(op.op)) throw new Error(`unknown op ${op && op.op}`);
128
+ const needTab = !['set_tab', 'delete_tab', 'move_tab', 'set_meta', 'replace'].includes(op.op);
129
+ if (needTab && typeof op.tab !== 'string') throw new Error(`${op.op}: tab required`);
130
+ if (op.op === 'set_cell' && typeof op.key !== 'string') throw new Error('set_cell: key required');
131
+ if (op.op === 'set_cells' && (!op.cells || typeof op.cells !== 'object')) throw new Error('set_cells: cells required');
132
+ if (op.op === 'set_column' && !(op.column && typeof op.column.id === 'string')) throw new Error('set_column: column.id required');
133
+ if (op.op === 'set_row' && !(op.row && typeof op.row.id === 'string')) throw new Error('set_row: row.id required');
134
+ if (op.op === 'set_tab' && !(op.tab && typeof op.tab.id === 'string')) throw new Error('set_tab: tab.id required');
135
+ if ((op.op === 'delete_column' || op.op === 'move_column' || op.op === 'delete_row' || op.op === 'move_row'
136
+ || op.op === 'delete_tab' || op.op === 'move_tab') && typeof op.id !== 'string') throw new Error(`${op.op}: id required`);
137
+ if (op.op === 'set_meta' && typeof op.key !== 'string') throw new Error('set_meta: key required');
138
+ if (op.op === 'replace' && !(op.sheet && typeof op.sheet === 'object')) throw new Error('replace: sheet required');
139
+ }
140
+
141
+ function applyOne(doc, op) {
142
+ switch (op.op) {
143
+ case 'set_cell': {
144
+ const cells = map(doc, `cells:${op.tab}`);
145
+ if (op.cell === null || op.cell === undefined) cells.delete(op.key); else cells.set(op.key, op.cell);
146
+ return;
147
+ }
148
+ case 'set_cells': {
149
+ const cells = map(doc, `cells:${op.tab}`);
150
+ for (const [k, v] of Object.entries(op.cells)) { if (v === null || v === undefined) cells.delete(k); else cells.set(k, v); }
151
+ return;
152
+ }
153
+ case 'set_column': {
154
+ map(doc, `cols:${op.tab}`).set(op.column.id, op.column);
155
+ const order = arr(doc, `colorder:${op.tab}`);
156
+ if (Number.isInteger(op.at) || !order.toArray().includes(op.column.id)) placeInOrder(order, op.column.id, op.at);
157
+ return;
158
+ }
159
+ case 'delete_column': {
160
+ map(doc, `cols:${op.tab}`).delete(op.id);
161
+ removeFromOrder(arr(doc, `colorder:${op.tab}`), op.id);
162
+ const cells = map(doc, `cells:${op.tab}`);
163
+ for (const k of [...cells.keys()]) if (k.endsWith(`:${op.id}`)) cells.delete(k);
164
+ return;
165
+ }
166
+ case 'move_column': placeInOrder(arr(doc, `colorder:${op.tab}`), op.id, op.at); return;
167
+ case 'set_row': {
168
+ map(doc, `rows:${op.tab}`).set(op.row.id, op.row);
169
+ const order = arr(doc, `roworder:${op.tab}`);
170
+ if (Number.isInteger(op.at) || !order.toArray().includes(op.row.id)) placeInOrder(order, op.row.id, op.at);
171
+ return;
172
+ }
173
+ case 'delete_row': {
174
+ map(doc, `rows:${op.tab}`).delete(op.id);
175
+ removeFromOrder(arr(doc, `roworder:${op.tab}`), op.id);
176
+ const cells = map(doc, `cells:${op.tab}`);
177
+ for (const k of [...cells.keys()]) if (k.startsWith(`${op.id}:`)) cells.delete(k);
178
+ return;
179
+ }
180
+ case 'move_row': placeInOrder(arr(doc, `roworder:${op.tab}`), op.id, op.at); return;
181
+ case 'set_tab': {
182
+ const t = op.tab;
183
+ map(doc, 'tabs').set(t.id, { id: t.id, name: String(t.name || 'Sheet') });
184
+ const order = arr(doc, 'taborder');
185
+ if (Number.isInteger(op.at) || !order.toArray().includes(t.id)) placeInOrder(order, t.id, op.at);
186
+ return;
187
+ }
188
+ case 'delete_tab': {
189
+ map(doc, 'tabs').delete(op.id);
190
+ removeFromOrder(arr(doc, 'taborder'), op.id);
191
+ clearTab(doc, op.id);
192
+ return;
193
+ }
194
+ case 'move_tab': placeInOrder(arr(doc, 'taborder'), op.id, op.at); return;
195
+ case 'set_meta': {
196
+ const meta = map(doc, 'meta');
197
+ if (op.value === null || op.value === undefined) meta.delete(op.key); else meta.set(op.key, op.value);
198
+ return;
199
+ }
200
+ case 'replace': seed(doc, op.sheet, 'service'); return;
201
+ default: throw new Error(`unknown op ${op.op}`);
202
+ }
203
+ }
@@ -0,0 +1,102 @@
1
+ // The sheet's live document, shared by every host that renders the grid (the
2
+ // Sheets app, the studio's Spaces page). The Yjs document IS the sheet while
3
+ // people edit it (sheetDoc.js holds the layout); this hook keeps a JSON
4
+ // snapshot of it for rendering and hands out the ops the grid edits with,
5
+ // each a Yjs transaction, so two people never clobber each other and every
6
+ // change reaches every viewer as it happens. The service writes the same
7
+ // document (copilot builds, batch runs) and keeps its own keys on `meta`
8
+ // (run, copilot). Presence rides awareness on the shared live-document core.
9
+ // Hosts differ in auth, so the ticket fetch and the current member are injected.
10
+ import { useCallback, useEffect, useMemo, useState } from 'react';
11
+ import * as sheetDoc from './sheetDoc.js';
12
+ import { useLiveDoc } from '../collab/useLiveDoc.js';
13
+ import { peerColor } from '../collab/colors.js';
14
+
15
+ export { peerColor };
16
+
17
+ const COPILOT_STALE_MS = 15 * 60 * 1000;
18
+
19
+ /** The ops a host edits with, bound to one document. Each is one transaction. */
20
+ export function sheetOps(doc) {
21
+ const one = (op) => sheetDoc.apply(doc, [op], 'local');
22
+ return {
23
+ setCell: (tab, key, cell) => one({ op: 'set_cell', tab, key, cell }),
24
+ setCells: (tab, cells) => one({ op: 'set_cells', tab, cells }),
25
+ setColumn: (tab, column, at) => one({ op: 'set_column', tab, column, ...(Number.isInteger(at) ? { at } : {}) }),
26
+ deleteColumn: (tab, id) => one({ op: 'delete_column', tab, id }),
27
+ moveColumn: (tab, id, at) => one({ op: 'move_column', tab, id, at }),
28
+ setRow: (tab, row, at) => one({ op: 'set_row', tab, row, ...(Number.isInteger(at) ? { at } : {}) }),
29
+ deleteRow: (tab, id) => one({ op: 'delete_row', tab, id }),
30
+ moveRow: (tab, id, at) => one({ op: 'move_row', tab, id, at }),
31
+ setTab: (tab, at) => one({ op: 'set_tab', tab, ...(Number.isInteger(at) ? { at } : {}) }),
32
+ deleteTab: (id) => one({ op: 'delete_tab', id }),
33
+ moveTab: (id, at) => one({ op: 'move_tab', id, at }),
34
+ setTitle: (title) => one({ op: 'set_meta', key: 'title', value: title }),
35
+ };
36
+ }
37
+
38
+ /** Returns { ready, sheet, ops, liveRun, copilotBuilding, peers, setPresence }.
39
+ * fetchTicket(resourceId) -> {url, doc, token} | null (host-authenticated).
40
+ * me -> {id, name, email} of the current member, for presence.
41
+ * Presence (awareness): {id, name, tab, sel: {a:[rowId,colId], f:[rowId,colId]}|null,
42
+ * typing: {key, text}|null, at}; peers come back with their palette color. */
43
+ export function useSheetCollab(resourceId, { fetchTicket, me } = {}) {
44
+ const live = useLiveDoc(resourceId, { fetchTicket, field: 'presence' });
45
+ const [sheet, setSheet] = useState(null);
46
+ const [liveRun, setLiveRun] = useState(null);
47
+ const [copilotBuilding, setCopilotBuilding] = useState(false);
48
+ const who = me || {};
49
+
50
+ // One snapshot per tick however many updates arrive: the grid renders JSON,
51
+ // the document stays the truth. A timer, not an animation frame, so a tab
52
+ // in the background keeps converging and is current the moment someone
53
+ // returns to it.
54
+ useEffect(() => {
55
+ const ydoc = live.doc;
56
+ if (!ydoc) { setSheet(null); setLiveRun(null); setCopilotBuilding(false); return undefined; }
57
+ const meta = ydoc.getMap('meta');
58
+ let timer = 0;
59
+ let dead = false;
60
+ const snapshot = () => {
61
+ timer = 0;
62
+ if (dead) return;
63
+ setSheet(sheetDoc.toJSON(ydoc));
64
+ setLiveRun(meta.get('run') || null);
65
+ const cop = meta.get('copilot');
66
+ setCopilotBuilding(!!(cop && cop.building && (!cop.at || Date.now() - cop.at < COPILOT_STALE_MS)));
67
+ };
68
+ const onUpdate = () => { if (!timer) timer = window.setTimeout(snapshot, 0); };
69
+ ydoc.on('update', onUpdate);
70
+ snapshot();
71
+ return () => { dead = true; ydoc.off('update', onUpdate); window.clearTimeout(timer); };
72
+ }, [live.doc]);
73
+
74
+ // Announce this person on join (no selection yet).
75
+ useEffect(() => {
76
+ live.setAwareness({ id: who.id || '', name: who.name || who.email || 'Someone', tab: null, sel: null, typing: null, at: Date.now() });
77
+ // eslint-disable-next-line react-hooks/exhaustive-deps
78
+ }, [resourceId, live.setAwareness]);
79
+
80
+ // Everyone else in the document: every other client, including this same
81
+ // person in another window (their selection there is worth seeing too).
82
+ const peers = useMemo(() => {
83
+ const out = [];
84
+ for (const st of live.states) {
85
+ const p = st.presence;
86
+ if (!p || !p.id || st.clientId === live.selfClientId) continue;
87
+ out.push({ ...p, clientId: st.clientId, color: peerColor(p.id) });
88
+ }
89
+ return out;
90
+ }, [live.states, live.selfClientId]);
91
+
92
+ const ops = useMemo(() => (live.doc ? sheetOps(live.doc) : null), [live.doc]);
93
+
94
+ /** What this member is doing on a tab: their selection and, while they
95
+ * type in a cell, the text so far. */
96
+ const setPresence = useCallback((tab, state) => {
97
+ live.setAwareness({ id: who.id || '', name: who.name || who.email || 'Someone', tab: tab || null,
98
+ sel: (state && state.sel) || null, typing: (state && state.typing) || null, at: Date.now() });
99
+ }, [live.setAwareness, who.id, who.name, who.email]);
100
+
101
+ return { ready: live.ready, sheet, ops, liveRun, copilotBuilding, peers, setPresence };
102
+ }
@@ -0,0 +1,80 @@
1
+ // A batch run of a sheet, as the grid's hosts see it. The service starts the
2
+ // run; the document's live channel carries every finished cell and the run's
3
+ // own transitions (useSheetCollab: sheet, liveRun), so this hook only
4
+ // needs start and stop. Hosts differ in auth, so the API calls are injected:
5
+ // api.startRun(id, {tab, columns, rows, concurrency}) -> run summary
6
+ // api.cancelRun(id, runId) -> run summary
7
+ import { useCallback, useEffect, useState } from 'react';
8
+
9
+ const ACTIVE = new Set(['running', 'cancelling']);
10
+ export const isRunActive = (run) => !!run && ACTIVE.has(run.status);
11
+
12
+ export function useSheetRun(resourceId, api, liveRun) {
13
+ const [run, setRun] = useState(null);
14
+ const [error, setError] = useState('');
15
+
16
+ useEffect(() => { setRun(null); setError(''); }, [resourceId]);
17
+
18
+ // Adopt the channel's run when it is in progress (a reload, a run someone
19
+ // else or the copilot started) or when it is the one already shown (its
20
+ // outcome). A finished run from before this view opened stays out of the way.
21
+ useEffect(() => {
22
+ if (!liveRun) return;
23
+ setRun((cur) => {
24
+ if (isRunActive(liveRun) || (cur && cur.run_id === liveRun.run_id)) return liveRun;
25
+ return cur;
26
+ });
27
+ }, [liveRun]);
28
+
29
+ const start = useCallback(async (body) => {
30
+ setError('');
31
+ try {
32
+ const r = await api.startRun(resourceId, body);
33
+ setRun(r);
34
+ return r;
35
+ } catch (e) {
36
+ setError(String(e?.message || e));
37
+ return null;
38
+ }
39
+ }, [resourceId, api]);
40
+
41
+ const cancel = useCallback(async () => {
42
+ if (!isRunActive(run)) return;
43
+ try { setRun(await api.cancelRun(resourceId, run.run_id)); }
44
+ catch (e) { setError(String(e?.message || e)); }
45
+ }, [resourceId, api, run]);
46
+
47
+ const dismiss = useCallback(() => { setRun(null); setError(''); }, []);
48
+
49
+ return { run, error, start, cancel, dismiss };
50
+ }
51
+
52
+ /** The tab with the run's pending cells shown as queued: every cell the run
53
+ * will fill that the run has not written yet (running, done, failed or
54
+ * skipped cells carry the run's id). */
55
+ export function withQueuedCells(tab, run) {
56
+ if (!tab || !isRunActive(run) || run.tab_id !== tab.id) return tab;
57
+ const rows = run.rows || (tab.rows || []).map((r) => r.id);
58
+ const cells = { ...(tab.cells || {}) };
59
+ let touched = false;
60
+ for (const rid of rows) {
61
+ for (const col of run.columns || []) {
62
+ const key = `${rid}:${col.id}`;
63
+ const cur = cells[key];
64
+ if (cur && cur.run_id === run.run_id) continue;
65
+ cells[key] = { ...(cur || {}), status: 'queued' };
66
+ touched = true;
67
+ }
68
+ }
69
+ return touched ? { ...tab, cells } : tab;
70
+ }
71
+
72
+ /** How many of the run's cells have a result so far. */
73
+ export function runProgress(tab, run) {
74
+ if (!run) return 0;
75
+ let n = 0;
76
+ for (const cell of Object.values(tab?.cells || {})) {
77
+ if (cell && cell.run_id === run.run_id && cell.status !== 'running') n += 1;
78
+ }
79
+ return n;
80
+ }
package/styles/chat.css CHANGED
@@ -32,16 +32,29 @@
32
32
  /* A turn fills the column; user right-aligned, assistant stacks timeline above prose. */
33
33
  .wbx-turn { display: flex; min-width: 0; padding: 0 var(--uic-turn-pad-x, 28px); }
34
34
  .wbx-turn.user { justify-content: flex-end; }
35
+ /* The optional caption above a turn: who said it. In the user turn it shares a column with the
36
+ bubble (`.wbx-turn-body`) so both start at the same left edge; in the assistant turn it is simply
37
+ the first line. Never a percentage flex-basis here: in a column that is 100% of the HEIGHT. */
38
+ .wbx-role { flex: none; width: 100%; font-family: var(--uic-mono, ui-monospace, monospace); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--uic-cap, #a8a29e); margin-bottom: 7px; }
39
+ .wbx-turn-body { display: flex; flex-direction: column; min-width: 0; max-width: var(--uic-bubble-max-w, 80%); }
40
+ .wbx-turn-body > .wbx-bubble-user { max-width: none; }
35
41
  /* assistant turn stacks vertically: activity timeline ABOVE the answer (never side by side) */
36
42
  .wbx-turn.asst { flex-direction: column; gap: 10px; align-items: stretch; }
37
43
  .wbx-bubble-user { max-width: var(--uic-bubble-max-w, 80%); background: var(--uic-brand-faint, #EFF3FF);
38
44
  border: 1px solid var(--uic-brand-soft, #E1E9FF);
39
45
  color: var(--uic-ink, #111317); border-radius: 16px 16px 5px 16px; padding: 10px 14px;
40
46
  font-size: var(--uic-font-md, 14px); white-space: pre-wrap; line-height: 1.55; }
41
- .wbx-bubble-text { white-space: pre-wrap; }
47
+ /* A pasted URL, hash or base64 blob has no break opportunity, so without this it runs straight
48
+ out of its bubble and gets clipped by whatever encloses it. */
49
+ .wbx-bubble-text { white-space: pre-wrap; overflow-wrap: anywhere; }
42
50
 
43
51
  /* ── rendered markdown — proper typography, not raw text ─────────────────── */
44
- .wbx-md { color: var(--uic-ink, #111317); font-size: var(--uic-font-md, 14px); line-height: 1.62; min-width: 0; }
52
+ /* overflow-wrap: anywhere, not normal: agents answer with hashes, URLs, file paths and base64,
53
+ and an unbreakable 200-character token overflows its own box while the box stays the width of
54
+ the pane. Nothing widens, nothing scrolls, the text is simply clipped away and unreachable.
55
+ It bit hardest in a 340px arena column but the same text is lost in any narrow pane. */
56
+ .wbx-md { color: var(--uic-ink, #111317); font-size: var(--uic-font-md, 14px); line-height: 1.62;
57
+ min-width: 0; overflow-wrap: anywhere; }
45
58
  .wbx-md > :first-child { margin-top: 0; }
46
59
  .wbx-md > :last-child { margin-bottom: 0; }
47
60
  .wbx-md p { margin: 0 0 10px; }
@@ -53,7 +66,8 @@
53
66
  background: var(--uic-brand-faint, #EFF3FF); border: 1px solid var(--uic-line, #DDDFE6); border-radius: 5px; padding: 1px 5px; }
54
67
  .wbx-md pre { background: var(--uic-code-block-bg, #0f1117); color: var(--uic-code-block-ink, #e6e8ee);
55
68
  border-radius: 10px; padding: 12px 14px; overflow: auto; margin: 0 0 10px; }
56
- .wbx-md pre code { background: none; border: none; color: inherit; padding: 0; font-size: 12.5px; line-height: 1.5; }
69
+ .wbx-md pre code { background: none; border: none; color: inherit; padding: 0; font-size: 12.5px; line-height: 1.5;
70
+ overflow-wrap: normal; }
57
71
  /* ── CodeBlock: language-aware syntax highlighting (components/CodeBlock.jsx) ──
58
72
  The block itself carries the same geometry as .wbx-md pre (same padding/radius/font), fully
59
73
  styled here so it also works outside .wbx-md. hljs token classes map onto five --uic-code-*
@@ -85,7 +99,10 @@
85
99
  .wbx-mermaid-fallback { margin: 0 0 10px; }
86
100
  .wbx-md a { color: var(--uic-brand, #285AFF); text-decoration: underline; }
87
101
  .wbx-md blockquote { margin: 0 0 10px; padding: 2px 0 2px 12px; border-left: 3px solid var(--uic-line, #DDDFE6); color: var(--uic-mute, #5B5D66); }
88
- .wbx-md table { border-collapse: collapse; margin: 0 0 10px; font-size: 13px; }
102
+ /* Code and tables cannot wrap without changing their meaning, so a wide one scrolls inside
103
+ itself rather than being squeezed into unreadable columns or clipped at the pane edge. */
104
+ .wbx-md table { border-collapse: collapse; margin: 0 0 10px; font-size: 13px;
105
+ display: block; width: max-content; max-width: 100%; overflow-x: auto; }
89
106
  .wbx-md th, .wbx-md td { border: 1px solid var(--uic-line, #DDDFE6); padding: 5px 9px; text-align: left; }
90
107
 
91
108
  /* ── loading skeleton (ChatMessagesSkeleton) ─────────────────────────────────
@@ -141,6 +158,10 @@
141
158
  animation: wbxblink 1.4s infinite ease-in-out; }
142
159
  .wbx-working-dots span:nth-child(2) { animation-delay: .2s; } .wbx-working-dots span:nth-child(3) { animation-delay: .4s; }
143
160
  .wbx-working-txt { animation: wbxbreath 1.8s ease-in-out infinite; }
161
+ @media (prefers-reduced-motion: reduce) {
162
+ .wbx-working-dots span { animation: none; opacity: .6; }
163
+ .wbx-working-txt { animation: none; opacity: .8; }
164
+ }
144
165
  @keyframes wbxblink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: .9; } }
145
166
  @keyframes wbxbreath { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }
146
167
 
@@ -160,9 +181,17 @@
160
181
  /* auto-grows in JS up to ~15 rows, then scrolls */
161
182
  max-height: calc(var(--uic-font-md, 14px) * 1.5 * 15); }
162
183
  .wbx-composer-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
184
+ /* files held over the composer (or over the wider target a product names): the composer says so */
185
+ .wbx-composer.is-dropping { outline: 2px solid var(--uic-brand, #285AFF); outline-offset: -2px; }
163
186
  /* ── pane resizer (useResizablePane + PaneResizer) ── */
164
- .uic-vresize { flex: 0 0 7px; align-self: stretch; cursor: col-resize; background: transparent; }
187
+ .uic-vresize { flex: 0 0 7px; align-self: stretch; cursor: col-resize; background: transparent; touch-action: none; }
188
+ /* Stacked split (useResizablePane axis 'y'): the bar is horizontal, the drag is vertical. */
189
+ .uic-hresize { flex: 0 0 7px; align-self: stretch; width: 100%; cursor: row-resize; background: transparent; touch-action: none; }
190
+ .uic-hresize:hover { background: var(--uic-brand-soft); }
191
+ body.uic-resizing-y { user-select: none; cursor: row-resize; }
192
+ body.uic-resizing-y iframe { pointer-events: none; }
165
193
  .uic-vresize:hover { background: var(--uic-brand-soft, #E1E9FF); }
194
+ .uic-vresize:focus-visible { outline: none; background: var(--uic-brand, #285AFF); opacity: .5; }
166
195
  /* While dragging, neutralize embedded iframes + selection so mouseup always lands. */
167
196
  body.uic-resizing { user-select: none; cursor: col-resize; }
168
197
  body.uic-resizing iframe { pointer-events: none; }
@@ -320,3 +349,16 @@ body.uic-resizing iframe { pointer-events: none; }
320
349
  /* Dragging the divider is meaningless once the panel floats over the page. */
321
350
  body:has(.uic-chat:not(.is-collapsed)) .uic-vresize { display: none; }
322
351
  }
352
+
353
+ /* ── Composer tray (Composer.jsx `tray`) ──
354
+ Inside the card, under the action row, on the SAME surface — no divider band, no tinted
355
+ strip: the wireframe's "one box" reading. Wraps on narrow widths. */
356
+ .uic-composer-tray { display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
357
+ padding: 2px 2px 4px; }
358
+
359
+ /* ── Composer inline line (Composer.jsx `inline`) ── one row: accessories, textarea, send.
360
+ Centered, not flex-end: a single-line textarea's text must sit on the buttons' axis, and
361
+ bottom-pinning left the text visibly below them (measured). Multiline drafts keep the
362
+ buttons centered on the grown box, which is the common chat-input behavior. */
363
+ .uic-composer-line { display: flex; align-items: center; gap: 8px; }
364
+ .uic-composer-line textarea { flex: 1; min-width: 0; }
package/styles/chip.css CHANGED
@@ -51,3 +51,39 @@ button.uic-chip:hover { border-color: var(--uic-brand, #285AFF); color: var(--ui
51
51
  .uic-pop-item.is-on { background: var(--uic-brand-soft, #E1E9FF);
52
52
  color: var(--uic-brand-ink, #1641D8); font-weight: 600; }
53
53
  .uic-pop-check { width: 15px; flex-shrink: 0; display: inline-flex; color: var(--uic-brand, #285AFF); }
54
+
55
+ /* trailing — the compact control a chip can carry (Chip.jsx `trailing`). The chip supplies
56
+ spacing only; the control keeps its own semantics and focus behavior. */
57
+ .uic-chip-tr { display: inline-flex; align-items: center; min-width: 0; }
58
+ .uic-chip-tr select { border: none; background: transparent; font: inherit; font-size: 11.5px;
59
+ color: var(--uic-mute, #5B5D66); cursor: pointer; max-width: 160px; }
60
+ .uic-chip-tr select:focus { outline: none; color: var(--uic-ink, #111317); }
61
+
62
+ /* ── CascadeMenu ────────────────────────────────────────────────────────────
63
+ Two columns inside a Popover: items on the left, the highlighted item's options on the right.
64
+ Each column scrolls on its own inside the height the popover was given. Under the stack
65
+ breakpoint (JS) only one column shows at a time and the options column carries a way back. */
66
+ .uic-cascade { flex: 1; min-height: 0; display: flex; gap: 0; }
67
+ .uic-cascade-col { flex: 1 1 0; min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 6px; }
68
+ .uic-cascade-options { border-left: 1px solid var(--uic-line-soft, #EFF1F4); margin-left: 8px; padding-left: 8px; }
69
+ .uic-cascade.is-stacked .uic-cascade-options { border-left: 0; margin-left: 0; padding-left: 0; }
70
+ .uic-cascade-filter { flex: none; }
71
+ .uic-cascade-group { padding: 6px 10px 2px; font-size: 11px; font-weight: 600; letter-spacing: .04em;
72
+ text-transform: uppercase; color: var(--uic-mute, #5B5D66); }
73
+ .uic-cascade-head { flex: none; display: flex; align-items: center; gap: 8px; min-height: 32px; padding: 0 10px;
74
+ font-size: 13px; font-weight: 600; color: var(--uic-ink, #111317); }
75
+ .uic-cascade-back { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px;
76
+ margin-left: -6px; border: 0; border-radius: 8px; background: none; color: var(--uic-mute, #5B5D66); cursor: pointer; }
77
+ .uic-cascade-back:hover { background: var(--uic-line-soft, #EFF1F4); color: var(--uic-ink, #111317); }
78
+ .uic-cascade-ic { display: inline-flex; flex-shrink: 0; line-height: 0; }
79
+ .uic-cascade-item .uic-chip-t, .uic-cascade-opt .uic-chip-t { flex: 1; }
80
+ .uic-cascade-chev { display: inline-flex; flex-shrink: 0; color: var(--uic-mute, #5B5D66); opacity: .6; }
81
+ /* The highlighted item is the one whose options show: it reads as "open", not as "chosen". */
82
+ .uic-cascade-item.is-active { background: var(--uic-line-soft, #EFF1F4); color: var(--uic-ink, #111317); }
83
+ .uic-cascade-note { flex-shrink: 0; font-size: 11px; color: var(--uic-mute, #5B5D66); }
84
+ .uic-pop-item:disabled { opacity: .5; cursor: default; }
85
+ .uic-pop-item:disabled:hover { background: none; }
86
+ .uic-pop-item:focus-visible { outline: 2px solid var(--uic-brand, #285AFF); outline-offset: -2px; }
87
+ /* The press target of a split chip (label + trailing control + ✕) answers hover like the
88
+ one-piece button chip does. */
89
+ .uic-chip-press:hover { color: var(--uic-brand-ink, #1641D8); }