1
0
Fork 0
mirror of synced 2024-06-29 11:31:06 +12:00
budibase/packages/builder/src/components/userInterface/CurrentItemPreview.svelte

149 lines
3.8 KiB
Svelte
Raw Normal View History

2019-08-20 08:18:23 +12:00
<script>
import { store, backendUiStore } from "builderStore"
2020-02-12 05:36:16 +13:00
import { map, join } from "lodash/fp"
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-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-02-12 05:36:16 +13:00
return props
}
2020-02-12 05:36:16 +13:00
$: iframe &&
console.log(
iframe.contentDocument.head.insertAdjacentHTML(
"beforeend",
`<\style></style>`
)
)
$: hasComponent = !!$store.currentPreviewItem
$: styles = hasComponent ? $store.currentPreviewItem._css : ""
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 = {
componentLibraries: $store.loadLibraryUrls($store.currentPageName),
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": {} },
_id: "__screenslot__text_2",
2020-02-19 04:53:22 +13:00
_code: "",
text: "content",
font: "",
color: "",
textAlign: "inline",
verticalAlign: "inline",
formattingTag: "none"
}]
}
]
}
}],
appRootPath: `/_builder/instance/${$store.appname}/${$backendUiStore.selectedDatabase.id}/`,
2020-02-12 05:36:16 +13:00
}
$: backendDefinition = {
hierarchy: $store.hierarchy,
}
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}
srcdoc={`<html>
<head>
2020-02-11 05:58:20 +13:00
${stylesheetLinks}
2020-02-12 05:36:16 +13:00
<style>
${styles || ''}
2020-02-21 09:19:24 +13:00
.pos-${selectedComponentId} {
border: 2px solid #0055ff;
2020-02-21 09:19:24 +13:00
}
2020-02-12 05:36:16 +13:00
body, html {
height: 100%!important;
}
.lay-__screenslot__text {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
padding: 20px 0;
border: dashed 2px #ccc;
font-family: sans-serif;
font-size: 1.2rem;
color: #999;
text-transform: uppercase;
font-weight: bold;
}
2020-02-12 05:36:16 +13:00
<\/style>
<\script>
window["##BUDIBASE_FRONTEND_DEFINITION##"] = ${JSON.stringify(frontendDefinition)};
window["##BUDIBASE_BACKEND_DEFINITION##"] = ${JSON.stringify(backendDefinition)};
window["##BUDIBASE_FRONTEND_FUNCTIONS##"] = ${$store.currentPageFunctions};
2020-02-12 05:36:16 +13:00
import('/_builder/budibase-client.esm.mjs')
.then(module => {
module.loadBudibase({ window, localStorage });
})
2020-02-12 05:36:16 +13:00
<\/script>
</head>
<body>
</body>
</html>`} />
{/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;
padding-top: 56.25%;
margin: auto;
}
2020-02-12 05:36:16 +13:00
.component-container iframe {
border: 0;
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
}
2020-02-19 04:53:22 +13:00
</style>