react-resizable-panels 0.0.8 → 0.0.10

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,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.0.10
4
+ * Drag UX change: Reversing drag after dragging past the min/max size of a panel will no longer have an effect until the pointer overlaps with the resize handle. (Thanks @davidkpiano for the suggestion!)
5
+ * Bug fix: Resize handles are no longer left in a "focused" state after a touch/mouse event.
6
+
7
+ ## 0.0.9
8
+ * [#13](https://github.com/bvaughn/react-resizable-panels/issues/13): `PanelResizeHandle` should declare "separator" role and implement the recommended ["Window Splitter" pattern](https://www.w3.org/WAI/ARIA/apg/patterns/windowsplitter/)
9
+
3
10
  ## 0.0.8
4
11
  * [#7](https://github.com/bvaughn/react-resizable-panels/issues/7): Support "touch" events for mobile compatibility.
5
12
 
@@ -8,7 +15,7 @@
8
15
  ## 0.0.6
9
16
  * [#5](https://github.com/bvaughn/react-resizable-panels/issues/5): Removed `panelBefore` and `panelAfter` props from `PanelResizeHandle`. `PanelGroup` now infers this based on position within the group.
10
17
  ## 0.0.5
11
- * TypeScript props type fix
18
+ * TypeScript props type fix for `PanelGroup`'s `children` prop.
12
19
 
13
20
  ## 0.0.4
14
21
  * [#8](https://github.com/bvaughn/react-resizable-panels/issues/8): Added optional `order` prop to `Panel` to improve conditional rendering.
@@ -1 +1 @@
1
- {"mappings":";AAAA,iBAAwB,YAAY,GAAG,UAAU,CAAC;ACIlD,OAAO,MAAM;oBACK,MAAM,GAAG,IAAI;EAChB,CAAC;ACChB,sBAA8B,EAC5B,QAAe,EACf,SAAc,EACd,WAAiB,EACjB,EAAE,EACF,OAAa,EACb,KAAY,GACb,EAAE;IACD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,eAwCA;AI5CD,aAAa;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAQF,2BAAmC,EACjC,UAAU,EACV,QAAe,EACf,SAAc,EACd,SAAS,EACT,MAAM,EACN,KAAK,GACN,EAAE,KAAK,eA6OP;AC9QD,kCAA0C,EACxC,QAAe,EACf,SAAc,EACd,QAAgB,EAChB,EAAE,EAAE,MAAa,GAClB,EAAE;IACD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB,eA+EA","sources":["packages/react-resizable-panels/src/src/types.ts","packages/react-resizable-panels/src/src/PanelContexts.ts","packages/react-resizable-panels/src/src/Panel.tsx","packages/react-resizable-panels/src/src/hooks/useUniqueId.ts","packages/react-resizable-panels/src/src/utils/serialization.ts","packages/react-resizable-panels/src/src/utils/touch.ts","packages/react-resizable-panels/src/src/PanelGroup.tsx","packages/react-resizable-panels/src/src/PanelResizeHandle.tsx","packages/react-resizable-panels/src/src/index.ts","packages/react-resizable-panels/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,"import Panel from \"./Panel\";\nimport { PanelContext } from \"./PanelContexts\";\nimport PanelGroup from \"./PanelGroup\";\nimport PanelResizeHandle from \"./PanelResizeHandle\";\n\nexport { Panel, PanelContext, PanelGroup, PanelResizeHandle };\n"],"names":[],"version":3,"file":"react-resizable-panels.d.ts.map"}
1
+ {"mappings":";AAAA,iBAAwB,YAAY,GAAG,UAAU,CAAC;ACIlD,OAAO,MAAM;oBACK,MAAM,GAAG,IAAI;EAChB,CAAC;ACChB,sBAA8B,EAC5B,QAAe,EACf,SAAc,EACd,WAAiB,EACjB,EAAE,EACF,OAAa,EACb,KAAY,GACb,EAAE;IACD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,eA6CA;AO/BD,aAAa;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAMF,2BAAmC,EACjC,UAAU,EACV,QAAe,EACf,SAAc,EACd,SAAS,EACT,MAAM,EACN,KAAK,GACN,EAAE,KAAK,eA4NP;ACrQD,kCAA0C,EACxC,QAAe,EACf,SAAc,EACd,QAAgB,EAChB,EAAE,EAAE,MAAa,GAClB,EAAE;IACD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB,eAqGA","sources":["packages/react-resizable-panels/src/src/types.ts","packages/react-resizable-panels/src/src/PanelContexts.ts","packages/react-resizable-panels/src/src/Panel.tsx","packages/react-resizable-panels/src/src/hooks/useUniqueId.ts","packages/react-resizable-panels/src/src/utils/serialization.ts","packages/react-resizable-panels/src/src/constants.ts","packages/react-resizable-panels/src/src/utils/group.ts","packages/react-resizable-panels/src/src/utils/coordinates.ts","packages/react-resizable-panels/src/src/hooks/useWindowSplitterBehavior.ts","packages/react-resizable-panels/src/src/PanelGroup.tsx","packages/react-resizable-panels/src/src/PanelResizeHandle.tsx","packages/react-resizable-panels/src/src/index.ts","packages/react-resizable-panels/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,"import Panel from \"./Panel\";\nimport { PanelContext } from \"./PanelContexts\";\nimport PanelGroup from \"./PanelGroup\";\nimport PanelResizeHandle from \"./PanelResizeHandle\";\n\nexport { Panel, PanelContext, PanelGroup, PanelResizeHandle };\n"],"names":[],"version":3,"file":"react-resizable-panels.d.ts.map","sourceRoot":"../../../"}
@@ -46,6 +46,8 @@ function $6d390b7f2e6b107f$export$2e2bcd8739ae039({ children: children = null ,
46
46
  const style = getPanelStyle(id);
47
47
  return /*#__PURE__*/ (0, $b2QPe$reactjsxdevruntime.jsxDEV)("div", {
48
48
  className: className,
49
+ "data-panel-id": id,
50
+ id: `data-panel-id-${id}`,
49
51
  style: style,
50
52
  children: children
51
53
  }, void 0, false, {
@@ -95,31 +97,253 @@ function $e045b0dd313f33c7$export$af183b313c61be4f(autoSaveId, panelIds, sizes)
95
97
  }
96
98
 
97
99
 
98
- function $37410a9246dfda64$export$70637efcd850e4ef(event, prevCoordinates) {
99
- const { screenX: prevScreenX , screenY: prevScreenY } = prevCoordinates;
100
- const getMovementBetween = (current, prev)=>prev === 0 ? 0 : current - prev;
101
- if ($37410a9246dfda64$export$ce897e7f0aa63661(event)) {
102
- const firstTouch = event.touches[0];
103
- return {
104
- movementX: getMovementBetween(firstTouch.screenX, prevScreenX),
105
- movementY: getMovementBetween(firstTouch.screenY, prevScreenY),
106
- screenX: firstTouch.screenX,
107
- screenY: firstTouch.screenY
108
- };
100
+ const $3237bc4a138172cd$export$d6d3992f3becc879 = 5;
101
+
102
+
103
+ function $d520236daad9c5d5$export$f50bae335f53943c(panels, idBefore, idAfter, delta, prevSizes) {
104
+ if (delta === 0) return prevSizes;
105
+ const panelsArray = $d520236daad9c5d5$export$a861c0ad45885494(panels);
106
+ const nextSizes = prevSizes.concat();
107
+ let deltaApplied = 0;
108
+ // A resizing panel affects the panels before or after it.
109
+ //
110
+ // A negative delta means the panel immediately after the resizer should grow/expand by decreasing its offset.
111
+ // Other panels may also need to shrink/contract (and shift) to make room, depending on the min weights.
112
+ //
113
+ // A positive delta means the panel immediately before the resizer should "expand".
114
+ // This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resizer.
115
+ let pivotId = delta < 0 ? idBefore : idAfter;
116
+ let index = panelsArray.findIndex((panel)=>panel.id === pivotId);
117
+ while(true){
118
+ const panel = panelsArray[index];
119
+ const prevSize = prevSizes[index];
120
+ const nextSize = Math.max(prevSize - Math.abs(delta), panel.minSize);
121
+ if (prevSize !== nextSize) {
122
+ deltaApplied += prevSize - nextSize;
123
+ nextSizes[index] = nextSize;
124
+ if (deltaApplied.toPrecision((0, $3237bc4a138172cd$export$d6d3992f3becc879)) >= delta.toPrecision((0, $3237bc4a138172cd$export$d6d3992f3becc879))) break;
125
+ }
126
+ if (delta < 0) {
127
+ if (--index < 0) break;
128
+ } else {
129
+ if (++index >= panelsArray.length) break;
130
+ }
131
+ }
132
+ // If we were unable to resize any of the panels panels, return the previous state.
133
+ // This will essentially bailout and ignore the "mousemove" event.
134
+ if (deltaApplied === 0) return prevSizes;
135
+ // Adjust the pivot panel before, but only by the amount that surrounding panels were able to shrink/contract.
136
+ pivotId = delta < 0 ? idAfter : idBefore;
137
+ index = panelsArray.findIndex((panel)=>panel.id === pivotId);
138
+ nextSizes[index] = prevSizes[index] + deltaApplied;
139
+ return nextSizes;
140
+ }
141
+ function $d520236daad9c5d5$export$622cea445a1c5b7d(panels, id, direction, sizes, height, width) {
142
+ const panelsArray = $d520236daad9c5d5$export$a861c0ad45885494(panels);
143
+ let index = panelsArray.findIndex((panel)=>panel.id === id);
144
+ if (index < 0) return 0;
145
+ let scaledOffset = 0;
146
+ for(index = index - 1; index >= 0; index--){
147
+ const panel = panelsArray[index];
148
+ scaledOffset += $d520236daad9c5d5$export$31b21d0167753bb4(panels, panel.id, direction, sizes, height, width);
149
+ }
150
+ return Math.round(scaledOffset);
151
+ }
152
+ function $d520236daad9c5d5$export$7361ed18ff57179e(id) {
153
+ const element = document.querySelector(`[data-panel-id="${id}"]`);
154
+ if (element) return element;
155
+ return null;
156
+ }
157
+ function $d520236daad9c5d5$export$2e27d3a347680388(id) {
158
+ const element = document.querySelector(`[data-panel-resize-handle-id="${id}"]`);
159
+ if (element) return element;
160
+ return null;
161
+ }
162
+ function $d520236daad9c5d5$export$96a40be80fb6c3c8(id) {
163
+ const handles = $d520236daad9c5d5$export$8d0cd3c32ddc045e();
164
+ const index = handles.findIndex((handle)=>handle.getAttribute("data-panel-resize-handle-id") === id);
165
+ return index ?? null;
166
+ }
167
+ function $d520236daad9c5d5$export$8d0cd3c32ddc045e() {
168
+ return Array.from(document.querySelectorAll(`[data-panel-resize-handle-id]`));
169
+ }
170
+ function $d520236daad9c5d5$export$ae14931f0a0256a3(groupId) {
171
+ return Array.from(document.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
172
+ }
173
+ function $d520236daad9c5d5$export$68d3a33c21dfbe27(groupId, handleId, panelsArray) {
174
+ const handle = $d520236daad9c5d5$export$2e27d3a347680388(handleId);
175
+ const handles = $d520236daad9c5d5$export$ae14931f0a0256a3(groupId);
176
+ const index = handles.indexOf(handle);
177
+ const idBefore = panelsArray[index]?.id ?? null;
178
+ const idAfter = panelsArray[index + 1]?.id ?? null;
179
+ return [
180
+ idBefore,
181
+ idAfter
182
+ ];
183
+ }
184
+ function $d520236daad9c5d5$export$a861c0ad45885494(panels) {
185
+ return Array.from(panels.values()).sort((a, b)=>a.order - b.order);
186
+ }
187
+ function $d520236daad9c5d5$export$31b21d0167753bb4(panels, id, direction, sizes, height, width) {
188
+ const totalSize = direction === "horizontal" ? width : height;
189
+ if (panels.size === 1) return totalSize;
190
+ const panelsArray = $d520236daad9c5d5$export$a861c0ad45885494(panels);
191
+ const index = panelsArray.findIndex((panel)=>panel.id === id);
192
+ const size = sizes[index];
193
+ if (size == null) return 0;
194
+ return Math.round(size * totalSize);
195
+ }
196
+
197
+
198
+ const $f5af57c8e042a4ad$var$element = document.createElement("div");
199
+ $f5af57c8e042a4ad$var$element.getBoundingClientRect();
200
+ function $f5af57c8e042a4ad$export$354b17c0684607ed(event, handleId, { height: height , width: width }, direction) {
201
+ const isHorizontal = direction === "horizontal";
202
+ const size = isHorizontal ? width : height;
203
+ if ($f5af57c8e042a4ad$export$e7bf60a870f429b0(event)) {
204
+ const denominator = event.shiftKey ? 10 : 100;
205
+ const delta = size / denominator;
206
+ switch(event.key){
207
+ case "ArrowDown":
208
+ return delta;
209
+ case "ArrowLeft":
210
+ return -delta;
211
+ case "ArrowRight":
212
+ return delta;
213
+ case "ArrowUp":
214
+ return -delta;
215
+ case "End":
216
+ if (isHorizontal) return size;
217
+ else return size;
218
+ case "Home":
219
+ if (isHorizontal) return -size;
220
+ else return -size;
221
+ }
222
+ } else {
223
+ const handleElement = (0, $d520236daad9c5d5$export$2e27d3a347680388)(handleId);
224
+ const rect = handleElement.getBoundingClientRect();
225
+ const elementOffset = isHorizontal ? rect.left : rect.top;
226
+ let pointerOffset = 0;
227
+ if ($f5af57c8e042a4ad$export$5107d838cdd17dee(event)) pointerOffset = isHorizontal ? event.clientX : event.clientY;
228
+ else {
229
+ const firstTouch = event.touches[0];
230
+ pointerOffset = isHorizontal ? firstTouch.screenX : firstTouch.screenY;
231
+ }
232
+ return pointerOffset - elementOffset;
109
233
  }
110
- return {
111
- movementX: getMovementBetween(event.screenX, prevScreenX),
112
- movementY: getMovementBetween(event.screenY, prevScreenY),
113
- screenX: event.screenX,
114
- screenY: event.screenY
115
- };
116
234
  }
117
- function $37410a9246dfda64$export$ce897e7f0aa63661(event) {
235
+ function $f5af57c8e042a4ad$export$e7bf60a870f429b0(event) {
236
+ return event.type === "keydown";
237
+ }
238
+ function $f5af57c8e042a4ad$export$5107d838cdd17dee(event) {
239
+ return event.type === "mousemove";
240
+ }
241
+ function $f5af57c8e042a4ad$export$ce897e7f0aa63661(event) {
118
242
  return event.type === "touchmove";
119
243
  }
120
244
 
121
245
 
122
- const $d428eaeef644efb2$var$PRECISION = 5;
246
+
247
+
248
+
249
+
250
+ function $63be9a96d8675f03$export$d9fcbe062527d159({ committedValuesRef: committedValuesRef , groupId: groupId , panels: panels , setSizes: setSizes , sizes: sizes }) {
251
+ (0, $b2QPe$react.useEffect)(()=>{
252
+ const { direction: direction , height: height , panels: panels , width: width } = committedValuesRef.current;
253
+ const handles = (0, $d520236daad9c5d5$export$ae14931f0a0256a3)(groupId);
254
+ const cleanupFunctions = handles.map((handle)=>{
255
+ const handleId = handle.getAttribute("data-panel-resize-handle-id");
256
+ const panelsArray = (0, $d520236daad9c5d5$export$a861c0ad45885494)(panels);
257
+ const [idBefore, idAfter] = (0, $d520236daad9c5d5$export$68d3a33c21dfbe27)(groupId, handleId, panelsArray);
258
+ if (idBefore == null || idAfter == null) return ()=>{};
259
+ const ariaValueMax = panelsArray.reduce((difference, panel)=>{
260
+ if (panel.id !== idBefore) return difference - panel.minSize;
261
+ return difference;
262
+ }, 1);
263
+ const ariaValueMin = panelsArray.find((panel)=>panel.id == idBefore)?.minSize ?? 0;
264
+ const size = (0, $d520236daad9c5d5$export$31b21d0167753bb4)(panels, idBefore, direction, sizes, height, width);
265
+ const ariaValueNow = size / (direction === "horizontal" ? width : height);
266
+ handle.setAttribute("aria-valuemax", "" + Math.round(100 * ariaValueMax));
267
+ handle.setAttribute("aria-valuemin", "" + Math.round(100 * ariaValueMin));
268
+ handle.setAttribute("aria-valuenow", "" + Math.round(100 * ariaValueNow));
269
+ const onKeyDown = (event)=>{
270
+ switch(event.key){
271
+ case "Enter":
272
+ {
273
+ const index = panelsArray.findIndex((panel)=>panel.id === idBefore);
274
+ if (index >= 0) {
275
+ const panelData = panelsArray[index];
276
+ const size = sizes[index];
277
+ if (size != null) {
278
+ let delta = 0;
279
+ if (size.toPrecision((0, $3237bc4a138172cd$export$d6d3992f3becc879)) <= panelData.minSize.toPrecision((0, $3237bc4a138172cd$export$d6d3992f3becc879))) delta = direction === "horizontal" ? width : height;
280
+ else delta = -(direction === "horizontal" ? width : height);
281
+ const nextSizes = (0, $d520236daad9c5d5$export$f50bae335f53943c)(panels, idBefore, idAfter, delta, sizes);
282
+ if (sizes !== nextSizes) setSizes(nextSizes);
283
+ }
284
+ }
285
+ break;
286
+ }
287
+ }
288
+ };
289
+ handle.addEventListener("keydown", onKeyDown);
290
+ const panelBefore = (0, $d520236daad9c5d5$export$7361ed18ff57179e)(idBefore);
291
+ if (panelBefore != null) handle.setAttribute("aria-controls", panelBefore.id);
292
+ return ()=>{
293
+ handle.removeAttribute("aria-valuemax");
294
+ handle.removeAttribute("aria-valuemin");
295
+ handle.removeAttribute("aria-valuenow");
296
+ handle.removeEventListener("keydown", onKeyDown);
297
+ if (panelBefore != null) handle.removeAttribute("aria-controls");
298
+ };
299
+ });
300
+ return ()=>{
301
+ cleanupFunctions.forEach((cleanupFunction)=>cleanupFunction());
302
+ };
303
+ }, [
304
+ groupId,
305
+ panels,
306
+ sizes
307
+ ]);
308
+ }
309
+ function $63be9a96d8675f03$export$33b0bea6ac3ffb03({ disabled: disabled , handleId: handleId , resizeHandler: resizeHandler }) {
310
+ (0, $b2QPe$react.useEffect)(()=>{
311
+ if (disabled || resizeHandler == null) return;
312
+ const handleElement = (0, $d520236daad9c5d5$export$2e27d3a347680388)(handleId);
313
+ if (handleElement == null) return;
314
+ const onKeyDown = (event)=>{
315
+ switch(event.key){
316
+ case "ArrowDown":
317
+ case "ArrowLeft":
318
+ case "ArrowRight":
319
+ case "ArrowUp":
320
+ case "End":
321
+ case "Home":
322
+ resizeHandler(event);
323
+ break;
324
+ case "F6":
325
+ {
326
+ const handles = (0, $d520236daad9c5d5$export$8d0cd3c32ddc045e)();
327
+ const index = (0, $d520236daad9c5d5$export$96a40be80fb6c3c8)(handleId);
328
+ const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
329
+ const nextHandle = handles[nextIndex];
330
+ nextHandle.focus();
331
+ break;
332
+ }
333
+ }
334
+ };
335
+ handleElement.addEventListener("keydown", onKeyDown);
336
+ return ()=>{
337
+ handleElement.removeEventListener("keydown", onKeyDown);
338
+ };
339
+ }, [
340
+ disabled,
341
+ handleId,
342
+ resizeHandler
343
+ ]);
344
+ }
345
+
346
+
123
347
  function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , children: children = null , className: className = "" , direction: direction , height: height , width: width }) {
124
348
  const groupId = (0, $6d548a0d130941e3$export$2e2bcd8739ae039)();
125
349
  const [activeHandleId, setActiveHandleId] = (0, $b2QPe$react.useState)(null);
@@ -134,12 +358,6 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
134
358
  sizes: sizes,
135
359
  width: width
136
360
  });
137
- // Tracks the most recent coordinates of a touch/mouse event.
138
- // This is needed to calculate movement (because TouchEvent doesn't support movementX and movementY).
139
- const prevCoordinatesRef = (0, $b2QPe$react.useRef)({
140
- screenX: 0,
141
- screenY: 0
142
- });
143
361
  (0, $b2QPe$react.useLayoutEffect)(()=>{
144
362
  committedValuesRef.current.direction = direction;
145
363
  committedValuesRef.current.height = height;
@@ -147,6 +365,13 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
147
365
  committedValuesRef.current.sizes = sizes;
148
366
  committedValuesRef.current.width = width;
149
367
  });
368
+ (0, $63be9a96d8675f03$export$d9fcbe062527d159)({
369
+ committedValuesRef: committedValuesRef,
370
+ groupId: groupId,
371
+ panels: panels,
372
+ setSizes: setSizes,
373
+ sizes: sizes
374
+ });
150
375
  // Once all panels have registered themselves,
151
376
  // Compute the initial sizes based on default weights.
152
377
  // This assumes that panels register during initial mount (no conditional rendering)!
@@ -159,12 +384,12 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
159
384
  // default size should be restored from local storage if possible.
160
385
  let defaultSizes = undefined;
161
386
  if (autoSaveId) {
162
- const panelIds = $d428eaeef644efb2$var$panelsMapToSortedArray(panels).map((panel)=>panel.id);
387
+ const panelIds = (0, $d520236daad9c5d5$export$a861c0ad45885494)(panels).map((panel)=>panel.id);
163
388
  defaultSizes = (0, $e045b0dd313f33c7$export$9c80c6617f0386da)(autoSaveId, panelIds);
164
389
  }
165
390
  if (defaultSizes != null) setSizes(defaultSizes);
166
391
  else {
167
- const panelsArray = $d428eaeef644efb2$var$panelsMapToSortedArray(panels);
392
+ const panelsArray = (0, $d520236daad9c5d5$export$a861c0ad45885494)(panels);
168
393
  const totalWeight = panelsArray.reduce((weight, panel)=>{
169
394
  return weight + panel.defaultSize;
170
395
  }, 0);
@@ -178,7 +403,7 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
178
403
  // If this panel has been configured to persist sizing information, save sizes to local storage.
179
404
  if (autoSaveId) {
180
405
  if (sizes.length === 0 || sizes.length !== panels.size) return;
181
- const panelIds = $d428eaeef644efb2$var$panelsMapToSortedArray(panels).map((panel)=>panel.id);
406
+ const panelIds = (0, $d520236daad9c5d5$export$a861c0ad45885494)(panels).map((panel)=>panel.id);
182
407
  (0, $e045b0dd313f33c7$export$af183b313c61be4f)(autoSaveId, panelIds, sizes);
183
408
  }
184
409
  }, [
@@ -188,8 +413,8 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
188
413
  ]);
189
414
  const getPanelStyle = (0, $b2QPe$react.useCallback)((id)=>{
190
415
  const { panels: panels } = committedValuesRef.current;
191
- const offset = $d428eaeef644efb2$var$getOffset(panels, id, direction, sizes, height, width);
192
- const size = $d428eaeef644efb2$var$getSize(panels, id, direction, sizes, height, width);
416
+ const offset = (0, $d520236daad9c5d5$export$622cea445a1c5b7d)(panels, id, direction, sizes, height, width);
417
+ const size = (0, $d520236daad9c5d5$export$31b21d0167753bb4)(panels, id, direction, sizes, height, width);
193
418
  if (direction === "horizontal") return {
194
419
  height: "100%",
195
420
  position: "absolute",
@@ -218,26 +443,20 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
218
443
  return nextPanels;
219
444
  });
220
445
  }, []);
221
- const registerResizeHandle = (0, $b2QPe$react.useCallback)((id)=>{
446
+ const registerResizeHandle = (0, $b2QPe$react.useCallback)((handleId)=>{
222
447
  const resizeHandler = (event)=>{
223
448
  event.preventDefault();
224
449
  const { direction: direction , height: height , panels: panels , sizes: prevSizes , width: width } = committedValuesRef.current;
225
- const handle = document.querySelector(`[data-panel-resize-handle-id="${id}"]`);
226
- const handles = Array.from(document.querySelectorAll(`[data-panel-group-id="${groupId}"]`));
227
- const index = handles.indexOf(handle);
228
- const panelsArray = $d428eaeef644efb2$var$panelsMapToSortedArray(panels);
229
- const idBefore = panelsArray[index]?.id ?? null;
230
- const idAfter = panelsArray[index + 1]?.id ?? null;
450
+ const panelsArray = (0, $d520236daad9c5d5$export$a861c0ad45885494)(panels);
451
+ const [idBefore, idAfter] = (0, $d520236daad9c5d5$export$68d3a33c21dfbe27)(groupId, handleId, panelsArray);
231
452
  if (idBefore == null || idAfter == null) return;
232
- const nextCoordinates = (0, $37410a9246dfda64$export$70637efcd850e4ef)(event, prevCoordinatesRef.current);
233
- prevCoordinatesRef.current = {
234
- screenX: nextCoordinates.screenX,
235
- screenY: nextCoordinates.screenY
236
- };
453
+ const movement = (0, $f5af57c8e042a4ad$export$354b17c0684607ed)(event, handleId, {
454
+ height: height,
455
+ width: width
456
+ }, direction);
237
457
  const isHorizontal = direction === "horizontal";
238
- const movement = isHorizontal ? nextCoordinates.movementX : nextCoordinates.movementY;
239
458
  const delta = isHorizontal ? movement / width : movement / height;
240
- const nextSizes = $d428eaeef644efb2$var$adjustByDelta(panels, idBefore, idAfter, delta, prevSizes);
459
+ const nextSizes = (0, $d520236daad9c5d5$export$f50bae335f53943c)(panels, idBefore, idAfter, delta, prevSizes);
241
460
  if (prevSizes !== nextSizes) setSizes(nextSizes);
242
461
  };
243
462
  return resizeHandler;
@@ -261,10 +480,6 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
261
480
  startDragging: (id)=>setActiveHandleId(id),
262
481
  stopDragging: ()=>{
263
482
  setActiveHandleId(null);
264
- prevCoordinatesRef.current = {
265
- screenX: 0,
266
- screenY: 0
267
- };
268
483
  },
269
484
  unregisterPanel: unregisterPanel
270
485
  }), [
@@ -289,81 +504,21 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
289
504
  children: children
290
505
  }, void 0, false, {
291
506
  fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
292
- lineNumber: 273,
507
+ lineNumber: 272,
293
508
  columnNumber: 9
294
509
  }, this)
295
510
  }, void 0, false, {
296
511
  fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
297
- lineNumber: 272,
512
+ lineNumber: 271,
298
513
  columnNumber: 7
299
514
  }, this)
300
515
  }, void 0, false, {
301
516
  fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
302
- lineNumber: 271,
517
+ lineNumber: 270,
303
518
  columnNumber: 5
304
519
  }, this);
305
520
  }
306
- function $d428eaeef644efb2$var$adjustByDelta(panels, idBefore, idAfter, delta, prevSizes) {
307
- if (delta === 0) return prevSizes;
308
- const panelsArray = $d428eaeef644efb2$var$panelsMapToSortedArray(panels);
309
- const nextSizes = prevSizes.concat();
310
- let deltaApplied = 0;
311
- // A resizing panel affects the panels before or after it.
312
- //
313
- // A negative delta means the panel immediately after the resizer should grow/expand by decreasing its offset.
314
- // Other panels may also need to shrink/contract (and shift) to make room, depending on the min weights.
315
- //
316
- // A positive delta means the panel immediately before the resizer should "expand".
317
- // This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resizer.
318
- let pivotId = delta < 0 ? idBefore : idAfter;
319
- let index = panelsArray.findIndex((panel)=>panel.id === pivotId);
320
- while(true){
321
- const panel = panelsArray[index];
322
- const prevSize = prevSizes[index];
323
- const nextSize = Math.max(prevSize - Math.abs(delta), panel.minSize);
324
- if (prevSize !== nextSize) {
325
- deltaApplied += prevSize - nextSize;
326
- nextSizes[index] = nextSize;
327
- if (deltaApplied.toPrecision($d428eaeef644efb2$var$PRECISION) >= delta.toPrecision($d428eaeef644efb2$var$PRECISION)) break;
328
- }
329
- if (delta < 0) {
330
- if (--index < 0) break;
331
- } else {
332
- if (++index >= panelsArray.length) break;
333
- }
334
- }
335
- // If we were unable to resize any of the panels panels, return the previous state.
336
- // This will essentially bailout and ignore the "mousemove" event.
337
- if (deltaApplied === 0) return prevSizes;
338
- // Adjust the pivot panel before, but only by the amount that surrounding panels were able to shrink/contract.
339
- pivotId = delta < 0 ? idAfter : idBefore;
340
- index = panelsArray.findIndex((panel)=>panel.id === pivotId);
341
- nextSizes[index] = prevSizes[index] + deltaApplied;
342
- return nextSizes;
343
- }
344
- function $d428eaeef644efb2$var$getOffset(panels, id, direction, sizes, height, width) {
345
- const panelsArray = $d428eaeef644efb2$var$panelsMapToSortedArray(panels);
346
- let index = panelsArray.findIndex((panel)=>panel.id === id);
347
- if (index < 0) return 0;
348
- let scaledOffset = 0;
349
- for(index = index - 1; index >= 0; index--){
350
- const panel = panelsArray[index];
351
- scaledOffset += $d428eaeef644efb2$var$getSize(panels, panel.id, direction, sizes, height, width);
352
- }
353
- return Math.round(scaledOffset);
354
- }
355
- function $d428eaeef644efb2$var$getSize(panels, id, direction, sizes, height, width) {
356
- const totalSize = direction === "horizontal" ? width : height;
357
- if (panels.size === 1) return totalSize;
358
- const panelsArray = $d428eaeef644efb2$var$panelsMapToSortedArray(panels);
359
- const index = panelsArray.findIndex((panel)=>panel.id === id);
360
- const size = sizes[index];
361
- if (size == null) return 0;
362
- return Math.round(size * totalSize);
363
- }
364
- function $d428eaeef644efb2$var$panelsMapToSortedArray(panels) {
365
- return Array.from(panels.values()).sort((a, b)=>a.order - b.order);
366
- }
521
+
367
522
 
368
523
 
369
524
 
@@ -371,6 +526,7 @@ function $d428eaeef644efb2$var$panelsMapToSortedArray(panels) {
371
526
 
372
527
 
373
528
  function $d578a49f00f1bdeb$export$2e2bcd8739ae039({ children: children = null , className: className = "" , disabled: disabled = false , id: idProp = null }) {
529
+ const divElementRef = (0, $d578a49f00f1bdeb$import$65588215f5c347c3$b8f5890fc79d6aca)(null);
374
530
  const panelContext = (0, $b2QPe$react.useContext)((0, $3251d17c1c3bce6c$export$f34532ac99e32150));
375
531
  const panelGroupContext = (0, $b2QPe$react.useContext)((0, $3251d17c1c3bce6c$export$7d8c6d083caec74a));
376
532
  if (panelContext === null || panelGroupContext === null) throw Error(`PanelResizeHandle components must be rendered within a PanelGroup container`);
@@ -379,6 +535,15 @@ function $d578a49f00f1bdeb$export$2e2bcd8739ae039({ children: children = null ,
379
535
  const { direction: direction , groupId: groupId , registerResizeHandle: registerResizeHandle , startDragging: startDragging , stopDragging: stopDragging } = panelGroupContext;
380
536
  const isDragging = activeHandleId === id;
381
537
  const [resizeHandler, setResizeHandler] = (0, $b2QPe$react.useState)(null);
538
+ const stopDraggingAndBlur = (0, $d578a49f00f1bdeb$import$65588215f5c347c3$35808ee640e87ca7)(()=>{
539
+ // Clicking on the drag handle shouldn't leave it focused;
540
+ // That would cause the PanelGroup to think it was still active.
541
+ const div = divElementRef.current;
542
+ div.blur();
543
+ stopDragging();
544
+ }, [
545
+ stopDragging
546
+ ]);
382
547
  (0, $b2QPe$react.useEffect)(()=>{
383
548
  if (disabled) setResizeHandler(null);
384
549
  else {
@@ -387,7 +552,6 @@ function $d578a49f00f1bdeb$export$2e2bcd8739ae039({ children: children = null ,
387
552
  }
388
553
  }, [
389
554
  disabled,
390
- groupId,
391
555
  id,
392
556
  registerResizeHandle
393
557
  ]);
@@ -397,41 +561,50 @@ function $d578a49f00f1bdeb$export$2e2bcd8739ae039({ children: children = null ,
397
561
  const onMove = (event)=>{
398
562
  resizeHandler(event);
399
563
  };
400
- document.body.addEventListener("mouseleave", stopDragging);
564
+ document.body.addEventListener("mouseleave", stopDraggingAndBlur);
401
565
  document.body.addEventListener("mousemove", onMove);
402
566
  document.body.addEventListener("touchmove", onMove);
403
- document.body.addEventListener("mouseup", stopDragging);
567
+ document.body.addEventListener("mouseup", stopDraggingAndBlur);
404
568
  return ()=>{
405
569
  document.body.style.cursor = "";
406
- document.body.removeEventListener("mouseleave", stopDragging);
570
+ document.body.removeEventListener("mouseleave", stopDraggingAndBlur);
407
571
  document.body.removeEventListener("mousemove", onMove);
408
572
  document.body.removeEventListener("touchmove", onMove);
409
- document.body.removeEventListener("mouseup", stopDragging);
573
+ document.body.removeEventListener("mouseup", stopDraggingAndBlur);
410
574
  };
411
575
  }, [
412
576
  direction,
413
577
  disabled,
414
578
  isDragging,
415
579
  resizeHandler,
416
- stopDragging
580
+ stopDraggingAndBlur
417
581
  ]);
582
+ (0, $63be9a96d8675f03$export$33b0bea6ac3ffb03)({
583
+ disabled: disabled,
584
+ handleId: id,
585
+ resizeHandler: resizeHandler
586
+ });
418
587
  return /*#__PURE__*/ (0, $b2QPe$reactjsxdevruntime.jsxDEV)("div", {
419
588
  className: className,
420
589
  "data-panel-group-id": groupId,
590
+ "data-panel-resize-handle-enabled": !disabled,
421
591
  "data-panel-resize-handle-id": id,
422
592
  onMouseDown: ()=>startDragging(id),
423
- onMouseUp: stopDragging,
424
- onTouchCancel: stopDragging,
425
- onTouchEnd: stopDragging,
593
+ onMouseUp: stopDraggingAndBlur,
594
+ onTouchCancel: stopDraggingAndBlur,
595
+ onTouchEnd: stopDraggingAndBlur,
426
596
  onTouchStart: ()=>startDragging(id),
597
+ ref: divElementRef,
598
+ role: "separator",
427
599
  style: {
428
600
  cursor: direction === "horizontal" ? "ew-resize" : "ns-resize",
429
601
  touchAction: "none"
430
602
  },
603
+ tabIndex: 0,
431
604
  children: children
432
605
  }, void 0, false, {
433
606
  fileName: "packages/react-resizable-panels/src/PanelResizeHandle.tsx",
434
- lineNumber: 80,
607
+ lineNumber: 105,
435
608
  columnNumber: 5
436
609
  }, this);
437
610
  }