@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.
@@ -8259,6 +8259,12 @@ class CRDTElement {
8259
8259
  }
8260
8260
  return this.movedAt;
8261
8261
  }
8262
+ /**
8263
+ * `setCreatedAt` sets the creation time of this element manually.
8264
+ */
8265
+ setCreatedAt(createdAt) {
8266
+ this.createdAt = createdAt;
8267
+ }
8262
8268
  /**
8263
8269
  * `setMovedAt` sets the move time of this element.
8264
8270
  */
@@ -8370,12 +8376,12 @@ class ElementRHT {
8370
8376
  set(key, value, executedAt) {
8371
8377
  let removed;
8372
8378
  const node = this.nodeMapByKey.get(key);
8373
- if (node != null && !node.isRemoved() && node.remove(executedAt)) {
8379
+ if (!!node && !node.isRemoved() && node.remove(executedAt)) {
8374
8380
  removed = node.getValue();
8375
8381
  }
8376
8382
  const newNode = ElementRHTNode.of(key, value);
8377
8383
  this.nodeMapByCreatedAt.set(value.getCreatedAt().toIDString(), newNode);
8378
- if (node == null || executedAt.after(node.getValue().getPositionedAt())) {
8384
+ if (!node || executedAt.after(node.getValue().getPositionedAt())) {
8379
8385
  this.nodeMapByKey.set(key, newNode);
8380
8386
  value.setMovedAt(executedAt);
8381
8387
  }
@@ -8429,7 +8435,7 @@ class ElementRHT {
8429
8435
  */
8430
8436
  deleteByKey(key, removedAt) {
8431
8437
  const node = this.nodeMapByKey.get(key);
8432
- if (node == null) {
8438
+ if (!node) {
8433
8439
  return;
8434
8440
  }
8435
8441
  if (!node.remove(removedAt)) {
@@ -8442,7 +8448,7 @@ class ElementRHT {
8442
8448
  */
8443
8449
  has(key) {
8444
8450
  const node = this.nodeMapByKey.get(key);
8445
- if (node == null) {
8451
+ if (!node) {
8446
8452
  return false;
8447
8453
  }
8448
8454
  return !node.isRemoved();
@@ -10957,6 +10963,12 @@ class AddOperation extends Operation {
10957
10963
  getValue() {
10958
10964
  return this.value;
10959
10965
  }
10966
+ /**
10967
+ * `setPrevCreatedAt` sets the creation time of the previous element.
10968
+ */
10969
+ setPrevCreatedAt(createdAt) {
10970
+ this.prevCreatedAt = createdAt;
10971
+ }
10960
10972
  }
10961
10973
  class RemoveOperation extends Operation {
10962
10974
  constructor(parentCreatedAt, createdAt, executedAt) {
@@ -11067,6 +11079,12 @@ class RemoveOperation extends Operation {
11067
11079
  getCreatedAt() {
11068
11080
  return this.createdAt;
11069
11081
  }
11082
+ /**
11083
+ * `setCreatedAt` sets the creation time of the target element.
11084
+ */
11085
+ setCreatedAt(createdAt) {
11086
+ this.createdAt = createdAt;
11087
+ }
11070
11088
  }
11071
11089
  class SetOperation extends Operation {
11072
11090
  constructor(key, value, parentCreatedAt, executedAt) {
@@ -11258,6 +11276,18 @@ class MoveOperation extends Operation {
11258
11276
  getCreatedAt() {
11259
11277
  return this.createdAt;
11260
11278
  }
11279
+ /**
11280
+ * `setPrevCreatedAt` sets the creation time of the previous element.
11281
+ */
11282
+ setPrevCreatedAt(createdAt) {
11283
+ this.prevCreatedAt = createdAt;
11284
+ }
11285
+ /**
11286
+ * `setCreatedAt` sets the creation time of the target element.
11287
+ */
11288
+ setCreatedAt(createdAt) {
11289
+ this.createdAt = createdAt;
11290
+ }
11261
11291
  }
11262
11292
  class RHTNode {
11263
11293
  constructor(key, value, updatedAt, isRemoved) {
@@ -14413,6 +14443,12 @@ class VersionVector {
14413
14443
  get(actorID) {
14414
14444
  return this.vector.get(actorID);
14415
14445
  }
14446
+ /**
14447
+ * `has` checks if the given actor exists in the VersionVector.
14448
+ */
14449
+ has(actorID) {
14450
+ return this.vector.has(actorID);
14451
+ }
14416
14452
  /**
14417
14453
  * `maxLamport` returns max lamport value from vector
14418
14454
  */
@@ -15285,11 +15321,12 @@ class RGATreeSplitNode extends SplayNode {
15285
15321
  /**
15286
15322
  * `canDelete` checks if node is able to delete.
15287
15323
  */
15288
- canDelete(editedAt, clientLamportAtChange) {
15289
- const justRemoved = !this.removedAt;
15290
- const nodeExisted = this.getCreatedAt().getLamport() <= clientLamportAtChange;
15291
- if (nodeExisted && (!this.removedAt || editedAt.after(this.removedAt))) {
15292
- return justRemoved;
15324
+ canRemove(creationKnown) {
15325
+ if (!creationKnown) {
15326
+ return false;
15327
+ }
15328
+ if (!this.removedAt) {
15329
+ return true;
15293
15330
  }
15294
15331
  return false;
15295
15332
  }
@@ -15301,10 +15338,22 @@ class RGATreeSplitNode extends SplayNode {
15301
15338
  return nodeExisted && (!this.removedAt || editedAt.after(this.removedAt));
15302
15339
  }
15303
15340
  /**
15304
- * `remove` removes node of given edited time.
15341
+ * `setRemovedAt` sets the remove time of this node.
15305
15342
  */
15306
- remove(editedAt) {
15307
- this.removedAt = editedAt;
15343
+ setRemovedAt(removedAt) {
15344
+ this.removedAt = removedAt;
15345
+ }
15346
+ /**
15347
+ * `remove` removes the node of the given edited time.
15348
+ */
15349
+ remove(removedAt, tombstoneKnown) {
15350
+ if (!this.removedAt) {
15351
+ this.removedAt = removedAt;
15352
+ return;
15353
+ }
15354
+ if (!tombstoneKnown && removedAt.after(this.removedAt)) {
15355
+ this.removedAt = removedAt;
15356
+ }
15308
15357
  }
15309
15358
  /**
15310
15359
  * `createRange` creates ranges of RGATreeSplitPos.
@@ -15635,43 +15684,34 @@ class RGATreeSplit {
15635
15684
  subDataSize(diff, prvSize);
15636
15685
  return [splitNode, diff];
15637
15686
  }
15638
- deleteNodes(candidates, editedAt, versionVector) {
15687
+ deleteNodes(candidates, editedAt, vector) {
15639
15688
  if (!candidates.length) {
15640
15689
  return [[], /* @__PURE__ */ new Map()];
15641
15690
  }
15642
- const [nodesToDelete, nodesToKeep] = this.filterNodes(
15643
- candidates,
15644
- editedAt,
15645
- versionVector
15646
- );
15647
- const removedNodes = /* @__PURE__ */ new Map();
15648
- const changes = this.makeChanges(nodesToKeep, editedAt);
15649
- for (const node of nodesToDelete) {
15650
- removedNodes.set(node.getID().toIDString(), node);
15651
- node.remove(editedAt);
15652
- }
15653
- this.deleteIndexNodes(nodesToKeep);
15654
- return [changes, removedNodes];
15655
- }
15656
- filterNodes(candidates, editedAt, versionVector) {
15657
- const nodesToDelete = [];
15691
+ const isLocal = vector === void 0;
15692
+ const nodesToRemove = [];
15658
15693
  const nodesToKeep = [];
15659
15694
  const [leftEdge, rightEdge] = this.findEdgesOfCandidates(candidates);
15660
15695
  nodesToKeep.push(leftEdge);
15661
15696
  for (const node of candidates) {
15662
- const actorID = node.getCreatedAt().getActorID();
15663
- let clientLamportAtChange = MaxLamport;
15664
- if (versionVector != void 0) {
15665
- clientLamportAtChange = versionVector.get(actorID) ? versionVector.get(actorID) : 0n;
15666
- }
15667
- if (node.canDelete(editedAt, clientLamportAtChange)) {
15668
- nodesToDelete.push(node);
15697
+ if (node.canRemove(isLocal || vector.afterOrEqual(node.getCreatedAt()))) {
15698
+ nodesToRemove.push(node);
15669
15699
  } else {
15670
15700
  nodesToKeep.push(node);
15671
15701
  }
15672
15702
  }
15673
15703
  nodesToKeep.push(rightEdge);
15674
- return [nodesToDelete, nodesToKeep];
15704
+ const changes = this.makeChanges(nodesToKeep, editedAt);
15705
+ const removedNodes = /* @__PURE__ */ new Map();
15706
+ for (const node of nodesToRemove) {
15707
+ removedNodes.set(node.getID().toIDString(), node);
15708
+ node.remove(
15709
+ editedAt,
15710
+ node.isRemoved() && (isLocal || vector.afterOrEqual(node.getRemovedAt()))
15711
+ );
15712
+ }
15713
+ this.deleteIndexNodes(nodesToKeep);
15714
+ return [changes, removedNodes];
15675
15715
  }
15676
15716
  /**
15677
15717
  * `findEdgesOfCandidates` finds the edges outside `candidates`,
@@ -16212,11 +16252,12 @@ class ArraySetOperation extends Operation {
16212
16252
  `fail to execute, only array can execute set`
16213
16253
  );
16214
16254
  }
16255
+ const previousValue = parentObject.getByID(this.createdAt).deepcopy();
16256
+ const reverseOp = this.toReverseOperation(this.value, previousValue);
16215
16257
  const value = this.value.deepcopy();
16216
16258
  parentObject.insertAfter(this.createdAt, value, this.getExecutedAt());
16217
16259
  parentObject.delete(this.createdAt, this.getExecutedAt());
16218
16260
  root.registerElement(value);
16219
- const reverseOp = void 0;
16220
16261
  return {
16221
16262
  opInfos: [
16222
16263
  {
@@ -16227,6 +16268,17 @@ class ArraySetOperation extends Operation {
16227
16268
  reverseOp
16228
16269
  };
16229
16270
  }
16271
+ /**
16272
+ * `toReverseOperation` returns the reverse operation of this operation.
16273
+ */
16274
+ toReverseOperation(newValue, prevValue) {
16275
+ const reverseOp = ArraySetOperation.create(
16276
+ this.getParentCreatedAt(),
16277
+ newValue.getCreatedAt(),
16278
+ prevValue
16279
+ );
16280
+ return reverseOp;
16281
+ }
16230
16282
  /**
16231
16283
  * `getEffectedCreatedAt` returns the creation time of the effected element.
16232
16284
  */
@@ -16251,6 +16303,12 @@ class ArraySetOperation extends Operation {
16251
16303
  getValue() {
16252
16304
  return this.value;
16253
16305
  }
16306
+ /**
16307
+ * `setCreatedAt` sets the creation time of the target element.
16308
+ */
16309
+ setCreatedAt(createdAt) {
16310
+ this.createdAt = createdAt;
16311
+ }
16254
16312
  }
16255
16313
  function toPresence(presence) {
16256
16314
  const pbPresence = new Presence$1();
@@ -16969,7 +17027,7 @@ function fromTextNode(pbTextNode) {
16969
17027
  fromTextNodeID(pbTextNode.id),
16970
17028
  textValue
16971
17029
  );
16972
- textNode.remove(fromTimeTicket(pbTextNode.removedAt));
17030
+ textNode.setRemovedAt(fromTimeTicket(pbTextNode.removedAt));
16973
17031
  return textNode;
16974
17032
  }
16975
17033
  function fromTreePos(pbTreePos) {
@@ -17500,7 +17558,7 @@ function uuid() {
17500
17558
  });
17501
17559
  }
17502
17560
  class Attachment {
17503
- constructor(reconnectStreamDelay, doc, docID, syncMode, unsubscribeBroacastEvent) {
17561
+ constructor(reconnectStreamDelay, doc, docID, syncMode, unsubscribeBroadcastEvent) {
17504
17562
  // TODO(hackerwins): Consider to changing the modifiers of the following properties to private.
17505
17563
  __publicField(this, "reconnectStreamDelay");
17506
17564
  __publicField(this, "doc");
@@ -17518,7 +17576,7 @@ class Attachment {
17518
17576
  this.syncMode = syncMode;
17519
17577
  this.remoteChangeEventReceived = false;
17520
17578
  this.cancelled = false;
17521
- this.unsubscribeBroadcastEvent = unsubscribeBroacastEvent;
17579
+ this.unsubscribeBroadcastEvent = unsubscribeBroadcastEvent;
17522
17580
  }
17523
17581
  /**
17524
17582
  * `changeSyncMode` changes the sync mode of the document.
@@ -17629,7 +17687,7 @@ function validateValue(value, rule) {
17629
17687
  errors: [
17630
17688
  {
17631
17689
  path: rule.path,
17632
- message: `Expected object at path ${rule.path}`
17690
+ message: `expected object at path ${rule.path}`
17633
17691
  }
17634
17692
  ]
17635
17693
  };
@@ -17642,7 +17700,7 @@ function validateValue(value, rule) {
17642
17700
  errors: [
17643
17701
  {
17644
17702
  path: rule.path,
17645
- message: `Expected array at path ${rule.path}`
17703
+ message: `expected array at path ${rule.path}`
17646
17704
  }
17647
17705
  ]
17648
17706
  };
@@ -17655,7 +17713,7 @@ function validateValue(value, rule) {
17655
17713
  errors: [
17656
17714
  {
17657
17715
  path: rule.path,
17658
- message: `Expected yorkie.Text at path ${rule.path}`
17716
+ message: `expected yorkie.Text at path ${rule.path}`
17659
17717
  }
17660
17718
  ]
17661
17719
  };
@@ -17668,7 +17726,7 @@ function validateValue(value, rule) {
17668
17726
  errors: [
17669
17727
  {
17670
17728
  path: rule.path,
17671
- message: `Expected yorkie.Tree at path ${rule.path}`
17729
+ message: `expected yorkie.Tree at path ${rule.path}`
17672
17730
  }
17673
17731
  ]
17674
17732
  };
@@ -17681,7 +17739,7 @@ function validateValue(value, rule) {
17681
17739
  errors: [
17682
17740
  {
17683
17741
  path: rule.path,
17684
- message: `Expected yorkie.Counter at path ${rule.path}`
17742
+ message: `expected yorkie.Counter at path ${rule.path}`
17685
17743
  }
17686
17744
  ]
17687
17745
  };
@@ -17725,7 +17783,7 @@ function validatePrimitiveValue(value, rule) {
17725
17783
  errors: [
17726
17784
  {
17727
17785
  path: rule.path,
17728
- message: `Expected ${rule.type} at path ${rule.path}`
17786
+ message: `expected ${rule.type} at path ${rule.path}`
17729
17787
  }
17730
17788
  ]
17731
17789
  };
@@ -20174,6 +20232,32 @@ class History {
20174
20232
  getRedoStackForTest() {
20175
20233
  return this.redoStack;
20176
20234
  }
20235
+ /**
20236
+ * `reconcileCreatedAt` updates the createdAt and prevCreatedAt fields.
20237
+ *
20238
+ * When an element is replaced(e.g., UndoRemove as Add, or Set),
20239
+ * it receives a new createdAt(executedAt). However, existing history
20240
+ * operations may still reference the old createdAt or prevCreatedAt.
20241
+ *
20242
+ * This method scans both undo/redo stacks and replaces any matching
20243
+ * createdAt/prevCreatedAt with the new one, ensuring consistency.
20244
+ */
20245
+ reconcileCreatedAt(prevCreatedAt, currCreatedAt) {
20246
+ const replace = (stack) => {
20247
+ for (const ops of stack) {
20248
+ for (const op of ops) {
20249
+ if ((op instanceof ArraySetOperation || op instanceof RemoveOperation || op instanceof MoveOperation) && op.getCreatedAt() === prevCreatedAt) {
20250
+ op.setCreatedAt(currCreatedAt);
20251
+ }
20252
+ if ((op instanceof AddOperation || op instanceof MoveOperation) && op.getPrevCreatedAt() === prevCreatedAt) {
20253
+ op.setPrevCreatedAt(currCreatedAt);
20254
+ }
20255
+ }
20256
+ }
20257
+ };
20258
+ replace(this.undoStack);
20259
+ replace(this.redoStack);
20260
+ }
20177
20261
  }
20178
20262
  const EventSourceDevPanel = "yorkie-devtools-panel";
20179
20263
  const EventSourceSDK = "yorkie-devtools-sdk";
@@ -20431,6 +20515,14 @@ class Document {
20431
20515
  this.presences,
20432
20516
  OpSource.Local
20433
20517
  );
20518
+ for (const op of change.getOperations()) {
20519
+ if (op instanceof ArraySetOperation) {
20520
+ this.internalHistory.reconcileCreatedAt(
20521
+ op.getCreatedAt(),
20522
+ op.getValue().getCreatedAt()
20523
+ );
20524
+ }
20525
+ }
20434
20526
  const reversePresence = context.getReversePresence();
20435
20527
  if (reversePresence) {
20436
20528
  reverseOps.push({
@@ -21387,6 +21479,15 @@ class Document {
21387
21479
  }
21388
21480
  const ticket = context.issueTimeTicket();
21389
21481
  undoOp.setExecutedAt(ticket);
21482
+ if (undoOp instanceof ArraySetOperation) {
21483
+ const prev = undoOp.getCreatedAt();
21484
+ undoOp.getValue().setCreatedAt(ticket);
21485
+ this.internalHistory.reconcileCreatedAt(prev, ticket);
21486
+ } else if (undoOp instanceof AddOperation) {
21487
+ const prev = undoOp.getValue().getCreatedAt();
21488
+ undoOp.getValue().setCreatedAt(ticket);
21489
+ this.internalHistory.reconcileCreatedAt(prev, ticket);
21490
+ }
21390
21491
  context.push(undoOp);
21391
21492
  }
21392
21493
  const change = context.toChange();
@@ -21474,6 +21575,15 @@ class Document {
21474
21575
  }
21475
21576
  const ticket = context.issueTimeTicket();
21476
21577
  redoOp.setExecutedAt(ticket);
21578
+ if (redoOp instanceof ArraySetOperation) {
21579
+ const prev = redoOp.getCreatedAt();
21580
+ redoOp.getValue().setCreatedAt(ticket);
21581
+ this.internalHistory.reconcileCreatedAt(prev, ticket);
21582
+ } else if (redoOp instanceof AddOperation) {
21583
+ const prev = redoOp.getValue().getCreatedAt();
21584
+ redoOp.getValue().setCreatedAt(ticket);
21585
+ this.internalHistory.reconcileCreatedAt(prev, ticket);
21586
+ }
21477
21587
  context.push(redoOp);
21478
21588
  }
21479
21589
  const change = context.toChange();
@@ -21576,7 +21686,7 @@ function createAuthInterceptor(apiKey, token) {
21576
21686
  };
21577
21687
  }
21578
21688
  const name$1 = "@yorkie-js/sdk";
21579
- const version$1 = "0.6.25";
21689
+ const version$1 = "0.6.27";
21580
21690
  const pkg$1 = {
21581
21691
  name: name$1,
21582
21692
  version: version$1
@@ -22339,6 +22449,7 @@ class Client {
22339
22449
  return;
22340
22450
  }
22341
22451
  attachment.cancelWatchStream();
22452
+ attachment.doc.resetOnlineClients();
22342
22453
  attachment.unsubscribeBroadcastEvent();
22343
22454
  this.attachmentMap.delete(docKey);
22344
22455
  }
@@ -22466,7 +22577,7 @@ if (typeof globalThis !== "undefined") {
22466
22577
  };
22467
22578
  }
22468
22579
  const name = "@yorkie-js/react";
22469
- const version = "0.6.25";
22580
+ const version = "0.6.27";
22470
22581
  const pkg = {
22471
22582
  name,
22472
22583
  version