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
  */
@@ -872,7 +872,17 @@
872
872
  size = typeof size === 'number' ? size : item.size;
873
873
  size = clamp(size, item.minimumSize, item.maximumSize);
874
874
  item.size = size;
875
- this.relayout([index]);
875
+ const indexes = range(this.viewItems.length).filter((i) => i !== index);
876
+ const lowPriorityIndexes = [
877
+ ...indexes.filter((i) => this.viewItems[i].priority === exports.LayoutPriority.Low),
878
+ index,
879
+ ];
880
+ const highPriorityIndexes = indexes.filter((i) => this.viewItems[i].priority === exports.LayoutPriority.High);
881
+ /**
882
+ * add this view we are changing to the low-index list since we have determined the size
883
+ * here and don't want it changed
884
+ */
885
+ this.relayout([...lowPriorityIndexes, index], highPriorityIndexes);
876
886
  }
877
887
  addView(view, size = { type: 'distribute' }, index = this.viewItems.length, skipLayout) {
878
888
  const container = document.createElement('div');
@@ -1629,6 +1639,7 @@
1629
1639
  orientation: this.orientation,
1630
1640
  descriptor,
1631
1641
  proportionalLayout,
1642
+ styles,
1632
1643
  });
1633
1644
  }
1634
1645
  this.addDisposables(this._onDidChange, this.splitview.onDidSashEnd(() => {
@@ -2140,6 +2151,14 @@
2140
2151
  const child = sibling.children[i];
2141
2152
  grandParent.addChild(child, child.size, parentIndex + i);
2142
2153
  }
2154
+ /**
2155
+ * clean down the branch node since we need to dipose of it and
2156
+ * when .dispose() it called on a branch it will dispose of any
2157
+ * views it is holding onto.
2158
+ */
2159
+ while (sibling.children.length > 0) {
2160
+ sibling.removeChild(0);
2161
+ }
2143
2162
  }
2144
2163
  else {
2145
2164
  // otherwise create a new leaf node and add that to the grandparent
@@ -3198,6 +3217,19 @@
3198
3217
  this.leftActions = element;
3199
3218
  }
3200
3219
  }
3220
+ setPrefixActionsElement(element) {
3221
+ if (this.preActions === element) {
3222
+ return;
3223
+ }
3224
+ if (this.preActions) {
3225
+ this.preActions.remove();
3226
+ this.preActions = undefined;
3227
+ }
3228
+ if (element) {
3229
+ this.preActionsContainer.appendChild(element);
3230
+ this.preActions = element;
3231
+ }
3232
+ }
3201
3233
  get element() {
3202
3234
  return this._element;
3203
3235
  }
@@ -3238,9 +3270,12 @@
3238
3270
  this.rightActionsContainer.className = 'right-actions-container';
3239
3271
  this.leftActionsContainer = document.createElement('div');
3240
3272
  this.leftActionsContainer.className = 'left-actions-container';
3273
+ this.preActionsContainer = document.createElement('div');
3274
+ this.preActionsContainer.className = 'pre-actions-container';
3241
3275
  this.tabContainer = document.createElement('div');
3242
3276
  this.tabContainer.className = 'tabs-container';
3243
3277
  this.voidContainer = new VoidContainer(this.accessor, this.group);
3278
+ this._element.appendChild(this.preActionsContainer);
3244
3279
  this._element.appendChild(this.tabContainer);
3245
3280
  this._element.appendChild(this.leftActionsContainer);
3246
3281
  this._element.appendChild(this.voidContainer.element);
@@ -3530,6 +3565,16 @@
3530
3565
  });
3531
3566
  this.tabsContainer.setLeftActionsElement(this._leftHeaderActions.element);
3532
3567
  }
3568
+ if (this.accessor.options.createPrefixHeaderActionsElement) {
3569
+ this._prefixHeaderActions =
3570
+ this.accessor.options.createPrefixHeaderActionsElement(this.groupPanel);
3571
+ this.addDisposables(this._prefixHeaderActions);
3572
+ this._prefixHeaderActions.init({
3573
+ containerApi: new DockviewApi(this.accessor),
3574
+ api: this.groupPanel.api,
3575
+ });
3576
+ this.tabsContainer.setPrefixActionsElement(this._prefixHeaderActions.element);
3577
+ }
3533
3578
  }
3534
3579
  indexOf(panel) {
3535
3580
  return this.tabsContainer.indexOf(panel.id);
@@ -3872,6 +3917,14 @@
3872
3917
  */
3873
3918
  return;
3874
3919
  }
3920
+ if (!document.body.contains(this._element)) {
3921
+ /**
3922
+ * since the event is dispatched through requestAnimationFrame there is a small chance
3923
+ * the component is no longer attached to the DOM, if that is the case the dimensions
3924
+ * are mostly likely all zero and meaningless. we should skip this case.
3925
+ */
3926
+ return;
3927
+ }
3875
3928
  const { width, height } = entry.contentRect;
3876
3929
  this.layout(width, height);
3877
3930
  }));
@@ -5900,61 +5953,114 @@
5900
5953
  fromJSON(data) {
5901
5954
  var _a;
5902
5955
  this.clear();
5956
+ if (typeof data !== 'object' || data === null) {
5957
+ throw new Error('serialized layout must be a non-null object');
5958
+ }
5903
5959
  const { grid, panels, activeGroup } = data;
5904
5960
  if (grid.root.type !== 'branch' || !Array.isArray(grid.root.data)) {
5905
5961
  throw new Error('root must be of type branch');
5906
5962
  }
5907
- // take note of the existing dimensions
5908
- const width = this.width;
5909
- const height = this.height;
5910
- const createGroupFromSerializedState = (data) => {
5911
- const { id, locked, hideHeader, views, activeView } = data;
5912
- const group = this.createGroup({
5913
- id,
5914
- locked: !!locked,
5915
- hideHeader: !!hideHeader,
5916
- });
5917
- this._onDidAddGroup.fire(group);
5918
- for (const child of views) {
5919
- const panel = this._deserializer.fromJSON(panels[child], group);
5920
- const isActive = typeof activeView === 'string' && activeView === panel.id;
5921
- group.model.openPanel(panel, {
5922
- skipSetPanelActive: !isActive,
5923
- skipSetGroupActive: true,
5963
+ try {
5964
+ // take note of the existing dimensions
5965
+ const width = this.width;
5966
+ const height = this.height;
5967
+ const createGroupFromSerializedState = (data) => {
5968
+ const { id, locked, hideHeader, views, activeView } = data;
5969
+ if (typeof id !== 'string') {
5970
+ throw new Error('group id must be of type string');
5971
+ }
5972
+ const group = this.createGroup({
5973
+ id,
5974
+ locked: !!locked,
5975
+ hideHeader: !!hideHeader,
5924
5976
  });
5977
+ const createdPanels = [];
5978
+ for (const child of views) {
5979
+ /**
5980
+ * Run the deserializer step seperately since this may fail to due corrupted external state.
5981
+ * In running this section first we avoid firing lots of 'add' events in the event of a failure
5982
+ * due to a corruption of input data.
5983
+ */
5984
+ const panel = this._deserializer.fromJSON(panels[child], group);
5985
+ createdPanels.push(panel);
5986
+ }
5987
+ this._onDidAddGroup.fire(group);
5988
+ for (let i = 0; i < views.length; i++) {
5989
+ const panel = createdPanels[i];
5990
+ const isActive = typeof activeView === 'string' &&
5991
+ activeView === panel.id;
5992
+ group.model.openPanel(panel, {
5993
+ skipSetPanelActive: !isActive,
5994
+ skipSetGroupActive: true,
5995
+ });
5996
+ }
5997
+ if (!group.activePanel && group.panels.length > 0) {
5998
+ group.model.openPanel(group.panels[group.panels.length - 1], {
5999
+ skipSetGroupActive: true,
6000
+ });
6001
+ }
6002
+ return group;
6003
+ };
6004
+ this.gridview.deserialize(grid, {
6005
+ fromJSON: (node) => {
6006
+ return createGroupFromSerializedState(node.data);
6007
+ },
6008
+ });
6009
+ this.layout(width, height, true);
6010
+ const serializedFloatingGroups = (_a = data.floatingGroups) !== null && _a !== void 0 ? _a : [];
6011
+ for (const serializedFloatingGroup of serializedFloatingGroups) {
6012
+ const { data, position } = serializedFloatingGroup;
6013
+ const group = createGroupFromSerializedState(data);
6014
+ this.addFloatingGroup(group, {
6015
+ x: position.left,
6016
+ y: position.top,
6017
+ height: position.height,
6018
+ width: position.width,
6019
+ }, { skipRemoveGroup: true, inDragMode: false });
6020
+ }
6021
+ for (const floatingGroup of this.floatingGroups) {
6022
+ floatingGroup.overlay.setBounds();
6023
+ }
6024
+ if (typeof activeGroup === 'string') {
6025
+ const panel = this.getPanel(activeGroup);
6026
+ if (panel) {
6027
+ this.doSetGroupActive(panel);
6028
+ }
5925
6029
  }
5926
- if (!group.activePanel && group.panels.length > 0) {
5927
- group.model.openPanel(group.panels[group.panels.length - 1], {
5928
- skipSetGroupActive: true,
5929
- });
6030
+ }
6031
+ catch (err) {
6032
+ /**
6033
+ * Takes all the successfully created groups and remove all of their panels.
6034
+ */
6035
+ for (const group of this.groups) {
6036
+ for (const panel of group.panels) {
6037
+ this.removePanel(panel, {
6038
+ removeEmptyGroup: false,
6039
+ skipDispose: false,
6040
+ });
6041
+ }
5930
6042
  }
5931
- return group;
5932
- };
5933
- this.gridview.deserialize(grid, {
5934
- fromJSON: (node) => {
5935
- return createGroupFromSerializedState(node.data);
5936
- },
5937
- });
5938
- this.layout(width, height, true);
5939
- const serializedFloatingGroups = (_a = data.floatingGroups) !== null && _a !== void 0 ? _a : [];
5940
- for (const serializedFloatingGroup of serializedFloatingGroups) {
5941
- const { data, position } = serializedFloatingGroup;
5942
- const group = createGroupFromSerializedState(data);
5943
- this.addFloatingGroup(group, {
5944
- x: position.left,
5945
- y: position.top,
5946
- height: position.height,
5947
- width: position.width,
5948
- }, { skipRemoveGroup: true, inDragMode: false });
5949
- }
5950
- for (const floatingGroup of this.floatingGroups) {
5951
- floatingGroup.overlay.setBounds();
5952
- }
5953
- if (typeof activeGroup === 'string') {
5954
- const panel = this.getPanel(activeGroup);
5955
- if (panel) {
5956
- this.doSetGroupActive(panel);
6043
+ /**
6044
+ * To remove a group we cannot call this.removeGroup(...) since this makes assumptions about
6045
+ * the underlying HTMLElement existing in the Gridview.
6046
+ */
6047
+ for (const group of this.groups) {
6048
+ group.dispose();
6049
+ this._groups.delete(group.id);
6050
+ this._onDidRemoveGroup.fire(group);
6051
+ }
6052
+ // iterate over a reassigned array since original array will be modified
6053
+ for (const floatingGroup of [...this.floatingGroups]) {
6054
+ floatingGroup.dispose();
5957
6055
  }
6056
+ // fires clean-up events and clears the underlying HTML gridview.
6057
+ this.clear();
6058
+ /**
6059
+ * even though we have cleaned-up we still want to inform the caller of their error
6060
+ * and we'll do this through re-throwing the original error since afterall you would
6061
+ * expect trying to load a corrupted layout to result in an error and not silently fail...
6062
+ */
6063
+ throw err;
5958
6064
  }
5959
6065
  this._onDidLayoutFromJSON.fire();
5960
6066
  }
@@ -6168,6 +6274,7 @@
6168
6274
  if (!(options === null || options === void 0 ? void 0 : options.skipDispose)) {
6169
6275
  floatingGroup.group.dispose();
6170
6276
  this._groups.delete(group.id);
6277
+ // TODO: fire group removed event?
6171
6278
  }
6172
6279
  floatingGroup.dispose();
6173
6280
  return floatingGroup.group;
@@ -6408,42 +6515,63 @@
6408
6515
  fromJSON(serializedGridview) {
6409
6516
  this.clear();
6410
6517
  const { grid, activePanel } = serializedGridview;
6411
- const queue = [];
6412
- // take note of the existing dimensions
6413
- const width = this.width;
6414
- const height = this.height;
6415
- this.gridview.deserialize(grid, {
6416
- fromJSON: (node) => {
6417
- const { data } = node;
6418
- const view = createComponent(data.id, data.component, this.options.components || {}, this.options.frameworkComponents || {}, this.options.frameworkComponentFactory
6419
- ? {
6420
- createComponent: this.options.frameworkComponentFactory
6421
- .createComponent,
6422
- }
6423
- : undefined);
6424
- queue.push(() => view.init({
6425
- params: data.params,
6426
- minimumWidth: data.minimumWidth,
6427
- maximumWidth: data.maximumWidth,
6428
- minimumHeight: data.minimumHeight,
6429
- maximumHeight: data.maximumHeight,
6430
- priority: data.priority,
6431
- snap: !!data.snap,
6432
- accessor: this,
6433
- isVisible: node.visible,
6434
- }));
6435
- this._onDidAddGroup.fire(view);
6436
- this.registerPanel(view);
6437
- return view;
6438
- },
6439
- });
6440
- this.layout(width, height, true);
6441
- queue.forEach((f) => f());
6442
- if (typeof activePanel === 'string') {
6443
- const panel = this.getPanel(activePanel);
6444
- if (panel) {
6445
- this.doSetGroupActive(panel);
6518
+ try {
6519
+ const queue = [];
6520
+ // take note of the existing dimensions
6521
+ const width = this.width;
6522
+ const height = this.height;
6523
+ this.gridview.deserialize(grid, {
6524
+ fromJSON: (node) => {
6525
+ const { data } = node;
6526
+ const view = createComponent(data.id, data.component, this.options.components || {}, this.options.frameworkComponents || {}, this.options.frameworkComponentFactory
6527
+ ? {
6528
+ createComponent: this.options.frameworkComponentFactory
6529
+ .createComponent,
6530
+ }
6531
+ : undefined);
6532
+ queue.push(() => view.init({
6533
+ params: data.params,
6534
+ minimumWidth: data.minimumWidth,
6535
+ maximumWidth: data.maximumWidth,
6536
+ minimumHeight: data.minimumHeight,
6537
+ maximumHeight: data.maximumHeight,
6538
+ priority: data.priority,
6539
+ snap: !!data.snap,
6540
+ accessor: this,
6541
+ isVisible: node.visible,
6542
+ }));
6543
+ this._onDidAddGroup.fire(view);
6544
+ this.registerPanel(view);
6545
+ return view;
6546
+ },
6547
+ });
6548
+ this.layout(width, height, true);
6549
+ queue.forEach((f) => f());
6550
+ if (typeof activePanel === 'string') {
6551
+ const panel = this.getPanel(activePanel);
6552
+ if (panel) {
6553
+ this.doSetGroupActive(panel);
6554
+ }
6555
+ }
6556
+ }
6557
+ catch (err) {
6558
+ /**
6559
+ * To remove a group we cannot call this.removeGroup(...) since this makes assumptions about
6560
+ * the underlying HTMLElement existing in the Gridview.
6561
+ */
6562
+ for (const group of this.groups) {
6563
+ group.dispose();
6564
+ this._groups.delete(group.id);
6565
+ this._onDidRemoveGroup.fire(group);
6446
6566
  }
6567
+ // fires clean-up events and clears the underlying HTML gridview.
6568
+ this.clear();
6569
+ /**
6570
+ * even though we have cleaned-up we still want to inform the caller of their error
6571
+ * and we'll do this through re-throwing the original error since afterall you would
6572
+ * expect trying to load a corrupted layout to result in an error and not silently fail...
6573
+ */
6574
+ throw err;
6447
6575
  }
6448
6576
  this._onDidLayoutfromJSON.fire();
6449
6577
  }