More work on the new rich text editor...

This commit is contained in:
Scott Idem
2024-12-03 12:39:30 -05:00
parent 971ffbad02
commit 6d94583885
4 changed files with 309 additions and 361 deletions

View File

@@ -37,11 +37,11 @@ import './element_tiptap_editor.scss';
export let html_text: string = '';
export let default_minimal: boolean = false;
export let show_menu: boolean = true;
export let show_toolbar: boolean = true;
export let placeholder: string = 'Type your text here...';
if (default_minimal) {
show_menu = false;
show_toolbar = false;
}
// export let html_text: string = `
@@ -79,43 +79,9 @@ let element: HTMLDivElement;
let editor: any;
// More default options should be defined later.
// minimal, basic, full
let show_button_kv_defaults: any = {
bold: true,
italic: true,
strike: true,
code: true,
paragraph: false,
heading__h1: false,
heading__h2: false,
heading__h3: false,
heading__h4: false,
heading__h5: false,
heading__h6: false,
bulletList: false,
orderedList: false,
codeBlock: false,
blockquote: false,
horizontalRule: false,
hardBreak: true,
link: false,
unsetLink: true,
unsetAllMarks: true,
undo: true,
redo: false,
};
export let show_button_kv: any;
if (show_button_kv) {
show_button_kv = { ...show_button_kv_defaults, ...show_button_kv };
} else {
show_button_kv = show_button_kv_defaults;
}
// export let new_json = editor?.getJSON();
export let new_html: string = '';
@@ -133,13 +99,10 @@ let mouse_leave_wait: number = 2000;
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- class:py-1={show_menu} -->
{#if 1==3}
<div
on:click={() => {
if (default_minimal) {
editor.chain().focus().setParagraph().run();
show_menu = true;
show_toolbar = true;
}
}}
on:mouseleave={() => {
@@ -147,77 +110,30 @@ let mouse_leave_wait: number = 2000;
mouse_entered_timer = setTimeout(() => {
if (default_minimal) {
show_menu = false;
show_toolbar = false;
}
}, mouse_leave_wait);
// if (default_minimal) {
// show_menu = false;
// }
}}
on:mouseenter={() => {
clearTimeout(mouse_entered_timer);
mouse_entered_timer = setTimeout(() => {
if (default_minimal) {
show_menu = true;
show_toolbar = true;
}
}, mouse_enter_wait);
// if (default_minimal) {
// show_menu = true;
// }
}}
class="xxxeditor textarea p-1 transition-all duration-1000"
class:hidden={true}
class=""
>
<!-- && show_menu -->
<!-- class:h-0={!show_menu} -->
<!-- class:h-auto={show_menu} -->
<!-- class:opacity-0={!show_menu} -->
<!-- class:opacity-100={show_menu} -->
{#if editor && show_menu}
<div
transition:fade={{delay: 250, duration: 750, easing: cubicOut}}
class="
control-group button-group
bg-gray-200
border-b border-gray-400
p-1
transition-all duration-1000
flex flex-row flex-wrap gap-4
items-center justify-between
"
>
<!-- Nothing Here Anymore -->
</div>
{/if} <!-- show_menu -->
<!-- bg-slate-100 px-2 py-2 -->
<div
bind:this={element}
class="tiptap px-2 py-2 relative"
class:font-mono={show_menu}
>
<span
class="placeholder text-sm text-gray-400 italic absolute"
contenteditable="false"
hidden={editor?.getHTML() !== '<p></p>'}
>{placeholder}</span>
</div>
<ShadEditor
class="p-1 transition-all duration-1000"
bind:content={html_text}
bind:new_html={new_html}
placeholder={placeholder}
show_toolbar={show_toolbar}
show_button_kv={show_button_kv}
/>
</div>
{/if}
<main class="my-10 flex w-full flex-col items-center justify-center">
<ShadEditor
class="editor textarea p-1 transition-all duration-1000"
bind:content={html_text}
bind:new_html={new_html}
placeholder={placeholder}
/>
</main>
<style lang="scss">
// :global(.ProseMirror) {