From 044edb1acac9c09ca76ee2c332625ee47d1b60da Mon Sep 17 00:00:00 2001 From: pngwn Date: Fri, 24 Jan 2020 14:30:17 +0000 Subject: [PATCH] Remove validation, use references rather than clones where possible, prioritise side-panel working with components for now. --- packages/builder/src/builderStore/store.js | 30 ++-- .../src/userInterface/ComponentPanel.svelte | 152 ++---------------- .../userInterface/ComponentsHierarchy.svelte | 71 +------- ...lte => ComponentsHierarchyChildren.svelte} | 2 +- .../src/userInterface/ComponentsList.svelte | 3 - .../userInterface/EditComponentProps.svelte | 104 +----------- .../userInterface/EventListSelector.svelte | 3 +- .../src/userInterface/PropControl.svelte | 23 ++- .../src/userInterface/PropsView.svelte | 70 ++------ 9 files changed, 73 insertions(+), 385 deletions(-) rename packages/builder/src/userInterface/{ComponentHierarchyChildren.svelte => ComponentsHierarchyChildren.svelte} (91%) diff --git a/packages/builder/src/builderStore/store.js b/packages/builder/src/builderStore/store.js index ce35cf1f29..35191904ad 100644 --- a/packages/builder/src/builderStore/store.js +++ b/packages/builder/src/builderStore/store.js @@ -93,7 +93,8 @@ export const getStore = () => { store.createGeneratedComponents = createGeneratedComponents(store); store.addChildComponent = addChildComponent(store); store.selectComponent = selectComponent(store); - store.saveComponent = saveComponent(store); + store.updateComponentProp = updateComponentProp(store); + return store; } @@ -137,6 +138,7 @@ const initialise = (store, initial) => async () => { shadowHierarchy, initial.currentNode.nodeId ); } + console.log(initial) store.set(initial); return initial; } @@ -701,19 +703,16 @@ const addChildComponent = store => component => { const children = s.currentFrontEndItem.props._children; - const component_definition = { - ...newComponent.fullProps, + const component_definition = Object.assign( + cloneDeep(newComponent.fullProps), { _component: component, - name: component, - description: '', - location: (s.currentFrontEndItem.location ? s.currentFrontEndItem.location : []) - .concat(children && children.length || 0) - } + }) s.currentFrontEndItem.props._children = children ? children.concat(component_definition) : [component_definition]; + console.log(component_definition) return s; }) @@ -721,15 +720,20 @@ const addChildComponent = store => component => { const selectComponent = store => component => { store.update(s => { - s.currentComponentInfo = getComponentInfo(s.components, component); + s.currentComponentInfo = component; + console.log(s) return s; }) + } -const saveComponent = store => component => { +const updateComponentProp = store => (name, value) => { store.update(s => { - s.currentComponentInfo = getComponentInfo(s.components, component); - console.log(s.currentFrontEndItem, s.screens) - return _saveScreen(store, s, s.currentFrontEndItem); + const current_component = s.currentComponentInfo; + s.currentComponentInfo[name] = value; + _saveScreen(store, s, s.currentFrontEndItem); + s.currentComponentInfo = current_component; + return s; }) + } diff --git a/packages/builder/src/userInterface/ComponentPanel.svelte b/packages/builder/src/userInterface/ComponentPanel.svelte index 7dcfc32efe..580cfefd2c 100644 --- a/packages/builder/src/userInterface/ComponentPanel.svelte +++ b/packages/builder/src/userInterface/ComponentPanel.svelte @@ -5,13 +5,10 @@ import { store } from "../builderStore"; import { isRootComponent } from "./pagesParsing/searchComponents"; import IconButton from "../common/IconButton.svelte"; import Textbox from "../common/Textbox.svelte"; -// import UIkit from "uikit"; import { pipe } from "../common/core"; import { getScreenInfo } from "./pagesParsing/createProps"; -// import Button from "../common/Button.svelte"; -// import ButtonGroup from "../common/ButtonGroup.svelte"; import { LayoutIcon, PaintIcon, TerminalIcon } from '../common/Icons/'; import CodeEditor from './CodeEditor.svelte'; import LayoutEditor from './LayoutEditor.svelte'; @@ -32,18 +29,18 @@ let name = ""; let description = ""; let tagsString = ""; let nameInvalid = ""; -let componentInfo; +let componentInfo = {}; let modalElement let propsValidationErrors = []; let originalName=""; let components; let ignoreStore = false; -$: shortName = last(name.split("/")); +// $: shortName = last(name.split("/")); store.subscribe(s => { if(ignoreStore) return; - component = s.currentComponentInfo.component; + component = s.currentComponentInfo; if(!component) return; originalName = component.name; name = component.name; @@ -53,100 +50,12 @@ store.subscribe(s => { components = s.components; }); -const save = () => { - - ignoreStore = true; - if(!validate()) { - ignoreStore = false; - return; - } - - component.name = originalName || name; - component.description = description; - component.tags = pipe(tagsString, [ - split(","), - map(s => s.trim()) - ]); - - store.saveComponent(component); - - ignoreStore = false; - // now do the rename - if(name !== originalName) { - store.renameScreen(originalName, name); - } -} - -const deleteComponent = () => { - showDialog(); -} - -const confirmDeleteComponent = () => { - store.deleteScreen(component.name); - hideDialog(); -} - -const onPropsValidate = result => { - propsValidationErrors = result; -} - -const updateComponent = doChange => { - const newComponent = cloneDeep(component); - - component = doChange(newComponent); - console.log(component, $store.screens[0].props._children[1]) - componentInfo = getScreenInfo(components, newComponent); -} - -const onPropsChanged = newProps => { - updateComponent(newComponent => - assign(newComponent, newProps)) - save(); - -} - -const validate = () => { - const fieldInvalid = (field, err) => - errors[field] = err; - const fieldValid = field => - errors[field] && delete errors[field]; - - if(!name) nameInvalid = "component name i not supplied"; - else nameInvalid = ""; - - return (!nameInvalid && propsValidationErrors.length === 0); -} - -// const hideDialog = () => { -// UIkit.modal(modalElement).hide(); -// } - -// const showDialog = () => { -// UIkit.modal(modalElement).show(); -// } +const onPropsChanged = store.updateComponentProp; let current_view = 'props'; - - -
- - - -
+ {#if !componentInfo.component} +
- {#if current_view === 'props'} - - {:else if current_view === 'layout'} - - {:else} - - {/if} + {#if current_view === 'props'} + + {:else if current_view === 'layout'} + + {:else} + + {/if} -
+
+ {:else} +

This is a screen, this will be dealt with later

+ {/if}
- -