From 93043c2ab391eb54a62602c81ca07b0040c02c2b Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Wed, 9 Sep 2020 21:16:26 +0100 Subject: [PATCH] events: Update record workings --- .../src/builderStore/replaceBindings.js | 41 +++ .../EventsEditor/EventEditorModal.svelte | 33 ++- .../EventsEditor/EventPropertyControl.svelte | 2 + .../EventsEditor/actions/UpdateRecord.svelte | 38 ++- .../userInterface/PropertyControl.svelte | 42 +--- packages/builder/yarn.lock | 236 +----------------- 6 files changed, 113 insertions(+), 279 deletions(-) create mode 100644 packages/builder/src/builderStore/replaceBindings.js diff --git a/packages/builder/src/builderStore/replaceBindings.js b/packages/builder/src/builderStore/replaceBindings.js new file mode 100644 index 0000000000..38cb67951d --- /dev/null +++ b/packages/builder/src/builderStore/replaceBindings.js @@ -0,0 +1,41 @@ +export const CAPTURE_VAR_INSIDE_MUSTACHE = /{{([^}]+)}}/g + +export function readableToRuntimeBinding(bindableProperties, textWithBindings) { + // Find all instances of mustasche + const boundValues = textWithBindings.match(CAPTURE_VAR_INSIDE_MUSTACHE) + + // Replace with names: + boundValues && + boundValues.forEach(boundValue => { + const binding = bindableProperties.find(({ readableBinding }) => { + return boundValue === `{{ ${readableBinding} }}` + }) + if (binding) { + textWithBindings = textWithBindings.replace( + boundValue, + `{{ ${binding.runtimeBinding} }}` + ) + } + }) + return textWithBindings +} + +export function runtimeToReadableBinding(bindableProperties, textWithBindings) { + let temp = textWithBindings + const boundValues = + (typeof textWithBindings === "string" && + textWithBindings.match(CAPTURE_VAR_INSIDE_MUSTACHE)) || + [] + + // Replace with names: + boundValues.forEach(v => { + const binding = bindableProperties.find(({ runtimeBinding }) => { + return v === `{{ ${runtimeBinding} }}` + }) + if (binding) { + temp = temp.replace(v, `{{ ${binding.readableBinding} }}`) + } + }) + + return temp +} diff --git a/packages/builder/src/components/userInterface/EventsEditor/EventEditorModal.svelte b/packages/builder/src/components/userInterface/EventsEditor/EventEditorModal.svelte index 6e804ae3fd..c1611d0c22 100644 --- a/packages/builder/src/components/userInterface/EventsEditor/EventEditorModal.svelte +++ b/packages/builder/src/components/userInterface/EventsEditor/EventEditorModal.svelte @@ -1,12 +1,6 @@