@liveblocks/client 0.18.0-beta0 → 0.18.0-beta3

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/internal.js CHANGED
@@ -1,549 +1,370 @@
1
- "use strict";
2
- function _arrayLikeToArray(arr, len) {
3
- if (len == null || len > arr.length) len = arr.length;
4
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
5
- return arr2;
6
- }
7
- function _arrayWithHoles(arr) {
8
- if (Array.isArray(arr)) return arr;
9
- }
10
- function _arrayWithoutHoles(arr) {
11
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
12
- }
13
- function _defineProperty(obj, key, value) {
14
- if (key in obj) {
15
- Object.defineProperty(obj, key, {
16
- value: value,
17
- enumerable: true,
18
- configurable: true,
19
- writable: true
20
- });
21
- } else {
22
- obj[key] = value;
23
- }
24
- return obj;
25
- }
26
- function _instanceof(left, right) {
27
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
28
- return !!right[Symbol.hasInstance](left);
29
- } else {
30
- return left instanceof right;
31
- }
32
- }
33
- function _iterableToArray(iter) {
34
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
35
- }
36
- function _iterableToArrayLimit(arr, i) {
37
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
38
- if (_i == null) return;
39
- var _arr = [];
40
- var _n = true;
41
- var _d = false;
42
- var _s, _e;
43
- try {
44
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
45
- _arr.push(_s.value);
46
- if (i && _arr.length === i) break;
47
- }
48
- } catch (err) {
49
- _d = true;
50
- _e = err;
51
- } finally{
52
- try {
53
- if (!_n && _i["return"] != null) _i["return"]();
54
- } finally{
55
- if (_d) throw _e;
56
- }
57
- }
58
- return _arr;
59
- }
60
- function _nonIterableRest() {
61
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
62
- }
63
- function _nonIterableSpread() {
64
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
65
- }
66
- function _objectSpread(target) {
67
- for(var i = 1; i < arguments.length; i++){
68
- var source = arguments[i] != null ? arguments[i] : {};
69
- var ownKeys = Object.keys(source);
70
- if (typeof Object.getOwnPropertySymbols === "function") {
71
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
72
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
73
- }));
74
- }
75
- ownKeys.forEach(function(key) {
76
- _defineProperty(target, key, source[key]);
77
- });
78
- }
79
- return target;
80
- }
81
- function ownKeys(object, enumerableOnly) {
82
- var keys = Object.keys(object);
83
- if (Object.getOwnPropertySymbols) {
84
- var symbols = Object.getOwnPropertySymbols(object);
85
- if (enumerableOnly) {
86
- symbols = symbols.filter(function(sym) {
87
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
88
- });
89
- }
90
- keys.push.apply(keys, symbols);
91
- }
92
- return keys;
93
- }
94
- function _objectSpreadProps(target, source) {
95
- source = source != null ? source : {};
96
- if (Object.getOwnPropertyDescriptors) {
97
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
98
- } else {
99
- ownKeys(Object(source)).forEach(function(key) {
100
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
101
- });
102
- }
103
- return target;
104
- }
105
- function _slicedToArray(arr, i) {
106
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
107
- }
108
- function _toConsumableArray(arr) {
109
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
110
- }
111
- function _unsupportedIterableToArray(o, minLen) {
112
- if (!o) return;
113
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
114
- var n = Object.prototype.toString.call(o).slice(8, -1);
115
- if (n === "Object" && o.constructor) n = o.constructor.name;
116
- if (n === "Map" || n === "Set") return Array.from(n);
117
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
118
- }
119
- Object.defineProperty(exports, "__esModule", {
120
- value: true
121
- });
122
- function _optionalChain(ops) {
123
- var lastAccessLHS = undefined;
124
- var value = ops[0];
125
- var i = 1;
126
- while(i < ops.length){
127
- var op = ops[i];
128
- var fn = ops[i + 1];
129
- i += 2;
130
- if ((op === "optionalAccess" || op === "optionalCall") && value == null) {
131
- return undefined;
132
- }
133
- if (op === "access" || op === "optionalAccess") {
134
- lastAccessLHS = value;
135
- value = fn(value);
136
- } else if (op === "call" || op === "optionalCall") {
137
- var _value;
138
- value = fn(function() {
139
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
140
- args[_key] = arguments[_key];
141
- }
142
- return (_value = value).call.apply(_value, [
143
- lastAccessLHS
144
- ].concat(_toConsumableArray(args)));
145
- });
146
- lastAccessLHS = undefined;
147
- }
148
- }
149
- return value;
150
- }
151
- var _chunkZR7CHFN6js = require("./chunk-ZR7CHFN6.js");
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+ var _chunkUV2F4F4Rjs = require('./chunk-UV2F4F4R.js');
39
+
152
40
  // src/immutable.ts
153
41
  function lsonObjectToJson(obj) {
154
- var result = {};
155
- for(var key in obj){
156
- var val = obj[key];
157
- if (val !== void 0) {
158
- result[key] = lsonToJson(val);
159
- }
42
+ const result = {};
43
+ for (const key in obj) {
44
+ const val = obj[key];
45
+ if (val !== void 0) {
46
+ result[key] = lsonToJson(val);
160
47
  }
161
- return result;
48
+ }
49
+ return result;
162
50
  }
163
51
  function liveObjectToJson(liveObject) {
164
- return lsonObjectToJson(liveObject.toObject());
52
+ return lsonObjectToJson(liveObject.toObject());
165
53
  }
166
54
  function liveMapToJson(map) {
167
- var result = {};
168
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
169
- try {
170
- for(var _iterator = map.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
171
- var _value = _slicedToArray(_step.value, 2), key = _value[0], value = _value[1];
172
- result[key] = lsonToJson(value);
173
- }
174
- } catch (err) {
175
- _didIteratorError = true;
176
- _iteratorError = err;
177
- } finally{
178
- try {
179
- if (!_iteratorNormalCompletion && _iterator.return != null) {
180
- _iterator.return();
181
- }
182
- } finally{
183
- if (_didIteratorError) {
184
- throw _iteratorError;
185
- }
186
- }
187
- }
188
- return result;
55
+ const result = {};
56
+ for (const [key, value] of map.entries()) {
57
+ result[key] = lsonToJson(value);
58
+ }
59
+ return result;
189
60
  }
190
61
  function lsonListToJson(value) {
191
- return value.map(lsonToJson);
62
+ return value.map(lsonToJson);
192
63
  }
193
64
  function liveListToJson(value) {
194
- return lsonListToJson(value.toArray());
65
+ return lsonListToJson(value.toArray());
195
66
  }
196
67
  function lsonToJson(value) {
197
- if (_instanceof(value, _chunkZR7CHFN6js.LiveObject)) {
198
- return liveObjectToJson(value);
199
- } else if (_instanceof(value, _chunkZR7CHFN6js.LiveList)) {
200
- return liveListToJson(value);
201
- } else if (_instanceof(value, _chunkZR7CHFN6js.LiveMap)) {
202
- return liveMapToJson(value);
203
- } else if (_instanceof(value, _chunkZR7CHFN6js.LiveRegister)) {
204
- return value.data;
205
- }
206
- if (Array.isArray(value)) {
207
- return lsonListToJson(value);
208
- } else if (_chunkZR7CHFN6js.isPlainObject.call(void 0, value)) {
209
- return lsonObjectToJson(value);
210
- }
211
- return value;
68
+ if (value instanceof _chunkUV2F4F4Rjs.LiveObject) {
69
+ return liveObjectToJson(value);
70
+ } else if (value instanceof _chunkUV2F4F4Rjs.LiveList) {
71
+ return liveListToJson(value);
72
+ } else if (value instanceof _chunkUV2F4F4Rjs.LiveMap) {
73
+ return liveMapToJson(value);
74
+ } else if (value instanceof _chunkUV2F4F4Rjs.LiveRegister) {
75
+ return value.data;
76
+ }
77
+ if (Array.isArray(value)) {
78
+ return lsonListToJson(value);
79
+ } else if (_chunkUV2F4F4Rjs.isPlainObject.call(void 0, value)) {
80
+ return lsonObjectToJson(value);
81
+ }
82
+ return value;
212
83
  }
213
84
  function deepLiveify(value) {
214
- if (Array.isArray(value)) {
215
- return new (0, _chunkZR7CHFN6js.LiveList)(value.map(deepLiveify));
216
- } else if (_chunkZR7CHFN6js.isPlainObject.call(void 0, value)) {
217
- var init = {};
218
- for(var key in value){
219
- var val = value[key];
220
- if (val === void 0) {
221
- continue;
222
- }
223
- init[key] = deepLiveify(val);
224
- }
225
- return new (0, _chunkZR7CHFN6js.LiveObject)(init);
226
- } else {
227
- return value;
85
+ if (Array.isArray(value)) {
86
+ return new (0, _chunkUV2F4F4Rjs.LiveList)(value.map(deepLiveify));
87
+ } else if (_chunkUV2F4F4Rjs.isPlainObject.call(void 0, value)) {
88
+ const init = {};
89
+ for (const key in value) {
90
+ const val = value[key];
91
+ if (val === void 0) {
92
+ continue;
93
+ }
94
+ init[key] = deepLiveify(val);
228
95
  }
96
+ return new (0, _chunkUV2F4F4Rjs.LiveObject)(init);
97
+ } else {
98
+ return value;
99
+ }
229
100
  }
230
101
  function patchLiveList(liveList, prev, next) {
231
- var i = 0;
232
- var prevEnd = prev.length - 1;
233
- var nextEnd = next.length - 1;
234
- var prevNode = prev[0];
235
- var nextNode = next[0];
236
- outer: {
237
- while(prevNode === nextNode){
238
- ++i;
239
- if (i > prevEnd || i > nextEnd) {
240
- break outer;
241
- }
242
- prevNode = prev[i];
243
- nextNode = next[i];
244
- }
245
- prevNode = prev[prevEnd];
246
- nextNode = next[nextEnd];
247
- while(prevNode === nextNode){
248
- prevEnd--;
249
- nextEnd--;
250
- if (i > prevEnd || i > nextEnd) {
251
- break outer;
252
- }
253
- prevNode = prev[prevEnd];
254
- nextNode = next[nextEnd];
255
- }
102
+ let i = 0;
103
+ let prevEnd = prev.length - 1;
104
+ let nextEnd = next.length - 1;
105
+ let prevNode = prev[0];
106
+ let nextNode = next[0];
107
+ outer: {
108
+ while (prevNode === nextNode) {
109
+ ++i;
110
+ if (i > prevEnd || i > nextEnd) {
111
+ break outer;
112
+ }
113
+ prevNode = prev[i];
114
+ nextNode = next[i];
256
115
  }
257
- if (i > prevEnd) {
258
- if (i <= nextEnd) {
259
- while(i <= nextEnd){
260
- liveList.insert(deepLiveify(next[i]), i);
261
- i++;
262
- }
263
- }
264
- } else if (i > nextEnd) {
265
- var localI = i;
266
- while(localI <= prevEnd){
267
- liveList.delete(i);
268
- localI++;
269
- }
270
- } else {
271
- while(i <= prevEnd && i <= nextEnd){
272
- prevNode = prev[i];
273
- nextNode = next[i];
274
- var liveListNode = liveList.get(i);
275
- if (_chunkZR7CHFN6js.isLiveObject.call(void 0, liveListNode) && _chunkZR7CHFN6js.isPlainObject.call(void 0, prevNode) && _chunkZR7CHFN6js.isPlainObject.call(void 0, nextNode)) {
276
- patchLiveObject(liveListNode, prevNode, nextNode);
277
- } else {
278
- liveList.set(i, deepLiveify(nextNode));
279
- }
280
- i++;
281
- }
282
- while(i <= nextEnd){
283
- liveList.insert(deepLiveify(next[i]), i);
284
- i++;
285
- }
286
- var localI1 = i;
287
- while(localI1 <= prevEnd){
288
- liveList.delete(i);
289
- localI1++;
290
- }
116
+ prevNode = prev[prevEnd];
117
+ nextNode = next[nextEnd];
118
+ while (prevNode === nextNode) {
119
+ prevEnd--;
120
+ nextEnd--;
121
+ if (i > prevEnd || i > nextEnd) {
122
+ break outer;
123
+ }
124
+ prevNode = prev[prevEnd];
125
+ nextNode = next[nextEnd];
126
+ }
127
+ }
128
+ if (i > prevEnd) {
129
+ if (i <= nextEnd) {
130
+ while (i <= nextEnd) {
131
+ liveList.insert(deepLiveify(next[i]), i);
132
+ i++;
133
+ }
134
+ }
135
+ } else if (i > nextEnd) {
136
+ let localI = i;
137
+ while (localI <= prevEnd) {
138
+ liveList.delete(i);
139
+ localI++;
140
+ }
141
+ } else {
142
+ while (i <= prevEnd && i <= nextEnd) {
143
+ prevNode = prev[i];
144
+ nextNode = next[i];
145
+ const liveListNode = liveList.get(i);
146
+ if (_chunkUV2F4F4Rjs.isLiveObject.call(void 0, liveListNode) && _chunkUV2F4F4Rjs.isPlainObject.call(void 0, prevNode) && _chunkUV2F4F4Rjs.isPlainObject.call(void 0, nextNode)) {
147
+ patchLiveObject(liveListNode, prevNode, nextNode);
148
+ } else {
149
+ liveList.set(i, deepLiveify(nextNode));
150
+ }
151
+ i++;
152
+ }
153
+ while (i <= nextEnd) {
154
+ liveList.insert(deepLiveify(next[i]), i);
155
+ i++;
291
156
  }
157
+ let localI = i;
158
+ while (localI <= prevEnd) {
159
+ liveList.delete(i);
160
+ localI++;
161
+ }
162
+ }
292
163
  }
293
164
  function patchLiveObjectKey(liveObject, key, prev, next) {
294
- if (process.env.NODE_ENV !== "production") {
295
- var nonSerializableValue = _chunkZR7CHFN6js.findNonSerializableValue.call(void 0, next);
296
- if (nonSerializableValue) {
297
- console.error("New state path: '".concat(nonSerializableValue.path, "' value: '").concat(nonSerializableValue.value, "' is not serializable.\nOnly serializable value can be synced with Liveblocks."));
298
- return;
299
- }
300
- }
301
- var value = liveObject.get(key);
302
- if (next === void 0) {
303
- liveObject.delete(key);
304
- } else if (value === void 0) {
305
- liveObject.set(key, deepLiveify(next));
306
- } else if (prev === next) {
307
- return;
308
- } else if (_chunkZR7CHFN6js.isLiveList.call(void 0, value) && Array.isArray(prev) && Array.isArray(next)) {
309
- patchLiveList(value, prev, next);
310
- } else if (_chunkZR7CHFN6js.isLiveObject.call(void 0, value) && _chunkZR7CHFN6js.isPlainObject.call(void 0, prev) && _chunkZR7CHFN6js.isPlainObject.call(void 0, next)) {
311
- patchLiveObject(value, prev, next);
312
- } else {
313
- liveObject.set(key, deepLiveify(next));
165
+ if (process.env.NODE_ENV !== "production") {
166
+ const nonSerializableValue = _chunkUV2F4F4Rjs.findNonSerializableValue.call(void 0, next);
167
+ if (nonSerializableValue) {
168
+ console.error(
169
+ `New state path: '${nonSerializableValue.path}' value: '${nonSerializableValue.value}' is not serializable.
170
+ Only serializable value can be synced with Liveblocks.`
171
+ );
172
+ return;
314
173
  }
174
+ }
175
+ const value = liveObject.get(key);
176
+ if (next === void 0) {
177
+ liveObject.delete(key);
178
+ } else if (value === void 0) {
179
+ liveObject.set(key, deepLiveify(next));
180
+ } else if (prev === next) {
181
+ return;
182
+ } else if (_chunkUV2F4F4Rjs.isLiveList.call(void 0, value) && Array.isArray(prev) && Array.isArray(next)) {
183
+ patchLiveList(value, prev, next);
184
+ } else if (_chunkUV2F4F4Rjs.isLiveObject.call(void 0, value) && _chunkUV2F4F4Rjs.isPlainObject.call(void 0, prev) && _chunkUV2F4F4Rjs.isPlainObject.call(void 0, next)) {
185
+ patchLiveObject(value, prev, next);
186
+ } else {
187
+ liveObject.set(key, deepLiveify(next));
188
+ }
315
189
  }
316
190
  function patchLiveObject(root, prev, next) {
317
- var updates = {};
318
- for(var key in next){
319
- patchLiveObjectKey(root, key, prev[key], next[key]);
320
- }
321
- for(var key1 in prev){
322
- if (next[key1] === void 0) {
323
- root.delete(key1);
324
- }
325
- }
326
- if (Object.keys(updates).length > 0) {
327
- root.update(updates);
191
+ const updates = {};
192
+ for (const key in next) {
193
+ patchLiveObjectKey(root, key, prev[key], next[key]);
194
+ }
195
+ for (const key in prev) {
196
+ if (next[key] === void 0) {
197
+ root.delete(key);
328
198
  }
199
+ }
200
+ if (Object.keys(updates).length > 0) {
201
+ root.update(updates);
202
+ }
329
203
  }
330
204
  function getParentsPath(node) {
331
- var path = [];
332
- while(node.parent.type === "HasParent"){
333
- if (_chunkZR7CHFN6js.isLiveList.call(void 0, node.parent.node)) {
334
- path.push(node.parent.node._indexOfPosition(node.parent.key));
335
- } else {
336
- path.push(node.parent.key);
337
- }
338
- node = node.parent.node;
205
+ const path = [];
206
+ while (node.parent.type === "HasParent") {
207
+ if (_chunkUV2F4F4Rjs.isLiveList.call(void 0, node.parent.node)) {
208
+ path.push(node.parent.node._indexOfPosition(node.parent.key));
209
+ } else {
210
+ path.push(node.parent.key);
339
211
  }
340
- return path;
212
+ node = node.parent.node;
213
+ }
214
+ return path;
341
215
  }
342
216
  function legacy_patchImmutableObject(state, updates) {
343
- return updates.reduce(function(state2, update) {
344
- return legacy_patchImmutableObjectWithUpdate(state2, update);
345
- }, state);
217
+ return updates.reduce(
218
+ (state2, update) => legacy_patchImmutableObjectWithUpdate(state2, update),
219
+ state
220
+ );
346
221
  }
347
222
  function legacy_patchImmutableObjectWithUpdate(state, update) {
348
- var path = getParentsPath(update.node);
349
- return legacy_patchImmutableNode(state, path, update);
223
+ const path = getParentsPath(update.node);
224
+ return legacy_patchImmutableNode(state, path, update);
350
225
  }
351
226
  function legacy_patchImmutableNode(state, path, update) {
352
- var pathItem = path.pop();
353
- if (pathItem === void 0) {
354
- switch(update.type){
355
- case "LiveObject":
356
- {
357
- var _loop = function(key) {
358
- if (_optionalChain([
359
- update,
360
- "access",
361
- function(_) {
362
- return _.updates;
363
- },
364
- "access",
365
- function(_2) {
366
- return _2[key];
367
- },
368
- "optionalAccess",
369
- function(_3) {
370
- return _3.type;
371
- }
372
- ]) === "update") {
373
- var val = update.node.get(key);
374
- if (val !== void 0) {
375
- newState[key] = lsonToJson(val);
376
- }
377
- } else if (_optionalChain([
378
- update,
379
- "access",
380
- function(_4) {
381
- return _4.updates;
382
- },
383
- "access",
384
- function(_5) {
385
- return _5[key];
386
- },
387
- "optionalAccess",
388
- function(_6) {
389
- return _6.type;
390
- }
391
- ]) === "delete") {
392
- delete newState[key];
393
- }
394
- };
395
- if (state === null || typeof state !== "object" || Array.isArray(state)) {
396
- throw new Error("Internal: received update on LiveObject but state was not an object");
397
- }
398
- var newState = Object.assign({}, state);
399
- for(var key in update.updates)_loop(key);
400
- return newState;
401
- }
402
- case "LiveList":
403
- {
404
- if (!Array.isArray(state)) {
405
- throw new Error("Internal: received update on LiveList but state was not an array");
406
- }
407
- var newState1 = state.map(function(x) {
408
- return x;
409
- });
410
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
411
- try {
412
- var _loop1 = function() {
413
- var listUpdate = _step.value;
414
- if (listUpdate.type === "set") {
415
- newState1 = newState1.map(function(item, index) {
416
- return index === listUpdate.index ? lsonToJson(listUpdate.item) : item;
417
- });
418
- } else if (listUpdate.type === "insert") {
419
- if (listUpdate.index === newState1.length) {
420
- newState1.push(lsonToJson(listUpdate.item));
421
- } else {
422
- newState1 = _toConsumableArray(newState1.slice(0, listUpdate.index)).concat([
423
- lsonToJson(listUpdate.item)
424
- ], _toConsumableArray(newState1.slice(listUpdate.index)));
425
- }
426
- } else if (listUpdate.type === "delete") {
427
- newState1.splice(listUpdate.index, 1);
428
- } else if (listUpdate.type === "move") {
429
- if (listUpdate.previousIndex > listUpdate.index) {
430
- newState1 = _toConsumableArray(newState1.slice(0, listUpdate.index)).concat([
431
- lsonToJson(listUpdate.item)
432
- ], _toConsumableArray(newState1.slice(listUpdate.index, listUpdate.previousIndex)), _toConsumableArray(newState1.slice(listUpdate.previousIndex + 1)));
433
- } else {
434
- newState1 = _toConsumableArray(newState1.slice(0, listUpdate.previousIndex)).concat(_toConsumableArray(newState1.slice(listUpdate.previousIndex + 1, listUpdate.index + 1)), [
435
- lsonToJson(listUpdate.item)
436
- ], _toConsumableArray(newState1.slice(listUpdate.index + 1)));
437
- }
438
- }
439
- };
440
- for(var _iterator = update.updates[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop1();
441
- } catch (err) {
442
- _didIteratorError = true;
443
- _iteratorError = err;
444
- } finally{
445
- try {
446
- if (!_iteratorNormalCompletion && _iterator.return != null) {
447
- _iterator.return();
448
- }
449
- } finally{
450
- if (_didIteratorError) {
451
- throw _iteratorError;
452
- }
453
- }
454
- }
455
- return newState1;
456
- }
457
- case "LiveMap":
458
- {
459
- var _loop2 = function(key1) {
460
- if (_optionalChain([
461
- update,
462
- "access",
463
- function(_7) {
464
- return _7.updates;
465
- },
466
- "access",
467
- function(_8) {
468
- return _8[key1];
469
- },
470
- "optionalAccess",
471
- function(_9) {
472
- return _9.type;
473
- }
474
- ]) === "update") {
475
- var value = update.node.get(key1);
476
- if (value !== void 0) {
477
- newState2[key1] = lsonToJson(value);
478
- }
479
- } else if (_optionalChain([
480
- update,
481
- "access",
482
- function(_10) {
483
- return _10.updates;
484
- },
485
- "access",
486
- function(_11) {
487
- return _11[key1];
488
- },
489
- "optionalAccess",
490
- function(_12) {
491
- return _12.type;
492
- }
493
- ]) === "delete") {
494
- delete newState2[key1];
495
- }
496
- };
497
- if (state === null || typeof state !== "object" || Array.isArray(state)) {
498
- throw new Error("Internal: received update on LiveMap but state was not an object");
499
- }
500
- var newState2 = Object.assign({}, state);
501
- for(var key1 in update.updates)_loop2(key1);
502
- return newState2;
503
- }
227
+ var _a, _b, _c, _d;
228
+ const pathItem = path.pop();
229
+ if (pathItem === void 0) {
230
+ switch (update.type) {
231
+ case "LiveObject": {
232
+ if (state === null || typeof state !== "object" || Array.isArray(state)) {
233
+ throw new Error(
234
+ "Internal: received update on LiveObject but state was not an object"
235
+ );
504
236
  }
505
- }
506
- if (Array.isArray(state)) {
507
- var newArray = _toConsumableArray(state);
508
- newArray[pathItem] = legacy_patchImmutableNode(state[pathItem], path, update);
509
- return newArray;
510
- } else if (state !== null && typeof state === "object") {
511
- var node = state[pathItem];
512
- if (node === void 0) {
513
- return state;
514
- } else {
515
- return _objectSpreadProps(_objectSpread({}, state), _defineProperty({}, pathItem, legacy_patchImmutableNode(node, path, update)));
237
+ const newState = Object.assign({}, state);
238
+ for (const key in update.updates) {
239
+ if (((_a = update.updates[key]) == null ? void 0 : _a.type) === "update") {
240
+ const val = update.node.get(key);
241
+ if (val !== void 0) {
242
+ newState[key] = lsonToJson(val);
243
+ }
244
+ } else if (((_b = update.updates[key]) == null ? void 0 : _b.type) === "delete") {
245
+ delete newState[key];
246
+ }
516
247
  }
248
+ return newState;
249
+ }
250
+ case "LiveList": {
251
+ if (!Array.isArray(state)) {
252
+ throw new Error(
253
+ "Internal: received update on LiveList but state was not an array"
254
+ );
255
+ }
256
+ let newState = state.map((x) => x);
257
+ for (const listUpdate of update.updates) {
258
+ if (listUpdate.type === "set") {
259
+ newState = newState.map(
260
+ (item, index) => index === listUpdate.index ? lsonToJson(listUpdate.item) : item
261
+ );
262
+ } else if (listUpdate.type === "insert") {
263
+ if (listUpdate.index === newState.length) {
264
+ newState.push(lsonToJson(listUpdate.item));
265
+ } else {
266
+ newState = [
267
+ ...newState.slice(0, listUpdate.index),
268
+ lsonToJson(listUpdate.item),
269
+ ...newState.slice(listUpdate.index)
270
+ ];
271
+ }
272
+ } else if (listUpdate.type === "delete") {
273
+ newState.splice(listUpdate.index, 1);
274
+ } else if (listUpdate.type === "move") {
275
+ if (listUpdate.previousIndex > listUpdate.index) {
276
+ newState = [
277
+ ...newState.slice(0, listUpdate.index),
278
+ lsonToJson(listUpdate.item),
279
+ ...newState.slice(listUpdate.index, listUpdate.previousIndex),
280
+ ...newState.slice(listUpdate.previousIndex + 1)
281
+ ];
282
+ } else {
283
+ newState = [
284
+ ...newState.slice(0, listUpdate.previousIndex),
285
+ ...newState.slice(
286
+ listUpdate.previousIndex + 1,
287
+ listUpdate.index + 1
288
+ ),
289
+ lsonToJson(listUpdate.item),
290
+ ...newState.slice(listUpdate.index + 1)
291
+ ];
292
+ }
293
+ }
294
+ }
295
+ return newState;
296
+ }
297
+ case "LiveMap": {
298
+ if (state === null || typeof state !== "object" || Array.isArray(state)) {
299
+ throw new Error(
300
+ "Internal: received update on LiveMap but state was not an object"
301
+ );
302
+ }
303
+ const newState = Object.assign({}, state);
304
+ for (const key in update.updates) {
305
+ if (((_c = update.updates[key]) == null ? void 0 : _c.type) === "update") {
306
+ const value = update.node.get(key);
307
+ if (value !== void 0) {
308
+ newState[key] = lsonToJson(value);
309
+ }
310
+ } else if (((_d = update.updates[key]) == null ? void 0 : _d.type) === "delete") {
311
+ delete newState[key];
312
+ }
313
+ }
314
+ return newState;
315
+ }
316
+ }
317
+ }
318
+ if (Array.isArray(state)) {
319
+ const newArray = [...state];
320
+ newArray[pathItem] = legacy_patchImmutableNode(
321
+ state[pathItem],
322
+ path,
323
+ update
324
+ );
325
+ return newArray;
326
+ } else if (state !== null && typeof state === "object") {
327
+ const node = state[pathItem];
328
+ if (node === void 0) {
329
+ return state;
517
330
  } else {
518
- return state;
331
+ return _chunkUV2F4F4Rjs.__spreadProps.call(void 0, _chunkUV2F4F4Rjs.__spreadValues.call(void 0, {}, state), {
332
+ [pathItem]: legacy_patchImmutableNode(node, path, update)
333
+ });
519
334
  }
335
+ } else {
336
+ return state;
337
+ }
520
338
  }
521
- exports.ClientMsgCode = _chunkZR7CHFN6js.ClientMsgCode;
522
- exports.CrdtType = _chunkZR7CHFN6js.CrdtType;
523
- exports.OpCode = _chunkZR7CHFN6js.OpCode;
524
- exports.ServerMsgCode = _chunkZR7CHFN6js.ServerMsgCode;
525
- exports.WebsocketCloseCodes = _chunkZR7CHFN6js.WebsocketCloseCodes;
526
- exports.assertNever = _chunkZR7CHFN6js.assertNever;
527
- exports.b64decode = _chunkZR7CHFN6js.b64decode;
528
- exports.comparePosition = _chunkZR7CHFN6js.comparePosition;
529
- exports.deprecate = _chunkZR7CHFN6js.deprecate;
530
- exports.deprecateIf = _chunkZR7CHFN6js.deprecateIf;
531
- exports.errorIf = _chunkZR7CHFN6js.errorIf;
532
- exports.freeze = _chunkZR7CHFN6js.freeze;
533
- exports.isAppOnlyAuthToken = _chunkZR7CHFN6js.isAppOnlyAuthToken;
534
- exports.isAuthToken = _chunkZR7CHFN6js.isAuthToken;
535
- exports.isChildCrdt = _chunkZR7CHFN6js.isChildCrdt;
536
- exports.isJsonArray = _chunkZR7CHFN6js.isJsonArray;
537
- exports.isJsonObject = _chunkZR7CHFN6js.isJsonObject;
538
- exports.isJsonScalar = _chunkZR7CHFN6js.isJsonScalar;
539
- exports.isPlainObject = _chunkZR7CHFN6js.isPlainObject;
540
- exports.isRoomAuthToken = _chunkZR7CHFN6js.isRoomAuthToken;
541
- exports.isRootCrdt = _chunkZR7CHFN6js.isRootCrdt;
542
- exports.isScope = _chunkZR7CHFN6js.isScope;
543
- exports.legacy_patchImmutableObject = legacy_patchImmutableObject;
544
- exports.lsonToJson = lsonToJson;
545
- exports.makePosition = _chunkZR7CHFN6js.makePosition;
546
- exports.nn = _chunkZR7CHFN6js.nn;
547
- exports.patchLiveObjectKey = patchLiveObjectKey;
548
- exports.throwUsageError = _chunkZR7CHFN6js.throwUsageError;
549
- exports.tryParseJson = _chunkZR7CHFN6js.tryParseJson;
339
+
340
+
341
+
342
+
343
+
344
+
345
+
346
+
347
+
348
+
349
+
350
+
351
+
352
+
353
+
354
+
355
+
356
+
357
+
358
+
359
+
360
+
361
+
362
+
363
+
364
+
365
+
366
+
367
+
368
+
369
+
370
+ exports.ClientMsgCode = _chunkUV2F4F4Rjs.ClientMsgCode; exports.CrdtType = _chunkUV2F4F4Rjs.CrdtType; exports.OpCode = _chunkUV2F4F4Rjs.OpCode; exports.ServerMsgCode = _chunkUV2F4F4Rjs.ServerMsgCode; exports.WebsocketCloseCodes = _chunkUV2F4F4Rjs.WebsocketCloseCodes; exports.asArrayWithLegacyMethods = _chunkUV2F4F4Rjs.asArrayWithLegacyMethods; exports.assertNever = _chunkUV2F4F4Rjs.assertNever; exports.b64decode = _chunkUV2F4F4Rjs.b64decode; exports.comparePosition = _chunkUV2F4F4Rjs.comparePosition; exports.deprecate = _chunkUV2F4F4Rjs.deprecate; exports.deprecateIf = _chunkUV2F4F4Rjs.deprecateIf; exports.errorIf = _chunkUV2F4F4Rjs.errorIf; exports.freeze = _chunkUV2F4F4Rjs.freeze; exports.isAppOnlyAuthToken = _chunkUV2F4F4Rjs.isAppOnlyAuthToken; exports.isAuthToken = _chunkUV2F4F4Rjs.isAuthToken; exports.isChildCrdt = _chunkUV2F4F4Rjs.isChildCrdt; exports.isJsonArray = _chunkUV2F4F4Rjs.isJsonArray; exports.isJsonObject = _chunkUV2F4F4Rjs.isJsonObject; exports.isJsonScalar = _chunkUV2F4F4Rjs.isJsonScalar; exports.isPlainObject = _chunkUV2F4F4Rjs.isPlainObject; exports.isRoomAuthToken = _chunkUV2F4F4Rjs.isRoomAuthToken; exports.isRootCrdt = _chunkUV2F4F4Rjs.isRootCrdt; exports.isScope = _chunkUV2F4F4Rjs.isScope; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makePosition = _chunkUV2F4F4Rjs.makePosition; exports.nn = _chunkUV2F4F4Rjs.nn; exports.patchLiveObjectKey = patchLiveObjectKey; exports.throwUsageError = _chunkUV2F4F4Rjs.throwUsageError; exports.tryParseJson = _chunkUV2F4F4Rjs.tryParseJson;