@iamevan/react-resizable-panels 3.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/README.md +260 -0
  2. package/dist/declarations/src/Panel.d.ts +70 -0
  3. package/dist/declarations/src/PanelGroup.d.ts +38 -0
  4. package/dist/declarations/src/PanelResizeHandle.d.ts +23 -0
  5. package/dist/declarations/src/PanelResizeHandleRegistry.d.ts +19 -0
  6. package/dist/declarations/src/constants.d.ts +15 -0
  7. package/dist/declarations/src/hooks/usePanelGroupContext.d.ts +4 -0
  8. package/dist/declarations/src/index.d.ts +23 -0
  9. package/dist/declarations/src/types.d.ts +3 -0
  10. package/dist/declarations/src/utils/assert.d.ts +1 -0
  11. package/dist/declarations/src/utils/csp.d.ts +2 -0
  12. package/dist/declarations/src/utils/cursor.d.ts +18 -0
  13. package/dist/declarations/src/utils/dom/getPanelElement.d.ts +1 -0
  14. package/dist/declarations/src/utils/dom/getPanelElementsForGroup.d.ts +1 -0
  15. package/dist/declarations/src/utils/dom/getPanelGroupElement.d.ts +1 -0
  16. package/dist/declarations/src/utils/dom/getResizeHandleElement.d.ts +1 -0
  17. package/dist/declarations/src/utils/dom/getResizeHandleElementIndex.d.ts +1 -0
  18. package/dist/declarations/src/utils/dom/getResizeHandleElementsForGroup.d.ts +1 -0
  19. package/dist/declarations/src/utils/dom/getResizeHandlePanelIds.d.ts +2 -0
  20. package/dist/declarations/src/utils/rects/getIntersectingRectangle.d.ts +2 -0
  21. package/dist/declarations/src/utils/rects/intersects.d.ts +2 -0
  22. package/dist/declarations/src/utils/rects/types.d.ts +6 -0
  23. package/dist/iamevan-react-resizable-panels.browser.development.js +2592 -0
  24. package/dist/iamevan-react-resizable-panels.browser.js +2486 -0
  25. package/dist/iamevan-react-resizable-panels.d.ts +2 -0
  26. package/dist/iamevan-react-resizable-panels.development.edge-light.js +2365 -0
  27. package/dist/iamevan-react-resizable-panels.development.js +2599 -0
  28. package/dist/iamevan-react-resizable-panels.edge-light.js +2264 -0
  29. package/dist/iamevan-react-resizable-panels.js +2488 -0
  30. package/package.json +84 -0
@@ -0,0 +1,2365 @@
1
+ import * as React from 'react';
2
+ import { createContext, useRef, forwardRef, createElement, useContext, useImperativeHandle, useState, useCallback, useEffect, useMemo } from 'react';
3
+
4
+ // The "contextmenu" event is not supported as a PointerEvent in all browsers yet, so MouseEvent still need to be handled
5
+
6
+ const PanelGroupContext = createContext(null);
7
+ PanelGroupContext.displayName = "PanelGroupContext";
8
+
9
+ const DATA_ATTRIBUTES = {
10
+ group: "data-panel-group",
11
+ groupDirection: "data-panel-group-direction",
12
+ groupId: "data-panel-group-id",
13
+ panel: "data-panel",
14
+ panelCollapsible: "data-panel-collapsible",
15
+ panelId: "data-panel-id",
16
+ panelSize: "data-panel-size",
17
+ resizeHandle: "data-resize-handle",
18
+ resizeHandleActive: "data-resize-handle-active",
19
+ resizeHandleEnabled: "data-panel-resize-handle-enabled",
20
+ resizeHandleId: "data-panel-resize-handle-id",
21
+ resizeHandleState: "data-resize-handle-state"
22
+ };
23
+ const PRECISION = 10;
24
+
25
+ const useId = React["useId".toString()];
26
+ const wrappedUseId = typeof useId === "function" ? useId : () => null;
27
+ let counter = 0;
28
+ function useUniqueId(idFromParams = null) {
29
+ const idFromUseId = wrappedUseId();
30
+ const idRef = useRef(idFromParams || idFromUseId || null);
31
+ if (idRef.current === null) {
32
+ idRef.current = "" + counter++;
33
+ }
34
+ return idFromParams !== null && idFromParams !== void 0 ? idFromParams : idRef.current;
35
+ }
36
+
37
+ function PanelWithForwardedRef({
38
+ children,
39
+ className: classNameFromProps = "",
40
+ collapsedSize,
41
+ collapsible,
42
+ defaultSize,
43
+ forwardedRef,
44
+ id: idFromProps,
45
+ maxSize,
46
+ minSize,
47
+ onCollapse,
48
+ onExpand,
49
+ onResize,
50
+ order,
51
+ style: styleFromProps,
52
+ tagName: Type = "div",
53
+ ...rest
54
+ }) {
55
+ const context = useContext(PanelGroupContext);
56
+ if (context === null) {
57
+ throw Error(`Panel components must be rendered within a PanelGroup container`);
58
+ }
59
+ const {
60
+ collapsePanel,
61
+ expandPanel,
62
+ getPanelSize,
63
+ getPanelStyle,
64
+ groupId,
65
+ isPanelCollapsed,
66
+ reevaluatePanelConstraints,
67
+ registerPanel,
68
+ resizePanel,
69
+ unregisterPanel
70
+ } = context;
71
+ const panelId = useUniqueId(idFromProps);
72
+ const panelDataRef = useRef({
73
+ callbacks: {
74
+ onCollapse,
75
+ onExpand,
76
+ onResize
77
+ },
78
+ constraints: {
79
+ collapsedSize,
80
+ collapsible,
81
+ defaultSize,
82
+ maxSize,
83
+ minSize
84
+ },
85
+ id: panelId,
86
+ idIsFromProps: idFromProps !== undefined,
87
+ order
88
+ });
89
+ const devWarningsRef = useRef({
90
+ didLogMissingDefaultSizeWarning: false
91
+ });
92
+
93
+ // Normally we wouldn't log a warning during render,
94
+ // but effects don't run on the server, so we can't do it there
95
+ {
96
+ if (!devWarningsRef.current.didLogMissingDefaultSizeWarning) {
97
+ if (defaultSize == null) {
98
+ devWarningsRef.current.didLogMissingDefaultSizeWarning = true;
99
+ console.warn(`WARNING: Panel defaultSize prop recommended to avoid layout shift after server rendering`);
100
+ }
101
+ }
102
+ }
103
+ useImperativeHandle(forwardedRef, () => ({
104
+ collapse: () => {
105
+ collapsePanel(panelDataRef.current);
106
+ },
107
+ expand: minSize => {
108
+ expandPanel(panelDataRef.current, minSize);
109
+ },
110
+ getId() {
111
+ return panelId;
112
+ },
113
+ getSize() {
114
+ return getPanelSize(panelDataRef.current);
115
+ },
116
+ isCollapsed() {
117
+ return isPanelCollapsed(panelDataRef.current);
118
+ },
119
+ isExpanded() {
120
+ return !isPanelCollapsed(panelDataRef.current);
121
+ },
122
+ resize: size => {
123
+ resizePanel(panelDataRef.current, size);
124
+ }
125
+ }), [collapsePanel, expandPanel, getPanelSize, isPanelCollapsed, panelId, resizePanel]);
126
+ const style = getPanelStyle(panelDataRef.current, defaultSize);
127
+ return createElement(Type, {
128
+ ...rest,
129
+ children,
130
+ className: classNameFromProps,
131
+ id: panelId,
132
+ style: {
133
+ ...style,
134
+ ...styleFromProps
135
+ },
136
+ // CSS selectors
137
+ [DATA_ATTRIBUTES.groupId]: groupId,
138
+ [DATA_ATTRIBUTES.panel]: "",
139
+ [DATA_ATTRIBUTES.panelCollapsible]: collapsible || undefined,
140
+ [DATA_ATTRIBUTES.panelId]: panelId,
141
+ [DATA_ATTRIBUTES.panelSize]: parseFloat("" + style.flexGrow).toFixed(1)
142
+ });
143
+ }
144
+ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
145
+ ...props,
146
+ forwardedRef: ref
147
+ }));
148
+ PanelWithForwardedRef.displayName = "Panel";
149
+ Panel.displayName = "forwardRef(Panel)";
150
+
151
+ let nonce;
152
+ function getNonce() {
153
+ return nonce;
154
+ }
155
+ function setNonce(value) {
156
+ nonce = value;
157
+ }
158
+
159
+ let currentCursorStyle = null;
160
+ let enabled = true;
161
+ let getCustomCursorStyleFunction = null;
162
+ let prevRuleIndex = -1;
163
+ let styleElement = null;
164
+ function customizeGlobalCursorStyles(callback) {
165
+ getCustomCursorStyleFunction = callback;
166
+ }
167
+ function disableGlobalCursorStyles() {
168
+ enabled = false;
169
+ }
170
+ function enableGlobalCursorStyles() {
171
+ enabled = true;
172
+ }
173
+ function getCursorStyle(state, constraintFlags, isPointerDown) {
174
+ const horizontalMin = (constraintFlags & EXCEEDED_HORIZONTAL_MIN) !== 0;
175
+ const horizontalMax = (constraintFlags & EXCEEDED_HORIZONTAL_MAX) !== 0;
176
+ const verticalMin = (constraintFlags & EXCEEDED_VERTICAL_MIN) !== 0;
177
+ const verticalMax = (constraintFlags & EXCEEDED_VERTICAL_MAX) !== 0;
178
+ if (getCustomCursorStyleFunction) {
179
+ return getCustomCursorStyleFunction({
180
+ exceedsHorizontalMaximum: horizontalMax,
181
+ exceedsHorizontalMinimum: horizontalMin,
182
+ exceedsVerticalMaximum: verticalMax,
183
+ exceedsVerticalMinimum: verticalMin,
184
+ intersectsHorizontalDragHandle: state === "horizontal" || state === "intersection",
185
+ intersectsVerticalDragHandle: state === "vertical" || state === "intersection",
186
+ isPointerDown
187
+ });
188
+ }
189
+ if (constraintFlags) {
190
+ if (horizontalMin) {
191
+ if (verticalMin) {
192
+ return "se-resize";
193
+ } else if (verticalMax) {
194
+ return "ne-resize";
195
+ } else {
196
+ return "e-resize";
197
+ }
198
+ } else if (horizontalMax) {
199
+ if (verticalMin) {
200
+ return "sw-resize";
201
+ } else if (verticalMax) {
202
+ return "nw-resize";
203
+ } else {
204
+ return "w-resize";
205
+ }
206
+ } else if (verticalMin) {
207
+ return "s-resize";
208
+ } else if (verticalMax) {
209
+ return "n-resize";
210
+ }
211
+ }
212
+ switch (state) {
213
+ case "horizontal":
214
+ return "ew-resize";
215
+ case "intersection":
216
+ return "move";
217
+ case "vertical":
218
+ return "ns-resize";
219
+ }
220
+ }
221
+ function resetGlobalCursorStyle() {
222
+ if (styleElement !== null) {
223
+ document.head.removeChild(styleElement);
224
+ currentCursorStyle = null;
225
+ styleElement = null;
226
+ prevRuleIndex = -1;
227
+ }
228
+ }
229
+ function setGlobalCursorStyle(state, constraintFlags, isPointerDown) {
230
+ var _styleElement$sheet$i, _styleElement$sheet2;
231
+ if (!enabled) {
232
+ return;
233
+ }
234
+ const style = getCursorStyle(state, constraintFlags, isPointerDown);
235
+ if (currentCursorStyle === style) {
236
+ return;
237
+ }
238
+ currentCursorStyle = style;
239
+ if (styleElement === null) {
240
+ styleElement = document.createElement("style");
241
+ const nonce = getNonce();
242
+ if (nonce) {
243
+ styleElement.setAttribute("nonce", nonce);
244
+ }
245
+ document.head.appendChild(styleElement);
246
+ }
247
+ if (prevRuleIndex >= 0) {
248
+ var _styleElement$sheet;
249
+ (_styleElement$sheet = styleElement.sheet) === null || _styleElement$sheet === void 0 ? void 0 : _styleElement$sheet.removeRule(prevRuleIndex);
250
+ }
251
+ prevRuleIndex = (_styleElement$sheet$i = (_styleElement$sheet2 = styleElement.sheet) === null || _styleElement$sheet2 === void 0 ? void 0 : _styleElement$sheet2.insertRule(`*{cursor: ${style} !important;}`)) !== null && _styleElement$sheet$i !== void 0 ? _styleElement$sheet$i : -1;
252
+ }
253
+
254
+ function isKeyDown(event) {
255
+ return event.type === "keydown";
256
+ }
257
+ function isPointerEvent(event) {
258
+ return event.type.startsWith("pointer");
259
+ }
260
+ function isMouseEvent(event) {
261
+ return event.type.startsWith("mouse");
262
+ }
263
+
264
+ function getResizeEventCoordinates(event) {
265
+ if (isPointerEvent(event)) {
266
+ if (event.isPrimary) {
267
+ return {
268
+ x: event.clientX,
269
+ y: event.clientY
270
+ };
271
+ }
272
+ } else if (isMouseEvent(event)) {
273
+ return {
274
+ x: event.clientX,
275
+ y: event.clientY
276
+ };
277
+ }
278
+ return {
279
+ x: Infinity,
280
+ y: Infinity
281
+ };
282
+ }
283
+
284
+ function getInputType() {
285
+ if (typeof matchMedia === "function") {
286
+ return matchMedia("(pointer:coarse)").matches ? "coarse" : "fine";
287
+ }
288
+ }
289
+
290
+ function intersects(rectOne, rectTwo, strict) {
291
+ if (strict) {
292
+ return rectOne.x < rectTwo.x + rectTwo.width && rectOne.x + rectOne.width > rectTwo.x && rectOne.y < rectTwo.y + rectTwo.height && rectOne.y + rectOne.height > rectTwo.y;
293
+ } else {
294
+ return rectOne.x <= rectTwo.x + rectTwo.width && rectOne.x + rectOne.width >= rectTwo.x && rectOne.y <= rectTwo.y + rectTwo.height && rectOne.y + rectOne.height >= rectTwo.y;
295
+ }
296
+ }
297
+
298
+ // Forked from NPM stacking-order@2.0.0
299
+
300
+ /**
301
+ * Determine which of two nodes appears in front of the other —
302
+ * if `a` is in front, returns 1, otherwise returns -1
303
+ * @param {HTMLElement | SVGElement} a
304
+ * @param {HTMLElement | SVGElement} b
305
+ */
306
+ function compare(a, b) {
307
+ if (a === b) throw new Error("Cannot compare node with itself");
308
+ const ancestors = {
309
+ a: get_ancestors(a),
310
+ b: get_ancestors(b)
311
+ };
312
+ let common_ancestor;
313
+
314
+ // remove shared ancestors
315
+ while (ancestors.a.at(-1) === ancestors.b.at(-1)) {
316
+ a = ancestors.a.pop();
317
+ b = ancestors.b.pop();
318
+ common_ancestor = a;
319
+ }
320
+ assert(common_ancestor, "Stacking order can only be calculated for elements with a common ancestor");
321
+ const z_indexes = {
322
+ a: get_z_index(find_stacking_context(ancestors.a)),
323
+ b: get_z_index(find_stacking_context(ancestors.b))
324
+ };
325
+ if (z_indexes.a === z_indexes.b) {
326
+ const children = common_ancestor.childNodes;
327
+ const furthest_ancestors = {
328
+ a: ancestors.a.at(-1),
329
+ b: ancestors.b.at(-1)
330
+ };
331
+ let i = children.length;
332
+ while (i--) {
333
+ const child = children[i];
334
+ if (child === furthest_ancestors.a) return 1;
335
+ if (child === furthest_ancestors.b) return -1;
336
+ }
337
+ }
338
+ return Math.sign(z_indexes.a - z_indexes.b);
339
+ }
340
+ const props = /\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;
341
+
342
+ /** @param {HTMLElement | SVGElement} node */
343
+ function is_flex_item(node) {
344
+ var _get_parent;
345
+ // @ts-ignore
346
+ const display = getComputedStyle((_get_parent = get_parent(node)) !== null && _get_parent !== void 0 ? _get_parent : node).display;
347
+ return display === "flex" || display === "inline-flex";
348
+ }
349
+
350
+ /** @param {HTMLElement | SVGElement} node */
351
+ function creates_stacking_context(node) {
352
+ const style = getComputedStyle(node);
353
+
354
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context
355
+ if (style.position === "fixed") return true;
356
+ // Forked to fix upstream bug https://github.com/Rich-Harris/stacking-order/issues/3
357
+ // if (
358
+ // (style.zIndex !== "auto" && style.position !== "static") ||
359
+ // is_flex_item(node)
360
+ // )
361
+ if (style.zIndex !== "auto" && (style.position !== "static" || is_flex_item(node))) return true;
362
+ if (+style.opacity < 1) return true;
363
+ if ("transform" in style && style.transform !== "none") return true;
364
+ if ("webkitTransform" in style && style.webkitTransform !== "none") return true;
365
+ if ("mixBlendMode" in style && style.mixBlendMode !== "normal") return true;
366
+ if ("filter" in style && style.filter !== "none") return true;
367
+ if ("webkitFilter" in style && style.webkitFilter !== "none") return true;
368
+ if ("isolation" in style && style.isolation === "isolate") return true;
369
+ if (props.test(style.willChange)) return true;
370
+ // @ts-expect-error
371
+ if (style.webkitOverflowScrolling === "touch") return true;
372
+ return false;
373
+ }
374
+
375
+ /** @param {(HTMLElement| SVGElement)[]} nodes */
376
+ function find_stacking_context(nodes) {
377
+ let i = nodes.length;
378
+ while (i--) {
379
+ const node = nodes[i];
380
+ assert(node, "Missing node");
381
+ if (creates_stacking_context(node)) return node;
382
+ }
383
+ return null;
384
+ }
385
+
386
+ /** @param {HTMLElement | SVGElement} node */
387
+ function get_z_index(node) {
388
+ return node && Number(getComputedStyle(node).zIndex) || 0;
389
+ }
390
+
391
+ /** @param {HTMLElement} node */
392
+ function get_ancestors(node) {
393
+ const ancestors = [];
394
+ while (node) {
395
+ ancestors.push(node);
396
+ // @ts-ignore
397
+ node = get_parent(node);
398
+ }
399
+ return ancestors; // [ node, ... <body>, <html>, document ]
400
+ }
401
+
402
+ /** @param {HTMLElement} node */
403
+ function get_parent(node) {
404
+ const {
405
+ parentNode
406
+ } = node;
407
+ if (parentNode && parentNode instanceof ShadowRoot) {
408
+ return parentNode.host;
409
+ }
410
+ return parentNode;
411
+ }
412
+
413
+ const EXCEEDED_HORIZONTAL_MIN = 0b0001;
414
+ const EXCEEDED_HORIZONTAL_MAX = 0b0010;
415
+ const EXCEEDED_VERTICAL_MIN = 0b0100;
416
+ const EXCEEDED_VERTICAL_MAX = 0b1000;
417
+ const isCoarsePointer = getInputType() === "coarse";
418
+ let intersectingHandles = [];
419
+ let isPointerDown = false;
420
+ let ownerDocumentCounts = new Map();
421
+ let panelConstraintFlags = new Map();
422
+ const registeredResizeHandlers = new Set();
423
+ function registerResizeHandle(resizeHandleId, element, direction, hitAreaMargins, setResizeHandlerState) {
424
+ var _ownerDocumentCounts$;
425
+ const {
426
+ ownerDocument
427
+ } = element;
428
+ const data = {
429
+ direction,
430
+ element,
431
+ hitAreaMargins,
432
+ setResizeHandlerState
433
+ };
434
+ const count = (_ownerDocumentCounts$ = ownerDocumentCounts.get(ownerDocument)) !== null && _ownerDocumentCounts$ !== void 0 ? _ownerDocumentCounts$ : 0;
435
+ ownerDocumentCounts.set(ownerDocument, count + 1);
436
+ registeredResizeHandlers.add(data);
437
+ updateListeners();
438
+ return function unregisterResizeHandle() {
439
+ var _ownerDocumentCounts$2;
440
+ panelConstraintFlags.delete(resizeHandleId);
441
+ registeredResizeHandlers.delete(data);
442
+ const count = (_ownerDocumentCounts$2 = ownerDocumentCounts.get(ownerDocument)) !== null && _ownerDocumentCounts$2 !== void 0 ? _ownerDocumentCounts$2 : 1;
443
+ ownerDocumentCounts.set(ownerDocument, count - 1);
444
+ updateListeners();
445
+ if (count === 1) {
446
+ ownerDocumentCounts.delete(ownerDocument);
447
+ }
448
+
449
+ // If the resize handle that is currently unmounting is intersecting with the pointer,
450
+ // update the global pointer to account for the change
451
+ if (intersectingHandles.includes(data)) {
452
+ const index = intersectingHandles.indexOf(data);
453
+ if (index >= 0) {
454
+ intersectingHandles.splice(index, 1);
455
+ }
456
+ updateCursor();
457
+
458
+ // Also instruct the handle to stop dragging; this prevents the parent group from being left in an inconsistent state
459
+ // See github.com/bvaughn/react-resizable-panels/issues/402
460
+ setResizeHandlerState("up", true, null);
461
+ }
462
+ };
463
+ }
464
+ function handlePointerDown(event) {
465
+ const {
466
+ target
467
+ } = event;
468
+ const {
469
+ x,
470
+ y
471
+ } = getResizeEventCoordinates(event);
472
+ isPointerDown = true;
473
+ recalculateIntersectingHandles({
474
+ target,
475
+ x,
476
+ y
477
+ });
478
+ updateListeners();
479
+ if (intersectingHandles.length > 0) {
480
+ updateResizeHandlerStates("down", event);
481
+
482
+ // Update cursor based on return value(s) from active handles
483
+ updateCursor();
484
+ event.preventDefault();
485
+ if (!isWithinResizeHandle(target)) {
486
+ event.stopImmediatePropagation();
487
+ }
488
+ }
489
+ }
490
+ function handlePointerMove(event) {
491
+ const {
492
+ x,
493
+ y
494
+ } = getResizeEventCoordinates(event);
495
+
496
+ // Edge case (see #340)
497
+ // Detect when the pointer has been released outside an iframe on a different domain
498
+ if (isPointerDown &&
499
+ // Skip this check for "pointerleave" events, else Firefox triggers a false positive (see #514)
500
+ event.type !== "pointerleave" && event.buttons === 0) {
501
+ isPointerDown = false;
502
+ updateResizeHandlerStates("up", event);
503
+ }
504
+ if (!isPointerDown) {
505
+ const {
506
+ target
507
+ } = event;
508
+
509
+ // Recalculate intersecting handles whenever the pointer moves, except if it has already been pressed
510
+ // at that point, the handles may not move with the pointer (depending on constraints)
511
+ // but the same set of active handles should be locked until the pointer is released
512
+ recalculateIntersectingHandles({
513
+ target,
514
+ x,
515
+ y
516
+ });
517
+ }
518
+ updateResizeHandlerStates("move", event);
519
+
520
+ // Update cursor based on return value(s) from active handles
521
+ updateCursor();
522
+ if (intersectingHandles.length > 0) {
523
+ event.preventDefault();
524
+ }
525
+ }
526
+ function handlePointerUp(event) {
527
+ const {
528
+ target
529
+ } = event;
530
+ const {
531
+ x,
532
+ y
533
+ } = getResizeEventCoordinates(event);
534
+ panelConstraintFlags.clear();
535
+ isPointerDown = false;
536
+ if (intersectingHandles.length > 0) {
537
+ event.preventDefault();
538
+ if (!isWithinResizeHandle(target)) {
539
+ event.stopImmediatePropagation();
540
+ }
541
+ }
542
+ updateResizeHandlerStates("up", event);
543
+ recalculateIntersectingHandles({
544
+ target,
545
+ x,
546
+ y
547
+ });
548
+ updateCursor();
549
+ updateListeners();
550
+ }
551
+ function isWithinResizeHandle(element) {
552
+ let currentElement = element;
553
+ while (currentElement) {
554
+ if (currentElement.hasAttribute(DATA_ATTRIBUTES.resizeHandle)) {
555
+ return true;
556
+ }
557
+ currentElement = currentElement.parentElement;
558
+ }
559
+ return false;
560
+ }
561
+ function recalculateIntersectingHandles({
562
+ target,
563
+ x,
564
+ y
565
+ }) {
566
+ intersectingHandles.splice(0);
567
+ let targetElement = null;
568
+ if (target instanceof HTMLElement || target instanceof SVGElement) {
569
+ targetElement = target;
570
+ }
571
+ registeredResizeHandlers.forEach(data => {
572
+ const {
573
+ element: dragHandleElement,
574
+ hitAreaMargins
575
+ } = data;
576
+ const dragHandleRect = dragHandleElement.getBoundingClientRect();
577
+ const {
578
+ bottom,
579
+ left,
580
+ right,
581
+ top
582
+ } = dragHandleRect;
583
+ const margin = isCoarsePointer ? hitAreaMargins.coarse : hitAreaMargins.fine;
584
+ const eventIntersects = x >= left - margin && x <= right + margin && y >= top - margin && y <= bottom + margin;
585
+ if (eventIntersects) {
586
+ // TRICKY
587
+ // We listen for pointers events at the root in order to support hit area margins
588
+ // (determining when the pointer is close enough to an element to be considered a "hit")
589
+ // Clicking on an element "above" a handle (e.g. a modal) should prevent a hit though
590
+ // so at this point we need to compare stacking order of a potentially intersecting drag handle,
591
+ // and the element that was actually clicked/touched
592
+ if (targetElement !== null && document.contains(targetElement) && dragHandleElement !== targetElement && !dragHandleElement.contains(targetElement) && !targetElement.contains(dragHandleElement) &&
593
+ // Calculating stacking order has a cost, so we should avoid it if possible
594
+ // That is why we only check potentially intersecting handles,
595
+ // and why we skip if the event target is within the handle's DOM
596
+ compare(targetElement, dragHandleElement) > 0) {
597
+ // If the target is above the drag handle, then we also need to confirm they overlap
598
+ // If they are beside each other (e.g. a panel and its drag handle) then the handle is still interactive
599
+ //
600
+ // It's not enough to compare only the target
601
+ // The target might be a small element inside of a larger container
602
+ // (For example, a SPAN or a DIV inside of a larger modal dialog)
603
+ let currentElement = targetElement;
604
+ let didIntersect = false;
605
+ while (currentElement) {
606
+ if (currentElement.contains(dragHandleElement)) {
607
+ break;
608
+ } else if (intersects(currentElement.getBoundingClientRect(), dragHandleRect, true)) {
609
+ didIntersect = true;
610
+ break;
611
+ }
612
+ currentElement = currentElement.parentElement;
613
+ }
614
+ if (didIntersect) {
615
+ return;
616
+ }
617
+ }
618
+ intersectingHandles.push(data);
619
+ }
620
+ });
621
+ }
622
+ function reportConstraintsViolation(resizeHandleId, flag) {
623
+ panelConstraintFlags.set(resizeHandleId, flag);
624
+ }
625
+ function updateCursor() {
626
+ let intersectsHorizontal = false;
627
+ let intersectsVertical = false;
628
+ intersectingHandles.forEach(data => {
629
+ const {
630
+ direction
631
+ } = data;
632
+ if (direction === "horizontal") {
633
+ intersectsHorizontal = true;
634
+ } else {
635
+ intersectsVertical = true;
636
+ }
637
+ });
638
+ let constraintFlags = 0;
639
+ panelConstraintFlags.forEach(flag => {
640
+ constraintFlags |= flag;
641
+ });
642
+ if (intersectsHorizontal && intersectsVertical) {
643
+ setGlobalCursorStyle("intersection", constraintFlags, isPointerDown);
644
+ } else if (intersectsHorizontal) {
645
+ setGlobalCursorStyle("horizontal", constraintFlags, isPointerDown);
646
+ } else if (intersectsVertical) {
647
+ setGlobalCursorStyle("vertical", constraintFlags, isPointerDown);
648
+ } else {
649
+ resetGlobalCursorStyle();
650
+ }
651
+ }
652
+ let listenersAbortController;
653
+ function updateListeners() {
654
+ var _listenersAbortContro;
655
+ (_listenersAbortContro = listenersAbortController) === null || _listenersAbortContro === void 0 ? void 0 : _listenersAbortContro.abort();
656
+ listenersAbortController = new AbortController();
657
+ const options = {
658
+ capture: true,
659
+ signal: listenersAbortController.signal
660
+ };
661
+ if (!registeredResizeHandlers.size) {
662
+ return;
663
+ }
664
+ if (isPointerDown) {
665
+ if (intersectingHandles.length > 0) {
666
+ ownerDocumentCounts.forEach((count, ownerDocument) => {
667
+ const {
668
+ body
669
+ } = ownerDocument;
670
+ if (count > 0) {
671
+ body.addEventListener("contextmenu", handlePointerUp, options);
672
+ body.addEventListener("pointerleave", handlePointerMove, options);
673
+ body.addEventListener("pointermove", handlePointerMove, options);
674
+ }
675
+ });
676
+ }
677
+ ownerDocumentCounts.forEach((_, ownerDocument) => {
678
+ const {
679
+ body
680
+ } = ownerDocument;
681
+ body.addEventListener("pointerup", handlePointerUp, options);
682
+ body.addEventListener("pointercancel", handlePointerUp, options);
683
+ });
684
+ } else {
685
+ ownerDocumentCounts.forEach((count, ownerDocument) => {
686
+ const {
687
+ body
688
+ } = ownerDocument;
689
+ if (count > 0) {
690
+ body.addEventListener("pointerdown", handlePointerDown, options);
691
+ body.addEventListener("pointermove", handlePointerMove, options);
692
+ }
693
+ });
694
+ }
695
+ }
696
+ function updateResizeHandlerStates(action, event) {
697
+ registeredResizeHandlers.forEach(data => {
698
+ const {
699
+ setResizeHandlerState
700
+ } = data;
701
+ const isActive = intersectingHandles.includes(data);
702
+ setResizeHandlerState(action, isActive, event);
703
+ });
704
+ }
705
+
706
+ function useForceUpdate() {
707
+ const [_, setCount] = useState(0);
708
+ return useCallback(() => setCount(prevCount => prevCount + 1), []);
709
+ }
710
+
711
+ function assert(expectedCondition, message) {
712
+ if (!expectedCondition) {
713
+ console.error(message);
714
+ throw Error(message);
715
+ }
716
+ }
717
+
718
+ function fuzzyCompareNumbers(actual, expected, fractionDigits = PRECISION) {
719
+ if (actual.toFixed(fractionDigits) === expected.toFixed(fractionDigits)) {
720
+ return 0;
721
+ } else {
722
+ return actual > expected ? 1 : -1;
723
+ }
724
+ }
725
+ function fuzzyNumbersEqual$1(actual, expected, fractionDigits = PRECISION) {
726
+ return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
727
+ }
728
+
729
+ function fuzzyNumbersEqual(actual, expected, fractionDigits) {
730
+ return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
731
+ }
732
+
733
+ function fuzzyLayoutsEqual(actual, expected, fractionDigits) {
734
+ if (actual.length !== expected.length) {
735
+ return false;
736
+ }
737
+ for (let index = 0; index < actual.length; index++) {
738
+ const actualSize = actual[index];
739
+ const expectedSize = expected[index];
740
+ if (!fuzzyNumbersEqual(actualSize, expectedSize, fractionDigits)) {
741
+ return false;
742
+ }
743
+ }
744
+ return true;
745
+ }
746
+
747
+ // Panel size must be in percentages; pixel values should be pre-converted
748
+ function resizePanel({
749
+ panelConstraints: panelConstraintsArray,
750
+ panelIndex,
751
+ size
752
+ }) {
753
+ const panelConstraints = panelConstraintsArray[panelIndex];
754
+ assert(panelConstraints != null, `Panel constraints not found for index ${panelIndex}`);
755
+ let {
756
+ collapsedSize = 0,
757
+ collapsible,
758
+ maxSize = 100,
759
+ minSize = 0
760
+ } = panelConstraints;
761
+ if (fuzzyCompareNumbers(size, minSize) < 0) {
762
+ if (collapsible) {
763
+ // Collapsible panels should snap closed or open only once they cross the halfway point between collapsed and min size.
764
+ const halfwayPoint = (collapsedSize + minSize) / 2;
765
+ if (fuzzyCompareNumbers(size, halfwayPoint) < 0) {
766
+ size = collapsedSize;
767
+ } else {
768
+ size = minSize;
769
+ }
770
+ } else {
771
+ size = minSize;
772
+ }
773
+ }
774
+ size = Math.min(maxSize, size);
775
+ size = parseFloat(size.toFixed(PRECISION));
776
+ return size;
777
+ }
778
+
779
+ // All units must be in percentages; pixel values should be pre-converted
780
+ function adjustLayoutByDelta({
781
+ delta,
782
+ initialLayout,
783
+ panelConstraints: panelConstraintsArray,
784
+ pivotIndices,
785
+ prevLayout,
786
+ trigger
787
+ }) {
788
+ if (fuzzyNumbersEqual(delta, 0)) {
789
+ return initialLayout;
790
+ }
791
+ const nextLayout = [...initialLayout];
792
+ const [firstPivotIndex, secondPivotIndex] = pivotIndices;
793
+ assert(firstPivotIndex != null, "Invalid first pivot index");
794
+ assert(secondPivotIndex != null, "Invalid second pivot index");
795
+ let deltaApplied = 0;
796
+
797
+ // const DEBUG = [];
798
+ // DEBUG.push(`adjustLayoutByDelta()`);
799
+ // DEBUG.push(` initialLayout: ${initialLayout.join(", ")}`);
800
+ // DEBUG.push(` prevLayout: ${prevLayout.join(", ")}`);
801
+ // DEBUG.push(` delta: ${delta}`);
802
+ // DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
803
+ // DEBUG.push(` trigger: ${trigger}`);
804
+ // DEBUG.push("");
805
+
806
+ // A resizing panel affects the panels before or after it.
807
+ //
808
+ // A negative delta means the panel(s) immediately after the resize handle should grow/expand by decreasing its offset.
809
+ // Other panels may also need to shrink/contract (and shift) to make room, depending on the min weights.
810
+ //
811
+ // A positive delta means the panel(s) immediately before the resize handle should "expand".
812
+ // This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resize handle.
813
+
814
+ {
815
+ // If this is a resize triggered by a keyboard event, our logic for expanding/collapsing is different.
816
+ // We no longer check the halfway threshold because this may prevent the panel from expanding at all.
817
+ if (trigger === "keyboard") {
818
+ {
819
+ // Check if we should expand a collapsed panel
820
+ const index = delta < 0 ? secondPivotIndex : firstPivotIndex;
821
+ const panelConstraints = panelConstraintsArray[index];
822
+ assert(panelConstraints, `Panel constraints not found for index ${index}`);
823
+ const {
824
+ collapsedSize = 0,
825
+ collapsible,
826
+ minSize = 0
827
+ } = panelConstraints;
828
+
829
+ // DEBUG.push(`edge case check 1: ${index}`);
830
+ // DEBUG.push(` -> collapsible? ${collapsible}`);
831
+ if (collapsible) {
832
+ const prevSize = initialLayout[index];
833
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
834
+ if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
835
+ const localDelta = minSize - prevSize;
836
+ // DEBUG.push(` -> expand delta: ${localDelta}`);
837
+
838
+ if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
839
+ delta = delta < 0 ? 0 - localDelta : localDelta;
840
+ // DEBUG.push(` -> delta: ${delta}`);
841
+ }
842
+ }
843
+ }
844
+ }
845
+
846
+ {
847
+ // Check if we should collapse a panel at its minimum size
848
+ const index = delta < 0 ? firstPivotIndex : secondPivotIndex;
849
+ const panelConstraints = panelConstraintsArray[index];
850
+ assert(panelConstraints, `No panel constraints found for index ${index}`);
851
+ const {
852
+ collapsedSize = 0,
853
+ collapsible,
854
+ minSize = 0
855
+ } = panelConstraints;
856
+
857
+ // DEBUG.push(`edge case check 2: ${index}`);
858
+ // DEBUG.push(` -> collapsible? ${collapsible}`);
859
+ if (collapsible) {
860
+ const prevSize = initialLayout[index];
861
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
862
+ if (fuzzyNumbersEqual(prevSize, minSize)) {
863
+ const localDelta = prevSize - collapsedSize;
864
+ // DEBUG.push(` -> expand delta: ${localDelta}`);
865
+
866
+ if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
867
+ delta = delta < 0 ? 0 - localDelta : localDelta;
868
+ // DEBUG.push(` -> delta: ${delta}`);
869
+ }
870
+ }
871
+ }
872
+ }
873
+ }
874
+ // DEBUG.push("");
875
+ }
876
+
877
+ {
878
+ // Pre-calculate max available delta in the opposite direction of our pivot.
879
+ // This will be the maximum amount we're allowed to expand/contract the panels in the primary direction.
880
+ // If this amount is less than the requested delta, adjust the requested delta.
881
+ // If this amount is greater than the requested delta, that's useful information too–
882
+ // as an expanding panel might change from collapsed to min size.
883
+
884
+ const increment = delta < 0 ? 1 : -1;
885
+ let index = delta < 0 ? secondPivotIndex : firstPivotIndex;
886
+ let maxAvailableDelta = 0;
887
+
888
+ // DEBUG.push("pre calc...");
889
+ while (true) {
890
+ const prevSize = initialLayout[index];
891
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
892
+ const maxSafeSize = resizePanel({
893
+ panelConstraints: panelConstraintsArray,
894
+ panelIndex: index,
895
+ size: 100
896
+ });
897
+ const delta = maxSafeSize - prevSize;
898
+ // DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
899
+
900
+ maxAvailableDelta += delta;
901
+ index += increment;
902
+ if (index < 0 || index >= panelConstraintsArray.length) {
903
+ break;
904
+ }
905
+ }
906
+
907
+ // DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
908
+ const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
909
+ delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
910
+ // DEBUG.push(` -> adjusted delta: ${delta}`);
911
+ // DEBUG.push("");
912
+ }
913
+
914
+ {
915
+ // Delta added to a panel needs to be subtracted from other panels (within the constraints that those panels allow).
916
+
917
+ const pivotIndex = delta < 0 ? firstPivotIndex : secondPivotIndex;
918
+ let index = pivotIndex;
919
+ while (index >= 0 && index < panelConstraintsArray.length) {
920
+ const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
921
+ const prevSize = initialLayout[index];
922
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
923
+ const unsafeSize = prevSize - deltaRemaining;
924
+ const safeSize = resizePanel({
925
+ panelConstraints: panelConstraintsArray,
926
+ panelIndex: index,
927
+ size: unsafeSize
928
+ });
929
+ if (!fuzzyNumbersEqual(prevSize, safeSize)) {
930
+ deltaApplied += prevSize - safeSize;
931
+ nextLayout[index] = safeSize;
932
+ if (deltaApplied.toFixed(3).localeCompare(Math.abs(delta).toFixed(3), undefined, {
933
+ numeric: true
934
+ }) >= 0) {
935
+ break;
936
+ }
937
+ }
938
+ if (delta < 0) {
939
+ index--;
940
+ } else {
941
+ index++;
942
+ }
943
+ }
944
+ }
945
+ // DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
946
+ // DEBUG.push(` deltaApplied: ${deltaApplied}`);
947
+ // DEBUG.push("");
948
+
949
+ // If we were unable to resize any of the panels panels, return the previous state.
950
+ // This will essentially bailout and ignore e.g. drags past a panel's boundaries
951
+ if (fuzzyLayoutsEqual(prevLayout, nextLayout)) {
952
+ // DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
953
+ // console.log(DEBUG.join("\n"));
954
+
955
+ return prevLayout;
956
+ }
957
+ {
958
+ // Now distribute the applied delta to the panels in the other direction
959
+ const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
960
+ const prevSize = initialLayout[pivotIndex];
961
+ assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
962
+ const unsafeSize = prevSize + deltaApplied;
963
+ const safeSize = resizePanel({
964
+ panelConstraints: panelConstraintsArray,
965
+ panelIndex: pivotIndex,
966
+ size: unsafeSize
967
+ });
968
+
969
+ // Adjust the pivot panel before, but only by the amount that surrounding panels were able to shrink/contract.
970
+ nextLayout[pivotIndex] = safeSize;
971
+
972
+ // Edge case where expanding or contracting one panel caused another one to change collapsed state
973
+ if (!fuzzyNumbersEqual(safeSize, unsafeSize)) {
974
+ let deltaRemaining = unsafeSize - safeSize;
975
+ const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
976
+ let index = pivotIndex;
977
+ while (index >= 0 && index < panelConstraintsArray.length) {
978
+ const prevSize = nextLayout[index];
979
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
980
+ const unsafeSize = prevSize + deltaRemaining;
981
+ const safeSize = resizePanel({
982
+ panelConstraints: panelConstraintsArray,
983
+ panelIndex: index,
984
+ size: unsafeSize
985
+ });
986
+ if (!fuzzyNumbersEqual(prevSize, safeSize)) {
987
+ deltaRemaining -= safeSize - prevSize;
988
+ nextLayout[index] = safeSize;
989
+ }
990
+ if (fuzzyNumbersEqual(deltaRemaining, 0)) {
991
+ break;
992
+ }
993
+ if (delta > 0) {
994
+ index--;
995
+ } else {
996
+ index++;
997
+ }
998
+ }
999
+ }
1000
+ }
1001
+ // DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
1002
+ // DEBUG.push(` deltaApplied: ${deltaApplied}`);
1003
+ // DEBUG.push("");
1004
+
1005
+ const totalSize = nextLayout.reduce((total, size) => size + total, 0);
1006
+ // DEBUG.push(`total size: ${totalSize}`);
1007
+
1008
+ // If our new layout doesn't add up to 100%, that means the requested delta can't be applied
1009
+ // In that case, fall back to our most recent valid layout
1010
+ if (!fuzzyNumbersEqual(totalSize, 100)) {
1011
+ // DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
1012
+ // console.log(DEBUG.join("\n"));
1013
+
1014
+ return prevLayout;
1015
+ }
1016
+
1017
+ // console.log(DEBUG.join("\n"));
1018
+ return nextLayout;
1019
+ }
1020
+
1021
+ function getResizeHandleElementsForGroup(groupId, scope = document) {
1022
+ return Array.from(scope.querySelectorAll(`[${DATA_ATTRIBUTES.resizeHandleId}][data-panel-group-id="${groupId}"]`));
1023
+ }
1024
+
1025
+ function getResizeHandleElementIndex(groupId, id, scope = document) {
1026
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
1027
+ const index = handles.findIndex(handle => handle.getAttribute(DATA_ATTRIBUTES.resizeHandleId) === id);
1028
+ return index !== null && index !== void 0 ? index : null;
1029
+ }
1030
+
1031
+ function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
1032
+ const index = getResizeHandleElementIndex(groupId, dragHandleId, panelGroupElement);
1033
+ return index != null ? [index, index + 1] : [-1, -1];
1034
+ }
1035
+
1036
+ function isHTMLElement(target) {
1037
+ if (target instanceof HTMLElement) {
1038
+ return true;
1039
+ }
1040
+
1041
+ // Fallback to duck typing to handle edge case of portals within a popup window
1042
+ return typeof target === "object" && target !== null && "tagName" in target && "getAttribute" in target;
1043
+ }
1044
+
1045
+ function getPanelGroupElement(id, rootElement = document) {
1046
+ // If the root element is the PanelGroup
1047
+ if (isHTMLElement(rootElement) && rootElement.dataset.panelGroupId == id) {
1048
+ return rootElement;
1049
+ }
1050
+
1051
+ // Else query children
1052
+ const element = rootElement.querySelector(`[data-panel-group][data-panel-group-id="${id}"]`);
1053
+ if (element) {
1054
+ return element;
1055
+ }
1056
+ return null;
1057
+ }
1058
+
1059
+ function getResizeHandleElement(id, scope = document) {
1060
+ const element = scope.querySelector(`[${DATA_ATTRIBUTES.resizeHandleId}="${id}"]`);
1061
+ if (element) {
1062
+ return element;
1063
+ }
1064
+ return null;
1065
+ }
1066
+
1067
+ function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
1068
+ var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
1069
+ const handle = getResizeHandleElement(handleId, scope);
1070
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
1071
+ const index = handle ? handles.indexOf(handle) : -1;
1072
+ const idBefore = (_panelsArray$index$id = (_panelsArray$index = panelsArray[index]) === null || _panelsArray$index === void 0 ? void 0 : _panelsArray$index.id) !== null && _panelsArray$index$id !== void 0 ? _panelsArray$index$id : null;
1073
+ const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
1074
+ return [idBefore, idAfter];
1075
+ }
1076
+
1077
+ // https://www.w3.org/WAI/ARIA/apg/patterns/windowsplitter/
1078
+
1079
+ function useWindowSplitterPanelGroupBehavior({
1080
+ committedValuesRef,
1081
+ eagerValuesRef,
1082
+ groupId,
1083
+ layout,
1084
+ panelDataArray,
1085
+ panelGroupElement,
1086
+ setLayout
1087
+ }) {
1088
+ useRef({
1089
+ didWarnAboutMissingResizeHandle: false
1090
+ });
1091
+ useEffect(() => {
1092
+ if (!panelGroupElement) {
1093
+ return;
1094
+ }
1095
+ const eagerValues = eagerValuesRef.current;
1096
+ assert(eagerValues, `Eager values not found`);
1097
+ const {
1098
+ panelDataArray
1099
+ } = eagerValues;
1100
+ const groupElement = getPanelGroupElement(groupId, panelGroupElement);
1101
+ assert(groupElement != null, `No group found for id "${groupId}"`);
1102
+ const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1103
+ assert(handles, `No resize handles found for group id "${groupId}"`);
1104
+ const cleanupFunctions = handles.map(handle => {
1105
+ const handleId = handle.getAttribute(DATA_ATTRIBUTES.resizeHandleId);
1106
+ assert(handleId, `Resize handle element has no handle id attribute`);
1107
+ const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
1108
+ if (idBefore == null || idAfter == null) {
1109
+ return () => {};
1110
+ }
1111
+ const onKeyDown = event => {
1112
+ if (event.defaultPrevented) {
1113
+ return;
1114
+ }
1115
+ switch (event.key) {
1116
+ case "Enter":
1117
+ {
1118
+ event.preventDefault();
1119
+ const index = panelDataArray.findIndex(panelData => panelData.id === idBefore);
1120
+ if (index >= 0) {
1121
+ const panelData = panelDataArray[index];
1122
+ assert(panelData, `No panel data found for index ${index}`);
1123
+ const size = layout[index];
1124
+ const {
1125
+ collapsedSize = 0,
1126
+ collapsible,
1127
+ minSize = 0
1128
+ } = panelData.constraints;
1129
+ if (size != null && collapsible) {
1130
+ const nextLayout = adjustLayoutByDelta({
1131
+ delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
1132
+ initialLayout: layout,
1133
+ panelConstraints: panelDataArray.map(panelData => panelData.constraints),
1134
+ pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
1135
+ prevLayout: layout,
1136
+ trigger: "keyboard"
1137
+ });
1138
+ if (layout !== nextLayout) {
1139
+ setLayout(nextLayout);
1140
+ }
1141
+ }
1142
+ }
1143
+ break;
1144
+ }
1145
+ }
1146
+ };
1147
+ handle.addEventListener("keydown", onKeyDown);
1148
+ return () => {
1149
+ handle.removeEventListener("keydown", onKeyDown);
1150
+ };
1151
+ });
1152
+ return () => {
1153
+ cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
1154
+ };
1155
+ }, [panelGroupElement, committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
1156
+ }
1157
+
1158
+ function areEqual(arrayA, arrayB) {
1159
+ if (arrayA.length !== arrayB.length) {
1160
+ return false;
1161
+ }
1162
+ for (let index = 0; index < arrayA.length; index++) {
1163
+ if (arrayA[index] !== arrayB[index]) {
1164
+ return false;
1165
+ }
1166
+ }
1167
+ return true;
1168
+ }
1169
+
1170
+ function getResizeEventCursorPosition(direction, event) {
1171
+ const isHorizontal = direction === "horizontal";
1172
+ const {
1173
+ x,
1174
+ y
1175
+ } = getResizeEventCoordinates(event);
1176
+ return isHorizontal ? x : y;
1177
+ }
1178
+
1179
+ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
1180
+ const isHorizontal = direction === "horizontal";
1181
+ const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
1182
+ assert(handleElement, `No resize handle element found for id "${dragHandleId}"`);
1183
+ const groupId = handleElement.getAttribute(DATA_ATTRIBUTES.groupId);
1184
+ assert(groupId, `Resize handle element has no group id attribute`);
1185
+ let {
1186
+ initialCursorPosition
1187
+ } = initialDragState;
1188
+ const cursorPosition = getResizeEventCursorPosition(direction, event);
1189
+ const groupElement = getPanelGroupElement(groupId, panelGroupElement);
1190
+ assert(groupElement, `No group element found for id "${groupId}"`);
1191
+ const groupRect = groupElement.getBoundingClientRect();
1192
+ const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
1193
+ const offsetPixels = cursorPosition - initialCursorPosition;
1194
+ const offsetPercentage = offsetPixels / groupSizeInPixels * 100;
1195
+ return offsetPercentage;
1196
+ }
1197
+
1198
+ // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX
1199
+ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy, panelGroupElement) {
1200
+ if (isKeyDown(event)) {
1201
+ const isHorizontal = direction === "horizontal";
1202
+ let delta = 0;
1203
+ if (event.shiftKey) {
1204
+ delta = 100;
1205
+ } else if (keyboardResizeBy != null) {
1206
+ delta = keyboardResizeBy;
1207
+ } else {
1208
+ delta = 10;
1209
+ }
1210
+ let movement = 0;
1211
+ switch (event.key) {
1212
+ case "ArrowDown":
1213
+ movement = isHorizontal ? 0 : delta;
1214
+ break;
1215
+ case "ArrowLeft":
1216
+ movement = isHorizontal ? -delta : 0;
1217
+ break;
1218
+ case "ArrowRight":
1219
+ movement = isHorizontal ? delta : 0;
1220
+ break;
1221
+ case "ArrowUp":
1222
+ movement = isHorizontal ? 0 : -delta;
1223
+ break;
1224
+ case "End":
1225
+ movement = 100;
1226
+ break;
1227
+ case "Home":
1228
+ movement = -100;
1229
+ break;
1230
+ }
1231
+ return movement;
1232
+ } else {
1233
+ if (initialDragState == null) {
1234
+ return 0;
1235
+ }
1236
+ return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement);
1237
+ }
1238
+ }
1239
+
1240
+ // Layout should be pre-converted into percentages
1241
+ function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
1242
+ layout.forEach((size, index) => {
1243
+ const panelData = panelsArray[index];
1244
+ assert(panelData, `Panel data not found for index ${index}`);
1245
+ const {
1246
+ callbacks,
1247
+ constraints,
1248
+ id: panelId
1249
+ } = panelData;
1250
+ const {
1251
+ collapsedSize = 0,
1252
+ collapsible
1253
+ } = constraints;
1254
+ const lastNotifiedSize = panelIdToLastNotifiedSizeMap[panelId];
1255
+ if (lastNotifiedSize == null || size !== lastNotifiedSize) {
1256
+ panelIdToLastNotifiedSizeMap[panelId] = size;
1257
+ const {
1258
+ onCollapse,
1259
+ onExpand,
1260
+ onResize
1261
+ } = callbacks;
1262
+ if (onResize) {
1263
+ onResize(size, lastNotifiedSize);
1264
+ }
1265
+ if (collapsible && (onCollapse || onExpand)) {
1266
+ if (onExpand && (lastNotifiedSize == null || fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && !fuzzyNumbersEqual$1(size, collapsedSize)) {
1267
+ onExpand();
1268
+ }
1269
+ if (onCollapse && (lastNotifiedSize == null || !fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && fuzzyNumbersEqual$1(size, collapsedSize)) {
1270
+ onCollapse();
1271
+ }
1272
+ }
1273
+ }
1274
+ });
1275
+ }
1276
+
1277
+ function compareLayouts(a, b) {
1278
+ if (a.length !== b.length) {
1279
+ return false;
1280
+ } else {
1281
+ for (let index = 0; index < a.length; index++) {
1282
+ if (a[index] != b[index]) {
1283
+ return false;
1284
+ }
1285
+ }
1286
+ }
1287
+ return true;
1288
+ }
1289
+
1290
+ // This method returns a number between 1 and 100 representing
1291
+
1292
+ // the % of the group's overall space this panel should occupy.
1293
+ function computePanelFlexBoxStyle({
1294
+ defaultSize,
1295
+ dragState,
1296
+ layout,
1297
+ panelData,
1298
+ panelIndex,
1299
+ precision = 3
1300
+ }) {
1301
+ const size = layout[panelIndex];
1302
+ let flexGrow;
1303
+ if (size == null) {
1304
+ // Initial render (before panels have registered themselves)
1305
+ // In order to support server rendering, fall back to default size if provided
1306
+ flexGrow = defaultSize != undefined ? defaultSize.toFixed(precision) : "1";
1307
+ } else if (panelData.length === 1) {
1308
+ // Special case: Single panel group should always fill full width/height
1309
+ flexGrow = "1";
1310
+ } else {
1311
+ flexGrow = size.toFixed(precision);
1312
+ }
1313
+ return {
1314
+ flexBasis: 0,
1315
+ flexGrow,
1316
+ flexShrink: 1,
1317
+ // Without this, Panel sizes may be unintentionally overridden by their content
1318
+ overflow: "hidden",
1319
+ // Disable pointer events inside of a panel during resize
1320
+ // This avoid edge cases like nested iframes
1321
+ pointerEvents: dragState !== null ? "none" : undefined
1322
+ };
1323
+ }
1324
+
1325
+ function debounce(callback, durationMs = 10) {
1326
+ let timeoutId = null;
1327
+ let callable = (...args) => {
1328
+ if (timeoutId !== null) {
1329
+ clearTimeout(timeoutId);
1330
+ }
1331
+ timeoutId = setTimeout(() => {
1332
+ callback(...args);
1333
+ }, durationMs);
1334
+ };
1335
+ return callable;
1336
+ }
1337
+
1338
+ // PanelGroup might be rendering in a server-side environment where localStorage is not available
1339
+ // or on a browser with cookies/storage disabled.
1340
+ // In either case, this function avoids accessing localStorage until needed,
1341
+ // and avoids throwing user-visible errors.
1342
+ function initializeDefaultStorage(storageObject) {
1343
+ try {
1344
+ if (typeof localStorage !== "undefined") {
1345
+ // Bypass this check for future calls
1346
+ storageObject.getItem = name => {
1347
+ return localStorage.getItem(name);
1348
+ };
1349
+ storageObject.setItem = (name, value) => {
1350
+ localStorage.setItem(name, value);
1351
+ };
1352
+ } else {
1353
+ throw new Error("localStorage not supported in this environment");
1354
+ }
1355
+ } catch (error) {
1356
+ console.error(error);
1357
+ storageObject.getItem = () => null;
1358
+ storageObject.setItem = () => {};
1359
+ }
1360
+ }
1361
+
1362
+ function getPanelGroupKey(autoSaveId) {
1363
+ return `react-resizable-panels:${autoSaveId}`;
1364
+ }
1365
+
1366
+ // Note that Panel ids might be user-provided (stable) or useId generated (non-deterministic)
1367
+ // so they should not be used as part of the serialization key.
1368
+ // Using the min/max size attributes should work well enough as a backup.
1369
+ // Pre-sorting by minSize allows remembering layouts even if panels are re-ordered/dragged.
1370
+ function getPanelKey(panels) {
1371
+ return panels.map(panel => {
1372
+ const {
1373
+ constraints,
1374
+ id,
1375
+ idIsFromProps,
1376
+ order
1377
+ } = panel;
1378
+ if (idIsFromProps) {
1379
+ return id;
1380
+ } else {
1381
+ return order ? `${order}:${JSON.stringify(constraints)}` : JSON.stringify(constraints);
1382
+ }
1383
+ }).sort((a, b) => a.localeCompare(b)).join(",");
1384
+ }
1385
+ function loadSerializedPanelGroupState(autoSaveId, storage) {
1386
+ try {
1387
+ const panelGroupKey = getPanelGroupKey(autoSaveId);
1388
+ const serialized = storage.getItem(panelGroupKey);
1389
+ if (serialized) {
1390
+ const parsed = JSON.parse(serialized);
1391
+ if (typeof parsed === "object" && parsed != null) {
1392
+ return parsed;
1393
+ }
1394
+ }
1395
+ } catch (error) {}
1396
+ return null;
1397
+ }
1398
+ function savePanelGroupState(autoSaveId, panels, panelSizesBeforeCollapse, sizes, storage) {
1399
+ var _loadSerializedPanelG2;
1400
+ const panelGroupKey = getPanelGroupKey(autoSaveId);
1401
+ const panelKey = getPanelKey(panels);
1402
+ const state = (_loadSerializedPanelG2 = loadSerializedPanelGroupState(autoSaveId, storage)) !== null && _loadSerializedPanelG2 !== void 0 ? _loadSerializedPanelG2 : {};
1403
+ state[panelKey] = {
1404
+ expandToSizes: Object.fromEntries(panelSizesBeforeCollapse.entries()),
1405
+ layout: sizes
1406
+ };
1407
+ try {
1408
+ storage.setItem(panelGroupKey, JSON.stringify(state));
1409
+ } catch (error) {
1410
+ console.error(error);
1411
+ }
1412
+ }
1413
+
1414
+ function validatePanelConstraints({
1415
+ panelConstraints: panelConstraintsArray,
1416
+ panelId,
1417
+ panelIndex
1418
+ }) {
1419
+ {
1420
+ const warnings = [];
1421
+ const panelConstraints = panelConstraintsArray[panelIndex];
1422
+ assert(panelConstraints, `No panel constraints found for index ${panelIndex}`);
1423
+ const {
1424
+ collapsedSize = 0,
1425
+ collapsible = false,
1426
+ defaultSize,
1427
+ maxSize = 100,
1428
+ minSize = 0
1429
+ } = panelConstraints;
1430
+ if (minSize > maxSize) {
1431
+ warnings.push(`min size (${minSize}%) should not be greater than max size (${maxSize}%)`);
1432
+ }
1433
+ if (defaultSize != null) {
1434
+ if (defaultSize < 0) {
1435
+ warnings.push("default size should not be less than 0");
1436
+ } else if (defaultSize < minSize && (!collapsible || defaultSize !== collapsedSize)) {
1437
+ warnings.push("default size should not be less than min size");
1438
+ }
1439
+ if (defaultSize > 100) {
1440
+ warnings.push("default size should not be greater than 100");
1441
+ } else if (defaultSize > maxSize) {
1442
+ warnings.push("default size should not be greater than max size");
1443
+ }
1444
+ }
1445
+ if (collapsedSize > minSize) {
1446
+ warnings.push("collapsed size should not be greater than min size");
1447
+ }
1448
+ if (warnings.length > 0) {
1449
+ const name = panelId != null ? `Panel "${panelId}"` : "Panel";
1450
+ console.warn(`${name} has an invalid configuration:\n\n${warnings.join("\n")}`);
1451
+ return false;
1452
+ }
1453
+ }
1454
+ return true;
1455
+ }
1456
+
1457
+ // All units must be in percentages; pixel values should be pre-converted
1458
+ function validatePanelGroupLayout({
1459
+ layout: prevLayout,
1460
+ panelConstraints
1461
+ }) {
1462
+ const nextLayout = [...prevLayout];
1463
+ const nextLayoutTotalSize = nextLayout.reduce((accumulated, current) => accumulated + current, 0);
1464
+
1465
+ // Validate layout expectations
1466
+ if (nextLayout.length !== panelConstraints.length) {
1467
+ throw Error(`Invalid ${panelConstraints.length} panel layout: ${nextLayout.map(size => `${size}%`).join(", ")}`);
1468
+ } else if (!fuzzyNumbersEqual(nextLayoutTotalSize, 100) && nextLayout.length > 0) {
1469
+ // This is not ideal so we should warn about it, but it may be recoverable in some cases
1470
+ // (especially if the amount is small)
1471
+ {
1472
+ console.warn(`WARNING: Invalid layout total size: ${nextLayout.map(size => `${size}%`).join(", ")}. Layout normalization will be applied.`);
1473
+ }
1474
+ for (let index = 0; index < panelConstraints.length; index++) {
1475
+ const unsafeSize = nextLayout[index];
1476
+ assert(unsafeSize != null, `No layout data found for index ${index}`);
1477
+ const safeSize = 100 / nextLayoutTotalSize * unsafeSize;
1478
+ nextLayout[index] = safeSize;
1479
+ }
1480
+ }
1481
+ let remainingSize = 0;
1482
+
1483
+ // First pass: Validate the proposed layout given each panel's constraints
1484
+ for (let index = 0; index < panelConstraints.length; index++) {
1485
+ const unsafeSize = nextLayout[index];
1486
+ assert(unsafeSize != null, `No layout data found for index ${index}`);
1487
+ const safeSize = resizePanel({
1488
+ panelConstraints,
1489
+ panelIndex: index,
1490
+ size: unsafeSize
1491
+ });
1492
+ if (unsafeSize != safeSize) {
1493
+ remainingSize += unsafeSize - safeSize;
1494
+ nextLayout[index] = safeSize;
1495
+ }
1496
+ }
1497
+
1498
+ // If there is additional, left over space, assign it to any panel(s) that permits it
1499
+ // (It's not worth taking multiple additional passes to evenly distribute)
1500
+ if (!fuzzyNumbersEqual(remainingSize, 0)) {
1501
+ for (let index = 0; index < panelConstraints.length; index++) {
1502
+ const prevSize = nextLayout[index];
1503
+ assert(prevSize != null, `No layout data found for index ${index}`);
1504
+ const unsafeSize = prevSize + remainingSize;
1505
+ const safeSize = resizePanel({
1506
+ panelConstraints,
1507
+ panelIndex: index,
1508
+ size: unsafeSize
1509
+ });
1510
+ if (prevSize !== safeSize) {
1511
+ remainingSize -= safeSize - prevSize;
1512
+ nextLayout[index] = safeSize;
1513
+
1514
+ // Once we've used up the remainder, bail
1515
+ if (fuzzyNumbersEqual(remainingSize, 0)) {
1516
+ break;
1517
+ }
1518
+ }
1519
+ }
1520
+ }
1521
+ return nextLayout;
1522
+ }
1523
+
1524
+ const LOCAL_STORAGE_DEBOUNCE_INTERVAL = 100;
1525
+ const defaultStorage = {
1526
+ getItem: name => {
1527
+ initializeDefaultStorage(defaultStorage);
1528
+ return defaultStorage.getItem(name);
1529
+ },
1530
+ setItem: (name, value) => {
1531
+ initializeDefaultStorage(defaultStorage);
1532
+ defaultStorage.setItem(name, value);
1533
+ }
1534
+ };
1535
+ const debounceMap = {};
1536
+ function PanelGroupWithForwardedRef({
1537
+ autoSaveId = null,
1538
+ children,
1539
+ className: classNameFromProps = "",
1540
+ direction,
1541
+ forwardedRef,
1542
+ id: idFromProps = null,
1543
+ onLayout = null,
1544
+ keyboardResizeBy = null,
1545
+ storage = defaultStorage,
1546
+ style: styleFromProps,
1547
+ tagName: Type = "div",
1548
+ ...rest
1549
+ }) {
1550
+ const groupId = useUniqueId(idFromProps);
1551
+ const panelGroupElementRef = useRef(null);
1552
+ const [dragState, setDragState] = useState(null);
1553
+ const [layout, setLayout] = useState([]);
1554
+ const forceUpdate = useForceUpdate();
1555
+ const panelIdToLastNotifiedSizeMapRef = useRef({});
1556
+ const panelSizeBeforeCollapseRef = useRef(new Map());
1557
+ const prevDeltaRef = useRef(0);
1558
+ const committedValuesRef = useRef({
1559
+ autoSaveId,
1560
+ direction,
1561
+ dragState,
1562
+ id: groupId,
1563
+ keyboardResizeBy,
1564
+ onLayout,
1565
+ storage
1566
+ });
1567
+ const eagerValuesRef = useRef({
1568
+ layout,
1569
+ panelDataArray: [],
1570
+ panelDataArrayChanged: false
1571
+ });
1572
+ const devWarningsRef = useRef({
1573
+ didLogIdAndOrderWarning: false,
1574
+ didLogPanelConstraintsWarning: false,
1575
+ prevPanelIds: []
1576
+ });
1577
+ useImperativeHandle(forwardedRef, () => ({
1578
+ getId: () => committedValuesRef.current.id,
1579
+ getLayout: () => {
1580
+ const {
1581
+ layout
1582
+ } = eagerValuesRef.current;
1583
+ return layout;
1584
+ },
1585
+ setLayout: unsafeLayout => {
1586
+ const {
1587
+ onLayout
1588
+ } = committedValuesRef.current;
1589
+ const {
1590
+ layout: prevLayout,
1591
+ panelDataArray
1592
+ } = eagerValuesRef.current;
1593
+ const safeLayout = validatePanelGroupLayout({
1594
+ layout: unsafeLayout,
1595
+ panelConstraints: panelDataArray.map(panelData => panelData.constraints)
1596
+ });
1597
+ if (!areEqual(prevLayout, safeLayout)) {
1598
+ setLayout(safeLayout);
1599
+ eagerValuesRef.current.layout = safeLayout;
1600
+ if (onLayout) {
1601
+ onLayout(safeLayout);
1602
+ }
1603
+ callPanelCallbacks(panelDataArray, safeLayout, panelIdToLastNotifiedSizeMapRef.current);
1604
+ }
1605
+ }
1606
+ }), []);
1607
+ useWindowSplitterPanelGroupBehavior({
1608
+ committedValuesRef,
1609
+ eagerValuesRef,
1610
+ groupId,
1611
+ layout,
1612
+ panelDataArray: eagerValuesRef.current.panelDataArray,
1613
+ setLayout,
1614
+ panelGroupElement: panelGroupElementRef.current
1615
+ });
1616
+ useEffect(() => {
1617
+ const {
1618
+ panelDataArray
1619
+ } = eagerValuesRef.current;
1620
+
1621
+ // If this panel has been configured to persist sizing information, save sizes to local storage.
1622
+ if (autoSaveId) {
1623
+ if (layout.length === 0 || layout.length !== panelDataArray.length) {
1624
+ return;
1625
+ }
1626
+ let debouncedSave = debounceMap[autoSaveId];
1627
+
1628
+ // Limit the frequency of localStorage updates.
1629
+ if (debouncedSave == null) {
1630
+ debouncedSave = debounce(savePanelGroupState, LOCAL_STORAGE_DEBOUNCE_INTERVAL);
1631
+ debounceMap[autoSaveId] = debouncedSave;
1632
+ }
1633
+
1634
+ // Clone mutable data before passing to the debounced function,
1635
+ // else we run the risk of saving an incorrect combination of mutable and immutable values to state.
1636
+ const clonedPanelDataArray = [...panelDataArray];
1637
+ const clonedPanelSizesBeforeCollapse = new Map(panelSizeBeforeCollapseRef.current);
1638
+ debouncedSave(autoSaveId, clonedPanelDataArray, clonedPanelSizesBeforeCollapse, layout, storage);
1639
+ }
1640
+ }, [autoSaveId, layout, storage]);
1641
+
1642
+ // DEV warnings
1643
+ useEffect(() => {
1644
+ {
1645
+ const {
1646
+ panelDataArray
1647
+ } = eagerValuesRef.current;
1648
+ const {
1649
+ didLogIdAndOrderWarning,
1650
+ didLogPanelConstraintsWarning,
1651
+ prevPanelIds
1652
+ } = devWarningsRef.current;
1653
+ if (!didLogIdAndOrderWarning) {
1654
+ const panelIds = panelDataArray.map(({
1655
+ id
1656
+ }) => id);
1657
+ devWarningsRef.current.prevPanelIds = panelIds;
1658
+ const panelsHaveChanged = prevPanelIds.length > 0 && !areEqual(prevPanelIds, panelIds);
1659
+ if (panelsHaveChanged) {
1660
+ if (panelDataArray.find(({
1661
+ idIsFromProps,
1662
+ order
1663
+ }) => !idIsFromProps || order == null)) {
1664
+ devWarningsRef.current.didLogIdAndOrderWarning = true;
1665
+ console.warn(`WARNING: Panel id and order props recommended when panels are dynamically rendered`);
1666
+ }
1667
+ }
1668
+ }
1669
+ if (!didLogPanelConstraintsWarning) {
1670
+ const panelConstraints = panelDataArray.map(panelData => panelData.constraints);
1671
+ for (let panelIndex = 0; panelIndex < panelConstraints.length; panelIndex++) {
1672
+ const panelData = panelDataArray[panelIndex];
1673
+ assert(panelData, `Panel data not found for index ${panelIndex}`);
1674
+ const isValid = validatePanelConstraints({
1675
+ panelConstraints,
1676
+ panelId: panelData.id,
1677
+ panelIndex
1678
+ });
1679
+ if (!isValid) {
1680
+ devWarningsRef.current.didLogPanelConstraintsWarning = true;
1681
+ break;
1682
+ }
1683
+ }
1684
+ }
1685
+ }
1686
+ });
1687
+
1688
+ // External APIs are safe to memoize via committed values ref
1689
+ const collapsePanel = useCallback(panelData => {
1690
+ const {
1691
+ onLayout
1692
+ } = committedValuesRef.current;
1693
+ const {
1694
+ layout: prevLayout,
1695
+ panelDataArray
1696
+ } = eagerValuesRef.current;
1697
+ if (panelData.constraints.collapsible) {
1698
+ const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1699
+ const {
1700
+ collapsedSize = 0,
1701
+ panelSize,
1702
+ pivotIndices
1703
+ } = panelDataHelper(panelDataArray, panelData, prevLayout);
1704
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1705
+ if (!fuzzyNumbersEqual$1(panelSize, collapsedSize)) {
1706
+ // Store size before collapse;
1707
+ // This is the size that gets restored if the expand() API is used.
1708
+ panelSizeBeforeCollapseRef.current.set(panelData.id, panelSize);
1709
+ const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
1710
+ const delta = isLastPanel ? panelSize - collapsedSize : collapsedSize - panelSize;
1711
+ const nextLayout = adjustLayoutByDelta({
1712
+ delta,
1713
+ initialLayout: prevLayout,
1714
+ panelConstraints: panelConstraintsArray,
1715
+ pivotIndices,
1716
+ prevLayout,
1717
+ trigger: "imperative-api"
1718
+ });
1719
+ if (!compareLayouts(prevLayout, nextLayout)) {
1720
+ setLayout(nextLayout);
1721
+ eagerValuesRef.current.layout = nextLayout;
1722
+ if (onLayout) {
1723
+ onLayout(nextLayout);
1724
+ }
1725
+ callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
1726
+ }
1727
+ }
1728
+ }
1729
+ }, []);
1730
+
1731
+ // External APIs are safe to memoize via committed values ref
1732
+ const expandPanel = useCallback((panelData, minSizeOverride) => {
1733
+ const {
1734
+ onLayout
1735
+ } = committedValuesRef.current;
1736
+ const {
1737
+ layout: prevLayout,
1738
+ panelDataArray
1739
+ } = eagerValuesRef.current;
1740
+ if (panelData.constraints.collapsible) {
1741
+ const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1742
+ const {
1743
+ collapsedSize = 0,
1744
+ panelSize = 0,
1745
+ minSize: minSizeFromProps = 0,
1746
+ pivotIndices
1747
+ } = panelDataHelper(panelDataArray, panelData, prevLayout);
1748
+ const minSize = minSizeOverride !== null && minSizeOverride !== void 0 ? minSizeOverride : minSizeFromProps;
1749
+ if (fuzzyNumbersEqual$1(panelSize, collapsedSize)) {
1750
+ // Restore this panel to the size it was before it was collapsed, if possible.
1751
+ const prevPanelSize = panelSizeBeforeCollapseRef.current.get(panelData.id);
1752
+ const baseSize = prevPanelSize != null && prevPanelSize >= minSize ? prevPanelSize : minSize;
1753
+ const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
1754
+ const delta = isLastPanel ? panelSize - baseSize : baseSize - panelSize;
1755
+ const nextLayout = adjustLayoutByDelta({
1756
+ delta,
1757
+ initialLayout: prevLayout,
1758
+ panelConstraints: panelConstraintsArray,
1759
+ pivotIndices,
1760
+ prevLayout,
1761
+ trigger: "imperative-api"
1762
+ });
1763
+ if (!compareLayouts(prevLayout, nextLayout)) {
1764
+ setLayout(nextLayout);
1765
+ eagerValuesRef.current.layout = nextLayout;
1766
+ if (onLayout) {
1767
+ onLayout(nextLayout);
1768
+ }
1769
+ callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
1770
+ }
1771
+ }
1772
+ }
1773
+ }, []);
1774
+
1775
+ // External APIs are safe to memoize via committed values ref
1776
+ const getPanelSize = useCallback(panelData => {
1777
+ const {
1778
+ layout,
1779
+ panelDataArray
1780
+ } = eagerValuesRef.current;
1781
+ const {
1782
+ panelSize
1783
+ } = panelDataHelper(panelDataArray, panelData, layout);
1784
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1785
+ return panelSize;
1786
+ }, []);
1787
+
1788
+ // This API should never read from committedValuesRef
1789
+ const getPanelStyle = useCallback((panelData, defaultSize) => {
1790
+ const {
1791
+ panelDataArray
1792
+ } = eagerValuesRef.current;
1793
+ const panelIndex = findPanelDataIndex(panelDataArray, panelData);
1794
+ return computePanelFlexBoxStyle({
1795
+ defaultSize,
1796
+ dragState,
1797
+ layout,
1798
+ panelData: panelDataArray,
1799
+ panelIndex
1800
+ });
1801
+ }, [dragState, layout]);
1802
+
1803
+ // External APIs are safe to memoize via committed values ref
1804
+ const isPanelCollapsed = useCallback(panelData => {
1805
+ const {
1806
+ layout,
1807
+ panelDataArray
1808
+ } = eagerValuesRef.current;
1809
+ const {
1810
+ collapsedSize = 0,
1811
+ collapsible,
1812
+ panelSize
1813
+ } = panelDataHelper(panelDataArray, panelData, layout);
1814
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1815
+ return collapsible === true && fuzzyNumbersEqual$1(panelSize, collapsedSize);
1816
+ }, []);
1817
+
1818
+ // External APIs are safe to memoize via committed values ref
1819
+ const isPanelExpanded = useCallback(panelData => {
1820
+ const {
1821
+ layout,
1822
+ panelDataArray
1823
+ } = eagerValuesRef.current;
1824
+ const {
1825
+ collapsedSize = 0,
1826
+ collapsible,
1827
+ panelSize
1828
+ } = panelDataHelper(panelDataArray, panelData, layout);
1829
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1830
+ return !collapsible || fuzzyCompareNumbers(panelSize, collapsedSize) > 0;
1831
+ }, []);
1832
+ const registerPanel = useCallback(panelData => {
1833
+ const {
1834
+ panelDataArray
1835
+ } = eagerValuesRef.current;
1836
+ panelDataArray.push(panelData);
1837
+ panelDataArray.sort((panelA, panelB) => {
1838
+ const orderA = panelA.order;
1839
+ const orderB = panelB.order;
1840
+ if (orderA == null && orderB == null) {
1841
+ return 0;
1842
+ } else if (orderA == null) {
1843
+ return -1;
1844
+ } else if (orderB == null) {
1845
+ return 1;
1846
+ } else {
1847
+ return orderA - orderB;
1848
+ }
1849
+ });
1850
+ eagerValuesRef.current.panelDataArrayChanged = true;
1851
+ forceUpdate();
1852
+ }, [forceUpdate]);
1853
+ const registerResizeHandle = useCallback(dragHandleId => {
1854
+ let isRTL = false;
1855
+ const panelGroupElement = panelGroupElementRef.current;
1856
+ if (panelGroupElement) {
1857
+ const style = window.getComputedStyle(panelGroupElement, null);
1858
+ if (style.getPropertyValue("direction") === "rtl") {
1859
+ isRTL = true;
1860
+ }
1861
+ }
1862
+ return function resizeHandler(event) {
1863
+ event.preventDefault();
1864
+ const panelGroupElement = panelGroupElementRef.current;
1865
+ if (!panelGroupElement) {
1866
+ return () => null;
1867
+ }
1868
+ const {
1869
+ direction,
1870
+ dragState,
1871
+ id: groupId,
1872
+ keyboardResizeBy,
1873
+ onLayout
1874
+ } = committedValuesRef.current;
1875
+ const {
1876
+ layout: prevLayout,
1877
+ panelDataArray
1878
+ } = eagerValuesRef.current;
1879
+ const {
1880
+ initialLayout
1881
+ } = dragState !== null && dragState !== void 0 ? dragState : {};
1882
+ const pivotIndices = determinePivotIndices(groupId, dragHandleId, panelGroupElement);
1883
+ let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy, panelGroupElement);
1884
+ const isHorizontal = direction === "horizontal";
1885
+ if (isHorizontal && isRTL) {
1886
+ delta = -delta;
1887
+ }
1888
+ const panelConstraints = panelDataArray.map(panelData => panelData.constraints);
1889
+ const nextLayout = adjustLayoutByDelta({
1890
+ delta,
1891
+ initialLayout: initialLayout !== null && initialLayout !== void 0 ? initialLayout : prevLayout,
1892
+ panelConstraints,
1893
+ pivotIndices,
1894
+ prevLayout,
1895
+ trigger: isKeyDown(event) ? "keyboard" : "mouse-or-touch"
1896
+ });
1897
+ const layoutChanged = !compareLayouts(prevLayout, nextLayout);
1898
+
1899
+ // Only update the cursor for layout changes triggered by touch/mouse events (not keyboard)
1900
+ // Update the cursor even if the layout hasn't changed (we may need to show an invalid cursor state)
1901
+ if (isPointerEvent(event) || isMouseEvent(event)) {
1902
+ // Watch for multiple subsequent deltas; this might occur for tiny cursor movements.
1903
+ // In this case, Panel sizes might not change–
1904
+ // but updating cursor in this scenario would cause a flicker.
1905
+ if (prevDeltaRef.current != delta) {
1906
+ prevDeltaRef.current = delta;
1907
+ if (!layoutChanged && delta !== 0) {
1908
+ // If the pointer has moved too far to resize the panel any further, note this so we can update the cursor.
1909
+ // This mimics VS Code behavior.
1910
+ if (isHorizontal) {
1911
+ reportConstraintsViolation(dragHandleId, delta < 0 ? EXCEEDED_HORIZONTAL_MIN : EXCEEDED_HORIZONTAL_MAX);
1912
+ } else {
1913
+ reportConstraintsViolation(dragHandleId, delta < 0 ? EXCEEDED_VERTICAL_MIN : EXCEEDED_VERTICAL_MAX);
1914
+ }
1915
+ } else {
1916
+ reportConstraintsViolation(dragHandleId, 0);
1917
+ }
1918
+ }
1919
+ }
1920
+ if (layoutChanged) {
1921
+ setLayout(nextLayout);
1922
+ eagerValuesRef.current.layout = nextLayout;
1923
+ if (onLayout) {
1924
+ onLayout(nextLayout);
1925
+ }
1926
+ callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
1927
+ }
1928
+ };
1929
+ }, []);
1930
+
1931
+ // External APIs are safe to memoize via committed values ref
1932
+ const resizePanel = useCallback((panelData, unsafePanelSize) => {
1933
+ const {
1934
+ onLayout
1935
+ } = committedValuesRef.current;
1936
+ const {
1937
+ layout: prevLayout,
1938
+ panelDataArray
1939
+ } = eagerValuesRef.current;
1940
+ const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1941
+ const {
1942
+ panelSize,
1943
+ pivotIndices
1944
+ } = panelDataHelper(panelDataArray, panelData, prevLayout);
1945
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1946
+ const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
1947
+ const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
1948
+ const nextLayout = adjustLayoutByDelta({
1949
+ delta,
1950
+ initialLayout: prevLayout,
1951
+ panelConstraints: panelConstraintsArray,
1952
+ pivotIndices,
1953
+ prevLayout,
1954
+ trigger: "imperative-api"
1955
+ });
1956
+ if (!compareLayouts(prevLayout, nextLayout)) {
1957
+ setLayout(nextLayout);
1958
+ eagerValuesRef.current.layout = nextLayout;
1959
+ if (onLayout) {
1960
+ onLayout(nextLayout);
1961
+ }
1962
+ callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
1963
+ }
1964
+ }, []);
1965
+ const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
1966
+ const {
1967
+ layout,
1968
+ panelDataArray
1969
+ } = eagerValuesRef.current;
1970
+ const {
1971
+ collapsedSize: prevCollapsedSize = 0,
1972
+ collapsible: prevCollapsible
1973
+ } = prevConstraints;
1974
+ const {
1975
+ collapsedSize: nextCollapsedSize = 0,
1976
+ collapsible: nextCollapsible,
1977
+ maxSize: nextMaxSize = 100,
1978
+ minSize: nextMinSize = 0
1979
+ } = panelData.constraints;
1980
+ const {
1981
+ panelSize: prevPanelSize
1982
+ } = panelDataHelper(panelDataArray, panelData, layout);
1983
+ if (prevPanelSize == null) {
1984
+ // It's possible that the panels in this group have changed since the last render
1985
+ return;
1986
+ }
1987
+ if (prevCollapsible && nextCollapsible && fuzzyNumbersEqual$1(prevPanelSize, prevCollapsedSize)) {
1988
+ if (!fuzzyNumbersEqual$1(prevCollapsedSize, nextCollapsedSize)) {
1989
+ resizePanel(panelData, nextCollapsedSize);
1990
+ }
1991
+ } else if (prevPanelSize < nextMinSize) {
1992
+ resizePanel(panelData, nextMinSize);
1993
+ } else if (prevPanelSize > nextMaxSize) {
1994
+ resizePanel(panelData, nextMaxSize);
1995
+ }
1996
+ }, [resizePanel]);
1997
+
1998
+ // TODO Multiple drag handles can be active at the same time so this API is a bit awkward now
1999
+ const startDragging = useCallback((dragHandleId, event) => {
2000
+ const {
2001
+ direction
2002
+ } = committedValuesRef.current;
2003
+ const {
2004
+ layout
2005
+ } = eagerValuesRef.current;
2006
+ if (!panelGroupElementRef.current) {
2007
+ return;
2008
+ }
2009
+ const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
2010
+ assert(handleElement, `Drag handle element not found for id "${dragHandleId}"`);
2011
+ const initialCursorPosition = getResizeEventCursorPosition(direction, event);
2012
+ setDragState({
2013
+ dragHandleId,
2014
+ dragHandleRect: handleElement.getBoundingClientRect(),
2015
+ initialCursorPosition,
2016
+ initialLayout: layout
2017
+ });
2018
+ }, []);
2019
+ const stopDragging = useCallback(() => {
2020
+ setDragState(null);
2021
+ }, []);
2022
+ const unregisterPanel = useCallback(panelData => {
2023
+ const {
2024
+ panelDataArray
2025
+ } = eagerValuesRef.current;
2026
+ const index = findPanelDataIndex(panelDataArray, panelData);
2027
+ if (index >= 0) {
2028
+ panelDataArray.splice(index, 1);
2029
+
2030
+ // TRICKY
2031
+ // When a panel is removed from the group, we should delete the most recent prev-size entry for it.
2032
+ // If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
2033
+ // Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
2034
+ delete panelIdToLastNotifiedSizeMapRef.current[panelData.id];
2035
+ eagerValuesRef.current.panelDataArrayChanged = true;
2036
+ forceUpdate();
2037
+ }
2038
+ }, [forceUpdate]);
2039
+ const context = useMemo(() => ({
2040
+ collapsePanel,
2041
+ direction,
2042
+ dragState,
2043
+ expandPanel,
2044
+ getPanelSize,
2045
+ getPanelStyle,
2046
+ groupId,
2047
+ isPanelCollapsed,
2048
+ isPanelExpanded,
2049
+ reevaluatePanelConstraints,
2050
+ registerPanel,
2051
+ registerResizeHandle,
2052
+ resizePanel,
2053
+ startDragging,
2054
+ stopDragging,
2055
+ unregisterPanel,
2056
+ panelGroupElement: panelGroupElementRef.current
2057
+ }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
2058
+ const style = {
2059
+ display: "flex",
2060
+ flexDirection: direction === "horizontal" ? "row" : "column",
2061
+ height: "100%",
2062
+ overflow: "hidden",
2063
+ width: "100%"
2064
+ };
2065
+ return createElement(PanelGroupContext.Provider, {
2066
+ value: context
2067
+ }, createElement(Type, {
2068
+ ...rest,
2069
+ children,
2070
+ className: classNameFromProps,
2071
+ id: idFromProps,
2072
+ ref: panelGroupElementRef,
2073
+ style: {
2074
+ ...style,
2075
+ ...styleFromProps
2076
+ },
2077
+ // CSS selectors
2078
+ [DATA_ATTRIBUTES.group]: "",
2079
+ [DATA_ATTRIBUTES.groupDirection]: direction,
2080
+ [DATA_ATTRIBUTES.groupId]: groupId
2081
+ }));
2082
+ }
2083
+ const PanelGroup = forwardRef((props, ref) => createElement(PanelGroupWithForwardedRef, {
2084
+ ...props,
2085
+ forwardedRef: ref
2086
+ }));
2087
+ PanelGroupWithForwardedRef.displayName = "PanelGroup";
2088
+ PanelGroup.displayName = "forwardRef(PanelGroup)";
2089
+ function findPanelDataIndex(panelDataArray, panelData) {
2090
+ return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
2091
+ }
2092
+ function panelDataHelper(panelDataArray, panelData, layout) {
2093
+ const panelIndex = findPanelDataIndex(panelDataArray, panelData);
2094
+ const isLastPanel = panelIndex === panelDataArray.length - 1;
2095
+ const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
2096
+ const panelSize = layout[panelIndex];
2097
+ return {
2098
+ ...panelData.constraints,
2099
+ panelSize,
2100
+ pivotIndices
2101
+ };
2102
+ }
2103
+
2104
+ // https://www.w3.org/WAI/ARIA/apg/patterns/windowsplitter/
2105
+
2106
+ function useWindowSplitterResizeHandlerBehavior({
2107
+ disabled,
2108
+ handleId,
2109
+ resizeHandler,
2110
+ panelGroupElement
2111
+ }) {
2112
+ useEffect(() => {
2113
+ if (disabled || resizeHandler == null || panelGroupElement == null) {
2114
+ return;
2115
+ }
2116
+ const handleElement = getResizeHandleElement(handleId, panelGroupElement);
2117
+ if (handleElement == null) {
2118
+ return;
2119
+ }
2120
+ const onKeyDown = event => {
2121
+ if (event.defaultPrevented) {
2122
+ return;
2123
+ }
2124
+ switch (event.key) {
2125
+ case "ArrowDown":
2126
+ case "ArrowLeft":
2127
+ case "ArrowRight":
2128
+ case "ArrowUp":
2129
+ case "End":
2130
+ case "Home":
2131
+ {
2132
+ event.preventDefault();
2133
+ resizeHandler(event);
2134
+ break;
2135
+ }
2136
+ case "F6":
2137
+ {
2138
+ event.preventDefault();
2139
+ const groupId = handleElement.getAttribute(DATA_ATTRIBUTES.groupId);
2140
+ assert(groupId, `No group element found for id "${groupId}"`);
2141
+ const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
2142
+ const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
2143
+ assert(index !== null, `No resize element found for id "${handleId}"`);
2144
+ const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
2145
+ const nextHandle = handles[nextIndex];
2146
+ nextHandle.focus();
2147
+ break;
2148
+ }
2149
+ }
2150
+ };
2151
+ handleElement.addEventListener("keydown", onKeyDown);
2152
+ return () => {
2153
+ handleElement.removeEventListener("keydown", onKeyDown);
2154
+ };
2155
+ }, [panelGroupElement, disabled, handleId, resizeHandler]);
2156
+ }
2157
+
2158
+ function PanelResizeHandle({
2159
+ children = null,
2160
+ className: classNameFromProps = "",
2161
+ disabled = false,
2162
+ hitAreaMargins,
2163
+ id: idFromProps,
2164
+ onBlur,
2165
+ onClick,
2166
+ onDragging,
2167
+ onFocus,
2168
+ onPointerDown,
2169
+ onPointerUp,
2170
+ style: styleFromProps = {},
2171
+ tabIndex = 0,
2172
+ tagName: Type = "div",
2173
+ ...rest
2174
+ }) {
2175
+ var _hitAreaMargins$coars, _hitAreaMargins$fine;
2176
+ const elementRef = useRef(null);
2177
+
2178
+ // Use a ref to guard against users passing inline props
2179
+ const callbacksRef = useRef({
2180
+ onClick,
2181
+ onDragging,
2182
+ onPointerDown,
2183
+ onPointerUp
2184
+ });
2185
+ useEffect(() => {
2186
+ callbacksRef.current.onClick = onClick;
2187
+ callbacksRef.current.onDragging = onDragging;
2188
+ callbacksRef.current.onPointerDown = onPointerDown;
2189
+ callbacksRef.current.onPointerUp = onPointerUp;
2190
+ });
2191
+ const panelGroupContext = useContext(PanelGroupContext);
2192
+ if (panelGroupContext === null) {
2193
+ throw Error(`PanelResizeHandle components must be rendered within a PanelGroup container`);
2194
+ }
2195
+ const {
2196
+ direction,
2197
+ groupId,
2198
+ registerResizeHandle: registerResizeHandleWithParentGroup,
2199
+ startDragging,
2200
+ stopDragging,
2201
+ panelGroupElement
2202
+ } = panelGroupContext;
2203
+ const resizeHandleId = useUniqueId(idFromProps);
2204
+ const [state, setState] = useState("inactive");
2205
+ const [isFocused, setIsFocused] = useState(false);
2206
+ const [resizeHandler, setResizeHandler] = useState(null);
2207
+ const committedValuesRef = useRef({
2208
+ state
2209
+ });
2210
+ useEffect(() => {
2211
+ if (disabled) {
2212
+ setResizeHandler(null);
2213
+ } else {
2214
+ const resizeHandler = registerResizeHandleWithParentGroup(resizeHandleId);
2215
+ setResizeHandler(() => resizeHandler);
2216
+ }
2217
+ }, [disabled, resizeHandleId, registerResizeHandleWithParentGroup]);
2218
+
2219
+ // Extract hit area margins before passing them to the effect's dependency array
2220
+ // so that inline object values won't trigger re-renders
2221
+ const coarseHitAreaMargins = (_hitAreaMargins$coars = hitAreaMargins === null || hitAreaMargins === void 0 ? void 0 : hitAreaMargins.coarse) !== null && _hitAreaMargins$coars !== void 0 ? _hitAreaMargins$coars : 15;
2222
+ const fineHitAreaMargins = (_hitAreaMargins$fine = hitAreaMargins === null || hitAreaMargins === void 0 ? void 0 : hitAreaMargins.fine) !== null && _hitAreaMargins$fine !== void 0 ? _hitAreaMargins$fine : 5;
2223
+ useEffect(() => {
2224
+ if (disabled || resizeHandler == null) {
2225
+ return;
2226
+ }
2227
+ const element = elementRef.current;
2228
+ assert(element, "Element ref not attached");
2229
+ let didMove = false;
2230
+ const setResizeHandlerState = (action, isActive, event) => {
2231
+ if (!isActive) {
2232
+ setState("inactive");
2233
+ return;
2234
+ }
2235
+ switch (action) {
2236
+ case "down":
2237
+ {
2238
+ setState("drag");
2239
+ didMove = false;
2240
+ assert(event, 'Expected event to be defined for "down" action');
2241
+ startDragging(resizeHandleId, event);
2242
+ const {
2243
+ onDragging,
2244
+ onPointerDown
2245
+ } = callbacksRef.current;
2246
+ onDragging === null || onDragging === void 0 ? void 0 : onDragging(true);
2247
+ onPointerDown === null || onPointerDown === void 0 ? void 0 : onPointerDown();
2248
+ break;
2249
+ }
2250
+ case "move":
2251
+ {
2252
+ const {
2253
+ state
2254
+ } = committedValuesRef.current;
2255
+ didMove = true;
2256
+ if (state !== "drag") {
2257
+ setState("hover");
2258
+ }
2259
+ assert(event, 'Expected event to be defined for "move" action');
2260
+ resizeHandler(event);
2261
+ break;
2262
+ }
2263
+ case "up":
2264
+ {
2265
+ setState("hover");
2266
+ stopDragging();
2267
+ const {
2268
+ onClick,
2269
+ onDragging,
2270
+ onPointerUp
2271
+ } = callbacksRef.current;
2272
+ onDragging === null || onDragging === void 0 ? void 0 : onDragging(false);
2273
+ onPointerUp === null || onPointerUp === void 0 ? void 0 : onPointerUp();
2274
+ if (!didMove) {
2275
+ onClick === null || onClick === void 0 ? void 0 : onClick();
2276
+ }
2277
+ break;
2278
+ }
2279
+ }
2280
+ };
2281
+ return registerResizeHandle(resizeHandleId, element, direction, {
2282
+ coarse: coarseHitAreaMargins,
2283
+ fine: fineHitAreaMargins
2284
+ }, setResizeHandlerState);
2285
+ }, [coarseHitAreaMargins, direction, disabled, fineHitAreaMargins, registerResizeHandleWithParentGroup, resizeHandleId, resizeHandler, startDragging, stopDragging]);
2286
+ useWindowSplitterResizeHandlerBehavior({
2287
+ disabled,
2288
+ handleId: resizeHandleId,
2289
+ resizeHandler,
2290
+ panelGroupElement
2291
+ });
2292
+ const style = {
2293
+ touchAction: "none",
2294
+ userSelect: "none"
2295
+ };
2296
+ return createElement(Type, {
2297
+ ...rest,
2298
+ children,
2299
+ className: classNameFromProps,
2300
+ id: idFromProps,
2301
+ onBlur: () => {
2302
+ setIsFocused(false);
2303
+ onBlur === null || onBlur === void 0 ? void 0 : onBlur();
2304
+ },
2305
+ onFocus: () => {
2306
+ setIsFocused(true);
2307
+ onFocus === null || onFocus === void 0 ? void 0 : onFocus();
2308
+ },
2309
+ ref: elementRef,
2310
+ role: "separator",
2311
+ style: {
2312
+ ...style,
2313
+ ...styleFromProps
2314
+ },
2315
+ tabIndex,
2316
+ // CSS selectors
2317
+ [DATA_ATTRIBUTES.groupDirection]: direction,
2318
+ [DATA_ATTRIBUTES.groupId]: groupId,
2319
+ [DATA_ATTRIBUTES.resizeHandle]: "",
2320
+ [DATA_ATTRIBUTES.resizeHandleActive]: state === "drag" ? "pointer" : isFocused ? "keyboard" : undefined,
2321
+ [DATA_ATTRIBUTES.resizeHandleEnabled]: !disabled,
2322
+ [DATA_ATTRIBUTES.resizeHandleId]: resizeHandleId,
2323
+ [DATA_ATTRIBUTES.resizeHandleState]: state
2324
+ });
2325
+ }
2326
+ PanelResizeHandle.displayName = "PanelResizeHandle";
2327
+
2328
+ function usePanelGroupContext() {
2329
+ const context = useContext(PanelGroupContext);
2330
+ return {
2331
+ direction: context === null || context === void 0 ? void 0 : context.direction,
2332
+ groupId: context === null || context === void 0 ? void 0 : context.groupId
2333
+ };
2334
+ }
2335
+
2336
+ function getPanelElement(id, scope = document) {
2337
+ const element = scope.querySelector(`[data-panel-id="${id}"]`);
2338
+ if (element) {
2339
+ return element;
2340
+ }
2341
+ return null;
2342
+ }
2343
+
2344
+ function getPanelElementsForGroup(groupId, scope = document) {
2345
+ return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
2346
+ }
2347
+
2348
+ function getIntersectingRectangle(rectOne, rectTwo, strict) {
2349
+ if (!intersects(rectOne, rectTwo, strict)) {
2350
+ return {
2351
+ x: 0,
2352
+ y: 0,
2353
+ width: 0,
2354
+ height: 0
2355
+ };
2356
+ }
2357
+ return {
2358
+ x: Math.max(rectOne.x, rectTwo.x),
2359
+ y: Math.max(rectOne.y, rectTwo.y),
2360
+ width: Math.min(rectOne.x + rectOne.width, rectTwo.x + rectTwo.width) - Math.max(rectOne.x, rectTwo.x),
2361
+ height: Math.min(rectOne.y + rectOne.height, rectTwo.y + rectTwo.height) - Math.max(rectOne.y, rectTwo.y)
2362
+ };
2363
+ }
2364
+
2365
+ export { DATA_ATTRIBUTES, Panel, PanelGroup, PanelResizeHandle, assert, customizeGlobalCursorStyles, disableGlobalCursorStyles, enableGlobalCursorStyles, getIntersectingRectangle, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds, intersects, setNonce, usePanelGroupContext };