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