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

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.
@@ -680,6 +680,12 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
680
680
  return this.setInstance(instance, props, value, rowIndex);
681
681
  }
682
682
  },
683
+ {
684
+ key: "getRule",
685
+ value: function getRule(controlType, props) {
686
+ return Runtime.staticGetRules(controlType, props);
687
+ }
688
+ },
683
689
  {
684
690
  key: "getAllRules",
685
691
  value: function getAllRules(controlId) {
@@ -1343,14 +1349,18 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1343
1349
  }
1344
1350
  var rowIndex;
1345
1351
  // @ts-ignore
1346
- if (this.assertInstance(instance.parent, CONTROL_TYPE.SUBTABLE)) {
1352
+ if (this.assertInstance(instance.parent, CONTROL_TYPE.SUBTABLE) || this.assertInstance(instance.parent, CONTROL_TYPE.SUBTABLE_COLUMN)) {
1347
1353
  // 表头内的控件
1348
1354
  // @ts-ignore
1349
1355
  if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE_COLUMN)) {
1350
1356
  rowIndex = -1;
1351
1357
  } else {
1352
1358
  // @ts-ignore
1353
- var index = instance.parent.children.findIndex(function(item) {
1359
+ // const index = instance.parent.children.findIndex(
1360
+ // (item: any) => item === instance
1361
+ // )
1362
+ var instances = this.runtime.instanceMap[instance.id] || [];
1363
+ var index = instances.findIndex(function(item) {
1354
1364
  return item === instance;
1355
1365
  });
1356
1366
  if (index > -1) {
@@ -1466,12 +1476,8 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1466
1476
  {
1467
1477
  key: "register",
1468
1478
  value: // 注册外部控件
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));
1479
+ function register(control) {
1480
+ return Runtime.register(control, 'Runtime');
1475
1481
  }
1476
1482
  },
1477
1483
  {
@@ -1483,5 +1489,5 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1483
1489
  ]);
1484
1490
  return Engine;
1485
1491
  }(Watcher);
1492
+ // @ts-ignore
1486
1493
  export { Engine };
1487
- console.log('a');
@@ -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, loopFormSchema } from '@byteluck-fe/model-driven-shared';
87
+ import { CONTROL_BASE_TYPE, CONTROL_TYPE, JSONCopy, loopFormSchema, isArray } 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,6 +96,7 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls1) {
96
96
  _this = _super.call(this, 'Runtime');
97
97
  _this._flatInstances = [];
98
98
  _this._instanceMap = {};
99
+ _this._controlParentIdMap = {};
99
100
  var schema = props.schema;
100
101
  _this._schema = schema;
101
102
  _this._instance = _this.createControl(schema, props.beforeCreateInstance);
@@ -108,19 +109,26 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls1) {
108
109
  value: function getFlatInstances() {
109
110
  var instances = [];
110
111
  var instanceMap = {};
111
- loop(this._instance, function(item) {
112
+ var controlParentIdMap = {};
113
+ loop(this._instance, '', function(item, parentId) {
112
114
  // 3.4.1 避免将subtable-row 放到 _flatInstances 中
113
- if (item.type === 'subtable-row' || item.type === 'subtable-column') {
114
- return;
115
- }
115
+ //4.3.0-lh2 将自处注释掉,为使instance.parent能取到父级
116
+ // if (item.type === 'subtable-row' || item.type === 'subtable-column') {
117
+ // return
118
+ // }
116
119
  instances.push(item);
117
120
  if (!instanceMap[item.id]) {
118
121
  instanceMap[item.id] = [];
119
122
  }
120
123
  instanceMap[item.id].push(item);
124
+ if (parentId) {
125
+ // @ts-ignore
126
+ controlParentIdMap[item.id] = parentId;
127
+ }
121
128
  });
122
129
  this._flatInstances = instances;
123
130
  this._instanceMap = instanceMap;
131
+ this._controlParentIdMap = controlParentIdMap;
124
132
  return this._flatInstances;
125
133
  }
126
134
  },
@@ -154,8 +162,9 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls1) {
154
162
  var antdRules = {};
155
163
  var ruleItems = {};
156
164
  loopDataViewControl(this._instance, function(dataView) {
157
- ruleItems[dataView.id] = dataView.rules[0];
158
- antdRules[dataView.id] = dataView.rules[0];
165
+ var result = Runtime.staticGetRules(dataView.type, dataView.props);
166
+ ruleItems[dataView.id] = JSONCopy(result[0]);
167
+ antdRules[dataView.id] = JSONCopy(result[0]);
159
168
  loopFormControl(dataView.children, function(item) {
160
169
  // if (
161
170
  // item instanceof RuntimeFormControl ||
@@ -178,7 +187,9 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls1) {
178
187
  get: function get() {
179
188
  var ruleItems = {};
180
189
  loopDataViewControl(this._instance, function(dataView) {
181
- ruleItems[dataView.id] = dataView.rules[0];
190
+ var result = Runtime.staticGetRules(dataView.type, dataView.props);
191
+ // ruleItems[dataView.id] = dataView.rules[0]
192
+ ruleItems[dataView.id] = result[0];
182
193
  loopFormControl(dataView.children, function(item) {
183
194
  // if (
184
195
  // item instanceof RuntimeFormControl ||
@@ -197,7 +208,9 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls1) {
197
208
  get: function get() {
198
209
  var antdRules = {};
199
210
  loopDataViewControl(this._instance, function(dataView) {
200
- antdRules[dataView.id] = dataView.rules[0];
211
+ var result = Runtime.staticGetRules(dataView.type, dataView.props);
212
+ // antdRules[dataView.id] = dataView.rules[0]
213
+ antdRules[dataView.id] = result[0];
201
214
  loopFormControl(dataView.children, function(item) {
202
215
  // if (
203
216
  // item instanceof RuntimeFormControl ||
@@ -214,22 +227,30 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls1) {
214
227
  ]);
215
228
  return Runtime;
216
229
  }(RegisterControls);
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);
230
+ function loop(control, parentId, callback) {
231
+ var _instances = Array.isArray(control) ? control : [
232
+ control
233
+ ];
234
+ _instances.map(function(item) {
235
+ callback(item, parentId);
236
+ if (hasChildrenControl(item)) {
237
+ var ctl = item;
238
+ if (!ctl.children) {
239
+ ctl.children = [];
228
240
  }
229
- });
230
- } else {
231
- callback(control);
232
- }
241
+ // @ts-ignore
242
+ loop(ctl.children, ctl.id, callback);
243
+ }
244
+ if (hasHeaderOrFooterControl(item, 'headers')) {
245
+ loop(item.props.headers, item.id, callback);
246
+ }
247
+ if (hasHeaderOrFooterControl(item, 'footers')) {
248
+ loop(item.props.footers, item.id, callback);
249
+ }
250
+ });
251
+ }
252
+ function hasHeaderOrFooterControl(control, checkType) {
253
+ return checkType in control.props && isArray(control.props[checkType]);
233
254
  }
234
255
  /**
235
256
  * 控件是否在视图中隐藏,遍历查找所有parent
@@ -237,7 +258,7 @@ function loop(control, callback) {
237
258
  if (control.props.isHide) {
238
259
  return true;
239
260
  }
240
- if (control.parent === null) {
261
+ if (control.parent === null || control.parent === undefined) {
241
262
  return false;
242
263
  }
243
264
  return getControlIsHide(control.parent);
@@ -247,11 +268,14 @@ item) {
247
268
  if (getControlIsHide(item)) {
248
269
  return;
249
270
  }
271
+ var result = Runtime.staticGetRules(item.type, item.props);
250
272
  // if (item instanceof RuntimeFormControl) {
251
273
  if (item.controlType === CONTROL_BASE_TYPE.FORM) {
252
- data[item.id] = item.rules;
274
+ // data[item.id] = item.rules
275
+ data[item.id] = result;
253
276
  } else if (item.type === CONTROL_TYPE.SUBTABLE) {
254
- data[item.id] = item.rules;
277
+ // data[item.id] = item.rules
278
+ data[item.id] = result;
255
279
  var itemRules = {
256
280
  type: 'array',
257
281
  fields: {}
@@ -266,8 +290,13 @@ item) {
266
290
  fields: {}
267
291
  };
268
292
  }
293
+ // // @ts-ignore
294
+ // itemRules.fields[index].fields[formControl.id] = (
295
+ // formControl as RuntimeFormControl
296
+ // ).rules
297
+ var childResult = Runtime.staticGetRules(formControl.type, formControl.props);
269
298
  // @ts-ignore
270
- itemRules.fields[index].fields[formControl.id] = formControl.rules;
299
+ itemRules.fields[index].fields[formControl.id] = childResult;
271
300
  }
272
301
  });
273
302
  });
@@ -279,15 +308,19 @@ item) {
279
308
  if (getControlIsHide(item)) {
280
309
  return;
281
310
  }
311
+ var result = Runtime.staticGetRules(item.type, item.props);
282
312
  // if (item instanceof RuntimeFormControl) {
283
313
  if (item.controlType === CONTROL_BASE_TYPE.FORM) {
284
- antdRules[item.id] = item.rules;
314
+ // antdRules[item.id] = item.rules
315
+ antdRules[item.id] = result;
285
316
  } else if (item.type === CONTROL_TYPE.SUBTABLE && item.children.length) {
286
317
  antdRules[item.id] = [];
287
318
  item.children.forEach(function(row) {
288
319
  var rules = {};
289
320
  loopFormSchema(row.children, function(formControl) {
290
- rules[formControl.id] = formControl.rules;
321
+ // rules[formControl.id] = (formControl as RuntimeFormControl).rules
322
+ var childResult = Runtime.staticGetRules(formControl.type, formControl.props);
323
+ rules[formControl.id] = childResult;
291
324
  });
292
325
  antdRules[item.id].push(rules);
293
326
  });