-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support injecting Blockly into shadowDom #1114
Comments
Here's an old forum discussion from people trying to do the same thing. |
@rachel-fenichel it looks like the consensus they came to was "it's impossible just put it in an iframe" which doesn't sound like much of a solution. |
I linked to the forum post because they discussed specific things that broke when you put Blockly in a shadow DOM.
and
|
can you help me? I don't know how to fix my code.
|
I'm experiencing this issue in angularJS as well. |
Same issue
Code below window.customElements.define('blockly-block' ,class extends HTMLElement{
} connectedCallback(){ |
any progress yet on this one ? |
workspace = {
const container = document.querySelector('#blockly_div');
removeAllChildNodes(container);
const workspace = Blockly.inject('blockly_div', {
media: 'https://unpkg.com/blockly/media/',
toolbox: defaultToolboxConfiguration(Blockly),
grid: { spacing: 20, length: 3, colour: '#ccc', snap: true },
zoom: {
controls: true,
wheel: true,
startScale: 1.0,
maxScale: 2.0,
minScale: 1.0,
scaleSpeed: 0.4
},
trashcan: true
});
return workspace;
} |
@BeksOmega please put this issue to higher priority. It is more than 4 years old :) |
This issue is indeed a major blocker for every project that uses web components (which are being made more popular by Google's own Lit). Just removing the validation check in the original post won't fix the issue however. Blockly injects styles and scripts into the Are there any plans for fixing this issue? Or any avenues of development to help contributors work on a PR? |
With a small hack, it looks as if blockly works well in a shadow DOM. getBlocklyCSS() { and in the render() function you can do something like: return html I am pretty sure that this solution is not optimized at all, but, together with the removal of the check for the blockly container in Blockly.inject makes a non invasive hack. Actually, you can do a new Blockly.inject function and then you do not need to change any code. So it works in the compressed version without any compilation. |
I solved it atm. with a hack like this:
means after injecting blockly, I search the document for the styles and move them to my component |
I already did a little bit better fix:
but there are also problems when using blockly in shadow dom, for example the overlay input for enter text is at the wrong position. There may be more, this is my first day testing this. But at least I could get it to render and I could drag/drop items... |
Could you provide some more details about why shadow dom is important to your project? We have a lot of things we are planning to do in Q1 and I'm not sure that we have time to prioritize this :/ (including review). It would be very helpful to have more details about if and where this is blocking you! |
ShadowDom is important for me, as my complete UI is based on WebComponents wich use shadowdom. At the moment I could solve my usage with this code...
but I feels very hacky for me atm. So it is not so critical as it works . I could work on this, the Blockly Codebase seems very easy to understand, but at first there needs to be a consense how some of the issues could & should be solved (I created a list of the TODOs in the other issue) |
Hiya @jogibear9988 so it sounds like this isn't strictly blocking you. So we probably won't get to it in the first 3 months of 2024. But I've added it to the triage list so the triage team can get back to you and confirm! Really appreciate you offering to work on this! But like you said first there needs to be a consensus, and I don't think we have bandwidth to make those design decisions at the moment. |
Yeah, atm. it is workin with the dirty hacks. |
Hi @jogibear9988 unfortunately our team doesn't have the cycles right now to look at webcomponents. We love that you're willing to help with this issue though. If you'd like to put together a proposal or other information about what you'd need for webcomponents, that would be great, but we also won't have the cycles to review that kind of proposal right now either. It would be a while before we are able to review any kind of proposal and take action on it. Thanks again for your interest in this issue. For now, it's going back to our backlog. |
So I'm trying to put blockly in a webcomponent, and I'm getting
Uncaught Error: container is not in current document
. Looking at the source code, this appears to be a deliberate line inBlockly.inject()
that checks to make sure you're not using shadow-dom.what's the reason for this? is there some principled reason we shouldn't be using blockly in a webcomponent?
The text was updated successfully, but these errors were encountered: