image icon indicating copy to clipboard operation
image copied to clipboard

How to use with existing file manager

Open newelement opened this issue 4 years ago • 6 comments

Sorry is this is obvious, but I cannot wrap my head around making custom blocks. I have an existing file manager in a CMS I'm working on. Is there a callback I can use to insert a block with the image I pick from my file manager?

newelement avatar Dec 02 '19 19:12 newelement

@newelement i am facing the same issue right now. I have implemented a Media Library where i can reuse photos from. I want user to pick image from Library from a modal.

Well going through the source now though. If i get something cool from there i will definitely open a pull request for the functionality.

mernxl avatar Apr 25 '20 14:04 mernxl

+1 Any updates guys?

waynehaffenden avatar Jun 07 '20 12:06 waynehaffenden

Hi,

You can achieve that by adding to the Uploader a new custom method which return the data from your image picker then pass this method to the constructor of the UI object.

Let's say I have a new method loadIframeImagePicker(pageId, callback) which call callback then return the result of callback which look like that return { success: true, file: { url: src } };

then in Ui() instantiation in the Image constructor, call your new method in the onSelectFile event :

/**
     * Module for working with UI
     */
    this.ui = new Ui({
      api,
      config: this.config,
      onSelectFile: () => {
        console.log(this.config);
        this.loadIframeImagePicker(this.config.pwconfig.editorjs.pageid, this.config.pwconfig.callback);
      }
    });

If you want a concrete example, refer to this post on ProcessWire forum : Load IFrame Native Image Picker

flydev-fr avatar Jun 29 '20 14:06 flydev-fr

Hello @newelement, I opened the above pull request which will permit us do the following, hope it helps.

I use this on my website, and it works perfectly.

const imageToolConfig = {
  class: EditorJSImage,
  config: {
    onSelectFile: tool => {
      toggleLibrary(img => {
        const data = tool.data;

        data.file = img; // set image
        data.caption = data.caption || img.meta;

        tool.data = data;
        toggleLibrary(undefined);
      });
      },
    uploader: {
       uploadByFile: ...
       uploadByUrl: ...
    }
  }
}

mernxl avatar Jul 23 '20 10:07 mernxl

Would be nice feature indeed

O4epegb avatar Oct 13 '20 09:10 O4epegb

@mernxl Hi could you please provide an example for toggleLibrary?

MohmmedAshraf avatar May 10 '22 08:05 MohmmedAshraf