Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/core/src/utils/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ export function yTextToSlateElement(yText: Y.XmlText): Element {
const children =
// eslint-disable-next-line @typescript-eslint/no-use-before-define
delta.length > 0 ? delta.map(deltaInsertToSlateNode) : [{ text: '' }];
const attributes = yText.getAttributes();

return { ...yText.getAttributes(), children };
return { ...attributes, children };
}

export function deltaInsertToSlateNode(insert: DeltaInsert): Node {
Expand Down
10 changes: 9 additions & 1 deletion packages/core/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type FixtureModule = {
module: {
input: Editor;
expected: Editor;
run: (e: Editor) => void;
run: (e: Editor) => any;
};
};

Expand Down Expand Up @@ -60,6 +60,14 @@ async function runCollaborationTest({ module }: FixtureModule) {
expect(editor.children).toEqual(expectedEditor.children);
}

async function runUnitTest({ module }: FixtureModule) {
const { input, run, expected } = module;
const editor = await withTestingElements(input);
const runOutput = run(editor);
expect(runOutput).toEqual(expected);
}

describe('adapter', () => {
fixtures(__dirname, 'unit', runUnitTest);
fixtures(__dirname, 'collaboration', runCollaborationTest);
});
27 changes: 27 additions & 0 deletions packages/core/test/unit/yTextToSlate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/** @jsx jsx */
import { Editor } from 'slate';
import { jsx } from '../../../../support/jsx';
import { YjsEditor, yTextToSlateElement } from '../../src';

export const input = (
<editor>
<unstyled>
<text bold />
</unstyled>
</editor>
);

export const expected = {
children: [
<unstyled>
<text bold />
</unstyled>,
],
};

export function run(editor: Editor) {
const isYJSEditor = YjsEditor.isYjsEditor(editor);
if (!isYJSEditor) return;

return yTextToSlateElement(editor.sharedRoot);
}