@byteluck-fe/model-driven-engine 2.7.0-alpha.1 → 2.7.0-alpha.11
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.
- package/dist/esm/common/ActionManager.js +72 -154
- package/dist/esm/common/DataManager.js +60 -128
- package/dist/esm/common/Engine.js +1145 -1066
- package/dist/esm/common/OkWorker.js +106 -75
- package/dist/esm/common/Runtime.js +34 -28
- package/dist/esm/common/Store.js +186 -157
- package/dist/esm/common/checkerValue.js +341 -259
- package/dist/esm/common/index.js +2 -2
- package/dist/esm/common/proxyState.js +47 -47
- package/dist/esm/index.js +3 -3
- package/dist/esm/plugins/CalcPlugin.js +382 -306
- package/dist/esm/plugins/ControlsEventPlugin.js +141 -225
- package/dist/esm/plugins/ES6ModulePlugin.js +56 -38
- package/dist/esm/plugins/LifecycleEventPlugin.js +107 -190
- package/dist/esm/plugins/StylePlugin.js +31 -13
- package/dist/esm/plugins/index.js +5 -5
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/utils/runtimeUtils.js +9 -6
- package/dist/index.umd.js +11 -11
- package/dist/types/common/Engine.d.ts +7 -7
- package/dist/types/common/Runtime.d.ts +1 -1
- package/dist/types/common/Store.d.ts +5 -5
- package/dist/types/common/proxyState.d.ts +3 -3
- package/dist/types/plugins/ControlsEventPlugin.d.ts +1 -1
- package/dist/types/plugins/ES6ModulePlugin.d.ts +4 -4
- package/dist/types/plugins/LifecycleEventPlugin.d.ts +1 -1
- package/dist/types/plugins/StylePlugin.d.ts +1 -1
- package/package.json +4 -4
|
@@ -3,87 +3,118 @@ function _classCallCheck(instance, Constructor) {
|
|
|
3
3
|
throw new TypeError("Cannot call a class as a function");
|
|
4
4
|
}
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
function _defineProperties(target, props) {
|
|
7
|
+
for(var i = 0; i < props.length; i++){
|
|
8
|
+
var descriptor = props[i];
|
|
9
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
10
|
+
descriptor.configurable = true;
|
|
11
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
12
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
16
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
17
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
18
|
+
return Constructor;
|
|
19
|
+
}
|
|
20
|
+
import { log } from '@byteluck-fe/model-driven-shared';
|
|
7
21
|
var OkWorker = /*#__PURE__*/ function() {
|
|
8
22
|
"use strict";
|
|
9
23
|
function OkWorker() {
|
|
10
24
|
_classCallCheck(this, OkWorker);
|
|
11
25
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
_proto.destroy = function destroy() {
|
|
21
|
-
var _this_worker;
|
|
22
|
-
(_this_worker = this.worker) === null || _this_worker === void 0 ? void 0 : _this_worker.terminate();
|
|
23
|
-
};
|
|
24
|
-
_proto.postMessage = function postMessage(message) {
|
|
25
|
-
var _this_worker;
|
|
26
|
-
(_this_worker = this.worker) === null || _this_worker === void 0 ? void 0 : _this_worker.postMessage(message);
|
|
27
|
-
};
|
|
28
|
-
OkWorker.createWorker = function createWorker() {
|
|
29
|
-
var blob = new Blob([
|
|
30
|
-
"(".concat(OkWorker.createWorkerFunction().toString(), ")()")
|
|
31
|
-
]);
|
|
32
|
-
var url = window.URL.createObjectURL(blob);
|
|
33
|
-
return new Worker(url);
|
|
34
|
-
};
|
|
35
|
-
OkWorker.createWorkerFunction = function createWorkerFunction() {
|
|
36
|
-
return function() {
|
|
37
|
-
var createHandler = function createHandler(parentKey) {
|
|
38
|
-
return {
|
|
39
|
-
get: function get(target, key, value) {
|
|
40
|
-
return Reflect.get(target, key, value);
|
|
41
|
-
},
|
|
42
|
-
set: function set(target, key, value) {
|
|
43
|
-
if (parentKey) {
|
|
44
|
-
_self.postMessage({
|
|
45
|
-
action: "update",
|
|
46
|
-
key: "".concat(parentKey, ".").concat(key)
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
return Reflect.set(target, key, value);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
log("\uD83D\uDE80 worker running");
|
|
54
|
-
var _self = self;
|
|
55
|
-
// function createProxy(
|
|
56
|
-
// obj: Record<string, unknown> | Array<Record<string, unknown>>,
|
|
57
|
-
// parentKey?: string
|
|
58
|
-
// ) {
|
|
59
|
-
// for (const key in obj) {
|
|
60
|
-
// if (Array.isArray(obj[key])) {
|
|
61
|
-
//
|
|
62
|
-
// }
|
|
63
|
-
// }
|
|
64
|
-
// return new Proxy(obj, createHandler(parentKey))
|
|
65
|
-
// }
|
|
66
|
-
_self.addEventListener("message", function(event) {
|
|
67
|
-
var _event_data = event.data, action = _event_data.action, payload = _event_data.payload, fn = _event_data.fn;
|
|
68
|
-
log(action, payload);
|
|
69
|
-
// 通过proxy进行代理,每次修改的时候,自动向外抛出postMessage
|
|
70
|
-
// data.key1 = 1
|
|
71
|
-
//
|
|
72
|
-
// data.key2.amount = 1
|
|
73
|
-
//
|
|
74
|
-
// data.key3[0].key1 = 2
|
|
75
|
-
//
|
|
76
|
-
// const result = fn(data, schema)
|
|
77
|
-
_self.postMessage({
|
|
78
|
-
action: "delete",
|
|
79
|
-
payload: {
|
|
80
|
-
key: "key3[0].key1",
|
|
81
|
-
value: "index"
|
|
82
|
-
}
|
|
26
|
+
_createClass(OkWorker, [
|
|
27
|
+
{
|
|
28
|
+
key: "run",
|
|
29
|
+
value: function run(initState) {
|
|
30
|
+
this.worker = OkWorker.createWorker();
|
|
31
|
+
this.postMessage({
|
|
32
|
+
action: 'init',
|
|
33
|
+
payload: initState
|
|
83
34
|
});
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
key: "destroy",
|
|
39
|
+
value: function destroy() {
|
|
40
|
+
var ref;
|
|
41
|
+
(ref = this.worker) === null || ref === void 0 ? void 0 : ref.terminate();
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
key: "postMessage",
|
|
46
|
+
value: function postMessage(message) {
|
|
47
|
+
var ref;
|
|
48
|
+
(ref = this.worker) === null || ref === void 0 ? void 0 : ref.postMessage(message);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
], [
|
|
52
|
+
{
|
|
53
|
+
key: "createWorker",
|
|
54
|
+
value: function createWorker() {
|
|
55
|
+
var blob = new Blob([
|
|
56
|
+
"(".concat(OkWorker.createWorkerFunction().toString(), ")()")
|
|
57
|
+
]);
|
|
58
|
+
var url = window.URL.createObjectURL(blob);
|
|
59
|
+
return new Worker(url);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
key: "createWorkerFunction",
|
|
64
|
+
value: function createWorkerFunction() {
|
|
65
|
+
return function() {
|
|
66
|
+
var createHandler = function createHandler(parentKey) {
|
|
67
|
+
return {
|
|
68
|
+
get: function get(target, key, value) {
|
|
69
|
+
return Reflect.get(target, key, value);
|
|
70
|
+
},
|
|
71
|
+
set: function set(target, key, value) {
|
|
72
|
+
if (parentKey) {
|
|
73
|
+
_self.postMessage({
|
|
74
|
+
action: 'update',
|
|
75
|
+
key: "".concat(parentKey, ".").concat(key)
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return Reflect.set(target, key, value);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
log('🚀 worker running');
|
|
83
|
+
var _self = self;
|
|
84
|
+
// function createProxy(
|
|
85
|
+
// obj: Record<string, unknown> | Array<Record<string, unknown>>,
|
|
86
|
+
// parentKey?: string
|
|
87
|
+
// ) {
|
|
88
|
+
// for (const key in obj) {
|
|
89
|
+
// if (Array.isArray(obj[key])) {
|
|
90
|
+
//
|
|
91
|
+
// }
|
|
92
|
+
// }
|
|
93
|
+
// return new Proxy(obj, createHandler(parentKey))
|
|
94
|
+
// }
|
|
95
|
+
_self.addEventListener('message', function(event) {
|
|
96
|
+
var _data = event.data, action = _data.action, payload = _data.payload, fn = _data.fn;
|
|
97
|
+
log(action, payload);
|
|
98
|
+
// 通过proxy进行代理,每次修改的时候,自动向外抛出postMessage
|
|
99
|
+
// data.key1 = 1
|
|
100
|
+
//
|
|
101
|
+
// data.key2.amount = 1
|
|
102
|
+
//
|
|
103
|
+
// data.key3[0].key1 = 2
|
|
104
|
+
//
|
|
105
|
+
// const result = fn(data, schema)
|
|
106
|
+
_self.postMessage({
|
|
107
|
+
action: 'delete',
|
|
108
|
+
payload: {
|
|
109
|
+
key: 'key3[0].key1',
|
|
110
|
+
value: 'index'
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
]);
|
|
87
118
|
return OkWorker;
|
|
88
119
|
}();
|
|
89
120
|
export { OkWorker };
|
|
@@ -83,17 +83,17 @@ function _createSuper(Derived) {
|
|
|
83
83
|
return _possibleConstructorReturn(this, result);
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
|
-
import { RegisterControls } from
|
|
87
|
-
import { CONTROL_BASE_TYPE, CONTROL_TYPE, loopFormSchema } from
|
|
88
|
-
import { hasChildrenControl, loopDataViewControl, loopFormControl } from
|
|
89
|
-
export var Runtime = /*#__PURE__*/ function(
|
|
86
|
+
import { RegisterControls } from '@byteluck-fe/model-driven-core';
|
|
87
|
+
import { CONTROL_BASE_TYPE, CONTROL_TYPE, loopFormSchema } from '@byteluck-fe/model-driven-shared';
|
|
88
|
+
import { hasChildrenControl, loopDataViewControl, loopFormControl } from '../utils/runtimeUtils';
|
|
89
|
+
export var Runtime = /*#__PURE__*/ function(RegisterControls1) {
|
|
90
90
|
"use strict";
|
|
91
|
-
_inherits(Runtime,
|
|
91
|
+
_inherits(Runtime, RegisterControls1);
|
|
92
92
|
var _super = _createSuper(Runtime);
|
|
93
93
|
function Runtime(props) {
|
|
94
94
|
_classCallCheck(this, Runtime);
|
|
95
95
|
var _this;
|
|
96
|
-
_this = _super.call(this,
|
|
96
|
+
_this = _super.call(this, 'Runtime');
|
|
97
97
|
_this._flatInstances = [];
|
|
98
98
|
_this._instanceMap = {};
|
|
99
99
|
var schema = props.schema;
|
|
@@ -102,26 +102,28 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
|
|
|
102
102
|
_this.getFlatInstances();
|
|
103
103
|
return _this;
|
|
104
104
|
}
|
|
105
|
-
var _proto = Runtime.prototype;
|
|
106
|
-
_proto.getFlatInstances = function getFlatInstances() {
|
|
107
|
-
var instances = [];
|
|
108
|
-
var instanceMap = {};
|
|
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
|
-
}
|
|
114
|
-
instances.push(item);
|
|
115
|
-
if (!instanceMap[item.id]) {
|
|
116
|
-
instanceMap[item.id] = [];
|
|
117
|
-
}
|
|
118
|
-
instanceMap[item.id].push(item);
|
|
119
|
-
});
|
|
120
|
-
this._flatInstances = instances;
|
|
121
|
-
this._instanceMap = instanceMap;
|
|
122
|
-
return this._flatInstances;
|
|
123
|
-
};
|
|
124
105
|
_createClass(Runtime, [
|
|
106
|
+
{
|
|
107
|
+
key: "getFlatInstances",
|
|
108
|
+
value: function getFlatInstances() {
|
|
109
|
+
var instances = [];
|
|
110
|
+
var instanceMap = {};
|
|
111
|
+
loop(this._instance, function(item) {
|
|
112
|
+
// 3.4.1 避免将subtable-row 放到 _flatInstances 中
|
|
113
|
+
if (item.type === 'subtable-row' || item.type === 'subtable-column') {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
instances.push(item);
|
|
117
|
+
if (!instanceMap[item.id]) {
|
|
118
|
+
instanceMap[item.id] = [];
|
|
119
|
+
}
|
|
120
|
+
instanceMap[item.id].push(item);
|
|
121
|
+
});
|
|
122
|
+
this._flatInstances = instances;
|
|
123
|
+
this._instanceMap = instanceMap;
|
|
124
|
+
return this._flatInstances;
|
|
125
|
+
}
|
|
126
|
+
},
|
|
125
127
|
{
|
|
126
128
|
key: "schema",
|
|
127
129
|
get: function get() {
|
|
@@ -217,8 +219,12 @@ function loop(control, callback) {
|
|
|
217
219
|
control.map(function(item) {
|
|
218
220
|
callback(item);
|
|
219
221
|
if (hasChildrenControl(item)) {
|
|
222
|
+
var ctl = item;
|
|
223
|
+
if (!ctl.children) {
|
|
224
|
+
ctl.children = [];
|
|
225
|
+
}
|
|
220
226
|
// @ts-ignore
|
|
221
|
-
loop(
|
|
227
|
+
loop(ctl.children, callback);
|
|
222
228
|
}
|
|
223
229
|
});
|
|
224
230
|
} else {
|
|
@@ -247,7 +253,7 @@ item) {
|
|
|
247
253
|
} else if (item.type === CONTROL_TYPE.SUBTABLE) {
|
|
248
254
|
data[item.id] = item.rules;
|
|
249
255
|
var itemRules = {
|
|
250
|
-
type:
|
|
256
|
+
type: 'array',
|
|
251
257
|
fields: {}
|
|
252
258
|
};
|
|
253
259
|
item.children.forEach(function(row, index) {
|
|
@@ -255,7 +261,7 @@ item) {
|
|
|
255
261
|
if (itemRules.fields) {
|
|
256
262
|
if (!itemRules.fields[index]) {
|
|
257
263
|
itemRules.fields[index] = {
|
|
258
|
-
type:
|
|
264
|
+
type: 'object',
|
|
259
265
|
required: true,
|
|
260
266
|
fields: {}
|
|
261
267
|
};
|