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.
Files changed (216) hide show
  1. package/dist/{FloatingPanelFrame-SgYLc6Ud.js → FloatingPanelFrame-3eU9AwPo.js} +2 -2
  2. package/dist/{FloatingPanelFrame-SgYLc6Ud.js.map → FloatingPanelFrame-3eU9AwPo.js.map} +1 -1
  3. package/dist/FloatingWindow-CUXnEtrb.js +827 -0
  4. package/dist/FloatingWindow-CUXnEtrb.js.map +1 -0
  5. package/dist/FloatingWindow-DMwyK0eK.cjs +2 -0
  6. package/dist/FloatingWindow-DMwyK0eK.cjs.map +1 -0
  7. package/dist/GridLayout-DKTg_N61.cjs +2 -0
  8. package/dist/{GridLayout-B4VRsC0r.cjs.map → GridLayout-DKTg_N61.cjs.map} +1 -1
  9. package/dist/{GridLayout-BltqeCPK.js → GridLayout-UWNxXw77.js} +34 -35
  10. package/dist/{GridLayout-BltqeCPK.js.map → GridLayout-UWNxXw77.js.map} +1 -1
  11. package/dist/{HorizontalDivider-WF1k_qND.js → HorizontalDivider-DdxzfV0l.js} +3 -3
  12. package/dist/{HorizontalDivider-WF1k_qND.js.map → HorizontalDivider-DdxzfV0l.js.map} +1 -1
  13. package/dist/{HorizontalDivider-B5Z-KZLk.cjs → HorizontalDivider-_pgV4Mcv.cjs} +2 -2
  14. package/dist/{HorizontalDivider-B5Z-KZLk.cjs.map → HorizontalDivider-_pgV4Mcv.cjs.map} +1 -1
  15. package/dist/{PanelSystem-Dr1TBhxM.js → PanelSystem-BqUzNtf2.js} +5 -5
  16. package/dist/{PanelSystem-Dr1TBhxM.js.map → PanelSystem-BqUzNtf2.js.map} +1 -1
  17. package/dist/{PanelSystem-Bs8bQwQF.cjs → PanelSystem-D603LKKv.cjs} +2 -2
  18. package/dist/{PanelSystem-Bs8bQwQF.cjs.map → PanelSystem-D603LKKv.cjs.map} +1 -1
  19. package/dist/ResizeHandle-CBcAS918.cjs +2 -0
  20. package/dist/{ResizeHandle-CScipO5l.cjs.map → ResizeHandle-CBcAS918.cjs.map} +1 -1
  21. package/dist/{ResizeHandle-CdA_JYfN.js → ResizeHandle-CXjc1meV.js} +28 -29
  22. package/dist/{ResizeHandle-CdA_JYfN.js.map → ResizeHandle-CXjc1meV.js.map} +1 -1
  23. package/dist/SwipePivotTabBar-DWrCuwEI.js +411 -0
  24. package/dist/SwipePivotTabBar-DWrCuwEI.js.map +1 -0
  25. package/dist/SwipePivotTabBar-fjjXkpj7.cjs +2 -0
  26. package/dist/SwipePivotTabBar-fjjXkpj7.cjs.map +1 -0
  27. package/dist/components/gesture/SwipeSafeZone.d.ts +40 -0
  28. package/dist/components/window/Drawer.d.ts +3 -1
  29. package/dist/components/window/DrawerLayers.d.ts +1 -1
  30. package/dist/components/window/drawerStyles.d.ts +69 -0
  31. package/dist/components/window/drawerSwipeConfig.d.ts +29 -0
  32. package/dist/components/window/useDrawerSwipeTransform.d.ts +23 -0
  33. package/dist/config.cjs +1 -1
  34. package/dist/config.js +3 -3
  35. package/dist/constants/styles.d.ts +17 -0
  36. package/dist/dialog/index.d.ts +69 -0
  37. package/dist/floating.js +1 -1
  38. package/dist/grid.cjs +1 -1
  39. package/dist/grid.js +2 -2
  40. package/dist/hooks/gesture/testing/createGestureSimulator.d.ts +7 -0
  41. package/dist/hooks/gesture/types.d.ts +48 -5
  42. package/dist/hooks/gesture/utils.d.ts +19 -0
  43. package/dist/hooks/useAnimationFrame.d.ts +2 -0
  44. package/dist/hooks/useOperationContinuity.d.ts +64 -0
  45. package/dist/hooks/useResizeObserver.d.ts +33 -1
  46. package/dist/hooks/useSharedElementTransition.d.ts +112 -0
  47. package/dist/hooks/useSwipeContentTransform.d.ts +9 -2
  48. package/dist/index.cjs +1 -1
  49. package/dist/index.js +7 -7
  50. package/dist/modules/dialog/AlertDialog.d.ts +9 -0
  51. package/dist/modules/dialog/DialogContainer.d.ts +37 -0
  52. package/dist/modules/dialog/Modal.d.ts +26 -0
  53. package/dist/modules/dialog/SwipeDialogContainer.d.ts +16 -0
  54. package/dist/modules/dialog/dialogAnimationUtils.d.ts +113 -0
  55. package/dist/modules/dialog/types.d.ts +183 -0
  56. package/dist/modules/dialog/useDialog.d.ts +39 -0
  57. package/dist/modules/dialog/useDialogContainer.d.ts +47 -0
  58. package/dist/modules/dialog/useDialogSwipeInput.d.ts +70 -0
  59. package/dist/modules/dialog/useDialogTransform.d.ts +82 -0
  60. package/dist/modules/drawer/types.d.ts +74 -0
  61. package/dist/modules/drawer/useDrawerSwipeInput.d.ts +24 -0
  62. package/dist/modules/pivot/SwipePivotTabBar.d.ts +3 -0
  63. package/dist/modules/stack/SwipeStackContent.d.ts +6 -3
  64. package/dist/modules/stack/SwipeStackOutlet.d.ts +4 -4
  65. package/dist/modules/stack/computeSwipeStackTransform.d.ts +1 -1
  66. package/dist/panels.cjs +1 -1
  67. package/dist/panels.js +1 -1
  68. package/dist/pivot.cjs +1 -1
  69. package/dist/pivot.js +1 -1
  70. package/dist/resizer.cjs +1 -1
  71. package/dist/resizer.js +2 -2
  72. package/dist/stack.cjs +1 -1
  73. package/dist/stack.cjs.map +1 -1
  74. package/dist/stack.js +503 -762
  75. package/dist/stack.js.map +1 -1
  76. package/dist/sticky-header/calculateStickyMetrics.d.ts +28 -0
  77. package/dist/sticky-header.cjs +1 -1
  78. package/dist/sticky-header.cjs.map +1 -1
  79. package/dist/sticky-header.js +59 -51
  80. package/dist/sticky-header.js.map +1 -1
  81. package/dist/{styles-DPPuJ0sf.js → styles-NkjuMOVS.js} +13 -13
  82. package/dist/{styles-DPPuJ0sf.js.map → styles-NkjuMOVS.js.map} +1 -1
  83. package/dist/styles-qf6ptVLD.cjs.map +1 -1
  84. package/dist/types.d.ts +16 -0
  85. package/dist/useDocumentPointerEvents-DXxw3qWj.js +54 -0
  86. package/dist/useDocumentPointerEvents-DXxw3qWj.js.map +1 -0
  87. package/dist/useDocumentPointerEvents-DxDSOtip.cjs +2 -0
  88. package/dist/useDocumentPointerEvents-DxDSOtip.cjs.map +1 -0
  89. package/dist/useNativeGestureGuard-C7TSqEkr.cjs +2 -0
  90. package/dist/useNativeGestureGuard-C7TSqEkr.cjs.map +1 -0
  91. package/dist/useNativeGestureGuard-CGYo6O0r.js +347 -0
  92. package/dist/useNativeGestureGuard-CGYo6O0r.js.map +1 -0
  93. package/dist/window/index.d.ts +2 -0
  94. package/dist/window.cjs +1 -1
  95. package/dist/window.cjs.map +1 -1
  96. package/dist/window.js +114 -103
  97. package/dist/window.js.map +1 -1
  98. package/package.json +6 -1
  99. package/src/components/gesture/SwipeSafeZone.tsx +69 -0
  100. package/src/components/window/Drawer.tsx +249 -162
  101. package/src/components/window/DrawerLayers.tsx +13 -3
  102. package/src/components/window/drawerStyles.spec.ts +263 -0
  103. package/src/components/window/drawerStyles.ts +228 -0
  104. package/src/components/window/drawerSwipeConfig.spec.ts +131 -0
  105. package/src/components/window/drawerSwipeConfig.ts +112 -0
  106. package/src/components/window/useDrawerSwipeTransform.spec.ts +234 -0
  107. package/src/components/window/useDrawerSwipeTransform.ts +129 -0
  108. package/src/constants/styles.ts +19 -0
  109. package/src/demo/pages/Dialog/alerts/index.tsx +22 -0
  110. package/src/demo/pages/Dialog/card/index.tsx +22 -0
  111. package/src/demo/pages/Dialog/components/AlertDialogDemo.tsx +124 -0
  112. package/src/demo/pages/Dialog/components/CardExpandDemo.module.css +243 -0
  113. package/src/demo/pages/Dialog/components/CardExpandDemo.tsx +204 -0
  114. package/src/demo/pages/Dialog/components/CustomAlertDialogDemo.tsx +219 -0
  115. package/src/demo/pages/Dialog/components/DialogDemos.module.css +77 -0
  116. package/src/demo/pages/Dialog/components/ModalBasics.tsx +45 -0
  117. package/src/demo/pages/Dialog/components/SwipeDialogDemo.module.css +77 -0
  118. package/src/demo/pages/Dialog/components/SwipeDialogDemo.tsx +181 -0
  119. package/src/demo/pages/Dialog/custom-alert/index.tsx +22 -0
  120. package/src/demo/pages/Dialog/modal/index.tsx +17 -0
  121. package/src/demo/pages/Dialog/swipe/index.tsx +22 -0
  122. package/src/demo/pages/Drawer/components/DrawerSwipe.module.css +316 -0
  123. package/src/demo/pages/Drawer/components/DrawerSwipe.tsx +178 -0
  124. package/src/demo/pages/Drawer/swipe/index.tsx +17 -0
  125. package/src/demo/pages/Pivot/components/SwipeTabsPivot.tsx +54 -23
  126. package/src/demo/pages/Pivot/swipe-debug/index.tsx +1 -1
  127. package/src/demo/pages/Stack/components/StackBasics.spec.tsx +152 -0
  128. package/src/demo/pages/Stack/components/StackBasics.tsx +179 -95
  129. package/src/demo/pages/Stack/components/StackTablet.spec.tsx +120 -0
  130. package/src/demo/pages/Stack/components/StackTablet.tsx +42 -21
  131. package/src/demo/routes.tsx +22 -1
  132. package/src/dialog/index.ts +85 -0
  133. package/src/hooks/gesture/testing/createGestureSimulator.spec.ts +68 -64
  134. package/src/hooks/gesture/testing/createGestureSimulator.ts +112 -37
  135. package/src/hooks/gesture/types.ts +83 -6
  136. package/src/hooks/gesture/useEdgeSwipeInput.spec.ts +22 -14
  137. package/src/hooks/gesture/useNativeGestureGuard.spec.ts +91 -31
  138. package/src/hooks/gesture/useNativeGestureGuard.ts +3 -1
  139. package/src/hooks/gesture/utils.ts +91 -0
  140. package/src/hooks/useAnimatedVisibility.spec.ts +44 -24
  141. package/src/hooks/useAnimatedVisibility.ts +28 -2
  142. package/src/hooks/useAnimationFrame.ts +8 -0
  143. package/src/hooks/useOperationContinuity.spec.ts +387 -0
  144. package/src/hooks/useOperationContinuity.ts +135 -0
  145. package/src/hooks/useResizeObserver.spec.tsx +277 -0
  146. package/src/hooks/useResizeObserver.tsx +108 -39
  147. package/src/hooks/useScrollContainer.ts +4 -10
  148. package/src/hooks/useSharedElementTransition.ts +333 -0
  149. package/src/hooks/useSwipeContentTransform.spec.ts +18 -18
  150. package/src/hooks/useSwipeContentTransform.ts +166 -28
  151. package/src/modules/dialog/AlertDialog.spec.tsx +387 -0
  152. package/src/modules/dialog/AlertDialog.tsx +221 -0
  153. package/src/modules/dialog/DialogContainer.spec.tsx +228 -0
  154. package/src/modules/dialog/DialogContainer.tsx +188 -0
  155. package/src/modules/dialog/Modal.spec.tsx +220 -0
  156. package/src/modules/dialog/Modal.tsx +182 -0
  157. package/src/modules/dialog/SwipeDialogContainer.tsx +208 -0
  158. package/src/modules/dialog/dialogAnimationUtils.spec.ts +253 -0
  159. package/src/modules/dialog/dialogAnimationUtils.ts +297 -0
  160. package/src/modules/dialog/types.ts +186 -0
  161. package/src/modules/dialog/useDialog.spec.tsx +447 -0
  162. package/src/modules/dialog/useDialog.ts +214 -0
  163. package/src/modules/dialog/useDialogContainer.spec.ts +331 -0
  164. package/src/modules/dialog/useDialogContainer.ts +150 -0
  165. package/src/modules/dialog/useDialogSwipeInput.spec.ts +157 -0
  166. package/src/modules/dialog/useDialogSwipeInput.ts +319 -0
  167. package/src/modules/dialog/useDialogTransform.spec.ts +370 -0
  168. package/src/modules/dialog/useDialogTransform.ts +407 -0
  169. package/src/modules/drawer/types.ts +102 -0
  170. package/src/modules/drawer/useDrawerSwipeInput.spec.ts +566 -0
  171. package/src/modules/drawer/useDrawerSwipeInput.ts +399 -0
  172. package/src/modules/panels/rendering/ContentRegistry.spec.tsx +21 -14
  173. package/src/modules/pivot/SwipePivotContent.position.spec.tsx +12 -8
  174. package/src/modules/pivot/SwipePivotContent.spec.tsx +55 -25
  175. package/src/modules/pivot/SwipePivotContent.tsx +2 -2
  176. package/src/modules/pivot/SwipePivotTabBar.spec.tsx +85 -68
  177. package/src/modules/pivot/SwipePivotTabBar.tsx +75 -15
  178. package/src/modules/pivot/scaleInputState.spec.ts +11 -2
  179. package/src/modules/pivot/usePivot.spec.ts +17 -3
  180. package/src/modules/pivot/usePivotSwipeInput.spec.ts +182 -123
  181. package/src/modules/stack/SwipeStackContent.spec.tsx +387 -100
  182. package/src/modules/stack/SwipeStackContent.tsx +43 -33
  183. package/src/modules/stack/SwipeStackOutlet.spec.tsx +14 -16
  184. package/src/modules/stack/SwipeStackOutlet.tsx +6 -6
  185. package/src/modules/stack/computeSwipeStackTransform.spec.ts +5 -5
  186. package/src/modules/stack/computeSwipeStackTransform.ts +3 -3
  187. package/src/modules/stack/swipeTransitionContinuity.spec.tsx +1133 -0
  188. package/src/modules/stack/useStackAnimationState.spec.ts +3 -1
  189. package/src/modules/stack/useStackAnimationState.ts +18 -13
  190. package/src/modules/stack/useStackNavigation.spec.ts +198 -3
  191. package/src/modules/stack/useStackNavigation.tsx +113 -56
  192. package/src/modules/stack/useStackSwipeInput.spec.ts +65 -32
  193. package/src/modules/stack/useStackSwipeInput.ts +1 -1
  194. package/src/sticky-header/StickyArea.tsx +29 -57
  195. package/src/sticky-header/calculateStickyMetrics.spec.ts +105 -0
  196. package/src/sticky-header/calculateStickyMetrics.ts +50 -0
  197. package/src/types.ts +18 -0
  198. package/src/window/index.ts +2 -0
  199. package/dist/FloatingWindow-BpdOpg_L.js +0 -400
  200. package/dist/FloatingWindow-BpdOpg_L.js.map +0 -1
  201. package/dist/FloatingWindow-TCDNY5gE.cjs +0 -2
  202. package/dist/FloatingWindow-TCDNY5gE.cjs.map +0 -1
  203. package/dist/GridLayout-B4VRsC0r.cjs +0 -2
  204. package/dist/ResizeHandle-CScipO5l.cjs +0 -2
  205. package/dist/SwipePivotTabBar-BGO9X94m.js +0 -407
  206. package/dist/SwipePivotTabBar-BGO9X94m.js.map +0 -1
  207. package/dist/SwipePivotTabBar-BrQismcZ.cjs +0 -2
  208. package/dist/SwipePivotTabBar-BrQismcZ.cjs.map +0 -1
  209. package/dist/useDocumentPointerEvents-CKdhGXd0.js +0 -46
  210. package/dist/useDocumentPointerEvents-CKdhGXd0.js.map +0 -1
  211. package/dist/useDocumentPointerEvents-ChqrKXDk.cjs +0 -2
  212. package/dist/useDocumentPointerEvents-ChqrKXDk.cjs.map +0 -1
  213. package/dist/useEffectEvent-Dp7HLCf0.js +0 -13
  214. package/dist/useEffectEvent-Dp7HLCf0.js.map +0 -1
  215. package/dist/useEffectEvent-huSsGUnl.cjs +0 -2
  216. 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
- describe("usePivotSwipeInput", () => {
10
- beforeEach(() => {
11
- vi.useFakeTimers();
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
- afterEach(() => {
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 = (): Pick<UsePivotResult, "go" | "canGo"> => ({
24
- go: vi.fn(),
25
- canGo: vi.fn().mockReturnValue(true),
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(pivot.go).toHaveBeenCalledWith(1);
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(pivot.go).toHaveBeenCalledWith(-1);
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(pivot.go).not.toHaveBeenCalled();
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(pivot.go).toHaveBeenCalledWith(1);
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
- const { result } = renderHook(() =>
344
- usePivotSwipeInput({
345
- containerRef,
346
- pivot,
347
- // 推奨閾値: コンテナ幅の25%程度
348
- thresholds: {
349
- distanceThreshold: containerWidth * 0.25, // 100px
350
- velocityThreshold: 0.5, // より高い閾値
351
- lockThreshold: 10,
352
- },
353
- }),
354
- );
355
-
356
- // Pointer down
357
- const downEvent = {
358
- clientX: 200,
359
- clientY: 100,
360
- pointerId: 1,
361
- isPrimary: true,
362
- pointerType: "touch",
363
- button: 0,
364
- } as React.PointerEvent<HTMLElement>;
365
-
366
- act(() => {
367
- result.current.containerProps.onPointerDown?.(downEvent);
368
- });
369
-
370
- // 小さな移動 (80px left)
371
- const moveEvent = new PointerEvent("pointermove", {
372
- clientX: 200 - smallDisplacement,
373
- clientY: 102,
374
- pointerId: 1,
375
- });
376
-
377
- act(() => {
378
- document.dispatchEvent(moveEvent);
379
- });
380
-
381
- // Pointer up
382
- const upEvent = new PointerEvent("pointerup", { pointerId: 1 });
383
-
384
- act(() => {
385
- document.dispatchEvent(upEvent);
386
- });
387
-
388
- // 閾値未満の移動ではナビゲーションされないべき
389
- expect(pivot.go).not.toHaveBeenCalled();
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(pivot.go).toHaveBeenCalledWith(1);
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
- // デフォルト閾値: distanceThreshold: 100px, velocityThreshold: 0.5 px/ms
450
- const { result } = renderHook(() =>
451
- usePivotSwipeInput({
452
- containerRef,
453
- pivot,
454
- // デフォルト値を使用
455
- }),
456
- );
457
-
458
- const downEvent = {
459
- clientX: 200,
460
- clientY: 100,
461
- pointerId: 1,
462
- isPrimary: true,
463
- pointerType: "touch",
464
- button: 0,
465
- } as React.PointerEvent<HTMLElement>;
466
-
467
- act(() => {
468
- result.current.containerProps.onPointerDown?.(downEvent);
469
- });
470
-
471
- // 60pxは新しいデフォルト閾値(100px)未満
472
- const moveEvent = new PointerEvent("pointermove", {
473
- clientX: 140, // -60px (< 100px threshold)
474
- clientY: 102,
475
- pointerId: 1,
476
- });
477
-
478
- act(() => {
479
- document.dispatchEvent(moveEvent);
480
- });
481
-
482
- const upEvent = new PointerEvent("pointerup", { pointerId: 1 });
483
-
484
- act(() => {
485
- document.dispatchEvent(upEvent);
486
- });
487
-
488
- // 閾値未満なのでトリガーされない
489
- expect(pivot.go).not.toHaveBeenCalled();
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(pivot.go).toHaveBeenCalledWith(1);
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(pivot.go).not.toHaveBeenCalled();
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(pivot.go).toHaveBeenCalledWith(1);
704
+ expect(calls.go.calls).toHaveLength(1);
705
+ expect(calls.go.calls[0]?.[0]).toBe(1);
647
706
  });
648
707
  });
649
708
  });