vevet 4.3.1 → 4.4.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/lib/cjs/components/CustomScrollDragPlugin/index.js +3 -0
- package/lib/cjs/components/CustomScrollDragPlugin/index.js.map +1 -1
- package/lib/cjs/components/DraggerBase/index.js +29 -114
- package/lib/cjs/components/DraggerBase/index.js.map +1 -1
- package/lib/cjs/components/DraggerDirection/index.js +7 -8
- package/lib/cjs/components/DraggerDirection/index.js.map +1 -1
- package/lib/cjs/components/DraggerMove/index.js +81 -62
- package/lib/cjs/components/DraggerMove/index.js.map +1 -1
- package/lib/cjs/components/Marquee/index.js +2 -0
- package/lib/cjs/components/Marquee/index.js.map +1 -1
- package/lib/cjs/components/ScrollBar/Bar/index.js +1 -2
- package/lib/cjs/components/ScrollBar/Bar/index.js.map +1 -1
- package/lib/cjs/components/SlideProgress/index.js +32 -58
- package/lib/cjs/components/SlideProgress/index.js.map +1 -1
- package/lib/cjs/utils/scroll/index.js +0 -1
- package/lib/cjs/utils/scroll/index.js.map +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/components/CustomScrollDragPlugin/index.js +3 -0
- package/lib/esm/components/CustomScrollDragPlugin/index.js.map +1 -1
- package/lib/esm/components/DraggerBase/index.js +29 -105
- package/lib/esm/components/DraggerBase/index.js.map +1 -1
- package/lib/esm/components/DraggerDirection/index.js +7 -8
- package/lib/esm/components/DraggerDirection/index.js.map +1 -1
- package/lib/esm/components/DraggerMove/index.js +81 -62
- package/lib/esm/components/DraggerMove/index.js.map +1 -1
- package/lib/esm/components/Marquee/index.js +2 -0
- package/lib/esm/components/Marquee/index.js.map +1 -1
- package/lib/esm/components/ScrollBar/Bar/index.js +1 -2
- package/lib/esm/components/ScrollBar/Bar/index.js.map +1 -1
- package/lib/esm/components/SlideProgress/index.js +33 -57
- package/lib/esm/components/SlideProgress/index.js.map +1 -1
- package/lib/esm/utils/scroll/index.js +0 -1
- package/lib/esm/utils/scroll/index.js.map +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/types/components/CustomScrollDragPlugin/index.d.ts.map +1 -1
- package/lib/types/components/DraggerBase/index.d.ts +5 -56
- package/lib/types/components/DraggerBase/index.d.ts.map +1 -1
- package/lib/types/components/DraggerBase/types.d.ts +5 -9
- package/lib/types/components/DraggerBase/types.d.ts.map +1 -1
- package/lib/types/components/DraggerDirection/index.d.ts +3 -3
- package/lib/types/components/DraggerDirection/index.d.ts.map +1 -1
- package/lib/types/components/DraggerMove/index.d.ts +27 -22
- package/lib/types/components/DraggerMove/index.d.ts.map +1 -1
- package/lib/types/components/DraggerMove/types.d.ts +7 -10
- package/lib/types/components/DraggerMove/types.d.ts.map +1 -1
- package/lib/types/components/Marquee/index.d.ts.map +1 -1
- package/lib/types/components/ScrollBar/Bar/index.d.ts.map +1 -1
- package/lib/types/components/SlideProgress/index.d.ts +2 -13
- package/lib/types/components/SlideProgress/index.d.ts.map +1 -1
- package/lib/types/components/SlideProgress/types.d.ts +3 -1
- package/lib/types/components/SlideProgress/types.d.ts.map +1 -1
- package/lib/types/utils/scroll/index.d.ts +0 -1
- package/lib/types/utils/scroll/index.d.ts.map +1 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/CustomScrollDragPlugin/index.ts +4 -0
- package/src/components/DraggerBase/index.ts +41 -142
- package/src/components/DraggerBase/types.ts +5 -11
- package/src/components/DraggerDirection/index.ts +12 -11
- package/src/components/DraggerDirection/stories/index.tsx +1 -0
- package/src/components/DraggerMove/index.ts +100 -77
- package/src/components/DraggerMove/stories/index.stories.tsx +3 -1
- package/src/components/DraggerMove/stories/index.tsx +7 -4
- package/src/components/DraggerMove/types.ts +8 -11
- package/src/components/Marquee/index.ts +3 -0
- package/src/components/ScrollBar/Bar/index.ts +0 -3
- package/src/components/SlideProgress/index.ts +40 -78
- package/src/components/SlideProgress/types.ts +3 -1
- package/src/utils/scroll/index.ts +0 -1
- package/src/version.ts +1 -1
- package/lib/cjs/utils/scroll/isPageScrolling.js +0 -73
- package/lib/cjs/utils/scroll/isPageScrolling.js.map +0 -1
- package/lib/esm/utils/scroll/isPageScrolling.js +0 -69
- package/lib/esm/utils/scroll/isPageScrolling.js.map +0 -1
- package/lib/types/utils/scroll/isPageScrolling.d.ts +0 -25
- package/lib/types/utils/scroll/isPageScrolling.d.ts.map +0 -1
- package/src/utils/scroll/isPageScrolling.ts +0 -80
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { addEventListener } from '@/utils/dom/addEventListener';
|
|
2
2
|
import { DraggerBase, NDraggerBase } from '../DraggerBase';
|
|
3
3
|
import { NDraggerMove } from './types';
|
|
4
|
+
import { getApp } from '@/utils/internal/getApp';
|
|
4
5
|
|
|
5
6
|
export type { NDraggerMove };
|
|
6
7
|
|
|
@@ -22,14 +23,20 @@ export class DraggerMove<
|
|
|
22
23
|
protected _getDefaultProps() {
|
|
23
24
|
return {
|
|
24
25
|
...super._getDefaultProps(),
|
|
25
|
-
|
|
26
|
+
threshold: 5,
|
|
26
27
|
};
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
/** Remember scroll values on start */
|
|
31
|
+
protected _startScroll = { top: 0, left: 0 };
|
|
32
|
+
|
|
33
|
+
/** If move callback is being called */
|
|
34
|
+
protected _isMoving = false;
|
|
35
|
+
|
|
29
36
|
/**
|
|
30
37
|
* Returns the difference between the current pointer coordinates and the previous coordinates (the step of movement).
|
|
31
38
|
*/
|
|
32
|
-
get
|
|
39
|
+
get step() {
|
|
33
40
|
return {
|
|
34
41
|
x: this.coords.x - this.prevCoords.x,
|
|
35
42
|
y: this.coords.y - this.prevCoords.y,
|
|
@@ -39,23 +46,23 @@ export class DraggerMove<
|
|
|
39
46
|
/**
|
|
40
47
|
* Returns the difference between the starting coordinates and the current coordinates.
|
|
41
48
|
*/
|
|
42
|
-
get
|
|
49
|
+
get diff() {
|
|
43
50
|
return {
|
|
44
|
-
x: this.coords.x - this.
|
|
45
|
-
y: this.coords.y - this.
|
|
51
|
+
x: this.coords.x - this.start.x,
|
|
52
|
+
y: this.coords.y - this.start.y,
|
|
46
53
|
};
|
|
47
54
|
}
|
|
48
55
|
|
|
49
56
|
/**
|
|
50
|
-
* Stores the absolute
|
|
57
|
+
* Stores the total absolute movement.
|
|
51
58
|
*/
|
|
52
|
-
protected
|
|
59
|
+
protected _total: NDraggerBase.IVector2 = { x: 0, y: 0 };
|
|
53
60
|
|
|
54
61
|
/**
|
|
55
|
-
* Returns the absolute
|
|
62
|
+
* Returns the total absolute movement.
|
|
56
63
|
*/
|
|
57
|
-
get
|
|
58
|
-
return this.
|
|
64
|
+
get total() {
|
|
65
|
+
return this._total;
|
|
59
66
|
}
|
|
60
67
|
|
|
61
68
|
/**
|
|
@@ -65,59 +72,83 @@ export class DraggerMove<
|
|
|
65
72
|
protected _addRuntimeEvents() {
|
|
66
73
|
super._addRuntimeEvents();
|
|
67
74
|
|
|
68
|
-
const { isPassive } = this.props;
|
|
69
|
-
|
|
70
75
|
this._runtimeListeners.push(
|
|
71
76
|
addEventListener(
|
|
72
77
|
window,
|
|
73
|
-
'
|
|
74
|
-
(event) =>
|
|
75
|
-
|
|
76
|
-
this._handleMove(event);
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
passive: isPassive,
|
|
81
|
-
},
|
|
78
|
+
'pointermove',
|
|
79
|
+
(event) => this._handleMove(event),
|
|
80
|
+
{ passive: false },
|
|
82
81
|
),
|
|
83
82
|
);
|
|
83
|
+
}
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
},
|
|
97
|
-
),
|
|
98
|
-
);
|
|
85
|
+
/**
|
|
86
|
+
* Handles the start of a drag event.
|
|
87
|
+
*/
|
|
88
|
+
protected _handleStart(event: PointerEvent) {
|
|
89
|
+
super._handleStart(event);
|
|
90
|
+
|
|
91
|
+
// Remember scroll values on start
|
|
92
|
+
this._startScroll = {
|
|
93
|
+
top: window.scrollY,
|
|
94
|
+
left: window.scrollX,
|
|
95
|
+
};
|
|
99
96
|
}
|
|
100
97
|
|
|
101
98
|
/**
|
|
102
99
|
* Handles the movement during dragging, updating the current coordinates and calculating the step and total movement.
|
|
103
|
-
* Disables pointer events if necessary based on the `disablePointerEventsAt` threshold.
|
|
104
100
|
*
|
|
105
101
|
* @param event - The event representing the movement (either `MouseEvent` or `TouchEvent`).
|
|
106
102
|
*/
|
|
107
|
-
protected _handleMove(event:
|
|
108
|
-
const { x, y
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
103
|
+
protected _handleMove(event: PointerEvent) {
|
|
104
|
+
const { clientX: x, clientY: y } = event;
|
|
105
|
+
const { threshold } = this.props;
|
|
106
|
+
|
|
107
|
+
// get scroll values
|
|
108
|
+
const currentScroll = {
|
|
109
|
+
top: window.scrollY,
|
|
110
|
+
left: window.scrollX,
|
|
111
|
+
};
|
|
112
|
+
const startScroll = this._startScroll;
|
|
113
113
|
|
|
114
114
|
// Update previous and current coordinates
|
|
115
115
|
this.prevCoords = { x: this.coords.x, y: this.coords.y };
|
|
116
116
|
this.coords = { x, y };
|
|
117
117
|
|
|
118
|
-
// Update
|
|
119
|
-
this.
|
|
120
|
-
this.
|
|
118
|
+
// Update total movement
|
|
119
|
+
this._total.x += Math.abs(this.step.x);
|
|
120
|
+
this._total.y += Math.abs(this.step.y);
|
|
121
|
+
|
|
122
|
+
// check trheshold
|
|
123
|
+
if (
|
|
124
|
+
threshold &&
|
|
125
|
+
Math.sqrt(this.total.x ** 2 + this.total.y ** 2) < threshold ** 2
|
|
126
|
+
) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// check if scrolling at the moment
|
|
131
|
+
if (
|
|
132
|
+
getApp().isMobile &&
|
|
133
|
+
(startScroll.top !== currentScroll.top ||
|
|
134
|
+
startScroll.left !== currentScroll.left)
|
|
135
|
+
) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// moving
|
|
140
|
+
if (!this._isMoving) {
|
|
141
|
+
this._isMoving = true;
|
|
142
|
+
|
|
143
|
+
this._start = { x, y };
|
|
144
|
+
this._prevCoords = { x, y };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// prevent defaults
|
|
148
|
+
|
|
149
|
+
if (this.props.preventDefault) {
|
|
150
|
+
event.preventDefault();
|
|
151
|
+
}
|
|
121
152
|
|
|
122
153
|
// Optionally disable pointer events during movement
|
|
123
154
|
this._togglePointerEvents(false);
|
|
@@ -125,58 +156,50 @@ export class DraggerMove<
|
|
|
125
156
|
// Trigger 'move' callback with relevant data
|
|
126
157
|
this.callbacks.tbt('move', {
|
|
127
158
|
event,
|
|
128
|
-
start: this.
|
|
159
|
+
start: this.start,
|
|
129
160
|
coords: this.coords,
|
|
130
|
-
step: this.
|
|
131
|
-
diff: this.
|
|
132
|
-
|
|
161
|
+
step: this.step,
|
|
162
|
+
diff: this.diff,
|
|
163
|
+
total: this.total,
|
|
133
164
|
});
|
|
134
|
-
|
|
135
|
-
return true;
|
|
136
165
|
}
|
|
137
166
|
|
|
138
167
|
/**
|
|
139
|
-
* Handles the end of
|
|
140
|
-
* Re-enables pointer events if they were disabled during movement.
|
|
141
|
-
*
|
|
142
|
-
* @param event - The event representing the end of the drag (either `MouseEvent` or `TouchEvent`).
|
|
168
|
+
* Handles the end of a drag event and initiates cleanup.
|
|
143
169
|
*/
|
|
144
|
-
protected _handleEnd(
|
|
145
|
-
super._handleEnd(
|
|
170
|
+
protected _handleEnd() {
|
|
171
|
+
super._handleEnd(null);
|
|
146
172
|
|
|
147
|
-
// Reset
|
|
148
|
-
this.
|
|
173
|
+
// Reset
|
|
174
|
+
this._total = { x: 0, y: 0 };
|
|
175
|
+
this._isMoving = false;
|
|
149
176
|
|
|
150
177
|
// Re-enable pointer events
|
|
151
178
|
this._togglePointerEvents(true);
|
|
152
179
|
}
|
|
153
180
|
|
|
181
|
+
/** Cancel dragging */
|
|
182
|
+
public cancel() {
|
|
183
|
+
this._handleEnd();
|
|
184
|
+
}
|
|
185
|
+
|
|
154
186
|
/**
|
|
155
|
-
* Toggles pointer events on or off
|
|
187
|
+
* Toggles pointer events on or off.
|
|
156
188
|
*
|
|
157
|
-
* @param
|
|
189
|
+
* @param isEnabled - If true, pointer events will be re-enabled.
|
|
158
190
|
*/
|
|
159
|
-
protected _togglePointerEvents(
|
|
160
|
-
if (typeof this.props.disablePointerEventsAt !== 'number') {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
|
|
191
|
+
protected _togglePointerEvents(isEnabled: boolean) {
|
|
164
192
|
if (!(this.container instanceof HTMLElement)) {
|
|
165
193
|
return;
|
|
166
194
|
}
|
|
167
195
|
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
Math.abs(this.diffCoords.y) < this.props.disablePointerEventsAt) ||
|
|
171
|
-
isEnabledProp;
|
|
196
|
+
const { total } = this;
|
|
197
|
+
const { threshold } = this.props;
|
|
172
198
|
|
|
173
|
-
|
|
174
|
-
}
|
|
199
|
+
const isEnoughToBlockListeners = total.x > threshold || total.y > threshold;
|
|
175
200
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
protected _destroy() {
|
|
180
|
-
super._destroy();
|
|
201
|
+
const isDisabled = isEnabled ? false : isEnoughToBlockListeners;
|
|
202
|
+
|
|
203
|
+
this.container.style.pointerEvents = isDisabled ? 'none' : '';
|
|
181
204
|
}
|
|
182
205
|
}
|
|
@@ -14,8 +14,8 @@ export const Component: FC = () => {
|
|
|
14
14
|
|
|
15
15
|
const instance = new DraggerMove({
|
|
16
16
|
container: thumb,
|
|
17
|
-
disablePointerEventsAt: 5,
|
|
18
17
|
});
|
|
18
|
+
|
|
19
19
|
setDragger(instance);
|
|
20
20
|
|
|
21
21
|
instance.addCallback('move', ({ diff }) => {
|
|
@@ -50,6 +50,7 @@ export const Component: FC = () => {
|
|
|
50
50
|
<div
|
|
51
51
|
style={{
|
|
52
52
|
position: 'relative',
|
|
53
|
+
marginTop: 10,
|
|
53
54
|
width: '300px',
|
|
54
55
|
height: '300px',
|
|
55
56
|
display: 'flex',
|
|
@@ -64,8 +65,8 @@ export const Component: FC = () => {
|
|
|
64
65
|
id="drag-thumb"
|
|
65
66
|
style={{
|
|
66
67
|
position: 'relative',
|
|
67
|
-
width: '
|
|
68
|
-
height: '
|
|
68
|
+
width: '250px',
|
|
69
|
+
height: '250px',
|
|
69
70
|
display: 'flex',
|
|
70
71
|
flexDirection: 'row',
|
|
71
72
|
alignItems: 'center',
|
|
@@ -74,9 +75,11 @@ export const Component: FC = () => {
|
|
|
74
75
|
cursor: 'pointer',
|
|
75
76
|
textAlign: 'center',
|
|
76
77
|
color: '#fff',
|
|
78
|
+
opacity: 0.75,
|
|
79
|
+
touchAction: 'pan-y',
|
|
77
80
|
}}
|
|
78
81
|
>
|
|
79
|
-
<a href="/"
|
|
82
|
+
<a href="/" style={{ color: 'currentcolor' }}>
|
|
80
83
|
Drag me
|
|
81
84
|
</a>
|
|
82
85
|
</div>
|
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import { NDraggerBase } from '../DraggerBase';
|
|
2
2
|
|
|
3
3
|
export namespace NDraggerMove {
|
|
4
|
-
export interface IStaticProps extends NDraggerBase.IStaticProps {
|
|
4
|
+
export interface IStaticProps extends NDraggerBase.IStaticProps {}
|
|
5
|
+
|
|
6
|
+
export interface IChangeableProps extends NDraggerBase.IChangeableProps {
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Set to `false` to leave pointer events unaffected.
|
|
9
|
-
*
|
|
10
|
-
* @default false
|
|
8
|
+
* Threshold value in px. If "touch distance" will be lower than this value then dragger move events will not trigger
|
|
9
|
+
* @default 5
|
|
11
10
|
*/
|
|
12
|
-
|
|
11
|
+
threshold?: number;
|
|
13
12
|
}
|
|
14
13
|
|
|
15
|
-
export interface IChangeableProps extends NDraggerBase.IChangeableProps {}
|
|
16
|
-
|
|
17
14
|
export interface ICallbacksTypes extends NDraggerBase.ICallbacksTypes {
|
|
18
15
|
/**
|
|
19
16
|
* Callback triggered during the drag movement, providing details about the current, step, and difference coordinates.
|
|
@@ -33,8 +30,8 @@ export namespace NDraggerMove {
|
|
|
33
30
|
diff: NDraggerBase.IVector2;
|
|
34
31
|
|
|
35
32
|
/**
|
|
36
|
-
*
|
|
33
|
+
* Total movement
|
|
37
34
|
*/
|
|
38
|
-
|
|
35
|
+
total: NDraggerBase.IVector2;
|
|
39
36
|
}
|
|
40
37
|
}
|
|
@@ -243,12 +243,9 @@ export class Bar {
|
|
|
243
243
|
* @param param - The drag event data.
|
|
244
244
|
*/
|
|
245
245
|
private _handleThumbDrag({
|
|
246
|
-
event,
|
|
247
246
|
coords,
|
|
248
247
|
start,
|
|
249
248
|
}: NDraggerMove.ICallbacksTypes['move']) {
|
|
250
|
-
event.preventDefault();
|
|
251
|
-
|
|
252
249
|
const { scrollLine } = this;
|
|
253
250
|
const { container } = this.props;
|
|
254
251
|
|
|
@@ -2,11 +2,9 @@ import { Component as ComponentClass } from '@/base/Component';
|
|
|
2
2
|
import { NSlideProgress } from './types';
|
|
3
3
|
import { clamp, lerp } from '@/utils/math';
|
|
4
4
|
import { normalizeWheel } from '@/utils/scroll/normalizeWheel';
|
|
5
|
-
import { createIsPageScrolling } from '@/utils/scroll/isPageScrolling';
|
|
6
5
|
import { AnimationFrame } from '../AnimationFrame';
|
|
7
6
|
import { DraggerMove, NDraggerMove } from '../DraggerMove';
|
|
8
7
|
import { Timeline } from '../Timeline';
|
|
9
|
-
import { NDraggerBase } from '../DraggerBase';
|
|
10
8
|
|
|
11
9
|
export type { NSlideProgress };
|
|
12
10
|
|
|
@@ -40,12 +38,12 @@ export class SlideProgress<
|
|
|
40
38
|
hasWheel: true,
|
|
41
39
|
wheelSpeed: 1,
|
|
42
40
|
stickyEndDuration: 500,
|
|
43
|
-
dragThreshold:
|
|
41
|
+
dragThreshold: 5,
|
|
44
42
|
};
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
/** Animation frame for smooth animations */
|
|
48
|
-
protected
|
|
46
|
+
protected _raf: AnimationFrame;
|
|
49
47
|
|
|
50
48
|
/** Dragging behavior manager */
|
|
51
49
|
protected _dragger: DraggerMove;
|
|
@@ -68,14 +66,11 @@ export class SlideProgress<
|
|
|
68
66
|
}
|
|
69
67
|
|
|
70
68
|
/** Timeline for smooth transitions */
|
|
71
|
-
protected
|
|
69
|
+
protected _timeline?: Timeline;
|
|
72
70
|
|
|
73
71
|
/** Timeout for sticky behavior at the end */
|
|
74
72
|
protected _stickyEndTimeout?: NodeJS.Timeout;
|
|
75
73
|
|
|
76
|
-
/** Determines if dragging is allowed */
|
|
77
|
-
protected _canDragMove = false;
|
|
78
|
-
|
|
79
74
|
/** Direction of progress */
|
|
80
75
|
protected _direction: 1 | -1 = 1;
|
|
81
76
|
|
|
@@ -85,34 +80,34 @@ export class SlideProgress<
|
|
|
85
80
|
/** Current handler for user interactions: 'wheel' or 'drag' */
|
|
86
81
|
protected _currentHandler: 'wheel' | 'drag' = 'wheel';
|
|
87
82
|
|
|
88
|
-
/** Checks if the page is scrolling */
|
|
89
|
-
protected _createIsPageScrolling: ReturnType<typeof createIsPageScrolling>;
|
|
90
|
-
|
|
91
83
|
constructor(initialProps?: StaticProps & ChangeableProps, canInit = true) {
|
|
92
84
|
super(initialProps, false);
|
|
93
85
|
|
|
94
|
-
const { container } = this.props;
|
|
86
|
+
const { container, hasDrag, dragDirection, dragThreshold } = this.props;
|
|
95
87
|
|
|
96
88
|
// Create the animation frame
|
|
97
|
-
this.
|
|
98
|
-
this.
|
|
99
|
-
|
|
100
|
-
|
|
89
|
+
this._raf = new AnimationFrame();
|
|
90
|
+
this._raf.addCallback('frame', () => this._handleAnimationFrame());
|
|
91
|
+
|
|
92
|
+
// Create dragger
|
|
93
|
+
this._dragger = new DraggerMove({
|
|
94
|
+
container,
|
|
95
|
+
isEnabled: hasDrag,
|
|
96
|
+
threshold: dragThreshold,
|
|
97
|
+
});
|
|
101
98
|
|
|
102
|
-
// Create the dragger
|
|
103
|
-
this._dragger = new DraggerMove({ container });
|
|
104
99
|
this._dragger.addCallback('move', (event) => this._handleDrag(event));
|
|
105
100
|
this._dragger.addCallback('start', ({ event }) => event.stopPropagation());
|
|
106
101
|
this._dragger.addCallback('end', () => this._handleDragEnd());
|
|
107
102
|
|
|
103
|
+
// Touch Action
|
|
104
|
+
container.style.touchAction = dragDirection === 'x' ? 'pan-y' : 'pan-x';
|
|
105
|
+
|
|
108
106
|
// Add wheel event listener
|
|
109
107
|
this.addEventListener(container, 'wheel', (event) =>
|
|
110
108
|
this._handleWheel(event),
|
|
111
109
|
);
|
|
112
110
|
|
|
113
|
-
// Create page scrolling check
|
|
114
|
-
this._createIsPageScrolling = createIsPageScrolling();
|
|
115
|
-
|
|
116
111
|
// Initialize the class
|
|
117
112
|
if (canInit) {
|
|
118
113
|
this.init();
|
|
@@ -125,7 +120,11 @@ export class SlideProgress<
|
|
|
125
120
|
protected _onPropsMutate() {
|
|
126
121
|
super._onPropsMutate();
|
|
127
122
|
|
|
128
|
-
|
|
123
|
+
const { container, hasDrag, dragThreshold, dragDirection } = this.props;
|
|
124
|
+
|
|
125
|
+
this._dragger.changeProps({ isEnabled: hasDrag, threshold: dragThreshold });
|
|
126
|
+
|
|
127
|
+
container.style.touchAction = dragDirection === 'x' ? 'pan-y' : 'pan-x';
|
|
129
128
|
}
|
|
130
129
|
|
|
131
130
|
/**
|
|
@@ -133,7 +132,7 @@ export class SlideProgress<
|
|
|
133
132
|
* @param event - The wheel event.
|
|
134
133
|
*/
|
|
135
134
|
protected _handleWheel(event: WheelEvent) {
|
|
136
|
-
if (this.
|
|
135
|
+
if (this._timeline || !this.props.hasWheel) {
|
|
137
136
|
return;
|
|
138
137
|
}
|
|
139
138
|
|
|
@@ -159,7 +158,8 @@ export class SlideProgress<
|
|
|
159
158
|
this._direction = this._wheelIntensity > 0 ? 1 : -1;
|
|
160
159
|
progress.target = clamp(progress.target + y, [min, max]);
|
|
161
160
|
|
|
162
|
-
|
|
161
|
+
// play animation
|
|
162
|
+
this._raf.play();
|
|
163
163
|
|
|
164
164
|
// Set timeout for sticky behavior
|
|
165
165
|
this._stickyEndTimeout = setTimeout(() => {
|
|
@@ -171,55 +171,18 @@ export class SlideProgress<
|
|
|
171
171
|
this.callbacks.tbt('wheel', wheel);
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
/**
|
|
175
|
-
* Checks if dragging is allowed.
|
|
176
|
-
* @param absDiff - Absolute difference in dragging distance.
|
|
177
|
-
*/
|
|
178
|
-
protected _checkCanDragMove(absDiff: NDraggerBase.IVector2) {
|
|
179
|
-
const { dragDirection, dragThreshold } = this.props;
|
|
180
|
-
|
|
181
|
-
if (this._canDragMove) {
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (absDiff.x < dragThreshold && absDiff.y < dragThreshold) {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (dragDirection === 'x' && absDiff.x > absDiff.y) {
|
|
190
|
-
this._canDragMove = true;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (dragDirection === 'y' && absDiff.y > absDiff.x) {
|
|
194
|
-
this._canDragMove = true;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
174
|
/**
|
|
201
175
|
* Handles the drag movement for adjusting progress.
|
|
202
176
|
* @param data - The drag event data.
|
|
203
177
|
*/
|
|
204
178
|
protected _handleDrag(data: NDraggerMove.IMoveParameter) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (this._timelineTo || !this.props.hasDrag || isPageScrolling) {
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (!this._checkCanDragMove(data.absDiff)) {
|
|
179
|
+
if (this._timeline) {
|
|
212
180
|
return;
|
|
213
181
|
}
|
|
214
182
|
|
|
215
183
|
const { _progressLerp: progress, props } = this;
|
|
216
184
|
const { container, dragSpeed, dragDirection, min, max } = props;
|
|
217
|
-
const {
|
|
218
|
-
|
|
219
|
-
if (event.cancelable) {
|
|
220
|
-
event.preventDefault();
|
|
221
|
-
}
|
|
222
|
-
event.stopPropagation();
|
|
185
|
+
const { step, diff } = data;
|
|
223
186
|
|
|
224
187
|
// Update handler
|
|
225
188
|
this._currentHandler = 'drag';
|
|
@@ -235,7 +198,7 @@ export class SlideProgress<
|
|
|
235
198
|
const dragDiff = dragDirection === 'y' ? diff.y : diff.x;
|
|
236
199
|
this._direction = dragDiff < 0 ? 1 : -1;
|
|
237
200
|
|
|
238
|
-
this.
|
|
201
|
+
this._raf.play();
|
|
239
202
|
|
|
240
203
|
// Callbacks
|
|
241
204
|
this.callbacks.tbt('dragMove', data);
|
|
@@ -245,9 +208,10 @@ export class SlideProgress<
|
|
|
245
208
|
* Handles the end of a drag event and triggers sticky behavior.
|
|
246
209
|
*/
|
|
247
210
|
private _handleDragEnd() {
|
|
248
|
-
this._canDragMove = false;
|
|
249
|
-
|
|
250
211
|
this._goStickyEnd();
|
|
212
|
+
|
|
213
|
+
// Callbacks
|
|
214
|
+
this.callbacks.tbt('dragEnd', undefined);
|
|
251
215
|
}
|
|
252
216
|
|
|
253
217
|
/**
|
|
@@ -285,11 +249,11 @@ export class SlideProgress<
|
|
|
285
249
|
protected _handleAnimationFrame() {
|
|
286
250
|
const { _progressLerp: progress } = this;
|
|
287
251
|
const { ease, friction, step } = this.props;
|
|
288
|
-
const { fpsMultiplier } = this.
|
|
252
|
+
const { fpsMultiplier } = this._raf;
|
|
289
253
|
|
|
290
254
|
const nearestSteppedProgress = this._getNearestStep(progress.target);
|
|
291
255
|
|
|
292
|
-
if (!this.
|
|
256
|
+
if (!this._timeline) {
|
|
293
257
|
progress.target = lerp(
|
|
294
258
|
progress.target,
|
|
295
259
|
nearestSteppedProgress,
|
|
@@ -303,7 +267,7 @@ export class SlideProgress<
|
|
|
303
267
|
progress.current === progress.target &&
|
|
304
268
|
progress.current % step === 0
|
|
305
269
|
) {
|
|
306
|
-
this.
|
|
270
|
+
this._raf.pause();
|
|
307
271
|
}
|
|
308
272
|
}
|
|
309
273
|
|
|
@@ -370,7 +334,7 @@ export class SlideProgress<
|
|
|
370
334
|
onProgress,
|
|
371
335
|
onEnd,
|
|
372
336
|
}: NSlideProgress.IToProps) {
|
|
373
|
-
this.
|
|
337
|
+
this._timeline?.destroy();
|
|
374
338
|
|
|
375
339
|
const startValue = this._progressLerp.current;
|
|
376
340
|
const diff = Math.abs(startValue - endValue);
|
|
@@ -384,7 +348,7 @@ export class SlideProgress<
|
|
|
384
348
|
);
|
|
385
349
|
|
|
386
350
|
const timeline = new Timeline({ duration });
|
|
387
|
-
this.
|
|
351
|
+
this._timeline = timeline;
|
|
388
352
|
|
|
389
353
|
timeline.addCallback('progress', (data) => {
|
|
390
354
|
this._progressLerp.target = lerp(startValue, endValue, data.e, 0);
|
|
@@ -394,15 +358,15 @@ export class SlideProgress<
|
|
|
394
358
|
});
|
|
395
359
|
|
|
396
360
|
timeline.addCallback('end', () => {
|
|
397
|
-
this.
|
|
398
|
-
this.
|
|
361
|
+
this._timeline?.destroy();
|
|
362
|
+
this._timeline = undefined;
|
|
399
363
|
|
|
400
364
|
onEnd?.();
|
|
401
365
|
});
|
|
402
366
|
|
|
403
367
|
timeline.play();
|
|
404
368
|
|
|
405
|
-
this.
|
|
369
|
+
this._raf.play();
|
|
406
370
|
}
|
|
407
371
|
|
|
408
372
|
/**
|
|
@@ -411,12 +375,10 @@ export class SlideProgress<
|
|
|
411
375
|
protected _destroy() {
|
|
412
376
|
super._destroy();
|
|
413
377
|
|
|
414
|
-
this.
|
|
415
|
-
|
|
416
|
-
this._animationFrame.destroy();
|
|
378
|
+
this._raf.destroy();
|
|
417
379
|
this._dragger.destroy();
|
|
418
380
|
|
|
419
|
-
this.
|
|
381
|
+
this._timeline?.destroy();
|
|
420
382
|
|
|
421
383
|
if (this._stickyEndTimeout) {
|
|
422
384
|
clearTimeout(this._stickyEndTimeout);
|
|
@@ -63,7 +63,7 @@ export namespace NSlideProgress {
|
|
|
63
63
|
stickyEndDuration?: TDuration | null;
|
|
64
64
|
/**
|
|
65
65
|
* Minimum threshold for drag movements (in pixels).
|
|
66
|
-
* @default
|
|
66
|
+
* @default 5
|
|
67
67
|
*/
|
|
68
68
|
dragThreshold?: number;
|
|
69
69
|
}
|
|
@@ -77,6 +77,8 @@ export namespace NSlideProgress {
|
|
|
77
77
|
wheel: TNormalizeWheel;
|
|
78
78
|
/** Fired when a drag event moves the slider */
|
|
79
79
|
dragMove: NDraggerMove.IMoveParameter;
|
|
80
|
+
/** Fired when dragging ends */
|
|
81
|
+
dragEnd: undefined;
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
export interface IWithLerp {
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const version = '4.
|
|
1
|
+
const version = '4.4.0';
|
|
2
2
|
export default version;
|