@liveblocks/core 1.2.2-test2 → 1.2.2-test3

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-test2";
3
+ var PKG_VERSION = "1.2.2-test3";
4
4
  var PKG_FORMAT = "cjs";
5
5
 
6
6
  // src/dupe-detection.ts
@@ -2068,6 +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
2072
  this._unacknowledgedSets = /* @__PURE__ */ new Map();
2072
2073
  let position = void 0;
2073
2074
  for (const item of items) {
@@ -2219,6 +2220,10 @@ var LiveList = class _LiveList extends AbstractCrdt {
2219
2220
  this._unacknowledgedSets.delete(op.parentKey);
2220
2221
  }
2221
2222
  }
2223
+ if (this._unacknowledgedDeletedIds.has(op.id)) {
2224
+ this._unacknowledgedDeletedIds.delete(op.id);
2225
+ return delta.length === 0 ? { modified: false } : { modified: makeUpdate(this, delta), reverse: [] };
2226
+ }
2222
2227
  const indexOfItemWithSamePosition = this._indexOfPosition(op.parentKey);
2223
2228
  const existingItem = this._items.find((item) => item._id === op.id);
2224
2229
  if (existingItem !== void 0) {
@@ -2316,6 +2321,11 @@ var LiveList = class _LiveList extends AbstractCrdt {
2316
2321
  }
2317
2322
  /** @internal */
2318
2323
  _applyInsertAck(op) {
2324
+ if (this._unacknowledgedDeletedIds.has(op.id)) {
2325
+ return {
2326
+ modified: false
2327
+ };
2328
+ }
2319
2329
  const existingItem = this._items.find((item) => item._id === op.id);
2320
2330
  const key = asPos(op.parentKey);
2321
2331
  const itemIndexAtPosition = this._indexOfPosition(key);
@@ -2658,7 +2668,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2658
2668
  _optionalChain([this, 'access', _74 => _74._pool, 'optionalAccess', _75 => _75.assertStorageIsWritable, 'call', _76 => _76()]);
2659
2669
  if (index < 0 || index > this._items.length) {
2660
2670
  throw new Error(
2661
- `Cannot insert list item at index "${index}". index should be between 0 and ${this._items.length}`
2671
+ `Cannot insert list item at index "${index}". index should be between 0 and ${this._items.length}`
2662
2672
  );
2663
2673
  }
2664
2674
  const before2 = this._items[index - 1] ? this._items[index - 1]._parentPos : void 0;
@@ -2746,7 +2756,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2746
2756
  _optionalChain([this, 'access', _80 => _80._pool, 'optionalAccess', _81 => _81.assertStorageIsWritable, 'call', _82 => _82()]);
2747
2757
  if (index < 0 || index >= this._items.length) {
2748
2758
  throw new Error(
2749
- `Cannot delete list item at index "${index}". index should be between 0 and ${this._items.length - 1}`
2759
+ `Cannot delete list item at index "${index}". index should be between 0 and ${this._items.length - 1}`
2750
2760
  );
2751
2761
  }
2752
2762
  const item = this._items[index];
@@ -2754,8 +2764,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
2754
2764
  this._items.splice(index, 1);
2755
2765
  this.invalidate();
2756
2766
  if (this._pool) {
2757
- const childRecordId = item._id;
2758
- if (childRecordId) {
2767
+ const childId = item._id;
2768
+ if (childId) {
2759
2769
  const storageUpdates = /* @__PURE__ */ new Map();
2760
2770
  storageUpdates.set(
2761
2771
  nn(this._id),
@@ -2764,7 +2774,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
2764
2774
  this._pool.dispatch(
2765
2775
  [
2766
2776
  {
2767
- id: childRecordId,
2777
+ id: childId,
2768
2778
  opId: this._pool.generateOpId(),
2769
2779
  type: 5 /* DELETE_CRDT */
2770
2780
  }
@@ -2813,13 +2823,16 @@ var LiveList = class _LiveList extends AbstractCrdt {
2813
2823
  _optionalChain([this, 'access', _86 => _86._pool, 'optionalAccess', _87 => _87.assertStorageIsWritable, 'call', _88 => _88()]);
2814
2824
  if (index < 0 || index >= this._items.length) {
2815
2825
  throw new Error(
2816
- `Cannot set list item at index "${index}". index should be between 0 and ${this._items.length - 1}`
2826
+ `Cannot set list item at index "${index}". index should be between 0 and ${this._items.length - 1}`
2817
2827
  );
2818
2828
  }
2819
2829
  const existingItem = this._items[index];
2820
2830
  const position = existingItem._getParentKeyOrThrow();
2821
2831
  const existingId = existingItem._id;
2822
2832
  existingItem._detach();
2833
+ if (existingId !== void 0) {
2834
+ this._unacknowledgedDeletedIds.add(existingId);
2835
+ }
2823
2836
  const value = lsonToLiveNode(item);
2824
2837
  value._setParentLink(this, position);
2825
2838
  this._items[index] = value;