@rowsncolumns/y-spreadsheet 16.1.0 → 17.0.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/Readme.md +21 -6
- package/dist/cjs/helpers-v5.d.ts +11 -11
- package/dist/cjs/helpers-v5.d.ts.map +1 -1
- package/dist/cjs/helpers-v5.js +46 -33
- package/dist/cjs/helpers.d.ts +17 -19
- package/dist/cjs/helpers.d.ts.map +1 -1
- package/dist/cjs/helpers.js +89 -86
- package/dist/cjs/observables.d.ts +7 -7
- package/dist/cjs/observables.d.ts.map +1 -1
- package/dist/cjs/observables.js +34 -46
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/cjs/types.d.ts +96 -19
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/cjs/use-yspreadsheet-v2.d.ts +11 -10
- package/dist/cjs/use-yspreadsheet-v2.d.ts.map +1 -1
- package/dist/cjs/use-yspreadsheet-v2.js +79 -90
- package/dist/cjs/use-yspreadsheet.d.ts +6 -6
- package/dist/cjs/use-yspreadsheet.d.ts.map +1 -1
- package/dist/cjs/use-yspreadsheet.js +38 -74
- package/dist/cjs/yjs-runtime.js +5 -5
- package/dist/cjs/ynodes.d.ts +61 -0
- package/dist/cjs/ynodes.d.ts.map +1 -0
- package/dist/cjs/ynodes.js +224 -0
- package/dist/esm/helpers-v5.d.ts +11 -11
- package/dist/esm/helpers-v5.d.ts.map +1 -1
- package/dist/esm/helpers-v5.js +46 -33
- package/dist/esm/helpers.d.ts +17 -19
- package/dist/esm/helpers.d.ts.map +1 -1
- package/dist/esm/helpers.js +90 -87
- package/dist/esm/observables.d.ts +7 -7
- package/dist/esm/observables.d.ts.map +1 -1
- package/dist/esm/observables.js +21 -25
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/types.d.ts +96 -19
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/use-yspreadsheet-v2.d.ts +11 -10
- package/dist/esm/use-yspreadsheet-v2.d.ts.map +1 -1
- package/dist/esm/use-yspreadsheet-v2.js +76 -88
- package/dist/esm/use-yspreadsheet.d.ts +6 -6
- package/dist/esm/use-yspreadsheet.d.ts.map +1 -1
- package/dist/esm/use-yspreadsheet.js +17 -43
- package/dist/esm/yjs-runtime.js +5 -5
- package/dist/esm/ynodes.d.ts +61 -0
- package/dist/esm/ynodes.d.ts.map +1 -0
- package/dist/esm/ynodes.js +146 -0
- package/package.json +9 -8
package/dist/cjs/helpers.js
CHANGED
|
@@ -9,6 +9,7 @@ var set_1 = tslib_1.__importDefault(require("lodash/set"));
|
|
|
9
9
|
var get_1 = tslib_1.__importDefault(require("lodash/get"));
|
|
10
10
|
var unset_1 = tslib_1.__importDefault(require("lodash/unset"));
|
|
11
11
|
var yjs_runtime_1 = require("./yjs-runtime");
|
|
12
|
+
var ynodes_1 = require("./ynodes");
|
|
12
13
|
var helpers_v5_1 = require("./helpers-v5");
|
|
13
14
|
tslib_1.__exportStar(require("./helpers-v5"), exports);
|
|
14
15
|
/**
|
|
@@ -23,24 +24,26 @@ var applyPatchesToYDoc = function (doc, userId, patches, source, sheetDataVersio
|
|
|
23
24
|
var e_1, _a;
|
|
24
25
|
var _b, _c;
|
|
25
26
|
var yjs = (0, yjs_runtime_1.resolveYjsRuntime)(yjsRuntime);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
-
var
|
|
39
|
-
var
|
|
40
|
-
var
|
|
27
|
+
// Maps: sheetDataV2, sheetDataV3, docMeta, sharedStringsMap, cellXfs,
|
|
28
|
+
// disableRecalc. Arrays: everything else.
|
|
29
|
+
var ySheetDataV2 = doc.get("sheetDataV2");
|
|
30
|
+
var ySheetDataV3 = doc.get("sheetDataV3");
|
|
31
|
+
var yDocMeta = doc.get("docMeta");
|
|
32
|
+
var yRecalcCells = doc.get("recalcCells");
|
|
33
|
+
var ySheets = doc.get("sheets");
|
|
34
|
+
var yTables = doc.get("tables");
|
|
35
|
+
var yEmbeds = doc.get("embeds");
|
|
36
|
+
var yCharts = doc.get("charts");
|
|
37
|
+
var yConditionalFormats = doc.get("conditionalFormats");
|
|
38
|
+
var yDataValidations = doc.get("dataValidations");
|
|
39
|
+
var yNamedRanges = doc.get("namedRanges");
|
|
40
|
+
var ySharedStringsMap = doc.get("sharedStringsMap");
|
|
41
|
+
var yProtectedRanges = doc.get("protectedRanges");
|
|
42
|
+
var yCellXfs = doc.get("cellXfs");
|
|
43
|
+
var yDisableRecalc = doc.get("disableRecalc");
|
|
41
44
|
// Check version flag to determine which sheet data format to use
|
|
42
45
|
// Use param if provided, otherwise fall back to docMeta for backwards compatibility
|
|
43
|
-
var resolvedVersion = sheetDataVersion !== null && sheetDataVersion !== void 0 ? sheetDataVersion : yDocMeta.
|
|
46
|
+
var resolvedVersion = sheetDataVersion !== null && sheetDataVersion !== void 0 ? sheetDataVersion : yDocMeta.getAttr("sheetDataVersion");
|
|
44
47
|
var isV3 = resolvedVersion === "v3";
|
|
45
48
|
var isV5 = resolvedVersion === "v5";
|
|
46
49
|
try {
|
|
@@ -125,8 +128,8 @@ var applyPatchesToYDoc = function (doc, userId, patches, source, sheetDataVersio
|
|
|
125
128
|
finally { if (e_1) throw e_1.error; }
|
|
126
129
|
}
|
|
127
130
|
// Set disable recalc flag (only if it's currently truthy, to avoid redundant Y.Map writes)
|
|
128
|
-
if (yDisableRecalc.
|
|
129
|
-
yDisableRecalc.
|
|
131
|
+
if (yDisableRecalc.getAttr("disableRecalc") !== false) {
|
|
132
|
+
yDisableRecalc.setAttr("disableRecalc", false);
|
|
130
133
|
}
|
|
131
134
|
};
|
|
132
135
|
exports.applyPatchesToYDoc = applyPatchesToYDoc;
|
|
@@ -223,7 +226,7 @@ var addSheetDataPatches = function (ySheetData, patches, yjsRuntime) {
|
|
|
223
226
|
// Replace. User is replacing the entire data
|
|
224
227
|
if (op === "replace") {
|
|
225
228
|
// Remove all sheet data
|
|
226
|
-
ySheetData.
|
|
229
|
+
ySheetData.clearAttrs();
|
|
227
230
|
}
|
|
228
231
|
// Assign values
|
|
229
232
|
for (var curSheetId in value) {
|
|
@@ -244,7 +247,7 @@ var addSheetDataPatches = function (ySheetData, patches, yjsRuntime) {
|
|
|
244
247
|
var _c = tslib_1.__read(path, 2), rowIndex = _c[1];
|
|
245
248
|
var rowData_1 = (0, exports.getRowDataFromSheet)(ysheet_1, rowIndex, yjs);
|
|
246
249
|
// Clear existing row data
|
|
247
|
-
|
|
250
|
+
(0, ynodes_1.listDelete)(rowData_1, 0, rowData_1.length);
|
|
248
251
|
if (Array.isArray(value)) {
|
|
249
252
|
// Value is the values array directly
|
|
250
253
|
// Sort keys to maintain order during insertion
|
|
@@ -267,7 +270,7 @@ var addSheetDataPatches = function (ySheetData, patches, yjsRuntime) {
|
|
|
267
270
|
// Replace entire row with new values
|
|
268
271
|
var rowData_2 = (0, exports.getRowDataFromSheet)(ysheet_1, rowIndex, yjs);
|
|
269
272
|
// Clear existing row data
|
|
270
|
-
|
|
273
|
+
(0, ynodes_1.listDelete)(rowData_2, 0, rowData_2.length);
|
|
271
274
|
// Add new cell values
|
|
272
275
|
// Sort keys to maintain order during insertion
|
|
273
276
|
Object.entries(value.values)
|
|
@@ -290,7 +293,7 @@ var addSheetDataPatches = function (ySheetData, patches, yjsRuntime) {
|
|
|
290
293
|
else if (path.length === 1) {
|
|
291
294
|
if (value) {
|
|
292
295
|
// Clear entire sheet
|
|
293
|
-
|
|
296
|
+
(0, ynodes_1.listDelete)(ysheet_1, 0, ysheet_1.length);
|
|
294
297
|
// Add all new data
|
|
295
298
|
Object.entries(value)
|
|
296
299
|
.sort(function (_a, _b) {
|
|
@@ -370,17 +373,17 @@ exports.addSheetDataPatches = addSheetDataPatches;
|
|
|
370
373
|
var getSheetFromYSheetData = function (ySheetData, sheetId, yjsRuntime) {
|
|
371
374
|
var yjs = (0, yjs_runtime_1.resolveYjsRuntime)(yjsRuntime);
|
|
372
375
|
var id = String(sheetId);
|
|
373
|
-
var sheet = ySheetData.
|
|
376
|
+
var sheet = ySheetData.getAttr(id);
|
|
374
377
|
if (!sheet) {
|
|
375
|
-
sheet =
|
|
376
|
-
ySheetData.
|
|
378
|
+
sheet = yjs.createArray();
|
|
379
|
+
ySheetData.setAttr(id, sheet);
|
|
377
380
|
}
|
|
378
381
|
return sheet;
|
|
379
382
|
};
|
|
380
383
|
exports.getSheetFromYSheetData = getSheetFromYSheetData;
|
|
381
384
|
var deleteSheetFromYSheetData = function (ySheetData, sheetId) {
|
|
382
385
|
var id = String(sheetId);
|
|
383
|
-
ySheetData.
|
|
386
|
+
ySheetData.deleteAttr(id);
|
|
384
387
|
};
|
|
385
388
|
exports.deleteSheetFromYSheetData = deleteSheetFromYSheetData;
|
|
386
389
|
var getRowDataFromSheet = function (ysheet, rowIndex, yjsRuntime) {
|
|
@@ -392,11 +395,11 @@ var getRowDataFromSheet = function (ysheet, rowIndex, yjsRuntime) {
|
|
|
392
395
|
// Extend array if needed
|
|
393
396
|
if (index >= ysheet.length) {
|
|
394
397
|
var padding = new Array(index - ysheet.length).fill(null);
|
|
395
|
-
|
|
398
|
+
(0, ynodes_1.listInsert)(ysheet, ysheet.length, padding);
|
|
396
399
|
ysheet.insert(index, [null]); // Insert null first
|
|
397
|
-
// Create new row data
|
|
398
|
-
|
|
399
|
-
newRowData.
|
|
400
|
+
// Create new row data (a node is built with its content: it can be read
|
|
401
|
+
// only once it is in the document)
|
|
402
|
+
var newRowData = yjs.createMap([["values", yjs.createArray()]]);
|
|
400
403
|
// Replace the null
|
|
401
404
|
ysheet.insert(index, [newRowData]);
|
|
402
405
|
ysheet.delete(index + 1, 1);
|
|
@@ -408,20 +411,19 @@ var getRowDataFromSheet = function (ysheet, rowIndex, yjsRuntime) {
|
|
|
408
411
|
// Insert newRowData at index. length = index+2.
|
|
409
412
|
// Delete at index+1. length = index+1.
|
|
410
413
|
// Correct.
|
|
411
|
-
return newRowData.
|
|
414
|
+
return newRowData.getAttr("values");
|
|
412
415
|
}
|
|
413
416
|
// Get or create existing row data
|
|
414
417
|
var rowData = ysheet.get(index);
|
|
415
|
-
if (!rowData || !rowData.
|
|
418
|
+
if (!rowData || !rowData.getAttr("values")) {
|
|
416
419
|
// Create new row data if it doesn't exist or is incomplete
|
|
417
|
-
var newRowData =
|
|
418
|
-
newRowData.set("values", new yjs.Array());
|
|
420
|
+
var newRowData = yjs.createMap([["values", yjs.createArray()]]);
|
|
419
421
|
// Replace the existing item
|
|
420
422
|
ysheet.insert(index, [newRowData]);
|
|
421
423
|
ysheet.delete(index + 1, 1);
|
|
422
|
-
return newRowData.
|
|
424
|
+
return newRowData.getAttr("values");
|
|
423
425
|
}
|
|
424
|
-
return rowData.
|
|
426
|
+
return rowData.getAttr("values");
|
|
425
427
|
};
|
|
426
428
|
exports.getRowDataFromSheet = getRowDataFromSheet;
|
|
427
429
|
var setCellDataInRowData = function (rowData, columnIndex, cellData) {
|
|
@@ -459,13 +461,13 @@ exports.removeRowData = removeRowData;
|
|
|
459
461
|
* getRowDataFromSheet, which lazily create them).
|
|
460
462
|
*/
|
|
461
463
|
var getCellDataFromYSheetData = function (ySheetData, sheetId, rowIndex, columnIndex) {
|
|
462
|
-
var sheet = ySheetData.
|
|
464
|
+
var sheet = ySheetData.getAttr(String(sheetId));
|
|
463
465
|
var rowIdx = Number(rowIndex);
|
|
464
466
|
if (!sheet || rowIdx < 0 || rowIdx >= sheet.length) {
|
|
465
467
|
return undefined;
|
|
466
468
|
}
|
|
467
469
|
var row = sheet.get(rowIdx);
|
|
468
|
-
var values = row === null || row === void 0 ? void 0 : row.
|
|
470
|
+
var values = row === null || row === void 0 ? void 0 : row.getAttr("values");
|
|
469
471
|
var colIdx = Number(columnIndex);
|
|
470
472
|
if (!values || colIdx < 0 || colIdx >= values.length) {
|
|
471
473
|
return undefined;
|
|
@@ -626,8 +628,8 @@ var updateArrayType = function (yarray, patches) {
|
|
|
626
628
|
flushPending();
|
|
627
629
|
// User is replacing the entire array
|
|
628
630
|
if (op === "replace") {
|
|
629
|
-
|
|
630
|
-
yarray.
|
|
631
|
+
(0, ynodes_1.listDelete)(yarray, 0, yarray.length);
|
|
632
|
+
(0, ynodes_1.listInsert)(yarray, yarray.length, value);
|
|
631
633
|
}
|
|
632
634
|
return;
|
|
633
635
|
}
|
|
@@ -719,7 +721,7 @@ exports.updateArrayType = updateArrayType;
|
|
|
719
721
|
function ensureArraySize(yarray, index) {
|
|
720
722
|
if (index >= yarray.length) {
|
|
721
723
|
var gaps = new Array(index - yarray.length).fill(null);
|
|
722
|
-
|
|
724
|
+
(0, ynodes_1.listInsert)(yarray, yarray.length, gaps);
|
|
723
725
|
yarray.insert(index, [null]); // Insert placeholder that will be replaced
|
|
724
726
|
}
|
|
725
727
|
}
|
|
@@ -772,18 +774,18 @@ var applyMapPatches = function (yMap, patches) {
|
|
|
772
774
|
if (!path || !path.length) {
|
|
773
775
|
if (op === "remove") {
|
|
774
776
|
// Only clear if there's something to clear
|
|
775
|
-
if (
|
|
776
|
-
yMap.
|
|
777
|
+
if ((0, ynodes_1.hasEntries)(yMap))
|
|
778
|
+
yMap.clearAttrs();
|
|
777
779
|
}
|
|
778
780
|
else if (op === "replace") {
|
|
779
781
|
// Diff against current contents instead of clear-and-rewrite, so keys
|
|
780
782
|
// whose references haven't changed don't generate Y.Map tombstones.
|
|
781
783
|
var incoming = new Map(value);
|
|
782
784
|
try {
|
|
783
|
-
for (var _e = (e_8 = void 0, tslib_1.__values(Array.from(yMap.
|
|
785
|
+
for (var _e = (e_8 = void 0, tslib_1.__values(Array.from(yMap.attrKeys()))), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
784
786
|
var k = _f.value;
|
|
785
787
|
if (!incoming.has(k))
|
|
786
|
-
yMap.
|
|
788
|
+
yMap.deleteAttr(k);
|
|
787
789
|
}
|
|
788
790
|
}
|
|
789
791
|
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
@@ -796,8 +798,8 @@ var applyMapPatches = function (yMap, patches) {
|
|
|
796
798
|
try {
|
|
797
799
|
for (var incoming_1 = (e_9 = void 0, tslib_1.__values(incoming)), incoming_1_1 = incoming_1.next(); !incoming_1_1.done; incoming_1_1 = incoming_1.next()) {
|
|
798
800
|
var _g = tslib_1.__read(incoming_1_1.value, 2), k = _g[0], v = _g[1];
|
|
799
|
-
if (yMap.
|
|
800
|
-
yMap.
|
|
801
|
+
if (yMap.getAttr(k) !== v)
|
|
802
|
+
yMap.setAttr(k, v);
|
|
801
803
|
}
|
|
802
804
|
}
|
|
803
805
|
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
@@ -812,12 +814,12 @@ var applyMapPatches = function (yMap, patches) {
|
|
|
812
814
|
}
|
|
813
815
|
var index = path[0];
|
|
814
816
|
if (op === "remove") {
|
|
815
|
-
if (yMap.
|
|
816
|
-
yMap.
|
|
817
|
+
if (yMap.hasAttr(index))
|
|
818
|
+
yMap.deleteAttr(index);
|
|
817
819
|
}
|
|
818
820
|
else if (op === "add" || op === "replace") {
|
|
819
|
-
if (yMap.
|
|
820
|
-
yMap.
|
|
821
|
+
if (yMap.getAttr(index) !== value)
|
|
822
|
+
yMap.setAttr(index, value);
|
|
821
823
|
}
|
|
822
824
|
}
|
|
823
825
|
}
|
|
@@ -834,8 +836,9 @@ exports.applyMapPatches = applyMapPatches;
|
|
|
834
836
|
* Process events to find changes in sheet data
|
|
835
837
|
* Returns a new sheet data object with only the changes applied if possible, or null if a full reload is needed
|
|
836
838
|
*/
|
|
837
|
-
var processSheetDataEvents = function (events, currentSheetData, ySheetDataV2) {
|
|
839
|
+
var processSheetDataEvents = function (events, currentSheetData, ySheetDataV2, yjsRuntime) {
|
|
838
840
|
var e_10, _a;
|
|
841
|
+
var yjs = (0, yjs_runtime_1.resolveYjsRuntime)(yjsRuntime);
|
|
839
842
|
var changes = new Map();
|
|
840
843
|
var fullReloadSheets = new Set();
|
|
841
844
|
var _loop_1 = function (event_1) {
|
|
@@ -925,20 +928,20 @@ var processSheetDataEvents = function (events, currentSheetData, ySheetDataV2) {
|
|
|
925
928
|
var next_1 = tslib_1.__assign({}, currentSheetData);
|
|
926
929
|
var hasChanges_1 = false;
|
|
927
930
|
fullReloadSheets.forEach(function (sheetId) {
|
|
928
|
-
var ySheet = ySheetDataV2.
|
|
931
|
+
var ySheet = ySheetDataV2.getAttr(sheetId);
|
|
929
932
|
if (!ySheet)
|
|
930
933
|
return;
|
|
931
|
-
var sheetData =
|
|
934
|
+
var sheetData = (0, ynodes_1.arrayJson)(ySheet, yjs);
|
|
932
935
|
next_1[sheetId] = sheetData;
|
|
933
936
|
hasChanges_1 = true;
|
|
934
937
|
});
|
|
935
938
|
changes.forEach(function (rowIndices, sheetId) {
|
|
936
|
-
var ySheet = ySheetDataV2.
|
|
939
|
+
var ySheet = ySheetDataV2.getAttr(sheetId);
|
|
937
940
|
if (!ySheet)
|
|
938
941
|
return;
|
|
939
942
|
// If full sheet reload needed
|
|
940
943
|
if (fullReloadSheets.has(sheetId)) {
|
|
941
|
-
var sheetData =
|
|
944
|
+
var sheetData = (0, ynodes_1.arrayJson)(ySheet, yjs);
|
|
942
945
|
next_1[sheetId] = sheetData;
|
|
943
946
|
hasChanges_1 = true;
|
|
944
947
|
return;
|
|
@@ -949,7 +952,7 @@ var processSheetDataEvents = function (events, currentSheetData, ySheetDataV2) {
|
|
|
949
952
|
}
|
|
950
953
|
if (next_1[sheetId].length < ySheet.length) {
|
|
951
954
|
if (next_1[sheetId].length !== ySheet.length) {
|
|
952
|
-
var sheetData =
|
|
955
|
+
var sheetData = (0, ynodes_1.arrayJson)(ySheet, yjs);
|
|
953
956
|
next_1[sheetId] = sheetData;
|
|
954
957
|
hasChanges_1 = true;
|
|
955
958
|
return;
|
|
@@ -964,7 +967,7 @@ var processSheetDataEvents = function (events, currentSheetData, ySheetDataV2) {
|
|
|
964
967
|
if (change.full) {
|
|
965
968
|
var normalizedRow = null;
|
|
966
969
|
if (yRow) {
|
|
967
|
-
var rowJson =
|
|
970
|
+
var rowJson = (0, ynodes_1.nodeJson)(yRow, yjs);
|
|
968
971
|
normalizedRow = rowJson;
|
|
969
972
|
}
|
|
970
973
|
nextSheet[rowIndex] = normalizedRow;
|
|
@@ -977,14 +980,14 @@ var processSheetDataEvents = function (events, currentSheetData, ySheetDataV2) {
|
|
|
977
980
|
}
|
|
978
981
|
return;
|
|
979
982
|
}
|
|
980
|
-
var yValues_1 = yRow.
|
|
983
|
+
var yValues_1 = yRow.getAttr("values");
|
|
981
984
|
if (!yValues_1) {
|
|
982
985
|
if (currentRow) {
|
|
983
986
|
nextSheet[rowIndex] = currentRow;
|
|
984
987
|
}
|
|
985
988
|
return;
|
|
986
989
|
}
|
|
987
|
-
var baseRow = currentRow !== null && currentRow !== void 0 ? currentRow :
|
|
990
|
+
var baseRow = currentRow !== null && currentRow !== void 0 ? currentRow : (0, ynodes_1.nodeJson)(yRow, yjs);
|
|
988
991
|
if (!baseRow) {
|
|
989
992
|
return;
|
|
990
993
|
}
|
|
@@ -1136,7 +1139,7 @@ exports.sheetDataV3ToV2 = sheetDataV3ToV2;
|
|
|
1136
1139
|
*/
|
|
1137
1140
|
var getCellV3 = function (ySheetDataV3, sheetId, rowIndex, columnIndex) {
|
|
1138
1141
|
var key = (0, exports.createCellKeyV3)(sheetId, rowIndex, columnIndex);
|
|
1139
|
-
return ySheetDataV3.
|
|
1142
|
+
return ySheetDataV3.getAttr(key);
|
|
1140
1143
|
};
|
|
1141
1144
|
exports.getCellV3 = getCellV3;
|
|
1142
1145
|
/**
|
|
@@ -1144,7 +1147,7 @@ exports.getCellV3 = getCellV3;
|
|
|
1144
1147
|
*/
|
|
1145
1148
|
var setCellV3 = function (ySheetDataV3, sheetId, rowIndex, columnIndex, value) {
|
|
1146
1149
|
var key = (0, exports.createCellKeyV3)(sheetId, rowIndex, columnIndex);
|
|
1147
|
-
ySheetDataV3.
|
|
1150
|
+
ySheetDataV3.setAttr(key, (0, exports.createCellDataV3)(value, sheetId, rowIndex, columnIndex));
|
|
1148
1151
|
};
|
|
1149
1152
|
exports.setCellV3 = setCellV3;
|
|
1150
1153
|
/**
|
|
@@ -1152,7 +1155,7 @@ exports.setCellV3 = setCellV3;
|
|
|
1152
1155
|
*/
|
|
1153
1156
|
var deleteCellV3 = function (ySheetDataV3, sheetId, rowIndex, columnIndex) {
|
|
1154
1157
|
var key = (0, exports.createCellKeyV3)(sheetId, rowIndex, columnIndex);
|
|
1155
|
-
ySheetDataV3.
|
|
1158
|
+
ySheetDataV3.deleteAttr(key);
|
|
1156
1159
|
};
|
|
1157
1160
|
exports.deleteCellV3 = deleteCellV3;
|
|
1158
1161
|
/**
|
|
@@ -1162,10 +1165,10 @@ var deleteSheetV3 = function (ySheetDataV3, sheetId) {
|
|
|
1162
1165
|
var e_12, _a;
|
|
1163
1166
|
var prefix = "".concat(sheetId, "!");
|
|
1164
1167
|
try {
|
|
1165
|
-
for (var _b = tslib_1.__values(ySheetDataV3.
|
|
1168
|
+
for (var _b = tslib_1.__values(ySheetDataV3.attrKeys()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1166
1169
|
var key = _c.value;
|
|
1167
1170
|
if (key.startsWith(prefix)) {
|
|
1168
|
-
ySheetDataV3.
|
|
1171
|
+
ySheetDataV3.deleteAttr(key);
|
|
1169
1172
|
}
|
|
1170
1173
|
}
|
|
1171
1174
|
}
|
|
@@ -1182,7 +1185,7 @@ exports.deleteSheetV3 = deleteSheetV3;
|
|
|
1182
1185
|
* Get V3 sheet data map from Y.Doc
|
|
1183
1186
|
*/
|
|
1184
1187
|
var getSheetDataV3 = function (doc) {
|
|
1185
|
-
return doc.
|
|
1188
|
+
return doc.get("sheetDataV3");
|
|
1186
1189
|
};
|
|
1187
1190
|
exports.getSheetDataV3 = getSheetDataV3;
|
|
1188
1191
|
/**
|
|
@@ -1212,7 +1215,7 @@ var addSheetDataPatchesV3 = function (ySheetDataV3, patches) {
|
|
|
1212
1215
|
}
|
|
1213
1216
|
rowCellKeyIndex = new Map();
|
|
1214
1217
|
try {
|
|
1215
|
-
for (var _b = tslib_1.__values(ySheetDataV3.
|
|
1218
|
+
for (var _b = tslib_1.__values(ySheetDataV3.attrEntries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1216
1219
|
var _d = tslib_1.__read(_c.value, 2), key = _d[0], cellData = _d[1];
|
|
1217
1220
|
var rk = rowIndexKey(cellData === null || cellData === void 0 ? void 0 : cellData.sId, cellData === null || cellData === void 0 ? void 0 : cellData.r);
|
|
1218
1221
|
var keys = rowCellKeyIndex.get(rk);
|
|
@@ -1257,7 +1260,7 @@ var addSheetDataPatchesV3 = function (ySheetDataV3, patches) {
|
|
|
1257
1260
|
try {
|
|
1258
1261
|
for (var keys_1 = tslib_1.__values(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
|
|
1259
1262
|
var key = keys_1_1.value;
|
|
1260
|
-
ySheetDataV3.
|
|
1263
|
+
ySheetDataV3.deleteAttr(key);
|
|
1261
1264
|
}
|
|
1262
1265
|
}
|
|
1263
1266
|
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
@@ -1306,11 +1309,11 @@ var addSheetDataPatchesV3 = function (ySheetDataV3, patches) {
|
|
|
1306
1309
|
for (var pendingCellUpdates_2 = tslib_1.__values(pendingCellUpdates), pendingCellUpdates_2_1 = pendingCellUpdates_2.next(); !pendingCellUpdates_2_1.done; pendingCellUpdates_2_1 = pendingCellUpdates_2.next()) {
|
|
1307
1310
|
var _b = tslib_1.__read(pendingCellUpdates_2_1.value, 2), key = _b[0], _c = _b[1], sheetId = _c.sheetId, rowIdx = _c.rowIdx, colIdx = _c.colIdx, value = _c.value;
|
|
1308
1311
|
if (value) {
|
|
1309
|
-
ySheetDataV3.
|
|
1312
|
+
ySheetDataV3.setAttr(key, (0, exports.createCellDataV3)(value, sheetId, rowIdx, colIdx));
|
|
1310
1313
|
trackCellKeySet(sheetId, rowIdx, key);
|
|
1311
1314
|
}
|
|
1312
1315
|
else {
|
|
1313
|
-
ySheetDataV3.
|
|
1316
|
+
ySheetDataV3.deleteAttr(key);
|
|
1314
1317
|
untrackCellKey(sheetId, rowIdx, key);
|
|
1315
1318
|
}
|
|
1316
1319
|
}
|
|
@@ -1334,9 +1337,9 @@ var addSheetDataPatchesV3 = function (ySheetDataV3, patches) {
|
|
|
1334
1337
|
if (op === "replace") {
|
|
1335
1338
|
try {
|
|
1336
1339
|
// Clear all cells
|
|
1337
|
-
for (var _f = tslib_1.__values(ySheetDataV3.
|
|
1340
|
+
for (var _f = tslib_1.__values(ySheetDataV3.attrKeys()), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1338
1341
|
var key = _g.value;
|
|
1339
|
-
ySheetDataV3.
|
|
1342
|
+
ySheetDataV3.deleteAttr(key);
|
|
1340
1343
|
}
|
|
1341
1344
|
}
|
|
1342
1345
|
catch (e_18_1) { e_18 = { error: e_18_1 }; }
|
|
@@ -1365,7 +1368,7 @@ var addSheetDataPatchesV3 = function (ySheetDataV3, patches) {
|
|
|
1365
1368
|
if (cellData) {
|
|
1366
1369
|
var colIdx = Number(colIndexStr);
|
|
1367
1370
|
var key = (0, exports.createCellKeyV3)(sheetId_3, rowIdx, colIdx);
|
|
1368
|
-
ySheetDataV3.
|
|
1371
|
+
ySheetDataV3.setAttr(key, (0, exports.createCellDataV3)(cellData, sheetId_3, rowIdx, colIdx));
|
|
1369
1372
|
trackCellKeySet(sheetId_3, rowIdx, key);
|
|
1370
1373
|
}
|
|
1371
1374
|
});
|
|
@@ -1387,11 +1390,11 @@ var addSheetDataPatchesV3 = function (ySheetDataV3, patches) {
|
|
|
1387
1390
|
var colIdx = Number(columnIndex);
|
|
1388
1391
|
var key = (0, exports.createCellKeyV3)(sheetId, rowIdx, colIdx);
|
|
1389
1392
|
// Get existing cell data or create empty
|
|
1390
|
-
var existing = ySheetDataV3.
|
|
1393
|
+
var existing = ySheetDataV3.getAttr(key);
|
|
1391
1394
|
var cellData = (existing === null || existing === void 0 ? void 0 : existing.value) ? (0, cloneDeep_1.default)(existing.value) : {};
|
|
1392
1395
|
// Apply nested property change
|
|
1393
1396
|
(0, set_1.default)(cellData, nestedPath, value);
|
|
1394
|
-
ySheetDataV3.
|
|
1397
|
+
ySheetDataV3.setAttr(key, (0, exports.createCellDataV3)(cellData, sheetId, rowIdx, colIdx));
|
|
1395
1398
|
trackCellKeySet(sheetId, rowIdx, key);
|
|
1396
1399
|
}
|
|
1397
1400
|
// [sheetId, rowIndex, 'values'] - Replace values array
|
|
@@ -1405,7 +1408,7 @@ var addSheetDataPatchesV3 = function (ySheetDataV3, patches) {
|
|
|
1405
1408
|
value.forEach(function (cellData, colIndex) {
|
|
1406
1409
|
if (cellData) {
|
|
1407
1410
|
var key = (0, exports.createCellKeyV3)(sheetId, rowIdx_1, colIndex);
|
|
1408
|
-
ySheetDataV3.
|
|
1411
|
+
ySheetDataV3.setAttr(key, (0, exports.createCellDataV3)(cellData, sheetId, rowIdx_1, colIndex));
|
|
1409
1412
|
trackCellKeySet(sheetId, rowIdx_1, key);
|
|
1410
1413
|
}
|
|
1411
1414
|
});
|
|
@@ -1424,7 +1427,7 @@ var addSheetDataPatchesV3 = function (ySheetDataV3, patches) {
|
|
|
1424
1427
|
if (cellData) {
|
|
1425
1428
|
var colIndex = Number(colIndexStr);
|
|
1426
1429
|
var key = (0, exports.createCellKeyV3)(sheetId, rowIdx_2, colIndex);
|
|
1427
|
-
ySheetDataV3.
|
|
1430
|
+
ySheetDataV3.setAttr(key, (0, exports.createCellDataV3)(cellData, sheetId, rowIdx_2, colIndex));
|
|
1428
1431
|
trackCellKeySet(sheetId, rowIdx_2, key);
|
|
1429
1432
|
}
|
|
1430
1433
|
});
|
|
@@ -1435,10 +1438,10 @@ var addSheetDataPatchesV3 = function (ySheetDataV3, patches) {
|
|
|
1435
1438
|
// Delete all cells for this sheet
|
|
1436
1439
|
var prefix = "".concat(sheetId, "!");
|
|
1437
1440
|
try {
|
|
1438
|
-
for (var _l = tslib_1.__values(ySheetDataV3.
|
|
1441
|
+
for (var _l = tslib_1.__values(ySheetDataV3.attrKeys()), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
1439
1442
|
var key = _m.value;
|
|
1440
1443
|
if (key.startsWith(prefix)) {
|
|
1441
|
-
ySheetDataV3.
|
|
1444
|
+
ySheetDataV3.deleteAttr(key);
|
|
1442
1445
|
}
|
|
1443
1446
|
}
|
|
1444
1447
|
}
|
|
@@ -1461,7 +1464,7 @@ var addSheetDataPatchesV3 = function (ySheetDataV3, patches) {
|
|
|
1461
1464
|
if (cellData) {
|
|
1462
1465
|
var colIndex = Number(colIndexStr);
|
|
1463
1466
|
var key = (0, exports.createCellKeyV3)(sheetId, rowIdx_3, colIndex);
|
|
1464
|
-
ySheetDataV3.
|
|
1467
|
+
ySheetDataV3.setAttr(key, (0, exports.createCellDataV3)(cellData, sheetId, rowIdx_3, colIndex));
|
|
1465
1468
|
trackCellKeySet(sheetId, rowIdx_3, key);
|
|
1466
1469
|
}
|
|
1467
1470
|
});
|
|
@@ -1478,11 +1481,11 @@ var addSheetDataPatchesV3 = function (ySheetDataV3, patches) {
|
|
|
1478
1481
|
var rowIdx = Number(rowIndex);
|
|
1479
1482
|
var colIdx = Number(columnIndex);
|
|
1480
1483
|
var key = (0, exports.createCellKeyV3)(sheetId, rowIdx, colIdx);
|
|
1481
|
-
var existing = ySheetDataV3.
|
|
1484
|
+
var existing = ySheetDataV3.getAttr(key);
|
|
1482
1485
|
if ((existing === null || existing === void 0 ? void 0 : existing.value) && typeof existing.value === "object") {
|
|
1483
1486
|
var cellData = (0, cloneDeep_1.default)(existing.value);
|
|
1484
1487
|
(0, unset_1.default)(cellData, nestedPath);
|
|
1485
|
-
ySheetDataV3.
|
|
1488
|
+
ySheetDataV3.setAttr(key, (0, exports.createCellDataV3)(cellData, sheetId, rowIdx, colIdx));
|
|
1486
1489
|
trackCellKeySet(sheetId, rowIdx, key);
|
|
1487
1490
|
}
|
|
1488
1491
|
}
|
|
@@ -1496,10 +1499,10 @@ var addSheetDataPatchesV3 = function (ySheetDataV3, patches) {
|
|
|
1496
1499
|
else if (path.length === 1) {
|
|
1497
1500
|
var prefix = "".concat(sheetId, "!");
|
|
1498
1501
|
try {
|
|
1499
|
-
for (var _q = tslib_1.__values(ySheetDataV3.
|
|
1502
|
+
for (var _q = tslib_1.__values(ySheetDataV3.attrKeys()), _r = _q.next(); !_r.done; _r = _q.next()) {
|
|
1500
1503
|
var key = _r.value;
|
|
1501
1504
|
if (key.startsWith(prefix)) {
|
|
1502
|
-
ySheetDataV3.
|
|
1505
|
+
ySheetDataV3.deleteAttr(key);
|
|
1503
1506
|
}
|
|
1504
1507
|
}
|
|
1505
1508
|
}
|
|
@@ -1553,7 +1556,7 @@ exports.addSheetDataPatchesV3 = addSheetDataPatchesV3;
|
|
|
1553
1556
|
* Process V3 events and return updated sheet data
|
|
1554
1557
|
* @param changedKeys - Pre-extracted changes from Yjs event
|
|
1555
1558
|
* @param currentSheetData - Current sheet data state
|
|
1556
|
-
* @param ySheetDataV3 - The
|
|
1559
|
+
* @param ySheetDataV3 - The map node for V3 data
|
|
1557
1560
|
*/
|
|
1558
1561
|
var processSheetDataEventsV3 = function (changedKeys, currentSheetData, ySheetDataV3) {
|
|
1559
1562
|
if (changedKeys.size === 0)
|
|
@@ -1601,7 +1604,7 @@ var processSheetDataEventsV3 = function (changedKeys, currentSheetData, ySheetDa
|
|
|
1601
1604
|
}
|
|
1602
1605
|
else {
|
|
1603
1606
|
// Cell was added or updated
|
|
1604
|
-
var cellDataV3 = ySheetDataV3.
|
|
1607
|
+
var cellDataV3 = ySheetDataV3.getAttr(cellKey);
|
|
1605
1608
|
if (cellDataV3) {
|
|
1606
1609
|
// Ensure row exists
|
|
1607
1610
|
if (!sheet[rowIdx]) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Patch } from "immer";
|
|
2
2
|
import { Observable } from "rxjs";
|
|
3
|
-
import type
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
export declare const createSheetDataObservable: (ySheetData:
|
|
7
|
-
export declare const getPatchDeltasFromEvent: <S extends PatchCoordinate | Patch, T extends PatchDocument<S>>(event:
|
|
8
|
-
export declare const createObservable:
|
|
9
|
-
export declare const createDeepObservable: (yArr:
|
|
3
|
+
import type { PatchCoordinate, PatchDocument, YEvent, YjsRuntime, YNode } from "./types";
|
|
4
|
+
import { type YDeepEvent } from "./ynodes";
|
|
5
|
+
export type { YDeepEvent } from "./ynodes";
|
|
6
|
+
export declare const createSheetDataObservable: (ySheetData: YNode, yjsRuntime?: YjsRuntime) => Observable<YDeepEvent[]>;
|
|
7
|
+
export declare const getPatchDeltasFromEvent: <S extends PatchCoordinate | Patch, T extends PatchDocument<S>>(event: YEvent) => S[];
|
|
8
|
+
export declare const createObservable: (yArr: YNode) => Observable<YEvent>;
|
|
9
|
+
export declare const createDeepObservable: (yArr: YNode, yjsRuntime?: YjsRuntime) => Observable<YDeepEvent[]>;
|
|
10
10
|
//# sourceMappingURL=observables.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observables.d.ts","sourceRoot":"","sources":["../../observables.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"observables.d.ts","sourceRoot":"","sources":["../../observables.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACb,MAAM,EACN,UAAU,EACV,KAAK,EAEN,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAkC,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3E,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAwB3C,eAAO,MAAM,yBAAyB,GACpC,YAAY,KAAK,EACjB,aAAa,UAAU,6BACqB,CAAC;AAE/C,eAAO,MAAM,uBAAuB,GAClC,CAAC,SAAS,eAAe,GAAG,KAAK,EACjC,CAAC,SAAS,aAAa,CAAC,CAAC,CAAC,EAE1B,OAAO,MAAM,QAWd,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,MAAM,KAAK,uBAY3C,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,MAAM,KAAK,EAAE,aAAa,UAAU,6BACpC,CAAC"}
|
package/dist/cjs/observables.js
CHANGED
|
@@ -3,60 +3,56 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createDeepObservable = exports.createObservable = exports.getPatchDeltasFromEvent = exports.createSheetDataObservable = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var rxjs_1 = require("rxjs");
|
|
6
|
-
var
|
|
6
|
+
var yjs_runtime_1 = require("./yjs-runtime");
|
|
7
|
+
var ynodes_1 = require("./ynodes");
|
|
8
|
+
/**
|
|
9
|
+
* Every transaction's changes at or below `node`, as Yjs 13's `observeDeep`
|
|
10
|
+
* delivered them: one entry per changed node still in the document, with its
|
|
11
|
+
* path from `node`, top level first (see `liveDeepEvents`). A transaction
|
|
12
|
+
* whose changes all fell inside deleted nodes emits nothing.
|
|
13
|
+
*/
|
|
14
|
+
var observeDeepEvents = function (node, yjsRuntime) {
|
|
15
|
+
var yjs = (0, yjs_runtime_1.resolveYjsRuntime)(yjsRuntime);
|
|
7
16
|
return new rxjs_1.Observable(function (observer) {
|
|
8
|
-
var callback = function (
|
|
9
|
-
|
|
17
|
+
var callback = function (_event, transaction) {
|
|
18
|
+
var events = (0, ynodes_1.liveDeepEvents)(node, transaction, yjs);
|
|
19
|
+
if (events.length)
|
|
20
|
+
observer.next(events);
|
|
10
21
|
};
|
|
11
|
-
|
|
22
|
+
node.observeDeep(callback);
|
|
12
23
|
return function () {
|
|
13
|
-
|
|
24
|
+
node.unobserveDeep(callback);
|
|
14
25
|
};
|
|
15
26
|
});
|
|
16
27
|
};
|
|
28
|
+
var createSheetDataObservable = function (ySheetData, yjsRuntime) { return observeDeepEvents(ySheetData, yjsRuntime); };
|
|
17
29
|
exports.createSheetDataObservable = createSheetDataObservable;
|
|
18
30
|
var getPatchDeltasFromEvent = function (event) {
|
|
19
|
-
var e_1, _a, e_2, _b
|
|
31
|
+
var e_1, _a, e_2, _b;
|
|
20
32
|
var patches = [];
|
|
21
33
|
if (event.transaction.origin !== "local") {
|
|
22
34
|
try {
|
|
23
|
-
for (var
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var userPatches = _g.value.patches;
|
|
30
|
-
try {
|
|
31
|
-
for (var _h = (e_3 = void 0, tslib_1.__values(userPatches)), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
32
|
-
var patch = _j.value;
|
|
33
|
-
patches.push(patch);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
37
|
-
finally {
|
|
38
|
-
try {
|
|
39
|
-
if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
|
|
40
|
-
}
|
|
41
|
-
finally { if (e_3) throw e_3.error; }
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
46
|
-
finally {
|
|
47
|
-
try {
|
|
48
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
49
|
-
}
|
|
50
|
-
finally { if (e_2) throw e_2.error; }
|
|
51
|
-
}
|
|
35
|
+
for (var _c = tslib_1.__values((0, ynodes_1.insertedValues)(event)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
36
|
+
var userPatches = _d.value.patches;
|
|
37
|
+
try {
|
|
38
|
+
for (var _e = (e_2 = void 0, tslib_1.__values(userPatches)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
39
|
+
var patch = _f.value;
|
|
40
|
+
patches.push(patch);
|
|
52
41
|
}
|
|
53
42
|
}
|
|
43
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
44
|
+
finally {
|
|
45
|
+
try {
|
|
46
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
47
|
+
}
|
|
48
|
+
finally { if (e_2) throw e_2.error; }
|
|
49
|
+
}
|
|
54
50
|
}
|
|
55
51
|
}
|
|
56
52
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
57
53
|
finally {
|
|
58
54
|
try {
|
|
59
|
-
if (
|
|
55
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
60
56
|
}
|
|
61
57
|
finally { if (e_1) throw e_1.error; }
|
|
62
58
|
}
|
|
@@ -76,15 +72,7 @@ var createObservable = function (yArr) {
|
|
|
76
72
|
});
|
|
77
73
|
};
|
|
78
74
|
exports.createObservable = createObservable;
|
|
79
|
-
var createDeepObservable = function (yArr) {
|
|
80
|
-
return
|
|
81
|
-
var callback = function (event) {
|
|
82
|
-
observer.next(event);
|
|
83
|
-
};
|
|
84
|
-
yArr.observeDeep(callback);
|
|
85
|
-
return function () {
|
|
86
|
-
yArr.unobserveDeep(callback);
|
|
87
|
-
};
|
|
88
|
-
});
|
|
75
|
+
var createDeepObservable = function (yArr, yjsRuntime) {
|
|
76
|
+
return observeDeepEvents(yArr, yjsRuntime);
|
|
89
77
|
};
|
|
90
78
|
exports.createDeepObservable = createDeepObservable;
|