react-resizable-panels 1.0.7 → 1.0.8
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.
- package/CHANGELOG.md +6 -0
- package/dist/declarations/src/Panel.d.ts +3 -3
- package/dist/declarations/src/PanelGroup.d.ts +2 -2
- package/dist/declarations/src/PanelResizeHandle.d.ts +2 -2
- package/dist/declarations/src/utils/dom/calculateAvailablePanelSizeInPixels.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getAvailableGroupSizePixels.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getPanelElement.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getPanelElementsForGroup.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getPanelGroupElement.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getResizeHandleElement.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getResizeHandleElementIndex.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getResizeHandleElementsForGroup.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getResizeHandlePanelIds.d.ts +1 -1
- package/dist/declarations/src/vendor/react.d.ts +2 -2
- package/dist/react-resizable-panels.browser.cjs.js +74 -51
- package/dist/react-resizable-panels.browser.development.cjs.js +76 -52
- package/dist/react-resizable-panels.browser.development.esm.js +76 -52
- package/dist/react-resizable-panels.browser.esm.js +74 -51
- package/dist/react-resizable-panels.cjs.js +74 -51
- package/dist/react-resizable-panels.development.cjs.js +76 -52
- package/dist/react-resizable-panels.development.esm.js +76 -52
- package/dist/react-resizable-panels.development.node.cjs.js +71 -50
- package/dist/react-resizable-panels.development.node.esm.js +71 -50
- package/dist/react-resizable-panels.esm.js +74 -51
- package/dist/react-resizable-panels.node.cjs.js +69 -49
- package/dist/react-resizable-panels.node.esm.js +69 -49
- package/package.json +1 -1
- package/src/Panel.test.tsx +3 -2
- package/src/Panel.ts +2 -2
- package/src/PanelGroup.test.tsx +3 -2
- package/src/PanelGroup.ts +48 -28
- package/src/PanelGroupContext.ts +4 -2
- package/src/PanelResizeHandle.test.tsx +3 -3
- package/src/PanelResizeHandle.ts +4 -2
- package/src/hooks/useWindowSplitterBehavior.ts +14 -5
- package/src/hooks/useWindowSplitterPanelGroupBehavior.ts +23 -7
- package/src/utils/calculateDeltaPercentage.ts +4 -2
- package/src/utils/calculateDragOffsetPercentage.ts +4 -3
- package/src/utils/determinePivotIndices.ts +7 -2
- package/src/utils/dom/calculateAvailablePanelSizeInPixels.ts +8 -3
- package/src/utils/dom/getAvailableGroupSizePixels.ts +8 -7
- package/src/utils/dom/getPanelElement.ts +5 -2
- package/src/utils/dom/getPanelElementsForGroup.ts +7 -2
- package/src/utils/dom/getPanelGroupElement.ts +14 -2
- package/src/utils/dom/getResizeHandleElement.ts +5 -2
- package/src/utils/dom/getResizeHandleElementIndex.ts +3 -2
- package/src/utils/dom/getResizeHandleElementsForGroup.ts +3 -2
- package/src/utils/dom/getResizeHandlePanelIds.ts +4 -3
- package/src/utils/validatePanelConstraints.test.ts +45 -0
- package/src/utils/validatePanelConstraints.ts +5 -1
- package/src/vendor/react.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.8
|
|
4
|
+
|
|
5
|
+
- Update component signature to declare `ReactElement` return type (rather than `ReactNode`) (#256)
|
|
6
|
+
- Update `Panel` dev warning to avoid warning when `defaultSize === collapsedSize` for collapsible panels (#257)
|
|
7
|
+
- Support shadow dom by removing direct references to / dependencies on the root `document` (#204)
|
|
8
|
+
|
|
3
9
|
## 1.0.7
|
|
4
10
|
|
|
5
11
|
- Narrow `tagName` prop to only allow `HTMLElement` names (rather than the broader `Element` type) (#251)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ForwardedRef, HTMLAttributes, PropsWithChildren,
|
|
1
|
+
import { ForwardedRef, HTMLAttributes, PropsWithChildren, ReactElement } from "./vendor/react.js";
|
|
2
2
|
export type PanelOnCollapse = () => void;
|
|
3
3
|
export type PanelOnExpand = () => void;
|
|
4
4
|
export type PanelOnResize = (size: number, prevSize: number | undefined) => void;
|
|
@@ -47,7 +47,7 @@ export type PanelProps = Omit<HTMLAttributes<keyof HTMLElementTagNameMap>, "id"
|
|
|
47
47
|
}>;
|
|
48
48
|
export declare function PanelWithForwardedRef({ children, className: classNameFromProps, collapsedSize, collapsible, defaultSize, forwardedRef, id: idFromProps, maxSize, minSize, onCollapse, onExpand, onResize, order, style: styleFromProps, tagName: Type, ...rest }: PanelProps & {
|
|
49
49
|
forwardedRef: ForwardedRef<ImperativePanelHandle>;
|
|
50
|
-
}):
|
|
50
|
+
}): ReactElement;
|
|
51
51
|
export declare namespace PanelWithForwardedRef {
|
|
52
52
|
var displayName: string;
|
|
53
53
|
}
|
|
@@ -66,5 +66,5 @@ export declare const Panel: import("react").ForwardRefExoticComponent<Omit<HTMLA
|
|
|
66
66
|
style?: object | undefined;
|
|
67
67
|
tagName?: keyof HTMLElementTagNameMap | undefined;
|
|
68
68
|
} & {
|
|
69
|
-
children?: ReactNode;
|
|
69
|
+
children?: import("react").ReactNode;
|
|
70
70
|
} & import("react").RefAttributes<ImperativePanelHandle>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Direction } from "./types.js";
|
|
2
|
-
import { CSSProperties, HTMLAttributes, PropsWithChildren
|
|
2
|
+
import { CSSProperties, HTMLAttributes, PropsWithChildren } from "./vendor/react.js";
|
|
3
3
|
export type ImperativePanelGroupHandle = {
|
|
4
4
|
getId: () => string;
|
|
5
5
|
getLayout: () => number[];
|
|
@@ -32,5 +32,5 @@ export declare const PanelGroup: import("react").ForwardRefExoticComponent<Omit<
|
|
|
32
32
|
style?: CSSProperties | undefined;
|
|
33
33
|
tagName?: keyof HTMLElementTagNameMap | undefined;
|
|
34
34
|
} & {
|
|
35
|
-
children?: ReactNode;
|
|
35
|
+
children?: import("react").ReactNode;
|
|
36
36
|
} & import("react").RefAttributes<ImperativePanelGroupHandle>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CSSProperties, HTMLAttributes, PropsWithChildren,
|
|
1
|
+
import { CSSProperties, HTMLAttributes, PropsWithChildren, ReactElement } from "./vendor/react.js";
|
|
2
2
|
export type PanelResizeHandleOnDragging = (isDragging: boolean) => void;
|
|
3
3
|
export type PanelResizeHandleProps = Omit<HTMLAttributes<keyof HTMLElementTagNameMap>, "id"> & PropsWithChildren<{
|
|
4
4
|
className?: string;
|
|
@@ -9,7 +9,7 @@ export type PanelResizeHandleProps = Omit<HTMLAttributes<keyof HTMLElementTagNam
|
|
|
9
9
|
tabIndex?: number;
|
|
10
10
|
tagName?: keyof HTMLElementTagNameMap;
|
|
11
11
|
}>;
|
|
12
|
-
export declare function PanelResizeHandle({ children, className: classNameFromProps, disabled, id: idFromProps, onDragging, style: styleFromProps, tabIndex, tagName: Type, ...rest }: PanelResizeHandleProps):
|
|
12
|
+
export declare function PanelResizeHandle({ children, className: classNameFromProps, disabled, id: idFromProps, onDragging, style: styleFromProps, tabIndex, tagName: Type, ...rest }: PanelResizeHandleProps): ReactElement;
|
|
13
13
|
export declare namespace PanelResizeHandle {
|
|
14
14
|
var displayName: string;
|
|
15
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function calculateAvailablePanelSizeInPixels(groupId: string): number;
|
|
1
|
+
export declare function calculateAvailablePanelSizeInPixels(groupId: string, panelGroupElement: HTMLElement): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getAvailableGroupSizePixels(groupId: string): number;
|
|
1
|
+
export declare function getAvailableGroupSizePixels(groupId: string, panelGroupElement: HTMLElement): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getPanelElement(id: string): HTMLElement | null;
|
|
1
|
+
export declare function getPanelElement(id: string, panelGroupElement: HTMLElement): HTMLElement | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getPanelElementsForGroup(groupId: string): HTMLElement[];
|
|
1
|
+
export declare function getPanelElementsForGroup(groupId: string, panelGroupElement: HTMLElement): HTMLElement[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getPanelGroupElement(id: string): HTMLElement | null;
|
|
1
|
+
export declare function getPanelGroupElement(id: string, rootElement: ParentNode | HTMLElement): HTMLElement | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getResizeHandleElement(id: string): HTMLElement | null;
|
|
1
|
+
export declare function getResizeHandleElement(id: string, panelGroupElement: ParentNode): HTMLElement | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getResizeHandleElementIndex(groupId: string, id: string): number | null;
|
|
1
|
+
export declare function getResizeHandleElementIndex(groupId: string, id: string, panelGroupElement: ParentNode): number | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getResizeHandleElementsForGroup(groupId: string): HTMLElement[];
|
|
1
|
+
export declare function getResizeHandleElementsForGroup(groupId: string, panelGroupElement: ParentNode): HTMLElement[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { PanelData } from "../../Panel.js";
|
|
2
|
-
export declare function getResizeHandlePanelIds(groupId: string, handleId: string, panelsArray: PanelData[]): [idBefore: string | null, idAfter: string | null];
|
|
2
|
+
export declare function getResizeHandlePanelIds(groupId: string, handleId: string, panelsArray: PanelData[], panelGroupElement: ParentNode): [idBefore: string | null, idAfter: string | null];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import type { CSSProperties, ElementType, ForwardedRef, HTMLAttributes, MouseEvent, PropsWithChildren, ReactNode, RefObject, TouchEvent } from "react";
|
|
2
|
+
import type { CSSProperties, ElementType, ForwardedRef, HTMLAttributes, MouseEvent, PropsWithChildren, ReactElement, ReactNode, RefObject, TouchEvent } from "react";
|
|
3
3
|
declare const createElement: typeof React.createElement, createContext: typeof React.createContext, createRef: typeof React.createRef, forwardRef: typeof React.forwardRef, useCallback: typeof React.useCallback, useContext: typeof React.useContext, useEffect: typeof React.useEffect, useImperativeHandle: typeof React.useImperativeHandle, useLayoutEffect: typeof React.useLayoutEffect, useMemo: typeof React.useMemo, useRef: typeof React.useRef, useState: typeof React.useState;
|
|
4
4
|
declare const useId: () => string;
|
|
5
5
|
export { createElement, createContext, createRef, forwardRef, useCallback, useContext, useEffect, useId, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, };
|
|
6
|
-
export type { CSSProperties, ElementType, ForwardedRef, HTMLAttributes, MouseEvent, PropsWithChildren, ReactNode, RefObject, TouchEvent, };
|
|
6
|
+
export type { CSSProperties, ElementType, ForwardedRef, HTMLAttributes, MouseEvent, PropsWithChildren, ReactElement, ReactNode, RefObject, TouchEvent, };
|
|
@@ -519,41 +519,48 @@ function calculateAriaValues({
|
|
|
519
519
|
};
|
|
520
520
|
}
|
|
521
521
|
|
|
522
|
-
function getResizeHandleElementsForGroup(groupId) {
|
|
523
|
-
return Array.from(
|
|
522
|
+
function getResizeHandleElementsForGroup(groupId, panelGroupElement) {
|
|
523
|
+
return Array.from(panelGroupElement.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
|
|
524
524
|
}
|
|
525
525
|
|
|
526
|
-
function getResizeHandleElementIndex(groupId, id) {
|
|
527
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
526
|
+
function getResizeHandleElementIndex(groupId, id, panelGroupElement) {
|
|
527
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
528
528
|
const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
|
|
529
529
|
return index !== null && index !== void 0 ? index : null;
|
|
530
530
|
}
|
|
531
531
|
|
|
532
|
-
function determinePivotIndices(groupId, dragHandleId) {
|
|
533
|
-
const index = getResizeHandleElementIndex(groupId, dragHandleId);
|
|
532
|
+
function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
|
|
533
|
+
const index = getResizeHandleElementIndex(groupId, dragHandleId, panelGroupElement);
|
|
534
534
|
return index != null ? [index, index + 1] : [-1, -1];
|
|
535
535
|
}
|
|
536
536
|
|
|
537
|
-
function getPanelGroupElement(id) {
|
|
538
|
-
|
|
537
|
+
function getPanelGroupElement(id, rootElement) {
|
|
538
|
+
var _dataset;
|
|
539
|
+
//If the root element is the PanelGroup
|
|
540
|
+
if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
|
|
541
|
+
return rootElement;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
//Else query children
|
|
545
|
+
const element = rootElement.querySelector(`[data-panel-group][data-panel-group-id="${id}"]`);
|
|
539
546
|
if (element) {
|
|
540
547
|
return element;
|
|
541
548
|
}
|
|
542
549
|
return null;
|
|
543
550
|
}
|
|
544
551
|
|
|
545
|
-
function getResizeHandleElement(id) {
|
|
546
|
-
const element =
|
|
552
|
+
function getResizeHandleElement(id, panelGroupElement) {
|
|
553
|
+
const element = panelGroupElement.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
547
554
|
if (element) {
|
|
548
555
|
return element;
|
|
549
556
|
}
|
|
550
557
|
return null;
|
|
551
558
|
}
|
|
552
559
|
|
|
553
|
-
function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
|
|
560
|
+
function getResizeHandlePanelIds(groupId, handleId, panelsArray, panelGroupElement) {
|
|
554
561
|
var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
|
|
555
|
-
const handle = getResizeHandleElement(handleId);
|
|
556
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
562
|
+
const handle = getResizeHandleElement(handleId, panelGroupElement);
|
|
563
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
557
564
|
const index = handle ? handles.indexOf(handle) : -1;
|
|
558
565
|
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;
|
|
559
566
|
const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
|
|
@@ -568,13 +575,17 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
568
575
|
groupId,
|
|
569
576
|
layout,
|
|
570
577
|
panelDataArray,
|
|
578
|
+
panelGroupElement,
|
|
571
579
|
setLayout
|
|
572
580
|
}) {
|
|
573
581
|
useRef({
|
|
574
582
|
didWarnAboutMissingResizeHandle: false
|
|
575
583
|
});
|
|
576
584
|
useIsomorphicLayoutEffect(() => {
|
|
577
|
-
|
|
585
|
+
if (!panelGroupElement) {
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
const resizeHandleElements = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
578
589
|
for (let index = 0; index < panelDataArray.length - 1; index++) {
|
|
579
590
|
const {
|
|
580
591
|
valueMax,
|
|
@@ -603,21 +614,24 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
603
614
|
resizeHandleElement.removeAttribute("aria-valuenow");
|
|
604
615
|
});
|
|
605
616
|
};
|
|
606
|
-
}, [groupId, layout, panelDataArray]);
|
|
617
|
+
}, [groupId, layout, panelDataArray, panelGroupElement]);
|
|
607
618
|
useEffect(() => {
|
|
619
|
+
if (!panelGroupElement) {
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
608
622
|
const eagerValues = eagerValuesRef.current;
|
|
609
623
|
assert(eagerValues);
|
|
610
624
|
const {
|
|
611
625
|
panelDataArray
|
|
612
626
|
} = eagerValues;
|
|
613
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
627
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
614
628
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
615
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
629
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
616
630
|
assert(handles);
|
|
617
631
|
const cleanupFunctions = handles.map(handle => {
|
|
618
632
|
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
619
633
|
assert(handleId);
|
|
620
|
-
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray);
|
|
634
|
+
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
|
|
621
635
|
if (idBefore == null || idAfter == null) {
|
|
622
636
|
return () => {};
|
|
623
637
|
}
|
|
@@ -644,7 +658,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
644
658
|
delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
|
|
645
659
|
layout,
|
|
646
660
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints),
|
|
647
|
-
pivotIndices: determinePivotIndices(groupId, handleId),
|
|
661
|
+
pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
|
|
648
662
|
trigger: "keyboard"
|
|
649
663
|
});
|
|
650
664
|
if (layout !== nextLayout) {
|
|
@@ -664,7 +678,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
664
678
|
return () => {
|
|
665
679
|
cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
|
|
666
680
|
};
|
|
667
|
-
}, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
681
|
+
}, [panelGroupElement, committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
668
682
|
}
|
|
669
683
|
|
|
670
684
|
function areEqual(arrayA, arrayB) {
|
|
@@ -702,9 +716,9 @@ function getResizeEventCursorPosition(direction, event) {
|
|
|
702
716
|
}
|
|
703
717
|
}
|
|
704
718
|
|
|
705
|
-
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState) {
|
|
719
|
+
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
706
720
|
const isHorizontal = direction === "horizontal";
|
|
707
|
-
const handleElement = getResizeHandleElement(dragHandleId);
|
|
721
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
|
|
708
722
|
assert(handleElement);
|
|
709
723
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
710
724
|
assert(groupId);
|
|
@@ -712,7 +726,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
712
726
|
initialCursorPosition
|
|
713
727
|
} = initialDragState;
|
|
714
728
|
const cursorPosition = getResizeEventCursorPosition(direction, event);
|
|
715
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
729
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
716
730
|
assert(groupElement);
|
|
717
731
|
const groupRect = groupElement.getBoundingClientRect();
|
|
718
732
|
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
|
|
@@ -722,7 +736,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
722
736
|
}
|
|
723
737
|
|
|
724
738
|
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX
|
|
725
|
-
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy) {
|
|
739
|
+
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy, panelGroupElement) {
|
|
726
740
|
if (isKeyDown(event)) {
|
|
727
741
|
const isHorizontal = direction === "horizontal";
|
|
728
742
|
let delta = 0;
|
|
@@ -759,7 +773,7 @@ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragSta
|
|
|
759
773
|
if (initialDragState == null) {
|
|
760
774
|
return 0;
|
|
761
775
|
}
|
|
762
|
-
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState);
|
|
776
|
+
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement);
|
|
763
777
|
}
|
|
764
778
|
}
|
|
765
779
|
|
|
@@ -1111,6 +1125,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1111
1125
|
...rest
|
|
1112
1126
|
}) {
|
|
1113
1127
|
const groupId = useUniqueId(idFromProps);
|
|
1128
|
+
const panelGroupElementRef = useRef(null);
|
|
1114
1129
|
const [dragState, setDragState] = useState(null);
|
|
1115
1130
|
const [layout, setLayout] = useState([]);
|
|
1116
1131
|
const panelIdToLastNotifiedSizeMapRef = useRef({});
|
|
@@ -1179,7 +1194,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1179
1194
|
groupId,
|
|
1180
1195
|
layout,
|
|
1181
1196
|
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1182
|
-
setLayout
|
|
1197
|
+
setLayout,
|
|
1198
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1183
1199
|
});
|
|
1184
1200
|
useEffect(() => {
|
|
1185
1201
|
const {
|
|
@@ -1422,6 +1438,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1422
1438
|
const registerResizeHandle = useCallback(dragHandleId => {
|
|
1423
1439
|
return function resizeHandler(event) {
|
|
1424
1440
|
event.preventDefault();
|
|
1441
|
+
const panelGroupElement = panelGroupElementRef.current;
|
|
1442
|
+
if (!panelGroupElement) {
|
|
1443
|
+
return () => null;
|
|
1444
|
+
}
|
|
1425
1445
|
const {
|
|
1426
1446
|
direction,
|
|
1427
1447
|
dragState,
|
|
@@ -1436,8 +1456,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1436
1456
|
const {
|
|
1437
1457
|
initialLayout
|
|
1438
1458
|
} = dragState !== null && dragState !== void 0 ? dragState : {};
|
|
1439
|
-
const pivotIndices = determinePivotIndices(groupId, dragHandleId);
|
|
1440
|
-
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy);
|
|
1459
|
+
const pivotIndices = determinePivotIndices(groupId, dragHandleId, panelGroupElement);
|
|
1460
|
+
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy, panelGroupElement);
|
|
1441
1461
|
if (delta === 0) {
|
|
1442
1462
|
return;
|
|
1443
1463
|
}
|
|
@@ -1532,7 +1552,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1532
1552
|
const {
|
|
1533
1553
|
layout
|
|
1534
1554
|
} = eagerValuesRef.current;
|
|
1535
|
-
|
|
1555
|
+
if (!panelGroupElementRef.current) {
|
|
1556
|
+
return;
|
|
1557
|
+
}
|
|
1558
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
|
|
1536
1559
|
assert(handleElement);
|
|
1537
1560
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1538
1561
|
setDragState({
|
|
@@ -1577,7 +1600,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1577
1600
|
resizePanel,
|
|
1578
1601
|
startDragging,
|
|
1579
1602
|
stopDragging,
|
|
1580
|
-
unregisterPanel
|
|
1603
|
+
unregisterPanel,
|
|
1604
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1581
1605
|
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1582
1606
|
const style = {
|
|
1583
1607
|
display: "flex",
|
|
@@ -1596,6 +1620,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1596
1620
|
...style,
|
|
1597
1621
|
...styleFromProps
|
|
1598
1622
|
},
|
|
1623
|
+
ref: panelGroupElementRef,
|
|
1599
1624
|
// CSS selectors
|
|
1600
1625
|
"data-panel-group": "",
|
|
1601
1626
|
"data-panel-group-direction": direction,
|
|
@@ -1630,13 +1655,14 @@ function panelDataHelper(panelDataArray, panelData, layout) {
|
|
|
1630
1655
|
function useWindowSplitterResizeHandlerBehavior({
|
|
1631
1656
|
disabled,
|
|
1632
1657
|
handleId,
|
|
1633
|
-
resizeHandler
|
|
1658
|
+
resizeHandler,
|
|
1659
|
+
panelGroupElement
|
|
1634
1660
|
}) {
|
|
1635
1661
|
useEffect(() => {
|
|
1636
|
-
if (disabled || resizeHandler == null) {
|
|
1662
|
+
if (disabled || resizeHandler == null || panelGroupElement == null) {
|
|
1637
1663
|
return;
|
|
1638
1664
|
}
|
|
1639
|
-
const handleElement = getResizeHandleElement(handleId);
|
|
1665
|
+
const handleElement = getResizeHandleElement(handleId, panelGroupElement);
|
|
1640
1666
|
if (handleElement == null) {
|
|
1641
1667
|
return;
|
|
1642
1668
|
}
|
|
@@ -1661,8 +1687,8 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1661
1687
|
event.preventDefault();
|
|
1662
1688
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
1663
1689
|
assert(groupId);
|
|
1664
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
1665
|
-
const index = getResizeHandleElementIndex(groupId, handleId);
|
|
1690
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1691
|
+
const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
|
|
1666
1692
|
assert(index !== null);
|
|
1667
1693
|
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
1668
1694
|
const nextHandle = handles[nextIndex];
|
|
@@ -1675,7 +1701,7 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1675
1701
|
return () => {
|
|
1676
1702
|
handleElement.removeEventListener("keydown", onKeyDown);
|
|
1677
1703
|
};
|
|
1678
|
-
}, [disabled, handleId, resizeHandler]);
|
|
1704
|
+
}, [panelGroupElement, disabled, handleId, resizeHandler]);
|
|
1679
1705
|
}
|
|
1680
1706
|
|
|
1681
1707
|
function PanelResizeHandle({
|
|
@@ -1708,7 +1734,8 @@ function PanelResizeHandle({
|
|
|
1708
1734
|
groupId,
|
|
1709
1735
|
registerResizeHandle,
|
|
1710
1736
|
startDragging,
|
|
1711
|
-
stopDragging
|
|
1737
|
+
stopDragging,
|
|
1738
|
+
panelGroupElement
|
|
1712
1739
|
} = panelGroupContext;
|
|
1713
1740
|
const resizeHandleId = useUniqueId(idFromProps);
|
|
1714
1741
|
const isDragging = (dragState === null || dragState === void 0 ? void 0 : dragState.dragHandleId) === resizeHandleId;
|
|
@@ -1767,7 +1794,8 @@ function PanelResizeHandle({
|
|
|
1767
1794
|
useWindowSplitterResizeHandlerBehavior({
|
|
1768
1795
|
disabled,
|
|
1769
1796
|
handleId: resizeHandleId,
|
|
1770
|
-
resizeHandler
|
|
1797
|
+
resizeHandler,
|
|
1798
|
+
panelGroupElement
|
|
1771
1799
|
});
|
|
1772
1800
|
const style = {
|
|
1773
1801
|
cursor: getCursorStyle(direction),
|
|
@@ -1823,13 +1851,12 @@ function PanelResizeHandle({
|
|
|
1823
1851
|
}
|
|
1824
1852
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1825
1853
|
|
|
1826
|
-
function calculateAvailablePanelSizeInPixels(groupId) {
|
|
1827
|
-
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1854
|
+
function calculateAvailablePanelSizeInPixels(groupId, panelGroupElement) {
|
|
1828
1855
|
if (panelGroupElement == null) {
|
|
1829
1856
|
return NaN;
|
|
1830
1857
|
}
|
|
1831
1858
|
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1832
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1859
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1833
1860
|
if (direction === "horizontal") {
|
|
1834
1861
|
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1835
1862
|
return accumulated + handle.offsetWidth;
|
|
@@ -1841,13 +1868,9 @@ function calculateAvailablePanelSizeInPixels(groupId) {
|
|
|
1841
1868
|
}
|
|
1842
1869
|
}
|
|
1843
1870
|
|
|
1844
|
-
function getAvailableGroupSizePixels(groupId) {
|
|
1845
|
-
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1846
|
-
if (panelGroupElement == null) {
|
|
1847
|
-
return NaN;
|
|
1848
|
-
}
|
|
1871
|
+
function getAvailableGroupSizePixels(groupId, panelGroupElement) {
|
|
1849
1872
|
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1850
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1873
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1851
1874
|
if (direction === "horizontal") {
|
|
1852
1875
|
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1853
1876
|
return accumulated + handle.offsetWidth;
|
|
@@ -1859,16 +1882,16 @@ function getAvailableGroupSizePixels(groupId) {
|
|
|
1859
1882
|
}
|
|
1860
1883
|
}
|
|
1861
1884
|
|
|
1862
|
-
function getPanelElement(id) {
|
|
1863
|
-
const element =
|
|
1885
|
+
function getPanelElement(id, panelGroupElement) {
|
|
1886
|
+
const element = panelGroupElement.querySelector(`[data-panel-id="${id}"]`);
|
|
1864
1887
|
if (element) {
|
|
1865
1888
|
return element;
|
|
1866
1889
|
}
|
|
1867
1890
|
return null;
|
|
1868
1891
|
}
|
|
1869
1892
|
|
|
1870
|
-
function getPanelElementsForGroup(groupId) {
|
|
1871
|
-
return Array.from(
|
|
1893
|
+
function getPanelElementsForGroup(groupId, panelGroupElement) {
|
|
1894
|
+
return Array.from(panelGroupElement.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1872
1895
|
}
|
|
1873
1896
|
|
|
1874
1897
|
exports.Panel = Panel;
|