File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,8 +10,9 @@ export function yTextToSlateElement(yText: Y.XmlText): Element {
1010 const children =
1111 // eslint-disable-next-line @typescript-eslint/no-use-before-define
1212 delta . length > 0 ? delta . map ( deltaInsertToSlateNode ) : [ { text : '' } ] ;
13+ const attributes = yText . getAttributes ( ) ;
1314
14- return { ...yText . getAttributes ( ) , children } ;
15+ return { ...attributes , children } ;
1516}
1617
1718export function deltaInsertToSlateNode ( insert : DeltaInsert ) : Node {
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ export type FixtureModule = {
1010 module : {
1111 input : Editor ;
1212 expected : Editor ;
13- run : ( e : Editor ) => void ;
13+ run : ( e : Editor ) => any ;
1414 } ;
1515} ;
1616
@@ -60,6 +60,14 @@ async function runCollaborationTest({ module }: FixtureModule) {
6060 expect ( editor . children ) . toEqual ( expectedEditor . children ) ;
6161}
6262
63+ async function runUnitTest ( { module } : FixtureModule ) {
64+ const { input, run, expected } = module ;
65+ const editor = await withTestingElements ( input ) ;
66+ const runOutput = run ( editor ) ;
67+ expect ( runOutput ) . toEqual ( expected ) ;
68+ }
69+
6370describe ( 'adapter' , ( ) => {
71+ fixtures ( __dirname , 'unit' , runUnitTest ) ;
6472 fixtures ( __dirname , 'collaboration' , runCollaborationTest ) ;
6573} ) ;
Original file line number Diff line number Diff line change 1+ /** @jsx jsx */
2+ import { Editor } from 'slate' ;
3+ import { jsx } from '../../../../support/jsx' ;
4+ import { YjsEditor , yTextToSlateElement } from '../../src' ;
5+
6+ export const input = (
7+ < editor >
8+ < unstyled >
9+ < text bold />
10+ </ unstyled >
11+ </ editor >
12+ ) ;
13+
14+ export const expected = {
15+ children : [
16+ < unstyled >
17+ < text bold />
18+ </ unstyled > ,
19+ ] ,
20+ } ;
21+
22+ export function run ( editor : Editor ) {
23+ const isYJSEditor = YjsEditor . isYjsEditor ( editor ) ;
24+ if ( ! isYJSEditor ) return ;
25+
26+ return yTextToSlateElement ( editor . sharedRoot ) ;
27+ }
You can’t perform that action at this time.
0 commit comments