2026-06-07 18:43:05 +01:00
|
|
|
<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">
|
2026-06-07 18:43:05 +01:00
|
|
|
// Type-only imports are erased at build time — no static TipTap dependency.
|
2025-12-02 09:54:38 +01:00
|
|
|
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 {
|
2025-11-21 12:18:04 +01:00
|
|
|
placeholder?: string | ((node: any) => string);
|
2025-12-02 09:54:38 +01:00
|
|
|
content?: HTMLContent;
|
2025-11-21 12:18:04 +01:00
|
|
|
showToolBar?: boolean;
|
|
|
|
|
editable?: boolean;
|
|
|
|
|
enablePersistence?: boolean;
|
|
|
|
|
contentStorageKey?: string;
|
|
|
|
|
editableStorageKey?: string;
|
|
|
|
|
class?: string;
|
|
|
|
|
editorClass?: string;
|
2025-12-02 09:54:38 +01:00
|
|
|
onChange?: (content: HTMLContent) => void;
|
2025-11-21 12:18:04 +01:00
|
|
|
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 = '',
|
2025-11-21 12:18:04 +01:00
|
|
|
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>
|
|
|
|
|
|
2026-06-07 18:43:05 +01:00
|
|
|
{#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}
|