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

94 lines
1.9 KiB
Svelte
Raw Normal View History

2019-08-20 08:18:23 +12:00
<script>
import { store } from "../builderStore";
2019-08-27 18:32:56 +12:00
import { makeLibraryUrl } from "../builderStore/loadComponentLibraries";
2019-08-20 08:18:23 +12:00
import {
2019-09-22 16:02:33 +12:00
last, split, map, join
2019-08-20 08:18:23 +12:00
} from "lodash/fp";
import { pipe } from "../common/core";
import { splitName } from "./pagesParsing/splitRootComponentName"
2019-08-20 19:24:07 +12:00
import { afterUpdate } from 'svelte';
2019-09-03 21:42:19 +12:00
import { getRootComponent } from "./pagesParsing/getRootComponent";
2019-09-22 16:02:33 +12:00
import { buildPropsHierarchy } from "./pagesParsing/buildPropsHierarchy";
2019-09-03 21:42:19 +12:00
2019-08-20 08:18:23 +12:00
2019-10-07 18:03:41 +13:00
let hasComponent=false;
2019-08-20 19:24:07 +12:00
let stylesheetLinks = "";
2019-09-22 16:02:33 +12:00
let appDefinition = {};
2019-08-20 08:18:23 +12:00
store.subscribe(s => {
2019-10-07 18:03:41 +13:00
hasComponent = !!s.currentFrontEndItem;
2019-08-20 19:24:07 +12:00
stylesheetLinks = pipe(s.pages.stylesheets, [
map(s => `<link rel="stylesheet" href="${s}"/>`),
join("\n")
2019-08-27 18:32:56 +12:00
]);
2019-09-22 16:02:33 +12:00
appDefinition = {
componentLibraries: s.loadLibraryUrls(),
props: buildPropsHierarchy(
s.components,
s.screens,
s.currentFrontEndItem),
2019-11-09 21:14:10 +13:00
hierarchy: s.hierarchy,
appRootPath: ""
2019-09-22 16:02:33 +12:00
};
2019-10-07 18:03:41 +13:00
2019-08-20 08:18:23 +12:00
});
2019-08-20 19:24:07 +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"
srcdoc={
2019-08-27 18:32:56 +12:00
`<html>
<head>
${stylesheetLinks}
<script>
2019-09-22 16:02:33 +12:00
window["##BUDIBASE_APPDEFINITION##"] = ${JSON.stringify(appDefinition)};
2019-11-09 21:14:10 +13:00
import('/_builder/budibase-client.esm.mjs')
2019-08-27 18:32:56 +12:00
.then(module => {
2019-09-22 16:02:33 +12:00
module.loadBudibase();
})
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;
}
</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;
2019-10-03 18:12:13 +13:00
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%;
2019-08-20 08:18:23 +12:00
}
</style>