mtrl-addons 0.2.1 → 0.2.3
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/{src/components/index.ts → dist/components/index.d.ts} +0 -2
- package/dist/components/vlist/config.d.ts +86 -0
- package/{src/components/vlist/constants.ts → dist/components/vlist/constants.d.ts} +10 -11
- package/dist/components/vlist/features/api.d.ts +7 -0
- package/{src/components/vlist/features/index.ts → dist/components/vlist/features/index.d.ts} +0 -2
- package/dist/components/vlist/features/selection.d.ts +6 -0
- package/dist/components/vlist/features/viewport.d.ts +9 -0
- package/dist/components/vlist/features.d.ts +31 -0
- package/{src/components/vlist/index.ts → dist/components/vlist/index.d.ts} +1 -9
- package/dist/components/vlist/types.d.ts +596 -0
- package/dist/components/vlist/vlist.d.ts +29 -0
- package/dist/core/compose/features/gestures/index.d.ts +86 -0
- package/dist/core/compose/features/gestures/longpress.d.ts +85 -0
- package/dist/core/compose/features/gestures/pan.d.ts +108 -0
- package/dist/core/compose/features/gestures/pinch.d.ts +111 -0
- package/dist/core/compose/features/gestures/rotate.d.ts +111 -0
- package/dist/core/compose/features/gestures/swipe.d.ts +149 -0
- package/dist/core/compose/features/gestures/tap.d.ts +79 -0
- package/{src/core/compose/features/index.ts → dist/core/compose/features/index.d.ts} +1 -2
- package/{src/core/compose/index.ts → dist/core/compose/index.d.ts} +2 -11
- package/{src/core/gestures/index.ts → dist/core/gestures/index.d.ts} +1 -20
- package/dist/core/gestures/longpress.d.ts +23 -0
- package/dist/core/gestures/manager.d.ts +14 -0
- package/dist/core/gestures/pan.d.ts +12 -0
- package/dist/core/gestures/pinch.d.ts +14 -0
- package/dist/core/gestures/rotate.d.ts +14 -0
- package/dist/core/gestures/swipe.d.ts +20 -0
- package/dist/core/gestures/tap.d.ts +12 -0
- package/dist/core/gestures/types.d.ts +320 -0
- package/dist/core/gestures/utils.d.ts +57 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/layout/config.d.ts +33 -0
- package/dist/core/layout/index.d.ts +51 -0
- package/dist/core/layout/jsx.d.ts +65 -0
- package/dist/core/layout/schema.d.ts +112 -0
- package/dist/core/layout/types.d.ts +69 -0
- package/dist/core/viewport/constants.d.ts +105 -0
- package/dist/core/viewport/features/base.d.ts +14 -0
- package/dist/core/viewport/features/collection.d.ts +41 -0
- package/dist/core/viewport/features/events.d.ts +13 -0
- package/{src/core/viewport/features/index.ts → dist/core/viewport/features/index.d.ts} +0 -7
- package/dist/core/viewport/features/item-size.d.ts +30 -0
- package/dist/core/viewport/features/loading.d.ts +34 -0
- package/dist/core/viewport/features/momentum.d.ts +17 -0
- package/dist/core/viewport/features/performance.d.ts +53 -0
- package/dist/core/viewport/features/placeholders.d.ts +38 -0
- package/dist/core/viewport/features/rendering.d.ts +16 -0
- package/dist/core/viewport/features/scrollbar.d.ts +26 -0
- package/dist/core/viewport/features/scrolling.d.ts +16 -0
- package/dist/core/viewport/features/utils.d.ts +43 -0
- package/dist/core/viewport/features/virtual.d.ts +18 -0
- package/{src/core/viewport/index.ts → dist/core/viewport/index.d.ts} +1 -17
- package/dist/core/viewport/types.d.ts +96 -0
- package/dist/core/viewport/utils/speed-tracker.d.ts +22 -0
- package/dist/core/viewport/viewport.d.ts +11 -0
- package/{src/index.ts → dist/index.d.ts} +0 -4
- package/dist/index.js +5143 -0
- package/dist/index.mjs +5111 -0
- package/dist/styles.css +254 -0
- package/dist/styles.css.map +1 -0
- package/package.json +6 -1
- package/src/styles/components/_vlist.scss +234 -213
- package/.cursorrules +0 -117
- package/AI.md +0 -241
- package/build.js +0 -201
- package/scripts/analyze-orphaned-functions.ts +0 -387
- package/scripts/debug/vlist-selection.ts +0 -121
- package/src/components/vlist/config.ts +0 -323
- package/src/components/vlist/features/api.ts +0 -322
- package/src/components/vlist/features/selection.ts +0 -444
- package/src/components/vlist/features/viewport.ts +0 -65
- package/src/components/vlist/features.ts +0 -112
- package/src/components/vlist/types.ts +0 -591
- package/src/components/vlist/vlist.ts +0 -92
- package/src/core/compose/features/gestures/index.ts +0 -227
- package/src/core/compose/features/gestures/longpress.ts +0 -383
- package/src/core/compose/features/gestures/pan.ts +0 -424
- package/src/core/compose/features/gestures/pinch.ts +0 -475
- package/src/core/compose/features/gestures/rotate.ts +0 -485
- package/src/core/compose/features/gestures/swipe.ts +0 -492
- package/src/core/compose/features/gestures/tap.ts +0 -334
- package/src/core/gestures/longpress.ts +0 -68
- package/src/core/gestures/manager.ts +0 -418
- package/src/core/gestures/pan.ts +0 -48
- package/src/core/gestures/pinch.ts +0 -58
- package/src/core/gestures/rotate.ts +0 -58
- package/src/core/gestures/swipe.ts +0 -66
- package/src/core/gestures/tap.ts +0 -45
- package/src/core/gestures/types.ts +0 -387
- package/src/core/gestures/utils.ts +0 -128
- package/src/core/index.ts +0 -43
- package/src/core/layout/config.ts +0 -102
- package/src/core/layout/index.ts +0 -168
- package/src/core/layout/jsx.ts +0 -174
- package/src/core/layout/schema.ts +0 -1001
- package/src/core/layout/types.ts +0 -95
- package/src/core/viewport/constants.ts +0 -140
- package/src/core/viewport/features/base.ts +0 -73
- package/src/core/viewport/features/collection.ts +0 -882
- package/src/core/viewport/features/events.ts +0 -130
- package/src/core/viewport/features/item-size.ts +0 -271
- package/src/core/viewport/features/loading.ts +0 -263
- package/src/core/viewport/features/momentum.ts +0 -260
- package/src/core/viewport/features/performance.ts +0 -161
- package/src/core/viewport/features/placeholders.ts +0 -335
- package/src/core/viewport/features/rendering.ts +0 -568
- package/src/core/viewport/features/scrollbar.ts +0 -434
- package/src/core/viewport/features/scrolling.ts +0 -618
- package/src/core/viewport/features/utils.ts +0 -88
- package/src/core/viewport/features/virtual.ts +0 -384
- package/src/core/viewport/types.ts +0 -133
- package/src/core/viewport/utils/speed-tracker.ts +0 -79
- package/src/core/viewport/viewport.ts +0 -246
- package/test/benchmarks/layout/advanced.test.ts +0 -656
- package/test/benchmarks/layout/comparison.test.ts +0 -519
- package/test/benchmarks/layout/performance-comparison.test.ts +0 -274
- package/test/benchmarks/layout/real-components.test.ts +0 -733
- package/test/benchmarks/layout/simple.test.ts +0 -321
- package/test/benchmarks/layout/stress.test.ts +0 -990
- package/test/collection/basic.test.ts +0 -304
- package/test/components/vlist-selection.test.ts +0 -240
- package/test/components/vlist.test.ts +0 -63
- package/test/core/collection/adapter.test.ts +0 -161
- package/test/core/collection/collection.test.ts +0 -394
- package/test/core/layout/layout.test.ts +0 -201
- package/test/utils/dom-helpers.ts +0 -275
- package/test/utils/performance-helpers.ts +0 -392
- package/tsconfig.json +0 -20
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
// src/core/compose/features/gestures/tap.ts
|
|
2
|
-
/**
|
|
3
|
-
* @module core/compose/features/gestures
|
|
4
|
-
* @description Adds tap gesture recognition to components
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { BaseComponent, ElementComponent } from "mtrl";
|
|
8
|
-
import { TapEvent, GestureHandler } from "../../../gestures";
|
|
9
|
-
import { hasLifecycle, hasEmit } from "mtrl";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Configuration for tap gesture feature
|
|
13
|
-
*/
|
|
14
|
-
export interface TapGestureConfig {
|
|
15
|
-
/**
|
|
16
|
-
* Distance threshold (in pixels) for tap recognition
|
|
17
|
-
* @default 10
|
|
18
|
-
*/
|
|
19
|
-
tapDistanceThreshold?: number;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Whether to prevent default behaviors on touch events
|
|
23
|
-
* @default true
|
|
24
|
-
*/
|
|
25
|
-
preventDefault?: boolean;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Handler for tap gesture
|
|
29
|
-
*/
|
|
30
|
-
onTap?: GestureHandler;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Whether to enable tap recognition immediately
|
|
34
|
-
* @default true
|
|
35
|
-
*/
|
|
36
|
-
enabled?: boolean;
|
|
37
|
-
|
|
38
|
-
[key: string]: any;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Component with tap gesture recognition capabilities
|
|
43
|
-
*/
|
|
44
|
-
export interface TapGestureComponent extends BaseComponent {
|
|
45
|
-
/**
|
|
46
|
-
* Add a tap event handler
|
|
47
|
-
* @param handler - Event handler function
|
|
48
|
-
* @returns Component for chaining
|
|
49
|
-
*/
|
|
50
|
-
onTap: (handler: (event: TapEvent) => void) => TapGestureComponent;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Remove a tap event handler
|
|
54
|
-
* @param handler - Event handler function
|
|
55
|
-
* @returns Component for chaining
|
|
56
|
-
*/
|
|
57
|
-
offTap: (handler: (event: TapEvent) => void) => TapGestureComponent;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Enable tap recognition
|
|
61
|
-
* @returns Component for chaining
|
|
62
|
-
*/
|
|
63
|
-
enableTap: () => TapGestureComponent;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Disable tap recognition
|
|
67
|
-
* @returns Component for chaining
|
|
68
|
-
*/
|
|
69
|
-
disableTap: () => TapGestureComponent;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Adds tap gesture recognition to a component.
|
|
74
|
-
* This is a lightweight alternative to the full gesture system,
|
|
75
|
-
* focused only on tap detection.
|
|
76
|
-
*
|
|
77
|
-
* @param config - Configuration object containing tap settings
|
|
78
|
-
* @returns Function that enhances a component with tap capabilities
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```ts
|
|
82
|
-
* // Add tap gesture recognition to a component
|
|
83
|
-
* const component = pipe(
|
|
84
|
-
* createBase,
|
|
85
|
-
* withElement(...),
|
|
86
|
-
* withTapGesture({
|
|
87
|
-
* onTap: (e) => console.log('Tapped at', e.x, e.y)
|
|
88
|
-
* })
|
|
89
|
-
* )(config);
|
|
90
|
-
* ```
|
|
91
|
-
*/
|
|
92
|
-
export const withTapGesture =
|
|
93
|
-
(config: TapGestureConfig = {}) =>
|
|
94
|
-
<C extends ElementComponent>(component: C): C & TapGestureComponent => {
|
|
95
|
-
if (!component.element) {
|
|
96
|
-
console.warn("Cannot add tap gesture recognition: missing element");
|
|
97
|
-
return component as C & TapGestureComponent;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Default configuration
|
|
101
|
-
const {
|
|
102
|
-
tapDistanceThreshold = 10,
|
|
103
|
-
preventDefault = true,
|
|
104
|
-
onTap,
|
|
105
|
-
enabled = true,
|
|
106
|
-
} = config;
|
|
107
|
-
|
|
108
|
-
// Event handlers storage
|
|
109
|
-
const handlers: Set<(event: TapEvent) => void> = new Set();
|
|
110
|
-
|
|
111
|
-
// If initial handler provided, add it
|
|
112
|
-
if (onTap) {
|
|
113
|
-
handlers.add(onTap as (event: TapEvent) => void);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Gesture state for tracking
|
|
117
|
-
let startX = 0;
|
|
118
|
-
let startY = 0;
|
|
119
|
-
let active = false;
|
|
120
|
-
let startTime = 0;
|
|
121
|
-
let lastTapTime = 0;
|
|
122
|
-
let tapCount = 0;
|
|
123
|
-
let isEnabled = enabled;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Dispatch a tap event to all handlers
|
|
127
|
-
*/
|
|
128
|
-
const dispatchTap = (
|
|
129
|
-
e: MouseEvent | TouchEvent,
|
|
130
|
-
x: number,
|
|
131
|
-
y: number
|
|
132
|
-
): void => {
|
|
133
|
-
const now = Date.now();
|
|
134
|
-
const isDoubleTap = now - lastTapTime < 300;
|
|
135
|
-
|
|
136
|
-
if (isDoubleTap) {
|
|
137
|
-
tapCount++;
|
|
138
|
-
} else {
|
|
139
|
-
tapCount = 1;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
lastTapTime = now;
|
|
143
|
-
|
|
144
|
-
// Create the tap event
|
|
145
|
-
const tapEvent: TapEvent = {
|
|
146
|
-
type: "tap",
|
|
147
|
-
originalEvent: e,
|
|
148
|
-
target: e.target!,
|
|
149
|
-
startTime,
|
|
150
|
-
endTime: now,
|
|
151
|
-
duration: now - startTime,
|
|
152
|
-
defaultPrevented: false,
|
|
153
|
-
preventDefault: () => {
|
|
154
|
-
tapEvent.defaultPrevented = true;
|
|
155
|
-
if (e.cancelable) {
|
|
156
|
-
e.preventDefault();
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
stopPropagation: () => {
|
|
160
|
-
e.stopPropagation();
|
|
161
|
-
},
|
|
162
|
-
count: tapCount,
|
|
163
|
-
x,
|
|
164
|
-
y,
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
// Call each handler
|
|
168
|
-
handlers.forEach((handler) => {
|
|
169
|
-
try {
|
|
170
|
-
handler(tapEvent);
|
|
171
|
-
} catch (error) {
|
|
172
|
-
console.error("Error in tap handler:", error);
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
// Forward to component's event system if available
|
|
177
|
-
if (hasEmit(component)) {
|
|
178
|
-
component.emit("tap", tapEvent);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Apply preventDefault if configured
|
|
182
|
-
if (preventDefault && !tapEvent.defaultPrevented) {
|
|
183
|
-
tapEvent.preventDefault();
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Handle touch/mouse start
|
|
189
|
-
*/
|
|
190
|
-
const handleStart = (e: MouseEvent | TouchEvent): void => {
|
|
191
|
-
if (!isEnabled) return;
|
|
192
|
-
|
|
193
|
-
const touch = "touches" in e ? e.touches[0] : e;
|
|
194
|
-
|
|
195
|
-
startX = touch.clientX;
|
|
196
|
-
startY = touch.clientY;
|
|
197
|
-
startTime = Date.now();
|
|
198
|
-
active = true;
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Handle touch/mouse end
|
|
203
|
-
*/
|
|
204
|
-
const handleEnd = (e: MouseEvent | TouchEvent): void => {
|
|
205
|
-
if (!active || !isEnabled) return;
|
|
206
|
-
|
|
207
|
-
const touch =
|
|
208
|
-
"changedTouches" in e && e.changedTouches.length > 0
|
|
209
|
-
? e.changedTouches[0]
|
|
210
|
-
: (e as MouseEvent);
|
|
211
|
-
|
|
212
|
-
const endX = touch.clientX;
|
|
213
|
-
const endY = touch.clientY;
|
|
214
|
-
|
|
215
|
-
// Calculate distance moved
|
|
216
|
-
const deltaX = endX - startX;
|
|
217
|
-
const deltaY = endY - startY;
|
|
218
|
-
const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
|
219
|
-
|
|
220
|
-
// Check if movement is within threshold
|
|
221
|
-
if (distance < tapDistanceThreshold) {
|
|
222
|
-
dispatchTap(e, endX, endY);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
active = false;
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Handle touch/mouse cancel
|
|
230
|
-
*/
|
|
231
|
-
const handleCancel = (): void => {
|
|
232
|
-
active = false;
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
// Event listeners dictionary
|
|
236
|
-
const eventListeners: Record<string, EventListener> = {
|
|
237
|
-
mousedown: handleStart as EventListener,
|
|
238
|
-
mouseup: handleEnd as EventListener,
|
|
239
|
-
mouseleave: handleCancel as EventListener,
|
|
240
|
-
touchstart: handleStart as EventListener,
|
|
241
|
-
touchend: handleEnd as EventListener,
|
|
242
|
-
touchcancel: handleCancel as EventListener,
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Add event listeners to element
|
|
247
|
-
*/
|
|
248
|
-
const setupEventListeners = (): void => {
|
|
249
|
-
Object.entries(eventListeners).forEach(([event, listener]) => {
|
|
250
|
-
component.element.addEventListener(event, listener, {
|
|
251
|
-
passive: !preventDefault,
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Remove event listeners from element
|
|
258
|
-
*/
|
|
259
|
-
const removeEventListeners = (): void => {
|
|
260
|
-
Object.entries(eventListeners).forEach(([event, listener]) => {
|
|
261
|
-
component.element.removeEventListener(event, listener);
|
|
262
|
-
});
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
// Setup listeners if initially enabled
|
|
266
|
-
if (isEnabled) {
|
|
267
|
-
setupEventListeners();
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// Handle lifecycle integration
|
|
271
|
-
if (hasLifecycle(component)) {
|
|
272
|
-
const originalDestroy = component.lifecycle.destroy;
|
|
273
|
-
|
|
274
|
-
component.lifecycle.destroy = () => {
|
|
275
|
-
// Clean up event listeners
|
|
276
|
-
removeEventListeners();
|
|
277
|
-
|
|
278
|
-
// Clear handlers
|
|
279
|
-
handlers.clear();
|
|
280
|
-
|
|
281
|
-
// Call original destroy method
|
|
282
|
-
originalDestroy.call(component.lifecycle);
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// Create enhanced component
|
|
287
|
-
return {
|
|
288
|
-
...component,
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Add a tap event handler
|
|
292
|
-
* @param handler - Event handler function
|
|
293
|
-
* @returns Component for chaining
|
|
294
|
-
*/
|
|
295
|
-
onTap(handler: (event: TapEvent) => void) {
|
|
296
|
-
handlers.add(handler);
|
|
297
|
-
return this;
|
|
298
|
-
},
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Remove a tap event handler
|
|
302
|
-
* @param handler - Event handler function
|
|
303
|
-
* @returns Component for chaining
|
|
304
|
-
*/
|
|
305
|
-
offTap(handler: (event: TapEvent) => void) {
|
|
306
|
-
handlers.delete(handler);
|
|
307
|
-
return this;
|
|
308
|
-
},
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Enable tap recognition
|
|
312
|
-
* @returns Component for chaining
|
|
313
|
-
*/
|
|
314
|
-
enableTap() {
|
|
315
|
-
if (!isEnabled) {
|
|
316
|
-
isEnabled = true;
|
|
317
|
-
setupEventListeners();
|
|
318
|
-
}
|
|
319
|
-
return this;
|
|
320
|
-
},
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Disable tap recognition
|
|
324
|
-
* @returns Component for chaining
|
|
325
|
-
*/
|
|
326
|
-
disableTap() {
|
|
327
|
-
if (isEnabled) {
|
|
328
|
-
isEnabled = false;
|
|
329
|
-
removeEventListeners();
|
|
330
|
-
}
|
|
331
|
-
return this;
|
|
332
|
-
},
|
|
333
|
-
};
|
|
334
|
-
};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
// src/core/gestures/longpress.ts
|
|
2
|
-
/**
|
|
3
|
-
* @module core/gestures
|
|
4
|
-
* @description Long press gesture detection
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { LongPressEvent, GestureDetectionContext } from './types';
|
|
8
|
-
import { createGestureEvent } from './utils';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Detect long press gesture
|
|
12
|
-
*
|
|
13
|
-
* This is slightly different from other gesture detectors as it sets up a timer
|
|
14
|
-
* and returns a callback function that will be triggered when the timer completes.
|
|
15
|
-
*
|
|
16
|
-
* @param context - Gesture detection context
|
|
17
|
-
* @param callback - Function to call when long press is detected
|
|
18
|
-
* @returns Cleanup function to cancel the long press detection
|
|
19
|
-
*/
|
|
20
|
-
export function detectLongPress(
|
|
21
|
-
context: GestureDetectionContext,
|
|
22
|
-
callback: (event: LongPressEvent) => void
|
|
23
|
-
): () => void {
|
|
24
|
-
const { state, options, originalEvent } = context;
|
|
25
|
-
|
|
26
|
-
// Set a timer for long press detection
|
|
27
|
-
const timer = window.setTimeout(() => {
|
|
28
|
-
// Only trigger if gesture is still active
|
|
29
|
-
if (state.active) {
|
|
30
|
-
// Check if movement is within threshold
|
|
31
|
-
const diffX = Math.abs(state.currentX - state.startX);
|
|
32
|
-
const diffY = Math.abs(state.currentY - state.startY);
|
|
33
|
-
|
|
34
|
-
if (diffX < options.tapDistanceThreshold && diffY < options.tapDistanceThreshold) {
|
|
35
|
-
// Create long press event
|
|
36
|
-
const longPressEvent: LongPressEvent = {
|
|
37
|
-
...createGestureEvent('longpress', originalEvent, state),
|
|
38
|
-
type: 'longpress',
|
|
39
|
-
x: state.currentX,
|
|
40
|
-
y: state.currentY
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// Trigger callback
|
|
44
|
-
callback(longPressEvent);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}, options.longPressTime);
|
|
48
|
-
|
|
49
|
-
// Return cleanup function
|
|
50
|
-
return () => {
|
|
51
|
-
clearTimeout(timer);
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Check if movement would cancel a long press
|
|
57
|
-
*
|
|
58
|
-
* @param context - Gesture detection context
|
|
59
|
-
* @returns Whether the long press should be canceled
|
|
60
|
-
*/
|
|
61
|
-
export function shouldCancelLongPress(context: GestureDetectionContext): boolean {
|
|
62
|
-
const { state, options } = context;
|
|
63
|
-
|
|
64
|
-
const diffX = Math.abs(state.currentX - state.startX);
|
|
65
|
-
const diffY = Math.abs(state.currentY - state.startY);
|
|
66
|
-
|
|
67
|
-
return diffX > options.tapDistanceThreshold || diffY > options.tapDistanceThreshold;
|
|
68
|
-
}
|