@yorkie-js/react 0.6.8-rc → 0.6.9

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.
@@ -7,7 +7,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
7
7
 
8
8
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
9
9
  const name$1 = "@yorkie-js/react";
10
- const version$1 = "0.6.8-rc";
10
+ const version$1 = "0.6.9";
11
11
  const pkg$1 = {
12
12
  name: name$1,
13
13
  version: version$1
@@ -11732,6 +11732,18 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
11732
11732
  hasTextChild() {
11733
11733
  return this.children.length > 0 && this.children.every((child) => child.isText);
11734
11734
  }
11735
+ /**
11736
+ * `getChildrenText` returns text value of all text type children.
11737
+ */
11738
+ getChildrenText() {
11739
+ if (this.isText) {
11740
+ return this.value;
11741
+ }
11742
+ if (this.hasTextChild()) {
11743
+ return this.children.map((child) => child.value).join("");
11744
+ }
11745
+ return "";
11746
+ }
11735
11747
  /**
11736
11748
  * `append` appends the given nodes to the children.
11737
11749
  */
@@ -12930,7 +12942,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
12930
12942
  return pairs;
12931
12943
  }
12932
12944
  }
12933
- function toTreeNode(node) {
12945
+ function toTreeNode$1(node) {
12934
12946
  var _a2;
12935
12947
  if (node.isText) {
12936
12948
  const currentNode = node;
@@ -12941,7 +12953,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
12941
12953
  }
12942
12954
  const treeNode = {
12943
12955
  type: node.type,
12944
- children: node.children.map(toTreeNode)
12956
+ children: node.children.map(toTreeNode$1)
12945
12957
  };
12946
12958
  if (node.attrs) {
12947
12959
  treeNode.attributes = parseObjectValues((_a2 = node.attrs) == null ? void 0 : _a2.toObject());
@@ -13285,7 +13297,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
13285
13297
  }
13286
13298
  }
13287
13299
  if (aliveContents.length) {
13288
- const value = aliveContents.map((content) => toTreeNode(content));
13300
+ const value = aliveContents.map((content) => toTreeNode$1(content));
13289
13301
  if (changes.length && changes[changes.length - 1].from === fromIdx) {
13290
13302
  changes[changes.length - 1].value = value;
13291
13303
  } else {
@@ -13327,6 +13339,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
13327
13339
  `not implemented: ${target}, ${source}, ${ticket}`
13328
13340
  );
13329
13341
  }
13342
+ /**
13343
+ * `pathToTreePos` converts the given path of the node to the TreePos.
13344
+ */
13345
+ pathToTreePos(path) {
13346
+ return this.indexTree.pathToTreePos(path);
13347
+ }
13330
13348
  /**
13331
13349
  * `purge` physically purges the given node.
13332
13350
  */
@@ -13496,7 +13514,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
13496
13514
  * `getRootTreeNode` returns the converted value of this tree to TreeNode.
13497
13515
  */
13498
13516
  getRootTreeNode() {
13499
- return toTreeNode(this.indexTree.getRoot());
13517
+ return toTreeNode$1(this.indexTree.getRoot());
13500
13518
  }
13501
13519
  /**
13502
13520
  * `toTestTreeNode` returns the JSON of this tree for debugging.
@@ -18371,6 +18389,81 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
18371
18389
  return this.counter.toJSForTest();
18372
18390
  }
18373
18391
  }
18392
+ function toTreeNode(node) {
18393
+ if (node.isText) {
18394
+ return {
18395
+ type: node.type,
18396
+ value: node.value
18397
+ };
18398
+ }
18399
+ const newNode = {
18400
+ type: node.type,
18401
+ children: node.children.map((child) => toTreeNode(child))
18402
+ };
18403
+ if (node.attrs) {
18404
+ newNode.attributes = parseObjectValues(node.attrs.toObject());
18405
+ }
18406
+ return newNode;
18407
+ }
18408
+ function createSplitNode(node, offset) {
18409
+ const newNode = {
18410
+ type: node.isText ? node.parent.type : node.type,
18411
+ children: node.isText ? node.parent.getChildrenText().length === offset ? [] : [
18412
+ {
18413
+ type: DefaultTextType,
18414
+ value: node.parent.getChildrenText().slice(offset)
18415
+ }
18416
+ ] : node.children.slice(offset).map((child) => toTreeNode(child))
18417
+ };
18418
+ if (node.attrs) {
18419
+ newNode.attributes = parseObjectValues(node.attrs.toObject());
18420
+ } else if (node.isText && node.parent.attrs) {
18421
+ newNode.attributes = parseObjectValues(node.parent.attrs.toObject());
18422
+ }
18423
+ return newNode;
18424
+ }
18425
+ function separateSplit(treePos, path) {
18426
+ const { node } = treePos;
18427
+ const parentPath = [...path].slice(0, -1);
18428
+ const last = node.isText ? node.parent.getChildrenText().length : node.children.length;
18429
+ const toPath = [...parentPath, last];
18430
+ const insertPath = [...parentPath];
18431
+ const res = [];
18432
+ insertPath[insertPath.length - 1] += 1;
18433
+ if (!path.every((v, i) => v === toPath[i])) {
18434
+ res.push({ fromPath: [...path], toPath });
18435
+ }
18436
+ const newNode = createSplitNode(node, path[path.length - 1]);
18437
+ if (newNode) {
18438
+ res.push({ fromPath: insertPath, toPath: insertPath, content: newNode });
18439
+ }
18440
+ return res;
18441
+ }
18442
+ function separateMerge(treePos, path) {
18443
+ const { node: parentNode, offset } = treePos;
18444
+ const node = parentNode.children[offset];
18445
+ const leftSiblingNode = parentNode.children[offset - 1];
18446
+ const { children } = node;
18447
+ const parentPath = [...path].slice(0, -1);
18448
+ const res = [
18449
+ { fromPath: [...path], toPath: [...parentPath, offset + 1] }
18450
+ ];
18451
+ if (!node.children.length) {
18452
+ return res;
18453
+ }
18454
+ const insertPath = [
18455
+ ...parentPath,
18456
+ offset - 1,
18457
+ leftSiblingNode.hasTextChild() ? leftSiblingNode.getChildrenText().length : leftSiblingNode.children.length
18458
+ ];
18459
+ const nodes = children.map((child) => toTreeNode(child));
18460
+ res.push({
18461
+ fromPath: insertPath,
18462
+ toPath: insertPath,
18463
+ content: nodes
18464
+ });
18465
+ return res;
18466
+ }
18374
18467
  function buildDescendants(treeNode, parent, context) {
18375
18468
  const { type } = treeNode;
18376
18469
  const ticket = context.issueTimeTicket();
@@ -18551,6 +18644,62 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
18551
18644
  }
18552
18645
  return this.tree.getIndexTree();
18553
18646
  }
18647
+ /**
18648
+ * `splitByPath` splits the tree by the given path.
18649
+ */
18650
+ splitByPath(path) {
18651
+ if (!this.context || !this.tree) {
18652
+ throw new YorkieError(
18653
+ Code.ErrNotInitialized,
18654
+ "Tree is not initialized yet"
18655
+ );
18656
+ }
18657
+ if (!path.length) {
18658
+ throw new YorkieError(
18659
+ Code.ErrInvalidArgument,
18660
+ "path should not be empty"
18661
+ );
18662
+ }
18663
+ const treePos = this.tree.pathToTreePos(path);
18664
+ const commands = separateSplit(treePos, path);
18665
+ for (const command of commands) {
18666
+ const { fromPath, toPath, content } = command;
18667
+ const fromPos = this.tree.pathToPos(fromPath);
18668
+ const toPos = this.tree.pathToPos(toPath);
18669
+ this.editInternal(fromPos, toPos, content ? [content] : [], 0);
18670
+ }
18671
+ }
18672
+ /**
18673
+ * `mergeByPath` merges the tree by the given path.
18674
+ */
18675
+ mergeByPath(path) {
18676
+ if (!this.context || !this.tree) {
18677
+ throw new YorkieError(
18678
+ Code.ErrNotInitialized,
18679
+ "Tree is not initialized yet"
18680
+ );
18681
+ }
18682
+ if (!path.length) {
18683
+ throw new YorkieError(
18684
+ Code.ErrInvalidArgument,
18685
+ "path should not be empty"
18686
+ );
18687
+ }
18688
+ const treePos = this.tree.pathToTreePos(path);
18689
+ if (treePos.node.isText) {
18690
+ throw new YorkieError(
18691
+ Code.ErrInvalidArgument,
18692
+ "text node cannot be merged"
18693
+ );
18694
+ }
18695
+ const commands = separateMerge(treePos, path);
18696
+ for (const command of commands) {
18697
+ const { fromPath, toPath, content } = command;
18698
+ const fromPos = this.tree.pathToPos(fromPath);
18699
+ const toPos = this.tree.pathToPos(toPath);
18700
+ this.editInternal(fromPos, toPos, content ?? [], 0);
18701
+ }
18702
+ }
18554
18703
  /**
18555
18704
  * `styleByPath` sets the attributes to the elements of the given path.
18556
18705
  */
@@ -20449,7 +20598,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
20449
20598
  };
20450
20599
  }
20451
20600
  const name = "@yorkie-js/sdk";
20452
- const version = "0.6.7";
20601
+ const version = "0.6.9";
20453
20602
  const pkg = {
20454
20603
  name,
20455
20604
  version