From 6c274946aa6b3a6c7923a1eb7da0ea78192b7d9b Mon Sep 17 00:00:00 2001 From: Mihilion Date: Wed, 2 Aug 2023 14:37:08 +0200 Subject: [PATCH] Add support for mode event --- src/ckeditor/ckeditor.component.spec.ts | 11 +++++++++++ src/ckeditor/ckeditor.component.ts | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/ckeditor/ckeditor.component.spec.ts b/src/ckeditor/ckeditor.component.spec.ts index c29d84f..699960c 100644 --- a/src/ckeditor/ckeditor.component.spec.ts +++ b/src/ckeditor/ckeditor.component.spec.ts @@ -323,6 +323,17 @@ describe( 'CKEditorComponent', () => { expect( spy ).toHaveBeenCalledTimes( 1 ); } ); + it( 'mode should emit component mode', () => { + fixture.detectChanges(); + + const spy = jasmine.createSpy(); + component.mode.subscribe( spy ); + + component.instance.fire( 'mode' ); + + expect( spy ).toHaveBeenCalledTimes( 1 ); + } ); + it( 'paste should emit component paste', () => { fixture.detectChanges(); diff --git a/src/ckeditor/ckeditor.component.ts b/src/ckeditor/ckeditor.component.ts index e814139..72b738a 100644 --- a/src/ckeditor/ckeditor.component.ts +++ b/src/ckeditor/ckeditor.component.ts @@ -225,6 +225,13 @@ export class CKEditorComponent implements AfterViewInit, OnDestroy, ControlValue */ @Output() blur = new EventEmitter(); + /** + * Fires when the native mode event occurs. It corresponds with the `editor#mode` + * https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_editor.html#event-mode + * event. + */ + @Output() mode = new EventEmitter(); + /** * A callback executed when the content of the editor changes. Part of the * `ControlValueAccessor` (https://angular.io/api/forms/ControlValueAccessor) interface. @@ -417,6 +424,12 @@ export class CKEditorComponent implements AfterViewInit, OnDestroy, ControlValue } ); } ); + editor.on( 'mode', evt => { + this.ngZone.run( () => { + this.mode.emit( evt ); + } ); + } ); + editor.on( 'dataReady', this.propagateChange, this ); if ( this.instance.undoManager ) {