Skip to main content

Vue Reference

The @pexelize/vue-editor package provides a Vue 3 component and composable for embedding the Pexelize editor.

Installation

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

Quick Start

<script setup lang="ts">
import { PexelizeEditor } from '@pexelize/vue-editor';
import type { DesignJson, EditorOptions } from '@pexelize/editor-types';

const options: EditorOptions = {
user: { id: 'user-1', name: 'Jane', email: 'jane@example.com' },
appearance: { theme: 'light' },
};

function onReady() {
console.log('Editor ready');
}

function onChange(design: DesignJson) {
console.log('Changed', design);
}
</script>

<template>
<PexelizeEditor
:options="options"
style="height: 100vh"
@ready="onReady"
@change="onChange"
/>
</template>

Component Props

PropTypeRequiredDescription
optionsEditorOptionsYesEditor configuration. See Configuration.
designDesignJsonNoInitial design JSON to load.

Component Emits

EventPayloadDescription
readyEditor is fully initialized.
loadDesignJsonA design was loaded.
changeDesignJsonThe design changed.
errorEditorErrorAn editor error occurred.
moduleSaveModuleSaveDataA module was saved.
previewPreviewDataThe user clicked preview.
contentDialogContentDialogDataThe content dialog opened.

Exposed Methods

Access methods via template ref:

<script setup lang="ts">
import { ref } from 'vue';
import { PexelizeEditor } from '@pexelize/vue-editor';
import type { DesignJson, ExportHtmlData } from '@pexelize/editor-types';

const editorRef = ref<InstanceType<typeof PexelizeEditor>>();

async function handleExport() {
const html: ExportHtmlData = await editorRef.value!.exportHtml();
console.log(html);
}

function handleUndo() {
editorRef.value?.undo();
}
</script>

<template>
<button @click="handleExport">Export</button>
<button @click="handleUndo">Undo</button>
<PexelizeEditor
ref="editorRef"
:options="{ user: { id: '1', name: 'Jane', email: 'jane@example.com' } }"
style="height: 100vh"
/>
</template>

Methods Reference

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 theme.
showPreview() => voidOpen preview modal.
hidePreview() => voidClose preview modal.

usePexelizeEditor Composable

For reactive control over the editor:

<script setup lang="ts">
import { PexelizeEditor, usePexelizeEditor } from '@pexelize/vue-editor';

const {
editorRef,
isReady,
loadDesign,
getDesign,
exportHtml,
undo,
redo,
setViewMode,
} = usePexelizeEditor();

async function save() {
const design = getDesign();
const html = await exportHtml();
await fetch('/api/designs', {
method: 'POST',
body: JSON.stringify({ design, html }),
});
}
</script>

<template>
<button @click="save" :disabled="!isReady">Save</button>
<PexelizeEditor
ref="editorRef"
:options="{ user: { id: '1', name: 'Jane', email: 'jane@example.com' } }"
style="height: 100vh"
/>
</template>

Composable Return Values

PropertyTypeDescription
editorRefRef<InstanceType<typeof PexelizeEditor>>Template ref to bind.
isReadyRef<boolean>Reactive ready state.
loadDesign(design: DesignJson) => voidLoad a design.
getDesign() => DesignJsonGet the current design.
exportHtml() => Promise<ExportHtmlData>Export as HTML.
exportImage(opts?) => Promise<ExportImageData>Export as image.
exportPdf(opts?) => Promise<ExportPdfData>Export as PDF.
undo() => voidUndo.
redo() => voidRedo.
setViewMode(mode: ViewMode) => voidSwitch view mode.
setTheme(theme: ThemeMode) => voidSwitch theme.
showPreview() => voidOpen preview.
hidePreview() => voidClose preview.

TypeScript

Types are re-exported from @pexelize/editor-types:

import type { DesignJson, EditorOptions, ExportHtmlData } from '@pexelize/vue-editor';
warning

Set an explicit height on the editor container. The editor fills its parent and requires a defined height to render.

tip

The composable is the recommended API — it provides reactive isReady state and avoids manual ref type assertions.