react-panel-layout 0.6.0 → 0.6.1
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/dist/{FloatingPanelFrame-SgYLc6Ud.js → FloatingPanelFrame-3eU9AwPo.js} +2 -2
- package/dist/{FloatingPanelFrame-SgYLc6Ud.js.map → FloatingPanelFrame-3eU9AwPo.js.map} +1 -1
- package/dist/FloatingWindow-CUXnEtrb.js +827 -0
- package/dist/FloatingWindow-CUXnEtrb.js.map +1 -0
- package/dist/FloatingWindow-DMwyK0eK.cjs +2 -0
- package/dist/FloatingWindow-DMwyK0eK.cjs.map +1 -0
- package/dist/GridLayout-DKTg_N61.cjs +2 -0
- package/dist/{GridLayout-B4VRsC0r.cjs.map → GridLayout-DKTg_N61.cjs.map} +1 -1
- package/dist/{GridLayout-BltqeCPK.js → GridLayout-UWNxXw77.js} +34 -35
- package/dist/{GridLayout-BltqeCPK.js.map → GridLayout-UWNxXw77.js.map} +1 -1
- package/dist/{HorizontalDivider-WF1k_qND.js → HorizontalDivider-DdxzfV0l.js} +3 -3
- package/dist/{HorizontalDivider-WF1k_qND.js.map → HorizontalDivider-DdxzfV0l.js.map} +1 -1
- package/dist/{HorizontalDivider-B5Z-KZLk.cjs → HorizontalDivider-_pgV4Mcv.cjs} +2 -2
- package/dist/{HorizontalDivider-B5Z-KZLk.cjs.map → HorizontalDivider-_pgV4Mcv.cjs.map} +1 -1
- package/dist/{PanelSystem-Dr1TBhxM.js → PanelSystem-BqUzNtf2.js} +5 -5
- package/dist/{PanelSystem-Dr1TBhxM.js.map → PanelSystem-BqUzNtf2.js.map} +1 -1
- package/dist/{PanelSystem-Bs8bQwQF.cjs → PanelSystem-D603LKKv.cjs} +2 -2
- package/dist/{PanelSystem-Bs8bQwQF.cjs.map → PanelSystem-D603LKKv.cjs.map} +1 -1
- package/dist/ResizeHandle-CBcAS918.cjs +2 -0
- package/dist/{ResizeHandle-CScipO5l.cjs.map → ResizeHandle-CBcAS918.cjs.map} +1 -1
- package/dist/{ResizeHandle-CdA_JYfN.js → ResizeHandle-CXjc1meV.js} +28 -29
- package/dist/{ResizeHandle-CdA_JYfN.js.map → ResizeHandle-CXjc1meV.js.map} +1 -1
- package/dist/SwipePivotTabBar-DWrCuwEI.js +411 -0
- package/dist/SwipePivotTabBar-DWrCuwEI.js.map +1 -0
- package/dist/SwipePivotTabBar-fjjXkpj7.cjs +2 -0
- package/dist/SwipePivotTabBar-fjjXkpj7.cjs.map +1 -0
- package/dist/components/gesture/SwipeSafeZone.d.ts +40 -0
- package/dist/components/window/Drawer.d.ts +3 -1
- package/dist/components/window/DrawerLayers.d.ts +1 -1
- package/dist/components/window/drawerStyles.d.ts +69 -0
- package/dist/components/window/drawerSwipeConfig.d.ts +29 -0
- package/dist/components/window/useDrawerSwipeTransform.d.ts +23 -0
- package/dist/config.cjs +1 -1
- package/dist/config.js +3 -3
- package/dist/constants/styles.d.ts +17 -0
- package/dist/dialog/index.d.ts +69 -0
- package/dist/floating.js +1 -1
- package/dist/grid.cjs +1 -1
- package/dist/grid.js +2 -2
- package/dist/hooks/gesture/testing/createGestureSimulator.d.ts +7 -0
- package/dist/hooks/gesture/types.d.ts +48 -5
- package/dist/hooks/gesture/utils.d.ts +19 -0
- package/dist/hooks/useAnimationFrame.d.ts +2 -0
- package/dist/hooks/useOperationContinuity.d.ts +64 -0
- package/dist/hooks/useResizeObserver.d.ts +33 -1
- package/dist/hooks/useSharedElementTransition.d.ts +112 -0
- package/dist/hooks/useSwipeContentTransform.d.ts +9 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +7 -7
- package/dist/modules/dialog/AlertDialog.d.ts +9 -0
- package/dist/modules/dialog/DialogContainer.d.ts +37 -0
- package/dist/modules/dialog/Modal.d.ts +26 -0
- package/dist/modules/dialog/SwipeDialogContainer.d.ts +16 -0
- package/dist/modules/dialog/dialogAnimationUtils.d.ts +113 -0
- package/dist/modules/dialog/types.d.ts +183 -0
- package/dist/modules/dialog/useDialog.d.ts +39 -0
- package/dist/modules/dialog/useDialogContainer.d.ts +47 -0
- package/dist/modules/dialog/useDialogSwipeInput.d.ts +70 -0
- package/dist/modules/dialog/useDialogTransform.d.ts +82 -0
- package/dist/modules/drawer/types.d.ts +74 -0
- package/dist/modules/drawer/useDrawerSwipeInput.d.ts +24 -0
- package/dist/modules/pivot/SwipePivotTabBar.d.ts +3 -0
- package/dist/modules/stack/SwipeStackContent.d.ts +6 -3
- package/dist/modules/stack/SwipeStackOutlet.d.ts +4 -4
- package/dist/modules/stack/computeSwipeStackTransform.d.ts +1 -1
- package/dist/panels.cjs +1 -1
- package/dist/panels.js +1 -1
- package/dist/pivot.cjs +1 -1
- package/dist/pivot.js +1 -1
- package/dist/resizer.cjs +1 -1
- package/dist/resizer.js +2 -2
- package/dist/stack.cjs +1 -1
- package/dist/stack.cjs.map +1 -1
- package/dist/stack.js +503 -762
- package/dist/stack.js.map +1 -1
- package/dist/sticky-header/calculateStickyMetrics.d.ts +28 -0
- package/dist/sticky-header.cjs +1 -1
- package/dist/sticky-header.cjs.map +1 -1
- package/dist/sticky-header.js +59 -51
- package/dist/sticky-header.js.map +1 -1
- package/dist/{styles-DPPuJ0sf.js → styles-NkjuMOVS.js} +13 -13
- package/dist/{styles-DPPuJ0sf.js.map → styles-NkjuMOVS.js.map} +1 -1
- package/dist/styles-qf6ptVLD.cjs.map +1 -1
- package/dist/types.d.ts +16 -0
- package/dist/useDocumentPointerEvents-DXxw3qWj.js +54 -0
- package/dist/useDocumentPointerEvents-DXxw3qWj.js.map +1 -0
- package/dist/useDocumentPointerEvents-DxDSOtip.cjs +2 -0
- package/dist/useDocumentPointerEvents-DxDSOtip.cjs.map +1 -0
- package/dist/useNativeGestureGuard-C7TSqEkr.cjs +2 -0
- package/dist/useNativeGestureGuard-C7TSqEkr.cjs.map +1 -0
- package/dist/useNativeGestureGuard-CGYo6O0r.js +347 -0
- package/dist/useNativeGestureGuard-CGYo6O0r.js.map +1 -0
- package/dist/window/index.d.ts +2 -0
- package/dist/window.cjs +1 -1
- package/dist/window.cjs.map +1 -1
- package/dist/window.js +114 -103
- package/dist/window.js.map +1 -1
- package/package.json +6 -1
- package/src/components/gesture/SwipeSafeZone.tsx +69 -0
- package/src/components/window/Drawer.tsx +249 -162
- package/src/components/window/DrawerLayers.tsx +13 -3
- package/src/components/window/drawerStyles.spec.ts +263 -0
- package/src/components/window/drawerStyles.ts +228 -0
- package/src/components/window/drawerSwipeConfig.spec.ts +131 -0
- package/src/components/window/drawerSwipeConfig.ts +112 -0
- package/src/components/window/useDrawerSwipeTransform.spec.ts +234 -0
- package/src/components/window/useDrawerSwipeTransform.ts +129 -0
- package/src/constants/styles.ts +19 -0
- package/src/demo/pages/Dialog/alerts/index.tsx +22 -0
- package/src/demo/pages/Dialog/card/index.tsx +22 -0
- package/src/demo/pages/Dialog/components/AlertDialogDemo.tsx +124 -0
- package/src/demo/pages/Dialog/components/CardExpandDemo.module.css +243 -0
- package/src/demo/pages/Dialog/components/CardExpandDemo.tsx +204 -0
- package/src/demo/pages/Dialog/components/CustomAlertDialogDemo.tsx +219 -0
- package/src/demo/pages/Dialog/components/DialogDemos.module.css +77 -0
- package/src/demo/pages/Dialog/components/ModalBasics.tsx +45 -0
- package/src/demo/pages/Dialog/components/SwipeDialogDemo.module.css +77 -0
- package/src/demo/pages/Dialog/components/SwipeDialogDemo.tsx +181 -0
- package/src/demo/pages/Dialog/custom-alert/index.tsx +22 -0
- package/src/demo/pages/Dialog/modal/index.tsx +17 -0
- package/src/demo/pages/Dialog/swipe/index.tsx +22 -0
- package/src/demo/pages/Drawer/components/DrawerSwipe.module.css +316 -0
- package/src/demo/pages/Drawer/components/DrawerSwipe.tsx +178 -0
- package/src/demo/pages/Drawer/swipe/index.tsx +17 -0
- package/src/demo/pages/Pivot/components/SwipeTabsPivot.tsx +54 -23
- package/src/demo/pages/Pivot/swipe-debug/index.tsx +1 -1
- package/src/demo/pages/Stack/components/StackBasics.spec.tsx +152 -0
- package/src/demo/pages/Stack/components/StackBasics.tsx +179 -95
- package/src/demo/pages/Stack/components/StackTablet.spec.tsx +120 -0
- package/src/demo/pages/Stack/components/StackTablet.tsx +42 -21
- package/src/demo/routes.tsx +22 -1
- package/src/dialog/index.ts +85 -0
- package/src/hooks/gesture/testing/createGestureSimulator.spec.ts +68 -64
- package/src/hooks/gesture/testing/createGestureSimulator.ts +112 -37
- package/src/hooks/gesture/types.ts +83 -6
- package/src/hooks/gesture/useEdgeSwipeInput.spec.ts +22 -14
- package/src/hooks/gesture/useNativeGestureGuard.spec.ts +91 -31
- package/src/hooks/gesture/useNativeGestureGuard.ts +3 -1
- package/src/hooks/gesture/utils.ts +91 -0
- package/src/hooks/useAnimatedVisibility.spec.ts +44 -24
- package/src/hooks/useAnimatedVisibility.ts +28 -2
- package/src/hooks/useAnimationFrame.ts +8 -0
- package/src/hooks/useOperationContinuity.spec.ts +387 -0
- package/src/hooks/useOperationContinuity.ts +135 -0
- package/src/hooks/useResizeObserver.spec.tsx +277 -0
- package/src/hooks/useResizeObserver.tsx +108 -39
- package/src/hooks/useScrollContainer.ts +4 -10
- package/src/hooks/useSharedElementTransition.ts +333 -0
- package/src/hooks/useSwipeContentTransform.spec.ts +18 -18
- package/src/hooks/useSwipeContentTransform.ts +166 -28
- package/src/modules/dialog/AlertDialog.spec.tsx +387 -0
- package/src/modules/dialog/AlertDialog.tsx +221 -0
- package/src/modules/dialog/DialogContainer.spec.tsx +228 -0
- package/src/modules/dialog/DialogContainer.tsx +188 -0
- package/src/modules/dialog/Modal.spec.tsx +220 -0
- package/src/modules/dialog/Modal.tsx +182 -0
- package/src/modules/dialog/SwipeDialogContainer.tsx +208 -0
- package/src/modules/dialog/dialogAnimationUtils.spec.ts +253 -0
- package/src/modules/dialog/dialogAnimationUtils.ts +297 -0
- package/src/modules/dialog/types.ts +186 -0
- package/src/modules/dialog/useDialog.spec.tsx +447 -0
- package/src/modules/dialog/useDialog.ts +214 -0
- package/src/modules/dialog/useDialogContainer.spec.ts +331 -0
- package/src/modules/dialog/useDialogContainer.ts +150 -0
- package/src/modules/dialog/useDialogSwipeInput.spec.ts +157 -0
- package/src/modules/dialog/useDialogSwipeInput.ts +319 -0
- package/src/modules/dialog/useDialogTransform.spec.ts +370 -0
- package/src/modules/dialog/useDialogTransform.ts +407 -0
- package/src/modules/drawer/types.ts +102 -0
- package/src/modules/drawer/useDrawerSwipeInput.spec.ts +566 -0
- package/src/modules/drawer/useDrawerSwipeInput.ts +399 -0
- package/src/modules/panels/rendering/ContentRegistry.spec.tsx +21 -14
- package/src/modules/pivot/SwipePivotContent.position.spec.tsx +12 -8
- package/src/modules/pivot/SwipePivotContent.spec.tsx +55 -25
- package/src/modules/pivot/SwipePivotContent.tsx +2 -2
- package/src/modules/pivot/SwipePivotTabBar.spec.tsx +85 -68
- package/src/modules/pivot/SwipePivotTabBar.tsx +75 -15
- package/src/modules/pivot/scaleInputState.spec.ts +11 -2
- package/src/modules/pivot/usePivot.spec.ts +17 -3
- package/src/modules/pivot/usePivotSwipeInput.spec.ts +182 -123
- package/src/modules/stack/SwipeStackContent.spec.tsx +387 -100
- package/src/modules/stack/SwipeStackContent.tsx +43 -33
- package/src/modules/stack/SwipeStackOutlet.spec.tsx +14 -16
- package/src/modules/stack/SwipeStackOutlet.tsx +6 -6
- package/src/modules/stack/computeSwipeStackTransform.spec.ts +5 -5
- package/src/modules/stack/computeSwipeStackTransform.ts +3 -3
- package/src/modules/stack/swipeTransitionContinuity.spec.tsx +1133 -0
- package/src/modules/stack/useStackAnimationState.spec.ts +3 -1
- package/src/modules/stack/useStackAnimationState.ts +18 -13
- package/src/modules/stack/useStackNavigation.spec.ts +198 -3
- package/src/modules/stack/useStackNavigation.tsx +113 -56
- package/src/modules/stack/useStackSwipeInput.spec.ts +65 -32
- package/src/modules/stack/useStackSwipeInput.ts +1 -1
- package/src/sticky-header/StickyArea.tsx +29 -57
- package/src/sticky-header/calculateStickyMetrics.spec.ts +105 -0
- package/src/sticky-header/calculateStickyMetrics.ts +50 -0
- package/src/types.ts +18 -0
- package/src/window/index.ts +2 -0
- package/dist/FloatingWindow-BpdOpg_L.js +0 -400
- package/dist/FloatingWindow-BpdOpg_L.js.map +0 -1
- package/dist/FloatingWindow-TCDNY5gE.cjs +0 -2
- package/dist/FloatingWindow-TCDNY5gE.cjs.map +0 -1
- package/dist/GridLayout-B4VRsC0r.cjs +0 -2
- package/dist/ResizeHandle-CScipO5l.cjs +0 -2
- package/dist/SwipePivotTabBar-BGO9X94m.js +0 -407
- package/dist/SwipePivotTabBar-BGO9X94m.js.map +0 -1
- package/dist/SwipePivotTabBar-BrQismcZ.cjs +0 -2
- package/dist/SwipePivotTabBar-BrQismcZ.cjs.map +0 -1
- package/dist/useDocumentPointerEvents-CKdhGXd0.js +0 -46
- package/dist/useDocumentPointerEvents-CKdhGXd0.js.map +0 -1
- package/dist/useDocumentPointerEvents-ChqrKXDk.cjs +0 -2
- package/dist/useDocumentPointerEvents-ChqrKXDk.cjs.map +0 -1
- package/dist/useEffectEvent-Dp7HLCf0.js +0 -13
- package/dist/useEffectEvent-Dp7HLCf0.js.map +0 -1
- package/dist/useEffectEvent-huSsGUnl.cjs +0 -2
- package/dist/useEffectEvent-huSsGUnl.cjs.map +0 -1
|
@@ -6,29 +6,57 @@ import * as React from "react";
|
|
|
6
6
|
import { usePivotSwipeInput } from "./usePivotSwipeInput.js";
|
|
7
7
|
import type { UsePivotResult } from "./types.js";
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
type CallTracker = {
|
|
10
|
+
calls: ReadonlyArray<ReadonlyArray<unknown>>;
|
|
11
|
+
fn: (...args: ReadonlyArray<unknown>) => void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const createCallTracker = (): CallTracker => {
|
|
15
|
+
const calls: Array<ReadonlyArray<unknown>> = [];
|
|
16
|
+
const fn = (...args: ReadonlyArray<unknown>): void => {
|
|
17
|
+
calls.push(args);
|
|
18
|
+
};
|
|
19
|
+
return { calls, fn };
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type MockPivotState = {
|
|
23
|
+
pivot: Pick<UsePivotResult, "go" | "canGo">;
|
|
24
|
+
calls: {
|
|
25
|
+
go: CallTracker;
|
|
26
|
+
canGo: CallTracker;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
13
29
|
|
|
14
|
-
|
|
15
|
-
vi.useRealTimers();
|
|
16
|
-
});
|
|
30
|
+
describe("usePivotSwipeInput", () => {
|
|
17
31
|
|
|
18
32
|
const createRef = (): React.RefObject<HTMLDivElement> => {
|
|
19
33
|
const element = document.createElement("div");
|
|
20
34
|
return { current: element };
|
|
21
35
|
};
|
|
22
36
|
|
|
23
|
-
const createMockPivot = (
|
|
24
|
-
go
|
|
25
|
-
canGo
|
|
26
|
-
|
|
37
|
+
const createMockPivot = (canGoResult: boolean = true): MockPivotState => {
|
|
38
|
+
const go = createCallTracker();
|
|
39
|
+
const canGo = createCallTracker();
|
|
40
|
+
const canGoFn = (direction: number): boolean => {
|
|
41
|
+
canGo.fn(direction);
|
|
42
|
+
return canGoResult;
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
pivot: {
|
|
46
|
+
go: go.fn,
|
|
47
|
+
canGo: canGoFn,
|
|
48
|
+
},
|
|
49
|
+
calls: {
|
|
50
|
+
go,
|
|
51
|
+
canGo,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
};
|
|
27
55
|
|
|
28
56
|
describe("initialization", () => {
|
|
29
57
|
it("starts with idle state", () => {
|
|
30
58
|
const containerRef = createRef();
|
|
31
|
-
const pivot = createMockPivot();
|
|
59
|
+
const { pivot } = createMockPivot(true);
|
|
32
60
|
|
|
33
61
|
const { result } = renderHook(() =>
|
|
34
62
|
usePivotSwipeInput({ containerRef, pivot }),
|
|
@@ -39,7 +67,7 @@ describe("usePivotSwipeInput", () => {
|
|
|
39
67
|
|
|
40
68
|
it("provides container props with style", () => {
|
|
41
69
|
const containerRef = createRef();
|
|
42
|
-
const pivot = createMockPivot();
|
|
70
|
+
const { pivot } = createMockPivot(true);
|
|
43
71
|
|
|
44
72
|
const { result } = renderHook(() =>
|
|
45
73
|
usePivotSwipeInput({ containerRef, pivot }),
|
|
@@ -53,7 +81,7 @@ describe("usePivotSwipeInput", () => {
|
|
|
53
81
|
describe("swipe to navigate", () => {
|
|
54
82
|
it("calls go(1) when swiping left (to see next)", () => {
|
|
55
83
|
const containerRef = createRef();
|
|
56
|
-
const pivot = createMockPivot();
|
|
84
|
+
const { pivot, calls } = createMockPivot(true);
|
|
57
85
|
|
|
58
86
|
const { result } = renderHook(() =>
|
|
59
87
|
usePivotSwipeInput({
|
|
@@ -96,12 +124,13 @@ describe("usePivotSwipeInput", () => {
|
|
|
96
124
|
});
|
|
97
125
|
|
|
98
126
|
// Swipe left (-1 direction) should call go(1) to show next
|
|
99
|
-
expect(
|
|
127
|
+
expect(calls.go.calls).toHaveLength(1);
|
|
128
|
+
expect(calls.go.calls[0]?.[0]).toBe(1);
|
|
100
129
|
});
|
|
101
130
|
|
|
102
131
|
it("calls go(-1) when swiping right (to see previous)", () => {
|
|
103
132
|
const containerRef = createRef();
|
|
104
|
-
const pivot = createMockPivot();
|
|
133
|
+
const { pivot, calls } = createMockPivot(true);
|
|
105
134
|
|
|
106
135
|
const { result } = renderHook(() =>
|
|
107
136
|
usePivotSwipeInput({
|
|
@@ -144,13 +173,13 @@ describe("usePivotSwipeInput", () => {
|
|
|
144
173
|
});
|
|
145
174
|
|
|
146
175
|
// Swipe right (1 direction) should call go(-1) to show previous
|
|
147
|
-
expect(
|
|
176
|
+
expect(calls.go.calls).toHaveLength(1);
|
|
177
|
+
expect(calls.go.calls[0]?.[0]).toBe(-1);
|
|
148
178
|
});
|
|
149
179
|
|
|
150
180
|
it("does not call go when canGo returns false", () => {
|
|
151
181
|
const containerRef = createRef();
|
|
152
|
-
const pivot = createMockPivot();
|
|
153
|
-
(pivot.canGo as ReturnType<typeof vi.fn>).mockReturnValue(false);
|
|
182
|
+
const { pivot, calls } = createMockPivot(false);
|
|
154
183
|
|
|
155
184
|
const { result } = renderHook(() =>
|
|
156
185
|
usePivotSwipeInput({
|
|
@@ -192,14 +221,14 @@ describe("usePivotSwipeInput", () => {
|
|
|
192
221
|
document.dispatchEvent(upEvent);
|
|
193
222
|
});
|
|
194
223
|
|
|
195
|
-
expect(
|
|
224
|
+
expect(calls.go.calls).toHaveLength(0);
|
|
196
225
|
});
|
|
197
226
|
});
|
|
198
227
|
|
|
199
228
|
describe("input state tracking", () => {
|
|
200
229
|
it("updates inputState during swipe", () => {
|
|
201
230
|
const containerRef = createRef();
|
|
202
|
-
const pivot = createMockPivot();
|
|
231
|
+
const { pivot } = createMockPivot();
|
|
203
232
|
|
|
204
233
|
const { result } = renderHook(() =>
|
|
205
234
|
usePivotSwipeInput({ containerRef, pivot }),
|
|
@@ -240,7 +269,7 @@ describe("usePivotSwipeInput", () => {
|
|
|
240
269
|
describe("disabled state", () => {
|
|
241
270
|
it("does not track when disabled", () => {
|
|
242
271
|
const containerRef = createRef();
|
|
243
|
-
const pivot = createMockPivot();
|
|
272
|
+
const { pivot } = createMockPivot();
|
|
244
273
|
|
|
245
274
|
const { result } = renderHook(() =>
|
|
246
275
|
usePivotSwipeInput({ containerRef, pivot, enabled: false }),
|
|
@@ -266,7 +295,7 @@ describe("usePivotSwipeInput", () => {
|
|
|
266
295
|
describe("vertical axis", () => {
|
|
267
296
|
it("supports vertical swipe when axis is vertical", () => {
|
|
268
297
|
const containerRef = createRef();
|
|
269
|
-
const pivot = createMockPivot();
|
|
298
|
+
const { pivot, calls } = createMockPivot();
|
|
270
299
|
|
|
271
300
|
const { result } = renderHook(() =>
|
|
272
301
|
usePivotSwipeInput({
|
|
@@ -312,7 +341,8 @@ describe("usePivotSwipeInput", () => {
|
|
|
312
341
|
});
|
|
313
342
|
|
|
314
343
|
// Swipe up (-1 direction) should call go(1) to show next
|
|
315
|
-
expect(
|
|
344
|
+
expect(calls.go.calls).toHaveLength(1);
|
|
345
|
+
expect(calls.go.calls[0]?.[0]).toBe(1);
|
|
316
346
|
});
|
|
317
347
|
});
|
|
318
348
|
|
|
@@ -334,64 +364,77 @@ describe("usePivotSwipeInput", () => {
|
|
|
334
364
|
|
|
335
365
|
it("should NOT trigger navigation with small displacement (under 25% of container)", () => {
|
|
336
366
|
const containerRef = createRef();
|
|
337
|
-
const pivot = createMockPivot();
|
|
367
|
+
const { pivot, calls } = createMockPivot();
|
|
338
368
|
|
|
339
369
|
// コンテナ幅が400pxの場合、25%=100px未満はトリガーしないべき
|
|
340
370
|
const containerWidth = 400;
|
|
341
371
|
const smallDisplacement = containerWidth * 0.2; // 80px = 20%
|
|
342
372
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
373
|
+
// Mock performance.now() to control velocity calculation
|
|
374
|
+
// 80px / 200ms = 0.4 px/ms (under 0.5 threshold)
|
|
375
|
+
let mockTime = 0;
|
|
376
|
+
const originalPerformanceNow = performance.now;
|
|
377
|
+
performance.now = () => mockTime;
|
|
378
|
+
|
|
379
|
+
try {
|
|
380
|
+
const { result } = renderHook(() =>
|
|
381
|
+
usePivotSwipeInput({
|
|
382
|
+
containerRef,
|
|
383
|
+
pivot,
|
|
384
|
+
// 推奨閾値: コンテナ幅の25%程度
|
|
385
|
+
thresholds: {
|
|
386
|
+
distanceThreshold: containerWidth * 0.25, // 100px
|
|
387
|
+
velocityThreshold: 0.5, // より高い閾値
|
|
388
|
+
lockThreshold: 10,
|
|
389
|
+
},
|
|
390
|
+
}),
|
|
391
|
+
);
|
|
392
|
+
|
|
393
|
+
// Pointer down at time 0
|
|
394
|
+
mockTime = 0;
|
|
395
|
+
const downEvent = {
|
|
396
|
+
clientX: 200,
|
|
397
|
+
clientY: 100,
|
|
398
|
+
pointerId: 1,
|
|
399
|
+
isPrimary: true,
|
|
400
|
+
pointerType: "touch",
|
|
401
|
+
button: 0,
|
|
402
|
+
} as React.PointerEvent<HTMLElement>;
|
|
403
|
+
|
|
404
|
+
act(() => {
|
|
405
|
+
result.current.containerProps.onPointerDown?.(downEvent);
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
// 小さな移動 (80px left) at time 200ms
|
|
409
|
+
// velocity = 80px / 200ms = 0.4 px/ms (under 0.5 threshold)
|
|
410
|
+
mockTime = 200;
|
|
411
|
+
const moveEvent = new PointerEvent("pointermove", {
|
|
412
|
+
clientX: 200 - smallDisplacement,
|
|
413
|
+
clientY: 102,
|
|
414
|
+
pointerId: 1,
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
act(() => {
|
|
418
|
+
document.dispatchEvent(moveEvent);
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
// Pointer up
|
|
422
|
+
const upEvent = new PointerEvent("pointerup", { pointerId: 1 });
|
|
423
|
+
|
|
424
|
+
act(() => {
|
|
425
|
+
document.dispatchEvent(upEvent);
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
// 閾値未満の移動ではナビゲーションされないべき
|
|
429
|
+
expect(calls.go.calls).toHaveLength(0);
|
|
430
|
+
} finally {
|
|
431
|
+
performance.now = originalPerformanceNow;
|
|
432
|
+
}
|
|
390
433
|
});
|
|
391
434
|
|
|
392
435
|
it("should trigger navigation with significant displacement (over 25% of container)", () => {
|
|
393
436
|
const containerRef = createRef();
|
|
394
|
-
const pivot = createMockPivot();
|
|
437
|
+
const { pivot, calls } = createMockPivot();
|
|
395
438
|
|
|
396
439
|
const containerWidth = 400;
|
|
397
440
|
const significantDisplacement = containerWidth * 0.3; // 120px = 30%
|
|
@@ -439,59 +482,73 @@ describe("usePivotSwipeInput", () => {
|
|
|
439
482
|
});
|
|
440
483
|
|
|
441
484
|
// 閾値を超えた移動ではナビゲーションされる
|
|
442
|
-
expect(
|
|
485
|
+
expect(calls.go.calls).toHaveLength(1);
|
|
486
|
+
expect(calls.go.calls[0]?.[0]).toBe(1);
|
|
443
487
|
});
|
|
444
488
|
|
|
445
489
|
it("does NOT trigger with displacement under default threshold (100px)", () => {
|
|
446
490
|
const containerRef = createRef();
|
|
447
|
-
const pivot = createMockPivot();
|
|
448
|
-
|
|
449
|
-
//
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
491
|
+
const { pivot, calls } = createMockPivot();
|
|
492
|
+
|
|
493
|
+
// Mock performance.now() to control velocity calculation
|
|
494
|
+
// 60px / 200ms = 0.3 px/ms (under 0.5 threshold)
|
|
495
|
+
let mockTime = 0;
|
|
496
|
+
const originalPerformanceNow = performance.now;
|
|
497
|
+
performance.now = () => mockTime;
|
|
498
|
+
|
|
499
|
+
try {
|
|
500
|
+
// デフォルト閾値: distanceThreshold: 100px, velocityThreshold: 0.5 px/ms
|
|
501
|
+
const { result } = renderHook(() =>
|
|
502
|
+
usePivotSwipeInput({
|
|
503
|
+
containerRef,
|
|
504
|
+
pivot,
|
|
505
|
+
// デフォルト値を使用
|
|
506
|
+
}),
|
|
507
|
+
);
|
|
508
|
+
|
|
509
|
+
mockTime = 0;
|
|
510
|
+
const downEvent = {
|
|
511
|
+
clientX: 200,
|
|
512
|
+
clientY: 100,
|
|
513
|
+
pointerId: 1,
|
|
514
|
+
isPrimary: true,
|
|
515
|
+
pointerType: "touch",
|
|
516
|
+
button: 0,
|
|
517
|
+
} as React.PointerEvent<HTMLElement>;
|
|
518
|
+
|
|
519
|
+
act(() => {
|
|
520
|
+
result.current.containerProps.onPointerDown?.(downEvent);
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
// 60pxは新しいデフォルト閾値(100px)未満
|
|
524
|
+
// velocity = 60px / 200ms = 0.3 px/ms (under 0.5 threshold)
|
|
525
|
+
mockTime = 200;
|
|
526
|
+
const moveEvent = new PointerEvent("pointermove", {
|
|
527
|
+
clientX: 140, // -60px (< 100px threshold)
|
|
528
|
+
clientY: 102,
|
|
529
|
+
pointerId: 1,
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
act(() => {
|
|
533
|
+
document.dispatchEvent(moveEvent);
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
const upEvent = new PointerEvent("pointerup", { pointerId: 1 });
|
|
537
|
+
|
|
538
|
+
act(() => {
|
|
539
|
+
document.dispatchEvent(upEvent);
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
// 閾値未満なのでトリガーされない
|
|
543
|
+
expect(calls.go.calls).toHaveLength(0);
|
|
544
|
+
} finally {
|
|
545
|
+
performance.now = originalPerformanceNow;
|
|
546
|
+
}
|
|
490
547
|
});
|
|
491
548
|
|
|
492
549
|
it("triggers with displacement over default threshold (100px)", () => {
|
|
493
550
|
const containerRef = createRef();
|
|
494
|
-
const pivot = createMockPivot();
|
|
551
|
+
const { pivot, calls } = createMockPivot();
|
|
495
552
|
|
|
496
553
|
const { result } = renderHook(() =>
|
|
497
554
|
usePivotSwipeInput({
|
|
@@ -530,7 +587,8 @@ describe("usePivotSwipeInput", () => {
|
|
|
530
587
|
document.dispatchEvent(upEvent);
|
|
531
588
|
});
|
|
532
589
|
|
|
533
|
-
expect(
|
|
590
|
+
expect(calls.go.calls).toHaveLength(1);
|
|
591
|
+
expect(calls.go.calls[0]?.[0]).toBe(1);
|
|
534
592
|
});
|
|
535
593
|
});
|
|
536
594
|
|
|
@@ -551,7 +609,7 @@ describe("usePivotSwipeInput", () => {
|
|
|
551
609
|
|
|
552
610
|
it("should NOT trigger navigation when pointercancel fires (finger still down)", () => {
|
|
553
611
|
const containerRef = createRef();
|
|
554
|
-
const pivot = createMockPivot();
|
|
612
|
+
const { pivot, calls } = createMockPivot();
|
|
555
613
|
|
|
556
614
|
const { result } = renderHook(() =>
|
|
557
615
|
usePivotSwipeInput({
|
|
@@ -595,12 +653,12 @@ describe("usePivotSwipeInput", () => {
|
|
|
595
653
|
});
|
|
596
654
|
|
|
597
655
|
// Navigation should NOT be triggered - the swipe was canceled, not completed
|
|
598
|
-
expect(
|
|
656
|
+
expect(calls.go.calls).toHaveLength(0);
|
|
599
657
|
});
|
|
600
658
|
|
|
601
659
|
it("should trigger navigation normally on pointerup", () => {
|
|
602
660
|
const containerRef = createRef();
|
|
603
|
-
const pivot = createMockPivot();
|
|
661
|
+
const { pivot, calls } = createMockPivot();
|
|
604
662
|
|
|
605
663
|
const { result } = renderHook(() =>
|
|
606
664
|
usePivotSwipeInput({
|
|
@@ -643,7 +701,8 @@ describe("usePivotSwipeInput", () => {
|
|
|
643
701
|
});
|
|
644
702
|
|
|
645
703
|
// Navigation SHOULD be triggered
|
|
646
|
-
expect(
|
|
704
|
+
expect(calls.go.calls).toHaveLength(1);
|
|
705
|
+
expect(calls.go.calls[0]?.[0]).toBe(1);
|
|
647
706
|
});
|
|
648
707
|
});
|
|
649
708
|
});
|