Appearance
Callable functions on the Email Editor instance
Initialization
Load the editor script, then call the global TopolEmailEditor factory. Options go under config; callbacks are top-level properties passed next to config. The factory returns the instance your application calls methods on, and render() mounts the editor iframe into the container.
html
<script
src="https://v4.email-assets.topol.io/loader/build.js"
type="text/javascript"
></script>js
const editor = TopolEmailEditor({
config: {
authorize: { apiKey: "YOUR_API_KEY", entityId: "user-123" },
// ... other options
},
onSave({ json, html, mutations, syncedSections }) {
console.log("Saved:", json, html);
},
onInit() {
console.log("Editor is ready");
},
});
editor.render("#app");Every method below returns a Promise. The editor runs in an iframe, so each call is forwarded to it and resolves once the editor has processed it. Calls made right after render() are queued until the editor has initialized, so there is no need to wait for onInit before calling load().
Methods Reference
render(container: string | HTMLElement) => Promise<void>Creates the editor iframe inside the given container (a CSS selector or an element). The container needs an explicit width and height. Learn more
destroy() => Promise<void>Tears down the editor: removes the iframe and empties the container it was mounted into. Safe to call more than once. The same method is available under this name in the NPM packages. close() still works as an alias.
changeEmailToDesktop() => Promise<void>Switches the editing canvas back to desktop view. Learn more
changeEmailToMobile() => Promise<void>Switches the editing canvas to mobile view. Learn more
chooseFile(url: string) => Promise<void>Returns the selected file URL to the editor (for custom file manager). Learn more
createLanguage(code: string) => Promise<void>Creates a new language mutation for the given language code and fires onLanguageCreated. Learn more
createNotification(notification: INotification) => Promise<void>Displays a custom notification in the editor. Always shown, even with disableAlerts enabled. Learn more
deleteLanguage(code: string) => Promise<void>Deletes a language mutation, after the editor shows a confirmation modal. Learn more
getMutations() => Promise<IMutation[]>Resolves to the template's language mutations as { code, primary } entries, without modifying any state. The same list also goes to the onGetMutations callback. Learn more
load(json: string | object) => Promise<void>Loads a template into the editor; accepts a JSON string or a parsed object. Learn more
openPremadeTemplatesSelection() => Promise<void>Opens the premade templates picker dialog. Learn more
redo() => Promise<void>Redoes the last undone change and fires onRedoChange. Learn more
refreshComments(key: string) => Promise<void>Refreshes the comment list; if key matches an open conversation, its detail refreshes too. Pass "" to refresh only the list. The Promise resolves once the list has reloaded. Learn more
refreshSyncedSections() => Promise<void>Refreshes synced sections listing and reloads placed sections with the latest changes. The Promise resolves once the placed sections are reloaded. Learn more
save(options?: { langCode?: string }) => Promise<void>Renders the current template server-side, then triggers the onSave({ json, html, mutations, syncedSections }) callback. The optional langCode selects which language mutation's HTML is returned. The Promise resolves after onSave has settled, including any Promise onSave itself returns. It also resolves when the save fails, so a failure is reported through onEditorError with source: "save". It rejects, with err.code === "SAVE_IN_PROGRESS", only while another save is still running. Learn more
selectLanguage(code: string) => Promise<void>Switches the active editing language and fires onLanguageSelected. Learn more
setActiveMembers(activeMembers: string[]) => Promise<void>Replaces the presence list shown next to the template name in the Window Bar. It is a display indicator, not co-editing. Learn more
setPreviewHTML(html: string | null) => Promise<void>Overrides the HTML shown in the preview pane — used with the onPreview callback to preview server-rendered output. Pass null to clear the override.
setPrimaryLanguage(code: string) => Promise<void>Makes the given language the primary mutation, creating it first if it does not exist yet. Learn more
setSavedSections(savedSections: ISavedSection[]) => Promise<void>Replaces the saved sections list — call it after your application handles a section save, edit, or delete. Learn more
setTemplateName(newName: string) => Promise<void>Sets the template name shown in the editor. Does not re-fire onTemplateRename, so it is safe to call from that callback. Learn more
toggleAutosaves() => Promise<void>Opens or closes the autosave history panel. Learn more
toggleChatAI() => Promise<void>Opens or closes the AI chat panel. Learn more
toggleComments() => Promise<void>Opens or closes the comments sidebar. Learn more
toggleSelectionPanel() => Promise<void>Shows or hides the property panel, the one that shows the selected element's settings. Learn more
toggleDarkMode() => Promise<void>Toggles dark mode rendering of the preview — for host applications with their own theme switch. Learn more
togglePreview() => Promise<void>Enters or leaves preview mode; leaving fires onPreviewClose. Learn more
togglePreviewSize() => Promise<void>Toggles the preview viewport between mobile (375 px) and desktop width. Learn more
translateAllLanguages() => Promise<void>AI-translates every non-primary language from the primary in one pass, overwriting existing translations. The Promise resolves once every language has been processed; a failed language is reported to the user in a notification. Learn more
translateLanguage(code: string, sourceCode?: string) => Promise<void>AI-translates a single language mutation, sourcing from the primary language unless sourceCode is given. The Promise resolves once the translation has finished; a failure is reported to the user in a notification. Learn more
undo() => Promise<void>Undoes the last change and fires onUndoChange. Learn more
updateCustomBlockContent(content: string) => Promise<void>Writes new HTML content into the currently selected custom block. Learn more
updateOptions(options: Partial<Omit<IPluginOptions, 'authorize'>>) => Promise<void>Reconfigures a running editor with a partial options object. Every option except authorize can be passed; the credentials are fixed when the editor starts. The Promise resolves once the options, including a new language, are applied. Learn more
updateTemplate(json: string | object, options?: IUpdateTemplateOptions) => Promise<void>Replaces the whole template in a running editor and fires onTemplateUpdated; pass skipSnapshot: true to skip the undo snapshot. Learn more
Example Usage
js
const editor = TopolEmailEditor({
config: TOPOL_OPTIONS,
onSave({ json, html }) {
/* ... */
},
});
editor.render("#app");
// Load a template
editor.load(templateJson);
// Trigger save
editor.save();
// Save a specific language mutation
editor.save({ langCode: "en" });
// Update authorization header
editor.updateApiAuthorizationHeader("Bearer new_token");
// Reconfigure a running editor
editor.updateOptions({ language: "de" });
// Tear down the editor
editor.destroy();TypeScript Interface
ts
export default interface ITopolEmailEditor {
render: (container: string | HTMLElement) => Promise<void>;
destroy: () => Promise<void>;
/** Alias of `destroy`. */
close: () => Promise<void>;
changeEmailToDesktop: () => Promise<void>;
changeEmailToMobile: () => Promise<void>;
chooseFile: (url: string) => Promise<void>;
createLanguage: (code: string) => Promise<void>;
createNotification: (notification: INotification) => Promise<void>;
deleteLanguage: (code: string) => Promise<void>;
getMutations: () => Promise<IMutation[]>;
load: (json: string | object) => Promise<void>;
openPremadeTemplatesSelection: () => Promise<void>;
redo: () => Promise<void>;
refreshComments: (key: string) => Promise<void>;
refreshSyncedSections: () => Promise<void>;
save: (options?: { langCode?: string }) => Promise<void>;
selectLanguage: (code: string) => Promise<void>;
setActiveMembers: (activeMembers: string[]) => Promise<void>;
setMergeTags: (mergeTags: Array<unknown>) => Promise<void>;
setPreviewHTML: (html: string | null) => Promise<void>;
setPrimaryLanguage: (code: string) => Promise<void>;
setSavedSections: (savedSections: ISavedSection[]) => Promise<void>;
setTemplateName: (newName: string) => Promise<void>;
toggleAutosaves: () => Promise<void>;
toggleHiddenElementsVisibility: () => Promise<void>;
toggleChatAI: () => Promise<void>;
toggleComments: () => Promise<void>;
toggleSelectionPanel: () => Promise<void>;
toggleDarkMode: () => Promise<void>;
togglePreview: () => Promise<void>;
togglePreviewSize: () => Promise<void>;
translateAllLanguages: () => Promise<void>;
translateLanguage: (code: string, sourceCode?: string) => Promise<void>;
undo: () => Promise<void>;
updateApiAuthorizationHeader: (
newAuthHeader: string | Record<string, string | null>
) => Promise<void>;
updateCustomBlockContent: (content: string) => Promise<void>;
updateOptions: (
options: Partial<Omit<IPluginOptions, "authorize">>
) => Promise<void>;
updateTemplate: (
json: string | object,
options?: IUpdateTemplateOptions
) => Promise<void>;
}
interface IMutation {
code: string;
primary: boolean;
}
interface IUpdateTemplateOptions {
skipSnapshot?: boolean;
}IPluginOptions is the options interface from the Options reference.
