From 6aa6c4d433f15ed6c2543e038e41626e155d6c01 Mon Sep 17 00:00:00 2001 From: pngwn Date: Tue, 28 Jan 2020 21:17:04 +0000 Subject: [PATCH] 48 builder frontend 2 (#70) * Implement collapsing component hierarchy. * Save screen when adding new components. * Allow creation of nested child components. * Fix level-based indentation of hierarchy. * Rename updateComponentProps to setComponentProps * Save layout information to the disk. * Cleanup: switch to autosubscriptions to prevent memory leaks, remove unused imports. * Remove unused css. * Fix incorrect subscription. --- packages/builder/src/builderStore/store.js | 53 +++- .../builder/src/common/Icons/ArrowDown.svelte | 4 + packages/builder/src/common/Icons/index.js | 1 + .../src/common/Inputs/InputGroup.svelte | 10 +- .../src/userInterface/ComponentPanel.svelte | 70 ++---- .../src/userInterface/ComponentSearch.svelte | 30 +-- .../userInterface/ComponentSelector.svelte | 106 ++++---- .../userInterface/ComponentsHierarchy.svelte | 147 ++++++----- .../ComponentsHierarchyChildren.svelte | 47 +++- .../src/userInterface/ComponentsList.svelte | 91 +++---- .../ComponentsPaneSwitcher.svelte | 16 +- .../userInterface/CurrentItemPreview.svelte | 77 +++--- .../userInterface/EditComponentProps.svelte | 173 +++++-------- .../userInterface/EventListSelector.svelte | 110 ++++----- .../src/userInterface/EventSelector.svelte | 144 ++++++----- .../src/userInterface/LayoutEditor.svelte | 92 +++---- .../src/userInterface/NewComponent.svelte | 121 ++++----- .../builder/src/userInterface/PageView.svelte | 74 +++--- .../src/userInterface/PagesList.svelte | 105 ++++---- .../src/userInterface/PropControl.svelte | 75 +++--- .../src/userInterface/PropsView.svelte | 80 +++--- .../src/userInterface/SettingsView.svelte | 150 ++++++------ .../userInterface/StateBindingControl.svelte | 223 ++++++++--------- .../userInterface/UserInterfaceRoot.svelte | 231 +++++++++--------- 24 files changed, 1022 insertions(+), 1208 deletions(-) create mode 100644 packages/builder/src/common/Icons/ArrowDown.svelte diff --git a/packages/builder/src/builderStore/store.js b/packages/builder/src/builderStore/store.js index e40470d78d..0975671073 100644 --- a/packages/builder/src/builderStore/store.js +++ b/packages/builder/src/builderStore/store.js @@ -4,7 +4,7 @@ import { import { filter, cloneDeep, sortBy, map, last, keys, concat, keyBy, - find, isEmpty, reduce, values + find, isEmpty, reduce, values, isEqual } from "lodash/fp"; import { pipe, getNode, validate, @@ -93,8 +93,8 @@ export const getStore = () => { store.createGeneratedComponents = createGeneratedComponents(store); store.addChildComponent = addChildComponent(store); store.selectComponent = selectComponent(store); - store.updateComponentProp = updateComponentProp(store); - + store.setComponentProp = setComponentProp(store); + store.setComponentStyle = setComponentStyle(store); return store; } @@ -456,6 +456,10 @@ const _saveScreen = (store, s, screen) => { return s; } +const _save = (appname, screen, store, s) => + api.post(`/_builder/api/${appname}/screen`, screen) + .then(() => savePackage(store, s)); + const createScreen = store => (screenName, layoutComponentName) => { store.update(s => { const newComponentInfo = getNewComponentInfo( @@ -597,8 +601,6 @@ const addComponentLibrary = store => async lib => { return s; }) - - } const removeComponentLibrary = store => lib => { @@ -701,17 +703,31 @@ const addChildComponent = store => component => { const newComponent = getNewComponentInfo( s.components, component); - const children = s.currentFrontEndItem.props._children; + let children = s.currentComponentInfo.component ? + s.currentComponentInfo.component.props._children : + s.currentComponentInfo._children; const component_definition = Object.assign( cloneDeep(newComponent.fullProps), { _component: component, + _layout: {} }) - s.currentFrontEndItem.props._children = - children ? - children.concat(component_definition) : - [component_definition]; + if (children) { + if (s.currentComponentInfo.component) { + s.currentComponentInfo.component.props._children = children.concat(component_definition); + } else { + s.currentComponentInfo._children = children.concat(component_definition) + } + } else { + if (s.currentComponentInfo.component) { + s.currentComponentInfo.component.props._children = [component_definition]; + } else { + s.currentComponentInfo._children = [component_definition] + } + } + + _saveScreen(store, s, s.currentFrontEndItem); return s; }) @@ -725,7 +741,7 @@ const selectComponent = store => component => { } -const updateComponentProp = store => (name, value) => { +const setComponentProp = store => (name, value) => { store.update(s => { const current_component = s.currentComponentInfo; s.currentComponentInfo[name] = value; @@ -733,5 +749,18 @@ const updateComponentProp = store => (name, value) => { s.currentComponentInfo = current_component; return s; }) - +} + +const setComponentStyle = store => (name, value) => { + store.update(s => { + if (!s.currentComponentInfo._layout) { + s.currentComponentInfo._layout = {}; + } + s.currentComponentInfo._layout[name] = value; + + // save without messing with the store + _save(s.appname, s.currentFrontEndItem, store, s) + + return s; + }) } diff --git a/packages/builder/src/common/Icons/ArrowDown.svelte b/packages/builder/src/common/Icons/ArrowDown.svelte new file mode 100644 index 0000000000..a710c8ae84 --- /dev/null +++ b/packages/builder/src/common/Icons/ArrowDown.svelte @@ -0,0 +1,4 @@ + + + + diff --git a/packages/builder/src/common/Icons/index.js b/packages/builder/src/common/Icons/index.js index 7ab39dfdd0..2e2ffc2010 100644 --- a/packages/builder/src/common/Icons/index.js +++ b/packages/builder/src/common/Icons/index.js @@ -3,3 +3,4 @@ export { default as PaintIcon } from './Paint.svelte'; export { default as TerminalIcon } from './Terminal.svelte'; export { default as InputIcon } from './Input.svelte'; export { default as ImageIcon } from './Image.svelte'; +export { default as ArrowDownIcon } from './ArrowDown.svelte'; diff --git a/packages/builder/src/common/Inputs/InputGroup.svelte b/packages/builder/src/common/Inputs/InputGroup.svelte index 09ed8298b7..55bede83f2 100644 --- a/packages/builder/src/common/Inputs/InputGroup.svelte +++ b/packages/builder/src/common/Inputs/InputGroup.svelte @@ -2,11 +2,19 @@ export let meta = []; export let size = ''; export let values = []; + export let onStyleChanged = () => {}; + + let _values = values.map(v => v); + + $: onStyleChanged(_values);
{#each meta as { placeholder }, i} - + _values[i] = e.target.value} /> {/each}
diff --git a/packages/builder/src/userInterface/ComponentPanel.svelte b/packages/builder/src/userInterface/ComponentPanel.svelte index 580cfefd2c..5649820970 100644 --- a/packages/builder/src/userInterface/ComponentPanel.svelte +++ b/packages/builder/src/userInterface/ComponentPanel.svelte @@ -1,58 +1,22 @@
@@ -78,9 +42,9 @@ let current_view = 'props';
{#if current_view === 'props'} - + {:else if current_view === 'layout'} - + {:else} {/if} diff --git a/packages/builder/src/userInterface/ComponentSearch.svelte b/packages/builder/src/userInterface/ComponentSearch.svelte index a2281ba070..a569329632 100644 --- a/packages/builder/src/userInterface/ComponentSearch.svelte +++ b/packages/builder/src/userInterface/ComponentSearch.svelte @@ -1,31 +1,27 @@
@@ -65,4 +61,4 @@ $: filteredComponents = font-style: italic; } - \ No newline at end of file + diff --git a/packages/builder/src/userInterface/ComponentSelector.svelte b/packages/builder/src/userInterface/ComponentSelector.svelte index d46a8dc79c..9a7ad0c194 100644 --- a/packages/builder/src/userInterface/ComponentSelector.svelte +++ b/packages/builder/src/userInterface/ComponentSelector.svelte @@ -1,74 +1,66 @@ {#each componentLibraries as lib} diff --git a/packages/builder/src/userInterface/ComponentsHierarchy.svelte b/packages/builder/src/userInterface/ComponentsHierarchy.svelte index 7522f4eb31..48f0ed1757 100644 --- a/packages/builder/src/userInterface/ComponentsHierarchy.svelte +++ b/packages/builder/src/userInterface/ComponentsHierarchy.svelte @@ -1,90 +1,79 @@
- {#each _components as component} -
store.setCurrentScreen(component.component.name)}> +
store.setCurrentScreen(component.component.name)}> - {component.title} -
- {#if component.component.props && component.component.props._children} + + {#if component.component.props && component.component.props._children} + + {/if} + + + {component.title} +
+ + {#if isScreenSelected(component) && component.component.props && component.component.props._children} select_component(component.component.name, child)} /> {/if} {/each} @@ -102,9 +91,10 @@ function select_component(screen, component) { .hierarchy-item { cursor: pointer; padding: 11px 7px; - margin: 5px 0; border-radius: 5px; + display: flex; + align-items: center; } .hierarchy-item:hover { @@ -112,12 +102,6 @@ function select_component(screen, component) { background: #fafafa; } - - -.currentfolder { - color: var(--secondary100); -} - .selected { color: var(--button-text); background: var(--background-button)!important; @@ -127,5 +111,10 @@ function select_component(screen, component) { margin-left: 10px; } - +.icon { + display: inline-block; + transition: 0.2s; + width: 24px; + height: 24px; +} diff --git a/packages/builder/src/userInterface/ComponentsHierarchyChildren.svelte b/packages/builder/src/userInterface/ComponentsHierarchyChildren.svelte index 821c8757c2..4211f05b41 100644 --- a/packages/builder/src/userInterface/ComponentsHierarchyChildren.svelte +++ b/packages/builder/src/userInterface/ComponentsHierarchyChildren.svelte @@ -3,22 +3,55 @@ import { pipe } from "../common/core"; export let components = []; + export let currentComponent; export let onSelect = () => {}; + export let level = 0; + const capitalise = s => s.substring(0,1).toUpperCase() + s.substring(1); const get_name = s => last(s.split('/')); const get_capitalised_name = name => pipe(name, [get_name,capitalise]); -{#each components as component} -
    -
  • onSelect(component)}> - {get_capitalised_name(component._component)} +
      + {#each components as component} +
    • onSelect(component)}> + + {get_capitalised_name(component._component)} + {#if component._children} - + {/if}
    • + {/each} +
    -
-{/each} + diff --git a/packages/builder/src/userInterface/ComponentsList.svelte b/packages/builder/src/userInterface/ComponentsList.svelte index fefde0c114..ca8ea68246 100644 --- a/packages/builder/src/userInterface/ComponentsList.svelte +++ b/packages/builder/src/userInterface/ComponentsList.svelte @@ -1,52 +1,43 @@
@@ -115,13 +106,6 @@ let current_view = 'text'; min-height: 0px; } -.inner-header { - font-size: 0.9em; - font-weight: bold; - margin-top: 7px; - margin-bottom: 3px; -} - .component { padding: 0 15px; cursor: pointer; @@ -147,13 +131,6 @@ let current_view = 'text'; opacity: 0.6; } -.component > .description { - font-size: 0.8em; - color: var(--secondary75); - display: inline-block; - margin-left: 10px; -} - ul { list-style: none; display: flex; diff --git a/packages/builder/src/userInterface/ComponentsPaneSwitcher.svelte b/packages/builder/src/userInterface/ComponentsPaneSwitcher.svelte index 7ea0f19e6b..7877bee626 100644 --- a/packages/builder/src/userInterface/ComponentsPaneSwitcher.svelte +++ b/packages/builder/src/userInterface/ComponentsPaneSwitcher.svelte @@ -1,16 +1,14 @@
diff --git a/packages/builder/src/userInterface/CurrentItemPreview.svelte b/packages/builder/src/userInterface/CurrentItemPreview.svelte index caba4efc9e..2156d18529 100644 --- a/packages/builder/src/userInterface/CurrentItemPreview.svelte +++ b/packages/builder/src/userInterface/CurrentItemPreview.svelte @@ -1,41 +1,25 @@ @@ -52,7 +36,6 @@ store.subscribe(s => { window["##BUDIBASE_APPDEFINITION##"] = ${JSON.stringify(appDefinition)}; import('/_builder/budibase-client.esm.mjs') .then(module => { - console.log(module, window); module.loadBudibase({ window, localStorage }); }) @@ -73,23 +56,21 @@ store.subscribe(s => { diff --git a/packages/builder/src/userInterface/EditComponentProps.svelte b/packages/builder/src/userInterface/EditComponentProps.svelte index 4b823bd920..4ac515cbe5 100644 --- a/packages/builder/src/userInterface/EditComponentProps.svelte +++ b/packages/builder/src/userInterface/EditComponentProps.svelte @@ -1,68 +1,31 @@
@@ -74,74 +37,54 @@ const onPropsChanged = newProps => {
- - - -
-
diff --git a/packages/builder/src/userInterface/EventListSelector.svelte b/packages/builder/src/userInterface/EventListSelector.svelte index b4d6645f79..cfbe20345d 100644 --- a/packages/builder/src/userInterface/EventListSelector.svelte +++ b/packages/builder/src/userInterface/EventListSelector.svelte @@ -1,45 +1,39 @@ @@ -67,32 +61,28 @@ const removeHandler = (index) => () => { diff --git a/packages/builder/src/userInterface/EventSelector.svelte b/packages/builder/src/userInterface/EventSelector.svelte index 6274912c30..e109d8122d 100644 --- a/packages/builder/src/userInterface/EventSelector.svelte +++ b/packages/builder/src/userInterface/EventSelector.svelte @@ -1,71 +1,67 @@ @@ -77,35 +73,33 @@ const onParameterChanged = index => val => { {/each} -
{#if parameters} -{#each parameters as p, index} + {#each parameters as p, index} -
- {p.name} -
- +
+ {p.name} +
+ -{/each} + {/each} {/if} \ No newline at end of file + .type-selector { + border-color: var(--primary50); + border-radius: 2px; + width: 50px; + flex: 1 0 auto; + } + diff --git a/packages/builder/src/userInterface/LayoutEditor.svelte b/packages/builder/src/userInterface/LayoutEditor.svelte index 0b26f19d33..6e58551d22 100644 --- a/packages/builder/src/userInterface/LayoutEditor.svelte +++ b/packages/builder/src/userInterface/LayoutEditor.svelte @@ -1,13 +1,8 @@ @@ -30,48 +46,41 @@

Positioning

-
-
Grid Area:
- -
- -
-
Column:
- -
- -
-
Row:
- -
- -
-
Gap:
- -
+ {#each Object.entries(positions) as [key, [name, meta, size]]} +
+
Grid Area:
+ onStyleChanged(key, _value)} + values={layout[key] || newValue(meta.length)} + {meta} + {size} /> +
+ {/each}

Spacing

-
-
-
Margin:
- -
- -
-
Padding:
- -
+ {#each Object.entries(spacing) as [key, [name, meta, size]]} +
+
Grid Area:
+ onStyleChanged(key, _value)} + values={layout[key] || newValue(meta.length)} + {meta} + {size} /> +
+ {/each}

Z-Index

-
-
-
Z-Index:
- -
+ {#each Object.entries(zindex) as [key, [name, meta, size]]} +
+
Grid Area:
+ onStyleChanged(key, _value)} + values={layout[key] || newValue(meta.length)} + {meta} + {size} /> +
+ {/each}
diff --git a/packages/builder/src/userInterface/NewComponent.svelte b/packages/builder/src/userInterface/NewComponent.svelte index 608097838c..5343e8e079 100644 --- a/packages/builder/src/userInterface/NewComponent.svelte +++ b/packages/builder/src/userInterface/NewComponent.svelte @@ -1,65 +1,64 @@ @@ -106,27 +105,7 @@ const screenNameExists = (name) => diff --git a/packages/builder/src/userInterface/PageView.svelte b/packages/builder/src/userInterface/PageView.svelte index 64f75b213f..00db1fc073 100644 --- a/packages/builder/src/userInterface/PageView.svelte +++ b/packages/builder/src/userInterface/PageView.svelte @@ -1,44 +1,36 @@
@@ -61,11 +53,11 @@ const save = () => {
\ No newline at end of file + .root { + padding: 15px; + } + .help-text { + color: var(--slate); + font-size: 10pt; + } + diff --git a/packages/builder/src/userInterface/PagesList.svelte b/packages/builder/src/userInterface/PagesList.svelte index 9fb9148f86..f148371fea 100644 --- a/packages/builder/src/userInterface/PagesList.svelte +++ b/packages/builder/src/userInterface/PagesList.svelte @@ -1,22 +1,21 @@
@@ -31,46 +30,44 @@ store.setCurrentPage('main')
diff --git a/packages/builder/src/userInterface/PropControl.svelte b/packages/builder/src/userInterface/PropControl.svelte index e5b09a1610..779ebbecfb 100644 --- a/packages/builder/src/userInterface/PropControl.svelte +++ b/packages/builder/src/userInterface/PropControl.svelte @@ -1,37 +1,25 @@
- - {#if prop_type === "event"} - - - - {:else } + {#if prop_type !== "event" }
{prop_name}
{ onChanged={v => setProp(prop_name, v)}/> {/if} -
diff --git a/packages/builder/src/userInterface/PropsView.svelte b/packages/builder/src/userInterface/PropsView.svelte index 8ac1de4b60..4e2a93beea 100644 --- a/packages/builder/src/userInterface/PropsView.svelte +++ b/packages/builder/src/userInterface/PropsView.svelte @@ -1,44 +1,32 @@
@@ -65,20 +53,18 @@ const fieldHasError = (propName) => diff --git a/packages/builder/src/userInterface/SettingsView.svelte b/packages/builder/src/userInterface/SettingsView.svelte index cd9ce470b6..d292d8cc7f 100644 --- a/packages/builder/src/userInterface/SettingsView.svelte +++ b/packages/builder/src/userInterface/SettingsView.svelte @@ -1,52 +1,46 @@
@@ -65,7 +59,7 @@ export const show = () => {

Component Libraries - + @@ -73,17 +67,17 @@ export const show = () => { {#each $store.pages.componentLibraries as lib}

{lib} - removeLibrary(lib)}/>
{/each}
- +

Stylesheets - + @@ -91,55 +85,53 @@ export const show = () => { {#each $store.pages.stylesheets as stylesheet}

{stylesheet} - removeStylesheet(stylesheet)}/>
{/each}
- +
\ No newline at end of file + .header > div:nth-child(2) { + grid-column-start: icon; + } + diff --git a/packages/builder/src/userInterface/StateBindingControl.svelte b/packages/builder/src/userInterface/StateBindingControl.svelte index bbc81ef535..32065a111e 100644 --- a/packages/builder/src/userInterface/StateBindingControl.svelte +++ b/packages/builder/src/userInterface/StateBindingControl.svelte @@ -1,145 +1,130 @@ {#if isBound} -
-
-
{isExpanded ? "" : bindingPath}
- isExpanded=!isExpanded}/> - {#if !canOnlyBind} - +
+
+
{isExpanded ? "" : bindingPath}
+ isExpanded=!isExpanded}/> + {#if !canOnlyBind} + + {/if} +
+ {#if isExpanded} +
+
Binding Path
+ +
Fallback Value
+ +
Binding Source
+ +
{/if} +
- {#if isExpanded} -
-
Binding Path
- -
Fallback Value
- -
Binding Source
- -
- {/if} - -
{:else} -
+
- {#if type === "bool"} + {#if type === "bool"} +
+ onChanged(!value)} /> +
+ {:else if type === "options"} + + {:else} + onChanged(ev.target.value)} + bind:value={value} + style="flex: 1 0 auto;" /> + {/if} -
- onChanged(!value)} />
- - {:else if type === "options"} - - - - {:else} - - onChanged(ev.target.value)} - bind:value={value} - style="flex: 1 0 auto;" /> - - - {/if} - -
{/if} diff --git a/packages/builder/src/userInterface/UserInterfaceRoot.svelte b/packages/builder/src/userInterface/UserInterfaceRoot.svelte index deadd829e6..fb6fb513a0 100644 --- a/packages/builder/src/userInterface/UserInterfaceRoot.svelte +++ b/packages/builder/src/userInterface/UserInterfaceRoot.svelte @@ -1,28 +1,25 @@
@@ -44,11 +41,6 @@ const settings = () => { Screens
- -
@@ -61,16 +53,16 @@ const settings = () => {
{#if $store.currentFrontEndType === "screen"} - + {:else if $store.currentFrontEndType === "page"} - + {/if}
{#if $store.currentFrontEndType === "screen"} -
- -
+
+ +
{/if}
@@ -81,109 +73,108 @@ const settings = () => {