@donotdev/ui 0.3.1 → 0.3.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.
- package/README.md +2 -3
- package/dist/components/auth/AuthHeader.js +1 -93
- package/dist/components/auth/AuthMenu.d.ts.map +1 -1
- package/dist/components/auth/AuthMenu.js +3 -286
- package/dist/components/auth/index.js +1 -9
- package/dist/components/common/FeatureCard.d.ts.map +1 -1
- package/dist/components/common/FeatureCard.js +1 -86
- package/dist/components/common/FeatureDisabled.js +1 -67
- package/dist/components/common/IconPlaceholder.d.ts +24 -0
- package/dist/components/common/IconPlaceholder.d.ts.map +1 -0
- package/dist/components/common/IconPlaceholder.js +1 -0
- package/dist/components/common/LazyLucideIcon.d.ts +39 -0
- package/dist/components/common/LazyLucideIcon.d.ts.map +1 -0
- package/dist/components/common/LazyLucideIcon.js +1 -0
- package/dist/components/common/ProgressBar.js +1 -84
- package/dist/components/common/RedirectOverlay.js +1 -243
- package/dist/components/common/Skeleton.js +1 -144
- package/dist/components/common/TechBento.d.ts.map +1 -1
- package/dist/components/common/TechBento.js +1 -53
- package/dist/components/common/icon.d.ts +1 -1
- package/dist/components/common/icon.d.ts.map +1 -1
- package/dist/components/common/icon.js +1 -84
- package/dist/components/common/iconByName.d.ts +33 -0
- package/dist/components/common/iconByName.d.ts.map +1 -0
- package/dist/components/common/iconByName.js +1 -0
- package/dist/components/common/index.js +1 -16
- package/dist/components/cookie-consent/ConsentBanner.d.ts +3 -1
- package/dist/components/cookie-consent/ConsentBanner.d.ts.map +1 -1
- package/dist/components/cookie-consent/ConsentBanner.js +1 -31
- package/dist/components/cookie-consent/CookieConsent.d.ts.map +1 -1
- package/dist/components/cookie-consent/CookieConsent.js +1 -183
- package/dist/components/cookie-consent/index.js +1 -11
- package/dist/components/cookie-consent/useCookieNoticeRequired.d.ts +7 -0
- package/dist/components/cookie-consent/useCookieNoticeRequired.d.ts.map +1 -0
- package/dist/components/cookie-consent/useCookieNoticeRequired.js +1 -0
- package/dist/components/index.js +1 -13
- package/dist/components/layout/GameContainer.d.ts.map +1 -1
- package/dist/components/layout/GameContainer.js +1 -72
- package/dist/components/layout/GameFlow.d.ts.map +1 -1
- package/dist/components/layout/GameFlow.js +1 -93
- package/dist/components/layout/PageConfig.d.ts.map +1 -1
- package/dist/components/layout/PageConfig.js +1 -47
- package/dist/components/layout/PageContainer.d.ts.map +1 -1
- package/dist/components/layout/PageContainer.js +1 -38
- package/dist/components/layout/components/Breadcrumbs.d.ts +2 -1
- package/dist/components/layout/components/Breadcrumbs.d.ts.map +1 -1
- package/dist/components/layout/components/Breadcrumbs.js +1 -89
- package/dist/components/layout/components/DropdownNavigation.d.ts.map +1 -1
- package/dist/components/layout/components/DropdownNavigation.js +1 -30
- package/dist/components/layout/components/FloatingLanguageSwitcher.d.ts.map +1 -1
- package/dist/components/layout/components/FloatingLanguageSwitcher.js +1 -26
- package/dist/components/layout/components/Notifications.js +1 -182
- package/dist/components/layout/components/header/AppBranding.d.ts.map +1 -1
- package/dist/components/layout/components/header/AppBranding.js +1 -54
- package/dist/components/layout/components/header/AppIcon.d.ts.map +1 -1
- package/dist/components/layout/components/header/AppIcon.js +1 -59
- package/dist/components/layout/components/header/AppTitle.d.ts.map +1 -1
- package/dist/components/layout/components/header/AppTitle.js +1 -40
- package/dist/components/layout/components/header/CacheSettings.js +1 -225
- package/dist/components/layout/components/header/GameTitle.d.ts.map +1 -1
- package/dist/components/layout/components/header/GameTitle.js +1 -66
- package/dist/components/layout/components/header/HeaderMenu.js +1 -75
- package/dist/components/layout/components/header/HeaderNavigation.d.ts.map +1 -1
- package/dist/components/layout/components/header/HeaderNavigation.js +1 -66
- package/dist/components/layout/components/header/SettingsMenu.d.ts.map +1 -1
- package/dist/components/layout/components/header/SettingsMenu.js +1 -85
- package/dist/components/layout/components/header/ThemeToggle.d.ts.map +1 -1
- package/dist/components/layout/components/header/ThemeToggle.js +1 -93
- package/dist/components/layout/components/index.js +1 -25
- package/dist/components/layout/index.js +1 -14
- package/dist/crud/components/ChildRowsPicker.js +1 -68
- package/dist/crud/components/CrudCardLink.js +1 -14
- package/dist/crud/components/EntityCardList.d.ts +4 -1
- package/dist/crud/components/EntityCardList.d.ts.map +1 -1
- package/dist/crud/components/EntityCardList.js +1 -184
- package/dist/crud/components/EntityDisplayRenderer.js +1 -130
- package/dist/crud/components/EntityFormRenderer.js +1 -433
- package/dist/crud/components/EntityList.js +1 -521
- package/dist/crud/components/EntityRecommendations.js +1 -87
- package/dist/crud/components/EntityWorkflow.js +1 -55
- package/dist/crud/components/Form.d.ts.map +1 -1
- package/dist/crud/components/Form.js +1 -198
- package/dist/crud/components/cellEditFor.js +1 -74
- package/dist/crud/components/entityParent.js +1 -76
- package/dist/crud/components/index.js +1 -16
- package/dist/crud/components/useRecordBreadcrumb.d.ts +3 -1
- package/dist/crud/components/useRecordBreadcrumb.d.ts.map +1 -1
- package/dist/crud/components/useRecordBreadcrumb.js +1 -43
- package/dist/crud/crudImports.js +1 -51
- package/dist/crud/index.js +1 -11
- package/dist/data/techLogos.js +1 -99
- package/dist/dndev-next.css +113 -41
- package/dist/dndev.css +113 -41
- package/dist/index.js +1 -5
- package/dist/internal/common/DnDevErrorBoundary.js +1 -55
- package/dist/internal/common/ErrorFallback.js +3 -214
- package/dist/internal/common/GlobalErrorFallback.js +1 -45
- package/dist/internal/common/RouteErrorFallback.js +3 -140
- package/dist/internal/devtools/DebugTools.js +1 -131
- package/dist/internal/devtools/components/AuthDebugButton.js +1 -72
- package/dist/internal/devtools/components/ConfigTab.js +1 -61
- package/dist/internal/devtools/components/CookieTab.js +1 -156
- package/dist/internal/devtools/components/DebugDialog.js +1 -48
- package/dist/internal/devtools/components/DesignTab.js +1 -469
- package/dist/internal/devtools/components/LayoutReset.js +1 -214
- package/dist/internal/devtools/components/MaskedValue.js +1 -39
- package/dist/internal/devtools/components/StoresTab.js +1 -90
- package/dist/internal/devtools/components/index.js +1 -16
- package/dist/internal/devtools/index.js +1 -13
- package/dist/internal/devtools/types.js +0 -2
- package/dist/internal/devtools/utils/envVarDiscovery.js +1 -106
- package/dist/internal/devtools/utils/index.js +1 -12
- package/dist/internal/devtools/utils/maskSensitive.js +1 -59
- package/dist/internal/devtools/utils/virtualModuleInspector.js +1 -309
- package/dist/internal/initializers/BaseStoresInitializer.js +1 -367
- package/dist/internal/initializers/NextJsStoresInitializer.js +1 -78
- package/dist/internal/initializers/ViteStoresInitializer.js +1 -20
- package/dist/internal/initializers/index.js +1 -11
- package/dist/internal/layout/DnDevLayout.js +1 -321
- package/dist/internal/layout/components/AutoMetaTags.d.ts +5 -0
- package/dist/internal/layout/components/AutoMetaTags.d.ts.map +1 -1
- package/dist/internal/layout/components/AutoMetaTags.js +1 -338
- package/dist/internal/layout/components/FaviconHead.d.ts +18 -14
- package/dist/internal/layout/components/FaviconHead.d.ts.map +1 -1
- package/dist/internal/layout/components/FaviconHead.js +1 -60
- package/dist/internal/layout/components/FontPreloadLinks.js +1 -31
- package/dist/internal/layout/components/HeadTags.js +1 -20
- package/dist/internal/layout/components/PWAUpdateNotification.js +1 -131
- package/dist/internal/layout/components/footer/FooterBranding.d.ts.map +1 -1
- package/dist/internal/layout/components/footer/FooterBranding.js +1 -35
- package/dist/internal/layout/components/footer/FooterCopyright.d.ts.map +1 -1
- package/dist/internal/layout/components/footer/FooterCopyright.js +1 -37
- package/dist/internal/layout/components/footer/FooterLegalLinks.d.ts.map +1 -1
- package/dist/internal/layout/components/footer/FooterLegalLinks.js +1 -44
- package/dist/internal/layout/components/footer/useLegalLinks.d.ts +4 -2
- package/dist/internal/layout/components/footer/useLegalLinks.d.ts.map +1 -1
- package/dist/internal/layout/components/footer/useLegalLinks.js +1 -21
- package/dist/internal/layout/components/headTagElement.d.ts +16 -0
- package/dist/internal/layout/components/headTagElement.d.ts.map +1 -0
- package/dist/internal/layout/components/headTagElement.js +1 -0
- package/dist/internal/layout/components/index.js +1 -13
- package/dist/internal/layout/components/prerenderedHead.d.ts +15 -0
- package/dist/internal/layout/components/prerenderedHead.d.ts.map +1 -0
- package/dist/internal/layout/components/prerenderedHead.js +1 -0
- package/dist/internal/layout/components/trailingSlash.d.ts +13 -0
- package/dist/internal/layout/components/trailingSlash.d.ts.map +1 -0
- package/dist/internal/layout/components/trailingSlash.js +1 -0
- package/dist/internal/layout/config/defaults.js +1 -47
- package/dist/internal/layout/config/index.js +1 -11
- package/dist/internal/layout/config/presets/admin.js +1 -35
- package/dist/internal/layout/config/presets/blog.js +1 -31
- package/dist/internal/layout/config/presets/docs.js +1 -51
- package/dist/internal/layout/config/presets/game.js +1 -53
- package/dist/internal/layout/config/presets/index.js +1 -24
- package/dist/internal/layout/config/presets/landing.js +1 -42
- package/dist/internal/layout/config/presets/moolti.js +1 -52
- package/dist/internal/layout/config/presets/plain.js +1 -25
- package/dist/internal/layout/renderers/index.js +0 -10
- package/dist/internal/layout/zones/DnDevFooter.d.ts.map +1 -1
- package/dist/internal/layout/zones/DnDevFooter.js +1 -67
- package/dist/internal/layout/zones/DnDevHeader.js +1 -41
- package/dist/internal/layout/zones/DnDevMergedBar.d.ts.map +1 -1
- package/dist/internal/layout/zones/DnDevMergedBar.js +1 -52
- package/dist/internal/layout/zones/DnDevSidebar.d.ts.map +1 -1
- package/dist/internal/layout/zones/DnDevSidebar.js +1 -181
- package/dist/internal/layout/zones/index.js +1 -14
- package/dist/internal/providers/NavigationProvider.d.ts.map +1 -1
- package/dist/internal/providers/NavigationProvider.js +1 -71
- package/dist/internal/providers/SentryInitializer.d.ts.map +1 -1
- package/dist/internal/providers/SentryInitializer.js +1 -36
- package/dist/internal/providers/UIProviders.js +1 -79
- package/dist/internal/providers/index.js +1 -12
- package/dist/next.js +1 -11
- package/dist/providers/NextJsAppProviders.d.ts.map +1 -1
- package/dist/providers/NextJsAppProviders.js +1 -107
- package/dist/providers/ViteAppProviders.d.ts +11 -9
- package/dist/providers/ViteAppProviders.d.ts.map +1 -1
- package/dist/providers/ViteAppProviders.js +1 -117
- package/dist/providers/index.js +1 -11
- package/dist/routing/404.js +1 -108
- package/dist/routing/AuthGuard.js +1 -178
- package/dist/routing/AuthGuardFallback.d.ts.map +1 -1
- package/dist/routing/AuthGuardFallback.js +1 -67
- package/dist/routing/AuthReturnTo.js +1 -68
- package/dist/routing/DnDevNavigationMenu.d.ts.map +1 -1
- package/dist/routing/DnDevNavigationMenu.js +1 -138
- package/dist/routing/GoTo.d.ts.map +1 -1
- package/dist/routing/GoTo.js +1 -38
- package/dist/routing/GoToDialog.d.ts.map +1 -1
- package/dist/routing/GoToDialog.js +1 -97
- package/dist/routing/GoToInput.d.ts.map +1 -1
- package/dist/routing/GoToInput.js +1 -49
- package/dist/routing/GoToWrapper.d.ts.map +1 -1
- package/dist/routing/GoToWrapper.js +1 -59
- package/dist/routing/Link.d.ts +10 -2
- package/dist/routing/Link.d.ts.map +1 -1
- package/dist/routing/Link.js +1 -109
- package/dist/routing/NavigationItem.d.ts.map +1 -1
- package/dist/routing/NavigationItem.js +1 -44
- package/dist/routing/NotFoundDocument.d.ts +33 -0
- package/dist/routing/NotFoundDocument.d.ts.map +1 -0
- package/dist/routing/NotFoundDocument.js +1 -0
- package/dist/routing/SignedInRedirect.js +1 -47
- package/dist/routing/hooks/hooks.next.js +1 -1
- package/dist/routing/hooks/hooks.vite.js +1 -1
- package/dist/routing/hooks/index.js +1 -26
- package/dist/routing/hooks/types.js +0 -2
- package/dist/routing/hooks/useLocation.next.js +1 -35
- package/dist/routing/hooks/useLocation.vite.js +1 -13
- package/dist/routing/hooks/useMatch.next.js +1 -31
- package/dist/routing/hooks/useMatch.vite.js +1 -6
- package/dist/routing/hooks/useNavigate.next.js +1 -64
- package/dist/routing/hooks/useNavigate.vite.js +1 -61
- package/dist/routing/hooks/useParams.next.js +1 -9
- package/dist/routing/hooks/useParams.vite.js +1 -6
- package/dist/routing/hooks/useQueryParams.next.js +1 -66
- package/dist/routing/hooks/useQueryParams.vite.js +1 -66
- package/dist/routing/hooks/useRedirectGuard.next.js +1 -119
- package/dist/routing/hooks/useRedirectGuard.vite.js +1 -117
- package/dist/routing/hooks/useRouteParam.next.js +1 -38
- package/dist/routing/hooks/useRouteParam.vite.js +1 -38
- package/dist/routing/hooks/useRoutePath.next.d.ts +5 -3
- package/dist/routing/hooks/useRoutePath.next.d.ts.map +1 -1
- package/dist/routing/hooks/useRoutePath.next.js +1 -36
- package/dist/routing/hooks/useRoutePath.vite.js +1 -25
- package/dist/routing/hooks/useSearchParams.next.js +1 -22
- package/dist/routing/hooks/useSearchParams.vite.js +1 -22
- package/dist/routing/hooks/useUrlLanguage.next.js +1 -50
- package/dist/routing/hooks/useUrlLanguage.vite.js +1 -41
- package/dist/routing/index.d.ts +1 -0
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/index.js +1 -32
- package/dist/routing/link/InternalLink.next.d.ts +23 -0
- package/dist/routing/link/InternalLink.next.d.ts.map +1 -0
- package/dist/routing/link/InternalLink.next.js +1 -0
- package/dist/routing/link/InternalLink.vite.d.ts +22 -0
- package/dist/routing/link/InternalLink.vite.d.ts.map +1 -0
- package/dist/routing/link/InternalLink.vite.js +1 -0
- package/dist/routing/link/absolutePath.d.ts +17 -0
- package/dist/routing/link/absolutePath.d.ts.map +1 -0
- package/dist/routing/link/absolutePath.js +1 -0
- package/dist/routing/link/link.next.d.ts +12 -0
- package/dist/routing/link/link.next.d.ts.map +1 -0
- package/dist/routing/link/link.next.js +1 -0
- package/dist/routing/link/link.vite.d.ts +12 -0
- package/dist/routing/link/link.vite.d.ts.map +1 -0
- package/dist/routing/link/link.vite.js +1 -0
- package/dist/routing/link/types.d.ts +30 -0
- package/dist/routing/link/types.d.ts.map +1 -0
- package/dist/routing/link/types.js +0 -0
- package/dist/routing/parentRoute.js +1 -43
- package/dist/routing/useGoTo.d.ts.map +1 -1
- package/dist/routing/useGoTo.js +1 -59
- package/dist/routing/useNavigation.d.ts.map +1 -1
- package/dist/routing/useNavigation.js +1 -114
- package/dist/routing/useRouteDiscovery.d.ts +4 -0
- package/dist/routing/useRouteDiscovery.d.ts.map +1 -1
- package/dist/routing/useRouteDiscovery.js +1 -313
- package/dist/rsc.d.ts +28 -0
- package/dist/rsc.d.ts.map +1 -0
- package/dist/rsc.js +1 -0
- package/dist/styles/index.css +113 -41
- package/dist/styles/index.js +1 -10
- package/dist/styles/layoutConstants.js +1 -134
- package/dist/symbol-index.json +1 -1
- package/dist/utils/assetResolver.d.ts +19 -19
- package/dist/utils/assetResolver.d.ts.map +1 -1
- package/dist/utils/assetResolver.js +1 -297
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -23
- package/dist/utils/sanitizeSvg.js +1 -51
- package/dist/utils/tList.js +1 -42
- package/dist/utils/useAISafe.d.ts.map +1 -1
- package/dist/utils/useAISafe.js +1 -53
- package/dist/utils/useAuthSafe.d.ts.map +1 -1
- package/dist/utils/useAuthSafe.js +1 -78
- package/dist/utils/useAuthVisibility.d.ts.map +1 -1
- package/dist/utils/useAuthVisibility.js +1 -63
- package/dist/utils/useBillingVisibility.d.ts.map +1 -1
- package/dist/utils/useBillingVisibility.js +1 -57
- package/dist/utils/useCrudSafe.d.ts.map +1 -1
- package/dist/utils/useCrudSafe.js +1 -75
- package/dist/utils/useDeleteAccountSafe.js +1 -52
- package/dist/utils/useFormStoreSafe.d.ts.map +1 -1
- package/dist/utils/useFormStoreSafe.js +1 -85
- package/dist/utils/useOAuthSafe.d.ts.map +1 -1
- package/dist/utils/useOAuthSafe.js +1 -38
- package/dist/utils/useStripeBillingSafe.d.ts.map +1 -1
- package/dist/utils/useStripeBillingSafe.js +1 -81
- package/dist/vite-routing/AppRoutes.d.ts.map +1 -1
- package/dist/vite-routing/AppRoutes.js +1 -235
- package/dist/vite-routing/RootLayout.d.ts.map +1 -1
- package/dist/vite-routing/RootLayout.js +1 -205
- package/dist/vite-routing/index.js +1 -11
- package/dist/vite.js +1 -10
- package/guidelines/COMPONENTS.md +3 -3
- package/guidelines/PAGES.md +3 -0
- package/guidelines/ROUTING.md +16 -0
- package/guidelines/SEO.md +160 -142
- package/package.json +18 -8
- package/dist/ChildRowsPicker-63M4EQUQ.js +0 -1
- package/dist/ChildRowsPicker-ISP365ON.js +0 -1
- package/dist/ChildRowsPicker-PQFE6NCR.js +0 -1
- package/dist/ChildRowsPicker-XXFFSMWY.js +0 -1
- package/dist/CookieConsent-QOUAY6B4.js +0 -1
- package/dist/GoToDialog-KSBGOIWO.js +0 -1
- package/dist/GoToDialog-XBK5EZF4.js +0 -1
- package/dist/chunk-3CIZFGST.js +0 -1
- package/dist/chunk-LHMKU342.js +0 -1
- package/dist/chunk-MS7ZIW5Z.js +0 -1
- package/dist/chunk-O2XFH626.js +0 -1
- package/dist/chunk-P2DHZWPY.js +0 -1
- package/dist/components/common/lucideIconByName.d.ts +0 -9
- package/dist/components/common/lucideIconByName.d.ts.map +0 -1
- package/dist/components/common/lucideIconByName.js +0 -32
- package/dist/internal/layout/components/PerformanceHints.d.ts +0 -71
- package/dist/internal/layout/components/PerformanceHints.d.ts.map +0 -1
- package/dist/internal/layout/components/PerformanceHints.js +0 -71
- package/dist/internal/layout/components/i18nSeoMeta.d.ts +0 -54
- package/dist/internal/layout/components/i18nSeoMeta.d.ts.map +0 -1
- package/dist/internal/layout/components/i18nSeoMeta.js +0 -53
- package/dist/utils/useSeo.d.ts +0 -129
- package/dist/utils/useSeo.d.ts.map +0 -1
- package/dist/utils/useSeo.js +0 -151
|
@@ -1,64 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// packages/ui/src/routing/hooks/useNavigate.next.ts
|
|
3
|
-
/**
|
|
4
|
-
* @fileoverview Next.js-specific navigation hooks
|
|
5
|
-
* @description Navigation hooks for Next.js App Router
|
|
6
|
-
*
|
|
7
|
-
* @version 0.3.0
|
|
8
|
-
* @since 0.0.1
|
|
9
|
-
* @author AMBROISE PARK Consulting
|
|
10
|
-
*/
|
|
11
|
-
import { useRouter as useNextRouter } from 'next/navigation';
|
|
12
|
-
import { isClient, useOverlayStore } from '@donotdev/core';
|
|
13
|
-
import { useLocalizedPath } from './useUrlLanguage.next';
|
|
14
|
-
/**
|
|
15
|
-
* Navigation hook. Auth is handled by AuthGuard (cold-load redirect).
|
|
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
|
|
22
|
-
*/
|
|
23
|
-
export function useNavigate() {
|
|
24
|
-
const router = useNextRouter();
|
|
25
|
-
const closeAll = useOverlayStore((state) => state.closeAll);
|
|
26
|
-
const localize = useLocalizedPath();
|
|
27
|
-
return (path, options) => {
|
|
28
|
-
if (path === 'back') {
|
|
29
|
-
closeAll();
|
|
30
|
-
return router.back();
|
|
31
|
-
}
|
|
32
|
-
closeAll();
|
|
33
|
-
const to = localize(path);
|
|
34
|
-
if (options?.preserveScroll && isClient()) {
|
|
35
|
-
const scrollY = window.scrollY;
|
|
36
|
-
if (options?.replace) {
|
|
37
|
-
router.replace(to);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
router.push(to);
|
|
41
|
-
}
|
|
42
|
-
requestAnimationFrame(() => {
|
|
43
|
-
window.scrollTo({ top: scrollY, behavior: 'auto' });
|
|
44
|
-
});
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (options?.replace)
|
|
48
|
-
return router.replace(to);
|
|
49
|
-
return router.push(to);
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
export function useBack() {
|
|
53
|
-
const router = useNextRouter();
|
|
54
|
-
return () => router.back();
|
|
55
|
-
}
|
|
56
|
-
export function useRefresh() {
|
|
57
|
-
const router = useNextRouter();
|
|
58
|
-
return () => router.refresh();
|
|
59
|
-
}
|
|
60
|
-
export function usePrefetch() {
|
|
61
|
-
const router = useNextRouter();
|
|
62
|
-
const localize = useLocalizedPath();
|
|
63
|
-
return (to) => router.prefetch(localize(to));
|
|
64
|
-
}
|
|
1
|
+
"use client";import{useRouter as s}from"next/navigation";import{isClient as l,useOverlayStore as a}from"@donotdev/core";import{useLocalizedPath as u}from"./useUrlLanguage.next.js";function h(){let e=s(),r=a(t=>t.closeAll),c=u();return(t,n)=>{if(t==="back")return r(),e.back();r();let o=c(t);if(n?.preserveScroll&&l()){let i=window.scrollY;n?.replace?e.replace(o):e.push(o),requestAnimationFrame(()=>{window.scrollTo({top:i,behavior:"auto"})});return}return n?.replace?e.replace(o):e.push(o)}}function v(){let e=s();return()=>e.back()}function g(){let e=s();return()=>e.refresh()}function x(){let e=s(),r=u();return c=>e.prefetch(r(c))}export{v as useBack,h as useNavigate,x as usePrefetch,g as useRefresh};
|
|
@@ -1,61 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// packages/ui/src/routing/hooks/useNavigate.vite.ts
|
|
3
|
-
/**
|
|
4
|
-
* @fileoverview Vite-specific navigation hooks
|
|
5
|
-
* @description Navigation hooks for React Router (Vite)
|
|
6
|
-
*
|
|
7
|
-
* @version 0.3.0
|
|
8
|
-
* @since 0.0.1
|
|
9
|
-
* @author AMBROISE PARK Consulting
|
|
10
|
-
*/
|
|
11
|
-
import { useNavigate as useRouterNavigate } from 'react-router-dom';
|
|
12
|
-
import { getLanguageRouting, isClient, splitLanguagePath, useOverlayStore, } from '@donotdev/core';
|
|
13
|
-
import { useUrlLanguage } from './useUrlLanguage.vite';
|
|
14
|
-
/**
|
|
15
|
-
* Navigation hook. Auth is handled by AuthGuard (cold-load redirect).
|
|
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
|
|
23
|
-
*/
|
|
24
|
-
export function useNavigate() {
|
|
25
|
-
const routerNavigate = useRouterNavigate();
|
|
26
|
-
const closeAll = useOverlayStore((state) => state.closeAll);
|
|
27
|
-
const language = useUrlLanguage();
|
|
28
|
-
return (path, options) => {
|
|
29
|
-
if (path === 'back') {
|
|
30
|
-
closeAll();
|
|
31
|
-
return routerNavigate(-1);
|
|
32
|
-
}
|
|
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;
|
|
42
|
-
if (options?.replace)
|
|
43
|
-
return routerNavigate(to, { replace: true });
|
|
44
|
-
return routerNavigate(to);
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
export function useBack() {
|
|
48
|
-
const navigate = useRouterNavigate();
|
|
49
|
-
return () => navigate(-1);
|
|
50
|
-
}
|
|
51
|
-
export function useRefresh() {
|
|
52
|
-
return () => {
|
|
53
|
-
if (isClient())
|
|
54
|
-
window.location.reload();
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
export function usePrefetch() {
|
|
58
|
-
return (_to) => {
|
|
59
|
-
// Vite: no-op
|
|
60
|
-
};
|
|
61
|
-
}
|
|
1
|
+
"use client";import{useNavigate as i}from"react-router-dom";import{getLanguageRouting as u,isClient as g,splitLanguagePath as l,useOverlayStore as c}from"@donotdev/core";import{useUrlLanguage as f}from"./useUrlLanguage.vite.js";function x(){let t=i(),n=c(e=>e.closeAll),a=f();return(e,s)=>{if(e==="back")return n(),t(-1);n();let r=e.startsWith("/")?l(e,u()):null;if(r?.prefixed&&r.language!==a){window.location.assign(e);return}let o=r?.prefixed?r.path:e;return s?.replace?t(o,{replace:!0}):t(o)}}function N(){let t=i();return()=>t(-1)}function d(){return()=>{g()&&window.location.reload()}}function w(){return t=>{}}export{N as useBack,x as useNavigate,w as usePrefetch,d as useRefresh};
|
|
@@ -1,9 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// packages/ui/src/routing/hooks/useParams.next.ts
|
|
3
|
-
import { useParams as useNextParams } from 'next/navigation';
|
|
4
|
-
export function useParams() {
|
|
5
|
-
const params = useNextParams();
|
|
6
|
-
if (!params)
|
|
7
|
-
return {};
|
|
8
|
-
return params;
|
|
9
|
-
}
|
|
1
|
+
"use client";import{useParams as s}from"next/navigation";function n(){let r=s();return r||{}}export{n as useParams};
|
|
@@ -1,6 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// packages/ui/src/routing/hooks/useParams.vite.ts
|
|
3
|
-
import { useParams as useRouterParams } from 'react-router-dom';
|
|
4
|
-
export function useParams() {
|
|
5
|
-
return useRouterParams();
|
|
6
|
-
}
|
|
1
|
+
"use client";import{useParams as r}from"react-router-dom";function s(){return r()}export{s as useParams};
|
|
@@ -1,66 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// packages/ui/src/routing/hooks/useQueryParams.next.ts
|
|
3
|
-
/**
|
|
4
|
-
* @fileoverview Next.js-specific useQueryParams hook
|
|
5
|
-
* @description Query parameters hook with setter functionality for App Router
|
|
6
|
-
*
|
|
7
|
-
* @version 0.1.0
|
|
8
|
-
* @since 0.0.1
|
|
9
|
-
* @author AMBROISE PARK Consulting
|
|
10
|
-
*/
|
|
11
|
-
import { useCallback } from 'react';
|
|
12
|
-
import { useLocation } from './useLocation.next';
|
|
13
|
-
import { useNavigate } from './useNavigate.next';
|
|
14
|
-
import { useSearchParams } from './useSearchParams.next';
|
|
15
|
-
/**
|
|
16
|
-
* Platform-agnostic useQueryParams hook
|
|
17
|
-
*
|
|
18
|
-
* Provides easy access to query parameters with setter functionality
|
|
19
|
-
*
|
|
20
|
-
* @returns Object with query parameters and setter functions
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```tsx
|
|
24
|
-
* const { query, setQuery, removeQuery } = useQueryParams();
|
|
25
|
-
*
|
|
26
|
-
* // Get a query parameter
|
|
27
|
-
* const page = query.get('page');
|
|
28
|
-
*
|
|
29
|
-
* // Set a query parameter
|
|
30
|
-
* setQuery('page', '2');
|
|
31
|
-
*
|
|
32
|
-
* // Remove a query parameter
|
|
33
|
-
* removeQuery('page');
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export function useQueryParams() {
|
|
37
|
-
const searchParams = useSearchParams();
|
|
38
|
-
const navigate = useNavigate();
|
|
39
|
-
const location = useLocation();
|
|
40
|
-
const setQuery = useCallback((key, value) => {
|
|
41
|
-
const newParams = new URLSearchParams(searchParams.toString());
|
|
42
|
-
newParams.set(key, value);
|
|
43
|
-
const newSearch = newParams.toString();
|
|
44
|
-
const pathname = location.pathname || '/';
|
|
45
|
-
const newUrl = `${pathname}${newSearch ? `?${newSearch}` : ''}`;
|
|
46
|
-
navigate(newUrl);
|
|
47
|
-
}, [searchParams, navigate, location.pathname]);
|
|
48
|
-
const removeQuery = useCallback((key) => {
|
|
49
|
-
const newParams = new URLSearchParams(searchParams.toString());
|
|
50
|
-
newParams.delete(key);
|
|
51
|
-
const newSearch = newParams.toString();
|
|
52
|
-
const pathname = location.pathname || '/';
|
|
53
|
-
const newUrl = `${pathname}${newSearch ? `?${newSearch}` : ''}`;
|
|
54
|
-
navigate(newUrl);
|
|
55
|
-
}, [searchParams, navigate, location.pathname]);
|
|
56
|
-
const clearQueries = useCallback(() => {
|
|
57
|
-
const pathname = location.pathname || '/';
|
|
58
|
-
navigate(pathname);
|
|
59
|
-
}, [navigate, location.pathname]);
|
|
60
|
-
return {
|
|
61
|
-
query: searchParams,
|
|
62
|
-
setQuery,
|
|
63
|
-
removeQuery,
|
|
64
|
-
clearQueries,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
1
|
+
"use client";import{useCallback as c}from"react";import{useLocation as g}from"./useLocation.next.js";import{useNavigate as S}from"./useNavigate.next.js";import{useSearchParams as l}from"./useSearchParams.next.js";function y(){let e=l(),t=S(),a=g(),i=c((n,s)=>{let r=new URLSearchParams(e.toString());r.set(n,s);let o=r.toString(),u=`${a.pathname||"/"}${o?`?${o}`:""}`;t(u)},[e,t,a.pathname]),h=c(n=>{let s=new URLSearchParams(e.toString());s.delete(n);let r=s.toString(),m=`${a.pathname||"/"}${r?`?${r}`:""}`;t(m)},[e,t,a.pathname]),p=c(()=>{let n=a.pathname||"/";t(n)},[t,a.pathname]);return{query:e,setQuery:i,removeQuery:h,clearQueries:p}}export{y as useQueryParams};
|
|
@@ -1,66 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// packages/ui/src/routing/hooks/useQueryParams.vite.ts
|
|
3
|
-
/**
|
|
4
|
-
* @fileoverview Vite-specific useQueryParams hook
|
|
5
|
-
* @description Query parameters hook with setter functionality for React Router
|
|
6
|
-
*
|
|
7
|
-
* @version 0.1.0
|
|
8
|
-
* @since 0.0.1
|
|
9
|
-
* @author AMBROISE PARK Consulting
|
|
10
|
-
*/
|
|
11
|
-
import { useCallback } from 'react';
|
|
12
|
-
import { useLocation } from './useLocation.vite';
|
|
13
|
-
import { useNavigate } from './useNavigate.vite';
|
|
14
|
-
import { useSearchParams } from './useSearchParams.vite';
|
|
15
|
-
/**
|
|
16
|
-
* Platform-agnostic useQueryParams hook
|
|
17
|
-
*
|
|
18
|
-
* Provides easy access to query parameters with setter functionality
|
|
19
|
-
*
|
|
20
|
-
* @returns Object with query parameters and setter functions
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```tsx
|
|
24
|
-
* const { query, setQuery, removeQuery } = useQueryParams();
|
|
25
|
-
*
|
|
26
|
-
* // Get a query parameter
|
|
27
|
-
* const page = query.get('page');
|
|
28
|
-
*
|
|
29
|
-
* // Set a query parameter
|
|
30
|
-
* setQuery('page', '2');
|
|
31
|
-
*
|
|
32
|
-
* // Remove a query parameter
|
|
33
|
-
* removeQuery('page');
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export function useQueryParams() {
|
|
37
|
-
const searchParams = useSearchParams();
|
|
38
|
-
const navigate = useNavigate();
|
|
39
|
-
const location = useLocation();
|
|
40
|
-
const setQuery = useCallback((key, value) => {
|
|
41
|
-
const newParams = new URLSearchParams(searchParams.toString());
|
|
42
|
-
newParams.set(key, value);
|
|
43
|
-
const newSearch = newParams.toString();
|
|
44
|
-
const pathname = location.pathname || '/';
|
|
45
|
-
const newUrl = `${pathname}${newSearch ? `?${newSearch}` : ''}`;
|
|
46
|
-
navigate(newUrl);
|
|
47
|
-
}, [searchParams, navigate, location.pathname]);
|
|
48
|
-
const removeQuery = useCallback((key) => {
|
|
49
|
-
const newParams = new URLSearchParams(searchParams.toString());
|
|
50
|
-
newParams.delete(key);
|
|
51
|
-
const newSearch = newParams.toString();
|
|
52
|
-
const pathname = location.pathname || '/';
|
|
53
|
-
const newUrl = `${pathname}${newSearch ? `?${newSearch}` : ''}`;
|
|
54
|
-
navigate(newUrl);
|
|
55
|
-
}, [searchParams, navigate, location.pathname]);
|
|
56
|
-
const clearQueries = useCallback(() => {
|
|
57
|
-
const pathname = location.pathname || '/';
|
|
58
|
-
navigate(pathname);
|
|
59
|
-
}, [navigate, location.pathname]);
|
|
60
|
-
return {
|
|
61
|
-
query: searchParams,
|
|
62
|
-
setQuery,
|
|
63
|
-
removeQuery,
|
|
64
|
-
clearQueries,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
1
|
+
"use client";import{useCallback as c}from"react";import{useLocation as g}from"./useLocation.vite.js";import{useNavigate as S}from"./useNavigate.vite.js";import{useSearchParams as l}from"./useSearchParams.vite.js";function y(){let e=l(),t=S(),a=g(),i=c((n,s)=>{let r=new URLSearchParams(e.toString());r.set(n,s);let o=r.toString(),u=`${a.pathname||"/"}${o?`?${o}`:""}`;t(u)},[e,t,a.pathname]),h=c(n=>{let s=new URLSearchParams(e.toString());s.delete(n);let r=s.toString(),m=`${a.pathname||"/"}${r?`?${r}`:""}`;t(m)},[e,t,a.pathname]),p=c(()=>{let n=a.pathname||"/";t(n)},[t,a.pathname]);return{query:e,setQuery:i,removeQuery:h,clearQueries:p}}export{y as useQueryParams};
|
|
@@ -1,119 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// packages/ui/src/routing/hooks/useRedirectGuard.next.ts
|
|
3
|
-
/**
|
|
4
|
-
* @fileoverview Next.js Redirect Guard Hook
|
|
5
|
-
* @description Determines redirect state before render. Prevents content flash.
|
|
6
|
-
*
|
|
7
|
-
* @version 0.1.0
|
|
8
|
-
* @since 0.0.1
|
|
9
|
-
* @author AMBROISE PARK Consulting
|
|
10
|
-
*/
|
|
11
|
-
import { useMemo } from 'react';
|
|
12
|
-
import { isClient, FEATURE_STATUS } from '@donotdev/core';
|
|
13
|
-
import { useAppConfig, useAuthConfig } from '@donotdev/core';
|
|
14
|
-
import { useAuthSafe } from '../../utils/useAuthSafe';
|
|
15
|
-
/**
|
|
16
|
-
* Hook that checks if redirect should happen before render
|
|
17
|
-
*
|
|
18
|
-
* Prevents content flash by determining redirect state synchronously.
|
|
19
|
-
* Returns safe defaults on server (SSR-safe). Reads the query string from
|
|
20
|
-
* `window.location` when it redirects, not through `useSearchParams`: a cached
|
|
21
|
-
* (static) page using it keeps its server-rendered HTML.
|
|
22
|
-
*
|
|
23
|
-
* @param options - Redirect guard configuration
|
|
24
|
-
* @returns Redirect guard state
|
|
25
|
-
*/
|
|
26
|
-
export function useRedirectGuard(options = {}) {
|
|
27
|
-
const { auth, redirectTo: customRedirectTo, condition } = options;
|
|
28
|
-
// Hooks must be called unconditionally (Rules of Hooks). No useLocation(): reading
|
|
29
|
-
// the query string through a hook would move a cached (static) page to the browser.
|
|
30
|
-
const authConfig = useAuthConfig();
|
|
31
|
-
const authDisabled = useAppConfig().auth === false;
|
|
32
|
-
const user = useAuthSafe('user');
|
|
33
|
-
const can = useAuthSafe('can');
|
|
34
|
-
const status = useAuthSafe('status');
|
|
35
|
-
// Determine redirect state
|
|
36
|
-
const redirectState = useMemo(() => {
|
|
37
|
-
const noAction = {
|
|
38
|
-
shouldRedirect: false,
|
|
39
|
-
redirectTo: null,
|
|
40
|
-
isChecking: false,
|
|
41
|
-
};
|
|
42
|
-
// SSR-safe: return safe defaults on server
|
|
43
|
-
if (!isClient())
|
|
44
|
-
return noAction;
|
|
45
|
-
// Only INITIALIZING = still checking. DEGRADED/ERROR/READY = auth resolved (proceed with current user)
|
|
46
|
-
if (status === FEATURE_STATUS.INITIALIZING) {
|
|
47
|
-
return { ...noAction, isChecking: true };
|
|
48
|
-
}
|
|
49
|
-
// Custom condition provided
|
|
50
|
-
if (condition) {
|
|
51
|
-
const shouldRedirect = condition(user, status);
|
|
52
|
-
return {
|
|
53
|
-
shouldRedirect,
|
|
54
|
-
redirectTo: shouldRedirect ? customRedirectTo || null : null,
|
|
55
|
-
isChecking: false,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
// Use auth config to determine redirect
|
|
59
|
-
if (auth !== false && auth !== undefined) {
|
|
60
|
-
if (!can)
|
|
61
|
-
return noAction;
|
|
62
|
-
// Check if user can navigate to this route
|
|
63
|
-
if (!can.navigate(auth)) {
|
|
64
|
-
// Redirect targets come from AppConfig.auth: none exist when auth is disabled
|
|
65
|
-
if (authDisabled && !customRedirectTo) {
|
|
66
|
-
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.");
|
|
67
|
-
}
|
|
68
|
-
let targetRoute = null;
|
|
69
|
-
// Authentication failure (not logged in) → always redirect
|
|
70
|
-
if (typeof auth === 'object' && auth.required && !user) {
|
|
71
|
-
// Check if we have OAuth parameters that need to be preserved
|
|
72
|
-
// (client only, see isClient() above: read at decision time)
|
|
73
|
-
const search = window.location.search;
|
|
74
|
-
const hasOAuthParams = search.includes('code=') ||
|
|
75
|
-
search.includes('state=') ||
|
|
76
|
-
search.includes('error=');
|
|
77
|
-
const authRoute = authConfig.authRoute;
|
|
78
|
-
if (hasOAuthParams) {
|
|
79
|
-
targetRoute = `${authRoute}${search}`;
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
targetRoute = authRoute;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// Authorization failure (wrong role)
|
|
86
|
-
else if (typeof auth === 'object' && auth.role) {
|
|
87
|
-
targetRoute = authConfig.roleRoute;
|
|
88
|
-
}
|
|
89
|
-
// Authorization failure (wrong tier)
|
|
90
|
-
else if (typeof auth === 'object' && auth.tier) {
|
|
91
|
-
targetRoute = authConfig.tierRoute;
|
|
92
|
-
}
|
|
93
|
-
// Fallback
|
|
94
|
-
else {
|
|
95
|
-
targetRoute = authConfig.roleRoute;
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
shouldRedirect: true,
|
|
99
|
-
redirectTo: customRedirectTo || targetRoute,
|
|
100
|
-
isChecking: false,
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
// No redirect needed
|
|
105
|
-
return noAction;
|
|
106
|
-
}, [
|
|
107
|
-
auth,
|
|
108
|
-
status,
|
|
109
|
-
user,
|
|
110
|
-
can,
|
|
111
|
-
condition,
|
|
112
|
-
customRedirectTo,
|
|
113
|
-
authDisabled,
|
|
114
|
-
authConfig.authRoute,
|
|
115
|
-
authConfig.roleRoute,
|
|
116
|
-
authConfig.tierRoute,
|
|
117
|
-
]);
|
|
118
|
-
return redirectState;
|
|
119
|
-
}
|
|
1
|
+
"use client";import{useMemo as p}from"react";import{isClient as g,FEATURE_STATUS as m}from"@donotdev/core";import{useAppConfig as A,useAuthConfig as T}from"@donotdev/core";import{useAuthSafe as l}from"../../utils/useAuthSafe.js";function y(h={}){let{auth:e,redirectTo:o,condition:s}=h,r=T(),d=A().auth===!1,n=l("user"),a=l("can"),c=l("status");return p(()=>{let i={shouldRedirect:!1,redirectTo:null,isChecking:!1};if(!g())return i;if(c===m.INITIALIZING)return{...i,isChecking:!0};if(s){let t=s(n,c);return{shouldRedirect:t,redirectTo:t&&o||null,isChecking:!1}}if(e!==!1&&e!==void 0){if(!a)return i;if(!a.navigate(e)){if(d&&!o)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 t=null;if(typeof e=="object"&&e.required&&!n){let u=window.location.search,R=u.includes("code=")||u.includes("state=")||u.includes("error="),f=r.authRoute;R?t=`${f}${u}`:t=f}else typeof e=="object"&&e.role?t=r.roleRoute:typeof e=="object"&&e.tier?t=r.tierRoute:t=r.roleRoute;return{shouldRedirect:!0,redirectTo:o||t,isChecking:!1}}}return i},[e,c,n,a,s,o,d,r.authRoute,r.roleRoute,r.tierRoute])}export{y as useRedirectGuard};
|
|
@@ -1,117 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// packages/ui/src/routing/hooks/useRedirectGuard.vite.ts
|
|
3
|
-
/**
|
|
4
|
-
* @fileoverview Vite Redirect Guard Hook
|
|
5
|
-
* @description Determines redirect state before render. Prevents content flash.
|
|
6
|
-
*
|
|
7
|
-
* @version 0.1.0
|
|
8
|
-
* @since 0.0.1
|
|
9
|
-
* @author AMBROISE PARK Consulting
|
|
10
|
-
*/
|
|
11
|
-
import { useMemo } from 'react';
|
|
12
|
-
import { isClient, FEATURE_STATUS } from '@donotdev/core';
|
|
13
|
-
import { useAppConfig, useAuthConfig } from '@donotdev/core';
|
|
14
|
-
import { useLocation } from './useLocation.vite';
|
|
15
|
-
import { useAuthSafe } from '../../utils/useAuthSafe';
|
|
16
|
-
/**
|
|
17
|
-
* Hook that checks if redirect should happen before render
|
|
18
|
-
*
|
|
19
|
-
* Prevents content flash by determining redirect state synchronously.
|
|
20
|
-
* Returns safe defaults on server (SSR-safe).
|
|
21
|
-
*
|
|
22
|
-
* @param options - Redirect guard configuration
|
|
23
|
-
* @returns Redirect guard state
|
|
24
|
-
*/
|
|
25
|
-
export function useRedirectGuard(options = {}) {
|
|
26
|
-
const { auth, redirectTo: customRedirectTo, condition } = options;
|
|
27
|
-
// Hooks must be called unconditionally (Rules of Hooks)
|
|
28
|
-
const location = useLocation();
|
|
29
|
-
const authConfig = useAuthConfig();
|
|
30
|
-
const authDisabled = useAppConfig().auth === false;
|
|
31
|
-
const user = useAuthSafe('user');
|
|
32
|
-
const can = useAuthSafe('can');
|
|
33
|
-
const status = useAuthSafe('status');
|
|
34
|
-
// Determine redirect state
|
|
35
|
-
const redirectState = useMemo(() => {
|
|
36
|
-
const noAction = {
|
|
37
|
-
shouldRedirect: false,
|
|
38
|
-
redirectTo: null,
|
|
39
|
-
isChecking: false,
|
|
40
|
-
};
|
|
41
|
-
// SSR-safe: return safe defaults on server
|
|
42
|
-
if (!isClient())
|
|
43
|
-
return noAction;
|
|
44
|
-
// Only INITIALIZING = still checking. DEGRADED/ERROR/READY = auth resolved (proceed with current user)
|
|
45
|
-
if (status === FEATURE_STATUS.INITIALIZING) {
|
|
46
|
-
return { ...noAction, isChecking: true };
|
|
47
|
-
}
|
|
48
|
-
// Custom condition provided
|
|
49
|
-
if (condition) {
|
|
50
|
-
const shouldRedirect = condition(user, status);
|
|
51
|
-
return {
|
|
52
|
-
shouldRedirect,
|
|
53
|
-
redirectTo: shouldRedirect ? customRedirectTo || null : null,
|
|
54
|
-
isChecking: false,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
// Use auth config to determine redirect
|
|
58
|
-
if (auth !== false && auth !== undefined) {
|
|
59
|
-
if (!can)
|
|
60
|
-
return noAction;
|
|
61
|
-
// Check if user can navigate to this route
|
|
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
|
-
}
|
|
67
|
-
let targetRoute = null;
|
|
68
|
-
// Authentication failure (not logged in) → always redirect
|
|
69
|
-
if (typeof auth === 'object' && auth.required && !user) {
|
|
70
|
-
// Check if we have OAuth parameters that need to be preserved
|
|
71
|
-
const hasOAuthParams = location.search.includes('code=') ||
|
|
72
|
-
location.search.includes('state=') ||
|
|
73
|
-
location.search.includes('error=');
|
|
74
|
-
const authRoute = authConfig.authRoute;
|
|
75
|
-
if (hasOAuthParams) {
|
|
76
|
-
targetRoute = `${authRoute}${location.search}`;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
targetRoute = authRoute;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
// Authorization failure (wrong role)
|
|
83
|
-
else if (typeof auth === 'object' && auth.role) {
|
|
84
|
-
targetRoute = authConfig.roleRoute;
|
|
85
|
-
}
|
|
86
|
-
// Authorization failure (wrong tier)
|
|
87
|
-
else if (typeof auth === 'object' && auth.tier) {
|
|
88
|
-
targetRoute = authConfig.tierRoute;
|
|
89
|
-
}
|
|
90
|
-
// Fallback
|
|
91
|
-
else {
|
|
92
|
-
targetRoute = authConfig.roleRoute;
|
|
93
|
-
}
|
|
94
|
-
return {
|
|
95
|
-
shouldRedirect: true,
|
|
96
|
-
redirectTo: customRedirectTo || targetRoute,
|
|
97
|
-
isChecking: false,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
// No redirect needed
|
|
102
|
-
return noAction;
|
|
103
|
-
}, [
|
|
104
|
-
auth,
|
|
105
|
-
status,
|
|
106
|
-
user,
|
|
107
|
-
can,
|
|
108
|
-
condition,
|
|
109
|
-
customRedirectTo,
|
|
110
|
-
location.search,
|
|
111
|
-
authDisabled,
|
|
112
|
-
authConfig.authRoute,
|
|
113
|
-
authConfig.roleRoute,
|
|
114
|
-
authConfig.tierRoute,
|
|
115
|
-
]);
|
|
116
|
-
return redirectState;
|
|
117
|
-
}
|
|
1
|
+
"use client";import{useMemo as p}from"react";import{isClient as m,FEATURE_STATUS as g}from"@donotdev/core";import{useAppConfig as A,useAuthConfig as T}from"@donotdev/core";import{useLocation as C}from"./useLocation.vite.js";import{useAuthSafe as l}from"../../utils/useAuthSafe.js";function v(h={}){let{auth:e,redirectTo:i,condition:s}=h,o=C(),r=T(),d=A().auth===!1,n=l("user"),a=l("can"),c=l("status");return p(()=>{let u={shouldRedirect:!1,redirectTo:null,isChecking:!1};if(!m())return u;if(c===g.INITIALIZING)return{...u,isChecking:!0};if(s){let t=s(n,c);return{shouldRedirect:t,redirectTo:t&&i||null,isChecking:!1}}if(e!==!1&&e!==void 0){if(!a)return u;if(!a.navigate(e)){if(d&&!i)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 t=null;if(typeof e=="object"&&e.required&&!n){let R=o.search.includes("code=")||o.search.includes("state=")||o.search.includes("error="),f=r.authRoute;R?t=`${f}${o.search}`:t=f}else typeof e=="object"&&e.role?t=r.roleRoute:typeof e=="object"&&e.tier?t=r.tierRoute:t=r.roleRoute;return{shouldRedirect:!0,redirectTo:i||t,isChecking:!1}}}return u},[e,c,n,a,s,i,o.search,d,r.authRoute,r.roleRoute,r.tierRoute])}export{v as useRedirectGuard};
|
|
@@ -1,38 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// packages/ui/src/routing/hooks/useRouteParam.next.ts
|
|
3
|
-
/**
|
|
4
|
-
* @fileoverview useRouteParam hook - Next.js implementation
|
|
5
|
-
* @description Helper hook to safely extract a single route parameter as a string
|
|
6
|
-
*
|
|
7
|
-
* @version 0.1.0
|
|
8
|
-
* @since 0.0.1
|
|
9
|
-
* @author AMBROISE PARK Consulting
|
|
10
|
-
*/
|
|
11
|
-
import { useParams } from './useParams.next';
|
|
12
|
-
/**
|
|
13
|
-
* Safely extract a route parameter as a string
|
|
14
|
-
*
|
|
15
|
-
* Handles the fact that useParams can return string | string[] | undefined.
|
|
16
|
-
* For standard path parameters (not catch-all routes), this will always be a string.
|
|
17
|
-
*
|
|
18
|
-
* @param paramName - Name of the route parameter
|
|
19
|
-
* @returns The parameter value as a string, or undefined if not present
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```tsx
|
|
23
|
-
* // Route: /product/:id
|
|
24
|
-
* const id = useRouteParam('id'); // string | undefined
|
|
25
|
-
* if (!id) return <NotFound />;
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export function useRouteParam(paramName) {
|
|
29
|
-
const params = useParams();
|
|
30
|
-
const value = params[paramName];
|
|
31
|
-
if (typeof value === 'string') {
|
|
32
|
-
return value;
|
|
33
|
-
}
|
|
34
|
-
if (Array.isArray(value) && value.length > 0) {
|
|
35
|
-
return value[0];
|
|
36
|
-
}
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
1
|
+
"use client";import{useParams as n}from"./useParams.next.js";function a(e){let r=n()[e];if(typeof r=="string")return r;if(Array.isArray(r)&&r.length>0)return r[0]}export{a as useRouteParam};
|
|
@@ -1,38 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// packages/ui/src/routing/hooks/useRouteParam.vite.ts
|
|
3
|
-
/**
|
|
4
|
-
* @fileoverview useRouteParam hook - Vite/React Router implementation
|
|
5
|
-
* @description Helper hook to safely extract a single route parameter as a string
|
|
6
|
-
*
|
|
7
|
-
* @version 0.1.0
|
|
8
|
-
* @since 0.0.1
|
|
9
|
-
* @author AMBROISE PARK Consulting
|
|
10
|
-
*/
|
|
11
|
-
import { useParams } from './useParams.vite';
|
|
12
|
-
/**
|
|
13
|
-
* Safely extract a route parameter as a string
|
|
14
|
-
*
|
|
15
|
-
* Handles the fact that useParams can return string | string[] | undefined.
|
|
16
|
-
* For standard path parameters (not catch-all routes), this will always be a string.
|
|
17
|
-
*
|
|
18
|
-
* @param paramName - Name of the route parameter
|
|
19
|
-
* @returns The parameter value as a string, or undefined if not present
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```tsx
|
|
23
|
-
* // Route: /product/:id
|
|
24
|
-
* const id = useRouteParam('id'); // string | undefined
|
|
25
|
-
* if (!id) return <NotFound />;
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export function useRouteParam(paramName) {
|
|
29
|
-
const params = useParams();
|
|
30
|
-
const value = params[paramName];
|
|
31
|
-
if (typeof value === 'string') {
|
|
32
|
-
return value;
|
|
33
|
-
}
|
|
34
|
-
if (Array.isArray(value) && value.length > 0) {
|
|
35
|
-
return value[0];
|
|
36
|
-
}
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
1
|
+
"use client";import{useParams as n}from"./useParams.vite.js";function a(e){let r=n()[e];if(typeof r=="string")return r;if(Array.isArray(r)&&r.length>0)return r[0]}export{a as useRouteParam};
|
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
* `useSearchParams`) moves the render to the browser up to the nearest Suspense
|
|
6
6
|
* boundary. Use it whenever the query string is not needed. The server render of a
|
|
7
7
|
* per-request page reads its internal pathname (`/<lang>/dndev-session/…`): dropped here, so
|
|
8
|
-
* the server and the browser see the same path.
|
|
8
|
+
* the server and the browser see the same path. Under Next `trailingSlash: true` the URL
|
|
9
|
+
* ends with `/` (`/en/produits/`): the route path does not (`/produits`), the form of the
|
|
10
|
+
* route mapping.
|
|
9
11
|
*
|
|
10
|
-
* @returns Route path, always starting with `/`
|
|
12
|
+
* @returns Route path, always starting with `/`, never ending with `/` (except the root)
|
|
11
13
|
*
|
|
12
14
|
* @example
|
|
13
15
|
* ```tsx
|
|
@@ -15,7 +17,7 @@
|
|
|
15
17
|
* const active = path === '/produits';
|
|
16
18
|
* ```
|
|
17
19
|
*
|
|
18
|
-
* @version 0.1.
|
|
20
|
+
* @version 0.1.1
|
|
19
21
|
* @since 0.2.3
|
|
20
22
|
* @author AMBROISE PARK Consulting
|
|
21
23
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRoutePath.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useRoutePath.next.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRoutePath.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useRoutePath.next.ts"],"names":[],"mappings":"AAqBA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAKrC"}
|