Fix inserting bindings manually when using JS
This commit is contained in:
parent
67a74ee327
commit
43d546b2db
|
@ -438,10 +438,6 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,13 +19,12 @@
|
||||||
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 = ""
|
||||||
let mode = "Handlebars"
|
let mode = value?.startsWith("{{ js ") ? "JavaScript" : "Handlebars"
|
||||||
|
|
||||||
|
$: jsValue = value?.startsWith("{{ js ")
|
||||||
$: usingJS = mode === "JavaScript"
|
$: usingJS = mode === "JavaScript"
|
||||||
$: valid = isValid(readableToRuntimeBinding(bindableProperties, value))
|
$: valid = isValid(readableToRuntimeBinding(bindableProperties, value))
|
||||||
$: dispatch("change", value)
|
$: dispatch("change", value)
|
||||||
|
@ -38,13 +37,20 @@
|
||||||
return helper.label.match(searchRgx) || helper.description.match(searchRgx)
|
return helper.label.match(searchRgx) || helper.description.match(searchRgx)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Adds a HBS helper to the expression
|
||||||
const addHelper = helper => {
|
const addHelper = helper => {
|
||||||
value = addHBSBinding(value, getCaretPosition(), helper.text)
|
value = addHBSBinding(value, getCaretPosition(), helper.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adds a data binding to the expression
|
||||||
const addBinding = binding => {
|
const addBinding = binding => {
|
||||||
const fn = usingJS ? addJSBinding : addHBSBinding
|
if (usingJS) {
|
||||||
value = fn(value, getCaretPosition(), binding.readableBinding)
|
let js = decodeJSBinding(value)
|
||||||
|
js = addJSBinding(js, getCaretPosition(), binding.readableBinding)
|
||||||
|
value = encodeJSBinding(js)
|
||||||
|
} else {
|
||||||
|
value = addHBSBinding(value, getCaretPosition(), binding.readableBinding)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -93,7 +99,7 @@
|
||||||
<div class="main-content">
|
<div class="main-content">
|
||||||
<TextArea
|
<TextArea
|
||||||
bind:getCaretPosition
|
bind:getCaretPosition
|
||||||
{value}
|
value={jsValue ? null : value}
|
||||||
on:change={e => (value = e.detail)}
|
on:change={e => (value = e.detail)}
|
||||||
placeholder="Add text, or click the objects on the left to add them to the textbox."
|
placeholder="Add text, or click the objects on the left to add them to the textbox."
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -38,7 +38,6 @@ module.exports.processJS = (handlebars, context) => {
|
||||||
vm.createContext(sandboxContext)
|
vm.createContext(sandboxContext)
|
||||||
return vm.runInNewContext(js, sandboxContext)
|
return vm.runInNewContext(js, sandboxContext)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn(error)
|
|
||||||
return "Error while executing JS"
|
return "Error while executing JS"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue