@raulaguila/maat-ui 0.4.0 → 0.6.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.
Files changed (50) hide show
  1. package/README.md +137 -2
  2. package/dist/account-menu.d.ts +10 -0
  3. package/dist/account-menu.js +17 -0
  4. package/dist/auth-card.d.ts +22 -0
  5. package/dist/auth-card.js +14 -0
  6. package/dist/badge.d.ts +1 -1
  7. package/dist/breadcrumb.d.ts +15 -0
  8. package/dist/breadcrumb.js +24 -0
  9. package/dist/button.d.ts +5 -2
  10. package/dist/button.js +4 -3
  11. package/dist/device.d.ts +5 -0
  12. package/dist/device.js +23 -0
  13. package/dist/error-screens.d.ts +14 -0
  14. package/dist/error-screens.js +18 -0
  15. package/dist/form-error.d.ts +6 -0
  16. package/dist/form-error.js +8 -0
  17. package/dist/form-field.d.ts +4 -2
  18. package/dist/form-field.js +10 -2
  19. package/dist/format.d.ts +12 -0
  20. package/dist/format.js +46 -0
  21. package/dist/hooks.d.ts +26 -0
  22. package/dist/hooks.js +87 -0
  23. package/dist/index.d.ts +15 -0
  24. package/dist/index.js +15 -0
  25. package/dist/labels.d.ts +66 -3
  26. package/dist/labels.js +55 -5
  27. package/dist/notification-bell.d.ts +5 -0
  28. package/dist/notification-bell.js +11 -0
  29. package/dist/password-strength.d.ts +7 -0
  30. package/dist/password-strength.js +27 -0
  31. package/dist/pre-paint.d.ts +9 -0
  32. package/dist/pre-paint.js +12 -0
  33. package/dist/save-bar.d.ts +20 -0
  34. package/dist/save-bar.js +19 -0
  35. package/dist/selection-bar.d.ts +8 -0
  36. package/dist/selection-bar.js +11 -0
  37. package/dist/sessions-table.d.ts +20 -0
  38. package/dist/sessions-table.js +48 -0
  39. package/dist/skeleton.d.ts +6 -1
  40. package/dist/skeleton.js +6 -1
  41. package/dist/sonner.d.ts +13 -1
  42. package/dist/sonner.js +29 -2
  43. package/dist/sort-head.d.ts +12 -0
  44. package/dist/sort-head.js +10 -0
  45. package/dist/status-badge.d.ts +8 -0
  46. package/dist/status-badge.js +13 -0
  47. package/dist/theme-toggle.d.ts +4 -0
  48. package/dist/theme-toggle.js +20 -0
  49. package/package.json +78 -4
  50. package/styles.css +55 -0
package/dist/hooks.js ADDED
@@ -0,0 +1,87 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useEffect, useState } from "react";
4
+ import { ConfirmDialog } from "./confirm-dialog.js";
5
+ import { useFamilyLabels } from "./labels.js";
6
+ /** The value once it has stopped changing for `ms`; keeps typing from firing a request per key. */
7
+ export function useDebounced(value, ms = 300) {
8
+ const [debounced, setDebounced] = useState(value);
9
+ useEffect(() => {
10
+ const id = setTimeout(() => setDebounced(value), ms);
11
+ return () => clearTimeout(id);
12
+ }, [value, ms]);
13
+ return debounced;
14
+ }
15
+ /**
16
+ * Guards unsaved work while `dirty`: tab close and reload always ask. With `onOpenChange` (a dialog),
17
+ * `requestClose` replaces it and asks before closing through `discardDialog`, which the caller renders.
18
+ * Without it (a page), clicks on in-app links ask first.
19
+ * shortcut: browser back/forward inside the app is not caught, the App Router has no blocking API.
20
+ */
21
+ export function useDiscardChanges(dirty, onOpenChange) {
22
+ const labels = useFamilyLabels();
23
+ const [confirmOpen, setConfirmOpen] = useState(false);
24
+ const guardLinks = !onOpenChange;
25
+ const message = labels.discardChanges;
26
+ useEffect(() => {
27
+ if (!dirty)
28
+ return;
29
+ const unload = (e) => { e.preventDefault(); e.returnValue = ""; };
30
+ const click = (e) => {
31
+ const a = e.target?.closest("a[href]");
32
+ if (!a || a.getAttribute("target") === "_blank" || e.metaKey || e.ctrlKey || e.shiftKey)
33
+ return;
34
+ if (!window.confirm(message)) {
35
+ e.preventDefault();
36
+ e.stopPropagation();
37
+ }
38
+ };
39
+ window.addEventListener("beforeunload", unload);
40
+ if (guardLinks)
41
+ document.addEventListener("click", click, true);
42
+ return () => {
43
+ window.removeEventListener("beforeunload", unload);
44
+ document.removeEventListener("click", click, true);
45
+ };
46
+ }, [dirty, guardLinks, message]);
47
+ const requestClose = (next) => {
48
+ if (!next && dirty)
49
+ setConfirmOpen(true);
50
+ else
51
+ onOpenChange?.(next);
52
+ };
53
+ const discardDialog = _jsx(ConfirmDialog, { open: confirmOpen, onOpenChange: setConfirmOpen, title: labels.discardTitle, description: labels.discardChanges, cancelLabel: labels.keepEditing, confirmLabel: labels.discard, destructive: true, onConfirm: () => onOpenChange?.(false) });
54
+ return { requestClose, discardDialog };
55
+ }
56
+ /** The token an e-mail link carries (`#token=`, or `?token=` from links sent before the fragment), and the address without it. */
57
+ export function takeToken(href) {
58
+ const url = new URL(href);
59
+ const token = new URLSearchParams(url.hash.slice(1)).get("token") ?? url.searchParams.get("token");
60
+ url.searchParams.delete("token");
61
+ if (new URLSearchParams(url.hash.slice(1)).has("token"))
62
+ url.hash = "";
63
+ return { token, clean: url.pathname + url.search + url.hash };
64
+ }
65
+ /**
66
+ * Reads the link's token once mounted and clears it from the address bar, so it stays out of history and
67
+ * of any server log. `read` turns true after the first look; `setToken` takes a pasted one.
68
+ */
69
+ export function useHashToken() {
70
+ const [token, setToken] = useState("");
71
+ const [read, setRead] = useState(false);
72
+ useEffect(() => {
73
+ const take = () => {
74
+ const { token: fromLink, clean } = takeToken(window.location.href);
75
+ setRead(true);
76
+ if (!fromLink)
77
+ return;
78
+ setToken(fromLink);
79
+ window.history.replaceState(null, "", clean);
80
+ };
81
+ take();
82
+ // A link pasted into the same tab changes only the fragment, so the page does not reload.
83
+ window.addEventListener("hashchange", take);
84
+ return () => window.removeEventListener("hashchange", take);
85
+ }, []);
86
+ return { token, setToken, read };
87
+ }
package/dist/index.d.ts CHANGED
@@ -29,3 +29,18 @@ export * from "./password-input.js";
29
29
  export * from "./confirm-dialog.js";
30
30
  export * from "./empty-state.js";
31
31
  export * from "./query-error-state.js";
32
+ export * from "./auth-card.js";
33
+ export * from "./device.js";
34
+ export * from "./status-badge.js";
35
+ export * from "./form-error.js";
36
+ export * from "./save-bar.js";
37
+ export * from "./selection-bar.js";
38
+ export * from "./sort-head.js";
39
+ export * from "./error-screens.js";
40
+ export * from "./account-menu.js";
41
+ export * from "./notification-bell.js";
42
+ export * from "./breadcrumb.js";
43
+ export * from "./format.js";
44
+ export * from "./hooks.js";
45
+ export * from "./password-strength.js";
46
+ export * from "./pre-paint.js";
package/dist/index.js CHANGED
@@ -29,3 +29,18 @@ export * from "./password-input.js";
29
29
  export * from "./confirm-dialog.js";
30
30
  export * from "./empty-state.js";
31
31
  export * from "./query-error-state.js";
32
+ export * from "./auth-card.js";
33
+ export * from "./device.js";
34
+ export * from "./status-badge.js";
35
+ export * from "./form-error.js";
36
+ export * from "./save-bar.js";
37
+ export * from "./selection-bar.js";
38
+ export * from "./sort-head.js";
39
+ export * from "./error-screens.js";
40
+ export * from "./account-menu.js";
41
+ export * from "./notification-bell.js";
42
+ export * from "./breadcrumb.js";
43
+ export * from "./format.js";
44
+ export * from "./hooks.js";
45
+ export * from "./password-strength.js";
46
+ export * from "./pre-paint.js";
package/dist/labels.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type ReactNode } from "react";
1
+ import { type ElementType, type ReactNode } from "react";
2
2
  export interface FamilyLabels {
3
3
  close: string;
4
4
  rows: string;
@@ -15,9 +15,72 @@ export interface FamilyLabels {
15
15
  errorTitle?: string;
16
16
  errorDescription?: string;
17
17
  retry?: string;
18
+ goHome?: string;
19
+ pageNotFound?: string;
20
+ pageNotFoundDescription?: string;
21
+ save?: string;
22
+ discard?: string;
23
+ keepEditing?: string;
24
+ unsaved?: string;
25
+ discardTitle?: string;
26
+ discardChanges?: string;
27
+ selection?: string;
28
+ selectedOne?: string;
29
+ selectedMany?: string;
30
+ clearSelection?: string;
31
+ accountMenu?: string;
32
+ profile?: string;
33
+ shortcuts?: string;
34
+ logout?: string;
35
+ notifications?: string;
36
+ /** "{count}" is replaced by the number. */
37
+ notificationsUnread?: string;
38
+ themeToDark?: string;
39
+ themeToLight?: string;
40
+ breadcrumb?: string;
41
+ passwordStrength?: string;
42
+ passwordWeak?: string;
43
+ passwordFair?: string;
44
+ passwordGood?: string;
45
+ passwordStrong?: string;
46
+ sessions?: string;
47
+ device?: string;
48
+ ip?: string;
49
+ lastSeen?: string;
50
+ thisDevice?: string;
51
+ unknownDevice?: string;
52
+ revoke?: string;
53
+ revokeOthers?: string;
54
+ revokeOthersDescription?: string;
55
+ revokeFailed?: string;
56
+ /** "{n}" is replaced by the number of sessions. */
57
+ sessionsAll?: string;
58
+ sessionsFewer?: string;
59
+ twoStepLogin?: string;
60
+ passwordsMismatch?: string;
61
+ backToLogin?: string;
62
+ email?: string;
18
63
  }
19
- export declare function FamilyUIProvider({ labels, children }: {
64
+ /** Portuguese, the library's default language. */
65
+ export declare const familyLabelsPtBR: Required<FamilyLabels>;
66
+ export declare const familyLabelsEn: Required<FamilyLabels>;
67
+ /** How the library renders an in-app link (Next's Link, for example); a plain <a> by default. */
68
+ export type FamilyLink = ElementType<{
69
+ href: string;
70
+ className?: string;
71
+ children?: ReactNode;
72
+ }>;
73
+ export declare function FamilyUIProvider({ labels, locale, link, children }: {
20
74
  labels: FamilyLabels;
75
+ /** BCP 47 locale for dates and numbers. */
76
+ locale?: string;
77
+ link?: FamilyLink;
21
78
  children: ReactNode;
22
79
  }): import("react").JSX.Element;
23
- export declare function useFamilyLabels(): FamilyLabels;
80
+ /** The host's labels; a key it leaves out falls back to Portuguese. */
81
+ export declare function useFamilyLabels(): Required<FamilyLabels>;
82
+ /** The host's locale and link component. */
83
+ export declare function useFamilyUI(): {
84
+ locale: string;
85
+ link: FamilyLink;
86
+ };
package/dist/labels.js CHANGED
@@ -1,10 +1,60 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { createContext, useContext } from "react";
4
- const Labels = createContext({
4
+ /** Portuguese, the library's default language. */
5
+ export const familyLabelsPtBR = {
5
6
  close: "Fechar", rows: "Linhas", of: "de", previous: "Página anterior", next: "Próxima página",
6
- });
7
- export function FamilyUIProvider({ labels, children }) {
8
- return _jsx(Labels.Provider, { value: labels, children: children });
7
+ noChoices: "Nenhuma opção encontrada.", hidePassword: "Ocultar senha", showPassword: "Mostrar senha",
8
+ cancel: "Cancelar", confirm: "Confirmar", confirming: "Aguarde…", confirmFailed: "Não foi possível concluir a ação.",
9
+ errorTitle: "Algo deu errado", errorDescription: "Os dados não puderam ser carregados.", retry: "Tentar de novo",
10
+ goHome: "Ir para o início", pageNotFound: "Página não encontrada", pageNotFoundDescription: "O endereço não existe ou mudou.",
11
+ save: "Salvar", discard: "Descartar", keepEditing: "Continuar editando", unsaved: "Alterações não salvas",
12
+ discardTitle: "Descartar alterações?", discardChanges: "Há alterações não salvas. Descartar e fechar?",
13
+ selection: "Seleção", selectedOne: "selecionado", selectedMany: "selecionados", clearSelection: "Limpar seleção",
14
+ accountMenu: "Menu da conta", profile: "Perfil", shortcuts: "Atalhos", logout: "Sair",
15
+ notifications: "Notificações", notificationsUnread: "Notificações, {count} por ler",
16
+ themeToDark: "Mudar para tema escuro", themeToLight: "Mudar para tema claro", breadcrumb: "Caminho da página",
17
+ passwordStrength: "Força da senha", passwordWeak: "Fraca", passwordFair: "Razoável", passwordGood: "Boa", passwordStrong: "Forte",
18
+ sessions: "Sessões", device: "Dispositivo", ip: "IP", lastSeen: "Último acesso", thisDevice: "Este dispositivo",
19
+ unknownDevice: "Dispositivo desconhecido", revoke: "Encerrar", revokeOthers: "Encerrar as outras",
20
+ revokeOthersDescription: "Todas as sessões, exceto esta, serão encerradas.", revokeFailed: "Não foi possível encerrar a sessão.",
21
+ sessionsAll: "Ver todas as {n} sessões", sessionsFewer: "Ver menos",
22
+ twoStepLogin: "Login em duas etapas", passwordsMismatch: "As senhas não coincidem", backToLogin: "Voltar para o login",
23
+ email: "e-mail",
24
+ };
25
+ export const familyLabelsEn = {
26
+ close: "Close", rows: "Rows", of: "of", previous: "Previous page", next: "Next page",
27
+ noChoices: "No options found.", hidePassword: "Hide password", showPassword: "Show password",
28
+ cancel: "Cancel", confirm: "Confirm", confirming: "Please wait…", confirmFailed: "The action could not be completed.",
29
+ errorTitle: "Something went wrong", errorDescription: "The data could not be loaded.", retry: "Try again",
30
+ goHome: "Go to home", pageNotFound: "Page not found", pageNotFoundDescription: "The address does not exist or has moved.",
31
+ save: "Save", discard: "Discard", keepEditing: "Keep editing", unsaved: "Unsaved changes",
32
+ discardTitle: "Discard changes?", discardChanges: "You have unsaved changes. Discard and close?",
33
+ selection: "Selection", selectedOne: "selected", selectedMany: "selected", clearSelection: "Clear selection",
34
+ accountMenu: "Account menu", profile: "Profile", shortcuts: "Shortcuts", logout: "Sign out",
35
+ notifications: "Notifications", notificationsUnread: "Notifications, {count} unread",
36
+ themeToDark: "Switch to dark theme", themeToLight: "Switch to light theme", breadcrumb: "Page path",
37
+ passwordStrength: "Password strength", passwordWeak: "Weak", passwordFair: "Fair", passwordGood: "Good", passwordStrong: "Strong",
38
+ sessions: "Sessions", device: "Device", ip: "IP", lastSeen: "Last seen", thisDevice: "This device",
39
+ unknownDevice: "Unknown device", revoke: "End", revokeOthers: "End the others",
40
+ revokeOthersDescription: "Every session except this one will be ended.", revokeFailed: "The session could not be ended.",
41
+ sessionsAll: "Show all {n} sessions", sessionsFewer: "Show fewer",
42
+ twoStepLogin: "Two-step login", passwordsMismatch: "The passwords do not match", backToLogin: "Back to sign in",
43
+ email: "email",
44
+ };
45
+ const Labels = createContext(familyLabelsPtBR);
46
+ const Env = createContext({ locale: "pt-BR", link: "a" });
47
+ export function FamilyUIProvider({ labels, locale = "pt-BR", link = "a", children }) {
48
+ return _jsx(Env.Provider, { value: { locale, link }, children: _jsx(Labels.Provider, { value: labels, children: children }) });
9
49
  }
10
- export function useFamilyLabels() { return useContext(Labels); }
50
+ /** The host's labels; a key it leaves out falls back to Portuguese. */
51
+ export function useFamilyLabels() {
52
+ const labels = useContext(Labels);
53
+ const merged = { ...familyLabelsPtBR };
54
+ for (const [k, v] of Object.entries(labels))
55
+ if (v !== undefined)
56
+ merged[k] = v;
57
+ return merged;
58
+ }
59
+ /** The host's locale and link component. */
60
+ export function useFamilyUI() { return useContext(Env); }
@@ -0,0 +1,5 @@
1
+ /** Header link to the notifications page with the unread count; the badge is decoration, the name says the number. */
2
+ export declare function NotificationBell({ count, href }: {
3
+ count: number;
4
+ href: string;
5
+ }): import("react").JSX.Element;
@@ -0,0 +1,11 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Bell } from "lucide-react";
4
+ import { useFamilyLabels, useFamilyUI } from "./labels.js";
5
+ /** Header link to the notifications page with the unread count; the badge is decoration, the name says the number. */
6
+ export function NotificationBell({ count, href }) {
7
+ const labels = useFamilyLabels();
8
+ const { link: Link } = useFamilyUI();
9
+ const label = count > 0 ? labels.notificationsUnread.replace("{count}", String(count)) : labels.notifications;
10
+ return (_jsxs(Link, { href: href, "aria-label": label, title: label, className: "relative flex size-11 items-center justify-center rounded-md text-muted-foreground outline-none hover:bg-accent hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring md:pointer-fine:size-8", children: [_jsx(Bell, { className: "size-4", "aria-hidden": true }), count > 0 && _jsx("span", { "aria-hidden": true, className: "absolute -right-0.5 -top-0.5 min-w-4 rounded-full bg-primary px-1 text-center text-xs font-semibold leading-4 text-primary-foreground", children: count > 99 ? "99+" : count })] }));
11
+ }
@@ -0,0 +1,7 @@
1
+ /** 0 under 8 characters; then 1, plus one each for 12+ characters, mixed case, and a digit with a symbol. */
2
+ export declare function passwordScore(pw: string): number;
3
+ /** Four bars and a word under a new-password field; nothing while empty. */
4
+ export declare function PasswordStrength({ password, className }: {
5
+ password: string;
6
+ className?: string;
7
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,27 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { cn } from "./cn.js";
4
+ import { useFamilyLabels } from "./labels.js";
5
+ /** 0 under 8 characters; then 1, plus one each for 12+ characters, mixed case, and a digit with a symbol. */
6
+ export function passwordScore(pw) {
7
+ if (pw.length < 8)
8
+ return 0;
9
+ let score = 1;
10
+ if (pw.length >= 12)
11
+ score++;
12
+ if (/[a-z]/.test(pw) && /[A-Z]/.test(pw))
13
+ score++;
14
+ if (/\d/.test(pw) && /[^A-Za-z0-9]/.test(pw))
15
+ score++;
16
+ return score;
17
+ }
18
+ const BAR = ["bg-destructive", "bg-destructive", "bg-warn", "bg-success/70", "bg-success"];
19
+ /** Four bars and a word under a new-password field; nothing while empty. */
20
+ export function PasswordStrength({ password, className }) {
21
+ const labels = useFamilyLabels();
22
+ if (!password)
23
+ return null;
24
+ const score = passwordScore(password);
25
+ const word = [labels.passwordWeak, labels.passwordWeak, labels.passwordFair, labels.passwordGood, labels.passwordStrong][score];
26
+ return (_jsxs("div", { className: cn("flex items-center gap-2", className), "aria-live": "polite", children: [_jsx("div", { className: "flex flex-1 gap-1", "aria-hidden": true, children: [1, 2, 3, 4].map((i) => _jsx("div", { className: cn("h-1 flex-1 rounded-full bg-muted", i <= Math.max(score, 1) && BAR[score]) }, i)) }), _jsxs("span", { className: "w-16 text-right text-xs text-muted-foreground", children: [_jsxs("span", { className: "sr-only", children: [labels.passwordStrength, ": "] }), word] })] }));
27
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Inline <head> script that applies the saved collapsed sidebar (zustand-persisted `state.sidebarCollapsed`
3
+ * under `uiKey`) and density (under `densityKey`) before the first paint. The shell removes the
4
+ * `sidebar-collapsed` class once its store takes over.
5
+ */
6
+ export declare function prePaintScript({ uiKey, densityKey }: {
7
+ uiKey: string;
8
+ densityKey?: string;
9
+ }): string;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Inline <head> script that applies the saved collapsed sidebar (zustand-persisted `state.sidebarCollapsed`
3
+ * under `uiKey`) and density (under `densityKey`) before the first paint. The shell removes the
4
+ * `sidebar-collapsed` class once its store takes over.
5
+ */
6
+ export function prePaintScript({ uiKey, densityKey }) {
7
+ const ui = JSON.stringify(uiKey);
8
+ const density = densityKey
9
+ ? `try{var d=localStorage.getItem(${JSON.stringify(densityKey)});if(d==='comfortable'||d==='compact')document.documentElement.setAttribute('data-density',d)}catch(e){}`
10
+ : "";
11
+ return `(function(){try{var r=localStorage.getItem(${ui});var p=r&&JSON.parse(r);if(p&&p.state&&p.state.sidebarCollapsed)document.documentElement.classList.add('sidebar-collapsed')}catch(e){}${density}})();`;
12
+ }
@@ -0,0 +1,20 @@
1
+ import type { ReactNode } from "react";
2
+ /**
3
+ * Save control, sticky at the bottom while `dirty`. As the last child of FormSections, `footer` makes it
4
+ * the card's footer; otherwise it sits inside its section. `submit` makes Save the form's submit button, so Enter saves.
5
+ */
6
+ export declare function SaveBar({ dirty, saving, canSave, onSave, onDiscard, label, error, saveLabel, discardLabel, submit, footer }: {
7
+ dirty: boolean;
8
+ saving?: boolean;
9
+ canSave?: boolean;
10
+ onSave?: () => void;
11
+ onDiscard: () => void;
12
+ /** Names the bar; "Alterações não salvas" by default. */
13
+ label?: string;
14
+ /** Takes the label's place, so the buttons keep theirs. */
15
+ error?: ReactNode;
16
+ saveLabel?: string;
17
+ discardLabel?: string;
18
+ submit?: boolean;
19
+ footer?: boolean;
20
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,19 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Button } from "./button.js";
4
+ import { cn } from "./cn.js";
5
+ import { FormError } from "./form-error.js";
6
+ import { useFamilyLabels } from "./labels.js";
7
+ /**
8
+ * Save control, sticky at the bottom while `dirty`. As the last child of FormSections, `footer` makes it
9
+ * the card's footer; otherwise it sits inside its section. `submit` makes Save the form's submit button, so Enter saves.
10
+ */
11
+ export function SaveBar({ dirty, saving = false, canSave = true, onSave, onDiscard, label, error, saveLabel, discardLabel, submit = false, footer = false }) {
12
+ const labels = useFamilyLabels();
13
+ if (!dirty)
14
+ return null;
15
+ const name = label ?? labels.unsaved;
16
+ return (_jsxs("div", { role: "region", "aria-label": name, className: cn("sticky z-10 flex flex-wrap items-center gap-3",
17
+ // The negative margins undo FormSections' padding so the bar spans the card.
18
+ footer ? "bottom-0 -mx-6 -mb-6 rounded-b-xl border-t bg-card px-6 py-4 sm:-mx-8 sm:-mb-8 sm:px-8" : "bottom-4 rounded-lg border bg-muted px-4 py-3"), children: [_jsx("div", { className: "min-w-0 flex-1 text-sm font-medium", children: error ? _jsx(FormError, { children: error }) : name }), _jsx(Button, { type: "button", variant: "ghost", disabled: saving, onClick: onDiscard, children: discardLabel ?? labels.discard }), _jsx(Button, { type: submit ? "submit" : "button", loading: saving, disabled: !canSave, onClick: submit ? undefined : onSave, children: saveLabel ?? labels.save })] }));
19
+ }
@@ -0,0 +1,8 @@
1
+ import type { ReactNode } from "react";
2
+ /** Sticky bar with the count and the bulk actions while rows are ticked; nothing at zero. */
3
+ export declare function SelectionBar({ count, onClear, children, label }: {
4
+ count: number;
5
+ onClear: () => void;
6
+ children?: ReactNode;
7
+ label?: string;
8
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,11 @@
1
+ "use client";
2
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
3
+ import { Button } from "./button.js";
4
+ import { useFamilyLabels } from "./labels.js";
5
+ /** Sticky bar with the count and the bulk actions while rows are ticked; nothing at zero. */
6
+ export function SelectionBar({ count, onClear, children, label }) {
7
+ const labels = useFamilyLabels();
8
+ if (count === 0)
9
+ return null;
10
+ return (_jsxs("div", { role: "region", "aria-label": label ?? labels.selection, className: "sticky bottom-4 z-10 flex flex-wrap items-center gap-2 rounded-xl border bg-card px-4 py-3 shadow-lg", children: [_jsxs("span", { "aria-live": "polite", className: "flex-1 text-sm font-medium", children: [count, " ", count === 1 ? labels.selectedOne : labels.selectedMany] }), _jsx(Button, { variant: "ghost", onClick: onClear, children: labels.clearSelection }), children] }));
11
+ }
@@ -0,0 +1,20 @@
1
+ export interface SessionItem {
2
+ id: string;
3
+ user_agent: string | null;
4
+ ip_address: string | null;
5
+ /** RFC 3339. */
6
+ last_seen_at: string;
7
+ current?: boolean;
8
+ }
9
+ /**
10
+ * The account's sessions: this device first, then the newest; a long list shows five until asked.
11
+ * "Encerrar as outras" asks first. A failed revoke toasts `formatError(error)` (or a generic line).
12
+ */
13
+ export declare function SessionsTable({ items, currentId, onRevoke, onRevokeOthers, formatError }: {
14
+ items: SessionItem[];
15
+ /** The current session, when items do not mark it with `current`. */
16
+ currentId?: string;
17
+ onRevoke: (id: string) => Promise<unknown>;
18
+ onRevokeOthers: () => Promise<unknown>;
19
+ formatError?: (error: unknown) => string;
20
+ }): import("react").JSX.Element;
@@ -0,0 +1,48 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useState } from "react";
4
+ import { Monitor, Smartphone } from "lucide-react";
5
+ import { toast } from "sonner";
6
+ import { Badge } from "./badge.js";
7
+ import { Button } from "./button.js";
8
+ import { Card } from "./card.js";
9
+ import { ConfirmDialog } from "./confirm-dialog.js";
10
+ import { describeDevice } from "./device.js";
11
+ import { formatDateTime, relativeTime } from "./format.js";
12
+ import { useFamilyLabels, useFamilyUI } from "./labels.js";
13
+ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "./table.js";
14
+ const SHOWN = 5;
15
+ /**
16
+ * The account's sessions: this device first, then the newest; a long list shows five until asked.
17
+ * "Encerrar as outras" asks first. A failed revoke toasts `formatError(error)` (or a generic line).
18
+ */
19
+ export function SessionsTable({ items, currentId, onRevoke, onRevokeOthers, formatError }) {
20
+ const labels = useFamilyLabels();
21
+ const { locale } = useFamilyUI();
22
+ const [all, setAll] = useState(false);
23
+ const [confirmOthers, setConfirmOthers] = useState(false);
24
+ const [pending, setPending] = useState(null);
25
+ const isCurrent = (s) => s.current ?? s.id === currentId;
26
+ const sorted = items.slice().sort((a, b) => Number(isCurrent(b)) - Number(isCurrent(a)) || b.last_seen_at.localeCompare(a.last_seen_at));
27
+ const shown = all ? sorted : sorted.slice(0, SHOWN);
28
+ const others = sorted.filter((s) => !isCurrent(s)).length;
29
+ const revoke = async (id) => {
30
+ setPending(id);
31
+ try {
32
+ await onRevoke(id);
33
+ }
34
+ catch (e) {
35
+ toast.error(formatError?.(e) ?? labels.revokeFailed);
36
+ }
37
+ finally {
38
+ setPending(null);
39
+ }
40
+ };
41
+ return (_jsxs("div", { className: "space-y-3", children: [others > 0 && (_jsx("div", { className: "flex justify-end", children: _jsx(Button, { variant: "outline", size: "sm", onClick: () => setConfirmOthers(true), children: labels.revokeOthers }) })), _jsxs(Card, { className: "gap-0 overflow-hidden p-0", children: [_jsxs(Table, { "aria-label": labels.sessions, children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: labels.device }), _jsx(TableHead, { className: "max-sm:hidden", children: labels.ip }), _jsx(TableHead, { children: labels.lastSeen }), _jsx(TableHead, { className: "w-28", children: _jsx("span", { className: "sr-only", children: labels.revoke }) })] }) }), _jsx(TableBody, { children: shown.map((s) => {
42
+ const device = describeDevice(s.user_agent);
43
+ const Icon = device.mobile ? Smartphone : Monitor;
44
+ return (_jsxs(TableRow, { children: [_jsx(TableCell, { className: "w-1/2 max-w-0", children: _jsxs("span", { className: "flex min-w-0 items-center gap-2", children: [_jsx(Icon, { className: "size-4 shrink-0 text-muted-foreground", "aria-hidden": true }), _jsx("span", { className: "truncate font-medium", title: s.user_agent ?? undefined, children: device.label ?? labels.unknownDevice })] }) }), _jsx(TableCell, { className: "font-mono text-xs text-muted-foreground max-sm:hidden", children: s.ip_address ?? "—" }), _jsx(TableCell, { className: "whitespace-normal text-muted-foreground", children: _jsx("time", { dateTime: s.last_seen_at, title: formatDateTime(s.last_seen_at, locale), children: relativeTime(s.last_seen_at, locale) }) }), _jsx(TableCell, { className: "text-right", children: isCurrent(s)
45
+ ? _jsx(Badge, { variant: "secondary", children: labels.thisDevice })
46
+ : _jsx(Button, { variant: "ghost", size: "sm", loading: pending === s.id, disabled: pending !== null, onClick: () => void revoke(s.id), children: labels.revoke }) })] }, s.id));
47
+ }) })] }), sorted.length > SHOWN && (_jsx("div", { className: "border-t px-4 py-2", children: _jsx(Button, { variant: "link", size: "sm", className: "h-auto p-0", "aria-expanded": all, onClick: () => setAll(!all), children: all ? labels.sessionsFewer : labels.sessionsAll.replace("{n}", String(sorted.length)) }) }))] }), _jsx(ConfirmDialog, { open: confirmOthers, onOpenChange: setConfirmOthers, title: labels.revokeOthers, description: labels.revokeOthersDescription, destructive: true, formatError: formatError, onConfirm: async () => { await onRevokeOthers(); } })] }));
48
+ }
@@ -1,2 +1,7 @@
1
1
  declare function Skeleton({ className, ...props }: React.ComponentProps<"div">): import("react").JSX.Element;
2
- export { Skeleton };
2
+ /** Stacked rows standing in for a list while it loads. */
3
+ declare function ListSkeleton({ rows, className }: {
4
+ rows?: number;
5
+ className?: string;
6
+ }): import("react").JSX.Element;
7
+ export { Skeleton, ListSkeleton };
package/dist/skeleton.js CHANGED
@@ -1,6 +1,11 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Card } from "./card.js";
2
3
  import { cn } from "./cn.js";
3
4
  function Skeleton({ className, ...props }) {
4
5
  return (_jsx("div", { "data-slot": "skeleton", className: cn("animate-pulse rounded-md bg-muted", className), ...props }));
5
6
  }
6
- export { Skeleton };
7
+ /** Stacked rows standing in for a list while it loads. */
8
+ function ListSkeleton({ rows = 5, className }) {
9
+ return (_jsx(Card, { "aria-hidden": true, className: cn("gap-0 divide-y p-0", className), children: Array.from({ length: rows }, (_, i) => (_jsx("div", { className: "px-4 py-3", children: _jsx(Skeleton, { className: "h-4 w-1/2" }) }, i))) }));
10
+ }
11
+ export { Skeleton, ListSkeleton };
package/dist/sonner.d.ts CHANGED
@@ -1,3 +1,15 @@
1
1
  import { type ToasterProps } from "sonner";
2
2
  declare const Toaster: ({ ...props }: ToasterProps) => import("react").JSX.Element;
3
- export { Toaster };
3
+ /**
4
+ * Deletes after a short window the user can undo. The caller hides the rows at
5
+ * once; onSettled runs after the delete, whether it worked or not, and after an
6
+ * undo. Closing the tab inside the window keeps the rows.
7
+ */
8
+ declare function deleteWithUndo(opts: {
9
+ message: string;
10
+ undoLabel: string;
11
+ run: () => Promise<void>;
12
+ onError: (err: unknown) => void;
13
+ onSettled: () => void;
14
+ }): void;
15
+ export { Toaster, deleteWithUndo };
package/dist/sonner.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { useFamilyLabels } from "./labels.js";
4
4
  import { useTheme } from "next-themes";
5
- import { Toaster as Sonner } from "sonner";
5
+ import { Toaster as Sonner, toast } from "sonner";
6
6
  import { CircleCheckIcon, InfoIcon, TriangleAlertIcon, OctagonXIcon, Loader2Icon } from "lucide-react";
7
7
  const Toaster = ({ ...props }) => {
8
8
  const { theme = "system" } = useTheme();
@@ -25,4 +25,31 @@ const Toaster = ({ ...props }) => {
25
25
  },
26
26
  }, ...props }));
27
27
  };
28
- export { Toaster };
28
+ const UNDO_MS = 5_000;
29
+ /**
30
+ * Deletes after a short window the user can undo. The caller hides the rows at
31
+ * once; onSettled runs after the delete, whether it worked or not, and after an
32
+ * undo. Closing the tab inside the window keeps the rows.
33
+ */
34
+ function deleteWithUndo(opts) {
35
+ let settled = false;
36
+ const commit = () => {
37
+ if (settled)
38
+ return;
39
+ settled = true;
40
+ opts.run().catch(opts.onError).finally(opts.onSettled);
41
+ };
42
+ toast(opts.message, {
43
+ duration: UNDO_MS,
44
+ action: {
45
+ label: opts.undoLabel,
46
+ onClick: () => {
47
+ settled = true;
48
+ opts.onSettled();
49
+ },
50
+ },
51
+ onAutoClose: commit,
52
+ onDismiss: commit,
53
+ });
54
+ }
55
+ export { Toaster, deleteWithUndo };
@@ -0,0 +1,12 @@
1
+ import { type LucideIcon } from "lucide-react";
2
+ export type SortOrder = "asc" | "desc";
3
+ /** A column header that sorts the list; a new column starts ascending, dates (`*_at`) newest first. */
4
+ export declare function SortHead({ field, label, icon: Icon, sort, order, onSort, className }: {
5
+ field: string;
6
+ label: string;
7
+ icon?: LucideIcon;
8
+ sort: string;
9
+ order: SortOrder;
10
+ onSort: (sort: string, order: SortOrder) => void;
11
+ className?: string;
12
+ }): import("react").JSX.Element;
@@ -0,0 +1,10 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { ArrowDown, ArrowUp } from "lucide-react";
4
+ import { TableHead } from "./table.js";
5
+ /** A column header that sorts the list; a new column starts ascending, dates (`*_at`) newest first. */
6
+ export function SortHead({ field, label, icon: Icon, sort, order, onSort, className }) {
7
+ const active = sort === field;
8
+ const next = active ? (order === "asc" ? "desc" : "asc") : field.endsWith("_at") ? "desc" : "asc";
9
+ return (_jsx(TableHead, { className: className, "aria-sort": active ? (order === "asc" ? "ascending" : "descending") : undefined, children: _jsxs("button", { type: "button", className: "inline-flex items-center gap-1 rounded-sm outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring", onClick: () => onSort(field, next), children: [Icon && _jsx(Icon, { className: "size-3.5 opacity-60", "aria-hidden": true }), label, active && (order === "asc" ? _jsx(ArrowUp, { "aria-hidden": true, className: "size-3.5" }) : _jsx(ArrowDown, { "aria-hidden": true, className: "size-3.5" }))] }) }));
10
+ }
@@ -0,0 +1,8 @@
1
+ import type { ReactNode } from "react";
2
+ export type StatusTone = "success" | "warn" | "danger" | "muted" | "info";
3
+ /** A state as a tinted pill with a dot (active, failed, running…); the product maps its states to tones. */
4
+ export declare function StatusBadge({ tone, children, className }: {
5
+ tone: StatusTone;
6
+ children: ReactNode;
7
+ className?: string;
8
+ }): import("react").JSX.Element;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cn } from "./cn.js";
3
+ const TONE = {
4
+ success: "bg-success/15 text-success",
5
+ warn: "bg-warn/15 text-warn",
6
+ danger: "bg-destructive/15 text-destructive",
7
+ muted: "bg-muted-foreground/15 text-muted-foreground",
8
+ info: "bg-info/15 text-info",
9
+ };
10
+ /** A state as a tinted pill with a dot (active, failed, running…); the product maps its states to tones. */
11
+ export function StatusBadge({ tone, children, className }) {
12
+ return (_jsxs("span", { "data-slot": "status-badge", "data-tone": tone, className: cn("inline-flex items-center gap-1.5 whitespace-nowrap rounded-full px-2 py-0.5 text-xs font-medium", TONE[tone], className), children: [_jsx("span", { "aria-hidden": true, className: "size-1.5 shrink-0 rounded-full bg-current" }), children] }));
13
+ }
@@ -0,0 +1,4 @@
1
+ /** Light/dark switch (next-themes). `onToggle` replaces setTheme, to save the choice to the account. */
2
+ export declare function ThemeToggle({ onToggle }: {
3
+ onToggle?: (theme: "light" | "dark") => void;
4
+ }): import("react").JSX.Element;