Update binding popovers to remove example bindings and therefore make consistent across the board
This commit is contained in:
parent
7e724e8d8b
commit
07ea080ab8
|
@ -47,7 +47,6 @@
|
||||||
|
|
||||||
export let label
|
export let label
|
||||||
export let completions = []
|
export let completions = []
|
||||||
export let resize = "none"
|
|
||||||
export let mode = EditorModes.Handlebars
|
export let mode = EditorModes.Handlebars
|
||||||
export let value = ""
|
export let value = ""
|
||||||
export let placeholder = null
|
export let placeholder = null
|
||||||
|
@ -55,6 +54,8 @@
|
||||||
export let autofocus = false
|
export let autofocus = false
|
||||||
export let jsBindingWrapping = true
|
export let jsBindingWrapping = true
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
// Export a function to expose caret position
|
// Export a function to expose caret position
|
||||||
export const getCaretPosition = () => {
|
export const getCaretPosition = () => {
|
||||||
const selection_range = editor.state.selection.ranges[0]
|
const selection_range = editor.state.selection.ranges[0]
|
||||||
|
@ -106,8 +107,6 @@
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
|
||||||
|
|
||||||
// Theming!
|
// Theming!
|
||||||
let currentTheme = $themeStore?.theme
|
let currentTheme = $themeStore?.theme
|
||||||
let isDark = !currentTheme.includes("light")
|
let isDark = !currentTheme.includes("light")
|
||||||
|
|
|
@ -163,26 +163,12 @@ export const jsAutocomplete = baseCompletions => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const buildBindingInfoNode = (completion, binding) => {
|
export const buildBindingInfoNode = (completion, binding) => {
|
||||||
|
if (!binding.valueHTML || binding.value == null) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
const ele = document.createElement("div")
|
const ele = document.createElement("div")
|
||||||
ele.classList.add("info-bubble")
|
ele.classList.add("info-bubble")
|
||||||
|
ele.innerHTML = `<div class="binding__example">${binding.valueHTML}</div>`
|
||||||
if (binding.value != null && binding.valueHTML) {
|
|
||||||
ele.innerHTML = `<div class="binding__example">${binding.valueHTML}</div>`
|
|
||||||
return ele
|
|
||||||
}
|
|
||||||
|
|
||||||
const exampleNodeHtml = binding.readableBinding
|
|
||||||
? `<div class="binding__example">{{ ${binding.readableBinding} }}</div>`
|
|
||||||
: ""
|
|
||||||
|
|
||||||
const descriptionNodeHtml = binding.description
|
|
||||||
? `<div class="binding__description">${binding.description}</div>`
|
|
||||||
: ""
|
|
||||||
|
|
||||||
ele.innerHTML = `
|
|
||||||
${exampleNodeHtml}
|
|
||||||
${descriptionNodeHtml}
|
|
||||||
`
|
|
||||||
return ele
|
return ele
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,6 +108,9 @@
|
||||||
|
|
||||||
const enrichBindings = (bindings, context) => {
|
const enrichBindings = (bindings, context) => {
|
||||||
return bindings.map(binding => {
|
return bindings.map(binding => {
|
||||||
|
if (!context) {
|
||||||
|
return binding
|
||||||
|
}
|
||||||
const value = getBindingValue(binding, context)
|
const value = getBindingValue(binding, context)
|
||||||
return {
|
return {
|
||||||
...binding,
|
...binding,
|
||||||
|
@ -227,6 +230,7 @@
|
||||||
]}
|
]}
|
||||||
autofocus={autofocusEditor}
|
autofocus={autofocusEditor}
|
||||||
placeholder="Add bindings by typing {{ or use the menu on the right"
|
placeholder="Add bindings by typing {{ or use the menu on the right"
|
||||||
|
jsBindingWrapping={false}
|
||||||
/>
|
/>
|
||||||
{:else if mode === Modes.JavaScript}
|
{:else if mode === Modes.JavaScript}
|
||||||
<CodeEditor
|
<CodeEditor
|
||||||
|
@ -243,6 +247,7 @@
|
||||||
bind:insertAtPos
|
bind:insertAtPos
|
||||||
autofocus={autofocusEditor}
|
autofocus={autofocusEditor}
|
||||||
placeholder="Add bindings by typing $ or use the menu on the right"
|
placeholder="Add bindings by typing $ or use the menu on the right"
|
||||||
|
jsBindingWrapping
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
{#if targetMode}
|
{#if targetMode}
|
||||||
|
@ -279,7 +284,7 @@
|
||||||
{context}
|
{context}
|
||||||
addHelper={onSelectHelper}
|
addHelper={onSelectHelper}
|
||||||
addBinding={onSelectBinding}
|
addBinding={onSelectBinding}
|
||||||
js={editorMode === EditorModes.JS}
|
{mode}
|
||||||
/>
|
/>
|
||||||
{:else if sidePanel === SidePanels.Evaluation}
|
{:else if sidePanel === SidePanels.Evaluation}
|
||||||
<EvaluationSidePanel
|
<EvaluationSidePanel
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
export let addHelper
|
export let addHelper
|
||||||
export let addBinding
|
export let addBinding
|
||||||
export let bindings
|
export let bindings
|
||||||
export let js
|
export let mode
|
||||||
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)) &&
|
||||||
(!js || helper.allowsJs)
|
(mode.name !== "javascript" || helper.allowsJs)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -71,16 +71,14 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const showBindingPopover = (binding, target) => {
|
const showBindingPopover = (binding, target) => {
|
||||||
let code = binding.valueHTML
|
|
||||||
if (!context || !binding.value || binding.value === "") {
|
if (!context || !binding.value || binding.value === "") {
|
||||||
code = null
|
return
|
||||||
}
|
}
|
||||||
stopHidingPopover()
|
stopHidingPopover()
|
||||||
popoverAnchor = target
|
popoverAnchor = target
|
||||||
hoverTarget = {
|
hoverTarget = {
|
||||||
helper: false,
|
helper: false,
|
||||||
code,
|
code: binding.valueHTML,
|
||||||
binding: binding.readableBinding,
|
|
||||||
}
|
}
|
||||||
popover.show()
|
popover.show()
|
||||||
}
|
}
|
||||||
|
@ -94,7 +92,7 @@
|
||||||
hoverTarget = {
|
hoverTarget = {
|
||||||
helper: true,
|
helper: true,
|
||||||
description: helper.description,
|
description: helper.description,
|
||||||
code: getHelperExample(helper, js),
|
code: getHelperExample(helper, mode.name === "javascript"),
|
||||||
}
|
}
|
||||||
popover.show()
|
popover.show()
|
||||||
}
|
}
|
||||||
|
@ -114,15 +112,6 @@
|
||||||
hideTimeout = null
|
hideTimeout = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getReadableBindingLabel = readableBinding => {
|
|
||||||
console.log(js)
|
|
||||||
if (js) {
|
|
||||||
return `$("${readableBinding}")`
|
|
||||||
} else {
|
|
||||||
return `{{ ${readableBinding} }}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Popover
|
<Popover
|
||||||
|
@ -137,9 +126,6 @@
|
||||||
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-->
|
||||||
|
@ -260,7 +246,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, js)}
|
on:click={() => addHelper(helper, mode.name === "javascript")}
|
||||||
>
|
>
|
||||||
<span class="binding__label">{helper.displayText}</span>
|
<span class="binding__label">{helper.displayText}</span>
|
||||||
<span class="binding__typeWrap">
|
<span class="binding__typeWrap">
|
||||||
|
@ -418,8 +404,7 @@
|
||||||
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) {
|
||||||
|
|
Loading…
Reference in New Issue