@donotdev/ui 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ChildRowsPicker-63M4EQUQ.js +1 -0
- package/dist/ChildRowsPicker-ISP365ON.js +1 -0
- package/dist/ChildRowsPicker-PQFE6NCR.js +1 -0
- package/dist/ChildRowsPicker-XXFFSMWY.js +1 -0
- package/dist/{GoToDialog-CICRYHHG.js → GoToDialog-KSBGOIWO.js} +1 -1
- package/dist/{GoToDialog-YGBON6FR.js → GoToDialog-XBK5EZF4.js} +1 -1
- package/dist/chunk-3CIZFGST.js +1 -0
- package/dist/chunk-LHMKU342.js +1 -0
- package/dist/chunk-MS7ZIW5Z.js +1 -0
- package/dist/chunk-P2DHZWPY.js +1 -0
- package/dist/components/auth/AuthHeader.d.ts.map +1 -1
- package/dist/components/auth/AuthHeader.js +0 -2
- package/dist/components/auth/AuthMenu.d.ts.map +1 -1
- package/dist/components/auth/AuthMenu.js +6 -40
- package/dist/components/common/icon.d.ts.map +1 -1
- package/dist/components/common/icon.js +2 -1
- package/dist/components/common/lucideIconByName.d.ts +9 -0
- package/dist/components/common/lucideIconByName.d.ts.map +1 -0
- package/dist/components/common/lucideIconByName.js +32 -0
- package/dist/components/layout/GameFlow.d.ts.map +1 -1
- package/dist/components/layout/components/Breadcrumbs.d.ts.map +1 -1
- package/dist/components/layout/components/Breadcrumbs.js +18 -12
- package/dist/components/layout/components/header/CacheSettings.d.ts.map +1 -1
- package/dist/components/layout/components/header/CacheSettings.js +6 -4
- package/dist/components/layout/components/header/SettingsMenu.d.ts.map +1 -1
- package/dist/components/layout/components/header/SettingsMenu.js +4 -3
- package/dist/components/layout/components/header/ThemeToggle.d.ts.map +1 -1
- package/dist/components/layout/components/header/ThemeToggle.js +2 -1
- package/dist/crud/components/ChildRowsPicker.d.ts +21 -0
- package/dist/crud/components/ChildRowsPicker.d.ts.map +1 -0
- package/dist/crud/components/ChildRowsPicker.js +68 -0
- package/dist/crud/components/CrudCardLink.d.ts +6 -6
- package/dist/crud/components/CrudCardLink.d.ts.map +1 -1
- package/dist/crud/components/CrudCardLink.js +3 -9
- package/dist/crud/components/EntityCardList.d.ts.map +1 -1
- package/dist/crud/components/EntityCardList.js +10 -26
- package/dist/crud/components/EntityDisplayRenderer.d.ts.map +1 -1
- package/dist/crud/components/EntityDisplayRenderer.js +6 -3
- package/dist/crud/components/EntityFormRenderer.d.ts +4 -2
- package/dist/crud/components/EntityFormRenderer.d.ts.map +1 -1
- package/dist/crud/components/EntityFormRenderer.js +160 -56
- package/dist/crud/components/EntityList.d.ts +6 -4
- package/dist/crud/components/EntityList.d.ts.map +1 -1
- package/dist/crud/components/EntityList.js +437 -92
- package/dist/crud/components/EntityRecommendations.js +1 -1
- package/dist/crud/components/EntityWorkflow.d.ts.map +1 -1
- package/dist/crud/components/EntityWorkflow.js +6 -4
- package/dist/crud/components/Form.d.ts +1 -1
- package/dist/crud/components/Form.d.ts.map +1 -1
- package/dist/crud/components/Form.js +2 -2
- package/dist/crud/components/cellEditFor.d.ts +43 -0
- package/dist/crud/components/cellEditFor.d.ts.map +1 -0
- package/dist/crud/components/cellEditFor.js +74 -0
- package/dist/crud/components/entityParent.d.ts +33 -0
- package/dist/crud/components/entityParent.d.ts.map +1 -0
- package/dist/crud/components/entityParent.js +76 -0
- package/dist/crud/components/useRecordBreadcrumb.d.ts +11 -0
- package/dist/crud/components/useRecordBreadcrumb.d.ts.map +1 -0
- package/dist/crud/components/useRecordBreadcrumb.js +43 -0
- package/dist/crud/crudImports.d.ts +12 -1
- package/dist/crud/crudImports.d.ts.map +1 -1
- package/dist/crud/crudImports.js +11 -0
- package/dist/dndev-next.css +782 -193
- package/dist/dndev.css +784 -193
- package/dist/index.js +4 -4
- package/dist/internal/common/RouteErrorFallback.d.ts.map +1 -1
- package/dist/internal/common/RouteErrorFallback.js +2 -4
- package/dist/internal/devtools/components/ConfigTab.d.ts.map +1 -1
- package/dist/internal/devtools/components/ConfigTab.js +1 -1
- package/dist/internal/devtools/components/CookieTab.d.ts.map +1 -1
- package/dist/internal/devtools/components/CookieTab.js +1 -5
- package/dist/internal/devtools/components/DesignTab.d.ts.map +1 -1
- package/dist/internal/devtools/components/DesignTab.js +18 -7
- package/dist/internal/devtools/components/StoresTab.d.ts.map +1 -1
- package/dist/internal/devtools/components/StoresTab.js +17 -3
- package/dist/internal/devtools/types.d.ts +3 -3
- package/dist/internal/devtools/types.d.ts.map +1 -1
- package/dist/internal/devtools/utils/maskSensitive.d.ts +1 -1
- package/dist/internal/devtools/utils/maskSensitive.d.ts.map +1 -1
- package/dist/internal/initializers/NextJsStoresInitializer.d.ts +3 -0
- package/dist/internal/initializers/NextJsStoresInitializer.d.ts.map +1 -1
- package/dist/internal/initializers/NextJsStoresInitializer.js +8 -1
- package/dist/internal/layout/DnDevLayout.d.ts.map +1 -1
- package/dist/internal/layout/DnDevLayout.js +21 -21
- package/dist/internal/layout/components/AutoMetaTags.d.ts.map +1 -1
- package/dist/internal/layout/components/AutoMetaTags.js +42 -38
- package/dist/internal/layout/components/FontPreloadLinks.d.ts +7 -4
- package/dist/internal/layout/components/FontPreloadLinks.d.ts.map +1 -1
- package/dist/internal/layout/components/FontPreloadLinks.js +12 -25
- package/dist/internal/layout/components/footer/FooterCopyright.d.ts +2 -0
- package/dist/internal/layout/components/footer/FooterCopyright.d.ts.map +1 -1
- package/dist/internal/layout/components/footer/FooterCopyright.js +4 -0
- package/dist/internal/layout/components/footer/useLegalLinks.d.ts +2 -1
- package/dist/internal/layout/components/footer/useLegalLinks.d.ts.map +1 -1
- package/dist/internal/layout/components/footer/useLegalLinks.js +4 -3
- package/dist/internal/layout/components/i18nSeoMeta.d.ts.map +1 -1
- package/dist/internal/layout/components/i18nSeoMeta.js +1 -0
- package/dist/internal/layout/zones/DnDevMergedBar.js +3 -3
- package/dist/internal/providers/UIProviders.d.ts +0 -8
- package/dist/internal/providers/UIProviders.d.ts.map +1 -1
- package/dist/internal/providers/UIProviders.js +45 -2
- package/dist/providers/NextJsAppProviders.d.ts +5 -1
- package/dist/providers/NextJsAppProviders.d.ts.map +1 -1
- package/dist/providers/NextJsAppProviders.js +36 -6
- package/dist/providers/ViteAppProviders.d.ts.map +1 -1
- package/dist/providers/ViteAppProviders.js +42 -7
- package/dist/routing/404.d.ts +8 -1
- package/dist/routing/404.d.ts.map +1 -1
- package/dist/routing/404.js +9 -5
- package/dist/routing/AuthGuardFallback.d.ts.map +1 -1
- package/dist/routing/AuthGuardFallback.js +1 -2
- package/dist/routing/AuthReturnTo.d.ts.map +1 -1
- package/dist/routing/AuthReturnTo.js +9 -2
- package/dist/routing/GoTo.d.ts +0 -6
- package/dist/routing/GoTo.d.ts.map +1 -1
- package/dist/routing/GoTo.js +5 -8
- package/dist/routing/Link.d.ts +4 -2
- package/dist/routing/Link.d.ts.map +1 -1
- package/dist/routing/Link.js +8 -5
- package/dist/routing/SignedInRedirect.d.ts +27 -0
- package/dist/routing/SignedInRedirect.d.ts.map +1 -0
- package/dist/routing/SignedInRedirect.js +47 -0
- package/dist/routing/hooks/hooks.next.d.ts +2 -0
- package/dist/routing/hooks/hooks.next.d.ts.map +1 -1
- package/dist/routing/hooks/hooks.next.js +1 -1
- package/dist/routing/hooks/hooks.vite.d.ts +2 -0
- package/dist/routing/hooks/hooks.vite.d.ts.map +1 -1
- package/dist/routing/hooks/hooks.vite.js +1 -1
- package/dist/routing/hooks/useLocation.next.d.ts +12 -0
- package/dist/routing/hooks/useLocation.next.d.ts.map +1 -1
- package/dist/routing/hooks/useLocation.next.js +17 -4
- package/dist/routing/hooks/useMatch.next.d.ts +6 -0
- package/dist/routing/hooks/useMatch.next.d.ts.map +1 -1
- package/dist/routing/hooks/useMatch.next.js +8 -2
- package/dist/routing/hooks/useNavigate.next.d.ts +6 -1
- package/dist/routing/hooks/useNavigate.next.d.ts.map +1 -1
- package/dist/routing/hooks/useNavigate.next.js +13 -4
- package/dist/routing/hooks/useNavigate.vite.d.ts +7 -1
- package/dist/routing/hooks/useNavigate.vite.d.ts.map +1 -1
- package/dist/routing/hooks/useNavigate.vite.js +20 -4
- package/dist/routing/hooks/useRedirectGuard.next.d.ts +3 -1
- package/dist/routing/hooks/useRedirectGuard.next.d.ts.map +1 -1
- package/dist/routing/hooks/useRedirectGuard.next.js +18 -10
- package/dist/routing/hooks/useRedirectGuard.vite.d.ts.map +1 -1
- package/dist/routing/hooks/useRedirectGuard.vite.js +7 -1
- package/dist/routing/hooks/useRoutePath.next.d.ts +23 -0
- package/dist/routing/hooks/useRoutePath.next.d.ts.map +1 -0
- package/dist/routing/hooks/useRoutePath.next.js +36 -0
- package/dist/routing/hooks/useRoutePath.vite.d.ts +13 -0
- package/dist/routing/hooks/useRoutePath.vite.d.ts.map +1 -0
- package/dist/routing/hooks/useRoutePath.vite.js +25 -0
- package/dist/routing/hooks/useUrlLanguage.next.d.ts +28 -0
- package/dist/routing/hooks/useUrlLanguage.next.d.ts.map +1 -0
- package/dist/routing/hooks/useUrlLanguage.next.js +50 -0
- package/dist/routing/hooks/useUrlLanguage.vite.d.ts +22 -0
- package/dist/routing/hooks/useUrlLanguage.vite.d.ts.map +1 -0
- package/dist/routing/hooks/useUrlLanguage.vite.js +41 -0
- package/dist/routing/index.d.ts +3 -1
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/index.js +2 -1
- package/dist/routing/parentRoute.d.ts +27 -0
- package/dist/routing/parentRoute.d.ts.map +1 -0
- package/dist/routing/parentRoute.js +43 -0
- package/dist/routing/useNavigation.d.ts.map +1 -1
- package/dist/routing/useNavigation.js +8 -27
- package/dist/routing/useRouteDiscovery.d.ts +2 -2
- package/dist/routing/useRouteDiscovery.d.ts.map +1 -1
- package/dist/routing/useRouteDiscovery.js +6 -5
- package/dist/styles/index.css +781 -192
- package/dist/symbol-index.json +1 -1
- package/dist/utils/assetResolver.d.ts.map +1 -1
- package/dist/utils/assetResolver.js +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +3 -0
- package/dist/utils/useDeleteAccountSafe.d.ts +17 -0
- package/dist/utils/useDeleteAccountSafe.d.ts.map +1 -0
- package/dist/utils/useDeleteAccountSafe.js +52 -0
- package/dist/utils/useFormStoreSafe.d.ts.map +1 -1
- package/dist/utils/useFormStoreSafe.js +1 -0
- package/dist/utils/useSeo.d.ts +10 -2
- package/dist/utils/useSeo.d.ts.map +1 -1
- package/dist/utils/useSeo.js +44 -9
- package/dist/vite-routing/AppRoutes.d.ts.map +1 -1
- package/dist/vite-routing/AppRoutes.js +37 -4
- package/guidelines/COMPONENTS.md +2 -1
- package/guidelines/GOTCHAS.md +2 -0
- package/guidelines/LAYOUTS.md +4 -0
- package/guidelines/PAGES.md +30 -3
- package/guidelines/ROUTING.md +29 -0
- package/guidelines/SEO.md +52 -0
- package/package.json +9 -9
- package/dist/CookieConsent-5NH5DNTP.js +0 -1
- package/dist/CookieConsent-W7UE647Y.js +0 -1
- package/dist/chunk-DRFM6WXH.js +0 -1
- package/dist/chunk-MIPTBUWY.js +0 -1
- package/dist/internal/layout/components/NextJsAutoMetaTags.d.ts +0 -57
- package/dist/internal/layout/components/NextJsAutoMetaTags.d.ts.map +0 -1
- package/dist/internal/layout/components/NextJsAutoMetaTags.js +0 -182
package/dist/routing/GoTo.js
CHANGED
|
@@ -11,20 +11,17 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
11
11
|
import { Search } from 'lucide-react';
|
|
12
12
|
import { Button, BUTTON_VARIANT, DISPLAY } from '@donotdev/components';
|
|
13
13
|
import { useOverlayStore, useTranslation } from '@donotdev/core';
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* Opens command dialog on click.
|
|
19
|
-
*/
|
|
14
|
+
/** Reads the UA-CH platform when the browser exposes it. */
|
|
15
|
+
function readUserAgentPlatform(nav) {
|
|
16
|
+
return nav.userAgentData?.platform;
|
|
17
|
+
}
|
|
20
18
|
export const GoTo = ({ display = DISPLAY.AUTO, className, onOpen, }) => {
|
|
21
19
|
const { t } = useTranslation('dndev');
|
|
22
20
|
const openCommandDialog = useOverlayStore((state) => state.openCommandDialog);
|
|
23
21
|
// Platform-aware shortcut (Mac: ⌘K, others: Ctrl+K)
|
|
24
22
|
// navigator.userAgentData?.platform is modern; navigator.platform is the deprecated fallback
|
|
25
23
|
const isMac = typeof navigator !== 'undefined' &&
|
|
26
|
-
/Mac|iPhone|iPad/.test(navigator
|
|
27
|
-
.userAgentData?.platform ?? navigator.platform);
|
|
24
|
+
/Mac|iPhone|iPad/.test(readUserAgentPlatform(navigator) ?? navigator.platform);
|
|
28
25
|
const shortcut = isMac ? '⌘K' : 'Ctrl+K';
|
|
29
26
|
const handleClick = () => {
|
|
30
27
|
openCommandDialog();
|
package/dist/routing/Link.d.ts
CHANGED
|
@@ -21,9 +21,11 @@ export interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
|
21
21
|
'aria-describedby'?: string;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
-
* Link component
|
|
24
|
+
* Link component. Internal paths are app paths (`/produits`): the rendered `href` and
|
|
25
|
+
* the navigation use the current language's URL (`/en/produits` on an English page,
|
|
26
|
+
* unchanged in the default language or a one-language app).
|
|
25
27
|
*
|
|
26
|
-
* @version 0.
|
|
28
|
+
* @version 0.2.0
|
|
27
29
|
* @since 0.0.1
|
|
28
30
|
* @author AMBROISE PARK Consulting
|
|
29
31
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Link.d.ts","sourceRoot":"","sources":["../../src/routing/Link.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EAEb,oBAAoB,EACrB,MAAM,OAAO,CAAC;AASf;;;;;;GAMG;AACH,MAAM,WAAW,SAAU,SAAQ,oBAAoB,CAAC,iBAAiB,CAAC;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,iDAAiD;IACjD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gDAAgD;IAChD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED
|
|
1
|
+
{"version":3,"file":"Link.d.ts","sourceRoot":"","sources":["../../src/routing/Link.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EAEb,oBAAoB,EACrB,MAAM,OAAO,CAAC;AASf;;;;;;GAMG;AACH,MAAM,WAAW,SAAU,SAAQ,oBAAoB,CAAC,iBAAiB,CAAC;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,iDAAiD;IACjD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gDAAgD;IAChD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,IAAI,EAAE,aAAa,CAAC,SAAS,CA0JzC,CAAC"}
|
package/dist/routing/Link.js
CHANGED
|
@@ -13,17 +13,20 @@ import { Link as LinkIcon } from 'lucide-react';
|
|
|
13
13
|
import { cn } from '@donotdev/components';
|
|
14
14
|
import { useConsent } from '@donotdev/core';
|
|
15
15
|
// Platform-specific hooks via conditional exports
|
|
16
|
-
import { useNavigate } from '@donotdev/ui/routing/hooks';
|
|
16
|
+
import { useLocalizedPath, useNavigate } from '@donotdev/ui/routing/hooks';
|
|
17
17
|
import { Icon } from '../components/common/icon';
|
|
18
18
|
/**
|
|
19
|
-
* Link component
|
|
19
|
+
* Link component. Internal paths are app paths (`/produits`): the rendered `href` and
|
|
20
|
+
* the navigation use the current language's URL (`/en/produits` on an English page,
|
|
21
|
+
* unchanged in the default language or a one-language app).
|
|
20
22
|
*
|
|
21
|
-
* @version 0.
|
|
23
|
+
* @version 0.2.0
|
|
22
24
|
* @since 0.0.1
|
|
23
25
|
* @author AMBROISE PARK Consulting
|
|
24
26
|
*/
|
|
25
27
|
export const Link = ({ path, replace, prefetch = true, children, icon, iconEnd = false, label, onClick, className, 'aria-label': ariaLabel, 'aria-describedby': ariaDescribedBy, target, rel, ...rest }) => {
|
|
26
28
|
const navigate = useNavigate();
|
|
29
|
+
const localize = useLocalizedPath();
|
|
27
30
|
const showCookieBanner = useConsent('showCookieBanner');
|
|
28
31
|
// Special framework trigger: #cookie-settings
|
|
29
32
|
if (path === '#cookie-settings') {
|
|
@@ -97,8 +100,8 @@ export const Link = ({ path, replace, prefetch = true, children, icon, iconEnd =
|
|
|
97
100
|
gap: icon && (label || children) ? 'var(--gap-sm)' : undefined,
|
|
98
101
|
}, ...accessibilityProps, ...rest, children: linkContent }));
|
|
99
102
|
}
|
|
100
|
-
// Internal links:
|
|
101
|
-
return (_jsx("a", { href: path, onClick: handleClick, className: className, style: {
|
|
103
|
+
// Internal links: the URL in the current language (`/en/…`), same as navigate()
|
|
104
|
+
return (_jsx("a", { href: localize(path), onClick: handleClick, className: className, style: {
|
|
102
105
|
display: icon && (label || children) ? 'flex' : undefined,
|
|
103
106
|
alignItems: icon && (label || children) ? 'center' : undefined,
|
|
104
107
|
gap: icon && (label || children) ? 'var(--gap-sm)' : undefined,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Props for SignedInRedirect
|
|
4
|
+
*/
|
|
5
|
+
export interface SignedInRedirectProps {
|
|
6
|
+
/** App path signed-in visitors are sent to (PageMeta `signedInRedirect`) */
|
|
7
|
+
to: string;
|
|
8
|
+
/** The page, rendered for everyone until the redirect happens */
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* SignedInRedirect - sends signed-in visitors of a page to `to` (replace).
|
|
13
|
+
*
|
|
14
|
+
* Renders the page for everyone (server render, signed-out visitors). Once the auth
|
|
15
|
+
* user is known, navigates to `to` unless a return-to is pending (`?returnTo=` or
|
|
16
|
+
* the saved `dndev.auth.returnTo`): AuthReturnTo takes the visitor there instead.
|
|
17
|
+
* Generated route wrappers (Next) and createAppRouter (Vite) mount it for pages whose
|
|
18
|
+
* PageMeta sets `signedInRedirect`.
|
|
19
|
+
*
|
|
20
|
+
* @component
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* <SignedInRedirect to="/catalogue"><HomePage /></SignedInRedirect>
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function SignedInRedirect({ to, children }: SignedInRedirectProps): import("react").JSX.Element;
|
|
27
|
+
//# sourceMappingURL=SignedInRedirect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SignedInRedirect.d.ts","sourceRoot":"","sources":["../../src/routing/SignedInRedirect.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAOvC;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,4EAA4E;IAC5E,EAAE,EAAE,MAAM,CAAC;IACX,iEAAiE;IACjE,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,qBAAqB,+BAYvE"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
// packages/ui/src/routing/SignedInRedirect.tsx
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview SignedInRedirect component
|
|
6
|
+
* @description Client side of PageMeta `signedInRedirect`: sends a signed-in visitor
|
|
7
|
+
* of the page to another path. The generated Next proxy redirects before render when
|
|
8
|
+
* it can read the session cookie; this covers sign-ins on the page itself (no server
|
|
9
|
+
* request) and sessions the server cannot read.
|
|
10
|
+
*
|
|
11
|
+
* @version 0.1.0
|
|
12
|
+
* @since 0.6.0
|
|
13
|
+
* @author AMBROISE PARK Consulting
|
|
14
|
+
*/
|
|
15
|
+
import { useEffect } from 'react';
|
|
16
|
+
import { isClient, safeSessionStorage } from '@donotdev/core';
|
|
17
|
+
import { useNavigate } from '@donotdev/ui/routing/hooks';
|
|
18
|
+
import { useAuthSafe } from '../utils/useAuthSafe';
|
|
19
|
+
/**
|
|
20
|
+
* SignedInRedirect - sends signed-in visitors of a page to `to` (replace).
|
|
21
|
+
*
|
|
22
|
+
* Renders the page for everyone (server render, signed-out visitors). Once the auth
|
|
23
|
+
* user is known, navigates to `to` unless a return-to is pending (`?returnTo=` or
|
|
24
|
+
* the saved `dndev.auth.returnTo`): AuthReturnTo takes the visitor there instead.
|
|
25
|
+
* Generated route wrappers (Next) and createAppRouter (Vite) mount it for pages whose
|
|
26
|
+
* PageMeta sets `signedInRedirect`.
|
|
27
|
+
*
|
|
28
|
+
* @component
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* <SignedInRedirect to="/catalogue"><HomePage /></SignedInRedirect>
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function SignedInRedirect({ to, children }) {
|
|
35
|
+
const user = useAuthSafe('user');
|
|
36
|
+
const navigate = useNavigate();
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (!user || !isClient())
|
|
39
|
+
return;
|
|
40
|
+
if (new URLSearchParams(window.location.search).has('returnTo'))
|
|
41
|
+
return;
|
|
42
|
+
if (safeSessionStorage.getItem('dndev.auth.returnTo'))
|
|
43
|
+
return;
|
|
44
|
+
navigate(to, { replace: true });
|
|
45
|
+
}, [user, to, navigate]);
|
|
46
|
+
return _jsx(_Fragment, { children: children });
|
|
47
|
+
}
|
|
@@ -9,12 +9,14 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export { useNavigate, useBack, useRefresh, usePrefetch, } from './useNavigate.next';
|
|
11
11
|
export { useLocation } from './useLocation.next';
|
|
12
|
+
export { useRoutePath } from './useRoutePath.next';
|
|
12
13
|
export { useParams } from './useParams.next';
|
|
13
14
|
export { useRouteParam } from './useRouteParam.next';
|
|
14
15
|
export { useSearchParams } from './useSearchParams.next';
|
|
15
16
|
export { useMatch } from './useMatch.next';
|
|
16
17
|
export { useQueryParams } from './useQueryParams.next';
|
|
17
18
|
export { useRedirectGuard } from './useRedirectGuard.next';
|
|
19
|
+
export { useLocalizedPath, useUrlLanguage } from './useUrlLanguage.next';
|
|
18
20
|
export type { NavigateOptions } from './types';
|
|
19
21
|
export type { RedirectGuardOptions, RedirectGuardResult, } from './useRedirectGuard.next';
|
|
20
22
|
//# sourceMappingURL=hooks.next.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/hooks.next.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,EACV,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,YAAY,EACV,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"hooks.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/hooks.next.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,EACV,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACzE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,YAAY,EACV,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useRouter as
|
|
1
|
+
"use client";import{useRouter as d}from"next/navigation";import{isClient as G,useOverlayStore as $}from"@donotdev/core";import{usePathname as L}from"next/navigation";import{getLanguageRouting as b,localizePath as T,publicPathname as N,splitLanguagePath as I}from"@donotdev/core";function w(){return I(N(L()??"/"),b()).language}function h(){let e=w(),t=b();return r=>T(r,e,t)}function P(){let e=d(),t=$(n=>n.closeAll),r=h();return(n,o)=>{if(n==="back")return t(),e.back();t();let u=r(n);if(o?.preserveScroll&&G()){let s=window.scrollY;o?.replace?e.replace(u):e.push(u),requestAnimationFrame(()=>{window.scrollTo({top:s,behavior:"auto"})});return}return o?.replace?e.replace(u):e.push(u)}}function U(){let e=d();return()=>e.back()}function K(){let e=d();return()=>e.refresh()}function E(){let e=d(),t=h();return r=>e.prefetch(t(r))}import{useSearchParams as D}from"next/navigation";import{usePathname as O}from"next/navigation";import{getLanguageRouting as z,publicPathname as q,splitLanguagePath as Q}from"@donotdev/core";function m(){return Q(q(O()??"/"),z()).path}function R(){let e=m(),r=D().toString(),n=r?`?${r}`:void 0;return{pathname:e,search:n,hash:"",state:null}}import{useParams as F}from"next/navigation";function x(){let e=F();return e||{}}function M(e){let r=x()[e];if(typeof r=="string")return r;if(Array.isArray(r)&&r.length>0)return r[0]}import{useSearchParams as j}from"next/navigation";function A(){return j()}function _(e){let t=m(),r=e.replace(/:[^/]+/g,"([^/]+)").replace(/\*/g,".*"),n=new RegExp(`^${r}$`),o=t.match(n);if(!o)return null;let u=e.match(/:[^/]+/g)?.map(a=>a.slice(1))||[],s={};return u.forEach((a,i)=>{s[a]=o[i+1]||""}),{params:s,pathname:t,pattern:e}}import{useCallback as S}from"react";function B(){let e=A(),t=P(),r=R(),n=S((s,a)=>{let i=new URLSearchParams(e.toString());i.set(s,a);let p=i.toString(),c=`${r.pathname||"/"}${p?`?${p}`:""}`;t(c)},[e,t,r.pathname]),o=S(s=>{let a=new URLSearchParams(e.toString());a.delete(s);let i=a.toString(),l=`${r.pathname||"/"}${i?`?${i}`:""}`;t(l)},[e,t,r.pathname]),u=S(()=>{let s=r.pathname||"/";t(s)},[t,r.pathname]);return{query:e,setQuery:n,removeQuery:o,clearQueries:u}}import{useMemo as Z}from"react";import{isClient as J,FEATURE_STATUS as V}from"@donotdev/core";import{useAppConfig as W,useAuthConfig as X}from"@donotdev/core";import*as k from"@donotdev/auth";import{DEGRADED_AUTH_API as Y}from"@donotdev/core";var v=k?.useAuth;function H(e){return Y[e]}function g(e){return v?v(e):H(e)}var Le=k?.PasswordResetCallback??(()=>null);function ee(e={}){let{auth:t,redirectTo:r,condition:n}=e,o=X(),u=W().auth===!1,s=g("user"),a=g("can"),i=g("status");return Z(()=>{let l={shouldRedirect:!1,redirectTo:null,isChecking:!1};if(!J())return l;if(i===V.INITIALIZING)return{...l,isChecking:!0};if(n){let c=n(s,i);return{shouldRedirect:c,redirectTo:c&&r||null,isChecking:!1}}if(t!==!1&&t!==void 0){if(!a)return l;if(!a.navigate(t)){if(u&&!r)throw new Error("[dndev] This route declares auth requirements but AppConfig.auth is false, so there is no auth route to redirect to. Enable auth in AppConfig or remove the route's auth requirement.");let c=null;if(typeof t=="object"&&t.required&&!s){let f=window.location.search,C=f.includes("code=")||f.includes("state=")||f.includes("error="),y=o.authRoute;C?c=`${y}${f}`:c=y}else typeof t=="object"&&t.role?c=o.roleRoute:typeof t=="object"&&t.tier?c=o.tierRoute:c=o.roleRoute;return{shouldRedirect:!0,redirectTo:r||c,isChecking:!1}}}return l},[t,i,s,a,n,r,u,o.authRoute,o.roleRoute,o.tierRoute])}export{U as useBack,h as useLocalizedPath,R as useLocation,_ as useMatch,P as useNavigate,x as useParams,E as usePrefetch,B as useQueryParams,ee as useRedirectGuard,K as useRefresh,M as useRouteParam,m as useRoutePath,A as useSearchParams,w as useUrlLanguage};
|
|
@@ -9,12 +9,14 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export { useNavigate, useBack, useRefresh, usePrefetch, } from './useNavigate.vite';
|
|
11
11
|
export { useLocation } from './useLocation.vite';
|
|
12
|
+
export { useRoutePath } from './useRoutePath.vite';
|
|
12
13
|
export { useParams } from './useParams.vite';
|
|
13
14
|
export { useRouteParam } from './useRouteParam.vite';
|
|
14
15
|
export { useSearchParams } from './useSearchParams.vite';
|
|
15
16
|
export { useMatch } from './useMatch.vite';
|
|
16
17
|
export { useQueryParams } from './useQueryParams.vite';
|
|
17
18
|
export { useRedirectGuard } from './useRedirectGuard.vite';
|
|
19
|
+
export { useLocalizedPath, useUrlLanguage } from './useUrlLanguage.vite';
|
|
18
20
|
export type { NavigateOptions } from './types';
|
|
19
21
|
export type { RedirectGuardOptions, RedirectGuardResult, } from './useRedirectGuard.vite';
|
|
20
22
|
//# sourceMappingURL=hooks.vite.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.vite.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/hooks.vite.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,EACV,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,YAAY,EACV,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"hooks.vite.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/hooks.vite.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,EACV,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACzE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,YAAY,EACV,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useNavigate as
|
|
1
|
+
"use client";import{useNavigate as S}from"react-router-dom";import{getLanguageRouting as T,isClient as G,splitLanguagePath as U,useOverlayStore as N}from"@donotdev/core";import{useHref as b}from"react-router-dom";import{getLanguageRouting as y,localizePath as C,splitLanguagePath as k}from"@donotdev/core";function p(){return k(b("/"),y()).language}function I(){let e=p(),t=y();return r=>C(r,e,t)}function g(){let e=S(),t=N(n=>n.closeAll),r=p();return(n,a)=>{if(n==="back")return t(),e(-1);t();let o=n.startsWith("/")?U(n,T()):null;if(o?.prefixed&&o.language!==r){window.location.assign(n);return}let s=o?.prefixed?o.path:n;return a?.replace?e(s,{replace:!0}):e(s)}}function K(){let e=S();return()=>e(-1)}function O(){return()=>{G()&&window.location.reload()}}function $(){return e=>{}}import{useLocation as E}from"react-router-dom";function m(){return E()}import{useLocation as M}from"react-router-dom";function Q(){return M().pathname}import{useParams as q}from"react-router-dom";function R(){return q()}function D(e){let r=R()[e];if(typeof r=="string")return r;if(Array.isArray(r)&&r.length>0)return r[0]}import{useSearchParams as _}from"react-router-dom";function P(){return _()[0]}import{useMatch as j}from"react-router-dom";function z(e){return j(e)}import{useCallback as A}from"react";function F(){let e=P(),t=g(),r=m(),n=A((s,c)=>{let u=new URLSearchParams(e.toString());u.set(s,c);let f=u.toString(),l=`${r.pathname||"/"}${f?`?${f}`:""}`;t(l)},[e,t,r.pathname]),a=A(s=>{let c=new URLSearchParams(e.toString());c.delete(s);let u=c.toString(),d=`${r.pathname||"/"}${u?`?${u}`:""}`;t(d)},[e,t,r.pathname]),o=A(()=>{let s=r.pathname||"/";t(s)},[t,r.pathname]);return{query:e,setQuery:n,removeQuery:a,clearQueries:o}}import{useMemo as W}from"react";import{isClient as Z,FEATURE_STATUS as J}from"@donotdev/core";import{useAppConfig as V,useAuthConfig as X}from"@donotdev/core";import*as L from"@donotdev/auth";import{DEGRADED_AUTH_API as B}from"@donotdev/core";var v=L?.useAuth;function H(e){return B[e]}function h(e){return v?v(e):H(e)}var we=L?.PasswordResetCallback??(()=>null);function Y(e={}){let{auth:t,redirectTo:r,condition:n}=e,a=m(),o=X(),s=V().auth===!1,c=h("user"),u=h("can"),f=h("status");return W(()=>{let l={shouldRedirect:!1,redirectTo:null,isChecking:!1};if(!Z())return l;if(f===J.INITIALIZING)return{...l,isChecking:!0};if(n){let i=n(c,f);return{shouldRedirect:i,redirectTo:i&&r||null,isChecking:!1}}if(t!==!1&&t!==void 0){if(!u)return l;if(!u.navigate(t)){if(s&&!r)throw new Error("[dndev] This route declares auth requirements but AppConfig.auth is false, so there is no auth route to redirect to. Enable auth in AppConfig or remove the route's auth requirement.");let i=null;if(typeof t=="object"&&t.required&&!c){let w=a.search.includes("code=")||a.search.includes("state=")||a.search.includes("error="),x=o.authRoute;w?i=`${x}${a.search}`:i=x}else typeof t=="object"&&t.role?i=o.roleRoute:typeof t=="object"&&t.tier?i=o.tierRoute:i=o.roleRoute;return{shouldRedirect:!0,redirectTo:r||i,isChecking:!1}}}return l},[t,f,c,u,n,r,a.search,s,o.authRoute,o.roleRoute,o.tierRoute])}export{K as useBack,I as useLocalizedPath,m as useLocation,z as useMatch,g as useNavigate,R as useParams,$ as usePrefetch,F as useQueryParams,Y as useRedirectGuard,O as useRefresh,D as useRouteParam,Q as useRoutePath,P as useSearchParams,p as useUrlLanguage};
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Current location, route-relative: `pathname` has no language prefix (`/en/produits`
|
|
3
|
+
* → `/produits`), so route matching, breadcrumbs and guards see app paths.
|
|
4
|
+
*
|
|
5
|
+
* Reads the query string (`search`): in a cached (static) render that moves the
|
|
6
|
+
* render to the browser up to the nearest Suspense boundary. Use `useRoutePath()`
|
|
7
|
+
* when only the path is needed.
|
|
8
|
+
*
|
|
9
|
+
* @version 0.2.0
|
|
10
|
+
* @since 0.0.1
|
|
11
|
+
* @author AMBROISE PARK Consulting
|
|
12
|
+
*/
|
|
1
13
|
export declare function useLocation(): {
|
|
2
14
|
pathname: string;
|
|
3
15
|
search: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocation.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useLocation.next.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocation.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useLocation.next.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW;;;;;EAY1B"}
|
|
@@ -3,18 +3,31 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* @fileoverview Next.js-specific location hook
|
|
5
5
|
*
|
|
6
|
-
* @version 0.
|
|
6
|
+
* @version 0.2.0
|
|
7
|
+
* @since 0.0.1
|
|
8
|
+
* @author AMBROISE PARK Consulting
|
|
9
|
+
*/
|
|
10
|
+
import { useSearchParams as useNextSearchParams } from 'next/navigation';
|
|
11
|
+
import { useRoutePath } from './useRoutePath.next';
|
|
12
|
+
/**
|
|
13
|
+
* Current location, route-relative: `pathname` has no language prefix (`/en/produits`
|
|
14
|
+
* → `/produits`), so route matching, breadcrumbs and guards see app paths.
|
|
15
|
+
*
|
|
16
|
+
* Reads the query string (`search`): in a cached (static) render that moves the
|
|
17
|
+
* render to the browser up to the nearest Suspense boundary. Use `useRoutePath()`
|
|
18
|
+
* when only the path is needed.
|
|
19
|
+
*
|
|
20
|
+
* @version 0.2.0
|
|
7
21
|
* @since 0.0.1
|
|
8
22
|
* @author AMBROISE PARK Consulting
|
|
9
23
|
*/
|
|
10
|
-
import { usePathname, useSearchParams as useNextSearchParams, } from 'next/navigation';
|
|
11
24
|
export function useLocation() {
|
|
12
|
-
const pathname =
|
|
25
|
+
const pathname = useRoutePath();
|
|
13
26
|
const searchParams = useNextSearchParams();
|
|
14
27
|
const searchString = searchParams.toString();
|
|
15
28
|
const search = searchString ? `?${searchString}` : undefined;
|
|
16
29
|
return {
|
|
17
|
-
pathname
|
|
30
|
+
pathname,
|
|
18
31
|
search,
|
|
19
32
|
hash: '',
|
|
20
33
|
state: null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMatch.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useMatch.next.ts"],"names":[],"mappings":"AAKA,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM;;;;SA0BvC"}
|
|
1
|
+
{"version":3,"file":"useMatch.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useMatch.next.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM;;;;SA0BvC"}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
// packages/ui/src/routing/hooks/useMatch.next.ts
|
|
3
|
-
import {
|
|
3
|
+
import { useRoutePath } from './useRoutePath.next';
|
|
4
|
+
/**
|
|
5
|
+
* Match the current route path (language prefix stripped) against a pattern.
|
|
6
|
+
*
|
|
7
|
+
* @version 0.2.0
|
|
8
|
+
* @since 0.0.1
|
|
9
|
+
*/
|
|
4
10
|
export function useMatch(pattern) {
|
|
5
|
-
const pathname =
|
|
11
|
+
const pathname = useRoutePath();
|
|
6
12
|
// Simple pattern matching for Next.js
|
|
7
13
|
const regexPattern = pattern
|
|
8
14
|
.replace(/:[^/]+/g, '([^/]+)') // Replace :param with regex group
|
|
@@ -2,8 +2,13 @@ import type { NavigateOptions } from './types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Navigation hook. Auth is handled by AuthGuard (cold-load redirect).
|
|
4
4
|
* Protected routes are hidden from unauthorized users via useAccessibleRoutes.
|
|
5
|
+
* App paths stay in the current URL's language (`/produits` → `/en/produits` on an
|
|
6
|
+
* English page); a path with an explicit language prefix keeps it.
|
|
7
|
+
*
|
|
8
|
+
* @version 0.3.0
|
|
9
|
+
* @since 0.0.1
|
|
5
10
|
*/
|
|
6
|
-
export declare function useNavigate(): (
|
|
11
|
+
export declare function useNavigate(): (path: string, options?: NavigateOptions) => void;
|
|
7
12
|
export declare function useBack(): () => void;
|
|
8
13
|
export declare function useRefresh(): () => void;
|
|
9
14
|
export declare function usePrefetch(): (to: string) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNavigate.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useNavigate.next.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"useNavigate.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useNavigate.next.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG/C;;;;;;;;GAQG;AACH,wBAAgB,WAAW,KAKjB,MAAM,MAAM,EAAE,UAAU,eAAe,UAyBhD;AAED,wBAAgB,OAAO,eAGtB;AAED,wBAAgB,UAAU,eAGzB;AAED,wBAAgB,WAAW,KAGjB,IAAI,MAAM,UACnB"}
|
|
@@ -4,25 +4,33 @@
|
|
|
4
4
|
* @fileoverview Next.js-specific navigation hooks
|
|
5
5
|
* @description Navigation hooks for Next.js App Router
|
|
6
6
|
*
|
|
7
|
-
* @version 0.
|
|
7
|
+
* @version 0.3.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
import { useRouter as useNextRouter } from 'next/navigation';
|
|
12
12
|
import { isClient, useOverlayStore } from '@donotdev/core';
|
|
13
|
+
import { useLocalizedPath } from './useUrlLanguage.next';
|
|
13
14
|
/**
|
|
14
15
|
* Navigation hook. Auth is handled by AuthGuard (cold-load redirect).
|
|
15
16
|
* Protected routes are hidden from unauthorized users via useAccessibleRoutes.
|
|
17
|
+
* App paths stay in the current URL's language (`/produits` → `/en/produits` on an
|
|
18
|
+
* English page); a path with an explicit language prefix keeps it.
|
|
19
|
+
*
|
|
20
|
+
* @version 0.3.0
|
|
21
|
+
* @since 0.0.1
|
|
16
22
|
*/
|
|
17
23
|
export function useNavigate() {
|
|
18
24
|
const router = useNextRouter();
|
|
19
25
|
const closeAll = useOverlayStore((state) => state.closeAll);
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
const localize = useLocalizedPath();
|
|
27
|
+
return (path, options) => {
|
|
28
|
+
if (path === 'back') {
|
|
22
29
|
closeAll();
|
|
23
30
|
return router.back();
|
|
24
31
|
}
|
|
25
32
|
closeAll();
|
|
33
|
+
const to = localize(path);
|
|
26
34
|
if (options?.preserveScroll && isClient()) {
|
|
27
35
|
const scrollY = window.scrollY;
|
|
28
36
|
if (options?.replace) {
|
|
@@ -51,5 +59,6 @@ export function useRefresh() {
|
|
|
51
59
|
}
|
|
52
60
|
export function usePrefetch() {
|
|
53
61
|
const router = useNextRouter();
|
|
54
|
-
|
|
62
|
+
const localize = useLocalizedPath();
|
|
63
|
+
return (to) => router.prefetch(localize(to));
|
|
55
64
|
}
|
|
@@ -2,8 +2,14 @@ import type { NavigateOptions } from './types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Navigation hook. Auth is handled by AuthGuard (cold-load redirect).
|
|
4
4
|
* Protected routes are hidden from unauthorized users via useAccessibleRoutes.
|
|
5
|
+
* The router basename carries the language prefix (createAppRouter), so app paths
|
|
6
|
+
* stay in the current language. A path prefixed with another language opens that
|
|
7
|
+
* language's URL (document navigation: the router restarts under its prefix).
|
|
8
|
+
*
|
|
9
|
+
* @version 0.3.0
|
|
10
|
+
* @since 0.0.1
|
|
5
11
|
*/
|
|
6
|
-
export declare function useNavigate(): (
|
|
12
|
+
export declare function useNavigate(): (path: string, options?: NavigateOptions) => void | Promise<void>;
|
|
7
13
|
export declare function useBack(): () => void | Promise<void>;
|
|
8
14
|
export declare function useRefresh(): () => void;
|
|
9
15
|
export declare function usePrefetch(): (_to: string) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNavigate.vite.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useNavigate.vite.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useNavigate.vite.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useNavigate.vite.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG/C;;;;;;;;;GASG;AACH,wBAAgB,WAAW,KAKjB,MAAM,MAAM,EAAE,UAAU,eAAe,0BAoBhD;AAED,wBAAgB,OAAO,+BAGtB;AAED,wBAAgB,UAAU,eAIzB;AAED,wBAAgB,WAAW,KACjB,KAAK,MAAM,UAGpB"}
|
|
@@ -4,25 +4,41 @@
|
|
|
4
4
|
* @fileoverview Vite-specific navigation hooks
|
|
5
5
|
* @description Navigation hooks for React Router (Vite)
|
|
6
6
|
*
|
|
7
|
-
* @version 0.
|
|
7
|
+
* @version 0.3.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
import { useNavigate as useRouterNavigate } from 'react-router-dom';
|
|
12
|
-
import { isClient, useOverlayStore } from '@donotdev/core';
|
|
12
|
+
import { getLanguageRouting, isClient, splitLanguagePath, useOverlayStore, } from '@donotdev/core';
|
|
13
|
+
import { useUrlLanguage } from './useUrlLanguage.vite';
|
|
13
14
|
/**
|
|
14
15
|
* Navigation hook. Auth is handled by AuthGuard (cold-load redirect).
|
|
15
16
|
* Protected routes are hidden from unauthorized users via useAccessibleRoutes.
|
|
17
|
+
* The router basename carries the language prefix (createAppRouter), so app paths
|
|
18
|
+
* stay in the current language. A path prefixed with another language opens that
|
|
19
|
+
* language's URL (document navigation: the router restarts under its prefix).
|
|
20
|
+
*
|
|
21
|
+
* @version 0.3.0
|
|
22
|
+
* @since 0.0.1
|
|
16
23
|
*/
|
|
17
24
|
export function useNavigate() {
|
|
18
25
|
const routerNavigate = useRouterNavigate();
|
|
19
26
|
const closeAll = useOverlayStore((state) => state.closeAll);
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
const language = useUrlLanguage();
|
|
28
|
+
return (path, options) => {
|
|
29
|
+
if (path === 'back') {
|
|
22
30
|
closeAll();
|
|
23
31
|
return routerNavigate(-1);
|
|
24
32
|
}
|
|
25
33
|
closeAll();
|
|
34
|
+
const split = path.startsWith('/')
|
|
35
|
+
? splitLanguagePath(path, getLanguageRouting())
|
|
36
|
+
: null;
|
|
37
|
+
if (split?.prefixed && split.language !== language) {
|
|
38
|
+
window.location.assign(path);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const to = split?.prefixed ? split.path : path;
|
|
26
42
|
if (options?.replace)
|
|
27
43
|
return routerNavigate(to, { replace: true });
|
|
28
44
|
return routerNavigate(to);
|
|
@@ -21,7 +21,9 @@ export interface RedirectGuardResult {
|
|
|
21
21
|
* Hook that checks if redirect should happen before render
|
|
22
22
|
*
|
|
23
23
|
* Prevents content flash by determining redirect state synchronously.
|
|
24
|
-
* Returns safe defaults on server (SSR-safe).
|
|
24
|
+
* Returns safe defaults on server (SSR-safe). Reads the query string from
|
|
25
|
+
* `window.location` when it redirects, not through `useSearchParams`: a cached
|
|
26
|
+
* (static) page using it keeps its server-rendered HTML.
|
|
25
27
|
*
|
|
26
28
|
* @param options - Redirect guard configuration
|
|
27
29
|
* @returns Redirect guard state
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRedirectGuard.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useRedirectGuard.next.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"useRedirectGuard.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useRedirectGuard.next.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAI9D,yDAAyD;AACzD,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,IAAI,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;IACxB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,mEAAmE;IAEnE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC;CAC3D;AAED,iDAAiD;AACjD,MAAM,WAAW,mBAAmB;IAClC,qCAAqC;IACrC,cAAc,EAAE,OAAO,CAAC;IACxB,uDAAuD;IACvD,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,gDAAgD;IAChD,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,GAAE,oBAAyB,GACjC,mBAAmB,CAyGrB"}
|
|
@@ -10,23 +10,25 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { useMemo } from 'react';
|
|
12
12
|
import { isClient, FEATURE_STATUS } from '@donotdev/core';
|
|
13
|
-
import { useAuthConfig } from '@donotdev/core';
|
|
14
|
-
import { useLocation } from './useLocation.next';
|
|
13
|
+
import { useAppConfig, useAuthConfig } from '@donotdev/core';
|
|
15
14
|
import { useAuthSafe } from '../../utils/useAuthSafe';
|
|
16
15
|
/**
|
|
17
16
|
* Hook that checks if redirect should happen before render
|
|
18
17
|
*
|
|
19
18
|
* Prevents content flash by determining redirect state synchronously.
|
|
20
|
-
* Returns safe defaults on server (SSR-safe).
|
|
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.
|
|
21
22
|
*
|
|
22
23
|
* @param options - Redirect guard configuration
|
|
23
24
|
* @returns Redirect guard state
|
|
24
25
|
*/
|
|
25
26
|
export function useRedirectGuard(options = {}) {
|
|
26
27
|
const { auth, redirectTo: customRedirectTo, condition } = options;
|
|
27
|
-
// Hooks must be called unconditionally (Rules of Hooks)
|
|
28
|
-
|
|
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.
|
|
29
30
|
const authConfig = useAuthConfig();
|
|
31
|
+
const authDisabled = useAppConfig().auth === false;
|
|
30
32
|
const user = useAuthSafe('user');
|
|
31
33
|
const can = useAuthSafe('can');
|
|
32
34
|
const status = useAuthSafe('status');
|
|
@@ -59,16 +61,22 @@ export function useRedirectGuard(options = {}) {
|
|
|
59
61
|
return noAction;
|
|
60
62
|
// Check if user can navigate to this route
|
|
61
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
|
+
}
|
|
62
68
|
let targetRoute = null;
|
|
63
69
|
// Authentication failure (not logged in) → always redirect
|
|
64
70
|
if (typeof auth === 'object' && auth.required && !user) {
|
|
65
71
|
// Check if we have OAuth parameters that need to be preserved
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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=');
|
|
69
77
|
const authRoute = authConfig.authRoute;
|
|
70
78
|
if (hasOAuthParams) {
|
|
71
|
-
targetRoute = `${authRoute}${
|
|
79
|
+
targetRoute = `${authRoute}${search}`;
|
|
72
80
|
}
|
|
73
81
|
else {
|
|
74
82
|
targetRoute = authRoute;
|
|
@@ -102,7 +110,7 @@ export function useRedirectGuard(options = {}) {
|
|
|
102
110
|
can,
|
|
103
111
|
condition,
|
|
104
112
|
customRedirectTo,
|
|
105
|
-
|
|
113
|
+
authDisabled,
|
|
106
114
|
authConfig.authRoute,
|
|
107
115
|
authConfig.roleRoute,
|
|
108
116
|
authConfig.tierRoute,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRedirectGuard.vite.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useRedirectGuard.vite.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAK9D,yDAAyD;AACzD,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,IAAI,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;IACxB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,mEAAmE;
|
|
1
|
+
{"version":3,"file":"useRedirectGuard.vite.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useRedirectGuard.vite.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAK9D,yDAAyD;AACzD,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,IAAI,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;IACxB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,mEAAmE;IAEnE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC;CAC3D;AAED,iDAAiD;AACjD,MAAM,WAAW,mBAAmB;IAClC,qCAAqC;IACrC,cAAc,EAAE,OAAO,CAAC;IACxB,uDAAuD;IACvD,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,gDAAgD;IAChD,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,GAAE,oBAAyB,GACjC,mBAAmB,CAwGrB"}
|