@alepha/ui 0.36.1 → 0.37.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/dist/account/$pageAccount.d.ts +1 -1
- package/dist/account/$pageAccount.d.ts.map +1 -1
- package/dist/account/$pageAccount.js.map +1 -1
- package/dist/account/AccountDisplay.d.ts +13 -0
- package/dist/account/AccountDisplay.d.ts.map +1 -0
- package/dist/account/AccountDisplay.js +48 -0
- package/dist/account/AccountDisplay.js.map +1 -0
- package/dist/account/AccountProfile.d.ts.map +1 -1
- package/dist/account/AccountProfile.js +14 -10
- package/dist/account/AccountProfile.js.map +1 -1
- package/dist/account/AccountRouter.d.ts +6 -6
- package/dist/account/AccountRouter.d.ts.map +1 -1
- package/dist/account/index.d.ts +5 -0
- package/dist/account/index.d.ts.map +1 -1
- package/dist/account/index.js +2 -1
- package/dist/admin/$pageAdmin.d.ts +1 -1
- package/dist/admin/$pageAdmin.d.ts.map +1 -1
- package/dist/admin/$pageAdmin.js.map +1 -1
- package/dist/admin/AdminAudits.js.map +1 -1
- package/dist/admin/AdminJobDetail.js.map +1 -1
- package/dist/admin/AdminJobs.js.map +1 -1
- package/dist/admin/AdminNotifications.js.map +1 -1
- package/dist/admin/AdminRouter.d.ts +14 -14
- package/dist/admin/AdminRouter.d.ts.map +1 -1
- package/dist/admin/AdminUserDetail.js.map +1 -1
- package/dist/admin/AdminUsers.js.map +1 -1
- package/dist/admin/ParameterHistoryItem.js.map +1 -1
- package/dist/ai/AiChat.d.ts +26 -39
- package/dist/ai/AiChat.d.ts.map +1 -1
- package/dist/ai/AiChat.js +65 -123
- package/dist/ai/AiChat.js.map +1 -1
- package/dist/ai/AiChatDock.d.ts +23 -0
- package/dist/ai/AiChatDock.d.ts.map +1 -0
- package/dist/ai/AiChatDock.js +90 -0
- package/dist/ai/AiChatDock.js.map +1 -0
- package/dist/ai/AiChatDockSlot.d.ts +15 -0
- package/dist/ai/AiChatDockSlot.d.ts.map +1 -0
- package/dist/ai/AiChatDockSlot.js +20 -0
- package/dist/ai/AiChatDockSlot.js.map +1 -0
- package/dist/ai/AiChatLauncher.d.ts +17 -0
- package/dist/ai/AiChatLauncher.d.ts.map +1 -0
- package/dist/ai/AiChatLauncher.js +42 -0
- package/dist/ai/AiChatLauncher.js.map +1 -0
- package/dist/ai/AiChatMessage.d.ts +6 -0
- package/dist/ai/AiChatMessage.d.ts.map +1 -1
- package/dist/ai/AiChatMessage.js +20 -4
- package/dist/ai/AiChatMessage.js.map +1 -1
- package/dist/ai/AiChatPanel.d.ts +71 -0
- package/dist/ai/AiChatPanel.d.ts.map +1 -0
- package/dist/ai/AiChatPanel.js +143 -0
- package/dist/ai/AiChatPanel.js.map +1 -0
- package/dist/ai/index.d.ts +8 -4
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +5 -1
- package/dist/ai/useAiChat.d.ts +12 -0
- package/dist/ai/useAiChat.d.ts.map +1 -1
- package/dist/ai/useAiChat.js +32 -15
- package/dist/ai/useAiChat.js.map +1 -1
- package/dist/auth/AuthLogin.d.ts +9 -0
- package/dist/auth/AuthLogin.d.ts.map +1 -1
- package/dist/auth/AuthLogin.js +2 -2
- package/dist/auth/AuthLogin.js.map +1 -1
- package/dist/auth/AuthRegister.d.ts +4 -1
- package/dist/auth/AuthRegister.d.ts.map +1 -1
- package/dist/auth/AuthRegister.js +1 -1
- package/dist/auth/AuthRegister.js.map +1 -1
- package/dist/auth/AuthResetPassword.d.ts +8 -0
- package/dist/auth/AuthResetPassword.d.ts.map +1 -1
- package/dist/auth/AuthResetPassword.js +2 -2
- package/dist/auth/AuthResetPassword.js.map +1 -1
- package/dist/auth/AuthRouter.d.ts +4 -4
- package/dist/auth/AuthRouter.d.ts.map +1 -1
- package/dist/core/Badge.d.ts.map +1 -1
- package/dist/core/Badge.js +7 -3
- package/dist/core/Badge.js.map +1 -1
- package/dist/core/Collapsible.d.ts +50 -0
- package/dist/core/Collapsible.d.ts.map +1 -0
- package/dist/core/Collapsible.js +70 -0
- package/dist/core/Collapsible.js.map +1 -0
- package/dist/core/Combobox.d.ts +7 -1
- package/dist/core/Combobox.d.ts.map +1 -1
- package/dist/core/Combobox.js +2 -2
- package/dist/core/Combobox.js.map +1 -1
- package/dist/core/PaneRail.d.ts +24 -7
- package/dist/core/PaneRail.d.ts.map +1 -1
- package/dist/core/PaneRail.js +24 -19
- package/dist/core/PaneRail.js.map +1 -1
- package/dist/core/Stepper.d.ts +36 -0
- package/dist/core/Stepper.d.ts.map +1 -0
- package/dist/core/Stepper.js +54 -0
- package/dist/core/Stepper.js.map +1 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +3 -1
- package/dist/core/useToast.js +13 -13
- package/dist/core/useToast.js.map +1 -1
- package/dist/form/AutoForm.d.ts.map +1 -1
- package/dist/form/AutoForm.js +29 -0
- package/dist/form/AutoForm.js.map +1 -1
- package/dist/form/AutoFormErrorPopover.js +13 -3
- package/dist/form/AutoFormErrorPopover.js.map +1 -1
- package/dist/form/Control.d.ts +14 -1
- package/dist/form/Control.d.ts.map +1 -1
- package/dist/form/Control.js +12 -2
- package/dist/form/Control.js.map +1 -1
- package/dist/form/ControlDate.d.ts.map +1 -1
- package/dist/form/ControlDate.js +3 -0
- package/dist/form/ControlDate.js.map +1 -1
- package/dist/form/ControlDateRange.d.ts +12 -1
- package/dist/form/ControlDateRange.d.ts.map +1 -1
- package/dist/form/ControlDateRange.js +11 -1
- package/dist/form/ControlDateRange.js.map +1 -1
- package/dist/form/ControlNumber.d.ts.map +1 -1
- package/dist/form/ControlNumber.js +2 -0
- package/dist/form/ControlNumber.js.map +1 -1
- package/dist/form/ControlObject.d.ts.map +1 -1
- package/dist/form/ControlObject.js +15 -1
- package/dist/form/ControlObject.js.map +1 -1
- package/dist/form/ControlPassword.d.ts +4 -0
- package/dist/form/ControlPassword.d.ts.map +1 -1
- package/dist/form/ControlPassword.js +1 -0
- package/dist/form/ControlPassword.js.map +1 -1
- package/dist/form/ControlSelect.d.ts +23 -1
- package/dist/form/ControlSelect.d.ts.map +1 -1
- package/dist/form/ControlSelect.js +5 -0
- package/dist/form/ControlSelect.js.map +1 -1
- package/dist/form/ControlSelectCombobox.d.ts +11 -1
- package/dist/form/ControlSelectCombobox.d.ts.map +1 -1
- package/dist/form/ControlSelectCombobox.js +9 -1
- package/dist/form/ControlSelectCombobox.js.map +1 -1
- package/dist/form/ControlUpload.d.ts.map +1 -1
- package/dist/form/ControlUpload.js +1 -0
- package/dist/form/ControlUpload.js.map +1 -1
- package/dist/form/FormField.d.ts +5 -0
- package/dist/form/FormField.d.ts.map +1 -1
- package/dist/form/FormField.js +7 -0
- package/dist/form/FormField.js.map +1 -1
- package/dist/i18n/fr/uiFr.d.ts.map +1 -1
- package/dist/i18n/fr/uiFr.js +14 -0
- package/dist/i18n/fr/uiFr.js.map +1 -1
- package/dist/shell/$pageNav.d.ts +2 -2
- package/dist/shell/$pageNav.d.ts.map +1 -1
- package/dist/shell/$pageNav.js.map +1 -1
- package/dist/shell/AppShell.d.ts +6 -0
- package/dist/shell/AppShell.d.ts.map +1 -1
- package/dist/shell/AppShell.js +31 -27
- package/dist/shell/AppShell.js.map +1 -1
- package/dist/shell/ButtonSettings.d.ts +6 -2
- package/dist/shell/ButtonSettings.d.ts.map +1 -1
- package/dist/shell/ButtonSettings.js +17 -3
- package/dist/shell/ButtonSettings.js.map +1 -1
- package/dist/shell/ButtonSettingsVisionMenuItem.d.ts +16 -0
- package/dist/shell/ButtonSettingsVisionMenuItem.d.ts.map +1 -0
- package/dist/shell/ButtonSettingsVisionMenuItem.js +24 -0
- package/dist/shell/ButtonSettingsVisionMenuItem.js.map +1 -0
- package/dist/shell/ButtonVision.d.ts +28 -0
- package/dist/shell/ButtonVision.d.ts.map +1 -0
- package/dist/shell/ButtonVision.js +46 -0
- package/dist/shell/ButtonVision.js.map +1 -0
- package/dist/shell/index.d.ts +6 -3
- package/dist/shell/index.d.ts.map +1 -1
- package/dist/shell/index.js +2 -1
- package/dist/styles.css +57 -0
- package/dist/table/DataTable.d.ts.map +1 -1
- package/dist/table/DataTable.js +29 -4
- package/dist/table/DataTable.js.map +1 -1
- package/dist/table/DataTableColumnPicker.d.ts.map +1 -1
- package/dist/table/DataTableColumnPicker.js +1 -0
- package/dist/table/DataTableColumnPicker.js.map +1 -1
- package/dist/table/DataTableFilterBar.d.ts +1 -1
- package/dist/table/DataTableFilterBar.d.ts.map +1 -1
- package/dist/table/DataTableFilterBar.js +5 -108
- package/dist/table/DataTableFilterBar.js.map +1 -1
- package/dist/table/DataTableHeaderFilter.d.ts +51 -0
- package/dist/table/DataTableHeaderFilter.d.ts.map +1 -0
- package/dist/table/DataTableHeaderFilter.js +113 -0
- package/dist/table/DataTableHeaderFilter.js.map +1 -0
- package/dist/table/DataTableHeaderRow.d.ts +7 -0
- package/dist/table/DataTableHeaderRow.d.ts.map +1 -1
- package/dist/table/DataTableHeaderRow.js +92 -74
- package/dist/table/DataTableHeaderRow.js.map +1 -1
- package/dist/table/DataTableTabs.d.ts +42 -0
- package/dist/table/DataTableTabs.d.ts.map +1 -0
- package/dist/table/DataTableTabs.js +55 -0
- package/dist/table/DataTableTabs.js.map +1 -0
- package/dist/table/dataTableBaseProps.d.ts +12 -0
- package/dist/table/dataTableBaseProps.d.ts.map +1 -1
- package/dist/table/dataTablePersistence.d.ts.map +1 -1
- package/dist/table/dataTablePersistence.js +4 -2
- package/dist/table/dataTablePersistence.js.map +1 -1
- package/dist/table/dataTableTypes.d.ts +18 -0
- package/dist/table/dataTableTypes.d.ts.map +1 -1
- package/dist/table/index.d.ts +5 -2
- package/dist/table/index.d.ts.map +1 -1
- package/dist/table/index.js +2 -1
- package/dist/table/useDataTableColumns.d.ts.map +1 -1
- package/dist/table/useDataTableColumns.js +1 -0
- package/dist/table/useDataTableColumns.js.map +1 -1
- package/dist/table/useDataTableFilterModel.d.ts +110 -0
- package/dist/table/useDataTableFilterModel.d.ts.map +1 -0
- package/dist/table/useDataTableFilterModel.js +154 -0
- package/dist/table/useDataTableFilterModel.js.map +1 -0
- package/docs/packages-alepha-ui-account.md +4 -0
- package/docs/packages-alepha-ui-ai.md +5 -5
- package/docs/packages-alepha-ui-shell.md +4 -3
- package/docs/packages-alepha-ui-table.md +4 -2
- package/package.json +8 -8
- package/src/account/$pageAccount.tsx +5 -4
- package/src/account/AccountDisplay.tsx +58 -0
- package/src/account/AccountProfile.tsx +30 -42
- package/src/account/__tests__/AccountProfile.browser.spec.tsx +141 -0
- package/src/account/__tests__/AccountRecoveryCodes.browser.spec.tsx +1 -1
- package/src/account/index.ts +5 -0
- package/src/admin/$pageAdmin.tsx +5 -4
- package/src/admin/AdminAudits.tsx +1 -1
- package/src/admin/AdminJobDetail.tsx +1 -1
- package/src/admin/AdminJobs.tsx +1 -1
- package/src/admin/AdminNotifications.tsx +1 -1
- package/src/admin/AdminUserDetail.tsx +1 -1
- package/src/admin/AdminUsers.tsx +1 -1
- package/src/admin/ParameterHistoryItem.tsx +1 -1
- package/src/admin/__tests__/AdminFilesUsageCard.browser.spec.tsx +17 -9
- package/src/ai/AiChat.tsx +94 -183
- package/src/ai/AiChatDock.tsx +129 -0
- package/src/ai/AiChatDockSlot.tsx +23 -0
- package/src/ai/AiChatLauncher.tsx +58 -0
- package/src/ai/AiChatMessage.tsx +36 -2
- package/src/ai/AiChatPanel.tsx +252 -0
- package/src/ai/__tests__/AiChat.browser.spec.tsx +187 -5
- package/src/ai/index.ts +8 -4
- package/src/ai/useAiChat.ts +63 -14
- package/src/auth/AuthLogin.tsx +19 -4
- package/src/auth/AuthRegister.tsx +6 -3
- package/src/auth/AuthResetPassword.tsx +18 -8
- package/src/auth/__tests__/AuthCancel.browser.spec.tsx +129 -0
- package/src/core/Badge.tsx +7 -3
- package/src/core/Collapsible.tsx +95 -0
- package/src/core/Combobox.tsx +11 -3
- package/src/core/PaneRail.tsx +36 -20
- package/src/core/Stepper.tsx +118 -0
- package/src/core/__tests__/Badge.browser.spec.tsx +5 -5
- package/src/core/__tests__/Collapsible.browser.spec.tsx +88 -0
- package/src/core/__tests__/PaneRail.browser.spec.tsx +48 -0
- package/src/core/__tests__/Stepper.browser.spec.tsx +39 -0
- package/src/core/__tests__/primitiveSlots.spec.ts +7 -0
- package/src/core/index.ts +15 -0
- package/src/form/AutoForm.tsx +32 -0
- package/src/form/AutoFormErrorPopover.tsx +27 -6
- package/src/form/Control.tsx +22 -0
- package/src/form/ControlDate.tsx +3 -0
- package/src/form/ControlDateRange.tsx +87 -58
- package/src/form/ControlNumber.tsx +2 -0
- package/src/form/ControlObject.tsx +20 -1
- package/src/form/ControlPassword.tsx +5 -0
- package/src/form/ControlSelect.tsx +32 -1
- package/src/form/ControlSelectCombobox.tsx +82 -56
- package/src/form/ControlUpload.tsx +1 -0
- package/src/form/FormField.tsx +23 -1
- package/src/form/__tests__/ControlFieldErrors.browser.spec.tsx +253 -0
- package/src/form/__tests__/ControlValidateMode.browser.spec.tsx +217 -0
- package/src/form/__tests__/ControlVariantErrors.browser.spec.tsx +133 -0
- package/src/i18n/fr/uiFr.ts +18 -1
- package/src/markdown/css.d.ts +11 -0
- package/src/shell/$pageNav.tsx +6 -4
- package/src/shell/AppShell.tsx +7 -0
- package/src/shell/ButtonSettings.tsx +20 -5
- package/src/shell/ButtonSettingsVisionMenuItem.tsx +40 -0
- package/src/shell/ButtonVision.tsx +73 -0
- package/src/shell/__tests__/ButtonSettings.browser.spec.tsx +42 -2
- package/src/shell/__tests__/ButtonVision.browser.spec.tsx +73 -0
- package/src/shell/__tests__/visionTokens.spec.ts +104 -0
- package/src/shell/index.ts +6 -3
- package/src/styles.css +57 -0
- package/src/table/DataTable.tsx +52 -4
- package/src/table/DataTableColumnPicker.tsx +3 -0
- package/src/table/DataTableFilterBar.tsx +18 -191
- package/src/table/DataTableHeaderFilter.tsx +156 -0
- package/src/table/DataTableHeaderRow.tsx +78 -40
- package/src/table/DataTableTabs.tsx +114 -0
- package/src/table/__tests__/DataTableHeaderFilter.browser.spec.tsx +174 -0
- package/src/table/__tests__/DataTableStaleColumns.browser.spec.tsx +80 -0
- package/src/table/__tests__/DataTableTabs.browser.spec.tsx +72 -0
- package/src/table/dataTableBaseProps.ts +12 -0
- package/src/table/dataTablePersistence.ts +11 -5
- package/src/table/dataTableTypes.ts +18 -0
- package/src/table/index.ts +9 -2
- package/src/table/useDataTableColumns.ts +1 -0
- package/src/table/useDataTableFilterModel.tsx +240 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ControlUpload.js","names":["FileIcon"],"sources":["../../src/form/ControlUpload.tsx"],"sourcesContent":["import * as React from \"react\";\n\nvoid React;\n\nimport type { FileController } from \"alepha/api/files\";\nimport { useClient } from \"alepha/react\";\nimport {\n type BaseInputField,\n parseField,\n useFieldValue,\n useFormState,\n} from \"alepha/react/form\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport { File as FileIcon, Loader2, Upload, X } from \"lucide-react\";\nimport {\n type ChangeEvent,\n type DragEvent,\n useEffect,\n useId,\n useRef,\n useState,\n} from \"react\";\n\nimport { Button } from \"../core/Button.tsx\";\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogHeader,\n DialogTitle,\n} from \"../core/Dialog.tsx\";\nimport { Tooltip, TooltipContent, TooltipTrigger } from \"../core/Tooltip.tsx\";\nimport { useToast } from \"../core/useToast.tsx\";\nimport { formatBytes } from \"../core/utils.ts\";\nimport { ControlUploadItemThumb } from \"./ControlUploadItemThumb.tsx\";\nimport { FormField } from \"./FormField.tsx\";\nimport { type ResizeImageOptions, resizeImage } from \"./resizeImage.ts\";\n\nexport interface ControlUploadProps {\n /**\n * Bound `InputField` from `useForm`. Stores the uploaded file ID(s).\n */\n input: BaseInputField;\n /**\n * Field label. Falls back to schema `title`.\n */\n label?: string;\n /**\n * Helper text shown below the dropzone.\n */\n description?: string;\n /**\n * Multi-file mode. The form value becomes an `Array<string>` of file\n * IDs. Single mode (default) stores a bare UUID string.\n */\n multi?: boolean;\n /**\n * HTML `accept` filter on the file picker (e.g. `\"image/*\"`,\n * `\".pdf,.docx\"`).\n */\n accept?: string;\n /**\n * Max size per file (bytes). Files over the limit are rejected.\n */\n maxSize?: number;\n /**\n * Downscale images to these bounds before uploading.\n *\n * Set it wherever the result is rendered small — the bytes never leave the\n * machine, so it speeds up the upload as well as every later fetch. Applied\n * before {@link maxSize}, so a photo that would have been rejected for being\n * too large is resized and accepted instead.\n *\n * Best-effort by design: a browser without `OffscreenCanvas`, an SVG, or an\n * image the decoder chokes on is uploaded as-is, and the storage's own\n * `maxSize` remains what actually bounds it. That trade is deliberate — a\n * server-side codec able to close the gap costs more bundle than the case is\n * worth on an edge runtime, and encodes worse (see `files:upload:before` in\n * `alepha/api/files` for where it would attach if you want it anyway).\n *\n * @example { maxWidth: 256 }\n */\n image?: ResizeImageOptions;\n /**\n * Bucket name passed to the upload endpoint.\n */\n bucket?: string;\n /**\n * Disable the dropzone.\n */\n disabled?: boolean;\n}\n\n/**\n * File upload control. Wraps `FileController.uploadFile`, stores the\n * resulting file ID(s) in the form, and renders a thumbnail preview for\n * images and a chip-style summary for everything else.\n *\n * Single-file: form value is a uuid string.\n * Multi-file: form value is an array of uuid strings.\n */\nexport const ControlUpload = (props: ControlUploadProps) => {\n const form = useFormState(props.input, [\"error\"]);\n const [value, setValue] = useFieldValue(props.input);\n const client = useClient<FileController>();\n const { tr } = useI18n();\n const toast = useToast();\n const inputId = useId();\n const fileInputRef = useRef<HTMLInputElement>(null);\n const [uploading, setUploading] = useState(false);\n const [progress, setProgress] = useState(0);\n const [meta, setMeta] = useState<Map<string, UploadedFileMeta>>(new Map());\n const [dragOver, setDragOver] = useState(false);\n const [previewId, setPreviewId] = useState<string | null>(null);\n\n /**\n * Backfill `meta` for ids that arrived from form state (e.g. after a page\n * reload) so the renderer can show a thumbnail / chip instead of the raw\n * uuid. We can't infer the real mime type without an extra request, so we\n * fall back to a stub entry pointing at `/api/files/:id` and let the\n * `<img>` `onError` swap to the generic file chip.\n */\n useEffect(() => {\n const ids: string[] = props.multi\n ? Array.isArray(value)\n ? (value as string[])\n : []\n : value\n ? [value as string]\n : [];\n // Reconciles a cache of per-file metadata against the ids the field now\n // holds, and the entries it keeps were filled in by the upload requests this\n // same effect issues. It is the cache for an external system, not derived\n // state; the updater already no-ops when nothing changed.\n // oxlint-disable-next-line react/set-state-in-effect -- reconciles a cache for an external system, see the comment above\n setMeta((current) => {\n let changed = false;\n const next = new Map(current);\n for (const id of ids) {\n if (!next.has(id)) {\n next.set(id, {\n id,\n name: id,\n previewUrl: `/api/files/${id}`,\n });\n changed = true;\n }\n }\n return changed ? next : current;\n });\n }, [Array.isArray(value) ? value.join(\",\") : value, props.multi]);\n\n if (!props.input?.props) return null;\n\n const fieldMeta = parseField(props.input, {\n label: props.label,\n description: props.description,\n error: form.error,\n });\n\n const ids: string[] = props.multi\n ? Array.isArray(value)\n ? (value as string[])\n : []\n : value\n ? [value as string]\n : [];\n\n const handleFiles = async (files: FileList) => {\n if (!files.length) return;\n if (!props.multi && files.length > 1) {\n toast.error(\n tr(\"controlUpload.singleOnly\", { default: \"Only one file allowed\" }),\n );\n return;\n }\n\n setUploading(true);\n setProgress(0);\n const next = new Map(meta);\n const newIds: string[] = [];\n\n try {\n for (let i = 0; i < files.length; i++) {\n // Ahead of the size check on purpose: a 4 MB photo destined for a 32px\n // avatar should become a few kilobytes, not an error.\n const file = props.image\n ? await resizeImage(files[i], props.image)\n : files[i];\n\n if (props.maxSize && file.size > props.maxSize) {\n toast.error(\n tr(\"controlUpload.tooBig\", {\n default: `${file.name} exceeds ${formatBytes(props.maxSize)}`,\n args: [file.name, formatBytes(props.maxSize)],\n }),\n );\n continue;\n }\n\n const resource = await client.uploadFile({\n body: { file },\n query: props.bucket ? { bucket: props.bucket } : {},\n });\n\n const previewUrl = file.type.startsWith(\"image/\")\n ? URL.createObjectURL(file)\n : undefined;\n\n next.set(resource.id, {\n id: resource.id,\n name: resource.name ?? file.name,\n mimeType: resource.mimeType ?? file.type,\n size: resource.size ?? file.size,\n previewUrl,\n });\n newIds.push(resource.id);\n setProgress(Math.round(((i + 1) / files.length) * 100));\n }\n\n setMeta(next);\n if (props.multi) {\n setValue([...ids, ...newIds]);\n } else if (newIds[0]) {\n setValue(newIds[0]);\n }\n if (newIds.length) {\n toast.success(\n newIds.length === 1\n ? tr(\"controlUpload.uploadedOne\", { default: \"File uploaded\" })\n : tr(\"controlUpload.uploadedMany\", {\n default: `${newIds.length} files uploaded`,\n args: [String(newIds.length)],\n }),\n );\n }\n } catch (e) {\n const msg = (e as Error).message;\n toast.error(\n tr(\"controlUpload.failed\", {\n default: `Upload failed: ${msg}`,\n args: [msg],\n }),\n );\n } finally {\n setUploading(false);\n setProgress(0);\n if (fileInputRef.current) fileInputRef.current.value = \"\";\n }\n };\n\n const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {\n if (e.target.files) void handleFiles(e.target.files);\n };\n\n const handleDrop = (e: DragEvent) => {\n e.preventDefault();\n setDragOver(false);\n if (props.disabled) return;\n if (e.dataTransfer.files) void handleFiles(e.dataTransfer.files);\n };\n\n const removeOne = (id: string) => {\n const next = new Map(meta);\n const item = next.get(id);\n if (item?.previewUrl) URL.revokeObjectURL(item.previewUrl);\n next.delete(id);\n setMeta(next);\n\n if (props.multi) {\n setValue(ids.filter((it) => it !== id));\n } else {\n setValue(undefined);\n }\n };\n\n const renderItem = (id: string) => {\n const item = meta.get(id);\n const acceptsImage = (props.accept ?? \"\").includes(\"image\");\n const mimeIsImage = item?.mimeType?.startsWith(\"image/\");\n const isImage =\n mimeIsImage || (acceptsImage && !!item?.previewUrl && !item?.mimeType);\n\n const canClear = !props.disabled && !fieldMeta.required;\n\n return (\n <div\n key={id}\n className={`border-border dark:bg-input/30 relative flex h-9 cursor-zoom-in items-center rounded-md border bg-transparent pl-1 ${canClear ? \"pr-9\" : \"pr-2\"}`}\n onClick={() => setPreviewId(id)}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n setPreviewId(id);\n }\n }}\n role=\"button\"\n tabIndex={0}\n >\n {isImage && item?.previewUrl ? (\n <ControlUploadItemThumb url={item.previewUrl} alt={item.name ?? id} />\n ) : (\n <div className=\"bg-muted text-muted-foreground flex size-7 shrink-0 items-center justify-center rounded\">\n <FileIcon className=\"size-4\" />\n </div>\n )}\n {canClear && (\n <button\n type=\"button\"\n onClick={(e) => {\n e.stopPropagation();\n removeOne(id);\n }}\n aria-label={tr(\"controlUpload.remove\", { default: \"Remove\" })}\n className=\"text-muted-foreground hover:text-foreground absolute top-1/2 right-2 -translate-y-1/2 p-1\"\n >\n <X className=\"size-3.5\" />\n </button>\n )}\n </div>\n );\n };\n\n const previewItem = previewId ? meta.get(previewId) : undefined;\n const previewIsImage = previewItem\n ? previewItem.mimeType?.startsWith(\"image/\") ||\n ((props.accept ?? \"\").includes(\"image\") &&\n !!previewItem.previewUrl &&\n !previewItem.mimeType)\n : false;\n const previewHasName =\n !!previewItem?.name && previewItem.name !== previewItem.id;\n\n const dragDropHint =\n tr(\"controlUpload.dragDrop\", { default: \"Upload or drag and drop here\" }) +\n (props.maxSize\n ? ` · ${tr(\"controlUpload.max\", {\n default: `max ${formatBytes(props.maxSize)}`,\n args: [formatBytes(props.maxSize)],\n })}`\n : \"\");\n\n const dropZone = (\n <Tooltip>\n <TooltipTrigger\n render={\n <Button\n type=\"button\"\n variant=\"outlined\"\n size=\"sm\"\n disabled={props.disabled || uploading}\n onClick={() => fileInputRef.current?.click()}\n onDragOver={(e) => {\n e.preventDefault();\n setDragOver(true);\n }}\n onDragLeave={() => setDragOver(false)}\n onDrop={handleDrop}\n className={dragOver ? \"border-primary bg-primary/5\" : \"\"}\n />\n }\n >\n {uploading ? (\n <>\n <Loader2 className=\"mr-1 size-4 animate-spin\" />\n {tr(\"controlUpload.uploading\", { default: \"Uploading…\" })}\n </>\n ) : (\n <>\n <Upload className=\"mr-1 size-4\" />\n {props.multi\n ? tr(\"controlUpload.chooseFiles\", { default: \"Choose files\" })\n : tr(\"controlUpload.chooseFile\", { default: \"Choose a file\" })}\n </>\n )}\n </TooltipTrigger>\n <TooltipContent>{dragDropHint}</TooltipContent>\n </Tooltip>\n );\n\n return (\n <FormField\n id={inputId}\n label={fieldMeta.label}\n description={fieldMeta.description}\n error={fieldMeta.error}\n required={fieldMeta.required}\n >\n <input\n ref={fileInputRef}\n type=\"file\"\n id={inputId}\n name={props.input.props.name}\n className=\"hidden\"\n accept={props.accept}\n multiple={props.multi}\n disabled={props.disabled}\n onChange={handleInputChange}\n />\n\n <div className=\"flex flex-col gap-2\">\n {ids.length > 0 && (\n <div className=\"flex flex-col gap-2\">{ids.map(renderItem)}</div>\n )}\n {(props.multi || ids.length === 0) && dropZone}\n {uploading && (\n <div className=\"bg-muted h-1 w-full overflow-hidden rounded\">\n <div\n className=\"bg-primary h-full transition-all\"\n style={{ width: `${progress}%` }}\n />\n </div>\n )}\n </div>\n\n <Dialog\n open={previewId !== null}\n onOpenChange={(o) => !o && setPreviewId(null)}\n >\n <DialogContent className=\"w-fit max-w-fit p-0\">\n <DialogHeader className=\"sr-only\">\n <DialogTitle>\n {previewHasName\n ? previewItem?.name\n : tr(\"controlUpload.savedFile\", { default: \"Saved file\" })}\n </DialogTitle>\n <DialogDescription>\n {previewItem?.mimeType ?? \"uploaded\"}\n </DialogDescription>\n </DialogHeader>\n <div className=\"p-4\">\n {previewIsImage && previewItem?.previewUrl ? (\n <img\n src={previewItem.previewUrl}\n alt={previewItem.name ?? \"\"}\n className=\"size-72 rounded object-contain\"\n />\n ) : (\n <div className=\"bg-muted text-muted-foreground flex size-72 items-center justify-center rounded\">\n <FileIcon className=\"size-16\" />\n </div>\n )}\n </div>\n {(previewHasName || previewItem?.mimeType) && (\n <div className=\"bg-muted/30 flex flex-col gap-0 border-t px-4 py-2\">\n {previewHasName && (\n <span className=\"truncate text-sm font-medium\">\n {previewItem?.name}\n </span>\n )}\n {previewItem?.mimeType && (\n <span className=\"text-muted-foreground truncate text-xs\">\n {previewItem.mimeType}\n </span>\n )}\n </div>\n )}\n </DialogContent>\n </Dialog>\n </FormField>\n );\n};\n\ninterface UploadedFileMeta {\n id: string;\n name: string;\n mimeType?: string;\n size?: number;\n /**\n * Object URL for image preview, when applicable.\n */\n previewUrl?: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAqGA,MAAa,iBAAiB,UAA8B;CAC1D,MAAM,OAAO,aAAa,MAAM,OAAO,CAAC,OAAO,CAAC;CAChD,MAAM,CAAC,OAAO,YAAY,cAAc,MAAM,KAAK;CACnD,MAAM,SAAS,UAA0B;CACzC,MAAM,EAAE,OAAO,QAAQ;CACvB,MAAM,QAAQ,SAAS;CACvB,MAAM,UAAU,MAAM;CACtB,MAAM,eAAe,OAAyB,IAAI;CAClD,MAAM,CAAC,WAAW,gBAAgB,SAAS,KAAK;CAChD,MAAM,CAAC,UAAU,eAAe,SAAS,CAAC;CAC1C,MAAM,CAAC,MAAM,WAAW,yBAAwC,IAAI,IAAI,CAAC;CACzE,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAC9C,MAAM,CAAC,WAAW,gBAAgB,SAAwB,IAAI;;;;;;;;CAS9D,gBAAgB;EACd,MAAM,MAAgB,MAAM,QACxB,MAAM,QAAQ,KAAK,IAChB,QACD,CAAC,IACH,QACE,CAAC,KAAe,IAChB,CAAC;EAMP,SAAS,YAAY;GACnB,IAAI,UAAU;GACd,MAAM,OAAO,IAAI,IAAI,OAAO;GAC5B,KAAK,MAAM,MAAM,KACf,IAAI,CAAC,KAAK,IAAI,EAAE,GAAG;IACjB,KAAK,IAAI,IAAI;KACX;KACA,MAAM;KACN,YAAY,cAAc;IAC5B,CAAC;IACD,UAAU;GACZ;GAEF,OAAO,UAAU,OAAO;EAC1B,CAAC;CACH,GAAG,CAAC,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAK,GAAG,IAAI,OAAO,MAAM,KAAK,CAAC;CAEhE,IAAI,CAAC,MAAM,OAAO,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B,UAAA,IAAI,IAAI,UAAU;KAAO,CAAA;MAE/D,MAAM,SAAS,IAAI,WAAW,MAAM;KACrC,aACC,oBAAC,OAAD;MAAK,WAAU;MACb,UAAA,oBAAC,OAAD;OACE,WAAU;OACV,OAAO,EAAE,OAAO,GAAG,SAAS,GAAG;MAChC,CAAA;KACE,CAAA;IAEJ;;GAEL,oBAAC,QAAD;IACE,MAAM,cAAc;IACpB,eAAe,MAAM,CAAC,KAAK,aAAa,IAAI;IAE5C,UAAA,qBAAC,eAAD;KAAe,WAAU;KAAzB,UAAA;MACE,qBAAC,cAAD;OAAc,WAAU;OAAxB,UAAA,CACE,oBAAC,aAAD,EAAA,UACG,iBACG,aAAa,OACb,GAAG,2BAA2B,EAAE,SAAS,aAAa,CAAC,EAChD,CAAA,GACb,oBAAC,mBAAD,EAAA,UACG,aAAa,YAAY,WACT,CAAA,CACP;;MACd,oBAAC,OAAD;OAAK,WAAU;OACZ,UAAA,kBAAkB,aAAa,aAC9B,oBAAC,OAAD;QACE,KAAK,YAAY;QACjB,KAAK,YAAY,QAAQ;QACzB,WAAU;OACX,CAAA,IAED,oBAAC,OAAD;QAAK,WAAU;QACb,UAAA,oBAACA,MAAD,EAAU,WAAU,UAAW,CAAA;OAC5B,CAAA;MAEJ,CAAA;OACH,kBAAkB,aAAa,aAC/B,qBAAC,OAAD;OAAK,WAAU;OAAf,UAAA,CACG,kBACC,oBAAC,QAAD;QAAM,WAAU;QACb,UAAA,aAAa;OACV,CAAA,GAEP,aAAa,YACZ,oBAAC,QAAD;QAAM,WAAU;QACb,UAAA,YAAY;OACT,CAAA,CAEL;;KAEM;;GACT,CAAA;EACC;;AAEf"}
|
|
1
|
+
{"version":3,"file":"ControlUpload.js","names":["FileIcon"],"sources":["../../src/form/ControlUpload.tsx"],"sourcesContent":["import * as React from \"react\";\n\nvoid React;\n\nimport type { FileController } from \"alepha/api/files\";\nimport { useClient } from \"alepha/react\";\nimport {\n type BaseInputField,\n parseField,\n useFieldValue,\n useFormState,\n} from \"alepha/react/form\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport { File as FileIcon, Loader2, Upload, X } from \"lucide-react\";\nimport {\n type ChangeEvent,\n type DragEvent,\n useEffect,\n useId,\n useRef,\n useState,\n} from \"react\";\n\nimport { Button } from \"../core/Button.tsx\";\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogHeader,\n DialogTitle,\n} from \"../core/Dialog.tsx\";\nimport { Tooltip, TooltipContent, TooltipTrigger } from \"../core/Tooltip.tsx\";\nimport { useToast } from \"../core/useToast.tsx\";\nimport { formatBytes } from \"../core/utils.ts\";\nimport { ControlUploadItemThumb } from \"./ControlUploadItemThumb.tsx\";\nimport { FormField } from \"./FormField.tsx\";\nimport { type ResizeImageOptions, resizeImage } from \"./resizeImage.ts\";\n\nexport interface ControlUploadProps {\n /**\n * Bound `InputField` from `useForm`. Stores the uploaded file ID(s).\n */\n input: BaseInputField;\n /**\n * Field label. Falls back to schema `title`.\n */\n label?: string;\n /**\n * Helper text shown below the dropzone.\n */\n description?: string;\n /**\n * Multi-file mode. The form value becomes an `Array<string>` of file\n * IDs. Single mode (default) stores a bare UUID string.\n */\n multi?: boolean;\n /**\n * HTML `accept` filter on the file picker (e.g. `\"image/*\"`,\n * `\".pdf,.docx\"`).\n */\n accept?: string;\n /**\n * Max size per file (bytes). Files over the limit are rejected.\n */\n maxSize?: number;\n /**\n * Downscale images to these bounds before uploading.\n *\n * Set it wherever the result is rendered small — the bytes never leave the\n * machine, so it speeds up the upload as well as every later fetch. Applied\n * before {@link maxSize}, so a photo that would have been rejected for being\n * too large is resized and accepted instead.\n *\n * Best-effort by design: a browser without `OffscreenCanvas`, an SVG, or an\n * image the decoder chokes on is uploaded as-is, and the storage's own\n * `maxSize` remains what actually bounds it. That trade is deliberate — a\n * server-side codec able to close the gap costs more bundle than the case is\n * worth on an edge runtime, and encodes worse (see `files:upload:before` in\n * `alepha/api/files` for where it would attach if you want it anyway).\n *\n * @example { maxWidth: 256 }\n */\n image?: ResizeImageOptions;\n /**\n * Bucket name passed to the upload endpoint.\n */\n bucket?: string;\n /**\n * Disable the dropzone.\n */\n disabled?: boolean;\n}\n\n/**\n * File upload control. Wraps `FileController.uploadFile`, stores the\n * resulting file ID(s) in the form, and renders a thumbnail preview for\n * images and a chip-style summary for everything else.\n *\n * Single-file: form value is a uuid string.\n * Multi-file: form value is an array of uuid strings.\n */\nexport const ControlUpload = (props: ControlUploadProps) => {\n const form = useFormState(props.input, [\"error\"]);\n const [value, setValue] = useFieldValue(props.input);\n const client = useClient<FileController>();\n const { tr } = useI18n();\n const toast = useToast();\n const inputId = useId();\n const fileInputRef = useRef<HTMLInputElement>(null);\n const [uploading, setUploading] = useState(false);\n const [progress, setProgress] = useState(0);\n const [meta, setMeta] = useState<Map<string, UploadedFileMeta>>(new Map());\n const [dragOver, setDragOver] = useState(false);\n const [previewId, setPreviewId] = useState<string | null>(null);\n\n /**\n * Backfill `meta` for ids that arrived from form state (e.g. after a page\n * reload) so the renderer can show a thumbnail / chip instead of the raw\n * uuid. We can't infer the real mime type without an extra request, so we\n * fall back to a stub entry pointing at `/api/files/:id` and let the\n * `<img>` `onError` swap to the generic file chip.\n */\n useEffect(() => {\n const ids: string[] = props.multi\n ? Array.isArray(value)\n ? (value as string[])\n : []\n : value\n ? [value as string]\n : [];\n // Reconciles a cache of per-file metadata against the ids the field now\n // holds, and the entries it keeps were filled in by the upload requests this\n // same effect issues. It is the cache for an external system, not derived\n // state; the updater already no-ops when nothing changed.\n // oxlint-disable-next-line react/set-state-in-effect -- reconciles a cache for an external system, see the comment above\n setMeta((current) => {\n let changed = false;\n const next = new Map(current);\n for (const id of ids) {\n if (!next.has(id)) {\n next.set(id, {\n id,\n name: id,\n previewUrl: `/api/files/${id}`,\n });\n changed = true;\n }\n }\n return changed ? next : current;\n });\n }, [Array.isArray(value) ? value.join(\",\") : value, props.multi]);\n\n if (!props.input?.props) return null;\n\n const fieldMeta = parseField(props.input, {\n label: props.label,\n description: props.description,\n error: form.error,\n });\n\n const ids: string[] = props.multi\n ? Array.isArray(value)\n ? (value as string[])\n : []\n : value\n ? [value as string]\n : [];\n\n const handleFiles = async (files: FileList) => {\n if (!files.length) return;\n if (!props.multi && files.length > 1) {\n toast.error(\n tr(\"controlUpload.singleOnly\", { default: \"Only one file allowed\" }),\n );\n return;\n }\n\n setUploading(true);\n setProgress(0);\n const next = new Map(meta);\n const newIds: string[] = [];\n\n try {\n for (let i = 0; i < files.length; i++) {\n // Ahead of the size check on purpose: a 4 MB photo destined for a 32px\n // avatar should become a few kilobytes, not an error.\n const file = props.image\n ? await resizeImage(files[i], props.image)\n : files[i];\n\n if (props.maxSize && file.size > props.maxSize) {\n toast.error(\n tr(\"controlUpload.tooBig\", {\n default: `${file.name} exceeds ${formatBytes(props.maxSize)}`,\n args: [file.name, formatBytes(props.maxSize)],\n }),\n );\n continue;\n }\n\n const resource = await client.uploadFile({\n body: { file },\n query: props.bucket ? { bucket: props.bucket } : {},\n });\n\n const previewUrl = file.type.startsWith(\"image/\")\n ? URL.createObjectURL(file)\n : undefined;\n\n next.set(resource.id, {\n id: resource.id,\n name: resource.name ?? file.name,\n mimeType: resource.mimeType ?? file.type,\n size: resource.size ?? file.size,\n previewUrl,\n });\n newIds.push(resource.id);\n setProgress(Math.round(((i + 1) / files.length) * 100));\n }\n\n setMeta(next);\n if (props.multi) {\n setValue([...ids, ...newIds]);\n } else if (newIds[0]) {\n setValue(newIds[0]);\n }\n if (newIds.length) {\n toast.success(\n newIds.length === 1\n ? tr(\"controlUpload.uploadedOne\", { default: \"File uploaded\" })\n : tr(\"controlUpload.uploadedMany\", {\n default: `${newIds.length} files uploaded`,\n args: [String(newIds.length)],\n }),\n );\n }\n } catch (e) {\n const msg = (e as Error).message;\n toast.error(\n tr(\"controlUpload.failed\", {\n default: `Upload failed: ${msg}`,\n args: [msg],\n }),\n );\n } finally {\n setUploading(false);\n setProgress(0);\n if (fileInputRef.current) fileInputRef.current.value = \"\";\n }\n };\n\n const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {\n if (e.target.files) void handleFiles(e.target.files);\n };\n\n const handleDrop = (e: DragEvent) => {\n e.preventDefault();\n setDragOver(false);\n if (props.disabled) return;\n if (e.dataTransfer.files) void handleFiles(e.dataTransfer.files);\n };\n\n const removeOne = (id: string) => {\n const next = new Map(meta);\n const item = next.get(id);\n if (item?.previewUrl) URL.revokeObjectURL(item.previewUrl);\n next.delete(id);\n setMeta(next);\n\n if (props.multi) {\n setValue(ids.filter((it) => it !== id));\n } else {\n setValue(undefined);\n }\n };\n\n const renderItem = (id: string) => {\n const item = meta.get(id);\n const acceptsImage = (props.accept ?? \"\").includes(\"image\");\n const mimeIsImage = item?.mimeType?.startsWith(\"image/\");\n const isImage =\n mimeIsImage || (acceptsImage && !!item?.previewUrl && !item?.mimeType);\n\n const canClear = !props.disabled && !fieldMeta.required;\n\n return (\n <div\n key={id}\n className={`border-border dark:bg-input/30 relative flex h-9 cursor-zoom-in items-center rounded-md border bg-transparent pl-1 ${canClear ? \"pr-9\" : \"pr-2\"}`}\n onClick={() => setPreviewId(id)}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n setPreviewId(id);\n }\n }}\n role=\"button\"\n tabIndex={0}\n >\n {isImage && item?.previewUrl ? (\n <ControlUploadItemThumb url={item.previewUrl} alt={item.name ?? id} />\n ) : (\n <div className=\"bg-muted text-muted-foreground flex size-7 shrink-0 items-center justify-center rounded\">\n <FileIcon className=\"size-4\" />\n </div>\n )}\n {canClear && (\n <button\n type=\"button\"\n onClick={(e) => {\n e.stopPropagation();\n removeOne(id);\n }}\n aria-label={tr(\"controlUpload.remove\", { default: \"Remove\" })}\n className=\"text-muted-foreground hover:text-foreground absolute top-1/2 right-2 -translate-y-1/2 p-1\"\n >\n <X className=\"size-3.5\" />\n </button>\n )}\n </div>\n );\n };\n\n const previewItem = previewId ? meta.get(previewId) : undefined;\n const previewIsImage = previewItem\n ? previewItem.mimeType?.startsWith(\"image/\") ||\n ((props.accept ?? \"\").includes(\"image\") &&\n !!previewItem.previewUrl &&\n !previewItem.mimeType)\n : false;\n const previewHasName =\n !!previewItem?.name && previewItem.name !== previewItem.id;\n\n const dragDropHint =\n tr(\"controlUpload.dragDrop\", { default: \"Upload or drag and drop here\" }) +\n (props.maxSize\n ? ` · ${tr(\"controlUpload.max\", {\n default: `max ${formatBytes(props.maxSize)}`,\n args: [formatBytes(props.maxSize)],\n })}`\n : \"\");\n\n const dropZone = (\n <Tooltip>\n <TooltipTrigger\n render={\n <Button\n type=\"button\"\n variant=\"outlined\"\n size=\"sm\"\n disabled={props.disabled || uploading}\n onClick={() => fileInputRef.current?.click()}\n onDragOver={(e) => {\n e.preventDefault();\n setDragOver(true);\n }}\n onDragLeave={() => setDragOver(false)}\n onDrop={handleDrop}\n className={dragOver ? \"border-primary bg-primary/5\" : \"\"}\n />\n }\n >\n {uploading ? (\n <>\n <Loader2 className=\"mr-1 size-4 animate-spin\" />\n {tr(\"controlUpload.uploading\", { default: \"Uploading…\" })}\n </>\n ) : (\n <>\n <Upload className=\"mr-1 size-4\" />\n {props.multi\n ? tr(\"controlUpload.chooseFiles\", { default: \"Choose files\" })\n : tr(\"controlUpload.chooseFile\", { default: \"Choose a file\" })}\n </>\n )}\n </TooltipTrigger>\n <TooltipContent>{dragDropHint}</TooltipContent>\n </Tooltip>\n );\n\n return (\n <FormField\n onBlur={() => props.input.form?.blur(props.input.path)}\n id={inputId}\n label={fieldMeta.label}\n description={fieldMeta.description}\n error={fieldMeta.error}\n required={fieldMeta.required}\n >\n <input\n ref={fileInputRef}\n type=\"file\"\n id={inputId}\n name={props.input.props.name}\n className=\"hidden\"\n accept={props.accept}\n multiple={props.multi}\n disabled={props.disabled}\n onChange={handleInputChange}\n />\n\n <div className=\"flex flex-col gap-2\">\n {ids.length > 0 && (\n <div className=\"flex flex-col gap-2\">{ids.map(renderItem)}</div>\n )}\n {(props.multi || ids.length === 0) && dropZone}\n {uploading && (\n <div className=\"bg-muted h-1 w-full overflow-hidden rounded\">\n <div\n className=\"bg-primary h-full transition-all\"\n style={{ width: `${progress}%` }}\n />\n </div>\n )}\n </div>\n\n <Dialog\n open={previewId !== null}\n onOpenChange={(o) => !o && setPreviewId(null)}\n >\n <DialogContent className=\"w-fit max-w-fit p-0\">\n <DialogHeader className=\"sr-only\">\n <DialogTitle>\n {previewHasName\n ? previewItem?.name\n : tr(\"controlUpload.savedFile\", { default: \"Saved file\" })}\n </DialogTitle>\n <DialogDescription>\n {previewItem?.mimeType ?? \"uploaded\"}\n </DialogDescription>\n </DialogHeader>\n <div className=\"p-4\">\n {previewIsImage && previewItem?.previewUrl ? (\n <img\n src={previewItem.previewUrl}\n alt={previewItem.name ?? \"\"}\n className=\"size-72 rounded object-contain\"\n />\n ) : (\n <div className=\"bg-muted text-muted-foreground flex size-72 items-center justify-center rounded\">\n <FileIcon className=\"size-16\" />\n </div>\n )}\n </div>\n {(previewHasName || previewItem?.mimeType) && (\n <div className=\"bg-muted/30 flex flex-col gap-0 border-t px-4 py-2\">\n {previewHasName && (\n <span className=\"truncate text-sm font-medium\">\n {previewItem?.name}\n </span>\n )}\n {previewItem?.mimeType && (\n <span className=\"text-muted-foreground truncate text-xs\">\n {previewItem.mimeType}\n </span>\n )}\n </div>\n )}\n </DialogContent>\n </Dialog>\n </FormField>\n );\n};\n\ninterface UploadedFileMeta {\n id: string;\n name: string;\n mimeType?: string;\n size?: number;\n /**\n * Object URL for image preview, when applicable.\n */\n previewUrl?: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAqGA,MAAa,iBAAiB,UAA8B;CAC1D,MAAM,OAAO,aAAa,MAAM,OAAO,CAAC,OAAO,CAAC;CAChD,MAAM,CAAC,OAAO,YAAY,cAAc,MAAM,KAAK;CACnD,MAAM,SAAS,UAA0B;CACzC,MAAM,EAAE,OAAO,QAAQ;CACvB,MAAM,QAAQ,SAAS;CACvB,MAAM,UAAU,MAAM;CACtB,MAAM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ACG,iBACG,aAAa,OACb,GAAG,2BAA2B,EAAE,SAAS,aAAa,CAAC,EAChD,CAAA,GACb,oBAAC,mBAAD,EAAA,UACG,aAAa,YAAY,WACT,CAAA,CACP;;MACd,oBAAC,OAAD;OAAK,WAAU;OACZ,UAAA,kBAAkB,aAAa,aAC9B,oBAAC,OAAD;QACE,KAAK,YAAY;QACjB,KAAK,YAAY,QAAQ;QACzB,WAAU;OACX,CAAA,IAED,oBAAC,OAAD;QAAK,WAAU;QACb,UAAA,oBAACA,MAAD,EAAU,WAAU,UAAW,CAAA;OAC5B,CAAA;MAEJ,CAAA;OACH,kBAAkB,aAAa,aAC/B,qBAAC,OAAD;OAAK,WAAU;OAAf,UAAA,CACG,kBACC,oBAAC,QAAD;QAAM,WAAU;QACb,UAAA,aAAa;OACV,CAAA,GAEP,aAAa,YACZ,oBAAC,QAAD;QAAM,WAAU;QACb,UAAA,YAAY;OACT,CAAA,CAEL;;KAEM;;GACT,CAAA;EACC;;AAEf"}
|
package/dist/form/FormField.d.ts
CHANGED
|
@@ -35,6 +35,11 @@ export interface FormFieldProps {
|
|
|
35
35
|
* When omitted, falls back to the ambient `<FormFieldLayoutProvider>`.
|
|
36
36
|
*/
|
|
37
37
|
layout?: FormFieldLayout;
|
|
38
|
+
/**
|
|
39
|
+
* Called when focus leaves the field: the control and anything inside it
|
|
40
|
+
* (a picker's trigger and its inline parts). `validate: "blur"` hangs on it.
|
|
41
|
+
*/
|
|
42
|
+
onBlur?: () => void;
|
|
38
43
|
/**
|
|
39
44
|
* The control to wrap.
|
|
40
45
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormField.d.ts","sourceRoot":"","sources":["../../src/form/FormField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,
|
|
1
|
+
{"version":3,"file":"FormField.d.ts","sourceRoot":"","sources":["../../src/form/FormField.tsx"],"names":[],"mappings":"AAAA,OAAO,KA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AAM,CAAC;IAC5B,eAAe,CAAC,EAAE,IAAI,CAAC;CACxB,CAWA;AAED,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,OAAO,CAAC,EAAE,IAAI,CAAC;IACf;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAQD;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAEhD"}
|
package/dist/form/FormField.js
CHANGED
|
@@ -19,6 +19,11 @@ const FormField = (props) => {
|
|
|
19
19
|
const showRequiredMarker = props.required && requiredMarker;
|
|
20
20
|
const invalidClasses = props.error ? "[&_input]:border-danger [&_input]:focus-visible:ring-danger/30 [&_textarea]:border-danger [&_textarea]:focus-visible:ring-danger/30 [&_[role=combobox]]:border-danger" : "";
|
|
21
21
|
const dataInvalid = props.error ? true : void 0;
|
|
22
|
+
const onBlur = props.onBlur ? (event) => {
|
|
23
|
+
const next = event.relatedTarget;
|
|
24
|
+
if (next && event.currentTarget.contains(next)) return;
|
|
25
|
+
props.onBlur?.();
|
|
26
|
+
} : void 0;
|
|
22
27
|
const errorId = formFieldErrorId(props.id, props.error);
|
|
23
28
|
const descriptionId = formFieldDescriptionId(props.id, props.description, props.error);
|
|
24
29
|
const a11y = useMemo(() => ({
|
|
@@ -36,6 +41,7 @@ const FormField = (props) => {
|
|
|
36
41
|
if (layout === "row") return /* @__PURE__ */ jsxs("div", {
|
|
37
42
|
className: cn("flex flex-col gap-3 px-4 py-3 sm:grid sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center sm:gap-6", invalidClasses, props.className),
|
|
38
43
|
"data-invalid": dataInvalid,
|
|
44
|
+
onBlur,
|
|
39
45
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
40
46
|
className: "flex flex-col gap-0.5",
|
|
41
47
|
children: [
|
|
@@ -71,6 +77,7 @@ const FormField = (props) => {
|
|
|
71
77
|
return /* @__PURE__ */ jsxs("div", {
|
|
72
78
|
className: cn("flex flex-col gap-1.5", invalidClasses, props.className),
|
|
73
79
|
"data-invalid": dataInvalid,
|
|
80
|
+
onBlur,
|
|
74
81
|
children: [
|
|
75
82
|
props.label && /* @__PURE__ */ jsxs(Label, {
|
|
76
83
|
htmlFor: props.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormField.js","names":[],"sources":["../../src/form/FormField.tsx"],"sourcesContent":["import * as React from \"react\";\n\nvoid React;\n\nimport { createContext, type ReactNode, useContext, useMemo } from \"react\";\n\nimport { Label } from \"../core/Label.tsx\";\nimport { cn } from \"../core/utils.ts\";\nimport {\n type FormFieldLayout,\n useFormFieldLayout,\n} from \"./FormFieldLayoutProvider.tsx\";\nimport { useFormFieldRequiredMarker } from \"./FormFieldRequiredMarkerProvider.tsx\";\n\nexport interface FormFieldProps {\n /**\n * `id` linked to the inner control's `htmlFor`.\n */\n id?: string;\n /**\n * Label text rendered above the control.\n */\n label?: string;\n /**\n * Helper text rendered below the control.\n */\n description?: string;\n /**\n * Error message. When set, marks descendant inputs invalid via `data-invalid`.\n */\n error?: string;\n /**\n * Show a required marker (`*`) next to the label.\n */\n required?: boolean;\n /**\n * Extra classes applied to the wrapper.\n */\n className?: string;\n /**\n * Layout variant.\n * - `\"stack\"` (default): label on top, control below, description under.\n * - `\"row\"`: settings-style — label/description on the left, control on\n * the right. Stacks on narrow viewports.\n *\n * When omitted, falls back to the ambient `<FormFieldLayoutProvider>`.\n */\n layout?: FormFieldLayout;\n /**\n * The control to wrap.\n */\n children: ReactNode;\n}\n\n/**\n * Label + description + error wrapper shared by every Control variant.\n *\n * When `error` is set, applies a red ring to any descendant `<input>`,\n * `<textarea>`, or trigger button via the `data-invalid` attribute (so we\n * don't have to thread `error` through every leaf widget).\n */\nexport const FormField = (props: FormFieldProps) => {\n const ambient = useFormFieldLayout();\n const layout = props.layout ?? ambient;\n // Hook first, `&&` after: `props.required && useFormFieldRequiredMarker()`\n // short-circuits, which would make this a conditional hook call.\n const requiredMarker = useFormFieldRequiredMarker();\n const showRequiredMarker = props.required && requiredMarker;\n const invalidClasses = props.error\n ? \"[&_input]:border-danger [&_input]:focus-visible:ring-danger/30 [&_textarea]:border-danger [&_textarea]:focus-visible:ring-danger/30 [&_[role=combobox]]:border-danger\"\n : \"\";\n const dataInvalid = props.error ? true : undefined;\n\n const errorId = formFieldErrorId(props.id, props.error);\n const descriptionId = formFieldDescriptionId(\n props.id,\n props.description,\n props.error,\n );\n const a11y = useMemo<FormFieldA11y>(\n () => ({\n invalid: props.error ? true : undefined,\n describedBy: errorId ?? descriptionId,\n }),\n [props.error, errorId, descriptionId],\n );\n const children = (\n <FormFieldA11yContext.Provider value={a11y}>\n {props.children}\n </FormFieldA11yContext.Provider>\n );\n\n if (layout === \"row\") {\n return (\n <div\n className={cn(\n \"flex flex-col gap-3 px-4 py-3 sm:grid sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center sm:gap-6\",\n invalidClasses,\n props.className,\n )}\n data-invalid={dataInvalid}\n >\n <div className=\"flex flex-col gap-0.5\">\n {props.label && (\n <Label htmlFor={props.id} className=\"font-medium\">\n {props.label}\n {showRequiredMarker && (\n <span className=\"text-danger-text ml-0.5\" aria-hidden>\n *\n </span>\n )}\n </Label>\n )}\n {props.description && !props.error && (\n <p id={descriptionId} className=\"text-muted-foreground text-xs\">\n {props.description}\n </p>\n )}\n {props.error && (\n <p\n id={errorId}\n className=\"text-danger-text flex items-center gap-1 text-xs\"\n role=\"alert\"\n >\n <span aria-hidden>⚠</span>\n {props.error}\n </p>\n )}\n </div>\n <div className=\"flex min-w-0 justify-start sm:justify-end\">\n {children}\n </div>\n </div>\n );\n }\n\n return (\n <div\n className={cn(\"flex flex-col gap-1.5\", invalidClasses, props.className)}\n data-invalid={dataInvalid}\n >\n {props.label && (\n <Label htmlFor={props.id}>\n {props.label}\n {showRequiredMarker && (\n <span className=\"text-danger-text ml-0.5\" aria-hidden>\n *\n </span>\n )}\n </Label>\n )}\n {children}\n {props.description && !props.error && (\n <p id={descriptionId} className=\"text-muted-foreground text-xs\">\n {props.description}\n </p>\n )}\n {props.error && (\n <p\n id={errorId}\n className=\"text-danger-text flex items-center gap-1 text-xs\"\n role=\"alert\"\n >\n <span aria-hidden>⚠</span>\n {props.error}\n </p>\n )}\n </div>\n );\n};\n\n/**\n * Id of the error element a `<FormField id={id} error>` renders.\n */\nexport function formFieldErrorId(\n id?: string,\n error?: string,\n): string | undefined {\n return id && error ? `${id}-error` : undefined;\n}\n\n/**\n * Id of the description element a `<FormField id={id} description>` renders\n * (the description is replaced by the error when both are set).\n */\nexport function formFieldDescriptionId(\n id?: string,\n description?: string,\n error?: string,\n): string | undefined {\n return id && description && !error ? `${id}-description` : undefined;\n}\n\n/**\n * The aria attributes a control spreads on its native element when it\n * renders its own `<FormField>` (id/error/description in hand). Widgets\n * nested under someone else's FormField use {@link useFormFieldA11y}\n * instead.\n */\nexport function formFieldAriaProps(props: {\n id?: string;\n error?: string;\n description?: string;\n required?: boolean;\n}): {\n \"aria-invalid\"?: true;\n \"aria-describedby\"?: string;\n \"aria-required\"?: true;\n} {\n return {\n \"aria-invalid\": props.error ? true : undefined,\n \"aria-describedby\":\n formFieldErrorId(props.id, props.error) ??\n formFieldDescriptionId(props.id, props.description, props.error),\n // The visible marker is `aria-hidden`, so without this a required field\n // announced nothing at all. It is read from the schema, never from the\n // marker flag — see `FormFieldRequiredMarkerProvider.tsx`.\n \"aria-required\": props.required ? true : undefined,\n };\n}\n\nexport interface FormFieldA11y {\n /**\n * `true` when the surrounding FormField carries an error — mirror it\n * onto the widget's `aria-invalid`.\n */\n invalid?: true;\n /**\n * Id of the FormField's error (or description) element — mirror it\n * onto the widget's `aria-describedby`.\n */\n describedBy?: string;\n}\n\n/**\n * Context exemption: the ids and invalid state one `FormField` hands the\n * widget inside it. Every field on a page has its own.\n */\nconst FormFieldA11yContext = createContext<FormFieldA11y>({});\n\n/**\n * Read the surrounding FormField's accessibility wiring. Leaf widgets\n * spread the result onto their native element so screen readers announce\n * the invalid state and the error/description text:\n *\n * ```tsx\n * const a11y = useFormFieldA11y();\n * <input aria-invalid={a11y.invalid} aria-describedby={a11y.describedBy} />\n * ```\n */\nexport function useFormFieldA11y(): FormFieldA11y {\n return useContext(FormFieldA11yContext);\n}\n"],"mappings":";;;;;;;;;;;;;;AA6DA,MAAa,aAAa,UAA0B;CAClD,MAAM,UAAU,mBAAmB;CACnC,MAAM,SAAS,MAAM,UAAU;CAG/B,MAAM,iBAAiB,2BAA2B;CAClD,MAAM,qBAAqB,MAAM,YAAY;CAC7C,MAAM,iBAAiB,MAAM,QACzB,0KACA;CACJ,MAAM,cAAc,MAAM,QAAQ,OAAO,KAAA;CAEzC,MAAM,UAAU,iBAAiB,MAAM,IAAI,MAAM,KAAK;CACtD,MAAM,gBAAgB,uBACpB,MAAM,IACN,MAAM,aACN,MAAM,KACR;CACA,MAAM,OAAO,eACJ;EACL,SAAS,MAAM,QAAQ,OAAO,KAAA;EAC9B,aAAa,WAAW;CAC1B,IACA;EAAC,MAAM;EAAO;EAAS;CAAa,CACtC;CACA,MAAM,WACJ,oBAAC,qBAAqB,UAAtB;EAA+B,OAAO;EACnC,UAAA,MAAM;CACsB,CAAA;CAGjC,IAAI,WAAW,OACb,OACE,qBAAC,OAAD;EACE,WAAW,GACT,oGACA,gBACA,MAAM,SACR;EACA,gBAAc;EANhB,UAAA,CAQE,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA;IACG,MAAM,SACL,qBAAC,OAAD;KAAO,SAAS,MAAM;KAAI,WAAU;KAApC,UAAA,CACG,MAAM,OACN,sBACC,oBAAC,QAAD;MAAM,WAAU;MAA0B,eAAA;MAAY,UAAA;KAEhD,CAAA,CAEH;;IAER,MAAM,eAAe,CAAC,MAAM,SAC3B,oBAAC,KAAD;KAAG,IAAI;KAAe,WAAU;KAC7B,UAAA,MAAM;IACN,CAAA;IAEJ,MAAM,SACL,qBAAC,KAAD;KACE,IAAI;KACJ,WAAU;KACV,MAAK;KAHP,UAAA,CAKE,oBAAC,QAAD;M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["../../src/form/FormField.tsx"],"sourcesContent":["import * as React from \"react\";\n\nvoid React;\n\nimport {\n createContext,\n type FocusEvent,\n type ReactNode,\n useContext,\n useMemo,\n} from \"react\";\n\nimport { Label } from \"../core/Label.tsx\";\nimport { cn } from \"../core/utils.ts\";\nimport {\n type FormFieldLayout,\n useFormFieldLayout,\n} from \"./FormFieldLayoutProvider.tsx\";\nimport { useFormFieldRequiredMarker } from \"./FormFieldRequiredMarkerProvider.tsx\";\n\nexport interface FormFieldProps {\n /**\n * `id` linked to the inner control's `htmlFor`.\n */\n id?: string;\n /**\n * Label text rendered above the control.\n */\n label?: string;\n /**\n * Helper text rendered below the control.\n */\n description?: string;\n /**\n * Error message. When set, marks descendant inputs invalid via `data-invalid`.\n */\n error?: string;\n /**\n * Show a required marker (`*`) next to the label.\n */\n required?: boolean;\n /**\n * Extra classes applied to the wrapper.\n */\n className?: string;\n /**\n * Layout variant.\n * - `\"stack\"` (default): label on top, control below, description under.\n * - `\"row\"`: settings-style — label/description on the left, control on\n * the right. Stacks on narrow viewports.\n *\n * When omitted, falls back to the ambient `<FormFieldLayoutProvider>`.\n */\n layout?: FormFieldLayout;\n /**\n * Called when focus leaves the field: the control and anything inside it\n * (a picker's trigger and its inline parts). `validate: \"blur\"` hangs on it.\n */\n onBlur?: () => void;\n /**\n * The control to wrap.\n */\n children: ReactNode;\n}\n\n/**\n * Label + description + error wrapper shared by every Control variant.\n *\n * When `error` is set, applies a red ring to any descendant `<input>`,\n * `<textarea>`, or trigger button via the `data-invalid` attribute (so we\n * don't have to thread `error` through every leaf widget).\n */\nexport const FormField = (props: FormFieldProps) => {\n const ambient = useFormFieldLayout();\n const layout = props.layout ?? ambient;\n // Hook first, `&&` after: `props.required && useFormFieldRequiredMarker()`\n // short-circuits, which would make this a conditional hook call.\n const requiredMarker = useFormFieldRequiredMarker();\n const showRequiredMarker = props.required && requiredMarker;\n const invalidClasses = props.error\n ? \"[&_input]:border-danger [&_input]:focus-visible:ring-danger/30 [&_textarea]:border-danger [&_textarea]:focus-visible:ring-danger/30 [&_[role=combobox]]:border-danger\"\n : \"\";\n const dataInvalid = props.error ? true : undefined;\n // `focusout` bubbles, so one listener on the wrapper hears every input of\n // the control; moving focus between two of its own parts is not leaving.\n const onBlur = props.onBlur\n ? (event: FocusEvent<HTMLDivElement>) => {\n const next = event.relatedTarget as Node | null;\n if (next && event.currentTarget.contains(next)) return;\n props.onBlur?.();\n }\n : undefined;\n\n const errorId = formFieldErrorId(props.id, props.error);\n const descriptionId = formFieldDescriptionId(\n props.id,\n props.description,\n props.error,\n );\n const a11y = useMemo<FormFieldA11y>(\n () => ({\n invalid: props.error ? true : undefined,\n describedBy: errorId ?? descriptionId,\n }),\n [props.error, errorId, descriptionId],\n );\n const children = (\n <FormFieldA11yContext.Provider value={a11y}>\n {props.children}\n </FormFieldA11yContext.Provider>\n );\n\n if (layout === \"row\") {\n return (\n <div\n className={cn(\n \"flex flex-col gap-3 px-4 py-3 sm:grid sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center sm:gap-6\",\n invalidClasses,\n props.className,\n )}\n data-invalid={dataInvalid}\n onBlur={onBlur}\n >\n <div className=\"flex flex-col gap-0.5\">\n {props.label && (\n <Label htmlFor={props.id} className=\"font-medium\">\n {props.label}\n {showRequiredMarker && (\n <span className=\"text-danger-text ml-0.5\" aria-hidden>\n *\n </span>\n )}\n </Label>\n )}\n {props.description && !props.error && (\n <p id={descriptionId} className=\"text-muted-foreground text-xs\">\n {props.description}\n </p>\n )}\n {props.error && (\n <p\n id={errorId}\n className=\"text-danger-text flex items-center gap-1 text-xs\"\n role=\"alert\"\n >\n <span aria-hidden>⚠</span>\n {props.error}\n </p>\n )}\n </div>\n <div className=\"flex min-w-0 justify-start sm:justify-end\">\n {children}\n </div>\n </div>\n );\n }\n\n return (\n <div\n className={cn(\"flex flex-col gap-1.5\", invalidClasses, props.className)}\n data-invalid={dataInvalid}\n onBlur={onBlur}\n >\n {props.label && (\n <Label htmlFor={props.id}>\n {props.label}\n {showRequiredMarker && (\n <span className=\"text-danger-text ml-0.5\" aria-hidden>\n *\n </span>\n )}\n </Label>\n )}\n {children}\n {props.description && !props.error && (\n <p id={descriptionId} className=\"text-muted-foreground text-xs\">\n {props.description}\n </p>\n )}\n {props.error && (\n <p\n id={errorId}\n className=\"text-danger-text flex items-center gap-1 text-xs\"\n role=\"alert\"\n >\n <span aria-hidden>⚠</span>\n {props.error}\n </p>\n )}\n </div>\n );\n};\n\n/**\n * Id of the error element a `<FormField id={id} error>` renders.\n */\nexport function formFieldErrorId(\n id?: string,\n error?: string,\n): string | undefined {\n return id && error ? `${id}-error` : undefined;\n}\n\n/**\n * Id of the description element a `<FormField id={id} description>` renders\n * (the description is replaced by the error when both are set).\n */\nexport function formFieldDescriptionId(\n id?: string,\n description?: string,\n error?: string,\n): string | undefined {\n return id && description && !error ? `${id}-description` : undefined;\n}\n\n/**\n * The aria attributes a control spreads on its native element when it\n * renders its own `<FormField>` (id/error/description in hand). Widgets\n * nested under someone else's FormField use {@link useFormFieldA11y}\n * instead.\n */\nexport function formFieldAriaProps(props: {\n id?: string;\n error?: string;\n description?: string;\n required?: boolean;\n}): {\n \"aria-invalid\"?: true;\n \"aria-describedby\"?: string;\n \"aria-required\"?: true;\n} {\n return {\n \"aria-invalid\": props.error ? true : undefined,\n \"aria-describedby\":\n formFieldErrorId(props.id, props.error) ??\n formFieldDescriptionId(props.id, props.description, props.error),\n // The visible marker is `aria-hidden`, so without this a required field\n // announced nothing at all. It is read from the schema, never from the\n // marker flag — see `FormFieldRequiredMarkerProvider.tsx`.\n \"aria-required\": props.required ? true : undefined,\n };\n}\n\nexport interface FormFieldA11y {\n /**\n * `true` when the surrounding FormField carries an error — mirror it\n * onto the widget's `aria-invalid`.\n */\n invalid?: true;\n /**\n * Id of the FormField's error (or description) element — mirror it\n * onto the widget's `aria-describedby`.\n */\n describedBy?: string;\n}\n\n/**\n * Context exemption: the ids and invalid state one `FormField` hands the\n * widget inside it. Every field on a page has its own.\n */\nconst FormFieldA11yContext = createContext<FormFieldA11y>({});\n\n/**\n * Read the surrounding FormField's accessibility wiring. Leaf widgets\n * spread the result onto their native element so screen readers announce\n * the invalid state and the error/description text:\n *\n * ```tsx\n * const a11y = useFormFieldA11y();\n * <input aria-invalid={a11y.invalid} aria-describedby={a11y.describedBy} />\n * ```\n */\nexport function useFormFieldA11y(): FormFieldA11y {\n return useContext(FormFieldA11yContext);\n}\n"],"mappings":";;;;;;;;;;;;;;AAwEA,MAAa,aAAa,UAA0B;CAClD,MAAM,UAAU,mBAAmB;CACnC,MAAM,SAAS,MAAM,UAAU;CAG/B,MAAM,iBAAiB,2BAA2B;CAClD,MAAM,qBAAqB,MAAM,YAAY;CAC7C,MAAM,iBAAiB,MAAM,QACzB,0KACA;CACJ,MAAM,cAAc,MAAM,QAAQ,OAAO,KAAA;CAGzC,MAAM,SAAS,MAAM,UAChB,UAAsC;EACrC,MAAM,OAAO,MAAM;EACnB,IAAI,QAAQ,MAAM,cAAc,SAAS,IAAI,GAAG;EAChD,MAAM,SAAS;CACjB,IACA,KAAA;CAEJ,MAAM,UAAU,iBAAiB,MAAM,IAAI,MAAM,KAAK;CACtD,MAAM,gBAAgB,uBACpB,MAAM,IACN,MAAM,aACN,MAAM,KACR;CACA,MAAM,OAAO,eACJ;EACL,SAAS,MAAM,QAAQ,OAAO,KAAA;EAC9B,aAAa,WAAW;CAC1B,IACA;EAAC,MAAM;EAAO;EAAS;CAAa,CACtC;CACA,MAAM,WACJ,oBAAC,qBAAqB,UAAtB;EAA+B,OAAO;EACnC,UAAA,MAAM;CACsB,CAAA;CAGjC,IAAI,WAAW,OACb,OACE,qBAAC,OAAD;EACE,WAAW,GACT,oGACA,gBACA,MAAM,SACR;EACA,gBAAc;EACN;EAPV,UAAA,CASE,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA;IACG,MAAM,SACL,qBAAC,OAAD;KAAO,SAAS,MAAM;KAAI,WAAU;KAApC,UAAA,CACG,MAAM,OACN,sBAC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,IAAI,MAAM,KAAK,KACtC,uBAAuB,MAAM,IAAI,MAAM,aAAa,MAAM,KAAK;EAIjE,iBAAiB,MAAM,WAAW,OAAO,KAAA;CAC3C;AACF;;;;;AAmBA,MAAM,uBAAuB,cAA6B,CAAC,CAAC;;;;;;;;;;;AAY5D,SAAgB,mBAAkC;CAChD,OAAO,WAAW,oBAAoB;AACxC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uiFr.d.ts","sourceRoot":"","sources":["../../../src/i18n/fr/uiFr.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"uiFr.d.ts","sourceRoot":"","sources":["../../../src/i18n/fr/uiFr.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA6xCvC,CAAC"}
|
package/dist/i18n/fr/uiFr.js
CHANGED
|
@@ -45,17 +45,24 @@
|
|
|
45
45
|
*/
|
|
46
46
|
const uiFr = {
|
|
47
47
|
"ai.chat.approve": "Approuver",
|
|
48
|
+
"ai.chat.awaiting": "Action à valider",
|
|
48
49
|
"ai.chat.close": "Fermer",
|
|
49
50
|
"ai.chat.confirmTitle": "Exécuter $1 ?",
|
|
51
|
+
"ai.chat.continue": "Continuer",
|
|
52
|
+
"ai.chat.continueMessage": "Continue",
|
|
53
|
+
"ai.chat.cut": "Cette réponse a été coupée : elle a atteint la limite de longueur. Posez une question plus précise, ou continuez.",
|
|
50
54
|
"ai.chat.deny": "Refuser",
|
|
51
55
|
"ai.chat.empty": "Posez une question sur cette page.",
|
|
52
56
|
"ai.chat.emptyTitle": "Que voulez-vous faire ?",
|
|
53
57
|
"ai.chat.hint": "Entrée pour envoyer, Maj+Entrée pour aller à la ligne",
|
|
54
58
|
"ai.chat.history": "Historique",
|
|
55
59
|
"ai.chat.message": "Message",
|
|
60
|
+
"ai.chat.minimize": "Réduire",
|
|
56
61
|
"ai.chat.new": "Nouvelle conversation",
|
|
57
62
|
"ai.chat.noHistory": "Aucune conversation pour l'instant",
|
|
58
63
|
"ai.chat.placeholder": "Demandez à l'assistant",
|
|
64
|
+
"ai.chat.resize": "Redimensionner l'assistant",
|
|
65
|
+
"ai.chat.restore": "Ouvrir $1",
|
|
59
66
|
"ai.chat.running": "Exécution de $1",
|
|
60
67
|
"ai.chat.send": "Envoyer",
|
|
61
68
|
"ai.chat.stop": "Arrêter",
|
|
@@ -95,6 +102,8 @@ const uiFr = {
|
|
|
95
102
|
"dataTable.addFilter": "Ajouter des filtres",
|
|
96
103
|
"dataTable.addFilterLabel": "Ajouter un filtre",
|
|
97
104
|
"dataTable.filterBy": "Filtrer par",
|
|
105
|
+
"dataTable.filterColumn": "Filtrer : $1",
|
|
106
|
+
"dataTable.filterColumnMenu": "Filtrer",
|
|
98
107
|
"dataTable.filterName": "$1 :",
|
|
99
108
|
"dataTable.filterType.date": "date",
|
|
100
109
|
"dataTable.filterType.list": "liste",
|
|
@@ -550,6 +559,7 @@ const uiFr = {
|
|
|
550
559
|
"shell.settings.menu": "Menu du compte",
|
|
551
560
|
"shell.settings.signIn": "Se connecter",
|
|
552
561
|
"shell.settings.theme": "Thème",
|
|
562
|
+
"shell.settings.vision": "Mode daltonien",
|
|
553
563
|
"admin.nav.admin": "Administration",
|
|
554
564
|
"admin.nav.analytics": "Analytique",
|
|
555
565
|
"admin.nav.audits": "Journal d'audit",
|
|
@@ -959,6 +969,10 @@ const uiFr = {
|
|
|
959
969
|
"account.password.set": "Mot de passe défini",
|
|
960
970
|
"account.password.setDescription": "Vous pourrez vous connecter avec votre mot de passe en plus de votre méthode actuelle.",
|
|
961
971
|
"account.password.setTitle": "Définir un mot de passe",
|
|
972
|
+
"account.display.description": "La façon dont l'interface est dessinée pour vous, sur ce navigateur.",
|
|
973
|
+
"account.display.title": "Affichage",
|
|
974
|
+
"account.display.vision": "Mode daltonien",
|
|
975
|
+
"account.display.visionDescription": "Des couleurs d'état qui restent distinctes pour le daltonisme rouge-vert.",
|
|
962
976
|
"account.profile.accountDescription": "Informations que vous ne pouvez pas modifier depuis cette page.",
|
|
963
977
|
"account.profile.accountTitle": "Compte",
|
|
964
978
|
"account.profile.avatar": "Avatar",
|