|
|
@ -21,42 +21,7 @@ |
|
|
return componentName || "element" |
|
|
return componentName || "element" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$: iframe && |
|
|
const screenPlaceholder = { |
|
|
console.log( |
|
|
|
|
|
iframe.contentDocument.head.insertAdjacentHTML( |
|
|
|
|
|
"beforeend", |
|
|
|
|
|
`<\style></style>` |
|
|
|
|
|
) |
|
|
|
|
|
) |
|
|
|
|
|
$: hasComponent = !!$store.currentPreviewItem |
|
|
|
|
|
$: { |
|
|
|
|
|
styles = "" |
|
|
|
|
|
// Apply the CSS from the currently selected page and its screens |
|
|
|
|
|
const currentPage = $store.pages[$store.currentPageName] |
|
|
|
|
|
styles += currentPage._css |
|
|
|
|
|
for (let screen of currentPage._screens) { |
|
|
|
|
|
styles += screen._css |
|
|
|
|
|
} |
|
|
|
|
|
styles = styles |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$: stylesheetLinks = pipe($store.pages.stylesheets, [ |
|
|
|
|
|
map(s => `<link rel="stylesheet" href="${s}"/>`), |
|
|
|
|
|
join("\n"), |
|
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
$: screensExist = |
|
|
|
|
|
$store.currentPreviewItem._screens && |
|
|
|
|
|
$store.currentPreviewItem._screens.length > 0 |
|
|
|
|
|
|
|
|
|
|
|
$: frontendDefinition = { |
|
|
|
|
|
appId: $store.appId, |
|
|
|
|
|
libraries: $store.libraries, |
|
|
|
|
|
page: $store.currentPreviewItem, |
|
|
|
|
|
screens: screensExist |
|
|
|
|
|
? $store.currentPreviewItem._screens |
|
|
|
|
|
: [ |
|
|
|
|
|
{ |
|
|
|
|
|
name: "Screen Placeholder", |
|
|
name: "Screen Placeholder", |
|
|
route: "*", |
|
|
route: "*", |
|
|
props: { |
|
|
props: { |
|
|
@ -93,7 +58,39 @@ |
|
|
}, |
|
|
}, |
|
|
], |
|
|
], |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$: hasComponent = !!$store.currentPreviewItem |
|
|
|
|
|
|
|
|
|
|
|
$: { |
|
|
|
|
|
styles = "" |
|
|
|
|
|
// Apply the CSS from the currently selected page and its screens |
|
|
|
|
|
const currentPage = $store.pages[$store.currentPageName] |
|
|
|
|
|
styles += currentPage._css |
|
|
|
|
|
for (let screen of currentPage._screens) { |
|
|
|
|
|
styles += screen._css |
|
|
|
|
|
} |
|
|
|
|
|
styles = styles |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$: stylesheetLinks = pipe($store.pages.stylesheets, [ |
|
|
|
|
|
map(s => `<link rel="stylesheet" href="${s}"/>`), |
|
|
|
|
|
join("\n"), |
|
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
$: screensExist = |
|
|
|
|
|
$store.currentPreviewItem._screens && |
|
|
|
|
|
$store.currentPreviewItem._screens.length > 0 |
|
|
|
|
|
|
|
|
|
|
|
$: frontendDefinition = { |
|
|
|
|
|
appId: $store.appId, |
|
|
|
|
|
libraries: $store.libraries, |
|
|
|
|
|
page: $store.pages[$store.currentPageName], |
|
|
|
|
|
screens: [ |
|
|
|
|
|
$store.currentFrontEndType === "page" |
|
|
|
|
|
? screenPlaceholder |
|
|
|
|
|
: $store.currentPreviewItem, |
|
|
], |
|
|
], |
|
|
appRootPath: "", |
|
|
appRootPath: "", |
|
|
} |
|
|
} |
|
|
@ -103,6 +100,22 @@ |
|
|
$: selectedComponentId = $store.currentComponentInfo |
|
|
$: selectedComponentId = $store.currentComponentInfo |
|
|
? $store.currentComponentInfo._id |
|
|
? $store.currentComponentInfo._id |
|
|
: "" |
|
|
: "" |
|
|
|
|
|
|
|
|
|
|
|
const refreshContent = () => { |
|
|
|
|
|
iframe.contentWindow.postMessage(JSON.stringify({ |
|
|
|
|
|
styles, |
|
|
|
|
|
stylesheetLinks, |
|
|
|
|
|
selectedComponentType, |
|
|
|
|
|
selectedComponentId, |
|
|
|
|
|
frontendDefinition, |
|
|
|
|
|
})) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$: if(iframe) iframe.contentWindow.addEventListener("bb-ready", refreshContent, { once: true }) |
|
|
|
|
|
|
|
|
|
|
|
$: if(iframe && frontendDefinition) { |
|
|
|
|
|
refreshContent() |
|
|
|
|
|
} |
|
|
</script> |
|
|
</script> |
|
|
|
|
|
|
|
|
<div class="component-container"> |
|
|
<div class="component-container"> |
|
|
@ -111,13 +124,7 @@ |
|
|
style="height: 100%; width: 100%" |
|
|
style="height: 100%; width: 100%" |
|
|
title="componentPreview" |
|
|
title="componentPreview" |
|
|
bind:this={iframe} |
|
|
bind:this={iframe} |
|
|
srcdoc={iframeTemplate({ |
|
|
srcdoc={iframeTemplate} /> |
|
|
styles, |
|
|
|
|
|
stylesheetLinks, |
|
|
|
|
|
selectedComponentType, |
|
|
|
|
|
selectedComponentId, |
|
|
|
|
|
frontendDefinition: JSON.stringify(frontendDefinition), |
|
|
|
|
|
})} /> |
|
|
|
|
|
{/if} |
|
|
{/if} |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
|
|
|
|