Skip to content

Commit 36d1d3b

Browse files
liujupingJackLian
authored andcommitted
feat: support webview type resource in workspace mode
1 parent 8c82fe8 commit 36d1d3b

File tree

13 files changed

+105
-28
lines changed

13 files changed

+105
-28
lines changed

packages/shell/src/model/resource.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,12 @@ export class Resource implements IPublicModelResource {
3232
get category() {
3333
return this[resourceSymbol].category;
3434
}
35+
36+
get children() {
37+
return this[resourceSymbol].children.map((child) => new Resource(child));
38+
}
39+
40+
get viewType() {
41+
return this[resourceSymbol].viewType;
42+
}
3543
}

packages/types/src/shell/api/workspace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface IPublicApiWorkspace {
2121
setResourceList(resourceList: IPublicResourceList): void;
2222

2323
/** 资源树列表更新事件 */
24-
onResourceListChange(fn: (resourceList: IPublicResourceList) => void): () => IPublicTypeDisposable;
24+
onResourceListChange(fn: (resourceList: IPublicResourceList) => void): IPublicTypeDisposable;
2525

2626
/** 注册资源 */
2727
registerResourceType(resourceTypeModel: IPublicTypeResourceType): void;

packages/types/src/shell/type/editor-view-config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ export interface IPublicEditorViewConfig {
55

66
/** 资源保存时,会调用视图的钩子 */
77
save?: () => Promise<void>;
8+
9+
/** viewType 类型为 'webview' 时渲染的地址 */
10+
url?: () => Promise<string>;
811
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
import { ReactElement } from 'react';
2+
13
export interface IPublicResourceData {
24
resourceName: string;
35
title: string;
46
category?: string;
7+
viewType?: string;
8+
icon?: ReactElement;
59
options: {
610
[key: string]: any;
711
};
12+
children?: IPublicResourceData[];
813
}
914

1015
export type IPublicResourceList = IPublicResourceData[];

packages/types/src/shell/type/resource-type-config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ export interface IPublicResourceTypeConfig {
2828

2929
/** 默认标题 */
3030
defaultTitle?: string;
31+
32+
/** resourceType 类型为 'webview' 时渲染的地址 */
33+
url?: () => Promise<string>;
3134
}

packages/types/src/shell/type/resource-type.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { IPublicResourceTypeConfig } from './resource-type-config';
44
export interface IPublicTypeResourceType {
55
resourceName: string;
66

7-
resourceType: string;
7+
resourceType: 'editor' | 'webview';
88

9-
(ctx: IPublicModelPluginContext): IPublicResourceTypeConfig;
9+
(ctx: IPublicModelPluginContext, options: Object): IPublicResourceTypeConfig;
1010
}

packages/workspace/src/context/base-context.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,22 @@ import {
2828
Canvas,
2929
} from '@alilc/lowcode-shell';
3030
import {
31+
IPluginPreferenceMananger,
32+
IPublicApiEvent,
33+
IPublicModelPluginContext,
3134
IPublicTypePluginMeta,
3235
} from '@alilc/lowcode-types';
3336
import { getLogger } from '@alilc/lowcode-utils';
3437
import { Workspace as InnerWorkspace } from '../workspace';
3538
import { EditorWindow } from '../window';
3639

37-
export class BasicContext {
40+
export class BasicContext implements IPublicModelPluginContext {
3841
skeleton: Skeleton;
3942
plugins: Plugins;
4043
project: Project;
4144
setters: Setters;
4245
material: Material;
46+
common: Common;
4347
config;
4448
event;
4549
logger;
@@ -53,6 +57,8 @@ export class BasicContext {
5357
innerHotkey: InnerHotkey;
5458
innerPlugins: LowCodePluginManager;
5559
canvas: Canvas;
60+
pluginEvent: IPublicApiEvent;
61+
preference: IPluginPreferenceMananger;
5662

5763
constructor(innerWorkspace: InnerWorkspace, viewName: string, public editorWindow?: EditorWindow) {
5864
const editor = new Editor(viewName, true);
@@ -101,6 +107,7 @@ export class BasicContext {
101107
this.designer = designer;
102108
this.canvas = canvas;
103109
const common = new Common(editor, innerSkeleton);
110+
this.common = common;
104111
let plugins: any;
105112

106113
const pluginContextApiAssembler: ILowCodePluginContextApiAssembler = {

packages/workspace/src/context/view-context.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { makeObservable, obx } from '@alilc/lowcode-editor-core';
1+
import { computed, makeObservable, obx } from '@alilc/lowcode-editor-core';
22
import { IPublicEditorViewConfig, IPublicTypeEditorView } from '@alilc/lowcode-types';
33
import { flow } from 'mobx';
44
import { Workspace as InnerWorkspace } from '../workspace';
@@ -17,7 +17,7 @@ export class Context extends BasicContext {
1717

1818
@obx isInit: boolean = false;
1919

20-
get active() {
20+
@computed get active() {
2121
return this._activate;
2222
}
2323

@@ -33,7 +33,7 @@ export class Context extends BasicContext {
3333
this.isInit = true;
3434
});
3535

36-
constructor(public workspace: InnerWorkspace, public editorWindow: EditorWindow, public editorView: IPublicTypeEditorView, options: Object) {
36+
constructor(public workspace: InnerWorkspace, public editorWindow: EditorWindow, public editorView: IPublicTypeEditorView, options: Object | undefined) {
3737
super(workspace, editorView.viewName, editorWindow);
3838
this.viewType = editorView.viewType || 'editor';
3939
this.viewName = editorView.viewName;

packages/workspace/src/inner-plugins/webview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IPublicModelPluginContext } from '@alilc/lowcode-types';
22

3-
function DesignerView(props: {
3+
export function DesignerView(props: {
44
url: string;
55
viewName: string;
66
}) {

packages/workspace/src/resource.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ export class Resource implements IPublicModelResource {
1717
return this.resourceType.name;
1818
}
1919

20+
get viewType() {
21+
return this.resourceData.viewType;
22+
}
23+
2024
get description() {
2125
return this.resourceTypeInstance?.description;
2226
}
2327

2428
get icon() {
25-
return this.resourceTypeInstance?.icon;
29+
return this.resourceData.icon || this.resourceTypeInstance?.icon;
2630
}
2731

2832
get type() {
@@ -45,9 +49,13 @@ export class Resource implements IPublicModelResource {
4549
return this.context.innerSkeleton;
4650
}
4751

48-
constructor(readonly resourceData: IPublicResourceData, readonly resourceType: ResourceType, workspace: InnerWorkSpace) {
52+
get children(): Resource[] {
53+
return this.resourceData?.children?.map(d => new Resource(d, this.resourceType, this.workspace)) || [];
54+
}
55+
56+
constructor(readonly resourceData: IPublicResourceData, readonly resourceType: ResourceType, readonly workspace: InnerWorkSpace) {
4957
this.context = new BasicContext(workspace, `resource-${resourceData.resourceName || resourceType.name}`);
50-
this.resourceTypeInstance = resourceType.resourceTypeModel(this.context, {});
58+
this.resourceTypeInstance = resourceType.resourceTypeModel(this.context, this.options);
5159
this.init();
5260
if (this.resourceTypeInstance.editorViews) {
5361
this.resourceTypeInstance.editorViews.forEach((d: any) => {
@@ -68,6 +76,10 @@ export class Resource implements IPublicModelResource {
6876
return await this.resourceTypeInstance.import?.(schema);
6977
}
7078

79+
async url() {
80+
return await this.resourceTypeInstance.url?.();
81+
}
82+
7183
async save(value: any) {
7284
return await this.resourceTypeInstance.save?.(value);
7385
}

0 commit comments

Comments
 (0)