@liveblocks/core 3.14.0-pre4 → 3.14.0-pre6

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 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.14.0-pre4";
9
+ var PKG_VERSION = "3.14.0-pre6";
10
10
  var PKG_FORMAT = "cjs";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -567,6 +567,9 @@ var SortedList = class _SortedList {
567
567
  this.#lt = lt;
568
568
  this.#data = alreadySortedList;
569
569
  }
570
+ /**
571
+ * Creates an empty SortedList with the given "less than" function.
572
+ */
570
573
  static with(lt) {
571
574
  return _SortedList.fromAlreadySorted([], lt);
572
575
  }
@@ -588,10 +591,12 @@ var SortedList = class _SortedList {
588
591
  }
589
592
  /**
590
593
  * Adds a new item to the sorted list, such that it remains sorted.
594
+ * Returns the index where the item was inserted.
591
595
  */
592
596
  add(value) {
593
597
  const idx = bisectRight(this.#data, value, this.#lt);
594
598
  this.#data.splice(idx, 0, value);
599
+ return idx;
595
600
  }
596
601
  /**
597
602
  * Removes all values from the sorted list, making it empty again.
@@ -636,6 +641,60 @@ var SortedList = class _SortedList {
636
641
  }
637
642
  return false;
638
643
  }
644
+ /**
645
+ * Removes the item at the given index.
646
+ * Returns the removed item, or undefined if index is out of bounds.
647
+ */
648
+ removeAt(index) {
649
+ if (index < 0 || index >= this.#data.length) {
650
+ return void 0;
651
+ }
652
+ const [removed] = this.#data.splice(index, 1);
653
+ return removed;
654
+ }
655
+ /**
656
+ * Repositions an item to maintain sorted order after its sort key has
657
+ * been mutated in-place. For example:
658
+ *
659
+ * const item = sorted.at(3);
660
+ * item.updatedAt = new Date(); // mutate the item's sort key in-place
661
+ * sorted.reposition(item); // restore sorted order
662
+ *
663
+ * Returns the new index of the item. Throws if the item is not in the list.
664
+ *
665
+ * Semantically equivalent to remove(value) + add(value), but optimized
666
+ * to avoid array shifting when the item only moves a short distance.
667
+ */
668
+ reposition(value) {
669
+ const oldIdx = this.#data.indexOf(value);
670
+ if (oldIdx < 0) {
671
+ throw new Error("Cannot reposition item that is not in the list");
672
+ }
673
+ const prev = this.#data[oldIdx - 1];
674
+ const next = this.#data[oldIdx + 1];
675
+ const validLeft = prev === void 0 || this.#lt(prev, value);
676
+ const validRight = next === void 0 || this.#lt(value, next);
677
+ if (validLeft && validRight) {
678
+ return oldIdx;
679
+ }
680
+ let newIdx = oldIdx;
681
+ while (newIdx > 0 && this.#lt(value, this.#data[newIdx - 1])) {
682
+ this.#data[newIdx] = this.#data[newIdx - 1];
683
+ newIdx--;
684
+ }
685
+ if (newIdx < oldIdx) {
686
+ this.#data[newIdx] = value;
687
+ return newIdx;
688
+ }
689
+ while (newIdx < this.#data.length - 1 && !this.#lt(value, this.#data[newIdx + 1])) {
690
+ this.#data[newIdx] = this.#data[newIdx + 1];
691
+ newIdx++;
692
+ }
693
+ if (newIdx !== oldIdx) {
694
+ this.#data[newIdx] = value;
695
+ }
696
+ return newIdx;
697
+ }
639
698
  at(index) {
640
699
  return this.#data[index];
641
700
  }
@@ -5898,16 +5957,68 @@ function before(pos) {
5898
5957
  }
5899
5958
  return ONE;
5900
5959
  }
5960
+ var VIEWPORT_START = 2;
5961
+ var VIEWPORT_STEP = 3;
5901
5962
  function after(pos) {
5902
- for (let i = 0; i <= pos.length - 1; i++) {
5963
+ for (let i = 0; i < pos.length; i++) {
5903
5964
  const code = pos.charCodeAt(i);
5904
- if (code >= MAX_CODE) {
5905
- continue;
5965
+ if (code < MIN_CODE || code > MAX_CODE) {
5966
+ return pos + ONE;
5906
5967
  }
5907
- return pos.substring(0, i) + String.fromCharCode(code + 1);
5968
+ }
5969
+ while (pos.length > 1 && pos.charCodeAt(pos.length - 1) === MIN_CODE) {
5970
+ pos = pos.slice(0, -1);
5971
+ }
5972
+ if (pos.length === 0 || pos === ZERO) {
5973
+ return ONE;
5974
+ }
5975
+ let viewport = VIEWPORT_START;
5976
+ if (pos.length > VIEWPORT_START) {
5977
+ viewport = VIEWPORT_START + Math.ceil((pos.length - VIEWPORT_START) / VIEWPORT_STEP) * VIEWPORT_STEP;
5978
+ }
5979
+ const result = incrementWithinViewport(pos, viewport);
5980
+ if (result !== null) {
5981
+ return result;
5982
+ }
5983
+ viewport += VIEWPORT_STEP;
5984
+ const extendedResult = incrementWithinViewport(pos, viewport);
5985
+ if (extendedResult !== null) {
5986
+ return extendedResult;
5908
5987
  }
5909
5988
  return pos + ONE;
5910
5989
  }
5990
+ function incrementWithinViewport(pos, viewport) {
5991
+ const digits = [];
5992
+ for (let i = 0; i < viewport; i++) {
5993
+ if (i < pos.length) {
5994
+ digits.push(pos.charCodeAt(i) - MIN_CODE);
5995
+ } else {
5996
+ digits.push(0);
5997
+ }
5998
+ }
5999
+ let carry = 1;
6000
+ for (let i = viewport - 1; i >= 0 && carry; i--) {
6001
+ const sum = digits[i] + carry;
6002
+ if (sum >= NUM_DIGITS) {
6003
+ digits[i] = 0;
6004
+ carry = 1;
6005
+ } else {
6006
+ digits[i] = sum;
6007
+ carry = 0;
6008
+ }
6009
+ }
6010
+ if (carry) {
6011
+ return null;
6012
+ }
6013
+ let result = "";
6014
+ for (const d of digits) {
6015
+ result += String.fromCharCode(d + MIN_CODE);
6016
+ }
6017
+ while (result.length > 1 && result.charCodeAt(result.length - 1) === MIN_CODE) {
6018
+ result = result.slice(0, -1);
6019
+ }
6020
+ return result;
6021
+ }
5911
6022
  function between(lo, hi) {
5912
6023
  if (lo < hi) {
5913
6024
  return _between(lo, hi);
@@ -6368,29 +6479,27 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
6368
6479
  };
6369
6480
 
6370
6481
  // src/crdts/LiveList.ts
6371
- function compareNodePosition(itemA, itemB) {
6372
- const posA = itemA._parentPos;
6373
- const posB = itemB._parentPos;
6374
- return posA === posB ? 0 : posA < posB ? -1 : 1;
6482
+ function childNodeLt(a, b) {
6483
+ return a._parentPos < b._parentPos;
6375
6484
  }
6376
6485
  var LiveList = class _LiveList extends AbstractCrdt {
6377
- // TODO: Naive array at first, find a better data structure. Maybe an Order statistics tree?
6378
6486
  #items;
6379
6487
  #implicitlyDeletedItems;
6380
6488
  #unacknowledgedSets;
6381
6489
  constructor(items) {
6382
6490
  super();
6383
- this.#items = [];
6384
6491
  this.#implicitlyDeletedItems = /* @__PURE__ */ new WeakSet();
6385
6492
  this.#unacknowledgedSets = /* @__PURE__ */ new Map();
6386
- let position = void 0;
6493
+ const nodes = [];
6494
+ let lastPos;
6387
6495
  for (const item of items) {
6388
- const newPosition = makePosition(position);
6496
+ const pos = makePosition(lastPos);
6389
6497
  const node = lsonToLiveNode(item);
6390
- node._setParentLink(this, newPosition);
6391
- this.#items.push(node);
6392
- position = newPosition;
6498
+ node._setParentLink(this, pos);
6499
+ nodes.push(node);
6500
+ lastPos = pos;
6393
6501
  }
6502
+ this.#items = SortedList.fromAlreadySorted(nodes, childNodeLt);
6394
6503
  }
6395
6504
  /** @internal */
6396
6505
  static _deserialize([id, _], parentToChildren, pool) {
@@ -6404,7 +6513,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6404
6513
  const crdt = node[1];
6405
6514
  const child = deserialize(node, parentToChildren, pool);
6406
6515
  child._setParentLink(list, crdt.parentKey);
6407
- list._insertAndSort(child);
6516
+ list.#insert(child);
6408
6517
  }
6409
6518
  return list;
6410
6519
  }
@@ -6435,24 +6544,40 @@ var LiveList = class _LiveList extends AbstractCrdt {
6435
6544
  item._toOps(this._id, parentKey2),
6436
6545
  void 0
6437
6546
  );
6438
- ops.push(...childOps);
6547
+ for (const childOp of childOps) {
6548
+ ops.push(childOp);
6549
+ }
6439
6550
  }
6440
6551
  return ops;
6441
6552
  }
6442
6553
  /**
6443
- * @internal
6444
- *
6445
- * Adds a new item into the sorted list, in the correct position.
6554
+ * Inserts a new child into the list in the correct location (binary search
6555
+ * finds correct position efficiently). Returns the insertion index.
6446
6556
  */
6447
- _insertAndSort(item) {
6448
- this.#items.push(item);
6449
- this._sortItems();
6557
+ #insert(childNode) {
6558
+ const index = this.#items.add(childNode);
6559
+ this.invalidate();
6560
+ return index;
6450
6561
  }
6451
- /** @internal */
6452
- _sortItems() {
6453
- this.#items.sort(compareNodePosition);
6562
+ /**
6563
+ * Updates an item's position and repositions it in the sorted list.
6564
+ * Encapsulates the remove -> mutate -> add cycle needed when changing sort keys.
6565
+ *
6566
+ * IMPORTANT: Item must exist in this list. List count remains unchanged.
6567
+ */
6568
+ #updateItemPosition(item, newKey) {
6569
+ item._setParentLink(this, newKey);
6570
+ this.#items.reposition(item);
6454
6571
  this.invalidate();
6455
6572
  }
6573
+ /**
6574
+ * Updates an item's position by index. Safer than #updateItemPosition when you have
6575
+ * an index, as it ensures the item exists and is from this list.
6576
+ */
6577
+ #updateItemPositionAt(index, newKey) {
6578
+ const item = nn(this.#items.at(index));
6579
+ this.#updateItemPosition(item, newKey);
6580
+ }
6456
6581
  /** @internal */
6457
6582
  _indexOfPosition(position) {
6458
6583
  return this.#items.findIndex(
@@ -6484,10 +6609,12 @@ var LiveList = class _LiveList extends AbstractCrdt {
6484
6609
  const deletedId = op.deletedId;
6485
6610
  const indexOfItemWithSamePosition = this._indexOfPosition(key);
6486
6611
  if (indexOfItemWithSamePosition !== -1) {
6487
- const itemWithSamePosition = this.#items[indexOfItemWithSamePosition];
6612
+ const itemWithSamePosition = nn(
6613
+ this.#items.removeAt(indexOfItemWithSamePosition)
6614
+ );
6488
6615
  if (itemWithSamePosition._id === deletedId) {
6489
6616
  itemWithSamePosition._detach();
6490
- this.#items[indexOfItemWithSamePosition] = child;
6617
+ this.#items.add(child);
6491
6618
  return {
6492
6619
  modified: makeUpdate(this, [
6493
6620
  setDelta(indexOfItemWithSamePosition, child)
@@ -6496,7 +6623,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
6496
6623
  };
6497
6624
  } else {
6498
6625
  this.#implicitlyDeletedItems.add(itemWithSamePosition);
6499
- this.#items[indexOfItemWithSamePosition] = child;
6626
+ this.#items.remove(itemWithSamePosition);
6627
+ this.#items.add(child);
6500
6628
  const delta = [
6501
6629
  setDelta(indexOfItemWithSamePosition, child)
6502
6630
  ];
@@ -6519,7 +6647,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6519
6647
  if (deleteDelta2) {
6520
6648
  updates.push(deleteDelta2);
6521
6649
  }
6522
- this._insertAndSort(child);
6650
+ this.#insert(child);
6523
6651
  updates.push(insertDelta(this._indexOfPosition(key), child));
6524
6652
  return {
6525
6653
  reverse: [],
@@ -6554,16 +6682,15 @@ var LiveList = class _LiveList extends AbstractCrdt {
6554
6682
  };
6555
6683
  }
6556
6684
  if (indexOfItemWithSamePosition !== -1) {
6557
- this.#implicitlyDeletedItems.add(
6558
- this.#items[indexOfItemWithSamePosition]
6685
+ const itemAtPosition = nn(
6686
+ this.#items.removeAt(indexOfItemWithSamePosition)
6559
6687
  );
6560
- const [prevNode] = this.#items.splice(indexOfItemWithSamePosition, 1);
6561
- delta.push(deleteDelta(indexOfItemWithSamePosition, prevNode));
6688
+ this.#implicitlyDeletedItems.add(itemAtPosition);
6689
+ delta.push(deleteDelta(indexOfItemWithSamePosition, itemAtPosition));
6562
6690
  }
6563
- const prevIndex = this.#items.indexOf(existingItem);
6564
- existingItem._setParentLink(this, op.parentKey);
6565
- this._sortItems();
6566
- const newIndex = this.#items.indexOf(existingItem);
6691
+ const prevIndex = this.#items.findIndex((item) => item === existingItem);
6692
+ this.#updateItemPosition(existingItem, op.parentKey);
6693
+ const newIndex = this.#items.findIndex((item) => item === existingItem);
6567
6694
  if (newIndex !== prevIndex) {
6568
6695
  delta.push(moveDelta(prevIndex, newIndex, existingItem));
6569
6696
  }
@@ -6576,8 +6703,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6576
6703
  if (orphan && this.#implicitlyDeletedItems.has(orphan)) {
6577
6704
  orphan._setParentLink(this, op.parentKey);
6578
6705
  this.#implicitlyDeletedItems.delete(orphan);
6579
- this._insertAndSort(orphan);
6580
- const recreatedItemIndex = this.#items.indexOf(orphan);
6706
+ const recreatedItemIndex = this.#insert(orphan);
6581
6707
  return {
6582
6708
  modified: makeUpdate(this, [
6583
6709
  // If there is an item at this position, update is a set, else it's an insert
@@ -6588,7 +6714,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6588
6714
  };
6589
6715
  } else {
6590
6716
  if (indexOfItemWithSamePosition !== -1) {
6591
- this.#items.splice(indexOfItemWithSamePosition, 1);
6717
+ nn(this.#items.removeAt(indexOfItemWithSamePosition));
6592
6718
  }
6593
6719
  const { newItem, newIndex } = this.#createAttachItemAndSort(
6594
6720
  op,
@@ -6647,12 +6773,13 @@ var LiveList = class _LiveList extends AbstractCrdt {
6647
6773
  modified: false
6648
6774
  };
6649
6775
  } else {
6650
- const oldPositionIndex = this.#items.indexOf(existingItem);
6776
+ const oldPositionIndex = this.#items.findIndex(
6777
+ (item) => item === existingItem
6778
+ );
6651
6779
  if (itemIndexAtPosition !== -1) {
6652
6780
  this.#shiftItemPosition(itemIndexAtPosition, key);
6653
6781
  }
6654
- existingItem._setParentLink(this, key);
6655
- this._sortItems();
6782
+ this.#updateItemPosition(existingItem, key);
6656
6783
  const newIndex = this._indexOfPosition(key);
6657
6784
  if (newIndex === oldPositionIndex) {
6658
6785
  return { modified: false };
@@ -6669,7 +6796,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6669
6796
  if (orphan && this.#implicitlyDeletedItems.has(orphan)) {
6670
6797
  orphan._setParentLink(this, key);
6671
6798
  this.#implicitlyDeletedItems.delete(orphan);
6672
- this._insertAndSort(orphan);
6799
+ this.#insert(orphan);
6673
6800
  const newIndex = this._indexOfPosition(key);
6674
6801
  return {
6675
6802
  modified: makeUpdate(this, [insertDelta(newIndex, orphan)]),
@@ -6698,12 +6825,12 @@ var LiveList = class _LiveList extends AbstractCrdt {
6698
6825
  const existingItemIndex = this._indexOfPosition(key);
6699
6826
  let newKey = key;
6700
6827
  if (existingItemIndex !== -1) {
6701
- const before2 = _optionalChain([this, 'access', _118 => _118.#items, 'access', _119 => _119[existingItemIndex], 'optionalAccess', _120 => _120._parentPos]);
6702
- const after2 = _optionalChain([this, 'access', _121 => _121.#items, 'access', _122 => _122[existingItemIndex + 1], 'optionalAccess', _123 => _123._parentPos]);
6828
+ const before2 = _optionalChain([this, 'access', _118 => _118.#items, 'access', _119 => _119.at, 'call', _120 => _120(existingItemIndex), 'optionalAccess', _121 => _121._parentPos]);
6829
+ const after2 = _optionalChain([this, 'access', _122 => _122.#items, 'access', _123 => _123.at, 'call', _124 => _124(existingItemIndex + 1), 'optionalAccess', _125 => _125._parentPos]);
6703
6830
  newKey = makePosition(before2, after2);
6704
6831
  child._setParentLink(this, newKey);
6705
6832
  }
6706
- this._insertAndSort(child);
6833
+ this.#insert(child);
6707
6834
  const newIndex = this._indexOfPosition(newKey);
6708
6835
  return {
6709
6836
  modified: makeUpdate(this, [insertDelta(newIndex, child)]),
@@ -6713,7 +6840,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6713
6840
  #applySetUndoRedo(op) {
6714
6841
  const { id, parentKey: key } = op;
6715
6842
  const child = creationOpToLiveNode(op);
6716
- if (_optionalChain([this, 'access', _124 => _124._pool, 'optionalAccess', _125 => _125.getNode, 'call', _126 => _126(id)]) !== void 0) {
6843
+ if (_optionalChain([this, 'access', _126 => _126._pool, 'optionalAccess', _127 => _127.getNode, 'call', _128 => _128(id)]) !== void 0) {
6717
6844
  return { modified: false };
6718
6845
  }
6719
6846
  this.#unacknowledgedSets.set(key, nn(op.opId));
@@ -6722,9 +6849,10 @@ var LiveList = class _LiveList extends AbstractCrdt {
6722
6849
  child._setParentLink(this, key);
6723
6850
  const newKey = key;
6724
6851
  if (indexOfItemWithSameKey !== -1) {
6725
- const existingItem = this.#items[indexOfItemWithSameKey];
6852
+ const existingItem = this.#items.at(indexOfItemWithSameKey);
6726
6853
  existingItem._detach();
6727
- this.#items[indexOfItemWithSameKey] = child;
6854
+ this.#items.remove(existingItem);
6855
+ this.#items.add(child);
6728
6856
  const reverse = HACK_addIntentAndDeletedIdToOperation(
6729
6857
  existingItem._toOps(nn(this._id), key),
6730
6858
  op.id
@@ -6741,7 +6869,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6741
6869
  reverse
6742
6870
  };
6743
6871
  } else {
6744
- this._insertAndSort(child);
6872
+ this.#insert(child);
6745
6873
  this.#detachItemAssociatedToSetOperation(op.deletedId);
6746
6874
  const newIndex = this._indexOfPosition(newKey);
6747
6875
  return {
@@ -6783,13 +6911,14 @@ var LiveList = class _LiveList extends AbstractCrdt {
6783
6911
  if (child) {
6784
6912
  const parentKey = nn(child._parentKey);
6785
6913
  const reverse = child._toOps(nn(this._id), parentKey);
6786
- const indexToDelete = this.#items.indexOf(child);
6914
+ const indexToDelete = this.#items.findIndex((item) => item === child);
6787
6915
  if (indexToDelete === -1) {
6788
6916
  return {
6789
6917
  modified: false
6790
6918
  };
6791
6919
  }
6792
- const [previousNode] = this.#items.splice(indexToDelete, 1);
6920
+ const previousNode = this.#items.at(indexToDelete);
6921
+ this.#items.remove(child);
6793
6922
  this.invalidate();
6794
6923
  child._detach();
6795
6924
  return {
@@ -6803,8 +6932,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6803
6932
  if (this.#implicitlyDeletedItems.has(child)) {
6804
6933
  this.#implicitlyDeletedItems.delete(child);
6805
6934
  child._setParentLink(this, newKey);
6806
- this._insertAndSort(child);
6807
- const newIndex = this.#items.indexOf(child);
6935
+ const newIndex = this.#insert(child);
6808
6936
  return {
6809
6937
  modified: makeUpdate(this, [insertDelta(newIndex, child)]),
6810
6938
  reverse: []
@@ -6818,10 +6946,9 @@ var LiveList = class _LiveList extends AbstractCrdt {
6818
6946
  }
6819
6947
  const existingItemIndex = this._indexOfPosition(newKey);
6820
6948
  if (existingItemIndex === -1) {
6821
- const previousIndex = this.#items.indexOf(child);
6822
- child._setParentLink(this, newKey);
6823
- this._sortItems();
6824
- const newIndex = this.#items.indexOf(child);
6949
+ const previousIndex = this.#items.findIndex((item) => item === child);
6950
+ this.#updateItemPosition(child, newKey);
6951
+ const newIndex = this.#items.findIndex((item) => item === child);
6825
6952
  if (newIndex === previousIndex) {
6826
6953
  return {
6827
6954
  modified: false
@@ -6832,14 +6959,13 @@ var LiveList = class _LiveList extends AbstractCrdt {
6832
6959
  reverse: []
6833
6960
  };
6834
6961
  } else {
6835
- this.#items[existingItemIndex]._setParentLink(
6836
- this,
6837
- makePosition(newKey, _optionalChain([this, 'access', _127 => _127.#items, 'access', _128 => _128[existingItemIndex + 1], 'optionalAccess', _129 => _129._parentPos]))
6962
+ this.#updateItemPositionAt(
6963
+ existingItemIndex,
6964
+ makePosition(newKey, _optionalChain([this, 'access', _129 => _129.#items, 'access', _130 => _130.at, 'call', _131 => _131(existingItemIndex + 1), 'optionalAccess', _132 => _132._parentPos]))
6838
6965
  );
6839
- const previousIndex = this.#items.indexOf(child);
6840
- child._setParentLink(this, newKey);
6841
- this._sortItems();
6842
- const newIndex = this.#items.indexOf(child);
6966
+ const previousIndex = this.#items.findIndex((item) => item === child);
6967
+ this.#updateItemPosition(child, newKey);
6968
+ const newIndex = this.#items.findIndex((item) => item === child);
6843
6969
  if (newIndex === previousIndex) {
6844
6970
  return {
6845
6971
  modified: false
@@ -6857,14 +6983,18 @@ var LiveList = class _LiveList extends AbstractCrdt {
6857
6983
  const existingItemIndex = this._indexOfPosition(newKey);
6858
6984
  this.#implicitlyDeletedItems.delete(child);
6859
6985
  if (existingItemIndex !== -1) {
6860
- this.#items[existingItemIndex]._setParentLink(
6986
+ const existingItem = this.#items.at(existingItemIndex);
6987
+ existingItem._setParentLink(
6861
6988
  this,
6862
- makePosition(newKey, _optionalChain([this, 'access', _130 => _130.#items, 'access', _131 => _131[existingItemIndex + 1], 'optionalAccess', _132 => _132._parentPos]))
6989
+ makePosition(
6990
+ newKey,
6991
+ _optionalChain([this, 'access', _133 => _133.#items, 'access', _134 => _134.at, 'call', _135 => _135(existingItemIndex + 1), 'optionalAccess', _136 => _136._parentPos])
6992
+ )
6863
6993
  );
6994
+ this.#items.reposition(existingItem);
6864
6995
  }
6865
6996
  child._setParentLink(this, newKey);
6866
- this._insertAndSort(child);
6867
- const newIndex = this.#items.indexOf(child);
6997
+ const newIndex = this.#insert(child);
6868
6998
  return {
6869
6999
  modified: makeUpdate(this, [insertDelta(newIndex, child)]),
6870
7000
  reverse: []
@@ -6875,17 +7005,19 @@ var LiveList = class _LiveList extends AbstractCrdt {
6875
7005
  modified: false
6876
7006
  };
6877
7007
  }
6878
- const previousIndex = this.#items.indexOf(child);
7008
+ const previousIndex = this.#items.findIndex((item) => item === child);
6879
7009
  const existingItemIndex = this._indexOfPosition(newKey);
6880
7010
  if (existingItemIndex !== -1) {
6881
- this.#items[existingItemIndex]._setParentLink(
6882
- this,
6883
- makePosition(newKey, _optionalChain([this, 'access', _133 => _133.#items, 'access', _134 => _134[existingItemIndex + 1], 'optionalAccess', _135 => _135._parentPos]))
7011
+ this.#updateItemPositionAt(
7012
+ existingItemIndex,
7013
+ makePosition(
7014
+ newKey,
7015
+ _optionalChain([this, 'access', _137 => _137.#items, 'access', _138 => _138.at, 'call', _139 => _139(existingItemIndex + 1), 'optionalAccess', _140 => _140._parentPos])
7016
+ )
6884
7017
  );
6885
7018
  }
6886
- child._setParentLink(this, newKey);
6887
- this._sortItems();
6888
- const newIndex = this.#items.indexOf(child);
7019
+ this.#updateItemPosition(child, newKey);
7020
+ const newIndex = this.#items.findIndex((item) => item === child);
6889
7021
  if (previousIndex === newIndex) {
6890
7022
  return {
6891
7023
  modified: false
@@ -6902,18 +7034,17 @@ var LiveList = class _LiveList extends AbstractCrdt {
6902
7034
  }
6903
7035
  #applySetChildKeyUndoRedo(newKey, child) {
6904
7036
  const previousKey = nn(child._parentKey);
6905
- const previousIndex = this.#items.indexOf(child);
7037
+ const previousIndex = this.#items.findIndex((item) => item === child);
6906
7038
  const existingItemIndex = this._indexOfPosition(newKey);
6907
7039
  let actualNewKey = newKey;
6908
7040
  if (existingItemIndex !== -1) {
6909
7041
  actualNewKey = makePosition(
6910
7042
  newKey,
6911
- _optionalChain([this, 'access', _136 => _136.#items, 'access', _137 => _137[existingItemIndex + 1], 'optionalAccess', _138 => _138._parentPos])
7043
+ _optionalChain([this, 'access', _141 => _141.#items, 'access', _142 => _142.at, 'call', _143 => _143(existingItemIndex + 1), 'optionalAccess', _144 => _144._parentPos])
6912
7044
  );
6913
7045
  }
6914
- child._setParentLink(this, actualNewKey);
6915
- this._sortItems();
6916
- const newIndex = this.#items.indexOf(child);
7046
+ this.#updateItemPosition(child, actualNewKey);
7047
+ const newIndex = this.#items.findIndex((item) => item === child);
6917
7048
  if (previousIndex === newIndex) {
6918
7049
  return {
6919
7050
  modified: false
@@ -6966,7 +7097,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6966
7097
  * @param element The element to add to the end of the LiveList.
6967
7098
  */
6968
7099
  push(element) {
6969
- _optionalChain([this, 'access', _139 => _139._pool, 'optionalAccess', _140 => _140.assertStorageIsWritable, 'call', _141 => _141()]);
7100
+ _optionalChain([this, 'access', _145 => _145._pool, 'optionalAccess', _146 => _146.assertStorageIsWritable, 'call', _147 => _147()]);
6970
7101
  return this.insert(element, this.length);
6971
7102
  }
6972
7103
  /**
@@ -6975,18 +7106,18 @@ var LiveList = class _LiveList extends AbstractCrdt {
6975
7106
  * @param index The index at which you want to insert the element.
6976
7107
  */
6977
7108
  insert(element, index) {
6978
- _optionalChain([this, 'access', _142 => _142._pool, 'optionalAccess', _143 => _143.assertStorageIsWritable, 'call', _144 => _144()]);
7109
+ _optionalChain([this, 'access', _148 => _148._pool, 'optionalAccess', _149 => _149.assertStorageIsWritable, 'call', _150 => _150()]);
6979
7110
  if (index < 0 || index > this.#items.length) {
6980
7111
  throw new Error(
6981
7112
  `Cannot insert list item at index "${index}". index should be between 0 and ${this.#items.length}`
6982
7113
  );
6983
7114
  }
6984
- const before2 = this.#items[index - 1] ? this.#items[index - 1]._parentPos : void 0;
6985
- const after2 = this.#items[index] ? this.#items[index]._parentPos : void 0;
7115
+ const before2 = _optionalChain([this, 'access', _151 => _151.#items, 'access', _152 => _152.at, 'call', _153 => _153(index - 1), 'optionalAccess', _154 => _154._parentPos]);
7116
+ const after2 = _optionalChain([this, 'access', _155 => _155.#items, 'access', _156 => _156.at, 'call', _157 => _157(index), 'optionalAccess', _158 => _158._parentPos]);
6986
7117
  const position = makePosition(before2, after2);
6987
7118
  const value = lsonToLiveNode(element);
6988
7119
  value._setParentLink(this, position);
6989
- this._insertAndSort(value);
7120
+ this.#insert(value);
6990
7121
  if (this._pool && this._id) {
6991
7122
  const id = this._pool.generateId();
6992
7123
  value._attach(id, this._pool);
@@ -7005,7 +7136,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
7005
7136
  * @param targetIndex The index where the element should be after moving.
7006
7137
  */
7007
7138
  move(index, targetIndex) {
7008
- _optionalChain([this, 'access', _145 => _145._pool, 'optionalAccess', _146 => _146.assertStorageIsWritable, 'call', _147 => _147()]);
7139
+ _optionalChain([this, 'access', _159 => _159._pool, 'optionalAccess', _160 => _160.assertStorageIsWritable, 'call', _161 => _161()]);
7009
7140
  if (targetIndex < 0) {
7010
7141
  throw new Error("targetIndex cannot be less than 0");
7011
7142
  }
@@ -7023,17 +7154,16 @@ var LiveList = class _LiveList extends AbstractCrdt {
7023
7154
  let beforePosition = null;
7024
7155
  let afterPosition = null;
7025
7156
  if (index < targetIndex) {
7026
- afterPosition = targetIndex === this.#items.length - 1 ? void 0 : this.#items[targetIndex + 1]._parentPos;
7027
- beforePosition = this.#items[targetIndex]._parentPos;
7157
+ afterPosition = targetIndex === this.#items.length - 1 ? void 0 : _optionalChain([this, 'access', _162 => _162.#items, 'access', _163 => _163.at, 'call', _164 => _164(targetIndex + 1), 'optionalAccess', _165 => _165._parentPos]);
7158
+ beforePosition = this.#items.at(targetIndex)._parentPos;
7028
7159
  } else {
7029
- afterPosition = this.#items[targetIndex]._parentPos;
7030
- beforePosition = targetIndex === 0 ? void 0 : this.#items[targetIndex - 1]._parentPos;
7160
+ afterPosition = this.#items.at(targetIndex)._parentPos;
7161
+ beforePosition = targetIndex === 0 ? void 0 : _optionalChain([this, 'access', _166 => _166.#items, 'access', _167 => _167.at, 'call', _168 => _168(targetIndex - 1), 'optionalAccess', _169 => _169._parentPos]);
7031
7162
  }
7032
7163
  const position = makePosition(beforePosition, afterPosition);
7033
- const item = this.#items[index];
7164
+ const item = this.#items.at(index);
7034
7165
  const previousPosition = item._getParentKeyOrThrow();
7035
- item._setParentLink(this, position);
7036
- this._sortItems();
7166
+ this.#updateItemPositionAt(index, position);
7037
7167
  if (this._pool && this._id) {
7038
7168
  const storageUpdates = /* @__PURE__ */ new Map([
7039
7169
  [this._id, makeUpdate(this, [moveDelta(index, targetIndex, item)])]
@@ -7063,15 +7193,15 @@ var LiveList = class _LiveList extends AbstractCrdt {
7063
7193
  * @param index The index of the element to delete
7064
7194
  */
7065
7195
  delete(index) {
7066
- _optionalChain([this, 'access', _148 => _148._pool, 'optionalAccess', _149 => _149.assertStorageIsWritable, 'call', _150 => _150()]);
7196
+ _optionalChain([this, 'access', _170 => _170._pool, 'optionalAccess', _171 => _171.assertStorageIsWritable, 'call', _172 => _172()]);
7067
7197
  if (index < 0 || index >= this.#items.length) {
7068
7198
  throw new Error(
7069
7199
  `Cannot delete list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
7070
7200
  );
7071
7201
  }
7072
- const item = this.#items[index];
7202
+ const item = this.#items.at(index);
7073
7203
  item._detach();
7074
- const [prev] = this.#items.splice(index, 1);
7204
+ this.#items.remove(item);
7075
7205
  this.invalidate();
7076
7206
  if (this._pool) {
7077
7207
  const childRecordId = item._id;
@@ -7079,7 +7209,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
7079
7209
  const storageUpdates = /* @__PURE__ */ new Map();
7080
7210
  storageUpdates.set(
7081
7211
  nn(this._id),
7082
- makeUpdate(this, [deleteDelta(index, prev)])
7212
+ makeUpdate(this, [deleteDelta(index, item)])
7083
7213
  );
7084
7214
  this._pool.dispatch(
7085
7215
  [
@@ -7096,7 +7226,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
7096
7226
  }
7097
7227
  }
7098
7228
  clear() {
7099
- _optionalChain([this, 'access', _151 => _151._pool, 'optionalAccess', _152 => _152.assertStorageIsWritable, 'call', _153 => _153()]);
7229
+ _optionalChain([this, 'access', _173 => _173._pool, 'optionalAccess', _174 => _174.assertStorageIsWritable, 'call', _175 => _175()]);
7100
7230
  if (this._pool) {
7101
7231
  const ops = [];
7102
7232
  const reverseOps = [];
@@ -7116,7 +7246,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
7116
7246
  updateDelta.push(deleteDelta(0, item));
7117
7247
  }
7118
7248
  }
7119
- this.#items = [];
7249
+ this.#items.clear();
7120
7250
  this.invalidate();
7121
7251
  const storageUpdates = /* @__PURE__ */ new Map();
7122
7252
  storageUpdates.set(nn(this._id), makeUpdate(this, updateDelta));
@@ -7125,24 +7255,25 @@ var LiveList = class _LiveList extends AbstractCrdt {
7125
7255
  for (const item of this.#items) {
7126
7256
  item._detach();
7127
7257
  }
7128
- this.#items = [];
7258
+ this.#items.clear();
7129
7259
  this.invalidate();
7130
7260
  }
7131
7261
  }
7132
7262
  set(index, item) {
7133
- _optionalChain([this, 'access', _154 => _154._pool, 'optionalAccess', _155 => _155.assertStorageIsWritable, 'call', _156 => _156()]);
7263
+ _optionalChain([this, 'access', _176 => _176._pool, 'optionalAccess', _177 => _177.assertStorageIsWritable, 'call', _178 => _178()]);
7134
7264
  if (index < 0 || index >= this.#items.length) {
7135
7265
  throw new Error(
7136
7266
  `Cannot set list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
7137
7267
  );
7138
7268
  }
7139
- const existingItem = this.#items[index];
7269
+ const existingItem = this.#items.at(index);
7140
7270
  const position = existingItem._getParentKeyOrThrow();
7141
7271
  const existingId = existingItem._id;
7142
7272
  existingItem._detach();
7143
7273
  const value = lsonToLiveNode(item);
7144
7274
  value._setParentLink(this, position);
7145
- this.#items[index] = value;
7275
+ this.#items.remove(existingItem);
7276
+ this.#items.add(value);
7146
7277
  this.invalidate();
7147
7278
  if (this._pool && this._id) {
7148
7279
  const id = this._pool.generateId();
@@ -7165,11 +7296,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
7165
7296
  * Returns an Array of all the elements in the LiveList.
7166
7297
  */
7167
7298
  toArray() {
7168
- return this.#items.map(
7169
- (entry) => liveNodeToLson(entry)
7170
- // ^^^^^^^^
7171
- // FIXME! This isn't safe.
7172
- );
7299
+ return Array.from(this.#items, (entry) => liveNodeToLson(entry));
7173
7300
  }
7174
7301
  /**
7175
7302
  * Tests whether all elements pass the test implemented by the provided function.
@@ -7219,7 +7346,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
7219
7346
  if (index < 0 || index >= this.#items.length) {
7220
7347
  return void 0;
7221
7348
  }
7222
- return liveNodeToLson(this.#items[index]);
7349
+ const item = this.#items.at(index);
7350
+ return item ? liveNodeToLson(item) : void 0;
7223
7351
  }
7224
7352
  /**
7225
7353
  * Returns the first index at which a given element can be found in the LiveList, or -1 if it is not present.
@@ -7245,14 +7373,20 @@ var LiveList = class _LiveList extends AbstractCrdt {
7245
7373
  * @returns An array with each element being the result of the callback function.
7246
7374
  */
7247
7375
  map(callback) {
7248
- return this.#items.map(
7249
- (entry, i) => callback(
7250
- liveNodeToLson(entry),
7251
- // ^^^^^^^^
7252
- // FIXME! This isn't safe.
7253
- i
7254
- )
7255
- );
7376
+ const result = [];
7377
+ let i = 0;
7378
+ for (const entry of this.#items) {
7379
+ result.push(
7380
+ callback(
7381
+ liveNodeToLson(entry),
7382
+ // ^^^^^^^^
7383
+ // FIXME! This isn't safe.
7384
+ i
7385
+ )
7386
+ );
7387
+ i++;
7388
+ }
7389
+ return result;
7256
7390
  }
7257
7391
  /**
7258
7392
  * Tests whether at least one element in the LiveList passes the test implemented by the provided function.
@@ -7269,26 +7403,30 @@ var LiveList = class _LiveList extends AbstractCrdt {
7269
7403
  const newItem = creationOpToLiveNode(op);
7270
7404
  newItem._attach(op.id, nn(this._pool));
7271
7405
  newItem._setParentLink(this, key);
7272
- this._insertAndSort(newItem);
7406
+ this.#insert(newItem);
7273
7407
  const newIndex = this._indexOfPosition(key);
7274
7408
  return { newItem, newIndex };
7275
7409
  }
7276
7410
  #shiftItemPosition(index, key) {
7277
7411
  const shiftedPosition = makePosition(
7278
7412
  key,
7279
- this.#items.length > index + 1 ? _optionalChain([this, 'access', _157 => _157.#items, 'access', _158 => _158[index + 1], 'optionalAccess', _159 => _159._parentPos]) : void 0
7413
+ this.#items.length > index + 1 ? _optionalChain([this, 'access', _179 => _179.#items, 'access', _180 => _180.at, 'call', _181 => _181(index + 1), 'optionalAccess', _182 => _182._parentPos]) : void 0
7280
7414
  );
7281
- this.#items[index]._setParentLink(this, shiftedPosition);
7415
+ this.#updateItemPositionAt(index, shiftedPosition);
7282
7416
  }
7283
7417
  /** @internal */
7284
7418
  _toTreeNode(key) {
7419
+ const payload = [];
7420
+ let index = 0;
7421
+ for (const item of this.#items) {
7422
+ payload.push(item.toTreeNode(index.toString()));
7423
+ index++;
7424
+ }
7285
7425
  return {
7286
7426
  type: "LiveList",
7287
7427
  id: _nullishCoalesce(this._id, () => ( nanoid())),
7288
7428
  key,
7289
- payload: this.#items.map(
7290
- (item, index) => item.toTreeNode(index.toString())
7291
- )
7429
+ payload
7292
7430
  };
7293
7431
  }
7294
7432
  toImmutable() {
@@ -7296,11 +7434,13 @@ var LiveList = class _LiveList extends AbstractCrdt {
7296
7434
  }
7297
7435
  /** @internal */
7298
7436
  _toImmutable() {
7299
- const result = this.#items.map((node) => node.toImmutable());
7437
+ const result = Array.from(this.#items, (node) => node.toImmutable());
7300
7438
  return process.env.NODE_ENV === "production" ? result : Object.freeze(result);
7301
7439
  }
7302
7440
  clone() {
7303
- return new _LiveList(this.#items.map((item) => item.clone()));
7441
+ return new _LiveList(
7442
+ Array.from(this.#items, (item) => item.clone())
7443
+ );
7304
7444
  }
7305
7445
  };
7306
7446
  var LiveListIterator = class {
@@ -7407,7 +7547,9 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
7407
7547
  };
7408
7548
  ops.push(op);
7409
7549
  for (const [key, value] of this.#map) {
7410
- ops.push(...value._toOps(this._id, key));
7550
+ for (const childOp of value._toOps(this._id, key)) {
7551
+ ops.push(childOp);
7552
+ }
7411
7553
  }
7412
7554
  return ops;
7413
7555
  }
@@ -7541,7 +7683,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
7541
7683
  * @param value The value of the element to add. Should be serializable to JSON.
7542
7684
  */
7543
7685
  set(key, value) {
7544
- _optionalChain([this, 'access', _160 => _160._pool, 'optionalAccess', _161 => _161.assertStorageIsWritable, 'call', _162 => _162()]);
7686
+ _optionalChain([this, 'access', _183 => _183._pool, 'optionalAccess', _184 => _184.assertStorageIsWritable, 'call', _185 => _185()]);
7545
7687
  const oldValue = this.#map.get(key);
7546
7688
  if (oldValue) {
7547
7689
  oldValue._detach();
@@ -7587,7 +7729,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
7587
7729
  * @returns true if an element existed and has been removed, or false if the element does not exist.
7588
7730
  */
7589
7731
  delete(key) {
7590
- _optionalChain([this, 'access', _163 => _163._pool, 'optionalAccess', _164 => _164.assertStorageIsWritable, 'call', _165 => _165()]);
7732
+ _optionalChain([this, 'access', _186 => _186._pool, 'optionalAccess', _187 => _187.assertStorageIsWritable, 'call', _188 => _188()]);
7591
7733
  const item = this.#map.get(key);
7592
7734
  if (item === void 0) {
7593
7735
  return false;
@@ -7806,7 +7948,9 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7806
7948
  ops.push(op);
7807
7949
  for (const [key, value] of this.#map) {
7808
7950
  if (isLiveNode(value)) {
7809
- ops.push(...value._toOps(this._id, key));
7951
+ for (const childOp of value._toOps(this._id, key)) {
7952
+ ops.push(childOp);
7953
+ }
7810
7954
  } else {
7811
7955
  op.data[key] = value;
7812
7956
  }
@@ -7975,7 +8119,9 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
7975
8119
  for (const key in op.data) {
7976
8120
  const oldValue = this.#map.get(key);
7977
8121
  if (isLiveNode(oldValue)) {
7978
- reverse.push(...oldValue._toOps(id, key));
8122
+ for (const childOp of oldValue._toOps(id, key)) {
8123
+ reverse.push(childOp);
8124
+ }
7979
8125
  oldValue._detach();
7980
8126
  } else if (oldValue !== void 0) {
7981
8127
  reverseUpdate.data[key] = oldValue;
@@ -8068,7 +8214,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
8068
8214
  * @param value The value of the property to add
8069
8215
  */
8070
8216
  set(key, value) {
8071
- _optionalChain([this, 'access', _166 => _166._pool, 'optionalAccess', _167 => _167.assertStorageIsWritable, 'call', _168 => _168()]);
8217
+ _optionalChain([this, 'access', _189 => _189._pool, 'optionalAccess', _190 => _190.assertStorageIsWritable, 'call', _191 => _191()]);
8072
8218
  this.update({ [key]: value });
8073
8219
  }
8074
8220
  /**
@@ -8083,7 +8229,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
8083
8229
  * @param key The key of the property to delete
8084
8230
  */
8085
8231
  delete(key) {
8086
- _optionalChain([this, 'access', _169 => _169._pool, 'optionalAccess', _170 => _170.assertStorageIsWritable, 'call', _171 => _171()]);
8232
+ _optionalChain([this, 'access', _192 => _192._pool, 'optionalAccess', _193 => _193.assertStorageIsWritable, 'call', _194 => _194()]);
8087
8233
  const keyAsString = key;
8088
8234
  const oldValue = this.#map.get(keyAsString);
8089
8235
  if (oldValue === void 0) {
@@ -8138,7 +8284,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
8138
8284
  * @param patch The object used to overrides properties
8139
8285
  */
8140
8286
  update(patch) {
8141
- _optionalChain([this, 'access', _172 => _172._pool, 'optionalAccess', _173 => _173.assertStorageIsWritable, 'call', _174 => _174()]);
8287
+ _optionalChain([this, 'access', _195 => _195._pool, 'optionalAccess', _196 => _196.assertStorageIsWritable, 'call', _197 => _197()]);
8142
8288
  if (_LiveObject.detectLargeObjects) {
8143
8289
  const data = {};
8144
8290
  for (const [key, value] of this.#map) {
@@ -8199,7 +8345,9 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
8199
8345
  }
8200
8346
  const oldValue = this.#map.get(key);
8201
8347
  if (isLiveNode(oldValue)) {
8202
- reverseOps.push(...oldValue._toOps(this._id, key));
8348
+ for (const childOp of oldValue._toOps(this._id, key)) {
8349
+ reverseOps.push(childOp);
8350
+ }
8203
8351
  oldValue._detach();
8204
8352
  } else if (oldValue === void 0) {
8205
8353
  reverseOps.push({ type: OpCode.DELETE_OBJECT_KEY, id: this._id, key });
@@ -8220,7 +8368,9 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
8220
8368
  if (createCrdtOp) {
8221
8369
  this.#unackedOpsByKey.set(key, nn(createCrdtOp.opId));
8222
8370
  }
8223
- ops.push(...newAttachChildOps);
8371
+ for (const childOp of newAttachChildOps) {
8372
+ ops.push(childOp);
8373
+ }
8224
8374
  } else {
8225
8375
  updatedProps[key] = newValue;
8226
8376
  this.#unackedOpsByKey.set(key, opId);
@@ -8869,15 +9019,15 @@ function installBackgroundTabSpy() {
8869
9019
  const doc = typeof document !== "undefined" ? document : void 0;
8870
9020
  const inBackgroundSince = { current: null };
8871
9021
  function onVisibilityChange() {
8872
- if (_optionalChain([doc, 'optionalAccess', _175 => _175.visibilityState]) === "hidden") {
9022
+ if (_optionalChain([doc, 'optionalAccess', _198 => _198.visibilityState]) === "hidden") {
8873
9023
  inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
8874
9024
  } else {
8875
9025
  inBackgroundSince.current = null;
8876
9026
  }
8877
9027
  }
8878
- _optionalChain([doc, 'optionalAccess', _176 => _176.addEventListener, 'call', _177 => _177("visibilitychange", onVisibilityChange)]);
9028
+ _optionalChain([doc, 'optionalAccess', _199 => _199.addEventListener, 'call', _200 => _200("visibilitychange", onVisibilityChange)]);
8879
9029
  const unsub = () => {
8880
- _optionalChain([doc, 'optionalAccess', _178 => _178.removeEventListener, 'call', _179 => _179("visibilitychange", onVisibilityChange)]);
9030
+ _optionalChain([doc, 'optionalAccess', _201 => _201.removeEventListener, 'call', _202 => _202("visibilitychange", onVisibilityChange)]);
8881
9031
  };
8882
9032
  return [inBackgroundSince, unsub];
8883
9033
  }
@@ -9063,7 +9213,7 @@ function createRoom(options, config) {
9063
9213
  }
9064
9214
  }
9065
9215
  function isStorageWritable() {
9066
- const scopes = _optionalChain([context, 'access', _180 => _180.dynamicSessionInfoSig, 'access', _181 => _181.get, 'call', _182 => _182(), 'optionalAccess', _183 => _183.scopes]);
9216
+ const scopes = _optionalChain([context, 'access', _203 => _203.dynamicSessionInfoSig, 'access', _204 => _204.get, 'call', _205 => _205(), 'optionalAccess', _206 => _206.scopes]);
9067
9217
  return scopes !== void 0 ? canWriteStorage(scopes) : true;
9068
9218
  }
9069
9219
  const eventHub = {
@@ -9194,7 +9344,7 @@ function createRoom(options, config) {
9194
9344
  // be stuck in "synchronizing" forever).
9195
9345
  case "experimental-fallback-to-http": {
9196
9346
  warn("Message is too large for websockets, so sending over HTTP instead");
9197
- const nonce = _nullishCoalesce(_optionalChain([context, 'access', _184 => _184.dynamicSessionInfoSig, 'access', _185 => _185.get, 'call', _186 => _186(), 'optionalAccess', _187 => _187.nonce]), () => ( raise("Session is not authorized to send message over HTTP")));
9347
+ const nonce = _nullishCoalesce(_optionalChain([context, 'access', _207 => _207.dynamicSessionInfoSig, 'access', _208 => _208.get, 'call', _209 => _209(), 'optionalAccess', _210 => _210.nonce]), () => ( raise("Session is not authorized to send message over HTTP")));
9198
9348
  void httpClient.sendMessagesOverHTTP({ roomId, nonce, messages }).then((resp) => {
9199
9349
  if (!resp.ok && resp.status === 403) {
9200
9350
  managedSocket.reconnect();
@@ -9241,15 +9391,24 @@ function createRoom(options, config) {
9241
9391
  (me) => me !== null ? userToTreeNode("Me", me) : null
9242
9392
  );
9243
9393
  function createOrUpdateRootFromMessage(nodes) {
9394
+ if (nodes.size === 0) {
9395
+ throw new Error("Internal error: cannot load storage without items");
9396
+ }
9244
9397
  if (context.root !== void 0) {
9245
- updateRoot(nodes);
9398
+ const currentItems = /* @__PURE__ */ new Map();
9399
+ for (const [id, crdt] of context.pool.nodes) {
9400
+ currentItems.set(id, crdt._serialize());
9401
+ }
9402
+ const ops = getTreesDiffOperations(currentItems, nodes);
9403
+ const result = applyRemoteOps(ops);
9404
+ notify(result.updates);
9246
9405
  } else {
9247
9406
  context.root = LiveObject._fromItems(
9248
9407
  nodes,
9249
9408
  context.pool
9250
9409
  );
9251
9410
  }
9252
- const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _188 => _188.get, 'call', _189 => _189(), 'optionalAccess', _190 => _190.canWrite]), () => ( true));
9411
+ const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _211 => _211.get, 'call', _212 => _212(), 'optionalAccess', _213 => _213.canWrite]), () => ( true));
9253
9412
  const stackSizeBefore = context.undoStack.length;
9254
9413
  for (const key in context.initialStorage) {
9255
9414
  if (context.root.get(key) === void 0) {
@@ -9264,21 +9423,6 @@ function createRoom(options, config) {
9264
9423
  }
9265
9424
  context.undoStack.length = stackSizeBefore;
9266
9425
  }
9267
- function updateRoot(nodes) {
9268
- if (nodes.size === 0) {
9269
- throw new Error("Internal error: cannot load storage without items");
9270
- }
9271
- if (context.root === void 0) {
9272
- return;
9273
- }
9274
- const currentItems = /* @__PURE__ */ new Map();
9275
- for (const [id, crdt] of context.pool.nodes) {
9276
- currentItems.set(id, crdt._serialize());
9277
- }
9278
- const ops = getTreesDiffOperations(currentItems, nodes);
9279
- const result = applyRemoteOps(ops);
9280
- notify(result.updates);
9281
- }
9282
9426
  function _addToRealUndoStack(frames) {
9283
9427
  if (context.undoStack.length >= 50) {
9284
9428
  context.undoStack.shift();
@@ -9468,7 +9612,7 @@ function createRoom(options, config) {
9468
9612
  }
9469
9613
  context.myPresence.patch(patch);
9470
9614
  if (context.activeBatch) {
9471
- if (_optionalChain([options2, 'optionalAccess', _191 => _191.addToHistory])) {
9615
+ if (_optionalChain([options2, 'optionalAccess', _214 => _214.addToHistory])) {
9472
9616
  context.activeBatch.reverseOps.pushLeft({
9473
9617
  type: "presence",
9474
9618
  data: oldValues
@@ -9477,7 +9621,7 @@ function createRoom(options, config) {
9477
9621
  context.activeBatch.updates.presence = true;
9478
9622
  } else {
9479
9623
  flushNowOrSoon();
9480
- if (_optionalChain([options2, 'optionalAccess', _192 => _192.addToHistory])) {
9624
+ if (_optionalChain([options2, 'optionalAccess', _215 => _215.addToHistory])) {
9481
9625
  addToUndoStack([{ type: "presence", data: oldValues }]);
9482
9626
  }
9483
9627
  notify({ presence: true });
@@ -9802,7 +9946,7 @@ function createRoom(options, config) {
9802
9946
  const unacknowledgedOps = new Map(context.unacknowledgedOps);
9803
9947
  createOrUpdateRootFromMessage(nodes);
9804
9948
  applyAndSendOfflineOps(unacknowledgedOps);
9805
- _optionalChain([_resolveStoragePromise, 'optionalCall', _193 => _193()]);
9949
+ _optionalChain([_resolveStoragePromise, 'optionalCall', _216 => _216()]);
9806
9950
  notifyStorageStatus();
9807
9951
  eventHub.storageDidLoad.notify();
9808
9952
  }
@@ -10022,8 +10166,8 @@ function createRoom(options, config) {
10022
10166
  async function getThreads(options2) {
10023
10167
  return httpClient.getThreads({
10024
10168
  roomId,
10025
- query: _optionalChain([options2, 'optionalAccess', _194 => _194.query]),
10026
- cursor: _optionalChain([options2, 'optionalAccess', _195 => _195.cursor])
10169
+ query: _optionalChain([options2, 'optionalAccess', _217 => _217.query]),
10170
+ cursor: _optionalChain([options2, 'optionalAccess', _218 => _218.cursor])
10027
10171
  });
10028
10172
  }
10029
10173
  async function getThread(threadId) {
@@ -10145,7 +10289,7 @@ function createRoom(options, config) {
10145
10289
  function getSubscriptionSettings(options2) {
10146
10290
  return httpClient.getSubscriptionSettings({
10147
10291
  roomId,
10148
- signal: _optionalChain([options2, 'optionalAccess', _196 => _196.signal])
10292
+ signal: _optionalChain([options2, 'optionalAccess', _219 => _219.signal])
10149
10293
  });
10150
10294
  }
10151
10295
  function updateSubscriptionSettings(settings) {
@@ -10167,7 +10311,7 @@ function createRoom(options, config) {
10167
10311
  {
10168
10312
  [kInternal]: {
10169
10313
  get presenceBuffer() {
10170
- return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _197 => _197.buffer, 'access', _198 => _198.presenceUpdates, 'optionalAccess', _199 => _199.data]), () => ( null)));
10314
+ return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _220 => _220.buffer, 'access', _221 => _221.presenceUpdates, 'optionalAccess', _222 => _222.data]), () => ( null)));
10171
10315
  },
10172
10316
  // prettier-ignore
10173
10317
  get undoStack() {
@@ -10182,9 +10326,9 @@ function createRoom(options, config) {
10182
10326
  return context.yjsProvider;
10183
10327
  },
10184
10328
  setYjsProvider(newProvider) {
10185
- _optionalChain([context, 'access', _200 => _200.yjsProvider, 'optionalAccess', _201 => _201.off, 'call', _202 => _202("status", yjsStatusDidChange)]);
10329
+ _optionalChain([context, 'access', _223 => _223.yjsProvider, 'optionalAccess', _224 => _224.off, 'call', _225 => _225("status", yjsStatusDidChange)]);
10186
10330
  context.yjsProvider = newProvider;
10187
- _optionalChain([newProvider, 'optionalAccess', _203 => _203.on, 'call', _204 => _204("status", yjsStatusDidChange)]);
10331
+ _optionalChain([newProvider, 'optionalAccess', _226 => _226.on, 'call', _227 => _227("status", yjsStatusDidChange)]);
10188
10332
  context.yjsProviderDidChange.notify();
10189
10333
  },
10190
10334
  yjsProviderDidChange: context.yjsProviderDidChange.observable,
@@ -10230,7 +10374,7 @@ function createRoom(options, config) {
10230
10374
  source.dispose();
10231
10375
  }
10232
10376
  eventHub.roomWillDestroy.notify();
10233
- _optionalChain([context, 'access', _205 => _205.yjsProvider, 'optionalAccess', _206 => _206.off, 'call', _207 => _207("status", yjsStatusDidChange)]);
10377
+ _optionalChain([context, 'access', _228 => _228.yjsProvider, 'optionalAccess', _229 => _229.off, 'call', _230 => _230("status", yjsStatusDidChange)]);
10234
10378
  syncSourceForStorage.destroy();
10235
10379
  syncSourceForYjs.destroy();
10236
10380
  uninstallBgTabSpy();
@@ -10381,7 +10525,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
10381
10525
  }
10382
10526
  if (isLiveNode(first)) {
10383
10527
  const node = first;
10384
- if (_optionalChain([options, 'optionalAccess', _208 => _208.isDeep])) {
10528
+ if (_optionalChain([options, 'optionalAccess', _231 => _231.isDeep])) {
10385
10529
  const storageCallback = second;
10386
10530
  return subscribeToLiveStructureDeeply(node, storageCallback);
10387
10531
  } else {
@@ -10463,8 +10607,8 @@ function createClient(options) {
10463
10607
  const authManager = createAuthManager(options, (token) => {
10464
10608
  currentUserId.set(() => token.uid);
10465
10609
  });
10466
- const fetchPolyfill = _optionalChain([clientOptions, 'access', _209 => _209.polyfills, 'optionalAccess', _210 => _210.fetch]) || /* istanbul ignore next */
10467
- _optionalChain([globalThis, 'access', _211 => _211.fetch, 'optionalAccess', _212 => _212.bind, 'call', _213 => _213(globalThis)]);
10610
+ const fetchPolyfill = _optionalChain([clientOptions, 'access', _232 => _232.polyfills, 'optionalAccess', _233 => _233.fetch]) || /* istanbul ignore next */
10611
+ _optionalChain([globalThis, 'access', _234 => _234.fetch, 'optionalAccess', _235 => _235.bind, 'call', _236 => _236(globalThis)]);
10468
10612
  const httpClient = createApiClient({
10469
10613
  baseUrl,
10470
10614
  fetchPolyfill,
@@ -10482,7 +10626,7 @@ function createClient(options) {
10482
10626
  delegates: {
10483
10627
  createSocket: makeCreateSocketDelegateForAi(
10484
10628
  baseUrl,
10485
- _optionalChain([clientOptions, 'access', _214 => _214.polyfills, 'optionalAccess', _215 => _215.WebSocket])
10629
+ _optionalChain([clientOptions, 'access', _237 => _237.polyfills, 'optionalAccess', _238 => _238.WebSocket])
10486
10630
  ),
10487
10631
  authenticate: async () => {
10488
10632
  const resp = await authManager.getAuthValue({
@@ -10542,7 +10686,7 @@ function createClient(options) {
10542
10686
  createSocket: makeCreateSocketDelegateForRoom(
10543
10687
  roomId,
10544
10688
  baseUrl,
10545
- _optionalChain([clientOptions, 'access', _216 => _216.polyfills, 'optionalAccess', _217 => _217.WebSocket]),
10689
+ _optionalChain([clientOptions, 'access', _239 => _239.polyfills, 'optionalAccess', _240 => _240.WebSocket]),
10546
10690
  options2.engine
10547
10691
  ),
10548
10692
  authenticate: makeAuthDelegateForRoom(roomId, authManager)
@@ -10567,7 +10711,7 @@ function createClient(options) {
10567
10711
  const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
10568
10712
  if (shouldConnect) {
10569
10713
  if (typeof atob === "undefined") {
10570
- if (_optionalChain([clientOptions, 'access', _218 => _218.polyfills, 'optionalAccess', _219 => _219.atob]) === void 0) {
10714
+ if (_optionalChain([clientOptions, 'access', _241 => _241.polyfills, 'optionalAccess', _242 => _242.atob]) === void 0) {
10571
10715
  throw new Error(
10572
10716
  "You need to polyfill atob to use the client in your environment. Please follow the instructions at https://liveblocks.io/docs/errors/liveblocks-client/atob-polyfill"
10573
10717
  );
@@ -10579,7 +10723,7 @@ function createClient(options) {
10579
10723
  return leaseRoom(newRoomDetails);
10580
10724
  }
10581
10725
  function getRoom(roomId) {
10582
- const room = _optionalChain([roomsById, 'access', _220 => _220.get, 'call', _221 => _221(roomId), 'optionalAccess', _222 => _222.room]);
10726
+ const room = _optionalChain([roomsById, 'access', _243 => _243.get, 'call', _244 => _244(roomId), 'optionalAccess', _245 => _245.room]);
10583
10727
  return room ? room : null;
10584
10728
  }
10585
10729
  function logout() {
@@ -10595,7 +10739,7 @@ function createClient(options) {
10595
10739
  const batchedResolveUsers = new Batch(
10596
10740
  async (batchedUserIds) => {
10597
10741
  const userIds = batchedUserIds.flat();
10598
- const users = await _optionalChain([resolveUsers, 'optionalCall', _223 => _223({ userIds })]);
10742
+ const users = await _optionalChain([resolveUsers, 'optionalCall', _246 => _246({ userIds })]);
10599
10743
  warnOnceIf(
10600
10744
  !resolveUsers,
10601
10745
  "Set the resolveUsers option in createClient to specify user info."
@@ -10612,7 +10756,7 @@ function createClient(options) {
10612
10756
  const batchedResolveRoomsInfo = new Batch(
10613
10757
  async (batchedRoomIds) => {
10614
10758
  const roomIds = batchedRoomIds.flat();
10615
- const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _224 => _224({ roomIds })]);
10759
+ const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _247 => _247({ roomIds })]);
10616
10760
  warnOnceIf(
10617
10761
  !resolveRoomsInfo,
10618
10762
  "Set the resolveRoomsInfo option in createClient to specify room info."
@@ -10629,7 +10773,7 @@ function createClient(options) {
10629
10773
  const batchedResolveGroupsInfo = new Batch(
10630
10774
  async (batchedGroupIds) => {
10631
10775
  const groupIds = batchedGroupIds.flat();
10632
- const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall', _225 => _225({ groupIds })]);
10776
+ const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall', _248 => _248({ groupIds })]);
10633
10777
  warnOnceIf(
10634
10778
  !resolveGroupsInfo,
10635
10779
  "Set the resolveGroupsInfo option in createClient to specify group info."
@@ -10685,7 +10829,7 @@ function createClient(options) {
10685
10829
  }
10686
10830
  };
10687
10831
  const win = typeof window !== "undefined" ? window : void 0;
10688
- _optionalChain([win, 'optionalAccess', _226 => _226.addEventListener, 'call', _227 => _227("beforeunload", maybePreventClose)]);
10832
+ _optionalChain([win, 'optionalAccess', _249 => _249.addEventListener, 'call', _250 => _250("beforeunload", maybePreventClose)]);
10689
10833
  }
10690
10834
  async function getNotificationSettings(options2) {
10691
10835
  const plainSettings = await httpClient.getNotificationSettings(options2);
@@ -10812,7 +10956,7 @@ var commentBodyElementsTypes = {
10812
10956
  mention: "inline"
10813
10957
  };
10814
10958
  function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
10815
- if (!body || !_optionalChain([body, 'optionalAccess', _228 => _228.content])) {
10959
+ if (!body || !_optionalChain([body, 'optionalAccess', _251 => _251.content])) {
10816
10960
  return;
10817
10961
  }
10818
10962
  const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
@@ -10822,13 +10966,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
10822
10966
  for (const block of body.content) {
10823
10967
  if (type === "all" || type === "block") {
10824
10968
  if (guard(block)) {
10825
- _optionalChain([visitor, 'optionalCall', _229 => _229(block)]);
10969
+ _optionalChain([visitor, 'optionalCall', _252 => _252(block)]);
10826
10970
  }
10827
10971
  }
10828
10972
  if (type === "all" || type === "inline") {
10829
10973
  for (const inline of block.children) {
10830
10974
  if (guard(inline)) {
10831
- _optionalChain([visitor, 'optionalCall', _230 => _230(inline)]);
10975
+ _optionalChain([visitor, 'optionalCall', _253 => _253(inline)]);
10832
10976
  }
10833
10977
  }
10834
10978
  }
@@ -10998,7 +11142,7 @@ var stringifyCommentBodyPlainElements = {
10998
11142
  text: ({ element }) => element.text,
10999
11143
  link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
11000
11144
  mention: ({ element, user, group }) => {
11001
- return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _231 => _231.name]), () => ( _optionalChain([group, 'optionalAccess', _232 => _232.name]))), () => ( element.id))}`;
11145
+ return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _254 => _254.name]), () => ( _optionalChain([group, 'optionalAccess', _255 => _255.name]))), () => ( element.id))}`;
11002
11146
  }
11003
11147
  };
11004
11148
  var stringifyCommentBodyHtmlElements = {
@@ -11028,7 +11172,7 @@ var stringifyCommentBodyHtmlElements = {
11028
11172
  return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
11029
11173
  },
11030
11174
  mention: ({ element, user, group }) => {
11031
- return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _233 => _233.name]) ? html`${_optionalChain([user, 'optionalAccess', _234 => _234.name])}` : _optionalChain([group, 'optionalAccess', _235 => _235.name]) ? html`${_optionalChain([group, 'optionalAccess', _236 => _236.name])}` : element.id}</span>`;
11175
+ return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _256 => _256.name]) ? html`${_optionalChain([user, 'optionalAccess', _257 => _257.name])}` : _optionalChain([group, 'optionalAccess', _258 => _258.name]) ? html`${_optionalChain([group, 'optionalAccess', _259 => _259.name])}` : element.id}</span>`;
11032
11176
  }
11033
11177
  };
11034
11178
  var stringifyCommentBodyMarkdownElements = {
@@ -11058,20 +11202,20 @@ var stringifyCommentBodyMarkdownElements = {
11058
11202
  return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
11059
11203
  },
11060
11204
  mention: ({ element, user, group }) => {
11061
- return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _237 => _237.name]), () => ( _optionalChain([group, 'optionalAccess', _238 => _238.name]))), () => ( element.id))}`;
11205
+ return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _260 => _260.name]), () => ( _optionalChain([group, 'optionalAccess', _261 => _261.name]))), () => ( element.id))}`;
11062
11206
  }
11063
11207
  };
11064
11208
  async function stringifyCommentBody(body, options) {
11065
- const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _239 => _239.format]), () => ( "plain"));
11066
- const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _240 => _240.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
11209
+ const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _262 => _262.format]), () => ( "plain"));
11210
+ const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _263 => _263.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
11067
11211
  const elements = {
11068
11212
  ...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
11069
- ..._optionalChain([options, 'optionalAccess', _241 => _241.elements])
11213
+ ..._optionalChain([options, 'optionalAccess', _264 => _264.elements])
11070
11214
  };
11071
11215
  const { users: resolvedUsers, groups: resolvedGroupsInfo } = await resolveMentionsInCommentBody(
11072
11216
  body,
11073
- _optionalChain([options, 'optionalAccess', _242 => _242.resolveUsers]),
11074
- _optionalChain([options, 'optionalAccess', _243 => _243.resolveGroupsInfo])
11217
+ _optionalChain([options, 'optionalAccess', _265 => _265.resolveUsers]),
11218
+ _optionalChain([options, 'optionalAccess', _266 => _266.resolveGroupsInfo])
11075
11219
  );
11076
11220
  const blocks = body.content.flatMap((block, blockIndex) => {
11077
11221
  switch (block.type) {
@@ -11358,12 +11502,12 @@ function legacy_patchImmutableNode(state, path, update) {
11358
11502
  }
11359
11503
  const newState = Object.assign({}, state);
11360
11504
  for (const key in update.updates) {
11361
- if (_optionalChain([update, 'access', _244 => _244.updates, 'access', _245 => _245[key], 'optionalAccess', _246 => _246.type]) === "update") {
11505
+ if (_optionalChain([update, 'access', _267 => _267.updates, 'access', _268 => _268[key], 'optionalAccess', _269 => _269.type]) === "update") {
11362
11506
  const val = update.node.get(key);
11363
11507
  if (val !== void 0) {
11364
11508
  newState[key] = lsonToJson(val);
11365
11509
  }
11366
- } else if (_optionalChain([update, 'access', _247 => _247.updates, 'access', _248 => _248[key], 'optionalAccess', _249 => _249.type]) === "delete") {
11510
+ } else if (_optionalChain([update, 'access', _270 => _270.updates, 'access', _271 => _271[key], 'optionalAccess', _272 => _272.type]) === "delete") {
11367
11511
  delete newState[key];
11368
11512
  }
11369
11513
  }
@@ -11424,12 +11568,12 @@ function legacy_patchImmutableNode(state, path, update) {
11424
11568
  }
11425
11569
  const newState = Object.assign({}, state);
11426
11570
  for (const key in update.updates) {
11427
- if (_optionalChain([update, 'access', _250 => _250.updates, 'access', _251 => _251[key], 'optionalAccess', _252 => _252.type]) === "update") {
11571
+ if (_optionalChain([update, 'access', _273 => _273.updates, 'access', _274 => _274[key], 'optionalAccess', _275 => _275.type]) === "update") {
11428
11572
  const value = update.node.get(key);
11429
11573
  if (value !== void 0) {
11430
11574
  newState[key] = lsonToJson(value);
11431
11575
  }
11432
- } else if (_optionalChain([update, 'access', _253 => _253.updates, 'access', _254 => _254[key], 'optionalAccess', _255 => _255.type]) === "delete") {
11576
+ } else if (_optionalChain([update, 'access', _276 => _276.updates, 'access', _277 => _277[key], 'optionalAccess', _278 => _278.type]) === "delete") {
11433
11577
  delete newState[key];
11434
11578
  }
11435
11579
  }
@@ -11509,9 +11653,9 @@ function makePoller(callback, intervalMs, options) {
11509
11653
  const startTime = performance.now();
11510
11654
  const doc = typeof document !== "undefined" ? document : void 0;
11511
11655
  const win = typeof window !== "undefined" ? window : void 0;
11512
- const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _256 => _256.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
11656
+ const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _279 => _279.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
11513
11657
  const context = {
11514
- inForeground: _optionalChain([doc, 'optionalAccess', _257 => _257.visibilityState]) !== "hidden",
11658
+ inForeground: _optionalChain([doc, 'optionalAccess', _280 => _280.visibilityState]) !== "hidden",
11515
11659
  lastSuccessfulPollAt: startTime,
11516
11660
  count: 0,
11517
11661
  backoff: 0
@@ -11592,11 +11736,11 @@ function makePoller(callback, intervalMs, options) {
11592
11736
  pollNowIfStale();
11593
11737
  }
11594
11738
  function onVisibilityChange() {
11595
- setInForeground(_optionalChain([doc, 'optionalAccess', _258 => _258.visibilityState]) !== "hidden");
11739
+ setInForeground(_optionalChain([doc, 'optionalAccess', _281 => _281.visibilityState]) !== "hidden");
11596
11740
  }
11597
- _optionalChain([doc, 'optionalAccess', _259 => _259.addEventListener, 'call', _260 => _260("visibilitychange", onVisibilityChange)]);
11598
- _optionalChain([win, 'optionalAccess', _261 => _261.addEventListener, 'call', _262 => _262("online", onVisibilityChange)]);
11599
- _optionalChain([win, 'optionalAccess', _263 => _263.addEventListener, 'call', _264 => _264("focus", pollNowIfStale)]);
11741
+ _optionalChain([doc, 'optionalAccess', _282 => _282.addEventListener, 'call', _283 => _283("visibilitychange", onVisibilityChange)]);
11742
+ _optionalChain([win, 'optionalAccess', _284 => _284.addEventListener, 'call', _285 => _285("online", onVisibilityChange)]);
11743
+ _optionalChain([win, 'optionalAccess', _286 => _286.addEventListener, 'call', _287 => _287("focus", pollNowIfStale)]);
11600
11744
  fsm.start();
11601
11745
  return {
11602
11746
  inc,