Update binding side panel to show readable bindings and real values

This commit is contained in:
Andrew Kingston 2024-03-11 11:45:11 +00:00
parent 10c5eee87e
commit 7e724e8d8b
2 changed files with 23 additions and 8 deletions

View File

@ -279,7 +279,7 @@
{context} {context}
addHelper={onSelectHelper} addHelper={onSelectHelper}
addBinding={onSelectBinding} addBinding={onSelectBinding}
mode={editorMode} js={editorMode === EditorModes.JS}
/> />
{:else if sidePanel === SidePanels.Evaluation} {:else if sidePanel === SidePanels.Evaluation}
<EvaluationSidePanel <EvaluationSidePanel

View File

@ -7,7 +7,7 @@
export let addHelper export let addHelper
export let addBinding export let addBinding
export let bindings export let bindings
export let mode export let js
export let allowHelpers export let allowHelpers
export let context = null export let context = null
@ -47,7 +47,7 @@
(!search || (!search ||
helper.label.match(searchRgx) || helper.label.match(searchRgx) ||
helper.description.match(searchRgx)) && helper.description.match(searchRgx)) &&
(mode.name !== "javascript" || helper.allowsJs) (!js || helper.allowsJs)
) )
}) })
@ -71,14 +71,16 @@
} }
const showBindingPopover = (binding, target) => { const showBindingPopover = (binding, target) => {
let code = binding.valueHTML
if (!context || !binding.value || binding.value === "") { if (!context || !binding.value || binding.value === "") {
return code = null
} }
stopHidingPopover() stopHidingPopover()
popoverAnchor = target popoverAnchor = target
hoverTarget = { hoverTarget = {
helper: false, helper: false,
code: binding.valueHTML, code,
binding: binding.readableBinding,
} }
popover.show() popover.show()
} }
@ -92,7 +94,7 @@
hoverTarget = { hoverTarget = {
helper: true, helper: true,
description: helper.description, description: helper.description,
code: getHelperExample(helper, mode.name === "javascript"), code: getHelperExample(helper, js),
} }
popover.show() popover.show()
} }
@ -112,6 +114,15 @@
hideTimeout = null hideTimeout = null
} }
} }
const getReadableBindingLabel = readableBinding => {
console.log(js)
if (js) {
return `$("${readableBinding}")`
} else {
return `{{ ${readableBinding} }}`
}
}
</script> </script>
<Popover <Popover
@ -126,6 +137,9 @@
on:mouseleave={hidePopover} on:mouseleave={hidePopover}
> >
<div class="binding-popover" class:helper={hoverTarget.helper}> <div class="binding-popover" class:helper={hoverTarget.helper}>
{#if hoverTarget.binding}
<pre class="binding">{getReadableBindingLabel(hoverTarget.binding)}</pre>
{/if}
{#if hoverTarget.description} {#if hoverTarget.description}
<div> <div>
<!-- eslint-disable-next-line svelte/no-at-html-tags--> <!-- eslint-disable-next-line svelte/no-at-html-tags-->
@ -246,7 +260,7 @@
class="binding" class="binding"
on:mouseenter={e => showHelperPopover(helper, e.target)} on:mouseenter={e => showHelperPopover(helper, e.target)}
on:mouseleave={hidePopover} on:mouseleave={hidePopover}
on:click={() => addHelper(helper, mode.name === "javascript")} on:click={() => addHelper(helper, js)}
> >
<span class="binding__label">{helper.displayText}</span> <span class="binding__label">{helper.displayText}</span>
<span class="binding__typeWrap"> <span class="binding__typeWrap">
@ -404,7 +418,8 @@
text-overflow: ellipsis; text-overflow: ellipsis;
overflow: hidden; overflow: hidden;
} }
.binding-popover.helper pre { .binding-popover.helper pre,
.binding-popover pre.binding {
color: var(--spectrum-global-color-blue-700); color: var(--spectrum-global-color-blue-700);
} }
.binding-popover pre :global(span) { .binding-popover pre :global(span) {