forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresource.ts
More file actions
121 lines (90 loc) · 3.28 KB
/
Copy pathresource.ts
File metadata and controls
121 lines (90 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { ISkeleton } from '@alilc/lowcode-editor-skeleton';
import { IPublicTypeEditorView, IPublicResourceData, IPublicResourceTypeConfig, IBaseModelResource } from '@alilc/lowcode-types';
import { Logger } from '@alilc/lowcode-utils';
import { BasicContext, IBasicContext } from './context/base-context';
import { ResourceType, IResourceType } from './resource-type';
import { IWorkspace } from './workspace';
const logger = new Logger({ level: 'warn', bizName: 'workspace:resource' });
export interface IBaseResource<T> extends IBaseModelResource<T> {
readonly resourceType: ResourceType;
skeleton: ISkeleton;
get editorViews(): IPublicTypeEditorView[];
get defaultViewType(): string;
getEditorView(name: string): IPublicTypeEditorView | undefined;
import(schema: any): Promise<any>;
save(value: any): Promise<any>;
url(): Promise<string | undefined>;
}
export type IResource = IBaseResource<IResource>;
export class Resource implements IResource {
private context: IBasicContext;
resourceTypeInstance: IPublicResourceTypeConfig;
editorViewMap: Map<string, IPublicTypeEditorView> = new Map<string, IPublicTypeEditorView>();
get name() {
return this.resourceType.name;
}
get viewName() {
return this.resourceData.viewName || (this.resourceData as any).viewType;
}
get description() {
return this.resourceTypeInstance?.description;
}
get icon() {
return this.resourceData.icon || this.resourceTypeInstance?.icon;
}
get type() {
return this.resourceType.type;
}
get title(): string | undefined {
return this.resourceData.title || this.resourceTypeInstance.defaultTitle;
}
get options() {
return this.resourceData.options;
}
get category() {
return this.resourceData?.category;
}
get skeleton() {
return this.context.innerSkeleton;
}
get children(): IResource[] {
return this.resourceData?.children?.map(d => new Resource(d, this.workspace.getResourceType(d.resourceName || this.resourceType.name), this.workspace)) || [];
}
constructor(readonly resourceData: IPublicResourceData, readonly resourceType: IResourceType, readonly workspace: IWorkspace) {
this.context = new BasicContext(workspace, `resource-${resourceData.resourceName || resourceType.name}`);
this.resourceTypeInstance = resourceType.resourceTypeModel(this.context.innerPlugins._getLowCodePluginContext({
pluginName: '',
}), this.options);
this.init();
if (this.resourceTypeInstance.editorViews) {
this.resourceTypeInstance.editorViews.forEach((d: any) => {
this.editorViewMap.set(d.viewName, d);
});
}
if (!resourceType) {
logger.error(`resourceType[${resourceType}] is unValid.`);
}
}
async init() {
await this.resourceTypeInstance.init?.();
await this.context.innerPlugins.init();
}
async import(schema: any) {
return await this.resourceTypeInstance.import?.(schema);
}
async url() {
return await this.resourceTypeInstance.url?.();
}
async save(value: any) {
return await this.resourceTypeInstance.save?.(value);
}
get editorViews() {
return this.resourceTypeInstance.editorViews;
}
get defaultViewType() {
return this.resourceTypeInstance.defaultViewType;
}
getEditorView(name: string) {
return this.editorViewMap.get(name);
}
}