From 47ca9250036ddb6c04d52492af978a68dc71b8ec Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 13 Aug 2021 11:24:47 +0100 Subject: [PATCH 1/3] Add global data bindings for mobile and tablet device sizes --- .../builder/src/builderStore/dataBinding.js | 29 +++++++++- .../src/builderStore/store/frontend.js | 1 + .../common/bindings/BindingPanel.svelte | 2 +- .../client/src/components/ClientApp.svelte | 58 ++++++++----------- .../components/DeviceBindingsProvider.svelte | 33 +++++++++++ .../components/UserBindingsProvider.svelte | 19 ++++++ packages/standard-components/manifest.json | 3 +- 7 files changed, 109 insertions(+), 36 deletions(-) create mode 100644 packages/client/src/components/DeviceBindingsProvider.svelte create mode 100644 packages/client/src/components/UserBindingsProvider.svelte diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index 6d7cad1cd0..dc995d611c 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -17,7 +17,13 @@ export const getBindableProperties = (asset, componentId) => { const contextBindings = getContextBindings(asset, componentId) const userBindings = getUserBindings() const urlBindings = getUrlBindings(asset) - return [...contextBindings, ...userBindings, ...urlBindings] + const deviceBindings = getDeviceBindings() + return [ + ...deviceBindings, + ...urlBindings, + ...contextBindings, + ...userBindings, + ] } /** @@ -221,6 +227,27 @@ const getUserBindings = () => { return bindings } +/** + * Gets all device bindings that are globally available. + */ +const getDeviceBindings = () => { + let bindings = [] + if (get(store).clientFeatures?.deviceAwareness) { + const safeDevice = makePropSafe("device") + bindings.push({ + type: "context", + runtimeBinding: `${safeDevice}.${makePropSafe("mobile")}`, + readableBinding: `Device.Mobile`, + }) + bindings.push({ + type: "context", + runtimeBinding: `${safeDevice}.${makePropSafe("tablet")}`, + readableBinding: `Device.Tablet`, + }) + } + return bindings +} + /** * Gets all bindable properties from URL parameters. */ diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index 3339ea07d6..1924ae07a2 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -35,6 +35,7 @@ const INITIAL_FRONTEND_STATE = { clientFeatures: { spectrumThemes: false, intelligentLoading: false, + deviceAwareness: false, }, currentFrontEndType: "none", selectedScreenId: "", diff --git a/packages/builder/src/components/common/bindings/BindingPanel.svelte b/packages/builder/src/components/common/bindings/BindingPanel.svelte index 6290bd2a3d..fdf708dc4e 100644 --- a/packages/builder/src/components/common/bindings/BindingPanel.svelte +++ b/packages/builder/src/components/common/bindings/BindingPanel.svelte @@ -38,7 +38,7 @@ {#if filteredColumns?.length}
-
Columns
+
Bindable Values