@primecoderin/fast-ui-react 0.0.0-stage → 1.0.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/CHANGELOG.md +106 -0
- package/LICENSE +21 -0
- package/README.md +180 -3
- package/dist/_virtual/_rolldown/runtime.js +12 -0
- package/dist/charts.d.ts +7 -0
- package/dist/charts.js +7 -0
- package/dist/components/Avatar/Avatar.d.ts +12 -0
- package/dist/components/Avatar/Avatar.js +92 -0
- package/dist/components/Button/Button.d.ts +44 -0
- package/dist/components/Button/Button.js +221 -0
- package/dist/components/Checkbox/CheckboxBox.d.ts +33 -0
- package/dist/components/Checkbox/CheckboxBox.js +148 -0
- package/dist/components/CodeSnippet/CodeSnippet.d.ts +26 -0
- package/dist/components/CodeSnippet/CodeSnippet.js +153 -0
- package/dist/components/Collapsible/Collapsible.d.ts +20 -0
- package/dist/components/Collapsible/Collapsible.js +97 -0
- package/dist/components/Container/Container.d.ts +301 -0
- package/dist/components/Container/Container.js +20 -0
- package/dist/components/FloatingActionButton/FloatingActionButton.d.ts +22 -0
- package/dist/components/FloatingActionButton/FloatingActionButton.js +141 -0
- package/dist/components/Grid/Grid.d.ts +311 -0
- package/dist/components/Grid/Grid.js +30 -0
- package/dist/components/IconTile/IconTile.d.ts +12 -0
- package/dist/components/IconTile/IconTile.js +70 -0
- package/dist/components/InlineError/InlineError.d.ts +9 -0
- package/dist/components/InlineError/InlineError.js +62 -0
- package/dist/components/Kbd/Kbd.d.ts +11 -0
- package/dist/components/Kbd/Kbd.js +31 -0
- package/dist/components/Link/Link.d.ts +18 -0
- package/dist/components/Link/Link.js +68 -0
- package/dist/components/Menu/ContextMenu.d.ts +18 -0
- package/dist/components/Menu/ContextMenu.js +68 -0
- package/dist/components/Menu/Menu.d.ts +86 -0
- package/dist/components/Menu/Menu.js +394 -0
- package/dist/components/OtpInput/OtpInput.d.ts +32 -0
- package/dist/components/OtpInput/OtpInput.js +177 -0
- package/dist/components/Popover/HoverPopover.d.ts +22 -0
- package/dist/components/Popover/HoverPopover.js +74 -0
- package/dist/components/Popover/Popover.d.ts +21 -0
- package/dist/components/Popover/Popover.js +64 -0
- package/dist/components/ProgressBar/ProgressBar.d.ts +17 -0
- package/dist/components/ProgressBar/ProgressBar.js +44 -0
- package/dist/components/Rating/Rating.d.ts +49 -0
- package/dist/components/Rating/Rating.js +241 -0
- package/dist/components/ScrollArea/ScrollArea.d.ts +23 -0
- package/dist/components/ScrollArea/ScrollArea.js +90 -0
- package/dist/components/SegmentedControl/SegmentedControl.d.ts +29 -0
- package/dist/components/SegmentedControl/SegmentedControl.js +99 -0
- package/dist/components/Separator/Separator.d.ts +9 -0
- package/dist/components/Separator/Separator.js +34 -0
- package/dist/components/Skeleton/Skeleton.d.ts +31 -0
- package/dist/components/Skeleton/Skeleton.js +152 -0
- package/dist/components/Slider/Slider.d.ts +54 -0
- package/dist/components/Slider/Slider.js +178 -0
- package/dist/components/Spinner/Spinner.d.ts +17 -0
- package/dist/components/Spinner/Spinner.js +118 -0
- package/dist/components/Stack/Stack.d.ts +302 -0
- package/dist/components/Stack/Stack.js +14 -0
- package/dist/components/StateIcon/StateIcon.d.ts +11 -0
- package/dist/components/StateIcon/StateIcon.js +65 -0
- package/dist/components/StatusBadge/StatusBadge.d.ts +19 -0
- package/dist/components/StatusBadge/StatusBadge.js +82 -0
- package/dist/components/Tabs/Tabs.d.ts +28 -0
- package/dist/components/Tabs/Tabs.js +109 -0
- package/dist/components/Tag/Tag.d.ts +11 -0
- package/dist/components/Tag/Tag.js +66 -0
- package/dist/components/Toast/AppToaster.d.ts +8 -0
- package/dist/components/Toast/AppToaster.js +135 -0
- package/dist/components/Toast/toast-manager.d.ts +28 -0
- package/dist/components/Toast/toast-manager.js +47 -0
- package/dist/components/ToggleButton/ToggleButton.d.ts +26 -0
- package/dist/components/ToggleButton/ToggleButton.js +106 -0
- package/dist/components/ToggleGroup/ToggleGroup.d.ts +32 -0
- package/dist/components/ToggleGroup/ToggleGroup.js +79 -0
- package/dist/components/Tooltip/Tooltip.d.ts +16 -0
- package/dist/components/Tooltip/Tooltip.js +58 -0
- package/dist/components/Tooltip/TooltipGroup.d.ts +22 -0
- package/dist/components/Tooltip/TooltipGroup.js +65 -0
- package/dist/components/Typography/Typography.d.ts +17 -0
- package/dist/components/Typography/Typography.js +100 -0
- package/dist/editor-forms.d.ts +1 -0
- package/dist/editor-forms.js +1 -0
- package/dist/editor.d.ts +1 -0
- package/dist/editor.js +1 -0
- package/dist/fonts/LICENSE +93 -0
- package/dist/fonts/inter-cyrillic-ext-wght-normal.woff2 +0 -0
- package/dist/fonts/inter-cyrillic-wght-normal.woff2 +0 -0
- package/dist/fonts/inter-greek-ext-wght-normal.woff2 +0 -0
- package/dist/fonts/inter-greek-wght-normal.woff2 +0 -0
- package/dist/fonts/inter-latin-ext-wght-normal.woff2 +0 -0
- package/dist/fonts/inter-latin-wght-normal.woff2 +0 -0
- package/dist/fonts/inter-vietnamese-wght-normal.woff2 +0 -0
- package/dist/fonts.css +69 -0
- package/dist/forms.d.ts +22 -0
- package/dist/forms.js +23 -0
- package/dist/foundation.css +23 -0
- package/dist/global.css +116 -0
- package/dist/hooks/useAppToast.d.ts +12 -0
- package/dist/hooks/useAppToast.js +29 -0
- package/dist/icons/icons.d.ts +43 -0
- package/dist/icons/icons.js +44 -0
- package/dist/index.d.ts +106 -0
- package/dist/index.js +101 -0
- package/dist/patterns/Accordion/Accordion.d.ts +35 -0
- package/dist/patterns/Accordion/Accordion.js +139 -0
- package/dist/patterns/Alert/Alert.d.ts +38 -0
- package/dist/patterns/Alert/Alert.js +151 -0
- package/dist/patterns/AppShell/AppShell.d.ts +39 -0
- package/dist/patterns/AppShell/AppShell.js +218 -0
- package/dist/patterns/Breadcrumbs/Breadcrumbs.d.ts +21 -0
- package/dist/patterns/Breadcrumbs/Breadcrumbs.js +73 -0
- package/dist/patterns/Calendar/Calendar.d.ts +59 -0
- package/dist/patterns/Calendar/Calendar.js +283 -0
- package/dist/patterns/Calendar/DateRangePicker.d.ts +53 -0
- package/dist/patterns/Calendar/DateRangePicker.js +266 -0
- package/dist/patterns/Calendar/FormDateRangeField.d.ts +24 -0
- package/dist/patterns/Calendar/FormDateRangeField.js +138 -0
- package/dist/patterns/Card/Card.d.ts +26 -0
- package/dist/patterns/Card/Card.js +125 -0
- package/dist/patterns/Carousel/Carousel.d.ts +33 -0
- package/dist/patterns/Carousel/Carousel.js +127 -0
- package/dist/patterns/Cascader/Cascader.d.ts +53 -0
- package/dist/patterns/Cascader/Cascader.js +371 -0
- package/dist/patterns/Cascader/FormCascaderField.d.ts +21 -0
- package/dist/patterns/Cascader/FormCascaderField.js +130 -0
- package/dist/patterns/Charts/AreaChart.d.ts +13 -0
- package/dist/patterns/Charts/AreaChart.js +220 -0
- package/dist/patterns/Charts/BarChart.d.ts +11 -0
- package/dist/patterns/Charts/BarChart.js +220 -0
- package/dist/patterns/Charts/DonutChart.d.ts +37 -0
- package/dist/patterns/Charts/DonutChart.js +215 -0
- package/dist/patterns/Charts/GaugeChart.d.ts +44 -0
- package/dist/patterns/Charts/GaugeChart.js +210 -0
- package/dist/patterns/Charts/LineChart.d.ts +14 -0
- package/dist/patterns/Charts/LineChart.js +222 -0
- package/dist/patterns/Charts/Sparkline.d.ts +24 -0
- package/dist/patterns/Charts/Sparkline.js +81 -0
- package/dist/patterns/Charts/chart-parts.d.ts +139 -0
- package/dist/patterns/Charts/chart-parts.js +385 -0
- package/dist/patterns/Charts/gauge-math.d.ts +20 -0
- package/dist/patterns/Charts/gauge-math.js +21 -0
- package/dist/patterns/Charts/sparkline-path.d.ts +11 -0
- package/dist/patterns/Charts/sparkline-path.js +24 -0
- package/dist/patterns/ColorPicker/ColorPicker.d.ts +50 -0
- package/dist/patterns/ColorPicker/ColorPicker.js +590 -0
- package/dist/patterns/ColorPicker/FormColorField.d.ts +21 -0
- package/dist/patterns/ColorPicker/FormColorField.js +130 -0
- package/dist/patterns/ColorPicker/color-value.d.ts +19 -0
- package/dist/patterns/ColorPicker/color-value.js +72 -0
- package/dist/patterns/Combobox/Autocomplete.d.ts +48 -0
- package/dist/patterns/Combobox/Autocomplete.js +158 -0
- package/dist/patterns/Combobox/Combobox.d.ts +52 -0
- package/dist/patterns/Combobox/Combobox.js +195 -0
- package/dist/patterns/Combobox/ComboboxPopup.d.ts +24 -0
- package/dist/patterns/Combobox/ComboboxPopup.js +107 -0
- package/dist/patterns/Combobox/FormAutocompleteField.d.ts +17 -0
- package/dist/patterns/Combobox/FormAutocompleteField.js +119 -0
- package/dist/patterns/Combobox/FormComboboxField.d.ts +18 -0
- package/dist/patterns/Combobox/FormComboboxField.js +119 -0
- package/dist/patterns/Combobox/FormMultiSelectField.d.ts +18 -0
- package/dist/patterns/Combobox/FormMultiSelectField.js +119 -0
- package/dist/patterns/Combobox/MultiSelect.d.ts +54 -0
- package/dist/patterns/Combobox/MultiSelect.js +175 -0
- package/dist/patterns/CommandPalette/CommandPalette.d.ts +50 -0
- package/dist/patterns/CommandPalette/CommandPalette.js +193 -0
- package/dist/patterns/DataTable/DataTable.d.ts +107 -0
- package/dist/patterns/DataTable/DataTable.js +364 -0
- package/dist/patterns/DateTimePicker/DateTimePanel.d.ts +28 -0
- package/dist/patterns/DateTimePicker/DateTimePanel.js +444 -0
- package/dist/patterns/DateTimePicker/DateTimePicker.d.ts +75 -0
- package/dist/patterns/DateTimePicker/DateTimePicker.js +271 -0
- package/dist/patterns/DateTimePicker/FormDateTimeField.d.ts +32 -0
- package/dist/patterns/DateTimePicker/FormDateTimeField.js +148 -0
- package/dist/patterns/DateTimePicker/TimeSliders.d.ts +14 -0
- package/dist/patterns/DateTimePicker/TimeSliders.js +206 -0
- package/dist/patterns/DateTimePicker/picker-labels.d.ts +30 -0
- package/dist/patterns/DateTimePicker/picker-labels.js +23 -0
- package/dist/patterns/DateTimePicker/picker-values.d.ts +98 -0
- package/dist/patterns/DateTimePicker/picker-values.js +194 -0
- package/dist/patterns/DescriptionList/DescriptionList.d.ts +20 -0
- package/dist/patterns/DescriptionList/DescriptionList.js +57 -0
- package/dist/patterns/Dialog/Dialog.d.ts +26 -0
- package/dist/patterns/Dialog/Dialog.js +212 -0
- package/dist/patterns/Drawer/Drawer.d.ts +33 -0
- package/dist/patterns/Drawer/Drawer.js +153 -0
- package/dist/patterns/EmptyState/EmptyState.d.ts +35 -0
- package/dist/patterns/EmptyState/EmptyState.js +44 -0
- package/dist/patterns/FileUpload/FileUpload.d.ts +87 -0
- package/dist/patterns/FileUpload/FileUpload.js +417 -0
- package/dist/patterns/FileUpload/FormFileUploadField.d.ts +19 -0
- package/dist/patterns/FileUpload/FormFileUploadField.js +117 -0
- package/dist/patterns/FileUpload/add-files.d.ts +26 -0
- package/dist/patterns/FileUpload/add-files.js +35 -0
- package/dist/patterns/FileUpload/file-size.d.ts +14 -0
- package/dist/patterns/FileUpload/file-size.js +44 -0
- package/dist/patterns/FormField/CheckboxField.d.ts +26 -0
- package/dist/patterns/FormField/CheckboxField.js +97 -0
- package/dist/patterns/FormField/FieldFrame.d.ts +85 -0
- package/dist/patterns/FormField/FieldFrame.js +257 -0
- package/dist/patterns/FormField/FormCheckboxField.d.ts +17 -0
- package/dist/patterns/FormField/FormCheckboxField.js +92 -0
- package/dist/patterns/FormField/FormRadioGroupField.d.ts +16 -0
- package/dist/patterns/FormField/FormRadioGroupField.js +97 -0
- package/dist/patterns/FormField/FormRatingField.d.ts +19 -0
- package/dist/patterns/FormField/FormRatingField.js +119 -0
- package/dist/patterns/FormField/FormSelectField.d.ts +16 -0
- package/dist/patterns/FormField/FormSelectField.js +91 -0
- package/dist/patterns/FormField/FormSliderField.d.ts +22 -0
- package/dist/patterns/FormField/FormSliderField.js +128 -0
- package/dist/patterns/FormField/FormSwitchField.d.ts +19 -0
- package/dist/patterns/FormField/FormSwitchField.js +88 -0
- package/dist/patterns/FormField/FormTextAreaField.d.ts +12 -0
- package/dist/patterns/FormField/FormTextAreaField.js +91 -0
- package/dist/patterns/FormField/FormTextField.d.ts +23 -0
- package/dist/patterns/FormField/FormTextField.js +103 -0
- package/dist/patterns/FormField/RadioGroupField.d.ts +38 -0
- package/dist/patterns/FormField/RadioGroupField.js +201 -0
- package/dist/patterns/FormField/SelectField.d.ts +43 -0
- package/dist/patterns/FormField/SelectField.js +211 -0
- package/dist/patterns/FormField/SwitchField.d.ts +27 -0
- package/dist/patterns/FormField/SwitchField.js +105 -0
- package/dist/patterns/FormField/TextAreaField.d.ts +37 -0
- package/dist/patterns/FormField/TextAreaField.js +134 -0
- package/dist/patterns/FormField/TextField.d.ts +51 -0
- package/dist/patterns/FormField/TextField.js +256 -0
- package/dist/patterns/FormField/error-message.d.ts +6 -0
- package/dist/patterns/FormField/error-message.js +8 -0
- package/dist/patterns/FormField/field-styles.d.ts +44 -0
- package/dist/patterns/FormField/field-styles.js +89 -0
- package/dist/patterns/FormField/field-types.d.ts +4 -0
- package/dist/patterns/FormField/use-field-ids.d.ts +18 -0
- package/dist/patterns/FormField/use-field-ids.js +53 -0
- package/dist/patterns/List/List.d.ts +38 -0
- package/dist/patterns/List/List.js +174 -0
- package/dist/patterns/MentionsInput/FormMentionsField.d.ts +18 -0
- package/dist/patterns/MentionsInput/FormMentionsField.js +124 -0
- package/dist/patterns/MentionsInput/MentionsInput.d.ts +57 -0
- package/dist/patterns/MentionsInput/MentionsInput.js +133 -0
- package/dist/patterns/MentionsInput/mention-text.d.ts +24 -0
- package/dist/patterns/MentionsInput/mention-text.js +31 -0
- package/dist/patterns/Menubar/Menubar.d.ts +22 -0
- package/dist/patterns/Menubar/Menubar.js +79 -0
- package/dist/patterns/NavigationMenu/NavigationMenu.d.ts +27 -0
- package/dist/patterns/NavigationMenu/NavigationMenu.js +104 -0
- package/dist/patterns/NumberField/FormNumberField.d.ts +18 -0
- package/dist/patterns/NumberField/FormNumberField.js +119 -0
- package/dist/patterns/NumberField/NumberField.d.ts +57 -0
- package/dist/patterns/NumberField/NumberField.js +242 -0
- package/dist/patterns/Pagination/Pagination.d.ts +31 -0
- package/dist/patterns/Pagination/Pagination.js +275 -0
- package/dist/patterns/Pagination/page-items.d.ts +18 -0
- package/dist/patterns/Pagination/page-items.js +40 -0
- package/dist/patterns/PhoneField/FormPhoneField.d.ts +22 -0
- package/dist/patterns/PhoneField/FormPhoneField.js +97 -0
- package/dist/patterns/PhoneField/PhoneField.d.ts +60 -0
- package/dist/patterns/PhoneField/PhoneField.js +448 -0
- package/dist/patterns/PhoneField/phone-value.d.ts +26 -0
- package/dist/patterns/PhoneField/phone-value.js +38 -0
- package/dist/patterns/QRCode/QRCode.d.ts +37 -0
- package/dist/patterns/QRCode/QRCode.js +120 -0
- package/dist/patterns/QRCode/qr-path.d.ts +7 -0
- package/dist/patterns/QRCode/qr-path.js +25 -0
- package/dist/patterns/ResizablePanels/ResizablePanels.d.ts +34 -0
- package/dist/patterns/ResizablePanels/ResizablePanels.js +175 -0
- package/dist/patterns/ResizablePanels/panel-sizes.d.ts +31 -0
- package/dist/patterns/ResizablePanels/panel-sizes.js +54 -0
- package/dist/patterns/RichTextEditor/FormRichTextField.d.ts +18 -0
- package/dist/patterns/RichTextEditor/FormRichTextField.js +118 -0
- package/dist/patterns/RichTextEditor/RichTextEditor.d.ts +71 -0
- package/dist/patterns/RichTextEditor/RichTextEditor.js +453 -0
- package/dist/patterns/SearchInput/SearchInput.d.ts +26 -0
- package/dist/patterns/SearchInput/SearchInput.js +98 -0
- package/dist/patterns/SideNav/SideNav.d.ts +50 -0
- package/dist/patterns/SideNav/SideNav.js +269 -0
- package/dist/patterns/Stat/Stat.d.ts +51 -0
- package/dist/patterns/Stat/Stat.js +292 -0
- package/dist/patterns/Stepper/Stepper.d.ts +35 -0
- package/dist/patterns/Stepper/Stepper.js +110 -0
- package/dist/patterns/TagGroup/TagGroup.d.ts +44 -0
- package/dist/patterns/TagGroup/TagGroup.js +151 -0
- package/dist/patterns/TagsInput/FormTagsInputField.d.ts +18 -0
- package/dist/patterns/TagsInput/FormTagsInputField.js +124 -0
- package/dist/patterns/TagsInput/TagsInput.d.ts +51 -0
- package/dist/patterns/TagsInput/TagsInput.js +97 -0
- package/dist/patterns/Timeline/Timeline.d.ts +29 -0
- package/dist/patterns/Timeline/Timeline.js +85 -0
- package/dist/patterns/Toolbar/Toolbar.d.ts +31 -0
- package/dist/patterns/Toolbar/Toolbar.js +105 -0
- package/dist/patterns/Tour/Tour.d.ts +38 -0
- package/dist/patterns/Tour/Tour.js +333 -0
- package/dist/patterns/TransferList/FormTransferListField.d.ts +19 -0
- package/dist/patterns/TransferList/FormTransferListField.js +117 -0
- package/dist/patterns/TransferList/TransferList.d.ts +53 -0
- package/dist/patterns/TransferList/TransferList.js +441 -0
- package/dist/patterns/TreeSelect/FormTreeSelectField.d.ts +28 -0
- package/dist/patterns/TreeSelect/FormTreeSelectField.js +88 -0
- package/dist/patterns/TreeSelect/TreeSelect.d.ts +49 -0
- package/dist/patterns/TreeSelect/TreeSelect.js +375 -0
- package/dist/patterns/TreeView/TreeView.d.ts +40 -0
- package/dist/patterns/TreeView/TreeView.js +296 -0
- package/dist/provider/DesignSystemProvider.d.ts +54 -0
- package/dist/provider/DesignSystemProvider.js +270 -0
- package/dist/provider/nonce.d.ts +7 -0
- package/dist/provider/nonce.js +13 -0
- package/dist/styles.css +2 -0
- package/dist/theme/chart-palette.d.ts +51 -0
- package/dist/theme/chart-palette.js +112 -0
- package/dist/theme/create-theme.d.ts +52 -0
- package/dist/theme/create-theme.js +75 -0
- package/dist/theme/style-element.d.ts +28 -0
- package/dist/theme/style-element.js +79 -0
- package/dist/theme/tenant-branding.d.ts +48 -0
- package/dist/theme/tenant-branding.js +65 -0
- package/dist/theme/theme-switch.d.ts +25 -0
- package/dist/theme/theme-switch.js +90 -0
- package/dist/theme/token-names.d.ts +3 -0
- package/dist/theme/token-names.js +166 -0
- package/dist/theme.css +241 -0
- package/dist/tokens.css +383 -0
- package/dist/types/direction.d.ts +4 -0
- package/dist/types/tone.d.ts +7 -0
- package/dist/utils/cn.d.ts +7 -0
- package/dist/utils/cn.js +50 -0
- package/dist/utils/first-field.d.ts +8 -0
- package/dist/utils/first-field.js +10 -0
- package/dist/utils/layout.d.ts +33 -0
- package/dist/utils/layout.js +30 -0
- package/dist/utils/popup.d.ts +12 -0
- package/dist/utils/popup.js +27 -0
- package/docs/accessibility.md +61 -0
- package/docs/advanced-components.md +38 -0
- package/docs/ai-assistants.md +44 -0
- package/docs/architecture.md +65 -0
- package/docs/browser-support.md +30 -0
- package/docs/charts.md +56 -0
- package/docs/components.md +2928 -0
- package/docs/conventions.md +19 -0
- package/docs/customization.md +79 -0
- package/docs/dates-files-data.md +48 -0
- package/docs/design-principles.md +50 -0
- package/docs/faq.md +68 -0
- package/docs/forms.md +114 -0
- package/docs/getting-started.md +64 -0
- package/docs/icons.md +48 -0
- package/docs/internationalization.md +64 -0
- package/docs/layout-and-navigation.md +51 -0
- package/docs/nextjs.md +69 -0
- package/docs/releasing.md +40 -0
- package/docs/testing.md +242 -0
- package/docs/theming.md +118 -0
- package/docs/typescript.md +62 -0
- package/llms-full.txt +4573 -0
- package/llms.txt +52 -0
- package/package.json +193 -6
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { c } from "react/compiler-runtime";
|
|
3
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
4
|
+
import { Progress } from "@base-ui/react/progress";
|
|
5
|
+
import { File, UploadCloud, X } from "lucide-react";
|
|
6
|
+
import { cn } from "../../utils/cn.js";
|
|
7
|
+
import { Button } from "../../components/Button/Button.js";
|
|
8
|
+
import { addFiles } from "./add-files.js";
|
|
9
|
+
import { formatFileSize } from "./file-size.js";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
// src/patterns/FileUpload/FileUpload.tsx
|
|
12
|
+
/**
|
|
13
|
+
* Puts files in a file input, where a form's own submit finds them. Whether it could: a browser that cannot build a
|
|
14
|
+
* DataTransfer leaves the input as it is.
|
|
15
|
+
*/
|
|
16
|
+
var fillInput = (element, files) => {
|
|
17
|
+
if (typeof DataTransfer === "undefined") return false;
|
|
18
|
+
try {
|
|
19
|
+
const transfer = new DataTransfer();
|
|
20
|
+
for (const file of files) transfer.items.add(file);
|
|
21
|
+
element.files = transfer.files;
|
|
22
|
+
return true;
|
|
23
|
+
} catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A drop area and a button for choosing files, and the list of what was chosen, each with its size, a progress
|
|
29
|
+
* bar if the app reports one, and a button that removes it. Files are checked against `accept`, `maxSize` and
|
|
30
|
+
* `maxFiles` as they are added; what is refused is reported, not shown, so the app words it. The drop is for the
|
|
31
|
+
* pointer; the button is for everyone else. Sending the files is the app's; a form the browser submits itself
|
|
32
|
+
* sends them under `name`. A file's error is announced when the app sets it, and describes its Remove button.
|
|
33
|
+
*/
|
|
34
|
+
var FileUpload = (t0) => {
|
|
35
|
+
const $ = c(98);
|
|
36
|
+
const { value, onValueChange, labels, accept, multiple: t1, maxSize, maxFiles, onReject, statuses, description, locale, disabled: t2, invalid: t3, name, id, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, onBlur, buttonRef, className } = t0;
|
|
37
|
+
const multiple = t1 === void 0 ? false : t1;
|
|
38
|
+
const disabled = t2 === void 0 ? false : t2;
|
|
39
|
+
const invalid = t3 === void 0 ? false : t3;
|
|
40
|
+
const input = useRef(null);
|
|
41
|
+
const root = useRef(null);
|
|
42
|
+
const list = useRef(null);
|
|
43
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
44
|
+
const listId = useId();
|
|
45
|
+
const focusAfterRemove = useRef(null);
|
|
46
|
+
let t4;
|
|
47
|
+
let t5;
|
|
48
|
+
if ($[0] !== value) {
|
|
49
|
+
t4 = () => {
|
|
50
|
+
if (input.current) fillInput(input.current, value);
|
|
51
|
+
};
|
|
52
|
+
t5 = [value];
|
|
53
|
+
$[0] = value;
|
|
54
|
+
$[1] = t4;
|
|
55
|
+
$[2] = t5;
|
|
56
|
+
} else {
|
|
57
|
+
t4 = $[1];
|
|
58
|
+
t5 = $[2];
|
|
59
|
+
}
|
|
60
|
+
useEffect(t4, t5);
|
|
61
|
+
let t6;
|
|
62
|
+
let t7;
|
|
63
|
+
if ($[3] !== value) {
|
|
64
|
+
t6 = () => {
|
|
65
|
+
const pending = focusAfterRemove.current;
|
|
66
|
+
if (pending === null) return;
|
|
67
|
+
focusAfterRemove.current = null;
|
|
68
|
+
if (value.includes(pending.removed)) return;
|
|
69
|
+
const at = pending.next === null ? -1 : value.indexOf(pending.next);
|
|
70
|
+
(at === -1 ? root.current?.querySelector("[data-browse]") : list.current?.querySelectorAll("[data-remove]")[at])?.focus();
|
|
71
|
+
};
|
|
72
|
+
t7 = [value];
|
|
73
|
+
$[3] = value;
|
|
74
|
+
$[4] = t6;
|
|
75
|
+
$[5] = t7;
|
|
76
|
+
} else {
|
|
77
|
+
t6 = $[4];
|
|
78
|
+
t7 = $[5];
|
|
79
|
+
}
|
|
80
|
+
useEffect(t6, t7);
|
|
81
|
+
let t8;
|
|
82
|
+
if ($[6] !== accept || $[7] !== maxFiles || $[8] !== maxSize || $[9] !== multiple || $[10] !== onReject || $[11] !== onValueChange || $[12] !== value) {
|
|
83
|
+
t8 = (incoming) => {
|
|
84
|
+
const { files, rejected } = addFiles(value, incoming, {
|
|
85
|
+
accept,
|
|
86
|
+
multiple,
|
|
87
|
+
maxSize,
|
|
88
|
+
maxFiles
|
|
89
|
+
});
|
|
90
|
+
if (rejected.length > 0) onReject?.(rejected);
|
|
91
|
+
if (files.length !== value.length || files.some((file, at_0) => file !== value[at_0])) onValueChange(files);
|
|
92
|
+
};
|
|
93
|
+
$[6] = accept;
|
|
94
|
+
$[7] = maxFiles;
|
|
95
|
+
$[8] = maxSize;
|
|
96
|
+
$[9] = multiple;
|
|
97
|
+
$[10] = onReject;
|
|
98
|
+
$[11] = onValueChange;
|
|
99
|
+
$[12] = value;
|
|
100
|
+
$[13] = t8;
|
|
101
|
+
} else t8 = $[13];
|
|
102
|
+
const add = t8;
|
|
103
|
+
let t9;
|
|
104
|
+
if ($[14] !== accept || $[15] !== add || $[16] !== ariaDescribedBy || $[17] !== ariaLabel || $[18] !== ariaLabelledBy || $[19] !== buttonRef || $[20] !== className || $[21] !== description || $[22] !== disabled || $[23] !== id || $[24] !== invalid || $[25] !== isDragging || $[26] !== labels || $[27] !== listId || $[28] !== locale || $[29] !== multiple || $[30] !== name || $[31] !== onBlur || $[32] !== onValueChange || $[33] !== statuses || $[34] !== value) {
|
|
105
|
+
const remove = (file_0, at_1) => {
|
|
106
|
+
focusAfterRemove.current = {
|
|
107
|
+
removed: file_0,
|
|
108
|
+
next: value[at_1 + 1] ?? value[at_1 - 1] ?? null
|
|
109
|
+
};
|
|
110
|
+
onValueChange(value.filter((other) => other !== file_0));
|
|
111
|
+
};
|
|
112
|
+
const t10 = value.length > 0 ? listId : void 0;
|
|
113
|
+
let t11;
|
|
114
|
+
if ($[36] !== ariaDescribedBy || $[37] !== t10) {
|
|
115
|
+
t11 = [ariaDescribedBy, t10].filter(Boolean);
|
|
116
|
+
$[36] = ariaDescribedBy;
|
|
117
|
+
$[37] = t10;
|
|
118
|
+
$[38] = t11;
|
|
119
|
+
} else t11 = $[38];
|
|
120
|
+
const browseDescribedBy = t11.join(" ");
|
|
121
|
+
let t12;
|
|
122
|
+
if ($[39] !== add || $[40] !== disabled) {
|
|
123
|
+
t12 = (event) => {
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
setIsDragging(false);
|
|
126
|
+
if (disabled) return;
|
|
127
|
+
add([...event.dataTransfer.files]);
|
|
128
|
+
};
|
|
129
|
+
$[39] = add;
|
|
130
|
+
$[40] = disabled;
|
|
131
|
+
$[41] = t12;
|
|
132
|
+
} else t12 = $[41];
|
|
133
|
+
const onDrop = t12;
|
|
134
|
+
let t13;
|
|
135
|
+
if ($[42] !== className) {
|
|
136
|
+
t13 = cn("flex min-w-0 flex-col gap-3", className);
|
|
137
|
+
$[42] = className;
|
|
138
|
+
$[43] = t13;
|
|
139
|
+
} else t13 = $[43];
|
|
140
|
+
let t14;
|
|
141
|
+
if ($[44] !== id) {
|
|
142
|
+
t14 = id ? { id } : {};
|
|
143
|
+
$[44] = id;
|
|
144
|
+
$[45] = t14;
|
|
145
|
+
} else t14 = $[45];
|
|
146
|
+
let t15;
|
|
147
|
+
if ($[46] !== ariaLabel) {
|
|
148
|
+
t15 = ariaLabel ? { "aria-label": ariaLabel } : {};
|
|
149
|
+
$[46] = ariaLabel;
|
|
150
|
+
$[47] = t15;
|
|
151
|
+
} else t15 = $[47];
|
|
152
|
+
let t16;
|
|
153
|
+
if ($[48] !== ariaLabelledBy) {
|
|
154
|
+
t16 = ariaLabelledBy ? { "aria-labelledby": ariaLabelledBy } : {};
|
|
155
|
+
$[48] = ariaLabelledBy;
|
|
156
|
+
$[49] = t16;
|
|
157
|
+
} else t16 = $[49];
|
|
158
|
+
let t17;
|
|
159
|
+
if ($[50] !== ariaDescribedBy) {
|
|
160
|
+
t17 = ariaDescribedBy ? { "aria-describedby": ariaDescribedBy } : {};
|
|
161
|
+
$[50] = ariaDescribedBy;
|
|
162
|
+
$[51] = t17;
|
|
163
|
+
} else t17 = $[51];
|
|
164
|
+
const t18 = invalid || void 0;
|
|
165
|
+
const t19 = invalid || void 0;
|
|
166
|
+
const t20 = isDragging || void 0;
|
|
167
|
+
const t21 = disabled || void 0;
|
|
168
|
+
let t22;
|
|
169
|
+
if ($[52] === Symbol.for("react.memo_cache_sentinel")) {
|
|
170
|
+
t22 = cn("flex flex-col items-center gap-2 rounded-lg border border-dashed border-line-strong bg-surface px-4 py-6 text-center text-body-sm text-fg-secondary transition-colors", "data-dragging:border-primary data-dragging:bg-primary-pale data-invalid:border-error-solid data-disabled:cursor-not-allowed data-disabled:bg-subtle");
|
|
171
|
+
$[52] = t22;
|
|
172
|
+
} else t22 = $[52];
|
|
173
|
+
let t23;
|
|
174
|
+
if ($[53] !== disabled) {
|
|
175
|
+
t23 = (event_0) => {
|
|
176
|
+
event_0.preventDefault();
|
|
177
|
+
if (!disabled) setIsDragging(true);
|
|
178
|
+
};
|
|
179
|
+
$[53] = disabled;
|
|
180
|
+
$[54] = t23;
|
|
181
|
+
} else t23 = $[54];
|
|
182
|
+
let t24;
|
|
183
|
+
if ($[55] === Symbol.for("react.memo_cache_sentinel")) {
|
|
184
|
+
t24 = (event_1) => {
|
|
185
|
+
if (!event_1.currentTarget.contains(event_1.relatedTarget)) setIsDragging(false);
|
|
186
|
+
};
|
|
187
|
+
$[55] = t24;
|
|
188
|
+
} else t24 = $[55];
|
|
189
|
+
let t25;
|
|
190
|
+
if ($[56] === Symbol.for("react.memo_cache_sentinel")) {
|
|
191
|
+
t25 = /* @__PURE__ */ jsx(UploadCloud, {
|
|
192
|
+
"aria-hidden": "true",
|
|
193
|
+
className: "size-6 text-fg-tertiary"
|
|
194
|
+
});
|
|
195
|
+
$[56] = t25;
|
|
196
|
+
} else t25 = $[56];
|
|
197
|
+
let t26;
|
|
198
|
+
if ($[57] !== labels.drop) {
|
|
199
|
+
t26 = /* @__PURE__ */ jsx("span", { children: labels.drop });
|
|
200
|
+
$[57] = labels.drop;
|
|
201
|
+
$[58] = t26;
|
|
202
|
+
} else t26 = $[58];
|
|
203
|
+
let t27;
|
|
204
|
+
if ($[59] !== browseDescribedBy) {
|
|
205
|
+
t27 = browseDescribedBy ? { "aria-describedby": browseDescribedBy } : {};
|
|
206
|
+
$[59] = browseDescribedBy;
|
|
207
|
+
$[60] = t27;
|
|
208
|
+
} else t27 = $[60];
|
|
209
|
+
let t28;
|
|
210
|
+
if ($[61] === Symbol.for("react.memo_cache_sentinel")) {
|
|
211
|
+
t28 = () => {
|
|
212
|
+
input.current?.click();
|
|
213
|
+
};
|
|
214
|
+
$[61] = t28;
|
|
215
|
+
} else t28 = $[61];
|
|
216
|
+
let t29;
|
|
217
|
+
if ($[62] !== buttonRef || $[63] !== disabled || $[64] !== labels.browse || $[65] !== onBlur || $[66] !== t27) {
|
|
218
|
+
t29 = /* @__PURE__ */ jsx(Button, {
|
|
219
|
+
ref: buttonRef,
|
|
220
|
+
variant: "secondary",
|
|
221
|
+
size: "small",
|
|
222
|
+
disabled,
|
|
223
|
+
"data-browse": "",
|
|
224
|
+
...t27,
|
|
225
|
+
onClick: t28,
|
|
226
|
+
onBlur,
|
|
227
|
+
children: labels.browse
|
|
228
|
+
});
|
|
229
|
+
$[62] = buttonRef;
|
|
230
|
+
$[63] = disabled;
|
|
231
|
+
$[64] = labels.browse;
|
|
232
|
+
$[65] = onBlur;
|
|
233
|
+
$[66] = t27;
|
|
234
|
+
$[67] = t29;
|
|
235
|
+
} else t29 = $[67];
|
|
236
|
+
let t30;
|
|
237
|
+
if ($[68] !== description) {
|
|
238
|
+
t30 = description ? /* @__PURE__ */ jsx("span", {
|
|
239
|
+
className: "text-caption text-fg-tertiary",
|
|
240
|
+
children: description
|
|
241
|
+
}) : null;
|
|
242
|
+
$[68] = description;
|
|
243
|
+
$[69] = t30;
|
|
244
|
+
} else t30 = $[69];
|
|
245
|
+
let t31;
|
|
246
|
+
if ($[70] !== accept) {
|
|
247
|
+
t31 = accept ? { accept } : {};
|
|
248
|
+
$[70] = accept;
|
|
249
|
+
$[71] = t31;
|
|
250
|
+
} else t31 = $[71];
|
|
251
|
+
let t32;
|
|
252
|
+
if ($[72] !== name) {
|
|
253
|
+
t32 = name ? { name } : {};
|
|
254
|
+
$[72] = name;
|
|
255
|
+
$[73] = t32;
|
|
256
|
+
} else t32 = $[73];
|
|
257
|
+
let t33;
|
|
258
|
+
if ($[74] !== add || $[75] !== value) {
|
|
259
|
+
t33 = (event_2) => {
|
|
260
|
+
const element = event_2.currentTarget;
|
|
261
|
+
add([...element.files ?? []]);
|
|
262
|
+
if (!fillInput(element, value)) element.value = "";
|
|
263
|
+
};
|
|
264
|
+
$[74] = add;
|
|
265
|
+
$[75] = value;
|
|
266
|
+
$[76] = t33;
|
|
267
|
+
} else t33 = $[76];
|
|
268
|
+
let t34;
|
|
269
|
+
if ($[77] !== disabled || $[78] !== multiple || $[79] !== t31 || $[80] !== t32 || $[81] !== t33) {
|
|
270
|
+
t34 = /* @__PURE__ */ jsx("input", {
|
|
271
|
+
ref: input,
|
|
272
|
+
type: "file",
|
|
273
|
+
hidden: true,
|
|
274
|
+
tabIndex: -1,
|
|
275
|
+
"aria-hidden": "true",
|
|
276
|
+
multiple,
|
|
277
|
+
disabled,
|
|
278
|
+
...t31,
|
|
279
|
+
...t32,
|
|
280
|
+
onChange: t33
|
|
281
|
+
});
|
|
282
|
+
$[77] = disabled;
|
|
283
|
+
$[78] = multiple;
|
|
284
|
+
$[79] = t31;
|
|
285
|
+
$[80] = t32;
|
|
286
|
+
$[81] = t33;
|
|
287
|
+
$[82] = t34;
|
|
288
|
+
} else t34 = $[82];
|
|
289
|
+
let t35;
|
|
290
|
+
if ($[83] !== onDrop || $[84] !== t14 || $[85] !== t15 || $[86] !== t16 || $[87] !== t17 || $[88] !== t18 || $[89] !== t19 || $[90] !== t20 || $[91] !== t21 || $[92] !== t23 || $[93] !== t26 || $[94] !== t29 || $[95] !== t30 || $[96] !== t34) {
|
|
291
|
+
t35 = /* @__PURE__ */ jsxs("div", {
|
|
292
|
+
role: "group",
|
|
293
|
+
...t14,
|
|
294
|
+
...t15,
|
|
295
|
+
...t16,
|
|
296
|
+
...t17,
|
|
297
|
+
"aria-invalid": t18,
|
|
298
|
+
"data-invalid": t19,
|
|
299
|
+
"data-dragging": t20,
|
|
300
|
+
"data-disabled": t21,
|
|
301
|
+
className: t22,
|
|
302
|
+
onDragOver: t23,
|
|
303
|
+
onDragLeave: t24,
|
|
304
|
+
onDrop,
|
|
305
|
+
children: [
|
|
306
|
+
t25,
|
|
307
|
+
t26,
|
|
308
|
+
t29,
|
|
309
|
+
t30,
|
|
310
|
+
t34
|
|
311
|
+
]
|
|
312
|
+
});
|
|
313
|
+
$[83] = onDrop;
|
|
314
|
+
$[84] = t14;
|
|
315
|
+
$[85] = t15;
|
|
316
|
+
$[86] = t16;
|
|
317
|
+
$[87] = t17;
|
|
318
|
+
$[88] = t18;
|
|
319
|
+
$[89] = t19;
|
|
320
|
+
$[90] = t20;
|
|
321
|
+
$[91] = t21;
|
|
322
|
+
$[92] = t23;
|
|
323
|
+
$[93] = t26;
|
|
324
|
+
$[94] = t29;
|
|
325
|
+
$[95] = t30;
|
|
326
|
+
$[96] = t34;
|
|
327
|
+
$[97] = t35;
|
|
328
|
+
} else t35 = $[97];
|
|
329
|
+
t9 = /* @__PURE__ */ jsxs("div", {
|
|
330
|
+
ref: root,
|
|
331
|
+
className: t13,
|
|
332
|
+
children: [t35, value.length > 0 ? /* @__PURE__ */ jsx("ul", {
|
|
333
|
+
ref: list,
|
|
334
|
+
id: listId,
|
|
335
|
+
className: "m-0 flex list-none flex-col gap-2 p-0",
|
|
336
|
+
children: value.map((file_1, at_2) => {
|
|
337
|
+
const status = statuses?.get(file_1);
|
|
338
|
+
const nameId = `${listId}-${String(at_2)}`;
|
|
339
|
+
const errorId = `${nameId}-error`;
|
|
340
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
341
|
+
className: "flex flex-col gap-1.5 rounded-md border border-line bg-surface px-3 py-2",
|
|
342
|
+
children: [
|
|
343
|
+
/* @__PURE__ */ jsxs("div", {
|
|
344
|
+
className: "flex items-center gap-2.5",
|
|
345
|
+
children: [
|
|
346
|
+
/* @__PURE__ */ jsx(File, {
|
|
347
|
+
"aria-hidden": "true",
|
|
348
|
+
className: "size-4 shrink-0 text-fg-secondary"
|
|
349
|
+
}),
|
|
350
|
+
/* @__PURE__ */ jsx("span", {
|
|
351
|
+
id: nameId,
|
|
352
|
+
className: "min-w-0 flex-1 truncate text-body-sm text-fg",
|
|
353
|
+
children: file_1.name
|
|
354
|
+
}),
|
|
355
|
+
/* @__PURE__ */ jsx("span", {
|
|
356
|
+
className: "shrink-0 text-caption text-fg-secondary",
|
|
357
|
+
children: formatFileSize(file_1.size, locale)
|
|
358
|
+
}),
|
|
359
|
+
/* @__PURE__ */ jsx(Button, {
|
|
360
|
+
variant: "subtle",
|
|
361
|
+
size: "small",
|
|
362
|
+
disabled,
|
|
363
|
+
"aria-label": labels.remove(file_1.name),
|
|
364
|
+
...status?.error ? { "aria-describedby": errorId } : {},
|
|
365
|
+
"data-remove": "",
|
|
366
|
+
icon: /* @__PURE__ */ jsx(X, {}),
|
|
367
|
+
onClick: () => {
|
|
368
|
+
remove(file_1, at_2);
|
|
369
|
+
}
|
|
370
|
+
})
|
|
371
|
+
]
|
|
372
|
+
}),
|
|
373
|
+
status?.progress !== void 0 ? /* @__PURE__ */ jsx(Progress.Root, {
|
|
374
|
+
value: status.progress,
|
|
375
|
+
"aria-labelledby": nameId,
|
|
376
|
+
children: /* @__PURE__ */ jsx(Progress.Track, {
|
|
377
|
+
className: "relative block h-1.5 overflow-hidden rounded-pill bg-primary-light",
|
|
378
|
+
children: /* @__PURE__ */ jsx(Progress.Indicator, { className: "block h-full rounded-pill bg-primary transition-[width] duration-200 ease-standard motion-reduce:transition-none" })
|
|
379
|
+
})
|
|
380
|
+
}) : null,
|
|
381
|
+
status?.error ? /* @__PURE__ */ jsx("span", {
|
|
382
|
+
id: errorId,
|
|
383
|
+
role: "alert",
|
|
384
|
+
className: "text-caption text-error-text",
|
|
385
|
+
children: status.error
|
|
386
|
+
}) : null
|
|
387
|
+
]
|
|
388
|
+
}, `${file_1.name}-${String(file_1.size)}-${String(file_1.lastModified)}`);
|
|
389
|
+
})
|
|
390
|
+
}) : null]
|
|
391
|
+
});
|
|
392
|
+
$[14] = accept;
|
|
393
|
+
$[15] = add;
|
|
394
|
+
$[16] = ariaDescribedBy;
|
|
395
|
+
$[17] = ariaLabel;
|
|
396
|
+
$[18] = ariaLabelledBy;
|
|
397
|
+
$[19] = buttonRef;
|
|
398
|
+
$[20] = className;
|
|
399
|
+
$[21] = description;
|
|
400
|
+
$[22] = disabled;
|
|
401
|
+
$[23] = id;
|
|
402
|
+
$[24] = invalid;
|
|
403
|
+
$[25] = isDragging;
|
|
404
|
+
$[26] = labels;
|
|
405
|
+
$[27] = listId;
|
|
406
|
+
$[28] = locale;
|
|
407
|
+
$[29] = multiple;
|
|
408
|
+
$[30] = name;
|
|
409
|
+
$[31] = onBlur;
|
|
410
|
+
$[32] = onValueChange;
|
|
411
|
+
$[33] = statuses;
|
|
412
|
+
$[34] = value;
|
|
413
|
+
$[35] = t9;
|
|
414
|
+
} else t9 = $[35];
|
|
415
|
+
return t9;
|
|
416
|
+
};
|
|
417
|
+
export { FileUpload };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Control, type ControllerProps, type FieldPath, type FieldValues } from "react-hook-form";
|
|
2
|
+
import type { FieldOrientation } from "../FormField/field-types.js";
|
|
3
|
+
import { type FileUploadProps } from "./FileUpload.js";
|
|
4
|
+
export type { FileUploadLabels } from "./FileUpload.js";
|
|
5
|
+
export interface FormFileUploadFieldProps<TValues extends FieldValues> extends Omit<FileUploadProps, "name" | "value" | "onValueChange" | "onBlur" | "invalid" | "buttonRef" | "id" | "aria-label" | "aria-labelledby" | "aria-describedby" | "className"> {
|
|
6
|
+
control: Control<TValues>;
|
|
7
|
+
name: FieldPath<TValues>;
|
|
8
|
+
label: string;
|
|
9
|
+
hint?: string | undefined;
|
|
10
|
+
required?: boolean | undefined;
|
|
11
|
+
/** Label above the control (default) or in a column beside it. */
|
|
12
|
+
orientation?: FieldOrientation | undefined;
|
|
13
|
+
/** react-hook-form validation rules, for forms that do not use a schema resolver. */
|
|
14
|
+
rules?: ControllerProps<TValues, FieldPath<TValues>>["rules"] | undefined;
|
|
15
|
+
/** Turns a stored schema message (an i18n key) into display text. */
|
|
16
|
+
formatError?: ((message: string) => string) | undefined;
|
|
17
|
+
}
|
|
18
|
+
/** A FileUpload in a field, bound to a react-hook-form field holding an array of `File`s. */
|
|
19
|
+
export declare const FormFileUploadField: <TValues extends FieldValues>({ control, name, label, hint, required, orientation, rules, formatError, disabled, ...uploadProps }: FormFileUploadFieldProps<TValues>) => import("react").JSX.Element;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { c } from "react/compiler-runtime";
|
|
3
|
+
import { Controller } from "react-hook-form";
|
|
4
|
+
import { toErrorText } from "../FormField/error-message.js";
|
|
5
|
+
import { FieldFrame } from "../FormField/FieldFrame.js";
|
|
6
|
+
import { useFieldIds } from "../FormField/use-field-ids.js";
|
|
7
|
+
import { FileUpload } from "./FileUpload.js";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
// src/patterns/FileUpload/FormFileUploadField.tsx
|
|
10
|
+
/** A FileUpload in a field, bound to a react-hook-form field holding an array of `File`s. */
|
|
11
|
+
var FormFileUploadField = (t0) => {
|
|
12
|
+
const $ = c(29);
|
|
13
|
+
let control;
|
|
14
|
+
let formatError;
|
|
15
|
+
let hint;
|
|
16
|
+
let label;
|
|
17
|
+
let name;
|
|
18
|
+
let orientation;
|
|
19
|
+
let required;
|
|
20
|
+
let rules;
|
|
21
|
+
let t1;
|
|
22
|
+
let uploadProps;
|
|
23
|
+
if ($[0] !== t0) {
|
|
24
|
+
({control, name, label, hint, required, orientation, rules, formatError, disabled: t1, ...uploadProps} = t0);
|
|
25
|
+
$[0] = t0;
|
|
26
|
+
$[1] = control;
|
|
27
|
+
$[2] = formatError;
|
|
28
|
+
$[3] = hint;
|
|
29
|
+
$[4] = label;
|
|
30
|
+
$[5] = name;
|
|
31
|
+
$[6] = orientation;
|
|
32
|
+
$[7] = required;
|
|
33
|
+
$[8] = rules;
|
|
34
|
+
$[9] = t1;
|
|
35
|
+
$[10] = uploadProps;
|
|
36
|
+
} else {
|
|
37
|
+
control = $[1];
|
|
38
|
+
formatError = $[2];
|
|
39
|
+
hint = $[3];
|
|
40
|
+
label = $[4];
|
|
41
|
+
name = $[5];
|
|
42
|
+
orientation = $[6];
|
|
43
|
+
required = $[7];
|
|
44
|
+
rules = $[8];
|
|
45
|
+
t1 = $[9];
|
|
46
|
+
uploadProps = $[10];
|
|
47
|
+
}
|
|
48
|
+
const disabled = t1 === void 0 ? false : t1;
|
|
49
|
+
const { labelId, messageIds, describe } = useFieldIds();
|
|
50
|
+
let t2;
|
|
51
|
+
if ($[11] !== rules) {
|
|
52
|
+
t2 = rules ? { rules } : {};
|
|
53
|
+
$[11] = rules;
|
|
54
|
+
$[12] = t2;
|
|
55
|
+
} else t2 = $[12];
|
|
56
|
+
let t3;
|
|
57
|
+
if ($[13] !== describe || $[14] !== disabled || $[15] !== formatError || $[16] !== hint || $[17] !== label || $[18] !== labelId || $[19] !== messageIds || $[20] !== orientation || $[21] !== required || $[22] !== uploadProps) {
|
|
58
|
+
t3 = (t4) => {
|
|
59
|
+
const { field, fieldState } = t4;
|
|
60
|
+
const errorMessage = toErrorText(fieldState.error?.message, formatError);
|
|
61
|
+
const describedBy = describe(errorMessage, hint);
|
|
62
|
+
return /* @__PURE__ */ jsx(FieldFrame, {
|
|
63
|
+
name: field.name,
|
|
64
|
+
label,
|
|
65
|
+
labelId,
|
|
66
|
+
triggerLabel: true,
|
|
67
|
+
messageIds,
|
|
68
|
+
disabled,
|
|
69
|
+
invalid: fieldState.invalid,
|
|
70
|
+
touched: fieldState.isTouched,
|
|
71
|
+
dirty: fieldState.isDirty,
|
|
72
|
+
...hint ? { hint } : {},
|
|
73
|
+
...required ? { required } : {},
|
|
74
|
+
...orientation ? { orientation } : {},
|
|
75
|
+
...errorMessage === void 0 ? {} : { errorMessage },
|
|
76
|
+
children: /* @__PURE__ */ jsx(FileUpload, {
|
|
77
|
+
...uploadProps,
|
|
78
|
+
buttonRef: field.ref,
|
|
79
|
+
"aria-labelledby": labelId,
|
|
80
|
+
...describedBy ? { "aria-describedby": describedBy } : {},
|
|
81
|
+
value: Array.isArray(field.value) ? field.value : [],
|
|
82
|
+
onValueChange: field.onChange,
|
|
83
|
+
onBlur: field.onBlur,
|
|
84
|
+
invalid: fieldState.invalid,
|
|
85
|
+
disabled
|
|
86
|
+
})
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
$[13] = describe;
|
|
90
|
+
$[14] = disabled;
|
|
91
|
+
$[15] = formatError;
|
|
92
|
+
$[16] = hint;
|
|
93
|
+
$[17] = label;
|
|
94
|
+
$[18] = labelId;
|
|
95
|
+
$[19] = messageIds;
|
|
96
|
+
$[20] = orientation;
|
|
97
|
+
$[21] = required;
|
|
98
|
+
$[22] = uploadProps;
|
|
99
|
+
$[23] = t3;
|
|
100
|
+
} else t3 = $[23];
|
|
101
|
+
let t4;
|
|
102
|
+
if ($[24] !== control || $[25] !== name || $[26] !== t2 || $[27] !== t3) {
|
|
103
|
+
t4 = /* @__PURE__ */ jsx(Controller, {
|
|
104
|
+
control,
|
|
105
|
+
name,
|
|
106
|
+
...t2,
|
|
107
|
+
render: t3
|
|
108
|
+
});
|
|
109
|
+
$[24] = control;
|
|
110
|
+
$[25] = name;
|
|
111
|
+
$[26] = t2;
|
|
112
|
+
$[27] = t3;
|
|
113
|
+
$[28] = t4;
|
|
114
|
+
} else t4 = $[28];
|
|
115
|
+
return t4;
|
|
116
|
+
};
|
|
117
|
+
export { FormFileUploadField };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { FileUploadRejection } from "./FileUpload.js";
|
|
2
|
+
/** What decides whether a file is added: FileUpload's props of the same names. */
|
|
3
|
+
export interface FileLimits {
|
|
4
|
+
/** The kinds of file taken, as the file input writes them: `"image/*,.pdf"`. Anything if omitted. */
|
|
5
|
+
accept?: string | undefined;
|
|
6
|
+
/** Whether the list takes several files. Otherwise it holds one, and a new file replaces it. */
|
|
7
|
+
multiple: boolean;
|
|
8
|
+
/** The largest a file may be, in bytes. */
|
|
9
|
+
maxSize?: number | undefined;
|
|
10
|
+
/** The most files the list takes. */
|
|
11
|
+
maxFiles?: number | undefined;
|
|
12
|
+
}
|
|
13
|
+
/** What adding files comes to: the new list, and the files that were refused, with the reason. */
|
|
14
|
+
export interface AddedFiles {
|
|
15
|
+
files: File[];
|
|
16
|
+
rejected: FileUploadRejection[];
|
|
17
|
+
}
|
|
18
|
+
/** The same file chosen twice: the same name, size and time of its last change. */
|
|
19
|
+
export declare const isSameFile: (a: File, b: File) => boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The list once files are chosen or dropped, in the order they came, and the files refused: `type` (not in
|
|
22
|
+
* `accept`), `size` (over `maxSize`) or `count` (no room: `maxFiles` reached, or, without `multiple`, a file was
|
|
23
|
+
* already taken from the same choice). A file already in the list is skipped and not reported. Without
|
|
24
|
+
* `multiple` the list starts again: the first file that passes replaces the one before.
|
|
25
|
+
*/
|
|
26
|
+
export declare const addFiles: (current: readonly File[], incoming: readonly File[], limits: FileLimits) => AddedFiles;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { matchesAccept } from "./file-size.js";
|
|
2
|
+
// src/patterns/FileUpload/add-files.ts
|
|
3
|
+
/** The same file chosen twice: the same name, size and time of its last change. */
|
|
4
|
+
var isSameFile = (a, b) => a.name === b.name && a.size === b.size && a.lastModified === b.lastModified;
|
|
5
|
+
/**
|
|
6
|
+
* The list once files are chosen or dropped, in the order they came, and the files refused: `type` (not in
|
|
7
|
+
* `accept`), `size` (over `maxSize`) or `count` (no room: `maxFiles` reached, or, without `multiple`, a file was
|
|
8
|
+
* already taken from the same choice). A file already in the list is skipped and not reported. Without
|
|
9
|
+
* `multiple` the list starts again: the first file that passes replaces the one before.
|
|
10
|
+
*/
|
|
11
|
+
var addFiles = (current, incoming, limits) => {
|
|
12
|
+
const { accept, multiple, maxSize, maxFiles } = limits;
|
|
13
|
+
const files = multiple ? [...current] : [];
|
|
14
|
+
const room = multiple ? maxFiles ?? Number.POSITIVE_INFINITY : Math.min(1, maxFiles ?? 1);
|
|
15
|
+
const rejected = [];
|
|
16
|
+
for (const file of incoming) if (!matchesAccept(file, accept)) rejected.push({
|
|
17
|
+
file,
|
|
18
|
+
reason: "type"
|
|
19
|
+
});
|
|
20
|
+
else if (maxSize !== void 0 && file.size > maxSize) rejected.push({
|
|
21
|
+
file,
|
|
22
|
+
reason: "size"
|
|
23
|
+
});
|
|
24
|
+
else if (files.some((other) => isSameFile(other, file))) continue;
|
|
25
|
+
else if (files.length >= room) rejected.push({
|
|
26
|
+
file,
|
|
27
|
+
reason: "count"
|
|
28
|
+
});
|
|
29
|
+
else files.push(file);
|
|
30
|
+
return {
|
|
31
|
+
files,
|
|
32
|
+
rejected
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export { addFiles, isSameFile };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A file's size the way a person reads it: "12 byte", "3.4 kB", "1.2 MB" in the user's language (the unit names
|
|
3
|
+
* come from the browser's Intl, so nothing here needs translating). Units step by 1024. `locale` is a BCP 47 tag;
|
|
4
|
+
* if omitted, the runtime's default locale (the browser's or the server's), not the page's `lang`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const formatFileSize: (bytes: number, locale?: string) => string;
|
|
7
|
+
/**
|
|
8
|
+
* Whether a file matches an `accept` list as the file input writes it: extensions (".png"), exact types
|
|
9
|
+
* ("image/png") and wildcards ("image/*"), separated by commas. An empty list accepts everything.
|
|
10
|
+
*/
|
|
11
|
+
export declare const matchesAccept: (file: {
|
|
12
|
+
name: string;
|
|
13
|
+
type: string;
|
|
14
|
+
}, accept: string | undefined) => boolean;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// src/patterns/FileUpload/file-size.ts
|
|
2
|
+
/** The units a size is written in, from the smallest: the bytes a file has become when it is divided by 1024 each time. */
|
|
3
|
+
var UNITS = [
|
|
4
|
+
"byte",
|
|
5
|
+
"kilobyte",
|
|
6
|
+
"megabyte",
|
|
7
|
+
"gigabyte",
|
|
8
|
+
"terabyte"
|
|
9
|
+
];
|
|
10
|
+
/**
|
|
11
|
+
* A file's size the way a person reads it: "12 byte", "3.4 kB", "1.2 MB" in the user's language (the unit names
|
|
12
|
+
* come from the browser's Intl, so nothing here needs translating). Units step by 1024. `locale` is a BCP 47 tag;
|
|
13
|
+
* if omitted, the runtime's default locale (the browser's or the server's), not the page's `lang`.
|
|
14
|
+
*/
|
|
15
|
+
var formatFileSize = (bytes, locale) => {
|
|
16
|
+
let value = Math.max(0, bytes);
|
|
17
|
+
let unit = 0;
|
|
18
|
+
while (value >= 1024 && unit < UNITS.length - 1) {
|
|
19
|
+
value /= 1024;
|
|
20
|
+
unit += 1;
|
|
21
|
+
}
|
|
22
|
+
return new Intl.NumberFormat(locale, {
|
|
23
|
+
style: "unit",
|
|
24
|
+
unit: UNITS[unit] ?? "byte",
|
|
25
|
+
unitDisplay: "narrow",
|
|
26
|
+
maximumFractionDigits: unit === 0 ? 0 : 1
|
|
27
|
+
}).format(value);
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Whether a file matches an `accept` list as the file input writes it: extensions (".png"), exact types
|
|
31
|
+
* ("image/png") and wildcards ("image/*"), separated by commas. An empty list accepts everything.
|
|
32
|
+
*/
|
|
33
|
+
var matchesAccept = (file, accept) => {
|
|
34
|
+
const tokens = (accept ?? "").split(",").map((token) => token.trim().toLowerCase()).filter((token) => token !== "");
|
|
35
|
+
if (tokens.length === 0) return true;
|
|
36
|
+
const name = file.name.toLowerCase();
|
|
37
|
+
const type = file.type.toLowerCase();
|
|
38
|
+
return tokens.some((token) => {
|
|
39
|
+
if (token.startsWith(".")) return name.endsWith(token);
|
|
40
|
+
if (token.endsWith("/*")) return type.startsWith(token.slice(0, -1));
|
|
41
|
+
return type === token;
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
export { formatFileSize, matchesAccept };
|