2019-08-20 08:18:23 +12:00
|
|
|
<script>
|
2020-04-01 00:16:03 +13:00
|
|
|
import { store, backendUiStore } from "builderStore"
|
2020-02-12 05:36:16 +13:00
|
|
|
import { map, join } from "lodash/fp"
|
2020-05-03 22:33:20 +12:00
|
|
|
import iframeTemplate from "./iframeTemplate";
|
2020-04-01 00:16:03 +13:00
|
|
|
import { pipe } from "components/common/core"
|
2019-09-03 21:42:19 +12:00
|
|
|
|
2020-02-12 05:36:16 +13:00
|
|
|
let iframe
|
2020-05-06 21:33:30 +12:00
|
|
|
let styles = ""
|
2020-02-01 05:01:58 +13:00
|
|
|
|
2020-02-12 05:36:16 +13:00
|
|
|
function transform_component(comp) {
|
|
|
|
const props = comp.props || comp
|
|
|
|
if (props && props._children && props._children.length) {
|
|
|
|
props._children = props._children.map(transform_component)
|
|
|
|
}
|
2020-01-29 10:17:04 +13:00
|
|
|
|
2020-02-12 05:36:16 +13:00
|
|
|
return props
|
|
|
|
}
|
2020-02-11 10:35:51 +13:00
|
|
|
|
2020-02-12 05:36:16 +13:00
|
|
|
$: iframe &&
|
|
|
|
console.log(
|
|
|
|
iframe.contentDocument.head.insertAdjacentHTML(
|
|
|
|
"beforeend",
|
|
|
|
`<\style></style>`
|
|
|
|
)
|
|
|
|
)
|
|
|
|
$: hasComponent = !!$store.currentPreviewItem
|
2020-05-06 21:33:30 +12:00
|
|
|
$: {
|
|
|
|
// 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
|
|
|
|
}
|
2019-08-20 08:18:23 +12:00
|
|
|
|
2020-02-12 05:36:16 +13:00
|
|
|
$: stylesheetLinks = pipe(
|
|
|
|
$store.pages.stylesheets,
|
|
|
|
[map(s => `<link rel="stylesheet" href="${s}"/>`), join("\n")]
|
|
|
|
)
|
2020-02-11 05:58:20 +13:00
|
|
|
|
2020-04-07 04:06:04 +12:00
|
|
|
$: screensExist = $store.currentPreviewItem._screens && $store.currentPreviewItem._screens.length > 0
|
|
|
|
|
2020-02-12 05:36:16 +13:00
|
|
|
$: frontendDefinition = {
|
2020-05-03 02:29:10 +12:00
|
|
|
libraries: $store.libraries,
|
2020-02-12 05:36:16 +13:00
|
|
|
page: $store.currentPreviewItem,
|
2020-04-07 04:06:04 +12:00
|
|
|
screens: screensExist ? $store.currentPreviewItem._screens : [{
|
2020-02-19 04:53:22 +13:00
|
|
|
name: "Screen Placeholder",
|
|
|
|
route: "*",
|
|
|
|
props: {
|
|
|
|
_component: "@budibase/standard-components/container",
|
|
|
|
type: "div",
|
|
|
|
_children: [
|
|
|
|
{
|
|
|
|
_component: "@budibase/standard-components/container",
|
|
|
|
_styles: { "position": {},"layout": {} },
|
|
|
|
_id: "__screenslot__text",
|
|
|
|
_code: "",
|
|
|
|
className: "",
|
|
|
|
onLoad: [],
|
|
|
|
type: "div",
|
|
|
|
_children: [{
|
|
|
|
_component:"@budibase/standard-components/text",
|
|
|
|
_styles: { "position": {}, "layout": {} },
|
2020-02-19 06:00:56 +13:00
|
|
|
_id: "__screenslot__text_2",
|
2020-02-19 04:53:22 +13:00
|
|
|
_code: "",
|
|
|
|
text: "content",
|
|
|
|
font: "",
|
|
|
|
color: "",
|
|
|
|
textAlign: "inline",
|
|
|
|
verticalAlign: "inline",
|
|
|
|
formattingTag: "none"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}],
|
2020-05-06 21:33:30 +12:00
|
|
|
appRootPath: `/`,
|
2020-02-12 05:36:16 +13:00
|
|
|
}
|
|
|
|
|
2020-02-22 07:06:23 +13:00
|
|
|
$: selectedComponentId = $store.currentComponentInfo ? $store.currentComponentInfo._id : ""
|
2020-02-12 05:36:16 +13:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="component-container">
|
|
|
|
{#if hasComponent && $store.currentPreviewItem}
|
|
|
|
<iframe
|
|
|
|
style="height: 100%; width: 100%"
|
|
|
|
title="componentPreview"
|
|
|
|
bind:this={iframe}
|
2020-05-03 22:33:20 +12:00
|
|
|
srcdoc={iframeTemplate({
|
|
|
|
styles,
|
|
|
|
stylesheetLinks,
|
|
|
|
selectedComponentId,
|
|
|
|
frontendDefinition: JSON.stringify(frontendDefinition),
|
|
|
|
currentPageFunctions: $store.currentPageFunctions
|
|
|
|
})} />
|
2020-02-12 05:36:16 +13:00
|
|
|
{/if}
|
2019-08-20 08:18:23 +12:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
2020-02-12 05:36:16 +13:00
|
|
|
.component-container {
|
|
|
|
grid-row-start: middle;
|
|
|
|
grid-column-start: middle;
|
|
|
|
position: relative;
|
|
|
|
overflow: hidden;
|
|
|
|
margin: auto;
|
2020-04-24 21:35:54 +12:00
|
|
|
height: 100%;
|
2020-02-12 05:36:16 +13:00
|
|
|
}
|
2020-01-29 10:17:04 +13:00
|
|
|
|
2020-02-12 05:36:16 +13:00
|
|
|
.component-container iframe {
|
|
|
|
border: 0;
|
|
|
|
left: 0;
|
|
|
|
top: 0;
|
|
|
|
width: 100%;
|
|
|
|
}
|
2020-02-19 04:53:22 +13:00
|
|
|
</style>
|