Skip to content

Developing Plugins

Plugins usually extend Runtime by registering lifecycle steps.

Plugin Shape

js
export default {
    name: 'MyPlugin',
    install(runtime) {
        runtime.lifecycleChain.addStep('BEFORE_TRANSFORM_DATA', (data) => {
            return data;
        });
    },
};

Installing a Plugin

js
import { useRuntimeApp } from '@ptahjs/ui-vue';
import MyPlugin from './my-plugin';

const runtime = useRuntimeApp({ id: 've1' });
MyPlugin.install(runtime);
TypeDescription
BEFORE_TRANSFORM_DATANormalize or validate raw schema before compile
GET_PAGE_SCHEMA_DATAAdjust exported page schema
RENDERER_MODULE_CONTENTWrap rendered content
RENDERER_MODULE_ITEMOverride per-module rendering

Example

js
import { LIFECYCLE_TYPE } from '@ptahjs/ui-vue';

export const DefaultScenePlugin = {
    name: 'DefaultScenePlugin',
    install(runtime) {
        runtime.lifecycleChain.addStep(LIFECYCLE_TYPE.BEFORE_TRANSFORM_DATA, (schema) => {
            if (!schema.scenes || schema.scenes.length === 0) {
                return {
                    ...schema,
                    scenes: [{ id: 'default', props: { title: 'Page 1' } }],
                };
            }
            return schema;
        });
    },
};