@donotdev/ui 0.3.1 → 0.3.2
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/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.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.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 +25 -4
- package/dist/dndev.css +25 -4
- 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 +2 -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.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/i18nSeoMeta.js +1 -53
- package/dist/internal/layout/components/index.js +1 -13
- 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.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.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.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 +1 -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 +25 -4
- 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.map +1 -1
- package/dist/utils/assetResolver.js +1 -297
- 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/useSeo.js +1 -151
- 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 +15 -0
- package/guidelines/SEO.md +4 -1
- 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
|
@@ -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};
|
|
@@ -1,36 +1 @@
|
|
|
1
|
-
|
|
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
|
-
}
|
|
1
|
+
"use client";import{usePathname as t}from"next/navigation";import{getLanguageRouting as e,publicPathname as a,splitLanguagePath as n}from"@donotdev/core";function o(){return n(a(t()??"/"),e()).path}export{o as useRoutePath};
|
|
@@ -1,25 +1 @@
|
|
|
1
|
-
|
|
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
|
-
}
|
|
1
|
+
"use client";import{useLocation as t}from"react-router-dom";function o(){return t().pathname}export{o as useRoutePath};
|
|
@@ -1,22 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// packages/ui/src/routing/hooks/useSearchParams.next.ts
|
|
3
|
-
import { useSearchParams as useNextSearchParams } from 'next/navigation';
|
|
4
|
-
/**
|
|
5
|
-
* Get current URL search parameters (read-only).
|
|
6
|
-
* Returns a ReadonlyURLSearchParams instance directly (NOT a tuple).
|
|
7
|
-
*
|
|
8
|
-
* To modify search params, use `useNavigate()` with a query string
|
|
9
|
-
* or `useQueryParams()` for a key-value API with defaults.
|
|
10
|
-
*
|
|
11
|
-
* @returns ReadonlyURLSearchParams instance with `.get()`, `.has()`, `.getAll()`, etc.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```tsx
|
|
15
|
-
* const searchParams = useSearchParams();
|
|
16
|
-
* const page = searchParams.get('page');
|
|
17
|
-
* const sort = searchParams.get('sort');
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export function useSearchParams() {
|
|
21
|
-
return useNextSearchParams();
|
|
22
|
-
}
|
|
1
|
+
"use client";import{useSearchParams as e}from"next/navigation";function a(){return e()}export{a as useSearchParams};
|
|
@@ -1,22 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// packages/ui/src/routing/hooks/useSearchParams.vite.ts
|
|
3
|
-
import { useSearchParams as useRouterSearchParams } from 'react-router-dom';
|
|
4
|
-
/**
|
|
5
|
-
* Get current URL search parameters (read-only).
|
|
6
|
-
* Returns a URLSearchParams instance directly (NOT a tuple).
|
|
7
|
-
*
|
|
8
|
-
* To modify search params, use `useNavigate()` with a query string
|
|
9
|
-
* or `useQueryParams()` for a key-value API with defaults.
|
|
10
|
-
*
|
|
11
|
-
* @returns URLSearchParams instance with `.get()`, `.has()`, `.getAll()`, etc.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```tsx
|
|
15
|
-
* const searchParams = useSearchParams();
|
|
16
|
-
* const page = searchParams.get('page');
|
|
17
|
-
* const sort = searchParams.get('sort');
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export function useSearchParams() {
|
|
21
|
-
return useRouterSearchParams()[0];
|
|
22
|
-
}
|
|
1
|
+
"use client";import{useSearchParams as r}from"react-router-dom";function e(){return r()[0]}export{e as useSearchParams};
|
|
@@ -1,50 +1 @@
|
|
|
1
|
-
|
|
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
|
-
}
|
|
1
|
+
"use client";import{usePathname as g}from"next/navigation";import{getLanguageRouting as t,localizePath as r,publicPathname as u,splitLanguagePath as i}from"@donotdev/core";function o(){return i(u(g()??"/"),t()).language}function c(){let n=o(),a=t();return e=>r(e,n,a)}export{c as useLocalizedPath,o as useUrlLanguage};
|
|
@@ -1,41 +1 @@
|
|
|
1
|
-
|
|
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
|
-
}
|
|
1
|
+
"use client";import{useHref as r}from"react-router-dom";import{getLanguageRouting as t,localizePath as a,splitLanguagePath as u}from"@donotdev/core";function i(){return u(r("/"),t()).language}function l(){let n=i(),e=t();return g=>a(g,n,e)}export{l as useLocalizedPath,i as useUrlLanguage};
|
package/dist/routing/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export { default as GoToWrapper } from './GoToWrapper';
|
|
|
18
18
|
export { default as GoToInput } from './GoToInput';
|
|
19
19
|
export * from './DnDevNavigationMenu';
|
|
20
20
|
export { default as NotFoundPage } from './404';
|
|
21
|
+
export { NotFoundDocument, useIsNotFoundDocument } from './NotFoundDocument';
|
|
21
22
|
export { useNavigate, useBack, useRefresh, usePrefetch, useLocation, useRoutePath, useParams, useRouteParam, useSearchParams, useMatch, useQueryParams, useRedirectGuard, useLocalizedPath, useUrlLanguage, } from '@donotdev/ui/routing/hooks';
|
|
22
23
|
export type { NavigateOptions, RedirectGuardOptions, RedirectGuardResult, } from '@donotdev/ui/routing/hooks';
|
|
23
24
|
export * from './useNavigation';
|
|
@@ -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,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;
|
|
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;AAChD,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAO7E,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
|
@@ -1,32 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Routing package
|
|
4
|
-
* @description Platform-agnostic routing components and hooks (work in both Vite + Next.js)
|
|
5
|
-
* Vite-specific routing (AppRoutes, RootLayout) moved to ../vite-routing
|
|
6
|
-
*
|
|
7
|
-
* @version 0.1.0
|
|
8
|
-
* @since 0.0.1
|
|
9
|
-
* @author AMBROISE PARK Consulting
|
|
10
|
-
*/
|
|
11
|
-
// Components - all platform-agnostic
|
|
12
|
-
export * from './Link';
|
|
13
|
-
// NavigationItemComponent intentionally NOT exported — internal building block.
|
|
14
|
-
// Public API: HeaderNavigation (path prop for single item), DnDevNavigationMenu (full menu).
|
|
15
|
-
export * from './AuthGuard';
|
|
16
|
-
export * from './AuthGuardFallback';
|
|
17
|
-
export { AuthReturnTo } from './AuthReturnTo';
|
|
18
|
-
export { SignedInRedirect } from './SignedInRedirect';
|
|
19
|
-
export * from './GoTo';
|
|
20
|
-
export { default as GoToWrapper } from './GoToWrapper';
|
|
21
|
-
export { default as GoToInput } from './GoToInput';
|
|
22
|
-
// GoToDialog intentionally NOT exported - lazy loaded by GoToWrapper
|
|
23
|
-
export * from './DnDevNavigationMenu';
|
|
24
|
-
export { default as NotFoundPage } from './404';
|
|
25
|
-
// Hooks - platform-specific via conditional exports
|
|
26
|
-
// '@donotdev/ui/routing/hooks' resolves to:
|
|
27
|
-
// - hooks.vite.ts when bundled with Vite (vite-app condition)
|
|
28
|
-
// - hooks.next.ts when bundled with Next.js (default condition)
|
|
29
|
-
// NOTE: Explicit named exports required - esbuild can't re-export with 'export *' from external
|
|
30
|
-
export { useNavigate, useBack, useRefresh, usePrefetch, useLocation, useRoutePath, useParams, useRouteParam, useSearchParams, useMatch, useQueryParams, useRedirectGuard, useLocalizedPath, useUrlLanguage, } from '@donotdev/ui/routing/hooks';
|
|
31
|
-
export * from './useNavigation';
|
|
32
|
-
export * from './useGoTo';
|
|
1
|
+
export*from"./Link.js";export*from"./AuthGuard.js";export*from"./AuthGuardFallback.js";import{AuthReturnTo as a}from"./AuthReturnTo.js";import{SignedInRedirect as p}from"./SignedInRedirect.js";export*from"./GoTo.js";import{default as f}from"./GoToWrapper.js";import{default as i}from"./GoToInput.js";export*from"./DnDevNavigationMenu.js";import{default as R}from"./404.js";import{NotFoundDocument as P,useIsNotFoundDocument as h}from"./NotFoundDocument.js";import{useNavigate as G,useBack as I,useRefresh as N,usePrefetch as S,useLocation as v,useRoutePath as y,useParams as F,useRouteParam as L,useSearchParams as T,useMatch as k,useQueryParams as D,useRedirectGuard as O,useLocalizedPath as z,useUrlLanguage as A}from"@donotdev/ui/routing/hooks";export*from"./useNavigation.js";export*from"./useGoTo.js";export{a as AuthReturnTo,i as GoToInput,f as GoToWrapper,P as NotFoundDocument,R as NotFoundPage,p as SignedInRedirect,I as useBack,h as useIsNotFoundDocument,z as useLocalizedPath,v as useLocation,k as useMatch,G as useNavigate,F as useParams,S as usePrefetch,D as useQueryParams,O as useRedirectGuard,N as useRefresh,L as useRouteParam,y as useRoutePath,T as useSearchParams,A as useUrlLanguage};
|