* Initializes the editor by creating a proper watchdog and initializing it with the editor's configuration.
()
| 228 | * Initializes the editor by creating a proper watchdog and initializing it with the editor's configuration. |
| 229 | */ |
| 230 | private async _initializeEditor(): Promise<EditorSemaphoreMountResult<TEditor>> { |
| 231 | const supports = getInstalledCKBaseFeatures(); |
| 232 | const { |
| 233 | editor: Editor, |
| 234 | disableWatchdog, |
| 235 | watchdogConfig |
| 236 | } = this.props; |
| 237 | |
| 238 | const mergedConfig = this._getMergedConfig( true ); |
| 239 | |
| 240 | if ( disableWatchdog ) { |
| 241 | const instance = await this._createEditor( mergedConfig ); |
| 242 | |
| 243 | return { |
| 244 | instance, |
| 245 | watchdog: null |
| 246 | }; |
| 247 | } |
| 248 | |
| 249 | const watchdog = ( () => { |
| 250 | // There is small delay where React did not update the context yet but watchdog is already destroyed. |
| 251 | // However editor should be created again in such case, after receiving new context. |
| 252 | if ( isContextWatchdogReadyToUse( this.context ) ) { |
| 253 | return new EditorWatchdogAdapter( this.context.watchdog ); |
| 254 | } |
| 255 | |
| 256 | return new Editor.EditorWatchdog( Editor, watchdogConfig ); |
| 257 | } )() as EditorWatchdogAdapter<TEditor>; |
| 258 | |
| 259 | watchdog.on( 'error', ( _, { error, causesRestart } ) => { |
| 260 | const onError = this.props.onError ?? console.error; |
| 261 | |
| 262 | onError( error, { phase: 'runtime', willEditorRestart: causesRestart } ); |
| 263 | } ); |
| 264 | |
| 265 | /* istanbul ignore if -- @preserve */ |
| 266 | if ( supports.elementConfigAttachment ) { |
| 267 | watchdog.setCreator( async ( config: EditorConfig ) => this._watchdogCreateEditor( watchdog, config ) ); |
| 268 | await watchdog.create( mergedConfig ); |
| 269 | } else { |
| 270 | watchdog.setCreator( async ( _, config ) => this._watchdogCreateEditor( watchdog, config ) ); |
| 271 | await watchdog.create( this.domContainer.current!, mergedConfig ); |
| 272 | } |
| 273 | |
| 274 | return { |
| 275 | watchdog, |
| 276 | instance: watchdog!.editor |
| 277 | }; |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * Creates editor in watchdog context. |
no test coverage detected