From 37ca0ee1d84f50a981b96d3421b693af666110cf Mon Sep 17 00:00:00 2001 From: kevmodrome Date: Wed, 22 Apr 2020 08:25:59 +0200 Subject: [PATCH] makes the Component panel tabs more generic --- .../ComponentSelectionList.svelte | 32 ++++++++++------ .../{ComponentTab => ItemTab}/Item.svelte | 28 +++++++------- .../{ComponentTab => ItemTab}/Tab.svelte | 25 +++++------- .../userInterface/temporaryPanelStructure.js | 38 +++++++++---------- 4 files changed, 62 insertions(+), 61 deletions(-) rename packages/builder/src/components/userInterface/{ComponentTab => ItemTab}/Item.svelte (64%) rename packages/builder/src/components/userInterface/{ComponentTab => ItemTab}/Tab.svelte (53%) diff --git a/packages/builder/src/components/userInterface/ComponentSelectionList.svelte b/packages/builder/src/components/userInterface/ComponentSelectionList.svelte index 12159f675c..d769321de1 100644 --- a/packages/builder/src/components/userInterface/ComponentSelectionList.svelte +++ b/packages/builder/src/components/userInterface/ComponentSelectionList.svelte @@ -20,7 +20,7 @@ pipe, } from "components/common/core" - import Tab from "./ComponentTab/Tab.svelte" + import Tab from "./ItemTab/Tab.svelte" import { store } from "builderStore" export let toggleTab @@ -51,6 +51,15 @@ selectTemplateDialog.show() } + const onComponentChosen = component => { + if (component.template) { + onTemplateChosen(component.template) + } else { + store.addChildComponent(component._component) + toggleTab() + } + } + const onTemplateInstanceChosen = () => { selectedComponent = null const instance = templateInstances.find( @@ -63,16 +72,13 @@ $: templatesByComponent = groupBy(t => t.component)($store.templates) $: hierarchy = $store.hierarchy $: libraryModules = $store.libraries - $: standaloneTemplates = pipe( - templatesByComponent, - [ - values, - flatten, - filter(t => !$store.components.some(c => c.name === t.component)), - map(t => ({ name: splitName(t.component).componentName, template: t })), - uniqBy(t => t.name), - ] - ) + $: standaloneTemplates = pipe(templatesByComponent, [ + values, + flatten, + filter(t => !$store.components.some(c => c.name === t.component)), + map(t => ({ name: splitName(t.component).componentName, template: t })), + uniqBy(t => t.name), + ])
@@ -86,7 +92,9 @@ {/each}
- + onComponentChosen(e.detail)} />
diff --git a/packages/builder/src/components/userInterface/ComponentTab/Item.svelte b/packages/builder/src/components/userInterface/ItemTab/Item.svelte similarity index 64% rename from packages/builder/src/components/userInterface/ComponentTab/Item.svelte rename to packages/builder/src/components/userInterface/ItemTab/Item.svelte index 5730df484c..23d978813f 100644 --- a/packages/builder/src/components/userInterface/ComponentTab/Item.svelte +++ b/packages/builder/src/components/userInterface/ItemTab/Item.svelte @@ -1,21 +1,21 @@ -
-
- +
+
+
-
-
{component.name}
-
-

{component.description}

+
+
{item.name}
+
+

{item.description}