editor.js icon indicating copy to clipboard operation
editor.js copied to clipboard

Using Vue in tool development?

Open butaminas opened this issue 5 years ago • 9 comments

I was wondering if anyone had some experiences or ideas on how could Vue be used for custom tool development?

I know there is a Vue wrapper for editor.js, but it's just a wrapper and I'm not looking for that, I'm looking to develop a custom tool that could utilize the reactivity of Vue.

butaminas avatar May 13 '19 06:05 butaminas

you can achieve this by doing something like this:

import CustomBlock from './CustomBlock.vue';
const ComponentCtor = Vue.extend(CustomBlock);

class SimpleImage {
  constructor({ data }: ImageProps) {
    this.data = data;
    this.wrapper = null;
  }

  static get toolbox() {
  // see the getting started tutorial;
  }

  render() {
    this.wrapper = document.createElement('div');
    this.wrapper.id = 'custom-id';
    // this you can use this like any other vue component.
    this.component = new ComponentCtor({
      propsData: this.data,
    });
    this.component.$mount('#custom-id');
    return this.wrapper;
  }

  save(blockContent) {
   // in the component have a function that returns the required data.
    return this.component.getData();
  }

  validate(savedData) {
    if (!savedData.url.trim()) {
      return false;
    }

    return true;
  }
}

i hope this is enough to get you started.

Neophen avatar Jan 17 '20 20:01 Neophen

I ended up doing the following

render() {
        this.wrapper = document.createElement('div');
        this.wrapper.id = 'custom-id';
        // this you can use this like any other vue component.
        this.component = new ComponentCtor({
            propsData: {
                filetypes: []
            },
        });
        this.component.$mount();
        return this.wrapper.appendChild(this.component.$el);
}

Devin345458 avatar Jan 25 '20 01:01 Devin345458

any know a way to access the current vue instance in the class maybe pass it via config or is there a other way? i use nuxt i dont have a way to import or export vue itself

//e found a other way i will make a config callback which is calling in the initalizer component then i will pass my data back

cannap avatar Jan 20 '21 12:01 cannap

Is there any work around for this in the vue 3?

luckyboy07 avatar Apr 27 '22 02:04 luckyboy07

@luckyboy07 sorry for my late answer, i just did this in vue 3 using my own custom vue 3 component: (you need render and h from 'vue')

https://gist.github.com/bettysteger/d7f2b1a52bb1c23a0c24f3a9ff5832d9

bettysteger avatar Nov 27 '23 09:11 bettysteger

@bettysteger Thank you so much, I will definitely try this one.

luckyboy07 avatar Nov 27 '23 09:11 luckyboy07