@byteluck-fe/model-driven-engine 2.7.0-alpha.31b → 2.7.0-alpha.35

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.
Files changed (41) hide show
  1. package/README.md +30 -30
  2. package/dist/esm/common/ActionManager.js +177 -60
  3. package/dist/esm/common/DataManager.js +134 -25
  4. package/dist/esm/common/Engine.js +480 -406
  5. package/dist/esm/common/OkWorker.js +31 -17
  6. package/dist/esm/common/Plugin.js +2 -2
  7. package/dist/esm/common/Runtime.js +80 -104
  8. package/dist/esm/common/Store.js +63 -62
  9. package/dist/esm/common/checkerValue.js +108 -108
  10. package/dist/esm/common/index.js +2 -2
  11. package/dist/esm/common/proxyState.js +76 -76
  12. package/dist/esm/index.js +3 -3
  13. package/dist/esm/plugins/CalcPlugin.js +128 -120
  14. package/dist/esm/plugins/ControlsEventPlugin.js +196 -73
  15. package/dist/esm/plugins/ES6ModulePlugin.js +54 -66
  16. package/dist/esm/plugins/LifecycleEventPlugin.js +198 -79
  17. package/dist/esm/plugins/StylePlugin.js +26 -11
  18. package/dist/esm/plugins/index.js +5 -5
  19. package/dist/esm/utils/index.js +1 -1
  20. package/dist/esm/utils/runtimeUtils.js +5 -7
  21. package/dist/index.umd.js +8 -8
  22. package/dist/types/common/ActionManager.d.ts +14 -14
  23. package/dist/types/common/DataManager.d.ts +10 -10
  24. package/dist/types/common/Engine.d.ts +184 -181
  25. package/dist/types/common/OkWorker.d.ts +13 -13
  26. package/dist/types/common/Plugin.d.ts +6 -6
  27. package/dist/types/common/Runtime.d.ts +25 -26
  28. package/dist/types/common/Store.d.ts +50 -50
  29. package/dist/types/common/checkerValue.d.ts +3 -3
  30. package/dist/types/common/index.d.ts +2 -2
  31. package/dist/types/common/proxyState.d.ts +30 -30
  32. package/dist/types/index.d.ts +3 -3
  33. package/dist/types/plugins/CalcPlugin.d.ts +121 -121
  34. package/dist/types/plugins/ControlsEventPlugin.d.ts +15 -15
  35. package/dist/types/plugins/ES6ModulePlugin.d.ts +26 -27
  36. package/dist/types/plugins/LifecycleEventPlugin.d.ts +14 -14
  37. package/dist/types/plugins/StylePlugin.d.ts +12 -12
  38. package/dist/types/plugins/index.d.ts +5 -5
  39. package/dist/types/utils/index.d.ts +1 -1
  40. package/dist/types/utils/runtimeUtils.d.ts +5 -5
  41. package/package.json +4 -4
@@ -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,24 +12,38 @@ 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
- import { log } from '@byteluck-fe/model-driven-shared';
20
+ function _define_property(obj, key, value) {
21
+ if (key in obj) {
22
+ Object.defineProperty(obj, key, {
23
+ value: value,
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true
27
+ });
28
+ } else {
29
+ obj[key] = value;
30
+ }
31
+ return obj;
32
+ }
33
+ import { log } from "@byteluck-fe/model-driven-shared";
21
34
  var OkWorker = /*#__PURE__*/ function() {
22
35
  "use strict";
23
36
  function OkWorker() {
24
- _classCallCheck(this, OkWorker);
37
+ _class_call_check(this, OkWorker);
38
+ _define_property(this, "worker", void 0);
25
39
  }
26
- _createClass(OkWorker, [
40
+ _create_class(OkWorker, [
27
41
  {
28
42
  key: "run",
29
43
  value: function run(initState) {
30
44
  this.worker = OkWorker.createWorker();
31
45
  this.postMessage({
32
- action: 'init',
46
+ action: "init",
33
47
  payload: initState
34
48
  });
35
49
  }
@@ -37,15 +51,15 @@ var OkWorker = /*#__PURE__*/ function() {
37
51
  {
38
52
  key: "destroy",
39
53
  value: function destroy() {
40
- var ref;
41
- (ref = this.worker) === null || ref === void 0 ? void 0 : ref.terminate();
54
+ var _this_worker;
55
+ (_this_worker = this.worker) === null || _this_worker === void 0 ? void 0 : _this_worker.terminate();
42
56
  }
43
57
  },
44
58
  {
45
59
  key: "postMessage",
46
60
  value: function postMessage(message) {
47
- var ref;
48
- (ref = this.worker) === null || ref === void 0 ? void 0 : ref.postMessage(message);
61
+ var _this_worker;
62
+ (_this_worker = this.worker) === null || _this_worker === void 0 ? void 0 : _this_worker.postMessage(message);
49
63
  }
50
64
  }
51
65
  ], [
@@ -71,7 +85,7 @@ var OkWorker = /*#__PURE__*/ function() {
71
85
  set: function set(target, key, value) {
72
86
  if (parentKey) {
73
87
  _self.postMessage({
74
- action: 'update',
88
+ action: "update",
75
89
  key: "".concat(parentKey, ".").concat(key)
76
90
  });
77
91
  }
@@ -79,7 +93,7 @@ var OkWorker = /*#__PURE__*/ function() {
79
93
  }
80
94
  };
81
95
  };
82
- log('‍🚀 worker running');
96
+ log("‍\uD83D\uDE80 worker running");
83
97
  var _self = self;
84
98
  // function createProxy(
85
99
  // obj: Record<string, unknown> | Array<Record<string, unknown>>,
@@ -92,8 +106,8 @@ var OkWorker = /*#__PURE__*/ function() {
92
106
  // }
93
107
  // return new Proxy(obj, createHandler(parentKey))
94
108
  // }
95
- _self.addEventListener('message', function(event) {
96
- var _data = event.data, action = _data.action, payload = _data.payload, fn = _data.fn;
109
+ _self.addEventListener("message", function(event) {
110
+ var _event_data = event.data, action = _event_data.action, payload = _event_data.payload, fn = _event_data.fn;
97
111
  log(action, payload);
98
112
  // 通过proxy进行代理,每次修改的时候,自动向外抛出postMessage
99
113
  // data.key1 = 1
@@ -104,10 +118,10 @@ var OkWorker = /*#__PURE__*/ function() {
104
118
  //
105
119
  // const result = fn(data, schema)
106
120
  _self.postMessage({
107
- action: 'delete',
121
+ action: "delete",
108
122
  payload: {
109
- key: 'key3[0].key1',
110
- value: 'index'
123
+ key: "key3[0].key1",
124
+ value: "index"
111
125
  }
112
126
  });
113
127
  });
@@ -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,16 +18,29 @@ 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 _getPrototypeOf(o) {
27
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
26
+ function _define_property(obj, key, value) {
27
+ if (key in obj) {
28
+ Object.defineProperty(obj, key, {
29
+ value: value,
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true
33
+ });
34
+ } else {
35
+ obj[key] = value;
36
+ }
37
+ return obj;
38
+ }
39
+ function _get_prototype_of(o) {
40
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
28
41
  return o.__proto__ || Object.getPrototypeOf(o);
29
42
  };
30
- return _getPrototypeOf(o);
43
+ return _get_prototype_of(o);
31
44
  }
32
45
  function _inherits(subClass, superClass) {
33
46
  if (typeof superClass !== "function" && superClass !== null) {
@@ -40,26 +53,26 @@ function _inherits(subClass, superClass) {
40
53
  configurable: true
41
54
  }
42
55
  });
43
- if (superClass) _setPrototypeOf(subClass, superClass);
56
+ if (superClass) _set_prototype_of(subClass, superClass);
44
57
  }
45
- function _possibleConstructorReturn(self, call) {
46
- 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")) {
47
60
  return call;
48
61
  }
49
- return _assertThisInitialized(self);
62
+ return _assert_this_initialized(self);
50
63
  }
51
- function _setPrototypeOf(o, p) {
52
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
64
+ function _set_prototype_of(o, p) {
65
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
53
66
  o.__proto__ = p;
54
67
  return o;
55
68
  };
56
- return _setPrototypeOf(o, p);
69
+ return _set_prototype_of(o, p);
57
70
  }
58
- var _typeof = function(obj) {
71
+ function _type_of(obj) {
59
72
  "@swc/helpers - typeof";
60
73
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
61
- };
62
- function _isNativeReflectConstruct() {
74
+ }
75
+ function _is_native_reflect_construct() {
63
76
  if (typeof Reflect === "undefined" || !Reflect.construct) return false;
64
77
  if (Reflect.construct.sham) return false;
65
78
  if (typeof Proxy === "function") return true;
@@ -70,71 +83,59 @@ function _isNativeReflectConstruct() {
70
83
  return false;
71
84
  }
72
85
  }
73
- function _createSuper(Derived) {
74
- var hasNativeReflectConstruct = _isNativeReflectConstruct();
86
+ function _create_super(Derived) {
87
+ var hasNativeReflectConstruct = _is_native_reflect_construct();
75
88
  return function _createSuperInternal() {
76
- var Super = _getPrototypeOf(Derived), result;
89
+ var Super = _get_prototype_of(Derived), result;
77
90
  if (hasNativeReflectConstruct) {
78
- var NewTarget = _getPrototypeOf(this).constructor;
91
+ var NewTarget = _get_prototype_of(this).constructor;
79
92
  result = Reflect.construct(Super, arguments, NewTarget);
80
93
  } else {
81
94
  result = Super.apply(this, arguments);
82
95
  }
83
- return _possibleConstructorReturn(this, result);
96
+ return _possible_constructor_return(this, result);
84
97
  };
85
98
  }
86
- import { RegisterControls } from '@byteluck-fe/model-driven-core';
87
- import { CONTROL_BASE_TYPE, CONTROL_TYPE, JSONCopy, loopFormSchema, isArray } from '@byteluck-fe/model-driven-shared';
88
- import { hasChildrenControl, loopDataViewControl, loopFormControl } from '../utils/runtimeUtils';
89
- export var Runtime = /*#__PURE__*/ function(RegisterControls1) {
99
+ import { RegisterControls } from "@byteluck-fe/model-driven-core";
100
+ import { CONTROL_BASE_TYPE, CONTROL_TYPE, loopFormSchema } from "@byteluck-fe/model-driven-shared";
101
+ import { hasChildrenControl, loopDataViewControl, loopFormControl } from "../utils/runtimeUtils";
102
+ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
90
103
  "use strict";
91
- _inherits(Runtime, RegisterControls1);
92
- var _super = _createSuper(Runtime);
104
+ _inherits(Runtime, RegisterControls);
105
+ var _super = _create_super(Runtime);
93
106
  function Runtime(props) {
94
- _classCallCheck(this, Runtime);
107
+ _class_call_check(this, Runtime);
95
108
  var _this;
96
- _this = _super.call(this, 'Runtime');
97
- _this._flatInstances = [];
98
- _this._instanceMap = {};
99
- _this._controlParentIdMap = {};
109
+ _this = _super.call(this, "Runtime");
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", {});
100
114
  var schema = props.schema;
101
115
  _this._schema = schema;
102
116
  _this._instance = _this.createControl(schema, props.beforeCreateInstance);
103
117
  _this.getFlatInstances();
104
118
  return _this;
105
119
  }
106
- _createClass(Runtime, [
120
+ _create_class(Runtime, [
107
121
  {
108
122
  key: "getFlatInstances",
109
123
  value: function getFlatInstances() {
110
124
  var instances = [];
111
125
  var instanceMap = {};
112
- var controlParentIdMap = {};
113
- loop(this._instance, '', function(item, parentId) {
126
+ loop(this._instance, function(item) {
114
127
  // 3.4.1 避免将subtable-row 放到 _flatInstances 中
115
- //4.3.0-lh2 将自处注释掉,为使instance.parent能取到父级
116
- // if (item.type === 'subtable-row' || item.type === 'subtable-column') {
117
- // return
118
- // }
119
- if (parentId) {
120
- // @ts-ignore
121
- controlParentIdMap[item.id] = parentId;
128
+ if (item.type === "subtable-row" || item.type === "subtable-column") {
129
+ return;
122
130
  }
131
+ instances.push(item);
123
132
  if (!instanceMap[item.id]) {
124
133
  instanceMap[item.id] = [];
125
134
  }
126
- //不知为何subtable-column会多存一次
127
- if (item.type === 'subtable-column') {
128
- if (instanceMap[item.id].length > 0) {
129
- return;
130
- }
131
- }
132
- instances.push(item);
133
135
  instanceMap[item.id].push(item);
134
136
  });
135
137
  this._flatInstances = instances;
136
138
  this._instanceMap = instanceMap;
137
- this._controlParentIdMap = controlParentIdMap;
138
139
  return this._flatInstances;
139
140
  }
140
141
  },
@@ -168,9 +169,8 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls1) {
168
169
  var antdRules = {};
169
170
  var ruleItems = {};
170
171
  loopDataViewControl(this._instance, function(dataView) {
171
- var result = Runtime.staticGetRules(dataView.type, dataView.props);
172
- ruleItems[dataView.id] = JSONCopy(result[0]);
173
- antdRules[dataView.id] = JSONCopy(result[0]);
172
+ ruleItems[dataView.id] = dataView.rules[0];
173
+ antdRules[dataView.id] = dataView.rules[0];
174
174
  loopFormControl(dataView.children, function(item) {
175
175
  // if (
176
176
  // item instanceof RuntimeFormControl ||
@@ -193,9 +193,7 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls1) {
193
193
  get: function get() {
194
194
  var ruleItems = {};
195
195
  loopDataViewControl(this._instance, function(dataView) {
196
- var result = Runtime.staticGetRules(dataView.type, dataView.props);
197
- // ruleItems[dataView.id] = dataView.rules[0]
198
- ruleItems[dataView.id] = result[0];
196
+ ruleItems[dataView.id] = dataView.rules[0];
199
197
  loopFormControl(dataView.children, function(item) {
200
198
  // if (
201
199
  // item instanceof RuntimeFormControl ||
@@ -214,9 +212,7 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls1) {
214
212
  get: function get() {
215
213
  var antdRules = {};
216
214
  loopDataViewControl(this._instance, function(dataView) {
217
- var result = Runtime.staticGetRules(dataView.type, dataView.props);
218
- // antdRules[dataView.id] = dataView.rules[0]
219
- antdRules[dataView.id] = result[0];
215
+ antdRules[dataView.id] = dataView.rules[0];
220
216
  loopFormControl(dataView.children, function(item) {
221
217
  // if (
222
218
  // item instanceof RuntimeFormControl ||
@@ -233,38 +229,30 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls1) {
233
229
  ]);
234
230
  return Runtime;
235
231
  }(RegisterControls);
236
- function loop(control, parentId, callback) {
237
- var _instances = Array.isArray(control) ? control : [
238
- control
239
- ];
240
- _instances.map(function(item) {
241
- callback(item, parentId);
242
- if (hasChildrenControl(item)) {
243
- var ctl = item;
244
- if (!ctl.children) {
245
- ctl.children = [];
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);
246
243
  }
247
- // @ts-ignore
248
- loop(ctl.children, ctl.id, callback);
249
- }
250
- if (hasHeaderOrFooterControl(item, 'headers')) {
251
- loop(item.props.headers, item.id, callback);
252
- }
253
- if (hasHeaderOrFooterControl(item, 'footers')) {
254
- loop(item.props.footers, item.id, callback);
255
- }
256
- });
257
- }
258
- function hasHeaderOrFooterControl(control, checkType) {
259
- return checkType in control.props && isArray(control.props[checkType]);
244
+ });
245
+ } else {
246
+ callback(control);
247
+ }
260
248
  }
261
- /**
262
- * 控件是否在视图中隐藏,遍历查找所有parent
249
+ /**
250
+ * 控件是否在视图中隐藏,遍历查找所有parent
263
251
  * */ function getControlIsHide(control) {
264
252
  if (control.props.isHide) {
265
253
  return true;
266
254
  }
267
- if (control.parent === null || control.parent === undefined) {
255
+ if (control.parent === null) {
268
256
  return false;
269
257
  }
270
258
  return getControlIsHide(control.parent);
@@ -274,16 +262,13 @@ item) {
274
262
  if (getControlIsHide(item)) {
275
263
  return;
276
264
  }
277
- var result = Runtime.staticGetRules(item.type, item.props);
278
265
  // if (item instanceof RuntimeFormControl) {
279
266
  if (item.controlType === CONTROL_BASE_TYPE.FORM) {
280
- // data[item.id] = item.rules
281
- data[item.id] = result;
267
+ data[item.id] = item.rules;
282
268
  } else if (item.type === CONTROL_TYPE.SUBTABLE) {
283
- // data[item.id] = item.rules
284
- data[item.id] = result;
269
+ data[item.id] = item.rules;
285
270
  var itemRules = {
286
- type: 'array',
271
+ type: "array",
287
272
  fields: {}
288
273
  };
289
274
  item.children.forEach(function(row, index) {
@@ -291,18 +276,13 @@ item) {
291
276
  if (itemRules.fields) {
292
277
  if (!itemRules.fields[index]) {
293
278
  itemRules.fields[index] = {
294
- type: 'object',
279
+ type: "object",
295
280
  required: true,
296
281
  fields: {}
297
282
  };
298
283
  }
299
- // // @ts-ignore
300
- // itemRules.fields[index].fields[formControl.id] = (
301
- // formControl as RuntimeFormControl
302
- // ).rules
303
- var childResult = Runtime.staticGetRules(formControl.type, formControl.props);
304
284
  // @ts-ignore
305
- itemRules.fields[index].fields[formControl.id] = childResult;
285
+ itemRules.fields[index].fields[formControl.id] = formControl.rules;
306
286
  }
307
287
  });
308
288
  });
@@ -314,19 +294,15 @@ item) {
314
294
  if (getControlIsHide(item)) {
315
295
  return;
316
296
  }
317
- var result = Runtime.staticGetRules(item.type, item.props);
318
297
  // if (item instanceof RuntimeFormControl) {
319
298
  if (item.controlType === CONTROL_BASE_TYPE.FORM) {
320
- // antdRules[item.id] = item.rules
321
- antdRules[item.id] = result;
299
+ antdRules[item.id] = item.rules;
322
300
  } else if (item.type === CONTROL_TYPE.SUBTABLE && item.children.length) {
323
301
  antdRules[item.id] = [];
324
302
  item.children.forEach(function(row) {
325
303
  var rules = {};
326
304
  loopFormSchema(row.children, function(formControl) {
327
- // rules[formControl.id] = (formControl as RuntimeFormControl).rules
328
- var childResult = Runtime.staticGetRules(formControl.type, formControl.props);
329
- rules[formControl.id] = childResult;
305
+ rules[formControl.id] = formControl.rules;
330
306
  });
331
307
  antdRules[item.id].push(rules);
332
308
  });