1
0
Fork 0
mirror of synced 2024-07-10 00:35:57 +12:00

Merge pull request #125 from mjashanks/master

Bugfixing
This commit is contained in:
Michael Shanks 2020-02-24 16:09:10 +00:00 committed by GitHub
commit d988922bda
17 changed files with 69 additions and 45 deletions

View file

@ -23,7 +23,7 @@ export const buildCodeForScreens = screens => {
allfunctions += buildCodeForSingleScreen(screen) allfunctions += buildCodeForSingleScreen(screen)
} }
return `return ({ ${allfunctions} });` return `({ ${allfunctions} });`
} }
const buildComponentCode = componentProps => const buildComponentCode = componentProps =>

View file

@ -12,6 +12,6 @@ export const insertCodeMetadata = props => {
const codeMetaData = code => { const codeMetaData = code => {
return { return {
dependsOnStore: RegExp(/(store.)/g).test(code), dependsOnStore: RegExp(/(state.)/g).test(code),
} }
} }

View file

@ -517,7 +517,7 @@ const setCurrentScreen = store => screenName => {
getContainerComponent(s.components), getContainerComponent(s.components),
screen.props screen.props
) )
setCurrentScreenFunctions(s) setCurrentPageFunctions(s)
return s return s
}) })
} }
@ -675,7 +675,7 @@ const _savePage = async s => {
await api.post(`/_builder/api/${appname}/pages/${s.currentPageName}`, { await api.post(`/_builder/api/${appname}/pages/${s.currentPageName}`, {
page: { componentLibraries: s.pages.componentLibraries, ...page }, page: { componentLibraries: s.pages.componentLibraries, ...page },
uiFunctions: "{'1234':() => 'test return'}", uiFunctions: s.currentPageFunctions,
screens: page._screens, screens: page._screens,
}) })
} }
@ -709,7 +709,11 @@ const setCurrentPage = store => pageName => {
s.currentPreviewItem.props, s.currentPreviewItem.props,
]) ])
setCurrentScreenFunctions(s) for (let screen of s.screens) {
screen._css = generate_screen_css([screen.props])
}
setCurrentPageFunctions(s)
return s return s
}) })
} }
@ -819,7 +823,7 @@ const setComponentCode = store => code => {
store.update(s => { store.update(s => {
s.currentComponentInfo._code = code s.currentComponentInfo._code = code
setCurrentScreenFunctions(s) setCurrentPageFunctions(s)
// save without messing with the store // save without messing with the store
_saveScreenApi(s.currentPreviewItem, s) _saveScreenApi(s.currentPreviewItem, s)
@ -827,15 +831,13 @@ const setComponentCode = store => code => {
}) })
} }
const setCurrentScreenFunctions = s => { const setCurrentPageFunctions = s => {
s.currentScreenFunctions = s.currentPageFunctions = buildPageCode(s.screens, s.pages[s.currentPageName])
s.currentPreviewItem === "screen"
? buildCodeForScreens([s.currentPreviewItem])
: "({});"
insertCodeMetadata(s.currentPreviewItem.props) insertCodeMetadata(s.currentPreviewItem.props)
} }
const buildPageCode = (screens, page) => buildCodeForScreens([page, ...screens])
const setScreenType = store => type => { const setScreenType = store => type => {
store.update(s => { store.update(s => {
s.currentFrontEndType = type s.currentFrontEndType = type

View file

@ -111,7 +111,7 @@
<\script> <\script>
window["##BUDIBASE_FRONTEND_DEFINITION##"] = ${JSON.stringify(frontendDefinition)}; window["##BUDIBASE_FRONTEND_DEFINITION##"] = ${JSON.stringify(frontendDefinition)};
window["##BUDIBASE_BACKEND_DEFINITION##"] = ${JSON.stringify(backendDefinition)}; window["##BUDIBASE_BACKEND_DEFINITION##"] = ${JSON.stringify(backendDefinition)};
window["##BUDIBASE_FRONTEND_FUNCTIONS##"] = ${$store.currentScreenFunctions}; window["##BUDIBASE_FRONTEND_FUNCTIONS##"] = ${$store.currentPageFunctions};
import('/_builder/budibase-client.esm.mjs') import('/_builder/budibase-client.esm.mjs')
.then(module => { .then(module => {

View file

@ -32,6 +32,7 @@ export const createApp = (
uiFunctions, uiFunctions,
onScreenSlotRendered: () => {}, onScreenSlotRendered: () => {},
routeTo, routeTo,
appRootPath: frontendDefinition.appRootPath,
}) })
const getAttchChildrenParams = attachChildrenParams(stateManager) const getAttchChildrenParams = attachChildrenParams(stateManager)
screenSlotNode.props._children = [screen.props] screenSlotNode.props._children = [screen.props]
@ -78,6 +79,7 @@ export const createApp = (
componentLibraries, componentLibraries,
uiFunctions, uiFunctions,
onScreenSlotRendered, onScreenSlotRendered,
appRootPath: frontendDefinition.appRootPath,
// seems weird, but the routeTo variable may not be available at this point // seems weird, but the routeTo variable may not be available at this point
routeTo: url => routeTo(url), routeTo: url => routeTo(url),
}) })

View file

@ -25,7 +25,7 @@ export const screenRouter = (screens, onScreenSelected, appRootPath) => {
const params = {} const params = {}
if (current === -1) { if (current === -1) {
routes.forEach(([p], i) => { routes.forEach((p, i) => {
const pm = regexparam(p) const pm = regexparam(p)
const matches = pm.pattern.exec(_url) const matches = pm.pattern.exec(_url)

View file

@ -17,7 +17,7 @@ export const setState = (store, path, value) => {
if ( if (
state[currentKey] === null || state[currentKey] === null ||
state[currentKey] === undefined || state[currentKey] === undefined ||
!isObject(obj[currentKey]) !isObject(state[currentKey])
) { ) {
state[currentKey] = {} state[currentKey] = {}
} }

View file

@ -23,14 +23,14 @@ const isMetaProp = propName =>
export const createStateManager = ({ export const createStateManager = ({
store, store,
coreApi, coreApi,
rootPath, appRootPath,
frontendDefinition, frontendDefinition,
componentLibraries, componentLibraries,
uiFunctions, uiFunctions,
onScreenSlotRendered, onScreenSlotRendered,
routeTo, routeTo,
}) => { }) => {
let handlerTypes = eventHandlers(store, coreApi, rootPath, routeTo) let handlerTypes = eventHandlers(store, coreApi, appRootPath, routeTo)
let currentState let currentState
// any nodes that have props that are bound to the store // any nodes that have props that are bound to the store
@ -251,11 +251,11 @@ const _setup = (
const makeHandler = (handlerTypes, handlerInfo) => { const makeHandler = (handlerTypes, handlerInfo) => {
const handlerType = handlerTypes[handlerInfo.handlerType] const handlerType = handlerTypes[handlerInfo.handlerType]
return context => { return async context => {
const parameters = {} const parameters = {}
for (let paramName in handlerInfo.parameters) { for (let paramName in handlerInfo.parameters) {
parameters[paramName] = handlerInfo.parameters[paramName](context) parameters[paramName] = handlerInfo.parameters[paramName](context)
} }
handlerType.execute(parameters) await handlerType.execute(parameters)
} }
} }

View file

@ -5,7 +5,7 @@ export default function ripple(
props = { colour: "primary", unbounded: false } props = { colour: "primary", unbounded: false }
) { ) {
node.classList.add("mdc-ripple-surface") node.classList.add("mdc-ripple-surface")
const component = new MDCRipple(node) let component = new MDCRipple(node)
component.unbounded = props.unbounded component.unbounded = props.unbounded
if (props.colour === "secondary") { if (props.colour === "secondary") {

View file

@ -1,5 +1,5 @@
<script> <script>
import { onMount, setContext } from "svelte" import { onMount } from "svelte"
import { MDCDataTable } from "@material/data-table" import { MDCDataTable } from "@material/data-table"
import Row from "./DatatableRow.svelte" import Row from "./DatatableRow.svelte"
import Cell from "./DatatableCell.svelte" import Cell from "./DatatableCell.svelte"
@ -10,13 +10,14 @@
export let onLoad export let onLoad
const cb = new ClassBuilder("data-table") const cb = new ClassBuilder("data-table")
setContext("BBMD:data-table:cb", cb)
let datatable = null let datatable = null
let instance = null let instance = null
let tableElement let tableElement
let initialied = false let initialied = false
$: { $: {
if(tableElement && datatable && !initialied) { if(tableElement && datatable && !initialied) {
const children = _bb.attachChildren(tableElement) const children = _bb.attachChildren(tableElement)
@ -30,7 +31,11 @@
onMount(() => { onMount(() => {
return () => { return () => {
try {
!!instance && instance.destroy() !!instance && instance.destroy()
} catch(e) {
console.log(e)
}
instance = null instance = null
} }
}) })

View file

@ -4,7 +4,7 @@ import ClassBuilder from "../ClassBuilder.js"
export let _bb export let _bb
const cb = getContext("BBMD:data-table:cb") const cb = new ClassBuilder("data-table")
let tbody let tbody

View file

@ -1,11 +1,12 @@
<script> <script>
import { getContext } from "svelte" import { getContext } from "svelte"
import ClassBuilder from "../ClassBuilder.js"
export let isHeader = false export let isHeader = false
export let numeric = false export let numeric = false
export let _bb export let _bb
const cb = getContext("BBMD:data-table:cb") const cb = new ClassBuilder("data-table")
let elementName = isHeader ? "header-cell" : "cell" let elementName = isHeader ? "header-cell" : "cell"
let modifiers = { numeric } let modifiers = { numeric }

View file

@ -1,7 +1,11 @@
<script> <script>
import ClassBuilder from "../ClassBuilder.js"
export let _bb export let _bb
const cb = new ClassBuilder("data-table")
let thead let thead
$: thead && _bb.attachChildren(thead) $: thead && _bb.attachChildren(thead)

View file

@ -1,5 +1,6 @@
<script> <script>
import { getContext } from "svelte"; import { getContext } from "svelte";
import ClassBuilder from "../ClassBuilder.js"
export let onSelect = () => {}; export let onSelect = () => {};
export let isHeader = false; export let isHeader = false;
@ -9,7 +10,7 @@
let row = null; let row = null;
let selected = false; let selected = false;
const cb = getContext("BBMD:data-table:cb"); const cb = new ClassBuilder("data-table")
let elementName = isHeader ? "header-row" : "row"; let elementName = isHeader ? "header-row" : "row";
let modifiers = {}; let modifiers = {};

View file

@ -55,11 +55,7 @@ const dataCells = (index, indexSchema) =>
{ {
_component: "@budibase/standard-components/text", _component: "@budibase/standard-components/text",
type: "none", type: "none",
text: { text: `context.${dataItem(index)}.${col.name}`,
"##bbstate": `${dataItem(index)}.${col.name}`,
"##bbstatefallback": "",
"##bbsource": "context",
},
}, },
], ],
})) }))

View file

@ -7,8 +7,17 @@ export default ({ records }) =>
const outerContainer = record => ({ const outerContainer = record => ({
_component: "@budibase/standard-components/container", _component: "@budibase/standard-components/container",
_code: "", _code: "",
onLoad: [],
type: "div", type: "div",
onLoad: [
{
"##eventHandlerType": "Get New Record",
parameters: {
collectionKey: record.collectionKey,
childRecordType: record.name,
statePath: record.name,
},
},
],
_children: [ _children: [
heading(record), heading(record),
...record.fields.map(f => field(record, f)), ...record.fields.map(f => field(record, f)),
@ -33,7 +42,8 @@ const textField = (record, f) => ({
disabled: false, disabled: false,
fullwidth: false, fullwidth: false,
colour: "primary", colour: "primary",
maxLength: f.typeOptions && f.typeOptions.maxLength ? f.typeOptions : 0, maxLength:
f.typeOptions && f.typeOptions.maxLength ? f.typeOptions.maxLength : 0,
placeholder: f.label, placeholder: f.label,
value: fieldValueBinding(record, f), value: fieldValueBinding(record, f),
}) })
@ -57,15 +67,15 @@ const buttons = record => ({
position: { position: {
column: ["", ""], column: ["", ""],
row: ["", ""], row: ["", ""],
margin: ["","","",""], margin: ["", "", "", ""],
padding: ["30px","","",""], padding: ["30px", "", "", ""],
height: [""], height: [""],
width: [""], width: [""],
zindex: [""] zindex: [""],
}, },
layout: { layout: {
templaterows: [""], templaterows: [""],
templatecolumns: [""] templatecolumns: [""],
}, },
}, },
_children: [ _children: [

View file

@ -18,7 +18,7 @@
onMount(() => { onMount(() => {
if (!!tf) tfInstance = new MDCTextField(tf) if (!!tf) tfInstance = new MDCTextField(tf)
return () => { return () => {
!!tfInstance && tf.tfInstance.destroy() !!tfInstance && tf.tfInstance && tf.tfInstance.destroy()
tf = null tf = null
} }
}) })
@ -79,6 +79,7 @@
$: useNotchedOutline = variant == "outlined" || textarea $: useNotchedOutline = variant == "outlined" || textarea
$: renderLeadingIcon = useIcon && !trailingIcon $: renderLeadingIcon = useIcon && !trailingIcon
$: renderTrailingIcon = useIcon && trailingIcon $: renderTrailingIcon = useIcon && trailingIcon
$: safeMaxLength = maxLength <= 0 ? undefined : maxLength
let props = { modifiers, customs } let props = { modifiers, customs }
const blockClasses = cb.build({ props }) const blockClasses = cb.build({ props })
@ -91,10 +92,12 @@
} }
function changed(e) { function changed(e) {
const val = e.target.value
value = val
if (_bb.isBound(_bb.props.value)) { if (_bb.isBound(_bb.props.value)) {
_bb.setStateFromBinding(_bb.props.value, e.target.value) _bb.setStateFromBinding(_bb.props.value, val)
} }
_bb.call(onChange, e.target.value) _bb.call(onChange, val)
} }
</script> </script>
@ -116,7 +119,7 @@ TODO:Needs error handling - this will depend on how Budibase handles errors
{required} {required}
{placeholder} {placeholder}
{minLength} {minLength}
{maxLength} maxLength={safeMaxLength}
value={value} value={value}
on:change={changed} /> on:change={changed} />
{:else} {:else}
@ -131,11 +134,11 @@ TODO:Needs error handling - this will depend on how Budibase handles errors
{required} {required}
placeholder={!!label && fullwidth ? label : placeholder} placeholder={!!label && fullwidth ? label : placeholder}
{minLength} {minLength}
{maxLength} maxLength={safeMaxLength}
value={value} value={value}
aria-label={`Textfield ${variant}`} aria-label={`Textfield ${variant}`}
on:focus={focus} on:focus={focus}
on:change={changed} /> on:input={changed} />
{#if renderTrailingIcon} {#if renderTrailingIcon}
<Icon {icon} /> <Icon {icon} />
{/if} {/if}