@liveblocks/core 3.19.4-rc1 → 3.19.4
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/index.cjs +54 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +54 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6,7 +6,7 @@ var __export = (target, all) => {
|
|
|
6
6
|
|
|
7
7
|
// src/version.ts
|
|
8
8
|
var PKG_NAME = "@liveblocks/core";
|
|
9
|
-
var PKG_VERSION = "3.19.4
|
|
9
|
+
var PKG_VERSION = "3.19.4";
|
|
10
10
|
var PKG_FORMAT = "cjs";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -7928,6 +7928,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7928
7928
|
const id = nn(this._id);
|
|
7929
7929
|
const parentKey = nn(child._parentKey);
|
|
7930
7930
|
const reverse = child._toOps(id, parentKey);
|
|
7931
|
+
const deletedItem = liveNodeToLson(child);
|
|
7931
7932
|
for (const [key, value] of this.#synced) {
|
|
7932
7933
|
if (value === child) {
|
|
7933
7934
|
this.#synced.delete(key);
|
|
@@ -7939,7 +7940,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7939
7940
|
node: this,
|
|
7940
7941
|
type: "LiveObject",
|
|
7941
7942
|
updates: {
|
|
7942
|
-
[parentKey]: { type: "delete" }
|
|
7943
|
+
[parentKey]: { type: "delete", deletedItem }
|
|
7943
7944
|
}
|
|
7944
7945
|
};
|
|
7945
7946
|
return { modified: storageUpdate, reverse };
|
|
@@ -8541,6 +8542,35 @@ function dumpPool(pool) {
|
|
|
8541
8542
|
(r) => ` ${r.id} parent=${r.parentId} key=${r.key || "\u2014"} ${r.value}`
|
|
8542
8543
|
).join("\n");
|
|
8543
8544
|
}
|
|
8545
|
+
function isJsonEq(a, b) {
|
|
8546
|
+
if (a === b) {
|
|
8547
|
+
return true;
|
|
8548
|
+
}
|
|
8549
|
+
if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) {
|
|
8550
|
+
return false;
|
|
8551
|
+
}
|
|
8552
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
8553
|
+
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) {
|
|
8554
|
+
return false;
|
|
8555
|
+
}
|
|
8556
|
+
for (let i = 0; i < a.length; i++) {
|
|
8557
|
+
if (!isJsonEq(a[i], b[i])) {
|
|
8558
|
+
return false;
|
|
8559
|
+
}
|
|
8560
|
+
}
|
|
8561
|
+
return true;
|
|
8562
|
+
}
|
|
8563
|
+
const aKeys = Object.keys(a);
|
|
8564
|
+
if (aKeys.length !== Object.keys(b).length) {
|
|
8565
|
+
return false;
|
|
8566
|
+
}
|
|
8567
|
+
for (const key of aKeys) {
|
|
8568
|
+
if (!isJsonEq(a[key], b[key])) {
|
|
8569
|
+
return false;
|
|
8570
|
+
}
|
|
8571
|
+
}
|
|
8572
|
+
return true;
|
|
8573
|
+
}
|
|
8544
8574
|
function getTreesDiffOperations(currentItems, newItems) {
|
|
8545
8575
|
const ops = [];
|
|
8546
8576
|
currentItems.forEach((_, id) => {
|
|
@@ -8552,12 +8582,28 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
8552
8582
|
const currentCrdt = currentItems.get(id);
|
|
8553
8583
|
if (currentCrdt) {
|
|
8554
8584
|
if (crdt.type === CrdtType.OBJECT) {
|
|
8555
|
-
if (currentCrdt.type !== CrdtType.OBJECT
|
|
8556
|
-
ops.push({
|
|
8557
|
-
|
|
8558
|
-
|
|
8559
|
-
|
|
8560
|
-
|
|
8585
|
+
if (currentCrdt.type !== CrdtType.OBJECT) {
|
|
8586
|
+
ops.push({ type: OpCode.UPDATE_OBJECT, id, data: crdt.data });
|
|
8587
|
+
} else {
|
|
8588
|
+
const changed = /* @__PURE__ */ new Map();
|
|
8589
|
+
for (const key of Object.keys(crdt.data)) {
|
|
8590
|
+
const value = crdt.data[key];
|
|
8591
|
+
if (value !== void 0 && !isJsonEq(value, currentCrdt.data[key])) {
|
|
8592
|
+
changed.set(key, value);
|
|
8593
|
+
}
|
|
8594
|
+
}
|
|
8595
|
+
if (changed.size > 0) {
|
|
8596
|
+
ops.push({
|
|
8597
|
+
type: OpCode.UPDATE_OBJECT,
|
|
8598
|
+
id,
|
|
8599
|
+
data: Object.fromEntries(changed)
|
|
8600
|
+
});
|
|
8601
|
+
}
|
|
8602
|
+
for (const key of Object.keys(currentCrdt.data)) {
|
|
8603
|
+
if (!(key in crdt.data)) {
|
|
8604
|
+
ops.push({ type: OpCode.DELETE_OBJECT_KEY, id, key });
|
|
8605
|
+
}
|
|
8606
|
+
}
|
|
8561
8607
|
}
|
|
8562
8608
|
}
|
|
8563
8609
|
if (crdt.parentKey !== currentCrdt.parentKey) {
|