@slate-yjs/core 0.1.1 → 0.2.2
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/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 -14
- package/dist/plugins/withYHistory.d.ts.map +1 -1
- package/dist/plugins/withYjs.d.ts +42 -39
- 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/position.d.ts.map +1 -1
- package/dist/utils/slate.d.ts +2 -2
- package/dist/utils/slate.d.ts.map +1 -1
- package/dist/utils/yjs.d.ts +4 -4
- package/package.json +12 -12
- package/src/applyToSlate/index.ts +2 -2
- package/src/applyToSlate/textEvent.ts +21 -20
- package/src/plugins/withYHistory.ts +109 -65
- package/src/plugins/withYjs.ts +68 -33
- package/src/utils/delta.ts +36 -1
- package/src/utils/object.ts +65 -20
- package/src/utils/position.ts +1 -1
- package/src/utils/slate.ts +3 -3
- 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 +66 -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
|
@@ -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
|
-
});
|
package/test/concurrent.test.ts
DELETED
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import { Node } from 'slate';
|
|
2
|
-
import { yTextToSlateElement } from '../src/utils/convert';
|
|
3
|
-
import { TestEditor, TransformFunc } from './testEditor';
|
|
4
|
-
import { createNode, createTestEditor, wait } from './utils';
|
|
5
|
-
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
7
|
-
jest.mock('y-protocols/awareness', () => {});
|
|
8
|
-
|
|
9
|
-
const initialState: Node[] = [
|
|
10
|
-
createNode('paragraph', 'alfa bravo'),
|
|
11
|
-
createNode('paragraph', 'charlie delta'),
|
|
12
|
-
createNode('paragraph', 'echo foxtrot'),
|
|
13
|
-
createNode('paragraph', 'golf hotel'),
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
interface Test {
|
|
17
|
-
name: string;
|
|
18
|
-
transform: TransformFunc;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const tests: Test[] = [
|
|
22
|
-
{
|
|
23
|
-
name: 'Insert text into 1st paragraph',
|
|
24
|
-
transform: TestEditor.makeInsertText('india ', { path: [0, 0], offset: 5 }),
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
name: 'Insert text into 2nd paragraph',
|
|
28
|
-
transform: TestEditor.makeInsertText('juliett ', {
|
|
29
|
-
path: [1, 0],
|
|
30
|
-
offset: 8,
|
|
31
|
-
}),
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
name: 'Insert text into 3rd paragraph',
|
|
35
|
-
transform: TestEditor.makeInsertText('kilo ', { path: [2, 0], offset: 5 }),
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
name: 'Insert text into 4th paragraph',
|
|
39
|
-
transform: TestEditor.makeInsertText('lima ', { path: [3, 0], offset: 5 }),
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
name: 'Delete text from 1st paragraph',
|
|
43
|
-
transform: TestEditor.makeRemoveCharacters(5, { path: [0, 0], offset: 2 }),
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
name: 'Delete text from 2nd paragraph',
|
|
47
|
-
transform: TestEditor.makeRemoveCharacters(6, { path: [1, 0], offset: 4 }),
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
name: 'Delete text from 3nd paragraph',
|
|
51
|
-
transform: TestEditor.makeRemoveCharacters(5, { path: [2, 0], offset: 3 }),
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
name: 'Delete text from 4th paragraph',
|
|
55
|
-
transform: TestEditor.makeRemoveCharacters(7, { path: [3, 0], offset: 1 }),
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
name: 'Insert new paragraph before 1st',
|
|
59
|
-
transform: TestEditor.makeInsertNodes(createNode('paragraph', 'mike'), [0]),
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
name: 'Insert new paragraph between 1st and 2nd',
|
|
63
|
-
transform: TestEditor.makeInsertNodes(createNode('paragraph', 'november'), [
|
|
64
|
-
1,
|
|
65
|
-
]),
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
name: 'Insert new paragraph between 2nd and 3rd',
|
|
69
|
-
transform: TestEditor.makeInsertNodes(createNode('paragraph', 'oscar'), [
|
|
70
|
-
2,
|
|
71
|
-
]),
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
name: 'Insert new paragraph between 3rd and 4th',
|
|
75
|
-
transform: TestEditor.makeInsertNodes(createNode('paragraph', 'papa'), [3]),
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
name: 'Insert new paragraph after 4th',
|
|
79
|
-
transform: TestEditor.makeInsertNodes(createNode('paragraph', 'quebec'), [
|
|
80
|
-
4,
|
|
81
|
-
]),
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
name: 'Insert new text node into 1st paragraph',
|
|
85
|
-
transform: TestEditor.makeInsertNodes({ text: 'romeo' }, [0, 0]),
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
name: 'Insert new text node into 2nd paragraph',
|
|
89
|
-
transform: TestEditor.makeInsertNodes({ text: 'sierra' }, [1, 0]),
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
name: 'Insert new text node into 3rd paragraph',
|
|
93
|
-
transform: TestEditor.makeInsertNodes({ text: 'tango' }, [2, 0]),
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
name: 'Insert new text node into 4th paragraph',
|
|
97
|
-
transform: TestEditor.makeInsertNodes({ text: 'uniform' }, [3, 0]),
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
name: 'Merge 1st and 2nd paragraphs',
|
|
101
|
-
transform: TestEditor.makeMergeNodes([1]),
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
name: 'Merge 2nd and 3rd paragraphs',
|
|
105
|
-
transform: TestEditor.makeMergeNodes([2]),
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
name: 'Merge 3nd and 4th paragraphs',
|
|
109
|
-
transform: TestEditor.makeMergeNodes([3]),
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
name: 'Remove 1st paragraph',
|
|
113
|
-
transform: TestEditor.makeRemoveNodes([0]),
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
name: 'Remove 2nd paragraph',
|
|
117
|
-
transform: TestEditor.makeRemoveNodes([1]),
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
name: 'Remove 3rd paragraph',
|
|
121
|
-
transform: TestEditor.makeRemoveNodes([2]),
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
name: 'Remove 4th paragraph',
|
|
125
|
-
transform: TestEditor.makeRemoveNodes([3]),
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
name: 'Remove text node from 1st paragraph',
|
|
129
|
-
transform: TestEditor.makeRemoveNodes([0, 0]),
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
name: 'Remove text node from 2nd paragraph',
|
|
133
|
-
transform: TestEditor.makeRemoveNodes([1, 0]),
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
name: 'Remove text node from 3nd paragraph',
|
|
137
|
-
transform: TestEditor.makeRemoveNodes([2, 0]),
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
name: 'Remove text node from 4th paragraph',
|
|
141
|
-
transform: TestEditor.makeRemoveNodes([3, 0]),
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
name: 'Split 1st paragraph',
|
|
145
|
-
transform: TestEditor.makeSplitNodes({ path: [0, 0], offset: 4 }),
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
name: 'Split 2nd paragraph',
|
|
149
|
-
transform: TestEditor.makeSplitNodes({ path: [1, 0], offset: 5 }),
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
name: 'Split 3rd paragraph',
|
|
153
|
-
transform: TestEditor.makeSplitNodes({ path: [2, 0], offset: 6 }),
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
name: 'Split 4th paragraph',
|
|
157
|
-
transform: TestEditor.makeSplitNodes({ path: [3, 0], offset: 7 }),
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
name: 'Move 1st paragraph',
|
|
161
|
-
transform: TestEditor.makeMoveNodes([0], [3]),
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
name: 'Move 2nd paragraph',
|
|
165
|
-
transform: TestEditor.makeMoveNodes([3], [2]),
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
name: 'Move 3rd paragraph',
|
|
169
|
-
transform: TestEditor.makeMoveNodes([2], [1]),
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
name: 'Move 4th paragraph',
|
|
173
|
-
transform: TestEditor.makeMoveNodes([1], [0]),
|
|
174
|
-
},
|
|
175
|
-
];
|
|
176
|
-
|
|
177
|
-
const runOneTest = async (ti: Test, tj: Test) => {
|
|
178
|
-
// Create two editors.
|
|
179
|
-
const ei = await createTestEditor();
|
|
180
|
-
const ej = await createTestEditor();
|
|
181
|
-
|
|
182
|
-
// Set initial state for 1st editor, propagate changes to 2nd.
|
|
183
|
-
TestEditor.applyTransform(
|
|
184
|
-
ei,
|
|
185
|
-
TestEditor.makeInsertNodes(initialState as Node[], [0])
|
|
186
|
-
);
|
|
187
|
-
await wait();
|
|
188
|
-
|
|
189
|
-
const updates = TestEditor.getCapturedYjsUpdates(ei);
|
|
190
|
-
TestEditor.applyYjsUpdatesToYjs(ej, updates);
|
|
191
|
-
await wait();
|
|
192
|
-
|
|
193
|
-
// Verify initial states match.
|
|
194
|
-
expect(ei.children).toEqual(ej.children);
|
|
195
|
-
expect(yTextToSlateElement(ei.sharedRoot)).toEqual(
|
|
196
|
-
yTextToSlateElement(ej.sharedRoot)
|
|
197
|
-
);
|
|
198
|
-
|
|
199
|
-
// Apply 1st transform to 1st editor, capture updates.
|
|
200
|
-
TestEditor.applyTransform(ei, ti.transform);
|
|
201
|
-
await wait();
|
|
202
|
-
|
|
203
|
-
const updatesFromI = TestEditor.getCapturedYjsUpdates(ei);
|
|
204
|
-
|
|
205
|
-
// Apply 2nd transform to 2nd editor, capture updates.
|
|
206
|
-
TestEditor.applyTransform(ej, tj.transform);
|
|
207
|
-
await wait();
|
|
208
|
-
|
|
209
|
-
const updatesFromJ = TestEditor.getCapturedYjsUpdates(ej);
|
|
210
|
-
|
|
211
|
-
// Cross-propagate updates between editors.
|
|
212
|
-
TestEditor.applyYjsUpdatesToYjs(ei, updatesFromJ);
|
|
213
|
-
TestEditor.applyYjsUpdatesToYjs(ej, updatesFromI);
|
|
214
|
-
await wait();
|
|
215
|
-
|
|
216
|
-
// Verify final states match.
|
|
217
|
-
expect(ei.children).toEqual(ej.children);
|
|
218
|
-
expect(yTextToSlateElement(ei.sharedRoot)).toEqual(
|
|
219
|
-
yTextToSlateElement(ej.sharedRoot)
|
|
220
|
-
);
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
describe('model concurrent edits in separate editors', () => {
|
|
224
|
-
tests.forEach((test) => {
|
|
225
|
-
describe(`Test:${test.name}`, () => {
|
|
226
|
-
tests.forEach((concurrentTest) => {
|
|
227
|
-
it(`Concurrent:${concurrentTest.name}`, async () => {
|
|
228
|
-
await runOneTest(test, concurrentTest);
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
});
|