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
  */
@@ -3781,8 +3781,8 @@ define(['exports'], (function (exports) { 'use strict';
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'], (function (exports) { 'use strict';
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'], (function (exports) { 'use strict';
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'], (function (exports) { 'use strict';
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'], (function (exports) { 'use strict';
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;
@@ -8983,7 +9009,7 @@ define(['exports'], (function (exports) { 'use strict';
8983
9009
  : (_e = (_d = this.options.floatingGroupBounds) === null || _d === void 0 ? void 0 : _d.minimumHeightWithinViewport) !== null && _e !== void 0 ? _e : DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE }));
8984
9010
  const el = group.element.querySelector('.dv-void-container');
8985
9011
  if (!el) {
8986
- throw new Error('failed to find drag handle');
9012
+ throw new Error('dockview: failed to find drag handle');
8987
9013
  }
8988
9014
  overlay.setupDrag(el, {
8989
9015
  inDragMode: typeof (options === null || options === void 0 ? void 0 : options.inDragMode) === 'boolean'
@@ -9055,7 +9081,7 @@ define(['exports'], (function (exports) { 'use strict';
9055
9081
  case 'right':
9056
9082
  return this.createGroupAtLocation([this.gridview.length], undefined, options); // insert into last position
9057
9083
  default:
9058
- throw new Error(`unsupported position ${position}`);
9084
+ throw new Error(`dockview: unsupported position ${position}`);
9059
9085
  }
9060
9086
  }
9061
9087
  updateOptions(options) {
@@ -9201,15 +9227,48 @@ define(['exports'], (function (exports) { 'use strict';
9201
9227
  }
9202
9228
  return result;
9203
9229
  }
9204
- fromJSON(data) {
9230
+ fromJSON(data, options) {
9205
9231
  var _a, _b;
9232
+ const existingPanels = new Map();
9233
+ let tempGroup;
9234
+ if (options === null || options === void 0 ? void 0 : options.reuseExistingPanels) {
9235
+ /**
9236
+ * What are we doing here?
9237
+ *
9238
+ * 1. Create a temporary group to hold any panels that currently exist and that also exist in the new layout
9239
+ * 2. Remove that temporary group from the group mapping so that it doesn't get cleared when we clear the layout
9240
+ */
9241
+ tempGroup = this.createGroup();
9242
+ this._groups.delete(tempGroup.api.id);
9243
+ const newPanels = Object.keys(data.panels);
9244
+ for (const panel of this.panels) {
9245
+ if (newPanels.includes(panel.api.id)) {
9246
+ existingPanels.set(panel.api.id, panel);
9247
+ }
9248
+ }
9249
+ this.movingLock(() => {
9250
+ Array.from(existingPanels.values()).forEach((panel) => {
9251
+ this.moveGroupOrPanel({
9252
+ from: {
9253
+ groupId: panel.api.group.api.id,
9254
+ panelId: panel.api.id,
9255
+ },
9256
+ to: {
9257
+ group: tempGroup,
9258
+ position: 'center',
9259
+ },
9260
+ keepEmptyGroups: true,
9261
+ });
9262
+ });
9263
+ });
9264
+ }
9206
9265
  this.clear();
9207
9266
  if (typeof data !== 'object' || data === null) {
9208
- throw new Error('serialized layout must be a non-null object');
9267
+ throw new Error('dockview: serialized layout must be a non-null object');
9209
9268
  }
9210
9269
  const { grid, panels, activeGroup } = data;
9211
9270
  if (grid.root.type !== 'branch' || !Array.isArray(grid.root.data)) {
9212
- throw new Error('root must be of type branch');
9271
+ throw new Error('dockview: root must be of type branch');
9213
9272
  }
9214
9273
  try {
9215
9274
  // take note of the existing dimensions
@@ -9218,7 +9277,7 @@ define(['exports'], (function (exports) { 'use strict';
9218
9277
  const createGroupFromSerializedState = (data) => {
9219
9278
  const { id, locked, hideHeader, views, activeView } = data;
9220
9279
  if (typeof id !== 'string') {
9221
- throw new Error('group id must be of type string');
9280
+ throw new Error('dockview: group id must be of type string');
9222
9281
  }
9223
9282
  const group = this.createGroup({
9224
9283
  id,
@@ -9233,17 +9292,38 @@ define(['exports'], (function (exports) { 'use strict';
9233
9292
  * In running this section first we avoid firing lots of 'add' events in the event of a failure
9234
9293
  * due to a corruption of input data.
9235
9294
  */
9236
- const panel = this._deserializer.fromJSON(panels[child], group);
9237
- createdPanels.push(panel);
9295
+ const existingPanel = existingPanels.get(child);
9296
+ if (tempGroup && existingPanel) {
9297
+ this.movingLock(() => {
9298
+ tempGroup.model.removePanel(existingPanel);
9299
+ });
9300
+ createdPanels.push(existingPanel);
9301
+ existingPanel.updateFromStateModel(panels[child]);
9302
+ }
9303
+ else {
9304
+ const panel = this._deserializer.fromJSON(panels[child], group);
9305
+ createdPanels.push(panel);
9306
+ }
9238
9307
  }
9239
9308
  for (let i = 0; i < views.length; i++) {
9240
9309
  const panel = createdPanels[i];
9241
9310
  const isActive = typeof activeView === 'string' &&
9242
9311
  activeView === panel.id;
9243
- group.model.openPanel(panel, {
9244
- skipSetActive: !isActive,
9245
- skipSetGroupActive: true,
9246
- });
9312
+ const hasExisting = existingPanels.has(panel.api.id);
9313
+ if (hasExisting) {
9314
+ this.movingLock(() => {
9315
+ group.model.openPanel(panel, {
9316
+ skipSetActive: !isActive,
9317
+ skipSetGroupActive: true,
9318
+ });
9319
+ });
9320
+ }
9321
+ else {
9322
+ group.model.openPanel(panel, {
9323
+ skipSetActive: !isActive,
9324
+ skipSetGroupActive: true,
9325
+ });
9326
+ }
9247
9327
  }
9248
9328
  if (!group.activePanel && group.panels.length > 0) {
9249
9329
  group.model.openPanel(group.panels[group.panels.length - 1], {
@@ -9282,7 +9362,9 @@ define(['exports'], (function (exports) { 'use strict';
9282
9362
  setTimeout(() => {
9283
9363
  this.addPopoutGroup(group, {
9284
9364
  position: position !== null && position !== void 0 ? position : undefined,
9285
- overridePopoutGroup: gridReferenceGroup ? group : undefined,
9365
+ overridePopoutGroup: gridReferenceGroup
9366
+ ? group
9367
+ : undefined,
9286
9368
  referenceGroup: gridReferenceGroup
9287
9369
  ? this.getPanel(gridReferenceGroup)
9288
9370
  : undefined,
@@ -9368,11 +9450,11 @@ define(['exports'], (function (exports) { 'use strict';
9368
9450
  addPanel(options) {
9369
9451
  var _a, _b;
9370
9452
  if (this.panels.find((_) => _.id === options.id)) {
9371
- throw new Error(`panel with id ${options.id} already exists`);
9453
+ throw new Error(`dockview: panel with id ${options.id} already exists`);
9372
9454
  }
9373
9455
  let referenceGroup;
9374
9456
  if (options.position && options.floating) {
9375
- throw new Error('you can only provide one of: position, floating as arguments to .addPanel(...)');
9457
+ throw new Error('dockview: you can only provide one of: position, floating as arguments to .addPanel(...)');
9376
9458
  }
9377
9459
  const initial = {
9378
9460
  width: options.initialWidth,
@@ -9386,7 +9468,7 @@ define(['exports'], (function (exports) { 'use strict';
9386
9468
  : options.position.referencePanel;
9387
9469
  index = options.position.index;
9388
9470
  if (!referencePanel) {
9389
- throw new Error(`referencePanel '${options.position.referencePanel}' does not exist`);
9471
+ throw new Error(`dockview: referencePanel '${options.position.referencePanel}' does not exist`);
9390
9472
  }
9391
9473
  referenceGroup = this.findGroup(referencePanel);
9392
9474
  }
@@ -9397,7 +9479,7 @@ define(['exports'], (function (exports) { 'use strict';
9397
9479
  : options.position.referenceGroup;
9398
9480
  index = options.position.index;
9399
9481
  if (!referenceGroup) {
9400
- throw new Error(`referenceGroup '${options.position.referenceGroup}' does not exist`);
9482
+ throw new Error(`dockview: referenceGroup '${options.position.referenceGroup}' does not exist`);
9401
9483
  }
9402
9484
  }
9403
9485
  else {
@@ -9509,7 +9591,7 @@ define(['exports'], (function (exports) { 'use strict';
9509
9591
  }) {
9510
9592
  const group = panel.group;
9511
9593
  if (!group) {
9512
- throw new Error(`cannot remove panel ${panel.id}. it's missing a group.`);
9594
+ throw new Error(`dockview: cannot remove panel ${panel.id}. it's missing a group.`);
9513
9595
  }
9514
9596
  group.model.removePanel(panel, {
9515
9597
  skipSetActiveGroup: options.skipSetActiveGroup,
@@ -9558,11 +9640,11 @@ define(['exports'], (function (exports) { 'use strict';
9558
9640
  ? this.panels.find((panel) => panel.id === options.referencePanel)
9559
9641
  : options.referencePanel;
9560
9642
  if (!referencePanel) {
9561
- throw new Error(`reference panel ${options.referencePanel} does not exist`);
9643
+ throw new Error(`dockview: reference panel ${options.referencePanel} does not exist`);
9562
9644
  }
9563
9645
  referenceGroup = this.findGroup(referencePanel);
9564
9646
  if (!referenceGroup) {
9565
- throw new Error(`reference group for reference panel ${options.referencePanel} does not exist`);
9647
+ throw new Error(`dockview: reference group for reference panel ${options.referencePanel} does not exist`);
9566
9648
  }
9567
9649
  }
9568
9650
  else if (isGroupOptionsWithGroup(options)) {
@@ -9571,7 +9653,7 @@ define(['exports'], (function (exports) { 'use strict';
9571
9653
  ? (_a = this._groups.get(options.referenceGroup)) === null || _a === void 0 ? void 0 : _a.value
9572
9654
  : options.referenceGroup;
9573
9655
  if (!referenceGroup) {
9574
- throw new Error(`reference group ${options.referenceGroup} does not exist`);
9656
+ throw new Error(`dockview: reference group ${options.referenceGroup} does not exist`);
9575
9657
  }
9576
9658
  }
9577
9659
  else {
@@ -9639,7 +9721,7 @@ define(['exports'], (function (exports) { 'use strict';
9639
9721
  }
9640
9722
  return floatingGroup.group;
9641
9723
  }
9642
- throw new Error('failed to find floating group');
9724
+ throw new Error('dockview: failed to find floating group');
9643
9725
  }
9644
9726
  if (group.api.location.type === 'popout') {
9645
9727
  const selectedGroup = this._popoutGroups.find((_) => _.popoutGroup === group);
@@ -9670,7 +9752,7 @@ define(['exports'], (function (exports) { 'use strict';
9670
9752
  this.updateWatermark();
9671
9753
  return selectedGroup.popoutGroup;
9672
9754
  }
9673
- throw new Error('failed to find popout group');
9755
+ throw new Error('dockview: failed to find popout group');
9674
9756
  }
9675
9757
  const re = super.doRemoveGroup(group, options);
9676
9758
  if (!(options === null || options === void 0 ? void 0 : options.skipActive)) {
@@ -9701,7 +9783,7 @@ define(['exports'], (function (exports) { 'use strict';
9701
9783
  ? (_a = this._groups.get(sourceGroupId)) === null || _a === void 0 ? void 0 : _a.value
9702
9784
  : undefined;
9703
9785
  if (!sourceGroup) {
9704
- throw new Error(`Failed to find group id ${sourceGroupId}`);
9786
+ throw new Error(`dockview: Failed to find group id ${sourceGroupId}`);
9705
9787
  }
9706
9788
  if (sourceItemId === undefined) {
9707
9789
  /**
@@ -9726,9 +9808,9 @@ define(['exports'], (function (exports) { 'use strict';
9726
9808
  skipSetActiveGroup: true,
9727
9809
  }));
9728
9810
  if (!removedPanel) {
9729
- throw new Error(`No panel with id ${sourceItemId}`);
9811
+ throw new Error(`dockview: No panel with id ${sourceItemId}`);
9730
9812
  }
9731
- if (sourceGroup.model.size === 0) {
9813
+ if (!options.keepEmptyGroups && sourceGroup.model.size === 0) {
9732
9814
  // remove the group and do not set a new group as active
9733
9815
  this.doRemoveGroup(sourceGroup, { skipActive: true });
9734
9816
  }
@@ -9738,7 +9820,8 @@ define(['exports'], (function (exports) { 'use strict';
9738
9820
  var _a;
9739
9821
  return destinationGroup.model.openPanel(removedPanel, {
9740
9822
  index: destinationIndex,
9741
- skipSetActive: ((_a = options.skipSetActive) !== null && _a !== void 0 ? _a : false) && !isDestinationGroupEmpty,
9823
+ skipSetActive: ((_a = options.skipSetActive) !== null && _a !== void 0 ? _a : false) &&
9824
+ !isDestinationGroupEmpty,
9742
9825
  skipSetGroupActive: true,
9743
9826
  });
9744
9827
  });
@@ -9793,7 +9876,9 @@ define(['exports'], (function (exports) { 'use strict';
9793
9876
  }));
9794
9877
  this.doRemoveGroup(sourceGroup, { skipActive: true });
9795
9878
  const newGroup = this.createGroupAtLocation(targetLocation);
9796
- this.movingLock(() => newGroup.model.openPanel(removedPanel));
9879
+ this.movingLock(() => newGroup.model.openPanel(removedPanel, {
9880
+ skipSetActive: true,
9881
+ }));
9797
9882
  this.doSetGroupAndPanelActive(newGroup);
9798
9883
  this._onDidMovePanel.fire({
9799
9884
  panel: this.getGroupPanel(sourceItemId),
@@ -9826,7 +9911,7 @@ define(['exports'], (function (exports) { 'use strict';
9826
9911
  skipSetActiveGroup: true,
9827
9912
  }));
9828
9913
  if (!removedPanel) {
9829
- throw new Error(`No panel with id ${sourceItemId}`);
9914
+ throw new Error(`dockview: No panel with id ${sourceItemId}`);
9830
9915
  }
9831
9916
  const dropLocation = getRelativeLocation(this.gridview.orientation, referenceLocation, destinationTarget);
9832
9917
  const group = this.createGroupAtLocation(dropLocation);
@@ -9881,7 +9966,7 @@ define(['exports'], (function (exports) { 'use strict';
9881
9966
  case 'floating': {
9882
9967
  const selectedFloatingGroup = this._floatingGroups.find((x) => x.group === from);
9883
9968
  if (!selectedFloatingGroup) {
9884
- throw new Error('failed to find floating group');
9969
+ throw new Error('dockview: failed to find floating group');
9885
9970
  }
9886
9971
  selectedFloatingGroup.dispose();
9887
9972
  break;
@@ -9889,7 +9974,7 @@ define(['exports'], (function (exports) { 'use strict';
9889
9974
  case 'popout': {
9890
9975
  const selectedPopoutGroup = this._popoutGroups.find((x) => x.popoutGroup === from);
9891
9976
  if (!selectedPopoutGroup) {
9892
- throw new Error('failed to find popout group');
9977
+ throw new Error('dockview: failed to find popout group');
9893
9978
  }
9894
9979
  // Remove from popout groups list to prevent automatic restoration
9895
9980
  const index = this._popoutGroups.indexOf(selectedPopoutGroup);