From a88db662bf084c4eee74e4ec0a9d7600ef81eda0 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 29 Jan 2020 21:04:48 +0000 Subject: [PATCH] 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); };