@byteluck-fe/model-driven-driven 2.23.0-beta.3 → 2.23.0-beta.6
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.
- package/dist/esm/Builder.js +186 -0
- package/dist/esm/Designer.js +363 -0
- package/dist/esm/Driven.js +788 -0
- package/dist/esm/EventLogic.js +2 -0
- package/dist/esm/Plugin.js +10 -0
- package/dist/esm/Store.js +350 -0
- package/dist/esm/constants.js +33 -0
- package/dist/esm/designerUtils.js +34 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/utils.js +466 -0
- package/dist/index.umd.js +45 -0
- package/dist/types/Driven.d.ts +2 -2
- package/package.json +6 -6
|
@@ -0,0 +1,788 @@
|
|
|
1
|
+
function _array_like_to_array(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 _array_with_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function _array_without_holes(arr) {
|
|
10
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
11
|
+
}
|
|
12
|
+
function _assert_this_initialized(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 _call_super(_this, derived, args) {
|
|
19
|
+
derived = _get_prototype_of(derived);
|
|
20
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
21
|
+
}
|
|
22
|
+
function _class_call_check(instance, Constructor) {
|
|
23
|
+
if (!(instance instanceof Constructor)) {
|
|
24
|
+
throw new TypeError("Cannot call a class as a function");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function _defineProperties(target, props) {
|
|
28
|
+
for(var i = 0; i < props.length; i++){
|
|
29
|
+
var descriptor = props[i];
|
|
30
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
31
|
+
descriptor.configurable = true;
|
|
32
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
33
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
37
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
38
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
39
|
+
return Constructor;
|
|
40
|
+
}
|
|
41
|
+
function _define_property(obj, key, value) {
|
|
42
|
+
if (key in obj) {
|
|
43
|
+
Object.defineProperty(obj, key, {
|
|
44
|
+
value: value,
|
|
45
|
+
enumerable: true,
|
|
46
|
+
configurable: true,
|
|
47
|
+
writable: true
|
|
48
|
+
});
|
|
49
|
+
} else {
|
|
50
|
+
obj[key] = value;
|
|
51
|
+
}
|
|
52
|
+
return obj;
|
|
53
|
+
}
|
|
54
|
+
function _get(target, property, receiver) {
|
|
55
|
+
if (typeof Reflect !== "undefined" && Reflect.get) {
|
|
56
|
+
_get = Reflect.get;
|
|
57
|
+
} else {
|
|
58
|
+
_get = function get(target, property, receiver) {
|
|
59
|
+
var base = _super_prop_base(target, property);
|
|
60
|
+
if (!base) return;
|
|
61
|
+
var desc = Object.getOwnPropertyDescriptor(base, property);
|
|
62
|
+
if (desc.get) {
|
|
63
|
+
return desc.get.call(receiver || target);
|
|
64
|
+
}
|
|
65
|
+
return desc.value;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return _get(target, property, receiver || target);
|
|
69
|
+
}
|
|
70
|
+
function _get_prototype_of(o) {
|
|
71
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
72
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
73
|
+
};
|
|
74
|
+
return _get_prototype_of(o);
|
|
75
|
+
}
|
|
76
|
+
function _inherits(subClass, superClass) {
|
|
77
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
78
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
79
|
+
}
|
|
80
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
81
|
+
constructor: {
|
|
82
|
+
value: subClass,
|
|
83
|
+
writable: true,
|
|
84
|
+
configurable: true
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
88
|
+
}
|
|
89
|
+
function _iterable_to_array(iter) {
|
|
90
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
91
|
+
}
|
|
92
|
+
function _iterable_to_array_limit(arr, i) {
|
|
93
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
94
|
+
if (_i == null) return;
|
|
95
|
+
var _arr = [];
|
|
96
|
+
var _n = true;
|
|
97
|
+
var _d = false;
|
|
98
|
+
var _s, _e;
|
|
99
|
+
try {
|
|
100
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
101
|
+
_arr.push(_s.value);
|
|
102
|
+
if (i && _arr.length === i) break;
|
|
103
|
+
}
|
|
104
|
+
} catch (err) {
|
|
105
|
+
_d = true;
|
|
106
|
+
_e = err;
|
|
107
|
+
} finally{
|
|
108
|
+
try {
|
|
109
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
110
|
+
} finally{
|
|
111
|
+
if (_d) throw _e;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return _arr;
|
|
115
|
+
}
|
|
116
|
+
function _non_iterable_rest() {
|
|
117
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
118
|
+
}
|
|
119
|
+
function _non_iterable_spread() {
|
|
120
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
121
|
+
}
|
|
122
|
+
function _object_spread(target) {
|
|
123
|
+
for(var i = 1; i < arguments.length; i++){
|
|
124
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
125
|
+
var ownKeys = Object.keys(source);
|
|
126
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
127
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
128
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
ownKeys.forEach(function(key) {
|
|
132
|
+
_define_property(target, key, source[key]);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return target;
|
|
136
|
+
}
|
|
137
|
+
function _possible_constructor_return(self, call) {
|
|
138
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
139
|
+
return call;
|
|
140
|
+
}
|
|
141
|
+
return _assert_this_initialized(self);
|
|
142
|
+
}
|
|
143
|
+
function _set_prototype_of(o, p) {
|
|
144
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
145
|
+
o.__proto__ = p;
|
|
146
|
+
return o;
|
|
147
|
+
};
|
|
148
|
+
return _set_prototype_of(o, p);
|
|
149
|
+
}
|
|
150
|
+
function _sliced_to_array(arr, i) {
|
|
151
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
152
|
+
}
|
|
153
|
+
function _super_prop_base(object, property) {
|
|
154
|
+
while(!Object.prototype.hasOwnProperty.call(object, property)){
|
|
155
|
+
object = _get_prototype_of(object);
|
|
156
|
+
if (object === null) break;
|
|
157
|
+
}
|
|
158
|
+
return object;
|
|
159
|
+
}
|
|
160
|
+
function _to_consumable_array(arr) {
|
|
161
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
162
|
+
}
|
|
163
|
+
function _type_of(obj) {
|
|
164
|
+
"@swc/helpers - typeof";
|
|
165
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
166
|
+
}
|
|
167
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
168
|
+
if (!o) return;
|
|
169
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
170
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
171
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
172
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
173
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
174
|
+
}
|
|
175
|
+
function _is_native_reflect_construct() {
|
|
176
|
+
try {
|
|
177
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
178
|
+
} catch (_) {}
|
|
179
|
+
return (_is_native_reflect_construct = function() {
|
|
180
|
+
return !!result;
|
|
181
|
+
})();
|
|
182
|
+
}
|
|
183
|
+
import { CONTROL_BASE_TYPE, error, genNonDuplicateId, isArray, isBuiltInControls, isObject, isString, updateValueFromKeys, warn, Watcher } from '@byteluck-fe/model-driven-shared';
|
|
184
|
+
import { findInstanceDataScopeParent, Store } from './Store';
|
|
185
|
+
import { Designer } from './Designer';
|
|
186
|
+
import EventLogic from './EventLogic';
|
|
187
|
+
import { checkSchema, generatePermissions, getModelBindInfoList, toSchema } from './utils';
|
|
188
|
+
import { Group, initSettings, Tab } from '@byteluck-fe/model-driven-settings';
|
|
189
|
+
import { RulesMessage, DEFAULT_LOCALE } from '@byteluck-fe/model-driven-shared';
|
|
190
|
+
// 当前正在注册的插件名称
|
|
191
|
+
var applyingPluginName = '';
|
|
192
|
+
/**
|
|
193
|
+
* 设计器驱动
|
|
194
|
+
* */ var Driven = /*#__PURE__*/ function(Watcher) {
|
|
195
|
+
"use strict";
|
|
196
|
+
_inherits(Driven, Watcher);
|
|
197
|
+
function Driven(options) {
|
|
198
|
+
_class_call_check(this, Driven);
|
|
199
|
+
var _this;
|
|
200
|
+
_this = _call_super(this, Driven), _define_property(_this, "mode", void 0), _define_property(_this, "isMounted", false), _define_property(_this, "id", genNonDuplicateId(8)), /**
|
|
201
|
+
* 控件可选的事件
|
|
202
|
+
* */ _define_property(_this, "eventLogic", void 0), /**
|
|
203
|
+
* 处理数据存储,存放模型等
|
|
204
|
+
* */ _define_property(_this, "store", void 0), /**
|
|
205
|
+
* 额外参数存储
|
|
206
|
+
*/ _define_property(_this, "externalParams", void 0), /**
|
|
207
|
+
* 处理instance,和schema存储
|
|
208
|
+
* */ _define_property(_this, "designer", void 0), /**
|
|
209
|
+
* 插件数组
|
|
210
|
+
* */ _define_property(_this, "__plugins", void 0), _define_property(_this, "__pluginsApplied", false), _define_property(_this, "$options", void 0), // TODO 拿到schema
|
|
211
|
+
_define_property(_this, "getSchema", toSchema), // TODO 拿到model_bind_info_list
|
|
212
|
+
_define_property(_this, "getModelBindInfoList", getModelBindInfoList), // TODO 拿到permission_controls
|
|
213
|
+
_define_property(_this, "generatePermissions", generatePermissions);
|
|
214
|
+
_this.$options = Object.freeze(options);
|
|
215
|
+
var _this_$options = _this.$options, _this_$options_autoMount = _this_$options.autoMount, autoMount = _this_$options_autoMount === void 0 ? false : _this_$options_autoMount, tmp = _this_$options.Designer, DesignerClass = tmp === void 0 ? Designer : tmp, schema = _this_$options.schema, _this_$options_mode = _this_$options.mode, mode = _this_$options_mode === void 0 ? 'form' : _this_$options_mode, tmp1 = _this_$options.store, storeOptions = tmp1 === void 0 ? {} : tmp1, messagesI18n = _this_$options.messagesI18n, _this_$options_language = _this_$options.language, language = _this_$options_language === void 0 ? DEFAULT_LOCALE : _this_$options_language;
|
|
216
|
+
RulesMessage.setLocale(language, messagesI18n);
|
|
217
|
+
_this.eventLogic = new EventLogic();
|
|
218
|
+
_this.designer = new DesignerClass();
|
|
219
|
+
_this.store = new Store(_object_spread({
|
|
220
|
+
instance: _this.designer.createControl(Array.isArray(schema) ? schema : [
|
|
221
|
+
schema
|
|
222
|
+
])
|
|
223
|
+
}, storeOptions));
|
|
224
|
+
_this.mode = mode;
|
|
225
|
+
autoMount && _this.mount();
|
|
226
|
+
return _this;
|
|
227
|
+
}
|
|
228
|
+
_create_class(Driven, [
|
|
229
|
+
{
|
|
230
|
+
key: "mount",
|
|
231
|
+
value: // 挂载
|
|
232
|
+
function mount() {
|
|
233
|
+
var _this_$options = this.$options, _this_$options_plugins = _this_$options.plugins, plugins = _this_$options_plugins === void 0 ? [] : _this_$options_plugins;
|
|
234
|
+
this.__plugins = plugins;
|
|
235
|
+
this.applyPlugins();
|
|
236
|
+
this.isMounted = true;
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
key: "use",
|
|
241
|
+
value: function use(plugin) {
|
|
242
|
+
if (!this.__pluginsApplied) {
|
|
243
|
+
this.__plugins.push(plugin);
|
|
244
|
+
}
|
|
245
|
+
return this;
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
key: "applyPlugins",
|
|
250
|
+
value: function applyPlugins() {
|
|
251
|
+
var _this = this;
|
|
252
|
+
if (this.__pluginsApplied) return;
|
|
253
|
+
this.__plugins.forEach(function(plugin) {
|
|
254
|
+
try {
|
|
255
|
+
var _plugin_pluginName;
|
|
256
|
+
applyingPluginName = (_plugin_pluginName = plugin.pluginName) !== null && _plugin_pluginName !== void 0 ? _plugin_pluginName : plugin.constructor.name;
|
|
257
|
+
plugin.apply(_this);
|
|
258
|
+
applyingPluginName = '';
|
|
259
|
+
} catch (e) {
|
|
260
|
+
error("".concat(applyingPluginName || plugin.constructor.name, " Plugin apply Error \n ").concat(e));
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
this.__pluginsApplied = true;
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
key: "emit",
|
|
268
|
+
value: function emit(key) {
|
|
269
|
+
for(var _len = arguments.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
|
|
270
|
+
payload[_key - 1] = arguments[_key];
|
|
271
|
+
}
|
|
272
|
+
return _get(_get_prototype_of(Driven.prototype), "emit", this).call(this, key, payload);
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
key: "on",
|
|
277
|
+
value: function on(key, callback) {
|
|
278
|
+
return _get(_get_prototype_of(Driven.prototype), "on", this).call(this, key, callback);
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
key: "setInstances",
|
|
283
|
+
value: function setInstances(schema, beforeCreateInstance) {
|
|
284
|
+
this.store.setInstances(this.designer.createControl(Array.isArray(schema) ? schema : [
|
|
285
|
+
schema
|
|
286
|
+
], beforeCreateInstance));
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
key: "beforeSelectInstance",
|
|
291
|
+
value: function beforeSelectInstance() {
|
|
292
|
+
this.store.setSelectInstance(null);
|
|
293
|
+
this.setSelectedFieldItem(null);
|
|
294
|
+
this.store.setSelectInstanceSettings([]);
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
key: "afterSelectInstance",
|
|
299
|
+
value: function afterSelectInstance() {
|
|
300
|
+
var instance = this.store.selected;
|
|
301
|
+
if (!instance) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
this.setSelectedInstanceSetting();
|
|
305
|
+
this.emit('select', {
|
|
306
|
+
instance: instance
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
key: "setSelectedInstanceSetting",
|
|
312
|
+
value: function setSelectedInstanceSetting() {
|
|
313
|
+
var _instance_parent;
|
|
314
|
+
var instance = this.store.selected;
|
|
315
|
+
if (!instance) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
var setting = this.getControlSetting(instance.type);
|
|
319
|
+
// console.log('iswrap:', instance.parent?.controlType, instance.parent)
|
|
320
|
+
// if (instance.parent instanceof DesignerWrapControl) {
|
|
321
|
+
// 如果父控件为自定义控件wrapper
|
|
322
|
+
if (((_instance_parent = instance.parent) === null || _instance_parent === void 0 ? void 0 : _instance_parent.controlType) === CONTROL_BASE_TYPE.WRAP) {
|
|
323
|
+
var _instance_parent1;
|
|
324
|
+
var wrapSetting = this.getControlSetting((_instance_parent1 = instance.parent) === null || _instance_parent1 === void 0 ? void 0 : _instance_parent1.type);
|
|
325
|
+
setting = this.concatSetting(setting, wrapSetting, instance.parent.id);
|
|
326
|
+
}
|
|
327
|
+
this.store.setSelectInstanceSettings(setting);
|
|
328
|
+
this.callSelectedEffect('');
|
|
329
|
+
// 选中触发scopeEffect
|
|
330
|
+
var payload = {
|
|
331
|
+
from: null,
|
|
332
|
+
current: this.store.selectedInstanceDataScopeParent,
|
|
333
|
+
oldParent: null,
|
|
334
|
+
newParent: instance.parent
|
|
335
|
+
};
|
|
336
|
+
this.callSelectedScopeEffect(payload);
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
key: "concatSetting",
|
|
341
|
+
value: function concatSetting(settings, otherSettings, settingFromId) {
|
|
342
|
+
var _this = this;
|
|
343
|
+
var _settings_, _otherSettings_, _settings_1, _otherSettings_1, _settings_2, _otherSettings_2, _settings_3, _otherSettings_3;
|
|
344
|
+
var result = settings;
|
|
345
|
+
// tab
|
|
346
|
+
if (((_settings_ = settings[0]) === null || _settings_ === void 0 ? void 0 : _settings_.type) === 'tab' && ((_otherSettings_ = otherSettings[0]) === null || _otherSettings_ === void 0 ? void 0 : _otherSettings_.type) === 'tab') {
|
|
347
|
+
var tabSettings = settings;
|
|
348
|
+
var otherTabSettings = otherSettings.slice(0);
|
|
349
|
+
result = tabSettings.map(function(tab, index) {
|
|
350
|
+
var result = new Tab(tab);
|
|
351
|
+
var otherTabIndex = otherTabSettings.findIndex(function(item) {
|
|
352
|
+
return item.title === tab.title;
|
|
353
|
+
});
|
|
354
|
+
if (otherTabIndex === -1) {
|
|
355
|
+
return result;
|
|
356
|
+
}
|
|
357
|
+
var otherTab = otherTabSettings.splice(otherTabIndex, 1)[0];
|
|
358
|
+
if (otherTab) {
|
|
359
|
+
result.items = _to_consumable_array(_this.formatGroupSetting(otherTab.items, settingFromId)).concat(_to_consumable_array(result.items));
|
|
360
|
+
}
|
|
361
|
+
return result;
|
|
362
|
+
});
|
|
363
|
+
if (otherTabSettings.length) {
|
|
364
|
+
result = _to_consumable_array(result).concat(_to_consumable_array(otherTabSettings.map(function(item) {
|
|
365
|
+
return _this.formatGroupSetting(item, settingFromId);
|
|
366
|
+
})));
|
|
367
|
+
}
|
|
368
|
+
// group
|
|
369
|
+
} else if (((_settings_1 = settings[0]) === null || _settings_1 === void 0 ? void 0 : _settings_1.type) === 'group' && ((_otherSettings_1 = otherSettings[0]) === null || _otherSettings_1 === void 0 ? void 0 : _otherSettings_1.type) === 'group') {
|
|
370
|
+
var groupSettings = settings;
|
|
371
|
+
var otherGroupSettings = otherSettings;
|
|
372
|
+
result = _to_consumable_array(this.formatGroupSetting(otherGroupSettings, settingFromId)).concat(_to_consumable_array(groupSettings));
|
|
373
|
+
// 当前控件setting是tab,合并控件setting是group
|
|
374
|
+
} else if (((_settings_2 = settings[0]) === null || _settings_2 === void 0 ? void 0 : _settings_2.type) === 'tab' && ((_otherSettings_2 = otherSettings[0]) === null || _otherSettings_2 === void 0 ? void 0 : _otherSettings_2.type) === 'group') {
|
|
375
|
+
var tabSettings1 = settings;
|
|
376
|
+
var otherGroupSettings1 = otherSettings;
|
|
377
|
+
result = tabSettings1.map(function(tab, index) {
|
|
378
|
+
var result = new Tab(tab);
|
|
379
|
+
if (index === 0) {
|
|
380
|
+
result.items = _to_consumable_array(_this.formatGroupSetting(otherGroupSettings1, settingFromId)).concat(_to_consumable_array(result.items));
|
|
381
|
+
}
|
|
382
|
+
return result;
|
|
383
|
+
});
|
|
384
|
+
} else if (((_settings_3 = settings[0]) === null || _settings_3 === void 0 ? void 0 : _settings_3.type) === 'group' && ((_otherSettings_3 = otherSettings[0]) === null || _otherSettings_3 === void 0 ? void 0 : _otherSettings_3.type) === 'tab') {
|
|
385
|
+
var groupSettings1 = settings;
|
|
386
|
+
var otherTabSettings1 = otherSettings;
|
|
387
|
+
result = otherTabSettings1.map(function(tab, index) {
|
|
388
|
+
var result = new Tab(tab);
|
|
389
|
+
if (index === 0) {
|
|
390
|
+
result.items = _to_consumable_array(result.items).concat(_to_consumable_array(_this.formatGroupSetting(groupSettings1, settingFromId)));
|
|
391
|
+
}
|
|
392
|
+
return result;
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
return result;
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
key: "formatGroupSetting",
|
|
400
|
+
value: function formatGroupSetting(tab, fromId) {
|
|
401
|
+
if (isArray(tab)) {
|
|
402
|
+
return tab.map(function(item) {
|
|
403
|
+
var group = new Group(item);
|
|
404
|
+
group.fromId = fromId;
|
|
405
|
+
return group;
|
|
406
|
+
});
|
|
407
|
+
} else {
|
|
408
|
+
var result = new Tab(tab);
|
|
409
|
+
result.items = this.formatGroupSetting(result.items, fromId);
|
|
410
|
+
return result;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
key: "setControlConfig",
|
|
416
|
+
value: function setControlConfig() {
|
|
417
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
418
|
+
args[_key] = arguments[_key];
|
|
419
|
+
}
|
|
420
|
+
var _this_designer;
|
|
421
|
+
return (_this_designer = this.designer).registerControlConfig.apply(_this_designer, _to_consumable_array(args));
|
|
422
|
+
}
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
key: "getControlConfig",
|
|
426
|
+
value: function getControlConfig(control) {
|
|
427
|
+
return this.designer.getControlConfig(control);
|
|
428
|
+
}
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
key: "getControlSetting",
|
|
432
|
+
value: function getControlSetting(type) {
|
|
433
|
+
var settingInit = this.designer.getControlSetting(type);
|
|
434
|
+
if (!settingInit) {
|
|
435
|
+
return [];
|
|
436
|
+
}
|
|
437
|
+
return initSettings(settingInit);
|
|
438
|
+
}
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
key: "selectInstance",
|
|
442
|
+
value: function selectInstance(instance) {
|
|
443
|
+
// 先清空上一次的store
|
|
444
|
+
this.beforeSelectInstance();
|
|
445
|
+
// 选中一个控件
|
|
446
|
+
this.store.setSelectInstance(instance);
|
|
447
|
+
// 针对这一次选中的控件初始化一些内容,并触发事件
|
|
448
|
+
this.afterSelectInstance();
|
|
449
|
+
}
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
key: "setSelectedFieldItem",
|
|
453
|
+
value: function setSelectedFieldItem(fieldItem) {
|
|
454
|
+
this.store.setSelectedFieldItem(fieldItem);
|
|
455
|
+
this.callSelectedEffect('dataBind', {
|
|
456
|
+
fieldItem: fieldItem
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
key: "moveStart",
|
|
462
|
+
value: function moveStart(instance) {
|
|
463
|
+
// 移动之前,记录控件原始的位置和父级
|
|
464
|
+
var _instance = this.getInstance(instance);
|
|
465
|
+
if (_instance) {
|
|
466
|
+
this.store.setMovingInstance(_instance);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
},
|
|
470
|
+
{
|
|
471
|
+
key: "moveEnd",
|
|
472
|
+
value: function moveEnd() {
|
|
473
|
+
var instance = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.store.movingInstance;
|
|
474
|
+
var _this_store_selected;
|
|
475
|
+
if (instance === null) return;
|
|
476
|
+
var _instance = this.getInstance(instance);
|
|
477
|
+
if (!_instance) return;
|
|
478
|
+
/*
|
|
479
|
+
移动之后,拿到控件新的位置,并触发事件, 如果是新增的控件的话,就没有原始位置和父级,
|
|
480
|
+
事件是否区分move和add
|
|
481
|
+
move是从主表移动到子表或子表移动到主表才触发,还是所有移动都触发
|
|
482
|
+
*/ var oldDataScopeParent = this.store.movingInstanceOldDataScopeParent;
|
|
483
|
+
var newDataScopeParent = findInstanceDataScopeParent(_instance);
|
|
484
|
+
var oldParent = this.store.movingInstanceOldParent;
|
|
485
|
+
var newParent = _instance.parent;
|
|
486
|
+
// 移动之后清空movingInstance
|
|
487
|
+
this.store.setMovingInstance(null);
|
|
488
|
+
if (_instance.id !== ((_this_store_selected = this.store.selected) === null || _this_store_selected === void 0 ? void 0 : _this_store_selected.id)) {
|
|
489
|
+
this.selectInstance(_instance);
|
|
490
|
+
} else {
|
|
491
|
+
this.store.setSelectInstance(_instance);
|
|
492
|
+
}
|
|
493
|
+
this.store.getFlatInstances();
|
|
494
|
+
// 结束以后
|
|
495
|
+
var payload = {
|
|
496
|
+
from: oldDataScopeParent,
|
|
497
|
+
current: newDataScopeParent,
|
|
498
|
+
oldParent: oldParent,
|
|
499
|
+
newParent: newParent
|
|
500
|
+
};
|
|
501
|
+
this.callSelectedScopeEffect(payload);
|
|
502
|
+
if (oldParent) {
|
|
503
|
+
this.emit('moved', _object_spread({}, payload));
|
|
504
|
+
} else {
|
|
505
|
+
this.emit('joined', _object_spread({}, payload));
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
key: "createInstance",
|
|
511
|
+
value: function createInstance(type, initSchema) {
|
|
512
|
+
return this.designer.createControlInstance(type, initSchema);
|
|
513
|
+
}
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
key: "getInstance",
|
|
517
|
+
value: function getInstance(instanceId) {
|
|
518
|
+
// if (instanceId instanceof DesignerControl) {
|
|
519
|
+
// return instanceId
|
|
520
|
+
// }
|
|
521
|
+
// return this.store.instanceIdMap.get(instanceId)
|
|
522
|
+
if (typeof instanceId === 'string') {
|
|
523
|
+
return this.store.instanceIdMap.get(instanceId);
|
|
524
|
+
}
|
|
525
|
+
return instanceId;
|
|
526
|
+
}
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
key: "getInstances",
|
|
530
|
+
value: function getInstances() {
|
|
531
|
+
return this.store.flatInstances;
|
|
532
|
+
}
|
|
533
|
+
},
|
|
534
|
+
{
|
|
535
|
+
key: "getInstancesFromType",
|
|
536
|
+
value: function getInstancesFromType(type) {
|
|
537
|
+
return this.getInstances().filter(function(item) {
|
|
538
|
+
return item.type === type;
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
},
|
|
542
|
+
{
|
|
543
|
+
key: "getDataScopeInstances",
|
|
544
|
+
value: function getDataScopeInstances() {
|
|
545
|
+
return this.store.selectedDataScopeFlatInstances;
|
|
546
|
+
}
|
|
547
|
+
},
|
|
548
|
+
{
|
|
549
|
+
key: "getDataScopeInstancesFromType",
|
|
550
|
+
value: function getDataScopeInstancesFromType(type) {
|
|
551
|
+
return this.getDataScopeInstances().filter(function(item) {
|
|
552
|
+
return item.type === type;
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
},
|
|
556
|
+
{
|
|
557
|
+
key: "updateInstancePropValue",
|
|
558
|
+
value: function updateInstancePropValue(instance, propName, value, payload) {
|
|
559
|
+
var _this_store_selected;
|
|
560
|
+
var result = updateValueFromKeys(instance.props, propName, value);
|
|
561
|
+
if (!result) {
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
// 修改dataBind的时候要更新 fieldCodeMap
|
|
565
|
+
if (propName.startsWith('dataBind')) {
|
|
566
|
+
this.store.updateDataFieldCodeMap(instance);
|
|
567
|
+
}
|
|
568
|
+
if (instance.id === ((_this_store_selected = this.store.selected) === null || _this_store_selected === void 0 ? void 0 : _this_store_selected.id)) {
|
|
569
|
+
this.callSelectedEffect(propName, payload);
|
|
570
|
+
}
|
|
571
|
+
this.emit('updated', {
|
|
572
|
+
instance: instance,
|
|
573
|
+
propName: propName,
|
|
574
|
+
value: value
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
},
|
|
578
|
+
{
|
|
579
|
+
key: "updateInstanceProps",
|
|
580
|
+
value: function updateInstanceProps(instance, props, payload) {
|
|
581
|
+
var _this = this;
|
|
582
|
+
var prevKey = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : '';
|
|
583
|
+
Object.entries(props).forEach(function(param) {
|
|
584
|
+
var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
|
|
585
|
+
var propName = "".concat(prevKey ? prevKey + '.' : '').concat(key);
|
|
586
|
+
if (isObject(value)) {
|
|
587
|
+
_this.updateInstanceProps(instance, value, payload, propName);
|
|
588
|
+
} else {
|
|
589
|
+
_this.updateInstancePropValue(instance, propName, value, payload);
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
},
|
|
594
|
+
{
|
|
595
|
+
key: "setInstance",
|
|
596
|
+
value: function setInstance(instance, propName, value, payload) {
|
|
597
|
+
if (isString(propName)) {
|
|
598
|
+
this.updateInstancePropValue(instance, String(propName), value, payload);
|
|
599
|
+
} else {
|
|
600
|
+
this.updateInstanceProps(instance, propName, value);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
key: "removeInstance",
|
|
606
|
+
value: /**
|
|
607
|
+
* 删除控件
|
|
608
|
+
* */ function removeInstance(instance) {
|
|
609
|
+
// 删除实例,并触发事件 removed
|
|
610
|
+
var parent = instance.parent;
|
|
611
|
+
if (!parent) {
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
var parentList = // parent instanceof DesignerListControl &&
|
|
615
|
+
parent.controlType === CONTROL_BASE_TYPE.LIST && parent.props.headers.includes(instance) ? parent.props.headers : parent.children;
|
|
616
|
+
var index = parentList.findIndex(function(item) {
|
|
617
|
+
return item === instance;
|
|
618
|
+
});
|
|
619
|
+
index > -1 && parentList.splice(index, 1);
|
|
620
|
+
this.store.getFlatInstances();
|
|
621
|
+
this.emit('removed', {
|
|
622
|
+
instance: instance,
|
|
623
|
+
index: index,
|
|
624
|
+
parent: parent
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
key: "replaceInstance",
|
|
630
|
+
value: function replaceInstance(oldInstance, newInstance) {
|
|
631
|
+
var parent = oldInstance.parent;
|
|
632
|
+
if (!parent) {
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
var parentList = // parent instanceof DesignerListControl &&
|
|
636
|
+
parent.controlType === CONTROL_BASE_TYPE.LIST && parent.props.headers.includes(oldInstance) ? parent.props.headers : parent.children;
|
|
637
|
+
var index = parentList.findIndex(function(item) {
|
|
638
|
+
return item === oldInstance;
|
|
639
|
+
});
|
|
640
|
+
index > -1 && parentList.splice(index, 1, newInstance);
|
|
641
|
+
this.store.getFlatInstances();
|
|
642
|
+
}
|
|
643
|
+
},
|
|
644
|
+
{
|
|
645
|
+
key: "updateInstanceType",
|
|
646
|
+
value: /**
|
|
647
|
+
* 修改控件类型
|
|
648
|
+
* */ function updateInstanceType(instance, type) {
|
|
649
|
+
var schema = instance.toSchema();
|
|
650
|
+
var newInstance = this.createInstance(type, {
|
|
651
|
+
id: schema.id,
|
|
652
|
+
props: schema.props
|
|
653
|
+
});
|
|
654
|
+
if (!newInstance) {
|
|
655
|
+
warn("can‘t update instance type to ".concat(type));
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
return newInstance;
|
|
659
|
+
}
|
|
660
|
+
},
|
|
661
|
+
{
|
|
662
|
+
key: "validate",
|
|
663
|
+
value: function validate(messages, ignore) {
|
|
664
|
+
//TODO 校验实例属性,并触发事件 before-validate 和 validated
|
|
665
|
+
return checkSchema(this.store.instance, messages, ignore);
|
|
666
|
+
}
|
|
667
|
+
},
|
|
668
|
+
{
|
|
669
|
+
key: "getCustomControlsInUse",
|
|
670
|
+
value: // 获取使用到的自定义控件
|
|
671
|
+
function getCustomControlsInUse() {
|
|
672
|
+
return this.getInstances().filter(this.assertInstanceIsCustomControl).reduce(function(result, item) {
|
|
673
|
+
if (!result.includes(item.type)) {
|
|
674
|
+
result.push(item.type);
|
|
675
|
+
}
|
|
676
|
+
return result;
|
|
677
|
+
}, []);
|
|
678
|
+
}
|
|
679
|
+
},
|
|
680
|
+
{
|
|
681
|
+
key: "assertInstanceIsCustomControl",
|
|
682
|
+
value: // 判断控件或控件类型是一个自定义控件
|
|
683
|
+
function assertInstanceIsCustomControl(instance) {
|
|
684
|
+
return !isBuiltInControls(isString(instance) ? instance : instance.type);
|
|
685
|
+
}
|
|
686
|
+
},
|
|
687
|
+
{
|
|
688
|
+
key: "judgeControlIsRegistered",
|
|
689
|
+
value: function judgeControlIsRegistered(control) {
|
|
690
|
+
return this.designer.registeredControlTypes.has(control.Designer.controlType);
|
|
691
|
+
}
|
|
692
|
+
},
|
|
693
|
+
{
|
|
694
|
+
key: "register",
|
|
695
|
+
value: function register() {
|
|
696
|
+
for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
|
|
697
|
+
arg[_key] = arguments[_key];
|
|
698
|
+
}
|
|
699
|
+
this.designer.registerControl(arg[0]);
|
|
700
|
+
return this;
|
|
701
|
+
}
|
|
702
|
+
},
|
|
703
|
+
{
|
|
704
|
+
key: "assertInstance",
|
|
705
|
+
value: /**
|
|
706
|
+
* 判断控件的类型,返回当前控件的正确类型
|
|
707
|
+
* */ function assertInstance(instance, types) {
|
|
708
|
+
return isString(types) ? instance.type === types : types.includes(instance.type);
|
|
709
|
+
}
|
|
710
|
+
},
|
|
711
|
+
{
|
|
712
|
+
key: "getInstanceInListControl",
|
|
713
|
+
value: /**
|
|
714
|
+
* 控件在列表控件内,如明细子表或列表控件
|
|
715
|
+
* */ function getInstanceInListControl(instance) {
|
|
716
|
+
var _instance = instance;
|
|
717
|
+
while(_instance){
|
|
718
|
+
// if (_instance instanceof DesignerListControl) {
|
|
719
|
+
if (_instance.controlType === CONTROL_BASE_TYPE.LIST) {
|
|
720
|
+
return true;
|
|
721
|
+
}
|
|
722
|
+
_instance = _instance.parent;
|
|
723
|
+
}
|
|
724
|
+
return false;
|
|
725
|
+
}
|
|
726
|
+
},
|
|
727
|
+
{
|
|
728
|
+
key: "getInstanceParentControl",
|
|
729
|
+
value: function getInstanceParentControl(instance, controlType) {
|
|
730
|
+
if (!instance.parent) {
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
if (this.assertInstance(instance.parent, controlType)) {
|
|
734
|
+
return instance.parent;
|
|
735
|
+
}
|
|
736
|
+
return this.getInstanceParentControl(instance.parent, controlType);
|
|
737
|
+
}
|
|
738
|
+
},
|
|
739
|
+
{
|
|
740
|
+
key: "callSelectedEffect",
|
|
741
|
+
value: function callSelectedEffect(effectKey) {
|
|
742
|
+
var _this = this;
|
|
743
|
+
var payload = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
744
|
+
this.store.selectedInstanceSettingItems.forEach(function(setting) {
|
|
745
|
+
setting.callEffect(effectKey, _this, _object_spread({
|
|
746
|
+
control: _this.store.selected
|
|
747
|
+
}, payload));
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
},
|
|
751
|
+
{
|
|
752
|
+
key: "callSelectedScopeEffect",
|
|
753
|
+
value: function callSelectedScopeEffect() {
|
|
754
|
+
var _this = this;
|
|
755
|
+
var payload = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
756
|
+
this.store.selectedInstanceSettingItems.forEach(function(setting) {
|
|
757
|
+
setting.callScopeEffect(_this, _object_spread({
|
|
758
|
+
control: _this.store.selected
|
|
759
|
+
}, payload));
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
], [
|
|
764
|
+
{
|
|
765
|
+
key: "register",
|
|
766
|
+
value: // 注册外部控件
|
|
767
|
+
function register() {
|
|
768
|
+
for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
|
|
769
|
+
arg[_key] = arguments[_key];
|
|
770
|
+
}
|
|
771
|
+
var _Designer;
|
|
772
|
+
(_Designer = Designer).register.apply(_Designer, _to_consumable_array(arg));
|
|
773
|
+
return this;
|
|
774
|
+
}
|
|
775
|
+
},
|
|
776
|
+
{
|
|
777
|
+
key: "judgeControlIsRegistered",
|
|
778
|
+
value: function judgeControlIsRegistered(control) {
|
|
779
|
+
return Designer.staticRegisteredTypes.has(control.Designer.controlType);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
]);
|
|
783
|
+
return Driven;
|
|
784
|
+
}(Watcher);
|
|
785
|
+
/**
|
|
786
|
+
* 控件事件定义
|
|
787
|
+
* */ _define_property(Driven, "EventLogic", EventLogic);
|
|
788
|
+
export { Driven };
|