Merge pull request #109 from pngwn/98-builtin-slot

98 builtin slot
This commit is contained in:
Michael Shanks 2020-02-18 17:14:34 +00:00 committed by GitHub
commit 57e7a3a768
8 changed files with 92 additions and 32 deletions

File diff suppressed because one or more lines are too long

View File

@ -30,6 +30,7 @@ import {
getNewScreen, getNewScreen,
createProps, createProps,
makePropsSafe, makePropsSafe,
getBuiltin,
} from "../userInterface/pagesParsing/createProps" } from "../userInterface/pagesParsing/createProps"
import { expandComponentDefinition } from "../userInterface/pagesParsing/types" import { expandComponentDefinition } from "../userInterface/pagesParsing/types"
import { import {
@ -158,6 +159,7 @@ const initialise = (store, initial) => async () => {
} }
initial.libraries = await loadLibs(appname, pkg) initial.libraries = await loadLibs(appname, pkg)
initial.generatorLibraries = await loadGeneratorLibs(appname, pkg) initial.generatorLibraries = await loadGeneratorLibs(appname, pkg)
initial.loadLibraryUrls = () => loadLibUrls(appname, pkg) initial.loadLibraryUrls = () => loadLibUrls(appname, pkg)
initial.appname = appname initial.appname = appname
@ -170,6 +172,7 @@ const initialise = (store, initial) => async () => {
initial.components = values(pkg.components.components).map( initial.components = values(pkg.components.components).map(
expandComponentDefinition expandComponentDefinition
) )
initial.builtins = [getBuiltin("##builtin/screenslot")]
initial.actions = values(pkg.appDefinition.actions) initial.actions = values(pkg.appDefinition.actions)
initial.triggers = pkg.appDefinition.triggers initial.triggers = pkg.appDefinition.triggers
@ -181,7 +184,6 @@ const initialise = (store, initial) => async () => {
} }
store.set(initial) store.set(initial)
return initial return initial
} }
@ -743,12 +745,15 @@ const setCurrentPage = store => pageName => {
}) })
} }
const getContainerComponent = components => const getContainerComponent = components =>
components.find(c => c.name === "@budibase/standard-components/container") components.find(c => c.name === "@budibase/standard-components/container")
const addChildComponent = store => componentName => { const addChildComponent = store => componentName => {
store.update(s => { store.update(s => {
const component = s.components.find(c => c.name === componentName) const component = componentName.startsWith("##")
? getBuiltin(componentName)
: s.components.find(c => c.name === componentName)
const newComponent = createProps(component) const newComponent = createProps(component)
s.currentComponentInfo._children = s.currentComponentInfo._children.concat( s.currentComponentInfo._children = s.currentComponentInfo._children.concat(
@ -756,14 +761,15 @@ const addChildComponent = store => componentName => {
) )
_savePage(s) _savePage(s)
return s return s
}) })
} }
const selectComponent = store => component => { const selectComponent = store => component => {
store.update(s => { store.update(s => {
const componentDef = s.components.find(c => c.name === component._component) const componentDef = component._component.startsWith("##")
? component
: s.components.find(c => c.name === component._component)
s.currentComponentInfo = makePropsSafe(componentDef, component) s.currentComponentInfo = makePropsSafe(componentDef, component)
return s return s
}) })

View File

@ -42,6 +42,7 @@
<LayoutIcon /> <LayoutIcon />
</button> </button>
</li> </li>
{#if !component._component.startsWith('##')}
<li> <li>
<button <button
class:selected={current_view === 'code'} class:selected={current_view === 'code'}
@ -61,9 +62,9 @@
<EventsIcon /> <EventsIcon />
</button> </button>
</li> </li>
{/if}
</ul> </ul>
{$store.currentFrontEndType} {$store.currentFrontEndType}
<div class="component-props-container"> <div class="component-props-container">
{#if current_view === 'props'} {#if current_view === 'props'}
@ -81,8 +82,6 @@
</div> </div>
</div> </div>
<style> <style>

View File

@ -66,7 +66,7 @@
</li> </li>
</ul> </ul>
{#each lib.components.filter(_ => true) as component} {#each $store.builtins.concat(lib.components.filter(_ => true)) as component}
<div <div
class="component" class="component"
on:click={() => onComponentChosen(component.name)}> on:click={() => onComponentChosen(component.name)}>

View File

@ -32,7 +32,37 @@
$: frontendDefinition = { $: frontendDefinition = {
componentLibraries: $store.loadLibraryUrls(), componentLibraries: $store.loadLibraryUrls(),
page: $store.currentPreviewItem, page: $store.currentPreviewItem,
screens: [], screens: [{
name: "Screen Placeholder",
route: "*",
props: {
_component: "@budibase/standard-components/container",
type: "div",
_children: [
{
_component: "@budibase/standard-components/container",
_styles: { "position": {},"layout": {} },
_id: "__screenslot__text",
_code: "",
className: "",
onLoad: [],
type: "div",
_children: [{
_component:"@budibase/standard-components/text",
_styles: { "position": {}, "layout": {} },
_id: "__screenslot__text_2",
_code: "",
text: "content",
font: "",
color: "",
textAlign: "inline",
verticalAlign: "inline",
formattingTag: "none"
}]
}
]
}
}],
appRootPath: "", appRootPath: "",
} }
@ -51,11 +81,26 @@
srcdoc={`<html> srcdoc={`<html>
<head> <head>
${stylesheetLinks} ${stylesheetLinks}
<style> <style>
${styles || ''} ${styles || ''}
body, html { body, html {
height: 100%!important; height: 100%!important;
} }
.lay-__screenslot__text {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
padding: 20px 0;
border: dashed 2px #ccc;
font-family: sans-serif;
font-size: 1.2rem;
color: #999;
text-transform: uppercase;
font-weight: bold;
}
<\/style> <\/style>
<\script> <\script>
window["##BUDIBASE_FRONTEND_DEFINITION##"] = ${JSON.stringify(frontendDefinition)}; window["##BUDIBASE_FRONTEND_DEFINITION##"] = ${JSON.stringify(frontendDefinition)};

View File

@ -3,6 +3,15 @@ import { types } from "./types"
import { assign } from "lodash" import { assign } from "lodash"
import { uuid } from "../../builderStore/uuid" import { uuid } from "../../builderStore/uuid"
export const getBuiltin = name => {
const { props } = createProps({ name })
return {
name,
props,
}
}
export const getNewScreen = (components, rootComponentName, name) => { export const getNewScreen = (components, rootComponentName, name) => {
const rootComponent = components.find(c => c.name === rootComponentName) const rootComponent = components.find(c => c.name === rootComponentName)
return { return {

View File

@ -9,6 +9,7 @@ export const screenRouter = (screens, onScreenSelected) => {
let current let current
function route(url) { function route(url) {
const _url = url.state || url const _url = url.state || url
current = routes.findIndex( current = routes.findIndex(
p => p !== "*" && new RegExp("^" + p + "$").test(_url) p => p !== "*" && new RegExp("^" + p + "$").test(_url)
@ -38,7 +39,7 @@ export const screenRouter = (screens, onScreenSelected) => {
if (current !== -1) { if (current !== -1) {
onScreenSelected(screens[current], store, _url) onScreenSelected(screens[current], store, _url)
} else if (fallback) { } else {
onScreenSelected(screens[fallback], store, _url) onScreenSelected(screens[fallback], store, _url)
} }

File diff suppressed because one or more lines are too long