@poadio/starter-next 0.0.0-stage → 0.2.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/.dockerignore +18 -0
- package/.env.example +8 -0
- package/Dockerfile +45 -0
- package/Dockerfile.dockerignore +18 -0
- package/README.md +197 -2
- package/bun.lock +156 -0
- package/gitignore +37 -0
- package/next.config.ts +14 -0
- package/package.json +72 -4
- package/public/logo.svg +1 -0
- package/public/providers/google.svg +1 -0
- package/public/providers/keycloak.svg +1 -0
- package/scripts/dev.mjs +92 -0
- package/scripts/env.mjs +160 -0
- package/scripts/env.test.mjs +93 -0
- package/src/app/(auth)/login/login-form.tsx +258 -0
- package/src/app/(auth)/login/page.tsx +16 -0
- package/src/app/(auth)/mfa/mfa-form.tsx +55 -0
- package/src/app/(auth)/mfa/page.tsx +16 -0
- package/src/app/(auth)/reset/page.tsx +16 -0
- package/src/app/(auth)/reset/reset-form.tsx +51 -0
- package/src/app/app/account/account.css +36 -0
- package/src/app/app/account/account.tsx +476 -0
- package/src/app/app/account/page.tsx +18 -0
- package/src/app/app/dashboard.tsx +58 -0
- package/src/app/app/hello/[name]/page.tsx +38 -0
- package/src/app/app/layout.tsx +12 -0
- package/src/app/app/page.tsx +18 -0
- package/src/app/app/public/page.tsx +15 -0
- package/src/app/app/public/public-content.tsx +31 -0
- package/src/app/globals.css +271 -0
- package/src/app/home.css +186 -0
- package/src/app/home.tsx +92 -0
- package/src/app/icon.svg +1 -0
- package/src/app/layout.tsx +59 -0
- package/src/app/not-found.tsx +6 -0
- package/src/app/page.tsx +6 -0
- package/src/app/providers.tsx +24 -0
- package/src/app/setup/page.tsx +39 -0
- package/src/app/shell.css +752 -0
- package/src/app.meta.ts +41 -0
- package/src/components/brand.tsx +15 -0
- package/src/components/captcha.tsx +93 -0
- package/src/components/link-button.tsx +9 -0
- package/src/components/rich.tsx +14 -0
- package/src/components/shell/app-menu.tsx +127 -0
- package/src/components/shell/app-shell.tsx +268 -0
- package/src/components/shell/page-title.tsx +29 -0
- package/src/components/shell/switches.tsx +35 -0
- package/src/components/shell/use-layout.ts +123 -0
- package/src/core/auth.tsx +228 -0
- package/src/core/env.server.ts +83 -0
- package/src/core/env.tsx +48 -0
- package/src/core/guards.tsx +74 -0
- package/src/core/messages.ts +18 -0
- package/src/core/providers.ts +32 -0
- package/src/core/theme-script.ts +7 -0
- package/src/core/theme.tsx +37 -0
- package/src/i18n/client.tsx +47 -0
- package/src/i18n/en.ts +228 -0
- package/src/i18n/fr.ts +251 -0
- package/src/i18n/index.ts +38 -0
- package/src/i18n/server.ts +19 -0
- package/tsconfig.json +21 -0
package/src/app.meta.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import pkg from '../package.json';
|
|
2
|
+
import type { MessageKey } from '@/i18n';
|
|
3
|
+
|
|
4
|
+
/** Identité de l'application, tirée de package.json (title, description, version) */
|
|
5
|
+
export const APP = {
|
|
6
|
+
name: (pkg as { title?: string }).title || pkg.name,
|
|
7
|
+
description: (pkg as { description?: string }).description ?? '',
|
|
8
|
+
version: pkg.version,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Entrée du menu du rail. Une entrée de premier niveau sans lien et avec des
|
|
13
|
+
* enfants est un intitulé de groupe ; une entrée avec lien et enfants est un
|
|
14
|
+
* parent dépliable. label : clé du catalogue (src/i18n/fr.ts).
|
|
15
|
+
*/
|
|
16
|
+
export interface AppMenuItem {
|
|
17
|
+
label: MessageKey;
|
|
18
|
+
icon?: string;
|
|
19
|
+
href?: string;
|
|
20
|
+
/** Lien externe (nouvel onglet) */
|
|
21
|
+
url?: string;
|
|
22
|
+
badge?: string | number;
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
visible?: boolean;
|
|
25
|
+
items?: AppMenuItem[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Menu de l'application */
|
|
29
|
+
export const MENU: AppMenuItem[] = [
|
|
30
|
+
{
|
|
31
|
+
label: 'menu.general',
|
|
32
|
+
items: [
|
|
33
|
+
{ label: 'menu.dashboard', icon: 'layout-dashboard', href: '/app' },
|
|
34
|
+
{ label: 'menu.public', icon: 'globe', href: '/app/public' },
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
label: 'menu.account',
|
|
39
|
+
items: [{ label: 'menu.myAccount', icon: 'user', href: '/app/account' }],
|
|
40
|
+
},
|
|
41
|
+
];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { APP } from '@/app.meta';
|
|
2
|
+
|
|
3
|
+
/** Logo + nom de l'application (public/logo.svg, title de package.json) */
|
|
4
|
+
export function Brand({ size = 32, version = false, className }: { size?: number; version?: boolean; className?: string }) {
|
|
5
|
+
return (
|
|
6
|
+
<span className={className ? `brand ${className}` : 'brand'}>
|
|
7
|
+
{/* eslint-disable-next-line @next/next/no-img-element */}
|
|
8
|
+
<img className="brand-logo" src="/logo.svg" alt="" width={size} height={size} />
|
|
9
|
+
<span className="brand-txt">
|
|
10
|
+
<span className="brand-title">{APP.name}</span>
|
|
11
|
+
{version && <span className="brand-ver">{APP.version}</span>}
|
|
12
|
+
</span>
|
|
13
|
+
</span>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef } from 'react';
|
|
3
|
+
|
|
4
|
+
type Provider = 'hcaptcha' | 'turnstile';
|
|
5
|
+
|
|
6
|
+
interface WidgetApi {
|
|
7
|
+
render(el: HTMLElement, options: Record<string, unknown>): string;
|
|
8
|
+
reset(id?: string): void;
|
|
9
|
+
remove?(id: string): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const SCRIPTS: Record<Provider, { src: string; global: string }> = {
|
|
13
|
+
turnstile: { src: 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit', global: 'turnstile' },
|
|
14
|
+
hcaptcha: { src: 'https://js.hcaptcha.com/1/api.js?render=explicit', global: 'hcaptcha' },
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const loading = new Map<Provider, Promise<WidgetApi>>();
|
|
18
|
+
|
|
19
|
+
/** Charge une seule fois le script du fournisseur */
|
|
20
|
+
function load(provider: Provider): Promise<WidgetApi> {
|
|
21
|
+
let p = loading.get(provider);
|
|
22
|
+
if (!p) {
|
|
23
|
+
const { src, global } = SCRIPTS[provider];
|
|
24
|
+
p = new Promise<WidgetApi>((resolve, reject) => {
|
|
25
|
+
const existing = (window as unknown as Record<string, WidgetApi | undefined>)[global];
|
|
26
|
+
if (existing) return resolve(existing);
|
|
27
|
+
const script = document.createElement('script');
|
|
28
|
+
script.src = src;
|
|
29
|
+
script.async = true;
|
|
30
|
+
script.onload = () => {
|
|
31
|
+
const api = (window as unknown as Record<string, WidgetApi | undefined>)[global];
|
|
32
|
+
if (api) resolve(api);
|
|
33
|
+
else reject(new Error(`${provider} unavailable`));
|
|
34
|
+
};
|
|
35
|
+
script.onerror = () => {
|
|
36
|
+
loading.delete(provider);
|
|
37
|
+
reject(new Error(`${provider} could not be loaded`));
|
|
38
|
+
};
|
|
39
|
+
document.head.appendChild(script);
|
|
40
|
+
});
|
|
41
|
+
loading.set(provider, p);
|
|
42
|
+
}
|
|
43
|
+
return p;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface CaptchaHandle {
|
|
47
|
+
/** Un jeton ne sert qu'une fois : à appeler après chaque envoi */
|
|
48
|
+
reset(): void;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Widget CAPTCHA (Turnstile ou hCaptcha) exigé par le projet (/settings) :
|
|
53
|
+
* onToken reçoit le jeton à passer en captchaToken.
|
|
54
|
+
*/
|
|
55
|
+
export const Captcha = forwardRef<CaptchaHandle, { provider: Provider; siteKey: string; onToken(token: string | null): void }>(
|
|
56
|
+
function Captcha({ provider, siteKey, onToken }, ref) {
|
|
57
|
+
const host = useRef<HTMLDivElement>(null);
|
|
58
|
+
const widget = useRef<{ api: WidgetApi; id: string } | null>(null);
|
|
59
|
+
const cb = useRef(onToken);
|
|
60
|
+
cb.current = onToken;
|
|
61
|
+
|
|
62
|
+
useImperativeHandle(ref, () => ({
|
|
63
|
+
reset() {
|
|
64
|
+
cb.current(null);
|
|
65
|
+
if (widget.current) widget.current.api.reset(widget.current.id);
|
|
66
|
+
},
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
let alive = true;
|
|
71
|
+
void load(provider).then((api) => {
|
|
72
|
+
const el = host.current;
|
|
73
|
+
if (!alive || !el) return;
|
|
74
|
+
el.innerHTML = '';
|
|
75
|
+
const id = api.render(el, {
|
|
76
|
+
sitekey: siteKey,
|
|
77
|
+
callback: (t: string) => cb.current(t),
|
|
78
|
+
'expired-callback': () => cb.current(null),
|
|
79
|
+
'error-callback': () => cb.current(null),
|
|
80
|
+
});
|
|
81
|
+
widget.current = { api, id };
|
|
82
|
+
});
|
|
83
|
+
return () => {
|
|
84
|
+
alive = false;
|
|
85
|
+
const w = widget.current;
|
|
86
|
+
if (w?.api.remove) w.api.remove(w.id);
|
|
87
|
+
widget.current = null;
|
|
88
|
+
};
|
|
89
|
+
}, [provider, siteKey]);
|
|
90
|
+
|
|
91
|
+
return <div ref={host} style={{ minHeight: 65 }} />;
|
|
92
|
+
},
|
|
93
|
+
);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import Link from 'next/link';
|
|
2
|
+
import type { ComponentProps } from 'react';
|
|
3
|
+
import { buttonClasses, type ButtonOptions } from '@poadio/ui-core';
|
|
4
|
+
|
|
5
|
+
/** Lien à l'allure de PoadButton (mêmes classes : buttonClasses de @poadio/ui-core) */
|
|
6
|
+
export function LinkButton({ severity, variant, size, block, className, ...rest }: ComponentProps<typeof Link> & ButtonOptions) {
|
|
7
|
+
const classes = buttonClasses({ severity, variant, size, block });
|
|
8
|
+
return <Link {...rest} className={className ? `${classes} ${className}` : classes} />;
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Fragment } from 'react';
|
|
2
|
+
|
|
3
|
+
/** Noms techniques d'un texte traduit (variables, fichiers, commandes) mis en <code> */
|
|
4
|
+
const TECH =
|
|
5
|
+
/(POAD_[A-Z_]+|[\w./[\]-]+\.(?:toml|local|example|tsx|ts|json|svg)\b|poad (?:init|start|run kc)|bun start|<SignedIn>|@poadio\/ui-react|user_metadata\.\w+|secure_password_change|\/app\/hello\/:name|src\/app\b)/g;
|
|
6
|
+
|
|
7
|
+
export function Rich({ text }: { text: string }) {
|
|
8
|
+
const parts = text.split(TECH);
|
|
9
|
+
return (
|
|
10
|
+
<>
|
|
11
|
+
{parts.map((p, i) => (i % 2 ? <code key={i}>{p}</code> : <Fragment key={i}>{p}</Fragment>))}
|
|
12
|
+
</>
|
|
13
|
+
);
|
|
14
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import Link from 'next/link';
|
|
4
|
+
import { usePathname } from 'next/navigation';
|
|
5
|
+
import { PoadIcon } from '@poadio/ui-react';
|
|
6
|
+
import { MENU, type AppMenuItem } from '@/app.meta';
|
|
7
|
+
import { useT } from '@/i18n/client';
|
|
8
|
+
import type { Translate } from '@/i18n';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Menu du rail.
|
|
12
|
+
*
|
|
13
|
+
* Une entrée de premier niveau SANS lien et AVEC des enfants est un intitulé de
|
|
14
|
+
* groupe : c'est ce qui donne au rail sa hiérarchie sans encadré ni séparateur.
|
|
15
|
+
*
|
|
16
|
+
* Le filtre de recherche traverse toute la profondeur : une entrée est conservée
|
|
17
|
+
* si elle correspond, ou si l'un de ses enfants correspond.
|
|
18
|
+
*/
|
|
19
|
+
export function AppMenu({ filterText }: { filterText: string }) {
|
|
20
|
+
const t = useT();
|
|
21
|
+
const q = filterText.trim().toLowerCase();
|
|
22
|
+
const shown = MENU.filter((i) => i.visible !== false);
|
|
23
|
+
const visible = q ? shown.map((i) => keep(i, q, t)).filter((i): i is AppMenuItem => i !== null) : shown;
|
|
24
|
+
const isGroup = (e: AppMenuItem) => !e.href && !e.url && !!e.items?.length;
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<nav className="layout-menu-host" aria-label={t('shell.nav')}>
|
|
28
|
+
<ul className="layout-menu">
|
|
29
|
+
{visible.map((entry) =>
|
|
30
|
+
isGroup(entry) ? (
|
|
31
|
+
<GroupEntries key={entry.label} entry={entry} />
|
|
32
|
+
) : (
|
|
33
|
+
<li key={entry.label} style={{ display: 'block' }}>
|
|
34
|
+
<MenuItem item={entry} />
|
|
35
|
+
</li>
|
|
36
|
+
),
|
|
37
|
+
)}
|
|
38
|
+
{!visible.length && <li className="menu-empty">{t('menu.empty')}</li>}
|
|
39
|
+
</ul>
|
|
40
|
+
</nav>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function GroupEntries({ entry }: { entry: AppMenuItem }) {
|
|
45
|
+
const t = useT();
|
|
46
|
+
return (
|
|
47
|
+
<>
|
|
48
|
+
<li className="menu-group-label">{t(entry.label)}</li>
|
|
49
|
+
{(entry.items ?? []).map((child) => (
|
|
50
|
+
<li key={child.label} style={{ display: 'block' }}>
|
|
51
|
+
<MenuItem item={child} />
|
|
52
|
+
</li>
|
|
53
|
+
))}
|
|
54
|
+
</>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Une entrée : un lien, ou un parent dépliable dont les enfants s'affichent en
|
|
60
|
+
* puces indentées. Les liens de premier niveau (« / », « /app ») se comparent
|
|
61
|
+
* en exact : sinon « /app » resterait actif sur toutes les pages.
|
|
62
|
+
*/
|
|
63
|
+
function MenuItem({ item }: { item: AppMenuItem }) {
|
|
64
|
+
const t = useT();
|
|
65
|
+
const pathname = usePathname();
|
|
66
|
+
// Déplié par défaut : un sous-menu replié cacherait la page courante
|
|
67
|
+
const [open, setOpen] = useState(true);
|
|
68
|
+
const children = (item.items ?? []).filter((c) => c.visible !== false);
|
|
69
|
+
const active = (href?: string) => {
|
|
70
|
+
if (!href) return false;
|
|
71
|
+
const exact = href.split('/').filter(Boolean).length <= 1;
|
|
72
|
+
return exact ? pathname === href : pathname === href || pathname.startsWith(`${href}/`);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
if (children.length) {
|
|
76
|
+
return (
|
|
77
|
+
<>
|
|
78
|
+
<button type="button" className="menu-item" aria-expanded={open} disabled={item.disabled} onClick={() => setOpen(!open)}>
|
|
79
|
+
{item.icon && <PoadIcon name={item.icon} size={15} />}
|
|
80
|
+
<span className="menu-label">{t(item.label)}</span>
|
|
81
|
+
<PoadIcon className="menu-caret" name={open ? 'chevron-down' : 'chevron-right'} size={13} />
|
|
82
|
+
</button>
|
|
83
|
+
{open && (
|
|
84
|
+
<ul className="menu-submenu">
|
|
85
|
+
{children.map((child) => (
|
|
86
|
+
<li key={child.label}>
|
|
87
|
+
<Link className={active(child.href) ? 'menu-subitem is-active' : 'menu-subitem'} href={child.href ?? '#'}>
|
|
88
|
+
<span className="menu-dot" aria-hidden="true" />
|
|
89
|
+
<span className="menu-label">{t(child.label)}</span>
|
|
90
|
+
</Link>
|
|
91
|
+
</li>
|
|
92
|
+
))}
|
|
93
|
+
</ul>
|
|
94
|
+
)}
|
|
95
|
+
</>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const body = (
|
|
100
|
+
<>
|
|
101
|
+
{item.icon && <PoadIcon name={item.icon} size={15} />}
|
|
102
|
+
<span className="menu-label">{t(item.label)}</span>
|
|
103
|
+
{item.badge != null && <span className="menu-count">{item.badge}</span>}
|
|
104
|
+
</>
|
|
105
|
+
);
|
|
106
|
+
if (item.url) {
|
|
107
|
+
return (
|
|
108
|
+
<a className="menu-item" href={item.url} target="_blank" rel="noopener" title={t(item.label)}>
|
|
109
|
+
{body}
|
|
110
|
+
</a>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
return (
|
|
114
|
+
<Link className={active(item.href) ? 'menu-item is-active' : 'menu-item'} href={item.href ?? '#'} title={t(item.label)} aria-current={active(item.href) ? 'page' : undefined}>
|
|
115
|
+
{body}
|
|
116
|
+
</Link>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Conserve une entrée si elle correspond, ou si un descendant correspond (on ne garde alors que ceux-là) */
|
|
121
|
+
function keep(item: AppMenuItem, q: string, t: Translate): AppMenuItem | null {
|
|
122
|
+
const self = t(item.label).toLowerCase().includes(q);
|
|
123
|
+
const kids = (item.items ?? []).map((c) => keep(c, q, t)).filter((c): c is AppMenuItem => c !== null);
|
|
124
|
+
if (self) return item;
|
|
125
|
+
if (kids.length) return { ...item, items: kids };
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useMemo, useState, type KeyboardEvent, type PointerEvent, type ReactNode } from 'react';
|
|
3
|
+
import Link from 'next/link';
|
|
4
|
+
import { usePathname, useRouter } from 'next/navigation';
|
|
5
|
+
import { PoadIcon, PoadMenu, PoadTooltip, type PoadMenuItem } from '@poadio/ui-react';
|
|
6
|
+
import { APP } from '@/app.meta';
|
|
7
|
+
import { useAuth } from '@/core/auth';
|
|
8
|
+
import { useT } from '@/i18n/client';
|
|
9
|
+
import { AppMenu } from './app-menu';
|
|
10
|
+
import { TitleProvider, useCanvasTitle } from './page-title';
|
|
11
|
+
import { LocaleSwitch, ThemeSwitch } from './switches';
|
|
12
|
+
import { RAIL_MAX, RAIL_MIN, useRailLayout } from './use-layout';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Cadre de l'application, repris du starter Angular (layout du template Cadriciel).
|
|
16
|
+
*
|
|
17
|
+
* Un RAIL de navigation, une BARRE SUPÉRIEURE qui porte l'utilisateur, un
|
|
18
|
+
* CANEVAS flottant qui porte le contenu.
|
|
19
|
+
*
|
|
20
|
+
* Le rail obéit à un seul concept : sa visibilité.
|
|
21
|
+
* - verrouillé (cadenas fermé) : il occupe la mise en page, largeur ajustable ;
|
|
22
|
+
* - déverrouillé : il devient un tiroir, rappelé au survol du bord ou par le hamburger ;
|
|
23
|
+
* - fenêtre étroite : le tiroir s'impose, sans choix offert.
|
|
24
|
+
* ⌘B (Ctrl+B) range ou rappelle le rail.
|
|
25
|
+
*/
|
|
26
|
+
export function AppShell({ children }: { children: ReactNode }) {
|
|
27
|
+
return (
|
|
28
|
+
<TitleProvider>
|
|
29
|
+
<Shell>{children}</Shell>
|
|
30
|
+
</TitleProvider>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function Shell({ children }: { children: ReactNode }) {
|
|
35
|
+
const layout = useRailLayout();
|
|
36
|
+
const auth = useAuth();
|
|
37
|
+
const t = useT();
|
|
38
|
+
const router = useRouter();
|
|
39
|
+
const pathname = usePathname();
|
|
40
|
+
const [query, setQuery] = useState('');
|
|
41
|
+
const { closeDrawer, toggleFromKeyboard } = layout;
|
|
42
|
+
|
|
43
|
+
// Naviguer referme le tiroir
|
|
44
|
+
useEffect(() => closeDrawer(), [pathname, closeDrawer]);
|
|
45
|
+
|
|
46
|
+
// ⌘B / Ctrl+B : range ou rappelle le rail
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
const onKeydown = (e: globalThis.KeyboardEvent) => {
|
|
49
|
+
if (!(e.metaKey || e.ctrlKey) || e.key.toLowerCase() !== 'b') return;
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
toggleFromKeyboard();
|
|
52
|
+
};
|
|
53
|
+
window.addEventListener('keydown', onKeydown);
|
|
54
|
+
return () => window.removeEventListener('keydown', onKeydown);
|
|
55
|
+
}, [toggleFromKeyboard]);
|
|
56
|
+
|
|
57
|
+
const projectInitials = APP.description
|
|
58
|
+
.split(/\s+/)
|
|
59
|
+
.filter(Boolean)
|
|
60
|
+
.slice(0, 2)
|
|
61
|
+
.map((w) => w[0])
|
|
62
|
+
.join('')
|
|
63
|
+
.toUpperCase();
|
|
64
|
+
|
|
65
|
+
const parts = auth.displayName.split(/[\s@._-]+/).filter(Boolean);
|
|
66
|
+
const initials = ((parts[0]?.[0] ?? '?') + (parts[1]?.[0] ?? '')).toUpperCase();
|
|
67
|
+
const user = auth.user;
|
|
68
|
+
// Sous le nom : l'adresse (si le nom n'est pas déjà l'adresse), sinon « anonyme »
|
|
69
|
+
const subtitle = !user ? '' : user.is_anonymous ? t('common.anonymous') : user.email && user.email !== auth.displayName ? user.email : '';
|
|
70
|
+
const lockLabel = layout.locked ? t('shell.locked') : t('shell.unlocked');
|
|
71
|
+
|
|
72
|
+
const userItems = useMemo<PoadMenuItem[]>(
|
|
73
|
+
() => [
|
|
74
|
+
{ label: t('menu.myAccount'), icon: 'user', command: () => router.push('/app/account') },
|
|
75
|
+
{ separator: true },
|
|
76
|
+
{ label: t('common.signOut'), icon: 'log-out', command: () => auth.signOut() },
|
|
77
|
+
],
|
|
78
|
+
[t, router, auth],
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
/** Glissement de la poignée ; le seuil de 4 px ignore les micro-mouvements. */
|
|
82
|
+
const onHandleDown = (event: PointerEvent<HTMLDivElement>) => {
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
const startX = event.clientX;
|
|
85
|
+
const target = event.currentTarget;
|
|
86
|
+
target.setPointerCapture?.(event.pointerId);
|
|
87
|
+
let moved = false;
|
|
88
|
+
const move = (e: globalThis.PointerEvent) => {
|
|
89
|
+
if (!moved && Math.abs(e.clientX - startX) < 4) return;
|
|
90
|
+
if (!moved) {
|
|
91
|
+
moved = true;
|
|
92
|
+
layout.setResizing(true);
|
|
93
|
+
}
|
|
94
|
+
layout.resizeTo(e.clientX);
|
|
95
|
+
};
|
|
96
|
+
const up = () => {
|
|
97
|
+
target.removeEventListener('pointermove', move);
|
|
98
|
+
target.removeEventListener('pointerup', up);
|
|
99
|
+
target.removeEventListener('pointercancel', up);
|
|
100
|
+
layout.setResizing(false);
|
|
101
|
+
};
|
|
102
|
+
target.addEventListener('pointermove', move);
|
|
103
|
+
target.addEventListener('pointerup', up);
|
|
104
|
+
target.addEventListener('pointercancel', up);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/** La poignée est atteignable au clavier : les flèches ajustent la largeur. */
|
|
108
|
+
const onHandleKey = (event: KeyboardEvent<HTMLDivElement>) => {
|
|
109
|
+
const step = event.shiftKey ? 32 : 8;
|
|
110
|
+
if (event.key === 'ArrowLeft') {
|
|
111
|
+
event.preventDefault();
|
|
112
|
+
layout.resizeTo(layout.railWidth - step);
|
|
113
|
+
} else if (event.key === 'ArrowRight') {
|
|
114
|
+
event.preventDefault();
|
|
115
|
+
layout.resizeTo(layout.railWidth + step);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const classes = [
|
|
120
|
+
'layout-container',
|
|
121
|
+
layout.loaded && 'is-ready',
|
|
122
|
+
!layout.railInFlow && 'rail-drawer',
|
|
123
|
+
layout.drawerOpen && 'drawer-open',
|
|
124
|
+
layout.narrow && 'is-narrow',
|
|
125
|
+
layout.resizing && 'is-resizing',
|
|
126
|
+
]
|
|
127
|
+
.filter(Boolean)
|
|
128
|
+
.join(' ');
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<div className={classes} style={{ '--lay-rail': `${layout.railWidth}px` } as React.CSSProperties}>
|
|
132
|
+
{/* Bande sensible du bord : rappelle le tiroir au survol. */}
|
|
133
|
+
{!layout.railInFlow && <div className="rail-hot" onMouseEnter={() => layout.peek(true)} aria-hidden="true" />}
|
|
134
|
+
|
|
135
|
+
{layout.drawerOpen && <button type="button" className="layout-scrim" aria-label={t('shell.closeMenu')} onClick={layout.closeDrawer} />}
|
|
136
|
+
|
|
137
|
+
<aside className="layout-rail" onMouseEnter={layout.holdOpen} onMouseLeave={() => layout.peek(false)}>
|
|
138
|
+
<div className="rail-head">
|
|
139
|
+
<Link className="rail-brand" href="/" title={APP.name}>
|
|
140
|
+
<span className="brand-mark" aria-hidden="true">
|
|
141
|
+
{/* eslint-disable-next-line @next/next/no-img-element */}
|
|
142
|
+
<img src="/logo.svg" alt="" />
|
|
143
|
+
</span>
|
|
144
|
+
<span className="brand-name">{APP.name}</span>
|
|
145
|
+
</Link>
|
|
146
|
+
|
|
147
|
+
{!layout.railInFlow && (
|
|
148
|
+
<button type="button" className="rail-btn" aria-label={t('shell.stowMenu')} onClick={layout.closeDrawer}>
|
|
149
|
+
<PoadIcon name="x" size={15} />
|
|
150
|
+
</button>
|
|
151
|
+
)}
|
|
152
|
+
|
|
153
|
+
{!layout.narrow && (
|
|
154
|
+
<PoadTooltip content={lockLabel}>
|
|
155
|
+
<button type="button" className="rail-btn is-lock" aria-pressed={layout.locked} aria-label={lockLabel} onClick={layout.toggleLock}>
|
|
156
|
+
<PoadIcon name={layout.locked ? 'lock' : 'unlock'} size={15} />
|
|
157
|
+
</button>
|
|
158
|
+
</PoadTooltip>
|
|
159
|
+
)}
|
|
160
|
+
</div>
|
|
161
|
+
|
|
162
|
+
<label className="rail-search">
|
|
163
|
+
<PoadIcon name="search" size={14} />
|
|
164
|
+
<input type="search" placeholder={t('shell.search')} value={query} onChange={(e) => setQuery(e.target.value)} />
|
|
165
|
+
</label>
|
|
166
|
+
|
|
167
|
+
<AppMenu filterText={query} />
|
|
168
|
+
|
|
169
|
+
<div className="rail-foot">
|
|
170
|
+
<ThemeSwitch />
|
|
171
|
+
<LocaleSwitch />
|
|
172
|
+
<span className="rail-version">v{APP.version}</span>
|
|
173
|
+
</div>
|
|
174
|
+
|
|
175
|
+
{layout.railInFlow && (
|
|
176
|
+
<div
|
|
177
|
+
className={layout.resizing ? 'rail-handle is-active' : 'rail-handle'}
|
|
178
|
+
role="separator"
|
|
179
|
+
aria-orientation="vertical"
|
|
180
|
+
tabIndex={0}
|
|
181
|
+
aria-label={t('shell.resize')}
|
|
182
|
+
aria-valuenow={layout.railWidth}
|
|
183
|
+
aria-valuemin={RAIL_MIN}
|
|
184
|
+
aria-valuemax={RAIL_MAX}
|
|
185
|
+
onPointerDown={onHandleDown}
|
|
186
|
+
onDoubleClick={layout.resetWidth}
|
|
187
|
+
onKeyDown={onHandleKey}
|
|
188
|
+
/>
|
|
189
|
+
)}
|
|
190
|
+
</aside>
|
|
191
|
+
|
|
192
|
+
<div className="layout-main">
|
|
193
|
+
<header className="layout-topbar">
|
|
194
|
+
{!layout.railInFlow && (
|
|
195
|
+
<button type="button" className="topbar-btn" aria-label={t('shell.openMenu')} onClick={layout.toggleDrawer}>
|
|
196
|
+
<PoadIcon name="menu" size={17} />
|
|
197
|
+
</button>
|
|
198
|
+
)}
|
|
199
|
+
|
|
200
|
+
{APP.description && (
|
|
201
|
+
<>
|
|
202
|
+
<span className="project-mark" aria-hidden="true">
|
|
203
|
+
{projectInitials}
|
|
204
|
+
</span>
|
|
205
|
+
<span className="project-title">{APP.description}</span>
|
|
206
|
+
</>
|
|
207
|
+
)}
|
|
208
|
+
|
|
209
|
+
<span className="topbar-spacer" />
|
|
210
|
+
|
|
211
|
+
{user ? (
|
|
212
|
+
<PoadMenu
|
|
213
|
+
items={userItems}
|
|
214
|
+
minWidth={210}
|
|
215
|
+
aria-label={t('shell.userMenu')}
|
|
216
|
+
trigger={
|
|
217
|
+
<button type="button" className="topbar-user">
|
|
218
|
+
<span className="user-avatar">{initials}</span>
|
|
219
|
+
<span className="user-id">
|
|
220
|
+
<span className="user-name">{auth.displayName}</span>
|
|
221
|
+
{subtitle && <span className="user-sub">{subtitle}</span>}
|
|
222
|
+
</span>
|
|
223
|
+
<PoadIcon className="user-chevron" name="chevron-down" size={13} />
|
|
224
|
+
</button>
|
|
225
|
+
}
|
|
226
|
+
/>
|
|
227
|
+
) : (
|
|
228
|
+
auth.ready && (
|
|
229
|
+
<Link className="topbar-signin" href={`/login?next=${encodeURIComponent(pathname)}`}>
|
|
230
|
+
<PoadIcon name="log-in" size={15} /> {t('common.signIn')}
|
|
231
|
+
</Link>
|
|
232
|
+
)
|
|
233
|
+
)}
|
|
234
|
+
</header>
|
|
235
|
+
|
|
236
|
+
<main className="layout-canvas">
|
|
237
|
+
<CanvasHead />
|
|
238
|
+
<div className="canvas-body">{children}</div>
|
|
239
|
+
</main>
|
|
240
|
+
</div>
|
|
241
|
+
</div>
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* En-tête du canevas : titre posé par la page (<PageTitle>), sinon dérivé du
|
|
247
|
+
* dernier segment d'URL — une page reste titrée sans rien avoir à câbler.
|
|
248
|
+
*/
|
|
249
|
+
function CanvasHead() {
|
|
250
|
+
const title = useCanvasTitle();
|
|
251
|
+
const pathname = usePathname();
|
|
252
|
+
const t = useT();
|
|
253
|
+
return (
|
|
254
|
+
<header className="canvas-head">
|
|
255
|
+
<div style={{ minWidth: 0 }}>
|
|
256
|
+
<h1 className="canvas-title">{title || titleFromUrl(pathname, t('title.home'))}</h1>
|
|
257
|
+
</div>
|
|
258
|
+
<div className="canvas-actions" />
|
|
259
|
+
</header>
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function titleFromUrl(url: string, home: string): string {
|
|
264
|
+
const segment = url.split('/').filter(Boolean).pop();
|
|
265
|
+
if (!segment) return home;
|
|
266
|
+
const words = decodeURIComponent(segment).replace(/[-_]+/g, ' ').trim();
|
|
267
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
268
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { createContext, useContext, useEffect, useState, type ReactNode } from 'react';
|
|
3
|
+
import { useT } from '@/i18n/client';
|
|
4
|
+
import type { MessageKey } from '@/i18n';
|
|
5
|
+
|
|
6
|
+
/** Titre affiché en tête du canevas, posé par la page (<PageTitle>) */
|
|
7
|
+
const TitleContext = createContext<{ title: string; set(t: string): void }>({ title: '', set: () => {} });
|
|
8
|
+
|
|
9
|
+
export function TitleProvider({ children }: { children: ReactNode }) {
|
|
10
|
+
const [title, set] = useState('');
|
|
11
|
+
return <TitleContext.Provider value={{ title, set }}>{children}</TitleContext.Provider>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const useCanvasTitle = () => useContext(TitleContext).title;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Titre de la page dans l'en-tête du canevas : <PageTitle k="title.account" />.
|
|
18
|
+
* Le titre de l'onglet, lui, vient de generateMetadata (titled() dans src/i18n/server.ts).
|
|
19
|
+
*/
|
|
20
|
+
export function PageTitle({ k, text }: { k?: MessageKey; text?: string }) {
|
|
21
|
+
const t = useT();
|
|
22
|
+
const { set } = useContext(TitleContext);
|
|
23
|
+
const value = text ?? (k ? t(k) : '');
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
set(value);
|
|
26
|
+
return () => set('');
|
|
27
|
+
}, [value, set]);
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { PoadIcon } from '@poadio/ui-react';
|
|
3
|
+
import { useTheme } from '@/core/theme';
|
|
4
|
+
import { useI18n } from '@/i18n/client';
|
|
5
|
+
import { LOCALES } from '@/i18n';
|
|
6
|
+
|
|
7
|
+
/** Bascule clair / sombre */
|
|
8
|
+
export function ThemeSwitch() {
|
|
9
|
+
const theme = useTheme();
|
|
10
|
+
const { t } = useI18n();
|
|
11
|
+
return (
|
|
12
|
+
<div className="theme-switch" role="group" aria-label={t('common.theme')}>
|
|
13
|
+
<button type="button" className={theme.dark ? '' : 'is-on'} aria-label={t('common.themeLight')} aria-pressed={!theme.dark} onClick={() => theme.set(false)}>
|
|
14
|
+
<PoadIcon name="sun" size={14} />
|
|
15
|
+
</button>
|
|
16
|
+
<button type="button" className={theme.dark ? 'is-on' : ''} aria-label={t('common.themeDark')} aria-pressed={theme.dark} onClick={() => theme.set(true)}>
|
|
17
|
+
<PoadIcon name="moon" size={14} />
|
|
18
|
+
</button>
|
|
19
|
+
</div>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Choix de la langue (cookie app.locale, relu par le serveur) */
|
|
24
|
+
export function LocaleSwitch() {
|
|
25
|
+
const { locale, setLocale, t } = useI18n();
|
|
26
|
+
return (
|
|
27
|
+
<div className="theme-switch locale-switch" role="group" aria-label={t('common.language')}>
|
|
28
|
+
{LOCALES.map((l) => (
|
|
29
|
+
<button key={l} type="button" lang={l} className={l === locale ? 'is-on' : ''} aria-pressed={l === locale} onClick={() => setLocale(l)}>
|
|
30
|
+
{l.toUpperCase()}
|
|
31
|
+
</button>
|
|
32
|
+
))}
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
}
|