diff --git a/packages/bbui/src/Form/Core/RichTextField.svelte b/packages/bbui/src/Form/Core/RichTextField.svelte
index 33534485d2..7d2c87fde9 100644
--- a/packages/bbui/src/Form/Core/RichTextField.svelte
+++ b/packages/bbui/src/Form/Core/RichTextField.svelte
@@ -6,6 +6,7 @@
export let disabled = false
export let error = null
export let height = null
+ export let id = null
-
+
diff --git a/packages/bbui/src/Form/RichTextField.svelte b/packages/bbui/src/Form/RichTextField.svelte
index 10c9d96139..8dfc70fa26 100644
--- a/packages/bbui/src/Form/RichTextField.svelte
+++ b/packages/bbui/src/Form/RichTextField.svelte
@@ -10,6 +10,7 @@
export let disabled = false
export let error = null
export let height = null
+ export let id = null
const dispatch = createEventDispatcher()
const onChange = e => {
@@ -25,6 +26,7 @@
{value}
{placeholder}
{height}
+ {id}
on:change={onChange}
/>
diff --git a/packages/bbui/src/Markdown/MarkdownEditor.svelte b/packages/bbui/src/Markdown/MarkdownEditor.svelte
index 0b57a6e844..0b5811db0d 100644
--- a/packages/bbui/src/Markdown/MarkdownEditor.svelte
+++ b/packages/bbui/src/Markdown/MarkdownEditor.svelte
@@ -2,15 +2,18 @@
import SpectrumMDE from "./SpectrumMDE.svelte"
import { createEventDispatcher, onMount } from "svelte"
- export let value
+ export let value = null
export let height = "300px"
- export let placeholder
+ export let placeholder = null
+ export let id = null
const dispatch = createEventDispatcher()
let latestValue
let mde
+ // Ensure the value is updated if the value prop changes outside the editor's
+ // control
$: checkValue(value)
const checkValue = val => {
@@ -19,11 +22,24 @@
}
}
+ const debounce = (fn, interval) => {
+ let timeout
+ return () => {
+ clearTimeout(timeout)
+ timeout = setTimeout(fn, interval)
+ }
+ }
+
+ const update = () => {
+ latestValue = mde.value()
+ dispatch("change", latestValue)
+ }
+
+ // Debounce the update function to avoid spamming it constantly
+ const debouncedUpdate = debounce(update, 250)
+
onMount(() => {
- mde.codemirror.on("change", () => {
- latestValue = mde.value()
- dispatch("change", latestValue)
- })
+ mde.codemirror.on("change", debouncedUpdate)
})
@@ -31,6 +47,7 @@
bind:mde
scroll={true}
{height}
+ {id}
easyMDEOptions={{
initialValue: value,
placeholder,
diff --git a/packages/bbui/src/Markdown/MarkdownViewer.svelte b/packages/bbui/src/Markdown/MarkdownViewer.svelte
index 89865346ee..b601bbf027 100644
--- a/packages/bbui/src/Markdown/MarkdownViewer.svelte
+++ b/packages/bbui/src/Markdown/MarkdownViewer.svelte
@@ -3,6 +3,7 @@
import { onMount } from "svelte"
export let value
+ export let height
let mde
@@ -15,7 +16,7 @@
})
-