Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up editor types #133

Merged
merged 13 commits into from
Sep 16, 2020
3 changes: 1 addition & 2 deletions src/app/demo-form/demo-form.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ <h3>User profile form</h3>
<ckeditor
[(ngModel)]="model.description"
id="description"
name="description"
type="divarea">
name="description">
Dumluregn marked this conversation as resolved.
Show resolved Hide resolved
</ckeditor>

<p *ngIf="description && description.dirty" class="alert">Description is "dirty".</p>
Expand Down
1 change: 0 additions & 1 deletion src/app/demo-form/demo-form.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ describe( 'DemoFormComponent', () => {
} );

ckeditorComponent.instance.setData( '<p>An unidentified person</p>' );

} );

it( 'when reset button is clicked should reset form', done => {
Expand Down
1 change: 0 additions & 1 deletion src/app/simple-usage/simple-usage.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ describe( 'SimpleUsageComponent', () => {
} );
} );


describe( 'listeners', () => {
beforeEach( () => {
spy = spyOn( console, 'log' );
Expand Down
2 changes: 1 addition & 1 deletion src/app/simple-usage/simple-usage.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class SimpleUsageComponent {
While it’s also nice to learn about cultures online or from books, nothing comes close to experiencing cultural diversity in person.
You learn to appreciate each and every single one of the differences while you become more culturally fluid.</p>`;

editors = [ 'Classic', 'Divarea', 'Inline' ];
editors = [ 'Classic', 'Inline' ];

isHidden = false;

Expand Down
53 changes: 0 additions & 53 deletions src/ckeditor/ckeditor.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ describe( 'CKEditorComponent', () => {
} );

[
EditorType.DIVAREA,
EditorType.INLINE,
EditorType.CLASSIC
].forEach( editorType => {
Expand Down Expand Up @@ -117,58 +116,6 @@ describe( 'CKEditorComponent', () => {
} );
} );

const isDivarea = editorType === EditorType.DIVAREA;

[ {
newConfig: undefined,
msg: 'without config',
warn: false
}, {
newConfig: { extraPlugins: 'basicstyles,divarea,link' },
msg: 'config.extraPlugins defined as a string',
warn: false
}, {
newConfig: { extraPlugins: [ 'basicstyles', 'divarea', 'link' ] },
msg: 'config.extraPlugins defined as an array',
warn: false
}, {
newConfig: { removePlugins: 'basicstyles,divarea,link,divarea' },
msg: 'config.removePlugins defined as a string',
warn: isDivarea
}, {
newConfig: { removePlugins: [ 'basicstyles', 'divarea', 'link', 'divarea' ] },
msg: 'config.removePlugins defined as an array',
warn: isDivarea
} ].forEach( ( { newConfig, msg, warn } ) => {
describe( msg, () => {
beforeEach( () => {
config = newConfig;
} );

it( `console ${warn ? 'should' : 'shouldn\'t'} warn`, () => {
const spy = spyOn( console, 'warn' );

fixture.detectChanges();

return whenEvent( 'ready', component ).then( () => {
warn
? expect( spy ).toHaveBeenCalled()
: expect( spy ).not.toHaveBeenCalled();
} );
} );

it( `editor ${ isDivarea ? 'should' : 'shouldn\'t' } use divarea plugin`, () => {
fixture.detectChanges();

return whenEvent( 'ready', component ).then( ( { editor } ) => {
isDivarea
? expect( editor.plugins.divarea ).not.toBeUndefined()
: expect( editor.plugins.divarea ).toBeUndefined();
} );
} );
} );
} );

describe( 'when set with config', () => {
beforeEach( () => {
component.config = {
Expand Down
56 changes: 9 additions & 47 deletions src/ckeditor/ckeditor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ declare let CKEDITOR: any;
export class CKEditorComponent implements AfterViewInit, OnDestroy, ControlValueAccessor {
/**
* The configuration of the editor.
*
* See https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html
* to learn more.
*/
Expand All @@ -55,8 +56,8 @@ export class CKEditorComponent implements AfterViewInit, OnDestroy, ControlValue
/**
* The type of the editor interface.
*
* By default editor interface will be initialized as `divarea` editor which is an inline editor with fixed UI.
* You can change interface type by choosing between `divarea` and `inline` editor interface types.
* By default editor interface will be initialized as `classic` editor.
* You can also choose to create an editor with `inline` interface type instead.
*
* See https://ckeditor.com/docs/ckeditor4/latest/guide/dev_uitypes.html
* and https://ckeditor.com/docs/ckeditor4/latest/examples/fixedui.html
Expand Down Expand Up @@ -84,16 +85,16 @@ export class CKEditorComponent implements AfterViewInit, OnDestroy, ControlValue
}

this._data = data;

}

get data(): string {
return this._data;
}

/**
* When set `true`, the editor becomes read-only.
* https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_editor.html#property-readOnly
* When set to `true`, the editor becomes read-only.
*
* See https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_editor.html#property-readOnly
* to learn more.
*/
@Input() set readOnly( isReadOnly: boolean ) {
Expand Down Expand Up @@ -147,14 +148,14 @@ export class CKEditorComponent implements AfterViewInit, OnDestroy, ControlValue
@Output() dataChange = new EventEmitter<CKEditor4.EventInfo>();

/**
* Fires when the native drop event occurs. It corresponds with the `editor#dragstart`
* Fires when the native dragStart event occurs. It corresponds with the `editor#dragstart`
* https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_editor.html#event-dragstart
* event.
*/
@Output() dragStart = new EventEmitter<CKEditor4.EventInfo>();

/**
* Fires when the native drop event occurs. It corresponds with the `editor#dragend`
* Fires when the native dragEnd event occurs. It corresponds with the `editor#dragend`
* https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_editor.html#event-dragend
* event.
*/
Expand Down Expand Up @@ -182,7 +183,7 @@ export class CKEditorComponent implements AfterViewInit, OnDestroy, ControlValue
@Output() fileUploadRequest = new EventEmitter<CKEditor4.EventInfo>();

/**
* Fires when the editing view of the editor is focused. It corresponds with the `editor#focus`
* Fires when the editing area of the editor is focused. It corresponds with the `editor#focus`
* https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_editor.html#event-focus
* event.
*/
Expand Down Expand Up @@ -290,10 +291,6 @@ export class CKEditorComponent implements AfterViewInit, OnDestroy, ControlValue
const element = document.createElement( this.tagName );
this.elementRef.nativeElement.appendChild( element );

if ( this.type === CKEditor4.EditorType.DIVAREA ) {
this.config = this.ensureDivareaPlugin( this.config || {} );
}

const instance: CKEditor4.Editor = this.type === CKEditor4.EditorType.INLINE
? CKEDITOR.inline( element, this.config )
: CKEDITOR.replace( element, this.config );
Expand Down Expand Up @@ -424,39 +421,4 @@ export class CKEditorComponent implements AfterViewInit, OnDestroy, ControlValue
} );
}

private ensureDivareaPlugin( config: CKEditor4.Config ): CKEditor4.Config {
let { extraPlugins, removePlugins } = config;

extraPlugins = this.removePlugin( extraPlugins, 'divarea' ) || '';
extraPlugins = extraPlugins.concat( typeof extraPlugins === 'string' ? ',divarea' : 'divarea' );

if ( removePlugins && removePlugins.includes( 'divarea' ) ) {

removePlugins = this.removePlugin( removePlugins, 'divarea' );

console.warn( '[CKEDITOR] divarea plugin is required to initialize editor using Angular integration.' );
}

return Object.assign( {}, config, { extraPlugins, removePlugins } );
}

private removePlugin( plugins: string | string[], toRemove: string ): string | string[] {
if ( !plugins ) {
return null;
}

const isString = typeof plugins === 'string';

if ( isString ) {
plugins = ( plugins as string ).split( ',' );
}

plugins = ( plugins as string[] ).filter( plugin => plugin !== toRemove );

if ( isString ) {
plugins = ( plugins as string[] ).join( ',' );
}

return plugins;
}
}
1 change: 0 additions & 1 deletion src/ckeditor/ckeditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export namespace CKEditor4 {
* to learn more.
*/
export const enum EditorType {
DIVAREA = 'divarea',
INLINE = 'inline',
CLASSIC = 'classic'
}
Expand Down
5 changes: 2 additions & 3 deletions src/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
// (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
// (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames

/*
/**
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
* with the following flag, it will bypass `zone.js` patch for IE/Edge
*/
// (window as any).__Zone_enable_cross_context_check = true;

/***************************************************************************************************
* Browser Polyfills
* IE11 needs those in general. Currently we use only some of them in tests using console and ensuring that 'divarea' plugin is loaded,
* but they may come in handy later.
* IE11 needs those in general. Currently we use only some of them, but they may come in handy later.
*/

import 'core-js/es/symbol';
Expand Down