@rowsncolumns/y-spreadsheet 17.1.2 → 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 +8 -0
- package/dist/cjs/helpers.d.ts.map +1 -1
- package/dist/cjs/helpers.js +60 -0
- 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 +8 -0
- package/dist/esm/helpers.d.ts.map +1 -1
- package/dist/esm/helpers.js +61 -1
- 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 +2 -2
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.
|
|
@@ -288,6 +297,7 @@ export const getSheetFromYSheetData = (ySheetData, sheetId, yjsRuntime) => {
|
|
|
288
297
|
return sheet;
|
|
289
298
|
};
|
|
290
299
|
export const deleteSheetFromYSheetData = (ySheetData, sheetId) => {
|
|
300
|
+
refuseEngineOwnedType(ySheetData);
|
|
291
301
|
const id = String(sheetId);
|
|
292
302
|
ySheetData.deleteAttr(id);
|
|
293
303
|
};
|
|
@@ -529,6 +539,7 @@ export const mergeErrorEffectiveValueIntoCellData = (currentCellData, incomingCe
|
|
|
529
539
|
* Update array type with immer patches
|
|
530
540
|
*/
|
|
531
541
|
export const updateArrayType = (yarray, patches) => {
|
|
542
|
+
refuseEngineOwnedType(yarray);
|
|
532
543
|
// Consecutive nested-path patches targeting the same array item are
|
|
533
544
|
// consolidated into one cloneDeep + one Y.Array write. An immer splice on
|
|
534
545
|
// a nested array (e.g. a sheet's rowMetadata on row insert/delete) emits
|
|
@@ -685,6 +696,7 @@ export const validateSheets = (sheets) => {
|
|
|
685
696
|
* Map operations
|
|
686
697
|
*/
|
|
687
698
|
export const applyMapPatches = (yMap, patches) => {
|
|
699
|
+
refuseEngineOwnedType(yMap);
|
|
688
700
|
for (const { op, path, value } of patches) {
|
|
689
701
|
if (!path || !path.length) {
|
|
690
702
|
if (op === "remove") {
|
|
@@ -886,6 +898,41 @@ export const processSheetDataEvents = (events, currentSheetData, ySheetDataV2, y
|
|
|
886
898
|
// ============================================================================
|
|
887
899
|
// V3 Helper Functions (Flat Map Structure)
|
|
888
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
|
+
};
|
|
889
936
|
/**
|
|
890
937
|
* Convert letter to column index (1-based)
|
|
891
938
|
* A = 1, B = 2, ..., Z = 26, AA = 27, etc.
|
|
@@ -959,6 +1006,7 @@ export const sheetDataV2ToV3 = (v2Data) => {
|
|
|
959
1006
|
* Convert V3 flat Map format to V2 SheetData
|
|
960
1007
|
* V3: Map<cellKey, CellDataV3>
|
|
961
1008
|
* V2: { sheetId: [rows with values arrays] }
|
|
1009
|
+
* Handed plain data, it cannot tell a doc stamped final: its caller checks `docIsFinalFormat` first.
|
|
962
1010
|
*/
|
|
963
1011
|
export const sheetDataV3ToV2 = (v3Data) => {
|
|
964
1012
|
const sheetData = {};
|
|
@@ -990,29 +1038,37 @@ export const sheetDataV3ToV2 = (v3Data) => {
|
|
|
990
1038
|
};
|
|
991
1039
|
/**
|
|
992
1040
|
* Get a cell from V3 flat structure
|
|
1041
|
+
* @throws FinalFormatError on a doc stamped final (`docIsFinalFormat`).
|
|
993
1042
|
*/
|
|
994
1043
|
export const getCellV3 = (ySheetDataV3, sheetId, rowIndex, columnIndex) => {
|
|
1044
|
+
refuseFinalFormatV3(ySheetDataV3);
|
|
995
1045
|
const key = createCellKeyV3(sheetId, rowIndex, columnIndex);
|
|
996
1046
|
return ySheetDataV3.getAttr(key);
|
|
997
1047
|
};
|
|
998
1048
|
/**
|
|
999
1049
|
* Set a cell in V3 flat structure
|
|
1050
|
+
* @throws FinalFormatError on a doc stamped final (`docIsFinalFormat`): nothing is written.
|
|
1000
1051
|
*/
|
|
1001
1052
|
export const setCellV3 = (ySheetDataV3, sheetId, rowIndex, columnIndex, value) => {
|
|
1053
|
+
refuseWriteV3(ySheetDataV3);
|
|
1002
1054
|
const key = createCellKeyV3(sheetId, rowIndex, columnIndex);
|
|
1003
1055
|
ySheetDataV3.setAttr(key, createCellDataV3(value, sheetId, rowIndex, columnIndex));
|
|
1004
1056
|
};
|
|
1005
1057
|
/**
|
|
1006
1058
|
* Delete a cell from V3 flat structure
|
|
1059
|
+
* @throws FinalFormatError on a doc stamped final (`docIsFinalFormat`): nothing is written.
|
|
1007
1060
|
*/
|
|
1008
1061
|
export const deleteCellV3 = (ySheetDataV3, sheetId, rowIndex, columnIndex) => {
|
|
1062
|
+
refuseWriteV3(ySheetDataV3);
|
|
1009
1063
|
const key = createCellKeyV3(sheetId, rowIndex, columnIndex);
|
|
1010
1064
|
ySheetDataV3.deleteAttr(key);
|
|
1011
1065
|
};
|
|
1012
1066
|
/**
|
|
1013
1067
|
* Delete all cells for a sheet from V3 flat structure
|
|
1068
|
+
* @throws FinalFormatError on a doc stamped final (`docIsFinalFormat`): nothing is written.
|
|
1014
1069
|
*/
|
|
1015
1070
|
export const deleteSheetV3 = (ySheetDataV3, sheetId) => {
|
|
1071
|
+
refuseWriteV3(ySheetDataV3);
|
|
1016
1072
|
const prefix = `${sheetId}!`;
|
|
1017
1073
|
for (const key of ySheetDataV3.attrKeys()) {
|
|
1018
1074
|
if (key.startsWith(prefix)) {
|
|
@@ -1033,8 +1089,10 @@ export const getSheetDataV3 = (doc) => {
|
|
|
1033
1089
|
* patches before applying to Y.js. This reduces overhead by:
|
|
1034
1090
|
* 1. Deduplicating patches targeting the same cell (later patches win)
|
|
1035
1091
|
* 2. Processing all cell updates in a single pass
|
|
1092
|
+
* @throws FinalFormatError on a doc stamped final (`docIsFinalFormat`): nothing is written.
|
|
1036
1093
|
*/
|
|
1037
1094
|
export const addSheetDataPatchesV3 = (ySheetDataV3, patches) => {
|
|
1095
|
+
refuseWriteV3(ySheetDataV3);
|
|
1038
1096
|
// Row-targeted patches (e.g. the per-shifted-row patches an immer array
|
|
1039
1097
|
// splice emits for a row insert/delete) previously scanned the entire flat
|
|
1040
1098
|
// cell map once per patch — O(patches × totalCells), which freezes the tab
|
|
@@ -1296,8 +1354,10 @@ export const addSheetDataPatchesV3 = (ySheetDataV3, patches) => {
|
|
|
1296
1354
|
* @param changedKeys - Pre-extracted changes from Yjs event
|
|
1297
1355
|
* @param currentSheetData - Current sheet data state
|
|
1298
1356
|
* @param ySheetDataV3 - The map node for V3 data
|
|
1357
|
+
* @throws FinalFormatError on a doc stamped final (`docIsFinalFormat`).
|
|
1299
1358
|
*/
|
|
1300
1359
|
export const processSheetDataEventsV3 = (changedKeys, currentSheetData, ySheetDataV3) => {
|
|
1360
|
+
refuseFinalFormatV3(ySheetDataV3);
|
|
1301
1361
|
if (changedKeys.size === 0)
|
|
1302
1362
|
return null;
|
|
1303
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,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AM,CAAA;KAAE,CAAC,KACrE,IAAI,CAAC;CACX,CAAC;AAEF,uFAAuF;AACvF,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC;AAC7B,gEAAgE;AAChE,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC;AAI/B,eAAO,MAAM,iBAAiB,GAC5B,CAAC,SAAS,QAAQ,EAClB,CAAC,SAAS,KAAK,EACf,CAAC,SAAS,aAAa,EACvB,CAAC,SAAS,cAAc,EACxB,0uBA0CC,sBAAsB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;;;gCAsyBtB,CACP,KAAK,EAAE,gBAAgB,CAAC,KAAK,CAAC,EAC9B,IAAI,CAAC,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CACtC,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,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;
|
|
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,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAMnC,OAAO,KAAK,EACV,kBAAkB,EAGlB,IAAI,EAEJ,UAAU,EAEX,MAAM,SAAS,CAAC;AAkBjB,MAAM,MAAM,oBAAoB,CAC9B,CAAC,SAAS,QAAQ,EAClB,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C,qBAAqB,EAAE,CAAC,CAC9C,CAAC;IACF,uBAAuB,CAAC,EAAE,KAAK,CAAC,QAAQ,CACtC,KAAK,CAAC,cAAc,CAAC,wBAAwB,EAAE,CAAC,CACjD,CAAC;IACF,kBAAkB,EAAE,CAAC,SAAS,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAC9D,OAAO,CAAC,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7B,mBAAmB,CAAC,IAAI,IAAI,CAAC;CAC9B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAC1B,CAAC,SAAS,QAAQ,EAClB,CAAC,SAAS,KAAK,EACf,CAAC,SAAS,aAAa,EACvB,CAAC,SAAS,cAAc,EACxB,0SAoBC,oBAAoB,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": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@rowsncolumns/common-types": ">=5.5.1",
|
|
38
38
|
"@rowsncolumns/fast-formula-parser": ">=6.2.49",
|
|
39
39
|
"@rowsncolumns/grid": ">=13.12.2",
|
|
40
|
-
"@rowsncolumns/spreadsheet": ">=10.20.
|
|
40
|
+
"@rowsncolumns/spreadsheet": ">=10.20.2",
|
|
41
41
|
"@rowsncolumns/spreadsheet-state": ">=29.8.3",
|
|
42
42
|
"@rowsncolumns/ui": ">=16.2.8",
|
|
43
43
|
"@rowsncolumns/utils": ">=9.8.4",
|