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
  */
@@ -3755,8 +3755,8 @@
3755
3755
  /**
3756
3756
  * Create a component from a serialized object.
3757
3757
  */
3758
- fromJSON(data) {
3759
- this.component.fromJSON(data);
3758
+ fromJSON(data, options) {
3759
+ this.component.fromJSON(data, options);
3760
3760
  }
3761
3761
  /**
3762
3762
  * Create a serialized object of the current component.
@@ -4987,6 +4987,7 @@
4987
4987
  }
4988
4988
  if (doRender) {
4989
4989
  const focusTracker = trackFocus(container);
4990
+ this.focusTracker = focusTracker;
4990
4991
  const disposable = new CompositeDisposable();
4991
4992
  disposable.addDisposables(focusTracker, focusTracker.onDidFocus(() => this._onDidFocus.fire()), focusTracker.onDidBlur(() => this._onDidBlur.fire()));
4992
4993
  this.disposable.value = disposable;
@@ -5014,6 +5015,16 @@
5014
5015
  this.disposable.dispose();
5015
5016
  super.dispose();
5016
5017
  }
5018
+ /**
5019
+ * Refresh the focus tracker state to handle cases where focus state
5020
+ * gets out of sync due to programmatic panel activation
5021
+ */
5022
+ refreshFocusState() {
5023
+ var _a;
5024
+ if ((_a = this.focusTracker) === null || _a === void 0 ? void 0 : _a.refreshState) {
5025
+ this.focusTracker.refreshState();
5026
+ }
5027
+ }
5017
5028
  }
5018
5029
 
5019
5030
  function addGhostImage(dataTransfer, ghostElement, options) {
@@ -6340,8 +6351,11 @@
6340
6351
  this._activePanel = panel;
6341
6352
  if (panel) {
6342
6353
  this.tabsContainer.setActivePanel(panel);
6354
+ this.contentContainer.openPanel(panel);
6343
6355
  panel.layout(this._width, this._height);
6344
6356
  this.updateMru(panel);
6357
+ // Refresh focus state to handle programmatic activation without DOM focus change
6358
+ this.contentContainer.refreshFocusState();
6345
6359
  this._onDidActivePanelChange.fire({
6346
6360
  panel,
6347
6361
  });
@@ -7171,6 +7185,18 @@
7171
7185
  params: this._params,
7172
7186
  });
7173
7187
  }
7188
+ updateFromStateModel(state) {
7189
+ var _a, _b, _c;
7190
+ this._maximumHeight = state.maximumHeight;
7191
+ this._minimumHeight = state.minimumHeight;
7192
+ this._maximumWidth = state.maximumWidth;
7193
+ this._minimumWidth = state.minimumWidth;
7194
+ this.update({ params: (_a = state.params) !== null && _a !== void 0 ? _a : {} });
7195
+ this.setTitle((_b = state.title) !== null && _b !== void 0 ? _b : this.id);
7196
+ this.setRenderer((_c = state.renderer) !== null && _c !== void 0 ? _c : this.accessor.renderer);
7197
+ // state.contentComponent;
7198
+ // state.tabComponent;
7199
+ }
7174
7200
  updateParentGroup(group, options) {
7175
7201
  this._group = group;
7176
7202
  this.api.group = this._group;
@@ -8957,7 +8983,7 @@
8957
8983
  : (_e = (_d = this.options.floatingGroupBounds) === null || _d === void 0 ? void 0 : _d.minimumHeightWithinViewport) !== null && _e !== void 0 ? _e : DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE }));
8958
8984
  const el = group.element.querySelector('.dv-void-container');
8959
8985
  if (!el) {
8960
- throw new Error('failed to find drag handle');
8986
+ throw new Error('dockview: failed to find drag handle');
8961
8987
  }
8962
8988
  overlay.setupDrag(el, {
8963
8989
  inDragMode: typeof (options === null || options === void 0 ? void 0 : options.inDragMode) === 'boolean'
@@ -9029,7 +9055,7 @@
9029
9055
  case 'right':
9030
9056
  return this.createGroupAtLocation([this.gridview.length], undefined, options); // insert into last position
9031
9057
  default:
9032
- throw new Error(`unsupported position ${position}`);
9058
+ throw new Error(`dockview: unsupported position ${position}`);
9033
9059
  }
9034
9060
  }
9035
9061
  updateOptions(options) {
@@ -9175,15 +9201,48 @@
9175
9201
  }
9176
9202
  return result;
9177
9203
  }
9178
- fromJSON(data) {
9204
+ fromJSON(data, options) {
9179
9205
  var _a, _b;
9206
+ const existingPanels = new Map();
9207
+ let tempGroup;
9208
+ if (options === null || options === void 0 ? void 0 : options.reuseExistingPanels) {
9209
+ /**
9210
+ * What are we doing here?
9211
+ *
9212
+ * 1. Create a temporary group to hold any panels that currently exist and that also exist in the new layout
9213
+ * 2. Remove that temporary group from the group mapping so that it doesn't get cleared when we clear the layout
9214
+ */
9215
+ tempGroup = this.createGroup();
9216
+ this._groups.delete(tempGroup.api.id);
9217
+ const newPanels = Object.keys(data.panels);
9218
+ for (const panel of this.panels) {
9219
+ if (newPanels.includes(panel.api.id)) {
9220
+ existingPanels.set(panel.api.id, panel);
9221
+ }
9222
+ }
9223
+ this.movingLock(() => {
9224
+ Array.from(existingPanels.values()).forEach((panel) => {
9225
+ this.moveGroupOrPanel({
9226
+ from: {
9227
+ groupId: panel.api.group.api.id,
9228
+ panelId: panel.api.id,
9229
+ },
9230
+ to: {
9231
+ group: tempGroup,
9232
+ position: 'center',
9233
+ },
9234
+ keepEmptyGroups: true,
9235
+ });
9236
+ });
9237
+ });
9238
+ }
9180
9239
  this.clear();
9181
9240
  if (typeof data !== 'object' || data === null) {
9182
- throw new Error('serialized layout must be a non-null object');
9241
+ throw new Error('dockview: serialized layout must be a non-null object');
9183
9242
  }
9184
9243
  const { grid, panels, activeGroup } = data;
9185
9244
  if (grid.root.type !== 'branch' || !Array.isArray(grid.root.data)) {
9186
- throw new Error('root must be of type branch');
9245
+ throw new Error('dockview: root must be of type branch');
9187
9246
  }
9188
9247
  try {
9189
9248
  // take note of the existing dimensions
@@ -9192,7 +9251,7 @@
9192
9251
  const createGroupFromSerializedState = (data) => {
9193
9252
  const { id, locked, hideHeader, views, activeView } = data;
9194
9253
  if (typeof id !== 'string') {
9195
- throw new Error('group id must be of type string');
9254
+ throw new Error('dockview: group id must be of type string');
9196
9255
  }
9197
9256
  const group = this.createGroup({
9198
9257
  id,
@@ -9207,17 +9266,38 @@
9207
9266
  * In running this section first we avoid firing lots of 'add' events in the event of a failure
9208
9267
  * due to a corruption of input data.
9209
9268
  */
9210
- const panel = this._deserializer.fromJSON(panels[child], group);
9211
- createdPanels.push(panel);
9269
+ const existingPanel = existingPanels.get(child);
9270
+ if (tempGroup && existingPanel) {
9271
+ this.movingLock(() => {
9272
+ tempGroup.model.removePanel(existingPanel);
9273
+ });
9274
+ createdPanels.push(existingPanel);
9275
+ existingPanel.updateFromStateModel(panels[child]);
9276
+ }
9277
+ else {
9278
+ const panel = this._deserializer.fromJSON(panels[child], group);
9279
+ createdPanels.push(panel);
9280
+ }
9212
9281
  }
9213
9282
  for (let i = 0; i < views.length; i++) {
9214
9283
  const panel = createdPanels[i];
9215
9284
  const isActive = typeof activeView === 'string' &&
9216
9285
  activeView === panel.id;
9217
- group.model.openPanel(panel, {
9218
- skipSetActive: !isActive,
9219
- skipSetGroupActive: true,
9220
- });
9286
+ const hasExisting = existingPanels.has(panel.api.id);
9287
+ if (hasExisting) {
9288
+ this.movingLock(() => {
9289
+ group.model.openPanel(panel, {
9290
+ skipSetActive: !isActive,
9291
+ skipSetGroupActive: true,
9292
+ });
9293
+ });
9294
+ }
9295
+ else {
9296
+ group.model.openPanel(panel, {
9297
+ skipSetActive: !isActive,
9298
+ skipSetGroupActive: true,
9299
+ });
9300
+ }
9221
9301
  }
9222
9302
  if (!group.activePanel && group.panels.length > 0) {
9223
9303
  group.model.openPanel(group.panels[group.panels.length - 1], {
@@ -9256,7 +9336,9 @@
9256
9336
  setTimeout(() => {
9257
9337
  this.addPopoutGroup(group, {
9258
9338
  position: position !== null && position !== void 0 ? position : undefined,
9259
- overridePopoutGroup: gridReferenceGroup ? group : undefined,
9339
+ overridePopoutGroup: gridReferenceGroup
9340
+ ? group
9341
+ : undefined,
9260
9342
  referenceGroup: gridReferenceGroup
9261
9343
  ? this.getPanel(gridReferenceGroup)
9262
9344
  : undefined,
@@ -9342,11 +9424,11 @@
9342
9424
  addPanel(options) {
9343
9425
  var _a, _b;
9344
9426
  if (this.panels.find((_) => _.id === options.id)) {
9345
- throw new Error(`panel with id ${options.id} already exists`);
9427
+ throw new Error(`dockview: panel with id ${options.id} already exists`);
9346
9428
  }
9347
9429
  let referenceGroup;
9348
9430
  if (options.position && options.floating) {
9349
- throw new Error('you can only provide one of: position, floating as arguments to .addPanel(...)');
9431
+ throw new Error('dockview: you can only provide one of: position, floating as arguments to .addPanel(...)');
9350
9432
  }
9351
9433
  const initial = {
9352
9434
  width: options.initialWidth,
@@ -9360,7 +9442,7 @@
9360
9442
  : options.position.referencePanel;
9361
9443
  index = options.position.index;
9362
9444
  if (!referencePanel) {
9363
- throw new Error(`referencePanel '${options.position.referencePanel}' does not exist`);
9445
+ throw new Error(`dockview: referencePanel '${options.position.referencePanel}' does not exist`);
9364
9446
  }
9365
9447
  referenceGroup = this.findGroup(referencePanel);
9366
9448
  }
@@ -9371,7 +9453,7 @@
9371
9453
  : options.position.referenceGroup;
9372
9454
  index = options.position.index;
9373
9455
  if (!referenceGroup) {
9374
- throw new Error(`referenceGroup '${options.position.referenceGroup}' does not exist`);
9456
+ throw new Error(`dockview: referenceGroup '${options.position.referenceGroup}' does not exist`);
9375
9457
  }
9376
9458
  }
9377
9459
  else {
@@ -9483,7 +9565,7 @@
9483
9565
  }) {
9484
9566
  const group = panel.group;
9485
9567
  if (!group) {
9486
- throw new Error(`cannot remove panel ${panel.id}. it's missing a group.`);
9568
+ throw new Error(`dockview: cannot remove panel ${panel.id}. it's missing a group.`);
9487
9569
  }
9488
9570
  group.model.removePanel(panel, {
9489
9571
  skipSetActiveGroup: options.skipSetActiveGroup,
@@ -9532,11 +9614,11 @@
9532
9614
  ? this.panels.find((panel) => panel.id === options.referencePanel)
9533
9615
  : options.referencePanel;
9534
9616
  if (!referencePanel) {
9535
- throw new Error(`reference panel ${options.referencePanel} does not exist`);
9617
+ throw new Error(`dockview: reference panel ${options.referencePanel} does not exist`);
9536
9618
  }
9537
9619
  referenceGroup = this.findGroup(referencePanel);
9538
9620
  if (!referenceGroup) {
9539
- throw new Error(`reference group for reference panel ${options.referencePanel} does not exist`);
9621
+ throw new Error(`dockview: reference group for reference panel ${options.referencePanel} does not exist`);
9540
9622
  }
9541
9623
  }
9542
9624
  else if (isGroupOptionsWithGroup(options)) {
@@ -9545,7 +9627,7 @@
9545
9627
  ? (_a = this._groups.get(options.referenceGroup)) === null || _a === void 0 ? void 0 : _a.value
9546
9628
  : options.referenceGroup;
9547
9629
  if (!referenceGroup) {
9548
- throw new Error(`reference group ${options.referenceGroup} does not exist`);
9630
+ throw new Error(`dockview: reference group ${options.referenceGroup} does not exist`);
9549
9631
  }
9550
9632
  }
9551
9633
  else {
@@ -9613,7 +9695,7 @@
9613
9695
  }
9614
9696
  return floatingGroup.group;
9615
9697
  }
9616
- throw new Error('failed to find floating group');
9698
+ throw new Error('dockview: failed to find floating group');
9617
9699
  }
9618
9700
  if (group.api.location.type === 'popout') {
9619
9701
  const selectedGroup = this._popoutGroups.find((_) => _.popoutGroup === group);
@@ -9644,7 +9726,7 @@
9644
9726
  this.updateWatermark();
9645
9727
  return selectedGroup.popoutGroup;
9646
9728
  }
9647
- throw new Error('failed to find popout group');
9729
+ throw new Error('dockview: failed to find popout group');
9648
9730
  }
9649
9731
  const re = super.doRemoveGroup(group, options);
9650
9732
  if (!(options === null || options === void 0 ? void 0 : options.skipActive)) {
@@ -9675,7 +9757,7 @@
9675
9757
  ? (_a = this._groups.get(sourceGroupId)) === null || _a === void 0 ? void 0 : _a.value
9676
9758
  : undefined;
9677
9759
  if (!sourceGroup) {
9678
- throw new Error(`Failed to find group id ${sourceGroupId}`);
9760
+ throw new Error(`dockview: Failed to find group id ${sourceGroupId}`);
9679
9761
  }
9680
9762
  if (sourceItemId === undefined) {
9681
9763
  /**
@@ -9700,9 +9782,9 @@
9700
9782
  skipSetActiveGroup: true,
9701
9783
  }));
9702
9784
  if (!removedPanel) {
9703
- throw new Error(`No panel with id ${sourceItemId}`);
9785
+ throw new Error(`dockview: No panel with id ${sourceItemId}`);
9704
9786
  }
9705
- if (sourceGroup.model.size === 0) {
9787
+ if (!options.keepEmptyGroups && sourceGroup.model.size === 0) {
9706
9788
  // remove the group and do not set a new group as active
9707
9789
  this.doRemoveGroup(sourceGroup, { skipActive: true });
9708
9790
  }
@@ -9712,7 +9794,8 @@
9712
9794
  var _a;
9713
9795
  return destinationGroup.model.openPanel(removedPanel, {
9714
9796
  index: destinationIndex,
9715
- skipSetActive: ((_a = options.skipSetActive) !== null && _a !== void 0 ? _a : false) && !isDestinationGroupEmpty,
9797
+ skipSetActive: ((_a = options.skipSetActive) !== null && _a !== void 0 ? _a : false) &&
9798
+ !isDestinationGroupEmpty,
9716
9799
  skipSetGroupActive: true,
9717
9800
  });
9718
9801
  });
@@ -9767,7 +9850,9 @@
9767
9850
  }));
9768
9851
  this.doRemoveGroup(sourceGroup, { skipActive: true });
9769
9852
  const newGroup = this.createGroupAtLocation(targetLocation);
9770
- this.movingLock(() => newGroup.model.openPanel(removedPanel));
9853
+ this.movingLock(() => newGroup.model.openPanel(removedPanel, {
9854
+ skipSetActive: true,
9855
+ }));
9771
9856
  this.doSetGroupAndPanelActive(newGroup);
9772
9857
  this._onDidMovePanel.fire({
9773
9858
  panel: this.getGroupPanel(sourceItemId),
@@ -9800,7 +9885,7 @@
9800
9885
  skipSetActiveGroup: true,
9801
9886
  }));
9802
9887
  if (!removedPanel) {
9803
- throw new Error(`No panel with id ${sourceItemId}`);
9888
+ throw new Error(`dockview: No panel with id ${sourceItemId}`);
9804
9889
  }
9805
9890
  const dropLocation = getRelativeLocation(this.gridview.orientation, referenceLocation, destinationTarget);
9806
9891
  const group = this.createGroupAtLocation(dropLocation);
@@ -9855,7 +9940,7 @@
9855
9940
  case 'floating': {
9856
9941
  const selectedFloatingGroup = this._floatingGroups.find((x) => x.group === from);
9857
9942
  if (!selectedFloatingGroup) {
9858
- throw new Error('failed to find floating group');
9943
+ throw new Error('dockview: failed to find floating group');
9859
9944
  }
9860
9945
  selectedFloatingGroup.dispose();
9861
9946
  break;
@@ -9863,7 +9948,7 @@
9863
9948
  case 'popout': {
9864
9949
  const selectedPopoutGroup = this._popoutGroups.find((x) => x.popoutGroup === from);
9865
9950
  if (!selectedPopoutGroup) {
9866
- throw new Error('failed to find popout group');
9951
+ throw new Error('dockview: failed to find popout group');
9867
9952
  }
9868
9953
  // Remove from popout groups list to prevent automatic restoration
9869
9954
  const index = this._popoutGroups.indexOf(selectedPopoutGroup);