From ea77c72ec65dff1e45a73dd5e4349b51fec542ea Mon Sep 17 00:00:00 2001 From: Marcin Panek Date: Tue, 28 Mar 2023 10:18:28 +0200 Subject: [PATCH] Revert fix for default props - failing test is blocking the fix. --- src/ckeditor.tsx | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/ckeditor.tsx b/src/ckeditor.tsx index 23ca9e2..e172bc9 100644 --- a/src/ckeditor.tsx +++ b/src/ckeditor.tsx @@ -131,9 +131,7 @@ export default class CKEditor extends React.Component { - const onError = this.props.onError || ( ( error, details ) => console.error( error, details ) ); - + private async _initializeEditor(): Promise { await this.editorDestructionInProgress; /* istanbul ignore next */ @@ -150,11 +148,11 @@ export default class CKEditor extends React.Component this._createEditor( el, config ) ); this.watchdog.on( 'error', ( _, { error, causesRestart } ) => { - onError( error, { phase: 'runtime', willEditorRestart: causesRestart } ); + this.props.onError( error, { phase: 'runtime', willEditorRestart: causesRestart } ); } ); await this.watchdog.create( this.domContainer.current!, this._getConfig() ) - .catch( error => onError( error, { phase: 'initialization', willEditorRestart: false } ) ); + .catch( error => this.props.onError( error, { phase: 'initialization', willEditorRestart: false } ) ); } /** @@ -263,9 +261,7 @@ export default class CKEditor extends React.Component extends React.Component extends React.Component }>, + editor: PropTypes.func.isRequired, data: PropTypes.string, config: PropTypes.object, watchdogConfig: PropTypes.object, @@ -304,20 +300,23 @@ export default class CKEditor extends React.Component> = { + config: {}, + onError: ( error, details ) => console.error( error, details ) + }; + // Store the API in the static property to easily overwrite it in tests. // Too bad dependency injection does not work in Webpack + ES 6 (const) + Babel. public static _EditorWatchdog = EditorWatchdog; } -/** - * TODO this is type space definition for props, the CKEditor.propTypes is a run-time props validation that should match. - */ -interface Props extends InferProps { +interface Props extends Pick, 'data' | 'disabled' | 'id'> { editor: { create( ...args: any ): Promise }; - config?: EditorConfig; + config: EditorConfig; watchdogConfig?: WatchdogConfig; onReady?: ( editor: TEditor ) => void; - onError?: ( error: Error, details: ErrorDetails ) => void; + onError: ( error: Error, details: ErrorDetails ) => void; onChange?: ( event: EventInfo, editor: TEditor ) => void; onFocus?: ( event: EventInfo, editor: TEditor ) => void; onBlur?: ( event: EventInfo, editor: TEditor ) => void;