From a40bf95c413dd008a7c25f1b88a080a2fb434355 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 6 Jan 2021 10:13:30 +0000 Subject: [PATCH] Enable selecting components from the builder preview and apply any custom styles --- .../client/src/components/ClientApp.svelte | 1 + .../client/src/components/Component.svelte | 12 ++- packages/client/src/components/Router.svelte | 5 +- packages/client/src/utils/styleable.js | 89 ++++++++++++++++--- 4 files changed, 93 insertions(+), 14 deletions(-) diff --git a/packages/client/src/components/ClientApp.svelte b/packages/client/src/components/ClientApp.svelte index a7a972a435..222344420e 100644 --- a/packages/client/src/components/ClientApp.svelte +++ b/packages/client/src/components/ClientApp.svelte @@ -9,6 +9,7 @@ setContext("sdk", SDK) setContext("component", writable({})) setContext("data", createDataStore()) + setContext("screenslot", false) let loaded = false diff --git a/packages/client/src/components/Component.svelte b/packages/client/src/components/Component.svelte index 56591133e5..23ba364dfb 100644 --- a/packages/client/src/components/Component.svelte +++ b/packages/client/src/components/Component.svelte @@ -8,8 +8,9 @@ export let definition = {} - // Get local data binding context + // Get contexts const dataContext = getContext("data") + const screenslotContext = getContext("screenslot") // Create component context const componentStore = writable({}) @@ -20,10 +21,15 @@ $: children = definition._children $: id = definition._id $: enrichedProps = enrichProps(definition, $dataContext, $bindingStore) - $: selected = id === $builderStore.selectedComponentId + $: styles = definition._styles + + // Allow component selection in the builder preview if we're previewing a + // layout, or we're preview a screen and we're inside the screenslot + $: allowSelection = + $builderStore.previewType === "layout" || screenslotContext // Update component context - $: componentStore.set({ id, styles: { ...definition._styles, selected } }) + $: componentStore.set({ id, styles: { ...styles, id, allowSelection } }) // Gets the component constructor for the specified component const getComponentConstructor = component => { diff --git a/packages/client/src/components/Router.svelte b/packages/client/src/components/Router.svelte index 3c2d71c422..5477d02f86 100644 --- a/packages/client/src/components/Router.svelte +++ b/packages/client/src/components/Router.svelte @@ -1,5 +1,5 @@