@grampro/kit 0.0.0-stage → 2.4.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/.gbs/skills/gbs-components/SKILL.md +190 -0
- package/.gbs/skills/gbs-components/references/accessibility.md +102 -0
- package/.gbs/skills/gbs-components/references/data-display.md +185 -0
- package/.gbs/skills/gbs-components/references/data-grid.md +116 -0
- package/.gbs/skills/gbs-components/references/forms.md +202 -0
- package/.gbs/skills/gbs-components/references/install.md +211 -0
- package/.gbs/skills/gbs-components/references/overlays.md +206 -0
- package/.gbs/skills/gbs-components/references/pickers.md +83 -0
- package/.gbs/skills/gbs-components/references/styling.md +246 -0
- package/.gbs/skills/gbs-components/references/toaster.md +57 -0
- package/CHANGELOG.md +139 -0
- package/LICENSE +15 -0
- package/README.md +193 -2
- package/index.cjs +1370 -0
- package/package.json +74 -4
- package/schema/passport-v1.schema.json +204 -0
- package/source/components/accordion/README.md +45 -0
- package/source/components/accordion/core/index.ts +2 -0
- package/source/components/accordion/core/open.ts +56 -0
- package/source/components/accordion/core/types.ts +17 -0
- package/source/components/accordion/index.ts +8 -0
- package/source/components/accordion/passport.json +259 -0
- package/source/components/accordion/react/Accordion.tsx +133 -0
- package/source/components/accordion/react/AccordionItem.tsx +120 -0
- package/source/components/accordion/react/context.ts +20 -0
- package/source/components/accordion/react/props.ts +13 -0
- package/source/components/accordion/styles.css +207 -0
- package/source/components/alert/README.md +39 -0
- package/source/components/alert/core/index.ts +2 -0
- package/source/components/alert/core/live.ts +25 -0
- package/source/components/alert/core/types.ts +7 -0
- package/source/components/alert/index.ts +5 -0
- package/source/components/alert/passport.json +250 -0
- package/source/components/alert/react/Alert.tsx +113 -0
- package/source/components/alert/react/icons.tsx +21 -0
- package/source/components/alert/react/locale.ts +5 -0
- package/source/components/alert/react/props.ts +11 -0
- package/source/components/alert/styles.css +154 -0
- package/source/components/avatar/core/identity.ts +103 -0
- package/source/components/avatar/core/index.ts +2 -0
- package/source/components/avatar/core/types.ts +12 -0
- package/source/components/avatar/index.ts +7 -0
- package/source/components/avatar/passport.json +294 -0
- package/source/components/avatar/react/Avatar.tsx +118 -0
- package/source/components/avatar/react/AvatarGroup.tsx +74 -0
- package/source/components/avatar/react/locale.ts +11 -0
- package/source/components/avatar/react/props.ts +6 -0
- package/source/components/avatar/styles.css +225 -0
- package/source/components/badge/README.md +37 -0
- package/source/components/badge/core/count.ts +37 -0
- package/source/components/badge/core/index.ts +2 -0
- package/source/components/badge/core/types.ts +11 -0
- package/source/components/badge/index.ts +7 -0
- package/source/components/badge/passport.json +332 -0
- package/source/components/badge/react/Badge.tsx +89 -0
- package/source/components/badge/react/Tag.tsx +82 -0
- package/source/components/badge/react/locale.ts +5 -0
- package/source/components/badge/react/props.ts +6 -0
- package/source/components/badge/styles.css +203 -0
- package/source/components/breadcrumb/README.md +34 -0
- package/source/components/breadcrumb/core/index.ts +4 -0
- package/source/components/breadcrumb/core/trail.ts +42 -0
- package/source/components/breadcrumb/core/types.ts +20 -0
- package/source/components/breadcrumb/index.ts +5 -0
- package/source/components/breadcrumb/passport.json +243 -0
- package/source/components/breadcrumb/react/Breadcrumb.tsx +177 -0
- package/source/components/breadcrumb/react/locale.ts +6 -0
- package/source/components/breadcrumb/react/props.ts +14 -0
- package/source/components/breadcrumb/styles.css +138 -0
- package/source/components/button/README.md +32 -0
- package/source/components/button/core/index.ts +3 -0
- package/source/components/button/core/state.ts +16 -0
- package/source/components/button/core/types.ts +28 -0
- package/source/components/button/index.ts +5 -0
- package/source/components/button/passport.json +402 -0
- package/source/components/button/passport.manual.json +31 -0
- package/source/components/button/react/Button.tsx +173 -0
- package/source/components/button/react/locale.ts +5 -0
- package/source/components/button/react/props.ts +23 -0
- package/source/components/button/styles.css +232 -0
- package/source/components/card/README.md +60 -0
- package/source/components/card/core/index.ts +4 -0
- package/source/components/card/core/trend.ts +32 -0
- package/source/components/card/core/types.ts +5 -0
- package/source/components/card/index.ts +5 -0
- package/source/components/card/passport.json +337 -0
- package/source/components/card/react/Card.tsx +133 -0
- package/source/components/card/react/Stat.tsx +127 -0
- package/source/components/card/react/props.ts +4 -0
- package/source/components/card/styles.css +230 -0
- package/source/components/checkbox/README.md +36 -0
- package/source/components/checkbox/core/group.ts +30 -0
- package/source/components/checkbox/core/index.ts +3 -0
- package/source/components/checkbox/core/types.ts +17 -0
- package/source/components/checkbox/index.ts +9 -0
- package/source/components/checkbox/passport.json +456 -0
- package/source/components/checkbox/react/Checkbox.tsx +147 -0
- package/source/components/checkbox/react/CheckboxGroup.tsx +149 -0
- package/source/components/checkbox/react/context.ts +16 -0
- package/source/components/checkbox/react/locale.ts +5 -0
- package/source/components/checkbox/react/props.ts +6 -0
- package/source/components/checkbox/styles.css +211 -0
- package/source/components/combobox/README.md +170 -0
- package/source/components/combobox/core/filter.ts +155 -0
- package/source/components/combobox/core/index.ts +16 -0
- package/source/components/combobox/core/types.ts +48 -0
- package/source/components/combobox/core/virtual.ts +67 -0
- package/source/components/combobox/index.ts +13 -0
- package/source/components/combobox/passport.json +456 -0
- package/source/components/combobox/react/Listbox.tsx +310 -0
- package/source/components/combobox/react/MultiSelect.tsx +265 -0
- package/source/components/combobox/react/Popover.tsx +38 -0
- package/source/components/combobox/react/Select.tsx +200 -0
- package/source/components/combobox/react/icons.tsx +11 -0
- package/source/components/combobox/react/locale.ts +16 -0
- package/source/components/combobox/react/props.ts +88 -0
- package/source/components/combobox/react/useCombobox.ts +409 -0
- package/source/components/combobox/styles.css +419 -0
- package/source/components/data-grid/README.md +233 -0
- package/source/components/data-grid/agent/coerce.ts +368 -0
- package/source/components/data-grid/agent/contract.ts +410 -0
- package/source/components/data-grid/agent/dataset.ts +92 -0
- package/source/components/data-grid/agent/engine.ts +470 -0
- package/source/components/data-grid/agent/executors.ts +155 -0
- package/source/components/data-grid/agent/index.ts +79 -0
- package/source/components/data-grid/agent/intent.ts +324 -0
- package/source/components/data-grid/agent/operations.ts +335 -0
- package/source/components/data-grid/agent/validate.ts +630 -0
- package/source/components/data-grid/agent/webmcp.ts +107 -0
- package/source/components/data-grid/core/columnHelper.ts +21 -0
- package/source/components/data-grid/core/columns.ts +288 -0
- package/source/components/data-grid/core/filtering.ts +237 -0
- package/source/components/data-grid/core/grid.ts +638 -0
- package/source/components/data-grid/core/index.ts +14 -0
- package/source/components/data-grid/core/rows.ts +64 -0
- package/source/components/data-grid/core/sorting.ts +133 -0
- package/source/components/data-grid/core/state.ts +82 -0
- package/source/components/data-grid/core/store.ts +52 -0
- package/source/components/data-grid/core/types.ts +302 -0
- package/source/components/data-grid/core/values.ts +98 -0
- package/source/components/data-grid/core/virtual.ts +85 -0
- package/source/components/data-grid/export/csv.ts +32 -0
- package/source/components/data-grid/export/download.ts +12 -0
- package/source/components/data-grid/export/pdf-font.ts +139 -0
- package/source/components/data-grid/export/pdf-writer.ts +113 -0
- package/source/components/data-grid/export/pdf.ts +379 -0
- package/source/components/data-grid/export/table.ts +73 -0
- package/source/components/data-grid/export/xlsx.ts +145 -0
- package/source/components/data-grid/export/zip.ts +87 -0
- package/source/components/data-grid/index.ts +14 -0
- package/source/components/data-grid/passport.json +1051 -0
- package/source/components/data-grid/passport.manual.json +255 -0
- package/source/components/data-grid/react/AskGrid.tsx +164 -0
- package/source/components/data-grid/react/Cell.tsx +282 -0
- package/source/components/data-grid/react/ColumnMenu.tsx +135 -0
- package/source/components/data-grid/react/DataGrid.tsx +335 -0
- package/source/components/data-grid/react/FilterForm.tsx +142 -0
- package/source/components/data-grid/react/HeaderRow.tsx +332 -0
- package/source/components/data-grid/react/Pagination.tsx +107 -0
- package/source/components/data-grid/react/Popover.tsx +35 -0
- package/source/components/data-grid/react/Row.tsx +85 -0
- package/source/components/data-grid/react/Toolbar.tsx +267 -0
- package/source/components/data-grid/react/Viewport.tsx +167 -0
- package/source/components/data-grid/react/context.ts +57 -0
- package/source/components/data-grid/react/hooks.ts +83 -0
- package/source/components/data-grid/react/icons.tsx +45 -0
- package/source/components/data-grid/react/keyboard.ts +110 -0
- package/source/components/data-grid/react/locale.ts +130 -0
- package/source/components/data-grid/styles.css +874 -0
- package/source/components/date-picker/README.md +141 -0
- package/source/components/date-picker/core/calendar.ts +266 -0
- package/source/components/date-picker/core/format.ts +170 -0
- package/source/components/date-picker/core/index.ts +41 -0
- package/source/components/date-picker/core/today.ts +72 -0
- package/source/components/date-picker/core/types.ts +68 -0
- package/source/components/date-picker/index.ts +16 -0
- package/source/components/date-picker/passport.json +407 -0
- package/source/components/date-picker/react/Calendar.tsx +160 -0
- package/source/components/date-picker/react/CalendarPanel.tsx +170 -0
- package/source/components/date-picker/react/DatePicker.tsx +249 -0
- package/source/components/date-picker/react/DateRangePicker.tsx +291 -0
- package/source/components/date-picker/react/MonthYearPanels.tsx +123 -0
- package/source/components/date-picker/react/Popover.tsx +45 -0
- package/source/components/date-picker/react/icons.tsx +15 -0
- package/source/components/date-picker/react/locale.ts +23 -0
- package/source/components/date-picker/react/props.ts +76 -0
- package/source/components/date-picker/react/useDatePicker.ts +557 -0
- package/source/components/date-picker/styles.css +445 -0
- package/source/components/dialog/README.md +39 -0
- package/source/components/dialog/core/api.ts +34 -0
- package/source/components/dialog/core/dialog.ts +11 -0
- package/source/components/dialog/core/index.ts +7 -0
- package/source/components/dialog/core/store.ts +81 -0
- package/source/components/dialog/core/types.ts +59 -0
- package/source/components/dialog/index.ts +7 -0
- package/source/components/dialog/passport.json +344 -0
- package/source/components/dialog/react/Dialog.tsx +279 -0
- package/source/components/dialog/react/DialogHost.tsx +45 -0
- package/source/components/dialog/react/icons.tsx +20 -0
- package/source/components/dialog/react/locale.ts +8 -0
- package/source/components/dialog/react/props.ts +13 -0
- package/source/components/dialog/styles.css +280 -0
- package/source/components/file-uploader/README.md +99 -0
- package/source/components/file-uploader/core/format.ts +79 -0
- package/source/components/file-uploader/core/index.ts +26 -0
- package/source/components/file-uploader/core/store.ts +432 -0
- package/source/components/file-uploader/core/transport.ts +154 -0
- package/source/components/file-uploader/core/types.ts +126 -0
- package/source/components/file-uploader/core/validate.ts +83 -0
- package/source/components/file-uploader/index.ts +7 -0
- package/source/components/file-uploader/passport.json +518 -0
- package/source/components/file-uploader/react/FileRow.tsx +268 -0
- package/source/components/file-uploader/react/FileUploader.tsx +511 -0
- package/source/components/file-uploader/react/icons.tsx +60 -0
- package/source/components/file-uploader/react/locale.ts +33 -0
- package/source/components/file-uploader/react/props.ts +31 -0
- package/source/components/file-uploader/react/useFileUploader.ts +32 -0
- package/source/components/file-uploader/styles.css +394 -0
- package/source/components/input/README.md +44 -0
- package/source/components/input/core/count.ts +5 -0
- package/source/components/input/core/index.ts +11 -0
- package/source/components/input/core/otp.ts +64 -0
- package/source/components/input/core/types.ts +14 -0
- package/source/components/input/index.ts +8 -0
- package/source/components/input/passport.json +536 -0
- package/source/components/input/react/Input.tsx +219 -0
- package/source/components/input/react/OtpInput.tsx +256 -0
- package/source/components/input/react/dom.ts +10 -0
- package/source/components/input/react/icons.tsx +17 -0
- package/source/components/input/react/locale.ts +9 -0
- package/source/components/input/react/props.ts +6 -0
- package/source/components/input/styles.css +295 -0
- package/source/components/menu/README.md +68 -0
- package/source/components/menu/core/index.ts +11 -0
- package/source/components/menu/core/navigation.ts +84 -0
- package/source/components/menu/core/types.ts +32 -0
- package/source/components/menu/index.ts +19 -0
- package/source/components/menu/passport.json +322 -0
- package/source/components/menu/react/Menu.tsx +371 -0
- package/source/components/menu/react/context.ts +31 -0
- package/source/components/menu/react/items.tsx +268 -0
- package/source/components/menu/react/locale.ts +6 -0
- package/source/components/menu/react/props.ts +4 -0
- package/source/components/menu/react/useMenuKeys.ts +124 -0
- package/source/components/menu/styles.css +224 -0
- package/source/components/modal/README.md +51 -0
- package/source/components/modal/core/dismiss.ts +29 -0
- package/source/components/modal/core/index.ts +3 -0
- package/source/components/modal/core/types.ts +27 -0
- package/source/components/modal/index.ts +5 -0
- package/source/components/modal/passport.json +289 -0
- package/source/components/modal/react/Modal.tsx +242 -0
- package/source/components/modal/react/icons.tsx +1 -0
- package/source/components/modal/react/locale.ts +5 -0
- package/source/components/modal/react/props.ts +17 -0
- package/source/components/modal/styles.css +241 -0
- package/source/components/number-input/README.md +53 -0
- package/source/components/number-input/core/format.ts +37 -0
- package/source/components/number-input/core/index.ts +4 -0
- package/source/components/number-input/core/parse.ts +118 -0
- package/source/components/number-input/core/step.ts +73 -0
- package/source/components/number-input/core/types.ts +32 -0
- package/source/components/number-input/index.ts +5 -0
- package/source/components/number-input/passport.json +541 -0
- package/source/components/number-input/react/NumberInput.tsx +465 -0
- package/source/components/number-input/react/icons.tsx +17 -0
- package/source/components/number-input/react/locale.ts +7 -0
- package/source/components/number-input/react/props.ts +11 -0
- package/source/components/number-input/styles.css +230 -0
- package/source/components/popover/README.md +44 -0
- package/source/components/popover/core/index.ts +2 -0
- package/source/components/popover/core/types.ts +12 -0
- package/source/components/popover/index.ts +4 -0
- package/source/components/popover/passport.json +238 -0
- package/source/components/popover/react/Popover.tsx +202 -0
- package/source/components/popover/react/locale.ts +5 -0
- package/source/components/popover/react/props.ts +4 -0
- package/source/components/popover/styles.css +148 -0
- package/source/components/progress/README.md +38 -0
- package/source/components/progress/core/index.ts +2 -0
- package/source/components/progress/core/progress.ts +40 -0
- package/source/components/progress/core/types.ts +23 -0
- package/source/components/progress/index.ts +7 -0
- package/source/components/progress/passport.json +270 -0
- package/source/components/progress/react/CircularProgress.tsx +106 -0
- package/source/components/progress/react/Progress.tsx +113 -0
- package/source/components/progress/react/locale.ts +7 -0
- package/source/components/progress/react/props.ts +6 -0
- package/source/components/progress/styles.css +200 -0
- package/source/components/radio-group/README.md +58 -0
- package/source/components/radio-group/core/group.ts +36 -0
- package/source/components/radio-group/core/index.ts +2 -0
- package/source/components/radio-group/core/types.ts +20 -0
- package/source/components/radio-group/index.ts +9 -0
- package/source/components/radio-group/passport.json +477 -0
- package/source/components/radio-group/react/Radio.tsx +144 -0
- package/source/components/radio-group/react/RadioGroup.tsx +179 -0
- package/source/components/radio-group/react/context.ts +18 -0
- package/source/components/radio-group/react/locale.ts +5 -0
- package/source/components/radio-group/react/props.ts +12 -0
- package/source/components/radio-group/styles.css +269 -0
- package/source/components/shared/README.md +54 -0
- package/source/components/shared/core/agent/adapter.ts +65 -0
- package/source/components/shared/core/agent/history.ts +120 -0
- package/source/components/shared/core/agent/index.ts +46 -0
- package/source/components/shared/core/agent/numbers.ts +217 -0
- package/source/components/shared/core/agent/schema.ts +180 -0
- package/source/components/shared/core/agent/types.ts +169 -0
- package/source/components/shared/core/agent/webmcp.ts +328 -0
- package/source/components/shared/core/cx.ts +9 -0
- package/source/components/shared/core/field.ts +35 -0
- package/source/components/shared/core/position.ts +124 -0
- package/source/components/shared/core/text.ts +14 -0
- package/source/components/shared/index.ts +17 -0
- package/source/components/shared/react/GramproAIProvider.tsx +50 -0
- package/source/components/shared/react/Popover.tsx +189 -0
- package/source/components/shared/react/icons.tsx +74 -0
- package/source/components/shared/react/useAskAgent.ts +217 -0
- package/source/components/shared/react/useControllableState.ts +42 -0
- package/source/components/shared/styles.css +79 -0
- package/source/components/shared/version.json +4 -0
- package/source/components/shared/version.ts +6 -0
- package/source/components/skeleton/README.md +58 -0
- package/source/components/skeleton/core/index.ts +3 -0
- package/source/components/skeleton/core/lines.ts +25 -0
- package/source/components/skeleton/core/types.ts +5 -0
- package/source/components/skeleton/index.ts +5 -0
- package/source/components/skeleton/passport.json +251 -0
- package/source/components/skeleton/react/Empty.tsx +51 -0
- package/source/components/skeleton/react/Skeleton.tsx +92 -0
- package/source/components/skeleton/react/props.ts +4 -0
- package/source/components/skeleton/styles.css +185 -0
- package/source/components/spinner/README.md +29 -0
- package/source/components/spinner/core/index.ts +3 -0
- package/source/components/spinner/core/types.ts +28 -0
- package/source/components/spinner/core/visibility.ts +34 -0
- package/source/components/spinner/index.ts +6 -0
- package/source/components/spinner/passport.json +245 -0
- package/source/components/spinner/react/Spinner.tsx +96 -0
- package/source/components/spinner/react/locale.ts +5 -0
- package/source/components/spinner/react/props.ts +4 -0
- package/source/components/spinner/react/useDelayedLoading.ts +39 -0
- package/source/components/spinner/styles.css +173 -0
- package/source/components/switch/README.md +46 -0
- package/source/components/switch/core/index.ts +2 -0
- package/source/components/switch/core/toggle.ts +54 -0
- package/source/components/switch/core/types.ts +9 -0
- package/source/components/switch/index.ts +5 -0
- package/source/components/switch/passport.json +421 -0
- package/source/components/switch/react/Switch.tsx +219 -0
- package/source/components/switch/react/locale.ts +5 -0
- package/source/components/switch/react/props.ts +12 -0
- package/source/components/switch/styles.css +227 -0
- package/source/components/tabs/README.md +32 -0
- package/source/components/tabs/core/index.ts +3 -0
- package/source/components/tabs/core/navigation.ts +54 -0
- package/source/components/tabs/core/types.ts +16 -0
- package/source/components/tabs/index.ts +5 -0
- package/source/components/tabs/passport.json +315 -0
- package/source/components/tabs/react/Tabs.tsx +306 -0
- package/source/components/tabs/react/context.ts +21 -0
- package/source/components/tabs/styles.css +263 -0
- package/source/components/textarea/README.md +39 -0
- package/source/components/textarea/core/count.ts +5 -0
- package/source/components/textarea/core/index.ts +4 -0
- package/source/components/textarea/core/size.ts +23 -0
- package/source/components/textarea/core/types.ts +17 -0
- package/source/components/textarea/index.ts +5 -0
- package/source/components/textarea/passport.json +382 -0
- package/source/components/textarea/react/Textarea.tsx +208 -0
- package/source/components/textarea/react/locale.ts +5 -0
- package/source/components/textarea/react/props.ts +4 -0
- package/source/components/textarea/styles.css +158 -0
- package/source/components/toaster/README.md +128 -0
- package/source/components/toaster/core/api.ts +87 -0
- package/source/components/toaster/core/index.ts +14 -0
- package/source/components/toaster/core/store.ts +211 -0
- package/source/components/toaster/core/toast.ts +12 -0
- package/source/components/toaster/core/types.ts +78 -0
- package/source/components/toaster/index.ts +6 -0
- package/source/components/toaster/passport.json +221 -0
- package/source/components/toaster/react/ToastItem.tsx +164 -0
- package/source/components/toaster/react/Toaster.tsx +187 -0
- package/source/components/toaster/react/icons.tsx +23 -0
- package/source/components/toaster/react/locale.ts +6 -0
- package/source/components/toaster/react/props.ts +15 -0
- package/source/components/toaster/react/useToasts.ts +11 -0
- package/source/components/toaster/styles.css +282 -0
- package/source/components/tooltip/README.md +43 -0
- package/source/components/tooltip/core/index.ts +4 -0
- package/source/components/tooltip/core/types.ts +4 -0
- package/source/components/tooltip/core/visibility.ts +34 -0
- package/source/components/tooltip/index.ts +3 -0
- package/source/components/tooltip/passport.json +170 -0
- package/source/components/tooltip/react/Tooltip.tsx +196 -0
- package/source/components/tooltip/react/props.ts +4 -0
- package/source/components/tooltip/styles.css +71 -0
- package/source/fallback/index.tsx +11 -0
- package/source/globalStyle.ts +74 -0
- package/source/hooks/SelectionHooks/type.ts +4 -0
- package/source/hooks/SelectionHooks/useClickOutside.ts +22 -0
- package/source/hooks/SelectionHooks/useMultiSelectState.ts +64 -0
- package/source/hooks/SelectionHooks/useSelectData.ts +58 -0
- package/source/hooks/SelectionHooks/useSelectState.ts +36 -0
- package/source/icon/Icon.tsx +102 -0
- package/source/icon/iconPaths.ts +206 -0
- package/source/legacy-components/bargraph/index.tsx +95 -0
- package/source/legacy-components/bargraph/type.ts +12 -0
- package/source/legacy-components/breadcrumb/index.tsx +66 -0
- package/source/legacy-components/breadcrumb/types.ts +10 -0
- package/source/legacy-components/button/index.tsx +42 -0
- package/source/legacy-components/card/index.tsx +31 -0
- package/source/legacy-components/checkbox/index.tsx +25 -0
- package/source/legacy-components/contextmenu/ContextMenu.tsx +87 -0
- package/source/legacy-components/contextmenu/ContextMenuItem.tsx +30 -0
- package/source/legacy-components/contextmenu/index.ts +2 -0
- package/source/legacy-components/contextmenu/types.ts +19 -0
- package/source/legacy-components/darkmode/index.tsx +55 -0
- package/source/legacy-components/datagrid/context/GridContext.tsx +215 -0
- package/source/legacy-components/datagrid/createTemplate.tsx +82 -0
- package/source/legacy-components/datagrid/hooks/index.ts +6 -0
- package/source/legacy-components/datagrid/hooks/useColumns.ts +33 -0
- package/source/legacy-components/datagrid/hooks/useDataSource.ts +54 -0
- package/source/legacy-components/datagrid/hooks/useFiltering.ts +169 -0
- package/source/legacy-components/datagrid/hooks/usePagination.ts +112 -0
- package/source/legacy-components/datagrid/hooks/useRowSelection.ts +48 -0
- package/source/legacy-components/datagrid/hooks/useSearch.ts +90 -0
- package/source/legacy-components/datagrid/index.tsx +28 -0
- package/source/legacy-components/datagrid/layout/FilterPopup.tsx +92 -0
- package/source/legacy-components/datagrid/layout/GridBody.tsx +184 -0
- package/source/legacy-components/datagrid/layout/GridPagination.tsx +119 -0
- package/source/legacy-components/datagrid/layout/GridToolbar.tsx +109 -0
- package/source/legacy-components/datagrid/layout/index.tsx +68 -0
- package/source/legacy-components/datagrid/type.ts +198 -0
- package/source/legacy-components/datepicker/index.tsx +365 -0
- package/source/legacy-components/datepicker/types.ts +12 -0
- package/source/legacy-components/dialog/index.tsx +44 -0
- package/source/legacy-components/dialog/types.ts +12 -0
- package/source/legacy-components/formrenderer/componentHandles/CheckBoxHandles.tsx +80 -0
- package/source/legacy-components/formrenderer/componentHandles/DatePickerHandles.tsx +93 -0
- package/source/legacy-components/formrenderer/componentHandles/InputHandles.tsx +106 -0
- package/source/legacy-components/formrenderer/componentHandles/MultiHandles.tsx +93 -0
- package/source/legacy-components/formrenderer/componentHandles/SelectHandles.tsx +95 -0
- package/source/legacy-components/formrenderer/helperFunctions.ts +72 -0
- package/source/legacy-components/formrenderer/index.tsx +93 -0
- package/source/legacy-components/formrenderer/types.ts +127 -0
- package/source/legacy-components/input/index.tsx +142 -0
- package/source/legacy-components/input/types.ts +10 -0
- package/source/legacy-components/materialInput/index.tsx +138 -0
- package/source/legacy-components/materialInput/types.ts +16 -0
- package/source/legacy-components/modal/index.tsx +152 -0
- package/source/legacy-components/modal/types.ts +19 -0
- package/source/legacy-components/multiselect/PortalDropDown.tsx +44 -0
- package/source/legacy-components/multiselect/index.tsx +269 -0
- package/source/legacy-components/multiselect/types.ts +26 -0
- package/source/legacy-components/navbar/AuthSection.tsx +98 -0
- package/source/legacy-components/navbar/MobileToggle.tsx +31 -0
- package/source/legacy-components/navbar/NavItemComponent.tsx +119 -0
- package/source/legacy-components/navbar/SearchBar.tsx +55 -0
- package/source/legacy-components/navbar/helperFunctions.ts +27 -0
- package/source/legacy-components/navbar/index.tsx +156 -0
- package/source/legacy-components/navbar/types.ts +69 -0
- package/source/legacy-components/select/PortalDropDown.tsx +59 -0
- package/source/legacy-components/select/index.tsx +249 -0
- package/source/legacy-components/select/types.ts +29 -0
- package/source/legacy-components/sidebar/components/MenuItem.tsx +101 -0
- package/source/legacy-components/sidebar/components/MenuSection.tsx +34 -0
- package/source/legacy-components/sidebar/components/SidebarFooter.tsx +50 -0
- package/source/legacy-components/sidebar/components/SidebarLogo.tsx +24 -0
- package/source/legacy-components/sidebar/components/SidebarMenu.tsx +29 -0
- package/source/legacy-components/sidebar/components/UserProfile.tsx +31 -0
- package/source/legacy-components/sidebar/hooks/useSidebarState.ts +41 -0
- package/source/legacy-components/sidebar/index.tsx +77 -0
- package/source/legacy-components/sidebar/type.ts +42 -0
- package/source/legacy-components/spinner/Stroke.tsx +89 -0
- package/source/legacy-components/spinner/index.tsx +54 -0
- package/source/legacy-components/spinner/types.ts +9 -0
- package/source/legacy-components/tabs/index.tsx +71 -0
- package/source/legacy-components/tabs/types.ts +16 -0
- package/source/legacy-components/textarea/index.tsx +123 -0
- package/source/legacy-components/textarea/types.ts +15 -0
- package/source/legacy-components/toast/ToastComponent.tsx +101 -0
- package/source/legacy-components/toast/ToastIcon.tsx +61 -0
- package/source/legacy-components/toast/index.tsx +42 -0
- package/source/legacy-components/toast/toastStore.ts +42 -0
- package/source/legacy-components/toast/types.ts +18 -0
- package/source/legacy-components/toast/useToast.ts +12 -0
- package/source/legacy-components/uploader/ProgressAnimation.tsx +50 -0
- package/source/legacy-components/uploader/UploadedFilePreview.tsx +130 -0
- package/source/legacy-components/uploader/index.tsx +311 -0
- package/source/legacy-components/uploader/types.ts +30 -0
- package/source/legacy-components/uploader/uploaderIcon.tsx +72 -0
- package/source/legacy-components/uploader/uploaderService.ts +134 -0
- package/source/legacy-components/useUploader/useUploader.tsx +310 -0
- package/source/legacy-components/usepaginateddata/usePaginatedData.ts +174 -0
- package/source/theme.ts +40 -0
- package/source/utils.ts +10 -0
- package/tools/env.cjs +61 -0
- package/tools/passport/cli.cjs +79 -0
- package/tools/passport/extract.cjs +493 -0
- package/tools/passport/index.cjs +185 -0
- package/tools/passport/merge.cjs +131 -0
- package/tools/passport/policy.cjs +65 -0
- package/tools/passport/validate.cjs +277 -0
- package/tools/ts-require.cjs +79 -0
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
useEffect,
|
|
5
|
+
useId,
|
|
6
|
+
useImperativeHandle,
|
|
7
|
+
useMemo,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
type ClipboardEvent,
|
|
11
|
+
type CSSProperties,
|
|
12
|
+
type DragEvent,
|
|
13
|
+
type ReactNode,
|
|
14
|
+
type Ref,
|
|
15
|
+
} from "react";
|
|
16
|
+
import { describeField } from "../../shared/core/field";
|
|
17
|
+
import { formatBytes, readFileId } from "../core/format";
|
|
18
|
+
import { summarize } from "../core/store";
|
|
19
|
+
import { createHttpTransport, type HttpTransportOptions } from "../core/transport";
|
|
20
|
+
import type {
|
|
21
|
+
ExistingFile,
|
|
22
|
+
FileRejection,
|
|
23
|
+
Transport,
|
|
24
|
+
UploaderLocaleText,
|
|
25
|
+
UploaderSize,
|
|
26
|
+
UploadItem,
|
|
27
|
+
} from "../core/types";
|
|
28
|
+
import { ExistingFileRow, FileRow } from "./FileRow";
|
|
29
|
+
import { AlertIcon, UploadIcon, XIcon } from "./icons";
|
|
30
|
+
import { defaultUploaderText } from "./locale";
|
|
31
|
+
import { cx, type FileUploaderHandle, type UploaderSlot } from "./props";
|
|
32
|
+
import { useFileUploader } from "./useFileUploader";
|
|
33
|
+
|
|
34
|
+
export interface FileUploaderProps {
|
|
35
|
+
/* ----------------------------------------------------------- selection */
|
|
36
|
+
/** Several files. When false, a new file replaces the current one. Default false. */
|
|
37
|
+
multiple?: boolean;
|
|
38
|
+
/** Same syntax as `<input accept>`: `.pdf`, `image/*`, `application/json`. */
|
|
39
|
+
accept?: string;
|
|
40
|
+
/** Total files, counting ones already selected. */
|
|
41
|
+
maxFiles?: number;
|
|
42
|
+
/** Bytes per file. */
|
|
43
|
+
maxSize?: number;
|
|
44
|
+
/** Bytes per file. */
|
|
45
|
+
minSize?: number;
|
|
46
|
+
/** Return a message to reject a file. */
|
|
47
|
+
validate?(file: File): string | null | undefined;
|
|
48
|
+
allowDuplicates?: boolean;
|
|
49
|
+
|
|
50
|
+
/* ------------------------------------------------------------- upload */
|
|
51
|
+
/** Where chunks are POSTed. Without `endpoint` or `transport`, files are only selected. */
|
|
52
|
+
endpoint?: HttpTransportOptions["endpoint"];
|
|
53
|
+
method?: HttpTransportOptions["method"];
|
|
54
|
+
headers?: HttpTransportOptions["headers"];
|
|
55
|
+
withCredentials?: boolean;
|
|
56
|
+
/** Extra data sent as JSON with every chunk. */
|
|
57
|
+
params?: HttpTransportOptions["params"];
|
|
58
|
+
fieldNames?: HttpTransportOptions["fieldNames"];
|
|
59
|
+
parseResponse?: HttpTransportOptions["parseResponse"];
|
|
60
|
+
/** Replaces the built-in HTTP transport, e.g. for presigned URLs or an SDK. */
|
|
61
|
+
transport?: Transport;
|
|
62
|
+
/** Bytes per request. Default 5 MiB. */
|
|
63
|
+
chunkSize?: number;
|
|
64
|
+
/** Files uploading at once. Default 3. */
|
|
65
|
+
concurrency?: number;
|
|
66
|
+
/** Extra attempts per chunk. Default 3. */
|
|
67
|
+
retries?: number;
|
|
68
|
+
/** First retry delay in ms, doubled each time. Default 1000. */
|
|
69
|
+
retryDelay?: number;
|
|
70
|
+
/** Upload as soon as files are added. Default false. */
|
|
71
|
+
autoUpload?: boolean;
|
|
72
|
+
/** The value posted for an uploaded file. Default: the id found in the server's response. */
|
|
73
|
+
getFileId?(item: UploadItem): string | undefined;
|
|
74
|
+
|
|
75
|
+
/* ------------------------------------------------------ display & form */
|
|
76
|
+
/** Thumbnails for images. Default true. */
|
|
77
|
+
preview?: boolean;
|
|
78
|
+
/** Files already stored, shown above new ones. */
|
|
79
|
+
existingFiles?: readonly ExistingFile[];
|
|
80
|
+
onRemoveExisting?(file: ExistingFile): void;
|
|
81
|
+
/** Show remove buttons. Default true. */
|
|
82
|
+
removable?: boolean;
|
|
83
|
+
label?: ReactNode;
|
|
84
|
+
description?: ReactNode;
|
|
85
|
+
/** Message below the drop zone; also marks it invalid. */
|
|
86
|
+
error?: ReactNode;
|
|
87
|
+
required?: boolean;
|
|
88
|
+
disabled?: boolean;
|
|
89
|
+
size?: UploaderSize;
|
|
90
|
+
/**
|
|
91
|
+
* Form field name. With an endpoint, the stored file ids are posted; without
|
|
92
|
+
* one, the files themselves are, so a plain form or Server Action gets them.
|
|
93
|
+
*/
|
|
94
|
+
name?: string;
|
|
95
|
+
id?: string;
|
|
96
|
+
/** For sizes and percentages. */
|
|
97
|
+
locale?: string;
|
|
98
|
+
className?: string;
|
|
99
|
+
classNames?: Partial<Record<UploaderSlot, string>>;
|
|
100
|
+
style?: CSSProperties;
|
|
101
|
+
localeText?: Partial<UploaderLocaleText>;
|
|
102
|
+
|
|
103
|
+
/* ------------------------------------------------------------- events */
|
|
104
|
+
/** Selected files changed. */
|
|
105
|
+
onChange?(files: File[]): void;
|
|
106
|
+
onRejected?(rejections: FileRejection[]): void;
|
|
107
|
+
onFileSuccess?(item: UploadItem): void;
|
|
108
|
+
onFileError?(item: UploadItem, error: unknown): void;
|
|
109
|
+
/** Every file in an upload run has stopped (uploaded, failed, paused or canceled). */
|
|
110
|
+
onUploadComplete?(items: UploadItem[]): void;
|
|
111
|
+
|
|
112
|
+
ref?: Ref<FileUploaderHandle>;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** `.pdf, image/*` → `PDF, image/*` for the hint line. */
|
|
116
|
+
const describeAccept = (accept: string) =>
|
|
117
|
+
accept
|
|
118
|
+
.split(",")
|
|
119
|
+
.map((token) => token.trim())
|
|
120
|
+
.filter(Boolean)
|
|
121
|
+
.map((token) => (token.startsWith(".") ? token.slice(1).toUpperCase() : token))
|
|
122
|
+
.join(", ");
|
|
123
|
+
|
|
124
|
+
const carriesFiles = (event: DragEvent) => Array.from(event.dataTransfer.types).includes("Files");
|
|
125
|
+
|
|
126
|
+
/** Drop, browse or paste files; upload them in resumable chunks with progress. */
|
|
127
|
+
export function FileUploader(props: FileUploaderProps) {
|
|
128
|
+
const {
|
|
129
|
+
ref,
|
|
130
|
+
multiple = false,
|
|
131
|
+
accept,
|
|
132
|
+
maxFiles,
|
|
133
|
+
maxSize,
|
|
134
|
+
minSize,
|
|
135
|
+
validate,
|
|
136
|
+
allowDuplicates,
|
|
137
|
+
endpoint,
|
|
138
|
+
method,
|
|
139
|
+
headers,
|
|
140
|
+
withCredentials,
|
|
141
|
+
params,
|
|
142
|
+
fieldNames,
|
|
143
|
+
parseResponse,
|
|
144
|
+
transport: customTransport,
|
|
145
|
+
chunkSize,
|
|
146
|
+
concurrency,
|
|
147
|
+
retries,
|
|
148
|
+
retryDelay,
|
|
149
|
+
autoUpload = false,
|
|
150
|
+
getFileId,
|
|
151
|
+
preview = true,
|
|
152
|
+
existingFiles,
|
|
153
|
+
onRemoveExisting,
|
|
154
|
+
removable = true,
|
|
155
|
+
label,
|
|
156
|
+
description,
|
|
157
|
+
error,
|
|
158
|
+
required = false,
|
|
159
|
+
disabled = false,
|
|
160
|
+
size = "md",
|
|
161
|
+
name,
|
|
162
|
+
id: idProp,
|
|
163
|
+
locale,
|
|
164
|
+
className,
|
|
165
|
+
classNames,
|
|
166
|
+
style,
|
|
167
|
+
localeText,
|
|
168
|
+
onChange,
|
|
169
|
+
onRejected,
|
|
170
|
+
onFileSuccess,
|
|
171
|
+
onFileError,
|
|
172
|
+
onUploadComplete,
|
|
173
|
+
} = props;
|
|
174
|
+
|
|
175
|
+
const reactId = useId();
|
|
176
|
+
const id = idProp ?? reactId;
|
|
177
|
+
const text = useMemo(() => ({ ...defaultUploaderText, ...localeText }), [localeText]);
|
|
178
|
+
|
|
179
|
+
const pickerRef = useRef<HTMLInputElement>(null);
|
|
180
|
+
const formFilesRef = useRef<HTMLInputElement>(null);
|
|
181
|
+
const dragDepth = useRef(0);
|
|
182
|
+
const [dragging, setDragging] = useState(false);
|
|
183
|
+
const [announcement, setAnnouncement] = useState("");
|
|
184
|
+
|
|
185
|
+
const transport = useMemo<Transport | undefined>(() => {
|
|
186
|
+
if (customTransport) return customTransport;
|
|
187
|
+
if (!endpoint) return undefined;
|
|
188
|
+
return createHttpTransport({
|
|
189
|
+
endpoint,
|
|
190
|
+
method,
|
|
191
|
+
headers,
|
|
192
|
+
withCredentials,
|
|
193
|
+
params,
|
|
194
|
+
fieldNames,
|
|
195
|
+
parseResponse,
|
|
196
|
+
});
|
|
197
|
+
}, [customTransport, endpoint, method, headers, withCredentials, params, fieldNames, parseResponse]);
|
|
198
|
+
|
|
199
|
+
const { store, items, rejections } = useFileUploader({
|
|
200
|
+
multiple,
|
|
201
|
+
accept,
|
|
202
|
+
maxFiles,
|
|
203
|
+
maxSize,
|
|
204
|
+
minSize,
|
|
205
|
+
validate,
|
|
206
|
+
allowDuplicates,
|
|
207
|
+
transport,
|
|
208
|
+
chunkSize,
|
|
209
|
+
concurrency,
|
|
210
|
+
retries,
|
|
211
|
+
retryDelay,
|
|
212
|
+
autoUpload,
|
|
213
|
+
onChange,
|
|
214
|
+
onRejected,
|
|
215
|
+
onFileSuccess(item) {
|
|
216
|
+
setAnnouncement(text.announceDone(item.file.name));
|
|
217
|
+
onFileSuccess?.(item);
|
|
218
|
+
},
|
|
219
|
+
onFileError(item, reason) {
|
|
220
|
+
setAnnouncement(text.announceFailed(item.file.name));
|
|
221
|
+
onFileError?.(item, reason);
|
|
222
|
+
},
|
|
223
|
+
onComplete: onUploadComplete,
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
const canUpload = transport !== undefined;
|
|
227
|
+
const postsFiles = Boolean(name) && !canUpload;
|
|
228
|
+
|
|
229
|
+
// Without an endpoint the files ride along with the form, in a hidden file input.
|
|
230
|
+
useEffect(() => {
|
|
231
|
+
const input = formFilesRef.current;
|
|
232
|
+
if (!input) return;
|
|
233
|
+
const transfer = new DataTransfer();
|
|
234
|
+
for (const item of items) transfer.items.add(item.file);
|
|
235
|
+
input.files = transfer.files;
|
|
236
|
+
}, [items, postsFiles]);
|
|
237
|
+
|
|
238
|
+
const open = () => {
|
|
239
|
+
if (!disabled) pickerRef.current?.click();
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
useImperativeHandle(
|
|
243
|
+
ref,
|
|
244
|
+
() => ({
|
|
245
|
+
open: () => {
|
|
246
|
+
if (!disabled) pickerRef.current?.click();
|
|
247
|
+
},
|
|
248
|
+
addFiles: (files) => store.addFiles(files),
|
|
249
|
+
upload: () => store.upload(),
|
|
250
|
+
pause: (fileId) => store.pause(fileId),
|
|
251
|
+
cancel: (fileId) => store.cancel(fileId),
|
|
252
|
+
clear: () => store.clear(),
|
|
253
|
+
getFiles: () => store.getSnapshot().items.map((item) => item.file),
|
|
254
|
+
getItems: () => store.getSnapshot().items,
|
|
255
|
+
}),
|
|
256
|
+
[store, disabled],
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
const add = (files: FileList | null | undefined) => {
|
|
260
|
+
if (disabled || !files || files.length === 0) return;
|
|
261
|
+
store.addFiles(files);
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
const onDragEnter = (event: DragEvent<HTMLDivElement>) => {
|
|
265
|
+
if (disabled || !carriesFiles(event)) return;
|
|
266
|
+
event.preventDefault();
|
|
267
|
+
dragDepth.current += 1;
|
|
268
|
+
setDragging(true);
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
const onDragOver = (event: DragEvent<HTMLDivElement>) => {
|
|
272
|
+
if (disabled || !carriesFiles(event)) return;
|
|
273
|
+
event.preventDefault();
|
|
274
|
+
event.dataTransfer.dropEffect = "copy";
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
// dragenter/leave fire for every child the pointer crosses, so count the depth.
|
|
278
|
+
const onDragLeave = () => {
|
|
279
|
+
if (!dragging) return;
|
|
280
|
+
dragDepth.current -= 1;
|
|
281
|
+
if (dragDepth.current <= 0) {
|
|
282
|
+
dragDepth.current = 0;
|
|
283
|
+
setDragging(false);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
const onDrop = (event: DragEvent<HTMLDivElement>) => {
|
|
288
|
+
if (!carriesFiles(event)) return;
|
|
289
|
+
event.preventDefault();
|
|
290
|
+
dragDepth.current = 0;
|
|
291
|
+
setDragging(false);
|
|
292
|
+
add(event.dataTransfer.files);
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const onPaste = (event: ClipboardEvent<HTMLDivElement>) => {
|
|
296
|
+
if (event.clipboardData.files.length === 0) return;
|
|
297
|
+
event.preventDefault();
|
|
298
|
+
add(event.clipboardData.files);
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
const rejectionText = (rejection: FileRejection): string => {
|
|
302
|
+
const fileName = rejection.file.name;
|
|
303
|
+
switch (rejection.code) {
|
|
304
|
+
case "file-type":
|
|
305
|
+
return text.rejectFileType(fileName);
|
|
306
|
+
case "file-too-large":
|
|
307
|
+
return text.rejectTooLarge(fileName, formatBytes(maxSize ?? 0, locale));
|
|
308
|
+
case "file-too-small":
|
|
309
|
+
return text.rejectTooSmall(fileName, formatBytes(minSize ?? 0, locale));
|
|
310
|
+
case "too-many-files":
|
|
311
|
+
return text.rejectTooMany(String(multiple ? (maxFiles ?? 1) : 1));
|
|
312
|
+
case "duplicate":
|
|
313
|
+
return text.rejectDuplicate(fileName);
|
|
314
|
+
case "custom":
|
|
315
|
+
return rejection.message ?? fileName;
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
const hints = [
|
|
320
|
+
accept ? text.hintTypes(describeAccept(accept)) : null,
|
|
321
|
+
maxSize !== undefined ? text.hintMaxSize(formatBytes(maxSize, locale)) : null,
|
|
322
|
+
multiple && maxFiles !== undefined && Number.isFinite(maxFiles)
|
|
323
|
+
? text.hintMaxFiles(String(maxFiles))
|
|
324
|
+
: null,
|
|
325
|
+
]
|
|
326
|
+
.filter(Boolean)
|
|
327
|
+
.join(" · ");
|
|
328
|
+
|
|
329
|
+
const summary = summarize(items);
|
|
330
|
+
const uploadedIds = name && canUpload
|
|
331
|
+
? items
|
|
332
|
+
.filter((item) => item.status === "success")
|
|
333
|
+
.map((item) => getFileId?.(item) ?? readFileId(item.response) ?? item.uploadId)
|
|
334
|
+
: [];
|
|
335
|
+
const hasRows = items.length > 0 || (existingFiles?.length ?? 0) > 0;
|
|
336
|
+
const showFooter = items.length > 0 && (canUpload || multiple);
|
|
337
|
+
const describedBy = describeField(id, { hint: hints, description, error });
|
|
338
|
+
|
|
339
|
+
const rowProps = { preview, removable, disabled, locale, text, classNames };
|
|
340
|
+
|
|
341
|
+
return (
|
|
342
|
+
<div
|
|
343
|
+
className={cx("fu-root", classNames?.root, className)}
|
|
344
|
+
style={style}
|
|
345
|
+
data-size={size}
|
|
346
|
+
data-disabled={disabled || undefined}
|
|
347
|
+
data-invalid={error ? "" : undefined}
|
|
348
|
+
onPaste={onPaste}
|
|
349
|
+
>
|
|
350
|
+
{label && (
|
|
351
|
+
<span
|
|
352
|
+
id={`${id}-label`}
|
|
353
|
+
className={cx("fu-label", classNames?.label)}
|
|
354
|
+
data-required={required || undefined}
|
|
355
|
+
>
|
|
356
|
+
{label}
|
|
357
|
+
</span>
|
|
358
|
+
)}
|
|
359
|
+
|
|
360
|
+
<div
|
|
361
|
+
className={cx("fu-dropzone", classNames?.dropzone)}
|
|
362
|
+
data-dragging={dragging || undefined}
|
|
363
|
+
onDragEnter={onDragEnter}
|
|
364
|
+
onDragOver={onDragOver}
|
|
365
|
+
onDragLeave={onDragLeave}
|
|
366
|
+
onDrop={onDrop}
|
|
367
|
+
>
|
|
368
|
+
<button
|
|
369
|
+
type="button"
|
|
370
|
+
id={id}
|
|
371
|
+
className="fu-trigger"
|
|
372
|
+
disabled={disabled}
|
|
373
|
+
aria-labelledby={label ? `${id}-label ${id}-cta` : undefined}
|
|
374
|
+
aria-describedby={describedBy}
|
|
375
|
+
onClick={open}
|
|
376
|
+
>
|
|
377
|
+
<UploadIcon className="fu-dropzone-icon" />
|
|
378
|
+
<span id={`${id}-cta`} className="fu-dropzone-text">
|
|
379
|
+
{dragging ? (
|
|
380
|
+
text.dropHere
|
|
381
|
+
) : (
|
|
382
|
+
<>
|
|
383
|
+
{text.dropzone} <span className="fu-browse">{text.browse}</span>
|
|
384
|
+
</>
|
|
385
|
+
)}
|
|
386
|
+
</span>
|
|
387
|
+
{hints && (
|
|
388
|
+
<span id={`${id}-hint`} className="fu-hint">
|
|
389
|
+
{hints}
|
|
390
|
+
</span>
|
|
391
|
+
)}
|
|
392
|
+
</button>
|
|
393
|
+
<input
|
|
394
|
+
ref={pickerRef}
|
|
395
|
+
type="file"
|
|
396
|
+
className="fu-sr-only"
|
|
397
|
+
tabIndex={-1}
|
|
398
|
+
aria-hidden="true"
|
|
399
|
+
multiple={multiple}
|
|
400
|
+
accept={accept}
|
|
401
|
+
disabled={disabled}
|
|
402
|
+
onChange={(event) => {
|
|
403
|
+
add(event.currentTarget.files);
|
|
404
|
+
// Let the same file be picked again after it was removed.
|
|
405
|
+
event.currentTarget.value = "";
|
|
406
|
+
}}
|
|
407
|
+
/>
|
|
408
|
+
</div>
|
|
409
|
+
|
|
410
|
+
{description && (
|
|
411
|
+
<span id={`${id}-description`} className="fu-description">
|
|
412
|
+
{description}
|
|
413
|
+
</span>
|
|
414
|
+
)}
|
|
415
|
+
{error && (
|
|
416
|
+
<span id={`${id}-error`} className="fu-error" role="alert">
|
|
417
|
+
{error}
|
|
418
|
+
</span>
|
|
419
|
+
)}
|
|
420
|
+
|
|
421
|
+
{postsFiles && <input ref={formFilesRef} type="file" name={name} multiple hidden tabIndex={-1} />}
|
|
422
|
+
{uploadedIds.map((value) => (
|
|
423
|
+
<input key={value} type="hidden" name={name} value={value} />
|
|
424
|
+
))}
|
|
425
|
+
{name &&
|
|
426
|
+
existingFiles?.map((file) => (
|
|
427
|
+
<input key={file.id} type="hidden" name={`${name}-existing`} value={file.id} />
|
|
428
|
+
))}
|
|
429
|
+
|
|
430
|
+
{rejections.length > 0 && (
|
|
431
|
+
<ul className={cx("fu-rejections", classNames?.rejections)} role="alert">
|
|
432
|
+
{rejections.map((rejection) => (
|
|
433
|
+
<li key={rejection.id} className="fu-rejection">
|
|
434
|
+
<AlertIcon />
|
|
435
|
+
<span>{rejectionText(rejection)}</span>
|
|
436
|
+
<button
|
|
437
|
+
type="button"
|
|
438
|
+
className="fu-icon-button"
|
|
439
|
+
aria-label={text.dismiss}
|
|
440
|
+
title={text.dismiss}
|
|
441
|
+
onClick={() => store.dismissRejection(rejection.id)}
|
|
442
|
+
>
|
|
443
|
+
<XIcon />
|
|
444
|
+
</button>
|
|
445
|
+
</li>
|
|
446
|
+
))}
|
|
447
|
+
</ul>
|
|
448
|
+
)}
|
|
449
|
+
|
|
450
|
+
{hasRows && (
|
|
451
|
+
<ul
|
|
452
|
+
className={cx("fu-list", classNames?.list)}
|
|
453
|
+
aria-labelledby={label ? `${id}-label` : undefined}
|
|
454
|
+
>
|
|
455
|
+
{existingFiles?.map((file) => (
|
|
456
|
+
<ExistingFileRow key={`existing-${file.id}`} file={file} onRemove={onRemoveExisting} {...rowProps} />
|
|
457
|
+
))}
|
|
458
|
+
{items.map((item) => (
|
|
459
|
+
<FileRow key={item.id} item={item} store={store} canUpload={canUpload} {...rowProps} />
|
|
460
|
+
))}
|
|
461
|
+
</ul>
|
|
462
|
+
)}
|
|
463
|
+
|
|
464
|
+
{showFooter && (
|
|
465
|
+
<div className={cx("fu-footer", classNames?.footer)}>
|
|
466
|
+
{summary.busy ? (
|
|
467
|
+
<>
|
|
468
|
+
<div
|
|
469
|
+
className="fu-progress"
|
|
470
|
+
role="progressbar"
|
|
471
|
+
aria-valuemin={0}
|
|
472
|
+
aria-valuemax={100}
|
|
473
|
+
aria-valuenow={Math.round(summary.progress * 100)}
|
|
474
|
+
aria-label={typeof label === "string" ? label : undefined}
|
|
475
|
+
>
|
|
476
|
+
<span className="fu-progress-bar" style={{ transform: `scaleX(${summary.progress})` }} />
|
|
477
|
+
</div>
|
|
478
|
+
<span className="fu-footer-text">
|
|
479
|
+
{formatBytes(summary.uploadedBytes, locale)} / {formatBytes(summary.totalBytes, locale)}
|
|
480
|
+
</span>
|
|
481
|
+
<button type="button" className="fu-button" disabled={disabled} onClick={() => store.cancel()}>
|
|
482
|
+
{text.cancelAll}
|
|
483
|
+
</button>
|
|
484
|
+
</>
|
|
485
|
+
) : (
|
|
486
|
+
<>
|
|
487
|
+
<button type="button" className="fu-button" disabled={disabled} onClick={() => store.clear()}>
|
|
488
|
+
{text.clear}
|
|
489
|
+
</button>
|
|
490
|
+
{canUpload && summary.startable > 0 && (
|
|
491
|
+
<button
|
|
492
|
+
type="button"
|
|
493
|
+
className="fu-button"
|
|
494
|
+
data-variant="primary"
|
|
495
|
+
disabled={disabled}
|
|
496
|
+
onClick={() => void store.upload()}
|
|
497
|
+
>
|
|
498
|
+
{text.upload(String(summary.startable))}
|
|
499
|
+
</button>
|
|
500
|
+
)}
|
|
501
|
+
</>
|
|
502
|
+
)}
|
|
503
|
+
</div>
|
|
504
|
+
)}
|
|
505
|
+
|
|
506
|
+
<span className="fu-sr-only" role="status">
|
|
507
|
+
{announcement}
|
|
508
|
+
</span>
|
|
509
|
+
</div>
|
|
510
|
+
);
|
|
511
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { AlertCircleIcon, XIcon as SharedX, Svg, type IconProps } from "../../shared/react/icons";
|
|
2
|
+
import type { FileKind } from "../core/types";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* The row controls are 14px, so several fit beside a file name without
|
|
6
|
+
* dominating it.
|
|
7
|
+
*/
|
|
8
|
+
export const XIcon = (p: IconProps) => <SharedX width={14} height={14} {...p} />;
|
|
9
|
+
export const AlertIcon = (p: IconProps) => <AlertCircleIcon width={14} height={14} {...p} />;
|
|
10
|
+
|
|
11
|
+
export const UploadIcon = (p: IconProps) => (
|
|
12
|
+
<Svg width={28} height={28} strokeWidth={1.75} {...p}>
|
|
13
|
+
<path d="M12 15V4M7.5 8.5 12 4l4.5 4.5" />
|
|
14
|
+
<path d="M20 15v3a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-3" />
|
|
15
|
+
</Svg>
|
|
16
|
+
);
|
|
17
|
+
export const PauseIcon = (p: IconProps) => <Svg width={14} height={14} {...p}><path d="M8 5v14M16 5v14" /></Svg>;
|
|
18
|
+
export const PlayIcon = (p: IconProps) => <Svg width={14} height={14} {...p}><path d="M7 4.5v15L19 12Z" /></Svg>;
|
|
19
|
+
export const RetryIcon = (p: IconProps) => (
|
|
20
|
+
<Svg width={14} height={14} {...p}>
|
|
21
|
+
<path d="M3 12a9 9 0 0 1 15.5-6.2L21 8" />
|
|
22
|
+
<path d="M21 3v5h-5M21 12a9 9 0 0 1-15.5 6.2L3 16" />
|
|
23
|
+
<path d="M3 21v-5h5" />
|
|
24
|
+
</Svg>
|
|
25
|
+
);
|
|
26
|
+
export const DownloadIcon = (p: IconProps) => (
|
|
27
|
+
<Svg width={14} height={14} {...p}>
|
|
28
|
+
<path d="M12 4v11M7.5 10.5 12 15l4.5-4.5M5 20h14" />
|
|
29
|
+
</Svg>
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const KIND_PATHS: Record<FileKind, string> = {
|
|
33
|
+
image: "M3 16l5-5 4 4 3-3 6 6M8.5 8.5h.01",
|
|
34
|
+
video: "m10 9 5 3-5 3Z",
|
|
35
|
+
audio: "M9 18V6l10-2v12M9 18a2 2 0 1 1-4 0 2 2 0 0 1 4 0Zm10-2a2 2 0 1 1-4 0 2 2 0 0 1 4 0Z",
|
|
36
|
+
pdf: "M8 13h8M8 17h5",
|
|
37
|
+
spreadsheet: "M8 12h8M8 16h8M12 12v6",
|
|
38
|
+
document: "M8 12h8M8 16h8",
|
|
39
|
+
archive: "M11 4h2M11 7h2M11 10h2M10 13h4v4h-4Z",
|
|
40
|
+
other: "",
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** A page outline with a mark for the kind of file. */
|
|
44
|
+
export function FileKindIcon({ kind, ...p }: IconProps & { kind: FileKind }) {
|
|
45
|
+
if (kind === "image" || kind === "video" || kind === "audio") {
|
|
46
|
+
return (
|
|
47
|
+
<Svg width={20} height={20} {...p}>
|
|
48
|
+
{kind === "audio" ? null : <rect x="3" y="4" width="18" height="16" rx="2" />}
|
|
49
|
+
<path d={KIND_PATHS[kind]} />
|
|
50
|
+
</Svg>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return (
|
|
54
|
+
<Svg width={20} height={20} {...p}>
|
|
55
|
+
<path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8Z" />
|
|
56
|
+
<path d="M14 3v5h5" />
|
|
57
|
+
{KIND_PATHS[kind] && <path d={KIND_PATHS[kind]} />}
|
|
58
|
+
</Svg>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { UploaderLocaleText } from "../core/types";
|
|
2
|
+
|
|
3
|
+
export const defaultUploaderText: UploaderLocaleText = {
|
|
4
|
+
dropzone: "Drag files here or",
|
|
5
|
+
browse: "browse",
|
|
6
|
+
dropHere: "Drop to add files",
|
|
7
|
+
hintTypes: (types) => types,
|
|
8
|
+
hintMaxSize: (size) => `Up to ${size} each`,
|
|
9
|
+
hintMaxFiles: (count) => `${count} files max`,
|
|
10
|
+
upload: (count) => (count === "1" ? "Upload 1 file" : `Upload ${count} files`),
|
|
11
|
+
cancelAll: "Cancel all",
|
|
12
|
+
clear: "Clear",
|
|
13
|
+
dismiss: "Dismiss",
|
|
14
|
+
remove: (name) => `Remove ${name}`,
|
|
15
|
+
cancel: (name) => `Cancel ${name}`,
|
|
16
|
+
pause: (name) => `Pause ${name}`,
|
|
17
|
+
resume: (name) => `Resume ${name}`,
|
|
18
|
+
retry: (name) => `Retry ${name}`,
|
|
19
|
+
download: (name) => `Download ${name}`,
|
|
20
|
+
queued: "Waiting",
|
|
21
|
+
paused: "Paused",
|
|
22
|
+
uploaded: "Uploaded",
|
|
23
|
+
canceled: "Canceled",
|
|
24
|
+
failed: "Failed",
|
|
25
|
+
progress: (sent, total, percent) => `${sent} of ${total} · ${percent}`,
|
|
26
|
+
rejectFileType: (name) => `${name} isn't an allowed file type`,
|
|
27
|
+
rejectTooLarge: (name, max) => `${name} is larger than ${max}`,
|
|
28
|
+
rejectTooSmall: (name, min) => `${name} is smaller than ${min}`,
|
|
29
|
+
rejectTooMany: (max) => (max === "1" ? "Only one file can be added" : `You can add up to ${max} files`),
|
|
30
|
+
rejectDuplicate: (name) => `${name} is already added`,
|
|
31
|
+
announceDone: (name) => `${name} uploaded`,
|
|
32
|
+
announceFailed: (name) => `${name} failed to upload`,
|
|
33
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AddResult } from "../core/store";
|
|
2
|
+
import type { UploadItem } from "../core/types";
|
|
3
|
+
|
|
4
|
+
export type UploaderSlot =
|
|
5
|
+
| "root"
|
|
6
|
+
| "label"
|
|
7
|
+
| "dropzone"
|
|
8
|
+
| "rejections"
|
|
9
|
+
| "list"
|
|
10
|
+
| "item"
|
|
11
|
+
| "thumb"
|
|
12
|
+
| "progress"
|
|
13
|
+
| "actions"
|
|
14
|
+
| "footer";
|
|
15
|
+
|
|
16
|
+
export interface FileUploaderHandle {
|
|
17
|
+
/** Opens the system file picker. */
|
|
18
|
+
open(): void;
|
|
19
|
+
/** Adds files from code, with the same validation as a drop. */
|
|
20
|
+
addFiles(files: Iterable<File> | ArrayLike<File>): AddResult;
|
|
21
|
+
/** Uploads every file not uploaded yet. Resolves when they have all stopped. */
|
|
22
|
+
upload(): Promise<UploadItem[]>;
|
|
23
|
+
pause(id?: string): void;
|
|
24
|
+
cancel(id?: string): void;
|
|
25
|
+
clear(): void;
|
|
26
|
+
getFiles(): File[];
|
|
27
|
+
getItems(): readonly UploadItem[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Shared with every other component, so class handling cannot drift.
|
|
31
|
+
export { cx } from "../../shared/core/cx";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState, useSyncExternalStore } from "react";
|
|
4
|
+
import { createUploaderStore, type UploaderConfig, type UploaderStore } from "../core/store";
|
|
5
|
+
import type { UploaderSnapshot } from "../core/types";
|
|
6
|
+
|
|
7
|
+
export interface UseFileUploaderResult extends UploaderSnapshot {
|
|
8
|
+
store: UploaderStore;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* An upload store that lives as long as the component, always using the latest
|
|
13
|
+
* config and callbacks. Exported for building a different UI on the same engine.
|
|
14
|
+
*/
|
|
15
|
+
export function useFileUploader(config: UploaderConfig = {}): UseFileUploaderResult {
|
|
16
|
+
const [store] = useState(() => createUploaderStore(config));
|
|
17
|
+
|
|
18
|
+
// No dependency list on purpose: callbacks and limits stay current on every render.
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
store.configure(config);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Nothing should keep uploading for a component that is gone.
|
|
24
|
+
useEffect(() => () => store.cancel(), [store]);
|
|
25
|
+
|
|
26
|
+
const snapshot = useSyncExternalStore(
|
|
27
|
+
store.subscribe,
|
|
28
|
+
store.getSnapshot,
|
|
29
|
+
store.getServerSnapshot,
|
|
30
|
+
);
|
|
31
|
+
return { store, ...snapshot };
|
|
32
|
+
}
|