Web: Svelte
@nitrakit/svelte gives you two actions that show an editor in your elements. It builds on
@nitrakit/web: read the JavaScript page for requirements, the license key, media
and export. Everything from @nitrakit/web is re-exported.
npm install @nitrakit/svelte
Show the editor
Create the editor when the component mounts and destroy it when it goes away; the preview
and controls actions show it in any element.
<script lang="ts">
import { onMount } from 'svelte'
import { createEditor, preview, controls, type Editor } from '@nitrakit/svelte'
let editor = $state<Editor | null>(null)
onMount(() => {
const ready = createEditor({
width: 1080,
height: 1920,
async onRequest(request) {
if (request.kind === 'addMedia') {
const file = await openMyMediaLibrary()
return file ? { source: (await editor!.addMedia(startUpload(file), file)).source } : null
}
// anything else: the built-in picker
},
}).then((e) => (editor = e))
return () => ready.then((e) => e.destroy())
})
</script>
<div use:preview={editor} style="height: 60vh"></div>
<div use:controls={editor} style="height: 320px"></div>
Call load() and setLicense() once at start-up, before creating editors.