Unable to use inside Shadow Dom and Webcomponents #1881
Replies: 17 comments 3 replies
-
Hi @andrewebdev |
Beta Was this translation helpful? Give feedback.
-
yeah I just snipped that part out of the paste. All imports are working. The exact same config works in our iFrame version of the code, but as I mentioned we would like to transition away from the iframe requirement. |
Beta Was this translation helpful? Give feedback.
-
Could you provide Editor.js version also It seems something wrong with internal modules import |
Beta Was this translation helpful? Give feedback.
-
@gohabereg aha, you just made me think to look at something. Not all my modules are packaged for web, so some have relative imports which might then break the internal imports for other modules. I'll run everything through rollup and revert back with results. In the meantime, if still interested, here is the versions:
|
Beta Was this translation helpful? Give feedback.
-
@gohabereg ok so it seems id didn't just have anything to do with the tools. I attempted to use it without specifying any tools in my config, just to test. And the editor still doesn't load. |
Beta Was this translation helpful? Give feedback.
-
Ah @gohabereg I see the problem. It seems like, importing the editor will add the CSS to the main document, which of course wont leak through into the shadow dom of our custom element. Are the CSS exported in the main module, then I can maybe import it and insert it into the custom element. |
Beta Was this translation helpful? Give feedback.
-
I'm having the same issue. I've tried to render styles into shadowRoot by patching |
Beta Was this translation helpful? Give feedback.
-
@katsew I also discovered that every plugin also injects their own CSS into the main document as well. So every one of the plugins would also need to allow for usage inside the shadowroot, which is quite annoying. |
Beta Was this translation helpful? Give feedback.
-
I am facing the same issues. Any solution folks? Any suggested direction? Is there a manner in which the css can be appended to the webcomponent? Thanks |
Beta Was this translation helpful? Give feedback.
-
Any update on this? Btw, it's specially annoying that plugins doesn't use any encapsulation nor namespacing for class names, so it's very easy to mess up. Now that Shadow Dom is widely supported across all major browsers, it would be awesome to embrace it for editor.js internals as well! |
Beta Was this translation helpful? Give feedback.
-
Any update? |
Beta Was this translation helpful? Give feedback.
-
Yep, came here while trying to build a web component with editor.js, but with CSS in the wrong DOM it's not feasible. Another problem is that CSS is not distributed in the packages (except in the js bundle file), so can't incorporate it in the build process either. |
Beta Was this translation helpful? Give feedback.
-
I found an easy workaround to be able to use editorJS inside a web component. When designing your web component with your favorite framework (e.g. stencilJS, LitElement, Fast Element, etc.), create a as a placeholder for the editor. Since slot can be styled from outside (e.g. via a Document-level CSS), EditorJS will just work inside the web component. Here is some pseudo code for your reference: In your index.html, make editorjs DIV a child element of my-element, and add the following script: I hope this is helpful to you! |
Beta Was this translation helpful? Give feedback.
-
modifying the loadStyles function in ui.ts with a fork fixes it for me. Additional changes to prepare(holder) furnction are also needed. If I have time I will make a pr for this.
Styles are added with this but functionality in Shadow dom seems to still not work :/ |
Beta Was this translation helpful? Give feedback.
-
Yes, currently styles are appending to the document.head. We will need to find a solution. |
Beta Was this translation helpful? Give feedback.
-
@neSpecc you should insert styles next to the element you used as holder instead of the head. Here's is my ugly workaround for ShadowDom users (lit here). The idea is to move style defined in head inside the webcomponent. this.editor = new EditorJS({
holder: this.$editorContainer,
tools: {
...
},
onReady: () => {
const editorStyles = document.querySelector("#editor-js-styles");
this.shadowRoot.appendChild(editorStyles)
}
}); |
Beta Was this translation helpful? Give feedback.
-
not the best workaround but worked for me
` |
Beta Was this translation helpful? Give feedback.
-
We wanted to use EditorJS with customElements (we use
lit-html
internally). Our reasons behind this is because we wanted to isolate the editor styles away from the main dom so that our CMS styles don't make the editor content look strange. This way we can also customize the CSS nicely so that the end user looks at the formatting and text with about the same styles as they would on the frontend.We previously used a Iframe for this (which still works), but we would like to avoid that if possible.
With the editor in the customElement, we get errors like these:
Here is the code that creates the customElement:
And this is how we are using the element:
Edit: Oh and here is the config that is used.
Beta Was this translation helpful? Give feedback.
All reactions