@byteluck-fe/model-driven-engine 2.3.1-beta.25 → 2.3.1-beta.27

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