@tc96/cli 0.0.0-stage → 0.27.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/LICENSE +21 -0
- package/README.md +213 -2
- package/cli.js +1395 -0
- package/package.json +35 -4
- package/registry/agent-builder.json +503 -0
- package/registry/aggregate.json +4 -0
- package/registry/app-shell-1.json +81 -0
- package/registry/app-shell-2.json +89 -0
- package/registry/app-shell-3.json +109 -0
- package/registry/app-shell-4.json +104 -0
- package/registry/app-shell-5.json +106 -0
- package/registry/bulk-import-1.json +151 -0
- package/registry/card-1.json +104 -0
- package/registry/card-2.json +97 -0
- package/registry/card-3.json +104 -0
- package/registry/card-4.json +98 -0
- package/registry/card-5.json +85 -0
- package/registry/card-6.json +98 -0
- package/registry/card-7.json +104 -0
- package/registry/card-8.json +106 -0
- package/registry/card-9.json +92 -0
- package/registry/charts.json +30 -0
- package/registry/chat-assistant.json +110 -0
- package/registry/chats-panel.json +97 -0
- package/registry/checklist.json +307 -0
- package/registry/collection-layouts.json +836 -0
- package/registry/collection-views.json +836 -0
- package/registry/collection.json +831 -0
- package/registry/dashboard-1.json +160 -0
- package/registry/dashboard-2.json +153 -0
- package/registry/dashboard-3.json +154 -0
- package/registry/dashboard-4.json +168 -0
- package/registry/detail-sheet.json +54 -0
- package/registry/editable.json +36 -0
- package/registry/empty-state-1.json +40 -0
- package/registry/empty-state-2.json +39 -0
- package/registry/empty-state-3.json +61 -0
- package/registry/empty-state-4.json +39 -0
- package/registry/empty-state-5.json +47 -0
- package/registry/empty-state-6.json +40 -0
- package/registry/flow-canvas.json +198 -0
- package/registry/flow-inspector.json +151 -0
- package/registry/flow-step-library.json +112 -0
- package/registry/forgot-password-1.json +73 -0
- package/registry/forgot-password-2.json +73 -0
- package/registry/icon-row.json +52 -0
- package/registry/impact-map.json +75 -0
- package/registry/list-1.json +129 -0
- package/registry/list-2.json +117 -0
- package/registry/list-3.json +129 -0
- package/registry/list-4.json +105 -0
- package/registry/list-5.json +98 -0
- package/registry/list-6.json +92 -0
- package/registry/list.json +52 -0
- package/registry/login-1.json +89 -0
- package/registry/login-10.json +88 -0
- package/registry/login-2.json +81 -0
- package/registry/login-3.json +90 -0
- package/registry/login-4.json +81 -0
- package/registry/login-5.json +82 -0
- package/registry/login-6.json +88 -0
- package/registry/login-7.json +83 -0
- package/registry/login-8.json +81 -0
- package/registry/login-9.json +88 -0
- package/registry/lookup-create-1.json +157 -0
- package/registry/magic-link-6.json +79 -0
- package/registry/navbar-1.json +66 -0
- package/registry/navbar-2.json +48 -0
- package/registry/navbar-3.json +50 -0
- package/registry/navbar-4.json +39 -0
- package/registry/navbar-5.json +50 -0
- package/registry/next-steps-1.json +147 -0
- package/registry/onboarding-1.json +114 -0
- package/registry/onboarding-2.json +78 -0
- package/registry/onboarding-3.json +71 -0
- package/registry/otp-1.json +73 -0
- package/registry/properties.json +523 -0
- package/registry/record-dialog.json +88 -0
- package/registry/record-group.json +190 -0
- package/registry/record-preview.json +70 -0
- package/registry/record-status-list.json +70 -0
- package/registry/reset-password-1.json +92 -0
- package/registry/reset-password-2.json +98 -0
- package/registry/reset-password-6.json +91 -0
- package/registry/rich-text-editor.json +93 -0
- package/registry/run-monitor.json +198 -0
- package/registry/settings-1.json +119 -0
- package/registry/settings-10.json +218 -0
- package/registry/settings-11.json +129 -0
- package/registry/settings-12.json +130 -0
- package/registry/settings-13.json +130 -0
- package/registry/settings-14.json +173 -0
- package/registry/settings-15.json +149 -0
- package/registry/settings-16.json +129 -0
- package/registry/settings-17.json +117 -0
- package/registry/settings-18.json +117 -0
- package/registry/settings-19.json +125 -0
- package/registry/settings-2.json +123 -0
- package/registry/settings-20.json +112 -0
- package/registry/settings-21.json +116 -0
- package/registry/settings-22.json +118 -0
- package/registry/settings-23.json +118 -0
- package/registry/settings-3.json +123 -0
- package/registry/settings-4.json +116 -0
- package/registry/settings-5.json +119 -0
- package/registry/settings-6.json +125 -0
- package/registry/settings-7.json +128 -0
- package/registry/settings-8.json +116 -0
- package/registry/settings-9.json +118 -0
- package/registry/settings-shell.json +60 -0
- package/registry/settings.json +82 -0
- package/registry/signup-1.json +100 -0
- package/registry/signup-2.json +93 -0
- package/registry/signup-3.json +83 -0
- package/registry/signup-6.json +99 -0
- package/registry/state-surface.json +58 -0
- package/registry/stats-1.json +116 -0
- package/registry/stats-2.json +115 -0
- package/registry/stats-3.json +97 -0
- package/registry/stats-4.json +92 -0
- package/registry/stats-5.json +103 -0
- package/registry/stats-6.json +105 -0
- package/registry/stats-7.json +103 -0
- package/registry/stats.json +64 -0
- package/registry/timeline-1.json +97 -0
- package/registry/timeline-2.json +102 -0
- package/registry/timeline-3.json +68 -0
- package/registry/timeline-4.json +86 -0
- package/registry/ui/accordion.json +15 -0
- package/registry/ui/alert-dialog.json +14 -0
- package/registry/ui/alert.json +50 -0
- package/registry/ui/autocomplete.json +18 -0
- package/registry/ui/avatar.json +14 -0
- package/registry/ui/badge.json +51 -0
- package/registry/ui/breadcrumb.json +15 -0
- package/registry/ui/button.json +25 -0
- package/registry/ui/calendar.json +15 -0
- package/registry/ui/card.json +14 -0
- package/registry/ui/chat.json +115 -0
- package/registry/ui/checkbox-group.json +14 -0
- package/registry/ui/checkbox.json +14 -0
- package/registry/ui/collapsible.json +14 -0
- package/registry/ui/combobox.json +18 -0
- package/registry/ui/command.json +17 -0
- package/registry/ui/composer-clipboard.json +14 -0
- package/registry/ui/composer-document.json +14 -0
- package/registry/ui/composer-editor.json +16 -0
- package/registry/ui/composer-query.json +12 -0
- package/registry/ui/composer.json +17 -0
- package/registry/ui/context-menu.json +23 -0
- package/registry/ui/dialog.json +18 -0
- package/registry/ui/drawer.json +18 -0
- package/registry/ui/empty.json +14 -0
- package/registry/ui/field.json +22 -0
- package/registry/ui/fieldset.json +14 -0
- package/registry/ui/form.json +14 -0
- package/registry/ui/frame.json +12 -0
- package/registry/ui/gauge.json +31 -0
- package/registry/ui/group.json +17 -0
- package/registry/ui/icon-frame.json +31 -0
- package/registry/ui/input-group.json +17 -0
- package/registry/ui/input.json +14 -0
- package/registry/ui/kbd.json +12 -0
- package/registry/ui/label.json +14 -0
- package/registry/ui/menu.json +39 -0
- package/registry/ui/meter.json +14 -0
- package/registry/ui/number-field.json +17 -0
- package/registry/ui/otp-field.json +31 -0
- package/registry/ui/pagination.json +17 -0
- package/registry/ui/popover.json +14 -0
- package/registry/ui/preview-card.json +14 -0
- package/registry/ui/progress.json +14 -0
- package/registry/ui/radio-group.json +14 -0
- package/registry/ui/render-anchor.json +12 -0
- package/registry/ui/scroll-area.json +14 -0
- package/registry/ui/segmented-control.json +14 -0
- package/registry/ui/select.json +16 -0
- package/registry/ui/separator.json +14 -0
- package/registry/ui/sheet.json +18 -0
- package/registry/ui/sidebar.json +25 -0
- package/registry/ui/skeleton.json +24 -0
- package/registry/ui/slider.json +14 -0
- package/registry/ui/spinner.json +14 -0
- package/registry/ui/switch.json +14 -0
- package/registry/ui/table.json +14 -0
- package/registry/ui/tabs.json +16 -0
- package/registry/ui/text.json +31 -0
- package/registry/ui/textarea.json +14 -0
- package/registry/ui/toast.json +89 -0
- package/registry/ui/toggle-group.json +18 -0
- package/registry/ui/toggle.json +15 -0
- package/registry/ui/toolbar.json +14 -0
- package/registry/ui/tooltip.json +14 -0
- package/registry/ui/use-composer-editor.json +17 -0
- package/registry/ui/use-copy-to-clipboard.json +12 -0
- package/registry/ui/use-media-query.json +12 -0
- package/registry/view.json +831 -0
- package/registry/widgets.json +319 -0
- package/registry/wizard.json +89 -0
- package/registry/workflow-editor.json +460 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "reset-password-1",
|
|
3
|
+
"type": "registry:block",
|
|
4
|
+
"files": [
|
|
5
|
+
{
|
|
6
|
+
"path": "blocks/application/auth/reset-password-1/index.ts",
|
|
7
|
+
"type": "registry:file",
|
|
8
|
+
"content": "export type {\n AuthBaseProps,\n AuthCommonLabels,\n AuthFieldErrors,\n AuthNewPasswordLabels,\n AuthPasswordSuggestion,\n AuthRenderLink,\n} from '../shared/types'\nexport { ResetPassword1 } from './reset-password-1'\nexport type {\n ResetPasswordLabels,\n ResetPasswordProps,\n ResetPasswordValues,\n} from './types'\n",
|
|
9
|
+
"target": "~/packages/ui/src/blocks/application/auth/reset-password-1/index.ts"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"path": "blocks/application/auth/reset-password-1/labels.ts",
|
|
13
|
+
"type": "registry:file",
|
|
14
|
+
"content": "import {\n defaultAuthCommonLabels,\n defaultAuthNewPasswordLabels,\n} from '../shared/labels'\nimport type { ResetPasswordLabels } from './types'\n\nexport const defaultResetPasswordLabels: ResetPasswordLabels = {\n ...defaultAuthNewPasswordLabels,\n backToLogin: 'Voltar para entrar',\n description: 'Escolha uma nova senha para a sua conta.',\n errorTitle: defaultAuthCommonLabels.errorTitle,\n hidePassword: defaultAuthCommonLabels.hidePassword,\n newPassword: 'Nova senha',\n showPassword: defaultAuthCommonLabels.showPassword,\n submit: 'Redefinir senha',\n title: 'Redefinir senha',\n}\n",
|
|
15
|
+
"target": "~/packages/ui/src/blocks/application/auth/reset-password-1/labels.ts"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "blocks/application/auth/reset-password-1/reset-password-1.tsx",
|
|
19
|
+
"type": "registry:file",
|
|
20
|
+
"content": "'use client'\n\nimport { Button } from '@tc96/ui/button'\nimport { Form } from '@tc96/ui/form'\nimport { renderAnchor } from '@tc96/ui/render-anchor'\nimport { type ReactElement, useMemo, useRef, useState } from 'react'\nimport { AuthCard } from '../shared/auth-card'\nimport { AuthPasswordFeedback } from '../shared/auth-password-feedback'\nimport { AuthPasswordField } from '../shared/auth-password-field'\nimport { resolveAuthLabels } from '../shared/labels'\nimport { defaultPasswordSuggestions } from '../shared/password-suggestions'\nimport { toFormErrors } from '../shared/to-form-errors'\nimport { useFocusFirstInvalid } from '../shared/use-focus-first-invalid'\nimport { defaultResetPasswordLabels } from './labels'\nimport type { ResetPasswordProps, ResetPasswordValues } from './types'\n\nfunction toResetPasswordValues(\n values: Readonly<Record<string, unknown>>,\n): ResetPasswordValues {\n return { password: String(values.password ?? '') }\n}\n\nexport function ResetPassword1({\n error,\n fieldErrors,\n labels: labelsProp,\n loginHref,\n logo,\n onSubmit,\n passwordMinLength = 8,\n passwordSuggestions = defaultPasswordSuggestions,\n pending = false,\n renderLink = renderAnchor,\n}: Readonly<ResetPasswordProps>): ReactElement {\n const labels = resolveAuthLabels(defaultResetPasswordLabels, labelsProp)\n const formRef = useRef<HTMLFormElement>(null)\n const alertRef = useRef<HTMLDivElement>(null)\n const [password, setPassword] = useState('')\n const [mismatch, setMismatch] = useState(false)\n const errors = useMemo(\n () => ({\n ...toFormErrors(fieldErrors),\n ...(mismatch ? { confirmPassword: labels.passwordMismatch } : undefined),\n }),\n [fieldErrors, labels.passwordMismatch, mismatch],\n )\n\n useFocusFirstInvalid({ alertRef, error, fieldErrors, formRef })\n\n return (\n <AuthCard\n alertRef={alertRef}\n description={labels.description}\n error={error}\n errorTitle={labels.errorTitle}\n footer={\n loginHref ? (\n <Button\n className=\"underline\"\n render={renderLink(loginHref)}\n size=\"sm\"\n variant=\"link\"\n >\n {labels.backToLogin}\n </Button>\n ) : undefined\n }\n logo={logo}\n title={labels.title}\n >\n <Form\n aria-busy={pending}\n className=\"flex flex-col gap-4\"\n errors={errors}\n onFormSubmit={(values) => {\n if (pending) return\n if (values.password !== values.confirmPassword) {\n setMismatch(true)\n return\n }\n onSubmit(toResetPasswordValues(values))\n }}\n ref={formRef}\n >\n <AuthPasswordField\n autoComplete=\"new-password\"\n hideLabel={labels.hidePassword}\n label={labels.newPassword}\n minLength={passwordMinLength}\n name=\"password\"\n onValueChange={(value) => {\n setPassword(value)\n setMismatch(false)\n }}\n showLabel={labels.showPassword}\n >\n <AuthPasswordFeedback\n labels={labels}\n password={password}\n suggestions={passwordSuggestions}\n />\n </AuthPasswordField>\n <AuthPasswordField\n autoComplete=\"new-password\"\n hideLabel={labels.hidePassword}\n label={labels.confirmPassword}\n name=\"confirmPassword\"\n onValueChange={() => setMismatch(false)}\n showLabel={labels.showPassword}\n />\n <Button className=\"w-full\" loading={pending} type=\"submit\">\n {labels.submit}\n </Button>\n </Form>\n </AuthCard>\n )\n}\n",
|
|
21
|
+
"target": "~/packages/ui/src/blocks/application/auth/reset-password-1/reset-password-1.tsx"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "blocks/application/auth/reset-password-1/types.ts",
|
|
25
|
+
"type": "registry:file",
|
|
26
|
+
"content": "import type {\n AuthBaseProps,\n AuthCommonLabels,\n AuthFieldErrors,\n AuthNewPasswordLabels,\n AuthPasswordSuggestion,\n} from '../shared/types'\n\nexport interface ResetPasswordValues {\n password: string\n}\n\nexport interface ResetPasswordLabels\n extends Pick<\n AuthCommonLabels,\n 'errorTitle' | 'hidePassword' | 'showPassword'\n >,\n AuthNewPasswordLabels {\n backToLogin: string\n description: string\n newPassword: string\n submit: string\n title: string\n}\n\nexport interface ResetPasswordProps extends AuthBaseProps<ResetPasswordLabels> {\n fieldErrors?: AuthFieldErrors<ResetPasswordValues>\n loginHref?: string\n onSubmit: (values: ResetPasswordValues) => void\n passwordMinLength?: number\n passwordSuggestions?: AuthPasswordSuggestion[]\n}\n",
|
|
27
|
+
"target": "~/packages/ui/src/blocks/application/auth/reset-password-1/types.ts"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "blocks/application/auth/shared/auth-card.tsx",
|
|
31
|
+
"type": "registry:file",
|
|
32
|
+
"content": "'use client'\n\nimport { Alert, AlertDescription, AlertTitle } from '@tc96/ui/alert'\nimport {\n Card,\n CardDescription,\n CardHeader,\n CardPanel,\n CardTitle,\n} from '@tc96/ui/card'\nimport type { ReactElement, ReactNode, Ref } from 'react'\n\nexport interface AuthCardProps {\n alertRef?: Ref<HTMLDivElement>\n children?: ReactNode\n description?: ReactNode\n error?: string\n errorTitle: string\n footer?: ReactNode\n logo?: ReactNode\n notice?: ReactNode\n title: ReactNode\n titleRef?: Ref<HTMLDivElement>\n}\n\nexport function AuthCard({\n alertRef,\n children,\n description,\n error,\n errorTitle,\n footer,\n logo,\n notice,\n title,\n titleRef,\n}: Readonly<AuthCardProps>): ReactElement {\n return (\n <main className=\"flex min-h-svh items-center justify-center p-4 sm:p-6\">\n <div className=\"flex w-full max-w-sm flex-col gap-6\">\n <Card>\n <CardHeader className=\"justify-items-center text-center\">\n {logo ? (\n <div className=\"mb-2 flex justify-center\">{logo}</div>\n ) : null}\n <CardTitle\n ref={titleRef}\n render={(props) => <h1 {...props} />}\n tabIndex={titleRef ? -1 : undefined}\n >\n {title}\n </CardTitle>\n {description ? (\n <CardDescription>{description}</CardDescription>\n ) : null}\n </CardHeader>\n <CardPanel className=\"flex flex-col gap-4\">\n {error ? (\n <Alert ref={alertRef} tabIndex={-1} variant=\"error\">\n <AlertTitle>{errorTitle}</AlertTitle>\n <AlertDescription>{error}</AlertDescription>\n </Alert>\n ) : null}\n {children}\n </CardPanel>\n </Card>\n {footer ? (\n <div\n className=\"flex flex-wrap items-center justify-center gap-1 text-muted-foreground text-sm\"\n data-slot=\"auth-footer\"\n >\n {footer}\n </div>\n ) : null}\n {notice}\n </div>\n </main>\n )\n}\n",
|
|
33
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/auth-card.tsx"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"path": "blocks/application/auth/shared/auth-password-feedback.tsx",
|
|
37
|
+
"type": "registry:file",
|
|
38
|
+
"content": "'use client'\n\nimport { CheckIcon, CircleIcon } from '@phosphor-icons/react'\nimport { FieldDescription } from '@tc96/ui/field'\nimport { type ReactElement, useState } from 'react'\nimport { getPasswordSuggestions } from './password-suggestions'\nimport type { AuthNewPasswordLabels, AuthPasswordSuggestion } from './types'\n\nconst suggestionLabelKeys = {\n lowercase: 'suggestionLowercase',\n number: 'suggestionNumber',\n symbol: 'suggestionSymbol',\n uppercase: 'suggestionUppercase',\n} as const satisfies Record<AuthPasswordSuggestion, keyof AuthNewPasswordLabels>\n\nexport interface AuthPasswordFeedbackProps {\n labels: AuthNewPasswordLabels\n password: string\n suggestions: readonly AuthPasswordSuggestion[]\n}\n\ninterface FeedbackState {\n announcement: string\n met: readonly AuthPasswordSuggestion[]\n}\n\nexport function AuthPasswordFeedback({\n labels,\n password,\n suggestions,\n}: Readonly<AuthPasswordFeedbackProps>): ReactElement {\n const met = getPasswordSuggestions(password, suggestions)\n const [state, setState] = useState<FeedbackState>({\n announcement: '',\n met,\n })\n if (state.met.join() !== met.join()) {\n const messages: string[] = []\n for (const suggestion of suggestions) {\n const wasMet = state.met.includes(suggestion)\n const isMet = met.includes(suggestion)\n if (wasMet !== isMet)\n messages.push(\n `${labels[suggestionLabelKeys[suggestion]]}: ${isMet ? labels.suggestionMet : labels.suggestionMissing}`,\n )\n }\n setState({ announcement: messages.join('. '), met })\n }\n return (\n <>\n <FieldDescription className=\"flex flex-col gap-1.5\" render={<div />}>\n {suggestions.length ? (\n <ul className=\"flex gap-x-3 whitespace-nowrap text-xs\">\n {suggestions.map((suggestion) => {\n const isMet = met.includes(suggestion)\n return (\n <li\n className=\"flex items-center gap-1 transition-colors data-met:font-medium data-met:text-success-foreground\"\n data-met={isMet ? '' : undefined}\n key={suggestion}\n >\n {isMet ? (\n <CheckIcon aria-hidden className=\"size-3\" />\n ) : (\n <CircleIcon aria-hidden className=\"size-3\" />\n )}\n {labels[suggestionLabelKeys[suggestion]]}\n <span className=\"sr-only\">\n {` ${isMet ? labels.suggestionMet : labels.suggestionMissing}`}\n </span>\n </li>\n )\n })}\n </ul>\n ) : null}\n </FieldDescription>\n <div aria-live=\"polite\" className=\"sr-only\">\n {state.announcement}\n </div>\n </>\n )\n}\n",
|
|
39
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/auth-password-feedback.tsx"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "blocks/application/auth/shared/auth-password-field.tsx",
|
|
43
|
+
"type": "registry:file",
|
|
44
|
+
"content": "'use client'\n\nimport { EyeIcon, EyeSlashIcon } from '@phosphor-icons/react'\nimport { Button } from '@tc96/ui/button'\nimport { Field, FieldError, FieldLabel } from '@tc96/ui/field'\nimport {\n InputGroup,\n InputGroupAddon,\n InputGroupInput,\n} from '@tc96/ui/input-group'\nimport { type ReactElement, type ReactNode, useState } from 'react'\n\nexport interface AuthPasswordFieldProps {\n autoComplete: 'current-password' | 'new-password'\n children?: ReactNode\n hideLabel: string\n label: string\n labelAction?: ReactNode\n minLength?: number\n name: string\n onValueChange?: (value: string) => void\n required?: boolean\n showLabel: string\n}\n\nexport function AuthPasswordField({\n autoComplete,\n children,\n hideLabel,\n label,\n labelAction,\n minLength,\n name,\n onValueChange,\n required = true,\n showLabel,\n}: Readonly<AuthPasswordFieldProps>): ReactElement {\n const [visible, setVisible] = useState(false)\n const toggleLabel = visible ? hideLabel : showLabel\n return (\n <Field name={name}>\n {labelAction ? (\n <div className=\"flex w-full items-center justify-between gap-2\">\n <FieldLabel>{label}</FieldLabel>\n {labelAction}\n </div>\n ) : (\n <FieldLabel>{label}</FieldLabel>\n )}\n <InputGroup>\n <InputGroupInput\n autoComplete={autoComplete}\n minLength={minLength}\n onValueChange={onValueChange}\n required={required}\n type={visible ? 'text' : 'password'}\n />\n <InputGroupAddon align=\"inline-end\">\n <Button\n aria-label={toggleLabel}\n onClick={() => setVisible((current) => !current)}\n size=\"sm\"\n title={toggleLabel}\n type=\"button\"\n variant=\"ghost\"\n >\n {visible ? <EyeSlashIcon aria-hidden /> : <EyeIcon aria-hidden />}\n </Button>\n </InputGroupAddon>\n </InputGroup>\n <FieldError />\n {children}\n </Field>\n )\n}\n",
|
|
45
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/auth-password-field.tsx"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"path": "blocks/application/auth/shared/labels.ts",
|
|
49
|
+
"type": "registry:file",
|
|
50
|
+
"content": "import type { AuthCommonLabels, AuthNewPasswordLabels } from './types'\n\nexport const defaultAuthCommonLabels: AuthCommonLabels = {\n email: 'E-mail',\n errorTitle: 'Não foi possível continuar',\n hidePassword: 'Ocultar senha',\n password: 'Senha',\n providerContinue: (label) => `Continuar com ${label}`,\n providersGroup: 'Entrar com outro serviço',\n providersSeparator: 'ou continue com e-mail',\n showPassword: 'Mostrar senha',\n}\n\nexport const defaultAuthNewPasswordLabels: AuthNewPasswordLabels = {\n confirmPassword: 'Confirmar senha',\n passwordMismatch: 'As senhas não coincidem.',\n suggestionLowercase: 'minúscula',\n suggestionMet: 'atendida',\n suggestionMissing: 'faltando',\n suggestionNumber: 'número',\n suggestionSymbol: 'símbolo',\n suggestionUppercase: 'maiúscula',\n}\n\nexport function resolveAuthLabels<TLabels>(\n defaults: TLabels,\n labels?: Partial<TLabels>,\n): TLabels {\n return { ...defaults, ...labels }\n}\n",
|
|
51
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/labels.ts"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"path": "blocks/application/auth/shared/password-suggestions.ts",
|
|
55
|
+
"type": "registry:file",
|
|
56
|
+
"content": "import type { AuthPasswordSuggestion } from './types'\n\nconst suggestionPatterns: Record<AuthPasswordSuggestion, RegExp> = {\n lowercase: /\\p{Ll}/u,\n number: /\\p{Nd}/u,\n symbol: /[^\\p{L}\\p{N}\\s]/u,\n uppercase: /\\p{Lu}/u,\n}\n\nexport const defaultPasswordSuggestions: AuthPasswordSuggestion[] = [\n 'lowercase',\n 'uppercase',\n 'number',\n 'symbol',\n]\n\nexport function getPasswordSuggestions(\n password: string,\n suggestions: readonly AuthPasswordSuggestion[],\n): AuthPasswordSuggestion[] {\n return suggestions.filter((suggestion) =>\n suggestionPatterns[suggestion].test(password),\n )\n}\n",
|
|
57
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/password-suggestions.ts"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"path": "blocks/application/auth/shared/to-form-errors.ts",
|
|
61
|
+
"type": "registry:file",
|
|
62
|
+
"content": "export function toFormErrors(\n fieldErrors?: Readonly<Partial<Record<string, string>>>,\n): Record<string, string> {\n const errors: Record<string, string> = {}\n for (const [name, message] of Object.entries(fieldErrors ?? {}))\n if (message) errors[name] = message\n return errors\n}\n",
|
|
63
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/to-form-errors.ts"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"path": "blocks/application/auth/shared/types.ts",
|
|
67
|
+
"type": "registry:file",
|
|
68
|
+
"content": "import type { RenderLink } from '@tc96/ui/render-anchor'\nimport type { ReactNode } from 'react'\n\nexport type AuthRenderLink = RenderLink\n\nexport interface AuthProvider {\n icon?: ReactNode\n id: string\n label: string\n}\n\nexport type AuthFieldErrors<TValues> = Partial<Record<keyof TValues, string>>\n\nexport type AuthPasswordSuggestion =\n | 'lowercase'\n | 'uppercase'\n | 'number'\n | 'symbol'\n\nexport interface AuthCommonLabels {\n email: string\n errorTitle: string\n hidePassword: string\n password: string\n providerContinue: (label: string) => string\n providersGroup: string\n providersSeparator: string\n showPassword: string\n}\n\nexport interface AuthNewPasswordLabels {\n confirmPassword: string\n passwordMismatch: string\n suggestionLowercase: string\n suggestionMet: string\n suggestionMissing: string\n suggestionNumber: string\n suggestionSymbol: string\n suggestionUppercase: string\n}\n\nexport interface AuthBaseProps<TLabels> {\n error?: string\n labels?: Partial<TLabels>\n logo?: ReactNode\n pending?: boolean\n renderLink?: AuthRenderLink\n}\n",
|
|
69
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/types.ts"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"path": "blocks/application/auth/shared/use-focus-first-invalid.ts",
|
|
73
|
+
"type": "registry:file",
|
|
74
|
+
"content": "'use client'\n\nimport { type RefObject, useEffect, useRef } from 'react'\nimport { toFormErrors } from './to-form-errors'\n\nexport interface UseFocusFirstInvalidOptions {\n alertRef: RefObject<HTMLElement | null>\n error?: string\n fieldErrors?: Readonly<Partial<Record<string, string>>>\n formRef: RefObject<HTMLFormElement | null>\n}\n\nfunction findFirstNamedControl(\n form: HTMLFormElement | null,\n names: readonly string[],\n): HTMLElement | undefined {\n return Array.from(form?.elements ?? []).find(\n (element): element is HTMLElement =>\n element instanceof HTMLElement &&\n !(element instanceof HTMLInputElement && element.type === 'hidden') &&\n names.includes(element.getAttribute('name') ?? ''),\n )\n}\n\nexport function useFocusFirstInvalid({\n alertRef,\n error,\n fieldErrors,\n formRef,\n}: UseFocusFirstInvalidOptions): void {\n const invalidNames = Object.keys(toFormErrors(fieldErrors)).join('\\n')\n const hasError = Boolean(error)\n const previous = useRef({ hasError, invalidNames })\n\n useEffect(() => {\n const before = previous.current\n previous.current = { hasError, invalidNames }\n const hasFieldErrors = invalidNames !== ''\n const filled =\n (hasFieldErrors && before.invalidNames === '') ||\n (hasError && !before.hasError)\n if (!filled) return\n const field = hasFieldErrors\n ? findFirstNamedControl(formRef.current, invalidNames.split('\\n'))\n : undefined\n if (field) field.focus()\n else if (hasError) alertRef.current?.focus()\n }, [alertRef, formRef, hasError, invalidNames])\n}\n",
|
|
75
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/use-focus-first-invalid.ts"
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
"dependencies": [
|
|
79
|
+
"@phosphor-icons/react@2.1.10",
|
|
80
|
+
"react@19.1.1"
|
|
81
|
+
],
|
|
82
|
+
"registryDependencies": [
|
|
83
|
+
"@ui/alert",
|
|
84
|
+
"@ui/button",
|
|
85
|
+
"@ui/card",
|
|
86
|
+
"@ui/field",
|
|
87
|
+
"@ui/form",
|
|
88
|
+
"@ui/input-group",
|
|
89
|
+
"@ui/render-anchor"
|
|
90
|
+
],
|
|
91
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json"
|
|
92
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "reset-password-2",
|
|
3
|
+
"type": "registry:block",
|
|
4
|
+
"files": [
|
|
5
|
+
{
|
|
6
|
+
"path": "blocks/application/auth/reset-password-2/format-countdown.ts",
|
|
7
|
+
"type": "registry:file",
|
|
8
|
+
"content": "export function formatCountdown(seconds: number): string {\n const total = Number.isFinite(seconds) ? Math.max(0, Math.floor(seconds)) : 0\n const minutes = Math.floor(total / 60)\n const rest = total % 60\n return `${minutes}:${String(rest).padStart(2, '0')}`\n}\n",
|
|
9
|
+
"target": "~/packages/ui/src/blocks/application/auth/reset-password-2/format-countdown.ts"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"path": "blocks/application/auth/reset-password-2/index.ts",
|
|
13
|
+
"type": "registry:file",
|
|
14
|
+
"content": "export type {\n AuthBaseProps,\n AuthCommonLabels,\n AuthFieldErrors,\n AuthNewPasswordLabels,\n AuthPasswordSuggestion,\n AuthRenderLink,\n} from '../shared/types'\nexport { ResetPassword2 } from './reset-password-2'\nexport type {\n ResetPassword2Labels,\n ResetPassword2Props,\n ResetPassword2Values,\n} from './types'\n",
|
|
15
|
+
"target": "~/packages/ui/src/blocks/application/auth/reset-password-2/index.ts"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "blocks/application/auth/reset-password-2/labels.ts",
|
|
19
|
+
"type": "registry:file",
|
|
20
|
+
"content": "import {\n defaultAuthCommonLabels,\n defaultAuthNewPasswordLabels,\n} from '../shared/labels'\nimport type { ResetPassword2Labels } from './types'\n\nexport const defaultResetPassword2Labels: ResetPassword2Labels = {\n ...defaultAuthNewPasswordLabels,\n backToLogin: 'Voltar para entrar',\n description: 'Escolha uma nova senha para a sua conta.',\n errorTitle: defaultAuthCommonLabels.errorTitle,\n expiredDescription:\n 'Este link de redefinição expirou. Solicite um novo para continuar.',\n expiredTitle: 'Link expirado',\n expiringSoon: 'Falta menos de um minuto para este link expirar.',\n hidePassword: defaultAuthCommonLabels.hidePassword,\n linkExpiresIn: (time) => `Este link expira em ${time}`,\n newPassword: 'Nova senha',\n requestNewLink: 'Solicitar novo link',\n requestNewLinkIn: (time) => `Solicitar novamente em ${time}`,\n showPassword: defaultAuthCommonLabels.showPassword,\n submit: 'Redefinir senha',\n title: 'Redefinir senha',\n}\n",
|
|
21
|
+
"target": "~/packages/ui/src/blocks/application/auth/reset-password-2/labels.ts"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "blocks/application/auth/reset-password-2/reset-password-2.tsx",
|
|
25
|
+
"type": "registry:file",
|
|
26
|
+
"content": "'use client'\n\nimport { Button } from '@tc96/ui/button'\nimport { Form } from '@tc96/ui/form'\nimport { renderAnchor } from '@tc96/ui/render-anchor'\nimport { type ReactElement, useEffect, useMemo, useRef, useState } from 'react'\nimport { AuthCard } from '../shared/auth-card'\nimport { AuthPasswordFeedback } from '../shared/auth-password-feedback'\nimport { AuthPasswordField } from '../shared/auth-password-field'\nimport { resolveAuthLabels } from '../shared/labels'\nimport { defaultPasswordSuggestions } from '../shared/password-suggestions'\nimport { toFormErrors } from '../shared/to-form-errors'\nimport { useFocusFirstInvalid } from '../shared/use-focus-first-invalid'\nimport { formatCountdown } from './format-countdown'\nimport { defaultResetPassword2Labels } from './labels'\nimport type { ResetPassword2Props, ResetPassword2Values } from './types'\n\nconst expiringSoonSeconds = 60\n\nfunction toResetPassword2Values(\n values: Readonly<Record<string, unknown>>,\n): ResetPassword2Values {\n return { password: String(values.password ?? '') }\n}\n\nexport function ResetPassword2({\n error,\n expiresIn,\n fieldErrors,\n labels: labelsProp,\n loginHref,\n logo,\n onRequestNewLink,\n onSubmit,\n passwordMinLength = 8,\n passwordSuggestions = defaultPasswordSuggestions,\n pending = false,\n renderLink = renderAnchor,\n requestNewLinkIn = 0,\n}: Readonly<ResetPassword2Props>): ReactElement {\n const labels = resolveAuthLabels(defaultResetPassword2Labels, labelsProp)\n const formRef = useRef<HTMLFormElement>(null)\n const alertRef = useRef<HTMLDivElement>(null)\n const titleRef = useRef<HTMLDivElement>(null)\n const [password, setPassword] = useState('')\n const [mismatch, setMismatch] = useState(false)\n const errors = useMemo(\n () => ({\n ...toFormErrors(fieldErrors),\n ...(mismatch ? { confirmPassword: labels.passwordMismatch } : undefined),\n }),\n [fieldErrors, labels.passwordMismatch, mismatch],\n )\n const expired = expiresIn !== undefined && !(expiresIn > 0)\n const wasExpired = useRef(expired)\n const cooling = requestNewLinkIn > 0\n\n useFocusFirstInvalid({ alertRef, error, fieldErrors, formRef })\n\n useEffect(() => {\n if (expired && !wasExpired.current) titleRef.current?.focus()\n wasExpired.current = expired\n }, [expired])\n\n const footer = loginHref ? (\n <Button\n className=\"underline\"\n render={renderLink(loginHref)}\n size=\"sm\"\n variant=\"link\"\n >\n {labels.backToLogin}\n </Button>\n ) : undefined\n\n if (expired) {\n return (\n <AuthCard\n alertRef={alertRef}\n description={labels.expiredDescription}\n error={error}\n errorTitle={labels.errorTitle}\n footer={footer}\n logo={logo}\n title={labels.expiredTitle}\n titleRef={titleRef}\n >\n {onRequestNewLink ? (\n <Button\n className=\"w-full\"\n disabled={cooling || pending}\n onClick={() => {\n if (cooling || pending) return\n onRequestNewLink()\n }}\n type=\"button\"\n >\n {cooling\n ? labels.requestNewLinkIn(formatCountdown(requestNewLinkIn))\n : labels.requestNewLink}\n </Button>\n ) : null}\n </AuthCard>\n )\n }\n\n return (\n <AuthCard\n alertRef={alertRef}\n description={labels.description}\n error={error}\n errorTitle={labels.errorTitle}\n footer={footer}\n logo={logo}\n title={labels.title}\n >\n {expiresIn === undefined ? null : (\n <>\n <p className=\"text-muted-foreground text-sm tabular-nums\">\n {labels.linkExpiresIn(formatCountdown(expiresIn))}\n </p>\n <span aria-live=\"polite\" className=\"sr-only\">\n {expiresIn <= expiringSoonSeconds ? labels.expiringSoon : ''}\n </span>\n </>\n )}\n <Form\n aria-busy={pending}\n className=\"flex flex-col gap-4\"\n errors={errors}\n onFormSubmit={(values) => {\n if (pending) return\n if (values.password !== values.confirmPassword) {\n setMismatch(true)\n return\n }\n onSubmit(toResetPassword2Values(values))\n }}\n ref={formRef}\n >\n <AuthPasswordField\n autoComplete=\"new-password\"\n hideLabel={labels.hidePassword}\n label={labels.newPassword}\n minLength={passwordMinLength}\n name=\"password\"\n onValueChange={(value) => {\n setPassword(value)\n setMismatch(false)\n }}\n showLabel={labels.showPassword}\n >\n <AuthPasswordFeedback\n labels={labels}\n password={password}\n suggestions={passwordSuggestions}\n />\n </AuthPasswordField>\n <AuthPasswordField\n autoComplete=\"new-password\"\n hideLabel={labels.hidePassword}\n label={labels.confirmPassword}\n name=\"confirmPassword\"\n onValueChange={() => setMismatch(false)}\n showLabel={labels.showPassword}\n />\n <Button className=\"w-full\" loading={pending} type=\"submit\">\n {labels.submit}\n </Button>\n </Form>\n </AuthCard>\n )\n}\n",
|
|
27
|
+
"target": "~/packages/ui/src/blocks/application/auth/reset-password-2/reset-password-2.tsx"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "blocks/application/auth/reset-password-2/types.ts",
|
|
31
|
+
"type": "registry:file",
|
|
32
|
+
"content": "import type {\n AuthBaseProps,\n AuthCommonLabels,\n AuthFieldErrors,\n AuthNewPasswordLabels,\n AuthPasswordSuggestion,\n} from '../shared/types'\n\nexport interface ResetPassword2Values {\n password: string\n}\n\nexport interface ResetPassword2Labels\n extends Pick<\n AuthCommonLabels,\n 'errorTitle' | 'hidePassword' | 'showPassword'\n >,\n AuthNewPasswordLabels {\n backToLogin: string\n description: string\n expiredDescription: string\n expiredTitle: string\n expiringSoon: string\n linkExpiresIn: (time: string) => string\n newPassword: string\n requestNewLink: string\n requestNewLinkIn: (time: string) => string\n submit: string\n title: string\n}\n\nexport interface ResetPassword2Props\n extends AuthBaseProps<ResetPassword2Labels> {\n expiresIn?: number\n fieldErrors?: AuthFieldErrors<ResetPassword2Values>\n loginHref?: string\n onRequestNewLink?: () => void\n onSubmit: (values: ResetPassword2Values) => void\n passwordMinLength?: number\n passwordSuggestions?: AuthPasswordSuggestion[]\n requestNewLinkIn?: number\n}\n",
|
|
33
|
+
"target": "~/packages/ui/src/blocks/application/auth/reset-password-2/types.ts"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"path": "blocks/application/auth/shared/auth-card.tsx",
|
|
37
|
+
"type": "registry:file",
|
|
38
|
+
"content": "'use client'\n\nimport { Alert, AlertDescription, AlertTitle } from '@tc96/ui/alert'\nimport {\n Card,\n CardDescription,\n CardHeader,\n CardPanel,\n CardTitle,\n} from '@tc96/ui/card'\nimport type { ReactElement, ReactNode, Ref } from 'react'\n\nexport interface AuthCardProps {\n alertRef?: Ref<HTMLDivElement>\n children?: ReactNode\n description?: ReactNode\n error?: string\n errorTitle: string\n footer?: ReactNode\n logo?: ReactNode\n notice?: ReactNode\n title: ReactNode\n titleRef?: Ref<HTMLDivElement>\n}\n\nexport function AuthCard({\n alertRef,\n children,\n description,\n error,\n errorTitle,\n footer,\n logo,\n notice,\n title,\n titleRef,\n}: Readonly<AuthCardProps>): ReactElement {\n return (\n <main className=\"flex min-h-svh items-center justify-center p-4 sm:p-6\">\n <div className=\"flex w-full max-w-sm flex-col gap-6\">\n <Card>\n <CardHeader className=\"justify-items-center text-center\">\n {logo ? (\n <div className=\"mb-2 flex justify-center\">{logo}</div>\n ) : null}\n <CardTitle\n ref={titleRef}\n render={(props) => <h1 {...props} />}\n tabIndex={titleRef ? -1 : undefined}\n >\n {title}\n </CardTitle>\n {description ? (\n <CardDescription>{description}</CardDescription>\n ) : null}\n </CardHeader>\n <CardPanel className=\"flex flex-col gap-4\">\n {error ? (\n <Alert ref={alertRef} tabIndex={-1} variant=\"error\">\n <AlertTitle>{errorTitle}</AlertTitle>\n <AlertDescription>{error}</AlertDescription>\n </Alert>\n ) : null}\n {children}\n </CardPanel>\n </Card>\n {footer ? (\n <div\n className=\"flex flex-wrap items-center justify-center gap-1 text-muted-foreground text-sm\"\n data-slot=\"auth-footer\"\n >\n {footer}\n </div>\n ) : null}\n {notice}\n </div>\n </main>\n )\n}\n",
|
|
39
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/auth-card.tsx"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "blocks/application/auth/shared/auth-password-feedback.tsx",
|
|
43
|
+
"type": "registry:file",
|
|
44
|
+
"content": "'use client'\n\nimport { CheckIcon, CircleIcon } from '@phosphor-icons/react'\nimport { FieldDescription } from '@tc96/ui/field'\nimport { type ReactElement, useState } from 'react'\nimport { getPasswordSuggestions } from './password-suggestions'\nimport type { AuthNewPasswordLabels, AuthPasswordSuggestion } from './types'\n\nconst suggestionLabelKeys = {\n lowercase: 'suggestionLowercase',\n number: 'suggestionNumber',\n symbol: 'suggestionSymbol',\n uppercase: 'suggestionUppercase',\n} as const satisfies Record<AuthPasswordSuggestion, keyof AuthNewPasswordLabels>\n\nexport interface AuthPasswordFeedbackProps {\n labels: AuthNewPasswordLabels\n password: string\n suggestions: readonly AuthPasswordSuggestion[]\n}\n\ninterface FeedbackState {\n announcement: string\n met: readonly AuthPasswordSuggestion[]\n}\n\nexport function AuthPasswordFeedback({\n labels,\n password,\n suggestions,\n}: Readonly<AuthPasswordFeedbackProps>): ReactElement {\n const met = getPasswordSuggestions(password, suggestions)\n const [state, setState] = useState<FeedbackState>({\n announcement: '',\n met,\n })\n if (state.met.join() !== met.join()) {\n const messages: string[] = []\n for (const suggestion of suggestions) {\n const wasMet = state.met.includes(suggestion)\n const isMet = met.includes(suggestion)\n if (wasMet !== isMet)\n messages.push(\n `${labels[suggestionLabelKeys[suggestion]]}: ${isMet ? labels.suggestionMet : labels.suggestionMissing}`,\n )\n }\n setState({ announcement: messages.join('. '), met })\n }\n return (\n <>\n <FieldDescription className=\"flex flex-col gap-1.5\" render={<div />}>\n {suggestions.length ? (\n <ul className=\"flex gap-x-3 whitespace-nowrap text-xs\">\n {suggestions.map((suggestion) => {\n const isMet = met.includes(suggestion)\n return (\n <li\n className=\"flex items-center gap-1 transition-colors data-met:font-medium data-met:text-success-foreground\"\n data-met={isMet ? '' : undefined}\n key={suggestion}\n >\n {isMet ? (\n <CheckIcon aria-hidden className=\"size-3\" />\n ) : (\n <CircleIcon aria-hidden className=\"size-3\" />\n )}\n {labels[suggestionLabelKeys[suggestion]]}\n <span className=\"sr-only\">\n {` ${isMet ? labels.suggestionMet : labels.suggestionMissing}`}\n </span>\n </li>\n )\n })}\n </ul>\n ) : null}\n </FieldDescription>\n <div aria-live=\"polite\" className=\"sr-only\">\n {state.announcement}\n </div>\n </>\n )\n}\n",
|
|
45
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/auth-password-feedback.tsx"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"path": "blocks/application/auth/shared/auth-password-field.tsx",
|
|
49
|
+
"type": "registry:file",
|
|
50
|
+
"content": "'use client'\n\nimport { EyeIcon, EyeSlashIcon } from '@phosphor-icons/react'\nimport { Button } from '@tc96/ui/button'\nimport { Field, FieldError, FieldLabel } from '@tc96/ui/field'\nimport {\n InputGroup,\n InputGroupAddon,\n InputGroupInput,\n} from '@tc96/ui/input-group'\nimport { type ReactElement, type ReactNode, useState } from 'react'\n\nexport interface AuthPasswordFieldProps {\n autoComplete: 'current-password' | 'new-password'\n children?: ReactNode\n hideLabel: string\n label: string\n labelAction?: ReactNode\n minLength?: number\n name: string\n onValueChange?: (value: string) => void\n required?: boolean\n showLabel: string\n}\n\nexport function AuthPasswordField({\n autoComplete,\n children,\n hideLabel,\n label,\n labelAction,\n minLength,\n name,\n onValueChange,\n required = true,\n showLabel,\n}: Readonly<AuthPasswordFieldProps>): ReactElement {\n const [visible, setVisible] = useState(false)\n const toggleLabel = visible ? hideLabel : showLabel\n return (\n <Field name={name}>\n {labelAction ? (\n <div className=\"flex w-full items-center justify-between gap-2\">\n <FieldLabel>{label}</FieldLabel>\n {labelAction}\n </div>\n ) : (\n <FieldLabel>{label}</FieldLabel>\n )}\n <InputGroup>\n <InputGroupInput\n autoComplete={autoComplete}\n minLength={minLength}\n onValueChange={onValueChange}\n required={required}\n type={visible ? 'text' : 'password'}\n />\n <InputGroupAddon align=\"inline-end\">\n <Button\n aria-label={toggleLabel}\n onClick={() => setVisible((current) => !current)}\n size=\"sm\"\n title={toggleLabel}\n type=\"button\"\n variant=\"ghost\"\n >\n {visible ? <EyeSlashIcon aria-hidden /> : <EyeIcon aria-hidden />}\n </Button>\n </InputGroupAddon>\n </InputGroup>\n <FieldError />\n {children}\n </Field>\n )\n}\n",
|
|
51
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/auth-password-field.tsx"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"path": "blocks/application/auth/shared/labels.ts",
|
|
55
|
+
"type": "registry:file",
|
|
56
|
+
"content": "import type { AuthCommonLabels, AuthNewPasswordLabels } from './types'\n\nexport const defaultAuthCommonLabels: AuthCommonLabels = {\n email: 'E-mail',\n errorTitle: 'Não foi possível continuar',\n hidePassword: 'Ocultar senha',\n password: 'Senha',\n providerContinue: (label) => `Continuar com ${label}`,\n providersGroup: 'Entrar com outro serviço',\n providersSeparator: 'ou continue com e-mail',\n showPassword: 'Mostrar senha',\n}\n\nexport const defaultAuthNewPasswordLabels: AuthNewPasswordLabels = {\n confirmPassword: 'Confirmar senha',\n passwordMismatch: 'As senhas não coincidem.',\n suggestionLowercase: 'minúscula',\n suggestionMet: 'atendida',\n suggestionMissing: 'faltando',\n suggestionNumber: 'número',\n suggestionSymbol: 'símbolo',\n suggestionUppercase: 'maiúscula',\n}\n\nexport function resolveAuthLabels<TLabels>(\n defaults: TLabels,\n labels?: Partial<TLabels>,\n): TLabels {\n return { ...defaults, ...labels }\n}\n",
|
|
57
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/labels.ts"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"path": "blocks/application/auth/shared/password-suggestions.ts",
|
|
61
|
+
"type": "registry:file",
|
|
62
|
+
"content": "import type { AuthPasswordSuggestion } from './types'\n\nconst suggestionPatterns: Record<AuthPasswordSuggestion, RegExp> = {\n lowercase: /\\p{Ll}/u,\n number: /\\p{Nd}/u,\n symbol: /[^\\p{L}\\p{N}\\s]/u,\n uppercase: /\\p{Lu}/u,\n}\n\nexport const defaultPasswordSuggestions: AuthPasswordSuggestion[] = [\n 'lowercase',\n 'uppercase',\n 'number',\n 'symbol',\n]\n\nexport function getPasswordSuggestions(\n password: string,\n suggestions: readonly AuthPasswordSuggestion[],\n): AuthPasswordSuggestion[] {\n return suggestions.filter((suggestion) =>\n suggestionPatterns[suggestion].test(password),\n )\n}\n",
|
|
63
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/password-suggestions.ts"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"path": "blocks/application/auth/shared/to-form-errors.ts",
|
|
67
|
+
"type": "registry:file",
|
|
68
|
+
"content": "export function toFormErrors(\n fieldErrors?: Readonly<Partial<Record<string, string>>>,\n): Record<string, string> {\n const errors: Record<string, string> = {}\n for (const [name, message] of Object.entries(fieldErrors ?? {}))\n if (message) errors[name] = message\n return errors\n}\n",
|
|
69
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/to-form-errors.ts"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"path": "blocks/application/auth/shared/types.ts",
|
|
73
|
+
"type": "registry:file",
|
|
74
|
+
"content": "import type { RenderLink } from '@tc96/ui/render-anchor'\nimport type { ReactNode } from 'react'\n\nexport type AuthRenderLink = RenderLink\n\nexport interface AuthProvider {\n icon?: ReactNode\n id: string\n label: string\n}\n\nexport type AuthFieldErrors<TValues> = Partial<Record<keyof TValues, string>>\n\nexport type AuthPasswordSuggestion =\n | 'lowercase'\n | 'uppercase'\n | 'number'\n | 'symbol'\n\nexport interface AuthCommonLabels {\n email: string\n errorTitle: string\n hidePassword: string\n password: string\n providerContinue: (label: string) => string\n providersGroup: string\n providersSeparator: string\n showPassword: string\n}\n\nexport interface AuthNewPasswordLabels {\n confirmPassword: string\n passwordMismatch: string\n suggestionLowercase: string\n suggestionMet: string\n suggestionMissing: string\n suggestionNumber: string\n suggestionSymbol: string\n suggestionUppercase: string\n}\n\nexport interface AuthBaseProps<TLabels> {\n error?: string\n labels?: Partial<TLabels>\n logo?: ReactNode\n pending?: boolean\n renderLink?: AuthRenderLink\n}\n",
|
|
75
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/types.ts"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"path": "blocks/application/auth/shared/use-focus-first-invalid.ts",
|
|
79
|
+
"type": "registry:file",
|
|
80
|
+
"content": "'use client'\n\nimport { type RefObject, useEffect, useRef } from 'react'\nimport { toFormErrors } from './to-form-errors'\n\nexport interface UseFocusFirstInvalidOptions {\n alertRef: RefObject<HTMLElement | null>\n error?: string\n fieldErrors?: Readonly<Partial<Record<string, string>>>\n formRef: RefObject<HTMLFormElement | null>\n}\n\nfunction findFirstNamedControl(\n form: HTMLFormElement | null,\n names: readonly string[],\n): HTMLElement | undefined {\n return Array.from(form?.elements ?? []).find(\n (element): element is HTMLElement =>\n element instanceof HTMLElement &&\n !(element instanceof HTMLInputElement && element.type === 'hidden') &&\n names.includes(element.getAttribute('name') ?? ''),\n )\n}\n\nexport function useFocusFirstInvalid({\n alertRef,\n error,\n fieldErrors,\n formRef,\n}: UseFocusFirstInvalidOptions): void {\n const invalidNames = Object.keys(toFormErrors(fieldErrors)).join('\\n')\n const hasError = Boolean(error)\n const previous = useRef({ hasError, invalidNames })\n\n useEffect(() => {\n const before = previous.current\n previous.current = { hasError, invalidNames }\n const hasFieldErrors = invalidNames !== ''\n const filled =\n (hasFieldErrors && before.invalidNames === '') ||\n (hasError && !before.hasError)\n if (!filled) return\n const field = hasFieldErrors\n ? findFirstNamedControl(formRef.current, invalidNames.split('\\n'))\n : undefined\n if (field) field.focus()\n else if (hasError) alertRef.current?.focus()\n }, [alertRef, formRef, hasError, invalidNames])\n}\n",
|
|
81
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/use-focus-first-invalid.ts"
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
"dependencies": [
|
|
85
|
+
"@phosphor-icons/react@2.1.10",
|
|
86
|
+
"react@19.1.1"
|
|
87
|
+
],
|
|
88
|
+
"registryDependencies": [
|
|
89
|
+
"@ui/alert",
|
|
90
|
+
"@ui/button",
|
|
91
|
+
"@ui/card",
|
|
92
|
+
"@ui/field",
|
|
93
|
+
"@ui/form",
|
|
94
|
+
"@ui/input-group",
|
|
95
|
+
"@ui/render-anchor"
|
|
96
|
+
],
|
|
97
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json"
|
|
98
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "reset-password-6",
|
|
3
|
+
"type": "registry:block",
|
|
4
|
+
"files": [
|
|
5
|
+
{
|
|
6
|
+
"path": "blocks/application/auth/reset-password-6/index.ts",
|
|
7
|
+
"type": "registry:file",
|
|
8
|
+
"content": "export type {\n AuthBaseProps,\n AuthCommonLabels,\n AuthFieldErrors,\n AuthNewPasswordLabels,\n AuthPasswordSuggestion,\n AuthRenderLink,\n} from '../shared/types'\nexport { ResetPassword6 } from './reset-password-6'\nexport type {\n ResetPassword6Labels,\n ResetPassword6Props,\n ResetPassword6Values,\n} from './types'\n",
|
|
9
|
+
"target": "~/packages/ui/src/blocks/application/auth/reset-password-6/index.ts"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"path": "blocks/application/auth/reset-password-6/labels.ts",
|
|
13
|
+
"type": "registry:file",
|
|
14
|
+
"content": "import {\n defaultAuthCommonLabels,\n defaultAuthNewPasswordLabels,\n} from '../shared/labels'\nimport type { ResetPassword6Labels } from './types'\n\nexport const defaultResetPassword6Labels: ResetPassword6Labels = {\n ...defaultAuthNewPasswordLabels,\n backToLogin: 'Voltar para entrar',\n description: 'Escolha uma nova senha para a sua conta.',\n errorTitle: defaultAuthCommonLabels.errorTitle,\n hidePassword: defaultAuthCommonLabels.hidePassword,\n mediaLabel: 'Apresentação do produto',\n newPassword: 'Nova senha',\n showPassword: defaultAuthCommonLabels.showPassword,\n submit: 'Redefinir senha',\n title: 'Redefinir senha',\n}\n",
|
|
15
|
+
"target": "~/packages/ui/src/blocks/application/auth/reset-password-6/labels.ts"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "blocks/application/auth/reset-password-6/reset-password-6.tsx",
|
|
19
|
+
"type": "registry:file",
|
|
20
|
+
"content": "'use client'\n\nimport { Button } from '@tc96/ui/button'\nimport { Form } from '@tc96/ui/form'\nimport { renderAnchor } from '@tc96/ui/render-anchor'\nimport { type ReactElement, useMemo, useRef, useState } from 'react'\nimport { AuthPasswordFeedback } from '../shared/auth-password-feedback'\nimport { AuthPasswordField } from '../shared/auth-password-field'\nimport { AuthSplitLayout } from '../shared/auth-split-layout'\nimport { resolveAuthLabels } from '../shared/labels'\nimport { defaultPasswordSuggestions } from '../shared/password-suggestions'\nimport { toFormErrors } from '../shared/to-form-errors'\nimport { useFocusFirstInvalid } from '../shared/use-focus-first-invalid'\nimport { defaultResetPassword6Labels } from './labels'\nimport type { ResetPassword6Props, ResetPassword6Values } from './types'\n\nfunction toResetPassword6Values(\n values: Readonly<Record<string, unknown>>,\n): ResetPassword6Values {\n return { password: String(values.password ?? '') }\n}\n\nexport function ResetPassword6({\n error,\n fieldErrors,\n labels: labelsProp,\n loginHref,\n logo,\n media,\n onSubmit,\n passwordMinLength = 8,\n passwordSuggestions = defaultPasswordSuggestions,\n pending = false,\n renderLink = renderAnchor,\n}: Readonly<ResetPassword6Props>): ReactElement {\n const labels = resolveAuthLabels(defaultResetPassword6Labels, labelsProp)\n const formRef = useRef<HTMLFormElement>(null)\n const alertRef = useRef<HTMLDivElement>(null)\n const [password, setPassword] = useState('')\n const [mismatch, setMismatch] = useState(false)\n const errors = useMemo(\n () => ({\n ...toFormErrors(fieldErrors),\n ...(mismatch ? { confirmPassword: labels.passwordMismatch } : undefined),\n }),\n [fieldErrors, labels.passwordMismatch, mismatch],\n )\n\n useFocusFirstInvalid({ alertRef, error, fieldErrors, formRef })\n\n return (\n <AuthSplitLayout\n alertRef={alertRef}\n description={labels.description}\n error={error}\n errorTitle={labels.errorTitle}\n footer={\n loginHref ? (\n <Button\n className=\"underline\"\n render={renderLink(loginHref)}\n size=\"sm\"\n variant=\"link\"\n >\n {labels.backToLogin}\n </Button>\n ) : undefined\n }\n logo={logo}\n media={media}\n mediaLabel={labels.mediaLabel}\n title={labels.title}\n >\n <Form\n aria-busy={pending}\n className=\"flex flex-col gap-4\"\n errors={errors}\n onFormSubmit={(values) => {\n if (pending) return\n if (values.password !== values.confirmPassword) {\n setMismatch(true)\n return\n }\n onSubmit(toResetPassword6Values(values))\n }}\n ref={formRef}\n >\n <AuthPasswordField\n autoComplete=\"new-password\"\n hideLabel={labels.hidePassword}\n label={labels.newPassword}\n minLength={passwordMinLength}\n name=\"password\"\n onValueChange={(value) => {\n setPassword(value)\n setMismatch(false)\n }}\n showLabel={labels.showPassword}\n >\n <AuthPasswordFeedback\n labels={labels}\n password={password}\n suggestions={passwordSuggestions}\n />\n </AuthPasswordField>\n <AuthPasswordField\n autoComplete=\"new-password\"\n hideLabel={labels.hidePassword}\n label={labels.confirmPassword}\n name=\"confirmPassword\"\n onValueChange={() => setMismatch(false)}\n showLabel={labels.showPassword}\n />\n <Button className=\"w-full\" loading={pending} type=\"submit\">\n {labels.submit}\n </Button>\n </Form>\n </AuthSplitLayout>\n )\n}\n",
|
|
21
|
+
"target": "~/packages/ui/src/blocks/application/auth/reset-password-6/reset-password-6.tsx"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "blocks/application/auth/reset-password-6/types.ts",
|
|
25
|
+
"type": "registry:file",
|
|
26
|
+
"content": "import type { ReactNode } from 'react'\nimport type {\n AuthBaseProps,\n AuthCommonLabels,\n AuthFieldErrors,\n AuthNewPasswordLabels,\n AuthPasswordSuggestion,\n} from '../shared/types'\n\nexport interface ResetPassword6Values {\n password: string\n}\n\nexport interface ResetPassword6Labels\n extends Pick<\n AuthCommonLabels,\n 'errorTitle' | 'hidePassword' | 'showPassword'\n >,\n AuthNewPasswordLabels {\n backToLogin: string\n description: string\n mediaLabel: string\n newPassword: string\n submit: string\n title: string\n}\n\nexport interface ResetPassword6Props\n extends AuthBaseProps<ResetPassword6Labels> {\n fieldErrors?: AuthFieldErrors<ResetPassword6Values>\n loginHref?: string\n media?: ReactNode\n onSubmit: (values: ResetPassword6Values) => void\n passwordMinLength?: number\n passwordSuggestions?: AuthPasswordSuggestion[]\n}\n",
|
|
27
|
+
"target": "~/packages/ui/src/blocks/application/auth/reset-password-6/types.ts"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "blocks/application/auth/shared/auth-password-feedback.tsx",
|
|
31
|
+
"type": "registry:file",
|
|
32
|
+
"content": "'use client'\n\nimport { CheckIcon, CircleIcon } from '@phosphor-icons/react'\nimport { FieldDescription } from '@tc96/ui/field'\nimport { type ReactElement, useState } from 'react'\nimport { getPasswordSuggestions } from './password-suggestions'\nimport type { AuthNewPasswordLabels, AuthPasswordSuggestion } from './types'\n\nconst suggestionLabelKeys = {\n lowercase: 'suggestionLowercase',\n number: 'suggestionNumber',\n symbol: 'suggestionSymbol',\n uppercase: 'suggestionUppercase',\n} as const satisfies Record<AuthPasswordSuggestion, keyof AuthNewPasswordLabels>\n\nexport interface AuthPasswordFeedbackProps {\n labels: AuthNewPasswordLabels\n password: string\n suggestions: readonly AuthPasswordSuggestion[]\n}\n\ninterface FeedbackState {\n announcement: string\n met: readonly AuthPasswordSuggestion[]\n}\n\nexport function AuthPasswordFeedback({\n labels,\n password,\n suggestions,\n}: Readonly<AuthPasswordFeedbackProps>): ReactElement {\n const met = getPasswordSuggestions(password, suggestions)\n const [state, setState] = useState<FeedbackState>({\n announcement: '',\n met,\n })\n if (state.met.join() !== met.join()) {\n const messages: string[] = []\n for (const suggestion of suggestions) {\n const wasMet = state.met.includes(suggestion)\n const isMet = met.includes(suggestion)\n if (wasMet !== isMet)\n messages.push(\n `${labels[suggestionLabelKeys[suggestion]]}: ${isMet ? labels.suggestionMet : labels.suggestionMissing}`,\n )\n }\n setState({ announcement: messages.join('. '), met })\n }\n return (\n <>\n <FieldDescription className=\"flex flex-col gap-1.5\" render={<div />}>\n {suggestions.length ? (\n <ul className=\"flex gap-x-3 whitespace-nowrap text-xs\">\n {suggestions.map((suggestion) => {\n const isMet = met.includes(suggestion)\n return (\n <li\n className=\"flex items-center gap-1 transition-colors data-met:font-medium data-met:text-success-foreground\"\n data-met={isMet ? '' : undefined}\n key={suggestion}\n >\n {isMet ? (\n <CheckIcon aria-hidden className=\"size-3\" />\n ) : (\n <CircleIcon aria-hidden className=\"size-3\" />\n )}\n {labels[suggestionLabelKeys[suggestion]]}\n <span className=\"sr-only\">\n {` ${isMet ? labels.suggestionMet : labels.suggestionMissing}`}\n </span>\n </li>\n )\n })}\n </ul>\n ) : null}\n </FieldDescription>\n <div aria-live=\"polite\" className=\"sr-only\">\n {state.announcement}\n </div>\n </>\n )\n}\n",
|
|
33
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/auth-password-feedback.tsx"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"path": "blocks/application/auth/shared/auth-password-field.tsx",
|
|
37
|
+
"type": "registry:file",
|
|
38
|
+
"content": "'use client'\n\nimport { EyeIcon, EyeSlashIcon } from '@phosphor-icons/react'\nimport { Button } from '@tc96/ui/button'\nimport { Field, FieldError, FieldLabel } from '@tc96/ui/field'\nimport {\n InputGroup,\n InputGroupAddon,\n InputGroupInput,\n} from '@tc96/ui/input-group'\nimport { type ReactElement, type ReactNode, useState } from 'react'\n\nexport interface AuthPasswordFieldProps {\n autoComplete: 'current-password' | 'new-password'\n children?: ReactNode\n hideLabel: string\n label: string\n labelAction?: ReactNode\n minLength?: number\n name: string\n onValueChange?: (value: string) => void\n required?: boolean\n showLabel: string\n}\n\nexport function AuthPasswordField({\n autoComplete,\n children,\n hideLabel,\n label,\n labelAction,\n minLength,\n name,\n onValueChange,\n required = true,\n showLabel,\n}: Readonly<AuthPasswordFieldProps>): ReactElement {\n const [visible, setVisible] = useState(false)\n const toggleLabel = visible ? hideLabel : showLabel\n return (\n <Field name={name}>\n {labelAction ? (\n <div className=\"flex w-full items-center justify-between gap-2\">\n <FieldLabel>{label}</FieldLabel>\n {labelAction}\n </div>\n ) : (\n <FieldLabel>{label}</FieldLabel>\n )}\n <InputGroup>\n <InputGroupInput\n autoComplete={autoComplete}\n minLength={minLength}\n onValueChange={onValueChange}\n required={required}\n type={visible ? 'text' : 'password'}\n />\n <InputGroupAddon align=\"inline-end\">\n <Button\n aria-label={toggleLabel}\n onClick={() => setVisible((current) => !current)}\n size=\"sm\"\n title={toggleLabel}\n type=\"button\"\n variant=\"ghost\"\n >\n {visible ? <EyeSlashIcon aria-hidden /> : <EyeIcon aria-hidden />}\n </Button>\n </InputGroupAddon>\n </InputGroup>\n <FieldError />\n {children}\n </Field>\n )\n}\n",
|
|
39
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/auth-password-field.tsx"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "blocks/application/auth/shared/auth-split-layout.tsx",
|
|
43
|
+
"type": "registry:file",
|
|
44
|
+
"content": "'use client'\n\nimport { Alert, AlertDescription, AlertTitle } from '@tc96/ui/alert'\nimport type { ReactElement, ReactNode, Ref } from 'react'\n\nexport interface AuthSplitLayoutProps {\n alertRef?: Ref<HTMLDivElement>\n children: ReactNode\n description?: ReactNode\n error?: string\n errorTitle: string\n footer?: ReactNode\n logo?: ReactNode\n media?: ReactNode\n mediaLabel: string\n title: ReactNode\n titleRef?: Ref<HTMLHeadingElement>\n}\n\nexport function AuthSplitLayout({\n alertRef,\n children,\n description,\n error,\n errorTitle,\n footer,\n logo,\n media,\n mediaLabel,\n title,\n titleRef,\n}: Readonly<AuthSplitLayoutProps>): ReactElement {\n return (\n <div className=\"grid min-h-svh md:grid-cols-2\">\n <main className=\"flex flex-col gap-6 p-6 md:p-10\">\n {logo ? <div className=\"flex\">{logo}</div> : null}\n <div className=\"flex flex-1 items-center justify-center\">\n <div className=\"flex w-full max-w-sm flex-col gap-6\">\n <div className=\"flex flex-col gap-1\">\n <h1\n className=\"font-semibold text-2xl outline-none\"\n ref={titleRef}\n tabIndex={titleRef ? -1 : undefined}\n >\n {title}\n </h1>\n {description ? (\n <p className=\"text-muted-foreground text-sm\">{description}</p>\n ) : null}\n </div>\n {error ? (\n <Alert ref={alertRef} tabIndex={-1} variant=\"error\">\n <AlertTitle>{errorTitle}</AlertTitle>\n <AlertDescription>{error}</AlertDescription>\n </Alert>\n ) : null}\n {children}\n {footer ? (\n <div\n className=\"mt-6 flex flex-wrap items-center gap-1 text-muted-foreground text-sm\"\n data-slot=\"auth-footer\"\n >\n {footer}\n </div>\n ) : null}\n </div>\n </div>\n </main>\n {media ? (\n <aside\n aria-label={mediaLabel}\n className=\"hidden p-4 md:flex md:flex-col\"\n >\n <div className=\"flex-1 overflow-hidden rounded-xl border\">\n {media}\n </div>\n </aside>\n ) : null}\n </div>\n )\n}\n",
|
|
45
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/auth-split-layout.tsx"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"path": "blocks/application/auth/shared/labels.ts",
|
|
49
|
+
"type": "registry:file",
|
|
50
|
+
"content": "import type { AuthCommonLabels, AuthNewPasswordLabels } from './types'\n\nexport const defaultAuthCommonLabels: AuthCommonLabels = {\n email: 'E-mail',\n errorTitle: 'Não foi possível continuar',\n hidePassword: 'Ocultar senha',\n password: 'Senha',\n providerContinue: (label) => `Continuar com ${label}`,\n providersGroup: 'Entrar com outro serviço',\n providersSeparator: 'ou continue com e-mail',\n showPassword: 'Mostrar senha',\n}\n\nexport const defaultAuthNewPasswordLabels: AuthNewPasswordLabels = {\n confirmPassword: 'Confirmar senha',\n passwordMismatch: 'As senhas não coincidem.',\n suggestionLowercase: 'minúscula',\n suggestionMet: 'atendida',\n suggestionMissing: 'faltando',\n suggestionNumber: 'número',\n suggestionSymbol: 'símbolo',\n suggestionUppercase: 'maiúscula',\n}\n\nexport function resolveAuthLabels<TLabels>(\n defaults: TLabels,\n labels?: Partial<TLabels>,\n): TLabels {\n return { ...defaults, ...labels }\n}\n",
|
|
51
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/labels.ts"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"path": "blocks/application/auth/shared/password-suggestions.ts",
|
|
55
|
+
"type": "registry:file",
|
|
56
|
+
"content": "import type { AuthPasswordSuggestion } from './types'\n\nconst suggestionPatterns: Record<AuthPasswordSuggestion, RegExp> = {\n lowercase: /\\p{Ll}/u,\n number: /\\p{Nd}/u,\n symbol: /[^\\p{L}\\p{N}\\s]/u,\n uppercase: /\\p{Lu}/u,\n}\n\nexport const defaultPasswordSuggestions: AuthPasswordSuggestion[] = [\n 'lowercase',\n 'uppercase',\n 'number',\n 'symbol',\n]\n\nexport function getPasswordSuggestions(\n password: string,\n suggestions: readonly AuthPasswordSuggestion[],\n): AuthPasswordSuggestion[] {\n return suggestions.filter((suggestion) =>\n suggestionPatterns[suggestion].test(password),\n )\n}\n",
|
|
57
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/password-suggestions.ts"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"path": "blocks/application/auth/shared/to-form-errors.ts",
|
|
61
|
+
"type": "registry:file",
|
|
62
|
+
"content": "export function toFormErrors(\n fieldErrors?: Readonly<Partial<Record<string, string>>>,\n): Record<string, string> {\n const errors: Record<string, string> = {}\n for (const [name, message] of Object.entries(fieldErrors ?? {}))\n if (message) errors[name] = message\n return errors\n}\n",
|
|
63
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/to-form-errors.ts"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"path": "blocks/application/auth/shared/types.ts",
|
|
67
|
+
"type": "registry:file",
|
|
68
|
+
"content": "import type { RenderLink } from '@tc96/ui/render-anchor'\nimport type { ReactNode } from 'react'\n\nexport type AuthRenderLink = RenderLink\n\nexport interface AuthProvider {\n icon?: ReactNode\n id: string\n label: string\n}\n\nexport type AuthFieldErrors<TValues> = Partial<Record<keyof TValues, string>>\n\nexport type AuthPasswordSuggestion =\n | 'lowercase'\n | 'uppercase'\n | 'number'\n | 'symbol'\n\nexport interface AuthCommonLabels {\n email: string\n errorTitle: string\n hidePassword: string\n password: string\n providerContinue: (label: string) => string\n providersGroup: string\n providersSeparator: string\n showPassword: string\n}\n\nexport interface AuthNewPasswordLabels {\n confirmPassword: string\n passwordMismatch: string\n suggestionLowercase: string\n suggestionMet: string\n suggestionMissing: string\n suggestionNumber: string\n suggestionSymbol: string\n suggestionUppercase: string\n}\n\nexport interface AuthBaseProps<TLabels> {\n error?: string\n labels?: Partial<TLabels>\n logo?: ReactNode\n pending?: boolean\n renderLink?: AuthRenderLink\n}\n",
|
|
69
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/types.ts"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"path": "blocks/application/auth/shared/use-focus-first-invalid.ts",
|
|
73
|
+
"type": "registry:file",
|
|
74
|
+
"content": "'use client'\n\nimport { type RefObject, useEffect, useRef } from 'react'\nimport { toFormErrors } from './to-form-errors'\n\nexport interface UseFocusFirstInvalidOptions {\n alertRef: RefObject<HTMLElement | null>\n error?: string\n fieldErrors?: Readonly<Partial<Record<string, string>>>\n formRef: RefObject<HTMLFormElement | null>\n}\n\nfunction findFirstNamedControl(\n form: HTMLFormElement | null,\n names: readonly string[],\n): HTMLElement | undefined {\n return Array.from(form?.elements ?? []).find(\n (element): element is HTMLElement =>\n element instanceof HTMLElement &&\n !(element instanceof HTMLInputElement && element.type === 'hidden') &&\n names.includes(element.getAttribute('name') ?? ''),\n )\n}\n\nexport function useFocusFirstInvalid({\n alertRef,\n error,\n fieldErrors,\n formRef,\n}: UseFocusFirstInvalidOptions): void {\n const invalidNames = Object.keys(toFormErrors(fieldErrors)).join('\\n')\n const hasError = Boolean(error)\n const previous = useRef({ hasError, invalidNames })\n\n useEffect(() => {\n const before = previous.current\n previous.current = { hasError, invalidNames }\n const hasFieldErrors = invalidNames !== ''\n const filled =\n (hasFieldErrors && before.invalidNames === '') ||\n (hasError && !before.hasError)\n if (!filled) return\n const field = hasFieldErrors\n ? findFirstNamedControl(formRef.current, invalidNames.split('\\n'))\n : undefined\n if (field) field.focus()\n else if (hasError) alertRef.current?.focus()\n }, [alertRef, formRef, hasError, invalidNames])\n}\n",
|
|
75
|
+
"target": "~/packages/ui/src/blocks/application/auth/shared/use-focus-first-invalid.ts"
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
"dependencies": [
|
|
79
|
+
"@phosphor-icons/react@2.1.10",
|
|
80
|
+
"react@19.1.1"
|
|
81
|
+
],
|
|
82
|
+
"registryDependencies": [
|
|
83
|
+
"@ui/alert",
|
|
84
|
+
"@ui/button",
|
|
85
|
+
"@ui/field",
|
|
86
|
+
"@ui/form",
|
|
87
|
+
"@ui/input-group",
|
|
88
|
+
"@ui/render-anchor"
|
|
89
|
+
],
|
|
90
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json"
|
|
91
|
+
}
|