project - Model API
Module Overview
The orchestration module includes several models:
- Document Model DocumentModel
- Node Model Node
- Node Children Model NodeChildren
- Property Model Prop
- Property Set Model Props
Their relationships are shown below:

Within the document model, there are additional derived models:
The entire model system is accessed through the project API. All model instances must be obtained via project, e.g. project.currentDocument for the current document model, or project.currentDocument.nodesMap for all nodes in the current document.
Below is a detailed introduction to the project API.
Variables
currentDocument
Get the current document instance
/**
* Get the current document
* get current document
*/
get currentDocument(): IPublicModelDocumentModel | null;
Related type: IPublicModelDocumentModel
documents
Get all documents in the current project
/**
* Get all documents in the current project
* get all documents of this project
* @returns
*/
get documents(): IPublicModelDocumentModel[];
Related type: IPublicModelDocumentModel
simulatorHost
Get the simulator host
/**
* Get the simulator host
* get simulator host
*/
get simulatorHost(): IPublicApiSimulatorHost | null;
Related type: IPublicApiSimulatorHost
Methods
openDocument
Open a document
/**
* Open a document
* @param doc
* @returns
*/
openDocument(doc?: string | IPublicTypeRootSchema | undefined): IPublicModelDocumentModel | null;
Related types:
createDocument
Create a document
/**
* Create a document
* create a document
* @param data
* @returns
*/
createDocument(data?: IPublicTypeRootSchema): IPublicModelDocumentModel | null;
Related types:
removeDocument
Remove a document
/**
* Remove a document
* remove a document
* @param doc
*/
removeDocument(doc: IPublicModelDocumentModel): void;
Related type: IPublicApiSimulatorHost
getDocumentByFileName
Get a document by fileName
/**
* Get a document by fileName
* get a document by filename
* @param fileName
* @returns
*/
getDocumentByFileName(fileName: string): IPublicModelDocumentModel | null;
Related type: IPublicApiSimulatorHost
getDocumentById
Get a document by id
/**
* Get a document by id
* get a document by id
* @param id
* @returns
*/
getDocumentById(id: string): IPublicModelDocumentModel | null;
Related type: IPublicApiSimulatorHost
exportSchema
Export project schema
/**
* Export project
* export project to schema
* @returns
*/
exportSchema(stage: IPublicEnumTransformStage): IPublicTypeProjectSchema;
Related types:
importSchema
Import project schema
/**
* Import project schema
* import schema to project
* @param schema Project data to import
*/
importSchema(schema?: IPublicTypeProjectSchema): void;
Related type: IPublicTypeProjectSchema
addPropsTransducer
Add a property transducer function
/**
* Add a property transducer function
* add a transducer to process prop
* @param transducer
* @param stage
*/
addPropsTransducer(
transducer: IPublicTypePropsTransducer,
stage: IPublicEnumTransformStage,
): void;
Related types:
Example
Remove props.hidden from every component on save
import { project } from '@rchh/lowcode-engine';
import {
IPublicTypeCompositeObject,
IPublicEnumTransformStage,
IPublicModelPluginContext,
} from '@rchh/lowcode-types';
export const DeleteHiddenTransducer = (ctx: IPublicModelPluginContext) => {
return {
async init() {
const { project } = ctx;
project.addPropsTransducer(
(props: IPublicTypeCompositeObject): IPublicTypeCompositeObject => {
delete props.hidden;
return props;
},
IPublicEnumTransformStage.Save,
);
},
};
};
DeleteHiddenTransducer.pluginName = 'DeleteHiddenTransducer';
setI18n
Set i18n locale data
/**
* Set i18n locale data
* Data format reference: https://github.com/alibaba/lowcode-engine/blob/main/specs/lowcode-spec.md#2434%E5%9B%BD%E9%99%85%E5%8C%96%E5%A4%9A%E8%AF%AD%E8%A8%80%E7%B1%BB%E5%9E%8Baa
*
* set I18n data for this project
* @param value object
* @since v1.0.17
*/
setI18n(value: object): void;
@since v1.0.17
setConfig
Set current project configuration
/**
* Set current project configuration
* set config for this project
* @param value object
* @since v1.1.4
*/
setConfig(value: IPublicTypeAppConfig): void;
setConfig<T extends keyof IPublicTypeAppConfig>(key: T, value: IPublicTypeAppConfig[T]): void;
@since v1.1.4
How to extend project configuration
// shims.d.ts
declare module '@rchh/lowcode-types' {
export interface IPublicTypeAppConfig {
customProp: CustomPropType;
}
}
export {};
Events
onRemoveDocument
Bind document removal event
/**
* Bind document removal event
* set callback for event onDocumentRemoved
* @param fn
* @since v1.0.16
*/
onRemoveDocument(fn: (data: { id: string }) => void): IPublicTypeDisposable;
Related type: IPublicTypeDisposable
@since v1.0.16
onChangeDocument
Document change event within the current project
/**
* Document change event within the current project
* set callback for event onDocumentChanged
*/
onChangeDocument(fn: (doc: IPublicModelDocumentModel) => void): IPublicTypeDisposable;
Related types:
onSimulatorHostReady
Simulator ready event for the current project
/**
* Simulator ready event for the current project
* set callback for event onSimulatorHostReady
*/
onSimulatorHostReady(fn: (host: IPublicApiSimulatorHost) => void): IPublicTypeDisposable;
Related types:
onSimulatorRendererReady
Renderer ready event for the current project
/**
* Renderer ready event for the current project
* set callback for event onSimulatorRendererReady
*/
onSimulatorRendererReady(fn: () => void): IPublicTypeDisposable;
Related type: IPublicTypeDisposable