@byteluck-fe/model-driven-engine 2.22.4-beta.1 → 2.22.4-beta.10

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 +269 -0
  3. package/dist/esm/common/DataManager.js +209 -0
  4. package/dist/esm/common/Engine.js +1785 -0
  5. package/dist/esm/common/OkWorker.js +134 -0
  6. package/dist/esm/common/Plugin.js +10 -0
  7. package/dist/esm/common/Runtime.js +458 -0
  8. package/dist/esm/common/Store.js +444 -0
  9. package/dist/esm/common/checkerValue.js +609 -0
  10. package/dist/esm/common/index.js +2 -0
  11. package/dist/esm/common/proxyState.js +321 -0
  12. package/dist/esm/index.js +3 -0
  13. package/dist/esm/plugins/CalcPlugin.js +500 -0
  14. package/dist/esm/plugins/ControlsEventPlugin.js +315 -0
  15. package/dist/esm/plugins/ES6ModulePlugin.js +210 -0
  16. package/dist/esm/plugins/LifecycleEventPlugin.js +310 -0
  17. package/dist/esm/plugins/StylePlugin.js +74 -0
  18. package/dist/esm/plugins/index.js +5 -0
  19. package/dist/esm/utils/index.js +1 -0
  20. package/dist/esm/utils/runtimeUtils.js +45 -0
  21. package/dist/index.umd.js +54 -0
  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 +201 -0
  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 +31 -31
  28. package/dist/types/common/Store.d.ts +54 -54
  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 +17 -17
  35. package/dist/types/plugins/ES6ModulePlugin.d.ts +27 -27
  36. package/dist/types/plugins/LifecycleEventPlugin.d.ts +15 -15
  37. package/dist/types/plugins/StylePlugin.d.ts +13 -13
  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 +9 -6
@@ -0,0 +1,1785 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _array_without_holes(arr) {
10
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
11
+ }
12
+ function _assert_this_initialized(self) {
13
+ if (self === void 0) {
14
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
15
+ }
16
+ return self;
17
+ }
18
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
19
+ try {
20
+ var info = gen[key](arg);
21
+ var value = info.value;
22
+ } catch (error) {
23
+ reject(error);
24
+ return;
25
+ }
26
+ if (info.done) {
27
+ resolve(value);
28
+ } else {
29
+ Promise.resolve(value).then(_next, _throw);
30
+ }
31
+ }
32
+ function _async_to_generator(fn) {
33
+ return function() {
34
+ var self = this, args = arguments;
35
+ return new Promise(function(resolve, reject) {
36
+ var gen = fn.apply(self, args);
37
+ function _next(value) {
38
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
39
+ }
40
+ function _throw(err) {
41
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
42
+ }
43
+ _next(undefined);
44
+ });
45
+ };
46
+ }
47
+ function _call_super(_this, derived, args) {
48
+ derived = _get_prototype_of(derived);
49
+ return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
50
+ }
51
+ function _class_call_check(instance, Constructor) {
52
+ if (!(instance instanceof Constructor)) {
53
+ throw new TypeError("Cannot call a class as a function");
54
+ }
55
+ }
56
+ function _defineProperties(target, props) {
57
+ for(var i = 0; i < props.length; i++){
58
+ var descriptor = props[i];
59
+ descriptor.enumerable = descriptor.enumerable || false;
60
+ descriptor.configurable = true;
61
+ if ("value" in descriptor) descriptor.writable = true;
62
+ Object.defineProperty(target, descriptor.key, descriptor);
63
+ }
64
+ }
65
+ function _create_class(Constructor, protoProps, staticProps) {
66
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
67
+ if (staticProps) _defineProperties(Constructor, staticProps);
68
+ return Constructor;
69
+ }
70
+ function _define_property(obj, key, value) {
71
+ if (key in obj) {
72
+ Object.defineProperty(obj, key, {
73
+ value: value,
74
+ enumerable: true,
75
+ configurable: true,
76
+ writable: true
77
+ });
78
+ } else {
79
+ obj[key] = value;
80
+ }
81
+ return obj;
82
+ }
83
+ function _get(target, property, receiver) {
84
+ if (typeof Reflect !== "undefined" && Reflect.get) {
85
+ _get = Reflect.get;
86
+ } else {
87
+ _get = function get(target, property, receiver) {
88
+ var base = _super_prop_base(target, property);
89
+ if (!base) return;
90
+ var desc = Object.getOwnPropertyDescriptor(base, property);
91
+ if (desc.get) {
92
+ return desc.get.call(receiver || target);
93
+ }
94
+ return desc.value;
95
+ };
96
+ }
97
+ return _get(target, property, receiver || target);
98
+ }
99
+ function _get_prototype_of(o) {
100
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
101
+ return o.__proto__ || Object.getPrototypeOf(o);
102
+ };
103
+ return _get_prototype_of(o);
104
+ }
105
+ function _inherits(subClass, superClass) {
106
+ if (typeof superClass !== "function" && superClass !== null) {
107
+ throw new TypeError("Super expression must either be null or a function");
108
+ }
109
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
110
+ constructor: {
111
+ value: subClass,
112
+ writable: true,
113
+ configurable: true
114
+ }
115
+ });
116
+ if (superClass) _set_prototype_of(subClass, superClass);
117
+ }
118
+ function _iterable_to_array(iter) {
119
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
120
+ }
121
+ function _iterable_to_array_limit(arr, i) {
122
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
123
+ if (_i == null) return;
124
+ var _arr = [];
125
+ var _n = true;
126
+ var _d = false;
127
+ var _s, _e;
128
+ try {
129
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
130
+ _arr.push(_s.value);
131
+ if (i && _arr.length === i) break;
132
+ }
133
+ } catch (err) {
134
+ _d = true;
135
+ _e = err;
136
+ } finally{
137
+ try {
138
+ if (!_n && _i["return"] != null) _i["return"]();
139
+ } finally{
140
+ if (_d) throw _e;
141
+ }
142
+ }
143
+ return _arr;
144
+ }
145
+ function _non_iterable_rest() {
146
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
147
+ }
148
+ function _non_iterable_spread() {
149
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
150
+ }
151
+ function _object_spread(target) {
152
+ for(var i = 1; i < arguments.length; i++){
153
+ var source = arguments[i] != null ? arguments[i] : {};
154
+ var ownKeys = Object.keys(source);
155
+ if (typeof Object.getOwnPropertySymbols === "function") {
156
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
157
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
158
+ }));
159
+ }
160
+ ownKeys.forEach(function(key) {
161
+ _define_property(target, key, source[key]);
162
+ });
163
+ }
164
+ return target;
165
+ }
166
+ function ownKeys(object, enumerableOnly) {
167
+ var keys = Object.keys(object);
168
+ if (Object.getOwnPropertySymbols) {
169
+ var symbols = Object.getOwnPropertySymbols(object);
170
+ if (enumerableOnly) {
171
+ symbols = symbols.filter(function(sym) {
172
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
173
+ });
174
+ }
175
+ keys.push.apply(keys, symbols);
176
+ }
177
+ return keys;
178
+ }
179
+ function _object_spread_props(target, source) {
180
+ source = source != null ? source : {};
181
+ if (Object.getOwnPropertyDescriptors) {
182
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
183
+ } else {
184
+ ownKeys(Object(source)).forEach(function(key) {
185
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
186
+ });
187
+ }
188
+ return target;
189
+ }
190
+ function _possible_constructor_return(self, call) {
191
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
192
+ return call;
193
+ }
194
+ return _assert_this_initialized(self);
195
+ }
196
+ function _set_prototype_of(o, p) {
197
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
198
+ o.__proto__ = p;
199
+ return o;
200
+ };
201
+ return _set_prototype_of(o, p);
202
+ }
203
+ function _sliced_to_array(arr, i) {
204
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
205
+ }
206
+ function _super_prop_base(object, property) {
207
+ while(!Object.prototype.hasOwnProperty.call(object, property)){
208
+ object = _get_prototype_of(object);
209
+ if (object === null) break;
210
+ }
211
+ return object;
212
+ }
213
+ function _to_consumable_array(arr) {
214
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
215
+ }
216
+ function _type_of(obj) {
217
+ "@swc/helpers - typeof";
218
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
219
+ }
220
+ function _unsupported_iterable_to_array(o, minLen) {
221
+ if (!o) return;
222
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
223
+ var n = Object.prototype.toString.call(o).slice(8, -1);
224
+ if (n === "Object" && o.constructor) n = o.constructor.name;
225
+ if (n === "Map" || n === "Set") return Array.from(n);
226
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
227
+ }
228
+ function _is_native_reflect_construct() {
229
+ try {
230
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
231
+ } catch (_) {}
232
+ return (_is_native_reflect_construct = function() {
233
+ return !!result;
234
+ })();
235
+ }
236
+ function _ts_generator(thisArg, body) {
237
+ var f, y, t, _ = {
238
+ label: 0,
239
+ sent: function() {
240
+ if (t[0] & 1) throw t[1];
241
+ return t[1];
242
+ },
243
+ trys: [],
244
+ ops: []
245
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
246
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
247
+ return this;
248
+ }), g;
249
+ function verb(n) {
250
+ return function(v) {
251
+ return step([
252
+ n,
253
+ v
254
+ ]);
255
+ };
256
+ }
257
+ function step(op) {
258
+ if (f) throw new TypeError("Generator is already executing.");
259
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
260
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
261
+ if (y = 0, t) op = [
262
+ op[0] & 2,
263
+ t.value
264
+ ];
265
+ switch(op[0]){
266
+ case 0:
267
+ case 1:
268
+ t = op;
269
+ break;
270
+ case 4:
271
+ _.label++;
272
+ return {
273
+ value: op[1],
274
+ done: false
275
+ };
276
+ case 5:
277
+ _.label++;
278
+ y = op[1];
279
+ op = [
280
+ 0
281
+ ];
282
+ continue;
283
+ case 7:
284
+ op = _.ops.pop();
285
+ _.trys.pop();
286
+ continue;
287
+ default:
288
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
289
+ _ = 0;
290
+ continue;
291
+ }
292
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
293
+ _.label = op[1];
294
+ break;
295
+ }
296
+ if (op[0] === 6 && _.label < t[1]) {
297
+ _.label = t[1];
298
+ t = op;
299
+ break;
300
+ }
301
+ if (t && _.label < t[2]) {
302
+ _.label = t[2];
303
+ _.ops.push(op);
304
+ break;
305
+ }
306
+ if (t[2]) _.ops.pop();
307
+ _.trys.pop();
308
+ continue;
309
+ }
310
+ op = body.call(thisArg, _);
311
+ } catch (e) {
312
+ op = [
313
+ 6,
314
+ e
315
+ ];
316
+ y = 0;
317
+ } finally{
318
+ f = t = 0;
319
+ }
320
+ if (op[0] & 5) throw op[1];
321
+ return {
322
+ value: op[0] ? op[1] : void 0,
323
+ done: true
324
+ };
325
+ }
326
+ }
327
+ import { isDataBind } from '@byteluck-fe/model-driven-core';
328
+ import { CONTROL_BASE_TYPE, CONTROL_TYPE, DEFAULT_LOCALE, error, genNonDuplicateId, isString, JSONCopy, log, updateValueFromKeys, warn, Watcher, isBuiltInControls } from '@byteluck-fe/model-driven-shared';
329
+ import { Runtime } from './Runtime';
330
+ import { Store } from './Store';
331
+ import { findItem, proxyState } from './proxyState';
332
+ import { ActionManager } from './ActionManager';
333
+ import { DataManager } from './DataManager';
334
+ import { checkerSubtableValue, checkerValue } from './checkerValue';
335
+ import { buildUUID } from '../utils/runtimeUtils';
336
+ if (typeof window !== 'undefined') {
337
+ // @ts-ignore
338
+ window.engines = {};
339
+ }
340
+ // setState的时候,存储options中转变量
341
+ var eventOptionsTemp = null;
342
+ // 当前正在注册的插件名称
343
+ var applyingPluginName = '';
344
+ // 整体渲染引擎 并且 提供发布订阅能力
345
+ var Engine = /*#__PURE__*/ function(Watcher) {
346
+ "use strict";
347
+ _inherits(Engine, Watcher);
348
+ function Engine(props) {
349
+ _class_call_check(this, Engine);
350
+ var _this;
351
+ _this = _call_super(this, Engine), _define_property(_this, "store", void 0), _define_property(_this, "rawStore", {}), _define_property(_this, "parent", void 0), // 提供注册运行态控件以及实例化控件的能力
352
+ _define_property(_this, "runtime", void 0), // 提供子线程处理脚本以及修改数据的能力
353
+ // public worker: OkWorker
354
+ _define_property(_this, "isMounted", false), _define_property(_this, "id", genNonDuplicateId(8)), _define_property(_this, "externalParams", void 0), _define_property(_this, "children", void 0), // 提供外部注册插件,在不同的hooks触发时执行固定函数的能力
355
+ _define_property(_this, "__plugins", void 0), _define_property(_this, "__pluginsApplied", false), _define_property(_this, "$options", void 0), _define_property(_this, "actionManager", new ActionManager()), _define_property(_this, "dataManager", void 0), _define_property(_this, "_jobTasks", []), _define_property(_this, "createControlInstance", _this.createInstance);
356
+ _this.$options = Object.freeze(props);
357
+ var _this_$options = _this.$options, _this_$options_autoMount = _this_$options.autoMount, autoMount = _this_$options_autoMount === void 0 ? true : _this_$options_autoMount, schema = _this_$options.schema, beforeCreateInstance = _this_$options.beforeCreateInstance, externalParams = _this_$options.externalParams, _this_$options_language = _this_$options.// fieldModel,
358
+ language, language = _this_$options_language === void 0 ? DEFAULT_LOCALE : _this_$options_language, _this_$options_debug = _this_$options.debug, debug = _this_$options_debug === void 0 ? false : _this_$options_debug, messagesI18n = _this_$options.messagesI18n, children = _this_$options.children;
359
+ _this.debug = debug;
360
+ _this.runtime = new Runtime({
361
+ schema: schema,
362
+ beforeCreateInstance: beforeCreateInstance
363
+ });
364
+ _this.externalParams = externalParams;
365
+ _this.children = children;
366
+ _this.store = new Store({
367
+ instance: _this.runtime.instance
368
+ });
369
+ _this.debugLog('engine is Instantiation complete');
370
+ // 自动执行挂载完成,也可以手动调用mount方法
371
+ autoMount && _this.mount();
372
+ return _this;
373
+ }
374
+ _create_class(Engine, [
375
+ {
376
+ key: "debugLog",
377
+ value: function debugLog() {
378
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
379
+ args[_key] = arguments[_key];
380
+ }
381
+ this.debug && log.apply(void 0, _to_consumable_array(args));
382
+ }
383
+ },
384
+ {
385
+ key: "use",
386
+ value: function use(plugin) {
387
+ if (!this.__pluginsApplied) {
388
+ this.__plugins.push(plugin);
389
+ }
390
+ return this;
391
+ }
392
+ },
393
+ {
394
+ key: "registerControl",
395
+ value: // 注册外部控件
396
+ function registerControl() {
397
+ for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
398
+ arg[_key] = arguments[_key];
399
+ }
400
+ var _this_runtime;
401
+ (_this_runtime = this.runtime).register.apply(_this_runtime, _to_consumable_array(arg));
402
+ return this;
403
+ }
404
+ },
405
+ {
406
+ key: "mount",
407
+ value: function mount() {
408
+ // @i18n-translate-ignore
409
+ this.debugLog("engine的mount方法开始调用");
410
+ var _this_$options = this.$options, _this_$options_plugins = _this_$options.plugins, plugins = _this_$options_plugins === void 0 ? [] : _this_$options_plugins;
411
+ this._handlerProxyState();
412
+ this.__plugins = plugins;
413
+ this.applyPlugins();
414
+ // 触发所有控件的默认值的change事件
415
+ this.setStates(this.getState());
416
+ // @i18n-translate-ignore
417
+ this.debugLog("engine的mount方法调用结束");
418
+ if (this.debug && typeof window !== 'undefined') {
419
+ // @ts-ignore
420
+ window.engines[this.id] = this;
421
+ }
422
+ }
423
+ },
424
+ {
425
+ key: "destroy",
426
+ value: function destroy() {
427
+ if (this.debug && typeof window !== 'undefined') {
428
+ // @ts-ignore
429
+ delete window.engines[this.id];
430
+ }
431
+ }
432
+ },
433
+ {
434
+ key: "_handlerProxyState",
435
+ value: function _handlerProxyState() {
436
+ this.store.state = proxyState(this.store.state, this._proxyStateCallback.bind(this), this._proxyStateBeforeSetCallback.bind(this));
437
+ }
438
+ },
439
+ {
440
+ key: "_proxyStateBeforeSetCallback",
441
+ value: function _proxyStateBeforeSetCallback(state, key, newValue, oldValue) {
442
+ var instance = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
443
+ // 找不到控件说明不是改动控件上的字段,直接通过
444
+ if (!instance) {
445
+ return newValue;
446
+ }
447
+ // @ts-ignore
448
+ if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE)) {
449
+ if (newValue === null) {
450
+ return [];
451
+ }
452
+ // @ts-ignore
453
+ var fieldTypeMap = instance.props.headers.reduce(function(result, column) {
454
+ var formInstance = column.children[0];
455
+ // if (formInstance && formInstance instanceof RuntimeFormControl) {
456
+ if (formInstance && formInstance.controlType === CONTROL_BASE_TYPE.FORM) {
457
+ result[formInstance.id] = formInstance.fieldType;
458
+ }
459
+ return result;
460
+ }, {});
461
+ // @ts-ignore
462
+ var emptyState = this.getEmptyState(instance.id);
463
+ return newValue === null || newValue === void 0 ? void 0 : newValue.map(function(row) {
464
+ return(// @ts-ignore
465
+ checkerSubtableValue(fieldTypeMap, row, emptyState));
466
+ });
467
+ }
468
+ var keys = key.split('.');
469
+ var lastKey = keys[keys.length - 1];
470
+ try {
471
+ return checkerValue(instance.fieldType, lastKey, newValue, oldValue);
472
+ } catch (e) {
473
+ warn("the id=".concat(instance.id, "'s instance setState error, %o ").concat(e, "."), newValue);
474
+ throw e;
475
+ }
476
+ }
477
+ },
478
+ {
479
+ key: "_proxyStateCallback",
480
+ value: function _proxyStateCallback(state, key, type, args, result) {
481
+ if (Array.isArray(state)) {
482
+ this._handlerArrayUpdate(state, key, type, args, result);
483
+ } else {
484
+ this._handlerObjectUpdate(state, key, type, args);
485
+ }
486
+ }
487
+ },
488
+ {
489
+ key: "_handlerArrayUpdate",
490
+ value: function _handlerArrayUpdate(state, key, type, args, result) {
491
+ var _this = this;
492
+ var subtable = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
493
+ // if (!(subtable instanceof RuntimeListControl)) return
494
+ if (!((subtable === null || subtable === void 0 ? void 0 : subtable.controlType) === CONTROL_BASE_TYPE.LIST)) return;
495
+ // 新增多行方法
496
+ var createRows = function(len) {
497
+ // @ts-ignore
498
+ var newRows = [];
499
+ for(var i = 0; i < len; i++){
500
+ // @ts-ignore
501
+ var row = _this.listControlCreateRow(subtable, 'subtable-row');
502
+ row && newRows.push(row);
503
+ }
504
+ // @ts-ignore
505
+ return newRows;
506
+ };
507
+ var options = eventOptionsTemp;
508
+ // @ts-ignore
509
+ var createdNewRows = [];
510
+ var createdNewRowsData = [];
511
+ var deleted = [];
512
+ var isDeleteLastOne = false;
513
+ if (type && args) {
514
+ // const subtableOldLength = subtable.children.length
515
+ switch(type){
516
+ case 'push':
517
+ case 'unshift':
518
+ var _subtable_children;
519
+ var newRowLengths = args.length;
520
+ createdNewRows = createRows(newRowLengths);
521
+ createdNewRowsData = args;
522
+ (_subtable_children = subtable.children)[type].apply(_subtable_children, _to_consumable_array(createdNewRows));
523
+ break;
524
+ case 'splice':
525
+ if (args.length > 2) {
526
+ var // @ts-ignore
527
+ _subtable_children1;
528
+ var newRowLengths1 = args.length - 2;
529
+ var newValues = args.slice(2);
530
+ createdNewRows = createRows(newRowLengths1);
531
+ createdNewRowsData = newValues;
532
+ // 从哪儿开始
533
+ var start = args[0];
534
+ // 替换几个
535
+ var replace = args[1];
536
+ (_subtable_children1 = subtable.children)[type].apply(_subtable_children1, [
537
+ start,
538
+ replace
539
+ ].concat(_to_consumable_array(createdNewRows)));
540
+ // newValues.forEach((item: any, index) => {
541
+ // let newIndex = start + index
542
+ // this.setStates(item, newIndex, options)
543
+ // })
544
+ } else {
545
+ var // @ts-ignore
546
+ _subtable_children2;
547
+ // 从哪儿开始
548
+ var start1 = args[0];
549
+ // 替换几个
550
+ var replace1 = args[1];
551
+ if (start1 + replace1 === subtable.children.length - 1) {
552
+ isDeleteLastOne = true;
553
+ }
554
+ (_subtable_children2 = subtable.children)[type].apply(_subtable_children2, _to_consumable_array(args));
555
+ }
556
+ break;
557
+ default:
558
+ var // @ts-ignore
559
+ _subtable_children3;
560
+ (_subtable_children3 = subtable.children)[type].apply(_subtable_children3, _to_consumable_array(args));
561
+ break;
562
+ }
563
+ if (type === 'splice') {
564
+ deleted = result;
565
+ } else if ([
566
+ 'pop',
567
+ 'shift'
568
+ ].includes(type)) {
569
+ deleted = [
570
+ result
571
+ ];
572
+ }
573
+ var subtableData = this.getState(subtable.id);
574
+ this._handlerSubtableUpdateUid(subtableData);
575
+ this.runtime.getFlatInstances();
576
+ this.emit('list-change', {
577
+ instance: subtable,
578
+ value: subtableData,
579
+ options: Object.assign({}, options, {
580
+ changed: createdNewRows,
581
+ data: createdNewRowsData,
582
+ deleted: deleted !== null && deleted !== void 0 ? deleted : [],
583
+ jsonValue: JSON.stringify(subtableData),
584
+ isDeleteLastOne: isDeleteLastOne,
585
+ type: type,
586
+ args: args
587
+ })
588
+ });
589
+ // 主动清空本次任务中的options
590
+ eventOptionsTemp = null;
591
+ }
592
+ }
593
+ },
594
+ {
595
+ key: "_handlerSubtableUpdateUid",
596
+ value: function _handlerSubtableUpdateUid(subtableData) {
597
+ ;
598
+ subtableData.forEach(function(item) {
599
+ if (!item.uid) {
600
+ Object.assign(item, {
601
+ uid: 'new:' + buildUUID('uid')
602
+ });
603
+ }
604
+ });
605
+ }
606
+ },
607
+ {
608
+ key: "_handlerObjectUpdate",
609
+ value: function _handlerObjectUpdate(state, key, value, oldValue) {
610
+ var instance = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
611
+ if (!instance) {
612
+ return;
613
+ }
614
+ var index = this.getInstanceRowIndex(instance);
615
+ var options = eventOptionsTemp || {};
616
+ // if (instance instanceof RuntimeListControl) {
617
+ if (instance.controlType === CONTROL_BASE_TYPE.LIST && instance.type === CONTROL_TYPE.SUBTABLE) {
618
+ var // @ts-ignore
619
+ _instance_children;
620
+ instance.children.length = 0;
621
+ var newValue = value;
622
+ // @ts-ignore
623
+ var newRows = [];
624
+ for(var i = 0; i < newValue.length; i++){
625
+ // @ts-ignore
626
+ var row = this.listControlCreateRow(instance, 'subtable-row');
627
+ row && newRows.push(row);
628
+ }
629
+ (_instance_children = instance.children).push.apply(_instance_children, _to_consumable_array(newRows));
630
+ // 这里已经能拿到控件实例,所以在这里触发setStates,触发每一行每一个控件的change事件
631
+ // for (let i = 0; i < newValue.length; i++) {
632
+ // this.setStates(newValue[i], i, options)
633
+ // }
634
+ var deleted = oldValue !== null && oldValue !== void 0 ? oldValue : [];
635
+ if ((options === null || options === void 0 ? void 0 : options.setData) === true) {
636
+ deleted = [];
637
+ } else {
638
+ this.runtime.getFlatInstances();
639
+ }
640
+ this._handlerSubtableUpdateUid(newValue);
641
+ this.emit('list-change', {
642
+ instance: instance,
643
+ value: value,
644
+ options: _object_spread_props(_object_spread({}, options), {
645
+ // @ts-ignore
646
+ changed: newRows,
647
+ data: newValue,
648
+ deleted: deleted,
649
+ // deleted: oldValue ?? [],
650
+ type: 'push',
651
+ jsonValue: JSON.stringify(newValue)
652
+ })
653
+ });
654
+ } else {
655
+ this.emit('change', {
656
+ instance: instance,
657
+ value: this.getState(instance.id, index),
658
+ rowIndex: index,
659
+ options: _object_spread_props(_object_spread({}, options), {
660
+ oldValue: oldValue
661
+ })
662
+ });
663
+ }
664
+ }
665
+ },
666
+ {
667
+ key: "applyPlugins",
668
+ value: function applyPlugins() {
669
+ var _this = this;
670
+ if (this.__pluginsApplied) return;
671
+ this.__plugins.forEach(function(plugin) {
672
+ try {
673
+ var _plugin_pluginName;
674
+ applyingPluginName = (_plugin_pluginName = plugin.pluginName) !== null && _plugin_pluginName !== void 0 ? _plugin_pluginName : plugin.constructor.name;
675
+ plugin.apply(_this);
676
+ } catch (e) {
677
+ error("".concat(applyingPluginName, " Plugin apply Error \n ").concat(e));
678
+ } finally{
679
+ applyingPluginName = '';
680
+ }
681
+ });
682
+ this.__pluginsApplied = true;
683
+ }
684
+ },
685
+ {
686
+ key: "listControlCreateRow",
687
+ value: function listControlCreateRow(instance, rowType) {
688
+ var row;
689
+ if (rowType === 'subtable-row') {
690
+ row = {
691
+ children: [],
692
+ controlType: CONTROL_BASE_TYPE.LAYOUT,
693
+ id: genNonDuplicateId(),
694
+ type: 'subtable-row',
695
+ props: {
696
+ caption: '',
697
+ isHide: false,
698
+ style: {
699
+ height: '',
700
+ heightConfig: 'fill',
701
+ width: '',
702
+ widthConfig: 'fill'
703
+ }
704
+ },
705
+ fieldType: undefined,
706
+ customEvents: [],
707
+ pageStatus: 0,
708
+ rules: [],
709
+ parent: undefined
710
+ };
711
+ } else {
712
+ row = this.runtime.createControlInstance(rowType);
713
+ }
714
+ if (!row) return;
715
+ // if (row instanceof RuntimeLayoutControl) {
716
+ // @ts-ignore
717
+ if (row.controlType === CONTROL_BASE_TYPE.LAYOUT) {
718
+ var _inst_children;
719
+ var inst = row;
720
+ var template = JSONCopy(instance.props.headers);
721
+ // @ts-ignore
722
+ var columns = this.createControl(template);
723
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
724
+ try {
725
+ for(var _iterator = columns[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
726
+ var column = _step.value;
727
+ if (!column.parent) {
728
+ this.runtime.resetInstanceParent(column, inst);
729
+ }
730
+ }
731
+ } catch (err) {
732
+ _didIteratorError = true;
733
+ _iteratorError = err;
734
+ } finally{
735
+ try {
736
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
737
+ _iterator.return();
738
+ }
739
+ } finally{
740
+ if (_didIteratorError) {
741
+ throw _iteratorError;
742
+ }
743
+ }
744
+ }
745
+ (_inst_children = inst.children).push.apply(_inst_children, _to_consumable_array(columns));
746
+ }
747
+ //@ts-ignore
748
+ row.parent = instance;
749
+ return row;
750
+ }
751
+ },
752
+ {
753
+ key: "listControlAddRow",
754
+ value: function listControlAddRow(instance) {
755
+ var // @ts-ignore
756
+ rowType = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 'subtable-row';
757
+ var row = this.listControlCreateRow(instance, rowType);
758
+ if (!row) return;
759
+ instance.children.push(row);
760
+ }
761
+ },
762
+ {
763
+ key: "emit",
764
+ value: // payload应该是runtimeSchema和value,然后通过runTimeSchema去找需要修改的data里边的key
765
+ function emit(eventKey, payload) {
766
+ var _this = this;
767
+ var _this1 = this, _superprop_get_emit = function() {
768
+ return _get(_get_prototype_of(Engine.prototype), "emit", _this);
769
+ };
770
+ return _async_to_generator(function() {
771
+ var needWait, promiseResolver, promise, results;
772
+ return _ts_generator(this, function(_state) {
773
+ switch(_state.label){
774
+ case 0:
775
+ if (!(eventKey === 'engine-mounted')) return [
776
+ 3,
777
+ 3
778
+ ];
779
+ if (this.isMounted) {
780
+ warn('The engine-mounted life cycle can only be triggered once');
781
+ return [
782
+ 2,
783
+ Promise.resolve([])
784
+ ];
785
+ }
786
+ if (!this._jobTasks.length) return [
787
+ 3,
788
+ 2
789
+ ];
790
+ console.time('engine-mounted need wait');
791
+ needWait = _to_consumable_array(this._jobTasks);
792
+ return [
793
+ 4,
794
+ Promise.all(needWait)
795
+ ];
796
+ case 1:
797
+ _state.sent();
798
+ console.timeEnd('engine-mounted need wait');
799
+ _state.label = 2;
800
+ case 2:
801
+ this.isMounted = true;
802
+ _state.label = 3;
803
+ case 3:
804
+ // 如果没有挂载的话,需要记录在挂载之前触发的所有任务
805
+ if (!this.isMounted) {
806
+ promise = new Promise(function(resolve) {
807
+ promiseResolver = resolve;
808
+ });
809
+ this._jobTasks.push(promise);
810
+ }
811
+ return [
812
+ 4,
813
+ _superprop_get_emit().call(_this1, eventKey, payload)
814
+ ];
815
+ case 4:
816
+ results = _state.sent();
817
+ if (promiseResolver && promise) {
818
+ // 每一个任务完成的时候,都把自己从task中去掉
819
+ promiseResolver();
820
+ this._jobTasks.splice(this._jobTasks.indexOf(promise), 1);
821
+ }
822
+ return [
823
+ 2,
824
+ results
825
+ ];
826
+ }
827
+ });
828
+ }).call(this);
829
+ }
830
+ },
831
+ {
832
+ key: "on",
833
+ value: function on(key, callback) {
834
+ if (applyingPluginName) {
835
+ callback.applyingPluginName = applyingPluginName;
836
+ }
837
+ return _get(_get_prototype_of(Engine.prototype), "on", this).call(this, key, callback);
838
+ }
839
+ },
840
+ {
841
+ key: "createControl",
842
+ value: function createControl() {
843
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
844
+ args[_key] = arguments[_key];
845
+ }
846
+ var _this_runtime;
847
+ return (_this_runtime = this.runtime).createControl.apply(_this_runtime, _to_consumable_array(args));
848
+ }
849
+ },
850
+ {
851
+ key: "createInstance",
852
+ value: function createInstance(type, initSchema) {
853
+ return this.runtime.createControlInstance(type, initSchema);
854
+ }
855
+ },
856
+ {
857
+ key: "schemaEvent",
858
+ value: function schemaEvent(eventKey, payload) {
859
+ this.emit(eventKey, payload);
860
+ }
861
+ },
862
+ {
863
+ key: "updateInstanceProps",
864
+ value: function updateInstanceProps(instance, props, value, rowIndex) {
865
+ return this.setInstance(instance, props, value, rowIndex);
866
+ }
867
+ },
868
+ {
869
+ key: "getRule",
870
+ value: function getRule(controlType, props) {
871
+ return Runtime.staticGetRules(controlType, props);
872
+ }
873
+ },
874
+ {
875
+ key: "getAllRules",
876
+ value: function getAllRules(controlId) {
877
+ var rules = this.runtime.allRules;
878
+ if (controlId === undefined) {
879
+ return rules;
880
+ } else {
881
+ var _rules_rules_controlId, _rules_antdRules_controlId;
882
+ return {
883
+ rules: (_rules_rules_controlId = rules.rules[controlId]) === null || _rules_rules_controlId === void 0 ? void 0 : _rules_rules_controlId.fields,
884
+ antdRules: (_rules_antdRules_controlId = rules.antdRules[controlId]) === null || _rules_antdRules_controlId === void 0 ? void 0 : _rules_antdRules_controlId.fields
885
+ };
886
+ }
887
+ }
888
+ },
889
+ {
890
+ key: "getRules",
891
+ value: function getRules(controlId) {
892
+ var isGetFieldCodeRules = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
893
+ var controlIdRules = this.runtime.rules;
894
+ var fieldCodeRules = this.runtime.fieldCodeRules;
895
+ var controlIdMapping = this.store.controlIdMapping;
896
+ var rules = isGetFieldCodeRules ? fieldCodeRules : controlIdRules;
897
+ if (controlId === undefined) {
898
+ return isGetFieldCodeRules ? fieldCodeRules : rules;
899
+ } else {
900
+ var _controlIdMapping_controlId, _controlIdMapping_controlId_dataBind, _controlIdMapping_controlId_dataBind1;
901
+ controlId = isGetFieldCodeRules ? ((_controlIdMapping_controlId = controlIdMapping[controlId]) === null || _controlIdMapping_controlId === void 0 ? void 0 : _controlIdMapping_controlId.children) ? (_controlIdMapping_controlId_dataBind = controlIdMapping[controlId].dataBind) === null || _controlIdMapping_controlId_dataBind === void 0 ? void 0 : _controlIdMapping_controlId_dataBind.dataCode : ((_controlIdMapping_controlId_dataBind1 = controlIdMapping[controlId].dataBind) === null || _controlIdMapping_controlId_dataBind1 === void 0 ? void 0 : _controlIdMapping_controlId_dataBind1.fieldCode) || controlId : controlId;
902
+ if (controlId in rules) {
903
+ var _rules_controlId;
904
+ return (_rules_controlId = rules[controlId]) === null || _rules_controlId === void 0 ? void 0 : _rules_controlId.fields;
905
+ }
906
+ var ruleItems;
907
+ for(var id in rules){
908
+ var _rules_id;
909
+ if (controlId in (((_rules_id = rules[id]) === null || _rules_id === void 0 ? void 0 : _rules_id.fields) || {})) {
910
+ var _rules_id_fields, _rules_id1;
911
+ ruleItems = (_rules_id1 = rules[id]) === null || _rules_id1 === void 0 ? void 0 : (_rules_id_fields = _rules_id1.fields) === null || _rules_id_fields === void 0 ? void 0 : _rules_id_fields[controlId];
912
+ break;
913
+ }
914
+ }
915
+ return ruleItems;
916
+ }
917
+ }
918
+ },
919
+ {
920
+ key: "getAntdRules",
921
+ value: function getAntdRules(controlId) {
922
+ if (controlId === undefined) {
923
+ return this.runtime.antdRules;
924
+ } else {
925
+ var _this_runtime_antdRules_controlId;
926
+ return (_this_runtime_antdRules_controlId = this.runtime.antdRules[controlId]) === null || _this_runtime_antdRules_controlId === void 0 ? void 0 : _this_runtime_antdRules_controlId.fields;
927
+ }
928
+ }
929
+ },
930
+ {
931
+ key: "getState",
932
+ value: function getState(controlId, rowIndex) {
933
+ if (controlId === undefined) {
934
+ return this.store.state;
935
+ } else {
936
+ return this.store.getState(controlId, rowIndex);
937
+ }
938
+ }
939
+ },
940
+ {
941
+ key: "getEmptyState",
942
+ value: function getEmptyState(controlId) {
943
+ if (controlId === undefined) {
944
+ return JSONCopy(this.store.emptyState);
945
+ } else {
946
+ return JSONCopy(this.store.getEmptyState(controlId));
947
+ }
948
+ }
949
+ },
950
+ {
951
+ /**
952
+ * 设置payload的options,提供在不是使用标准api修改state的时候可以传递options,会在本次任务执行完成之后清空
953
+ * @param options 需要携带的options
954
+ * */ key: "setPayloadOptions",
955
+ value: function setPayloadOptions(options) {
956
+ eventOptionsTemp = options;
957
+ }
958
+ },
959
+ {
960
+ key: "setState",
961
+ value: function setState(controlId, value, rowIndex, options) {
962
+ eventOptionsTemp = options;
963
+ // @i18n-translate-ignore
964
+ this.debugLog('[%o]: 触发setState, 修改的值为%o, rowIndex=%o, options=%o', controlId, value, rowIndex, options);
965
+ this.store.setState(controlId, value, rowIndex);
966
+ // @i18n-translate-ignore
967
+ this.debugLog('[%o]: setState完成, 修改的值为%o, rowIndex=%o', controlId, value, rowIndex);
968
+ eventOptionsTemp = null;
969
+ }
970
+ },
971
+ {
972
+ /**
973
+ * 向Store设置一组值,明细表必须全量赋值,并触发事件(触发事件是根据组件在页面中的顺序逐个触发)
974
+ * @param states
975
+ */ key: "setStates",
976
+ value: function setStates(states, rowIndex, options) {
977
+ var _this = this;
978
+ var newStates = states !== null && states !== void 0 ? states : {};
979
+ Object.keys(newStates).forEach(function(stateId) {
980
+ Object.entries(_this.store.controlIdMapping).forEach(function(param) {
981
+ var _param = _sliced_to_array(param, 2), controlId = _param[0], controlIdMapping = _param[1];
982
+ if (controlIdMapping.dataView === stateId) {
983
+ // state对象是dataView包裹的
984
+ var value = newStates[stateId][controlId];
985
+ if (value !== undefined) {
986
+ _this.setState(controlId, value, rowIndex, options);
987
+ }
988
+ } else {
989
+ // state对象是单独的,没有被dataView包裹的
990
+ if (controlId === stateId || controlIdMapping.children && controlIdMapping.children[stateId]) {
991
+ if (newStates[stateId] !== undefined) {
992
+ _this.setState(stateId, newStates[stateId], rowIndex, options);
993
+ }
994
+ }
995
+ }
996
+ });
997
+ });
998
+ }
999
+ },
1000
+ {
1001
+ /**
1002
+ * 通过dataCode和fieldCode来获取控件的值
1003
+ * @param dataCode 模型编码 - 如果是主表的话就是主表的模型编码,明细子表的话就是子表的模型编码
1004
+ * @param fieldCode 字段编码 - 控件绑定的数据项的编码
1005
+ * @param rowIndex 行下标 - 如果是明细子表中的控件需要提供
1006
+ * */ key: "getField",
1007
+ value: function getField(dataCode, fieldCode, rowIndex) {
1008
+ if (!fieldCode) {
1009
+ var dataBindMapping = this.getDataBindMapping(dataCode);
1010
+ if (dataBindMapping) {
1011
+ var controlId = dataBindMapping.controlId;
1012
+ return this.getState(controlId);
1013
+ }
1014
+ return;
1015
+ }
1016
+ var dataBindMapping1 = this.getDataBindMapping(dataCode, fieldCode);
1017
+ if (!dataBindMapping1) {
1018
+ return;
1019
+ }
1020
+ var dataBind = dataBindMapping1.dataBind, controlId1 = dataBindMapping1.controlId;
1021
+ var state = this.getState(controlId1, rowIndex);
1022
+ //if (dataBind instanceof ObjectDataBind) {
1023
+ if (!isDataBind(dataBind)) {
1024
+ return Object.entries(dataBind).reduce(function(result, param) {
1025
+ var _param = _sliced_to_array(param, 2), key = _param[0], dataBind = _param[1];
1026
+ // objectDataBind的元素,跳过下一次赋值
1027
+ if (dataBind.fieldCode === fieldCode) {
1028
+ return result[key];
1029
+ }
1030
+ return result;
1031
+ }, state);
1032
+ } else {
1033
+ return state;
1034
+ }
1035
+ }
1036
+ },
1037
+ {
1038
+ key: "getData",
1039
+ value: function getData(dataCode) {
1040
+ if (!dataCode) return;
1041
+ var dataBindMapping = this.getDataBindMapping(dataCode);
1042
+ var controlIdMapping = this.getControlIdMapping();
1043
+ if (dataBindMapping) {
1044
+ var controlId = dataBindMapping.controlId;
1045
+ var getFieldData = this.getField(dataCode);
1046
+ // 明细子表值
1047
+ if (Array.isArray(getFieldData)) {
1048
+ var data = getFieldData.map(function(item) {
1049
+ var obj = {};
1050
+ for(var key in item){
1051
+ var _controlIdMapping_controlId_children_key_dataBind, _controlIdMapping_controlId_children_key, _controlIdMapping_controlId;
1052
+ var fieldCode = (_controlIdMapping_controlId = controlIdMapping[controlId]) === null || _controlIdMapping_controlId === void 0 ? void 0 : (_controlIdMapping_controlId_children_key = _controlIdMapping_controlId.children[key]) === null || _controlIdMapping_controlId_children_key === void 0 ? void 0 : (_controlIdMapping_controlId_children_key_dataBind = _controlIdMapping_controlId_children_key.dataBind) === null || _controlIdMapping_controlId_children_key_dataBind === void 0 ? void 0 : _controlIdMapping_controlId_children_key_dataBind.fieldCode;
1053
+ //未绑定字段的控件,直接抛弃
1054
+ if (fieldCode !== '') {
1055
+ var _controlIdMapping_controlId1;
1056
+ if (fieldCode) {
1057
+ obj[fieldCode] = item[key];
1058
+ } else if ((_controlIdMapping_controlId1 = controlIdMapping[controlId]) === null || _controlIdMapping_controlId1 === void 0 ? void 0 : _controlIdMapping_controlId1.children[key]) {
1059
+ // 兼容一个控件需要绑定多个字段的情况
1060
+ for(var keyChi in item[key]){
1061
+ var _controlIdMapping_controlId_children_key1, _controlIdMapping_controlId2;
1062
+ obj[(_controlIdMapping_controlId2 = controlIdMapping[controlId]) === null || _controlIdMapping_controlId2 === void 0 ? void 0 : (_controlIdMapping_controlId_children_key1 = _controlIdMapping_controlId2.children[key]) === null || _controlIdMapping_controlId_children_key1 === void 0 ? void 0 : _controlIdMapping_controlId_children_key1.dataBind[keyChi].fieldCode] = item[key][keyChi];
1063
+ }
1064
+ }
1065
+ }
1066
+ }
1067
+ return obj;
1068
+ });
1069
+ return data;
1070
+ } else {
1071
+ var _loop = function(key) {
1072
+ var _controlIdMapping_key_dataBind, _controlIdMapping_key, _controlIdMapping_key_dataBind1, _controlIdMapping_key1;
1073
+ if ((_controlIdMapping_key = controlIdMapping[key]) === null || _controlIdMapping_key === void 0 ? void 0 : (_controlIdMapping_key_dataBind = _controlIdMapping_key.dataBind) === null || _controlIdMapping_key_dataBind === void 0 ? void 0 : _controlIdMapping_key_dataBind.fieldCode) {
1074
+ var _controlIdMapping_key2;
1075
+ obj[(_controlIdMapping_key2 = controlIdMapping[key]) === null || _controlIdMapping_key2 === void 0 ? void 0 : _controlIdMapping_key2.dataBind.fieldCode] = getFieldData[key];
1076
+ } else if ((_controlIdMapping_key1 = controlIdMapping[key]) === null || _controlIdMapping_key1 === void 0 ? void 0 : (_controlIdMapping_key_dataBind1 = _controlIdMapping_key1.dataBind) === null || _controlIdMapping_key_dataBind1 === void 0 ? void 0 : _controlIdMapping_key_dataBind1.dataCode) {
1077
+ if (!Array.isArray(getFieldData[key])) {
1078
+ // obj[controlIdMapping[key]?.dataBind.dataCode] = ''
1079
+ } else {
1080
+ var _controlIdMapping_key3, _getFieldData_key;
1081
+ // 明细字表只循环一层明细子表未递归
1082
+ obj[(_controlIdMapping_key3 = controlIdMapping[key]) === null || _controlIdMapping_key3 === void 0 ? void 0 : _controlIdMapping_key3.dataBind.dataCode] = (_getFieldData_key = getFieldData[key]) === null || _getFieldData_key === void 0 ? void 0 : _getFieldData_key.map(function(item) {
1083
+ var objChi = {};
1084
+ for(var keyChi in item){
1085
+ var _controlIdMapping_key_children_keyChi;
1086
+ var fieldCode = (_controlIdMapping_key_children_keyChi = controlIdMapping[key].children[keyChi]) === null || _controlIdMapping_key_children_keyChi === void 0 ? void 0 : _controlIdMapping_key_children_keyChi.dataBind.fieldCode;
1087
+ //未绑定字段的控件,直接抛弃
1088
+ if (fieldCode !== '') {
1089
+ if (fieldCode) {
1090
+ objChi[fieldCode] = item[keyChi];
1091
+ } else {
1092
+ for(var keyChi1 in item[keyChi]){
1093
+ var _controlIdMapping_key_children_keyChi1;
1094
+ objChi[(_controlIdMapping_key_children_keyChi1 = controlIdMapping[key].children[keyChi]) === null || _controlIdMapping_key_children_keyChi1 === void 0 ? void 0 : _controlIdMapping_key_children_keyChi1.dataBind[keyChi1].fieldCode] = item[keyChi][keyChi1];
1095
+ }
1096
+ }
1097
+ }
1098
+ }
1099
+ return objChi;
1100
+ });
1101
+ }
1102
+ } else if (controlIdMapping[key]) {
1103
+ // 兼容一个控件需要绑定多个字段的情况
1104
+ for(var keyChi in getFieldData[key]){
1105
+ var _controlIdMapping_key_dataBind_keyChi, _controlIdMapping_key4;
1106
+ obj[(_controlIdMapping_key4 = controlIdMapping[key]) === null || _controlIdMapping_key4 === void 0 ? void 0 : (_controlIdMapping_key_dataBind_keyChi = _controlIdMapping_key4.dataBind[keyChi]) === null || _controlIdMapping_key_dataBind_keyChi === void 0 ? void 0 : _controlIdMapping_key_dataBind_keyChi.fieldCode] = getFieldData[key][keyChi];
1107
+ }
1108
+ }
1109
+ };
1110
+ // 主表
1111
+ var obj = {};
1112
+ for(var key in getFieldData)_loop(key);
1113
+ return obj;
1114
+ }
1115
+ }
1116
+ return;
1117
+ }
1118
+ },
1119
+ {
1120
+ /**
1121
+ * 通过dataCode和fieldCode来设置控件的值
1122
+ * @param dataCode 模型编码 - 如果是主表的话就是主表的模型编码,明细子表的话就是子表的模型编码
1123
+ * @param fieldCode 字段编码 - 控件绑定的数据项的编码
1124
+ * @param value 修改的值
1125
+ * @param rowIndex 行下标 - 如果是明细子表中的控件需要提供
1126
+ * @param options 触发事件携带的参数
1127
+ * */ key: "setField",
1128
+ value: function setField(dataCode, fieldCode, value, rowIndex, options) {
1129
+ var dataBindMapping = this.getDataBindMapping(dataCode, fieldCode);
1130
+ if (!dataBindMapping) {
1131
+ return;
1132
+ }
1133
+ var dataBind = dataBindMapping.dataBind, controlId = dataBindMapping.controlId;
1134
+ // if (dataBind instanceof ObjectDataBind) {
1135
+ if (!isDataBind(dataBind)) {
1136
+ var _JSONCopy;
1137
+ var oldState = (_JSONCopy = JSONCopy(this.getState(controlId, rowIndex))) !== null && _JSONCopy !== void 0 ? _JSONCopy : this.getEmptyState(controlId);
1138
+ // fieldCode不代表是key,所以需要找到对应的key
1139
+ var newState = Object.entries(dataBind).reduce(function(result, param) {
1140
+ var _param = _sliced_to_array(param, 2), key = _param[0], dataBind = _param[1];
1141
+ // objectDataBind的元素,跳过下一次赋值
1142
+ if (dataBind.fieldCode === fieldCode) {
1143
+ result[key] = value;
1144
+ }
1145
+ return result;
1146
+ }, oldState);
1147
+ this.setState(controlId, newState, rowIndex, options);
1148
+ } else {
1149
+ this.setState(controlId, value, rowIndex, options);
1150
+ }
1151
+ }
1152
+ },
1153
+ {
1154
+ /**
1155
+ * 通过dataCode和 state来给一组控件赋值,并触发事件携带options
1156
+ * @param dataCode 需要赋值的目标模型
1157
+ * @param state 赋值对象,以fieldCode为key组成的对象
1158
+ * @param rowIndex 行下标,给明细子表赋值时指定赋值某行
1159
+ * @param options 触发事件携带的参数
1160
+ * */ key: "setFields",
1161
+ value: function setFields(dataCode, state, rowIndex, options) {
1162
+ var _this = this;
1163
+ var mapping = this.getDataBindMapping(dataCode);
1164
+ if (!mapping) {
1165
+ return;
1166
+ }
1167
+ var skipKeys = [];
1168
+ mapping.fields.forEach(function(item) {
1169
+ var dataBind = item.dataBind, controlId = item.controlId, fieldCode = item.fieldCode;
1170
+ if (skipKeys.includes(fieldCode)) {
1171
+ return;
1172
+ }
1173
+ if (!Object.hasOwnProperty.call(state, fieldCode)) {
1174
+ return;
1175
+ }
1176
+ // 对象类型的值
1177
+ // if (dataBind instanceof ObjectDataBind) {
1178
+ if (!isDataBind(dataBind)) {
1179
+ var _JSONCopy;
1180
+ var oldState = (_JSONCopy = JSONCopy(_this.getState(controlId, rowIndex))) !== null && _JSONCopy !== void 0 ? _JSONCopy : _this.getEmptyState(controlId);
1181
+ // fieldCode不代表是key,所以需要找到对应的key
1182
+ var newState = Object.entries(dataBind).reduce(function(result, param) {
1183
+ var _param = _sliced_to_array(param, 2), key = _param[0], dataBind = _param[1];
1184
+ // objectDataBind的元素,跳过下一次赋值
1185
+ skipKeys.push(dataBind.fieldCode);
1186
+ var value = state[dataBind.fieldCode];
1187
+ if (value !== undefined) {
1188
+ result[key] = value;
1189
+ }
1190
+ return result;
1191
+ }, oldState);
1192
+ _this.setState(item.controlId, newState, rowIndex, options);
1193
+ } else {
1194
+ _this.setState(controlId, state[fieldCode], rowIndex, options);
1195
+ }
1196
+ });
1197
+ }
1198
+ },
1199
+ {
1200
+ /**
1201
+ * 通过dataCode来将state转化为标准的state结构
1202
+ * @param dataCode 需要转换的目标模型code
1203
+ * @param state 值对象,以fieldCode为key组成的对象
1204
+ * */ key: "buildFields",
1205
+ value: function buildFields(dataCode, state) {
1206
+ var _this = this;
1207
+ var mapping = this.getDataBindMapping(dataCode);
1208
+ if (!mapping || !mapping.fields) {
1209
+ return;
1210
+ }
1211
+ var skipKeys = [];
1212
+ var result = {};
1213
+ mapping.fields.forEach(function(item) {
1214
+ var dataBind = item.dataBind, controlId = item.controlId, fieldCode = item.fieldCode;
1215
+ if (skipKeys.includes(fieldCode)) {
1216
+ return;
1217
+ }
1218
+ if (!Object.hasOwnProperty.call(state, fieldCode)) {
1219
+ return;
1220
+ }
1221
+ // 对象类型的值
1222
+ // if (dataBind instanceof ObjectDataBind) {
1223
+ if (!isDataBind(dataBind)) {
1224
+ var oldState = _this.getEmptyState(controlId);
1225
+ // fieldCode不代表是key,所以需要找到对应的key
1226
+ result[item.controlId] = Object.entries(dataBind).reduce(function(result, param) {
1227
+ var _param = _sliced_to_array(param, 2), key = _param[0], dataBind = _param[1];
1228
+ // objectDataBind的元素,跳过下一次赋值
1229
+ skipKeys.push(dataBind.fieldCode);
1230
+ var value = state[dataBind.fieldCode];
1231
+ if (value !== undefined) {
1232
+ result[key] = value;
1233
+ }
1234
+ return result;
1235
+ }, oldState);
1236
+ } else {
1237
+ result[controlId] = state[fieldCode];
1238
+ }
1239
+ });
1240
+ return result;
1241
+ }
1242
+ },
1243
+ {
1244
+ /**
1245
+ * 向Store设置一组值,并触发事件携带options
1246
+ * @param dataSet
1247
+ * @options 传递给关联事件中 EventPayload中的options,一般在plugin中监听使用
1248
+ */ key: "setData",
1249
+ value: function setData(dataSet, options) {
1250
+ var _this = this;
1251
+ // @i18n-translate-ignore
1252
+ this.debugLog("engine setData方法执行,参数为%o,%o。", dataSet, options);
1253
+ var onlySetData = options === null || options === void 0 ? void 0 : options.onlySetData;
1254
+ var newState = this.store.defaultState;
1255
+ if (onlySetData === true) {
1256
+ newState = {};
1257
+ }
1258
+ Object.keys(dataSet).map(function(dataCode) {
1259
+ var entity = dataSet[dataCode];
1260
+ if (Array.isArray(entity)) {
1261
+ var mapping = _this.getDataBindMapping(dataCode);
1262
+ if (!mapping) {
1263
+ return;
1264
+ }
1265
+ if (!newState[mapping.dataViewId]) {
1266
+ newState[mapping.dataViewId] = {};
1267
+ }
1268
+ if (!entity.length) {
1269
+ var _newState_mapping_dataViewId_mapping_controlId;
1270
+ newState[mapping.dataViewId][mapping.controlId] = (_newState_mapping_dataViewId_mapping_controlId = newState[mapping.dataViewId][mapping.controlId]) !== null && _newState_mapping_dataViewId_mapping_controlId !== void 0 ? _newState_mapping_dataViewId_mapping_controlId : [];
1271
+ } else {
1272
+ newState[mapping.dataViewId][mapping.controlId] = [];
1273
+ }
1274
+ var cacheEmptyState = {};
1275
+ var cacheFieldMapping = {};
1276
+ entity.map(function(row) {
1277
+ var newRow = JSONCopy(_this.store.emptyState[mapping.dataViewId][mapping.controlId]);
1278
+ var skipKey = [] //qiyu ObjectDataBind中会提前将相关key拿出来赋值,为了避免重复赋值,设置了此变量
1279
+ ;
1280
+ Object.keys(row).map(function(fieldCode) {
1281
+ if (skipKey.includes(fieldCode)) {
1282
+ return;
1283
+ }
1284
+ if (cacheFieldMapping.hasOwnProperty(fieldCode) === false) {
1285
+ var _this_store_dataBindMapping_dataCode_fields, _this_store_dataBindMapping_dataCode;
1286
+ cacheFieldMapping[fieldCode] = (_this_store_dataBindMapping_dataCode = _this.store.dataBindMapping[dataCode]) === null || _this_store_dataBindMapping_dataCode === void 0 ? void 0 : (_this_store_dataBindMapping_dataCode_fields = _this_store_dataBindMapping_dataCode.fields) === null || _this_store_dataBindMapping_dataCode_fields === void 0 ? void 0 : _this_store_dataBindMapping_dataCode_fields.find(function(i) {
1287
+ return i.fieldCode === fieldCode;
1288
+ });
1289
+ }
1290
+ var fieldMapping = cacheFieldMapping[fieldCode];
1291
+ if (fieldMapping) {
1292
+ if (// fieldMapping.dataBind instanceof DataBind &&
1293
+ isDataBind(fieldMapping.dataBind) && row[fieldCode] !== undefined) {
1294
+ newRow[fieldMapping.controlId] = row[fieldCode];
1295
+ // } else if (fieldMapping.dataBind instanceof ObjectDataBind) {
1296
+ } else if (!isDataBind(fieldMapping.dataBind)) {
1297
+ if (cacheEmptyState.hasOwnProperty(fieldMapping.controlId) === false) {
1298
+ var _this_getEmptyState;
1299
+ cacheEmptyState[fieldMapping.controlId] = JSONCopy((_this_getEmptyState = _this.getEmptyState(fieldMapping.controlId)) !== null && _this_getEmptyState !== void 0 ? _this_getEmptyState : {});
1300
+ }
1301
+ var objValue = JSONCopy(cacheEmptyState[fieldMapping.controlId]);
1302
+ Object.keys(fieldMapping.dataBind).map(function(key) {
1303
+ var dataBind = fieldMapping.dataBind[key];
1304
+ if (row[dataBind.fieldCode] !== undefined) {
1305
+ objValue[key] = row[dataBind.fieldCode];
1306
+ }
1307
+ skipKey.push(dataBind.fieldCode);
1308
+ });
1309
+ newRow[fieldMapping.controlId] = objValue;
1310
+ }
1311
+ } else if (fieldCode === 'uid' && row.uid !== undefined) {
1312
+ newRow.uid = row.uid;
1313
+ } else if (fieldCode === 'virtualStore' && row.virtualStore !== undefined) {
1314
+ newRow.virtualStore = Object.freeze(row.virtualStore);
1315
+ }
1316
+ });
1317
+ newState[mapping.dataViewId][mapping.controlId].push(newRow);
1318
+ });
1319
+ } else if (entity) {
1320
+ var _Object_keys;
1321
+ var skipKey = [] //qiyu ObjectDataBind中会提前将相关key拿出来赋值,为了避免重复赋值,设置了此变量
1322
+ ;
1323
+ var emptyState = JSONCopy(_this.store.emptyState);
1324
+ if (!((_Object_keys = Object.keys(entity)) === null || _Object_keys === void 0 ? void 0 : _Object_keys.length)) {
1325
+ // newState = this.store.defaultState
1326
+ } else {
1327
+ Object.keys(entity).map(function(fieldCode) {
1328
+ if (skipKey.includes(fieldCode)) {
1329
+ return;
1330
+ }
1331
+ var mapping = _this.getDataBindMapping(dataCode, fieldCode);
1332
+ if (mapping) {
1333
+ if (!newState[mapping.dataViewId[0]]) {
1334
+ newState[mapping.dataViewId[0]] = {};
1335
+ }
1336
+ if (// mapping.dataBind instanceof DataBind &&
1337
+ isDataBind(mapping.dataBind) && entity[fieldCode] !== undefined) {
1338
+ newState[mapping.dataViewId[0]][mapping.controlId] = entity[fieldCode] !== undefined ? entity[fieldCode] : emptyState[mapping.dataViewId[0]][mapping.controlId];
1339
+ // } else if (mapping.dataBind instanceof ObjectDataBind) {
1340
+ } else if (!isDataBind(mapping.dataBind)) {
1341
+ var _this_getEmptyState;
1342
+ var objValue = (_this_getEmptyState = _this.getEmptyState(mapping.controlId)) !== null && _this_getEmptyState !== void 0 ? _this_getEmptyState : {};
1343
+ Object.keys(mapping.dataBind).map(function(key) {
1344
+ var dataBind = mapping.dataBind[key];
1345
+ if (entity[dataBind.fieldCode] !== undefined) {
1346
+ objValue[key] = entity[dataBind.fieldCode];
1347
+ }
1348
+ skipKey.push(dataBind.fieldCode);
1349
+ });
1350
+ newState[mapping.dataViewId[0]][mapping.controlId] = objValue;
1351
+ }
1352
+ }
1353
+ });
1354
+ }
1355
+ var newMapping = _this.getDataBindMapping(dataCode);
1356
+ if (newMapping) {
1357
+ var _newMapping_fields;
1358
+ var mappingKeys = newMapping === null || newMapping === void 0 ? void 0 : (_newMapping_fields = newMapping.fields) === null || _newMapping_fields === void 0 ? void 0 : _newMapping_fields.map(function(item) {
1359
+ return item === null || item === void 0 ? void 0 : item.controlId;
1360
+ });
1361
+ var mappingValue = _this.getEmptyState(newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId);
1362
+ var _newState_newMapping_controlId;
1363
+ var mainStateKeys = Object.keys((_newState_newMapping_controlId = newState === null || newState === void 0 ? void 0 : newState[newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId]) !== null && _newState_newMapping_controlId !== void 0 ? _newState_newMapping_controlId : {});
1364
+ mappingKeys === null || mappingKeys === void 0 ? void 0 : mappingKeys.forEach(function(key) {
1365
+ if (!mainStateKeys.includes(key) && key !== 'uid' && newState[newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId]) {
1366
+ if (Object.keys(newState).length) {
1367
+ Object.assign(newState[newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId], _define_property({}, key, mappingValue[key]));
1368
+ } else {
1369
+ Object.assign(newState, _define_property({}, newMapping.controlId, _define_property({}, key, mappingValue[key])));
1370
+ }
1371
+ }
1372
+ });
1373
+ // @i18n-translate-ignore
1374
+ _this.debugLog("engine setData方法默认值及表单数据组合完成,参数为%o。", newState);
1375
+ }
1376
+ }
1377
+ });
1378
+ // @i18n-translate-ignore
1379
+ this.debugLog("engine setData方法数据组合完成,参数为%o。", newState);
1380
+ this.setStates(newState, undefined, _object_spread({
1381
+ setData: true
1382
+ }, options));
1383
+ this.runtime.getFlatInstances();
1384
+ // @i18n-translate-ignore
1385
+ this.debugLog("engine setData方法执行完成。");
1386
+ }
1387
+ },
1388
+ {
1389
+ /**
1390
+ * 获取控件的dataBind
1391
+ * @param controlId
1392
+ * */ key: "getDataBind",
1393
+ value: function getDataBind(controlId) {
1394
+ return this.store.getDataBind(controlId);
1395
+ }
1396
+ },
1397
+ {
1398
+ /**
1399
+ * 获取组件实例,传入rowIndex代表获取明细表内的控件实例,rowIndex传入-1代表获取表头内的实例
1400
+ * @param controlId
1401
+ * @param rowIndex
1402
+ */ key: "getInstance",
1403
+ value: function getInstance(controlId, rowIndex) {
1404
+ var instances = this.getInstances(controlId, rowIndex === -1);
1405
+ if (instances.length > 0) {
1406
+ if (rowIndex !== undefined) {
1407
+ if (rowIndex === -1) {
1408
+ return instances[0];
1409
+ }
1410
+ return instances[rowIndex];
1411
+ } else {
1412
+ return instances[0];
1413
+ }
1414
+ } else {
1415
+ return undefined;
1416
+ }
1417
+ }
1418
+ },
1419
+ {
1420
+ /**
1421
+ * 获取组件实例,明细表中的组件将会得到数组, 第二个参数为(false/不传入)则获取到的是明细表内不包含表头内实例的所有控件实例,传入true则获取到包含表头内实例的所有控件实例,表头内实例永远在下标0的位置
1422
+ * @param controlId
1423
+ * @param header 明细表内是否获取表头的控件
1424
+ */ // getInstances(
1425
+ // controlId?: string,
1426
+ // header: boolean = false
1427
+ // ): ControlRuntimeInstance<ControlsKeys>[] {
1428
+ // // const cc = console
1429
+ // // const label = '🐑 genInstances ' + controlId + ' ' + Date.now()
1430
+ // // cc.time(label)
1431
+ //
1432
+ // if (controlId === undefined) {
1433
+ // // cc.timeEnd(label)
1434
+ // return this.runtime.flatInstances
1435
+ // }
1436
+ // const instances = Array.from(this.runtime.instanceMap[controlId] || [])
1437
+ // if (header) {
1438
+ // // 如果能从flatInstances里边取到,就通过getInstanceInSubtableHeader方法取,取不到则换一种方式
1439
+ // if (instances.length) {
1440
+ // const instance: RuntimeControl = instances[0]
1441
+ // // if (this.inList(instance.id) === true) {
1442
+ // if (this.inList(instance.id) !== undefined) {
1443
+ // const headerInstance = this.getInstanceInSubtableHeader(instance)
1444
+ // if (headerInstance) {
1445
+ // instances.unshift(headerInstance)
1446
+ // }
1447
+ // }
1448
+ // } else {
1449
+ // const controlIdMapping = this.getControlIdMapping()
1450
+ // const [subtableId] =
1451
+ // Object.entries(controlIdMapping).find(
1452
+ // ([_, mapping]) => mapping.children && controlId in mapping.children
1453
+ // ) ?? []
1454
+ // if (subtableId) {
1455
+ // const subtable = this.getInstance(subtableId)
1456
+ // // @ts-ignore
1457
+ // const headerColumn = subtable.props.headers.find((column: any) =>
1458
+ // column.children.find((item: any) => item.id === controlId)
1459
+ // )
1460
+ // if (headerColumn) {
1461
+ // const headerInstance = headerColumn.children.find(
1462
+ // (item: any) => item.id === controlId
1463
+ // )
1464
+ // if (headerInstance) {
1465
+ // instances.unshift(
1466
+ // headerInstance as ControlRuntimeInstance<ControlsKeys>
1467
+ // )
1468
+ // }
1469
+ // }
1470
+ // }
1471
+ // }
1472
+ // }
1473
+ // // @ts-ignore
1474
+ // return instances
1475
+ // }
1476
+ key: "getInstances",
1477
+ value: function getInstances(controlId) {
1478
+ var header = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
1479
+ // const cc = console
1480
+ // const label = '🐑 genInstances ' + controlId + ' ' + Date.now()
1481
+ // cc.time(label)
1482
+ if (controlId === undefined) {
1483
+ // cc.timeEnd(label)
1484
+ return this.runtime.flatInstances;
1485
+ }
1486
+ var instances = Array.from(this.runtime.instanceMap[controlId] || []);
1487
+ if (header) {
1488
+ // 如果能从flatInstances里边取到,就通过getInstanceInSubtableHeader方法取,取不到则换一种方式
1489
+ // if (instances.length) {
1490
+ // const instance: RuntimeControl = instances[0]
1491
+ // const headerInstance = this.findSubtableHeadersControl(instance.id)
1492
+ // if (headerInstance !== undefined) {
1493
+ // instances.unshift(headerInstance)
1494
+ // }
1495
+ // }
1496
+ var headerInstance = this.findSubtableHeadersControl(controlId);
1497
+ if (headerInstance !== undefined) {
1498
+ instances.unshift(headerInstance);
1499
+ }
1500
+ }
1501
+ // @ts-ignore
1502
+ return instances;
1503
+ }
1504
+ },
1505
+ {
1506
+ key: "setInstance",
1507
+ value: function setInstance(instance, props, value, rowIndex) {
1508
+ var _this = this;
1509
+ try {
1510
+ if (typeof instance === 'string' && rowIndex === -1) {
1511
+ //修改明细表整列属性的逻辑
1512
+ var instances = this.getInstances(instance, rowIndex === -1);
1513
+ instances.map(function(_instance) {
1514
+ if (_instance) {
1515
+ // @i18n-translate-ignore
1516
+ _this.debugLog("[%o]: 修改instance: %o的%o属性,修改的值为%o。", _instance.id, _instance, props, value);
1517
+ updateValueFromKeys(_instance.props, props, value);
1518
+ _this.schemaEvent('schema-change', {
1519
+ instance: _instance,
1520
+ props: props,
1521
+ value: value,
1522
+ rowIndex: rowIndex
1523
+ });
1524
+ }
1525
+ });
1526
+ } else {
1527
+ var _instance;
1528
+ if (typeof instance === 'string') {
1529
+ _instance = this.getInstance(instance, rowIndex);
1530
+ } else {
1531
+ _instance = instance;
1532
+ }
1533
+ if (!_instance) {
1534
+ return;
1535
+ }
1536
+ // @i18n-translate-ignore
1537
+ this.debugLog("[%o]: 修改instance: %o的%o属性,修改的值为%o。", _instance.id, _instance, props, value);
1538
+ updateValueFromKeys(_instance.props, props, value);
1539
+ this.schemaEvent('schema-change', {
1540
+ instance: _instance,
1541
+ props: props,
1542
+ value: value,
1543
+ rowIndex: rowIndex
1544
+ });
1545
+ }
1546
+ } catch (e) {
1547
+ throw e;
1548
+ }
1549
+ }
1550
+ },
1551
+ {
1552
+ key: "getControlIdMapping",
1553
+ value: function getControlIdMapping() {
1554
+ return this.store.controlIdMapping;
1555
+ }
1556
+ },
1557
+ {
1558
+ key: "getDataBindMapping",
1559
+ value: function getDataBindMapping(dataCode, fieldCode) {
1560
+ if (!dataCode && !fieldCode) {
1561
+ return this.store.dataBindMapping;
1562
+ }
1563
+ var mapping = this.store.dataBindMapping[dataCode];
1564
+ if (!mapping) {
1565
+ // warn(`No corresponding dataCode=${dataCode} was found`)
1566
+ return;
1567
+ }
1568
+ if (!fieldCode) {
1569
+ return mapping;
1570
+ }
1571
+ var dataBindMapping = mapping.fields.find(function(item) {
1572
+ return item.fieldCode === fieldCode;
1573
+ });
1574
+ if (!dataBindMapping) {
1575
+ // warn(`No corresponding fieldCode=${fieldCode} was found`)
1576
+ return;
1577
+ }
1578
+ return dataBindMapping;
1579
+ }
1580
+ },
1581
+ {
1582
+ key: "getAction",
1583
+ value: function getAction() {
1584
+ return this.actionManager;
1585
+ }
1586
+ },
1587
+ {
1588
+ key: "initDataManager",
1589
+ value: function initDataManager(callbackExecuter) {
1590
+ this.dataManager = new DataManager(callbackExecuter);
1591
+ }
1592
+ },
1593
+ {
1594
+ key: "getDataManager",
1595
+ value: function getDataManager() {
1596
+ return this.dataManager;
1597
+ }
1598
+ },
1599
+ {
1600
+ key: "assertInstance",
1601
+ value: /**
1602
+ * 判断控件的类型,返回当前控件的正确类型
1603
+ * */ function assertInstance(instance, types) {
1604
+ return isString(types) ? instance.type === types : types.includes(instance.type);
1605
+ }
1606
+ },
1607
+ {
1608
+ key: "assertInstanceIsCustomControl",
1609
+ value: /**
1610
+ * 判断控件或控件类型是一个自定义控件
1611
+ * */ function assertInstanceIsCustomControl(instance) {
1612
+ return !isBuiltInControls(isString(instance) ? instance : instance.type);
1613
+ }
1614
+ },
1615
+ {
1616
+ key: "getInstanceRowIndex",
1617
+ value: /**
1618
+ * 获取控件在明细子表中的行下标,
1619
+ * 如果控件在表头内,则返回-1
1620
+ * 如果控件在表内,则返回行下标
1621
+ * 如果控件不在明细表内,则返回undefined
1622
+ * */ // public getInstanceRowIndex(
1623
+ // instance: ControlRuntimeInstance<ControlsKeys> | RuntimeControl
1624
+ // ) {
1625
+ // if (!instance.parent) {
1626
+ // return
1627
+ // }
1628
+ // let rowIndex: number | undefined
1629
+ // // @ts-ignore
1630
+ // if (this.assertInstance(instance.parent, CONTROL_TYPE.SUBTABLE)) {
1631
+ // // 表头内的控件
1632
+ // // @ts-ignore
1633
+ // if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE_COLUMN)) {
1634
+ // rowIndex = -1
1635
+ // } else {
1636
+ // // @ts-ignore
1637
+ // // const index = instance.parent.children.findIndex(
1638
+ // // (item: any) => item === instance
1639
+ // // )
1640
+ // let instances = this.runtime.instanceMap[instance.id] || []
1641
+ // const index = instances.findIndex((item: any) => item === instance)
1642
+ // if (index > -1) {
1643
+ // rowIndex = index
1644
+ // }
1645
+ // }
1646
+ // } else {
1647
+ // rowIndex = this.getInstanceRowIndex(instance.parent)
1648
+ // }
1649
+ // return rowIndex
1650
+ // }
1651
+ function getInstanceRowIndex(instance) {
1652
+ if (!instance.parent) {
1653
+ return;
1654
+ }
1655
+ var rowIndex;
1656
+ var isHeaders = // @ts-ignore
1657
+ this.assertInstance(instance.parent, CONTROL_TYPE.SUBTABLE_COLUMN) && // @ts-ignore
1658
+ this.assertInstance(instance.parent.parent, CONTROL_TYPE.SUBTABLE);
1659
+ if (isHeaders) {
1660
+ rowIndex = -1;
1661
+ } else {
1662
+ var isColumnChild = this.getInstanceParentControl(instance, // @ts-ignore
1663
+ CONTROL_TYPE.SUBTABLE_COLUMN);
1664
+ if (isColumnChild) {
1665
+ var instanceList = this.runtime.instanceMap[instance.id];
1666
+ if (Object.prototype.toString.call(instanceList) === '[object Array]') {
1667
+ var index = instanceList.findIndex(function(item) {
1668
+ return item === instance;
1669
+ });
1670
+ if (index > -1) {
1671
+ rowIndex = index;
1672
+ }
1673
+ }
1674
+ }
1675
+ }
1676
+ return rowIndex;
1677
+ }
1678
+ },
1679
+ {
1680
+ key: "getInstanceParentControl",
1681
+ value: function getInstanceParentControl(instance, controlType) {
1682
+ if (!instance.parent) {
1683
+ return;
1684
+ }
1685
+ if (this.assertInstance(instance.parent, controlType)) {
1686
+ return instance.parent;
1687
+ }
1688
+ return this.getInstanceParentControl(instance.parent, controlType);
1689
+ }
1690
+ },
1691
+ {
1692
+ key: "getInstanceInSubtableHeader",
1693
+ value: function getInstanceInSubtableHeader(instance) {
1694
+ var rowIndex = this.getInstanceRowIndex(instance);
1695
+ if (rowIndex === undefined) {
1696
+ return;
1697
+ }
1698
+ if (rowIndex === -1) {
1699
+ return instance;
1700
+ }
1701
+ var columnInstance = this.assertInstance(instance, // @ts-ignore
1702
+ CONTROL_TYPE.SUBTABLE_COLUMN) ? instance : this.getInstanceParentControl(instance, // @ts-ignore
1703
+ CONTROL_TYPE.SUBTABLE_COLUMN);
1704
+ if (!columnInstance) {
1705
+ return;
1706
+ }
1707
+ var subtable = this.getInstanceParentControl(instance, // @ts-ignore
1708
+ CONTROL_TYPE.SUBTABLE);
1709
+ // @ts-ignore
1710
+ var headerColumn = subtable.props.headers.find(// @ts-ignore
1711
+ function(column) {
1712
+ return column.id === columnInstance.id;
1713
+ });
1714
+ if (!headerColumn) {
1715
+ return;
1716
+ }
1717
+ return headerColumn.children.find(// @ts-ignore
1718
+ function(item) {
1719
+ return item.id === instance.id;
1720
+ });
1721
+ }
1722
+ },
1723
+ {
1724
+ key: "setControlConfig",
1725
+ value: function setControlConfig() {
1726
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1727
+ args[_key] = arguments[_key];
1728
+ }
1729
+ var _this_runtime;
1730
+ return (_this_runtime = this.runtime).registerControlConfig.apply(_this_runtime, _to_consumable_array(args));
1731
+ }
1732
+ },
1733
+ {
1734
+ key: "getControlConfig",
1735
+ value: function getControlConfig(control) {
1736
+ return this.runtime.getControlConfig(control);
1737
+ }
1738
+ },
1739
+ {
1740
+ key: "inList",
1741
+ value: function inList(controlId) {
1742
+ var mapping = this.store.subtableHeadersControlIdMapping;
1743
+ var subtableId = undefined;
1744
+ for(var key in mapping){
1745
+ if (controlId in mapping[key]) {
1746
+ subtableId = key;
1747
+ break;
1748
+ }
1749
+ }
1750
+ return subtableId;
1751
+ }
1752
+ },
1753
+ {
1754
+ key: "findSubtableHeadersControl",
1755
+ value: function findSubtableHeadersControl(controlId) {
1756
+ var mapping = this.store.subtableHeadersControlIdMapping;
1757
+ var instance = undefined;
1758
+ for(var key in mapping){
1759
+ if (controlId in mapping[key]) {
1760
+ instance = mapping[key][controlId];
1761
+ break;
1762
+ }
1763
+ }
1764
+ return instance;
1765
+ }
1766
+ }
1767
+ ], [
1768
+ {
1769
+ key: "register",
1770
+ value: // 注册外部控件
1771
+ function register(control) {
1772
+ return Runtime.register(control, 'Runtime');
1773
+ }
1774
+ },
1775
+ {
1776
+ key: "judgeControlIsRegistered",
1777
+ value: function judgeControlIsRegistered(control) {
1778
+ return Runtime.staticRegisteredTypes.has(control.Runtime.controlType);
1779
+ }
1780
+ }
1781
+ ]);
1782
+ return Engine;
1783
+ }(Watcher);
1784
+ // @ts-ignore
1785
+ export { Engine };