dockview-react 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.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * dockview-react
3
- * @version 4.11.0
3
+ * @version 4.12.0
4
4
  * @link https://github.com/mathuo/dockview
5
5
  * @license MIT
6
6
  */
@@ -3782,8 +3782,8 @@ class DockviewApi {
3782
3782
  /**
3783
3783
  * Create a component from a serialized object.
3784
3784
  */
3785
- fromJSON(data) {
3786
- this.component.fromJSON(data);
3785
+ fromJSON(data, options) {
3786
+ this.component.fromJSON(data, options);
3787
3787
  }
3788
3788
  /**
3789
3789
  * Create a serialized object of the current component.
@@ -5014,6 +5014,7 @@ class ContentContainer extends CompositeDisposable {
5014
5014
  }
5015
5015
  if (doRender) {
5016
5016
  const focusTracker = trackFocus(container);
5017
+ this.focusTracker = focusTracker;
5017
5018
  const disposable = new CompositeDisposable();
5018
5019
  disposable.addDisposables(focusTracker, focusTracker.onDidFocus(() => this._onDidFocus.fire()), focusTracker.onDidBlur(() => this._onDidBlur.fire()));
5019
5020
  this.disposable.value = disposable;
@@ -5041,6 +5042,16 @@ class ContentContainer extends CompositeDisposable {
5041
5042
  this.disposable.dispose();
5042
5043
  super.dispose();
5043
5044
  }
5045
+ /**
5046
+ * Refresh the focus tracker state to handle cases where focus state
5047
+ * gets out of sync due to programmatic panel activation
5048
+ */
5049
+ refreshFocusState() {
5050
+ var _a;
5051
+ if ((_a = this.focusTracker) === null || _a === void 0 ? void 0 : _a.refreshState) {
5052
+ this.focusTracker.refreshState();
5053
+ }
5054
+ }
5044
5055
  }
5045
5056
 
5046
5057
  function addGhostImage(dataTransfer, ghostElement, options) {
@@ -6367,8 +6378,11 @@ class DockviewGroupPanelModel extends CompositeDisposable {
6367
6378
  this._activePanel = panel;
6368
6379
  if (panel) {
6369
6380
  this.tabsContainer.setActivePanel(panel);
6381
+ this.contentContainer.openPanel(panel);
6370
6382
  panel.layout(this._width, this._height);
6371
6383
  this.updateMru(panel);
6384
+ // Refresh focus state to handle programmatic activation without DOM focus change
6385
+ this.contentContainer.refreshFocusState();
6372
6386
  this._onDidActivePanelChange.fire({
6373
6387
  panel,
6374
6388
  });
@@ -7198,6 +7212,18 @@ class DockviewPanel extends CompositeDisposable {
7198
7212
  params: this._params,
7199
7213
  });
7200
7214
  }
7215
+ updateFromStateModel(state) {
7216
+ var _a, _b, _c;
7217
+ this._maximumHeight = state.maximumHeight;
7218
+ this._minimumHeight = state.minimumHeight;
7219
+ this._maximumWidth = state.maximumWidth;
7220
+ this._minimumWidth = state.minimumWidth;
7221
+ this.update({ params: (_a = state.params) !== null && _a !== void 0 ? _a : {} });
7222
+ this.setTitle((_b = state.title) !== null && _b !== void 0 ? _b : this.id);
7223
+ this.setRenderer((_c = state.renderer) !== null && _c !== void 0 ? _c : this.accessor.renderer);
7224
+ // state.contentComponent;
7225
+ // state.tabComponent;
7226
+ }
7201
7227
  updateParentGroup(group, options) {
7202
7228
  this._group = group;
7203
7229
  this.api.group = this._group;
@@ -8961,7 +8987,7 @@ class DockviewComponent extends BaseGrid {
8961
8987
  : (_e = (_d = this.options.floatingGroupBounds) === null || _d === void 0 ? void 0 : _d.minimumHeightWithinViewport) !== null && _e !== void 0 ? _e : DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE }));
8962
8988
  const el = group.element.querySelector('.dv-void-container');
8963
8989
  if (!el) {
8964
- throw new Error('failed to find drag handle');
8990
+ throw new Error('dockview: failed to find drag handle');
8965
8991
  }
8966
8992
  overlay.setupDrag(el, {
8967
8993
  inDragMode: typeof (options === null || options === void 0 ? void 0 : options.inDragMode) === 'boolean'
@@ -9033,7 +9059,7 @@ class DockviewComponent extends BaseGrid {
9033
9059
  case 'right':
9034
9060
  return this.createGroupAtLocation([this.gridview.length], undefined, options); // insert into last position
9035
9061
  default:
9036
- throw new Error(`unsupported position ${position}`);
9062
+ throw new Error(`dockview: unsupported position ${position}`);
9037
9063
  }
9038
9064
  }
9039
9065
  updateOptions(options) {
@@ -9179,15 +9205,48 @@ class DockviewComponent extends BaseGrid {
9179
9205
  }
9180
9206
  return result;
9181
9207
  }
9182
- fromJSON(data) {
9208
+ fromJSON(data, options) {
9183
9209
  var _a, _b;
9210
+ const existingPanels = new Map();
9211
+ let tempGroup;
9212
+ if (options === null || options === void 0 ? void 0 : options.reuseExistingPanels) {
9213
+ /**
9214
+ * What are we doing here?
9215
+ *
9216
+ * 1. Create a temporary group to hold any panels that currently exist and that also exist in the new layout
9217
+ * 2. Remove that temporary group from the group mapping so that it doesn't get cleared when we clear the layout
9218
+ */
9219
+ tempGroup = this.createGroup();
9220
+ this._groups.delete(tempGroup.api.id);
9221
+ const newPanels = Object.keys(data.panels);
9222
+ for (const panel of this.panels) {
9223
+ if (newPanels.includes(panel.api.id)) {
9224
+ existingPanels.set(panel.api.id, panel);
9225
+ }
9226
+ }
9227
+ this.movingLock(() => {
9228
+ Array.from(existingPanels.values()).forEach((panel) => {
9229
+ this.moveGroupOrPanel({
9230
+ from: {
9231
+ groupId: panel.api.group.api.id,
9232
+ panelId: panel.api.id,
9233
+ },
9234
+ to: {
9235
+ group: tempGroup,
9236
+ position: 'center',
9237
+ },
9238
+ keepEmptyGroups: true,
9239
+ });
9240
+ });
9241
+ });
9242
+ }
9184
9243
  this.clear();
9185
9244
  if (typeof data !== 'object' || data === null) {
9186
- throw new Error('serialized layout must be a non-null object');
9245
+ throw new Error('dockview: serialized layout must be a non-null object');
9187
9246
  }
9188
9247
  const { grid, panels, activeGroup } = data;
9189
9248
  if (grid.root.type !== 'branch' || !Array.isArray(grid.root.data)) {
9190
- throw new Error('root must be of type branch');
9249
+ throw new Error('dockview: root must be of type branch');
9191
9250
  }
9192
9251
  try {
9193
9252
  // take note of the existing dimensions
@@ -9196,7 +9255,7 @@ class DockviewComponent extends BaseGrid {
9196
9255
  const createGroupFromSerializedState = (data) => {
9197
9256
  const { id, locked, hideHeader, views, activeView } = data;
9198
9257
  if (typeof id !== 'string') {
9199
- throw new Error('group id must be of type string');
9258
+ throw new Error('dockview: group id must be of type string');
9200
9259
  }
9201
9260
  const group = this.createGroup({
9202
9261
  id,
@@ -9211,17 +9270,38 @@ class DockviewComponent extends BaseGrid {
9211
9270
  * In running this section first we avoid firing lots of 'add' events in the event of a failure
9212
9271
  * due to a corruption of input data.
9213
9272
  */
9214
- const panel = this._deserializer.fromJSON(panels[child], group);
9215
- createdPanels.push(panel);
9273
+ const existingPanel = existingPanels.get(child);
9274
+ if (tempGroup && existingPanel) {
9275
+ this.movingLock(() => {
9276
+ tempGroup.model.removePanel(existingPanel);
9277
+ });
9278
+ createdPanels.push(existingPanel);
9279
+ existingPanel.updateFromStateModel(panels[child]);
9280
+ }
9281
+ else {
9282
+ const panel = this._deserializer.fromJSON(panels[child], group);
9283
+ createdPanels.push(panel);
9284
+ }
9216
9285
  }
9217
9286
  for (let i = 0; i < views.length; i++) {
9218
9287
  const panel = createdPanels[i];
9219
9288
  const isActive = typeof activeView === 'string' &&
9220
9289
  activeView === panel.id;
9221
- group.model.openPanel(panel, {
9222
- skipSetActive: !isActive,
9223
- skipSetGroupActive: true,
9224
- });
9290
+ const hasExisting = existingPanels.has(panel.api.id);
9291
+ if (hasExisting) {
9292
+ this.movingLock(() => {
9293
+ group.model.openPanel(panel, {
9294
+ skipSetActive: !isActive,
9295
+ skipSetGroupActive: true,
9296
+ });
9297
+ });
9298
+ }
9299
+ else {
9300
+ group.model.openPanel(panel, {
9301
+ skipSetActive: !isActive,
9302
+ skipSetGroupActive: true,
9303
+ });
9304
+ }
9225
9305
  }
9226
9306
  if (!group.activePanel && group.panels.length > 0) {
9227
9307
  group.model.openPanel(group.panels[group.panels.length - 1], {
@@ -9260,7 +9340,9 @@ class DockviewComponent extends BaseGrid {
9260
9340
  setTimeout(() => {
9261
9341
  this.addPopoutGroup(group, {
9262
9342
  position: position !== null && position !== void 0 ? position : undefined,
9263
- overridePopoutGroup: gridReferenceGroup ? group : undefined,
9343
+ overridePopoutGroup: gridReferenceGroup
9344
+ ? group
9345
+ : undefined,
9264
9346
  referenceGroup: gridReferenceGroup
9265
9347
  ? this.getPanel(gridReferenceGroup)
9266
9348
  : undefined,
@@ -9346,11 +9428,11 @@ class DockviewComponent extends BaseGrid {
9346
9428
  addPanel(options) {
9347
9429
  var _a, _b;
9348
9430
  if (this.panels.find((_) => _.id === options.id)) {
9349
- throw new Error(`panel with id ${options.id} already exists`);
9431
+ throw new Error(`dockview: panel with id ${options.id} already exists`);
9350
9432
  }
9351
9433
  let referenceGroup;
9352
9434
  if (options.position && options.floating) {
9353
- throw new Error('you can only provide one of: position, floating as arguments to .addPanel(...)');
9435
+ throw new Error('dockview: you can only provide one of: position, floating as arguments to .addPanel(...)');
9354
9436
  }
9355
9437
  const initial = {
9356
9438
  width: options.initialWidth,
@@ -9364,7 +9446,7 @@ class DockviewComponent extends BaseGrid {
9364
9446
  : options.position.referencePanel;
9365
9447
  index = options.position.index;
9366
9448
  if (!referencePanel) {
9367
- throw new Error(`referencePanel '${options.position.referencePanel}' does not exist`);
9449
+ throw new Error(`dockview: referencePanel '${options.position.referencePanel}' does not exist`);
9368
9450
  }
9369
9451
  referenceGroup = this.findGroup(referencePanel);
9370
9452
  }
@@ -9375,7 +9457,7 @@ class DockviewComponent extends BaseGrid {
9375
9457
  : options.position.referenceGroup;
9376
9458
  index = options.position.index;
9377
9459
  if (!referenceGroup) {
9378
- throw new Error(`referenceGroup '${options.position.referenceGroup}' does not exist`);
9460
+ throw new Error(`dockview: referenceGroup '${options.position.referenceGroup}' does not exist`);
9379
9461
  }
9380
9462
  }
9381
9463
  else {
@@ -9487,7 +9569,7 @@ class DockviewComponent extends BaseGrid {
9487
9569
  }) {
9488
9570
  const group = panel.group;
9489
9571
  if (!group) {
9490
- throw new Error(`cannot remove panel ${panel.id}. it's missing a group.`);
9572
+ throw new Error(`dockview: cannot remove panel ${panel.id}. it's missing a group.`);
9491
9573
  }
9492
9574
  group.model.removePanel(panel, {
9493
9575
  skipSetActiveGroup: options.skipSetActiveGroup,
@@ -9536,11 +9618,11 @@ class DockviewComponent extends BaseGrid {
9536
9618
  ? this.panels.find((panel) => panel.id === options.referencePanel)
9537
9619
  : options.referencePanel;
9538
9620
  if (!referencePanel) {
9539
- throw new Error(`reference panel ${options.referencePanel} does not exist`);
9621
+ throw new Error(`dockview: reference panel ${options.referencePanel} does not exist`);
9540
9622
  }
9541
9623
  referenceGroup = this.findGroup(referencePanel);
9542
9624
  if (!referenceGroup) {
9543
- throw new Error(`reference group for reference panel ${options.referencePanel} does not exist`);
9625
+ throw new Error(`dockview: reference group for reference panel ${options.referencePanel} does not exist`);
9544
9626
  }
9545
9627
  }
9546
9628
  else if (isGroupOptionsWithGroup(options)) {
@@ -9549,7 +9631,7 @@ class DockviewComponent extends BaseGrid {
9549
9631
  ? (_a = this._groups.get(options.referenceGroup)) === null || _a === void 0 ? void 0 : _a.value
9550
9632
  : options.referenceGroup;
9551
9633
  if (!referenceGroup) {
9552
- throw new Error(`reference group ${options.referenceGroup} does not exist`);
9634
+ throw new Error(`dockview: reference group ${options.referenceGroup} does not exist`);
9553
9635
  }
9554
9636
  }
9555
9637
  else {
@@ -9617,7 +9699,7 @@ class DockviewComponent extends BaseGrid {
9617
9699
  }
9618
9700
  return floatingGroup.group;
9619
9701
  }
9620
- throw new Error('failed to find floating group');
9702
+ throw new Error('dockview: failed to find floating group');
9621
9703
  }
9622
9704
  if (group.api.location.type === 'popout') {
9623
9705
  const selectedGroup = this._popoutGroups.find((_) => _.popoutGroup === group);
@@ -9648,7 +9730,7 @@ class DockviewComponent extends BaseGrid {
9648
9730
  this.updateWatermark();
9649
9731
  return selectedGroup.popoutGroup;
9650
9732
  }
9651
- throw new Error('failed to find popout group');
9733
+ throw new Error('dockview: failed to find popout group');
9652
9734
  }
9653
9735
  const re = super.doRemoveGroup(group, options);
9654
9736
  if (!(options === null || options === void 0 ? void 0 : options.skipActive)) {
@@ -9679,7 +9761,7 @@ class DockviewComponent extends BaseGrid {
9679
9761
  ? (_a = this._groups.get(sourceGroupId)) === null || _a === void 0 ? void 0 : _a.value
9680
9762
  : undefined;
9681
9763
  if (!sourceGroup) {
9682
- throw new Error(`Failed to find group id ${sourceGroupId}`);
9764
+ throw new Error(`dockview: Failed to find group id ${sourceGroupId}`);
9683
9765
  }
9684
9766
  if (sourceItemId === undefined) {
9685
9767
  /**
@@ -9704,9 +9786,9 @@ class DockviewComponent extends BaseGrid {
9704
9786
  skipSetActiveGroup: true,
9705
9787
  }));
9706
9788
  if (!removedPanel) {
9707
- throw new Error(`No panel with id ${sourceItemId}`);
9789
+ throw new Error(`dockview: No panel with id ${sourceItemId}`);
9708
9790
  }
9709
- if (sourceGroup.model.size === 0) {
9791
+ if (!options.keepEmptyGroups && sourceGroup.model.size === 0) {
9710
9792
  // remove the group and do not set a new group as active
9711
9793
  this.doRemoveGroup(sourceGroup, { skipActive: true });
9712
9794
  }
@@ -9716,7 +9798,8 @@ class DockviewComponent extends BaseGrid {
9716
9798
  var _a;
9717
9799
  return destinationGroup.model.openPanel(removedPanel, {
9718
9800
  index: destinationIndex,
9719
- skipSetActive: ((_a = options.skipSetActive) !== null && _a !== void 0 ? _a : false) && !isDestinationGroupEmpty,
9801
+ skipSetActive: ((_a = options.skipSetActive) !== null && _a !== void 0 ? _a : false) &&
9802
+ !isDestinationGroupEmpty,
9720
9803
  skipSetGroupActive: true,
9721
9804
  });
9722
9805
  });
@@ -9771,7 +9854,9 @@ class DockviewComponent extends BaseGrid {
9771
9854
  }));
9772
9855
  this.doRemoveGroup(sourceGroup, { skipActive: true });
9773
9856
  const newGroup = this.createGroupAtLocation(targetLocation);
9774
- this.movingLock(() => newGroup.model.openPanel(removedPanel));
9857
+ this.movingLock(() => newGroup.model.openPanel(removedPanel, {
9858
+ skipSetActive: true,
9859
+ }));
9775
9860
  this.doSetGroupAndPanelActive(newGroup);
9776
9861
  this._onDidMovePanel.fire({
9777
9862
  panel: this.getGroupPanel(sourceItemId),
@@ -9804,7 +9889,7 @@ class DockviewComponent extends BaseGrid {
9804
9889
  skipSetActiveGroup: true,
9805
9890
  }));
9806
9891
  if (!removedPanel) {
9807
- throw new Error(`No panel with id ${sourceItemId}`);
9892
+ throw new Error(`dockview: No panel with id ${sourceItemId}`);
9808
9893
  }
9809
9894
  const dropLocation = getRelativeLocation(this.gridview.orientation, referenceLocation, destinationTarget);
9810
9895
  const group = this.createGroupAtLocation(dropLocation);
@@ -9859,7 +9944,7 @@ class DockviewComponent extends BaseGrid {
9859
9944
  case 'floating': {
9860
9945
  const selectedFloatingGroup = this._floatingGroups.find((x) => x.group === from);
9861
9946
  if (!selectedFloatingGroup) {
9862
- throw new Error('failed to find floating group');
9947
+ throw new Error('dockview: failed to find floating group');
9863
9948
  }
9864
9949
  selectedFloatingGroup.dispose();
9865
9950
  break;
@@ -9867,7 +9952,7 @@ class DockviewComponent extends BaseGrid {
9867
9952
  case 'popout': {
9868
9953
  const selectedPopoutGroup = this._popoutGroups.find((x) => x.popoutGroup === from);
9869
9954
  if (!selectedPopoutGroup) {
9870
- throw new Error('failed to find popout group');
9955
+ throw new Error('dockview: failed to find popout group');
9871
9956
  }
9872
9957
  // Remove from popout groups list to prevent automatic restoration
9873
9958
  const index = this._popoutGroups.indexOf(selectedPopoutGroup);