maxeckel / livewire-editorjs

This Package aims for an easy integration of Editor.JS with Laravel Livewire
MIT License
146 stars 20 forks source link

Can't find variable: editorInstance #24

Closed MrMooky closed 2 years ago

MrMooky commented 2 years ago

I'm probably doing something wrong, but can't figure it out. ._.

In order to be able to create my own plugins, I opted for option two regarding the assets.

I ended up with errors so I removed everything to a bare minimum:

import EditorJS from '@editorjs/editorjs';

window.editorInstance = function(dataProperty, editorId, readOnly, placeholder, logLevel) {
    return {
        instance: null,
        data: null,

        initEditor() {
            this.data = this.$wire.get(dataProperty);

            this.instance = new EditorJS({
                holder: editorId,

                readOnly,

                placeholder,

                logLevel,

                data: this.data,

                onChange: () => {
                    this.instance.save().then((outputData) => {
                        this.$wire.set(dataProperty, outputData);

                        this.$wire.call('save');
                    }).catch((error) => {
                        console.log('Saving failed: ', error)
                    });
                }
            });
        }
    }
}

But I'm still getting errors:

Screenshot 2022-02-27 at 13 21 37

Really not sure what I'm doing wrong. Any help is much appreciated.

MrMooky commented 2 years ago

Ah, never mind. Had to include the script before Alpine.js is initialised.