@byteluck-fe/model-driven-engine 2.2.1 → 2.2.2-beta.14

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
  };
@@ -730,6 +738,18 @@ var Engine = /*#__PURE__*/ function(Watcher) {
730
738
  _proto.updateInstanceProps = function updateInstanceProps(instance, props, value, rowIndex) {
731
739
  return this.setInstance(instance, props, value, rowIndex);
732
740
  };
741
+ _proto.getAllRules = function getAllRules(controlId) {
742
+ var rules = this.runtime.allRules;
743
+ if (controlId === undefined) {
744
+ return rules;
745
+ } else {
746
+ var _rules_rules_controlId, _rules_antdRules_controlId;
747
+ return {
748
+ rules: (_rules_rules_controlId = rules.rules[controlId]) === null || _rules_rules_controlId === void 0 ? void 0 : _rules_rules_controlId.fields,
749
+ antdRules: (_rules_antdRules_controlId = rules.antdRules[controlId]) === null || _rules_antdRules_controlId === void 0 ? void 0 : _rules_antdRules_controlId.fields
750
+ };
751
+ }
752
+ };
733
753
  _proto.getRules = function getRules(controlId) {
734
754
  if (controlId === undefined) {
735
755
  return this.runtime.rules;
@@ -879,7 +899,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
879
899
  for(var keyChi1 in item[keyChi]){
880
900
  var _controlIdMapping_key_children_keyChi2;
881
901
  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
- //
902
+ //
883
903
  }
884
904
  }
885
905
  }
@@ -1130,12 +1150,14 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1130
1150
  * @param header 明细表内是否获取表头的控件
1131
1151
  */ _proto.getInstances = function getInstances(controlId) {
1132
1152
  var header = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
1153
+ // const cc = console
1154
+ // const label = '🐑 genInstances ' + controlId + ' ' + Date.now()
1155
+ // cc.time(label)
1133
1156
  if (controlId === undefined) {
1157
+ // cc.timeEnd(label)
1134
1158
  return this.runtime.flatInstances;
1135
1159
  }
1136
- var instances = this.runtime.flatInstances.filter(function(item) {
1137
- return item.id === controlId;
1138
- });
1160
+ var instances = this.runtime.instanceMap[controlId] || [];
1139
1161
  if (header) {
1140
1162
  // 如果能从flatInstances里边取到,就通过getInstanceInSubtableHeader方法取,取不到则换一种方式
1141
1163
  if (instances.length) {
@@ -1191,7 +1213,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1191
1213
  this.schemaEvent("schema-change", {
1192
1214
  instance: _instance,
1193
1215
  props: props,
1194
- value: value
1216
+ value: value,
1217
+ rowIndex: rowIndex
1195
1218
  });
1196
1219
  } catch (e) {
1197
1220
  throw e;
@@ -1335,3 +1358,4 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1335
1358
  return Engine;
1336
1359
  }(Watcher);
1337
1360
  export { Engine };
1361
+ console.log("a");
@@ -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] = [];
@@ -149,6 +146,31 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
149
146
  return this._instanceMap;
150
147
  }
151
148
  },
149
+ {
150
+ key: "allRules",
151
+ get: function get() {
152
+ var antdRules = {};
153
+ var ruleItems = {};
154
+ loopDataViewControl(this._instance, function(dataView) {
155
+ ruleItems[dataView.id] = dataView.rules[0];
156
+ antdRules[dataView.id] = dataView.rules[0];
157
+ loopFormControl(dataView.children, function(item) {
158
+ // if (
159
+ // item instanceof RuntimeFormControl ||
160
+ // item instanceof RuntimeListControl
161
+ // ) {
162
+ if (item.controlType === CONTROL_BASE_TYPE.FORM || item.controlType === CONTROL_BASE_TYPE.LIST) {
163
+ buildControlRules(ruleItems[dataView.id].fields, item);
164
+ buildControlAntdRules(antdRules[dataView.id].fields, item);
165
+ }
166
+ });
167
+ });
168
+ return {
169
+ rules: ruleItems,
170
+ antdRules: antdRules
171
+ };
172
+ }
173
+ },
152
174
  {
153
175
  key: "rules",
154
176
  get: function get() {
@@ -156,7 +178,11 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
156
178
  loopDataViewControl(this._instance, function(dataView) {
157
179
  ruleItems[dataView.id] = dataView.rules[0];
158
180
  loopFormControl(dataView.children, function(item) {
159
- if (_instanceof(item, RuntimeFormControl) || _instanceof(item, RuntimeListControl)) {
181
+ // if (
182
+ // item instanceof RuntimeFormControl ||
183
+ // item instanceof RuntimeListControl
184
+ // ) {
185
+ if (item.controlType === CONTROL_BASE_TYPE.FORM || item.controlType === CONTROL_BASE_TYPE.LIST) {
160
186
  buildControlRules(ruleItems[dataView.id].fields, item);
161
187
  }
162
188
  });
@@ -171,7 +197,11 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
171
197
  loopDataViewControl(this._instance, function(dataView) {
172
198
  antdRules[dataView.id] = dataView.rules[0];
173
199
  loopFormControl(dataView.children, function(item) {
174
- if (_instanceof(item, RuntimeFormControl) || _instanceof(item, RuntimeListControl)) {
200
+ // if (
201
+ // item instanceof RuntimeFormControl ||
202
+ // item instanceof RuntimeListControl
203
+ // ) {
204
+ if (item.controlType === CONTROL_BASE_TYPE.FORM || item.controlType === CONTROL_BASE_TYPE.LIST) {
175
205
  buildControlAntdRules(antdRules[dataView.id].fields, item);
176
206
  }
177
207
  });
@@ -211,7 +241,8 @@ item) {
211
241
  if (getControlIsHide(item)) {
212
242
  return;
213
243
  }
214
- if (_instanceof(item, RuntimeFormControl)) {
244
+ // if (item instanceof RuntimeFormControl) {
245
+ if (item.controlType === CONTROL_BASE_TYPE.FORM) {
215
246
  data[item.id] = item.rules;
216
247
  } else if (item.type === CONTROL_TYPE.SUBTABLE) {
217
248
  data[item.id] = item.rules;
@@ -242,7 +273,8 @@ item) {
242
273
  if (getControlIsHide(item)) {
243
274
  return;
244
275
  }
245
- if (_instanceof(item, RuntimeFormControl)) {
276
+ // if (item instanceof RuntimeFormControl) {
277
+ if (item.controlType === CONTROL_BASE_TYPE.FORM) {
246
278
  antdRules[item.id] = item.rules;
247
279
  } else if (item.type === CONTROL_TYPE.SUBTABLE && item.children.length) {
248
280
  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;
@@ -20,7 +12,8 @@ export function loopFormControl(control, callback) {
20
12
  callback(item, children);
21
13
  } else if (hasChildrenControl(item)) {
22
14
  loopFormControl(item === null || item === void 0 ? void 0 : item.children, callback);
23
- } else if (_instanceof(item, RuntimeFormControl)) {
15
+ // @ts-ignore
16
+ } else if (item.controlType === CONTROL_BASE_TYPE.FORM) {
24
17
  callback(item);
25
18
  }
26
19
  });