@yorkie-js/react 0.7.6 → 0.7.7

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.
@@ -11132,6 +11132,32 @@ class IndexTreeNode {
11132
11132
  }
11133
11133
  actualRight.push(child);
11134
11134
  }
11135
+ if (versionVector) {
11136
+ const movedToLeft = [];
11137
+ const remaining = [];
11138
+ let boundaryReached = false;
11139
+ for (const child of actualRight) {
11140
+ if (!boundaryReached) {
11141
+ if (child.insPrevID !== void 0 && !child.isText) {
11142
+ remaining.push(child);
11143
+ continue;
11144
+ }
11145
+ const actorID = child.id.getCreatedAt().getActorID();
11146
+ const knownLamport = versionVector.get(actorID);
11147
+ if (knownLamport === void 0 || knownLamport < child.id.getCreatedAt().getLamport()) {
11148
+ movedToLeft.push(child);
11149
+ continue;
11150
+ }
11151
+ }
11152
+ boundaryReached = true;
11153
+ remaining.push(child);
11154
+ }
11155
+ if (movedToLeft.length > 0) {
11156
+ left.push(...movedToLeft);
11157
+ actualRight.length = 0;
11158
+ actualRight.push(...remaining);
11159
+ }
11160
+ }
11135
11161
  this._children = left;
11136
11162
  clone._children = actualRight;
11137
11163
  this.visibleSize = this._children.reduce(
@@ -11908,8 +11934,14 @@ class CRDTTreeNode extends IndexTreeNode {
11908
11934
  split.insPrevID = this.id;
11909
11935
  if (this.insNextID) {
11910
11936
  const insNext = tree.findFloorNode(this.insNextID);
11911
- insNext.insPrevID = split.id;
11912
11937
  split.insNextID = this.insNextID;
11938
+ if (insNext) {
11939
+ insNext.insPrevID = split.id;
11940
+ if (!this.isText && insNext.parent && !insNext.isRemoved && insNext.parent !== split.parent && split.allChildren.length === 0) {
11941
+ split.parent.detachChild(split);
11942
+ insNext.parent.insertBefore(split, insNext);
11943
+ }
11944
+ }
11913
11945
  }
11914
11946
  this.insNextID = split.id;
11915
11947
  tree.registerNode(split);
@@ -12133,7 +12165,7 @@ class CRDTTree extends CRDTElement {
12133
12165
  * given node, advancing past element-type split siblings that the editing
12134
12166
  * client did not know about (not in versionVector).
12135
12167
  */
12136
- advancePastUnknownSplitSiblings(node, versionVector) {
12168
+ advancePastUnknownSplitSiblings(node, versionVector, relaxParentCheck = false, skipActorID) {
12137
12169
  if (!versionVector || !node) {
12138
12170
  return node;
12139
12171
  }
@@ -12143,10 +12175,13 @@ class CRDTTree extends CRDTElement {
12143
12175
  if (!next || next.isText) {
12144
12176
  break;
12145
12177
  }
12146
- if (next.parent !== current.parent) {
12178
+ if (!relaxParentCheck && next.parent !== current.parent) {
12147
12179
  break;
12148
12180
  }
12149
12181
  const actorID = next.id.getCreatedAt().getActorID();
12182
+ if (skipActorID !== void 0 && actorID === skipActorID) {
12183
+ break;
12184
+ }
12150
12185
  const knownLamport = versionVector.get(actorID);
12151
12186
  if (knownLamport !== void 0 && knownLamport >= next.id.getCreatedAt().getLamport()) {
12152
12187
  break;
@@ -12487,6 +12522,23 @@ class CRDTTree extends CRDTElement {
12487
12522
  addDataSizes(diff, diffTo, diffFrom);
12488
12523
  const fromLeft = fromLeftRaw !== fromParent ? this.advancePastUnknownSplitSiblings(fromLeftRaw, versionVector) : fromLeftRaw;
12489
12524
  const toLeft = toLeftRaw !== toParent ? this.advancePastUnknownSplitSiblings(toLeftRaw, versionVector) : toLeftRaw;
12525
+ let collectFromParent = fromParent;
12526
+ let collectFromLeft = fromLeft;
12527
+ if (fromLeft !== fromParent && fromParent !== toParent) {
12528
+ let current = fromLeft;
12529
+ while (current.insNextID) {
12530
+ const next = this.findFloorNode(current.insNextID);
12531
+ if (!next || next.isText) {
12532
+ break;
12533
+ }
12534
+ if (next.parent && next.parent === toParent) {
12535
+ collectFromLeft = next;
12536
+ collectFromParent = toParent;
12537
+ break;
12538
+ }
12539
+ current = next;
12540
+ }
12541
+ }
12490
12542
  const fromIdx = this.toIndex(fromParent, fromLeft);
12491
12543
  const fromPath = this.toPath(fromParent, fromLeft);
12492
12544
  const nodesToBeRemoved = [];
@@ -12495,8 +12547,8 @@ class CRDTTree extends CRDTElement {
12495
12547
  const toBeMergedNodes = [];
12496
12548
  const preTombstoned = /* @__PURE__ */ new Set();
12497
12549
  this.traverseInPosRange(
12498
- fromParent,
12499
- fromLeft,
12550
+ collectFromParent,
12551
+ collectFromLeft,
12500
12552
  toParent,
12501
12553
  toLeft,
12502
12554
  ([node, tokenType], ended) => {
@@ -12600,9 +12652,20 @@ class CRDTTree extends CRDTElement {
12600
12652
  let parent = fromParent;
12601
12653
  let left = fromLeft;
12602
12654
  while (splitCount < splitLevel) {
12655
+ if (left !== parent) {
12656
+ left = this.advancePastUnknownSplitSiblings(
12657
+ left,
12658
+ versionVector,
12659
+ true,
12660
+ editedAt.getActorID()
12661
+ );
12662
+ if (left.parent && left.parent !== parent) {
12663
+ parent = left.parent;
12664
+ }
12665
+ }
12603
12666
  parent.split(
12604
12667
  this,
12605
- parent.findOffset(left, true) + 1,
12668
+ left !== parent ? parent.findOffset(left, true) + 1 : 0,
12606
12669
  issueTimeTicket,
12607
12670
  versionVector
12608
12671
  );
@@ -13209,10 +13272,10 @@ class TreeEditOperation extends Operation {
13209
13272
  );
13210
13273
  this.lastToIdx = preEditFromIdx + removedSize;
13211
13274
  let reverseOp;
13212
- const isPureL1Split = this.splitLevel === 1 && !this.contents?.length && removedNodes.length === 0;
13275
+ const isPureSplit = this.splitLevel > 0 && !this.contents?.length && removedNodes.length === 0;
13213
13276
  if (this.splitLevel === 0) {
13214
13277
  reverseOp = this.toReverseOperation(tree, removedNodes, preEditFromIdx);
13215
- } else if (isPureL1Split) {
13278
+ } else if (isPureSplit) {
13216
13279
  reverseOp = this.toSplitReverseOperation(tree, preEditFromIdx);
13217
13280
  }
13218
13281
  root.acc(diff);
@@ -20808,7 +20871,7 @@ function createAuthInterceptor(apiKey, token) {
20808
20871
  };
20809
20872
  }
20810
20873
  const name$1 = "@yorkie-js/sdk";
20811
- const version$1 = "0.7.6";
20874
+ const version$1 = "0.7.7";
20812
20875
  const pkg$1 = {
20813
20876
  name: name$1,
20814
20877
  version: version$1
@@ -22514,8 +22577,11 @@ function isBinData(value) {
22514
22577
  function isCounter(value) {
22515
22578
  return typeof value === "object" && value !== null && value.type === "Counter" && typeof value.value === "object";
22516
22579
  }
22580
+ function isDedupCounter(value) {
22581
+ return typeof value === "object" && value !== null && value.type === "DedupCounter" && typeof value.value === "object" && typeof value.registers === "string";
22582
+ }
22517
22583
  function isObject(value) {
22518
- return typeof value === "object" && value !== null && !Array.isArray(value) && !isText(value) && !isTree(value) && !isInt(value) && !isLong(value) && !isDate(value) && !isBinData(value) && !isCounter(value);
22584
+ return typeof value === "object" && value !== null && !Array.isArray(value) && !isText(value) && !isTree(value) && !isInt(value) && !isLong(value) && !isDate(value) && !isBinData(value) && !isCounter(value) && !isDedupCounter(value);
22519
22585
  }
22520
22586
  function parse(yson) {
22521
22587
  try {
@@ -22531,6 +22597,12 @@ function parse(yson) {
22531
22597
  }
22532
22598
  function preprocessYSON(yson) {
22533
22599
  let result = yson;
22600
+ result = result.replace(
22601
+ /DedupCounter\(Int\((-?\d+)\),"([^"]+)"\)/g,
22602
+ (_, value, registers) => {
22603
+ return `{"__yson_type":"DedupCounter","__yson_data":{"__yson_type":"Int","__yson_data":${value}},"__yson_registers":"${registers}"}`;
22604
+ }
22605
+ );
22534
22606
  result = result.replace(
22535
22607
  /Counter\((Int|Long)\((-?\d+)\)\)/g,
22536
22608
  (_, type, value) => {
@@ -22591,6 +22663,20 @@ function postprocessValue(value) {
22591
22663
  value: value.__yson_data
22592
22664
  };
22593
22665
  }
22666
+ if (value.__yson_type === "DedupCounter" && typeof value.__yson_data === "object" && typeof value.__yson_registers === "string") {
22667
+ const counterValue = postprocessValue(value.__yson_data);
22668
+ if (typeof counterValue === "object" && counterValue !== null && "type" in counterValue && counterValue.type === "Int") {
22669
+ return {
22670
+ type: "DedupCounter",
22671
+ value: counterValue,
22672
+ registers: value.__yson_registers
22673
+ };
22674
+ }
22675
+ throw new YorkieError(
22676
+ Code.ErrInvalidArgument,
22677
+ "DedupCounter must contain Int"
22678
+ );
22679
+ }
22594
22680
  if (value.__yson_type === "Counter" && typeof value.__yson_data === "object") {
22595
22681
  const counterValue = postprocessValue(value.__yson_data);
22596
22682
  if (typeof counterValue === "object" && counterValue !== null && "type" in counterValue && (counterValue.type === "Int" || counterValue.type === "Long")) {
@@ -22679,6 +22765,7 @@ const YSON = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty
22679
22765
  isBinData,
22680
22766
  isCounter,
22681
22767
  isDate,
22768
+ isDedupCounter,
22682
22769
  isInt,
22683
22770
  isLong,
22684
22771
  isObject,
@@ -22705,7 +22792,7 @@ if (typeof globalThis !== "undefined") {
22705
22792
  };
22706
22793
  }
22707
22794
  const name = "@yorkie-js/react";
22708
- const version = "0.7.6";
22795
+ const version = "0.7.7";
22709
22796
  const pkg = {
22710
22797
  name,
22711
22798
  version