@liveblocks/client 0.15.11 → 0.16.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 +2 -0
- package/lib/esm/index.js +155 -77
- package/lib/esm/index.mjs +155 -77
- package/lib/index.d.ts +194 -154
- package/lib/index.js +221 -123
- package/lib/internal.d.ts +29 -13
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -469,7 +469,7 @@ var LiveRegister = function (_AbstractCrdt) {
|
|
|
469
469
|
return _this;
|
|
470
470
|
}
|
|
471
471
|
|
|
472
|
-
LiveRegister._deserialize = function _deserialize(_ref,
|
|
472
|
+
LiveRegister._deserialize = function _deserialize(_ref, _parentToChildren, doc) {
|
|
473
473
|
var id = _ref[0],
|
|
474
474
|
item = _ref[1];
|
|
475
475
|
|
|
@@ -486,7 +486,7 @@ var LiveRegister = function (_AbstractCrdt) {
|
|
|
486
486
|
|
|
487
487
|
var _proto = LiveRegister.prototype;
|
|
488
488
|
|
|
489
|
-
_proto._serialize = function _serialize(parentId, parentKey, doc) {
|
|
489
|
+
_proto._serialize = function _serialize(parentId, parentKey, doc, intent) {
|
|
490
490
|
if (this._id == null || parentId == null || parentKey == null) {
|
|
491
491
|
throw new Error("Cannot serialize register if parentId or parentKey is undefined");
|
|
492
492
|
}
|
|
@@ -495,6 +495,7 @@ var LiveRegister = function (_AbstractCrdt) {
|
|
|
495
495
|
type: OpType.CreateRegister,
|
|
496
496
|
opId: doc == null ? void 0 : doc.generateOpId(),
|
|
497
497
|
id: this._id,
|
|
498
|
+
intent: intent,
|
|
498
499
|
parentId: parentId,
|
|
499
500
|
parentKey: parentKey,
|
|
500
501
|
data: this.data
|
|
@@ -512,7 +513,7 @@ var LiveRegister = function (_AbstractCrdt) {
|
|
|
512
513
|
};
|
|
513
514
|
};
|
|
514
515
|
|
|
515
|
-
_proto._attachChild = function _attachChild(
|
|
516
|
+
_proto._attachChild = function _attachChild(_op, _isLocal) {
|
|
516
517
|
throw new Error("Method not implemented.");
|
|
517
518
|
};
|
|
518
519
|
|
|
@@ -591,7 +592,7 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
591
592
|
|
|
592
593
|
var _proto = LiveList.prototype;
|
|
593
594
|
|
|
594
|
-
_proto._serialize = function _serialize(parentId, parentKey, doc) {
|
|
595
|
+
_proto._serialize = function _serialize(parentId, parentKey, doc, intent) {
|
|
595
596
|
if (this._id == null) {
|
|
596
597
|
throw new Error("Cannot serialize item is not attached");
|
|
597
598
|
}
|
|
@@ -604,6 +605,7 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
604
605
|
var op = {
|
|
605
606
|
id: this._id,
|
|
606
607
|
opId: doc == null ? void 0 : doc.generateOpId(),
|
|
608
|
+
intent: intent,
|
|
607
609
|
type: OpType.CreateList,
|
|
608
610
|
parentId: parentId,
|
|
609
611
|
parentKey: parentKey
|
|
@@ -648,11 +650,17 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
648
650
|
}
|
|
649
651
|
};
|
|
650
652
|
|
|
651
|
-
_proto._attachChild = function _attachChild(
|
|
653
|
+
_proto._attachChild = function _attachChild(op, isLocal) {
|
|
652
654
|
if (this._doc == null) {
|
|
653
655
|
throw new Error("Can't attach child if doc is not present");
|
|
654
656
|
}
|
|
655
657
|
|
|
658
|
+
var id = op.id,
|
|
659
|
+
parentKey = op.parentKey,
|
|
660
|
+
intent = op.intent;
|
|
661
|
+
var key = parentKey;
|
|
662
|
+
var child = creationOpToLiveStructure(op);
|
|
663
|
+
|
|
656
664
|
if (this._doc.getItem(id) !== undefined) {
|
|
657
665
|
return {
|
|
658
666
|
modified: false
|
|
@@ -670,7 +678,26 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
670
678
|
var newKey = key;
|
|
671
679
|
|
|
672
680
|
if (index !== -1) {
|
|
673
|
-
if (
|
|
681
|
+
if (intent === "set") {
|
|
682
|
+
var existingItem = this._items[index][0];
|
|
683
|
+
|
|
684
|
+
existingItem._detach();
|
|
685
|
+
|
|
686
|
+
var storageUpdate = {
|
|
687
|
+
node: this,
|
|
688
|
+
type: "LiveList",
|
|
689
|
+
updates: [{
|
|
690
|
+
index: index,
|
|
691
|
+
type: "set",
|
|
692
|
+
item: child instanceof LiveRegister ? child.data : child
|
|
693
|
+
}]
|
|
694
|
+
};
|
|
695
|
+
this._items[index][0] = child;
|
|
696
|
+
return {
|
|
697
|
+
modified: storageUpdate,
|
|
698
|
+
reverse: existingItem._serialize(this._id, key, this._doc, "set")
|
|
699
|
+
};
|
|
700
|
+
} else if (isLocal) {
|
|
674
701
|
var before = this._items[index] ? this._items[index][1] : undefined;
|
|
675
702
|
var after = this._items[index + 1] ? this._items[index + 1][1] : undefined;
|
|
676
703
|
newKey = makePosition(before, after);
|
|
@@ -1009,6 +1036,43 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
1009
1036
|
}
|
|
1010
1037
|
};
|
|
1011
1038
|
|
|
1039
|
+
_proto.set = function set(index, item) {
|
|
1040
|
+
if (index < 0 || index >= this._items.length) {
|
|
1041
|
+
throw new Error("Cannot set list item at index \"\x1D" + index + "\". index should be between 0 and " + (this._items.length - 1));
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
var _this$_items$index = this._items[index],
|
|
1045
|
+
existingItem = _this$_items$index[0],
|
|
1046
|
+
position = _this$_items$index[1];
|
|
1047
|
+
|
|
1048
|
+
existingItem._detach();
|
|
1049
|
+
|
|
1050
|
+
var value = selfOrRegister(item);
|
|
1051
|
+
|
|
1052
|
+
value._setParentLink(this, position);
|
|
1053
|
+
|
|
1054
|
+
this._items[index][0] = value;
|
|
1055
|
+
|
|
1056
|
+
if (this._doc && this._id) {
|
|
1057
|
+
var _id2 = this._doc.generateId();
|
|
1058
|
+
|
|
1059
|
+
value._attach(_id2, this._doc);
|
|
1060
|
+
|
|
1061
|
+
var storageUpdates = new Map();
|
|
1062
|
+
storageUpdates.set(this._id, {
|
|
1063
|
+
node: this,
|
|
1064
|
+
type: "LiveList",
|
|
1065
|
+
updates: [{
|
|
1066
|
+
index: index,
|
|
1067
|
+
item: value instanceof LiveRegister ? value.data : value,
|
|
1068
|
+
type: "set"
|
|
1069
|
+
}]
|
|
1070
|
+
});
|
|
1071
|
+
|
|
1072
|
+
this._doc.dispatch(value._serialize(this._id, position, this._doc, "set"), existingItem._serialize(this._id, position, undefined, "set"), storageUpdates);
|
|
1073
|
+
}
|
|
1074
|
+
};
|
|
1075
|
+
|
|
1012
1076
|
_proto.toArray = function toArray() {
|
|
1013
1077
|
return this._items.map(function (entry) {
|
|
1014
1078
|
return selfOrRegisterValue(entry[0]);
|
|
@@ -1135,7 +1199,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1135
1199
|
|
|
1136
1200
|
var _proto = LiveMap.prototype;
|
|
1137
1201
|
|
|
1138
|
-
_proto._serialize = function _serialize(parentId, parentKey, doc) {
|
|
1202
|
+
_proto._serialize = function _serialize(parentId, parentKey, doc, intent) {
|
|
1139
1203
|
if (this._id == null) {
|
|
1140
1204
|
throw new Error("Cannot serialize item is not attached");
|
|
1141
1205
|
}
|
|
@@ -1149,6 +1213,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1149
1213
|
id: this._id,
|
|
1150
1214
|
opId: doc == null ? void 0 : doc.generateOpId(),
|
|
1151
1215
|
type: OpType.CreateMap,
|
|
1216
|
+
intent: intent,
|
|
1152
1217
|
parentId: parentId,
|
|
1153
1218
|
parentKey: parentKey
|
|
1154
1219
|
};
|
|
@@ -1214,13 +1279,18 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1214
1279
|
}
|
|
1215
1280
|
};
|
|
1216
1281
|
|
|
1217
|
-
_proto._attachChild = function _attachChild(
|
|
1282
|
+
_proto._attachChild = function _attachChild(op, _isLocal) {
|
|
1218
1283
|
var _updates;
|
|
1219
1284
|
|
|
1220
1285
|
if (this._doc == null) {
|
|
1221
1286
|
throw new Error("Can't attach child if doc is not present");
|
|
1222
1287
|
}
|
|
1223
1288
|
|
|
1289
|
+
var id = op.id,
|
|
1290
|
+
parentKey = op.parentKey;
|
|
1291
|
+
var key = parentKey;
|
|
1292
|
+
var child = creationOpToLiveStructure(op);
|
|
1293
|
+
|
|
1224
1294
|
if (this._doc.getItem(id) !== undefined) {
|
|
1225
1295
|
return {
|
|
1226
1296
|
modified: false
|
|
@@ -1473,6 +1543,21 @@ function remove(array, item) {
|
|
|
1473
1543
|
}
|
|
1474
1544
|
}
|
|
1475
1545
|
}
|
|
1546
|
+
function creationOpToLiveStructure(op) {
|
|
1547
|
+
switch (op.type) {
|
|
1548
|
+
case OpType.CreateRegister:
|
|
1549
|
+
return new LiveRegister(op.data);
|
|
1550
|
+
|
|
1551
|
+
case OpType.CreateObject:
|
|
1552
|
+
return new LiveObject(op.data);
|
|
1553
|
+
|
|
1554
|
+
case OpType.CreateMap:
|
|
1555
|
+
return new LiveMap();
|
|
1556
|
+
|
|
1557
|
+
case OpType.CreateList:
|
|
1558
|
+
return new LiveList();
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1476
1561
|
function isSameNodeOrChildOf(node, parent) {
|
|
1477
1562
|
if (node === parent) {
|
|
1478
1563
|
return true;
|
|
@@ -1606,44 +1691,57 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
1606
1691
|
});
|
|
1607
1692
|
return ops;
|
|
1608
1693
|
}
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1694
|
+
|
|
1695
|
+
function mergeObjectStorageUpdates(first, second) {
|
|
1696
|
+
var updates = first.updates;
|
|
1697
|
+
|
|
1698
|
+
for (var _iterator = _createForOfIteratorHelperLoose(entries(second.updates)), _step; !(_step = _iterator()).done;) {
|
|
1699
|
+
var _step$value = _step.value,
|
|
1700
|
+
_key = _step$value[0],
|
|
1701
|
+
value = _step$value[1];
|
|
1702
|
+
updates[_key] = value;
|
|
1612
1703
|
}
|
|
1613
1704
|
|
|
1614
|
-
|
|
1615
|
-
|
|
1705
|
+
return _extends({}, second, {
|
|
1706
|
+
updates: updates
|
|
1707
|
+
});
|
|
1708
|
+
}
|
|
1616
1709
|
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
key = _Object$entries$_i[0],
|
|
1620
|
-
value = _Object$entries$_i[1];
|
|
1621
|
-
updates[key] = value;
|
|
1622
|
-
}
|
|
1710
|
+
function mergeMapStorageUpdates(first, second) {
|
|
1711
|
+
var updates = first.updates;
|
|
1623
1712
|
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1713
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(entries(second.updates)), _step2; !(_step2 = _iterator2()).done;) {
|
|
1714
|
+
var _step2$value = _step2.value,
|
|
1715
|
+
_key2 = _step2$value[0],
|
|
1716
|
+
value = _step2$value[1];
|
|
1717
|
+
updates[_key2] = value;
|
|
1718
|
+
}
|
|
1629
1719
|
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
_updates[_key] = _value;
|
|
1635
|
-
}
|
|
1720
|
+
return _extends({}, second, {
|
|
1721
|
+
updates: updates
|
|
1722
|
+
});
|
|
1723
|
+
}
|
|
1636
1724
|
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1725
|
+
function mergeListStorageUpdates(first, second) {
|
|
1726
|
+
var updates = first.updates;
|
|
1727
|
+
return _extends({}, second, {
|
|
1728
|
+
updates: updates.concat(second.updates)
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
function mergeStorageUpdates(first, second) {
|
|
1733
|
+
if (!first) {
|
|
1734
|
+
return second;
|
|
1645
1735
|
}
|
|
1646
1736
|
|
|
1737
|
+
if (first.type === "LiveObject" && second.type === "LiveObject") {
|
|
1738
|
+
return mergeObjectStorageUpdates(first, second);
|
|
1739
|
+
} else if (first.type === "LiveMap" && second.type === "LiveMap") {
|
|
1740
|
+
return mergeMapStorageUpdates(first, second);
|
|
1741
|
+
} else if (first.type === "LiveList" && second.type === "LiveList") {
|
|
1742
|
+
return mergeListStorageUpdates(first, second);
|
|
1743
|
+
} else ;
|
|
1744
|
+
|
|
1647
1745
|
return second;
|
|
1648
1746
|
}
|
|
1649
1747
|
|
|
@@ -1681,11 +1779,11 @@ function findNonSerializableValue(value, path) {
|
|
|
1681
1779
|
return false;
|
|
1682
1780
|
}
|
|
1683
1781
|
|
|
1684
|
-
for (var
|
|
1685
|
-
var _Object$
|
|
1686
|
-
|
|
1687
|
-
nestedValue = _Object$
|
|
1688
|
-
var nestedPath = path ? path + "." +
|
|
1782
|
+
for (var _i = 0, _Object$entries = Object.entries(value); _i < _Object$entries.length; _i++) {
|
|
1783
|
+
var _Object$entries$_i = _Object$entries[_i],
|
|
1784
|
+
_key3 = _Object$entries$_i[0],
|
|
1785
|
+
nestedValue = _Object$entries$_i[1];
|
|
1786
|
+
var nestedPath = path ? path + "." + _key3 : _key3;
|
|
1689
1787
|
|
|
1690
1788
|
if (!isPlain(nestedValue)) {
|
|
1691
1789
|
return {
|
|
@@ -1730,6 +1828,9 @@ function isTokenValid(token) {
|
|
|
1730
1828
|
|
|
1731
1829
|
return true;
|
|
1732
1830
|
}
|
|
1831
|
+
function entries(obj) {
|
|
1832
|
+
return Object.entries(obj);
|
|
1833
|
+
}
|
|
1733
1834
|
|
|
1734
1835
|
var LiveObject = function (_AbstractCrdt) {
|
|
1735
1836
|
_inheritsLoose(LiveObject, _AbstractCrdt);
|
|
@@ -1758,7 +1859,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
1758
1859
|
|
|
1759
1860
|
var _proto = LiveObject.prototype;
|
|
1760
1861
|
|
|
1761
|
-
_proto._serialize = function _serialize(parentId, parentKey, doc) {
|
|
1862
|
+
_proto._serialize = function _serialize(parentId, parentKey, doc, intent) {
|
|
1762
1863
|
if (this._id == null) {
|
|
1763
1864
|
throw new Error("Cannot serialize item is not attached");
|
|
1764
1865
|
}
|
|
@@ -1767,6 +1868,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
1767
1868
|
var op = {
|
|
1768
1869
|
id: this._id,
|
|
1769
1870
|
opId: doc == null ? void 0 : doc.generateOpId(),
|
|
1871
|
+
intent: intent,
|
|
1770
1872
|
type: OpType.CreateObject,
|
|
1771
1873
|
parentId: parentId,
|
|
1772
1874
|
parentKey: parentKey,
|
|
@@ -1843,13 +1945,19 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
1843
1945
|
}
|
|
1844
1946
|
};
|
|
1845
1947
|
|
|
1846
|
-
_proto._attachChild = function _attachChild(
|
|
1948
|
+
_proto._attachChild = function _attachChild(op, isLocal) {
|
|
1847
1949
|
var _updates;
|
|
1848
1950
|
|
|
1849
1951
|
if (this._doc == null) {
|
|
1850
1952
|
throw new Error("Can't attach child if doc is not present");
|
|
1851
1953
|
}
|
|
1852
1954
|
|
|
1955
|
+
var id = op.id,
|
|
1956
|
+
parentKey = op.parentKey,
|
|
1957
|
+
opId = op.opId;
|
|
1958
|
+
var key = parentKey;
|
|
1959
|
+
var child = creationOpToLiveStructure(op);
|
|
1960
|
+
|
|
1853
1961
|
if (this._doc.getItem(id) !== undefined) {
|
|
1854
1962
|
if (this._propToLastUpdate.get(key) === opId) {
|
|
1855
1963
|
this._propToLastUpdate.delete(key);
|
|
@@ -2435,9 +2543,9 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2435
2543
|
state.root = load(message.items);
|
|
2436
2544
|
}
|
|
2437
2545
|
|
|
2438
|
-
for (var
|
|
2439
|
-
if (state.root.get(
|
|
2440
|
-
state.root.set(
|
|
2546
|
+
for (var _key in state.defaultStorageRoot) {
|
|
2547
|
+
if (state.root.get(_key) == null) {
|
|
2548
|
+
state.root.set(_key, state.defaultStorageRoot[_key]);
|
|
2441
2549
|
}
|
|
2442
2550
|
}
|
|
2443
2551
|
}
|
|
@@ -2621,8 +2729,8 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2621
2729
|
data: {}
|
|
2622
2730
|
};
|
|
2623
2731
|
|
|
2624
|
-
for (var
|
|
2625
|
-
reverse.data[
|
|
2732
|
+
for (var _key2 in op.data) {
|
|
2733
|
+
reverse.data[_key2] = state.me[_key2];
|
|
2626
2734
|
}
|
|
2627
2735
|
|
|
2628
2736
|
state.me = _extends({}, state.me, op.data);
|
|
@@ -2630,8 +2738,8 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2630
2738
|
if (state.buffer.presence == null) {
|
|
2631
2739
|
state.buffer.presence = op.data;
|
|
2632
2740
|
} else {
|
|
2633
|
-
for (var
|
|
2634
|
-
state.buffer.presence[
|
|
2741
|
+
for (var _key3 in op.data) {
|
|
2742
|
+
state.buffer.presence[_key3] = op.data;
|
|
2635
2743
|
}
|
|
2636
2744
|
}
|
|
2637
2745
|
|
|
@@ -2706,55 +2814,19 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2706
2814
|
}
|
|
2707
2815
|
|
|
2708
2816
|
case OpType.CreateObject:
|
|
2709
|
-
{
|
|
2710
|
-
var parent = state.items.get(op.parentId);
|
|
2711
|
-
|
|
2712
|
-
if (parent == null) {
|
|
2713
|
-
return {
|
|
2714
|
-
modified: false
|
|
2715
|
-
};
|
|
2716
|
-
}
|
|
2717
|
-
|
|
2718
|
-
return parent._attachChild(op.id, op.parentKey, new LiveObject(op.data), op.opId, isLocal);
|
|
2719
|
-
}
|
|
2720
|
-
|
|
2721
2817
|
case OpType.CreateList:
|
|
2722
|
-
{
|
|
2723
|
-
var _parent = state.items.get(op.parentId);
|
|
2724
|
-
|
|
2725
|
-
if (_parent == null) {
|
|
2726
|
-
return {
|
|
2727
|
-
modified: false
|
|
2728
|
-
};
|
|
2729
|
-
}
|
|
2730
|
-
|
|
2731
|
-
return _parent._attachChild(op.id, op.parentKey, new LiveList(), op.opId, isLocal);
|
|
2732
|
-
}
|
|
2733
|
-
|
|
2734
|
-
case OpType.CreateRegister:
|
|
2735
|
-
{
|
|
2736
|
-
var _parent2 = state.items.get(op.parentId);
|
|
2737
|
-
|
|
2738
|
-
if (_parent2 == null) {
|
|
2739
|
-
return {
|
|
2740
|
-
modified: false
|
|
2741
|
-
};
|
|
2742
|
-
}
|
|
2743
|
-
|
|
2744
|
-
return _parent2._attachChild(op.id, op.parentKey, new LiveRegister(op.data), op.opId, isLocal);
|
|
2745
|
-
}
|
|
2746
|
-
|
|
2747
2818
|
case OpType.CreateMap:
|
|
2819
|
+
case OpType.CreateRegister:
|
|
2748
2820
|
{
|
|
2749
|
-
var
|
|
2821
|
+
var parent = state.items.get(op.parentId);
|
|
2750
2822
|
|
|
2751
|
-
if (
|
|
2823
|
+
if (parent == null) {
|
|
2752
2824
|
return {
|
|
2753
2825
|
modified: false
|
|
2754
2826
|
};
|
|
2755
2827
|
}
|
|
2756
2828
|
|
|
2757
|
-
return
|
|
2829
|
+
return parent._attachChild(op, isLocal);
|
|
2758
2830
|
}
|
|
2759
2831
|
}
|
|
2760
2832
|
|
|
@@ -2823,9 +2895,9 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2823
2895
|
state.buffer.presence = {};
|
|
2824
2896
|
}
|
|
2825
2897
|
|
|
2826
|
-
for (var
|
|
2827
|
-
state.buffer.presence[
|
|
2828
|
-
oldValues[
|
|
2898
|
+
for (var _key4 in overrides) {
|
|
2899
|
+
state.buffer.presence[_key4] = overrides[_key4];
|
|
2900
|
+
oldValues[_key4] = state.me[_key4];
|
|
2829
2901
|
}
|
|
2830
2902
|
|
|
2831
2903
|
state.me = _extends({}, state.me, overrides);
|
|
@@ -2937,10 +3009,10 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2937
3009
|
function onRoomStateMessage(message) {
|
|
2938
3010
|
var newUsers = {};
|
|
2939
3011
|
|
|
2940
|
-
for (var
|
|
2941
|
-
var _connectionId = Number.parseInt(
|
|
3012
|
+
for (var _key5 in message.users) {
|
|
3013
|
+
var _connectionId = Number.parseInt(_key5);
|
|
2942
3014
|
|
|
2943
|
-
var user = message.users[
|
|
3015
|
+
var user = message.users[_key5];
|
|
2944
3016
|
newUsers[_connectionId] = {
|
|
2945
3017
|
connectionId: _connectionId,
|
|
2946
3018
|
info: user.info,
|
|
@@ -3346,8 +3418,8 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3346
3418
|
}
|
|
3347
3419
|
|
|
3348
3420
|
function clearListeners() {
|
|
3349
|
-
for (var
|
|
3350
|
-
state.listeners[
|
|
3421
|
+
for (var _key6 in state.listeners) {
|
|
3422
|
+
state.listeners[_key6] = [];
|
|
3351
3423
|
}
|
|
3352
3424
|
}
|
|
3353
3425
|
|
|
@@ -3879,33 +3951,42 @@ function prepareAuthentication(clientOptions) {
|
|
|
3879
3951
|
throw new Error("Invalid Liveblocks client options. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClient");
|
|
3880
3952
|
}
|
|
3881
3953
|
|
|
3882
|
-
function
|
|
3954
|
+
function lsonObjectToJson(obj) {
|
|
3883
3955
|
var result = {};
|
|
3884
|
-
var obj = liveObject.toObject();
|
|
3885
3956
|
|
|
3886
3957
|
for (var _key in obj) {
|
|
3887
|
-
result[_key] =
|
|
3958
|
+
result[_key] = lsonToJson(obj[_key]);
|
|
3888
3959
|
}
|
|
3889
3960
|
|
|
3890
3961
|
return result;
|
|
3891
3962
|
}
|
|
3892
3963
|
|
|
3964
|
+
function liveObjectToJson(liveObject) {
|
|
3965
|
+
return lsonObjectToJson(liveObject.toObject());
|
|
3966
|
+
}
|
|
3967
|
+
|
|
3893
3968
|
function liveMapToJson(map) {
|
|
3894
3969
|
var result = {};
|
|
3895
|
-
var obj = Object.fromEntries(map);
|
|
3896
3970
|
|
|
3897
|
-
for (var
|
|
3898
|
-
|
|
3971
|
+
for (var _iterator = _createForOfIteratorHelperLoose(map.entries()), _step; !(_step = _iterator()).done;) {
|
|
3972
|
+
var _step$value = _step.value,
|
|
3973
|
+
_key2 = _step$value[0],
|
|
3974
|
+
value = _step$value[1];
|
|
3975
|
+
result[_key2] = lsonToJson(value);
|
|
3899
3976
|
}
|
|
3900
3977
|
|
|
3901
3978
|
return result;
|
|
3902
3979
|
}
|
|
3903
3980
|
|
|
3981
|
+
function lsonListToJson(value) {
|
|
3982
|
+
return value.map(lsonToJson);
|
|
3983
|
+
}
|
|
3984
|
+
|
|
3904
3985
|
function liveListToJson(value) {
|
|
3905
|
-
return value.toArray()
|
|
3986
|
+
return lsonListToJson(value.toArray());
|
|
3906
3987
|
}
|
|
3907
3988
|
|
|
3908
|
-
function
|
|
3989
|
+
function lsonToJson(value) {
|
|
3909
3990
|
if (value instanceof LiveObject) {
|
|
3910
3991
|
return liveObjectToJson(value);
|
|
3911
3992
|
} else if (value instanceof LiveList) {
|
|
@@ -3914,13 +3995,21 @@ function liveNodeToJson(value) {
|
|
|
3914
3995
|
return liveMapToJson(value);
|
|
3915
3996
|
} else if (value instanceof LiveRegister) {
|
|
3916
3997
|
return value.data;
|
|
3998
|
+
} else if (value instanceof AbstractCrdt) {
|
|
3999
|
+
throw new Error("Unhandled subclass of AbstractCrdt encountered");
|
|
4000
|
+
}
|
|
4001
|
+
|
|
4002
|
+
if (Array.isArray(value)) {
|
|
4003
|
+
return lsonListToJson(value);
|
|
4004
|
+
} else if (isPlainObject(value)) {
|
|
4005
|
+
return lsonObjectToJson(value);
|
|
3917
4006
|
}
|
|
3918
4007
|
|
|
3919
4008
|
return value;
|
|
3920
4009
|
}
|
|
3921
4010
|
|
|
3922
4011
|
function isPlainObject(obj) {
|
|
3923
|
-
return Object.prototype.toString.call(obj) === "[object Object]";
|
|
4012
|
+
return obj !== null && Object.prototype.toString.call(obj) === "[object Object]";
|
|
3924
4013
|
}
|
|
3925
4014
|
|
|
3926
4015
|
function anyToCrdt(obj) {
|
|
@@ -4003,8 +4092,7 @@ function patchLiveList(liveList, prev, next) {
|
|
|
4003
4092
|
if (liveListNode instanceof LiveObject && isPlainObject(prevNode) && isPlainObject(nextNode)) {
|
|
4004
4093
|
patchLiveObject(liveListNode, prevNode, nextNode);
|
|
4005
4094
|
} else {
|
|
4006
|
-
liveList.
|
|
4007
|
-
liveList.insert(anyToCrdt(nextNode), i);
|
|
4095
|
+
liveList.set(i, anyToCrdt(nextNode));
|
|
4008
4096
|
}
|
|
4009
4097
|
|
|
4010
4098
|
i++;
|
|
@@ -4015,9 +4103,11 @@ function patchLiveList(liveList, prev, next) {
|
|
|
4015
4103
|
i++;
|
|
4016
4104
|
}
|
|
4017
4105
|
|
|
4018
|
-
|
|
4106
|
+
var _localI = i;
|
|
4107
|
+
|
|
4108
|
+
while (_localI <= prevEnd) {
|
|
4019
4109
|
liveList.delete(i);
|
|
4020
|
-
|
|
4110
|
+
_localI++;
|
|
4021
4111
|
}
|
|
4022
4112
|
}
|
|
4023
4113
|
}
|
|
@@ -4109,7 +4199,7 @@ function patchImmutableNode(state, path, update) {
|
|
|
4109
4199
|
var _update$updates$_key, _update$updates$_key2;
|
|
4110
4200
|
|
|
4111
4201
|
if (((_update$updates$_key = update.updates[_key6]) == null ? void 0 : _update$updates$_key.type) === "update") {
|
|
4112
|
-
newState[_key6] =
|
|
4202
|
+
newState[_key6] = lsonToJson(update.node.get(_key6));
|
|
4113
4203
|
} else if (((_update$updates$_key2 = update.updates[_key6]) == null ? void 0 : _update$updates$_key2.type) === "delete") {
|
|
4114
4204
|
delete newState[_key6];
|
|
4115
4205
|
}
|
|
@@ -4128,24 +4218,32 @@ function patchImmutableNode(state, path, update) {
|
|
|
4128
4218
|
return x;
|
|
4129
4219
|
});
|
|
4130
4220
|
|
|
4131
|
-
|
|
4132
|
-
var listUpdate =
|
|
4221
|
+
var _loop = function _loop() {
|
|
4222
|
+
var listUpdate = _step2.value;
|
|
4133
4223
|
|
|
4134
|
-
if (listUpdate.type === "
|
|
4224
|
+
if (listUpdate.type === "set") {
|
|
4225
|
+
_newState = _newState.map(function (item, index) {
|
|
4226
|
+
return index === listUpdate.index ? listUpdate.item : item;
|
|
4227
|
+
});
|
|
4228
|
+
} else if (listUpdate.type === "insert") {
|
|
4135
4229
|
if (listUpdate.index === _newState.length) {
|
|
4136
|
-
_newState.push(
|
|
4230
|
+
_newState.push(lsonToJson(listUpdate.item));
|
|
4137
4231
|
} else {
|
|
4138
|
-
_newState = [].concat(_newState.slice(0, listUpdate.index), [
|
|
4232
|
+
_newState = [].concat(_newState.slice(0, listUpdate.index), [lsonToJson(listUpdate.item)], _newState.slice(listUpdate.index));
|
|
4139
4233
|
}
|
|
4140
4234
|
} else if (listUpdate.type === "delete") {
|
|
4141
4235
|
_newState.splice(listUpdate.index, 1);
|
|
4142
4236
|
} else if (listUpdate.type === "move") {
|
|
4143
4237
|
if (listUpdate.previousIndex > listUpdate.index) {
|
|
4144
|
-
_newState = [].concat(_newState.slice(0, listUpdate.index), [
|
|
4238
|
+
_newState = [].concat(_newState.slice(0, listUpdate.index), [lsonToJson(listUpdate.item)], _newState.slice(listUpdate.index, listUpdate.previousIndex), _newState.slice(listUpdate.previousIndex + 1));
|
|
4145
4239
|
} else {
|
|
4146
|
-
_newState = [].concat(_newState.slice(0, listUpdate.previousIndex), _newState.slice(listUpdate.previousIndex + 1, listUpdate.index + 1), [
|
|
4240
|
+
_newState = [].concat(_newState.slice(0, listUpdate.previousIndex), _newState.slice(listUpdate.previousIndex + 1, listUpdate.index + 1), [lsonToJson(listUpdate.item)], _newState.slice(listUpdate.index + 1));
|
|
4147
4241
|
}
|
|
4148
4242
|
}
|
|
4243
|
+
};
|
|
4244
|
+
|
|
4245
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(update.updates), _step2; !(_step2 = _iterator2()).done;) {
|
|
4246
|
+
_loop();
|
|
4149
4247
|
}
|
|
4150
4248
|
|
|
4151
4249
|
return _newState;
|
|
@@ -4163,7 +4261,7 @@ function patchImmutableNode(state, path, update) {
|
|
|
4163
4261
|
var _update$updates$_key3, _update$updates$_key4;
|
|
4164
4262
|
|
|
4165
4263
|
if (((_update$updates$_key3 = update.updates[_key7]) == null ? void 0 : _update$updates$_key3.type) === "update") {
|
|
4166
|
-
_newState2[_key7] =
|
|
4264
|
+
_newState2[_key7] = lsonToJson(update.node.get(_key7));
|
|
4167
4265
|
} else if (((_update$updates$_key4 = update.updates[_key7]) == null ? void 0 : _update$updates$_key4.type) === "delete") {
|
|
4168
4266
|
delete _newState2[_key7];
|
|
4169
4267
|
}
|
|
@@ -4187,7 +4285,7 @@ function patchImmutableNode(state, path, update) {
|
|
|
4187
4285
|
|
|
4188
4286
|
var internals = {
|
|
4189
4287
|
liveObjectToJson: liveObjectToJson,
|
|
4190
|
-
|
|
4288
|
+
lsonToJson: lsonToJson,
|
|
4191
4289
|
patchLiveList: patchLiveList,
|
|
4192
4290
|
patchImmutableObject: patchImmutableObject,
|
|
4193
4291
|
patchLiveObject: patchLiveObject,
|