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

81 lines
2 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
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>
<div class="component-preview" >
<div class="component-container">
2019-09-22 16:02:33 +12:00
<iframe style="height: 100%; width: 100%"
2019-08-27 18:32:56 +12:00
title="componentPreview"
srcdoc={
`<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>
</head>
<body>
</body>
</html>`}>
2019-08-20 08:18:23 +12:00
</iframe>
</div>
</div>
<style>
.component-preview {
display: grid;
grid-template-rows: [top] 1fr [middle] auto [bottom] 1fr;
grid-template-columns: [left] 1fr [middle] auto [right] 1fr;
grid-column-start: preview;
height:100%;
}
.component-container {
grid-row-start: middle;
grid-column-start: middle;
}
</style>