dockview-react 2.0.0 → 2.1.1

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-react
3
- * @version 2.0.0
3
+ * @version 2.1.1
4
4
  * @link https://github.com/mathuo/dockview
5
5
  * @license MIT
6
6
  */
@@ -2189,6 +2189,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
2189
2189
  if (this.hasMaximizedView()) {
2190
2190
  this.exitMaximizedView();
2191
2191
  }
2192
+ serializeBranchNode(this.getView(), this.orientation);
2192
2193
  const hiddenOnMaximize = [];
2193
2194
  function hideAllViewsBut(parent, exclude) {
2194
2195
  for (let i = 0; i < parent.children.length; i++) {
@@ -2210,7 +2211,10 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
2210
2211
  }
2211
2212
  hideAllViewsBut(this.root, node);
2212
2213
  this._maximizedNode = { leaf: node, hiddenOnMaximize };
2213
- this._onDidMaximizedNodeChange.fire();
2214
+ this._onDidMaximizedNodeChange.fire({
2215
+ view: node.view,
2216
+ isMaximized: true,
2217
+ });
2214
2218
  }
2215
2219
  exitMaximizedView() {
2216
2220
  if (!this._maximizedNode) {
@@ -2231,24 +2235,51 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
2231
2235
  }
2232
2236
  }
2233
2237
  showViewsInReverseOrder(this.root);
2238
+ const tmp = this._maximizedNode.leaf;
2234
2239
  this._maximizedNode = undefined;
2235
- this._onDidMaximizedNodeChange.fire();
2240
+ this._onDidMaximizedNodeChange.fire({
2241
+ view: tmp.view,
2242
+ isMaximized: false,
2243
+ });
2236
2244
  }
2237
2245
  serialize() {
2246
+ const maximizedView = this.maximizedView();
2247
+ let maxmizedViewLocation;
2248
+ if (maximizedView) {
2249
+ /**
2250
+ * The minimum information we can get away with in order to serialize a maxmized view is it's location within the grid
2251
+ * which is represented as a branch of indices
2252
+ */
2253
+ maxmizedViewLocation = getGridLocation(maximizedView.element);
2254
+ }
2238
2255
  if (this.hasMaximizedView()) {
2239
2256
  /**
2240
- * do not persist maximized view state
2241
- * firstly exit any maximized views to ensure the correct dimensions are persisted
2257
+ * the saved layout cannot be in its maxmized state otherwise all of the underlying
2258
+ * view dimensions will be wrong
2259
+ *
2260
+ * To counteract this we temporaily remove the maximized view to compute the serialized output
2261
+ * of the grid before adding back the maxmized view as to not alter the layout from the users
2262
+ * perspective when `.toJSON()` is called
2242
2263
  */
2243
2264
  this.exitMaximizedView();
2244
2265
  }
2245
2266
  const root = serializeBranchNode(this.getView(), this.orientation);
2246
- return {
2267
+ const resullt = {
2247
2268
  root,
2248
2269
  width: this.width,
2249
2270
  height: this.height,
2250
2271
  orientation: this.orientation,
2251
2272
  };
2273
+ if (maxmizedViewLocation) {
2274
+ resullt.maximizedNode = {
2275
+ location: maxmizedViewLocation,
2276
+ };
2277
+ }
2278
+ if (maximizedView) {
2279
+ // replace any maximzied view that was removed for serialization purposes
2280
+ this.maximizeView(maximizedView);
2281
+ }
2282
+ return resullt;
2252
2283
  }
2253
2284
  dispose() {
2254
2285
  this.disposable.dispose();
@@ -2267,6 +2298,19 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
2267
2298
  const orientation = json.orientation;
2268
2299
  const height = orientation === exports.Orientation.VERTICAL ? json.height : json.width;
2269
2300
  this._deserialize(json.root, orientation, deserializer, height);
2301
+ /**
2302
+ * The deserialied layout must be positioned through this.layout(...)
2303
+ * before any maximizedNode can be positioned
2304
+ */
2305
+ this.layout(json.width, json.height);
2306
+ if (json.maximizedNode) {
2307
+ const location = json.maximizedNode.location;
2308
+ const [_, node] = this.getNode(location);
2309
+ if (!(node instanceof LeafNode)) {
2310
+ return;
2311
+ }
2312
+ this.maximizeView(node.view);
2313
+ }
2270
2314
  }
2271
2315
  _deserialize(root, orientation, deserializer, orthogonalSize) {
2272
2316
  this.root = this._deserializeNode(root, orientation, deserializer, orthogonalSize);
@@ -2691,6 +2735,8 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
2691
2735
  this.onDidRemove = this._onDidRemove.event;
2692
2736
  this._onDidAdd = new Emitter();
2693
2737
  this.onDidAdd = this._onDidAdd.event;
2738
+ this._onDidMaximizedChange = new Emitter();
2739
+ this.onDidMaximizedChange = this._onDidMaximizedChange.event;
2694
2740
  this._onDidActiveChange = new Emitter();
2695
2741
  this.onDidActiveChange = this._onDidActiveChange.event;
2696
2742
  this._bufferOnDidLayoutChange = new AsapEvent();
@@ -2706,7 +2752,12 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
2706
2752
  this.gridview.locked = !!options.locked;
2707
2753
  this.element.appendChild(this.gridview.element);
2708
2754
  this.layout(0, 0, true); // set some elements height/widths
2709
- this.addDisposables(this.gridview.onDidViewVisibilityChange(() => this._onDidViewVisibilityChangeMicroTaskQueue.fire()), this.onDidViewVisibilityChangeMicroTaskQueue(() => {
2755
+ this.addDisposables(this.gridview.onDidMaximizedNodeChange((event) => {
2756
+ this._onDidMaximizedChange.fire({
2757
+ panel: event.view,
2758
+ isMaximized: event.isMaximized,
2759
+ });
2760
+ }), this.gridview.onDidViewVisibilityChange(() => this._onDidViewVisibilityChangeMicroTaskQueue.fire()), this.onDidViewVisibilityChangeMicroTaskQueue(() => {
2710
2761
  this.layout(this.width, this.height, true);
2711
2762
  }), exports.DockviewDisposable.from(() => {
2712
2763
  var _a;
@@ -2756,9 +2807,6 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
2756
2807
  hasMaximizedGroup() {
2757
2808
  return this.gridview.hasMaximizedView();
2758
2809
  }
2759
- get onDidMaximizedGroupChange() {
2760
- return this.gridview.onDidMaximizedNodeChange;
2761
- }
2762
2810
  doAddGroup(group, location = [0], size) {
2763
2811
  this.gridview.addView(group, size !== null && size !== void 0 ? size : exports.Sizing.Distribute, location);
2764
2812
  this._onDidAdd.fire(group);
@@ -4768,7 +4816,6 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
4768
4816
  this.onDragStart = this._onDragStart.event;
4769
4817
  this._element = document.createElement('div');
4770
4818
  this._element.className = 'dv-void-container';
4771
- this._element.tabIndex = 0;
4772
4819
  this._element.draggable = true;
4773
4820
  this.addDisposables(this._onDrop, this._onDragStart, addDisposableListener(this._element, 'pointerdown', () => {
4774
4821
  this.accessor.doSetGroupActive(this.group);
@@ -5082,6 +5129,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
5082
5129
  disableDnd: undefined,
5083
5130
  gap: undefined,
5084
5131
  className: undefined,
5132
+ noPanelsOverlay: undefined,
5085
5133
  };
5086
5134
  return Object.keys(properties);
5087
5135
  })();
@@ -5522,7 +5570,10 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
5522
5570
  this.doClose(panel);
5523
5571
  }
5524
5572
  doClose(panel) {
5525
- this.accessor.removePanel(panel);
5573
+ const isLast = this.panels.length === 1 && this.accessor.groups.length === 1;
5574
+ this.accessor.removePanel(panel, isLast && this.accessor.options.noPanelsOverlay === 'emptyGroup'
5575
+ ? { removeEmptyGroup: false }
5576
+ : undefined);
5526
5577
  }
5527
5578
  isPanelActive(panel) {
5528
5579
  return this._activePanel === panel;
@@ -5628,7 +5679,6 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
5628
5679
  }
5629
5680
  updateContainer() {
5630
5681
  var _a, _b;
5631
- toggleClass(this.container, 'dv-empty', this.isEmpty);
5632
5682
  this.panels.forEach((panel) => panel.runEvents());
5633
5683
  if (this.isEmpty && !this.watermark) {
5634
5684
  const watermark = this.accessor.createWatermarkComponent();
@@ -5642,14 +5692,12 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
5642
5692
  this.accessor.doSetGroupActive(this.groupPanel);
5643
5693
  }
5644
5694
  });
5645
- this.tabsContainer.hide();
5646
5695
  this.contentContainer.element.appendChild(this.watermark.element);
5647
5696
  }
5648
5697
  if (!this.isEmpty && this.watermark) {
5649
5698
  this.watermark.element.remove();
5650
5699
  (_b = (_a = this.watermark).dispose) === null || _b === void 0 ? void 0 : _b.call(_a);
5651
5700
  this.watermark = undefined;
5652
- this.tabsContainer.show();
5653
5701
  }
5654
5702
  }
5655
5703
  canDisplayOverlay(event, position, target) {
@@ -6577,38 +6625,9 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
6577
6625
  super();
6578
6626
  this._element = document.createElement('div');
6579
6627
  this._element.className = 'dv-watermark';
6580
- const title = document.createElement('div');
6581
- title.className = 'dv-watermark-title';
6582
- const emptySpace = document.createElement('span');
6583
- emptySpace.style.flexGrow = '1';
6584
- const content = document.createElement('div');
6585
- content.className = 'dv-watermark-content';
6586
- this._element.appendChild(title);
6587
- this._element.appendChild(content);
6588
- const actionsContainer = document.createElement('div');
6589
- actionsContainer.className = 'dv-actions-container';
6590
- const closeAnchor = document.createElement('div');
6591
- closeAnchor.className = 'dv-close-action';
6592
- closeAnchor.appendChild(createCloseButton());
6593
- actionsContainer.appendChild(closeAnchor);
6594
- title.appendChild(emptySpace);
6595
- title.appendChild(actionsContainer);
6596
- this.addDisposables(addDisposableListener(closeAnchor, 'click', (event) => {
6597
- var _a;
6598
- event.preventDefault();
6599
- if (this._group) {
6600
- (_a = this._api) === null || _a === void 0 ? void 0 : _a.removeGroup(this._group);
6601
- }
6602
- }));
6603
6628
  }
6604
6629
  init(_params) {
6605
- this._api = _params.containerApi;
6606
- this._group = _params.group;
6607
- this.render();
6608
- }
6609
- render() {
6610
- const isOneGroup = !!(this._api && this._api.size <= 1);
6611
- toggleClass(this.element, 'dv-has-actions', isOneGroup);
6630
+ // noop
6612
6631
  }
6613
6632
  }
6614
6633
 
@@ -6645,6 +6664,9 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
6645
6664
  get element() {
6646
6665
  return this._element;
6647
6666
  }
6667
+ get isVisible() {
6668
+ return this._isVisible;
6669
+ }
6648
6670
  constructor(options) {
6649
6671
  super();
6650
6672
  this.options = options;
@@ -6655,6 +6677,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
6655
6677
  this.onDidChangeEnd = this._onDidChangeEnd.event;
6656
6678
  this.addDisposables(this._onDidChange, this._onDidChangeEnd);
6657
6679
  this._element.className = 'dv-resize-container';
6680
+ this._isVisible = true;
6658
6681
  this.setupResize('top');
6659
6682
  this.setupResize('bottom');
6660
6683
  this.setupResize('left');
@@ -6669,6 +6692,13 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
6669
6692
  this.setBounds(Object.assign(Object.assign(Object.assign(Object.assign({ height: this.options.height, width: this.options.width }, ('top' in this.options && { top: this.options.top })), ('bottom' in this.options && { bottom: this.options.bottom })), ('left' in this.options && { left: this.options.left })), ('right' in this.options && { right: this.options.right })));
6670
6693
  arialLevelTracker.push(this._element);
6671
6694
  }
6695
+ setVisible(isVisible) {
6696
+ if (isVisible === this.isVisible) {
6697
+ return;
6698
+ }
6699
+ this._isVisible = isVisible;
6700
+ toggleClass(this.element, 'dv-hidden', !this.isVisible);
6701
+ }
6672
6702
  bringToFront() {
6673
6703
  arialLevelTracker.push(this._element);
6674
6704
  }
@@ -7405,6 +7435,8 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
7405
7435
  this.onDidActivePanelChange = this._onDidActivePanelChange.event;
7406
7436
  this._onDidMovePanel = new Emitter();
7407
7437
  this.onDidMovePanel = this._onDidMovePanel.event;
7438
+ this._onDidMaximizedGroupChange = new Emitter();
7439
+ this.onDidMaximizedGroupChange = this._onDidMaximizedGroupChange.event;
7408
7440
  this._floatingGroups = [];
7409
7441
  this._popoutGroups = [];
7410
7442
  this._onDidRemoveGroup = new Emitter();
@@ -7431,6 +7463,11 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
7431
7463
  if (!this._moving) {
7432
7464
  this._onDidActiveGroupChange.fire(event);
7433
7465
  }
7466
+ }), this.onDidMaximizedChange((event) => {
7467
+ this._onDidMaximizedGroupChange.fire({
7468
+ group: event.panel,
7469
+ isMaximized: event.isMaximized,
7470
+ });
7434
7471
  }), exports.DockviewEvent.any(this.onDidAdd, this.onDidRemove)(() => {
7435
7472
  this.updateWatermark();
7436
7473
  }), exports.DockviewEvent.any(this.onDidAddPanel, this.onDidRemovePanel, this.onDidAddGroup, this.onDidRemove, this.onDidMovePanel, this.onDidActivePanelChange)(() => {
@@ -7529,8 +7566,28 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
7529
7566
  this._api = new DockviewApi(this);
7530
7567
  this.updateWatermark();
7531
7568
  }
7569
+ setVisible(panel, visible) {
7570
+ switch (panel.api.location.type) {
7571
+ case 'grid':
7572
+ super.setVisible(panel, visible);
7573
+ break;
7574
+ case 'floating': {
7575
+ const item = this.floatingGroups.find((floatingGroup) => floatingGroup.group === panel);
7576
+ if (item) {
7577
+ item.overlay.setVisible(visible);
7578
+ panel.api._onDidVisibilityChange.fire({
7579
+ isVisible: visible,
7580
+ });
7581
+ }
7582
+ break;
7583
+ }
7584
+ case 'popout':
7585
+ console.warn('dockview: You cannot hide a group that is in a popout window');
7586
+ break;
7587
+ }
7588
+ }
7532
7589
  addPopoutGroup(itemToPopout, options) {
7533
- var _a, _b, _c;
7590
+ var _a, _b, _c, _d, _e;
7534
7591
  if (itemToPopout instanceof DockviewPanel &&
7535
7592
  itemToPopout.group.size === 1) {
7536
7593
  return this.addPopoutGroup(itemToPopout.group, options);
@@ -7553,7 +7610,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
7553
7610
  const groupId = (_b = (_a = options === null || options === void 0 ? void 0 : options.overridePopoutGroup) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : this.getNextGroupId();
7554
7611
  const _window = new PopoutWindow(`${this.id}-${groupId}`, // unique id
7555
7612
  theme !== null && theme !== void 0 ? theme : '', {
7556
- url: (_c = options === null || options === void 0 ? void 0 : options.popoutUrl) !== null && _c !== void 0 ? _c : '/popout.html',
7613
+ url: (_e = (_c = options === null || options === void 0 ? void 0 : options.popoutUrl) !== null && _c !== void 0 ? _c : (_d = this.options) === null || _d === void 0 ? void 0 : _d.popoutUrl) !== null && _e !== void 0 ? _e : '/popout.html',
7557
7614
  left: window.screenX + box.left,
7558
7615
  top: window.screenY + box.top,
7559
7616
  width: box.width,
@@ -7567,7 +7624,6 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
7567
7624
  return _window
7568
7625
  .open()
7569
7626
  .then((popoutContainer) => {
7570
- var _a;
7571
7627
  if (_window.isDisposed) {
7572
7628
  return false;
7573
7629
  }
@@ -7587,14 +7643,19 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
7587
7643
  * of this case is when being called from the `fromJSON(...)` method
7588
7644
  */
7589
7645
  const isGroupAddedToDom = referenceGroup.element.parentElement !== null;
7590
- const group = !isGroupAddedToDom
7591
- ? referenceGroup
7592
- : (_a = options === null || options === void 0 ? void 0 : options.overridePopoutGroup) !== null && _a !== void 0 ? _a : this.createGroup({ id: groupId });
7593
- group.model.renderContainer = overlayRenderContainer;
7594
- group.layout(_window.window.innerWidth, _window.window.innerHeight);
7595
- if (!this._groups.has(group.api.id)) {
7646
+ let group;
7647
+ if (!isGroupAddedToDom) {
7648
+ group = referenceGroup;
7649
+ }
7650
+ else if (options === null || options === void 0 ? void 0 : options.overridePopoutGroup) {
7651
+ group = options.overridePopoutGroup;
7652
+ }
7653
+ else {
7654
+ group = this.createGroup({ id: groupId });
7596
7655
  this._onDidAddGroup.fire(group);
7597
7656
  }
7657
+ group.model.renderContainer = overlayRenderContainer;
7658
+ group.layout(_window.window.innerWidth, _window.window.innerHeight);
7598
7659
  if (!(options === null || options === void 0 ? void 0 : options.overridePopoutGroup) && isGroupAddedToDom) {
7599
7660
  if (itemToPopout instanceof DockviewPanel) {
7600
7661
  this.movingLock(() => {
@@ -7625,6 +7686,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
7625
7686
  group.model.location = {
7626
7687
  type: 'popout',
7627
7688
  getWindow: () => _window.window,
7689
+ popoutUrl: options === null || options === void 0 ? void 0 : options.popoutUrl,
7628
7690
  };
7629
7691
  if (isGroupAddedToDom &&
7630
7692
  itemToPopout.api.location.type === 'grid') {
@@ -7641,16 +7703,15 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
7641
7703
  (_a = _window.window) === null || _a === void 0 ? void 0 : _a.focus();
7642
7704
  }));
7643
7705
  let returnedGroup;
7706
+ const isValidReferenceGroup = isGroupAddedToDom &&
7707
+ referenceGroup &&
7708
+ this.getPanel(referenceGroup.id);
7644
7709
  const value = {
7645
7710
  window: _window,
7646
7711
  popoutGroup: group,
7647
- referenceGroup: !isGroupAddedToDom
7648
- ? undefined
7649
- : referenceGroup
7650
- ? this.getPanel(referenceGroup.id)
7651
- ? referenceGroup.id
7652
- : undefined
7653
- : undefined,
7712
+ referenceGroup: isValidReferenceGroup
7713
+ ? referenceGroup.id
7714
+ : undefined,
7654
7715
  disposable: {
7655
7716
  dispose: () => {
7656
7717
  popoutWindowDisposable.dispose();
@@ -7999,6 +8060,9 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
7999
8060
  data: group.popoutGroup.toJSON(),
8000
8061
  gridReferenceGroup: group.referenceGroup,
8001
8062
  position: group.window.dimensions(),
8063
+ url: group.popoutGroup.api.location.type === 'popout'
8064
+ ? group.popoutGroup.api.location.popoutUrl
8065
+ : undefined,
8002
8066
  };
8003
8067
  });
8004
8068
  const result = {
@@ -8085,7 +8149,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
8085
8149
  }
8086
8150
  const serializedPopoutGroups = (_b = data.popoutGroups) !== null && _b !== void 0 ? _b : [];
8087
8151
  for (const serializedPopoutGroup of serializedPopoutGroups) {
8088
- const { data, position, gridReferenceGroup } = serializedPopoutGroup;
8152
+ const { data, position, gridReferenceGroup, url } = serializedPopoutGroup;
8089
8153
  const group = createGroupFromSerializedState(data);
8090
8154
  this.addPopoutGroup((_c = (gridReferenceGroup
8091
8155
  ? this.getPanel(gridReferenceGroup)
@@ -8094,6 +8158,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
8094
8158
  overridePopoutGroup: gridReferenceGroup
8095
8159
  ? group
8096
8160
  : undefined,
8161
+ popoutUrl: url,
8097
8162
  });
8098
8163
  }
8099
8164
  for (const floatingGroup of this._floatingGroups) {
@@ -8303,7 +8368,6 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
8303
8368
  }
8304
8369
  removePanel(panel, options = {
8305
8370
  removeEmptyGroup: true,
8306
- skipDispose: false,
8307
8371
  }) {
8308
8372
  const group = panel.group;
8309
8373
  if (!group) {
@@ -8447,7 +8511,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
8447
8511
  const refGroup = selectedGroup.referenceGroup
8448
8512
  ? this.getPanel(selectedGroup.referenceGroup)
8449
8513
  : undefined;
8450
- if (refGroup) {
8514
+ if (refGroup && refGroup.panels.length === 0) {
8451
8515
  this.removeGroup(refGroup);
8452
8516
  }
8453
8517
  }