@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 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
@@ -19,19 +19,18 @@ export function useClientSizeCssVar() {
19
19
  if (watching === true) return () => {}
20
20
 
21
21
  const recalc = () => {
22
- if (typeof window !== 'undefined') {
23
- const { x, y } = clientSize
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
- reset()
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
@@ -7,3 +7,4 @@ export * from './hooks/useConstant'
7
7
  export * from './hooks/useElementScroll'
8
8
  export * from './hooks/useIsomorphicLayoutEffect'
9
9
  export * from './hooks/useMotionValueValue'
10
+ export * from './hooks/useMotionSelector'
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/framer-utils",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "3.1.5",
5
+ "version": "3.2.1",
6
6
  "sideEffects": false,
7
7
  "scripts": {
8
8
  "dev": "tsc -W"