@devbie/fewbie-cli 1.9.0 → 1.11.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.
@@ -0,0 +1,74 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/r/registry-item.json",
3
+ "name": "forgot-password",
4
+ "type": "registry:block",
5
+ "title": "Forgot password page",
6
+ "description": "Page-level password reset block: email and verification code plus a new password with a live strength checklist. Transport and navigation come from the host through props.",
7
+ "postInstall": "Render <ForgotPasswordPage labels={...} port={...} /> inside your auth shell. The host supplies translated labels, a sendResetCode/resetPassword port, an optional initialEmail and navigates from onReset/onBack. Requires the shadcn ui primitives button, card, input and label.",
8
+ "x-fewbie.contract": {
9
+ "version": "1.0.0",
10
+ "framework": "^1.7.0",
11
+ "entry": "src/modules/forgot-password/index.ts",
12
+ "labels": [
13
+ "title",
14
+ "description",
15
+ "emailLabel",
16
+ "codeLabel",
17
+ "newPasswordLabel",
18
+ "getCode",
19
+ "resetButton",
20
+ "back",
21
+ "clearEmail",
22
+ "clearCode",
23
+ "clearPassword",
24
+ "showPassword",
25
+ "hidePassword",
26
+ "invalidEmail",
27
+ "emailRequired",
28
+ "codeDigits",
29
+ "codeRequired",
30
+ "passwordRule",
31
+ "passwordRequired",
32
+ "requestFailed",
33
+ "resetFailed",
34
+ "passwordRequirements",
35
+ "passwordRuleLength",
36
+ "passwordRuleLowercase",
37
+ "passwordRuleUppercase",
38
+ "passwordRuleNumber",
39
+ "passwordRuleSymbol"
40
+ ],
41
+ "ports": [
42
+ "sendResetCode",
43
+ "resetPassword"
44
+ ],
45
+ "ui": [
46
+ "button",
47
+ "card",
48
+ "input",
49
+ "label"
50
+ ],
51
+ "states": [
52
+ "loading",
53
+ "error",
54
+ "ready"
55
+ ]
56
+ },
57
+ "files": [
58
+ {
59
+ "path": "src/modules/forgot-password/index.ts",
60
+ "content": "export { ForgotPasswordPage } from \"./forgot-password\";\nexport type {\n ForgotPasswordLabels,\n ForgotPasswordPort,\n ForgotPasswordProps,\n ResetPasswordInput,\n SendResetCodeResult,\n} from \"./types\";\n",
61
+ "type": "registry:block"
62
+ },
63
+ {
64
+ "path": "src/modules/forgot-password/types.ts",
65
+ "content": "import type { ReactNode } from \"react\";\n\n/**\n * Every string the page renders. The host supplies translated copy; the module\n * owns no user-facing text of its own.\n */\nexport interface ForgotPasswordLabels {\n title: string;\n description: string;\n emailLabel: string;\n codeLabel: string;\n newPasswordLabel: string;\n getCode: string;\n resetButton: string;\n back: string;\n clearEmail: string;\n clearCode: string;\n clearPassword: string;\n showPassword: string;\n hidePassword: string;\n invalidEmail: string;\n emailRequired: string;\n codeDigits: string;\n codeRequired: string;\n passwordRule: string;\n passwordRequired: string;\n requestFailed: string;\n resetFailed: string;\n passwordRequirements: string;\n passwordRuleLength: string;\n passwordRuleLowercase: string;\n passwordRuleUppercase: string;\n passwordRuleNumber: string;\n passwordRuleSymbol: string;\n}\n\nexport interface ResetPasswordInput {\n email: string;\n verificationCode: string;\n newPassword: string;\n}\n\nexport interface SendResetCodeResult {\n /** Resend cooldown reported by the backend; defaults to 60 seconds. */\n secondsOfCountdown?: number;\n}\n\n/**\n * Host-owned transport. The module never calls fetch, a router or a toast\n * library: the host decides how to reach its backend and what to do after a\n * successful reset.\n */\nexport interface ForgotPasswordPort {\n sendResetCode(email: string): Promise<SendResetCodeResult>;\n resetPassword(input: ResetPasswordInput): Promise<void>;\n}\n\nexport interface ForgotPasswordProps {\n labels: ForgotPasswordLabels;\n port: ForgotPasswordPort;\n /** Email carried over from the sign-in page, used to seed the form. */\n initialEmail?: string;\n /** Persistent banners, host-styled. */\n notices?: ReactNode;\n /** Called after a verification code was sent; the host may toast. */\n onCodeSent?: () => void;\n /** Called after a successful reset; the host navigates. */\n onReset?: () => void;\n /** Renders the back link when provided; the host navigates. */\n onBack?: () => void;\n}\n",
66
+ "type": "registry:block"
67
+ },
68
+ {
69
+ "path": "src/modules/forgot-password/forgot-password.tsx",
70
+ "content": "\"use client\";\n\nimport { useEffect, useState, type FormEvent } from \"react\";\n\nimport { Button } from \"@/components/ui/button\";\nimport { Card, CardContent, CardDescription, CardHeader, CardTitle } from \"@/components/ui/card\";\nimport { Input } from \"@/components/ui/input\";\nimport { Label } from \"@/components/ui/label\";\nimport type { ForgotPasswordLabels, ForgotPasswordProps } from \"./types\";\n\nconst EMAIL_PATTERN = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\nconst CODE_LENGTH = 6;\nconst DEFAULT_RESEND_SECONDS = 60;\nconst PASSWORD_PATTERN = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[^\\w\\s]).{8,}$/;\n\nfunction Spinner() {\n return (\n <span\n aria-hidden=\"true\"\n className=\"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent\"\n />\n );\n}\n\nfunction ClearIcon() {\n return (\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n className=\"h-4 w-4\"\n >\n <path d=\"M18 6 6 18M6 6l12 12\" />\n </svg>\n );\n}\n\nfunction EyeIcon() {\n return (\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"h-4 w-4\"\n >\n <path d=\"M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12Z\" />\n <circle cx=\"12\" cy=\"12\" r=\"3\" />\n </svg>\n );\n}\n\nfunction EyeOffIcon() {\n return (\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"h-4 w-4\"\n >\n <path d=\"M3 3l18 18\" />\n <path d=\"M10.6 10.6a3 3 0 0 0 4.2 4.2\" />\n <path d=\"M9.9 5.2A10.9 10.9 0 0 1 12 5c6.5 0 10 7 10 7a17.6 17.6 0 0 1-3.2 4.1\" />\n <path d=\"M6.2 6.2A17.4 17.4 0 0 0 2 12s3.5 7 10 7a10.6 10.6 0 0 0 4.2-.9\" />\n </svg>\n );\n}\n\nfunction CheckIcon() {\n return (\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"h-3.5 w-3.5\"\n >\n <path d=\"M20 6 9 17l-5-5\" />\n </svg>\n );\n}\n\nfunction PasswordChecklist({ password, labels }: { password: string; labels: ForgotPasswordLabels }) {\n // Show nothing until the user starts typing, to keep the form calm.\n if (!password) return null;\n\n const rules = [\n { key: \"length\", label: labels.passwordRuleLength, met: password.length >= 8 },\n { key: \"lowercase\", label: labels.passwordRuleLowercase, met: /[a-z]/.test(password) },\n { key: \"uppercase\", label: labels.passwordRuleUppercase, met: /[A-Z]/.test(password) },\n { key: \"number\", label: labels.passwordRuleNumber, met: /\\d/.test(password) },\n { key: \"symbol\", label: labels.passwordRuleSymbol, met: /[^\\w\\s]/.test(password) },\n ];\n\n return (\n <ul className=\"space-y-1.5 rounded-md border bg-muted/40 p-3\" aria-label={labels.passwordRequirements}>\n {rules.map((rule) => (\n <li\n key={rule.key}\n className={`flex items-center gap-2 text-xs ${\n rule.met ? \"text-green-600 dark:text-green-500\" : \"text-muted-foreground\"\n }`}\n >\n {rule.met ? <CheckIcon /> : <ClearIcon />}\n {rule.label}\n </li>\n ))}\n </ul>\n );\n}\n\n/**\n * Page-level password reset module: email plus verification code plus a new\n * password, with a live strength checklist. Transport, navigation and toasts\n * belong to the host and enter through `port` and the `on*` callbacks.\n */\nexport function ForgotPasswordPage({\n labels,\n port,\n initialEmail = \"\",\n notices,\n onCodeSent,\n onReset,\n onBack,\n}: ForgotPasswordProps) {\n const [email, setEmail] = useState(initialEmail);\n const [code, setCode] = useState(\"\");\n const [newPassword, setNewPassword] = useState(\"\");\n const [showPassword, setShowPassword] = useState(false);\n // Seconds left before the user can request another verification code.\n const [secondsLeft, setSecondsLeft] = useState(0);\n const [sendPending, setSendPending] = useState(false);\n const [resetPending, setResetPending] = useState(false);\n const [errors, setErrors] = useState<{ email?: string; code?: string; newPassword?: string }>({});\n const [error, setError] = useState<string | null>(null);\n\n const isCountingDown = secondsLeft > 0;\n\n // Countdown timer for resending the verification code.\n useEffect(() => {\n if (!isCountingDown) return;\n const timer = setInterval(() => setSecondsLeft((prev) => Math.max(0, prev - 1)), 1000);\n return () => clearInterval(timer);\n }, [isCountingDown]);\n\n function validateEmail(value: string): string | undefined {\n if (!value.trim()) return labels.emailRequired;\n if (!EMAIL_PATTERN.test(value)) return labels.invalidEmail;\n return undefined;\n }\n\n async function handleGetCode(): Promise<void> {\n if (secondsLeft > 0 || sendPending) return;\n const emailError = validateEmail(email);\n setErrors((prev) => ({ ...prev, email: emailError }));\n if (emailError) return;\n\n setSendPending(true);\n setError(null);\n try {\n const result = await port.sendResetCode(email);\n // Follow the resend cooldown returned by the backend.\n setSecondsLeft(result.secondsOfCountdown ?? DEFAULT_RESEND_SECONDS);\n onCodeSent?.();\n } catch {\n setError(labels.requestFailed);\n } finally {\n setSendPending(false);\n }\n }\n\n async function handleSubmit(event: FormEvent<HTMLFormElement>): Promise<void> {\n event.preventDefault();\n if (resetPending) return;\n\n const nextErrors = {\n email: validateEmail(email),\n code: !code ? labels.codeRequired : code.length !== CODE_LENGTH ? labels.codeDigits : undefined,\n newPassword: !newPassword\n ? labels.passwordRequired\n : PASSWORD_PATTERN.test(newPassword)\n ? undefined\n : labels.passwordRule,\n };\n setErrors(nextErrors);\n if (nextErrors.email || nextErrors.code || nextErrors.newPassword) return;\n\n setResetPending(true);\n setError(null);\n try {\n await port.resetPassword({ email, verificationCode: code, newPassword });\n onReset?.();\n } catch {\n setError(labels.resetFailed);\n } finally {\n setResetPending(false);\n }\n }\n\n return (\n <Card className=\"w-full shadow-sm\">\n <CardHeader>\n <CardTitle className=\"text-xl\">{labels.title}</CardTitle>\n <CardDescription>{labels.description}</CardDescription>\n </CardHeader>\n <CardContent>\n {notices}\n\n {/* method=\"post\" keeps a native submit (before hydration) from\n serializing the new password into the query string. */}\n <form method=\"post\" onSubmit={(event) => void handleSubmit(event)} noValidate className=\"space-y-5\">\n <div className=\"space-y-2\">\n <Label htmlFor=\"forgot-password-email\">{labels.emailLabel}</Label>\n <div className=\"relative\">\n <Input\n id=\"forgot-password-email\"\n autoComplete=\"email\"\n value={email}\n onChange={(event) => setEmail(event.target.value)}\n className=\"pr-10\"\n />\n {email && (\n <button\n type=\"button\"\n onClick={() => setEmail(\"\")}\n className=\"absolute top-1/2 right-2 -translate-y-1/2 text-muted-foreground hover:text-foreground\"\n aria-label={labels.clearEmail}\n >\n <ClearIcon />\n </button>\n )}\n </div>\n {errors.email && <p className=\"text-sm text-destructive\">{errors.email}</p>}\n </div>\n\n <div className=\"space-y-2\">\n <Label htmlFor=\"forgot-password-code\">{labels.codeLabel}</Label>\n <div className=\"relative\">\n <Input\n id=\"forgot-password-code\"\n inputMode=\"numeric\"\n autoComplete=\"one-time-code\"\n value={code}\n onChange={(event) => setCode(event.target.value.replace(/\\D/g, \"\").slice(0, CODE_LENGTH))}\n className=\"pr-32\"\n />\n <div className=\"absolute top-1/2 right-2 flex -translate-y-1/2 items-center gap-2\">\n {code && (\n <button\n type=\"button\"\n onClick={() => setCode(\"\")}\n className=\"text-muted-foreground hover:text-foreground\"\n aria-label={labels.clearCode}\n >\n <ClearIcon />\n </button>\n )}\n <Button\n type=\"button\"\n variant=\"link\"\n size=\"sm\"\n className=\"h-auto p-0 text-xs font-normal\"\n onClick={() => void handleGetCode()}\n disabled={secondsLeft > 0 || sendPending}\n >\n {sendPending ? <Spinner /> : secondsLeft > 0 ? `${secondsLeft}s` : labels.getCode}\n </Button>\n </div>\n </div>\n {errors.code && <p className=\"text-sm text-destructive\">{errors.code}</p>}\n </div>\n\n <div className=\"space-y-2\">\n <Label htmlFor=\"forgot-password-new-password\">{labels.newPasswordLabel}</Label>\n <div className=\"relative\">\n <Input\n id=\"forgot-password-new-password\"\n type={showPassword ? \"text\" : \"password\"}\n autoComplete=\"new-password\"\n value={newPassword}\n onChange={(event) => setNewPassword(event.target.value)}\n className=\"pr-20\"\n />\n <div className=\"absolute top-1/2 right-2 flex -translate-y-1/2 items-center gap-1\">\n {newPassword && (\n <button\n type=\"button\"\n onClick={() => setNewPassword(\"\")}\n className=\"text-muted-foreground hover:text-foreground\"\n aria-label={labels.clearPassword}\n >\n <ClearIcon />\n </button>\n )}\n <button\n type=\"button\"\n onClick={() => setShowPassword((prev) => !prev)}\n className=\"text-muted-foreground hover:text-foreground\"\n aria-label={showPassword ? labels.hidePassword : labels.showPassword}\n >\n {showPassword ? <EyeOffIcon /> : <EyeIcon />}\n </button>\n </div>\n </div>\n <PasswordChecklist password={newPassword} labels={labels} />\n {errors.newPassword && <p className=\"text-sm text-destructive\">{errors.newPassword}</p>}\n </div>\n\n {error && <p className=\"text-sm text-destructive\">{error}</p>}\n\n {onBack && (\n <div className=\"flex justify-end\">\n <Button\n type=\"button\"\n variant=\"link\"\n size=\"sm\"\n className=\"h-auto p-0 text-xs font-normal\"\n onClick={onBack}\n >\n {labels.back}\n </Button>\n </div>\n )}\n\n <Button type=\"submit\" className=\"w-full\" disabled={resetPending}>\n {resetPending ? <Spinner /> : labels.resetButton}\n </Button>\n </form>\n </CardContent>\n </Card>\n );\n}\n",
71
+ "type": "registry:block"
72
+ }
73
+ ]
74
+ }
@@ -0,0 +1,50 @@
1
+ {
2
+ "version": "1.0.0",
3
+ "framework": "^1.7.0",
4
+ "entry": "src/modules/login-page/index.ts",
5
+ "labels": [
6
+ "title",
7
+ "description",
8
+ "tabPassword",
9
+ "tabVerificationCode",
10
+ "email",
11
+ "password",
12
+ "submit",
13
+ "verificationCode",
14
+ "getCode",
15
+ "orContinueWith",
16
+ "back",
17
+ "clearEmail",
18
+ "clearPassword",
19
+ "hidePassword",
20
+ "showPassword",
21
+ "clearCode",
22
+ "invalidEmail",
23
+ "emailRequired",
24
+ "passwordMin",
25
+ "passwordRequired",
26
+ "codeDigits",
27
+ "codeRequired",
28
+ "invalidCredentials",
29
+ "loginFailed",
30
+ "totpLabel",
31
+ "totpHint",
32
+ "totpSubmit"
33
+ ],
34
+ "ports": [
35
+ "signIn",
36
+ "sendVerificationCode"
37
+ ],
38
+ "ui": [
39
+ "button",
40
+ "card",
41
+ "input",
42
+ "label",
43
+ "tabs"
44
+ ],
45
+ "states": [
46
+ "loading",
47
+ "error",
48
+ "ready"
49
+ ]
50
+ }
@@ -0,0 +1,75 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/r/registry-item.json",
3
+ "name": "login-page",
4
+ "type": "registry:block",
5
+ "title": "Login page",
6
+ "description": "Page-level login block: password and verification-code tabs, inline TOTP challenge and third-party provider entries. Transport, navigation and copy come from the host through props.",
7
+ "postInstall": "Render <LoginPage labels={...} port={...} /> inside your auth shell. The host supplies translated labels, a signIn/sendVerificationCode port, optional notices and oauthProviders, and navigates from onSignedIn. Requires the shadcn ui primitives button, card, input, label and tabs.",
8
+ "x-fewbie.contract": {
9
+ "version": "1.0.0",
10
+ "framework": "^1.7.0",
11
+ "entry": "src/modules/login-page/index.ts",
12
+ "labels": [
13
+ "title",
14
+ "description",
15
+ "tabPassword",
16
+ "tabVerificationCode",
17
+ "email",
18
+ "password",
19
+ "submit",
20
+ "verificationCode",
21
+ "getCode",
22
+ "orContinueWith",
23
+ "back",
24
+ "clearEmail",
25
+ "clearPassword",
26
+ "hidePassword",
27
+ "showPassword",
28
+ "clearCode",
29
+ "invalidEmail",
30
+ "emailRequired",
31
+ "passwordMin",
32
+ "passwordRequired",
33
+ "codeDigits",
34
+ "codeRequired",
35
+ "invalidCredentials",
36
+ "loginFailed",
37
+ "totpLabel",
38
+ "totpHint",
39
+ "totpSubmit"
40
+ ],
41
+ "ports": [
42
+ "signIn",
43
+ "sendVerificationCode"
44
+ ],
45
+ "ui": [
46
+ "button",
47
+ "card",
48
+ "input",
49
+ "label",
50
+ "tabs"
51
+ ],
52
+ "states": [
53
+ "loading",
54
+ "error",
55
+ "ready"
56
+ ]
57
+ },
58
+ "files": [
59
+ {
60
+ "path": "src/modules/login-page/index.ts",
61
+ "content": "export { LoginPage } from \"./login-page\";\nexport type {\n LoginCredentials,\n LoginLabels,\n LoginOAuthProvider,\n LoginPageProps,\n LoginPort,\n LoginResult,\n LoginTotpChallenge,\n LoginVerificationCode,\n VerificationCodeResult,\n} from \"./types\";\n",
62
+ "type": "registry:block"
63
+ },
64
+ {
65
+ "path": "src/modules/login-page/types.ts",
66
+ "content": "import type { ReactNode } from \"react\";\n\n/**\n * Every string the page renders. The host supplies translated copy; the module\n * owns no user-facing text of its own, so a host that follows the fewbie\n * i18n rule (display copy lives in the host message files) stays compliant.\n */\nexport interface LoginLabels {\n title: string;\n description: string;\n tabPassword: string;\n tabVerificationCode: string;\n email: string;\n password: string;\n submit: string;\n verificationCode: string;\n getCode: string;\n orContinueWith: string;\n back: string;\n clearEmail: string;\n clearPassword: string;\n hidePassword: string;\n showPassword: string;\n clearCode: string;\n invalidEmail: string;\n emailRequired: string;\n passwordMin: string;\n passwordRequired: string;\n codeDigits: string;\n codeRequired: string;\n invalidCredentials: string;\n loginFailed: string;\n totpLabel: string;\n totpHint: string;\n totpSubmit: string;\n}\n\n/** One third-party sign-in entry; the host owns the URL and the brand mark. */\nexport interface LoginOAuthProvider {\n /** Stable key for React, e.g. \"google\". */\n id: string;\n label: string;\n /** Absolute URL of the provider's backend entry point. */\n href: string;\n icon?: ReactNode;\n}\n\nexport interface LoginCredentials {\n account: string;\n password: string;\n}\n\nexport interface LoginVerificationCode {\n account: string;\n verificationCode: string;\n}\n\n/** Second factor for a sign-in the backend already accepted. */\nexport interface LoginTotpChallenge {\n totpToken: string;\n code: string;\n}\n\nexport interface LoginResult {\n /** True only when a session was established. */\n ok: boolean;\n /** The backend rejected the credentials (as opposed to a transport error). */\n invalidCredentials?: boolean;\n /** A second factor is still required; the page renders the authenticator form. */\n multiFactorRequired?: boolean;\n totpToken?: string;\n}\n\nexport interface VerificationCodeResult {\n ok: boolean;\n /** Resend cooldown reported by the backend; defaults to 60 seconds. */\n secondsOfCountdown?: number;\n}\n\n/**\n * Host-owned transport and side effects. The module never calls fetch or the\n * router: the host decides how to reach its backend and where to navigate.\n */\nexport interface LoginPort {\n signIn(input: LoginCredentials | LoginVerificationCode | LoginTotpChallenge): Promise<LoginResult>;\n sendVerificationCode(email: string): Promise<VerificationCodeResult>;\n}\n\nexport interface LoginPageProps {\n labels: LoginLabels;\n port: LoginPort;\n /** Persistent banners (pending approval, disabled account, ...), host-styled. */\n notices?: ReactNode;\n /** Third-party providers; the divider is hidden when empty. */\n oauthProviders?: LoginOAuthProvider[];\n /** Called after a successful sign-in; the host navigates. */\n onSignedIn?: () => void;\n /** Called after a verification code was sent; the host may toast. */\n onCodeSent?: () => void;\n}\n",
67
+ "type": "registry:block"
68
+ },
69
+ {
70
+ "path": "src/modules/login-page/login-page.tsx",
71
+ "content": "\"use client\";\n\nimport { useEffect, useState, type FormEvent } from \"react\";\n\nimport { Button } from \"@/components/ui/button\";\nimport { Card, CardContent, CardDescription, CardHeader, CardTitle } from \"@/components/ui/card\";\nimport { Input } from \"@/components/ui/input\";\nimport { Label } from \"@/components/ui/label\";\nimport { Tabs, TabsList, TabsTrigger } from \"@/components/ui/tabs\";\nimport type { LoginLabels, LoginPageProps, LoginResult } from \"./types\";\n\ntype LoginMode = \"password\" | \"code\";\n\nconst EMAIL_PATTERN = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\nconst CODE_LENGTH = 6;\nconst DEFAULT_RESEND_SECONDS = 60;\n\nfunction Spinner() {\n return (\n <span\n aria-hidden=\"true\"\n className=\"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent\"\n />\n );\n}\n\nfunction ClearIcon() {\n return (\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n className=\"h-4 w-4\"\n >\n <path d=\"M18 6 6 18M6 6l12 12\" />\n </svg>\n );\n}\n\nfunction EyeIcon() {\n return (\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"h-4 w-4\"\n >\n <path d=\"M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12Z\" />\n <circle cx=\"12\" cy=\"12\" r=\"3\" />\n </svg>\n );\n}\n\nfunction EyeOffIcon() {\n return (\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"h-4 w-4\"\n >\n <path d=\"M3 3l18 18\" />\n <path d=\"M10.6 10.6a3 3 0 0 0 4.2 4.2\" />\n <path d=\"M9.9 5.2A10.9 10.9 0 0 1 12 5c6.5 0 10 7 10 7a17.6 17.6 0 0 1-3.2 4.1\" />\n <path d=\"M6.2 6.2A17.4 17.4 0 0 0 2 12s3.5 7 10 7a10.6 10.6 0 0 0 4.2-.9\" />\n </svg>\n );\n}\n\n/**\n * Page-level login module: password and verification-code tabs, an inline TOTP\n * challenge, and third-party entries. Transport, navigation, toasts and brand\n * shell belong to the host and enter through `port`, `oauthProviders` and the\n * `onSignedIn`/`onCodeSent` callbacks.\n */\nexport function LoginPage({ labels, port, notices, oauthProviders, onSignedIn, onCodeSent }: LoginPageProps) {\n const [mode, setMode] = useState<LoginMode>(\"password\");\n const [showPassword, setShowPassword] = useState(false);\n // Seconds left before the user can request another verification code.\n const [secondsLeft, setSecondsLeft] = useState(0);\n // When set, the primary factor was accepted and the user must finish login\n // with a TOTP code from their authenticator app.\n const [mfaToken, setMfaToken] = useState<string | null>(null);\n const [error, setError] = useState<string | null>(null);\n\n const [passwordEmail, setPasswordEmail] = useState(\"\");\n const [password, setPasswordValue] = useState(\"\");\n const [passwordErrors, setPasswordErrors] = useState<{ email?: string; password?: string }>({});\n\n const [codeEmail, setCodeEmail] = useState(\"\");\n const [code, setCode] = useState(\"\");\n const [codeErrors, setCodeErrors] = useState<{ email?: string; code?: string }>({});\n\n const [pending, setPending] = useState(false);\n const [sendPending, setSendPending] = useState(false);\n\n const isCountingDown = secondsLeft > 0;\n\n // Countdown timer for resending the verification code.\n useEffect(() => {\n if (!isCountingDown) return;\n const timer = setInterval(() => setSecondsLeft((prev) => Math.max(0, prev - 1)), 1000);\n return () => clearInterval(timer);\n }, [isCountingDown]);\n\n function complete(result: LoginResult): void {\n if (result.multiFactorRequired && result.totpToken) {\n setMfaToken(result.totpToken);\n return;\n }\n if (!result.ok) {\n setError(result.invalidCredentials ? labels.invalidCredentials : labels.loginFailed);\n return;\n }\n onSignedIn?.();\n }\n\n async function submit(input: Parameters<LoginPageProps[\"port\"][\"signIn\"]>[0]): Promise<void> {\n setPending(true);\n setError(null);\n try {\n complete(await port.signIn(input));\n } catch {\n setError(labels.loginFailed);\n } finally {\n setPending(false);\n }\n }\n\n function validateEmail(value: string): string | undefined {\n if (!value.trim()) return labels.emailRequired;\n if (!EMAIL_PATTERN.test(value)) return labels.invalidEmail;\n return undefined;\n }\n\n function onPasswordSubmit(event: FormEvent<HTMLFormElement>): void {\n event.preventDefault();\n const nextErrors = {\n email: validateEmail(passwordEmail),\n password: !password ? labels.passwordRequired : password.length < 8 ? labels.passwordMin : undefined,\n };\n setPasswordErrors(nextErrors);\n if (nextErrors.email || nextErrors.password) return;\n void submit({ account: passwordEmail, password });\n }\n\n function onCodeSubmit(event: FormEvent<HTMLFormElement>): void {\n event.preventDefault();\n const nextErrors = {\n email: validateEmail(codeEmail),\n code: !code ? labels.codeRequired : code.length !== CODE_LENGTH ? labels.codeDigits : undefined,\n };\n setCodeErrors(nextErrors);\n if (nextErrors.email || nextErrors.code) return;\n void submit({ account: codeEmail, verificationCode: code });\n }\n\n async function handleSendCode(): Promise<void> {\n if (secondsLeft > 0 || sendPending) return;\n const emailError = validateEmail(codeEmail);\n setCodeErrors((prev) => ({ ...prev, email: emailError }));\n if (emailError) return;\n\n setSendPending(true);\n try {\n const result = await port.sendVerificationCode(codeEmail);\n if (!result.ok) {\n setError(labels.loginFailed);\n return;\n }\n // Follow the resend cooldown returned by the backend.\n setSecondsLeft(result.secondsOfCountdown ?? DEFAULT_RESEND_SECONDS);\n onCodeSent?.();\n } catch {\n setError(labels.loginFailed);\n } finally {\n setSendPending(false);\n }\n }\n\n // Switch login mode while carrying the typed email between the two forms.\n function handleModeChange(value: LoginMode): void {\n if (value === \"code\") {\n if (passwordEmail) setCodeEmail(passwordEmail);\n } else if (codeEmail) {\n setPasswordEmail(codeEmail);\n }\n setError(null);\n setMode(value);\n }\n\n const showOAuth = (oauthProviders?.length ?? 0) > 0;\n\n return (\n <Card className=\"w-full shadow-sm\">\n <CardHeader>\n <CardTitle className=\"text-xl\">{labels.title}</CardTitle>\n <CardDescription>{labels.description}</CardDescription>\n </CardHeader>\n <CardContent>\n {notices}\n\n <Tabs value={mode} onValueChange={(value) => handleModeChange(value as LoginMode)} className=\"mb-6\">\n <TabsList className=\"w-full\">\n <TabsTrigger value=\"password\">{labels.tabPassword}</TabsTrigger>\n <TabsTrigger value=\"code\">{labels.tabVerificationCode}</TabsTrigger>\n </TabsList>\n </Tabs>\n\n {/* MFA challenge — primary factor accepted, TOTP code still required */}\n {mfaToken && (\n <TotpChallenge\n labels={labels}\n isPending={pending}\n onSubmit={(totpCode) => void submit({ totpToken: mfaToken, code: totpCode })}\n onBack={() => {\n setError(null);\n setMfaToken(null);\n }}\n />\n )}\n\n {/* Password login form. method=\"post\" keeps a native submit (before\n hydration) from serializing credentials into the query string. */}\n {mode === \"password\" && !mfaToken && (\n <form method=\"post\" onSubmit={onPasswordSubmit} noValidate className=\"space-y-5\">\n <div className=\"space-y-2\">\n <Label htmlFor=\"login-page-email\">{labels.email}</Label>\n <div className=\"relative\">\n <Input\n id=\"login-page-email\"\n autoComplete=\"email\"\n value={passwordEmail}\n onChange={(event) => setPasswordEmail(event.target.value)}\n className=\"pr-10\"\n />\n {passwordEmail && (\n <button\n type=\"button\"\n onClick={() => setPasswordEmail(\"\")}\n className=\"absolute top-1/2 right-2 -translate-y-1/2 text-muted-foreground hover:text-foreground\"\n aria-label={labels.clearEmail}\n >\n <ClearIcon />\n </button>\n )}\n </div>\n {passwordErrors.email && <p className=\"text-sm text-destructive\">{passwordErrors.email}</p>}\n </div>\n\n <div className=\"space-y-2\">\n <Label htmlFor=\"login-page-password\">{labels.password}</Label>\n <div className=\"relative\">\n <Input\n id=\"login-page-password\"\n type={showPassword ? \"text\" : \"password\"}\n autoComplete=\"current-password\"\n value={password}\n onChange={(event) => setPasswordValue(event.target.value)}\n className=\"pr-20\"\n />\n <div className=\"absolute top-1/2 right-2 flex -translate-y-1/2 items-center gap-1\">\n {password && (\n <button\n type=\"button\"\n onClick={() => setPasswordValue(\"\")}\n className=\"text-muted-foreground hover:text-foreground\"\n aria-label={labels.clearPassword}\n >\n <ClearIcon />\n </button>\n )}\n <button\n type=\"button\"\n onClick={() => setShowPassword((prev) => !prev)}\n className=\"text-muted-foreground hover:text-foreground\"\n aria-label={showPassword ? labels.hidePassword : labels.showPassword}\n >\n {showPassword ? <EyeOffIcon /> : <EyeIcon />}\n </button>\n </div>\n </div>\n {passwordErrors.password && <p className=\"text-sm text-destructive\">{passwordErrors.password}</p>}\n </div>\n\n {error && <p className=\"text-sm text-destructive\">{error}</p>}\n\n <Button type=\"submit\" className=\"w-full\" disabled={pending}>\n {pending ? <Spinner /> : labels.submit}\n </Button>\n </form>\n )}\n\n {/* Verification code login form */}\n {mode === \"code\" && !mfaToken && (\n <form method=\"post\" onSubmit={onCodeSubmit} noValidate className=\"space-y-5\">\n <div className=\"space-y-2\">\n <Label htmlFor=\"login-page-code-email\">{labels.email}</Label>\n <div className=\"relative\">\n <Input\n id=\"login-page-code-email\"\n autoComplete=\"email\"\n value={codeEmail}\n onChange={(event) => setCodeEmail(event.target.value)}\n className=\"pr-10\"\n />\n {codeEmail && (\n <button\n type=\"button\"\n onClick={() => setCodeEmail(\"\")}\n className=\"absolute top-1/2 right-2 -translate-y-1/2 text-muted-foreground hover:text-foreground\"\n aria-label={labels.clearEmail}\n >\n <ClearIcon />\n </button>\n )}\n </div>\n {codeErrors.email && <p className=\"text-sm text-destructive\">{codeErrors.email}</p>}\n </div>\n\n <div className=\"space-y-2\">\n <Label htmlFor=\"login-page-code\">{labels.verificationCode}</Label>\n <div className=\"relative\">\n <Input\n id=\"login-page-code\"\n inputMode=\"numeric\"\n autoComplete=\"one-time-code\"\n value={code}\n onChange={(event) => setCode(event.target.value.replace(/\\D/g, \"\").slice(0, CODE_LENGTH))}\n className=\"pr-32\"\n />\n <div className=\"absolute top-1/2 right-2 flex -translate-y-1/2 items-center gap-2\">\n {code && (\n <button\n type=\"button\"\n onClick={() => setCode(\"\")}\n className=\"text-muted-foreground hover:text-foreground\"\n aria-label={labels.clearCode}\n >\n <ClearIcon />\n </button>\n )}\n <Button\n type=\"button\"\n variant=\"link\"\n size=\"sm\"\n className=\"h-auto p-0 text-xs font-normal\"\n onClick={() => void handleSendCode()}\n disabled={secondsLeft > 0 || sendPending}\n >\n {sendPending ? <Spinner /> : secondsLeft > 0 ? `${secondsLeft}s` : labels.getCode}\n </Button>\n </div>\n </div>\n {codeErrors.code && <p className=\"text-sm text-destructive\">{codeErrors.code}</p>}\n </div>\n\n {error && <p className=\"text-sm text-destructive\">{error}</p>}\n\n <Button type=\"submit\" className=\"w-full\" disabled={pending}>\n {pending ? <Spinner /> : labels.submit}\n </Button>\n </form>\n )}\n\n {/* Third-party entries */}\n {showOAuth && (\n <div className=\"mt-6\">\n <div className=\"relative mb-4\">\n <div className=\"absolute inset-0 flex items-center\">\n <span className=\"w-full border-t\" />\n </div>\n <div className=\"relative flex justify-center text-xs uppercase\">\n <span className=\"bg-card px-2 text-muted-foreground\">{labels.orContinueWith}</span>\n </div>\n </div>\n {oauthProviders?.map((provider, index) => (\n <Button key={provider.id} asChild variant=\"outline\" className={index === 0 ? \"w-full\" : \"mt-3 w-full\"}>\n <a href={provider.href}>\n {provider.icon && <span className=\"mr-2 inline-flex items-center\">{provider.icon}</span>}\n {provider.label}\n </a>\n </Button>\n ))}\n </div>\n )}\n </CardContent>\n </Card>\n );\n}\n\ninterface TotpChallengeProps {\n labels: LoginLabels;\n isPending: boolean;\n onSubmit: (code: string) => void;\n onBack: () => void;\n}\n\nfunction TotpChallenge({ labels, isPending, onSubmit, onBack }: TotpChallengeProps) {\n const [totpCode, setTotpCode] = useState(\"\");\n\n return (\n <form\n method=\"post\"\n onSubmit={(event) => {\n event.preventDefault();\n if (totpCode.length === CODE_LENGTH) onSubmit(totpCode);\n }}\n noValidate\n className=\"space-y-5\"\n >\n <div className=\"space-y-2\">\n <Label htmlFor=\"login-page-totp\">{labels.totpLabel}</Label>\n <Input\n id=\"login-page-totp\"\n inputMode=\"numeric\"\n autoComplete=\"one-time-code\"\n value={totpCode}\n onChange={(event) => setTotpCode(event.target.value.replace(/\\D/g, \"\").slice(0, CODE_LENGTH))}\n placeholder=\"123456\"\n autoFocus\n />\n <p className=\"text-xs text-muted-foreground\">{labels.totpHint}</p>\n </div>\n\n <Button type=\"submit\" className=\"w-full\" disabled={isPending || totpCode.length !== CODE_LENGTH}>\n {isPending ? <Spinner /> : labels.totpSubmit}\n </Button>\n <Button type=\"button\" variant=\"link\" size=\"sm\" className=\"w-full\" onClick={onBack}>\n {labels.back}\n </Button>\n </form>\n );\n}\n",
72
+ "type": "registry:block"
73
+ }
74
+ ]
75
+ }
@@ -0,0 +1,37 @@
1
+ {
2
+ "version": "1.0.0",
3
+ "framework": "^1.7.0",
4
+ "entry": "src/modules/preferences-settings/index.ts",
5
+ "labels": [
6
+ "languageTitle",
7
+ "languageDesc",
8
+ "themeTitle",
9
+ "themeDesc",
10
+ "themeLight",
11
+ "themeDark",
12
+ "themeSystem",
13
+ "timezoneTitle",
14
+ "timezoneDesc",
15
+ "timezonePlaceholder",
16
+ "useBrowserTimezone",
17
+ "saveTimezone",
18
+ "updateFailed"
19
+ ],
20
+ "ports": [
21
+ "saveLanguage",
22
+ "saveTheme",
23
+ "saveTimezone"
24
+ ],
25
+ "ui": [
26
+ "button",
27
+ "card",
28
+ "input",
29
+ "label",
30
+ "select"
31
+ ],
32
+ "states": [
33
+ "loading",
34
+ "error",
35
+ "ready"
36
+ ]
37
+ }
@@ -0,0 +1,62 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/r/registry-item.json",
3
+ "name": "preferences-settings",
4
+ "type": "registry:block",
5
+ "title": "Preferences settings cards",
6
+ "description": "Account display preferences: interface language, theme and timezone. Persistence and the side effects of each change (locale cookie, theme class, cache refresh) stay in the host.",
7
+ "postInstall": "Render <PreferencesSettings labels={...} values={...} languages={...} port={...} /> inside your settings shell. The host supplies translated labels and language options, a saveLanguage/saveTheme/saveTimezone port, and applies the changed preference from the on* callbacks. Requires the shadcn ui primitives button, card, input, label and select.",
8
+ "x-fewbie.contract": {
9
+ "version": "1.0.0",
10
+ "framework": "^1.7.0",
11
+ "entry": "src/modules/preferences-settings/index.ts",
12
+ "labels": [
13
+ "languageTitle",
14
+ "languageDesc",
15
+ "themeTitle",
16
+ "themeDesc",
17
+ "themeLight",
18
+ "themeDark",
19
+ "themeSystem",
20
+ "timezoneTitle",
21
+ "timezoneDesc",
22
+ "timezonePlaceholder",
23
+ "useBrowserTimezone",
24
+ "saveTimezone",
25
+ "updateFailed"
26
+ ],
27
+ "ports": [
28
+ "saveLanguage",
29
+ "saveTheme",
30
+ "saveTimezone"
31
+ ],
32
+ "ui": [
33
+ "button",
34
+ "card",
35
+ "input",
36
+ "label",
37
+ "select"
38
+ ],
39
+ "states": [
40
+ "loading",
41
+ "error",
42
+ "ready"
43
+ ]
44
+ },
45
+ "files": [
46
+ {
47
+ "path": "src/modules/preferences-settings/index.ts",
48
+ "content": "export { PreferencesSettings } from \"./preferences-settings\";\nexport type {\n PreferencesLanguageOption,\n PreferencesSettingsLabels,\n PreferencesSettingsPort,\n PreferencesSettingsProps,\n PreferencesSettingsValues,\n ThemePreferenceValue,\n} from \"./types\";\n",
49
+ "type": "registry:block"
50
+ },
51
+ {
52
+ "path": "src/modules/preferences-settings/types.ts",
53
+ "content": "export type ThemePreferenceValue = \"LIGHT\" | \"DARK\" | \"SYSTEM\";\n\nexport interface PreferencesLanguageOption {\n value: string;\n label: string;\n}\n\n/**\n * Every string the cards render. The host supplies translated copy, including\n * the labels of the language options it passes in.\n */\nexport interface PreferencesSettingsLabels {\n languageTitle: string;\n languageDesc: string;\n themeTitle: string;\n themeDesc: string;\n themeLight: string;\n themeDark: string;\n themeSystem: string;\n timezoneTitle: string;\n timezoneDesc: string;\n timezonePlaceholder: string;\n useBrowserTimezone: string;\n saveTimezone: string;\n updateFailed: string;\n}\n\nexport interface PreferencesSettingsValues {\n language: string;\n theme: ThemePreferenceValue;\n timezone: string;\n}\n\n/**\n * Host-owned write path. The module never calls fetch, a router or a toast\n * library: the host persists each preference and decides how to apply it.\n */\nexport interface PreferencesSettingsPort {\n saveLanguage(language: string): Promise<void>;\n saveTheme(theme: ThemePreferenceValue): Promise<void>;\n saveTimezone(timezone: string): Promise<void>;\n}\n\nexport interface PreferencesSettingsProps {\n labels: PreferencesSettingsLabels;\n values: PreferencesSettingsValues;\n /** Languages the host ships dictionaries for. */\n languages: PreferencesLanguageOption[];\n port: PreferencesSettingsPort;\n /** Called after a language was saved; the host refreshes its locale. */\n onLanguageChanged?: (language: string) => void;\n /** Called after a theme was saved; the host applies it locally. */\n onThemeChanged?: (theme: ThemePreferenceValue) => void;\n /** Called after a timezone was saved; the host refreshes its cache. */\n onTimezoneChanged?: (timezone: string) => void;\n}\n",
54
+ "type": "registry:block"
55
+ },
56
+ {
57
+ "path": "src/modules/preferences-settings/preferences-settings.tsx",
58
+ "content": "\"use client\";\n\nimport { useState } from \"react\";\n\nimport { Button } from \"@/components/ui/button\";\nimport { Card, CardContent, CardHeader, CardTitle } from \"@/components/ui/card\";\nimport { Input } from \"@/components/ui/input\";\nimport { Label } from \"@/components/ui/label\";\nimport { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from \"@/components/ui/select\";\nimport type { PreferencesSettingsProps, ThemePreferenceValue } from \"./types\";\n\nfunction Spinner() {\n return (\n <span\n aria-hidden=\"true\"\n className=\"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent\"\n />\n );\n}\n\nfunction SunIcon() {\n return (\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"h-4 w-4\"\n >\n <circle cx=\"12\" cy=\"12\" r=\"4\" />\n <path d=\"M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4\" />\n </svg>\n );\n}\n\nfunction MoonIcon() {\n return (\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"h-4 w-4\"\n >\n <path d=\"M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8Z\" />\n </svg>\n );\n}\n\nfunction MonitorIcon() {\n return (\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"h-4 w-4\"\n >\n <rect x=\"2\" y=\"3\" width=\"20\" height=\"14\" rx=\"2\" />\n <path d=\"M8 21h8M12 17v4\" />\n </svg>\n );\n}\n\nfunction SaveIcon() {\n return (\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"h-4 w-4\"\n >\n <path d=\"M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2Z\" />\n <path d=\"M17 21v-8H7v8M7 3v5h8\" />\n </svg>\n );\n}\n\n/**\n * Account display preferences: interface language, theme and timezone. The\n * host owns transport and the side effects of each change (locale cookie,\n * theme class, caching), which enter through `port` and the `on*` callbacks.\n */\nexport function PreferencesSettings({\n labels,\n values,\n languages,\n port,\n onLanguageChanged,\n onThemeChanged,\n onTimezoneChanged,\n}: PreferencesSettingsProps) {\n const [timezone, setTimezone] = useState(values.timezone);\n // Re-seed when the host supplies a different account, comparing values (not\n // object identity) so a parent re-render never overwrites in-progress edits.\n const [seedTimezone, setSeedTimezone] = useState(values.timezone);\n if (values.timezone !== seedTimezone) {\n setSeedTimezone(values.timezone);\n setTimezone(values.timezone);\n }\n\n const [languagePending, setLanguagePending] = useState(false);\n const [themePending, setThemePending] = useState(false);\n const [timezonePending, setTimezonePending] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n async function handleLanguage(value: string): Promise<void> {\n if (languagePending) return;\n setLanguagePending(true);\n setError(null);\n try {\n await port.saveLanguage(value);\n onLanguageChanged?.(value);\n } catch {\n setError(labels.updateFailed);\n } finally {\n setLanguagePending(false);\n }\n }\n\n async function handleTheme(value: ThemePreferenceValue): Promise<void> {\n if (themePending) return;\n setThemePending(true);\n setError(null);\n try {\n await port.saveTheme(value);\n onThemeChanged?.(value);\n } catch {\n setError(labels.updateFailed);\n } finally {\n setThemePending(false);\n }\n }\n\n async function handleTimezone(): Promise<void> {\n if (timezonePending) return;\n setTimezonePending(true);\n setError(null);\n try {\n await port.saveTimezone(timezone.trim());\n onTimezoneChanged?.(timezone.trim());\n } catch {\n setError(labels.updateFailed);\n } finally {\n setTimezonePending(false);\n }\n }\n\n // Read the browser zone only inside the click handler: resolving it during\n // render would differ between the server and the browser.\n function useBrowserTimezone(): void {\n setTimezone(Intl.DateTimeFormat().resolvedOptions().timeZone);\n }\n\n const themeOptions: { value: ThemePreferenceValue; label: string; icon: React.ReactNode }[] = [\n { value: \"LIGHT\", label: labels.themeLight, icon: <SunIcon /> },\n { value: \"DARK\", label: labels.themeDark, icon: <MoonIcon /> },\n { value: \"SYSTEM\", label: labels.themeSystem, icon: <MonitorIcon /> },\n ];\n\n return (\n <div className=\"grid max-w-3xl gap-6\">\n <Card>\n <CardHeader>\n <CardTitle className=\"text-base\">{labels.languageTitle}</CardTitle>\n </CardHeader>\n <CardContent className=\"space-y-3\">\n <p className=\"text-sm text-muted-foreground\">{labels.languageDesc}</p>\n <Select\n value={values.language}\n onValueChange={(value) => void handleLanguage(value)}\n disabled={languagePending}\n >\n <SelectTrigger id=\"preferences-settings-language\" aria-label={labels.languageTitle} className=\"w-60\">\n <SelectValue />\n </SelectTrigger>\n <SelectContent>\n {languages.map((option) => (\n <SelectItem key={option.value} value={option.value}>\n {option.label}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n </CardContent>\n </Card>\n\n <Card>\n <CardHeader>\n <CardTitle className=\"text-base\">{labels.themeTitle}</CardTitle>\n </CardHeader>\n <CardContent className=\"space-y-3\">\n <p className=\"text-sm text-muted-foreground\">{labels.themeDesc}</p>\n <div className=\"flex flex-wrap gap-2\">\n {themeOptions.map((option) => {\n const active = values.theme === option.value;\n return (\n <Button\n key={option.value}\n type=\"button\"\n variant={active ? \"default\" : \"outline\"}\n aria-pressed={active}\n disabled={themePending}\n onClick={() => void handleTheme(option.value)}\n >\n {option.icon}\n {option.label}\n </Button>\n );\n })}\n </div>\n </CardContent>\n </Card>\n\n <Card>\n <CardHeader>\n <CardTitle className=\"text-base\">{labels.timezoneTitle}</CardTitle>\n </CardHeader>\n <CardContent className=\"space-y-4\">\n <p className=\"text-sm text-muted-foreground\">{labels.timezoneDesc}</p>\n <div className=\"space-y-2\">\n <Label htmlFor=\"preferences-settings-timezone\">{labels.timezoneTitle}</Label>\n <div className=\"flex flex-wrap items-center gap-2\">\n <Input\n id=\"preferences-settings-timezone\"\n value={timezone}\n onChange={(event) => setTimezone(event.target.value)}\n placeholder={labels.timezonePlaceholder}\n className=\"w-72\"\n disabled={timezonePending}\n />\n <Button\n type=\"button\"\n onClick={() => void handleTimezone()}\n disabled={timezonePending || timezone.trim() === \"\"}\n >\n {timezonePending ? <Spinner /> : <SaveIcon />}\n {labels.saveTimezone}\n </Button>\n <Button type=\"button\" variant=\"outline\" onClick={useBrowserTimezone} disabled={timezonePending}>\n {labels.useBrowserTimezone}\n </Button>\n </div>\n </div>\n </CardContent>\n </Card>\n\n {error && <p className=\"text-sm text-destructive\">{error}</p>}\n </div>\n );\n}\n",
59
+ "type": "registry:block"
60
+ }
61
+ ]
62
+ }
@@ -0,0 +1,30 @@
1
+ {
2
+ "version": "1.0.0",
3
+ "framework": "^1.7.0",
4
+ "entry": "src/modules/profile-settings/index.ts",
5
+ "labels": [
6
+ "personalInfo",
7
+ "firstName",
8
+ "middleName",
9
+ "lastName",
10
+ "displayName",
11
+ "displayNamePlaceholder",
12
+ "saveChanges",
13
+ "email",
14
+ "saveFailed"
15
+ ],
16
+ "ports": [
17
+ "onSave"
18
+ ],
19
+ "ui": [
20
+ "button",
21
+ "card",
22
+ "input",
23
+ "label"
24
+ ],
25
+ "states": [
26
+ "loading",
27
+ "error",
28
+ "ready"
29
+ ]
30
+ }
@@ -0,0 +1,55 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/r/registry-item.json",
3
+ "name": "profile-settings",
4
+ "type": "registry:block",
5
+ "title": "Profile settings card",
6
+ "description": "Account profile card: first, middle and last name plus the display name, with a host-owned save port. Data loading, persistence and toasts stay in the host.",
7
+ "postInstall": "Render <ProfileSettings labels={...} profile={...} onSave={...} /> inside your settings shell. The host supplies translated labels, the current account values and a save function that persists them and toasts. Requires the shadcn ui primitives button, card, input and label.",
8
+ "x-fewbie.contract": {
9
+ "version": "1.0.0",
10
+ "framework": "^1.7.0",
11
+ "entry": "src/modules/profile-settings/index.ts",
12
+ "labels": [
13
+ "personalInfo",
14
+ "firstName",
15
+ "middleName",
16
+ "lastName",
17
+ "displayName",
18
+ "displayNamePlaceholder",
19
+ "saveChanges",
20
+ "email",
21
+ "saveFailed"
22
+ ],
23
+ "ports": [
24
+ "onSave"
25
+ ],
26
+ "ui": [
27
+ "button",
28
+ "card",
29
+ "input",
30
+ "label"
31
+ ],
32
+ "states": [
33
+ "loading",
34
+ "error",
35
+ "ready"
36
+ ]
37
+ },
38
+ "files": [
39
+ {
40
+ "path": "src/modules/profile-settings/index.ts",
41
+ "content": "export { ProfileSettings } from \"./profile-settings\";\nexport type { ProfileSettingsLabels, ProfileSettingsProps, ProfileSettingsValues } from \"./types\";\n",
42
+ "type": "registry:block"
43
+ },
44
+ {
45
+ "path": "src/modules/profile-settings/types.ts",
46
+ "content": "/**\n * Every string the card renders. The host supplies translated copy.\n */\nexport interface ProfileSettingsLabels {\n personalInfo: string;\n firstName: string;\n middleName: string;\n lastName: string;\n displayName: string;\n displayNamePlaceholder: string;\n saveChanges: string;\n email: string;\n saveFailed: string;\n}\n\nexport interface ProfileSettingsValues {\n name: string;\n firstName: string;\n middleName: string;\n lastName: string;\n email?: string;\n}\n\n/**\n * Host-owned write path. The module never calls fetch or a toast library: the\n * host persists the values and decides how to report the outcome.\n */\nexport interface ProfileSettingsProps {\n labels: ProfileSettingsLabels;\n /** Current account values; the form re-seeds when these change. */\n profile: ProfileSettingsValues;\n /** Persist the edited values; the host toasts and refreshes its cache. */\n onSave(values: ProfileSettingsValues): Promise<void>;\n}\n",
47
+ "type": "registry:block"
48
+ },
49
+ {
50
+ "path": "src/modules/profile-settings/profile-settings.tsx",
51
+ "content": "\"use client\";\n\nimport { useState } from \"react\";\n\nimport { Button } from \"@/components/ui/button\";\nimport { Card, CardContent, CardHeader, CardTitle } from \"@/components/ui/card\";\nimport { Input } from \"@/components/ui/input\";\nimport { Label } from \"@/components/ui/label\";\nimport type { ProfileSettingsProps, ProfileSettingsValues } from \"./types\";\n\nfunction Spinner() {\n return (\n <span\n aria-hidden=\"true\"\n className=\"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent\"\n />\n );\n}\n\nfunction SaveIcon() {\n return (\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"h-4 w-4\"\n >\n <path d=\"M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2Z\" />\n <path d=\"M17 21v-8H7v8M7 3v5h8\" />\n </svg>\n );\n}\n\nfunction sameValues(left: ProfileSettingsValues, right: ProfileSettingsValues): boolean {\n return (\n left.name === right.name &&\n left.firstName === right.firstName &&\n left.middleName === right.middleName &&\n left.lastName === right.lastName &&\n left.email === right.email\n );\n}\n\n/**\n * Account profile card: first/middle/last name plus the display name. The host\n * owns data loading, persistence and toasts; the module only edits the values.\n */\nexport function ProfileSettings({ labels, profile, onSave }: ProfileSettingsProps) {\n const [form, setForm] = useState<ProfileSettingsValues>(profile);\n // Re-seed when the host supplies a different account, comparing values (not\n // object identity) so a parent re-render never overwrites in-progress edits.\n const [seed, setSeed] = useState<ProfileSettingsValues>(profile);\n if (!sameValues(profile, seed)) {\n setSeed(profile);\n setForm(profile);\n }\n\n const [pending, setPending] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n function updateField(field: keyof ProfileSettingsValues, value: string): void {\n setForm((prev) => ({ ...prev, [field]: value }));\n }\n\n async function handleSave(): Promise<void> {\n if (pending) return;\n setPending(true);\n setError(null);\n try {\n await onSave(form);\n } catch {\n setError(labels.saveFailed);\n } finally {\n setPending(false);\n }\n }\n\n return (\n <Card>\n <CardHeader>\n <CardTitle className=\"text-base\">{labels.personalInfo}</CardTitle>\n </CardHeader>\n <CardContent className=\"space-y-4\">\n <div className=\"grid gap-4 sm:grid-cols-3\">\n <div className=\"space-y-2\">\n <Label htmlFor=\"profile-settings-first-name\">{labels.firstName}</Label>\n <Input\n id=\"profile-settings-first-name\"\n value={form.firstName}\n onChange={(event) => updateField(\"firstName\", event.target.value)}\n placeholder={labels.firstName}\n />\n </div>\n <div className=\"space-y-2\">\n <Label htmlFor=\"profile-settings-middle-name\">{labels.middleName}</Label>\n <Input\n id=\"profile-settings-middle-name\"\n value={form.middleName}\n onChange={(event) => updateField(\"middleName\", event.target.value)}\n placeholder={labels.middleName}\n />\n </div>\n <div className=\"space-y-2\">\n <Label htmlFor=\"profile-settings-last-name\">{labels.lastName}</Label>\n <Input\n id=\"profile-settings-last-name\"\n value={form.lastName}\n onChange={(event) => updateField(\"lastName\", event.target.value)}\n placeholder={labels.lastName}\n />\n </div>\n </div>\n\n <div className=\"space-y-2\">\n <Label htmlFor=\"profile-settings-name\">{labels.displayName}</Label>\n <Input\n id=\"profile-settings-name\"\n value={form.name}\n onChange={(event) => updateField(\"name\", event.target.value)}\n placeholder={labels.displayNamePlaceholder}\n />\n </div>\n\n {error && <p className=\"text-sm text-destructive\">{error}</p>}\n\n <div className=\"flex items-center gap-3 border-t pt-4\">\n <Button type=\"button\" onClick={() => void handleSave()} disabled={pending}>\n {pending ? <Spinner /> : <SaveIcon />}\n {labels.saveChanges}\n </Button>\n <p className=\"text-xs text-muted-foreground\">\n {labels.email}: {profile.email ?? \"—\"}\n </p>\n </div>\n </CardContent>\n </Card>\n );\n}\n",
52
+ "type": "registry:block"
53
+ }
54
+ ]
55
+ }
@@ -0,0 +1,52 @@
1
+ {
2
+ "version": "1.0.0",
3
+ "framework": "^1.7.0",
4
+ "entry": "src/modules/security-settings/index.ts",
5
+ "labels": [
6
+ "activeSessions",
7
+ "loadingSessions",
8
+ "loadSessionsFailed",
9
+ "noSessions",
10
+ "unknownDevice",
11
+ "thisDevice",
12
+ "signOutSession",
13
+ "twoFactorTitle",
14
+ "statusEnabled",
15
+ "statusDisabled",
16
+ "twoFactorDesc",
17
+ "qrAlt",
18
+ "scanQr",
19
+ "enterCode",
20
+ "confirmEnable",
21
+ "currentPassword",
22
+ "passwordPlaceholder",
23
+ "or",
24
+ "authenticatorCode",
25
+ "disable",
26
+ "disableTwoFactor",
27
+ "setupWithApp",
28
+ "cancel",
29
+ "retry",
30
+ "actionFailed"
31
+ ],
32
+ "ports": [
33
+ "listSessions",
34
+ "revokeSession",
35
+ "setupTwoFactor",
36
+ "enableTwoFactor",
37
+ "disableTwoFactor"
38
+ ],
39
+ "ui": [
40
+ "badge",
41
+ "button",
42
+ "card",
43
+ "input",
44
+ "label"
45
+ ],
46
+ "states": [
47
+ "loading",
48
+ "error",
49
+ "empty",
50
+ "ready"
51
+ ]
52
+ }