@graphcommerce/framer-scroller 1.1.7 → 1.1.11
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
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.1.10](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/framer-scroller@1.1.9...@graphcommerce/framer-scroller@1.1.10) (2021-12-17)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **framer-scroller:** make sure we're not throwing only warning when there are no children ([001c7d9](https://github.com/ho-nl/m2-pwa/commit/001c7d9a00e447d44134c00bd77505e52cf0f9d4))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [1.1.8](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/framer-scroller@1.1.7...@graphcommerce/framer-scroller@1.1.8) (2021-12-15)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* scroller should not snap to off-axis while dragging and direction isn't set to both ([9118bfc](https://github.com/ho-nl/m2-pwa/commit/9118bfcb1eb9ade5f144167e47e0c26724ce832f))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
## [1.1.5](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/framer-scroller@1.1.4...@graphcommerce/framer-scroller@1.1.5) (2021-12-06)
|
|
7
29
|
|
|
8
30
|
|
|
@@ -118,7 +118,8 @@ export default function ScrollerProvider(props: ScrollerProviderProps) {
|
|
|
118
118
|
const registerChildren = useCallback(
|
|
119
119
|
(children: React.ReactNode) => {
|
|
120
120
|
const count = React.Children.count(children)
|
|
121
|
-
if (!count
|
|
121
|
+
if (!count && process.env.NODE_ENV !== 'production')
|
|
122
|
+
console.warn('[@graphcommerce/framer-scroller]: Can not find children')
|
|
122
123
|
if (count === items.get().length) return
|
|
123
124
|
|
|
124
125
|
const itemsArr: unknown[] = items.get().slice()
|
package/hooks/useScroller.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
import React, { ReactHTML, useState } from 'react'
|
|
14
14
|
import { ScrollSnapProps, ScrollSnapType } from '../types'
|
|
15
15
|
import { isHTMLMousePointerEvent } from '../utils/isHTMLMousePointerEvent'
|
|
16
|
+
import { scrollSnapTypeDirection } from '../utils/scrollSnapTypeDirection'
|
|
16
17
|
import { useScrollerContext } from './useScrollerContext'
|
|
17
18
|
import { useVelocitySnapTo } from './useVelocitySnapTo'
|
|
18
19
|
|
|
@@ -123,13 +124,6 @@ const useStyles = makeStyles(
|
|
|
123
124
|
export type ScrollableProps<TagName extends keyof ReactHTML = 'div'> = UseStyles<typeof useStyles> &
|
|
124
125
|
HTMLMotionProps<TagName> & { hideScrollbar?: boolean; grid?: boolean }
|
|
125
126
|
|
|
126
|
-
export function scrollSnapTypeDirection(scrollSnapType: ScrollSnapType) {
|
|
127
|
-
let smSnapDir = scrollSnapType.split(' ')[0]
|
|
128
|
-
smSnapDir = smSnapDir.replace('y', 'block')
|
|
129
|
-
smSnapDir = smSnapDir.replace('x', 'inline') as 'block' | 'inline' | 'both' | 'inline'
|
|
130
|
-
return smSnapDir
|
|
131
|
-
}
|
|
132
|
-
|
|
133
127
|
/** Make any HTML */
|
|
134
128
|
export function useScroller<TagName extends keyof ReactHTML = 'div'>(
|
|
135
129
|
props: ScrollableProps<TagName>,
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { Theme, useMediaQuery } from '@material-ui/core'
|
|
1
2
|
import { PanInfo } from 'framer-motion'
|
|
2
3
|
import { inertia, InertiaOptions } from 'popmotion'
|
|
4
|
+
import { scrollSnapTypeDirection } from '../utils/scrollSnapTypeDirection'
|
|
3
5
|
import { useScrollerContext } from './useScrollerContext'
|
|
4
6
|
|
|
5
7
|
const clamp = ({ velocity, offset }: PanInfo, axis: 'x' | 'y') =>
|
|
@@ -17,7 +19,11 @@ const closest = (counts: number[], target: number) =>
|
|
|
17
19
|
export const useVelocitySnapTo = (
|
|
18
20
|
ref: React.RefObject<HTMLElement> | React.MutableRefObject<HTMLElement | undefined>,
|
|
19
21
|
) => {
|
|
20
|
-
const { disableSnap, enableSnap, register, getScrollSnapPositions } =
|
|
22
|
+
const { disableSnap, enableSnap, register, getScrollSnapPositions, scrollSnap } =
|
|
23
|
+
useScrollerContext()
|
|
24
|
+
const direction = useMediaQuery<Theme>((theme) => theme.breakpoints.down('sm'))
|
|
25
|
+
? scrollSnapTypeDirection(scrollSnap.scrollSnapTypeSm)
|
|
26
|
+
: scrollSnapTypeDirection(scrollSnap.scrollSnapTypeMd)
|
|
21
27
|
|
|
22
28
|
const inertiaOptions: InertiaOptions = {
|
|
23
29
|
power: 1,
|
|
@@ -36,7 +42,8 @@ export const useVelocitySnapTo = (
|
|
|
36
42
|
|
|
37
43
|
const xDone = new Promise<void>((onComplete) => {
|
|
38
44
|
const targetX = clamp(info, 'x') * -1 + scrollLeft
|
|
39
|
-
const closestX =
|
|
45
|
+
const closestX =
|
|
46
|
+
direction !== 'block' ? closest(getScrollSnapPositions().x, targetX) : undefined
|
|
40
47
|
|
|
41
48
|
if (closestX !== scrollLeft) {
|
|
42
49
|
disableSnap()
|
|
@@ -46,7 +53,9 @@ export const useVelocitySnapTo = (
|
|
|
46
53
|
max: typeof closestX !== 'undefined' ? closestX - scrollLeft : undefined,
|
|
47
54
|
min: typeof closestX !== 'undefined' ? closestX - scrollLeft : undefined,
|
|
48
55
|
...inertiaOptions,
|
|
49
|
-
onUpdate: (v: number) =>
|
|
56
|
+
onUpdate: (v: number) => {
|
|
57
|
+
el.scrollLeft = Math.round(v + scrollLeft)
|
|
58
|
+
},
|
|
50
59
|
onComplete,
|
|
51
60
|
}),
|
|
52
61
|
)
|
|
@@ -57,7 +66,8 @@ export const useVelocitySnapTo = (
|
|
|
57
66
|
|
|
58
67
|
const yDone = new Promise<void>((onComplete) => {
|
|
59
68
|
const targetY = clamp(info, 'y') * -1 + scrollTop
|
|
60
|
-
const closestY =
|
|
69
|
+
const closestY =
|
|
70
|
+
direction !== 'inline' ? closest(getScrollSnapPositions().y, targetY) : undefined
|
|
61
71
|
|
|
62
72
|
if (closestY !== scrollTop) {
|
|
63
73
|
disableSnap()
|
|
@@ -67,7 +77,9 @@ export const useVelocitySnapTo = (
|
|
|
67
77
|
max: typeof closestY !== 'undefined' ? closestY - scrollTop : undefined,
|
|
68
78
|
min: typeof closestY !== 'undefined' ? closestY - scrollTop : undefined,
|
|
69
79
|
...inertiaOptions,
|
|
70
|
-
onUpdate: (v: number) =>
|
|
80
|
+
onUpdate: (v: number) => {
|
|
81
|
+
el.scrollTop = Math.round(v + scrollTop)
|
|
82
|
+
},
|
|
71
83
|
onComplete,
|
|
72
84
|
}),
|
|
73
85
|
)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphcommerce/framer-scroller",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.11",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "tsc -W"
|
|
@@ -16,15 +16,15 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@graphcommerce/framer-utils": "^2.103.
|
|
20
|
-
"@graphcommerce/image": "^2.105.
|
|
21
|
-
"@graphcommerce/next-ui": "^3.
|
|
19
|
+
"@graphcommerce/framer-utils": "^2.103.19",
|
|
20
|
+
"@graphcommerce/image": "^2.105.8",
|
|
21
|
+
"@graphcommerce/next-ui": "^3.21.1",
|
|
22
22
|
"@material-ui/core": "^4.12.3",
|
|
23
23
|
"popmotion": "11.0.3"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@graphcommerce/browserslist-config-pwa": "^3.0.2",
|
|
27
|
-
"@graphcommerce/eslint-config-pwa": "^3.1.
|
|
27
|
+
"@graphcommerce/eslint-config-pwa": "^3.1.8",
|
|
28
28
|
"@graphcommerce/prettier-config-pwa": "^3.0.4",
|
|
29
29
|
"@graphcommerce/typescript-config-pwa": "^3.1.1",
|
|
30
30
|
"@playwright/test": "^1.17.1"
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"react-dom": "^17.0.2",
|
|
37
37
|
"type-fest": "^2.8.0"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "6cab980582a62a8eee8d5f9bd77583cabc32c6f8"
|
|
40
40
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ScrollSnapType } from '../types'
|
|
2
|
+
|
|
3
|
+
type SnapTypeDirection = 'block' | 'inline' | 'both' | 'inline'
|
|
4
|
+
export function scrollSnapTypeDirection(scrollSnapType: ScrollSnapType): SnapTypeDirection {
|
|
5
|
+
let snapDir = scrollSnapType.split(' ')[0]
|
|
6
|
+
snapDir = snapDir.replace('y', 'block')
|
|
7
|
+
snapDir = snapDir.replace('x', 'inline')
|
|
8
|
+
return snapDir as SnapTypeDirection
|
|
9
|
+
}
|