3030
3131import { User } from '@blocknote/core/comments' ;
3232import { HocuspocusProvider } from '@hocuspocus/provider' ;
33+ import { Application } from '@hotwired/stimulus' ;
34+ import FlashController from 'core-stimulus/controllers/flash.controller' ;
3335import { LiveCollaborationManager } from 'core-stimulus/helpers/live-collaboration-helpers' ;
3436import { ShadowDomWrapper } from 'op-blocknote-extensions' ;
3537import React from 'react' ;
@@ -41,15 +43,20 @@ class BlockNoteElement extends HTMLElement {
4143 private mount :HTMLDivElement ;
4244 private errorContainer :HTMLDivElement ;
4345 private reactRoot :Root | null = null ;
46+ private stimulusApp :Application | null = null ;
4447
4548 constructor ( ) {
4649 super ( ) ;
4750
4851 const shadowRoot = this . attachShadow ( { mode : 'open' } ) ;
52+
4953 // Container for connection error/recovery messages (rendered by React via fetchConnectionTemplate)
5054 this . errorContainer = document . createElement ( 'div' ) ;
5155 this . errorContainer . id = 'documents-show-edit-view-connection-error-notice-component' ;
56+ this . errorContainer . dataset . controller = 'flash' ;
57+ this . errorContainer . dataset . flashAutohideValue = 'true' ;
5258 this . mount = document . createElement ( 'div' ) ;
59+
5360 shadowRoot . appendChild ( this . errorContainer ) ;
5461 shadowRoot . appendChild ( this . mount ) ;
5562
@@ -71,6 +78,11 @@ class BlockNoteElement extends HTMLElement {
7178 }
7279
7380 connectedCallback ( ) {
81+ // Initialize Stimulus application within shadow DOM
82+ this . stimulusApp = Application . start ( this . errorContainer ) ;
83+ this . stimulusApp . register ( 'flash' , FlashController ) ;
84+
85+ // Initialize React application within shadow DOM
7486 this . reactRoot = createRoot ( this . mount ) ;
7587
7688 const collaborationEnabled = this . getAttribute ( 'collaboration-enabled' ) === 'true' ;
@@ -93,6 +105,11 @@ class BlockNoteElement extends HTMLElement {
93105 this . reactRoot . unmount ( ) ;
94106 this . reactRoot = null ;
95107 }
108+
109+ if ( this . stimulusApp ) {
110+ this . stimulusApp . stop ( ) ;
111+ this . stimulusApp = null ;
112+ }
96113 }
97114
98115 private BlockNoteReactContainer = ( hocuspocusProvider ?:HocuspocusProvider ) => {
0 commit comments