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

How to use with existing file manager #56

Open
newelement opened this issue Dec 2, 2019 · 6 comments · May be fixed by #95 or #207
Open

How to use with existing file manager #56

newelement opened this issue Dec 2, 2019 · 6 comments · May be fixed by #95 or #207

Comments

@newelement
Copy link

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?

@mernxl
Copy link

mernxl commented Apr 25, 2020

@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.

@waynehaffenden
Copy link

+1 Any updates guys?

@flydev-fr
Copy link

flydev-fr commented Jun 29, 2020

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

mernxl added a commit to mernxl/image that referenced this issue Jul 23, 2020
This config option, if passed will be invoked on clicking "select an image". This callback receive the current imageTool as parameter, in order to permit user carry call methods like onUpload with the response object (`{ success: true, file: ... }`)

This should close editor-js#56
@mernxl mernxl linked a pull request Jul 23, 2020 that will close this issue
@mernxl
Copy link

mernxl commented Jul 23, 2020

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: ...
    }
  }
}

@O4epegb
Copy link

O4epegb commented Oct 13, 2020

Would be nice feature indeed

@MohmmedAshraf
Copy link

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

@kuzkov kuzkov linked a pull request Dec 28, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants