2020-12-29 04:01:30 +02:00
|
|
|
<script>
|
2022-12-30 13:08:54 +01:00
|
|
|
import { onMount } from 'svelte';
|
2020-12-29 04:01:30 +02:00
|
|
|
|
2022-12-30 13:08:54 +01:00
|
|
|
export let onChange;
|
|
|
|
|
export let content;
|
|
|
|
|
export let disable;
|
|
|
|
|
export let docId;
|
|
|
|
|
export let placeholder = 'Type something...';
|
2023-05-20 23:53:28 +00:00
|
|
|
export let errorMessage;
|
2020-12-29 04:01:30 +02:00
|
|
|
|
2022-12-30 13:08:54 +01:00
|
|
|
const settings = {
|
|
|
|
|
modules: {
|
|
|
|
|
toolbar: {
|
|
|
|
|
modules: {
|
|
|
|
|
syntax: true,
|
|
|
|
|
toolbar: [
|
|
|
|
|
[{ header: [1, 2, 3, false] }],
|
|
|
|
|
['bold', 'italic', 'underline', 'strike'],
|
|
|
|
|
['link', 'code-block'],
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
placeholder: 'Type something...',
|
|
|
|
|
theme: 'snow',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
theme: 'snow',
|
|
|
|
|
placeholder,
|
2021-05-08 11:47:18 +03:00
|
|
|
};
|
2022-12-30 13:08:54 +01:00
|
|
|
|
|
|
|
|
let quill = null;
|
|
|
|
|
let container = null;
|
|
|
|
|
|
|
|
|
|
function resetContent(docId) {
|
|
|
|
|
if (quill && quill.setText) {
|
|
|
|
|
if (content) {
|
|
|
|
|
quill.setContents(JSON.parse(content));
|
|
|
|
|
} else {
|
|
|
|
|
quill.setText('');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
|
const { default: Quill } = await import('quill');
|
|
|
|
|
|
|
|
|
|
Quill.prototype.getHTML = function () {
|
|
|
|
|
return this.container.querySelector('.ql-editor').innerHTML;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Quill.prototype.setHTML = function (html) {
|
|
|
|
|
this.container.querySelector('.ql-editor').innerHTML = html;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
quill = new Quill(container, settings);
|
|
|
|
|
|
|
|
|
|
quill.setHTML(content || '');
|
|
|
|
|
|
|
|
|
|
quill.on('text-change', function () {
|
|
|
|
|
onChange(quill.getHTML());
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$: {
|
|
|
|
|
if (quill && quill.setText) {
|
|
|
|
|
if (disable) {
|
|
|
|
|
quill.disable(disable);
|
|
|
|
|
} else {
|
|
|
|
|
quill.enable(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$: resetContent(docId);
|
2020-12-29 04:01:30 +02:00
|
|
|
</script>
|
|
|
|
|
|
2022-12-30 13:08:54 +01:00
|
|
|
<div class="p-2 w-full h-full">
|
|
|
|
|
<div bind:this={container} />
|
2023-05-20 23:53:28 +00:00
|
|
|
{#if errorMessage}
|
|
|
|
|
<p class="dark:text-white text-red-500 text-sm">
|
|
|
|
|
{errorMessage}
|
|
|
|
|
</p>
|
|
|
|
|
{/if}
|
2021-05-08 11:47:18 +03:00
|
|
|
</div>
|
2023-05-20 23:53:28 +00:00
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
:global(.dark .ql-stroke) {
|
|
|
|
|
stroke: #fff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
:global(.dark .ql-snow .ql-picker) {
|
|
|
|
|
color: #fff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
:global(.dark .ql-editor.ql-blank::before) {
|
|
|
|
|
color: #fff;
|
|
|
|
|
}
|
|
|
|
|
</style>
|