@byteluck-fe/model-driven-engine 2.0.9 → 2.1.0-beta.1
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.
|
@@ -333,7 +333,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
333
333
|
};
|
|
334
334
|
}
|
|
335
335
|
};
|
|
336
|
-
import { DataBind, ObjectDataBind, RuntimeFormControl,
|
|
336
|
+
import { DataBind, ObjectDataBind, RuntimeFormControl, RuntimeListControl } from "@byteluck-fe/model-driven-core";
|
|
337
337
|
import { CONTROL_TYPE, DEFAULT_LOCALE, error, genNonDuplicateId, isString, JSONCopy, log, RulesMessage, updateValueFromKeys, warn, Watcher } from "@byteluck-fe/model-driven-shared";
|
|
338
338
|
import { Runtime } from "./Runtime";
|
|
339
339
|
import { Store } from "./Store";
|
|
@@ -341,6 +341,7 @@ import { findItem, proxyState } from "./proxyState";
|
|
|
341
341
|
import { ActionManager } from "./ActionManager";
|
|
342
342
|
import { DataManager } from "./DataManager";
|
|
343
343
|
import { checkerSubtableValue, checkerValue } from "./checkerValue";
|
|
344
|
+
import { genSubTableRowInstanceFromHeaders } from "./SubTableSpeedUp";
|
|
344
345
|
if (typeof window !== "undefined") {
|
|
345
346
|
// @ts-ignore
|
|
346
347
|
window.engines = {};
|
|
@@ -430,7 +431,6 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
430
431
|
this.store.state = proxyState(this.store.state, this._proxyStateCallback.bind(this), this._proxyStateBeforeSetCallback.bind(this));
|
|
431
432
|
};
|
|
432
433
|
_proto._proxyStateBeforeSetCallback = function _proxyStateBeforeSetCallback(state, key, newValue, oldValue) {
|
|
433
|
-
var _this = this;
|
|
434
434
|
var instance = findItem(this.runtime.flatInstances, key);
|
|
435
435
|
// 找不到控件说明不是改动控件上的字段,直接通过
|
|
436
436
|
if (!instance) {
|
|
@@ -438,6 +438,9 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
438
438
|
}
|
|
439
439
|
// @ts-ignore
|
|
440
440
|
if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE)) {
|
|
441
|
+
if (newValue === null) {
|
|
442
|
+
return [];
|
|
443
|
+
}
|
|
441
444
|
// @ts-ignore
|
|
442
445
|
var fieldTypeMap = instance.props.headers.reduce(function(result, column) {
|
|
443
446
|
var formInstance = column.children[0];
|
|
@@ -446,12 +449,11 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
446
449
|
}
|
|
447
450
|
return result;
|
|
448
451
|
}, {});
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
}
|
|
452
|
+
// @ts-ignore
|
|
453
|
+
var emptyState = this.getEmptyState(instance.id);
|
|
452
454
|
return newValue.map(function(row) {
|
|
453
455
|
return(// @ts-ignore
|
|
454
|
-
checkerSubtableValue(fieldTypeMap, row,
|
|
456
|
+
checkerSubtableValue(fieldTypeMap, row, emptyState));
|
|
455
457
|
});
|
|
456
458
|
}
|
|
457
459
|
var keys = key.split(".");
|
|
@@ -471,20 +473,12 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
471
473
|
}
|
|
472
474
|
};
|
|
473
475
|
_proto._handlerArrayUpdate = function _handlerArrayUpdate(state, key, type, args, result) {
|
|
474
|
-
var _this = this;
|
|
475
476
|
var subtable = findItem(this.runtime.flatInstances, key);
|
|
476
477
|
if (!_instanceof(subtable, RuntimeListControl)) return;
|
|
477
478
|
// 新增多行方法
|
|
479
|
+
// JUTODO 这里已经直接删除了创建instance 的逻辑,或许以后连这个函数都不需要调用了
|
|
478
480
|
var createRows = function(len) {
|
|
479
|
-
|
|
480
|
-
var newRows = [];
|
|
481
|
-
for(var i = 0; i < len; i++){
|
|
482
|
-
// @ts-ignore
|
|
483
|
-
var row = _this.listControlCreateRow(subtable, "subtable-row");
|
|
484
|
-
row && newRows.push(row);
|
|
485
|
-
}
|
|
486
|
-
// @ts-ignore
|
|
487
|
-
return newRows;
|
|
481
|
+
return [];
|
|
488
482
|
};
|
|
489
483
|
var options = eventOptionsTemp;
|
|
490
484
|
// @ts-ignore
|
|
@@ -569,19 +563,10 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
569
563
|
var index = this.getInstanceRowIndex(instance);
|
|
570
564
|
var options = eventOptionsTemp || {};
|
|
571
565
|
if (_instanceof(instance, RuntimeListControl)) {
|
|
572
|
-
var // @ts-ignore
|
|
573
|
-
_instance_children;
|
|
574
566
|
instance.children.length = 0;
|
|
575
567
|
var newValue = value;
|
|
576
568
|
// @ts-ignore
|
|
577
569
|
var newRows = [];
|
|
578
|
-
for(var i = 0; i < newValue.length; i++){
|
|
579
|
-
// @ts-ignore
|
|
580
|
-
var row = this.listControlCreateRow(instance, "subtable-row");
|
|
581
|
-
row && newRows.push(row);
|
|
582
|
-
}
|
|
583
|
-
(_instance_children = instance.children).push.apply(_instance_children, _toConsumableArray(newRows));
|
|
584
|
-
this.runtime.getFlatInstances();
|
|
585
570
|
// 这里已经能拿到控件实例,所以在这里触发setStates,触发每一行每一个控件的change事件
|
|
586
571
|
// for (let i = 0; i < newValue.length; i++) {
|
|
587
572
|
// this.setStates(newValue[i], i, options)
|
|
@@ -624,23 +609,13 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
624
609
|
this.__pluginsApplied = true;
|
|
625
610
|
};
|
|
626
611
|
_proto.listControlCreateRow = function listControlCreateRow(instance, rowType) {
|
|
627
|
-
|
|
628
|
-
if (!row) return;
|
|
629
|
-
if (_instanceof(row, RuntimeLayoutControl)) {
|
|
630
|
-
var _row_children;
|
|
631
|
-
var template = JSONCopy(instance.props.headers);
|
|
632
|
-
// @ts-ignore
|
|
633
|
-
var columns = this.createControl(template);
|
|
634
|
-
(_row_children = row.children).push.apply(_row_children, _toConsumableArray(columns));
|
|
635
|
-
}
|
|
636
|
-
return row;
|
|
612
|
+
throw new Error("该api已废弃");
|
|
637
613
|
};
|
|
638
614
|
_proto.listControlAddRow = function listControlAddRow(instance) {
|
|
639
615
|
var // @ts-ignore
|
|
640
616
|
rowType = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "subtable-row";
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
instance.children.push(row);
|
|
617
|
+
// JUTODO 这似乎是个二开api
|
|
618
|
+
throw new Error("该api已废弃");
|
|
644
619
|
};
|
|
645
620
|
// payload应该是runtimeSchema和value,然后通过runTimeSchema去找需要修改的data里边的key
|
|
646
621
|
_proto.emit = function emit(eventKey, payload) {
|
|
@@ -879,7 +854,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
879
854
|
for(var keyChi1 in item[keyChi]){
|
|
880
855
|
var _controlIdMapping_key_children_keyChi2;
|
|
881
856
|
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];
|
|
882
|
-
//
|
|
857
|
+
//
|
|
883
858
|
}
|
|
884
859
|
}
|
|
885
860
|
}
|
|
@@ -1313,6 +1288,27 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
1313
1288
|
_proto.getControlConfig = function getControlConfig(control) {
|
|
1314
1289
|
return this.runtime.getControlConfig(control);
|
|
1315
1290
|
};
|
|
1291
|
+
_proto.initSubTableRowPropsFromInstanceHeaders = function initSubTableRowPropsFromInstanceHeaders(instance) {
|
|
1292
|
+
var cc = console;
|
|
1293
|
+
var now = Date.now();
|
|
1294
|
+
var timeLabel = "\uD83D\uDC2E initSubTableRowPropsFromInstanceHeaders " + now;
|
|
1295
|
+
cc.time(timeLabel);
|
|
1296
|
+
/**headers实际 是 SubTableColumnControl的数组 */ Object.assign(instance.rowProps, genSubTableRowInstanceFromHeaders(instance.props.headers));
|
|
1297
|
+
cc.timeEnd(timeLabel);
|
|
1298
|
+
};
|
|
1299
|
+
_proto.initSubTableRowPropsFromProxySetNewValue = function initSubTableRowPropsFromProxySetNewValue(instance, value) {
|
|
1300
|
+
var cc = console;
|
|
1301
|
+
var now = Date.now();
|
|
1302
|
+
var timeLabel = "\uD83D\uDC37 initSubTableRowPropsFromProxySetNewValue " + now;
|
|
1303
|
+
cc.time(timeLabel);
|
|
1304
|
+
value.forEach(function(item) {
|
|
1305
|
+
Object.assign(instance.rowProps, {
|
|
1306
|
+
// 这里只是做个性能测试,实际上需要merge rowProps,并且还需要一个恰当的key
|
|
1307
|
+
now: genSubTableRowInstanceFromHeaders(instance.props.headers)
|
|
1308
|
+
});
|
|
1309
|
+
});
|
|
1310
|
+
cc.timeEnd(timeLabel);
|
|
1311
|
+
};
|
|
1316
1312
|
// 注册外部控件
|
|
1317
1313
|
Engine.register = function register() {
|
|
1318
1314
|
for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// import { RuntimeSubTableColumnControl } from '@byteluck-fe/model-driven-core'
|
|
2
|
+
// import { RuntimeControl } from '@byteluck-fe/model-driven-core'
|
|
3
|
+
import cloneDeep from "lodash.clonedeep";
|
|
4
|
+
export function genSubTableRowInstanceFromHeaders(// headers: RuntimeSubTableColumnControl[]
|
|
5
|
+
headers) {
|
|
6
|
+
var subtableRow = headers.reduce(function(pre, cur) {
|
|
7
|
+
var children = cur.children;
|
|
8
|
+
children.forEach(function(control) {
|
|
9
|
+
pre[control.id] = copyPropsFromControlInstance(control);
|
|
10
|
+
});
|
|
11
|
+
return pre;
|
|
12
|
+
}, {});
|
|
13
|
+
return subtableRow;
|
|
14
|
+
}
|
|
15
|
+
function copyPropsFromControlInstance(control) {
|
|
16
|
+
return cloneDeep(control.props);
|
|
17
|
+
}
|