@liveblocks/core 1.2.2-test1 → 1.2.2-test2

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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/version.ts
2
2
  var PKG_NAME = "@liveblocks/core";
3
- var PKG_VERSION = "1.2.2-test1";
3
+ var PKG_VERSION = "1.2.2-test2";
4
4
  var PKG_FORMAT = "cjs";
5
5
 
6
6
  // src/dupe-detection.ts
@@ -2068,7 +2068,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2068
2068
  super();
2069
2069
  this._items = [];
2070
2070
  this._implicitlyDeletedItems = /* @__PURE__ */ new WeakSet();
2071
- this._unacknowledgedDeletedIds = /* @__PURE__ */ new Set();
2071
+ this._unacknowledgedSets = /* @__PURE__ */ new Map();
2072
2072
  let position = void 0;
2073
2073
  for (const item of items) {
2074
2074
  const newPosition = makePosition(position);
@@ -2211,9 +2211,13 @@ var LiveList = class _LiveList extends AbstractCrdt {
2211
2211
  if (deletedDelta) {
2212
2212
  delta.push(deletedDelta);
2213
2213
  }
2214
- if (this._unacknowledgedDeletedIds.has(op.id)) {
2215
- this._unacknowledgedDeletedIds.delete(op.id);
2216
- return delta.length === 0 ? { modified: false } : { modified: makeUpdate(this, delta), reverse: [] };
2214
+ const unacknowledgedOpId = this._unacknowledgedSets.get(op.parentKey);
2215
+ if (unacknowledgedOpId !== void 0) {
2216
+ if (unacknowledgedOpId !== op.opId) {
2217
+ return delta.length === 0 ? { modified: false } : { modified: makeUpdate(this, delta), reverse: [] };
2218
+ } else {
2219
+ this._unacknowledgedSets.delete(op.parentKey);
2220
+ }
2217
2221
  }
2218
2222
  const indexOfItemWithSamePosition = this._indexOfPosition(op.parentKey);
2219
2223
  const existingItem = this._items.find((item) => item._id === op.id);
@@ -2312,11 +2316,6 @@ var LiveList = class _LiveList extends AbstractCrdt {
2312
2316
  }
2313
2317
  /** @internal */
2314
2318
  _applyInsertAck(op) {
2315
- if (this._unacknowledgedDeletedIds.has(op.id)) {
2316
- return {
2317
- modified: false
2318
- };
2319
- }
2320
2319
  const existingItem = this._items.find((item) => item._id === op.id);
2321
2320
  const key = asPos(op.parentKey);
2322
2321
  const itemIndexAtPosition = this._indexOfPosition(key);
@@ -2397,6 +2396,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2397
2396
  if (_optionalChain([this, 'access', _56 => _56._pool, 'optionalAccess', _57 => _57.getNode, 'call', _58 => _58(id)]) !== void 0) {
2398
2397
  return { modified: false };
2399
2398
  }
2399
+ this._unacknowledgedSets.set(key, nn(op.opId));
2400
2400
  const indexOfItemWithSameKey = this._indexOfPosition(key);
2401
2401
  child._attach(id, nn(this._pool));
2402
2402
  child._setParentLink(this, key);
@@ -2658,7 +2658,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2658
2658
  _optionalChain([this, 'access', _74 => _74._pool, 'optionalAccess', _75 => _75.assertStorageIsWritable, 'call', _76 => _76()]);
2659
2659
  if (index < 0 || index > this._items.length) {
2660
2660
  throw new Error(
2661
- `Cannot insert list item at index "${index}". index should be between 0 and ${this._items.length}`
2661
+ `Cannot insert list item at index "${index}". index should be between 0 and ${this._items.length}`
2662
2662
  );
2663
2663
  }
2664
2664
  const before2 = this._items[index - 1] ? this._items[index - 1]._parentPos : void 0;
@@ -2746,7 +2746,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2746
2746
  _optionalChain([this, 'access', _80 => _80._pool, 'optionalAccess', _81 => _81.assertStorageIsWritable, 'call', _82 => _82()]);
2747
2747
  if (index < 0 || index >= this._items.length) {
2748
2748
  throw new Error(
2749
- `Cannot delete list item at index "${index}". index should be between 0 and ${this._items.length - 1}`
2749
+ `Cannot delete list item at index "${index}". index should be between 0 and ${this._items.length - 1}`
2750
2750
  );
2751
2751
  }
2752
2752
  const item = this._items[index];
@@ -2754,8 +2754,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
2754
2754
  this._items.splice(index, 1);
2755
2755
  this.invalidate();
2756
2756
  if (this._pool) {
2757
- const childId = item._id;
2758
- if (childId) {
2757
+ const childRecordId = item._id;
2758
+ if (childRecordId) {
2759
2759
  const storageUpdates = /* @__PURE__ */ new Map();
2760
2760
  storageUpdates.set(
2761
2761
  nn(this._id),
@@ -2764,7 +2764,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2764
2764
  this._pool.dispatch(
2765
2765
  [
2766
2766
  {
2767
- id: childId,
2767
+ id: childRecordId,
2768
2768
  opId: this._pool.generateOpId(),
2769
2769
  type: 5 /* DELETE_CRDT */
2770
2770
  }
@@ -2813,16 +2813,13 @@ var LiveList = class _LiveList extends AbstractCrdt {
2813
2813
  _optionalChain([this, 'access', _86 => _86._pool, 'optionalAccess', _87 => _87.assertStorageIsWritable, 'call', _88 => _88()]);
2814
2814
  if (index < 0 || index >= this._items.length) {
2815
2815
  throw new Error(
2816
- `Cannot set list item at index "${index}". index should be between 0 and ${this._items.length - 1}`
2816
+ `Cannot set list item at index "${index}". index should be between 0 and ${this._items.length - 1}`
2817
2817
  );
2818
2818
  }
2819
2819
  const existingItem = this._items[index];
2820
2820
  const position = existingItem._getParentKeyOrThrow();
2821
2821
  const existingId = existingItem._id;
2822
2822
  existingItem._detach();
2823
- if (existingId !== void 0) {
2824
- this._unacknowledgedDeletedIds.add(existingId);
2825
- }
2826
2823
  const value = lsonToLiveNode(item);
2827
2824
  value._setParentLink(this, position);
2828
2825
  this._items[index] = value;
@@ -2836,6 +2833,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2836
2833
  value._toOps(this._id, position, this._pool),
2837
2834
  existingId
2838
2835
  );
2836
+ this._unacknowledgedSets.set(position, nn(ops[0].opId));
2839
2837
  const reverseOps = HACK_addIntentAndDeletedIdToOperation(
2840
2838
  existingItem._toOps(this._id, position, void 0),
2841
2839
  id