diff --git a/packages/builder/src/builderStore/insertCodeMetadata.js b/packages/builder/src/builderStore/insertCodeMetadata.js new file mode 100644 index 0000000000..00c18901b5 --- /dev/null +++ b/packages/builder/src/builderStore/insertCodeMetadata.js @@ -0,0 +1,17 @@ +export const insertCodeMetadata = props => { + if (props._code && props._code.length > 0) { + props._codeMeta = codeMetaData(props._code) + } + + if (!props._children || props._children.length === 0) return + + for (let child of props._children) { + insertCodeMetadata(child) + } +} + +const codeMetaData = code => { + return { + dependsOnStore: RegExp(/(store.)/g).test(code), + } +} diff --git a/packages/builder/src/builderStore/store.js b/packages/builder/src/builderStore/store.js index 2e83bc820e..ead7e51109 100644 --- a/packages/builder/src/builderStore/store.js +++ b/packages/builder/src/builderStore/store.js @@ -40,6 +40,7 @@ import { } from "./loadComponentLibraries" import { buildCodeForScreens } from "./buildCodeForScreens" import { generate_screen_css } from "./generate_css" +import { insertCodeMetadata } from "./insertCodeMetadata" // import { uuid } from "./uuid" let appname = "" @@ -115,6 +116,7 @@ export const getStore = () => { store.setComponentStyle = setComponentStyle(store) store.setComponentCode = setComponentCode(store) store.setScreenType = setScreenType(store) + store.deleteComponent = deleteComponent(store) return store } @@ -824,6 +826,8 @@ const setCurrentScreenFunctions = s => { s.currentPreviewItem === "screen" ? buildCodeForScreens([s.currentPreviewItem]) : "({});" + + insertCodeMetadata(s.currentPreviewItem.props) } const setScreenType = store => type => { @@ -840,3 +844,39 @@ const setScreenType = store => type => { return s }) } + +const deleteComponent = store => component => { + store.update(s => { + let parent + walkProps(s.currentPreviewItem.props, (p, breakWalk) => { + if (p._children.includes(component)) { + parent = p + breakWalk() + } + }) + + if (parent) { + parent._children = parent._children.filter(c => c !== component) + } + + s.currentFrontEndType === "page" + ? _savePage(s) + : _saveScreenApi(s.currentPreviewItem, s) + + return s + }) +} + +const walkProps = (props, action, cancelToken = null) => { + cancelToken = cancelToken || { cancelled: false } + action(props, () => { + cancelToken.cancelled = true + }) + + if (props._children) { + for (let child of props._children) { + if (cancelToken.cancelled) return + walkProps(child, action, cancelToken) + } + } +} diff --git a/packages/builder/src/common/ConfirmDialog.svelte b/packages/builder/src/common/ConfirmDialog.svelte new file mode 100644 index 0000000000..592b73a395 --- /dev/null +++ b/packages/builder/src/common/ConfirmDialog.svelte @@ -0,0 +1,55 @@ + + + +
+
+ +
+

{title}

+
+
{body}
+ +
+
+ diff --git a/packages/builder/src/common/Icons/XCircle.svelte b/packages/builder/src/common/Icons/XCircle.svelte new file mode 100644 index 0000000000..1b0aae0a20 --- /dev/null +++ b/packages/builder/src/common/Icons/XCircle.svelte @@ -0,0 +1,23 @@ + + + + + + + + \ 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 32a450cffd..7258d4c90c 100644 --- a/packages/builder/src/common/Icons/index.js +++ b/packages/builder/src/common/Icons/index.js @@ -7,3 +7,4 @@ export { default as ArrowDownIcon } from "./ArrowDown.svelte" export { default as CircleIndicator } from "./CircleIndicator.svelte" export { default as PencilIcon } from "./Pencil.svelte" export { default as EventsIcon } from "./Events.svelte" +export { default as XCircleIcon } from "./XCircle.svelte" diff --git a/packages/builder/src/userInterface/ComponentsHierarchy.svelte b/packages/builder/src/userInterface/ComponentsHierarchy.svelte index 5c5917c536..274615c9cc 100644 --- a/packages/builder/src/userInterface/ComponentsHierarchy.svelte +++ b/packages/builder/src/userInterface/ComponentsHierarchy.svelte @@ -2,13 +2,16 @@ import ComponentsHierarchyChildren from "./ComponentsHierarchyChildren.svelte" import { last, sortBy, map, trimCharsStart, trimChars, join } from "lodash/fp" - + import ConfirmDialog from "../common/ConfirmDialog.svelte" import { pipe } from "../common/core" import { store } from "../builderStore" import { ArrowDownIcon } from "../common/Icons/" export let screens = [] + let confirmDeleteDialog + let componentToDelete = "" + const joinPath = join("/") const normalizedName = name => @@ -23,6 +26,7 @@ ) const lastPartOfName = c => + c && last(c.name ? c.name.split("/") : c._component.split("/")) const isComponentSelected = (current, comp) => current === comp @@ -38,6 +42,12 @@ component.component && $store.currentPreviewItem && component.component.name === $store.currentPreviewItem.name + + const confirmDeleteComponent = component => { + componentToDelete = component + confirmDeleteDialog.show() + } +
@@ -63,12 +73,20 @@ + onSelect={store.selectComponent} + onDeleteComponent={confirmDeleteComponent}/> {/if} {/each}
+ store.deleteComponent(componentToDelete)}/> +