@byteluck-fe/model-driven-engine 2.2.0 → 2.2.1-beta.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.
@@ -333,8 +333,8 @@ var __generator = this && this.__generator || function(thisArg, body) {
333
333
  };
334
334
  }
335
335
  };
336
- import { DataBind, ObjectDataBind, RuntimeFormControl, RuntimeLayoutControl, RuntimeListControl } from "@byteluck-fe/model-driven-core";
337
- import { CONTROL_TYPE, DEFAULT_LOCALE, error, genNonDuplicateId, isString, JSONCopy, log, RulesMessage, updateValueFromKeys, warn, Watcher } from "@byteluck-fe/model-driven-shared";
336
+ import { DataBind, ObjectDataBind, RuntimeListControl } from "@byteluck-fe/model-driven-core";
337
+ import { CONTROL_BASE_TYPE, CONTROL_TYPE, DEFAULT_LOCALE, error, genNonDuplicateId, isString, JSONCopy, log, RulesMessage, updateValueFromKeys, warn, Watcher } from "@byteluck-fe/model-driven-shared";
338
338
  import { Runtime } from "./Runtime";
339
339
  import { Store } from "./Store";
340
340
  import { findItem, proxyState } from "./proxyState";
@@ -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,28 +431,30 @@ 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];
444
- if (formInstance && _instanceof(formInstance, RuntimeFormControl)) {
447
+ // if (formInstance && formInstance instanceof RuntimeFormControl) {
448
+ if (formInstance && formInstance.controlType === CONTROL_BASE_TYPE.FORM) {
445
449
  result[formInstance.id] = formInstance.fieldType;
446
450
  }
447
451
  return result;
448
452
  }, {});
449
- if (newValue === null) {
450
- return [];
451
- }
453
+ // @ts-ignore
454
+ var emptyState = this.getEmptyState(instance.id);
452
455
  return newValue.map(function(row) {
453
456
  return(// @ts-ignore
454
- checkerSubtableValue(fieldTypeMap, row, _this.getEmptyState(instance.id)));
457
+ checkerSubtableValue(fieldTypeMap, row, emptyState));
455
458
  });
456
459
  }
457
460
  var keys = key.split(".");
@@ -472,7 +475,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
472
475
  };
473
476
  _proto._handlerArrayUpdate = function _handlerArrayUpdate(state, key, type, args, result) {
474
477
  var _this = this;
475
- var subtable = findItem(this.runtime.flatInstances, key);
478
+ var subtable = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
476
479
  if (!_instanceof(subtable, RuntimeListControl)) return;
477
480
  // 新增多行方法
478
481
  var createRows = function(len) {
@@ -554,7 +557,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
554
557
  options: Object.assign({}, options, {
555
558
  changed: createdNewRows,
556
559
  data: createdNewRowsData,
557
- deleted: deleted !== null && deleted !== void 0 ? deleted : []
560
+ deleted: deleted !== null && deleted !== void 0 ? deleted : [],
561
+ jsonValue: JSON.stringify(this.getState(subtable.id))
558
562
  })
559
563
  });
560
564
  // 主动清空本次任务中的options
@@ -562,13 +566,14 @@ var Engine = /*#__PURE__*/ function(Watcher) {
562
566
  }
563
567
  };
564
568
  _proto._handlerObjectUpdate = function _handlerObjectUpdate(state, key, value, oldValue) {
565
- var instance = findItem(this.runtime.flatInstances, key);
569
+ var instance = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
566
570
  if (!instance) {
567
571
  return;
568
572
  }
569
573
  var index = this.getInstanceRowIndex(instance);
570
574
  var options = eventOptionsTemp || {};
571
- if (_instanceof(instance, RuntimeListControl)) {
575
+ // if (instance instanceof RuntimeListControl) {
576
+ if (instance.controlType === CONTROL_BASE_TYPE.LIST) {
572
577
  var // @ts-ignore
573
578
  _instance_children;
574
579
  instance.children.length = 0;
@@ -626,12 +631,15 @@ var Engine = /*#__PURE__*/ function(Watcher) {
626
631
  _proto.listControlCreateRow = function listControlCreateRow(instance, rowType) {
627
632
  var row = this.runtime.createControlInstance(rowType);
628
633
  if (!row) return;
629
- if (_instanceof(row, RuntimeLayoutControl)) {
630
- var _row_children;
634
+ // if (row instanceof RuntimeLayoutControl) {
635
+ // @ts-ignore
636
+ if (row.controlType === CONTROL_BASE_TYPE.LAYOUT) {
637
+ var _inst_children;
638
+ var inst = row;
631
639
  var template = JSONCopy(instance.props.headers);
632
640
  // @ts-ignore
633
641
  var columns = this.createControl(template);
634
- (_row_children = row.children).push.apply(_row_children, _toConsumableArray(columns));
642
+ (_inst_children = inst.children).push.apply(_inst_children, _toConsumableArray(columns));
635
643
  }
636
644
  return row;
637
645
  };
@@ -879,7 +887,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
879
887
  for(var keyChi1 in item[keyChi]){
880
888
  var _controlIdMapping_key_children_keyChi2;
881
889
  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
- //
890
+ //
883
891
  }
884
892
  }
885
893
  }
@@ -1133,15 +1141,12 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1133
1141
  if (controlId === undefined) {
1134
1142
  return this.runtime.flatInstances;
1135
1143
  }
1136
- var instances = this.runtime.flatInstances.filter(// @ts-ignore
1137
- function(item) {
1138
- return item.id === controlId;
1139
- });
1144
+ var instances = this.runtime.instanceMap[controlId] || [];
1140
1145
  if (header) {
1141
1146
  // 如果能从flatInstances里边取到,就通过getInstanceInSubtableHeader方法取,取不到则换一种方式
1142
1147
  if (instances.length) {
1143
1148
  var instance = instances[0];
1144
- if (this.getInstanceRowIndex(instance) !== undefined) {
1149
+ if (this.inList(instance.id) === true) {
1145
1150
  var headerInstance = this.getInstanceInSubtableHeader(instance);
1146
1151
  if (headerInstance) {
1147
1152
  instances.unshift(headerInstance);
@@ -1173,6 +1178,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1173
1178
  }
1174
1179
  }
1175
1180
  }
1181
+ // @ts-ignore
1176
1182
  return instances;
1177
1183
  };
1178
1184
  _proto.setInstance = function setInstance(instance, props, value, rowIndex) {
@@ -1191,7 +1197,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1191
1197
  this.schemaEvent("schema-change", {
1192
1198
  instance: _instance,
1193
1199
  props: props,
1194
- value: value
1200
+ value: value,
1201
+ rowIndex: rowIndex
1195
1202
  });
1196
1203
  } catch (e) {
1197
1204
  throw e;
@@ -1313,6 +1320,14 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1313
1320
  _proto.getControlConfig = function getControlConfig(control) {
1314
1321
  return this.runtime.getControlConfig(control);
1315
1322
  };
1323
+ _proto.inList = function inList(controlId) {
1324
+ var mapping = this.store.controlIdMapping;
1325
+ var result = Object.keys(mapping).some(function(key) {
1326
+ var _mapping_key, _mapping_key_children;
1327
+ 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);
1328
+ });
1329
+ return result;
1330
+ };
1316
1331
  // 注册外部控件
1317
1332
  Engine.register = function register() {
1318
1333
  for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
@@ -42,13 +42,6 @@ function _inherits(subClass, superClass) {
42
42
  });
43
43
  if (superClass) _setPrototypeOf(subClass, superClass);
44
44
  }
45
- function _instanceof(left, right) {
46
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
47
- return !!right[Symbol.hasInstance](left);
48
- } else {
49
- return left instanceof right;
50
- }
51
- }
52
45
  function _possibleConstructorReturn(self, call) {
53
46
  if (call && (_typeof(call) === "object" || typeof call === "function")) {
54
47
  return call;
@@ -90,8 +83,8 @@ function _createSuper(Derived) {
90
83
  return _possibleConstructorReturn(this, result);
91
84
  };
92
85
  }
93
- import { RuntimeFormControl, RuntimeListControl, RegisterControls } from "@byteluck-fe/model-driven-core";
94
- import { CONTROL_TYPE, loopFormSchema } from "@byteluck-fe/model-driven-shared";
86
+ import { RegisterControls } from "@byteluck-fe/model-driven-core";
87
+ import { CONTROL_BASE_TYPE, CONTROL_TYPE, loopFormSchema } from "@byteluck-fe/model-driven-shared";
95
88
  import { hasChildrenControl, loopDataViewControl, loopFormControl } from "../utils/runtimeUtils";
96
89
  export var Runtime = /*#__PURE__*/ function(RegisterControls) {
97
90
  "use strict";
@@ -114,6 +107,10 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
114
107
  var instances = [];
115
108
  var instanceMap = {};
116
109
  loop(this._instance, function(item) {
110
+ // 3.4.1 避免将subtable-row 放到 _flatInstances 中
111
+ if (item.type === "subtable-row" || item.type === "subtable-column") {
112
+ return;
113
+ }
117
114
  instances.push(item);
118
115
  if (!instanceMap[item.id]) {
119
116
  instanceMap[item.id] = [];
@@ -156,7 +153,11 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
156
153
  loopDataViewControl(this._instance, function(dataView) {
157
154
  ruleItems[dataView.id] = dataView.rules[0];
158
155
  loopFormControl(dataView.children, function(item) {
159
- if (_instanceof(item, RuntimeFormControl) || _instanceof(item, RuntimeListControl)) {
156
+ // if (
157
+ // item instanceof RuntimeFormControl ||
158
+ // item instanceof RuntimeListControl
159
+ // ) {
160
+ if (item.controlType === CONTROL_BASE_TYPE.FORM || item.controlType === CONTROL_BASE_TYPE.LIST) {
160
161
  buildControlRules(ruleItems[dataView.id].fields, item);
161
162
  }
162
163
  });
@@ -171,7 +172,11 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
171
172
  loopDataViewControl(this._instance, function(dataView) {
172
173
  antdRules[dataView.id] = dataView.rules[0];
173
174
  loopFormControl(dataView.children, function(item) {
174
- if (_instanceof(item, RuntimeFormControl) || _instanceof(item, RuntimeListControl)) {
175
+ // if (
176
+ // item instanceof RuntimeFormControl ||
177
+ // item instanceof RuntimeListControl
178
+ // ) {
179
+ if (item.controlType === CONTROL_BASE_TYPE.FORM || item.controlType === CONTROL_BASE_TYPE.LIST) {
175
180
  buildControlAntdRules(antdRules[dataView.id].fields, item);
176
181
  }
177
182
  });
@@ -211,7 +216,8 @@ item) {
211
216
  if (getControlIsHide(item)) {
212
217
  return;
213
218
  }
214
- if (_instanceof(item, RuntimeFormControl)) {
219
+ // if (item instanceof RuntimeFormControl) {
220
+ if (item.controlType === CONTROL_BASE_TYPE.FORM) {
215
221
  data[item.id] = item.rules;
216
222
  } else if (item.type === CONTROL_TYPE.SUBTABLE) {
217
223
  data[item.id] = item.rules;
@@ -242,7 +248,8 @@ item) {
242
248
  if (getControlIsHide(item)) {
243
249
  return;
244
250
  }
245
- if (_instanceof(item, RuntimeFormControl)) {
251
+ // if (item instanceof RuntimeFormControl) {
252
+ if (item.controlType === CONTROL_BASE_TYPE.FORM) {
246
253
  antdRules[item.id] = item.rules;
247
254
  } else if (item.type === CONTROL_TYPE.SUBTABLE && item.children.length) {
248
255
  antdRules[item.id] = [];
@@ -23,8 +23,8 @@ function _instanceof(left, right) {
23
23
  return left instanceof right;
24
24
  }
25
25
  }
26
- import { RuntimeFormControl, DataBind, ObjectDataBind } from "@byteluck-fe/model-driven-core";
27
- import { loopFormSchema, JSONCopy, warn, CONTROL_TYPE } from "@byteluck-fe/model-driven-shared";
26
+ import { DataBind, ObjectDataBind } from "@byteluck-fe/model-driven-core";
27
+ import { loopFormSchema, JSONCopy, warn, CONTROL_TYPE, CONTROL_BASE_TYPE } from "@byteluck-fe/model-driven-shared";
28
28
  import { loopDataViewControl, loopFormControl } from "../utils/runtimeUtils";
29
29
  var Store = /*#__PURE__*/ function() {
30
30
  "use strict";
@@ -202,7 +202,8 @@ function init(instance) {
202
202
  }
203
203
  function buildState(dataViewState, emptyDataViewState, // @ts-ignore
204
204
  item) {
205
- if (_instanceof(item, RuntimeFormControl)) {
205
+ //if (item instanceof RuntimeFormControl) {
206
+ if (item.controlType === CONTROL_BASE_TYPE.FORM) {
206
207
  dataViewState[item.id] = JSONCopy(item.props.defaultValue);
207
208
  emptyDataViewState[item.id] = JSONCopy(item.props.defaultValue);
208
209
  } else {
@@ -219,7 +220,8 @@ item) {
219
220
  }
220
221
  function buildDataBindMapping(data, dataViewId, // @ts-ignore
221
222
  item) {
222
- if (_instanceof(item, RuntimeFormControl)) {
223
+ // if (item instanceof RuntimeFormControl) {
224
+ if (item.controlType === CONTROL_BASE_TYPE.FORM) {
223
225
  if (_instanceof(item.props.dataBind, ObjectDataBind)) {
224
226
  // 特殊的dataBind,比如:金额是currency+amount两个key组成的,日期区间,继承自ObjectDataBind的需要通过Object.keys拿到多个databind
225
227
  Object.keys(item.props.dataBind).map(function(key) {
@@ -303,7 +305,8 @@ item) {
303
305
  }
304
306
  function buildControlIdMapping(data, dataViewId, // @ts-ignore
305
307
  item) {
306
- if (_instanceof(item, RuntimeFormControl)) {
308
+ // if (item instanceof RuntimeFormControl) {
309
+ if (item.controlType === CONTROL_BASE_TYPE.FORM) {
307
310
  data[item.id] = {
308
311
  dataBind: item.props.dataBind,
309
312
  options: [],
@@ -6,13 +6,6 @@ function _arrayLikeToArray(arr, len) {
6
6
  function _arrayWithoutHoles(arr) {
7
7
  if (Array.isArray(arr)) return _arrayLikeToArray(arr);
8
8
  }
9
- function _instanceof(left, right) {
10
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
11
- return !!right[Symbol.hasInstance](left);
12
- } else {
13
- return left instanceof right;
14
- }
15
- }
16
9
  function _iterableToArray(iter) {
17
10
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
18
11
  }
@@ -30,8 +23,8 @@ function _unsupportedIterableToArray(o, minLen) {
30
23
  if (n === "Map" || n === "Set") return Array.from(n);
31
24
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
32
25
  }
33
- import { RuntimeFormControl } from "@byteluck-fe/model-driven-core";
34
- import { error, logerror } from "@byteluck-fe/model-driven-shared";
26
+ var cc = console;
27
+ import { CONTROL_BASE_TYPE, error, logerror } from "@byteluck-fe/model-driven-shared";
35
28
  var proxyArrayApi = [
36
29
  "splice",
37
30
  "push",
@@ -221,27 +214,33 @@ function flatInstanceForChildren(controls) {
221
214
  * 在flatInstance中通过key查找出对应的instance
222
215
  * @param flatInstance 拍平的instance数组
223
216
  * @param key 操作的数据在state的key - 可以是深层次的 subtable.0.input等
224
- * */ export function findItem(flatInstance, key) {
217
+ * */ export function findItem(flatInstance, key, instanceMap) {
225
218
  if (key === "") return undefined;
226
219
  var keys = key.split(".");
227
220
  if (keys.length === 0) return undefined;
228
221
  var oneKey = keys[0];
229
222
  var otherKeys = keys.slice(1);
230
- var initInstance = flatInstance.find(function(item) {
231
- return item.id === oneKey;
232
- });
223
+ // 3.4.1 优化速度,读取instanceMap
224
+ // cc.time('findItem flatInstance find')
225
+ // const initInstance = flatInstance.find((item) => item.id === oneKey)
226
+ // cc.log('🏠 findItem flatInstance find result', initInstance)
227
+ // cc.timeEnd('findItem flatInstance find')
228
+ // cc.time('findItem instanceMap match')
229
+ var initInstance = instanceMap[oneKey] ? instanceMap[oneKey][0] : undefined;
230
+ // cc.log('🏠 findItem instanceMap match result', initInstance)
231
+ // cc.timeEnd('findItem instanceMap match')
233
232
  if (otherKeys.length === 0) return initInstance;
234
233
  // @ts-ignore
235
234
  return otherKeys.reduce(function(prevItem, key) {
236
235
  var index = Number(key);
237
236
  var isNotIndex = Number.isNaN(index);
238
- if (isNotIndex) {
237
+ if (isNotIndex && prevItem) {
239
238
  var flatChildren = (prevItem === null || prevItem === void 0 ? void 0 : prevItem.children) ? flatInstanceForChildren(prevItem.children) : undefined;
240
239
  var findEndItem = flatChildren === null || flatChildren === void 0 ? void 0 : flatChildren.find(function(item) {
241
240
  return item.id === key;
242
241
  });
243
242
  // 最后一个key可能是值对象上边的key,比如金额的amount和currency,计算公式的result和unit,所以需要判断前一个控件是不是一个表单控件,是的话就返回最后一个表单控件
244
- return findEndItem ? findEndItem : _instanceof(prevItem, RuntimeFormControl) ? prevItem : undefined;
243
+ return findEndItem ? findEndItem : prevItem.controlType === CONTROL_BASE_TYPE.FORM ? prevItem : undefined;
245
244
  } else {
246
245
  var _prevItem_children;
247
246
  var _prevItem_children_index;
@@ -1,11 +1,3 @@
1
- function _instanceof(left, right) {
2
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
3
- return !!right[Symbol.hasInstance](left);
4
- } else {
5
- return left instanceof right;
6
- }
7
- }
8
- import { RuntimeFormControl } from "@byteluck-fe/model-driven-core";
9
1
  import { CONTROL_BASE_TYPE, CONTROL_TYPE } from "@byteluck-fe/model-driven-shared";
10
2
  export function hasChildrenControl(instance) {
11
3
  return instance.controlType === CONTROL_BASE_TYPE.LAYOUT || instance.controlType === CONTROL_BASE_TYPE.WRAP || instance.controlType === CONTROL_BASE_TYPE.LIST || instance.controlType === CONTROL_BASE_TYPE.SEARCH;
@@ -14,16 +6,13 @@ export function loopFormControl(control, callback) {
14
6
  if (Array.isArray(control)) {
15
7
  control.map(function(item) {
16
8
  //TODO 此处需要再抽象一层 datagrid/datalist
17
- // @ts-ignore
18
9
  if (item.type === CONTROL_TYPE.SUBTABLE) {
19
10
  // @ts-ignore
20
11
  var children = item.getChildrenFormControl();
21
12
  callback(item, children);
22
13
  } else if (hasChildrenControl(item)) {
23
- // @ts-ignore
24
14
  loopFormControl(item === null || item === void 0 ? void 0 : item.children, callback);
25
- // @ts-ignore
26
- } else if (_instanceof(item, RuntimeFormControl)) {
15
+ } else if (item.controlType === CONTROL_BASE_TYPE.FORM) {
27
16
  callback(item);
28
17
  }
29
18
  });
@@ -33,9 +22,7 @@ export function loopDataViewControl(control, // @ts-ignore
33
22
  callback) {
34
23
  if (Array.isArray(control)) {
35
24
  control.map(function(item) {
36
- if (// @ts-ignore
37
- item.type === CONTROL_TYPE.DATA_VIEW || // @ts-ignore
38
- item.type === CONTROL_TYPE.SIMPLE_SEARCH) {
25
+ if (item.type === CONTROL_TYPE.DATA_VIEW || item.type === CONTROL_TYPE.SIMPLE_SEARCH) {
39
26
  callback(item);
40
27
  } else if (hasChildrenControl(item)) {
41
28
  // @ts-ignore