2021-01-28 19:03:44 +01:00
|
|
|
<script>
|
2021-02-01 12:14:24 +01:00
|
|
|
import { onMount } from "svelte"
|
2021-01-28 19:03:44 +01:00
|
|
|
import { RichText } from "@budibase/bbui"
|
2021-02-05 11:53:25 +01:00
|
|
|
import Field from "./Field.svelte"
|
2021-01-28 19:03:44 +01:00
|
|
|
|
|
|
|
export let field
|
|
|
|
export let label
|
|
|
|
export let placeholder
|
|
|
|
|
|
|
|
let fieldState
|
|
|
|
let fieldApi
|
2021-01-29 11:28:13 +01:00
|
|
|
|
2021-02-01 12:14:24 +01:00
|
|
|
// Update form value from bound value after we've mounted
|
|
|
|
let value
|
|
|
|
let mounted = false
|
|
|
|
$: mounted && fieldApi?.setValue(value)
|
|
|
|
|
|
|
|
// Get the fields initial value after initialising
|
|
|
|
onMount(() => {
|
|
|
|
value = $fieldState?.value
|
|
|
|
mounted = true
|
|
|
|
})
|
2021-01-28 19:03:44 +01:00
|
|
|
|
|
|
|
// Options for rich text component
|
|
|
|
const options = {
|
|
|
|
modules: {
|
|
|
|
toolbar: [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
header: [1, 2, 3, false],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
["bold", "italic", "underline", "strike"],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
placeholder: placeholder || "Type something...",
|
|
|
|
theme: "snow",
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2021-02-05 11:53:25 +01:00
|
|
|
<Field
|
|
|
|
{label}
|
|
|
|
{field}
|
|
|
|
type="longform"
|
|
|
|
bind:fieldState
|
|
|
|
bind:fieldApi
|
|
|
|
defaultValue="">
|
2021-02-01 12:14:24 +01:00
|
|
|
{#if mounted}
|
2021-01-28 19:03:44 +01:00
|
|
|
<div>
|
|
|
|
<RichText bind:value {options} />
|
|
|
|
</div>
|
|
|
|
{/if}
|
2021-02-05 11:53:25 +01:00
|
|
|
</Field>
|
2021-01-28 19:03:44 +01:00
|
|
|
|
|
|
|
<style>
|
|
|
|
div {
|
|
|
|
background-color: white;
|
|
|
|
}
|
2021-02-01 19:00:38 +01:00
|
|
|
div :global(> div) {
|
|
|
|
width: auto !important;
|
|
|
|
}
|
2021-01-28 19:03:44 +01:00
|
|
|
div :global(.ql-snow.ql-toolbar:after, .ql-snow .ql-toolbar:after) {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
div :global(.ql-snow .ql-formats:after) {
|
|
|
|
display: none;
|
|
|
|
}
|
2021-02-10 20:23:53 +01:00
|
|
|
div :global(.ql-editor p) {
|
|
|
|
word-break: break-all;
|
|
|
|
}
|
2021-01-28 19:03:44 +01:00
|
|
|
</style>
|