@byteluck-fe/model-driven-engine 2.7.0-alpha.2 → 2.7.0-alpha.21

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.
@@ -1,9 +1,23 @@
1
- function _classCallCheck(instance, Constructor) {
1
+ function _class_call_check(instance, Constructor) {
2
2
  if (!(instance instanceof Constructor)) {
3
3
  throw new TypeError("Cannot call a class as a function");
4
4
  }
5
5
  }
6
- function _defineProperty(obj, key, value) {
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) {
7
21
  if (key in obj) {
8
22
  Object.defineProperty(obj, key, {
9
23
  value: value,
@@ -16,14 +30,7 @@ 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
- function _objectSpread(target) {
33
+ function _object_spread(target) {
27
34
  for(var i = 1; i < arguments.length; i++){
28
35
  var source = arguments[i] != null ? arguments[i] : {};
29
36
  var ownKeys = Object.keys(source);
@@ -33,18 +40,24 @@ function _objectSpread(target) {
33
40
  }));
34
41
  }
35
42
  ownKeys.forEach(function(key) {
36
- _defineProperty(target, key, source[key]);
43
+ _define_property(target, key, source[key]);
37
44
  });
38
45
  }
39
46
  return target;
40
47
  }
41
- import { DataBind, ObjectDataBind } from "@byteluck-fe/model-driven-core";
48
+ import { DataBind, isDataBind } from "@byteluck-fe/model-driven-core";
42
49
  import { loopFormSchema, JSONCopy, warn, CONTROL_TYPE, CONTROL_BASE_TYPE } from "@byteluck-fe/model-driven-shared";
43
50
  import { loopDataViewControl, loopFormControl, buildUUID } from "../utils/runtimeUtils";
44
51
  var Store = /*#__PURE__*/ function() {
45
52
  "use strict";
46
53
  function Store(props) {
47
- _classCallCheck(this, Store);
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
+ );
59
+ _define_property(this, "controlIdMapping", void 0);
60
+ _define_property(this, "defaultState", void 0);
48
61
  var _init = init(props.instance), state = _init.state, emptyState = _init.emptyState, databindMapping = _init.databindMapping, controlidMapping = _init.controlidMapping, defaultState = _init.defaultState;
49
62
  this.emptyState = emptyState;
50
63
  this.state = state;
@@ -52,145 +65,161 @@ var Store = /*#__PURE__*/ function() {
52
65
  this.controlIdMapping = controlidMapping;
53
66
  this.defaultState = defaultState;
54
67
  }
55
- var _proto = Store.prototype;
56
- /**
68
+ _create_class(Store, [
69
+ {
70
+ /**
57
71
  * 使用该方法仅改变数据,不会表单触发事件。明细表可全量赋值也可根据rowIndex进行单独设置
58
72
  * @param controlId 组件ID
59
73
  * @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;
74
+ */ key: "setState",
75
+ value: function setState(controlId, value, rowIndex) {
76
+ var _this = this;
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
+ //TODO 目前只找了一层明细表,没有递归 如果是添加uid
92
+ Object.keys(this.controlIdMapping).map(function(subtableId) {
93
+ var dataView = _this.controlIdMapping[subtableId].dataView;
94
+ var children = _this.controlIdMapping[subtableId].children;
95
+ if (children !== undefined) {
96
+ Object.keys(children).map(function(childControlId) {
97
+ if (childControlId === controlId) {
98
+ if (_this.state[dataView][subtableId][rowIndex]) {
99
+ _this.state[dataView][subtableId][rowIndex][controlId] = value;
100
+ }
101
+ }
102
+ });
84
103
  }
85
104
  });
105
+ } else {
106
+ //不存在的 controlId,直接被挂载到外部key
107
+ this.state[controlId] = value;
86
108
  }
87
- });
88
- } else {
89
- //不存在的 controlId,直接被挂载到外部key
90
- this.state[controlId] = value;
109
+ }
91
110
  }
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];
111
+ },
112
+ {
113
+ key: "getState",
114
+ value: function getState(controlId, rowIndex) {
115
+ var _this = this;
116
+ //qiyu 由于header的数据是后补充的,所以从state获取第一层值。
117
+ // const controlInfo = this.controlIdMapping[controlId]
118
+ var detection = this.state[controlId];
119
+ if (detection !== undefined) {
120
+ return this.state[controlId];
121
+ } else {
122
+ var controlInfo = this.controlIdMapping[controlId];
123
+ if (controlInfo !== undefined) {
124
+ return this.state[controlInfo.dataView][controlId];
125
+ } else {
126
+ if (rowIndex !== undefined) {
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
+ Object.keys(children).map(function(childControlId) {
134
+ if (childControlId === controlId) {
135
+ var _this_state_dataViewId_subtableId_rowIndex;
136
+ 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];
137
+ }
138
+ });
117
139
  }
118
140
  });
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]);
141
+ return state;
142
+ } else {
143
+ var states = [];
144
+ Object.keys(this.controlIdMapping).map(function(subtableId) {
145
+ var dataViewId = _this.controlIdMapping[subtableId].dataView;
146
+ var children = _this.controlIdMapping[subtableId].children;
147
+ if (children !== undefined) {
148
+ Object.keys(children).map(function(childControlId) {
149
+ if (childControlId === controlId) {
150
+ _this.state[dataViewId][subtableId].map(function(item) {
151
+ states.push(item[controlId]);
152
+ });
153
+ }
132
154
  });
133
155
  }
134
156
  });
157
+ return states;
135
158
  }
136
- });
137
- return states;
159
+ }
138
160
  }
139
161
  }
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];
162
+ },
163
+ {
164
+ key: "getEmptyState",
165
+ value: function getEmptyState(controlId) {
166
+ var _this = this;
167
+ var detection = this.emptyState[controlId];
168
+ if (detection !== undefined) {
169
+ return this.emptyState[controlId];
170
+ } else {
171
+ var controlInfo = this.controlIdMapping[controlId];
172
+ if (controlInfo !== undefined) {
173
+ var state = this.emptyState[controlInfo.dataView][controlId];
174
+ //判断找到的是否是明细表的控件
175
+ if ("children" in controlInfo) {
176
+ Object.assign(state, {
177
+ uid: "new:" + buildUUID("uid")
178
+ });
179
+ }
180
+ return state;
181
+ } else {
182
+ var state1;
183
+ //TODO 目前只找了一层明细表,没有递归
184
+ Object.keys(this.controlIdMapping).map(function(subtableId) {
185
+ var dataViewId = _this.controlIdMapping[subtableId].dataView;
186
+ var children = _this.controlIdMapping[subtableId].children;
187
+ if (children !== undefined) {
188
+ Object.keys(children).map(function(childControlId) {
189
+ if (childControlId === controlId) {
190
+ state1 = _this.emptyState[dataViewId][subtableId][controlId];
191
+ }
192
+ });
168
193
  }
169
194
  });
195
+ return state1;
170
196
  }
171
- });
172
- return state1;
197
+ }
173
198
  }
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;
199
+ },
200
+ {
201
+ key: "getDataBind",
202
+ value: function getDataBind(controlId) {
203
+ var _result;
204
+ var result = this.controlIdMapping[controlId];
205
+ if (result) {
206
+ return result.dataBind;
207
+ }
208
+ wrapperFor: for(var id in this.controlIdMapping){
209
+ var dataBindMapping = this.controlIdMapping[id];
210
+ if (dataBindMapping.children) {
211
+ for(var subId in dataBindMapping.children){
212
+ if (subId === controlId) {
213
+ result = dataBindMapping.children[subId];
214
+ break wrapperFor;
215
+ }
216
+ }
188
217
  }
189
218
  }
219
+ return (_result = result) === null || _result === void 0 ? void 0 : _result.dataBind;
190
220
  }
191
221
  }
192
- return result === null || result === void 0 ? void 0 : result.dataBind;
193
- };
222
+ ]);
194
223
  return Store;
195
224
  }();
196
225
  function init(instance) {
@@ -238,12 +267,12 @@ item) {
238
267
  loopFormSchema(item.props.headers, function(headerItem) {
239
268
  emptyTemplate[headerItem.id] = JSONCopy(headerItem.props.defaultValue);
240
269
  });
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() {
243
- return _objectSpread({
270
+ var _item_props_defaultRows, _fill_map;
271
+ 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() {
272
+ return _object_spread({
244
273
  uid: "new:" + buildUUID("uid")
245
274
  }, JSONCopy(emptyTemplate));
246
- });
275
+ })) !== null && _fill_map !== void 0 ? _fill_map : [];
247
276
  emptyDataViewState[item.id] = emptyTemplate;
248
277
  }
249
278
  }
@@ -251,8 +280,9 @@ function buildDataBindMapping(data, dataViewId, // @ts-ignore
251
280
  item) {
252
281
  // if (item instanceof RuntimeFormControl) {
253
282
  if (item.controlType === CONTROL_BASE_TYPE.FORM) {
254
- var _item_props, _item_props_dataBind;
255
- if (_instanceof(item.props.dataBind, ObjectDataBind)) {
283
+ var _item_props_dataBind, _item_props;
284
+ // if (item.props.dataBind instanceof ObjectDataBind) {
285
+ if (!isDataBind(item.props.dataBind)) {
256
286
  // 特殊的dataBind,比如:金额是currency+amount两个key组成的,日期区间,继承自ObjectDataBind的需要通过Object.keys拿到多个databind
257
287
  Object.keys(item.props.dataBind).map(function(key) {
258
288
  var dataBind = item.props.dataBind;
@@ -307,7 +337,8 @@ item) {
307
337
  };
308
338
  var subtableId = item.id;
309
339
  loopFormSchema(item.props.headers, function(item) {
310
- if (_instanceof(item.props.dataBind, ObjectDataBind)) {
340
+ // if (item.props.dataBind instanceof ObjectDataBind) {
341
+ if (!isDataBind(item.props.dataBind)) {
311
342
  Object.keys(item.props.dataBind).map(function(key) {
312
343
  var dataBind = item.props.dataBind;
313
344
  var dataCode = dataBind[key].dataCode;
@@ -357,7 +388,7 @@ item) {
357
388
  loopFormSchema(item.props.headers, function(formControl) {
358
389
  var _data_item_id;
359
390
  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, {
391
+ 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, {
361
392
  dataBind: formControl.props.dataBind
362
393
  }));
363
394
  });