forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetters.ts
More file actions
63 lines (53 loc) · 1.69 KB
/
Copy pathsetters.ts
File metadata and controls
63 lines (53 loc) · 1.69 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
import { IPublicTypeCustomView, IPublicApiSetters, IPublicTypeRegisteredSetter } from '@alilc/lowcode-types';
import { Setters as InnerSetters, globalContext } from '@alilc/lowcode-editor-core';
import { ReactNode } from 'react';
const innerSettersSymbol = Symbol('setters');
const settersSymbol = Symbol('setters');
export class Setters implements IPublicApiSetters {
readonly [innerSettersSymbol]: InnerSetters;
get [settersSymbol](): InnerSetters {
if (this.workspaceMode) {
return this[innerSettersSymbol];
}
const workspace = globalContext.get('workspace');
if (workspace.isActive) {
return workspace.window.innerSetters;
}
return this[innerSettersSymbol];
}
constructor(innerSetters: InnerSetters, readonly workspaceMode = false) {
this[innerSettersSymbol] = innerSetters;
}
/**
* 获取指定 setter
* @param type
* @returns
*/
getSetter = (type: string) => {
return this[settersSymbol].getSetter(type);
};
/**
* 获取已注册的所有 settersMap
* @returns
*/
getSettersMap(): Map<string, IPublicTypeRegisteredSetter & {
type: string;
}> {
return this[settersSymbol].getSettersMap();
}
/**
* 注册一个 setter
* @param typeOrMaps
* @param setter
* @returns
*/
registerSetter = (
typeOrMaps: string | { [key: string]: IPublicTypeCustomView | IPublicTypeRegisteredSetter },
setter?: IPublicTypeCustomView | IPublicTypeRegisteredSetter | undefined,
) => {
return this[settersSymbol].registerSetter(typeOrMaps, setter);
};
createSetterContent = (setter: any, props: Record<string, any>): ReactNode => {
return this[settersSymbol].createSetterContent(setter, props);
};
}