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
75 lines (64 loc) · 2.04 KB
/
setters.ts
File metadata and controls
75 lines (64 loc) · 2.04 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
import { IPublicTypeCustomView, IPublicApiSetters, IPublicTypeRegisteredSetter } from '@alilc/lowcode-types';
import { ISetters, globalContext, untracked } from '@alilc/lowcode-editor-core';
import { ReactNode } from 'react';
import { getLogger } from '@alilc/lowcode-utils';
const innerSettersSymbol = Symbol('setters');
const settersSymbol = Symbol('setters');
const logger = getLogger({ level: 'warn', bizName: 'shell-setters' });
export class Setters implements IPublicApiSetters {
readonly [innerSettersSymbol]: ISetters;
get [settersSymbol](): ISetters {
if (this.workspaceMode) {
return this[innerSettersSymbol];
}
const workspace = globalContext.get('workspace');
if (workspace.isActive) {
return untracked(() => {
if (!workspace.window?.innerSetters) {
logger.error('setter api 调用时机出现问题,请检查');
return this[innerSettersSymbol];
}
return workspace.window.innerSetters;
});
}
return this[innerSettersSymbol];
}
constructor(innerSetters: ISetters, 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);
};
/**
* @deprecated
*/
createSetterContent = (setter: any, props: Record<string, any>): ReactNode => {
return this[settersSymbol].createSetterContent(setter, props);
};
}