forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaterial.ts
More file actions
137 lines (123 loc) · 3.33 KB
/
material.ts
File metadata and controls
137 lines (123 loc) · 3.33 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { Editor } from '@alilc/lowcode-editor-core';
import {
Designer,
registerMetadataTransducer,
MetadataTransducer,
getRegisteredMetadataTransducers,
addBuiltinComponentAction,
removeBuiltinComponentAction,
modifyBuiltinComponentAction,
} from '@alilc/lowcode-designer';
import { AssetsJson } from '@alilc/lowcode-utils';
import { ComponentAction } from '@alilc/lowcode-types';
import { editorSymbol, designerSymbol } from './symbols';
import ComponentMeta from './component-meta';
export default class Material {
private readonly [editorSymbol]: Editor;
private readonly [designerSymbol]: Designer;
constructor(editor: Editor) {
this[editorSymbol] = editor;
this[designerSymbol] = editor.get('designer')!;
}
/**
* 获取组件 map 结构
*/
get componentsMap() {
return this[designerSymbol].componentsMap;
}
/**
* 设置「资产包」结构
* @param assets
* @returns
*/
setAssets(assets: AssetsJson) {
return this[editorSymbol].setAssets(assets);
}
/**
* 获取「资产包」结构
* @returns
*/
getAssets() {
return this[editorSymbol].get('assets');
}
/**
* 加载增量的「资产包」结构,该增量包会与原有的合并
* @param incrementalAssets
* @returns
*/
loadIncrementalAssets(incrementalAssets: AssetsJson) {
return this[designerSymbol].loadIncrementalAssets(incrementalAssets);
}
/**
* 注册物料元数据管道函数
* @param transducer
* @param level
* @param id
*/
registerMetadataTransducer(
transducer: MetadataTransducer,
level?: number,
id?: string | undefined,
) {
registerMetadataTransducer(transducer, level, id);
}
/**
* 获取所有物料元数据管道函数
* @returns
*/
getRegisteredMetadataTransducers() {
return getRegisteredMetadataTransducers();
}
/**
* 获取指定名称的物料元数据
* @param componentName
* @returns
*/
getComponentMeta(componentName: string) {
return ComponentMeta.create(this[designerSymbol].getComponentMeta(componentName));
}
/**
* 获取所有已注册的物料元数据
* @returns
*/
getComponentMetasMap() {
const map = new Map<string, ComponentMeta>();
const originalMap = this[designerSymbol].getComponentMetasMap();
for (let componentName in originalMap.keys()) {
map.set(componentName, this.getComponentMeta(componentName)!);
}
return map;
}
/**
* 在设计器辅助层增加一个扩展 action
* @param action
*/
addBuiltinComponentAction(action: ComponentAction) {
addBuiltinComponentAction(action);
}
/**
* 移除设计器辅助层的指定 action
* @param name
*/
removeBuiltinComponentAction(name: string) {
removeBuiltinComponentAction(name);
}
/**
* 修改已有的设计器辅助层的指定 action
* @param actionName
* @param handle
*/
modifyBuiltinComponentAction(actionName: string, handle: (action: ComponentAction) => void) {
modifyBuiltinComponentAction(actionName, handle);
}
/**
* 监听 assets 变化的事件
* @param fn
*/
onChangeAssets(fn: () => void) {
// 设置 assets,经过 setAssets 赋值
this[editorSymbol].onGot('assets', fn);
// 增量设置 assets,经过 loadIncrementalAssets 赋值
this[editorSymbol].on('designer.incrementalAssetsReady', fn);
}
}