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

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.
@@ -1178,7 +1178,12 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1178
1178
  if (!newState[mapping.dataViewId]) {
1179
1179
  newState[mapping.dataViewId] = {};
1180
1180
  }
1181
- newState[mapping.dataViewId][mapping.controlId] = [];
1181
+ if (!entity.length) {
1182
+ var _newState_mapping_dataViewId_mapping_controlId;
1183
+ newState[mapping.dataViewId][mapping.controlId] = (_newState_mapping_dataViewId_mapping_controlId = newState[mapping.dataViewId][mapping.controlId]) !== null && _newState_mapping_dataViewId_mapping_controlId !== void 0 ? _newState_mapping_dataViewId_mapping_controlId : [];
1184
+ } else {
1185
+ newState[mapping.dataViewId][mapping.controlId] = [];
1186
+ }
1182
1187
  entity.map(function(row) {
1183
1188
  var newRow = JSONCopy(_this.store.emptyState[mapping.dataViewId][mapping.controlId]);
1184
1189
  var skipKey = [] //qiyu ObjectDataBind中会提前将相关key拿出来赋值,为了避免重复赋值,设置了此变量
@@ -82,9 +82,10 @@ var Store = /*#__PURE__*/ function() {
82
82
  value: function setState(controlId, value, rowIndex) {
83
83
  var _this = this;
84
84
  var controlInfo = this.controlIdMapping[controlId];
85
+ var noProxyValue = JSONCopy(value);
85
86
  if (controlInfo !== undefined) {
86
87
  //qiyu 按照对象赋值,Object.assign会触发多次key的change事件
87
- this.state[controlInfo.dataView][controlId] = value;
88
+ this.state[controlInfo.dataView][controlId] = noProxyValue;
88
89
  // if (
89
90
  // controlInfo.dataBind instanceof ObjectDataBind &&
90
91
  // isPlainObject(value)
@@ -102,14 +103,16 @@ var Store = /*#__PURE__*/ function() {
102
103
  if (children !== undefined) {
103
104
  Object.keys(children).map(function(childControlId) {
104
105
  if (childControlId === controlId) {
105
- _this.state[dataView][subtableId][rowIndex][controlId] = value;
106
+ if (_this.state[dataView][subtableId][rowIndex]) {
107
+ _this.state[dataView][subtableId][rowIndex][controlId] = noProxyValue;
108
+ }
106
109
  }
107
110
  });
108
111
  }
109
112
  });
110
113
  } else {
111
114
  //不存在的 controlId,直接被挂载到外部key
112
- this.state[controlId] = value;
115
+ this.state[controlId] = noProxyValue;
113
116
  }
114
117
  }
115
118
  }
@@ -271,12 +274,12 @@ item) {
271
274
  loopFormSchema(item.props.headers, function(headerItem) {
272
275
  emptyTemplate[headerItem.id] = JSONCopy(headerItem.props.defaultValue);
273
276
  });
274
- var _item_props_defaultRows;
275
- 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() {
277
+ var _item_props_defaultRows, _fill_map;
278
+ 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() {
276
279
  return _objectSpread({
277
280
  uid: "new:" + buildUUID("uid")
278
281
  }, JSONCopy(emptyTemplate));
279
- });
282
+ })) !== null && _fill_map !== void 0 ? _fill_map : [];
280
283
  emptyDataViewState[item.id] = emptyTemplate;
281
284
  }
282
285
  }
@@ -24,7 +24,7 @@ function _unsupportedIterableToArray(o, minLen) {
24
24
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
25
25
  }
26
26
  var cc = console;
27
- import { CONTROL_BASE_TYPE, error, logerror } from "@byteluck-fe/model-driven-shared";
27
+ import { CONTROL_BASE_TYPE, error, logerror, JSONCopy } from "@byteluck-fe/model-driven-shared";
28
28
  var proxyArrayApi = [
29
29
  "splice",
30
30
  "push",
@@ -137,19 +137,19 @@ function ArrayHandler(target, propertyKey, value, thisKey, callback) {
137
137
  }
138
138
  }
139
139
  };
140
- var newValue = value;
140
+ var newValue = JSONCopy(value);
141
141
  // @ts-ignore
142
142
  var oldValue = target[propertyKey];
143
143
  var concatKey = thisKey === "" ? propertyKey : thisKey + "." + propertyKey;
144
144
  var _reProxyState;
145
- newValue = (_reProxyState = reProxyState(value)) !== null && _reProxyState !== void 0 ? _reProxyState : newValue;
145
+ newValue = (_reProxyState = reProxyState(newValue)) !== null && _reProxyState !== void 0 ? _reProxyState : newValue;
146
146
  // 先设置值,然后再进行触发回调,确保回调内拿到的是最新的值
147
147
  var setResult;
148
148
  // TODO 数组拦截操作需要重构,优化现有逻辑
149
149
  // TODO 直接操作下标改动明细表时,没有对行数据进行checker
150
150
  if (Array.isArray(target)) {
151
151
  // 操作数组的时候,不需要使用拼接的thisKey,先判断执行的是否是违规操作,违规操作的话会报错,不允许继续执行,正常操作的话,返回一个回调函数,用于在值修改完之后触发
152
- var nextHandler = ArrayHandler(target, propertyKey, value, thisKey, callback);
152
+ var nextHandler = ArrayHandler(target, propertyKey, newValue, thisKey, callback);
153
153
  setResult = Reflect.set(target, propertyKey, newValue, receiver);
154
154
  if (nextHandler) {
155
155
  nextHandler();
@@ -171,9 +171,11 @@ function ArrayHandler(target, propertyKey, value, thisKey, callback) {
171
171
  return true;
172
172
  }
173
173
  setResult = Reflect.set(target, propertyKey, newValue, receiver);
174
- callback.call(null, target, concatKey, value, oldValue);
174
+ callback.call(null, target, concatKey, newValue, oldValue);
175
175
  }
176
- return setResult;
176
+ // 不返回falsy 值(即 false、0、null、undefined、空字符串等)
177
+ //fix: TypeError: Proxy object's 'set' trap returned falsy value for property 'length'
178
+ return setResult ? setResult : true;
177
179
  }
178
180
  };
179
181
  }
@@ -213,7 +213,7 @@ export var ControlsEventPlugin = /*#__PURE__*/ function() {
213
213
  switch(_state.label){
214
214
  case 0:
215
215
  // 初始化state的时候不触发change事件,必须在engine mounted以后才触发
216
- if (eventKey === "change" && !_this.engine.isMounted) {
216
+ if ((eventKey === "change" || eventKey === "list-change") && !_this.engine.isMounted) {
217
217
  return [
218
218
  2
219
219
  ];