codex-team / editor.js

A block-style editor with clean JSON output
https://editorjs.io
Apache License 2.0
28.71k stars 2.08k forks source link

💡Ability to set block data externally? #1245

Closed jnguyen32 closed 4 years ago

jnguyen32 commented 4 years ago

I'm looking through the Core API and I am not sure of a way to set block data externally.

I have a Vue application that already has asset management (image upload/image selection) that I am looking to re-use.

I can trigger the asset manager to display by passing a function via the config.

e.g.,

tools: {
   ...
   image: {
      class: MyImageTool,
      config: {
          select_asset: function(e) {
              // display asset selector
          }
      }
   }

From within MyImageTool:

   this.api.listeners.on(button, 'click', () => { 
      this.config['select_asset'](this.data);
   });

The above code will trigger the display of the asset selector, but once you have the asset chosen (external to EditorJS), how do I pass it back into the tool for saving?

neSpecc commented 4 years ago

It is not related to the Core API. You can implement your own Image Tool with the asset manager using vue.js.

neSpecc commented 4 years ago

Because you can't just set the block data from the editor core — the tool should react to these changes. But you can use the blocks.insert() method to create the block with passed data.