@byteluck-fe/model-driven-engine 2.7.0-alpha.1 → 2.7.0-alpha.11

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