@donotdev/ui 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{GoToDialog-CICRYHHG.js → GoToDialog-KSBGOIWO.js} +1 -1
- package/dist/chunk-MS7ZIW5Z.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 +14 -9
- 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 +2 -1
- 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/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 +3 -11
- package/dist/crud/components/EntityDisplayRenderer.d.ts.map +1 -1
- package/dist/crud/components/EntityDisplayRenderer.js +4 -1
- package/dist/crud/components/EntityFormRenderer.d.ts.map +1 -1
- package/dist/crud/components/EntityFormRenderer.js +27 -5
- package/dist/crud/components/EntityList.d.ts +4 -4
- package/dist/crud/components/EntityList.d.ts.map +1 -1
- package/dist/crud/components/EntityList.js +136 -59
- 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 +28 -0
- package/dist/crud/components/cellEditFor.d.ts.map +1 -0
- package/dist/crud/components/cellEditFor.js +54 -0
- package/dist/crud/components/entityParent.d.ts +40 -0
- package/dist/crud/components/entityParent.d.ts.map +1 -0
- package/dist/crud/components/entityParent.js +54 -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 +34 -0
- package/dist/crud/crudImports.d.ts +2 -0
- package/dist/crud/crudImports.d.ts.map +1 -1
- package/dist/crud/crudImports.js +2 -0
- package/dist/dndev-next.css +483 -145
- package/dist/dndev.css +483 -145
- 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/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 +39 -36
- 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.map +1 -1
- package/dist/internal/providers/UIProviders.js +7 -2
- package/dist/providers/NextJsAppProviders.d.ts +5 -1
- package/dist/providers/NextJsAppProviders.d.ts.map +1 -1
- package/dist/providers/NextJsAppProviders.js +36 -5
- package/dist/providers/ViteAppProviders.d.ts.map +1 -1
- package/dist/providers/ViteAppProviders.js +42 -4
- package/dist/routing/404.js +4 -4
- 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.map +1 -1
- package/dist/routing/hooks/useRedirectGuard.next.js +7 -1
- 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/useNavigation.js +4 -4
- package/dist/styles/index.css +483 -145
- 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/PAGES.md +7 -0
- package/guidelines/ROUTING.md +4 -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/GoToDialog-YGBON6FR.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
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { Dialog, LinkRendererProvider, Toaster, TooltipProvider, } from '@donotdev/components';
|
|
4
4
|
import { useOverlayStore } from '@donotdev/core';
|
|
5
|
+
import { Link } from '../../routing/Link';
|
|
5
6
|
import DnDevErrorBoundary from '../common/DnDevErrorBoundary';
|
|
6
7
|
import GlobalErrorFallback from '../common/GlobalErrorFallback';
|
|
8
|
+
/** Router link for components' `href` props (Card): Next Link or react-router Link. */
|
|
9
|
+
function RouterLinkRenderer({ href, ...rest }) {
|
|
10
|
+
return _jsx(Link, { path: href, ...rest });
|
|
11
|
+
}
|
|
7
12
|
function UIGlobalErrorFallback(props) {
|
|
8
13
|
return _jsx(GlobalErrorFallback, { ...props });
|
|
9
14
|
}
|
|
@@ -15,7 +20,7 @@ function UIGlobalErrorFallback(props) {
|
|
|
15
20
|
* @author AMBROISE PARK Consulting
|
|
16
21
|
*/
|
|
17
22
|
export function UIProviders({ children }) {
|
|
18
|
-
return (_jsx(DnDevErrorBoundary, { level: "app", fallback: UIGlobalErrorFallback, children: _jsxs(TooltipProvider, { children: [children, _jsx(Toaster, {}), _jsx(ModalDialog, {})] }) }));
|
|
23
|
+
return (_jsx(DnDevErrorBoundary, { level: "app", fallback: UIGlobalErrorFallback, children: _jsx(LinkRendererProvider, { value: RouterLinkRenderer, children: _jsxs(TooltipProvider, { children: [children, _jsx(Toaster, {}), _jsx(ModalDialog, {})] }) }) }));
|
|
19
24
|
}
|
|
20
25
|
/**
|
|
21
26
|
* ModalDialog - Renders modal dialog using store directly
|
|
@@ -4,9 +4,13 @@ import type { AppProvidersProps } from '@donotdev/core';
|
|
|
4
4
|
*
|
|
5
5
|
* Clean provider hierarchy with configuration via context (no prop drilling).
|
|
6
6
|
*
|
|
7
|
+
* Language: the URL's with 2+ languages (one URL per language), else the request's
|
|
8
|
+
* (`serverCookies` / `acceptLanguage`). Language switchers navigate client-side to the
|
|
9
|
+
* other language's URL (LanguageNavigationProvider, Next router).
|
|
10
|
+
*
|
|
7
11
|
* Provider hierarchy:
|
|
8
12
|
* 1. AppConfigProvider (configuration context)
|
|
9
|
-
* 2.
|
|
13
|
+
* 2. AutoMetaTags (SEO head, server-rendered; no Helmet on Next)
|
|
10
14
|
* 3. NextJsStoresInitializer (store setup, SSR-safe)
|
|
11
15
|
* 4. QueryProviders (React Query)
|
|
12
16
|
* 5. UIProviders (design system)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NextJsAppProviders.d.ts","sourceRoot":"","sources":["../../src/providers/NextJsAppProviders.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NextJsAppProviders.d.ts","sourceRoot":"","sources":["../../src/providers/NextJsAppProviders.tsx"],"names":[],"mappings":"AAoCA,OAAO,KAAK,EAAE,iBAAiB,EAAoB,MAAM,gBAAgB,CAAC;AAwF1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,WAAW,uBAAwB,SAAQ,iBAAiB;IAChE;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,+EAA+E;IAC/E,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAQD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,+BA6FhE"}
|
|
@@ -9,11 +9,15 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
9
9
|
* @since 0.0.1
|
|
10
10
|
* @author AMBROISE PARK Consulting
|
|
11
11
|
*/
|
|
12
|
+
import { useRouter } from 'next/navigation';
|
|
12
13
|
import { lazy, Suspense, useEffect, useMemo, useState } from 'react';
|
|
13
14
|
import { ReactQueryStreamedHydration } from '@tanstack/react-query-next-experimental';
|
|
14
|
-
import { AppConfigProvider, AuthSessionProvider, getProvider, getRequestLanguage, hasProvider, QueryProviders, RequestLanguageProvider, } from '@donotdev/core';
|
|
15
|
+
import { AppConfigProvider, AuthSessionProvider, getI18nInstance, getLanguageRouting, getProvider, getRequestLanguage, hasProvider, isMultilingual, LanguageNavigationProvider, QueryProviders, RequestLanguageProvider, } from '@donotdev/core';
|
|
15
16
|
import { useConsent } from '@donotdev/core';
|
|
17
|
+
// Platform-specific hooks via conditional exports
|
|
18
|
+
import { useUrlLanguage } from '@donotdev/ui/routing/hooks';
|
|
16
19
|
import { NextJsStoresInitializer } from '../internal/initializers/NextJsStoresInitializer';
|
|
20
|
+
import { AutoMetaTags } from '../internal/layout/components/AutoMetaTags';
|
|
17
21
|
import FaviconHead from '../internal/layout/components/FaviconHead';
|
|
18
22
|
import PerformanceHints from '../internal/layout/components/PerformanceHints';
|
|
19
23
|
import { DnDevLayout } from '../internal/layout/DnDevLayout';
|
|
@@ -48,6 +52,29 @@ function ConsentBanner() {
|
|
|
48
52
|
}
|
|
49
53
|
return (_jsx(Suspense, { fallback: null, children: _jsx(CookieConsent, {}) }));
|
|
50
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Language of the render. 2+ languages: the URL's (`/en/…`, the default language at
|
|
57
|
+
* the root; the generated proxy already moved a first visit to the visitor's
|
|
58
|
+
* language). One language: from the request headers (language cookie >
|
|
59
|
+
* Accept-Language > fallback). Same inputs on the server and in the hydration pass.
|
|
60
|
+
*/
|
|
61
|
+
function useRenderLanguage(serverCookies, acceptLanguage) {
|
|
62
|
+
const urlLanguage = useUrlLanguage();
|
|
63
|
+
const multilingual = isMultilingual(getLanguageRouting().languages);
|
|
64
|
+
const requestLanguage = useMemo(() => getRequestLanguage(serverCookies, acceptLanguage), [serverCookies, acceptLanguage]);
|
|
65
|
+
return multilingual ? urlLanguage : requestLanguage;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The live i18n instance follows the render language: a language switch navigates
|
|
69
|
+
* client-side to the other language's URL, and the page re-renders in it.
|
|
70
|
+
*/
|
|
71
|
+
function useFollowLanguage(language) {
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
const instance = getI18nInstance();
|
|
74
|
+
if (instance.language !== language)
|
|
75
|
+
void instance.changeLanguage(language);
|
|
76
|
+
}, [language]);
|
|
77
|
+
}
|
|
51
78
|
/** Auth session snapshot of the request, `null` when the auth provider cannot tell. */
|
|
52
79
|
function readAuthSnapshot(cookieHeader) {
|
|
53
80
|
if (cookieHeader === undefined || !hasProvider('auth'))
|
|
@@ -56,9 +83,13 @@ function readAuthSnapshot(cookieHeader) {
|
|
|
56
83
|
}
|
|
57
84
|
export function NextJsAppProviders(props) {
|
|
58
85
|
const { config = {}, layout, children, serverCookies, acceptLanguage, customStores, } = props;
|
|
59
|
-
// Same header values on the server and in the hydration pass → same language
|
|
60
|
-
// signed-in state on both, so the first paint is final (no keys, no auth swap).
|
|
61
|
-
const
|
|
86
|
+
// Same URL and header values on the server and in the hydration pass → same language
|
|
87
|
+
// and signed-in state on both, so the first paint is final (no keys, no auth swap).
|
|
88
|
+
const language = useRenderLanguage(serverCookies, acceptLanguage);
|
|
89
|
+
useFollowLanguage(language);
|
|
90
|
+
// Language switchers (core) open the other language's URL through the Next router
|
|
91
|
+
const router = useRouter();
|
|
92
|
+
const navigateToLanguage = (url) => router.push(url, { scroll: false });
|
|
62
93
|
const authSnapshot = useMemo(() => readAuthSnapshot(serverCookies), [serverCookies]);
|
|
63
94
|
// SSR is the default for Next apps: render the provider tree on the server so
|
|
64
95
|
// page content is present in the initial HTML (crawlable, real SSR). An app
|
|
@@ -73,5 +104,5 @@ export function NextJsAppProviders(props) {
|
|
|
73
104
|
if (!ssr && !isMounted) {
|
|
74
105
|
return _jsx(_Fragment, { children: children });
|
|
75
106
|
}
|
|
76
|
-
return (_jsx(RequestLanguageProvider, { language:
|
|
107
|
+
return (_jsx(RequestLanguageProvider, { language: language, children: _jsx(LanguageNavigationProvider, { navigate: navigateToLanguage, children: _jsx(AuthSessionProvider, { snapshot: authSnapshot, children: _jsxs(AppConfigProvider, { config: config, platform: "nextjs", children: [_jsx(SentryInitializer, {}), _jsxs(NextJsStoresInitializer, { serverCookies: serverCookies, customStores: customStores, children: [_jsx(FaviconHead, {}), _jsx(PerformanceHints, {}), _jsx(QueryProviders, { children: _jsx(ReactQueryStreamedHydration, { children: _jsxs(UIProviders, { children: [_jsx(AutoMetaTags, {}), _jsx(DnDevLayout, { layout: layout, children: children }), _jsx(ConsentBanner, {}), _jsx(AuthReturnTo, {}), _jsx(PasswordResetCallback, {}), _jsx(Suspense, { fallback: null, children: _jsx(PWAUpdateNotification, {}) }), _jsx(Suspense, { fallback: null, children: _jsx(RedirectOverlay, {}) })] }) }) })] })] }) }) }) }));
|
|
77
108
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ViteAppProviders.d.ts","sourceRoot":"","sources":["../../src/providers/ViteAppProviders.tsx"],"names":[],"mappings":"AAcA,OAAO,aAAa,CAAC;AACrB,OAAO,gBAAgB,CAAC;AACxB,OAAO,sBAAsB,CAAC;AAC9B,OAAO,gBAAgB,CAAC;AACxB,OAAO,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"ViteAppProviders.d.ts","sourceRoot":"","sources":["../../src/providers/ViteAppProviders.tsx"],"names":[],"mappings":"AAcA,OAAO,aAAa,CAAC;AACrB,OAAO,gBAAgB,CAAC;AACxB,OAAO,sBAAsB,CAAC;AAC9B,OAAO,gBAAgB,CAAC;AACxB,OAAO,gBAAgB,CAAC;AAUxB,OAAO,KAAK,EAAE,iBAAiB,EAAoB,MAAM,gBAAgB,CAAC;AAyC1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,+BA+DxD"}
|
|
@@ -8,14 +8,14 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
|
-
import { lazy, Suspense, useMemo } from 'react';
|
|
11
|
+
import { lazy, Suspense, useEffect, useMemo, useRef, useState } from 'react';
|
|
12
12
|
// Import virtual modules to populate globalThis._DNDEV_CONFIG_ before any components load
|
|
13
13
|
import 'virtual:env';
|
|
14
14
|
import 'virtual:themes';
|
|
15
15
|
import 'virtual:i18n-mapping';
|
|
16
16
|
import 'virtual:routes';
|
|
17
17
|
import 'virtual:assets';
|
|
18
|
-
import { AppConfigProvider } from '@donotdev/core';
|
|
18
|
+
import { AppConfigProvider, applyFirstVisitLanguage, getI18nInstance, getLanguageRouting, getUrlLanguage, LanguageNavigationProvider, } from '@donotdev/core';
|
|
19
19
|
import { ViteStoresInitializer } from '../internal/initializers/ViteStoresInitializer';
|
|
20
20
|
import { NavigationProvider } from '../internal/providers/NavigationProvider';
|
|
21
21
|
import { SentryInitializer } from '../internal/providers/SentryInitializer';
|
|
@@ -33,6 +33,19 @@ const FaviconHead = lazy(() => import('../internal/layout/components/FaviconHead
|
|
|
33
33
|
const PerformanceHints = lazy(() => import('../internal/layout/components/PerformanceHints').then((m) => ({
|
|
34
34
|
default: m.default,
|
|
35
35
|
})));
|
|
36
|
+
/** Language of the browser URL (prefix, else the default language). */
|
|
37
|
+
function currentUrlLanguage() {
|
|
38
|
+
return getUrlLanguage(window.location.pathname);
|
|
39
|
+
}
|
|
40
|
+
/** Stop the history listener of a router replaced by a language switch. */
|
|
41
|
+
function useDisposeReplacedRouter(router) {
|
|
42
|
+
const previous = useRef(router);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (previous.current !== router)
|
|
45
|
+
previous.current.dispose();
|
|
46
|
+
previous.current = router;
|
|
47
|
+
}, [router]);
|
|
48
|
+
}
|
|
36
49
|
/**
|
|
37
50
|
* ViteAppProviders - Vite platform-specific app providers
|
|
38
51
|
*
|
|
@@ -77,6 +90,31 @@ export function ViteAppProviders(props) {
|
|
|
77
90
|
// Virtual modules are loaded at module level (lines 20-26), so routes are available
|
|
78
91
|
// HomePage.tsx is automatically assigned path "/" by RouteDiscovery convention
|
|
79
92
|
// Memoized so the router instance is stable across re-renders (Item 86)
|
|
80
|
-
|
|
81
|
-
|
|
93
|
+
// The router runs under the URL's language prefix (createAppRouter basename). A
|
|
94
|
+
// language switch moves the URL to the other language's prefix and recreates the
|
|
95
|
+
// router under it: client-side, no document reload.
|
|
96
|
+
const [urlLanguage, setUrlLanguage] = useState(currentUrlLanguage);
|
|
97
|
+
const router = useMemo(() => createAppRouter({ routeGroups, layout }),
|
|
98
|
+
// urlLanguage: a new router (new basename) per URL language
|
|
99
|
+
[routeGroups, layout, urlLanguage]);
|
|
100
|
+
useDisposeReplacedRouter(router);
|
|
101
|
+
// Back/forward across languages: the router of the other prefix takes over
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
const onPopState = () => {
|
|
104
|
+
// Same rule as a first visit (and as the Next proxy) for an unprefixed URL
|
|
105
|
+
const routing = getLanguageRouting();
|
|
106
|
+
applyFirstVisitLanguage(routing.languages, routing.defaultLanguage);
|
|
107
|
+
const language = currentUrlLanguage();
|
|
108
|
+
void getI18nInstance().changeLanguage(language);
|
|
109
|
+
setUrlLanguage(language);
|
|
110
|
+
};
|
|
111
|
+
window.addEventListener('popstate', onPopState);
|
|
112
|
+
return () => window.removeEventListener('popstate', onPopState);
|
|
113
|
+
}, []);
|
|
114
|
+
const navigateToLanguage = (url, language) => {
|
|
115
|
+
window.history.pushState(null, '', url);
|
|
116
|
+
void getI18nInstance().changeLanguage(language);
|
|
117
|
+
setUrlLanguage(language);
|
|
118
|
+
};
|
|
119
|
+
return (_jsxs(AppConfigProvider, { config: config, platform: "vite", children: [_jsx(SentryInitializer, {}), _jsx(ViteStoresInitializer, { customStores: customStores, children: _jsx(Suspense, { fallback: null, children: _jsxs(HelmetProvider, { children: [_jsx(FaviconHead, {}), _jsx(PerformanceHints, {}), _jsx(LanguageNavigationProvider, { navigate: navigateToLanguage, children: _jsx(NavigationProvider, { router: router }) })] }) }) })] }));
|
|
82
120
|
}
|
package/dist/routing/404.js
CHANGED
|
@@ -14,7 +14,7 @@ import { useMemo } from 'react';
|
|
|
14
14
|
import { Button, BUTTON_VARIANT, Stack, Text } from '@donotdev/components';
|
|
15
15
|
import { useTranslation } from '@donotdev/core';
|
|
16
16
|
// Platform-specific hooks via conditional exports
|
|
17
|
-
import {
|
|
17
|
+
import { useNavigate, useRoutePath } from '@donotdev/ui/routing/hooks';
|
|
18
18
|
import { Link } from './Link';
|
|
19
19
|
import { useNavigationItems } from './useNavigation';
|
|
20
20
|
import { Icon } from '../components/common/icon';
|
|
@@ -45,7 +45,7 @@ export const meta = {
|
|
|
45
45
|
*/
|
|
46
46
|
export default function NotFoundPage() {
|
|
47
47
|
const { t } = useTranslation('dndev');
|
|
48
|
-
const
|
|
48
|
+
const pathname = useRoutePath();
|
|
49
49
|
const navigate = useNavigate();
|
|
50
50
|
const navigationItems = useNavigationItems();
|
|
51
51
|
/**
|
|
@@ -83,7 +83,7 @@ export default function NotFoundPage() {
|
|
|
83
83
|
color: 'var(--muted-foreground)',
|
|
84
84
|
textAlign: 'center',
|
|
85
85
|
margin: 0,
|
|
86
|
-
}, children: t('errors.notFound.description', "The page you're looking for doesn't exist or has been moved.") }),
|
|
86
|
+
}, children: t('errors.notFound.description', "The page you're looking for doesn't exist or has been moved.") }), pathname && (_jsx("code", { style: {
|
|
87
87
|
padding: 'var(--gap-sm) var(--gap-md)',
|
|
88
88
|
background: 'var(--muted)',
|
|
89
89
|
borderRadius: 'var(--radius-md)',
|
|
@@ -95,7 +95,7 @@ export default function NotFoundPage() {
|
|
|
95
95
|
overflow: 'hidden',
|
|
96
96
|
textOverflow: 'ellipsis',
|
|
97
97
|
border: '1px solid var(--border-hairline)',
|
|
98
|
-
}, children:
|
|
98
|
+
}, children: pathname }))] }), suggestedRoutes.length > 0 && (_jsxs(Stack, { align: "center", children: [_jsx("p", { className: "dndev-text-base", style: {
|
|
99
99
|
fontSize: 'var(--font-size-md)',
|
|
100
100
|
fontWeight: 'var(--font-weight-semibold)',
|
|
101
101
|
margin: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthGuardFallback.d.ts","sourceRoot":"","sources":["../../src/routing/AuthGuardFallback.tsx"],"names":[],"mappings":"AA6BA,UAAU,sBAAsB;IAC9B,oCAAoC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oCAAoC;IACpC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gCAAgC;IAChC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,uBAAuB;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,WAAW,EACX,cAAqB,EACrB,MAAM,EACN,SAAc,GACf,EAAE,sBAAsB,+
|
|
1
|
+
{"version":3,"file":"AuthGuardFallback.d.ts","sourceRoot":"","sources":["../../src/routing/AuthGuardFallback.tsx"],"names":[],"mappings":"AA6BA,UAAU,sBAAsB;IAC9B,oCAAoC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oCAAoC;IACpC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gCAAgC;IAChC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,uBAAuB;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,WAAW,EACX,cAAqB,EACrB,MAAM,EACN,SAAc,GACf,EAAE,sBAAsB,+BAqHxB;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -14,7 +14,7 @@ import { Card, Button, Separator, Stack, cn } from '@donotdev/components';
|
|
|
14
14
|
import { useTranslation } from '@donotdev/core';
|
|
15
15
|
import { useBreakpoint } from '@donotdev/core';
|
|
16
16
|
// Platform-specific hooks via conditional exports
|
|
17
|
-
import {
|
|
17
|
+
import { useBack } from '@donotdev/ui/routing/hooks';
|
|
18
18
|
import { PageContainer } from '../components/layout/PageContainer';
|
|
19
19
|
// Lazy load MultipleAuthProviders to enable code splitting
|
|
20
20
|
const MultipleAuthProviders = lazy(() => import('@donotdev/auth').then((module) => ({
|
|
@@ -33,7 +33,6 @@ const MultipleAuthProviders = lazy(() => import('@donotdev/auth').then((module)
|
|
|
33
33
|
*/
|
|
34
34
|
export function AuthGuardFallback({ title, description, showBackButton = true, onBack, className = '', }) {
|
|
35
35
|
const { t } = useTranslation(['auth', 'common']);
|
|
36
|
-
const location = useLocation();
|
|
37
36
|
const back = useBack();
|
|
38
37
|
const handleBack = () => {
|
|
39
38
|
if (onBack) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthReturnTo.d.ts","sourceRoot":"","sources":["../../src/routing/AuthReturnTo.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AuthReturnTo.d.ts","sourceRoot":"","sources":["../../src/routing/AuthReturnTo.tsx"],"names":[],"mappings":"AA+BA;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,SAoC3B"}
|
|
@@ -19,6 +19,10 @@ import { useToast } from '@donotdev/components';
|
|
|
19
19
|
import { isClient, safeSessionStorage, useTranslation } from '@donotdev/core';
|
|
20
20
|
import { useNavigate } from '@donotdev/ui/routing/hooks';
|
|
21
21
|
import { useAuthSafe } from '../utils/useAuthSafe';
|
|
22
|
+
/** A path on this site (`/x`), never `//host` or `https://…` (no open redirect). */
|
|
23
|
+
function isSameOriginPath(value) {
|
|
24
|
+
return value.startsWith('/') && !value.startsWith('//') && !value.startsWith('/\\');
|
|
25
|
+
}
|
|
22
26
|
/**
|
|
23
27
|
* AuthReturnTo - Restores navigation after OAuth redirect.
|
|
24
28
|
*
|
|
@@ -45,11 +49,14 @@ export function AuthReturnTo() {
|
|
|
45
49
|
safeSessionStorage.removeItem('dndev.auth.guardToast');
|
|
46
50
|
toast('warning', t('guard.signInRequired', 'Please sign in to access this page'));
|
|
47
51
|
}, []);
|
|
48
|
-
// Return-to after sign-in
|
|
52
|
+
// Return-to after sign-in: saved by AuthGuard (sessionStorage) or passed as
|
|
53
|
+
// `?returnTo=` by the generated proxy's server redirect. Same-origin paths only.
|
|
49
54
|
useEffect(() => {
|
|
50
55
|
if (!user || !isClient())
|
|
51
56
|
return;
|
|
52
|
-
const
|
|
57
|
+
const fromQuery = new URLSearchParams(window.location.search).get('returnTo');
|
|
58
|
+
const returnTo = safeSessionStorage.getItem('dndev.auth.returnTo') ??
|
|
59
|
+
(fromQuery && isSameOriginPath(fromQuery) ? fromQuery : null);
|
|
53
60
|
if (!returnTo)
|
|
54
61
|
return;
|
|
55
62
|
safeSessionStorage.removeItem('dndev.auth.returnTo');
|
package/dist/routing/GoTo.d.ts
CHANGED
|
@@ -11,12 +11,6 @@ export interface GoToProps {
|
|
|
11
11
|
/** Optional callback called after opening command dialog (e.g., to close parent dropdown) */
|
|
12
12
|
onOpen?: () => void;
|
|
13
13
|
}
|
|
14
|
-
/**
|
|
15
|
-
* GoTo - Command palette trigger button
|
|
16
|
-
*
|
|
17
|
-
* Simple button: Search icon + "Go to" label + keyboard shortcut.
|
|
18
|
-
* Opens command dialog on click.
|
|
19
|
-
*/
|
|
20
14
|
export declare const GoTo: ({ display, className, onOpen, }: GoToProps) => import("react").JSX.Element;
|
|
21
15
|
export default GoTo;
|
|
22
16
|
//# sourceMappingURL=GoTo.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GoTo.d.ts","sourceRoot":"","sources":["../../src/routing/GoTo.tsx"],"names":[],"mappings":"AAaA,OAAO,EAA0B,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAGvE,kDAAkD;AAClD,MAAM,WAAW,SAAS;IACxB;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,OAAO,OAAO,CAAC,CAAC;IACjD,2BAA2B;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6FAA6F;IAC7F,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB;
|
|
1
|
+
{"version":3,"file":"GoTo.d.ts","sourceRoot":"","sources":["../../src/routing/GoTo.tsx"],"names":[],"mappings":"AAaA,OAAO,EAA0B,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAGvE,kDAAkD;AAClD,MAAM,WAAW,SAAS;IACxB;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,OAAO,OAAO,CAAC,CAAC;IACjD,2BAA2B;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6FAA6F;IAC7F,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB;AAkBD,eAAO,MAAM,IAAI,GAAI,iCAIlB,SAAS,gCAyCX,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
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 C}from"next/navigation";import{getLanguageRouting as b,localizePath as T,publicPathname as N,splitLanguagePath as I}from"@donotdev/core";function v(){return I(N(C()??"/"),b()).language}function h(){let e=v(),t=b();return r=>T(r,e,t)}function R(){let e=d(),t=$(s=>s.closeAll),r=h();return(s,n)=>{if(s==="back")return t(),e.back();t();let o=r(s);if(n?.preserveScroll&&G()){let a=window.scrollY;n?.replace?e.replace(o):e.push(o),requestAnimationFrame(()=>{window.scrollTo({top:a,behavior:"auto"})});return}return n?.replace?e.replace(o):e.push(o)}}function U(){let e=d();return()=>e.back()}function K(){let e=d();return()=>e.refresh()}function E(){let e=d(),t=h();return r=>e.prefetch(t(r))}import{useSearchParams as D}from"next/navigation";import{usePathname as O}from"next/navigation";import{getLanguageRouting as z,publicPathname as q,splitLanguagePath as Q}from"@donotdev/core";function p(){return Q(q(O()??"/"),z()).path}function f(){let e=p(),r=D().toString(),s=r?`?${r}`:void 0;return{pathname:e,search:s,hash:"",state:null}}import{useParams as F}from"next/navigation";function x(){let e=F();return e||{}}function M(e){let r=x()[e];if(typeof r=="string")return r;if(Array.isArray(r)&&r.length>0)return r[0]}import{useSearchParams as j}from"next/navigation";function A(){return j()}function _(e){let t=p(),r=e.replace(/:[^/]+/g,"([^/]+)").replace(/\*/g,".*"),s=new RegExp(`^${r}$`),n=t.match(s);if(!n)return null;let o=e.match(/:[^/]+/g)?.map(u=>u.slice(1))||[],a={};return o.forEach((u,i)=>{a[u]=n[i+1]||""}),{params:a,pathname:t,pattern:e}}import{useCallback as S}from"react";function B(){let e=A(),t=R(),r=f(),s=S((a,u)=>{let i=new URLSearchParams(e.toString());i.set(a,u);let m=i.toString(),l=`${r.pathname||"/"}${m?`?${m}`:""}`;t(l)},[e,t,r.pathname]),n=S(a=>{let u=new URLSearchParams(e.toString());u.delete(a);let i=u.toString(),P=`${r.pathname||"/"}${i?`?${i}`:""}`;t(P)},[e,t,r.pathname]),o=S(()=>{let a=r.pathname||"/";t(a)},[t,r.pathname]);return{query:e,setQuery:s,removeQuery:n,clearQueries:o}}import{useMemo as Z}from"react";import{isClient as J,FEATURE_STATUS as V}from"@donotdev/core";import{useAppConfig as W,useAuthConfig as X}from"@donotdev/core";import*as k from"@donotdev/auth";import{DEGRADED_AUTH_API as Y}from"@donotdev/core";var w=k?.useAuth;function H(e){return Y[e]}function g(e){return w?w(e):H(e)}var Ce=k?.PasswordResetCallback??(()=>null);function ee(e={}){let{auth:t,redirectTo:r,condition:s}=e,n=f(),o=X(),a=W().auth===!1,u=g("user"),i=g("can"),m=g("status");return Z(()=>{let l={shouldRedirect:!1,redirectTo:null,isChecking:!1};if(!J())return l;if(m===V.INITIALIZING)return{...l,isChecking:!0};if(s){let c=s(u,m);return{shouldRedirect:c,redirectTo:c&&r||null,isChecking:!1}}if(t!==!1&&t!==void 0){if(!i)return l;if(!i.navigate(t)){if(a&&!r)throw new Error("[dndev] This route declares auth requirements but AppConfig.auth is false, so there is no auth route to redirect to. Enable auth in AppConfig or remove the route's auth requirement.");let c=null;if(typeof t=="object"&&t.required&&!u){let L=n.search?.includes("code=")||n.search?.includes("state=")||n.search?.includes("error="),y=o.authRoute;L?c=`${y}${n.search}`:c=y}else typeof t=="object"&&t.role?c=o.roleRoute:typeof t=="object"&&t.tier?c=o.tierRoute:c=o.roleRoute;return{shouldRedirect:!0,redirectTo:r||c,isChecking:!1}}}return l},[t,m,u,i,s,r,n.search,a,o.authRoute,o.roleRoute,o.tierRoute])}export{U as useBack,h as useLocalizedPath,f as useLocation,_ as useMatch,R as useNavigate,x as useParams,E as usePrefetch,B as useQueryParams,ee as useRedirectGuard,K as useRefresh,M as useRouteParam,p as useRoutePath,A as useSearchParams,v as useUrlLanguage};
|
|
@@ -9,12 +9,14 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export { useNavigate, useBack, useRefresh, usePrefetch, } from './useNavigate.vite';
|
|
11
11
|
export { useLocation } from './useLocation.vite';
|
|
12
|
+
export { useRoutePath } from './useRoutePath.vite';
|
|
12
13
|
export { useParams } from './useParams.vite';
|
|
13
14
|
export { useRouteParam } from './useRouteParam.vite';
|
|
14
15
|
export { useSearchParams } from './useSearchParams.vite';
|
|
15
16
|
export { useMatch } from './useMatch.vite';
|
|
16
17
|
export { useQueryParams } from './useQueryParams.vite';
|
|
17
18
|
export { useRedirectGuard } from './useRedirectGuard.vite';
|
|
19
|
+
export { useLocalizedPath, useUrlLanguage } from './useUrlLanguage.vite';
|
|
18
20
|
export type { NavigateOptions } from './types';
|
|
19
21
|
export type { RedirectGuardOptions, RedirectGuardResult, } from './useRedirectGuard.vite';
|
|
20
22
|
//# sourceMappingURL=hooks.vite.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.vite.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/hooks.vite.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,EACV,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,YAAY,EACV,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"hooks.vite.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/hooks.vite.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,EACV,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACzE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,YAAY,EACV,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useNavigate as
|
|
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"}
|