Skip to content

Commit

Permalink
Schema extend moved to the afterInit function.
Browse files Browse the repository at this point in the history
  • Loading branch information
pszczesniak committed Mar 7, 2024
1 parent 4be4b1b commit 9d8c653
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export default class ImageResizeEditing extends Plugin {
const editor = this.editor;
const resizeImageCommand = new ResizeImageCommand( editor );

this._registerSchema();
this._registerConverters( 'imageBlock' );
this._registerConverters( 'imageInline' );

Expand All @@ -81,6 +80,13 @@ export default class ImageResizeEditing extends Plugin {
editor.commands.add( 'imageResize', resizeImageCommand );
}

/**
* @inheritDoc
*/
public afterInit(): void {
this._registerSchema();
}

private _registerSchema(): void {
if ( this.editor.plugins.has( 'ImageBlockEditing' ) ) {
this.editor.model.schema.extend( 'imageBlock', { allowAttributes: [ 'resizedWidth', 'resizedHeight' ] } );
Expand Down
24 changes: 24 additions & 0 deletions packages/ckeditor5-image/tests/imageresize/imageresizeediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,30 @@ describe( 'ImageResizeEditing', () => {
expect( newEditor.model.schema.checkAttribute( [ '$root', 'imageInline' ], 'resizedHeight' ) ).to.be.true;
await newEditor.destroy();
} );

it( 'allows the resizedWidth attribute when ImageBlock plugin is enabled (reverse order in plugins array)', async () => {
const newEditor = await ClassicEditor.create( editorElement, { plugins: [ ImageResizeEditing, ImageBlockEditing ] } );
expect( newEditor.model.schema.checkAttribute( [ '$root', 'imageBlock' ], 'resizedWidth' ) ).to.be.true;
await newEditor.destroy();
} );

it( 'allows the resizedHeight attribute when ImageBlock plugin is enabled (reverse order in plugins array)', async () => {
const newEditor = await ClassicEditor.create( editorElement, { plugins: [ ImageResizeEditing, ImageBlockEditing ] } );
expect( newEditor.model.schema.checkAttribute( [ '$root', 'imageBlock' ], 'resizedHeight' ) ).to.be.true;
await newEditor.destroy();
} );

it( 'allows the resizedWidth attribute when ImageInline plugin is enabled (reverse order in plugins array)', async () => {
const newEditor = await ClassicEditor.create( editorElement, { plugins: [ ImageResizeEditing, ImageInlineEditing ] } );
expect( newEditor.model.schema.checkAttribute( [ '$root', 'imageInline' ], 'resizedWidth' ) ).to.be.true;
await newEditor.destroy();
} );

it( 'allows the resizedHeight attribute when ImageInline plugin is enabled (reverse order in plugins array)', async () => {
const newEditor = await ClassicEditor.create( editorElement, { plugins: [ ImageResizeEditing, ImageInlineEditing ] } );
expect( newEditor.model.schema.checkAttribute( [ '$root', 'imageInline' ], 'resizedHeight' ) ).to.be.true;
await newEditor.destroy();
} );
} );

describe( 'command', () => {
Expand Down

0 comments on commit 9d8c653

Please sign in to comment.