Events
Every event the image editor emits.
Every callback and DOM event of the image editor, with its payload. See Events for examples.
Callbacks
| Callback | Arguments | When |
|---|---|---|
onExport | file: File, extras?: EditorExtras | The user presses Save & Exit or Share. |
callback | file: File, extras?: EditorExtras | The same moment as onExport. An older name. |
onClose | none | The user closes the editor, and after Save & Exit and Share. |
onSaveTemplate | props: { ...metadata, template: Template } | The user saves a template or a draft. Returns a promise. |
onGetTemplates | filter? | The Templates panel opens, or the user presses Refresh. Returns a promise of Template[]. |
onUploadAsset | file: File, ctx: UploadAssetContext | The editor stores a picture. Returns a promise of { url }. |
resolveAssetUrl | stored: string, ctx: { type } | The editor loads a stored picture. Returns a promise of an address. |
onCustomAction | event: ImageCustomActionEvent | A custom action starts or ends. |
onBrandChange | brandId: string | The editor opens with a brand kit, and the user switches the kit. See Brand kits. |
onLicenseState | report: LicenseStateReport | The license state changes. |
renderLicenseBlocked | state: BlockedState | The license check stops the editor. Returns your screen. |
DOM events
<media-editor-image> sends these events. They bubble, and they cross shadow DOM boundaries.
| Event | event.detail | When |
|---|---|---|
export | The exported File | The user presses Save & Exit or Share. |
close | none | The user closes the editor, and after Save & Exit and Share. |
templatesave | { template, saved } | After each save of a template or a draft. |
customaction | ImageCustomActionEvent | A custom action starts or ends. |
brandchange | The kit id, a string | The editor opens with a brand kit, and the user switches the kit. |
Callbacks that return a value, such as onSaveTemplate and onGetTemplates, have no DOM event. Pass them through the props property.
EditorExtras
The second argument of onExport.
| Field | Type | Description |
|---|---|---|
email | { to: string; name: string } | Present after Share: the address and the name that the user typed. |
templateID | string | The id of the defaultTemplate the editor was opened with. Absent when the editor was opened without one. |
Every field is optional, and so is the whole object. Read each field with a check, such as extras?.email?.to.
templatesave detail
| Field | Type | Description |
|---|---|---|
template | Template | null | The template that was saved. null when the editor could not prepare the design. |
saved | boolean | true when your onSaveTemplate promise resolved within 30 seconds. |
Template
| Field | Type | Description |
|---|---|---|
id | string | A new UUID for each save. |
scene | string | The design, as JSON text. |
thumbUri | string | A preview picture: a data: URL, or the address from onUploadAsset. |
sceneMode | string | 'image'. |
global | boolean | false. |
schemaVersion | number | The version of the scene format, 1. |
canvasWidth, canvasHeight | number | The page size in pixels. |
draft | boolean | true for a draft. |
brandKitId | string | The id of the brand kit that was active when the design was saved. Left out when there was none. |
UploadAssetContext
The second argument of onUploadAsset.
| Field | Type | Description |
|---|---|---|
type | 'image' | 'thumbnail' | A picture of the design, or the preview picture of a template. |
itemId | string | The id of the picture in the design. |
mimeType | string | The type of the file. |
templateId | string | The id of the template being saved. |
sceneMode | 'image' | The editor that asks. |
suggestedPath | string | A path you can use as the storage key. |
source | 'template' | 'generated' | A save, or a picture made or changed with AI. |
capability | string | For source: 'generated': the AI feature. |
producedBy | { capability, catalogId?, modelId?, providerId? } | For source: 'generated': the feature and the model. |
| your fields | string | Every key of assetMetadata. |
LicenseStateReport
The argument of onLicenseState. It never contains the license key.
| Field | Type | Description |
|---|---|---|
state | LicenseGateState | { status: 'running', expiringAt?, insecureContext? } or { status: 'blocked', reason, message }. The type also names pending-online, which is no longer produced. |
reference | string | A line for your support team, for example running · 3f9a12cd · lm-prod-2026-09 · sdk 1.0.0 · 2026-09-21T09:41Z. |
keyHashPrefix | string | The first 8 characters of a hash of the key. Empty when the key was refused in the browser. |
kid | string | The id of the Layermetry key that signed your license key. |
sdkVersion | string | The version of the package, for example 1.0.0. |
hostname | string | The host name of the page. |
insecureContext | boolean | true on a plain http:// page that is not your own computer. |
at | number | The time of the report, in milliseconds since 1 January 1970. |
stopIat | number | Present only when a signed stop from Layermetry stopped the editor. |
BlockedState, the argument of renderLicenseBlocked, is the blocked state: { status: 'blocked', reason, message }. See Error codes for every reason.
AI generation
Pass generation observers inside ai, rather than as editor event props.
import type { EditorAIConfig } from '@layermetry/media-editor';
export const ai: EditorAIConfig = {
endpointUrl: '/api/ai', image: true,
onGenerationError: (error, context) => {
console.warn(error.code, error.providerError?.requestId, context.attemptId);
},
onGenerationEvent: (event) => {
if (event.type === 'progress') console.info(event.percent, event.stage);
},
};| Hook | Arguments | Contract |
|---|---|---|
onGenerationError | SDK error, AIGenerationErrorContext | Observes each failed attempt once. |
onGenerationEvent | AIGenerationEvent | Observes start, progress and one terminal event. |
Hooks observe only. Returning a value does not recover a generation. Throwing does not change its outcome.
Error context
The error context identifies the attempt without copying request content.
| Field | Type | Description |
|---|---|---|
operation | AIInputOperation | The requested operation. |
attemptId | string | The identifier for one logical attempt. |
catalogId, modelId, revision | Optional string | The submitted model identity and schema revision. |
phase | configure, validate, submit, poll, download, read or apply | The stage reported for the failure. |
outcome | not-accepted, accepted or unknown | Whether work acceptance is known. |
requestId | Optional string | The server request identifier. |
fieldPath | Optional string | The outgoing field key that caused refusal. |
The context contains no prompt, source, body, header values or license key. The accompanying error can contain providerError; see Provider errors.
Lifecycle events
Every event contains type, attemptId and operation.
| Type | Other fields | When |
|---|---|---|
start | Optional catalogId, modelId, revision | A logical attempt starts. |
progress | percent, stage | A long-running job reports progress. |
success | Optional catalogId, modelId, requestId | Generation returns a usable result. |
failure | code, phase, optional requestId | Generation fails. |
cancel | phase | Generation is cancelled. |
One attempt emits one start and one terminal success, failure or cancel. A success event confirms generation, not a later user choice to place a candidate.
Generated file receipt
The context of onUploadAsset includes producedBy for generated media.
| Field | Type | Description |
|---|---|---|
capability | string | The operation that created the file. |
catalogId | Optional string | Your model entry’s id on the models route. |
modelId | Optional string | The reported model name, or the requested model when no name was reported. |
providerId | Optional string | The classic provider object’s identifier. |
An omitted identity field stays absent. These fields record identity; they do not prove that a provider applied each requested setting.
CustomActionEvent
| Field | Type | Description |
|---|---|---|
actionId | string | The action id. |
status | started, done, failed, aborted | The run state. |
error | Optional string | The message for a failed run. |
durationMs | Optional number | The elapsed time on every final event. |