@rowsncolumns/y-spreadsheet 17.1.1 → 17.1.3
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 +60 -0
- package/dist/cjs/helpers-v5.d.ts.map +1 -1
- package/dist/cjs/helpers-v5.js +160 -8
- package/dist/cjs/helpers.d.ts +23 -0
- package/dist/cjs/helpers.d.ts.map +1 -1
- package/dist/cjs/helpers.js +140 -58
- package/dist/cjs/use-yspreadsheet-v2.d.ts +2 -0
- package/dist/cjs/use-yspreadsheet-v2.d.ts.map +1 -1
- package/dist/cjs/use-yspreadsheet-v2.js +34 -6
- package/dist/cjs/use-yspreadsheet.d.ts +2 -0
- package/dist/cjs/use-yspreadsheet.d.ts.map +1 -1
- package/dist/cjs/use-yspreadsheet.js +24 -3
- package/dist/esm/helpers-v5.d.ts +60 -0
- package/dist/esm/helpers-v5.d.ts.map +1 -1
- package/dist/esm/helpers-v5.js +141 -7
- package/dist/esm/helpers.d.ts +23 -0
- package/dist/esm/helpers.d.ts.map +1 -1
- package/dist/esm/helpers.js +94 -4
- package/dist/esm/use-yspreadsheet-v2.d.ts +2 -0
- package/dist/esm/use-yspreadsheet-v2.d.ts.map +1 -1
- package/dist/esm/use-yspreadsheet-v2.js +35 -7
- package/dist/esm/use-yspreadsheet.d.ts +2 -0
- package/dist/esm/use-yspreadsheet.d.ts.map +1 -1
- package/dist/esm/use-yspreadsheet.js +24 -3
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,KAAK,EACX,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,gBAAgB,EACtB,MAAM,iCAAiC,CAAC;AAWzC,OAAO,KAAK,E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C,EACjE,kBAAkB,SAAS,CAAC,CAAC,CAAC,EAC9B,cAAc,YAAY,KACzB,SAAS,CAAC,CAAC,CAAC,GAAG,IA6EjB,CAAC"}
|
package/dist/esm/helpers.js
CHANGED
|
@@ -6,7 +6,7 @@ import get from "lodash/get";
|
|
|
6
6
|
import unset from "lodash/unset";
|
|
7
7
|
import { resolveYjsRuntime } from "./yjs-runtime";
|
|
8
8
|
import { arrayJson, hasEntries, listDelete, listInsert, nodeJson, } from "./ynodes";
|
|
9
|
-
import { addSheetDataPatchesV5 } from "./helpers-v5";
|
|
9
|
+
import { addSheetDataPatchesV5, refuseEngineOwnedFormat, refusePositionalWrite, } from "./helpers-v5";
|
|
10
10
|
export * from "./helpers-v5";
|
|
11
11
|
/**
|
|
12
12
|
* Apply patches to yjs
|
|
@@ -15,8 +15,17 @@ export * from "./helpers-v5";
|
|
|
15
15
|
* @param patches
|
|
16
16
|
* @param source
|
|
17
17
|
* @param sheetDataVersion - Version of sheet data format ("v2", "v3" or "v5"). Falls back to docMeta if undefined.
|
|
18
|
+
* @throws FinalFormatError on a doc stamped final (`docIsFinalFormat`), whatever `sheetDataVersion` says: nothing is written.
|
|
18
19
|
*/
|
|
19
20
|
export const applyPatchesToYDoc = (doc, userId, patches, source, sheetDataVersion, yjsRuntime) => {
|
|
21
|
+
// A final doc is the engine's: read here it is an empty positional sheet, and
|
|
22
|
+
// a cell written here is one no engine reads. So is a doc stamped with a
|
|
23
|
+
// format this package does not know; and a positional doc past
|
|
24
|
+
// `sheet-format.cells = 2` takes no cell this function writes.
|
|
25
|
+
if (sheetDataVersion === "v5")
|
|
26
|
+
refuseEngineOwnedFormat(doc);
|
|
27
|
+
else
|
|
28
|
+
refusePositionalWrite(doc);
|
|
20
29
|
const yjs = resolveYjsRuntime(yjsRuntime);
|
|
21
30
|
// Maps: sheetDataV2, sheetDataV3, docMeta, sharedStringsMap, cellXfs,
|
|
22
31
|
// disableRecalc. Arrays: everything else.
|
|
@@ -152,9 +161,7 @@ export const addSheetDataPatches = (ySheetData, patches, yjsRuntime) => {
|
|
|
152
161
|
const ysheet = getSheetFromYSheetData(ySheetData, sheetIdStr, yjs);
|
|
153
162
|
for (const [rowIdx, colUpdates] of rowUpdates) {
|
|
154
163
|
const rowData = getRowDataFromSheet(ysheet, rowIdx, yjs);
|
|
155
|
-
|
|
156
|
-
setCellDataInRowData(rowData, colIdx, value);
|
|
157
|
-
}
|
|
164
|
+
setCellRunsInRowData(rowData, colUpdates);
|
|
158
165
|
}
|
|
159
166
|
}
|
|
160
167
|
pendingCellUpdates.clear();
|
|
@@ -290,6 +297,7 @@ export const getSheetFromYSheetData = (ySheetData, sheetId, yjsRuntime) => {
|
|
|
290
297
|
return sheet;
|
|
291
298
|
};
|
|
292
299
|
export const deleteSheetFromYSheetData = (ySheetData, sheetId) => {
|
|
300
|
+
refuseEngineOwnedType(ySheetData);
|
|
293
301
|
const id = String(sheetId);
|
|
294
302
|
ySheetData.deleteAttr(id);
|
|
295
303
|
};
|
|
@@ -350,6 +358,38 @@ export const setCellDataInRowData = (rowData, columnIndex, cellData = null) => {
|
|
|
350
358
|
rowData.delete(index + 1, 1);
|
|
351
359
|
}
|
|
352
360
|
};
|
|
361
|
+
/**
|
|
362
|
+
* Writes several cells of one row: each run of consecutive column indices is
|
|
363
|
+
* one range delete and one insert, instead of an insert and a delete per cell.
|
|
364
|
+
*
|
|
365
|
+
* A row's cells are usually one Y.js item (a paste writes them together).
|
|
366
|
+
* Replacing a cell inside an item splits it, and every split is a splice into
|
|
367
|
+
* the client's list of structs, which grows with the document. A column insert
|
|
368
|
+
* rewrites every cell right of the new column in every row, so per-cell
|
|
369
|
+
* replaces cost (rows × shifted cells) splices into a list proportional to the
|
|
370
|
+
* sheet: quadratic, 4.8 s for 8,000 rows × 10 columns in V8. A run splits the
|
|
371
|
+
* row's item once.
|
|
372
|
+
*
|
|
373
|
+
* The row ends with the same content as `setCellDataInRowData` for each cell.
|
|
374
|
+
*/
|
|
375
|
+
export const setCellRunsInRowData = (rowData, cells) => {
|
|
376
|
+
const columns = Array.from(cells.keys()).sort((a, b) => a - b);
|
|
377
|
+
let i = 0;
|
|
378
|
+
while (i < columns.length) {
|
|
379
|
+
const start = columns[i];
|
|
380
|
+
const values = [cells.get(start) ?? null];
|
|
381
|
+
while (i + 1 < columns.length && columns[i + 1] === columns[i] + 1) {
|
|
382
|
+
i++;
|
|
383
|
+
values.push(cells.get(columns[i]) ?? null);
|
|
384
|
+
}
|
|
385
|
+
i++;
|
|
386
|
+
if (start > rowData.length) {
|
|
387
|
+
listInsert(rowData, rowData.length, new Array(start - rowData.length).fill(null));
|
|
388
|
+
}
|
|
389
|
+
listDelete(rowData, start, Math.min(values.length, rowData.length - start));
|
|
390
|
+
listInsert(rowData, start, values);
|
|
391
|
+
}
|
|
392
|
+
};
|
|
353
393
|
export const removeRowData = (ysheet, rowIndex) => {
|
|
354
394
|
const index = Number(rowIndex);
|
|
355
395
|
// Only remove if index is valid
|
|
@@ -499,6 +539,7 @@ export const mergeErrorEffectiveValueIntoCellData = (currentCellData, incomingCe
|
|
|
499
539
|
* Update array type with immer patches
|
|
500
540
|
*/
|
|
501
541
|
export const updateArrayType = (yarray, patches) => {
|
|
542
|
+
refuseEngineOwnedType(yarray);
|
|
502
543
|
// Consecutive nested-path patches targeting the same array item are
|
|
503
544
|
// consolidated into one cloneDeep + one Y.Array write. An immer splice on
|
|
504
545
|
// a nested array (e.g. a sheet's rowMetadata on row insert/delete) emits
|
|
@@ -655,6 +696,7 @@ export const validateSheets = (sheets) => {
|
|
|
655
696
|
* Map operations
|
|
656
697
|
*/
|
|
657
698
|
export const applyMapPatches = (yMap, patches) => {
|
|
699
|
+
refuseEngineOwnedType(yMap);
|
|
658
700
|
for (const { op, path, value } of patches) {
|
|
659
701
|
if (!path || !path.length) {
|
|
660
702
|
if (op === "remove") {
|
|
@@ -856,6 +898,41 @@ export const processSheetDataEvents = (events, currentSheetData, ySheetDataV2, y
|
|
|
856
898
|
// ============================================================================
|
|
857
899
|
// V3 Helper Functions (Flat Map Structure)
|
|
858
900
|
// ============================================================================
|
|
901
|
+
// A doc stamped final (`docIsFinalFormat`) keeps no cell in `sheetDataV3`: read
|
|
902
|
+
// here it is an empty sheet, and a cell written here is one no engine reads.
|
|
903
|
+
// Every function below that is handed the map refuses such a doc
|
|
904
|
+
// (`FinalFormatError`) before it reads or writes.
|
|
905
|
+
/**
|
|
906
|
+
* Throws `FinalFormatError` when the map is in a doc stamped final. The doc is
|
|
907
|
+
* reached through the map (a root, or a node inserted into a doc, names it); a
|
|
908
|
+
* map in no doc holds nothing to refuse.
|
|
909
|
+
*/
|
|
910
|
+
const refuseFinalFormatV3 = (ySheetDataV3) => {
|
|
911
|
+
const doc = ySheetDataV3.doc;
|
|
912
|
+
if (doc)
|
|
913
|
+
refuseEngineOwnedFormat(doc);
|
|
914
|
+
};
|
|
915
|
+
/**
|
|
916
|
+
* `refuseFinalFormatV3` for a writer of the positional plane: it also refuses
|
|
917
|
+
* a doc stamped with a format this package does not know and one whose
|
|
918
|
+
* `sheet-format.cells` is past 2 (`refusePositionalWrite`).
|
|
919
|
+
*/
|
|
920
|
+
const refuseWriteV3 = (ySheetDataV3) => {
|
|
921
|
+
const doc = ySheetDataV3.doc;
|
|
922
|
+
if (doc)
|
|
923
|
+
refusePositionalWrite(doc);
|
|
924
|
+
};
|
|
925
|
+
/**
|
|
926
|
+
* For the generic writers handed a shared type of any root (`updateArrayType`,
|
|
927
|
+
* `applyMapPatches`, `deleteSheetFromYSheetData`): a type in a doc only the
|
|
928
|
+
* engine writes (stamped final, or with a format this package does not know)
|
|
929
|
+
* is refused. A type in no doc holds nothing to refuse.
|
|
930
|
+
*/
|
|
931
|
+
const refuseEngineOwnedType = (type) => {
|
|
932
|
+
const doc = type.doc;
|
|
933
|
+
if (doc)
|
|
934
|
+
refuseEngineOwnedFormat(doc);
|
|
935
|
+
};
|
|
859
936
|
/**
|
|
860
937
|
* Convert letter to column index (1-based)
|
|
861
938
|
* A = 1, B = 2, ..., Z = 26, AA = 27, etc.
|
|
@@ -929,6 +1006,7 @@ export const sheetDataV2ToV3 = (v2Data) => {
|
|
|
929
1006
|
* Convert V3 flat Map format to V2 SheetData
|
|
930
1007
|
* V3: Map<cellKey, CellDataV3>
|
|
931
1008
|
* V2: { sheetId: [rows with values arrays] }
|
|
1009
|
+
* Handed plain data, it cannot tell a doc stamped final: its caller checks `docIsFinalFormat` first.
|
|
932
1010
|
*/
|
|
933
1011
|
export const sheetDataV3ToV2 = (v3Data) => {
|
|
934
1012
|
const sheetData = {};
|
|
@@ -960,29 +1038,37 @@ export const sheetDataV3ToV2 = (v3Data) => {
|
|
|
960
1038
|
};
|
|
961
1039
|
/**
|
|
962
1040
|
* Get a cell from V3 flat structure
|
|
1041
|
+
* @throws FinalFormatError on a doc stamped final (`docIsFinalFormat`).
|
|
963
1042
|
*/
|
|
964
1043
|
export const getCellV3 = (ySheetDataV3, sheetId, rowIndex, columnIndex) => {
|
|
1044
|
+
refuseFinalFormatV3(ySheetDataV3);
|
|
965
1045
|
const key = createCellKeyV3(sheetId, rowIndex, columnIndex);
|
|
966
1046
|
return ySheetDataV3.getAttr(key);
|
|
967
1047
|
};
|
|
968
1048
|
/**
|
|
969
1049
|
* Set a cell in V3 flat structure
|
|
1050
|
+
* @throws FinalFormatError on a doc stamped final (`docIsFinalFormat`): nothing is written.
|
|
970
1051
|
*/
|
|
971
1052
|
export const setCellV3 = (ySheetDataV3, sheetId, rowIndex, columnIndex, value) => {
|
|
1053
|
+
refuseWriteV3(ySheetDataV3);
|
|
972
1054
|
const key = createCellKeyV3(sheetId, rowIndex, columnIndex);
|
|
973
1055
|
ySheetDataV3.setAttr(key, createCellDataV3(value, sheetId, rowIndex, columnIndex));
|
|
974
1056
|
};
|
|
975
1057
|
/**
|
|
976
1058
|
* Delete a cell from V3 flat structure
|
|
1059
|
+
* @throws FinalFormatError on a doc stamped final (`docIsFinalFormat`): nothing is written.
|
|
977
1060
|
*/
|
|
978
1061
|
export const deleteCellV3 = (ySheetDataV3, sheetId, rowIndex, columnIndex) => {
|
|
1062
|
+
refuseWriteV3(ySheetDataV3);
|
|
979
1063
|
const key = createCellKeyV3(sheetId, rowIndex, columnIndex);
|
|
980
1064
|
ySheetDataV3.deleteAttr(key);
|
|
981
1065
|
};
|
|
982
1066
|
/**
|
|
983
1067
|
* Delete all cells for a sheet from V3 flat structure
|
|
1068
|
+
* @throws FinalFormatError on a doc stamped final (`docIsFinalFormat`): nothing is written.
|
|
984
1069
|
*/
|
|
985
1070
|
export const deleteSheetV3 = (ySheetDataV3, sheetId) => {
|
|
1071
|
+
refuseWriteV3(ySheetDataV3);
|
|
986
1072
|
const prefix = `${sheetId}!`;
|
|
987
1073
|
for (const key of ySheetDataV3.attrKeys()) {
|
|
988
1074
|
if (key.startsWith(prefix)) {
|
|
@@ -1003,8 +1089,10 @@ export const getSheetDataV3 = (doc) => {
|
|
|
1003
1089
|
* patches before applying to Y.js. This reduces overhead by:
|
|
1004
1090
|
* 1. Deduplicating patches targeting the same cell (later patches win)
|
|
1005
1091
|
* 2. Processing all cell updates in a single pass
|
|
1092
|
+
* @throws FinalFormatError on a doc stamped final (`docIsFinalFormat`): nothing is written.
|
|
1006
1093
|
*/
|
|
1007
1094
|
export const addSheetDataPatchesV3 = (ySheetDataV3, patches) => {
|
|
1095
|
+
refuseWriteV3(ySheetDataV3);
|
|
1008
1096
|
// Row-targeted patches (e.g. the per-shifted-row patches an immer array
|
|
1009
1097
|
// splice emits for a row insert/delete) previously scanned the entire flat
|
|
1010
1098
|
// cell map once per patch — O(patches × totalCells), which freezes the tab
|
|
@@ -1266,8 +1354,10 @@ export const addSheetDataPatchesV3 = (ySheetDataV3, patches) => {
|
|
|
1266
1354
|
* @param changedKeys - Pre-extracted changes from Yjs event
|
|
1267
1355
|
* @param currentSheetData - Current sheet data state
|
|
1268
1356
|
* @param ySheetDataV3 - The map node for V3 data
|
|
1357
|
+
* @throws FinalFormatError on a doc stamped final (`docIsFinalFormat`).
|
|
1269
1358
|
*/
|
|
1270
1359
|
export const processSheetDataEventsV3 = (changedKeys, currentSheetData, ySheetDataV3) => {
|
|
1360
|
+
refuseFinalFormatV3(ySheetDataV3);
|
|
1271
1361
|
if (changedKeys.size === 0)
|
|
1272
1362
|
return null;
|
|
1273
1363
|
const next = { ...currentSheetData };
|
|
@@ -78,6 +78,8 @@ export type UseYSpreadsheetPropsV2<T extends CellData, S extends Sheet, C extend
|
|
|
78
78
|
* This should be provided by the backend/server
|
|
79
79
|
* "v5" (also when `docMeta.sheetDataVersion` says so): stable line ids, read
|
|
80
80
|
* from `rncCells` and the cold `rncColumnBlocks`, written to `rncCells` (see `helpers-v5.ts`)
|
|
81
|
+
* A doc stamped final (`docMeta.sheetDataVersion` "v6", `docIsFinalFormat`) is
|
|
82
|
+
* refused whatever this says (`FinalFormatError`): open it through the engine.
|
|
81
83
|
*/
|
|
82
84
|
sheetDataVersion?: "v2" | "v3" | "v5";
|
|
83
85
|
/**
|
|
@@ -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,WA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ACtC,EAAE;;;CAgUR,CAAC"}
|
|
@@ -3,7 +3,7 @@ import { getCellUserEnteredValue, getExtendedValueFormula, isAFormula, isNil, so
|
|
|
3
3
|
import { useIsomorphicLayoutEffect } from "@rowsncolumns/ui";
|
|
4
4
|
import { useCallback, useMemo, useRef, useState } from "react";
|
|
5
5
|
import { flushSync } from "react-dom";
|
|
6
|
-
import { addSheetDataPatches, addSheetDataPatchesV5, addSheetDataPatchesV3, applyMapPatches, createCellReaderV5, createCellKeyV3, filterErrorCellPatches, getCellDataFromYSheetData, mergeErrorEffectiveValueIntoCellData, processSheetDataEvents, shouldPersistErrorCellPatch, processSheetDataEventsV3, processSheetDataChangesV5, readStyleOverlayV5, sheetDataV2ToV3, sheetDataV3ToV2, sheetDataV5ToV2, updateArrayType, validateSheets, } from "./helpers";
|
|
6
|
+
import { addSheetDataPatches, addSheetDataPatchesV5, addSheetDataPatchesV3, applyMapPatches, createCellReaderV5, createCellKeyV3, refuseEngineOwnedFormat, filterErrorCellPatches, sheetDataFormatOf, getCellDataFromYSheetData, mergeErrorEffectiveValueIntoCellData, processSheetDataEvents, shouldPersistErrorCellPatch, processSheetDataEventsV3, processSheetDataChangesV5, readStyleOverlayV5, sheetDataV2ToV3, sheetDataV3ToV2, sheetDataV5ToV2, updateArrayType, validateSheets, } from "./helpers";
|
|
7
7
|
import { resolveYjsRuntime } from "./yjs-runtime";
|
|
8
8
|
import { arrayJson, changedKeys as changedKeysOf, childDelta, listDelete, mapJson, } from "./ynodes";
|
|
9
9
|
/**
|
|
@@ -103,6 +103,17 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
|
|
|
103
103
|
const yDocMeta = useMemo(() => doc.get("docMeta"), [doc]);
|
|
104
104
|
// V5: the engine marks the doc in `docMeta`; read live (the marker may arrive with a sync)
|
|
105
105
|
const isV5Doc = useCallback(() => sheetDataVersion === "v5" || yDocMeta.getAttr("sheetDataVersion") === "v5", [sheetDataVersion, yDocMeta]);
|
|
106
|
+
// Final format (`docMeta.sheetDataVersion = "v6"`): the engine's. This hook
|
|
107
|
+
// would read it as an empty positional sheet, so its load and its writes
|
|
108
|
+
// refuse it (`FinalFormatError`) and its observers leave the state as it is.
|
|
109
|
+
// Read live: the stamp may arrive with a sync. A host checks
|
|
110
|
+
// `docIsFinalFormat` and opens such a doc through the engine instead.
|
|
111
|
+
// A doc stamped with a format this package does not know is refused the same
|
|
112
|
+
// way (`UnknownFormatError`): the engine alone decides what such a doc holds.
|
|
113
|
+
const isFinalDoc = useCallback(() => {
|
|
114
|
+
const format = sheetDataFormatOf(doc);
|
|
115
|
+
return format === "v6" || format === "unknown";
|
|
116
|
+
}, [doc]);
|
|
106
117
|
// V5: the composed style plane, folded on a full read and on a remote style
|
|
107
118
|
// change, updated in place by this hook's own writes
|
|
108
119
|
const stylesV5Ref = useRef(null);
|
|
@@ -238,6 +249,8 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
|
|
|
238
249
|
const initialSyncTimerRef = useRef(null);
|
|
239
250
|
// Trigger cell recalcs
|
|
240
251
|
const syncRecalcCells = useCallback((recalcCells, origin) => {
|
|
252
|
+
if (isFinalDoc())
|
|
253
|
+
return;
|
|
241
254
|
const readV5 = isV5Doc() ? createCellReaderV5(doc, stylesV5()) : null;
|
|
242
255
|
for (const [_, position, source] of recalcCells) {
|
|
243
256
|
// backend will calculate results
|
|
@@ -306,11 +319,14 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
|
|
|
306
319
|
useV3,
|
|
307
320
|
reevaluateDerivationsForCells,
|
|
308
321
|
isV5Doc,
|
|
322
|
+
isFinalDoc,
|
|
309
323
|
doc,
|
|
310
324
|
stylesV5,
|
|
311
325
|
]);
|
|
312
326
|
// Setup initial sync
|
|
313
327
|
const setupInitialSync = useCallback(() => {
|
|
328
|
+
// Before the migrations below write anything.
|
|
329
|
+
refuseEngineOwnedFormat(doc);
|
|
314
330
|
// Migration from sharedStrings (Array) to sharedStringsMap (Map) is disabled.
|
|
315
331
|
// Both formats are now supported simultaneously via handleSharedStringsMapChange
|
|
316
332
|
// and handleSharedStringsArrayChange callbacks.
|
|
@@ -416,6 +432,7 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
|
|
|
416
432
|
onMigrationComplete,
|
|
417
433
|
deleteV2AfterMigration,
|
|
418
434
|
isV5Doc,
|
|
435
|
+
isFinalDoc,
|
|
419
436
|
readSheetDataV5,
|
|
420
437
|
yjs,
|
|
421
438
|
]);
|
|
@@ -427,6 +444,8 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
|
|
|
427
444
|
* the backlog at all.
|
|
428
445
|
*/
|
|
429
446
|
const drainBacklog = useCallback(() => {
|
|
447
|
+
if (isFinalDoc())
|
|
448
|
+
return;
|
|
430
449
|
const backlog = getBacklog();
|
|
431
450
|
if (!backlog.length)
|
|
432
451
|
return;
|
|
@@ -436,7 +455,7 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
|
|
|
436
455
|
listDelete(yRecalcCells, 0, yRecalcCells.length);
|
|
437
456
|
}, origin);
|
|
438
457
|
}
|
|
439
|
-
}, [getBacklog, syncRecalcCells, doc, yRecalcCells]);
|
|
458
|
+
}, [getBacklog, syncRecalcCells, doc, yRecalcCells, isFinalDoc]);
|
|
440
459
|
// Synced
|
|
441
460
|
const onSynced = useCallback(() => {
|
|
442
461
|
if (!synced) {
|
|
@@ -503,7 +522,7 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
|
|
|
503
522
|
* This is to prevent yjs from observing sheetdata
|
|
504
523
|
* and updating it, which is not necessary
|
|
505
524
|
*/
|
|
506
|
-
if (events.length) {
|
|
525
|
+
if (events.length && !isFinalDoc()) {
|
|
507
526
|
const origin = events?.[0]?.event.transaction?.origin;
|
|
508
527
|
if (origin !== "local" || observesLocal()) {
|
|
509
528
|
// Convert Y.js events to SheetDataEvent format and apply incremental updates
|
|
@@ -519,13 +538,16 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
|
|
|
519
538
|
return () => {
|
|
520
539
|
subscription.unsubscribe();
|
|
521
540
|
};
|
|
522
|
-
}, [onChangeSheetData, ySheetDataV2, useV3, yjs, observesLocal]);
|
|
541
|
+
}, [onChangeSheetData, ySheetDataV2, useV3, yjs, observesLocal, isFinalDoc]);
|
|
523
542
|
// Only for sheet Data (V3 mode)
|
|
524
543
|
useIsomorphicLayoutEffect(() => {
|
|
525
544
|
if (!useV3)
|
|
526
545
|
return; // Skip V3 observer in V2 mode
|
|
527
546
|
// Subscribe to V3 sheet data (flat Map)
|
|
528
547
|
const callback = (event) => {
|
|
548
|
+
// The transaction that stamps a doc final empties `sheetDataV3`.
|
|
549
|
+
if (isFinalDoc())
|
|
550
|
+
return;
|
|
529
551
|
if (event.transaction.origin !== "local" ||
|
|
530
552
|
observesLocal()) {
|
|
531
553
|
// Extract changes synchronously - they are read from the document as
|
|
@@ -533,6 +555,9 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
|
|
|
533
555
|
const changedKeys = changedKeysOf(event);
|
|
534
556
|
// Now we can safely use the extracted data in the async setState callback
|
|
535
557
|
onChangeSheetData((prevSheetData) => {
|
|
558
|
+
// The stamp may have arrived between the event and this update.
|
|
559
|
+
if (isFinalDoc())
|
|
560
|
+
return prevSheetData;
|
|
536
561
|
const result = processSheetDataEventsV3(changedKeys, prevSheetData, ySheetDataV3);
|
|
537
562
|
if (result) {
|
|
538
563
|
return result;
|
|
@@ -548,7 +573,7 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
|
|
|
548
573
|
return () => {
|
|
549
574
|
ySheetDataV3.unobserve(callback);
|
|
550
575
|
};
|
|
551
|
-
}, [onChangeSheetData, ySheetDataV3, useV3, yjs, observesLocal]);
|
|
576
|
+
}, [onChangeSheetData, ySheetDataV3, useV3, yjs, observesLocal, isFinalDoc]);
|
|
552
577
|
// Only for sheet Data (V5 docs): `rncCells`, `rncNotes`, the style planes,
|
|
553
578
|
// the cold blocks and every sheet's id arrays. A change of an id array, a
|
|
554
579
|
// style plane, a cold block (or of `docMeta`): full re-read; a cell or note change alone is applied
|
|
@@ -557,7 +582,8 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
|
|
|
557
582
|
useIsomorphicLayoutEffect(() => {
|
|
558
583
|
const callback = (transaction) => {
|
|
559
584
|
if ((transaction.origin === "local" && !observesLocal()) ||
|
|
560
|
-
!isV5Doc()
|
|
585
|
+
!isV5Doc() ||
|
|
586
|
+
isFinalDoc())
|
|
561
587
|
return;
|
|
562
588
|
let full = false;
|
|
563
589
|
const cellKeys = [];
|
|
@@ -588,7 +614,7 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
|
|
|
588
614
|
return () => {
|
|
589
615
|
doc.off("afterTransaction", callback);
|
|
590
616
|
};
|
|
591
|
-
}, [doc, onChangeSheetData, isV5Doc, readSheetDataV5, stylesV5, observesLocal]);
|
|
617
|
+
}, [doc, onChangeSheetData, isV5Doc, isFinalDoc, readSheetDataV5, stylesV5, observesLocal]);
|
|
592
618
|
// CellXfs
|
|
593
619
|
useIsomorphicLayoutEffect(() => {
|
|
594
620
|
// Subscribe to sheet data
|
|
@@ -678,6 +704,7 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
|
|
|
678
704
|
}, [syncRecalcCells, recalcCellsMaxEntries, synced, yRecalcCells, observesLocal]);
|
|
679
705
|
// Broadcast patch
|
|
680
706
|
const onBroadcastPatch = useCallback((patches) => {
|
|
707
|
+
refuseEngineOwnedFormat(doc);
|
|
681
708
|
// Ignore push flag
|
|
682
709
|
const disableRecalc = Boolean(patches.find(([patch]) => patch?.disableRecalc));
|
|
683
710
|
// Check if this is a full recalc
|
|
@@ -826,6 +853,7 @@ export const useYSpreadsheetV2 = ({ onChangeSheetData, onChangeSheets, onChangeT
|
|
|
826
853
|
recalcCellsMaxEntries,
|
|
827
854
|
useV3,
|
|
828
855
|
isV5Doc,
|
|
856
|
+
isFinalDoc,
|
|
829
857
|
stylesV5,
|
|
830
858
|
]);
|
|
831
859
|
// Listen to active cell change
|
|
@@ -35,6 +35,8 @@ export type useYSpreadsheetProps<T extends CellData, S extends Sheet, C extends
|
|
|
35
35
|
/**
|
|
36
36
|
* Connects to a Y server and picks up the most recent change
|
|
37
37
|
* Does not load initial data
|
|
38
|
+
* A doc stamped final (`docMeta.sheetDataVersion` "v6", `docIsFinalFormat`) is
|
|
39
|
+
* refused (`FinalFormatError`): open it through the engine.
|
|
38
40
|
* @returns
|
|
39
41
|
*/
|
|
40
42
|
export declare const useYSpreadsheet: <T extends CellData, S extends Sheet, C extends EmbeddedChart, O extends EmbeddedObject>({ onChangeSheetData, onChangeSheets, onChangeTables, onChangeCharts, onChangeEmbeds, onChangeConditionalFormats, onChangeDataValidations, onChangeNamedRanges, onChangeProtectedRanges, onError, enqueueCalculation, calculateNow, userId, title, sheetId, activeCell, doc, provider, yjs: yjsRuntime, }: useYSpreadsheetProps<T, S, C, O>) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-yspreadsheet.d.ts","sourceRoot":"","sources":["../../use-yspreadsheet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EACZ,qBAAqB,EACrB,wBAAwB,EACxB,aAAa,EACb,cAAc,EACd,UAAU,EACV,cAAc,EACd,KAAK,EACL,SAAS,EACV,MAAM,2BAA2B,CAAC;AAKnC,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACpB,WAAW,EAEX,SAAS,EACT,gBAAgB,EACjB,MAA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CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;gCA0RpB,CACP,KAAK,EAAE,gBAAgB,CAAC,KAAK,CAAC,EAC9B,IAAI,CAAC,EAAE,WAAW,GAAG,SAAS,CAC/B,EAAE;;;CAyDR,CAAC"}
|
|
@@ -2,6 +2,7 @@ import { scheduleNormalPriorityCallback, useIsomorphicLayoutEffect, } from "@row
|
|
|
2
2
|
import { applyPatches } from "immer";
|
|
3
3
|
import uniqBy from "lodash/uniqBy";
|
|
4
4
|
import { useCallback, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { refuseEngineOwnedFormat, sheetDataFormatOf } from "./helpers-v5";
|
|
5
6
|
import { resolveYjsRuntime } from "./yjs-runtime";
|
|
6
7
|
import { insertedValues } from "./ynodes";
|
|
7
8
|
const getStateVector = (doc, yjs) => yjs.encodeStateVector(doc);
|
|
@@ -14,6 +15,8 @@ const getUpdatesBetween = (doc, stateVector1, stateVector2, yjs) => {
|
|
|
14
15
|
/**
|
|
15
16
|
* Connects to a Y server and picks up the most recent change
|
|
16
17
|
* Does not load initial data
|
|
18
|
+
* A doc stamped final (`docMeta.sheetDataVersion` "v6", `docIsFinalFormat`) is
|
|
19
|
+
* refused (`FinalFormatError`): open it through the engine.
|
|
17
20
|
* @returns
|
|
18
21
|
*/
|
|
19
22
|
export const useYSpreadsheet = ({ onChangeSheetData, onChangeSheets, onChangeTables, onChangeCharts, onChangeEmbeds, onChangeConditionalFormats, onChangeDataValidations, onChangeNamedRanges, onChangeProtectedRanges, onError, enqueueCalculation, calculateNow, userId, title, sheetId, activeCell, doc, provider, yjs: yjsRuntime, }) => {
|
|
@@ -22,6 +25,18 @@ export const useYSpreadsheet = ({ onChangeSheetData, onChangeSheets, onChangeTab
|
|
|
22
25
|
const [synced, setSynced] = useState(false);
|
|
23
26
|
const previousStateVectorRef = useRef(undefined);
|
|
24
27
|
const currentStateVectorRef = useRef(undefined);
|
|
28
|
+
// Final format (`docMeta.sheetDataVersion = "v6"`): the engine's. This hook
|
|
29
|
+
// keeps patch lists in roots such a doc uses otherwise (`sheets` is its sheet
|
|
30
|
+
// list), so its load and its writes refuse it (`FinalFormatError`) and its
|
|
31
|
+
// observers leave the state as it is. Read live: the stamp may arrive with a
|
|
32
|
+
// sync. A host checks `docIsFinalFormat` and opens such a doc through the
|
|
33
|
+
// engine instead.
|
|
34
|
+
// A doc stamped with a format this package does not know is refused the same
|
|
35
|
+
// way (`UnknownFormatError`): the engine alone decides what such a doc holds.
|
|
36
|
+
const isFinalDoc = useCallback(() => {
|
|
37
|
+
const format = sheetDataFormatOf(doc);
|
|
38
|
+
return format === "v6" || format === "unknown";
|
|
39
|
+
}, [doc]);
|
|
25
40
|
// Recalc cells
|
|
26
41
|
const yRecalcCells = useMemo(() => doc.get("recalcCells"), [doc]);
|
|
27
42
|
const yDisableRecalc = doc.get("disableRecalc");
|
|
@@ -67,6 +82,7 @@ export const useYSpreadsheet = ({ onChangeSheetData, onChangeSheets, onChangeTab
|
|
|
67
82
|
const awareness = provider?.awareness;
|
|
68
83
|
// Callback when the content is first synced
|
|
69
84
|
const onSynced = useCallback(() => {
|
|
85
|
+
refuseEngineOwnedFormat(doc);
|
|
70
86
|
let syncedDoc = doc;
|
|
71
87
|
if (previousStateVectorRef.current) {
|
|
72
88
|
// Capture the current state vector on subsequent syncs
|
|
@@ -118,7 +134,7 @@ export const useYSpreadsheet = ({ onChangeSheetData, onChangeSheets, onChangeTab
|
|
|
118
134
|
});
|
|
119
135
|
// Set synced
|
|
120
136
|
setSynced(true);
|
|
121
|
-
}, [calculateNow, docMap, onError, doc, yjs]);
|
|
137
|
+
}, [calculateNow, docMap, onError, doc, yjs, isFinalDoc]);
|
|
122
138
|
// Sync state
|
|
123
139
|
if (provider?.synced && !synced) {
|
|
124
140
|
onSynced();
|
|
@@ -192,6 +208,8 @@ export const useYSpreadsheet = ({ onChangeSheetData, onChangeSheets, onChangeTab
|
|
|
192
208
|
};
|
|
193
209
|
// Trigger cell recalcs
|
|
194
210
|
const onRecalcCellsChange = (event) => {
|
|
211
|
+
if (isFinalDoc())
|
|
212
|
+
return;
|
|
195
213
|
const patches = getPatchDeltasFromEvent(event);
|
|
196
214
|
if (event.transaction.origin !== "local") {
|
|
197
215
|
syncRecalcCells(patches);
|
|
@@ -202,6 +220,8 @@ export const useYSpreadsheet = ({ onChangeSheetData, onChangeSheets, onChangeTab
|
|
|
202
220
|
const subs = [];
|
|
203
221
|
for (const [_, [doc, setStateFn]] of docMap) {
|
|
204
222
|
const callback = (event) => {
|
|
223
|
+
if (isFinalDoc())
|
|
224
|
+
return;
|
|
205
225
|
const patches = getPatchDeltasFromEvent(event);
|
|
206
226
|
const disableRecalc = yDisableRecalc.getAttr("disableRecalc");
|
|
207
227
|
if (event.transaction.origin !== "local" && disableRecalc !== true) {
|
|
@@ -229,9 +249,10 @@ export const useYSpreadsheet = ({ onChangeSheetData, onChangeSheets, onChangeTab
|
|
|
229
249
|
yRecalcCells.unobserve(onRecalcCellsChange);
|
|
230
250
|
};
|
|
231
251
|
}
|
|
232
|
-
}, [userId, provider, synced, doc, yDisableRecalc]);
|
|
252
|
+
}, [userId, provider, synced, doc, yDisableRecalc, isFinalDoc]);
|
|
233
253
|
// Broadcast patch
|
|
234
254
|
const onBroadcastPatch = useCallback((patches) => {
|
|
255
|
+
refuseEngineOwnedFormat(doc);
|
|
235
256
|
doc.transact(() => {
|
|
236
257
|
for (const [patch, type = "redo"] of patches) {
|
|
237
258
|
const patchKey = type === "redo" ? "patches" : "inversePatches";
|
|
@@ -260,7 +281,7 @@ export const useYSpreadsheet = ({ onChangeSheetData, onChangeSheets, onChangeTab
|
|
|
260
281
|
}
|
|
261
282
|
}
|
|
262
283
|
}, "local");
|
|
263
|
-
}, [userId, docMap, doc, yRecalcCells, yDisableRecalc]);
|
|
284
|
+
}, [userId, docMap, doc, yRecalcCells, yDisableRecalc, isFinalDoc]);
|
|
264
285
|
// Listen to active cell change
|
|
265
286
|
useIsomorphicLayoutEffect(() => {
|
|
266
287
|
if (activeCell) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rowsncolumns/y-spreadsheet",
|
|
3
|
-
"version": "17.1.
|
|
3
|
+
"version": "17.1.3",
|
|
4
4
|
"main": "./dist/cjs/index.js",
|
|
5
5
|
"module": "./dist/esm/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"@hocuspocus/provider": "^3.1.1",
|
|
37
37
|
"@rowsncolumns/common-types": ">=5.5.1",
|
|
38
38
|
"@rowsncolumns/fast-formula-parser": ">=6.2.49",
|
|
39
|
-
"@rowsncolumns/grid": ">=13.12.
|
|
40
|
-
"@rowsncolumns/spreadsheet": ">=10.
|
|
41
|
-
"@rowsncolumns/spreadsheet-state": ">=29.8.
|
|
39
|
+
"@rowsncolumns/grid": ">=13.12.2",
|
|
40
|
+
"@rowsncolumns/spreadsheet": ">=10.20.2",
|
|
41
|
+
"@rowsncolumns/spreadsheet-state": ">=29.8.3",
|
|
42
42
|
"@rowsncolumns/ui": ">=16.2.8",
|
|
43
|
-
"@rowsncolumns/utils": ">=9.8.
|
|
43
|
+
"@rowsncolumns/utils": ">=9.8.4",
|
|
44
44
|
"@types/lodash": "^4.17.17",
|
|
45
45
|
"@y/y": "14.0.0-rc.29",
|
|
46
46
|
"immer": "^11.2.8",
|