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
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Tests for useDrawerSwipeInput hook.
|
|
3
|
+
*/
|
|
4
|
+
import { renderHook, act } from "@testing-library/react";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { useDrawerSwipeInput } from "./useDrawerSwipeInput.js";
|
|
7
|
+
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Test helpers (fakes instead of mocks)
|
|
10
|
+
// ============================================================================
|
|
11
|
+
|
|
12
|
+
type CallTracker = {
|
|
13
|
+
callCount: number;
|
|
14
|
+
call: () => void;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function createCallTracker(): CallTracker {
|
|
18
|
+
const tracker: CallTracker = {
|
|
19
|
+
callCount: 0,
|
|
20
|
+
call: () => {
|
|
21
|
+
tracker.callCount++;
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
return tracker;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe("useDrawerSwipeInput", () => {
|
|
28
|
+
const createRef = (width = 300, height = 500): React.RefObject<HTMLDivElement> => {
|
|
29
|
+
const element = document.createElement("div");
|
|
30
|
+
Object.defineProperty(element, "clientWidth", { value: width });
|
|
31
|
+
Object.defineProperty(element, "clientHeight", { value: height });
|
|
32
|
+
const defaultRect: DOMRect = {
|
|
33
|
+
left: 0,
|
|
34
|
+
right: width,
|
|
35
|
+
top: 0,
|
|
36
|
+
bottom: height,
|
|
37
|
+
width,
|
|
38
|
+
height,
|
|
39
|
+
x: 0,
|
|
40
|
+
y: 0,
|
|
41
|
+
toJSON: () => ({}),
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(element, "getBoundingClientRect", {
|
|
44
|
+
value: () => defaultRect,
|
|
45
|
+
});
|
|
46
|
+
return { current: element };
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Type guard for creating test pointer events.
|
|
51
|
+
* This pattern is allowed by lint rules for type assertions in test contexts.
|
|
52
|
+
*/
|
|
53
|
+
function isPointerEvent(event: unknown): event is React.PointerEvent<HTMLElement> {
|
|
54
|
+
if (typeof event !== "object" || event === null) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
const e = event as Record<string, unknown>;
|
|
58
|
+
return (
|
|
59
|
+
typeof e.clientX === "number" &&
|
|
60
|
+
typeof e.clientY === "number" &&
|
|
61
|
+
typeof e.pointerId === "number" &&
|
|
62
|
+
typeof e.preventDefault === "function"
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function createFakePointerEvent(props: {
|
|
67
|
+
clientX: number;
|
|
68
|
+
clientY: number;
|
|
69
|
+
pointerId?: number;
|
|
70
|
+
isPrimary?: boolean;
|
|
71
|
+
pointerType?: string;
|
|
72
|
+
button?: number;
|
|
73
|
+
}): React.PointerEvent<HTMLElement> {
|
|
74
|
+
const targetElement = document.createElement("div");
|
|
75
|
+
const nativeEvent = new PointerEvent("pointerdown", {
|
|
76
|
+
clientX: props.clientX,
|
|
77
|
+
clientY: props.clientY,
|
|
78
|
+
pointerId: props.pointerId ?? 1,
|
|
79
|
+
isPrimary: props.isPrimary ?? true,
|
|
80
|
+
pointerType: props.pointerType ?? "touch",
|
|
81
|
+
button: props.button ?? 0,
|
|
82
|
+
bubbles: true,
|
|
83
|
+
cancelable: true,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const event = {
|
|
87
|
+
clientX: props.clientX,
|
|
88
|
+
clientY: props.clientY,
|
|
89
|
+
pointerId: props.pointerId ?? 1,
|
|
90
|
+
isPrimary: props.isPrimary ?? true,
|
|
91
|
+
pointerType: props.pointerType ?? "touch",
|
|
92
|
+
button: props.button ?? 0,
|
|
93
|
+
preventDefault: () => {},
|
|
94
|
+
stopPropagation: () => {},
|
|
95
|
+
target: targetElement,
|
|
96
|
+
currentTarget: targetElement,
|
|
97
|
+
nativeEvent,
|
|
98
|
+
persist: () => {},
|
|
99
|
+
isDefaultPrevented: () => false,
|
|
100
|
+
isPropagationStopped: () => false,
|
|
101
|
+
bubbles: true,
|
|
102
|
+
cancelable: true,
|
|
103
|
+
type: "pointerdown",
|
|
104
|
+
eventPhase: 0,
|
|
105
|
+
isTrusted: false,
|
|
106
|
+
timeStamp: Date.now(),
|
|
107
|
+
defaultPrevented: false,
|
|
108
|
+
// Additional properties for React.PointerEvent
|
|
109
|
+
altKey: false,
|
|
110
|
+
ctrlKey: false,
|
|
111
|
+
metaKey: false,
|
|
112
|
+
shiftKey: false,
|
|
113
|
+
detail: 0,
|
|
114
|
+
view: window,
|
|
115
|
+
screenX: 0,
|
|
116
|
+
screenY: 0,
|
|
117
|
+
pageX: props.clientX,
|
|
118
|
+
pageY: props.clientY,
|
|
119
|
+
movementX: 0,
|
|
120
|
+
movementY: 0,
|
|
121
|
+
buttons: 1,
|
|
122
|
+
relatedTarget: null,
|
|
123
|
+
getModifierState: () => false,
|
|
124
|
+
height: 1,
|
|
125
|
+
width: 1,
|
|
126
|
+
pressure: 0.5,
|
|
127
|
+
tangentialPressure: 0,
|
|
128
|
+
tiltX: 0,
|
|
129
|
+
tiltY: 0,
|
|
130
|
+
twist: 0,
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
if (!isPointerEvent(event)) {
|
|
134
|
+
throw new Error("Failed to create valid pointer event");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return event;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
describe("initialization", () => {
|
|
141
|
+
it("starts with isOpening and isClosing false", () => {
|
|
142
|
+
const edgeContainerRef = createRef();
|
|
143
|
+
const drawerContentRef = createRef();
|
|
144
|
+
|
|
145
|
+
const { result } = renderHook(() =>
|
|
146
|
+
useDrawerSwipeInput({
|
|
147
|
+
edgeContainerRef,
|
|
148
|
+
drawerContentRef,
|
|
149
|
+
direction: "left",
|
|
150
|
+
isOpen: false,
|
|
151
|
+
onSwipeOpen: () => {},
|
|
152
|
+
onSwipeClose: () => {},
|
|
153
|
+
}),
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
expect(result.current.isOpening).toBe(false);
|
|
157
|
+
expect(result.current.isClosing).toBe(false);
|
|
158
|
+
expect(result.current.progress).toBe(0);
|
|
159
|
+
expect(result.current.displacement).toBe(0);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("provides container props", () => {
|
|
163
|
+
const edgeContainerRef = createRef();
|
|
164
|
+
const drawerContentRef = createRef();
|
|
165
|
+
|
|
166
|
+
const { result } = renderHook(() =>
|
|
167
|
+
useDrawerSwipeInput({
|
|
168
|
+
edgeContainerRef,
|
|
169
|
+
drawerContentRef,
|
|
170
|
+
direction: "left",
|
|
171
|
+
isOpen: false,
|
|
172
|
+
onSwipeOpen: () => {},
|
|
173
|
+
onSwipeClose: () => {},
|
|
174
|
+
}),
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
expect(result.current.edgeContainerProps.style).toBeDefined();
|
|
178
|
+
expect(result.current.drawerContentProps.style).toBeDefined();
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe("edge swipe to open (left drawer)", () => {
|
|
183
|
+
it("calls onSwipeOpen when swiping from left edge", () => {
|
|
184
|
+
const edgeContainerRef = createRef(300);
|
|
185
|
+
const drawerContentRef = createRef(280);
|
|
186
|
+
const openTracker = createCallTracker();
|
|
187
|
+
const closeTracker = createCallTracker();
|
|
188
|
+
|
|
189
|
+
const { result } = renderHook(() =>
|
|
190
|
+
useDrawerSwipeInput({
|
|
191
|
+
edgeContainerRef,
|
|
192
|
+
drawerContentRef,
|
|
193
|
+
direction: "left",
|
|
194
|
+
isOpen: false,
|
|
195
|
+
onSwipeOpen: openTracker.call,
|
|
196
|
+
onSwipeClose: closeTracker.call,
|
|
197
|
+
edgeWidth: 20,
|
|
198
|
+
}),
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
// Pointer down at left edge
|
|
202
|
+
const downEvent = createFakePointerEvent({ clientX: 10, clientY: 100 });
|
|
203
|
+
|
|
204
|
+
act(() => {
|
|
205
|
+
result.current.edgeContainerProps.onPointerDown?.(downEvent);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
expect(result.current.isOpening).toBe(true);
|
|
209
|
+
|
|
210
|
+
// Swipe right (to open drawer) - must exceed threshold
|
|
211
|
+
const moveEvent = new PointerEvent("pointermove", {
|
|
212
|
+
clientX: 120,
|
|
213
|
+
clientY: 105,
|
|
214
|
+
pointerId: 1,
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
act(() => {
|
|
218
|
+
document.dispatchEvent(moveEvent);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// Pointer up
|
|
222
|
+
const upEvent = new PointerEvent("pointerup", { pointerId: 1 });
|
|
223
|
+
|
|
224
|
+
act(() => {
|
|
225
|
+
document.dispatchEvent(upEvent);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
expect(openTracker.callCount).toBe(1);
|
|
229
|
+
expect(closeTracker.callCount).toBe(0);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("does not trigger open for reverse swipe direction", () => {
|
|
233
|
+
const edgeContainerRef = createRef(300);
|
|
234
|
+
const drawerContentRef = createRef(280);
|
|
235
|
+
const openTracker = createCallTracker();
|
|
236
|
+
|
|
237
|
+
const { result } = renderHook(() =>
|
|
238
|
+
useDrawerSwipeInput({
|
|
239
|
+
edgeContainerRef,
|
|
240
|
+
drawerContentRef,
|
|
241
|
+
direction: "left",
|
|
242
|
+
isOpen: false,
|
|
243
|
+
onSwipeOpen: openTracker.call,
|
|
244
|
+
onSwipeClose: () => {},
|
|
245
|
+
edgeWidth: 20,
|
|
246
|
+
}),
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
// Pointer down at left edge
|
|
250
|
+
const downEvent = createFakePointerEvent({ clientX: 10, clientY: 100 });
|
|
251
|
+
|
|
252
|
+
act(() => {
|
|
253
|
+
result.current.edgeContainerProps.onPointerDown?.(downEvent);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
// Swipe left (wrong direction)
|
|
257
|
+
const moveEvent = new PointerEvent("pointermove", {
|
|
258
|
+
clientX: 5,
|
|
259
|
+
clientY: 105,
|
|
260
|
+
pointerId: 1,
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
act(() => {
|
|
264
|
+
document.dispatchEvent(moveEvent);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
// Pointer up
|
|
268
|
+
const upEvent = new PointerEvent("pointerup", { pointerId: 1 });
|
|
269
|
+
|
|
270
|
+
act(() => {
|
|
271
|
+
document.dispatchEvent(upEvent);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
expect(openTracker.callCount).toBe(0);
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
describe("edge swipe to open (right drawer)", () => {
|
|
279
|
+
it("calls onSwipeOpen when swiping from right edge", () => {
|
|
280
|
+
const edgeContainerRef = createRef(300);
|
|
281
|
+
const drawerContentRef = createRef(280);
|
|
282
|
+
const openTracker = createCallTracker();
|
|
283
|
+
|
|
284
|
+
const { result } = renderHook(() =>
|
|
285
|
+
useDrawerSwipeInput({
|
|
286
|
+
edgeContainerRef,
|
|
287
|
+
drawerContentRef,
|
|
288
|
+
direction: "right",
|
|
289
|
+
isOpen: false,
|
|
290
|
+
onSwipeOpen: openTracker.call,
|
|
291
|
+
onSwipeClose: () => {},
|
|
292
|
+
edgeWidth: 20,
|
|
293
|
+
}),
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
// Pointer down at right edge (300 - 10 = 290)
|
|
297
|
+
const downEvent = createFakePointerEvent({ clientX: 290, clientY: 100 });
|
|
298
|
+
|
|
299
|
+
act(() => {
|
|
300
|
+
result.current.edgeContainerProps.onPointerDown?.(downEvent);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
expect(result.current.isOpening).toBe(true);
|
|
304
|
+
|
|
305
|
+
// Swipe left (to open right drawer)
|
|
306
|
+
const moveEvent = new PointerEvent("pointermove", {
|
|
307
|
+
clientX: 180,
|
|
308
|
+
clientY: 105,
|
|
309
|
+
pointerId: 1,
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
act(() => {
|
|
313
|
+
document.dispatchEvent(moveEvent);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// Pointer up
|
|
317
|
+
const upEvent = new PointerEvent("pointerup", { pointerId: 1 });
|
|
318
|
+
|
|
319
|
+
act(() => {
|
|
320
|
+
document.dispatchEvent(upEvent);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
expect(openTracker.callCount).toBe(1);
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
describe("swipe to close", () => {
|
|
328
|
+
it("calls onSwipeClose when dragging drawer closed", () => {
|
|
329
|
+
const edgeContainerRef = createRef(300);
|
|
330
|
+
const drawerContentRef = createRef(280);
|
|
331
|
+
const closeTracker = createCallTracker();
|
|
332
|
+
|
|
333
|
+
const { result } = renderHook(() =>
|
|
334
|
+
useDrawerSwipeInput({
|
|
335
|
+
edgeContainerRef,
|
|
336
|
+
drawerContentRef,
|
|
337
|
+
direction: "left",
|
|
338
|
+
isOpen: true,
|
|
339
|
+
onSwipeOpen: () => {},
|
|
340
|
+
onSwipeClose: closeTracker.call,
|
|
341
|
+
dismissThreshold: 0.3,
|
|
342
|
+
}),
|
|
343
|
+
);
|
|
344
|
+
|
|
345
|
+
// Pointer down on drawer content
|
|
346
|
+
const downEvent = createFakePointerEvent({ clientX: 100, clientY: 100 });
|
|
347
|
+
|
|
348
|
+
act(() => {
|
|
349
|
+
result.current.drawerContentProps.onPointerDown?.(downEvent);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
// Wait for state update
|
|
353
|
+
act(() => {});
|
|
354
|
+
|
|
355
|
+
expect(result.current.isClosing).toBe(true);
|
|
356
|
+
|
|
357
|
+
// Drag left to close (100px is ~36% of 280px drawer)
|
|
358
|
+
const moveEvent = new PointerEvent("pointermove", {
|
|
359
|
+
clientX: 0,
|
|
360
|
+
clientY: 105,
|
|
361
|
+
pointerId: 1,
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
act(() => {
|
|
365
|
+
document.dispatchEvent(moveEvent);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
// Pointer up
|
|
369
|
+
const upEvent = new PointerEvent("pointerup", { pointerId: 1 });
|
|
370
|
+
|
|
371
|
+
act(() => {
|
|
372
|
+
document.dispatchEvent(upEvent);
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
expect(closeTracker.callCount).toBe(1);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it("does not close when below threshold", () => {
|
|
379
|
+
const edgeContainerRef = createRef(300);
|
|
380
|
+
const drawerContentRef = createRef(280);
|
|
381
|
+
const closeTracker = createCallTracker();
|
|
382
|
+
|
|
383
|
+
const { result } = renderHook(() =>
|
|
384
|
+
useDrawerSwipeInput({
|
|
385
|
+
edgeContainerRef,
|
|
386
|
+
drawerContentRef,
|
|
387
|
+
direction: "left",
|
|
388
|
+
isOpen: true,
|
|
389
|
+
onSwipeOpen: () => {},
|
|
390
|
+
onSwipeClose: closeTracker.call,
|
|
391
|
+
dismissThreshold: 0.3,
|
|
392
|
+
}),
|
|
393
|
+
);
|
|
394
|
+
|
|
395
|
+
// Pointer down on drawer content
|
|
396
|
+
const downEvent = createFakePointerEvent({ clientX: 100, clientY: 100 });
|
|
397
|
+
|
|
398
|
+
act(() => {
|
|
399
|
+
result.current.drawerContentProps.onPointerDown?.(downEvent);
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
// Small drag (only 20px, less than 30% of 280px)
|
|
403
|
+
const moveEvent = new PointerEvent("pointermove", {
|
|
404
|
+
clientX: 80,
|
|
405
|
+
clientY: 105,
|
|
406
|
+
pointerId: 1,
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
act(() => {
|
|
410
|
+
document.dispatchEvent(moveEvent);
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
// Pointer up
|
|
414
|
+
const upEvent = new PointerEvent("pointerup", { pointerId: 1 });
|
|
415
|
+
|
|
416
|
+
act(() => {
|
|
417
|
+
document.dispatchEvent(upEvent);
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
expect(closeTracker.callCount).toBe(0);
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
describe("disabled states", () => {
|
|
425
|
+
it("does not track edge swipe when enableEdgeSwipeOpen is false", () => {
|
|
426
|
+
const edgeContainerRef = createRef();
|
|
427
|
+
const drawerContentRef = createRef();
|
|
428
|
+
|
|
429
|
+
const { result } = renderHook(() =>
|
|
430
|
+
useDrawerSwipeInput({
|
|
431
|
+
edgeContainerRef,
|
|
432
|
+
drawerContentRef,
|
|
433
|
+
direction: "left",
|
|
434
|
+
isOpen: false,
|
|
435
|
+
onSwipeOpen: () => {},
|
|
436
|
+
onSwipeClose: () => {},
|
|
437
|
+
enableEdgeSwipeOpen: false,
|
|
438
|
+
}),
|
|
439
|
+
);
|
|
440
|
+
|
|
441
|
+
const downEvent = createFakePointerEvent({ clientX: 10, clientY: 100 });
|
|
442
|
+
|
|
443
|
+
act(() => {
|
|
444
|
+
result.current.edgeContainerProps.onPointerDown?.(downEvent);
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
expect(result.current.isOpening).toBe(false);
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
it("does not track close swipe when enableSwipeClose is false", () => {
|
|
451
|
+
const edgeContainerRef = createRef();
|
|
452
|
+
const drawerContentRef = createRef();
|
|
453
|
+
|
|
454
|
+
const { result } = renderHook(() =>
|
|
455
|
+
useDrawerSwipeInput({
|
|
456
|
+
edgeContainerRef,
|
|
457
|
+
drawerContentRef,
|
|
458
|
+
direction: "left",
|
|
459
|
+
isOpen: true,
|
|
460
|
+
onSwipeOpen: () => {},
|
|
461
|
+
onSwipeClose: () => {},
|
|
462
|
+
enableSwipeClose: false,
|
|
463
|
+
}),
|
|
464
|
+
);
|
|
465
|
+
|
|
466
|
+
const downEvent = createFakePointerEvent({ clientX: 100, clientY: 100 });
|
|
467
|
+
|
|
468
|
+
act(() => {
|
|
469
|
+
result.current.drawerContentProps.onPointerDown?.(downEvent);
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
expect(result.current.isClosing).toBe(false);
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
it("does not track edge swipe when drawer is already open", () => {
|
|
476
|
+
const edgeContainerRef = createRef();
|
|
477
|
+
const drawerContentRef = createRef();
|
|
478
|
+
|
|
479
|
+
const { result } = renderHook(() =>
|
|
480
|
+
useDrawerSwipeInput({
|
|
481
|
+
edgeContainerRef,
|
|
482
|
+
drawerContentRef,
|
|
483
|
+
direction: "left",
|
|
484
|
+
isOpen: true, // Already open
|
|
485
|
+
onSwipeOpen: () => {},
|
|
486
|
+
onSwipeClose: () => {},
|
|
487
|
+
}),
|
|
488
|
+
);
|
|
489
|
+
|
|
490
|
+
const downEvent = createFakePointerEvent({ clientX: 10, clientY: 100 });
|
|
491
|
+
|
|
492
|
+
act(() => {
|
|
493
|
+
result.current.edgeContainerProps.onPointerDown?.(downEvent);
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
// Should not be opening because drawer is already open
|
|
497
|
+
expect(result.current.isOpening).toBe(false);
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
it("does not track close swipe when drawer is closed", () => {
|
|
501
|
+
const edgeContainerRef = createRef();
|
|
502
|
+
const drawerContentRef = createRef();
|
|
503
|
+
|
|
504
|
+
const { result } = renderHook(() =>
|
|
505
|
+
useDrawerSwipeInput({
|
|
506
|
+
edgeContainerRef,
|
|
507
|
+
drawerContentRef,
|
|
508
|
+
direction: "left",
|
|
509
|
+
isOpen: false, // Already closed
|
|
510
|
+
onSwipeOpen: () => {},
|
|
511
|
+
onSwipeClose: () => {},
|
|
512
|
+
}),
|
|
513
|
+
);
|
|
514
|
+
|
|
515
|
+
const downEvent = createFakePointerEvent({ clientX: 100, clientY: 100 });
|
|
516
|
+
|
|
517
|
+
act(() => {
|
|
518
|
+
result.current.drawerContentProps.onPointerDown?.(downEvent);
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
expect(result.current.isClosing).toBe(false);
|
|
522
|
+
});
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
describe("state output", () => {
|
|
526
|
+
it("provides correct ContinuousOperationState during open swipe", () => {
|
|
527
|
+
const edgeContainerRef = createRef(300);
|
|
528
|
+
const drawerContentRef = createRef(280);
|
|
529
|
+
|
|
530
|
+
const { result } = renderHook(() =>
|
|
531
|
+
useDrawerSwipeInput({
|
|
532
|
+
edgeContainerRef,
|
|
533
|
+
drawerContentRef,
|
|
534
|
+
direction: "left",
|
|
535
|
+
isOpen: false,
|
|
536
|
+
onSwipeOpen: () => {},
|
|
537
|
+
onSwipeClose: () => {},
|
|
538
|
+
edgeWidth: 20,
|
|
539
|
+
}),
|
|
540
|
+
);
|
|
541
|
+
|
|
542
|
+
// Initial state
|
|
543
|
+
expect(result.current.state.phase).toBe("idle");
|
|
544
|
+
|
|
545
|
+
// Pointer down at left edge
|
|
546
|
+
const downEvent = createFakePointerEvent({ clientX: 10, clientY: 100 });
|
|
547
|
+
|
|
548
|
+
act(() => {
|
|
549
|
+
result.current.edgeContainerProps.onPointerDown?.(downEvent);
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
// During swipe
|
|
553
|
+
const moveEvent = new PointerEvent("pointermove", {
|
|
554
|
+
clientX: 50,
|
|
555
|
+
clientY: 105,
|
|
556
|
+
pointerId: 1,
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
act(() => {
|
|
560
|
+
document.dispatchEvent(moveEvent);
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
expect(result.current.state.phase).toBe("operating");
|
|
564
|
+
});
|
|
565
|
+
});
|
|
566
|
+
});
|