Files
classroomio/apps/dashboard/src/lib/features/ui/text-editor.svelte
T

66 lines
1.8 KiB
Svelte
Raw Normal View History

<script module lang="ts">
// Module-level singleton: one Promise shared across all mounted instances.
// Dynamic imports are already cached by the JS engine after the first load,
// but reusing the same Promise avoids redundant microtask chains on remounts.
let pending: Promise<typeof import('@cio/ui/custom/editor')> | null = null;
function loadEditor() {
pending ??= import('@cio/ui/custom/editor');
return pending;
}
</script>
2023-09-11 13:15:50 +01:00
<script lang="ts">
// Type-only imports are erased at build time — no static TipTap dependency.
import type { HTMLContent, TiptapEditor } from '@cio/ui/custom/editor';
2020-12-29 04:01:30 +02:00
2025-11-01 15:49:29 +01:00
interface Props {
placeholder?: string | ((node: any) => string);
content?: HTMLContent;
showToolBar?: boolean;
editable?: boolean;
enablePersistence?: boolean;
contentStorageKey?: string;
editableStorageKey?: string;
class?: string;
editorClass?: string;
onChange?: (content: HTMLContent) => void;
onReady?: (editor: TiptapEditor) => void;
onEditorDestroy?: () => void;
2025-11-01 15:49:29 +01:00
}
2020-12-29 04:01:30 +02:00
2025-11-01 15:49:29 +01:00
let {
2026-03-09 11:18:22 +01:00
content = '',
showToolBar = true,
editable = true,
enablePersistence = false,
contentStorageKey = 'edra-content',
editableStorageKey = 'edra-editable',
class: className = '',
editorClass = '',
placeholder = 'Welcome to ClassroomIO',
onChange,
onReady,
onEditorDestroy
2025-11-01 15:49:29 +01:00
}: Props = $props();
2020-12-29 04:01:30 +02:00
</script>
{#await loadEditor()}
<div class="ui:animate-pulse ui:rounded-md ui:bg-muted ui:h-32 ui:w-full" />
{:then { Editor }}
<Editor
{content}
{showToolBar}
{editable}
{enablePersistence}
{contentStorageKey}
{editableStorageKey}
class={className}
{editorClass}
{placeholder}
onContentChange={onChange}
onEditorReady={onReady}
{onEditorDestroy}
/>
{/await}