@mediusinc/mng-commons 5.0.0 → 5.0.1

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.
@@ -1656,6 +1656,7 @@ class AFieldGroupDescriptor extends AGenericFieldDescriptor {
1656
1656
  class FieldTabGroupDescriptor extends AFieldGroupDescriptor {
1657
1657
  constructor(editor, name) {
1658
1658
  super(editor, name);
1659
+ this._fields = [];
1659
1660
  }
1660
1661
  get fields() {
1661
1662
  return this._fields;
@@ -1667,10 +1668,10 @@ class FieldTabGroupDescriptor extends AFieldGroupDescriptor {
1667
1668
  this._fields.push(field);
1668
1669
  return this;
1669
1670
  }
1670
- copy() {
1671
+ copy(skipFields = false) {
1671
1672
  const tab = new FieldTabGroupDescriptor(this._editor, this.name.substring(this.baseName.length));
1672
1673
  tab._title = this._title;
1673
- tab._fields = this.fields.map(f => f.copy());
1674
+ tab._fields = this.fields.map(f => f.copy(skipFields));
1674
1675
  tab._validations = this.validations.map(v => v.copy());
1675
1676
  return tab;
1676
1677
  }
@@ -1700,11 +1701,13 @@ class FieldGroupDescriptor extends AFieldGroupDescriptor {
1700
1701
  this._type = FieldGroupTypeEnum.Logical;
1701
1702
  return this;
1702
1703
  }
1703
- copy() {
1704
+ copy(skipFields = false) {
1704
1705
  const group = new FieldGroupDescriptor(this._editor, this.name.substring(this.baseName.length));
1705
1706
  group._type = this._type;
1706
1707
  group._title = this._title;
1707
- group._fields = this.fields.map(f => f.copy());
1708
+ if (!skipFields) {
1709
+ group._fields = this.fields.map(f => f.copy());
1710
+ }
1708
1711
  group._validations = this.validations.map(v => v.copy());
1709
1712
  return group;
1710
1713
  }
@@ -2853,17 +2856,32 @@ class EditorDescriptorInst {
2853
2856
  */
2854
2857
  copy() {
2855
2858
  const editor = new EditorDescriptorInst(this.model.copy(), this.tableviewEditorType);
2859
+ editor._fields = this._fields.map(f => f.copy());
2860
+ const fieldsMap = editor.fields.reduce((map, field) => {
2861
+ map.set(field.property, field);
2862
+ return map;
2863
+ }, new Map());
2856
2864
  for (const tabGroup of this._tabs) {
2857
- editor.createTabGroupDescriptor(tabGroup.copy());
2858
- }
2859
- for (const tabGroup of editor._tabs) {
2860
- for (const fieldGroup of tabGroup.fields) {
2861
- editor._fields.push(...fieldGroup.fields);
2865
+ const tabGroupCopy = tabGroup.copy(true);
2866
+ // set fields
2867
+ for (let i = 0; i < tabGroup.fields.length; i++) {
2868
+ const group = tabGroup.fields[i];
2869
+ const groupCopy = tabGroupCopy.fields[i];
2870
+ for (let j = 0; j < group.fields.length; j++) {
2871
+ const fieldCopy = fieldsMap.get(group.fields[j].property);
2872
+ if (!fieldCopy) {
2873
+ throw new CommonsInternalError(`Could not copy editor descriptor: field '${group.fields[j].property}' (tab '${tabGroup.name}', group ${group.name}').`);
2874
+ }
2875
+ groupCopy.addField(fieldCopy);
2876
+ }
2877
+ editor._groups.push(groupCopy);
2862
2878
  }
2863
- editor._groups.push(...tabGroup.fields);
2879
+ editor._tabs.push(tabGroupCopy);
2880
+ }
2881
+ editor._currentTabGroup = editor._tabs.length > 0 ? editor._tabs[editor._tabs.length - 1] : undefined;
2882
+ if (editor._currentTabGroup) {
2883
+ editor._currentGroup = editor._currentTabGroup.fields.length > 0 ? editor._currentTabGroup.fields[editor._currentTabGroup.fields.length - 1] : undefined;
2864
2884
  }
2865
- editor._currentTabGroup = editor._tabs[editor._tabs.length - 1];
2866
- editor._currentGroup = editor._currentTabGroup.fields[editor._currentTabGroup.fields.length - 1];
2867
2885
  editor._disabled = this._disabled;
2868
2886
  return editor;
2869
2887
  }