dockview-react 3.0.2 → 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.2
3
+ * @version 3.1.0
4
4
  * @link https://github.com/mathuo/dockview
5
5
  * @license MIT
6
6
  */
@@ -5061,6 +5061,9 @@
5061
5061
  delete(id) {
5062
5062
  const index = this.tabs.findIndex((tab) => tab.value.panel.id === id);
5063
5063
  const tabToRemove = this.tabs.splice(index, 1)[0];
5064
+ if (!tabToRemove) {
5065
+ throw new Error(`dockview: Tab not found`);
5066
+ }
5064
5067
  const { value, disposable } = tabToRemove;
5065
5068
  disposable.dispose();
5066
5069
  value.dispose();
@@ -5082,6 +5085,9 @@
5082
5085
  const disposable = new CompositeDisposable(tab.onDragStart((event) => {
5083
5086
  this._onTabDragStart.fire({ nativeEvent: event, panel });
5084
5087
  }), tab.onChanged((event) => {
5088
+ if (event.defaultPrevented) {
5089
+ return;
5090
+ }
5085
5091
  const isFloatingGroupsEnabled = !this.accessor.options.disableFloatingGroups;
5086
5092
  const isFloatingWithOnePanel = this.group.api.location.type === 'floating' &&
5087
5093
  this.size === 1;
@@ -5099,12 +5105,15 @@
5099
5105
  });
5100
5106
  return;
5101
5107
  }
5102
- const isLeftClick = event.button === 0;
5103
- if (!isLeftClick || event.defaultPrevented) {
5104
- return;
5105
- }
5106
- if (this.group.activePanel !== panel) {
5107
- 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;
5108
5117
  }
5109
5118
  }), tab.onDrop((event) => {
5110
5119
  this._onDrop.fire({
@@ -6054,12 +6063,11 @@
6054
6063
  constructor(id, accessor) {
6055
6064
  super(id, '__dockviewgroup__');
6056
6065
  this.accessor = accessor;
6057
- this._mutableDisposable = new MutableDisposable();
6058
6066
  this._onDidLocationChange = new Emitter();
6059
6067
  this.onDidLocationChange = this._onDidLocationChange.event;
6060
6068
  this._onDidActivePanelChange = new Emitter();
6061
6069
  this.onDidActivePanelChange = this._onDidActivePanelChange.event;
6062
- this.addDisposables(this._onDidLocationChange, this._onDidActivePanelChange, this._mutableDisposable);
6070
+ this.addDisposables(this._onDidLocationChange, this._onDidActivePanelChange);
6063
6071
  }
6064
6072
  close() {
6065
6073
  if (!this._group) {
@@ -6117,20 +6125,7 @@
6117
6125
  }
6118
6126
  }
6119
6127
  initialize(group) {
6120
- /**
6121
- * TODO: Annoying initialization order caveat, find a better way to initialize and avoid needing null checks
6122
- *
6123
- * Due to the order on initialization we know that the model isn't defined until later in the same stack-frame of setup.
6124
- * By queuing a microtask we can ensure the setup is completed within the same stack-frame, but after everything else has
6125
- * finished ensuring the `model` is defined.
6126
- */
6127
6128
  this._group = group;
6128
- queueMicrotask(() => {
6129
- this._mutableDisposable.value =
6130
- this._group.model.onDidActivePanelChange((event) => {
6131
- this._onDidActivePanelChange.fire(event);
6132
- });
6133
- });
6134
6129
  }
6135
6130
  }
6136
6131
 
@@ -6200,6 +6195,9 @@
6200
6195
  }, new DockviewGroupPanelApiImpl(id, accessor));
6201
6196
  this.api.initialize(this); // cannot use 'this' after after 'super' call
6202
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
+ }));
6203
6201
  }
6204
6202
  focus() {
6205
6203
  if (!this.api.isActive) {
@@ -6547,9 +6545,6 @@
6547
6545
  this.action.appendChild(createCloseButton());
6548
6546
  this._element.appendChild(this._content);
6549
6547
  this._element.appendChild(this.action);
6550
- this.addDisposables(addDisposableListener(this.action, 'pointerdown', (ev) => {
6551
- ev.preventDefault();
6552
- }));
6553
6548
  this.render();
6554
6549
  }
6555
6550
  init(params) {
@@ -7831,6 +7826,9 @@
7831
7826
  addDisposableWindowListener(_window.window, 'resize', () => {
7832
7827
  group.layout(_window.window.innerWidth, _window.window.innerHeight);
7833
7828
  }), overlayRenderContainer, exports.DockviewDisposable.from(() => {
7829
+ if (this.isDisposed) {
7830
+ return; // cleanup may run after instance is disposed
7831
+ }
7834
7832
  if (isGroupAddedToDom &&
7835
7833
  this.getPanel(referenceGroup.id)) {
7836
7834
  this.movingLock(() => moveGroupWithoutDestroying({
@@ -10544,16 +10542,7 @@
10544
10542
  const onPointerDown = React.useCallback((e) => {
10545
10543
  e.preventDefault();
10546
10544
  }, []);
10547
- const onClick = React.useCallback((event) => {
10548
- if (event.defaultPrevented) {
10549
- return;
10550
- }
10551
- api.setActive();
10552
- if (rest.onClick) {
10553
- rest.onClick(event);
10554
- }
10555
- }, [api, rest.onClick]);
10556
- 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" }),
10557
10546
  React.createElement("span", { className: "dv-default-tab-content" }, title),
10558
10547
  !hideClose && (React.createElement("div", { className: "dv-default-tab-action", onPointerDown: onPointerDown, onClick: onClose },
10559
10548
  React.createElement(CloseButton, null)))));