From e54fd6a0d9e5179106a20fdc52620b7252dbb533 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 28 Jan 2020 22:39:16 +0000 Subject: [PATCH 1/8] merge --- .../builder/src/common/Icons/Events.svelte | 8 + .../builder/src/common/Icons/Pencil.svelte | 19 ++ packages/builder/src/common/Icons/index.js | 2 + .../src/userInterface/ComponentPanel.svelte | 10 +- .../EventsEditor/EventEditorModal.svelte | 49 +++++ .../EventsEditor/EventSelector.svelte | 110 +++++++++++ .../EventsEditor/EventsEditor.svelte | 149 +++++++++++++++ .../EventsEditor/StateBindingControl.svelte | 177 ++++++++++++++++++ .../src/userInterface/EventsEditor/index.js | 1 + packages/server/package.json | 2 +- 10 files changed, 525 insertions(+), 2 deletions(-) create mode 100644 packages/builder/src/common/Icons/Events.svelte create mode 100644 packages/builder/src/common/Icons/Pencil.svelte create mode 100644 packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte create mode 100644 packages/builder/src/userInterface/EventsEditor/EventSelector.svelte create mode 100644 packages/builder/src/userInterface/EventsEditor/EventsEditor.svelte create mode 100644 packages/builder/src/userInterface/EventsEditor/StateBindingControl.svelte create mode 100644 packages/builder/src/userInterface/EventsEditor/index.js diff --git a/packages/builder/src/common/Icons/Events.svelte b/packages/builder/src/common/Icons/Events.svelte new file mode 100644 index 0000000000..d3728b9901 --- /dev/null +++ b/packages/builder/src/common/Icons/Events.svelte @@ -0,0 +1,8 @@ + + + + diff --git a/packages/builder/src/common/Icons/Pencil.svelte b/packages/builder/src/common/Icons/Pencil.svelte new file mode 100644 index 0000000000..266458a132 --- /dev/null +++ b/packages/builder/src/common/Icons/Pencil.svelte @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/packages/builder/src/common/Icons/index.js b/packages/builder/src/common/Icons/index.js index 2e2ffc2010..c00ebb3ce4 100644 --- a/packages/builder/src/common/Icons/index.js +++ b/packages/builder/src/common/Icons/index.js @@ -4,3 +4,5 @@ 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'; +export { default as EventsIcon } from './Events.svelte'; +export { default as PencilIcon } from './Pencil.svelte'; diff --git a/packages/builder/src/userInterface/ComponentPanel.svelte b/packages/builder/src/userInterface/ComponentPanel.svelte index 5649820970..1fa8ce0642 100644 --- a/packages/builder/src/userInterface/ComponentPanel.svelte +++ b/packages/builder/src/userInterface/ComponentPanel.svelte @@ -2,9 +2,10 @@ import PropsView from "./PropsView.svelte"; import { store } from "../builderStore"; import IconButton from "../common/IconButton.svelte"; - import { LayoutIcon, PaintIcon, TerminalIcon } from '../common/Icons/'; + import { LayoutIcon, PaintIcon, TerminalIcon, EventsIcon } from '../common/Icons/'; import CodeEditor from './CodeEditor.svelte'; import LayoutEditor from './LayoutEditor.svelte'; + import EventsEditor from "./EventsEditor"; let current_view = 'props'; @@ -36,6 +37,11 @@ +
  • + +
  • {#if !componentInfo.component} @@ -45,6 +51,8 @@ {:else if current_view === 'layout'} + {:else if current_view === 'events'} + {:else} {/if} diff --git a/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte b/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte new file mode 100644 index 0000000000..6cb72f6310 --- /dev/null +++ b/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte @@ -0,0 +1,49 @@ + + + +

    {action} Event

    + +
    + + \ No newline at end of file diff --git a/packages/builder/src/userInterface/EventsEditor/EventSelector.svelte b/packages/builder/src/userInterface/EventsEditor/EventSelector.svelte new file mode 100644 index 0000000000..332a2ed32b --- /dev/null +++ b/packages/builder/src/userInterface/EventsEditor/EventSelector.svelte @@ -0,0 +1,110 @@ + + + + +
    + + + + +
    + +{#if parameters} + {#each parameters as p, index} +
    {p.name}
    + + {/each} +{/if} diff --git a/packages/builder/src/userInterface/EventsEditor/EventsEditor.svelte b/packages/builder/src/userInterface/EventsEditor/EventsEditor.svelte new file mode 100644 index 0000000000..c1066322e8 --- /dev/null +++ b/packages/builder/src/userInterface/EventsEditor/EventsEditor.svelte @@ -0,0 +1,149 @@ + + + + +

    Events

    + +
    + +
    + {#each events as event, index} +
    + {event[0]} + openModal({ ...event, index })} /> +
    + {/each} +
    + +
    + +

    {action} Event

    + {#if selectedEvent} + {JSON.stringify(selectedEvent)} + + {:else} + + +
    + +
    + + {/if} +
    diff --git a/packages/builder/src/userInterface/EventsEditor/StateBindingControl.svelte b/packages/builder/src/userInterface/EventsEditor/StateBindingControl.svelte new file mode 100644 index 0000000000..f8e6ca6da8 --- /dev/null +++ b/packages/builder/src/userInterface/EventsEditor/StateBindingControl.svelte @@ -0,0 +1,177 @@ + + +{#if isBound} +
    +
    +
    {isExpanded ? "" : bindingPath}
    + isExpanded=!isExpanded}/> + {#if !canOnlyBind} + + {/if} +
    + {#if isExpanded} +
    +
    Binding Path
    + +
    Fallback Value
    + +
    Binding Source
    + +
    + {/if} + +
    +{:else} +
    + + {#if type === "bool"} + +
    + 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/EventsEditor/index.js b/packages/builder/src/userInterface/EventsEditor/index.js new file mode 100644 index 0000000000..7782e7fccd --- /dev/null +++ b/packages/builder/src/userInterface/EventsEditor/index.js @@ -0,0 +1 @@ +export { default } from "./EventsEditor.svelte"; \ No newline at end of file diff --git a/packages/server/package.json b/packages/server/package.json index 7f607b533d..6a86bb4d1f 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -8,7 +8,7 @@ "build": "cd appPackages/_master && yarn && cd ../testApp && yarn && cd ../testApp2 && yarn", "initialise": "node ./initialise/initialiseBudibase init -d ./myapps -c contributors -u admin -p admin", "budi": "node ../cli/bin/budi", - "dev:builder": "nodemon index" + "dev:builder": "node index" }, "keywords": [ "budibase" From f0e07cdfca9537207b08906138cd9ac3f8a538ff Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 29 Jan 2020 21:04:48 +0000 Subject: [PATCH 2/8] basic architecture complete --- packages/builder/src/common/PlusButton.svelte | 23 ++ .../EventsEditor/EventSelector.svelte | 110 ---------- .../EventsEditor/EventsEditor.svelte | 197 ++++++++++++++---- .../EventsEditor/HandlerSelector.svelte | 112 ++++++++++ .../src/userInterface/EventsEditor/index.js | 6 + packages/server/app.js | 2 +- 6 files changed, 294 insertions(+), 156 deletions(-) create mode 100644 packages/builder/src/common/PlusButton.svelte delete mode 100644 packages/builder/src/userInterface/EventsEditor/EventSelector.svelte create mode 100644 packages/builder/src/userInterface/EventsEditor/HandlerSelector.svelte diff --git a/packages/builder/src/common/PlusButton.svelte b/packages/builder/src/common/PlusButton.svelte new file mode 100644 index 0000000000..b7ae19fcbf --- /dev/null +++ b/packages/builder/src/common/PlusButton.svelte @@ -0,0 +1,23 @@ + + + diff --git a/packages/builder/src/userInterface/EventsEditor/EventSelector.svelte b/packages/builder/src/userInterface/EventsEditor/EventSelector.svelte deleted file mode 100644 index 332a2ed32b..0000000000 --- a/packages/builder/src/userInterface/EventsEditor/EventSelector.svelte +++ /dev/null @@ -1,110 +0,0 @@ - - - - -
    - - - - -
    - -{#if parameters} - {#each parameters as p, index} -
    {p.name}
    - - {/each} -{/if} diff --git a/packages/builder/src/userInterface/EventsEditor/EventsEditor.svelte b/packages/builder/src/userInterface/EventsEditor/EventsEditor.svelte index c1066322e8..fa21f2c56a 100644 --- a/packages/builder/src/userInterface/EventsEditor/EventsEditor.svelte +++ b/packages/builder/src/userInterface/EventsEditor/EventsEditor.svelte @@ -14,9 +14,10 @@ import Checkbox from "../../common/Checkbox.svelte"; import Textbox from "../../common/Textbox.svelte"; import Dropdown from "../../common/Dropdown.svelte"; + import PlusButton from "../../common/PlusButton.svelte"; import IconButton from "../../common/IconButton.svelte"; import Modal from "../../common/Modal.svelte"; - import EventSelector from "./EventSelector.svelte"; + import HandlerSelector from "./HandlerSelector.svelte"; import { PencilIcon } from "../../common/Icons"; import { EVENT_TYPE_MEMBER_NAME } from "../../common/eventHandlers"; @@ -27,12 +28,28 @@ export let onPropChanged = () => {}; export let components; + // Structure + // { + // [eventName]: [{eventHandler}, {eventHandler1}], + // [eventName1]: [{eventHandler}, {eventHandler1}], + // } + let modalOpen = false; let events = []; - let selectedEvent = null; + let selectedEvent = {}; let newEventType = "onClick"; // TODO: only show events that have handlers + + // $: { + // let componentEvents = {}; + // for (let propName in componentInfo) { + // const isEventProp = findType(propName) === EVENT_TYPE; + // if (isEventProp) componentEvents[propName] = componentInfo[propName]; + // } + // events = componentEvents; + // } + $: events = componentInfo && Object.entries(componentInfo).filter( @@ -47,7 +64,7 @@ .props[propName]; } - console.log(componentInfo, events, components); + console.log({ componentInfo, events, components }); const openModal = event => { selectedEvent = event; @@ -55,30 +72,47 @@ }; const closeModal = () => { - selectedEvent = null; + selectedEvent = {}; modalOpen = false; }; - const addEventHandler = event => { + const addEventHandler = eventType => { const newEventHandler = { parameters: {}, [EVENT_TYPE_MEMBER_NAME]: "" }; - events = [...events, newEventHandler]; - onPropChanged(newEventType, events); + // TODO: improve - just pass the event from props + selectedEvent = { + ...selectedEvent, + handlers: [...(selectedEvent.handlers || []), newEventHandler] + }; + // events = [...events, newEventHandler]; + onPropChanged(newEventType, [...selectedEvent.handlers, newEventHandler]); }; - const changeEventHandler = newEvent => { - console.log({ events, newEventType, newEvent }); - onPropChanged(newEventType, events); + const changeEventHandler = (updatedHandler, index) => { + // TODO: Improve + const handlers = [...selectedEvent.handlers]; + handlers[index] = updatedHandler; + + console.log("CHANGED HANDLERS", handlers); + + selectedEvent = { + ...selectedEvent, + handlers + }; + + onPropChanged(newEventType, handlers); }; - const removeEventHandler = index => () => { - events = filter(e => e !== events[index])(events); - onPropChanged(newEventType, []); + // TODO: verify + const removeEventHandler = index => { + const handlers = [...selectedEvent.handlers]; + handlers.splice(index, 1); + onPropChanged(newEventType, handlers); }; - console.log(events); + console.log("DA HANDLERS", selectedEvent.handlers); -

    Events

    +
    +

    Events

    + openModal({})} /> +
    - {#each events as event, index} -
    - {event[0]} - openModal({ ...event, index })} /> -
    + {#each events as [name, handlers], index} + {#if handlers.length > 0} +
    openModal({ name, handlers, index })}> + {name} + EDIT + updateState +
    + {/if} {/each}
    -
    -

    {action} Event

    - {#if selectedEvent} - {JSON.stringify(selectedEvent)} - - {:else} - - -
    - -
    - +

    Create a New Component Event

    + Click here to learn more about component events + +

    Event Name

    + + +

    Event Type

    + + +

    Event Action(s)

    + {#if selectedEvent.handlers} + {#each selectedEvent.handlers as handler, index} + +
    + {/each} {/if} +
    addEventHandler(newEventType)}> + + Add Handler +
    diff --git a/packages/builder/src/userInterface/EventsEditor/HandlerSelector.svelte b/packages/builder/src/userInterface/EventsEditor/HandlerSelector.svelte new file mode 100644 index 0000000000..dffcb06278 --- /dev/null +++ b/packages/builder/src/userInterface/EventsEditor/HandlerSelector.svelte @@ -0,0 +1,112 @@ + + + + +
    + Action + + {#if parameters} + {#each parameters as param, index} +
    {param.name}
    + + {/each} + {/if} +
    diff --git a/packages/builder/src/userInterface/EventsEditor/index.js b/packages/builder/src/userInterface/EventsEditor/index.js index 7782e7fccd..e010de3c69 100644 --- a/packages/builder/src/userInterface/EventsEditor/index.js +++ b/packages/builder/src/userInterface/EventsEditor/index.js @@ -1 +1,7 @@ +export const deleteElement = (array, index) => { + const arr = [...array]; + array.splice(index, 1); + return arr; +}; + export { default } from "./EventsEditor.svelte"; \ No newline at end of file diff --git a/packages/server/app.js b/packages/server/app.js index 5cfc2a432c..974c9a3593 100644 --- a/packages/server/app.js +++ b/packages/server/app.js @@ -14,7 +14,7 @@ module.exports = async (budibaseContext) => { app.context.master, config.latestPackagesFolder ); - app.use(koaBody({ multipart : true })); + app.use(koaBody({ multipart: true })); app.use(router(config, app).routes()); return app.listen(config.port); }; From c064f08d557052dc36a03ec6c761d2e993413e7b Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 29 Jan 2020 22:59:10 +0000 Subject: [PATCH 3/8] started implementing state management designs --- .../builder/src/common/Icons/Events.svelte | 3 +- packages/builder/src/common/Select.svelte | 54 +++++++++ .../EventsEditor/EventEditorModal.svelte | 104 +++++++++++++----- .../EventsEditor/EventsEditor.svelte | 91 ++------------- .../EventsEditor/HandlerSelector.svelte | 41 ++++--- 5 files changed, 165 insertions(+), 128 deletions(-) create mode 100644 packages/builder/src/common/Select.svelte diff --git a/packages/builder/src/common/Icons/Events.svelte b/packages/builder/src/common/Icons/Events.svelte index d3728b9901..b7d92481e3 100644 --- a/packages/builder/src/common/Icons/Events.svelte +++ b/packages/builder/src/common/Icons/Events.svelte @@ -4,5 +4,6 @@ width="24" height="24"> - + diff --git a/packages/builder/src/common/Select.svelte b/packages/builder/src/common/Select.svelte new file mode 100644 index 0000000000..9053803ca7 --- /dev/null +++ b/packages/builder/src/common/Select.svelte @@ -0,0 +1,54 @@ + + + + +
    + + + {@html getIcon('chevron-down', '24')} + +
    diff --git a/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte b/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte index 6cb72f6310..3fa7ab44f9 100644 --- a/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte +++ b/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte @@ -1,49 +1,95 @@ - -

    {action} Event

    - -
    - - .prop-container { - flex: 1 1 auto; - min-width: 250px; - } - - .edit-icon:hover { - cursor: pointer; - } - \ No newline at end of file + + {#if event} +

    {event.name}

    + {:else} +

    Create a New Component Event

    + {/if} + Click here to learn more about component events + +
    +
    +
    Event Name
    + +
    + +
    +
    Event Type
    + +
    +
    + +
    Event Action(s)
    + {#if event.handlers} + {#each event.handlers as handler, index} + removeEventHandler(index)} + {handler} /> +
    + {/each} + {/if} +
    addEventHandler(newEventType)}> + + Add Handler +
    +
    diff --git a/packages/builder/src/userInterface/EventsEditor/EventsEditor.svelte b/packages/builder/src/userInterface/EventsEditor/EventsEditor.svelte index fa21f2c56a..2947ca1b42 100644 --- a/packages/builder/src/userInterface/EventsEditor/EventsEditor.svelte +++ b/packages/builder/src/userInterface/EventsEditor/EventsEditor.svelte @@ -17,6 +17,7 @@ import PlusButton from "../../common/PlusButton.svelte"; import IconButton from "../../common/IconButton.svelte"; import Modal from "../../common/Modal.svelte"; + import EventEditorModal from "./EventEditorModal.svelte"; import HandlerSelector from "./HandlerSelector.svelte"; import { PencilIcon } from "../../common/Icons"; @@ -28,12 +29,6 @@ export let onPropChanged = () => {}; export let components; - // Structure - // { - // [eventName]: [{eventHandler}, {eventHandler1}], - // [eventName1]: [{eventHandler}, {eventHandler1}], - // } - let modalOpen = false; let events = []; let selectedEvent = {}; @@ -41,15 +36,6 @@ // TODO: only show events that have handlers - // $: { - // let componentEvents = {}; - // for (let propName in componentInfo) { - // const isEventProp = findType(propName) === EVENT_TYPE; - // if (isEventProp) componentEvents[propName] = componentInfo[propName]; - // } - // events = componentEvents; - // } - $: events = componentInfo && Object.entries(componentInfo).filter( @@ -64,8 +50,6 @@ .props[propName]; } - console.log({ componentInfo, events, components }); - const openModal = event => { selectedEvent = event; modalOpen = true; @@ -111,8 +95,6 @@ handlers.splice(index, 1); onPropChanged(newEventType, handlers); }; - - console.log("DA HANDLERS", selectedEvent.handlers);
    @@ -210,7 +165,7 @@ {#each events as [name, handlers], index} {#if handlers.length > 0}
    openModal({ name, handlers, index })}> {name} EDIT @@ -220,37 +175,11 @@ {/each}
    - -

    Create a New Component Event

    - Click here to learn more about component events - -

    Event Name

    - - -

    Event Type

    - - -

    Event Action(s)

    - {#if selectedEvent.handlers} - {#each selectedEvent.handlers as handler, index} - -
    - {/each} - {/if} -
    addEventHandler(newEventType)}> - - Add Handler -
    -
    + diff --git a/packages/builder/src/userInterface/EventsEditor/HandlerSelector.svelte b/packages/builder/src/userInterface/EventsEditor/HandlerSelector.svelte index dffcb06278..9c30efb266 100644 --- a/packages/builder/src/userInterface/EventsEditor/HandlerSelector.svelte +++ b/packages/builder/src/userInterface/EventsEditor/HandlerSelector.svelte @@ -1,5 +1,6 @@ + + + + diff --git a/packages/builder/src/common/Input.svelte b/packages/builder/src/common/Input.svelte new file mode 100644 index 0000000000..04938b670a --- /dev/null +++ b/packages/builder/src/common/Input.svelte @@ -0,0 +1,27 @@ + + + + + diff --git a/packages/builder/src/common/Modal.svelte b/packages/builder/src/common/Modal.svelte index 0f47d553a0..3e716f5c9a 100644 --- a/packages/builder/src/common/Modal.svelte +++ b/packages/builder/src/common/Modal.svelte @@ -36,6 +36,7 @@ $: { .uk-modal-dialog { border-radius: .3rem; + width: 60%; } \ No newline at end of file diff --git a/packages/builder/src/common/Select.svelte b/packages/builder/src/common/Select.svelte index 9053803ca7..bebad32c38 100644 --- a/packages/builder/src/common/Select.svelte +++ b/packages/builder/src/common/Select.svelte @@ -14,21 +14,22 @@ select { display: block; - font-size: 16px; + font-size: 14px; font-family: sans-serif; - font-weight: 700; - color: #444; + font-weight: 500; + color: #163057; line-height: 1.3; padding: 1em 2.6em 0.9em 1.4em; width: 100%; max-width: 100%; box-sizing: border-box; margin: 0; - border-radius: 0.5em; -moz-appearance: none; -webkit-appearance: none; appearance: none; - background-color: #fafafa; + background: #fff; + border: 1px solid #ccc; + height: 50px; } .arrow { diff --git a/packages/builder/src/userInterface/ComponentPanel.svelte b/packages/builder/src/userInterface/ComponentPanel.svelte index 1fa8ce0642..d4d982f2e2 100644 --- a/packages/builder/src/userInterface/ComponentPanel.svelte +++ b/packages/builder/src/userInterface/ComponentPanel.svelte @@ -18,6 +18,7 @@ const onPropChanged = store.setComponentProp; const onStyleChanged = store.setComponentStyle; +
    diff --git a/packages/builder/src/userInterface/EventListSelector.svelte b/packages/builder/src/userInterface/EventListSelector.svelte deleted file mode 100644 index cfbe20345d..0000000000 --- a/packages/builder/src/userInterface/EventListSelector.svelte +++ /dev/null @@ -1,88 +0,0 @@ - - -
    -
    - {#each events as ev, index} - -
    - - -
    - -
    - {/each} - -
    - -
    -
    -
    - - - diff --git a/packages/builder/src/userInterface/EventSelector.svelte b/packages/builder/src/userInterface/EventSelector.svelte deleted file mode 100644 index e109d8122d..0000000000 --- a/packages/builder/src/userInterface/EventSelector.svelte +++ /dev/null @@ -1,105 +0,0 @@ - - -
    - - - - -
    - -{#if parameters} - {#each parameters as p, index} - -
    - {p.name} -
    - - - {/each} -{/if} - - diff --git a/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte b/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte index 3fa7ab44f9..74e3e956a2 100644 --- a/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte +++ b/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte @@ -1,19 +1,58 @@ - - {#if event} -

    {event.name}

    - {:else} -

    Create a New Component Event

    - {/if} - Click here to learn more about component events + +

    {eventData.name || "Create a New Component Event"}

    +

    Click here to learn more about component events

    -
    -
    Event Name
    - -
    -
    Event Type
    - + {#each events as event} + {/each}
    Event Action(s)
    - {#if event.handlers} - {#each event.handlers as handler, index} + { + createNewEventHandler(newEventHandler) + newEventHandler = { parameters: [] }; + }} + handler={newEventHandler} /> + {#if eventData} + {#each eventData.handlers as handler, index} removeEventHandler(index)} + onRemoved={() => deleteEventHandler(index)} {handler} /> -
    {/each} {/if} -
    addEventHandler(newEventType)}> - - Add Handler + +
    + Delete + Save
    diff --git a/packages/builder/src/userInterface/EventsEditor/EventsEditor.svelte b/packages/builder/src/userInterface/EventsEditor/EventsEditor.svelte index 2947ca1b42..f351befc8d 100644 --- a/packages/builder/src/userInterface/EventsEditor/EventsEditor.svelte +++ b/packages/builder/src/userInterface/EventsEditor/EventsEditor.svelte @@ -31,18 +31,13 @@ let modalOpen = false; let events = []; - let selectedEvent = {}; - let newEventType = "onClick"; + let selectedEvent = null; - // TODO: only show events that have handlers - - $: events = - componentInfo && - Object.entries(componentInfo).filter( - ([name]) => findType(name) == EVENT_TYPE - ); - - $: action = selectedEvent ? "Edit" : "Create"; + $: { + events = Object.keys(componentInfo) + .filter(key => componentInfo[key].length && findType(key) === EVENT_TYPE) + .map(key => ({ name: key, handlers: componentInfo[key] })); + } function findType(propName) { if (!componentInfo._component) return; @@ -56,45 +51,9 @@ }; const closeModal = () => { - selectedEvent = {}; + selectedEvent = null; modalOpen = false; }; - - const addEventHandler = eventType => { - const newEventHandler = { - parameters: {}, - [EVENT_TYPE_MEMBER_NAME]: "" - }; - // TODO: improve - just pass the event from props - selectedEvent = { - ...selectedEvent, - handlers: [...(selectedEvent.handlers || []), newEventHandler] - }; - // events = [...events, newEventHandler]; - onPropChanged(newEventType, [...selectedEvent.handlers, newEventHandler]); - }; - - const changeEventHandler = (updatedHandler, index) => { - // TODO: Improve - const handlers = [...selectedEvent.handlers]; - handlers[index] = updatedHandler; - - console.log("CHANGED HANDLERS", handlers); - - selectedEvent = { - ...selectedEvent, - handlers - }; - - onPropChanged(newEventType, handlers); - }; - - // TODO: verify - const removeEventHandler = index => { - const handlers = [...selectedEvent.handlers]; - handlers.splice(index, 1); - onPropChanged(newEventType, handlers); - };

    Events

    - openModal({})} /> + openModal()} />
    -
    - {#each events as [name, handlers], index} - {#if handlers.length > 0} + {#each events as event, index} + {#if event.handlers.length > 0}
    openModal({ name, handlers, index })}> - {name} + class="handler-container hierarchy-item {selectedEvent && selectedEvent.index === index ? 'selected' : ''}" + on:click={() => openModal({ ...event, index })}> + {event.name} + {event.name} EDIT - updateState
    {/if} {/each}
    + /> diff --git a/packages/builder/src/userInterface/EventsEditor/HandlerSelector.svelte b/packages/builder/src/userInterface/EventsEditor/HandlerSelector.svelte index 9c30efb266..b84f371f73 100644 --- a/packages/builder/src/userInterface/EventsEditor/HandlerSelector.svelte +++ b/packages/builder/src/userInterface/EventsEditor/HandlerSelector.svelte @@ -1,7 +1,8 @@ - -{#if isBound} -
    -
    -
    {isExpanded ? "" : bindingPath}
    - isExpanded=!isExpanded}/> - {#if !canOnlyBind} - - {/if} -
    - {#if isExpanded} -
    -
    Binding Path
    - -
    Fallback Value
    - -
    Binding Source
    - -
    - {/if} - -
    -{:else} -
    - - {#if type === "bool"} - -
    - 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/StateBindingControl.svelte b/packages/builder/src/userInterface/StateBindingControl.svelte index 32065a111e..2e5de88d6a 100644 --- a/packages/builder/src/userInterface/StateBindingControl.svelte +++ b/packages/builder/src/userInterface/StateBindingControl.svelte @@ -1,5 +1,6 @@ @@ -19,12 +20,16 @@ } .action-button:disabled { - color:#163057; + color: #163057; cursor: default; background: transparent; } + + .hidden { + visibility: hidden; + } - diff --git a/packages/builder/src/common/PlusButton.svelte b/packages/builder/src/common/PlusButton.svelte index b7ae19fcbf..7424ffa66e 100644 --- a/packages/builder/src/common/PlusButton.svelte +++ b/packages/builder/src/common/PlusButton.svelte @@ -4,7 +4,7 @@ outline: none; border: none; border-radius: 5px; - background: var(--background-button); + background: rgba(249, 249, 249, 1); width: 1.8rem; height: 1.8rem; @@ -16,7 +16,7 @@ font-size: 1.2rem; font-weight: 700; - color: var(--button-text); + color: rgba(22, 48, 87, 1); } diff --git a/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte b/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte index 74e3e956a2..9e93be7a60 100644 --- a/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte +++ b/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte @@ -10,15 +10,20 @@ import { EVENT_TYPE_MEMBER_NAME } from "../../common/eventHandlers"; export let event; - - export let events; + export let eventOptions; export let open; export let onClose; export let onPropChanged; let eventType = "onClick"; let newEventHandler = { parameters: [] }; - let eventData = event || { handlers: [] }; + + $: eventData = event || { handlers: [] }; + + const resetModalState = () => { + newEventHandler = { parameters: [] }; + eventData = { handlers: [] }; + }; const changeEventHandler = (updatedHandler, index) => { eventData.handlers[index] = updatedHandler; @@ -44,13 +49,13 @@ const deleteEvent = () => { onPropChanged(eventType, []); - eventData = { handlers: [] }; + resetModalState(); onClose(); }; const saveEventData = () => { onPropChanged(eventType, eventData.handlers); - eventData = { handlers: [] }; + resetModalState(); onClose(); }; @@ -79,18 +84,24 @@ display: flex; justify-content: space-between; } + + p { + color: rgba(22, 48, 87, 0.6); + font-size: 12px; + margin-top: 0; + } -

    {eventData.name || "Create a New Component Event"}

    +

    {eventData.name || 'Create a New Component Event'}

    Click here to learn more about component events

    Event Type
    @@ -100,8 +111,8 @@ { - createNewEventHandler(newEventHandler) + onCreate={() => { + createNewEventHandler(newEventHandler); newEventHandler = { parameters: [] }; }} handler={newEventHandler} /> @@ -116,7 +127,16 @@ {/if}
    - Delete - Save + + Delete + + + Save +
    diff --git a/packages/builder/src/userInterface/EventsEditor/EventsEditor.svelte b/packages/builder/src/userInterface/EventsEditor/EventsEditor.svelte index f351befc8d..01f235c016 100644 --- a/packages/builder/src/userInterface/EventsEditor/EventsEditor.svelte +++ b/packages/builder/src/userInterface/EventsEditor/EventsEditor.svelte @@ -35,7 +35,7 @@ $: { events = Object.keys(componentInfo) - .filter(key => componentInfo[key].length && findType(key) === EVENT_TYPE) + .filter(key => findType(key) === EVENT_TYPE) .map(key => ({ name: key, handlers: componentInfo[key] })); } @@ -85,6 +85,7 @@ display: grid; grid-template-columns: repeat(2, 1fr); border: 2px solid #f9f9f9; + height: 80px; } .hierarchy-item { @@ -101,16 +102,11 @@ } .event-name { - font-size: 12px; - color: rgba(35, 65, 105, 0.4); - grid-column: 1 / span 2; - } - - .event-identifier { margin-top: 5px; font-weight: bold; font-size: 16px; - color: rgba(22, 48, 87, 0.6) + color: rgba(22, 48, 87, 0.6); + align-self: end; } .edit-text { @@ -141,7 +137,6 @@ class="handler-container hierarchy-item {selectedEvent && selectedEvent.index === index ? 'selected' : ''}" on:click={() => openModal({ ...event, index })}> {event.name} - {event.name} EDIT
    {/if} @@ -150,8 +145,8 @@
    diff --git a/packages/builder/src/userInterface/EventsEditor/HandlerSelector.svelte b/packages/builder/src/userInterface/EventsEditor/HandlerSelector.svelte index b84f371f73..d3ec42557e 100644 --- a/packages/builder/src/userInterface/EventsEditor/HandlerSelector.svelte +++ b/packages/builder/src/userInterface/EventsEditor/HandlerSelector.svelte @@ -107,12 +107,20 @@ grid-gap: 10px; padding: 22px; } + + .event-action-button { + margin-right: 20px; + } + + span { + margin-bottom: 5px; + }
    - Action + Action + on:change={setBindingPath} >
    Fallback Value
    - + on:change={setBindingFallback} >
    Binding Source
    onChanged(ev.target.value)} - bind:value={value} - style="flex: 1 0 auto;" /> + onChanged(ev.target.value)} + bind:value={value} /> {/if}
    From 96c61a5a7d8ce051d92facb29ec448ea81cfe7b8 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 30 Jan 2020 21:00:19 +0000 Subject: [PATCH 6/8] styling updates --- .../builder/src/common/ActionButton.svelte | 2 +- packages/builder/src/common/Modal.svelte | 1 + .../EventsEditor/EventEditorModal.svelte | 20 +++++++++++------- .../EventsEditor/HandlerSelector.svelte | 21 +++++++++---------- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/packages/builder/src/common/ActionButton.svelte b/packages/builder/src/common/ActionButton.svelte index 092123b47c..dd00966c49 100644 --- a/packages/builder/src/common/ActionButton.svelte +++ b/packages/builder/src/common/ActionButton.svelte @@ -20,7 +20,7 @@ } .action-button:disabled { - color: #163057; + color: rgba(22, 48, 87, 0.2); cursor: default; background: transparent; } diff --git a/packages/builder/src/common/Modal.svelte b/packages/builder/src/common/Modal.svelte index 3e716f5c9a..19db3b064e 100644 --- a/packages/builder/src/common/Modal.svelte +++ b/packages/builder/src/common/Modal.svelte @@ -37,6 +37,7 @@ $: { .uk-modal-dialog { border-radius: .3rem; width: 60%; + height: 80vh; } \ No newline at end of file diff --git a/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte b/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte index 9e93be7a60..5c288084e6 100644 --- a/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte +++ b/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte @@ -6,6 +6,7 @@ import PlusButton from "../../common/PlusButton.svelte"; import Select from "../../common/Select.svelte"; import Input from "../../common/Input.svelte"; + import getIcon from "../../common/icon"; import { EVENT_TYPE_MEMBER_NAME } from "../../common/eventHandlers"; @@ -70,8 +71,9 @@ h5 { color: rgba(22, 48, 87, 0.6); - font-size: 16px; + font-size: 15px; margin-bottom: 5px; + margin-top: 20px; } .event-options { @@ -80,12 +82,13 @@ grid-gap: 10px; } - .actions { + .actions, header { display: flex; justify-content: space-between; + align-items: center; } - p { + a { color: rgba(22, 48, 87, 0.6); font-size: 12px; margin-top: 0; @@ -93,13 +96,16 @@ -

    {eventData.name || 'Create a New Component Event'}

    -

    Click here to learn more about component events

    +

    {eventData.name ? `${eventData.name} Event` : 'Create a New Component Event'}

    + Click here to learn more about component events
    -
    Event Type
    - {#each eventOptions as option} {/each} diff --git a/packages/builder/src/userInterface/EventsEditor/HandlerSelector.svelte b/packages/builder/src/userInterface/EventsEditor/HandlerSelector.svelte index d3ec42557e..e22a992fe7 100644 --- a/packages/builder/src/userInterface/EventsEditor/HandlerSelector.svelte +++ b/packages/builder/src/userInterface/EventsEditor/HandlerSelector.svelte @@ -31,7 +31,6 @@ }) ); - // TODO: refactor $: { if (handler) { handlerType = handler[EVENT_TYPE_MEMBER_NAME]; @@ -40,6 +39,7 @@ value })); } else { + // Empty Handler handlerType = ""; parameters = []; } @@ -63,11 +63,11 @@ const handlerType = eventOptions.find( handler => handler.name === e.target.value ); - // Set default params for handler const defaultParams = handlerType.parameters.map(param => ({ name: param, value: "" })); + handlerChanged(handlerType.name, defaultParams); }; @@ -93,10 +93,6 @@ flex-direction: column; } - .handler-option > div { - margin-bottom: 5px; - } - .new-handler { background: #fff; } @@ -113,6 +109,7 @@ } span { + font-size: 12px; margin-bottom: 5px; } @@ -131,7 +128,7 @@ {#if parameters} {#each parameters as param, idx}
    -
    {param.name}
    + {param.name} @@ -140,10 +137,12 @@ {/if}
    - {#if newHandler} - - {:else} - + {#if parameters.length > 0} + {#if newHandler} + + {:else} + + {/if} {/if}
    From 8d656596c71a9d0d00495f535d821c1615bcaeb8 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Fri, 31 Jan 2020 09:45:02 +0000 Subject: [PATCH 7/8] final touches for design --- .../builder/src/common/ActionButton.svelte | 28 ++++++-- packages/builder/src/common/Modal.svelte | 61 +++++++++--------- .../EventsEditor/EventEditorModal.svelte | 64 ++++++++++++------- .../EventsEditor/EventsEditor.svelte | 6 +- 4 files changed, 97 insertions(+), 62 deletions(-) diff --git a/packages/builder/src/common/ActionButton.svelte b/packages/builder/src/common/ActionButton.svelte index dd00966c49..fca74c09ff 100644 --- a/packages/builder/src/common/ActionButton.svelte +++ b/packages/builder/src/common/ActionButton.svelte @@ -1,12 +1,23 @@ - diff --git a/packages/builder/src/common/Modal.svelte b/packages/builder/src/common/Modal.svelte index 19db3b064e..5d695d0fc1 100644 --- a/packages/builder/src/common/Modal.svelte +++ b/packages/builder/src/common/Modal.svelte @@ -1,43 +1,44 @@ -
    -
    - -
    -
    - - - \ No newline at end of file +
    +
    + {#if onClosed} +
    +
    diff --git a/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte b/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte index 5c288084e6..290381c5dc 100644 --- a/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte +++ b/packages/builder/src/userInterface/EventsEditor/EventEditorModal.svelte @@ -17,21 +17,22 @@ export let onPropChanged; let eventType = "onClick"; - let newEventHandler = { parameters: [] }; + let draftEventHandler = { parameters: [] }; $: eventData = event || { handlers: [] }; - const resetModalState = () => { - newEventHandler = { parameters: [] }; + const closeModal = () => { + onClose(); + draftEventHandler = { parameters: [] }; eventData = { handlers: [] }; }; - const changeEventHandler = (updatedHandler, index) => { + const updateEventHandler = (updatedHandler, index) => { eventData.handlers[index] = updatedHandler; }; - const changeNewEventHandler = updatedHandler => { - newEventHandler = updatedHandler; + const updateDraftEventHandler = updatedHandler => { + draftEventHandler = updatedHandler; }; const deleteEventHandler = index => { @@ -50,14 +51,12 @@ const deleteEvent = () => { onPropChanged(eventType, []); - resetModalState(); - onClose(); + closeModal(); }; const saveEventData = () => { onPropChanged(eventType, eventData.handlers); - resetModalState(); - onClose(); + closeModal(); }; @@ -72,8 +71,7 @@ h5 { color: rgba(22, 48, 87, 0.6); font-size: 15px; - margin-bottom: 5px; - margin-top: 20px; + margin: 0; } .event-options { @@ -82,12 +80,22 @@ grid-gap: 10px; } - .actions, header { + .actions, + header { display: flex; justify-content: space-between; align-items: center; } + .actions { + margin-top: auto; + } + + header { + margin-top: 30px; + margin-bottom: 10px; + } + a { color: rgba(22, 48, 87, 0.6); font-size: 12px; @@ -95,15 +103,19 @@ } - -

    {eventData.name ? `${eventData.name} Event` : 'Create a New Component Event'}

    - Click here to learn more about component events + +

    + {eventData.name ? `${eventData.name} Event` : 'Create a New Component Event'} +

    + + Click here to learn more about component events +
    Event Type
    - {@html getIcon('info')} + {@html getIcon('info', 20)}