|
|
@@ -35,12 +35,14 @@ export default class ImageUploadUI extends Plugin {
|
|
|
/**
|
|
|
* @inheritDoc
|
|
|
*/
|
|
|
- init() {
|
|
|
+ afterInit() {
|
|
|
const editor = this.editor;
|
|
|
const command = editor.commands.get( 'imageUpload' );
|
|
|
|
|
|
editor.ui.componentFactory.add( 'imageUpload', locale => {
|
|
|
- const imageUploadView = new ImageUploadPanelView( locale );
|
|
|
+ const integrations = this._prepareIntegrations();
|
|
|
+
|
|
|
+ const imageUploadView = new ImageUploadPanelView( locale, integrations && { integrations } );
|
|
|
const dropdownView = imageUploadView.dropdownView;
|
|
|
const panelView = dropdownView.panelView;
|
|
|
const splitButtonView = dropdownView.buttonView;
|
|
|
@@ -87,6 +89,7 @@ export default class ImageUploadUI extends Plugin {
|
|
|
} );
|
|
|
|
|
|
imageUploadView.delegate( 'submit', 'cancel' ).to( dropdownView );
|
|
|
+ this.delegate( 'cancel' ).to( dropdownView );
|
|
|
|
|
|
dropdownView.on( 'submit', () => {
|
|
|
closePanel();
|
|
|
@@ -107,7 +110,7 @@ export default class ImageUploadUI extends Plugin {
|
|
|
writer.removeAttribute( 'sizes', selectedElement );
|
|
|
} );
|
|
|
} else {
|
|
|
- editor.execute( 'imageInsert', { source: this.imageURLInputValue } );
|
|
|
+ editor.execute( 'imageInsert', { source: imageUploadView.imageURLInputValue } );
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -147,4 +150,49 @@ export default class ImageUploadUI extends Plugin {
|
|
|
|
|
|
return fileDialogButtonView;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Creates integrations object that will be passed to the
|
|
|
+ * {@link module:image/imageupload/ui/imageuploadpanelview~ImageUploadPanelView}.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @returns {Object}
|
|
|
+ */
|
|
|
+ _prepareIntegrations() {
|
|
|
+ const editor = this.editor;
|
|
|
+ const panelItems = editor.config.get( 'image.upload.panel.items' );
|
|
|
+
|
|
|
+ if ( !panelItems ) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const PREDEFINED_INTEGRATIONS = {
|
|
|
+ 'insertImageViaUrl': 'insertImageViaUrl'
|
|
|
+ };
|
|
|
+
|
|
|
+ // Prepares ckfinder component.
|
|
|
+ if ( editor.ui.componentFactory.has( 'ckfinder' ) ) {
|
|
|
+ const ckFinderButton = editor.ui.componentFactory.create( 'ckfinder' );
|
|
|
+ ckFinderButton.set( {
|
|
|
+ withText: true,
|
|
|
+ class: 'ck-image-upload__ck-finder-button'
|
|
|
+ } );
|
|
|
+
|
|
|
+ // We want to close the dropdown panel view when user clicks the ckFinderButton.
|
|
|
+ ckFinderButton.delegate( 'execute' ).to( this, 'cancel' );
|
|
|
+
|
|
|
+ PREDEFINED_INTEGRATIONS.openCKFinder = ckFinderButton;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Creates integrations object of valid views to pass it to the ImageUploadPanelView.
|
|
|
+ const integrations = panelItems.reduce( ( object, key ) => {
|
|
|
+ if ( PREDEFINED_INTEGRATIONS[ key ] ) {
|
|
|
+ object[ key ] = PREDEFINED_INTEGRATIONS[ key ];
|
|
|
+ }
|
|
|
+
|
|
|
+ return object;
|
|
|
+ }, {} );
|
|
|
+
|
|
|
+ return Object.keys( integrations ).length ? integrations : null;
|
|
|
+ }
|
|
|
}
|