next-intl 3.25.0 → 4.0.0-beta-00a79d4

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 (450) hide show
  1. package/config.d.ts +2 -1
  2. package/dist/cjs/development/plugin.cjs +167 -0
  3. package/dist/{development → esm/development}/config.js +1 -5
  4. package/dist/esm/development/index.react-client.js +3 -0
  5. package/dist/esm/development/index.react-server.js +8 -0
  6. package/dist/{development → esm/development}/middleware/getAlternateLinksHeaderValue.js +18 -25
  7. package/dist/esm/development/middleware/middleware.js +155 -0
  8. package/dist/{development → esm/development}/middleware/resolveLocale.js +13 -25
  9. package/dist/esm/development/middleware/syncCookie.js +20 -0
  10. package/dist/{development → esm/development}/middleware/utils.js +24 -54
  11. package/dist/esm/development/middleware.js +1 -0
  12. package/dist/{development → esm/development}/navigation/react-client/createNavigation.js +22 -29
  13. package/dist/esm/development/navigation/react-client/useBasePathname.js +27 -0
  14. package/dist/esm/development/navigation/react-server/createNavigation.js +22 -0
  15. package/dist/esm/development/navigation/react-server/getServerLocale.js +12 -0
  16. package/dist/{development → esm/development}/navigation/shared/BaseLink.js +31 -36
  17. package/dist/{development → esm/development}/navigation/shared/createSharedNavigationFns.js +39 -50
  18. package/dist/{development → esm/development}/navigation/shared/syncLocaleCookie.js +5 -9
  19. package/dist/{development → esm/development}/navigation/shared/utils.js +21 -35
  20. package/dist/esm/development/navigation.react-client.js +1 -0
  21. package/dist/esm/development/navigation.react-server.js +1 -0
  22. package/dist/esm/development/plugin/createMessagesDeclaration.js +61 -0
  23. package/dist/esm/development/plugin/createNextIntlPlugin.js +23 -0
  24. package/dist/esm/development/plugin/getNextConfig.js +82 -0
  25. package/dist/esm/development/plugin/utils.js +11 -0
  26. package/dist/esm/development/plugin.js +1 -0
  27. package/dist/esm/development/react-client/index.js +35 -0
  28. package/dist/esm/development/react-server/NextIntlClientProviderServer.js +31 -0
  29. package/dist/esm/development/react-server/useConfig.js +21 -0
  30. package/dist/esm/development/react-server/useFormatter.js +9 -0
  31. package/dist/esm/development/react-server/useLocale.js +8 -0
  32. package/dist/esm/development/react-server/useMessages.js +9 -0
  33. package/dist/esm/development/react-server/useNow.js +12 -0
  34. package/dist/esm/development/react-server/useTimeZone.js +8 -0
  35. package/dist/esm/development/react-server/useTranslations.js +9 -0
  36. package/dist/esm/development/routing/config.js +28 -0
  37. package/dist/esm/development/routing/defineRouting.js +5 -0
  38. package/dist/esm/development/routing.js +1 -0
  39. package/dist/{development → esm/development}/server/react-client/index.js +5 -16
  40. package/dist/{development → esm/development}/server/react-server/RequestLocale.js +10 -14
  41. package/dist/{development → esm/development}/server/react-server/RequestLocaleCache.js +3 -8
  42. package/dist/esm/development/server/react-server/createRequestConfig.js +2 -0
  43. package/dist/esm/development/server/react-server/getConfig.js +53 -0
  44. package/dist/esm/development/server/react-server/getConfigNow.js +10 -0
  45. package/dist/esm/development/server/react-server/getDefaultNow.js +9 -0
  46. package/dist/esm/development/server/react-server/getFormats.js +10 -0
  47. package/dist/esm/development/server/react-server/getFormatter.js +21 -0
  48. package/dist/esm/development/server/react-server/getLocale.js +10 -0
  49. package/dist/esm/development/server/react-server/getMessages.js +19 -0
  50. package/dist/esm/development/server/react-server/getNow.js +8 -0
  51. package/dist/{development → esm/development}/server/react-server/getRequestConfig.js +1 -5
  52. package/dist/esm/development/server/react-server/getServerFormatter.js +21 -0
  53. package/dist/esm/development/server/react-server/getServerTranslator.js +12 -0
  54. package/dist/esm/development/server/react-server/getTimeZone.js +13 -0
  55. package/dist/{development → esm/development}/server/react-server/getTranslations.js +7 -15
  56. package/dist/esm/development/server.react-client.js +1 -0
  57. package/dist/esm/development/server.react-server.js +8 -0
  58. package/dist/esm/development/shared/NextIntlClientProvider.js +18 -0
  59. package/dist/esm/development/shared/constants.js +4 -0
  60. package/dist/esm/development/shared/use.js +13 -0
  61. package/dist/{development → esm/development}/shared/utils.js +6 -50
  62. package/dist/esm/production/index.react-client.js +1 -0
  63. package/dist/esm/production/middleware/getAlternateLinksHeaderValue.js +1 -0
  64. package/dist/esm/production/middleware/middleware.js +1 -0
  65. package/dist/esm/production/middleware/resolveLocale.js +1 -0
  66. package/dist/esm/production/middleware/syncCookie.js +1 -0
  67. package/dist/esm/production/middleware/utils.js +1 -0
  68. package/dist/esm/production/navigation/react-client/createNavigation.js +1 -0
  69. package/dist/esm/production/navigation/react-client/useBasePathname.js +1 -0
  70. package/dist/esm/production/navigation/react-server/createNavigation.js +1 -0
  71. package/dist/esm/production/navigation/shared/BaseLink.js +2 -0
  72. package/dist/esm/production/navigation/shared/createSharedNavigationFns.js +1 -0
  73. package/dist/esm/production/navigation/shared/syncLocaleCookie.js +1 -0
  74. package/dist/esm/production/navigation/shared/utils.js +1 -0
  75. package/dist/esm/production/navigation.react-client.js +1 -0
  76. package/dist/esm/production/navigation.react-server.js +1 -0
  77. package/dist/esm/production/plugin/createMessagesDeclaration.js +1 -0
  78. package/dist/esm/production/plugin/createNextIntlPlugin.js +1 -0
  79. package/dist/esm/production/plugin/getNextConfig.js +1 -0
  80. package/dist/esm/production/plugin/utils.js +1 -0
  81. package/dist/esm/production/plugin.js +1 -0
  82. package/dist/esm/production/react-client/index.js +1 -0
  83. package/dist/esm/production/react-server/NextIntlClientProviderServer.js +1 -0
  84. package/dist/esm/production/react-server/useConfig.js +1 -0
  85. package/dist/esm/production/react-server/useFormatter.js +1 -0
  86. package/dist/esm/production/react-server/useLocale.js +1 -0
  87. package/dist/esm/production/react-server/useMessages.js +1 -0
  88. package/dist/esm/production/react-server/useNow.js +1 -0
  89. package/dist/esm/production/react-server/useTimeZone.js +1 -0
  90. package/dist/esm/production/react-server/useTranslations.js +1 -0
  91. package/dist/esm/production/routing/config.js +1 -0
  92. package/dist/esm/production/server/react-client/index.js +1 -0
  93. package/dist/esm/production/server/react-server/RequestLocale.js +1 -0
  94. package/dist/esm/production/server/react-server/getConfig.js +1 -0
  95. package/dist/esm/production/server/react-server/getConfigNow.js +1 -0
  96. package/dist/esm/production/server/react-server/getDefaultNow.js +1 -0
  97. package/dist/esm/production/server/react-server/getFormats.js +1 -0
  98. package/dist/esm/production/server/react-server/getFormatter.js +1 -0
  99. package/dist/esm/production/server/react-server/getLocale.js +1 -0
  100. package/dist/esm/production/server/react-server/getMessages.js +1 -0
  101. package/dist/esm/production/server/react-server/getNow.js +1 -0
  102. package/dist/esm/production/server/react-server/getServerFormatter.js +1 -0
  103. package/dist/esm/{server → production/server}/react-server/getTimeZone.js +1 -1
  104. package/dist/esm/production/server/react-server/getTranslations.js +1 -0
  105. package/dist/esm/production/server.react-client.js +1 -0
  106. package/dist/esm/production/server.react-server.js +1 -0
  107. package/dist/esm/production/shared/NextIntlClientProvider.js +2 -0
  108. package/dist/esm/production/shared/constants.js +1 -0
  109. package/dist/esm/production/shared/use.js +1 -0
  110. package/dist/esm/production/shared/utils.js +1 -0
  111. package/dist/types/{src/index.react-client.d.ts → index.react-client.d.ts} +1 -1
  112. package/dist/types/index.react-server.d.ts +1 -0
  113. package/dist/types/{src/middleware → middleware}/getAlternateLinksHeaderValue.d.ts +3 -3
  114. package/dist/types/{src/middleware → middleware}/index.d.ts +1 -1
  115. package/dist/types/middleware/middleware.d.ts +4 -0
  116. package/dist/types/{src/middleware → middleware}/resolveLocale.d.ts +5 -4
  117. package/dist/types/middleware/syncCookie.d.ts +7 -0
  118. package/dist/types/{src/middleware → middleware}/utils.d.ts +4 -3
  119. package/dist/types/middleware.d.ts +1 -0
  120. package/dist/types/{src/navigation → navigation}/react-client/createNavigation.d.ts +58 -57
  121. package/dist/types/navigation/react-client/index.d.ts +2 -0
  122. package/dist/types/{src/navigation → navigation}/react-client/useBasePathname.d.ts +1 -1
  123. package/dist/types/{src/navigation → navigation}/react-server/createNavigation.d.ts +30 -30
  124. package/dist/types/navigation/react-server/index.d.ts +2 -0
  125. package/dist/types/navigation/shared/BaseLink.d.ts +19 -0
  126. package/dist/types/navigation/shared/createSharedNavigationFns.d.ts +386 -0
  127. package/dist/types/{src/navigation → navigation}/shared/syncLocaleCookie.d.ts +3 -2
  128. package/dist/types/{src/navigation → navigation}/shared/utils.d.ts +5 -4
  129. package/dist/types/navigation.react-client.d.ts +1 -0
  130. package/dist/types/navigation.react-server.d.ts +1 -0
  131. package/dist/types/plugin/createMessagesDeclaration.d.ts +1 -0
  132. package/dist/types/plugin/createNextIntlPlugin.d.ts +3 -0
  133. package/dist/types/plugin/getNextConfig.d.ts +3 -0
  134. package/dist/types/plugin/index.d.ts +1 -0
  135. package/dist/types/plugin/types.d.ts +6 -0
  136. package/dist/types/plugin/utils.d.ts +2 -0
  137. package/dist/types/plugin.d.ts +1 -0
  138. package/dist/types/{src/react-client → react-client}/index.d.ts +1 -2
  139. package/dist/types/react-server/NextIntlClientProviderServer.d.ts +5 -0
  140. package/dist/types/react-server/index.d.ts +15 -0
  141. package/dist/types/{src/react-server → react-server}/testUtils.d.ts +1 -1
  142. package/dist/types/{src/react-server → react-server}/useConfig.d.ts +1 -1
  143. package/dist/types/react-server/useFormatter.d.ts +2 -0
  144. package/dist/types/react-server/useLocale.d.ts +2 -0
  145. package/dist/types/react-server/useMessages.d.ts +2 -0
  146. package/dist/types/react-server/useNow.d.ts +2 -0
  147. package/dist/types/react-server/useTimeZone.d.ts +2 -0
  148. package/dist/types/{src/routing → routing}/config.d.ts +2 -4
  149. package/dist/types/{src/routing → routing}/defineRouting.d.ts +2 -2
  150. package/dist/types/routing/index.d.ts +3 -0
  151. package/dist/types/routing.d.ts +1 -0
  152. package/dist/types/{src/server → server}/react-client/index.d.ts +1 -2
  153. package/dist/types/server/react-server/RequestLocaleCache.d.ts +3 -0
  154. package/dist/types/{src/server → server}/react-server/createRequestConfig.d.ts +1 -1
  155. package/dist/types/{src/server → server}/react-server/getConfig.d.ts +2 -3
  156. package/dist/types/server/react-server/getConfigNow.d.ts +4 -0
  157. package/dist/types/server/react-server/getDefaultNow.d.ts +3 -0
  158. package/dist/types/server/react-server/getFormats.d.ts +3 -0
  159. package/dist/types/{src/server → server}/react-server/getFormatter.d.ts +2 -2
  160. package/dist/types/server/react-server/getLocale.d.ts +4 -0
  161. package/dist/types/server/react-server/getMessages.d.ts +6 -0
  162. package/dist/types/server/react-server/getNow.d.ts +4 -0
  163. package/dist/types/{src/server → server}/react-server/getRequestConfig.d.ts +2 -19
  164. package/dist/types/server/react-server/getServerFormatter.d.ts +10 -0
  165. package/dist/types/server/react-server/getServerTranslator.d.ts +4 -0
  166. package/dist/types/server/react-server/getTimeZone.d.ts +4 -0
  167. package/dist/types/server/react-server/getTranslations.d.ts +8 -0
  168. package/dist/types/server/react-server/index.d.ts +11 -0
  169. package/dist/types/server.react-client.d.ts +1 -0
  170. package/dist/types/server.react-server.d.ts +1 -0
  171. package/dist/types/{src/shared → shared}/NextIntlClientProvider.d.ts +5 -4
  172. package/dist/types/shared/constants.d.ts +1 -0
  173. package/dist/types/shared/use.d.ts +3 -0
  174. package/dist/types/{src/shared → shared}/utils.d.ts +3 -9
  175. package/middleware.d.ts +2 -1
  176. package/navigation.d.ts +2 -1
  177. package/package.json +57 -26
  178. package/plugin.d.cts +3 -0
  179. package/plugin.d.ts +3 -7
  180. package/routing.d.ts +2 -1
  181. package/server.d.ts +2 -1
  182. package/dist/config.js +0 -7
  183. package/dist/development/_virtual/_rollupPluginBabelHelpers.js +0 -15
  184. package/dist/development/index.react-client.js +0 -21
  185. package/dist/development/index.react-server.js +0 -28
  186. package/dist/development/middleware/middleware.js +0 -169
  187. package/dist/development/middleware/syncCookie.js +0 -20
  188. package/dist/development/middleware.js +0 -9
  189. package/dist/development/navigation/react-client/ClientLink.js +0 -55
  190. package/dist/development/navigation/react-client/createLocalizedPathnamesNavigation.js +0 -156
  191. package/dist/development/navigation/react-client/createSharedPathnamesNavigation.js +0 -67
  192. package/dist/development/navigation/react-client/redirects.js +0 -32
  193. package/dist/development/navigation/react-client/useBasePathname.js +0 -31
  194. package/dist/development/navigation/react-client/useBaseRouter.js +0 -72
  195. package/dist/development/navigation/react-server/ServerLink.js +0 -32
  196. package/dist/development/navigation/react-server/createLocalizedPathnamesNavigation.js +0 -95
  197. package/dist/development/navigation/react-server/createNavigation.js +0 -30
  198. package/dist/development/navigation/react-server/createSharedPathnamesNavigation.js +0 -56
  199. package/dist/development/navigation/react-server/getServerLocale.js +0 -16
  200. package/dist/development/navigation/react-server/redirects.js +0 -24
  201. package/dist/development/navigation/shared/LegacyBaseLink.js +0 -57
  202. package/dist/development/navigation/shared/redirects.js +0 -25
  203. package/dist/development/navigation.react-client.js +0 -13
  204. package/dist/development/navigation.react-server.js +0 -13
  205. package/dist/development/plugin.js +0 -101
  206. package/dist/development/react-client/index.js +0 -38
  207. package/dist/development/react-client/useLocale.js +0 -28
  208. package/dist/development/react-server/NextIntlClientProviderServer.js +0 -33
  209. package/dist/development/react-server/getTranslator.js +0 -16
  210. package/dist/development/react-server/useConfig.js +0 -25
  211. package/dist/development/react-server/useFormatter.js +0 -18
  212. package/dist/development/react-server/useLocale.js +0 -15
  213. package/dist/development/react-server/useMessages.js +0 -16
  214. package/dist/development/react-server/useNow.js +0 -19
  215. package/dist/development/react-server/useTimeZone.js +0 -15
  216. package/dist/development/react-server/useTranslations.js +0 -17
  217. package/dist/development/routing/config.js +0 -35
  218. package/dist/development/routing/defineRouting.js +0 -9
  219. package/dist/development/routing.js +0 -9
  220. package/dist/development/server/react-server/RequestLocaleLegacy.js +0 -43
  221. package/dist/development/server/react-server/createRequestConfig.js +0 -16
  222. package/dist/development/server/react-server/getConfig.js +0 -73
  223. package/dist/development/server/react-server/getFormatter.js +0 -25
  224. package/dist/development/server/react-server/getLocale.js +0 -14
  225. package/dist/development/server/react-server/getMessages.js +0 -24
  226. package/dist/development/server/react-server/getNow.js +0 -17
  227. package/dist/development/server/react-server/getTimeZone.js +0 -17
  228. package/dist/development/server.react-client.js +0 -17
  229. package/dist/development/server.react-server.js +0 -24
  230. package/dist/development/shared/NextIntlClientProvider.js +0 -30
  231. package/dist/development/shared/constants.js +0 -12
  232. package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +0 -1
  233. package/dist/esm/index.react-client.js +0 -1
  234. package/dist/esm/middleware/getAlternateLinksHeaderValue.js +0 -1
  235. package/dist/esm/middleware/middleware.js +0 -1
  236. package/dist/esm/middleware/resolveLocale.js +0 -1
  237. package/dist/esm/middleware/syncCookie.js +0 -1
  238. package/dist/esm/middleware/utils.js +0 -1
  239. package/dist/esm/navigation/react-client/ClientLink.js +0 -1
  240. package/dist/esm/navigation/react-client/createLocalizedPathnamesNavigation.js +0 -1
  241. package/dist/esm/navigation/react-client/createNavigation.js +0 -1
  242. package/dist/esm/navigation/react-client/createSharedPathnamesNavigation.js +0 -1
  243. package/dist/esm/navigation/react-client/redirects.js +0 -1
  244. package/dist/esm/navigation/react-client/useBasePathname.js +0 -1
  245. package/dist/esm/navigation/react-client/useBaseRouter.js +0 -1
  246. package/dist/esm/navigation/react-server/ServerLink.js +0 -1
  247. package/dist/esm/navigation/react-server/createLocalizedPathnamesNavigation.js +0 -1
  248. package/dist/esm/navigation/react-server/createNavigation.js +0 -1
  249. package/dist/esm/navigation/react-server/createSharedPathnamesNavigation.js +0 -1
  250. package/dist/esm/navigation/react-server/redirects.js +0 -1
  251. package/dist/esm/navigation/shared/BaseLink.js +0 -2
  252. package/dist/esm/navigation/shared/LegacyBaseLink.js +0 -2
  253. package/dist/esm/navigation/shared/createSharedNavigationFns.js +0 -1
  254. package/dist/esm/navigation/shared/redirects.js +0 -1
  255. package/dist/esm/navigation/shared/syncLocaleCookie.js +0 -1
  256. package/dist/esm/navigation/shared/utils.js +0 -1
  257. package/dist/esm/navigation.react-client.js +0 -1
  258. package/dist/esm/navigation.react-server.js +0 -1
  259. package/dist/esm/plugin.js +0 -1
  260. package/dist/esm/react-client/index.js +0 -1
  261. package/dist/esm/react-client/useLocale.js +0 -1
  262. package/dist/esm/react-server/NextIntlClientProviderServer.js +0 -1
  263. package/dist/esm/react-server/useConfig.js +0 -1
  264. package/dist/esm/react-server/useFormatter.js +0 -1
  265. package/dist/esm/react-server/useLocale.js +0 -1
  266. package/dist/esm/react-server/useMessages.js +0 -1
  267. package/dist/esm/react-server/useNow.js +0 -1
  268. package/dist/esm/react-server/useTimeZone.js +0 -1
  269. package/dist/esm/react-server/useTranslations.js +0 -1
  270. package/dist/esm/routing/config.js +0 -1
  271. package/dist/esm/server/react-client/index.js +0 -1
  272. package/dist/esm/server/react-server/RequestLocale.js +0 -1
  273. package/dist/esm/server/react-server/RequestLocaleLegacy.js +0 -1
  274. package/dist/esm/server/react-server/getConfig.js +0 -1
  275. package/dist/esm/server/react-server/getFormatter.js +0 -1
  276. package/dist/esm/server/react-server/getLocale.js +0 -1
  277. package/dist/esm/server/react-server/getMessages.js +0 -1
  278. package/dist/esm/server/react-server/getNow.js +0 -1
  279. package/dist/esm/server/react-server/getTranslations.js +0 -1
  280. package/dist/esm/server.react-client.js +0 -1
  281. package/dist/esm/server.react-server.js +0 -1
  282. package/dist/esm/shared/NextIntlClientProvider.js +0 -2
  283. package/dist/esm/shared/constants.js +0 -1
  284. package/dist/esm/shared/utils.js +0 -1
  285. package/dist/index.react-client.js +0 -7
  286. package/dist/index.react-server.js +0 -7
  287. package/dist/middleware.js +0 -7
  288. package/dist/navigation.react-client.js +0 -7
  289. package/dist/navigation.react-server.js +0 -7
  290. package/dist/plugin.js +0 -7
  291. package/dist/production/_virtual/_rollupPluginBabelHelpers.js +0 -1
  292. package/dist/production/config.js +0 -1
  293. package/dist/production/index.react-client.js +0 -1
  294. package/dist/production/index.react-server.js +0 -1
  295. package/dist/production/middleware/getAlternateLinksHeaderValue.js +0 -1
  296. package/dist/production/middleware/middleware.js +0 -1
  297. package/dist/production/middleware/resolveLocale.js +0 -1
  298. package/dist/production/middleware/syncCookie.js +0 -1
  299. package/dist/production/middleware/utils.js +0 -1
  300. package/dist/production/middleware.js +0 -1
  301. package/dist/production/navigation/react-client/ClientLink.js +0 -1
  302. package/dist/production/navigation/react-client/createLocalizedPathnamesNavigation.js +0 -1
  303. package/dist/production/navigation/react-client/createNavigation.js +0 -1
  304. package/dist/production/navigation/react-client/createSharedPathnamesNavigation.js +0 -1
  305. package/dist/production/navigation/react-client/redirects.js +0 -1
  306. package/dist/production/navigation/react-client/useBasePathname.js +0 -1
  307. package/dist/production/navigation/react-client/useBaseRouter.js +0 -1
  308. package/dist/production/navigation/react-server/ServerLink.js +0 -1
  309. package/dist/production/navigation/react-server/createLocalizedPathnamesNavigation.js +0 -1
  310. package/dist/production/navigation/react-server/createNavigation.js +0 -1
  311. package/dist/production/navigation/react-server/createSharedPathnamesNavigation.js +0 -1
  312. package/dist/production/navigation/react-server/getServerLocale.js +0 -1
  313. package/dist/production/navigation/react-server/redirects.js +0 -1
  314. package/dist/production/navigation/shared/BaseLink.js +0 -2
  315. package/dist/production/navigation/shared/LegacyBaseLink.js +0 -2
  316. package/dist/production/navigation/shared/createSharedNavigationFns.js +0 -1
  317. package/dist/production/navigation/shared/redirects.js +0 -1
  318. package/dist/production/navigation/shared/syncLocaleCookie.js +0 -1
  319. package/dist/production/navigation/shared/utils.js +0 -1
  320. package/dist/production/navigation.react-client.js +0 -1
  321. package/dist/production/navigation.react-server.js +0 -1
  322. package/dist/production/plugin.js +0 -1
  323. package/dist/production/react-client/index.js +0 -1
  324. package/dist/production/react-client/useLocale.js +0 -1
  325. package/dist/production/react-server/NextIntlClientProviderServer.js +0 -1
  326. package/dist/production/react-server/getTranslator.js +0 -1
  327. package/dist/production/react-server/useConfig.js +0 -1
  328. package/dist/production/react-server/useFormatter.js +0 -1
  329. package/dist/production/react-server/useLocale.js +0 -1
  330. package/dist/production/react-server/useMessages.js +0 -1
  331. package/dist/production/react-server/useNow.js +0 -1
  332. package/dist/production/react-server/useTimeZone.js +0 -1
  333. package/dist/production/react-server/useTranslations.js +0 -1
  334. package/dist/production/routing/config.js +0 -1
  335. package/dist/production/routing/defineRouting.js +0 -1
  336. package/dist/production/routing.js +0 -1
  337. package/dist/production/server/react-client/index.js +0 -1
  338. package/dist/production/server/react-server/RequestLocale.js +0 -1
  339. package/dist/production/server/react-server/RequestLocaleCache.js +0 -1
  340. package/dist/production/server/react-server/RequestLocaleLegacy.js +0 -1
  341. package/dist/production/server/react-server/createRequestConfig.js +0 -1
  342. package/dist/production/server/react-server/getConfig.js +0 -1
  343. package/dist/production/server/react-server/getFormatter.js +0 -1
  344. package/dist/production/server/react-server/getLocale.js +0 -1
  345. package/dist/production/server/react-server/getMessages.js +0 -1
  346. package/dist/production/server/react-server/getNow.js +0 -1
  347. package/dist/production/server/react-server/getRequestConfig.js +0 -1
  348. package/dist/production/server/react-server/getTimeZone.js +0 -1
  349. package/dist/production/server/react-server/getTranslations.js +0 -1
  350. package/dist/production/server.react-client.js +0 -1
  351. package/dist/production/server.react-server.js +0 -1
  352. package/dist/production/shared/NextIntlClientProvider.js +0 -2
  353. package/dist/production/shared/constants.js +0 -1
  354. package/dist/production/shared/utils.js +0 -1
  355. package/dist/routing.js +0 -7
  356. package/dist/server.react-client.js +0 -7
  357. package/dist/server.react-server.js +0 -7
  358. package/dist/types/__mocks__/react.d.ts +0 -9
  359. package/dist/types/src/index.react-server.d.ts +0 -1
  360. package/dist/types/src/middleware/getAlternateLinksHeaderValue.test.d.ts +0 -1
  361. package/dist/types/src/middleware/middleware.d.ts +0 -13
  362. package/dist/types/src/middleware/middleware.test.d.ts +0 -1
  363. package/dist/types/src/middleware/resolveLocale.test.d.ts +0 -1
  364. package/dist/types/src/middleware/syncCookie.d.ts +0 -3
  365. package/dist/types/src/middleware/utils.test.d.ts +0 -1
  366. package/dist/types/src/middleware.d.ts +0 -1
  367. package/dist/types/src/navigation/createLocalizedPathnamesNavigation.test.d.ts +0 -1
  368. package/dist/types/src/navigation/createNavigation.test.d.ts +0 -1
  369. package/dist/types/src/navigation/createSharedPathnamesNavigation.test.d.ts +0 -1
  370. package/dist/types/src/navigation/react-client/ClientLink.d.ts +0 -31
  371. package/dist/types/src/navigation/react-client/ClientLink.test.d.ts +0 -1
  372. package/dist/types/src/navigation/react-client/createLocalizedPathnamesNavigation.d.ts +0 -91
  373. package/dist/types/src/navigation/react-client/createLocalizedPathnamesNavigation.test.d.ts +0 -1
  374. package/dist/types/src/navigation/react-client/createNavigation.test.d.ts +0 -1
  375. package/dist/types/src/navigation/react-client/createSharedPathnamesNavigation.d.ts +0 -66
  376. package/dist/types/src/navigation/react-client/createSharedPathnamesNavigation.test.d.ts +0 -1
  377. package/dist/types/src/navigation/react-client/index.d.ts +0 -7
  378. package/dist/types/src/navigation/react-client/redirects.d.ts +0 -10
  379. package/dist/types/src/navigation/react-client/useBasePathname.test.d.ts +0 -1
  380. package/dist/types/src/navigation/react-client/useBaseRouter.d.ts +0 -33
  381. package/dist/types/src/navigation/react-client/useBaseRouter.test.d.ts +0 -1
  382. package/dist/types/src/navigation/react-server/ServerLink.d.ts +0 -9
  383. package/dist/types/src/navigation/react-server/createLocalizedPathnamesNavigation.d.ts +0 -70
  384. package/dist/types/src/navigation/react-server/createNavigation.test.d.ts +0 -1
  385. package/dist/types/src/navigation/react-server/createSharedPathnamesNavigation.d.ts +0 -11
  386. package/dist/types/src/navigation/react-server/index.d.ts +0 -4
  387. package/dist/types/src/navigation/react-server/redirects.d.ts +0 -10
  388. package/dist/types/src/navigation/shared/BaseLink.d.ts +0 -17
  389. package/dist/types/src/navigation/shared/LegacyBaseLink.d.ts +0 -12
  390. package/dist/types/src/navigation/shared/createSharedNavigationFns.d.ts +0 -386
  391. package/dist/types/src/navigation/shared/redirects.d.ts +0 -11
  392. package/dist/types/src/navigation/shared/redirects.test.d.ts +0 -1
  393. package/dist/types/src/navigation/shared/utils.test.d.ts +0 -1
  394. package/dist/types/src/navigation.react-client.d.ts +0 -1
  395. package/dist/types/src/navigation.react-server.d.ts +0 -1
  396. package/dist/types/src/plugin.d.ts +0 -1
  397. package/dist/types/src/react-client/useFormatter.test.d.ts +0 -1
  398. package/dist/types/src/react-client/useLocale.d.ts +0 -1
  399. package/dist/types/src/react-client/useLocale.test.d.ts +0 -1
  400. package/dist/types/src/react-client/useNow.test.d.ts +0 -1
  401. package/dist/types/src/react-client/useTimeZone.test.d.ts +0 -1
  402. package/dist/types/src/react-client/useTranslations.test.d.ts +0 -1
  403. package/dist/types/src/react-server/NextIntlClientProviderServer.d.ts +0 -5
  404. package/dist/types/src/react-server/NextIntlClientProviderServer.test.d.ts +0 -1
  405. package/dist/types/src/react-server/getTranslator.d.ts +0 -51
  406. package/dist/types/src/react-server/index.d.ts +0 -15
  407. package/dist/types/src/react-server/index.test.d.ts +0 -1
  408. package/dist/types/src/react-server/useFormatter.d.ts +0 -2
  409. package/dist/types/src/react-server/useLocale.d.ts +0 -2
  410. package/dist/types/src/react-server/useMessages.d.ts +0 -2
  411. package/dist/types/src/react-server/useNow.d.ts +0 -2
  412. package/dist/types/src/react-server/useTimeZone.d.ts +0 -2
  413. package/dist/types/src/react-server/useTranslations.test.d.ts +0 -1
  414. package/dist/types/src/routing/defineRouting.test.d.ts +0 -1
  415. package/dist/types/src/routing/index.d.ts +0 -3
  416. package/dist/types/src/routing/types.test.d.ts +0 -1
  417. package/dist/types/src/routing.d.ts +0 -1
  418. package/dist/types/src/server/react-client/index.test.d.ts +0 -1
  419. package/dist/types/src/server/react-server/RequestLocaleCache.d.ts +0 -2
  420. package/dist/types/src/server/react-server/RequestLocaleLegacy.d.ts +0 -1
  421. package/dist/types/src/server/react-server/getLocale.d.ts +0 -3
  422. package/dist/types/src/server/react-server/getMessages.d.ts +0 -6
  423. package/dist/types/src/server/react-server/getNow.d.ts +0 -3
  424. package/dist/types/src/server/react-server/getTimeZone.d.ts +0 -3
  425. package/dist/types/src/server/react-server/getTranslations.d.ts +0 -92
  426. package/dist/types/src/server/react-server/index.d.ts +0 -14
  427. package/dist/types/src/server/react-server/index.test.d.ts +0 -1
  428. package/dist/types/src/server.react-client.d.ts +0 -1
  429. package/dist/types/src/server.react-server.d.ts +0 -1
  430. package/dist/types/src/shared/NextIntlClientProvider.test.d.ts +0 -1
  431. package/dist/types/src/shared/constants.d.ts +0 -3
  432. package/dist/types/src/shared/utils.test.d.ts +0 -1
  433. package/dist/types/test/setup.d.ts +0 -1
  434. /package/dist/esm/{config.js → production/config.js} +0 -0
  435. /package/dist/esm/{index.react-server.js → production/index.react-server.js} +0 -0
  436. /package/dist/esm/{middleware.js → production/middleware.js} +0 -0
  437. /package/dist/esm/{navigation → production/navigation}/react-server/getServerLocale.js +0 -0
  438. /package/dist/esm/{routing → production/routing}/defineRouting.js +0 -0
  439. /package/dist/esm/{routing.js → production/routing.js} +0 -0
  440. /package/dist/esm/{server → production/server}/react-server/RequestLocaleCache.js +0 -0
  441. /package/dist/esm/{server → production/server}/react-server/createRequestConfig.js +0 -0
  442. /package/dist/esm/{server → production/server}/react-server/getRequestConfig.js +0 -0
  443. /package/dist/esm/{react-server/getTranslator.js → production/server/react-server/getServerTranslator.js} +0 -0
  444. /package/dist/types/{src/config.d.ts → config.d.ts} +0 -0
  445. /package/dist/types/{src/navigation → navigation}/react-server/getServerLocale.d.ts +0 -0
  446. /package/dist/types/{src/navigation → navigation}/shared/StrictParams.d.ts +0 -0
  447. /package/dist/types/{src/react-server → react-server}/useTranslations.d.ts +0 -0
  448. /package/dist/types/{src/routing → routing}/types.d.ts +0 -0
  449. /package/dist/types/{src/server → server}/react-server/RequestLocale.d.ts +0 -0
  450. /package/dist/types/{src/shared → shared}/types.d.ts +0 -0
@@ -1,33 +1,26 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var utils = require('../shared/utils.js');
1
+ import { getSortedPathnames, matchesPathname, normalizeTrailingSlash, getLocalePrefix, templateToRegex, prefixPathname } from '../shared/utils.js';
6
2
 
7
3
  function getInternalTemplate(pathnames, pathname, locale) {
8
- const sortedPathnames = utils.getSortedPathnames(Object.keys(pathnames));
4
+ const sortedPathnames = getSortedPathnames(Object.keys(pathnames));
9
5
 
10
6
  // Try to find a localized pathname that matches
11
7
  for (const internalPathname of sortedPathnames) {
12
8
  const localizedPathnamesOrPathname = pathnames[internalPathname];
13
9
  if (typeof localizedPathnamesOrPathname === 'string') {
14
10
  const localizedPathname = localizedPathnamesOrPathname;
15
- if (utils.matchesPathname(localizedPathname, pathname)) {
11
+ if (matchesPathname(localizedPathname, pathname)) {
16
12
  return [undefined, internalPathname];
17
13
  }
18
14
  } else {
19
15
  // Prefer the entry with the current locale in case multiple
20
16
  // localized pathnames match the current pathname
21
17
  const sortedEntries = Object.entries(localizedPathnamesOrPathname);
22
- const curLocaleIndex = sortedEntries.findIndex(_ref => {
23
- let [entryLocale] = _ref;
24
- return entryLocale === locale;
25
- });
18
+ const curLocaleIndex = sortedEntries.findIndex(([entryLocale]) => entryLocale === locale);
26
19
  if (curLocaleIndex > 0) {
27
20
  sortedEntries.unshift(sortedEntries.splice(curLocaleIndex, 1)[0]);
28
21
  }
29
22
  for (const [entryLocale, entryPathname] of sortedEntries) {
30
- if (utils.matchesPathname(entryPathname, pathname)) {
23
+ if (matchesPathname(entryPathname, pathname)) {
31
24
  return [entryLocale, internalPathname];
32
25
  }
33
26
  }
@@ -37,7 +30,7 @@ function getInternalTemplate(pathnames, pathname, locale) {
37
30
  // Try to find an internal pathname that matches (this can be the case
38
31
  // if all localized pathnames are different from the internal pathnames)
39
32
  for (const internalPathname of Object.keys(pathnames)) {
40
- if (utils.matchesPathname(internalPathname, pathname)) {
33
+ if (matchesPathname(internalPathname, pathname)) {
41
34
  return [undefined, internalPathname];
42
35
  }
43
36
  }
@@ -53,7 +46,7 @@ function formatTemplatePathname(sourcePathname, sourceTemplate, targetTemplate,
53
46
  // A pathname with an optional catchall like `/categories/[[...slug]]`
54
47
  // should be normalized to `/categories` if the catchall is not present
55
48
  // and no trailing slash is configured
56
- targetPathname = utils.normalizeTrailingSlash(targetPathname);
49
+ targetPathname = normalizeTrailingSlash(targetPathname);
57
50
  return targetPathname;
58
51
  }
59
52
 
@@ -67,20 +60,16 @@ function getNormalizedPathname(pathname, locales, localePrefix) {
67
60
  pathname += '/';
68
61
  }
69
62
  const localePrefixes = getLocalePrefixes(locales, localePrefix);
70
- const regex = new RegExp("^(".concat(localePrefixes.map(_ref2 => {
71
- let [, prefix] = _ref2;
72
- return prefix.replaceAll('/', '\\/');
73
- }).join('|'), ")/(.*)"), 'i');
63
+ const regex = new RegExp(`^(${localePrefixes.map(([, prefix]) => prefix.replaceAll('/', '\\/')).join('|')})/(.*)`, 'i');
74
64
  const match = pathname.match(regex);
75
65
  let result = match ? '/' + match[2] : pathname;
76
66
  if (result !== '/') {
77
- result = utils.normalizeTrailingSlash(result);
67
+ result = normalizeTrailingSlash(result);
78
68
  }
79
69
  return result;
80
70
  }
81
- function getLocalePrefixes(locales, localePrefix) {
82
- let sort = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
83
- const prefixes = locales.map(locale => [locale, utils.getLocalePrefix(locale, localePrefix)]);
71
+ function getLocalePrefixes(locales, localePrefix, sort = true) {
72
+ const prefixes = locales.map(locale => [locale, getLocalePrefix(locale, localePrefix)]);
84
73
  if (sort) {
85
74
  // More specific ones first
86
75
  prefixes.sort((a, b) => b[1].length - a[1].length);
@@ -112,15 +101,14 @@ function getPathnameMatch(pathname, locales, localePrefix) {
112
101
  }
113
102
  }
114
103
  function getRouteParams(template, pathname) {
115
- const normalizedPathname = utils.normalizeTrailingSlash(pathname);
116
- const normalizedTemplate = utils.normalizeTrailingSlash(template);
117
- const regex = utils.templateToRegex(normalizedTemplate);
104
+ const normalizedPathname = normalizeTrailingSlash(pathname);
105
+ const normalizedTemplate = normalizeTrailingSlash(template);
106
+ const regex = templateToRegex(normalizedTemplate);
118
107
  const match = regex.exec(normalizedPathname);
119
108
  if (!match) return undefined;
120
109
  const params = {};
121
110
  for (let i = 1; i < match.length; i++) {
122
- var _normalizedTemplate$m;
123
- const key = (_normalizedTemplate$m = normalizedTemplate.match(/\[([^\]]+)\]/g)) === null || _normalizedTemplate$m === void 0 ? void 0 : _normalizedTemplate$m[i - 1].replace(/[[\]]/g, '');
111
+ const key = normalizedTemplate.match(/\[([^\]]+)\]/g)?.[i - 1].replace(/[[\]]/g, '');
124
112
  if (key) params[key] = match[i];
125
113
  }
126
114
  return params;
@@ -132,16 +120,15 @@ function formatPathnameTemplate(template, params) {
132
120
  // we can replace the value with simple interpolation
133
121
  template = template.replace(/\[\[/g, '[').replace(/\]\]/g, ']');
134
122
  let result = template;
135
- Object.entries(params).forEach(_ref3 => {
136
- let [key, value] = _ref3;
137
- result = result.replace("[".concat(key, "]"), value);
123
+ Object.entries(params).forEach(([key, value]) => {
124
+ result = result.replace(`[${key}]`, value);
138
125
  });
139
126
  return result;
140
127
  }
141
128
  function formatPathname(pathname, prefix, search) {
142
129
  let result = pathname;
143
130
  if (prefix) {
144
- result = utils.prefixPathname(prefix, result);
131
+ result = prefixPathname(prefix, result);
145
132
  }
146
133
  if (search) {
147
134
  result += search;
@@ -149,8 +136,7 @@ function formatPathname(pathname, prefix, search) {
149
136
  return result;
150
137
  }
151
138
  function getHost(requestHeaders) {
152
- var _ref4, _requestHeaders$get;
153
- return (_ref4 = (_requestHeaders$get = requestHeaders.get('x-forwarded-host')) !== null && _requestHeaders$get !== void 0 ? _requestHeaders$get : requestHeaders.get('host')) !== null && _ref4 !== void 0 ? _ref4 : undefined;
139
+ return requestHeaders.get('x-forwarded-host') ?? requestHeaders.get('host') ?? undefined;
154
140
  }
155
141
  function isLocaleSupportedOnDomain(locale, domain) {
156
142
  return domain.defaultLocale === locale || !domain.locales || domain.locales.includes(locale);
@@ -170,14 +156,11 @@ function getBestMatchingDomain(curHostDomain, locale, domainsConfig) {
170
156
 
171
157
  // Prio 3: Use alternative domain with restricted matching locale
172
158
  if (!domainConfig) {
173
- domainConfig = domainsConfig.find(cur => {
174
- var _cur$locales;
175
- return (_cur$locales = cur.locales) === null || _cur$locales === void 0 ? void 0 : _cur$locales.includes(locale);
176
- });
159
+ domainConfig = domainsConfig.find(cur => cur.locales?.includes(locale));
177
160
  }
178
161
 
179
162
  // Prio 4: Stay on the current domain if it supports all locales
180
- if (!domainConfig && (curHostDomain === null || curHostDomain === void 0 ? void 0 : curHostDomain.locales) == null) {
163
+ if (!domainConfig && curHostDomain?.locales == null) {
181
164
  domainConfig = curHostDomain;
182
165
  }
183
166
 
@@ -188,10 +171,10 @@ function getBestMatchingDomain(curHostDomain, locale, domainsConfig) {
188
171
  return domainConfig;
189
172
  }
190
173
  function applyBasePath(pathname, basePath) {
191
- return utils.normalizeTrailingSlash(basePath + pathname);
174
+ return normalizeTrailingSlash(basePath + pathname);
192
175
  }
193
176
  function getLocaleAsPrefix(locale) {
194
- return "/".concat(locale);
177
+ return `/${locale}`;
195
178
  }
196
179
  function sanitizePathname(pathname) {
197
180
  // Sanitize malicious URIs, e.g.:
@@ -200,17 +183,4 @@ function sanitizePathname(pathname) {
200
183
  return pathname.replace(/\\/g, '%5C').replace(/\/+/g, '/');
201
184
  }
202
185
 
203
- exports.applyBasePath = applyBasePath;
204
- exports.formatPathname = formatPathname;
205
- exports.formatPathnameTemplate = formatPathnameTemplate;
206
- exports.formatTemplatePathname = formatTemplatePathname;
207
- exports.getBestMatchingDomain = getBestMatchingDomain;
208
- exports.getHost = getHost;
209
- exports.getInternalTemplate = getInternalTemplate;
210
- exports.getLocaleAsPrefix = getLocaleAsPrefix;
211
- exports.getLocalePrefixes = getLocalePrefixes;
212
- exports.getNormalizedPathname = getNormalizedPathname;
213
- exports.getPathnameMatch = getPathnameMatch;
214
- exports.getRouteParams = getRouteParams;
215
- exports.isLocaleSupportedOnDomain = isLocaleSupportedOnDomain;
216
- exports.sanitizePathname = sanitizePathname;
186
+ export { applyBasePath, formatPathname, formatPathnameTemplate, formatTemplatePathname, getBestMatchingDomain, getHost, getInternalTemplate, getLocaleAsPrefix, getLocalePrefixes, getNormalizedPathname, getPathnameMatch, getRouteParams, isLocaleSupportedOnDomain, sanitizePathname };
@@ -0,0 +1 @@
1
+ export { default } from './middleware/middleware.js';
@@ -1,43 +1,36 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var navigation = require('next/navigation');
6
- var React = require('react');
7
- var useLocale = require('../../react-client/useLocale.js');
8
- var createSharedNavigationFns = require('../shared/createSharedNavigationFns.js');
9
- var syncLocaleCookie = require('../shared/syncLocaleCookie.js');
10
- var utils = require('../shared/utils.js');
11
- var useBasePathname = require('./useBasePathname.js');
1
+ import { useRouter, usePathname } from 'next/navigation.js';
2
+ import { useMemo } from 'react';
3
+ import { useLocale } from 'use-intl';
4
+ import createSharedNavigationFns from '../shared/createSharedNavigationFns.js';
5
+ import syncLocaleCookie from '../shared/syncLocaleCookie.js';
6
+ import { getRoute } from '../shared/utils.js';
7
+ import useBasePathname from './useBasePathname.js';
12
8
 
13
9
  function createNavigation(routing) {
14
- function useTypedLocale() {
15
- return useLocale.default();
16
- }
17
10
  const {
18
11
  Link,
19
12
  config,
20
13
  getPathname,
21
14
  ...redirects
22
- } = createSharedNavigationFns.default(useTypedLocale, routing);
15
+ } = createSharedNavigationFns(useLocale, routing);
23
16
 
24
17
  /** @see https://next-intl-docs.vercel.app/docs/routing/navigation#usepathname */
25
- function usePathname() {
26
- const pathname = useBasePathname.default(config.localePrefix);
27
- const locale = useTypedLocale();
18
+ function usePathname$1() {
19
+ const pathname = useBasePathname(config.localePrefix);
20
+ const locale = useLocale();
28
21
 
29
22
  // @ts-expect-error -- Mirror the behavior from Next.js, where `null` is returned when `usePathname` is used outside of Next, but the types indicate that a string is always returned.
30
- return React.useMemo(() => pathname &&
23
+ return useMemo(() => pathname &&
31
24
  // @ts-expect-error -- This is fine
32
- config.pathnames ? utils.getRoute(locale, pathname,
25
+ config.pathnames ? getRoute(locale, pathname,
33
26
  // @ts-expect-error -- This is fine
34
27
  config.pathnames) : pathname, [locale, pathname]);
35
28
  }
36
- function useRouter() {
37
- const router = navigation.useRouter();
38
- const curLocale = useTypedLocale();
39
- const nextPathname = navigation.usePathname();
40
- return React.useMemo(() => {
29
+ function useRouter$1() {
30
+ const router = useRouter();
31
+ const curLocale = useLocale();
32
+ const nextPathname = usePathname();
33
+ return useMemo(() => {
41
34
  function createHandler(fn) {
42
35
  return function handler(href, options) {
43
36
  const {
@@ -57,7 +50,7 @@ function createNavigation(routing) {
57
50
  args.push(rest);
58
51
  }
59
52
  fn(...args);
60
- syncLocaleCookie.default(config.localeCookie, nextPathname, curLocale, nextLocale);
53
+ syncLocaleCookie(config.localeCookie, nextPathname, curLocale, nextLocale);
61
54
  };
62
55
  }
63
56
  return {
@@ -74,10 +67,10 @@ function createNavigation(routing) {
74
67
  return {
75
68
  ...redirects,
76
69
  Link,
77
- usePathname,
78
- useRouter,
70
+ usePathname: usePathname$1,
71
+ useRouter: useRouter$1,
79
72
  getPathname
80
73
  };
81
74
  }
82
75
 
83
- exports.default = createNavigation;
76
+ export { createNavigation as default };
@@ -0,0 +1,27 @@
1
+ import { usePathname } from 'next/navigation.js';
2
+ import { useMemo } from 'react';
3
+ import { useLocale } from 'use-intl';
4
+ import { hasPathnamePrefixed, unprefixPathname, getLocalePrefix } from '../../shared/utils.js';
5
+
6
+ function useBasePathname(localePrefix) {
7
+ // The types aren't entirely correct here. Outside of Next.js
8
+ // `useParams` can be called, but the return type is `null`.
9
+
10
+ // Notes on `useNextPathname`:
11
+ // - Types aren't entirely correct. Outside of Next.js the
12
+ // hook will return `null` (e.g. unit tests)
13
+ // - A base path is stripped from the result
14
+ // - Rewrites *are* taken into account (i.e. the pathname
15
+ // that the user sees in the browser is returned)
16
+ const pathname = usePathname();
17
+ const locale = useLocale();
18
+ return useMemo(() => {
19
+ if (!pathname) return pathname;
20
+ const prefix = getLocalePrefix(locale, localePrefix);
21
+ const isPathnamePrefixed = hasPathnamePrefixed(prefix, pathname);
22
+ const unlocalizedPathname = isPathnamePrefixed ? unprefixPathname(pathname, prefix) : pathname;
23
+ return unlocalizedPathname;
24
+ }, [locale, localePrefix, pathname]);
25
+ }
26
+
27
+ export { useBasePathname as default };
@@ -0,0 +1,22 @@
1
+ import createSharedNavigationFns from '../shared/createSharedNavigationFns.js';
2
+ import getServerLocale from './getServerLocale.js';
3
+
4
+ function createNavigation(routing) {
5
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
+ const {
7
+ config,
8
+ ...fns
9
+ } = createSharedNavigationFns(getServerLocale, routing);
10
+ function notSupported(hookName) {
11
+ return () => {
12
+ throw new Error(`\`${hookName}\` is not supported in Server Components. You can use this hook if you convert the calling component to a Client Component.`);
13
+ };
14
+ }
15
+ return {
16
+ ...fns,
17
+ usePathname: notSupported('usePathname'),
18
+ useRouter: notSupported('useRouter')
19
+ };
20
+ }
21
+
22
+ export { createNavigation as default };
@@ -0,0 +1,12 @@
1
+ import getConfig from '../../server/react-server/getConfig.js';
2
+
3
+ /**
4
+ * This is only moved to a separate module for easier mocking in
5
+ * `../createNavigatoin.test.tsx` in order to avoid suspending.
6
+ */
7
+ async function getServerLocale() {
8
+ const config = await getConfig();
9
+ return config.locale;
10
+ }
11
+
12
+ export { getServerLocale as default };
@@ -1,32 +1,22 @@
1
1
  "use client";
2
- 'use strict';
2
+ import NextLink from 'next/link.js';
3
+ import { usePathname } from 'next/navigation.js';
4
+ import { forwardRef, useState, useEffect } from 'react';
5
+ import { useLocale } from 'use-intl';
6
+ import syncLocaleCookie from './syncLocaleCookie.js';
7
+ import { jsx } from 'react/jsx-runtime';
3
8
 
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
7
- var NextLink = require('next/link');
8
- var navigation = require('next/navigation');
9
- var React = require('react');
10
- var useLocale = require('../../react-client/useLocale.js');
11
- var syncLocaleCookie = require('./syncLocaleCookie.js');
12
-
13
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
-
15
- var NextLink__default = /*#__PURE__*/_interopDefault(NextLink);
16
- var React__default = /*#__PURE__*/_interopDefault(React);
17
-
18
- function BaseLink(_ref, ref) {
19
- let {
20
- defaultLocale,
21
- href,
22
- locale,
23
- localeCookie,
24
- onClick,
25
- prefetch,
26
- unprefixed,
27
- ...rest
28
- } = _ref;
29
- const curLocale = useLocale.default();
9
+ function BaseLink({
10
+ defaultLocale,
11
+ href,
12
+ locale,
13
+ localeCookie,
14
+ onClick,
15
+ prefetch,
16
+ unprefixed,
17
+ ...rest
18
+ }, ref) {
19
+ const curLocale = useLocale();
30
20
  const isChangingLocale = locale != null && locale !== curLocale;
31
21
  const linkLocale = locale || curLocale;
32
22
  const host = useHost();
@@ -44,9 +34,9 @@ function BaseLink(_ref, ref) {
44
34
 
45
35
  // The types aren't entirely correct here. Outside of Next.js
46
36
  // `useParams` can be called, but the return type is `null`.
47
- const pathname = navigation.usePathname();
37
+ const pathname = usePathname();
48
38
  function onLinkClick(event) {
49
- syncLocaleCookie.default(localeCookie, pathname, curLocale, locale);
39
+ syncLocaleCookie(localeCookie, pathname, curLocale, locale);
50
40
  if (onClick) onClick(event);
51
41
  }
52
42
  if (isChangingLocale) {
@@ -55,21 +45,26 @@ function BaseLink(_ref, ref) {
55
45
  }
56
46
  prefetch = false;
57
47
  }
58
- return /*#__PURE__*/React__default.default.createElement(NextLink__default.default, _rollupPluginBabelHelpers.extends({
48
+
49
+ // Somehow the types for `next/link` don't work as expected
50
+ // when `moduleResolution: "nodenext"` is used.
51
+ const Link = NextLink;
52
+ return /*#__PURE__*/jsx(Link, {
59
53
  ref: ref,
60
54
  href: finalHref,
61
55
  hrefLang: isChangingLocale ? locale : undefined,
62
56
  onClick: onLinkClick,
63
- prefetch: prefetch
64
- }, rest));
57
+ prefetch: prefetch,
58
+ ...rest
59
+ });
65
60
  }
66
61
  function useHost() {
67
- const [host, setHost] = React.useState();
68
- React.useEffect(() => {
62
+ const [host, setHost] = useState();
63
+ useEffect(() => {
69
64
  setHost(window.location.host);
70
65
  }, []);
71
66
  return host;
72
67
  }
73
- var BaseLink$1 = /*#__PURE__*/React.forwardRef(BaseLink);
68
+ var BaseLink$1 = /*#__PURE__*/forwardRef(BaseLink);
74
69
 
75
- exports.default = BaseLink$1;
70
+ export { BaseLink$1 as default };
@@ -1,28 +1,21 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
6
- var navigation = require('next/navigation');
7
- var React = require('react');
8
- var config = require('../../routing/config.js');
9
- var utils$1 = require('../../shared/utils.js');
10
- var BaseLink = require('./BaseLink.js');
11
- var utils = require('./utils.js');
12
-
13
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
-
15
- var React__default = /*#__PURE__*/_interopDefault(React);
1
+ import { redirect, permanentRedirect } from 'next/navigation.js';
2
+ import { forwardRef } from 'react';
3
+ import { receiveRoutingConfig } from '../../routing/config.js';
4
+ import use from '../../shared/use.js';
5
+ import { isLocalizableHref } from '../../shared/utils.js';
6
+ import BaseLink from './BaseLink.js';
7
+ import { validateReceivedConfig, serializeSearchParams, compileLocalizedPathname, applyPathnamePrefix, normalizeNameOrNameWithParams } from './utils.js';
8
+ import { jsx } from 'react/jsx-runtime';
16
9
 
17
10
  /**
18
11
  * Shared implementations for `react-server` and `react-client`
19
12
  */
20
13
  function createSharedNavigationFns(getLocale, routing) {
21
- const config$1 = config.receiveRoutingConfig(routing || {});
14
+ const config = receiveRoutingConfig(routing || {});
22
15
  {
23
- utils.validateReceivedConfig(config$1);
16
+ validateReceivedConfig(config);
24
17
  }
25
- const pathnames = config$1.pathnames;
18
+ const pathnames = config.pathnames;
26
19
 
27
20
  // This combination requires that the current host is known in order to
28
21
  // compute a correct pathname. Since that can only be achieved by reading from
@@ -30,13 +23,12 @@ function createSharedNavigationFns(getLocale, routing) {
30
23
  // always add a prefix in this case to be on the safe side. The downside is
31
24
  // that the user might get redirected again if the middleware detects that the
32
25
  // prefix is not needed.
33
- const forcePrefixSsr = config$1.localePrefix.mode === 'as-needed' && config$1.domains || undefined;
34
- function Link(_ref, ref) {
35
- let {
36
- href,
37
- locale,
38
- ...rest
39
- } = _ref;
26
+ const forcePrefixSsr = config.localePrefix.mode === 'as-needed' && config.domains || undefined;
27
+ function Link({
28
+ href,
29
+ locale,
30
+ ...rest
31
+ }, ref) {
40
32
  let pathname, params;
41
33
  if (typeof href === 'object') {
42
34
  pathname = href.pathname;
@@ -47,9 +39,9 @@ function createSharedNavigationFns(getLocale, routing) {
47
39
  }
48
40
 
49
41
  // @ts-expect-error -- This is ok
50
- const isLocalizable = utils$1.isLocalizableHref(href);
42
+ const isLocalizable = isLocalizableHref(href);
51
43
  const localePromiseOrValue = getLocale();
52
- const curLocale = localePromiseOrValue instanceof Promise ? React.use(localePromiseOrValue) : localePromiseOrValue;
44
+ const curLocale = localePromiseOrValue instanceof Promise ? use(localePromiseOrValue) : localePromiseOrValue;
53
45
  const finalPathname = isLocalizable ? getPathname(
54
46
  // @ts-expect-error -- This is ok
55
47
  {
@@ -59,11 +51,11 @@ function createSharedNavigationFns(getLocale, routing) {
59
51
  params
60
52
  }
61
53
  }, locale != null || forcePrefixSsr || undefined) : pathname;
62
- return /*#__PURE__*/React__default.default.createElement(BaseLink.default, _rollupPluginBabelHelpers.extends({
54
+ return /*#__PURE__*/jsx(BaseLink, {
63
55
  ref: ref
64
56
  // @ts-expect-error -- Available after the validation
65
57
  ,
66
- defaultLocale: config$1.defaultLocale
58
+ defaultLocale: config.defaultLocale
67
59
  // @ts-expect-error -- This is ok
68
60
  ,
69
61
  href: typeof href === 'object' ? {
@@ -71,13 +63,12 @@ function createSharedNavigationFns(getLocale, routing) {
71
63
  pathname: finalPathname
72
64
  } : finalPathname,
73
65
  locale: locale,
74
- localeCookie: config$1.localeCookie
66
+ localeCookie: config.localeCookie
75
67
  // Provide the minimal relevant information to the client side in order
76
68
  // to potentially remove the prefix in case of the `forcePrefixSsr` case
77
69
  ,
78
70
  unprefixed: forcePrefixSsr && isLocalizable ? {
79
- domains: config$1.domains.reduce((acc, domain) => {
80
- // @ts-expect-error -- This is ok
71
+ domains: config.domains.reduce((acc, domain) => {
81
72
  acc[domain.domain] = domain.defaultLocale;
82
73
  return acc;
83
74
  }, {}),
@@ -90,10 +81,11 @@ function createSharedNavigationFns(getLocale, routing) {
90
81
  params
91
82
  }
92
83
  }, false)
93
- } : undefined
94
- }, rest));
84
+ } : undefined,
85
+ ...rest
86
+ });
95
87
  }
96
- const LinkWithRef = /*#__PURE__*/React.forwardRef(Link);
88
+ const LinkWithRef = /*#__PURE__*/forwardRef(Link);
97
89
  function getPathname(args, /** @private Removed in types returned below */
98
90
  _forcePrefix) {
99
91
  const {
@@ -105,45 +97,42 @@ function createSharedNavigationFns(getLocale, routing) {
105
97
  if (typeof href === 'object') {
106
98
  pathname = href.pathname;
107
99
  if (href.query) {
108
- pathname += utils.serializeSearchParams(href.query);
100
+ pathname += serializeSearchParams(href.query);
109
101
  }
110
102
  } else {
111
103
  pathname = href;
112
104
  }
113
105
  } else {
114
- pathname = utils.compileLocalizedPathname({
106
+ pathname = compileLocalizedPathname({
115
107
  locale,
116
108
  // @ts-expect-error -- This is ok
117
- ...utils.normalizeNameOrNameWithParams(href),
109
+ ...normalizeNameOrNameWithParams(href),
118
110
  // @ts-expect-error -- This is ok
119
- pathnames: config$1.pathnames
111
+ pathnames: config.pathnames
120
112
  });
121
113
  }
122
- return utils.applyPathnamePrefix(pathname, locale, config$1,
114
+ return applyPathnamePrefix(pathname, locale, config,
123
115
  // @ts-expect-error -- This is ok
124
116
  args.domain, _forcePrefix);
125
117
  }
126
118
  function getRedirectFn(fn) {
127
119
  /** @see https://next-intl-docs.vercel.app/docs/routing/navigation#redirect */
128
- return function redirectFn(args) {
129
- for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
130
- rest[_key - 1] = arguments[_key];
131
- }
120
+ return function redirectFn(args, ...rest) {
132
121
  return fn(
133
122
  // @ts-expect-error -- We're forcing the prefix when no domain is provided
134
123
  getPathname(args, args.domain ? undefined : forcePrefixSsr), ...rest);
135
124
  };
136
125
  }
137
- const redirect = getRedirectFn(navigation.redirect);
138
- const permanentRedirect = getRedirectFn(navigation.permanentRedirect);
126
+ const redirect$1 = getRedirectFn(redirect);
127
+ const permanentRedirect$1 = getRedirectFn(permanentRedirect);
139
128
  return {
140
- config: config$1,
129
+ config,
141
130
  Link: LinkWithRef,
142
- redirect,
143
- permanentRedirect,
131
+ redirect: redirect$1,
132
+ permanentRedirect: permanentRedirect$1,
144
133
  // Remove `_forcePrefix` from public API
145
134
  getPathname: getPathname
146
135
  };
147
136
  }
148
137
 
149
- exports.default = createSharedNavigationFns;
138
+ export { createSharedNavigationFns as default };
@@ -1,8 +1,4 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var utils = require('./utils.js');
1
+ import { getBasePath } from './utils.js';
6
2
 
7
3
  /**
8
4
  * We have to keep the cookie value in sync as Next.js might
@@ -17,7 +13,7 @@ function syncLocaleCookie(localeCookie, pathname, locale, nextLocale) {
17
13
  !pathname) {
18
14
  return;
19
15
  }
20
- const basePath = utils.getBasePath(pathname);
16
+ const basePath = getBasePath(pathname);
21
17
  const hasBasePath = basePath !== '';
22
18
  const defaultPath = hasBasePath ? basePath : '/';
23
19
  const {
@@ -27,14 +23,14 @@ function syncLocaleCookie(localeCookie, pathname, locale, nextLocale) {
27
23
  if (!rest.path) {
28
24
  rest.path = defaultPath;
29
25
  }
30
- let localeCookieString = "".concat(name, "=").concat(nextLocale, ";");
26
+ let localeCookieString = `${name}=${nextLocale};`;
31
27
  for (const [key, value] of Object.entries(rest)) {
32
28
  // Map object properties to cookie properties.
33
29
  // Interestingly, `maxAge` corresponds to `max-age`,
34
30
  // while `sameSite` corresponds to `SameSite`.
35
31
  // Also, keys are case-insensitive.
36
32
  const targetKey = key === 'maxAge' ? 'max-age' : key;
37
- localeCookieString += "".concat(targetKey);
33
+ localeCookieString += `${targetKey}`;
38
34
  if (typeof value !== 'boolean') {
39
35
  localeCookieString += '=' + value;
40
36
  }
@@ -48,4 +44,4 @@ function syncLocaleCookie(localeCookie, pathname, locale, nextLocale) {
48
44
  document.cookie = localeCookieString;
49
45
  }
50
46
 
51
- exports.default = syncLocaleCookie;
47
+ export { syncLocaleCookie as default };