dockview-react 3.0.1 → 3.1.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.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * dockview-react
3
- * @version 3.0.1
3
+ * @version 3.1.0
4
4
  * @link https://github.com/mathuo/dockview
5
5
  * @license MIT
6
6
  */
@@ -854,7 +854,7 @@
854
854
  this._margin = value;
855
855
  }
856
856
  constructor(container, options) {
857
- var _a;
857
+ var _a, _b;
858
858
  this.container = container;
859
859
  this.viewItems = [];
860
860
  this.sashes = [];
@@ -952,9 +952,9 @@
952
952
  //
953
953
  return delta;
954
954
  };
955
- this._orientation = options.orientation;
955
+ this._orientation = (_a = options.orientation) !== null && _a !== void 0 ? _a : exports.Orientation.VERTICAL;
956
956
  this.element = this.createContainer();
957
- this.margin = (_a = options.margin) !== null && _a !== void 0 ? _a : 0;
957
+ this.margin = (_b = options.margin) !== null && _b !== void 0 ? _b : 0;
958
958
  this.proportionalLayout =
959
959
  options.proportionalLayout === undefined
960
960
  ? true
@@ -2773,9 +2773,9 @@
2773
2773
  set locked(value) {
2774
2774
  this.gridview.locked = value;
2775
2775
  }
2776
- constructor(parentElement, options) {
2776
+ constructor(container, options) {
2777
2777
  var _a;
2778
- super(parentElement, options.disableAutoResizing);
2778
+ super(document.createElement('div'), options.disableAutoResizing);
2779
2779
  this._id = nextLayoutId$1.next();
2780
2780
  this._groups = new Map();
2781
2781
  this._onDidRemove = new Emitter();
@@ -2794,6 +2794,8 @@
2794
2794
  this.element.style.width = '100%';
2795
2795
  this._classNames = new Classnames(this.element);
2796
2796
  this._classNames.setClassNames((_a = options.className) !== null && _a !== void 0 ? _a : '');
2797
+ // the container is owned by the third-party, do not modify/delete it
2798
+ container.appendChild(this.element);
2797
2799
  this.gridview = new Gridview(!!options.proportionalLayout, options.styles, options.orientation, options.locked, options.margin);
2798
2800
  this.gridview.locked = !!options.locked;
2799
2801
  this.element.appendChild(this.gridview.element);
@@ -5059,6 +5061,9 @@
5059
5061
  delete(id) {
5060
5062
  const index = this.tabs.findIndex((tab) => tab.value.panel.id === id);
5061
5063
  const tabToRemove = this.tabs.splice(index, 1)[0];
5064
+ if (!tabToRemove) {
5065
+ throw new Error(`dockview: Tab not found`);
5066
+ }
5062
5067
  const { value, disposable } = tabToRemove;
5063
5068
  disposable.dispose();
5064
5069
  value.dispose();
@@ -5080,6 +5085,9 @@
5080
5085
  const disposable = new CompositeDisposable(tab.onDragStart((event) => {
5081
5086
  this._onTabDragStart.fire({ nativeEvent: event, panel });
5082
5087
  }), tab.onChanged((event) => {
5088
+ if (event.defaultPrevented) {
5089
+ return;
5090
+ }
5083
5091
  const isFloatingGroupsEnabled = !this.accessor.options.disableFloatingGroups;
5084
5092
  const isFloatingWithOnePanel = this.group.api.location.type === 'floating' &&
5085
5093
  this.size === 1;
@@ -5097,12 +5105,15 @@
5097
5105
  });
5098
5106
  return;
5099
5107
  }
5100
- const isLeftClick = event.button === 0;
5101
- if (!isLeftClick || event.defaultPrevented) {
5102
- return;
5103
- }
5104
- if (this.group.activePanel !== panel) {
5105
- this.group.model.openPanel(panel);
5108
+ switch (event.button) {
5109
+ case 0: // left click or touch
5110
+ if (this.group.activePanel !== panel) {
5111
+ this.group.model.openPanel(panel);
5112
+ }
5113
+ break;
5114
+ case 1: // middle click
5115
+ panel.api.close();
5116
+ break;
5106
5117
  }
5107
5118
  }), tab.onDrop((event) => {
5108
5119
  this._onDrop.fire({
@@ -6052,12 +6063,11 @@
6052
6063
  constructor(id, accessor) {
6053
6064
  super(id, '__dockviewgroup__');
6054
6065
  this.accessor = accessor;
6055
- this._mutableDisposable = new MutableDisposable();
6056
6066
  this._onDidLocationChange = new Emitter();
6057
6067
  this.onDidLocationChange = this._onDidLocationChange.event;
6058
6068
  this._onDidActivePanelChange = new Emitter();
6059
6069
  this.onDidActivePanelChange = this._onDidActivePanelChange.event;
6060
- this.addDisposables(this._onDidLocationChange, this._onDidActivePanelChange, this._mutableDisposable);
6070
+ this.addDisposables(this._onDidLocationChange, this._onDidActivePanelChange);
6061
6071
  }
6062
6072
  close() {
6063
6073
  if (!this._group) {
@@ -6115,20 +6125,7 @@
6115
6125
  }
6116
6126
  }
6117
6127
  initialize(group) {
6118
- /**
6119
- * TODO: Annoying initialization order caveat, find a better way to initialize and avoid needing null checks
6120
- *
6121
- * Due to the order on initialization we know that the model isn't defined until later in the same stack-frame of setup.
6122
- * By queuing a microtask we can ensure the setup is completed within the same stack-frame, but after everything else has
6123
- * finished ensuring the `model` is defined.
6124
- */
6125
6128
  this._group = group;
6126
- queueMicrotask(() => {
6127
- this._mutableDisposable.value =
6128
- this._group.model.onDidActivePanelChange((event) => {
6129
- this._onDidActivePanelChange.fire(event);
6130
- });
6131
- });
6132
6129
  }
6133
6130
  }
6134
6131
 
@@ -6198,6 +6195,9 @@
6198
6195
  }, new DockviewGroupPanelApiImpl(id, accessor));
6199
6196
  this.api.initialize(this); // cannot use 'this' after after 'super' call
6200
6197
  this._model = new DockviewGroupPanelModel(this.element, accessor, id, options, this);
6198
+ this.addDisposables(this.model.onDidActivePanelChange((event) => {
6199
+ this.api._onDidActivePanelChange.fire(event);
6200
+ }));
6201
6201
  }
6202
6202
  focus() {
6203
6203
  if (!this.api.isActive) {
@@ -6545,9 +6545,6 @@
6545
6545
  this.action.appendChild(createCloseButton());
6546
6546
  this._element.appendChild(this._content);
6547
6547
  this._element.appendChild(this.action);
6548
- this.addDisposables(addDisposableListener(this.action, 'pointerdown', (ev) => {
6549
- ev.preventDefault();
6550
- }));
6551
6548
  this.render();
6552
6549
  }
6553
6550
  init(params) {
@@ -7490,9 +7487,9 @@
7490
7487
  get floatingGroups() {
7491
7488
  return this._floatingGroups;
7492
7489
  }
7493
- constructor(parentElement, options) {
7490
+ constructor(container, options) {
7494
7491
  var _a;
7495
- super(parentElement, {
7492
+ super(container, {
7496
7493
  proportionalLayout: true,
7497
7494
  orientation: exports.Orientation.HORIZONTAL,
7498
7495
  styles: options.hideBorders
@@ -7829,6 +7826,9 @@
7829
7826
  addDisposableWindowListener(_window.window, 'resize', () => {
7830
7827
  group.layout(_window.window.innerWidth, _window.window.innerHeight);
7831
7828
  }), overlayRenderContainer, exports.DockviewDisposable.from(() => {
7829
+ if (this.isDisposed) {
7830
+ return; // cleanup may run after instance is disposed
7831
+ }
7832
7832
  if (isGroupAddedToDom &&
7833
7833
  this.getPanel(referenceGroup.id)) {
7834
7834
  this.movingLock(() => moveGroupWithoutDestroying({
@@ -7848,6 +7848,16 @@
7848
7848
  group.model.renderContainer =
7849
7849
  this.overlayRenderContainer;
7850
7850
  returnedGroup = group;
7851
+ const alreadyRemoved = !this._popoutGroups.find((p) => p.popoutGroup === group);
7852
+ if (alreadyRemoved) {
7853
+ /**
7854
+ * If this popout group was explicitly removed then we shouldn't run the additional
7855
+ * steps. To tell if the running of this disposable is the result of this popout group
7856
+ * being explicitly removed we can check if this popout group is still referenced in
7857
+ * the `this._popoutGroups` list.
7858
+ */
7859
+ return;
7860
+ }
7851
7861
  if (floatingBox) {
7852
7862
  this.addFloatingGroup(group, {
7853
7863
  height: floatingBox.height,
@@ -9024,9 +9034,9 @@
9024
9034
  set deserializer(value) {
9025
9035
  this._deserializer = value;
9026
9036
  }
9027
- constructor(parentElement, options) {
9037
+ constructor(container, options) {
9028
9038
  var _a;
9029
- super(parentElement, {
9039
+ super(container, {
9030
9040
  proportionalLayout: (_a = options.proportionalLayout) !== null && _a !== void 0 ? _a : true,
9031
9041
  orientation: options.orientation,
9032
9042
  styles: options.hideBorders
@@ -9315,9 +9325,9 @@
9315
9325
  ? this.splitview.size
9316
9326
  : this.splitview.orthogonalSize;
9317
9327
  }
9318
- constructor(parentElement, options) {
9328
+ constructor(container, options) {
9319
9329
  var _a;
9320
- super(parentElement, options.disableAutoResizing);
9330
+ super(document.createElement('div'), options.disableAutoResizing);
9321
9331
  this._splitviewChangeDisposable = new MutableDisposable();
9322
9332
  this._panels = new Map();
9323
9333
  this._onDidLayoutfromJSON = new Emitter();
@@ -9328,8 +9338,12 @@
9328
9338
  this.onDidRemoveView = this._onDidRemoveView.event;
9329
9339
  this._onDidLayoutChange = new Emitter();
9330
9340
  this.onDidLayoutChange = this._onDidLayoutChange.event;
9341
+ this.element.style.height = '100%';
9342
+ this.element.style.width = '100%';
9331
9343
  this._classNames = new Classnames(this.element);
9332
9344
  this._classNames.setClassNames((_a = options.className) !== null && _a !== void 0 ? _a : '');
9345
+ // the container is owned by the third-party, do not modify/delete it
9346
+ container.appendChild(this.element);
9333
9347
  this._options = options;
9334
9348
  this.splitview = new Splitview(this.element, options);
9335
9349
  this.addDisposables(this._onDidAddView, this._onDidLayoutfromJSON, this._onDidRemoveView, this._onDidLayoutChange);
@@ -9639,9 +9653,9 @@
9639
9653
  get options() {
9640
9654
  return this._options;
9641
9655
  }
9642
- constructor(parentElement, options) {
9656
+ constructor(container, options) {
9643
9657
  var _a;
9644
- super(parentElement, options.disableAutoResizing);
9658
+ super(document.createElement('div'), options.disableAutoResizing);
9645
9659
  this._id = nextLayoutId.next();
9646
9660
  this._disposable = new MutableDisposable();
9647
9661
  this._viewDisposables = new Map();
@@ -9657,9 +9671,13 @@
9657
9671
  this.onDidRemoveView = this._onDidRemoveView.event;
9658
9672
  this._onUnhandledDragOverEvent = new Emitter();
9659
9673
  this.onUnhandledDragOverEvent = this._onUnhandledDragOverEvent.event;
9674
+ this.element.style.height = '100%';
9675
+ this.element.style.width = '100%';
9660
9676
  this.addDisposables(this._onDidLayoutChange, this._onDidLayoutfromJSON, this._onDidDrop, this._onDidAddView, this._onDidRemoveView, this._onUnhandledDragOverEvent);
9661
9677
  this._classNames = new Classnames(this.element);
9662
9678
  this._classNames.setClassNames((_a = options.className) !== null && _a !== void 0 ? _a : '');
9679
+ // the container is owned by the third-party, do not modify/delete it
9680
+ container.appendChild(this.element);
9663
9681
  this._options = options;
9664
9682
  this.paneview = new Paneview(this.element, {
9665
9683
  // only allow paneview in the vertical orientation for now
@@ -10479,7 +10497,7 @@
10479
10497
  createPrefixHeaderActionComponent: createGroupControlElement(props.prefixHeaderActionsComponent, { addPortal }),
10480
10498
  });
10481
10499
  }, [props.prefixHeaderActionsComponent]);
10482
- return (React.createElement("div", { className: props.className, style: { height: '100%', width: '100%' }, ref: domRef }, portals));
10500
+ return (React.createElement("div", { style: { height: '100%', width: '100%' }, ref: domRef }, portals));
10483
10501
  });
10484
10502
  DockviewReact.displayName = 'DockviewComponent';
10485
10503
 
@@ -10524,16 +10542,7 @@
10524
10542
  const onPointerDown = React.useCallback((e) => {
10525
10543
  e.preventDefault();
10526
10544
  }, []);
10527
- const onClick = React.useCallback((event) => {
10528
- if (event.defaultPrevented) {
10529
- return;
10530
- }
10531
- api.setActive();
10532
- if (rest.onClick) {
10533
- rest.onClick(event);
10534
- }
10535
- }, [api, rest.onClick]);
10536
- return (React.createElement("div", Object.assign({ "data-testid": "dockview-dv-default-tab" }, rest, { onClick: onClick, className: "dv-default-tab" }),
10545
+ return (React.createElement("div", Object.assign({ "data-testid": "dockview-dv-default-tab" }, rest, { className: "dv-default-tab" }),
10537
10546
  React.createElement("span", { className: "dv-default-tab-content" }, title),
10538
10547
  !hideClose && (React.createElement("div", { className: "dv-default-tab-action", onPointerDown: onPointerDown, onClick: onClose },
10539
10548
  React.createElement(CloseButton, null)))));
@@ -10616,7 +10625,7 @@
10616
10625
  },
10617
10626
  });
10618
10627
  }, [props.components]);
10619
- return (React.createElement("div", { className: props.className, style: { height: '100%', width: '100%' }, ref: domRef }, portals));
10628
+ return (React.createElement("div", { style: { height: '100%', width: '100%' }, ref: domRef }, portals));
10620
10629
  });
10621
10630
  SplitviewReact.displayName = 'SplitviewComponent';
10622
10631
 
@@ -10699,7 +10708,7 @@
10699
10708
  },
10700
10709
  });
10701
10710
  }, [props.components]);
10702
- return (React.createElement("div", { className: props.className, style: { height: '100%', width: '100%' }, ref: domRef }, portals));
10711
+ return (React.createElement("div", { style: { height: '100%', width: '100%' }, ref: domRef }, portals));
10703
10712
  });
10704
10713
  GridviewReact.displayName = 'GridviewComponent';
10705
10714
 
@@ -10831,7 +10840,7 @@
10831
10840
  disposable.dispose();
10832
10841
  };
10833
10842
  }, [props.onDidDrop]);
10834
- return (React.createElement("div", { className: props.className, style: { height: '100%', width: '100%' }, ref: domRef }, portals));
10843
+ return (React.createElement("div", { style: { height: '100%', width: '100%' }, ref: domRef }, portals));
10835
10844
  });
10836
10845
  PaneviewReact.displayName = 'PaneviewComponent';
10837
10846