diff --git a/packages/builder/src/components/common/bindings/BindingPanel.svelte b/packages/builder/src/components/common/bindings/BindingPanel.svelte index 2a9a64b455..4dc9d9700e 100644 --- a/packages/builder/src/components/common/bindings/BindingPanel.svelte +++ b/packages/builder/src/components/common/bindings/BindingPanel.svelte @@ -24,6 +24,7 @@ import { addHBSBinding, addJSBinding } from "./utils" import CodeMirrorEditor from "components/common/CodeMirrorEditor.svelte" import { convertToJS } from "@budibase/string-templates" + import { admin } from "stores/portal" const dispatch = createEventDispatcher() @@ -62,16 +63,24 @@ const updateValue = val => { valid = isValid(readableToRuntimeBinding(bindings, val)) - console.log(readableToRuntimeBinding(bindings, val)) if (valid) { dispatch("change", val) } } - // Adds a HBS helper to the expression - const addHelper = helper => { - hbsValue = addHBSBinding(hbsValue, getCaretPosition(), helper.text) - updateValue(hbsValue) + // Adds a JS/HBS helper to the expression + const addHelper = (helper, js) => { + let value + const pos = getCaretPosition() + if (js) { + const decoded = decodeJSBinding(jsValue) + value = jsValue = encodeJSBinding( + addJSBinding(decoded, pos, helper.text, { helper: true }) + ) + } else { + value = hbsValue = addHBSBinding(hbsValue, pos, helper.text) + } + updateValue(value) } // Adds a data binding to the expression @@ -108,7 +117,6 @@ const convert = () => { const runtime = readableToRuntimeBinding(bindings, hbsValue) - console.log(runtime) const runtimeJs = encodeJSBinding(convertToJS(runtime)) jsValue = runtimeToReadableBinding(bindings, runtimeJs) hbsValue = null @@ -116,6 +124,17 @@ addBinding("", { forceJS: true }) } + const getHelperExample = (helper, js) => { + let example = helper.example || "" + if (js) { + example = convertToJS(example).split("\n")[0].split("= ")[1] + if (example === "null;") { + example = "" + } + } + return example || "" + } + onMount(() => { valid = isValid(readableToRuntimeBinding(bindings, value)) }) @@ -151,18 +170,21 @@ {/if} {/each} - {#if filteredHelpers?.length && !usingJS} + {#if filteredHelpers?.length}
Helpers