@slate-yjs/core 0.2.0 → 0.2.3
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/CHANGELOG.md +7 -0
- package/README.md +3 -0
- package/dist/applyToSlate/index.d.ts +19 -19
- package/dist/applyToSlate/index.d.ts.map +1 -1
- package/dist/applyToSlate/textEvent.d.ts +3 -3
- package/dist/applyToSlate/textEvent.d.ts.map +1 -1
- package/dist/applyToYjs/index.d.ts +3 -3
- package/dist/applyToYjs/node/index.d.ts +3 -3
- package/dist/applyToYjs/node/insertNode.d.ts +3 -3
- package/dist/applyToYjs/node/mergeNode.d.ts +3 -3
- package/dist/applyToYjs/node/moveNode.d.ts +3 -3
- package/dist/applyToYjs/node/removeNode.d.ts +3 -3
- package/dist/applyToYjs/node/setNode.d.ts +3 -3
- package/dist/applyToYjs/node/splitNode.d.ts +3 -3
- package/dist/applyToYjs/text/index.d.ts +3 -3
- package/dist/applyToYjs/text/insertText.d.ts +3 -3
- package/dist/applyToYjs/text/removeText.d.ts +3 -3
- package/dist/applyToYjs/types.d.ts +8 -8
- package/dist/index.cjs +1280 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.global.js +10418 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +1257 -10
- package/dist/index.js.map +1 -1
- package/dist/model/types.d.ts +37 -37
- package/dist/plugins/index.d.ts +3 -3
- package/dist/plugins/withCursors.d.ts +38 -38
- package/dist/plugins/withYHistory.d.ts +19 -19
- package/dist/plugins/withYHistory.d.ts.map +1 -1
- package/dist/plugins/withYjs.d.ts +42 -42
- package/dist/plugins/withYjs.d.ts.map +1 -1
- package/dist/utils/clone.d.ts +4 -4
- package/dist/utils/convert.d.ts +7 -7
- package/dist/utils/delta.d.ts +7 -6
- package/dist/utils/delta.d.ts.map +1 -1
- package/dist/utils/location.d.ts +11 -11
- package/dist/utils/object.d.ts +9 -6
- package/dist/utils/object.d.ts.map +1 -1
- package/dist/utils/position.d.ts +19 -19
- package/dist/utils/slate.d.ts +2 -2
- package/dist/utils/yjs.d.ts +4 -4
- package/package.json +13 -13
- package/src/applyToSlate/index.ts +2 -2
- package/src/applyToSlate/textEvent.ts +21 -20
- package/src/plugins/withYHistory.ts +84 -61
- package/src/plugins/withYjs.ts +14 -5
- package/src/utils/delta.ts +36 -1
- package/src/utils/object.ts +65 -20
- package/test/collaboration/addMark/acrossMarks.tsx +40 -0
- package/test/collaboration/addMark/acrossMarksSame.tsx +36 -0
- package/test/collaboration/addMark/atBeginningOfDocument.tsx +27 -0
- package/test/collaboration/addMark/atEndOfDocument.tsx +30 -0
- package/test/collaboration/addMark/withOtherMarks.tsx +31 -0
- package/test/collaboration/insertNode/atBeginningOfDocument.tsx +28 -0
- package/test/collaboration/insertNode/atEndOfDocument.tsx +28 -0
- package/test/collaboration/insertNode/inTheMiddle.tsx +30 -0
- package/test/collaboration/insertText/atBeginningOfBlock.tsx +26 -0
- package/test/collaboration/insertText/atBeginningOfDocument.tsx +26 -0
- package/test/collaboration/insertText/atEndOfBlock.tsx +26 -0
- package/test/collaboration/insertText/atEndOfDocument.tsx +26 -0
- package/test/collaboration/insertText/inTheMiddle.tsx +32 -0
- package/test/collaboration/insertText/inTheMiddleOfNestedBlock.tsx +30 -0
- package/test/collaboration/insertText/insideMarks.tsx +28 -0
- package/test/collaboration/insertText/withEmptyString.tsx +25 -0
- package/test/collaboration/insertText/withEntities.tsx +28 -0
- package/test/collaboration/insertText/withMarks.tsx +25 -0
- package/test/collaboration/insertText/withUnicode.tsx +28 -0
- package/test/collaboration/mergeNode/afterADeleteBackward.tsx +27 -0
- package/test/collaboration/mergeNode/onMixedNestedNodes.tsx +29 -0
- package/test/collaboration/mergeNode/onMixedTypeNodes.tsx +27 -0
- package/test/collaboration/mergeNode/withUnicode.tsx +25 -0
- package/test/collaboration/moveNode/downward/whenBlockBecomesNested.tsx +43 -0
- package/test/collaboration/moveNode/downward/whenBlockBecomesNonNested.tsx +41 -0
- package/test/collaboration/moveNode/downward/whenBlockStaysNested.tsx +38 -0
- package/test/collaboration/moveNode/downward/whenBlockStaysNonNested.tsx +30 -0
- package/test/collaboration/moveNode/upward/whenBlockBecomesNested.tsx +43 -0
- package/test/collaboration/moveNode/upward/whenBlockBecomesNonNested.tsx +41 -0
- package/test/collaboration/moveNode/upward/whenBlockStaysNested.tsx +38 -0
- package/test/collaboration/moveNode/upward/whenBlockStaysNonNested.tsx +30 -0
- package/test/collaboration/removeMark/inTheMiddleOfText.tsx +43 -0
- package/test/collaboration/removeMark/withAddMark.tsx +31 -0
- package/test/collaboration/removeMark/withOtherMarks.tsx +47 -0
- package/test/collaboration/removeNode/atBeginningOfDocument.tsx +26 -0
- package/test/collaboration/removeNode/atEndOfDocument.tsx +26 -0
- package/test/collaboration/removeNode/nestedBlock.tsx +28 -0
- package/test/collaboration/removeNode/wrapperBlock.tsx +28 -0
- package/test/collaboration/removeText/atBeginningOfDocument.tsx +34 -0
- package/test/collaboration/removeText/atEndOfDocument.tsx +37 -0
- package/test/collaboration/removeText/withUnicode.tsx +29 -0
- package/test/collaboration/setNode/atBeginningOfDocument.tsx +27 -0
- package/test/collaboration/setNode/atEndOfDocument.tsx +27 -0
- package/test/collaboration/setNode/onDataChange.tsx +35 -0
- package/test/collaboration/setNode/onDataChangeOnInline.tsx +35 -0
- package/test/collaboration/setNode/onResetBlock.tsx +27 -0
- package/test/collaboration/setNode/withAChangeOfType.tsx +26 -0
- package/test/collaboration/splitNode/atBeginningOfDocument.tsx +28 -0
- package/test/collaboration/splitNode/atEndOfBlock.tsx +27 -0
- package/test/collaboration/splitNode/atEndOfDocument.tsx +27 -0
- package/test/collaboration/splitNode/onNonDefaultBlock.tsx +27 -0
- package/test/collaboration/splitNode/withMultipleSubNodes.tsx +32 -0
- package/test/collaboration/splitNode/withUnicode.tsx +29 -0
- package/test/index.test.ts +65 -0
- package/test/{types.d.ts → slate.d.ts} +0 -0
- package/test/withTestingElements.ts +46 -0
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/tsup.config.ts +32 -0
- package/dist/applyToSlate/Untitled-1.d.ts +0 -101
- package/dist/applyToSlate/Untitled-1.d.ts.map +0 -1
- package/dist/applyToSlate/index.js +0 -32
- package/dist/applyToSlate/index.js.map +0 -1
- package/dist/applyToSlate/textEvent.js +0 -166
- package/dist/applyToSlate/textEvent.js.map +0 -1
- package/dist/applyToYjs/index.js +0 -17
- package/dist/applyToYjs/index.js.map +0 -1
- package/dist/applyToYjs/node/index.js +0 -15
- package/dist/applyToYjs/node/index.js.map +0 -1
- package/dist/applyToYjs/node/insertNode.js +0 -12
- package/dist/applyToYjs/node/insertNode.js.map +0 -1
- package/dist/applyToYjs/node/mergeNode.js +0 -32
- package/dist/applyToYjs/node/mergeNode.js.map +0 -1
- package/dist/applyToYjs/node/moveNode.js +0 -28
- package/dist/applyToYjs/node/moveNode.js.map +0 -1
- package/dist/applyToYjs/node/removeNode.js +0 -6
- package/dist/applyToYjs/node/removeNode.js.map +0 -1
- package/dist/applyToYjs/node/setNode.js +0 -21
- package/dist/applyToYjs/node/setNode.js.map +0 -1
- package/dist/applyToYjs/node/splitNode.js +0 -50
- package/dist/applyToYjs/node/splitNode.js.map +0 -1
- package/dist/applyToYjs/text/index.js +0 -7
- package/dist/applyToYjs/text/index.js.map +0 -1
- package/dist/applyToYjs/text/insertText.js +0 -12
- package/dist/applyToYjs/text/insertText.js.map +0 -1
- package/dist/applyToYjs/text/removeText.js +0 -6
- package/dist/applyToYjs/text/removeText.js.map +0 -1
- package/dist/applyToYjs/types.js +0 -2
- package/dist/applyToYjs/types.js.map +0 -1
- package/dist/index.modern.js +0 -2
- package/dist/index.modern.js.map +0 -1
- package/dist/index.module.js +0 -2
- package/dist/index.module.js.map +0 -1
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.map +0 -1
- package/dist/model/types.js +0 -2
- package/dist/model/types.js.map +0 -1
- package/dist/plugins/index.js +0 -4
- package/dist/plugins/index.js.map +0 -1
- package/dist/plugins/withCursors.js +0 -145
- package/dist/plugins/withCursors.js.map +0 -1
- package/dist/plugins/withYHistory.js +0 -66
- package/dist/plugins/withYHistory.js.map +0 -1
- package/dist/plugins/withYjs.js +0 -155
- package/dist/plugins/withYjs.js.map +0 -1
- package/dist/utils/clone.js +0 -23
- package/dist/utils/clone.js.map +0 -1
- package/dist/utils/convert.js +0 -35
- package/dist/utils/convert.js.map +0 -1
- package/dist/utils/delta.js +0 -42
- package/dist/utils/delta.js.map +0 -1
- package/dist/utils/location.js +0 -111
- package/dist/utils/location.js.map +0 -1
- package/dist/utils/object.js +0 -27
- package/dist/utils/object.js.map +0 -1
- package/dist/utils/position.js +0 -140
- package/dist/utils/position.js.map +0 -1
- package/dist/utils/slate.js +0 -6
- package/dist/utils/slate.js.map +0 -1
- package/dist/utils/yjs.js +0 -7
- package/dist/utils/yjs.js.map +0 -1
- package/test/collaboration.test.ts +0 -395
- package/test/concurrent.test.ts +0 -233
- package/test/testEditor.ts +0 -134
- package/test/utils.ts +0 -64
package/dist/utils/object.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export function isObject(v) {
|
|
2
|
-
return v !== null && typeof v === 'object';
|
|
3
|
-
}
|
|
4
|
-
export function deepEquals(obj, other) {
|
|
5
|
-
const keys1 = Object.keys(obj);
|
|
6
|
-
const keys2 = Object.keys(other);
|
|
7
|
-
if (keys1.length !== keys2.length) {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
return keys1.every((key) => {
|
|
11
|
-
const val1 = obj[key];
|
|
12
|
-
const val2 = other[key];
|
|
13
|
-
if (!isObject(val1)) {
|
|
14
|
-
return val1 === val2;
|
|
15
|
-
}
|
|
16
|
-
return isObject(val2) && deepEquals(val1, val2);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
20
|
-
export function pick(obj, ...keys) {
|
|
21
|
-
return Object.fromEntries(Object.entries(obj).filter(([key]) => keys.includes(key)));
|
|
22
|
-
}
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
24
|
-
export function omit(obj, ...keys) {
|
|
25
|
-
return Object.fromEntries(Object.entries(obj).filter(([key]) => !keys.includes(key)));
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=object.js.map
|
package/dist/utils/object.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/utils/object.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,QAAQ,CAAC,CAAU;IACjC,OAAO,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,UAAU,CACxB,GAAsB,EACtB,KAAwB;IAExB,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/B,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAEjC,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,EAAE;QACjC,OAAO,KAAK,CAAC;KACd;IAED,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACzB,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QACtB,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QAExB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YACnB,OAAO,IAAI,KAAK,IAAI,CAAC;SACtB;QAED,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,IAAI,CAClB,GAAS,EACT,GAAG,IAAa;IAEhB,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAY,CAAC,CAAC,CAC9C,CAAC;AACzB,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,IAAI,CAClB,GAAS,EACT,GAAG,IAAa;IAEhB,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAY,CAAC,CAAC,CAC/C,CAAC;AACzB,CAAC"}
|
package/dist/utils/position.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { Node, Text } from 'slate';
|
|
2
|
-
import * as Y from 'yjs';
|
|
3
|
-
import { getInsertDeltaLength, yTextToInsertDelta } from './delta';
|
|
4
|
-
import { getSlatePath, getYTarget, yOffsetToSlateOffsets } from './location';
|
|
5
|
-
import { assertDocumentAttachment } from './yjs';
|
|
6
|
-
export const STORED_POSITION_PREFIX = '__slateYjsStoredPosition_';
|
|
7
|
-
export function slatePointToRelativePosition(sharedRoot, slateRoot, point) {
|
|
8
|
-
const { yTarget, yParent, textRange } = getYTarget(sharedRoot, slateRoot, point.path);
|
|
9
|
-
if (yTarget) {
|
|
10
|
-
throw new Error('Slate point points to a non-text element inside sharedRoot');
|
|
11
|
-
}
|
|
12
|
-
return Y.createRelativePositionFromTypeIndex(yParent, textRange.start + point.offset, point.offset === textRange.end ? -1 : 0);
|
|
13
|
-
}
|
|
14
|
-
export function absolutePositionToSlatePoint(sharedRoot, slateRoot, { type, index, assoc }) {
|
|
15
|
-
if (!(type instanceof Y.XmlText)) {
|
|
16
|
-
throw new Error('Absolute position points to a non-XMLText');
|
|
17
|
-
}
|
|
18
|
-
const parentPath = getSlatePath(sharedRoot, slateRoot, type);
|
|
19
|
-
const parent = Node.get(slateRoot, parentPath);
|
|
20
|
-
if (Text.isText(parent)) {
|
|
21
|
-
throw new Error("Absolute position doesn't match slateRoot, cannot descent into text");
|
|
22
|
-
}
|
|
23
|
-
const [pathOffset, textOffset] = yOffsetToSlateOffsets(parent, index, {
|
|
24
|
-
assoc,
|
|
25
|
-
});
|
|
26
|
-
const target = parent.children[pathOffset];
|
|
27
|
-
if (!Text.isText(target)) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
return { path: [...parentPath, pathOffset], offset: textOffset };
|
|
31
|
-
}
|
|
32
|
-
export function relativePositionToSlatePoint(sharedRoot, slateRoot, pos) {
|
|
33
|
-
if (!sharedRoot.doc) {
|
|
34
|
-
throw new Error("sharedRoot isn't attach to a yDoc");
|
|
35
|
-
}
|
|
36
|
-
const absPos = Y.createAbsolutePositionFromRelativePosition(pos, sharedRoot.doc);
|
|
37
|
-
return absPos && absolutePositionToSlatePoint(sharedRoot, slateRoot, absPos);
|
|
38
|
-
}
|
|
39
|
-
export function getStoredPosition(sharedRoot, key) {
|
|
40
|
-
const rawPosition = sharedRoot.getAttribute(STORED_POSITION_PREFIX + key);
|
|
41
|
-
if (!rawPosition) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
return Y.decodeRelativePosition(rawPosition);
|
|
45
|
-
}
|
|
46
|
-
export function getStoredPositions(sharedRoot) {
|
|
47
|
-
return Object.fromEntries(Object.entries(sharedRoot.getAttributes())
|
|
48
|
-
.filter(([key]) => key.startsWith(STORED_POSITION_PREFIX))
|
|
49
|
-
.map(([key, position]) => [
|
|
50
|
-
key.slice(STORED_POSITION_PREFIX.length),
|
|
51
|
-
Y.createRelativePositionFromJSON(position),
|
|
52
|
-
]));
|
|
53
|
-
}
|
|
54
|
-
function getStoredPositionsAbsolute(sharedRoot) {
|
|
55
|
-
assertDocumentAttachment(sharedRoot);
|
|
56
|
-
return Object.fromEntries(Object.entries(sharedRoot.getAttributes())
|
|
57
|
-
.filter(([key]) => key.startsWith(STORED_POSITION_PREFIX))
|
|
58
|
-
.map(([key, position]) => [
|
|
59
|
-
key.slice(STORED_POSITION_PREFIX.length),
|
|
60
|
-
Y.createAbsolutePositionFromRelativePosition(Y.createRelativePositionFromJSON(position), sharedRoot.doc),
|
|
61
|
-
])
|
|
62
|
-
.filter(([, position]) => position));
|
|
63
|
-
}
|
|
64
|
-
export function removeStoredPosition(sharedRoot, key) {
|
|
65
|
-
sharedRoot.removeAttribute(STORED_POSITION_PREFIX + key);
|
|
66
|
-
}
|
|
67
|
-
export function setStoredPosition(sharedRoot, key, position) {
|
|
68
|
-
sharedRoot.setAttribute(STORED_POSITION_PREFIX + key, Y.encodeRelativePosition(position));
|
|
69
|
-
}
|
|
70
|
-
function getAbsolutePositionsInTextRange(absolutePositions, yTarget, textRange) {
|
|
71
|
-
return Object.fromEntries(Object.entries(absolutePositions).filter(([, position]) => {
|
|
72
|
-
if (position.type !== yTarget) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
if (!textRange) {
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
return position.assoc >= 0
|
|
79
|
-
? position.index >= textRange.start && position.index < textRange.end
|
|
80
|
-
: position.index > textRange.start && position.index >= textRange.end;
|
|
81
|
-
}));
|
|
82
|
-
}
|
|
83
|
-
function getAbsolutePositionsInYText(absolutePositions, yText, parentPath = '') {
|
|
84
|
-
const positions = {
|
|
85
|
-
[parentPath]: getAbsolutePositionsInTextRange(absolutePositions, yText),
|
|
86
|
-
};
|
|
87
|
-
const insertDelta = yTextToInsertDelta(yText);
|
|
88
|
-
insertDelta.forEach(({ insert }, i) => {
|
|
89
|
-
if (insert instanceof Y.XmlText) {
|
|
90
|
-
Object.assign(positions, getAbsolutePositionsInYText(absolutePositions, insert, parentPath ? `${parentPath}.${i}` : i.toString()));
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
return positions;
|
|
94
|
-
}
|
|
95
|
-
export function getStoredPositionsInDeltaAbsolute(sharedRoot, yText, delta, deltaOffset = 0) {
|
|
96
|
-
const absolutePositions = getStoredPositionsAbsolute(sharedRoot);
|
|
97
|
-
const positions = {
|
|
98
|
-
'': getAbsolutePositionsInTextRange(absolutePositions, yText, {
|
|
99
|
-
start: deltaOffset,
|
|
100
|
-
end: deltaOffset + getInsertDeltaLength(delta),
|
|
101
|
-
}),
|
|
102
|
-
};
|
|
103
|
-
delta.forEach(({ insert }, i) => {
|
|
104
|
-
if (insert instanceof Y.XmlText) {
|
|
105
|
-
Object.assign(positions, getAbsolutePositionsInYText(absolutePositions, insert, i.toString()));
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
return positions;
|
|
109
|
-
}
|
|
110
|
-
export function restoreStoredPositionsWithDeltaAbsolute(sharedRoot, yText, absolutePositions, delta, newDeltaOffset = 0, previousDeltaOffset = 0, path = '') {
|
|
111
|
-
const toRestore = absolutePositions[path];
|
|
112
|
-
if (toRestore) {
|
|
113
|
-
Object.entries(toRestore).forEach(([key, position]) => {
|
|
114
|
-
setStoredPosition(sharedRoot, key, Y.createRelativePositionFromTypeIndex(yText, position.index - previousDeltaOffset + newDeltaOffset, position.assoc));
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
delta.forEach(({ insert }, i) => {
|
|
118
|
-
if (insert instanceof Y.XmlText) {
|
|
119
|
-
restoreStoredPositionsWithDeltaAbsolute(sharedRoot, insert, absolutePositions, yTextToInsertDelta(insert), 0, 0, path ? `${path}.${i}` : i.toString());
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
export function slateRangeToRelativeRange(sharedRoot, slateRoot, range) {
|
|
124
|
-
return {
|
|
125
|
-
anchor: slatePointToRelativePosition(sharedRoot, slateRoot, range.anchor),
|
|
126
|
-
focus: slatePointToRelativePosition(sharedRoot, slateRoot, range.focus),
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
export function relativeRangeToSlateRange(sharedRoot, slateRoot, range) {
|
|
130
|
-
const anchor = relativePositionToSlatePoint(sharedRoot, slateRoot, range.anchor);
|
|
131
|
-
if (!anchor) {
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
const focus = relativePositionToSlatePoint(sharedRoot, slateRoot, range.focus);
|
|
135
|
-
if (!focus) {
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
return { anchor, focus };
|
|
139
|
-
}
|
|
140
|
-
//# sourceMappingURL=position.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"position.js","sourceRoot":"","sources":["../../src/utils/position.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,IAAI,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO,EAAE,wBAAwB,EAAE,MAAM,OAAO,CAAC;AAEjD,MAAM,CAAC,MAAM,sBAAsB,GAAG,2BAA2B,CAAC;AAElE,MAAM,UAAU,4BAA4B,CAC1C,UAAqB,EACrB,SAAe,EACf,KAAgB;IAEhB,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,UAAU,CAChD,UAAU,EACV,SAAS,EACT,KAAK,CAAC,IAAI,CACX,CAAC;IAEF,IAAI,OAAO,EAAE;QACX,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;KACH;IAED,OAAO,CAAC,CAAC,mCAAmC,CAC1C,OAAO,EACP,SAAS,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,EAC9B,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACxC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,4BAA4B,CAC1C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BAA4B,CACxC,UAAU,EACV,SAAS,EACT,KAAK,CAAC,KAAK,CACZ,CAAC;IAEF,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,IAAI,CAAC;KACb;IAED,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AAC3B,CAAC"}
|
package/dist/utils/slate.js
DELETED
package/dist/utils/slate.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"slate.js","sourceRoot":"","sources":["../../src/utils/slate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,IAAI,EAAE,MAAM,OAAO,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,MAAM,UAAU,aAAa,CAC3B,IAAW;IAEX,OAAO,IAAI,CACT,IAAI,EACJ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAgB,CACW,CAAC;AACxE,CAAC"}
|
package/dist/utils/yjs.js
DELETED
package/dist/utils/yjs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"yjs.js","sourceRoot":"","sources":["../../src/utils/yjs.ts"],"names":[],"mappings":"AAEA,8DAA8D;AAC9D,MAAM,UAAU,wBAAwB,CACtC,UAAa;IAEb,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;KAC7D;AACH,CAAC"}
|
|
@@ -1,395 +0,0 @@
|
|
|
1
|
-
import { Node } from 'slate';
|
|
2
|
-
import { yTextToSlateElement } from '../src/utils/convert';
|
|
3
|
-
import { TestEditor, TransformFunc } from './testEditor';
|
|
4
|
-
import { createNode, createTestEditor, createValue, wait } from './utils';
|
|
5
|
-
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
7
|
-
jest.mock('y-protocols/awareness', () => {});
|
|
8
|
-
|
|
9
|
-
const tests = [
|
|
10
|
-
[
|
|
11
|
-
'Insert text into a paragraph node',
|
|
12
|
-
[createNode('paragraph', '')],
|
|
13
|
-
[
|
|
14
|
-
TestEditor.makeInsertText('Hello ', { path: [0, 0], offset: 0 }),
|
|
15
|
-
TestEditor.makeInsertText('collaborator', { path: [0, 0], offset: 6 }),
|
|
16
|
-
TestEditor.makeInsertText('!', { path: [0, 0], offset: 18 }),
|
|
17
|
-
],
|
|
18
|
-
[createNode('paragraph', 'Hello collaborator!')],
|
|
19
|
-
],
|
|
20
|
-
[
|
|
21
|
-
'Delete characters from a paragraph node',
|
|
22
|
-
[createNode('paragraph', 'Hello collaborator!')],
|
|
23
|
-
[
|
|
24
|
-
TestEditor.makeRemoveCharacters(7, { path: [0, 0], offset: 11 }),
|
|
25
|
-
TestEditor.makeRemoveCharacters(6, { path: [0, 0], offset: 5 }),
|
|
26
|
-
],
|
|
27
|
-
[createNode('paragraph', 'Hello!')],
|
|
28
|
-
],
|
|
29
|
-
[
|
|
30
|
-
'Insert new nodes (both paragraph and text)',
|
|
31
|
-
[createNode()],
|
|
32
|
-
[
|
|
33
|
-
TestEditor.makeInsertNodes({ type: 'paragraph', children: [] }, [1]),
|
|
34
|
-
TestEditor.makeInsertNodes({ text: 'Hello collaborator!' }, [1, 0]),
|
|
35
|
-
],
|
|
36
|
-
[createNode(), createNode('paragraph', 'Hello collaborator!')],
|
|
37
|
-
],
|
|
38
|
-
[
|
|
39
|
-
'Insert new nodes (two paragraphs)',
|
|
40
|
-
[
|
|
41
|
-
createNode('paragraph', 'alfa'),
|
|
42
|
-
createNode('paragraph', 'bravo'),
|
|
43
|
-
createNode('paragraph', 'charlie'),
|
|
44
|
-
createNode('paragraph', 'delta'),
|
|
45
|
-
],
|
|
46
|
-
[
|
|
47
|
-
TestEditor.makeInsertNodes(createNode('paragraph', 'echo'), [1]),
|
|
48
|
-
TestEditor.makeInsertNodes(createNode('paragraph', 'foxtrot'), [4]),
|
|
49
|
-
],
|
|
50
|
-
[
|
|
51
|
-
createNode('paragraph', 'alfa'),
|
|
52
|
-
createNode('paragraph', 'echo'),
|
|
53
|
-
createNode('paragraph', 'bravo'),
|
|
54
|
-
createNode('paragraph', 'charlie'),
|
|
55
|
-
createNode('paragraph', 'foxtrot'),
|
|
56
|
-
createNode('paragraph', 'delta'),
|
|
57
|
-
],
|
|
58
|
-
],
|
|
59
|
-
[
|
|
60
|
-
'Insert new nodes (three paragraphs)',
|
|
61
|
-
[
|
|
62
|
-
createNode('paragraph', 'one'),
|
|
63
|
-
createNode('paragraph', 'two'),
|
|
64
|
-
createNode('paragraph', 'three'),
|
|
65
|
-
createNode('paragraph', 'four'),
|
|
66
|
-
],
|
|
67
|
-
[
|
|
68
|
-
TestEditor.makeInsertNodes(createNode('paragraph', 'five'), [1]),
|
|
69
|
-
TestEditor.makeInsertNodes(createNode('paragraph', 'six'), [3]),
|
|
70
|
-
TestEditor.makeInsertNodes(createNode('paragraph', 'seven'), [5]),
|
|
71
|
-
],
|
|
72
|
-
[
|
|
73
|
-
createNode('paragraph', 'one'),
|
|
74
|
-
createNode('paragraph', 'five'),
|
|
75
|
-
createNode('paragraph', 'two'),
|
|
76
|
-
createNode('paragraph', 'six'),
|
|
77
|
-
createNode('paragraph', 'three'),
|
|
78
|
-
createNode('paragraph', 'seven'),
|
|
79
|
-
createNode('paragraph', 'four'),
|
|
80
|
-
],
|
|
81
|
-
],
|
|
82
|
-
[
|
|
83
|
-
'Merge two paragraph nodes',
|
|
84
|
-
[
|
|
85
|
-
createNode('paragraph', 'Hello '),
|
|
86
|
-
createNode('paragraph', 'collaborator!'),
|
|
87
|
-
],
|
|
88
|
-
[TestEditor.makeMergeNodes([1])],
|
|
89
|
-
[createNode('paragraph', 'Hello collaborator!')],
|
|
90
|
-
],
|
|
91
|
-
[
|
|
92
|
-
'Move a paragraph node to an existing position',
|
|
93
|
-
[
|
|
94
|
-
createNode('paragraph', 'first'),
|
|
95
|
-
createNode('paragraph', 'second'),
|
|
96
|
-
createNode('paragraph', 'third'),
|
|
97
|
-
],
|
|
98
|
-
[TestEditor.makeMoveNodes([1], [0])],
|
|
99
|
-
[
|
|
100
|
-
createNode('paragraph', 'second'),
|
|
101
|
-
createNode('paragraph', 'first'),
|
|
102
|
-
createNode('paragraph', 'third'),
|
|
103
|
-
],
|
|
104
|
-
],
|
|
105
|
-
[
|
|
106
|
-
'Move a paragraph node to the end',
|
|
107
|
-
[
|
|
108
|
-
createNode('paragraph', 'first'),
|
|
109
|
-
createNode('paragraph', 'second'),
|
|
110
|
-
createNode('paragraph', 'third'),
|
|
111
|
-
],
|
|
112
|
-
[TestEditor.makeMoveNodes([0], [3])],
|
|
113
|
-
[
|
|
114
|
-
createNode('paragraph', 'second'),
|
|
115
|
-
createNode('paragraph', 'third'),
|
|
116
|
-
createNode('paragraph', 'first'),
|
|
117
|
-
],
|
|
118
|
-
],
|
|
119
|
-
[
|
|
120
|
-
'Move a paragraph node far past the end',
|
|
121
|
-
[
|
|
122
|
-
createNode('paragraph', 'first'),
|
|
123
|
-
createNode('paragraph', 'second'),
|
|
124
|
-
createNode('paragraph', 'third'),
|
|
125
|
-
],
|
|
126
|
-
[TestEditor.makeMoveNodes([0], [1000])],
|
|
127
|
-
[
|
|
128
|
-
createNode('paragraph', 'second'),
|
|
129
|
-
createNode('paragraph', 'third'),
|
|
130
|
-
createNode('paragraph', 'first'),
|
|
131
|
-
],
|
|
132
|
-
],
|
|
133
|
-
[
|
|
134
|
-
'Move a text node',
|
|
135
|
-
[
|
|
136
|
-
createNode('paragraph', 'first'),
|
|
137
|
-
createNode('paragraph', 'second'),
|
|
138
|
-
createNode('paragraph', 'third'),
|
|
139
|
-
],
|
|
140
|
-
[TestEditor.makeMoveNodes([1, 0], [2, 0])],
|
|
141
|
-
[
|
|
142
|
-
createNode('paragraph', 'first'),
|
|
143
|
-
createNode('paragraph', ''),
|
|
144
|
-
createNode('paragraph', 'secondthird'),
|
|
145
|
-
],
|
|
146
|
-
],
|
|
147
|
-
[
|
|
148
|
-
'Remove a paragraph node',
|
|
149
|
-
[
|
|
150
|
-
createNode('paragraph', 'first'),
|
|
151
|
-
createNode('paragraph', 'second'),
|
|
152
|
-
createNode('paragraph', 'third'),
|
|
153
|
-
],
|
|
154
|
-
[TestEditor.makeRemoveNodes([0])],
|
|
155
|
-
[createNode('paragraph', 'second'), createNode('paragraph', 'third')],
|
|
156
|
-
],
|
|
157
|
-
|
|
158
|
-
[
|
|
159
|
-
'Remove two non-consecutive paragraph nodes',
|
|
160
|
-
[
|
|
161
|
-
createNode('paragraph', 'first'),
|
|
162
|
-
createNode('paragraph', 'second'),
|
|
163
|
-
createNode('paragraph', 'third'),
|
|
164
|
-
createNode('paragraph', 'fourth'),
|
|
165
|
-
],
|
|
166
|
-
[TestEditor.makeRemoveNodes([0]), TestEditor.makeRemoveNodes([1])],
|
|
167
|
-
[createNode('paragraph', 'second'), createNode('paragraph', 'fourth')],
|
|
168
|
-
],
|
|
169
|
-
[
|
|
170
|
-
'Remove two consecutive paragraph nodes',
|
|
171
|
-
[
|
|
172
|
-
createNode('paragraph', 'first'),
|
|
173
|
-
createNode('paragraph', 'second'),
|
|
174
|
-
createNode('paragraph', 'third'),
|
|
175
|
-
createNode('paragraph', 'fourth'),
|
|
176
|
-
],
|
|
177
|
-
[TestEditor.makeRemoveNodes([1]), TestEditor.makeRemoveNodes([1])],
|
|
178
|
-
[createNode('paragraph', 'first'), createNode('paragraph', 'fourth')],
|
|
179
|
-
],
|
|
180
|
-
[
|
|
181
|
-
'Remove a text node',
|
|
182
|
-
[
|
|
183
|
-
createNode('paragraph', 'first'),
|
|
184
|
-
createNode('paragraph', 'second'),
|
|
185
|
-
createNode('paragraph', 'third'),
|
|
186
|
-
],
|
|
187
|
-
[TestEditor.makeRemoveNodes([1, 0])],
|
|
188
|
-
[
|
|
189
|
-
createNode('paragraph', 'first'),
|
|
190
|
-
createNode('paragraph', ''),
|
|
191
|
-
createNode('paragraph', 'third'),
|
|
192
|
-
],
|
|
193
|
-
],
|
|
194
|
-
[
|
|
195
|
-
'Set properties of a paragraph node',
|
|
196
|
-
[
|
|
197
|
-
createNode('paragraph', 'first', { test: '1234' }),
|
|
198
|
-
createNode('paragraph', 'second'),
|
|
199
|
-
],
|
|
200
|
-
[TestEditor.makeSetNodes([0], { test: '4567' })],
|
|
201
|
-
[
|
|
202
|
-
createNode('paragraph', 'first', { test: '4567' }),
|
|
203
|
-
createNode('paragraph', 'second'),
|
|
204
|
-
],
|
|
205
|
-
],
|
|
206
|
-
[
|
|
207
|
-
'Set properties of a text node',
|
|
208
|
-
[
|
|
209
|
-
createNode('paragraph', 'first', { test: '1234' }),
|
|
210
|
-
createNode('paragraph', 'second'),
|
|
211
|
-
],
|
|
212
|
-
[TestEditor.makeSetNodes([1, 0], { data: '4567' })],
|
|
213
|
-
[
|
|
214
|
-
createNode('paragraph', 'first', { test: '1234' }),
|
|
215
|
-
{
|
|
216
|
-
type: 'paragraph',
|
|
217
|
-
children: [
|
|
218
|
-
{
|
|
219
|
-
data: '4567',
|
|
220
|
-
text: 'second',
|
|
221
|
-
},
|
|
222
|
-
],
|
|
223
|
-
},
|
|
224
|
-
],
|
|
225
|
-
],
|
|
226
|
-
[
|
|
227
|
-
'Split an existing paragraph',
|
|
228
|
-
[createNode('paragraph', 'Hello collaborator!')],
|
|
229
|
-
[TestEditor.makeSplitNodes({ path: [0, 0], offset: 6 })],
|
|
230
|
-
[
|
|
231
|
-
createNode('paragraph', 'Hello '),
|
|
232
|
-
createNode('paragraph', 'collaborator!'),
|
|
233
|
-
],
|
|
234
|
-
],
|
|
235
|
-
[
|
|
236
|
-
'Insert and remove text in the same paragraph',
|
|
237
|
-
[createNode('paragraph', 'abc def')],
|
|
238
|
-
[
|
|
239
|
-
TestEditor.makeInsertText('ghi ', { path: [0, 0], offset: 4 }),
|
|
240
|
-
TestEditor.makeRemoveCharacters(2, { path: [0, 0], offset: 1 }),
|
|
241
|
-
TestEditor.makeInsertText('jkl ', { path: [0, 0], offset: 6 }),
|
|
242
|
-
TestEditor.makeRemoveCharacters(1, { path: [0, 0], offset: 11 }),
|
|
243
|
-
TestEditor.makeInsertText(' mno', { path: [0, 0], offset: 12 }),
|
|
244
|
-
],
|
|
245
|
-
[createNode('paragraph', 'a ghi jkl df mno')],
|
|
246
|
-
],
|
|
247
|
-
[
|
|
248
|
-
'Remove first paragraph, insert text into second paragraph',
|
|
249
|
-
[createNode('paragraph', 'abcd'), createNode('paragraph', 'efgh')],
|
|
250
|
-
[
|
|
251
|
-
TestEditor.makeRemoveNodes([0]),
|
|
252
|
-
TestEditor.makeInsertText(' ijkl ', { path: [0, 0], offset: 2 }),
|
|
253
|
-
],
|
|
254
|
-
[createNode('paragraph', 'ef ijkl gh')],
|
|
255
|
-
],
|
|
256
|
-
[
|
|
257
|
-
'More complex case: insert text, both insert and remove nodes',
|
|
258
|
-
[
|
|
259
|
-
createNode('paragraph', 'abcd'),
|
|
260
|
-
createNode('paragraph', 'efgh'),
|
|
261
|
-
createNode('paragraph', 'ijkl'),
|
|
262
|
-
],
|
|
263
|
-
[
|
|
264
|
-
TestEditor.makeInsertText(' mnop ', { path: [0, 0], offset: 2 }),
|
|
265
|
-
TestEditor.makeRemoveNodes([1]),
|
|
266
|
-
TestEditor.makeInsertText(' qrst ', { path: [1, 0], offset: 2 }),
|
|
267
|
-
TestEditor.makeInsertNodes(createNode('paragraph', 'uvxw'), [1]),
|
|
268
|
-
],
|
|
269
|
-
[
|
|
270
|
-
createNode('paragraph', 'ab mnop cd'),
|
|
271
|
-
createNode('paragraph', 'uvxw'),
|
|
272
|
-
createNode('paragraph', 'ij qrst kl'),
|
|
273
|
-
],
|
|
274
|
-
],
|
|
275
|
-
[
|
|
276
|
-
'Insert text, then insert node that affects the path to the affected text',
|
|
277
|
-
[createNode('paragraph', 'abcd')],
|
|
278
|
-
[
|
|
279
|
-
TestEditor.makeInsertText(' efgh ', { path: [0, 0], offset: 2 }),
|
|
280
|
-
TestEditor.makeInsertNodes(createNode('paragraph', 'ijkl'), [0]),
|
|
281
|
-
],
|
|
282
|
-
[createNode('paragraph', 'ijkl'), createNode('paragraph', 'ab efgh cd')],
|
|
283
|
-
],
|
|
284
|
-
[
|
|
285
|
-
'Set properties, then insert node that affects path to the affected node',
|
|
286
|
-
[createNode('paragraph', 'abcd')],
|
|
287
|
-
[
|
|
288
|
-
TestEditor.makeSetNodes([0], { test: '1234' }),
|
|
289
|
-
TestEditor.makeInsertNodes(createNode('paragraph', 'ijkl'), [0]),
|
|
290
|
-
],
|
|
291
|
-
[
|
|
292
|
-
createNode('paragraph', 'ijkl'),
|
|
293
|
-
createNode('paragraph', 'abcd', { test: '1234' }),
|
|
294
|
-
],
|
|
295
|
-
],
|
|
296
|
-
[
|
|
297
|
-
'Insert node, then insert second node that affects path to the first node',
|
|
298
|
-
[
|
|
299
|
-
createValue([
|
|
300
|
-
createNode('paragraph', 'abc'),
|
|
301
|
-
createNode('paragraph', 'def'),
|
|
302
|
-
]),
|
|
303
|
-
],
|
|
304
|
-
[
|
|
305
|
-
TestEditor.makeInsertNodes(createNode('paragraph', 'jkl'), [0, 1]),
|
|
306
|
-
TestEditor.makeInsertNodes(createNode('paragraph', 'ghi'), [0]),
|
|
307
|
-
],
|
|
308
|
-
[
|
|
309
|
-
createNode('paragraph', 'ghi'),
|
|
310
|
-
createValue([
|
|
311
|
-
createNode('paragraph', 'abc'),
|
|
312
|
-
createNode('paragraph', 'jkl'),
|
|
313
|
-
createNode('paragraph', 'def'),
|
|
314
|
-
]),
|
|
315
|
-
],
|
|
316
|
-
],
|
|
317
|
-
[
|
|
318
|
-
'remove_text op spans location of previous remove_text op',
|
|
319
|
-
[createNode('paragraph', 'abc defg ijklm')],
|
|
320
|
-
[TestEditor.makeRemoveCharacters(5, { path: [0, 0], offset: 4 })],
|
|
321
|
-
[createNode('paragraph', 'abc ijklm')],
|
|
322
|
-
[TestEditor.makeRemoveCharacters(6, { path: [0, 0], offset: 1 })],
|
|
323
|
-
[createNode('paragraph', 'alm')],
|
|
324
|
-
],
|
|
325
|
-
[
|
|
326
|
-
'remove_text op spans locations of two previous remove_text ops',
|
|
327
|
-
[createNode('paragraph', 'abcdefghijklmnopqrst')],
|
|
328
|
-
[TestEditor.makeRemoveCharacters(3, { path: [0, 0], offset: 2 })],
|
|
329
|
-
[createNode('paragraph', 'abfghijklmnopqrst')],
|
|
330
|
-
[TestEditor.makeRemoveCharacters(8, { path: [0, 0], offset: 5 })],
|
|
331
|
-
[createNode('paragraph', 'abfghqrst')],
|
|
332
|
-
[TestEditor.makeRemoveCharacters(7, { path: [0, 0], offset: 1 })],
|
|
333
|
-
[createNode('paragraph', 'at')],
|
|
334
|
-
],
|
|
335
|
-
[
|
|
336
|
-
'set_selection op is a null op',
|
|
337
|
-
[createNode('paragraph', 'abcdefghijklmnopqrst')],
|
|
338
|
-
[
|
|
339
|
-
TestEditor.makeSetSelection(
|
|
340
|
-
{ path: [0, 0], offset: 2 },
|
|
341
|
-
{ path: [0, 0], offset: 4 }
|
|
342
|
-
),
|
|
343
|
-
],
|
|
344
|
-
[createNode('paragraph', 'abcdefghijklmnopqrst')],
|
|
345
|
-
],
|
|
346
|
-
];
|
|
347
|
-
|
|
348
|
-
describe('slate operations propagate between editors', () => {
|
|
349
|
-
tests.forEach(([testName, input, ...cases]) => {
|
|
350
|
-
it(`${testName}`, async () => {
|
|
351
|
-
// Create two editors.
|
|
352
|
-
const src = await createTestEditor();
|
|
353
|
-
const dst = await createTestEditor();
|
|
354
|
-
|
|
355
|
-
// Set initial state for src editor, propagate changes to dst editor.
|
|
356
|
-
TestEditor.applyTransform(
|
|
357
|
-
src,
|
|
358
|
-
TestEditor.makeInsertNodes(input as Node[], [0])
|
|
359
|
-
);
|
|
360
|
-
await wait();
|
|
361
|
-
|
|
362
|
-
let updates = TestEditor.getCapturedYjsUpdates(src);
|
|
363
|
-
TestEditor.applyYjsUpdatesToYjs(dst, updates);
|
|
364
|
-
await wait();
|
|
365
|
-
|
|
366
|
-
// Verify initial states.
|
|
367
|
-
expect(src.children).toEqual(input);
|
|
368
|
-
expect(yTextToSlateElement(src.sharedRoot).children).toEqual(input);
|
|
369
|
-
expect(yTextToSlateElement(dst.sharedRoot).children).toEqual(input);
|
|
370
|
-
expect(dst.children).toEqual(input);
|
|
371
|
-
|
|
372
|
-
// Allow for multiple rounds of applying transforms and verifying state.
|
|
373
|
-
const toTest = cases.slice();
|
|
374
|
-
while (toTest.length > 0) {
|
|
375
|
-
const [transforms, output] = toTest.splice(0, 2);
|
|
376
|
-
|
|
377
|
-
// Apply transforms to src editor, propagate changes to dst editor.
|
|
378
|
-
TestEditor.applyTransforms(src, transforms as TransformFunc[]);
|
|
379
|
-
// eslint-disable-next-line no-await-in-loop
|
|
380
|
-
await wait();
|
|
381
|
-
|
|
382
|
-
updates = TestEditor.getCapturedYjsUpdates(src);
|
|
383
|
-
TestEditor.applyYjsUpdatesToYjs(dst, updates);
|
|
384
|
-
// eslint-disable-next-line no-await-in-loop
|
|
385
|
-
await wait();
|
|
386
|
-
|
|
387
|
-
// Verify final states.
|
|
388
|
-
expect(src.children).toEqual(output);
|
|
389
|
-
expect(yTextToSlateElement(src.sharedRoot).children).toEqual(output);
|
|
390
|
-
expect(yTextToSlateElement(dst.sharedRoot).children).toEqual(output);
|
|
391
|
-
expect(dst.children).toEqual(output);
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
});
|
|
395
|
-
});
|