@byteluck-fe/model-driven-engine 2.2.1-test.1 → 2.2.2-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";
@@ -444,7 +444,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
444
444
  // @ts-ignore
445
445
  var fieldTypeMap = instance.props.headers.reduce(function(result, column) {
446
446
  var formInstance = column.children[0];
447
- if (formInstance && _instanceof(formInstance, RuntimeFormControl)) {
447
+ // if (formInstance && formInstance instanceof RuntimeFormControl) {
448
+ if (formInstance && formInstance.controlType === CONTROL_BASE_TYPE.FORM) {
448
449
  result[formInstance.id] = formInstance.fieldType;
449
450
  }
450
451
  return result;
@@ -556,7 +557,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
556
557
  options: Object.assign({}, options, {
557
558
  changed: createdNewRows,
558
559
  data: createdNewRowsData,
559
- deleted: deleted !== null && deleted !== void 0 ? deleted : []
560
+ deleted: deleted !== null && deleted !== void 0 ? deleted : [],
561
+ jsonValue: JSON.stringify(this.getState(subtable.id))
560
562
  })
561
563
  });
562
564
  // 主动清空本次任务中的options
@@ -570,7 +572,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
570
572
  }
571
573
  var index = this.getInstanceRowIndex(instance);
572
574
  var options = eventOptionsTemp || {};
573
- if (_instanceof(instance, RuntimeListControl)) {
575
+ // if (instance instanceof RuntimeListControl) {
576
+ if (instance.controlType === CONTROL_BASE_TYPE.LIST) {
574
577
  var // @ts-ignore
575
578
  _instance_children;
576
579
  instance.children.length = 0;
@@ -628,12 +631,15 @@ var Engine = /*#__PURE__*/ function(Watcher) {
628
631
  _proto.listControlCreateRow = function listControlCreateRow(instance, rowType) {
629
632
  var row = this.runtime.createControlInstance(rowType);
630
633
  if (!row) return;
631
- if (_instanceof(row, RuntimeLayoutControl)) {
632
- 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;
633
639
  var template = JSONCopy(instance.props.headers);
634
640
  // @ts-ignore
635
641
  var columns = this.createControl(template);
636
- (_row_children = row.children).push.apply(_row_children, _toConsumableArray(columns));
642
+ (_inst_children = inst.children).push.apply(_inst_children, _toConsumableArray(columns));
637
643
  }
638
644
  return row;
639
645
  };
@@ -732,6 +738,18 @@ var Engine = /*#__PURE__*/ function(Watcher) {
732
738
  _proto.updateInstanceProps = function updateInstanceProps(instance, props, value, rowIndex) {
733
739
  return this.setInstance(instance, props, value, rowIndex);
734
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
+ };
735
753
  _proto.getRules = function getRules(controlId) {
736
754
  if (controlId === undefined) {
737
755
  return this.runtime.rules;
@@ -1132,7 +1150,11 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1132
1150
  * @param header 明细表内是否获取表头的控件
1133
1151
  */ _proto.getInstances = function getInstances(controlId) {
1134
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)
1135
1156
  if (controlId === undefined) {
1157
+ // cc.timeEnd(label)
1136
1158
  return this.runtime.flatInstances;
1137
1159
  }
1138
1160
  var instances = this.runtime.instanceMap[controlId] || [];
@@ -1336,3 +1358,4 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1336
1358
  return Engine;
1337
1359
  }(Watcher);
1338
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,8 +107,8 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
114
107
  var instances = [];
115
108
  var instanceMap = {};
116
109
  loop(this._instance, function(item) {
117
- // 3.4.1 避免将subtable-row 放到 _flatInstances 中
118
- if (item.type === "subtable-row") {
110
+ // 3.4.1 避免将 subtable-column 放到 _flatInstances 中
111
+ if (item.type === "subtable-column") {
119
112
  return;
120
113
  }
121
114
  instances.push(item);
@@ -153,6 +146,31 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
153
146
  return this._instanceMap;
154
147
  }
155
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
+ },
156
174
  {
157
175
  key: "rules",
158
176
  get: function get() {
@@ -160,7 +178,11 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
160
178
  loopDataViewControl(this._instance, function(dataView) {
161
179
  ruleItems[dataView.id] = dataView.rules[0];
162
180
  loopFormControl(dataView.children, function(item) {
163
- 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) {
164
186
  buildControlRules(ruleItems[dataView.id].fields, item);
165
187
  }
166
188
  });
@@ -175,7 +197,11 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
175
197
  loopDataViewControl(this._instance, function(dataView) {
176
198
  antdRules[dataView.id] = dataView.rules[0];
177
199
  loopFormControl(dataView.children, function(item) {
178
- 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) {
179
205
  buildControlAntdRules(antdRules[dataView.id].fields, item);
180
206
  }
181
207
  });
@@ -215,7 +241,8 @@ item) {
215
241
  if (getControlIsHide(item)) {
216
242
  return;
217
243
  }
218
- if (_instanceof(item, RuntimeFormControl)) {
244
+ // if (item instanceof RuntimeFormControl) {
245
+ if (item.controlType === CONTROL_BASE_TYPE.FORM) {
219
246
  data[item.id] = item.rules;
220
247
  } else if (item.type === CONTROL_TYPE.SUBTABLE) {
221
248
  data[item.id] = item.rules;
@@ -246,7 +273,8 @@ item) {
246
273
  if (getControlIsHide(item)) {
247
274
  return;
248
275
  }
249
- if (_instanceof(item, RuntimeFormControl)) {
276
+ // if (item instanceof RuntimeFormControl) {
277
+ if (item.controlType === CONTROL_BASE_TYPE.FORM) {
250
278
  antdRules[item.id] = item.rules;
251
279
  } else if (item.type === CONTROL_TYPE.SUBTABLE && item.children.length) {
252
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,7 @@ 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
+ import { CONTROL_BASE_TYPE, error, logerror } from "@byteluck-fe/model-driven-shared";
35
27
  var cc = console;
36
28
  var proxyArrayApi = [
37
29
  "splice",
@@ -248,7 +240,7 @@ function flatInstanceForChildren(controls) {
248
240
  return item.id === key;
249
241
  });
250
242
  // 最后一个key可能是值对象上边的key,比如金额的amount和currency,计算公式的result和unit,所以需要判断前一个控件是不是一个表单控件,是的话就返回最后一个表单控件
251
- return findEndItem ? findEndItem : _instanceof(prevItem, RuntimeFormControl) ? prevItem : undefined;
243
+ return findEndItem ? findEndItem : prevItem.controlType === CONTROL_BASE_TYPE.FORM ? prevItem : undefined;
252
244
  } else {
253
245
  var _prevItem_children;
254
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
  });