@@ -5,6 +5,19 @@ import { Transformer } from './types'
55
66class Prosemirror implements Transformer {
77
8+ defaultSchema : Schema = new Schema ( {
9+ nodes : {
10+ text : { } ,
11+ doc : { content : 'text*' } ,
12+ } ,
13+ } )
14+
15+ schema ( schema : Schema ) : Prosemirror {
16+ this . defaultSchema = schema
17+
18+ return this
19+ }
20+
821 fromYdoc ( document : Doc , fieldName ?: string | Array < string > ) : any {
922 const data = { }
1023
@@ -26,17 +39,17 @@ class Prosemirror implements Transformer {
2639 return data
2740 }
2841
29- toYdoc ( document : any , schema : Schema , fieldName : string | Array < string > = 'prosemirror' ) : Doc {
42+ toYdoc ( document : any , schema ? : Schema , fieldName : string | Array < string > = 'prosemirror' ) : Doc {
3043 // allow a single field name
3144 if ( typeof fieldName === 'string' ) {
32- return prosemirrorJSONToYDoc ( schema , document , fieldName )
45+ return prosemirrorJSONToYDoc ( schema || this . defaultSchema , document , fieldName )
3346 }
3447
3548 const ydoc = new Doc ( )
3649
3750 fieldName . forEach ( field => {
3851 const update = encodeStateAsUpdate (
39- prosemirrorJSONToYDoc ( schema , document , field ) ,
52+ prosemirrorJSONToYDoc ( schema || this . defaultSchema , document , field ) ,
4053 )
4154
4255 applyUpdate ( ydoc , update )
0 commit comments