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
  */
@@ -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
  });
@@ -7201,6 +7215,18 @@
7201
7215
  params: this._params,
7202
7216
  });
7203
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
+ }
7204
7230
  updateParentGroup(group, options) {
7205
7231
  this._group = group;
7206
7232
  this.api.group = this._group;
@@ -8987,7 +9013,7 @@
8987
9013
  : (_e = (_d = this.options.floatingGroupBounds) === null || _d === void 0 ? void 0 : _d.minimumHeightWithinViewport) !== null && _e !== void 0 ? _e : DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE }));
8988
9014
  const el = group.element.querySelector('.dv-void-container');
8989
9015
  if (!el) {
8990
- throw new Error('failed to find drag handle');
9016
+ throw new Error('dockview: failed to find drag handle');
8991
9017
  }
8992
9018
  overlay.setupDrag(el, {
8993
9019
  inDragMode: typeof (options === null || options === void 0 ? void 0 : options.inDragMode) === 'boolean'
@@ -9059,7 +9085,7 @@
9059
9085
  case 'right':
9060
9086
  return this.createGroupAtLocation([this.gridview.length], undefined, options); // insert into last position
9061
9087
  default:
9062
- throw new Error(`unsupported position ${position}`);
9088
+ throw new Error(`dockview: unsupported position ${position}`);
9063
9089
  }
9064
9090
  }
9065
9091
  updateOptions(options) {
@@ -9205,15 +9231,48 @@
9205
9231
  }
9206
9232
  return result;
9207
9233
  }
9208
- fromJSON(data) {
9234
+ fromJSON(data, options) {
9209
9235
  var _a, _b;
9236
+ const existingPanels = new Map();
9237
+ let tempGroup;
9238
+ if (options === null || options === void 0 ? void 0 : options.reuseExistingPanels) {
9239
+ /**
9240
+ * What are we doing here?
9241
+ *
9242
+ * 1. Create a temporary group to hold any panels that currently exist and that also exist in the new layout
9243
+ * 2. Remove that temporary group from the group mapping so that it doesn't get cleared when we clear the layout
9244
+ */
9245
+ tempGroup = this.createGroup();
9246
+ this._groups.delete(tempGroup.api.id);
9247
+ const newPanels = Object.keys(data.panels);
9248
+ for (const panel of this.panels) {
9249
+ if (newPanels.includes(panel.api.id)) {
9250
+ existingPanels.set(panel.api.id, panel);
9251
+ }
9252
+ }
9253
+ this.movingLock(() => {
9254
+ Array.from(existingPanels.values()).forEach((panel) => {
9255
+ this.moveGroupOrPanel({
9256
+ from: {
9257
+ groupId: panel.api.group.api.id,
9258
+ panelId: panel.api.id,
9259
+ },
9260
+ to: {
9261
+ group: tempGroup,
9262
+ position: 'center',
9263
+ },
9264
+ keepEmptyGroups: true,
9265
+ });
9266
+ });
9267
+ });
9268
+ }
9210
9269
  this.clear();
9211
9270
  if (typeof data !== 'object' || data === null) {
9212
- throw new Error('serialized layout must be a non-null object');
9271
+ throw new Error('dockview: serialized layout must be a non-null object');
9213
9272
  }
9214
9273
  const { grid, panels, activeGroup } = data;
9215
9274
  if (grid.root.type !== 'branch' || !Array.isArray(grid.root.data)) {
9216
- throw new Error('root must be of type branch');
9275
+ throw new Error('dockview: root must be of type branch');
9217
9276
  }
9218
9277
  try {
9219
9278
  // take note of the existing dimensions
@@ -9222,7 +9281,7 @@
9222
9281
  const createGroupFromSerializedState = (data) => {
9223
9282
  const { id, locked, hideHeader, views, activeView } = data;
9224
9283
  if (typeof id !== 'string') {
9225
- throw new Error('group id must be of type string');
9284
+ throw new Error('dockview: group id must be of type string');
9226
9285
  }
9227
9286
  const group = this.createGroup({
9228
9287
  id,
@@ -9237,17 +9296,38 @@
9237
9296
  * In running this section first we avoid firing lots of 'add' events in the event of a failure
9238
9297
  * due to a corruption of input data.
9239
9298
  */
9240
- const panel = this._deserializer.fromJSON(panels[child], group);
9241
- createdPanels.push(panel);
9299
+ const existingPanel = existingPanels.get(child);
9300
+ if (tempGroup && existingPanel) {
9301
+ this.movingLock(() => {
9302
+ tempGroup.model.removePanel(existingPanel);
9303
+ });
9304
+ createdPanels.push(existingPanel);
9305
+ existingPanel.updateFromStateModel(panels[child]);
9306
+ }
9307
+ else {
9308
+ const panel = this._deserializer.fromJSON(panels[child], group);
9309
+ createdPanels.push(panel);
9310
+ }
9242
9311
  }
9243
9312
  for (let i = 0; i < views.length; i++) {
9244
9313
  const panel = createdPanels[i];
9245
9314
  const isActive = typeof activeView === 'string' &&
9246
9315
  activeView === panel.id;
9247
- group.model.openPanel(panel, {
9248
- skipSetActive: !isActive,
9249
- skipSetGroupActive: true,
9250
- });
9316
+ const hasExisting = existingPanels.has(panel.api.id);
9317
+ if (hasExisting) {
9318
+ this.movingLock(() => {
9319
+ group.model.openPanel(panel, {
9320
+ skipSetActive: !isActive,
9321
+ skipSetGroupActive: true,
9322
+ });
9323
+ });
9324
+ }
9325
+ else {
9326
+ group.model.openPanel(panel, {
9327
+ skipSetActive: !isActive,
9328
+ skipSetGroupActive: true,
9329
+ });
9330
+ }
9251
9331
  }
9252
9332
  if (!group.activePanel && group.panels.length > 0) {
9253
9333
  group.model.openPanel(group.panels[group.panels.length - 1], {
@@ -9286,7 +9366,9 @@
9286
9366
  setTimeout(() => {
9287
9367
  this.addPopoutGroup(group, {
9288
9368
  position: position !== null && position !== void 0 ? position : undefined,
9289
- overridePopoutGroup: gridReferenceGroup ? group : undefined,
9369
+ overridePopoutGroup: gridReferenceGroup
9370
+ ? group
9371
+ : undefined,
9290
9372
  referenceGroup: gridReferenceGroup
9291
9373
  ? this.getPanel(gridReferenceGroup)
9292
9374
  : undefined,
@@ -9372,11 +9454,11 @@
9372
9454
  addPanel(options) {
9373
9455
  var _a, _b;
9374
9456
  if (this.panels.find((_) => _.id === options.id)) {
9375
- throw new Error(`panel with id ${options.id} already exists`);
9457
+ throw new Error(`dockview: panel with id ${options.id} already exists`);
9376
9458
  }
9377
9459
  let referenceGroup;
9378
9460
  if (options.position && options.floating) {
9379
- throw new Error('you can only provide one of: position, floating as arguments to .addPanel(...)');
9461
+ throw new Error('dockview: you can only provide one of: position, floating as arguments to .addPanel(...)');
9380
9462
  }
9381
9463
  const initial = {
9382
9464
  width: options.initialWidth,
@@ -9390,7 +9472,7 @@
9390
9472
  : options.position.referencePanel;
9391
9473
  index = options.position.index;
9392
9474
  if (!referencePanel) {
9393
- throw new Error(`referencePanel '${options.position.referencePanel}' does not exist`);
9475
+ throw new Error(`dockview: referencePanel '${options.position.referencePanel}' does not exist`);
9394
9476
  }
9395
9477
  referenceGroup = this.findGroup(referencePanel);
9396
9478
  }
@@ -9401,7 +9483,7 @@
9401
9483
  : options.position.referenceGroup;
9402
9484
  index = options.position.index;
9403
9485
  if (!referenceGroup) {
9404
- throw new Error(`referenceGroup '${options.position.referenceGroup}' does not exist`);
9486
+ throw new Error(`dockview: referenceGroup '${options.position.referenceGroup}' does not exist`);
9405
9487
  }
9406
9488
  }
9407
9489
  else {
@@ -9513,7 +9595,7 @@
9513
9595
  }) {
9514
9596
  const group = panel.group;
9515
9597
  if (!group) {
9516
- throw new Error(`cannot remove panel ${panel.id}. it's missing a group.`);
9598
+ throw new Error(`dockview: cannot remove panel ${panel.id}. it's missing a group.`);
9517
9599
  }
9518
9600
  group.model.removePanel(panel, {
9519
9601
  skipSetActiveGroup: options.skipSetActiveGroup,
@@ -9562,11 +9644,11 @@
9562
9644
  ? this.panels.find((panel) => panel.id === options.referencePanel)
9563
9645
  : options.referencePanel;
9564
9646
  if (!referencePanel) {
9565
- throw new Error(`reference panel ${options.referencePanel} does not exist`);
9647
+ throw new Error(`dockview: reference panel ${options.referencePanel} does not exist`);
9566
9648
  }
9567
9649
  referenceGroup = this.findGroup(referencePanel);
9568
9650
  if (!referenceGroup) {
9569
- throw new Error(`reference group for reference panel ${options.referencePanel} does not exist`);
9651
+ throw new Error(`dockview: reference group for reference panel ${options.referencePanel} does not exist`);
9570
9652
  }
9571
9653
  }
9572
9654
  else if (isGroupOptionsWithGroup(options)) {
@@ -9575,7 +9657,7 @@
9575
9657
  ? (_a = this._groups.get(options.referenceGroup)) === null || _a === void 0 ? void 0 : _a.value
9576
9658
  : options.referenceGroup;
9577
9659
  if (!referenceGroup) {
9578
- throw new Error(`reference group ${options.referenceGroup} does not exist`);
9660
+ throw new Error(`dockview: reference group ${options.referenceGroup} does not exist`);
9579
9661
  }
9580
9662
  }
9581
9663
  else {
@@ -9643,7 +9725,7 @@
9643
9725
  }
9644
9726
  return floatingGroup.group;
9645
9727
  }
9646
- throw new Error('failed to find floating group');
9728
+ throw new Error('dockview: failed to find floating group');
9647
9729
  }
9648
9730
  if (group.api.location.type === 'popout') {
9649
9731
  const selectedGroup = this._popoutGroups.find((_) => _.popoutGroup === group);
@@ -9674,7 +9756,7 @@
9674
9756
  this.updateWatermark();
9675
9757
  return selectedGroup.popoutGroup;
9676
9758
  }
9677
- throw new Error('failed to find popout group');
9759
+ throw new Error('dockview: failed to find popout group');
9678
9760
  }
9679
9761
  const re = super.doRemoveGroup(group, options);
9680
9762
  if (!(options === null || options === void 0 ? void 0 : options.skipActive)) {
@@ -9705,7 +9787,7 @@
9705
9787
  ? (_a = this._groups.get(sourceGroupId)) === null || _a === void 0 ? void 0 : _a.value
9706
9788
  : undefined;
9707
9789
  if (!sourceGroup) {
9708
- throw new Error(`Failed to find group id ${sourceGroupId}`);
9790
+ throw new Error(`dockview: Failed to find group id ${sourceGroupId}`);
9709
9791
  }
9710
9792
  if (sourceItemId === undefined) {
9711
9793
  /**
@@ -9730,9 +9812,9 @@
9730
9812
  skipSetActiveGroup: true,
9731
9813
  }));
9732
9814
  if (!removedPanel) {
9733
- throw new Error(`No panel with id ${sourceItemId}`);
9815
+ throw new Error(`dockview: No panel with id ${sourceItemId}`);
9734
9816
  }
9735
- if (sourceGroup.model.size === 0) {
9817
+ if (!options.keepEmptyGroups && sourceGroup.model.size === 0) {
9736
9818
  // remove the group and do not set a new group as active
9737
9819
  this.doRemoveGroup(sourceGroup, { skipActive: true });
9738
9820
  }
@@ -9742,7 +9824,8 @@
9742
9824
  var _a;
9743
9825
  return destinationGroup.model.openPanel(removedPanel, {
9744
9826
  index: destinationIndex,
9745
- skipSetActive: ((_a = options.skipSetActive) !== null && _a !== void 0 ? _a : false) && !isDestinationGroupEmpty,
9827
+ skipSetActive: ((_a = options.skipSetActive) !== null && _a !== void 0 ? _a : false) &&
9828
+ !isDestinationGroupEmpty,
9746
9829
  skipSetGroupActive: true,
9747
9830
  });
9748
9831
  });
@@ -9797,7 +9880,9 @@
9797
9880
  }));
9798
9881
  this.doRemoveGroup(sourceGroup, { skipActive: true });
9799
9882
  const newGroup = this.createGroupAtLocation(targetLocation);
9800
- this.movingLock(() => newGroup.model.openPanel(removedPanel));
9883
+ this.movingLock(() => newGroup.model.openPanel(removedPanel, {
9884
+ skipSetActive: true,
9885
+ }));
9801
9886
  this.doSetGroupAndPanelActive(newGroup);
9802
9887
  this._onDidMovePanel.fire({
9803
9888
  panel: this.getGroupPanel(sourceItemId),
@@ -9830,7 +9915,7 @@
9830
9915
  skipSetActiveGroup: true,
9831
9916
  }));
9832
9917
  if (!removedPanel) {
9833
- throw new Error(`No panel with id ${sourceItemId}`);
9918
+ throw new Error(`dockview: No panel with id ${sourceItemId}`);
9834
9919
  }
9835
9920
  const dropLocation = getRelativeLocation(this.gridview.orientation, referenceLocation, destinationTarget);
9836
9921
  const group = this.createGroupAtLocation(dropLocation);
@@ -9885,7 +9970,7 @@
9885
9970
  case 'floating': {
9886
9971
  const selectedFloatingGroup = this._floatingGroups.find((x) => x.group === from);
9887
9972
  if (!selectedFloatingGroup) {
9888
- throw new Error('failed to find floating group');
9973
+ throw new Error('dockview: failed to find floating group');
9889
9974
  }
9890
9975
  selectedFloatingGroup.dispose();
9891
9976
  break;
@@ -9893,7 +9978,7 @@
9893
9978
  case 'popout': {
9894
9979
  const selectedPopoutGroup = this._popoutGroups.find((x) => x.popoutGroup === from);
9895
9980
  if (!selectedPopoutGroup) {
9896
- throw new Error('failed to find popout group');
9981
+ throw new Error('dockview: failed to find popout group');
9897
9982
  }
9898
9983
  // Remove from popout groups list to prevent automatic restoration
9899
9984
  const index = this._popoutGroups.indexOf(selectedPopoutGroup);