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 @@ + + + +