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.
@@ -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
  */
@@ -914,7 +914,7 @@
914
914
  //add sash
915
915
  const sash = document.createElement('div');
916
916
  sash.className = 'sash';
917
- const onStart = (event) => {
917
+ const onPointerStart = (event) => {
918
918
  for (const item of this.viewItems) {
919
919
  item.enabled = false;
920
920
  }
@@ -973,11 +973,10 @@
973
973
  size: snappedViewItem.size,
974
974
  };
975
975
  }
976
- //
977
- const mousemove = (mousemoveEvent) => {
976
+ const onPointerMove = (event) => {
978
977
  const current = this._orientation === exports.Orientation.HORIZONTAL
979
- ? mousemoveEvent.clientX
980
- : mousemoveEvent.clientY;
978
+ ? event.clientX
979
+ : event.clientY;
981
980
  const delta = current - start;
982
981
  this.resize(sashIndex, delta, sizes, undefined, undefined, minDelta, maxDelta, snapBefore, snapAfter);
983
982
  this.distributeEmptySpace();
@@ -991,18 +990,20 @@
991
990
  iframe.style.pointerEvents = 'auto';
992
991
  }
993
992
  this.saveProportions();
994
- document.removeEventListener('mousemove', mousemove);
995
- document.removeEventListener('mouseup', end);
993
+ document.removeEventListener('pointermove', onPointerMove);
994
+ document.removeEventListener('pointerup', end);
995
+ document.removeEventListener('pointercancel', end);
996
996
  this._onDidSashEnd.fire(undefined);
997
997
  };
998
- document.addEventListener('mousemove', mousemove);
999
- document.addEventListener('mouseup', end);
998
+ document.addEventListener('pointermove', onPointerMove);
999
+ document.addEventListener('pointerup', end);
1000
+ document.addEventListener('pointercancel', end);
1000
1001
  };
1001
- sash.addEventListener('mousedown', onStart);
1002
+ sash.addEventListener('pointerdown', onPointerStart);
1002
1003
  const sashItem = {
1003
1004
  container: sash,
1004
1005
  disposable: () => {
1005
- sash.removeEventListener('mousedown', onStart);
1006
+ sash.removeEventListener('pointerdown', onPointerStart);
1006
1007
  this.sashContainer.removeChild(sash);
1007
1008
  },
1008
1009
  };
@@ -2095,52 +2096,70 @@
2095
2096
  if (!(parent instanceof BranchNode)) {
2096
2097
  throw new Error('Invalid location');
2097
2098
  }
2098
- const node = parent.children[index];
2099
- if (!(node instanceof LeafNode)) {
2099
+ const nodeToRemove = parent.children[index];
2100
+ if (!(nodeToRemove instanceof LeafNode)) {
2100
2101
  throw new Error('Invalid location');
2101
2102
  }
2102
2103
  parent.removeChild(index, sizing);
2103
- if (parent.children.length === 0) {
2104
- return node.view;
2105
- }
2106
- if (parent.children.length > 1) {
2107
- return node.view;
2108
- }
2104
+ nodeToRemove.dispose();
2105
+ if (parent.children.length !== 1) {
2106
+ return nodeToRemove.view;
2107
+ }
2108
+ // if the parent has only one child and we know the parent is a BranchNode we can make the tree
2109
+ // more efficiently spaced by replacing the parent BranchNode with the child.
2110
+ // if that child is a LeafNode then we simply replace the BranchNode with the child otherwise if the child
2111
+ // is a BranchNode too we should spread it's children into the grandparent.
2112
+ // refer to the remaining child as the sibling
2109
2113
  const sibling = parent.children[0];
2110
2114
  if (pathToParent.length === 0) {
2111
- // parent is root
2115
+ // if the parent is root
2112
2116
  if (sibling instanceof LeafNode) {
2113
- return node.view;
2117
+ // if the sibling is a leaf node no action is required
2118
+ return nodeToRemove.view;
2114
2119
  }
2115
- // we must promote sibling to be the new root
2120
+ // otherwise the sibling is a branch node. since the parent is the root and the root has only one child
2121
+ // which is a branch node we can just set this branch node to be the new root node
2122
+ // for good housekeeping we'll removing the sibling from it's existing tree
2116
2123
  parent.removeChild(0, sizing);
2124
+ // and set that sibling node to be root
2117
2125
  this.root = sibling;
2118
- return node.view;
2126
+ return nodeToRemove.view;
2119
2127
  }
2128
+ // otherwise the parent is apart of a large sub-tree
2120
2129
  const [grandParent, ..._] = [...pathToParent].reverse();
2121
2130
  const [parentIndex, ...__] = [...rest].reverse();
2122
2131
  const isSiblingVisible = parent.isChildVisible(0);
2132
+ // either way we need to remove the sibling from it's existing tree
2123
2133
  parent.removeChild(0, sizing);
2134
+ // note the sizes of all of the grandparents children
2124
2135
  const sizes = grandParent.children.map((_size, i) => grandParent.getChildSize(i));
2125
- grandParent.removeChild(parentIndex, sizing);
2136
+ // remove the parent from the grandparent since we are moving the sibling to take the parents place
2137
+ // this parent is no longer used and can be disposed of
2138
+ grandParent.removeChild(parentIndex, sizing).dispose();
2126
2139
  if (sibling instanceof BranchNode) {
2140
+ // replace the parent with the siblings children
2127
2141
  sizes.splice(parentIndex, 1, ...sibling.children.map((c) => c.size));
2142
+ // and add those siblings to the grandparent
2128
2143
  for (let i = 0; i < sibling.children.length; i++) {
2129
2144
  const child = sibling.children[i];
2130
2145
  grandParent.addChild(child, child.size, parentIndex + i);
2131
2146
  }
2132
2147
  }
2133
2148
  else {
2149
+ // otherwise create a new leaf node and add that to the grandparent
2134
2150
  const newSibling = new LeafNode(sibling.view, orthogonal(sibling.orientation), sibling.size);
2135
2151
  const siblingSizing = isSiblingVisible
2136
2152
  ? sibling.orthogonalSize
2137
2153
  : exports.Sizing.Invisible(sibling.orthogonalSize);
2138
2154
  grandParent.addChild(newSibling, siblingSizing, parentIndex);
2139
2155
  }
2156
+ // the containing node of the sibling is no longer required and can be disposed of
2157
+ sibling.dispose();
2158
+ // resize everything
2140
2159
  for (let i = 0; i < sizes.length; i++) {
2141
2160
  grandParent.resizeChild(i, sizes[i]);
2142
2161
  }
2143
- return node.view;
2162
+ return nodeToRemove.view;
2144
2163
  }
2145
2164
  layout(width, height) {
2146
2165
  const [size, orthogonalSize] = this.root.orientation === exports.Orientation.HORIZONTAL
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dockview",
3
- "version": "1.7.5",
3
+ "version": "1.7.6",
4
4
  "description": "Zero dependency layout manager supporting tabs, grids and splitviews with ReactJS support",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "types": "./dist/cjs/index.d.ts",
@@ -56,7 +56,7 @@
56
56
  "author": "https://github.com/mathuo",
57
57
  "license": "MIT",
58
58
  "dependencies": {
59
- "dockview-core": "^1.7.5"
59
+ "dockview-core": "^1.7.6"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@rollup/plugin-node-resolve": "^15.0.1",
@@ -73,5 +73,5 @@
73
73
  "rollup": "^3.15.0",
74
74
  "rollup-plugin-postcss": "^4.0.2"
75
75
  },
76
- "gitHead": "54bc30c1aa7bd523a5fea025cf438ef221cc3a9b"
76
+ "gitHead": "5d1b6c336f066cfc43eb07ad6d27e1e30d1fe16f"
77
77
  }