@byteluck-fe/model-driven-core 2.7.0-alpha.2 → 2.7.0-alpha.4

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.
@@ -219,12 +219,22 @@ var Control = /*#__PURE__*/ function _target() {
219
219
  function Control(props) {
220
220
  var _this = this;
221
221
  _classCallCheck(this, Control);
222
- this.setting = [];
223
- this.eventKeys = [];
224
- this.customEvents = [];
225
- this.parent = null;
226
- this.updateSetting = updateSetting;
227
- this.removeSetting = removeSetting;
222
+ _defineProperty(this, "id", void 0 // 唯一标识符
223
+ );
224
+ _defineProperty(this, "name", void 0);
225
+ _defineProperty(this, "icon", void 0);
226
+ _defineProperty(this, "type", void 0);
227
+ _defineProperty(this, "controlType", void 0);
228
+ _defineProperty(this, "props", void 0);
229
+ _defineProperty(this, "setting", []);
230
+ _defineProperty(this, "fieldType", void 0);
231
+ _defineProperty(this, "eventKeys", []);
232
+ _defineProperty(this, "customEvents", []);
233
+ _defineProperty(this, "parent", null);
234
+ _defineProperty(this, "updateSetting", updateSetting);
235
+ _defineProperty(this, "removeSetting", removeSetting);
236
+ _defineProperty(this, "addSetting", addSetting);
237
+ _defineProperty(this, "replaceSetting", replaceSetting);
228
238
  this._callControlHooks("preInstance", props);
229
239
  var _ref = _instanceof(this, Control) ? this.constructor : void 0, controlName = _ref.controlName, controlIcon = _ref.controlIcon, controlType = _ref.controlType, controlFieldType = _ref.controlFieldType, controlEventKeys = _ref.controlEventKeys, controlCustomEvents = _ref.controlCustomEvents, name = _ref.name, setting = _ref.setting;
230
240
  if (!(controlName && controlIcon && controlType)) {
@@ -248,180 +258,6 @@ var Control = /*#__PURE__*/ function _target() {
248
258
  _this._callControlHooks("postInstance", props);
249
259
  });
250
260
  }
251
- var _proto = Control.prototype;
252
- _proto._callControlHooks = function _callControlHooks() {
253
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
254
- args[_key] = arguments[_key];
255
- }
256
- var _controlHooksEmitter;
257
- var _args = _toArray(args), key = _args[0], arg = _args.slice(1);
258
- return (_controlHooksEmitter = controlHooksEmitter).emit.apply(_controlHooksEmitter, [
259
- key,
260
- this
261
- ].concat(_toConsumableArray(arg)));
262
- };
263
- _proto.preUpdate = function preUpdate(key, value) {
264
- // 在修改props之前
265
- this._callControlHooks("preUpdateProps", key, value);
266
- };
267
- _proto.postUpdate = function postUpdate(key, value) {
268
- // 在修改props之后
269
- this._callControlHooks("postUpdateProps", key, value);
270
- };
271
- // 修改实例上的props,key可以是caption,caption.zh...
272
- _proto.updateProps = function updateProps(key, value) {
273
- this.preUpdate(key, value);
274
- updateValueFromKeys(this.props, key, value);
275
- this.postUpdate(key, value);
276
- };
277
- _proto.preValidate = function preValidate() {
278
- var _this = this;
279
- return _asyncToGenerator(function() {
280
- var rules, results, result;
281
- return __generator(this, function(_state) {
282
- switch(_state.label){
283
- case 0:
284
- rules = _objectSpread({}, _this.rules);
285
- return [
286
- 4,
287
- _this._callControlHooks("preValidate", rules)
288
- ];
289
- case 1:
290
- results = _state.sent();
291
- result = results[results.length - 1];
292
- return [
293
- 2,
294
- result === false ? undefined : result
295
- ];
296
- }
297
- });
298
- })();
299
- };
300
- // property校验
301
- _proto.validate = function validate(messages, ignore) {
302
- var _this = this;
303
- return _asyncToGenerator(function() {
304
- var result, rules, validator, err;
305
- return __generator(this, function(_state) {
306
- switch(_state.label){
307
- case 0:
308
- return [
309
- 4,
310
- _this.preValidate()
311
- ];
312
- case 1:
313
- result = _state.sent();
314
- rules = result !== undefined ? result : _objectSpread({}, _this.rules);
315
- if (Array.isArray(ignore)) {
316
- ignore.forEach(function(key) {
317
- if (rules.hasOwnProperty(key)) {
318
- delete rules[key];
319
- }
320
- });
321
- }
322
- validator = createValidator(rules, messages);
323
- _state.label = 2;
324
- case 2:
325
- _state.trys.push([
326
- 2,
327
- 4,
328
- ,
329
- 5
330
- ]);
331
- return [
332
- 4,
333
- validator.validate(_this.props)
334
- ];
335
- case 3:
336
- _state.sent();
337
- return [
338
- 2,
339
- true
340
- ];
341
- case 4:
342
- err = _state.sent();
343
- if (!err.control) {
344
- err.control = _this;
345
- }
346
- throw err;
347
- case 5:
348
- return [
349
- 2
350
- ];
351
- }
352
- });
353
- })();
354
- };
355
- _proto.toDataBindModel = function toDataBindModel() {
356
- var parentId = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : null;
357
- var fieldType = this.fieldType;
358
- var controlId = this.id;
359
- var type = this.type;
360
- var _this_props = this.props, dataBind = _this_props.dataBind, datasourceBind = _this_props.datasourceBind, optionConfig = _this_props.optionConfig, caption = _this_props.caption, required = _this_props.required, maxLength = _this_props.maxLength, options = _this_props.options, encrypted = _this_props.encrypted, encryptedMode = _this_props.encryptedMode;
361
- if (!fieldType && !dataBind && !datasourceBind) return;
362
- var dataBindModelType = {
363
- parentId: parentId,
364
- fieldType: fieldType,
365
- controlId: controlId,
366
- caption: caption,
367
- type: type,
368
- props: {}
369
- };
370
- if (dataBind) {
371
- dataBindModelType.dataBind = dataBind;
372
- }
373
- switch(optionConfig){
374
- case "datasource":
375
- case undefined:
376
- if (datasourceBind) {
377
- dataBindModelType.datasourceBind = datasourceBind;
378
- }
379
- break;
380
- case "custom":
381
- dataBindModelType.props.options = options;
382
- break;
383
- }
384
- if (required !== undefined) {
385
- dataBindModelType.required = required;
386
- }
387
- if (maxLength !== undefined) {
388
- dataBindModelType.maxLength = maxLength;
389
- }
390
- if (encrypted !== undefined) {
391
- dataBindModelType.encrypted = encrypted;
392
- }
393
- if (encryptedMode !== undefined) {
394
- dataBindModelType.encryptedMode = encryptedMode;
395
- }
396
- return dataBindModelType;
397
- };
398
- _proto.preToSchema = function preToSchema() {
399
- // 在处理Schema之前,预留的钩子函数,允许在toSchema之前处理一些数据
400
- this._callControlHooks("preToSchema", this);
401
- };
402
- _proto.toSchema = function toSchema() {
403
- this.preToSchema();
404
- return {
405
- id: this.id,
406
- type: this.type,
407
- props: JSONCopy(this.props),
408
- fieldType: this.fieldType,
409
- controlType: this.controlType
410
- };
411
- };
412
- Control.updateBasicControl = function updateBasicControl(key, setting) {
413
- if (key !== "setting") return;
414
- if (setting.add) {
415
- var _this_setting;
416
- (_this_setting = this.setting).push.apply(_this_setting, _toConsumableArray(setting.add));
417
- }
418
- if (setting.remove) {
419
- this.removeSettingItem(setting.remove);
420
- }
421
- if (setting.update) {
422
- // this.updateSettingItem(setting.update, false)
423
- }
424
- };
425
261
  _createClass(Control, [
426
262
  {
427
263
  key: "rules",
@@ -432,23 +268,228 @@ var Control = /*#__PURE__*/ function _target() {
432
268
  }
433
269
  return {};
434
270
  }
271
+ },
272
+ {
273
+ key: "_callControlHooks",
274
+ value: function _callControlHooks() {
275
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
276
+ args[_key] = arguments[_key];
277
+ }
278
+ var _controlHooksEmitter;
279
+ var _args = _toArray(args), key = _args[0], arg = _args.slice(1);
280
+ return (_controlHooksEmitter = controlHooksEmitter).emit.apply(_controlHooksEmitter, [
281
+ key,
282
+ this
283
+ ].concat(_toConsumableArray(arg)));
284
+ }
285
+ },
286
+ {
287
+ key: "preUpdate",
288
+ value: function preUpdate(key, value) {
289
+ // 在修改props之前
290
+ this._callControlHooks("preUpdateProps", key, value);
291
+ }
292
+ },
293
+ {
294
+ key: "postUpdate",
295
+ value: function postUpdate(key, value) {
296
+ // 在修改props之后
297
+ this._callControlHooks("postUpdateProps", key, value);
298
+ }
299
+ },
300
+ {
301
+ key: "updateProps",
302
+ value: // 修改实例上的props,key可以是caption,caption.zh...
303
+ function updateProps(key, value) {
304
+ this.preUpdate(key, value);
305
+ updateValueFromKeys(this.props, key, value);
306
+ this.postUpdate(key, value);
307
+ }
308
+ },
309
+ {
310
+ key: "preValidate",
311
+ value: function preValidate() {
312
+ var _this = this;
313
+ return _asyncToGenerator(function() {
314
+ var rules, results, result;
315
+ return __generator(this, function(_state) {
316
+ switch(_state.label){
317
+ case 0:
318
+ rules = _objectSpread({}, _this.rules);
319
+ return [
320
+ 4,
321
+ _this._callControlHooks("preValidate", rules)
322
+ ];
323
+ case 1:
324
+ results = _state.sent();
325
+ result = results[results.length - 1];
326
+ return [
327
+ 2,
328
+ result === false ? undefined : result
329
+ ];
330
+ }
331
+ });
332
+ })();
333
+ }
334
+ },
335
+ {
336
+ key: "validate",
337
+ value: // property校验
338
+ function validate(messages, ignore) {
339
+ var _this = this;
340
+ return _asyncToGenerator(function() {
341
+ var result, rules, validator, err;
342
+ return __generator(this, function(_state) {
343
+ switch(_state.label){
344
+ case 0:
345
+ return [
346
+ 4,
347
+ _this.preValidate()
348
+ ];
349
+ case 1:
350
+ result = _state.sent();
351
+ rules = result !== undefined ? result : _objectSpread({}, _this.rules);
352
+ if (Array.isArray(ignore)) {
353
+ ignore.forEach(function(key) {
354
+ if (rules.hasOwnProperty(key)) {
355
+ delete rules[key];
356
+ }
357
+ });
358
+ }
359
+ validator = createValidator(rules, messages);
360
+ _state.label = 2;
361
+ case 2:
362
+ _state.trys.push([
363
+ 2,
364
+ 4,
365
+ ,
366
+ 5
367
+ ]);
368
+ return [
369
+ 4,
370
+ validator.validate(_this.props)
371
+ ];
372
+ case 3:
373
+ _state.sent();
374
+ return [
375
+ 2,
376
+ true
377
+ ];
378
+ case 4:
379
+ err = _state.sent();
380
+ if (!err.control) {
381
+ err.control = _this;
382
+ }
383
+ throw err;
384
+ case 5:
385
+ return [
386
+ 2
387
+ ];
388
+ }
389
+ });
390
+ })();
391
+ }
392
+ },
393
+ {
394
+ key: "toDataBindModel",
395
+ value: function toDataBindModel() {
396
+ var parentId = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : null;
397
+ var fieldType = this.fieldType;
398
+ var controlId = this.id;
399
+ var type = this.type;
400
+ var _this_props = this.props, dataBind = _this_props.dataBind, datasourceBind = _this_props.datasourceBind, optionConfig = _this_props.optionConfig, caption = _this_props.caption, required = _this_props.required, maxLength = _this_props.maxLength, options = _this_props.options, encrypted = _this_props.encrypted, encryptedMode = _this_props.encryptedMode;
401
+ if (!fieldType && !dataBind && !datasourceBind) return;
402
+ var dataBindModelType = {
403
+ parentId: parentId,
404
+ fieldType: fieldType,
405
+ controlId: controlId,
406
+ caption: caption,
407
+ type: type,
408
+ props: {}
409
+ };
410
+ if (dataBind) {
411
+ dataBindModelType.dataBind = dataBind;
412
+ }
413
+ switch(optionConfig){
414
+ case "datasource":
415
+ case undefined:
416
+ if (datasourceBind) {
417
+ dataBindModelType.datasourceBind = datasourceBind;
418
+ }
419
+ break;
420
+ case "custom":
421
+ dataBindModelType.props.options = options;
422
+ break;
423
+ }
424
+ if (required !== undefined) {
425
+ dataBindModelType.required = required;
426
+ }
427
+ if (maxLength !== undefined) {
428
+ dataBindModelType.maxLength = maxLength;
429
+ }
430
+ if (encrypted !== undefined) {
431
+ dataBindModelType.encrypted = encrypted;
432
+ }
433
+ if (encryptedMode !== undefined) {
434
+ dataBindModelType.encryptedMode = encryptedMode;
435
+ }
436
+ return dataBindModelType;
437
+ }
438
+ },
439
+ {
440
+ key: "preToSchema",
441
+ value: function preToSchema() {
442
+ // 在处理Schema之前,预留的钩子函数,允许在toSchema之前处理一些数据
443
+ this._callControlHooks("preToSchema", this);
444
+ }
445
+ },
446
+ {
447
+ key: "toSchema",
448
+ value: function toSchema() {
449
+ this.preToSchema();
450
+ return {
451
+ id: this.id,
452
+ type: this.type,
453
+ props: JSONCopy(this.props),
454
+ fieldType: this.fieldType,
455
+ controlType: this.controlType
456
+ };
457
+ }
458
+ }
459
+ ], [
460
+ {
461
+ key: "updateBasicControl",
462
+ value: function updateBasicControl(key, setting) {
463
+ if (key !== "setting") return;
464
+ if (setting.add) {
465
+ var _this_setting;
466
+ (_this_setting = this.setting).push.apply(_this_setting, _toConsumableArray(setting.add));
467
+ }
468
+ if (setting.remove) {
469
+ this.removeSettingItem(setting.remove);
470
+ }
471
+ if (setting.update) {
472
+ // this.updateSettingItem(setting.update, false)
473
+ }
474
+ }
435
475
  }
436
476
  ]);
437
477
  return Control;
438
478
  }();
439
- Control.controlName = "控件";
440
- Control.controlIcon = "icon";
441
- Control.controlType = "control";
479
+ _defineProperty(Control, "controlName", "控件");
480
+ _defineProperty(Control, "controlIcon", "icon");
481
+ _defineProperty(Control, "controlType", "control");
482
+ _defineProperty(Control, "controlFieldType", void 0);
442
483
  // 控件可以触发的事件key
443
- Control.controlEventKeys = [];
444
- Control.controlCustomEvents = [];
484
+ _defineProperty(Control, "controlEventKeys", []);
485
+ _defineProperty(Control, "controlCustomEvents", []);
445
486
  // setting应该是全量的设置项,外部控制,在初始化的时候会deepCopy一份
446
- Control.setting = [];
447
- Control.__is_control__ = true;
487
+ _defineProperty(Control, "setting", []);
488
+ _defineProperty(Control, "__is_control__", true);
448
489
  // 删除指定的settingItem
449
- Control.removeSettingItem = removeSetting;
490
+ _defineProperty(Control, "removeSettingItem", removeSetting);
450
491
  // 修改指定的settingItem的visible
451
- Control.updateSettingItem = updateSetting;
492
+ _defineProperty(Control, "updateSettingItem", updateSetting);
452
493
  export default Control;
453
494
  export { Control as DesignerControl };
454
495
  /**
@@ -464,6 +505,7 @@ export { Control as DesignerControl };
464
505
  var _this_setting;
465
506
  // 是否存在子项
466
507
  var isHasItem = typeof deleteKey !== "string";
508
+ // 判断setting是否是自定义控件setting项
467
509
  // @ts-ignore
468
510
  if (!Array.isArray(_this.setting)) return;
469
511
  // @ts-ignore
@@ -496,6 +538,8 @@ export { Control as DesignerControl };
496
538
  settingKey
497
539
  ] : settingKey;
498
540
  keys.forEach(function(key) {
541
+ // @ts-ignore
542
+ if (!Array.isArray(_this.setting)) return;
499
543
  // @ts-ignore
500
544
  var settingItem = _this.setting.find(function(item) {
501
545
  return item.key === key;
@@ -516,3 +560,23 @@ export { Control as DesignerControl };
516
560
  }
517
561
  });
518
562
  }
563
+ /**
564
+ * @function 新增控件或者实例上的setting的方法
565
+ * @description 其中的this可能是DesignerControl的类,也可以是实例
566
+ * @param setting 需要新增的setting或者setting项组成的数组
567
+ * */ function addSetting(setting) {
568
+ var // @ts-ignore
569
+ _this_setting;
570
+ var settings = Object.prototype.toString.call(setting) === "[object Object]" ? [
571
+ setting
572
+ ] : setting;
573
+ (_this_setting = this.setting).push.apply(_this_setting, _toConsumableArray(settings));
574
+ }
575
+ /**
576
+ * @function 新增控件或者实例上的setting的方法
577
+ * @description 其中的this可能是DesignerControl的类,也可以是实例
578
+ * @param setting 需要新增的setting或者setting项组成的数组
579
+ * */ function replaceSetting(setting) {
580
+ // @ts-ignore
581
+ this.setting = setting;
582
+ }
@@ -37,6 +37,19 @@ function _construct(Parent, args, Class) {
37
37
  }
38
38
  return _construct.apply(null, arguments);
39
39
  }
40
+ function _defineProperty(obj, key, value) {
41
+ if (key in obj) {
42
+ Object.defineProperty(obj, key, {
43
+ value: value,
44
+ enumerable: true,
45
+ configurable: true,
46
+ writable: true
47
+ });
48
+ } else {
49
+ obj[key] = value;
50
+ }
51
+ return obj;
52
+ }
40
53
  function _getPrototypeOf(o) {
41
54
  _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
42
55
  return o.__proto__ || Object.getPrototypeOf(o);
@@ -130,9 +143,9 @@ import { BaseStyle } from "../../framework";
130
143
  var PropertyRules = function PropertyRules(props) {
131
144
  "use strict";
132
145
  _classCallCheck(this, PropertyRules);
133
- this.isHide = {
146
+ _defineProperty(this, "isHide", {
134
147
  type: "boolean"
135
- };
148
+ });
136
149
  };
137
150
  var PropertyRuntimeRules = /*#__PURE__*/ function(Array1) {
138
151
  "use strict";
@@ -151,13 +164,25 @@ var PropertyRuntimeRules = /*#__PURE__*/ function(Array1) {
151
164
  "use strict";
152
165
  var caption = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
153
166
  _classCallCheck(this, Property);
167
+ /**
168
+ * 是否隐藏
169
+ * @public
170
+ * @defaultValue false
171
+ */ _defineProperty(this, "isHide", void 0);
172
+ _defineProperty(this, "className", void 0);
173
+ _defineProperty(this, "style", void 0);
174
+ /**
175
+ * 标题
176
+ * @public
177
+ * @defaultValue ''
178
+ */ _defineProperty(this, "caption", void 0);
154
179
  var _props_isHide;
155
180
  this.isHide = (_props_isHide = props === null || props === void 0 ? void 0 : props.isHide) !== null && _props_isHide !== void 0 ? _props_isHide : false;
156
181
  this.style = new BaseStyle(props === null || props === void 0 ? void 0 : props.style);
157
182
  var _props_caption;
158
183
  this.caption = (_props_caption = props === null || props === void 0 ? void 0 : props.caption) !== null && _props_caption !== void 0 ? _props_caption : caption;
159
184
  };
160
- Property.Rules = PropertyRules;
161
- Property.RuntimeRules = PropertyRuntimeRules;
185
+ _defineProperty(Property, "Rules", PropertyRules);
186
+ _defineProperty(Property, "RuntimeRules", PropertyRuntimeRules);
162
187
  export default Property;
163
188
  export { Property, PropertyRules, PropertyRuntimeRules };
@@ -17,6 +17,19 @@ function _createClass(Constructor, protoProps, staticProps) {
17
17
  if (staticProps) _defineProperties(Constructor, staticProps);
18
18
  return Constructor;
19
19
  }
20
+ function _defineProperty(obj, key, value) {
21
+ if (key in obj) {
22
+ Object.defineProperty(obj, key, {
23
+ value: value,
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true
27
+ });
28
+ } else {
29
+ obj[key] = value;
30
+ }
31
+ return obj;
32
+ }
20
33
  function _instanceof(left, right) {
21
34
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
22
35
  return !!right[Symbol.hasInstance](left);
@@ -31,8 +44,15 @@ var Control = /*#__PURE__*/ function _target() {
31
44
  "use strict";
32
45
  function Control(props) {
33
46
  _classCallCheck(this, Control);
34
- this.customEvents = [];
35
- this.parent = null;
47
+ _defineProperty(this, "id", void 0 // 唯一标识符
48
+ );
49
+ _defineProperty(this, "type", void 0);
50
+ _defineProperty(this, "controlType", void 0);
51
+ _defineProperty(this, "props", void 0);
52
+ _defineProperty(this, "fieldType", void 0);
53
+ _defineProperty(this, "customEvents", []);
54
+ _defineProperty(this, "pageStatus", void 0);
55
+ _defineProperty(this, "parent", null);
36
56
  var _ref = _instanceof(this, Control) ? this.constructor : void 0, controlType = _ref.controlType, controlFieldType = _ref.controlFieldType, name = _ref.name, controlCustomEvents = _ref.controlCustomEvents;
37
57
  if (!controlType) {
38
58
  referenceError("The ".concat(name, " controlType is not define"));
@@ -65,8 +85,9 @@ var Control = /*#__PURE__*/ function _target() {
65
85
  ]);
66
86
  return Control;
67
87
  }();
68
- Control.controlType = "control";
69
- Control.__is_control__ = true;
70
- Control.controlCustomEvents = [];
88
+ _defineProperty(Control, "controlType", "control");
89
+ _defineProperty(Control, "controlFieldType", void 0);
90
+ _defineProperty(Control, "__is_control__", true);
91
+ _defineProperty(Control, "controlCustomEvents", []);
71
92
  export default Control;
72
93
  export { Control as RuntimeControl };
@@ -9,6 +9,19 @@ function _classCallCheck(instance, Constructor) {
9
9
  throw new TypeError("Cannot call a class as a function");
10
10
  }
11
11
  }
12
+ function _defineProperty(obj, key, value) {
13
+ if (key in obj) {
14
+ Object.defineProperty(obj, key, {
15
+ value: value,
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true
19
+ });
20
+ } else {
21
+ obj[key] = value;
22
+ }
23
+ return obj;
24
+ }
12
25
  function _getPrototypeOf(o) {
13
26
  _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
14
27
  return o.__proto__ || Object.getPrototypeOf(o);
@@ -79,7 +92,8 @@ var ColumnControl = /*#__PURE__*/ function(DesignerControl) {
79
92
  _classCallCheck(this, ColumnControl);
80
93
  var _this;
81
94
  _this = _super.call(this, props);
82
- _this.controlType = "column";
95
+ _defineProperty(_assertThisInitialized(_this), "controlType", "column");
96
+ _defineProperty(_assertThisInitialized(_this), "props", void 0);
83
97
  _this.props = new ColumnControlProperty(props === null || props === void 0 ? void 0 : props.props);
84
98
  return _this;
85
99
  }