@graphcommerce/framer-scroller 7.0.0-canary.21 → 7.0.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/CHANGELOG.md +202 -2
- package/components/ScrollerBar.tsx +1 -0
- package/components/ScrollerDot.tsx +1 -0
- package/components/ScrollerDots.tsx +1 -0
- package/components/ScrollerProvider.tsx +45 -31
- package/hooks/useScrollTo.ts +21 -7
- package/hooks/useScroller.ts +12 -16
- package/hooks/useVelocitySnapTo.ts +1 -1
- package/package.json +8 -8
- package/types.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,208 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
## 7.0.0
|
|
3
|
+
## 7.0.0
|
|
4
4
|
|
|
5
|
-
###
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#1996](https://github.com/graphcommerce-org/graphcommerce/pull/1996) [`3ed66a849`](https://github.com/graphcommerce-org/graphcommerce/commit/3ed66a849430d6ad1c46d20828eb988283da0c4a) - SidebarGallery now has a disableZoom prop to disable all zoom functionality ([@Jessevdpoel](https://github.com/Jessevdpoel))
|
|
8
|
+
|
|
9
|
+
- [#1937](https://github.com/graphcommerce-org/graphcommerce/pull/1937) [`a98e23e3a`](https://github.com/graphcommerce-org/graphcommerce/commit/a98e23e3a250157b9d3756b656f1a4c3c52b0ec0) - Assign correct scroll-snap-type type, to prevent error on firefox ([@mikekeehnen](https://github.com/mikekeehnen))
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#1993](https://github.com/graphcommerce-org/graphcommerce/pull/1993) [`f9bd75108`](https://github.com/graphcommerce-org/graphcommerce/commit/f9bd75108ecef583ecd32e701c10d70537cb8a89) - Scrollers would not working properly in Firefox, it would drag elements instead of the scroller. ([@Jessevdpoel](https://github.com/Jessevdpoel))
|
|
14
|
+
|
|
15
|
+
- [#2031](https://github.com/graphcommerce-org/graphcommerce/pull/2031) [`4d8fc9e99`](https://github.com/graphcommerce-org/graphcommerce/commit/4d8fc9e998fc9361282833316ec9564da0644ed6) - Eslint fixes and suppress accepted warnings ([@paales](https://github.com/paales))
|
|
16
|
+
|
|
17
|
+
- [#1954](https://github.com/graphcommerce-org/graphcommerce/pull/1954) [`ec82fe49c`](https://github.com/graphcommerce-org/graphcommerce/commit/ec82fe49cd9aa0865b6c21eb405f05d8596748f6) - Prevent overlays from auto-closing on iOS 14 ([@FrankHarland](https://github.com/FrankHarland))
|
|
18
|
+
|
|
19
|
+
- [#1998](https://github.com/graphcommerce-org/graphcommerce/pull/1998) [`a788baaeb`](https://github.com/graphcommerce-org/graphcommerce/commit/a788baaeb9646c5a30b55998697d38a6093b6c44) - Added option to useScrollTo to allow/disallow stopping the scroll animation on user scroll interaction ([@bramvanderholst](https://github.com/bramvanderholst))
|
|
20
|
+
|
|
21
|
+
## 6.2.0-canary.98
|
|
22
|
+
|
|
23
|
+
## 6.2.0-canary.97
|
|
24
|
+
|
|
25
|
+
## 6.2.0-canary.96
|
|
26
|
+
|
|
27
|
+
## 6.2.0-canary.95
|
|
28
|
+
|
|
29
|
+
## 6.2.0-canary.94
|
|
30
|
+
|
|
31
|
+
## 6.2.0-canary.93
|
|
32
|
+
|
|
33
|
+
## 6.2.0-canary.92
|
|
34
|
+
|
|
35
|
+
## 6.2.0-canary.91
|
|
36
|
+
|
|
37
|
+
## 6.2.0-canary.90
|
|
38
|
+
|
|
39
|
+
## 6.2.0-canary.89
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- [#2031](https://github.com/graphcommerce-org/graphcommerce/pull/2031) [`4d8fc9e99`](https://github.com/graphcommerce-org/graphcommerce/commit/4d8fc9e998fc9361282833316ec9564da0644ed6) - Eslint fixes and suppress accepted warnings ([@paales](https://github.com/paales))
|
|
44
|
+
|
|
45
|
+
## 6.2.0-canary.88
|
|
46
|
+
|
|
47
|
+
## 6.2.0-canary.87
|
|
48
|
+
|
|
49
|
+
## 6.2.0-canary.86
|
|
50
|
+
|
|
51
|
+
## 6.2.0-canary.85
|
|
52
|
+
|
|
53
|
+
## 6.2.0-canary.84
|
|
54
|
+
|
|
55
|
+
## 6.2.0-canary.83
|
|
56
|
+
|
|
57
|
+
## 6.2.0-canary.82
|
|
58
|
+
|
|
59
|
+
## 6.2.0-canary.81
|
|
60
|
+
|
|
61
|
+
## 6.2.0-canary.80
|
|
62
|
+
|
|
63
|
+
## 6.2.0-canary.79
|
|
64
|
+
|
|
65
|
+
### Patch Changes
|
|
66
|
+
|
|
67
|
+
- [#2013](https://github.com/graphcommerce-org/graphcommerce/pull/2013) [`c57bdf8a4`](https://github.com/graphcommerce-org/graphcommerce/commit/c57bdf8a4ce936c3eedc4dfada3a464a113ac68a) - Updated @mui and framer-motion packages to latest versions ([@paales](https://github.com/paales))
|
|
68
|
+
|
|
69
|
+
## 6.2.0-canary.78
|
|
70
|
+
|
|
71
|
+
## 6.2.0-canary.77
|
|
72
|
+
|
|
73
|
+
## 6.2.0-canary.76
|
|
74
|
+
|
|
75
|
+
## 6.2.0-canary.75
|
|
76
|
+
|
|
77
|
+
## 6.2.0-canary.74
|
|
78
|
+
|
|
79
|
+
## 6.2.0-canary.73
|
|
80
|
+
|
|
81
|
+
## 6.2.0-canary.72
|
|
82
|
+
|
|
83
|
+
## 6.2.0-canary.71
|
|
84
|
+
|
|
85
|
+
## 6.2.0-canary.70
|
|
86
|
+
|
|
87
|
+
### Patch Changes
|
|
88
|
+
|
|
89
|
+
- [#2010](https://github.com/graphcommerce-org/graphcommerce/pull/2010) [`236471e8c`](https://github.com/graphcommerce-org/graphcommerce/commit/236471e8ca892be337de31bd3d654f2ddddf8695) - Fixed bug which caused the sign in field to not be focusable ([@Jessevdpoel](https://github.com/Jessevdpoel))
|
|
90
|
+
|
|
91
|
+
## 6.2.0-canary.69
|
|
92
|
+
|
|
93
|
+
## 6.2.0-canary.68
|
|
94
|
+
|
|
95
|
+
## 6.2.0-canary.67
|
|
96
|
+
|
|
97
|
+
## 6.2.0-canary.66
|
|
98
|
+
|
|
99
|
+
### Patch Changes
|
|
100
|
+
|
|
101
|
+
- [#1993](https://github.com/graphcommerce-org/graphcommerce/pull/1993) [`f9bd75108`](https://github.com/graphcommerce-org/graphcommerce/commit/f9bd75108ecef583ecd32e701c10d70537cb8a89) - Fixed scrollers not working properly in Firefox due to the `draggable` html property being handled differently. Added event.preventDefault() onMouseDown to useScroller to prevent drag and drop functionality inside scrollers. ([@Jessevdpoel](https://github.com/Jessevdpoel))
|
|
102
|
+
|
|
103
|
+
## 6.2.0-canary.65
|
|
104
|
+
|
|
105
|
+
### Minor Changes
|
|
106
|
+
|
|
107
|
+
- [#1996](https://github.com/graphcommerce-org/graphcommerce/pull/1996) [`3ed66a849`](https://github.com/graphcommerce-org/graphcommerce/commit/3ed66a849430d6ad1c46d20828eb988283da0c4a) - Added a disableZoom prop to SidebarGallery to disable all zoom functionality ([@Jessevdpoel](https://github.com/Jessevdpoel))
|
|
108
|
+
|
|
109
|
+
## 6.2.0-canary.64
|
|
110
|
+
|
|
111
|
+
### Patch Changes
|
|
112
|
+
|
|
113
|
+
- [#1998](https://github.com/graphcommerce-org/graphcommerce/pull/1998) [`a788baaeb`](https://github.com/graphcommerce-org/graphcommerce/commit/a788baaeb9646c5a30b55998697d38a6093b6c44) - Added option to useScrollTo to allow/disallow stopping the scroll animation on user scroll interaction ([@bramvanderholst](https://github.com/bramvanderholst))
|
|
114
|
+
|
|
115
|
+
## 6.2.0-canary.63
|
|
116
|
+
|
|
117
|
+
## 6.2.0-canary.62
|
|
118
|
+
|
|
119
|
+
## 6.2.0-canary.61
|
|
120
|
+
|
|
121
|
+
## 6.2.0-canary.60
|
|
122
|
+
|
|
123
|
+
## 6.2.0-canary.59
|
|
124
|
+
|
|
125
|
+
## 6.2.0-canary.58
|
|
126
|
+
|
|
127
|
+
## 6.2.0-canary.57
|
|
128
|
+
|
|
129
|
+
## 6.2.0-canary.56
|
|
130
|
+
|
|
131
|
+
## 6.2.0-canary.55
|
|
132
|
+
|
|
133
|
+
## 6.2.0-canary.54
|
|
134
|
+
|
|
135
|
+
## 6.2.0-canary.53
|
|
136
|
+
|
|
137
|
+
## 6.2.0-canary.52
|
|
138
|
+
|
|
139
|
+
## 6.2.0-canary.51
|
|
140
|
+
|
|
141
|
+
## 6.2.0-canary.50
|
|
142
|
+
|
|
143
|
+
## 6.2.0-canary.49
|
|
144
|
+
|
|
145
|
+
## 6.2.0-canary.48
|
|
146
|
+
|
|
147
|
+
## 6.2.0-canary.47
|
|
148
|
+
|
|
149
|
+
## 6.2.0-canary.46
|
|
150
|
+
|
|
151
|
+
## 6.2.0-canary.45
|
|
152
|
+
|
|
153
|
+
## 6.2.0-canary.44
|
|
154
|
+
|
|
155
|
+
## 6.2.0-canary.43
|
|
156
|
+
|
|
157
|
+
## 6.2.0-canary.42
|
|
158
|
+
|
|
159
|
+
## 6.2.0-canary.41
|
|
160
|
+
|
|
161
|
+
## 6.2.0-canary.40
|
|
162
|
+
|
|
163
|
+
## 6.2.0-canary.39
|
|
164
|
+
|
|
165
|
+
## 6.2.0-canary.38
|
|
166
|
+
|
|
167
|
+
## 6.2.0-canary.37
|
|
168
|
+
|
|
169
|
+
## 6.2.0-canary.36
|
|
170
|
+
|
|
171
|
+
## 6.2.0-canary.35
|
|
172
|
+
|
|
173
|
+
### Patch Changes
|
|
174
|
+
|
|
175
|
+
- [#1954](https://github.com/graphcommerce-org/graphcommerce/pull/1954) [`ec82fe49c`](https://github.com/graphcommerce-org/graphcommerce/commit/ec82fe49cd9aa0865b6c21eb405f05d8596748f6) - fix: prevent overlays from aut-closing on iOS 14 ([@FrankHarland](https://github.com/FrankHarland))
|
|
176
|
+
|
|
177
|
+
## 6.2.0-canary.34
|
|
178
|
+
|
|
179
|
+
## 6.2.0-canary.33
|
|
180
|
+
|
|
181
|
+
## 6.2.0-canary.32
|
|
182
|
+
|
|
183
|
+
## 6.2.0-canary.31
|
|
184
|
+
|
|
185
|
+
## 6.2.0-canary.30
|
|
186
|
+
|
|
187
|
+
## 6.2.0-canary.29
|
|
188
|
+
|
|
189
|
+
## 6.2.0-canary.28
|
|
190
|
+
|
|
191
|
+
## 6.2.0-canary.27
|
|
192
|
+
|
|
193
|
+
## 6.2.0-canary.26
|
|
194
|
+
|
|
195
|
+
## 6.2.0-canary.25
|
|
196
|
+
|
|
197
|
+
## 6.2.0-canary.24
|
|
198
|
+
|
|
199
|
+
## 6.2.0-canary.23
|
|
200
|
+
|
|
201
|
+
## 6.2.0-canary.22
|
|
202
|
+
|
|
203
|
+
## 6.2.0-canary.21
|
|
204
|
+
|
|
205
|
+
### Minor Changes
|
|
6
206
|
|
|
7
207
|
- [#1937](https://github.com/graphcommerce-org/graphcommerce/pull/1937) [`a98e23e3a`](https://github.com/graphcommerce-org/graphcommerce/commit/a98e23e3a250157b9d3756b656f1a4c3c52b0ec0) - Assign correct scroll-snap-type type, to prevent error on firefox ([@mikekeehnen](https://github.com/mikekeehnen))
|
|
8
208
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useMotionValueValue } from '@graphcommerce/framer-utils'
|
|
2
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
3
|
import { extendableComponent } from '@graphcommerce/next-ui/Styles'
|
|
3
4
|
import { i18n } from '@lingui/core'
|
|
4
5
|
import { Fab, FabProps, styled } from '@mui/material'
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useMotionValueValue } from '@graphcommerce/framer-utils'
|
|
2
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
3
|
import { extendableComponent } from '@graphcommerce/next-ui/Styles'
|
|
3
4
|
import { Box, FabProps, styled, SxProps, Theme } from '@mui/material'
|
|
4
5
|
import { m } from 'framer-motion'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useConstant, useElementScroll } from '@graphcommerce/framer-utils'
|
|
2
|
-
import { MotionValue, motionValue, Point, useMotionValue } from 'framer-motion'
|
|
2
|
+
import { MotionValue, motionValue, Point, useDomEvent, useMotionValue } from 'framer-motion'
|
|
3
3
|
import { PlaybackControls } from 'popmotion'
|
|
4
4
|
import React, { useEffect, useRef, useMemo, useCallback } from 'react'
|
|
5
5
|
import { scrollerContext } from '../context/scrollerContext'
|
|
@@ -85,6 +85,7 @@ export function ScrollerProvider(props: ScrollerProviderProps) {
|
|
|
85
85
|
)
|
|
86
86
|
|
|
87
87
|
const snap = useMotionValue(_inititalSnap)
|
|
88
|
+
const stopOnInteraction = useMotionValue(_inititalSnap)
|
|
88
89
|
|
|
89
90
|
// Monitor the visbility of all elements and store them for later use.
|
|
90
91
|
const items = useMotionValue<ItemState[]>([])
|
|
@@ -104,42 +105,55 @@ export function ScrollerProvider(props: ScrollerProviderProps) {
|
|
|
104
105
|
[stop],
|
|
105
106
|
)
|
|
106
107
|
|
|
107
|
-
const disableSnap = useCallback(
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
const disableSnap = useCallback(
|
|
109
|
+
(stopAnimationOnScroll = true) => {
|
|
110
|
+
stopOnInteraction.set(stopAnimationOnScroll)
|
|
111
|
+
if (snap.get() === false) stop()
|
|
112
|
+
if (scrollerRef.current) scrollerRef.current.style.scrollSnapType = 'none'
|
|
110
113
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
+
scroll.animating.set(true)
|
|
115
|
+
snap.set(false)
|
|
116
|
+
},
|
|
117
|
+
[stopOnInteraction, snap, stop, scroll.animating],
|
|
118
|
+
)
|
|
114
119
|
|
|
115
120
|
const enableSnap = useCallback(() => {
|
|
116
121
|
if (snap.get() === true) return
|
|
117
|
-
if (scrollerRef.current) scrollerRef.current.style.scrollSnapType = ''
|
|
118
|
-
snap.set(true)
|
|
119
122
|
|
|
120
|
-
|
|
121
|
-
* There is a bug in Firefox where the actual max scrollLeft isn't the same as the max measured
|
|
122
|
-
* bounds of the elements. If we do not exactly set the correct scrollLeft the scrollLeft is
|
|
123
|
-
* reset to 0 on firefox (instead of chrome/safari where it will snap to the nearest valid
|
|
124
|
-
* position).
|
|
125
|
-
*
|
|
126
|
-
* This can be checked by opening a LayoutOverlay.
|
|
127
|
-
*
|
|
128
|
-
* So we're setting a 'too big' scroll position by an arbitrary amount.
|
|
129
|
-
*
|
|
130
|
-
* To check if it works in a more recent version of FireFox:
|
|
131
|
-
*
|
|
132
|
-
* - Move `scroll.animating.set(false)` outside the requestAnimationFrame
|
|
133
|
-
* - Remove `scrollerRef.current.scrollLeft = prev + 10`
|
|
134
|
-
*/
|
|
135
|
-
const prev = scroll.x.get()
|
|
136
|
-
requestAnimationFrame(() => {
|
|
137
|
-
if (scrollerRef.current && Math.round(scrollerRef.current.scrollLeft) !== prev)
|
|
138
|
-
scrollerRef.current.scrollLeft = prev + 10
|
|
123
|
+
stop()
|
|
139
124
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
125
|
+
const scroller = scrollerRef.current
|
|
126
|
+
if (scroller) scroller.style.scrollSnapType = ''
|
|
127
|
+
|
|
128
|
+
snap.set(true)
|
|
129
|
+
scroll.animating.set(false)
|
|
130
|
+
// Fix for iOS Safari 14 where the scrollPosition would be reset to 0.
|
|
131
|
+
if (scroller) {
|
|
132
|
+
const { scrollLeft, scrollTop } = scroller
|
|
133
|
+
requestAnimationFrame(() => {
|
|
134
|
+
// We're forcing a layout calculation, else Safari 14 will still close.
|
|
135
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
136
|
+
const forceLayout = scroller.scrollTop
|
|
137
|
+
requestAnimationFrame(() => {
|
|
138
|
+
if (scroller.scrollTop === 0 && scrollTop !== 0) scroller.scrollTop = scrollTop
|
|
139
|
+
if (scroller.scrollLeft === 0 && scrollLeft !== 0) scroller.scrollLeft = scrollLeft
|
|
140
|
+
})
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
}, [snap, scroll.animating, stop])
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* If the scroller is animating and the user now uses their scrollwheel, enable the snapping
|
|
147
|
+
* behavior.
|
|
148
|
+
*
|
|
149
|
+
* If the scroller doesn't have snap enabled and isPanning===false, enable snap
|
|
150
|
+
*/
|
|
151
|
+
useDomEvent(scrollerRef as React.RefObject<EventTarget>, 'wheel', () => {
|
|
152
|
+
if (stopOnInteraction.get()) enableSnap()
|
|
153
|
+
})
|
|
154
|
+
useDomEvent(scrollerRef as React.RefObject<EventTarget>, 'touchmove', () => {
|
|
155
|
+
if (stopOnInteraction.get()) stop()
|
|
156
|
+
})
|
|
143
157
|
|
|
144
158
|
useObserveItems(scrollerRef, items)
|
|
145
159
|
|
package/hooks/useScrollTo.ts
CHANGED
|
@@ -4,6 +4,10 @@ import { useCallback, useContext } from 'react'
|
|
|
4
4
|
import { distanceAnimationDuration } from '../utils/distanceAnimationDuration'
|
|
5
5
|
import { useScrollerContext } from './useScrollerContext'
|
|
6
6
|
|
|
7
|
+
type Options = {
|
|
8
|
+
stopAnimationOnScroll?: boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
7
11
|
export function useScrollTo() {
|
|
8
12
|
const { scrollerRef, register, disableSnap, enableSnap, scroll, getScrollSnapPositions } =
|
|
9
13
|
useScrollerContext()
|
|
@@ -11,8 +15,13 @@ export function useScrollTo() {
|
|
|
11
15
|
const duration = (useContext(MotionConfigContext).transition as Tween | undefined)?.duration ?? 0
|
|
12
16
|
|
|
13
17
|
const scrollTo = useCallback(
|
|
14
|
-
async (
|
|
18
|
+
async (
|
|
19
|
+
incoming: Point | [number, number],
|
|
20
|
+
options: Options = { stopAnimationOnScroll: true },
|
|
21
|
+
__retrigger = 0,
|
|
22
|
+
) => {
|
|
15
23
|
const ref = scrollerRef.current
|
|
24
|
+
const { stopAnimationOnScroll } = options
|
|
16
25
|
if (!ref) return
|
|
17
26
|
|
|
18
27
|
let to: Point
|
|
@@ -24,20 +33,20 @@ export function useScrollTo() {
|
|
|
24
33
|
to = incoming
|
|
25
34
|
}
|
|
26
35
|
|
|
27
|
-
if (process.env.NODE_ENV === 'development' && scroll.animating.get() &&
|
|
36
|
+
if (process.env.NODE_ENV === 'development' && scroll.animating.get() && __retrigger === 0) {
|
|
28
37
|
console.warn(
|
|
29
38
|
`scrollTo triggered while another animation is in progress. This cancels the current animation and creates a new one.`,
|
|
30
39
|
)
|
|
31
40
|
}
|
|
32
41
|
|
|
33
|
-
if (process.env.NODE_ENV === 'development' &&
|
|
42
|
+
if (process.env.NODE_ENV === 'development' && __retrigger > 5) {
|
|
34
43
|
console.error(
|
|
35
44
|
`scrollTo triggered more than 5 times, is the element resizing constantly? Bailing out.`,
|
|
36
45
|
)
|
|
37
46
|
return
|
|
38
47
|
}
|
|
39
48
|
|
|
40
|
-
if (process.env.NODE_ENV === 'development' &&
|
|
49
|
+
if (process.env.NODE_ENV === 'development' && __retrigger > 0) {
|
|
41
50
|
console.warn(
|
|
42
51
|
`scrollTo re-animating to because the final location changed during animation.`,
|
|
43
52
|
)
|
|
@@ -47,7 +56,8 @@ export function useScrollTo() {
|
|
|
47
56
|
|
|
48
57
|
const xDone = new Promise<void>((onComplete) => {
|
|
49
58
|
if (ref.scrollLeft !== to.x) {
|
|
50
|
-
disableSnap()
|
|
59
|
+
disableSnap(stopAnimationOnScroll)
|
|
60
|
+
if (!stopAnimationOnScroll) ref.style.overflow = 'hidden'
|
|
51
61
|
|
|
52
62
|
stop.push(
|
|
53
63
|
animate({
|
|
@@ -68,7 +78,9 @@ export function useScrollTo() {
|
|
|
68
78
|
|
|
69
79
|
const yDone = new Promise<void>((onComplete) => {
|
|
70
80
|
if (ref.scrollTop !== to.y) {
|
|
71
|
-
disableSnap()
|
|
81
|
+
disableSnap(stopAnimationOnScroll)
|
|
82
|
+
if (!stopAnimationOnScroll) ref.style.overflow = 'hidden'
|
|
83
|
+
|
|
72
84
|
stop.push(
|
|
73
85
|
animate({
|
|
74
86
|
from: ref.scrollTop,
|
|
@@ -92,10 +104,12 @@ export function useScrollTo() {
|
|
|
92
104
|
register({ stop: () => stop.forEach((s) => s.stop()) })
|
|
93
105
|
await Promise.all([xDone, yDone])
|
|
94
106
|
|
|
107
|
+
if (!stopAnimationOnScroll) ref.style.removeProperty('overflow')
|
|
108
|
+
|
|
95
109
|
if (Array.isArray(incoming)) {
|
|
96
110
|
const checkPositions = getScrollSnapPositions()
|
|
97
111
|
if (checkPositions.x[incoming[0]] !== to.x || checkPositions.y[incoming[1]] !== to.y)
|
|
98
|
-
await scrollTo(incoming,
|
|
112
|
+
await scrollTo(incoming, options, __retrigger + 1)
|
|
99
113
|
}
|
|
100
114
|
enableSnap()
|
|
101
115
|
},
|
package/hooks/useScroller.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useConstant, useMotionValueValue } from '@graphcommerce/framer-utils'
|
|
2
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
3
|
import { extendableComponent } from '@graphcommerce/next-ui/Styles'
|
|
3
4
|
import { SxProps, Theme } from '@mui/material'
|
|
4
5
|
import {
|
|
@@ -7,10 +8,9 @@ import {
|
|
|
7
8
|
MotionValue,
|
|
8
9
|
PanHandlers,
|
|
9
10
|
PanInfo,
|
|
10
|
-
useDomEvent,
|
|
11
11
|
useTransform,
|
|
12
12
|
} from 'framer-motion'
|
|
13
|
-
import React, { ReactHTML, useEffect, useState } from 'react'
|
|
13
|
+
import React, { MouseEventHandler, ReactHTML, useEffect, useState } from 'react'
|
|
14
14
|
import { isHTMLMousePointerEvent } from '../utils/isHTMLMousePointerEvent'
|
|
15
15
|
import { scrollSnapTypeDirection, SnapTypeDirection } from '../utils/scrollSnapTypeDirection'
|
|
16
16
|
import { useScrollerContext } from './useScrollerContext'
|
|
@@ -47,7 +47,7 @@ export function useScroller<
|
|
|
47
47
|
>(props: ScrollableProps<TagName>, forwardedRef: React.ForwardedRef<E>) {
|
|
48
48
|
const { hideScrollbar = false, children, grid = false, ...divProps } = props
|
|
49
49
|
|
|
50
|
-
const { scrollSnap, scrollerRef,
|
|
50
|
+
const { scrollSnap, scrollerRef, disableSnap, snap, registerChildren, scroll } =
|
|
51
51
|
useScrollerContext()
|
|
52
52
|
|
|
53
53
|
useEffect(() => {
|
|
@@ -68,19 +68,6 @@ export function useScroller<
|
|
|
68
68
|
|
|
69
69
|
const [isPanning, setPanning] = useState(false)
|
|
70
70
|
|
|
71
|
-
/** If the scroller doesn't have snap enabled and the user is not panning, enable snap */
|
|
72
|
-
useDomEvent(scrollerRef as React.RefObject<EventTarget>, 'wheel', (e) => {
|
|
73
|
-
/**
|
|
74
|
-
* Todo: this is actually incorrect because when enabling the snap points, the area jumps to the
|
|
75
|
-
* nearest point a snap.
|
|
76
|
-
*
|
|
77
|
-
* What we SHOULD do is wait for the scroll position to be set exactly on a snappoint and then
|
|
78
|
-
* enable it. However, to do that then we need to know the position of all elements at all time,
|
|
79
|
-
* we now are lazy :)
|
|
80
|
-
*/
|
|
81
|
-
if (!snap.get() && !isPanning && e instanceof WheelEvent) enableSnap()
|
|
82
|
-
})
|
|
83
|
-
|
|
84
71
|
const scrollStart = useConstant(() => ({ x: motionValue(0), y: motionValue(0) }))
|
|
85
72
|
const onPanStart: PanHandlers['onPanStart'] = (event) => {
|
|
86
73
|
// If we're not dealing with the mouse we don't need to do anything
|
|
@@ -102,6 +89,14 @@ export function useScroller<
|
|
|
102
89
|
setPanning(true)
|
|
103
90
|
}
|
|
104
91
|
|
|
92
|
+
const onMouseDown: MouseEventHandler<HTMLDivElement> = (event) => {
|
|
93
|
+
if (event.target instanceof Element) {
|
|
94
|
+
if (event.target.tagName === 'INPUT' || event.target.tagName === 'TEXTAREA') return
|
|
95
|
+
if (event.target.querySelector(':scope > input, :scope > textarea')) return
|
|
96
|
+
}
|
|
97
|
+
event.preventDefault()
|
|
98
|
+
}
|
|
99
|
+
|
|
105
100
|
const onPan: PanHandlers['onPan'] = (event, info: PanInfo) => {
|
|
106
101
|
if (!scrollerRef.current) return
|
|
107
102
|
|
|
@@ -289,6 +284,7 @@ export function useScroller<
|
|
|
289
284
|
onPanStart,
|
|
290
285
|
onPan,
|
|
291
286
|
onPanEnd,
|
|
287
|
+
onMouseDown,
|
|
292
288
|
children,
|
|
293
289
|
className: `${classes.root} ${props.className}`,
|
|
294
290
|
sx,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
1
2
|
import { useMatchMedia } from '@graphcommerce/next-ui/hooks/useMatchMedia'
|
|
2
3
|
import { PanInfo } from 'framer-motion'
|
|
3
4
|
import { inertia, InertiaOptions } from 'popmotion'
|
|
4
|
-
import { ScrollerContext } from '../types'
|
|
5
5
|
import { scrollSnapTypeDirection } from '../utils/scrollSnapTypeDirection'
|
|
6
6
|
import { useScrollerContext } from './useScrollerContext'
|
|
7
7
|
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/framer-scroller",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "7.0.0
|
|
5
|
+
"version": "7.0.0",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"scripts": {
|
|
8
8
|
"dev": "tsc -W"
|
|
@@ -16,18 +16,18 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"popmotion": "11.0.5",
|
|
19
|
-
"@graphcommerce/framer-utils": "7.0.0
|
|
20
|
-
"@graphcommerce/image": "7.0.0
|
|
19
|
+
"@graphcommerce/framer-utils": "7.0.0",
|
|
20
|
+
"@graphcommerce/image": "7.0.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@graphcommerce/eslint-config-pwa": "7.0.0
|
|
24
|
-
"@graphcommerce/prettier-config-pwa": "7.0.0
|
|
25
|
-
"@graphcommerce/typescript-config-pwa": "7.0.0
|
|
23
|
+
"@graphcommerce/eslint-config-pwa": "7.0.0",
|
|
24
|
+
"@graphcommerce/prettier-config-pwa": "7.0.0",
|
|
25
|
+
"@graphcommerce/typescript-config-pwa": "7.0.0"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@mui/material": "^5.10.16",
|
|
29
|
-
"@lingui/react": "^
|
|
30
|
-
"@lingui/core": "^
|
|
29
|
+
"@lingui/react": "^4.2.1",
|
|
30
|
+
"@lingui/core": "^4.2.1",
|
|
31
31
|
"framer-motion": "^10.0.0",
|
|
32
32
|
"next": "^13.2.0",
|
|
33
33
|
"react": "^18.2.0",
|
package/types.ts
CHANGED
|
@@ -32,7 +32,7 @@ export type ScrollerContext = {
|
|
|
32
32
|
/** @private */
|
|
33
33
|
enableSnap: () => void
|
|
34
34
|
/** @private */
|
|
35
|
-
disableSnap: () => void
|
|
35
|
+
disableSnap: (stopAnimationOnScroll?: boolean) => void
|
|
36
36
|
/** @private */
|
|
37
37
|
register: (controls: PlaybackControls) => void
|
|
38
38
|
/** @private */
|