@@ -62,8 +62,9 @@ function extractTextFormatting(node: import('prosemirror-model').Node): { fontFa
6262 // to get consistent "first run" formatting rather than mixed properties.
6363 node . descendants ( ( child ) => {
6464 if ( fontFamily !== undefined || fontSize !== undefined ) return false ;
65- if ( ! child . isText || child . marks . length === 0 ) return ;
66- for ( const mark of child . marks ) {
65+ const marks = child . marks ?? [ ] ;
66+ if ( ! child . isText || marks . length === 0 ) return ;
67+ for ( const mark of marks ) {
6768 const attrs = mark . attrs as Record < string , unknown > ;
6869 if ( typeof attrs . fontFamily === 'string' && attrs . fontFamily ) {
6970 fontFamily = attrs . fontFamily ;
@@ -85,6 +86,14 @@ function extractTextFormatting(node: import('prosemirror-model').Node): { fontFa
8586 */
8687function collectDocumentStyles ( editor : Editor ) : { styles : DocumentStyles ; defaults : DocumentDefaults } {
8788 const headingPattern = HEADING_STYLE_PATTERN ;
89+ const doc = editor . state ?. doc ;
90+
91+ if ( ! doc ?. descendants ) {
92+ return {
93+ styles : { paragraphStyles : [ ] } ,
94+ defaults : { styleId : 'Normal' } ,
95+ } ;
96+ }
8897
8998 // Per-style data
9099 const styleData = new Map < string , { count : number ; fontFamily ?: string ; fontSize ?: number } > ( ) ;
@@ -93,7 +102,7 @@ function collectDocumentStyles(editor: Editor): { styles: DocumentStyles; defaul
93102 const fontCounts = new Map < string , number > ( ) ;
94103 const sizeCounts = new Map < number , number > ( ) ;
95104
96- editor . state . doc . descendants ( ( node ) => {
105+ doc . descendants ( ( node ) => {
97106 if ( node . type . name !== 'paragraph' ) return ;
98107
99108 const props = node . attrs . paragraphProperties as { styleId ?: string } | undefined ;
0 commit comments