@yorkie-js/react 0.6.25 → 0.6.27

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.
@@ -8261,6 +8261,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
8261
8261
  }
8262
8262
  return this.movedAt;
8263
8263
  }
8264
+ /**
8265
+ * `setCreatedAt` sets the creation time of this element manually.
8266
+ */
8267
+ setCreatedAt(createdAt) {
8268
+ this.createdAt = createdAt;
8269
+ }
8264
8270
  /**
8265
8271
  * `setMovedAt` sets the move time of this element.
8266
8272
  */
@@ -8372,12 +8378,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
8372
8378
  set(key, value, executedAt) {
8373
8379
  let removed;
8374
8380
  const node = this.nodeMapByKey.get(key);
8375
- if (node != null && !node.isRemoved() && node.remove(executedAt)) {
8381
+ if (!!node && !node.isRemoved() && node.remove(executedAt)) {
8376
8382
  removed = node.getValue();
8377
8383
  }
8378
8384
  const newNode = ElementRHTNode.of(key, value);
8379
8385
  this.nodeMapByCreatedAt.set(value.getCreatedAt().toIDString(), newNode);
8380
- if (node == null || executedAt.after(node.getValue().getPositionedAt())) {
8386
+ if (!node || executedAt.after(node.getValue().getPositionedAt())) {
8381
8387
  this.nodeMapByKey.set(key, newNode);
8382
8388
  value.setMovedAt(executedAt);
8383
8389
  }
@@ -8431,7 +8437,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
8431
8437
  */
8432
8438
  deleteByKey(key, removedAt) {
8433
8439
  const node = this.nodeMapByKey.get(key);
8434
- if (node == null) {
8440
+ if (!node) {
8435
8441
  return;
8436
8442
  }
8437
8443
  if (!node.remove(removedAt)) {
@@ -8444,7 +8450,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
8444
8450
  */
8445
8451
  has(key) {
8446
8452
  const node = this.nodeMapByKey.get(key);
8447
- if (node == null) {
8453
+ if (!node) {
8448
8454
  return false;
8449
8455
  }
8450
8456
  return !node.isRemoved();
@@ -10959,6 +10965,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
10959
10965
  getValue() {
10960
10966
  return this.value;
10961
10967
  }
10968
+ /**
10969
+ * `setPrevCreatedAt` sets the creation time of the previous element.
10970
+ */
10971
+ setPrevCreatedAt(createdAt) {
10972
+ this.prevCreatedAt = createdAt;
10973
+ }
10962
10974
  }
10963
10975
  class RemoveOperation extends Operation {
10964
10976
  constructor(parentCreatedAt, createdAt, executedAt) {
@@ -11069,6 +11081,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
11069
11081
  getCreatedAt() {
11070
11082
  return this.createdAt;
11071
11083
  }
11084
+ /**
11085
+ * `setCreatedAt` sets the creation time of the target element.
11086
+ */
11087
+ setCreatedAt(createdAt) {
11088
+ this.createdAt = createdAt;
11089
+ }
11072
11090
  }
11073
11091
  class SetOperation extends Operation {
11074
11092
  constructor(key, value, parentCreatedAt, executedAt) {
@@ -11260,6 +11278,18 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
11260
11278
  getCreatedAt() {
11261
11279
  return this.createdAt;
11262
11280
  }
11281
+ /**
11282
+ * `setPrevCreatedAt` sets the creation time of the previous element.
11283
+ */
11284
+ setPrevCreatedAt(createdAt) {
11285
+ this.prevCreatedAt = createdAt;
11286
+ }
11287
+ /**
11288
+ * `setCreatedAt` sets the creation time of the target element.
11289
+ */
11290
+ setCreatedAt(createdAt) {
11291
+ this.createdAt = createdAt;
11292
+ }
11263
11293
  }
11264
11294
  class RHTNode {
11265
11295
  constructor(key, value, updatedAt, isRemoved) {
@@ -14415,6 +14445,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
14415
14445
  get(actorID) {
14416
14446
  return this.vector.get(actorID);
14417
14447
  }
14448
+ /**
14449
+ * `has` checks if the given actor exists in the VersionVector.
14450
+ */
14451
+ has(actorID) {
14452
+ return this.vector.has(actorID);
14453
+ }
14418
14454
  /**
14419
14455
  * `maxLamport` returns max lamport value from vector
14420
14456
  */
@@ -15287,11 +15323,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
15287
15323
  /**
15288
15324
  * `canDelete` checks if node is able to delete.
15289
15325
  */
15290
- canDelete(editedAt, clientLamportAtChange) {
15291
- const justRemoved = !this.removedAt;
15292
- const nodeExisted = this.getCreatedAt().getLamport() <= clientLamportAtChange;
15293
- if (nodeExisted && (!this.removedAt || editedAt.after(this.removedAt))) {
15294
- return justRemoved;
15326
+ canRemove(creationKnown) {
15327
+ if (!creationKnown) {
15328
+ return false;
15329
+ }
15330
+ if (!this.removedAt) {
15331
+ return true;
15295
15332
  }
15296
15333
  return false;
15297
15334
  }
@@ -15303,10 +15340,22 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
15303
15340
  return nodeExisted && (!this.removedAt || editedAt.after(this.removedAt));
15304
15341
  }
15305
15342
  /**
15306
- * `remove` removes node of given edited time.
15343
+ * `setRemovedAt` sets the remove time of this node.
15307
15344
  */
15308
- remove(editedAt) {
15309
- this.removedAt = editedAt;
15345
+ setRemovedAt(removedAt) {
15346
+ this.removedAt = removedAt;
15347
+ }
15348
+ /**
15349
+ * `remove` removes the node of the given edited time.
15350
+ */
15351
+ remove(removedAt, tombstoneKnown) {
15352
+ if (!this.removedAt) {
15353
+ this.removedAt = removedAt;
15354
+ return;
15355
+ }
15356
+ if (!tombstoneKnown && removedAt.after(this.removedAt)) {
15357
+ this.removedAt = removedAt;
15358
+ }
15310
15359
  }
15311
15360
  /**
15312
15361
  * `createRange` creates ranges of RGATreeSplitPos.
@@ -15637,43 +15686,34 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
15637
15686
  subDataSize(diff, prvSize);
15638
15687
  return [splitNode, diff];
15639
15688
  }
15640
- deleteNodes(candidates, editedAt, versionVector) {
15689
+ deleteNodes(candidates, editedAt, vector) {
15641
15690
  if (!candidates.length) {
15642
15691
  return [[], /* @__PURE__ */ new Map()];
15643
15692
  }
15644
- const [nodesToDelete, nodesToKeep] = this.filterNodes(
15645
- candidates,
15646
- editedAt,
15647
- versionVector
15648
- );
15649
- const removedNodes = /* @__PURE__ */ new Map();
15650
- const changes = this.makeChanges(nodesToKeep, editedAt);
15651
- for (const node of nodesToDelete) {
15652
- removedNodes.set(node.getID().toIDString(), node);
15653
- node.remove(editedAt);
15654
- }
15655
- this.deleteIndexNodes(nodesToKeep);
15656
- return [changes, removedNodes];
15657
- }
15658
- filterNodes(candidates, editedAt, versionVector) {
15659
- const nodesToDelete = [];
15693
+ const isLocal = vector === void 0;
15694
+ const nodesToRemove = [];
15660
15695
  const nodesToKeep = [];
15661
15696
  const [leftEdge, rightEdge] = this.findEdgesOfCandidates(candidates);
15662
15697
  nodesToKeep.push(leftEdge);
15663
15698
  for (const node of candidates) {
15664
- const actorID = node.getCreatedAt().getActorID();
15665
- let clientLamportAtChange = MaxLamport;
15666
- if (versionVector != void 0) {
15667
- clientLamportAtChange = versionVector.get(actorID) ? versionVector.get(actorID) : 0n;
15668
- }
15669
- if (node.canDelete(editedAt, clientLamportAtChange)) {
15670
- nodesToDelete.push(node);
15699
+ if (node.canRemove(isLocal || vector.afterOrEqual(node.getCreatedAt()))) {
15700
+ nodesToRemove.push(node);
15671
15701
  } else {
15672
15702
  nodesToKeep.push(node);
15673
15703
  }
15674
15704
  }
15675
15705
  nodesToKeep.push(rightEdge);
15676
- return [nodesToDelete, nodesToKeep];
15706
+ const changes = this.makeChanges(nodesToKeep, editedAt);
15707
+ const removedNodes = /* @__PURE__ */ new Map();
15708
+ for (const node of nodesToRemove) {
15709
+ removedNodes.set(node.getID().toIDString(), node);
15710
+ node.remove(
15711
+ editedAt,
15712
+ node.isRemoved() && (isLocal || vector.afterOrEqual(node.getRemovedAt()))
15713
+ );
15714
+ }
15715
+ this.deleteIndexNodes(nodesToKeep);
15716
+ return [changes, removedNodes];
15677
15717
  }
15678
15718
  /**
15679
15719
  * `findEdgesOfCandidates` finds the edges outside `candidates`,
@@ -16214,11 +16254,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
16214
16254
  `fail to execute, only array can execute set`
16215
16255
  );
16216
16256
  }
16257
+ const previousValue = parentObject.getByID(this.createdAt).deepcopy();
16258
+ const reverseOp = this.toReverseOperation(this.value, previousValue);
16217
16259
  const value = this.value.deepcopy();
16218
16260
  parentObject.insertAfter(this.createdAt, value, this.getExecutedAt());
16219
16261
  parentObject.delete(this.createdAt, this.getExecutedAt());
16220
16262
  root.registerElement(value);
16221
- const reverseOp = void 0;
16222
16263
  return {
16223
16264
  opInfos: [
16224
16265
  {
@@ -16229,6 +16270,17 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
16229
16270
  reverseOp
16230
16271
  };
16231
16272
  }
16273
+ /**
16274
+ * `toReverseOperation` returns the reverse operation of this operation.
16275
+ */
16276
+ toReverseOperation(newValue, prevValue) {
16277
+ const reverseOp = ArraySetOperation.create(
16278
+ this.getParentCreatedAt(),
16279
+ newValue.getCreatedAt(),
16280
+ prevValue
16281
+ );
16282
+ return reverseOp;
16283
+ }
16232
16284
  /**
16233
16285
  * `getEffectedCreatedAt` returns the creation time of the effected element.
16234
16286
  */
@@ -16253,6 +16305,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
16253
16305
  getValue() {
16254
16306
  return this.value;
16255
16307
  }
16308
+ /**
16309
+ * `setCreatedAt` sets the creation time of the target element.
16310
+ */
16311
+ setCreatedAt(createdAt) {
16312
+ this.createdAt = createdAt;
16313
+ }
16256
16314
  }
16257
16315
  function toPresence(presence) {
16258
16316
  const pbPresence = new Presence$1();
@@ -16971,7 +17029,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
16971
17029
  fromTextNodeID(pbTextNode.id),
16972
17030
  textValue
16973
17031
  );
16974
- textNode.remove(fromTimeTicket(pbTextNode.removedAt));
17032
+ textNode.setRemovedAt(fromTimeTicket(pbTextNode.removedAt));
16975
17033
  return textNode;
16976
17034
  }
16977
17035
  function fromTreePos(pbTreePos) {
@@ -17502,7 +17560,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
17502
17560
  });
17503
17561
  }
17504
17562
  class Attachment {
17505
- constructor(reconnectStreamDelay, doc, docID, syncMode, unsubscribeBroacastEvent) {
17563
+ constructor(reconnectStreamDelay, doc, docID, syncMode, unsubscribeBroadcastEvent) {
17506
17564
  // TODO(hackerwins): Consider to changing the modifiers of the following properties to private.
17507
17565
  __publicField(this, "reconnectStreamDelay");
17508
17566
  __publicField(this, "doc");
@@ -17520,7 +17578,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
17520
17578
  this.syncMode = syncMode;
17521
17579
  this.remoteChangeEventReceived = false;
17522
17580
  this.cancelled = false;
17523
- this.unsubscribeBroadcastEvent = unsubscribeBroacastEvent;
17581
+ this.unsubscribeBroadcastEvent = unsubscribeBroadcastEvent;
17524
17582
  }
17525
17583
  /**
17526
17584
  * `changeSyncMode` changes the sync mode of the document.
@@ -17631,7 +17689,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
17631
17689
  errors: [
17632
17690
  {
17633
17691
  path: rule.path,
17634
- message: `Expected object at path ${rule.path}`
17692
+ message: `expected object at path ${rule.path}`
17635
17693
  }
17636
17694
  ]
17637
17695
  };
@@ -17644,7 +17702,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
17644
17702
  errors: [
17645
17703
  {
17646
17704
  path: rule.path,
17647
- message: `Expected array at path ${rule.path}`
17705
+ message: `expected array at path ${rule.path}`
17648
17706
  }
17649
17707
  ]
17650
17708
  };
@@ -17657,7 +17715,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
17657
17715
  errors: [
17658
17716
  {
17659
17717
  path: rule.path,
17660
- message: `Expected yorkie.Text at path ${rule.path}`
17718
+ message: `expected yorkie.Text at path ${rule.path}`
17661
17719
  }
17662
17720
  ]
17663
17721
  };
@@ -17670,7 +17728,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
17670
17728
  errors: [
17671
17729
  {
17672
17730
  path: rule.path,
17673
- message: `Expected yorkie.Tree at path ${rule.path}`
17731
+ message: `expected yorkie.Tree at path ${rule.path}`
17674
17732
  }
17675
17733
  ]
17676
17734
  };
@@ -17683,7 +17741,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
17683
17741
  errors: [
17684
17742
  {
17685
17743
  path: rule.path,
17686
- message: `Expected yorkie.Counter at path ${rule.path}`
17744
+ message: `expected yorkie.Counter at path ${rule.path}`
17687
17745
  }
17688
17746
  ]
17689
17747
  };
@@ -17727,7 +17785,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
17727
17785
  errors: [
17728
17786
  {
17729
17787
  path: rule.path,
17730
- message: `Expected ${rule.type} at path ${rule.path}`
17788
+ message: `expected ${rule.type} at path ${rule.path}`
17731
17789
  }
17732
17790
  ]
17733
17791
  };
@@ -20176,6 +20234,32 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
20176
20234
  getRedoStackForTest() {
20177
20235
  return this.redoStack;
20178
20236
  }
20237
+ /**
20238
+ * `reconcileCreatedAt` updates the createdAt and prevCreatedAt fields.
20239
+ *
20240
+ * When an element is replaced(e.g., UndoRemove as Add, or Set),
20241
+ * it receives a new createdAt(executedAt). However, existing history
20242
+ * operations may still reference the old createdAt or prevCreatedAt.
20243
+ *
20244
+ * This method scans both undo/redo stacks and replaces any matching
20245
+ * createdAt/prevCreatedAt with the new one, ensuring consistency.
20246
+ */
20247
+ reconcileCreatedAt(prevCreatedAt, currCreatedAt) {
20248
+ const replace = (stack) => {
20249
+ for (const ops of stack) {
20250
+ for (const op of ops) {
20251
+ if ((op instanceof ArraySetOperation || op instanceof RemoveOperation || op instanceof MoveOperation) && op.getCreatedAt() === prevCreatedAt) {
20252
+ op.setCreatedAt(currCreatedAt);
20253
+ }
20254
+ if ((op instanceof AddOperation || op instanceof MoveOperation) && op.getPrevCreatedAt() === prevCreatedAt) {
20255
+ op.setPrevCreatedAt(currCreatedAt);
20256
+ }
20257
+ }
20258
+ }
20259
+ };
20260
+ replace(this.undoStack);
20261
+ replace(this.redoStack);
20262
+ }
20179
20263
  }
20180
20264
  const EventSourceDevPanel = "yorkie-devtools-panel";
20181
20265
  const EventSourceSDK = "yorkie-devtools-sdk";
@@ -20433,6 +20517,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
20433
20517
  this.presences,
20434
20518
  OpSource.Local
20435
20519
  );
20520
+ for (const op of change.getOperations()) {
20521
+ if (op instanceof ArraySetOperation) {
20522
+ this.internalHistory.reconcileCreatedAt(
20523
+ op.getCreatedAt(),
20524
+ op.getValue().getCreatedAt()
20525
+ );
20526
+ }
20527
+ }
20436
20528
  const reversePresence = context.getReversePresence();
20437
20529
  if (reversePresence) {
20438
20530
  reverseOps.push({
@@ -21389,6 +21481,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
21389
21481
  }
21390
21482
  const ticket = context.issueTimeTicket();
21391
21483
  undoOp.setExecutedAt(ticket);
21484
+ if (undoOp instanceof ArraySetOperation) {
21485
+ const prev = undoOp.getCreatedAt();
21486
+ undoOp.getValue().setCreatedAt(ticket);
21487
+ this.internalHistory.reconcileCreatedAt(prev, ticket);
21488
+ } else if (undoOp instanceof AddOperation) {
21489
+ const prev = undoOp.getValue().getCreatedAt();
21490
+ undoOp.getValue().setCreatedAt(ticket);
21491
+ this.internalHistory.reconcileCreatedAt(prev, ticket);
21492
+ }
21392
21493
  context.push(undoOp);
21393
21494
  }
21394
21495
  const change = context.toChange();
@@ -21476,6 +21577,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
21476
21577
  }
21477
21578
  const ticket = context.issueTimeTicket();
21478
21579
  redoOp.setExecutedAt(ticket);
21580
+ if (redoOp instanceof ArraySetOperation) {
21581
+ const prev = redoOp.getCreatedAt();
21582
+ redoOp.getValue().setCreatedAt(ticket);
21583
+ this.internalHistory.reconcileCreatedAt(prev, ticket);
21584
+ } else if (redoOp instanceof AddOperation) {
21585
+ const prev = redoOp.getValue().getCreatedAt();
21586
+ redoOp.getValue().setCreatedAt(ticket);
21587
+ this.internalHistory.reconcileCreatedAt(prev, ticket);
21588
+ }
21479
21589
  context.push(redoOp);
21480
21590
  }
21481
21591
  const change = context.toChange();
@@ -21578,7 +21688,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
21578
21688
  };
21579
21689
  }
21580
21690
  const name$1 = "@yorkie-js/sdk";
21581
- const version$1 = "0.6.25";
21691
+ const version$1 = "0.6.27";
21582
21692
  const pkg$1 = {
21583
21693
  name: name$1,
21584
21694
  version: version$1
@@ -22341,6 +22451,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
22341
22451
  return;
22342
22452
  }
22343
22453
  attachment.cancelWatchStream();
22454
+ attachment.doc.resetOnlineClients();
22344
22455
  attachment.unsubscribeBroadcastEvent();
22345
22456
  this.attachmentMap.delete(docKey);
22346
22457
  }
@@ -22468,7 +22579,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
22468
22579
  };
22469
22580
  }
22470
22581
  const name = "@yorkie-js/react";
22471
- const version = "0.6.25";
22582
+ const version = "0.6.27";
22472
22583
  const pkg = {
22473
22584
  name,
22474
22585
  version