codex-team / editor.js

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

❓Editor.js inside web component #2026

Open lukaszkaleta opened 2 years ago

lukaszkaleta commented 2 years ago

Question

How do I embed editor js inside web component ?

Context

Our application is developed around web component (Lit) and we would like to give a try to editorjs. But when we use it something wierd happens with styles.

image

` import {css, html, LitElement} from 'lit' import EditorJS from '@editorjs/editorjs';

export class TestingEditor extends LitElement {

firstUpdated(_changedProperties) {
    const editor = new EditorJS(this.renderRoot.querySelector('#editorjs'));
}

render() {
    return html`<div id="editorjs"></div>`
}

}

customElements.define('testing-editor', TestingEditor)

`

Any tips appreciated.

blahah commented 2 years ago

does disabling shadowRoot for the LitElement fix it? If so you need to attach the editorjs styles to the shadowRoot

MadeByMike commented 2 years ago

@blahah I'm not saying this is the best code ever written but here:

 editor.isReady.then(() => {
   const styles = document.querySelector("#editor-js-styles").cloneNode(true);
   this.shadowRoot.appendChild(styles)
 })

It would probably be nice to have an option to render the styles directly within the holder container.

MadeByMike commented 2 years ago

FYI I found many other issues with this working inside a shadow DOM. Had to revert to no shadow DOM.