@apexhub/apex-ui-react-source 0.0.0-stage → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +97 -2
- package/bin/apex-ui-react-source.mjs +717 -0
- package/dist/files/AGENTS.md +89 -0
- package/dist/files/LICENSE +21 -0
- package/dist/files/_assets/adapt-to-page.raw.ts +3 -0
- package/dist/files/_assets/adapt-to-page.url.ts +3 -0
- package/dist/files/_assets/calendar.raw.ts +3 -0
- package/dist/files/_assets/doc-format.raw.ts +3 -0
- package/dist/files/_assets/docx-format.raw.ts +3 -0
- package/dist/files/_assets/full-screen.raw.ts +3 -0
- package/dist/files/_assets/full-screen.url.ts +3 -0
- package/dist/files/_assets/gif-format.raw.ts +3 -0
- package/dist/files/_assets/jpeg-format.raw.ts +3 -0
- package/dist/files/_assets/jpg-format.raw.ts +3 -0
- package/dist/files/_assets/ofd-format.raw.ts +3 -0
- package/dist/files/_assets/one-to-one.raw.ts +3 -0
- package/dist/files/_assets/one-to-one.url.ts +3 -0
- package/dist/files/_assets/pdf-format.raw.ts +3 -0
- package/dist/files/_assets/png-format.raw.ts +3 -0
- package/dist/files/_assets/rotate-left.raw.ts +3 -0
- package/dist/files/_assets/rotate-left.url.ts +3 -0
- package/dist/files/_assets/rotate-right.raw.ts +3 -0
- package/dist/files/_assets/rotate-right.url.ts +3 -0
- package/dist/files/_assets/table-empty.url.ts +3 -0
- package/dist/files/_assets/txt-format.raw.ts +3 -0
- package/dist/files/_assets/upload-file-doc-20.raw.ts +3 -0
- package/dist/files/_assets/upload-file-docx-20.raw.ts +3 -0
- package/dist/files/_assets/upload-file-gif-20.raw.ts +3 -0
- package/dist/files/_assets/upload-file-jpeg-20.raw.ts +3 -0
- package/dist/files/_assets/upload-file-jpg-20.raw.ts +3 -0
- package/dist/files/_assets/upload-file-ofd-20.raw.ts +3 -0
- package/dist/files/_assets/upload-file-pdf-20.raw.ts +3 -0
- package/dist/files/_assets/upload-file-png-20.raw.ts +3 -0
- package/dist/files/_assets/upload-file-txt-20.raw.ts +3 -0
- package/dist/files/_assets/upload-file-xlsx-20.raw.ts +3 -0
- package/dist/files/_assets/xlsx-format.raw.ts +3 -0
- package/dist/files/_assets/zoom-in.raw.ts +3 -0
- package/dist/files/_assets/zoom-in.url.ts +3 -0
- package/dist/files/_assets/zoom-out.raw.ts +3 -0
- package/dist/files/_assets/zoom-out.url.ts +3 -0
- package/dist/files/_headless/dismiss-intent.ts +1 -0
- package/dist/files/_headless/placement.ts +1 -0
- package/dist/files/_headless/use-embedded-scroll-lock-guard.ts +47 -0
- package/dist/files/_headless/use-floating-overlay.tsx +3 -0
- package/dist/files/_namespace/constants.ts +23 -0
- package/dist/files/_namespace/index.ts +1 -0
- package/dist/files/_overlay/auto-update-anchored-overlay.ts +11 -0
- package/dist/files/_overlay/collision-boundary.ts +78 -0
- package/dist/files/_overlay/dismiss-intent.ts +107 -0
- package/dist/files/_overlay/get-overlay-root.ts +157 -0
- package/dist/files/_overlay/index.ts +57 -0
- package/dist/files/_overlay/observe-anchor-lifecycle.ts +72 -0
- package/dist/files/_overlay/overlay-theme.ts +91 -0
- package/dist/files/_overlay/overlay-trigger.ts +100 -0
- package/dist/files/_overlay/overlay.css +29 -0
- package/dist/files/_overlay/placement.ts +18 -0
- package/dist/files/_overlay/resolve-portal-container.ts +13 -0
- package/dist/files/_overlay/use-anchored-overlay.tsx +493 -0
- package/dist/files/_overlay/zIndex.ts +17 -0
- package/dist/files/_tags/MaxTagList.tsx +336 -0
- package/dist/files/_tags/OverflowTagPopover.tsx +315 -0
- package/dist/files/_tags/get-max-tag-display.ts +26 -0
- package/dist/files/_tags/index.ts +15 -0
- package/dist/files/_tags/resolve-max-tag-popover.ts +28 -0
- package/dist/files/_tags/tags.css +126 -0
- package/dist/files/_tags/types.ts +46 -0
- package/dist/files/_tags/use-responsive-max-tag-count.ts +165 -0
- package/dist/files/alert/Alert.tsx +100 -0
- package/dist/files/alert/alert.css +85 -0
- package/dist/files/alert/index.ts +2 -0
- package/dist/files/alert/interface.ts +59 -0
- package/dist/files/alert/llm.txt +160 -0
- package/dist/files/alert/tokens.txt +44 -0
- package/dist/files/alert/variants.ts +17 -0
- package/dist/files/apex-env.d.ts +2 -0
- package/dist/files/apex-provider/ApexProvider.tsx +53 -0
- package/dist/files/apex-provider/apex-provider.css +0 -0
- package/dist/files/apex-provider/context.ts +17 -0
- package/dist/files/apex-provider/index.ts +18 -0
- package/dist/files/apex-provider/interface.ts +181 -0
- package/dist/files/apex-provider/llm.txt +367 -0
- package/dist/files/apex-provider/localeKind.ts +20 -0
- package/dist/files/auto-complete/AutoComplete.tsx +419 -0
- package/dist/files/auto-complete/auto-complete.css +108 -0
- package/dist/files/auto-complete/auto-complete.stories.css +17 -0
- package/dist/files/auto-complete/index.ts +8 -0
- package/dist/files/auto-complete/interface.ts +77 -0
- package/dist/files/auto-complete/llm.txt +374 -0
- package/dist/files/auto-complete/tokens.txt +77 -0
- package/dist/files/auto-complete/variants.ts +19 -0
- package/dist/files/avatar/Avatar.tsx +277 -0
- package/dist/files/avatar/avatar.css +159 -0
- package/dist/files/avatar/index.ts +2 -0
- package/dist/files/avatar/interface.ts +147 -0
- package/dist/files/avatar/llm.txt +195 -0
- package/dist/files/avatar/tokens.txt +38 -0
- package/dist/files/avatar/use-responsive-size.ts +66 -0
- package/dist/files/avatar/variants.ts +41 -0
- package/dist/files/breadcrumb/Breadcrumb.stories.css +5 -0
- package/dist/files/breadcrumb/Breadcrumb.tsx +238 -0
- package/dist/files/breadcrumb/BreadcrumbLink.tsx +63 -0
- package/dist/files/breadcrumb/BreadcrumbSeparatorIcon.tsx +30 -0
- package/dist/files/breadcrumb/breadcrumb.css +113 -0
- package/dist/files/breadcrumb/index.ts +12 -0
- package/dist/files/breadcrumb/interface.ts +81 -0
- package/dist/files/breadcrumb/llm.txt +249 -0
- package/dist/files/breadcrumb/tokens.txt +193 -0
- package/dist/files/breadcrumb/variants.ts +8 -0
- package/dist/files/button/Button.tsx +235 -0
- package/dist/files/button/button.css +261 -0
- package/dist/files/button/index.ts +2 -0
- package/dist/files/button/interface.ts +145 -0
- package/dist/files/button/llm.txt +254 -0
- package/dist/files/button/tokens.txt +470 -0
- package/dist/files/button/variants.ts +89 -0
- package/dist/files/card/Card.tsx +63 -0
- package/dist/files/card/card.css +66 -0
- package/dist/files/card/index.ts +2 -0
- package/dist/files/card/interface.ts +25 -0
- package/dist/files/card/llm.txt +93 -0
- package/dist/files/card/tokens.txt +27 -0
- package/dist/files/cascader/Cascader.tsx +955 -0
- package/dist/files/cascader/_adapter/locale.ts +4 -0
- package/dist/files/cascader/cascader-data.ts +354 -0
- package/dist/files/cascader/cascader.css +382 -0
- package/dist/files/cascader/index.ts +16 -0
- package/dist/files/cascader/interface.ts +358 -0
- package/dist/files/cascader/llm.txt +897 -0
- package/dist/files/cascader/tokens.txt +253 -0
- package/dist/files/cascader/variants.ts +35 -0
- package/dist/files/checkbox/Checkbox.tsx +477 -0
- package/dist/files/checkbox/checkbox.css +196 -0
- package/dist/files/checkbox/index.ts +9 -0
- package/dist/files/checkbox/interface.ts +162 -0
- package/dist/files/checkbox/llm.txt +326 -0
- package/dist/files/checkbox/tokens.txt +28 -0
- package/dist/files/checkbox/variants.ts +29 -0
- package/dist/files/clear/Clear.tsx +49 -0
- package/dist/files/clear/clear.css +60 -0
- package/dist/files/clear/index.ts +2 -0
- package/dist/files/clear/interface.ts +8 -0
- package/dist/files/collapse/Collapse.tsx +163 -0
- package/dist/files/collapse/collapse.css +174 -0
- package/dist/files/collapse/index.ts +2 -0
- package/dist/files/collapse/interface.ts +132 -0
- package/dist/files/collapse/llm.txt +328 -0
- package/dist/files/collapse/tokens.txt +84 -0
- package/dist/files/core/date-picker/index.ts +191 -0
- package/dist/files/core/form/index.ts +212 -0
- package/dist/files/core/index.ts +11 -0
- package/dist/files/core/input-number/index.ts +112 -0
- package/dist/files/core/namespace/index.ts +14 -0
- package/dist/files/core/overlay/index.ts +40 -0
- package/dist/files/core/pagination/index.ts +128 -0
- package/dist/files/core/table/access.ts +37 -0
- package/dist/files/core/table/columns.ts +4 -0
- package/dist/files/core/table/data-model.ts +58 -0
- package/dist/files/core/table/fixed-offset.ts +29 -0
- package/dist/files/core/table/grouped-header.ts +24 -0
- package/dist/files/core/table/index.ts +11 -0
- package/dist/files/core/table/merge.ts +132 -0
- package/dist/files/core/table/pagination.ts +51 -0
- package/dist/files/core/table/rowModel.ts +4 -0
- package/dist/files/core/table/types.ts +14 -0
- package/dist/files/core/typography/index.ts +125 -0
- package/dist/files/core/upload/file-type.ts +160 -0
- package/dist/files/core/upload/format-size.ts +17 -0
- package/dist/files/core/upload/index.ts +19 -0
- package/dist/files/core/upload/limits.ts +76 -0
- package/dist/files/core/utils/cn.ts +6 -0
- package/dist/files/core/utils/index.ts +2 -0
- package/dist/files/core/utils/svg.ts +101 -0
- package/dist/files/date-picker/DatePicker.tsx +601 -0
- package/dist/files/date-picker/RangePicker.tsx +1047 -0
- package/dist/files/date-picker/Trigger.tsx +115 -0
- package/dist/files/date-picker/_adapter/calendar.ts +136 -0
- package/dist/files/date-picker/_adapter/disable.ts +89 -0
- package/dist/files/date-picker/_adapter/format.ts +54 -0
- package/dist/files/date-picker/_adapter/keymap.ts +17 -0
- package/dist/files/date-picker/_adapter/locale.ts +4 -0
- package/dist/files/date-picker/_adapter/presets.ts +30 -0
- package/dist/files/date-picker/_adapter/range.ts +44 -0
- package/dist/files/date-picker/_adapter/types.ts +29 -0
- package/dist/files/date-picker/context.ts +60 -0
- package/dist/files/date-picker/date-picker.css +1093 -0
- package/dist/files/date-picker/index.ts +26 -0
- package/dist/files/date-picker/interface.ts +135 -0
- package/dist/files/date-picker/llm.txt +422 -0
- package/dist/files/date-picker/panels/DatePanel.tsx +110 -0
- package/dist/files/date-picker/panels/DecadePanel.tsx +49 -0
- package/dist/files/date-picker/panels/Footer.tsx +109 -0
- package/dist/files/date-picker/panels/Header.tsx +228 -0
- package/dist/files/date-picker/panels/MonthPanel.tsx +83 -0
- package/dist/files/date-picker/panels/Panel.tsx +339 -0
- package/dist/files/date-picker/panels/QuarterPanel.tsx +70 -0
- package/dist/files/date-picker/panels/TimePanel.tsx +171 -0
- package/dist/files/date-picker/panels/WeekPanel.tsx +145 -0
- package/dist/files/date-picker/panels/YearPanel.tsx +89 -0
- package/dist/files/date-picker/panels/time-panel-utils.ts +33 -0
- package/dist/files/date-picker/tokens.txt +171 -0
- package/dist/files/date-picker/variants.ts +20 -0
- package/dist/files/divider/Divider.tsx +80 -0
- package/dist/files/divider/divider.css +66 -0
- package/dist/files/divider/index.ts +7 -0
- package/dist/files/divider/interface.ts +58 -0
- package/dist/files/divider/llm.txt +158 -0
- package/dist/files/divider/tokens.txt +22 -0
- package/dist/files/drawer/Drawer.tsx +491 -0
- package/dist/files/drawer/drawer.css +201 -0
- package/dist/files/drawer/index.ts +13 -0
- package/dist/files/drawer/interface.ts +172 -0
- package/dist/files/drawer/llm.txt +374 -0
- package/dist/files/drawer/tokens.txt +71 -0
- package/dist/files/drawer/variants.ts +14 -0
- package/dist/files/dropdown/Dropdown.tsx +629 -0
- package/dist/files/dropdown/dropdown.css +243 -0
- package/dist/files/dropdown/index.ts +12 -0
- package/dist/files/dropdown/interface.ts +91 -0
- package/dist/files/dropdown/lib.ts +78 -0
- package/dist/files/dropdown/llm.txt +427 -0
- package/dist/files/dropdown/tokens.txt +59 -0
- package/dist/files/form/Form.tsx +229 -0
- package/dist/files/form/FormItem.tsx +526 -0
- package/dist/files/form/_adapter/bindField.ts +189 -0
- package/dist/files/form/_adapter/compileRules.ts +185 -0
- package/dist/files/form/_adapter/controlStatus.ts +23 -0
- package/dist/files/form/_adapter/deriveStatus.ts +42 -0
- package/dist/files/form/_adapter/instance.ts +281 -0
- package/dist/files/form/_adapter/messages.ts +15 -0
- package/dist/files/form/_adapter/types.ts +82 -0
- package/dist/files/form/_adapter/validationMeta.ts +29 -0
- package/dist/files/form/_adapter/validationTransaction.ts +69 -0
- package/dist/files/form/context.ts +38 -0
- package/dist/files/form/form.css +268 -0
- package/dist/files/form/index.ts +13 -0
- package/dist/files/form/interface.ts +99 -0
- package/dist/files/form/llm.txt +346 -0
- package/dist/files/form/tokens.txt +26 -0
- package/dist/files/form/useForm.ts +150 -0
- package/dist/files/form/utils.ts +28 -0
- package/dist/files/form/variants.ts +30 -0
- package/dist/files/global.css +8 -0
- package/dist/files/grid/Col.tsx +104 -0
- package/dist/files/grid/Grid.tsx +18 -0
- package/dist/files/grid/Row.tsx +129 -0
- package/dist/files/grid/grid.css +990 -0
- package/dist/files/grid/index.ts +12 -0
- package/dist/files/grid/interface.ts +109 -0
- package/dist/files/grid/llm.txt +419 -0
- package/dist/files/grid/useBreakpoint.ts +67 -0
- package/dist/files/icon/Icon.tsx +16 -0
- package/dist/files/icon/icon.css +26 -0
- package/dist/files/icon/icons-map.ts +1 -0
- package/dist/files/icon/index.ts +2 -0
- package/dist/files/icon/interface.ts +9 -0
- package/dist/files/icons/ActionIcons.tsx +105 -0
- package/dist/files/icons/AlertCloseIcon.tsx +21 -0
- package/dist/files/icons/CalendarIcon.tsx +6 -0
- package/dist/files/icons/CaretIcons.tsx +43 -0
- package/dist/files/icons/FileFormatIcons.tsx +27 -0
- package/dist/files/icons/Icons.tsx +10 -0
- package/dist/files/icons/MagnifyingGlassIcon.tsx +26 -0
- package/dist/files/icons/MessageIcons.tsx +111 -0
- package/dist/files/icons/NavigationIcons.tsx +126 -0
- package/dist/files/icons/PreviewIcons.tsx +18 -0
- package/dist/files/icons/StarIcons.tsx +71 -0
- package/dist/files/icons/UploadIcons.tsx +167 -0
- package/dist/files/icons/XCloseIcon.tsx +26 -0
- package/dist/files/icons/createAssetIcon.tsx +64 -0
- package/dist/files/icons/icons.css +4 -0
- package/dist/files/icons/index.ts +36 -0
- package/dist/files/icons/interface.ts +9 -0
- package/dist/files/icons/registry.ts +94 -0
- package/dist/files/image/Image.tsx +328 -0
- package/dist/files/image/ImageActionIcons.tsx +60 -0
- package/dist/files/image/ImagePreview.tsx +684 -0
- package/dist/files/image/_adapter/locale.ts +4 -0
- package/dist/files/image/image.css +451 -0
- package/dist/files/image/index.ts +7 -0
- package/dist/files/image/interface.ts +139 -0
- package/dist/files/image/llm.txt +429 -0
- package/dist/files/image/tokens.txt +28 -0
- package/dist/files/input/Input.tsx +261 -0
- package/dist/files/input/icons.tsx +3 -0
- package/dist/files/input/index.ts +12 -0
- package/dist/files/input/input-clear.stories.css +12 -0
- package/dist/files/input/input-size.ts +36 -0
- package/dist/files/input/input.css +366 -0
- package/dist/files/input/interface.ts +204 -0
- package/dist/files/input/lib.ts +51 -0
- package/dist/files/input/llm.txt +419 -0
- package/dist/files/input/tokens.txt +136 -0
- package/dist/files/input/variants.ts +17 -0
- package/dist/files/input-number/InputNumber.tsx +510 -0
- package/dist/files/input-number/icons.tsx +28 -0
- package/dist/files/input-number/index.ts +15 -0
- package/dist/files/input-number/input-number.css +440 -0
- package/dist/files/input-number/interface.ts +269 -0
- package/dist/files/input-number/lib.ts +128 -0
- package/dist/files/input-number/llm.txt +484 -0
- package/dist/files/input-number/tokens.txt +159 -0
- package/dist/files/input-number/variants.ts +27 -0
- package/dist/files/layout/Layout.tsx +360 -0
- package/dist/files/layout/index.ts +21 -0
- package/dist/files/layout/interface.ts +106 -0
- package/dist/files/layout/layout.css +278 -0
- package/dist/files/layout/llm.txt +296 -0
- package/dist/files/layout/tokens.txt +29 -0
- package/dist/files/llms-theme.txt +32 -0
- package/dist/files/llms.txt +895 -0
- package/dist/files/locale/en_US.ts +167 -0
- package/dist/files/locale/zh_CN.ts +166 -0
- package/dist/files/menu/Menu.stories.shared.tsx +85 -0
- package/dist/files/menu/Menu.tsx +713 -0
- package/dist/files/menu/demo/menu-sliding-panel.css +71 -0
- package/dist/files/menu/demo/use-sliding-panel.ts +35 -0
- package/dist/files/menu/icons.tsx +92 -0
- package/dist/files/menu/index.ts +17 -0
- package/dist/files/menu/interface.ts +229 -0
- package/dist/files/menu/lib.ts +160 -0
- package/dist/files/menu/llm.txt +686 -0
- package/dist/files/menu/menu.css +455 -0
- package/dist/files/menu/tokens.txt +87 -0
- package/dist/files/message/Message.tsx +217 -0
- package/dist/files/message/index.ts +2 -0
- package/dist/files/message/interface.ts +149 -0
- package/dist/files/message/lib/constants.ts +18 -0
- package/dist/files/message/lib/helpers.ts +26 -0
- package/dist/files/message/lib/motion.ts +117 -0
- package/dist/files/message/lib/store.ts +72 -0
- package/dist/files/message/llm.txt +301 -0
- package/dist/files/message/message.css +178 -0
- package/dist/files/message/tokens.txt +25 -0
- package/dist/files/modal/Modal.tsx +547 -0
- package/dist/files/modal/_adapter/locale.ts +4 -0
- package/dist/files/modal/index.ts +16 -0
- package/dist/files/modal/interface.ts +368 -0
- package/dist/files/modal/lib/ConfirmDialog.tsx +229 -0
- package/dist/files/modal/lib/confirm.tsx +112 -0
- package/dist/files/modal/lib/confirmIcons.tsx +21 -0
- package/dist/files/modal/lib/useModal.tsx +130 -0
- package/dist/files/modal/llm.txt +586 -0
- package/dist/files/modal/modal-padding.stories.css +22 -0
- package/dist/files/modal/modal.css +322 -0
- package/dist/files/modal/tokens.txt +96 -0
- package/dist/files/modal/variants.ts +41 -0
- package/dist/files/notification/Notification.tsx +354 -0
- package/dist/files/notification/index.ts +8 -0
- package/dist/files/notification/interface.ts +140 -0
- package/dist/files/notification/lib/constants.ts +40 -0
- package/dist/files/notification/lib/helpers.ts +31 -0
- package/dist/files/notification/lib/motion.ts +148 -0
- package/dist/files/notification/lib/store.ts +149 -0
- package/dist/files/notification/llm.txt +386 -0
- package/dist/files/notification/notification.css +416 -0
- package/dist/files/notification/tokens.txt +79 -0
- package/dist/files/pagination/PageButton.tsx +48 -0
- package/dist/files/pagination/PageSizeChanger.tsx +42 -0
- package/dist/files/pagination/Pagination.tsx +308 -0
- package/dist/files/pagination/QuickJumper.tsx +52 -0
- package/dist/files/pagination/TotalText.tsx +28 -0
- package/dist/files/pagination/_adapter/calculate.ts +33 -0
- package/dist/files/pagination/_adapter/locale.ts +4 -0
- package/dist/files/pagination/_adapter/responsive.ts +22 -0
- package/dist/files/pagination/_adapter/types.ts +27 -0
- package/dist/files/pagination/context.ts +15 -0
- package/dist/files/pagination/index.ts +3 -0
- package/dist/files/pagination/interface.ts +55 -0
- package/dist/files/pagination/llm.txt +204 -0
- package/dist/files/pagination/pagination.css +241 -0
- package/dist/files/pagination/tokens.txt +33 -0
- package/dist/files/pagination/useResizeObserver.ts +40 -0
- package/dist/files/pagination/variants.ts +3 -0
- package/dist/files/popover/Popover.tsx +353 -0
- package/dist/files/popover/index.ts +2 -0
- package/dist/files/popover/interface.ts +124 -0
- package/dist/files/popover/llm.txt +235 -0
- package/dist/files/popover/placement.ts +39 -0
- package/dist/files/popover/popover.css +65 -0
- package/dist/files/popover/popover.stories.css +42 -0
- package/dist/files/popover/tokens.txt +28 -0
- package/dist/files/progress/Progress.tsx +213 -0
- package/dist/files/progress/index.ts +4 -0
- package/dist/files/progress/interface.ts +89 -0
- package/dist/files/progress/llm.txt +277 -0
- package/dist/files/progress/progress.css +192 -0
- package/dist/files/progress/tokens.txt +83 -0
- package/dist/files/radio/Radio.tsx +315 -0
- package/dist/files/radio/context.tsx +16 -0
- package/dist/files/radio/helpers.ts +163 -0
- package/dist/files/radio/index.ts +13 -0
- package/dist/files/radio/interface.ts +207 -0
- package/dist/files/radio/llm.txt +344 -0
- package/dist/files/radio/radio.css +137 -0
- package/dist/files/radio/tokens.txt +21 -0
- package/dist/files/radio/variants.ts +20 -0
- package/dist/files/rate/Rate.tsx +199 -0
- package/dist/files/rate/RateItem.tsx +113 -0
- package/dist/files/rate/StarFilled.tsx +19 -0
- package/dist/files/rate/index.ts +11 -0
- package/dist/files/rate/interface.ts +116 -0
- package/dist/files/rate/lib.ts +72 -0
- package/dist/files/rate/llm.txt +237 -0
- package/dist/files/rate/rate.css +126 -0
- package/dist/files/rate/tokens.txt +20 -0
- package/dist/files/rate/variants.ts +19 -0
- package/dist/files/scrollbar.css +148 -0
- package/dist/files/select/Select.tsx +1366 -0
- package/dist/files/select/_adapter/locale.ts +4 -0
- package/dist/files/select/index.ts +17 -0
- package/dist/files/select/interface.ts +494 -0
- package/dist/files/select/llm.txt +828 -0
- package/dist/files/select/select-overflow.stories.css +3 -0
- package/dist/files/select/select.css +443 -0
- package/dist/files/select/tokens.txt +160 -0
- package/dist/files/select/variants.ts +63 -0
- package/dist/files/skeleton/Skeleton.tsx +345 -0
- package/dist/files/skeleton/index.ts +19 -0
- package/dist/files/skeleton/interface.ts +101 -0
- package/dist/files/skeleton/llm.txt +274 -0
- package/dist/files/skeleton/skeleton.css +171 -0
- package/dist/files/skeleton/tokens.txt +15 -0
- package/dist/files/skeleton/variants.ts +40 -0
- package/dist/files/spin/Spin.tsx +197 -0
- package/dist/files/spin/index.ts +2 -0
- package/dist/files/spin/interface.ts +69 -0
- package/dist/files/spin/llm.txt +294 -0
- package/dist/files/spin/spin.css +111 -0
- package/dist/files/spin/tokens.txt +21 -0
- package/dist/files/spin/variants.ts +19 -0
- package/dist/files/steps/Steps.tsx +211 -0
- package/dist/files/steps/index.ts +11 -0
- package/dist/files/steps/interface.ts +155 -0
- package/dist/files/steps/lib.ts +46 -0
- package/dist/files/steps/llm.txt +296 -0
- package/dist/files/steps/steps.css +268 -0
- package/dist/files/steps/tokens.txt +30 -0
- package/dist/files/steps/variants.ts +15 -0
- package/dist/files/switch/Switch.tsx +131 -0
- package/dist/files/switch/index.ts +2 -0
- package/dist/files/switch/interface.ts +92 -0
- package/dist/files/switch/llm.txt +212 -0
- package/dist/files/switch/switch.css +198 -0
- package/dist/files/switch/tokens.txt +38 -0
- package/dist/files/switch/variants.ts +15 -0
- package/dist/files/table/Table.stories.css +56 -0
- package/dist/files/table/Table.tsx +481 -0
- package/dist/files/table/_adapter/locale.ts +4 -0
- package/dist/files/table/constants.ts +7 -0
- package/dist/files/table/context.ts +46 -0
- package/dist/files/table/hooks/useColumnControl.ts +135 -0
- package/dist/files/table/hooks/useColumns.ts +87 -0
- package/dist/files/table/hooks/useExpandable.tsx +271 -0
- package/dist/files/table/hooks/useOverlayScrollbar.ts +304 -0
- package/dist/files/table/hooks/usePagination.ts +110 -0
- package/dist/files/table/hooks/useRowSelection.tsx +250 -0
- package/dist/files/table/hooks/useScrollShadow.ts +66 -0
- package/dist/files/table/hooks/useSkeletonRowCount.ts +78 -0
- package/dist/files/table/hooks/useTableLayoutScale.ts +38 -0
- package/dist/files/table/hooks/useTableModel.ts +91 -0
- package/dist/files/table/index.ts +24 -0
- package/dist/files/table/interface.ts +407 -0
- package/dist/files/table/llm.txt +1050 -0
- package/dist/files/table/parts/TableBody.tsx +396 -0
- package/dist/files/table/parts/TableCell.tsx +123 -0
- package/dist/files/table/parts/TableColgroup.tsx +35 -0
- package/dist/files/table/parts/TableEmpty.tsx +48 -0
- package/dist/files/table/parts/TableEmptyIllustration.tsx +27 -0
- package/dist/files/table/parts/TableHeader.tsx +102 -0
- package/dist/files/table/parts/TablePagination.tsx +46 -0
- package/dist/files/table/parts/TableRow.tsx +42 -0
- package/dist/files/table/parts/TableScrollbars.tsx +79 -0
- package/dist/files/table/parts/TableSkeleton.tsx +47 -0
- package/dist/files/table/parts/TableSummary.tsx +121 -0
- package/dist/files/table/table.css +850 -0
- package/dist/files/table/tokenScopes.ts +28 -0
- package/dist/files/table/tokens.txt +94 -0
- package/dist/files/table/utils/computeMergeGrid.ts +41 -0
- package/dist/files/table/utils/dataModel.ts +45 -0
- package/dist/files/table/utils/getCellValue.ts +7 -0
- package/dist/files/table/utils/getGroupedHeaderSpan.ts +73 -0
- package/dist/files/table/utils/getRowKey.ts +31 -0
- package/dist/files/table/utils/paginationState.ts +31 -0
- package/dist/files/table/utils/prefixSvgIds.ts +6 -0
- package/dist/files/table/utils/scaleFixedOffset.ts +19 -0
- package/dist/files/tabs/Tabs.tsx +140 -0
- package/dist/files/tabs/index.ts +2 -0
- package/dist/files/tabs/interface.ts +117 -0
- package/dist/files/tabs/llm.txt +305 -0
- package/dist/files/tabs/tabs.css +299 -0
- package/dist/files/tabs/tokens.txt +78 -0
- package/dist/files/tabs/variants.ts +51 -0
- package/dist/files/tag/Tag.tsx +180 -0
- package/dist/files/tag/index.ts +8 -0
- package/dist/files/tag/interface.ts +68 -0
- package/dist/files/tag/llm.txt +301 -0
- package/dist/files/tag/tag.css +96 -0
- package/dist/files/tag/tokens.txt +76 -0
- package/dist/files/tag/variants.ts +71 -0
- package/dist/files/theme/aliases.css +217 -0
- package/dist/files/theme/component-tokens.css +2211 -0
- package/dist/files/theme/index.css +4 -0
- package/dist/files/theme/primitives.css +182 -0
- package/dist/files/theme/static.css +13 -0
- package/dist/files/tooltip/Tooltip.tsx +362 -0
- package/dist/files/tooltip/index.ts +7 -0
- package/dist/files/tooltip/interface.ts +118 -0
- package/dist/files/tooltip/llm.txt +308 -0
- package/dist/files/tooltip/placement.ts +51 -0
- package/dist/files/tooltip/tokens.txt +22 -0
- package/dist/files/tooltip/tooltip.css +78 -0
- package/dist/files/tree/Tree.tsx +1069 -0
- package/dist/files/tree/constants.ts +2 -0
- package/dist/files/tree/index.ts +22 -0
- package/dist/files/tree/interface.ts +447 -0
- package/dist/files/tree/llm.txt +501 -0
- package/dist/files/tree/tokens.txt +36 -0
- package/dist/files/tree/tree-data.ts +260 -0
- package/dist/files/tree/tree.css +231 -0
- package/dist/files/tree/variants.ts +25 -0
- package/dist/files/tree-select/TreeSelect.tsx +864 -0
- package/dist/files/tree-select/_adapter/locale.ts +4 -0
- package/dist/files/tree-select/index.ts +23 -0
- package/dist/files/tree-select/interface.ts +415 -0
- package/dist/files/tree-select/llm.txt +754 -0
- package/dist/files/tree-select/tokens.txt +174 -0
- package/dist/files/tree-select/tree-select-data.ts +294 -0
- package/dist/files/tree-select/tree-select.css +303 -0
- package/dist/files/tree-select/variants.ts +42 -0
- package/dist/files/typography/Typography.tsx +739 -0
- package/dist/files/typography/_adapter/locale.ts +4 -0
- package/dist/files/typography/canvasTextMeasure.ts +148 -0
- package/dist/files/typography/index.ts +21 -0
- package/dist/files/typography/interface.ts +154 -0
- package/dist/files/typography/llm.txt +412 -0
- package/dist/files/typography/tokens.txt +60 -0
- package/dist/files/typography/typography.css +312 -0
- package/dist/files/typography/useEllipsisSuffix.ts +245 -0
- package/dist/files/typography/variants.ts +24 -0
- package/dist/files/upload/Upload.stories.css +54 -0
- package/dist/files/upload/Upload.stories.shared.ts +21 -0
- package/dist/files/upload/Upload.tsx +1108 -0
- package/dist/files/upload/UploadActionIcons.tsx +13 -0
- package/dist/files/upload/UploadFileIcon.tsx +52 -0
- package/dist/files/upload/_adapter/locale.ts +4 -0
- package/dist/files/upload/constants.ts +46 -0
- package/dist/files/upload/index.ts +38 -0
- package/dist/files/upload/interface.ts +302 -0
- package/dist/files/upload/lib/file-type.ts +60 -0
- package/dist/files/upload/lib/format-size.ts +6 -0
- package/dist/files/upload/lib/limits.ts +46 -0
- package/dist/files/upload/llm.txt +705 -0
- package/dist/files/upload/tokens.txt +201 -0
- package/dist/files/upload/upload.css +460 -0
- package/dist/files/utils/cn.ts +16 -0
- package/dist/files/utils/env.ts +16 -0
- package/dist/files/utils/normalizeRawSvg.ts +12 -0
- package/dist/manifest.json +580 -0
- package/package.json +41 -3
|
@@ -0,0 +1,1108 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import './upload.css'
|
|
4
|
+
import * as React from 'react'
|
|
5
|
+
import { useConfig } from '../apex-provider'
|
|
6
|
+
import { Button } from '../button'
|
|
7
|
+
import { Icon } from '../icon'
|
|
8
|
+
import { Image } from '../image'
|
|
9
|
+
import { message } from '../message'
|
|
10
|
+
import { Spin } from '../spin'
|
|
11
|
+
import { Typography } from '../typography'
|
|
12
|
+
import { defaultLocale } from './_adapter/locale'
|
|
13
|
+
import { getUploadItemTokenClass, getUploadTriggerTokenClass } from './constants'
|
|
14
|
+
import type { UploadDraggerProps, UploadFile, UploadProps, UploadRequestOptions } from './interface'
|
|
15
|
+
import { UPLOAD_LIST_IGNORE } from './interface'
|
|
16
|
+
import {
|
|
17
|
+
getFileExtension,
|
|
18
|
+
getFileFormatIconName,
|
|
19
|
+
getFilePreviewUrl,
|
|
20
|
+
isDocumentFile,
|
|
21
|
+
isImageFile,
|
|
22
|
+
} from './lib/file-type'
|
|
23
|
+
import { formatFileSize } from './lib/format-size'
|
|
24
|
+
import {
|
|
25
|
+
countAvailableSlots,
|
|
26
|
+
filterFilesByMaxSize,
|
|
27
|
+
getUploadLimitMessages,
|
|
28
|
+
resolveUploadLimits,
|
|
29
|
+
} from './lib/limits'
|
|
30
|
+
import { uploadDeleteIcon, uploadDownloadIcon, uploadViewIcon } from './UploadActionIcons'
|
|
31
|
+
import { UploadFileIcon } from './UploadFileIcon'
|
|
32
|
+
|
|
33
|
+
const defaultRequest = (options: UploadRequestOptions) => {
|
|
34
|
+
const xhr = new XMLHttpRequest()
|
|
35
|
+
const {
|
|
36
|
+
action,
|
|
37
|
+
file,
|
|
38
|
+
fileName,
|
|
39
|
+
filename = 'file',
|
|
40
|
+
data,
|
|
41
|
+
headers,
|
|
42
|
+
method = 'post',
|
|
43
|
+
withCredentials,
|
|
44
|
+
onProgress,
|
|
45
|
+
onSuccess,
|
|
46
|
+
onError,
|
|
47
|
+
} = options
|
|
48
|
+
|
|
49
|
+
xhr.open(method, action, true)
|
|
50
|
+
if (withCredentials) {
|
|
51
|
+
xhr.withCredentials = true
|
|
52
|
+
}
|
|
53
|
+
if (headers) {
|
|
54
|
+
Object.keys(headers).forEach((key) => xhr.setRequestHeader(key, headers[key]))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (xhr.upload && onProgress) {
|
|
58
|
+
xhr.upload.onprogress = (e) => {
|
|
59
|
+
if (e.lengthComputable) {
|
|
60
|
+
onProgress({ percent: Math.round((e.loaded / e.total) * 100) })
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
xhr.onload = () => {
|
|
66
|
+
if (xhr.status < 200 || xhr.status >= 300) {
|
|
67
|
+
return onError?.(new Error(`Upload Error: ${xhr.status}`), xhr.response)
|
|
68
|
+
}
|
|
69
|
+
let body = xhr.response
|
|
70
|
+
try {
|
|
71
|
+
body = JSON.parse(body)
|
|
72
|
+
} catch (_e) {
|
|
73
|
+
/* ignore invalid JSON */
|
|
74
|
+
}
|
|
75
|
+
onSuccess?.(body)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
xhr.onerror = () => onError?.(new Error('Upload Error'), xhr.response)
|
|
79
|
+
|
|
80
|
+
const formData = new FormData()
|
|
81
|
+
if (data) {
|
|
82
|
+
Object.keys(data).forEach((key) => formData.append(key, data[key] as string | Blob))
|
|
83
|
+
}
|
|
84
|
+
if (file instanceof File) {
|
|
85
|
+
formData.append(filename, file, fileName ?? file.name)
|
|
86
|
+
} else {
|
|
87
|
+
formData.append(filename, file, fileName)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
xhr.send(formData)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const generateUid = () => `apex-upload-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`
|
|
94
|
+
|
|
95
|
+
function matchesAcceptFormat(file: File, format?: string): boolean {
|
|
96
|
+
if (!format?.trim()) return true
|
|
97
|
+
|
|
98
|
+
return format.split(',').some((rawRule) => {
|
|
99
|
+
const rule = rawRule.trim().toLowerCase()
|
|
100
|
+
if (!rule) return false
|
|
101
|
+
if (rule.startsWith('.')) return file.name.toLowerCase().endsWith(rule)
|
|
102
|
+
if (rule.endsWith('/*')) return file.type.toLowerCase().startsWith(rule.slice(0, -1))
|
|
103
|
+
return file.type.toLowerCase() === rule
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function acceptsFile(file: File, accept: UploadProps['accept']): boolean {
|
|
108
|
+
try {
|
|
109
|
+
if (!accept) return true
|
|
110
|
+
const format = typeof accept === 'string' ? accept : accept.format
|
|
111
|
+
if (!matchesAcceptFormat(file, format)) return false
|
|
112
|
+
return typeof accept === 'object' && typeof accept.filter === 'function'
|
|
113
|
+
? accept.filter(file)
|
|
114
|
+
: true
|
|
115
|
+
} catch (_error) {
|
|
116
|
+
return false
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function supportsDisabledProp(element: React.ReactElement): boolean {
|
|
121
|
+
if (element.type === React.Fragment) return false
|
|
122
|
+
if (typeof element.type !== 'string') return true
|
|
123
|
+
return ['button', 'input', 'select', 'textarea', 'fieldset', 'optgroup', 'option'].includes(
|
|
124
|
+
element.type,
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function isInteractiveTriggerElement(element: React.ReactElement): boolean {
|
|
129
|
+
if (typeof element.type === 'string') {
|
|
130
|
+
if (['button', 'input', 'select', 'textarea'].includes(element.type)) return true
|
|
131
|
+
return element.type === 'a' && Boolean((element.props as { href?: unknown }).href)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const component = element.type as { displayName?: string; name?: string }
|
|
135
|
+
return component.displayName === 'Button' || component.name === 'Button'
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function resolveFileBoolean(
|
|
139
|
+
value: boolean | ((file: UploadFile) => boolean) | undefined,
|
|
140
|
+
file: UploadFile,
|
|
141
|
+
fallback: boolean,
|
|
142
|
+
) {
|
|
143
|
+
if (typeof value === 'function') return value(file)
|
|
144
|
+
return value ?? fallback
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function resolveFileNode(
|
|
148
|
+
value: React.ReactNode | ((file: UploadFile) => React.ReactNode) | undefined,
|
|
149
|
+
file: UploadFile,
|
|
150
|
+
fallback: React.ReactNode,
|
|
151
|
+
) {
|
|
152
|
+
return typeof value === 'function' ? value(file) : (value ?? fallback)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const isBlobUrl = (url?: string): url is `blob:${string}` =>
|
|
156
|
+
typeof url === 'string' && url.startsWith('blob:')
|
|
157
|
+
|
|
158
|
+
const revokeBlobUrl = (url?: string) => {
|
|
159
|
+
if (isBlobUrl(url) && typeof URL !== 'undefined' && URL.revokeObjectURL) {
|
|
160
|
+
URL.revokeObjectURL(url)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function triggerAnchorDownload(href: string, filename: string, openInNewTab = false) {
|
|
165
|
+
if (typeof document === 'undefined') return
|
|
166
|
+
|
|
167
|
+
const link = document.createElement('a')
|
|
168
|
+
link.href = href
|
|
169
|
+
link.rel = 'noopener noreferrer'
|
|
170
|
+
link.download = filename
|
|
171
|
+
if (openInNewTab) {
|
|
172
|
+
link.target = '_blank'
|
|
173
|
+
}
|
|
174
|
+
link.style.display = 'none'
|
|
175
|
+
document.body.appendChild(link)
|
|
176
|
+
link.click()
|
|
177
|
+
document.body.removeChild(link)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function defaultDownloadFile(file: UploadFile) {
|
|
181
|
+
const url = getFilePreviewUrl(file)
|
|
182
|
+
const filename = file.name || 'download'
|
|
183
|
+
|
|
184
|
+
if (url) {
|
|
185
|
+
const sameOrigin =
|
|
186
|
+
typeof window !== 'undefined' &&
|
|
187
|
+
(isBlobUrl(url) || url.startsWith(window.location.origin) || url.startsWith('/'))
|
|
188
|
+
triggerAnchorDownload(url, filename, !sameOrigin)
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const blobSource = file.originFileObj
|
|
193
|
+
if (!blobSource || typeof URL === 'undefined') return
|
|
194
|
+
|
|
195
|
+
const blobUrl = URL.createObjectURL(blobSource)
|
|
196
|
+
triggerAnchorDownload(blobUrl, filename)
|
|
197
|
+
URL.revokeObjectURL(blobUrl)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** File.name / size / type are non-enumerable — spread would drop them. */
|
|
201
|
+
const mergeUploadFile = (file: UploadFile, patch: Partial<UploadFile> = {}): UploadFile =>
|
|
202
|
+
({
|
|
203
|
+
uid: file.uid,
|
|
204
|
+
name: file.name,
|
|
205
|
+
lastModified: file.lastModified,
|
|
206
|
+
size: file.size,
|
|
207
|
+
type: file.type,
|
|
208
|
+
webkitRelativePath: file.webkitRelativePath,
|
|
209
|
+
status: file.status,
|
|
210
|
+
percent: file.percent,
|
|
211
|
+
thumbUrl: file.thumbUrl,
|
|
212
|
+
url: file.url,
|
|
213
|
+
response: file.response,
|
|
214
|
+
error: file.error,
|
|
215
|
+
originFileObj: file.originFileObj,
|
|
216
|
+
...patch,
|
|
217
|
+
}) as UploadFile
|
|
218
|
+
|
|
219
|
+
function getUploadFileSize(file: UploadFile): number | undefined {
|
|
220
|
+
if (typeof file.size === 'number' && Number.isFinite(file.size)) {
|
|
221
|
+
return file.size
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const originSize = file.originFileObj?.size
|
|
225
|
+
if (typeof originSize === 'number' && Number.isFinite(originSize)) {
|
|
226
|
+
return originSize
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return undefined
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export const Upload: React.FC<UploadProps> & { Dragger: React.FC<UploadDraggerProps> } = (
|
|
233
|
+
props: UploadProps,
|
|
234
|
+
) => {
|
|
235
|
+
const {
|
|
236
|
+
accept,
|
|
237
|
+
action,
|
|
238
|
+
beforeUpload,
|
|
239
|
+
customRequest,
|
|
240
|
+
data,
|
|
241
|
+
defaultFileList,
|
|
242
|
+
disabled = false,
|
|
243
|
+
fileList,
|
|
244
|
+
headers,
|
|
245
|
+
isImageUrl,
|
|
246
|
+
itemRender,
|
|
247
|
+
prefixIcon,
|
|
248
|
+
listType = 'text',
|
|
249
|
+
variant = 'default',
|
|
250
|
+
maxCount,
|
|
251
|
+
maxSize,
|
|
252
|
+
method = 'post',
|
|
253
|
+
multiple = false,
|
|
254
|
+
name = 'file',
|
|
255
|
+
openFileDialogOnClick = true,
|
|
256
|
+
showUploadList = true,
|
|
257
|
+
withCredentials = false,
|
|
258
|
+
onChange,
|
|
259
|
+
onBlur,
|
|
260
|
+
onDrop,
|
|
261
|
+
onDownload,
|
|
262
|
+
onPreview,
|
|
263
|
+
onRemove,
|
|
264
|
+
children,
|
|
265
|
+
className,
|
|
266
|
+
ref,
|
|
267
|
+
...restProps
|
|
268
|
+
} = props
|
|
269
|
+
|
|
270
|
+
const uploadLocale = useConfig()?.locale?.Upload ?? defaultLocale
|
|
271
|
+
const resolvedLimits = React.useMemo(
|
|
272
|
+
() => resolveUploadLimits({ maxCount, maxSize }, listType),
|
|
273
|
+
[maxCount, maxSize, listType],
|
|
274
|
+
)
|
|
275
|
+
const effectiveMaxCount = resolvedLimits.maxCount
|
|
276
|
+
const effectiveMaxSize = resolvedLimits.maxSize
|
|
277
|
+
const limitMessages = React.useMemo(
|
|
278
|
+
() => getUploadLimitMessages(uploadLocale, resolvedLimits),
|
|
279
|
+
[uploadLocale, resolvedLimits],
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
const [internalFileList, setInternalFileList] = React.useState<UploadFile[]>(
|
|
283
|
+
defaultFileList || [],
|
|
284
|
+
)
|
|
285
|
+
const [previewOpen, setPreviewOpen] = React.useState(false)
|
|
286
|
+
const [previewCurrent, setPreviewCurrent] = React.useState(0)
|
|
287
|
+
const [isDragOver, setIsDragOver] = React.useState(false)
|
|
288
|
+
const mergedFileList = fileList !== undefined ? fileList : internalFileList
|
|
289
|
+
const fileInputRef = React.useRef<HTMLInputElement>(null)
|
|
290
|
+
const fileDialogOpenRef = React.useRef(false)
|
|
291
|
+
const dragEnterCountRef = React.useRef(0)
|
|
292
|
+
const fileListRef = React.useRef(mergedFileList)
|
|
293
|
+
fileListRef.current = mergedFileList
|
|
294
|
+
const ownedBlobUrlsRef = React.useRef(new Map<string, string>())
|
|
295
|
+
const renderedFileListRef = React.useRef(mergedFileList)
|
|
296
|
+
const registerBlobThumbUrl = (uid: string, thumbUrl: string) => {
|
|
297
|
+
if (!isBlobUrl(thumbUrl)) return
|
|
298
|
+
const prev = ownedBlobUrlsRef.current.get(uid)
|
|
299
|
+
if (prev && prev !== thumbUrl) revokeBlobUrl(prev)
|
|
300
|
+
ownedBlobUrlsRef.current.set(uid, thumbUrl)
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const revokeFileBlobUrl = (file: UploadFile) => {
|
|
304
|
+
const tracked = ownedBlobUrlsRef.current.get(file.uid)
|
|
305
|
+
if (tracked) {
|
|
306
|
+
revokeBlobUrl(tracked)
|
|
307
|
+
ownedBlobUrlsRef.current.delete(file.uid)
|
|
308
|
+
return
|
|
309
|
+
}
|
|
310
|
+
revokeBlobUrl(file.thumbUrl)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const revokeDroppedFiles = (prevList: UploadFile[], nextList: UploadFile[]) => {
|
|
314
|
+
const nextUids = new Set(nextList.map((f) => f.uid))
|
|
315
|
+
for (const file of prevList) {
|
|
316
|
+
if (!nextUids.has(file.uid)) revokeFileBlobUrl(file)
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
React.useEffect(() => {
|
|
321
|
+
const nextUids = new Set(mergedFileList.map((file) => file.uid))
|
|
322
|
+
for (const file of renderedFileListRef.current) {
|
|
323
|
+
if (nextUids.has(file.uid)) continue
|
|
324
|
+
const tracked = ownedBlobUrlsRef.current.get(file.uid)
|
|
325
|
+
if (tracked) {
|
|
326
|
+
revokeBlobUrl(tracked)
|
|
327
|
+
ownedBlobUrlsRef.current.delete(file.uid)
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
renderedFileListRef.current = mergedFileList
|
|
331
|
+
}, [mergedFileList])
|
|
332
|
+
|
|
333
|
+
React.useEffect(() => {
|
|
334
|
+
return () => {
|
|
335
|
+
for (const url of ownedBlobUrlsRef.current.values()) {
|
|
336
|
+
revokeBlobUrl(url)
|
|
337
|
+
}
|
|
338
|
+
ownedBlobUrlsRef.current.clear()
|
|
339
|
+
}
|
|
340
|
+
}, [])
|
|
341
|
+
|
|
342
|
+
const applyFileList = (
|
|
343
|
+
nextList: UploadFile[],
|
|
344
|
+
changedUid: string,
|
|
345
|
+
event?: ProgressEvent,
|
|
346
|
+
): UploadFile[] => {
|
|
347
|
+
if (fileList === undefined) revokeDroppedFiles(fileListRef.current, nextList)
|
|
348
|
+
fileListRef.current = nextList
|
|
349
|
+
const changedFile = nextList.find((f) => f.uid === changedUid)
|
|
350
|
+
if (!changedFile) return nextList
|
|
351
|
+
if (fileList === undefined) {
|
|
352
|
+
setInternalFileList(nextList)
|
|
353
|
+
}
|
|
354
|
+
onChange?.({ file: changedFile, fileList: nextList, event })
|
|
355
|
+
return nextList
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const patchFileByUid = (
|
|
359
|
+
uid: string,
|
|
360
|
+
patch: (file: UploadFile) => UploadFile,
|
|
361
|
+
event?: ProgressEvent,
|
|
362
|
+
) => {
|
|
363
|
+
const hasFile = fileListRef.current.some((f) => f.uid === uid)
|
|
364
|
+
if (!hasFile) return fileListRef.current
|
|
365
|
+
const nextList = fileListRef.current.map((f) => (f.uid === uid ? patch(f) : f))
|
|
366
|
+
return applyFileList(nextList, uid, event)
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const constrainFileList = (list: UploadFile[], uid: string) => {
|
|
370
|
+
if (effectiveMaxCount === 1) {
|
|
371
|
+
const target = list.find((f) => f.uid === uid)
|
|
372
|
+
return target ? [target] : list
|
|
373
|
+
}
|
|
374
|
+
if (effectiveMaxCount !== undefined) return list.slice(-effectiveMaxCount)
|
|
375
|
+
return list
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const imagePreviewItems = React.useMemo(() => {
|
|
379
|
+
const checkIsImage = isImageUrl ?? isImageFile
|
|
380
|
+
return mergedFileList
|
|
381
|
+
.filter((f) => checkIsImage(f) && Boolean(f.url || f.thumbUrl))
|
|
382
|
+
.map((f) => ({
|
|
383
|
+
key: f.uid,
|
|
384
|
+
src: (f.url || f.thumbUrl)!,
|
|
385
|
+
alt: f.name,
|
|
386
|
+
}))
|
|
387
|
+
}, [mergedFileList, isImageUrl])
|
|
388
|
+
|
|
389
|
+
const handlePreview = (file: UploadFile) => {
|
|
390
|
+
const checkIsImage = isImageUrl ?? isImageFile
|
|
391
|
+
const fileIsImage = checkIsImage(file)
|
|
392
|
+
const fileUrl = getFilePreviewUrl(file)
|
|
393
|
+
|
|
394
|
+
if (!fileIsImage) {
|
|
395
|
+
onPreview?.(file)
|
|
396
|
+
return
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (!fileUrl) {
|
|
400
|
+
onPreview?.(file)
|
|
401
|
+
return
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const result = onPreview?.(file)
|
|
405
|
+
if (result === false) return
|
|
406
|
+
|
|
407
|
+
const idx = imagePreviewItems.findIndex((item) => item.key === file.uid)
|
|
408
|
+
if (idx >= 0) {
|
|
409
|
+
setPreviewCurrent(idx)
|
|
410
|
+
setPreviewOpen(true)
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const handleDownload = (file: UploadFile) => {
|
|
415
|
+
if (onDownload) {
|
|
416
|
+
onDownload(file)
|
|
417
|
+
return
|
|
418
|
+
}
|
|
419
|
+
defaultDownloadFile(file)
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const handleRemove = async (file: UploadFile) => {
|
|
423
|
+
if (disabled) return
|
|
424
|
+
let canRemove: boolean | void = true
|
|
425
|
+
if (onRemove) {
|
|
426
|
+
try {
|
|
427
|
+
canRemove = await onRemove(file)
|
|
428
|
+
} catch (_e) {
|
|
429
|
+
canRemove = false
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
if (canRemove === false) return
|
|
433
|
+
|
|
434
|
+
if (fileList === undefined) revokeFileBlobUrl(file)
|
|
435
|
+
const nextList = fileListRef.current.filter((f) => f.uid !== file.uid)
|
|
436
|
+
const removedFile = mergeUploadFile(file, { status: 'removed' })
|
|
437
|
+
fileListRef.current = nextList
|
|
438
|
+
if (fileList === undefined) {
|
|
439
|
+
setInternalFileList(nextList)
|
|
440
|
+
}
|
|
441
|
+
onChange?.({ file: removedFile, fileList: nextList })
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
type PreparedUpload = {
|
|
445
|
+
mode: 'ignore' | 'manual' | 'upload'
|
|
446
|
+
sourceFile: File
|
|
447
|
+
targetFile: UploadFile
|
|
448
|
+
uploadSource: File | Blob
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const prepareUpload = async (
|
|
452
|
+
targetFile: UploadFile,
|
|
453
|
+
selectedFiles: File[],
|
|
454
|
+
): Promise<PreparedUpload | undefined> => {
|
|
455
|
+
const sourceFile = targetFile.originFileObj
|
|
456
|
+
if (!sourceFile) return undefined
|
|
457
|
+
|
|
458
|
+
if (!beforeUpload) {
|
|
459
|
+
return { mode: 'upload', sourceFile, targetFile, uploadSource: sourceFile }
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
try {
|
|
463
|
+
const before = await beforeUpload(sourceFile, selectedFiles)
|
|
464
|
+
if (before === UPLOAD_LIST_IGNORE) {
|
|
465
|
+
return { mode: 'ignore', sourceFile, targetFile, uploadSource: sourceFile }
|
|
466
|
+
}
|
|
467
|
+
if (before === false) {
|
|
468
|
+
return { mode: 'manual', sourceFile, targetFile, uploadSource: sourceFile }
|
|
469
|
+
}
|
|
470
|
+
return {
|
|
471
|
+
mode: 'upload',
|
|
472
|
+
sourceFile,
|
|
473
|
+
targetFile,
|
|
474
|
+
uploadSource: before && typeof before !== 'boolean' ? before : sourceFile,
|
|
475
|
+
}
|
|
476
|
+
} catch (_error) {
|
|
477
|
+
return { mode: 'manual', sourceFile, targetFile, uploadSource: sourceFile }
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
const stagePreparedUpload = (prepared: PreparedUpload): boolean => {
|
|
482
|
+
const { mode, targetFile } = prepared
|
|
483
|
+
const baseList = fileListRef.current
|
|
484
|
+
const isRetry = baseList.some((file) => file.uid === targetFile.uid)
|
|
485
|
+
|
|
486
|
+
if (mode === 'ignore') {
|
|
487
|
+
if (!isRetry) revokeFileBlobUrl(targetFile)
|
|
488
|
+
return false
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
const nextStatus = mode === 'manual' ? undefined : 'uploading'
|
|
492
|
+
const nextList = constrainFileList(
|
|
493
|
+
isRetry
|
|
494
|
+
? baseList.map((file) =>
|
|
495
|
+
file.uid === targetFile.uid
|
|
496
|
+
? mergeUploadFile(file, {
|
|
497
|
+
...targetFile,
|
|
498
|
+
status: nextStatus,
|
|
499
|
+
percent: mode === 'manual' ? undefined : 0,
|
|
500
|
+
error: undefined,
|
|
501
|
+
})
|
|
502
|
+
: file,
|
|
503
|
+
)
|
|
504
|
+
: [
|
|
505
|
+
...baseList,
|
|
506
|
+
mergeUploadFile(targetFile, {
|
|
507
|
+
status: nextStatus,
|
|
508
|
+
percent: mode === 'manual' ? undefined : 0,
|
|
509
|
+
}),
|
|
510
|
+
],
|
|
511
|
+
targetFile.uid,
|
|
512
|
+
)
|
|
513
|
+
applyFileList(nextList, targetFile.uid)
|
|
514
|
+
return mode === 'upload'
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
const executePreparedUpload = async (prepared: PreparedUpload) => {
|
|
518
|
+
const { sourceFile, targetFile, uploadSource } = prepared
|
|
519
|
+
const uid = targetFile.uid
|
|
520
|
+
|
|
521
|
+
try {
|
|
522
|
+
const uploadAction = typeof action === 'function' ? await action(sourceFile) : action
|
|
523
|
+
const options: UploadRequestOptions = {
|
|
524
|
+
action: uploadAction || '',
|
|
525
|
+
file: uploadSource,
|
|
526
|
+
fileName: uploadSource instanceof File ? uploadSource.name : sourceFile.name,
|
|
527
|
+
filename: name,
|
|
528
|
+
headers,
|
|
529
|
+
method,
|
|
530
|
+
withCredentials,
|
|
531
|
+
data: typeof data === 'function' ? await data(sourceFile) : data,
|
|
532
|
+
onProgress: (event) => {
|
|
533
|
+
patchFileByUid(
|
|
534
|
+
uid,
|
|
535
|
+
(file) => mergeUploadFile(file, { percent: event.percent }),
|
|
536
|
+
event as unknown as ProgressEvent,
|
|
537
|
+
)
|
|
538
|
+
},
|
|
539
|
+
onSuccess: (response) => {
|
|
540
|
+
patchFileByUid(uid, (file) => mergeUploadFile(file, { status: 'done', response }))
|
|
541
|
+
},
|
|
542
|
+
onError: (error, response) => {
|
|
543
|
+
patchFileByUid(uid, (file) => mergeUploadFile(file, { status: 'error', error, response }))
|
|
544
|
+
},
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (customRequest) {
|
|
548
|
+
await customRequest(options, { defaultRequest })
|
|
549
|
+
} else if (uploadAction) {
|
|
550
|
+
defaultRequest(options)
|
|
551
|
+
} else {
|
|
552
|
+
options.onError?.(new Error('No action configured'))
|
|
553
|
+
}
|
|
554
|
+
} catch (error) {
|
|
555
|
+
const uploadError = error instanceof Error ? error : new Error(String(error))
|
|
556
|
+
patchFileByUid(uid, (file) => mergeUploadFile(file, { status: 'error', error: uploadError }))
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
const uploadFile = async (
|
|
561
|
+
targetFile: UploadFile,
|
|
562
|
+
selectedFiles: File[] = targetFile.originFileObj ? [targetFile.originFileObj] : [],
|
|
563
|
+
) => {
|
|
564
|
+
if (disabled) return
|
|
565
|
+
const prepared = await prepareUpload(targetFile, selectedFiles)
|
|
566
|
+
if (!prepared || !stagePreparedUpload(prepared)) return
|
|
567
|
+
await executePreparedUpload(prepared)
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
const handleFiles = async (files: FileList | File[]) => {
|
|
571
|
+
if (disabled) return
|
|
572
|
+
|
|
573
|
+
const selectedFiles = Array.from(files)
|
|
574
|
+
let incomingFiles = selectedFiles.filter((file) => acceptsFile(file, accept))
|
|
575
|
+
if (!multiple) incomingFiles = incomingFiles.slice(0, 1)
|
|
576
|
+
|
|
577
|
+
const { accepted, rejected } = filterFilesByMaxSize(incomingFiles, effectiveMaxSize)
|
|
578
|
+
incomingFiles = accepted
|
|
579
|
+
if (rejected.length > 0) message.error(limitMessages.exceedMaxSize())
|
|
580
|
+
if (incomingFiles.length === 0) return
|
|
581
|
+
|
|
582
|
+
if (effectiveMaxCount === 1) incomingFiles = [incomingFiles.at(-1)!]
|
|
583
|
+
|
|
584
|
+
const availableSlots =
|
|
585
|
+
effectiveMaxCount === 1
|
|
586
|
+
? undefined
|
|
587
|
+
: countAvailableSlots(fileListRef.current.length, effectiveMaxCount)
|
|
588
|
+
|
|
589
|
+
if (availableSlots !== undefined) {
|
|
590
|
+
if (availableSlots <= 0) {
|
|
591
|
+
message.error(limitMessages.exceedMaxCount())
|
|
592
|
+
return
|
|
593
|
+
}
|
|
594
|
+
if (incomingFiles.length > availableSlots) {
|
|
595
|
+
message.error(limitMessages.exceedMaxCount())
|
|
596
|
+
incomingFiles = incomingFiles.slice(0, availableSlots)
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
const acceptedFiles = [...incomingFiles]
|
|
601
|
+
const parsedFiles = acceptedFiles.map((file) => {
|
|
602
|
+
const uid = generateUid()
|
|
603
|
+
const thumbUrl =
|
|
604
|
+
isImageFile({ name: file.name, type: file.type }) &&
|
|
605
|
+
typeof URL !== 'undefined' &&
|
|
606
|
+
URL.createObjectURL
|
|
607
|
+
? URL.createObjectURL(file)
|
|
608
|
+
: undefined
|
|
609
|
+
if (thumbUrl) registerBlobThumbUrl(uid, thumbUrl)
|
|
610
|
+
const uploadFile = {
|
|
611
|
+
uid,
|
|
612
|
+
name: file.name,
|
|
613
|
+
lastModified: file.lastModified,
|
|
614
|
+
size: file.size,
|
|
615
|
+
type: file.type,
|
|
616
|
+
webkitRelativePath: file.webkitRelativePath,
|
|
617
|
+
originFileObj: file,
|
|
618
|
+
thumbUrl,
|
|
619
|
+
} as unknown as UploadFile
|
|
620
|
+
return uploadFile
|
|
621
|
+
})
|
|
622
|
+
|
|
623
|
+
const preparedFiles = await Promise.all(
|
|
624
|
+
parsedFiles.map((file) => prepareUpload(file, acceptedFiles)),
|
|
625
|
+
)
|
|
626
|
+
const uploads = preparedFiles.filter(
|
|
627
|
+
(prepared): prepared is PreparedUpload => prepared !== undefined,
|
|
628
|
+
)
|
|
629
|
+
const stagedUploads = uploads.filter(stagePreparedUpload)
|
|
630
|
+
await Promise.all(stagedUploads.map(executePreparedUpload))
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
const handleClick = () => {
|
|
634
|
+
if (disabled || !openFileDialogOnClick) return
|
|
635
|
+
fileDialogOpenRef.current = true
|
|
636
|
+
fileInputRef.current?.click()
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
640
|
+
fileDialogOpenRef.current = false
|
|
641
|
+
const input = e.currentTarget
|
|
642
|
+
if (input.files) void handleFiles(input.files)
|
|
643
|
+
input.value = ''
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
React.useEffect(() => {
|
|
647
|
+
const handleDialogClose = () => {
|
|
648
|
+
fileDialogOpenRef.current = false
|
|
649
|
+
}
|
|
650
|
+
const input = fileInputRef.current
|
|
651
|
+
window.addEventListener('focus', handleDialogClose)
|
|
652
|
+
input?.addEventListener('cancel', handleDialogClose)
|
|
653
|
+
return () => {
|
|
654
|
+
window.removeEventListener('focus', handleDialogClose)
|
|
655
|
+
input?.removeEventListener('cancel', handleDialogClose)
|
|
656
|
+
}
|
|
657
|
+
}, [])
|
|
658
|
+
|
|
659
|
+
const prefixCls = 'apex-upload'
|
|
660
|
+
const classes = [prefixCls, className].filter(Boolean).join(' ')
|
|
661
|
+
|
|
662
|
+
// `showUploadList.showTrigger === false` hides the trigger for every listType,
|
|
663
|
+
// leaving a read-only preview of the uploaded list.
|
|
664
|
+
const showTrigger =
|
|
665
|
+
typeof showUploadList === 'object' ? showUploadList.showTrigger !== false : true
|
|
666
|
+
|
|
667
|
+
const acceptStr = typeof accept === 'object' ? accept.format : accept
|
|
668
|
+
const isDragger =
|
|
669
|
+
!!(props as Record<string, unknown>)['data-type'] &&
|
|
670
|
+
(props as Record<string, unknown>)['data-type'] === 'dragger'
|
|
671
|
+
|
|
672
|
+
React.useEffect(() => {
|
|
673
|
+
if (!isDragger || disabled) {
|
|
674
|
+
dragEnterCountRef.current = 0
|
|
675
|
+
setIsDragOver(false)
|
|
676
|
+
}
|
|
677
|
+
}, [disabled, isDragger])
|
|
678
|
+
|
|
679
|
+
const onDragEnter = (e: React.DragEvent<HTMLDivElement>) => {
|
|
680
|
+
if (isDragger && !disabled) {
|
|
681
|
+
e.preventDefault()
|
|
682
|
+
dragEnterCountRef.current += 1
|
|
683
|
+
setIsDragOver(true)
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
const onDragOver = (e: React.DragEvent<HTMLDivElement>) => {
|
|
688
|
+
if (isDragger && !disabled) {
|
|
689
|
+
e.preventDefault()
|
|
690
|
+
setIsDragOver(true)
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
const onDragLeave = (e: React.DragEvent<HTMLDivElement>) => {
|
|
695
|
+
if (isDragger && !disabled) {
|
|
696
|
+
e.preventDefault()
|
|
697
|
+
dragEnterCountRef.current = Math.max(0, dragEnterCountRef.current - 1)
|
|
698
|
+
if (dragEnterCountRef.current === 0) {
|
|
699
|
+
setIsDragOver(false)
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
const onDropHandler = (e: React.DragEvent<HTMLDivElement>) => {
|
|
705
|
+
if (isDragger && !disabled) {
|
|
706
|
+
e.preventDefault()
|
|
707
|
+
dragEnterCountRef.current = 0
|
|
708
|
+
setIsDragOver(false)
|
|
709
|
+
onDrop?.(e)
|
|
710
|
+
if (e.dataTransfer.files) {
|
|
711
|
+
void handleFiles(e.dataTransfer.files)
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
const renderTrigger = (asListItem = false) => {
|
|
717
|
+
const onlyChild =
|
|
718
|
+
React.Children.count(children) === 1 && React.isValidElement(children) ? children : undefined
|
|
719
|
+
const childIsInteractive = Boolean(onlyChild && isInteractiveTriggerElement(onlyChild))
|
|
720
|
+
// Custom components own their semantic root. The wrapper remains the trigger
|
|
721
|
+
// for plain host content, while interactive children keep their own focus target.
|
|
722
|
+
const wrapperOwnsAccessibility =
|
|
723
|
+
!onlyChild || (typeof onlyChild.type === 'string' && !childIsInteractive)
|
|
724
|
+
const triggerProps = {
|
|
725
|
+
'data-slot': 'upload-trigger',
|
|
726
|
+
'data-disabled': disabled ? '' : undefined,
|
|
727
|
+
'data-state': isDragger && !disabled && isDragOver ? 'over' : undefined,
|
|
728
|
+
'aria-disabled': disabled,
|
|
729
|
+
'aria-label':
|
|
730
|
+
children == null ? (isDragger ? uploadLocale.dragger : uploadLocale.upload) : undefined,
|
|
731
|
+
role: wrapperOwnsAccessibility ? 'button' : undefined,
|
|
732
|
+
tabIndex: wrapperOwnsAccessibility ? (disabled ? -1 : 0) : undefined,
|
|
733
|
+
className: `apex-upload ${prefixCls}__trigger ${getUploadTriggerTokenClass(variant)} ${
|
|
734
|
+
isDragger ? 'apex-trigger-md-upload' : 'apex-trigger-sm-upload'
|
|
735
|
+
}`,
|
|
736
|
+
onClick: handleClick,
|
|
737
|
+
onKeyDown: !wrapperOwnsAccessibility
|
|
738
|
+
? undefined
|
|
739
|
+
: (event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
740
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
741
|
+
event.preventDefault()
|
|
742
|
+
handleClick()
|
|
743
|
+
}
|
|
744
|
+
},
|
|
745
|
+
onDragEnter,
|
|
746
|
+
onDragOver,
|
|
747
|
+
onDragLeave,
|
|
748
|
+
onDrop: onDropHandler,
|
|
749
|
+
}
|
|
750
|
+
const childForDisabled = onlyChild as React.ReactElement<Record<string, unknown>> | undefined
|
|
751
|
+
const renderedChildren =
|
|
752
|
+
disabled && childForDisabled && supportsDisabledProp(childForDisabled)
|
|
753
|
+
? React.cloneElement(childForDisabled, { disabled: true, tabIndex: -1 })
|
|
754
|
+
: children
|
|
755
|
+
const trigger = (
|
|
756
|
+
<div {...triggerProps}>
|
|
757
|
+
{renderedChildren ??
|
|
758
|
+
(listType === 'picture-card' ? (
|
|
759
|
+
<Icon name="plus" className={`${prefixCls}__trigger-icon`} />
|
|
760
|
+
) : (
|
|
761
|
+
<>
|
|
762
|
+
<Icon name="upload-trigger" className={`${prefixCls}__default-trigger-icon`} />
|
|
763
|
+
<Typography.Text>
|
|
764
|
+
{isDragger ? uploadLocale.dragger : uploadLocale.upload}
|
|
765
|
+
</Typography.Text>
|
|
766
|
+
</>
|
|
767
|
+
))}
|
|
768
|
+
</div>
|
|
769
|
+
)
|
|
770
|
+
|
|
771
|
+
if (!asListItem) return trigger
|
|
772
|
+
|
|
773
|
+
return (
|
|
774
|
+
<li
|
|
775
|
+
key="__apex-upload-trigger__"
|
|
776
|
+
className={`${prefixCls}__list-trigger`}
|
|
777
|
+
data-slot="upload-list-trigger"
|
|
778
|
+
>
|
|
779
|
+
{trigger}
|
|
780
|
+
</li>
|
|
781
|
+
)
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
const renderList = (trailing?: React.ReactNode) => {
|
|
785
|
+
const config = typeof showUploadList === 'object' ? showUploadList : {}
|
|
786
|
+
const items =
|
|
787
|
+
showUploadList && mergedFileList.length > 0
|
|
788
|
+
? mergedFileList.map((file) => {
|
|
789
|
+
let thumb = null
|
|
790
|
+
if (listType === 'picture' || listType === 'picture-card') {
|
|
791
|
+
const isImg = (isImageUrl ?? isImageFile)(file)
|
|
792
|
+
const isDoc = isDocumentFile(file)
|
|
793
|
+
if (isImg && (file.thumbUrl || file.url)) {
|
|
794
|
+
thumb = (
|
|
795
|
+
<img
|
|
796
|
+
src={file.thumbUrl || file.url}
|
|
797
|
+
alt={file.name}
|
|
798
|
+
data-slot="upload-list-item-thumb"
|
|
799
|
+
/>
|
|
800
|
+
)
|
|
801
|
+
} else if (isDoc && file.status === 'done') {
|
|
802
|
+
thumb = (
|
|
803
|
+
<div
|
|
804
|
+
className={`${prefixCls}__doc-thumb`}
|
|
805
|
+
data-slot="upload-list-item-thumb"
|
|
806
|
+
data-file-kind="document"
|
|
807
|
+
>
|
|
808
|
+
<Icon
|
|
809
|
+
name={getFileFormatIconName(file)}
|
|
810
|
+
className={`${prefixCls}__doc-thumb-icon`}
|
|
811
|
+
/>
|
|
812
|
+
<Typography.Text
|
|
813
|
+
variant="caption"
|
|
814
|
+
className={`${prefixCls}__doc-thumb-ext`}
|
|
815
|
+
ellipsis
|
|
816
|
+
>
|
|
817
|
+
{getFileExtension(file.name).toUpperCase() || file.name}
|
|
818
|
+
</Typography.Text>
|
|
819
|
+
</div>
|
|
820
|
+
)
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
const isPictureCard = listType === 'picture-card'
|
|
825
|
+
const itemScopeClass = isPictureCard
|
|
826
|
+
? 'apex-picture-upload apex-trigger-sm-upload'
|
|
827
|
+
: listType === 'picture'
|
|
828
|
+
? 'apex-item-md-upload'
|
|
829
|
+
: 'apex-item-sm-upload'
|
|
830
|
+
const fileSize = getUploadFileSize(file)
|
|
831
|
+
const canPreview =
|
|
832
|
+
file.status === 'done' &&
|
|
833
|
+
(((isImageUrl ?? isImageFile)(file) && !!getFilePreviewUrl(file)) || !!onPreview)
|
|
834
|
+
const showPreviewAction =
|
|
835
|
+
canPreview && resolveFileBoolean(config.showPreviewIcon, file, true)
|
|
836
|
+
const showDownloadAction =
|
|
837
|
+
file.status === 'done' &&
|
|
838
|
+
resolveFileBoolean(config.showDownloadIcon, file, !isPictureCard)
|
|
839
|
+
const showRemoveAction = resolveFileBoolean(config.showRemoveIcon, file, !disabled)
|
|
840
|
+
const previewIcon = resolveFileNode(config.previewIcon, file, uploadViewIcon)
|
|
841
|
+
const downloadIcon = showDownloadAction
|
|
842
|
+
? resolveFileNode(config.downloadIcon, file, uploadDownloadIcon)
|
|
843
|
+
: null
|
|
844
|
+
const removeIcon = resolveFileNode(config.removeIcon, file, uploadDeleteIcon)
|
|
845
|
+
const extra = resolveFileNode(config.extra, file, null)
|
|
846
|
+
const leadingIcon =
|
|
847
|
+
listType === 'text'
|
|
848
|
+
? typeof prefixIcon === 'function'
|
|
849
|
+
? prefixIcon(file)
|
|
850
|
+
: prefixIcon
|
|
851
|
+
: undefined
|
|
852
|
+
let originNode: React.ReactElement
|
|
853
|
+
|
|
854
|
+
if (isPictureCard) {
|
|
855
|
+
originNode = (
|
|
856
|
+
<li
|
|
857
|
+
className={`apex-upload apex-image apex-picture-image ${prefixCls}__list-item ${itemScopeClass}`}
|
|
858
|
+
data-slot={`upload-${listType}-list-item`}
|
|
859
|
+
data-status={file.status}
|
|
860
|
+
data-disabled={disabled ? '' : undefined}
|
|
861
|
+
>
|
|
862
|
+
{file.status === 'uploading' ? (
|
|
863
|
+
<div
|
|
864
|
+
className={`${prefixCls}__uploading-wrapper`}
|
|
865
|
+
data-slot="upload-list-item-progress"
|
|
866
|
+
>
|
|
867
|
+
<Spin size="small" />
|
|
868
|
+
</div>
|
|
869
|
+
) : (
|
|
870
|
+
thumb
|
|
871
|
+
)}
|
|
872
|
+
<div className={`${prefixCls}__card-mask`} data-slot="upload-picture-card-mask">
|
|
873
|
+
<span className={`${prefixCls}__actions`} data-slot="upload-actions">
|
|
874
|
+
{showPreviewAction && (
|
|
875
|
+
<Button
|
|
876
|
+
type="text"
|
|
877
|
+
size="small"
|
|
878
|
+
className={`${prefixCls}__text-btn`}
|
|
879
|
+
aria-label={uploadLocale.preview}
|
|
880
|
+
icon={previewIcon}
|
|
881
|
+
onClick={() => handlePreview(file)}
|
|
882
|
+
/>
|
|
883
|
+
)}
|
|
884
|
+
{showDownloadAction && (
|
|
885
|
+
<Button
|
|
886
|
+
type="text"
|
|
887
|
+
size="small"
|
|
888
|
+
className={`${prefixCls}__text-btn`}
|
|
889
|
+
aria-label={uploadLocale.download}
|
|
890
|
+
icon={downloadIcon}
|
|
891
|
+
onClick={() => handleDownload(file)}
|
|
892
|
+
/>
|
|
893
|
+
)}
|
|
894
|
+
{file.status === 'error' && file.originFileObj && (
|
|
895
|
+
<Button
|
|
896
|
+
type="text"
|
|
897
|
+
size="small"
|
|
898
|
+
disabled={disabled}
|
|
899
|
+
className={`${prefixCls}__text-btn`}
|
|
900
|
+
data-slot="upload-list-item-retry"
|
|
901
|
+
onClick={(e) => {
|
|
902
|
+
e.stopPropagation()
|
|
903
|
+
void uploadFile(file)
|
|
904
|
+
}}
|
|
905
|
+
>
|
|
906
|
+
{uploadLocale.retry}
|
|
907
|
+
</Button>
|
|
908
|
+
)}
|
|
909
|
+
{showRemoveAction && (
|
|
910
|
+
<Button
|
|
911
|
+
type="text"
|
|
912
|
+
size="small"
|
|
913
|
+
disabled={disabled}
|
|
914
|
+
className={`${prefixCls}__text-btn`}
|
|
915
|
+
aria-label={uploadLocale.remove}
|
|
916
|
+
icon={removeIcon}
|
|
917
|
+
onClick={() => handleRemove(file)}
|
|
918
|
+
/>
|
|
919
|
+
)}
|
|
920
|
+
{extra ? <span className={`${prefixCls}__extra`}>{extra}</span> : null}
|
|
921
|
+
</span>
|
|
922
|
+
</div>
|
|
923
|
+
</li>
|
|
924
|
+
)
|
|
925
|
+
} else {
|
|
926
|
+
originNode = (
|
|
927
|
+
<li
|
|
928
|
+
className={`apex-upload ${prefixCls}__list-item ${getUploadItemTokenClass(
|
|
929
|
+
variant,
|
|
930
|
+
)} ${itemScopeClass}`}
|
|
931
|
+
data-slot={`upload-${listType}-list-item`}
|
|
932
|
+
data-status={file.status}
|
|
933
|
+
data-disabled={disabled ? '' : undefined}
|
|
934
|
+
>
|
|
935
|
+
{thumb}
|
|
936
|
+
{listType === 'text' &&
|
|
937
|
+
(leadingIcon === undefined ? (
|
|
938
|
+
<UploadFileIcon iconName={getFileFormatIconName(file)} />
|
|
939
|
+
) : leadingIcon === null || typeof leadingIcon === 'boolean' ? null : (
|
|
940
|
+
<span
|
|
941
|
+
className="apex-upload__prefix-icon"
|
|
942
|
+
data-slot="upload-list-item-icon"
|
|
943
|
+
aria-hidden
|
|
944
|
+
>
|
|
945
|
+
{leadingIcon}
|
|
946
|
+
</span>
|
|
947
|
+
))}
|
|
948
|
+
|
|
949
|
+
<Typography.Text
|
|
950
|
+
data-slot="upload-list-item-name"
|
|
951
|
+
className={`${prefixCls}__file-name`}
|
|
952
|
+
ellipsis
|
|
953
|
+
>
|
|
954
|
+
{file.name}
|
|
955
|
+
</Typography.Text>
|
|
956
|
+
|
|
957
|
+
<span className={`${prefixCls}__actions`} data-slot="upload-actions">
|
|
958
|
+
{fileSize != null && (
|
|
959
|
+
<Typography.Text
|
|
960
|
+
variant="caption"
|
|
961
|
+
className={`${prefixCls}__file-size`}
|
|
962
|
+
data-slot="upload-list-item-size"
|
|
963
|
+
>
|
|
964
|
+
{formatFileSize(fileSize)}
|
|
965
|
+
</Typography.Text>
|
|
966
|
+
)}
|
|
967
|
+
{listType === 'picture' && showPreviewAction && (
|
|
968
|
+
<Button
|
|
969
|
+
variant="icon"
|
|
970
|
+
size="small"
|
|
971
|
+
className={`${prefixCls}__text-btn`}
|
|
972
|
+
aria-label={uploadLocale.preview}
|
|
973
|
+
icon={previewIcon}
|
|
974
|
+
onClick={() => handlePreview(file)}
|
|
975
|
+
/>
|
|
976
|
+
)}
|
|
977
|
+
{file.status === 'error' && file.originFileObj && (
|
|
978
|
+
<Button
|
|
979
|
+
type="link"
|
|
980
|
+
size="small"
|
|
981
|
+
disabled={disabled}
|
|
982
|
+
className={`${prefixCls}__text-btn`}
|
|
983
|
+
data-slot="upload-list-item-retry"
|
|
984
|
+
onClick={(e) => {
|
|
985
|
+
e.stopPropagation()
|
|
986
|
+
void uploadFile(file)
|
|
987
|
+
}}
|
|
988
|
+
>
|
|
989
|
+
<Typography.Text variant="caption">{uploadLocale.retry}</Typography.Text>
|
|
990
|
+
</Button>
|
|
991
|
+
)}
|
|
992
|
+
{file.status === 'uploading' && (
|
|
993
|
+
<span className={`${prefixCls}__spin`} data-slot="upload-list-item-progress">
|
|
994
|
+
<Spin size="small" />
|
|
995
|
+
</span>
|
|
996
|
+
)}
|
|
997
|
+
{showDownloadAction && (
|
|
998
|
+
<Button
|
|
999
|
+
variant="icon"
|
|
1000
|
+
size="small"
|
|
1001
|
+
className={`${prefixCls}__text-btn`}
|
|
1002
|
+
aria-label={uploadLocale.download}
|
|
1003
|
+
icon={downloadIcon}
|
|
1004
|
+
onClick={() => handleDownload(file)}
|
|
1005
|
+
/>
|
|
1006
|
+
)}
|
|
1007
|
+
{showRemoveAction && (
|
|
1008
|
+
<Button
|
|
1009
|
+
variant="icon"
|
|
1010
|
+
size="small"
|
|
1011
|
+
disabled={disabled}
|
|
1012
|
+
className={`${prefixCls}__text-btn`}
|
|
1013
|
+
aria-label={uploadLocale.remove}
|
|
1014
|
+
icon={removeIcon}
|
|
1015
|
+
onClick={() => handleRemove(file)}
|
|
1016
|
+
/>
|
|
1017
|
+
)}
|
|
1018
|
+
{extra ? <span className={`${prefixCls}__extra`}>{extra}</span> : null}
|
|
1019
|
+
</span>
|
|
1020
|
+
</li>
|
|
1021
|
+
)
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
const renderedNode = itemRender
|
|
1025
|
+
? itemRender(originNode, file, mergedFileList, {
|
|
1026
|
+
download: () => handleDownload(file),
|
|
1027
|
+
preview: () => handlePreview(file),
|
|
1028
|
+
remove: () => handleRemove(file),
|
|
1029
|
+
})
|
|
1030
|
+
: originNode
|
|
1031
|
+
|
|
1032
|
+
return <React.Fragment key={file.uid}>{renderedNode}</React.Fragment>
|
|
1033
|
+
})
|
|
1034
|
+
: null
|
|
1035
|
+
|
|
1036
|
+
if (!items && !trailing) return null
|
|
1037
|
+
|
|
1038
|
+
return (
|
|
1039
|
+
<ul className={`${prefixCls}__list`} data-slot="upload-list">
|
|
1040
|
+
{items}
|
|
1041
|
+
{trailing}
|
|
1042
|
+
</ul>
|
|
1043
|
+
)
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
return (
|
|
1047
|
+
<div
|
|
1048
|
+
className={classes}
|
|
1049
|
+
data-slot="upload"
|
|
1050
|
+
data-list-type={listType}
|
|
1051
|
+
data-variant={variant}
|
|
1052
|
+
data-disabled={disabled ? '' : undefined}
|
|
1053
|
+
ref={ref}
|
|
1054
|
+
{...restProps}
|
|
1055
|
+
onBlur={(event) => {
|
|
1056
|
+
if (!fileDialogOpenRef.current) onBlur?.(event)
|
|
1057
|
+
}}
|
|
1058
|
+
>
|
|
1059
|
+
<input
|
|
1060
|
+
type="file"
|
|
1061
|
+
className={`${prefixCls}__input`}
|
|
1062
|
+
data-slot="upload-input"
|
|
1063
|
+
hidden
|
|
1064
|
+
aria-hidden="true"
|
|
1065
|
+
accept={acceptStr}
|
|
1066
|
+
multiple={multiple}
|
|
1067
|
+
disabled={disabled}
|
|
1068
|
+
ref={fileInputRef}
|
|
1069
|
+
onChange={handleChange}
|
|
1070
|
+
/>
|
|
1071
|
+
|
|
1072
|
+
{listType === 'picture-card' ? (
|
|
1073
|
+
renderList(
|
|
1074
|
+
showTrigger &&
|
|
1075
|
+
(effectiveMaxCount === 1 ||
|
|
1076
|
+
!effectiveMaxCount ||
|
|
1077
|
+
mergedFileList.length < effectiveMaxCount)
|
|
1078
|
+
? renderTrigger(true)
|
|
1079
|
+
: null,
|
|
1080
|
+
)
|
|
1081
|
+
) : (
|
|
1082
|
+
<>
|
|
1083
|
+
{showTrigger ? renderTrigger() : null}
|
|
1084
|
+
{renderList()}
|
|
1085
|
+
</>
|
|
1086
|
+
)}
|
|
1087
|
+
|
|
1088
|
+
<Image.PreviewGroup
|
|
1089
|
+
items={imagePreviewItems}
|
|
1090
|
+
open={previewOpen}
|
|
1091
|
+
current={previewCurrent}
|
|
1092
|
+
onOpenChange={setPreviewOpen}
|
|
1093
|
+
onCurrentChange={setPreviewCurrent}
|
|
1094
|
+
/>
|
|
1095
|
+
</div>
|
|
1096
|
+
)
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
Upload.displayName = 'ApexUpload'
|
|
1100
|
+
|
|
1101
|
+
const Dragger: React.FC<UploadDraggerProps> = (props) => {
|
|
1102
|
+
return <Upload {...props} data-type="dragger" />
|
|
1103
|
+
}
|
|
1104
|
+
Dragger.displayName = 'ApexUploadDragger'
|
|
1105
|
+
|
|
1106
|
+
Upload.Dragger = Dragger
|
|
1107
|
+
|
|
1108
|
+
export default Upload
|