unframer 2.25.0 → 2.25.2

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
@@ -269,6 +269,13 @@ function isRelativeLink(url) {
269
269
  }
270
270
  return url?.startsWith?.('/') || url?.startsWith?.('#')
271
271
  }
272
+
273
+ function isMailto(url) {
274
+ if (!url) {
275
+ return false
276
+ }
277
+ return url?.startsWith?.('mailto:')
278
+ }
272
279
  export function AdaptedLink({
273
280
  href,
274
281
  nodeId,
@@ -278,12 +285,12 @@ export function AdaptedLink({
278
285
  ...rest
279
286
  }) {
280
287
  const context = useContext(unframerContext)
281
- let onClick =
288
+ let navigateClientSide =
282
289
  context.navigate && !openInNewTab
283
290
  ? (e) => {
284
291
  if (!context.navigate) return
285
292
  const href = e.currentTarget?.getAttribute('href')
286
- if (!href) return
293
+ if (!href || !isRelativeLink(href)) return
287
294
  e.preventDefault()
288
295
  if (rest.onClick) rest.onClick(e)
289
296
  context.navigate(href)
@@ -295,9 +302,8 @@ export function AdaptedLink({
295
302
  const pathVariables = href?.pathVariables as Record<string, string>
296
303
  const route = routes?.[webPageId]
297
304
  const target = openInNewTab ? '_blank' : undefined
298
- // console.log({ href, pathVariables, path: route?.path, ...rest })
299
- if (isRelativeLink(href)) {
300
- return React.cloneElement(children, { ...rest, onClick, href, target })
305
+ if (isRelativeLink(href) || isMailto(href)) {
306
+ return React.cloneElement(children, { ...rest, onClick: navigateClientSide, href, target })
301
307
  }
302
308
  if (!webPageId) {
303
309
  return <Link href={href} {...rest} {...onlyForFramer} />
@@ -306,20 +312,20 @@ export function AdaptedLink({
306
312
  if (!route || !route.path) {
307
313
  return <Link href={href} {...rest} {...onlyForFramer} />
308
314
  }
309
- let path = route.path
315
+ let resolvedPath = route.path
310
316
  if (pathVariables) {
311
- path = replacePathParams(path, pathVariables)
317
+ resolvedPath = replacePathParams(resolvedPath, pathVariables)
312
318
  }
313
- if (isRelativeLink(path)) {
319
+ if (isRelativeLink(resolvedPath) || isMailto(href)) {
314
320
  return React.cloneElement(children, {
315
321
  ...rest,
316
- onClick,
317
- href: path,
322
+ onClick: navigateClientSide,
323
+ href: resolvedPath,
318
324
  target,
319
325
  })
320
326
  }
321
327
 
322
- return <Link href={path} {...rest} {...onlyForFramer} />
328
+ return <Link href={resolvedPath} {...rest} {...onlyForFramer} />
323
329
  }
324
330
 
325
331
  export function ContextProviders({
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.25.0'
1
+ export const version = '2.25.2'