Rebuilt frontmatter templates as template widgets

This commit is contained in:
Zef Hemel
2024-01-08 17:08:35 +01:00
parent 5b3dd500e4
commit 848e11a773
45 changed files with 471 additions and 483 deletions
+23 -21
View File
@@ -104,7 +104,7 @@ export function mountIFrame(
preloadedIFrame: PreloadedIFrame,
client: Client,
widgetHeightCacheKey: string | null,
content: WidgetContent | Promise<WidgetContent>,
content: WidgetContent | null | Promise<WidgetContent | null>,
onMessage?: (message: any) => void,
) {
const iframe = preloadedIFrame.iframe;
@@ -174,26 +174,28 @@ export function mountIFrame(
console.warn("Iframe went away or content was not loaded");
return;
}
if (resolvedContent.html) {
iframe.contentWindow!.postMessage({
type: "html",
html: resolvedContent.html,
script: resolvedContent.script,
theme: document.getElementsByTagName("html")[0].dataset.theme,
});
} else if (resolvedContent.url) {
iframe.contentWindow!.location.href = resolvedContent.url;
if (resolvedContent.height) {
iframe.height = resolvedContent.height + "px";
if (widgetHeightCacheKey) {
client.setCachedWidgetHeight(
widgetHeightCacheKey!,
resolvedContent.height,
);
if (resolvedContent) {
if (resolvedContent.html) {
iframe.contentWindow!.postMessage({
type: "html",
html: resolvedContent.html,
script: resolvedContent.script,
theme: document.getElementsByTagName("html")[0].dataset.theme,
});
} else if (resolvedContent.url) {
iframe.contentWindow!.location.href = resolvedContent.url;
if (resolvedContent.height) {
iframe.height = resolvedContent.height + "px";
if (widgetHeightCacheKey) {
client.setCachedWidgetHeight(
widgetHeightCacheKey!,
resolvedContent.height,
);
}
}
if (resolvedContent.width) {
iframe.width = resolvedContent.width + "px";
}
}
if (resolvedContent.width) {
iframe.width = resolvedContent.width + "px";
}
}
}).catch(console.error);
@@ -202,7 +204,7 @@ export function mountIFrame(
export function createWidgetSandboxIFrame(
client: Client,
widgetHeightCacheKey: string | null,
content: WidgetContent | Promise<WidgetContent>,
content: WidgetContent | null | Promise<WidgetContent | null>,
onMessage?: (message: any) => void,
) {
// console.log("Claiming iframe");