@byteluck-fe/model-driven-engine 2.2.0 → 2.2.1-test

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.
@@ -358,6 +358,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
358
358
  _classCallCheck(this, Engine);
359
359
  var _this;
360
360
  _this = _super.call(this);
361
+ _this.rawStore = {};
361
362
  // 提供子线程处理脚本以及修改数据的能力
362
363
  // public worker: OkWorker
363
364
  _this.isMounted = false;
@@ -430,14 +431,16 @@ var Engine = /*#__PURE__*/ function(Watcher) {
430
431
  this.store.state = proxyState(this.store.state, this._proxyStateCallback.bind(this), this._proxyStateBeforeSetCallback.bind(this));
431
432
  };
432
433
  _proto._proxyStateBeforeSetCallback = function _proxyStateBeforeSetCallback(state, key, newValue, oldValue) {
433
- var _this = this;
434
- var instance = findItem(this.runtime.flatInstances, key);
434
+ var instance = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
435
435
  // 找不到控件说明不是改动控件上的字段,直接通过
436
436
  if (!instance) {
437
437
  return newValue;
438
438
  }
439
439
  // @ts-ignore
440
440
  if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE)) {
441
+ if (newValue === null) {
442
+ return [];
443
+ }
441
444
  // @ts-ignore
442
445
  var fieldTypeMap = instance.props.headers.reduce(function(result, column) {
443
446
  var formInstance = column.children[0];
@@ -446,12 +449,11 @@ var Engine = /*#__PURE__*/ function(Watcher) {
446
449
  }
447
450
  return result;
448
451
  }, {});
449
- if (newValue === null) {
450
- return [];
451
- }
452
+ // @ts-ignore
453
+ var emptyState = this.getEmptyState(instance.id);
452
454
  return newValue.map(function(row) {
453
455
  return(// @ts-ignore
454
- checkerSubtableValue(fieldTypeMap, row, _this.getEmptyState(instance.id)));
456
+ checkerSubtableValue(fieldTypeMap, row, emptyState));
455
457
  });
456
458
  }
457
459
  var keys = key.split(".");
@@ -472,7 +474,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
472
474
  };
473
475
  _proto._handlerArrayUpdate = function _handlerArrayUpdate(state, key, type, args, result) {
474
476
  var _this = this;
475
- var subtable = findItem(this.runtime.flatInstances, key);
477
+ var subtable = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
476
478
  if (!_instanceof(subtable, RuntimeListControl)) return;
477
479
  // 新增多行方法
478
480
  var createRows = function(len) {
@@ -562,7 +564,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
562
564
  }
563
565
  };
564
566
  _proto._handlerObjectUpdate = function _handlerObjectUpdate(state, key, value, oldValue) {
565
- var instance = findItem(this.runtime.flatInstances, key);
567
+ var instance = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
566
568
  if (!instance) {
567
569
  return;
568
570
  }
@@ -879,7 +881,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
879
881
  for(var keyChi1 in item[keyChi]){
880
882
  var _controlIdMapping_key_children_keyChi2;
881
883
  objChi[(_controlIdMapping_key_children_keyChi2 = controlIdMapping[key].children[keyChi]) === null || _controlIdMapping_key_children_keyChi2 === void 0 ? void 0 : _controlIdMapping_key_children_keyChi2.dataBind[keyChi1].fieldCode] = item[keyChi][keyChi1];
882
- //
884
+ //
883
885
  }
884
886
  }
885
887
  }
@@ -1133,15 +1135,12 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1133
1135
  if (controlId === undefined) {
1134
1136
  return this.runtime.flatInstances;
1135
1137
  }
1136
- var instances = this.runtime.flatInstances.filter(// @ts-ignore
1137
- function(item) {
1138
- return item.id === controlId;
1139
- });
1138
+ var instances = this.runtime.instanceMap[controlId] || [];
1140
1139
  if (header) {
1141
1140
  // 如果能从flatInstances里边取到,就通过getInstanceInSubtableHeader方法取,取不到则换一种方式
1142
1141
  if (instances.length) {
1143
1142
  var instance = instances[0];
1144
- if (this.getInstanceRowIndex(instance) !== undefined) {
1143
+ if (this.inList(instance.id) === true) {
1145
1144
  var headerInstance = this.getInstanceInSubtableHeader(instance);
1146
1145
  if (headerInstance) {
1147
1146
  instances.unshift(headerInstance);
@@ -1173,6 +1172,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1173
1172
  }
1174
1173
  }
1175
1174
  }
1175
+ // @ts-ignore
1176
1176
  return instances;
1177
1177
  };
1178
1178
  _proto.setInstance = function setInstance(instance, props, value, rowIndex) {
@@ -1313,6 +1313,14 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1313
1313
  _proto.getControlConfig = function getControlConfig(control) {
1314
1314
  return this.runtime.getControlConfig(control);
1315
1315
  };
1316
+ _proto.inList = function inList(controlId) {
1317
+ var mapping = this.store.controlIdMapping;
1318
+ var result = Object.keys(mapping).some(function(key) {
1319
+ var _mapping_key, _mapping_key_children;
1320
+ return (_mapping_key = mapping[key]) === null || _mapping_key === void 0 ? void 0 : (_mapping_key_children = _mapping_key.children) === null || _mapping_key_children === void 0 ? void 0 : _mapping_key_children.hasOwnProperty(controlId);
1321
+ });
1322
+ return result;
1323
+ };
1316
1324
  // 注册外部控件
1317
1325
  Engine.register = function register() {
1318
1326
  for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
@@ -114,6 +114,10 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
114
114
  var instances = [];
115
115
  var instanceMap = {};
116
116
  loop(this._instance, function(item) {
117
+ // 3.4.1 避免将subtable-row 放到 _flatInstances 中
118
+ if (item.type === "subtable-row") {
119
+ return;
120
+ }
117
121
  instances.push(item);
118
122
  if (!instanceMap[item.id]) {
119
123
  instanceMap[item.id] = [];
@@ -32,6 +32,7 @@ function _unsupportedIterableToArray(o, minLen) {
32
32
  }
33
33
  import { RuntimeFormControl } from "@byteluck-fe/model-driven-core";
34
34
  import { error, logerror } from "@byteluck-fe/model-driven-shared";
35
+ var cc = console;
35
36
  var proxyArrayApi = [
36
37
  "splice",
37
38
  "push",
@@ -221,15 +222,21 @@ function flatInstanceForChildren(controls) {
221
222
  * 在flatInstance中通过key查找出对应的instance
222
223
  * @param flatInstance 拍平的instance数组
223
224
  * @param key 操作的数据在state的key - 可以是深层次的 subtable.0.input等
224
- * */ export function findItem(flatInstance, key) {
225
+ * */ export function findItem(flatInstance, key, instanceMap) {
225
226
  if (key === "") return undefined;
226
227
  var keys = key.split(".");
227
228
  if (keys.length === 0) return undefined;
228
229
  var oneKey = keys[0];
229
230
  var otherKeys = keys.slice(1);
230
- var initInstance = flatInstance.find(function(item) {
231
- return item.id === oneKey;
232
- });
231
+ // 3.4.1 优化速度,读取instanceMap
232
+ // cc.time('findItem flatInstance find')
233
+ // const initInstance = flatInstance.find((item) => item.id === oneKey)
234
+ // cc.log('🏠 findItem flatInstance find result', initInstance)
235
+ // cc.timeEnd('findItem flatInstance find')
236
+ // cc.time('findItem instanceMap match')
237
+ var initInstance = instanceMap[oneKey] ? instanceMap[oneKey][0] : undefined;
238
+ // cc.log('🏠 findItem instanceMap match result', initInstance)
239
+ // cc.timeEnd('findItem instanceMap match')
233
240
  if (otherKeys.length === 0) return initInstance;
234
241
  // @ts-ignore
235
242
  return otherKeys.reduce(function(prevItem, key) {
@@ -14,15 +14,12 @@ export function loopFormControl(control, callback) {
14
14
  if (Array.isArray(control)) {
15
15
  control.map(function(item) {
16
16
  //TODO 此处需要再抽象一层 datagrid/datalist
17
- // @ts-ignore
18
17
  if (item.type === CONTROL_TYPE.SUBTABLE) {
19
18
  // @ts-ignore
20
19
  var children = item.getChildrenFormControl();
21
20
  callback(item, children);
22
21
  } else if (hasChildrenControl(item)) {
23
- // @ts-ignore
24
22
  loopFormControl(item === null || item === void 0 ? void 0 : item.children, callback);
25
- // @ts-ignore
26
23
  } else if (_instanceof(item, RuntimeFormControl)) {
27
24
  callback(item);
28
25
  }
@@ -33,9 +30,7 @@ export function loopDataViewControl(control, // @ts-ignore
33
30
  callback) {
34
31
  if (Array.isArray(control)) {
35
32
  control.map(function(item) {
36
- if (// @ts-ignore
37
- item.type === CONTROL_TYPE.DATA_VIEW || // @ts-ignore
38
- item.type === CONTROL_TYPE.SIMPLE_SEARCH) {
33
+ if (item.type === CONTROL_TYPE.DATA_VIEW || item.type === CONTROL_TYPE.SIMPLE_SEARCH) {
39
34
  callback(item);
40
35
  } else if (hasChildrenControl(item)) {
41
36
  // @ts-ignore