From d03f96ceb8327d46245700c404831e8afd9c3bbc Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 28 Apr 2023 09:03:09 +0100 Subject: [PATCH 01/31] Make all blindings global and improve client component performance --- .../builder/src/builderStore/dataBinding.js | 34 ++++++--- .../src/builderStore/store/frontend.js | 7 +- .../controls/DataProviderSelect.svelte | 9 +-- packages/client/manifest.json | 11 --- .../client/src/components/Component.svelte | 71 ++++++++++++++----- .../src/components/context/Provider.svelte | 6 +- packages/client/src/stores/context.js | 61 +++++++--------- packages/client/src/utils/componentProps.js | 16 +---- .../client/src/utils/enrichDataBinding.js | 1 + yarn.lock | 12 ++-- 10 files changed, 127 insertions(+), 101 deletions(-) diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index 0d41931a55..9f253f9f75 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -199,15 +199,7 @@ export const getContextProviderComponents = ( return [] } - // Get the component tree leading up to this component, ignoring the component - // itself - const path = findComponentPath(asset.props, componentId) - if (!options?.includeSelf) { - path.pop() - } - - // Filter by only data provider components - return path.filter(component => { + return findAllMatchingComponents(asset.props, component => { const def = store.actions.components.getDefinition(component._component) if (!def?.context) { return false @@ -222,6 +214,30 @@ export const getContextProviderComponents = ( const contexts = Array.isArray(def.context) ? def.context : [def.context] return contexts.find(context => context.type === type) != null }) + // + // // Get the component tree leading up to this component, ignoring the component + // // itself + // const path = findComponentPath(asset.props, componentId) + // if (!options?.includeSelf) { + // path.pop() + // } + // + // // Filter by only data provider components + // return path.filter(component => { + // const def = store.actions.components.getDefinition(component._component) + // if (!def?.context) { + // return false + // } + // + // // If no type specified, return anything that exposes context + // if (!type) { + // return true + // } + // + // // Otherwise only match components with the specific context type + // const contexts = Array.isArray(def.context) ? def.context : [def.context] + // return contexts.find(context => context.type === type) != null + // }) } /** diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index e264dc099b..fb3eb8f1d9 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -621,10 +621,9 @@ export const getFrontendStore = () => { else { if (setting.type === "dataProvider") { // Validate data provider exists, or else clear it - const treeId = parent?._id || component._id - const path = findComponentPath(screen?.props, treeId) - const providers = path.filter(component => - component._component?.endsWith("/dataprovider") + const providers = findAllMatchingComponents( + screen?.props, + component => component._component?.endsWith("/dataprovider") ) // Validate non-empty values const valid = providers?.some(dp => value.includes?.(dp._id)) diff --git a/packages/builder/src/components/design/settings/controls/DataProviderSelect.svelte b/packages/builder/src/components/design/settings/controls/DataProviderSelect.svelte index 83255ec325..9fd220e798 100644 --- a/packages/builder/src/components/design/settings/controls/DataProviderSelect.svelte +++ b/packages/builder/src/components/design/settings/controls/DataProviderSelect.svelte @@ -1,15 +1,16 @@