@byteluck-fe/model-driven-driven 2.7.0-alpha.2 → 2.7.0-alpha.3
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 +125 -85
- package/dist/esm/Designer.js +125 -70
- package/dist/esm/Driven.js +558 -399
- package/dist/esm/Store.js +148 -91
- package/dist/index.umd.js +3 -3
- package/package.json +5 -5
package/dist/esm/Driven.js
CHANGED
|
@@ -20,6 +20,20 @@ function _classCallCheck(instance, Constructor) {
|
|
|
20
20
|
throw new TypeError("Cannot call a class as a function");
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
+
function _defineProperties(target, props) {
|
|
24
|
+
for(var i = 0; i < props.length; i++){
|
|
25
|
+
var descriptor = props[i];
|
|
26
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
27
|
+
descriptor.configurable = true;
|
|
28
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
29
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
33
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
34
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
35
|
+
return Constructor;
|
|
36
|
+
}
|
|
23
37
|
function _defineProperty(obj, key, value) {
|
|
24
38
|
if (key in obj) {
|
|
25
39
|
Object.defineProperty(obj, key, {
|
|
@@ -196,15 +210,32 @@ var applyingPluginName = "";
|
|
|
196
210
|
_classCallCheck(this, Driven);
|
|
197
211
|
var _this;
|
|
198
212
|
_this = _super.call(this);
|
|
199
|
-
_this
|
|
200
|
-
_this
|
|
201
|
-
_this
|
|
213
|
+
_defineProperty(_assertThisInitialized(_this), "mode", void 0);
|
|
214
|
+
_defineProperty(_assertThisInitialized(_this), "isMounted", false);
|
|
215
|
+
_defineProperty(_assertThisInitialized(_this), "id", genNonDuplicateId(8));
|
|
216
|
+
/**
|
|
217
|
+
* 控件可选的事件
|
|
218
|
+
* */ _defineProperty(_assertThisInitialized(_this), "eventLogic", void 0);
|
|
219
|
+
/**
|
|
220
|
+
* 处理数据存储,存放模型等
|
|
221
|
+
* */ _defineProperty(_assertThisInitialized(_this), "store", void 0);
|
|
222
|
+
/**
|
|
223
|
+
* 额外参数存储
|
|
224
|
+
*/ _defineProperty(_assertThisInitialized(_this), "externalParams", void 0);
|
|
225
|
+
/**
|
|
226
|
+
* 处理instance,和schema存储
|
|
227
|
+
* */ _defineProperty(_assertThisInitialized(_this), "designer", void 0);
|
|
228
|
+
/**
|
|
229
|
+
* 插件数组
|
|
230
|
+
* */ _defineProperty(_assertThisInitialized(_this), "__plugins", void 0);
|
|
231
|
+
_defineProperty(_assertThisInitialized(_this), "__pluginsApplied", false);
|
|
232
|
+
_defineProperty(_assertThisInitialized(_this), "$options", void 0);
|
|
202
233
|
// TODO 拿到schema
|
|
203
|
-
_this
|
|
234
|
+
_defineProperty(_assertThisInitialized(_this), "getSchema", toSchema);
|
|
204
235
|
// TODO 拿到model_bind_info_list
|
|
205
|
-
_this
|
|
236
|
+
_defineProperty(_assertThisInitialized(_this), "getModelBindInfoList", getModelBindInfoList);
|
|
206
237
|
// TODO 拿到permission_controls
|
|
207
|
-
_this
|
|
238
|
+
_defineProperty(_assertThisInitialized(_this), "generatePermissions", generatePermissions);
|
|
208
239
|
_this.$options = Object.freeze(options);
|
|
209
240
|
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;
|
|
210
241
|
_this.eventLogic = new EventLogic();
|
|
@@ -218,417 +249,545 @@ var applyingPluginName = "";
|
|
|
218
249
|
autoMount && _this.mount();
|
|
219
250
|
return _this;
|
|
220
251
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if (!this.__pluginsApplied) {
|
|
231
|
-
this.__plugins.push(plugin);
|
|
232
|
-
}
|
|
233
|
-
return this;
|
|
234
|
-
};
|
|
235
|
-
_proto.applyPlugins = function applyPlugins() {
|
|
236
|
-
var _this = this;
|
|
237
|
-
if (this.__pluginsApplied) return;
|
|
238
|
-
this.__plugins.forEach(function(plugin) {
|
|
239
|
-
try {
|
|
240
|
-
var _plugin_pluginName;
|
|
241
|
-
applyingPluginName = (_plugin_pluginName = plugin.pluginName) !== null && _plugin_pluginName !== void 0 ? _plugin_pluginName : plugin.constructor.name;
|
|
242
|
-
plugin.apply(_this);
|
|
243
|
-
applyingPluginName = "";
|
|
244
|
-
} catch (e) {
|
|
245
|
-
error("".concat(applyingPluginName || plugin.constructor.name, " Plugin apply Error \n ").concat(e));
|
|
252
|
+
_createClass(Driven, [
|
|
253
|
+
{
|
|
254
|
+
key: "mount",
|
|
255
|
+
value: // 挂载
|
|
256
|
+
function mount() {
|
|
257
|
+
var _this_$options = this.$options, _this_$options_plugins = _this_$options.plugins, plugins = _this_$options_plugins === void 0 ? [] : _this_$options_plugins;
|
|
258
|
+
this.__plugins = plugins;
|
|
259
|
+
this.applyPlugins();
|
|
260
|
+
this.isMounted = true;
|
|
246
261
|
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
if (!instance) {
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
this.setSelectedInstanceSetting();
|
|
275
|
-
this.emit("select", {
|
|
276
|
-
instance: instance
|
|
277
|
-
});
|
|
278
|
-
};
|
|
279
|
-
_proto.setSelectedInstanceSetting = function setSelectedInstanceSetting() {
|
|
280
|
-
var _instance_parent;
|
|
281
|
-
var instance = this.store.selected;
|
|
282
|
-
if (!instance) {
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
var setting = this.getControlSetting(instance.type);
|
|
286
|
-
// console.log('iswrap:', instance.parent?.controlType, instance.parent)
|
|
287
|
-
// if (instance.parent instanceof DesignerWrapControl) {
|
|
288
|
-
if (((_instance_parent = instance.parent) === null || _instance_parent === void 0 ? void 0 : _instance_parent.controlType) === CONTROL_BASE_TYPE.WRAP) {
|
|
289
|
-
var _instance_parent1;
|
|
290
|
-
var wrapSetting = this.getControlSetting((_instance_parent1 = instance.parent) === null || _instance_parent1 === void 0 ? void 0 : _instance_parent1.type);
|
|
291
|
-
setting = this.concatSetting(setting, wrapSetting, instance.parent.id);
|
|
292
|
-
}
|
|
293
|
-
this.store.setSelectInstanceSettings(setting);
|
|
294
|
-
this.callSelectedEffect("");
|
|
295
|
-
// 选中触发scopeEffect
|
|
296
|
-
var payload = {
|
|
297
|
-
from: null,
|
|
298
|
-
current: this.store.selectedInstanceDataScopeParent,
|
|
299
|
-
oldParent: null,
|
|
300
|
-
newParent: instance.parent
|
|
301
|
-
};
|
|
302
|
-
this.callSelectedScopeEffect(payload);
|
|
303
|
-
};
|
|
304
|
-
_proto.concatSetting = function concatSetting(settings, otherSettings, settingFromId) {
|
|
305
|
-
var _this = this;
|
|
306
|
-
var _settings_, _otherSettings_, _settings_1, _otherSettings_1;
|
|
307
|
-
var result = settings;
|
|
308
|
-
// tab
|
|
309
|
-
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") {
|
|
310
|
-
var tabSettings = settings;
|
|
311
|
-
var otherTabSettings = otherSettings.slice(0);
|
|
312
|
-
result = tabSettings.map(function(tab, index) {
|
|
313
|
-
var result = new Tab(tab);
|
|
314
|
-
var otherTabIndex = otherTabSettings.findIndex(function(item) {
|
|
315
|
-
return item.title === tab.title;
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
key: "use",
|
|
265
|
+
value: function use(plugin) {
|
|
266
|
+
if (!this.__pluginsApplied) {
|
|
267
|
+
this.__plugins.push(plugin);
|
|
268
|
+
}
|
|
269
|
+
return this;
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
key: "applyPlugins",
|
|
274
|
+
value: function applyPlugins() {
|
|
275
|
+
var _this = this;
|
|
276
|
+
if (this.__pluginsApplied) return;
|
|
277
|
+
this.__plugins.forEach(function(plugin) {
|
|
278
|
+
try {
|
|
279
|
+
var _plugin_pluginName;
|
|
280
|
+
applyingPluginName = (_plugin_pluginName = plugin.pluginName) !== null && _plugin_pluginName !== void 0 ? _plugin_pluginName : plugin.constructor.name;
|
|
281
|
+
plugin.apply(_this);
|
|
282
|
+
applyingPluginName = "";
|
|
283
|
+
} catch (e) {
|
|
284
|
+
error("".concat(applyingPluginName || plugin.constructor.name, " Plugin apply Error \n ").concat(e));
|
|
285
|
+
}
|
|
316
286
|
});
|
|
317
|
-
|
|
318
|
-
|
|
287
|
+
this.__pluginsApplied = true;
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
key: "emit",
|
|
292
|
+
value: function emit(key) {
|
|
293
|
+
for(var _len = arguments.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
|
|
294
|
+
payload[_key - 1] = arguments[_key];
|
|
295
|
+
}
|
|
296
|
+
return _get(_getPrototypeOf(Driven.prototype), "emit", this).call(this, key, payload);
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
key: "on",
|
|
301
|
+
value: function on(key, callback) {
|
|
302
|
+
return _get(_getPrototypeOf(Driven.prototype), "on", this).call(this, key, callback);
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
key: "setInstances",
|
|
307
|
+
value: function setInstances(schema, beforeCreateInstance) {
|
|
308
|
+
this.store.setInstances(this.designer.createControl(Array.isArray(schema) ? schema : [
|
|
309
|
+
schema
|
|
310
|
+
], beforeCreateInstance));
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
key: "beforeSelectInstance",
|
|
315
|
+
value: function beforeSelectInstance() {
|
|
316
|
+
this.store.setSelectInstance(null);
|
|
317
|
+
this.setSelectedFieldItem(null);
|
|
318
|
+
this.store.setSelectInstanceSettings([]);
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
key: "afterSelectInstance",
|
|
323
|
+
value: function afterSelectInstance() {
|
|
324
|
+
var instance = this.store.selected;
|
|
325
|
+
if (!instance) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
this.setSelectedInstanceSetting();
|
|
329
|
+
this.emit("select", {
|
|
330
|
+
instance: instance
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
key: "setSelectedInstanceSetting",
|
|
336
|
+
value: function setSelectedInstanceSetting() {
|
|
337
|
+
var _instance_parent;
|
|
338
|
+
var instance = this.store.selected;
|
|
339
|
+
if (!instance) {
|
|
340
|
+
return;
|
|
319
341
|
}
|
|
320
|
-
var
|
|
321
|
-
|
|
322
|
-
|
|
342
|
+
var setting = this.getControlSetting(instance.type);
|
|
343
|
+
// console.log('iswrap:', instance.parent?.controlType, instance.parent)
|
|
344
|
+
// if (instance.parent instanceof DesignerWrapControl) {
|
|
345
|
+
if (((_instance_parent = instance.parent) === null || _instance_parent === void 0 ? void 0 : _instance_parent.controlType) === CONTROL_BASE_TYPE.WRAP) {
|
|
346
|
+
var _instance_parent1;
|
|
347
|
+
var wrapSetting = this.getControlSetting((_instance_parent1 = instance.parent) === null || _instance_parent1 === void 0 ? void 0 : _instance_parent1.type);
|
|
348
|
+
setting = this.concatSetting(setting, wrapSetting, instance.parent.id);
|
|
349
|
+
}
|
|
350
|
+
this.store.setSelectInstanceSettings(setting);
|
|
351
|
+
this.callSelectedEffect("");
|
|
352
|
+
// 选中触发scopeEffect
|
|
353
|
+
var payload = {
|
|
354
|
+
from: null,
|
|
355
|
+
current: this.store.selectedInstanceDataScopeParent,
|
|
356
|
+
oldParent: null,
|
|
357
|
+
newParent: instance.parent
|
|
358
|
+
};
|
|
359
|
+
this.callSelectedScopeEffect(payload);
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
key: "concatSetting",
|
|
364
|
+
value: function concatSetting(settings, otherSettings, settingFromId) {
|
|
365
|
+
var _this = this;
|
|
366
|
+
var _settings_, _otherSettings_, _settings_1, _otherSettings_1;
|
|
367
|
+
var result = settings;
|
|
368
|
+
// tab
|
|
369
|
+
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") {
|
|
370
|
+
var tabSettings = settings;
|
|
371
|
+
var otherTabSettings = otherSettings.slice(0);
|
|
372
|
+
result = tabSettings.map(function(tab, index) {
|
|
373
|
+
var result = new Tab(tab);
|
|
374
|
+
var otherTabIndex = otherTabSettings.findIndex(function(item) {
|
|
375
|
+
return item.title === tab.title;
|
|
376
|
+
});
|
|
377
|
+
if (otherTabIndex === -1) {
|
|
378
|
+
return result;
|
|
379
|
+
}
|
|
380
|
+
var otherTab = otherTabSettings.splice(otherTabIndex, 1)[0];
|
|
381
|
+
if (otherTab) {
|
|
382
|
+
result.items = _toConsumableArray(_this.formatGroupSetting(otherTab.items, settingFromId)).concat(_toConsumableArray(result.items));
|
|
383
|
+
}
|
|
384
|
+
return result;
|
|
385
|
+
});
|
|
386
|
+
if (otherTabSettings.length) {
|
|
387
|
+
result = _toConsumableArray(result).concat(_toConsumableArray(otherTabSettings.map(function(item) {
|
|
388
|
+
return _this.formatGroupSetting(item, settingFromId);
|
|
389
|
+
})));
|
|
390
|
+
}
|
|
391
|
+
// group
|
|
392
|
+
} 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") {
|
|
393
|
+
var groupSettings = settings;
|
|
394
|
+
var otherGroupSettings = otherSettings;
|
|
395
|
+
result = _toConsumableArray(this.formatGroupSetting(otherGroupSettings, settingFromId)).concat(_toConsumableArray(groupSettings));
|
|
396
|
+
} else {
|
|
397
|
+
// 一个是tab,一个是group,暂时不支持
|
|
323
398
|
}
|
|
324
399
|
return result;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
400
|
+
}
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
key: "formatGroupSetting",
|
|
404
|
+
value: function formatGroupSetting(tab, fromId) {
|
|
405
|
+
if (isArray(tab)) {
|
|
406
|
+
return tab.map(function(item) {
|
|
407
|
+
var group = new Group(item);
|
|
408
|
+
group.fromId = fromId;
|
|
409
|
+
return group;
|
|
410
|
+
});
|
|
411
|
+
} else {
|
|
412
|
+
var result = new Tab(tab);
|
|
413
|
+
result.items = this.formatGroupSetting(result.items, fromId);
|
|
414
|
+
return result;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
key: "setControlConfig",
|
|
420
|
+
value: function setControlConfig() {
|
|
421
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
422
|
+
args[_key] = arguments[_key];
|
|
423
|
+
}
|
|
424
|
+
var _this_designer;
|
|
425
|
+
return (_this_designer = this.designer).registerControlConfig.apply(_this_designer, _toConsumableArray(args));
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
key: "getControlConfig",
|
|
430
|
+
value: function getControlConfig(control) {
|
|
431
|
+
return this.designer.getControlConfig(control);
|
|
432
|
+
}
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
key: "getControlSetting",
|
|
436
|
+
value: function getControlSetting(type) {
|
|
437
|
+
var settingInit = this.designer.getControlSetting(type);
|
|
438
|
+
if (!settingInit) {
|
|
439
|
+
return [];
|
|
440
|
+
}
|
|
441
|
+
return initSettings(settingInit);
|
|
442
|
+
}
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
key: "selectInstance",
|
|
446
|
+
value: function selectInstance(instance) {
|
|
447
|
+
// 先清空上一次的store
|
|
448
|
+
this.beforeSelectInstance();
|
|
449
|
+
// 选中一个控件
|
|
450
|
+
this.store.setSelectInstance(instance);
|
|
451
|
+
// 针对这一次选中的控件初始化一些内容,并触发事件
|
|
452
|
+
this.afterSelectInstance();
|
|
453
|
+
}
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
key: "setSelectedFieldItem",
|
|
457
|
+
value: function setSelectedFieldItem(fieldItem) {
|
|
458
|
+
this.store.setSelectedFieldItem(fieldItem);
|
|
459
|
+
this.callSelectedEffect("dataBind", {
|
|
460
|
+
fieldItem: fieldItem
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
key: "moveStart",
|
|
466
|
+
value: function moveStart(instance) {
|
|
467
|
+
// 移动之前,记录控件原始的位置和父级
|
|
468
|
+
var _instance = this.getInstance(instance);
|
|
469
|
+
if (_instance) {
|
|
470
|
+
this.store.setMovingInstance(_instance);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
},
|
|
474
|
+
{
|
|
475
|
+
key: "moveEnd",
|
|
476
|
+
value: function moveEnd() {
|
|
477
|
+
var instance = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.store.movingInstance;
|
|
478
|
+
var _this_store_selected;
|
|
479
|
+
if (instance === null) return;
|
|
480
|
+
var _instance = this.getInstance(instance);
|
|
481
|
+
if (!_instance) return;
|
|
482
|
+
/*
|
|
399
483
|
移动之后,拿到控件新的位置,并触发事件, 如果是新增的控件的话,就没有原始位置和父级,
|
|
400
484
|
事件是否区分move和add
|
|
401
485
|
move是从主表移动到子表或子表移动到主表才触发,还是所有移动都触发
|
|
402
486
|
*/ var oldDataScopeParent = this.store.movingInstanceOldDataScopeParent;
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
};
|
|
428
|
-
_proto.createInstance = function createInstance(type, initSchema) {
|
|
429
|
-
return this.designer.createControlInstance(type, initSchema);
|
|
430
|
-
};
|
|
431
|
-
_proto.getInstance = function getInstance(instanceId) {
|
|
432
|
-
// if (instanceId instanceof DesignerControl) {
|
|
433
|
-
// return instanceId
|
|
434
|
-
// }
|
|
435
|
-
// return this.store.instanceIdMap.get(instanceId)
|
|
436
|
-
if (typeof instanceId === "string") {
|
|
437
|
-
return this.store.instanceIdMap.get(instanceId);
|
|
438
|
-
}
|
|
439
|
-
return 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 _this_store_selected;
|
|
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 === ((_this_store_selected = this.store.selected) === null || _this_store_selected === void 0 ? void 0 : _this_store_selected.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);
|
|
487
|
+
var newDataScopeParent = findInstanceDataScopeParent(_instance);
|
|
488
|
+
var oldParent = this.store.movingInstanceOldParent;
|
|
489
|
+
var newParent = _instance.parent;
|
|
490
|
+
// 移动之后清空movingInstance
|
|
491
|
+
this.store.setMovingInstance(null);
|
|
492
|
+
if (_instance.id !== ((_this_store_selected = this.store.selected) === null || _this_store_selected === void 0 ? void 0 : _this_store_selected.id)) {
|
|
493
|
+
this.selectInstance(_instance);
|
|
494
|
+
} else {
|
|
495
|
+
this.store.setSelectInstance(_instance);
|
|
496
|
+
}
|
|
497
|
+
this.store.getFlatInstances();
|
|
498
|
+
// 结束以后
|
|
499
|
+
var payload = {
|
|
500
|
+
from: oldDataScopeParent,
|
|
501
|
+
current: newDataScopeParent,
|
|
502
|
+
oldParent: oldParent,
|
|
503
|
+
newParent: newParent
|
|
504
|
+
};
|
|
505
|
+
this.callSelectedScopeEffect(payload);
|
|
506
|
+
if (oldParent) {
|
|
507
|
+
this.emit("moved", _objectSpread({}, payload));
|
|
508
|
+
} else {
|
|
509
|
+
this.emit("joined", _objectSpread({}, payload));
|
|
510
|
+
}
|
|
486
511
|
}
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
512
|
+
},
|
|
513
|
+
{
|
|
514
|
+
key: "createInstance",
|
|
515
|
+
value: function createInstance(type, initSchema) {
|
|
516
|
+
return this.designer.createControlInstance(type, initSchema);
|
|
517
|
+
}
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
key: "getInstance",
|
|
521
|
+
value: function getInstance(instanceId) {
|
|
522
|
+
// if (instanceId instanceof DesignerControl) {
|
|
523
|
+
// return instanceId
|
|
524
|
+
// }
|
|
525
|
+
// return this.store.instanceIdMap.get(instanceId)
|
|
526
|
+
if (typeof instanceId === "string") {
|
|
527
|
+
return this.store.instanceIdMap.get(instanceId);
|
|
528
|
+
}
|
|
529
|
+
return instanceId;
|
|
530
|
+
}
|
|
531
|
+
},
|
|
532
|
+
{
|
|
533
|
+
key: "getInstances",
|
|
534
|
+
value: function getInstances() {
|
|
535
|
+
return this.store.flatInstances;
|
|
536
|
+
}
|
|
537
|
+
},
|
|
538
|
+
{
|
|
539
|
+
key: "getInstancesFromType",
|
|
540
|
+
value: function getInstancesFromType(type) {
|
|
541
|
+
return this.getInstances().filter(function(item) {
|
|
542
|
+
return item.type === type;
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
},
|
|
546
|
+
{
|
|
547
|
+
key: "getDataScopeInstances",
|
|
548
|
+
value: function getDataScopeInstances() {
|
|
549
|
+
return this.store.selectedDataScopeFlatInstances;
|
|
550
|
+
}
|
|
551
|
+
},
|
|
552
|
+
{
|
|
553
|
+
key: "getDataScopeInstancesFromType",
|
|
554
|
+
value: function getDataScopeInstancesFromType(type) {
|
|
555
|
+
return this.getDataScopeInstances().filter(function(item) {
|
|
556
|
+
return item.type === type;
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
},
|
|
560
|
+
{
|
|
561
|
+
key: "updateInstancePropValue",
|
|
562
|
+
value: function updateInstancePropValue(instance, propName, value, payload) {
|
|
563
|
+
var _this_store_selected;
|
|
564
|
+
var result = updateValueFromKeys(instance.props, propName, value);
|
|
565
|
+
if (!result) {
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
// 修改dataBind的时候要更新 fieldCodeMap
|
|
569
|
+
if (propName.startsWith("dataBind")) {
|
|
570
|
+
this.store.updateDataFieldCodeMap(instance);
|
|
571
|
+
}
|
|
572
|
+
if (instance.id === ((_this_store_selected = this.store.selected) === null || _this_store_selected === void 0 ? void 0 : _this_store_selected.id)) {
|
|
573
|
+
this.callSelectedEffect(propName, payload);
|
|
574
|
+
}
|
|
575
|
+
this.emit("updated", {
|
|
576
|
+
instance: instance,
|
|
577
|
+
propName: propName,
|
|
578
|
+
value: value
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
key: "updateInstanceProps",
|
|
584
|
+
value: function updateInstanceProps(instance, props, payload) {
|
|
585
|
+
var prevKey = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "";
|
|
586
|
+
var _this = this;
|
|
587
|
+
Object.entries(props).forEach(function(param) {
|
|
588
|
+
var _param = _slicedToArray(param, 2), key = _param[0], value = _param[1];
|
|
589
|
+
var propName = "".concat(prevKey ? prevKey + "." : "").concat(key);
|
|
590
|
+
if (isObject(value)) {
|
|
591
|
+
_this.updateInstanceProps(instance, value, payload, propName);
|
|
592
|
+
} else {
|
|
593
|
+
_this.updateInstancePropValue(instance, propName, value, payload);
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
},
|
|
598
|
+
{
|
|
599
|
+
key: "setInstance",
|
|
600
|
+
value: function setInstance(instance, propName, value, payload) {
|
|
601
|
+
if (isString(propName)) {
|
|
602
|
+
this.updateInstancePropValue(instance, String(propName), value, payload);
|
|
603
|
+
} else {
|
|
604
|
+
this.updateInstanceProps(instance, propName, value);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
},
|
|
608
|
+
{
|
|
609
|
+
key: "removeInstance",
|
|
610
|
+
value: /**
|
|
497
611
|
* 删除控件
|
|
498
|
-
* */
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
612
|
+
* */ function removeInstance(instance) {
|
|
613
|
+
// 删除实例,并触发事件 removed
|
|
614
|
+
var parent = instance.parent;
|
|
615
|
+
if (!parent) {
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
var parentList = // parent instanceof DesignerListControl &&
|
|
619
|
+
parent.controlType === CONTROL_BASE_TYPE.LIST && parent.props.headers.includes(instance) ? parent.props.headers : parent.children;
|
|
620
|
+
var index = parentList.findIndex(function(item) {
|
|
621
|
+
return item === instance;
|
|
622
|
+
});
|
|
623
|
+
index > -1 && parentList.splice(index, 1);
|
|
624
|
+
this.store.getFlatInstances();
|
|
625
|
+
this.emit("removed", {
|
|
626
|
+
instance: instance,
|
|
627
|
+
index: index,
|
|
628
|
+
parent: parent
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
},
|
|
632
|
+
{
|
|
633
|
+
key: "replaceInstance",
|
|
634
|
+
value: function replaceInstance(oldInstance, newInstance) {
|
|
635
|
+
var parent = oldInstance.parent;
|
|
636
|
+
if (!parent) {
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
var parentList = // parent instanceof DesignerListControl &&
|
|
640
|
+
parent.controlType === CONTROL_BASE_TYPE.LIST && parent.props.headers.includes(oldInstance) ? parent.props.headers : parent.children;
|
|
641
|
+
var index = parentList.findIndex(function(item) {
|
|
642
|
+
return item === oldInstance;
|
|
643
|
+
});
|
|
644
|
+
index > -1 && parentList.splice(index, 1, newInstance);
|
|
645
|
+
this.store.getFlatInstances();
|
|
646
|
+
}
|
|
647
|
+
},
|
|
648
|
+
{
|
|
649
|
+
key: "updateInstanceType",
|
|
650
|
+
value: /**
|
|
531
651
|
* 修改控件类型
|
|
532
|
-
* */
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
652
|
+
* */ function updateInstanceType(instance, type) {
|
|
653
|
+
var schema = instance.toSchema();
|
|
654
|
+
var newInstance = this.createInstance(type, {
|
|
655
|
+
id: schema.id,
|
|
656
|
+
props: schema.props
|
|
657
|
+
});
|
|
658
|
+
if (!newInstance) {
|
|
659
|
+
warn("can‘t update instance type to ".concat(type));
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
return newInstance;
|
|
663
|
+
}
|
|
664
|
+
},
|
|
665
|
+
{
|
|
666
|
+
key: "validate",
|
|
667
|
+
value: function validate(messages, ignore) {
|
|
668
|
+
//TODO 校验实例属性,并触发事件 before-validate 和 validated
|
|
669
|
+
return checkSchema(this.store.instance, messages, ignore);
|
|
670
|
+
}
|
|
671
|
+
},
|
|
672
|
+
{
|
|
673
|
+
key: "getCustomControlsInUse",
|
|
674
|
+
value: // 获取使用到的自定义控件
|
|
675
|
+
function getCustomControlsInUse() {
|
|
676
|
+
return this.getInstances().filter(this.assertInstanceIsCustomControl).reduce(function(result, item) {
|
|
677
|
+
if (!result.includes(item.type)) {
|
|
678
|
+
result.push(item.type);
|
|
679
|
+
}
|
|
680
|
+
return result;
|
|
681
|
+
}, []);
|
|
682
|
+
}
|
|
683
|
+
},
|
|
684
|
+
{
|
|
685
|
+
key: "assertInstanceIsCustomControl",
|
|
686
|
+
value: // 判断控件或控件类型是一个自定义控件
|
|
687
|
+
function assertInstanceIsCustomControl(instance) {
|
|
688
|
+
return !isBuiltInControls(isString(instance) ? instance : instance.type);
|
|
689
|
+
}
|
|
690
|
+
},
|
|
691
|
+
{
|
|
692
|
+
key: "judgeControlIsRegistered",
|
|
693
|
+
value: function judgeControlIsRegistered(control) {
|
|
694
|
+
return this.designer.registeredControlTypes.has(control.Designer.controlType);
|
|
695
|
+
}
|
|
696
|
+
},
|
|
697
|
+
{
|
|
698
|
+
key: "register",
|
|
699
|
+
value: function register() {
|
|
700
|
+
for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
|
|
701
|
+
arg[_key] = arguments[_key];
|
|
702
|
+
}
|
|
703
|
+
var _this_designer;
|
|
704
|
+
(_this_designer = this.designer).registerControl.apply(_this_designer, _toConsumableArray(arg));
|
|
705
|
+
return this;
|
|
706
|
+
}
|
|
707
|
+
},
|
|
708
|
+
{
|
|
709
|
+
key: "assertInstance",
|
|
710
|
+
value: /**
|
|
573
711
|
* 判断控件的类型,返回当前控件的正确类型
|
|
574
|
-
* */
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
712
|
+
* */ function assertInstance(instance, types) {
|
|
713
|
+
return isString(types) ? instance.type === types : types.includes(instance.type);
|
|
714
|
+
}
|
|
715
|
+
},
|
|
716
|
+
{
|
|
717
|
+
key: "getInstanceInListControl",
|
|
718
|
+
value: /**
|
|
578
719
|
* 控件在列表控件内,如明细子表或列表控件
|
|
579
|
-
* */
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
720
|
+
* */ function getInstanceInListControl(instance) {
|
|
721
|
+
var _instance = instance;
|
|
722
|
+
while(_instance){
|
|
723
|
+
// if (_instance instanceof DesignerListControl) {
|
|
724
|
+
if (_instance.controlType === CONTROL_BASE_TYPE.LIST) {
|
|
725
|
+
return true;
|
|
726
|
+
}
|
|
727
|
+
_instance = _instance.parent;
|
|
728
|
+
}
|
|
729
|
+
return false;
|
|
730
|
+
}
|
|
731
|
+
},
|
|
732
|
+
{
|
|
733
|
+
key: "getInstanceParentControl",
|
|
734
|
+
value: function getInstanceParentControl(instance, controlType) {
|
|
735
|
+
if (!instance.parent) {
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
if (this.assertInstance(instance.parent, controlType)) {
|
|
739
|
+
return instance.parent;
|
|
740
|
+
}
|
|
741
|
+
return this.getInstanceParentControl(instance.parent, controlType);
|
|
742
|
+
}
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
key: "callSelectedEffect",
|
|
746
|
+
value: function callSelectedEffect(effectKey) {
|
|
747
|
+
var payload = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
748
|
+
var _this = this;
|
|
749
|
+
this.store.selectedInstanceSettingItems.forEach(function(setting) {
|
|
750
|
+
setting.callEffect(effectKey, _this, _objectSpread({
|
|
751
|
+
control: _this.store.selected
|
|
752
|
+
}, payload));
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
},
|
|
756
|
+
{
|
|
757
|
+
key: "callSelectedScopeEffect",
|
|
758
|
+
value: function callSelectedScopeEffect() {
|
|
759
|
+
var payload = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
760
|
+
var _this = this;
|
|
761
|
+
this.store.selectedInstanceSettingItems.forEach(function(setting) {
|
|
762
|
+
setting.callScopeEffect(_this, _objectSpread({
|
|
763
|
+
control: _this.store.selected
|
|
764
|
+
}, payload));
|
|
765
|
+
});
|
|
766
|
+
}
|
|
596
767
|
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
}
|
|
615
|
-
});
|
|
616
|
-
};
|
|
617
|
-
// 注册外部控件
|
|
618
|
-
Driven.register = function register() {
|
|
619
|
-
for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
|
|
620
|
-
arg[_key] = arguments[_key];
|
|
768
|
+
], [
|
|
769
|
+
{
|
|
770
|
+
key: "register",
|
|
771
|
+
value: // 注册外部控件
|
|
772
|
+
function register() {
|
|
773
|
+
for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
|
|
774
|
+
arg[_key] = arguments[_key];
|
|
775
|
+
}
|
|
776
|
+
var _Designer;
|
|
777
|
+
(_Designer = Designer).register.apply(_Designer, _toConsumableArray(arg));
|
|
778
|
+
return this;
|
|
779
|
+
}
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
key: "judgeControlIsRegistered",
|
|
783
|
+
value: function judgeControlIsRegistered(control) {
|
|
784
|
+
return Designer.staticRegisteredTypes.has(control.Designer.controlType);
|
|
785
|
+
}
|
|
621
786
|
}
|
|
622
|
-
|
|
623
|
-
(_Designer = Designer).register.apply(_Designer, _toConsumableArray(arg));
|
|
624
|
-
return this;
|
|
625
|
-
};
|
|
626
|
-
Driven.judgeControlIsRegistered = function judgeControlIsRegistered(control) {
|
|
627
|
-
return Designer.staticRegisteredTypes.has(control.Designer.controlType);
|
|
628
|
-
};
|
|
787
|
+
]);
|
|
629
788
|
return Driven;
|
|
630
789
|
}(Watcher);
|
|
631
790
|
/**
|
|
632
791
|
* 控件事件定义
|
|
633
|
-
* */ Driven
|
|
792
|
+
* */ _defineProperty(Driven, "EventLogic", EventLogic);
|
|
634
793
|
export { Driven };
|