Skip to content

Commit 840e70e

Browse files
liujupingJackLian
authored andcommitted
docs: add workspace docs
1 parent fadce95 commit 840e70e

File tree

9 files changed

+123
-27
lines changed

9 files changed

+123
-27
lines changed

docs/docs/api/model/window.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: Window
3+
sidebar_position: 12
4+
---
5+
6+
> **@types** [IPublicModelWindow](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/window.ts)<br/>
7+
> **@since** v1.1.0
8+
9+
10+
## 基本介绍
11+
12+
低代码设计器窗口模型
13+
14+
## 方法签名
15+
16+
### importSchema(schema: IPublicTypeNodeSchema)
17+
当前窗口导入 schema
18+
19+
### changeViewType(viewName: string)
20+
修改当前窗口视图类型
21+
22+
### async save
23+
调用当前窗口视图保存钩子

docs/docs/api/workspace.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: workspace - 应用级 API
3+
sidebar_position: 12
4+
---
5+
6+
> **@types** [IPublicApiWorkspace](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/workspace.ts)<br/>
7+
> **@since** v1.1.0
8+
9+
10+
## 模块简介
11+
12+
通过该模块可以开发应用级低代码设计器。
13+
14+
## 变量
15+
16+
### isActive
17+
18+
是否启用 workspace 模式
19+
20+
### window
21+
22+
当前设计器窗口模型
23+
24+
关联模型 [IPublicModelWindow](./model/window)
25+
26+
## 方法签名
27+
28+
### registerResourceType
29+
注册资源
30+
31+
```typescript
32+
/** 注册资源 */
33+
registerResourceType(resourceName: string, resourceType: 'editor', options: IPublicResourceOptions): void;
34+
```

packages/shell/src/model/window.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class Window implements IPublicModelWindow {
1717
this[windowSymbol].changeViewType(viewName);
1818
}
1919

20-
save() {
21-
return this[windowSymbol].save();
20+
async save() {
21+
return await this[windowSymbol].save();
2222
}
2323
}
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
1-
export interface IPublicApiWorkspace {}
1+
import { IPublicModelWindow } from '../model';
2+
import { IPublicResourceOptions } from '../type';
3+
4+
export interface IPublicApiWorkspace {
5+
/** 是否启用 workspace 模式 */
6+
isActive: boolean;
7+
8+
/** 当前设计器窗口 */
9+
window: IPublicModelWindow;
10+
11+
/** 注册资源 */
12+
registerResourceType(resourceName: string, resourceType: 'editor', options: IPublicResourceOptions): void;
13+
}
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1-
export interface IPublicModelWindow {}
1+
import { IPublicTypeNodeSchema } from '../type';
2+
3+
export interface IPublicModelWindow {
4+
/** 当前窗口导入 schema */
5+
importSchema(schema: IPublicTypeNodeSchema): void;
6+
7+
/** 修改当前窗口视图类型 */
8+
changeViewType(viewName: string): void;
9+
10+
/** 调用当前窗口视图保存钩子 */
11+
save(): Promise<{
12+
[viewName: string]: IPublicTypeNodeSchema | any;
13+
}>;
14+
}

packages/types/src/shell/type/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,5 @@ export * from './setter-config';
7272
export * from './tip-config';
7373
export * from './widget-config-area';
7474
export * from './hotkey-callback';
75-
export * from './plugin-register-options';
75+
export * from './plugin-register-options';
76+
export * from './resource-options';
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export interface IPublicViewFunctions {
2+
/** 视图初始化 */
3+
init?: () => Promise<void>;
4+
/** 资源保存时调用视图的钩子 */
5+
save?: () => Promise<void>;
6+
}
7+
8+
export interface IPublicEditorView {
9+
/** 资源名字 */
10+
viewName: string;
11+
(ctx: any): IPublicViewFunctions;
12+
}
13+
14+
export interface IPublicResourceOptions {
15+
/** 资源名字 */
16+
name: string;
17+
18+
/** 资源描述 */
19+
description?: string;
20+
21+
/** 默认视图类型 */
22+
defaultViewType: string;
23+
24+
/** 资源视图 */
25+
editorViews: IPublicEditorView[];
26+
27+
/** save 钩子 */
28+
save?: () => Promise<void>;
29+
30+
/** import 钩子 */
31+
import?: () => Promise<void>;
32+
}

packages/workspace/src/editor-window/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class EditorWindow {
2626
const saveResult = await this.editorViews.get(name)?.save();
2727
value[name] = saveResult;
2828
}
29-
this.resource.save(value);
29+
return await this.resource.save(value);
3030
}
3131

3232
async init() {

packages/workspace/src/index.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Editor } from '@alilc/lowcode-editor-core';
22
import {
33
Skeleton as InnerSkeleton,
44
} from '@alilc/lowcode-editor-skeleton';
5+
import { IPublicResourceOptions } from '@alilc/lowcode-types';
56
import { EditorWindow } from './editor-window/context';
67
import { Resource } from './resource';
78

@@ -35,7 +36,7 @@ export class Workspace {
3536

3637
private resources: Map<string, Resource> = new Map();
3738

38-
registerResourceType(resourceName: string, resourceType: 'editor' | 'webview', options: ResourceOptions): void {
39+
registerResourceType(resourceName: string, resourceType: 'editor' | 'webview', options: IPublicResourceOptions): void {
3940
if (resourceType === 'editor') {
4041
const resource = new Resource(options);
4142
this.resources.set(resourceName, resource);
@@ -62,23 +63,3 @@ export class Workspace {
6263

6364
openEditorWindow() {}
6465
}
65-
66-
export interface ResourceOptions {
67-
description: string;
68-
defaultViewType?: string;
69-
editorViews?: EditorViewOptions[];
70-
init: (ctx: any) => Promise<void>;
71-
dispose: (ctx: any) => Promise<void>;
72-
import: (ctx: any) => Promise<any>;
73-
save: (value: any) => Promise<any>;
74-
}
75-
76-
export interface ViewFunctions {
77-
init: () => Promise<void>;
78-
save: () => Promise<void>;
79-
}
80-
81-
export type EditorViewOptions = {
82-
viewName: string;
83-
(ctx: any): ViewFunctions;
84-
};

0 commit comments

Comments
 (0)