Svelte integration

Embed the hosted MailLayers editor in Svelte

Use the lightweight Svelte SDK to mount the hosted MailLayers editor in an iframe with typed props, dispatched events, reload methods, and deterministic destroy cleanup.

Published on npm

Version 0.1.0 · Install from npm or review the source on GitHub.

npm install @maillayers/svelte-email-editor
Svelte component
<script lang="ts">
  import { MailLayersEmailEditor } from "@maillayers/svelte-email-editor";

  let apiKey = "your-browser-sdk-key";
  let embedToken = "server-issued-token";
</script>

<MailLayersEmailEditor
  {apiKey}
  {embedToken}
  initialHtml="<h1>Welcome</h1>"
  on:change={(e) => saveDraft(e.detail)}
  on:save={(e) => persistHtml(e.detail)}
  on:authError={(e) => reportAuthError(e.detail)}
/>

Production integration

Content, assets, security, and lifecycle

A useful embedded email editor is more than a mounted component. Plan the persistence and trust boundaries before connecting it to customer data.

Editor data methods

Use getHtml() for a sendable snapshot and getJson() for structured editor state. Call reload() only when staged content or configuration should start a new iframe handshake; use ready, load, change, save, and status callbacks for normal updates.

Assets

Implement upload, list, and delete handlers against storage owned by your application. Validate file type and size on the server, authorize each tenant-scoped object, return HTTPS URLs, and treat delete as an authenticated operation.

API keys and allowed domains

Use a browser SDK key only from an exact configured origin. Keep privileged secrets on your server, issue scoped embed tokens after authenticating the user, and do not treat iframe messages as trusted until origin and payload validation pass.

Multiple instances

Give each mounted editor stable state and separate callbacks. Avoid reusing one imperative ref across instances, and unmount inactive editors when tabs or routes no longer need them so listeners and iframe resources are released.

Performance

Reserve editor height to prevent layout shift, defer mounting until the authoring UI is needed, and show a stable loading fallback. Avoid remounting the iframe for ordinary form-state changes; prefer events and staged reloads.

Troubleshooting

If the editor does not become ready, verify the allowed origin, browser key, embed-token lifetime, editor URL, and Content Security Policy. For missing saves, inspect callback errors and confirm the host persistence request succeeds independently of the iframe.

Integration

Svelte props and events map to the hosted iframe bridge

  1. 01

    Pass apiKey, embedToken, and initialHtml as component props. Content props are staged and applied when reload() starts a new handshake.

  2. 02

    Listen for change, save, ready, load, statusChange, and authError events dispatched from the component.

  3. 03

    Call reload() on the component instance when staged initial content or configuration should begin a new handshake. onDestroy tears down the iframe bridge.

Relevant capabilities

What this integration actually supports

Svelte 4+
The package targets Svelte 4 and later with standard component props and event dispatchers.
Full asset callbacks
Upload, list, and delete handlers connect the editor to your storage boundary.
Typed events
Change, save, ready, status, load, and sanitized authError events integrate with your store or persistence layer.

Product boundary: MailLayers is the hosted editing surface, not an authentication provider, asset store, approval engine, ESP, or email delivery service. The editor mounts only in a browser with a real host element.

Related integration guides

Engineering articles

Read implementation notes about editor security, persistence, asset workflows, and framework-specific patterns.

Browse the MailLayers blog

FAQ

Questions specific to this integration

Which Svelte version is supported?

Svelte 4 and later. The package requires svelte >=4.0.0 as a peer dependency.

Can SvelteKit import the package?

Yes, but the editor component must mount on the client. Use a client-only boundary for the editor route or component.

How do I persist editor content?

Handle the change event for draft HTML and the save event when you need a committed snapshot for your sending workflow.

Continue with the verified integration guide

Review licensing, allowed domains, events, assets, SSR boundaries, and troubleshooting before production use.