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
  */
@@ -3751,8 +3751,8 @@ define(['exports'], (function (exports) { 'use strict';
3751
3751
  /**
3752
3752
  * Create a component from a serialized object.
3753
3753
  */
3754
- fromJSON(data) {
3755
- this.component.fromJSON(data);
3754
+ fromJSON(data, options) {
3755
+ this.component.fromJSON(data, options);
3756
3756
  }
3757
3757
  /**
3758
3758
  * Create a serialized object of the current component.
@@ -4983,6 +4983,7 @@ define(['exports'], (function (exports) { 'use strict';
4983
4983
  }
4984
4984
  if (doRender) {
4985
4985
  const focusTracker = trackFocus(container);
4986
+ this.focusTracker = focusTracker;
4986
4987
  const disposable = new CompositeDisposable();
4987
4988
  disposable.addDisposables(focusTracker, focusTracker.onDidFocus(() => this._onDidFocus.fire()), focusTracker.onDidBlur(() => this._onDidBlur.fire()));
4988
4989
  this.disposable.value = disposable;
@@ -5010,6 +5011,16 @@ define(['exports'], (function (exports) { 'use strict';
5010
5011
  this.disposable.dispose();
5011
5012
  super.dispose();
5012
5013
  }
5014
+ /**
5015
+ * Refresh the focus tracker state to handle cases where focus state
5016
+ * gets out of sync due to programmatic panel activation
5017
+ */
5018
+ refreshFocusState() {
5019
+ var _a;
5020
+ if ((_a = this.focusTracker) === null || _a === void 0 ? void 0 : _a.refreshState) {
5021
+ this.focusTracker.refreshState();
5022
+ }
5023
+ }
5013
5024
  }
5014
5025
 
5015
5026
  function addGhostImage(dataTransfer, ghostElement, options) {
@@ -6336,8 +6347,11 @@ define(['exports'], (function (exports) { 'use strict';
6336
6347
  this._activePanel = panel;
6337
6348
  if (panel) {
6338
6349
  this.tabsContainer.setActivePanel(panel);
6350
+ this.contentContainer.openPanel(panel);
6339
6351
  panel.layout(this._width, this._height);
6340
6352
  this.updateMru(panel);
6353
+ // Refresh focus state to handle programmatic activation without DOM focus change
6354
+ this.contentContainer.refreshFocusState();
6341
6355
  this._onDidActivePanelChange.fire({
6342
6356
  panel,
6343
6357
  });
@@ -7167,6 +7181,18 @@ define(['exports'], (function (exports) { 'use strict';
7167
7181
  params: this._params,
7168
7182
  });
7169
7183
  }
7184
+ updateFromStateModel(state) {
7185
+ var _a, _b, _c;
7186
+ this._maximumHeight = state.maximumHeight;
7187
+ this._minimumHeight = state.minimumHeight;
7188
+ this._maximumWidth = state.maximumWidth;
7189
+ this._minimumWidth = state.minimumWidth;
7190
+ this.update({ params: (_a = state.params) !== null && _a !== void 0 ? _a : {} });
7191
+ this.setTitle((_b = state.title) !== null && _b !== void 0 ? _b : this.id);
7192
+ this.setRenderer((_c = state.renderer) !== null && _c !== void 0 ? _c : this.accessor.renderer);
7193
+ // state.contentComponent;
7194
+ // state.tabComponent;
7195
+ }
7170
7196
  updateParentGroup(group, options) {
7171
7197
  this._group = group;
7172
7198
  this.api.group = this._group;
@@ -8953,7 +8979,7 @@ define(['exports'], (function (exports) { 'use strict';
8953
8979
  : (_e = (_d = this.options.floatingGroupBounds) === null || _d === void 0 ? void 0 : _d.minimumHeightWithinViewport) !== null && _e !== void 0 ? _e : DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE }));
8954
8980
  const el = group.element.querySelector('.dv-void-container');
8955
8981
  if (!el) {
8956
- throw new Error('failed to find drag handle');
8982
+ throw new Error('dockview: failed to find drag handle');
8957
8983
  }
8958
8984
  overlay.setupDrag(el, {
8959
8985
  inDragMode: typeof (options === null || options === void 0 ? void 0 : options.inDragMode) === 'boolean'
@@ -9025,7 +9051,7 @@ define(['exports'], (function (exports) { 'use strict';
9025
9051
  case 'right':
9026
9052
  return this.createGroupAtLocation([this.gridview.length], undefined, options); // insert into last position
9027
9053
  default:
9028
- throw new Error(`unsupported position ${position}`);
9054
+ throw new Error(`dockview: unsupported position ${position}`);
9029
9055
  }
9030
9056
  }
9031
9057
  updateOptions(options) {
@@ -9171,15 +9197,48 @@ define(['exports'], (function (exports) { 'use strict';
9171
9197
  }
9172
9198
  return result;
9173
9199
  }
9174
- fromJSON(data) {
9200
+ fromJSON(data, options) {
9175
9201
  var _a, _b;
9202
+ const existingPanels = new Map();
9203
+ let tempGroup;
9204
+ if (options === null || options === void 0 ? void 0 : options.reuseExistingPanels) {
9205
+ /**
9206
+ * What are we doing here?
9207
+ *
9208
+ * 1. Create a temporary group to hold any panels that currently exist and that also exist in the new layout
9209
+ * 2. Remove that temporary group from the group mapping so that it doesn't get cleared when we clear the layout
9210
+ */
9211
+ tempGroup = this.createGroup();
9212
+ this._groups.delete(tempGroup.api.id);
9213
+ const newPanels = Object.keys(data.panels);
9214
+ for (const panel of this.panels) {
9215
+ if (newPanels.includes(panel.api.id)) {
9216
+ existingPanels.set(panel.api.id, panel);
9217
+ }
9218
+ }
9219
+ this.movingLock(() => {
9220
+ Array.from(existingPanels.values()).forEach((panel) => {
9221
+ this.moveGroupOrPanel({
9222
+ from: {
9223
+ groupId: panel.api.group.api.id,
9224
+ panelId: panel.api.id,
9225
+ },
9226
+ to: {
9227
+ group: tempGroup,
9228
+ position: 'center',
9229
+ },
9230
+ keepEmptyGroups: true,
9231
+ });
9232
+ });
9233
+ });
9234
+ }
9176
9235
  this.clear();
9177
9236
  if (typeof data !== 'object' || data === null) {
9178
- throw new Error('serialized layout must be a non-null object');
9237
+ throw new Error('dockview: serialized layout must be a non-null object');
9179
9238
  }
9180
9239
  const { grid, panels, activeGroup } = data;
9181
9240
  if (grid.root.type !== 'branch' || !Array.isArray(grid.root.data)) {
9182
- throw new Error('root must be of type branch');
9241
+ throw new Error('dockview: root must be of type branch');
9183
9242
  }
9184
9243
  try {
9185
9244
  // take note of the existing dimensions
@@ -9188,7 +9247,7 @@ define(['exports'], (function (exports) { 'use strict';
9188
9247
  const createGroupFromSerializedState = (data) => {
9189
9248
  const { id, locked, hideHeader, views, activeView } = data;
9190
9249
  if (typeof id !== 'string') {
9191
- throw new Error('group id must be of type string');
9250
+ throw new Error('dockview: group id must be of type string');
9192
9251
  }
9193
9252
  const group = this.createGroup({
9194
9253
  id,
@@ -9203,17 +9262,38 @@ define(['exports'], (function (exports) { 'use strict';
9203
9262
  * In running this section first we avoid firing lots of 'add' events in the event of a failure
9204
9263
  * due to a corruption of input data.
9205
9264
  */
9206
- const panel = this._deserializer.fromJSON(panels[child], group);
9207
- createdPanels.push(panel);
9265
+ const existingPanel = existingPanels.get(child);
9266
+ if (tempGroup && existingPanel) {
9267
+ this.movingLock(() => {
9268
+ tempGroup.model.removePanel(existingPanel);
9269
+ });
9270
+ createdPanels.push(existingPanel);
9271
+ existingPanel.updateFromStateModel(panels[child]);
9272
+ }
9273
+ else {
9274
+ const panel = this._deserializer.fromJSON(panels[child], group);
9275
+ createdPanels.push(panel);
9276
+ }
9208
9277
  }
9209
9278
  for (let i = 0; i < views.length; i++) {
9210
9279
  const panel = createdPanels[i];
9211
9280
  const isActive = typeof activeView === 'string' &&
9212
9281
  activeView === panel.id;
9213
- group.model.openPanel(panel, {
9214
- skipSetActive: !isActive,
9215
- skipSetGroupActive: true,
9216
- });
9282
+ const hasExisting = existingPanels.has(panel.api.id);
9283
+ if (hasExisting) {
9284
+ this.movingLock(() => {
9285
+ group.model.openPanel(panel, {
9286
+ skipSetActive: !isActive,
9287
+ skipSetGroupActive: true,
9288
+ });
9289
+ });
9290
+ }
9291
+ else {
9292
+ group.model.openPanel(panel, {
9293
+ skipSetActive: !isActive,
9294
+ skipSetGroupActive: true,
9295
+ });
9296
+ }
9217
9297
  }
9218
9298
  if (!group.activePanel && group.panels.length > 0) {
9219
9299
  group.model.openPanel(group.panels[group.panels.length - 1], {
@@ -9252,7 +9332,9 @@ define(['exports'], (function (exports) { 'use strict';
9252
9332
  setTimeout(() => {
9253
9333
  this.addPopoutGroup(group, {
9254
9334
  position: position !== null && position !== void 0 ? position : undefined,
9255
- overridePopoutGroup: gridReferenceGroup ? group : undefined,
9335
+ overridePopoutGroup: gridReferenceGroup
9336
+ ? group
9337
+ : undefined,
9256
9338
  referenceGroup: gridReferenceGroup
9257
9339
  ? this.getPanel(gridReferenceGroup)
9258
9340
  : undefined,
@@ -9338,11 +9420,11 @@ define(['exports'], (function (exports) { 'use strict';
9338
9420
  addPanel(options) {
9339
9421
  var _a, _b;
9340
9422
  if (this.panels.find((_) => _.id === options.id)) {
9341
- throw new Error(`panel with id ${options.id} already exists`);
9423
+ throw new Error(`dockview: panel with id ${options.id} already exists`);
9342
9424
  }
9343
9425
  let referenceGroup;
9344
9426
  if (options.position && options.floating) {
9345
- throw new Error('you can only provide one of: position, floating as arguments to .addPanel(...)');
9427
+ throw new Error('dockview: you can only provide one of: position, floating as arguments to .addPanel(...)');
9346
9428
  }
9347
9429
  const initial = {
9348
9430
  width: options.initialWidth,
@@ -9356,7 +9438,7 @@ define(['exports'], (function (exports) { 'use strict';
9356
9438
  : options.position.referencePanel;
9357
9439
  index = options.position.index;
9358
9440
  if (!referencePanel) {
9359
- throw new Error(`referencePanel '${options.position.referencePanel}' does not exist`);
9441
+ throw new Error(`dockview: referencePanel '${options.position.referencePanel}' does not exist`);
9360
9442
  }
9361
9443
  referenceGroup = this.findGroup(referencePanel);
9362
9444
  }
@@ -9367,7 +9449,7 @@ define(['exports'], (function (exports) { 'use strict';
9367
9449
  : options.position.referenceGroup;
9368
9450
  index = options.position.index;
9369
9451
  if (!referenceGroup) {
9370
- throw new Error(`referenceGroup '${options.position.referenceGroup}' does not exist`);
9452
+ throw new Error(`dockview: referenceGroup '${options.position.referenceGroup}' does not exist`);
9371
9453
  }
9372
9454
  }
9373
9455
  else {
@@ -9479,7 +9561,7 @@ define(['exports'], (function (exports) { 'use strict';
9479
9561
  }) {
9480
9562
  const group = panel.group;
9481
9563
  if (!group) {
9482
- throw new Error(`cannot remove panel ${panel.id}. it's missing a group.`);
9564
+ throw new Error(`dockview: cannot remove panel ${panel.id}. it's missing a group.`);
9483
9565
  }
9484
9566
  group.model.removePanel(panel, {
9485
9567
  skipSetActiveGroup: options.skipSetActiveGroup,
@@ -9528,11 +9610,11 @@ define(['exports'], (function (exports) { 'use strict';
9528
9610
  ? this.panels.find((panel) => panel.id === options.referencePanel)
9529
9611
  : options.referencePanel;
9530
9612
  if (!referencePanel) {
9531
- throw new Error(`reference panel ${options.referencePanel} does not exist`);
9613
+ throw new Error(`dockview: reference panel ${options.referencePanel} does not exist`);
9532
9614
  }
9533
9615
  referenceGroup = this.findGroup(referencePanel);
9534
9616
  if (!referenceGroup) {
9535
- throw new Error(`reference group for reference panel ${options.referencePanel} does not exist`);
9617
+ throw new Error(`dockview: reference group for reference panel ${options.referencePanel} does not exist`);
9536
9618
  }
9537
9619
  }
9538
9620
  else if (isGroupOptionsWithGroup(options)) {
@@ -9541,7 +9623,7 @@ define(['exports'], (function (exports) { 'use strict';
9541
9623
  ? (_a = this._groups.get(options.referenceGroup)) === null || _a === void 0 ? void 0 : _a.value
9542
9624
  : options.referenceGroup;
9543
9625
  if (!referenceGroup) {
9544
- throw new Error(`reference group ${options.referenceGroup} does not exist`);
9626
+ throw new Error(`dockview: reference group ${options.referenceGroup} does not exist`);
9545
9627
  }
9546
9628
  }
9547
9629
  else {
@@ -9609,7 +9691,7 @@ define(['exports'], (function (exports) { 'use strict';
9609
9691
  }
9610
9692
  return floatingGroup.group;
9611
9693
  }
9612
- throw new Error('failed to find floating group');
9694
+ throw new Error('dockview: failed to find floating group');
9613
9695
  }
9614
9696
  if (group.api.location.type === 'popout') {
9615
9697
  const selectedGroup = this._popoutGroups.find((_) => _.popoutGroup === group);
@@ -9640,7 +9722,7 @@ define(['exports'], (function (exports) { 'use strict';
9640
9722
  this.updateWatermark();
9641
9723
  return selectedGroup.popoutGroup;
9642
9724
  }
9643
- throw new Error('failed to find popout group');
9725
+ throw new Error('dockview: failed to find popout group');
9644
9726
  }
9645
9727
  const re = super.doRemoveGroup(group, options);
9646
9728
  if (!(options === null || options === void 0 ? void 0 : options.skipActive)) {
@@ -9671,7 +9753,7 @@ define(['exports'], (function (exports) { 'use strict';
9671
9753
  ? (_a = this._groups.get(sourceGroupId)) === null || _a === void 0 ? void 0 : _a.value
9672
9754
  : undefined;
9673
9755
  if (!sourceGroup) {
9674
- throw new Error(`Failed to find group id ${sourceGroupId}`);
9756
+ throw new Error(`dockview: Failed to find group id ${sourceGroupId}`);
9675
9757
  }
9676
9758
  if (sourceItemId === undefined) {
9677
9759
  /**
@@ -9696,9 +9778,9 @@ define(['exports'], (function (exports) { 'use strict';
9696
9778
  skipSetActiveGroup: true,
9697
9779
  }));
9698
9780
  if (!removedPanel) {
9699
- throw new Error(`No panel with id ${sourceItemId}`);
9781
+ throw new Error(`dockview: No panel with id ${sourceItemId}`);
9700
9782
  }
9701
- if (sourceGroup.model.size === 0) {
9783
+ if (!options.keepEmptyGroups && sourceGroup.model.size === 0) {
9702
9784
  // remove the group and do not set a new group as active
9703
9785
  this.doRemoveGroup(sourceGroup, { skipActive: true });
9704
9786
  }
@@ -9708,7 +9790,8 @@ define(['exports'], (function (exports) { 'use strict';
9708
9790
  var _a;
9709
9791
  return destinationGroup.model.openPanel(removedPanel, {
9710
9792
  index: destinationIndex,
9711
- skipSetActive: ((_a = options.skipSetActive) !== null && _a !== void 0 ? _a : false) && !isDestinationGroupEmpty,
9793
+ skipSetActive: ((_a = options.skipSetActive) !== null && _a !== void 0 ? _a : false) &&
9794
+ !isDestinationGroupEmpty,
9712
9795
  skipSetGroupActive: true,
9713
9796
  });
9714
9797
  });
@@ -9763,7 +9846,9 @@ define(['exports'], (function (exports) { 'use strict';
9763
9846
  }));
9764
9847
  this.doRemoveGroup(sourceGroup, { skipActive: true });
9765
9848
  const newGroup = this.createGroupAtLocation(targetLocation);
9766
- this.movingLock(() => newGroup.model.openPanel(removedPanel));
9849
+ this.movingLock(() => newGroup.model.openPanel(removedPanel, {
9850
+ skipSetActive: true,
9851
+ }));
9767
9852
  this.doSetGroupAndPanelActive(newGroup);
9768
9853
  this._onDidMovePanel.fire({
9769
9854
  panel: this.getGroupPanel(sourceItemId),
@@ -9796,7 +9881,7 @@ define(['exports'], (function (exports) { 'use strict';
9796
9881
  skipSetActiveGroup: true,
9797
9882
  }));
9798
9883
  if (!removedPanel) {
9799
- throw new Error(`No panel with id ${sourceItemId}`);
9884
+ throw new Error(`dockview: No panel with id ${sourceItemId}`);
9800
9885
  }
9801
9886
  const dropLocation = getRelativeLocation(this.gridview.orientation, referenceLocation, destinationTarget);
9802
9887
  const group = this.createGroupAtLocation(dropLocation);
@@ -9851,7 +9936,7 @@ define(['exports'], (function (exports) { 'use strict';
9851
9936
  case 'floating': {
9852
9937
  const selectedFloatingGroup = this._floatingGroups.find((x) => x.group === from);
9853
9938
  if (!selectedFloatingGroup) {
9854
- throw new Error('failed to find floating group');
9939
+ throw new Error('dockview: failed to find floating group');
9855
9940
  }
9856
9941
  selectedFloatingGroup.dispose();
9857
9942
  break;
@@ -9859,7 +9944,7 @@ define(['exports'], (function (exports) { 'use strict';
9859
9944
  case 'popout': {
9860
9945
  const selectedPopoutGroup = this._popoutGroups.find((x) => x.popoutGroup === from);
9861
9946
  if (!selectedPopoutGroup) {
9862
- throw new Error('failed to find popout group');
9947
+ throw new Error('dockview: failed to find popout group');
9863
9948
  }
9864
9949
  // Remove from popout groups list to prevent automatic restoration
9865
9950
  const index = this._popoutGroups.indexOf(selectedPopoutGroup);