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

80 lines
1.7 KiB
Svelte
Raw Normal View History

2019-08-20 08:18:23 +12:00
<script>
import { store } from "../builderStore";
import {
last,
2019-08-20 19:24:07 +12:00
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-08-20 08:18:23 +12:00
let component;
2019-08-20 19:24:07 +12:00
let stylesheetLinks = "";
let componentHtml = "";
2019-08-22 18:57:56 +12:00
let props;
2019-08-20 08:18:23 +12:00
store.subscribe(s => {
const {componentName, libName} = splitName(
s.currentComponentInfo.rootComponent.name);
2019-08-22 18:57:56 +12:00
props = s.currentComponentInfo.fullProps;
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-20 08:18:23 +12:00
});
2019-08-20 19:24:07 +12:00
afterUpdate(() => {
2019-08-22 18:57:56 +12:00
setTimeout(() => {
componentHtml = document.getElementById("comonent-container-mock").innerHTML
}, 1);
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-08-20 19:24:07 +12:00
<iframe title="componentPreview"
srcdoc={`<html>
2019-08-20 08:18:23 +12:00
<head>
2019-08-20 19:24:07 +12:00
${stylesheetLinks}
2019-08-20 08:18:23 +12:00
</head>
<body>
2019-08-20 19:24:07 +12:00
${componentHtml}
2019-08-20 08:18:23 +12:00
</body>
2019-08-20 19:24:07 +12:00
</html>`}>
2019-08-20 08:18:23 +12:00
</iframe>
</div>
</div>
2019-08-20 19:24:07 +12:00
<div id="comonent-container-mock">
2019-08-22 18:57:56 +12:00
<svelte:component this={component} {...props}/>
2019-08-20 19:24:07 +12:00
</div>
2019-08-20 08:18:23 +12:00
<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;
}
2019-08-20 19:24:07 +12:00
#comonent-container-mock {
position:fixed;
left: -2000px
}
2019-08-20 08:18:23 +12:00
</style>