Merge pull request #5172 from Budibase/fix/in-preview-editing
Fix in-preview text editing bugs
This commit is contained in:
commit
a6d9661ccc
|
@ -2529,7 +2529,6 @@
|
||||||
"name": "Embedded Map",
|
"name": "Embedded Map",
|
||||||
"icon": "Location",
|
"icon": "Location",
|
||||||
"styles": ["size"],
|
"styles": ["size"],
|
||||||
"editable": true,
|
|
||||||
"draggable": false,
|
"draggable": false,
|
||||||
"illegalChildren": ["section"],
|
"illegalChildren": ["section"],
|
||||||
"settings": [
|
"settings": [
|
||||||
|
@ -3631,7 +3630,6 @@
|
||||||
"name": "Markdown Viewer",
|
"name": "Markdown Viewer",
|
||||||
"icon": "TaskList",
|
"icon": "TaskList",
|
||||||
"styles": ["size"],
|
"styles": ["size"],
|
||||||
"editable": true,
|
|
||||||
"settings": [
|
"settings": [
|
||||||
{
|
{
|
||||||
"type": "text",
|
"type": "text",
|
||||||
|
|
|
@ -22,41 +22,43 @@
|
||||||
$: componentText = getComponentText(text, $builderStore, $component)
|
$: componentText = getComponentText(text, $builderStore, $component)
|
||||||
|
|
||||||
const getComponentText = (text, builderState, componentState) => {
|
const getComponentText = (text, builderState, componentState) => {
|
||||||
if (!builderState.inBuilder || componentState.editing) {
|
if (componentState.editing) {
|
||||||
return text || " "
|
return text || " "
|
||||||
}
|
}
|
||||||
return text || componentState.name || "Placeholder text"
|
return text || componentState.name || "Placeholder text"
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateText = e => {
|
const updateText = e => {
|
||||||
builderStore.actions.updateProp("text", e.target.textContent.trim())
|
builderStore.actions.updateProp("text", e.target.textContent)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<button
|
{#key $component.editing}
|
||||||
class={`spectrum-Button spectrum-Button--size${size} spectrum-Button--${type}`}
|
<button
|
||||||
class:spectrum-Button--quiet={quiet}
|
class={`spectrum-Button spectrum-Button--size${size} spectrum-Button--${type}`}
|
||||||
{disabled}
|
class:spectrum-Button--quiet={quiet}
|
||||||
use:styleable={$component.styles}
|
{disabled}
|
||||||
on:click={onClick}
|
use:styleable={$component.styles}
|
||||||
contenteditable={$component.editing && !icon}
|
on:click={onClick}
|
||||||
on:blur={$component.editing ? updateText : null}
|
contenteditable={$component.editing && !icon}
|
||||||
bind:this={node}
|
on:blur={$component.editing ? updateText : null}
|
||||||
class:active
|
bind:this={node}
|
||||||
>
|
class:active
|
||||||
{#if icon}
|
>
|
||||||
<svg
|
{#if icon}
|
||||||
class:hasText={componentText?.length > 0}
|
<svg
|
||||||
class="spectrum-Icon spectrum-Icon--size{size.toUpperCase()}"
|
class:hasText={componentText?.length > 0}
|
||||||
focusable="false"
|
class="spectrum-Icon spectrum-Icon--size{size.toUpperCase()}"
|
||||||
aria-hidden="true"
|
focusable="false"
|
||||||
aria-label={icon}
|
aria-hidden="true"
|
||||||
>
|
aria-label={icon}
|
||||||
<use xlink:href="#spectrum-icon-18-{icon}" />
|
>
|
||||||
</svg>
|
<use xlink:href="#spectrum-icon-18-{icon}" />
|
||||||
{/if}
|
</svg>
|
||||||
{componentText}
|
{/if}
|
||||||
</button>
|
{componentText}
|
||||||
|
</button>
|
||||||
|
{/key}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
button {
|
button {
|
||||||
|
|
|
@ -47,24 +47,25 @@
|
||||||
|
|
||||||
// Convert contenteditable HTML to text and save
|
// Convert contenteditable HTML to text and save
|
||||||
const updateText = e => {
|
const updateText = e => {
|
||||||
const sanitized = e.target.innerHTML.replace(/<br>/gi, "\n").trim()
|
builderStore.actions.updateProp("text", e.target.textContent)
|
||||||
builderStore.actions.updateProp("text", sanitized)
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<h1
|
{#key $component.editing}
|
||||||
bind:this={node}
|
<h1
|
||||||
contenteditable={$component.editing}
|
bind:this={node}
|
||||||
use:styleable={styles}
|
contenteditable={$component.editing}
|
||||||
class:placeholder
|
use:styleable={styles}
|
||||||
class:bold
|
class:placeholder
|
||||||
class:italic
|
class:bold
|
||||||
class:underline
|
class:italic
|
||||||
class="spectrum-Heading {sizeClass} {alignClass}"
|
class:underline
|
||||||
on:blur={$component.editing ? updateText : null}
|
class="spectrum-Heading {sizeClass} {alignClass}"
|
||||||
>
|
on:blur={$component.editing ? updateText : null}
|
||||||
{componentText}
|
>
|
||||||
</h1>
|
{componentText}
|
||||||
|
</h1>
|
||||||
|
{/key}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
h1 {
|
h1 {
|
||||||
|
|
|
@ -61,7 +61,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateText = e => {
|
const updateText = e => {
|
||||||
builderStore.actions.updateProp("text", e.target.textContent.trim())
|
builderStore.actions.updateProp("text", e.target.textContent)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -46,24 +46,25 @@
|
||||||
|
|
||||||
// Convert contenteditable HTML to text and save
|
// Convert contenteditable HTML to text and save
|
||||||
const updateText = e => {
|
const updateText = e => {
|
||||||
const sanitized = e.target.innerHTML.replace(/<br>/gi, "\n").trim()
|
builderStore.actions.updateProp("text", e.target.textContent)
|
||||||
builderStore.actions.updateProp("text", sanitized)
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<p
|
{#key $component.editing}
|
||||||
bind:this={node}
|
<p
|
||||||
contenteditable={$component.editing}
|
bind:this={node}
|
||||||
use:styleable={styles}
|
contenteditable={$component.editing}
|
||||||
class:placeholder
|
use:styleable={styles}
|
||||||
class:bold
|
class:placeholder
|
||||||
class:italic
|
class:bold
|
||||||
class:underline
|
class:italic
|
||||||
class="spectrum-Body {sizeClass} {alignClass}"
|
class:underline
|
||||||
on:blur={$component.editing ? updateText : null}
|
class="spectrum-Body {sizeClass} {alignClass}"
|
||||||
>
|
on:blur={$component.editing ? updateText : null}
|
||||||
{componentText}
|
>
|
||||||
</p>
|
{componentText}
|
||||||
|
</p>
|
||||||
|
{/key}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
p {
|
p {
|
||||||
|
|
|
@ -50,22 +50,24 @@
|
||||||
$: labelClass = labelPos === "above" ? "" : `spectrum-FieldLabel--${labelPos}`
|
$: labelClass = labelPos === "above" ? "" : `spectrum-FieldLabel--${labelPos}`
|
||||||
|
|
||||||
const updateLabel = e => {
|
const updateLabel = e => {
|
||||||
builderStore.actions.updateProp("label", e.target.textContent.trim())
|
builderStore.actions.updateProp("label", e.target.textContent)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<FieldGroupFallback>
|
<FieldGroupFallback>
|
||||||
<div class="spectrum-Form-item" use:styleable={$component.styles}>
|
<div class="spectrum-Form-item" use:styleable={$component.styles}>
|
||||||
<label
|
{#key $component.editing}
|
||||||
bind:this={labelNode}
|
<label
|
||||||
contenteditable={$component.editing}
|
bind:this={labelNode}
|
||||||
on:blur={$component.editing ? updateLabel : null}
|
contenteditable={$component.editing}
|
||||||
class:hidden={!label}
|
on:blur={$component.editing ? updateLabel : null}
|
||||||
for={fieldState?.fieldId}
|
class:hidden={!label}
|
||||||
class={`spectrum-FieldLabel spectrum-FieldLabel--sizeM spectrum-Form-itemLabel ${labelClass}`}
|
for={fieldState?.fieldId}
|
||||||
>
|
class={`spectrum-FieldLabel spectrum-FieldLabel--sizeM spectrum-Form-itemLabel ${labelClass}`}
|
||||||
{label || " "}
|
>
|
||||||
</label>
|
{label || " "}
|
||||||
|
</label>
|
||||||
|
{/key}
|
||||||
<div class="spectrum-Form-itemField">
|
<div class="spectrum-Form-itemField">
|
||||||
{#if !formContext}
|
{#if !formContext}
|
||||||
<Placeholder text="Form components need to be wrapped in a form" />
|
<Placeholder text="Form components need to be wrapped in a form" />
|
||||||
|
|
Loading…
Reference in New Issue