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