@byteluck-fe/model-driven-engine 2.23.0-beta.26-chrome86 → 2.23.0-beta.26-chrome86-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.
- package/README.md +30 -30
- package/dist/esm/common/ActionManager.js +269 -0
- package/dist/esm/common/DataManager.js +208 -0
- package/dist/esm/common/Engine.js +1787 -0
- package/dist/esm/common/OkWorker.js +134 -0
- package/dist/esm/common/Plugin.js +10 -0
- package/dist/esm/common/Runtime.js +458 -0
- package/dist/esm/common/Store.js +443 -0
- package/dist/esm/common/checkerValue.js +609 -0
- package/dist/esm/common/index.js +2 -0
- package/dist/esm/common/proxyState.js +321 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/plugins/CalcPlugin.js +500 -0
- package/dist/esm/plugins/ControlsEventPlugin.js +315 -0
- package/dist/esm/plugins/ES6ModulePlugin.js +210 -0
- package/dist/esm/plugins/LifecycleEventPlugin.js +310 -0
- package/dist/esm/plugins/StylePlugin.js +73 -0
- package/dist/esm/plugins/index.js +5 -0
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/runtimeUtils.js +45 -0
- package/dist/index.umd.js +22 -0
- package/dist/types/common/ActionManager.d.ts +14 -14
- package/dist/types/common/DataManager.d.ts +10 -10
- package/dist/types/common/Engine.d.ts +201 -0
- package/dist/types/common/OkWorker.d.ts +13 -13
- package/dist/types/common/Plugin.d.ts +6 -6
- package/dist/types/common/Runtime.d.ts +31 -31
- package/dist/types/common/Store.d.ts +54 -54
- package/dist/types/common/checkerValue.d.ts +3 -3
- package/dist/types/common/index.d.ts +2 -2
- package/dist/types/common/proxyState.d.ts +30 -30
- package/dist/types/index.d.ts +3 -3
- package/dist/types/plugins/CalcPlugin.d.ts +121 -121
- package/dist/types/plugins/ControlsEventPlugin.d.ts +17 -17
- package/dist/types/plugins/ES6ModulePlugin.d.ts +27 -27
- package/dist/types/plugins/LifecycleEventPlugin.d.ts +15 -15
- package/dist/types/plugins/StylePlugin.d.ts +13 -13
- package/dist/types/plugins/index.d.ts +5 -5
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/runtimeUtils.d.ts +5 -5
- package/package.json +4 -4
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
function _class_call_check(instance, Constructor) {
|
|
2
|
+
if (!(instance instanceof Constructor)) {
|
|
3
|
+
throw new TypeError("Cannot call a class as a function");
|
|
4
|
+
}
|
|
5
|
+
}
|
|
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 _create_class(Constructor, protoProps, staticProps) {
|
|
16
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
17
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
18
|
+
return Constructor;
|
|
19
|
+
}
|
|
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';
|
|
34
|
+
var OkWorker = /*#__PURE__*/ function() {
|
|
35
|
+
"use strict";
|
|
36
|
+
function OkWorker() {
|
|
37
|
+
_class_call_check(this, OkWorker);
|
|
38
|
+
_define_property(this, "worker", void 0);
|
|
39
|
+
}
|
|
40
|
+
_create_class(OkWorker, [
|
|
41
|
+
{
|
|
42
|
+
key: "run",
|
|
43
|
+
value: function run(initState) {
|
|
44
|
+
this.worker = OkWorker.createWorker();
|
|
45
|
+
this.postMessage({
|
|
46
|
+
action: 'init',
|
|
47
|
+
payload: initState
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
key: "destroy",
|
|
53
|
+
value: function destroy() {
|
|
54
|
+
var _this_worker;
|
|
55
|
+
(_this_worker = this.worker) === null || _this_worker === void 0 ? void 0 : _this_worker.terminate();
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
key: "postMessage",
|
|
60
|
+
value: function postMessage(message) {
|
|
61
|
+
var _this_worker;
|
|
62
|
+
(_this_worker = this.worker) === null || _this_worker === void 0 ? void 0 : _this_worker.postMessage(message);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
], [
|
|
66
|
+
{
|
|
67
|
+
key: "createWorker",
|
|
68
|
+
value: function createWorker() {
|
|
69
|
+
var blob = new Blob([
|
|
70
|
+
"(".concat(OkWorker.createWorkerFunction().toString(), ")()")
|
|
71
|
+
]);
|
|
72
|
+
var url = window.URL.createObjectURL(blob);
|
|
73
|
+
return new Worker(url);
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
key: "createWorkerFunction",
|
|
78
|
+
value: function createWorkerFunction() {
|
|
79
|
+
return function() {
|
|
80
|
+
log('🚀 worker running');
|
|
81
|
+
var _self = self;
|
|
82
|
+
function createHandler(parentKey) {
|
|
83
|
+
return {
|
|
84
|
+
get: function get(target, key, value) {
|
|
85
|
+
return Reflect.get(target, key, value);
|
|
86
|
+
},
|
|
87
|
+
set: function set(target, key, value) {
|
|
88
|
+
if (parentKey) {
|
|
89
|
+
_self.postMessage({
|
|
90
|
+
action: 'update',
|
|
91
|
+
key: "".concat(parentKey, ".").concat(key)
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return Reflect.set(target, key, value);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
// function createProxy(
|
|
99
|
+
// obj: Record<string, unknown> | Array<Record<string, unknown>>,
|
|
100
|
+
// parentKey?: string
|
|
101
|
+
// ) {
|
|
102
|
+
// for (const key in obj) {
|
|
103
|
+
// if (Array.isArray(obj[key])) {
|
|
104
|
+
//
|
|
105
|
+
// }
|
|
106
|
+
// }
|
|
107
|
+
// return new Proxy(obj, createHandler(parentKey))
|
|
108
|
+
// }
|
|
109
|
+
_self.addEventListener('message', function(event) {
|
|
110
|
+
var _event_data = event.data, action = _event_data.action, payload = _event_data.payload, fn = _event_data.fn;
|
|
111
|
+
log(action, payload);
|
|
112
|
+
// 通过proxy进行代理,每次修改的时候,自动向外抛出postMessage
|
|
113
|
+
// data.key1 = 1
|
|
114
|
+
//
|
|
115
|
+
// data.key2.amount = 1
|
|
116
|
+
//
|
|
117
|
+
// data.key3[0].key1 = 2
|
|
118
|
+
//
|
|
119
|
+
// const result = fn(data, schema)
|
|
120
|
+
_self.postMessage({
|
|
121
|
+
action: 'delete',
|
|
122
|
+
payload: {
|
|
123
|
+
key: 'key3[0].key1',
|
|
124
|
+
value: 'index'
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
]);
|
|
132
|
+
return OkWorker;
|
|
133
|
+
}();
|
|
134
|
+
export { OkWorker };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function _class_call_check(instance, Constructor) {
|
|
2
|
+
if (!(instance instanceof Constructor)) {
|
|
3
|
+
throw new TypeError("Cannot call a class as a function");
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
var Plugin = function Plugin() {
|
|
7
|
+
"use strict";
|
|
8
|
+
_class_call_check(this, Plugin);
|
|
9
|
+
};
|
|
10
|
+
export { Plugin };
|
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
function _assert_this_initialized(self) {
|
|
2
|
+
if (self === void 0) {
|
|
3
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
4
|
+
}
|
|
5
|
+
return self;
|
|
6
|
+
}
|
|
7
|
+
function _call_super(_this, derived, args) {
|
|
8
|
+
derived = _get_prototype_of(derived);
|
|
9
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
10
|
+
}
|
|
11
|
+
function _class_call_check(instance, Constructor) {
|
|
12
|
+
if (!(instance instanceof Constructor)) {
|
|
13
|
+
throw new TypeError("Cannot call a class as a function");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function _defineProperties(target, props) {
|
|
17
|
+
for(var i = 0; i < props.length; i++){
|
|
18
|
+
var descriptor = props[i];
|
|
19
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
20
|
+
descriptor.configurable = true;
|
|
21
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
22
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
26
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
27
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
28
|
+
return Constructor;
|
|
29
|
+
}
|
|
30
|
+
function _define_property(obj, key, value) {
|
|
31
|
+
if (key in obj) {
|
|
32
|
+
Object.defineProperty(obj, key, {
|
|
33
|
+
value: value,
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
obj[key] = value;
|
|
40
|
+
}
|
|
41
|
+
return obj;
|
|
42
|
+
}
|
|
43
|
+
function _get_prototype_of(o) {
|
|
44
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
45
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
46
|
+
};
|
|
47
|
+
return _get_prototype_of(o);
|
|
48
|
+
}
|
|
49
|
+
function _inherits(subClass, superClass) {
|
|
50
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
51
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
52
|
+
}
|
|
53
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
54
|
+
constructor: {
|
|
55
|
+
value: subClass,
|
|
56
|
+
writable: true,
|
|
57
|
+
configurable: true
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
61
|
+
}
|
|
62
|
+
function _possible_constructor_return(self, call) {
|
|
63
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
64
|
+
return call;
|
|
65
|
+
}
|
|
66
|
+
return _assert_this_initialized(self);
|
|
67
|
+
}
|
|
68
|
+
function _set_prototype_of(o, p) {
|
|
69
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
70
|
+
o.__proto__ = p;
|
|
71
|
+
return o;
|
|
72
|
+
};
|
|
73
|
+
return _set_prototype_of(o, p);
|
|
74
|
+
}
|
|
75
|
+
function _type_of(obj) {
|
|
76
|
+
"@swc/helpers - typeof";
|
|
77
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
78
|
+
}
|
|
79
|
+
function _is_native_reflect_construct() {
|
|
80
|
+
try {
|
|
81
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
82
|
+
} catch (_) {}
|
|
83
|
+
return (_is_native_reflect_construct = function() {
|
|
84
|
+
return !!result;
|
|
85
|
+
})();
|
|
86
|
+
}
|
|
87
|
+
import { RegisterControls, isDataBind } from '@byteluck-fe/model-driven-core';
|
|
88
|
+
import { CONTROL_BASE_TYPE, CONTROL_TYPE, JSONCopy, loopFormSchema, isArray } from '@byteluck-fe/model-driven-shared';
|
|
89
|
+
import { hasChildrenControl, loopDataViewControl, loopFormControl } from '../utils/runtimeUtils';
|
|
90
|
+
export var Runtime = /*#__PURE__*/ function(RegisterControls) {
|
|
91
|
+
"use strict";
|
|
92
|
+
_inherits(Runtime, RegisterControls);
|
|
93
|
+
function Runtime(props) {
|
|
94
|
+
_class_call_check(this, Runtime);
|
|
95
|
+
var _this;
|
|
96
|
+
_this = _call_super(this, Runtime, [
|
|
97
|
+
'Runtime'
|
|
98
|
+
]), _define_property(_this, "_schema", void 0), _define_property(_this, "_instance", void 0), _define_property(_this, "_flatInstances", []), _define_property(_this, "_instanceMap", {}), _define_property(_this, "_controlParentIdMap", {});
|
|
99
|
+
var schema = props.schema;
|
|
100
|
+
_this._schema = schema;
|
|
101
|
+
_this._instance = _this.createControl(schema, props.beforeCreateInstance);
|
|
102
|
+
_this.getFlatInstances();
|
|
103
|
+
return _this;
|
|
104
|
+
}
|
|
105
|
+
_create_class(Runtime, [
|
|
106
|
+
{
|
|
107
|
+
key: "getFlatInstances",
|
|
108
|
+
value: function getFlatInstances() {
|
|
109
|
+
var instances = [];
|
|
110
|
+
var instanceMap = {};
|
|
111
|
+
var controlParentIdMap = {};
|
|
112
|
+
loop(this._instance, '', function(item, parentId) {
|
|
113
|
+
var _item_parent;
|
|
114
|
+
// 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;
|
|
122
|
+
}
|
|
123
|
+
if (!instanceMap[item.id]) {
|
|
124
|
+
instanceMap[item.id] = [];
|
|
125
|
+
}
|
|
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
|
+
if (((_item_parent = item.parent) === null || _item_parent === void 0 ? void 0 : _item_parent.type) === CONTROL_TYPE.SUBTABLE_COLUMN && item.parent.parent === undefined) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
instanceMap[item.id].push(item);
|
|
137
|
+
});
|
|
138
|
+
this._flatInstances = instances;
|
|
139
|
+
this._instanceMap = instanceMap;
|
|
140
|
+
this._controlParentIdMap = controlParentIdMap;
|
|
141
|
+
return this._flatInstances;
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
key: "schema",
|
|
146
|
+
get: function get() {
|
|
147
|
+
return this._schema;
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
key: "instance",
|
|
152
|
+
get: function get() {
|
|
153
|
+
return this._instance;
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
key: "flatInstances",
|
|
158
|
+
get: function get() {
|
|
159
|
+
return this._flatInstances;
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
key: "instanceMap",
|
|
164
|
+
get: function get() {
|
|
165
|
+
return this._instanceMap;
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
key: "allRules",
|
|
170
|
+
get: function get() {
|
|
171
|
+
var defaultAntdRules = {};
|
|
172
|
+
var defaultRule = {};
|
|
173
|
+
var defaultFieldRules = {};
|
|
174
|
+
loopDataViewControl(this._instance, function(dataView) {
|
|
175
|
+
var result = Runtime.staticGetRules(dataView.type, dataView.props);
|
|
176
|
+
defaultRule[dataView.id] = JSONCopy(result[0]);
|
|
177
|
+
defaultAntdRules[dataView.id] = JSONCopy(result[0]);
|
|
178
|
+
defaultFieldRules[dataView.id] = JSONCopy(result[0]);
|
|
179
|
+
loopFormControl(dataView.children, function(item) {
|
|
180
|
+
// if (
|
|
181
|
+
// item instanceof RuntimeFormControl ||
|
|
182
|
+
// item instanceof RuntimeListControl
|
|
183
|
+
// ) {
|
|
184
|
+
if (item.controlType === CONTROL_BASE_TYPE.FORM || item.controlType === CONTROL_BASE_TYPE.LIST) {
|
|
185
|
+
buildControlRules(defaultRule[dataView.id].fields, item, true);
|
|
186
|
+
buildControlAntdRules(defaultAntdRules[dataView.id].fields, item, true);
|
|
187
|
+
buildFieldCodeRules(defaultFieldRules[dataView.id].fields, item, true);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
return {
|
|
192
|
+
rules: this.rules,
|
|
193
|
+
antdRules: this.antdRules,
|
|
194
|
+
fieldCodeRules: this.fieldCodeRules,
|
|
195
|
+
defaultAntdRules: defaultAntdRules,
|
|
196
|
+
defaultRule: defaultRule,
|
|
197
|
+
defaultFieldRules: defaultFieldRules
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
key: "rules",
|
|
203
|
+
get: function get() {
|
|
204
|
+
var ruleItems = {};
|
|
205
|
+
loopDataViewControl(this._instance, function(dataView) {
|
|
206
|
+
var result = Runtime.staticGetRules(dataView.type, dataView.props);
|
|
207
|
+
// ruleItems[dataView.id] = dataView.rules[0]
|
|
208
|
+
ruleItems[dataView.id] = result[0];
|
|
209
|
+
loopFormControl(dataView.children, function(item) {
|
|
210
|
+
// if (
|
|
211
|
+
// item instanceof RuntimeFormControl ||
|
|
212
|
+
// item instanceof RuntimeListControl
|
|
213
|
+
// ) {
|
|
214
|
+
if (item.controlType === CONTROL_BASE_TYPE.FORM || item.controlType === CONTROL_BASE_TYPE.LIST) {
|
|
215
|
+
buildControlRules(ruleItems[dataView.id].fields, item);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
return ruleItems;
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
key: "fieldCodeRules",
|
|
224
|
+
get: function get() {
|
|
225
|
+
var ruleItems = {};
|
|
226
|
+
loopDataViewControl(this._instance, function(dataView) {
|
|
227
|
+
var result = Runtime.staticGetRules(dataView.type, dataView.props);
|
|
228
|
+
// ruleItems[dataView.id] = dataView.rules[0]
|
|
229
|
+
ruleItems[dataView.id] = result[0];
|
|
230
|
+
loopFormControl(dataView.children, function(item) {
|
|
231
|
+
// if (
|
|
232
|
+
// item instanceof RuntimeFormControl ||
|
|
233
|
+
// item instanceof RuntimeListControl
|
|
234
|
+
// ) {
|
|
235
|
+
if (item.controlType === CONTROL_BASE_TYPE.FORM || item.controlType === CONTROL_BASE_TYPE.LIST) {
|
|
236
|
+
buildFieldCodeRules(ruleItems[dataView.id].fields, item);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
return ruleItems;
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
key: "antdRules",
|
|
245
|
+
get: function get() {
|
|
246
|
+
var antdRules = {};
|
|
247
|
+
loopDataViewControl(this._instance, function(dataView) {
|
|
248
|
+
var result = Runtime.staticGetRules(dataView.type, dataView.props);
|
|
249
|
+
// antdRules[dataView.id] = dataView.rules[0]
|
|
250
|
+
antdRules[dataView.id] = result[0];
|
|
251
|
+
loopFormControl(dataView.children, function(item) {
|
|
252
|
+
// if (
|
|
253
|
+
// item instanceof RuntimeFormControl ||
|
|
254
|
+
// item instanceof RuntimeListControl
|
|
255
|
+
// ) {
|
|
256
|
+
if (item.controlType === CONTROL_BASE_TYPE.FORM || item.controlType === CONTROL_BASE_TYPE.LIST) {
|
|
257
|
+
buildControlAntdRules(antdRules[dataView.id].fields, item);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
return antdRules;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
]);
|
|
265
|
+
return Runtime;
|
|
266
|
+
}(RegisterControls);
|
|
267
|
+
function loop(control, parentId, callback) {
|
|
268
|
+
var _instances = Array.isArray(control) ? control : [
|
|
269
|
+
control
|
|
270
|
+
];
|
|
271
|
+
_instances.map(function(item) {
|
|
272
|
+
callback(item, parentId);
|
|
273
|
+
if (hasChildrenControl(item)) {
|
|
274
|
+
var ctl = item;
|
|
275
|
+
if (!ctl.children) {
|
|
276
|
+
ctl.children = [];
|
|
277
|
+
}
|
|
278
|
+
// @ts-ignore
|
|
279
|
+
loop(ctl.children, ctl.id, callback);
|
|
280
|
+
}
|
|
281
|
+
if (hasHeaderOrFooterControl(item, 'headers')) {
|
|
282
|
+
loop(item.props.headers, item.id, callback);
|
|
283
|
+
}
|
|
284
|
+
// if (hasHeaderOrFooterControl(item, 'footers')) {
|
|
285
|
+
// loop((item.props as any).footers, item.id, callback)
|
|
286
|
+
// }
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
function hasHeaderOrFooterControl(control, checkType) {
|
|
290
|
+
return checkType in control.props && isArray(control.props[checkType]);
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* 控件是否在视图中隐藏,遍历查找所有parent
|
|
294
|
+
* */ function getControlIsHide(control) {
|
|
295
|
+
if (control.props.isHide) {
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
if (control.parent === null || control.parent === undefined) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
return getControlIsHide(control.parent);
|
|
302
|
+
}
|
|
303
|
+
function buildControlRules(data, // @ts-ignore
|
|
304
|
+
item) {
|
|
305
|
+
var isSubtableDefaultRules = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
|
|
306
|
+
if (getControlIsHide(item)) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
var result = Runtime.staticGetRules(item.type, item.props);
|
|
310
|
+
// if (item instanceof RuntimeFormControl) {
|
|
311
|
+
if (item.controlType === CONTROL_BASE_TYPE.FORM) {
|
|
312
|
+
// data[item.id] = item.rules
|
|
313
|
+
data[item.id] = result;
|
|
314
|
+
} else if (item.type === CONTROL_TYPE.SUBTABLE) {
|
|
315
|
+
// data[item.id] = item.rules
|
|
316
|
+
data[item.id] = result;
|
|
317
|
+
var itemRules = {
|
|
318
|
+
type: 'array',
|
|
319
|
+
fields: {}
|
|
320
|
+
};
|
|
321
|
+
(isSubtableDefaultRules === true ? [
|
|
322
|
+
{
|
|
323
|
+
children: item.props.headers
|
|
324
|
+
}
|
|
325
|
+
] : item.children).forEach(function(row, index) {
|
|
326
|
+
loopFormSchema(row.children, function(formControl) {
|
|
327
|
+
if (itemRules.fields) {
|
|
328
|
+
if (!itemRules.fields[index]) {
|
|
329
|
+
itemRules.fields[index] = {
|
|
330
|
+
type: 'object',
|
|
331
|
+
required: true,
|
|
332
|
+
fields: {}
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
// // @ts-ignore
|
|
336
|
+
// itemRules.fields[index].fields[formControl.id] = (
|
|
337
|
+
// formControl as RuntimeFormControl
|
|
338
|
+
// ).rules
|
|
339
|
+
var childResult = Runtime.staticGetRules(formControl.type, formControl.props);
|
|
340
|
+
// @ts-ignore
|
|
341
|
+
itemRules.fields[index].fields[formControl.id] = childResult;
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
data[item.id].push(itemRules);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
function buildFieldCodeRules(data, // @ts-ignore
|
|
349
|
+
item) {
|
|
350
|
+
var isSubtableDefaultRules = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
|
|
351
|
+
if (getControlIsHide(item)) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
var result = Runtime.staticGetRules(item.type, item.props);
|
|
355
|
+
// if (item instanceof RuntimeFormControl) {
|
|
356
|
+
if (item.controlType === CONTROL_BASE_TYPE.FORM) {
|
|
357
|
+
if (isDataBind(item.props.dataBind)) {
|
|
358
|
+
var _item_props_dataBind;
|
|
359
|
+
if (((_item_props_dataBind = item.props.dataBind) === null || _item_props_dataBind === void 0 ? void 0 : _item_props_dataBind.fieldCode) != '') {
|
|
360
|
+
var _item_props_dataBind1;
|
|
361
|
+
data[(_item_props_dataBind1 = item.props.dataBind) === null || _item_props_dataBind1 === void 0 ? void 0 : _item_props_dataBind1.fieldCode] = result;
|
|
362
|
+
}
|
|
363
|
+
} else {
|
|
364
|
+
for(var dataBindKey in item.props.dataBind){
|
|
365
|
+
var _item_props_dataBind_dataBindKey;
|
|
366
|
+
// @ts-ignore
|
|
367
|
+
if (((_item_props_dataBind_dataBindKey = item.props.dataBind[dataBindKey]) === null || _item_props_dataBind_dataBindKey === void 0 ? void 0 : _item_props_dataBind_dataBindKey.fieldCode) != '') {
|
|
368
|
+
var // @ts-ignore
|
|
369
|
+
_item_props_dataBind_dataBindKey1, _findFields;
|
|
370
|
+
// @ts-ignore
|
|
371
|
+
data[(_item_props_dataBind_dataBindKey1 = item.props.dataBind[dataBindKey]) === null || _item_props_dataBind_dataBindKey1 === void 0 ? void 0 : _item_props_dataBind_dataBindKey1.fieldCode] = ((_findFields = findFields(result)) === null || _findFields === void 0 ? void 0 : _findFields[dataBindKey]) || [];
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
} else if (item.type === CONTROL_TYPE.SUBTABLE) {
|
|
376
|
+
var _item_props_datasourceBind, _item_props_datasourceBind1;
|
|
377
|
+
data[(_item_props_datasourceBind = item.props.datasourceBind) === null || _item_props_datasourceBind === void 0 ? void 0 : _item_props_datasourceBind.dataCode] = result;
|
|
378
|
+
var itemRules = {
|
|
379
|
+
type: 'array',
|
|
380
|
+
fields: {}
|
|
381
|
+
};
|
|
382
|
+
(isSubtableDefaultRules === true ? [
|
|
383
|
+
{
|
|
384
|
+
children: item.props.headers
|
|
385
|
+
}
|
|
386
|
+
] : item.children).forEach(function(row, index) {
|
|
387
|
+
loopFormSchema(row.children, function(formControl) {
|
|
388
|
+
if (itemRules.fields) {
|
|
389
|
+
if (!itemRules.fields[index]) {
|
|
390
|
+
itemRules.fields[index] = {
|
|
391
|
+
type: 'object',
|
|
392
|
+
required: true,
|
|
393
|
+
fields: {}
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
var childResult = Runtime.staticGetRules(formControl.type, formControl.props);
|
|
397
|
+
if (!isDataBind(formControl.props.dataBind)) {
|
|
398
|
+
for(var dataBindKey in formControl.props.dataBind){
|
|
399
|
+
var _formControl_props_dataBind_dataBindKey;
|
|
400
|
+
// @ts-ignore
|
|
401
|
+
if (((_formControl_props_dataBind_dataBindKey = formControl.props.dataBind[dataBindKey]) === null || _formControl_props_dataBind_dataBindKey === void 0 ? void 0 : _formControl_props_dataBind_dataBindKey.fieldCode) != '') {
|
|
402
|
+
var _findFields;
|
|
403
|
+
// @ts-ignore
|
|
404
|
+
itemRules.fields[index].fields[// @ts-ignore
|
|
405
|
+
formControl.props.dataBind[dataBindKey].fieldCode] = ((_findFields = findFields(childResult)) === null || _findFields === void 0 ? void 0 : _findFields[dataBindKey]) || [];
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
} else {
|
|
409
|
+
var _formControl_props_dataBind;
|
|
410
|
+
if (((_formControl_props_dataBind = formControl.props.dataBind) === null || _formControl_props_dataBind === void 0 ? void 0 : _formControl_props_dataBind.fieldCode) != '') {
|
|
411
|
+
var _formControl_props_dataBind1;
|
|
412
|
+
// @ts-ignore
|
|
413
|
+
itemRules.fields[index].fields[(_formControl_props_dataBind1 = formControl.props.dataBind) === null || _formControl_props_dataBind1 === void 0 ? void 0 : _formControl_props_dataBind1.fieldCode] = childResult;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
});
|
|
419
|
+
data[(_item_props_datasourceBind1 = item.props.datasourceBind) === null || _item_props_datasourceBind1 === void 0 ? void 0 : _item_props_datasourceBind1.dataCode].push(itemRules);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
function findFields(childResult) {
|
|
423
|
+
var ruleItem = {};
|
|
424
|
+
childResult.map(function(item) {
|
|
425
|
+
if (item.fields) {
|
|
426
|
+
ruleItem = item;
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
return ruleItem === null || ruleItem === void 0 ? void 0 : ruleItem.fields;
|
|
430
|
+
}
|
|
431
|
+
function buildControlAntdRules(antdRules, // @ts-ignore
|
|
432
|
+
item) {
|
|
433
|
+
var isSubtableDefaultRules = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
|
|
434
|
+
if (getControlIsHide(item)) {
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
var result = Runtime.staticGetRules(item.type, item.props);
|
|
438
|
+
// if (item instanceof RuntimeFormControl) {
|
|
439
|
+
if (item.controlType === CONTROL_BASE_TYPE.FORM) {
|
|
440
|
+
// antdRules[item.id] = item.rules
|
|
441
|
+
antdRules[item.id] = result;
|
|
442
|
+
} else if (item.type === CONTROL_TYPE.SUBTABLE && item.children.length) {
|
|
443
|
+
antdRules[item.id] = [];
|
|
444
|
+
(isSubtableDefaultRules === true ? [
|
|
445
|
+
{
|
|
446
|
+
children: item.props.headers
|
|
447
|
+
}
|
|
448
|
+
] : item.children).forEach(function(row) {
|
|
449
|
+
var rules = {};
|
|
450
|
+
loopFormSchema(row.children, function(formControl) {
|
|
451
|
+
// rules[formControl.id] = (formControl as RuntimeFormControl).rules
|
|
452
|
+
var childResult = Runtime.staticGetRules(formControl.type, formControl.props);
|
|
453
|
+
rules[formControl.id] = childResult;
|
|
454
|
+
});
|
|
455
|
+
antdRules[item.id].push(rules);
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
}
|