reifyui 0.12.0 → 0.13.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 +29 -0
- package/dist/chart.js +2 -0
- package/dist/chart.js.map +1 -1
- package/dist/chunk-EL2DHWOH.js +1710 -0
- package/dist/chunk-EL2DHWOH.js.map +1 -0
- package/dist/chunk-J633KV57.js +41 -0
- package/dist/chunk-J633KV57.js.map +1 -0
- package/dist/chunk-J7SECRIG.js +295 -0
- package/dist/chunk-J7SECRIG.js.map +1 -0
- package/dist/chunk-PIRPLH2Z.js +231 -0
- package/dist/chunk-PIRPLH2Z.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-UKG4Z6QK.js +130 -0
- package/dist/chunk-UKG4Z6QK.js.map +1 -0
- package/dist/chunk-ZYWE47EO.js +19 -0
- package/dist/chunk-ZYWE47EO.js.map +1 -0
- package/dist/collab.cjs +169 -0
- package/dist/collab.cjs.map +1 -0
- package/dist/collab.d.ts +30 -0
- package/dist/collab.js +18 -0
- package/dist/collab.js.map +1 -0
- package/dist/graph.cjs +2244 -0
- package/dist/graph.cjs.map +1 -0
- package/dist/graph.d.ts +41 -0
- package/dist/graph.js +1870 -0
- package/dist/graph.js.map +1 -0
- package/dist/harness.js +1 -0
- package/dist/harness.js.map +1 -1
- package/dist/index.cjs +1699 -817
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +680 -1769
- package/dist/index.js.map +1 -1
- package/dist/sheet-doc.cjs +235 -0
- package/dist/sheet-doc.cjs.map +1 -0
- package/dist/sheet-doc.d.ts +16 -0
- package/dist/sheet-doc.js +20 -0
- package/dist/sheet-doc.js.map +1 -0
- package/dist/sheet.cjs +2322 -0
- package/dist/sheet.cjs.map +1 -0
- package/dist/sheet.d.ts +23 -0
- package/dist/sheet.js +237 -0
- package/dist/sheet.js.map +1 -0
- package/dist/slides.js +2 -0
- package/dist/slides.js.map +1 -1
- package/package.json +34 -2
- package/src/auth/client.js +4 -2
- package/src/collab/colors.js +18 -0
- package/src/collab/index.d.ts +30 -0
- package/src/collab/index.js +8 -0
- package/src/collab/keepAlive.js +34 -0
- package/src/collab/useLiveDoc.js +76 -0
- package/src/components/CascadeMenu.jsx +9 -3
- package/src/components/Composer.jsx +37 -3
- package/src/components/resizable.jsx +82 -12
- package/src/graph/ConnectPane.jsx +634 -0
- package/src/graph/ConnectToolDetail.jsx +565 -0
- package/src/graph/LogsPane.jsx +328 -0
- package/src/graph/Skeleton.jsx +13 -0
- package/src/graph/draft.js +108 -0
- package/src/graph/format.js +37 -0
- package/src/graph/index.d.ts +41 -0
- package/src/graph/index.js +14 -0
- package/src/graph/useGraphCollab.js +299 -0
- package/src/graph/vgraph.js +215 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +4 -1
- package/src/mention/MentionInput.jsx +420 -0
- package/src/mention/mentionModel.js +177 -0
- package/src/sheet/RunStrip.jsx +57 -0
- package/src/sheet/SheetGrid.jsx +448 -423
- package/src/sheet/doc.d.ts +16 -0
- package/src/sheet/index.d.ts +23 -0
- package/src/sheet/index.js +10 -0
- package/src/sheet/sheetDoc.js +203 -0
- package/src/sheet/useSheetCollab.js +102 -0
- package/src/sheet/useSheetRun.js +80 -0
- package/styles/chat.css +2 -0
- package/styles/graph.css +395 -0
- package/styles/mention.css +79 -0
- 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
|
@@ -181,6 +181,8 @@
|
|
|
181
181
|
/* auto-grows in JS up to ~15 rows, then scrolls */
|
|
182
182
|
max-height: calc(var(--uic-font-md, 14px) * 1.5 * 15); }
|
|
183
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; }
|
|
184
186
|
/* ── pane resizer (useResizablePane + PaneResizer) ── */
|
|
185
187
|
.uic-vresize { flex: 0 0 7px; align-self: stretch; cursor: col-resize; background: transparent; touch-action: none; }
|
|
186
188
|
/* Stacked split (useResizablePane axis 'y'): the bar is horizontal, the drag is vertical. */
|