@yorkie-js/sdk 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.
@@ -11134,6 +11134,32 @@
11134
11134
  }
11135
11135
  actualRight.push(child);
11136
11136
  }
11137
+ if (versionVector) {
11138
+ const movedToLeft = [];
11139
+ const remaining = [];
11140
+ let boundaryReached = false;
11141
+ for (const child of actualRight) {
11142
+ if (!boundaryReached) {
11143
+ if (child.insPrevID !== void 0 && !child.isText) {
11144
+ remaining.push(child);
11145
+ continue;
11146
+ }
11147
+ const actorID = child.id.getCreatedAt().getActorID();
11148
+ const knownLamport = versionVector.get(actorID);
11149
+ if (knownLamport === void 0 || knownLamport < child.id.getCreatedAt().getLamport()) {
11150
+ movedToLeft.push(child);
11151
+ continue;
11152
+ }
11153
+ }
11154
+ boundaryReached = true;
11155
+ remaining.push(child);
11156
+ }
11157
+ if (movedToLeft.length > 0) {
11158
+ left.push(...movedToLeft);
11159
+ actualRight.length = 0;
11160
+ actualRight.push(...remaining);
11161
+ }
11162
+ }
11137
11163
  this._children = left;
11138
11164
  clone._children = actualRight;
11139
11165
  this.visibleSize = this._children.reduce(
@@ -11910,8 +11936,14 @@
11910
11936
  split.insPrevID = this.id;
11911
11937
  if (this.insNextID) {
11912
11938
  const insNext = tree.findFloorNode(this.insNextID);
11913
- insNext.insPrevID = split.id;
11914
11939
  split.insNextID = this.insNextID;
11940
+ if (insNext) {
11941
+ insNext.insPrevID = split.id;
11942
+ if (!this.isText && insNext.parent && !insNext.isRemoved && insNext.parent !== split.parent && split.allChildren.length === 0) {
11943
+ split.parent.detachChild(split);
11944
+ insNext.parent.insertBefore(split, insNext);
11945
+ }
11946
+ }
11915
11947
  }
11916
11948
  this.insNextID = split.id;
11917
11949
  tree.registerNode(split);
@@ -12135,7 +12167,7 @@
12135
12167
  * given node, advancing past element-type split siblings that the editing
12136
12168
  * client did not know about (not in versionVector).
12137
12169
  */
12138
- advancePastUnknownSplitSiblings(node, versionVector) {
12170
+ advancePastUnknownSplitSiblings(node, versionVector, relaxParentCheck = false, skipActorID) {
12139
12171
  if (!versionVector || !node) {
12140
12172
  return node;
12141
12173
  }
@@ -12145,10 +12177,13 @@
12145
12177
  if (!next || next.isText) {
12146
12178
  break;
12147
12179
  }
12148
- if (next.parent !== current.parent) {
12180
+ if (!relaxParentCheck && next.parent !== current.parent) {
12149
12181
  break;
12150
12182
  }
12151
12183
  const actorID = next.id.getCreatedAt().getActorID();
12184
+ if (skipActorID !== void 0 && actorID === skipActorID) {
12185
+ break;
12186
+ }
12152
12187
  const knownLamport = versionVector.get(actorID);
12153
12188
  if (knownLamport !== void 0 && knownLamport >= next.id.getCreatedAt().getLamport()) {
12154
12189
  break;
@@ -12489,6 +12524,23 @@
12489
12524
  addDataSizes(diff, diffTo, diffFrom);
12490
12525
  const fromLeft = fromLeftRaw !== fromParent ? this.advancePastUnknownSplitSiblings(fromLeftRaw, versionVector) : fromLeftRaw;
12491
12526
  const toLeft = toLeftRaw !== toParent ? this.advancePastUnknownSplitSiblings(toLeftRaw, versionVector) : toLeftRaw;
12527
+ let collectFromParent = fromParent;
12528
+ let collectFromLeft = fromLeft;
12529
+ if (fromLeft !== fromParent && fromParent !== toParent) {
12530
+ let current = fromLeft;
12531
+ while (current.insNextID) {
12532
+ const next = this.findFloorNode(current.insNextID);
12533
+ if (!next || next.isText) {
12534
+ break;
12535
+ }
12536
+ if (next.parent && next.parent === toParent) {
12537
+ collectFromLeft = next;
12538
+ collectFromParent = toParent;
12539
+ break;
12540
+ }
12541
+ current = next;
12542
+ }
12543
+ }
12492
12544
  const fromIdx = this.toIndex(fromParent, fromLeft);
12493
12545
  const fromPath = this.toPath(fromParent, fromLeft);
12494
12546
  const nodesToBeRemoved = [];
@@ -12497,8 +12549,8 @@
12497
12549
  const toBeMergedNodes = [];
12498
12550
  const preTombstoned = /* @__PURE__ */ new Set();
12499
12551
  this.traverseInPosRange(
12500
- fromParent,
12501
- fromLeft,
12552
+ collectFromParent,
12553
+ collectFromLeft,
12502
12554
  toParent,
12503
12555
  toLeft,
12504
12556
  ([node, tokenType], ended) => {
@@ -12602,9 +12654,20 @@
12602
12654
  let parent = fromParent;
12603
12655
  let left = fromLeft;
12604
12656
  while (splitCount < splitLevel) {
12657
+ if (left !== parent) {
12658
+ left = this.advancePastUnknownSplitSiblings(
12659
+ left,
12660
+ versionVector,
12661
+ true,
12662
+ editedAt.getActorID()
12663
+ );
12664
+ if (left.parent && left.parent !== parent) {
12665
+ parent = left.parent;
12666
+ }
12667
+ }
12605
12668
  parent.split(
12606
12669
  this,
12607
- parent.findOffset(left, true) + 1,
12670
+ left !== parent ? parent.findOffset(left, true) + 1 : 0,
12608
12671
  issueTimeTicket,
12609
12672
  versionVector
12610
12673
  );
@@ -13211,10 +13274,10 @@
13211
13274
  );
13212
13275
  this.lastToIdx = preEditFromIdx + removedSize;
13213
13276
  let reverseOp;
13214
- const isPureL1Split = this.splitLevel === 1 && !this.contents?.length && removedNodes.length === 0;
13277
+ const isPureSplit = this.splitLevel > 0 && !this.contents?.length && removedNodes.length === 0;
13215
13278
  if (this.splitLevel === 0) {
13216
13279
  reverseOp = this.toReverseOperation(tree, removedNodes, preEditFromIdx);
13217
- } else if (isPureL1Split) {
13280
+ } else if (isPureSplit) {
13218
13281
  reverseOp = this.toSplitReverseOperation(tree, preEditFromIdx);
13219
13282
  }
13220
13283
  root.acc(diff);
@@ -20815,7 +20878,7 @@
20815
20878
  };
20816
20879
  }
20817
20880
  const name = "@yorkie-js/sdk";
20818
- const version = "0.7.6";
20881
+ const version = "0.7.7";
20819
20882
  const pkg = {
20820
20883
  name,
20821
20884
  version
@@ -22531,8 +22594,11 @@
22531
22594
  function isCounter(value) {
22532
22595
  return typeof value === "object" && value !== null && value.type === "Counter" && typeof value.value === "object";
22533
22596
  }
22597
+ function isDedupCounter(value) {
22598
+ return typeof value === "object" && value !== null && value.type === "DedupCounter" && typeof value.value === "object" && typeof value.registers === "string";
22599
+ }
22534
22600
  function isObject(value) {
22535
- return typeof value === "object" && value !== null && !Array.isArray(value) && !isText(value) && !isTree(value) && !isInt(value) && !isLong(value) && !isDate(value) && !isBinData(value) && !isCounter(value);
22601
+ 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);
22536
22602
  }
22537
22603
  function parse(yson) {
22538
22604
  try {
@@ -22548,6 +22614,12 @@
22548
22614
  }
22549
22615
  function preprocessYSON(yson) {
22550
22616
  let result = yson;
22617
+ result = result.replace(
22618
+ /DedupCounter\(Int\((-?\d+)\),"([^"]+)"\)/g,
22619
+ (_, value, registers) => {
22620
+ return `{"__yson_type":"DedupCounter","__yson_data":{"__yson_type":"Int","__yson_data":${value}},"__yson_registers":"${registers}"}`;
22621
+ }
22622
+ );
22551
22623
  result = result.replace(
22552
22624
  /Counter\((Int|Long)\((-?\d+)\)\)/g,
22553
22625
  (_, type, value) => {
@@ -22608,6 +22680,20 @@
22608
22680
  value: value.__yson_data
22609
22681
  };
22610
22682
  }
22683
+ if (value.__yson_type === "DedupCounter" && typeof value.__yson_data === "object" && typeof value.__yson_registers === "string") {
22684
+ const counterValue = postprocessValue(value.__yson_data);
22685
+ if (typeof counterValue === "object" && counterValue !== null && "type" in counterValue && counterValue.type === "Int") {
22686
+ return {
22687
+ type: "DedupCounter",
22688
+ value: counterValue,
22689
+ registers: value.__yson_registers
22690
+ };
22691
+ }
22692
+ throw new YorkieError(
22693
+ Code.ErrInvalidArgument,
22694
+ "DedupCounter must contain Int"
22695
+ );
22696
+ }
22611
22697
  if (value.__yson_type === "Counter" && typeof value.__yson_data === "object") {
22612
22698
  const counterValue = postprocessValue(value.__yson_data);
22613
22699
  if (typeof counterValue === "object" && counterValue !== null && "type" in counterValue && (counterValue.type === "Int" || counterValue.type === "Long")) {
@@ -22696,6 +22782,7 @@
22696
22782
  isBinData,
22697
22783
  isCounter,
22698
22784
  isDate,
22785
+ isDedupCounter,
22699
22786
  isInt,
22700
22787
  isLong,
22701
22788
  isObject,