Fixes the white flash for widget iframes & Make use of panel api (#882)
* Fix widget iframes flashing when loading * Set the data-theme attribute for all panelspull/887/head
parent
ff923b8718
commit
892849c30b
|
@ -26,8 +26,6 @@ export async function updateMarkdownPreview() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const customStyles = await editor.getUiOption("customStyles");
|
const customStyles = await editor.getUiOption("customStyles");
|
||||||
const darkMode = await clientStore.get("darkMode");
|
|
||||||
const theme = darkMode ? "dark" : "light";
|
|
||||||
await editor.showPanel(
|
await editor.showPanel(
|
||||||
"rhs",
|
"rhs",
|
||||||
2,
|
2,
|
||||||
|
@ -40,11 +38,7 @@ export async function updateMarkdownPreview() {
|
||||||
|
|
||||||
<div id="root" class="sb-preview">${html}</div>
|
<div id="root" class="sb-preview">${html}</div>
|
||||||
`,
|
`,
|
||||||
`
|
js,
|
||||||
document.documentElement.dataset.theme = ${JSON.stringify(theme)};
|
|
||||||
|
|
||||||
${js}
|
|
||||||
`,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ export function Panel({
|
||||||
type: "html",
|
type: "html",
|
||||||
html: config.html,
|
html: config.html,
|
||||||
script: config.script,
|
script: config.script,
|
||||||
|
theme: document.getElementsByTagName("html")[0].dataset.theme
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,10 +52,12 @@ export function prepareSandboxIFrame(): PreloadedIFrame {
|
||||||
// Empty page with current origin. Handled this differently before, but "dock apps" in Safari (PWA implementation) seem to have various restrictions
|
// Empty page with current origin. Handled this differently before, but "dock apps" in Safari (PWA implementation) seem to have various restrictions
|
||||||
// This one works in all browsers, although it's probably less secure
|
// This one works in all browsers, although it's probably less secure
|
||||||
iframe.src = "about:blank";
|
iframe.src = "about:blank";
|
||||||
|
iframe.style.visibility = "hidden";
|
||||||
|
|
||||||
const ready = new Promise<void>((resolve) => {
|
const ready = new Promise<void>((resolve) => {
|
||||||
iframe.onload = () => {
|
iframe.onload = () => {
|
||||||
iframe.contentDocument!.write(panelHtml);
|
iframe.contentDocument!.write(panelHtml);
|
||||||
|
iframe.style.visibility = "visible";
|
||||||
// Now ready to use
|
// Now ready to use
|
||||||
resolve();
|
resolve();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue