@byteluck-fe/model-driven-engine 2.3.1-beta.24 → 2.3.1-beta.25

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