@slate-yjs/core 1.0.3 → 1.0.5

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 (84) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/applyToYjs/node/mergeNode.d.ts.map +1 -1
  3. package/dist/applyToYjs/node/moveNode.d.ts.map +1 -1
  4. package/dist/applyToYjs/node/splitNode.d.ts.map +1 -1
  5. package/dist/index.cjs +60 -36
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.global.js +3851 -5380
  8. package/dist/index.global.js.map +1 -1
  9. package/dist/index.js +60 -36
  10. package/dist/index.js.map +1 -1
  11. package/dist/plugins/withCursors.d.ts.map +1 -1
  12. package/dist/plugins/withYjs.d.ts.map +1 -1
  13. package/dist/utils/clone.d.ts.map +1 -1
  14. package/dist/utils/convert.d.ts.map +1 -1
  15. package/dist/utils/yjs.d.ts +3 -0
  16. package/dist/utils/yjs.d.ts.map +1 -1
  17. package/package.json +10 -5
  18. package/src/applyToYjs/node/mergeNode.ts +2 -3
  19. package/src/applyToYjs/node/moveNode.ts +41 -14
  20. package/src/applyToYjs/node/splitNode.ts +2 -3
  21. package/src/plugins/withCursors.ts +38 -11
  22. package/src/plugins/withYjs.ts +17 -0
  23. package/src/utils/clone.ts +5 -3
  24. package/src/utils/convert.ts +2 -1
  25. package/src/utils/yjs.ts +6 -0
  26. package/test/collaboration/addMark/acrossMarks.tsx +0 -40
  27. package/test/collaboration/addMark/acrossMarksSame.tsx +0 -36
  28. package/test/collaboration/addMark/atBeginningOfDocument.tsx +0 -27
  29. package/test/collaboration/addMark/atEndOfDocument.tsx +0 -30
  30. package/test/collaboration/addMark/withOtherMarks.tsx +0 -31
  31. package/test/collaboration/insertNode/atBeginningOfDocument.tsx +0 -28
  32. package/test/collaboration/insertNode/atEndOfDocument.tsx +0 -28
  33. package/test/collaboration/insertNode/inTheMiddle.tsx +0 -30
  34. package/test/collaboration/insertText/atBeginningOfBlock.tsx +0 -26
  35. package/test/collaboration/insertText/atBeginningOfDocument.tsx +0 -26
  36. package/test/collaboration/insertText/atEndOfBlock.tsx +0 -26
  37. package/test/collaboration/insertText/atEndOfDocument.tsx +0 -26
  38. package/test/collaboration/insertText/inTheMiddle.tsx +0 -32
  39. package/test/collaboration/insertText/inTheMiddleOfNestedBlock.tsx +0 -30
  40. package/test/collaboration/insertText/insideMarks.tsx +0 -28
  41. package/test/collaboration/insertText/withEmptyString.tsx +0 -25
  42. package/test/collaboration/insertText/withEntities.tsx +0 -28
  43. package/test/collaboration/insertText/withMarks.tsx +0 -25
  44. package/test/collaboration/insertText/withUnicode.tsx +0 -28
  45. package/test/collaboration/mergeNode/afterADeleteBackward.tsx +0 -27
  46. package/test/collaboration/mergeNode/inSameParent.tsx +0 -34
  47. package/test/collaboration/mergeNode/onMixedNestedNodes.tsx +0 -29
  48. package/test/collaboration/mergeNode/onMixedTypeNodes.tsx +0 -27
  49. package/test/collaboration/mergeNode/withUnicode.tsx +0 -25
  50. package/test/collaboration/moveNode/downward/whenBlockBecomesNested.tsx +0 -43
  51. package/test/collaboration/moveNode/downward/whenBlockBecomesNonNested.tsx +0 -41
  52. package/test/collaboration/moveNode/downward/whenBlockStaysNested.tsx +0 -38
  53. package/test/collaboration/moveNode/downward/whenBlockStaysNonNested.tsx +0 -30
  54. package/test/collaboration/moveNode/upward/whenBlockBecomesNested.tsx +0 -43
  55. package/test/collaboration/moveNode/upward/whenBlockBecomesNonNested.tsx +0 -41
  56. package/test/collaboration/moveNode/upward/whenBlockStaysNested.tsx +0 -38
  57. package/test/collaboration/moveNode/upward/whenBlockStaysNonNested.tsx +0 -30
  58. package/test/collaboration/removeMark/inTheMiddleOfText.tsx +0 -43
  59. package/test/collaboration/removeMark/withAddMark.tsx +0 -31
  60. package/test/collaboration/removeMark/withOtherMarks.tsx +0 -47
  61. package/test/collaboration/removeNode/atBeginningOfDocument.tsx +0 -26
  62. package/test/collaboration/removeNode/atEndOfDocument.tsx +0 -26
  63. package/test/collaboration/removeNode/nestedBlock.tsx +0 -28
  64. package/test/collaboration/removeNode/wrapperBlock.tsx +0 -28
  65. package/test/collaboration/removeText/atBeginningOfDocument.tsx +0 -34
  66. package/test/collaboration/removeText/atEndOfDocument.tsx +0 -37
  67. package/test/collaboration/removeText/withUnicode.tsx +0 -29
  68. package/test/collaboration/setNode/atBeginningOfDocument.tsx +0 -27
  69. package/test/collaboration/setNode/atEndOfDocument.tsx +0 -27
  70. package/test/collaboration/setNode/onDataChange.tsx +0 -35
  71. package/test/collaboration/setNode/onDataChangeOnInline.tsx +0 -35
  72. package/test/collaboration/setNode/onResetBlock.tsx +0 -27
  73. package/test/collaboration/setNode/withAChangeOfType.tsx +0 -26
  74. package/test/collaboration/splitNode/atBeginningOfDocument.tsx +0 -28
  75. package/test/collaboration/splitNode/atEndOfBlock.tsx +0 -27
  76. package/test/collaboration/splitNode/atEndOfDocument.tsx +0 -27
  77. package/test/collaboration/splitNode/onNonDefaultBlock.tsx +0 -27
  78. package/test/collaboration/splitNode/withMultipleSubNodes.tsx +0 -32
  79. package/test/collaboration/splitNode/withUnicode.tsx +0 -29
  80. package/test/index.test.ts +0 -65
  81. package/test/slate.d.ts +0 -8
  82. package/test/withTestingElements.ts +0 -46
  83. package/tsconfig.json +0 -11
  84. package/tsup.config.ts +0 -32
@@ -1,65 +0,0 @@
1
- /* eslint-disable import/no-extraneous-dependencies */
2
- import { createEditor, Editor } from 'slate';
3
- import { describe, expect } from 'vitest';
4
- import * as Y from 'yjs';
5
- import { fixtures } from '../../../support/fixtures';
6
- import { yTextToSlateElement } from '../src';
7
- import { withTestingElements } from './withTestingElements';
8
-
9
- export type FixtureModule = {
10
- module: {
11
- input: Editor;
12
- expected: Editor;
13
- run: (e: Editor) => void;
14
- };
15
- };
16
-
17
- async function normalizedSlateDoc(sharedRoot: Y.XmlText) {
18
- const editor = createEditor();
19
- editor.children = yTextToSlateElement(sharedRoot).children;
20
- const e = await withTestingElements(editor);
21
- Editor.normalize(e, { force: true });
22
- return e.children;
23
- }
24
-
25
- async function runCollaborationTest({ module }: FixtureModule) {
26
- // Setup 'local' editor
27
- const { input, run, expected } = module;
28
- const editor = await withTestingElements(input);
29
-
30
- // Keep the 'local' editor state before applying run.
31
- const baseState = Y.encodeStateAsUpdateV2(editor.sharedRoot.doc);
32
-
33
- Editor.normalize(editor, { force: true });
34
-
35
- // The normalized editor state should match the shared root.
36
- expect(await normalizedSlateDoc(editor.sharedRoot)).toEqual(editor.children);
37
-
38
- run(editor);
39
- editor.onChange();
40
-
41
- // Editor state after run should match shared root.
42
- expect(await normalizedSlateDoc(editor.sharedRoot)).toEqual(editor.children);
43
-
44
- // Setup remote editor with input base state
45
- const remoteDoc = new Y.Doc();
46
- Y.applyUpdateV2(remoteDoc, baseState);
47
- const remote = await withTestingElements(createEditor(), remoteDoc);
48
-
49
- // Apply changes from 'run'
50
- Y.applyUpdateV2(remoteDoc, Y.encodeStateAsUpdateV2(editor.sharedRoot.doc));
51
-
52
- // Verify remote and editor state are equal
53
- expect(await normalizedSlateDoc(remote.sharedRoot)).toEqual(remote.children);
54
- expect(editor.children).toEqual(remote.children);
55
- expect(await normalizedSlateDoc(editor.sharedRoot)).toEqual(editor.children);
56
-
57
- // Verify editor is in expected state
58
- const expectedEditor = await withTestingElements(expected);
59
- Editor.normalize(expectedEditor, { force: true });
60
- expect(editor.children).toEqual(expectedEditor.children);
61
- }
62
-
63
- describe('adapter', () => {
64
- fixtures(__dirname, 'collaboration', runCollaborationTest);
65
- });
package/test/slate.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import { BaseElement, BaseText } from 'slate';
2
-
3
- declare module 'slate' {
4
- interface CustomTypes {
5
- Element: BaseElement & Record<string, unknown>;
6
- Text: BaseText & Record<string, unknown>;
7
- }
8
- }
@@ -1,46 +0,0 @@
1
- import { Editor, Element, Transforms } from 'slate';
2
- import * as Y from 'yjs';
3
- import { wait } from '../../../support/utils';
4
- import { slateNodesToInsertDelta, withYjs } from '../src';
5
-
6
- const INLINE_ELEMENTS = ['note-link', 'link'];
7
-
8
- export async function withTestingElements(
9
- editor: Editor,
10
- doc: Y.Doc = new Y.Doc()
11
- ) {
12
- const { normalizeNode, isInline } = editor;
13
-
14
- // normalizations needed for nested tests
15
- editor.normalizeNode = (entry) => {
16
- const [node, path] = entry;
17
-
18
- // remove empty list
19
- if (
20
- Element.isElement(node) &&
21
- !Editor.isEditor(node) &&
22
- node.type === 'unordered-list'
23
- ) {
24
- if (!node.children.length) {
25
- return Transforms.removeNodes(editor, { at: path });
26
- }
27
- }
28
-
29
- normalizeNode(entry);
30
- };
31
-
32
- editor.isInline = (element) =>
33
- INLINE_ELEMENTS.includes(element.type as string) || isInline(element);
34
-
35
- const sharedType = doc.get('sharedRoot', Y.XmlText) as Y.XmlText;
36
- if (sharedType.toDelta().length === 0) {
37
- sharedType.applyDelta(slateNodesToInsertDelta(editor.children));
38
- }
39
-
40
- const e = withYjs(editor, sharedType, { autoConnect: true });
41
-
42
- // Wait for editor to be initialized
43
- await wait();
44
-
45
- return e;
46
- }
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "../../config/typescript/tsconfig.json",
3
- "include": ["src/**/*"],
4
- "compilerOptions": {
5
- "rootDir": "./src",
6
- "outDir": "./dist",
7
- "declarationDir": "./dist",
8
- "composite": true
9
- },
10
- "references": []
11
- }
package/tsup.config.ts DELETED
@@ -1,32 +0,0 @@
1
- /* eslint-disable import/no-default-export */
2
- /* eslint-disable import/no-extraneous-dependencies */
3
- import { defineConfig, Options } from 'tsup';
4
-
5
- export default defineConfig(
6
- ({ watch }) => <Options[]>[
7
- {
8
- entry: ['src/index.ts'],
9
- outDir: 'dist',
10
- format: ['cjs', 'iife', 'esm'],
11
- globalName: 'SlateYjsCore',
12
- platform: 'browser',
13
- splitting: false,
14
- bundle: true,
15
- sourcemap: true,
16
- minify: false,
17
- clean: !watch,
18
- },
19
- !!watch && {
20
- entry: ['src'],
21
- outDir: 'dist',
22
- format: [],
23
- platform: 'browser',
24
- splitting: false,
25
- bundle: false,
26
- sourcemap: true,
27
- dts: true,
28
- minify: false,
29
- clean: false,
30
- },
31
- ].filter(Boolean)
32
- );