@byteluck-fe/model-driven-engine 2.6.0-alpha.17d → 2.6.0-alpha.18

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.
@@ -1337,55 +1337,55 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1337
1337
  * 如果控件在表头内,则返回-1
1338
1338
  * 如果控件在表内,则返回行下标
1339
1339
  * 如果控件不在明细表内,则返回undefined
1340
- * */ // public getInstanceRowIndex(
1341
- // instance: ControlRuntimeInstance<ControlsKeys> | RuntimeControl
1342
- // ) {
1343
- // if (!instance.parent) {
1344
- // return
1345
- // }
1346
- // let rowIndex: number | undefined
1347
- // // @ts-ignore
1348
- // if (this.assertInstance(instance.parent, CONTROL_TYPE.SUBTABLE)) {
1349
- // // 表头内的控件
1350
- // // @ts-ignore
1351
- // if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE_COLUMN)) {
1352
- // rowIndex = -1
1353
- // } else {
1354
- // // @ts-ignore
1355
- // const index = instance.parent.children.findIndex(
1356
- // (item: any) => item === instance
1357
- // )
1358
- // if (index > -1) {
1359
- // rowIndex = index
1360
- // }
1361
- // }
1362
- // } else {
1363
- // rowIndex = this.getInstanceRowIndex(instance.parent)
1364
- // }
1365
- // return rowIndex
1366
- // }
1367
- function getInstanceRowIndex(instance) {
1340
+ * */ function getInstanceRowIndex(instance) {
1341
+ if (!instance.parent) {
1342
+ return;
1343
+ }
1368
1344
  var rowIndex;
1369
1345
  // @ts-ignore
1370
- if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE_COLUMN)) {
1371
- rowIndex = -1;
1372
- } else {
1373
- var instanceList = this.runtime.instanceMap[instance.id];
1374
- if (Object.prototype.toString.call(instanceList) === '[object Array]') {
1375
- var index = instanceList.findIndex(function(item) {
1346
+ if (this.assertInstance(instance.parent, CONTROL_TYPE.SUBTABLE)) {
1347
+ // 表头内的控件
1348
+ // @ts-ignore
1349
+ if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE_COLUMN)) {
1350
+ rowIndex = -1;
1351
+ } else {
1352
+ // @ts-ignore
1353
+ var index = instance.parent.children.findIndex(function(item) {
1376
1354
  return item === instance;
1377
1355
  });
1378
1356
  if (index > -1) {
1379
1357
  rowIndex = index;
1380
1358
  }
1381
1359
  }
1360
+ } else {
1361
+ rowIndex = this.getInstanceRowIndex(instance.parent);
1382
1362
  }
1383
1363
  return rowIndex;
1384
1364
  }
1385
1365
  },
1386
1366
  {
1387
1367
  key: "getInstanceParentControl",
1388
- value: function getInstanceParentControl(instance, controlType) {
1368
+ value: // public getInstanceRowIndex(
1369
+ // instance: ControlRuntimeInstance<ControlsKeys> | RuntimeControl
1370
+ // ) {
1371
+ // let rowIndex: number | undefined
1372
+ // // @ts-ignore
1373
+ // if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE_COLUMN)) {
1374
+ // rowIndex = -1
1375
+ // }else{
1376
+ // const instanceList = this.runtime.instanceMap[instance.id]
1377
+ // if(Object.prototype.toString.call(instanceList) === '[object Array]'){
1378
+ // const index = instanceList.findIndex(
1379
+ // (item: any) => item === instance
1380
+ // )
1381
+ // if (index > -1) {
1382
+ // rowIndex = index
1383
+ // }
1384
+ // }
1385
+ // }
1386
+ // return rowIndex
1387
+ // }
1388
+ function getInstanceParentControl(instance, controlType) {
1389
1389
  if (!instance.parent) {
1390
1390
  return;
1391
1391
  }
@@ -1466,8 +1466,12 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1466
1466
  {
1467
1467
  key: "register",
1468
1468
  value: // 注册外部控件
1469
- function register(control) {
1470
- return Runtime.register(control, 'Runtime');
1469
+ function register() {
1470
+ for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
1471
+ arg[_key] = arguments[_key];
1472
+ }
1473
+ var _Runtime;
1474
+ return (_Runtime = Runtime).register.apply(_Runtime, _toConsumableArray(arg));
1471
1475
  }
1472
1476
  },
1473
1477
  {
@@ -84,7 +84,7 @@ function _createSuper(Derived) {
84
84
  };
85
85
  }
86
86
  import { RegisterControls } from '@byteluck-fe/model-driven-core';
87
- import { CONTROL_BASE_TYPE, CONTROL_TYPE, JSONCopy, loopFormSchema, isArray } from '@byteluck-fe/model-driven-shared';
87
+ import { CONTROL_BASE_TYPE, CONTROL_TYPE, loopFormSchema } from '@byteluck-fe/model-driven-shared';
88
88
  import { hasChildrenControl, loopDataViewControl, loopFormControl } from '../utils/runtimeUtils';
89
89
  export var Runtime = /*#__PURE__*/ function(RegisterControls1) {
90
90
  "use strict";
@@ -96,7 +96,6 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls1) {
96
96
  _this = _super.call(this, 'Runtime');
97
97
  _this._flatInstances = [];
98
98
  _this._instanceMap = {};
99
- _this._controlParentIdMap = {};
100
99
  var schema = props.schema;
101
100
  _this._schema = schema;
102
101
  _this._instance = _this.createControl(schema, props.beforeCreateInstance);
@@ -109,26 +108,19 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls1) {
109
108
  value: function getFlatInstances() {
110
109
  var instances = [];
111
110
  var instanceMap = {};
112
- var controlParentIdMap = {};
113
- loop(this._instance, '', function(item, parentId) {
111
+ loop(this._instance, function(item) {
114
112
  // 3.4.1 避免将subtable-row 放到 _flatInstances 中
115
- //4.3.0-lh2 将自处注释掉,为使instance.parent能取到父级
116
- // if (item.type === 'subtable-row' || item.type === 'subtable-column') {
117
- // return
118
- // }
113
+ if (item.type === 'subtable-row' || item.type === 'subtable-column') {
114
+ return;
115
+ }
119
116
  instances.push(item);
120
117
  if (!instanceMap[item.id]) {
121
118
  instanceMap[item.id] = [];
122
119
  }
123
120
  instanceMap[item.id].push(item);
124
- if (parentId) {
125
- // @ts-ignore
126
- controlParentIdMap[item.id] = parentId;
127
- }
128
121
  });
129
122
  this._flatInstances = instances;
130
123
  this._instanceMap = instanceMap;
131
- this._controlParentIdMap = controlParentIdMap;
132
124
  return this._flatInstances;
133
125
  }
134
126
  },
@@ -162,14 +154,8 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls1) {
162
154
  var antdRules = {};
163
155
  var ruleItems = {};
164
156
  loopDataViewControl(this._instance, function(dataView) {
165
- var result = {};
166
- var Rules = Runtime.staticControlsRuntimeRules.get(dataView.type);
167
- if (Rules) {
168
- var rules = new Rules(dataView.props);
169
- result = Array.from(rules)[0];
170
- }
171
- ruleItems[dataView.id] = JSONCopy(result);
172
- antdRules[dataView.id] = JSONCopy(result);
157
+ ruleItems[dataView.id] = dataView.rules[0];
158
+ antdRules[dataView.id] = dataView.rules[0];
173
159
  loopFormControl(dataView.children, function(item) {
174
160
  // if (
175
161
  // item instanceof RuntimeFormControl ||
@@ -192,14 +178,7 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls1) {
192
178
  get: function get() {
193
179
  var ruleItems = {};
194
180
  loopDataViewControl(this._instance, function(dataView) {
195
- var result = {};
196
- var Rules = Runtime.staticControlsRuntimeRules.get(dataView.type);
197
- if (Rules) {
198
- var rules = new Rules(dataView.props);
199
- result = Array.from(rules)[0];
200
- }
201
- // ruleItems[dataView.id] = dataView.rules[0]
202
- ruleItems[dataView.id] = result;
181
+ ruleItems[dataView.id] = dataView.rules[0];
203
182
  loopFormControl(dataView.children, function(item) {
204
183
  // if (
205
184
  // item instanceof RuntimeFormControl ||
@@ -218,14 +197,7 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls1) {
218
197
  get: function get() {
219
198
  var antdRules = {};
220
199
  loopDataViewControl(this._instance, function(dataView) {
221
- var result = {};
222
- var Rules = Runtime.staticControlsRuntimeRules.get(dataView.type);
223
- if (Rules) {
224
- var rules = new Rules(dataView.props);
225
- result = Array.from(rules)[0];
226
- }
227
- // antdRules[dataView.id] = dataView.rules[0]
228
- antdRules[dataView.id] = result;
200
+ antdRules[dataView.id] = dataView.rules[0];
229
201
  loopFormControl(dataView.children, function(item) {
230
202
  // if (
231
203
  // item instanceof RuntimeFormControl ||
@@ -242,30 +214,22 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls1) {
242
214
  ]);
243
215
  return Runtime;
244
216
  }(RegisterControls);
245
- function loop(control, parentId, callback) {
246
- var _instances = Array.isArray(control) ? control : [
247
- control
248
- ];
249
- _instances.map(function(item) {
250
- callback(item, parentId);
251
- if (hasChildrenControl(item)) {
252
- var ctl = item;
253
- if (!ctl.children) {
254
- ctl.children = [];
217
+ function loop(control, callback) {
218
+ if (Array.isArray(control)) {
219
+ control.map(function(item) {
220
+ callback(item);
221
+ if (hasChildrenControl(item)) {
222
+ var ctl = item;
223
+ if (!ctl.children) {
224
+ ctl.children = [];
225
+ }
226
+ // @ts-ignore
227
+ loop(ctl.children, callback);
255
228
  }
256
- // @ts-ignore
257
- loop(ctl.children, ctl.id, callback);
258
- }
259
- if (hasHeaderOrFooterControl(item, 'headers')) {
260
- loop(item.props.headers, item.id, callback);
261
- }
262
- if (hasHeaderOrFooterControl(item, 'footers')) {
263
- loop(item.props.footers, item.id, callback);
264
- }
265
- });
266
- }
267
- function hasHeaderOrFooterControl(control, checkType) {
268
- return checkType in control.props && isArray(control.props[checkType]);
229
+ });
230
+ } else {
231
+ callback(control);
232
+ }
269
233
  }
270
234
  /**
271
235
  * 控件是否在视图中隐藏,遍历查找所有parent
@@ -273,7 +237,7 @@ function hasHeaderOrFooterControl(control, checkType) {
273
237
  if (control.props.isHide) {
274
238
  return true;
275
239
  }
276
- if (control.parent === null || control.parent === undefined) {
240
+ if (control.parent === null) {
277
241
  return false;
278
242
  }
279
243
  return getControlIsHide(control.parent);
@@ -283,19 +247,11 @@ item) {
283
247
  if (getControlIsHide(item)) {
284
248
  return;
285
249
  }
286
- var result = [];
287
- var Rules = Runtime.staticControlsRuntimeRules.get(item.type);
288
- if (Rules) {
289
- var rules = new Rules(item.props);
290
- result = Array.from(rules);
291
- }
292
250
  // if (item instanceof RuntimeFormControl) {
293
251
  if (item.controlType === CONTROL_BASE_TYPE.FORM) {
294
- // data[item.id] = item.rules
295
- data[item.id] = result;
252
+ data[item.id] = item.rules;
296
253
  } else if (item.type === CONTROL_TYPE.SUBTABLE) {
297
- // data[item.id] = item.rules
298
- data[item.id] = result;
254
+ data[item.id] = item.rules;
299
255
  var itemRules = {
300
256
  type: 'array',
301
257
  fields: {}
@@ -310,18 +266,8 @@ item) {
310
266
  fields: {}
311
267
  };
312
268
  }
313
- // // @ts-ignore
314
- // itemRules.fields[index].fields[formControl.id] = (
315
- // formControl as RuntimeFormControl
316
- // ).rules
317
- var childResult = [];
318
- var childRules = Runtime.staticControlsRuntimeRules.get(formControl.type);
319
- if (childRules) {
320
- var childrules = new childRules(formControl.props);
321
- childResult = Array.from(childrules);
322
- }
323
269
  // @ts-ignore
324
- itemRules.fields[index].fields[formControl.id] = childResult;
270
+ itemRules.fields[index].fields[formControl.id] = formControl.rules;
325
271
  }
326
272
  });
327
273
  });
@@ -333,29 +279,15 @@ item) {
333
279
  if (getControlIsHide(item)) {
334
280
  return;
335
281
  }
336
- var result = [];
337
- var Rules = Runtime.staticControlsRuntimeRules.get(item.type);
338
- if (Rules) {
339
- var rules = new Rules(item.props);
340
- result = Array.from(rules);
341
- }
342
282
  // if (item instanceof RuntimeFormControl) {
343
283
  if (item.controlType === CONTROL_BASE_TYPE.FORM) {
344
- // antdRules[item.id] = item.rules
345
- antdRules[item.id] = result;
284
+ antdRules[item.id] = item.rules;
346
285
  } else if (item.type === CONTROL_TYPE.SUBTABLE && item.children.length) {
347
286
  antdRules[item.id] = [];
348
287
  item.children.forEach(function(row) {
349
288
  var rules = {};
350
289
  loopFormSchema(row.children, function(formControl) {
351
- // rules[formControl.id] = (formControl as RuntimeFormControl).rules
352
- var childResult = [];
353
- var childRules = Runtime.staticControlsRuntimeRules.get(formControl.type);
354
- if (childRules) {
355
- var childrules = new childRules(formControl.props);
356
- childResult = Array.from(childrules);
357
- }
358
- rules[formControl.id] = childResult;
290
+ rules[formControl.id] = formControl.rules;
359
291
  });
360
292
  antdRules[item.id].push(rules);
361
293
  });