Appearance
Landing Page Editor Instance
Initialization
Load the editor script, then call the global LandingPageEditor factory. Options go under config; callbacks are top-level properties passed next to config.
html
<script
src="https://v1.page-assets.topol.io/loader/build.js"
type="text/javascript"
></script>The legacy https://v1.page-assets.topol.io/topol-lpe.js URL still serves the same file for existing integrations.
js
const editor = LandingPageEditor({
config: {
authorize: { apiKey: "YOUR_API_KEY", entityId: "user-123" },
// ... other options
},
onSave({ json, html }) {
console.log("Saved:", json, html);
},
onInit() {
console.log("Editor is ready");
},
});
editor.render("#landing-page-editor");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.
Methods Reference
render(container: string | HTMLElement) => Promise<void>Renders the editor into the given container (a CSS selector or an element). Learn more
load(json: string | object) => Promise<void>Loads a template into the editor; accepts a JSON string or a parsed object. The Promise resolves once the template is applied. Synced sections in the loaded template are then refreshed from api.SAVED_SECTIONS. A template that fails to load is reported to the user in a notification and the Promise still resolves.
save({ langCode? }?) => Promise<void>Renders the current template server-side, then triggers the onSave({ json, html, mutations }) callback. For a multilingual page, langCode picks the language of the returned html (default: the primary language). The Promise settles once the save has finished, including your onSave Promise, so the onSave fired meanwhile is this call's answer. Only one save runs at a time: calling save() while another save is running rejects with err.code === "SAVE_IN_PROGRESS" and fires no onSave. A langCode the page does not have rejects with err.name === "UnknownLanguageError" before anything is rendered, and fires no onSave either: the editor never substitutes the primary language for a language you asked for. A failed save still resolves the Promise and is reported through onEditorError with source: "save". See one save at a time.
togglePreview() => Promise<void>Toggles preview mode on or off.
setPreviewSize(index: number) => Promise<void>Switches the preview device by numeric index (0 = mobile, 1 = mobile landscape, 2 = tablet, 3 = desktop). Any other value selects desktop.
undo() => Promise<void>Undoes the last change.
redo() => Promise<void>Redoes the last undone change.
chooseFile(url: string) => Promise<void>Returns the selected file URL to the editor (for custom file manager). Learn more
refreshSyncedSections() => Promise<void>Refreshes synced sections listing and reloads template with latest changes. The Promise resolves once the placed sections are reloaded. Learn more
refreshComments(key: string) => Promise<void>Refreshes comments for a specific conversation. The Promise resolves once the conversation list has reloaded. Learn more
openPremadeTemplatesSelection() => Promise<void>Opens the premade templates picker dialog.
setTemplateName(name: string) => Promise<void>Sets the template name shown in the editor.
updateOptions(options: Partial<Omit<IPluginOptions, 'authorize'>>) => Promise<void>Reconfigures a running editor. Accepts any editor options except authorize; the credentials are fixed when the editor starts. The Promise resolves once the options are applied and rejects when they fail validation. Learn more
toggleSelectionPanel() => Promise<void>Collapses or expands the right-side selection panel (properties of the selected element).
toggleAutosaves() => Promise<void>Opens or closes the autosaves panel. Does nothing while enableAutosaves is off. Learn more
toggleComments() => Promise<void>Opens or closes the comments panel. Does nothing while enableComments is off. Learn more
setActiveMembers(activeMembers: string[]) => Promise<void>Replaces the presence list shown in the top bar. It is a display indicator, not co-editing.
updateCustomBlockContent(content: string) => Promise<void>Replaces the content of the custom block whose dialog was last opened through onOpenCustomBlockDialog. The Promise rejects when content is not a string. Learn more
createNotification(notification: INotification) => Promise<void>Displays a custom notification in the editor. Always shown, even with disableAlerts enabled, and never forwarded to onAlert. Learn more
createLanguage(code: string, primary?: boolean) => voidAdds a page language; the first one becomes primary. Learn more
selectLanguage(code: string) => voidShows the given language in the editor.
setPrimaryLanguage(code: string) => voidMakes the given language primary (an unknown code is created as the new primary).
deleteLanguage(code: string) => voidRemoves a non-primary language.
getMutations() => Promise<{ code: string; primary: boolean }[]>Returns the page languages; also delivered through onGetMutations({ mutations }).
translateLanguage(code: string, sourceCode?: string) => Promise<void>Translates the given language with AI from sourceCode (default: the primary language).
translateAllLanguages() => Promise<void>Translates every non-primary language from the primary one with AI.
translateTemplate(code: string) => Promise<boolean>Translates the page in place into code with AI (pages without languages; resolves false on a multilingual page or for an invalid code). Synced structures are left out. When every text was translated, the page language in the settings is set to code.
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.
Example Usage
js
// Load a template
editor.load(templateJson);
// Trigger save
editor.save();
// Update authorization header
editor.updateApiAuthorizationHeader("Bearer new_token");
// Refresh synced sections
editor.refreshSyncedSections();
// Reconfigure a running editor
editor.updateOptions({ hideSelectionPanel: true });
// Tear down the editor iframe
editor.destroy();TypeScript Interface
ts
interface ILandingPageEditor {
render: (container: string | HTMLElement) => Promise<void>;
load: (json: string | object) => Promise<void>;
save: () => Promise<void>;
togglePreview: () => Promise<void>;
setPreviewSize: (index: number) => Promise<void>;
undo: () => Promise<void>;
redo: () => Promise<void>;
chooseFile: (url: string) => Promise<void>;
refreshSyncedSections: () => Promise<void>;
refreshComments: (key: string) => Promise<void>;
openPremadeTemplatesSelection: () => Promise<void>;
setTemplateName: (name: string) => Promise<void>;
updateOptions: (
options: Partial<Omit<IPluginOptions, "authorize">>
) => Promise<void>;
toggleSelectionPanel: () => Promise<void>;
toggleAutosaves: () => Promise<void>;
toggleComments: () => Promise<void>;
setActiveMembers: (activeMembers: string[]) => Promise<void>;
updateCustomBlockContent: (content: string) => Promise<void>;
updateApiAuthorizationHeader: (
newAuthHeader: string | Record<string, string | null>
) => Promise<void>;
createNotification: (notification: INotification) => Promise<void>;
destroy: () => Promise<void>;
/** Alias of `destroy`. */
close: () => Promise<void>;
}IPluginOptions is the options interface from the Options reference.
