Live demo: https://unlayer-svelte.vercel.app/
Svelte 5 + TypeScript SDK wrapper for the Unlayer Email Editor, plus a minimal demo.
npm i
npm run dev:demo
then open http://localhost:5173npm run build
(outputs dist/
)npm run build:demo
(outputs dist-demo/
)npm i unlayer-svelte
svelte@^5
Install the package and import the Svelte component.
<script lang="ts">
import UnlayerEditor from 'unlayer-svelte'
let editor: InstanceType<typeof UnlayerEditor>
const options = { displayMode: 'email' }
function exportHtml() {
editor.exportHtml()
}
function onExport(e: CustomEvent<{ html: string; design: unknown }>) {
console.log('HTML:', e.detail.html)
}
</script>
<UnlayerEditor bind:this={editor} {options} on:export-html={onExport} />
Props:
design?: object
initial JSON designoptions?: Record<string, any>
Unlayer init options (e.g. { displayMode: 'email' }
)tools?: { whitelist?: string[]; blacklist?: string[] }
simple tools enable/disable helperEvents:
loaded
– editor readydesign-updated
– emits updated JSON designexport-html
– emits { html, design }
error
– when initialization or actions failPublic methods via bind:this
:
exportHtml()
loadDesign(design)
Located under src/demo/
. The main page renders the editor with controls to load public/welcome.json
, export HTML, and preview it in a modal.
Commands:
npm run dev:demo
– start dev server for demonpm run build:demo
– build static demo to dist-demo/
https://editor.unlayer.com/embed.js
as a fallback, avoiding direct npm bundling issues and keeping bundle small.onMount
; destroy()
is called in onDestroy
to prevent leaks.getDesign
.tools
config ({ toolName: { enabled: boolean } }
).window
.npm run build:demo
, Output Directory to dist-demo
.npm run build:demo
and deploy dist-demo/
to any static host.