@graphcommerce/framer-utils 3.1.5 → 3.2.1
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 +14 -0
- package/hooks/useClientSize.ts +6 -7
- package/hooks/useMotionSelector.ts +27 -0
- package/index.ts +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 3.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1675](https://github.com/graphcommerce-org/graphcommerce/pull/1675) [`1b1504c9b`](https://github.com/graphcommerce-org/graphcommerce/commit/1b1504c9b0e51f2787bce91e1ff1940f540411d6) Thanks [@paales](https://github.com/paales)! - Added crosssel functionality
|
|
8
|
+
|
|
9
|
+
- [#1675](https://github.com/graphcommerce-org/graphcommerce/pull/1675) [`6c2e27b1b`](https://github.com/graphcommerce-org/graphcommerce/commit/6c2e27b1be4aaa888e65a2bd69eaeb467a54a023) Thanks [@paales](https://github.com/paales)! - Use event listeners directly for the client-size, because it wasn’t updating properly it seemed
|
|
10
|
+
|
|
11
|
+
## 3.2.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- [#1601](https://github.com/graphcommerce-org/graphcommerce/pull/1601) [`01372b918`](https://github.com/graphcommerce-org/graphcommerce/commit/01372b918a291e01cbf5db40edcb40fb1c2af313) Thanks [@paales](https://github.com/paales)! - Added a useMotionSelector which acceps an array of motion values
|
|
16
|
+
|
|
3
17
|
## 3.1.5
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/hooks/useClientSize.ts
CHANGED
|
@@ -19,19 +19,18 @@ export function useClientSizeCssVar() {
|
|
|
19
19
|
if (watching === true) return () => {}
|
|
20
20
|
|
|
21
21
|
const recalc = () => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
document.body.style.setProperty('--client-size-x', `${x.get()}px`)
|
|
25
|
-
document.body.style.setProperty('--client-size-y', `${y.get()}px`)
|
|
26
|
-
}
|
|
22
|
+
document.body.style.setProperty('--client-size-x', `${global.window?.innerWidth ?? 0}px`)
|
|
23
|
+
document.body.style.setProperty('--client-size-y', `${global.window?.innerHeight ?? 0}px`)
|
|
27
24
|
}
|
|
25
|
+
|
|
26
|
+
window.addEventListener('resize', recalc)
|
|
27
|
+
|
|
28
28
|
recalc()
|
|
29
29
|
watching = true
|
|
30
|
-
const reset = clientSize.y.onChange(recalc)
|
|
31
30
|
|
|
32
31
|
return () => {
|
|
33
32
|
watching = false
|
|
34
|
-
|
|
33
|
+
window.removeEventListener('resize', recalc)
|
|
35
34
|
}
|
|
36
35
|
}, [])
|
|
37
36
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { MotionValue } from 'framer-motion'
|
|
2
|
+
import { startTransition, useState } from 'react'
|
|
3
|
+
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'
|
|
4
|
+
|
|
5
|
+
type UnwrapMotionValue<T> = T extends MotionValue<infer U> ? U : T
|
|
6
|
+
type UnwrapMotionValues<T extends [...any[]]> = T extends [infer Head, ...infer Tail]
|
|
7
|
+
? [UnwrapMotionValue<Head>, ...UnwrapMotionValues<Tail>]
|
|
8
|
+
: []
|
|
9
|
+
|
|
10
|
+
export function useMotionSelector<T extends [...any[]], R>(
|
|
11
|
+
motionValues: readonly [...T],
|
|
12
|
+
effect: (v: UnwrapMotionValues<T>) => R,
|
|
13
|
+
) {
|
|
14
|
+
const calcEffect = () => effect(motionValues.map((v) => v.get()) as UnwrapMotionValues<T>)
|
|
15
|
+
const [result, setResult] = useState<R>(calcEffect)
|
|
16
|
+
|
|
17
|
+
useIsomorphicLayoutEffect(() => {
|
|
18
|
+
const set = () => startTransition(() => setResult(calcEffect))
|
|
19
|
+
setResult(calcEffect)
|
|
20
|
+
|
|
21
|
+
const unsubscribers = motionValues.map((motionValue) => motionValue.onChange(set))
|
|
22
|
+
return () => unsubscribers.forEach((unsubscribe) => unsubscribe())
|
|
23
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
24
|
+
}, [motionValues])
|
|
25
|
+
|
|
26
|
+
return result
|
|
27
|
+
}
|
package/index.ts
CHANGED
package/package.json
CHANGED