@rowsncolumns/y-spreadsheet 17.0.2 → 17.1.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.
- package/dist/cjs/helpers-v5.d.ts +79 -5
- package/dist/cjs/helpers-v5.d.ts.map +1 -1
- package/dist/cjs/helpers-v5.js +345 -33
- package/dist/cjs/use-yspreadsheet-v2.d.ts +1 -1
- package/dist/cjs/use-yspreadsheet-v2.d.ts.map +1 -1
- package/dist/cjs/use-yspreadsheet-v2.js +4 -3
- package/dist/esm/helpers-v5.d.ts +79 -5
- package/dist/esm/helpers-v5.d.ts.map +1 -1
- package/dist/esm/helpers-v5.js +335 -32
- package/dist/esm/use-yspreadsheet-v2.d.ts +1 -1
- package/dist/esm/use-yspreadsheet-v2.d.ts.map +1 -1
- package/dist/esm/use-yspreadsheet-v2.js +4 -3
- package/package.json +4 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-yspreadsheet-v2.d.ts","sourceRoot":"","sources":["../../use-yspreadsheet-v2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAEL,UAAU,EACV,KAAK,QAAQ,EAEb,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAC7B,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,KAAK,EACV,KAAK,SAAS,EACf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,g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0CC,sBAAsB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;;;gCAgxBtB,CACP,KAAK,EAAE,gBAAgB,CAAC,KAAK,CAAC,EAC9B,IAAI,CAAC,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CACtC,EAAE;;;CA6SR,CAAC"}
|
|
@@ -635,9 +635,9 @@ var useYSpreadsheetV2 = function (_a) {
|
|
|
635
635
|
ySheetDataV3.unobserve(callback);
|
|
636
636
|
};
|
|
637
637
|
}, [onChangeSheetData, ySheetDataV3, useV3, yjs, observesLocal]);
|
|
638
|
-
// Only for sheet Data (V5 docs): `rncCells`, `rncNotes`, the style planes
|
|
639
|
-
// every sheet's id arrays. A change of an id array, a
|
|
640
|
-
// `docMeta`): full re-read; a cell or note change alone is applied
|
|
638
|
+
// Only for sheet Data (V5 docs): `rncCells`, `rncNotes`, the style planes,
|
|
639
|
+
// the cold blocks and every sheet's id arrays. A change of an id array, a
|
|
640
|
+
// style plane, a cold block (or of `docMeta`): full re-read; a cell or note change alone is applied
|
|
641
641
|
// incrementally. Roots are matched by name in `doc.share`, so a root a peer
|
|
642
642
|
// created after this effect ran is seen too.
|
|
643
643
|
(0, ui_1.useIsomorphicLayoutEffect)(function () {
|
|
@@ -658,6 +658,7 @@ var useYSpreadsheetV2 = function (_a) {
|
|
|
658
658
|
changed.forEach(function (key) { return key !== null && cellKeys.push(key); });
|
|
659
659
|
}
|
|
660
660
|
else if (name_1 === "docMeta" ||
|
|
661
|
+
name_1 === "rncColumnBlocks" ||
|
|
661
662
|
name_1 === "rncCellStylesLog" ||
|
|
662
663
|
name_1 === "rncCellStyles" ||
|
|
663
664
|
name_1.startsWith("rncRowIds:") ||
|
package/dist/esm/helpers-v5.d.ts
CHANGED
|
@@ -26,9 +26,25 @@ export declare const parseCellKeyV5: (key: string) => ParsedCellKeyV5 | null;
|
|
|
26
26
|
*/
|
|
27
27
|
export declare const readStyleOverlayV5: (doc: YDoc) => StyleOverlayV5;
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
|
|
29
|
+
* Cell bodies of a block by row offset (`decode_cell_block_bodies`, v1 too).
|
|
30
|
+
* A malformed block reads as the entries decoded before the damage.
|
|
31
|
+
*/
|
|
32
|
+
export declare const decodeColumnBlockV5: (buf: Uint8Array) => Map<number, CellData>;
|
|
33
|
+
/**
|
|
34
|
+
* Whether the doc's format marker says `sheet-format.cells >= 2`
|
|
35
|
+
* (`stage2_cell_format` in rnc-yrs-store-v3): on a v5 doc past it, formula text
|
|
36
|
+
* is rendered from `ft` on read and a stored `ue.fv` may be stale.
|
|
37
|
+
*/
|
|
38
|
+
export declare const v5RendersFormulaTextOnRead: (doc: YDoc) => boolean;
|
|
39
|
+
/** What every reader and writer here throws on a doc past the marker. */
|
|
40
|
+
export declare class V5FormulaTextOnReadError extends Error {
|
|
41
|
+
constructor();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A v5 doc as V2 `SheetData` (same shape as `sheetDataV3ToV2`): every key of
|
|
45
|
+
* `rncCells`, `rncNotes`, the composed style plane and every cold block entry,
|
|
46
|
+
* composed as `composeCell` does (hot shadows cold; tombstones and orphans
|
|
47
|
+
* skipped). Inflates every cold block once.
|
|
32
48
|
*/
|
|
33
49
|
export declare const sheetDataV5ToV2: <T extends CellData>(doc: YDoc, styles?: ReadonlyMap<string, CellFormat>) => SheetData<T>;
|
|
34
50
|
/**
|
|
@@ -40,10 +56,68 @@ export declare const createCellReaderV5: <T extends CellData = CellData>(doc: YD
|
|
|
40
56
|
export declare const getCellV5: <T extends CellData = CellData>(doc: YDoc, sheetId: number, rowIndex: number, columnIndex: number, styles?: ReadonlyMap<string, CellFormat>) => T | undefined;
|
|
41
57
|
/**
|
|
42
58
|
* Apply changed `rncCells` / `rncNotes` keys to `currentSheetData` (copy-on-write,
|
|
43
|
-
* like `processSheetDataEventsV3`), `uf` from `styles
|
|
44
|
-
*
|
|
59
|
+
* like `processSheetDataEventsV3`), `uf` from `styles`; a removed hot entry
|
|
60
|
+
* reveals the cold cell under it. Only valid while no id array, no style and no
|
|
61
|
+
* cold block changed (those need `sheetDataV5ToV2`). Null when nothing changed.
|
|
45
62
|
*/
|
|
46
63
|
export declare const processSheetDataChangesV5: <T extends CellData>(changedKeys: Iterable<string>, currentSheetData: SheetData<T>, doc: YDoc, styles?: ReadonlyMap<string, CellFormat>) => SheetData<T> | null;
|
|
64
|
+
/** A decoded `Addr`; line ids as decimal strings, `null` = an open side (`B:B`, `1:1`). */
|
|
65
|
+
export type FacetAddrV5 = {
|
|
66
|
+
kind: "range";
|
|
67
|
+
sheetId: number;
|
|
68
|
+
r0: string | null;
|
|
69
|
+
r1: string | null;
|
|
70
|
+
c0: string | null;
|
|
71
|
+
c1: string | null;
|
|
72
|
+
} | {
|
|
73
|
+
kind: "cell" | "point";
|
|
74
|
+
sheetId: number;
|
|
75
|
+
row: string;
|
|
76
|
+
col: string;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* How one anchored map of a facet value reads:
|
|
80
|
+
* - `positional`: no usable anchor (none, undecodable, its recorded fields no
|
|
81
|
+
* longer equal the stored ones, or it names another sheet's lines): the
|
|
82
|
+
* stored positional fields are the truth.
|
|
83
|
+
* - `resolved`: the positional fields now (`fields`; an open side's field is
|
|
84
|
+
* absent and keeps its stored value).
|
|
85
|
+
* - `engine`: a corner line is not in this doc's axis (deleted, or not synced
|
|
86
|
+
* yet). The engine repairs or falls back from what its session saw; a native
|
|
87
|
+
* reader cannot, so read the facet through the engine (or treat it as stale).
|
|
88
|
+
*/
|
|
89
|
+
export type ResolvedFacetAnchorV5 = {
|
|
90
|
+
status: "positional";
|
|
91
|
+
} | {
|
|
92
|
+
status: "resolved";
|
|
93
|
+
fields: Record<string, number>;
|
|
94
|
+
} | {
|
|
95
|
+
status: "engine";
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Decode a facet `anchor` buffer (`decode_anchor`): `u8 n`, the `n` positional
|
|
99
|
+
* fields as written (zigzag varints), then one `Addr` filling the rest.
|
|
100
|
+
*/
|
|
101
|
+
export declare const decodeFacetAnchorV5: (buf: Uint8Array) => {
|
|
102
|
+
frame: number[];
|
|
103
|
+
addr: FacetAddrV5;
|
|
104
|
+
} | null;
|
|
105
|
+
/**
|
|
106
|
+
* Resolve the `anchor` of one anchored map inside a facet value (`site_now`):
|
|
107
|
+
* `site` `"range"` = a map with `startRowIndex`…`endColumnIndex` (a named
|
|
108
|
+
* range, merge, CF / DV range, table, chart range, …), `"cell"` = a one-cell
|
|
109
|
+
* map (`rowIndex` / `columnIndex`) that goes with its lines (data-table input,
|
|
110
|
+
* scenario cells), `"point"` = a floating object's anchor cell. `sheetId` is
|
|
111
|
+
* the sheet the facet lives on.
|
|
112
|
+
*
|
|
113
|
+
* Only live corner lines are resolved here; anything the engine would repair
|
|
114
|
+
* (a deleted line) or fall back on (a line this replica never saw) answers
|
|
115
|
+
* `engine`. Which maps of which facet carry an anchor (and the derived ones:
|
|
116
|
+
* table filter column offsets, print breaks, print titles) is the engine's
|
|
117
|
+
* walk (`facet_anchor.rs`); for those, and whenever the exact answer matters,
|
|
118
|
+
* read facets through the engine.
|
|
119
|
+
*/
|
|
120
|
+
export declare const resolveFacetAnchorV5: (doc: YDoc, sheetId: number, value: Record<string, unknown>, site: "range" | "cell" | "point") => ResolvedFacetAnchorV5;
|
|
47
121
|
/**
|
|
48
122
|
* Apply immer `SheetData` patches to a v5 doc in one transaction (`origin`, the
|
|
49
123
|
* caller's; nested in an open transaction it joins that one). Positional, like
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers-v5.d.ts","sourceRoot":"","sources":["../../helpers-v5.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helpers-v5.d.ts","sourceRoot":"","sources":["../../helpers-v5.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;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AAA;CAAE,GACxB;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GACtD;IAAE,MAAM,EAAE,QAAQ,CAAA;CAAE,CAAC;AAgBzB;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAC9B,KAAK,UAAU,KACd;IAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,WAAW,CAAA;CAAE,GAAG,IA8C3C,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,oBAAoB,GAC/B,KAAK,IAAI,EACT,SAAS,MAAM,EACf,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,MAAM,OAAO,GAAG,MAAM,GAAG,OAAO,KAC/B,qBAmDF,CAAC;AA0SF;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,GAChC,KAAK,IAAI,EACT,SAAS,KAAK,EAAE,GAAG,SAAS,EAC5B,SAAQ,OAAc,EACtB,SAAS,cAAc,SA+CxB,CAAC;AAEF,8DAA8D;AAC9D,eAAO,MAAM,SAAS,GACpB,KAAK,IAAI,EACT,SAAS,MAAM,EACf,UAAU,MAAM,EAChB,aAAa,MAAM,EACnB,OAAO,QAAQ,KACd,IAGC,CAAC;AAEL,iEAAiE;AACjE,eAAO,MAAM,YAAY,GACvB,KAAK,IAAI,EACT,SAAS,MAAM,EACf,UAAU,MAAM,EAChB,aAAa,MAAM,KAClB,IAGC,CAAC;AAEL,kFAAkF;AAClF,eAAO,MAAM,aAAa,GAAI,KAAK,IAAI,EAAE,SAAS,MAAM,KAAG,IACM,CAAC"}
|
package/dist/esm/helpers-v5.js
CHANGED
|
@@ -5,15 +5,28 @@
|
|
|
5
5
|
// (`RNC_CELLS`, `c0_floor`, …) are the Rust ones in rust/crates/rnc-yrs-store/src
|
|
6
6
|
// (lib.rs unless a module is named); they win over this module.
|
|
7
7
|
//
|
|
8
|
-
// Readers
|
|
9
|
-
// `
|
|
10
|
-
// `
|
|
8
|
+
// Readers: `sheetDataV5ToV2`, `getCellV5`, `createCellReaderV5`,
|
|
9
|
+
// `processSheetDataChangesV5`. A cell is its hot `rncCells` entry, else its cold
|
|
10
|
+
// `rncColumnBlocks` body (a hot `null` hides the cold cell; orphans of deleted
|
|
11
|
+
// lines are skipped); `uf` from the composed style plane, `note` from
|
|
12
|
+
// `rncNotes`, so a cell read here can be written back unchanged.
|
|
13
|
+
// Facets: `resolveFacetAnchorV5` resolves one stored `anchor` from live line
|
|
14
|
+
// ids; a deleted or unsynced corner line needs the engine's repair.
|
|
11
15
|
// Writer: `addSheetDataPatchesV5` applies immer `SheetData` patches positionally
|
|
12
16
|
// (a structural edit arrives as rewritten rows, v3 parity); it names lines past
|
|
13
17
|
// an axis with client-0 ids exactly as `YrsStore::ensure_lines` does and logs
|
|
14
|
-
// `uf` changes as `STYLE_LOG_V2` ops. It never writes `ft
|
|
15
|
-
//
|
|
18
|
+
// `uf` changes as `STYLE_LOG_V2` ops. It never writes `ft` (engine-owned: the
|
|
19
|
+
// engine derives it on its next write of the cell; until then the formula is
|
|
20
|
+
// positional in its write frame, `ue.fv` being the truth) and never writes a
|
|
21
|
+
// facet `anchor` (a facet written here is positional and gains one on its next
|
|
22
|
+
// engine write).
|
|
23
|
+
// Past the Stage 2 format marker (`sheet-format.cells >= 2`) a structural edit
|
|
24
|
+
// leaves `ue.fv` as written and the engine renders formula text from `ft` on
|
|
25
|
+
// read, so a stored `ue.fv` may name cells the formula no longer reads. This
|
|
26
|
+
// module reads `ue.fv` as stored: every reader and writer here refuses such a
|
|
27
|
+
// doc (`V5FormulaTextOnReadError`); read it through the engine.
|
|
16
28
|
import { getCellUserEnteredFormat } from "@rowsncolumns/utils";
|
|
29
|
+
import { inflateSync } from "fflate";
|
|
17
30
|
import * as decoding from "lib0/decoding";
|
|
18
31
|
import * as encoding from "lib0/encoding";
|
|
19
32
|
import cloneDeep from "lodash/cloneDeep";
|
|
@@ -30,7 +43,10 @@ const BLOCKS_V5 = "rncColumnBlocks"; // RNC_COLUMN_BLOCKS
|
|
|
30
43
|
const BLOCK_ROWS = 32768; // BLOCK_ROWS
|
|
31
44
|
const BLOCK_V2_MAGIC = 0x80000000; // BLOCK_V2_MAGIC
|
|
32
45
|
const BLOCK_V2_DENSE = 0x40000000; // BLOCK_V2_DENSE
|
|
46
|
+
const MAX_BLOCK_RAW_BYTES = 512 * 1024 * 1024; // MAX_BLOCK_RAW_BYTES
|
|
33
47
|
const STYLE_LOG_V1 = 1; // STYLE_LOG_V1
|
|
48
|
+
const FORMAT_ROOT = "sheet-format"; // rnc-yrs-store-v3 node_cell::FORMAT_ROOT
|
|
49
|
+
const NODE_CELL_FORMAT = 2; // rnc-yrs-store-v3 node_cell::NODE_CELL_FORMAT
|
|
34
50
|
const STYLE_LOG_V2 = 2; // STYLE_LOG_V2
|
|
35
51
|
const CELL_KEY_V5 = /^(-?\d+):(-?\d+):(-?\d+)$/; // cell_key
|
|
36
52
|
const BLOCK_KEY_V5 = /^(-?\d+):(-?\d+):(\d+)$/; // block_key
|
|
@@ -275,16 +291,128 @@ const coldCellExists = (doc, cache, sheetId, rowId, colId) => {
|
|
|
275
291
|
}
|
|
276
292
|
return offsets.has((counter - 1) % BLOCK_ROWS);
|
|
277
293
|
};
|
|
294
|
+
/**
|
|
295
|
+
* Cell bodies of a block by row offset (`decode_cell_block_bodies`, v1 too).
|
|
296
|
+
* A malformed block reads as the entries decoded before the damage.
|
|
297
|
+
*/
|
|
298
|
+
export const decodeColumnBlockV5 = (buf) => {
|
|
299
|
+
const out = new Map();
|
|
300
|
+
if (buf.length < 4)
|
|
301
|
+
return out;
|
|
302
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
303
|
+
const text = new TextDecoder();
|
|
304
|
+
const body = (bytes, pos, len) => {
|
|
305
|
+
if (pos + len > bytes.length)
|
|
306
|
+
return null;
|
|
307
|
+
const value = JSON.parse(text.decode(bytes.subarray(pos, pos + len)));
|
|
308
|
+
return isPlainObject(value) ? value : null;
|
|
309
|
+
};
|
|
310
|
+
try {
|
|
311
|
+
const first = view.getUint32(0, true);
|
|
312
|
+
if (first & BLOCK_V2_MAGIC) {
|
|
313
|
+
const offsets = blockRowOffsets(buf);
|
|
314
|
+
const pos = 8 + (first & BLOCK_V2_DENSE ? 0 : offsets.length * 4);
|
|
315
|
+
if (pos + 4 > buf.length)
|
|
316
|
+
return out;
|
|
317
|
+
const rawLen = view.getUint32(pos, true);
|
|
318
|
+
if (rawLen > MAX_BLOCK_RAW_BYTES)
|
|
319
|
+
return out;
|
|
320
|
+
const bodies = inflateSync(buf.subarray(pos + 4), { out: new Uint8Array(rawLen) });
|
|
321
|
+
const bodyView = new DataView(bodies.buffer, bodies.byteOffset, bodies.byteLength);
|
|
322
|
+
for (let i = 0, at = 0; i < offsets.length && at + 4 <= bodies.length; i++) {
|
|
323
|
+
const len = bodyView.getUint32(at, true);
|
|
324
|
+
const cell = body(bodies, at + 4, len);
|
|
325
|
+
if (cell)
|
|
326
|
+
out.set(offsets[i], cell);
|
|
327
|
+
at += 4 + len;
|
|
328
|
+
}
|
|
329
|
+
return out;
|
|
330
|
+
}
|
|
331
|
+
for (let i = 0, pos = 4; i < first && pos + 8 <= buf.length; i++) {
|
|
332
|
+
const offset = view.getUint32(pos, true);
|
|
333
|
+
const len = view.getUint32(pos + 4, true);
|
|
334
|
+
const cell = body(buf, pos + 8, len);
|
|
335
|
+
if (cell)
|
|
336
|
+
out.set(offset, cell);
|
|
337
|
+
pos += 8 + len;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
catch (_e) {
|
|
341
|
+
// Truncated deflate stream or a body that is not JSON: keep what decoded.
|
|
342
|
+
}
|
|
343
|
+
return out;
|
|
344
|
+
};
|
|
345
|
+
/** Whether `rncColumnBlocks` key `key` is a v5 block (its column part a line id, not `< 2^32`). */
|
|
346
|
+
const parseBlockKeyV5 = (key) => {
|
|
347
|
+
const match = BLOCK_KEY_V5.exec(key);
|
|
348
|
+
if (!match)
|
|
349
|
+
return null;
|
|
350
|
+
const colId = BigInt(match[2]);
|
|
351
|
+
if (BigInt.asIntN(64, colId) !== colId || idCounter(colId) === 0)
|
|
352
|
+
return null;
|
|
353
|
+
return { sheetId: Number(match[1]), colId: colId.toString(), block: Number(match[3]) };
|
|
354
|
+
};
|
|
355
|
+
/**
|
|
356
|
+
* The cold body of the cell at `rowId` × `colId`: entry `(counter - 1) % BLOCK_ROWS`
|
|
357
|
+
* of block `(counter - 1) / BLOCK_ROWS` of the column, for a client-0 row id only.
|
|
358
|
+
*/
|
|
359
|
+
const coldCellV5 = (doc, cache, sheetId, rowId, colId) => {
|
|
360
|
+
const counter = c0Counter(rowId);
|
|
361
|
+
if (!counter || !doc.share.has(BLOCKS_V5))
|
|
362
|
+
return null;
|
|
363
|
+
const key = `${sheetId}:${colId}:${Math.floor((counter - 1) / BLOCK_ROWS)}`;
|
|
364
|
+
let cells = cache.get(key);
|
|
365
|
+
if (!cells) {
|
|
366
|
+
const buf = doc.get(BLOCKS_V5).getAttr(key);
|
|
367
|
+
cells = buf instanceof Uint8Array ? decodeColumnBlockV5(buf) : new Map();
|
|
368
|
+
cache.set(key, cells);
|
|
369
|
+
}
|
|
370
|
+
return cells.get((counter - 1) % BLOCK_ROWS) ?? null;
|
|
371
|
+
};
|
|
278
372
|
// ── readers ─────────────────────────────────────────────────────────────────
|
|
279
373
|
/**
|
|
280
|
-
*
|
|
281
|
-
* `
|
|
282
|
-
*
|
|
374
|
+
* Whether the doc's format marker says `sheet-format.cells >= 2`
|
|
375
|
+
* (`stage2_cell_format` in rnc-yrs-store-v3): on a v5 doc past it, formula text
|
|
376
|
+
* is rendered from `ft` on read and a stored `ue.fv` may be stale.
|
|
283
377
|
*/
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
378
|
+
export const v5RendersFormulaTextOnRead = (doc) => {
|
|
379
|
+
if (!doc.share.has(FORMAT_ROOT))
|
|
380
|
+
return false;
|
|
381
|
+
const cells = doc.get(FORMAT_ROOT).getAttr("cells");
|
|
382
|
+
return typeof cells === "number" && cells >= NODE_CELL_FORMAT;
|
|
383
|
+
};
|
|
384
|
+
/** What every reader and writer here throws on a doc past the marker. */
|
|
385
|
+
export class V5FormulaTextOnReadError extends Error {
|
|
386
|
+
constructor() {
|
|
387
|
+
super("This sheet renders formula text on read (sheet-format.cells >= 2): read and write it through the engine");
|
|
388
|
+
this.name = "V5FormulaTextOnReadError";
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
const refuseRenderedText = (doc) => {
|
|
392
|
+
if (v5RendersFormulaTextOnRead(doc))
|
|
393
|
+
throw new V5FormulaTextOnReadError();
|
|
394
|
+
};
|
|
395
|
+
/**
|
|
396
|
+
* The stored value of the cell under `key`: its hot entry (`ft` stripped; a
|
|
397
|
+
* `null` or any non-map is a tombstone and reads null), else its cold body.
|
|
398
|
+
*/
|
|
399
|
+
const storedCellV5 = (doc, key, cold) => {
|
|
400
|
+
const hot = doc.share.has(CELLS_V5) ? doc.get(CELLS_V5) : null;
|
|
401
|
+
if (hot?.hasAttr(key))
|
|
402
|
+
return cellDataV5(hot.getAttr(key));
|
|
403
|
+
const parsed = parseCellKeyV5(key);
|
|
404
|
+
if (!parsed)
|
|
405
|
+
return null;
|
|
406
|
+
const body = coldCellV5(doc, cold, parsed.sheetId, parsed.rowId, parsed.colId);
|
|
407
|
+
return body ? cellDataV5(body) : null;
|
|
408
|
+
};
|
|
409
|
+
/**
|
|
410
|
+
* The cell under `key` as the readers show it: the stored value
|
|
411
|
+
* (`storedCellV5`), `uf` from `styles` where it has an entry, `note` from
|
|
412
|
+
* `rncNotes` where it has one. Null when none of the three holds anything.
|
|
413
|
+
*/
|
|
414
|
+
const composeCell = (doc, key, styles, cold) => {
|
|
415
|
+
let cell = storedCellV5(doc, key, cold);
|
|
288
416
|
const uf = styles.get(key);
|
|
289
417
|
if (uf)
|
|
290
418
|
cell = { ...cell, uf };
|
|
@@ -294,13 +422,16 @@ const composeCell = (doc, key, styles) => {
|
|
|
294
422
|
return cell;
|
|
295
423
|
};
|
|
296
424
|
/**
|
|
297
|
-
* A v5 doc as V2 `SheetData` (same shape as `sheetDataV3ToV2`)
|
|
298
|
-
*
|
|
299
|
-
* `composeCell` does (tombstones and orphans
|
|
425
|
+
* A v5 doc as V2 `SheetData` (same shape as `sheetDataV3ToV2`): every key of
|
|
426
|
+
* `rncCells`, `rncNotes`, the composed style plane and every cold block entry,
|
|
427
|
+
* composed as `composeCell` does (hot shadows cold; tombstones and orphans
|
|
428
|
+
* skipped). Inflates every cold block once.
|
|
300
429
|
*/
|
|
301
430
|
export const sheetDataV5ToV2 = (doc, styles = readStyleOverlayV5(doc)) => {
|
|
431
|
+
refuseRenderedText(doc);
|
|
302
432
|
const sheetData = {};
|
|
303
433
|
const cache = new Map();
|
|
434
|
+
const cold = new Map();
|
|
304
435
|
const keys = new Set(styles.keys());
|
|
305
436
|
for (const name of [CELLS_V5, NOTES_V5]) {
|
|
306
437
|
if (doc.share.has(name)) {
|
|
@@ -308,10 +439,26 @@ export const sheetDataV5ToV2 = (doc, styles = readStyleOverlayV5(doc)) => {
|
|
|
308
439
|
keys.add(key);
|
|
309
440
|
}
|
|
310
441
|
}
|
|
442
|
+
if (doc.share.has(BLOCKS_V5)) {
|
|
443
|
+
forEachEntry(doc.get(BLOCKS_V5), (value, blockKey) => {
|
|
444
|
+
const parsed = parseBlockKeyV5(blockKey);
|
|
445
|
+
if (!parsed || !(value instanceof Uint8Array))
|
|
446
|
+
return;
|
|
447
|
+
const cells = decodeColumnBlockV5(value);
|
|
448
|
+
cold.set(blockKey, cells);
|
|
449
|
+
const { rows } = sheetLinesV5(doc, cache, parsed.sheetId);
|
|
450
|
+
cells.forEach((_cell, offset) => {
|
|
451
|
+
const rowId = c0Id(parsed.block * BLOCK_ROWS + offset + 1);
|
|
452
|
+
// A row not in the axis is deleted: its block cells are orphans.
|
|
453
|
+
if (rows.has(rowId))
|
|
454
|
+
keys.add(createCellKeyV5(parsed.sheetId, rowId, parsed.colId));
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
}
|
|
311
458
|
for (const key of keys) {
|
|
312
459
|
const parsed = parseCellKeyV5(key);
|
|
313
460
|
const pos = parsed && positionV5(doc, cache, parsed);
|
|
314
|
-
const cell = pos && composeCell(doc, key, styles);
|
|
461
|
+
const cell = pos && composeCell(doc, key, styles, cold);
|
|
315
462
|
if (!parsed || !pos || !cell)
|
|
316
463
|
continue;
|
|
317
464
|
const [rowIdx, colIdx] = pos;
|
|
@@ -332,8 +479,12 @@ export const sheetDataV5ToV2 = (doc, styles = readStyleOverlayV5(doc)) => {
|
|
|
332
479
|
* per sheet. Undefined when nothing is there or the line is unnamed.
|
|
333
480
|
*/
|
|
334
481
|
export const createCellReaderV5 = (doc, styles = readStyleOverlayV5(doc)) => {
|
|
482
|
+
refuseRenderedText(doc);
|
|
335
483
|
const lines = new Map();
|
|
484
|
+
const cold = new Map();
|
|
336
485
|
return (sheetId, rowIndex, columnIndex) => {
|
|
486
|
+
// The marker can arrive with a sync after the reader was made.
|
|
487
|
+
refuseRenderedText(doc);
|
|
337
488
|
let ids = lines.get(sheetId);
|
|
338
489
|
if (!ids) {
|
|
339
490
|
ids = [readLineIds(doc, sheetId, "row"), readLineIds(doc, sheetId, "column")];
|
|
@@ -343,18 +494,21 @@ export const createCellReaderV5 = (doc, styles = readStyleOverlayV5(doc)) => {
|
|
|
343
494
|
const colId = ids[1][columnIndex - 1];
|
|
344
495
|
if (rowId === undefined || colId === undefined)
|
|
345
496
|
return undefined;
|
|
346
|
-
return composeCell(doc, createCellKeyV5(sheetId, rowId, colId), styles) ?? undefined;
|
|
497
|
+
return (composeCell(doc, createCellKeyV5(sheetId, rowId, colId), styles, cold) ?? undefined);
|
|
347
498
|
};
|
|
348
499
|
};
|
|
349
500
|
/** `createCellReaderV5` for one cell (reads both id arrays: O(lines)). */
|
|
350
501
|
export const getCellV5 = (doc, sheetId, rowIndex, columnIndex, styles) => createCellReaderV5(doc, styles)(sheetId, rowIndex, columnIndex);
|
|
351
502
|
/**
|
|
352
503
|
* Apply changed `rncCells` / `rncNotes` keys to `currentSheetData` (copy-on-write,
|
|
353
|
-
* like `processSheetDataEventsV3`), `uf` from `styles
|
|
354
|
-
*
|
|
504
|
+
* like `processSheetDataEventsV3`), `uf` from `styles`; a removed hot entry
|
|
505
|
+
* reveals the cold cell under it. Only valid while no id array, no style and no
|
|
506
|
+
* cold block changed (those need `sheetDataV5ToV2`). Null when nothing changed.
|
|
355
507
|
*/
|
|
356
508
|
export const processSheetDataChangesV5 = (changedKeys, currentSheetData, doc, styles = readStyleOverlayV5(doc)) => {
|
|
509
|
+
refuseRenderedText(doc);
|
|
357
510
|
const cache = new Map();
|
|
511
|
+
const cold = new Map();
|
|
358
512
|
const next = { ...currentSheetData };
|
|
359
513
|
const clonedSheets = new Set();
|
|
360
514
|
const clonedRows = new Set();
|
|
@@ -366,7 +520,7 @@ export const processSheetDataChangesV5 = (changedKeys, currentSheetData, doc, st
|
|
|
366
520
|
continue;
|
|
367
521
|
const [rowIdx, colIdx] = pos;
|
|
368
522
|
const { sheetId } = parsed;
|
|
369
|
-
const cell = composeCell(doc, key, styles);
|
|
523
|
+
const cell = composeCell(doc, key, styles, cold);
|
|
370
524
|
const row = next[sheetId]?.[rowIdx];
|
|
371
525
|
if (!cell && !row?.values?.[colIdx])
|
|
372
526
|
continue;
|
|
@@ -391,6 +545,159 @@ export const processSheetDataChangesV5 = (changedKeys, currentSheetData, doc, st
|
|
|
391
545
|
}
|
|
392
546
|
return hasChanges ? next : null;
|
|
393
547
|
};
|
|
548
|
+
// ── facet anchors (facet_anchor.rs, addr.rs) ────────────────────────────────
|
|
549
|
+
const MAX_ROW = 1048576; // MAX_ROW
|
|
550
|
+
const MAX_COL = 16384; // MAX_COL
|
|
551
|
+
const TAG_RANGE = 1; // TAG_RANGE
|
|
552
|
+
const TAG_CELL = 2; // TAG_CELL
|
|
553
|
+
const TAG_POINT = 3; // TAG_POINT
|
|
554
|
+
const RANGE_KEYS = ["startRowIndex", "endRowIndex", "startColumnIndex", "endColumnIndex"];
|
|
555
|
+
const CELL_KEYS = ["rowIndex", "columnIndex"];
|
|
556
|
+
/** Zigzag LEB128 `i64` (`get_var`). */
|
|
557
|
+
const readVar = (buf, at) => {
|
|
558
|
+
let z = BigInt(0);
|
|
559
|
+
for (let shift = BigInt(0); shift < BigInt(64); shift += BigInt(7)) {
|
|
560
|
+
if (at.pos >= buf.length)
|
|
561
|
+
return null;
|
|
562
|
+
const b = buf[at.pos++];
|
|
563
|
+
z |= BigInt(b & 0x7f) << shift;
|
|
564
|
+
if ((b & 0x80) === 0) {
|
|
565
|
+
return BigInt.asIntN(64, (z >> BigInt(1)) ^ -(z & BigInt(1)));
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
return null;
|
|
569
|
+
};
|
|
570
|
+
/**
|
|
571
|
+
* Decode a facet `anchor` buffer (`decode_anchor`): `u8 n`, the `n` positional
|
|
572
|
+
* fields as written (zigzag varints), then one `Addr` filling the rest.
|
|
573
|
+
*/
|
|
574
|
+
export const decodeFacetAnchorV5 = (buf) => {
|
|
575
|
+
const at = { pos: 0 };
|
|
576
|
+
if (!buf.length)
|
|
577
|
+
return null;
|
|
578
|
+
const n = buf[at.pos++];
|
|
579
|
+
const frame = [];
|
|
580
|
+
for (let i = 0; i < n; i++) {
|
|
581
|
+
const v = readVar(buf, at);
|
|
582
|
+
if (v === null)
|
|
583
|
+
return null;
|
|
584
|
+
frame.push(Number(v));
|
|
585
|
+
}
|
|
586
|
+
if (at.pos >= buf.length)
|
|
587
|
+
return null;
|
|
588
|
+
const tag = buf[at.pos++];
|
|
589
|
+
const sheet = readVar(buf, at);
|
|
590
|
+
if (sheet === null)
|
|
591
|
+
return null;
|
|
592
|
+
const sheetId = Number(sheet);
|
|
593
|
+
const id = () => readVar(buf, at)?.toString() ?? null;
|
|
594
|
+
let addr;
|
|
595
|
+
if (tag === TAG_RANGE) {
|
|
596
|
+
if (at.pos + 2 > buf.length)
|
|
597
|
+
return null;
|
|
598
|
+
at.pos++; // abs
|
|
599
|
+
const bits = buf[at.pos++];
|
|
600
|
+
const corners = [];
|
|
601
|
+
for (let i = 0; i < 4; i++) {
|
|
602
|
+
if (bits & (1 << i)) {
|
|
603
|
+
const c = id();
|
|
604
|
+
if (c === null)
|
|
605
|
+
return null;
|
|
606
|
+
corners.push(c);
|
|
607
|
+
}
|
|
608
|
+
else {
|
|
609
|
+
corners.push(null);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
const [r0, r1, c0, c1] = corners;
|
|
613
|
+
addr = { kind: "range", sheetId, r0, r1, c0, c1 };
|
|
614
|
+
}
|
|
615
|
+
else if (tag === TAG_CELL || tag === TAG_POINT) {
|
|
616
|
+
if (tag === TAG_CELL) {
|
|
617
|
+
if (at.pos >= buf.length)
|
|
618
|
+
return null;
|
|
619
|
+
at.pos++; // abs
|
|
620
|
+
}
|
|
621
|
+
const row = id();
|
|
622
|
+
const col = id();
|
|
623
|
+
if (row === null || col === null)
|
|
624
|
+
return null;
|
|
625
|
+
addr = { kind: tag === TAG_CELL ? "cell" : "point", sheetId, row, col };
|
|
626
|
+
}
|
|
627
|
+
else {
|
|
628
|
+
return null;
|
|
629
|
+
}
|
|
630
|
+
return at.pos === buf.length ? { frame, addr } : null;
|
|
631
|
+
};
|
|
632
|
+
/**
|
|
633
|
+
* Resolve the `anchor` of one anchored map inside a facet value (`site_now`):
|
|
634
|
+
* `site` `"range"` = a map with `startRowIndex`…`endColumnIndex` (a named
|
|
635
|
+
* range, merge, CF / DV range, table, chart range, …), `"cell"` = a one-cell
|
|
636
|
+
* map (`rowIndex` / `columnIndex`) that goes with its lines (data-table input,
|
|
637
|
+
* scenario cells), `"point"` = a floating object's anchor cell. `sheetId` is
|
|
638
|
+
* the sheet the facet lives on.
|
|
639
|
+
*
|
|
640
|
+
* Only live corner lines are resolved here; anything the engine would repair
|
|
641
|
+
* (a deleted line) or fall back on (a line this replica never saw) answers
|
|
642
|
+
* `engine`. Which maps of which facet carry an anchor (and the derived ones:
|
|
643
|
+
* table filter column offsets, print breaks, print titles) is the engine's
|
|
644
|
+
* walk (`facet_anchor.rs`); for those, and whenever the exact answer matters,
|
|
645
|
+
* read facets through the engine.
|
|
646
|
+
*/
|
|
647
|
+
export const resolveFacetAnchorV5 = (doc, sheetId, value, site) => {
|
|
648
|
+
const positional = { status: "positional" };
|
|
649
|
+
const buf = value.anchor;
|
|
650
|
+
if (!(buf instanceof Uint8Array))
|
|
651
|
+
return positional;
|
|
652
|
+
const decoded = decodeFacetAnchorV5(buf);
|
|
653
|
+
if (!decoded)
|
|
654
|
+
return positional;
|
|
655
|
+
const { frame, addr } = decoded;
|
|
656
|
+
const keys = site === "range" ? RANGE_KEYS : CELL_KEYS;
|
|
657
|
+
const stored = keys.map((k) => value[k]);
|
|
658
|
+
if (stored.length !== frame.length ||
|
|
659
|
+
stored.some((v, i) => typeof v !== "number" || v !== frame[i])) {
|
|
660
|
+
return positional;
|
|
661
|
+
}
|
|
662
|
+
// A value copied onto another sheet with its anchors names the source's lines.
|
|
663
|
+
if (addr.sheetId !== sheetId)
|
|
664
|
+
return positional;
|
|
665
|
+
const lines = sheetLinesV5(doc, new Map(), sheetId);
|
|
666
|
+
if (site === "point") {
|
|
667
|
+
if (addr.kind !== "point")
|
|
668
|
+
return positional;
|
|
669
|
+
const row = lines.rows.get(addr.row);
|
|
670
|
+
const col = lines.cols.get(addr.col);
|
|
671
|
+
if (row === undefined || col === undefined)
|
|
672
|
+
return { status: "engine" };
|
|
673
|
+
return { status: "resolved", fields: { rowIndex: row, columnIndex: col } };
|
|
674
|
+
}
|
|
675
|
+
if (addr.kind !== "range")
|
|
676
|
+
return positional;
|
|
677
|
+
const axis = (index, c0, c1, max) => {
|
|
678
|
+
const s = c0 === null ? 1 : index.get(c0);
|
|
679
|
+
const e = c1 === null ? max : index.get(c1);
|
|
680
|
+
if (s === undefined || e === undefined)
|
|
681
|
+
return null;
|
|
682
|
+
// Both lines live in the other order (a move): the box of both.
|
|
683
|
+
return s <= e ? [s, e] : [e, s];
|
|
684
|
+
};
|
|
685
|
+
const rows = axis(lines.rows, addr.r0, addr.r1, MAX_ROW);
|
|
686
|
+
const cols = axis(lines.cols, addr.c0, addr.c1, MAX_COL);
|
|
687
|
+
if (!rows || !cols)
|
|
688
|
+
return { status: "engine" };
|
|
689
|
+
if (site === "cell") {
|
|
690
|
+
return { status: "resolved", fields: { rowIndex: rows[0], columnIndex: cols[0] } };
|
|
691
|
+
}
|
|
692
|
+
const now = [rows[0], rows[1], cols[0], cols[1]];
|
|
693
|
+
const open = [addr.r0, addr.r1, addr.c0, addr.c1].map((c) => c === null);
|
|
694
|
+
const fields = {};
|
|
695
|
+
RANGE_KEYS.forEach((k, i) => {
|
|
696
|
+
if (!open[i])
|
|
697
|
+
fields[k] = now[i];
|
|
698
|
+
});
|
|
699
|
+
return { status: "resolved", fields };
|
|
700
|
+
};
|
|
394
701
|
const axisKey = (sheetId, isRow) => `${sheetId}:${isRow ? "R" : "C"}`;
|
|
395
702
|
const writerStyles = (w) => (w.styles ??= readStyleOverlayV5(w.doc));
|
|
396
703
|
const writerAxis = (w, sheetId, isRow) => {
|
|
@@ -502,7 +809,8 @@ const queueStyle = (w, sheetId, rowId, colId, format) => {
|
|
|
502
809
|
* composed plane's entry, else the inline `uf`) is logged as a replace (a
|
|
503
810
|
* clear, then the format; a style reference only clears: the engine cannot
|
|
504
811
|
* resolve it). A note lives in `rncNotes` when the key has an entry there,
|
|
505
|
-
* inline otherwise. An unchanged cell
|
|
812
|
+
* inline otherwise. An unchanged cell (hot, or cold with no hot entry) is not
|
|
813
|
+
* rewritten (its `ft` survives; a cold cell gets no hot copy).
|
|
506
814
|
*/
|
|
507
815
|
const writeCell = (w, sheetId, row, col, cell) => {
|
|
508
816
|
if (!validPosition(row, col))
|
|
@@ -510,7 +818,7 @@ const writeCell = (w, sheetId, row, col, cell) => {
|
|
|
510
818
|
const rowId = ensureLine(w, sheetId, true, row);
|
|
511
819
|
const colId = ensureLine(w, sheetId, false, col);
|
|
512
820
|
const key = createCellKeyV5(sheetId, rowId, colId);
|
|
513
|
-
const stored =
|
|
821
|
+
const stored = storedCellV5(w.doc, key, w.cold);
|
|
514
822
|
const format = normalizedFormat(getCellUserEnteredFormat(cell));
|
|
515
823
|
const storedFormat = normalizedFormat(writerStyles(w).get(key) ?? getCellUserEnteredFormat(stored));
|
|
516
824
|
if (!isEqual(format, storedFormat)) {
|
|
@@ -614,6 +922,7 @@ const clearSheets = (w, match) => {
|
|
|
614
922
|
drop(BLOCKS_V5);
|
|
615
923
|
drop(NOTES_V5);
|
|
616
924
|
drop(STYLES_SEED_V5);
|
|
925
|
+
w.cold.clear();
|
|
617
926
|
for (const key of Array.from(writerStyles(w).keys())) {
|
|
618
927
|
const parsed = parseCellKeyV5(key);
|
|
619
928
|
if (parsed && match(parsed.sheetId)) {
|
|
@@ -622,17 +931,14 @@ const clearSheets = (w, match) => {
|
|
|
622
931
|
}
|
|
623
932
|
w.offsets.clear();
|
|
624
933
|
};
|
|
625
|
-
/** The cell a nested patch edits: the stored cell as the readers show it. */
|
|
934
|
+
/** The cell a nested patch edits: the stored cell (hot, else cold) as the readers show it. */
|
|
626
935
|
const nestedBase = (w, sheetId, row, col) => {
|
|
627
936
|
const rowId = writerAxis(w, sheetId, true).ids[row - 1];
|
|
628
937
|
const colId = writerAxis(w, sheetId, false).ids[col - 1];
|
|
629
938
|
if (rowId === undefined || colId === undefined)
|
|
630
939
|
return {};
|
|
631
940
|
const key = createCellKeyV5(sheetId, rowId, colId);
|
|
632
|
-
|
|
633
|
-
return null;
|
|
634
|
-
}
|
|
635
|
-
return composeCell(w.doc, key, writerStyles(w)) ?? {};
|
|
941
|
+
return composeCell(w.doc, key, writerStyles(w), w.cold) ?? {};
|
|
636
942
|
};
|
|
637
943
|
const applyPatchV5 = (w, { op, path, value }) => {
|
|
638
944
|
if (path.length === 0) {
|
|
@@ -652,11 +958,6 @@ const applyPatchV5 = (w, { op, path, value }) => {
|
|
|
652
958
|
if (!validPosition(row, col))
|
|
653
959
|
return;
|
|
654
960
|
const base = nestedBase(w, sheetId, row, col);
|
|
655
|
-
if (base === null) {
|
|
656
|
-
// Cold-only cell: its body needs an async inflate, a sync writer cannot merge into it.
|
|
657
|
-
console.warn(`y-spreadsheet v5: nested patch on cold cell ${sheetId}!R${row}C${col} skipped`);
|
|
658
|
-
return;
|
|
659
|
-
}
|
|
660
961
|
const cell = cloneDeep(base);
|
|
661
962
|
const nested = path.slice(4);
|
|
662
963
|
if (op === "remove") {
|
|
@@ -695,6 +996,7 @@ const applyPatchV5 = (w, { op, path, value }) => {
|
|
|
695
996
|
export const addSheetDataPatchesV5 = (doc, patches, origin = null, styles) => {
|
|
696
997
|
if (!patches?.length)
|
|
697
998
|
return;
|
|
999
|
+
refuseRenderedText(doc);
|
|
698
1000
|
doc.transact(() => {
|
|
699
1001
|
const w = {
|
|
700
1002
|
doc,
|
|
@@ -704,6 +1006,7 @@ export const addSheetDataPatchesV5 = (doc, patches, origin = null, styles) => {
|
|
|
704
1006
|
styles: styles ?? null,
|
|
705
1007
|
ops: [],
|
|
706
1008
|
offsets: new Map(),
|
|
1009
|
+
cold: new Map(),
|
|
707
1010
|
};
|
|
708
1011
|
// Consecutive cell patches are consolidated (the later one wins) but never
|
|
709
1012
|
// reordered across a row-, sheet- or document-level patch (v3 parity).
|