react-resizable-panels 2.0.2 → 2.0.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.3
4
+
5
+ - Fix resize handle onDragging callback (#278)
6
+
3
7
  ## 2.0.2
4
8
 
5
9
  - Fixed an issue where size might not be re-initialized correctly after a panel was hidden by the `unstable_Activity` (previously "Offscreen") API.
@@ -2068,11 +2068,23 @@ function PanelResizeHandle({
2068
2068
  case "down":
2069
2069
  {
2070
2070
  startDragging(resizeHandleId, event);
2071
+ const {
2072
+ onDragging
2073
+ } = callbacksRef.current;
2074
+ if (onDragging) {
2075
+ onDragging(true);
2076
+ }
2071
2077
  break;
2072
2078
  }
2073
2079
  case "up":
2074
2080
  {
2075
2081
  stopDragging();
2082
+ const {
2083
+ onDragging
2084
+ } = callbacksRef.current;
2085
+ if (onDragging) {
2086
+ onDragging(false);
2087
+ }
2076
2088
  break;
2077
2089
  }
2078
2090
  }
@@ -2174,11 +2174,23 @@ function PanelResizeHandle({
2174
2174
  case "down":
2175
2175
  {
2176
2176
  startDragging(resizeHandleId, event);
2177
+ const {
2178
+ onDragging
2179
+ } = callbacksRef.current;
2180
+ if (onDragging) {
2181
+ onDragging(true);
2182
+ }
2177
2183
  break;
2178
2184
  }
2179
2185
  case "up":
2180
2186
  {
2181
2187
  stopDragging();
2188
+ const {
2189
+ onDragging
2190
+ } = callbacksRef.current;
2191
+ if (onDragging) {
2192
+ onDragging(false);
2193
+ }
2182
2194
  break;
2183
2195
  }
2184
2196
  }
@@ -2150,11 +2150,23 @@ function PanelResizeHandle({
2150
2150
  case "down":
2151
2151
  {
2152
2152
  startDragging(resizeHandleId, event);
2153
+ const {
2154
+ onDragging
2155
+ } = callbacksRef.current;
2156
+ if (onDragging) {
2157
+ onDragging(true);
2158
+ }
2153
2159
  break;
2154
2160
  }
2155
2161
  case "up":
2156
2162
  {
2157
2163
  stopDragging();
2164
+ const {
2165
+ onDragging
2166
+ } = callbacksRef.current;
2167
+ if (onDragging) {
2168
+ onDragging(false);
2169
+ }
2158
2170
  break;
2159
2171
  }
2160
2172
  }
@@ -2044,11 +2044,23 @@ function PanelResizeHandle({
2044
2044
  case "down":
2045
2045
  {
2046
2046
  startDragging(resizeHandleId, event);
2047
+ const {
2048
+ onDragging
2049
+ } = callbacksRef.current;
2050
+ if (onDragging) {
2051
+ onDragging(true);
2052
+ }
2047
2053
  break;
2048
2054
  }
2049
2055
  case "up":
2050
2056
  {
2051
2057
  stopDragging();
2058
+ const {
2059
+ onDragging
2060
+ } = callbacksRef.current;
2061
+ if (onDragging) {
2062
+ onDragging(false);
2063
+ }
2052
2064
  break;
2053
2065
  }
2054
2066
  }
@@ -2070,11 +2070,23 @@ function PanelResizeHandle({
2070
2070
  case "down":
2071
2071
  {
2072
2072
  startDragging(resizeHandleId, event);
2073
+ const {
2074
+ onDragging
2075
+ } = callbacksRef.current;
2076
+ if (onDragging) {
2077
+ onDragging(true);
2078
+ }
2073
2079
  break;
2074
2080
  }
2075
2081
  case "up":
2076
2082
  {
2077
2083
  stopDragging();
2084
+ const {
2085
+ onDragging
2086
+ } = callbacksRef.current;
2087
+ if (onDragging) {
2088
+ onDragging(false);
2089
+ }
2078
2090
  break;
2079
2091
  }
2080
2092
  }
@@ -2181,11 +2181,23 @@ function PanelResizeHandle({
2181
2181
  case "down":
2182
2182
  {
2183
2183
  startDragging(resizeHandleId, event);
2184
+ const {
2185
+ onDragging
2186
+ } = callbacksRef.current;
2187
+ if (onDragging) {
2188
+ onDragging(true);
2189
+ }
2184
2190
  break;
2185
2191
  }
2186
2192
  case "up":
2187
2193
  {
2188
2194
  stopDragging();
2195
+ const {
2196
+ onDragging
2197
+ } = callbacksRef.current;
2198
+ if (onDragging) {
2199
+ onDragging(false);
2200
+ }
2189
2201
  break;
2190
2202
  }
2191
2203
  }
@@ -2157,11 +2157,23 @@ function PanelResizeHandle({
2157
2157
  case "down":
2158
2158
  {
2159
2159
  startDragging(resizeHandleId, event);
2160
+ const {
2161
+ onDragging
2162
+ } = callbacksRef.current;
2163
+ if (onDragging) {
2164
+ onDragging(true);
2165
+ }
2160
2166
  break;
2161
2167
  }
2162
2168
  case "up":
2163
2169
  {
2164
2170
  stopDragging();
2171
+ const {
2172
+ onDragging
2173
+ } = callbacksRef.current;
2174
+ if (onDragging) {
2175
+ onDragging(false);
2176
+ }
2165
2177
  break;
2166
2178
  }
2167
2179
  }
@@ -1950,11 +1950,23 @@ function PanelResizeHandle({
1950
1950
  case "down":
1951
1951
  {
1952
1952
  startDragging(resizeHandleId, event);
1953
+ const {
1954
+ onDragging
1955
+ } = callbacksRef.current;
1956
+ if (onDragging) {
1957
+ onDragging(true);
1958
+ }
1953
1959
  break;
1954
1960
  }
1955
1961
  case "up":
1956
1962
  {
1957
1963
  stopDragging();
1964
+ const {
1965
+ onDragging
1966
+ } = callbacksRef.current;
1967
+ if (onDragging) {
1968
+ onDragging(false);
1969
+ }
1958
1970
  break;
1959
1971
  }
1960
1972
  }
@@ -1926,11 +1926,23 @@ function PanelResizeHandle({
1926
1926
  case "down":
1927
1927
  {
1928
1928
  startDragging(resizeHandleId, event);
1929
+ const {
1930
+ onDragging
1931
+ } = callbacksRef.current;
1932
+ if (onDragging) {
1933
+ onDragging(true);
1934
+ }
1929
1935
  break;
1930
1936
  }
1931
1937
  case "up":
1932
1938
  {
1933
1939
  stopDragging();
1940
+ const {
1941
+ onDragging
1942
+ } = callbacksRef.current;
1943
+ if (onDragging) {
1944
+ onDragging(false);
1945
+ }
1934
1946
  break;
1935
1947
  }
1936
1948
  }
@@ -2046,11 +2046,23 @@ function PanelResizeHandle({
2046
2046
  case "down":
2047
2047
  {
2048
2048
  startDragging(resizeHandleId, event);
2049
+ const {
2050
+ onDragging
2051
+ } = callbacksRef.current;
2052
+ if (onDragging) {
2053
+ onDragging(true);
2054
+ }
2049
2055
  break;
2050
2056
  }
2051
2057
  case "up":
2052
2058
  {
2053
2059
  stopDragging();
2060
+ const {
2061
+ onDragging
2062
+ } = callbacksRef.current;
2063
+ if (onDragging) {
2064
+ onDragging(false);
2065
+ }
2054
2066
  break;
2055
2067
  }
2056
2068
  }
@@ -1849,11 +1849,23 @@ function PanelResizeHandle({
1849
1849
  case "down":
1850
1850
  {
1851
1851
  startDragging(resizeHandleId, event);
1852
+ const {
1853
+ onDragging
1854
+ } = callbacksRef.current;
1855
+ if (onDragging) {
1856
+ onDragging(true);
1857
+ }
1852
1858
  break;
1853
1859
  }
1854
1860
  case "up":
1855
1861
  {
1856
1862
  stopDragging();
1863
+ const {
1864
+ onDragging
1865
+ } = callbacksRef.current;
1866
+ if (onDragging) {
1867
+ onDragging(false);
1868
+ }
1857
1869
  break;
1858
1870
  }
1859
1871
  }
@@ -1825,11 +1825,23 @@ function PanelResizeHandle({
1825
1825
  case "down":
1826
1826
  {
1827
1827
  startDragging(resizeHandleId, event);
1828
+ const {
1829
+ onDragging
1830
+ } = callbacksRef.current;
1831
+ if (onDragging) {
1832
+ onDragging(true);
1833
+ }
1828
1834
  break;
1829
1835
  }
1830
1836
  case "up":
1831
1837
  {
1832
1838
  stopDragging();
1839
+ const {
1840
+ onDragging
1841
+ } = callbacksRef.current;
1842
+ if (onDragging) {
1843
+ onDragging(false);
1844
+ }
1833
1845
  break;
1834
1846
  }
1835
1847
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-resizable-panels",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "React components for resizable panel groups/layouts",
5
5
  "author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
6
6
  "license": "MIT",
@@ -72,6 +72,8 @@
72
72
  "eslint": "^8.37.0",
73
73
  "eslint-plugin-no-restricted-imports": "^0.0.0",
74
74
  "eslint-plugin-react-hooks": "^4.6.0",
75
+ "jest": "^29.7.0",
76
+ "jest-environment-jsdom": "^29.7.0",
75
77
  "react": "experimental",
76
78
  "react-dom": "experimental"
77
79
  },
@@ -3,6 +3,7 @@ import { act } from "react-dom/test-utils";
3
3
  import { Panel, PanelGroup, PanelResizeHandle } from ".";
4
4
  import { assert } from "./utils/assert";
5
5
  import { getResizeHandleElement } from "./utils/dom/getResizeHandleElement";
6
+ import { dispatchPointerEvent } from "./utils/test-utils";
6
7
 
7
8
  describe("PanelResizeHandle", () => {
8
9
  let expectedWarnings: string[] = [];
@@ -68,7 +69,45 @@ describe("PanelResizeHandle", () => {
68
69
 
69
70
  describe("callbacks", () => {
70
71
  describe("onDragging", () => {
71
- // TODO: Test this
72
+ it("should fire when dragging starts/stops", async () => {
73
+ const onDragging = jest.fn();
74
+
75
+ act(() => {
76
+ root.render(
77
+ <PanelGroup direction="horizontal">
78
+ <Panel />
79
+ <PanelResizeHandle
80
+ id="handle"
81
+ onDragging={onDragging}
82
+ tabIndex={123}
83
+ title="bar"
84
+ />
85
+ <Panel />
86
+ </PanelGroup>
87
+ );
88
+ });
89
+
90
+ const handleElement = container.querySelector(
91
+ '[data-panel-resize-handle-id="handle"]'
92
+ ) as HTMLElement;
93
+
94
+ act(() => {
95
+ dispatchPointerEvent("mouseover", handleElement);
96
+ });
97
+ expect(onDragging).not.toHaveBeenCalled();
98
+
99
+ act(() => {
100
+ dispatchPointerEvent("mousedown", handleElement);
101
+ });
102
+ expect(onDragging).toHaveBeenCalledTimes(1);
103
+ expect(onDragging).toHaveBeenCalledWith(true);
104
+
105
+ act(() => {
106
+ dispatchPointerEvent("mouseup", handleElement);
107
+ });
108
+ expect(onDragging).toHaveBeenCalledTimes(2);
109
+ expect(onDragging).toHaveBeenCalledWith(false);
110
+ });
72
111
  });
73
112
  });
74
113
  });
@@ -117,10 +117,20 @@ export function PanelResizeHandle({
117
117
  switch (action) {
118
118
  case "down": {
119
119
  startDragging(resizeHandleId, event);
120
+
121
+ const { onDragging } = callbacksRef.current;
122
+ if (onDragging) {
123
+ onDragging(true);
124
+ }
120
125
  break;
121
126
  }
122
127
  case "up": {
123
128
  stopDragging();
129
+
130
+ const { onDragging } = callbacksRef.current;
131
+ if (onDragging) {
132
+ onDragging(false);
133
+ }
124
134
  break;
125
135
  }
126
136
  }
@@ -68,8 +68,8 @@ export function useWindowSplitterResizeHandlerBehavior({
68
68
  ? index - 1
69
69
  : handles.length - 1
70
70
  : index + 1 < handles.length
71
- ? index + 1
72
- : 0;
71
+ ? index + 1
72
+ : 0;
73
73
 
74
74
  const nextHandle = handles[nextIndex] as HTMLElement;
75
75
  nextHandle.focus();
@@ -2,6 +2,33 @@ import { assert } from "./assert";
2
2
 
3
3
  const util = require("util");
4
4
 
5
+ export function dispatchPointerEvent(type: string, target: HTMLElement) {
6
+ const rect = target.getBoundingClientRect();
7
+
8
+ const clientX = rect.left + rect.width / 2;
9
+ const clientY = rect.top + rect.height / 2;
10
+
11
+ const event = new MouseEvent(type, {
12
+ bubbles: true,
13
+ clientX,
14
+ clientY,
15
+ });
16
+ Object.defineProperties(event, {
17
+ pageX: {
18
+ get() {
19
+ return clientX;
20
+ },
21
+ },
22
+ pageY: {
23
+ get() {
24
+ return clientY;
25
+ },
26
+ },
27
+ });
28
+
29
+ target.dispatchEvent(event);
30
+ }
31
+
5
32
  export function expectToBeCloseToArray(
6
33
  actualNumbers: number[],
7
34
  expectedNumbers: number[]