@yorkie-js/react 0.6.49 → 0.7.0
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.
package/dist/yorkie-js-react.js
CHANGED
|
@@ -12499,7 +12499,7 @@
|
|
|
12499
12499
|
}
|
|
12500
12500
|
}
|
|
12501
12501
|
}
|
|
12502
|
-
return [changes, pairs, diff];
|
|
12502
|
+
return [changes, pairs, diff, nodesToBeRemoved, fromIdx];
|
|
12503
12503
|
}
|
|
12504
12504
|
/**
|
|
12505
12505
|
* `editT` edits the given range with the given value.
|
|
@@ -12937,29 +12937,46 @@
|
|
|
12937
12937
|
return [prev, prev.isText ? TokenType.Text : TokenType.End];
|
|
12938
12938
|
}
|
|
12939
12939
|
}
|
|
12940
|
+
function clearRemovedAt(node) {
|
|
12941
|
+
traverseAll(node, (n) => {
|
|
12942
|
+
n.removedAt = void 0;
|
|
12943
|
+
n.visibleSize = n.totalSize;
|
|
12944
|
+
});
|
|
12945
|
+
}
|
|
12940
12946
|
class TreeEditOperation extends Operation {
|
|
12941
12947
|
fromPos;
|
|
12942
12948
|
toPos;
|
|
12943
12949
|
contents;
|
|
12944
12950
|
splitLevel;
|
|
12945
|
-
|
|
12951
|
+
isUndoOp;
|
|
12952
|
+
fromIdx;
|
|
12953
|
+
toIdx;
|
|
12954
|
+
lastFromIdx;
|
|
12955
|
+
lastToIdx;
|
|
12956
|
+
constructor(parentCreatedAt, fromPos, toPos, contents, splitLevel, executedAt, isUndoOp, fromIdx, toIdx) {
|
|
12946
12957
|
super(parentCreatedAt, executedAt);
|
|
12947
12958
|
this.fromPos = fromPos;
|
|
12948
12959
|
this.toPos = toPos;
|
|
12949
12960
|
this.contents = contents;
|
|
12950
12961
|
this.splitLevel = splitLevel;
|
|
12962
|
+
this.isUndoOp = isUndoOp;
|
|
12963
|
+
this.fromIdx = fromIdx;
|
|
12964
|
+
this.toIdx = toIdx;
|
|
12951
12965
|
}
|
|
12952
12966
|
/**
|
|
12953
12967
|
* `create` creates a new instance of EditOperation.
|
|
12954
12968
|
*/
|
|
12955
|
-
static create(parentCreatedAt, fromPos, toPos, contents, splitLevel, executedAt) {
|
|
12969
|
+
static create(parentCreatedAt, fromPos, toPos, contents, splitLevel, executedAt, isUndoOp, fromIdx, toIdx) {
|
|
12956
12970
|
return new TreeEditOperation(
|
|
12957
12971
|
parentCreatedAt,
|
|
12958
12972
|
fromPos,
|
|
12959
12973
|
toPos,
|
|
12960
12974
|
contents,
|
|
12961
12975
|
splitLevel,
|
|
12962
|
-
executedAt
|
|
12976
|
+
executedAt,
|
|
12977
|
+
isUndoOp,
|
|
12978
|
+
fromIdx,
|
|
12979
|
+
toIdx
|
|
12963
12980
|
);
|
|
12964
12981
|
}
|
|
12965
12982
|
/**
|
|
@@ -12981,7 +12998,15 @@
|
|
|
12981
12998
|
}
|
|
12982
12999
|
const editedAt = this.getExecutedAt();
|
|
12983
13000
|
const tree = parentObject;
|
|
12984
|
-
|
|
13001
|
+
if (this.isUndoOp && this.fromIdx !== void 0 && this.toIdx !== void 0) {
|
|
13002
|
+
this.fromPos = tree.findPos(this.fromIdx);
|
|
13003
|
+
if (this.fromIdx === this.toIdx) {
|
|
13004
|
+
this.toPos = this.fromPos;
|
|
13005
|
+
} else {
|
|
13006
|
+
this.toPos = tree.findPos(this.toIdx);
|
|
13007
|
+
}
|
|
13008
|
+
}
|
|
13009
|
+
const [changes, pairs, diff, removedNodes, preEditFromIdx] = tree.edit(
|
|
12985
13010
|
[this.fromPos, this.toPos],
|
|
12986
13011
|
this.contents?.map((content) => content.deepcopy()),
|
|
12987
13012
|
this.splitLevel,
|
|
@@ -13007,6 +13032,13 @@
|
|
|
13007
13032
|
})(),
|
|
13008
13033
|
versionVector
|
|
13009
13034
|
);
|
|
13035
|
+
this.lastFromIdx = preEditFromIdx;
|
|
13036
|
+
const removedSize = removedNodes.reduce(
|
|
13037
|
+
(sum, node) => sum + node.paddedSize(),
|
|
13038
|
+
0
|
|
13039
|
+
);
|
|
13040
|
+
this.lastToIdx = preEditFromIdx + removedSize;
|
|
13041
|
+
const reverseOp = this.splitLevel === 0 ? this.toReverseOperation(tree, removedNodes, preEditFromIdx) : void 0;
|
|
13010
13042
|
root.acc(diff);
|
|
13011
13043
|
for (const pair of pairs) {
|
|
13012
13044
|
root.registerGCPair(pair);
|
|
@@ -13025,9 +13057,131 @@
|
|
|
13025
13057
|
toPath
|
|
13026
13058
|
};
|
|
13027
13059
|
}
|
|
13028
|
-
)
|
|
13060
|
+
),
|
|
13061
|
+
reverseOp
|
|
13029
13062
|
};
|
|
13030
13063
|
}
|
|
13064
|
+
/**
|
|
13065
|
+
* `toReverseOperation` creates the reverse operation for undo.
|
|
13066
|
+
*
|
|
13067
|
+
* The reverse op stores both CRDTTreePos (for initial use) and integer
|
|
13068
|
+
* indices (for reconciliation adjustment when remote edits arrive).
|
|
13069
|
+
* At undo execution time, the integer indices take precedence and are
|
|
13070
|
+
* converted to CRDTTreePos via tree.findPos().
|
|
13071
|
+
*
|
|
13072
|
+
* @param tree - The CRDTTree after the edit has been applied
|
|
13073
|
+
* @param removedNodes - Nodes that were removed by this edit
|
|
13074
|
+
* @param preEditFromIdx - The from index captured BEFORE the edit
|
|
13075
|
+
*/
|
|
13076
|
+
toReverseOperation(tree, removedNodes, preEditFromIdx) {
|
|
13077
|
+
const insertedContentSize = this.contents ? this.contents.reduce((sum, node) => sum + node.paddedSize(), 0) : 0;
|
|
13078
|
+
const maxNeededIdx = preEditFromIdx + insertedContentSize;
|
|
13079
|
+
if (maxNeededIdx > tree.getSize()) {
|
|
13080
|
+
return void 0;
|
|
13081
|
+
}
|
|
13082
|
+
const topLevelRemoved = removedNodes.filter(
|
|
13083
|
+
(node) => !node.parent || !removedNodes.includes(node.parent)
|
|
13084
|
+
);
|
|
13085
|
+
const reverseContents = topLevelRemoved.length > 0 ? topLevelRemoved.map((n) => {
|
|
13086
|
+
const clone = n.deepcopy();
|
|
13087
|
+
clearRemovedAt(clone);
|
|
13088
|
+
return clone;
|
|
13089
|
+
}) : void 0;
|
|
13090
|
+
const reverseFromPos = tree.findPos(preEditFromIdx);
|
|
13091
|
+
let reverseToPos;
|
|
13092
|
+
if (insertedContentSize > 0) {
|
|
13093
|
+
reverseToPos = tree.findPos(preEditFromIdx + insertedContentSize);
|
|
13094
|
+
} else {
|
|
13095
|
+
reverseToPos = reverseFromPos;
|
|
13096
|
+
}
|
|
13097
|
+
const reverseFromIdx = preEditFromIdx;
|
|
13098
|
+
const reverseToIdx = preEditFromIdx + insertedContentSize;
|
|
13099
|
+
return TreeEditOperation.create(
|
|
13100
|
+
this.getParentCreatedAt(),
|
|
13101
|
+
reverseFromPos,
|
|
13102
|
+
reverseToPos,
|
|
13103
|
+
reverseContents,
|
|
13104
|
+
0,
|
|
13105
|
+
// splitLevel always 0
|
|
13106
|
+
void 0,
|
|
13107
|
+
// executedAt set during undo
|
|
13108
|
+
true,
|
|
13109
|
+
// isUndoOp
|
|
13110
|
+
reverseFromIdx,
|
|
13111
|
+
reverseToIdx
|
|
13112
|
+
);
|
|
13113
|
+
}
|
|
13114
|
+
/**
|
|
13115
|
+
* `normalizePos` returns the visible-index range of this operation.
|
|
13116
|
+
* For undo ops, returns the stored (possibly reconciled) indices.
|
|
13117
|
+
* For forward ops, returns the pre-edit indices captured during execute().
|
|
13118
|
+
*/
|
|
13119
|
+
normalizePos() {
|
|
13120
|
+
if (this.isUndoOp && this.fromIdx !== void 0 && this.toIdx !== void 0) {
|
|
13121
|
+
return [this.fromIdx, this.toIdx];
|
|
13122
|
+
}
|
|
13123
|
+
if (this.lastFromIdx !== void 0 && this.lastToIdx !== void 0) {
|
|
13124
|
+
return [this.lastFromIdx, this.lastToIdx];
|
|
13125
|
+
}
|
|
13126
|
+
return [0, 0];
|
|
13127
|
+
}
|
|
13128
|
+
/**
|
|
13129
|
+
* `reconcileOperation` adjusts this undo operation's integer indices
|
|
13130
|
+
* when a remote edit modifies the same tree. Uses the same 6-case
|
|
13131
|
+
* overlap logic as EditOperation.reconcileOperation for Text.
|
|
13132
|
+
*/
|
|
13133
|
+
reconcileOperation(remoteFrom, remoteTo, contentLen) {
|
|
13134
|
+
if (!this.isUndoOp) {
|
|
13135
|
+
return;
|
|
13136
|
+
}
|
|
13137
|
+
if (this.fromIdx === void 0 || this.toIdx === void 0) {
|
|
13138
|
+
return;
|
|
13139
|
+
}
|
|
13140
|
+
if (remoteFrom > remoteTo) {
|
|
13141
|
+
return;
|
|
13142
|
+
}
|
|
13143
|
+
const remoteRangeLen = remoteTo - remoteFrom;
|
|
13144
|
+
const localFrom = this.fromIdx;
|
|
13145
|
+
const localTo = this.toIdx;
|
|
13146
|
+
const apply = (na, nb) => {
|
|
13147
|
+
this.fromIdx = Math.max(0, na);
|
|
13148
|
+
this.toIdx = Math.max(0, nb);
|
|
13149
|
+
};
|
|
13150
|
+
if (remoteTo <= localFrom) {
|
|
13151
|
+
apply(
|
|
13152
|
+
localFrom - remoteRangeLen + contentLen,
|
|
13153
|
+
localTo - remoteRangeLen + contentLen
|
|
13154
|
+
);
|
|
13155
|
+
return;
|
|
13156
|
+
}
|
|
13157
|
+
if (localTo <= remoteFrom) {
|
|
13158
|
+
return;
|
|
13159
|
+
}
|
|
13160
|
+
if (remoteFrom <= localFrom && localTo <= remoteTo && remoteFrom !== remoteTo) {
|
|
13161
|
+
apply(remoteFrom, remoteFrom);
|
|
13162
|
+
return;
|
|
13163
|
+
}
|
|
13164
|
+
if (localFrom <= remoteFrom && remoteTo <= localTo && localFrom !== localTo) {
|
|
13165
|
+
apply(localFrom, localTo - remoteRangeLen + contentLen);
|
|
13166
|
+
return;
|
|
13167
|
+
}
|
|
13168
|
+
if (remoteFrom < localFrom && localFrom < remoteTo && remoteTo < localTo) {
|
|
13169
|
+
apply(remoteFrom, remoteFrom + (localTo - remoteTo));
|
|
13170
|
+
return;
|
|
13171
|
+
}
|
|
13172
|
+
if (localFrom < remoteFrom && remoteFrom < localTo && localTo < remoteTo) {
|
|
13173
|
+
apply(localFrom, remoteFrom);
|
|
13174
|
+
return;
|
|
13175
|
+
}
|
|
13176
|
+
}
|
|
13177
|
+
/**
|
|
13178
|
+
* `getContentSize` returns the total visible size of this operation's
|
|
13179
|
+
* content (for reconciliation).
|
|
13180
|
+
*/
|
|
13181
|
+
getContentSize() {
|
|
13182
|
+
if (!this.contents) return 0;
|
|
13183
|
+
return this.contents.reduce((sum, node) => sum + node.paddedSize(), 0);
|
|
13184
|
+
}
|
|
13031
13185
|
/**
|
|
13032
13186
|
* `getEffectedCreatedAt` returns the creation time of the effected element.
|
|
13033
13187
|
*/
|
|
@@ -17955,6 +18109,24 @@
|
|
|
17955
18109
|
replace(this.undoStack);
|
|
17956
18110
|
replace(this.redoStack);
|
|
17957
18111
|
}
|
|
18112
|
+
/**
|
|
18113
|
+
* `reconcileTreeEdit` reconciles the tree edit operation.
|
|
18114
|
+
* Scan both undo/redo stacks and adjust tree edit operations
|
|
18115
|
+
* when a remote edit modifies the same tree.
|
|
18116
|
+
*/
|
|
18117
|
+
reconcileTreeEdit(parentCreatedAt, rangeFrom, rangeTo, contentSize) {
|
|
18118
|
+
const replace = (stack) => {
|
|
18119
|
+
for (const ops of stack) {
|
|
18120
|
+
for (const op of ops) {
|
|
18121
|
+
if (op instanceof TreeEditOperation && op.getParentCreatedAt().compare(parentCreatedAt) === 0) {
|
|
18122
|
+
op.reconcileOperation(rangeFrom, rangeTo, contentSize);
|
|
18123
|
+
}
|
|
18124
|
+
}
|
|
18125
|
+
}
|
|
18126
|
+
};
|
|
18127
|
+
replace(this.undoStack);
|
|
18128
|
+
replace(this.redoStack);
|
|
18129
|
+
}
|
|
17958
18130
|
}
|
|
17959
18131
|
function validateYorkieRuleset(data, ruleset) {
|
|
17960
18132
|
const errors = [];
|
|
@@ -18908,6 +19080,15 @@
|
|
|
18908
19080
|
op.getContent()?.length ?? 0
|
|
18909
19081
|
);
|
|
18910
19082
|
}
|
|
19083
|
+
if (op instanceof TreeEditOperation) {
|
|
19084
|
+
const [from, to] = op.normalizePos();
|
|
19085
|
+
this.internalHistory.reconcileTreeEdit(
|
|
19086
|
+
op.getParentCreatedAt(),
|
|
19087
|
+
from,
|
|
19088
|
+
to,
|
|
19089
|
+
op.getContentSize()
|
|
19090
|
+
);
|
|
19091
|
+
}
|
|
18911
19092
|
}
|
|
18912
19093
|
this.changeID = this.changeID.syncClocks(change.getID());
|
|
18913
19094
|
if (opInfos.length) {
|
|
@@ -19453,7 +19634,7 @@
|
|
|
19453
19634
|
};
|
|
19454
19635
|
}
|
|
19455
19636
|
const name$1 = "@yorkie-js/sdk";
|
|
19456
|
-
const version$1 = "0.
|
|
19637
|
+
const version$1 = "0.7.0";
|
|
19457
19638
|
const pkg$1 = {
|
|
19458
19639
|
name: name$1,
|
|
19459
19640
|
version: version$1
|
|
@@ -21308,7 +21489,7 @@
|
|
|
21308
21489
|
};
|
|
21309
21490
|
}
|
|
21310
21491
|
const name = "@yorkie-js/react";
|
|
21311
|
-
const version = "0.
|
|
21492
|
+
const version = "0.7.0";
|
|
21312
21493
|
const pkg = {
|
|
21313
21494
|
name,
|
|
21314
21495
|
version
|