@wix/site-ui 1.347.0 → 1.349.0
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/{6706.js → 1093.js} +3 -3
- package/dist/{8724.js → 1219.js} +2 -2
- package/dist/{7373.js → 1288.js} +8 -2
- package/dist/{5299.js → 1381.js} +98 -127
- package/dist/{3056.js → 1607.js} +32 -34
- package/dist/1629.js +2 -0
- package/dist/1669.js +75 -0
- package/dist/1718.js +26 -0
- package/dist/{1477.js → 201.js} +17 -26
- package/dist/2221.js +9 -0
- package/dist/{2445.js → 226.js} +12 -48
- package/dist/2387.js +7 -0
- package/dist/2580.js +6 -0
- package/dist/{1500.js → 2859.js} +10 -34
- package/dist/3014.js +178 -0
- package/dist/{6247.js → 3054.js} +3 -3
- package/dist/{7642.js → 3093.js} +1 -1
- package/dist/3189.js +5 -0
- package/dist/{7564.js → 331.js} +2 -2
- package/dist/3357.js +7 -0
- package/dist/{487.js → 3398.js} +38 -39
- package/dist/3502.js +224 -0
- package/dist/3695.js +50 -0
- package/dist/3829.js +1 -1
- package/dist/{6588.js → 3859.js} +115 -92
- package/dist/{3670.js → 3910.js} +28 -21
- package/dist/392.js +7 -0
- package/dist/{4549.js → 4155.js} +11 -3
- package/dist/4226.js +7 -0
- package/dist/{6329.js → 4229.js} +1 -1
- package/dist/4293.js +3 -0
- package/dist/4346.js +853 -2
- package/dist/{285.js → 4472.js} +3 -3
- package/dist/4605.js +207 -0
- package/dist/{7366.js → 488.js} +60 -7
- package/dist/{8750.js → 497.js} +190 -375
- package/dist/4989.js +35 -0
- package/dist/{6270.js → 510.js} +157 -196
- package/dist/5258.js +26 -0
- package/dist/{5036.js → 5275.js} +0 -3
- package/dist/{8171.js → 5298.js} +90 -102
- package/dist/5473.js +11 -0
- package/dist/{4745.js → 5490.js} +3 -1
- package/dist/{6089.js → 5561.js} +869 -786
- package/dist/{8996.js → 5595.js} +4 -3
- package/dist/5890.js +25 -0
- package/dist/{6046.js → 5969.js} +1 -1
- package/dist/5984.js +38 -0
- package/dist/{8527.js → 6006.js} +3 -3
- package/dist/6040.js +97 -0
- package/dist/{8758.js → 6137.js} +10 -8
- package/dist/{4281.js → 6140.js} +18 -10
- package/dist/{8960.js → 6191.js} +2 -2
- package/dist/6240.js +121 -0
- package/dist/{4490.js → 6373.js} +7 -5
- package/dist/{904.js → 6487.js} +19 -17
- package/dist/{9635.js → 6498.js} +1 -1
- package/dist/6499.js +4 -7
- package/dist/6508.js +7 -0
- package/dist/{8225.js → 6540.js} +1 -0
- package/dist/6551.js +46 -0
- package/dist/{9369.js → 6620.js} +35 -34
- package/dist/{4143.js → 6838.js} +19 -10
- package/dist/6902.js +48 -0
- package/dist/6904.js +51 -0
- package/dist/70.js +24 -0
- package/dist/7024.js +39 -0
- package/dist/{6882.js → 721.js} +737 -362
- package/dist/{951.js → 7270.js} +4 -4
- package/dist/{3485.js → 7323.js} +143 -111
- package/dist/{7541.js → 7488.js} +2 -2
- package/dist/{4863.js → 7542.js} +7 -6
- package/dist/7551.js +28 -0
- package/dist/{7021.js → 7640.js} +1 -1
- package/dist/{353.js → 7692.js} +3 -7
- package/dist/{4707.js → 7930.js} +2 -2
- package/dist/{8052.js → 8.js} +80 -64
- package/dist/{6914.js → 8129.js} +3 -15
- package/dist/{3319.js → 8358.js} +62 -63
- package/dist/{5864.js → 8407.js} +13 -13
- package/dist/8488.js +15 -0
- package/dist/{4768.js → 8495.js} +1 -1
- package/dist/8734.js +171 -0
- package/dist/{1763.js → 9018.js} +205 -331
- package/dist/9053.js +29 -0
- package/dist/9067.js +41 -0
- package/dist/{2861.js → 9120.js} +2 -2
- package/dist/{42.js → 9197.js} +2 -2
- package/dist/{9189.js → 9248.js} +36 -17
- package/dist/{2801.js → 9252.js} +4 -9
- package/dist/9295.js +7 -0
- package/dist/9303.js +8 -0
- package/dist/{167.js → 9374.js} +1 -1
- package/dist/{9352.js → 9540.js} +17 -47
- package/dist/9576.js +51 -0
- package/dist/{8272.js → 9591.js} +36 -46
- package/dist/{6107.js → 9770.js} +2 -2
- package/dist/{5085.js → 9880.js} +6 -3
- package/dist/Accordion/index.d.ts +207 -41
- package/dist/Accordion/index.js +75 -177
- package/dist/AlertDialog/index.d.ts +440 -140
- package/dist/AlertDialog/index.js +3 -13
- package/dist/Autocomplete/index.d.ts +722 -150
- package/dist/Autocomplete/index.js +16 -29
- package/dist/Avatar/index.d.ts +38 -3
- package/dist/Avatar/index.js +82 -28
- package/dist/Breadcrumbs/index.d.ts +63 -91
- package/dist/Breadcrumbs/index.js +1 -1
- package/dist/Button/index.d.ts +11 -0
- package/dist/Button/index.js +2 -2
- package/dist/Checkbox/index.d.ts +206 -36
- package/dist/Checkbox/index.js +293 -8
- package/dist/CheckboxField/index.css +1 -1
- package/dist/CheckboxField/index.d.ts +40 -36
- package/dist/CheckboxGroup/index.d.ts +50 -36
- package/dist/CheckboxGroup/index.js +87 -58
- package/dist/CheckboxGroupField/index.css +1 -1
- package/dist/Collapsible/index.d.ts +128 -36
- package/dist/Collapsible/index.js +21 -25
- package/dist/Combobox/index.d.ts +801 -158
- package/dist/Combobox/index.js +70 -114
- package/dist/ContextMenu/index.d.ts +1162 -195
- package/dist/ContextMenu/index.js +46 -36
- package/dist/Dialog/index.d.ts +425 -133
- package/dist/Dialog/index.js +8 -4
- package/dist/Drawer/index.d.ts +589 -144
- package/dist/Drawer/index.js +482 -562
- package/dist/Field/index.css +1 -1
- package/dist/Field/index.d.ts +341 -42
- package/dist/Field/index.js +123 -273
- package/dist/Fieldset/index.d.ts +11 -0
- package/dist/Fieldset/index.js +10 -17
- package/dist/Form/index.d.ts +43 -39
- package/dist/Form/index.js +58 -50
- package/dist/Input/index.css +1 -1
- package/dist/Input/index.d.ts +94 -42
- package/dist/Input/index.js +1 -1
- package/dist/Menu/index.d.ts +1140 -175
- package/dist/Menu/index.js +51 -67
- package/dist/Menubar/index.d.ts +651 -173
- package/dist/Menubar/index.js +12 -16
- package/dist/Meter/index.js +21 -18
- package/dist/NavigationMenu/index.d.ts +370 -86
- package/dist/NavigationMenu/index.js +144 -178
- package/dist/NumberField/index.css +1 -1
- package/dist/NumberField/index.d.ts +507 -47
- package/dist/NumberField/index.js +434 -718
- package/dist/Popover/index.d.ts +561 -142
- package/dist/Popover/index.js +181 -252
- package/dist/PreviewCard/index.d.ts +507 -143
- package/dist/PreviewCard/index.js +97 -151
- package/dist/Progress/index.d.ts +117 -3
- package/dist/Progress/index.js +37 -36
- package/dist/Radio/index.d.ts +177 -7
- package/dist/Radio/index.js +54 -70
- package/dist/RadioField/index.css +1 -1
- package/dist/RadioField/index.d.ts +23 -7
- package/dist/RadioGroup/index.d.ts +51 -37
- package/dist/RadioGroup/index.js +60 -51
- package/dist/RadioGroupField/index.css +1 -1
- package/dist/RadioGroupField/index.d.ts +40 -37
- package/dist/ScrollArea/index.d.ts +295 -1
- package/dist/ScrollArea/index.js +256 -324
- package/dist/Select/index.d.ts +516 -123
- package/dist/Select/index.js +513 -635
- package/dist/SelectField/index.css +1 -1
- package/dist/SelectField/index.d.ts +109 -134
- package/dist/SelectField/index.js +5 -1
- package/dist/Separator/index.d.ts +12 -0
- package/dist/Separator/index.js +1 -1
- package/dist/Slider/index.d.ts +383 -64
- package/dist/Slider/index.js +298 -374
- package/dist/Switch/index.d.ts +184 -37
- package/dist/Switch/index.js +44 -58
- package/dist/Tabs/index.d.ts +220 -35
- package/dist/Tabs/index.js +199 -193
- package/dist/Toast/index.d.ts +280 -64
- package/dist/Toast/index.js +299 -374
- package/dist/Toggle/index.d.ts +55 -35
- package/dist/Toggle/index.js +19 -13
- package/dist/ToggleGroup/index.d.ts +62 -35
- package/dist/ToggleGroup/index.js +13 -31
- package/dist/Toolbar/index.d.ts +117 -2
- package/dist/Toolbar/index.js +31 -43
- package/dist/Tooltip/index.d.ts +507 -150
- package/dist/Tooltip/index.js +163 -213
- package/dist/index.d.ts +12912 -5382
- package/package.json +3 -3
- package/dist/2205.js +0 -26
- package/dist/2274.js +0 -34
- package/dist/2287.js +0 -17
- package/dist/3020.js +0 -7
- package/dist/3021.js +0 -72
- package/dist/3140.js +0 -4
- package/dist/3248.js +0 -307
- package/dist/4026.js +0 -12
- package/dist/4922.js +0 -15
- package/dist/5659.js +0 -4
- package/dist/5992.js +0 -447
- package/dist/6330.js +0 -30
- package/dist/6535.js +0 -72
- package/dist/6917.js +0 -55
- package/dist/7725.js +0 -10
- package/dist/7871.js +0 -38
- package/dist/8106.js +0 -239
- package/dist/8685.js +0 -102
- package/dist/8935.js +0 -8
- package/dist/8971.js +0 -40
- package/dist/8979.js +0 -10
- package/dist/9048.js +0 -52
- package/dist/9087.js +0 -256
- package/dist/9255.js +0 -136
- /package/dist/{1457.js → 1068.js} +0 -0
- /package/dist/{6003.js → 1234.js} +0 -0
- /package/dist/{4723.js → 1282.js} +0 -0
- /package/dist/{6825.js → 1876.js} +0 -0
- /package/dist/{5778.js → 1885.js} +0 -0
- /package/dist/{2445.js.LICENSE.txt → 226.js.LICENSE.txt} +0 -0
- /package/dist/{1279.js → 3278.js} +0 -0
- /package/dist/{3296.js → 5568.js} +0 -0
- /package/dist/{8685.css → 6240.css} +0 -0
- /package/dist/{9829.js → 6488.js} +0 -0
- /package/dist/{9863.js → 6534.js} +0 -0
- /package/dist/{4495.js → 7718.js} +0 -0
- /package/dist/{3395.js → 8866.js} +0 -0
- /package/dist/{2418.js → 9837.js} +0 -0
package/dist/{1763.js → 9018.js}
RENAMED
|
@@ -1,43 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { useStableCallback } from "./7488.js";
|
|
2
|
+
import { clamp } from "./5568.js";
|
|
3
|
+
import { getTarget, closest, contains } from "./4155.js";
|
|
4
|
+
import { findScrollableTouchTarget, findScrollableAncestor } from "./5258.js";
|
|
5
|
+
import { ownerDocument } from "./6488.js";
|
|
6
|
+
import { getElementTransform } from "./7551.js";
|
|
6
7
|
import * as __rspack_external_react from "react";
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
if ('vertical' === axis) {
|
|
10
|
-
const overflowY = style.overflowY;
|
|
11
|
-
return ('auto' === overflowY || 'scroll' === overflowY) && element.scrollHeight > element.clientHeight;
|
|
12
|
-
}
|
|
13
|
-
const overflowX = style.overflowX;
|
|
14
|
-
return ('auto' === overflowX || 'scroll' === overflowX) && element.scrollWidth > element.clientWidth;
|
|
15
|
-
}
|
|
16
|
-
function hasScrollableAncestor(target, root, axes) {
|
|
17
|
-
let node = target;
|
|
18
|
-
while(node && node !== root){
|
|
19
|
-
for (const axis of axes)if (isScrollable(node, axis)) return true;
|
|
20
|
-
node = node.parentElement;
|
|
21
|
-
}
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
function findScrollableTouchTarget(target, root, axis = 'vertical') {
|
|
25
|
-
let node = isHTMLElement(target) ? target : null;
|
|
26
|
-
while(node && node !== root){
|
|
27
|
-
if (isScrollable(node, axis)) return node;
|
|
28
|
-
node = node.parentElement;
|
|
29
|
-
}
|
|
30
|
-
return isScrollable(root, axis) ? root : null;
|
|
31
|
-
}
|
|
32
|
-
function getElementAtPoint(doc, x, y) {
|
|
33
|
-
return 'function' == typeof doc?.elementFromPoint ? doc.elementFromPoint(x, y) : null;
|
|
8
|
+
function getElementAtPoint(root, x, y) {
|
|
9
|
+
return 'function' == typeof root?.elementFromPoint ? root.elementFromPoint(x, y) : null;
|
|
34
10
|
}
|
|
35
11
|
const DEFAULT_SWIPE_THRESHOLD = 40;
|
|
36
12
|
const REVERSE_CANCEL_THRESHOLD = 10;
|
|
37
|
-
const MIN_DRAG_THRESHOLD = 1;
|
|
38
13
|
const MIN_VELOCITY_DURATION_MS = 50;
|
|
39
|
-
const MIN_RELEASE_VELOCITY_DURATION_MS =
|
|
14
|
+
const MIN_RELEASE_VELOCITY_DURATION_MS = 4;
|
|
40
15
|
const MAX_RELEASE_VELOCITY_AGE_MS = 80;
|
|
16
|
+
const MIN_VELOCITY_SAMPLE_DISTANCE = 1;
|
|
41
17
|
const DEFAULT_IGNORE_SELECTOR = 'button,a,input,select,textarea,label,[role="button"]';
|
|
42
18
|
function getDisplacement(direction, deltaX, deltaY) {
|
|
43
19
|
switch(direction){
|
|
@@ -53,36 +29,12 @@ function getDisplacement(direction, deltaX, deltaY) {
|
|
|
53
29
|
return 0;
|
|
54
30
|
}
|
|
55
31
|
}
|
|
56
|
-
function getElementTransform(element) {
|
|
57
|
-
const computedStyle = getWindow(element).getComputedStyle(element);
|
|
58
|
-
const transform = computedStyle.transform;
|
|
59
|
-
let translateX = 0;
|
|
60
|
-
let translateY = 0;
|
|
61
|
-
let scale = 1;
|
|
62
|
-
if (transform && 'none' !== transform) {
|
|
63
|
-
const matrix = transform.match(/matrix(?:3d)?\(([^)]+)\)/);
|
|
64
|
-
if (matrix) {
|
|
65
|
-
const values = matrix[1].split(', ').map(parseFloat);
|
|
66
|
-
if (6 === values.length) {
|
|
67
|
-
translateX = values[4];
|
|
68
|
-
translateY = values[5];
|
|
69
|
-
scale = Math.sqrt(values[0] * values[0] + values[1] * values[1]);
|
|
70
|
-
} else if (16 === values.length) {
|
|
71
|
-
translateX = values[12];
|
|
72
|
-
translateY = values[13];
|
|
73
|
-
scale = values[0];
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
x: translateX,
|
|
79
|
-
y: translateY,
|
|
80
|
-
scale
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
32
|
function getValidTimeStamp(timeStamp) {
|
|
84
33
|
return Number.isFinite(timeStamp) && timeStamp > 0 ? timeStamp : null;
|
|
85
34
|
}
|
|
35
|
+
function getDragTransform(dragOffset, scale) {
|
|
36
|
+
return `translate3d(${dragOffset.x}px,${dragOffset.y}px,0) scale(${scale})`;
|
|
37
|
+
}
|
|
86
38
|
function hasPrimaryMouseButton(buttons) {
|
|
87
39
|
return buttons % 2 === 1;
|
|
88
40
|
}
|
|
@@ -107,29 +59,10 @@ function useSwipeDismiss(options) {
|
|
|
107
59
|
const allowDown = directions.includes('down');
|
|
108
60
|
const hasHorizontal = allowLeft || allowRight;
|
|
109
61
|
const hasVertical = allowUp || allowDown;
|
|
110
|
-
const
|
|
111
|
-
const axes = [];
|
|
112
|
-
if (hasVertical) axes.push('vertical');
|
|
113
|
-
if (hasHorizontal) axes.push('horizontal');
|
|
114
|
-
return axes;
|
|
115
|
-
}, [
|
|
116
|
-
hasHorizontal,
|
|
117
|
-
hasVertical
|
|
118
|
-
]);
|
|
62
|
+
const scrollAxis = hasHorizontal ? 'horizontal' : 'vertical';
|
|
119
63
|
const [currentSwipeDirection, setCurrentSwipeDirection] = __rspack_external_react.useState(void 0);
|
|
120
64
|
const [isSwiping, setIsSwiping] = __rspack_external_react.useState(false);
|
|
121
|
-
const [isRealSwipe, setIsRealSwipe] = __rspack_external_react.useState(false);
|
|
122
65
|
const [dragDismissed, setDragDismissed] = __rspack_external_react.useState(false);
|
|
123
|
-
const [dragOffset, setDragOffset] = __rspack_external_react.useState({
|
|
124
|
-
x: 0,
|
|
125
|
-
y: 0
|
|
126
|
-
});
|
|
127
|
-
const [initialTransform, setInitialTransform] = __rspack_external_react.useState({
|
|
128
|
-
x: 0,
|
|
129
|
-
y: 0,
|
|
130
|
-
scale: 1
|
|
131
|
-
});
|
|
132
|
-
const [lockedDirection, setLockedDirection] = __rspack_external_react.useState(null);
|
|
133
66
|
const dragStartPosRef = __rspack_external_react.useRef({
|
|
134
67
|
x: 0,
|
|
135
68
|
y: 0
|
|
@@ -162,14 +95,17 @@ function useSwipeDismiss(options) {
|
|
|
162
95
|
});
|
|
163
96
|
const swipeProgressRef = __rspack_external_react.useRef(0);
|
|
164
97
|
const swipeThresholdRef = __rspack_external_react.useRef(swipeThresholdDefault);
|
|
98
|
+
const swipeThresholdFunctionRef = __rspack_external_react.useRef(null);
|
|
165
99
|
const swipeStartTimeRef = __rspack_external_react.useRef(null);
|
|
166
100
|
const lastDragSampleRef = __rspack_external_react.useRef(null);
|
|
101
|
+
const hasStationarySampleRef = __rspack_external_react.useRef(false);
|
|
167
102
|
const lastDragVelocityRef = __rspack_external_react.useRef({
|
|
168
103
|
x: 0,
|
|
169
104
|
y: 0
|
|
170
105
|
});
|
|
171
106
|
const lastProgressDetailsRef = __rspack_external_react.useRef(null);
|
|
172
107
|
const isSwipingRef = __rspack_external_react.useRef(false);
|
|
108
|
+
const dragStyleSnapshotRef = __rspack_external_react.useRef(null);
|
|
173
109
|
const setSwiping = useStableCallback((nextSwiping)=>{
|
|
174
110
|
if (isSwipingRef.current === nextSwiping) return;
|
|
175
111
|
isSwipingRef.current = nextSwiping;
|
|
@@ -178,13 +114,10 @@ function useSwipeDismiss(options) {
|
|
|
178
114
|
});
|
|
179
115
|
function resolveSwipeThreshold(direction) {
|
|
180
116
|
if (!direction) return;
|
|
181
|
-
if ('function' != typeof swipeThresholdProp) {
|
|
182
|
-
swipeThresholdRef.current = swipeThresholdDefault;
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
117
|
const element = elementRef.current;
|
|
186
|
-
|
|
187
|
-
|
|
118
|
+
const thresholdFunction = swipeThresholdFunctionRef.current;
|
|
119
|
+
if (!element || !thresholdFunction) return;
|
|
120
|
+
const value = thresholdFunction({
|
|
188
121
|
element,
|
|
189
122
|
direction
|
|
190
123
|
});
|
|
@@ -204,10 +137,40 @@ function useSwipeDismiss(options) {
|
|
|
204
137
|
else if (progressChanged) lastProgressDetailsRef.current = null;
|
|
205
138
|
onProgress?.(nextProgress, details);
|
|
206
139
|
});
|
|
140
|
+
const syncDragStyles = useStableCallback((swiping)=>{
|
|
141
|
+
const element = elementRef.current;
|
|
142
|
+
if (!trackDrag || !element) {
|
|
143
|
+
if (!swiping) dragStyleSnapshotRef.current = null;
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const style = element.style;
|
|
147
|
+
const dragStyleSnapshot = dragStyleSnapshotRef.current;
|
|
148
|
+
if (swiping) {
|
|
149
|
+
if (!dragStyleSnapshot) dragStyleSnapshotRef.current = [
|
|
150
|
+
style.transition,
|
|
151
|
+
style.transform
|
|
152
|
+
];
|
|
153
|
+
style.transition = 'none';
|
|
154
|
+
} else if (dragStyleSnapshot) {
|
|
155
|
+
[style.transition, style.transform] = dragStyleSnapshot;
|
|
156
|
+
dragStyleSnapshotRef.current = null;
|
|
157
|
+
}
|
|
158
|
+
const dragOffset = dragOffsetRef.current;
|
|
159
|
+
const initialTransform = initialTransformRef.current;
|
|
160
|
+
const deltaX = dragOffset.x - initialTransform.x;
|
|
161
|
+
const deltaY = dragOffset.y - initialTransform.y;
|
|
162
|
+
if (swiping) style.transform = getDragTransform(dragOffset, initialTransform.scale);
|
|
163
|
+
style.setProperty(movementCssVars.x, `${deltaX}px`);
|
|
164
|
+
style.setProperty(movementCssVars.y, `${deltaY}px`);
|
|
165
|
+
});
|
|
207
166
|
function recordDragSample(offset, timeStamp) {
|
|
208
167
|
if (null === timeStamp) return;
|
|
209
168
|
const lastSample = lastDragSampleRef.current;
|
|
210
169
|
if (lastSample && timeStamp > lastSample.time) {
|
|
170
|
+
const stationary = Math.abs(offset.x - lastSample.x) < MIN_VELOCITY_SAMPLE_DISTANCE && Math.abs(offset.y - lastSample.y) < MIN_VELOCITY_SAMPLE_DISTANCE;
|
|
171
|
+
const skipSample = stationary && !hasStationarySampleRef.current;
|
|
172
|
+
hasStationarySampleRef.current = stationary;
|
|
173
|
+
if (skipSample) return;
|
|
211
174
|
const durationMs = Math.max(timeStamp - lastSample.time, MIN_RELEASE_VELOCITY_DURATION_MS);
|
|
212
175
|
lastDragVelocityRef.current = {
|
|
213
176
|
x: (offset.x - lastSample.x) / durationMs,
|
|
@@ -223,20 +186,10 @@ function useSwipeDismiss(options) {
|
|
|
223
186
|
const reset = __rspack_external_react.useCallback(()=>{
|
|
224
187
|
setCurrentSwipeDirection(void 0);
|
|
225
188
|
setSwiping(false);
|
|
226
|
-
setIsRealSwipe(false);
|
|
227
189
|
setDragDismissed(false);
|
|
228
|
-
setDragOffset({
|
|
229
|
-
x: 0,
|
|
230
|
-
y: 0
|
|
231
|
-
});
|
|
232
|
-
setInitialTransform({
|
|
233
|
-
x: 0,
|
|
234
|
-
y: 0,
|
|
235
|
-
scale: 1
|
|
236
|
-
});
|
|
237
|
-
setLockedDirection(null);
|
|
238
190
|
updateSwipeProgress(0);
|
|
239
191
|
swipeThresholdRef.current = swipeThresholdDefault;
|
|
192
|
+
swipeThresholdFunctionRef.current = null;
|
|
240
193
|
dragStartPosRef.current = {
|
|
241
194
|
x: 0,
|
|
242
195
|
y: 0
|
|
@@ -269,22 +222,19 @@ function useSwipeDismiss(options) {
|
|
|
269
222
|
};
|
|
270
223
|
swipeStartTimeRef.current = null;
|
|
271
224
|
lastDragSampleRef.current = null;
|
|
225
|
+
hasStationarySampleRef.current = false;
|
|
272
226
|
lastDragVelocityRef.current = {
|
|
273
227
|
x: 0,
|
|
274
228
|
y: 0
|
|
275
229
|
};
|
|
276
230
|
lastProgressDetailsRef.current = null;
|
|
231
|
+
syncDragStyles(false);
|
|
277
232
|
}, [
|
|
278
233
|
setSwiping,
|
|
279
234
|
swipeThresholdDefault,
|
|
235
|
+
syncDragStyles,
|
|
280
236
|
updateSwipeProgress
|
|
281
237
|
]);
|
|
282
|
-
__rspack_external_react.useEffect(()=>{
|
|
283
|
-
if ('function' != typeof swipeThresholdProp) swipeThresholdRef.current = swipeThresholdDefault;
|
|
284
|
-
}, [
|
|
285
|
-
swipeThresholdDefault,
|
|
286
|
-
swipeThresholdProp
|
|
287
|
-
]);
|
|
288
238
|
function getPrimaryPointerPosition(event) {
|
|
289
239
|
if ('touches' in event) {
|
|
290
240
|
const touch = event.touches[0];
|
|
@@ -303,15 +253,18 @@ function useSwipeDismiss(options) {
|
|
|
303
253
|
return 'touch' === event.pointerType;
|
|
304
254
|
}
|
|
305
255
|
function getTargetAtPoint(position, nativeEvent) {
|
|
306
|
-
const
|
|
307
|
-
const elementAtPoint = getElementAtPoint(
|
|
256
|
+
const root = elementRef.current?.getRootNode();
|
|
257
|
+
const elementAtPoint = getElementAtPoint(root, position.x, position.y);
|
|
308
258
|
const target = elementAtPoint ?? getTarget(nativeEvent);
|
|
309
259
|
return target;
|
|
310
260
|
}
|
|
311
261
|
function findGestureScrollableTouchTarget(target, root) {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
262
|
+
const find = (axis)=>{
|
|
263
|
+
const scrollTarget = findScrollableTouchTarget(target, root, axis);
|
|
264
|
+
const doc = ownerDocument(scrollTarget);
|
|
265
|
+
return scrollTarget === doc.body || scrollTarget === doc.documentElement ? null : scrollTarget;
|
|
266
|
+
};
|
|
267
|
+
return find(scrollAxis);
|
|
315
268
|
}
|
|
316
269
|
function startSwipeAtPosition(event, position, startOptions) {
|
|
317
270
|
swipeFromScrollableRef.current = false;
|
|
@@ -323,20 +276,28 @@ function useSwipeDismiss(options) {
|
|
|
323
276
|
const ignoreScrollableTarget = startOptions?.ignoreScrollableTarget ?? false;
|
|
324
277
|
if (scrollableTarget && !ignoreScrollableTarget) return false;
|
|
325
278
|
swipeFromScrollableRef.current = Boolean(scrollableTarget && ignoreScrollableTarget);
|
|
326
|
-
const isInteractiveElement = target
|
|
279
|
+
const isInteractiveElement = closest(target, ignoreSelector);
|
|
327
280
|
if (isInteractiveElement && (!touchLike || ignoreSelectorWhenTouch)) return false;
|
|
328
281
|
const element = elementRef.current;
|
|
329
|
-
if (ignoreScrollableAncestors && element && target
|
|
282
|
+
if (ignoreScrollableAncestors && element && target) {
|
|
330
283
|
const ignoreAncestors = startOptions?.ignoreScrollableAncestors ?? false;
|
|
331
|
-
if (!ignoreAncestors &&
|
|
284
|
+
if (!ignoreAncestors && null != findScrollableAncestor(target, element, scrollAxis)) return false;
|
|
332
285
|
}
|
|
333
286
|
cancelledSwipeRef.current = false;
|
|
334
287
|
intendedSwipeDirectionRef.current = void 0;
|
|
335
288
|
maxSwipeDisplacementRef.current = 0;
|
|
336
289
|
dragStartPosRef.current = position;
|
|
337
290
|
swipeStartTimeRef.current = getValidTimeStamp(event.timeStamp);
|
|
291
|
+
lastDragSampleRef.current = null;
|
|
292
|
+
hasStationarySampleRef.current = false;
|
|
293
|
+
lastDragVelocityRef.current = {
|
|
294
|
+
x: 0,
|
|
295
|
+
y: 0
|
|
296
|
+
};
|
|
338
297
|
swipeCancelBaselineRef.current = position;
|
|
339
298
|
lastMovePosRef.current = position;
|
|
299
|
+
swipeThresholdRef.current = swipeThresholdDefault;
|
|
300
|
+
swipeThresholdFunctionRef.current = 'function' == typeof swipeThresholdProp ? swipeThresholdProp : null;
|
|
340
301
|
if (element) {
|
|
341
302
|
elementSizeRef.current = {
|
|
342
303
|
width: element.offsetWidth,
|
|
@@ -349,11 +310,6 @@ function useSwipeDismiss(options) {
|
|
|
349
310
|
x: transform.x,
|
|
350
311
|
y: transform.y
|
|
351
312
|
};
|
|
352
|
-
setInitialTransform(transform);
|
|
353
|
-
setDragOffset({
|
|
354
|
-
x: transform.x,
|
|
355
|
-
y: transform.y
|
|
356
|
-
});
|
|
357
313
|
recordDragSample({
|
|
358
314
|
x: transform.x,
|
|
359
315
|
y: transform.y
|
|
@@ -362,10 +318,9 @@ function useSwipeDismiss(options) {
|
|
|
362
318
|
}
|
|
363
319
|
onSwipeStart?.(event.nativeEvent);
|
|
364
320
|
setSwiping(true);
|
|
365
|
-
setIsRealSwipe(false);
|
|
366
|
-
setLockedDirection(null);
|
|
367
321
|
isFirstPointerMoveRef.current = true;
|
|
368
322
|
updateSwipeProgress(0);
|
|
323
|
+
syncDragStyles(true);
|
|
369
324
|
return true;
|
|
370
325
|
}
|
|
371
326
|
function resetPendingSwipeState() {
|
|
@@ -381,19 +336,14 @@ function useSwipeDismiss(options) {
|
|
|
381
336
|
resetPendingSwipeState();
|
|
382
337
|
if (!isSwipingRef.current) return;
|
|
383
338
|
setSwiping(false);
|
|
384
|
-
|
|
385
|
-
setLockedDirection(null);
|
|
386
|
-
const resolvedInitialTransform = trackDrag ? initialTransform : initialTransformRef.current;
|
|
339
|
+
const resolvedInitialTransform = initialTransformRef.current;
|
|
387
340
|
dragOffsetRef.current = {
|
|
388
341
|
x: resolvedInitialTransform.x,
|
|
389
342
|
y: resolvedInitialTransform.y
|
|
390
343
|
};
|
|
391
|
-
setDragOffset({
|
|
392
|
-
x: resolvedInitialTransform.x,
|
|
393
|
-
y: resolvedInitialTransform.y
|
|
394
|
-
});
|
|
395
344
|
setCurrentSwipeDirection(void 0);
|
|
396
345
|
sawPrimaryButtonsOnMoveRef.current = false;
|
|
346
|
+
syncDragStyles(false);
|
|
397
347
|
const element = elementRef.current;
|
|
398
348
|
if (element) safelyChangePointerCapture(element, event.pointerId, 'releasePointerCapture');
|
|
399
349
|
updateSwipeProgress(0, {
|
|
@@ -404,10 +354,9 @@ function useSwipeDismiss(options) {
|
|
|
404
354
|
onCancel?.(event.nativeEvent);
|
|
405
355
|
}
|
|
406
356
|
function applyDirectionalDamping(deltaX, deltaY) {
|
|
407
|
-
const exponent = (value)=>value
|
|
357
|
+
const exponent = (value)=>Math.sign(value) * Math.abs(value) ** 0.5;
|
|
408
358
|
const dampAxis = (delta, allowNegative, allowPositive)=>{
|
|
409
|
-
if (!allowNegative && delta < 0) return exponent(delta);
|
|
410
|
-
if (!allowPositive && delta > 0) return exponent(delta);
|
|
359
|
+
if (!allowNegative && delta < 0 || !allowPositive && delta > 0) return exponent(delta);
|
|
411
360
|
return delta;
|
|
412
361
|
};
|
|
413
362
|
const newDeltaX = hasHorizontal ? dampAxis(deltaX, allowLeft, allowRight) : exponent(deltaX);
|
|
@@ -418,30 +367,9 @@ function useSwipeDismiss(options) {
|
|
|
418
367
|
};
|
|
419
368
|
}
|
|
420
369
|
function canSwipeFromScrollEdgeOnPendingMove(scrollTarget, deltaX, deltaY) {
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
if (useVerticalAxis) {
|
|
425
|
-
const maxScrollTop = Math.max(0, scrollTarget.scrollHeight - scrollTarget.clientHeight);
|
|
426
|
-
const atTop = scrollTarget.scrollTop <= 0;
|
|
427
|
-
const atBottom = scrollTarget.scrollTop >= maxScrollTop;
|
|
428
|
-
const movingDown = deltaY > 0;
|
|
429
|
-
const movingUp = deltaY < 0;
|
|
430
|
-
const canSwipeDown = movingDown && atTop && allowDown;
|
|
431
|
-
const canSwipeUp = movingUp && atBottom && allowUp;
|
|
432
|
-
return canSwipeDown || canSwipeUp;
|
|
433
|
-
}
|
|
434
|
-
const useHorizontalAxis = hasHorizontal && 0 !== deltaX && (!hasVertical || absDeltaX > absDeltaY);
|
|
435
|
-
if (useHorizontalAxis) {
|
|
436
|
-
const maxScrollLeft = Math.max(0, scrollTarget.scrollWidth - scrollTarget.clientWidth);
|
|
437
|
-
const atLeft = scrollTarget.scrollLeft <= 0;
|
|
438
|
-
const atRight = scrollTarget.scrollLeft >= maxScrollLeft;
|
|
439
|
-
const movingRight = deltaX > 0;
|
|
440
|
-
const movingLeft = deltaX < 0;
|
|
441
|
-
const canSwipeRight = movingRight && atLeft && allowRight;
|
|
442
|
-
const canSwipeLeft = movingLeft && atRight && allowLeft;
|
|
443
|
-
return canSwipeRight || canSwipeLeft;
|
|
444
|
-
}
|
|
370
|
+
const canSwipeOnAxis = (delta, scrollOffset, maxScrollOffset, allowTowardStart, allowTowardEnd)=>delta > 0 && scrollOffset <= 0 && allowTowardStart || delta < 0 && scrollOffset >= Math.max(0, maxScrollOffset) && allowTowardEnd;
|
|
371
|
+
if (hasVertical && 0 !== deltaY) return canSwipeOnAxis(deltaY, scrollTarget.scrollTop, scrollTarget.scrollHeight - scrollTarget.clientHeight, allowDown, allowUp);
|
|
372
|
+
if (hasHorizontal && 0 !== deltaX) return canSwipeOnAxis(deltaX, scrollTarget.scrollLeft, scrollTarget.scrollWidth - scrollTarget.clientWidth, allowRight, allowLeft);
|
|
445
373
|
return null;
|
|
446
374
|
}
|
|
447
375
|
const handleStart = useStableCallback((event)=>{
|
|
@@ -453,7 +381,7 @@ function useSwipeDismiss(options) {
|
|
|
453
381
|
pendingSwipeRef.current = true;
|
|
454
382
|
pendingSwipeStartPosRef.current = startPos;
|
|
455
383
|
swipeFromScrollableRef.current = false;
|
|
456
|
-
sawPrimaryButtonsOnMoveRef.current =
|
|
384
|
+
sawPrimaryButtonsOnMoveRef.current = !('touches' in event);
|
|
457
385
|
const allowedToStart = canStart ? canStart(startPos, {
|
|
458
386
|
nativeEvent: event.nativeEvent,
|
|
459
387
|
direction: primaryDirection
|
|
@@ -470,10 +398,14 @@ function useSwipeDismiss(options) {
|
|
|
470
398
|
}
|
|
471
399
|
if (!('touches' in event)) event.preventDefault();
|
|
472
400
|
if (isFirstPointerMoveRef.current) {
|
|
473
|
-
dragStartPosRef.current = position;
|
|
474
|
-
const moveTime = getValidTimeStamp(event.timeStamp);
|
|
475
|
-
if (null !== moveTime) swipeStartTimeRef.current = moveTime;
|
|
476
401
|
isFirstPointerMoveRef.current = false;
|
|
402
|
+
if (trackDrag) {
|
|
403
|
+
dragStartPosRef.current = position;
|
|
404
|
+
const moveTime = getValidTimeStamp(event.timeStamp);
|
|
405
|
+
if (null !== moveTime) swipeStartTimeRef.current = moveTime;
|
|
406
|
+
lastDragSampleRef.current = null;
|
|
407
|
+
hasStationarySampleRef.current = false;
|
|
408
|
+
}
|
|
477
409
|
}
|
|
478
410
|
const clientX = position.x;
|
|
479
411
|
const clientY = position.y;
|
|
@@ -491,19 +423,6 @@ function useSwipeDismiss(options) {
|
|
|
491
423
|
const deltaY = clientY - dragStartPosRef.current.y;
|
|
492
424
|
const cancelDeltaY = clientY - swipeCancelBaselineRef.current.y;
|
|
493
425
|
const cancelDeltaX = clientX - swipeCancelBaselineRef.current.x;
|
|
494
|
-
if (!isRealSwipe) {
|
|
495
|
-
const movementDistance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
|
496
|
-
if (movementDistance >= MIN_DRAG_THRESHOLD) {
|
|
497
|
-
setIsRealSwipe(true);
|
|
498
|
-
if (null === lockedDirection) {
|
|
499
|
-
if (hasHorizontal && hasVertical) {
|
|
500
|
-
const absX = Math.abs(deltaX);
|
|
501
|
-
const absY = Math.abs(deltaY);
|
|
502
|
-
setLockedDirection(absX > absY ? 'horizontal' : 'vertical');
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
426
|
let candidate;
|
|
508
427
|
if (intendedSwipeDirectionRef.current) {
|
|
509
428
|
const direction = intendedSwipeDirectionRef.current;
|
|
@@ -513,13 +432,7 @@ function useSwipeDismiss(options) {
|
|
|
513
432
|
setCurrentSwipeDirection(direction);
|
|
514
433
|
} else if (!(allowLeft && allowRight) && !(allowUp && allowDown) && maxSwipeDisplacementRef.current - currentDisplacement >= REVERSE_CANCEL_THRESHOLD) cancelledSwipeRef.current = true;
|
|
515
434
|
} else {
|
|
516
|
-
|
|
517
|
-
if (deltaY > 0) candidate = 'down';
|
|
518
|
-
else if (deltaY < 0) candidate = 'up';
|
|
519
|
-
} else if ('horizontal' === lockedDirection) {
|
|
520
|
-
if (deltaX > 0) candidate = 'right';
|
|
521
|
-
else if (deltaX < 0) candidate = 'left';
|
|
522
|
-
} else candidate = Math.abs(deltaX) >= Math.abs(deltaY) ? deltaX > 0 ? 'right' : 'left' : deltaY > 0 ? 'down' : 'up';
|
|
435
|
+
candidate = Math.abs(deltaX) >= Math.abs(deltaY) ? deltaX > 0 ? 'right' : 'left' : deltaY > 0 ? 'down' : 'up';
|
|
523
436
|
if (candidate) {
|
|
524
437
|
const isAllowed = 'left' === candidate && allowLeft || 'right' === candidate && allowRight || 'up' === candidate && allowUp || 'down' === candidate && allowDown;
|
|
525
438
|
if (isAllowed) {
|
|
@@ -533,115 +446,36 @@ function useSwipeDismiss(options) {
|
|
|
533
446
|
const dampedDelta = applyDirectionalDamping(deltaX, deltaY);
|
|
534
447
|
let newOffsetX = initialTransformRef.current.x;
|
|
535
448
|
let newOffsetY = initialTransformRef.current.y;
|
|
536
|
-
if (
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
} else {
|
|
541
|
-
if (hasHorizontal) newOffsetX += dampedDelta.x;
|
|
542
|
-
if (hasVertical) newOffsetY += dampedDelta.y;
|
|
543
|
-
}
|
|
449
|
+
if (hasHorizontal) newOffsetX += dampedDelta.x;
|
|
450
|
+
if (hasVertical) newOffsetY += dampedDelta.y;
|
|
451
|
+
const previousOffset = dragOffsetRef.current;
|
|
452
|
+
const offsetChanged = newOffsetX !== previousOffset.x || newOffsetY !== previousOffset.y;
|
|
544
453
|
dragOffsetRef.current = {
|
|
545
454
|
x: newOffsetX,
|
|
546
455
|
y: newOffsetY
|
|
547
456
|
};
|
|
548
|
-
if (
|
|
549
|
-
x: newOffsetX,
|
|
550
|
-
y: newOffsetY
|
|
551
|
-
});
|
|
457
|
+
if (offsetChanged) syncDragStyles(true);
|
|
552
458
|
recordDragSample({
|
|
553
459
|
x: newOffsetX,
|
|
554
460
|
y: newOffsetY
|
|
555
461
|
}, getValidTimeStamp(event.timeStamp));
|
|
556
462
|
const dragDeltaX = newOffsetX - initialTransformRef.current.x;
|
|
557
463
|
const dragDeltaY = newOffsetY - initialTransformRef.current.y;
|
|
558
|
-
const
|
|
559
|
-
const progressDirection = primaryDirection ?? intendedSwipeDirectionRef.current;
|
|
560
|
-
if (!progressDirection) return void updateSwipeProgress(0, {
|
|
561
|
-
deltaX: dragDeltaX,
|
|
562
|
-
deltaY: dragDeltaY,
|
|
563
|
-
direction: swipeDirectionDetails
|
|
564
|
-
});
|
|
565
|
-
const size = 'left' === progressDirection || 'right' === progressDirection ? elementSizeRef.current.width : elementSizeRef.current.height;
|
|
566
|
-
const scale = initialTransformRef.current.scale || 1;
|
|
567
|
-
if (size <= 0 || scale <= 0) return void updateSwipeProgress(0, {
|
|
568
|
-
deltaX: dragDeltaX,
|
|
569
|
-
deltaY: dragDeltaY,
|
|
570
|
-
direction: swipeDirectionDetails
|
|
571
|
-
});
|
|
572
|
-
const progressDisplacement = getDisplacement(progressDirection, newOffsetX - initialTransformRef.current.x, newOffsetY - initialTransformRef.current.y);
|
|
573
|
-
if (progressDisplacement <= 0) return void updateSwipeProgress(0, {
|
|
574
|
-
deltaX: dragDeltaX,
|
|
575
|
-
deltaY: dragDeltaY,
|
|
576
|
-
direction: swipeDirectionDetails
|
|
577
|
-
});
|
|
578
|
-
updateSwipeProgress(progressDisplacement / (size * scale), {
|
|
464
|
+
const progressDetails = {
|
|
579
465
|
deltaX: dragDeltaX,
|
|
580
466
|
deltaY: dragDeltaY,
|
|
581
|
-
direction:
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
|
-
const handleMove = useStableCallback((event)=>{
|
|
585
|
-
const currentPos = getPrimaryPointerPosition(event);
|
|
586
|
-
if (!currentPos) return;
|
|
587
|
-
if (!('touches' in event)) {
|
|
588
|
-
const hasPrimaryButton = hasPrimaryMouseButton(event.buttons);
|
|
589
|
-
if (hasPrimaryButton) sawPrimaryButtonsOnMoveRef.current = true;
|
|
590
|
-
const lostPrimaryButtonDuringSwipe = 0 === event.buttons && sawPrimaryButtonsOnMoveRef.current;
|
|
591
|
-
if (0 !== event.buttons && !hasPrimaryButton || lostPrimaryButtonDuringSwipe) return void cancelSwipeInteraction(event);
|
|
592
|
-
}
|
|
593
|
-
if (!isSwiping && pendingSwipeRef.current) {
|
|
594
|
-
if (!isTouchLikeEvent(event) && (event.defaultPrevented || event.nativeEvent.defaultPrevented)) return void resetPendingSwipeState();
|
|
595
|
-
const allowedToStart = canStart ? canStart(currentPos, {
|
|
596
|
-
nativeEvent: event.nativeEvent,
|
|
597
|
-
direction: primaryDirection
|
|
598
|
-
}) : true;
|
|
599
|
-
if (allowedToStart) {
|
|
600
|
-
const pendingStartPos = pendingSwipeStartPosRef.current;
|
|
601
|
-
let ignoreScrollableOnStart = false;
|
|
602
|
-
if (isTouchLikeEvent(event)) {
|
|
603
|
-
const element = elementRef.current;
|
|
604
|
-
if (pendingStartPos && element) {
|
|
605
|
-
const target = getTargetAtPoint(currentPos, event.nativeEvent);
|
|
606
|
-
const doc = ownerDocument(element);
|
|
607
|
-
const body = doc.body;
|
|
608
|
-
const scrollTarget = body ? findGestureScrollableTouchTarget(target, body) : null;
|
|
609
|
-
if (scrollTarget && (contains(element, scrollTarget) || contains(scrollTarget, element))) {
|
|
610
|
-
const deltaX = currentPos.x - pendingStartPos.x;
|
|
611
|
-
const deltaY = currentPos.y - pendingStartPos.y;
|
|
612
|
-
const canSwipeFromEdge = canSwipeFromScrollEdgeOnPendingMove(scrollTarget, deltaX, deltaY);
|
|
613
|
-
if (false === canSwipeFromEdge) return;
|
|
614
|
-
if (true === canSwipeFromEdge) ignoreScrollableOnStart = true;
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
const started = startSwipeAtPosition(event, currentPos, {
|
|
619
|
-
ignoreScrollableTarget: ignoreScrollableOnStart,
|
|
620
|
-
ignoreScrollableAncestors: ignoreScrollableOnStart
|
|
621
|
-
});
|
|
622
|
-
if (started) if (pendingStartPos && ignoreScrollableOnStart) {
|
|
623
|
-
clearPendingSwipeStartState();
|
|
624
|
-
dragStartPosRef.current = pendingStartPos;
|
|
625
|
-
swipeCancelBaselineRef.current = pendingStartPos;
|
|
626
|
-
lastMovePosRef.current = pendingStartPos;
|
|
627
|
-
isFirstPointerMoveRef.current = false;
|
|
628
|
-
} else {
|
|
629
|
-
clearPendingSwipeStartState();
|
|
630
|
-
swipeFromScrollableRef.current = false;
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
const previousPos = lastMovePosRef.current;
|
|
635
|
-
const movement = null === previousPos ? {
|
|
636
|
-
x: 0,
|
|
637
|
-
y: 0
|
|
638
|
-
} : {
|
|
639
|
-
x: currentPos.x - previousPos.x,
|
|
640
|
-
y: currentPos.y - previousPos.y
|
|
467
|
+
direction: intendedSwipeDirectionRef.current
|
|
641
468
|
};
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
469
|
+
let progress = 0;
|
|
470
|
+
const progressDirection = primaryDirection ?? intendedSwipeDirectionRef.current;
|
|
471
|
+
if (progressDirection) {
|
|
472
|
+
const size = 'left' === progressDirection || 'right' === progressDirection ? elementSizeRef.current.width : elementSizeRef.current.height;
|
|
473
|
+
const scale = initialTransformRef.current.scale || 1;
|
|
474
|
+
const progressDisplacement = getDisplacement(progressDirection, dragDeltaX, dragDeltaY);
|
|
475
|
+
if (size > 0 && scale > 0 && progressDisplacement > 0) progress = progressDisplacement / (size * scale);
|
|
476
|
+
}
|
|
477
|
+
updateSwipeProgress(progress, progressDetails);
|
|
478
|
+
}
|
|
645
479
|
const handleEnd = useStableCallback((event)=>{
|
|
646
480
|
if (!enabled) return;
|
|
647
481
|
const resolvedDragOffset = dragOffsetRef.current;
|
|
@@ -651,7 +485,7 @@ function useSwipeDismiss(options) {
|
|
|
651
485
|
const progressDetails = {
|
|
652
486
|
deltaX: releaseDeltaX,
|
|
653
487
|
deltaY: releaseDeltaY,
|
|
654
|
-
direction:
|
|
488
|
+
direction: intendedSwipeDirectionRef.current
|
|
655
489
|
};
|
|
656
490
|
if (!isSwipingRef.current) {
|
|
657
491
|
resetPendingSwipeState();
|
|
@@ -659,8 +493,6 @@ function useSwipeDismiss(options) {
|
|
|
659
493
|
return;
|
|
660
494
|
}
|
|
661
495
|
setSwiping(false);
|
|
662
|
-
setIsRealSwipe(false);
|
|
663
|
-
setLockedDirection(null);
|
|
664
496
|
resetPendingSwipeState();
|
|
665
497
|
sawPrimaryButtonsOnMoveRef.current = false;
|
|
666
498
|
const element = elementRef.current;
|
|
@@ -686,8 +518,8 @@ function useSwipeDismiss(options) {
|
|
|
686
518
|
const deltaFromLastSampleY = resolvedDragOffset.y - lastSample.y;
|
|
687
519
|
const sampleVelocityX = deltaFromLastSampleX / sampleDurationMs;
|
|
688
520
|
const sampleVelocityY = deltaFromLastSampleY / sampleDurationMs;
|
|
689
|
-
if (
|
|
690
|
-
if (
|
|
521
|
+
if (Math.abs(deltaFromLastSampleX) >= MIN_VELOCITY_SAMPLE_DISTANCE) releaseVelocityX = sampleVelocityX;
|
|
522
|
+
if (Math.abs(deltaFromLastSampleY) >= MIN_VELOCITY_SAMPLE_DISTANCE) releaseVelocityY = sampleVelocityY;
|
|
691
523
|
} else {
|
|
692
524
|
releaseVelocityX = 0;
|
|
693
525
|
releaseVelocityY = 0;
|
|
@@ -695,7 +527,7 @@ function useSwipeDismiss(options) {
|
|
|
695
527
|
}
|
|
696
528
|
const releaseDecision = onRelease?.({
|
|
697
529
|
event: event.nativeEvent,
|
|
698
|
-
direction:
|
|
530
|
+
direction: intendedSwipeDirectionRef.current,
|
|
699
531
|
deltaX,
|
|
700
532
|
deltaY,
|
|
701
533
|
velocityX,
|
|
@@ -709,11 +541,8 @@ function useSwipeDismiss(options) {
|
|
|
709
541
|
x: resolvedInitialTransform.x,
|
|
710
542
|
y: resolvedInitialTransform.y
|
|
711
543
|
};
|
|
712
|
-
setDragOffset({
|
|
713
|
-
x: resolvedInitialTransform.x,
|
|
714
|
-
y: resolvedInitialTransform.y
|
|
715
|
-
});
|
|
716
544
|
setCurrentSwipeDirection(void 0);
|
|
545
|
+
syncDragStyles(false);
|
|
717
546
|
updateSwipeProgress(0, progressDetails);
|
|
718
547
|
return;
|
|
719
548
|
}
|
|
@@ -721,41 +550,16 @@ function useSwipeDismiss(options) {
|
|
|
721
550
|
let dismissDirection;
|
|
722
551
|
if (hasReleaseDecision) {
|
|
723
552
|
shouldClose = releaseDecision;
|
|
724
|
-
dismissDirection =
|
|
725
|
-
} else for (const direction of directions){
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
shouldClose = true;
|
|
730
|
-
dismissDirection = 'right';
|
|
731
|
-
}
|
|
732
|
-
break;
|
|
733
|
-
case 'left':
|
|
734
|
-
if (deltaX < -swipeThresholdRef.current) {
|
|
735
|
-
shouldClose = true;
|
|
736
|
-
dismissDirection = 'left';
|
|
737
|
-
}
|
|
738
|
-
break;
|
|
739
|
-
case 'down':
|
|
740
|
-
if (deltaY > swipeThresholdRef.current) {
|
|
741
|
-
shouldClose = true;
|
|
742
|
-
dismissDirection = 'down';
|
|
743
|
-
}
|
|
744
|
-
break;
|
|
745
|
-
case 'up':
|
|
746
|
-
if (deltaY < -swipeThresholdRef.current) {
|
|
747
|
-
shouldClose = true;
|
|
748
|
-
dismissDirection = 'up';
|
|
749
|
-
}
|
|
750
|
-
break;
|
|
751
|
-
default:
|
|
752
|
-
break;
|
|
753
|
-
}
|
|
754
|
-
if (shouldClose) break;
|
|
553
|
+
dismissDirection = intendedSwipeDirectionRef.current ?? primaryDirection;
|
|
554
|
+
} else for (const direction of directions)if (getDisplacement(direction, deltaX, deltaY) > swipeThresholdRef.current) {
|
|
555
|
+
shouldClose = true;
|
|
556
|
+
dismissDirection = direction;
|
|
557
|
+
break;
|
|
755
558
|
}
|
|
756
559
|
if (shouldClose && dismissDirection) {
|
|
757
560
|
setCurrentSwipeDirection(dismissDirection);
|
|
758
561
|
setDragDismissed(true);
|
|
562
|
+
syncDragStyles(false);
|
|
759
563
|
onDismiss?.(event.nativeEvent, {
|
|
760
564
|
direction: dismissDirection
|
|
761
565
|
});
|
|
@@ -764,36 +568,105 @@ function useSwipeDismiss(options) {
|
|
|
764
568
|
x: resolvedInitialTransform.x,
|
|
765
569
|
y: resolvedInitialTransform.y
|
|
766
570
|
};
|
|
767
|
-
setDragOffset({
|
|
768
|
-
x: resolvedInitialTransform.x,
|
|
769
|
-
y: resolvedInitialTransform.y
|
|
770
|
-
});
|
|
771
571
|
setCurrentSwipeDirection(void 0);
|
|
572
|
+
syncDragStyles(false);
|
|
772
573
|
updateSwipeProgress(0, progressDetails);
|
|
773
574
|
}
|
|
774
575
|
});
|
|
576
|
+
const handleMove = useStableCallback((event)=>{
|
|
577
|
+
const currentPos = getPrimaryPointerPosition(event);
|
|
578
|
+
if (!currentPos) return;
|
|
579
|
+
let endAfterMove = false;
|
|
580
|
+
if (!('touches' in event)) {
|
|
581
|
+
const hasPrimaryButton = hasPrimaryMouseButton(event.buttons);
|
|
582
|
+
if (hasPrimaryButton) sawPrimaryButtonsOnMoveRef.current = true;
|
|
583
|
+
if (0 !== event.buttons && !hasPrimaryButton) return void cancelSwipeInteraction(event);
|
|
584
|
+
if (0 === event.buttons && sawPrimaryButtonsOnMoveRef.current) {
|
|
585
|
+
if (!isSwipingRef.current) return void handleEnd(event);
|
|
586
|
+
endAfterMove = true;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
if (!isSwiping && pendingSwipeRef.current) {
|
|
590
|
+
if (!isTouchLikeEvent(event) && (event.defaultPrevented || event.nativeEvent.defaultPrevented)) return void resetPendingSwipeState();
|
|
591
|
+
const allowedToStart = canStart ? canStart(currentPos, {
|
|
592
|
+
nativeEvent: event.nativeEvent,
|
|
593
|
+
direction: primaryDirection
|
|
594
|
+
}) : true;
|
|
595
|
+
if (allowedToStart) {
|
|
596
|
+
const pendingStartPos = pendingSwipeStartPosRef.current;
|
|
597
|
+
let ignoreScrollableOnStart = false;
|
|
598
|
+
if (isTouchLikeEvent(event)) {
|
|
599
|
+
const element = elementRef.current;
|
|
600
|
+
if (pendingStartPos && element) {
|
|
601
|
+
const target = getTargetAtPoint(currentPos, event.nativeEvent);
|
|
602
|
+
const doc = ownerDocument(element);
|
|
603
|
+
const body = doc.body;
|
|
604
|
+
const scrollTarget = body ? findGestureScrollableTouchTarget(target, body) : null;
|
|
605
|
+
if (scrollTarget && (contains(element, scrollTarget) || contains(scrollTarget, element))) {
|
|
606
|
+
const deltaX = currentPos.x - pendingStartPos.x;
|
|
607
|
+
const deltaY = currentPos.y - pendingStartPos.y;
|
|
608
|
+
const canSwipeFromEdge = canSwipeFromScrollEdgeOnPendingMove(scrollTarget, deltaX, deltaY);
|
|
609
|
+
if (false === canSwipeFromEdge) return;
|
|
610
|
+
if (true === canSwipeFromEdge) ignoreScrollableOnStart = true;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
const started = startSwipeAtPosition(event, currentPos, {
|
|
615
|
+
ignoreScrollableTarget: ignoreScrollableOnStart,
|
|
616
|
+
ignoreScrollableAncestors: ignoreScrollableOnStart
|
|
617
|
+
});
|
|
618
|
+
if (started) if (pendingStartPos && ignoreScrollableOnStart) {
|
|
619
|
+
clearPendingSwipeStartState();
|
|
620
|
+
dragStartPosRef.current = pendingStartPos;
|
|
621
|
+
swipeCancelBaselineRef.current = pendingStartPos;
|
|
622
|
+
lastMovePosRef.current = pendingStartPos;
|
|
623
|
+
isFirstPointerMoveRef.current = false;
|
|
624
|
+
} else {
|
|
625
|
+
clearPendingSwipeStartState();
|
|
626
|
+
swipeFromScrollableRef.current = false;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
const previousPos = lastMovePosRef.current;
|
|
631
|
+
const movement = null === previousPos ? {
|
|
632
|
+
x: 0,
|
|
633
|
+
y: 0
|
|
634
|
+
} : {
|
|
635
|
+
x: currentPos.x - previousPos.x,
|
|
636
|
+
y: currentPos.y - previousPos.y
|
|
637
|
+
};
|
|
638
|
+
lastMovePosRef.current = currentPos;
|
|
639
|
+
handleMoveCore(event, currentPos, movement);
|
|
640
|
+
if (endAfterMove && !('touches' in event)) handleEnd(event);
|
|
641
|
+
});
|
|
642
|
+
const moveNative = useStableCallback((nativeEvent, currentTarget)=>{
|
|
643
|
+
handleMove({
|
|
644
|
+
touches: nativeEvent.touches,
|
|
645
|
+
currentTarget,
|
|
646
|
+
nativeEvent,
|
|
647
|
+
defaultPrevented: nativeEvent.defaultPrevented,
|
|
648
|
+
timeStamp: nativeEvent.timeStamp
|
|
649
|
+
});
|
|
650
|
+
});
|
|
775
651
|
const getDragStyles = __rspack_external_react.useCallback(()=>{
|
|
776
|
-
const
|
|
777
|
-
const
|
|
778
|
-
|
|
652
|
+
const swiping = isSwipingRef.current;
|
|
653
|
+
const dragOffset = dragOffsetRef.current;
|
|
654
|
+
const initialTransform = initialTransformRef.current;
|
|
655
|
+
const deltaX = dragOffset.x - initialTransform.x;
|
|
656
|
+
const deltaY = dragOffset.y - initialTransform.y;
|
|
657
|
+
if (!swiping && 0 === deltaX && 0 === deltaY && !dragDismissed) return {
|
|
779
658
|
[movementCssVars.x]: '0px',
|
|
780
659
|
[movementCssVars.y]: '0px'
|
|
781
660
|
};
|
|
782
|
-
const deltaX = resolvedDragOffset.x - resolvedInitialTransform.x;
|
|
783
|
-
const deltaY = resolvedDragOffset.y - resolvedInitialTransform.y;
|
|
784
661
|
return {
|
|
785
|
-
transition:
|
|
786
|
-
transform:
|
|
662
|
+
transition: swiping ? 'none' : void 0,
|
|
663
|
+
transform: swiping ? getDragTransform(dragOffset, initialTransform.scale) : void 0,
|
|
787
664
|
[movementCssVars.x]: `${deltaX}px`,
|
|
788
665
|
[movementCssVars.y]: `${deltaY}px`
|
|
789
666
|
};
|
|
790
667
|
}, [
|
|
791
668
|
dragDismissed,
|
|
792
|
-
|
|
793
|
-
initialTransform,
|
|
794
|
-
isSwiping,
|
|
795
|
-
movementCssVars,
|
|
796
|
-
trackDrag
|
|
669
|
+
movementCssVars
|
|
797
670
|
]);
|
|
798
671
|
const getPointerProps = __rspack_external_react.useCallback(()=>{
|
|
799
672
|
if (!enabled) return {};
|
|
@@ -829,8 +702,9 @@ function useSwipeDismiss(options) {
|
|
|
829
702
|
dragDismissed,
|
|
830
703
|
getPointerProps,
|
|
831
704
|
getTouchProps,
|
|
705
|
+
moveNative,
|
|
832
706
|
getDragStyles,
|
|
833
707
|
reset
|
|
834
708
|
};
|
|
835
709
|
}
|
|
836
|
-
export {
|
|
710
|
+
export { getDisplacement, getElementAtPoint, useSwipeDismiss };
|