A Svelte wrapper for the Unlayer Email Editor, making it easy to integrate the editor into Svelte applications.
npm install @unlayer/svelte
Or if you prefer using yarn:
yarn add @unlayer/svelte
<script lang="ts">
import { UnlayerEditor } from '@unlayer/svelte';
function handleExport(event) {
const { html, design } = event.detail;
console.log(html, design);
}
</script>
<UnlayerEditor
on:export-html={handleExport}
/>
<script lang="ts">
import { UnlayerEditor } from '@unlayer/svelte';
import initialDesign from './welcome.json';
function handleExport(event) {
const { html, design } = event.detail;
console.log(html, design);
}
</script>
<UnlayerEditor
design={initialDesign}
on:export-html={handleExport}
/>
<script lang="ts">
import { UnlayerEditor } from '@unlayer/svelte';
// Only allow specific tools
const tools = {
list: ['text', 'button', 'image', 'divider'],
exclude: false // This is a whitelist
};
</script>
<UnlayerEditor
tools={tools}
/>
<script lang="ts">
import { UnlayerEditor } from '@unlayer/svelte';
const options = {
displayMode: 'email',
appearance: {
theme: 'dark'
},
features: {
imageEditor: true
}
};
</script>
<UnlayerEditor
options={options}
/>
<script lang="ts">
import { UnlayerEditor } from '@unlayer/svelte';
let editor: UnlayerEditor;
function exportHtml() {
editor.exportHtml();
}
function loadDesign() {
editor.loadDesign({
body: {
rows: [],
values: {}
}
});
}
</script>
<button on:click={exportHtml}>Export HTML</button>
<button on:click={loadDesign}>Load Empty Design</button>
<UnlayerEditor bind:this={editor} />
Prop | Type | Description |
---|---|---|
design |
Design |
The design JSON to load into the editor |
tools |
Tools |
Tools configuration for the editor (whitelist or blacklist) |
options |
UnlayerOptions |
Additional options for the Unlayer editor |
Event | Detail | Description |
---|---|---|
loaded |
void |
Fired when the editor is fully loaded and ready |
design-updated |
{ design: Design } |
Fired when the design is updated |
export-html |
{ html: string, design: Design } |
Fired when HTML is exported |
Method | Parameters | Description |
---|---|---|
exportHtml() |
None | Exports the current design as HTML |
loadDesign(design: Design) |
design: Design |
Loads a design into the editor |
saveDesign(callback?: (design: Design) => void) |
callback?: (design: Design) => void |
Saves the current design |
This package includes TypeScript definitions for all props, events, and methods. You can import the types from the package:
import type { Design, Tools, UnlayerOptions } from '@unlayer/svelte';
git clone https://github.com/your-username/unlayer-svelte.git
cd unlayer-svelte
npm install
npm run dev
npm run build
MIT