MCPcopy Create free account
hub / github.com/ckeditor/ckeditor5-react / _initializeEditor

Method _initializeEditor

src/ckeditor.tsx:230–278  ·  view source on GitHub ↗

* Initializes the editor by creating a proper watchdog and initializing it with the editor's configuration.

()

Source from the content-addressed store, hash-verified

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.

Callers 1

Calls 7

_getMergedConfigMethod · 0.95
_createEditorMethod · 0.95
_watchdogCreateEditorMethod · 0.95
onMethod · 0.80
setCreatorMethod · 0.80
createMethod · 0.45

Tested by

no test coverage detected