dockview-react 4.10.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.10.0
3
+ * @version 4.12.0
4
4
  * @link https://github.com/mathuo/dockview
5
5
  * @license MIT
6
6
  */
@@ -3785,8 +3785,8 @@
3785
3785
  /**
3786
3786
  * Create a component from a serialized object.
3787
3787
  */
3788
- fromJSON(data) {
3789
- this.component.fromJSON(data);
3788
+ fromJSON(data, options) {
3789
+ this.component.fromJSON(data, options);
3790
3790
  }
3791
3791
  /**
3792
3792
  * Create a serialized object of the current component.
@@ -5017,6 +5017,7 @@
5017
5017
  }
5018
5018
  if (doRender) {
5019
5019
  const focusTracker = trackFocus(container);
5020
+ this.focusTracker = focusTracker;
5020
5021
  const disposable = new CompositeDisposable();
5021
5022
  disposable.addDisposables(focusTracker, focusTracker.onDidFocus(() => this._onDidFocus.fire()), focusTracker.onDidBlur(() => this._onDidBlur.fire()));
5022
5023
  this.disposable.value = disposable;
@@ -5044,6 +5045,16 @@
5044
5045
  this.disposable.dispose();
5045
5046
  super.dispose();
5046
5047
  }
5048
+ /**
5049
+ * Refresh the focus tracker state to handle cases where focus state
5050
+ * gets out of sync due to programmatic panel activation
5051
+ */
5052
+ refreshFocusState() {
5053
+ var _a;
5054
+ if ((_a = this.focusTracker) === null || _a === void 0 ? void 0 : _a.refreshState) {
5055
+ this.focusTracker.refreshState();
5056
+ }
5057
+ }
5047
5058
  }
5048
5059
 
5049
5060
  function addGhostImage(dataTransfer, ghostElement, options) {
@@ -6370,8 +6381,11 @@
6370
6381
  this._activePanel = panel;
6371
6382
  if (panel) {
6372
6383
  this.tabsContainer.setActivePanel(panel);
6384
+ this.contentContainer.openPanel(panel);
6373
6385
  panel.layout(this._width, this._height);
6374
6386
  this.updateMru(panel);
6387
+ // Refresh focus state to handle programmatic activation without DOM focus change
6388
+ this.contentContainer.refreshFocusState();
6375
6389
  this._onDidActivePanelChange.fire({
6376
6390
  panel,
6377
6391
  });
@@ -6795,11 +6809,16 @@
6795
6809
  }
6796
6810
  }
6797
6811
 
6812
+ // GridConstraintChangeEvent2 is not exported, so we'll type it manually
6798
6813
  const MINIMUM_DOCKVIEW_GROUP_PANEL_WIDTH = 100;
6799
6814
  const MINIMUM_DOCKVIEW_GROUP_PANEL_HEIGHT = 100;
6800
6815
  class DockviewGroupPanel extends GridviewPanel {
6801
6816
  get minimumWidth() {
6802
6817
  var _a;
6818
+ // Check for explicitly set group constraint first
6819
+ if (typeof this._explicitConstraints.minimumWidth === 'number') {
6820
+ return this._explicitConstraints.minimumWidth;
6821
+ }
6803
6822
  const activePanelMinimumWidth = (_a = this.activePanel) === null || _a === void 0 ? void 0 : _a.minimumWidth;
6804
6823
  if (typeof activePanelMinimumWidth === 'number') {
6805
6824
  return activePanelMinimumWidth;
@@ -6808,6 +6827,10 @@
6808
6827
  }
6809
6828
  get minimumHeight() {
6810
6829
  var _a;
6830
+ // Check for explicitly set group constraint first
6831
+ if (typeof this._explicitConstraints.minimumHeight === 'number') {
6832
+ return this._explicitConstraints.minimumHeight;
6833
+ }
6811
6834
  const activePanelMinimumHeight = (_a = this.activePanel) === null || _a === void 0 ? void 0 : _a.minimumHeight;
6812
6835
  if (typeof activePanelMinimumHeight === 'number') {
6813
6836
  return activePanelMinimumHeight;
@@ -6816,6 +6839,10 @@
6816
6839
  }
6817
6840
  get maximumWidth() {
6818
6841
  var _a;
6842
+ // Check for explicitly set group constraint first
6843
+ if (typeof this._explicitConstraints.maximumWidth === 'number') {
6844
+ return this._explicitConstraints.maximumWidth;
6845
+ }
6819
6846
  const activePanelMaximumWidth = (_a = this.activePanel) === null || _a === void 0 ? void 0 : _a.maximumWidth;
6820
6847
  if (typeof activePanelMaximumWidth === 'number') {
6821
6848
  return activePanelMaximumWidth;
@@ -6824,6 +6851,10 @@
6824
6851
  }
6825
6852
  get maximumHeight() {
6826
6853
  var _a;
6854
+ // Check for explicitly set group constraint first
6855
+ if (typeof this._explicitConstraints.maximumHeight === 'number') {
6856
+ return this._explicitConstraints.maximumHeight;
6857
+ }
6827
6858
  const activePanelMaximumHeight = (_a = this.activePanel) === null || _a === void 0 ? void 0 : _a.maximumHeight;
6828
6859
  if (typeof activePanelMaximumHeight === 'number') {
6829
6860
  return activePanelMaximumHeight;
@@ -6855,14 +6886,39 @@
6855
6886
  var _a, _b, _c, _d, _e, _f;
6856
6887
  super(id, 'groupview_default', {
6857
6888
  minimumHeight: (_b = (_a = options.constraints) === null || _a === void 0 ? void 0 : _a.minimumHeight) !== null && _b !== void 0 ? _b : MINIMUM_DOCKVIEW_GROUP_PANEL_HEIGHT,
6858
- minimumWidth: (_d = (_c = options.constraints) === null || _c === void 0 ? void 0 : _c.maximumHeight) !== null && _d !== void 0 ? _d : MINIMUM_DOCKVIEW_GROUP_PANEL_WIDTH,
6889
+ minimumWidth: (_d = (_c = options.constraints) === null || _c === void 0 ? void 0 : _c.minimumWidth) !== null && _d !== void 0 ? _d : MINIMUM_DOCKVIEW_GROUP_PANEL_WIDTH,
6859
6890
  maximumHeight: (_e = options.constraints) === null || _e === void 0 ? void 0 : _e.maximumHeight,
6860
6891
  maximumWidth: (_f = options.constraints) === null || _f === void 0 ? void 0 : _f.maximumWidth,
6861
6892
  }, new DockviewGroupPanelApiImpl(id, accessor));
6893
+ // Track explicitly set constraints to override panel constraints
6894
+ this._explicitConstraints = {};
6862
6895
  this.api.initialize(this); // cannot use 'this' after after 'super' call
6863
6896
  this._model = new DockviewGroupPanelModel(this.element, accessor, id, options, this);
6864
6897
  this.addDisposables(this.model.onDidActivePanelChange((event) => {
6865
6898
  this.api._onDidActivePanelChange.fire(event);
6899
+ }), this.api.onDidConstraintsChangeInternal((event) => {
6900
+ // Track explicitly set constraints to override panel constraints
6901
+ // Extract numeric values from functions or values
6902
+ if (event.minimumWidth !== undefined) {
6903
+ this._explicitConstraints.minimumWidth = typeof event.minimumWidth === 'function'
6904
+ ? event.minimumWidth()
6905
+ : event.minimumWidth;
6906
+ }
6907
+ if (event.minimumHeight !== undefined) {
6908
+ this._explicitConstraints.minimumHeight = typeof event.minimumHeight === 'function'
6909
+ ? event.minimumHeight()
6910
+ : event.minimumHeight;
6911
+ }
6912
+ if (event.maximumWidth !== undefined) {
6913
+ this._explicitConstraints.maximumWidth = typeof event.maximumWidth === 'function'
6914
+ ? event.maximumWidth()
6915
+ : event.maximumWidth;
6916
+ }
6917
+ if (event.maximumHeight !== undefined) {
6918
+ this._explicitConstraints.maximumHeight = typeof event.maximumHeight === 'function'
6919
+ ? event.maximumHeight()
6920
+ : event.maximumHeight;
6921
+ }
6866
6922
  }));
6867
6923
  }
6868
6924
  focus() {
@@ -7159,6 +7215,18 @@
7159
7215
  params: this._params,
7160
7216
  });
7161
7217
  }
7218
+ updateFromStateModel(state) {
7219
+ var _a, _b, _c;
7220
+ this._maximumHeight = state.maximumHeight;
7221
+ this._minimumHeight = state.minimumHeight;
7222
+ this._maximumWidth = state.maximumWidth;
7223
+ this._minimumWidth = state.minimumWidth;
7224
+ this.update({ params: (_a = state.params) !== null && _a !== void 0 ? _a : {} });
7225
+ this.setTitle((_b = state.title) !== null && _b !== void 0 ? _b : this.id);
7226
+ this.setRenderer((_c = state.renderer) !== null && _c !== void 0 ? _c : this.accessor.renderer);
7227
+ // state.contentComponent;
7228
+ // state.tabComponent;
7229
+ }
7162
7230
  updateParentGroup(group, options) {
7163
7231
  this._group = group;
7164
7232
  this.api.group = this._group;
@@ -8922,7 +8990,7 @@
8922
8990
  : (_e = (_d = this.options.floatingGroupBounds) === null || _d === void 0 ? void 0 : _d.minimumHeightWithinViewport) !== null && _e !== void 0 ? _e : DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE }));
8923
8991
  const el = group.element.querySelector('.dv-void-container');
8924
8992
  if (!el) {
8925
- throw new Error('failed to find drag handle');
8993
+ throw new Error('dockview: failed to find drag handle');
8926
8994
  }
8927
8995
  overlay.setupDrag(el, {
8928
8996
  inDragMode: typeof (options === null || options === void 0 ? void 0 : options.inDragMode) === 'boolean'
@@ -8994,7 +9062,7 @@
8994
9062
  case 'right':
8995
9063
  return this.createGroupAtLocation([this.gridview.length], undefined, options); // insert into last position
8996
9064
  default:
8997
- throw new Error(`unsupported position ${position}`);
9065
+ throw new Error(`dockview: unsupported position ${position}`);
8998
9066
  }
8999
9067
  }
9000
9068
  updateOptions(options) {
@@ -9140,15 +9208,48 @@
9140
9208
  }
9141
9209
  return result;
9142
9210
  }
9143
- fromJSON(data) {
9211
+ fromJSON(data, options) {
9144
9212
  var _a, _b;
9213
+ const existingPanels = new Map();
9214
+ let tempGroup;
9215
+ if (options === null || options === void 0 ? void 0 : options.reuseExistingPanels) {
9216
+ /**
9217
+ * What are we doing here?
9218
+ *
9219
+ * 1. Create a temporary group to hold any panels that currently exist and that also exist in the new layout
9220
+ * 2. Remove that temporary group from the group mapping so that it doesn't get cleared when we clear the layout
9221
+ */
9222
+ tempGroup = this.createGroup();
9223
+ this._groups.delete(tempGroup.api.id);
9224
+ const newPanels = Object.keys(data.panels);
9225
+ for (const panel of this.panels) {
9226
+ if (newPanels.includes(panel.api.id)) {
9227
+ existingPanels.set(panel.api.id, panel);
9228
+ }
9229
+ }
9230
+ this.movingLock(() => {
9231
+ Array.from(existingPanels.values()).forEach((panel) => {
9232
+ this.moveGroupOrPanel({
9233
+ from: {
9234
+ groupId: panel.api.group.api.id,
9235
+ panelId: panel.api.id,
9236
+ },
9237
+ to: {
9238
+ group: tempGroup,
9239
+ position: 'center',
9240
+ },
9241
+ keepEmptyGroups: true,
9242
+ });
9243
+ });
9244
+ });
9245
+ }
9145
9246
  this.clear();
9146
9247
  if (typeof data !== 'object' || data === null) {
9147
- throw new Error('serialized layout must be a non-null object');
9248
+ throw new Error('dockview: serialized layout must be a non-null object');
9148
9249
  }
9149
9250
  const { grid, panels, activeGroup } = data;
9150
9251
  if (grid.root.type !== 'branch' || !Array.isArray(grid.root.data)) {
9151
- throw new Error('root must be of type branch');
9252
+ throw new Error('dockview: root must be of type branch');
9152
9253
  }
9153
9254
  try {
9154
9255
  // take note of the existing dimensions
@@ -9157,7 +9258,7 @@
9157
9258
  const createGroupFromSerializedState = (data) => {
9158
9259
  const { id, locked, hideHeader, views, activeView } = data;
9159
9260
  if (typeof id !== 'string') {
9160
- throw new Error('group id must be of type string');
9261
+ throw new Error('dockview: group id must be of type string');
9161
9262
  }
9162
9263
  const group = this.createGroup({
9163
9264
  id,
@@ -9172,17 +9273,38 @@
9172
9273
  * In running this section first we avoid firing lots of 'add' events in the event of a failure
9173
9274
  * due to a corruption of input data.
9174
9275
  */
9175
- const panel = this._deserializer.fromJSON(panels[child], group);
9176
- createdPanels.push(panel);
9276
+ const existingPanel = existingPanels.get(child);
9277
+ if (tempGroup && existingPanel) {
9278
+ this.movingLock(() => {
9279
+ tempGroup.model.removePanel(existingPanel);
9280
+ });
9281
+ createdPanels.push(existingPanel);
9282
+ existingPanel.updateFromStateModel(panels[child]);
9283
+ }
9284
+ else {
9285
+ const panel = this._deserializer.fromJSON(panels[child], group);
9286
+ createdPanels.push(panel);
9287
+ }
9177
9288
  }
9178
9289
  for (let i = 0; i < views.length; i++) {
9179
9290
  const panel = createdPanels[i];
9180
9291
  const isActive = typeof activeView === 'string' &&
9181
9292
  activeView === panel.id;
9182
- group.model.openPanel(panel, {
9183
- skipSetActive: !isActive,
9184
- skipSetGroupActive: true,
9185
- });
9293
+ const hasExisting = existingPanels.has(panel.api.id);
9294
+ if (hasExisting) {
9295
+ this.movingLock(() => {
9296
+ group.model.openPanel(panel, {
9297
+ skipSetActive: !isActive,
9298
+ skipSetGroupActive: true,
9299
+ });
9300
+ });
9301
+ }
9302
+ else {
9303
+ group.model.openPanel(panel, {
9304
+ skipSetActive: !isActive,
9305
+ skipSetGroupActive: true,
9306
+ });
9307
+ }
9186
9308
  }
9187
9309
  if (!group.activePanel && group.panels.length > 0) {
9188
9310
  group.model.openPanel(group.panels[group.panels.length - 1], {
@@ -9221,7 +9343,9 @@
9221
9343
  setTimeout(() => {
9222
9344
  this.addPopoutGroup(group, {
9223
9345
  position: position !== null && position !== void 0 ? position : undefined,
9224
- overridePopoutGroup: gridReferenceGroup ? group : undefined,
9346
+ overridePopoutGroup: gridReferenceGroup
9347
+ ? group
9348
+ : undefined,
9225
9349
  referenceGroup: gridReferenceGroup
9226
9350
  ? this.getPanel(gridReferenceGroup)
9227
9351
  : undefined,
@@ -9307,11 +9431,11 @@
9307
9431
  addPanel(options) {
9308
9432
  var _a, _b;
9309
9433
  if (this.panels.find((_) => _.id === options.id)) {
9310
- throw new Error(`panel with id ${options.id} already exists`);
9434
+ throw new Error(`dockview: panel with id ${options.id} already exists`);
9311
9435
  }
9312
9436
  let referenceGroup;
9313
9437
  if (options.position && options.floating) {
9314
- throw new Error('you can only provide one of: position, floating as arguments to .addPanel(...)');
9438
+ throw new Error('dockview: you can only provide one of: position, floating as arguments to .addPanel(...)');
9315
9439
  }
9316
9440
  const initial = {
9317
9441
  width: options.initialWidth,
@@ -9325,7 +9449,7 @@
9325
9449
  : options.position.referencePanel;
9326
9450
  index = options.position.index;
9327
9451
  if (!referencePanel) {
9328
- throw new Error(`referencePanel '${options.position.referencePanel}' does not exist`);
9452
+ throw new Error(`dockview: referencePanel '${options.position.referencePanel}' does not exist`);
9329
9453
  }
9330
9454
  referenceGroup = this.findGroup(referencePanel);
9331
9455
  }
@@ -9336,7 +9460,7 @@
9336
9460
  : options.position.referenceGroup;
9337
9461
  index = options.position.index;
9338
9462
  if (!referenceGroup) {
9339
- throw new Error(`referenceGroup '${options.position.referenceGroup}' does not exist`);
9463
+ throw new Error(`dockview: referenceGroup '${options.position.referenceGroup}' does not exist`);
9340
9464
  }
9341
9465
  }
9342
9466
  else {
@@ -9448,7 +9572,7 @@
9448
9572
  }) {
9449
9573
  const group = panel.group;
9450
9574
  if (!group) {
9451
- throw new Error(`cannot remove panel ${panel.id}. it's missing a group.`);
9575
+ throw new Error(`dockview: cannot remove panel ${panel.id}. it's missing a group.`);
9452
9576
  }
9453
9577
  group.model.removePanel(panel, {
9454
9578
  skipSetActiveGroup: options.skipSetActiveGroup,
@@ -9497,11 +9621,11 @@
9497
9621
  ? this.panels.find((panel) => panel.id === options.referencePanel)
9498
9622
  : options.referencePanel;
9499
9623
  if (!referencePanel) {
9500
- throw new Error(`reference panel ${options.referencePanel} does not exist`);
9624
+ throw new Error(`dockview: reference panel ${options.referencePanel} does not exist`);
9501
9625
  }
9502
9626
  referenceGroup = this.findGroup(referencePanel);
9503
9627
  if (!referenceGroup) {
9504
- throw new Error(`reference group for reference panel ${options.referencePanel} does not exist`);
9628
+ throw new Error(`dockview: reference group for reference panel ${options.referencePanel} does not exist`);
9505
9629
  }
9506
9630
  }
9507
9631
  else if (isGroupOptionsWithGroup(options)) {
@@ -9510,7 +9634,7 @@
9510
9634
  ? (_a = this._groups.get(options.referenceGroup)) === null || _a === void 0 ? void 0 : _a.value
9511
9635
  : options.referenceGroup;
9512
9636
  if (!referenceGroup) {
9513
- throw new Error(`reference group ${options.referenceGroup} does not exist`);
9637
+ throw new Error(`dockview: reference group ${options.referenceGroup} does not exist`);
9514
9638
  }
9515
9639
  }
9516
9640
  else {
@@ -9578,7 +9702,7 @@
9578
9702
  }
9579
9703
  return floatingGroup.group;
9580
9704
  }
9581
- throw new Error('failed to find floating group');
9705
+ throw new Error('dockview: failed to find floating group');
9582
9706
  }
9583
9707
  if (group.api.location.type === 'popout') {
9584
9708
  const selectedGroup = this._popoutGroups.find((_) => _.popoutGroup === group);
@@ -9609,7 +9733,7 @@
9609
9733
  this.updateWatermark();
9610
9734
  return selectedGroup.popoutGroup;
9611
9735
  }
9612
- throw new Error('failed to find popout group');
9736
+ throw new Error('dockview: failed to find popout group');
9613
9737
  }
9614
9738
  const re = super.doRemoveGroup(group, options);
9615
9739
  if (!(options === null || options === void 0 ? void 0 : options.skipActive)) {
@@ -9640,7 +9764,7 @@
9640
9764
  ? (_a = this._groups.get(sourceGroupId)) === null || _a === void 0 ? void 0 : _a.value
9641
9765
  : undefined;
9642
9766
  if (!sourceGroup) {
9643
- throw new Error(`Failed to find group id ${sourceGroupId}`);
9767
+ throw new Error(`dockview: Failed to find group id ${sourceGroupId}`);
9644
9768
  }
9645
9769
  if (sourceItemId === undefined) {
9646
9770
  /**
@@ -9665,9 +9789,9 @@
9665
9789
  skipSetActiveGroup: true,
9666
9790
  }));
9667
9791
  if (!removedPanel) {
9668
- throw new Error(`No panel with id ${sourceItemId}`);
9792
+ throw new Error(`dockview: No panel with id ${sourceItemId}`);
9669
9793
  }
9670
- if (sourceGroup.model.size === 0) {
9794
+ if (!options.keepEmptyGroups && sourceGroup.model.size === 0) {
9671
9795
  // remove the group and do not set a new group as active
9672
9796
  this.doRemoveGroup(sourceGroup, { skipActive: true });
9673
9797
  }
@@ -9677,7 +9801,8 @@
9677
9801
  var _a;
9678
9802
  return destinationGroup.model.openPanel(removedPanel, {
9679
9803
  index: destinationIndex,
9680
- skipSetActive: ((_a = options.skipSetActive) !== null && _a !== void 0 ? _a : false) && !isDestinationGroupEmpty,
9804
+ skipSetActive: ((_a = options.skipSetActive) !== null && _a !== void 0 ? _a : false) &&
9805
+ !isDestinationGroupEmpty,
9681
9806
  skipSetGroupActive: true,
9682
9807
  });
9683
9808
  });
@@ -9732,7 +9857,9 @@
9732
9857
  }));
9733
9858
  this.doRemoveGroup(sourceGroup, { skipActive: true });
9734
9859
  const newGroup = this.createGroupAtLocation(targetLocation);
9735
- this.movingLock(() => newGroup.model.openPanel(removedPanel));
9860
+ this.movingLock(() => newGroup.model.openPanel(removedPanel, {
9861
+ skipSetActive: true,
9862
+ }));
9736
9863
  this.doSetGroupAndPanelActive(newGroup);
9737
9864
  this._onDidMovePanel.fire({
9738
9865
  panel: this.getGroupPanel(sourceItemId),
@@ -9765,7 +9892,7 @@
9765
9892
  skipSetActiveGroup: true,
9766
9893
  }));
9767
9894
  if (!removedPanel) {
9768
- throw new Error(`No panel with id ${sourceItemId}`);
9895
+ throw new Error(`dockview: No panel with id ${sourceItemId}`);
9769
9896
  }
9770
9897
  const dropLocation = getRelativeLocation(this.gridview.orientation, referenceLocation, destinationTarget);
9771
9898
  const group = this.createGroupAtLocation(dropLocation);
@@ -9820,7 +9947,7 @@
9820
9947
  case 'floating': {
9821
9948
  const selectedFloatingGroup = this._floatingGroups.find((x) => x.group === from);
9822
9949
  if (!selectedFloatingGroup) {
9823
- throw new Error('failed to find floating group');
9950
+ throw new Error('dockview: failed to find floating group');
9824
9951
  }
9825
9952
  selectedFloatingGroup.dispose();
9826
9953
  break;
@@ -9828,7 +9955,7 @@
9828
9955
  case 'popout': {
9829
9956
  const selectedPopoutGroup = this._popoutGroups.find((x) => x.popoutGroup === from);
9830
9957
  if (!selectedPopoutGroup) {
9831
- throw new Error('failed to find popout group');
9958
+ throw new Error('dockview: failed to find popout group');
9832
9959
  }
9833
9960
  // Remove from popout groups list to prevent automatic restoration
9834
9961
  const index = this._popoutGroups.indexOf(selectedPopoutGroup);