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