Skip to content

Commit

Permalink
Add supports for shadow DOM
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Fontorbe <guillaume.fontorbe@typefox.io>
  • Loading branch information
gfontorbe committed Feb 21, 2024
1 parent c0e7745 commit 91fdf57
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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 @@ -29,6 +29,8 @@ export interface ViewerOptions {
/** CSS class added to the base element of the hidden rendering. */
hiddenClass: string
/** ID of the HTML element into which hover popup boxes are rendered. */
shadowRoot?: string
/** ID of the HTML element holding the shadow root. */
popupDiv: string
/** CSS class added to the base element of popup boxes. */
popupClass: string
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

0 comments on commit 91fdf57

Please sign in to comment.