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