@liveblocks/core 1.2.0 → 1.2.2-test1

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.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/version.ts
2
2
  var PKG_NAME = "@liveblocks/core";
3
- var PKG_VERSION = "1.2.0";
3
+ var PKG_VERSION = "1.2.2-test1";
4
4
  var PKG_FORMAT = "esm";
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._unacknowledgedSets = /* @__PURE__ */ new Map();
2071
+ this._unacknowledgedDeletedIds = /* @__PURE__ */ new Set();
2072
2072
  let position = void 0;
2073
2073
  for (const item of items) {
2074
2074
  const newPosition = makePosition(position);
@@ -2211,13 +2211,9 @@ var LiveList = class _LiveList extends AbstractCrdt {
2211
2211
  if (deletedDelta) {
2212
2212
  delta.push(deletedDelta);
2213
2213
  }
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
- }
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: [] };
2221
2217
  }
2222
2218
  const indexOfItemWithSamePosition = this._indexOfPosition(op.parentKey);
2223
2219
  const existingItem = this._items.find((item) => item._id === op.id);
@@ -2316,6 +2312,11 @@ var LiveList = class _LiveList extends AbstractCrdt {
2316
2312
  }
2317
2313
  /** @internal */
2318
2314
  _applyInsertAck(op) {
2315
+ if (this._unacknowledgedDeletedIds.has(op.id)) {
2316
+ return {
2317
+ modified: false
2318
+ };
2319
+ }
2319
2320
  const existingItem = this._items.find((item) => item._id === op.id);
2320
2321
  const key = asPos(op.parentKey);
2321
2322
  const itemIndexAtPosition = this._indexOfPosition(key);
@@ -2396,7 +2397,6 @@ var LiveList = class _LiveList extends AbstractCrdt {
2396
2397
  if (this._pool?.getNode(id) !== void 0) {
2397
2398
  return { modified: false };
2398
2399
  }
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
  this._pool?.assertStorageIsWritable();
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
  this._pool?.assertStorageIsWritable();
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 childRecordId = item._id;
2758
- if (childRecordId) {
2757
+ const childId = item._id;
2758
+ if (childId) {
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: childRecordId,
2767
+ id: childId,
2768
2768
  opId: this._pool.generateOpId(),
2769
2769
  type: 5 /* DELETE_CRDT */
2770
2770
  }
@@ -2813,13 +2813,16 @@ var LiveList = class _LiveList extends AbstractCrdt {
2813
2813
  this._pool?.assertStorageIsWritable();
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
+ }
2823
2826
  const value = lsonToLiveNode(item);
2824
2827
  value._setParentLink(this, position);
2825
2828
  this._items[index] = value;
@@ -2833,7 +2836,6 @@ var LiveList = class _LiveList extends AbstractCrdt {
2833
2836
  value._toOps(this._id, position, this._pool),
2834
2837
  existingId
2835
2838
  );
2836
- this._unacknowledgedSets.set(position, nn(ops[0].opId));
2837
2839
  const reverseOps = HACK_addIntentAndDeletedIdToOperation(
2838
2840
  existingItem._toOps(this._id, position, void 0),
2839
2841
  id