@@ -187,7 +187,6 @@ export class SuperDoc extends EventEmitter {
187187
188188 // If a toolbar element is provided, render a toolbar
189189 this . addToolbar ( this ) ;
190-
191190 }
192191
193192 get requiredNumberOfEditors ( ) {
@@ -354,11 +353,13 @@ export class SuperDoc extends EventEmitter {
354353 role : this . config . role ,
355354 pagination : this . config . pagination ,
356355 icons : this . config . toolbarIcons ,
356+ documentMode : this . config . documentMode ,
357357 superdoc : this ,
358358 } ;
359359
360360 this . toolbar = new SuperToolbar ( config ) ;
361361 this . toolbar . on ( 'superdoc-command' , this . onToolbarCommand . bind ( this ) ) ;
362+ this . once ( 'editorCreate' , ( ) => this . toolbar . updateToolbarState ( ) ) ;
362363 }
363364
364365 addCommentsList ( element ) {
@@ -402,26 +403,38 @@ export class SuperDoc extends EventEmitter {
402403 if ( this . config . role !== 'editor' ) return this . #setModeSuggesting( ) ;
403404 if ( this . superdocStore . documents . length > 0 ) {
404405 const firstEditor = this . superdocStore . documents [ 0 ] ?. getEditor ( ) ;
405- if ( firstEditor ) {
406- this . setActiveEditor ( firstEditor ) ;
407- this . toolbar . activeEditor = firstEditor ;
408- }
406+ if ( firstEditor ) this . setActiveEditor ( firstEditor ) ;
409407 }
410408
411409 this . superdocStore . documents . forEach ( ( doc ) => {
412410 doc . restoreComments ( ) ;
413411 const editor = doc . getEditor ( ) ;
414412 if ( editor ) editor . setDocumentMode ( 'editing' ) ;
415413 } ) ;
414+
415+ if ( this . toolbar ) {
416+ this . toolbar . documentMode = 'editing' ;
417+ this . toolbar . updateToolbarState ( ) ;
418+ }
416419 }
417420
418421 #setModeSuggesting( ) {
419422 if ( ! [ 'editor' , 'suggester' ] . includes ( this . config . role ) ) return this . #setModeViewing( ) ;
423+ if ( this . superdocStore . documents . length > 0 ) {
424+ const firstEditor = this . superdocStore . documents [ 0 ] ?. getEditor ( ) ;
425+ if ( firstEditor ) this . setActiveEditor ( firstEditor ) ;
426+ }
427+
420428 this . superdocStore . documents . forEach ( ( doc ) => {
421429 doc . restoreComments ( ) ;
422430 const editor = doc . getEditor ( ) ;
423431 if ( editor ) editor . setDocumentMode ( 'suggesting' ) ;
424432 } ) ;
433+
434+ if ( this . toolbar ) {
435+ this . toolbar . documentMode = 'suggesting' ;
436+ this . toolbar . updateToolbarState ( ) ;
437+ }
425438 }
426439
427440 #setModeViewing( ) {
@@ -431,6 +444,11 @@ export class SuperDoc extends EventEmitter {
431444 const editor = doc . getEditor ( ) ;
432445 if ( editor ) editor . setDocumentMode ( 'viewing' ) ;
433446 } ) ;
447+
448+ if ( this . toolbar ) {
449+ this . toolbar . documentMode = 'viewing' ;
450+ this . toolbar . updateToolbarState ( ) ;
451+ }
434452 }
435453
436454 /**
0 commit comments