unframer 2.22.0 → 2.23.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/src/index.ts CHANGED
@@ -9,6 +9,7 @@ export {
9
9
  WithFramerBreakpoints,
10
10
  ContextProviders,
11
11
  AdaptedLink,
12
+ UnframerProvider,
12
13
  // withCSS,
13
14
  } from './react.js'
14
15
 
package/src/react.tsx CHANGED
@@ -4,7 +4,9 @@ import { combinedCSSRules, withCSS as originalWithCSS } from './framer.js'
4
4
  import {
5
5
  ComponentPropsWithoutRef,
6
6
  ComponentType,
7
+ createContext,
7
8
  forwardRef,
9
+ useContext,
8
10
  useMemo,
9
11
  useSyncExternalStore,
10
12
  } from 'react'
@@ -275,6 +277,18 @@ export function AdaptedLink({
275
277
  children,
276
278
  ...rest
277
279
  }) {
280
+ const context = useContext(unframerContext)
281
+ let onClick =
282
+ context.navigate && !openInNewTab
283
+ ? (e) => {
284
+ if (!context.navigate) return
285
+ const href = e.currentTarget?.getAttribute('href')
286
+ if (!href) return
287
+ e.preventDefault()
288
+ if (rest.onClick) rest.onClick(e)
289
+ context.navigate(href)
290
+ }
291
+ : null
278
292
  const onlyForFramer = { children, nodeId, openInNewTab, smoothScroll }
279
293
  const routes = React.useContext(routesContext)
280
294
  const webPageId = href?.webPageId as string
@@ -283,7 +297,7 @@ export function AdaptedLink({
283
297
  const target = openInNewTab ? '_blank' : undefined
284
298
  // console.log({ href, pathVariables, path: route?.path, ...rest })
285
299
  if (isRelativeLink(href)) {
286
- return React.cloneElement(children, { ...rest, href, target })
300
+ return React.cloneElement(children, { ...rest, onClick, href, target })
287
301
  }
288
302
  if (!webPageId) {
289
303
  return <Link href={href} {...rest} {...onlyForFramer} />
@@ -299,6 +313,7 @@ export function AdaptedLink({
299
313
  if (isRelativeLink(path)) {
300
314
  return React.cloneElement(children, {
301
315
  ...rest,
316
+ onClick,
302
317
  href: path,
303
318
  target,
304
319
  })
@@ -382,3 +397,20 @@ function isEmpty(obj: Record<any, any>) {
382
397
  }
383
398
  return true
384
399
  }
400
+
401
+ type UnframerProviderProps = {
402
+ navigate?: (url: string) => void
403
+ children: React.ReactNode
404
+ }
405
+
406
+ const unframerContext = createContext<Partial<UnframerProviderProps>>({
407
+ navigate: undefined,
408
+ })
409
+
410
+ export function UnframerProvider(props: UnframerProviderProps) {
411
+ return (
412
+ <unframerContext.Provider value={props}>
413
+ {props.children}
414
+ </unframerContext.Provider>
415
+ )
416
+ }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.22.0'
1
+ export const version = '2.23.0'