@yorkie-js/react 0.6.18 → 0.6.20

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.
@@ -5,7 +5,7 @@ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
5
5
  import { jsx } from "react/jsx-runtime";
6
6
  import { createContext, useMemo, useState, useEffect, useContext, useCallback } from "react";
7
7
  const name$1 = "@yorkie-js/react";
8
- const version$1 = "0.6.18";
8
+ const version$1 = "0.6.20";
9
9
  const pkg$1 = {
10
10
  name: name$1,
11
11
  version: version$1
@@ -10655,8 +10655,8 @@ class CRDTArray extends CRDTContainer {
10655
10655
  /**
10656
10656
  * `insertAfter` adds a new node after the the given node.
10657
10657
  */
10658
- insertAfter(prevCreatedAt, value) {
10659
- this.elements.insertAfter(prevCreatedAt, value);
10658
+ insertAfter(prevCreatedAt, value, executedAt) {
10659
+ this.elements.insertAfter(prevCreatedAt, value, executedAt);
10660
10660
  }
10661
10661
  /**
10662
10662
  * `moveAfter` moves the given `createdAt` element after the `prevCreatedAt`.
@@ -10824,6 +10824,84 @@ class CRDTArray extends CRDTContainer {
10824
10824
  return clone;
10825
10825
  }
10826
10826
  }
10827
+ class AddOperation extends Operation {
10828
+ constructor(parentCreatedAt, prevCreatedAt, value, executedAt) {
10829
+ super(parentCreatedAt, executedAt);
10830
+ __publicField(this, "prevCreatedAt");
10831
+ __publicField(this, "value");
10832
+ this.prevCreatedAt = prevCreatedAt;
10833
+ this.value = value;
10834
+ }
10835
+ /**
10836
+ * `create` creates a new instance of AddOperation.
10837
+ */
10838
+ static create(parentCreatedAt, prevCreatedAt, value, executedAt) {
10839
+ return new AddOperation(parentCreatedAt, prevCreatedAt, value, executedAt);
10840
+ }
10841
+ /**
10842
+ * `execute` executes this operation on the given `CRDTRoot`.
10843
+ */
10844
+ execute(root) {
10845
+ const parentObject = root.findByCreatedAt(this.getParentCreatedAt());
10846
+ if (!parentObject) {
10847
+ throw new YorkieError(
10848
+ Code.ErrInvalidArgument,
10849
+ `fail to find ${this.getParentCreatedAt()}`
10850
+ );
10851
+ }
10852
+ if (!(parentObject instanceof CRDTArray)) {
10853
+ throw new YorkieError(
10854
+ Code.ErrInvalidArgument,
10855
+ `fail to execute, only array can execute add`
10856
+ );
10857
+ }
10858
+ const array = parentObject;
10859
+ const value = this.value.deepcopy();
10860
+ array.insertAfter(this.prevCreatedAt, value, this.getExecutedAt());
10861
+ root.registerElement(value, array);
10862
+ return {
10863
+ opInfos: [
10864
+ {
10865
+ type: "add",
10866
+ path: root.createPath(this.getParentCreatedAt()),
10867
+ index: Number(array.subPathOf(this.getEffectedCreatedAt()))
10868
+ }
10869
+ ],
10870
+ reverseOp: this.toReverseOperation()
10871
+ };
10872
+ }
10873
+ toReverseOperation() {
10874
+ const reverseOp = RemoveOperation.create(
10875
+ this.getParentCreatedAt(),
10876
+ this.value.getCreatedAt()
10877
+ );
10878
+ return reverseOp;
10879
+ }
10880
+ /**
10881
+ * `getEffectedCreatedAt` returns the creation time of the effected element.
10882
+ */
10883
+ getEffectedCreatedAt() {
10884
+ return this.value.getCreatedAt();
10885
+ }
10886
+ /**
10887
+ * `toTestString` returns a string containing the meta data.
10888
+ */
10889
+ toTestString() {
10890
+ return `${this.getParentCreatedAt().toTestString()}.ADD.${this.value.toJSON()}`;
10891
+ }
10892
+ /**
10893
+ * `getPrevCreatedAt` returns the creation time of previous element.
10894
+ */
10895
+ getPrevCreatedAt() {
10896
+ return this.prevCreatedAt;
10897
+ }
10898
+ /**
10899
+ * `getValue` returns the value of this operation.
10900
+ */
10901
+ getValue() {
10902
+ return this.value;
10903
+ }
10904
+ }
10827
10905
  class RemoveOperation extends Operation {
10828
10906
  constructor(parentCreatedAt, createdAt, executedAt) {
10829
10907
  super(parentCreatedAt, executedAt);
@@ -10888,6 +10966,19 @@ class RemoveOperation extends Operation {
10888
10966
  * `toReverseOperation` returns the reverse operation of this operation.
10889
10967
  */
10890
10968
  toReverseOperation(parentObject) {
10969
+ if (parentObject instanceof CRDTArray) {
10970
+ const value = parentObject.getByID(this.createdAt);
10971
+ if (value !== void 0) {
10972
+ const prevCreatedAt = parentObject.getPrevCreatedAt(
10973
+ this.createdAt
10974
+ );
10975
+ return AddOperation.create(
10976
+ this.getParentCreatedAt(),
10977
+ prevCreatedAt,
10978
+ value.deepcopy()
10979
+ );
10980
+ }
10981
+ }
10891
10982
  if (parentObject instanceof CRDTObject) {
10892
10983
  const key = parentObject.subPathOf(this.createdAt);
10893
10984
  if (key !== void 0) {
@@ -11026,76 +11117,6 @@ class SetOperation extends Operation {
11026
11117
  return this.value;
11027
11118
  }
11028
11119
  }
11029
- class AddOperation extends Operation {
11030
- constructor(parentCreatedAt, prevCreatedAt, value, executedAt) {
11031
- super(parentCreatedAt, executedAt);
11032
- __publicField(this, "prevCreatedAt");
11033
- __publicField(this, "value");
11034
- this.prevCreatedAt = prevCreatedAt;
11035
- this.value = value;
11036
- }
11037
- /**
11038
- * `create` creates a new instance of AddOperation.
11039
- */
11040
- static create(parentCreatedAt, prevCreatedAt, value, executedAt) {
11041
- return new AddOperation(parentCreatedAt, prevCreatedAt, value, executedAt);
11042
- }
11043
- /**
11044
- * `execute` executes this operation on the given `CRDTRoot`.
11045
- */
11046
- execute(root) {
11047
- const parentObject = root.findByCreatedAt(this.getParentCreatedAt());
11048
- if (!parentObject) {
11049
- throw new YorkieError(
11050
- Code.ErrInvalidArgument,
11051
- `fail to find ${this.getParentCreatedAt()}`
11052
- );
11053
- }
11054
- if (!(parentObject instanceof CRDTArray)) {
11055
- throw new YorkieError(
11056
- Code.ErrInvalidArgument,
11057
- `fail to execute, only array can execute add`
11058
- );
11059
- }
11060
- const array = parentObject;
11061
- const value = this.value.deepcopy();
11062
- array.insertAfter(this.prevCreatedAt, value);
11063
- root.registerElement(value, array);
11064
- return {
11065
- opInfos: [
11066
- {
11067
- type: "add",
11068
- path: root.createPath(this.getParentCreatedAt()),
11069
- index: Number(array.subPathOf(this.getEffectedCreatedAt()))
11070
- }
11071
- ]
11072
- };
11073
- }
11074
- /**
11075
- * `getEffectedCreatedAt` returns the creation time of the effected element.
11076
- */
11077
- getEffectedCreatedAt() {
11078
- return this.value.getCreatedAt();
11079
- }
11080
- /**
11081
- * `toTestString` returns a string containing the meta data.
11082
- */
11083
- toTestString() {
11084
- return `${this.getParentCreatedAt().toTestString()}.ADD.${this.value.toJSON()}`;
11085
- }
11086
- /**
11087
- * `getPrevCreatedAt` returns the creation time of previous element.
11088
- */
11089
- getPrevCreatedAt() {
11090
- return this.prevCreatedAt;
11091
- }
11092
- /**
11093
- * `getValue` returns the value of this operation.
11094
- */
11095
- getValue() {
11096
- return this.value;
11097
- }
11098
- }
11099
11120
  class MoveOperation extends Operation {
11100
11121
  constructor(parentCreatedAt, prevCreatedAt, createdAt, executedAt) {
11101
11122
  super(parentCreatedAt, executedAt);
@@ -11133,6 +11154,7 @@ class MoveOperation extends Operation {
11133
11154
  );
11134
11155
  }
11135
11156
  const array = parentObject;
11157
+ const reverseOp = this.toReverseOperation(array);
11136
11158
  const previousIndex = Number(array.subPathOf(this.createdAt));
11137
11159
  array.moveAfter(this.prevCreatedAt, this.createdAt, this.getExecutedAt());
11138
11160
  const index = Number(array.subPathOf(this.createdAt));
@@ -11144,9 +11166,18 @@ class MoveOperation extends Operation {
11144
11166
  index,
11145
11167
  previousIndex
11146
11168
  }
11147
- ]
11169
+ ],
11170
+ reverseOp
11148
11171
  };
11149
11172
  }
11173
+ toReverseOperation(array) {
11174
+ const preservePrevCreatedAt = array.getPrevCreatedAt(this.createdAt);
11175
+ return MoveOperation.create(
11176
+ this.getParentCreatedAt(),
11177
+ preservePrevCreatedAt,
11178
+ this.createdAt
11179
+ );
11180
+ }
11150
11181
  /**
11151
11182
  * `getEffectedCreatedAt` returns the creation time of the effected element.
11152
11183
  */
@@ -21233,7 +21264,7 @@ function createAuthInterceptor(apiKey, token) {
21233
21264
  };
21234
21265
  }
21235
21266
  const name = "@yorkie-js/sdk";
21236
- const version = "0.6.18";
21267
+ const version = "0.6.20";
21237
21268
  const pkg = {
21238
21269
  name,
21239
21270
  version