react-resizable-panels 2.0.5 → 2.0.7
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 +8 -0
- package/dist/declarations/src/vendor/react.d.ts +3 -2
- package/dist/react-resizable-panels.browser.cjs.js +4 -3
- package/dist/react-resizable-panels.browser.development.cjs.js +4 -3
- package/dist/react-resizable-panels.browser.development.esm.js +4 -3
- package/dist/react-resizable-panels.browser.esm.js +4 -3
- package/dist/react-resizable-panels.cjs.js +4 -3
- package/dist/react-resizable-panels.development.cjs.js +4 -3
- package/dist/react-resizable-panels.development.esm.js +4 -3
- package/dist/react-resizable-panels.development.node.cjs.js +1 -4
- package/dist/react-resizable-panels.development.node.esm.js +1 -4
- package/dist/react-resizable-panels.esm.js +4 -3
- package/dist/react-resizable-panels.node.cjs.js +1 -4
- package/dist/react-resizable-panels.node.esm.js +1 -4
- package/package.json +1 -1
- package/src/PanelResizeHandle.ts +2 -2
- package/src/hooks/useIsomorphicEffect.ts +4 -2
- package/src/utils/computePanelFlexBoxStyle.test.ts +123 -0
- package/src/utils/computePanelFlexBoxStyle.ts +2 -1
- package/src/vendor/react.ts +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.0.7
|
|
4
|
+
|
|
5
|
+
- Group default layouts use `toPrecision` to avoid small layout shifts due to floating point precision differences between initial server rendering and client hydration (#295)
|
|
6
|
+
|
|
7
|
+
## 2.0.6
|
|
8
|
+
|
|
9
|
+
- Replace `useLayoutEffect` usage with SSR-safe wrapper hook (#294)
|
|
10
|
+
|
|
3
11
|
## 2.0.5
|
|
4
12
|
|
|
5
13
|
- Resize handle hit detection considers [stacking context](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context) when determining hit detection (#291)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import type { CSSProperties, ElementType, ForwardedRef, HTMLAttributes, MouseEvent, PropsWithChildren, ReactElement, ReactNode, RefObject, TouchEvent } from "react";
|
|
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,
|
|
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, useMemo: typeof React.useMemo, useRef: typeof React.useRef, useState: typeof React.useState;
|
|
4
4
|
declare const useId: () => string;
|
|
5
|
-
|
|
5
|
+
declare const useLayoutEffect_do_not_use_directly: typeof React.useLayoutEffect;
|
|
6
|
+
export { createElement, createContext, createRef, forwardRef, useCallback, useContext, useEffect, useId, useImperativeHandle, useLayoutEffect_do_not_use_directly, useMemo, useRef, useState, };
|
|
6
7
|
export type { CSSProperties, ElementType, ForwardedRef, HTMLAttributes, MouseEvent, PropsWithChildren, ReactElement, ReactNode, RefObject, TouchEvent, };
|
|
@@ -46,11 +46,12 @@ const {
|
|
|
46
46
|
|
|
47
47
|
// `toString()` prevents bundlers from trying to `import { useId } from 'react'`
|
|
48
48
|
const useId = React__namespace["useId".toString()];
|
|
49
|
+
const useLayoutEffect_do_not_use_directly = useLayoutEffect;
|
|
49
50
|
|
|
50
51
|
const PanelGroupContext = createContext(null);
|
|
51
52
|
PanelGroupContext.displayName = "PanelGroupContext";
|
|
52
53
|
|
|
53
|
-
const useIsomorphicLayoutEffect =
|
|
54
|
+
const useIsomorphicLayoutEffect = useLayoutEffect_do_not_use_directly ;
|
|
54
55
|
|
|
55
56
|
const wrappedUseId = typeof useId === "function" ? useId : () => null;
|
|
56
57
|
let counter = 0;
|
|
@@ -1244,7 +1245,7 @@ function computePanelFlexBoxStyle({
|
|
|
1244
1245
|
if (size == null) {
|
|
1245
1246
|
// Initial render (before panels have registered themselves)
|
|
1246
1247
|
// In order to support server rendering, fall back to default size if provided
|
|
1247
|
-
flexGrow = defaultSize
|
|
1248
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1248
1249
|
} else if (panelData.length === 1) {
|
|
1249
1250
|
// Special case: Single panel group should always fill full width/height
|
|
1250
1251
|
flexGrow = "1";
|
|
@@ -2098,7 +2099,7 @@ function PanelResizeHandle({
|
|
|
2098
2099
|
const committedValuesRef = useRef({
|
|
2099
2100
|
state
|
|
2100
2101
|
});
|
|
2101
|
-
|
|
2102
|
+
useIsomorphicLayoutEffect(() => {
|
|
2102
2103
|
committedValuesRef.current.state = state;
|
|
2103
2104
|
});
|
|
2104
2105
|
useEffect(() => {
|
|
@@ -46,11 +46,12 @@ const {
|
|
|
46
46
|
|
|
47
47
|
// `toString()` prevents bundlers from trying to `import { useId } from 'react'`
|
|
48
48
|
const useId = React__namespace["useId".toString()];
|
|
49
|
+
const useLayoutEffect_do_not_use_directly = useLayoutEffect;
|
|
49
50
|
|
|
50
51
|
const PanelGroupContext = createContext(null);
|
|
51
52
|
PanelGroupContext.displayName = "PanelGroupContext";
|
|
52
53
|
|
|
53
|
-
const useIsomorphicLayoutEffect =
|
|
54
|
+
const useIsomorphicLayoutEffect = useLayoutEffect_do_not_use_directly ;
|
|
54
55
|
|
|
55
56
|
const wrappedUseId = typeof useId === "function" ? useId : () => null;
|
|
56
57
|
let counter = 0;
|
|
@@ -1260,7 +1261,7 @@ function computePanelFlexBoxStyle({
|
|
|
1260
1261
|
if (size == null) {
|
|
1261
1262
|
// Initial render (before panels have registered themselves)
|
|
1262
1263
|
// In order to support server rendering, fall back to default size if provided
|
|
1263
|
-
flexGrow = defaultSize
|
|
1264
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1264
1265
|
} else if (panelData.length === 1) {
|
|
1265
1266
|
// Special case: Single panel group should always fill full width/height
|
|
1266
1267
|
flexGrow = "1";
|
|
@@ -2204,7 +2205,7 @@ function PanelResizeHandle({
|
|
|
2204
2205
|
const committedValuesRef = useRef({
|
|
2205
2206
|
state
|
|
2206
2207
|
});
|
|
2207
|
-
|
|
2208
|
+
useIsomorphicLayoutEffect(() => {
|
|
2208
2209
|
committedValuesRef.current.state = state;
|
|
2209
2210
|
});
|
|
2210
2211
|
useEffect(() => {
|
|
@@ -22,11 +22,12 @@ const {
|
|
|
22
22
|
|
|
23
23
|
// `toString()` prevents bundlers from trying to `import { useId } from 'react'`
|
|
24
24
|
const useId = React["useId".toString()];
|
|
25
|
+
const useLayoutEffect_do_not_use_directly = useLayoutEffect;
|
|
25
26
|
|
|
26
27
|
const PanelGroupContext = createContext(null);
|
|
27
28
|
PanelGroupContext.displayName = "PanelGroupContext";
|
|
28
29
|
|
|
29
|
-
const useIsomorphicLayoutEffect =
|
|
30
|
+
const useIsomorphicLayoutEffect = useLayoutEffect_do_not_use_directly ;
|
|
30
31
|
|
|
31
32
|
const wrappedUseId = typeof useId === "function" ? useId : () => null;
|
|
32
33
|
let counter = 0;
|
|
@@ -1236,7 +1237,7 @@ function computePanelFlexBoxStyle({
|
|
|
1236
1237
|
if (size == null) {
|
|
1237
1238
|
// Initial render (before panels have registered themselves)
|
|
1238
1239
|
// In order to support server rendering, fall back to default size if provided
|
|
1239
|
-
flexGrow = defaultSize
|
|
1240
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1240
1241
|
} else if (panelData.length === 1) {
|
|
1241
1242
|
// Special case: Single panel group should always fill full width/height
|
|
1242
1243
|
flexGrow = "1";
|
|
@@ -2180,7 +2181,7 @@ function PanelResizeHandle({
|
|
|
2180
2181
|
const committedValuesRef = useRef({
|
|
2181
2182
|
state
|
|
2182
2183
|
});
|
|
2183
|
-
|
|
2184
|
+
useIsomorphicLayoutEffect(() => {
|
|
2184
2185
|
committedValuesRef.current.state = state;
|
|
2185
2186
|
});
|
|
2186
2187
|
useEffect(() => {
|
|
@@ -22,11 +22,12 @@ const {
|
|
|
22
22
|
|
|
23
23
|
// `toString()` prevents bundlers from trying to `import { useId } from 'react'`
|
|
24
24
|
const useId = React["useId".toString()];
|
|
25
|
+
const useLayoutEffect_do_not_use_directly = useLayoutEffect;
|
|
25
26
|
|
|
26
27
|
const PanelGroupContext = createContext(null);
|
|
27
28
|
PanelGroupContext.displayName = "PanelGroupContext";
|
|
28
29
|
|
|
29
|
-
const useIsomorphicLayoutEffect =
|
|
30
|
+
const useIsomorphicLayoutEffect = useLayoutEffect_do_not_use_directly ;
|
|
30
31
|
|
|
31
32
|
const wrappedUseId = typeof useId === "function" ? useId : () => null;
|
|
32
33
|
let counter = 0;
|
|
@@ -1220,7 +1221,7 @@ function computePanelFlexBoxStyle({
|
|
|
1220
1221
|
if (size == null) {
|
|
1221
1222
|
// Initial render (before panels have registered themselves)
|
|
1222
1223
|
// In order to support server rendering, fall back to default size if provided
|
|
1223
|
-
flexGrow = defaultSize
|
|
1224
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1224
1225
|
} else if (panelData.length === 1) {
|
|
1225
1226
|
// Special case: Single panel group should always fill full width/height
|
|
1226
1227
|
flexGrow = "1";
|
|
@@ -2074,7 +2075,7 @@ function PanelResizeHandle({
|
|
|
2074
2075
|
const committedValuesRef = useRef({
|
|
2075
2076
|
state
|
|
2076
2077
|
});
|
|
2077
|
-
|
|
2078
|
+
useIsomorphicLayoutEffect(() => {
|
|
2078
2079
|
committedValuesRef.current.state = state;
|
|
2079
2080
|
});
|
|
2080
2081
|
useEffect(() => {
|
|
@@ -48,11 +48,12 @@ const {
|
|
|
48
48
|
|
|
49
49
|
// `toString()` prevents bundlers from trying to `import { useId } from 'react'`
|
|
50
50
|
const useId = React__namespace["useId".toString()];
|
|
51
|
+
const useLayoutEffect_do_not_use_directly = useLayoutEffect;
|
|
51
52
|
|
|
52
53
|
const PanelGroupContext = createContext(null);
|
|
53
54
|
PanelGroupContext.displayName = "PanelGroupContext";
|
|
54
55
|
|
|
55
|
-
const useIsomorphicLayoutEffect = isBrowser ?
|
|
56
|
+
const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect_do_not_use_directly : () => {};
|
|
56
57
|
|
|
57
58
|
const wrappedUseId = typeof useId === "function" ? useId : () => null;
|
|
58
59
|
let counter = 0;
|
|
@@ -1246,7 +1247,7 @@ function computePanelFlexBoxStyle({
|
|
|
1246
1247
|
if (size == null) {
|
|
1247
1248
|
// Initial render (before panels have registered themselves)
|
|
1248
1249
|
// In order to support server rendering, fall back to default size if provided
|
|
1249
|
-
flexGrow = defaultSize
|
|
1250
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1250
1251
|
} else if (panelData.length === 1) {
|
|
1251
1252
|
// Special case: Single panel group should always fill full width/height
|
|
1252
1253
|
flexGrow = "1";
|
|
@@ -2100,7 +2101,7 @@ function PanelResizeHandle({
|
|
|
2100
2101
|
const committedValuesRef = useRef({
|
|
2101
2102
|
state
|
|
2102
2103
|
});
|
|
2103
|
-
|
|
2104
|
+
useIsomorphicLayoutEffect(() => {
|
|
2104
2105
|
committedValuesRef.current.state = state;
|
|
2105
2106
|
});
|
|
2106
2107
|
useEffect(() => {
|
|
@@ -48,11 +48,12 @@ const {
|
|
|
48
48
|
|
|
49
49
|
// `toString()` prevents bundlers from trying to `import { useId } from 'react'`
|
|
50
50
|
const useId = React__namespace["useId".toString()];
|
|
51
|
+
const useLayoutEffect_do_not_use_directly = useLayoutEffect;
|
|
51
52
|
|
|
52
53
|
const PanelGroupContext = createContext(null);
|
|
53
54
|
PanelGroupContext.displayName = "PanelGroupContext";
|
|
54
55
|
|
|
55
|
-
const useIsomorphicLayoutEffect = isBrowser ?
|
|
56
|
+
const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect_do_not_use_directly : () => {};
|
|
56
57
|
|
|
57
58
|
const wrappedUseId = typeof useId === "function" ? useId : () => null;
|
|
58
59
|
let counter = 0;
|
|
@@ -1267,7 +1268,7 @@ function computePanelFlexBoxStyle({
|
|
|
1267
1268
|
if (size == null) {
|
|
1268
1269
|
// Initial render (before panels have registered themselves)
|
|
1269
1270
|
// In order to support server rendering, fall back to default size if provided
|
|
1270
|
-
flexGrow = defaultSize
|
|
1271
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1271
1272
|
} else if (panelData.length === 1) {
|
|
1272
1273
|
// Special case: Single panel group should always fill full width/height
|
|
1273
1274
|
flexGrow = "1";
|
|
@@ -2211,7 +2212,7 @@ function PanelResizeHandle({
|
|
|
2211
2212
|
const committedValuesRef = useRef({
|
|
2212
2213
|
state
|
|
2213
2214
|
});
|
|
2214
|
-
|
|
2215
|
+
useIsomorphicLayoutEffect(() => {
|
|
2215
2216
|
committedValuesRef.current.state = state;
|
|
2216
2217
|
});
|
|
2217
2218
|
useEffect(() => {
|
|
@@ -24,11 +24,12 @@ const {
|
|
|
24
24
|
|
|
25
25
|
// `toString()` prevents bundlers from trying to `import { useId } from 'react'`
|
|
26
26
|
const useId = React["useId".toString()];
|
|
27
|
+
const useLayoutEffect_do_not_use_directly = useLayoutEffect;
|
|
27
28
|
|
|
28
29
|
const PanelGroupContext = createContext(null);
|
|
29
30
|
PanelGroupContext.displayName = "PanelGroupContext";
|
|
30
31
|
|
|
31
|
-
const useIsomorphicLayoutEffect = isBrowser ?
|
|
32
|
+
const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect_do_not_use_directly : () => {};
|
|
32
33
|
|
|
33
34
|
const wrappedUseId = typeof useId === "function" ? useId : () => null;
|
|
34
35
|
let counter = 0;
|
|
@@ -1243,7 +1244,7 @@ function computePanelFlexBoxStyle({
|
|
|
1243
1244
|
if (size == null) {
|
|
1244
1245
|
// Initial render (before panels have registered themselves)
|
|
1245
1246
|
// In order to support server rendering, fall back to default size if provided
|
|
1246
|
-
flexGrow = defaultSize
|
|
1247
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1247
1248
|
} else if (panelData.length === 1) {
|
|
1248
1249
|
// Special case: Single panel group should always fill full width/height
|
|
1249
1250
|
flexGrow = "1";
|
|
@@ -2187,7 +2188,7 @@ function PanelResizeHandle({
|
|
|
2187
2188
|
const committedValuesRef = useRef({
|
|
2188
2189
|
state
|
|
2189
2190
|
});
|
|
2190
|
-
|
|
2191
|
+
useIsomorphicLayoutEffect(() => {
|
|
2191
2192
|
committedValuesRef.current.state = state;
|
|
2192
2193
|
});
|
|
2193
2194
|
useEffect(() => {
|
|
@@ -1106,7 +1106,7 @@ function computePanelFlexBoxStyle({
|
|
|
1106
1106
|
if (size == null) {
|
|
1107
1107
|
// Initial render (before panels have registered themselves)
|
|
1108
1108
|
// In order to support server rendering, fall back to default size if provided
|
|
1109
|
-
flexGrow = defaultSize
|
|
1109
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1110
1110
|
} else if (panelData.length === 1) {
|
|
1111
1111
|
// Special case: Single panel group should always fill full width/height
|
|
1112
1112
|
flexGrow = "1";
|
|
@@ -1980,9 +1980,6 @@ function PanelResizeHandle({
|
|
|
1980
1980
|
const committedValuesRef = useRef({
|
|
1981
1981
|
state
|
|
1982
1982
|
});
|
|
1983
|
-
useLayoutEffect(() => {
|
|
1984
|
-
committedValuesRef.current.state = state;
|
|
1985
|
-
});
|
|
1986
1983
|
useEffect(() => {
|
|
1987
1984
|
if (disabled) {
|
|
1988
1985
|
setResizeHandler(null);
|
|
@@ -1082,7 +1082,7 @@ function computePanelFlexBoxStyle({
|
|
|
1082
1082
|
if (size == null) {
|
|
1083
1083
|
// Initial render (before panels have registered themselves)
|
|
1084
1084
|
// In order to support server rendering, fall back to default size if provided
|
|
1085
|
-
flexGrow = defaultSize
|
|
1085
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1086
1086
|
} else if (panelData.length === 1) {
|
|
1087
1087
|
// Special case: Single panel group should always fill full width/height
|
|
1088
1088
|
flexGrow = "1";
|
|
@@ -1956,9 +1956,6 @@ function PanelResizeHandle({
|
|
|
1956
1956
|
const committedValuesRef = useRef({
|
|
1957
1957
|
state
|
|
1958
1958
|
});
|
|
1959
|
-
useLayoutEffect(() => {
|
|
1960
|
-
committedValuesRef.current.state = state;
|
|
1961
|
-
});
|
|
1962
1959
|
useEffect(() => {
|
|
1963
1960
|
if (disabled) {
|
|
1964
1961
|
setResizeHandler(null);
|
|
@@ -24,11 +24,12 @@ const {
|
|
|
24
24
|
|
|
25
25
|
// `toString()` prevents bundlers from trying to `import { useId } from 'react'`
|
|
26
26
|
const useId = React["useId".toString()];
|
|
27
|
+
const useLayoutEffect_do_not_use_directly = useLayoutEffect;
|
|
27
28
|
|
|
28
29
|
const PanelGroupContext = createContext(null);
|
|
29
30
|
PanelGroupContext.displayName = "PanelGroupContext";
|
|
30
31
|
|
|
31
|
-
const useIsomorphicLayoutEffect = isBrowser ?
|
|
32
|
+
const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect_do_not_use_directly : () => {};
|
|
32
33
|
|
|
33
34
|
const wrappedUseId = typeof useId === "function" ? useId : () => null;
|
|
34
35
|
let counter = 0;
|
|
@@ -1222,7 +1223,7 @@ function computePanelFlexBoxStyle({
|
|
|
1222
1223
|
if (size == null) {
|
|
1223
1224
|
// Initial render (before panels have registered themselves)
|
|
1224
1225
|
// In order to support server rendering, fall back to default size if provided
|
|
1225
|
-
flexGrow = defaultSize
|
|
1226
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1226
1227
|
} else if (panelData.length === 1) {
|
|
1227
1228
|
// Special case: Single panel group should always fill full width/height
|
|
1228
1229
|
flexGrow = "1";
|
|
@@ -2076,7 +2077,7 @@ function PanelResizeHandle({
|
|
|
2076
2077
|
const committedValuesRef = useRef({
|
|
2077
2078
|
state
|
|
2078
2079
|
});
|
|
2079
|
-
|
|
2080
|
+
useIsomorphicLayoutEffect(() => {
|
|
2080
2081
|
committedValuesRef.current.state = state;
|
|
2081
2082
|
});
|
|
2082
2083
|
useEffect(() => {
|
|
@@ -1095,7 +1095,7 @@ function computePanelFlexBoxStyle({
|
|
|
1095
1095
|
if (size == null) {
|
|
1096
1096
|
// Initial render (before panels have registered themselves)
|
|
1097
1097
|
// In order to support server rendering, fall back to default size if provided
|
|
1098
|
-
flexGrow = defaultSize
|
|
1098
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1099
1099
|
} else if (panelData.length === 1) {
|
|
1100
1100
|
// Special case: Single panel group should always fill full width/height
|
|
1101
1101
|
flexGrow = "1";
|
|
@@ -1879,9 +1879,6 @@ function PanelResizeHandle({
|
|
|
1879
1879
|
const committedValuesRef = useRef({
|
|
1880
1880
|
state
|
|
1881
1881
|
});
|
|
1882
|
-
useLayoutEffect(() => {
|
|
1883
|
-
committedValuesRef.current.state = state;
|
|
1884
|
-
});
|
|
1885
1882
|
useEffect(() => {
|
|
1886
1883
|
if (disabled) {
|
|
1887
1884
|
setResizeHandler(null);
|
|
@@ -1071,7 +1071,7 @@ function computePanelFlexBoxStyle({
|
|
|
1071
1071
|
if (size == null) {
|
|
1072
1072
|
// Initial render (before panels have registered themselves)
|
|
1073
1073
|
// In order to support server rendering, fall back to default size if provided
|
|
1074
|
-
flexGrow = defaultSize
|
|
1074
|
+
flexGrow = defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
1075
1075
|
} else if (panelData.length === 1) {
|
|
1076
1076
|
// Special case: Single panel group should always fill full width/height
|
|
1077
1077
|
flexGrow = "1";
|
|
@@ -1855,9 +1855,6 @@ function PanelResizeHandle({
|
|
|
1855
1855
|
const committedValuesRef = useRef({
|
|
1856
1856
|
state
|
|
1857
1857
|
});
|
|
1858
|
-
useLayoutEffect(() => {
|
|
1859
|
-
committedValuesRef.current.state = state;
|
|
1860
|
-
});
|
|
1861
1858
|
useEffect(() => {
|
|
1862
1859
|
if (disabled) {
|
|
1863
1860
|
setResizeHandler(null);
|
package/package.json
CHANGED
package/src/PanelResizeHandle.ts
CHANGED
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
ReactElement,
|
|
8
8
|
useContext,
|
|
9
9
|
useEffect,
|
|
10
|
-
useLayoutEffect,
|
|
11
10
|
useRef,
|
|
12
11
|
useState,
|
|
13
12
|
} from "./vendor/react";
|
|
@@ -24,6 +23,7 @@ import {
|
|
|
24
23
|
ResizeHandlerAction,
|
|
25
24
|
} from "./PanelResizeHandleRegistry";
|
|
26
25
|
import { assert } from "./utils/assert";
|
|
26
|
+
import useIsomorphicLayoutEffect from "./hooks/useIsomorphicEffect";
|
|
27
27
|
|
|
28
28
|
export type PanelResizeHandleOnDragging = (isDragging: boolean) => void;
|
|
29
29
|
export type ResizeHandlerState = "drag" | "hover" | "inactive";
|
|
@@ -97,7 +97,7 @@ export function PanelResizeHandle({
|
|
|
97
97
|
state,
|
|
98
98
|
});
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
useIsomorphicLayoutEffect(() => {
|
|
101
101
|
committedValuesRef.current.state = state;
|
|
102
102
|
});
|
|
103
103
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { isBrowser } from "#is-browser";
|
|
2
|
-
import {
|
|
2
|
+
import { useLayoutEffect_do_not_use_directly } from "../vendor/react";
|
|
3
3
|
|
|
4
|
-
const useIsomorphicLayoutEffect = isBrowser
|
|
4
|
+
const useIsomorphicLayoutEffect = isBrowser
|
|
5
|
+
? useLayoutEffect_do_not_use_directly
|
|
6
|
+
: () => {};
|
|
5
7
|
|
|
6
8
|
export default useIsomorphicLayoutEffect;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { PanelConstraints, PanelData } from "../Panel";
|
|
2
|
+
import { computePanelFlexBoxStyle } from "./computePanelFlexBoxStyle";
|
|
3
|
+
|
|
4
|
+
describe("computePanelFlexBoxStyle", () => {
|
|
5
|
+
function createPanelData(constraints: PanelConstraints = {}): PanelData {
|
|
6
|
+
return {
|
|
7
|
+
callbacks: {},
|
|
8
|
+
constraints,
|
|
9
|
+
id: "fake",
|
|
10
|
+
idIsFromProps: false,
|
|
11
|
+
order: undefined,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
it("should observe a panel's default size if group layout has not yet been computed", () => {
|
|
16
|
+
expect(
|
|
17
|
+
computePanelFlexBoxStyle({
|
|
18
|
+
defaultSize: 0.1233456789,
|
|
19
|
+
dragState: null,
|
|
20
|
+
layout: [],
|
|
21
|
+
panelData: [
|
|
22
|
+
createPanelData({
|
|
23
|
+
defaultSize: 0.1233456789,
|
|
24
|
+
}),
|
|
25
|
+
createPanelData(),
|
|
26
|
+
],
|
|
27
|
+
panelIndex: 0,
|
|
28
|
+
precision: 2,
|
|
29
|
+
})
|
|
30
|
+
).toMatchInlineSnapshot(`
|
|
31
|
+
{
|
|
32
|
+
"flexBasis": 0,
|
|
33
|
+
"flexGrow": "0.12",
|
|
34
|
+
"flexShrink": 1,
|
|
35
|
+
"overflow": "hidden",
|
|
36
|
+
"pointerEvents": undefined,
|
|
37
|
+
}
|
|
38
|
+
`);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should always fill the full width for single-panel groups", () => {
|
|
42
|
+
expect(
|
|
43
|
+
computePanelFlexBoxStyle({
|
|
44
|
+
defaultSize: undefined,
|
|
45
|
+
dragState: null,
|
|
46
|
+
layout: [],
|
|
47
|
+
panelData: [createPanelData()],
|
|
48
|
+
panelIndex: 0,
|
|
49
|
+
precision: 2,
|
|
50
|
+
})
|
|
51
|
+
).toMatchInlineSnapshot(`
|
|
52
|
+
{
|
|
53
|
+
"flexBasis": 0,
|
|
54
|
+
"flexGrow": "1",
|
|
55
|
+
"flexShrink": 1,
|
|
56
|
+
"overflow": "hidden",
|
|
57
|
+
"pointerEvents": undefined,
|
|
58
|
+
}
|
|
59
|
+
`);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("should round sizes to avoid floating point precision errors", () => {
|
|
63
|
+
const layout = [0.25435, 0.5758, 0.1698];
|
|
64
|
+
const panelData = [createPanelData(), createPanelData(), createPanelData()];
|
|
65
|
+
|
|
66
|
+
expect(
|
|
67
|
+
computePanelFlexBoxStyle({
|
|
68
|
+
defaultSize: undefined,
|
|
69
|
+
dragState: null,
|
|
70
|
+
layout,
|
|
71
|
+
panelData,
|
|
72
|
+
panelIndex: 0,
|
|
73
|
+
precision: 2,
|
|
74
|
+
})
|
|
75
|
+
).toMatchInlineSnapshot(`
|
|
76
|
+
{
|
|
77
|
+
"flexBasis": 0,
|
|
78
|
+
"flexGrow": "0.25",
|
|
79
|
+
"flexShrink": 1,
|
|
80
|
+
"overflow": "hidden",
|
|
81
|
+
"pointerEvents": undefined,
|
|
82
|
+
}
|
|
83
|
+
`);
|
|
84
|
+
|
|
85
|
+
expect(
|
|
86
|
+
computePanelFlexBoxStyle({
|
|
87
|
+
defaultSize: undefined,
|
|
88
|
+
dragState: null,
|
|
89
|
+
layout,
|
|
90
|
+
panelData,
|
|
91
|
+
panelIndex: 1,
|
|
92
|
+
precision: 2,
|
|
93
|
+
})
|
|
94
|
+
).toMatchInlineSnapshot(`
|
|
95
|
+
{
|
|
96
|
+
"flexBasis": 0,
|
|
97
|
+
"flexGrow": "0.58",
|
|
98
|
+
"flexShrink": 1,
|
|
99
|
+
"overflow": "hidden",
|
|
100
|
+
"pointerEvents": undefined,
|
|
101
|
+
}
|
|
102
|
+
`);
|
|
103
|
+
|
|
104
|
+
expect(
|
|
105
|
+
computePanelFlexBoxStyle({
|
|
106
|
+
defaultSize: undefined,
|
|
107
|
+
dragState: null,
|
|
108
|
+
layout,
|
|
109
|
+
panelData,
|
|
110
|
+
panelIndex: 2,
|
|
111
|
+
precision: 2,
|
|
112
|
+
})
|
|
113
|
+
).toMatchInlineSnapshot(`
|
|
114
|
+
{
|
|
115
|
+
"flexBasis": 0,
|
|
116
|
+
"flexGrow": "0.17",
|
|
117
|
+
"flexShrink": 1,
|
|
118
|
+
"overflow": "hidden",
|
|
119
|
+
"pointerEvents": undefined,
|
|
120
|
+
}
|
|
121
|
+
`);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
@@ -26,7 +26,8 @@ export function computePanelFlexBoxStyle({
|
|
|
26
26
|
if (size == null) {
|
|
27
27
|
// Initial render (before panels have registered themselves)
|
|
28
28
|
// In order to support server rendering, fall back to default size if provided
|
|
29
|
-
flexGrow =
|
|
29
|
+
flexGrow =
|
|
30
|
+
defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
|
|
30
31
|
} else if (panelData.length === 1) {
|
|
31
32
|
// Special case: Single panel group should always fill full width/height
|
|
32
33
|
flexGrow = "1";
|
package/src/vendor/react.ts
CHANGED
|
@@ -39,6 +39,8 @@ const {
|
|
|
39
39
|
// `toString()` prevents bundlers from trying to `import { useId } from 'react'`
|
|
40
40
|
const useId = (React as any)["useId".toString()] as () => string;
|
|
41
41
|
|
|
42
|
+
const useLayoutEffect_do_not_use_directly = useLayoutEffect;
|
|
43
|
+
|
|
42
44
|
export {
|
|
43
45
|
createElement,
|
|
44
46
|
createContext,
|
|
@@ -49,7 +51,7 @@ export {
|
|
|
49
51
|
useEffect,
|
|
50
52
|
useId,
|
|
51
53
|
useImperativeHandle,
|
|
52
|
-
|
|
54
|
+
useLayoutEffect_do_not_use_directly,
|
|
53
55
|
useMemo,
|
|
54
56
|
useRef,
|
|
55
57
|
useState,
|