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

86 lines
2 KiB
Svelte
Raw Normal View History

2019-08-20 08:18:23 +12:00
<script>
import { store } from "../builderStore";
import { map, join } from "lodash/fp";
import { pipe } from "../common/core";
import { buildPropsHierarchy } from "./pagesParsing/buildPropsHierarchy";
2019-09-03 21:42:19 +12:00
let iframe;
$: iframe && console.log(iframe.contentDocument.head.insertAdjacentHTML('beforeend', '<style></style>'))
$: hasComponent = !!$store.currentFrontEndItem;
$: styles = hasComponent ? $store.currentFrontEndItem._css : '';
2019-08-20 08:18:23 +12:00
$: stylesheetLinks = pipe($store.pages.stylesheets, [
2019-08-20 19:24:07 +12:00
map(s => `<link rel="stylesheet" href="${s}"/>`),
join("\n")
2019-08-27 18:32:56 +12:00
]);
$: appDefinition = {
componentLibraries: $store.loadLibraryUrls(),
props: buildPropsHierarchy(
$store.components,
$store.screens,
$store.currentFrontEndItem),
hierarchy: $store.hierarchy,
2019-11-09 21:14:10 +13:00
appRootPath: ""
2019-09-22 16:02:33 +12:00
};
2019-08-20 08:18:23 +12:00
</script>
2019-10-03 18:12:13 +13:00
<div class="component-container">
2019-10-07 18:03:41 +13:00
{#if hasComponent}
2019-10-03 18:12:13 +13:00
<iframe style="height: 100%; width: 100%"
title="componentPreview"
bind:this={iframe}
2019-10-03 18:12:13 +13:00
srcdoc={
2019-08-27 18:32:56 +12:00
`<html>
2019-08-27 18:32:56 +12:00
<head>
${stylesheetLinks}
<script>
2019-09-22 16:02:33 +12:00
window["##BUDIBASE_APPDEFINITION##"] = ${JSON.stringify(appDefinition)};
window["##BUDIBASE_UIFUNCTIONS"] = ${$store.currentScreenFunctions};
2019-11-09 21:14:10 +13:00
import('/_builder/budibase-client.esm.mjs')
2019-08-27 18:32:56 +12:00
.then(module => {
module.loadBudibase({ window, localStorage });
})
2019-08-27 18:32:56 +12:00
</script>
2019-10-03 18:12:13 +13:00
<style>
body {
box-sizing: border-box;
padding: 20px;
}
${styles}
2019-10-03 18:12:13 +13:00
</style>
2019-08-27 18:32:56 +12:00
</head>
<body>
</body>
</html>`}>
2019-10-03 18:12:13 +13:00
</iframe>
2019-10-07 18:03:41 +13:00
{/if}
2019-08-20 08:18:23 +12:00
</div>
2019-10-03 18:12:13 +13:00
2019-08-20 08:18:23 +12:00
<style>
.component-container {
grid-row-start: middle;
grid-column-start: middle;
position: relative;
overflow: hidden;
padding-top: 56.25%;
margin: auto;
}
.component-container iframe {
border: 0;
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
}
</style>