dockview 1.7.4 → 1.7.6

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
3
- * @version 1.7.4
3
+ * @version 1.7.6
4
4
  * @link https://github.com/mathuo/dockview
5
5
  * @license MIT
6
6
  */
@@ -247,7 +247,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
247
247
  element.addEventListener(type, listener, options);
248
248
  return {
249
249
  dispose: () => {
250
- element.removeEventListener(type, listener);
250
+ element.removeEventListener(type, listener, options);
251
251
  },
252
252
  };
253
253
  }
@@ -255,7 +255,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
255
255
  element.addEventListener(type, listener, options);
256
256
  return {
257
257
  dispose: () => {
258
- element.removeEventListener(type, listener);
258
+ element.removeEventListener(type, listener, options);
259
259
  },
260
260
  };
261
261
  }
@@ -940,7 +940,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
940
940
  //add sash
941
941
  const sash = document.createElement('div');
942
942
  sash.className = 'sash';
943
- const onStart = (event) => {
943
+ const onPointerStart = (event) => {
944
944
  for (const item of this.viewItems) {
945
945
  item.enabled = false;
946
946
  }
@@ -999,11 +999,10 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
999
999
  size: snappedViewItem.size,
1000
1000
  };
1001
1001
  }
1002
- //
1003
- const mousemove = (mousemoveEvent) => {
1002
+ const onPointerMove = (event) => {
1004
1003
  const current = this._orientation === exports.Orientation.HORIZONTAL
1005
- ? mousemoveEvent.clientX
1006
- : mousemoveEvent.clientY;
1004
+ ? event.clientX
1005
+ : event.clientY;
1007
1006
  const delta = current - start;
1008
1007
  this.resize(sashIndex, delta, sizes, undefined, undefined, minDelta, maxDelta, snapBefore, snapAfter);
1009
1008
  this.distributeEmptySpace();
@@ -1017,20 +1016,20 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
1017
1016
  iframe.style.pointerEvents = 'auto';
1018
1017
  }
1019
1018
  this.saveProportions();
1020
- document.removeEventListener('mousemove', mousemove);
1021
- document.removeEventListener('mouseup', end);
1022
- document.removeEventListener('mouseend', end);
1019
+ document.removeEventListener('pointermove', onPointerMove);
1020
+ document.removeEventListener('pointerup', end);
1021
+ document.removeEventListener('pointercancel', end);
1023
1022
  this._onDidSashEnd.fire(undefined);
1024
1023
  };
1025
- document.addEventListener('mousemove', mousemove);
1026
- document.addEventListener('mouseup', end);
1027
- document.addEventListener('mouseend', end);
1024
+ document.addEventListener('pointermove', onPointerMove);
1025
+ document.addEventListener('pointerup', end);
1026
+ document.addEventListener('pointercancel', end);
1028
1027
  };
1029
- sash.addEventListener('mousedown', onStart);
1028
+ sash.addEventListener('pointerdown', onPointerStart);
1030
1029
  const sashItem = {
1031
1030
  container: sash,
1032
1031
  disposable: () => {
1033
- sash.removeEventListener('mousedown', onStart);
1032
+ sash.removeEventListener('pointerdown', onPointerStart);
1034
1033
  this.sashContainer.removeChild(sash);
1035
1034
  },
1036
1035
  };
@@ -2123,58 +2122,70 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
2123
2122
  if (!(parent instanceof BranchNode)) {
2124
2123
  throw new Error('Invalid location');
2125
2124
  }
2126
- const node = parent.children[index];
2127
- if (!(node instanceof LeafNode)) {
2125
+ const nodeToRemove = parent.children[index];
2126
+ if (!(nodeToRemove instanceof LeafNode)) {
2128
2127
  throw new Error('Invalid location');
2129
2128
  }
2130
- const view = node.view;
2131
- node.dispose(); // dispose of node
2132
- const child = parent.removeChild(index, sizing);
2133
- child.dispose();
2134
- if (parent.children.length === 0) {
2135
- return view;
2136
- }
2137
- if (parent.children.length > 1) {
2138
- return view;
2129
+ parent.removeChild(index, sizing);
2130
+ nodeToRemove.dispose();
2131
+ if (parent.children.length !== 1) {
2132
+ return nodeToRemove.view;
2139
2133
  }
2134
+ // if the parent has only one child and we know the parent is a BranchNode we can make the tree
2135
+ // more efficiently spaced by replacing the parent BranchNode with the child.
2136
+ // if that child is a LeafNode then we simply replace the BranchNode with the child otherwise if the child
2137
+ // is a BranchNode too we should spread it's children into the grandparent.
2138
+ // refer to the remaining child as the sibling
2140
2139
  const sibling = parent.children[0];
2141
2140
  if (pathToParent.length === 0) {
2142
- // parent is root
2141
+ // if the parent is root
2143
2142
  if (sibling instanceof LeafNode) {
2144
- return view;
2145
- }
2146
- // we must promote sibling to be the new root
2147
- const child = parent.removeChild(0, sizing);
2148
- child.dispose();
2143
+ // if the sibling is a leaf node no action is required
2144
+ return nodeToRemove.view;
2145
+ }
2146
+ // otherwise the sibling is a branch node. since the parent is the root and the root has only one child
2147
+ // which is a branch node we can just set this branch node to be the new root node
2148
+ // for good housekeeping we'll removing the sibling from it's existing tree
2149
+ parent.removeChild(0, sizing);
2150
+ // and set that sibling node to be root
2149
2151
  this.root = sibling;
2150
- return view;
2152
+ return nodeToRemove.view;
2151
2153
  }
2154
+ // otherwise the parent is apart of a large sub-tree
2152
2155
  const [grandParent, ..._] = [...pathToParent].reverse();
2153
2156
  const [parentIndex, ...__] = [...rest].reverse();
2154
2157
  const isSiblingVisible = parent.isChildVisible(0);
2155
- const childNode = parent.removeChild(0, sizing);
2156
- childNode.dispose();
2158
+ // either way we need to remove the sibling from it's existing tree
2159
+ parent.removeChild(0, sizing);
2160
+ // note the sizes of all of the grandparents children
2157
2161
  const sizes = grandParent.children.map((_size, i) => grandParent.getChildSize(i));
2158
- const parentNode = grandParent.removeChild(parentIndex, sizing);
2159
- parentNode.dispose();
2162
+ // remove the parent from the grandparent since we are moving the sibling to take the parents place
2163
+ // this parent is no longer used and can be disposed of
2164
+ grandParent.removeChild(parentIndex, sizing).dispose();
2160
2165
  if (sibling instanceof BranchNode) {
2166
+ // replace the parent with the siblings children
2161
2167
  sizes.splice(parentIndex, 1, ...sibling.children.map((c) => c.size));
2168
+ // and add those siblings to the grandparent
2162
2169
  for (let i = 0; i < sibling.children.length; i++) {
2163
2170
  const child = sibling.children[i];
2164
2171
  grandParent.addChild(child, child.size, parentIndex + i);
2165
2172
  }
2166
2173
  }
2167
2174
  else {
2175
+ // otherwise create a new leaf node and add that to the grandparent
2168
2176
  const newSibling = new LeafNode(sibling.view, orthogonal(sibling.orientation), sibling.size);
2169
2177
  const siblingSizing = isSiblingVisible
2170
2178
  ? sibling.orthogonalSize
2171
2179
  : exports.Sizing.Invisible(sibling.orthogonalSize);
2172
2180
  grandParent.addChild(newSibling, siblingSizing, parentIndex);
2173
2181
  }
2182
+ // the containing node of the sibling is no longer required and can be disposed of
2183
+ sibling.dispose();
2184
+ // resize everything
2174
2185
  for (let i = 0; i < sizes.length; i++) {
2175
2186
  grandParent.resizeChild(i, sizes[i]);
2176
2187
  }
2177
- return view;
2188
+ return nodeToRemove.view;
2178
2189
  }
2179
2190
  layout(width, height) {
2180
2191
  const [size, orthogonalSize] = this.root.orientation === exports.Orientation.HORIZONTAL
@@ -2887,25 +2898,32 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
2887
2898
  constructor(el) {
2888
2899
  super();
2889
2900
  this.el = el;
2890
- this.disposable = new MutableDisposable();
2901
+ this.dataDisposable = new MutableDisposable();
2902
+ this.pointerEventsDisposable = new MutableDisposable();
2891
2903
  this._onDragStart = new Emitter();
2892
2904
  this.onDragStart = this._onDragStart.event;
2893
- this.iframes = [];
2894
- this.addDisposables(this._onDragStart);
2905
+ this.addDisposables(this._onDragStart, this.dataDisposable, this.pointerEventsDisposable);
2895
2906
  this.configure();
2896
2907
  }
2897
2908
  configure() {
2898
2909
  this.addDisposables(this._onDragStart, addDisposableListener(this.el, 'dragstart', (event) => {
2899
- this.iframes = [
2910
+ const iframes = [
2900
2911
  ...getElementsByTagName('iframe'),
2901
2912
  ...getElementsByTagName('webview'),
2902
2913
  ];
2903
- for (const iframe of this.iframes) {
2914
+ this.pointerEventsDisposable.value = {
2915
+ dispose: () => {
2916
+ for (const iframe of iframes) {
2917
+ iframe.style.pointerEvents = 'auto';
2918
+ }
2919
+ },
2920
+ };
2921
+ for (const iframe of iframes) {
2904
2922
  iframe.style.pointerEvents = 'none';
2905
2923
  }
2906
2924
  this.el.classList.add('dv-dragged');
2907
2925
  setTimeout(() => this.el.classList.remove('dv-dragged'), 0);
2908
- this.disposable.value = this.getData(event.dataTransfer);
2926
+ this.dataDisposable.value = this.getData(event.dataTransfer);
2909
2927
  if (event.dataTransfer) {
2910
2928
  event.dataTransfer.effectAllowed = 'move';
2911
2929
  /**
@@ -2920,11 +2938,8 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
2920
2938
  event.dataTransfer.setData('text/plain', '__dockview_internal_drag_event__');
2921
2939
  }
2922
2940
  }), addDisposableListener(this.el, 'dragend', () => {
2923
- for (const iframe of this.iframes) {
2924
- iframe.style.pointerEvents = 'auto';
2925
- }
2926
- this.iframes = [];
2927
- this.disposable.dispose();
2941
+ this.pointerEventsDisposable.dispose();
2942
+ this.dataDisposable.dispose();
2928
2943
  }));
2929
2944
  }
2930
2945
  }