dockview 1.7.5 → 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.
package/dist/dockview.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * dockview
3
- * @version 1.7.5
3
+ * @version 1.7.6
4
4
  * @link https://github.com/mathuo/dockview
5
5
  * @license MIT
6
6
  */
@@ -944,7 +944,7 @@
944
944
  //add sash
945
945
  const sash = document.createElement('div');
946
946
  sash.className = 'sash';
947
- const onStart = (event) => {
947
+ const onPointerStart = (event) => {
948
948
  for (const item of this.viewItems) {
949
949
  item.enabled = false;
950
950
  }
@@ -1003,11 +1003,10 @@
1003
1003
  size: snappedViewItem.size,
1004
1004
  };
1005
1005
  }
1006
- //
1007
- const mousemove = (mousemoveEvent) => {
1006
+ const onPointerMove = (event) => {
1008
1007
  const current = this._orientation === exports.Orientation.HORIZONTAL
1009
- ? mousemoveEvent.clientX
1010
- : mousemoveEvent.clientY;
1008
+ ? event.clientX
1009
+ : event.clientY;
1011
1010
  const delta = current - start;
1012
1011
  this.resize(sashIndex, delta, sizes, undefined, undefined, minDelta, maxDelta, snapBefore, snapAfter);
1013
1012
  this.distributeEmptySpace();
@@ -1021,18 +1020,20 @@
1021
1020
  iframe.style.pointerEvents = 'auto';
1022
1021
  }
1023
1022
  this.saveProportions();
1024
- document.removeEventListener('mousemove', mousemove);
1025
- document.removeEventListener('mouseup', end);
1023
+ document.removeEventListener('pointermove', onPointerMove);
1024
+ document.removeEventListener('pointerup', end);
1025
+ document.removeEventListener('pointercancel', end);
1026
1026
  this._onDidSashEnd.fire(undefined);
1027
1027
  };
1028
- document.addEventListener('mousemove', mousemove);
1029
- document.addEventListener('mouseup', end);
1028
+ document.addEventListener('pointermove', onPointerMove);
1029
+ document.addEventListener('pointerup', end);
1030
+ document.addEventListener('pointercancel', end);
1030
1031
  };
1031
- sash.addEventListener('mousedown', onStart);
1032
+ sash.addEventListener('pointerdown', onPointerStart);
1032
1033
  const sashItem = {
1033
1034
  container: sash,
1034
1035
  disposable: () => {
1035
- sash.removeEventListener('mousedown', onStart);
1036
+ sash.removeEventListener('pointerdown', onPointerStart);
1036
1037
  this.sashContainer.removeChild(sash);
1037
1038
  },
1038
1039
  };
@@ -2125,52 +2126,70 @@
2125
2126
  if (!(parent instanceof BranchNode)) {
2126
2127
  throw new Error('Invalid location');
2127
2128
  }
2128
- const node = parent.children[index];
2129
- if (!(node instanceof LeafNode)) {
2129
+ const nodeToRemove = parent.children[index];
2130
+ if (!(nodeToRemove instanceof LeafNode)) {
2130
2131
  throw new Error('Invalid location');
2131
2132
  }
2132
2133
  parent.removeChild(index, sizing);
2133
- if (parent.children.length === 0) {
2134
- return node.view;
2135
- }
2136
- if (parent.children.length > 1) {
2137
- return node.view;
2138
- }
2134
+ nodeToRemove.dispose();
2135
+ if (parent.children.length !== 1) {
2136
+ return nodeToRemove.view;
2137
+ }
2138
+ // if the parent has only one child and we know the parent is a BranchNode we can make the tree
2139
+ // more efficiently spaced by replacing the parent BranchNode with the child.
2140
+ // if that child is a LeafNode then we simply replace the BranchNode with the child otherwise if the child
2141
+ // is a BranchNode too we should spread it's children into the grandparent.
2142
+ // refer to the remaining child as the sibling
2139
2143
  const sibling = parent.children[0];
2140
2144
  if (pathToParent.length === 0) {
2141
- // parent is root
2145
+ // if the parent is root
2142
2146
  if (sibling instanceof LeafNode) {
2143
- return node.view;
2147
+ // if the sibling is a leaf node no action is required
2148
+ return nodeToRemove.view;
2144
2149
  }
2145
- // we must promote sibling to be the new root
2150
+ // otherwise the sibling is a branch node. since the parent is the root and the root has only one child
2151
+ // which is a branch node we can just set this branch node to be the new root node
2152
+ // for good housekeeping we'll removing the sibling from it's existing tree
2146
2153
  parent.removeChild(0, sizing);
2154
+ // and set that sibling node to be root
2147
2155
  this.root = sibling;
2148
- return node.view;
2156
+ return nodeToRemove.view;
2149
2157
  }
2158
+ // otherwise the parent is apart of a large sub-tree
2150
2159
  const [grandParent, ..._] = [...pathToParent].reverse();
2151
2160
  const [parentIndex, ...__] = [...rest].reverse();
2152
2161
  const isSiblingVisible = parent.isChildVisible(0);
2162
+ // either way we need to remove the sibling from it's existing tree
2153
2163
  parent.removeChild(0, sizing);
2164
+ // note the sizes of all of the grandparents children
2154
2165
  const sizes = grandParent.children.map((_size, i) => grandParent.getChildSize(i));
2155
- grandParent.removeChild(parentIndex, sizing);
2166
+ // remove the parent from the grandparent since we are moving the sibling to take the parents place
2167
+ // this parent is no longer used and can be disposed of
2168
+ grandParent.removeChild(parentIndex, sizing).dispose();
2156
2169
  if (sibling instanceof BranchNode) {
2170
+ // replace the parent with the siblings children
2157
2171
  sizes.splice(parentIndex, 1, ...sibling.children.map((c) => c.size));
2172
+ // and add those siblings to the grandparent
2158
2173
  for (let i = 0; i < sibling.children.length; i++) {
2159
2174
  const child = sibling.children[i];
2160
2175
  grandParent.addChild(child, child.size, parentIndex + i);
2161
2176
  }
2162
2177
  }
2163
2178
  else {
2179
+ // otherwise create a new leaf node and add that to the grandparent
2164
2180
  const newSibling = new LeafNode(sibling.view, orthogonal(sibling.orientation), sibling.size);
2165
2181
  const siblingSizing = isSiblingVisible
2166
2182
  ? sibling.orthogonalSize
2167
2183
  : exports.Sizing.Invisible(sibling.orthogonalSize);
2168
2184
  grandParent.addChild(newSibling, siblingSizing, parentIndex);
2169
2185
  }
2186
+ // the containing node of the sibling is no longer required and can be disposed of
2187
+ sibling.dispose();
2188
+ // resize everything
2170
2189
  for (let i = 0; i < sizes.length; i++) {
2171
2190
  grandParent.resizeChild(i, sizes[i]);
2172
2191
  }
2173
- return node.view;
2192
+ return nodeToRemove.view;
2174
2193
  }
2175
2194
  layout(width, height) {
2176
2195
  const [size, orthogonalSize] = this.root.orientation === exports.Orientation.HORIZONTAL