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.
@@ -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
@@ -18,7 +18,7 @@ export type PanelData = {
18
18
  onResize: PanelOnResize | null;
19
19
  }>;
20
20
  collapsible: boolean;
21
- defaultSize: number;
21
+ defaultSize: number | null;
22
22
  id: string;
23
23
  maxSize: number;
24
24
  minSize: number;
@@ -0,0 +1,10 @@
1
+ export function assert(
2
+ expectedCondition: boolean,
3
+ message: string = "Assertion failed!"
4
+ ): asserts expectedCondition {
5
+ if (!expectedCondition) {
6
+ console.error(message);
7
+
8
+ throw Error(message);
9
+ }
10
+ }
@@ -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
 
@@ -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
- clearTimeout(timeoutId);
8
+ if (timeoutId !== null) {
9
+ clearTimeout(timeoutId);
10
+ }
9
11
 
10
12
  timeoutId = setTimeout(() => {
11
13
  callback(...args);
@@ -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((a, b) => a.order - b.order);
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(