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);Recommended Hook Types
| Type | Description |
|---|---|
BEFORE_TRANSFORM_DATA | Normalize or validate raw schema before compile |
GET_PAGE_SCHEMA_DATA | Adjust exported page schema |
RENDERER_MODULE_CONTENT | Wrap rendered content |
RENDERER_MODULE_ITEM | Override 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;
});
},
};