unframer 2.8.0 → 2.9.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/src/react.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  'use client'
2
- import { combinedCSSRules, LayoutGroup } from './framer.js'
2
+ import { combinedCSSRules, LayoutGroup, MotionConfig } from './framer.js'
3
3
 
4
4
  import {
5
5
  ComponentPropsWithoutRef,
@@ -142,30 +142,42 @@ export const WithFramerBreakpoints = forwardRef(function WithFramerBreakpoints<
142
142
  return ''
143
143
  },
144
144
  )
145
+ const allBreakpoints = fillBreakpoints(_breakpointsMap)
146
+ const variants = new Map<
147
+ string,
148
+ { className: string; variant: string; breakpoints: string[] }
149
+ >()
150
+ for (let breakpointName of Object.keys(allBreakpoints)) {
151
+ const realVariant = allBreakpoints[breakpointName]
152
+ if (!realVariant) {
153
+ continue
154
+ }
145
155
 
146
- const parts = useMemo(() => {
147
- const allBreakpoints = fillBreakpoints(_breakpointsMap)
148
- const variants = {} as Record<
149
- string,
150
- { className: string; variant: string }
151
- >
152
- for (let breakpointName of Object.keys(allBreakpoints)) {
153
- const realVariant = allBreakpoints[breakpointName]
154
- if (!realVariant) {
155
- continue
156
- }
157
- if (currentBreakpoint && currentBreakpoint !== breakpointName) {
158
- continue
159
- }
160
-
161
- let className = classNames(
162
- variants[realVariant]?.className || 'unframer-hidden',
156
+ const existingVariant = variants.get(realVariant)
157
+ if (existingVariant) {
158
+ existingVariant.breakpoints.push(breakpointName)
159
+ existingVariant.className = classNames(
160
+ existingVariant.className,
163
161
  `unframer-${breakpointName}`,
164
162
  )
165
- variants[realVariant] = { className, variant: realVariant }
163
+ } else {
164
+ variants.set(realVariant, {
165
+ className: classNames(
166
+ 'unframer-hidden',
167
+ `unframer-${breakpointName}`,
168
+ ),
169
+ variant: realVariant,
170
+ breakpoints: [breakpointName],
171
+ })
166
172
  }
167
-
168
- return Object.values(variants).map(({ className, variant }) => {
173
+ }
174
+ const parts = [...variants.values()].map(
175
+ ({ className, breakpoints, variant }) => {
176
+ const shouldShow =
177
+ !currentBreakpoint || breakpoints.includes(currentBreakpoint)
178
+ if (!shouldShow) {
179
+ return null
180
+ }
169
181
  return (
170
182
  <div key={variant} className={className}>
171
183
  {/* @ts-ignore */}
@@ -182,8 +194,8 @@ export const WithFramerBreakpoints = forwardRef(function WithFramerBreakpoints<
182
194
  />
183
195
  </div>
184
196
  )
185
- })
186
- }, [currentBreakpoint, rest, _breakpointsMap])
197
+ },
198
+ )
187
199
 
188
200
  return parts
189
201
  })
@@ -192,3 +204,63 @@ const onResize = (callback) => {
192
204
  window.addEventListener('resize', callback)
193
205
  return () => window.removeEventListener('resize', callback)
194
206
  }
207
+
208
+ const onResizeWithDebounce = (callback) => {
209
+ let timeoutId
210
+ const debouncedCallback = () => {
211
+ clearTimeout(timeoutId)
212
+ timeoutId = setTimeout(() => {
213
+ callback()
214
+ }, 16)
215
+ }
216
+ window.addEventListener('resize', debouncedCallback)
217
+ return () => {
218
+ clearTimeout(timeoutId)
219
+ window.removeEventListener('resize', debouncedCallback)
220
+ }
221
+ }
222
+
223
+ import {
224
+ // @ts-ignore
225
+ CustomCursorHost,
226
+ // @ts-ignore
227
+ FetchClientProvider,
228
+ // @ts-ignore
229
+ FormContext,
230
+ // @ts-ignore
231
+ Router,
232
+ } from './framer.js'
233
+
234
+ export function ContextProviders({
235
+ locale,
236
+ children,
237
+ framerSiteId,
238
+ routes,
239
+ routeId,
240
+ pathVariables,
241
+ collectionUtils,
242
+ locales,
243
+ }) {
244
+ const localeId = locales?.find(
245
+ (l) => l.slug === locale || l.code === locale || l.id === locale,
246
+ )?.id
247
+ return (
248
+ <FetchClientProvider>
249
+ <CustomCursorHost>
250
+ <FormContext.Provider value={framerSiteId}>
251
+ <Router
252
+ initialRoute={routeId}
253
+ initialPathVariables={pathVariables}
254
+ initialLocaleId={localeId}
255
+ enableImproveInpDuringHydration={true}
256
+ routes={routes}
257
+ collectionUtils={collectionUtils}
258
+ locales={locales}
259
+ >
260
+ {children}
261
+ </Router>
262
+ </FormContext.Provider>
263
+ </CustomCursorHost>
264
+ </FetchClientProvider>
265
+ )
266
+ }