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

I/6333: Create MediaFormView for each dropdown instance separately #6736

Merged
merged 4 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions packages/ckeditor5-media-embed/src/mediaembedui.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,14 @@ export default class MediaEmbedUI extends Plugin {
const command = editor.commands.get( 'mediaEmbed' );
const registry = editor.plugins.get( MediaEmbedEditing ).registry;

/**
* The form view displayed inside the drop-down.
*
* @member {module:media-embed/ui/mediaformview~MediaFormView}
*/
this.form = new MediaFormView( getFormValidators( editor.t, registry ), editor.locale );

// Setup `imageUpload` button.
editor.ui.componentFactory.add( 'mediaEmbed', locale => {
const dropdown = createDropdown( locale );

this._setUpDropdown( dropdown, this.form, command, editor );
this._setUpForm( this.form, dropdown, command );
const mediaForm = new MediaFormView( getFormValidators( editor.t, registry ), editor.locale );

this._setUpDropdown( dropdown, mediaForm, command, editor );
this._setUpForm( dropdown, mediaForm, command );

return dropdown;
} );
Expand Down Expand Up @@ -103,7 +98,7 @@ export default class MediaEmbedUI extends Plugin {
}
}

_setUpForm( form, dropdown, command ) {
_setUpForm( dropdown, form, command ) {
form.delegate( 'submit', 'cancel' ).to( dropdown );
form.urlInputView.bind( 'value' ).to( command, 'value' );

Expand Down
9 changes: 9 additions & 0 deletions packages/ckeditor5-media-embed/tests/mediaembedui.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ describe( 'MediaEmbedUI', () => {
expect( dropdown ).to.be.instanceOf( DropdownView );
} );

it( 'should allow creating two instances', () => {
let secondInstance;

expect( function createSecondInstance() {
secondInstance = editor.ui.componentFactory.create( 'mediaEmbed' );
} ).not.to.throw();
expect( dropdown ).to.not.equal( secondInstance );
} );

describe( 'dropdown', () => {
it( 'should bind #isEnabled to the command', () => {
const command = editor.commands.get( 'mediaEmbed' );
Expand Down