@byteluck-fe/model-driven-engine 2.23.0-beta.26-chrome86 → 2.23.0-beta.26-chrome86-2

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.
Files changed (41) hide show
  1. package/README.md +30 -30
  2. package/dist/esm/common/ActionManager.js +269 -0
  3. package/dist/esm/common/DataManager.js +208 -0
  4. package/dist/esm/common/Engine.js +1787 -0
  5. package/dist/esm/common/OkWorker.js +134 -0
  6. package/dist/esm/common/Plugin.js +10 -0
  7. package/dist/esm/common/Runtime.js +458 -0
  8. package/dist/esm/common/Store.js +443 -0
  9. package/dist/esm/common/checkerValue.js +609 -0
  10. package/dist/esm/common/index.js +2 -0
  11. package/dist/esm/common/proxyState.js +321 -0
  12. package/dist/esm/index.js +3 -0
  13. package/dist/esm/plugins/CalcPlugin.js +500 -0
  14. package/dist/esm/plugins/ControlsEventPlugin.js +315 -0
  15. package/dist/esm/plugins/ES6ModulePlugin.js +210 -0
  16. package/dist/esm/plugins/LifecycleEventPlugin.js +310 -0
  17. package/dist/esm/plugins/StylePlugin.js +73 -0
  18. package/dist/esm/plugins/index.js +5 -0
  19. package/dist/esm/utils/index.js +1 -0
  20. package/dist/esm/utils/runtimeUtils.js +45 -0
  21. package/dist/index.umd.js +22 -0
  22. package/dist/types/common/ActionManager.d.ts +14 -14
  23. package/dist/types/common/DataManager.d.ts +10 -10
  24. package/dist/types/common/Engine.d.ts +201 -0
  25. package/dist/types/common/OkWorker.d.ts +13 -13
  26. package/dist/types/common/Plugin.d.ts +6 -6
  27. package/dist/types/common/Runtime.d.ts +31 -31
  28. package/dist/types/common/Store.d.ts +54 -54
  29. package/dist/types/common/checkerValue.d.ts +3 -3
  30. package/dist/types/common/index.d.ts +2 -2
  31. package/dist/types/common/proxyState.d.ts +30 -30
  32. package/dist/types/index.d.ts +3 -3
  33. package/dist/types/plugins/CalcPlugin.d.ts +121 -121
  34. package/dist/types/plugins/ControlsEventPlugin.d.ts +17 -17
  35. package/dist/types/plugins/ES6ModulePlugin.d.ts +27 -27
  36. package/dist/types/plugins/LifecycleEventPlugin.d.ts +15 -15
  37. package/dist/types/plugins/StylePlugin.d.ts +13 -13
  38. package/dist/types/plugins/index.d.ts +5 -5
  39. package/dist/types/utils/index.d.ts +1 -1
  40. package/dist/types/utils/runtimeUtils.d.ts +5 -5
  41. package/package.json +4 -4
@@ -0,0 +1,443 @@
1
+ function _class_call_check(instance, Constructor) {
2
+ if (!(instance instanceof Constructor)) {
3
+ throw new TypeError("Cannot call a class as a function");
4
+ }
5
+ }
6
+ function _defineProperties(target, props) {
7
+ for(var i = 0; i < props.length; i++){
8
+ var descriptor = props[i];
9
+ descriptor.enumerable = descriptor.enumerable || false;
10
+ descriptor.configurable = true;
11
+ if ("value" in descriptor) descriptor.writable = true;
12
+ Object.defineProperty(target, descriptor.key, descriptor);
13
+ }
14
+ }
15
+ function _create_class(Constructor, protoProps, staticProps) {
16
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
+ if (staticProps) _defineProperties(Constructor, staticProps);
18
+ return Constructor;
19
+ }
20
+ function _define_property(obj, key, value) {
21
+ if (key in obj) {
22
+ Object.defineProperty(obj, key, {
23
+ value: value,
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true
27
+ });
28
+ } else {
29
+ obj[key] = value;
30
+ }
31
+ return obj;
32
+ }
33
+ function _object_spread(target) {
34
+ for(var i = 1; i < arguments.length; i++){
35
+ var source = arguments[i] != null ? arguments[i] : {};
36
+ var ownKeys = Object.keys(source);
37
+ if (typeof Object.getOwnPropertySymbols === "function") {
38
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
39
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
40
+ }));
41
+ }
42
+ ownKeys.forEach(function(key) {
43
+ _define_property(target, key, source[key]);
44
+ });
45
+ }
46
+ return target;
47
+ }
48
+ import { DataBind, isDataBind } from '@byteluck-fe/model-driven-core';
49
+ import { loopFormSchema, JSONCopy, warn, CONTROL_TYPE, CONTROL_BASE_TYPE } from '@byteluck-fe/model-driven-shared';
50
+ import { loopDataViewControl, loopFormControl, buildUUID } from '../utils/runtimeUtils';
51
+ var Store = /*#__PURE__*/ function() {
52
+ "use strict";
53
+ function Store(props) {
54
+ _class_call_check(this, Store);
55
+ _define_property(this, "emptyState", void 0);
56
+ _define_property(this, "state", void 0);
57
+ _define_property(this, "dataBindMapping", void 0); // 主要提供给二开使用
58
+ _define_property(this, "controlIdMapping", void 0);
59
+ _define_property(this, "subtableHeadersControlIdMapping", void 0);
60
+ _define_property(this, "defaultState", void 0);
61
+ var _init = init(props.instance), state = _init.state, emptyState = _init.emptyState, databindMapping = _init.databindMapping, controlidMapping = _init.controlidMapping, defaultState = _init.defaultState, subtableHeadersControlIdMapping = _init.subtableHeadersControlIdMapping;
62
+ this.emptyState = emptyState;
63
+ this.state = state;
64
+ this.dataBindMapping = databindMapping;
65
+ this.controlIdMapping = controlidMapping;
66
+ this.defaultState = defaultState;
67
+ this.subtableHeadersControlIdMapping = subtableHeadersControlIdMapping;
68
+ }
69
+ _create_class(Store, [
70
+ {
71
+ /**
72
+ * 使用该方法仅改变数据,不会表单触发事件。明细表可全量赋值也可根据rowIndex进行单独设置
73
+ * @param controlId 组件ID
74
+ * @param value
75
+ */ key: "setState",
76
+ value: function setState(controlId, value, rowIndex) {
77
+ var _this = this;
78
+ var controlInfo = this.controlIdMapping[controlId];
79
+ var noProxyValue = JSONCopy(value);
80
+ if (controlInfo !== undefined) {
81
+ //明细表
82
+ if (controlInfo.children) {
83
+ ;
84
+ value.forEach(function(item) {
85
+ if (!item.uid) {
86
+ Object.assign(item, {
87
+ uid: 'new:' + buildUUID('uid')
88
+ });
89
+ }
90
+ });
91
+ }
92
+ //qiyu 按照对象赋值,Object.assign会触发多次key的change事件
93
+ this.state[controlInfo.dataView][controlId] = noProxyValue;
94
+ // if (
95
+ // controlInfo.dataBind instanceof ObjectDataBind &&
96
+ // isPlainObject(value)
97
+ // ) {
98
+ // Object.assign(this.state[controlInfo.dataView][controlId], value)
99
+ // } else {
100
+ // this.state[controlInfo.dataView][controlId] = value
101
+ // }
102
+ } else {
103
+ if (rowIndex !== undefined) {
104
+ //TODO 目前只找了一层明细表,没有递归 如果是添加uid
105
+ Object.keys(this.controlIdMapping).map(function(subtableId) {
106
+ var dataView = _this.controlIdMapping[subtableId].dataView;
107
+ var children = _this.controlIdMapping[subtableId].children;
108
+ if (children !== undefined) {
109
+ Object.keys(children).map(function(childControlId) {
110
+ if (childControlId === controlId) {
111
+ if (_this.state[dataView][subtableId][rowIndex]) {
112
+ ;
113
+ _this.state[dataView][subtableId][rowIndex][controlId] = noProxyValue;
114
+ }
115
+ }
116
+ });
117
+ }
118
+ });
119
+ } else {
120
+ //不存在的 controlId,直接被挂载到外部key
121
+ this.state[controlId] = noProxyValue;
122
+ }
123
+ }
124
+ }
125
+ },
126
+ {
127
+ key: "getState",
128
+ value: function getState(controlId, rowIndex) {
129
+ var _this = this;
130
+ //qiyu 由于header的数据是后补充的,所以从state获取第一层值。
131
+ // const controlInfo = this.controlIdMapping[controlId]
132
+ var detection = this.state[controlId];
133
+ if (detection !== undefined) {
134
+ return this.state[controlId];
135
+ } else {
136
+ var controlInfo = this.controlIdMapping[controlId];
137
+ if (controlInfo !== undefined) {
138
+ var data = this.state[controlInfo.dataView][controlId];
139
+ var _controlInfo_children;
140
+ // 只有明细表key,再通过rowIndex获取行数据
141
+ if (rowIndex !== undefined && Object.keys((_controlInfo_children = controlInfo === null || controlInfo === void 0 ? void 0 : controlInfo.children) !== null && _controlInfo_children !== void 0 ? _controlInfo_children : {}).length > 0) {
142
+ return data[rowIndex];
143
+ } else {
144
+ return data;
145
+ }
146
+ } else {
147
+ if (rowIndex !== undefined) {
148
+ var state;
149
+ //TODO 目前只找了一层明细表,没有递归
150
+ Object.keys(this.controlIdMapping).map(function(subtableId) {
151
+ var dataViewId = _this.controlIdMapping[subtableId].dataView;
152
+ var children = _this.controlIdMapping[subtableId].children;
153
+ if (children !== undefined) {
154
+ Object.keys(children).map(function(childControlId) {
155
+ if (childControlId === controlId) {
156
+ var _this_state_dataViewId_subtableId_rowIndex;
157
+ state = (_this_state_dataViewId_subtableId_rowIndex = _this.state[dataViewId][subtableId][rowIndex]) === null || _this_state_dataViewId_subtableId_rowIndex === void 0 ? void 0 : _this_state_dataViewId_subtableId_rowIndex[controlId];
158
+ }
159
+ });
160
+ }
161
+ });
162
+ return state;
163
+ } else {
164
+ var states = [];
165
+ Object.keys(this.controlIdMapping).map(function(subtableId) {
166
+ var dataViewId = _this.controlIdMapping[subtableId].dataView;
167
+ var children = _this.controlIdMapping[subtableId].children;
168
+ if (children !== undefined) {
169
+ Object.keys(children).map(function(childControlId) {
170
+ if (childControlId === controlId) {
171
+ ;
172
+ _this.state[dataViewId][subtableId].map(function(item) {
173
+ states.push(item[controlId]);
174
+ });
175
+ }
176
+ });
177
+ }
178
+ });
179
+ return states;
180
+ }
181
+ }
182
+ }
183
+ }
184
+ },
185
+ {
186
+ key: "getEmptyState",
187
+ value: function getEmptyState(controlId) {
188
+ var _this = this;
189
+ var detection = this.emptyState[controlId];
190
+ if (detection !== undefined) {
191
+ return this.emptyState[controlId];
192
+ } else {
193
+ var controlInfo = this.controlIdMapping[controlId];
194
+ if (controlInfo !== undefined) {
195
+ var state = this.emptyState[controlInfo.dataView][controlId];
196
+ //判断找到的是否是明细表的控件
197
+ if ('children' in controlInfo) {
198
+ Object.assign(state, {
199
+ uid: 'new:' + buildUUID('uid')
200
+ });
201
+ }
202
+ return state;
203
+ } else {
204
+ var state1;
205
+ //TODO 目前只找了一层明细表,没有递归
206
+ Object.keys(this.controlIdMapping).map(function(subtableId) {
207
+ var dataViewId = _this.controlIdMapping[subtableId].dataView;
208
+ var children = _this.controlIdMapping[subtableId].children;
209
+ if (children !== undefined) {
210
+ Object.keys(children).map(function(childControlId) {
211
+ if (childControlId === controlId) {
212
+ state1 = _this.emptyState[dataViewId][subtableId][controlId];
213
+ }
214
+ });
215
+ }
216
+ });
217
+ return state1;
218
+ }
219
+ }
220
+ }
221
+ },
222
+ {
223
+ key: "getDataBind",
224
+ value: function getDataBind(controlId) {
225
+ var result = this.controlIdMapping[controlId];
226
+ if (result) {
227
+ return result.dataBind;
228
+ }
229
+ wrapperFor: for(var id in this.controlIdMapping){
230
+ var dataBindMapping = this.controlIdMapping[id];
231
+ if (dataBindMapping.children) {
232
+ for(var subId in dataBindMapping.children){
233
+ if (subId === controlId) {
234
+ result = dataBindMapping.children[subId];
235
+ break wrapperFor;
236
+ }
237
+ }
238
+ }
239
+ }
240
+ return result === null || result === void 0 ? void 0 : result.dataBind;
241
+ }
242
+ }
243
+ ]);
244
+ return Store;
245
+ }();
246
+ function init(instance) {
247
+ var state = {};
248
+ var emptyState = {};
249
+ var databindMapping = {};
250
+ var controlidMapping = {};
251
+ var subtableHeadersControlIdMapping = {};
252
+ var defaultState = {};
253
+ // loopFormControl(instance, (item, children) => {
254
+ // })
255
+ // @ts-ignore
256
+ loopDataViewControl(instance, function(dataView) {
257
+ var dvId = dataView.id;
258
+ var dataViewState = {};
259
+ var emptyDataViewState = {};
260
+ // @ts-ignore
261
+ loopFormControl([
262
+ dataView
263
+ ], function(item, children) {
264
+ buildState(dataViewState, emptyDataViewState, item);
265
+ buildDataBindMapping(databindMapping, dvId, item);
266
+ buildControlIdMapping(controlidMapping, dvId, item);
267
+ buildSubtableHeadersControlIdMapping(subtableHeadersControlIdMapping, item);
268
+ });
269
+ state[dvId] = {};
270
+ defaultState[dvId] = dataViewState;
271
+ emptyState[dvId] = emptyDataViewState;
272
+ });
273
+ return {
274
+ state: state,
275
+ defaultState: defaultState,
276
+ subtableHeadersControlIdMapping: subtableHeadersControlIdMapping,
277
+ emptyState: emptyState,
278
+ databindMapping: databindMapping,
279
+ controlidMapping: controlidMapping
280
+ };
281
+ }
282
+ function buildState(dataViewState, emptyDataViewState, // @ts-ignore
283
+ item) {
284
+ //if (item instanceof RuntimeFormControl) {
285
+ if (item.controlType === CONTROL_BASE_TYPE.FORM) {
286
+ // 2023-4-2 jiaqi 首次进入页面去除填充默认值
287
+ dataViewState[item.id] = JSONCopy(item.props.defaultValue);
288
+ emptyDataViewState[item.id] = JSONCopy(item.props.defaultValue);
289
+ } else {
290
+ var emptyTemplate = {};
291
+ loopFormSchema(item.props.headers, function(headerItem) {
292
+ emptyTemplate[headerItem.id] = JSONCopy(headerItem.props.defaultValue);
293
+ });
294
+ var _item_props_defaultRows, _fill_map;
295
+ dataViewState[item.id] = (_fill_map = new Array((_item_props_defaultRows = item.props.defaultRows) !== null && _item_props_defaultRows !== void 0 ? _item_props_defaultRows : 1).fill(0).map(function() {
296
+ return _object_spread({
297
+ uid: 'new:' + buildUUID('uid')
298
+ }, JSONCopy(emptyTemplate));
299
+ })) !== null && _fill_map !== void 0 ? _fill_map : [];
300
+ emptyDataViewState[item.id] = emptyTemplate;
301
+ }
302
+ }
303
+ function buildDataBindMapping(data, dataViewId, // @ts-ignore
304
+ item) {
305
+ // if (item instanceof RuntimeFormControl) {
306
+ if (item.controlType === CONTROL_BASE_TYPE.FORM) {
307
+ var _item_props_dataBind, _item_props;
308
+ // if (item.props.dataBind instanceof ObjectDataBind) {
309
+ if (!isDataBind(item.props.dataBind)) {
310
+ // 特殊的dataBind,比如:金额是currency+amount两个key组成的,日期区间,继承自ObjectDataBind的需要通过Object.keys拿到多个databind
311
+ Object.keys(item.props.dataBind).map(function(key) {
312
+ var dataBind = item.props.dataBind;
313
+ var dataCode = dataBind[key].dataCode;
314
+ if (dataCode !== undefined) {
315
+ if (data[dataCode] === undefined) {
316
+ data[dataCode] = {
317
+ controlId: item.id,
318
+ fields: [],
319
+ dataViewId: dataViewId
320
+ };
321
+ }
322
+ data[dataCode].fields.push({
323
+ fieldCode: dataBind[key].fieldCode,
324
+ controlId: item.id,
325
+ dataBind: dataBind,
326
+ dataViewId: [
327
+ dataViewId
328
+ ]
329
+ });
330
+ }
331
+ });
332
+ } else if (((_item_props = item.props) === null || _item_props === void 0 ? void 0 : (_item_props_dataBind = _item_props.dataBind) === null || _item_props_dataBind === void 0 ? void 0 : _item_props_dataBind.dataCode) === undefined) {
333
+ //qiyu 2023-2-27 为空跳过。form自定义组件加载失败时,hack的组件props为空。
334
+ } else {
335
+ if (data[item.props.dataBind.dataCode] === undefined) {
336
+ data[item.props.dataBind.dataCode] = {
337
+ controlId: dataViewId,
338
+ fields: [],
339
+ dataViewId: dataViewId
340
+ };
341
+ }
342
+ data[item.props.dataBind.dataCode].fields.push({
343
+ fieldCode: item.props.dataBind.fieldCode,
344
+ controlId: item.id,
345
+ dataBind: item.props.dataBind,
346
+ dataViewId: [
347
+ dataViewId
348
+ ]
349
+ });
350
+ }
351
+ } else {
352
+ if (item.props.datasourceBind.dataCode === '') {
353
+ //敏捷依赖后端生成dataCode,预览的时候没有
354
+ warn("datasourceBind.dataCode is empty! maybe in preview mode, control:".concat(item.id, " type:").concat(item.type));
355
+ return;
356
+ }
357
+ data[item.props.datasourceBind.dataCode] = {
358
+ controlId: item.id,
359
+ fields: [],
360
+ dataViewId: dataViewId
361
+ };
362
+ var subtableId = item.id;
363
+ loopFormSchema(item.props.headers, function(item) {
364
+ // if (item.props.dataBind instanceof ObjectDataBind) {
365
+ if (!isDataBind(item.props.dataBind)) {
366
+ Object.keys(item.props.dataBind).map(function(key) {
367
+ var dataBind = item.props.dataBind;
368
+ var dataCode = dataBind[key].dataCode;
369
+ if (dataBind[key].fieldCode !== '') {
370
+ data[dataCode].fields.push({
371
+ fieldCode: dataBind[key].fieldCode,
372
+ controlId: item.id,
373
+ dataBind: dataBind,
374
+ dataViewId: [
375
+ dataViewId,
376
+ subtableId
377
+ ]
378
+ });
379
+ }
380
+ });
381
+ } else {
382
+ if (data[item.props.dataBind.dataCode] === undefined) {
383
+ data[item.props.dataBind.dataCode] = {
384
+ controlId: dataViewId,
385
+ fields: [],
386
+ dataViewId: dataViewId
387
+ };
388
+ }
389
+ data[item.props.dataBind.dataCode].fields.push({
390
+ fieldCode: item.props.dataBind.fieldCode,
391
+ controlId: item.id,
392
+ dataBind: item.props.dataBind,
393
+ dataViewId: [
394
+ dataViewId,
395
+ subtableId
396
+ ]
397
+ });
398
+ }
399
+ });
400
+ }
401
+ }
402
+ function buildControlIdMapping(data, dataViewId, // @ts-ignore
403
+ item) {
404
+ // if (item instanceof RuntimeFormControl) {
405
+ if (item.controlType === CONTROL_BASE_TYPE.FORM) {
406
+ data[item.id] = {
407
+ dataBind: item.props.dataBind,
408
+ options: [],
409
+ dataView: dataViewId
410
+ };
411
+ } else if (item.type === CONTROL_TYPE.SUBTABLE) {
412
+ data[item.id] = {
413
+ dataBind: new DataBind({
414
+ dataCode: item.props.datasourceBind.dataCode,
415
+ fieldCode: ''
416
+ }),
417
+ dataView: dataViewId,
418
+ children: {},
419
+ options: []
420
+ };
421
+ loopFormSchema(item.props.headers, function(formControl) {
422
+ var _data_item_id;
423
+ var _data_item_id_children;
424
+ Object.assign((_data_item_id_children = (_data_item_id = data[item.id]) === null || _data_item_id === void 0 ? void 0 : _data_item_id.children) !== null && _data_item_id_children !== void 0 ? _data_item_id_children : {}, _define_property({}, formControl.id, {
425
+ dataBind: formControl.props.dataBind
426
+ }));
427
+ });
428
+ }
429
+ }
430
+ function buildSubtableHeadersControlIdMapping(data, // @ts-ignore
431
+ item) {
432
+ if (item.type === CONTROL_TYPE.SUBTABLE) {
433
+ var headersInstances = {};
434
+ item.props.headers.map(// @ts-ignore
435
+ function(item) {
436
+ item.children.map(function(item) {
437
+ Object.assign(headersInstances, _define_property({}, item.id, item));
438
+ });
439
+ });
440
+ Object.assign(data, _define_property({}, item.id, headersInstances));
441
+ }
442
+ }
443
+ export { Store };