@slate-yjs/core 0.1.0 → 0.2.1
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 +2 -2
- package/dist/applyToSlate/index.d.ts.map +1 -1
- package/dist/applyToSlate/index.js +3 -1
- package/dist/applyToSlate/index.js.map +1 -1
- package/dist/applyToSlate/textEvent.d.ts.map +1 -1
- package/dist/applyToSlate/textEvent.js +17 -15
- package/dist/applyToSlate/textEvent.js.map +1 -1
- package/dist/applyToYjs/node/splitNode.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +1 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +1 -1
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/plugins/withCursors.js +30 -29
- package/dist/plugins/withCursors.js.map +1 -1
- package/dist/plugins/withYHistory.d.ts +7 -2
- package/dist/plugins/withYHistory.d.ts.map +1 -1
- package/dist/plugins/withYHistory.js +20 -10
- package/dist/plugins/withYHistory.js.map +1 -1
- package/dist/plugins/withYjs.d.ts +9 -6
- package/dist/plugins/withYjs.d.ts.map +1 -1
- package/dist/plugins/withYjs.js +60 -38
- package/dist/plugins/withYjs.js.map +1 -1
- package/dist/utils/delta.d.ts +1 -0
- package/dist/utils/delta.d.ts.map +1 -1
- package/dist/utils/delta.js +26 -1
- package/dist/utils/delta.js.map +1 -1
- package/dist/utils/object.d.ts +7 -4
- package/dist/utils/object.d.ts.map +1 -1
- package/dist/utils/object.js +54 -15
- package/dist/utils/object.js.map +1 -1
- 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/slate.js.map +1 -1
- package/package.json +5 -5
- package/src/applyToSlate/index.ts +2 -2
- package/src/applyToSlate/textEvent.ts +21 -20
- package/src/plugins/withYHistory.ts +26 -5
- 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.tsbuildinfo +1 -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/test/testEditor.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { Editor, Location, Node, Path, Point, Transforms } from 'slate';
|
|
2
|
-
import * as Y from 'yjs';
|
|
3
|
-
import { YjsEditor } from '../src';
|
|
4
|
-
|
|
5
|
-
export interface TestEditor extends YjsEditor {
|
|
6
|
-
shouldCaptureYjsUpdates: boolean;
|
|
7
|
-
capturedYjsUpdates: Uint8Array[];
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export type TransformFunc = (e: Editor) => void;
|
|
11
|
-
|
|
12
|
-
export const TestEditor = {
|
|
13
|
-
/**
|
|
14
|
-
* Capture Yjs updates generated by this editor.
|
|
15
|
-
*/
|
|
16
|
-
captureYjsUpdate: (e: TestEditor, update: Uint8Array): void => {
|
|
17
|
-
if (!e.shouldCaptureYjsUpdates) return;
|
|
18
|
-
e.capturedYjsUpdates.push(update);
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Return captured Yjs updates.
|
|
23
|
-
*/
|
|
24
|
-
getCapturedYjsUpdates: (e: TestEditor): Uint8Array[] => {
|
|
25
|
-
const result = e.capturedYjsUpdates;
|
|
26
|
-
e.capturedYjsUpdates = [];
|
|
27
|
-
return result;
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Apply one Yjs update to Yjs.
|
|
32
|
-
*/
|
|
33
|
-
applyYjsUpdateToYjs: (e: TestEditor, update: Uint8Array): void => {
|
|
34
|
-
e.shouldCaptureYjsUpdates = false;
|
|
35
|
-
Y.applyUpdate(e.sharedRoot.doc, update);
|
|
36
|
-
e.shouldCaptureYjsUpdates = true;
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Apply multiple Yjs updates to Yjs.
|
|
41
|
-
*/
|
|
42
|
-
applyYjsUpdatesToYjs: (e: TestEditor, updates: Uint8Array[]): void => {
|
|
43
|
-
updates.forEach((update) => {
|
|
44
|
-
TestEditor.applyYjsUpdateToYjs(e, update);
|
|
45
|
-
});
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Apply one TransformFunc to slate.
|
|
50
|
-
*/
|
|
51
|
-
applyTransform: (e: TestEditor, transform: TransformFunc): void => {
|
|
52
|
-
transform(e);
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Apply multiple TransformFuncs to slate.
|
|
57
|
-
*/
|
|
58
|
-
applyTransforms: (e: TestEditor, transforms: TransformFunc[]): void => {
|
|
59
|
-
transforms.forEach((transform) => {
|
|
60
|
-
TestEditor.applyTransform(e, transform);
|
|
61
|
-
});
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
makeInsertText:
|
|
65
|
-
(text: string, at: Location): TransformFunc =>
|
|
66
|
-
(e: Editor) => {
|
|
67
|
-
Transforms.insertText(e, text, { at });
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
makeRemoveCharacters:
|
|
71
|
-
(count: number, at: Location): TransformFunc =>
|
|
72
|
-
(e: Editor) => {
|
|
73
|
-
Transforms.delete(e, { distance: count, at });
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
makeInsertNodes:
|
|
77
|
-
(nodes: Node | Node[], at: Location): TransformFunc =>
|
|
78
|
-
(e: Editor) => {
|
|
79
|
-
Transforms.insertNodes(e, nodes, { at });
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
makeMergeNodes:
|
|
83
|
-
(at: Path): TransformFunc =>
|
|
84
|
-
(e: Editor) => {
|
|
85
|
-
Transforms.mergeNodes(e, { at });
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
makeMoveNodes:
|
|
89
|
-
(from: Path, to: Path): TransformFunc =>
|
|
90
|
-
(e: Editor) => {
|
|
91
|
-
Transforms.moveNodes(e, { at: from, to });
|
|
92
|
-
},
|
|
93
|
-
|
|
94
|
-
makeRemoveNodes:
|
|
95
|
-
(at: Path): TransformFunc =>
|
|
96
|
-
(e: Editor) => {
|
|
97
|
-
Transforms.removeNodes(e, { at });
|
|
98
|
-
},
|
|
99
|
-
|
|
100
|
-
makeSetNodes:
|
|
101
|
-
(at: Location, props: Partial<Node>): TransformFunc =>
|
|
102
|
-
(e: Editor) => {
|
|
103
|
-
Transforms.setNodes(e, props, { at });
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
makeSplitNodes:
|
|
107
|
-
(at: Location): TransformFunc =>
|
|
108
|
-
(e: Editor) => {
|
|
109
|
-
Transforms.splitNodes(e, { at });
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
makeSetSelection:
|
|
113
|
-
(anchor: Point, focus: Point): TransformFunc =>
|
|
114
|
-
(e: Editor) => {
|
|
115
|
-
Transforms.setSelection(e, { anchor, focus });
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export function withTest<T extends YjsEditor>(editor: T): T & TestEditor {
|
|
120
|
-
const e = editor as T & TestEditor;
|
|
121
|
-
|
|
122
|
-
if (!e.sharedRoot.doc) {
|
|
123
|
-
throw new Error('Shared type should be bound to a document');
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
e.sharedRoot.doc.on('update', (updateMessage: Uint8Array) => {
|
|
127
|
-
TestEditor.captureYjsUpdate(e, updateMessage);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
e.shouldCaptureYjsUpdates = true;
|
|
131
|
-
e.capturedYjsUpdates = [];
|
|
132
|
-
|
|
133
|
-
return e;
|
|
134
|
-
}
|
package/test/utils.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { createEditor, Node, Text } from 'slate';
|
|
2
|
-
import * as Y from 'yjs';
|
|
3
|
-
import { TestEditor, withTest } from './testEditor';
|
|
4
|
-
import { withYjs, WithYjsOptions } from '../src';
|
|
5
|
-
import { slateNodesToInsertDelta } from '../src/utils/convert';
|
|
6
|
-
|
|
7
|
-
export function createText(text = ''): Text {
|
|
8
|
-
return {
|
|
9
|
-
text,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function createNode(
|
|
14
|
-
type = 'paragraph',
|
|
15
|
-
text = '',
|
|
16
|
-
data?: Partial<Node>
|
|
17
|
-
): Node {
|
|
18
|
-
return {
|
|
19
|
-
type,
|
|
20
|
-
children: [createText(text)],
|
|
21
|
-
...data,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function createValue(children?: Node[]): { children: Node[] } {
|
|
26
|
-
return {
|
|
27
|
-
children: children || [createNode()],
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function createDoc(children?: Node[]): Y.Doc {
|
|
32
|
-
const doc = new Y.Doc();
|
|
33
|
-
const insertDelta = slateNodesToInsertDelta(createValue(children).children);
|
|
34
|
-
|
|
35
|
-
const sharedRoot = doc.get('content', Y.XmlText) as Y.XmlText;
|
|
36
|
-
sharedRoot.applyDelta(insertDelta, { sanitize: false });
|
|
37
|
-
|
|
38
|
-
return doc;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function wait(ms = 0): Promise<void> {
|
|
42
|
-
return new Promise<void>((resolve) => setTimeout(resolve, ms));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function createTestEditor(
|
|
46
|
-
value?: Node[],
|
|
47
|
-
options?: WithYjsOptions
|
|
48
|
-
): Promise<TestEditor> {
|
|
49
|
-
const doc = new Y.Doc();
|
|
50
|
-
|
|
51
|
-
const sharedRoot = doc.get('content', Y.XmlText) as Y.XmlText;
|
|
52
|
-
|
|
53
|
-
if (value) {
|
|
54
|
-
const insertDelta = slateNodesToInsertDelta(value);
|
|
55
|
-
sharedRoot.applyDelta(insertDelta, { sanitize: false });
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const editor = withTest(withYjs(createEditor(), sharedRoot, options));
|
|
59
|
-
|
|
60
|
-
// wait for value sync
|
|
61
|
-
await wait();
|
|
62
|
-
|
|
63
|
-
return editor;
|
|
64
|
-
}
|