diff --git a/docs/docs/api/model/window.md b/docs/docs/api/model/window.md new file mode 100644 index 000000000..8c2fa1802 --- /dev/null +++ b/docs/docs/api/model/window.md @@ -0,0 +1,23 @@ +--- +title: Window +sidebar_position: 12 +--- + +> **@types** [IPublicModelWindow](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/window.ts)
+> **@since** v1.1.0 + + +## 基本介绍 + +低代码设计器窗口模型 + +## 方法签名 + +### importSchema(schema: IPublicTypeNodeSchema) +当前窗口导入 schema + +### changeViewType(viewName: string) +修改当前窗口视图类型 + +### async save +调用当前窗口视图保存钩子 diff --git a/docs/docs/api/workspace.md b/docs/docs/api/workspace.md new file mode 100644 index 000000000..99d1fb6df --- /dev/null +++ b/docs/docs/api/workspace.md @@ -0,0 +1,34 @@ +--- +title: workspace - 应用级 API +sidebar_position: 12 +--- + +> **@types** [IPublicApiWorkspace](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/workspace.ts)
+> **@since** v1.1.0 + + +## 模块简介 + +通过该模块可以开发应用级低代码设计器。 + +## 变量 + +### isActive + +是否启用 workspace 模式 + +### window + +当前设计器窗口模型 + +关联模型 [IPublicModelWindow](./model/window) + +## 方法签名 + +### registerResourceType +注册资源 + +```typescript +/** 注册资源 */ +registerResourceType(resourceName: string, resourceType: 'editor', options: IPublicResourceOptions): void; +``` diff --git a/packages/shell/src/model/window.ts b/packages/shell/src/model/window.ts index c909ee0fa..b471fc864 100644 --- a/packages/shell/src/model/window.ts +++ b/packages/shell/src/model/window.ts @@ -17,7 +17,7 @@ export class Window implements IPublicModelWindow { this[windowSymbol].changeViewType(viewName); } - save() { - return this[windowSymbol].save(); + async save() { + return await this[windowSymbol].save(); } } diff --git a/packages/types/src/shell/api/workspace.ts b/packages/types/src/shell/api/workspace.ts index d8aba8cf1..52db05825 100644 --- a/packages/types/src/shell/api/workspace.ts +++ b/packages/types/src/shell/api/workspace.ts @@ -1 +1,13 @@ -export interface IPublicApiWorkspace {} \ No newline at end of file +import { IPublicModelWindow } from '../model'; +import { IPublicResourceOptions } from '../type'; + +export interface IPublicApiWorkspace { + /** 是否启用 workspace 模式 */ + isActive: boolean; + + /** 当前设计器窗口 */ + window: IPublicModelWindow; + + /** 注册资源 */ + registerResourceType(resourceName: string, resourceType: 'editor', options: IPublicResourceOptions): void; +} \ No newline at end of file diff --git a/packages/types/src/shell/model/window.ts b/packages/types/src/shell/model/window.ts index e5430ab5a..4ffed5d07 100644 --- a/packages/types/src/shell/model/window.ts +++ b/packages/types/src/shell/model/window.ts @@ -1 +1,14 @@ -export interface IPublicModelWindow {} \ No newline at end of file +import { IPublicTypeNodeSchema } from '../type'; + +export interface IPublicModelWindow { + /** 当前窗口导入 schema */ + importSchema(schema: IPublicTypeNodeSchema): void; + + /** 修改当前窗口视图类型 */ + changeViewType(viewName: string): void; + + /** 调用当前窗口视图保存钩子 */ + save(): Promise<{ + [viewName: string]: IPublicTypeNodeSchema | any; + }>; +} \ No newline at end of file diff --git a/packages/types/src/shell/type/index.ts b/packages/types/src/shell/type/index.ts index a42e65e3e..99a510292 100644 --- a/packages/types/src/shell/type/index.ts +++ b/packages/types/src/shell/type/index.ts @@ -72,4 +72,5 @@ export * from './setter-config'; export * from './tip-config'; export * from './widget-config-area'; export * from './hotkey-callback'; -export * from './plugin-register-options'; \ No newline at end of file +export * from './plugin-register-options'; +export * from './resource-options'; \ No newline at end of file diff --git a/packages/types/src/shell/type/resource-options.ts b/packages/types/src/shell/type/resource-options.ts new file mode 100644 index 000000000..63e8e4add --- /dev/null +++ b/packages/types/src/shell/type/resource-options.ts @@ -0,0 +1,32 @@ +export interface IPublicViewFunctions { + /** 视图初始化 */ + init?: () => Promise; + /** 资源保存时调用视图的钩子 */ + save?: () => Promise; +} + +export interface IPublicEditorView { + /** 资源名字 */ + viewName: string; + (ctx: any): IPublicViewFunctions; +} + +export interface IPublicResourceOptions { + /** 资源名字 */ + name: string; + + /** 资源描述 */ + description?: string; + + /** 默认视图类型 */ + defaultViewType: string; + + /** 资源视图 */ + editorViews: IPublicEditorView[]; + + /** save 钩子 */ + save?: () => Promise; + + /** import 钩子 */ + import?: () => Promise; +} \ No newline at end of file diff --git a/packages/workspace/src/editor-window/context.ts b/packages/workspace/src/editor-window/context.ts index 11e101720..31bbc88f3 100644 --- a/packages/workspace/src/editor-window/context.ts +++ b/packages/workspace/src/editor-window/context.ts @@ -26,7 +26,7 @@ export class EditorWindow { const saveResult = await this.editorViews.get(name)?.save(); value[name] = saveResult; } - this.resource.save(value); + return await this.resource.save(value); } async init() { diff --git a/packages/workspace/src/index.ts b/packages/workspace/src/index.ts index 6cd7dd5d3..7faad05f6 100644 --- a/packages/workspace/src/index.ts +++ b/packages/workspace/src/index.ts @@ -2,6 +2,7 @@ import { Editor } from '@alilc/lowcode-editor-core'; import { Skeleton as InnerSkeleton, } from '@alilc/lowcode-editor-skeleton'; +import { IPublicResourceOptions } from '@alilc/lowcode-types'; import { EditorWindow } from './editor-window/context'; import { Resource } from './resource'; @@ -35,7 +36,7 @@ export class Workspace { private resources: Map = new Map(); - registerResourceType(resourceName: string, resourceType: 'editor' | 'webview', options: ResourceOptions): void { + registerResourceType(resourceName: string, resourceType: 'editor' | 'webview', options: IPublicResourceOptions): void { if (resourceType === 'editor') { const resource = new Resource(options); this.resources.set(resourceName, resource); @@ -62,23 +63,3 @@ export class Workspace { openEditorWindow() {} } - -export interface ResourceOptions { - description: string; - defaultViewType?: string; - editorViews?: EditorViewOptions[]; - init: (ctx: any) => Promise; - dispose: (ctx: any) => Promise; - import: (ctx: any) => Promise; - save: (value: any) => Promise; -} - -export interface ViewFunctions { - init: () => Promise; - save: () => Promise; -} - -export type EditorViewOptions = { - viewName: string; - (ctx: any): ViewFunctions; -};