Quick Start: Implement the Edra Editor in Svelte 5
nextTo use Edra, install it via the shadcn-svelte registry, then use createEditor to instantiate the editor instance and the <Edra> component to render the UI.
Edra provides several sub-components for building the interface:
<Edra.Toolbar />: The editor toolbar.<Edra.BubbleMenu />: A floating menu that appears when text is selected.<Edra.Content />: The main editable area.<Edra.DragHandle />: Provides Notion-like drag-and-drop block mechanics.<Edra.UseAI />: Enables AI-driven features.
You can provide an onUpdate callback to handle content changes and a callAI function to implement your own AI provider for streaming completions.
<script lang="ts">
import { createEditor, Edra } from '$lib/edra/shadcn/index.js';
import { updateInDB } from '$lib/db';
const onUpdate = () => {
const content = editor?.getJSON();
updateInDB(content);
};
async function callAI(
prompt: string,
onChunk: (chunk: string) => void,
onError: (error: Error) => void
) {}
const editor = createEditor({
onUpdate,
callAI
});
</script>
<div class="rounded-lg border">
<Edra {editor}>
<Edra.UseAI />
<Edra.Toolbar class="max-w-full! scrollbar-none overflow-x-scroll border-b p-1" />
<Edra.BubbleMenu />
<Edra.Content class="h-150 cursor-auto overflow-y-scroll px-8 py-4 *:outline-none" />
<Edra.DragHandle />
</Edra>
</div