Skip to content
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

Add supports for shadow DOM #435

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/sprotty/src/base/views/viewer-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export interface ViewerOptions {
hiddenDiv: string
/** CSS class added to the base element of the hidden rendering. */
hiddenClass: string
/** ID of the HTML element holding the shadow root. */
spoenemann marked this conversation as resolved.
Show resolved Hide resolved
shadowRoot?: string
/** ID of the HTML element into which hover popup boxes are rendered. */
popupDiv: string
/** CSS class added to the base element of popup boxes. */
Expand Down
10 changes: 9 additions & 1 deletion packages/sprotty/src/base/views/viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,15 @@ export class ModelViewer implements IViewer {
this.lastVDOM = this.patcher.call(this, this.lastVDOM, newVDOM);
this.restoreFocus(hadFocus);
} else if (typeof document !== 'undefined') {
const placeholder = document.getElementById(this.options.baseDiv);
let placeholder = null;
if (this.options.shadowRoot) {
const shadowRoot = document.getElementById(this.options.shadowRoot)?.shadowRoot;
if (shadowRoot) {
placeholder = shadowRoot.getElementById(this.options.baseDiv);
}
} else {
placeholder = document.getElementById(this.options.baseDiv);
}
if (placeholder !== null) {
if (typeof window !== 'undefined') {
window.addEventListener('resize', () => {
Expand Down
Loading