2023-09-11 13:15:50 +01:00
|
|
|
<script lang="ts">
|
2024-05-14 15:22:30 +01:00
|
|
|
import Editor from './TinymceSvelte/index.svelte';
|
2024-02-01 20:18:03 +01:00
|
|
|
import { globalStore } from '$lib/utils/store/app';
|
2024-04-02 15:21:49 +01:00
|
|
|
import { addMathPlugin } from '$lib/utils/functions/tinymce/plugins';
|
2020-12-29 04:01:30 +02:00
|
|
|
|
2023-09-13 18:56:58 +00:00
|
|
|
export let id = '';
|
2023-12-04 19:39:39 +03:00
|
|
|
export let value: string | undefined = '';
|
2023-09-14 23:04:51 +01:00
|
|
|
export let onChange = (html: string) => {};
|
2023-09-05 13:21:44 +00:00
|
|
|
export let height = 300;
|
|
|
|
|
export let placeholder = '';
|
2023-11-01 09:45:40 +00:00
|
|
|
export let editorWindowRef: Window | undefined = undefined;
|
2023-10-08 15:34:37 +01:00
|
|
|
export let maxHeight: number | undefined = undefined;
|
2020-12-29 04:01:30 +02:00
|
|
|
|
2023-12-04 19:39:39 +03:00
|
|
|
let unmount = false;
|
2024-04-19 05:45:48 +01:00
|
|
|
let editorChangeHandlerId;
|
2023-11-26 12:51:55 +00:00
|
|
|
|
2024-04-02 15:21:49 +01:00
|
|
|
function getTinymce() {
|
|
|
|
|
const getSink = () => {
|
|
|
|
|
return typeof window !== 'undefined' ? window : global;
|
|
|
|
|
};
|
|
|
|
|
const sink = getSink();
|
2024-05-14 15:22:30 +01:00
|
|
|
const res = sink && sink.tinymce ? sink.tinymce : null;
|
|
|
|
|
console.log({ res });
|
|
|
|
|
return res;
|
2024-04-02 15:21:49 +01:00
|
|
|
}
|
|
|
|
|
|
2023-09-05 13:21:44 +00:00
|
|
|
// editor configuration
|
|
|
|
|
let conf = {
|
2025-10-28 11:59:21 +01:00
|
|
|
plugins: 'lists, link, emoticons, code, media, searchreplace, eqneditor',
|
2023-09-05 13:21:44 +00:00
|
|
|
toolbar: [
|
|
|
|
|
{ name: 'history', items: ['undo', 'redo'] },
|
|
|
|
|
{ name: 'styles', items: ['styles'] },
|
|
|
|
|
{ name: 'formatting', items: ['bold', 'italic'] },
|
|
|
|
|
{ name: 'alignment', items: ['alignleft', 'aligncenter', 'alignright', 'alignjustify'] },
|
|
|
|
|
{ name: 'indentation', items: ['outdent', 'indent'] },
|
2023-12-06 18:05:00 +03:00
|
|
|
{ name: 'list', items: ['numlist', 'bullist'] },
|
|
|
|
|
{ name: 'link', items: ['link'] },
|
|
|
|
|
{ name: 'insert', items: ['emoticons'] },
|
|
|
|
|
{ name: 'code', items: ['code'] },
|
2024-04-02 15:21:49 +01:00
|
|
|
{ name: 'media', items: ['media'] },
|
2025-10-28 11:59:21 +01:00
|
|
|
{ name: 'search', items: ['searchreplace'] },
|
2024-04-02 15:21:49 +01:00
|
|
|
{ name: 'eqneditor', items: ['eqneditor'] }
|
2023-09-05 13:21:44 +00:00
|
|
|
],
|
|
|
|
|
lists_indent_on_tab: false,
|
|
|
|
|
min_height: height,
|
2023-10-08 15:34:37 +01:00
|
|
|
max_height: maxHeight,
|
2023-09-05 13:21:44 +00:00
|
|
|
placeholder: placeholder,
|
2023-11-26 12:51:55 +00:00
|
|
|
skin: 'oxide-dark',
|
|
|
|
|
content_css: 'dark',
|
2024-04-02 15:21:49 +01:00
|
|
|
extended_valid_elements: '*[.*]',
|
2024-04-15 21:37:59 +01:00
|
|
|
license_key: 'gpl',
|
2024-04-02 15:21:49 +01:00
|
|
|
setup: () => {
|
|
|
|
|
addMathPlugin(getTinymce());
|
|
|
|
|
},
|
2023-09-11 13:15:50 +01:00
|
|
|
init_instance_callback: function (editor: any) {
|
2023-09-05 13:21:44 +00:00
|
|
|
editorWindowRef = editor.iframeElement?.contentWindow;
|
2023-11-26 12:51:55 +00:00
|
|
|
|
2024-04-19 05:45:48 +01:00
|
|
|
editor.on('Paste Change input Undo Redo', function () {
|
|
|
|
|
clearTimeout(editorChangeHandlerId);
|
2024-07-07 07:34:33 +01:00
|
|
|
const html = editor.getContent();
|
2023-09-13 18:56:58 +00:00
|
|
|
|
2024-04-19 05:45:48 +01:00
|
|
|
editorChangeHandlerId = setTimeout(function () {
|
|
|
|
|
if (onChange) {
|
|
|
|
|
onChange(html);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (id) {
|
|
|
|
|
localStorage.setItem(id, html);
|
|
|
|
|
}
|
|
|
|
|
}, 1000);
|
2023-09-05 13:21:44 +00:00
|
|
|
});
|
|
|
|
|
}
|
2021-05-08 11:47:18 +03:00
|
|
|
};
|
2023-09-11 13:15:50 +01:00
|
|
|
|
2023-11-26 12:51:55 +00:00
|
|
|
function handleModeChange(isDark: boolean) {
|
|
|
|
|
if (isDark) {
|
|
|
|
|
conf.content_css = 'dark';
|
|
|
|
|
conf.skin = 'oxide-dark';
|
|
|
|
|
} else {
|
|
|
|
|
conf.content_css = 'light';
|
|
|
|
|
conf.skin = 'oxide';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unmount = true;
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
unmount = false;
|
|
|
|
|
}, 200);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-11 13:15:50 +01:00
|
|
|
$: value = !value ? '' : value;
|
2023-11-26 12:51:55 +00:00
|
|
|
|
2024-02-01 20:18:03 +01:00
|
|
|
$: handleModeChange($globalStore.isDark);
|
2020-12-29 04:01:30 +02:00
|
|
|
</script>
|
|
|
|
|
|
2024-05-14 15:22:30 +01:00
|
|
|
<svelte:head>
|
|
|
|
|
<link rel="stylesheet" href="https://unpkg.com/katex@0.12.0/dist/katex.min.css" />
|
|
|
|
|
</svelte:head>
|
|
|
|
|
|
2023-09-05 13:21:44 +00:00
|
|
|
<div>
|
2023-11-26 12:51:55 +00:00
|
|
|
{#if !unmount}
|
2024-05-14 15:22:30 +01:00
|
|
|
<Editor bind:value bind:conf />
|
2023-11-26 12:51:55 +00:00
|
|
|
{/if}
|
2021-05-08 11:47:18 +03:00
|
|
|
</div>
|