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

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