@byteluck-fe/model-driven-engine 2.7.0-alpha.27 → 2.7.0-alpha.28a

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.
@@ -704,6 +704,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
704
704
  var columns = this.createControl(template);
705
705
  (_inst_children = inst.children).push.apply(_inst_children, _to_consumable_array(columns));
706
706
  }
707
+ //@ts-ignore
708
+ row.parent = instance;
707
709
  return row;
708
710
  }
709
711
  },
@@ -823,6 +825,12 @@ var Engine = /*#__PURE__*/ function(Watcher) {
823
825
  return this.setInstance(instance, props, value, rowIndex);
824
826
  }
825
827
  },
828
+ {
829
+ key: "getRule",
830
+ value: function getRule(controlType, props) {
831
+ return Runtime.staticGetRules(controlType, props);
832
+ }
833
+ },
826
834
  {
827
835
  key: "getAllRules",
828
836
  value: function getAllRules(controlId) {
@@ -1132,7 +1140,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1132
1140
  value: function buildFields(dataCode, state) {
1133
1141
  var _this = this;
1134
1142
  var mapping = this.getDataBindMapping(dataCode);
1135
- if (!mapping) {
1143
+ if (!mapping || !mapping.fields) {
1136
1144
  return;
1137
1145
  }
1138
1146
  var skipKeys = [];
@@ -1328,7 +1336,59 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1328
1336
  * 获取组件实例,明细表中的组件将会得到数组, 第二个参数为(false/不传入)则获取到的是明细表内不包含表头内实例的所有控件实例,传入true则获取到包含表头内实例的所有控件实例,表头内实例永远在下标0的位置
1329
1337
  * @param controlId
1330
1338
  * @param header 明细表内是否获取表头的控件
1331
- */ key: "getInstances",
1339
+ */ // getInstances(
1340
+ // controlId?: string,
1341
+ // header: boolean = false
1342
+ // ): ControlRuntimeInstance<ControlsKeys>[] {
1343
+ // // const cc = console
1344
+ // // const label = '🐑 genInstances ' + controlId + ' ' + Date.now()
1345
+ // // cc.time(label)
1346
+ //
1347
+ // if (controlId === undefined) {
1348
+ // // cc.timeEnd(label)
1349
+ // return this.runtime.flatInstances
1350
+ // }
1351
+ // const instances = Array.from(this.runtime.instanceMap[controlId] || [])
1352
+ // if (header) {
1353
+ // // 如果能从flatInstances里边取到,就通过getInstanceInSubtableHeader方法取,取不到则换一种方式
1354
+ // if (instances.length) {
1355
+ // const instance: RuntimeControl = instances[0]
1356
+ // // if (this.inList(instance.id) === true) {
1357
+ // if (this.inList(instance.id) !== undefined) {
1358
+ // const headerInstance = this.getInstanceInSubtableHeader(instance)
1359
+ // if (headerInstance) {
1360
+ // instances.unshift(headerInstance)
1361
+ // }
1362
+ // }
1363
+ // } else {
1364
+ // const controlIdMapping = this.getControlIdMapping()
1365
+ // const [subtableId] =
1366
+ // Object.entries(controlIdMapping).find(
1367
+ // ([_, mapping]) => mapping.children && controlId in mapping.children
1368
+ // ) ?? []
1369
+ // if (subtableId) {
1370
+ // const subtable = this.getInstance(subtableId)
1371
+ // // @ts-ignore
1372
+ // const headerColumn = subtable.props.headers.find((column: any) =>
1373
+ // column.children.find((item: any) => item.id === controlId)
1374
+ // )
1375
+ // if (headerColumn) {
1376
+ // const headerInstance = headerColumn.children.find(
1377
+ // (item: any) => item.id === controlId
1378
+ // )
1379
+ // if (headerInstance) {
1380
+ // instances.unshift(
1381
+ // headerInstance as ControlRuntimeInstance<ControlsKeys>
1382
+ // )
1383
+ // }
1384
+ // }
1385
+ // }
1386
+ // }
1387
+ // }
1388
+ // // @ts-ignore
1389
+ // return instances
1390
+ // }
1391
+ key: "getInstances",
1332
1392
  value: function getInstances(controlId) {
1333
1393
  var header = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
1334
1394
  // const cc = console
@@ -1338,42 +1398,15 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1338
1398
  // cc.timeEnd(label)
1339
1399
  return this.runtime.flatInstances;
1340
1400
  }
1341
- var instances = Array.from(this.runtime.instanceMap[controlId] || []);
1401
+ var instances = this.runtime.instanceMap[controlId] || [];
1342
1402
  if (header) {
1343
- // 如果能从flatInstances里边取到,就通过getInstanceInSubtableHeader方法取,取不到则换一种方式
1344
- if (instances.length) {
1345
- var instance = instances[0];
1346
- // if (this.inList(instance.id) === true) {
1347
- if (this.inList(instance.id) !== undefined) {
1348
- var headerInstance = this.getInstanceInSubtableHeader(instance);
1349
- if (headerInstance) {
1350
- instances.unshift(headerInstance);
1351
- }
1352
- }
1353
- } else {
1354
- var _this_getControlIdMapping;
1355
- var controlIdMapping = (_this_getControlIdMapping = this.getControlIdMapping()) !== null && _this_getControlIdMapping !== void 0 ? _this_getControlIdMapping : {};
1356
- var _Object_entries_find;
1357
- var _ref = _sliced_to_array((_Object_entries_find = Object.entries(controlIdMapping).find(function(param) {
1358
- var _param = _sliced_to_array(param, 2), _ = _param[0], mapping = _param[1];
1359
- return mapping.children && controlId in mapping.children;
1360
- })) !== null && _Object_entries_find !== void 0 ? _Object_entries_find : [], 1), subtableId = _ref[0];
1361
- if (subtableId) {
1362
- var subtable = this.getInstance(subtableId);
1363
- // @ts-ignore
1364
- var headerColumn = subtable.props.headers.find(function(column) {
1365
- return column.children.find(function(item) {
1366
- return item.id === controlId;
1367
- });
1368
- });
1369
- if (headerColumn) {
1370
- var headerInstance1 = headerColumn.children.find(function(item) {
1371
- return item.id === controlId;
1372
- });
1373
- if (headerInstance1) {
1374
- instances.unshift(headerInstance1);
1375
- }
1376
- }
1403
+ var instance = instances[0];
1404
+ if (instance) {
1405
+ var _instance_parent;
1406
+ // @ts-ignore
1407
+ var parentId = (_instance_parent = instance.parent) === null || _instance_parent === void 0 ? void 0 : _instance_parent.id;
1408
+ if (parentId) {
1409
+ instances = this.runtime.instanceMap[parentId] || [];
1377
1410
  }
1378
1411
  }
1379
1412
  }
@@ -1488,55 +1521,64 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1488
1521
  * 如果控件在表头内,则返回-1
1489
1522
  * 如果控件在表内,则返回行下标
1490
1523
  * 如果控件不在明细表内,则返回undefined
1491
- * */ function getInstanceRowIndex(instance) {
1524
+ * */ // public getInstanceRowIndex(
1525
+ // instance: ControlRuntimeInstance<ControlsKeys> | RuntimeControl
1526
+ // ) {
1527
+ // if (!instance.parent) {
1528
+ // return
1529
+ // }
1530
+ // let rowIndex: number | undefined
1531
+ // // @ts-ignore
1532
+ // if (this.assertInstance(instance.parent, CONTROL_TYPE.SUBTABLE)) {
1533
+ // // 表头内的控件
1534
+ // // @ts-ignore
1535
+ // if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE_COLUMN)) {
1536
+ // rowIndex = -1
1537
+ // } else {
1538
+ // // @ts-ignore
1539
+ // // const index = instance.parent.children.findIndex(
1540
+ // // (item: any) => item === instance
1541
+ // // )
1542
+ // let instances = this.runtime.instanceMap[instance.id] || []
1543
+ // const index = instances.findIndex((item: any) => item === instance)
1544
+ // if (index > -1) {
1545
+ // rowIndex = index
1546
+ // }
1547
+ // }
1548
+ // } else {
1549
+ // rowIndex = this.getInstanceRowIndex(instance.parent)
1550
+ // }
1551
+ // return rowIndex
1552
+ // }
1553
+ function getInstanceRowIndex(instance) {
1492
1554
  if (!instance.parent) {
1493
1555
  return;
1494
1556
  }
1495
1557
  var rowIndex;
1496
1558
  // @ts-ignore
1497
- if (this.assertInstance(instance.parent, CONTROL_TYPE.SUBTABLE)) {
1498
- // 表头内的控件
1499
- // @ts-ignore
1500
- if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE_COLUMN)) {
1501
- rowIndex = -1;
1502
- } else {
1503
- // @ts-ignore
1504
- var index = instance.parent.children.findIndex(function(item) {
1505
- return item === instance;
1506
- });
1507
- if (index > -1) {
1508
- rowIndex = index;
1559
+ if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE_COLUMN)) {
1560
+ rowIndex = -1;
1561
+ } else {
1562
+ var isColumnChild = this.getInstanceParentControl(instance, // @ts-ignore
1563
+ CONTROL_TYPE.SUBTABLE_COLUMN);
1564
+ if (isColumnChild) {
1565
+ var instanceList = this.runtime.instanceMap[instance.id];
1566
+ if (Object.prototype.toString.call(instanceList) === "[object Array]") {
1567
+ var index = instanceList.findIndex(function(item) {
1568
+ return item === instance;
1569
+ });
1570
+ if (index > -1) {
1571
+ rowIndex = index;
1572
+ }
1509
1573
  }
1510
1574
  }
1511
- } else {
1512
- rowIndex = this.getInstanceRowIndex(instance.parent);
1513
1575
  }
1514
1576
  return rowIndex;
1515
1577
  }
1516
1578
  },
1517
1579
  {
1518
1580
  key: "getInstanceParentControl",
1519
- value: // public getInstanceRowIndex(
1520
- // instance: ControlRuntimeInstance<ControlsKeys> | RuntimeControl
1521
- // ) {
1522
- // let rowIndex: number | undefined
1523
- // // @ts-ignore
1524
- // if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE_COLUMN)) {
1525
- // rowIndex = -1
1526
- // }else{
1527
- // const instanceList = this.runtime.instanceMap[instance.id]
1528
- // if(Object.prototype.toString.call(instanceList) === '[object Array]'){
1529
- // const index = instanceList.findIndex(
1530
- // (item: any) => item === instance
1531
- // )
1532
- // if (index > -1) {
1533
- // rowIndex = index
1534
- // }
1535
- // }
1536
- // }
1537
- // return rowIndex
1538
- // }
1539
- function getInstanceParentControl(instance, controlType) {
1581
+ value: function getInstanceParentControl(instance, controlType) {
1540
1582
  if (!instance.parent) {
1541
1583
  return;
1542
1584
  }
@@ -1615,12 +1657,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1615
1657
  {
1616
1658
  key: "register",
1617
1659
  value: // 注册外部控件
1618
- function register() {
1619
- for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
1620
- arg[_key] = arguments[_key];
1621
- }
1622
- var _Runtime;
1623
- return (_Runtime = Runtime).register.apply(_Runtime, _to_consumable_array(arg));
1660
+ function register(control) {
1661
+ return Runtime.register(control, "Runtime");
1624
1662
  }
1625
1663
  },
1626
1664
  {
@@ -1632,4 +1670,5 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1632
1670
  ]);
1633
1671
  return Engine;
1634
1672
  }(Watcher);
1673
+ // @ts-ignore
1635
1674
  export { Engine };
@@ -97,7 +97,7 @@ function _create_super(Derived) {
97
97
  };
98
98
  }
99
99
  import { RegisterControls } from "@byteluck-fe/model-driven-core";
100
- import { CONTROL_BASE_TYPE, CONTROL_TYPE, loopFormSchema } from "@byteluck-fe/model-driven-shared";
100
+ import { CONTROL_BASE_TYPE, CONTROL_TYPE, JSONCopy, loopFormSchema, isArray } from "@byteluck-fe/model-driven-shared";
101
101
  import { hasChildrenControl, loopDataViewControl, loopFormControl } from "../utils/runtimeUtils";
102
102
  export var Runtime = /*#__PURE__*/ function(RegisterControls) {
103
103
  "use strict";
@@ -111,6 +111,7 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
111
111
  _define_property(_assert_this_initialized(_this), "_instance", void 0);
112
112
  _define_property(_assert_this_initialized(_this), "_flatInstances", []);
113
113
  _define_property(_assert_this_initialized(_this), "_instanceMap", {});
114
+ _define_property(_assert_this_initialized(_this), "_controlParentIdMap", {});
114
115
  var schema = props.schema;
115
116
  _this._schema = schema;
116
117
  _this._instance = _this.createControl(schema, props.beforeCreateInstance);
@@ -123,19 +124,32 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
123
124
  value: function getFlatInstances() {
124
125
  var instances = [];
125
126
  var instanceMap = {};
126
- loop(this._instance, function(item) {
127
+ var controlParentIdMap = {};
128
+ loop(this._instance, "", function(item, parentId) {
127
129
  // 3.4.1 避免将subtable-row 放到 _flatInstances 中
128
- if (item.type === "subtable-row" || item.type === "subtable-column") {
129
- return;
130
+ //4.3.0-lh2 将自处注释掉,为使instance.parent能取到父级
131
+ // if (item.type === 'subtable-row' || item.type === 'subtable-column') {
132
+ // return
133
+ // }
134
+ if (parentId) {
135
+ // @ts-ignore
136
+ controlParentIdMap[item.id] = parentId;
130
137
  }
131
- instances.push(item);
132
138
  if (!instanceMap[item.id]) {
133
139
  instanceMap[item.id] = [];
134
140
  }
141
+ //不知为何subtable-column会多存一次
142
+ if (item.type === "subtable-column") {
143
+ if (instanceMap[item.id].length > 0) {
144
+ return;
145
+ }
146
+ }
147
+ instances.push(item);
135
148
  instanceMap[item.id].push(item);
136
149
  });
137
150
  this._flatInstances = instances;
138
151
  this._instanceMap = instanceMap;
152
+ this._controlParentIdMap = controlParentIdMap;
139
153
  return this._flatInstances;
140
154
  }
141
155
  },
@@ -169,8 +183,9 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
169
183
  var antdRules = {};
170
184
  var ruleItems = {};
171
185
  loopDataViewControl(this._instance, function(dataView) {
172
- ruleItems[dataView.id] = dataView.rules[0];
173
- antdRules[dataView.id] = dataView.rules[0];
186
+ var result = Runtime.staticGetRules(dataView.type, dataView.props);
187
+ ruleItems[dataView.id] = JSONCopy(result[0]);
188
+ antdRules[dataView.id] = JSONCopy(result[0]);
174
189
  loopFormControl(dataView.children, function(item) {
175
190
  // if (
176
191
  // item instanceof RuntimeFormControl ||
@@ -193,7 +208,9 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
193
208
  get: function get() {
194
209
  var ruleItems = {};
195
210
  loopDataViewControl(this._instance, function(dataView) {
196
- ruleItems[dataView.id] = dataView.rules[0];
211
+ var result = Runtime.staticGetRules(dataView.type, dataView.props);
212
+ // ruleItems[dataView.id] = dataView.rules[0]
213
+ ruleItems[dataView.id] = result[0];
197
214
  loopFormControl(dataView.children, function(item) {
198
215
  // if (
199
216
  // item instanceof RuntimeFormControl ||
@@ -212,7 +229,9 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
212
229
  get: function get() {
213
230
  var antdRules = {};
214
231
  loopDataViewControl(this._instance, function(dataView) {
215
- antdRules[dataView.id] = dataView.rules[0];
232
+ var result = Runtime.staticGetRules(dataView.type, dataView.props);
233
+ // antdRules[dataView.id] = dataView.rules[0]
234
+ antdRules[dataView.id] = result[0];
216
235
  loopFormControl(dataView.children, function(item) {
217
236
  // if (
218
237
  // item instanceof RuntimeFormControl ||
@@ -229,22 +248,30 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
229
248
  ]);
230
249
  return Runtime;
231
250
  }(RegisterControls);
232
- function loop(control, callback) {
233
- if (Array.isArray(control)) {
234
- control.map(function(item) {
235
- callback(item);
236
- if (hasChildrenControl(item)) {
237
- var ctl = item;
238
- if (!ctl.children) {
239
- ctl.children = [];
240
- }
241
- // @ts-ignore
242
- loop(ctl.children, callback);
251
+ function loop(control, parentId, callback) {
252
+ var _instances = Array.isArray(control) ? control : [
253
+ control
254
+ ];
255
+ _instances.map(function(item) {
256
+ callback(item, parentId);
257
+ if (hasChildrenControl(item)) {
258
+ var ctl = item;
259
+ if (!ctl.children) {
260
+ ctl.children = [];
243
261
  }
244
- });
245
- } else {
246
- callback(control);
247
- }
262
+ // @ts-ignore
263
+ loop(ctl.children, ctl.id, callback);
264
+ }
265
+ if (hasHeaderOrFooterControl(item, "headers")) {
266
+ loop(item.props.headers, item.id, callback);
267
+ }
268
+ if (hasHeaderOrFooterControl(item, "footers")) {
269
+ loop(item.props.footers, item.id, callback);
270
+ }
271
+ });
272
+ }
273
+ function hasHeaderOrFooterControl(control, checkType) {
274
+ return checkType in control.props && isArray(control.props[checkType]);
248
275
  }
249
276
  /**
250
277
  * 控件是否在视图中隐藏,遍历查找所有parent
@@ -252,7 +279,7 @@ function loop(control, callback) {
252
279
  if (control.props.isHide) {
253
280
  return true;
254
281
  }
255
- if (control.parent === null) {
282
+ if (control.parent === null || control.parent === undefined) {
256
283
  return false;
257
284
  }
258
285
  return getControlIsHide(control.parent);
@@ -262,11 +289,14 @@ item) {
262
289
  if (getControlIsHide(item)) {
263
290
  return;
264
291
  }
292
+ var result = Runtime.staticGetRules(item.type, item.props);
265
293
  // if (item instanceof RuntimeFormControl) {
266
294
  if (item.controlType === CONTROL_BASE_TYPE.FORM) {
267
- data[item.id] = item.rules;
295
+ // data[item.id] = item.rules
296
+ data[item.id] = result;
268
297
  } else if (item.type === CONTROL_TYPE.SUBTABLE) {
269
- data[item.id] = item.rules;
298
+ // data[item.id] = item.rules
299
+ data[item.id] = result;
270
300
  var itemRules = {
271
301
  type: "array",
272
302
  fields: {}
@@ -281,8 +311,13 @@ item) {
281
311
  fields: {}
282
312
  };
283
313
  }
314
+ // // @ts-ignore
315
+ // itemRules.fields[index].fields[formControl.id] = (
316
+ // formControl as RuntimeFormControl
317
+ // ).rules
318
+ var childResult = Runtime.staticGetRules(formControl.type, formControl.props);
284
319
  // @ts-ignore
285
- itemRules.fields[index].fields[formControl.id] = formControl.rules;
320
+ itemRules.fields[index].fields[formControl.id] = childResult;
286
321
  }
287
322
  });
288
323
  });
@@ -294,15 +329,19 @@ item) {
294
329
  if (getControlIsHide(item)) {
295
330
  return;
296
331
  }
332
+ var result = Runtime.staticGetRules(item.type, item.props);
297
333
  // if (item instanceof RuntimeFormControl) {
298
334
  if (item.controlType === CONTROL_BASE_TYPE.FORM) {
299
- antdRules[item.id] = item.rules;
335
+ // antdRules[item.id] = item.rules
336
+ antdRules[item.id] = result;
300
337
  } else if (item.type === CONTROL_TYPE.SUBTABLE && item.children.length) {
301
338
  antdRules[item.id] = [];
302
339
  item.children.forEach(function(row) {
303
340
  var rules = {};
304
341
  loopFormSchema(row.children, function(formControl) {
305
- rules[formControl.id] = formControl.rules;
342
+ // rules[formControl.id] = (formControl as RuntimeFormControl).rules
343
+ var childResult = Runtime.staticGetRules(formControl.type, formControl.props);
344
+ rules[formControl.id] = childResult;
306
345
  });
307
346
  antdRules[item.id].push(rules);
308
347
  });
@@ -156,7 +156,7 @@ export var CalcPlugin = /*#__PURE__*/ function() {
156
156
  if (control.props.isHide) {
157
157
  return true;
158
158
  }
159
- if (control.parent === null) {
159
+ if (control.parent === null || control.parent === undefined) {
160
160
  return false;
161
161
  }
162
162
  return this.getControlIsHide(control.parent);