dockview-core 1.8.3 → 1.8.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.
Files changed (95) hide show
  1. package/dist/cjs/dockview/components/titlebar/tabsContainer.d.ts +4 -0
  2. package/dist/cjs/dockview/components/titlebar/tabsContainer.d.ts.map +1 -1
  3. package/dist/cjs/dockview/components/titlebar/tabsContainer.js +16 -0
  4. package/dist/cjs/dockview/components/titlebar/tabsContainer.js.map +1 -1
  5. package/dist/cjs/dockview/dockviewComponent.d.ts +1 -1
  6. package/dist/cjs/dockview/dockviewComponent.d.ts.map +1 -1
  7. package/dist/cjs/dockview/dockviewComponent.js +232 -78
  8. package/dist/cjs/dockview/dockviewComponent.js.map +1 -1
  9. package/dist/cjs/dockview/dockviewGroupPanelModel.d.ts +1 -0
  10. package/dist/cjs/dockview/dockviewGroupPanelModel.d.ts.map +1 -1
  11. package/dist/cjs/dockview/dockviewGroupPanelModel.js +10 -0
  12. package/dist/cjs/dockview/dockviewGroupPanelModel.js.map +1 -1
  13. package/dist/cjs/dockview/options.d.ts +1 -0
  14. package/dist/cjs/dockview/options.d.ts.map +1 -1
  15. package/dist/cjs/dockview/options.js.map +1 -1
  16. package/dist/cjs/gridview/baseComponentGridview.d.ts +1 -1
  17. package/dist/cjs/gridview/baseComponentGridview.d.ts.map +1 -1
  18. package/dist/cjs/gridview/baseComponentGridview.js.map +1 -1
  19. package/dist/cjs/gridview/branchNode.d.ts.map +1 -1
  20. package/dist/cjs/gridview/branchNode.js +1 -0
  21. package/dist/cjs/gridview/branchNode.js.map +1 -1
  22. package/dist/cjs/gridview/gridview.d.ts.map +1 -1
  23. package/dist/cjs/gridview/gridview.js +8 -0
  24. package/dist/cjs/gridview/gridview.js.map +1 -1
  25. package/dist/cjs/gridview/gridviewComponent.d.ts.map +1 -1
  26. package/dist/cjs/gridview/gridviewComponent.js +71 -39
  27. package/dist/cjs/gridview/gridviewComponent.js.map +1 -1
  28. package/dist/cjs/index.d.ts +1 -0
  29. package/dist/cjs/index.d.ts.map +1 -1
  30. package/dist/cjs/index.js.map +1 -1
  31. package/dist/cjs/resizable.d.ts.map +1 -1
  32. package/dist/cjs/resizable.js +8 -0
  33. package/dist/cjs/resizable.js.map +1 -1
  34. package/dist/cjs/splitview/splitview.d.ts.map +1 -1
  35. package/dist/cjs/splitview/splitview.js +11 -1
  36. package/dist/cjs/splitview/splitview.js.map +1 -1
  37. package/dist/dockview-core.amd.js +212 -84
  38. package/dist/dockview-core.amd.js.map +1 -1
  39. package/dist/dockview-core.amd.min.js +2 -2
  40. package/dist/dockview-core.amd.min.js.map +1 -1
  41. package/dist/dockview-core.amd.min.noStyle.js +2 -2
  42. package/dist/dockview-core.amd.min.noStyle.js.map +1 -1
  43. package/dist/dockview-core.amd.noStyle.js +212 -84
  44. package/dist/dockview-core.amd.noStyle.js.map +1 -1
  45. package/dist/dockview-core.cjs.js +212 -84
  46. package/dist/dockview-core.cjs.js.map +1 -1
  47. package/dist/dockview-core.esm.js +212 -84
  48. package/dist/dockview-core.esm.js.map +1 -1
  49. package/dist/dockview-core.esm.min.js +2 -2
  50. package/dist/dockview-core.esm.min.js.map +1 -1
  51. package/dist/dockview-core.js +212 -84
  52. package/dist/dockview-core.js.map +1 -1
  53. package/dist/dockview-core.min.js +2 -2
  54. package/dist/dockview-core.min.js.map +1 -1
  55. package/dist/dockview-core.min.noStyle.js +2 -2
  56. package/dist/dockview-core.min.noStyle.js.map +1 -1
  57. package/dist/dockview-core.noStyle.js +212 -84
  58. package/dist/dockview-core.noStyle.js.map +1 -1
  59. package/dist/esm/dockview/components/titlebar/tabsContainer.d.ts +4 -0
  60. package/dist/esm/dockview/components/titlebar/tabsContainer.d.ts.map +1 -1
  61. package/dist/esm/dockview/components/titlebar/tabsContainer.js +16 -0
  62. package/dist/esm/dockview/components/titlebar/tabsContainer.js.map +1 -1
  63. package/dist/esm/dockview/dockviewComponent.d.ts +1 -1
  64. package/dist/esm/dockview/dockviewComponent.d.ts.map +1 -1
  65. package/dist/esm/dockview/dockviewComponent.js +161 -47
  66. package/dist/esm/dockview/dockviewComponent.js.map +1 -1
  67. package/dist/esm/dockview/dockviewGroupPanelModel.d.ts +1 -0
  68. package/dist/esm/dockview/dockviewGroupPanelModel.d.ts.map +1 -1
  69. package/dist/esm/dockview/dockviewGroupPanelModel.js +10 -0
  70. package/dist/esm/dockview/dockviewGroupPanelModel.js.map +1 -1
  71. package/dist/esm/dockview/options.d.ts +1 -0
  72. package/dist/esm/dockview/options.d.ts.map +1 -1
  73. package/dist/esm/dockview/options.js.map +1 -1
  74. package/dist/esm/gridview/baseComponentGridview.d.ts +1 -1
  75. package/dist/esm/gridview/baseComponentGridview.d.ts.map +1 -1
  76. package/dist/esm/gridview/baseComponentGridview.js.map +1 -1
  77. package/dist/esm/gridview/branchNode.d.ts.map +1 -1
  78. package/dist/esm/gridview/branchNode.js +1 -0
  79. package/dist/esm/gridview/branchNode.js.map +1 -1
  80. package/dist/esm/gridview/gridview.d.ts.map +1 -1
  81. package/dist/esm/gridview/gridview.js +8 -0
  82. package/dist/esm/gridview/gridview.js.map +1 -1
  83. package/dist/esm/gridview/gridviewComponent.d.ts.map +1 -1
  84. package/dist/esm/gridview/gridviewComponent.js +56 -35
  85. package/dist/esm/gridview/gridviewComponent.js.map +1 -1
  86. package/dist/esm/index.d.ts +1 -0
  87. package/dist/esm/index.d.ts.map +1 -1
  88. package/dist/esm/index.js.map +1 -1
  89. package/dist/esm/resizable.d.ts.map +1 -1
  90. package/dist/esm/resizable.js +8 -0
  91. package/dist/esm/resizable.js.map +1 -1
  92. package/dist/esm/splitview/splitview.d.ts.map +1 -1
  93. package/dist/esm/splitview/splitview.js +11 -1
  94. package/dist/esm/splitview/splitview.js.map +1 -1
  95. package/package.json +3 -4
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * dockview-core
3
- * @version 1.8.3
3
+ * @version 1.8.4
4
4
  * @link https://github.com/mathuo/dockview
5
5
  * @license MIT
6
6
  */
@@ -898,7 +898,17 @@ define(['exports'], (function (exports) { 'use strict';
898
898
  size = typeof size === 'number' ? size : item.size;
899
899
  size = clamp(size, item.minimumSize, item.maximumSize);
900
900
  item.size = size;
901
- this.relayout([index]);
901
+ const indexes = range(this.viewItems.length).filter((i) => i !== index);
902
+ const lowPriorityIndexes = [
903
+ ...indexes.filter((i) => this.viewItems[i].priority === exports.LayoutPriority.Low),
904
+ index,
905
+ ];
906
+ const highPriorityIndexes = indexes.filter((i) => this.viewItems[i].priority === exports.LayoutPriority.High);
907
+ /**
908
+ * add this view we are changing to the low-index list since we have determined the size
909
+ * here and don't want it changed
910
+ */
911
+ this.relayout([...lowPriorityIndexes, index], highPriorityIndexes);
902
912
  }
903
913
  addView(view, size = { type: 'distribute' }, index = this.viewItems.length, skipLayout) {
904
914
  const container = document.createElement('div');
@@ -1655,6 +1665,7 @@ define(['exports'], (function (exports) { 'use strict';
1655
1665
  orientation: this.orientation,
1656
1666
  descriptor,
1657
1667
  proportionalLayout,
1668
+ styles,
1658
1669
  });
1659
1670
  }
1660
1671
  this.addDisposables(this._onDidChange, this.splitview.onDidSashEnd(() => {
@@ -2166,6 +2177,14 @@ define(['exports'], (function (exports) { 'use strict';
2166
2177
  const child = sibling.children[i];
2167
2178
  grandParent.addChild(child, child.size, parentIndex + i);
2168
2179
  }
2180
+ /**
2181
+ * clean down the branch node since we need to dipose of it and
2182
+ * when .dispose() it called on a branch it will dispose of any
2183
+ * views it is holding onto.
2184
+ */
2185
+ while (sibling.children.length > 0) {
2186
+ sibling.removeChild(0);
2187
+ }
2169
2188
  }
2170
2189
  else {
2171
2190
  // otherwise create a new leaf node and add that to the grandparent
@@ -3224,6 +3243,19 @@ define(['exports'], (function (exports) { 'use strict';
3224
3243
  this.leftActions = element;
3225
3244
  }
3226
3245
  }
3246
+ setPrefixActionsElement(element) {
3247
+ if (this.preActions === element) {
3248
+ return;
3249
+ }
3250
+ if (this.preActions) {
3251
+ this.preActions.remove();
3252
+ this.preActions = undefined;
3253
+ }
3254
+ if (element) {
3255
+ this.preActionsContainer.appendChild(element);
3256
+ this.preActions = element;
3257
+ }
3258
+ }
3227
3259
  get element() {
3228
3260
  return this._element;
3229
3261
  }
@@ -3264,9 +3296,12 @@ define(['exports'], (function (exports) { 'use strict';
3264
3296
  this.rightActionsContainer.className = 'right-actions-container';
3265
3297
  this.leftActionsContainer = document.createElement('div');
3266
3298
  this.leftActionsContainer.className = 'left-actions-container';
3299
+ this.preActionsContainer = document.createElement('div');
3300
+ this.preActionsContainer.className = 'pre-actions-container';
3267
3301
  this.tabContainer = document.createElement('div');
3268
3302
  this.tabContainer.className = 'tabs-container';
3269
3303
  this.voidContainer = new VoidContainer(this.accessor, this.group);
3304
+ this._element.appendChild(this.preActionsContainer);
3270
3305
  this._element.appendChild(this.tabContainer);
3271
3306
  this._element.appendChild(this.leftActionsContainer);
3272
3307
  this._element.appendChild(this.voidContainer.element);
@@ -3556,6 +3591,16 @@ define(['exports'], (function (exports) { 'use strict';
3556
3591
  });
3557
3592
  this.tabsContainer.setLeftActionsElement(this._leftHeaderActions.element);
3558
3593
  }
3594
+ if (this.accessor.options.createPrefixHeaderActionsElement) {
3595
+ this._prefixHeaderActions =
3596
+ this.accessor.options.createPrefixHeaderActionsElement(this.groupPanel);
3597
+ this.addDisposables(this._prefixHeaderActions);
3598
+ this._prefixHeaderActions.init({
3599
+ containerApi: new DockviewApi(this.accessor),
3600
+ api: this.groupPanel.api,
3601
+ });
3602
+ this.tabsContainer.setPrefixActionsElement(this._prefixHeaderActions.element);
3603
+ }
3559
3604
  }
3560
3605
  indexOf(panel) {
3561
3606
  return this.tabsContainer.indexOf(panel.id);
@@ -3898,6 +3943,14 @@ define(['exports'], (function (exports) { 'use strict';
3898
3943
  */
3899
3944
  return;
3900
3945
  }
3946
+ if (!document.body.contains(this._element)) {
3947
+ /**
3948
+ * since the event is dispatched through requestAnimationFrame there is a small chance
3949
+ * the component is no longer attached to the DOM, if that is the case the dimensions
3950
+ * are mostly likely all zero and meaningless. we should skip this case.
3951
+ */
3952
+ return;
3953
+ }
3901
3954
  const { width, height } = entry.contentRect;
3902
3955
  this.layout(width, height);
3903
3956
  }));
@@ -5926,61 +5979,114 @@ define(['exports'], (function (exports) { 'use strict';
5926
5979
  fromJSON(data) {
5927
5980
  var _a;
5928
5981
  this.clear();
5982
+ if (typeof data !== 'object' || data === null) {
5983
+ throw new Error('serialized layout must be a non-null object');
5984
+ }
5929
5985
  const { grid, panels, activeGroup } = data;
5930
5986
  if (grid.root.type !== 'branch' || !Array.isArray(grid.root.data)) {
5931
5987
  throw new Error('root must be of type branch');
5932
5988
  }
5933
- // take note of the existing dimensions
5934
- const width = this.width;
5935
- const height = this.height;
5936
- const createGroupFromSerializedState = (data) => {
5937
- const { id, locked, hideHeader, views, activeView } = data;
5938
- const group = this.createGroup({
5939
- id,
5940
- locked: !!locked,
5941
- hideHeader: !!hideHeader,
5942
- });
5943
- this._onDidAddGroup.fire(group);
5944
- for (const child of views) {
5945
- const panel = this._deserializer.fromJSON(panels[child], group);
5946
- const isActive = typeof activeView === 'string' && activeView === panel.id;
5947
- group.model.openPanel(panel, {
5948
- skipSetPanelActive: !isActive,
5949
- skipSetGroupActive: true,
5989
+ try {
5990
+ // take note of the existing dimensions
5991
+ const width = this.width;
5992
+ const height = this.height;
5993
+ const createGroupFromSerializedState = (data) => {
5994
+ const { id, locked, hideHeader, views, activeView } = data;
5995
+ if (typeof id !== 'string') {
5996
+ throw new Error('group id must be of type string');
5997
+ }
5998
+ const group = this.createGroup({
5999
+ id,
6000
+ locked: !!locked,
6001
+ hideHeader: !!hideHeader,
5950
6002
  });
6003
+ const createdPanels = [];
6004
+ for (const child of views) {
6005
+ /**
6006
+ * Run the deserializer step seperately since this may fail to due corrupted external state.
6007
+ * In running this section first we avoid firing lots of 'add' events in the event of a failure
6008
+ * due to a corruption of input data.
6009
+ */
6010
+ const panel = this._deserializer.fromJSON(panels[child], group);
6011
+ createdPanels.push(panel);
6012
+ }
6013
+ this._onDidAddGroup.fire(group);
6014
+ for (let i = 0; i < views.length; i++) {
6015
+ const panel = createdPanels[i];
6016
+ const isActive = typeof activeView === 'string' &&
6017
+ activeView === panel.id;
6018
+ group.model.openPanel(panel, {
6019
+ skipSetPanelActive: !isActive,
6020
+ skipSetGroupActive: true,
6021
+ });
6022
+ }
6023
+ if (!group.activePanel && group.panels.length > 0) {
6024
+ group.model.openPanel(group.panels[group.panels.length - 1], {
6025
+ skipSetGroupActive: true,
6026
+ });
6027
+ }
6028
+ return group;
6029
+ };
6030
+ this.gridview.deserialize(grid, {
6031
+ fromJSON: (node) => {
6032
+ return createGroupFromSerializedState(node.data);
6033
+ },
6034
+ });
6035
+ this.layout(width, height, true);
6036
+ const serializedFloatingGroups = (_a = data.floatingGroups) !== null && _a !== void 0 ? _a : [];
6037
+ for (const serializedFloatingGroup of serializedFloatingGroups) {
6038
+ const { data, position } = serializedFloatingGroup;
6039
+ const group = createGroupFromSerializedState(data);
6040
+ this.addFloatingGroup(group, {
6041
+ x: position.left,
6042
+ y: position.top,
6043
+ height: position.height,
6044
+ width: position.width,
6045
+ }, { skipRemoveGroup: true, inDragMode: false });
6046
+ }
6047
+ for (const floatingGroup of this.floatingGroups) {
6048
+ floatingGroup.overlay.setBounds();
6049
+ }
6050
+ if (typeof activeGroup === 'string') {
6051
+ const panel = this.getPanel(activeGroup);
6052
+ if (panel) {
6053
+ this.doSetGroupActive(panel);
6054
+ }
5951
6055
  }
5952
- if (!group.activePanel && group.panels.length > 0) {
5953
- group.model.openPanel(group.panels[group.panels.length - 1], {
5954
- skipSetGroupActive: true,
5955
- });
6056
+ }
6057
+ catch (err) {
6058
+ /**
6059
+ * Takes all the successfully created groups and remove all of their panels.
6060
+ */
6061
+ for (const group of this.groups) {
6062
+ for (const panel of group.panels) {
6063
+ this.removePanel(panel, {
6064
+ removeEmptyGroup: false,
6065
+ skipDispose: false,
6066
+ });
6067
+ }
5956
6068
  }
5957
- return group;
5958
- };
5959
- this.gridview.deserialize(grid, {
5960
- fromJSON: (node) => {
5961
- return createGroupFromSerializedState(node.data);
5962
- },
5963
- });
5964
- this.layout(width, height, true);
5965
- const serializedFloatingGroups = (_a = data.floatingGroups) !== null && _a !== void 0 ? _a : [];
5966
- for (const serializedFloatingGroup of serializedFloatingGroups) {
5967
- const { data, position } = serializedFloatingGroup;
5968
- const group = createGroupFromSerializedState(data);
5969
- this.addFloatingGroup(group, {
5970
- x: position.left,
5971
- y: position.top,
5972
- height: position.height,
5973
- width: position.width,
5974
- }, { skipRemoveGroup: true, inDragMode: false });
5975
- }
5976
- for (const floatingGroup of this.floatingGroups) {
5977
- floatingGroup.overlay.setBounds();
5978
- }
5979
- if (typeof activeGroup === 'string') {
5980
- const panel = this.getPanel(activeGroup);
5981
- if (panel) {
5982
- this.doSetGroupActive(panel);
6069
+ /**
6070
+ * To remove a group we cannot call this.removeGroup(...) since this makes assumptions about
6071
+ * the underlying HTMLElement existing in the Gridview.
6072
+ */
6073
+ for (const group of this.groups) {
6074
+ group.dispose();
6075
+ this._groups.delete(group.id);
6076
+ this._onDidRemoveGroup.fire(group);
6077
+ }
6078
+ // iterate over a reassigned array since original array will be modified
6079
+ for (const floatingGroup of [...this.floatingGroups]) {
6080
+ floatingGroup.dispose();
5983
6081
  }
6082
+ // fires clean-up events and clears the underlying HTML gridview.
6083
+ this.clear();
6084
+ /**
6085
+ * even though we have cleaned-up we still want to inform the caller of their error
6086
+ * and we'll do this through re-throwing the original error since afterall you would
6087
+ * expect trying to load a corrupted layout to result in an error and not silently fail...
6088
+ */
6089
+ throw err;
5984
6090
  }
5985
6091
  this._onDidLayoutFromJSON.fire();
5986
6092
  }
@@ -6194,6 +6300,7 @@ define(['exports'], (function (exports) { 'use strict';
6194
6300
  if (!(options === null || options === void 0 ? void 0 : options.skipDispose)) {
6195
6301
  floatingGroup.group.dispose();
6196
6302
  this._groups.delete(group.id);
6303
+ // TODO: fire group removed event?
6197
6304
  }
6198
6305
  floatingGroup.dispose();
6199
6306
  return floatingGroup.group;
@@ -6434,42 +6541,63 @@ define(['exports'], (function (exports) { 'use strict';
6434
6541
  fromJSON(serializedGridview) {
6435
6542
  this.clear();
6436
6543
  const { grid, activePanel } = serializedGridview;
6437
- const queue = [];
6438
- // take note of the existing dimensions
6439
- const width = this.width;
6440
- const height = this.height;
6441
- this.gridview.deserialize(grid, {
6442
- fromJSON: (node) => {
6443
- const { data } = node;
6444
- const view = createComponent(data.id, data.component, this.options.components || {}, this.options.frameworkComponents || {}, this.options.frameworkComponentFactory
6445
- ? {
6446
- createComponent: this.options.frameworkComponentFactory
6447
- .createComponent,
6448
- }
6449
- : undefined);
6450
- queue.push(() => view.init({
6451
- params: data.params,
6452
- minimumWidth: data.minimumWidth,
6453
- maximumWidth: data.maximumWidth,
6454
- minimumHeight: data.minimumHeight,
6455
- maximumHeight: data.maximumHeight,
6456
- priority: data.priority,
6457
- snap: !!data.snap,
6458
- accessor: this,
6459
- isVisible: node.visible,
6460
- }));
6461
- this._onDidAddGroup.fire(view);
6462
- this.registerPanel(view);
6463
- return view;
6464
- },
6465
- });
6466
- this.layout(width, height, true);
6467
- queue.forEach((f) => f());
6468
- if (typeof activePanel === 'string') {
6469
- const panel = this.getPanel(activePanel);
6470
- if (panel) {
6471
- this.doSetGroupActive(panel);
6544
+ try {
6545
+ const queue = [];
6546
+ // take note of the existing dimensions
6547
+ const width = this.width;
6548
+ const height = this.height;
6549
+ this.gridview.deserialize(grid, {
6550
+ fromJSON: (node) => {
6551
+ const { data } = node;
6552
+ const view = createComponent(data.id, data.component, this.options.components || {}, this.options.frameworkComponents || {}, this.options.frameworkComponentFactory
6553
+ ? {
6554
+ createComponent: this.options.frameworkComponentFactory
6555
+ .createComponent,
6556
+ }
6557
+ : undefined);
6558
+ queue.push(() => view.init({
6559
+ params: data.params,
6560
+ minimumWidth: data.minimumWidth,
6561
+ maximumWidth: data.maximumWidth,
6562
+ minimumHeight: data.minimumHeight,
6563
+ maximumHeight: data.maximumHeight,
6564
+ priority: data.priority,
6565
+ snap: !!data.snap,
6566
+ accessor: this,
6567
+ isVisible: node.visible,
6568
+ }));
6569
+ this._onDidAddGroup.fire(view);
6570
+ this.registerPanel(view);
6571
+ return view;
6572
+ },
6573
+ });
6574
+ this.layout(width, height, true);
6575
+ queue.forEach((f) => f());
6576
+ if (typeof activePanel === 'string') {
6577
+ const panel = this.getPanel(activePanel);
6578
+ if (panel) {
6579
+ this.doSetGroupActive(panel);
6580
+ }
6581
+ }
6582
+ }
6583
+ catch (err) {
6584
+ /**
6585
+ * To remove a group we cannot call this.removeGroup(...) since this makes assumptions about
6586
+ * the underlying HTMLElement existing in the Gridview.
6587
+ */
6588
+ for (const group of this.groups) {
6589
+ group.dispose();
6590
+ this._groups.delete(group.id);
6591
+ this._onDidRemoveGroup.fire(group);
6472
6592
  }
6593
+ // fires clean-up events and clears the underlying HTML gridview.
6594
+ this.clear();
6595
+ /**
6596
+ * even though we have cleaned-up we still want to inform the caller of their error
6597
+ * and we'll do this through re-throwing the original error since afterall you would
6598
+ * expect trying to load a corrupted layout to result in an error and not silently fail...
6599
+ */
6600
+ throw err;
6473
6601
  }
6474
6602
  this._onDidLayoutfromJSON.fire();
6475
6603
  }