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
  */
@@ -896,7 +896,17 @@ class Splitview {
896
896
  size = typeof size === 'number' ? size : item.size;
897
897
  size = clamp(size, item.minimumSize, item.maximumSize);
898
898
  item.size = size;
899
- this.relayout([index]);
899
+ const indexes = range(this.viewItems.length).filter((i) => i !== index);
900
+ const lowPriorityIndexes = [
901
+ ...indexes.filter((i) => this.viewItems[i].priority === LayoutPriority.Low),
902
+ index,
903
+ ];
904
+ const highPriorityIndexes = indexes.filter((i) => this.viewItems[i].priority === LayoutPriority.High);
905
+ /**
906
+ * add this view we are changing to the low-index list since we have determined the size
907
+ * here and don't want it changed
908
+ */
909
+ this.relayout([...lowPriorityIndexes, index], highPriorityIndexes);
900
910
  }
901
911
  addView(view, size = { type: 'distribute' }, index = this.viewItems.length, skipLayout) {
902
912
  const container = document.createElement('div');
@@ -1653,6 +1663,7 @@ class BranchNode extends CompositeDisposable {
1653
1663
  orientation: this.orientation,
1654
1664
  descriptor,
1655
1665
  proportionalLayout,
1666
+ styles,
1656
1667
  });
1657
1668
  }
1658
1669
  this.addDisposables(this._onDidChange, this.splitview.onDidSashEnd(() => {
@@ -2164,6 +2175,14 @@ class Gridview {
2164
2175
  const child = sibling.children[i];
2165
2176
  grandParent.addChild(child, child.size, parentIndex + i);
2166
2177
  }
2178
+ /**
2179
+ * clean down the branch node since we need to dipose of it and
2180
+ * when .dispose() it called on a branch it will dispose of any
2181
+ * views it is holding onto.
2182
+ */
2183
+ while (sibling.children.length > 0) {
2184
+ sibling.removeChild(0);
2185
+ }
2167
2186
  }
2168
2187
  else {
2169
2188
  // otherwise create a new leaf node and add that to the grandparent
@@ -3222,6 +3241,19 @@ class TabsContainer extends CompositeDisposable {
3222
3241
  this.leftActions = element;
3223
3242
  }
3224
3243
  }
3244
+ setPrefixActionsElement(element) {
3245
+ if (this.preActions === element) {
3246
+ return;
3247
+ }
3248
+ if (this.preActions) {
3249
+ this.preActions.remove();
3250
+ this.preActions = undefined;
3251
+ }
3252
+ if (element) {
3253
+ this.preActionsContainer.appendChild(element);
3254
+ this.preActions = element;
3255
+ }
3256
+ }
3225
3257
  get element() {
3226
3258
  return this._element;
3227
3259
  }
@@ -3262,9 +3294,12 @@ class TabsContainer extends CompositeDisposable {
3262
3294
  this.rightActionsContainer.className = 'right-actions-container';
3263
3295
  this.leftActionsContainer = document.createElement('div');
3264
3296
  this.leftActionsContainer.className = 'left-actions-container';
3297
+ this.preActionsContainer = document.createElement('div');
3298
+ this.preActionsContainer.className = 'pre-actions-container';
3265
3299
  this.tabContainer = document.createElement('div');
3266
3300
  this.tabContainer.className = 'tabs-container';
3267
3301
  this.voidContainer = new VoidContainer(this.accessor, this.group);
3302
+ this._element.appendChild(this.preActionsContainer);
3268
3303
  this._element.appendChild(this.tabContainer);
3269
3304
  this._element.appendChild(this.leftActionsContainer);
3270
3305
  this._element.appendChild(this.voidContainer.element);
@@ -3554,6 +3589,16 @@ class DockviewGroupPanelModel extends CompositeDisposable {
3554
3589
  });
3555
3590
  this.tabsContainer.setLeftActionsElement(this._leftHeaderActions.element);
3556
3591
  }
3592
+ if (this.accessor.options.createPrefixHeaderActionsElement) {
3593
+ this._prefixHeaderActions =
3594
+ this.accessor.options.createPrefixHeaderActionsElement(this.groupPanel);
3595
+ this.addDisposables(this._prefixHeaderActions);
3596
+ this._prefixHeaderActions.init({
3597
+ containerApi: new DockviewApi(this.accessor),
3598
+ api: this.groupPanel.api,
3599
+ });
3600
+ this.tabsContainer.setPrefixActionsElement(this._prefixHeaderActions.element);
3601
+ }
3557
3602
  }
3558
3603
  indexOf(panel) {
3559
3604
  return this.tabsContainer.indexOf(panel.id);
@@ -3896,6 +3941,14 @@ class Resizable extends CompositeDisposable {
3896
3941
  */
3897
3942
  return;
3898
3943
  }
3944
+ if (!document.body.contains(this._element)) {
3945
+ /**
3946
+ * since the event is dispatched through requestAnimationFrame there is a small chance
3947
+ * the component is no longer attached to the DOM, if that is the case the dimensions
3948
+ * are mostly likely all zero and meaningless. we should skip this case.
3949
+ */
3950
+ return;
3951
+ }
3899
3952
  const { width, height } = entry.contentRect;
3900
3953
  this.layout(width, height);
3901
3954
  }));
@@ -5924,61 +5977,114 @@ class DockviewComponent extends BaseGrid {
5924
5977
  fromJSON(data) {
5925
5978
  var _a;
5926
5979
  this.clear();
5980
+ if (typeof data !== 'object' || data === null) {
5981
+ throw new Error('serialized layout must be a non-null object');
5982
+ }
5927
5983
  const { grid, panels, activeGroup } = data;
5928
5984
  if (grid.root.type !== 'branch' || !Array.isArray(grid.root.data)) {
5929
5985
  throw new Error('root must be of type branch');
5930
5986
  }
5931
- // take note of the existing dimensions
5932
- const width = this.width;
5933
- const height = this.height;
5934
- const createGroupFromSerializedState = (data) => {
5935
- const { id, locked, hideHeader, views, activeView } = data;
5936
- const group = this.createGroup({
5937
- id,
5938
- locked: !!locked,
5939
- hideHeader: !!hideHeader,
5940
- });
5941
- this._onDidAddGroup.fire(group);
5942
- for (const child of views) {
5943
- const panel = this._deserializer.fromJSON(panels[child], group);
5944
- const isActive = typeof activeView === 'string' && activeView === panel.id;
5945
- group.model.openPanel(panel, {
5946
- skipSetPanelActive: !isActive,
5947
- skipSetGroupActive: true,
5987
+ try {
5988
+ // take note of the existing dimensions
5989
+ const width = this.width;
5990
+ const height = this.height;
5991
+ const createGroupFromSerializedState = (data) => {
5992
+ const { id, locked, hideHeader, views, activeView } = data;
5993
+ if (typeof id !== 'string') {
5994
+ throw new Error('group id must be of type string');
5995
+ }
5996
+ const group = this.createGroup({
5997
+ id,
5998
+ locked: !!locked,
5999
+ hideHeader: !!hideHeader,
5948
6000
  });
6001
+ const createdPanels = [];
6002
+ for (const child of views) {
6003
+ /**
6004
+ * Run the deserializer step seperately since this may fail to due corrupted external state.
6005
+ * In running this section first we avoid firing lots of 'add' events in the event of a failure
6006
+ * due to a corruption of input data.
6007
+ */
6008
+ const panel = this._deserializer.fromJSON(panels[child], group);
6009
+ createdPanels.push(panel);
6010
+ }
6011
+ this._onDidAddGroup.fire(group);
6012
+ for (let i = 0; i < views.length; i++) {
6013
+ const panel = createdPanels[i];
6014
+ const isActive = typeof activeView === 'string' &&
6015
+ activeView === panel.id;
6016
+ group.model.openPanel(panel, {
6017
+ skipSetPanelActive: !isActive,
6018
+ skipSetGroupActive: true,
6019
+ });
6020
+ }
6021
+ if (!group.activePanel && group.panels.length > 0) {
6022
+ group.model.openPanel(group.panels[group.panels.length - 1], {
6023
+ skipSetGroupActive: true,
6024
+ });
6025
+ }
6026
+ return group;
6027
+ };
6028
+ this.gridview.deserialize(grid, {
6029
+ fromJSON: (node) => {
6030
+ return createGroupFromSerializedState(node.data);
6031
+ },
6032
+ });
6033
+ this.layout(width, height, true);
6034
+ const serializedFloatingGroups = (_a = data.floatingGroups) !== null && _a !== void 0 ? _a : [];
6035
+ for (const serializedFloatingGroup of serializedFloatingGroups) {
6036
+ const { data, position } = serializedFloatingGroup;
6037
+ const group = createGroupFromSerializedState(data);
6038
+ this.addFloatingGroup(group, {
6039
+ x: position.left,
6040
+ y: position.top,
6041
+ height: position.height,
6042
+ width: position.width,
6043
+ }, { skipRemoveGroup: true, inDragMode: false });
6044
+ }
6045
+ for (const floatingGroup of this.floatingGroups) {
6046
+ floatingGroup.overlay.setBounds();
6047
+ }
6048
+ if (typeof activeGroup === 'string') {
6049
+ const panel = this.getPanel(activeGroup);
6050
+ if (panel) {
6051
+ this.doSetGroupActive(panel);
6052
+ }
5949
6053
  }
5950
- if (!group.activePanel && group.panels.length > 0) {
5951
- group.model.openPanel(group.panels[group.panels.length - 1], {
5952
- skipSetGroupActive: true,
5953
- });
6054
+ }
6055
+ catch (err) {
6056
+ /**
6057
+ * Takes all the successfully created groups and remove all of their panels.
6058
+ */
6059
+ for (const group of this.groups) {
6060
+ for (const panel of group.panels) {
6061
+ this.removePanel(panel, {
6062
+ removeEmptyGroup: false,
6063
+ skipDispose: false,
6064
+ });
6065
+ }
5954
6066
  }
5955
- return group;
5956
- };
5957
- this.gridview.deserialize(grid, {
5958
- fromJSON: (node) => {
5959
- return createGroupFromSerializedState(node.data);
5960
- },
5961
- });
5962
- this.layout(width, height, true);
5963
- const serializedFloatingGroups = (_a = data.floatingGroups) !== null && _a !== void 0 ? _a : [];
5964
- for (const serializedFloatingGroup of serializedFloatingGroups) {
5965
- const { data, position } = serializedFloatingGroup;
5966
- const group = createGroupFromSerializedState(data);
5967
- this.addFloatingGroup(group, {
5968
- x: position.left,
5969
- y: position.top,
5970
- height: position.height,
5971
- width: position.width,
5972
- }, { skipRemoveGroup: true, inDragMode: false });
5973
- }
5974
- for (const floatingGroup of this.floatingGroups) {
5975
- floatingGroup.overlay.setBounds();
5976
- }
5977
- if (typeof activeGroup === 'string') {
5978
- const panel = this.getPanel(activeGroup);
5979
- if (panel) {
5980
- this.doSetGroupActive(panel);
6067
+ /**
6068
+ * To remove a group we cannot call this.removeGroup(...) since this makes assumptions about
6069
+ * the underlying HTMLElement existing in the Gridview.
6070
+ */
6071
+ for (const group of this.groups) {
6072
+ group.dispose();
6073
+ this._groups.delete(group.id);
6074
+ this._onDidRemoveGroup.fire(group);
6075
+ }
6076
+ // iterate over a reassigned array since original array will be modified
6077
+ for (const floatingGroup of [...this.floatingGroups]) {
6078
+ floatingGroup.dispose();
5981
6079
  }
6080
+ // fires clean-up events and clears the underlying HTML gridview.
6081
+ this.clear();
6082
+ /**
6083
+ * even though we have cleaned-up we still want to inform the caller of their error
6084
+ * and we'll do this through re-throwing the original error since afterall you would
6085
+ * expect trying to load a corrupted layout to result in an error and not silently fail...
6086
+ */
6087
+ throw err;
5982
6088
  }
5983
6089
  this._onDidLayoutFromJSON.fire();
5984
6090
  }
@@ -6192,6 +6298,7 @@ class DockviewComponent extends BaseGrid {
6192
6298
  if (!(options === null || options === void 0 ? void 0 : options.skipDispose)) {
6193
6299
  floatingGroup.group.dispose();
6194
6300
  this._groups.delete(group.id);
6301
+ // TODO: fire group removed event?
6195
6302
  }
6196
6303
  floatingGroup.dispose();
6197
6304
  return floatingGroup.group;
@@ -6432,42 +6539,63 @@ class GridviewComponent extends BaseGrid {
6432
6539
  fromJSON(serializedGridview) {
6433
6540
  this.clear();
6434
6541
  const { grid, activePanel } = serializedGridview;
6435
- const queue = [];
6436
- // take note of the existing dimensions
6437
- const width = this.width;
6438
- const height = this.height;
6439
- this.gridview.deserialize(grid, {
6440
- fromJSON: (node) => {
6441
- const { data } = node;
6442
- const view = createComponent(data.id, data.component, this.options.components || {}, this.options.frameworkComponents || {}, this.options.frameworkComponentFactory
6443
- ? {
6444
- createComponent: this.options.frameworkComponentFactory
6445
- .createComponent,
6446
- }
6447
- : undefined);
6448
- queue.push(() => view.init({
6449
- params: data.params,
6450
- minimumWidth: data.minimumWidth,
6451
- maximumWidth: data.maximumWidth,
6452
- minimumHeight: data.minimumHeight,
6453
- maximumHeight: data.maximumHeight,
6454
- priority: data.priority,
6455
- snap: !!data.snap,
6456
- accessor: this,
6457
- isVisible: node.visible,
6458
- }));
6459
- this._onDidAddGroup.fire(view);
6460
- this.registerPanel(view);
6461
- return view;
6462
- },
6463
- });
6464
- this.layout(width, height, true);
6465
- queue.forEach((f) => f());
6466
- if (typeof activePanel === 'string') {
6467
- const panel = this.getPanel(activePanel);
6468
- if (panel) {
6469
- this.doSetGroupActive(panel);
6542
+ try {
6543
+ const queue = [];
6544
+ // take note of the existing dimensions
6545
+ const width = this.width;
6546
+ const height = this.height;
6547
+ this.gridview.deserialize(grid, {
6548
+ fromJSON: (node) => {
6549
+ const { data } = node;
6550
+ const view = createComponent(data.id, data.component, this.options.components || {}, this.options.frameworkComponents || {}, this.options.frameworkComponentFactory
6551
+ ? {
6552
+ createComponent: this.options.frameworkComponentFactory
6553
+ .createComponent,
6554
+ }
6555
+ : undefined);
6556
+ queue.push(() => view.init({
6557
+ params: data.params,
6558
+ minimumWidth: data.minimumWidth,
6559
+ maximumWidth: data.maximumWidth,
6560
+ minimumHeight: data.minimumHeight,
6561
+ maximumHeight: data.maximumHeight,
6562
+ priority: data.priority,
6563
+ snap: !!data.snap,
6564
+ accessor: this,
6565
+ isVisible: node.visible,
6566
+ }));
6567
+ this._onDidAddGroup.fire(view);
6568
+ this.registerPanel(view);
6569
+ return view;
6570
+ },
6571
+ });
6572
+ this.layout(width, height, true);
6573
+ queue.forEach((f) => f());
6574
+ if (typeof activePanel === 'string') {
6575
+ const panel = this.getPanel(activePanel);
6576
+ if (panel) {
6577
+ this.doSetGroupActive(panel);
6578
+ }
6579
+ }
6580
+ }
6581
+ catch (err) {
6582
+ /**
6583
+ * To remove a group we cannot call this.removeGroup(...) since this makes assumptions about
6584
+ * the underlying HTMLElement existing in the Gridview.
6585
+ */
6586
+ for (const group of this.groups) {
6587
+ group.dispose();
6588
+ this._groups.delete(group.id);
6589
+ this._onDidRemoveGroup.fire(group);
6470
6590
  }
6591
+ // fires clean-up events and clears the underlying HTML gridview.
6592
+ this.clear();
6593
+ /**
6594
+ * even though we have cleaned-up we still want to inform the caller of their error
6595
+ * and we'll do this through re-throwing the original error since afterall you would
6596
+ * expect trying to load a corrupted layout to result in an error and not silently fail...
6597
+ */
6598
+ throw err;
6471
6599
  }
6472
6600
  this._onDidLayoutfromJSON.fire();
6473
6601
  }