@byteluck-fe/model-driven-engine 2.1.0-beta.4 → 2.1.0-sourcemap.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.
@@ -333,7 +333,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
333
333
  };
334
334
  }
335
335
  };
336
- import { DataBind, ObjectDataBind, RuntimeFormControl, RuntimeListControl } from "@byteluck-fe/model-driven-core";
336
+ import { DataBind, ObjectDataBind, RuntimeFormControl, RuntimeLayoutControl, 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,7 +341,6 @@ 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";
345
344
  if (typeof window !== "undefined") {
346
345
  // @ts-ignore
347
346
  window.engines = {};
@@ -359,6 +358,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
359
358
  _classCallCheck(this, Engine);
360
359
  var _this;
361
360
  _this = _super.call(this);
361
+ _this.rawStore = {};
362
362
  // 提供子线程处理脚本以及修改数据的能力
363
363
  // public worker: OkWorker
364
364
  _this.isMounted = false;
@@ -431,7 +431,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
431
431
  this.store.state = proxyState(this.store.state, this._proxyStateCallback.bind(this), this._proxyStateBeforeSetCallback.bind(this));
432
432
  };
433
433
  _proto._proxyStateBeforeSetCallback = function _proxyStateBeforeSetCallback(state, key, newValue, oldValue) {
434
- var instance = findItem(this.runtime.flatInstances, key, this.store, this.runtime);
434
+ var instance = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
435
435
  // 找不到控件说明不是改动控件上的字段,直接通过
436
436
  if (!instance) {
437
437
  return newValue;
@@ -473,12 +473,20 @@ var Engine = /*#__PURE__*/ function(Watcher) {
473
473
  }
474
474
  };
475
475
  _proto._handlerArrayUpdate = function _handlerArrayUpdate(state, key, type, args, result) {
476
- var subtable = findItem(this.runtime.flatInstances, key, this.store, this.runtime);
476
+ var _this = this;
477
+ var subtable = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
477
478
  if (!_instanceof(subtable, RuntimeListControl)) return;
478
479
  // 新增多行方法
479
- // JUTODO 这里已经直接删除了创建instance 的逻辑,或许以后连这个函数都不需要调用了
480
480
  var createRows = function(len) {
481
- return [];
481
+ // @ts-ignore
482
+ var newRows = [];
483
+ for(var i = 0; i < len; i++){
484
+ // @ts-ignore
485
+ var row = _this.listControlCreateRow(subtable, "subtable-row");
486
+ row && newRows.push(row);
487
+ }
488
+ // @ts-ignore
489
+ return newRows;
482
490
  };
483
491
  var options = eventOptionsTemp;
484
492
  // @ts-ignore
@@ -556,17 +564,26 @@ var Engine = /*#__PURE__*/ function(Watcher) {
556
564
  }
557
565
  };
558
566
  _proto._handlerObjectUpdate = function _handlerObjectUpdate(state, key, value, oldValue) {
559
- var instance = findItem(this.runtime.flatInstances, key, this.store, this.runtime);
567
+ var instance = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
560
568
  if (!instance) {
561
569
  return;
562
570
  }
563
571
  var index = this.getInstanceRowIndex(instance);
564
572
  var options = eventOptionsTemp || {};
565
573
  if (_instanceof(instance, RuntimeListControl)) {
574
+ var // @ts-ignore
575
+ _instance_children;
566
576
  instance.children.length = 0;
567
577
  var newValue = value;
568
578
  // @ts-ignore
569
579
  var newRows = [];
580
+ for(var i = 0; i < newValue.length; i++){
581
+ // @ts-ignore
582
+ var row = this.listControlCreateRow(instance, "subtable-row");
583
+ row && newRows.push(row);
584
+ }
585
+ (_instance_children = instance.children).push.apply(_instance_children, _toConsumableArray(newRows));
586
+ this.runtime.getFlatInstances();
570
587
  // 这里已经能拿到控件实例,所以在这里触发setStates,触发每一行每一个控件的change事件
571
588
  // for (let i = 0; i < newValue.length; i++) {
572
589
  // this.setStates(newValue[i], i, options)
@@ -609,13 +626,23 @@ var Engine = /*#__PURE__*/ function(Watcher) {
609
626
  this.__pluginsApplied = true;
610
627
  };
611
628
  _proto.listControlCreateRow = function listControlCreateRow(instance, rowType) {
612
- throw new Error("该api已废弃");
629
+ var row = this.runtime.createControlInstance(rowType);
630
+ if (!row) return;
631
+ if (_instanceof(row, RuntimeLayoutControl)) {
632
+ var _row_children;
633
+ var template = JSONCopy(instance.props.headers);
634
+ // @ts-ignore
635
+ var columns = this.createControl(template);
636
+ (_row_children = row.children).push.apply(_row_children, _toConsumableArray(columns));
637
+ }
638
+ return row;
613
639
  };
614
640
  _proto.listControlAddRow = function listControlAddRow(instance) {
615
641
  var // @ts-ignore
616
642
  rowType = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "subtable-row";
617
- // JUTODO 这似乎是个二开api
618
- throw new Error("该api已废弃");
643
+ var row = this.listControlCreateRow(instance, rowType);
644
+ if (!row) return;
645
+ instance.children.push(row);
619
646
  };
620
647
  // payload应该是runtimeSchema和value,然后通过runTimeSchema去找需要修改的data里边的key
621
648
  _proto.emit = function emit(eventKey, payload) {
@@ -1105,13 +1132,14 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1105
1132
  * @param header 明细表内是否获取表头的控件
1106
1133
  */ _proto.getInstances = function getInstances(controlId) {
1107
1134
  var header = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
1135
+ var cc = console;
1136
+ var label = "\uD83D\uDC11 genInstances " + controlId + " " + Date.now();
1137
+ cc.time(label);
1108
1138
  if (controlId === undefined) {
1139
+ cc.timeEnd(label);
1109
1140
  return this.runtime.flatInstances;
1110
1141
  }
1111
- var instances = this.runtime.flatInstances.filter(// @ts-ignore
1112
- function(item) {
1113
- return item.id === controlId;
1114
- });
1142
+ var instances = this.runtime.instanceMap[controlId] || [];
1115
1143
  if (header) {
1116
1144
  // 如果能从flatInstances里边取到,就通过getInstanceInSubtableHeader方法取,取不到则换一种方式
1117
1145
  if (instances.length) {
@@ -1148,6 +1176,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1148
1176
  }
1149
1177
  }
1150
1178
  }
1179
+ cc.timeEnd(label);
1151
1180
  return instances;
1152
1181
  };
1153
1182
  _proto.setInstance = function setInstance(instance, props, value, rowIndex) {
@@ -1288,27 +1317,6 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1288
1317
  _proto.getControlConfig = function getControlConfig(control) {
1289
1318
  return this.runtime.getControlConfig(control);
1290
1319
  };
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
- };
1312
1320
  // 注册外部控件
1313
1321
  Engine.register = function register() {
1314
1322
  for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
@@ -1323,3 +1331,4 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1323
1331
  return Engine;
1324
1332
  }(Watcher);
1325
1333
  export { Engine };
1334
+ console.log("a");
@@ -114,6 +114,10 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
114
114
  var instances = [];
115
115
  var instanceMap = {};
116
116
  loop(this._instance, function(item) {
117
+ // 3.4.1 避免将 subtable-column 放到 _flatInstances 中
118
+ if (item.type === "subtable-column") {
119
+ return;
120
+ }
117
121
  instances.push(item);
118
122
  if (!instanceMap[item.id]) {
119
123
  instanceMap[item.id] = [];
@@ -30,9 +30,9 @@ function _unsupportedIterableToArray(o, minLen) {
30
30
  if (n === "Map" || n === "Set") return Array.from(n);
31
31
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
32
32
  }
33
- import { RuntimeFormControl, RuntimeListControl } from "@byteluck-fe/model-driven-core";
34
- import { error, log, logerror, warn } from "@byteluck-fe/model-driven-shared";
35
- import { copyPropsFromControlInstance } from "./SubTableSpeedUp";
33
+ import { RuntimeFormControl } from "@byteluck-fe/model-driven-core";
34
+ import { error, logerror } from "@byteluck-fe/model-driven-shared";
35
+ var cc = console;
36
36
  var proxyArrayApi = [
37
37
  "splice",
38
38
  "push",
@@ -218,99 +218,25 @@ function flatInstanceForChildren(controls) {
218
218
  });
219
219
  return result;
220
220
  }
221
- var findRowIndex = function(keys) {
222
- return keys.find(isNumberString);
223
- };
224
- var isNumberString = function(item) {
225
- return item === String(Number(item));
226
- };
227
- var isInSubtable = function(keys) {
228
- return keys.some(isNumberString);
229
- };
230
- var findSubTableInstanceFromKeyPath = function(flatInstance, keys) {
231
- if (keys.length < 2) {
232
- warn("未找到 明细子表控件", keys);
233
- return undefined;
234
- }
235
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
236
- try {
237
- for(var _iterator = flatInstance[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
238
- var instance = _step.value;
239
- if (keys.includes(instance.id)) {
240
- if (_instanceof(instance, RuntimeListControl)) {
241
- return instance;
242
- }
243
- }
244
- }
245
- } catch (err) {
246
- _didIteratorError = true;
247
- _iteratorError = err;
248
- } finally{
249
- try {
250
- if (!_iteratorNormalCompletion && _iterator.return != null) {
251
- _iterator.return();
252
- }
253
- } finally{
254
- if (_didIteratorError) {
255
- throw _iteratorError;
256
- }
257
- }
258
- }
259
- warn("未找到 明细子表控件", keys);
260
- return undefined;
261
- };
262
221
  /**
263
222
  * 在flatInstance中通过key查找出对应的instance
264
223
  * @param flatInstance 拍平的instance数组
265
224
  * @param key 操作的数据在state的key - 可以是深层次的 subtable.0.input等
266
- * */ export function findItem(flatInstance, key, store, runtime) {
225
+ * */ export function findItem(flatInstance, key, instanceMap) {
267
226
  if (key === "") return undefined;
268
227
  var keys = key.split(".");
269
228
  if (keys.length === 0) return undefined;
270
- // 在明细子表里的,就直接给create 一个 instance,并从subtable instance上取得对应 目标的props 赋值上去
271
- if (isInSubtable(keys)) {
272
- console.log("findItem isInSubtable");
273
- // 先找到 明细子表的instance
274
- var subTableInstance = findSubTableInstanceFromKeyPath(flatInstance, keys);
275
- if (!subTableInstance) {
276
- return undefined;
277
- }
278
- // 再找到 明细子表的 state
279
- var subTableState = store.getState(subTableInstance.id);
280
- if (!subTableState) {
281
- return undefined;
282
- }
283
- var rowIndex = Number(findRowIndex(keys));
284
- if (!Number.isInteger(rowIndex)) {
285
- return undefined;
286
- }
287
- // 最后找到 行 的state
288
- var rowState = subTableState[rowIndex];
289
- var rowUid = rowState.uid;
290
- var headerInstances = subTableInstance.props.headers.map(function(v) {
291
- return v.children[0];
292
- });
293
- var columnId = keys[keys.length - 1];
294
- var targetInstance = headerInstances.find(function(i) {
295
- return i.id === columnId;
296
- });
297
- if (!targetInstance) {
298
- return undefined;
299
- }
300
- // 当 rowProps 中没有对应的 rowProps时候,进行copy
301
- if (rowUid && !subTableInstance.rowProps[rowUid]) {
302
- log("\uD83C\uDF1F copy rowProps", subTableInstance.id, rowUid, columnId);
303
- subTableInstance.rowProps[rowUid] = copyPropsFromControlInstance(targetInstance);
304
- }
305
- // @ts-ignore
306
- var tempInstance = runtime.createControlInstance(targetInstance.type);
307
- return tempInstance;
308
- }
309
229
  var oneKey = keys[0];
310
230
  var otherKeys = keys.slice(1);
311
- var initInstance = flatInstance.find(function(item) {
312
- return item.id === oneKey;
313
- });
231
+ // 3.4.1 优化速度,读取instanceMap
232
+ // cc.time('findItem flatInstance find')
233
+ // const initInstance = flatInstance.find((item) => item.id === oneKey)
234
+ // cc.log('🏠 findItem flatInstance find result', initInstance)
235
+ // cc.timeEnd('findItem flatInstance find')
236
+ // cc.time('findItem instanceMap match')
237
+ var initInstance = instanceMap[oneKey] ? instanceMap[oneKey][0] : undefined;
238
+ // cc.log('🏠 findItem instanceMap match result', initInstance)
239
+ // cc.timeEnd('findItem instanceMap match')
314
240
  if (otherKeys.length === 0) return initInstance;
315
241
  // @ts-ignore
316
242
  return otherKeys.reduce(function(prevItem, key) {