@byteluck-fe/model-driven-engine 2.1.0-sourcemap.9 → 2.2.1-beta.1

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;
@@ -443,7 +444,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
443
444
  // @ts-ignore
444
445
  var fieldTypeMap = instance.props.headers.reduce(function(result, column) {
445
446
  var formInstance = column.children[0];
446
- if (formInstance && _instanceof(formInstance, RuntimeFormControl)) {
447
+ // if (formInstance && formInstance instanceof RuntimeFormControl) {
448
+ if (formInstance && formInstance.controlType === CONTROL_BASE_TYPE.FORM) {
447
449
  result[formInstance.id] = formInstance.fieldType;
448
450
  }
449
451
  return result;
@@ -555,7 +557,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
555
557
  options: Object.assign({}, options, {
556
558
  changed: createdNewRows,
557
559
  data: createdNewRowsData,
558
- deleted: deleted !== null && deleted !== void 0 ? deleted : []
560
+ deleted: deleted !== null && deleted !== void 0 ? deleted : [],
561
+ jsonValue: JSON.stringify(this.getState(subtable.id))
559
562
  })
560
563
  });
561
564
  // 主动清空本次任务中的options
@@ -569,7 +572,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
569
572
  }
570
573
  var index = this.getInstanceRowIndex(instance);
571
574
  var options = eventOptionsTemp || {};
572
- if (_instanceof(instance, RuntimeListControl)) {
575
+ // if (instance instanceof RuntimeListControl) {
576
+ if (instance.controlType === CONTROL_BASE_TYPE.LIST) {
573
577
  var // @ts-ignore
574
578
  _instance_children;
575
579
  instance.children.length = 0;
@@ -627,12 +631,15 @@ var Engine = /*#__PURE__*/ function(Watcher) {
627
631
  _proto.listControlCreateRow = function listControlCreateRow(instance, rowType) {
628
632
  var row = this.runtime.createControlInstance(rowType);
629
633
  if (!row) return;
630
- if (_instanceof(row, RuntimeLayoutControl)) {
631
- 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;
632
639
  var template = JSONCopy(instance.props.headers);
633
640
  // @ts-ignore
634
641
  var columns = this.createControl(template);
635
- (_row_children = row.children).push.apply(_row_children, _toConsumableArray(columns));
642
+ (_inst_children = inst.children).push.apply(_inst_children, _toConsumableArray(columns));
636
643
  }
637
644
  return row;
638
645
  };
@@ -1131,22 +1138,15 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1131
1138
  * @param header 明细表内是否获取表头的控件
1132
1139
  */ _proto.getInstances = function getInstances(controlId) {
1133
1140
  var header = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
1134
- var cc = console;
1135
- var label = "\uD83D\uDC11 genInstances " + controlId + " " + Date.now();
1136
- cc.time(label);
1137
1141
  if (controlId === undefined) {
1138
- cc.timeEnd(label);
1139
1142
  return this.runtime.flatInstances;
1140
1143
  }
1141
- var instances = this.runtime.flatInstances.filter(// @ts-ignore
1142
- function(item) {
1143
- return item.id === controlId;
1144
- });
1144
+ var instances = this.runtime.instanceMap[controlId] || [];
1145
1145
  if (header) {
1146
1146
  // 如果能从flatInstances里边取到,就通过getInstanceInSubtableHeader方法取,取不到则换一种方式
1147
1147
  if (instances.length) {
1148
1148
  var instance = instances[0];
1149
- if (this.getInstanceRowIndex(instance) !== undefined) {
1149
+ if (this.inList(instance.id) === true) {
1150
1150
  var headerInstance = this.getInstanceInSubtableHeader(instance);
1151
1151
  if (headerInstance) {
1152
1152
  instances.unshift(headerInstance);
@@ -1178,7 +1178,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1178
1178
  }
1179
1179
  }
1180
1180
  }
1181
- cc.timeEnd(label);
1181
+ // @ts-ignore
1182
1182
  return instances;
1183
1183
  };
1184
1184
  _proto.setInstance = function setInstance(instance, props, value, rowIndex) {
@@ -1197,7 +1197,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1197
1197
  this.schemaEvent("schema-change", {
1198
1198
  instance: _instance,
1199
1199
  props: props,
1200
- value: value
1200
+ value: value,
1201
+ rowIndex: rowIndex
1201
1202
  });
1202
1203
  } catch (e) {
1203
1204
  throw e;
@@ -1319,6 +1320,14 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1319
1320
  _proto.getControlConfig = function getControlConfig(control) {
1320
1321
  return this.runtime.getControlConfig(control);
1321
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
+ };
1322
1331
  // 注册外部控件
1323
1332
  Engine.register = function register() {
1324
1333
  for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
@@ -1333,4 +1342,3 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1333
1342
  return Engine;
1334
1343
  }(Watcher);
1335
1344
  export { Engine };
1336
- 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-column 放到 _flatInstances 中
118
- if (item.type === "subtable-column") {
110
+ // 3.4.1 避免将subtable-row 放到 _flatInstances 中
111
+ if (item.type === "subtable-row" || item.type === "subtable-column") {
119
112
  return;
120
113
  }
121
114
  instances.push(item);
@@ -160,7 +153,11 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
160
153
  loopDataViewControl(this._instance, function(dataView) {
161
154
  ruleItems[dataView.id] = dataView.rules[0];
162
155
  loopFormControl(dataView.children, function(item) {
163
- 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) {
164
161
  buildControlRules(ruleItems[dataView.id].fields, item);
165
162
  }
166
163
  });
@@ -175,7 +172,11 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
175
172
  loopDataViewControl(this._instance, function(dataView) {
176
173
  antdRules[dataView.id] = dataView.rules[0];
177
174
  loopFormControl(dataView.children, function(item) {
178
- 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) {
179
180
  buildControlAntdRules(antdRules[dataView.id].fields, item);
180
181
  }
181
182
  });
@@ -215,7 +216,8 @@ item) {
215
216
  if (getControlIsHide(item)) {
216
217
  return;
217
218
  }
218
- if (_instanceof(item, RuntimeFormControl)) {
219
+ // if (item instanceof RuntimeFormControl) {
220
+ if (item.controlType === CONTROL_BASE_TYPE.FORM) {
219
221
  data[item.id] = item.rules;
220
222
  } else if (item.type === CONTROL_TYPE.SUBTABLE) {
221
223
  data[item.id] = item.rules;
@@ -246,7 +248,8 @@ item) {
246
248
  if (getControlIsHide(item)) {
247
249
  return;
248
250
  }
249
- if (_instanceof(item, RuntimeFormControl)) {
251
+ // if (item instanceof RuntimeFormControl) {
252
+ if (item.controlType === CONTROL_BASE_TYPE.FORM) {
250
253
  antdRules[item.id] = item.rules;
251
254
  } else if (item.type === CONTROL_TYPE.SUBTABLE && item.children.length) {
252
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,9 +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";
35
26
  var cc = console;
27
+ import { CONTROL_BASE_TYPE, error, logerror } from "@byteluck-fe/model-driven-shared";
36
28
  var proxyArrayApi = [
37
29
  "splice",
38
30
  "push",
@@ -234,7 +226,7 @@ function flatInstanceForChildren(controls) {
234
226
  // cc.log('🏠 findItem flatInstance find result', initInstance)
235
227
  // cc.timeEnd('findItem flatInstance find')
236
228
  // cc.time('findItem instanceMap match')
237
- var initInstance = instanceMap[oneKey][0];
229
+ var initInstance = instanceMap[oneKey] ? instanceMap[oneKey][0] : undefined;
238
230
  // cc.log('🏠 findItem instanceMap match result', initInstance)
239
231
  // cc.timeEnd('findItem instanceMap match')
240
232
  if (otherKeys.length === 0) return initInstance;
@@ -242,13 +234,13 @@ function flatInstanceForChildren(controls) {
242
234
  return otherKeys.reduce(function(prevItem, key) {
243
235
  var index = Number(key);
244
236
  var isNotIndex = Number.isNaN(index);
245
- if (isNotIndex) {
237
+ if (isNotIndex && prevItem) {
246
238
  var flatChildren = (prevItem === null || prevItem === void 0 ? void 0 : prevItem.children) ? flatInstanceForChildren(prevItem.children) : undefined;
247
239
  var findEndItem = flatChildren === null || flatChildren === void 0 ? void 0 : flatChildren.find(function(item) {
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;
@@ -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