@oinone/kunlun-meta 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/oinone-kunlun-meta.esm.js +496 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/src/element/ActionElement.d.ts +15 -0
- package/dist/types/src/element/ApiElement.d.ts +21 -0
- package/dist/types/src/element/ClearElement.d.ts +9 -0
- package/dist/types/src/element/ConfigElement.d.ts +6 -0
- package/dist/types/src/element/ContextElement.d.ts +9 -0
- package/dist/types/src/element/CustomElement.d.ts +7 -0
- package/dist/types/src/element/FieldElement.d.ts +25 -0
- package/dist/types/src/element/IBaseElement.d.ts +5 -0
- package/dist/types/src/element/PropElement.d.ts +6 -0
- package/dist/types/src/element/RequestElement.d.ts +9 -0
- package/dist/types/src/element/ResponseElement.d.ts +9 -0
- package/dist/types/src/element/SubscribeElement.d.ts +9 -0
- package/dist/types/src/element/ValidationElement.d.ts +12 -0
- package/dist/types/src/element/ViewElement.d.ts +15 -0
- package/dist/types/src/element/WidgetElement.d.ts +23 -0
- package/dist/types/src/element/index.d.ts +14 -0
- package/dist/types/src/global-config/index.d.ts +2 -0
- package/dist/types/src/global-config/runtime-config.d.ts +14 -0
- package/dist/types/src/global-config/type.d.ts +26 -0
- package/dist/types/src/index.d.ts +5 -0
- package/dist/types/src/metadata/constant/config.d.ts +1 -0
- package/dist/types/src/metadata/constant/index.d.ts +2 -0
- package/dist/types/src/metadata/constant/module-name.d.ts +20 -0
- package/dist/types/src/metadata/fragment/action.d.ts +6 -0
- package/dist/types/src/metadata/fragment/field.d.ts +2 -0
- package/dist/types/src/metadata/fragment/func.d.ts +2 -0
- package/dist/types/src/metadata/fragment/index.d.ts +13 -0
- package/dist/types/src/metadata/fragment/menu.d.ts +2 -0
- package/dist/types/src/metadata/fragment/model.d.ts +2 -0
- package/dist/types/src/metadata/fragment/page.d.ts +2 -0
- package/dist/types/src/metadata/index.d.ts +4 -0
- package/dist/types/src/metadata/runtime-fragment/action.d.ts +8 -0
- package/dist/types/src/metadata/runtime-fragment/function.d.ts +3 -0
- package/dist/types/src/metadata/runtime-fragment/index.d.ts +20 -0
- package/dist/types/src/metadata/runtime-fragment/model.d.ts +2 -0
- package/dist/types/src/metadata/runtime-fragment/module.d.ts +2 -0
- package/dist/types/src/metadata/runtime-fragment/view.d.ts +6 -0
- package/dist/types/src/metadata/types/dsl-node.d.ts +12 -0
- package/dist/types/src/metadata/types/enumeration.d.ts +18 -0
- package/dist/types/src/metadata/types/index.d.ts +8 -0
- package/dist/types/src/metadata/types/layout.d.ts +4 -0
- package/dist/types/src/metadata/types/model.d.ts +573 -0
- package/dist/types/src/metadata/types/tag.d.ts +23 -0
- package/dist/types/src/metadata/types/user.d.ts +22 -0
- package/dist/types/src/metadata/types/value.d.ts +3 -0
- package/dist/types/src/metadata/types/view.d.ts +170 -0
- package/dist/types/src/plugin-loader/factory/PluginLoaderFactory.d.ts +4 -0
- package/dist/types/src/plugin-loader/factory/index.d.ts +1 -0
- package/dist/types/src/plugin-loader/index.d.ts +5 -0
- package/dist/types/src/plugin-loader/loader/CJSPluginLoader.d.ts +7 -0
- package/dist/types/src/plugin-loader/loader/CSSPluginLoader.d.ts +7 -0
- package/dist/types/src/plugin-loader/loader/ESMPluginLoader.d.ts +7 -0
- package/dist/types/src/plugin-loader/loader/IIFEPluginLoader.d.ts +7 -0
- package/dist/types/src/plugin-loader/loader/LoadedEvent.d.ts +4 -0
- package/dist/types/src/plugin-loader/loader/PluginLoader.d.ts +5 -0
- package/dist/types/src/plugin-loader/loader/RemotePluginLoader.d.ts +5 -0
- package/dist/types/src/plugin-loader/loader/UMDPluginLoader.d.ts +6 -0
- package/dist/types/src/plugin-loader/loader/index.d.ts +1 -0
- package/dist/types/src/plugin-loader/typing/index.d.ts +2 -0
- package/dist/types/src/plugin-loader/typing/load-option.d.ts +48 -0
- package/dist/types/src/plugin-loader/typing/loader-config.d.ts +38 -0
- package/dist/types/src/plugin-loader/util/PluginLoadHelper.d.ts +7 -0
- package/dist/types/src/plugin-loader/util/index.d.ts +1 -0
- package/dist/types/src/util/element.d.ts +16 -0
- package/dist/types/src/util/field.d.ts +7 -0
- package/dist/types/src/util/helper.d.ts +2 -0
- package/dist/types/src/util/index.d.ts +6 -0
- package/dist/types/src/util/ke-common.d.ts +6 -0
- package/dist/types/src/util/lang.d.ts +4 -0
- package/dist/types/src/util/validation-utils.d.ts +3 -0
- package/index.ts +1 -0
- package/package.json +17 -0
- package/rollup.config.js +4 -0
- package/src/element/ActionElement.ts +20 -0
- package/src/element/ApiElement.ts +22 -0
- package/src/element/ClearElement.ts +10 -0
- package/src/element/ConfigElement.ts +7 -0
- package/src/element/ContextElement.ts +10 -0
- package/src/element/CustomElement.ts +22 -0
- package/src/element/FieldElement.ts +41 -0
- package/src/element/IBaseElement.ts +5 -0
- package/src/element/PropElement.ts +7 -0
- package/src/element/RequestElement.ts +10 -0
- package/src/element/ResponseElement.ts +10 -0
- package/src/element/SubscribeElement.ts +10 -0
- package/src/element/ValidationElement.ts +17 -0
- package/src/element/ViewElement.ts +23 -0
- package/src/element/WidgetElement.ts +33 -0
- package/src/element/index.ts +14 -0
- package/src/global-config/index.ts +2 -0
- package/src/global-config/runtime-config.ts +83 -0
- package/src/global-config/type.ts +48 -0
- package/src/index.ts +5 -0
- package/src/metadata/constant/config.ts +1 -0
- package/src/metadata/constant/index.ts +2 -0
- package/src/metadata/constant/module-name.ts +21 -0
- package/src/metadata/fragment/action.ts +119 -0
- package/src/metadata/fragment/field.ts +42 -0
- package/src/metadata/fragment/func.ts +21 -0
- package/src/metadata/fragment/index.ts +20 -0
- package/src/metadata/fragment/menu.ts +35 -0
- package/src/metadata/fragment/model.ts +76 -0
- package/src/metadata/fragment/page.ts +17 -0
- package/src/metadata/index.ts +4 -0
- package/src/metadata/runtime-fragment/action.ts +159 -0
- package/src/metadata/runtime-fragment/function.ts +25 -0
- package/src/metadata/runtime-fragment/index.ts +36 -0
- package/src/metadata/runtime-fragment/model.ts +18 -0
- package/src/metadata/runtime-fragment/module.ts +11 -0
- package/src/metadata/runtime-fragment/view.ts +44 -0
- package/src/metadata/types/dsl-node.ts +14 -0
- package/src/metadata/types/enumeration.ts +19 -0
- package/src/metadata/types/index.ts +8 -0
- package/src/metadata/types/layout.ts +4 -0
- package/src/metadata/types/model.ts +823 -0
- package/src/metadata/types/tag.ts +24 -0
- package/src/metadata/types/user.ts +27 -0
- package/src/metadata/types/value.ts +3 -0
- package/src/metadata/types/view.ts +194 -0
- package/src/plugin-loader/factory/PluginLoaderFactory.ts +23 -0
- package/src/plugin-loader/factory/index.ts +1 -0
- package/src/plugin-loader/index.ts +33 -0
- package/src/plugin-loader/loader/CJSPluginLoader.ts +18 -0
- package/src/plugin-loader/loader/CSSPluginLoader.ts +29 -0
- package/src/plugin-loader/loader/ESMPluginLoader.ts +53 -0
- package/src/plugin-loader/loader/IIFEPluginLoader.ts +18 -0
- package/src/plugin-loader/loader/LoadedEvent.ts +24 -0
- package/src/plugin-loader/loader/PluginLoader.ts +12 -0
- package/src/plugin-loader/loader/RemotePluginLoader.ts +54 -0
- package/src/plugin-loader/loader/UMDPluginLoader.ts +50 -0
- package/src/plugin-loader/loader/index.ts +1 -0
- package/src/plugin-loader/typing/index.ts +2 -0
- package/src/plugin-loader/typing/load-option.ts +51 -0
- package/src/plugin-loader/typing/loader-config.ts +38 -0
- package/src/plugin-loader/util/PluginLoadHelper.ts +70 -0
- package/src/plugin-loader/util/index.ts +1 -0
- package/src/util/element.ts +154 -0
- package/src/util/field.ts +63 -0
- package/src/util/helper.ts +6 -0
- package/src/util/index.ts +6 -0
- package/src/util/ke-common.ts +25 -0
- package/src/util/lang.ts +8 -0
- package/src/util/validation-utils.ts +17 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
enum ElementType {
|
|
2
|
+
MASK = 'MASK',
|
|
3
|
+
BLOCK = 'BLOCK',
|
|
4
|
+
HEADER = 'HEADER',
|
|
5
|
+
CONTAINER = 'CONTAINER',
|
|
6
|
+
SIDEBAR = 'SIDEBAR',
|
|
7
|
+
CONTENT = 'CONTENT',
|
|
8
|
+
VIEW = 'VIEW',
|
|
9
|
+
FIELD = 'FIELD',
|
|
10
|
+
GROUP = 'GROUP',
|
|
11
|
+
GRID = 'GRID',
|
|
12
|
+
ACTION = 'ACTION',
|
|
13
|
+
API = 'API',
|
|
14
|
+
CONTEXT = 'CONTEXT',
|
|
15
|
+
REQUEST = 'REQUEST',
|
|
16
|
+
RESPONSE = 'RESPONSE',
|
|
17
|
+
CLEAR = 'CLEAR',
|
|
18
|
+
FILTER = 'FILTER',
|
|
19
|
+
WIDGET = 'WIDGET',
|
|
20
|
+
PROP = 'PROP',
|
|
21
|
+
VALIDATION = 'VALIDATION'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { ElementType };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export enum UserBehaviorEventEnum {
|
|
2
|
+
SIGN_UP_PHONE = 'SIGN_UP_PHONE', // 手机号注册
|
|
3
|
+
SIGN_UP_EMAIL = 'SIGN_UP_EMAIL', // 邮箱注册
|
|
4
|
+
|
|
5
|
+
PHONE_MODIFY_PASSWORD_BY_PHONE_SUBMIT = 'MODIFY_PASSWORD_BY_PHONE', // "手机验证修改密码"
|
|
6
|
+
PHONE_MODIFY_PASSWORD_BY_PHONE_SEND_CODE = 'MODIFY_PASSWORD_BYPHONE_SEND_CODE', // "发送修改手机密码验证码"
|
|
7
|
+
EMAIL_MODIFY_PASSWORD_BY_EMAIL_SUBMIT = 'MODIFY_PASSWORD_BY_EMAIL', // "邮箱验证修改密码"
|
|
8
|
+
EMAIL_MODIFY_PASSWORD_BY_EMAIL_SEND_CODE = 'MODIFY_PASSWORD_SEND_RESET_EMAIL', // "发送重置密码邮件"
|
|
9
|
+
|
|
10
|
+
PHONE_MODIFY_PHONE_SUBMIT = 'MODIFY_PHONE', // "修改手机号"
|
|
11
|
+
PHONE_MODIFY_PHONE_OLD_PHONE_CODE = 'MODIFY_PHONE_OLD_PHONE_CODE', // "发送修改手机号-原手机验证码"
|
|
12
|
+
EMAIL_MODIFY_PHONE_SEND_EMAIL_CODE = 'MODIFY_PHONE_SEND_EMAIL', // "发送修改手机号-邮箱验证码"
|
|
13
|
+
PHONE_MODIFY_PHONE_NEW_PHONE_CODE = 'MODIFY_PHONE_NEW_PHONE_CODE', // "发送修改手机号-新手机验证码"
|
|
14
|
+
|
|
15
|
+
EMAIL_MODIFY_EMAIL_SUBMIT = 'MODIFY_EMAIL', // "修改邮箱", "修改邮箱"),
|
|
16
|
+
EMAIL_MODIFY_EMAIL_SEND_OLD_EMAIL = 'MODIFY_EMAIL_SEND_OLD_EMAIL', // "修改邮箱-发送原邮箱确认邮件"
|
|
17
|
+
PHONE_MODIFY_EMAIL_SEND_PHONE_CODE = 'MODIFY_EMAIL_SEND_PHONE_CODE', // "修改邮箱-手机验证码"
|
|
18
|
+
EMAIL_MODIFY_EMAIL_SEND_NEW_EMAIL = 'MODIFY_EMAIL_SEND_NEW_EMAIL', // "修改邮箱-发送新邮箱确认邮件"
|
|
19
|
+
|
|
20
|
+
PHONE_ADD_CORP_SEND_PHONE_CODE = 'ADD_CORP_SEND_PHONE_CODE', // "加入团队手机验证码"
|
|
21
|
+
EMAIL_ADD_CORP_SEND_EMAIL_CODE = 'ADD_CORP_SEND_EMAIL_CODE', // "加入团队邮件验证码"
|
|
22
|
+
|
|
23
|
+
PHONE_LOGIN_BY_PHONE_CODE = 'LOGIN_BY_PHONE_CODE', // 手机验证码登录
|
|
24
|
+
PHONE_SEND_LOGIN_BY_PHONE_CODE = 'SEND_LOGIN_BY_PHONE_CODE', // 发送手机验证码
|
|
25
|
+
EMAIL_LOGIN_BY_EMAIL_CODE = 'LOGIN_BY_EMAIL_CODE', // 邮箱验证码登录
|
|
26
|
+
EMAIL_SEND_LOGIN_BY_EMAIL_CODE = 'SEND_LOGIN_BY_EMAIL_CODE' // 发送邮箱验证码
|
|
27
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { BIGINT, EntityId } from './value';
|
|
2
|
+
|
|
3
|
+
export type ViewId = EntityId;
|
|
4
|
+
|
|
5
|
+
// 视图分类,按照数据源形态区分
|
|
6
|
+
export enum DataClass {
|
|
7
|
+
List = 'LIST', // 数据源为 ListValue
|
|
8
|
+
Object = 'OBJECT' // 数据源为 ObjectValue
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 视图客户端类型
|
|
13
|
+
*/
|
|
14
|
+
export enum ViewClientType {
|
|
15
|
+
/**
|
|
16
|
+
* PC端
|
|
17
|
+
*/
|
|
18
|
+
PC = 'PC',
|
|
19
|
+
/**
|
|
20
|
+
* 移动端
|
|
21
|
+
*/
|
|
22
|
+
MOBILE = 'MOBILE'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* <h3>视图类型</h3>
|
|
27
|
+
* <p>
|
|
28
|
+
* 视图类型是描述数据类型、数据传递、数据交互的基本属性
|
|
29
|
+
* </p>
|
|
30
|
+
*/
|
|
31
|
+
export enum ViewType {
|
|
32
|
+
/**
|
|
33
|
+
* 表格
|
|
34
|
+
*/
|
|
35
|
+
Table = 'TABLE',
|
|
36
|
+
/**
|
|
37
|
+
* 表单
|
|
38
|
+
*/
|
|
39
|
+
Form = 'FORM',
|
|
40
|
+
/**
|
|
41
|
+
* 详情
|
|
42
|
+
*/
|
|
43
|
+
Detail = 'DETAIL',
|
|
44
|
+
/**
|
|
45
|
+
* 搜索
|
|
46
|
+
*/
|
|
47
|
+
Search = 'SEARCH',
|
|
48
|
+
/**
|
|
49
|
+
* 画廊
|
|
50
|
+
*/
|
|
51
|
+
Gallery = 'GALLERY',
|
|
52
|
+
/**
|
|
53
|
+
* 树
|
|
54
|
+
*/
|
|
55
|
+
Tree = 'TREE',
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 多视图
|
|
59
|
+
*/
|
|
60
|
+
Multiple = 'MULTIPLE',
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 自定义
|
|
64
|
+
*/
|
|
65
|
+
Custom = 'CUSTOM'
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* <h3>视图模式</h3>
|
|
70
|
+
* <p>
|
|
71
|
+
* 视图模式是视图类型更具备操作性的定义,相同的视图类型会有不同模式进行描述。
|
|
72
|
+
* <p>例如:</p>
|
|
73
|
+
* <ul>
|
|
74
|
+
* <li>【表单】视图类型可能会存在【创建】和【编辑】两种不同的模式</li>
|
|
75
|
+
* <li>【表单】视图类型可能会在某些情况下手动修改为【只读】状态</li>
|
|
76
|
+
* </ul>
|
|
77
|
+
* </p>
|
|
78
|
+
*/
|
|
79
|
+
export enum ViewMode {
|
|
80
|
+
/**
|
|
81
|
+
* 创建
|
|
82
|
+
*/
|
|
83
|
+
Create = 'CREATE',
|
|
84
|
+
/**
|
|
85
|
+
* 编辑
|
|
86
|
+
*/
|
|
87
|
+
Editor = 'EDITOR',
|
|
88
|
+
/**
|
|
89
|
+
* 查看
|
|
90
|
+
*/
|
|
91
|
+
Lookup = 'LOOKUP'
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 跳转动作路由类型
|
|
96
|
+
*/
|
|
97
|
+
export enum ViewActionTarget {
|
|
98
|
+
/**
|
|
99
|
+
* 页面路由
|
|
100
|
+
*/
|
|
101
|
+
Router = 'ROUTER',
|
|
102
|
+
/**
|
|
103
|
+
* 页面弹窗
|
|
104
|
+
*/
|
|
105
|
+
Dialog = 'DIALOG',
|
|
106
|
+
/**
|
|
107
|
+
* 页面抽屉
|
|
108
|
+
*/
|
|
109
|
+
Drawer = 'DRAWER',
|
|
110
|
+
/**
|
|
111
|
+
* 页内路由
|
|
112
|
+
*/
|
|
113
|
+
Inner = 'INNER',
|
|
114
|
+
/**
|
|
115
|
+
* 打开新窗口
|
|
116
|
+
*/
|
|
117
|
+
OpenWindow = 'OPEN_WINDOW',
|
|
118
|
+
/**
|
|
119
|
+
* 页面嵌入
|
|
120
|
+
*/
|
|
121
|
+
Frame = 'iframe'
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export enum SystemSource {
|
|
125
|
+
SYSTEM = 'SYSTEM', // 内核
|
|
126
|
+
BASE = 'BASE', // 系统原生
|
|
127
|
+
MANUAL = 'MANUAL', // 手工新增
|
|
128
|
+
UI = 'UI', // 界面新增
|
|
129
|
+
RELATION = 'RELATION', // 关联关系生成
|
|
130
|
+
ABSTRACT_INHERITED = 'ABSTRACT_INHERITED', // 抽象继承
|
|
131
|
+
TRANSIENT_INHERITED = 'TRANSIENT_INHERITED', // 临时继承
|
|
132
|
+
EXTEND_INHERITED = 'EXTEND_INHERITED', // 同表继承
|
|
133
|
+
MULTI_TABLE_INHERITED = 'MULTI_TABLE_INHERITED', // 多表继承
|
|
134
|
+
PROXY_INHERITED = 'PROXY_INHERITED' // 代理继承
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface IView {
|
|
138
|
+
id: ViewId;
|
|
139
|
+
name: string;
|
|
140
|
+
type: ViewType;
|
|
141
|
+
model: string;
|
|
142
|
+
priority: BIGINT; // 优先级
|
|
143
|
+
template: string; // 自定义的模板
|
|
144
|
+
active?: any; // 激活状态,暂时不使用
|
|
145
|
+
title?: string;
|
|
146
|
+
systemSource?: SystemSource; // 系统来源
|
|
147
|
+
// 仅前端用,浏览器的title那里需要
|
|
148
|
+
moduleDisplayName?: SystemSource;
|
|
149
|
+
|
|
150
|
+
extension?: Record<string, string>;
|
|
151
|
+
|
|
152
|
+
modelDefinition?: {
|
|
153
|
+
model?: string;
|
|
154
|
+
name?: string;
|
|
155
|
+
moduleName?: string;
|
|
156
|
+
module?: string;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
baseLayoutName?: string;
|
|
160
|
+
baseLayoutDefinition?: {
|
|
161
|
+
name: string;
|
|
162
|
+
template: string;
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* 组件的标签内的 <config /> 配置
|
|
168
|
+
*/
|
|
169
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
170
|
+
export interface IBaseWidgetConfig {}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 视图组件基础配置
|
|
174
|
+
*/
|
|
175
|
+
export interface IViewWidgetConfig extends IBaseWidgetConfig {
|
|
176
|
+
// 数据的提交方式:all 全量一次性提交 非all的为先提交关联数据再提交主数据
|
|
177
|
+
submit?: string;
|
|
178
|
+
// 排除的动作,英文逗号分隔多个值
|
|
179
|
+
excludedActions?: string;
|
|
180
|
+
// 校验提示
|
|
181
|
+
validateTip?: boolean;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* select组件配置
|
|
186
|
+
*/
|
|
187
|
+
export interface IBaseSelectWidgetConfig extends IBaseWidgetConfig {
|
|
188
|
+
// 搜索的时候匹配的字段,多个值用逗号分隔
|
|
189
|
+
searchField?: string;
|
|
190
|
+
// 展示选用的字段,多个值用逗号分隔
|
|
191
|
+
labelField?: string;
|
|
192
|
+
// 默认值 '-',labelField多值间的分隔符,后端目前配置的是 name-separator,需要替换掉
|
|
193
|
+
separator?: string;
|
|
194
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CJSPluginLoader } from '../loader/CJSPluginLoader';
|
|
2
|
+
import { CSSPluginLoader } from '../loader/CSSPluginLoader';
|
|
3
|
+
import { ESMPluginLoader } from '../loader/ESMPluginLoader';
|
|
4
|
+
import { IIFEPluginLoader } from '../loader/IIFEPluginLoader';
|
|
5
|
+
import { UMDPluginLoader } from '../loader/UMDPluginLoader';
|
|
6
|
+
import { PluginLoader, PluginLoadType } from '../typing';
|
|
7
|
+
|
|
8
|
+
export class PluginLoaderFactory {
|
|
9
|
+
public static get(type: PluginLoadType): PluginLoader | undefined {
|
|
10
|
+
switch (type) {
|
|
11
|
+
case 'esm':
|
|
12
|
+
return ESMPluginLoader.INSTANCE;
|
|
13
|
+
case 'cjs':
|
|
14
|
+
return CJSPluginLoader.INSTANCE;
|
|
15
|
+
case 'umd':
|
|
16
|
+
return UMDPluginLoader.INSTANCE;
|
|
17
|
+
case 'iife':
|
|
18
|
+
return IIFEPluginLoader.INSTANCE;
|
|
19
|
+
case 'css':
|
|
20
|
+
return CSSPluginLoader.INSTANCE;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './PluginLoaderFactory';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { RemotePluginLoader } from './loader/RemotePluginLoader';
|
|
2
|
+
import { PluginLoadDependencies, PluginsLoaderConfig } from './typing';
|
|
3
|
+
import { PluginLoadHelper } from './util';
|
|
4
|
+
|
|
5
|
+
export class PluginsLoader {
|
|
6
|
+
public static async load(config: PluginsLoaderConfig, localDependencies?: PluginLoadDependencies): Promise<void> {
|
|
7
|
+
const { dependencies: dynamicDependencies, mounted, usingRemote } = config;
|
|
8
|
+
if (localDependencies) {
|
|
9
|
+
await PluginLoadHelper.loadDependencies(localDependencies);
|
|
10
|
+
}
|
|
11
|
+
if (dynamicDependencies) {
|
|
12
|
+
await PluginLoadHelper.loadDependencies(dynamicDependencies);
|
|
13
|
+
}
|
|
14
|
+
if (mounted) {
|
|
15
|
+
if (Array.isArray(mounted)) {
|
|
16
|
+
await PluginLoadHelper.loadJavascript(mounted);
|
|
17
|
+
} else {
|
|
18
|
+
const { js, css } = mounted;
|
|
19
|
+
if (js) {
|
|
20
|
+
await PluginLoadHelper.loadJavascript(js);
|
|
21
|
+
}
|
|
22
|
+
if (css) {
|
|
23
|
+
await PluginLoadHelper.loadCSS(css);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (usingRemote) {
|
|
28
|
+
await RemotePluginLoader.INSTANCE.load();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export * from './typing';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PluginLoader, PluginLoadOption } from '../typing';
|
|
2
|
+
import { ESMPluginLoader } from './ESMPluginLoader';
|
|
3
|
+
|
|
4
|
+
export class CJSPluginLoader implements PluginLoader {
|
|
5
|
+
public static readonly INSTANCE = new CJSPluginLoader();
|
|
6
|
+
|
|
7
|
+
private constructor() {
|
|
8
|
+
// reject create object
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public load(option: PluginLoadOption) {
|
|
12
|
+
return ESMPluginLoader.INSTANCE.load(option);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public loadDependencies(dependencies: Record<string, unknown>) {
|
|
16
|
+
return ESMPluginLoader.INSTANCE.loadDependencies(dependencies);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PluginLoader, PluginLoadOption } from '../typing';
|
|
2
|
+
import { bindLinkLoadedEvent } from './LoadedEvent';
|
|
3
|
+
|
|
4
|
+
export class CSSPluginLoader implements PluginLoader {
|
|
5
|
+
public static readonly INSTANCE = new CSSPluginLoader();
|
|
6
|
+
|
|
7
|
+
private constructor() {
|
|
8
|
+
// reject create object
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public async load(option: PluginLoadOption): Promise<void> {
|
|
12
|
+
const { id, path } = option;
|
|
13
|
+
const element = document.getElementById(id);
|
|
14
|
+
if (element) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
return new Promise<void>((resolve) => {
|
|
18
|
+
const link = document.createElement('link');
|
|
19
|
+
link.id = id;
|
|
20
|
+
link.href = path;
|
|
21
|
+
link.rel = 'stylesheet';
|
|
22
|
+
link.type = 'text/css';
|
|
23
|
+
bindLinkLoadedEvent(link, resolve);
|
|
24
|
+
document.body.append(link);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public async loadDependencies(): Promise<void> {}
|
|
29
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { PluginLoader, PluginLoadOption } from '../typing';
|
|
2
|
+
import { bindScriptLoadedEvent } from './LoadedEvent';
|
|
3
|
+
|
|
4
|
+
let counter = 0;
|
|
5
|
+
|
|
6
|
+
export class ESMPluginLoader implements PluginLoader {
|
|
7
|
+
public static readonly INSTANCE = new ESMPluginLoader();
|
|
8
|
+
|
|
9
|
+
private constructor() {
|
|
10
|
+
// reject create object
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public async load(option: PluginLoadOption): Promise<void> {
|
|
14
|
+
const { id, path, dependencies } = option;
|
|
15
|
+
const element = document.getElementById(id);
|
|
16
|
+
if (element) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (dependencies) {
|
|
20
|
+
await this.loadDependencies(dependencies);
|
|
21
|
+
}
|
|
22
|
+
return new Promise<void>((resolve) => {
|
|
23
|
+
const script = document.createElement('script');
|
|
24
|
+
script.id = id;
|
|
25
|
+
script.src = path;
|
|
26
|
+
script.type = 'module';
|
|
27
|
+
bindScriptLoadedEvent(script, resolve);
|
|
28
|
+
document.body.append(script);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public async loadDependencies(dependencies: Record<string, unknown>): Promise<void> {
|
|
33
|
+
const importMap: Record<string, string> = {};
|
|
34
|
+
Object.entries(dependencies).forEach(([key, value]) => {
|
|
35
|
+
if (typeof value === 'string') {
|
|
36
|
+
importMap[key] = value;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
if (!Object.keys(importMap).length) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
return new Promise((resolve) => {
|
|
43
|
+
const importMapScript = document.createElement('script');
|
|
44
|
+
importMapScript.id = `import-map-${counter++}`;
|
|
45
|
+
importMapScript.type = 'importmap';
|
|
46
|
+
importMapScript.text = JSON.stringify({
|
|
47
|
+
imports: importMap
|
|
48
|
+
});
|
|
49
|
+
bindScriptLoadedEvent(importMapScript, resolve);
|
|
50
|
+
document.body.append(importMapScript);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PluginLoader, PluginLoadOption } from '../typing';
|
|
2
|
+
import { UMDPluginLoader } from './UMDPluginLoader';
|
|
3
|
+
|
|
4
|
+
export class IIFEPluginLoader implements PluginLoader {
|
|
5
|
+
public static readonly INSTANCE = new IIFEPluginLoader();
|
|
6
|
+
|
|
7
|
+
private constructor() {
|
|
8
|
+
// reject create object
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public load(option: PluginLoadOption) {
|
|
12
|
+
return UMDPluginLoader.INSTANCE.load(option);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public loadDependencies(dependencies: Record<string, unknown>) {
|
|
16
|
+
return UMDPluginLoader.INSTANCE.loadDependencies(dependencies);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
type ResolveFunction = () => void;
|
|
2
|
+
|
|
3
|
+
export function bindScriptLoadedEvent(script: HTMLScriptElement, resolve: ResolveFunction): void {
|
|
4
|
+
script.onload = onLoaded(script.src, resolve);
|
|
5
|
+
script.onerror = onErrorLoaded(script.src, resolve);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function bindLinkLoadedEvent(link: HTMLLinkElement, resolve: ResolveFunction): void {
|
|
9
|
+
link.onload = onLoaded(link.href, resolve);
|
|
10
|
+
link.onerror = onErrorLoaded(link.href, resolve);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function onLoaded(src: string, resolve: ResolveFunction) {
|
|
14
|
+
return () => {
|
|
15
|
+
resolve();
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function onErrorLoaded(src: string, resolve: ResolveFunction) {
|
|
20
|
+
return () => {
|
|
21
|
+
resolve();
|
|
22
|
+
console.error(`load error. ${src}`);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PluginLoaderFactory } from '../factory';
|
|
2
|
+
import { PluginLoadOption, PluginLoadType } from '../typing';
|
|
3
|
+
|
|
4
|
+
export class PluginLoader {
|
|
5
|
+
public static async load(options: PluginLoadOption[]): Promise<void> {
|
|
6
|
+
await Promise.allSettled(options.map((option) => PluginLoaderFactory.get(option.type)?.load(option)));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
public static async loadDependencies(type: PluginLoadType, dependencies: Record<string, unknown>): Promise<void> {
|
|
10
|
+
await PluginLoaderFactory.get(type)?.loadDependencies(dependencies);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { gql, HttpClient } from '@oinone/kunlun-request';
|
|
2
|
+
import { SYSTEM_MODULE_NAME } from '../../metadata';
|
|
3
|
+
import { RemoteLoadOption } from '../typing';
|
|
4
|
+
import { PluginLoadHelper } from '../util';
|
|
5
|
+
|
|
6
|
+
const http = HttpClient.getInstance();
|
|
7
|
+
|
|
8
|
+
export class RemotePluginLoader {
|
|
9
|
+
public static readonly INSTANCE = new RemotePluginLoader();
|
|
10
|
+
|
|
11
|
+
private cache: RemoteLoadOption | null | undefined;
|
|
12
|
+
|
|
13
|
+
public async load(): Promise<void> {
|
|
14
|
+
let option = this.cache;
|
|
15
|
+
if (option === undefined) {
|
|
16
|
+
option = await fetchRemoteLoadOptions();
|
|
17
|
+
if (!option) {
|
|
18
|
+
option = null;
|
|
19
|
+
}
|
|
20
|
+
this.cache = option;
|
|
21
|
+
}
|
|
22
|
+
if (option) {
|
|
23
|
+
const { javascript: js, css } = option;
|
|
24
|
+
const promises: Promise<void>[] = [];
|
|
25
|
+
if (js) {
|
|
26
|
+
promises.push(PluginLoadHelper.loadJavascript(js));
|
|
27
|
+
}
|
|
28
|
+
if (css) {
|
|
29
|
+
promises.push(PluginLoadHelper.loadCSS(css));
|
|
30
|
+
}
|
|
31
|
+
await Promise.allSettled(promises);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function fetchRemoteLoadOptions(): Promise<RemoteLoadOption | undefined> {
|
|
37
|
+
const queryGql = gql`
|
|
38
|
+
{
|
|
39
|
+
widgetDefinitionQuery {
|
|
40
|
+
loadSDK(data: {}) {
|
|
41
|
+
javascript
|
|
42
|
+
css
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
try {
|
|
48
|
+
const result = await http.query<RemoteLoadOption>(SYSTEM_MODULE_NAME.BASE, queryGql);
|
|
49
|
+
return result.data.widgetDefinitionQuery.loadSDK;
|
|
50
|
+
} catch (e) {
|
|
51
|
+
console.error('remote plugin load error.', e);
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { PluginLoader, PluginLoadOption } from '../typing';
|
|
2
|
+
import { bindScriptLoadedEvent } from './LoadedEvent';
|
|
3
|
+
|
|
4
|
+
export class UMDPluginLoader implements PluginLoader {
|
|
5
|
+
public static readonly INSTANCE = new UMDPluginLoader();
|
|
6
|
+
|
|
7
|
+
public async load(option: PluginLoadOption): Promise<void> {
|
|
8
|
+
const { id, path, dependencies } = option;
|
|
9
|
+
const element = document.getElementById(id);
|
|
10
|
+
if (element) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (dependencies) {
|
|
14
|
+
await this.loadDependencies(dependencies);
|
|
15
|
+
}
|
|
16
|
+
return new Promise((resolve) => {
|
|
17
|
+
const script = document.createElement('script');
|
|
18
|
+
script.id = id;
|
|
19
|
+
script.src = path;
|
|
20
|
+
script.type = 'text/javascript';
|
|
21
|
+
bindScriptLoadedEvent(script, resolve);
|
|
22
|
+
document.body.append(script);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public async loadDependencies(dependencies: Record<string, unknown>): Promise<void> {
|
|
27
|
+
if (!dependencies) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const global = window as unknown as Record<string, unknown>;
|
|
31
|
+
await Promise.allSettled(
|
|
32
|
+
Object.entries(dependencies).map(async ([key, value]) => {
|
|
33
|
+
if (global[key] === undefined) {
|
|
34
|
+
let mountModule: unknown | null | undefined;
|
|
35
|
+
if (typeof value === 'string') {
|
|
36
|
+
mountModule = await import(value);
|
|
37
|
+
} else {
|
|
38
|
+
mountModule = await value;
|
|
39
|
+
}
|
|
40
|
+
if (!mountModule) {
|
|
41
|
+
mountModule = null;
|
|
42
|
+
}
|
|
43
|
+
if (global[key] === undefined) {
|
|
44
|
+
global[key] = mountModule;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './PluginLoader';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 插件加载类型
|
|
3
|
+
*/
|
|
4
|
+
export type PluginLoadType = 'esm' | 'cjs' | 'umd' | 'iife' | 'css';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Javascript插件
|
|
8
|
+
* default type: umd
|
|
9
|
+
*/
|
|
10
|
+
export type JavascriptPlugin = string | { type: PluginLoadType; path: string };
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* CSS插件
|
|
14
|
+
* type: css
|
|
15
|
+
*/
|
|
16
|
+
export type CSSPlugin = string;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* key: module
|
|
20
|
+
* value: global name or module
|
|
21
|
+
*/
|
|
22
|
+
type PluginLoadDependencies = Record<string, unknown>;
|
|
23
|
+
|
|
24
|
+
export interface PluginLoadOption {
|
|
25
|
+
id: string;
|
|
26
|
+
type: PluginLoadType;
|
|
27
|
+
path: string;
|
|
28
|
+
dependencies?: PluginLoadDependencies;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface RemoteLoadOption {
|
|
32
|
+
javascript?: JavascriptPlugin[];
|
|
33
|
+
css?: CSSPlugin[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 加载器
|
|
38
|
+
*/
|
|
39
|
+
export interface PluginLoader {
|
|
40
|
+
/**
|
|
41
|
+
* 通过加载可选项进行加载
|
|
42
|
+
* @param option
|
|
43
|
+
*/
|
|
44
|
+
load(option: PluginLoadOption): Promise<void>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 依赖加载
|
|
48
|
+
* @param dependencies 加载依赖
|
|
49
|
+
*/
|
|
50
|
+
loadDependencies(dependencies: PluginLoadDependencies): Promise<void>;
|
|
51
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { CSSPlugin, JavascriptPlugin, PluginLoadType } from './load-option';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 插件加载依赖
|
|
5
|
+
*/
|
|
6
|
+
export type PluginLoadDependency = {
|
|
7
|
+
/**
|
|
8
|
+
* 插件加载类型
|
|
9
|
+
*/
|
|
10
|
+
type: PluginLoadType;
|
|
11
|
+
/**
|
|
12
|
+
* 依赖项
|
|
13
|
+
*/
|
|
14
|
+
dependencies: Record<string, unknown>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 插件加载依赖
|
|
19
|
+
*/
|
|
20
|
+
export type PluginLoadDependencies = Record<string, unknown> | PluginLoadDependency[];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 插件加载配置
|
|
24
|
+
*/
|
|
25
|
+
export interface PluginsLoaderConfig {
|
|
26
|
+
/**
|
|
27
|
+
* 动态指定依赖(未实现)
|
|
28
|
+
*/
|
|
29
|
+
dependencies?: PluginLoadDependencies;
|
|
30
|
+
/**
|
|
31
|
+
* 挂载指定外部js和css;数组默认使用js加载
|
|
32
|
+
*/
|
|
33
|
+
mounted?: JavascriptPlugin[] | { js?: JavascriptPlugin[]; css?: CSSPlugin[] };
|
|
34
|
+
/**
|
|
35
|
+
* 使用低无一体组件;默认为false
|
|
36
|
+
*/
|
|
37
|
+
usingRemote?: boolean;
|
|
38
|
+
}
|