From 168ec6634ea2ae493319b53d79caac08b806b578 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 26 Apr 2022 13:44:21 +0100 Subject: [PATCH] Add back in working component tree with scrolling and dropdown menus --- packages/builder/src/builderStore/index.js | 25 ++-- .../src/builderStore/store/frontend.js | 40 ++---- .../AppPanel/ComponentSelectionList.svelte | 114 ------------------ .../FrontendNavigatePane.svelte | 12 -- .../NavigationPanel/NavigationPanel.svelte | 14 ++- .../ComponentNavigationTree.svelte} | 11 +- .../LayoutDropdownMenu.svelte | 0 .../PathDropdownMenu.svelte | 0 .../PathTree.svelte | 7 +- .../design/_components/AppPanel.svelte | 2 +- .../design/_components/AppPreview.svelte | 5 +- .../_components}/ComponentDropdownMenu.svelte | 0 .../ComponentNavigationPanel.svelte | 95 +++++++++++++-- .../_components}/ComponentTree.svelte | 13 +- .../_components/ScreenslotDropdownMenu.svelte | 52 ++++++++ .../_components}/dragDropStore.js | 0 .../[screenId]/[componentId]/_layout.svelte | 30 +++++ .../components/[screenId]/_layout.svelte | 1 + .../design/components/[screenId]/index.svelte | 2 +- ...tPanel.svelte => NewComponentPanel.svelte} | 18 ++- .../NewComponentTargetPanel.svelte | 10 ++ .../components/[screenId]/new/index.svelte | 6 +- .../_components/ScreenNavigationPanel.svelte | 13 ++ .../[application]/design/theme/index.svelte | 4 +- 24 files changed, 260 insertions(+), 214 deletions(-) delete mode 100644 packages/builder/src/components/design/AppPanel/ComponentSelectionList.svelte rename packages/builder/src/components/design/{NavigationPanel/ComponentNavigationTree/index.svelte => _old/ComponentNavigationTree.svelte} (89%) rename packages/builder/src/components/design/{NavigationPanel/ComponentNavigationTree => _old}/LayoutDropdownMenu.svelte (100%) rename packages/builder/src/components/design/{NavigationPanel/ComponentNavigationTree => _old}/PathDropdownMenu.svelte (100%) rename packages/builder/src/components/design/{NavigationPanel/ComponentNavigationTree => _old}/PathTree.svelte (92%) rename packages/builder/src/{components/design/NavigationPanel/ComponentNavigationTree => pages/builder/app/[application]/design/components/[screenId]/[componentId]/_components}/ComponentDropdownMenu.svelte (100%) rename packages/builder/src/{components/design/NavigationPanel/ComponentNavigationTree => pages/builder/app/[application]/design/components/[screenId]/[componentId]/_components}/ComponentTree.svelte (94%) create mode 100644 packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/[componentId]/_components/ScreenslotDropdownMenu.svelte rename packages/builder/src/{components/design/NavigationPanel/ComponentNavigationTree => pages/builder/app/[application]/design/components/[screenId]/[componentId]/_components}/dragDropStore.js (100%) create mode 100644 packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/[componentId]/_layout.svelte rename packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/new/_components/{ComponentListPanel.svelte => NewComponentPanel.svelte} (89%) create mode 100644 packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/new/_components/NewComponentTargetPanel.svelte diff --git a/packages/builder/src/builderStore/index.js b/packages/builder/src/builderStore/index.js index 9d7c3ca128..3a9b84b2c5 100644 --- a/packages/builder/src/builderStore/index.js +++ b/packages/builder/src/builderStore/index.js @@ -2,7 +2,7 @@ import { getFrontendStore } from "./store/frontend" import { getAutomationStore } from "./store/automation" import { getThemeStore } from "./store/theme" import { derived, writable } from "svelte/store" -import { FrontendTypes, LAYOUT_NAMES } from "../constants" +import { LAYOUT_NAMES } from "../constants" import { findComponent, findComponentPath } from "./componentUtils" export const store = getFrontendStore() @@ -13,32 +13,26 @@ export const selectedScreen = derived(store, $store => { return $store.screens.find(screen => screen._id === $store.selectedScreenId) }) -export const currentAsset = selectedScreen - export const selectedComponent = derived( - [store, currentAsset], - ([$store, $currentAsset]) => { - if (!$currentAsset || !$store.selectedComponentId) { + [store, selectedScreen], + ([$store, $selectedScreen]) => { + if (!$selectedScreen || !$store.selectedComponentId) { return null } - return findComponent($currentAsset?.props, $store.selectedComponentId) + return findComponent($selectedScreen?.props, $store.selectedComponentId) } ) export const selectedComponentPath = derived( - [store, currentAsset], - ([$store, $currentAsset]) => { + [store, selectedScreen], + ([$store, $selectedScreen]) => { return findComponentPath( - $currentAsset?.props, + $selectedScreen?.props, $store.selectedComponentId ).map(component => component._id) } ) -export const currentAssetName = derived(currentAsset, $currentAsset => { - return $currentAsset?.name -}) - export const mainLayout = derived(store, $store => { return $store.layouts?.find( layout => layout._id === LAYOUT_NAMES.MASTER.PRIVATE @@ -47,4 +41,5 @@ export const mainLayout = derived(store, $store => { export const selectedAccessRole = writable("BASIC") -export const screenSearchString = writable(null) +// For compatibility +export const currentAsset = selectedScreen diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index fe6721324e..8827aea3a8 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -48,7 +48,6 @@ const INITIAL_FRONTEND_STATE = { }, currentFrontEndType: "none", selectedLayoutId: "", - selectedComponentId: "", errors: [], hasAppPackage: false, libraries: null, @@ -61,6 +60,7 @@ const INITIAL_FRONTEND_STATE = { // URL params selectedScreenId: null, + selectedComponentId: null, } export const getFrontendStore = () => { @@ -300,32 +300,6 @@ export const getFrontendStore = () => { }, }, components: { - select: component => { - const asset = get(currentAsset) - if (!asset || !component) { - return - } - - // If this is the root component, select the asset instead - const parent = findComponentParent(asset.props, component._id) - if (parent == null) { - const state = get(store) - const isLayout = state.currentFrontEndType === FrontendTypes.LAYOUT - if (isLayout) { - store.actions.layouts.select(asset._id) - } else { - store.actions.screens.select(asset._id) - } - return - } - - // Otherwise select the component - store.update(state => { - state.selectedComponentId = component._id - state.currentView = "component" - return state - }) - }, getDefinition: componentName => { if (!componentName) { return null @@ -464,7 +438,10 @@ export const getFrontendStore = () => { parent._children = parent._children.filter( child => child._id !== component._id ) - store.actions.components.select(parent) + store.update(state => { + state.selectedComponentId = parent._id + return state + }) } await store.actions.preview.saveSelected() }, @@ -488,7 +465,10 @@ export const getFrontendStore = () => { parent._children = parent._children.filter( child => child._id !== component._id ) - store.actions.components.select(parent) + store.update(state => { + state.selectedComponentId = parent._id + return state + }) } } }, @@ -539,7 +519,7 @@ export const getFrontendStore = () => { // Save and select the new component promises.push(store.actions.preview.saveSelected()) - store.actions.components.select(componentToPaste) + state.selectedComponentId = componentToPaste._id return state }) await Promise.all(promises) diff --git a/packages/builder/src/components/design/AppPanel/ComponentSelectionList.svelte b/packages/builder/src/components/design/AppPanel/ComponentSelectionList.svelte deleted file mode 100644 index cabcea756e..0000000000 --- a/packages/builder/src/components/design/AppPanel/ComponentSelectionList.svelte +++ /dev/null @@ -1,114 +0,0 @@ - - -
- {#each enrichedStructure as item} - - onItemChosen(item)} - > -
- {item.name} - {#if item.isCategory} - - {/if} -
-
- {#each item.children || [] as item} - {#if !item.showOnAsset || item.showOnAsset.includes($currentAssetName)} - onItemChosen(item)} - disabled={isChildAllowed(item, $selectedComponent)} - > - {item.name} - - {/if} - {/each} -
- {/each} -
- - diff --git a/packages/builder/src/components/design/NavigationPanel/FrontendNavigatePane.svelte b/packages/builder/src/components/design/NavigationPanel/FrontendNavigatePane.svelte index c100a52329..9d8d1cc8cc 100644 --- a/packages/builder/src/components/design/NavigationPanel/FrontendNavigatePane.svelte +++ b/packages/builder/src/components/design/NavigationPanel/FrontendNavigatePane.svelte @@ -127,9 +127,6 @@
-
@@ -190,15 +187,6 @@ gap: var(--spacing-xl); } - .nav-items-container { - border-top: var(--border-light); - margin: 0 calc(-1 * var(--spacing-xl)); - padding: var(--spacing-m) 0; - flex: 1 1 auto; - overflow: auto; - height: 0; - position: relative; - } .nav-items-container--layouts { border-top: none; margin-top: calc(-1 * var(--spectrum-global-dimension-static-size-150)); diff --git a/packages/builder/src/components/design/NavigationPanel/NavigationPanel.svelte b/packages/builder/src/components/design/NavigationPanel/NavigationPanel.svelte index 1dcebb4b62..b295182562 100644 --- a/packages/builder/src/components/design/NavigationPanel/NavigationPanel.svelte +++ b/packages/builder/src/components/design/NavigationPanel/NavigationPanel.svelte @@ -23,7 +23,9 @@ {/if} - +
+ +
diff --git a/packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/index.svelte b/packages/builder/src/components/design/_old/ComponentNavigationTree.svelte similarity index 89% rename from packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/index.svelte rename to packages/builder/src/components/design/_old/ComponentNavigationTree.svelte index ed064f8307..a2032441c3 100644 --- a/packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/index.svelte +++ b/packages/builder/src/components/design/_old/ComponentNavigationTree.svelte @@ -64,20 +64,11 @@ {#each paths as path, idx (path)} 0} {path} route={routes[path]} /> {/each} - {#if !paths.length} -
- There aren't any screens configured with this access role. -
- {/if} + {#if !paths.length}{/if} diff --git a/packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/LayoutDropdownMenu.svelte b/packages/builder/src/components/design/_old/LayoutDropdownMenu.svelte similarity index 100% rename from packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/LayoutDropdownMenu.svelte rename to packages/builder/src/components/design/_old/LayoutDropdownMenu.svelte diff --git a/packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/PathDropdownMenu.svelte b/packages/builder/src/components/design/_old/PathDropdownMenu.svelte similarity index 100% rename from packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/PathDropdownMenu.svelte rename to packages/builder/src/components/design/_old/PathDropdownMenu.svelte diff --git a/packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/PathTree.svelte b/packages/builder/src/components/design/_old/PathTree.svelte similarity index 92% rename from packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/PathTree.svelte rename to packages/builder/src/components/design/_old/PathTree.svelte index 30520a6212..110338e733 100644 --- a/packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/PathTree.svelte +++ b/packages/builder/src/components/design/_old/PathTree.svelte @@ -1,10 +1,5 @@ $goto("../new")} > - - (searchString = e.detail)} + + + diff --git a/packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/ComponentTree.svelte b/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/[componentId]/_components/ComponentTree.svelte similarity index 94% rename from packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/ComponentTree.svelte rename to packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/[componentId]/_components/ComponentTree.svelte index 6b78bc40c1..e0a40cda30 100644 --- a/packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/ComponentTree.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/[componentId]/_components/ComponentTree.svelte @@ -9,16 +9,11 @@ export let components = [] export let currentComponent - export let onSelect = () => {} export let level = 0 export let dragDropStore let closedNodes = {} - const selectComponent = component => { - store.actions.components.select(component) - } - const dragstart = component => e => { e.dataTransfer.dropEffect = DropEffect.MOVE dragDropStore.actions.dragstart(component) @@ -86,7 +81,11 @@
    {#each components || [] as component, index (component._id)} -
  • selectComponent(component)}> +
  • { + $store.selectedComponentId = component._id + }} + > {#if $dragDropStore?.targetComponent === component && $dragDropStore.dropPosition === DropPosition.ABOVE}
    diff --git a/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/[componentId]/_components/ScreenslotDropdownMenu.svelte b/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/[componentId]/_components/ScreenslotDropdownMenu.svelte new file mode 100644 index 0000000000..7ec7b0821c --- /dev/null +++ b/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/[componentId]/_components/ScreenslotDropdownMenu.svelte @@ -0,0 +1,52 @@ + + +{#if showMenu} + +
    + +
    + storeComponentForCopy(false)}> + Copy + + pasteComponent("inside")} + disabled={noPaste} + > + Paste inside + +
    +{/if} + + diff --git a/packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/dragDropStore.js b/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/[componentId]/_components/dragDropStore.js similarity index 100% rename from packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/dragDropStore.js rename to packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/[componentId]/_components/dragDropStore.js diff --git a/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/[componentId]/_layout.svelte b/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/[componentId]/_layout.svelte new file mode 100644 index 0000000000..c877bba443 --- /dev/null +++ b/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/[componentId]/_layout.svelte @@ -0,0 +1,30 @@ + + + diff --git a/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/_layout.svelte b/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/_layout.svelte index 5a8d26a452..491db67ddd 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/_layout.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/_layout.svelte @@ -18,6 +18,7 @@ params, goto, redirect, + baseUrl: "..", }) onDestroy(stopSyncing) diff --git a/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/index.svelte b/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/index.svelte index e7f6eca5d7..02ce985c9f 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/index.svelte @@ -6,7 +6,7 @@ onMount(() => { if ($selectedScreen) { // Select the screen slot if a screen exists - $redirect(`./slot`) + $redirect(`./${$selectedScreen.props._id}`) } else { // Otherwise go up so we can select a new valid screen $redirect("../") diff --git a/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/new/_components/ComponentListPanel.svelte b/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/new/_components/NewComponentPanel.svelte similarity index 89% rename from packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/new/_components/ComponentListPanel.svelte rename to packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/new/_components/NewComponentPanel.svelte index 6927bc8f15..b3315403af 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/new/_components/ComponentListPanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/new/_components/NewComponentPanel.svelte @@ -10,6 +10,7 @@ Icon, Body, Divider, + notifications, } from "@budibase/bbui" import structure from "./componentStructure.json" import { store } from "builderStore" @@ -75,7 +76,20 @@ return structure } - const addComponent = () => {} + const isChildAllowed = ({ name }, selectedComponent) => { + const currentComponent = store.actions.components.getDefinition( + selectedComponent?._component + ) + return currentComponent?.illegalChildren?.includes(name.toLowerCase()) + } + + const addComponent = async item => { + try { + await store.actions.components.create(item.component) + } catch (error) { + notifications.error("Error creating component") + } + } - Blocks are a collection of pre-built components + Blocks are a collection of pre-built components {#each blocks as block}
    diff --git a/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/new/_components/NewComponentTargetPanel.svelte b/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/new/_components/NewComponentTargetPanel.svelte new file mode 100644 index 0000000000..fd43983d9c --- /dev/null +++ b/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/new/_components/NewComponentTargetPanel.svelte @@ -0,0 +1,10 @@ + + + + + The component you add will be placed inside Screen + + diff --git a/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/new/index.svelte b/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/new/index.svelte index ac287edf6f..4f8a42c6d4 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/new/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/components/[screenId]/new/index.svelte @@ -1,5 +1,7 @@ - + + diff --git a/packages/builder/src/pages/builder/app/[application]/design/screens/_components/ScreenNavigationPanel.svelte b/packages/builder/src/pages/builder/app/[application]/design/screens/_components/ScreenNavigationPanel.svelte index 5f37f1f4a5..9728fb43c9 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/screens/_components/ScreenNavigationPanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/screens/_components/ScreenNavigationPanel.svelte @@ -67,6 +67,19 @@ {/each} + {#if !filteredScreens?.length} +
    + There aren't any screens matching the current filters +
    + {/if} + + diff --git a/packages/builder/src/pages/builder/app/[application]/design/theme/index.svelte b/packages/builder/src/pages/builder/app/[application]/design/theme/index.svelte index 8687344ca7..f21267d810 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/theme/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/theme/index.svelte @@ -6,9 +6,7 @@ - - Your theme is set across all the screens within your app - + Your theme is set across all the screens within your app