@eifi1/ui-kit 0.29.0 → 0.31.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/README.md +65 -6
- package/dist/account/account-parts.d.ts +21 -0
- package/dist/account/account-parts.js +40 -0
- package/dist/account/account-parts.js.map +1 -0
- package/dist/account/data-export-setting.d.ts +73 -0
- package/dist/account/data-export-setting.js +114 -0
- package/dist/account/data-export-setting.js.map +1 -0
- package/dist/account/delete-account-setting.d.ts +95 -0
- package/dist/account/delete-account-setting.js +200 -0
- package/dist/account/delete-account-setting.js.map +1 -0
- package/dist/account/email-change-setting.d.ts +136 -0
- package/dist/account/email-change-setting.js +278 -0
- package/dist/account/email-change-setting.js.map +1 -0
- package/dist/account/sessions-setting.d.ts +110 -0
- package/dist/account/sessions-setting.js +147 -0
- package/dist/account/sessions-setting.js.map +1 -0
- package/dist/admin/admin-action-confirm.d.ts +95 -0
- package/dist/admin/admin-action-confirm.js +276 -0
- package/dist/admin/admin-action-confirm.js.map +1 -0
- package/dist/admin/admin-action-log.d.ts +105 -0
- package/dist/admin/admin-action-log.js +153 -0
- package/dist/admin/admin-action-log.js.map +1 -0
- package/dist/admin/admin-parts.d.ts +40 -0
- package/dist/admin/admin-parts.js +45 -0
- package/dist/admin/admin-parts.js.map +1 -0
- package/dist/admin/invitations-panel.d.ts +95 -0
- package/dist/admin/invitations-panel.js +290 -0
- package/dist/admin/invitations-panel.js.map +1 -0
- package/dist/admin/reviewer-scope-editor.d.ts +95 -0
- package/dist/admin/reviewer-scope-editor.js +134 -0
- package/dist/admin/reviewer-scope-editor.js.map +1 -0
- package/dist/admin/role-select.d.ts +95 -0
- package/dist/admin/role-select.js +128 -0
- package/dist/admin/role-select.js.map +1 -0
- package/dist/admin/transfer-ownership-dialog.d.ts +95 -0
- package/dist/admin/transfer-ownership-dialog.js +83 -0
- package/dist/admin/transfer-ownership-dialog.js.map +1 -0
- package/dist/admin/user-roster.d.ts +95 -0
- package/dist/admin/user-roster.js +285 -0
- package/dist/admin/user-roster.js.map +1 -0
- package/dist/auth/auth-errors.d.ts +103 -6
- package/dist/auth/auth-errors.js +68 -2
- package/dist/auth/auth-errors.js.map +1 -1
- package/dist/auth/forgot-password-form.d.ts +10 -3
- package/dist/auth/forgot-password-form.js +6 -3
- package/dist/auth/forgot-password-form.js.map +1 -1
- package/dist/auth/register-form.d.ts +21 -12
- package/dist/auth/register-form.js +6 -4
- package/dist/auth/register-form.js.map +1 -1
- package/dist/auth/reset-password-form.d.ts +10 -3
- package/dist/auth/reset-password-form.js +6 -3
- package/dist/auth/reset-password-form.js.map +1 -1
- package/dist/auth/sign-in-form.d.ts +75 -9
- package/dist/auth/sign-in-form.js +105 -15
- package/dist/auth/sign-in-form.js.map +1 -1
- package/dist/auth/verify-email.d.ts +7 -2
- package/dist/auth/verify-email.js +44 -8
- package/dist/auth/verify-email.js.map +1 -1
- package/dist/chart.d.ts +20 -11
- package/dist/components/account-chips.d.ts +47 -7
- package/dist/components/account-chips.js +19 -3
- package/dist/components/account-chips.js.map +1 -1
- package/dist/components/account-settings-labels.d.ts +24 -1
- package/dist/components/account-settings-labels.js +6 -2
- package/dist/components/account-settings-labels.js.map +1 -1
- package/dist/components/account-settings.d.ts +69 -8
- package/dist/components/account-settings.js +133 -25
- package/dist/components/account-settings.js.map +1 -1
- package/dist/components/amount-input.d.ts +21 -12
- package/dist/components/button-group.d.ts +21 -12
- package/dist/components/calculator.d.ts +21 -12
- package/dist/components/confirm-dialog.d.ts +21 -12
- package/dist/components/copy-button.d.ts +18 -9
- package/dist/components/danger-confirm.d.ts +21 -12
- package/dist/components/data-table.js +8 -1
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/date-picker.js +9 -4
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/facing-pair.d.ts +21 -12
- package/dist/components/file-button.d.ts +21 -12
- package/dist/components/file-dropzone.d.ts +21 -12
- package/dist/components/form-actions.d.ts +21 -12
- package/dist/components/iban-input.d.ts +21 -12
- package/dist/components/language-select.d.ts +21 -12
- package/dist/components/legal-page.d.ts +21 -12
- package/dist/components/legal.d.ts +21 -12
- package/dist/components/money-field.d.ts +21 -12
- package/dist/components/number-field.d.ts +21 -12
- package/dist/components/number-input.d.ts +21 -12
- package/dist/components/numpad-sheet.d.ts +21 -12
- package/dist/components/passkeys-setting.js +2 -1
- package/dist/components/passkeys-setting.js.map +1 -1
- package/dist/components/phone-input.d.ts +21 -12
- package/dist/components/series-chart.d.ts +21 -12
- package/dist/components/settings-fields.d.ts +55 -13
- package/dist/components/settings-fields.js +20 -1
- package/dist/components/settings-fields.js.map +1 -1
- package/dist/components/share-card.d.ts +20 -11
- package/dist/components/text-link.d.ts +21 -12
- package/dist/components/time-input.d.ts +21 -12
- package/dist/components/ui.d.ts +17 -8
- package/dist/{register-form-V1OeNlMr.d.ts → delete-account-setting-DCFS5Vof.d.ts} +6612 -5612
- package/dist/demo/demo-banner.d.ts +51 -0
- package/dist/demo/demo-banner.js +97 -0
- package/dist/demo/demo-banner.js.map +1 -0
- package/dist/demo/demo-countdown.d.ts +58 -0
- package/dist/demo/demo-countdown.js +79 -0
- package/dist/demo/demo-countdown.js.map +1 -0
- package/dist/demo/demo-ended.d.ts +45 -0
- package/dist/demo/demo-ended.js +42 -0
- package/dist/demo/demo-ended.js.map +1 -0
- package/dist/demo/demo-labels.d.ts +53 -0
- package/dist/demo/demo-labels.js +29 -0
- package/dist/demo/demo-labels.js.map +1 -0
- package/dist/demo/demo-session.d.ts +30 -0
- package/dist/demo/demo-session.js +8 -0
- package/dist/demo/demo-session.js.map +1 -0
- package/dist/demo/demo-start.d.ts +54 -0
- package/dist/demo/demo-start.js +68 -0
- package/dist/demo/demo-start.js.map +1 -0
- package/dist/feedback/feedback-attachment.d.ts +21 -12
- package/dist/feedback/feedback-context.d.ts +21 -12
- package/dist/feedback/feedback-crash.d.ts +21 -12
- package/dist/feedback/feedback-dialog.d.ts +21 -12
- package/dist/feedback/feedback-inbox.d.ts +21 -12
- package/dist/feedback/feedback-inbox.js +12 -2
- package/dist/feedback/feedback-inbox.js.map +1 -1
- package/dist/feedback/feedback-labels.d.ts +21 -12
- package/dist/feedback/feedback-labels.js +1 -0
- package/dist/feedback/feedback-labels.js.map +1 -1
- package/dist/feedback/feedback-menu.d.ts +21 -12
- package/dist/feedback/feedback-record.d.ts +21 -12
- package/dist/feedback/feedback-record.js +2 -0
- package/dist/feedback/feedback-record.js.map +1 -1
- package/dist/feedback/feedback-row-detail.d.ts +21 -12
- package/dist/feedback/feedback-row-detail.js +7 -0
- package/dist/feedback/feedback-row-detail.js.map +1 -1
- package/dist/feedback/feedback-status-undo.d.ts +21 -12
- package/dist/feedback/feedback-submit.d.ts +21 -12
- package/dist/feedback/feedback-swipe.d.ts +22 -13
- package/dist/feedback/feedback-swipe.js.map +1 -1
- package/dist/feedback/feedback-table.d.ts +18 -9
- package/dist/feedback/feedback-thread.d.ts +21 -12
- package/dist/feedback.d.ts +21 -12
- package/dist/hooks/use-anchored-panel.d.ts +6 -2
- package/dist/hooks/use-anchored-panel.js +2 -1
- package/dist/hooks/use-anchored-panel.js.map +1 -1
- package/dist/hooks/use-file-drop.d.ts +21 -12
- package/dist/i18n/defaults.d.ts +21 -12
- package/dist/i18n/defaults.js +28 -0
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/german.d.ts +21 -12
- package/dist/i18n/german.js +298 -12
- package/dist/i18n/german.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +14 -5
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/languages.d.ts +15 -6
- package/dist/i18n/locales/de-CH.d.ts +21 -12
- package/dist/i18n/locales/en.d.ts +21 -12
- package/dist/i18n/locales/es.d.ts +21 -12
- package/dist/i18n/locales/es.js +287 -10
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.d.ts +21 -12
- package/dist/i18n/locales/fr.js +290 -7
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.d.ts +21 -12
- package/dist/i18n/locales/hu.js +288 -12
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.d.ts +21 -12
- package/dist/i18n/locales/it.js +289 -7
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.d.ts +21 -12
- package/dist/i18n/locales/zh.js +279 -7
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/review.d.ts +21 -12
- package/dist/i18n/review.js +50 -1
- package/dist/i18n/review.js.map +1 -1
- package/dist/index.d.ts +31 -4
- package/dist/index.js +148 -0
- package/dist/index.js.map +1 -1
- package/dist/landing/access.d.ts +48 -0
- package/dist/landing/access.js +38 -0
- package/dist/landing/access.js.map +1 -0
- package/dist/landing/landing-actions.d.ts +138 -0
- package/dist/landing/landing-actions.js +39 -0
- package/dist/landing/landing-actions.js.map +1 -0
- package/dist/landing/landing-labels.d.ts +43 -0
- package/dist/landing/landing-labels.js +23 -0
- package/dist/landing/landing-labels.js.map +1 -0
- package/dist/landing/landing-sections.d.ts +218 -0
- package/dist/landing/landing-sections.js +167 -0
- package/dist/landing/landing-sections.js.map +1 -0
- package/dist/landing/page-seo.d.ts +99 -0
- package/dist/landing/page-seo.js +121 -0
- package/dist/landing/page-seo.js.map +1 -0
- package/dist/landing/public-header.d.ts +148 -0
- package/dist/landing/public-header.js +49 -0
- package/dist/landing/public-header.js.map +1 -0
- package/dist/landing/routing.d.ts +218 -0
- package/dist/landing/routing.js +81 -0
- package/dist/landing/routing.js.map +1 -0
- package/dist/rhf/fields.d.ts +21 -12
- package/dist/rhf/form.d.ts +21 -12
- package/dist/rhf.d.ts +21 -12
- package/dist/settings/settings-catalogue.d.ts +84 -0
- package/dist/settings/settings-catalogue.js +47 -0
- package/dist/settings/settings-catalogue.js.map +1 -0
- package/dist/settings/settings-context.d.ts +31 -0
- package/dist/settings/settings-context.js +11 -0
- package/dist/settings/settings-context.js.map +1 -0
- package/dist/settings/settings-heading.d.ts +50 -0
- package/dist/settings/settings-heading.js +27 -0
- package/dist/settings/settings-heading.js.map +1 -0
- package/dist/settings/settings-labels.d.ts +41 -0
- package/dist/settings/settings-labels.js +38 -0
- package/dist/settings/settings-labels.js.map +1 -0
- package/dist/settings/settings-layout.d.ts +77 -0
- package/dist/settings/settings-layout.js +242 -0
- package/dist/settings/settings-layout.js.map +1 -0
- package/dist/settings/settings-section.d.ts +133 -0
- package/dist/settings/settings-section.js +63 -0
- package/dist/settings/settings-section.js.map +1 -0
- package/dist/settings/use-account-language.d.ts +83 -0
- package/dist/settings/use-account-language.js +62 -0
- package/dist/settings/use-account-language.js.map +1 -0
- package/dist/settings/use-settings-focus.d.ts +34 -0
- package/dist/settings/use-settings-focus.js +77 -0
- package/dist/settings/use-settings-focus.js.map +1 -0
- package/dist/settings/use-settings-route.d.ts +118 -0
- package/dist/settings/use-settings-route.js +120 -0
- package/dist/settings/use-settings-route.js.map +1 -0
- package/dist/shell/app-shell.d.ts +27 -12
- package/dist/shell/app-shell.js +3 -2
- package/dist/shell/app-shell.js.map +1 -1
- package/dist/shell/top-bar-brand.d.ts +21 -12
- package/dist/shell.d.ts +25 -6
- package/dist/shell.js +56 -0
- package/dist/shell.js.map +1 -1
- package/dist/wizard/stepper-nav.d.ts +21 -12
- package/dist/wizard.d.ts +21 -12
- package/package.json +2 -1
- package/src/account/account-parts.ts +67 -0
- package/src/account/data-export-setting.tsx +219 -0
- package/src/account/delete-account-setting.tsx +363 -0
- package/src/account/email-change-setting.tsx +454 -0
- package/src/account/sessions-setting.tsx +284 -0
- package/src/admin/admin-action-confirm.tsx +495 -0
- package/src/admin/admin-action-log.tsx +297 -0
- package/src/admin/admin-parts.ts +82 -0
- package/src/admin/invitations-panel.tsx +523 -0
- package/src/admin/reviewer-scope-editor.tsx +234 -0
- package/src/admin/role-select.tsx +286 -0
- package/src/admin/transfer-ownership-dialog.tsx +172 -0
- package/src/admin/user-roster.tsx +573 -0
- package/src/auth/auth-errors.ts +196 -8
- package/src/auth/forgot-password-form.tsx +21 -5
- package/src/auth/register-form.tsx +24 -6
- package/src/auth/reset-password-form.tsx +19 -5
- package/src/auth/sign-in-form.tsx +241 -38
- package/src/auth/verify-email.tsx +59 -8
- package/src/components/account-chips.tsx +64 -7
- package/src/components/account-settings-labels.ts +28 -1
- package/src/components/account-settings.tsx +231 -34
- package/src/components/data-table.tsx +8 -0
- package/src/components/date-picker.tsx +9 -4
- package/src/components/passkeys-setting.tsx +2 -1
- package/src/components/settings-fields.tsx +50 -1
- package/src/demo/demo-banner.tsx +159 -0
- package/src/demo/demo-countdown.ts +141 -0
- package/src/demo/demo-ended.tsx +89 -0
- package/src/demo/demo-labels.ts +78 -0
- package/src/demo/demo-session.ts +32 -0
- package/src/demo/demo-start.tsx +150 -0
- package/src/feedback/feedback-inbox.tsx +21 -8
- package/src/feedback/feedback-labels.ts +2 -1
- package/src/feedback/feedback-record.ts +10 -7
- package/src/feedback/feedback-row-detail.tsx +28 -4
- package/src/feedback/feedback-swipe.tsx +1 -1
- package/src/hooks/use-anchored-panel.ts +14 -3
- package/src/i18n/defaults.ts +28 -0
- package/src/i18n/german.ts +327 -5
- package/src/i18n/kit-labels.tsx +42 -0
- package/src/i18n/locales/es.ts +313 -3
- package/src/i18n/locales/fr.ts +316 -0
- package/src/i18n/locales/hu.ts +308 -5
- package/src/i18n/locales/it.ts +313 -0
- package/src/i18n/locales/zh.ts +286 -0
- package/src/i18n/review.ts +49 -0
- package/src/index.ts +184 -0
- package/src/landing/access.ts +97 -0
- package/src/landing/landing-actions.tsx +92 -0
- package/src/landing/landing-labels.ts +59 -0
- package/src/landing/landing-sections.tsx +337 -0
- package/src/landing/page-seo.ts +251 -0
- package/src/landing/public-header.tsx +120 -0
- package/src/landing/routing.tsx +209 -0
- package/src/settings/settings-catalogue.ts +132 -0
- package/src/settings/settings-context.ts +33 -0
- package/src/settings/settings-heading.tsx +65 -0
- package/src/settings/settings-labels.ts +75 -0
- package/src/settings/settings-layout.tsx +379 -0
- package/src/settings/settings-section.tsx +108 -0
- package/src/settings/use-account-language.ts +146 -0
- package/src/settings/use-settings-focus.ts +120 -0
- package/src/settings/use-settings-route.ts +258 -0
- package/src/shell/app-shell.tsx +10 -2
- package/src/shell.ts +45 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { useLocation, useNavigate } from "react-router";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The ring a `?focus=` target wears for {@link SETTINGS_FOCUS_MS} — keksdose's
|
|
6
|
+
* `HIGHLIGHT`, in tokens: `--brand` for the ring and the page's own surface for the gap,
|
|
7
|
+
* where keksdose named a slate for the dark theme. A ring rather than a background
|
|
8
|
+
* flash: the destructive cards already own a background tint, and a ring reads the same
|
|
9
|
+
* on every card.
|
|
10
|
+
*/
|
|
11
|
+
export const SETTINGS_FOCUS_RING = ["ring-2", "ring-[var(--brand)]", "ring-offset-2", "ring-offset-[var(--bg-page)]"];
|
|
12
|
+
|
|
13
|
+
/** How long the ring stays (§3.5). */
|
|
14
|
+
export const SETTINGS_FOCUS_MS = 1800;
|
|
15
|
+
|
|
16
|
+
/** How long a target that is not on the page yet (a lazy card, a card waiting for its
|
|
17
|
+
* data) is waited for before the hook gives up on it. */
|
|
18
|
+
const WAIT_MS = 5000;
|
|
19
|
+
|
|
20
|
+
const HEADING = "[data-settings-heading], h1, h2, h3, h4, h5, h6";
|
|
21
|
+
|
|
22
|
+
function prefersReducedMotion(): boolean {
|
|
23
|
+
return typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* `?focus=<anchor>` (docs/settings-harmonization.md §3.5): scroll the card into view, ring
|
|
28
|
+
* it for 1.8 s, move focus to its heading for a screen reader, then remove `focus` — and
|
|
29
|
+
* ONLY `focus` — with a replace, so a reload does not ring it again. Every other
|
|
30
|
+
* parameter stays: a tour's `tour` / `tourStep`, the admin roster's filters (dropping URL
|
|
31
|
+
* parts broke keksdose's tours once, dev#495). The hash and `location.state` stay too.
|
|
32
|
+
*
|
|
33
|
+
* A search hit, ⌘K, a tour and a mail link all arrive this way. `SettingsLayout` calls it
|
|
34
|
+
* for its own page; an app's own page can call it with no argument to act on its URL.
|
|
35
|
+
*
|
|
36
|
+
* `anchor`:
|
|
37
|
+
* - left out: the URL's `focus` parameter;
|
|
38
|
+
* - a string: that anchor (the layout passes the URL's, once its route is canonical);
|
|
39
|
+
* - `null`: nothing to do yet — the layout passes it while the address is about to be
|
|
40
|
+
* replaced, so a removal here cannot undo a redirect there.
|
|
41
|
+
*
|
|
42
|
+
* "Once its group has rendered": the effect runs after the commit that mounted the
|
|
43
|
+
* group's cards, so the card is there; a card that mounts later (lazy, or behind its
|
|
44
|
+
* data) is waited for, for a few seconds, before the hook gives up and leaves the URL
|
|
45
|
+
* as it is.
|
|
46
|
+
*/
|
|
47
|
+
export function useSettingsFocus(anchor?: string | null): void {
|
|
48
|
+
const location = useLocation();
|
|
49
|
+
const navigate = useNavigate();
|
|
50
|
+
const target = anchor === undefined ? new URLSearchParams(location.search).get("focus") : anchor;
|
|
51
|
+
// The ring outlives the effect that drew it: removing `focus` from the URL re-runs the
|
|
52
|
+
// effect (and cleans it up) at once, and the ring must still stay its 1.8 s.
|
|
53
|
+
const ring = useRef<{ el: HTMLElement; timer: number } | null>(null);
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (!target) return;
|
|
57
|
+
const { pathname, search, hash, state } = location;
|
|
58
|
+
|
|
59
|
+
const land = (el: HTMLElement) => {
|
|
60
|
+
el.scrollIntoView?.({ behavior: prefersReducedMotion() ? "auto" : "smooth", block: "center" });
|
|
61
|
+
|
|
62
|
+
if (ring.current) {
|
|
63
|
+
window.clearTimeout(ring.current.timer);
|
|
64
|
+
ring.current.el.classList.remove(...SETTINGS_FOCUS_RING);
|
|
65
|
+
}
|
|
66
|
+
el.classList.add(...SETTINGS_FOCUS_RING);
|
|
67
|
+
el.setAttribute("data-settings-focus", "");
|
|
68
|
+
const timer = window.setTimeout(() => {
|
|
69
|
+
el.classList.remove(...SETTINGS_FOCUS_RING);
|
|
70
|
+
el.removeAttribute("data-settings-focus");
|
|
71
|
+
if (ring.current?.el === el) ring.current = null;
|
|
72
|
+
}, SETTINGS_FOCUS_MS);
|
|
73
|
+
ring.current = { el, timer };
|
|
74
|
+
|
|
75
|
+
// The heading, so a screen reader starts at the card's name; the card itself when
|
|
76
|
+
// it has none. `preventScroll`: the smooth scroll above is already on its way.
|
|
77
|
+
const heading = el.querySelector<HTMLElement>(HEADING) ?? el;
|
|
78
|
+
if (!heading.hasAttribute("tabindex")) heading.setAttribute("tabindex", "-1");
|
|
79
|
+
heading.focus({ preventScroll: true });
|
|
80
|
+
|
|
81
|
+
const params = new URLSearchParams(search);
|
|
82
|
+
if (params.get("focus") !== target) return;
|
|
83
|
+
params.delete("focus");
|
|
84
|
+
const rest = params.toString();
|
|
85
|
+
navigate({ pathname, search: rest ? `?${rest}` : "", hash }, { replace: true, state });
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const found = document.getElementById(target);
|
|
89
|
+
if (found) {
|
|
90
|
+
land(found);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const observer = new MutationObserver(() => {
|
|
94
|
+
const el = document.getElementById(target);
|
|
95
|
+
if (!el) return;
|
|
96
|
+
observer.disconnect();
|
|
97
|
+
window.clearTimeout(giveUp);
|
|
98
|
+
land(el);
|
|
99
|
+
});
|
|
100
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
101
|
+
const giveUp = window.setTimeout(() => observer.disconnect(), WAIT_MS);
|
|
102
|
+
return () => {
|
|
103
|
+
observer.disconnect();
|
|
104
|
+
window.clearTimeout(giveUp);
|
|
105
|
+
};
|
|
106
|
+
// `location`, a new object per navigation: the same hit picked twice is two
|
|
107
|
+
// navigations, and rings twice.
|
|
108
|
+
}, [target, location, navigate]);
|
|
109
|
+
|
|
110
|
+
useEffect(
|
|
111
|
+
() => () => {
|
|
112
|
+
const current = ring.current;
|
|
113
|
+
if (!current) return;
|
|
114
|
+
window.clearTimeout(current.timer);
|
|
115
|
+
current.el.classList.remove(...SETTINGS_FOCUS_RING);
|
|
116
|
+
current.el.removeAttribute("data-settings-focus");
|
|
117
|
+
},
|
|
118
|
+
[],
|
|
119
|
+
);
|
|
120
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo } from "react";
|
|
2
|
+
import { useLocation, useNavigate } from "react-router";
|
|
3
|
+
import { useMediaQuery } from "../hooks/use-media-query";
|
|
4
|
+
import { PHONE_QUERY } from "../components/ui";
|
|
5
|
+
import { normalizeSettingsBase, visibleSettingsGroups } from "./settings-catalogue";
|
|
6
|
+
import type { SettingsEntry, SettingsGroup } from "./settings-catalogue";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Which layout the settings page is in. `"auto"` follows the screen ({@link PHONE_QUERY},
|
|
10
|
+
* as `Tabs` does); `"desktop"` / `"phone"` pin one — for a preview of both side by side,
|
|
11
|
+
* where the window is one width.
|
|
12
|
+
*/
|
|
13
|
+
export type SettingsLayoutMode = "auto" | "desktop" | "phone";
|
|
14
|
+
|
|
15
|
+
export interface UseSettingsRouteOptions<G extends string> {
|
|
16
|
+
groups: readonly SettingsGroup<G>[];
|
|
17
|
+
/** The catalogue's entries. Given, a group with no visible entry is hidden (§4.1), and
|
|
18
|
+
* `/settings?focus=<anchor>` finds the anchor's group. */
|
|
19
|
+
entries?: readonly SettingsEntry<G>[];
|
|
20
|
+
/** `/settings` or `/admin`. */
|
|
21
|
+
basePath: string;
|
|
22
|
+
/** The group `/settings` opens on a desktop. Default: the first visible group (§4.1). */
|
|
23
|
+
defaultGroup?: G;
|
|
24
|
+
/** Retired group ids and their successors — `{ overview: "metrics" }` — applied with a
|
|
25
|
+
* replace (§3.1, keksdose's admin). */
|
|
26
|
+
aliases?: Readonly<Partial<Record<string, G>>>;
|
|
27
|
+
/** See {@link SettingsLayoutMode}. Default `"auto"`. */
|
|
28
|
+
layout?: SettingsLayoutMode;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface SettingsRoute<G extends string> {
|
|
32
|
+
/** The group on screen. `null` on a phone's list (and while there is no visible group). */
|
|
33
|
+
group: G | null;
|
|
34
|
+
/** The segment after the group, owned by a card; `null` without one. */
|
|
35
|
+
sub: string | null;
|
|
36
|
+
/** `?focus=<anchor>`, or `null`. */
|
|
37
|
+
focus: string | null;
|
|
38
|
+
/** Open a group: a PUSH on a phone, so the system back gesture returns to the list; a
|
|
39
|
+
* REPLACE on a desktop, so back leaves settings instead of walking every group looked
|
|
40
|
+
* at (§3.1, keksdose's rule). */
|
|
41
|
+
select: (group: G) => void;
|
|
42
|
+
/** See {@link SettingsLayoutContextValue.selectSub}. */
|
|
43
|
+
selectSub: (sub: string | null) => void;
|
|
44
|
+
/** To the list: `navigate(-1)` when the list is the previous entry, else a replace to
|
|
45
|
+
* the base path — so a deep link from a mail never sends "back" out of the app. */
|
|
46
|
+
back: () => void;
|
|
47
|
+
/** The visible groups, in order. */
|
|
48
|
+
groups: SettingsGroup<G>[];
|
|
49
|
+
/** Whether the phone layout is in force. */
|
|
50
|
+
phone: boolean;
|
|
51
|
+
/** Whether this location is about to be replaced (a legacy hash, an alias, an unknown
|
|
52
|
+
* group): what renders meanwhile is already the destination's, but nothing should
|
|
53
|
+
* act on the URL until it is. */
|
|
54
|
+
redirecting: boolean;
|
|
55
|
+
/** Whether the list is the entry before this one (the marker {@link select} and the
|
|
56
|
+
* list's links leave in `location.state`). */
|
|
57
|
+
fromList: boolean;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The `location.state` key that says "the list is the entry before this one". Written by
|
|
62
|
+
* the phone list's links and {@link SettingsRoute.select}; carried over by every replace
|
|
63
|
+
* the page makes, since a replace does not change what came before.
|
|
64
|
+
*/
|
|
65
|
+
export const SETTINGS_FROM_LIST_STATE = "eifi1.settings.fromList";
|
|
66
|
+
|
|
67
|
+
/** `location.state` with the marker set — for an app's own link to a group page that is
|
|
68
|
+
* opened FROM the list it renders. */
|
|
69
|
+
export function settingsFromListState(): Record<string, true> {
|
|
70
|
+
return { [SETTINGS_FROM_LIST_STATE]: true };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function isFromList(state: unknown): boolean {
|
|
74
|
+
return typeof state === "object" && state !== null && (state as Record<string, unknown>)[SETTINGS_FROM_LIST_STATE] === true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface SettingsLocation {
|
|
78
|
+
pathname: string;
|
|
79
|
+
search: string;
|
|
80
|
+
hash: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface SettingsLocationRules<G extends string> {
|
|
84
|
+
basePath: string;
|
|
85
|
+
/** The visible group ids. */
|
|
86
|
+
groups: readonly G[];
|
|
87
|
+
/** The resolved default group, `null` with no visible group. */
|
|
88
|
+
defaultGroup: G | null;
|
|
89
|
+
aliases?: Readonly<Partial<Record<string, G>>>;
|
|
90
|
+
/** Anchor → group, for `/settings?focus=<anchor>` with no group named. */
|
|
91
|
+
anchorGroup?: ReadonlyMap<string, G>;
|
|
92
|
+
phone: boolean;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface SettingsLocationResult<G extends string> {
|
|
96
|
+
group: G | null;
|
|
97
|
+
sub: string | null;
|
|
98
|
+
/** The path (with query) to replace the location with, or `null` when it is already
|
|
99
|
+
* canonical. */
|
|
100
|
+
redirect: string | null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Where a location lands on the settings page — pure, so the rules of §3.1 are testable
|
|
105
|
+
* without a router:
|
|
106
|
+
*
|
|
107
|
+
* - `/settings` → the default group on a desktop (a replace), the list on a phone;
|
|
108
|
+
* - `/settings/<group>[/<sub>]` → that group, the rest of the path as `sub`;
|
|
109
|
+
* - an alias → its successor, with a replace, `sub`, query and hash kept;
|
|
110
|
+
* - an unknown or hidden group → the default group (desktop) or the list (phone), with
|
|
111
|
+
* a replace and the query kept — never a 404, so an old bookmark still lands;
|
|
112
|
+
* - keksdose's legacy `/settings?<query>#<group>[/<sub>]` →
|
|
113
|
+
* `/settings/<group>[/<sub>]?<query>`, the WHOLE query carried (a tour's
|
|
114
|
+
* `tour`/`tourStep` as well as `focus`), then resolved by the rules above;
|
|
115
|
+
* - `/settings?focus=<anchor>` with no group → the anchor's group, where it can ring.
|
|
116
|
+
*/
|
|
117
|
+
export function resolveSettingsLocation<G extends string>(
|
|
118
|
+
location: SettingsLocation,
|
|
119
|
+
rules: SettingsLocationRules<G>,
|
|
120
|
+
): SettingsLocationResult<G> {
|
|
121
|
+
const base = normalizeSettingsBase(rules.basePath);
|
|
122
|
+
const { pathname, search, hash } = location;
|
|
123
|
+
const known = new Set<string>(rules.groups);
|
|
124
|
+
const atBase = pathname === base || pathname === `${base}/` || (base === "" && pathname === "/");
|
|
125
|
+
|
|
126
|
+
if (atBase) {
|
|
127
|
+
const legacy = hash.replace(/^#/, "").replace(/^\/+/, "");
|
|
128
|
+
if (legacy) {
|
|
129
|
+
// The hash becomes the path; whatever the path then says (an alias, an unknown
|
|
130
|
+
// group) is resolved in the same step, so the history sees one replace.
|
|
131
|
+
const converted = `${base}/${legacy}`;
|
|
132
|
+
const next = resolveSettingsLocation({ pathname: converted, search, hash: "" }, rules);
|
|
133
|
+
return { ...next, redirect: next.redirect ?? `${converted}${search}` };
|
|
134
|
+
}
|
|
135
|
+
const anchor = new URLSearchParams(search).get("focus");
|
|
136
|
+
const anchorGroup = anchor ? rules.anchorGroup?.get(anchor) : undefined;
|
|
137
|
+
if (anchorGroup && known.has(anchorGroup)) {
|
|
138
|
+
return { group: anchorGroup, sub: null, redirect: `${base}/${anchorGroup}${search}` };
|
|
139
|
+
}
|
|
140
|
+
if (rules.phone || rules.defaultGroup === null) return { group: null, sub: null, redirect: null };
|
|
141
|
+
return { group: rules.defaultGroup, sub: null, redirect: `${base}/${rules.defaultGroup}${search}` };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (!pathname.startsWith(`${base}/`)) {
|
|
145
|
+
// Mounted somewhere `basePath` does not name: a misconfiguration, not a link to
|
|
146
|
+
// correct. Show what the base path would, and leave the address alone.
|
|
147
|
+
return { group: rules.phone ? null : rules.defaultGroup, sub: null, redirect: null };
|
|
148
|
+
}
|
|
149
|
+
const rest = pathname.slice(base.length + 1);
|
|
150
|
+
const [segment = "", ...subParts] = rest.split("/");
|
|
151
|
+
const sub = subParts.filter(Boolean).join("/") || null;
|
|
152
|
+
if (known.has(segment)) return { group: segment as G, sub, redirect: null };
|
|
153
|
+
|
|
154
|
+
const successor = rules.aliases?.[segment];
|
|
155
|
+
if (successor !== undefined && known.has(successor)) {
|
|
156
|
+
return {
|
|
157
|
+
group: successor,
|
|
158
|
+
sub,
|
|
159
|
+
redirect: `${base}/${successor}${sub ? `/${sub}` : ""}${search}${hash}`,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Unknown or hidden. The hash is dropped: on the list it would read as a legacy group
|
|
164
|
+
// and send the page round again.
|
|
165
|
+
if (rules.phone || rules.defaultGroup === null) {
|
|
166
|
+
return { group: null, sub: null, redirect: `${base || "/"}${search}` };
|
|
167
|
+
}
|
|
168
|
+
return { group: rules.defaultGroup, sub: null, redirect: `${base}/${rules.defaultGroup}${search}` };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* The settings page's route (docs/settings-harmonization.md §3.1): which group the URL
|
|
173
|
+
* names, and the history rules for moving between groups.
|
|
174
|
+
*
|
|
175
|
+
* The URL IS the selection, as it was in keksdose (where it was the hash): there is no
|
|
176
|
+
* state to keep in step with it, so a deep link, a reload, back and forward all land
|
|
177
|
+
* where the address says. Everything that is not canonical — `/settings` on a desktop, a
|
|
178
|
+
* legacy hash, an alias, an unknown or hidden group — is replaced by its canonical path.
|
|
179
|
+
*
|
|
180
|
+
* **The replace runs on every navigation**, keyed on `location.key`, not once on mount:
|
|
181
|
+
* the router keeps the page mounted across links followed inside the app — keksdose's
|
|
182
|
+
* inbox renders admin-typed URLs, and a push click routes an open window without a
|
|
183
|
+
* reload — so a legacy `/settings#security` arriving while the page is open converts too
|
|
184
|
+
* (§10.1).
|
|
185
|
+
*/
|
|
186
|
+
export function useSettingsRoute<G extends string>(options: UseSettingsRouteOptions<G>): SettingsRoute<G> {
|
|
187
|
+
const { groups, entries, basePath, defaultGroup, aliases, layout = "auto" } = options;
|
|
188
|
+
const location = useLocation();
|
|
189
|
+
const navigate = useNavigate();
|
|
190
|
+
const narrow = useMediaQuery(PHONE_QUERY, false);
|
|
191
|
+
const phone = layout === "phone" || (layout === "auto" && narrow);
|
|
192
|
+
const base = normalizeSettingsBase(basePath);
|
|
193
|
+
|
|
194
|
+
const visible = useMemo(() => visibleSettingsGroups(groups, entries), [groups, entries]);
|
|
195
|
+
const anchorGroup = useMemo(() => {
|
|
196
|
+
const map = new Map<string, G>();
|
|
197
|
+
for (const e of entries ?? []) if (e.visible !== false && !map.has(e.anchor)) map.set(e.anchor, e.group);
|
|
198
|
+
return map;
|
|
199
|
+
}, [entries]);
|
|
200
|
+
const ids = visible.map((g) => g.id);
|
|
201
|
+
const fallback =
|
|
202
|
+
defaultGroup !== undefined && ids.includes(defaultGroup) ? defaultGroup : (ids[0] ?? null);
|
|
203
|
+
|
|
204
|
+
const { group, sub, redirect } = resolveSettingsLocation(location, {
|
|
205
|
+
basePath: base,
|
|
206
|
+
groups: ids,
|
|
207
|
+
defaultGroup: fallback,
|
|
208
|
+
aliases,
|
|
209
|
+
anchorGroup,
|
|
210
|
+
phone,
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const { key, state, search } = location;
|
|
214
|
+
useEffect(() => {
|
|
215
|
+
// `state` rides along: the marker describes the entry BEFORE this one, which a
|
|
216
|
+
// replace does not change.
|
|
217
|
+
if (redirect) navigate(redirect, { replace: true, state });
|
|
218
|
+
}, [key, redirect, state, navigate]);
|
|
219
|
+
|
|
220
|
+
const select = useCallback(
|
|
221
|
+
(next: G) => {
|
|
222
|
+
const to = `${base}/${next}`;
|
|
223
|
+
// From the list, the push marks it, so the group page's back is a real back.
|
|
224
|
+
if (phone) navigate(to, group === null ? { state: settingsFromListState() } : undefined);
|
|
225
|
+
// A new group is a new page: the old one's query (a focus, a roster filter) stays
|
|
226
|
+
// behind, as keksdose's `selectGroup` left it.
|
|
227
|
+
else navigate(to, { replace: true, state });
|
|
228
|
+
},
|
|
229
|
+
[base, phone, group, state, navigate],
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
const selectSub = useCallback(
|
|
233
|
+
(next: string | null) => {
|
|
234
|
+
if (group === null) return;
|
|
235
|
+
navigate(`${base}/${group}${next ? `/${next}` : ""}${search}`, { replace: true, state });
|
|
236
|
+
},
|
|
237
|
+
[base, group, search, state, navigate],
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
const fromList = isFromList(state);
|
|
241
|
+
const back = useCallback(() => {
|
|
242
|
+
if (fromList) navigate(-1);
|
|
243
|
+
else navigate(base || "/", { replace: true });
|
|
244
|
+
}, [fromList, base, navigate]);
|
|
245
|
+
|
|
246
|
+
return {
|
|
247
|
+
group,
|
|
248
|
+
sub,
|
|
249
|
+
focus: new URLSearchParams(search).get("focus"),
|
|
250
|
+
select,
|
|
251
|
+
selectSub,
|
|
252
|
+
back,
|
|
253
|
+
groups: visible,
|
|
254
|
+
phone,
|
|
255
|
+
redirecting: redirect !== null,
|
|
256
|
+
fromList,
|
|
257
|
+
};
|
|
258
|
+
}
|
package/src/shell/app-shell.tsx
CHANGED
|
@@ -37,6 +37,12 @@ export interface AppShellNavItem {
|
|
|
37
37
|
* shortening the real label, which the sidebar has ample room for and which is the
|
|
38
38
|
* name the rest of the product uses. */
|
|
39
39
|
shortLabel?: string;
|
|
40
|
+
/** 0.31.0: leave this entry out of the MOBILE BOTTOM BAR; the sidebar keeps it.
|
|
41
|
+
* For an entry a phone reaches another way — the brand link to the start page —
|
|
42
|
+
* when one cell fewer is what keeps the others' labels whole (the bar divides its
|
|
43
|
+
* width evenly, see `shortLabel`). Its group's sub-row still shows while one of its
|
|
44
|
+
* pages is open. Named like `DataTable`'s column `mobileHidden`. */
|
|
45
|
+
mobileHidden?: boolean;
|
|
40
46
|
icon: LucideIcon;
|
|
41
47
|
/** Passed to NavLink's `end` (exact match). Defaults to true. */
|
|
42
48
|
end?: boolean;
|
|
@@ -272,6 +278,8 @@ export function AppShell({
|
|
|
272
278
|
...rest
|
|
273
279
|
}: AppShellProps) {
|
|
274
280
|
const embedded = useContext(AppShellNesting) || !!embeddedProp;
|
|
281
|
+
// The bottom bar's cells: every entry the phone does not reach another way.
|
|
282
|
+
const barNav = nav.filter((item) => !item.mobileHidden);
|
|
275
283
|
// An embedded shell sharing the default key would overwrite the outer app's sidebar
|
|
276
284
|
// preference with its own — so it persists only when given a key of its own.
|
|
277
285
|
const collapseStorageKey =
|
|
@@ -448,9 +456,9 @@ export function AppShell({
|
|
|
448
456
|
<nav
|
|
449
457
|
data-tour="nav"
|
|
450
458
|
className="grid"
|
|
451
|
-
style={{ gridTemplateColumns: `repeat(${
|
|
459
|
+
style={{ gridTemplateColumns: `repeat(${barNav.length}, minmax(0, 1fr))` }}
|
|
452
460
|
>
|
|
453
|
-
{
|
|
461
|
+
{barNav.map((item) => (
|
|
454
462
|
<MobileNavItem key={item.to} item={item} />
|
|
455
463
|
))}
|
|
456
464
|
</nav>
|
package/src/shell.ts
CHANGED
|
@@ -10,3 +10,48 @@ export * from "./shell/role-switcher";
|
|
|
10
10
|
export * from "./shell/topbar-action-menu";
|
|
11
11
|
export * from "./shell/top-bar-brand";
|
|
12
12
|
export * from "./shell/auth-layout";
|
|
13
|
+
// 0.31.0: the settings and admin pages' shell (docs/settings-harmonization.md §3, §5).
|
|
14
|
+
export { SettingsLayout, SETTINGS_SEARCH_THRESHOLD } from "./settings/settings-layout";
|
|
15
|
+
export type { SettingsLayoutProps, SettingsLayoutWidth } from "./settings/settings-layout";
|
|
16
|
+
export {
|
|
17
|
+
useSettingsRoute,
|
|
18
|
+
resolveSettingsLocation,
|
|
19
|
+
settingsFromListState,
|
|
20
|
+
SETTINGS_FROM_LIST_STATE,
|
|
21
|
+
} from "./settings/use-settings-route";
|
|
22
|
+
export type {
|
|
23
|
+
UseSettingsRouteOptions,
|
|
24
|
+
SettingsRoute,
|
|
25
|
+
SettingsLayoutMode,
|
|
26
|
+
SettingsLocation,
|
|
27
|
+
SettingsLocationRules,
|
|
28
|
+
SettingsLocationResult,
|
|
29
|
+
} from "./settings/use-settings-route";
|
|
30
|
+
export { useSettingsFocus, SETTINGS_FOCUS_RING, SETTINGS_FOCUS_MS } from "./settings/use-settings-focus";
|
|
31
|
+
export { SettingsSection } from "./settings/settings-section";
|
|
32
|
+
export type { SettingsSectionProps } from "./settings/settings-section";
|
|
33
|
+
export { useSettingsLayout } from "./settings/settings-context";
|
|
34
|
+
export type { SettingsLayoutContextValue } from "./settings/settings-context";
|
|
35
|
+
export { SettingsHeadingLevel, useSettingsHeadingLevel } from "./settings/settings-heading";
|
|
36
|
+
export type { SettingsHeadingLevelProps, SettingsHeadingTag } from "./settings/settings-heading";
|
|
37
|
+
export {
|
|
38
|
+
settingsSearchEntries,
|
|
39
|
+
visibleSettingsGroups,
|
|
40
|
+
visibleSettingsEntries,
|
|
41
|
+
settingsHref,
|
|
42
|
+
} from "./settings/settings-catalogue";
|
|
43
|
+
export type { SettingsGroup, SettingsEntry, SettingsSearchEntriesOptions } from "./settings/settings-catalogue";
|
|
44
|
+
// 0.31.0: the public pages' header and the resume (docs/landing-demo-harmonization.md §3, §4.1).
|
|
45
|
+
export {
|
|
46
|
+
RootEntry,
|
|
47
|
+
RedirectIfAuthed,
|
|
48
|
+
useLastVisitedPage,
|
|
49
|
+
readLastVisitedPage,
|
|
50
|
+
clearLastVisitedPage,
|
|
51
|
+
safeNextPath,
|
|
52
|
+
NEXT_PARAM,
|
|
53
|
+
DEFAULT_LAST_VISITED_EXCLUDES,
|
|
54
|
+
} from "./landing/routing";
|
|
55
|
+
export type { RootEntryProps, RedirectIfAuthedProps, LastVisitedPageOptions, PathPattern } from "./landing/routing";
|
|
56
|
+
export { PublicHeader } from "./landing/public-header";
|
|
57
|
+
export type { PublicHeaderProps, PublicHeaderBrand } from "./landing/public-header";
|