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