1
0
Fork 0
mirror of synced 2024-07-01 12:30:41 +12:00
budibase/packages/builder/src/userInterface/CurrentItemPreview.svelte

96 lines
2.1 KiB
Svelte
Raw Normal View History

2019-08-20 08:18:23 +12:00
<script>
2020-02-03 22:50:30 +13:00
import { store } from "../builderStore"
import { map, join } from "lodash/fp"
import { pipe } from "../common/core"
2019-09-03 21:42:19 +12:00
2020-02-03 22:50:30 +13:00
let iframe
function transform_component(comp) {
const props = comp.props || comp
if (props && props._children && props._children.length) {
props._children = props._children.map(transform_component)
}
return props
}
2020-02-03 22:50:30 +13:00
$: iframe &&
console.log(
iframe.contentDocument.head.insertAdjacentHTML(
"beforeend",
`<\style></style>`
2020-02-03 22:50:30 +13:00
)
)
$: hasComponent = !!$store.currentPreviewItem
$: styles = hasComponent ? $store.currentPreviewItem._css : ""
2019-08-20 08:18:23 +12:00
$: stylesheetLinks = pipe(
$store.pages.stylesheets,
[map(s => `<link rel="stylesheet" href="${s}"/>`), join("\n")]
)
$: frontendDefinition = {
2020-02-03 22:50:30 +13:00
componentLibraries: $store.loadLibraryUrls(),
page: $store.currentPreviewItem,
screens: [],
2020-02-03 22:50:30 +13:00
appRootPath: "",
}
$: backendDefinition = {
hierarchy: $store.hierarchy,
}
2019-08-20 08:18:23 +12:00
</script>
2019-10-03 18:12:13 +13:00
<div class="component-container">
{#if hasComponent && $store.currentPreviewItem}
2020-02-03 22:50:30 +13:00
<iframe
style="height: 100%; width: 100%"
title="componentPreview"
bind:this={iframe}
srcdoc={`<html>
<head>
2019-08-27 18:32:56 +12:00
${stylesheetLinks}
<style>
${styles || ''}
body, html {
height: 100%!important;
}
<\/style>
<\script>
window["##BUDIBASE_FRONTEND_DEFINITION##"] = ${JSON.stringify(frontendDefinition)};
window["##BUDIBASE_BACKEND_DEFINITION##"] = ${JSON.stringify(backendDefinition)};
window["##BUDIBASE_FRONTEND_FUNCTIONS##"] = ${$store.currentScreenFunctions};
import('/_builder/budibase-client.esm.mjs')
.then(module => {
module.loadBudibase({ window, localStorage });
})
<\/script>
</head>
<body>
</body>
2020-02-03 22:50:30 +13:00
</html>`} />
{/if}
2019-08-20 08:18:23 +12:00
</div>
<style>
2020-02-03 22:50:30 +13:00
.component-container {
grid-row-start: middle;
grid-column-start: middle;
position: relative;
overflow: hidden;
padding-top: 56.25%;
margin: auto;
}
2020-02-03 22:50:30 +13:00
.component-container iframe {
border: 0;
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
}
</style>