@donotdev/ui 0.2.1 → 0.2.3

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 (174) hide show
  1. package/dist/{GoToDialog-CICRYHHG.js → GoToDialog-KSBGOIWO.js} +1 -1
  2. package/dist/chunk-MS7ZIW5Z.js +1 -0
  3. package/dist/components/auth/AuthHeader.d.ts.map +1 -1
  4. package/dist/components/auth/AuthHeader.js +0 -2
  5. package/dist/components/auth/AuthMenu.d.ts.map +1 -1
  6. package/dist/components/auth/AuthMenu.js +6 -40
  7. package/dist/components/common/TechBento.d.ts +2 -6
  8. package/dist/components/common/TechBento.d.ts.map +1 -1
  9. package/dist/components/common/TechBento.js +14 -16
  10. package/dist/components/common/icon.d.ts.map +1 -1
  11. package/dist/components/common/icon.js +2 -1
  12. package/dist/components/common/lucideIconByName.d.ts +9 -0
  13. package/dist/components/common/lucideIconByName.d.ts.map +1 -0
  14. package/dist/components/common/lucideIconByName.js +32 -0
  15. package/dist/components/layout/GameFlow.d.ts.map +1 -1
  16. package/dist/components/layout/components/Breadcrumbs.d.ts.map +1 -1
  17. package/dist/components/layout/components/Breadcrumbs.js +14 -9
  18. package/dist/components/layout/components/header/CacheSettings.d.ts.map +1 -1
  19. package/dist/components/layout/components/header/CacheSettings.js +6 -4
  20. package/dist/components/layout/components/header/SettingsMenu.d.ts.map +1 -1
  21. package/dist/components/layout/components/header/SettingsMenu.js +2 -1
  22. package/dist/components/layout/components/header/ThemeToggle.d.ts.map +1 -1
  23. package/dist/components/layout/components/header/ThemeToggle.js +2 -1
  24. package/dist/crud/components/CrudCardLink.d.ts +6 -6
  25. package/dist/crud/components/CrudCardLink.d.ts.map +1 -1
  26. package/dist/crud/components/CrudCardLink.js +3 -9
  27. package/dist/crud/components/EntityCardList.d.ts.map +1 -1
  28. package/dist/crud/components/EntityCardList.js +3 -11
  29. package/dist/crud/components/EntityDisplayRenderer.d.ts +1 -1
  30. package/dist/crud/components/EntityDisplayRenderer.d.ts.map +1 -1
  31. package/dist/crud/components/EntityDisplayRenderer.js +17 -58
  32. package/dist/crud/components/EntityFormRenderer.d.ts.map +1 -1
  33. package/dist/crud/components/EntityFormRenderer.js +27 -5
  34. package/dist/crud/components/EntityList.d.ts +4 -4
  35. package/dist/crud/components/EntityList.d.ts.map +1 -1
  36. package/dist/crud/components/EntityList.js +136 -59
  37. package/dist/crud/components/Form.d.ts +1 -1
  38. package/dist/crud/components/Form.d.ts.map +1 -1
  39. package/dist/crud/components/Form.js +2 -2
  40. package/dist/crud/components/cellEditFor.d.ts +28 -0
  41. package/dist/crud/components/cellEditFor.d.ts.map +1 -0
  42. package/dist/crud/components/cellEditFor.js +54 -0
  43. package/dist/crud/components/entityParent.d.ts +40 -0
  44. package/dist/crud/components/entityParent.d.ts.map +1 -0
  45. package/dist/crud/components/entityParent.js +54 -0
  46. package/dist/crud/components/useRecordBreadcrumb.d.ts +11 -0
  47. package/dist/crud/components/useRecordBreadcrumb.d.ts.map +1 -0
  48. package/dist/crud/components/useRecordBreadcrumb.js +34 -0
  49. package/dist/crud/crudImports.d.ts +3 -0
  50. package/dist/crud/crudImports.d.ts.map +1 -1
  51. package/dist/crud/crudImports.js +3 -0
  52. package/dist/dndev-next.css +483 -145
  53. package/dist/dndev.css +483 -145
  54. package/dist/index.js +4 -4
  55. package/dist/internal/common/RouteErrorFallback.d.ts.map +1 -1
  56. package/dist/internal/common/RouteErrorFallback.js +2 -4
  57. package/dist/internal/devtools/components/ConfigTab.d.ts.map +1 -1
  58. package/dist/internal/devtools/components/ConfigTab.js +1 -1
  59. package/dist/internal/devtools/components/CookieTab.d.ts.map +1 -1
  60. package/dist/internal/devtools/components/CookieTab.js +1 -5
  61. package/dist/internal/devtools/components/DesignTab.d.ts.map +1 -1
  62. package/dist/internal/devtools/components/DesignTab.js +18 -7
  63. package/dist/internal/devtools/components/StoresTab.d.ts.map +1 -1
  64. package/dist/internal/devtools/components/StoresTab.js +17 -3
  65. package/dist/internal/devtools/types.d.ts +3 -3
  66. package/dist/internal/devtools/types.d.ts.map +1 -1
  67. package/dist/internal/devtools/utils/maskSensitive.d.ts +1 -1
  68. package/dist/internal/devtools/utils/maskSensitive.d.ts.map +1 -1
  69. package/dist/internal/layout/DnDevLayout.d.ts.map +1 -1
  70. package/dist/internal/layout/DnDevLayout.js +21 -21
  71. package/dist/internal/layout/components/AutoMetaTags.d.ts.map +1 -1
  72. package/dist/internal/layout/components/AutoMetaTags.js +45 -58
  73. package/dist/internal/layout/components/footer/FooterLegalLinks.js +2 -2
  74. package/dist/internal/layout/components/footer/useLegalLinks.d.ts +0 -2
  75. package/dist/internal/layout/components/footer/useLegalLinks.d.ts.map +1 -1
  76. package/dist/internal/layout/components/footer/useLegalLinks.js +0 -2
  77. package/dist/internal/layout/components/i18nSeoMeta.d.ts +54 -0
  78. package/dist/internal/layout/components/i18nSeoMeta.d.ts.map +1 -0
  79. package/dist/internal/layout/components/i18nSeoMeta.js +53 -0
  80. package/dist/internal/layout/components/index.d.ts +1 -1
  81. package/dist/internal/layout/components/index.js +1 -1
  82. package/dist/internal/layout/zones/DnDevMergedBar.js +3 -3
  83. package/dist/internal/providers/UIProviders.d.ts.map +1 -1
  84. package/dist/internal/providers/UIProviders.js +7 -2
  85. package/dist/providers/NextJsAppProviders.d.ts +5 -1
  86. package/dist/providers/NextJsAppProviders.d.ts.map +1 -1
  87. package/dist/providers/NextJsAppProviders.js +36 -6
  88. package/dist/providers/ViteAppProviders.d.ts.map +1 -1
  89. package/dist/providers/ViteAppProviders.js +42 -4
  90. package/dist/routing/404.js +4 -4
  91. package/dist/routing/AuthGuard.d.ts +0 -4
  92. package/dist/routing/AuthGuard.d.ts.map +1 -1
  93. package/dist/routing/AuthGuard.js +0 -4
  94. package/dist/routing/AuthGuardFallback.d.ts.map +1 -1
  95. package/dist/routing/AuthGuardFallback.js +1 -2
  96. package/dist/routing/AuthReturnTo.d.ts.map +1 -1
  97. package/dist/routing/AuthReturnTo.js +9 -2
  98. package/dist/routing/GoTo.d.ts +0 -6
  99. package/dist/routing/GoTo.d.ts.map +1 -1
  100. package/dist/routing/GoTo.js +5 -8
  101. package/dist/routing/Link.d.ts +4 -2
  102. package/dist/routing/Link.d.ts.map +1 -1
  103. package/dist/routing/Link.js +8 -5
  104. package/dist/routing/SignedInRedirect.d.ts +27 -0
  105. package/dist/routing/SignedInRedirect.d.ts.map +1 -0
  106. package/dist/routing/SignedInRedirect.js +47 -0
  107. package/dist/routing/hooks/hooks.next.d.ts +2 -0
  108. package/dist/routing/hooks/hooks.next.d.ts.map +1 -1
  109. package/dist/routing/hooks/hooks.next.js +1 -1
  110. package/dist/routing/hooks/hooks.vite.d.ts +2 -0
  111. package/dist/routing/hooks/hooks.vite.d.ts.map +1 -1
  112. package/dist/routing/hooks/hooks.vite.js +1 -1
  113. package/dist/routing/hooks/useLocation.next.d.ts +12 -0
  114. package/dist/routing/hooks/useLocation.next.d.ts.map +1 -1
  115. package/dist/routing/hooks/useLocation.next.js +17 -4
  116. package/dist/routing/hooks/useMatch.next.d.ts +6 -0
  117. package/dist/routing/hooks/useMatch.next.d.ts.map +1 -1
  118. package/dist/routing/hooks/useMatch.next.js +8 -2
  119. package/dist/routing/hooks/useNavigate.next.d.ts +6 -1
  120. package/dist/routing/hooks/useNavigate.next.d.ts.map +1 -1
  121. package/dist/routing/hooks/useNavigate.next.js +13 -4
  122. package/dist/routing/hooks/useNavigate.vite.d.ts +7 -1
  123. package/dist/routing/hooks/useNavigate.vite.d.ts.map +1 -1
  124. package/dist/routing/hooks/useNavigate.vite.js +20 -4
  125. package/dist/routing/hooks/useRedirectGuard.next.d.ts.map +1 -1
  126. package/dist/routing/hooks/useRedirectGuard.next.js +7 -1
  127. package/dist/routing/hooks/useRedirectGuard.vite.d.ts.map +1 -1
  128. package/dist/routing/hooks/useRedirectGuard.vite.js +7 -1
  129. package/dist/routing/hooks/useRoutePath.next.d.ts +23 -0
  130. package/dist/routing/hooks/useRoutePath.next.d.ts.map +1 -0
  131. package/dist/routing/hooks/useRoutePath.next.js +36 -0
  132. package/dist/routing/hooks/useRoutePath.vite.d.ts +13 -0
  133. package/dist/routing/hooks/useRoutePath.vite.d.ts.map +1 -0
  134. package/dist/routing/hooks/useRoutePath.vite.js +25 -0
  135. package/dist/routing/hooks/useUrlLanguage.next.d.ts +28 -0
  136. package/dist/routing/hooks/useUrlLanguage.next.d.ts.map +1 -0
  137. package/dist/routing/hooks/useUrlLanguage.next.js +50 -0
  138. package/dist/routing/hooks/useUrlLanguage.vite.d.ts +22 -0
  139. package/dist/routing/hooks/useUrlLanguage.vite.d.ts.map +1 -0
  140. package/dist/routing/hooks/useUrlLanguage.vite.js +41 -0
  141. package/dist/routing/index.d.ts +3 -1
  142. package/dist/routing/index.d.ts.map +1 -1
  143. package/dist/routing/index.js +2 -1
  144. package/dist/routing/useNavigation.js +4 -4
  145. package/dist/styles/index.css +483 -145
  146. package/dist/symbol-index.json +1 -1
  147. package/dist/utils/assetResolver.d.ts.map +1 -1
  148. package/dist/utils/assetResolver.js +1 -0
  149. package/dist/utils/index.d.ts +2 -0
  150. package/dist/utils/index.d.ts.map +1 -1
  151. package/dist/utils/index.js +3 -0
  152. package/dist/utils/useDeleteAccountSafe.d.ts +17 -0
  153. package/dist/utils/useDeleteAccountSafe.d.ts.map +1 -0
  154. package/dist/utils/useDeleteAccountSafe.js +52 -0
  155. package/dist/utils/useFormStoreSafe.d.ts.map +1 -1
  156. package/dist/utils/useFormStoreSafe.js +1 -0
  157. package/dist/utils/useSeo.d.ts +10 -2
  158. package/dist/utils/useSeo.d.ts.map +1 -1
  159. package/dist/utils/useSeo.js +44 -9
  160. package/dist/vite-routing/AppRoutes.d.ts.map +1 -1
  161. package/dist/vite-routing/AppRoutes.js +37 -4
  162. package/guidelines/COMPONENTS.md +2 -1
  163. package/guidelines/PAGES.md +7 -0
  164. package/guidelines/ROUTING.md +4 -0
  165. package/guidelines/SEO.md +64 -0
  166. package/package.json +9 -9
  167. package/dist/CookieConsent-5NH5DNTP.js +0 -1
  168. package/dist/CookieConsent-W7UE647Y.js +0 -1
  169. package/dist/GoToDialog-YGBON6FR.js +0 -1
  170. package/dist/chunk-DRFM6WXH.js +0 -1
  171. package/dist/chunk-MIPTBUWY.js +0 -1
  172. package/dist/internal/layout/components/NextJsAutoMetaTags.d.ts +0 -57
  173. package/dist/internal/layout/components/NextJsAutoMetaTags.d.ts.map +0 -1
  174. package/dist/internal/layout/components/NextJsAutoMetaTags.js +0 -182
@@ -0,0 +1,27 @@
1
+ import type { ReactNode } from 'react';
2
+ /**
3
+ * Props for SignedInRedirect
4
+ */
5
+ export interface SignedInRedirectProps {
6
+ /** App path signed-in visitors are sent to (PageMeta `signedInRedirect`) */
7
+ to: string;
8
+ /** The page, rendered for everyone until the redirect happens */
9
+ children: ReactNode;
10
+ }
11
+ /**
12
+ * SignedInRedirect - sends signed-in visitors of a page to `to` (replace).
13
+ *
14
+ * Renders the page for everyone (server render, signed-out visitors). Once the auth
15
+ * user is known, navigates to `to` unless a return-to is pending (`?returnTo=` or
16
+ * the saved `dndev.auth.returnTo`): AuthReturnTo takes the visitor there instead.
17
+ * Generated route wrappers (Next) and createAppRouter (Vite) mount it for pages whose
18
+ * PageMeta sets `signedInRedirect`.
19
+ *
20
+ * @component
21
+ * @example
22
+ * ```tsx
23
+ * <SignedInRedirect to="/catalogue"><HomePage /></SignedInRedirect>
24
+ * ```
25
+ */
26
+ export declare function SignedInRedirect({ to, children }: SignedInRedirectProps): import("react").JSX.Element;
27
+ //# sourceMappingURL=SignedInRedirect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SignedInRedirect.d.ts","sourceRoot":"","sources":["../../src/routing/SignedInRedirect.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAOvC;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,4EAA4E;IAC5E,EAAE,EAAE,MAAM,CAAC;IACX,iEAAiE;IACjE,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,qBAAqB,+BAYvE"}
@@ -0,0 +1,47 @@
1
+ 'use client';
2
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
3
+ // packages/ui/src/routing/SignedInRedirect.tsx
4
+ /**
5
+ * @fileoverview SignedInRedirect component
6
+ * @description Client side of PageMeta `signedInRedirect`: sends a signed-in visitor
7
+ * of the page to another path. The generated Next proxy redirects before render when
8
+ * it can read the session cookie; this covers sign-ins on the page itself (no server
9
+ * request) and sessions the server cannot read.
10
+ *
11
+ * @version 0.1.0
12
+ * @since 0.6.0
13
+ * @author AMBROISE PARK Consulting
14
+ */
15
+ import { useEffect } from 'react';
16
+ import { isClient, safeSessionStorage } from '@donotdev/core';
17
+ import { useNavigate } from '@donotdev/ui/routing/hooks';
18
+ import { useAuthSafe } from '../utils/useAuthSafe';
19
+ /**
20
+ * SignedInRedirect - sends signed-in visitors of a page to `to` (replace).
21
+ *
22
+ * Renders the page for everyone (server render, signed-out visitors). Once the auth
23
+ * user is known, navigates to `to` unless a return-to is pending (`?returnTo=` or
24
+ * the saved `dndev.auth.returnTo`): AuthReturnTo takes the visitor there instead.
25
+ * Generated route wrappers (Next) and createAppRouter (Vite) mount it for pages whose
26
+ * PageMeta sets `signedInRedirect`.
27
+ *
28
+ * @component
29
+ * @example
30
+ * ```tsx
31
+ * <SignedInRedirect to="/catalogue"><HomePage /></SignedInRedirect>
32
+ * ```
33
+ */
34
+ export function SignedInRedirect({ to, children }) {
35
+ const user = useAuthSafe('user');
36
+ const navigate = useNavigate();
37
+ useEffect(() => {
38
+ if (!user || !isClient())
39
+ return;
40
+ if (new URLSearchParams(window.location.search).has('returnTo'))
41
+ return;
42
+ if (safeSessionStorage.getItem('dndev.auth.returnTo'))
43
+ return;
44
+ navigate(to, { replace: true });
45
+ }, [user, to, navigate]);
46
+ return _jsx(_Fragment, { children: children });
47
+ }
@@ -9,12 +9,14 @@
9
9
  */
10
10
  export { useNavigate, useBack, useRefresh, usePrefetch, } from './useNavigate.next';
11
11
  export { useLocation } from './useLocation.next';
12
+ export { useRoutePath } from './useRoutePath.next';
12
13
  export { useParams } from './useParams.next';
13
14
  export { useRouteParam } from './useRouteParam.next';
14
15
  export { useSearchParams } from './useSearchParams.next';
15
16
  export { useMatch } from './useMatch.next';
16
17
  export { useQueryParams } from './useQueryParams.next';
17
18
  export { useRedirectGuard } from './useRedirectGuard.next';
19
+ export { useLocalizedPath, useUrlLanguage } from './useUrlLanguage.next';
18
20
  export type { NavigateOptions } from './types';
19
21
  export type { RedirectGuardOptions, RedirectGuardResult, } from './useRedirectGuard.next';
20
22
  //# sourceMappingURL=hooks.next.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/hooks.next.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,EACV,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,YAAY,EACV,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"hooks.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/hooks.next.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,EACV,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACzE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,YAAY,EACV,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC"}
@@ -1 +1 @@
1
- "use client";import{useRouter as p}from"next/navigation";import{isClient as k,useOverlayStore as v}from"@donotdev/core";function d(){let e=p(),r=v(t=>t.closeAll);return(t,s)=>{if(t==="back")return r(),e.back();if(r(),s?.preserveScroll&&k()){let o=window.scrollY;s?.replace?e.replace(t):e.push(t),requestAnimationFrame(()=>{window.scrollTo({top:o,behavior:"auto"})});return}return s?.replace?e.replace(t):e.push(t)}}function b(){let e=p();return()=>e.back()}function w(){let e=p();return()=>e.refresh()}function N(){let e=p();return r=>e.prefetch(r)}import{usePathname as T,useSearchParams as I}from"next/navigation";function l(){let e=T(),t=I().toString(),s=t?`?${t}`:void 0;return{pathname:e||"/",search:s,hash:"",state:null}}import{useParams as C}from"next/navigation";function g(){let e=C();return e||{}}function G(e){let t=g()[e];if(typeof t=="string")return t;if(Array.isArray(t)&&t.length>0)return t[0]}import{useSearchParams as $}from"next/navigation";function R(){return $()}import{usePathname as K}from"next/navigation";function O(e){let r=K(),t=e.replace(/:[^/]+/g,"([^/]+)").replace(/\*/g,".*"),s=new RegExp(`^${t}$`),o=r.match(s);if(!o)return null;let u=e.match(/:[^/]+/g)?.map(a=>a.slice(1))||[],n={};return u.forEach((a,c)=>{n[a]=o[c+1]||""}),{params:n,pathname:r,pattern:e}}import{useCallback as P}from"react";function U(){let e=R(),r=d(),t=l(),s=P((n,a)=>{let c=new URLSearchParams(e.toString());c.set(n,a);let f=c.toString(),i=`${t.pathname||"/"}${f?`?${f}`:""}`;r(i)},[e,r,t.pathname]),o=P(n=>{let a=new URLSearchParams(e.toString());a.delete(n);let c=a.toString(),m=`${t.pathname||"/"}${c?`?${c}`:""}`;r(m)},[e,r,t.pathname]),u=P(()=>{let n=t.pathname||"/";r(n)},[r,t.pathname]);return{query:e,setQuery:s,removeQuery:o,clearQueries:u}}import{useMemo as Q}from"react";import{isClient as F,FEATURE_STATUS as M}from"@donotdev/core";import{useAuthConfig as j}from"@donotdev/core";import*as S from"@donotdev/auth";import{DEGRADED_AUTH_API as L}from"@donotdev/core";var A=S?.useAuth;function E(e){return L[e]}function h(e){return A?A(e):E(e)}var ce=S?.PasswordResetCallback??(()=>null);function q(e={}){let{auth:r,redirectTo:t,condition:s}=e,o=l(),u=j(),n=h("user"),a=h("can"),c=h("status");return Q(()=>{let m={shouldRedirect:!1,redirectTo:null,isChecking:!1};if(!F())return m;if(c===M.INITIALIZING)return{...m,isChecking:!0};if(s){let i=s(n,c);return{shouldRedirect:i,redirectTo:i&&t||null,isChecking:!1}}if(r!==!1&&r!==void 0){if(!a)return m;if(!a.navigate(r)){let i=null;if(typeof r=="object"&&r.required&&!n){let y=o.search?.includes("code=")||o.search?.includes("state=")||o.search?.includes("error="),x=u.authRoute;y?i=`${x}${o.search}`:i=x}else typeof r=="object"&&r.role?i=u.roleRoute:typeof r=="object"&&r.tier?i=u.tierRoute:i=u.roleRoute;return{shouldRedirect:!0,redirectTo:t||i,isChecking:!1}}}return m},[r,c,n,a,s,t,o.search,u.authRoute,u.roleRoute,u.tierRoute])}export{b as useBack,l as useLocation,O as useMatch,d as useNavigate,g as useParams,N as usePrefetch,U as useQueryParams,q as useRedirectGuard,w as useRefresh,G as useRouteParam,R as useSearchParams};
1
+ "use client";import{useRouter as d}from"next/navigation";import{isClient as G,useOverlayStore as $}from"@donotdev/core";import{usePathname as C}from"next/navigation";import{getLanguageRouting as b,localizePath as T,publicPathname as N,splitLanguagePath as I}from"@donotdev/core";function v(){return I(N(C()??"/"),b()).language}function h(){let e=v(),t=b();return r=>T(r,e,t)}function R(){let e=d(),t=$(s=>s.closeAll),r=h();return(s,n)=>{if(s==="back")return t(),e.back();t();let o=r(s);if(n?.preserveScroll&&G()){let a=window.scrollY;n?.replace?e.replace(o):e.push(o),requestAnimationFrame(()=>{window.scrollTo({top:a,behavior:"auto"})});return}return n?.replace?e.replace(o):e.push(o)}}function U(){let e=d();return()=>e.back()}function K(){let e=d();return()=>e.refresh()}function E(){let e=d(),t=h();return r=>e.prefetch(t(r))}import{useSearchParams as D}from"next/navigation";import{usePathname as O}from"next/navigation";import{getLanguageRouting as z,publicPathname as q,splitLanguagePath as Q}from"@donotdev/core";function p(){return Q(q(O()??"/"),z()).path}function f(){let e=p(),r=D().toString(),s=r?`?${r}`:void 0;return{pathname:e,search:s,hash:"",state:null}}import{useParams as F}from"next/navigation";function x(){let e=F();return e||{}}function M(e){let r=x()[e];if(typeof r=="string")return r;if(Array.isArray(r)&&r.length>0)return r[0]}import{useSearchParams as j}from"next/navigation";function A(){return j()}function _(e){let t=p(),r=e.replace(/:[^/]+/g,"([^/]+)").replace(/\*/g,".*"),s=new RegExp(`^${r}$`),n=t.match(s);if(!n)return null;let o=e.match(/:[^/]+/g)?.map(u=>u.slice(1))||[],a={};return o.forEach((u,i)=>{a[u]=n[i+1]||""}),{params:a,pathname:t,pattern:e}}import{useCallback as S}from"react";function B(){let e=A(),t=R(),r=f(),s=S((a,u)=>{let i=new URLSearchParams(e.toString());i.set(a,u);let m=i.toString(),l=`${r.pathname||"/"}${m?`?${m}`:""}`;t(l)},[e,t,r.pathname]),n=S(a=>{let u=new URLSearchParams(e.toString());u.delete(a);let i=u.toString(),P=`${r.pathname||"/"}${i?`?${i}`:""}`;t(P)},[e,t,r.pathname]),o=S(()=>{let a=r.pathname||"/";t(a)},[t,r.pathname]);return{query:e,setQuery:s,removeQuery:n,clearQueries:o}}import{useMemo as Z}from"react";import{isClient as J,FEATURE_STATUS as V}from"@donotdev/core";import{useAppConfig as W,useAuthConfig as X}from"@donotdev/core";import*as k from"@donotdev/auth";import{DEGRADED_AUTH_API as Y}from"@donotdev/core";var w=k?.useAuth;function H(e){return Y[e]}function g(e){return w?w(e):H(e)}var Ce=k?.PasswordResetCallback??(()=>null);function ee(e={}){let{auth:t,redirectTo:r,condition:s}=e,n=f(),o=X(),a=W().auth===!1,u=g("user"),i=g("can"),m=g("status");return Z(()=>{let l={shouldRedirect:!1,redirectTo:null,isChecking:!1};if(!J())return l;if(m===V.INITIALIZING)return{...l,isChecking:!0};if(s){let c=s(u,m);return{shouldRedirect:c,redirectTo:c&&r||null,isChecking:!1}}if(t!==!1&&t!==void 0){if(!i)return l;if(!i.navigate(t)){if(a&&!r)throw new Error("[dndev] This route declares auth requirements but AppConfig.auth is false, so there is no auth route to redirect to. Enable auth in AppConfig or remove the route's auth requirement.");let c=null;if(typeof t=="object"&&t.required&&!u){let L=n.search?.includes("code=")||n.search?.includes("state=")||n.search?.includes("error="),y=o.authRoute;L?c=`${y}${n.search}`:c=y}else typeof t=="object"&&t.role?c=o.roleRoute:typeof t=="object"&&t.tier?c=o.tierRoute:c=o.roleRoute;return{shouldRedirect:!0,redirectTo:r||c,isChecking:!1}}}return l},[t,m,u,i,s,r,n.search,a,o.authRoute,o.roleRoute,o.tierRoute])}export{U as useBack,h as useLocalizedPath,f as useLocation,_ as useMatch,R as useNavigate,x as useParams,E as usePrefetch,B as useQueryParams,ee as useRedirectGuard,K as useRefresh,M as useRouteParam,p as useRoutePath,A as useSearchParams,v as useUrlLanguage};
@@ -9,12 +9,14 @@
9
9
  */
10
10
  export { useNavigate, useBack, useRefresh, usePrefetch, } from './useNavigate.vite';
11
11
  export { useLocation } from './useLocation.vite';
12
+ export { useRoutePath } from './useRoutePath.vite';
12
13
  export { useParams } from './useParams.vite';
13
14
  export { useRouteParam } from './useRouteParam.vite';
14
15
  export { useSearchParams } from './useSearchParams.vite';
15
16
  export { useMatch } from './useMatch.vite';
16
17
  export { useQueryParams } from './useQueryParams.vite';
17
18
  export { useRedirectGuard } from './useRedirectGuard.vite';
19
+ export { useLocalizedPath, useUrlLanguage } from './useUrlLanguage.vite';
18
20
  export type { NavigateOptions } from './types';
19
21
  export type { RedirectGuardOptions, RedirectGuardResult, } from './useRedirectGuard.vite';
20
22
  //# sourceMappingURL=hooks.vite.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.vite.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/hooks.vite.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,EACV,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,YAAY,EACV,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"hooks.vite.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/hooks.vite.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,EACV,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACzE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,YAAY,EACV,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC"}
@@ -1 +1 @@
1
- "use client";import{useNavigate as P}from"react-router-dom";import{isClient as v,useOverlayStore as k}from"@donotdev/core";function h(){let e=P(),r=k(t=>t.closeAll);return(t,i)=>t==="back"?(r(),e(-1)):(r(),i?.replace?e(t,{replace:!0}):e(t))}function I(){let e=P();return()=>e(-1)}function b(){return()=>{v()&&window.location.reload()}}function w(){return e=>{}}import{useLocation as C}from"react-router-dom";function m(){return C()}import{useParams as G}from"react-router-dom";function d(){return G()}function T(e){let t=d()[e];if(typeof t=="string")return t;if(Array.isArray(t)&&t.length>0)return t[0]}import{useSearchParams as N}from"react-router-dom";function R(){return N()[0]}import{useMatch as L}from"react-router-dom";function K(e){return L(e)}import{useCallback as g}from"react";function U(){let e=R(),r=h(),t=m(),i=g((n,u)=>{let a=new URLSearchParams(e.toString());a.set(n,u);let l=a.toString(),o=`${t.pathname||"/"}${l?`?${l}`:""}`;r(o)},[e,r,t.pathname]),c=g(n=>{let u=new URLSearchParams(e.toString());u.delete(n);let a=u.toString(),f=`${t.pathname||"/"}${a?`?${a}`:""}`;r(f)},[e,r,t.pathname]),s=g(()=>{let n=t.pathname||"/";r(n)},[r,t.pathname]);return{query:e,setQuery:i,removeQuery:c,clearQueries:s}}import{useMemo as M}from"react";import{isClient as Q,FEATURE_STATUS as E}from"@donotdev/core";import{useAuthConfig as _}from"@donotdev/core";import*as y from"@donotdev/auth";import{DEGRADED_AUTH_API as O}from"@donotdev/core";var x=y?.useAuth;function $(e){return O[e]}function p(e){return x?x(e):$(e)}var ue=y?.PasswordResetCallback??(()=>null);function j(e={}){let{auth:r,redirectTo:t,condition:i}=e,c=m(),s=_(),n=p("user"),u=p("can"),a=p("status");return M(()=>{let f={shouldRedirect:!1,redirectTo:null,isChecking:!1};if(!Q())return f;if(a===E.INITIALIZING)return{...f,isChecking:!0};if(i){let o=i(n,a);return{shouldRedirect:o,redirectTo:o&&t||null,isChecking:!1}}if(r!==!1&&r!==void 0){if(!u)return f;if(!u.navigate(r)){let o=null;if(typeof r=="object"&&r.required&&!n){let S=c.search.includes("code=")||c.search.includes("state=")||c.search.includes("error="),A=s.authRoute;S?o=`${A}${c.search}`:o=A}else typeof r=="object"&&r.role?o=s.roleRoute:typeof r=="object"&&r.tier?o=s.tierRoute:o=s.roleRoute;return{shouldRedirect:!0,redirectTo:t||o,isChecking:!1}}}return f},[r,a,n,u,i,t,c.search,s.authRoute,s.roleRoute,s.tierRoute])}export{I as useBack,m as useLocation,K as useMatch,h as useNavigate,d as useParams,w as usePrefetch,U as useQueryParams,j as useRedirectGuard,b as useRefresh,T as useRouteParam,R as useSearchParams};
1
+ "use client";import{useNavigate as S}from"react-router-dom";import{getLanguageRouting as T,isClient as G,splitLanguagePath as U,useOverlayStore as N}from"@donotdev/core";import{useHref as b}from"react-router-dom";import{getLanguageRouting as y,localizePath as C,splitLanguagePath as k}from"@donotdev/core";function p(){return k(b("/"),y()).language}function I(){let e=p(),t=y();return r=>C(r,e,t)}function g(){let e=S(),t=N(n=>n.closeAll),r=p();return(n,a)=>{if(n==="back")return t(),e(-1);t();let o=n.startsWith("/")?U(n,T()):null;if(o?.prefixed&&o.language!==r){window.location.assign(n);return}let s=o?.prefixed?o.path:n;return a?.replace?e(s,{replace:!0}):e(s)}}function K(){let e=S();return()=>e(-1)}function O(){return()=>{G()&&window.location.reload()}}function $(){return e=>{}}import{useLocation as E}from"react-router-dom";function m(){return E()}import{useLocation as M}from"react-router-dom";function Q(){return M().pathname}import{useParams as q}from"react-router-dom";function R(){return q()}function D(e){let r=R()[e];if(typeof r=="string")return r;if(Array.isArray(r)&&r.length>0)return r[0]}import{useSearchParams as _}from"react-router-dom";function P(){return _()[0]}import{useMatch as j}from"react-router-dom";function z(e){return j(e)}import{useCallback as A}from"react";function F(){let e=P(),t=g(),r=m(),n=A((s,c)=>{let u=new URLSearchParams(e.toString());u.set(s,c);let f=u.toString(),l=`${r.pathname||"/"}${f?`?${f}`:""}`;t(l)},[e,t,r.pathname]),a=A(s=>{let c=new URLSearchParams(e.toString());c.delete(s);let u=c.toString(),d=`${r.pathname||"/"}${u?`?${u}`:""}`;t(d)},[e,t,r.pathname]),o=A(()=>{let s=r.pathname||"/";t(s)},[t,r.pathname]);return{query:e,setQuery:n,removeQuery:a,clearQueries:o}}import{useMemo as W}from"react";import{isClient as Z,FEATURE_STATUS as J}from"@donotdev/core";import{useAppConfig as V,useAuthConfig as X}from"@donotdev/core";import*as L from"@donotdev/auth";import{DEGRADED_AUTH_API as B}from"@donotdev/core";var v=L?.useAuth;function H(e){return B[e]}function h(e){return v?v(e):H(e)}var we=L?.PasswordResetCallback??(()=>null);function Y(e={}){let{auth:t,redirectTo:r,condition:n}=e,a=m(),o=X(),s=V().auth===!1,c=h("user"),u=h("can"),f=h("status");return W(()=>{let l={shouldRedirect:!1,redirectTo:null,isChecking:!1};if(!Z())return l;if(f===J.INITIALIZING)return{...l,isChecking:!0};if(n){let i=n(c,f);return{shouldRedirect:i,redirectTo:i&&r||null,isChecking:!1}}if(t!==!1&&t!==void 0){if(!u)return l;if(!u.navigate(t)){if(s&&!r)throw new Error("[dndev] This route declares auth requirements but AppConfig.auth is false, so there is no auth route to redirect to. Enable auth in AppConfig or remove the route's auth requirement.");let i=null;if(typeof t=="object"&&t.required&&!c){let w=a.search.includes("code=")||a.search.includes("state=")||a.search.includes("error="),x=o.authRoute;w?i=`${x}${a.search}`:i=x}else typeof t=="object"&&t.role?i=o.roleRoute:typeof t=="object"&&t.tier?i=o.tierRoute:i=o.roleRoute;return{shouldRedirect:!0,redirectTo:r||i,isChecking:!1}}}return l},[t,f,c,u,n,r,a.search,s,o.authRoute,o.roleRoute,o.tierRoute])}export{K as useBack,I as useLocalizedPath,m as useLocation,z as useMatch,g as useNavigate,R as useParams,$ as usePrefetch,F as useQueryParams,Y as useRedirectGuard,O as useRefresh,D as useRouteParam,Q as useRoutePath,P as useSearchParams,p as useUrlLanguage};
@@ -1,3 +1,15 @@
1
+ /**
2
+ * Current location, route-relative: `pathname` has no language prefix (`/en/produits`
3
+ * → `/produits`), so route matching, breadcrumbs and guards see app paths.
4
+ *
5
+ * Reads the query string (`search`): in a cached (static) render that moves the
6
+ * render to the browser up to the nearest Suspense boundary. Use `useRoutePath()`
7
+ * when only the path is needed.
8
+ *
9
+ * @version 0.2.0
10
+ * @since 0.0.1
11
+ * @author AMBROISE PARK Consulting
12
+ */
1
13
  export declare function useLocation(): {
2
14
  pathname: string;
3
15
  search: string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"useLocation.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useLocation.next.ts"],"names":[],"mappings":"AAgBA,wBAAgB,WAAW;;;;;EAY1B"}
1
+ {"version":3,"file":"useLocation.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useLocation.next.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW;;;;;EAY1B"}
@@ -3,18 +3,31 @@
3
3
  /**
4
4
  * @fileoverview Next.js-specific location hook
5
5
  *
6
- * @version 0.1.0
6
+ * @version 0.2.0
7
+ * @since 0.0.1
8
+ * @author AMBROISE PARK Consulting
9
+ */
10
+ import { useSearchParams as useNextSearchParams } from 'next/navigation';
11
+ import { useRoutePath } from './useRoutePath.next';
12
+ /**
13
+ * Current location, route-relative: `pathname` has no language prefix (`/en/produits`
14
+ * → `/produits`), so route matching, breadcrumbs and guards see app paths.
15
+ *
16
+ * Reads the query string (`search`): in a cached (static) render that moves the
17
+ * render to the browser up to the nearest Suspense boundary. Use `useRoutePath()`
18
+ * when only the path is needed.
19
+ *
20
+ * @version 0.2.0
7
21
  * @since 0.0.1
8
22
  * @author AMBROISE PARK Consulting
9
23
  */
10
- import { usePathname, useSearchParams as useNextSearchParams, } from 'next/navigation';
11
24
  export function useLocation() {
12
- const pathname = usePathname();
25
+ const pathname = useRoutePath();
13
26
  const searchParams = useNextSearchParams();
14
27
  const searchString = searchParams.toString();
15
28
  const search = searchString ? `?${searchString}` : undefined;
16
29
  return {
17
- pathname: pathname || '/',
30
+ pathname,
18
31
  search,
19
32
  hash: '',
20
33
  state: null,
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Match the current route path (language prefix stripped) against a pattern.
3
+ *
4
+ * @version 0.2.0
5
+ * @since 0.0.1
6
+ */
1
7
  export declare function useMatch(pattern: string): {
2
8
  params: Record<string, string>;
3
9
  pathname: string;
@@ -1 +1 @@
1
- {"version":3,"file":"useMatch.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useMatch.next.ts"],"names":[],"mappings":"AAKA,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM;;;;SA0BvC"}
1
+ {"version":3,"file":"useMatch.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useMatch.next.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM;;;;SA0BvC"}
@@ -1,8 +1,14 @@
1
1
  'use client';
2
2
  // packages/ui/src/routing/hooks/useMatch.next.ts
3
- import { usePathname } from 'next/navigation';
3
+ import { useRoutePath } from './useRoutePath.next';
4
+ /**
5
+ * Match the current route path (language prefix stripped) against a pattern.
6
+ *
7
+ * @version 0.2.0
8
+ * @since 0.0.1
9
+ */
4
10
  export function useMatch(pattern) {
5
- const pathname = usePathname();
11
+ const pathname = useRoutePath();
6
12
  // Simple pattern matching for Next.js
7
13
  const regexPattern = pattern
8
14
  .replace(/:[^/]+/g, '([^/]+)') // Replace :param with regex group
@@ -2,8 +2,13 @@ import type { NavigateOptions } from './types';
2
2
  /**
3
3
  * Navigation hook. Auth is handled by AuthGuard (cold-load redirect).
4
4
  * Protected routes are hidden from unauthorized users via useAccessibleRoutes.
5
+ * App paths stay in the current URL's language (`/produits` → `/en/produits` on an
6
+ * English page); a path with an explicit language prefix keeps it.
7
+ *
8
+ * @version 0.3.0
9
+ * @since 0.0.1
5
10
  */
6
- export declare function useNavigate(): (to: string, options?: NavigateOptions) => void;
11
+ export declare function useNavigate(): (path: string, options?: NavigateOptions) => void;
7
12
  export declare function useBack(): () => void;
8
13
  export declare function useRefresh(): () => void;
9
14
  export declare function usePrefetch(): (to: string) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"useNavigate.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useNavigate.next.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;;GAGG;AACH,wBAAgB,WAAW,KAIjB,IAAI,MAAM,EAAE,UAAU,eAAe,UAwB9C;AAED,wBAAgB,OAAO,eAGtB;AAED,wBAAgB,UAAU,eAGzB;AAED,wBAAgB,WAAW,KAEjB,IAAI,MAAM,UACnB"}
1
+ {"version":3,"file":"useNavigate.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useNavigate.next.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG/C;;;;;;;;GAQG;AACH,wBAAgB,WAAW,KAKjB,MAAM,MAAM,EAAE,UAAU,eAAe,UAyBhD;AAED,wBAAgB,OAAO,eAGtB;AAED,wBAAgB,UAAU,eAGzB;AAED,wBAAgB,WAAW,KAGjB,IAAI,MAAM,UACnB"}
@@ -4,25 +4,33 @@
4
4
  * @fileoverview Next.js-specific navigation hooks
5
5
  * @description Navigation hooks for Next.js App Router
6
6
  *
7
- * @version 0.2.0
7
+ * @version 0.3.0
8
8
  * @since 0.0.1
9
9
  * @author AMBROISE PARK Consulting
10
10
  */
11
11
  import { useRouter as useNextRouter } from 'next/navigation';
12
12
  import { isClient, useOverlayStore } from '@donotdev/core';
13
+ import { useLocalizedPath } from './useUrlLanguage.next';
13
14
  /**
14
15
  * Navigation hook. Auth is handled by AuthGuard (cold-load redirect).
15
16
  * Protected routes are hidden from unauthorized users via useAccessibleRoutes.
17
+ * App paths stay in the current URL's language (`/produits` → `/en/produits` on an
18
+ * English page); a path with an explicit language prefix keeps it.
19
+ *
20
+ * @version 0.3.0
21
+ * @since 0.0.1
16
22
  */
17
23
  export function useNavigate() {
18
24
  const router = useNextRouter();
19
25
  const closeAll = useOverlayStore((state) => state.closeAll);
20
- return (to, options) => {
21
- if (to === 'back') {
26
+ const localize = useLocalizedPath();
27
+ return (path, options) => {
28
+ if (path === 'back') {
22
29
  closeAll();
23
30
  return router.back();
24
31
  }
25
32
  closeAll();
33
+ const to = localize(path);
26
34
  if (options?.preserveScroll && isClient()) {
27
35
  const scrollY = window.scrollY;
28
36
  if (options?.replace) {
@@ -51,5 +59,6 @@ export function useRefresh() {
51
59
  }
52
60
  export function usePrefetch() {
53
61
  const router = useNextRouter();
54
- return (to) => router.prefetch(to);
62
+ const localize = useLocalizedPath();
63
+ return (to) => router.prefetch(localize(to));
55
64
  }
@@ -2,8 +2,14 @@ import type { NavigateOptions } from './types';
2
2
  /**
3
3
  * Navigation hook. Auth is handled by AuthGuard (cold-load redirect).
4
4
  * Protected routes are hidden from unauthorized users via useAccessibleRoutes.
5
+ * The router basename carries the language prefix (createAppRouter), so app paths
6
+ * stay in the current language. A path prefixed with another language opens that
7
+ * language's URL (document navigation: the router restarts under its prefix).
8
+ *
9
+ * @version 0.3.0
10
+ * @since 0.0.1
5
11
  */
6
- export declare function useNavigate(): (to: string, options?: NavigateOptions) => void | Promise<void>;
12
+ export declare function useNavigate(): (path: string, options?: NavigateOptions) => void | Promise<void>;
7
13
  export declare function useBack(): () => void | Promise<void>;
8
14
  export declare function useRefresh(): () => void;
9
15
  export declare function usePrefetch(): (_to: string) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"useNavigate.vite.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useNavigate.vite.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;;GAGG;AACH,wBAAgB,WAAW,KAIjB,IAAI,MAAM,EAAE,UAAU,eAAe,0BAW9C;AAED,wBAAgB,OAAO,+BAGtB;AAED,wBAAgB,UAAU,eAIzB;AAED,wBAAgB,WAAW,KACjB,KAAK,MAAM,UAGpB"}
1
+ {"version":3,"file":"useNavigate.vite.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useNavigate.vite.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG/C;;;;;;;;;GASG;AACH,wBAAgB,WAAW,KAKjB,MAAM,MAAM,EAAE,UAAU,eAAe,0BAoBhD;AAED,wBAAgB,OAAO,+BAGtB;AAED,wBAAgB,UAAU,eAIzB;AAED,wBAAgB,WAAW,KACjB,KAAK,MAAM,UAGpB"}
@@ -4,25 +4,41 @@
4
4
  * @fileoverview Vite-specific navigation hooks
5
5
  * @description Navigation hooks for React Router (Vite)
6
6
  *
7
- * @version 0.2.0
7
+ * @version 0.3.0
8
8
  * @since 0.0.1
9
9
  * @author AMBROISE PARK Consulting
10
10
  */
11
11
  import { useNavigate as useRouterNavigate } from 'react-router-dom';
12
- import { isClient, useOverlayStore } from '@donotdev/core';
12
+ import { getLanguageRouting, isClient, splitLanguagePath, useOverlayStore, } from '@donotdev/core';
13
+ import { useUrlLanguage } from './useUrlLanguage.vite';
13
14
  /**
14
15
  * Navigation hook. Auth is handled by AuthGuard (cold-load redirect).
15
16
  * Protected routes are hidden from unauthorized users via useAccessibleRoutes.
17
+ * The router basename carries the language prefix (createAppRouter), so app paths
18
+ * stay in the current language. A path prefixed with another language opens that
19
+ * language's URL (document navigation: the router restarts under its prefix).
20
+ *
21
+ * @version 0.3.0
22
+ * @since 0.0.1
16
23
  */
17
24
  export function useNavigate() {
18
25
  const routerNavigate = useRouterNavigate();
19
26
  const closeAll = useOverlayStore((state) => state.closeAll);
20
- return (to, options) => {
21
- if (to === 'back') {
27
+ const language = useUrlLanguage();
28
+ return (path, options) => {
29
+ if (path === 'back') {
22
30
  closeAll();
23
31
  return routerNavigate(-1);
24
32
  }
25
33
  closeAll();
34
+ const split = path.startsWith('/')
35
+ ? splitLanguagePath(path, getLanguageRouting())
36
+ : null;
37
+ if (split?.prefixed && split.language !== language) {
38
+ window.location.assign(path);
39
+ return;
40
+ }
41
+ const to = split?.prefixed ? split.path : path;
26
42
  if (options?.replace)
27
43
  return routerNavigate(to, { replace: true });
28
44
  return routerNavigate(to);
@@ -1 +1 @@
1
- {"version":3,"file":"useRedirectGuard.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useRedirectGuard.next.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAK9D,yDAAyD;AACzD,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,IAAI,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;IACxB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,mEAAmE;IACnE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC;CAC3D;AAED,iDAAiD;AACjD,MAAM,WAAW,mBAAmB;IAClC,qCAAqC;IACrC,cAAc,EAAE,OAAO,CAAC;IACxB,uDAAuD;IACvD,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,gDAAgD;IAChD,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,GAAE,oBAAyB,GACjC,mBAAmB,CAgGrB"}
1
+ {"version":3,"file":"useRedirectGuard.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useRedirectGuard.next.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAK9D,yDAAyD;AACzD,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,IAAI,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;IACxB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,mEAAmE;IAEnE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC;CAC3D;AAED,iDAAiD;AACjD,MAAM,WAAW,mBAAmB;IAClC,qCAAqC;IACrC,cAAc,EAAE,OAAO,CAAC;IACxB,uDAAuD;IACvD,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,gDAAgD;IAChD,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,GAAE,oBAAyB,GACjC,mBAAmB,CAwGrB"}
@@ -10,7 +10,7 @@
10
10
  */
11
11
  import { useMemo } from 'react';
12
12
  import { isClient, FEATURE_STATUS } from '@donotdev/core';
13
- import { useAuthConfig } from '@donotdev/core';
13
+ import { useAppConfig, useAuthConfig } from '@donotdev/core';
14
14
  import { useLocation } from './useLocation.next';
15
15
  import { useAuthSafe } from '../../utils/useAuthSafe';
16
16
  /**
@@ -27,6 +27,7 @@ export function useRedirectGuard(options = {}) {
27
27
  // Hooks must be called unconditionally (Rules of Hooks)
28
28
  const location = useLocation();
29
29
  const authConfig = useAuthConfig();
30
+ const authDisabled = useAppConfig().auth === false;
30
31
  const user = useAuthSafe('user');
31
32
  const can = useAuthSafe('can');
32
33
  const status = useAuthSafe('status');
@@ -59,6 +60,10 @@ export function useRedirectGuard(options = {}) {
59
60
  return noAction;
60
61
  // Check if user can navigate to this route
61
62
  if (!can.navigate(auth)) {
63
+ // Redirect targets come from AppConfig.auth: none exist when auth is disabled
64
+ if (authDisabled && !customRedirectTo) {
65
+ throw new Error("[dndev] This route declares auth requirements but AppConfig.auth is false, so there is no auth route to redirect to. Enable auth in AppConfig or remove the route's auth requirement.");
66
+ }
62
67
  let targetRoute = null;
63
68
  // Authentication failure (not logged in) → always redirect
64
69
  if (typeof auth === 'object' && auth.required && !user) {
@@ -103,6 +108,7 @@ export function useRedirectGuard(options = {}) {
103
108
  condition,
104
109
  customRedirectTo,
105
110
  location.search,
111
+ authDisabled,
106
112
  authConfig.authRoute,
107
113
  authConfig.roleRoute,
108
114
  authConfig.tierRoute,
@@ -1 +1 @@
1
- {"version":3,"file":"useRedirectGuard.vite.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useRedirectGuard.vite.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAK9D,yDAAyD;AACzD,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,IAAI,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;IACxB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,mEAAmE;IACnE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC;CAC3D;AAED,iDAAiD;AACjD,MAAM,WAAW,mBAAmB;IAClC,qCAAqC;IACrC,cAAc,EAAE,OAAO,CAAC;IACxB,uDAAuD;IACvD,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,gDAAgD;IAChD,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,GAAE,oBAAyB,GACjC,mBAAmB,CAgGrB"}
1
+ {"version":3,"file":"useRedirectGuard.vite.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useRedirectGuard.vite.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAK9D,yDAAyD;AACzD,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,IAAI,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;IACxB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,mEAAmE;IAEnE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC;CAC3D;AAED,iDAAiD;AACjD,MAAM,WAAW,mBAAmB;IAClC,qCAAqC;IACrC,cAAc,EAAE,OAAO,CAAC;IACxB,uDAAuD;IACvD,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,gDAAgD;IAChD,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,GAAE,oBAAyB,GACjC,mBAAmB,CAwGrB"}
@@ -10,7 +10,7 @@
10
10
  */
11
11
  import { useMemo } from 'react';
12
12
  import { isClient, FEATURE_STATUS } from '@donotdev/core';
13
- import { useAuthConfig } from '@donotdev/core';
13
+ import { useAppConfig, useAuthConfig } from '@donotdev/core';
14
14
  import { useLocation } from './useLocation.vite';
15
15
  import { useAuthSafe } from '../../utils/useAuthSafe';
16
16
  /**
@@ -27,6 +27,7 @@ export function useRedirectGuard(options = {}) {
27
27
  // Hooks must be called unconditionally (Rules of Hooks)
28
28
  const location = useLocation();
29
29
  const authConfig = useAuthConfig();
30
+ const authDisabled = useAppConfig().auth === false;
30
31
  const user = useAuthSafe('user');
31
32
  const can = useAuthSafe('can');
32
33
  const status = useAuthSafe('status');
@@ -59,6 +60,10 @@ export function useRedirectGuard(options = {}) {
59
60
  return noAction;
60
61
  // Check if user can navigate to this route
61
62
  if (!can.navigate(auth)) {
63
+ // Redirect targets come from AppConfig.auth: none exist when auth is disabled
64
+ if (authDisabled && !customRedirectTo) {
65
+ throw new Error("[dndev] This route declares auth requirements but AppConfig.auth is false, so there is no auth route to redirect to. Enable auth in AppConfig or remove the route's auth requirement.");
66
+ }
62
67
  let targetRoute = null;
63
68
  // Authentication failure (not logged in) → always redirect
64
69
  if (typeof auth === 'object' && auth.required && !user) {
@@ -103,6 +108,7 @@ export function useRedirectGuard(options = {}) {
103
108
  condition,
104
109
  customRedirectTo,
105
110
  location.search,
111
+ authDisabled,
106
112
  authConfig.authRoute,
107
113
  authConfig.roleRoute,
108
114
  authConfig.tierRoute,
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Route path of the current URL: the pathname without its language prefix
3
+ * (`/en/produits` → `/produits`). Reads the pathname only: safe in cached (static)
4
+ * renders, where reading the query string (`useLocation().search`,
5
+ * `useSearchParams`) moves the render to the browser up to the nearest Suspense
6
+ * boundary. Use it whenever the query string is not needed. The server render of a
7
+ * per-request page reads its internal pathname (`/<lang>/dndev-session/…`): dropped here, so
8
+ * the server and the browser see the same path.
9
+ *
10
+ * @returns Route path, always starting with `/`
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * const path = useRoutePath();
15
+ * const active = path === '/produits';
16
+ * ```
17
+ *
18
+ * @version 0.1.0
19
+ * @since 0.2.3
20
+ * @author AMBROISE PARK Consulting
21
+ */
22
+ export declare function useRoutePath(): string;
23
+ //# sourceMappingURL=useRoutePath.next.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRoutePath.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useRoutePath.next.ts"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAKrC"}
@@ -0,0 +1,36 @@
1
+ 'use client';
2
+ // packages/ui/src/routing/hooks/useRoutePath.next.ts
3
+ /**
4
+ * @fileoverview Next.js route path of the current URL
5
+ * @description The pathname without its language prefix, read without the query string.
6
+ *
7
+ * @version 0.1.0
8
+ * @since 0.2.3
9
+ * @author AMBROISE PARK Consulting
10
+ */
11
+ import { usePathname } from 'next/navigation';
12
+ import { getLanguageRouting, publicPathname, splitLanguagePath, } from '@donotdev/core';
13
+ /**
14
+ * Route path of the current URL: the pathname without its language prefix
15
+ * (`/en/produits` → `/produits`). Reads the pathname only: safe in cached (static)
16
+ * renders, where reading the query string (`useLocation().search`,
17
+ * `useSearchParams`) moves the render to the browser up to the nearest Suspense
18
+ * boundary. Use it whenever the query string is not needed. The server render of a
19
+ * per-request page reads its internal pathname (`/<lang>/dndev-session/…`): dropped here, so
20
+ * the server and the browser see the same path.
21
+ *
22
+ * @returns Route path, always starting with `/`
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * const path = useRoutePath();
27
+ * const active = path === '/produits';
28
+ * ```
29
+ *
30
+ * @version 0.1.0
31
+ * @since 0.2.3
32
+ * @author AMBROISE PARK Consulting
33
+ */
34
+ export function useRoutePath() {
35
+ return splitLanguagePath(publicPathname(usePathname() ?? '/'), getLanguageRouting()).path;
36
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Route path of the current URL: the pathname without its language prefix
3
+ * (`/en/produits` → `/produits`). Same as `useLocation().pathname`; on Next it is the
4
+ * one that stays safe in cached (static) renders.
5
+ *
6
+ * @returns Route path, always starting with `/`
7
+ *
8
+ * @version 0.1.0
9
+ * @since 0.2.3
10
+ * @author AMBROISE PARK Consulting
11
+ */
12
+ export declare function useRoutePath(): string;
13
+ //# sourceMappingURL=useRoutePath.vite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRoutePath.vite.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useRoutePath.vite.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC"}
@@ -0,0 +1,25 @@
1
+ 'use client';
2
+ // packages/ui/src/routing/hooks/useRoutePath.vite.ts
3
+ /**
4
+ * @fileoverview Vite route path of the current URL
5
+ * @description The router pathname (React Router strips the language basename).
6
+ *
7
+ * @version 0.1.0
8
+ * @since 0.2.3
9
+ * @author AMBROISE PARK Consulting
10
+ */
11
+ import { useLocation as useRouterLocation } from 'react-router-dom';
12
+ /**
13
+ * Route path of the current URL: the pathname without its language prefix
14
+ * (`/en/produits` → `/produits`). Same as `useLocation().pathname`; on Next it is the
15
+ * one that stays safe in cached (static) renders.
16
+ *
17
+ * @returns Route path, always starting with `/`
18
+ *
19
+ * @version 0.1.0
20
+ * @since 0.2.3
21
+ * @author AMBROISE PARK Consulting
22
+ */
23
+ export function useRoutePath() {
24
+ return useRouterLocation().pathname;
25
+ }