@byteluck-fe/model-driven-driven 1.3.0-beta.25 → 1.5.0-beta.2

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.
@@ -0,0 +1,631 @@
1
+ function _arrayLikeToArray(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _arrayWithHoles(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _arrayWithoutHoles(arr) {
10
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
11
+ }
12
+ function _assertThisInitialized(self) {
13
+ if (self === void 0) {
14
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
15
+ }
16
+ return self;
17
+ }
18
+ function _classCallCheck(instance, Constructor) {
19
+ if (!(instance instanceof Constructor)) {
20
+ throw new TypeError("Cannot call a class as a function");
21
+ }
22
+ }
23
+ function _defineProperty(obj, key, value) {
24
+ if (key in obj) {
25
+ Object.defineProperty(obj, key, {
26
+ value: value,
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true
30
+ });
31
+ } else {
32
+ obj[key] = value;
33
+ }
34
+ return obj;
35
+ }
36
+ function _get(target, property, receiver) {
37
+ if (typeof Reflect !== "undefined" && Reflect.get) {
38
+ _get = Reflect.get;
39
+ } else {
40
+ _get = function _get(target, property, receiver) {
41
+ var base = _superPropBase(target, property);
42
+ if (!base) return;
43
+ var desc = Object.getOwnPropertyDescriptor(base, property);
44
+ if (desc.get) {
45
+ return desc.get.call(receiver);
46
+ }
47
+ return desc.value;
48
+ };
49
+ }
50
+ return _get(target, property, receiver || target);
51
+ }
52
+ function _getPrototypeOf(o) {
53
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
54
+ return o.__proto__ || Object.getPrototypeOf(o);
55
+ };
56
+ return _getPrototypeOf(o);
57
+ }
58
+ function _inherits(subClass, superClass) {
59
+ if (typeof superClass !== "function" && superClass !== null) {
60
+ throw new TypeError("Super expression must either be null or a function");
61
+ }
62
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
63
+ constructor: {
64
+ value: subClass,
65
+ writable: true,
66
+ configurable: true
67
+ }
68
+ });
69
+ if (superClass) _setPrototypeOf(subClass, superClass);
70
+ }
71
+ function _instanceof(left, right) {
72
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
73
+ return !!right[Symbol.hasInstance](left);
74
+ } else {
75
+ return left instanceof right;
76
+ }
77
+ }
78
+ function _iterableToArray(iter) {
79
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
80
+ }
81
+ function _iterableToArrayLimit(arr, i) {
82
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
83
+ if (_i == null) return;
84
+ var _arr = [];
85
+ var _n = true;
86
+ var _d = false;
87
+ var _s, _e;
88
+ try {
89
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
90
+ _arr.push(_s.value);
91
+ if (i && _arr.length === i) break;
92
+ }
93
+ } catch (err) {
94
+ _d = true;
95
+ _e = err;
96
+ } finally{
97
+ try {
98
+ if (!_n && _i["return"] != null) _i["return"]();
99
+ } finally{
100
+ if (_d) throw _e;
101
+ }
102
+ }
103
+ return _arr;
104
+ }
105
+ function _nonIterableRest() {
106
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
107
+ }
108
+ function _nonIterableSpread() {
109
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
110
+ }
111
+ function _objectSpread(target) {
112
+ for(var i = 1; i < arguments.length; i++){
113
+ var source = arguments[i] != null ? arguments[i] : {};
114
+ var ownKeys = Object.keys(source);
115
+ if (typeof Object.getOwnPropertySymbols === "function") {
116
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
117
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
118
+ }));
119
+ }
120
+ ownKeys.forEach(function(key) {
121
+ _defineProperty(target, key, source[key]);
122
+ });
123
+ }
124
+ return target;
125
+ }
126
+ function _possibleConstructorReturn(self, call) {
127
+ if (call && (_typeof(call) === "object" || typeof call === "function")) {
128
+ return call;
129
+ }
130
+ return _assertThisInitialized(self);
131
+ }
132
+ function _setPrototypeOf(o, p) {
133
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
134
+ o.__proto__ = p;
135
+ return o;
136
+ };
137
+ return _setPrototypeOf(o, p);
138
+ }
139
+ function _slicedToArray(arr, i) {
140
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
141
+ }
142
+ function _superPropBase(object, property) {
143
+ while(!Object.prototype.hasOwnProperty.call(object, property)){
144
+ object = _getPrototypeOf(object);
145
+ if (object === null) break;
146
+ }
147
+ return object;
148
+ }
149
+ function _toConsumableArray(arr) {
150
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
151
+ }
152
+ var _typeof = function(obj) {
153
+ "@swc/helpers - typeof";
154
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
155
+ };
156
+ function _unsupportedIterableToArray(o, minLen) {
157
+ if (!o) return;
158
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
159
+ var n = Object.prototype.toString.call(o).slice(8, -1);
160
+ if (n === "Object" && o.constructor) n = o.constructor.name;
161
+ if (n === "Map" || n === "Set") return Array.from(n);
162
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
163
+ }
164
+ function _isNativeReflectConstruct() {
165
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
166
+ if (Reflect.construct.sham) return false;
167
+ if (typeof Proxy === "function") return true;
168
+ try {
169
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
170
+ return true;
171
+ } catch (e) {
172
+ return false;
173
+ }
174
+ }
175
+ function _createSuper(Derived) {
176
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
177
+ return function _createSuperInternal() {
178
+ var Super = _getPrototypeOf(Derived), result;
179
+ if (hasNativeReflectConstruct) {
180
+ var NewTarget = _getPrototypeOf(this).constructor;
181
+ result = Reflect.construct(Super, arguments, NewTarget);
182
+ } else {
183
+ result = Super.apply(this, arguments);
184
+ }
185
+ return _possibleConstructorReturn(this, result);
186
+ };
187
+ }
188
+ import { error, genNonDuplicateId, isArray, isBuiltInControls, isObject, isString, updateValueFromKeys, warn, Watcher } from "@byteluck-fe/model-driven-shared";
189
+ import { findInstanceDataScopeParent, Store } from "./Store";
190
+ import { Designer } from "./Designer";
191
+ import EventLogic from "./EventLogic";
192
+ import { DesignerControl, DesignerListControl, DesignerWrapControl } from "@byteluck-fe/model-driven-core";
193
+ import { checkSchema, generatePermissions, getModelBindInfoList, toSchema } from "./utils";
194
+ import { Group, initSettings, Tab } from "@byteluck-fe/model-driven-settings";
195
+ // 当前正在注册的插件名称
196
+ var applyingPluginName = "";
197
+ /**
198
+ * 设计器驱动
199
+ * */ var Driven = /*#__PURE__*/ function(Watcher) {
200
+ "use strict";
201
+ _inherits(Driven, Watcher);
202
+ var _super = _createSuper(Driven);
203
+ function Driven(options) {
204
+ _classCallCheck(this, Driven);
205
+ var _this;
206
+ _this = _super.call(this);
207
+ _this.isMounted = false;
208
+ _this.id = genNonDuplicateId(8);
209
+ _this.__pluginsApplied = false;
210
+ // TODO 拿到schema
211
+ _this.getSchema = toSchema;
212
+ // TODO 拿到model_bind_info_list
213
+ _this.getModelBindInfoList = getModelBindInfoList;
214
+ // TODO 拿到permission_controls
215
+ _this.generatePermissions = generatePermissions;
216
+ _this.$options = Object.freeze(options);
217
+ var _$options = _this.$options, _autoMount = _$options.autoMount, autoMount = _autoMount === void 0 ? false : _autoMount, tmp = _$options.Designer, DesignerClass = tmp === void 0 ? Designer : tmp, schema = _$options.schema, _mode = _$options.mode, mode = _mode === void 0 ? "form" : _mode, tmp1 = _$options.store, storeOptions = tmp1 === void 0 ? {} : tmp1;
218
+ _this.eventLogic = new EventLogic();
219
+ _this.designer = new DesignerClass();
220
+ _this.store = new Store(_objectSpread({
221
+ instance: _this.designer.createControl(Array.isArray(schema) ? schema : [
222
+ schema
223
+ ])
224
+ }, storeOptions));
225
+ _this.mode = mode;
226
+ autoMount && _this.mount();
227
+ return _this;
228
+ }
229
+ var _proto = Driven.prototype;
230
+ // 挂载
231
+ _proto.mount = function mount() {
232
+ var _$options = this.$options, _plugins = _$options.plugins, plugins = _plugins === void 0 ? [] : _plugins;
233
+ this.__plugins = plugins;
234
+ this.applyPlugins();
235
+ this.isMounted = true;
236
+ };
237
+ _proto.use = function use(plugin) {
238
+ if (!this.__pluginsApplied) {
239
+ this.__plugins.push(plugin);
240
+ }
241
+ return this;
242
+ };
243
+ _proto.applyPlugins = function applyPlugins() {
244
+ var _this = this;
245
+ if (this.__pluginsApplied) return;
246
+ this.__plugins.forEach(function(plugin) {
247
+ try {
248
+ var _pluginName;
249
+ applyingPluginName = (_pluginName = plugin.pluginName) !== null && _pluginName !== void 0 ? _pluginName : plugin.constructor.name;
250
+ plugin.apply(_this);
251
+ applyingPluginName = "";
252
+ } catch (e) {
253
+ error("".concat(applyingPluginName || plugin.constructor.name, " Plugin apply Error \n ").concat(e));
254
+ }
255
+ });
256
+ this.__pluginsApplied = true;
257
+ };
258
+ _proto.emit = function emit(key) {
259
+ for(var _len = arguments.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
260
+ payload[_key - 1] = arguments[_key];
261
+ }
262
+ return _get(_getPrototypeOf(Driven.prototype), "emit", this).call(this, key, payload);
263
+ };
264
+ _proto.on = function on(key, callback) {
265
+ return _get(_getPrototypeOf(Driven.prototype), "on", this).call(this, key, callback);
266
+ };
267
+ _proto.setInstances = function setInstances(schema, beforeCreateInstance) {
268
+ this.store.setInstances(this.designer.createControl(Array.isArray(schema) ? schema : [
269
+ schema
270
+ ], beforeCreateInstance));
271
+ };
272
+ _proto.beforeSelectInstance = function beforeSelectInstance() {
273
+ this.store.setSelectInstance(null);
274
+ this.setSelectedFieldItem(null);
275
+ this.store.setSelectInstanceSettings([]);
276
+ };
277
+ _proto.afterSelectInstance = function afterSelectInstance() {
278
+ var instance = this.store.selected;
279
+ if (!instance) {
280
+ return;
281
+ }
282
+ this.setSelectedInstanceSetting();
283
+ this.emit("select", {
284
+ instance: instance
285
+ });
286
+ };
287
+ _proto.setSelectedInstanceSetting = function setSelectedInstanceSetting() {
288
+ var instance = this.store.selected;
289
+ if (!instance) {
290
+ return;
291
+ }
292
+ var setting = this.getControlSetting(instance.type);
293
+ if (_instanceof(instance.parent, DesignerWrapControl)) {
294
+ var wrapSetting = this.getControlSetting(instance.parent.type);
295
+ setting = this.concatSetting(setting, wrapSetting, instance.parent.id);
296
+ }
297
+ this.store.setSelectInstanceSettings(setting);
298
+ this.callSelectedEffect("");
299
+ // 选中触发scopeEffect
300
+ var payload = {
301
+ from: null,
302
+ current: this.store.selectedInstanceDataScopeParent,
303
+ oldParent: null,
304
+ newParent: instance.parent
305
+ };
306
+ this.callSelectedScopeEffect(payload);
307
+ };
308
+ _proto.concatSetting = function concatSetting(settings, otherSettings, settingFromId) {
309
+ var _this = this;
310
+ var ref, ref1, ref2, ref3;
311
+ var result = settings;
312
+ // tab
313
+ if (((ref = settings[0]) === null || ref === void 0 ? void 0 : ref.type) === "tab" && ((ref1 = otherSettings[0]) === null || ref1 === void 0 ? void 0 : ref1.type) === "tab") {
314
+ var tabSettings = settings;
315
+ var otherTabSettings = otherSettings.slice(0);
316
+ result = tabSettings.map(function(tab, index) {
317
+ var result = new Tab(tab);
318
+ var otherTabIndex = otherTabSettings.findIndex(function(item) {
319
+ return item.title === tab.title;
320
+ });
321
+ if (otherTabIndex === -1) {
322
+ return result;
323
+ }
324
+ var otherTab = otherTabSettings.splice(otherTabIndex, 1)[0];
325
+ if (otherTab) {
326
+ result.items = _toConsumableArray(_this.formatGroupSetting(otherTab.items, settingFromId)).concat(_toConsumableArray(result.items));
327
+ }
328
+ return result;
329
+ });
330
+ if (otherTabSettings.length) {
331
+ result = _toConsumableArray(result).concat(_toConsumableArray(otherTabSettings.map(function(item) {
332
+ return _this.formatGroupSetting(item, settingFromId);
333
+ })));
334
+ }
335
+ // group
336
+ } else if (((ref2 = settings[0]) === null || ref2 === void 0 ? void 0 : ref2.type) === "group" && ((ref3 = otherSettings[0]) === null || ref3 === void 0 ? void 0 : ref3.type) === "group") {
337
+ var groupSettings = settings;
338
+ var otherGroupSettings = otherSettings;
339
+ result = _toConsumableArray(this.formatGroupSetting(otherGroupSettings, settingFromId)).concat(_toConsumableArray(groupSettings));
340
+ } else {
341
+ // 一个是tab,一个是group,暂时不支持
342
+ }
343
+ return result;
344
+ };
345
+ _proto.formatGroupSetting = function formatGroupSetting(tab, fromId) {
346
+ if (isArray(tab)) {
347
+ return tab.map(function(item) {
348
+ var group = new Group(item);
349
+ group.fromId = fromId;
350
+ return group;
351
+ });
352
+ } else {
353
+ var result = new Tab(tab);
354
+ result.items = this.formatGroupSetting(result.items, fromId);
355
+ return result;
356
+ }
357
+ };
358
+ _proto.setControlConfig = function setControlConfig() {
359
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
360
+ args[_key] = arguments[_key];
361
+ }
362
+ var _designer;
363
+ return (_designer = this.designer).registerControlConfig.apply(_designer, _toConsumableArray(args));
364
+ };
365
+ _proto.getControlConfig = function getControlConfig(control) {
366
+ return this.designer.getControlConfig(control);
367
+ };
368
+ _proto.getControlSetting = function getControlSetting(type) {
369
+ var settingInit = this.designer.getControlSetting(type);
370
+ if (!settingInit) {
371
+ return [];
372
+ }
373
+ return initSettings(settingInit);
374
+ };
375
+ _proto.selectInstance = function selectInstance(instance) {
376
+ // 先清空上一次的store
377
+ this.beforeSelectInstance();
378
+ // 选中一个控件
379
+ this.store.setSelectInstance(instance);
380
+ // 针对这一次选中的控件初始化一些内容,并触发事件
381
+ this.afterSelectInstance();
382
+ };
383
+ _proto.setSelectedFieldItem = function setSelectedFieldItem(fieldItem) {
384
+ this.store.setSelectedFieldItem(fieldItem);
385
+ this.callSelectedEffect("dataBind", {
386
+ fieldItem: fieldItem
387
+ });
388
+ };
389
+ _proto.moveStart = function moveStart(instance) {
390
+ // 移动之前,记录控件原始的位置和父级
391
+ var _instance = this.getInstance(instance);
392
+ if (_instance) {
393
+ this.store.setMovingInstance(_instance);
394
+ }
395
+ };
396
+ _proto.moveEnd = function moveEnd() {
397
+ var instance = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.store.movingInstance;
398
+ var ref;
399
+ if (instance === null) return;
400
+ var _instance = this.getInstance(instance);
401
+ if (!_instance) return;
402
+ /*
403
+ 移动之后,拿到控件新的位置,并触发事件, 如果是新增的控件的话,就没有原始位置和父级,
404
+ 事件是否区分move和add
405
+ move是从主表移动到子表或子表移动到主表才触发,还是所有移动都触发
406
+ */ var oldDataScopeParent = this.store.movingInstanceOldDataScopeParent;
407
+ var newDataScopeParent = findInstanceDataScopeParent(_instance);
408
+ var oldParent = this.store.movingInstanceOldParent;
409
+ var newParent = _instance.parent;
410
+ // 移动之后清空movingInstance
411
+ this.store.setMovingInstance(null);
412
+ if (_instance.id !== ((ref = this.store.selected) === null || ref === void 0 ? void 0 : ref.id)) {
413
+ this.selectInstance(_instance);
414
+ } else {
415
+ this.store.setSelectInstance(_instance);
416
+ }
417
+ this.store.getFlatInstances();
418
+ // 结束以后
419
+ var payload = {
420
+ from: oldDataScopeParent,
421
+ current: newDataScopeParent,
422
+ oldParent: oldParent,
423
+ newParent: newParent
424
+ };
425
+ this.callSelectedScopeEffect(payload);
426
+ if (oldParent) {
427
+ this.emit("moved", _objectSpread({}, payload));
428
+ } else {
429
+ this.emit("joined", _objectSpread({}, payload));
430
+ }
431
+ };
432
+ _proto.createInstance = function createInstance(type, initSchema) {
433
+ return this.designer.createControlInstance(type, initSchema);
434
+ };
435
+ _proto.getInstance = function getInstance(instanceId) {
436
+ if (_instanceof(instanceId, DesignerControl)) {
437
+ return instanceId;
438
+ }
439
+ return this.store.instanceIdMap.get(instanceId);
440
+ };
441
+ _proto.getInstances = function getInstances() {
442
+ return this.store.flatInstances;
443
+ };
444
+ _proto.getInstancesFromType = function getInstancesFromType(type) {
445
+ return this.getInstances().filter(function(item) {
446
+ return item.type === type;
447
+ });
448
+ };
449
+ _proto.getDataScopeInstances = function getDataScopeInstances() {
450
+ return this.store.selectedDataScopeFlatInstances;
451
+ };
452
+ _proto.getDataScopeInstancesFromType = function getDataScopeInstancesFromType(type) {
453
+ return this.getDataScopeInstances().filter(function(item) {
454
+ return item.type === type;
455
+ });
456
+ };
457
+ _proto.updateInstancePropValue = function updateInstancePropValue(instance, propName, value, payload) {
458
+ var ref;
459
+ var result = updateValueFromKeys(instance.props, propName, value);
460
+ if (!result) {
461
+ return;
462
+ }
463
+ // 修改dataBind的时候要更新 fieldCodeMap
464
+ if (propName.startsWith("dataBind")) {
465
+ this.store.updateDataFieldCodeMap(instance);
466
+ }
467
+ if (instance.id === ((ref = this.store.selected) === null || ref === void 0 ? void 0 : ref.id)) {
468
+ this.callSelectedEffect(propName, payload);
469
+ }
470
+ this.emit("updated", {
471
+ instance: instance,
472
+ propName: propName,
473
+ value: value
474
+ });
475
+ };
476
+ _proto.updateInstanceProps = function updateInstanceProps(instance, props, payload) {
477
+ var prevKey = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "";
478
+ var _this = this;
479
+ Object.entries(props).forEach(function(param) {
480
+ var _param = _slicedToArray(param, 2), key = _param[0], value = _param[1];
481
+ var propName = "".concat(prevKey ? prevKey + "." : "").concat(key);
482
+ if (isObject(value)) {
483
+ _this.updateInstanceProps(instance, value, payload, propName);
484
+ } else {
485
+ _this.updateInstancePropValue(instance, propName, value, payload);
486
+ }
487
+ });
488
+ };
489
+ _proto.setInstance = function setInstance(instance, propName, value, payload) {
490
+ if (isString(propName)) {
491
+ this.updateInstancePropValue(instance, String(propName), value, payload);
492
+ } else {
493
+ this.updateInstanceProps(instance, propName, value);
494
+ }
495
+ };
496
+ /**
497
+ * 删除控件
498
+ * */ _proto.removeInstance = function removeInstance(instance) {
499
+ // 删除实例,并触发事件 removed
500
+ var parent = instance.parent;
501
+ if (!parent) {
502
+ return;
503
+ }
504
+ var parentList = _instanceof(parent, DesignerListControl) && parent.props.headers.includes(instance) ? parent.props.headers : parent.children;
505
+ var index = parentList.findIndex(function(item) {
506
+ return item === instance;
507
+ });
508
+ index > -1 && parentList.splice(index, 1);
509
+ this.store.getFlatInstances();
510
+ this.emit("removed", {
511
+ instance: instance,
512
+ index: index,
513
+ parent: parent
514
+ });
515
+ };
516
+ _proto.replaceInstance = function replaceInstance(oldInstance, newInstance) {
517
+ var parent = oldInstance.parent;
518
+ if (!parent) {
519
+ return;
520
+ }
521
+ var parentList = _instanceof(parent, DesignerListControl) && parent.props.headers.includes(oldInstance) ? parent.props.headers : parent.children;
522
+ var index = parentList.findIndex(function(item) {
523
+ return item === oldInstance;
524
+ });
525
+ index > -1 && parentList.splice(index, 1, newInstance);
526
+ this.store.getFlatInstances();
527
+ };
528
+ /**
529
+ * 修改控件类型
530
+ * */ _proto.updateInstanceType = function updateInstanceType(instance, type) {
531
+ var schema = instance.toSchema();
532
+ var newInstance = this.createInstance(type, {
533
+ id: schema.id,
534
+ props: schema.props
535
+ });
536
+ if (!newInstance) {
537
+ warn("can‘t update instance type to ".concat(type));
538
+ return;
539
+ }
540
+ return newInstance;
541
+ };
542
+ _proto.validate = function validate(messages, ignore) {
543
+ //TODO 校验实例属性,并触发事件 before-validate 和 validated
544
+ return checkSchema(this.store.instance, messages, ignore);
545
+ };
546
+ // 获取使用到的自定义控件
547
+ _proto.getCustomControlsInUse = function getCustomControlsInUse() {
548
+ return this.getInstances().filter(this.assertInstanceIsCustomControl).reduce(function(result, item) {
549
+ if (!result.includes(item.type)) {
550
+ result.push(item.type);
551
+ }
552
+ return result;
553
+ }, []);
554
+ };
555
+ // 判断控件或控件类型是一个自定义控件
556
+ _proto.assertInstanceIsCustomControl = function assertInstanceIsCustomControl(instance) {
557
+ return !isBuiltInControls(isString(instance) ? instance : instance.type);
558
+ };
559
+ _proto.judgeControlIsRegistered = function judgeControlIsRegistered(control) {
560
+ return this.designer.registeredControlTypes.has(control.Designer.controlType);
561
+ };
562
+ _proto.register = function register() {
563
+ for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
564
+ arg[_key] = arguments[_key];
565
+ }
566
+ var _designer;
567
+ (_designer = this.designer).registerControl.apply(_designer, _toConsumableArray(arg));
568
+ return this;
569
+ };
570
+ /**
571
+ * 判断控件的类型,返回当前控件的正确类型
572
+ * */ _proto.assertInstance = function assertInstance(instance, types) {
573
+ return isString(types) ? instance.type === types : types.includes(instance.type);
574
+ };
575
+ /**
576
+ * 控件在列表控件内,如明细子表或列表控件
577
+ * */ _proto.getInstanceInListControl = function getInstanceInListControl(instance) {
578
+ var _instance = instance;
579
+ while(_instance){
580
+ if (_instanceof(_instance, DesignerListControl)) {
581
+ return true;
582
+ }
583
+ _instance = _instance.parent;
584
+ }
585
+ return false;
586
+ };
587
+ _proto.getInstanceParentControl = function getInstanceParentControl(instance, controlType) {
588
+ if (!instance.parent) {
589
+ return;
590
+ }
591
+ if (this.assertInstance(instance.parent, controlType)) {
592
+ return instance.parent;
593
+ }
594
+ return this.getInstanceParentControl(instance.parent, controlType);
595
+ };
596
+ _proto.callSelectedEffect = function callSelectedEffect(effectKey) {
597
+ var payload = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
598
+ var _this = this;
599
+ this.store.selectedInstanceSettingItems.forEach(function(setting) {
600
+ setting.callEffect(effectKey, _this, _objectSpread({
601
+ control: _this.store.selected
602
+ }, payload));
603
+ });
604
+ };
605
+ _proto.callSelectedScopeEffect = function callSelectedScopeEffect() {
606
+ var payload = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
607
+ var _this = this;
608
+ this.store.selectedInstanceSettingItems.forEach(function(setting) {
609
+ setting.callScopeEffect(_this, _objectSpread({
610
+ control: _this.store.selected
611
+ }, payload));
612
+ });
613
+ };
614
+ // 注册外部控件
615
+ Driven.register = function register() {
616
+ for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
617
+ arg[_key] = arguments[_key];
618
+ }
619
+ var _Designer;
620
+ (_Designer = Designer).register.apply(_Designer, _toConsumableArray(arg));
621
+ return this;
622
+ };
623
+ Driven.judgeControlIsRegistered = function judgeControlIsRegistered(control) {
624
+ return Designer.staticRegisteredTypes.has(control.Designer.controlType);
625
+ };
626
+ return Driven;
627
+ }(Watcher);
628
+ /**
629
+ * 控件事件定义
630
+ * */ Driven.EventLogic = EventLogic;
631
+ export { Driven };
@@ -0,0 +1,2 @@
1
+ import { EventLogic } from "@byteluck-fe/model-driven-shared";
2
+ export default EventLogic;
@@ -0,0 +1,10 @@
1
+ function _classCallCheck(instance, Constructor) {
2
+ if (!(instance instanceof Constructor)) {
3
+ throw new TypeError("Cannot call a class as a function");
4
+ }
5
+ }
6
+ var Plugin = function Plugin() {
7
+ "use strict";
8
+ _classCallCheck(this, Plugin);
9
+ };
10
+ export { Plugin };