Skip to main content

Vanilla JS Reference

The core @pexelize/editor package works in any JavaScript environment without a framework.

Installation

npm install @pexelize/editor @pexelize/editor-types

Or load via CDN:

<script src="https://cdn.pexelize.com/editor/latest/pexelize.min.js"></script>

Quick Start

<!DOCTYPE html>
<html>
<head>
<style>
#editor-container { height: 100vh; }
</style>
</head>
<body>
<div id="editor-container"></div>
<script type="module">
import { init, createEditor } from '@pexelize/editor';

await init();

const editor = await createEditor('editor-container', {
user: { id: 'user-1', name: 'Jane', email: 'jane@example.com' },
appearance: { theme: 'light' },
});

editor.addEventListener('ready', () => {
console.log('Editor ready');
});

editor.addEventListener('change', (design) => {
console.log('Changed', design);
});
</script>
</body>
</html>

API

init()

Initializes the Pexelize SDK. Must be called once before createEditor.

function init(): Promise<void>;

createEditor()

Creates an editor instance inside the given container element.

function createEditor(
containerId: string,
config: PexelizeConfig,
): Promise<PexelizeEditorInstance>;
ParameterTypeDescription
containerIdstringID of the DOM element to mount the editor into.
configPexelizeConfigFull editor configuration. See Configuration.

destroy()

Destroys the editor instance and cleans up all resources.

const editor = await createEditor('editor-container', config);
// later...
editor.destroy();

isReady()

Returns whether the editor is fully initialized.

editor.isReady(); // boolean

PexelizeEditorInstance Methods

MethodSignatureDescription
loadDesign(design: DesignJson) => voidLoad a design.
getDesign() => DesignJsonGet the current design JSON.
exportHtml() => Promise<ExportHtmlData>Export as HTML.
exportImage(options?: ExportImageOptions) => Promise<ExportImageData>Export as image.
exportPdf(options?: ExportPdfOptions) => Promise<ExportPdfData>Export as PDF.
undo() => voidUndo last action.
redo() => voidRedo last action.
setViewMode(mode: ViewMode) => voidSwitch desktop/tablet/mobile.
setTheme(theme: ThemeMode) => voidSwitch light/dark.
showPreview() => voidOpen preview.
hidePreview() => voidClose preview.
destroy() => voidDestroy the editor.
isReady() => booleanCheck ready state.
addEventListener(event: string, handler: Function) => voidSubscribe to events.
removeEventListener(event: string, handler: Function) => voidUnsubscribe from events.

PexelizeConfig

The full configuration object passed to createEditor:

interface PexelizeConfig {
user: { id: string; name: string; email: string };
locale?: string;
translations?: Record<string, Record<string, string>>;
textDirection?: 'ltr' | 'rtl';
mergeTags?: MergeTag[];
designTags?: Record<string, string>;
specialLinks?: SpecialLink[];
modules?: Module[];
displayConditions?: DisplayCondition[];
appearance?: AppearanceConfig;
tools?: ToolsConfig;
customTools?: CustomTool[];
fonts?: FontDefinition[];
bodyValues?: BodyValues;
header?: DesignJson;
footer?: DesignJson;
editor?: { minRows?: number; maxRows?: number };
features?: FeaturesConfig;
assetStorage?: AssetStorageConfig;
ai?: AIConfig;
callbacks?: PexelizeCallbacks;
}

See Configuration for the full reference of every option.

Complete Example

<!DOCTYPE html>
<html>
<head>
<style>
body { margin: 0; }
.toolbar { padding: 8px; display: flex; gap: 8px; }
#editor-container { height: calc(100vh - 48px); }
</style>
</head>
<body>
<div class="toolbar">
<button id="btn-export">Export HTML</button>
<button id="btn-undo">Undo</button>
<button id="btn-redo">Redo</button>
<button id="btn-save">Save</button>
</div>
<div id="editor-container"></div>

<script type="module">
import { init, createEditor } from '@pexelize/editor';

await init();

const editor = await createEditor('editor-container', {
user: { id: '1', name: 'Jane', email: 'jane@example.com' },
appearance: { theme: 'light', accentColor: '#4f46e5' },
ai: { mode: 'pexelize' },
});

document.getElementById('btn-export').addEventListener('click', async () => {
const { html } = await editor.exportHtml();
console.log(html);
});

document.getElementById('btn-undo').addEventListener('click', () => editor.undo());
document.getElementById('btn-redo').addEventListener('click', () => editor.redo());

document.getElementById('btn-save').addEventListener('click', () => {
const design = editor.getDesign();
fetch('/api/designs', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(design),
});
});
</script>
</body>
</html>
warning

Always call editor.destroy() before removing the container element from the DOM to prevent memory leaks.

tip

For SPAs without a framework, call init() once at app startup and createEditor/destroy per route transition.