@byteluck-fe/model-driven-engine 4.53.0-lx2 → 4.54.0-lx1

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,134 +0,0 @@
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 };
@@ -1,10 +0,0 @@
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 };
@@ -1,454 +0,0 @@
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
- // 3.4.1 避免将subtable-row 放到 _flatInstances 中
114
- //4.3.0-lh2 将自处注释掉,为使instance.parent能取到父级
115
- // if (item.type === 'subtable-row' || item.type === 'subtable-column') {
116
- // return
117
- // }
118
- if (parentId) {
119
- // @ts-ignore
120
- controlParentIdMap[item.id] = parentId;
121
- }
122
- if (!instanceMap[item.id]) {
123
- instanceMap[item.id] = [];
124
- }
125
- //不知为何subtable-column会多存一次
126
- if (item.type === 'subtable-column') {
127
- if (instanceMap[item.id].length > 0) {
128
- return;
129
- }
130
- }
131
- instances.push(item);
132
- instanceMap[item.id].push(item);
133
- });
134
- this._flatInstances = instances;
135
- this._instanceMap = instanceMap;
136
- this._controlParentIdMap = controlParentIdMap;
137
- return this._flatInstances;
138
- }
139
- },
140
- {
141
- key: "schema",
142
- get: function get() {
143
- return this._schema;
144
- }
145
- },
146
- {
147
- key: "instance",
148
- get: function get() {
149
- return this._instance;
150
- }
151
- },
152
- {
153
- key: "flatInstances",
154
- get: function get() {
155
- return this._flatInstances;
156
- }
157
- },
158
- {
159
- key: "instanceMap",
160
- get: function get() {
161
- return this._instanceMap;
162
- }
163
- },
164
- {
165
- key: "allRules",
166
- get: function get() {
167
- var defaultAntdRules = {};
168
- var defaultRule = {};
169
- var defaultFieldRules = {};
170
- loopDataViewControl(this._instance, function(dataView) {
171
- var result = Runtime.staticGetRules(dataView.type, dataView.props);
172
- defaultRule[dataView.id] = JSONCopy(result[0]);
173
- defaultAntdRules[dataView.id] = JSONCopy(result[0]);
174
- defaultFieldRules[dataView.id] = JSONCopy(result[0]);
175
- loopFormControl(dataView.children, function(item) {
176
- // if (
177
- // item instanceof RuntimeFormControl ||
178
- // item instanceof RuntimeListControl
179
- // ) {
180
- if (item.controlType === CONTROL_BASE_TYPE.FORM || item.controlType === CONTROL_BASE_TYPE.LIST) {
181
- buildControlRules(defaultRule[dataView.id].fields, item, true);
182
- buildControlAntdRules(defaultAntdRules[dataView.id].fields, item, true);
183
- buildFieldCodeRules(defaultFieldRules[dataView.id].fields, item, true);
184
- }
185
- });
186
- });
187
- return {
188
- rules: this.rules,
189
- antdRules: this.antdRules,
190
- fieldCodeRules: this.fieldCodeRules,
191
- defaultAntdRules: defaultAntdRules,
192
- defaultRule: defaultRule,
193
- defaultFieldRules: defaultFieldRules
194
- };
195
- }
196
- },
197
- {
198
- key: "rules",
199
- get: function get() {
200
- var ruleItems = {};
201
- loopDataViewControl(this._instance, function(dataView) {
202
- var result = Runtime.staticGetRules(dataView.type, dataView.props);
203
- // ruleItems[dataView.id] = dataView.rules[0]
204
- ruleItems[dataView.id] = result[0];
205
- loopFormControl(dataView.children, function(item) {
206
- // if (
207
- // item instanceof RuntimeFormControl ||
208
- // item instanceof RuntimeListControl
209
- // ) {
210
- if (item.controlType === CONTROL_BASE_TYPE.FORM || item.controlType === CONTROL_BASE_TYPE.LIST) {
211
- buildControlRules(ruleItems[dataView.id].fields, item);
212
- }
213
- });
214
- });
215
- return ruleItems;
216
- }
217
- },
218
- {
219
- key: "fieldCodeRules",
220
- get: function get() {
221
- var ruleItems = {};
222
- loopDataViewControl(this._instance, function(dataView) {
223
- var result = Runtime.staticGetRules(dataView.type, dataView.props);
224
- // ruleItems[dataView.id] = dataView.rules[0]
225
- ruleItems[dataView.id] = result[0];
226
- loopFormControl(dataView.children, function(item) {
227
- // if (
228
- // item instanceof RuntimeFormControl ||
229
- // item instanceof RuntimeListControl
230
- // ) {
231
- if (item.controlType === CONTROL_BASE_TYPE.FORM || item.controlType === CONTROL_BASE_TYPE.LIST) {
232
- buildFieldCodeRules(ruleItems[dataView.id].fields, item);
233
- }
234
- });
235
- });
236
- return ruleItems;
237
- }
238
- },
239
- {
240
- key: "antdRules",
241
- get: function get() {
242
- var antdRules = {};
243
- loopDataViewControl(this._instance, function(dataView) {
244
- var result = Runtime.staticGetRules(dataView.type, dataView.props);
245
- // antdRules[dataView.id] = dataView.rules[0]
246
- antdRules[dataView.id] = result[0];
247
- loopFormControl(dataView.children, function(item) {
248
- // if (
249
- // item instanceof RuntimeFormControl ||
250
- // item instanceof RuntimeListControl
251
- // ) {
252
- if (item.controlType === CONTROL_BASE_TYPE.FORM || item.controlType === CONTROL_BASE_TYPE.LIST) {
253
- buildControlAntdRules(antdRules[dataView.id].fields, item);
254
- }
255
- });
256
- });
257
- return antdRules;
258
- }
259
- }
260
- ]);
261
- return Runtime;
262
- }(RegisterControls);
263
- function loop(control, parentId, callback) {
264
- var _instances = Array.isArray(control) ? control : [
265
- control
266
- ];
267
- _instances.map(function(item) {
268
- callback(item, parentId);
269
- if (hasChildrenControl(item)) {
270
- var ctl = item;
271
- if (!ctl.children) {
272
- ctl.children = [];
273
- }
274
- // @ts-ignore
275
- loop(ctl.children, ctl.id, callback);
276
- }
277
- if (hasHeaderOrFooterControl(item, 'headers')) {
278
- loop(item.props.headers, item.id, callback);
279
- }
280
- if (hasHeaderOrFooterControl(item, 'footers')) {
281
- loop(item.props.footers, item.id, callback);
282
- }
283
- });
284
- }
285
- function hasHeaderOrFooterControl(control, checkType) {
286
- return checkType in control.props && isArray(control.props[checkType]);
287
- }
288
- /**
289
- * 控件是否在视图中隐藏,遍历查找所有parent
290
- * */ function getControlIsHide(control) {
291
- if (control.props.isHide) {
292
- return true;
293
- }
294
- if (control.parent === null || control.parent === undefined) {
295
- return false;
296
- }
297
- return getControlIsHide(control.parent);
298
- }
299
- function buildControlRules(data, // @ts-ignore
300
- item) {
301
- var isSubtableDefaultRules = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
302
- if (getControlIsHide(item)) {
303
- return;
304
- }
305
- var result = Runtime.staticGetRules(item.type, item.props);
306
- // if (item instanceof RuntimeFormControl) {
307
- if (item.controlType === CONTROL_BASE_TYPE.FORM) {
308
- // data[item.id] = item.rules
309
- data[item.id] = result;
310
- } else if (item.type === CONTROL_TYPE.SUBTABLE) {
311
- // data[item.id] = item.rules
312
- data[item.id] = result;
313
- var itemRules = {
314
- type: 'array',
315
- fields: {}
316
- };
317
- (isSubtableDefaultRules === true ? [
318
- {
319
- children: item.props.headers
320
- }
321
- ] : item.children).forEach(function(row, index) {
322
- loopFormSchema(row.children, function(formControl) {
323
- if (itemRules.fields) {
324
- if (!itemRules.fields[index]) {
325
- itemRules.fields[index] = {
326
- type: 'object',
327
- required: true,
328
- fields: {}
329
- };
330
- }
331
- // // @ts-ignore
332
- // itemRules.fields[index].fields[formControl.id] = (
333
- // formControl as RuntimeFormControl
334
- // ).rules
335
- var childResult = Runtime.staticGetRules(formControl.type, formControl.props);
336
- // @ts-ignore
337
- itemRules.fields[index].fields[formControl.id] = childResult;
338
- }
339
- });
340
- });
341
- data[item.id].push(itemRules);
342
- }
343
- }
344
- function buildFieldCodeRules(data, // @ts-ignore
345
- item) {
346
- var isSubtableDefaultRules = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
347
- if (getControlIsHide(item)) {
348
- return;
349
- }
350
- var result = Runtime.staticGetRules(item.type, item.props);
351
- // if (item instanceof RuntimeFormControl) {
352
- if (item.controlType === CONTROL_BASE_TYPE.FORM) {
353
- if (isDataBind(item.props.dataBind)) {
354
- var _item_props_dataBind;
355
- if (((_item_props_dataBind = item.props.dataBind) === null || _item_props_dataBind === void 0 ? void 0 : _item_props_dataBind.fieldCode) != '') {
356
- var _item_props_dataBind1;
357
- data[(_item_props_dataBind1 = item.props.dataBind) === null || _item_props_dataBind1 === void 0 ? void 0 : _item_props_dataBind1.fieldCode] = result;
358
- }
359
- } else {
360
- for(var dataBindKey in item.props.dataBind){
361
- var _item_props_dataBind_dataBindKey;
362
- // @ts-ignore
363
- if (((_item_props_dataBind_dataBindKey = item.props.dataBind[dataBindKey]) === null || _item_props_dataBind_dataBindKey === void 0 ? void 0 : _item_props_dataBind_dataBindKey.fieldCode) != '') {
364
- var // @ts-ignore
365
- _item_props_dataBind_dataBindKey1, _findFields;
366
- // @ts-ignore
367
- 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]) || [];
368
- }
369
- }
370
- }
371
- } else if (item.type === CONTROL_TYPE.SUBTABLE) {
372
- var _item_props_datasourceBind, _item_props_datasourceBind1;
373
- data[(_item_props_datasourceBind = item.props.datasourceBind) === null || _item_props_datasourceBind === void 0 ? void 0 : _item_props_datasourceBind.dataCode] = result;
374
- var itemRules = {
375
- type: 'array',
376
- fields: {}
377
- };
378
- (isSubtableDefaultRules === true ? [
379
- {
380
- children: item.props.headers
381
- }
382
- ] : item.children).forEach(function(row, index) {
383
- loopFormSchema(row.children, function(formControl) {
384
- if (itemRules.fields) {
385
- if (!itemRules.fields[index]) {
386
- itemRules.fields[index] = {
387
- type: 'object',
388
- required: true,
389
- fields: {}
390
- };
391
- }
392
- var childResult = Runtime.staticGetRules(formControl.type, formControl.props);
393
- if (!isDataBind(formControl.props.dataBind)) {
394
- for(var dataBindKey in formControl.props.dataBind){
395
- var _formControl_props_dataBind_dataBindKey;
396
- // @ts-ignore
397
- if (((_formControl_props_dataBind_dataBindKey = formControl.props.dataBind[dataBindKey]) === null || _formControl_props_dataBind_dataBindKey === void 0 ? void 0 : _formControl_props_dataBind_dataBindKey.fieldCode) != '') {
398
- var _findFields;
399
- // @ts-ignore
400
- itemRules.fields[index].fields[// @ts-ignore
401
- formControl.props.dataBind[dataBindKey].fieldCode] = ((_findFields = findFields(childResult)) === null || _findFields === void 0 ? void 0 : _findFields[dataBindKey]) || [];
402
- }
403
- }
404
- } else {
405
- var _formControl_props_dataBind;
406
- if (((_formControl_props_dataBind = formControl.props.dataBind) === null || _formControl_props_dataBind === void 0 ? void 0 : _formControl_props_dataBind.fieldCode) != '') {
407
- var _formControl_props_dataBind1;
408
- // @ts-ignore
409
- itemRules.fields[index].fields[(_formControl_props_dataBind1 = formControl.props.dataBind) === null || _formControl_props_dataBind1 === void 0 ? void 0 : _formControl_props_dataBind1.fieldCode] = childResult;
410
- }
411
- }
412
- }
413
- });
414
- });
415
- data[(_item_props_datasourceBind1 = item.props.datasourceBind) === null || _item_props_datasourceBind1 === void 0 ? void 0 : _item_props_datasourceBind1.dataCode].push(itemRules);
416
- }
417
- }
418
- function findFields(childResult) {
419
- var ruleItem = {};
420
- childResult.map(function(item) {
421
- if (item.fields) {
422
- ruleItem = item;
423
- }
424
- });
425
- return ruleItem === null || ruleItem === void 0 ? void 0 : ruleItem.fields;
426
- }
427
- function buildControlAntdRules(antdRules, // @ts-ignore
428
- item) {
429
- var isSubtableDefaultRules = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
430
- if (getControlIsHide(item)) {
431
- return;
432
- }
433
- var result = Runtime.staticGetRules(item.type, item.props);
434
- // if (item instanceof RuntimeFormControl) {
435
- if (item.controlType === CONTROL_BASE_TYPE.FORM) {
436
- // antdRules[item.id] = item.rules
437
- antdRules[item.id] = result;
438
- } else if (item.type === CONTROL_TYPE.SUBTABLE && item.children.length) {
439
- antdRules[item.id] = [];
440
- (isSubtableDefaultRules === true ? [
441
- {
442
- children: item.props.headers
443
- }
444
- ] : item.children).forEach(function(row) {
445
- var rules = {};
446
- loopFormSchema(row.children, function(formControl) {
447
- // rules[formControl.id] = (formControl as RuntimeFormControl).rules
448
- var childResult = Runtime.staticGetRules(formControl.type, formControl.props);
449
- rules[formControl.id] = childResult;
450
- });
451
- antdRules[item.id].push(rules);
452
- });
453
- }
454
- }