unframer 2.11.2 → 2.12.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.
Files changed (47) hide show
  1. package/dist/exporter.d.ts +3 -0
  2. package/dist/exporter.d.ts.map +1 -1
  3. package/dist/exporter.js +54 -30
  4. package/dist/exporter.js.map +1 -1
  5. package/dist/exporter.test.js +3 -0
  6. package/dist/exporter.test.js.map +1 -1
  7. package/dist/framer.d.ts.map +1 -1
  8. package/dist/framer.js +840 -488
  9. package/dist/framer.js.map +1 -1
  10. package/dist/index.d.ts +3 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +9 -5
  13. package/dist/index.js.map +1 -1
  14. package/dist/react.d.ts +15 -6
  15. package/dist/react.d.ts.map +1 -1
  16. package/dist/react.js +66 -3
  17. package/dist/react.js.map +1 -1
  18. package/dist/utils.d.ts +1 -1
  19. package/dist/utils.d.ts.map +1 -1
  20. package/dist/utils.js.map +1 -1
  21. package/esm/exporter.d.ts +3 -0
  22. package/esm/exporter.d.ts.map +1 -1
  23. package/esm/exporter.js +55 -32
  24. package/esm/exporter.js.map +1 -1
  25. package/esm/exporter.test.js +4 -1
  26. package/esm/exporter.test.js.map +1 -1
  27. package/esm/framer.d.ts.map +1 -1
  28. package/esm/framer.js +837 -488
  29. package/esm/framer.js.map +1 -1
  30. package/esm/index.d.ts +3 -1
  31. package/esm/index.d.ts.map +1 -1
  32. package/esm/index.js +3 -1
  33. package/esm/index.js.map +1 -1
  34. package/esm/react.d.ts +15 -6
  35. package/esm/react.d.ts.map +1 -1
  36. package/esm/react.js +65 -5
  37. package/esm/react.js.map +1 -1
  38. package/esm/utils.d.ts +1 -1
  39. package/esm/utils.d.ts.map +1 -1
  40. package/esm/utils.js.map +1 -1
  41. package/package.json +3 -3
  42. package/src/exporter.test.ts +6 -1
  43. package/src/exporter.ts +68 -33
  44. package/src/framer.js +891 -494
  45. package/src/index.ts +7 -1
  46. package/src/react.tsx +98 -16
  47. package/src/utils.ts +1 -1
package/src/index.ts CHANGED
@@ -1,8 +1,14 @@
1
1
  export * from './framer.js'
2
-
2
+ import {
3
+ AdaptedLink as Link,
4
+ ResolveLinksAdapted as ResolveLinks,
5
+ } from './react.js'
3
6
  export {
4
7
  FramerStyles,
5
8
  UnframerBreakpoint,
6
9
  WithFramerBreakpoints,
7
10
  ContextProviders,
11
+ AdaptedLink,
8
12
  } from './react.js'
13
+
14
+ export { Link, ResolveLinks }
package/src/react.tsx CHANGED
@@ -229,36 +229,118 @@ import {
229
229
  FormContext,
230
230
  // @ts-ignore
231
231
  Router,
232
+ // @ts-ignore
233
+ LocaleInfoContext,
234
+ // @ts-ignore
235
+ FramerLink as Link,
232
236
  } from './framer.js'
237
+ import React from 'react'
238
+
239
+ type Routes = Record<string, { path: string }>
240
+
241
+ const routesContext = React.createContext<Routes>({})
242
+
243
+ function replacePathParams(path: string, params: Record<string, string>) {
244
+ const paramRegex = /:[a-zA-Z]+/g
245
+ const matches = path.match(paramRegex)
246
+
247
+ // If there is only one match
248
+ if (matches?.length === 1) {
249
+ const paramValue = Object.values(params)[0]
250
+
251
+ let res = path.replace(paramRegex, paramValue)
252
+ // console.log({ matches, params, paramValue, res })
253
+
254
+ return res
255
+ }
256
+
257
+ return path.replace(paramRegex, (match) => {
258
+ const param = match.slice(1) // Remove the : prefix
259
+ return params[param] || match // Replace with param value or keep original if not found
260
+ })
261
+ }
262
+
263
+ export function ResolveLinksAdapted({ links, children }) {
264
+ // TODO add ref
265
+ return children(links.map((x) => x.href))
266
+ }
267
+
268
+ export function AdaptedLink({
269
+ href,
270
+ nodeId,
271
+ openInNewTab,
272
+ smoothScroll,
273
+ ...rest
274
+ }) {
275
+ const onlyForFramer = { nodeId, openInNewTab, smoothScroll }
276
+ const routes = React.useContext(routesContext)
277
+ const webPageId = href?.webPageId as string
278
+ const pathVariables = href?.pathVariables as Record<string, string>
279
+ const route = routes?.[webPageId]
280
+ const target = openInNewTab ? '_blank' : undefined
281
+ // console.log({ href, pathVariables, path: route?.path, ...rest })
282
+ if (href?.startsWith && href.startsWith('/')) {
283
+ return <a href={href} target={target} {...rest} />
284
+ }
285
+ if (!webPageId) {
286
+ return <Link href={href} {...rest} {...onlyForFramer} />
287
+ }
288
+
289
+ if (!route || !route.path) {
290
+ return <Link href={href} {...rest} {...onlyForFramer} />
291
+ }
292
+ let path = route.path
293
+ if (pathVariables) {
294
+ path = replacePathParams(path, pathVariables)
295
+ }
296
+ if (path?.startsWith?.('/')) {
297
+ return <a href={path} target={target} {...rest} />
298
+ }
299
+
300
+ return <Link href={path} {...rest} {...onlyForFramer} />
301
+ }
233
302
 
234
303
  export function ContextProviders({
235
304
  locale,
236
305
  children,
237
306
  framerSiteId,
238
307
  routes,
239
- routeId,
240
- pathVariables,
241
- collectionUtils,
308
+ // collectionUtils,
242
309
  locales,
243
310
  }) {
244
- const localeId = locales?.find(
311
+ const activeLocale = locales?.find(
245
312
  (l) => l.slug === locale || l.code === locale || l.id === locale,
246
- )?.id
313
+ )
314
+
315
+ const localeInfo = useMemo(() => {
316
+ return {
317
+ activeLocale,
318
+ locales,
319
+ setLocale: async (localeOrLocaleId) => {
320
+ console.log('setLocale', localeOrLocaleId)
321
+ },
322
+ }
323
+ }, [activeLocale, locales])
247
324
  return (
248
325
  <FetchClientProvider>
249
326
  <CustomCursorHost>
250
327
  <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>
328
+ <LocaleInfoContext value={localeInfo}>
329
+ <routesContext.Provider value={routes}>
330
+ {/* <Router
331
+ initialRoute='x'
332
+ routes={{
333
+ x: { page: children, path: '/' },
334
+ ...routes,
335
+ }}
336
+ locales={locales}
337
+ initialLocaleId={activeLocale?.id}
338
+ >
339
+ {children}
340
+ </Router> */}
341
+ {children}
342
+ </routesContext.Provider>
343
+ </LocaleInfoContext>
262
344
  </FormContext.Provider>
263
345
  </CustomCursorHost>
264
346
  </FetchClientProvider>
package/src/utils.ts CHANGED
@@ -4,7 +4,7 @@ import { marked } from 'marked'
4
4
  import { markedTerminal } from 'marked-terminal'
5
5
  import { createSpinner } from 'nanospinner'
6
6
 
7
- export const spinner = createSpinner('Downloading Framer Components') as any
7
+ export const spinner = createSpinner('Downloading Framer Components')
8
8
 
9
9
  marked.use(markedTerminal())
10
10