react-resizable-panels 0.0.53 → 0.0.55

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/dist/declarations/src/Panel.d.ts +6 -5
  3. package/dist/declarations/src/PanelGroup.d.ts +8 -4
  4. package/dist/declarations/src/PanelResizeHandle.d.ts +5 -2
  5. package/dist/declarations/src/index.d.ts +9 -8
  6. package/dist/declarations/src/types.d.ts +4 -2
  7. package/dist/declarations/src/utils/group.d.ts +29 -0
  8. package/dist/react-resizable-panels.browser.cjs.js +1709 -0
  9. package/dist/react-resizable-panels.browser.cjs.mjs +6 -0
  10. package/dist/react-resizable-panels.browser.development.cjs.js +1764 -0
  11. package/dist/react-resizable-panels.browser.development.cjs.mjs +6 -0
  12. package/dist/react-resizable-panels.browser.development.esm.js +1737 -0
  13. package/dist/react-resizable-panels.browser.esm.js +1682 -0
  14. package/dist/react-resizable-panels.cjs.js +395 -126
  15. package/dist/react-resizable-panels.cjs.js.map +1 -0
  16. package/dist/react-resizable-panels.cjs.mjs +2 -1
  17. package/dist/react-resizable-panels.development.cjs.js +452 -135
  18. package/dist/react-resizable-panels.development.cjs.mjs +6 -0
  19. package/dist/react-resizable-panels.development.esm.js +452 -136
  20. package/dist/react-resizable-panels.development.node.cjs.js +1579 -0
  21. package/dist/react-resizable-panels.development.node.cjs.mjs +6 -0
  22. package/dist/react-resizable-panels.development.node.esm.js +1552 -0
  23. package/dist/react-resizable-panels.esm.js +395 -127
  24. package/dist/react-resizable-panels.esm.js.map +1 -0
  25. package/dist/react-resizable-panels.node.cjs.js +1523 -0
  26. package/dist/react-resizable-panels.node.cjs.mjs +6 -0
  27. package/dist/react-resizable-panels.node.esm.js +1496 -0
  28. package/package.json +26 -1
  29. package/src/Panel.ts +37 -37
  30. package/src/PanelContexts.ts +5 -6
  31. package/src/PanelGroup.ts +269 -121
  32. package/src/PanelResizeHandle.ts +1 -4
  33. package/src/env-conditions/browser.ts +1 -0
  34. package/src/env-conditions/node.ts +1 -0
  35. package/src/env-conditions/unknown.ts +1 -0
  36. package/src/hooks/useIsomorphicEffect.ts +2 -9
  37. package/src/hooks/useWindowSplitterBehavior.ts +14 -11
  38. package/src/index.ts +11 -3
  39. package/src/types.ts +3 -1
  40. package/src/utils/group.ts +327 -28
  41. package/src/utils/ssr.ts +0 -7
@@ -0,0 +1,1764 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+
7
+ function _interopNamespace(e) {
8
+ if (e && e.__esModule) return e;
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () { return e[k]; }
17
+ });
18
+ }
19
+ });
20
+ }
21
+ n["default"] = e;
22
+ return Object.freeze(n);
23
+ }
24
+
25
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
26
+
27
+ // This module exists to work around Webpack issue https://github.com/webpack/webpack/issues/14814
28
+
29
+ // eslint-disable-next-line no-restricted-imports
30
+
31
+ const {
32
+ createElement,
33
+ createContext,
34
+ forwardRef,
35
+ useCallback,
36
+ useContext,
37
+ useEffect,
38
+ useImperativeHandle,
39
+ useLayoutEffect,
40
+ useMemo,
41
+ useRef,
42
+ useState
43
+ } = React__namespace;
44
+
45
+ // `toString()` prevents bundlers from trying to `import { useId } from 'react'`
46
+ const useId = React__namespace["useId".toString()];
47
+
48
+ const useIsomorphicLayoutEffect = useLayoutEffect ;
49
+
50
+ const wrappedUseId = typeof useId === "function" ? useId : () => null;
51
+ let counter = 0;
52
+ function useUniqueId(idFromParams = null) {
53
+ const idFromUseId = wrappedUseId();
54
+ const idRef = useRef(idFromParams || idFromUseId || null);
55
+ if (idRef.current === null) {
56
+ idRef.current = "" + counter++;
57
+ }
58
+ return idRef.current;
59
+ }
60
+
61
+ const PanelGroupContext = createContext(null);
62
+ PanelGroupContext.displayName = "PanelGroupContext";
63
+
64
+ function PanelWithForwardedRef({
65
+ children = null,
66
+ className: classNameFromProps = "",
67
+ collapsedSize = 0,
68
+ collapsible = false,
69
+ defaultSize = null,
70
+ forwardedRef,
71
+ id: idFromProps = null,
72
+ maxSize = null,
73
+ minSize,
74
+ onCollapse = null,
75
+ onResize = null,
76
+ order = null,
77
+ style: styleFromProps = {},
78
+ tagName: Type = "div"
79
+ }) {
80
+ const context = useContext(PanelGroupContext);
81
+ if (context === null) {
82
+ throw Error(`Panel components must be rendered within a PanelGroup container`);
83
+ }
84
+ const panelId = useUniqueId(idFromProps);
85
+ const {
86
+ collapsePanel,
87
+ expandPanel,
88
+ getPanelSize,
89
+ getPanelStyle,
90
+ registerPanel,
91
+ resizePanel,
92
+ units,
93
+ unregisterPanel
94
+ } = context;
95
+ if (minSize == null) {
96
+ if (units === "percentages") {
97
+ // Mimics legacy default value for percentage based panel groups
98
+ minSize = 10;
99
+ } else {
100
+ // There is no meaningful minimum pixel default we can provide
101
+ minSize = 0;
102
+ }
103
+ }
104
+
105
+ // Use a ref to guard against users passing inline props
106
+ const callbacksRef = useRef({
107
+ onCollapse,
108
+ onResize
109
+ });
110
+ useEffect(() => {
111
+ callbacksRef.current.onCollapse = onCollapse;
112
+ callbacksRef.current.onResize = onResize;
113
+ });
114
+ const style = getPanelStyle(panelId, defaultSize);
115
+ const committedValuesRef = useRef({
116
+ size: parseSizeFromStyle(style)
117
+ });
118
+ const panelDataRef = useRef({
119
+ callbacksRef,
120
+ collapsedSize,
121
+ collapsible,
122
+ defaultSize,
123
+ id: panelId,
124
+ idWasAutoGenerated: idFromProps == null,
125
+ maxSize,
126
+ minSize,
127
+ order
128
+ });
129
+ useIsomorphicLayoutEffect(() => {
130
+ committedValuesRef.current.size = parseSizeFromStyle(style);
131
+ panelDataRef.current.callbacksRef = callbacksRef;
132
+ panelDataRef.current.collapsedSize = collapsedSize;
133
+ panelDataRef.current.collapsible = collapsible;
134
+ panelDataRef.current.defaultSize = defaultSize;
135
+ panelDataRef.current.id = panelId;
136
+ panelDataRef.current.idWasAutoGenerated = idFromProps == null;
137
+ panelDataRef.current.maxSize = maxSize;
138
+ panelDataRef.current.minSize = minSize;
139
+ panelDataRef.current.order = order;
140
+ });
141
+ useIsomorphicLayoutEffect(() => {
142
+ registerPanel(panelId, panelDataRef);
143
+ return () => {
144
+ unregisterPanel(panelId);
145
+ };
146
+ }, [order, panelId, registerPanel, unregisterPanel]);
147
+ useImperativeHandle(forwardedRef, () => ({
148
+ collapse: () => collapsePanel(panelId),
149
+ expand: () => expandPanel(panelId),
150
+ getCollapsed() {
151
+ return committedValuesRef.current.size === 0;
152
+ },
153
+ getId() {
154
+ return panelId;
155
+ },
156
+ getSize(units) {
157
+ return getPanelSize(panelId, units);
158
+ },
159
+ resize: (percentage, units) => resizePanel(panelId, percentage, units)
160
+ }), [collapsePanel, expandPanel, getPanelSize, panelId, resizePanel]);
161
+ return createElement(Type, {
162
+ children,
163
+ className: classNameFromProps,
164
+ "data-panel": "",
165
+ "data-panel-collapsible": collapsible || undefined,
166
+ "data-panel-id": panelId,
167
+ "data-panel-size": parseFloat("" + style.flexGrow).toFixed(1),
168
+ id: `data-panel-id-${panelId}`,
169
+ style: {
170
+ ...style,
171
+ ...styleFromProps
172
+ }
173
+ });
174
+ }
175
+ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
176
+ ...props,
177
+ forwardedRef: ref
178
+ }));
179
+ PanelWithForwardedRef.displayName = "Panel";
180
+ Panel.displayName = "forwardRef(Panel)";
181
+
182
+ // HACK
183
+ function parseSizeFromStyle(style) {
184
+ const {
185
+ flexGrow
186
+ } = style;
187
+ if (typeof flexGrow === "string") {
188
+ return parseFloat(flexGrow);
189
+ } else {
190
+ return flexGrow;
191
+ }
192
+ }
193
+
194
+ const PRECISION = 10;
195
+
196
+ function adjustByDelta(event, committedValues, idBefore, idAfter, deltaPixels, prevSizes, panelSizeBeforeCollapse, initialDragState) {
197
+ const {
198
+ id: groupId,
199
+ panels,
200
+ units
201
+ } = committedValues;
202
+ const groupSizePixels = units === "pixels" ? getAvailableGroupSizePixels(groupId) : NaN;
203
+ const {
204
+ sizes: initialSizes
205
+ } = initialDragState || {};
206
+
207
+ // If we're resizing by mouse or touch, use the initial sizes as a base.
208
+ // This has the benefit of causing force-collapsed panels to spring back open if drag is reversed.
209
+ const baseSizes = initialSizes || prevSizes;
210
+ const panelsArray = panelsMapToSortedArray(panels);
211
+ const nextSizes = baseSizes.concat();
212
+ let deltaApplied = 0;
213
+
214
+ // A resizing panel affects the panels before or after it.
215
+ //
216
+ // A negative delta means the panel immediately after the resizer should grow/expand by decreasing its offset.
217
+ // Other panels may also need to shrink/contract (and shift) to make room, depending on the min weights.
218
+ //
219
+ // A positive delta means the panel immediately before the resizer should "expand".
220
+ // This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resizer.
221
+
222
+ // Max-bounds check the panel being expanded first.
223
+ {
224
+ const pivotId = deltaPixels < 0 ? idAfter : idBefore;
225
+ const index = panelsArray.findIndex(panel => panel.current.id === pivotId);
226
+ const panel = panelsArray[index];
227
+ const baseSize = baseSizes[index];
228
+ const nextSize = safeResizePanel(units, groupSizePixels, panel, baseSize, baseSize + Math.abs(deltaPixels), event);
229
+ if (baseSize === nextSize) {
230
+ // If there's no room for the pivot panel to grow, we can ignore this drag update.
231
+ return baseSizes;
232
+ } else {
233
+ if (nextSize === 0 && baseSize > 0) {
234
+ panelSizeBeforeCollapse.set(pivotId, baseSize);
235
+ }
236
+ deltaPixels = deltaPixels < 0 ? baseSize - nextSize : nextSize - baseSize;
237
+ }
238
+ }
239
+ let pivotId = deltaPixels < 0 ? idBefore : idAfter;
240
+ let index = panelsArray.findIndex(panel => panel.current.id === pivotId);
241
+ while (true) {
242
+ const panel = panelsArray[index];
243
+ const baseSize = baseSizes[index];
244
+ const deltaRemaining = Math.abs(deltaPixels) - Math.abs(deltaApplied);
245
+ const nextSize = safeResizePanel(units, groupSizePixels, panel, baseSize, baseSize - deltaRemaining, event);
246
+ if (baseSize !== nextSize) {
247
+ if (nextSize === 0 && baseSize > 0) {
248
+ panelSizeBeforeCollapse.set(panel.current.id, baseSize);
249
+ }
250
+ deltaApplied += baseSize - nextSize;
251
+ nextSizes[index] = nextSize;
252
+ if (deltaApplied.toPrecision(PRECISION).localeCompare(Math.abs(deltaPixels).toPrecision(PRECISION), undefined, {
253
+ numeric: true
254
+ }) >= 0) {
255
+ break;
256
+ }
257
+ }
258
+ if (deltaPixels < 0) {
259
+ if (--index < 0) {
260
+ break;
261
+ }
262
+ } else {
263
+ if (++index >= panelsArray.length) {
264
+ break;
265
+ }
266
+ }
267
+ }
268
+
269
+ // If we were unable to resize any of the panels panels, return the previous state.
270
+ // This will essentially bailout and ignore the "mousemove" event.
271
+ if (deltaApplied === 0) {
272
+ return baseSizes;
273
+ }
274
+
275
+ // Adjust the pivot panel before, but only by the amount that surrounding panels were able to shrink/contract.
276
+ pivotId = deltaPixels < 0 ? idAfter : idBefore;
277
+ index = panelsArray.findIndex(panel => panel.current.id === pivotId);
278
+ nextSizes[index] = baseSizes[index] + deltaApplied;
279
+ return nextSizes;
280
+ }
281
+ function callPanelCallbacks(panelsArray, sizes, panelIdToLastNotifiedSizeMap) {
282
+ sizes.forEach((size, index) => {
283
+ const panelRef = panelsArray[index];
284
+ if (!panelRef) {
285
+ // Handle initial mount (when panels are registered too late to be in the panels array)
286
+ // The subsequent render+effects will handle the resize notification
287
+ return;
288
+ }
289
+ const {
290
+ callbacksRef,
291
+ collapsedSize,
292
+ collapsible,
293
+ id
294
+ } = panelRef.current;
295
+ const lastNotifiedSize = panelIdToLastNotifiedSizeMap[id];
296
+ if (lastNotifiedSize !== size) {
297
+ panelIdToLastNotifiedSizeMap[id] = size;
298
+ const {
299
+ onCollapse,
300
+ onResize
301
+ } = callbacksRef.current;
302
+ if (onResize) {
303
+ onResize(size, lastNotifiedSize);
304
+ }
305
+ if (collapsible && onCollapse) {
306
+ if ((lastNotifiedSize == null || lastNotifiedSize === collapsedSize) && size !== collapsedSize) {
307
+ onCollapse(false);
308
+ } else if (lastNotifiedSize !== collapsedSize && size === collapsedSize) {
309
+ onCollapse(true);
310
+ }
311
+ }
312
+ }
313
+ });
314
+ }
315
+ function calculateDefaultLayout({
316
+ groupId,
317
+ panels,
318
+ units
319
+ }) {
320
+ const groupSizePixels = units === "pixels" ? getAvailableGroupSizePixels(groupId) : NaN;
321
+ const panelsArray = panelsMapToSortedArray(panels);
322
+ const sizes = Array(panelsArray.length);
323
+ let numPanelsWithSizes = 0;
324
+ let remainingSize = 100;
325
+
326
+ // Assigning default sizes requires a couple of passes:
327
+ // First, all panels with defaultSize should be set as-is
328
+ for (let index = 0; index < panelsArray.length; index++) {
329
+ const panel = panelsArray[index];
330
+ const {
331
+ defaultSize
332
+ } = panel.current;
333
+ if (defaultSize != null) {
334
+ numPanelsWithSizes++;
335
+ sizes[index] = units === "pixels" ? defaultSize / groupSizePixels * 100 : defaultSize;
336
+ remainingSize -= sizes[index];
337
+ }
338
+ }
339
+
340
+ // Remaining total size should be distributed evenly between panels
341
+ // This may require two passes, depending on min/max constraints
342
+ for (let index = 0; index < panelsArray.length; index++) {
343
+ const panel = panelsArray[index];
344
+ let {
345
+ defaultSize,
346
+ id,
347
+ maxSize,
348
+ minSize
349
+ } = panel.current;
350
+ if (defaultSize != null) {
351
+ continue;
352
+ }
353
+ if (units === "pixels") {
354
+ minSize = minSize / groupSizePixels * 100;
355
+ if (maxSize != null) {
356
+ maxSize = maxSize / groupSizePixels * 100;
357
+ }
358
+ }
359
+ const remainingPanels = panelsArray.length - numPanelsWithSizes;
360
+ const size = Math.min(maxSize != null ? maxSize : 100, Math.max(minSize, remainingSize / remainingPanels));
361
+ sizes[index] = size;
362
+ numPanelsWithSizes++;
363
+ remainingSize -= size;
364
+ }
365
+
366
+ // If there is additional, left over space, assign it to any panel(s) that permits it
367
+ // (It's not worth taking multiple additional passes to evenly distribute)
368
+ if (remainingSize !== 0) {
369
+ for (let index = 0; index < panelsArray.length; index++) {
370
+ const panel = panelsArray[index];
371
+ let {
372
+ maxSize,
373
+ minSize
374
+ } = panel.current;
375
+ if (units === "pixels") {
376
+ minSize = minSize / groupSizePixels * 100;
377
+ if (maxSize != null) {
378
+ maxSize = maxSize / groupSizePixels * 100;
379
+ }
380
+ }
381
+ const size = Math.min(maxSize != null ? maxSize : 100, Math.max(minSize, sizes[index] + remainingSize));
382
+ if (size !== sizes[index]) {
383
+ remainingSize -= size - sizes[index];
384
+ sizes[index] = size;
385
+
386
+ // Fuzzy comparison to account for imprecise floating point math
387
+ if (Math.abs(remainingSize).toFixed(3) === "0.000") {
388
+ break;
389
+ }
390
+ }
391
+ }
392
+ }
393
+
394
+ // Finally, if there is still left-over size, log an error
395
+ if (Math.abs(remainingSize).toFixed(3) !== "0.000") {
396
+ {
397
+ console.error(`Invalid panel group configuration; default panel sizes should total 100% but was ${(100 - remainingSize).toFixed(1)}%. This can cause the cursor to become misaligned while dragging.`);
398
+ }
399
+ }
400
+ return sizes;
401
+ }
402
+ function getBeforeAndAfterIds(id, panelsArray) {
403
+ if (panelsArray.length < 2) {
404
+ return [null, null];
405
+ }
406
+ const index = panelsArray.findIndex(panel => panel.current.id === id);
407
+ if (index < 0) {
408
+ return [null, null];
409
+ }
410
+ const isLastPanel = index === panelsArray.length - 1;
411
+ const idBefore = isLastPanel ? panelsArray[index - 1].current.id : id;
412
+ const idAfter = isLastPanel ? id : panelsArray[index + 1].current.id;
413
+ return [idBefore, idAfter];
414
+ }
415
+ function getAvailableGroupSizePixels(groupId) {
416
+ const panelGroupElement = getPanelGroup(groupId);
417
+ if (panelGroupElement == null) {
418
+ return NaN;
419
+ }
420
+ const direction = panelGroupElement.getAttribute("data-panel-group-direction");
421
+ const resizeHandles = getResizeHandlesForGroup(groupId);
422
+ if (direction === "horizontal") {
423
+ return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
424
+ return accumulated + handle.offsetWidth;
425
+ }, 0);
426
+ } else {
427
+ return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
428
+ return accumulated + handle.offsetHeight;
429
+ }, 0);
430
+ }
431
+ }
432
+
433
+ // This method returns a number between 1 and 100 representing
434
+ // the % of the group's overall space this panel should occupy.
435
+ function getFlexGrow(panels, id, sizes) {
436
+ if (panels.size === 1) {
437
+ return "100";
438
+ }
439
+ const panelsArray = panelsMapToSortedArray(panels);
440
+ const index = panelsArray.findIndex(panel => panel.current.id === id);
441
+ const size = sizes[index];
442
+ if (size == null) {
443
+ return "0";
444
+ }
445
+ return size.toPrecision(PRECISION);
446
+ }
447
+ function getPanel(id) {
448
+ const element = document.querySelector(`[data-panel-id="${id}"]`);
449
+ if (element) {
450
+ return element;
451
+ }
452
+ return null;
453
+ }
454
+ function getPanelGroup(id) {
455
+ const element = document.querySelector(`[data-panel-group-id="${id}"]`);
456
+ if (element) {
457
+ return element;
458
+ }
459
+ return null;
460
+ }
461
+ function getResizeHandle(id) {
462
+ const element = document.querySelector(`[data-panel-resize-handle-id="${id}"]`);
463
+ if (element) {
464
+ return element;
465
+ }
466
+ return null;
467
+ }
468
+ function getResizeHandleIndex(id) {
469
+ const handles = getResizeHandles();
470
+ const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
471
+ return index ?? null;
472
+ }
473
+ function getResizeHandles() {
474
+ return Array.from(document.querySelectorAll(`[data-panel-resize-handle-id]`));
475
+ }
476
+ function getResizeHandlesForGroup(groupId) {
477
+ return Array.from(document.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
478
+ }
479
+ function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
480
+ const handle = getResizeHandle(handleId);
481
+ const handles = getResizeHandlesForGroup(groupId);
482
+ const index = handle ? handles.indexOf(handle) : -1;
483
+ const idBefore = panelsArray[index]?.current?.id ?? null;
484
+ const idAfter = panelsArray[index + 1]?.current?.id ?? null;
485
+ return [idBefore, idAfter];
486
+ }
487
+ function panelsMapToSortedArray(panels) {
488
+ return Array.from(panels.values()).sort((panelA, panelB) => {
489
+ const orderA = panelA.current.order;
490
+ const orderB = panelB.current.order;
491
+ if (orderA == null && orderB == null) {
492
+ return 0;
493
+ } else if (orderA == null) {
494
+ return -1;
495
+ } else if (orderB == null) {
496
+ return 1;
497
+ } else {
498
+ return orderA - orderB;
499
+ }
500
+ });
501
+ }
502
+ function safeResizePanel(units, groupSizePixels, panel, prevSize, nextSize, event = null) {
503
+ let {
504
+ collapsedSize,
505
+ collapsible,
506
+ maxSize,
507
+ minSize
508
+ } = panel.current;
509
+ if (units === "pixels") {
510
+ collapsedSize = collapsedSize / groupSizePixels * 100;
511
+ if (maxSize != null) {
512
+ maxSize = maxSize / groupSizePixels * 100;
513
+ }
514
+ minSize = minSize / groupSizePixels * 100;
515
+ }
516
+ if (collapsible) {
517
+ if (prevSize > collapsedSize) {
518
+ // Mimic VS COde behavior; collapse a panel if it's smaller than half of its min-size
519
+ if (nextSize <= minSize / 2 + collapsedSize) {
520
+ return collapsedSize;
521
+ }
522
+ } else {
523
+ const isKeyboardEvent = event?.type?.startsWith("key");
524
+ if (!isKeyboardEvent) {
525
+ // Keyboard events should expand a collapsed panel to the min size,
526
+ // but mouse events should wait until the panel has reached its min size
527
+ // to avoid a visual flickering when dragging between collapsed and min size.
528
+ if (nextSize < minSize) {
529
+ return collapsedSize;
530
+ }
531
+ }
532
+ }
533
+ }
534
+ return Math.min(maxSize != null ? maxSize : 100, Math.max(minSize, nextSize));
535
+ }
536
+ function validatePanelProps(units, panelData) {
537
+ const {
538
+ collapsible,
539
+ defaultSize,
540
+ maxSize,
541
+ minSize
542
+ } = panelData.current;
543
+
544
+ // Basic props validation
545
+ if (minSize < 0 || units === "percentages" && minSize > 100) {
546
+ {
547
+ console.error(`Invalid Panel minSize provided, ${minSize}`);
548
+ }
549
+ panelData.current.minSize = 0;
550
+ }
551
+ if (maxSize != null) {
552
+ if (maxSize < 0 || units === "percentages" && maxSize > 100) {
553
+ {
554
+ console.error(`Invalid Panel maxSize provided, ${maxSize}`);
555
+ }
556
+ panelData.current.maxSize = null;
557
+ }
558
+ }
559
+ if (defaultSize !== null) {
560
+ if (defaultSize < 0 || units === "percentages" && defaultSize > 100) {
561
+ {
562
+ console.error(`Invalid Panel defaultSize provided, ${defaultSize}`);
563
+ }
564
+ panelData.current.defaultSize = null;
565
+ } else if (defaultSize < minSize && !collapsible) {
566
+ {
567
+ console.error(`Panel minSize (${minSize}) cannot be greater than defaultSize (${defaultSize})`);
568
+ }
569
+ panelData.current.defaultSize = minSize;
570
+ } else if (maxSize != null && defaultSize > maxSize) {
571
+ {
572
+ console.error(`Panel maxSize (${maxSize}) cannot be less than defaultSize (${defaultSize})`);
573
+ }
574
+ panelData.current.defaultSize = maxSize;
575
+ }
576
+ }
577
+ }
578
+ function validatePanelGroupLayout({
579
+ groupId,
580
+ panels,
581
+ nextSizes,
582
+ prevSizes,
583
+ units
584
+ }) {
585
+ // Clone because this method modifies
586
+ nextSizes = [...nextSizes];
587
+ const panelsArray = panelsMapToSortedArray(panels);
588
+ const groupSizePixels = units === "pixels" ? getAvailableGroupSizePixels(groupId) : NaN;
589
+ let remainingSize = 0;
590
+
591
+ // First, check all of the proposed sizes against the min/max constraints
592
+ for (let index = 0; index < panelsArray.length; index++) {
593
+ const panel = panelsArray[index];
594
+ const prevSize = prevSizes[index];
595
+ const nextSize = nextSizes[index];
596
+ const safeNextSize = safeResizePanel(units, groupSizePixels, panel, prevSize, nextSize);
597
+ if (nextSize != safeNextSize) {
598
+ remainingSize += nextSize - safeNextSize;
599
+ nextSizes[index] = safeNextSize;
600
+ {
601
+ console.error(`Invalid size (${nextSize}) specified for Panel "${panel.current.id}" given the panel's min/max size constraints`);
602
+ }
603
+ }
604
+ }
605
+
606
+ // If there is additional, left over space, assign it to any panel(s) that permits it
607
+ // (It's not worth taking multiple additional passes to evenly distribute)
608
+ if (remainingSize.toFixed(3) !== "0.000") {
609
+ for (let index = 0; index < panelsArray.length; index++) {
610
+ const panel = panelsArray[index];
611
+ let {
612
+ maxSize,
613
+ minSize
614
+ } = panel.current;
615
+ if (units === "pixels") {
616
+ minSize = minSize / groupSizePixels * 100;
617
+ if (maxSize != null) {
618
+ maxSize = maxSize / groupSizePixels * 100;
619
+ }
620
+ }
621
+ const size = Math.min(maxSize != null ? maxSize : 100, Math.max(minSize, nextSizes[index] + remainingSize));
622
+ if (size !== nextSizes[index]) {
623
+ remainingSize -= size - nextSizes[index];
624
+ nextSizes[index] = size;
625
+
626
+ // Fuzzy comparison to account for imprecise floating point math
627
+ if (Math.abs(remainingSize).toFixed(3) === "0.000") {
628
+ break;
629
+ }
630
+ }
631
+ }
632
+ }
633
+
634
+ // If we still have remainder, the requested layout wasn't valid and we should warn about it
635
+ if (remainingSize.toFixed(3) !== "0.000") {
636
+ {
637
+ console.error(`"Invalid panel group configuration; default panel sizes should total 100% but was ${100 - remainingSize}%`);
638
+ }
639
+ }
640
+ return nextSizes;
641
+ }
642
+
643
+ function assert(expectedCondition, message = "Assertion failed!") {
644
+ if (!expectedCondition) {
645
+ console.error(message);
646
+ throw Error(message);
647
+ }
648
+ }
649
+
650
+ // https://www.w3.org/WAI/ARIA/apg/patterns/windowsplitter/
651
+
652
+ function useWindowSplitterPanelGroupBehavior({
653
+ committedValuesRef,
654
+ groupId,
655
+ panels,
656
+ setSizes,
657
+ sizes,
658
+ panelSizeBeforeCollapse
659
+ }) {
660
+ useEffect(() => {
661
+ const {
662
+ direction,
663
+ panels
664
+ } = committedValuesRef.current;
665
+ const groupElement = getPanelGroup(groupId);
666
+ assert(groupElement != null, `No group found for id "${groupId}"`);
667
+ const {
668
+ height,
669
+ width
670
+ } = groupElement.getBoundingClientRect();
671
+ const handles = getResizeHandlesForGroup(groupId);
672
+ const cleanupFunctions = handles.map(handle => {
673
+ const handleId = handle.getAttribute("data-panel-resize-handle-id");
674
+ const panelsArray = panelsMapToSortedArray(panels);
675
+ const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelsArray);
676
+ if (idBefore == null || idAfter == null) {
677
+ return () => {};
678
+ }
679
+ let currentMinSize = 0;
680
+ let currentMaxSize = 100;
681
+ let totalMinSize = 0;
682
+ let totalMaxSize = 0;
683
+
684
+ // A panel's effective min/max sizes also need to account for other panel's sizes.
685
+ panelsArray.forEach(panelData => {
686
+ const {
687
+ id,
688
+ maxSize,
689
+ minSize
690
+ } = panelData.current;
691
+ if (id === idBefore) {
692
+ currentMinSize = minSize;
693
+ currentMaxSize = maxSize != null ? maxSize : 100;
694
+ } else {
695
+ totalMinSize += minSize;
696
+ totalMaxSize += maxSize != null ? maxSize : 100;
697
+ }
698
+ });
699
+ const ariaValueMax = Math.min(currentMaxSize, 100 - totalMinSize);
700
+ const ariaValueMin = Math.max(currentMinSize, (panelsArray.length - 1) * 100 - totalMaxSize);
701
+ const flexGrow = getFlexGrow(panels, idBefore, sizes);
702
+ handle.setAttribute("aria-valuemax", "" + Math.round(ariaValueMax));
703
+ handle.setAttribute("aria-valuemin", "" + Math.round(ariaValueMin));
704
+ handle.setAttribute("aria-valuenow", "" + Math.round(parseInt(flexGrow)));
705
+ const onKeyDown = event => {
706
+ if (event.defaultPrevented) {
707
+ return;
708
+ }
709
+ switch (event.key) {
710
+ case "Enter":
711
+ {
712
+ event.preventDefault();
713
+ const index = panelsArray.findIndex(panel => panel.current.id === idBefore);
714
+ if (index >= 0) {
715
+ const panelData = panelsArray[index];
716
+ const size = sizes[index];
717
+ if (size != null) {
718
+ let delta = 0;
719
+ if (size.toPrecision(PRECISION) <= panelData.current.minSize.toPrecision(PRECISION)) {
720
+ delta = direction === "horizontal" ? width : height;
721
+ } else {
722
+ delta = -(direction === "horizontal" ? width : height);
723
+ }
724
+ const nextSizes = adjustByDelta(event, committedValuesRef.current, idBefore, idAfter, delta, sizes, panelSizeBeforeCollapse.current, null);
725
+ if (sizes !== nextSizes) {
726
+ setSizes(nextSizes);
727
+ }
728
+ }
729
+ }
730
+ break;
731
+ }
732
+ }
733
+ };
734
+ handle.addEventListener("keydown", onKeyDown);
735
+ const panelBefore = getPanel(idBefore);
736
+ if (panelBefore != null) {
737
+ handle.setAttribute("aria-controls", panelBefore.id);
738
+ }
739
+ return () => {
740
+ handle.removeAttribute("aria-valuemax");
741
+ handle.removeAttribute("aria-valuemin");
742
+ handle.removeAttribute("aria-valuenow");
743
+ handle.removeEventListener("keydown", onKeyDown);
744
+ if (panelBefore != null) {
745
+ handle.removeAttribute("aria-controls");
746
+ }
747
+ };
748
+ });
749
+ return () => {
750
+ cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
751
+ };
752
+ }, [committedValuesRef, groupId, panels, panelSizeBeforeCollapse, setSizes, sizes]);
753
+ }
754
+ function useWindowSplitterResizeHandlerBehavior({
755
+ disabled,
756
+ handleId,
757
+ resizeHandler
758
+ }) {
759
+ useEffect(() => {
760
+ if (disabled || resizeHandler == null) {
761
+ return;
762
+ }
763
+ const handleElement = getResizeHandle(handleId);
764
+ if (handleElement == null) {
765
+ return;
766
+ }
767
+ const onKeyDown = event => {
768
+ if (event.defaultPrevented) {
769
+ return;
770
+ }
771
+ switch (event.key) {
772
+ case "ArrowDown":
773
+ case "ArrowLeft":
774
+ case "ArrowRight":
775
+ case "ArrowUp":
776
+ case "End":
777
+ case "Home":
778
+ {
779
+ event.preventDefault();
780
+ resizeHandler(event);
781
+ break;
782
+ }
783
+ case "F6":
784
+ {
785
+ event.preventDefault();
786
+ const handles = getResizeHandles();
787
+ const index = getResizeHandleIndex(handleId);
788
+ assert(index !== null);
789
+ const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
790
+ const nextHandle = handles[nextIndex];
791
+ nextHandle.focus();
792
+ break;
793
+ }
794
+ }
795
+ };
796
+ handleElement.addEventListener("keydown", onKeyDown);
797
+ return () => {
798
+ handleElement.removeEventListener("keydown", onKeyDown);
799
+ };
800
+ }, [disabled, handleId, resizeHandler]);
801
+ }
802
+
803
+ function areEqual(arrayA, arrayB) {
804
+ if (arrayA.length !== arrayB.length) {
805
+ return false;
806
+ }
807
+ for (let index = 0; index < arrayA.length; index++) {
808
+ if (arrayA[index] !== arrayB[index]) {
809
+ return false;
810
+ }
811
+ }
812
+ return true;
813
+ }
814
+
815
+ function getDragOffset(event, handleId, direction, initialOffset = 0, initialHandleElementRect = null) {
816
+ const isHorizontal = direction === "horizontal";
817
+ let pointerOffset = 0;
818
+ if (isMouseEvent(event)) {
819
+ pointerOffset = isHorizontal ? event.clientX : event.clientY;
820
+ } else if (isTouchEvent(event)) {
821
+ const firstTouch = event.touches[0];
822
+ pointerOffset = isHorizontal ? firstTouch.screenX : firstTouch.screenY;
823
+ } else {
824
+ return 0;
825
+ }
826
+ const handleElement = getResizeHandle(handleId);
827
+ const rect = initialHandleElementRect || handleElement.getBoundingClientRect();
828
+ const elementOffset = isHorizontal ? rect.left : rect.top;
829
+ return pointerOffset - elementOffset - initialOffset;
830
+ }
831
+
832
+ // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX
833
+ function getMovement(event, groupId, handleId, panelsArray, direction, prevSizes, initialDragState) {
834
+ const {
835
+ dragOffset = 0,
836
+ dragHandleRect,
837
+ sizes: initialSizes
838
+ } = initialDragState || {};
839
+
840
+ // If we're resizing by mouse or touch, use the initial sizes as a base.
841
+ // This has the benefit of causing force-collapsed panels to spring back open if drag is reversed.
842
+ const baseSizes = initialSizes || prevSizes;
843
+ if (isKeyDown(event)) {
844
+ const isHorizontal = direction === "horizontal";
845
+ const groupElement = getPanelGroup(groupId);
846
+ const rect = groupElement.getBoundingClientRect();
847
+ const groupSizeInPixels = isHorizontal ? rect.width : rect.height;
848
+ const denominator = event.shiftKey ? 10 : 100;
849
+ const delta = groupSizeInPixels / denominator;
850
+ let movement = 0;
851
+ switch (event.key) {
852
+ case "ArrowDown":
853
+ movement = isHorizontal ? 0 : delta;
854
+ break;
855
+ case "ArrowLeft":
856
+ movement = isHorizontal ? -delta : 0;
857
+ break;
858
+ case "ArrowRight":
859
+ movement = isHorizontal ? delta : 0;
860
+ break;
861
+ case "ArrowUp":
862
+ movement = isHorizontal ? 0 : -delta;
863
+ break;
864
+ case "End":
865
+ movement = groupSizeInPixels;
866
+ break;
867
+ case "Home":
868
+ movement = -groupSizeInPixels;
869
+ break;
870
+ }
871
+
872
+ // If the Panel being resized is collapsible,
873
+ // we need to special case resizing around the minSize boundary.
874
+ // If contracting, Panels should shrink to their minSize and then snap to fully collapsed.
875
+ // If expanding from collapsed, they should snap back to their minSize.
876
+ const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelsArray);
877
+ const targetPanelId = movement < 0 ? idBefore : idAfter;
878
+ const targetPanelIndex = panelsArray.findIndex(panel => panel.current.id === targetPanelId);
879
+ const targetPanel = panelsArray[targetPanelIndex];
880
+ if (targetPanel.current.collapsible) {
881
+ const baseSize = baseSizes[targetPanelIndex];
882
+ if (baseSize === 0 || baseSize.toPrecision(PRECISION) === targetPanel.current.minSize.toPrecision(PRECISION)) {
883
+ movement = movement < 0 ? -targetPanel.current.minSize * groupSizeInPixels : targetPanel.current.minSize * groupSizeInPixels;
884
+ }
885
+ }
886
+ return movement;
887
+ } else {
888
+ return getDragOffset(event, handleId, direction, dragOffset, dragHandleRect);
889
+ }
890
+ }
891
+ function isKeyDown(event) {
892
+ return event.type === "keydown";
893
+ }
894
+ function isMouseEvent(event) {
895
+ return event.type.startsWith("mouse");
896
+ }
897
+ function isTouchEvent(event) {
898
+ return event.type.startsWith("touch");
899
+ }
900
+
901
+ let currentState = null;
902
+ let element = null;
903
+ function getCursorStyle(state) {
904
+ switch (state) {
905
+ case "horizontal":
906
+ return "ew-resize";
907
+ case "horizontal-max":
908
+ return "w-resize";
909
+ case "horizontal-min":
910
+ return "e-resize";
911
+ case "vertical":
912
+ return "ns-resize";
913
+ case "vertical-max":
914
+ return "n-resize";
915
+ case "vertical-min":
916
+ return "s-resize";
917
+ }
918
+ }
919
+ function resetGlobalCursorStyle() {
920
+ if (element !== null) {
921
+ document.head.removeChild(element);
922
+ currentState = null;
923
+ element = null;
924
+ }
925
+ }
926
+ function setGlobalCursorStyle(state) {
927
+ if (currentState === state) {
928
+ return;
929
+ }
930
+ currentState = state;
931
+ const style = getCursorStyle(state);
932
+ if (element === null) {
933
+ element = document.createElement("style");
934
+ document.head.appendChild(element);
935
+ }
936
+ element.innerHTML = `*{cursor: ${style}!important;}`;
937
+ }
938
+
939
+ function debounce(callback, durationMs = 10) {
940
+ let timeoutId = null;
941
+ let callable = (...args) => {
942
+ if (timeoutId !== null) {
943
+ clearTimeout(timeoutId);
944
+ }
945
+ timeoutId = setTimeout(() => {
946
+ callback(...args);
947
+ }, durationMs);
948
+ };
949
+ return callable;
950
+ }
951
+
952
+ // Note that Panel ids might be user-provided (stable) or useId generated (non-deterministic)
953
+ // so they should not be used as part of the serialization key.
954
+ // Using an attribute like minSize instead should work well enough.
955
+ // Pre-sorting by minSize allows remembering layouts even if panels are re-ordered/dragged.
956
+ function getSerializationKey(panels) {
957
+ return panels.map(panel => {
958
+ const {
959
+ minSize,
960
+ order
961
+ } = panel.current;
962
+ return order ? `${order}:${minSize}` : `${minSize}`;
963
+ }).sort((a, b) => a.localeCompare(b)).join(",");
964
+ }
965
+ function loadSerializedPanelGroupState(autoSaveId, storage) {
966
+ try {
967
+ const serialized = storage.getItem(`PanelGroup:sizes:${autoSaveId}`);
968
+ if (serialized) {
969
+ const parsed = JSON.parse(serialized);
970
+ if (typeof parsed === "object" && parsed != null) {
971
+ return parsed;
972
+ }
973
+ }
974
+ } catch (error) {}
975
+ return null;
976
+ }
977
+ function loadPanelLayout(autoSaveId, panels, storage) {
978
+ const state = loadSerializedPanelGroupState(autoSaveId, storage);
979
+ if (state) {
980
+ const key = getSerializationKey(panels);
981
+ return state[key] ?? null;
982
+ }
983
+ return null;
984
+ }
985
+ function savePanelGroupLayout(autoSaveId, panels, sizes, storage) {
986
+ const key = getSerializationKey(panels);
987
+ const state = loadSerializedPanelGroupState(autoSaveId, storage) || {};
988
+ state[key] = sizes;
989
+ try {
990
+ storage.setItem(`PanelGroup:sizes:${autoSaveId}`, JSON.stringify(state));
991
+ } catch (error) {
992
+ console.error(error);
993
+ }
994
+ }
995
+
996
+ const debounceMap = {};
997
+
998
+ // PanelGroup might be rendering in a server-side environment where localStorage is not available
999
+ // or on a browser with cookies/storage disabled.
1000
+ // In either case, this function avoids accessing localStorage until needed,
1001
+ // and avoids throwing user-visible errors.
1002
+ function initializeDefaultStorage(storageObject) {
1003
+ try {
1004
+ if (typeof localStorage !== "undefined") {
1005
+ // Bypass this check for future calls
1006
+ storageObject.getItem = name => {
1007
+ return localStorage.getItem(name);
1008
+ };
1009
+ storageObject.setItem = (name, value) => {
1010
+ localStorage.setItem(name, value);
1011
+ };
1012
+ } else {
1013
+ throw new Error("localStorage not supported in this environment");
1014
+ }
1015
+ } catch (error) {
1016
+ console.error(error);
1017
+ storageObject.getItem = () => null;
1018
+ storageObject.setItem = () => {};
1019
+ }
1020
+ }
1021
+ const defaultStorage = {
1022
+ getItem: name => {
1023
+ initializeDefaultStorage(defaultStorage);
1024
+ return defaultStorage.getItem(name);
1025
+ },
1026
+ setItem: (name, value) => {
1027
+ initializeDefaultStorage(defaultStorage);
1028
+ defaultStorage.setItem(name, value);
1029
+ }
1030
+ };
1031
+
1032
+ // Initial drag state serves a few purposes:
1033
+ // * dragOffset:
1034
+ // Resize is calculated by the distance between the current pointer event and the resize handle being "dragged"
1035
+ // This value accounts for the initial offset when the touch/click starts, so the handle doesn't appear to "jump"
1036
+ // * dragHandleRect, sizes:
1037
+ // When resizing is done via mouse/touch event– some initial state is stored
1038
+ // so that any panels that contract will also expand if drag direction is reversed.
1039
+ function PanelGroupWithForwardedRef({
1040
+ autoSaveId,
1041
+ children = null,
1042
+ className: classNameFromProps = "",
1043
+ direction,
1044
+ disablePointerEventsDuringResize = false,
1045
+ forwardedRef,
1046
+ id: idFromProps = null,
1047
+ onLayout,
1048
+ storage = defaultStorage,
1049
+ style: styleFromProps = {},
1050
+ tagName: Type = "div",
1051
+ units = "percentages"
1052
+ }) {
1053
+ const groupId = useUniqueId(idFromProps);
1054
+ const [activeHandleId, setActiveHandleId] = useState(null);
1055
+ const [panels, setPanels] = useState(new Map());
1056
+
1057
+ // When resizing is done via mouse/touch event–
1058
+ // We store the initial Panel sizes in this ref, and apply move deltas to them instead of to the current sizes.
1059
+ // This has the benefit of causing force-collapsed panels to spring back open if drag is reversed.
1060
+ const initialDragStateRef = useRef(null);
1061
+ const devWarningsRef = useRef({
1062
+ didLogDefaultSizeWarning: false,
1063
+ didLogIdAndOrderWarning: false,
1064
+ didLogInvalidLayoutWarning: false,
1065
+ prevPanelIds: []
1066
+ });
1067
+
1068
+ // Use a ref to guard against users passing inline props
1069
+ const callbacksRef = useRef({
1070
+ onLayout
1071
+ });
1072
+ useEffect(() => {
1073
+ callbacksRef.current.onLayout = onLayout;
1074
+ });
1075
+ const panelIdToLastNotifiedSizeMapRef = useRef({});
1076
+
1077
+ // 0-1 values representing the relative size of each panel.
1078
+ const [sizes, setSizes] = useState([]);
1079
+
1080
+ // Used to support imperative collapse/expand API.
1081
+ const panelSizeBeforeCollapse = useRef(new Map());
1082
+ const prevDeltaRef = useRef(0);
1083
+
1084
+ // Store committed values to avoid unnecessarily re-running memoization/effects functions.
1085
+ const committedValuesRef = useRef({
1086
+ direction,
1087
+ id: groupId,
1088
+ panels,
1089
+ sizes,
1090
+ units
1091
+ });
1092
+ useImperativeHandle(forwardedRef, () => ({
1093
+ getId: () => groupId,
1094
+ getLayout: unitsFromParams => {
1095
+ const {
1096
+ sizes,
1097
+ units: unitsFromProps
1098
+ } = committedValuesRef.current;
1099
+ const units = unitsFromParams ?? unitsFromProps;
1100
+ if (units === "pixels") {
1101
+ const groupSizePixels = getAvailableGroupSizePixels(groupId);
1102
+ return sizes.map(size => size / 100 * groupSizePixels);
1103
+ } else {
1104
+ return sizes;
1105
+ }
1106
+ },
1107
+ setLayout: (sizes, unitsFromParams) => {
1108
+ const {
1109
+ id: groupId,
1110
+ panels,
1111
+ sizes: prevSizes,
1112
+ units
1113
+ } = committedValuesRef.current;
1114
+ if ((unitsFromParams || units) === "pixels") {
1115
+ const groupSizePixels = getAvailableGroupSizePixels(groupId);
1116
+ sizes = sizes.map(size => size / groupSizePixels * 100);
1117
+ }
1118
+ const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
1119
+ const panelsArray = panelsMapToSortedArray(panels);
1120
+ const nextSizes = validatePanelGroupLayout({
1121
+ groupId,
1122
+ panels,
1123
+ nextSizes: sizes,
1124
+ prevSizes,
1125
+ units
1126
+ });
1127
+ if (!areEqual(prevSizes, nextSizes)) {
1128
+ setSizes(nextSizes);
1129
+ callPanelCallbacks(panelsArray, nextSizes, panelIdToLastNotifiedSizeMap);
1130
+ }
1131
+ }
1132
+ }), [groupId]);
1133
+ useIsomorphicLayoutEffect(() => {
1134
+ committedValuesRef.current.direction = direction;
1135
+ committedValuesRef.current.id = groupId;
1136
+ committedValuesRef.current.panels = panels;
1137
+ committedValuesRef.current.sizes = sizes;
1138
+ committedValuesRef.current.units = units;
1139
+ });
1140
+ useWindowSplitterPanelGroupBehavior({
1141
+ committedValuesRef,
1142
+ groupId,
1143
+ panels,
1144
+ setSizes,
1145
+ sizes,
1146
+ panelSizeBeforeCollapse
1147
+ });
1148
+
1149
+ // Notify external code when sizes have changed.
1150
+ useEffect(() => {
1151
+ const {
1152
+ onLayout
1153
+ } = callbacksRef.current;
1154
+ const {
1155
+ panels,
1156
+ sizes
1157
+ } = committedValuesRef.current;
1158
+
1159
+ // Don't commit layout until all panels have registered and re-rendered with their actual sizes.
1160
+ if (sizes.length > 0) {
1161
+ if (onLayout) {
1162
+ onLayout(sizes);
1163
+ }
1164
+ const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
1165
+
1166
+ // When possible, we notify before the next render so that rendering work can be batched together.
1167
+ // Some cases are difficult to detect though,
1168
+ // for example– panels that are conditionally rendered can affect the size of neighboring panels.
1169
+ // In this case, the best we can do is notify on commit.
1170
+ // The callPanelCallbacks() uses its own memoization to avoid notifying panels twice in these cases.
1171
+ const panelsArray = panelsMapToSortedArray(panels);
1172
+ callPanelCallbacks(panelsArray, sizes, panelIdToLastNotifiedSizeMap);
1173
+ }
1174
+ }, [sizes]);
1175
+
1176
+ // Once all panels have registered themselves,
1177
+ // Compute the initial sizes based on default weights.
1178
+ // This assumes that panels register during initial mount (no conditional rendering)!
1179
+ useIsomorphicLayoutEffect(() => {
1180
+ const {
1181
+ id: groupId,
1182
+ sizes,
1183
+ units
1184
+ } = committedValuesRef.current;
1185
+ if (sizes.length === panels.size) {
1186
+ // Only compute (or restore) default sizes once per panel configuration.
1187
+ return;
1188
+ }
1189
+
1190
+ // If this panel has been configured to persist sizing information,
1191
+ // default size should be restored from local storage if possible.
1192
+ let defaultSizes = null;
1193
+ if (autoSaveId) {
1194
+ const panelsArray = panelsMapToSortedArray(panels);
1195
+ defaultSizes = loadPanelLayout(autoSaveId, panelsArray, storage);
1196
+ }
1197
+ if (defaultSizes != null) {
1198
+ // Validate saved sizes in case something has changed since last render
1199
+ // e.g. for pixel groups, this could be the size of the window
1200
+ const validatedSizes = validatePanelGroupLayout({
1201
+ groupId,
1202
+ panels,
1203
+ nextSizes: defaultSizes,
1204
+ prevSizes: defaultSizes,
1205
+ units
1206
+ });
1207
+ setSizes(validatedSizes);
1208
+ } else {
1209
+ const sizes = calculateDefaultLayout({
1210
+ groupId,
1211
+ panels,
1212
+ units
1213
+ });
1214
+ setSizes(sizes);
1215
+ }
1216
+ }, [autoSaveId, panels, storage]);
1217
+ useEffect(() => {
1218
+ // If this panel has been configured to persist sizing information, save sizes to local storage.
1219
+ if (autoSaveId) {
1220
+ if (sizes.length === 0 || sizes.length !== panels.size) {
1221
+ return;
1222
+ }
1223
+ const panelsArray = panelsMapToSortedArray(panels);
1224
+
1225
+ // Limit the frequency of localStorage updates.
1226
+ if (!debounceMap[autoSaveId]) {
1227
+ debounceMap[autoSaveId] = debounce(savePanelGroupLayout, 100);
1228
+ }
1229
+ debounceMap[autoSaveId](autoSaveId, panelsArray, sizes, storage);
1230
+ }
1231
+ {
1232
+ const {
1233
+ didLogIdAndOrderWarning,
1234
+ prevPanelIds
1235
+ } = devWarningsRef.current;
1236
+ if (!didLogIdAndOrderWarning) {
1237
+ const {
1238
+ panels
1239
+ } = committedValuesRef.current;
1240
+ const panelIds = Array.from(panels.keys());
1241
+ devWarningsRef.current.prevPanelIds = panelIds;
1242
+ const panelsHaveChanged = prevPanelIds.length > 0 && !areEqual(prevPanelIds, panelIds);
1243
+ if (panelsHaveChanged) {
1244
+ if (Array.from(panels.values()).find(panel => panel.current.idWasAutoGenerated || panel.current.order == null)) {
1245
+ devWarningsRef.current.didLogIdAndOrderWarning = true;
1246
+ console.warn(`WARNING: Panel id and order props recommended when panels are dynamically rendered`);
1247
+ }
1248
+ }
1249
+ }
1250
+ }
1251
+ }, [autoSaveId, panels, sizes, storage]);
1252
+ useIsomorphicLayoutEffect(() => {
1253
+ // Pixel panel constraints need to be reassessed after a group resize
1254
+ // We can avoid the ResizeObserver overhead for relative layouts
1255
+ if (units === "pixels") {
1256
+ const resizeObserver = new ResizeObserver(() => {
1257
+ const {
1258
+ panels,
1259
+ sizes: prevSizes
1260
+ } = committedValuesRef.current;
1261
+ const nextSizes = validatePanelGroupLayout({
1262
+ groupId,
1263
+ panels,
1264
+ nextSizes: prevSizes,
1265
+ prevSizes,
1266
+ units
1267
+ });
1268
+ if (!areEqual(prevSizes, nextSizes)) {
1269
+ setSizes(nextSizes);
1270
+ }
1271
+ });
1272
+ resizeObserver.observe(getPanelGroup(groupId));
1273
+ return () => {
1274
+ resizeObserver.disconnect();
1275
+ };
1276
+ }
1277
+ }, [groupId, units]);
1278
+ const getPanelSize = useCallback((id, unitsFromParams) => {
1279
+ const {
1280
+ panels,
1281
+ units: unitsFromProps
1282
+ } = committedValuesRef.current;
1283
+ const panelsArray = panelsMapToSortedArray(panels);
1284
+ const index = panelsArray.findIndex(panel => panel.current.id === id);
1285
+ const size = sizes[index];
1286
+ const units = unitsFromParams ?? unitsFromProps;
1287
+ if (units === "pixels") {
1288
+ const groupSizePixels = getAvailableGroupSizePixels(groupId);
1289
+ return size / 100 * groupSizePixels;
1290
+ } else {
1291
+ return size;
1292
+ }
1293
+ }, [groupId, sizes]);
1294
+ const getPanelStyle = useCallback((id, defaultSize) => {
1295
+ const {
1296
+ panels
1297
+ } = committedValuesRef.current;
1298
+
1299
+ // Before mounting, Panels will not yet have registered themselves.
1300
+ // This includes server rendering.
1301
+ // At this point the best we can do is render everything with the same size.
1302
+ if (panels.size === 0) {
1303
+ {
1304
+ if (!devWarningsRef.current.didLogDefaultSizeWarning) ;
1305
+ }
1306
+ return {
1307
+ flexBasis: 0,
1308
+ flexGrow: defaultSize != null ? defaultSize : undefined,
1309
+ flexShrink: 1,
1310
+ // Without this, Panel sizes may be unintentionally overridden by their content.
1311
+ overflow: "hidden"
1312
+ };
1313
+ }
1314
+ const flexGrow = getFlexGrow(panels, id, sizes);
1315
+ return {
1316
+ flexBasis: 0,
1317
+ flexGrow,
1318
+ flexShrink: 1,
1319
+ // Without this, Panel sizes may be unintentionally overridden by their content.
1320
+ overflow: "hidden",
1321
+ // Disable pointer events inside of a panel during resize.
1322
+ // This avoid edge cases like nested iframes.
1323
+ pointerEvents: disablePointerEventsDuringResize && activeHandleId !== null ? "none" : undefined
1324
+ };
1325
+ }, [activeHandleId, disablePointerEventsDuringResize, sizes]);
1326
+ const registerPanel = useCallback((id, panelRef) => {
1327
+ const {
1328
+ units
1329
+ } = committedValuesRef.current;
1330
+ validatePanelProps(units, panelRef);
1331
+ setPanels(prevPanels => {
1332
+ if (prevPanels.has(id)) {
1333
+ return prevPanels;
1334
+ }
1335
+ const nextPanels = new Map(prevPanels);
1336
+ nextPanels.set(id, panelRef);
1337
+ return nextPanels;
1338
+ });
1339
+ }, []);
1340
+ const registerResizeHandle = useCallback(handleId => {
1341
+ const resizeHandler = event => {
1342
+ event.preventDefault();
1343
+ const {
1344
+ direction,
1345
+ panels,
1346
+ sizes: prevSizes
1347
+ } = committedValuesRef.current;
1348
+ const panelsArray = panelsMapToSortedArray(panels);
1349
+ const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelsArray);
1350
+ if (idBefore == null || idAfter == null) {
1351
+ return;
1352
+ }
1353
+ let movement = getMovement(event, groupId, handleId, panelsArray, direction, prevSizes, initialDragStateRef.current);
1354
+ if (movement === 0) {
1355
+ return;
1356
+ }
1357
+ const groupElement = getPanelGroup(groupId);
1358
+ const rect = groupElement.getBoundingClientRect();
1359
+ const isHorizontal = direction === "horizontal";
1360
+
1361
+ // Support RTL layouts
1362
+ if (document.dir === "rtl" && isHorizontal) {
1363
+ movement = -movement;
1364
+ }
1365
+ const size = isHorizontal ? rect.width : rect.height;
1366
+ const delta = movement / size * 100;
1367
+
1368
+ // If a validateLayout method has been provided
1369
+ // it's important to use it before updating the mouse cursor
1370
+ const nextSizes = adjustByDelta(event, committedValuesRef.current, idBefore, idAfter, delta, prevSizes, panelSizeBeforeCollapse.current, initialDragStateRef.current);
1371
+ const sizesChanged = !areEqual(prevSizes, nextSizes);
1372
+
1373
+ // Don't update cursor for resizes triggered by keyboard interactions.
1374
+ if (isMouseEvent(event) || isTouchEvent(event)) {
1375
+ // Watch for multiple subsequent deltas; this might occur for tiny cursor movements.
1376
+ // In this case, Panel sizes might not change–
1377
+ // but updating cursor in this scenario would cause a flicker.
1378
+ if (prevDeltaRef.current != delta) {
1379
+ if (!sizesChanged) {
1380
+ // If the pointer has moved too far to resize the panel any further,
1381
+ // update the cursor style for a visual clue.
1382
+ // This mimics VS Code behavior.
1383
+
1384
+ if (isHorizontal) {
1385
+ setGlobalCursorStyle(movement < 0 ? "horizontal-min" : "horizontal-max");
1386
+ } else {
1387
+ setGlobalCursorStyle(movement < 0 ? "vertical-min" : "vertical-max");
1388
+ }
1389
+ } else {
1390
+ // Reset the cursor style to the the normal resize cursor.
1391
+ setGlobalCursorStyle(isHorizontal ? "horizontal" : "vertical");
1392
+ }
1393
+ }
1394
+ }
1395
+ if (sizesChanged) {
1396
+ const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
1397
+
1398
+ // It's okay to bypass in this case because we already validated above
1399
+ setSizes(nextSizes);
1400
+
1401
+ // If resize change handlers have been declared, this is the time to call them.
1402
+ // Trigger user callbacks after updating state, so that user code can override the sizes.
1403
+ callPanelCallbacks(panelsArray, nextSizes, panelIdToLastNotifiedSizeMap);
1404
+ }
1405
+ prevDeltaRef.current = delta;
1406
+ };
1407
+ return resizeHandler;
1408
+ }, [groupId]);
1409
+ const unregisterPanel = useCallback(id => {
1410
+ setPanels(prevPanels => {
1411
+ if (!prevPanels.has(id)) {
1412
+ return prevPanels;
1413
+ }
1414
+ const nextPanels = new Map(prevPanels);
1415
+ nextPanels.delete(id);
1416
+ return nextPanels;
1417
+ });
1418
+ }, []);
1419
+ const collapsePanel = useCallback(id => {
1420
+ const {
1421
+ panels,
1422
+ sizes: prevSizes
1423
+ } = committedValuesRef.current;
1424
+ const panel = panels.get(id);
1425
+ if (panel == null) {
1426
+ return;
1427
+ }
1428
+ const {
1429
+ collapsedSize,
1430
+ collapsible
1431
+ } = panel.current;
1432
+ if (!collapsible) {
1433
+ return;
1434
+ }
1435
+ const panelsArray = panelsMapToSortedArray(panels);
1436
+ const index = panelsArray.indexOf(panel);
1437
+ if (index < 0) {
1438
+ return;
1439
+ }
1440
+ const currentSize = prevSizes[index];
1441
+ if (currentSize === collapsedSize) {
1442
+ // Panel is already collapsed.
1443
+ return;
1444
+ }
1445
+ panelSizeBeforeCollapse.current.set(id, currentSize);
1446
+ const [idBefore, idAfter] = getBeforeAndAfterIds(id, panelsArray);
1447
+ if (idBefore == null || idAfter == null) {
1448
+ return;
1449
+ }
1450
+ const isLastPanel = index === panelsArray.length - 1;
1451
+ const delta = isLastPanel ? currentSize : collapsedSize - currentSize;
1452
+ const nextSizes = adjustByDelta(null, committedValuesRef.current, idBefore, idAfter, delta, prevSizes, panelSizeBeforeCollapse.current, null);
1453
+ if (prevSizes !== nextSizes) {
1454
+ const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
1455
+ setSizes(nextSizes);
1456
+
1457
+ // If resize change handlers have been declared, this is the time to call them.
1458
+ // Trigger user callbacks after updating state, so that user code can override the sizes.
1459
+ callPanelCallbacks(panelsArray, nextSizes, panelIdToLastNotifiedSizeMap);
1460
+ }
1461
+ }, []);
1462
+ const expandPanel = useCallback(id => {
1463
+ const {
1464
+ panels,
1465
+ sizes: prevSizes
1466
+ } = committedValuesRef.current;
1467
+ const panel = panels.get(id);
1468
+ if (panel == null) {
1469
+ return;
1470
+ }
1471
+ const {
1472
+ collapsedSize,
1473
+ minSize
1474
+ } = panel.current;
1475
+ const sizeBeforeCollapse = panelSizeBeforeCollapse.current.get(id) || minSize;
1476
+ if (!sizeBeforeCollapse) {
1477
+ return;
1478
+ }
1479
+ const panelsArray = panelsMapToSortedArray(panels);
1480
+ const index = panelsArray.indexOf(panel);
1481
+ if (index < 0) {
1482
+ return;
1483
+ }
1484
+ const currentSize = prevSizes[index];
1485
+ if (currentSize !== collapsedSize) {
1486
+ // Panel is already expanded.
1487
+ return;
1488
+ }
1489
+ const [idBefore, idAfter] = getBeforeAndAfterIds(id, panelsArray);
1490
+ if (idBefore == null || idAfter == null) {
1491
+ return;
1492
+ }
1493
+ const isLastPanel = index === panelsArray.length - 1;
1494
+ const delta = isLastPanel ? collapsedSize - sizeBeforeCollapse : sizeBeforeCollapse;
1495
+ const nextSizes = adjustByDelta(null, committedValuesRef.current, idBefore, idAfter, delta, prevSizes, panelSizeBeforeCollapse.current, null);
1496
+ if (prevSizes !== nextSizes) {
1497
+ const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
1498
+ setSizes(nextSizes);
1499
+
1500
+ // If resize change handlers have been declared, this is the time to call them.
1501
+ // Trigger user callbacks after updating state, so that user code can override the sizes.
1502
+ callPanelCallbacks(panelsArray, nextSizes, panelIdToLastNotifiedSizeMap);
1503
+ }
1504
+ }, []);
1505
+ const resizePanel = useCallback((id, nextSize, unitsFromParams) => {
1506
+ const {
1507
+ id: groupId,
1508
+ panels,
1509
+ sizes: prevSizes,
1510
+ units
1511
+ } = committedValuesRef.current;
1512
+ if ((unitsFromParams || units) === "pixels") {
1513
+ const groupSizePixels = getAvailableGroupSizePixels(groupId);
1514
+ nextSize = nextSize / groupSizePixels * 100;
1515
+ }
1516
+ const panel = panels.get(id);
1517
+ if (panel == null) {
1518
+ return;
1519
+ }
1520
+ let {
1521
+ collapsedSize,
1522
+ collapsible,
1523
+ maxSize,
1524
+ minSize
1525
+ } = panel.current;
1526
+ if (units === "pixels") {
1527
+ const groupSizePixels = getAvailableGroupSizePixels(groupId);
1528
+ minSize = minSize / groupSizePixels * 100;
1529
+ if (maxSize != null) {
1530
+ maxSize = maxSize / groupSizePixels * 100;
1531
+ }
1532
+ }
1533
+ const panelsArray = panelsMapToSortedArray(panels);
1534
+ const index = panelsArray.indexOf(panel);
1535
+ if (index < 0) {
1536
+ return;
1537
+ }
1538
+ const currentSize = prevSizes[index];
1539
+ if (currentSize === nextSize) {
1540
+ return;
1541
+ }
1542
+ if (collapsible && nextSize === collapsedSize) ; else {
1543
+ const unsafeNextSize = nextSize;
1544
+ nextSize = Math.min(maxSize != null ? maxSize : 100, Math.max(minSize, nextSize));
1545
+ {
1546
+ if (unsafeNextSize !== nextSize) {
1547
+ console.error(`Invalid size (${unsafeNextSize}) specified for Panel "${panel.current.id}" given the panel's min/max size constraints`);
1548
+ }
1549
+ }
1550
+ }
1551
+ const [idBefore, idAfter] = getBeforeAndAfterIds(id, panelsArray);
1552
+ if (idBefore == null || idAfter == null) {
1553
+ return;
1554
+ }
1555
+ const isLastPanel = index === panelsArray.length - 1;
1556
+ const delta = isLastPanel ? currentSize - nextSize : nextSize - currentSize;
1557
+ const nextSizes = adjustByDelta(null, committedValuesRef.current, idBefore, idAfter, delta, prevSizes, panelSizeBeforeCollapse.current, null);
1558
+ if (prevSizes !== nextSizes) {
1559
+ const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
1560
+ setSizes(nextSizes);
1561
+
1562
+ // If resize change handlers have been declared, this is the time to call them.
1563
+ // Trigger user callbacks after updating state, so that user code can override the sizes.
1564
+ callPanelCallbacks(panelsArray, nextSizes, panelIdToLastNotifiedSizeMap);
1565
+ }
1566
+ }, []);
1567
+ const context = useMemo(() => ({
1568
+ activeHandleId,
1569
+ collapsePanel,
1570
+ direction,
1571
+ expandPanel,
1572
+ getPanelSize,
1573
+ getPanelStyle,
1574
+ groupId,
1575
+ registerPanel,
1576
+ registerResizeHandle,
1577
+ resizePanel,
1578
+ startDragging: (id, event) => {
1579
+ setActiveHandleId(id);
1580
+ if (isMouseEvent(event) || isTouchEvent(event)) {
1581
+ const handleElement = getResizeHandle(id);
1582
+ initialDragStateRef.current = {
1583
+ dragHandleRect: handleElement.getBoundingClientRect(),
1584
+ dragOffset: getDragOffset(event, id, direction),
1585
+ sizes: committedValuesRef.current.sizes
1586
+ };
1587
+ }
1588
+ },
1589
+ stopDragging: () => {
1590
+ resetGlobalCursorStyle();
1591
+ setActiveHandleId(null);
1592
+ initialDragStateRef.current = null;
1593
+ },
1594
+ units,
1595
+ unregisterPanel
1596
+ }), [activeHandleId, collapsePanel, direction, expandPanel, getPanelSize, getPanelStyle, groupId, registerPanel, registerResizeHandle, resizePanel, units, unregisterPanel]);
1597
+ const style = {
1598
+ display: "flex",
1599
+ flexDirection: direction === "horizontal" ? "row" : "column",
1600
+ height: "100%",
1601
+ overflow: "hidden",
1602
+ width: "100%"
1603
+ };
1604
+ return createElement(PanelGroupContext.Provider, {
1605
+ children: createElement(Type, {
1606
+ children,
1607
+ className: classNameFromProps,
1608
+ "data-panel-group": "",
1609
+ "data-panel-group-direction": direction,
1610
+ "data-panel-group-id": groupId,
1611
+ "data-panel-group-units": units,
1612
+ style: {
1613
+ ...style,
1614
+ ...styleFromProps
1615
+ }
1616
+ }),
1617
+ value: context
1618
+ });
1619
+ }
1620
+ const PanelGroup = forwardRef((props, ref) => createElement(PanelGroupWithForwardedRef, {
1621
+ ...props,
1622
+ forwardedRef: ref
1623
+ }));
1624
+ PanelGroupWithForwardedRef.displayName = "PanelGroup";
1625
+ PanelGroup.displayName = "forwardRef(PanelGroup)";
1626
+
1627
+ function PanelResizeHandle({
1628
+ children = null,
1629
+ className: classNameFromProps = "",
1630
+ disabled = false,
1631
+ id: idFromProps = null,
1632
+ onDragging,
1633
+ style: styleFromProps = {},
1634
+ tagName: Type = "div"
1635
+ }) {
1636
+ const divElementRef = useRef(null);
1637
+
1638
+ // Use a ref to guard against users passing inline props
1639
+ const callbacksRef = useRef({
1640
+ onDragging
1641
+ });
1642
+ useEffect(() => {
1643
+ callbacksRef.current.onDragging = onDragging;
1644
+ });
1645
+ const panelGroupContext = useContext(PanelGroupContext);
1646
+ if (panelGroupContext === null) {
1647
+ throw Error(`PanelResizeHandle components must be rendered within a PanelGroup container`);
1648
+ }
1649
+ const {
1650
+ activeHandleId,
1651
+ direction,
1652
+ groupId,
1653
+ registerResizeHandle,
1654
+ startDragging,
1655
+ stopDragging
1656
+ } = panelGroupContext;
1657
+ const resizeHandleId = useUniqueId(idFromProps);
1658
+ const isDragging = activeHandleId === resizeHandleId;
1659
+ const [isFocused, setIsFocused] = useState(false);
1660
+ const [resizeHandler, setResizeHandler] = useState(null);
1661
+ const stopDraggingAndBlur = useCallback(() => {
1662
+ // Clicking on the drag handle shouldn't leave it focused;
1663
+ // That would cause the PanelGroup to think it was still active.
1664
+ const div = divElementRef.current;
1665
+ div.blur();
1666
+ stopDragging();
1667
+ const {
1668
+ onDragging
1669
+ } = callbacksRef.current;
1670
+ if (onDragging) {
1671
+ onDragging(false);
1672
+ }
1673
+ }, [stopDragging]);
1674
+ useEffect(() => {
1675
+ if (disabled) {
1676
+ setResizeHandler(null);
1677
+ } else {
1678
+ const resizeHandler = registerResizeHandle(resizeHandleId);
1679
+ setResizeHandler(() => resizeHandler);
1680
+ }
1681
+ }, [disabled, resizeHandleId, registerResizeHandle]);
1682
+ useEffect(() => {
1683
+ if (disabled || resizeHandler == null || !isDragging) {
1684
+ return;
1685
+ }
1686
+ const onMove = event => {
1687
+ resizeHandler(event);
1688
+ };
1689
+ const onMouseLeave = event => {
1690
+ resizeHandler(event);
1691
+ };
1692
+ const divElement = divElementRef.current;
1693
+ const targetDocument = divElement.ownerDocument;
1694
+ targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
1695
+ targetDocument.body.addEventListener("mousemove", onMove);
1696
+ targetDocument.body.addEventListener("touchmove", onMove);
1697
+ targetDocument.body.addEventListener("mouseleave", onMouseLeave);
1698
+ window.addEventListener("mouseup", stopDraggingAndBlur);
1699
+ window.addEventListener("touchend", stopDraggingAndBlur);
1700
+ return () => {
1701
+ targetDocument.body.removeEventListener("contextmenu", stopDraggingAndBlur);
1702
+ targetDocument.body.removeEventListener("mousemove", onMove);
1703
+ targetDocument.body.removeEventListener("touchmove", onMove);
1704
+ targetDocument.body.removeEventListener("mouseleave", onMouseLeave);
1705
+ window.removeEventListener("mouseup", stopDraggingAndBlur);
1706
+ window.removeEventListener("touchend", stopDraggingAndBlur);
1707
+ };
1708
+ }, [direction, disabled, isDragging, resizeHandler, stopDraggingAndBlur]);
1709
+ useWindowSplitterResizeHandlerBehavior({
1710
+ disabled,
1711
+ handleId: resizeHandleId,
1712
+ resizeHandler
1713
+ });
1714
+ const style = {
1715
+ cursor: getCursorStyle(direction),
1716
+ touchAction: "none",
1717
+ userSelect: "none"
1718
+ };
1719
+ return createElement(Type, {
1720
+ children,
1721
+ className: classNameFromProps,
1722
+ "data-resize-handle-active": isDragging ? "pointer" : isFocused ? "keyboard" : undefined,
1723
+ "data-panel-group-direction": direction,
1724
+ "data-panel-group-id": groupId,
1725
+ "data-panel-resize-handle-enabled": !disabled,
1726
+ "data-panel-resize-handle-id": resizeHandleId,
1727
+ onBlur: () => setIsFocused(false),
1728
+ onFocus: () => setIsFocused(true),
1729
+ onMouseDown: event => {
1730
+ startDragging(resizeHandleId, event.nativeEvent);
1731
+ const {
1732
+ onDragging
1733
+ } = callbacksRef.current;
1734
+ if (onDragging) {
1735
+ onDragging(true);
1736
+ }
1737
+ },
1738
+ onMouseUp: stopDraggingAndBlur,
1739
+ onTouchCancel: stopDraggingAndBlur,
1740
+ onTouchEnd: stopDraggingAndBlur,
1741
+ onTouchStart: event => {
1742
+ startDragging(resizeHandleId, event.nativeEvent);
1743
+ const {
1744
+ onDragging
1745
+ } = callbacksRef.current;
1746
+ if (onDragging) {
1747
+ onDragging(true);
1748
+ }
1749
+ },
1750
+ ref: divElementRef,
1751
+ role: "separator",
1752
+ style: {
1753
+ ...style,
1754
+ ...styleFromProps
1755
+ },
1756
+ tabIndex: 0
1757
+ });
1758
+ }
1759
+ PanelResizeHandle.displayName = "PanelResizeHandle";
1760
+
1761
+ exports.Panel = Panel;
1762
+ exports.PanelGroup = PanelGroup;
1763
+ exports.PanelResizeHandle = PanelResizeHandle;
1764
+ exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;