GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lowcode-engine/docs/docs/api/project.md at main · zhishouxun/lowcode-engine

Expand file tree

/

project.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
346 lines (270 loc) · 9.23 KB
/

project.md

Copy path

File metadata and controls

346 lines (270 loc) · 9.23 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions
title project - 模型 API
sidebar_position 3

模块简介

引擎编排模块中包含多种模型,包括:

  • 文档模型 DocumentModel
  • 节点模型 Node
  • 节点孩子模型 NodeChildren
  • 属性模型 Prop
  • 属性集模型 Props

他们的依赖关系如下图: image.png

在文档模型内部,又有一些引申模型,比如:

  • 历史操作 History)
  • 画布节点选中 Selection)
  • 画布节点悬停 Detecting)
  • 模态节点管理器 ModalNodesManager

整个模型系统,以 project API 为入口,所有模型实例均需要通过 project 来获得,比如 project.currentDocument 来获取当前的文档模型,project.currentDocument.nodesMap 来获取当前文档模型里所有的节点列表。

下面来看看 project API 的具体介绍

变量

currentDocument

获取当前的 document 实例

/**
 * 获取当前的 document
 * get current document
 */
get currentDocument(): IPublicModelDocumentModel | null;

相关类型:IPublicModelDocumentModel

documents

获取当前 project 下所有 documents

/**
 * 获取当前 project 下所有 documents
 * get all documents of this project
 * @returns
 */
get documents(): IPublicModelDocumentModel[];

相关类型:IPublicModelDocumentModel

simulatorHost

获取模拟器的 host

/**
 * 获取模拟器的 host
 * get simulator host
 */
get simulatorHost(): IPublicApiSimulatorHost | null;

相关类型:IPublicApiSimulatorHost

方法

openDocument

打开一个 document

/**
 * 打开一个 document
 * @param doc
 * @returns
 */
openDocument(doc?: string | IPublicTypeRootSchema | undefined): IPublicModelDocumentModel | null;

相关类型:

  • IPublicApiSimulatorHost
  • IPublicTypeRootSchema

createDocument

创建一个 document

/**
 * 创建一个 document
 * create a document
 * @param data
 * @returns
 */
createDocument(data?: IPublicTypeRootSchema): IPublicModelDocumentModel | null;

相关类型:

  • IPublicApiSimulatorHost
  • IPublicTypeRootSchema

removeDocument

删除一个 document

/**
 * 删除一个 document
 * remove a document
 * @param doc
 */
removeDocument(doc: IPublicModelDocumentModel): void;

相关类型:IPublicApiSimulatorHost

getDocumentByFileName

根据 fileName 获取 document

/**
 * 根据 fileName 获取 document
 * get a document by filename
 * @param fileName
 * @returns
 */
getDocumentByFileName(fileName: string): IPublicModelDocumentModel | null;

相关类型:IPublicApiSimulatorHost

getDocumentById

根据 id 获取 document

/**
 * 根据 id 获取 document
 * get a document by id
 * @param id
 * @returns
 */
getDocumentById(id: string): IPublicModelDocumentModel | null;

相关类型:IPublicApiSimulatorHost

exportSchema

导出 project schema

/**
 * 导出 project
 * export project to schema
 * @returns
 */
exportSchema(stage: IPublicEnumTransformStage): IPublicTypeProjectSchema;

相关类型:

  • IPublicEnumTransformStage
  • IPublicTypeProjectSchema

importSchema

导入 project

/**
 * 导入 project schema
 * import schema to project
 * @param schema 待导入的 project 数据
 */
importSchema(schema?: IPublicTypeProjectSchema): void;

相关类型:IPublicTypeProjectSchema

getCurrentDocument

获取当前的 document

/**
 * 获取当前的 document
 * get current document
 * @returns
 */
getCurrentDocument(): IPublicModelDocumentModel | null;

相关类型:IPublicModelDocumentModel

addPropsTransducer

增加一个属性的管道处理函数

/**
 * 增加一个属性的管道处理函数
 * add a transducer to process prop
 * @param transducer
 * @param stage
 */
addPropsTransducer(
    transducer: IPublicTypePropsTransducer,
    stage: IPublicEnumTransformStage,
  ): void;

相关类型:

  • IPublicTypePropsTransducer
  • IPublicEnumTransformStage

示例

在保存的时候删除每一个组件的 props.hidden

import { project } from '@alilc/lowcode-engine';
import { IPublicTypeCompositeObject, IPublicEnumTransformStage, IPublicModelPluginContext } from '@alilc/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

设置多语言语料

/**
 * 设置多语言语料
 * 数据格式参考 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 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

如何扩展项目配置

// shims.d.ts
declare module '@alilc/lowcode-types' {
  export interface IPublicTypeAppConfig {
    customProp: CustomPropType
  }
}

export {};

事件

onRemoveDocument

绑定删除文档事件

/**
 * 绑定删除文档事件
 * set callback for event onDocumentRemoved
 * @param fn
 * @since v1.0.16
 */
onRemoveDocument(fn: (data: { id: string }) => void): IPublicTypeDisposable;

相关类型:IPublicTypeDisposable

@since v1.0.16

onChangeDocument

当前 project 内的 document 变更事件

/**
 * 当前 project 内的 document 变更事件
 * set callback for event onDocumentChanged
 */
onChangeDocument(fn: (doc: IPublicModelDocumentModel) => void): IPublicTypeDisposable;

相关类型:

  • IPublicModelDocumentModel
  • IPublicTypeDisposable

onSimulatorHostReady

当前 project 的模拟器 ready 事件

/**
 * 当前 project 的模拟器 ready 事件
 * set callback for event onSimulatorHostReady
 */
onSimulatorHostReady(fn: (host: IPublicApiSimulatorHost) => void): IPublicTypeDisposable;

相关类型:

  • IPublicApiSimulatorHost
  • IPublicTypeDisposable

onSimulatorRendererReady

当前 project 的渲染器 ready 事件

/**
 * 当前 project 的渲染器 ready 事件
 * set callback for event onSimulatorRendererReady
 */
onSimulatorRendererReady(fn: () => void): IPublicTypeDisposable;

相关类型:IPublicTypeDisposable

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.