@byteluck-fe/model-driven-engine 2.7.0-alpha.25 → 2.7.0-alpha.28a

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.
@@ -1,4 +1,4 @@
1
- function _classCallCheck(instance, Constructor) {
1
+ function _class_call_check(instance, Constructor) {
2
2
  if (!(instance instanceof Constructor)) {
3
3
  throw new TypeError("Cannot call a class as a function");
4
4
  }
@@ -12,12 +12,12 @@ function _defineProperties(target, props) {
12
12
  Object.defineProperty(target, descriptor.key, descriptor);
13
13
  }
14
14
  }
15
- function _createClass(Constructor, protoProps, staticProps) {
15
+ function _create_class(Constructor, protoProps, staticProps) {
16
16
  if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
17
  if (staticProps) _defineProperties(Constructor, staticProps);
18
18
  return Constructor;
19
19
  }
20
- function _defineProperty(obj, key, value) {
20
+ function _define_property(obj, key, value) {
21
21
  if (key in obj) {
22
22
  Object.defineProperty(obj, key, {
23
23
  value: value,
@@ -34,10 +34,10 @@ import { log } from "@byteluck-fe/model-driven-shared";
34
34
  var OkWorker = /*#__PURE__*/ function() {
35
35
  "use strict";
36
36
  function OkWorker() {
37
- _classCallCheck(this, OkWorker);
38
- _defineProperty(this, "worker", void 0);
37
+ _class_call_check(this, OkWorker);
38
+ _define_property(this, "worker", void 0);
39
39
  }
40
- _createClass(OkWorker, [
40
+ _create_class(OkWorker, [
41
41
  {
42
42
  key: "run",
43
43
  value: function run(initState) {
@@ -1,10 +1,10 @@
1
- function _classCallCheck(instance, Constructor) {
1
+ function _class_call_check(instance, Constructor) {
2
2
  if (!(instance instanceof Constructor)) {
3
3
  throw new TypeError("Cannot call a class as a function");
4
4
  }
5
5
  }
6
6
  var Plugin = function Plugin() {
7
7
  "use strict";
8
- _classCallCheck(this, Plugin);
8
+ _class_call_check(this, Plugin);
9
9
  };
10
10
  export { Plugin };
@@ -1,10 +1,10 @@
1
- function _assertThisInitialized(self) {
1
+ function _assert_this_initialized(self) {
2
2
  if (self === void 0) {
3
3
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
4
4
  }
5
5
  return self;
6
6
  }
7
- function _classCallCheck(instance, Constructor) {
7
+ function _class_call_check(instance, Constructor) {
8
8
  if (!(instance instanceof Constructor)) {
9
9
  throw new TypeError("Cannot call a class as a function");
10
10
  }
@@ -18,12 +18,12 @@ function _defineProperties(target, props) {
18
18
  Object.defineProperty(target, descriptor.key, descriptor);
19
19
  }
20
20
  }
21
- function _createClass(Constructor, protoProps, staticProps) {
21
+ function _create_class(Constructor, protoProps, staticProps) {
22
22
  if (protoProps) _defineProperties(Constructor.prototype, protoProps);
23
23
  if (staticProps) _defineProperties(Constructor, staticProps);
24
24
  return Constructor;
25
25
  }
26
- function _defineProperty(obj, key, value) {
26
+ function _define_property(obj, key, value) {
27
27
  if (key in obj) {
28
28
  Object.defineProperty(obj, key, {
29
29
  value: value,
@@ -36,11 +36,11 @@ function _defineProperty(obj, key, value) {
36
36
  }
37
37
  return obj;
38
38
  }
39
- function _getPrototypeOf(o) {
40
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
39
+ function _get_prototype_of(o) {
40
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
41
41
  return o.__proto__ || Object.getPrototypeOf(o);
42
42
  };
43
- return _getPrototypeOf(o);
43
+ return _get_prototype_of(o);
44
44
  }
45
45
  function _inherits(subClass, superClass) {
46
46
  if (typeof superClass !== "function" && superClass !== null) {
@@ -53,26 +53,26 @@ function _inherits(subClass, superClass) {
53
53
  configurable: true
54
54
  }
55
55
  });
56
- if (superClass) _setPrototypeOf(subClass, superClass);
56
+ if (superClass) _set_prototype_of(subClass, superClass);
57
57
  }
58
- function _possibleConstructorReturn(self, call) {
59
- if (call && (_typeof(call) === "object" || typeof call === "function")) {
58
+ function _possible_constructor_return(self, call) {
59
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
60
60
  return call;
61
61
  }
62
- return _assertThisInitialized(self);
62
+ return _assert_this_initialized(self);
63
63
  }
64
- function _setPrototypeOf(o, p) {
65
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
64
+ function _set_prototype_of(o, p) {
65
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
66
66
  o.__proto__ = p;
67
67
  return o;
68
68
  };
69
- return _setPrototypeOf(o, p);
69
+ return _set_prototype_of(o, p);
70
70
  }
71
- var _typeof = function(obj) {
71
+ function _type_of(obj) {
72
72
  "@swc/helpers - typeof";
73
73
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
74
- };
75
- function _isNativeReflectConstruct() {
74
+ }
75
+ function _is_native_reflect_construct() {
76
76
  if (typeof Reflect === "undefined" || !Reflect.construct) return false;
77
77
  if (Reflect.construct.sham) return false;
78
78
  if (typeof Proxy === "function") return true;
@@ -83,59 +83,73 @@ function _isNativeReflectConstruct() {
83
83
  return false;
84
84
  }
85
85
  }
86
- function _createSuper(Derived) {
87
- var hasNativeReflectConstruct = _isNativeReflectConstruct();
86
+ function _create_super(Derived) {
87
+ var hasNativeReflectConstruct = _is_native_reflect_construct();
88
88
  return function _createSuperInternal() {
89
- var Super = _getPrototypeOf(Derived), result;
89
+ var Super = _get_prototype_of(Derived), result;
90
90
  if (hasNativeReflectConstruct) {
91
- var NewTarget = _getPrototypeOf(this).constructor;
91
+ var NewTarget = _get_prototype_of(this).constructor;
92
92
  result = Reflect.construct(Super, arguments, NewTarget);
93
93
  } else {
94
94
  result = Super.apply(this, arguments);
95
95
  }
96
- return _possibleConstructorReturn(this, result);
96
+ return _possible_constructor_return(this, result);
97
97
  };
98
98
  }
99
99
  import { RegisterControls } from "@byteluck-fe/model-driven-core";
100
- import { CONTROL_BASE_TYPE, CONTROL_TYPE, loopFormSchema } from "@byteluck-fe/model-driven-shared";
100
+ import { CONTROL_BASE_TYPE, CONTROL_TYPE, JSONCopy, loopFormSchema, isArray } from "@byteluck-fe/model-driven-shared";
101
101
  import { hasChildrenControl, loopDataViewControl, loopFormControl } from "../utils/runtimeUtils";
102
102
  export var Runtime = /*#__PURE__*/ function(RegisterControls) {
103
103
  "use strict";
104
104
  _inherits(Runtime, RegisterControls);
105
- var _super = _createSuper(Runtime);
105
+ var _super = _create_super(Runtime);
106
106
  function Runtime(props) {
107
- _classCallCheck(this, Runtime);
107
+ _class_call_check(this, Runtime);
108
108
  var _this;
109
109
  _this = _super.call(this, "Runtime");
110
- _defineProperty(_assertThisInitialized(_this), "_schema", void 0);
111
- _defineProperty(_assertThisInitialized(_this), "_instance", void 0);
112
- _defineProperty(_assertThisInitialized(_this), "_flatInstances", []);
113
- _defineProperty(_assertThisInitialized(_this), "_instanceMap", {});
110
+ _define_property(_assert_this_initialized(_this), "_schema", void 0);
111
+ _define_property(_assert_this_initialized(_this), "_instance", void 0);
112
+ _define_property(_assert_this_initialized(_this), "_flatInstances", []);
113
+ _define_property(_assert_this_initialized(_this), "_instanceMap", {});
114
+ _define_property(_assert_this_initialized(_this), "_controlParentIdMap", {});
114
115
  var schema = props.schema;
115
116
  _this._schema = schema;
116
117
  _this._instance = _this.createControl(schema, props.beforeCreateInstance);
117
118
  _this.getFlatInstances();
118
119
  return _this;
119
120
  }
120
- _createClass(Runtime, [
121
+ _create_class(Runtime, [
121
122
  {
122
123
  key: "getFlatInstances",
123
124
  value: function getFlatInstances() {
124
125
  var instances = [];
125
126
  var instanceMap = {};
126
- loop(this._instance, function(item) {
127
+ var controlParentIdMap = {};
128
+ loop(this._instance, "", function(item, parentId) {
127
129
  // 3.4.1 避免将subtable-row 放到 _flatInstances 中
128
- if (item.type === "subtable-row" || item.type === "subtable-column") {
129
- return;
130
+ //4.3.0-lh2 将自处注释掉,为使instance.parent能取到父级
131
+ // if (item.type === 'subtable-row' || item.type === 'subtable-column') {
132
+ // return
133
+ // }
134
+ if (parentId) {
135
+ // @ts-ignore
136
+ controlParentIdMap[item.id] = parentId;
130
137
  }
131
- instances.push(item);
132
138
  if (!instanceMap[item.id]) {
133
139
  instanceMap[item.id] = [];
134
140
  }
141
+ //不知为何subtable-column会多存一次
142
+ if (item.type === "subtable-column") {
143
+ if (instanceMap[item.id].length > 0) {
144
+ return;
145
+ }
146
+ }
147
+ instances.push(item);
135
148
  instanceMap[item.id].push(item);
136
149
  });
137
150
  this._flatInstances = instances;
138
151
  this._instanceMap = instanceMap;
152
+ this._controlParentIdMap = controlParentIdMap;
139
153
  return this._flatInstances;
140
154
  }
141
155
  },
@@ -169,8 +183,9 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
169
183
  var antdRules = {};
170
184
  var ruleItems = {};
171
185
  loopDataViewControl(this._instance, function(dataView) {
172
- ruleItems[dataView.id] = dataView.rules[0];
173
- antdRules[dataView.id] = dataView.rules[0];
186
+ var result = Runtime.staticGetRules(dataView.type, dataView.props);
187
+ ruleItems[dataView.id] = JSONCopy(result[0]);
188
+ antdRules[dataView.id] = JSONCopy(result[0]);
174
189
  loopFormControl(dataView.children, function(item) {
175
190
  // if (
176
191
  // item instanceof RuntimeFormControl ||
@@ -193,7 +208,9 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
193
208
  get: function get() {
194
209
  var ruleItems = {};
195
210
  loopDataViewControl(this._instance, function(dataView) {
196
- ruleItems[dataView.id] = dataView.rules[0];
211
+ var result = Runtime.staticGetRules(dataView.type, dataView.props);
212
+ // ruleItems[dataView.id] = dataView.rules[0]
213
+ ruleItems[dataView.id] = result[0];
197
214
  loopFormControl(dataView.children, function(item) {
198
215
  // if (
199
216
  // item instanceof RuntimeFormControl ||
@@ -212,7 +229,9 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
212
229
  get: function get() {
213
230
  var antdRules = {};
214
231
  loopDataViewControl(this._instance, function(dataView) {
215
- antdRules[dataView.id] = dataView.rules[0];
232
+ var result = Runtime.staticGetRules(dataView.type, dataView.props);
233
+ // antdRules[dataView.id] = dataView.rules[0]
234
+ antdRules[dataView.id] = result[0];
216
235
  loopFormControl(dataView.children, function(item) {
217
236
  // if (
218
237
  // item instanceof RuntimeFormControl ||
@@ -229,22 +248,30 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
229
248
  ]);
230
249
  return Runtime;
231
250
  }(RegisterControls);
232
- function loop(control, callback) {
233
- if (Array.isArray(control)) {
234
- control.map(function(item) {
235
- callback(item);
236
- if (hasChildrenControl(item)) {
237
- var ctl = item;
238
- if (!ctl.children) {
239
- ctl.children = [];
240
- }
241
- // @ts-ignore
242
- loop(ctl.children, callback);
251
+ function loop(control, parentId, callback) {
252
+ var _instances = Array.isArray(control) ? control : [
253
+ control
254
+ ];
255
+ _instances.map(function(item) {
256
+ callback(item, parentId);
257
+ if (hasChildrenControl(item)) {
258
+ var ctl = item;
259
+ if (!ctl.children) {
260
+ ctl.children = [];
243
261
  }
244
- });
245
- } else {
246
- callback(control);
247
- }
262
+ // @ts-ignore
263
+ loop(ctl.children, ctl.id, callback);
264
+ }
265
+ if (hasHeaderOrFooterControl(item, "headers")) {
266
+ loop(item.props.headers, item.id, callback);
267
+ }
268
+ if (hasHeaderOrFooterControl(item, "footers")) {
269
+ loop(item.props.footers, item.id, callback);
270
+ }
271
+ });
272
+ }
273
+ function hasHeaderOrFooterControl(control, checkType) {
274
+ return checkType in control.props && isArray(control.props[checkType]);
248
275
  }
249
276
  /**
250
277
  * 控件是否在视图中隐藏,遍历查找所有parent
@@ -252,7 +279,7 @@ function loop(control, callback) {
252
279
  if (control.props.isHide) {
253
280
  return true;
254
281
  }
255
- if (control.parent === null) {
282
+ if (control.parent === null || control.parent === undefined) {
256
283
  return false;
257
284
  }
258
285
  return getControlIsHide(control.parent);
@@ -262,11 +289,14 @@ item) {
262
289
  if (getControlIsHide(item)) {
263
290
  return;
264
291
  }
292
+ var result = Runtime.staticGetRules(item.type, item.props);
265
293
  // if (item instanceof RuntimeFormControl) {
266
294
  if (item.controlType === CONTROL_BASE_TYPE.FORM) {
267
- data[item.id] = item.rules;
295
+ // data[item.id] = item.rules
296
+ data[item.id] = result;
268
297
  } else if (item.type === CONTROL_TYPE.SUBTABLE) {
269
- data[item.id] = item.rules;
298
+ // data[item.id] = item.rules
299
+ data[item.id] = result;
270
300
  var itemRules = {
271
301
  type: "array",
272
302
  fields: {}
@@ -281,8 +311,13 @@ item) {
281
311
  fields: {}
282
312
  };
283
313
  }
314
+ // // @ts-ignore
315
+ // itemRules.fields[index].fields[formControl.id] = (
316
+ // formControl as RuntimeFormControl
317
+ // ).rules
318
+ var childResult = Runtime.staticGetRules(formControl.type, formControl.props);
284
319
  // @ts-ignore
285
- itemRules.fields[index].fields[formControl.id] = formControl.rules;
320
+ itemRules.fields[index].fields[formControl.id] = childResult;
286
321
  }
287
322
  });
288
323
  });
@@ -294,15 +329,19 @@ item) {
294
329
  if (getControlIsHide(item)) {
295
330
  return;
296
331
  }
332
+ var result = Runtime.staticGetRules(item.type, item.props);
297
333
  // if (item instanceof RuntimeFormControl) {
298
334
  if (item.controlType === CONTROL_BASE_TYPE.FORM) {
299
- antdRules[item.id] = item.rules;
335
+ // antdRules[item.id] = item.rules
336
+ antdRules[item.id] = result;
300
337
  } else if (item.type === CONTROL_TYPE.SUBTABLE && item.children.length) {
301
338
  antdRules[item.id] = [];
302
339
  item.children.forEach(function(row) {
303
340
  var rules = {};
304
341
  loopFormSchema(row.children, function(formControl) {
305
- rules[formControl.id] = formControl.rules;
342
+ // rules[formControl.id] = (formControl as RuntimeFormControl).rules
343
+ var childResult = Runtime.staticGetRules(formControl.type, formControl.props);
344
+ rules[formControl.id] = childResult;
306
345
  });
307
346
  antdRules[item.id].push(rules);
308
347
  });
@@ -1,4 +1,4 @@
1
- function _classCallCheck(instance, Constructor) {
1
+ function _class_call_check(instance, Constructor) {
2
2
  if (!(instance instanceof Constructor)) {
3
3
  throw new TypeError("Cannot call a class as a function");
4
4
  }
@@ -12,12 +12,12 @@ function _defineProperties(target, props) {
12
12
  Object.defineProperty(target, descriptor.key, descriptor);
13
13
  }
14
14
  }
15
- function _createClass(Constructor, protoProps, staticProps) {
15
+ function _create_class(Constructor, protoProps, staticProps) {
16
16
  if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
17
  if (staticProps) _defineProperties(Constructor, staticProps);
18
18
  return Constructor;
19
19
  }
20
- function _defineProperty(obj, key, value) {
20
+ function _define_property(obj, key, value) {
21
21
  if (key in obj) {
22
22
  Object.defineProperty(obj, key, {
23
23
  value: value,
@@ -30,7 +30,7 @@ function _defineProperty(obj, key, value) {
30
30
  }
31
31
  return obj;
32
32
  }
33
- function _objectSpread(target) {
33
+ function _object_spread(target) {
34
34
  for(var i = 1; i < arguments.length; i++){
35
35
  var source = arguments[i] != null ? arguments[i] : {};
36
36
  var ownKeys = Object.keys(source);
@@ -40,7 +40,7 @@ function _objectSpread(target) {
40
40
  }));
41
41
  }
42
42
  ownKeys.forEach(function(key) {
43
- _defineProperty(target, key, source[key]);
43
+ _define_property(target, key, source[key]);
44
44
  });
45
45
  }
46
46
  return target;
@@ -51,13 +51,13 @@ import { loopDataViewControl, loopFormControl, buildUUID } from "../utils/runtim
51
51
  var Store = /*#__PURE__*/ function() {
52
52
  "use strict";
53
53
  function Store(props) {
54
- _classCallCheck(this, Store);
55
- _defineProperty(this, "emptyState", void 0);
56
- _defineProperty(this, "state", void 0);
57
- _defineProperty(this, "dataBindMapping", void 0 // 主要提供给二开使用
54
+ _class_call_check(this, Store);
55
+ _define_property(this, "emptyState", void 0);
56
+ _define_property(this, "state", void 0);
57
+ _define_property(this, "dataBindMapping", void 0 // 主要提供给二开使用
58
58
  );
59
- _defineProperty(this, "controlIdMapping", void 0);
60
- _defineProperty(this, "defaultState", void 0);
59
+ _define_property(this, "controlIdMapping", void 0);
60
+ _define_property(this, "defaultState", void 0);
61
61
  var _init = init(props.instance), state = _init.state, emptyState = _init.emptyState, databindMapping = _init.databindMapping, controlidMapping = _init.controlidMapping, defaultState = _init.defaultState;
62
62
  this.emptyState = emptyState;
63
63
  this.state = state;
@@ -65,7 +65,7 @@ var Store = /*#__PURE__*/ function() {
65
65
  this.controlIdMapping = controlidMapping;
66
66
  this.defaultState = defaultState;
67
67
  }
68
- _createClass(Store, [
68
+ _create_class(Store, [
69
69
  {
70
70
  /**
71
71
  * 使用该方法仅改变数据,不会表单触发事件。明细表可全量赋值也可根据rowIndex进行单独设置
@@ -200,6 +200,7 @@ var Store = /*#__PURE__*/ function() {
200
200
  {
201
201
  key: "getDataBind",
202
202
  value: function getDataBind(controlId) {
203
+ var _result;
203
204
  var result = this.controlIdMapping[controlId];
204
205
  if (result) {
205
206
  return result.dataBind;
@@ -215,7 +216,7 @@ var Store = /*#__PURE__*/ function() {
215
216
  }
216
217
  }
217
218
  }
218
- return result === null || result === void 0 ? void 0 : result.dataBind;
219
+ return (_result = result) === null || _result === void 0 ? void 0 : _result.dataBind;
219
220
  }
220
221
  }
221
222
  ]);
@@ -268,7 +269,7 @@ item) {
268
269
  });
269
270
  var _item_props_defaultRows, _fill_map;
270
271
  dataViewState[item.id] = (_fill_map = new Array((_item_props_defaultRows = item.props.defaultRows) !== null && _item_props_defaultRows !== void 0 ? _item_props_defaultRows : 1).fill(0).map(function() {
271
- return _objectSpread({
272
+ return _object_spread({
272
273
  uid: "new:" + buildUUID("uid")
273
274
  }, JSONCopy(emptyTemplate));
274
275
  })) !== null && _fill_map !== void 0 ? _fill_map : [];
@@ -279,7 +280,7 @@ function buildDataBindMapping(data, dataViewId, // @ts-ignore
279
280
  item) {
280
281
  // if (item instanceof RuntimeFormControl) {
281
282
  if (item.controlType === CONTROL_BASE_TYPE.FORM) {
282
- var _item_props, _item_props_dataBind;
283
+ var _item_props_dataBind, _item_props;
283
284
  // if (item.props.dataBind instanceof ObjectDataBind) {
284
285
  if (!isDataBind(item.props.dataBind)) {
285
286
  // 特殊的dataBind,比如:金额是currency+amount两个key组成的,日期区间,继承自ObjectDataBind的需要通过Object.keys拿到多个databind
@@ -387,7 +388,7 @@ item) {
387
388
  loopFormSchema(item.props.headers, function(formControl) {
388
389
  var _data_item_id;
389
390
  var _data_item_id_children;
390
- Object.assign((_data_item_id_children = (_data_item_id = data[item.id]) === null || _data_item_id === void 0 ? void 0 : _data_item_id.children) !== null && _data_item_id_children !== void 0 ? _data_item_id_children : {}, _defineProperty({}, formControl.id, {
391
+ Object.assign((_data_item_id_children = (_data_item_id = data[item.id]) === null || _data_item_id === void 0 ? void 0 : _data_item_id.children) !== null && _data_item_id_children !== void 0 ? _data_item_id_children : {}, _define_property({}, formControl.id, {
391
392
  dataBind: formControl.props.dataBind
392
393
  }));
393
394
  });