react-resizable-panels 2.1.9 → 3.0.0

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