From 976904686e37a59aea181805a03c234a7e3358d7 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 17 May 2022 14:33:12 +0100 Subject: [PATCH] Add icons to app preview selection indicators --- .../client/src/components/Component.svelte | 15 ++---- .../src/components/preview/Indicator.svelte | 46 ++++++++++++++----- .../components/preview/IndicatorSet.svelte | 15 +++++- .../src/components/preview/SettingsBar.svelte | 2 +- packages/client/src/stores/components.js | 7 +++ 5 files changed, 60 insertions(+), 25 deletions(-) diff --git a/packages/client/src/components/Component.svelte b/packages/client/src/components/Component.svelte index 7a9a5cfb08..ae6db62282 100644 --- a/packages/client/src/components/Component.svelte +++ b/packages/client/src/components/Component.svelte @@ -20,7 +20,6 @@ } from "utils/componentProps" import { builderStore, devToolsStore, componentStore, appStore } from "stores" import { Helpers } from "@budibase/bbui" - import Manifest from "manifest.json" import { getActiveConditions, reduceConditionActions } from "utils/conditions" import Placeholder from "components/app/Placeholder.svelte" @@ -171,8 +170,9 @@ } // Pull definition and constructor - constructor = getComponentConstructor(instance._component) - definition = getComponentDefinition(instance._component) + const component = instance._component + constructor = getComponentConstructor(component) + definition = componentStore.actions.getComponentDefinition(component) if (!definition) { return } @@ -217,13 +217,6 @@ return AppComponents[name] } - // Gets this component's definition from the manifest - const getComponentDefinition = component => { - const prefix = "@budibase/standard-components/" - const type = component?.replace(prefix, "") - return type ? Manifest[type] : null - } - const getSettingsDefinitionMap = settingsDefinition => { let map = {} settingsDefinition?.forEach(setting => { @@ -382,7 +375,7 @@ if (!node) { return } - node.style.scrollMargin = "80px" + node.style.scrollMargin = "86px" node.scrollIntoView({ behavior: "smooth", block: "start", diff --git a/packages/client/src/components/preview/Indicator.svelte b/packages/client/src/components/preview/Indicator.svelte index ee969e3395..23051c73d1 100644 --- a/packages/client/src/components/preview/Indicator.svelte +++ b/packages/client/src/components/preview/Indicator.svelte @@ -1,18 +1,20 @@
- {#if text} -
- {text} + {#if text || icon} +
+ {#if icon} + + {/if} + {#if text} +
+ {text} +
+ {/if}
{/if}
diff --git a/packages/client/src/components/preview/IndicatorSet.svelte b/packages/client/src/components/preview/IndicatorSet.svelte index 6fcf552d21..298b65fbf0 100644 --- a/packages/client/src/components/preview/IndicatorSet.svelte +++ b/packages/client/src/components/preview/IndicatorSet.svelte @@ -2,7 +2,7 @@ import { onMount, onDestroy } from "svelte" import Indicator from "./Indicator.svelte" import { domDebounce } from "utils/domDebounce" - import { builderStore } from "stores" + import { builderStore, componentStore } from "stores" export let componentId export let color @@ -15,12 +15,24 @@ let text $: visibleIndicators = indicators.filter(x => x.visible) $: offset = $builderStore.inBuilder ? 0 : 2 + $: icon = getComponentIcon(componentId) + $: console.log(icon) let updating = false let observers = [] let callbackCount = 0 let nextIndicators = [] + const getComponentIcon = id => { + if (!id) { + return null + } + const component = componentStore.actions.getComponentById(id) + const type = component?._component + const definition = componentStore.actions.getComponentDefinition(type) + return definition?.icon + } + const createIntersectionCallback = idx => entries => { if (callbackCount >= observers.length) { return @@ -121,6 +133,7 @@ width={indicator.width} height={indicator.height} text={idx === 0 ? text : null} + icon={idx === 0 ? icon : null} {transition} {zIndex} {color} diff --git a/packages/client/src/components/preview/SettingsBar.svelte b/packages/client/src/components/preview/SettingsBar.svelte index 154a115c98..02589277c3 100644 --- a/packages/client/src/components/preview/SettingsBar.svelte +++ b/packages/client/src/components/preview/SettingsBar.svelte @@ -6,7 +6,7 @@ import { builderStore, componentStore } from "stores" import { domDebounce } from "utils/domDebounce" - const verticalOffset = 28 + const verticalOffset = 34 const horizontalOffset = 2 let top = 0 diff --git a/packages/client/src/stores/components.js b/packages/client/src/stores/components.js index a836ca150d..a7426113e2 100644 --- a/packages/client/src/stores/components.js +++ b/packages/client/src/stores/components.js @@ -67,6 +67,12 @@ const createComponentStore = () => { return findComponentById(asset?.props, id) } + const getComponentDefinition = type => { + const prefix = "@budibase/standard-components/" + type = type?.replace(prefix, "") + return type ? Manifest[type] : null + } + return { ...derivedStore, actions: { @@ -74,6 +80,7 @@ const createComponentStore = () => { unregisterInstance, isComponentRegistered, getComponentById, + getComponentDefinition, }, } }