taro-uno-ui 0.9.0-beta
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 +100 -0
- package/README.md +273 -0
- package/dist/js/index-6NJ3A1Dn.js +26535 -0
- package/dist/js/index-6NJ3A1Dn.js.map +1 -0
- package/dist/js/index-DFdcksbe.js +1165 -0
- package/dist/js/index-DFdcksbe.js.map +1 -0
- package/dist/js/index-DXRIkWX1.js +1148 -0
- package/dist/js/index-DXRIkWX1.js.map +1 -0
- package/dist/js/index-DffLRSro.js +26519 -0
- package/dist/js/index-DffLRSro.js.map +1 -0
- package/package.json +119 -0
- package/src/app.config.ts +55 -0
- package/src/app.scss +508 -0
- package/src/app.tsx +44 -0
- package/src/components/basic/Button/Button.styles.ts +130 -0
- package/src/components/basic/Button/Button.test.tsx +154 -0
- package/src/components/basic/Button/Button.tsx +93 -0
- package/src/components/basic/Button/Button.types.ts +45 -0
- package/src/components/basic/Button/index.tsx +6 -0
- package/src/components/basic/Divider/Divider.styles.ts +488 -0
- package/src/components/basic/Divider/Divider.test.tsx +551 -0
- package/src/components/basic/Divider/Divider.tsx +361 -0
- package/src/components/basic/Divider/Divider.types.ts +261 -0
- package/src/components/basic/Divider/index.tsx +25 -0
- package/src/components/basic/Icon/Icon.styles.ts +359 -0
- package/src/components/basic/Icon/Icon.test.tsx +357 -0
- package/src/components/basic/Icon/Icon.tsx +154 -0
- package/src/components/basic/Icon/Icon.types.ts +210 -0
- package/src/components/basic/Icon/index.tsx +22 -0
- package/src/components/basic/Text/Text.styles.ts +500 -0
- package/src/components/basic/Text/Text.test.tsx +299 -0
- package/src/components/basic/Text/Text.tsx +340 -0
- package/src/components/basic/Text/Text.types.ts +319 -0
- package/src/components/basic/Text/index.tsx +27 -0
- package/src/components/basic/Typography/Typography.styles.ts +346 -0
- package/src/components/basic/Typography/Typography.tsx +205 -0
- package/src/components/basic/Typography/Typography.types.ts +296 -0
- package/src/components/basic/Typography/index.tsx +14 -0
- package/src/components/basic/index.tsx +302 -0
- package/src/components/common/ErrorBoundary.tsx +87 -0
- package/src/components/common/LazyComponent.tsx +246 -0
- package/src/components/common/ResponsiveContainer.tsx +93 -0
- package/src/components/common/ResponsiveGrid.tsx +183 -0
- package/src/components/common/SecurityProvider.tsx +110 -0
- package/src/components/common/ThemeProvider.tsx +128 -0
- package/src/components/common/VirtualList.tsx +368 -0
- package/src/components/common/__tests__/ErrorBoundary.test.tsx +249 -0
- package/src/components/common/index.tsx +7 -0
- package/src/components/display/Avatar/Avatar.styles.ts +62 -0
- package/src/components/display/Avatar/Avatar.test.tsx +390 -0
- package/src/components/display/Avatar/Avatar.tsx +79 -0
- package/src/components/display/Avatar/Avatar.types.ts +40 -0
- package/src/components/display/Avatar/index.ts +3 -0
- package/src/components/display/Badge/Badge.tsx +42 -0
- package/src/components/display/Badge/Badge.types.ts +29 -0
- package/src/components/display/Badge/index.ts +2 -0
- package/src/components/display/Calendar/Calendar.styles.ts +255 -0
- package/src/components/display/Calendar/Calendar.test.tsx +30 -0
- package/src/components/display/Calendar/Calendar.tsx +337 -0
- package/src/components/display/Calendar/Calendar.types.ts +91 -0
- package/src/components/display/Calendar/index.ts +3 -0
- package/src/components/display/Card/Card.styles.ts +89 -0
- package/src/components/display/Card/Card.test.tsx +180 -0
- package/src/components/display/Card/Card.tsx +135 -0
- package/src/components/display/Card/Card.types.ts +55 -0
- package/src/components/display/Card/index.ts +3 -0
- package/src/components/display/Carousel/Carousel.styles.ts +206 -0
- package/src/components/display/Carousel/Carousel.tsx +295 -0
- package/src/components/display/Carousel/Carousel.types.ts +57 -0
- package/src/components/display/Carousel/index.ts +3 -0
- package/src/components/display/List/List.styles.ts +79 -0
- package/src/components/display/List/List.tsx +115 -0
- package/src/components/display/List/List.types.ts +68 -0
- package/src/components/display/List/index.ts +3 -0
- package/src/components/display/Rate/Rate.styles.ts +266 -0
- package/src/components/display/Rate/Rate.tsx +332 -0
- package/src/components/display/Rate/Rate.types.ts +111 -0
- package/src/components/display/Rate/index.ts +28 -0
- package/src/components/display/Table/Table.styles.ts +269 -0
- package/src/components/display/Table/Table.test.tsx +343 -0
- package/src/components/display/Table/Table.tsx +430 -0
- package/src/components/display/Table/Table.types.ts +255 -0
- package/src/components/display/Table/index.tsx +16 -0
- package/src/components/display/Tag/Tag.styles.ts +197 -0
- package/src/components/display/Tag/Tag.test.tsx +541 -0
- package/src/components/display/Tag/Tag.tsx +156 -0
- package/src/components/display/Tag/Tag.types.ts +49 -0
- package/src/components/display/Tag/index.ts +3 -0
- package/src/components/display/Timeline/Timeline.styles.ts +211 -0
- package/src/components/display/Timeline/Timeline.tsx +239 -0
- package/src/components/display/Timeline/Timeline.types.ts +56 -0
- package/src/components/display/Timeline/index.ts +3 -0
- package/src/components/display/index.tsx +143 -0
- package/src/components/feedback/Loading/Loading.styles.ts +117 -0
- package/src/components/feedback/Loading/Loading.test.tsx +534 -0
- package/src/components/feedback/Loading/Loading.tsx +127 -0
- package/src/components/feedback/Loading/Loading.types.ts +33 -0
- package/src/components/feedback/Loading/index.ts +9 -0
- package/src/components/feedback/Message/Message.styles.ts +41 -0
- package/src/components/feedback/Message/Message.test.tsx +234 -0
- package/src/components/feedback/Message/Message.tsx +96 -0
- package/src/components/feedback/Message/Message.types.ts +37 -0
- package/src/components/feedback/Message/index.ts +9 -0
- package/src/components/feedback/Modal/Modal.styles.ts +21 -0
- package/src/components/feedback/Modal/Modal.test.tsx +11 -0
- package/src/components/feedback/Modal/Modal.tsx +291 -0
- package/src/components/feedback/Modal/Modal.types.ts +141 -0
- package/src/components/feedback/Modal/index.tsx +11 -0
- package/src/components/feedback/Notification/Notification.styles.ts +443 -0
- package/src/components/feedback/Notification/Notification.test.tsx +401 -0
- package/src/components/feedback/Notification/Notification.tsx +370 -0
- package/src/components/feedback/Notification/Notification.types.ts +336 -0
- package/src/components/feedback/Notification/NotificationManager.tsx +376 -0
- package/src/components/feedback/Notification/index.ts +33 -0
- package/src/components/feedback/Notification/index.tsx +164 -0
- package/src/components/feedback/Progress/Progress.styles.ts +460 -0
- package/src/components/feedback/Progress/Progress.test.simple.tsx +14 -0
- package/src/components/feedback/Progress/Progress.test.tsx +312 -0
- package/src/components/feedback/Progress/Progress.tsx +508 -0
- package/src/components/feedback/Progress/Progress.types.ts +163 -0
- package/src/components/feedback/Progress/index.ts +3 -0
- package/src/components/feedback/Progress/index.tsx +38 -0
- package/src/components/feedback/Progress/utils/animation.ts +204 -0
- package/src/components/feedback/Progress/utils/index.ts +26 -0
- package/src/components/feedback/Progress/utils/progress-calculator.ts +217 -0
- package/src/components/feedback/Result/Result.styles.ts +139 -0
- package/src/components/feedback/Result/Result.tsx +233 -0
- package/src/components/feedback/Result/Result.types.ts +128 -0
- package/src/components/feedback/Result/index.tsx +3 -0
- package/src/components/feedback/Toast/Toast.styles.ts +17 -0
- package/src/components/feedback/Toast/Toast.test.tsx +10 -0
- package/src/components/feedback/Toast/Toast.tsx +372 -0
- package/src/components/feedback/Toast/Toast.types.ts +86 -0
- package/src/components/feedback/Toast/index.tsx +3 -0
- package/src/components/feedback/Tooltip/Tooltip.examples.tsx +458 -0
- package/src/components/feedback/Tooltip/Tooltip.styles.ts +346 -0
- package/src/components/feedback/Tooltip/Tooltip.test.tsx +446 -0
- package/src/components/feedback/Tooltip/Tooltip.tsx +283 -0
- package/src/components/feedback/Tooltip/Tooltip.types.ts +172 -0
- package/src/components/feedback/Tooltip/index.ts +3 -0
- package/src/components/feedback/Tooltip/index.tsx +258 -0
- package/src/components/feedback/index.tsx +164 -0
- package/src/components/form/Cascader/Cascader.styles.ts +526 -0
- package/src/components/form/Cascader/Cascader.test.tsx +77 -0
- package/src/components/form/Cascader/Cascader.tsx +585 -0
- package/src/components/form/Cascader/Cascader.types.ts +582 -0
- package/src/components/form/Cascader/hooks/index.ts +3 -0
- package/src/components/form/Cascader/hooks/useCascaderFieldNames.ts +16 -0
- package/src/components/form/Cascader/hooks/useCascaderOptions.ts +109 -0
- package/src/components/form/Cascader/hooks/useCascaderState.ts +133 -0
- package/src/components/form/Cascader/index.ts +25 -0
- package/src/components/form/Cascader/utils/formatDisplayValue.ts +19 -0
- package/src/components/form/Cascader/utils/index.ts +1 -0
- package/src/components/form/Checkbox/Checkbox.styles.ts +608 -0
- package/src/components/form/Checkbox/Checkbox.test.tsx +1140 -0
- package/src/components/form/Checkbox/Checkbox.tsx +496 -0
- package/src/components/form/Checkbox/Checkbox.types.ts +472 -0
- package/src/components/form/Checkbox/CheckboxGroup.tsx +444 -0
- package/src/components/form/Checkbox/index.tsx +27 -0
- package/src/components/form/DatePicker/DatePicker.styles.ts +393 -0
- package/src/components/form/DatePicker/DatePicker.test.tsx +407 -0
- package/src/components/form/DatePicker/DatePicker.tsx +360 -0
- package/src/components/form/DatePicker/DatePicker.types.ts +247 -0
- package/src/components/form/DatePicker/index.tsx +15 -0
- package/src/components/form/Form/Form.styles.ts +357 -0
- package/src/components/form/Form/Form.test.tsx +122 -0
- package/src/components/form/Form/Form.tsx +695 -0
- package/src/components/form/Form/Form.types.ts +407 -0
- package/src/components/form/Form/index.tsx +31 -0
- package/src/components/form/Input/Input.enhanced.tsx +732 -0
- package/src/components/form/Input/Input.styles.ts +438 -0
- package/src/components/form/Input/Input.test.tsx +494 -0
- package/src/components/form/Input/Input.tsx +541 -0
- package/src/components/form/Input/Input.types.ts +285 -0
- package/src/components/form/Input/index.tsx +26 -0
- package/src/components/form/InputNumber/InputNumber.styles.ts +665 -0
- package/src/components/form/InputNumber/InputNumber.tsx +370 -0
- package/src/components/form/InputNumber/InputNumber.types.ts +318 -0
- package/src/components/form/InputNumber/components/InputNumberClearButton.tsx +32 -0
- package/src/components/form/InputNumber/components/InputNumberControls.tsx +42 -0
- package/src/components/form/InputNumber/components/index.ts +2 -0
- package/src/components/form/InputNumber/hooks/index.ts +4 -0
- package/src/components/form/InputNumber/hooks/useInputNumberState.ts +315 -0
- package/src/components/form/InputNumber/hooks/useInputNumberValidation.ts +147 -0
- package/src/components/form/InputNumber/index.ts +25 -0
- package/src/components/form/Radio/Radio.styles.ts +458 -0
- package/src/components/form/Radio/Radio.test.tsx +547 -0
- package/src/components/form/Radio/Radio.tsx +283 -0
- package/src/components/form/Radio/Radio.types.ts +410 -0
- package/src/components/form/Radio/index.tsx +21 -0
- package/src/components/form/Select/Select.styles.ts +514 -0
- package/src/components/form/Select/Select.test.tsx +648 -0
- package/src/components/form/Select/Select.tsx +474 -0
- package/src/components/form/Select/Select.types.ts +428 -0
- package/src/components/form/Select/index.tsx +30 -0
- package/src/components/form/Slider/Slider.styles.ts +139 -0
- package/src/components/form/Slider/Slider.test.tsx +553 -0
- package/src/components/form/Slider/Slider.tsx +326 -0
- package/src/components/form/Slider/Slider.types.ts +108 -0
- package/src/components/form/Slider/index.tsx +10 -0
- package/src/components/form/Switch/Switch.styles.ts +540 -0
- package/src/components/form/Switch/Switch.test.tsx +345 -0
- package/src/components/form/Switch/Switch.tsx +464 -0
- package/src/components/form/Switch/Switch.types.ts +386 -0
- package/src/components/form/Switch/index.tsx +26 -0
- package/src/components/form/Textarea/Textarea.styles.ts +592 -0
- package/src/components/form/Textarea/Textarea.test.tsx +1075 -0
- package/src/components/form/Textarea/Textarea.tsx +602 -0
- package/src/components/form/Textarea/Textarea.types.ts +371 -0
- package/src/components/form/Textarea/index.tsx +26 -0
- package/src/components/form/TimePicker/TimePicker.styles.ts +438 -0
- package/src/components/form/TimePicker/TimePicker.test.tsx +306 -0
- package/src/components/form/TimePicker/TimePicker.tsx +228 -0
- package/src/components/form/TimePicker/TimePicker.types.ts +385 -0
- package/src/components/form/TimePicker/index.ts +21 -0
- package/src/components/form/Transfer/Transfer.styles.ts +502 -0
- package/src/components/form/Transfer/Transfer.test.tsx +316 -0
- package/src/components/form/Transfer/Transfer.tsx +402 -0
- package/src/components/form/Transfer/Transfer.types.ts +557 -0
- package/src/components/form/Transfer/components/TransferItem.tsx +101 -0
- package/src/components/form/Transfer/components/TransferList.tsx +285 -0
- package/src/components/form/Transfer/components/TransferOperations.tsx +84 -0
- package/src/components/form/Transfer/components/TransferPagination.tsx +135 -0
- package/src/components/form/Transfer/components/TransferSearch.tsx +88 -0
- package/src/components/form/Transfer/components/index.ts +6 -0
- package/src/components/form/Transfer/hooks/index.ts +3 -0
- package/src/components/form/Transfer/hooks/useTransferData.ts +192 -0
- package/src/components/form/Transfer/hooks/useTransferState.ts +114 -0
- package/src/components/form/Transfer/index.ts +33 -0
- package/src/components/form/Upload/Upload.styles.ts +145 -0
- package/src/components/form/Upload/Upload.test.tsx +10 -0
- package/src/components/form/Upload/Upload.tsx +451 -0
- package/src/components/form/Upload/Upload.types.ts +200 -0
- package/src/components/form/Upload/index.tsx +12 -0
- package/src/components/form/index.tsx +121 -0
- package/src/components/index.tsx +146 -0
- package/src/components/layout/Affix/Affix.styles.ts +37 -0
- package/src/components/layout/Affix/Affix.test.tsx +10 -0
- package/src/components/layout/Affix/Affix.tsx +91 -0
- package/src/components/layout/Affix/Affix.types.ts +29 -0
- package/src/components/layout/Affix/index.tsx +3 -0
- package/src/components/layout/Col/Col.styles.ts +185 -0
- package/src/components/layout/Col/Col.test.tsx +535 -0
- package/src/components/layout/Col/Col.tsx +115 -0
- package/src/components/layout/Col/Col.types.ts +59 -0
- package/src/components/layout/Col/index.tsx +3 -0
- package/src/components/layout/Container/Container.styles.ts +161 -0
- package/src/components/layout/Container/Container.test.tsx +380 -0
- package/src/components/layout/Container/Container.tsx +132 -0
- package/src/components/layout/Container/Container.types.ts +63 -0
- package/src/components/layout/Container/index.tsx +3 -0
- package/src/components/layout/Grid/Grid.styles.ts +183 -0
- package/src/components/layout/Grid/Grid.test.tsx +637 -0
- package/src/components/layout/Grid/Grid.tsx +173 -0
- package/src/components/layout/Grid/Grid.types.ts +78 -0
- package/src/components/layout/Grid/index.tsx +3 -0
- package/src/components/layout/Layout/Content.tsx +38 -0
- package/src/components/layout/Layout/Footer.tsx +38 -0
- package/src/components/layout/Layout/Header.tsx +38 -0
- package/src/components/layout/Layout/Layout.styles.ts +84 -0
- package/src/components/layout/Layout/Layout.test.tsx +10 -0
- package/src/components/layout/Layout/Layout.tsx +39 -0
- package/src/components/layout/Layout/Layout.types.ts +58 -0
- package/src/components/layout/Layout/Sider.tsx +56 -0
- package/src/components/layout/Layout/index.tsx +8 -0
- package/src/components/layout/Row/Row.styles.ts +159 -0
- package/src/components/layout/Row/Row.test.tsx +467 -0
- package/src/components/layout/Row/Row.tsx +139 -0
- package/src/components/layout/Row/Row.types.ts +60 -0
- package/src/components/layout/Row/index.tsx +3 -0
- package/src/components/layout/Space/Space.styles.ts +255 -0
- package/src/components/layout/Space/Space.test.tsx +682 -0
- package/src/components/layout/Space/Space.tsx +211 -0
- package/src/components/layout/Space/Space.types.ts +92 -0
- package/src/components/layout/Space/index.tsx +12 -0
- package/src/components/layout/index.tsx +68 -0
- package/src/components/navigation/Menu/Menu.styles.ts +779 -0
- package/src/components/navigation/Menu/Menu.tsx +355 -0
- package/src/components/navigation/Menu/Menu.types.ts +231 -0
- package/src/components/navigation/Menu/Menu.utils.ts +187 -0
- package/src/components/navigation/Menu/MenuItem.tsx +126 -0
- package/src/components/navigation/Menu/SubMenu.tsx +148 -0
- package/src/components/navigation/Menu/__tests__/Menu.test.tsx +687 -0
- package/src/components/navigation/Menu/index.tsx +124 -0
- package/src/components/navigation/NavBar/NavBar.styles.ts +129 -0
- package/src/components/navigation/NavBar/NavBar.test.tsx +287 -0
- package/src/components/navigation/NavBar/NavBar.tsx +231 -0
- package/src/components/navigation/NavBar/NavBar.types.ts +54 -0
- package/src/components/navigation/NavBar/index.tsx +3 -0
- package/src/components/navigation/Pagination/Pagination.styles.ts +187 -0
- package/src/components/navigation/Pagination/Pagination.test.tsx +673 -0
- package/src/components/navigation/Pagination/Pagination.tsx +395 -0
- package/src/components/navigation/Pagination/Pagination.types.ts +86 -0
- package/src/components/navigation/Pagination/index.ts +18 -0
- package/src/components/navigation/Pagination/index.tsx +9 -0
- package/src/components/navigation/Steps/Step.tsx +56 -0
- package/src/components/navigation/Steps/Steps.styles.ts +154 -0
- package/src/components/navigation/Steps/Steps.test.tsx +12 -0
- package/src/components/navigation/Steps/Steps.tsx +113 -0
- package/src/components/navigation/Steps/Steps.types.ts +47 -0
- package/src/components/navigation/Steps/index.tsx +3 -0
- package/src/components/navigation/Tabs/Tabs.styles.ts +199 -0
- package/src/components/navigation/Tabs/Tabs.test.tsx +661 -0
- package/src/components/navigation/Tabs/Tabs.tsx +253 -0
- package/src/components/navigation/Tabs/Tabs.types.ts +114 -0
- package/src/components/navigation/Tabs/index.tsx +3 -0
- package/src/components/navigation/Tree/Tree.styles.ts +553 -0
- package/src/components/navigation/Tree/Tree.test.basic.tsx +7 -0
- package/src/components/navigation/Tree/Tree.test.functional.tsx +496 -0
- package/src/components/navigation/Tree/Tree.test.import.check.tsx +6 -0
- package/src/components/navigation/Tree/Tree.test.import.tsx +6 -0
- package/src/components/navigation/Tree/Tree.test.minimal.tsx +5 -0
- package/src/components/navigation/Tree/Tree.test.simple.tsx +30 -0
- package/src/components/navigation/Tree/Tree.test.tsx +908 -0
- package/src/components/navigation/Tree/Tree.test.working.tsx +673 -0
- package/src/components/navigation/Tree/Tree.tsx +600 -0
- package/src/components/navigation/Tree/Tree.types.ts +909 -0
- package/src/components/navigation/Tree/Tree.utils.ts +452 -0
- package/src/components/navigation/Tree/index.ts +33 -0
- package/src/components/navigation/Tree/index.tsx +23 -0
- package/src/components/navigation/index.tsx +83 -0
- package/src/constants/index.ts +785 -0
- package/src/hooks/index.ts +110 -0
- package/src/hooks/types.ts +10 -0
- package/src/hooks/useAsync.ts +65 -0
- package/src/hooks/useEventHandling.ts +444 -0
- package/src/hooks/useLifecycle.ts +399 -0
- package/src/hooks/usePerformance.ts +441 -0
- package/src/hooks/usePerformanceMonitor.ts +348 -0
- package/src/hooks/usePlatform.ts +62 -0
- package/src/hooks/useRequest.test.ts +11 -0
- package/src/hooks/useRequest.ts +135 -0
- package/src/hooks/useStateManagement.ts +300 -0
- package/src/hooks/useStyle.ts +537 -0
- package/src/hooks/useTheme.ts +347 -0
- package/src/hooks/useVirtualScroll.ts +331 -0
- package/src/index.ts +298 -0
- package/src/platform/index.ts +1188 -0
- package/src/providers/AppProvider.test.tsx +63 -0
- package/src/providers/AppProvider.tsx +155 -0
- package/src/providers/index.ts +1 -0
- package/src/theme/ThemeProvider.tsx +283 -0
- package/src/theme/ThemeProvider.types.ts +26 -0
- package/src/theme/animations.tsx +660 -0
- package/src/theme/defaults.ts +188 -0
- package/src/theme/design-system.ts +562 -0
- package/src/theme/design-tokens.ts +1136 -0
- package/src/theme/generated/dark-theme.scss +120 -0
- package/src/theme/generated/tokens.css +441 -0
- package/src/theme/generated/tokens.scss +320 -0
- package/src/theme/index.ts +120 -0
- package/src/theme/responsive.tsx +193 -0
- package/src/theme/styles/mixins.scss +612 -0
- package/src/theme/styles/variables.scss +295 -0
- package/src/theme/styles.ts +403 -0
- package/src/theme/tokens/colors.ts +256 -0
- package/src/theme/tokens/effects.ts +260 -0
- package/src/theme/tokens/index.ts +217 -0
- package/src/theme/tokens/spacing.ts +137 -0
- package/src/theme/tokens/typography.ts +186 -0
- package/src/theme/types.ts +188 -0
- package/src/theme/useThemeUtils.ts +313 -0
- package/src/theme/utils.ts +501 -0
- package/src/theme/variables.ts +583 -0
- package/src/types/accessibility.ts +51 -0
- package/src/types/button.ts +562 -0
- package/src/types/component-props.ts +317 -0
- package/src/types/env.d.ts +20 -0
- package/src/types/index.ts +427 -0
- package/src/types/modules.d.ts +40 -0
- package/src/types/standardized-components.ts +544 -0
- package/src/types/taro-adapter.d.ts +174 -0
- package/src/types/taro-components.d.ts +73 -0
- package/src/types/utils.ts +410 -0
- package/src/utils/__tests__/inputValidator.test.ts +338 -0
- package/src/utils/__tests__/responsiveUtils.test.ts +310 -0
- package/src/utils/__tests__/xssProtection.test.ts +268 -0
- package/src/utils/cache.ts +83 -0
- package/src/utils/createNamespace.ts +24 -0
- package/src/utils/environment.ts +95 -0
- package/src/utils/error-handler.ts +88 -0
- package/src/utils/errorLogger.ts +197 -0
- package/src/utils/formatUtils.ts +444 -0
- package/src/utils/index.ts +115 -0
- package/src/utils/inputValidator.ts +261 -0
- package/src/utils/network/http-client.test.ts +18 -0
- package/src/utils/network/http-client.ts +151 -0
- package/src/utils/performance/performance.ts +850 -0
- package/src/utils/responsiveUtils.ts +357 -0
- package/src/utils/rtl-support.ts +344 -0
- package/src/utils/security/api-security.ts +386 -0
- package/src/utils/security/xss-protection.ts +69 -0
- package/src/utils/securityHeaders.ts +314 -0
- package/src/utils/typeHelpers.ts +16 -0
- package/src/utils/types/dataProcessing.ts +543 -0
- package/src/utils/types/typeHelpers.ts +187 -0
- package/src/utils/xssProtection.ts +420 -0
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import React, { forwardRef, useRef, useEffect, useState, useCallback } from 'react';
|
|
2
|
+
import { View, Text } from '@tarojs/components';
|
|
3
|
+
import {
|
|
4
|
+
NotificationProps,
|
|
5
|
+
NotificationRef,
|
|
6
|
+
NotificationType,
|
|
7
|
+
DEFAULT_NOTIFICATION_CONFIG
|
|
8
|
+
} from './Notification.types';
|
|
9
|
+
import { notificationStyles, notificationStyleHelpers } from './Notification.styles';
|
|
10
|
+
import { cn } from '../../../utils';
|
|
11
|
+
|
|
12
|
+
export const Notification = forwardRef<NotificationRef, NotificationProps>((props, ref) => {
|
|
13
|
+
const {
|
|
14
|
+
type = 'info',
|
|
15
|
+
title,
|
|
16
|
+
content,
|
|
17
|
+
icon,
|
|
18
|
+
closable = DEFAULT_NOTIFICATION_CONFIG.defaultClosable,
|
|
19
|
+
duration = DEFAULT_NOTIFICATION_CONFIG.defaultDuration,
|
|
20
|
+
placement = DEFAULT_NOTIFICATION_CONFIG.defaultPlacement,
|
|
21
|
+
className,
|
|
22
|
+
style,
|
|
23
|
+
onClose,
|
|
24
|
+
onClick,
|
|
25
|
+
showClose = DEFAULT_NOTIFICATION_CONFIG.defaultShowClose,
|
|
26
|
+
showIcon = DEFAULT_NOTIFICATION_CONFIG.defaultShowIcon,
|
|
27
|
+
autoClose = DEFAULT_NOTIFICATION_CONFIG.defaultAutoClose,
|
|
28
|
+
animation = DEFAULT_NOTIFICATION_CONFIG.defaultAnimation,
|
|
29
|
+
...rest
|
|
30
|
+
} = props;
|
|
31
|
+
|
|
32
|
+
// 错误状态管理
|
|
33
|
+
const [hasError, setHasError] = useState(false);
|
|
34
|
+
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
|
35
|
+
|
|
36
|
+
// 错误边界处理
|
|
37
|
+
const handleError = useCallback((error: Error, context: string) => {
|
|
38
|
+
console.error(`Notification error in ${context}:`, error);
|
|
39
|
+
setHasError(true);
|
|
40
|
+
setErrorMessage(error.message);
|
|
41
|
+
|
|
42
|
+
// 自动关闭错误的通知
|
|
43
|
+
if (timerRef.current) {
|
|
44
|
+
clearTimeout(timerRef.current);
|
|
45
|
+
timerRef.current = null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 延迟关闭以显示错误状态
|
|
49
|
+
timerRef.current = setTimeout(() => {
|
|
50
|
+
setVisible(false);
|
|
51
|
+
setIsClosing(true);
|
|
52
|
+
onClose?.();
|
|
53
|
+
}, 3000) as unknown as number;
|
|
54
|
+
}, [onClose]);
|
|
55
|
+
|
|
56
|
+
// 状态管理
|
|
57
|
+
const [visible, setVisible] = useState(true);
|
|
58
|
+
const [closeHovered, setCloseHovered] = useState(false);
|
|
59
|
+
const [isClosing, setIsClosing] = useState(false);
|
|
60
|
+
const [paused, setPaused] = useState(false);
|
|
61
|
+
|
|
62
|
+
// 定时器引用
|
|
63
|
+
const timerRef = useRef<number | null>(null);
|
|
64
|
+
const startTimeRef = useRef<number>(0);
|
|
65
|
+
const remainingTimeRef = useRef<number>(duration);
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
// 处理自动关闭
|
|
69
|
+
const handleAutoClose = useCallback(() => {
|
|
70
|
+
try {
|
|
71
|
+
if (!autoClose || duration <= 0 || paused) return;
|
|
72
|
+
|
|
73
|
+
if (timerRef.current) {
|
|
74
|
+
clearTimeout(timerRef.current);
|
|
75
|
+
timerRef.current = null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 使用更安全的定时器处理
|
|
79
|
+
const timeoutId = setTimeout(() => {
|
|
80
|
+
try {
|
|
81
|
+
setVisible(false);
|
|
82
|
+
setIsClosing(true);
|
|
83
|
+
onClose?.();
|
|
84
|
+
} catch (error) {
|
|
85
|
+
handleError(error as Error, 'autoCloseTimeout');
|
|
86
|
+
}
|
|
87
|
+
}, remainingTimeRef.current);
|
|
88
|
+
|
|
89
|
+
timerRef.current = timeoutId as unknown as number;
|
|
90
|
+
startTimeRef.current = Date.now();
|
|
91
|
+
} catch (error) {
|
|
92
|
+
handleError(error as Error, 'handleAutoClose');
|
|
93
|
+
}
|
|
94
|
+
}, [autoClose, duration, paused, onClose, remainingTimeRef, handleError]);
|
|
95
|
+
|
|
96
|
+
// 暂停自动关闭
|
|
97
|
+
const pauseProgress = useCallback(() => {
|
|
98
|
+
try {
|
|
99
|
+
if (timerRef.current) {
|
|
100
|
+
clearTimeout(timerRef.current);
|
|
101
|
+
const elapsed = Date.now() - startTimeRef.current;
|
|
102
|
+
remainingTimeRef.current = Math.max(0, remainingTimeRef.current - elapsed);
|
|
103
|
+
setPaused(true);
|
|
104
|
+
timerRef.current = null;
|
|
105
|
+
}
|
|
106
|
+
} catch (error) {
|
|
107
|
+
handleError(error as Error, 'pauseProgress');
|
|
108
|
+
}
|
|
109
|
+
}, [handleError]);
|
|
110
|
+
|
|
111
|
+
// 恢复自动关闭
|
|
112
|
+
const resumeProgress = useCallback(() => {
|
|
113
|
+
try {
|
|
114
|
+
setPaused(false);
|
|
115
|
+
handleAutoClose();
|
|
116
|
+
} catch (error) {
|
|
117
|
+
handleError(error as Error, 'resumeProgress');
|
|
118
|
+
}
|
|
119
|
+
}, [handleAutoClose, handleError]);
|
|
120
|
+
|
|
121
|
+
// 暴露方法给ref
|
|
122
|
+
React.useImperativeHandle(ref, () => ({
|
|
123
|
+
hide: () => {
|
|
124
|
+
setVisible(false);
|
|
125
|
+
setIsClosing(true);
|
|
126
|
+
if (timerRef.current) {
|
|
127
|
+
clearTimeout(timerRef.current);
|
|
128
|
+
timerRef.current = null;
|
|
129
|
+
}
|
|
130
|
+
onClose?.();
|
|
131
|
+
return true;
|
|
132
|
+
},
|
|
133
|
+
show: () => {
|
|
134
|
+
setVisible(true);
|
|
135
|
+
setIsClosing(false);
|
|
136
|
+
remainingTimeRef.current = duration;
|
|
137
|
+
handleAutoClose();
|
|
138
|
+
return true;
|
|
139
|
+
},
|
|
140
|
+
update: (newProps: Partial<NotificationProps>) => {
|
|
141
|
+
// 这里可以实现更新通知内容的逻辑
|
|
142
|
+
console.log('Update notification:', newProps);
|
|
143
|
+
return true;
|
|
144
|
+
},
|
|
145
|
+
pauseProgress,
|
|
146
|
+
resumeProgress,
|
|
147
|
+
getState: () => ({
|
|
148
|
+
visible,
|
|
149
|
+
paused,
|
|
150
|
+
closing: isClosing,
|
|
151
|
+
}),
|
|
152
|
+
}));
|
|
153
|
+
|
|
154
|
+
// 自动关闭效果
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
handleAutoClose();
|
|
157
|
+
|
|
158
|
+
return () => {
|
|
159
|
+
// 清理定时器
|
|
160
|
+
if (timerRef.current) {
|
|
161
|
+
clearTimeout(timerRef.current);
|
|
162
|
+
timerRef.current = null;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}, [handleAutoClose]);
|
|
166
|
+
|
|
167
|
+
// 组件卸载时的清理
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
return () => {
|
|
170
|
+
// 确保所有定时器都被清理
|
|
171
|
+
if (timerRef.current) {
|
|
172
|
+
clearTimeout(timerRef.current);
|
|
173
|
+
timerRef.current = null;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// 清理状态引用
|
|
177
|
+
setHasError(false);
|
|
178
|
+
setErrorMessage(null);
|
|
179
|
+
};
|
|
180
|
+
}, []);
|
|
181
|
+
|
|
182
|
+
// 关闭处理
|
|
183
|
+
const handleClose = useCallback((e?: any) => {
|
|
184
|
+
e?.stopPropagation();
|
|
185
|
+
setVisible(false);
|
|
186
|
+
setIsClosing(true);
|
|
187
|
+
if (timerRef.current) {
|
|
188
|
+
clearTimeout(timerRef.current);
|
|
189
|
+
timerRef.current = null;
|
|
190
|
+
}
|
|
191
|
+
onClose?.();
|
|
192
|
+
}, [onClose]);
|
|
193
|
+
|
|
194
|
+
// 点击处理
|
|
195
|
+
const handleClick = useCallback((e?: any) => {
|
|
196
|
+
try {
|
|
197
|
+
onClick?.(e);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
handleError(error as Error, 'handleClick');
|
|
200
|
+
}
|
|
201
|
+
}, [onClick, handleError]);
|
|
202
|
+
|
|
203
|
+
// 触摸开始处理(替代鼠标悬停)
|
|
204
|
+
const handleTouchStart = useCallback((_e?: any) => {
|
|
205
|
+
try {
|
|
206
|
+
setCloseHovered(true);
|
|
207
|
+
if (autoClose) {
|
|
208
|
+
pauseProgress();
|
|
209
|
+
}
|
|
210
|
+
} catch (error) {
|
|
211
|
+
handleError(error as Error, 'handleTouchStart');
|
|
212
|
+
}
|
|
213
|
+
}, [autoClose, pauseProgress, handleError]);
|
|
214
|
+
|
|
215
|
+
// 触摸结束处理(替代鼠标离开)
|
|
216
|
+
const handleTouchEnd = useCallback((_e?: any) => {
|
|
217
|
+
try {
|
|
218
|
+
setCloseHovered(false);
|
|
219
|
+
if (autoClose && paused) {
|
|
220
|
+
resumeProgress();
|
|
221
|
+
}
|
|
222
|
+
} catch (error) {
|
|
223
|
+
handleError(error as Error, 'handleTouchEnd');
|
|
224
|
+
}
|
|
225
|
+
}, [autoClose, paused, resumeProgress, handleError]);
|
|
226
|
+
|
|
227
|
+
// 渲染图标
|
|
228
|
+
const renderIcon = useCallback(() => {
|
|
229
|
+
try {
|
|
230
|
+
if (!showIcon) return null;
|
|
231
|
+
|
|
232
|
+
if (icon) {
|
|
233
|
+
return (
|
|
234
|
+
<View
|
|
235
|
+
className={notificationStyles['icon']}
|
|
236
|
+
>
|
|
237
|
+
{icon}
|
|
238
|
+
</View>
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const defaultIcons: Record<NotificationType, string> = {
|
|
243
|
+
success: '✓',
|
|
244
|
+
error: '✕',
|
|
245
|
+
warning: '⚠',
|
|
246
|
+
info: 'ℹ',
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
return (
|
|
250
|
+
<View
|
|
251
|
+
className={notificationStyles['icon']}
|
|
252
|
+
>
|
|
253
|
+
<Text
|
|
254
|
+
className={notificationStyles['iconText']}
|
|
255
|
+
>
|
|
256
|
+
{defaultIcons[type]}
|
|
257
|
+
</Text>
|
|
258
|
+
</View>
|
|
259
|
+
);
|
|
260
|
+
} catch (error) {
|
|
261
|
+
handleError(error as Error, 'renderIcon');
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
}, [showIcon, icon, type, handleError]);
|
|
265
|
+
|
|
266
|
+
// 计算容器样式
|
|
267
|
+
const containerStyle = React.useMemo(() => {
|
|
268
|
+
try {
|
|
269
|
+
const baseStyle = notificationStyleHelpers.getBaseStyle(placement, style);
|
|
270
|
+
const typeStyle = notificationStyleHelpers.getTypeStyle(type);
|
|
271
|
+
const animationStyle = notificationStyleHelpers.getAnimationStyle(animation, visible);
|
|
272
|
+
|
|
273
|
+
return {
|
|
274
|
+
...baseStyle,
|
|
275
|
+
...typeStyle,
|
|
276
|
+
...animationStyle,
|
|
277
|
+
};
|
|
278
|
+
} catch (error) {
|
|
279
|
+
handleError(error as Error, 'containerStyle');
|
|
280
|
+
return notificationStyleHelpers.getBaseStyle(placement, style);
|
|
281
|
+
}
|
|
282
|
+
}, [placement, style, type, animation, visible, handleError]);
|
|
283
|
+
|
|
284
|
+
// 计算类名
|
|
285
|
+
const containerClassName = React.useMemo(() => {
|
|
286
|
+
try {
|
|
287
|
+
const classes = [
|
|
288
|
+
'taro-uno-notification',
|
|
289
|
+
`taro-uno-notification-${type}`,
|
|
290
|
+
`taro-uno-notification-${placement}`,
|
|
291
|
+
isClosing && 'taro-uno-notification-closing',
|
|
292
|
+
closeHovered && 'taro-uno-notification-hovered',
|
|
293
|
+
paused && 'taro-uno-notification-paused',
|
|
294
|
+
hasError && 'taro-uno-notification-error',
|
|
295
|
+
className
|
|
296
|
+
];
|
|
297
|
+
return cn(...classes);
|
|
298
|
+
} catch (error) {
|
|
299
|
+
handleError(error as Error, 'containerClassName');
|
|
300
|
+
return 'taro-uno-notification taro-uno-notification-error';
|
|
301
|
+
}
|
|
302
|
+
}, [type, placement, isClosing, closeHovered, paused, hasError, className, handleError]);
|
|
303
|
+
|
|
304
|
+
// 如果不可见,返回null
|
|
305
|
+
if (!visible) return null;
|
|
306
|
+
|
|
307
|
+
return (
|
|
308
|
+
<View
|
|
309
|
+
style={containerStyle}
|
|
310
|
+
className={containerClassName}
|
|
311
|
+
onClick={handleClick}
|
|
312
|
+
onTouchStart={handleTouchStart}
|
|
313
|
+
onTouchEnd={handleTouchEnd}
|
|
314
|
+
{...rest}
|
|
315
|
+
>
|
|
316
|
+
{renderIcon()}
|
|
317
|
+
|
|
318
|
+
<View
|
|
319
|
+
className={notificationStyles['content']}
|
|
320
|
+
>
|
|
321
|
+
{hasError ? (
|
|
322
|
+
<Text
|
|
323
|
+
className={notificationStyles['title']}
|
|
324
|
+
>
|
|
325
|
+
通知错误
|
|
326
|
+
</Text>
|
|
327
|
+
) : title && (
|
|
328
|
+
<Text
|
|
329
|
+
className={notificationStyles['title']}
|
|
330
|
+
>
|
|
331
|
+
{title}
|
|
332
|
+
</Text>
|
|
333
|
+
)}
|
|
334
|
+
{hasError ? (
|
|
335
|
+
<Text
|
|
336
|
+
className={notificationStyles['text']}
|
|
337
|
+
>
|
|
338
|
+
{errorMessage || '通知显示异常'}
|
|
339
|
+
</Text>
|
|
340
|
+
) : content && (
|
|
341
|
+
<Text
|
|
342
|
+
className={notificationStyles['text']}
|
|
343
|
+
>
|
|
344
|
+
{content}
|
|
345
|
+
</Text>
|
|
346
|
+
)}
|
|
347
|
+
</View>
|
|
348
|
+
|
|
349
|
+
{showClose && closable && (
|
|
350
|
+
<View
|
|
351
|
+
className={cn(
|
|
352
|
+
notificationStyles['close'],
|
|
353
|
+
closeHovered && notificationStyles['closeHover']
|
|
354
|
+
)}
|
|
355
|
+
onClick={handleClose}
|
|
356
|
+
>
|
|
357
|
+
<Text
|
|
358
|
+
className={notificationStyles['closeIcon']}
|
|
359
|
+
>
|
|
360
|
+
✕
|
|
361
|
+
</Text>
|
|
362
|
+
</View>
|
|
363
|
+
)}
|
|
364
|
+
</View>
|
|
365
|
+
);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
Notification.displayName = 'Notification';
|
|
369
|
+
|
|
370
|
+
export default Notification;
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ITouchEvent } from '@tarojs/components';
|
|
3
|
+
|
|
4
|
+
/** 通知类型 */
|
|
5
|
+
export type NotificationType = 'success' | 'error' | 'warning' | 'info';
|
|
6
|
+
|
|
7
|
+
/** 通知位置 */
|
|
8
|
+
export type NotificationPlacement = 'topRight' | 'topLeft' | 'bottomRight' | 'bottomLeft' | 'top' | 'bottom';
|
|
9
|
+
|
|
10
|
+
/** 通知动画类型 */
|
|
11
|
+
export type NotificationAnimation = 'fade' | 'slide' | 'scale' | 'bounce' | 'none';
|
|
12
|
+
|
|
13
|
+
/** 通知项接口 */
|
|
14
|
+
export interface NotificationItem {
|
|
15
|
+
/** 通知唯一标识 */
|
|
16
|
+
key: string;
|
|
17
|
+
/** 通知类型 */
|
|
18
|
+
type?: NotificationType;
|
|
19
|
+
/** 通知标题 */
|
|
20
|
+
title?: React.ReactNode;
|
|
21
|
+
/** 通知内容 */
|
|
22
|
+
content?: React.ReactNode;
|
|
23
|
+
/** 自定义图标 */
|
|
24
|
+
icon?: React.ReactNode;
|
|
25
|
+
/** 是否可关闭 */
|
|
26
|
+
closable?: boolean;
|
|
27
|
+
/** 显示时长(毫秒) */
|
|
28
|
+
duration?: number;
|
|
29
|
+
/** 通知位置 */
|
|
30
|
+
placement?: NotificationPlacement;
|
|
31
|
+
/** 自定义类名 */
|
|
32
|
+
className?: string;
|
|
33
|
+
/** 自定义样式 */
|
|
34
|
+
style?: React.CSSProperties;
|
|
35
|
+
/** 关闭回调 */
|
|
36
|
+
onClose?: (_key: string) => void;
|
|
37
|
+
/** 点击回调 */
|
|
38
|
+
onClick?: () => void;
|
|
39
|
+
/** 显示关闭按钮 */
|
|
40
|
+
showClose?: boolean;
|
|
41
|
+
/** 显示图标 */
|
|
42
|
+
showIcon?: boolean;
|
|
43
|
+
/** 动画类型 */
|
|
44
|
+
animation?: NotificationAnimation;
|
|
45
|
+
/** 创建时间 */
|
|
46
|
+
createdAt: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 通知组件属性 */
|
|
50
|
+
export interface NotificationProps {
|
|
51
|
+
/** 通知类型 */
|
|
52
|
+
type?: NotificationType;
|
|
53
|
+
/** 通知标题 */
|
|
54
|
+
title?: React.ReactNode;
|
|
55
|
+
/** 通知内容 */
|
|
56
|
+
content?: React.ReactNode;
|
|
57
|
+
/** 自定义图标 */
|
|
58
|
+
icon?: React.ReactNode;
|
|
59
|
+
/** 是否可关闭 */
|
|
60
|
+
closable?: boolean;
|
|
61
|
+
/** 显示时长(毫秒) */
|
|
62
|
+
duration?: number;
|
|
63
|
+
/** 通知位置 */
|
|
64
|
+
placement?: NotificationPlacement;
|
|
65
|
+
/** 自定义类名 */
|
|
66
|
+
className?: string;
|
|
67
|
+
/** 自定义样式 */
|
|
68
|
+
style?: React.CSSProperties;
|
|
69
|
+
/** 关闭回调 */
|
|
70
|
+
onClose?: () => void;
|
|
71
|
+
/** 点击回调 */
|
|
72
|
+
onClick?: (event?: ITouchEvent) => void;
|
|
73
|
+
/** 显示关闭按钮 */
|
|
74
|
+
showClose?: boolean;
|
|
75
|
+
/** 显示图标 */
|
|
76
|
+
showIcon?: boolean;
|
|
77
|
+
/** 动画类型 */
|
|
78
|
+
animation?: NotificationAnimation;
|
|
79
|
+
/** 是否自动关闭 */
|
|
80
|
+
autoClose?: boolean;
|
|
81
|
+
/** 是否可拖拽 */
|
|
82
|
+
draggable?: boolean;
|
|
83
|
+
/** 拖拽阈值 */
|
|
84
|
+
dragThreshold?: number;
|
|
85
|
+
/** 堆叠索引 */
|
|
86
|
+
stackIndex?: number;
|
|
87
|
+
/** 悬停状态 */
|
|
88
|
+
hovered?: boolean;
|
|
89
|
+
/** 是否正在关闭 */
|
|
90
|
+
isClosing?: boolean;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** 通知组件引用 */
|
|
94
|
+
export interface NotificationRef {
|
|
95
|
+
/** 显示通知 */
|
|
96
|
+
show: () => boolean;
|
|
97
|
+
/** 隐藏通知 */
|
|
98
|
+
hide: () => boolean;
|
|
99
|
+
/** 更新通知内容 */
|
|
100
|
+
update: (_props: Partial<NotificationProps>) => boolean;
|
|
101
|
+
/** 暂停自动关闭 */
|
|
102
|
+
pauseProgress?: () => void;
|
|
103
|
+
/** 恢复自动关闭 */
|
|
104
|
+
resumeProgress?: () => void;
|
|
105
|
+
/** 获取通知状态 */
|
|
106
|
+
getState: () => {
|
|
107
|
+
visible: boolean;
|
|
108
|
+
paused: boolean;
|
|
109
|
+
closing: boolean;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** 通知管理器属性 */
|
|
114
|
+
export interface NotificationManagerProps {
|
|
115
|
+
/** 最大通知数量 */
|
|
116
|
+
maxCount?: number;
|
|
117
|
+
/** 默认位置 */
|
|
118
|
+
defaultPlacement?: NotificationPlacement;
|
|
119
|
+
/** 默认时长 */
|
|
120
|
+
defaultDuration?: number;
|
|
121
|
+
/** 默认动画 */
|
|
122
|
+
defaultAnimation?: NotificationAnimation;
|
|
123
|
+
/** 是否堆叠 */
|
|
124
|
+
stack?: boolean;
|
|
125
|
+
/** 堆叠最大数量 */
|
|
126
|
+
stackMaxCount?: number;
|
|
127
|
+
/** 允许拖拽 */
|
|
128
|
+
allowDrag?: boolean;
|
|
129
|
+
/** 拖拽阈值 */
|
|
130
|
+
dragThreshold?: number;
|
|
131
|
+
/** 显示分组 */
|
|
132
|
+
showGroup?: boolean;
|
|
133
|
+
/** 分组间隔 */
|
|
134
|
+
groupInterval?: number;
|
|
135
|
+
/** 自定义样式 */
|
|
136
|
+
style?: React.CSSProperties;
|
|
137
|
+
/** 自定义类名 */
|
|
138
|
+
className?: string;
|
|
139
|
+
/** 容器样式 */
|
|
140
|
+
containerStyle?: React.CSSProperties;
|
|
141
|
+
/** 容器类名 */
|
|
142
|
+
containerClassName?: string;
|
|
143
|
+
/** 进入回调 */
|
|
144
|
+
onEnter?: (_key: string) => void;
|
|
145
|
+
/** 离开回调 */
|
|
146
|
+
onLeave?: (_key: string) => void;
|
|
147
|
+
/** 全部关闭回调 */
|
|
148
|
+
onAllClose?: () => void;
|
|
149
|
+
/** 通知配置更新回调 */
|
|
150
|
+
onUpdate?: (_key: string, config: Partial<NotificationItem>) => void;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** 通知管理器引用 */
|
|
154
|
+
export interface NotificationManagerRef {
|
|
155
|
+
/** 显示通知 */
|
|
156
|
+
open: (_config: Omit<NotificationItem, 'key' | 'createdAt'>) => string;
|
|
157
|
+
/** 显示成功通知 */
|
|
158
|
+
success: (_config: Omit<NotificationItem, 'key' | 'createdAt' | 'type'>) => string;
|
|
159
|
+
/** 显示信息通知 */
|
|
160
|
+
info: (_config: Omit<NotificationItem, 'key' | 'createdAt' | 'type'>) => string;
|
|
161
|
+
/** 显示警告通知 */
|
|
162
|
+
warning: (_config: Omit<NotificationItem, 'key' | 'createdAt' | 'type'>) => string;
|
|
163
|
+
/** 显示错误通知 */
|
|
164
|
+
error: (_config: Omit<NotificationItem, 'key' | 'createdAt' | 'type'>) => string;
|
|
165
|
+
/** 关闭指定通知 */
|
|
166
|
+
close: (_key: string) => void;
|
|
167
|
+
/** 关闭所有通知 */
|
|
168
|
+
destroyAll: () => void;
|
|
169
|
+
/** 更新通知 */
|
|
170
|
+
update: (_key: string, config: Partial<NotificationItem>) => void;
|
|
171
|
+
/** 获取所有通知 */
|
|
172
|
+
getNotifications: () => NotificationItem[];
|
|
173
|
+
/** 获取通知数量 */
|
|
174
|
+
getCount: () => number;
|
|
175
|
+
/** 设置最大数量 */
|
|
176
|
+
setMaxCount: (_count: number) => void;
|
|
177
|
+
/** 设置默认位置 */
|
|
178
|
+
setDefaultPlacement: (_placement: NotificationPlacement) => void;
|
|
179
|
+
/** 设置默认时长 */
|
|
180
|
+
setDefaultDuration: (_duration: number) => void;
|
|
181
|
+
/** 暂停所有通知自动关闭 */
|
|
182
|
+
pauseAll: () => void;
|
|
183
|
+
/** 恢复所有通知自动关闭 */
|
|
184
|
+
resumeAll: () => void;
|
|
185
|
+
/** 清空历史记录 */
|
|
186
|
+
clearHistory: () => void;
|
|
187
|
+
/** 获取通知历史 */
|
|
188
|
+
getHistory: () => NotificationItem[];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** 通知样式配置 */
|
|
192
|
+
export interface NotificationStyleConfig {
|
|
193
|
+
/** 基础样式 */
|
|
194
|
+
base: React.CSSProperties;
|
|
195
|
+
/** 类型样式 */
|
|
196
|
+
type: Record<NotificationType, React.CSSProperties>;
|
|
197
|
+
/** 位置样式 */
|
|
198
|
+
placement: Record<NotificationPlacement, React.CSSProperties>;
|
|
199
|
+
/** 图标样式 */
|
|
200
|
+
icon: React.CSSProperties;
|
|
201
|
+
/** 内容样式 */
|
|
202
|
+
content: React.CSSProperties;
|
|
203
|
+
/** 标题样式 */
|
|
204
|
+
title: React.CSSProperties;
|
|
205
|
+
/** 文本样式 */
|
|
206
|
+
text: React.CSSProperties;
|
|
207
|
+
/** 关闭按钮样式 */
|
|
208
|
+
close: React.CSSProperties;
|
|
209
|
+
/** 悬停样式 */
|
|
210
|
+
closeHover: React.CSSProperties;
|
|
211
|
+
/** 关闭图标样式 */
|
|
212
|
+
closeIcon: React.CSSProperties;
|
|
213
|
+
/** 动画样式 */
|
|
214
|
+
animation: {
|
|
215
|
+
enter: React.CSSProperties;
|
|
216
|
+
enterActive: React.CSSProperties;
|
|
217
|
+
exit: React.CSSProperties;
|
|
218
|
+
exitActive: React.CSSProperties;
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** 通知配置 */
|
|
223
|
+
export type NotificationConfig = Partial<NotificationItem>;
|
|
224
|
+
|
|
225
|
+
/** 通知样式集合 */
|
|
226
|
+
export type NotificationStyles = {
|
|
227
|
+
[key in NotificationType]: React.CSSProperties;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
/** 通知位置样式 */
|
|
231
|
+
export type NotificationPlacementStyles = {
|
|
232
|
+
[key in NotificationPlacement]: React.CSSProperties;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
/** 通知动画样式 */
|
|
236
|
+
export type NotificationAnimationStyles = {
|
|
237
|
+
enter: React.CSSProperties;
|
|
238
|
+
enterActive: React.CSSProperties;
|
|
239
|
+
exit: React.CSSProperties;
|
|
240
|
+
exitActive: React.CSSProperties;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
/** 通知工具函数 */
|
|
244
|
+
export interface NotificationUtils {
|
|
245
|
+
/** 生成唯一键 */
|
|
246
|
+
generateKey: () => string;
|
|
247
|
+
/** 排序通知 */
|
|
248
|
+
sortNotifications: (_notifications: NotificationItem[]) => NotificationItem[];
|
|
249
|
+
/** 计算堆叠偏移 */
|
|
250
|
+
calculateStackOffset: (_index: number, baseOffset: number) => number;
|
|
251
|
+
/** 格式化持续时间 */
|
|
252
|
+
formatDuration: (_duration: number) => string;
|
|
253
|
+
/** 验证通知配置 */
|
|
254
|
+
validateConfig: (_config: Partial<NotificationItem>) => { valid: boolean; errors: string[] };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** 默认通知配置 */
|
|
258
|
+
export const DEFAULT_NOTIFICATION_CONFIG = {
|
|
259
|
+
/** 默认最大数量 */
|
|
260
|
+
defaultMaxCount: 5,
|
|
261
|
+
/** 默认位置 */
|
|
262
|
+
defaultPlacement: 'topRight' as NotificationPlacement,
|
|
263
|
+
/** 默认时长 */
|
|
264
|
+
defaultDuration: 4500,
|
|
265
|
+
/** 默认动画 */
|
|
266
|
+
defaultAnimation: 'fade' as NotificationAnimation,
|
|
267
|
+
/** 默认堆叠 */
|
|
268
|
+
defaultStack: true,
|
|
269
|
+
/** 默认堆叠最大数量 */
|
|
270
|
+
defaultStackMaxCount: 3,
|
|
271
|
+
/** 默认允许拖拽 */
|
|
272
|
+
defaultAllowDrag: false,
|
|
273
|
+
/** 默认拖拽阈值 */
|
|
274
|
+
defaultDragThreshold: 100,
|
|
275
|
+
/** 默认显示分组 */
|
|
276
|
+
defaultShowGroup: false,
|
|
277
|
+
/** 默认分组间隔 */
|
|
278
|
+
defaultGroupInterval: 1000,
|
|
279
|
+
/** 最大历史记录数量 */
|
|
280
|
+
maxHistoryCount: 50,
|
|
281
|
+
/** 默认自动关闭 */
|
|
282
|
+
defaultAutoClose: true,
|
|
283
|
+
/** 默认显示关闭按钮 */
|
|
284
|
+
defaultShowClose: true,
|
|
285
|
+
/** 默认显示图标 */
|
|
286
|
+
defaultShowIcon: true,
|
|
287
|
+
/** 默认可关闭 */
|
|
288
|
+
defaultClosable: true,
|
|
289
|
+
} as const;
|
|
290
|
+
|
|
291
|
+
/** 通知工具类 */
|
|
292
|
+
export const NotificationUtils = {
|
|
293
|
+
/** 生成唯一键 */
|
|
294
|
+
generateKey: (): string => {
|
|
295
|
+
return `notification_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
296
|
+
},
|
|
297
|
+
|
|
298
|
+
/** 排序通知 */
|
|
299
|
+
sortNotifications: (notifications: NotificationItem[]): NotificationItem[] => {
|
|
300
|
+
return [...notifications].sort((a, b) => a.createdAt - b.createdAt);
|
|
301
|
+
},
|
|
302
|
+
|
|
303
|
+
/** 计算堆叠偏移 */
|
|
304
|
+
calculateStackOffset: (index: number, baseOffset: number = 8): number => {
|
|
305
|
+
return index * baseOffset;
|
|
306
|
+
},
|
|
307
|
+
|
|
308
|
+
/** 格式化持续时间 */
|
|
309
|
+
formatDuration: (duration: number): string => {
|
|
310
|
+
if (duration < 1000) return `${duration}ms`;
|
|
311
|
+
if (duration < 60000) return `${(duration / 1000).toFixed(1)}s`;
|
|
312
|
+
return `${(duration / 60000).toFixed(1)}min`;
|
|
313
|
+
},
|
|
314
|
+
|
|
315
|
+
/** 验证通知配置 */
|
|
316
|
+
validateConfig: (config: Partial<NotificationItem>): { valid: boolean; errors: string[] } => {
|
|
317
|
+
const errors: string[] = [];
|
|
318
|
+
|
|
319
|
+
if (config.duration !== undefined && (config.duration < 0 || config.duration > 60000)) {
|
|
320
|
+
errors.push('duration must be between 0 and 60000ms');
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (config.type !== undefined && !['success', 'error', 'warning', 'info'].includes(config.type)) {
|
|
324
|
+
errors.push('type must be one of: success, error, warning, info');
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (config.placement !== undefined && !['topRight', 'topLeft', 'bottomRight', 'bottomLeft', 'top', 'bottom'].includes(config.placement)) {
|
|
328
|
+
errors.push('placement must be one of: topRight, topLeft, bottomRight, bottomLeft, top, bottom');
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return {
|
|
332
|
+
valid: errors.length === 0,
|
|
333
|
+
errors,
|
|
334
|
+
};
|
|
335
|
+
},
|
|
336
|
+
} as const;
|