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
  */
@@ -902,7 +902,17 @@
902
902
  size = typeof size === 'number' ? size : item.size;
903
903
  size = clamp(size, item.minimumSize, item.maximumSize);
904
904
  item.size = size;
905
- this.relayout([index]);
905
+ const indexes = range(this.viewItems.length).filter((i) => i !== index);
906
+ const lowPriorityIndexes = [
907
+ ...indexes.filter((i) => this.viewItems[i].priority === exports.LayoutPriority.Low),
908
+ index,
909
+ ];
910
+ const highPriorityIndexes = indexes.filter((i) => this.viewItems[i].priority === exports.LayoutPriority.High);
911
+ /**
912
+ * add this view we are changing to the low-index list since we have determined the size
913
+ * here and don't want it changed
914
+ */
915
+ this.relayout([...lowPriorityIndexes, index], highPriorityIndexes);
906
916
  }
907
917
  addView(view, size = { type: 'distribute' }, index = this.viewItems.length, skipLayout) {
908
918
  const container = document.createElement('div');
@@ -1659,6 +1669,7 @@
1659
1669
  orientation: this.orientation,
1660
1670
  descriptor,
1661
1671
  proportionalLayout,
1672
+ styles,
1662
1673
  });
1663
1674
  }
1664
1675
  this.addDisposables(this._onDidChange, this.splitview.onDidSashEnd(() => {
@@ -2170,6 +2181,14 @@
2170
2181
  const child = sibling.children[i];
2171
2182
  grandParent.addChild(child, child.size, parentIndex + i);
2172
2183
  }
2184
+ /**
2185
+ * clean down the branch node since we need to dipose of it and
2186
+ * when .dispose() it called on a branch it will dispose of any
2187
+ * views it is holding onto.
2188
+ */
2189
+ while (sibling.children.length > 0) {
2190
+ sibling.removeChild(0);
2191
+ }
2173
2192
  }
2174
2193
  else {
2175
2194
  // otherwise create a new leaf node and add that to the grandparent
@@ -3228,6 +3247,19 @@
3228
3247
  this.leftActions = element;
3229
3248
  }
3230
3249
  }
3250
+ setPrefixActionsElement(element) {
3251
+ if (this.preActions === element) {
3252
+ return;
3253
+ }
3254
+ if (this.preActions) {
3255
+ this.preActions.remove();
3256
+ this.preActions = undefined;
3257
+ }
3258
+ if (element) {
3259
+ this.preActionsContainer.appendChild(element);
3260
+ this.preActions = element;
3261
+ }
3262
+ }
3231
3263
  get element() {
3232
3264
  return this._element;
3233
3265
  }
@@ -3268,9 +3300,12 @@
3268
3300
  this.rightActionsContainer.className = 'right-actions-container';
3269
3301
  this.leftActionsContainer = document.createElement('div');
3270
3302
  this.leftActionsContainer.className = 'left-actions-container';
3303
+ this.preActionsContainer = document.createElement('div');
3304
+ this.preActionsContainer.className = 'pre-actions-container';
3271
3305
  this.tabContainer = document.createElement('div');
3272
3306
  this.tabContainer.className = 'tabs-container';
3273
3307
  this.voidContainer = new VoidContainer(this.accessor, this.group);
3308
+ this._element.appendChild(this.preActionsContainer);
3274
3309
  this._element.appendChild(this.tabContainer);
3275
3310
  this._element.appendChild(this.leftActionsContainer);
3276
3311
  this._element.appendChild(this.voidContainer.element);
@@ -3560,6 +3595,16 @@
3560
3595
  });
3561
3596
  this.tabsContainer.setLeftActionsElement(this._leftHeaderActions.element);
3562
3597
  }
3598
+ if (this.accessor.options.createPrefixHeaderActionsElement) {
3599
+ this._prefixHeaderActions =
3600
+ this.accessor.options.createPrefixHeaderActionsElement(this.groupPanel);
3601
+ this.addDisposables(this._prefixHeaderActions);
3602
+ this._prefixHeaderActions.init({
3603
+ containerApi: new DockviewApi(this.accessor),
3604
+ api: this.groupPanel.api,
3605
+ });
3606
+ this.tabsContainer.setPrefixActionsElement(this._prefixHeaderActions.element);
3607
+ }
3563
3608
  }
3564
3609
  indexOf(panel) {
3565
3610
  return this.tabsContainer.indexOf(panel.id);
@@ -3902,6 +3947,14 @@
3902
3947
  */
3903
3948
  return;
3904
3949
  }
3950
+ if (!document.body.contains(this._element)) {
3951
+ /**
3952
+ * since the event is dispatched through requestAnimationFrame there is a small chance
3953
+ * the component is no longer attached to the DOM, if that is the case the dimensions
3954
+ * are mostly likely all zero and meaningless. we should skip this case.
3955
+ */
3956
+ return;
3957
+ }
3905
3958
  const { width, height } = entry.contentRect;
3906
3959
  this.layout(width, height);
3907
3960
  }));
@@ -5930,61 +5983,114 @@
5930
5983
  fromJSON(data) {
5931
5984
  var _a;
5932
5985
  this.clear();
5986
+ if (typeof data !== 'object' || data === null) {
5987
+ throw new Error('serialized layout must be a non-null object');
5988
+ }
5933
5989
  const { grid, panels, activeGroup } = data;
5934
5990
  if (grid.root.type !== 'branch' || !Array.isArray(grid.root.data)) {
5935
5991
  throw new Error('root must be of type branch');
5936
5992
  }
5937
- // take note of the existing dimensions
5938
- const width = this.width;
5939
- const height = this.height;
5940
- const createGroupFromSerializedState = (data) => {
5941
- const { id, locked, hideHeader, views, activeView } = data;
5942
- const group = this.createGroup({
5943
- id,
5944
- locked: !!locked,
5945
- hideHeader: !!hideHeader,
5946
- });
5947
- this._onDidAddGroup.fire(group);
5948
- for (const child of views) {
5949
- const panel = this._deserializer.fromJSON(panels[child], group);
5950
- const isActive = typeof activeView === 'string' && activeView === panel.id;
5951
- group.model.openPanel(panel, {
5952
- skipSetPanelActive: !isActive,
5953
- skipSetGroupActive: true,
5993
+ try {
5994
+ // take note of the existing dimensions
5995
+ const width = this.width;
5996
+ const height = this.height;
5997
+ const createGroupFromSerializedState = (data) => {
5998
+ const { id, locked, hideHeader, views, activeView } = data;
5999
+ if (typeof id !== 'string') {
6000
+ throw new Error('group id must be of type string');
6001
+ }
6002
+ const group = this.createGroup({
6003
+ id,
6004
+ locked: !!locked,
6005
+ hideHeader: !!hideHeader,
5954
6006
  });
6007
+ const createdPanels = [];
6008
+ for (const child of views) {
6009
+ /**
6010
+ * Run the deserializer step seperately since this may fail to due corrupted external state.
6011
+ * In running this section first we avoid firing lots of 'add' events in the event of a failure
6012
+ * due to a corruption of input data.
6013
+ */
6014
+ const panel = this._deserializer.fromJSON(panels[child], group);
6015
+ createdPanels.push(panel);
6016
+ }
6017
+ this._onDidAddGroup.fire(group);
6018
+ for (let i = 0; i < views.length; i++) {
6019
+ const panel = createdPanels[i];
6020
+ const isActive = typeof activeView === 'string' &&
6021
+ activeView === panel.id;
6022
+ group.model.openPanel(panel, {
6023
+ skipSetPanelActive: !isActive,
6024
+ skipSetGroupActive: true,
6025
+ });
6026
+ }
6027
+ if (!group.activePanel && group.panels.length > 0) {
6028
+ group.model.openPanel(group.panels[group.panels.length - 1], {
6029
+ skipSetGroupActive: true,
6030
+ });
6031
+ }
6032
+ return group;
6033
+ };
6034
+ this.gridview.deserialize(grid, {
6035
+ fromJSON: (node) => {
6036
+ return createGroupFromSerializedState(node.data);
6037
+ },
6038
+ });
6039
+ this.layout(width, height, true);
6040
+ const serializedFloatingGroups = (_a = data.floatingGroups) !== null && _a !== void 0 ? _a : [];
6041
+ for (const serializedFloatingGroup of serializedFloatingGroups) {
6042
+ const { data, position } = serializedFloatingGroup;
6043
+ const group = createGroupFromSerializedState(data);
6044
+ this.addFloatingGroup(group, {
6045
+ x: position.left,
6046
+ y: position.top,
6047
+ height: position.height,
6048
+ width: position.width,
6049
+ }, { skipRemoveGroup: true, inDragMode: false });
6050
+ }
6051
+ for (const floatingGroup of this.floatingGroups) {
6052
+ floatingGroup.overlay.setBounds();
6053
+ }
6054
+ if (typeof activeGroup === 'string') {
6055
+ const panel = this.getPanel(activeGroup);
6056
+ if (panel) {
6057
+ this.doSetGroupActive(panel);
6058
+ }
5955
6059
  }
5956
- if (!group.activePanel && group.panels.length > 0) {
5957
- group.model.openPanel(group.panels[group.panels.length - 1], {
5958
- skipSetGroupActive: true,
5959
- });
6060
+ }
6061
+ catch (err) {
6062
+ /**
6063
+ * Takes all the successfully created groups and remove all of their panels.
6064
+ */
6065
+ for (const group of this.groups) {
6066
+ for (const panel of group.panels) {
6067
+ this.removePanel(panel, {
6068
+ removeEmptyGroup: false,
6069
+ skipDispose: false,
6070
+ });
6071
+ }
5960
6072
  }
5961
- return group;
5962
- };
5963
- this.gridview.deserialize(grid, {
5964
- fromJSON: (node) => {
5965
- return createGroupFromSerializedState(node.data);
5966
- },
5967
- });
5968
- this.layout(width, height, true);
5969
- const serializedFloatingGroups = (_a = data.floatingGroups) !== null && _a !== void 0 ? _a : [];
5970
- for (const serializedFloatingGroup of serializedFloatingGroups) {
5971
- const { data, position } = serializedFloatingGroup;
5972
- const group = createGroupFromSerializedState(data);
5973
- this.addFloatingGroup(group, {
5974
- x: position.left,
5975
- y: position.top,
5976
- height: position.height,
5977
- width: position.width,
5978
- }, { skipRemoveGroup: true, inDragMode: false });
5979
- }
5980
- for (const floatingGroup of this.floatingGroups) {
5981
- floatingGroup.overlay.setBounds();
5982
- }
5983
- if (typeof activeGroup === 'string') {
5984
- const panel = this.getPanel(activeGroup);
5985
- if (panel) {
5986
- this.doSetGroupActive(panel);
6073
+ /**
6074
+ * To remove a group we cannot call this.removeGroup(...) since this makes assumptions about
6075
+ * the underlying HTMLElement existing in the Gridview.
6076
+ */
6077
+ for (const group of this.groups) {
6078
+ group.dispose();
6079
+ this._groups.delete(group.id);
6080
+ this._onDidRemoveGroup.fire(group);
6081
+ }
6082
+ // iterate over a reassigned array since original array will be modified
6083
+ for (const floatingGroup of [...this.floatingGroups]) {
6084
+ floatingGroup.dispose();
5987
6085
  }
6086
+ // fires clean-up events and clears the underlying HTML gridview.
6087
+ this.clear();
6088
+ /**
6089
+ * even though we have cleaned-up we still want to inform the caller of their error
6090
+ * and we'll do this through re-throwing the original error since afterall you would
6091
+ * expect trying to load a corrupted layout to result in an error and not silently fail...
6092
+ */
6093
+ throw err;
5988
6094
  }
5989
6095
  this._onDidLayoutFromJSON.fire();
5990
6096
  }
@@ -6198,6 +6304,7 @@
6198
6304
  if (!(options === null || options === void 0 ? void 0 : options.skipDispose)) {
6199
6305
  floatingGroup.group.dispose();
6200
6306
  this._groups.delete(group.id);
6307
+ // TODO: fire group removed event?
6201
6308
  }
6202
6309
  floatingGroup.dispose();
6203
6310
  return floatingGroup.group;
@@ -6438,42 +6545,63 @@
6438
6545
  fromJSON(serializedGridview) {
6439
6546
  this.clear();
6440
6547
  const { grid, activePanel } = serializedGridview;
6441
- const queue = [];
6442
- // take note of the existing dimensions
6443
- const width = this.width;
6444
- const height = this.height;
6445
- this.gridview.deserialize(grid, {
6446
- fromJSON: (node) => {
6447
- const { data } = node;
6448
- const view = createComponent(data.id, data.component, this.options.components || {}, this.options.frameworkComponents || {}, this.options.frameworkComponentFactory
6449
- ? {
6450
- createComponent: this.options.frameworkComponentFactory
6451
- .createComponent,
6452
- }
6453
- : undefined);
6454
- queue.push(() => view.init({
6455
- params: data.params,
6456
- minimumWidth: data.minimumWidth,
6457
- maximumWidth: data.maximumWidth,
6458
- minimumHeight: data.minimumHeight,
6459
- maximumHeight: data.maximumHeight,
6460
- priority: data.priority,
6461
- snap: !!data.snap,
6462
- accessor: this,
6463
- isVisible: node.visible,
6464
- }));
6465
- this._onDidAddGroup.fire(view);
6466
- this.registerPanel(view);
6467
- return view;
6468
- },
6469
- });
6470
- this.layout(width, height, true);
6471
- queue.forEach((f) => f());
6472
- if (typeof activePanel === 'string') {
6473
- const panel = this.getPanel(activePanel);
6474
- if (panel) {
6475
- this.doSetGroupActive(panel);
6548
+ try {
6549
+ const queue = [];
6550
+ // take note of the existing dimensions
6551
+ const width = this.width;
6552
+ const height = this.height;
6553
+ this.gridview.deserialize(grid, {
6554
+ fromJSON: (node) => {
6555
+ const { data } = node;
6556
+ const view = createComponent(data.id, data.component, this.options.components || {}, this.options.frameworkComponents || {}, this.options.frameworkComponentFactory
6557
+ ? {
6558
+ createComponent: this.options.frameworkComponentFactory
6559
+ .createComponent,
6560
+ }
6561
+ : undefined);
6562
+ queue.push(() => view.init({
6563
+ params: data.params,
6564
+ minimumWidth: data.minimumWidth,
6565
+ maximumWidth: data.maximumWidth,
6566
+ minimumHeight: data.minimumHeight,
6567
+ maximumHeight: data.maximumHeight,
6568
+ priority: data.priority,
6569
+ snap: !!data.snap,
6570
+ accessor: this,
6571
+ isVisible: node.visible,
6572
+ }));
6573
+ this._onDidAddGroup.fire(view);
6574
+ this.registerPanel(view);
6575
+ return view;
6576
+ },
6577
+ });
6578
+ this.layout(width, height, true);
6579
+ queue.forEach((f) => f());
6580
+ if (typeof activePanel === 'string') {
6581
+ const panel = this.getPanel(activePanel);
6582
+ if (panel) {
6583
+ this.doSetGroupActive(panel);
6584
+ }
6585
+ }
6586
+ }
6587
+ catch (err) {
6588
+ /**
6589
+ * To remove a group we cannot call this.removeGroup(...) since this makes assumptions about
6590
+ * the underlying HTMLElement existing in the Gridview.
6591
+ */
6592
+ for (const group of this.groups) {
6593
+ group.dispose();
6594
+ this._groups.delete(group.id);
6595
+ this._onDidRemoveGroup.fire(group);
6476
6596
  }
6597
+ // fires clean-up events and clears the underlying HTML gridview.
6598
+ this.clear();
6599
+ /**
6600
+ * even though we have cleaned-up we still want to inform the caller of their error
6601
+ * and we'll do this through re-throwing the original error since afterall you would
6602
+ * expect trying to load a corrupted layout to result in an error and not silently fail...
6603
+ */
6604
+ throw err;
6477
6605
  }
6478
6606
  this._onDidLayoutfromJSON.fire();
6479
6607
  }