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
  */
@@ -2193,6 +2193,7 @@
2193
2193
  if (this.hasMaximizedView()) {
2194
2194
  this.exitMaximizedView();
2195
2195
  }
2196
+ serializeBranchNode(this.getView(), this.orientation);
2196
2197
  const hiddenOnMaximize = [];
2197
2198
  function hideAllViewsBut(parent, exclude) {
2198
2199
  for (let i = 0; i < parent.children.length; i++) {
@@ -2214,7 +2215,10 @@
2214
2215
  }
2215
2216
  hideAllViewsBut(this.root, node);
2216
2217
  this._maximizedNode = { leaf: node, hiddenOnMaximize };
2217
- this._onDidMaximizedNodeChange.fire();
2218
+ this._onDidMaximizedNodeChange.fire({
2219
+ view: node.view,
2220
+ isMaximized: true,
2221
+ });
2218
2222
  }
2219
2223
  exitMaximizedView() {
2220
2224
  if (!this._maximizedNode) {
@@ -2235,24 +2239,51 @@
2235
2239
  }
2236
2240
  }
2237
2241
  showViewsInReverseOrder(this.root);
2242
+ const tmp = this._maximizedNode.leaf;
2238
2243
  this._maximizedNode = undefined;
2239
- this._onDidMaximizedNodeChange.fire();
2244
+ this._onDidMaximizedNodeChange.fire({
2245
+ view: tmp.view,
2246
+ isMaximized: false,
2247
+ });
2240
2248
  }
2241
2249
  serialize() {
2250
+ const maximizedView = this.maximizedView();
2251
+ let maxmizedViewLocation;
2252
+ if (maximizedView) {
2253
+ /**
2254
+ * The minimum information we can get away with in order to serialize a maxmized view is it's location within the grid
2255
+ * which is represented as a branch of indices
2256
+ */
2257
+ maxmizedViewLocation = getGridLocation(maximizedView.element);
2258
+ }
2242
2259
  if (this.hasMaximizedView()) {
2243
2260
  /**
2244
- * do not persist maximized view state
2245
- * firstly exit any maximized views to ensure the correct dimensions are persisted
2261
+ * the saved layout cannot be in its maxmized state otherwise all of the underlying
2262
+ * view dimensions will be wrong
2263
+ *
2264
+ * To counteract this we temporaily remove the maximized view to compute the serialized output
2265
+ * of the grid before adding back the maxmized view as to not alter the layout from the users
2266
+ * perspective when `.toJSON()` is called
2246
2267
  */
2247
2268
  this.exitMaximizedView();
2248
2269
  }
2249
2270
  const root = serializeBranchNode(this.getView(), this.orientation);
2250
- return {
2271
+ const resullt = {
2251
2272
  root,
2252
2273
  width: this.width,
2253
2274
  height: this.height,
2254
2275
  orientation: this.orientation,
2255
2276
  };
2277
+ if (maxmizedViewLocation) {
2278
+ resullt.maximizedNode = {
2279
+ location: maxmizedViewLocation,
2280
+ };
2281
+ }
2282
+ if (maximizedView) {
2283
+ // replace any maximzied view that was removed for serialization purposes
2284
+ this.maximizeView(maximizedView);
2285
+ }
2286
+ return resullt;
2256
2287
  }
2257
2288
  dispose() {
2258
2289
  this.disposable.dispose();
@@ -2271,6 +2302,19 @@
2271
2302
  const orientation = json.orientation;
2272
2303
  const height = orientation === exports.Orientation.VERTICAL ? json.height : json.width;
2273
2304
  this._deserialize(json.root, orientation, deserializer, height);
2305
+ /**
2306
+ * The deserialied layout must be positioned through this.layout(...)
2307
+ * before any maximizedNode can be positioned
2308
+ */
2309
+ this.layout(json.width, json.height);
2310
+ if (json.maximizedNode) {
2311
+ const location = json.maximizedNode.location;
2312
+ const [_, node] = this.getNode(location);
2313
+ if (!(node instanceof LeafNode)) {
2314
+ return;
2315
+ }
2316
+ this.maximizeView(node.view);
2317
+ }
2274
2318
  }
2275
2319
  _deserialize(root, orientation, deserializer, orthogonalSize) {
2276
2320
  this.root = this._deserializeNode(root, orientation, deserializer, orthogonalSize);
@@ -2695,6 +2739,8 @@
2695
2739
  this.onDidRemove = this._onDidRemove.event;
2696
2740
  this._onDidAdd = new Emitter();
2697
2741
  this.onDidAdd = this._onDidAdd.event;
2742
+ this._onDidMaximizedChange = new Emitter();
2743
+ this.onDidMaximizedChange = this._onDidMaximizedChange.event;
2698
2744
  this._onDidActiveChange = new Emitter();
2699
2745
  this.onDidActiveChange = this._onDidActiveChange.event;
2700
2746
  this._bufferOnDidLayoutChange = new AsapEvent();
@@ -2710,7 +2756,12 @@
2710
2756
  this.gridview.locked = !!options.locked;
2711
2757
  this.element.appendChild(this.gridview.element);
2712
2758
  this.layout(0, 0, true); // set some elements height/widths
2713
- this.addDisposables(this.gridview.onDidViewVisibilityChange(() => this._onDidViewVisibilityChangeMicroTaskQueue.fire()), this.onDidViewVisibilityChangeMicroTaskQueue(() => {
2759
+ this.addDisposables(this.gridview.onDidMaximizedNodeChange((event) => {
2760
+ this._onDidMaximizedChange.fire({
2761
+ panel: event.view,
2762
+ isMaximized: event.isMaximized,
2763
+ });
2764
+ }), this.gridview.onDidViewVisibilityChange(() => this._onDidViewVisibilityChangeMicroTaskQueue.fire()), this.onDidViewVisibilityChangeMicroTaskQueue(() => {
2714
2765
  this.layout(this.width, this.height, true);
2715
2766
  }), exports.DockviewDisposable.from(() => {
2716
2767
  var _a;
@@ -2760,9 +2811,6 @@
2760
2811
  hasMaximizedGroup() {
2761
2812
  return this.gridview.hasMaximizedView();
2762
2813
  }
2763
- get onDidMaximizedGroupChange() {
2764
- return this.gridview.onDidMaximizedNodeChange;
2765
- }
2766
2814
  doAddGroup(group, location = [0], size) {
2767
2815
  this.gridview.addView(group, size !== null && size !== void 0 ? size : exports.Sizing.Distribute, location);
2768
2816
  this._onDidAdd.fire(group);
@@ -4772,7 +4820,6 @@
4772
4820
  this.onDragStart = this._onDragStart.event;
4773
4821
  this._element = document.createElement('div');
4774
4822
  this._element.className = 'dv-void-container';
4775
- this._element.tabIndex = 0;
4776
4823
  this._element.draggable = true;
4777
4824
  this.addDisposables(this._onDrop, this._onDragStart, addDisposableListener(this._element, 'pointerdown', () => {
4778
4825
  this.accessor.doSetGroupActive(this.group);
@@ -5086,6 +5133,7 @@
5086
5133
  disableDnd: undefined,
5087
5134
  gap: undefined,
5088
5135
  className: undefined,
5136
+ noPanelsOverlay: undefined,
5089
5137
  };
5090
5138
  return Object.keys(properties);
5091
5139
  })();
@@ -5526,7 +5574,10 @@
5526
5574
  this.doClose(panel);
5527
5575
  }
5528
5576
  doClose(panel) {
5529
- this.accessor.removePanel(panel);
5577
+ const isLast = this.panels.length === 1 && this.accessor.groups.length === 1;
5578
+ this.accessor.removePanel(panel, isLast && this.accessor.options.noPanelsOverlay === 'emptyGroup'
5579
+ ? { removeEmptyGroup: false }
5580
+ : undefined);
5530
5581
  }
5531
5582
  isPanelActive(panel) {
5532
5583
  return this._activePanel === panel;
@@ -5632,7 +5683,6 @@
5632
5683
  }
5633
5684
  updateContainer() {
5634
5685
  var _a, _b;
5635
- toggleClass(this.container, 'dv-empty', this.isEmpty);
5636
5686
  this.panels.forEach((panel) => panel.runEvents());
5637
5687
  if (this.isEmpty && !this.watermark) {
5638
5688
  const watermark = this.accessor.createWatermarkComponent();
@@ -5646,14 +5696,12 @@
5646
5696
  this.accessor.doSetGroupActive(this.groupPanel);
5647
5697
  }
5648
5698
  });
5649
- this.tabsContainer.hide();
5650
5699
  this.contentContainer.element.appendChild(this.watermark.element);
5651
5700
  }
5652
5701
  if (!this.isEmpty && this.watermark) {
5653
5702
  this.watermark.element.remove();
5654
5703
  (_b = (_a = this.watermark).dispose) === null || _b === void 0 ? void 0 : _b.call(_a);
5655
5704
  this.watermark = undefined;
5656
- this.tabsContainer.show();
5657
5705
  }
5658
5706
  }
5659
5707
  canDisplayOverlay(event, position, target) {
@@ -6581,38 +6629,9 @@
6581
6629
  super();
6582
6630
  this._element = document.createElement('div');
6583
6631
  this._element.className = 'dv-watermark';
6584
- const title = document.createElement('div');
6585
- title.className = 'dv-watermark-title';
6586
- const emptySpace = document.createElement('span');
6587
- emptySpace.style.flexGrow = '1';
6588
- const content = document.createElement('div');
6589
- content.className = 'dv-watermark-content';
6590
- this._element.appendChild(title);
6591
- this._element.appendChild(content);
6592
- const actionsContainer = document.createElement('div');
6593
- actionsContainer.className = 'dv-actions-container';
6594
- const closeAnchor = document.createElement('div');
6595
- closeAnchor.className = 'dv-close-action';
6596
- closeAnchor.appendChild(createCloseButton());
6597
- actionsContainer.appendChild(closeAnchor);
6598
- title.appendChild(emptySpace);
6599
- title.appendChild(actionsContainer);
6600
- this.addDisposables(addDisposableListener(closeAnchor, 'click', (event) => {
6601
- var _a;
6602
- event.preventDefault();
6603
- if (this._group) {
6604
- (_a = this._api) === null || _a === void 0 ? void 0 : _a.removeGroup(this._group);
6605
- }
6606
- }));
6607
6632
  }
6608
6633
  init(_params) {
6609
- this._api = _params.containerApi;
6610
- this._group = _params.group;
6611
- this.render();
6612
- }
6613
- render() {
6614
- const isOneGroup = !!(this._api && this._api.size <= 1);
6615
- toggleClass(this.element, 'dv-has-actions', isOneGroup);
6634
+ // noop
6616
6635
  }
6617
6636
  }
6618
6637
 
@@ -6649,6 +6668,9 @@
6649
6668
  get element() {
6650
6669
  return this._element;
6651
6670
  }
6671
+ get isVisible() {
6672
+ return this._isVisible;
6673
+ }
6652
6674
  constructor(options) {
6653
6675
  super();
6654
6676
  this.options = options;
@@ -6659,6 +6681,7 @@
6659
6681
  this.onDidChangeEnd = this._onDidChangeEnd.event;
6660
6682
  this.addDisposables(this._onDidChange, this._onDidChangeEnd);
6661
6683
  this._element.className = 'dv-resize-container';
6684
+ this._isVisible = true;
6662
6685
  this.setupResize('top');
6663
6686
  this.setupResize('bottom');
6664
6687
  this.setupResize('left');
@@ -6673,6 +6696,13 @@
6673
6696
  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 })));
6674
6697
  arialLevelTracker.push(this._element);
6675
6698
  }
6699
+ setVisible(isVisible) {
6700
+ if (isVisible === this.isVisible) {
6701
+ return;
6702
+ }
6703
+ this._isVisible = isVisible;
6704
+ toggleClass(this.element, 'dv-hidden', !this.isVisible);
6705
+ }
6676
6706
  bringToFront() {
6677
6707
  arialLevelTracker.push(this._element);
6678
6708
  }
@@ -7409,6 +7439,8 @@
7409
7439
  this.onDidActivePanelChange = this._onDidActivePanelChange.event;
7410
7440
  this._onDidMovePanel = new Emitter();
7411
7441
  this.onDidMovePanel = this._onDidMovePanel.event;
7442
+ this._onDidMaximizedGroupChange = new Emitter();
7443
+ this.onDidMaximizedGroupChange = this._onDidMaximizedGroupChange.event;
7412
7444
  this._floatingGroups = [];
7413
7445
  this._popoutGroups = [];
7414
7446
  this._onDidRemoveGroup = new Emitter();
@@ -7435,6 +7467,11 @@
7435
7467
  if (!this._moving) {
7436
7468
  this._onDidActiveGroupChange.fire(event);
7437
7469
  }
7470
+ }), this.onDidMaximizedChange((event) => {
7471
+ this._onDidMaximizedGroupChange.fire({
7472
+ group: event.panel,
7473
+ isMaximized: event.isMaximized,
7474
+ });
7438
7475
  }), exports.DockviewEvent.any(this.onDidAdd, this.onDidRemove)(() => {
7439
7476
  this.updateWatermark();
7440
7477
  }), exports.DockviewEvent.any(this.onDidAddPanel, this.onDidRemovePanel, this.onDidAddGroup, this.onDidRemove, this.onDidMovePanel, this.onDidActivePanelChange)(() => {
@@ -7533,8 +7570,28 @@
7533
7570
  this._api = new DockviewApi(this);
7534
7571
  this.updateWatermark();
7535
7572
  }
7573
+ setVisible(panel, visible) {
7574
+ switch (panel.api.location.type) {
7575
+ case 'grid':
7576
+ super.setVisible(panel, visible);
7577
+ break;
7578
+ case 'floating': {
7579
+ const item = this.floatingGroups.find((floatingGroup) => floatingGroup.group === panel);
7580
+ if (item) {
7581
+ item.overlay.setVisible(visible);
7582
+ panel.api._onDidVisibilityChange.fire({
7583
+ isVisible: visible,
7584
+ });
7585
+ }
7586
+ break;
7587
+ }
7588
+ case 'popout':
7589
+ console.warn('dockview: You cannot hide a group that is in a popout window');
7590
+ break;
7591
+ }
7592
+ }
7536
7593
  addPopoutGroup(itemToPopout, options) {
7537
- var _a, _b, _c;
7594
+ var _a, _b, _c, _d, _e;
7538
7595
  if (itemToPopout instanceof DockviewPanel &&
7539
7596
  itemToPopout.group.size === 1) {
7540
7597
  return this.addPopoutGroup(itemToPopout.group, options);
@@ -7557,7 +7614,7 @@
7557
7614
  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();
7558
7615
  const _window = new PopoutWindow(`${this.id}-${groupId}`, // unique id
7559
7616
  theme !== null && theme !== void 0 ? theme : '', {
7560
- url: (_c = options === null || options === void 0 ? void 0 : options.popoutUrl) !== null && _c !== void 0 ? _c : '/popout.html',
7617
+ 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',
7561
7618
  left: window.screenX + box.left,
7562
7619
  top: window.screenY + box.top,
7563
7620
  width: box.width,
@@ -7571,7 +7628,6 @@
7571
7628
  return _window
7572
7629
  .open()
7573
7630
  .then((popoutContainer) => {
7574
- var _a;
7575
7631
  if (_window.isDisposed) {
7576
7632
  return false;
7577
7633
  }
@@ -7591,14 +7647,19 @@
7591
7647
  * of this case is when being called from the `fromJSON(...)` method
7592
7648
  */
7593
7649
  const isGroupAddedToDom = referenceGroup.element.parentElement !== null;
7594
- const group = !isGroupAddedToDom
7595
- ? referenceGroup
7596
- : (_a = options === null || options === void 0 ? void 0 : options.overridePopoutGroup) !== null && _a !== void 0 ? _a : this.createGroup({ id: groupId });
7597
- group.model.renderContainer = overlayRenderContainer;
7598
- group.layout(_window.window.innerWidth, _window.window.innerHeight);
7599
- if (!this._groups.has(group.api.id)) {
7650
+ let group;
7651
+ if (!isGroupAddedToDom) {
7652
+ group = referenceGroup;
7653
+ }
7654
+ else if (options === null || options === void 0 ? void 0 : options.overridePopoutGroup) {
7655
+ group = options.overridePopoutGroup;
7656
+ }
7657
+ else {
7658
+ group = this.createGroup({ id: groupId });
7600
7659
  this._onDidAddGroup.fire(group);
7601
7660
  }
7661
+ group.model.renderContainer = overlayRenderContainer;
7662
+ group.layout(_window.window.innerWidth, _window.window.innerHeight);
7602
7663
  if (!(options === null || options === void 0 ? void 0 : options.overridePopoutGroup) && isGroupAddedToDom) {
7603
7664
  if (itemToPopout instanceof DockviewPanel) {
7604
7665
  this.movingLock(() => {
@@ -7629,6 +7690,7 @@
7629
7690
  group.model.location = {
7630
7691
  type: 'popout',
7631
7692
  getWindow: () => _window.window,
7693
+ popoutUrl: options === null || options === void 0 ? void 0 : options.popoutUrl,
7632
7694
  };
7633
7695
  if (isGroupAddedToDom &&
7634
7696
  itemToPopout.api.location.type === 'grid') {
@@ -7645,16 +7707,15 @@
7645
7707
  (_a = _window.window) === null || _a === void 0 ? void 0 : _a.focus();
7646
7708
  }));
7647
7709
  let returnedGroup;
7710
+ const isValidReferenceGroup = isGroupAddedToDom &&
7711
+ referenceGroup &&
7712
+ this.getPanel(referenceGroup.id);
7648
7713
  const value = {
7649
7714
  window: _window,
7650
7715
  popoutGroup: group,
7651
- referenceGroup: !isGroupAddedToDom
7652
- ? undefined
7653
- : referenceGroup
7654
- ? this.getPanel(referenceGroup.id)
7655
- ? referenceGroup.id
7656
- : undefined
7657
- : undefined,
7716
+ referenceGroup: isValidReferenceGroup
7717
+ ? referenceGroup.id
7718
+ : undefined,
7658
7719
  disposable: {
7659
7720
  dispose: () => {
7660
7721
  popoutWindowDisposable.dispose();
@@ -8003,6 +8064,9 @@
8003
8064
  data: group.popoutGroup.toJSON(),
8004
8065
  gridReferenceGroup: group.referenceGroup,
8005
8066
  position: group.window.dimensions(),
8067
+ url: group.popoutGroup.api.location.type === 'popout'
8068
+ ? group.popoutGroup.api.location.popoutUrl
8069
+ : undefined,
8006
8070
  };
8007
8071
  });
8008
8072
  const result = {
@@ -8089,7 +8153,7 @@
8089
8153
  }
8090
8154
  const serializedPopoutGroups = (_b = data.popoutGroups) !== null && _b !== void 0 ? _b : [];
8091
8155
  for (const serializedPopoutGroup of serializedPopoutGroups) {
8092
- const { data, position, gridReferenceGroup } = serializedPopoutGroup;
8156
+ const { data, position, gridReferenceGroup, url } = serializedPopoutGroup;
8093
8157
  const group = createGroupFromSerializedState(data);
8094
8158
  this.addPopoutGroup((_c = (gridReferenceGroup
8095
8159
  ? this.getPanel(gridReferenceGroup)
@@ -8098,6 +8162,7 @@
8098
8162
  overridePopoutGroup: gridReferenceGroup
8099
8163
  ? group
8100
8164
  : undefined,
8165
+ popoutUrl: url,
8101
8166
  });
8102
8167
  }
8103
8168
  for (const floatingGroup of this._floatingGroups) {
@@ -8307,7 +8372,6 @@
8307
8372
  }
8308
8373
  removePanel(panel, options = {
8309
8374
  removeEmptyGroup: true,
8310
- skipDispose: false,
8311
8375
  }) {
8312
8376
  const group = panel.group;
8313
8377
  if (!group) {
@@ -8451,7 +8515,7 @@
8451
8515
  const refGroup = selectedGroup.referenceGroup
8452
8516
  ? this.getPanel(selectedGroup.referenceGroup)
8453
8517
  : undefined;
8454
- if (refGroup) {
8518
+ if (refGroup && refGroup.panels.length === 0) {
8455
8519
  this.removeGroup(refGroup);
8456
8520
  }
8457
8521
  }