Fix bug determining if a binding is JS or not
This commit is contained in:
parent
21c60849c7
commit
d114b3f1ed
|
@ -438,6 +438,10 @@ function replaceBetween(string, start, end, replacement) {
|
||||||
function bindingReplacement(bindableProperties, textWithBindings, convertTo) {
|
function bindingReplacement(bindableProperties, textWithBindings, convertTo) {
|
||||||
// Decide from base64 if using JS
|
// Decide from base64 if using JS
|
||||||
const isJS = isJSBinding(textWithBindings)
|
const isJS = isJSBinding(textWithBindings)
|
||||||
|
console.log("isJS: " + isJS)
|
||||||
|
if (isJS) {
|
||||||
|
console.log(textWithBindings)
|
||||||
|
}
|
||||||
if (isJS) {
|
if (isJS) {
|
||||||
textWithBindings = decodeJSBinding(textWithBindings)
|
textWithBindings = decodeJSBinding(textWithBindings)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,11 @@
|
||||||
import groupBy from "lodash/fp/groupBy"
|
import groupBy from "lodash/fp/groupBy"
|
||||||
import { Search, TextArea, DrawerContent, Tabs, Tab } from "@budibase/bbui"
|
import { Search, TextArea, DrawerContent, Tabs, Tab } from "@budibase/bbui"
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher } from "svelte"
|
||||||
import { isValid } from "@budibase/string-templates"
|
import {
|
||||||
|
isValid,
|
||||||
|
decodeJSBinding,
|
||||||
|
encodeJSBinding,
|
||||||
|
} from "@budibase/string-templates"
|
||||||
import { readableToRuntimeBinding } from "builderStore/dataBinding"
|
import { readableToRuntimeBinding } from "builderStore/dataBinding"
|
||||||
import { handlebarsCompletions } from "constants/completions"
|
import { handlebarsCompletions } from "constants/completions"
|
||||||
import { addHBSBinding, addJSBinding } from "./utils"
|
import { addHBSBinding, addJSBinding } from "./utils"
|
||||||
|
@ -15,6 +19,8 @@
|
||||||
export let valid
|
export let valid
|
||||||
export let allowJS = true
|
export let allowJS = true
|
||||||
|
|
||||||
|
$: console.log(value)
|
||||||
|
|
||||||
let helpers = handlebarsCompletions()
|
let helpers = handlebarsCompletions()
|
||||||
let getCaretPosition
|
let getCaretPosition
|
||||||
let search = ""
|
let search = ""
|
||||||
|
@ -82,7 +88,7 @@
|
||||||
</div>
|
</div>
|
||||||
</svelte:fragment>
|
</svelte:fragment>
|
||||||
<div class="main">
|
<div class="main">
|
||||||
<Tabs selected="Handlebars" on:select={e => (mode = e.detail)}>
|
<Tabs selected={mode} on:select={e => (mode = e.detail)}>
|
||||||
<Tab title="Handlebars">
|
<Tab title="Handlebars">
|
||||||
<div class="main-content">
|
<div class="main-content">
|
||||||
<TextArea
|
<TextArea
|
||||||
|
@ -106,8 +112,8 @@
|
||||||
<CodeMirrorEditor
|
<CodeMirrorEditor
|
||||||
bind:getCaretPosition
|
bind:getCaretPosition
|
||||||
height={200}
|
height={200}
|
||||||
{value}
|
value={decodeJSBinding(value)}
|
||||||
on:change={e => (value = e.detail)}
|
on:change={e => (value = encodeJSBinding(e.detail))}
|
||||||
hints={context?.map(x => `$("${x.readableBinding}")`)}
|
hints={context?.map(x => `$("${x.readableBinding}")`)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -58,6 +58,12 @@ module.exports.decodeJSBinding = handlebars => {
|
||||||
if (!handlebars || typeof handlebars !== "string") {
|
if (!handlebars || typeof handlebars !== "string") {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// JS is only valid if it is the only HBS expression
|
||||||
|
if (!handlebars.trim().startsWith("{{ js ")) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
const match = handlebars.match(CAPTURE_JS)
|
const match = handlebars.match(CAPTURE_JS)
|
||||||
if (!match || match.length < 2) {
|
if (!match || match.length < 2) {
|
||||||
return null
|
return null
|
||||||
|
|
Loading…
Reference in New Issue