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