@byteluck-fe/model-driven-engine 2.7.0-alpha.0 → 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.
@@ -111,13 +111,6 @@ function _inherits(subClass, superClass) {
111
111
  });
112
112
  if (superClass) _setPrototypeOf(subClass, superClass);
113
113
  }
114
- function _instanceof(left, right) {
115
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
116
- return right[Symbol.hasInstance](left);
117
- } else {
118
- return left instanceof right;
119
- }
120
- }
121
114
  function _iterableToArray(iter) {
122
115
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
123
116
  }
@@ -229,7 +222,7 @@ function _createSuper(Derived) {
229
222
  };
230
223
  }
231
224
  import regeneratorRuntime from "regenerator-runtime";
232
- import { DataBind, ObjectDataBind, RuntimeListControl } from '@byteluck-fe/model-driven-core';
225
+ import { isDataBind } from '@byteluck-fe/model-driven-core';
233
226
  import { CONTROL_BASE_TYPE, CONTROL_TYPE, DEFAULT_LOCALE, error, genNonDuplicateId, isString, JSONCopy, log, RulesMessage, updateValueFromKeys, warn, Watcher } from '@byteluck-fe/model-driven-shared';
234
227
  import { Runtime } from './Runtime';
235
228
  import { Store } from './Store';
@@ -399,7 +392,8 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
399
392
  value: function _handlerArrayUpdate(state, key, type, args, result) {
400
393
  var _this = this;
401
394
  var subtable = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
402
- if (!_instanceof(subtable, RuntimeListControl)) return;
395
+ // if (!(subtable instanceof RuntimeListControl)) return
396
+ if (!(subtable.controlType === CONTROL_BASE_TYPE.LIST)) return;
403
397
  // 新增多行方法
404
398
  var createRows = function(len) {
405
399
  // @ts-ignore
@@ -815,7 +809,8 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
815
809
  }
816
810
  var dataBind1 = dataBindMapping1.dataBind, controlId1 = dataBindMapping1.controlId;
817
811
  var state = this.getState(controlId1, rowIndex);
818
- if (_instanceof(dataBind1, ObjectDataBind)) {
812
+ //if (dataBind instanceof ObjectDataBind) {
813
+ if (!isDataBind(dataBind1)) {
819
814
  return Object.entries(dataBind1).reduce(function(result, param) {
820
815
  var _param = _slicedToArray(param, 2), key = _param[0], dataBind = _param[1];
821
816
  // objectDataBind的元素,跳过下一次赋值
@@ -922,7 +917,8 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
922
917
  return;
923
918
  }
924
919
  var dataBind2 = dataBindMapping.dataBind, controlId = dataBindMapping.controlId;
925
- if (_instanceof(dataBind2, ObjectDataBind)) {
920
+ // if (dataBind instanceof ObjectDataBind) {
921
+ if (!isDataBind(dataBind2)) {
926
922
  var ref;
927
923
  var oldState = (ref = JSONCopy(this.getState(controlId, rowIndex))) !== null && ref !== void 0 ? ref : this.getEmptyState(controlId);
928
924
  // fieldCode不代表是key,所以需要找到对应的key
@@ -964,7 +960,8 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
964
960
  return;
965
961
  }
966
962
  // 对象类型的值
967
- if (_instanceof(dataBind3, ObjectDataBind)) {
963
+ // if (dataBind instanceof ObjectDataBind) {
964
+ if (!isDataBind(dataBind3)) {
968
965
  var ref;
969
966
  var oldState = (ref = JSONCopy(_this.getState(controlId, rowIndex))) !== null && ref !== void 0 ? ref : _this.getEmptyState(controlId);
970
967
  // fieldCode不代表是key,所以需要找到对应的key
@@ -1008,7 +1005,8 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1008
1005
  return;
1009
1006
  }
1010
1007
  // 对象类型的值
1011
- if (_instanceof(dataBind4, ObjectDataBind)) {
1008
+ // if (dataBind instanceof ObjectDataBind) {
1009
+ if (!isDataBind(dataBind4)) {
1012
1010
  var oldState = _this.getEmptyState(controlId);
1013
1011
  // fieldCode不代表是key,所以需要找到对应的key
1014
1012
  result1[item.controlId] = Object.entries(dataBind4).reduce(function(result, param) {
@@ -1049,7 +1047,12 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1049
1047
  if (!newState[mapping.dataViewId]) {
1050
1048
  newState[mapping.dataViewId] = {};
1051
1049
  }
1052
- newState[mapping.dataViewId][mapping.controlId] = [];
1050
+ if (!entity.length) {
1051
+ var _controlId;
1052
+ newState[mapping.dataViewId][mapping.controlId] = (_controlId = newState[mapping.dataViewId][mapping.controlId]) !== null && _controlId !== void 0 ? _controlId : [];
1053
+ } else {
1054
+ newState[mapping.dataViewId][mapping.controlId] = [];
1055
+ }
1053
1056
  entity.map(function(row) {
1054
1057
  var _this = _this4;
1055
1058
  var newRow = JSONCopy(_this4.store.emptyState[mapping.dataViewId][mapping.controlId]);
@@ -1064,9 +1067,11 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1064
1067
  return i.fieldCode === fieldCode;
1065
1068
  });
1066
1069
  if (fieldMapping) {
1067
- if (_instanceof(fieldMapping.dataBind, DataBind) && row[fieldCode] !== undefined) {
1070
+ if (// fieldMapping.dataBind instanceof DataBind &&
1071
+ isDataBind(fieldMapping.dataBind) && row[fieldCode] !== undefined) {
1068
1072
  newRow[fieldMapping.controlId] = row[fieldCode];
1069
- } else if (_instanceof(fieldMapping.dataBind, ObjectDataBind)) {
1073
+ // } else if (fieldMapping.dataBind instanceof ObjectDataBind) {
1074
+ } else if (!isDataBind(fieldMapping.dataBind)) {
1070
1075
  var ref19;
1071
1076
  var objValue = JSONCopy((ref19 = _this.getEmptyState(fieldMapping.controlId)) !== null && ref19 !== void 0 ? ref19 : {});
1072
1077
  Object.keys(fieldMapping.dataBind).map(function(key) {
@@ -1100,9 +1105,11 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1100
1105
  if (!newState[mapping.dataViewId[0]]) {
1101
1106
  newState[mapping.dataViewId[0]] = {};
1102
1107
  }
1103
- if (_instanceof(mapping.dataBind, DataBind) && entity[fieldCode] !== undefined) {
1108
+ if (// mapping.dataBind instanceof DataBind &&
1109
+ isDataBind(mapping.dataBind) && entity[fieldCode] !== undefined) {
1104
1110
  newState[mapping.dataViewId[0]][mapping.controlId] = entity[fieldCode] !== undefined ? entity[fieldCode] : emptyState[mapping.dataViewId[0]][mapping.controlId];
1105
- } else if (_instanceof(mapping.dataBind, ObjectDataBind)) {
1111
+ // } else if (mapping.dataBind instanceof ObjectDataBind) {
1112
+ } else if (!isDataBind(mapping.dataBind)) {
1106
1113
  var ref;
1107
1114
  var objValue = (ref = _this3.getEmptyState(mapping.controlId)) !== null && ref !== void 0 ? ref : {};
1108
1115
  Object.keys(mapping.dataBind).map(function(key) {
@@ -1195,6 +1202,7 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1195
1202
  // 如果能从flatInstances里边取到,就通过getInstanceInSubtableHeader方法取,取不到则换一种方式
1196
1203
  if (instances.length) {
1197
1204
  var instance = instances[0];
1205
+ // if (this.inList(instance.id) === true) {
1198
1206
  if (this.inList(instance.id) !== undefined) {
1199
1207
  var headerInstance = this.getInstanceInSubtableHeader(instance);
1200
1208
  if (headerInstance) {
@@ -1367,7 +1375,27 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1367
1375
  },
1368
1376
  {
1369
1377
  key: "getInstanceParentControl",
1370
- value: function getInstanceParentControl(instance, controlType) {
1378
+ value: // public getInstanceRowIndex(
1379
+ // instance: ControlRuntimeInstance<ControlsKeys> | RuntimeControl
1380
+ // ) {
1381
+ // let rowIndex: number | undefined
1382
+ // // @ts-ignore
1383
+ // if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE_COLUMN)) {
1384
+ // rowIndex = -1
1385
+ // }else{
1386
+ // const instanceList = this.runtime.instanceMap[instance.id]
1387
+ // if(Object.prototype.toString.call(instanceList) === '[object Array]'){
1388
+ // const index = instanceList.findIndex(
1389
+ // (item: any) => item === instance
1390
+ // )
1391
+ // if (index > -1) {
1392
+ // rowIndex = index
1393
+ // }
1394
+ // }
1395
+ // }
1396
+ // return rowIndex
1397
+ // }
1398
+ function getInstanceParentControl(instance, controlType) {
1371
1399
  if (!instance.parent) {
1372
1400
  return;
1373
1401
  }
@@ -219,8 +219,12 @@ function loop(control, callback) {
219
219
  control.map(function(item) {
220
220
  callback(item);
221
221
  if (hasChildrenControl(item)) {
222
+ var ctl = item;
223
+ if (!ctl.children) {
224
+ ctl.children = [];
225
+ }
222
226
  // @ts-ignore
223
- loop(item.children, callback);
227
+ loop(ctl.children, callback);
224
228
  }
225
229
  });
226
230
  } else {
@@ -30,13 +30,6 @@ function _defineProperty(obj, key, value) {
30
30
  }
31
31
  return obj;
32
32
  }
33
- function _instanceof(left, right) {
34
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
35
- return right[Symbol.hasInstance](left);
36
- } else {
37
- return left instanceof right;
38
- }
39
- }
40
33
  function _objectSpread(target) {
41
34
  for(var i = 1; i < arguments.length; i++){
42
35
  var source = arguments[i] != null ? arguments[i] : {};
@@ -52,7 +45,7 @@ function _objectSpread(target) {
52
45
  }
53
46
  return target;
54
47
  }
55
- import { DataBind, ObjectDataBind } from '@byteluck-fe/model-driven-core';
48
+ import { DataBind, isDataBind } from '@byteluck-fe/model-driven-core';
56
49
  import { loopFormSchema, JSONCopy, warn, CONTROL_TYPE, CONTROL_BASE_TYPE } from '@byteluck-fe/model-driven-shared';
57
50
  import { loopDataViewControl, loopFormControl, buildUUID } from '../utils/runtimeUtils';
58
51
  var Store = /*#__PURE__*/ function() {
@@ -97,7 +90,9 @@ var Store = /*#__PURE__*/ function() {
97
90
  var _this1 = _this;
98
91
  Object.keys(children).map(function(childControlId) {
99
92
  if (childControlId === controlId) {
100
- _this1.state[dataView][subtableId][rowIndex][controlId] = value;
93
+ if (_this1.state[dataView][subtableId][rowIndex]) {
94
+ _this1.state[dataView][subtableId][rowIndex][controlId] = value;
95
+ }
101
96
  }
102
97
  });
103
98
  }
@@ -270,12 +265,12 @@ item) {
270
265
  loopFormSchema(item.props.headers, function(headerItem) {
271
266
  emptyTemplate[headerItem.id] = JSONCopy(headerItem.props.defaultValue);
272
267
  });
273
- var _defaultRows;
274
- dataViewState[item.id] = new Array((_defaultRows = item.props.defaultRows) !== null && _defaultRows !== void 0 ? _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() {
275
270
  return _objectSpread({
276
271
  uid: 'new:' + buildUUID('uid')
277
272
  }, JSONCopy(emptyTemplate));
278
- });
273
+ })) !== null && ref !== void 0 ? ref : [];
279
274
  emptyDataViewState[item.id] = emptyTemplate;
280
275
  }
281
276
  }
@@ -284,7 +279,8 @@ item1) {
284
279
  // if (item instanceof RuntimeFormControl) {
285
280
  if (item1.controlType === CONTROL_BASE_TYPE.FORM) {
286
281
  var ref, ref1;
287
- if (_instanceof(item1.props.dataBind, ObjectDataBind)) {
282
+ // if (item.props.dataBind instanceof ObjectDataBind) {
283
+ if (!isDataBind(item1.props.dataBind)) {
288
284
  // 特殊的dataBind,比如:金额是currency+amount两个key组成的,日期区间,继承自ObjectDataBind的需要通过Object.keys拿到多个databind
289
285
  Object.keys(item1.props.dataBind).map(function(key) {
290
286
  var dataBind = item1.props.dataBind;
@@ -339,7 +335,8 @@ item1) {
339
335
  };
340
336
  var subtableId = item1.id;
341
337
  loopFormSchema(item1.props.headers, function(item) {
342
- if (_instanceof(item.props.dataBind, ObjectDataBind)) {
338
+ // if (item.props.dataBind instanceof ObjectDataBind) {
339
+ if (!isDataBind(item.props.dataBind)) {
343
340
  Object.keys(item.props.dataBind).map(function(key) {
344
341
  var dataBind = item.props.dataBind;
345
342
  var dataCode = dataBind[key].dataCode;
@@ -63,13 +63,6 @@ function _inherits(subClass, superClass) {
63
63
  });
64
64
  if (superClass) _setPrototypeOf(subClass, superClass);
65
65
  }
66
- function _instanceof(left, right) {
67
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
68
- return right[Symbol.hasInstance](left);
69
- } else {
70
- return left instanceof right;
71
- }
72
- }
73
66
  function _iterableToArrayLimit(arr, i) {
74
67
  var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
75
68
  if (_i == null) return;
@@ -344,7 +337,8 @@ var MoneyValueChecker = /*#__PURE__*/ function(ValueChecker) {
344
337
  {
345
338
  key: "validate",
346
339
  value: function validate(value) {
347
- return _instanceof(value, AmountValue) || isPlainObject(value) && 'amount' in value && isNumber(value.amount) && 'currency' in value && isString(value.currency);
340
+ return(// value instanceof AmountValue ||
341
+ (isPlainObject(value) && 'amount' in value && isNumber(value.amount) && 'currency' in value && isString(value.currency)));
348
342
  }
349
343
  },
350
344
  {
@@ -394,7 +388,8 @@ var TimeScopeValueChecker = /*#__PURE__*/ function(ValueChecker) {
394
388
  {
395
389
  key: "validate",
396
390
  value: function validate(value) {
397
- return _instanceof(value, RangeDateValue) || isPlainObject(value) && 'min' in value && isString(value.min) && 'max' in value && isString(value.max);
391
+ return(// value instanceof RangeDateValue ||
392
+ (isPlainObject(value) && 'min' in value && isString(value.min) && 'max' in value && isString(value.max)));
398
393
  }
399
394
  },
400
395
  {
@@ -441,7 +436,8 @@ var CalcValueChecker = /*#__PURE__*/ function(ValueChecker) {
441
436
  {
442
437
  key: "validate",
443
438
  value: function validate(value) {
444
- return _instanceof(value, CalcValue) || isPlainObject(value) && 'result' in value && isNumber(value.result) && 'unit' in value && isString(value.unit);
439
+ return(// value instanceof CalcValue ||
440
+ (isPlainObject(value) && 'result' in value && isNumber(value.result) && 'unit' in value && isString(value.unit)));
445
441
  }
446
442
  },
447
443
  {
@@ -491,7 +487,18 @@ var AddressValueChecker = /*#__PURE__*/ function(ValueChecker) {
491
487
  {
492
488
  key: "validate",
493
489
  value: function validate(value) {
494
- return _instanceof(value, AddressValue);
490
+ // return value instanceof AddressValue
491
+ if (isPlainObject(value)) {
492
+ // city?: string;
493
+ // cityDisplay?: string;
494
+ // district?: string;
495
+ // districtDisplay?: string;
496
+ // province?: string;
497
+ // provinceDisplay?: string
498
+ return true;
499
+ } else {
500
+ return false;
501
+ }
495
502
  }
496
503
  },
497
504
  {
@@ -8,7 +8,8 @@ export function loopFormControl(control, callback) {
8
8
  //TODO 此处需要再抽象一层 datagrid/datalist
9
9
  if (item.type === CONTROL_TYPE.SUBTABLE) {
10
10
  // @ts-ignore
11
- var children = item.getChildrenFormControl();
11
+ var children = []//item.getChildrenFormControl() as RuntimeFormControl[]
12
+ ;
12
13
  callback(item, children);
13
14
  } else if (hasChildrenControl(item)) {
14
15
  var ref;