react-resizable-panels 1.0.0-rc.3 → 1.0.0-rc.4

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.
@@ -1,149 +0,0 @@
1
- import { isDevelopment } from "#is-development";
2
- import { PanelData } from "./Panel";
3
- import { DragState, PanelGroupContext, ResizeEvent } from "./PanelGroupContext";
4
- import useIsomorphicLayoutEffect from "./hooks/useIsomorphicEffect";
5
- import useUniqueId from "./hooks/useUniqueId";
6
- import { useWindowSplitterPanelGroupBehavior } from "./hooks/useWindowSplitterPanelGroupBehavior";
7
- import { Direction } from "./types";
8
- import { adjustLayoutByDelta } from "./utils/adjustLayoutByDelta";
9
- import { areEqual } from "./utils/arrays";
10
- import { assert } from "./utils/assert";
11
- import { calculateDeltaPercentage } from "./utils/calculateDeltaPercentage";
12
- import { calculateUnsafeDefaultLayout } from "./utils/calculateUnsafeDefaultLayout";
13
- import { callPanelCallbacks } from "./utils/callPanelCallbacks";
14
- import { compareLayouts } from "./utils/compareLayouts";
15
- import { computePanelFlexBoxStyle } from "./utils/computePanelFlexBoxStyle";
16
- import { resetGlobalCursorStyle, setGlobalCursorStyle } from "./utils/cursor";
17
- import debounce from "./utils/debounce";
18
- import { determinePivotIndices } from "./utils/determinePivotIndices";
19
- import { getPanelElementsForGroup } from "./utils/dom/getPanelElementsForGroup";
20
- import { getResizeHandleElement } from "./utils/dom/getResizeHandleElement";
21
- import { isKeyDown, isMouseEvent, isTouchEvent } from "./utils/events";
22
- import { getResizeEventCursorPosition } from "./utils/getResizeEventCursorPosition";
23
- import { initializeDefaultStorage } from "./utils/initializeDefaultStorage";
24
- import { loadPanelLayout, savePanelGroupLayout } from "./utils/serialization";
25
- import { validatePanelConstraints } from "./utils/validatePanelConstraints";
26
- import { validatePanelGroupLayout } from "./utils/validatePanelGroupLayout";
27
- import {
28
- CSSProperties,
29
- ElementType,
30
- ForwardedRef,
31
- HTMLAttributes,
32
- PropsWithChildren,
33
- createElement,
34
- forwardRef,
35
- useCallback,
36
- useEffect,
37
- useImperativeHandle,
38
- useMemo,
39
- useRef,
40
- useState,
41
- } from "./vendor/react";
42
-
43
- const LOCAL_STORAGE_DEBOUNCE_INTERVAL = 100;
44
-
45
- export type ImperativePanelGroupHandle = {
46
- getId: () => string;
47
- getLayout: () => number[];
48
- setLayout: (layout: number[]) => void;
49
- };
50
-
51
- export type PanelGroupStorage = {
52
- getItem(name: string): string | null;
53
- setItem(name: string, value: string): void;
54
- };
55
-
56
- export type PanelGroupOnLayout = (layout: number[]) => void;
57
-
58
- const defaultStorage: PanelGroupStorage = {
59
- getItem: (name: string) => {
60
- initializeDefaultStorage(defaultStorage);
61
- return defaultStorage.getItem(name);
62
- },
63
- setItem: (name: string, value: string) => {
64
- initializeDefaultStorage(defaultStorage);
65
- defaultStorage.setItem(name, value);
66
- },
67
- };
68
-
69
- export type PanelGroupProps = Omit<HTMLAttributes<ElementType>, "id"> &
70
- PropsWithChildren<{
71
- autoSaveId?: string | null;
72
- className?: string;
73
- direction: Direction;
74
- id?: string | null;
75
- keyboardResizeBy?: number | null;
76
- onLayout?: PanelGroupOnLayout | null;
77
- storage?: PanelGroupStorage;
78
- style?: CSSProperties;
79
- tagName?: ElementType;
80
- }>;
81
-
82
- const debounceMap: {
83
- [key: string]: typeof savePanelGroupLayout;
84
- } = {};
85
-
86
- function PanelGroupWithForwardedRef({
87
- autoSaveId = null,
88
- children,
89
- className: classNameFromProps = "",
90
- direction,
91
- forwardedRef,
92
- id: idFromProps = null,
93
- onLayout = null,
94
- keyboardResizeBy = null,
95
- storage = defaultStorage,
96
- style: styleFromProps,
97
- tagName: Type = "div",
98
- ...rest
99
- }: PanelGroupProps & {
100
- forwardedRef: ForwardedRef<ImperativePanelGroupHandle>;
101
- }) {
102
- const groupId = useUniqueId(idFromProps);
103
-
104
- const stateRef = useRef<{
105
- layout: number[];
106
- }>({
107
- layout: [],
108
- });
109
-
110
- const context = null as any;
111
-
112
- const style: CSSProperties = {
113
- display: "flex",
114
- flexDirection: direction === "horizontal" ? "row" : "column",
115
- height: "100%",
116
- overflow: "hidden",
117
- width: "100%",
118
- };
119
-
120
- return createElement(
121
- PanelGroupContext.Provider,
122
- { value: context },
123
- createElement(Type, {
124
- ...rest,
125
-
126
- children,
127
- className: classNameFromProps,
128
- style: {
129
- ...style,
130
- ...styleFromProps,
131
- },
132
-
133
- // CSS selectors
134
- "data-panel-group": "",
135
- "data-panel-group-direction": direction,
136
- "data-panel-group-id": groupId,
137
- })
138
- );
139
- }
140
-
141
- export const PanelGroup = forwardRef<
142
- ImperativePanelGroupHandle,
143
- PanelGroupProps
144
- >((props: PanelGroupProps, ref: ForwardedRef<ImperativePanelGroupHandle>) =>
145
- createElement(PanelGroupWithForwardedRef, { ...props, forwardedRef: ref })
146
- );
147
-
148
- PanelGroupWithForwardedRef.displayName = "PanelGroup";
149
- PanelGroup.displayName = "forwardRef(PanelGroup)";