@liveblocks/core 3.19.3 → 3.20.0-pre1

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.d.cts CHANGED
@@ -454,40 +454,40 @@ type UpdateObjectOp = {
454
454
  type CreateObjectOp = {
455
455
  readonly opId?: string;
456
456
  readonly id: string;
457
- readonly intent?: "set";
458
- readonly deletedId?: string;
459
457
  readonly type: OpCode.CREATE_OBJECT;
460
458
  readonly parentId: string;
461
459
  readonly parentKey: string;
462
460
  readonly data: JsonObject;
461
+ readonly intent?: "set" | "push";
462
+ readonly deletedId?: string;
463
463
  };
464
464
  type CreateListOp = {
465
465
  readonly opId?: string;
466
466
  readonly id: string;
467
- readonly intent?: "set";
468
- readonly deletedId?: string;
469
467
  readonly type: OpCode.CREATE_LIST;
470
468
  readonly parentId: string;
471
469
  readonly parentKey: string;
470
+ readonly intent?: "set" | "push";
471
+ readonly deletedId?: string;
472
472
  };
473
473
  type CreateMapOp = {
474
474
  readonly opId?: string;
475
475
  readonly id: string;
476
- readonly intent?: "set";
477
- readonly deletedId?: string;
478
476
  readonly type: OpCode.CREATE_MAP;
479
477
  readonly parentId: string;
480
478
  readonly parentKey: string;
479
+ readonly intent?: "set" | "push";
480
+ readonly deletedId?: string;
481
481
  };
482
482
  type CreateRegisterOp = {
483
483
  readonly opId?: string;
484
484
  readonly id: string;
485
- readonly intent?: "set";
486
- readonly deletedId?: string;
487
485
  readonly type: OpCode.CREATE_REGISTER;
488
486
  readonly parentId: string;
489
487
  readonly parentKey: string;
490
488
  readonly data: Json;
489
+ readonly intent?: "set" | "push";
490
+ readonly deletedId?: string;
491
491
  };
492
492
  type DeleteCrdtOp = {
493
493
  readonly opId?: string;
package/dist/index.d.ts CHANGED
@@ -454,40 +454,40 @@ type UpdateObjectOp = {
454
454
  type CreateObjectOp = {
455
455
  readonly opId?: string;
456
456
  readonly id: string;
457
- readonly intent?: "set";
458
- readonly deletedId?: string;
459
457
  readonly type: OpCode.CREATE_OBJECT;
460
458
  readonly parentId: string;
461
459
  readonly parentKey: string;
462
460
  readonly data: JsonObject;
461
+ readonly intent?: "set" | "push";
462
+ readonly deletedId?: string;
463
463
  };
464
464
  type CreateListOp = {
465
465
  readonly opId?: string;
466
466
  readonly id: string;
467
- readonly intent?: "set";
468
- readonly deletedId?: string;
469
467
  readonly type: OpCode.CREATE_LIST;
470
468
  readonly parentId: string;
471
469
  readonly parentKey: string;
470
+ readonly intent?: "set" | "push";
471
+ readonly deletedId?: string;
472
472
  };
473
473
  type CreateMapOp = {
474
474
  readonly opId?: string;
475
475
  readonly id: string;
476
- readonly intent?: "set";
477
- readonly deletedId?: string;
478
476
  readonly type: OpCode.CREATE_MAP;
479
477
  readonly parentId: string;
480
478
  readonly parentKey: string;
479
+ readonly intent?: "set" | "push";
480
+ readonly deletedId?: string;
481
481
  };
482
482
  type CreateRegisterOp = {
483
483
  readonly opId?: string;
484
484
  readonly id: string;
485
- readonly intent?: "set";
486
- readonly deletedId?: string;
487
485
  readonly type: OpCode.CREATE_REGISTER;
488
486
  readonly parentId: string;
489
487
  readonly parentKey: string;
490
488
  readonly data: Json;
489
+ readonly intent?: "set" | "push";
490
+ readonly deletedId?: string;
491
491
  };
492
492
  type DeleteCrdtOp = {
493
493
  readonly opId?: string;
package/dist/index.js 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.19.3";
9
+ var PKG_VERSION = "3.20.0-pre1";
10
10
  var PKG_FORMAT = "esm";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -6123,9 +6123,9 @@ var LiveList = class _LiveList extends AbstractCrdt {
6123
6123
  ops.push(op);
6124
6124
  for (const item of this.#items) {
6125
6125
  const parentKey2 = item._getParentKeyOrThrow();
6126
- const childOps = HACK_addIntentAndDeletedIdToOperation(
6126
+ const childOps = addIntentToOpTree(
6127
6127
  item._toOps(this._id, parentKey2),
6128
- void 0
6128
+ "set"
6129
6129
  );
6130
6130
  for (const childOp of childOps) {
6131
6131
  ops.push(childOp);
@@ -6439,8 +6439,9 @@ var LiveList = class _LiveList extends AbstractCrdt {
6439
6439
  existingItem._detach();
6440
6440
  this.#items.remove(existingItem);
6441
6441
  this.#items.add(child);
6442
- const reverse = HACK_addIntentAndDeletedIdToOperation(
6442
+ const reverse = addIntentToOpTree(
6443
6443
  existingItem._toOps(nn(this._id), key),
6444
+ "set",
6444
6445
  op.id
6445
6446
  );
6446
6447
  const delta = [setDelta(indexOfItemWithSameKey, child)];
@@ -6683,8 +6684,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6683
6684
  * @param element The element to add to the end of the LiveList.
6684
6685
  */
6685
6686
  push(element) {
6686
- this._pool?.assertStorageIsWritable();
6687
- return this.insert(element, this.length);
6687
+ return this.#injectAt(element, this.length, "push");
6688
6688
  }
6689
6689
  /**
6690
6690
  * Inserts one element at a specified index.
@@ -6692,6 +6692,15 @@ var LiveList = class _LiveList extends AbstractCrdt {
6692
6692
  * @param index The index at which you want to insert the element.
6693
6693
  */
6694
6694
  insert(element, index) {
6695
+ return this.#injectAt(element, index, "insert");
6696
+ }
6697
+ /**
6698
+ * Shared implementation of `insert` and `push`. A `"push"` intent leaves the
6699
+ * client-computed position untouched (so optimistic rendering is unchanged),
6700
+ * but tags the Op so the server appends it to the true end of the list
6701
+ * instead of resolving its position against the client's stale view.
6702
+ */
6703
+ #injectAt(element, index, intent) {
6695
6704
  this._pool?.assertStorageIsWritable();
6696
6705
  if (index < 0 || index > this.#items.length) {
6697
6706
  throw new Error(
@@ -6707,8 +6716,9 @@ var LiveList = class _LiveList extends AbstractCrdt {
6707
6716
  if (this._pool && this._id) {
6708
6717
  const id = this._pool.generateId();
6709
6718
  value._attach(id, this._pool);
6719
+ const ops = value._toOpsWithOpId(this._id, position, this._pool);
6710
6720
  this._pool.dispatch(
6711
- value._toOpsWithOpId(this._id, position, this._pool),
6721
+ intent === "push" ? addIntentToOpTree(ops, "push") : ops,
6712
6722
  [{ type: OpCode.DELETE_CRDT, id }],
6713
6723
  /* @__PURE__ */ new Map([
6714
6724
  [this._id, makeUpdate(this, [insertDelta(index, value)])]
@@ -6866,13 +6876,15 @@ var LiveList = class _LiveList extends AbstractCrdt {
6866
6876
  value._attach(id, this._pool);
6867
6877
  const storageUpdates = /* @__PURE__ */ new Map();
6868
6878
  storageUpdates.set(this._id, makeUpdate(this, [setDelta(index, value)]));
6869
- const ops = HACK_addIntentAndDeletedIdToOperation(
6879
+ const ops = addIntentToOpTree(
6870
6880
  value._toOpsWithOpId(this._id, position, this._pool),
6881
+ "set",
6871
6882
  existingId
6872
6883
  );
6873
6884
  this.#unacknowledgedSets.set(position, nn(ops[0].opId));
6874
- const reverseOps = HACK_addIntentAndDeletedIdToOperation(
6885
+ const reverseOps = addIntentToOpTree(
6875
6886
  existingItem._toOps(this._id, position),
6887
+ "set",
6876
6888
  id
6877
6889
  );
6878
6890
  this._pool.dispatch(ops, reverseOps, storageUpdates);
@@ -7073,15 +7085,11 @@ function moveDelta(previousIndex, index, item) {
7073
7085
  previousIndex
7074
7086
  };
7075
7087
  }
7076
- function HACK_addIntentAndDeletedIdToOperation(ops, deletedId) {
7088
+ function addIntentToOpTree(ops, intent, deletedId) {
7077
7089
  return ops.map((op, index) => {
7078
7090
  if (index === 0) {
7079
7091
  const firstOp = op;
7080
- return {
7081
- ...firstOp,
7082
- intent: "set",
7083
- deletedId
7084
- };
7092
+ return { ...firstOp, intent, deletedId };
7085
7093
  } else {
7086
7094
  return op;
7087
7095
  }