@donotdev/ui 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ChildRowsPicker-63M4EQUQ.js +1 -0
- package/dist/ChildRowsPicker-ISP365ON.js +1 -0
- package/dist/ChildRowsPicker-PQFE6NCR.js +1 -0
- package/dist/ChildRowsPicker-XXFFSMWY.js +1 -0
- package/dist/{GoToDialog-CICRYHHG.js → GoToDialog-KSBGOIWO.js} +1 -1
- package/dist/{GoToDialog-YGBON6FR.js → GoToDialog-XBK5EZF4.js} +1 -1
- package/dist/chunk-3CIZFGST.js +1 -0
- package/dist/chunk-LHMKU342.js +1 -0
- package/dist/chunk-MS7ZIW5Z.js +1 -0
- package/dist/chunk-P2DHZWPY.js +1 -0
- package/dist/components/auth/AuthHeader.d.ts.map +1 -1
- package/dist/components/auth/AuthHeader.js +0 -2
- package/dist/components/auth/AuthMenu.d.ts.map +1 -1
- package/dist/components/auth/AuthMenu.js +6 -40
- package/dist/components/common/icon.d.ts.map +1 -1
- package/dist/components/common/icon.js +2 -1
- package/dist/components/common/lucideIconByName.d.ts +9 -0
- package/dist/components/common/lucideIconByName.d.ts.map +1 -0
- package/dist/components/common/lucideIconByName.js +32 -0
- package/dist/components/layout/GameFlow.d.ts.map +1 -1
- package/dist/components/layout/components/Breadcrumbs.d.ts.map +1 -1
- package/dist/components/layout/components/Breadcrumbs.js +18 -12
- package/dist/components/layout/components/header/CacheSettings.d.ts.map +1 -1
- package/dist/components/layout/components/header/CacheSettings.js +6 -4
- package/dist/components/layout/components/header/SettingsMenu.d.ts.map +1 -1
- package/dist/components/layout/components/header/SettingsMenu.js +4 -3
- package/dist/components/layout/components/header/ThemeToggle.d.ts.map +1 -1
- package/dist/components/layout/components/header/ThemeToggle.js +2 -1
- package/dist/crud/components/ChildRowsPicker.d.ts +21 -0
- package/dist/crud/components/ChildRowsPicker.d.ts.map +1 -0
- package/dist/crud/components/ChildRowsPicker.js +68 -0
- package/dist/crud/components/CrudCardLink.d.ts +6 -6
- package/dist/crud/components/CrudCardLink.d.ts.map +1 -1
- package/dist/crud/components/CrudCardLink.js +3 -9
- package/dist/crud/components/EntityCardList.d.ts.map +1 -1
- package/dist/crud/components/EntityCardList.js +10 -26
- package/dist/crud/components/EntityDisplayRenderer.d.ts.map +1 -1
- package/dist/crud/components/EntityDisplayRenderer.js +6 -3
- package/dist/crud/components/EntityFormRenderer.d.ts +4 -2
- package/dist/crud/components/EntityFormRenderer.d.ts.map +1 -1
- package/dist/crud/components/EntityFormRenderer.js +160 -56
- package/dist/crud/components/EntityList.d.ts +6 -4
- package/dist/crud/components/EntityList.d.ts.map +1 -1
- package/dist/crud/components/EntityList.js +437 -92
- package/dist/crud/components/EntityRecommendations.js +1 -1
- package/dist/crud/components/EntityWorkflow.d.ts.map +1 -1
- package/dist/crud/components/EntityWorkflow.js +6 -4
- package/dist/crud/components/Form.d.ts +1 -1
- package/dist/crud/components/Form.d.ts.map +1 -1
- package/dist/crud/components/Form.js +2 -2
- package/dist/crud/components/cellEditFor.d.ts +43 -0
- package/dist/crud/components/cellEditFor.d.ts.map +1 -0
- package/dist/crud/components/cellEditFor.js +74 -0
- package/dist/crud/components/entityParent.d.ts +33 -0
- package/dist/crud/components/entityParent.d.ts.map +1 -0
- package/dist/crud/components/entityParent.js +76 -0
- package/dist/crud/components/useRecordBreadcrumb.d.ts +11 -0
- package/dist/crud/components/useRecordBreadcrumb.d.ts.map +1 -0
- package/dist/crud/components/useRecordBreadcrumb.js +43 -0
- package/dist/crud/crudImports.d.ts +12 -1
- package/dist/crud/crudImports.d.ts.map +1 -1
- package/dist/crud/crudImports.js +11 -0
- package/dist/dndev-next.css +782 -193
- package/dist/dndev.css +784 -193
- package/dist/index.js +4 -4
- package/dist/internal/common/RouteErrorFallback.d.ts.map +1 -1
- package/dist/internal/common/RouteErrorFallback.js +2 -4
- package/dist/internal/devtools/components/ConfigTab.d.ts.map +1 -1
- package/dist/internal/devtools/components/ConfigTab.js +1 -1
- package/dist/internal/devtools/components/CookieTab.d.ts.map +1 -1
- package/dist/internal/devtools/components/CookieTab.js +1 -5
- package/dist/internal/devtools/components/DesignTab.d.ts.map +1 -1
- package/dist/internal/devtools/components/DesignTab.js +18 -7
- package/dist/internal/devtools/components/StoresTab.d.ts.map +1 -1
- package/dist/internal/devtools/components/StoresTab.js +17 -3
- package/dist/internal/devtools/types.d.ts +3 -3
- package/dist/internal/devtools/types.d.ts.map +1 -1
- package/dist/internal/devtools/utils/maskSensitive.d.ts +1 -1
- package/dist/internal/devtools/utils/maskSensitive.d.ts.map +1 -1
- package/dist/internal/initializers/NextJsStoresInitializer.d.ts +3 -0
- package/dist/internal/initializers/NextJsStoresInitializer.d.ts.map +1 -1
- package/dist/internal/initializers/NextJsStoresInitializer.js +8 -1
- package/dist/internal/layout/DnDevLayout.d.ts.map +1 -1
- package/dist/internal/layout/DnDevLayout.js +21 -21
- package/dist/internal/layout/components/AutoMetaTags.d.ts.map +1 -1
- package/dist/internal/layout/components/AutoMetaTags.js +42 -38
- package/dist/internal/layout/components/FontPreloadLinks.d.ts +7 -4
- package/dist/internal/layout/components/FontPreloadLinks.d.ts.map +1 -1
- package/dist/internal/layout/components/FontPreloadLinks.js +12 -25
- package/dist/internal/layout/components/footer/FooterCopyright.d.ts +2 -0
- package/dist/internal/layout/components/footer/FooterCopyright.d.ts.map +1 -1
- package/dist/internal/layout/components/footer/FooterCopyright.js +4 -0
- package/dist/internal/layout/components/footer/useLegalLinks.d.ts +2 -1
- package/dist/internal/layout/components/footer/useLegalLinks.d.ts.map +1 -1
- package/dist/internal/layout/components/footer/useLegalLinks.js +4 -3
- package/dist/internal/layout/components/i18nSeoMeta.d.ts.map +1 -1
- package/dist/internal/layout/components/i18nSeoMeta.js +1 -0
- package/dist/internal/layout/zones/DnDevMergedBar.js +3 -3
- package/dist/internal/providers/UIProviders.d.ts +0 -8
- package/dist/internal/providers/UIProviders.d.ts.map +1 -1
- package/dist/internal/providers/UIProviders.js +45 -2
- package/dist/providers/NextJsAppProviders.d.ts +5 -1
- package/dist/providers/NextJsAppProviders.d.ts.map +1 -1
- package/dist/providers/NextJsAppProviders.js +36 -6
- package/dist/providers/ViteAppProviders.d.ts.map +1 -1
- package/dist/providers/ViteAppProviders.js +42 -7
- package/dist/routing/404.d.ts +8 -1
- package/dist/routing/404.d.ts.map +1 -1
- package/dist/routing/404.js +9 -5
- package/dist/routing/AuthGuardFallback.d.ts.map +1 -1
- package/dist/routing/AuthGuardFallback.js +1 -2
- package/dist/routing/AuthReturnTo.d.ts.map +1 -1
- package/dist/routing/AuthReturnTo.js +9 -2
- package/dist/routing/GoTo.d.ts +0 -6
- package/dist/routing/GoTo.d.ts.map +1 -1
- package/dist/routing/GoTo.js +5 -8
- package/dist/routing/Link.d.ts +4 -2
- package/dist/routing/Link.d.ts.map +1 -1
- package/dist/routing/Link.js +8 -5
- package/dist/routing/SignedInRedirect.d.ts +27 -0
- package/dist/routing/SignedInRedirect.d.ts.map +1 -0
- package/dist/routing/SignedInRedirect.js +47 -0
- package/dist/routing/hooks/hooks.next.d.ts +2 -0
- package/dist/routing/hooks/hooks.next.d.ts.map +1 -1
- package/dist/routing/hooks/hooks.next.js +1 -1
- package/dist/routing/hooks/hooks.vite.d.ts +2 -0
- package/dist/routing/hooks/hooks.vite.d.ts.map +1 -1
- package/dist/routing/hooks/hooks.vite.js +1 -1
- package/dist/routing/hooks/useLocation.next.d.ts +12 -0
- package/dist/routing/hooks/useLocation.next.d.ts.map +1 -1
- package/dist/routing/hooks/useLocation.next.js +17 -4
- package/dist/routing/hooks/useMatch.next.d.ts +6 -0
- package/dist/routing/hooks/useMatch.next.d.ts.map +1 -1
- package/dist/routing/hooks/useMatch.next.js +8 -2
- package/dist/routing/hooks/useNavigate.next.d.ts +6 -1
- package/dist/routing/hooks/useNavigate.next.d.ts.map +1 -1
- package/dist/routing/hooks/useNavigate.next.js +13 -4
- package/dist/routing/hooks/useNavigate.vite.d.ts +7 -1
- package/dist/routing/hooks/useNavigate.vite.d.ts.map +1 -1
- package/dist/routing/hooks/useNavigate.vite.js +20 -4
- package/dist/routing/hooks/useRedirectGuard.next.d.ts +3 -1
- package/dist/routing/hooks/useRedirectGuard.next.d.ts.map +1 -1
- package/dist/routing/hooks/useRedirectGuard.next.js +18 -10
- package/dist/routing/hooks/useRedirectGuard.vite.d.ts.map +1 -1
- package/dist/routing/hooks/useRedirectGuard.vite.js +7 -1
- package/dist/routing/hooks/useRoutePath.next.d.ts +23 -0
- package/dist/routing/hooks/useRoutePath.next.d.ts.map +1 -0
- package/dist/routing/hooks/useRoutePath.next.js +36 -0
- package/dist/routing/hooks/useRoutePath.vite.d.ts +13 -0
- package/dist/routing/hooks/useRoutePath.vite.d.ts.map +1 -0
- package/dist/routing/hooks/useRoutePath.vite.js +25 -0
- package/dist/routing/hooks/useUrlLanguage.next.d.ts +28 -0
- package/dist/routing/hooks/useUrlLanguage.next.d.ts.map +1 -0
- package/dist/routing/hooks/useUrlLanguage.next.js +50 -0
- package/dist/routing/hooks/useUrlLanguage.vite.d.ts +22 -0
- package/dist/routing/hooks/useUrlLanguage.vite.d.ts.map +1 -0
- package/dist/routing/hooks/useUrlLanguage.vite.js +41 -0
- package/dist/routing/index.d.ts +3 -1
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/index.js +2 -1
- package/dist/routing/parentRoute.d.ts +27 -0
- package/dist/routing/parentRoute.d.ts.map +1 -0
- package/dist/routing/parentRoute.js +43 -0
- package/dist/routing/useNavigation.d.ts.map +1 -1
- package/dist/routing/useNavigation.js +8 -27
- package/dist/routing/useRouteDiscovery.d.ts +2 -2
- package/dist/routing/useRouteDiscovery.d.ts.map +1 -1
- package/dist/routing/useRouteDiscovery.js +6 -5
- package/dist/styles/index.css +781 -192
- package/dist/symbol-index.json +1 -1
- package/dist/utils/assetResolver.d.ts.map +1 -1
- package/dist/utils/assetResolver.js +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +3 -0
- package/dist/utils/useDeleteAccountSafe.d.ts +17 -0
- package/dist/utils/useDeleteAccountSafe.d.ts.map +1 -0
- package/dist/utils/useDeleteAccountSafe.js +52 -0
- package/dist/utils/useFormStoreSafe.d.ts.map +1 -1
- package/dist/utils/useFormStoreSafe.js +1 -0
- package/dist/utils/useSeo.d.ts +10 -2
- package/dist/utils/useSeo.d.ts.map +1 -1
- package/dist/utils/useSeo.js +44 -9
- package/dist/vite-routing/AppRoutes.d.ts.map +1 -1
- package/dist/vite-routing/AppRoutes.js +37 -4
- package/guidelines/COMPONENTS.md +2 -1
- package/guidelines/GOTCHAS.md +2 -0
- package/guidelines/LAYOUTS.md +4 -0
- package/guidelines/PAGES.md +30 -3
- package/guidelines/ROUTING.md +29 -0
- package/guidelines/SEO.md +52 -0
- package/package.json +9 -9
- package/dist/CookieConsent-5NH5DNTP.js +0 -1
- package/dist/CookieConsent-W7UE647Y.js +0 -1
- package/dist/chunk-DRFM6WXH.js +0 -1
- package/dist/chunk-MIPTBUWY.js +0 -1
- package/dist/internal/layout/components/NextJsAutoMetaTags.d.ts +0 -57
- package/dist/internal/layout/components/NextJsAutoMetaTags.d.ts.map +0 -1
- package/dist/internal/layout/components/NextJsAutoMetaTags.js +0 -182
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Language of the current URL: its prefix, else the default language.
|
|
3
|
+
*
|
|
4
|
+
* @returns Language code (`/en/produits` → `en`)
|
|
5
|
+
*
|
|
6
|
+
* @version 0.1.0
|
|
7
|
+
* @since 0.2.3
|
|
8
|
+
* @author AMBROISE PARK Consulting
|
|
9
|
+
*/
|
|
10
|
+
export declare function useUrlLanguage(): string;
|
|
11
|
+
/**
|
|
12
|
+
* Localize app paths in the current URL's language, for `href`s built outside `<Link>`.
|
|
13
|
+
* `<Link path>` and `navigate()` already do it.
|
|
14
|
+
*
|
|
15
|
+
* @returns `(path) => url`: `/produits` → `/en/produits` on an English page
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* const localize = useLocalizedPath();
|
|
20
|
+
* <a href={localize('/produits')}>…</a>
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @version 0.1.0
|
|
24
|
+
* @since 0.2.3
|
|
25
|
+
* @author AMBROISE PARK Consulting
|
|
26
|
+
*/
|
|
27
|
+
export declare function useLocalizedPath(): (path: string) => string;
|
|
28
|
+
//# sourceMappingURL=useUrlLanguage.next.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUrlLanguage.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useUrlLanguage.next.ts"],"names":[],"mappings":"AA0BA;;;;;;;;GAQG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAKvC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAI3D"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
// packages/ui/src/routing/hooks/useUrlLanguage.next.ts
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Next.js language of the URL
|
|
5
|
+
* @description The language of the current URL and the localized form of app paths
|
|
6
|
+
* (default language at the root, others under `/<lang>`; see languagePath in
|
|
7
|
+
* @donotdev/core). On the server a rewritten default-language page reads
|
|
8
|
+
* `/<default>/…` and the browser reads `/…` (a per-request page: `/<lang>/dndev-session/…`,
|
|
9
|
+
* dropped by publicPathname): both give the same language and paths, so the server
|
|
10
|
+
* HTML and the hydration pass agree.
|
|
11
|
+
*
|
|
12
|
+
* @version 0.1.0
|
|
13
|
+
* @since 0.2.3
|
|
14
|
+
* @author AMBROISE PARK Consulting
|
|
15
|
+
*/
|
|
16
|
+
import { usePathname } from 'next/navigation';
|
|
17
|
+
import { getLanguageRouting, localizePath, publicPathname, splitLanguagePath, } from '@donotdev/core';
|
|
18
|
+
/**
|
|
19
|
+
* Language of the current URL: its prefix, else the default language.
|
|
20
|
+
*
|
|
21
|
+
* @returns Language code (`/en/produits` → `en`)
|
|
22
|
+
*
|
|
23
|
+
* @version 0.1.0
|
|
24
|
+
* @since 0.2.3
|
|
25
|
+
* @author AMBROISE PARK Consulting
|
|
26
|
+
*/
|
|
27
|
+
export function useUrlLanguage() {
|
|
28
|
+
return splitLanguagePath(publicPathname(usePathname() ?? '/'), getLanguageRouting()).language;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Localize app paths in the current URL's language, for `href`s built outside `<Link>`.
|
|
32
|
+
* `<Link path>` and `navigate()` already do it.
|
|
33
|
+
*
|
|
34
|
+
* @returns `(path) => url`: `/produits` → `/en/produits` on an English page
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```tsx
|
|
38
|
+
* const localize = useLocalizedPath();
|
|
39
|
+
* <a href={localize('/produits')}>…</a>
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @version 0.1.0
|
|
43
|
+
* @since 0.2.3
|
|
44
|
+
* @author AMBROISE PARK Consulting
|
|
45
|
+
*/
|
|
46
|
+
export function useLocalizedPath() {
|
|
47
|
+
const language = useUrlLanguage();
|
|
48
|
+
const routing = getLanguageRouting();
|
|
49
|
+
return (path) => localizePath(path, language, routing);
|
|
50
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Language of the current URL: the router basename's language, else the default.
|
|
3
|
+
*
|
|
4
|
+
* @returns Language code
|
|
5
|
+
*
|
|
6
|
+
* @version 0.1.0
|
|
7
|
+
* @since 0.2.3
|
|
8
|
+
* @author AMBROISE PARK Consulting
|
|
9
|
+
*/
|
|
10
|
+
export declare function useUrlLanguage(): string;
|
|
11
|
+
/**
|
|
12
|
+
* Localize app paths in the current URL's language, for `href`s built outside `<Link>`.
|
|
13
|
+
* `<Link path>` and `navigate()` already do it.
|
|
14
|
+
*
|
|
15
|
+
* @returns `(path) => url`: `/produits` → `/en/produits` on an English page
|
|
16
|
+
*
|
|
17
|
+
* @version 0.1.0
|
|
18
|
+
* @since 0.2.3
|
|
19
|
+
* @author AMBROISE PARK Consulting
|
|
20
|
+
*/
|
|
21
|
+
export declare function useLocalizedPath(): (path: string) => string;
|
|
22
|
+
//# sourceMappingURL=useUrlLanguage.vite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUrlLanguage.vite.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useUrlLanguage.vite.ts"],"names":[],"mappings":"AAsBA;;;;;;;;GAQG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAI3D"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
// packages/ui/src/routing/hooks/useUrlLanguage.vite.ts
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Vite language of the URL
|
|
5
|
+
* @description The router runs under the language prefix as its basename
|
|
6
|
+
* (createAppRouter), so route paths never carry it. This reads the language from that
|
|
7
|
+
* basename and localizes app paths for `href`s.
|
|
8
|
+
*
|
|
9
|
+
* @version 0.1.0
|
|
10
|
+
* @since 0.2.3
|
|
11
|
+
* @author AMBROISE PARK Consulting
|
|
12
|
+
*/
|
|
13
|
+
import { useHref } from 'react-router-dom';
|
|
14
|
+
import { getLanguageRouting, localizePath, splitLanguagePath, } from '@donotdev/core';
|
|
15
|
+
/**
|
|
16
|
+
* Language of the current URL: the router basename's language, else the default.
|
|
17
|
+
*
|
|
18
|
+
* @returns Language code
|
|
19
|
+
*
|
|
20
|
+
* @version 0.1.0
|
|
21
|
+
* @since 0.2.3
|
|
22
|
+
* @author AMBROISE PARK Consulting
|
|
23
|
+
*/
|
|
24
|
+
export function useUrlLanguage() {
|
|
25
|
+
return splitLanguagePath(useHref('/'), getLanguageRouting()).language;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Localize app paths in the current URL's language, for `href`s built outside `<Link>`.
|
|
29
|
+
* `<Link path>` and `navigate()` already do it.
|
|
30
|
+
*
|
|
31
|
+
* @returns `(path) => url`: `/produits` → `/en/produits` on an English page
|
|
32
|
+
*
|
|
33
|
+
* @version 0.1.0
|
|
34
|
+
* @since 0.2.3
|
|
35
|
+
* @author AMBROISE PARK Consulting
|
|
36
|
+
*/
|
|
37
|
+
export function useLocalizedPath() {
|
|
38
|
+
const language = useUrlLanguage();
|
|
39
|
+
const routing = getLanguageRouting();
|
|
40
|
+
return (path) => localizePath(path, language, routing);
|
|
41
|
+
}
|
package/dist/routing/index.d.ts
CHANGED
|
@@ -11,12 +11,14 @@ export * from './Link';
|
|
|
11
11
|
export * from './AuthGuard';
|
|
12
12
|
export * from './AuthGuardFallback';
|
|
13
13
|
export { AuthReturnTo } from './AuthReturnTo';
|
|
14
|
+
export { SignedInRedirect } from './SignedInRedirect';
|
|
15
|
+
export type { SignedInRedirectProps } from './SignedInRedirect';
|
|
14
16
|
export * from './GoTo';
|
|
15
17
|
export { default as GoToWrapper } from './GoToWrapper';
|
|
16
18
|
export { default as GoToInput } from './GoToInput';
|
|
17
19
|
export * from './DnDevNavigationMenu';
|
|
18
20
|
export { default as NotFoundPage } from './404';
|
|
19
|
-
export { useNavigate, useBack, useRefresh, usePrefetch, useLocation, useParams, useRouteParam, useSearchParams, useMatch, useQueryParams, useRedirectGuard, } from '@donotdev/ui/routing/hooks';
|
|
21
|
+
export { useNavigate, useBack, useRefresh, usePrefetch, useLocation, useRoutePath, useParams, useRouteParam, useSearchParams, useMatch, useQueryParams, useRedirectGuard, useLocalizedPath, useUrlLanguage, } from '@donotdev/ui/routing/hooks';
|
|
20
22
|
export type { NavigateOptions, RedirectGuardOptions, RedirectGuardResult, } from '@donotdev/ui/routing/hooks';
|
|
21
23
|
export * from './useNavigation';
|
|
22
24
|
export * from './useGoTo';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/routing/index.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAGH,cAAc,QAAQ,CAAC;AAGvB,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AAEnD,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,OAAO,CAAC;AAOhD,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,EACV,WAAW,EACX,WAAW,EACX,SAAS,EACT,aAAa,EACb,eAAe,EACf,QAAQ,EACR,cAAc,EACd,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/routing/index.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAGH,cAAc,QAAQ,CAAC;AAGvB,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AAEnD,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,OAAO,CAAC;AAOhD,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,SAAS,EACT,aAAa,EACb,eAAe,EACf,QAAQ,EACR,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,GACf,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,eAAe,EACf,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,4BAA4B,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC"}
|
package/dist/routing/index.js
CHANGED
|
@@ -15,6 +15,7 @@ export * from './Link';
|
|
|
15
15
|
export * from './AuthGuard';
|
|
16
16
|
export * from './AuthGuardFallback';
|
|
17
17
|
export { AuthReturnTo } from './AuthReturnTo';
|
|
18
|
+
export { SignedInRedirect } from './SignedInRedirect';
|
|
18
19
|
export * from './GoTo';
|
|
19
20
|
export { default as GoToWrapper } from './GoToWrapper';
|
|
20
21
|
export { default as GoToInput } from './GoToInput';
|
|
@@ -26,6 +27,6 @@ export { default as NotFoundPage } from './404';
|
|
|
26
27
|
// - hooks.vite.ts when bundled with Vite (vite-app condition)
|
|
27
28
|
// - hooks.next.ts when bundled with Next.js (default condition)
|
|
28
29
|
// NOTE: Explicit named exports required - esbuild can't re-export with 'export *' from external
|
|
29
|
-
export { useNavigate, useBack, useRefresh, usePrefetch, useLocation, useParams, useRouteParam, useSearchParams, useMatch, useQueryParams, useRedirectGuard, } from '@donotdev/ui/routing/hooks';
|
|
30
|
+
export { useNavigate, useBack, useRefresh, usePrefetch, useLocation, useRoutePath, useParams, useRouteParam, useSearchParams, useMatch, useQueryParams, useRedirectGuard, useLocalizedPath, useUrlLanguage, } from '@donotdev/ui/routing/hooks';
|
|
30
31
|
export * from './useNavigation';
|
|
31
32
|
export * from './useGoTo';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Breadcrumb path rules
|
|
3
|
+
* @description One rule for Breadcrumbs and form navigation: every cumulative
|
|
4
|
+
* path prefix is a crumb, and a crumb links only when it is a known route.
|
|
5
|
+
*
|
|
6
|
+
* @version 0.1.0
|
|
7
|
+
* @since 0.2.5
|
|
8
|
+
* @author AMBROISE PARK Consulting
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Cumulative prefixes of a pathname: `/a/b/c` → `['/a', '/a/b', '/a/b/c']`.
|
|
12
|
+
*
|
|
13
|
+
* @param pathname - App path (no language prefix)
|
|
14
|
+
* @returns One entry per segment, in order
|
|
15
|
+
*/
|
|
16
|
+
export declare function getPathPrefixes(pathname: string): string[];
|
|
17
|
+
/**
|
|
18
|
+
* Previous breadcrumb: the nearest parent prefix that is a known route, else home.
|
|
19
|
+
* `/routines/abc` → `/routines`; `/reglages` → `/`.
|
|
20
|
+
*
|
|
21
|
+
* @param pathname - App path (no language prefix)
|
|
22
|
+
* @param routePaths - Known route paths (what Breadcrumbs links)
|
|
23
|
+
* @param homePath - Path when no parent route exists
|
|
24
|
+
* @returns The path the previous breadcrumb links to
|
|
25
|
+
*/
|
|
26
|
+
export declare function getParentRoutePath(pathname: string, routePaths: ReadonlySet<string>, homePath?: string): string;
|
|
27
|
+
//# sourceMappingURL=parentRoute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parentRoute.d.ts","sourceRoot":"","sources":["../../src/routing/parentRoute.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAQ1D;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,EAC/B,QAAQ,SAAM,GACb,MAAM,CAOR"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// packages/ui/src/routing/parentRoute.ts
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Breadcrumb path rules
|
|
4
|
+
* @description One rule for Breadcrumbs and form navigation: every cumulative
|
|
5
|
+
* path prefix is a crumb, and a crumb links only when it is a known route.
|
|
6
|
+
*
|
|
7
|
+
* @version 0.1.0
|
|
8
|
+
* @since 0.2.5
|
|
9
|
+
* @author AMBROISE PARK Consulting
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Cumulative prefixes of a pathname: `/a/b/c` → `['/a', '/a/b', '/a/b/c']`.
|
|
13
|
+
*
|
|
14
|
+
* @param pathname - App path (no language prefix)
|
|
15
|
+
* @returns One entry per segment, in order
|
|
16
|
+
*/
|
|
17
|
+
export function getPathPrefixes(pathname) {
|
|
18
|
+
const prefixes = [];
|
|
19
|
+
let current = '';
|
|
20
|
+
for (const segment of pathname.split('/').filter(Boolean)) {
|
|
21
|
+
current += `/${segment}`;
|
|
22
|
+
prefixes.push(current);
|
|
23
|
+
}
|
|
24
|
+
return prefixes;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Previous breadcrumb: the nearest parent prefix that is a known route, else home.
|
|
28
|
+
* `/routines/abc` → `/routines`; `/reglages` → `/`.
|
|
29
|
+
*
|
|
30
|
+
* @param pathname - App path (no language prefix)
|
|
31
|
+
* @param routePaths - Known route paths (what Breadcrumbs links)
|
|
32
|
+
* @param homePath - Path when no parent route exists
|
|
33
|
+
* @returns The path the previous breadcrumb links to
|
|
34
|
+
*/
|
|
35
|
+
export function getParentRoutePath(pathname, routePaths, homePath = '/') {
|
|
36
|
+
const parents = getPathPrefixes(pathname).slice(0, -1);
|
|
37
|
+
for (let index = parents.length - 1; index >= 0; index--) {
|
|
38
|
+
const path = parents[index];
|
|
39
|
+
if (path !== undefined && routePaths.has(path))
|
|
40
|
+
return path;
|
|
41
|
+
}
|
|
42
|
+
return homePath;
|
|
43
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNavigation.d.ts","sourceRoot":"","sources":["../../src/routing/useNavigation.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"useNavigation.d.ts","sourceRoot":"","sources":["../../src/routing/useNavigation.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAYtD;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,eAAe;IACrD,mEAAmE;IACnE,QAAQ,EAAE,OAAO,CAAC;IAClB,yCAAyC;IACzC,WAAW,EAAE,OAAO,CAAC;IACrB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,cAAc,EAAE,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,IAAI,cAAc,EAAE,CAyBrD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAG3E"}
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
* @author AMBROISE PARK Consulting
|
|
9
9
|
*/
|
|
10
10
|
import { useMemo } from 'react';
|
|
11
|
-
import { useNavigationStore, useTranslation } from '@donotdev/core';
|
|
11
|
+
import { filterNavigationRoutes, useNavigationStore, useTranslation, } from '@donotdev/core';
|
|
12
12
|
import { USER_ROLES } from '@donotdev/core';
|
|
13
13
|
// Platform-specific hooks via conditional exports
|
|
14
|
-
import {
|
|
14
|
+
import { useRoutePath } from '@donotdev/ui/routing/hooks';
|
|
15
15
|
import { useAuthSafe } from '../utils/useAuthSafe';
|
|
16
16
|
/**
|
|
17
17
|
* Smart navigation hook with auth filtering
|
|
@@ -33,44 +33,25 @@ import { useAuthSafe } from '../utils/useAuthSafe';
|
|
|
33
33
|
* ```
|
|
34
34
|
*/
|
|
35
35
|
export function useNavigationItems() {
|
|
36
|
-
const
|
|
36
|
+
const pathname = useRoutePath();
|
|
37
37
|
// Get auth state - hooks must be called at top level
|
|
38
38
|
const user = useAuthSafe('user');
|
|
39
39
|
const authenticated = !!user;
|
|
40
40
|
const { t } = useTranslation();
|
|
41
41
|
const role = user?.role || USER_ROLES.GUEST;
|
|
42
|
-
//
|
|
43
|
-
const
|
|
44
|
-
// Guard against undefined state during initialization
|
|
45
|
-
if (!state || typeof state.getFilteredRoutes !== 'function') {
|
|
46
|
-
if (process.env.NODE_ENV === 'development') {
|
|
47
|
-
console.warn('[useNavigationItems] Navigation store not initialized, returning empty routes');
|
|
48
|
-
}
|
|
49
|
-
return [];
|
|
50
|
-
}
|
|
51
|
-
return state.getFilteredRoutes({
|
|
52
|
-
authenticated,
|
|
53
|
-
role,
|
|
54
|
-
});
|
|
55
|
-
});
|
|
42
|
+
// Select snapshot-owned data; store getters close over live state during hydration.
|
|
43
|
+
const allRoutes = useNavigationStore((state) => state.cache.allRoutes);
|
|
56
44
|
return useMemo(() => {
|
|
57
|
-
|
|
58
|
-
if (!Array.isArray(filteredRoutes)) {
|
|
59
|
-
if (process.env.NODE_ENV === 'development') {
|
|
60
|
-
console.warn('[useNavigationItems] filteredRoutes is not an array:', filteredRoutes);
|
|
61
|
-
}
|
|
62
|
-
return [];
|
|
63
|
-
}
|
|
64
|
-
return filteredRoutes
|
|
45
|
+
return filterNavigationRoutes(allRoutes, { authenticated, role })
|
|
65
46
|
.map((route) => ({
|
|
66
47
|
...route,
|
|
67
48
|
label: routeLabel(route, t),
|
|
68
|
-
isActive: isRouteActive(route.path,
|
|
49
|
+
isActive: isRouteActive(route.path, pathname),
|
|
69
50
|
hasChildren: false,
|
|
70
51
|
children: undefined,
|
|
71
52
|
}))
|
|
72
53
|
.sort((a, b) => a.label.localeCompare(b.label, undefined, { sensitivity: 'base' })); // Alphabetical sorting by label
|
|
73
|
-
}, [
|
|
54
|
+
}, [allRoutes, authenticated, role, pathname, t]);
|
|
74
55
|
}
|
|
75
56
|
/**
|
|
76
57
|
* Resolves a single navigation item from the store by path.
|
|
@@ -109,8 +109,8 @@ export declare function useAccessibleRoutes(): RouteGroup[];
|
|
|
109
109
|
* navigation data with authentication filtering.
|
|
110
110
|
*
|
|
111
111
|
* Features:
|
|
112
|
-
* -
|
|
113
|
-
* - Automatic updates when auth
|
|
112
|
+
* - Memoized filtering of snapshot-owned routes
|
|
113
|
+
* - Automatic updates when routes or auth change
|
|
114
114
|
* - Consistent filtering logic with AuthGuard
|
|
115
115
|
* - Optimized for multiple component usage
|
|
116
116
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouteDiscovery.d.ts","sourceRoot":"","sources":["../../src/routing/useRouteDiscovery.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"useRouteDiscovery.d.ts","sourceRoot":"","sources":["../../src/routing/useRouteDiscovery.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAQvC,OAAO,KAAK,EAEV,eAAe,IAAI,mBAAmB,EACvC,MAAM,gBAAgB,CAAC;AAOxB;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACxB,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,2DAA2D;IAC3D,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,sEAAsE;IACtE,SAAS,EAAE,MAAM,CAAC;IAClB,8DAA8D;IAC9D,UAAU,EAAE,MAAM,CAAC;IACnB,oEAAoE;IACpE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iDAAiD;IACjD,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,gCAAgC;IAChC,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,kCAAkC;IAClC,IAAI,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACnB,qCAAqC;IACrC,MAAM,EAAE,SAAS,EAAE,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,mBAAmB,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,iBAAiB,IAAI,UAAU,EAAE,CA2BhD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,mBAAmB,IAAI,UAAU,EAAE,CAoBlD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,6BAA6B,IAAI,eAAe,EAAE,CAejE;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,YAAY,gBAK3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,gBAAgB;;;;;;SAQ/B"}
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
25
|
import { useMemo } from 'react';
|
|
26
|
-
import { useNavigationStore, getRoutes, getRouteManifest, } from '@donotdev/core';
|
|
26
|
+
import { useNavigationStore, filterNavigationRoutes, getRoutes, getRouteManifest, } from '@donotdev/core';
|
|
27
27
|
import { useAuthSafe } from '../utils/useAuthSafe';
|
|
28
28
|
/**
|
|
29
29
|
* Hook that provides auto-discovered routes from virtual module system
|
|
@@ -130,8 +130,8 @@ export function useAccessibleRoutes() {
|
|
|
130
130
|
* navigation data with authentication filtering.
|
|
131
131
|
*
|
|
132
132
|
* Features:
|
|
133
|
-
* -
|
|
134
|
-
* - Automatic updates when auth
|
|
133
|
+
* - Memoized filtering of snapshot-owned routes
|
|
134
|
+
* - Automatic updates when routes or auth change
|
|
135
135
|
* - Consistent filtering logic with AuthGuard
|
|
136
136
|
* - Optimized for multiple component usage
|
|
137
137
|
*
|
|
@@ -151,8 +151,9 @@ export function useAccessibleRoutes() {
|
|
|
151
151
|
*/
|
|
152
152
|
export function useAccessibleNavigationRoutes() {
|
|
153
153
|
const user = useAuthSafe('user');
|
|
154
|
+
const allRoutes = useNavigationStore((state) => state.cache.allRoutes);
|
|
154
155
|
return useMemo(() => {
|
|
155
|
-
const filteredRoutes =
|
|
156
|
+
const filteredRoutes = filterNavigationRoutes(allRoutes, {
|
|
156
157
|
authenticated: !!user,
|
|
157
158
|
role: user?.role || 'user',
|
|
158
159
|
});
|
|
@@ -162,7 +163,7 @@ export function useAccessibleNavigationRoutes() {
|
|
|
162
163
|
icon: route.icon,
|
|
163
164
|
meta: route.meta,
|
|
164
165
|
}));
|
|
165
|
-
}, [user]);
|
|
166
|
+
}, [allRoutes, user]);
|
|
166
167
|
}
|
|
167
168
|
/**
|
|
168
169
|
* Hook that returns all discovered routes as a flat list
|