react-resizable-panels 0.0.39 → 0.0.41
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/README.md +2 -0
- package/dist/react-resizable-panels.d.ts +5 -28
- package/dist/react-resizable-panels.d.ts.map +1 -1
- package/dist/react-resizable-panels.js +53 -24
- package/dist/react-resizable-panels.js.map +1 -1
- package/dist/react-resizable-panels.module.js +53 -24
- package/dist/react-resizable-panels.module.js.map +1 -1
- package/package.json +2 -2
- package/src/Panel.ts +1 -1
- package/src/PanelGroup.ts +45 -9
- package/src/PanelResizeHandle.ts +4 -4
- package/src/hooks/useWindowSplitterBehavior.ts +7 -4
- package/src/index.ts +1 -1
- package/src/types.ts +1 -1
- package/src/utils/assert.ts +10 -0
- package/src/utils/coordinates.ts +2 -2
- package/src/utils/debounce.ts +3 -1
- package/src/utils/group.ts +15 -3
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
getFlexGrow,
|
|
16
16
|
panelsMapToSortedArray,
|
|
17
17
|
} from "../utils/group";
|
|
18
|
+
import { assert } from "../utils/assert";
|
|
18
19
|
|
|
19
20
|
// https://www.w3.org/WAI/ARIA/apg/patterns/windowsplitter/
|
|
20
21
|
|
|
@@ -34,14 +35,14 @@ export function useWindowSplitterPanelGroupBehavior({
|
|
|
34
35
|
panelSizeBeforeCollapse: RefObject<Map<string, number>>;
|
|
35
36
|
}): void {
|
|
36
37
|
useEffect(() => {
|
|
37
|
-
const { direction, panels } = committedValuesRef.current
|
|
38
|
+
const { direction, panels } = committedValuesRef.current!;
|
|
38
39
|
|
|
39
|
-
const groupElement = getPanelGroup(groupId)
|
|
40
|
+
const groupElement = getPanelGroup(groupId)!;
|
|
40
41
|
const { height, width } = groupElement.getBoundingClientRect();
|
|
41
42
|
|
|
42
43
|
const handles = getResizeHandlesForGroup(groupId);
|
|
43
44
|
const cleanupFunctions = handles.map((handle) => {
|
|
44
|
-
const handleId = handle.getAttribute("data-panel-resize-handle-id")
|
|
45
|
+
const handleId = handle.getAttribute("data-panel-resize-handle-id")!;
|
|
45
46
|
const panelsArray = panelsMapToSortedArray(panels);
|
|
46
47
|
|
|
47
48
|
const [idBefore, idAfter] = getResizeHandlePanelIds(
|
|
@@ -114,7 +115,7 @@ export function useWindowSplitterPanelGroupBehavior({
|
|
|
114
115
|
idAfter,
|
|
115
116
|
delta,
|
|
116
117
|
sizes,
|
|
117
|
-
panelSizeBeforeCollapse.current
|
|
118
|
+
panelSizeBeforeCollapse.current!,
|
|
118
119
|
null
|
|
119
120
|
);
|
|
120
121
|
if (sizes !== nextSizes) {
|
|
@@ -202,6 +203,8 @@ export function useWindowSplitterResizeHandlerBehavior({
|
|
|
202
203
|
const handles = getResizeHandles();
|
|
203
204
|
const index = getResizeHandleIndex(handleId);
|
|
204
205
|
|
|
206
|
+
assert(index !== null);
|
|
207
|
+
|
|
205
208
|
const nextIndex = event.shiftKey
|
|
206
209
|
? index > 0
|
|
207
210
|
? index - 1
|
package/src/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { PanelGroup } from "./PanelGroup";
|
|
|
3
3
|
import { PanelResizeHandle } from "./PanelResizeHandle";
|
|
4
4
|
|
|
5
5
|
import type { ImperativePanelHandle, PanelProps } from "./Panel";
|
|
6
|
-
import type { PanelGroupProps } from "./PanelGroup";
|
|
6
|
+
import type { ImperativePanelGroupHandle, PanelGroupProps } from "./PanelGroup";
|
|
7
7
|
import type { PanelResizeHandleProps } from "./PanelResizeHandle";
|
|
8
8
|
import type { PanelGroupStorage } from "./types";
|
|
9
9
|
|
package/src/types.ts
CHANGED
package/src/utils/coordinates.ts
CHANGED
|
@@ -36,7 +36,7 @@ export function getDragOffset(
|
|
|
36
36
|
return 0;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
const handleElement = getResizeHandle(handleId)
|
|
39
|
+
const handleElement = getResizeHandle(handleId)!;
|
|
40
40
|
const rect =
|
|
41
41
|
initialHandleElementRect || handleElement.getBoundingClientRect();
|
|
42
42
|
const elementOffset = isHorizontal ? rect.left : rect.top;
|
|
@@ -67,7 +67,7 @@ export function getMovement(
|
|
|
67
67
|
if (isKeyDown(event)) {
|
|
68
68
|
const isHorizontal = direction === "horizontal";
|
|
69
69
|
|
|
70
|
-
const groupElement = getPanelGroup(groupId)
|
|
70
|
+
const groupElement = getPanelGroup(groupId)!;
|
|
71
71
|
const rect = groupElement.getBoundingClientRect();
|
|
72
72
|
const groupSizeInPixels = isHorizontal ? rect.width : rect.height;
|
|
73
73
|
|
package/src/utils/debounce.ts
CHANGED
|
@@ -5,7 +5,9 @@ export default function debounce<T extends Function>(
|
|
|
5
5
|
let timeoutId: NodeJS.Timeout | null = null;
|
|
6
6
|
|
|
7
7
|
let callable = (...args: any) => {
|
|
8
|
-
|
|
8
|
+
if (timeoutId !== null) {
|
|
9
|
+
clearTimeout(timeoutId);
|
|
10
|
+
}
|
|
9
11
|
|
|
10
12
|
timeoutId = setTimeout(() => {
|
|
11
13
|
callback(...args);
|
package/src/utils/group.ts
CHANGED
|
@@ -124,7 +124,7 @@ export function callPanelCallbacks(
|
|
|
124
124
|
const prevSize = prevSizes[index];
|
|
125
125
|
if (prevSize !== nextSize) {
|
|
126
126
|
const { callbacksRef, collapsible } = panelsArray[index];
|
|
127
|
-
const { onCollapse, onResize } = callbacksRef.current
|
|
127
|
+
const { onCollapse, onResize } = callbacksRef.current!;
|
|
128
128
|
|
|
129
129
|
if (onResize) {
|
|
130
130
|
onResize(nextSize);
|
|
@@ -238,7 +238,7 @@ export function getResizeHandlePanelIds(
|
|
|
238
238
|
): [idBefore: string | null, idAfter: string | null] {
|
|
239
239
|
const handle = getResizeHandle(handleId);
|
|
240
240
|
const handles = getResizeHandlesForGroup(groupId);
|
|
241
|
-
const index = handles.indexOf(handle);
|
|
241
|
+
const index = handle ? handles.indexOf(handle) : -1;
|
|
242
242
|
|
|
243
243
|
const idBefore: string | null = panelsArray[index]?.id ?? null;
|
|
244
244
|
const idAfter: string | null = panelsArray[index + 1]?.id ?? null;
|
|
@@ -249,7 +249,19 @@ export function getResizeHandlePanelIds(
|
|
|
249
249
|
export function panelsMapToSortedArray(
|
|
250
250
|
panels: Map<string, PanelData>
|
|
251
251
|
): PanelData[] {
|
|
252
|
-
return Array.from(panels.values()).sort((
|
|
252
|
+
return Array.from(panels.values()).sort((panelA, panelB) => {
|
|
253
|
+
const orderA = panelA.order;
|
|
254
|
+
const orderB = panelB.order;
|
|
255
|
+
if (orderA == null && orderB == null) {
|
|
256
|
+
return 0;
|
|
257
|
+
} else if (orderA == null) {
|
|
258
|
+
return -1;
|
|
259
|
+
} else if (orderB == null) {
|
|
260
|
+
return 1;
|
|
261
|
+
} else {
|
|
262
|
+
return orderA - orderB;
|
|
263
|
+
}
|
|
264
|
+
});
|
|
253
265
|
}
|
|
254
266
|
|
|
255
267
|
function safeResizePanel(
|