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
|
|
|
|
|
|
|
let component;
|
2019-08-20 19:24:07 +12:00
|
|
|
let stylesheetLinks = "";
|
2019-08-27 18:32:56 +12:00
|
|
|
let rootComponentName = "";
|
2019-09-03 21:42:19 +12:00
|
|
|
let libraries;
|
|
|
|
let allComponents;
|
2019-09-22 16:02:33 +12:00
|
|
|
let appDefinition = {};
|
2019-08-20 08:18:23 +12:00
|
|
|
|
|
|
|
store.subscribe(s => {
|
|
|
|
const {componentName, libName} = splitName(
|
|
|
|
s.currentComponentInfo.rootComponent.name);
|
|
|
|
|
2019-08-27 18:32:56 +12:00
|
|
|
rootComponentName = componentName;
|
2019-08-20 08:18:23 +12:00
|
|
|
component = s.libraries[libName][componentName];
|
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.allComponents, s.currentFrontEndItem)
|
|
|
|
};
|
2019-09-03 21:42:19 +12:00
|
|
|
libraries = s.libraries;
|
|
|
|
allComponents = s.allComponents;
|
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">
|
|
|
|
<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)};
|
|
|
|
import('./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-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>
|