1
0
Fork 0
mirror of synced 2024-10-03 10:36:59 +13:00

Merge pull request #344 from mjashanks/master

app preview improvements
This commit is contained in:
Michael Shanks 2020-06-09 11:50:48 +01:00 committed by GitHub
commit eea2dbf3b3
2 changed files with 108 additions and 77 deletions

View file

@ -21,14 +21,48 @@
return componentName || "element" return componentName || "element"
} }
$: iframe && const screenPlaceholder = {
console.log( name: "Screen Placeholder",
iframe.contentDocument.head.insertAdjacentHTML( route: "*",
"beforeend", props: {
`<\style></style>` _component: "@budibase/standard-components/container",
) type: "div",
) _children: [
{
_component: "@budibase/standard-components/container",
_styles: { normal: {}, hover: {}, active: {}, selected: {} },
_id: "__screenslot__text",
_code: "",
className: "",
onLoad: [],
type: "div",
_children: [
{
_component: "@budibase/standard-components/text",
_styles: {
normal: {},
hover: {},
active: {},
selected: {},
},
_id: "__screenslot__text_2",
_code: "",
text: "content",
font: "",
color: "",
textAlign: "inline",
verticalAlign: "inline",
formattingTag: "none",
},
],
},
],
},
}
$: hasComponent = !!$store.currentPreviewItem $: hasComponent = !!$store.currentPreviewItem
$: { $: {
styles = "" styles = ""
// Apply the CSS from the currently selected page and its screens // Apply the CSS from the currently selected page and its screens
@ -52,49 +86,12 @@
$: frontendDefinition = { $: frontendDefinition = {
appId: $store.appId, appId: $store.appId,
libraries: $store.libraries, libraries: $store.libraries,
page: $store.currentPreviewItem, page: $store.pages[$store.currentPageName],
screens: screensExist screens: [
? $store.currentPreviewItem._screens $store.currentFrontEndType === "page"
: [ ? screenPlaceholder
{ : $store.currentPreviewItem,
name: "Screen Placeholder", ],
route: "*",
props: {
_component: "@budibase/standard-components/container",
type: "div",
_children: [
{
_component: "@budibase/standard-components/container",
_styles: { normal: {}, hover: {}, active: {}, selected: {} },
_id: "__screenslot__text",
_code: "",
className: "",
onLoad: [],
type: "div",
_children: [
{
_component: "@budibase/standard-components/text",
_styles: {
normal: {},
hover: {},
active: {},
selected: {},
},
_id: "__screenslot__text_2",
_code: "",
text: "content",
font: "",
color: "",
textAlign: "inline",
verticalAlign: "inline",
formattingTag: "none",
},
],
},
],
},
},
],
appRootPath: "", appRootPath: "",
} }
@ -103,6 +100,22 @@
$: selectedComponentId = $store.currentComponentInfo $: selectedComponentId = $store.currentComponentInfo
? $store.currentComponentInfo._id ? $store.currentComponentInfo._id
: "" : ""
const refreshContent = () => {
iframe.contentWindow.postMessage(JSON.stringify({
styles,
stylesheetLinks,
selectedComponentType,
selectedComponentId,
frontendDefinition,
}))
}
$: if(iframe) iframe.contentWindow.addEventListener("bb-ready", refreshContent, { once: true })
$: if(iframe && frontendDefinition) {
refreshContent()
}
</script> </script>
<div class="component-container"> <div class="component-container">
@ -111,13 +124,7 @@
style="height: 100%; width: 100%" style="height: 100%; width: 100%"
title="componentPreview" title="componentPreview"
bind:this={iframe} bind:this={iframe}
srcdoc={iframeTemplate({ srcdoc={iframeTemplate} />
styles,
stylesheetLinks,
selectedComponentType,
selectedComponentId,
frontendDefinition: JSON.stringify(frontendDefinition),
})} />
{/if} {/if}
</div> </div>

View file

@ -1,20 +1,6 @@
export default ({ export default `<html>
styles,
stylesheetLinks,
selectedComponentType,
selectedComponentId,
frontendDefinition,
}) => `<html>
<head> <head>
${stylesheetLinks}
<style> <style>
${styles || ""}
.${selectedComponentType}-${selectedComponentId} {
border: 2px solid #0055ff;
}
body, html { body, html {
height: 100%!important; height: 100%!important;
font-family: Roboto !important; font-family: Roboto !important;
@ -35,12 +21,50 @@ export default ({
} }
</style> </style>
<script> <script>
window["##BUDIBASE_FRONTEND_DEFINITION##"] = ${frontendDefinition}; function receiveMessage(event) {
import('/_builder/budibase-client.esm.mjs') if (!event.data) return
.then(module => {
module.loadBudibase({ window, localStorage }); const data = JSON.parse(event.data)
})
try {
if (styles) document.head.removeChild(styles)
} catch(_) { }
try {
if (selectedComponentStyle) document.head.removeChild(selectedComponentStyle)
} catch(_) { }
selectedComponentStyle = document.createElement('style');
document.head.appendChild(selectedComponentStyle)
var selectedCss = '.' + data.selectedComponentType + '-' + data.selectedComponentId + '{ border: 2px solid #0055ff; }'
selectedComponentStyle.appendChild(document.createTextNode(selectedCss))
styles = document.createElement('style')
document.head.appendChild(styles)
styles.appendChild(document.createTextNode(data.styles))
window["##BUDIBASE_FRONTEND_DEFINITION##"] = data.frontendDefinition;
if (clientModule) {
clientModule.loadBudibase({ window, localStorage })
}
}
let clientModule
let styles
let selectedComponentStyle
document.addEventListener("click", function(e) {
e.preventDefault()
e.stopPropagation()
return false;
}, true)
import('/_builder/budibase-client.esm.mjs')
.then(module => {
clientModule = module
window.addEventListener('message', receiveMessage)
window.dispatchEvent(new Event('bb-ready'))
})
</script> </script>
</head> </head>
<body> <body>