Skip to content

Commit ea08173

Browse files
liujupingJackLian
authored andcommitted
feat: added apis support resource tree in workspace mode
1 parent a37a647 commit ea08173

File tree

25 files changed

+418
-100
lines changed

25 files changed

+418
-100
lines changed

docs/docs/api/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ sidebar_position: 0
4444
2. 事件(events)的命名格式为:on[Will|Did]VerbNoun?,参考 [https://code.visualstudio.com/api/references/vscode-api#events](https://code.visualstudio.com/api/references/vscode-api#events)
4545
3. 基于 Disposable 模式,对于事件的绑定、快捷键的绑定函数,返回值则是解绑函数
4646
4. 对于属性的导出,统一用 .xxx 的 getter 模式,(尽量)不使用 .getXxx()
47+
48+
## experimental
49+
50+
说明此模块处于公测阶段, API 可能会发生改变.

docs/docs/api/model/plugin-instance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: plugin-instance
2+
title: PluginInstance
33
sidebar_position: 12
44
---
55

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: ResourceType
3+
sidebar_position: 12
4+
---
5+
6+
> **[@experimental](./#experimental)**<br/>
7+
> **@types** [IPublicModelWindow](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/resource-type.ts)<br/>
8+
> **@since** v1.1.0
9+
10+
## 变量
11+
12+
### description
13+
14+
资源描述
15+
16+
`@type {string}`
17+
18+
### icon
19+
20+
资源 icon
21+
22+
`@type {ReactElement}`
23+
24+
### name
25+
26+
`@type {string}`

docs/docs/api/model/resource.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: Resource
3+
sidebar_position: 12
4+
---
5+
6+
> **[@experimental](./#experimental)**<br/>
7+
> **@types** [IPublicModelWindow](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/resource.ts)<br/>
8+
> **@since** v1.1.0
9+
10+
## 变量
11+
12+
### title
13+
14+
资源标题
15+
16+
`@type {string}`
17+
18+
### icon
19+
20+
资源 icon
21+
22+
`@type {ReactElement}`
23+
24+
### options
25+
26+
资源配置信息
27+
28+
`@type {Object}`
29+
30+
### resourceType
31+
32+
资源所属的资源类型
33+
34+
`@type {IPublicModelResourceType}`
35+
36+
关联模型 [IPublicModelResourceType](./resource-type)

docs/docs/api/model/window.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ title: Window
33
sidebar_position: 12
44
---
55

6+
> **[@experimental](./#experimental)**<br/>
67
> **@types** [IPublicModelWindow](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/window.ts)<br/>
78
> **@since** v1.1.0
89
@@ -17,13 +18,25 @@ sidebar_position: 12
1718

1819
窗口唯一 id
1920

21+
`@type {string}`
22+
2023
### title
2124

2225
窗口标题
2326

24-
### resourceName
27+
`@type {string}`
28+
29+
### icon
30+
31+
`@type {ReactElement}`
32+
33+
### resourceType
34+
35+
窗口资源类型
36+
37+
`@type {IPublicModelResourceType}`
2538

26-
窗口资源名字
39+
关联模型 [IPublicModelResourceType](./resource-type)
2740

2841
## 方法签名
2942

docs/docs/api/plugins.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ your-plugin/package.json
222222
}
223223
```
224224
转换后的结构:
225-
```json
225+
```typescript
226226
const debug = (ctx: IPublicModelPluginContext, options: any) => {
227227
return {};
228228
}

docs/docs/api/workspace.md

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ title: workspace - 应用级 API
33
sidebar_position: 12
44
---
55

6+
> **[@experimental](./#experimental)**<br/>
67
> **@types** [IPublicApiWorkspace](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/workspace.ts)<br/>
78
> **@since** v1.1.0
89
9-
1010
## 模块简介
1111

1212
通过该模块可以开发应用级低代码设计器。
@@ -47,14 +47,24 @@ get window(): IPublicModelWindow[]
4747

4848
关联模型 [IPublicModelWindow](./model/window)
4949

50+
### resourceList
51+
52+
当前设计器的资源列表数据
53+
54+
```
55+
get resourceList(): IPublicModelResource;
56+
```
57+
58+
关联模型 [IPublicModelResource](./model/resource)
59+
5060
## 方法签名
5161

5262
### registerResourceType
5363
注册资源
5464

5565
```typescript
5666
/** 注册资源 */
57-
registerResourceType(resourceName: string, resourceType: 'editor', options: IPublicResourceOptions): void;
67+
registerResourceType(name: string, type: 'editor', options: IPublicResourceOptions): void;
5868
```
5969

6070
相关类型:[IPublicResourceOptions](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/resource-options.ts)
@@ -74,3 +84,55 @@ active 窗口变更事件
7484
```typescript
7585
function onChangeActiveWindow(fn: () => void): void;
7686
```
87+
88+
### setResourceList
89+
90+
设置设计器资源列表数据
91+
92+
```typescript
93+
setResourceList(resourceList: IPublicResourceList) {}
94+
```
95+
96+
相关类型:[IPublicResourceOptions](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/resource-options.ts)
97+
98+
### onResourceListChange
99+
100+
设计器资源列表数据变更事件
101+
102+
```typescript
103+
onResourceListChange(fn: (resourceList: IPublicResourceList): void): (): void;
104+
```
105+
106+
相关类型:[IPublicResourceOptions](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/resource-options.ts)
107+
108+
### openEditorWindow
109+
110+
打开视图窗口
111+
112+
```typescript
113+
openEditorWindow(resourceName: string, title: string, options: Object, viewName?: string): void;
114+
```
115+
116+
### openEditorWindowById
117+
118+
通过视图 id 打开窗口
119+
120+
```typescript
121+
openEditorWindowById(id: string): void;
122+
```
123+
124+
### removeEditorWindow
125+
126+
移除视图窗口
127+
128+
```typescript
129+
removeEditorWindow(resourceName: string, title: string): void;
130+
```
131+
132+
### removeEditorWindowById
133+
134+
通过视图 id 移除窗口
135+
136+
```typescript
137+
removeEditorWindowById(id: string): void;
138+
```

packages/shell/src/api/workspace.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { IPublicApiWorkspace } from '@alilc/lowcode-types';
1+
import { IPublicApiWorkspace, IPublicResourceList, IPublicResourceOptions } from '@alilc/lowcode-types';
22
import { Workspace as InnerWorkSpace } from '@alilc/lowcode-workspace';
33
import { Plugins } from '@alilc/lowcode-shell';
44
import { Window } from '../model/window';
55
import { workspaceSymbol } from '../symbols';
6+
import { Resource } from '../model';
67

78
export class Workspace implements IPublicApiWorkspace {
89
readonly [workspaceSymbol]: InnerWorkSpace;
@@ -11,6 +12,18 @@ export class Workspace implements IPublicApiWorkspace {
1112
this[workspaceSymbol] = innerWorkspace;
1213
}
1314

15+
get resourceList() {
16+
return this[workspaceSymbol].getResourceList().map(d => new Resource(d));
17+
}
18+
19+
setResourceList(resourceList: IPublicResourceList) {
20+
this[workspaceSymbol].setResourceList(resourceList);
21+
}
22+
23+
onResourceListChange(fn: (resourceList: IPublicResourceList) => void): () => void {
24+
return this[workspaceSymbol].onResourceListChange(fn);
25+
}
26+
1427
get isActive() {
1528
return this[workspaceSymbol].isActive;
1629
}
@@ -19,12 +32,12 @@ export class Workspace implements IPublicApiWorkspace {
1932
return new Window(this[workspaceSymbol].window);
2033
}
2134

22-
registerResourceType(resourceName: string, resourceType: 'editor', options: any): void {
23-
this[workspaceSymbol].registerResourceType(resourceName, resourceType, options);
35+
registerResourceType(name: string, type: 'editor', options: IPublicResourceOptions): void {
36+
this[workspaceSymbol].registerResourceType(name, type, options);
2437
}
2538

26-
openEditorWindow(resourceName: string, title: string, viewType?: string) {
27-
this[workspaceSymbol].openEditorWindow(resourceName, title, viewType);
39+
openEditorWindow(resourceName: string, title: string, extra: Object, viewName?: string) {
40+
this[workspaceSymbol].openEditorWindow(resourceName, title, extra, viewName);
2841
}
2942

3043
openEditorWindowById(id: string) {

packages/shell/src/model/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ export * from './prop';
1313
export * from './props';
1414
export * from './selection';
1515
export * from './setting-prop-entry';
16-
export * from './setting-top-entry';
16+
export * from './setting-top-entry';
17+
export * from './resource';
18+
export * from './resource-type';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { IPublicModelResourceType } from '@alilc/lowcode-types';
2+
import { ResourceType as InnerResourceType } from '@alilc/lowcode-workspace';
3+
import { resourceTypeSymbol } from '../symbols';
4+
5+
export class ResourceType implements IPublicModelResourceType {
6+
readonly [resourceTypeSymbol]: InnerResourceType;
7+
constructor(resourceType: InnerResourceType) {
8+
this[resourceTypeSymbol] = resourceType;
9+
}
10+
11+
get name() {
12+
return this[resourceTypeSymbol].name;
13+
}
14+
15+
get description() {
16+
return this[resourceTypeSymbol].options.description;
17+
}
18+
19+
get icon() {
20+
return this[resourceTypeSymbol].options.icon;
21+
}
22+
}

0 commit comments

Comments
 (0)