dockview-core 4.11.0 → 4.12.0

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 (41) hide show
  1. package/dist/cjs/api/component.api.d.ts +3 -1
  2. package/dist/cjs/api/component.api.js +2 -2
  3. package/dist/cjs/dockview/components/panel/content.d.ts +7 -0
  4. package/dist/cjs/dockview/components/panel/content.js +11 -0
  5. package/dist/cjs/dockview/dockviewComponent.d.ts +7 -1
  6. package/dist/cjs/dockview/dockviewComponent.js +159 -84
  7. package/dist/cjs/dockview/dockviewGroupPanelModel.js +3 -0
  8. package/dist/cjs/dockview/dockviewPanel.d.ts +6 -4
  9. package/dist/cjs/dockview/dockviewPanel.js +12 -0
  10. package/dist/dockview-core.amd.js +119 -34
  11. package/dist/dockview-core.amd.js.map +1 -1
  12. package/dist/dockview-core.amd.min.js +2 -2
  13. package/dist/dockview-core.amd.min.js.map +1 -1
  14. package/dist/dockview-core.amd.min.noStyle.js +2 -2
  15. package/dist/dockview-core.amd.min.noStyle.js.map +1 -1
  16. package/dist/dockview-core.amd.noStyle.js +119 -34
  17. package/dist/dockview-core.amd.noStyle.js.map +1 -1
  18. package/dist/dockview-core.cjs.js +119 -34
  19. package/dist/dockview-core.cjs.js.map +1 -1
  20. package/dist/dockview-core.esm.js +119 -34
  21. package/dist/dockview-core.esm.js.map +1 -1
  22. package/dist/dockview-core.esm.min.js +2 -2
  23. package/dist/dockview-core.esm.min.js.map +1 -1
  24. package/dist/dockview-core.js +119 -34
  25. package/dist/dockview-core.js.map +1 -1
  26. package/dist/dockview-core.min.js +2 -2
  27. package/dist/dockview-core.min.js.map +1 -1
  28. package/dist/dockview-core.min.noStyle.js +2 -2
  29. package/dist/dockview-core.min.noStyle.js.map +1 -1
  30. package/dist/dockview-core.noStyle.js +119 -34
  31. package/dist/dockview-core.noStyle.js.map +1 -1
  32. package/dist/esm/api/component.api.d.ts +3 -1
  33. package/dist/esm/api/component.api.js +2 -2
  34. package/dist/esm/dockview/components/panel/content.d.ts +7 -0
  35. package/dist/esm/dockview/components/panel/content.js +11 -0
  36. package/dist/esm/dockview/dockviewComponent.d.ts +7 -1
  37. package/dist/esm/dockview/dockviewComponent.js +90 -31
  38. package/dist/esm/dockview/dockviewGroupPanelModel.js +3 -0
  39. package/dist/esm/dockview/dockviewPanel.d.ts +6 -4
  40. package/dist/esm/dockview/dockviewPanel.js +12 -0
  41. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * dockview-core
3
- * @version 4.11.0
3
+ * @version 4.12.0
4
4
  * @link https://github.com/mathuo/dockview
5
5
  * @license MIT
6
6
  */
@@ -3779,8 +3779,8 @@ class DockviewApi {
3779
3779
  /**
3780
3780
  * Create a component from a serialized object.
3781
3781
  */
3782
- fromJSON(data) {
3783
- this.component.fromJSON(data);
3782
+ fromJSON(data, options) {
3783
+ this.component.fromJSON(data, options);
3784
3784
  }
3785
3785
  /**
3786
3786
  * Create a serialized object of the current component.
@@ -5011,6 +5011,7 @@ class ContentContainer extends CompositeDisposable {
5011
5011
  }
5012
5012
  if (doRender) {
5013
5013
  const focusTracker = trackFocus(container);
5014
+ this.focusTracker = focusTracker;
5014
5015
  const disposable = new CompositeDisposable();
5015
5016
  disposable.addDisposables(focusTracker, focusTracker.onDidFocus(() => this._onDidFocus.fire()), focusTracker.onDidBlur(() => this._onDidBlur.fire()));
5016
5017
  this.disposable.value = disposable;
@@ -5038,6 +5039,16 @@ class ContentContainer extends CompositeDisposable {
5038
5039
  this.disposable.dispose();
5039
5040
  super.dispose();
5040
5041
  }
5042
+ /**
5043
+ * Refresh the focus tracker state to handle cases where focus state
5044
+ * gets out of sync due to programmatic panel activation
5045
+ */
5046
+ refreshFocusState() {
5047
+ var _a;
5048
+ if ((_a = this.focusTracker) === null || _a === void 0 ? void 0 : _a.refreshState) {
5049
+ this.focusTracker.refreshState();
5050
+ }
5051
+ }
5041
5052
  }
5042
5053
 
5043
5054
  function addGhostImage(dataTransfer, ghostElement, options) {
@@ -6364,8 +6375,11 @@ class DockviewGroupPanelModel extends CompositeDisposable {
6364
6375
  this._activePanel = panel;
6365
6376
  if (panel) {
6366
6377
  this.tabsContainer.setActivePanel(panel);
6378
+ this.contentContainer.openPanel(panel);
6367
6379
  panel.layout(this._width, this._height);
6368
6380
  this.updateMru(panel);
6381
+ // Refresh focus state to handle programmatic activation without DOM focus change
6382
+ this.contentContainer.refreshFocusState();
6369
6383
  this._onDidActivePanelChange.fire({
6370
6384
  panel,
6371
6385
  });
@@ -7195,6 +7209,18 @@ class DockviewPanel extends CompositeDisposable {
7195
7209
  params: this._params,
7196
7210
  });
7197
7211
  }
7212
+ updateFromStateModel(state) {
7213
+ var _a, _b, _c;
7214
+ this._maximumHeight = state.maximumHeight;
7215
+ this._minimumHeight = state.minimumHeight;
7216
+ this._maximumWidth = state.maximumWidth;
7217
+ this._minimumWidth = state.minimumWidth;
7218
+ this.update({ params: (_a = state.params) !== null && _a !== void 0 ? _a : {} });
7219
+ this.setTitle((_b = state.title) !== null && _b !== void 0 ? _b : this.id);
7220
+ this.setRenderer((_c = state.renderer) !== null && _c !== void 0 ? _c : this.accessor.renderer);
7221
+ // state.contentComponent;
7222
+ // state.tabComponent;
7223
+ }
7198
7224
  updateParentGroup(group, options) {
7199
7225
  this._group = group;
7200
7226
  this.api.group = this._group;
@@ -8981,7 +9007,7 @@ class DockviewComponent extends BaseGrid {
8981
9007
  : (_e = (_d = this.options.floatingGroupBounds) === null || _d === void 0 ? void 0 : _d.minimumHeightWithinViewport) !== null && _e !== void 0 ? _e : DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE }));
8982
9008
  const el = group.element.querySelector('.dv-void-container');
8983
9009
  if (!el) {
8984
- throw new Error('failed to find drag handle');
9010
+ throw new Error('dockview: failed to find drag handle');
8985
9011
  }
8986
9012
  overlay.setupDrag(el, {
8987
9013
  inDragMode: typeof (options === null || options === void 0 ? void 0 : options.inDragMode) === 'boolean'
@@ -9053,7 +9079,7 @@ class DockviewComponent extends BaseGrid {
9053
9079
  case 'right':
9054
9080
  return this.createGroupAtLocation([this.gridview.length], undefined, options); // insert into last position
9055
9081
  default:
9056
- throw new Error(`unsupported position ${position}`);
9082
+ throw new Error(`dockview: unsupported position ${position}`);
9057
9083
  }
9058
9084
  }
9059
9085
  updateOptions(options) {
@@ -9199,15 +9225,48 @@ class DockviewComponent extends BaseGrid {
9199
9225
  }
9200
9226
  return result;
9201
9227
  }
9202
- fromJSON(data) {
9228
+ fromJSON(data, options) {
9203
9229
  var _a, _b;
9230
+ const existingPanels = new Map();
9231
+ let tempGroup;
9232
+ if (options === null || options === void 0 ? void 0 : options.reuseExistingPanels) {
9233
+ /**
9234
+ * What are we doing here?
9235
+ *
9236
+ * 1. Create a temporary group to hold any panels that currently exist and that also exist in the new layout
9237
+ * 2. Remove that temporary group from the group mapping so that it doesn't get cleared when we clear the layout
9238
+ */
9239
+ tempGroup = this.createGroup();
9240
+ this._groups.delete(tempGroup.api.id);
9241
+ const newPanels = Object.keys(data.panels);
9242
+ for (const panel of this.panels) {
9243
+ if (newPanels.includes(panel.api.id)) {
9244
+ existingPanels.set(panel.api.id, panel);
9245
+ }
9246
+ }
9247
+ this.movingLock(() => {
9248
+ Array.from(existingPanels.values()).forEach((panel) => {
9249
+ this.moveGroupOrPanel({
9250
+ from: {
9251
+ groupId: panel.api.group.api.id,
9252
+ panelId: panel.api.id,
9253
+ },
9254
+ to: {
9255
+ group: tempGroup,
9256
+ position: 'center',
9257
+ },
9258
+ keepEmptyGroups: true,
9259
+ });
9260
+ });
9261
+ });
9262
+ }
9204
9263
  this.clear();
9205
9264
  if (typeof data !== 'object' || data === null) {
9206
- throw new Error('serialized layout must be a non-null object');
9265
+ throw new Error('dockview: serialized layout must be a non-null object');
9207
9266
  }
9208
9267
  const { grid, panels, activeGroup } = data;
9209
9268
  if (grid.root.type !== 'branch' || !Array.isArray(grid.root.data)) {
9210
- throw new Error('root must be of type branch');
9269
+ throw new Error('dockview: root must be of type branch');
9211
9270
  }
9212
9271
  try {
9213
9272
  // take note of the existing dimensions
@@ -9216,7 +9275,7 @@ class DockviewComponent extends BaseGrid {
9216
9275
  const createGroupFromSerializedState = (data) => {
9217
9276
  const { id, locked, hideHeader, views, activeView } = data;
9218
9277
  if (typeof id !== 'string') {
9219
- throw new Error('group id must be of type string');
9278
+ throw new Error('dockview: group id must be of type string');
9220
9279
  }
9221
9280
  const group = this.createGroup({
9222
9281
  id,
@@ -9231,17 +9290,38 @@ class DockviewComponent extends BaseGrid {
9231
9290
  * In running this section first we avoid firing lots of 'add' events in the event of a failure
9232
9291
  * due to a corruption of input data.
9233
9292
  */
9234
- const panel = this._deserializer.fromJSON(panels[child], group);
9235
- createdPanels.push(panel);
9293
+ const existingPanel = existingPanels.get(child);
9294
+ if (tempGroup && existingPanel) {
9295
+ this.movingLock(() => {
9296
+ tempGroup.model.removePanel(existingPanel);
9297
+ });
9298
+ createdPanels.push(existingPanel);
9299
+ existingPanel.updateFromStateModel(panels[child]);
9300
+ }
9301
+ else {
9302
+ const panel = this._deserializer.fromJSON(panels[child], group);
9303
+ createdPanels.push(panel);
9304
+ }
9236
9305
  }
9237
9306
  for (let i = 0; i < views.length; i++) {
9238
9307
  const panel = createdPanels[i];
9239
9308
  const isActive = typeof activeView === 'string' &&
9240
9309
  activeView === panel.id;
9241
- group.model.openPanel(panel, {
9242
- skipSetActive: !isActive,
9243
- skipSetGroupActive: true,
9244
- });
9310
+ const hasExisting = existingPanels.has(panel.api.id);
9311
+ if (hasExisting) {
9312
+ this.movingLock(() => {
9313
+ group.model.openPanel(panel, {
9314
+ skipSetActive: !isActive,
9315
+ skipSetGroupActive: true,
9316
+ });
9317
+ });
9318
+ }
9319
+ else {
9320
+ group.model.openPanel(panel, {
9321
+ skipSetActive: !isActive,
9322
+ skipSetGroupActive: true,
9323
+ });
9324
+ }
9245
9325
  }
9246
9326
  if (!group.activePanel && group.panels.length > 0) {
9247
9327
  group.model.openPanel(group.panels[group.panels.length - 1], {
@@ -9280,7 +9360,9 @@ class DockviewComponent extends BaseGrid {
9280
9360
  setTimeout(() => {
9281
9361
  this.addPopoutGroup(group, {
9282
9362
  position: position !== null && position !== void 0 ? position : undefined,
9283
- overridePopoutGroup: gridReferenceGroup ? group : undefined,
9363
+ overridePopoutGroup: gridReferenceGroup
9364
+ ? group
9365
+ : undefined,
9284
9366
  referenceGroup: gridReferenceGroup
9285
9367
  ? this.getPanel(gridReferenceGroup)
9286
9368
  : undefined,
@@ -9366,11 +9448,11 @@ class DockviewComponent extends BaseGrid {
9366
9448
  addPanel(options) {
9367
9449
  var _a, _b;
9368
9450
  if (this.panels.find((_) => _.id === options.id)) {
9369
- throw new Error(`panel with id ${options.id} already exists`);
9451
+ throw new Error(`dockview: panel with id ${options.id} already exists`);
9370
9452
  }
9371
9453
  let referenceGroup;
9372
9454
  if (options.position && options.floating) {
9373
- throw new Error('you can only provide one of: position, floating as arguments to .addPanel(...)');
9455
+ throw new Error('dockview: you can only provide one of: position, floating as arguments to .addPanel(...)');
9374
9456
  }
9375
9457
  const initial = {
9376
9458
  width: options.initialWidth,
@@ -9384,7 +9466,7 @@ class DockviewComponent extends BaseGrid {
9384
9466
  : options.position.referencePanel;
9385
9467
  index = options.position.index;
9386
9468
  if (!referencePanel) {
9387
- throw new Error(`referencePanel '${options.position.referencePanel}' does not exist`);
9469
+ throw new Error(`dockview: referencePanel '${options.position.referencePanel}' does not exist`);
9388
9470
  }
9389
9471
  referenceGroup = this.findGroup(referencePanel);
9390
9472
  }
@@ -9395,7 +9477,7 @@ class DockviewComponent extends BaseGrid {
9395
9477
  : options.position.referenceGroup;
9396
9478
  index = options.position.index;
9397
9479
  if (!referenceGroup) {
9398
- throw new Error(`referenceGroup '${options.position.referenceGroup}' does not exist`);
9480
+ throw new Error(`dockview: referenceGroup '${options.position.referenceGroup}' does not exist`);
9399
9481
  }
9400
9482
  }
9401
9483
  else {
@@ -9507,7 +9589,7 @@ class DockviewComponent extends BaseGrid {
9507
9589
  }) {
9508
9590
  const group = panel.group;
9509
9591
  if (!group) {
9510
- throw new Error(`cannot remove panel ${panel.id}. it's missing a group.`);
9592
+ throw new Error(`dockview: cannot remove panel ${panel.id}. it's missing a group.`);
9511
9593
  }
9512
9594
  group.model.removePanel(panel, {
9513
9595
  skipSetActiveGroup: options.skipSetActiveGroup,
@@ -9556,11 +9638,11 @@ class DockviewComponent extends BaseGrid {
9556
9638
  ? this.panels.find((panel) => panel.id === options.referencePanel)
9557
9639
  : options.referencePanel;
9558
9640
  if (!referencePanel) {
9559
- throw new Error(`reference panel ${options.referencePanel} does not exist`);
9641
+ throw new Error(`dockview: reference panel ${options.referencePanel} does not exist`);
9560
9642
  }
9561
9643
  referenceGroup = this.findGroup(referencePanel);
9562
9644
  if (!referenceGroup) {
9563
- throw new Error(`reference group for reference panel ${options.referencePanel} does not exist`);
9645
+ throw new Error(`dockview: reference group for reference panel ${options.referencePanel} does not exist`);
9564
9646
  }
9565
9647
  }
9566
9648
  else if (isGroupOptionsWithGroup(options)) {
@@ -9569,7 +9651,7 @@ class DockviewComponent extends BaseGrid {
9569
9651
  ? (_a = this._groups.get(options.referenceGroup)) === null || _a === void 0 ? void 0 : _a.value
9570
9652
  : options.referenceGroup;
9571
9653
  if (!referenceGroup) {
9572
- throw new Error(`reference group ${options.referenceGroup} does not exist`);
9654
+ throw new Error(`dockview: reference group ${options.referenceGroup} does not exist`);
9573
9655
  }
9574
9656
  }
9575
9657
  else {
@@ -9637,7 +9719,7 @@ class DockviewComponent extends BaseGrid {
9637
9719
  }
9638
9720
  return floatingGroup.group;
9639
9721
  }
9640
- throw new Error('failed to find floating group');
9722
+ throw new Error('dockview: failed to find floating group');
9641
9723
  }
9642
9724
  if (group.api.location.type === 'popout') {
9643
9725
  const selectedGroup = this._popoutGroups.find((_) => _.popoutGroup === group);
@@ -9668,7 +9750,7 @@ class DockviewComponent extends BaseGrid {
9668
9750
  this.updateWatermark();
9669
9751
  return selectedGroup.popoutGroup;
9670
9752
  }
9671
- throw new Error('failed to find popout group');
9753
+ throw new Error('dockview: failed to find popout group');
9672
9754
  }
9673
9755
  const re = super.doRemoveGroup(group, options);
9674
9756
  if (!(options === null || options === void 0 ? void 0 : options.skipActive)) {
@@ -9699,7 +9781,7 @@ class DockviewComponent extends BaseGrid {
9699
9781
  ? (_a = this._groups.get(sourceGroupId)) === null || _a === void 0 ? void 0 : _a.value
9700
9782
  : undefined;
9701
9783
  if (!sourceGroup) {
9702
- throw new Error(`Failed to find group id ${sourceGroupId}`);
9784
+ throw new Error(`dockview: Failed to find group id ${sourceGroupId}`);
9703
9785
  }
9704
9786
  if (sourceItemId === undefined) {
9705
9787
  /**
@@ -9724,9 +9806,9 @@ class DockviewComponent extends BaseGrid {
9724
9806
  skipSetActiveGroup: true,
9725
9807
  }));
9726
9808
  if (!removedPanel) {
9727
- throw new Error(`No panel with id ${sourceItemId}`);
9809
+ throw new Error(`dockview: No panel with id ${sourceItemId}`);
9728
9810
  }
9729
- if (sourceGroup.model.size === 0) {
9811
+ if (!options.keepEmptyGroups && sourceGroup.model.size === 0) {
9730
9812
  // remove the group and do not set a new group as active
9731
9813
  this.doRemoveGroup(sourceGroup, { skipActive: true });
9732
9814
  }
@@ -9736,7 +9818,8 @@ class DockviewComponent extends BaseGrid {
9736
9818
  var _a;
9737
9819
  return destinationGroup.model.openPanel(removedPanel, {
9738
9820
  index: destinationIndex,
9739
- skipSetActive: ((_a = options.skipSetActive) !== null && _a !== void 0 ? _a : false) && !isDestinationGroupEmpty,
9821
+ skipSetActive: ((_a = options.skipSetActive) !== null && _a !== void 0 ? _a : false) &&
9822
+ !isDestinationGroupEmpty,
9740
9823
  skipSetGroupActive: true,
9741
9824
  });
9742
9825
  });
@@ -9791,7 +9874,9 @@ class DockviewComponent extends BaseGrid {
9791
9874
  }));
9792
9875
  this.doRemoveGroup(sourceGroup, { skipActive: true });
9793
9876
  const newGroup = this.createGroupAtLocation(targetLocation);
9794
- this.movingLock(() => newGroup.model.openPanel(removedPanel));
9877
+ this.movingLock(() => newGroup.model.openPanel(removedPanel, {
9878
+ skipSetActive: true,
9879
+ }));
9795
9880
  this.doSetGroupAndPanelActive(newGroup);
9796
9881
  this._onDidMovePanel.fire({
9797
9882
  panel: this.getGroupPanel(sourceItemId),
@@ -9824,7 +9909,7 @@ class DockviewComponent extends BaseGrid {
9824
9909
  skipSetActiveGroup: true,
9825
9910
  }));
9826
9911
  if (!removedPanel) {
9827
- throw new Error(`No panel with id ${sourceItemId}`);
9912
+ throw new Error(`dockview: No panel with id ${sourceItemId}`);
9828
9913
  }
9829
9914
  const dropLocation = getRelativeLocation(this.gridview.orientation, referenceLocation, destinationTarget);
9830
9915
  const group = this.createGroupAtLocation(dropLocation);
@@ -9879,7 +9964,7 @@ class DockviewComponent extends BaseGrid {
9879
9964
  case 'floating': {
9880
9965
  const selectedFloatingGroup = this._floatingGroups.find((x) => x.group === from);
9881
9966
  if (!selectedFloatingGroup) {
9882
- throw new Error('failed to find floating group');
9967
+ throw new Error('dockview: failed to find floating group');
9883
9968
  }
9884
9969
  selectedFloatingGroup.dispose();
9885
9970
  break;
@@ -9887,7 +9972,7 @@ class DockviewComponent extends BaseGrid {
9887
9972
  case 'popout': {
9888
9973
  const selectedPopoutGroup = this._popoutGroups.find((x) => x.popoutGroup === from);
9889
9974
  if (!selectedPopoutGroup) {
9890
- throw new Error('failed to find popout group');
9975
+ throw new Error('dockview: failed to find popout group');
9891
9976
  }
9892
9977
  // Remove from popout groups list to prevent automatic restoration
9893
9978
  const index = this._popoutGroups.indexOf(selectedPopoutGroup);