@byteluck-fe/model-driven-engine 2.6.0-alpha.17c → 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 } 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,21 +214,21 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls1) {
242
214
  ]);
243
215
  return Runtime;
244
216
  }(RegisterControls);
245
- function loop(control, parentId, callback) {
217
+ function loop(control, callback) {
246
218
  if (Array.isArray(control)) {
247
219
  control.map(function(item) {
248
- callback(item, parentId);
220
+ callback(item);
249
221
  if (hasChildrenControl(item)) {
250
222
  var ctl = item;
251
223
  if (!ctl.children) {
252
224
  ctl.children = [];
253
225
  }
254
226
  // @ts-ignore
255
- loop(ctl.children, ctl.id, callback);
227
+ loop(ctl.children, callback);
256
228
  }
257
229
  });
258
230
  } else {
259
- callback(control, parentId);
231
+ callback(control);
260
232
  }
261
233
  }
262
234
  /**
@@ -265,7 +237,7 @@ function loop(control, parentId, callback) {
265
237
  if (control.props.isHide) {
266
238
  return true;
267
239
  }
268
- if (control.parent === null || control.parent === undefined) {
240
+ if (control.parent === null) {
269
241
  return false;
270
242
  }
271
243
  return getControlIsHide(control.parent);
@@ -275,19 +247,11 @@ item) {
275
247
  if (getControlIsHide(item)) {
276
248
  return;
277
249
  }
278
- var result = [];
279
- var Rules = Runtime.staticControlsRuntimeRules.get(item.type);
280
- if (Rules) {
281
- var rules = new Rules(item.props);
282
- result = Array.from(rules);
283
- }
284
250
  // if (item instanceof RuntimeFormControl) {
285
251
  if (item.controlType === CONTROL_BASE_TYPE.FORM) {
286
- // data[item.id] = item.rules
287
- data[item.id] = result;
252
+ data[item.id] = item.rules;
288
253
  } else if (item.type === CONTROL_TYPE.SUBTABLE) {
289
- // data[item.id] = item.rules
290
- data[item.id] = result;
254
+ data[item.id] = item.rules;
291
255
  var itemRules = {
292
256
  type: 'array',
293
257
  fields: {}
@@ -302,18 +266,8 @@ item) {
302
266
  fields: {}
303
267
  };
304
268
  }
305
- // // @ts-ignore
306
- // itemRules.fields[index].fields[formControl.id] = (
307
- // formControl as RuntimeFormControl
308
- // ).rules
309
- var childResult = [];
310
- var childRules = Runtime.staticControlsRuntimeRules.get(formControl.type);
311
- if (childRules) {
312
- var childrules = new childRules(formControl.props);
313
- childResult = Array.from(childrules);
314
- }
315
269
  // @ts-ignore
316
- itemRules.fields[index].fields[formControl.id] = childResult;
270
+ itemRules.fields[index].fields[formControl.id] = formControl.rules;
317
271
  }
318
272
  });
319
273
  });
@@ -325,29 +279,15 @@ item) {
325
279
  if (getControlIsHide(item)) {
326
280
  return;
327
281
  }
328
- var result = [];
329
- var Rules = Runtime.staticControlsRuntimeRules.get(item.type);
330
- if (Rules) {
331
- var rules = new Rules(item.props);
332
- result = Array.from(rules);
333
- }
334
282
  // if (item instanceof RuntimeFormControl) {
335
283
  if (item.controlType === CONTROL_BASE_TYPE.FORM) {
336
- // antdRules[item.id] = item.rules
337
- antdRules[item.id] = result;
284
+ antdRules[item.id] = item.rules;
338
285
  } else if (item.type === CONTROL_TYPE.SUBTABLE && item.children.length) {
339
286
  antdRules[item.id] = [];
340
287
  item.children.forEach(function(row) {
341
288
  var rules = {};
342
289
  loopFormSchema(row.children, function(formControl) {
343
- // rules[formControl.id] = (formControl as RuntimeFormControl).rules
344
- var childResult = [];
345
- var childRules = Runtime.staticControlsRuntimeRules.get(formControl.type);
346
- if (childRules) {
347
- var childrules = new childRules(formControl.props);
348
- childResult = Array.from(childrules);
349
- }
350
- rules[formControl.id] = childResult;
290
+ rules[formControl.id] = formControl.rules;
351
291
  });
352
292
  antdRules[item.id].push(rules);
353
293
  });