@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.
Files changed (111) hide show
  1. package/README.md +3 -0
  2. package/dist/applyToSlate/index.d.ts +2 -2
  3. package/dist/applyToSlate/index.d.ts.map +1 -1
  4. package/dist/applyToSlate/index.js +3 -1
  5. package/dist/applyToSlate/index.js.map +1 -1
  6. package/dist/applyToSlate/textEvent.d.ts.map +1 -1
  7. package/dist/applyToSlate/textEvent.js +17 -15
  8. package/dist/applyToSlate/textEvent.js.map +1 -1
  9. package/dist/applyToYjs/node/splitNode.js.map +1 -1
  10. package/dist/index.cjs +1 -1
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.js +1 -3
  13. package/dist/index.js.map +1 -1
  14. package/dist/index.modern.js +1 -1
  15. package/dist/index.modern.js.map +1 -1
  16. package/dist/index.module.js +1 -1
  17. package/dist/index.module.js.map +1 -1
  18. package/dist/index.umd.js +1 -1
  19. package/dist/index.umd.js.map +1 -1
  20. package/dist/plugins/withCursors.js +30 -29
  21. package/dist/plugins/withCursors.js.map +1 -1
  22. package/dist/plugins/withYHistory.d.ts +7 -2
  23. package/dist/plugins/withYHistory.d.ts.map +1 -1
  24. package/dist/plugins/withYHistory.js +20 -10
  25. package/dist/plugins/withYHistory.js.map +1 -1
  26. package/dist/plugins/withYjs.d.ts +9 -6
  27. package/dist/plugins/withYjs.d.ts.map +1 -1
  28. package/dist/plugins/withYjs.js +60 -38
  29. package/dist/plugins/withYjs.js.map +1 -1
  30. package/dist/utils/delta.d.ts +1 -0
  31. package/dist/utils/delta.d.ts.map +1 -1
  32. package/dist/utils/delta.js +26 -1
  33. package/dist/utils/delta.js.map +1 -1
  34. package/dist/utils/object.d.ts +7 -4
  35. package/dist/utils/object.d.ts.map +1 -1
  36. package/dist/utils/object.js +54 -15
  37. package/dist/utils/object.js.map +1 -1
  38. package/dist/utils/position.d.ts.map +1 -1
  39. package/dist/utils/slate.d.ts +2 -2
  40. package/dist/utils/slate.d.ts.map +1 -1
  41. package/dist/utils/slate.js.map +1 -1
  42. package/package.json +5 -5
  43. package/src/applyToSlate/index.ts +2 -2
  44. package/src/applyToSlate/textEvent.ts +21 -20
  45. package/src/plugins/withYHistory.ts +26 -5
  46. package/src/plugins/withYjs.ts +68 -33
  47. package/src/utils/delta.ts +36 -1
  48. package/src/utils/object.ts +65 -20
  49. package/src/utils/position.ts +1 -1
  50. package/src/utils/slate.ts +3 -3
  51. package/test/collaboration/addMark/acrossMarks.tsx +40 -0
  52. package/test/collaboration/addMark/acrossMarksSame.tsx +36 -0
  53. package/test/collaboration/addMark/atBeginningOfDocument.tsx +27 -0
  54. package/test/collaboration/addMark/atEndOfDocument.tsx +30 -0
  55. package/test/collaboration/addMark/withOtherMarks.tsx +31 -0
  56. package/test/collaboration/insertNode/atBeginningOfDocument.tsx +28 -0
  57. package/test/collaboration/insertNode/atEndOfDocument.tsx +28 -0
  58. package/test/collaboration/insertNode/inTheMiddle.tsx +30 -0
  59. package/test/collaboration/insertText/atBeginningOfBlock.tsx +26 -0
  60. package/test/collaboration/insertText/atBeginningOfDocument.tsx +26 -0
  61. package/test/collaboration/insertText/atEndOfBlock.tsx +26 -0
  62. package/test/collaboration/insertText/atEndOfDocument.tsx +26 -0
  63. package/test/collaboration/insertText/inTheMiddle.tsx +32 -0
  64. package/test/collaboration/insertText/inTheMiddleOfNestedBlock.tsx +30 -0
  65. package/test/collaboration/insertText/insideMarks.tsx +28 -0
  66. package/test/collaboration/insertText/withEmptyString.tsx +25 -0
  67. package/test/collaboration/insertText/withEntities.tsx +28 -0
  68. package/test/collaboration/insertText/withMarks.tsx +25 -0
  69. package/test/collaboration/insertText/withUnicode.tsx +28 -0
  70. package/test/collaboration/mergeNode/afterADeleteBackward.tsx +27 -0
  71. package/test/collaboration/mergeNode/onMixedNestedNodes.tsx +29 -0
  72. package/test/collaboration/mergeNode/onMixedTypeNodes.tsx +27 -0
  73. package/test/collaboration/mergeNode/withUnicode.tsx +25 -0
  74. package/test/collaboration/moveNode/downward/whenBlockBecomesNested.tsx +43 -0
  75. package/test/collaboration/moveNode/downward/whenBlockBecomesNonNested.tsx +41 -0
  76. package/test/collaboration/moveNode/downward/whenBlockStaysNested.tsx +38 -0
  77. package/test/collaboration/moveNode/downward/whenBlockStaysNonNested.tsx +30 -0
  78. package/test/collaboration/moveNode/upward/whenBlockBecomesNested.tsx +43 -0
  79. package/test/collaboration/moveNode/upward/whenBlockBecomesNonNested.tsx +41 -0
  80. package/test/collaboration/moveNode/upward/whenBlockStaysNested.tsx +38 -0
  81. package/test/collaboration/moveNode/upward/whenBlockStaysNonNested.tsx +30 -0
  82. package/test/collaboration/removeMark/inTheMiddleOfText.tsx +43 -0
  83. package/test/collaboration/removeMark/withAddMark.tsx +31 -0
  84. package/test/collaboration/removeMark/withOtherMarks.tsx +47 -0
  85. package/test/collaboration/removeNode/atBeginningOfDocument.tsx +26 -0
  86. package/test/collaboration/removeNode/atEndOfDocument.tsx +26 -0
  87. package/test/collaboration/removeNode/nestedBlock.tsx +28 -0
  88. package/test/collaboration/removeNode/wrapperBlock.tsx +28 -0
  89. package/test/collaboration/removeText/atBeginningOfDocument.tsx +34 -0
  90. package/test/collaboration/removeText/atEndOfDocument.tsx +37 -0
  91. package/test/collaboration/removeText/withUnicode.tsx +29 -0
  92. package/test/collaboration/setNode/atBeginningOfDocument.tsx +27 -0
  93. package/test/collaboration/setNode/atEndOfDocument.tsx +27 -0
  94. package/test/collaboration/setNode/onDataChange.tsx +35 -0
  95. package/test/collaboration/setNode/onDataChangeOnInline.tsx +35 -0
  96. package/test/collaboration/setNode/onResetBlock.tsx +27 -0
  97. package/test/collaboration/setNode/withAChangeOfType.tsx +26 -0
  98. package/test/collaboration/splitNode/atBeginningOfDocument.tsx +28 -0
  99. package/test/collaboration/splitNode/atEndOfBlock.tsx +27 -0
  100. package/test/collaboration/splitNode/atEndOfDocument.tsx +27 -0
  101. package/test/collaboration/splitNode/onNonDefaultBlock.tsx +27 -0
  102. package/test/collaboration/splitNode/withMultipleSubNodes.tsx +32 -0
  103. package/test/collaboration/splitNode/withUnicode.tsx +29 -0
  104. package/test/index.test.ts +66 -0
  105. package/test/{types.d.ts → slate.d.ts} +0 -0
  106. package/test/withTestingElements.ts +46 -0
  107. package/tsconfig.tsbuildinfo +1 -1
  108. package/test/collaboration.test.ts +0 -395
  109. package/test/concurrent.test.ts +0 -233
  110. package/test/testEditor.ts +0 -134
  111. package/test/utils.ts +0 -64
@@ -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
- }