taro-uno-ui 0.9.0 → 1.0.1
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/README.md +21 -0
- package/dist/js/{index-DffLRSro.js → index-CDFsvu80.js} +15369 -10741
- package/dist/js/index-CDFsvu80.js.map +1 -0
- package/dist/js/index-DFdcksbe.js.map +1 -1
- package/dist/js/index-DXRIkWX1.js.map +1 -1
- package/dist/js/{index-6NJ3A1Dn.js → index-JffnTUrv.js} +15430 -10801
- package/dist/js/index-JffnTUrv.js.map +1 -0
- package/dist/utils/http/request.d.ts +280 -0
- package/package.json +14 -10
- package/src/components/basic/Button/Button.tsx +53 -13
- package/src/components/basic/Button/Button.types.ts +45 -9
- package/src/components/basic/Divider/Divider.tsx +60 -29
- package/src/components/basic/Icon/Icon.data.ts +474 -0
- package/src/components/basic/Icon/Icon.test.tsx +2 -2
- package/src/components/basic/Icon/Icon.tsx +48 -35
- package/src/components/basic/Icon/IconManager.ts +229 -0
- package/src/components/basic/Text/Text.styles.ts +3 -3
- package/src/components/basic/Text/Text.types.ts +14 -4
- package/src/components/basic/Typography/Typography.styles.ts +10 -9
- package/src/components/basic/Typography/Typography.tsx +15 -13
- package/src/components/basic/Typography/Typography.types.ts +41 -41
- package/src/components/basic/Typography/index.tsx +1 -1
- package/src/components/basic/Video/Video.styles.ts +777 -0
- package/src/components/basic/Video/Video.test.tsx +490 -0
- package/src/components/basic/Video/Video.tsx +1468 -0
- package/src/components/basic/Video/Video.types.ts +500 -0
- package/src/components/basic/Video/index.tsx +26 -0
- package/src/components/basic/index.tsx +13 -15
- package/src/components/common/ErrorBoundary.tsx +1 -1
- package/src/components/common/LazyComponent.tsx +9 -8
- package/src/components/common/SecurityProvider.tsx +2 -14
- package/src/components/common/ThemeProvider.tsx +43 -56
- package/src/components/common/VirtualList.tsx +187 -205
- package/src/components/common/index.tsx +25 -0
- package/src/components/display/Avatar/Avatar.styles.ts +1 -1
- package/src/components/display/Avatar/Avatar.tsx +6 -19
- package/src/components/display/Avatar/Avatar.types.ts +1 -1
- package/src/components/display/Avatar/index.ts +1 -1
- package/src/components/display/Badge/Badge.tsx +3 -16
- package/src/components/display/Badge/Badge.types.ts +1 -1
- package/src/components/display/Badge/index.ts +1 -1
- package/src/components/display/Calendar/Calendar.styles.ts +36 -36
- package/src/components/display/Calendar/Calendar.test.tsx +27 -15
- package/src/components/display/Calendar/Calendar.tsx +56 -35
- package/src/components/display/Calendar/Calendar.types.ts +1 -1
- package/src/components/display/Calendar/index.ts +1 -1
- package/src/components/display/Card/Card.styles.ts +2 -2
- package/src/components/display/Card/Card.test.tsx +6 -4
- package/src/components/display/Card/Card.tsx +1 -1
- package/src/components/display/Card/Card.types.ts +4 -4
- package/src/components/display/Card/index.ts +1 -1
- package/src/components/display/Carousel/Carousel.styles.ts +31 -31
- package/src/components/display/Carousel/Carousel.tsx +34 -39
- package/src/components/display/Carousel/Carousel.types.ts +1 -1
- package/src/components/display/Carousel/index.ts +1 -1
- package/src/components/display/List/List.styles.ts +3 -3
- package/src/components/display/List/List.tsx +0 -1
- package/src/components/display/List/index.ts +1 -1
- package/src/components/display/Rate/Rate.styles.ts +5 -17
- package/src/components/display/Rate/Rate.tsx +6 -14
- package/src/components/display/Rate/Rate.types.ts +4 -3
- package/src/components/display/Rate/index.ts +3 -11
- package/src/components/display/Table/Table.test.tsx +2 -0
- package/src/components/display/Table/Table.tsx +3 -7
- package/src/components/display/Table/Table.types.ts +3 -2
- package/src/components/display/Tag/Tag.styles.ts +31 -31
- package/src/components/display/Tag/Tag.tsx +9 -26
- package/src/components/display/Tag/Tag.types.ts +1 -1
- package/src/components/display/Tag/index.ts +1 -1
- package/src/components/display/Timeline/Timeline.styles.ts +32 -32
- package/src/components/display/Timeline/Timeline.tsx +23 -42
- package/src/components/display/Timeline/Timeline.types.ts +1 -1
- package/src/components/display/Timeline/index.ts +1 -1
- package/src/components/display/index.tsx +33 -29
- package/src/components/feedback/Loading/Loading.tsx +6 -1
- package/src/components/feedback/Loading/index.ts +2 -5
- package/src/components/feedback/Message/Message.styles.ts +3 -3
- package/src/components/feedback/Message/index.ts +2 -5
- package/src/components/feedback/Modal/Modal.styles.ts +1 -1
- package/src/components/feedback/Modal/Modal.tsx +9 -31
- package/src/components/feedback/Modal/Modal.types.ts +12 -2
- package/src/components/feedback/Notification/Notification.styles.ts +49 -39
- package/src/components/feedback/Notification/Notification.test.tsx +1 -1
- package/src/components/feedback/Notification/Notification.tsx +97 -120
- package/src/components/feedback/Notification/Notification.types.ts +11 -8
- package/src/components/feedback/Notification/NotificationManager.tsx +135 -106
- package/src/components/feedback/Notification/index.ts +10 -3
- package/src/components/feedback/Notification/index.tsx +16 -26
- package/src/components/feedback/Progress/Progress.styles.ts +23 -14
- package/src/components/feedback/Progress/Progress.tsx +93 -113
- package/src/components/feedback/Progress/Progress.types.ts +1 -1
- package/src/components/feedback/Progress/index.ts +1 -1
- package/src/components/feedback/Progress/utils/animation.ts +12 -23
- package/src/components/feedback/Progress/utils/index.ts +2 -2
- package/src/components/feedback/Progress/utils/progress-calculator.ts +14 -32
- package/src/components/feedback/Result/Result.styles.ts +29 -29
- package/src/components/feedback/Result/Result.tsx +8 -20
- package/src/components/feedback/Result/Result.types.ts +7 -7
- package/src/components/feedback/Result/index.tsx +1 -1
- package/src/components/feedback/Toast/Toast.styles.ts +1 -1
- package/src/components/feedback/Toast/Toast.tsx +25 -13
- package/src/components/feedback/Tooltip/Tooltip.examples.tsx +21 -44
- package/src/components/feedback/Tooltip/Tooltip.styles.ts +16 -22
- package/src/components/feedback/Tooltip/Tooltip.test.tsx +1 -1
- package/src/components/feedback/Tooltip/Tooltip.tsx +65 -46
- package/src/components/feedback/Tooltip/Tooltip.types.ts +14 -20
- package/src/components/feedback/Tooltip/index.ts +1 -1
- package/src/components/feedback/Tooltip/index.tsx +12 -24
- package/src/components/feedback/index.tsx +54 -42
- package/src/components/form/Cascader/Cascader.styles.ts +2 -2
- package/src/components/form/Cascader/Cascader.tsx +84 -88
- package/src/components/form/Cascader/Cascader.types.ts +49 -50
- package/src/components/form/Cascader/hooks/useCascaderFieldNames.ts +11 -8
- package/src/components/form/Cascader/hooks/useCascaderOptions.ts +73 -55
- package/src/components/form/Cascader/hooks/useCascaderState.ts +31 -25
- package/src/components/form/Cascader/index.ts +1 -1
- package/src/components/form/Cascader/utils/formatDisplayValue.ts +4 -4
- package/src/components/form/Checkbox/Checkbox.styles.ts +83 -84
- package/src/components/form/Checkbox/Checkbox.tsx +2 -9
- package/src/components/form/Checkbox/CheckboxGroup.tsx +7 -7
- package/src/components/form/DatePicker/DatePicker.test.tsx +1 -1
- package/src/components/form/DatePicker/DatePicker.tsx +91 -75
- package/src/components/form/DatePicker/DatePicker.types.ts +4 -1
- package/src/components/form/Form/Form.tsx +66 -504
- package/src/components/form/Form/Form.types.ts +16 -1
- package/src/components/form/Form/useFormLogic.ts +497 -0
- package/src/components/form/Input/Input.styles.ts +8 -1
- package/src/components/form/Input/Input.tsx +55 -291
- package/src/components/form/Input/Input.types.ts +13 -1
- package/src/components/form/Input/useInputLogic.test.ts +82 -0
- package/src/components/form/Input/useInputLogic.ts +260 -0
- package/src/components/form/InputNumber/InputNumber.styles.ts +76 -25
- package/src/components/form/InputNumber/InputNumber.tsx +53 -21
- package/src/components/form/InputNumber/InputNumber.types.ts +21 -3
- package/src/components/form/InputNumber/components/InputNumberClearButton.tsx +3 -11
- package/src/components/form/InputNumber/components/InputNumberControls.tsx +3 -12
- package/src/components/form/InputNumber/hooks/index.ts +1 -1
- package/src/components/form/InputNumber/hooks/useInputNumberState.ts +7 -9
- package/src/components/form/InputNumber/hooks/useInputNumberValidation.ts +18 -17
- package/src/components/form/InputNumber/index.ts +7 -7
- package/src/components/form/Radio/Radio.styles.ts +1 -8
- package/src/components/form/Radio/Radio.tsx +3 -9
- package/src/components/form/Radio/Radio.types.ts +5 -1
- package/src/components/form/Select/Select.styles.ts +5 -1
- package/src/components/form/Select/Select.tsx +15 -15
- package/src/components/form/Select/Select.types.ts +2 -1
- package/src/components/form/Slider/Slider.styles.ts +13 -13
- package/src/components/form/Slider/Slider.tsx +19 -33
- package/src/components/form/Slider/Slider.types.ts +14 -12
- package/src/components/form/Slider/index.tsx +2 -9
- package/src/components/form/Switch/Switch.styles.ts +1 -7
- package/src/components/form/Switch/Switch.tsx +7 -13
- package/src/components/form/Textarea/Textarea.styles.ts +4 -4
- package/src/components/form/Textarea/Textarea.tsx +7 -1
- package/src/components/form/Textarea/Textarea.types.ts +4 -1
- package/src/components/form/TimePicker/TimePicker.styles.ts +8 -12
- package/src/components/form/TimePicker/TimePicker.tsx +122 -100
- package/src/components/form/TimePicker/TimePicker.types.ts +2 -2
- package/src/components/form/TimePicker/index.ts +1 -1
- package/src/components/form/Transfer/Transfer.styles.ts +3 -15
- package/src/components/form/Transfer/Transfer.tsx +146 -134
- package/src/components/form/Transfer/Transfer.types.ts +34 -26
- package/src/components/form/Transfer/components/TransferItem.tsx +55 -62
- package/src/components/form/Transfer/components/TransferList.tsx +212 -199
- package/src/components/form/Transfer/components/TransferOperations.tsx +52 -55
- package/src/components/form/Transfer/components/TransferPagination.tsx +115 -111
- package/src/components/form/Transfer/components/TransferSearch.tsx +52 -55
- package/src/components/form/Transfer/hooks/useTransferData.ts +91 -81
- package/src/components/form/Transfer/hooks/useTransferState.ts +22 -16
- package/src/components/form/Transfer/index.ts +2 -8
- package/src/components/form/Upload/Upload.styles.ts +21 -21
- package/src/components/form/Upload/Upload.tsx +189 -142
- package/src/components/form/Upload/Upload.types.ts +31 -31
- package/src/components/form/Upload/index.tsx +1 -1
- package/src/components/form/index.tsx +60 -29
- package/src/components/index.tsx +0 -1
- package/src/components/layout/Affix/Affix.styles.ts +16 -11
- package/src/components/layout/Affix/Affix.tsx +67 -75
- package/src/components/layout/Affix/Affix.types.ts +18 -18
- package/src/components/layout/Affix/index.tsx +1 -1
- package/src/components/layout/Col/Col.styles.ts +17 -17
- package/src/components/layout/Col/Col.test.tsx +7 -5
- package/src/components/layout/Col/Col.tsx +3 -21
- package/src/components/layout/Col/Col.types.ts +1 -1
- package/src/components/layout/Container/Container.styles.ts +3 -1
- package/src/components/layout/Container/Container.tsx +2 -11
- package/src/components/layout/Grid/Grid.tsx +3 -53
- package/src/components/layout/Layout/Content.tsx +24 -32
- package/src/components/layout/Layout/Footer.tsx +24 -32
- package/src/components/layout/Layout/Header.tsx +24 -32
- package/src/components/layout/Layout/Layout.styles.ts +17 -17
- package/src/components/layout/Layout/Layout.tsx +14 -25
- package/src/components/layout/Layout/Layout.types.ts +29 -29
- package/src/components/layout/Layout/Sider.tsx +44 -56
- package/src/components/layout/Layout/index.tsx +16 -2
- package/src/components/layout/Row/Row.tsx +15 -43
- package/src/components/layout/Space/Space.tsx +3 -11
- package/src/components/layout/Space/Space.types.ts +1 -1
- package/src/components/layout/index.tsx +29 -19
- package/src/components/navigation/Menu/Menu.constants.ts +69 -0
- package/src/components/navigation/Menu/Menu.stories.tsx +107 -0
- package/src/components/navigation/Menu/Menu.styles.ts +25 -37
- package/src/components/navigation/Menu/Menu.tsx +8 -11
- package/src/components/navigation/Menu/Menu.types.ts +2 -2
- package/src/components/navigation/Menu/Menu.utils.ts +17 -17
- package/src/components/navigation/Menu/MenuItem.tsx +9 -11
- package/src/components/navigation/Menu/SubMenu.tsx +8 -6
- package/src/components/navigation/Menu/index.tsx +4 -69
- package/src/components/navigation/NavBar/NavBar.styles.ts +1 -1
- package/src/components/navigation/NavBar/NavBar.tsx +7 -10
- package/src/components/navigation/NavBar/NavBar.types.ts +3 -3
- package/src/components/navigation/NavBar/index.tsx +1 -1
- package/src/components/navigation/Pagination/Pagination.test.tsx +2 -3
- package/src/components/navigation/Pagination/Pagination.tsx +3 -3
- package/src/components/navigation/Pagination/Pagination.types.ts +3 -2
- package/src/components/navigation/Pagination/index.ts +9 -3
- package/src/components/navigation/Steps/Step.tsx +24 -44
- package/src/components/navigation/Steps/Steps.styles.ts +28 -13
- package/src/components/navigation/Steps/Steps.test.tsx +2 -0
- package/src/components/navigation/Steps/Steps.tsx +88 -89
- package/src/components/navigation/Steps/Steps.types.ts +30 -30
- package/src/components/navigation/Steps/index.tsx +1 -1
- package/src/components/navigation/Tabs/Tabs.test.tsx +3 -2
- package/src/components/navigation/Tabs/Tabs.types.ts +4 -3
- package/src/components/navigation/index.tsx +21 -16
- package/src/constants/index.ts +1 -1
- package/src/hooks/index.ts +52 -102
- package/src/hooks/types.ts +4 -5
- package/src/hooks/useAsync.ts +46 -47
- package/src/hooks/useClickOutside.ts +52 -0
- package/src/hooks/useCounter.ts +87 -0
- package/src/hooks/useDebounce.ts +150 -0
- package/src/hooks/useDeepCompareEffect.ts +88 -0
- package/src/hooks/useEventListener.ts +77 -0
- package/src/hooks/useMediaQuery.ts +75 -0
- package/src/hooks/useMutation.ts +233 -0
- package/src/hooks/usePerformance.ts +1 -64
- package/src/hooks/usePlatform.ts +3 -1
- package/src/hooks/usePrevious.ts +25 -0
- package/src/hooks/useRequest.ts +12 -7
- package/src/hooks/useStateManagement.ts +1 -1
- package/src/hooks/useStorage.ts +169 -0
- package/src/hooks/useStyle.ts +8 -2
- package/src/hooks/useToggle.ts +54 -0
- package/src/index.ts +34 -9
- package/src/theme/ThemeProvider.tsx +3 -7
- package/src/theme/ThemeProvider.types.ts +1 -1
- package/src/theme/defaults.ts +1 -1
- package/src/theme/design-system.ts +2 -2
- package/src/theme/design-tokens.ts +85 -99
- package/src/theme/generated/dark-theme.scss +1 -1
- package/src/theme/generated/tokens.scss +82 -18
- package/src/theme/index.ts +8 -29
- package/src/theme/responsive.tsx +36 -34
- package/src/theme/styles.ts +1 -1
- package/src/theme/useThemeUtils.ts +43 -43
- package/src/theme/utils.ts +32 -32
- package/src/theme/variables.ts +70 -51
- package/src/types/accessibility.ts +36 -37
- package/src/types/button.ts +25 -27
- package/src/types/component-props.ts +6 -1
- package/src/types/glob.d.ts +4 -0
- package/src/types/index.ts +2 -2
- package/src/types/standardized-components.ts +9 -3
- package/src/types/utils.ts +13 -23
- package/src/utils/__tests__/responsiveUtils.test.ts +5 -4
- package/src/utils/abort-controller.ts +48 -0
- package/src/utils/cache.ts +2 -6
- package/src/utils/createNamespace.ts +4 -4
- package/src/utils/environment.ts +26 -6
- package/src/utils/error-handler.ts +2 -2
- package/src/utils/errorLogger.ts +16 -20
- package/src/utils/formatUtils.ts +38 -70
- package/src/utils/http/error-codes.ts +314 -0
- package/src/utils/http/http-client.test.ts +63 -0
- package/src/utils/{network → http}/http-client.ts +45 -35
- package/src/utils/http/request-cache.ts +127 -0
- package/src/utils/http/request.ts +954 -0
- package/src/utils/http/taro-adapter.test.ts +74 -0
- package/src/utils/http/taro-adapter.ts +24 -0
- package/src/utils/http/types.ts +414 -0
- package/src/utils/http/web-adapter.ts +33 -0
- package/src/utils/index.ts +5 -8
- package/src/utils/inputValidator.ts +17 -14
- package/src/utils/performance/performance.ts +60 -71
- package/src/utils/responsiveUtils.ts +7 -16
- package/src/utils/rtl-support.ts +29 -19
- package/src/utils/security/api-security.ts +47 -39
- package/src/utils/securityHeaders.ts +61 -67
- package/src/utils/typeHelpers.ts +10 -10
- package/src/utils/types/dataProcessing.ts +93 -92
- package/src/utils/types/typeHelpers.ts +31 -21
- package/src/utils/xssProtection.ts +96 -48
- package/dist/js/index-6NJ3A1Dn.js.map +0 -1
- package/dist/js/index-DffLRSro.js.map +0 -1
- package/src/components/form/Input/Input.enhanced.tsx +0 -732
- package/src/components/navigation/Menu/__tests__/Menu.test.tsx +0 -687
- package/src/components/navigation/Tree/Tree.styles.ts +0 -553
- package/src/components/navigation/Tree/Tree.test.basic.tsx +0 -7
- package/src/components/navigation/Tree/Tree.test.functional.tsx +0 -496
- package/src/components/navigation/Tree/Tree.test.import.check.tsx +0 -6
- package/src/components/navigation/Tree/Tree.test.import.tsx +0 -6
- package/src/components/navigation/Tree/Tree.test.minimal.tsx +0 -5
- package/src/components/navigation/Tree/Tree.test.simple.tsx +0 -30
- package/src/components/navigation/Tree/Tree.test.tsx +0 -908
- package/src/components/navigation/Tree/Tree.test.working.tsx +0 -673
- package/src/components/navigation/Tree/Tree.tsx +0 -600
- package/src/components/navigation/Tree/Tree.types.ts +0 -909
- package/src/components/navigation/Tree/Tree.utils.ts +0 -452
- package/src/components/navigation/Tree/index.ts +0 -33
- package/src/components/navigation/Tree/index.tsx +0 -23
- package/src/utils/network/http-client.test.ts +0 -18
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
NotificationManagerProps,
|
|
5
5
|
NotificationManagerRef,
|
|
6
6
|
NotificationItem,
|
|
7
|
-
NotificationPlacement
|
|
7
|
+
NotificationPlacement,
|
|
8
8
|
} from './Notification.types';
|
|
9
9
|
import { Notification } from './Notification';
|
|
10
10
|
import { notificationStyleHelpers } from './Notification.styles';
|
|
@@ -50,93 +50,102 @@ export const NotificationManager = forwardRef<NotificationManagerRef, Notificati
|
|
|
50
50
|
const notificationRefs = useRef<Map<string, { current: any }>>(new Map());
|
|
51
51
|
|
|
52
52
|
// 添加通知
|
|
53
|
-
const addNotification = useCallback(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
53
|
+
const addNotification = useCallback(
|
|
54
|
+
(config: Omit<NotificationItem, 'key' | 'createdAt'>): string => {
|
|
55
|
+
const key = NotificationUtils.generateKey();
|
|
56
|
+
const newNotification: InternalNotificationItem = {
|
|
57
|
+
...config,
|
|
58
|
+
key,
|
|
59
|
+
createdAt: Date.now(),
|
|
60
|
+
placement: config.placement || defaultPlacement,
|
|
61
|
+
duration: config.duration ?? defaultDuration,
|
|
62
|
+
animation: config.animation || defaultAnimation,
|
|
63
|
+
stackIndex: 0,
|
|
64
|
+
isClosing: false,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
setNotifications((prev) => {
|
|
68
|
+
// 检查是否超过最大数量
|
|
69
|
+
let updatedNotifications = [...prev, newNotification];
|
|
70
|
+
|
|
71
|
+
if (updatedNotifications.length > maxCount) {
|
|
72
|
+
// 移除最早的通知
|
|
73
|
+
const removed = updatedNotifications.shift();
|
|
74
|
+
if (removed) {
|
|
75
|
+
// 添加到历史记录
|
|
76
|
+
setHistory((prevHistory) => [...prevHistory.slice(-DEFAULT_NOTIFICATION_CONFIG.maxHistoryCount!), removed]);
|
|
77
|
+
onLeave?.(removed.key);
|
|
78
|
+
}
|
|
77
79
|
}
|
|
78
|
-
}
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
// 更新堆叠索引
|
|
82
|
+
return updateStackIndices(updatedNotifications);
|
|
83
|
+
});
|
|
83
84
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
onEnter?.(key);
|
|
86
|
+
return key;
|
|
87
|
+
},
|
|
88
|
+
[maxCount, defaultPlacement, defaultDuration, defaultAnimation, onEnter, onLeave],
|
|
89
|
+
);
|
|
87
90
|
|
|
88
91
|
// 更新堆叠索引
|
|
89
|
-
const updateStackIndices = useCallback(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
const updateStackIndices = useCallback(
|
|
93
|
+
(notificationsList: InternalNotificationItem[]): InternalNotificationItem[] => {
|
|
94
|
+
if (!stack) return notificationsList;
|
|
95
|
+
|
|
96
|
+
return notificationsList.map((notification, index) => ({
|
|
97
|
+
...notification,
|
|
98
|
+
stackIndex: index,
|
|
99
|
+
}));
|
|
100
|
+
},
|
|
101
|
+
[stack],
|
|
102
|
+
);
|
|
97
103
|
|
|
98
104
|
// 关闭通知
|
|
99
|
-
const closeNotification = useCallback(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
const closeNotification = useCallback(
|
|
106
|
+
(key: string) => {
|
|
107
|
+
setNotifications((prev) => {
|
|
108
|
+
const notificationIndex = prev.findIndex((n) => n.key === key);
|
|
109
|
+
if (notificationIndex === -1) return prev;
|
|
110
|
+
|
|
111
|
+
const notification = prev[notificationIndex];
|
|
112
|
+
const updatedNotifications = prev.filter((_, index) => index !== notificationIndex);
|
|
113
|
+
|
|
114
|
+
// 添加到历史记录
|
|
115
|
+
setHistory((prevHistory) => [
|
|
116
|
+
...prevHistory.slice(-DEFAULT_NOTIFICATION_CONFIG.maxHistoryCount!),
|
|
117
|
+
notification as NotificationItem,
|
|
118
|
+
]);
|
|
119
|
+
|
|
120
|
+
// 更新堆叠索引
|
|
121
|
+
return updateStackIndices(updatedNotifications);
|
|
122
|
+
});
|
|
113
123
|
|
|
114
|
-
|
|
115
|
-
|
|
124
|
+
onLeave?.(key);
|
|
125
|
+
},
|
|
126
|
+
[onLeave, updateStackIndices],
|
|
127
|
+
);
|
|
116
128
|
|
|
117
129
|
// 关闭所有通知
|
|
118
130
|
const closeAllNotifications = useCallback(() => {
|
|
119
|
-
setNotifications(prev => {
|
|
131
|
+
setNotifications((prev) => {
|
|
120
132
|
// 添加到历史记录
|
|
121
|
-
setHistory(prevHistory => [
|
|
122
|
-
...prevHistory.slice(-DEFAULT_NOTIFICATION_CONFIG.maxHistoryCount!),
|
|
123
|
-
...prev
|
|
124
|
-
]);
|
|
133
|
+
setHistory((prevHistory) => [...prevHistory.slice(-DEFAULT_NOTIFICATION_CONFIG.maxHistoryCount!), ...prev]);
|
|
125
134
|
|
|
126
135
|
const firstKey = prev[0]?.key;
|
|
127
136
|
if (firstKey) {
|
|
128
137
|
onLeave?.(firstKey);
|
|
129
138
|
}
|
|
130
139
|
onAllClose?.();
|
|
131
|
-
|
|
140
|
+
|
|
132
141
|
return [];
|
|
133
142
|
});
|
|
134
143
|
}, [onLeave, onAllClose]);
|
|
135
144
|
|
|
136
145
|
// 更新通知
|
|
137
146
|
const updateNotification = useCallback((key: string, config: Partial<NotificationItem>) => {
|
|
138
|
-
setNotifications(prev => {
|
|
139
|
-
return prev.map(notification => {
|
|
147
|
+
setNotifications((prev) => {
|
|
148
|
+
return prev.map((notification) => {
|
|
140
149
|
if (notification.key === key) {
|
|
141
150
|
return {
|
|
142
151
|
...notification,
|
|
@@ -152,34 +161,52 @@ export const NotificationManager = forwardRef<NotificationManagerRef, Notificati
|
|
|
152
161
|
}, []);
|
|
153
162
|
|
|
154
163
|
// 显示通知
|
|
155
|
-
const open = useCallback(
|
|
156
|
-
|
|
157
|
-
|
|
164
|
+
const open = useCallback(
|
|
165
|
+
(config: Omit<NotificationItem, 'key' | 'createdAt'>) => {
|
|
166
|
+
return addNotification(config);
|
|
167
|
+
},
|
|
168
|
+
[addNotification],
|
|
169
|
+
);
|
|
158
170
|
|
|
159
171
|
// 显示成功通知
|
|
160
|
-
const success = useCallback(
|
|
161
|
-
|
|
162
|
-
|
|
172
|
+
const success = useCallback(
|
|
173
|
+
(config: Omit<NotificationItem, 'key' | 'createdAt' | 'type'>) => {
|
|
174
|
+
return open({ ...config, type: 'success' });
|
|
175
|
+
},
|
|
176
|
+
[open],
|
|
177
|
+
);
|
|
163
178
|
|
|
164
179
|
// 显示信息通知
|
|
165
|
-
const info = useCallback(
|
|
166
|
-
|
|
167
|
-
|
|
180
|
+
const info = useCallback(
|
|
181
|
+
(config: Omit<NotificationItem, 'key' | 'createdAt' | 'type'>) => {
|
|
182
|
+
return open({ ...config, type: 'info' });
|
|
183
|
+
},
|
|
184
|
+
[open],
|
|
185
|
+
);
|
|
168
186
|
|
|
169
187
|
// 显示警告通知
|
|
170
|
-
const warning = useCallback(
|
|
171
|
-
|
|
172
|
-
|
|
188
|
+
const warning = useCallback(
|
|
189
|
+
(config: Omit<NotificationItem, 'key' | 'createdAt' | 'type'>) => {
|
|
190
|
+
return open({ ...config, type: 'warning' });
|
|
191
|
+
},
|
|
192
|
+
[open],
|
|
193
|
+
);
|
|
173
194
|
|
|
174
195
|
// 显示错误通知
|
|
175
|
-
const error = useCallback(
|
|
176
|
-
|
|
177
|
-
|
|
196
|
+
const error = useCallback(
|
|
197
|
+
(config: Omit<NotificationItem, 'key' | 'createdAt' | 'type'>) => {
|
|
198
|
+
return open({ ...config, type: 'error' });
|
|
199
|
+
},
|
|
200
|
+
[open],
|
|
201
|
+
);
|
|
178
202
|
|
|
179
203
|
// 关闭指定通知
|
|
180
|
-
const close = useCallback(
|
|
181
|
-
|
|
182
|
-
|
|
204
|
+
const close = useCallback(
|
|
205
|
+
(key: string) => {
|
|
206
|
+
closeNotification(key);
|
|
207
|
+
},
|
|
208
|
+
[closeNotification],
|
|
209
|
+
);
|
|
183
210
|
|
|
184
211
|
// 关闭所有通知
|
|
185
212
|
const destroyAll = useCallback(() => {
|
|
@@ -217,7 +244,7 @@ export const NotificationManager = forwardRef<NotificationManagerRef, Notificati
|
|
|
217
244
|
// 暂停所有通知自动关闭
|
|
218
245
|
const pauseAll = useCallback(() => {
|
|
219
246
|
setIsAllPaused(true);
|
|
220
|
-
notificationRefs.current.forEach(refObject => {
|
|
247
|
+
notificationRefs.current.forEach((refObject) => {
|
|
221
248
|
if (refObject?.current?.pauseProgress) {
|
|
222
249
|
refObject.current.pauseProgress();
|
|
223
250
|
}
|
|
@@ -227,7 +254,7 @@ export const NotificationManager = forwardRef<NotificationManagerRef, Notificati
|
|
|
227
254
|
// 恢复所有通知自动关闭
|
|
228
255
|
const resumeAll = useCallback(() => {
|
|
229
256
|
setIsAllPaused(false);
|
|
230
|
-
notificationRefs.current.forEach(ref => {
|
|
257
|
+
notificationRefs.current.forEach((ref) => {
|
|
231
258
|
if (ref?.current?.resumeProgress) {
|
|
232
259
|
ref.current.resumeProgress();
|
|
233
260
|
}
|
|
@@ -266,17 +293,23 @@ export const NotificationManager = forwardRef<NotificationManagerRef, Notificati
|
|
|
266
293
|
}));
|
|
267
294
|
|
|
268
295
|
// 处理通知关闭
|
|
269
|
-
const handleNotificationClose = useCallback(
|
|
270
|
-
|
|
271
|
-
|
|
296
|
+
const handleNotificationClose = useCallback(
|
|
297
|
+
(key: string) => {
|
|
298
|
+
closeNotification(key);
|
|
299
|
+
},
|
|
300
|
+
[closeNotification],
|
|
301
|
+
);
|
|
272
302
|
|
|
273
303
|
// 处理通知点击
|
|
274
|
-
const handleNotificationClick = useCallback(
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
notification
|
|
278
|
-
|
|
279
|
-
|
|
304
|
+
const handleNotificationClick = useCallback(
|
|
305
|
+
(key: string) => {
|
|
306
|
+
const notification = notifications.find((n) => n.key === key);
|
|
307
|
+
if (notification?.onClick) {
|
|
308
|
+
notification.onClick();
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
[notifications],
|
|
312
|
+
);
|
|
280
313
|
|
|
281
314
|
// 获取容器样式
|
|
282
315
|
const getContainerStyle = () => {
|
|
@@ -288,13 +321,9 @@ export const NotificationManager = forwardRef<NotificationManagerRef, Notificati
|
|
|
288
321
|
|
|
289
322
|
// 获取容器类名
|
|
290
323
|
const getContainerClassName = () => {
|
|
291
|
-
return cn(
|
|
292
|
-
'taro-uno-notification-container',
|
|
293
|
-
containerClassName
|
|
294
|
-
);
|
|
324
|
+
return cn('taro-uno-notification-container', containerClassName);
|
|
295
325
|
};
|
|
296
326
|
|
|
297
|
-
|
|
298
327
|
// 按位置分组通知
|
|
299
328
|
const renderNotificationsByPlacement = () => {
|
|
300
329
|
const notificationsByPlacement: Record<NotificationPlacement, InternalNotificationItem[]> = {
|
|
@@ -307,7 +336,7 @@ export const NotificationManager = forwardRef<NotificationManagerRef, Notificati
|
|
|
307
336
|
};
|
|
308
337
|
|
|
309
338
|
// 按位置分组
|
|
310
|
-
notifications.forEach(notification => {
|
|
339
|
+
notifications.forEach((notification) => {
|
|
311
340
|
const placement = notification.placement || defaultPlacement;
|
|
312
341
|
notificationsByPlacement[placement].push(notification);
|
|
313
342
|
});
|
|
@@ -317,7 +346,7 @@ export const NotificationManager = forwardRef<NotificationManagerRef, Notificati
|
|
|
317
346
|
if (placementNotifications.length === 0) return null;
|
|
318
347
|
|
|
319
348
|
const sortedNotifications = NotificationUtils.sortNotifications(placementNotifications);
|
|
320
|
-
|
|
349
|
+
|
|
321
350
|
return (
|
|
322
351
|
<View
|
|
323
352
|
key={placement}
|
|
@@ -357,15 +386,15 @@ export const NotificationManager = forwardRef<NotificationManagerRef, Notificati
|
|
|
357
386
|
|
|
358
387
|
// 获取位置样式
|
|
359
388
|
const getPlacementStyle = (placement: NotificationPlacement) => {
|
|
360
|
-
const placementStyleData = notificationStyleHelpers.getPlacementStyle(placement, {
|
|
389
|
+
const placementStyleData = notificationStyleHelpers.getPlacementStyle(placement, {
|
|
390
|
+
theme,
|
|
391
|
+
isMobile: platform.isMobile(),
|
|
392
|
+
});
|
|
361
393
|
return placementStyleData.container;
|
|
362
394
|
};
|
|
363
395
|
|
|
364
396
|
return (
|
|
365
|
-
<View
|
|
366
|
-
className={getContainerClassName()}
|
|
367
|
-
style={getContainerStyle()}
|
|
368
|
-
>
|
|
397
|
+
<View className={getContainerClassName()} style={getContainerStyle()}>
|
|
369
398
|
{renderNotificationsByPlacement()}
|
|
370
399
|
</View>
|
|
371
400
|
);
|
|
@@ -373,4 +402,4 @@ export const NotificationManager = forwardRef<NotificationManagerRef, Notificati
|
|
|
373
402
|
|
|
374
403
|
NotificationManager.displayName = 'NotificationManager';
|
|
375
404
|
|
|
376
|
-
export default NotificationManager;
|
|
405
|
+
export default NotificationManager;
|
|
@@ -4,7 +4,9 @@ export { default as NotificationManager } from './NotificationManager';
|
|
|
4
4
|
// Simple notification singleton for direct usage
|
|
5
5
|
class NotificationSingleton {
|
|
6
6
|
open = (_config: any) => {
|
|
7
|
-
console.warn(
|
|
7
|
+
console.warn(
|
|
8
|
+
'Notification singleton called. Please render <NotificationManager /> in your app for full functionality.',
|
|
9
|
+
);
|
|
8
10
|
return 'notification-key';
|
|
9
11
|
};
|
|
10
12
|
|
|
@@ -27,7 +29,12 @@ class NotificationSingleton {
|
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
export const notification = new NotificationSingleton();
|
|
30
|
-
export type {
|
|
32
|
+
export type {
|
|
33
|
+
NotificationProps,
|
|
34
|
+
NotificationRef,
|
|
35
|
+
NotificationManagerProps,
|
|
36
|
+
NotificationPlacement,
|
|
37
|
+
} from './Notification.types';
|
|
31
38
|
export { notificationStyles } from './Notification.styles';
|
|
32
39
|
|
|
33
|
-
export default Notification;
|
|
40
|
+
export default Notification;
|
|
@@ -56,67 +56,67 @@ export const notification = {
|
|
|
56
56
|
open: (config: Parameters<NotificationManagerRef['open']>[0]) => {
|
|
57
57
|
return globalNotificationRef?.open(config) || '';
|
|
58
58
|
},
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
// 显示成功通知
|
|
61
61
|
success: (config: Parameters<NotificationManagerRef['success']>[0]) => {
|
|
62
62
|
return globalNotificationRef?.success(config) || '';
|
|
63
63
|
},
|
|
64
|
-
|
|
64
|
+
|
|
65
65
|
// 显示信息通知
|
|
66
66
|
info: (config: Parameters<NotificationManagerRef['info']>[0]) => {
|
|
67
67
|
return globalNotificationRef?.info(config) || '';
|
|
68
68
|
},
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
// 显示警告通知
|
|
71
71
|
warning: (config: Parameters<NotificationManagerRef['warning']>[0]) => {
|
|
72
72
|
return globalNotificationRef?.warning(config) || '';
|
|
73
73
|
},
|
|
74
|
-
|
|
74
|
+
|
|
75
75
|
// 显示错误通知
|
|
76
76
|
error: (config: Parameters<NotificationManagerRef['error']>[0]) => {
|
|
77
77
|
return globalNotificationRef?.error(config) || '';
|
|
78
78
|
},
|
|
79
|
-
|
|
79
|
+
|
|
80
80
|
// 关闭通知
|
|
81
81
|
close: (key: string) => {
|
|
82
82
|
globalNotificationRef?.close(key);
|
|
83
83
|
},
|
|
84
|
-
|
|
84
|
+
|
|
85
85
|
// 关闭所有通知
|
|
86
86
|
destroyAll: () => {
|
|
87
87
|
globalNotificationRef?.destroyAll();
|
|
88
88
|
},
|
|
89
|
-
|
|
89
|
+
|
|
90
90
|
// 更新通知
|
|
91
91
|
update: (key: string, config: Parameters<NotificationManagerRef['update']>[1]) => {
|
|
92
92
|
globalNotificationRef?.update(key, config);
|
|
93
93
|
},
|
|
94
|
-
|
|
94
|
+
|
|
95
95
|
// 获取所有通知
|
|
96
96
|
getNotifications: () => {
|
|
97
97
|
return globalNotificationRef?.getNotifications() || [];
|
|
98
98
|
},
|
|
99
|
-
|
|
99
|
+
|
|
100
100
|
// 获取通知数量
|
|
101
101
|
getCount: () => {
|
|
102
102
|
return globalNotificationRef?.getCount() || 0;
|
|
103
103
|
},
|
|
104
|
-
|
|
104
|
+
|
|
105
105
|
// 暂停所有通知
|
|
106
106
|
pauseAll: () => {
|
|
107
107
|
globalNotificationRef?.pauseAll();
|
|
108
108
|
},
|
|
109
|
-
|
|
109
|
+
|
|
110
110
|
// 恢复所有通知
|
|
111
111
|
resumeAll: () => {
|
|
112
112
|
globalNotificationRef?.resumeAll();
|
|
113
113
|
},
|
|
114
|
-
|
|
114
|
+
|
|
115
115
|
// 清空历史记录
|
|
116
116
|
clearHistory: () => {
|
|
117
117
|
globalNotificationRef?.clearHistory();
|
|
118
118
|
},
|
|
119
|
-
|
|
119
|
+
|
|
120
120
|
// 获取通知历史
|
|
121
121
|
getHistory: () => {
|
|
122
122
|
return globalNotificationRef?.getHistory() || [];
|
|
@@ -124,15 +124,7 @@ export const notification = {
|
|
|
124
124
|
};
|
|
125
125
|
|
|
126
126
|
// 便捷方法
|
|
127
|
-
export const {
|
|
128
|
-
success,
|
|
129
|
-
info,
|
|
130
|
-
warning,
|
|
131
|
-
error,
|
|
132
|
-
destroyAll,
|
|
133
|
-
pauseAll,
|
|
134
|
-
resumeAll,
|
|
135
|
-
} = notification;
|
|
127
|
+
export const { success, info, warning, error, destroyAll, pauseAll, resumeAll } = notification;
|
|
136
128
|
|
|
137
129
|
// 默认导出
|
|
138
130
|
export default Notification;
|
|
@@ -143,7 +135,7 @@ export type {
|
|
|
143
135
|
NotificationType as Type,
|
|
144
136
|
NotificationPlacement as Placement,
|
|
145
137
|
NotificationAnimation as Animation,
|
|
146
|
-
|
|
138
|
+
|
|
147
139
|
// 通知接口
|
|
148
140
|
NotificationItem as Item,
|
|
149
141
|
NotificationProps as Props,
|
|
@@ -159,6 +151,4 @@ export { notification };
|
|
|
159
151
|
if (typeof Notification !== 'undefined') {
|
|
160
152
|
(Notification as any).displayName = 'Notification';
|
|
161
153
|
}
|
|
162
|
-
|
|
163
|
-
(NotificationManager as any).displayName = 'NotificationManager';
|
|
164
|
-
}
|
|
154
|
+
// NotificationManager displayName is set in NotificationManager.tsx
|
|
@@ -7,9 +7,9 @@ import type {
|
|
|
7
7
|
ProgressStyles as ProgressStylesType,
|
|
8
8
|
ProgressGradient,
|
|
9
9
|
} from './Progress.types';
|
|
10
|
-
import {
|
|
11
|
-
calculateCircleDimensions,
|
|
12
|
-
calculateCircleProgress,
|
|
10
|
+
import {
|
|
11
|
+
calculateCircleDimensions,
|
|
12
|
+
calculateCircleProgress,
|
|
13
13
|
calculateDashboardProgress,
|
|
14
14
|
getStatusColor,
|
|
15
15
|
calculateBorderRadius,
|
|
@@ -198,7 +198,11 @@ export const getLineStyle = (props: ProgressStyleProps) => {
|
|
|
198
198
|
|
|
199
199
|
const mergedTheme = { ...defaultTheme, ...theme };
|
|
200
200
|
const borderRadius = calculateBorderRadius(strokeWidth, strokeLinecap);
|
|
201
|
-
const color = strokeColor
|
|
201
|
+
const color = strokeColor
|
|
202
|
+
? typeof strokeColor === 'string'
|
|
203
|
+
? strokeColor
|
|
204
|
+
: mergedTheme.primaryColor
|
|
205
|
+
: getStatusColor(status, statusColors);
|
|
202
206
|
|
|
203
207
|
return {
|
|
204
208
|
outer: {
|
|
@@ -237,10 +241,14 @@ export const getCircleStyle = (props: ProgressStyleProps) => {
|
|
|
237
241
|
const sizeValue = sizeMapping[size];
|
|
238
242
|
const strokeWidth = customStrokeWidth || strokeWidthMapping[size];
|
|
239
243
|
const mergedTheme = { ...defaultTheme, ...theme };
|
|
240
|
-
|
|
244
|
+
|
|
241
245
|
const dimensions = calculateCircleDimensions(sizeValue, strokeWidth);
|
|
242
246
|
const progressData = calculateCircleProgress(dimensions, percent);
|
|
243
|
-
const color = strokeColor
|
|
247
|
+
const color = strokeColor
|
|
248
|
+
? typeof strokeColor === 'string'
|
|
249
|
+
? strokeColor
|
|
250
|
+
: mergedTheme.primaryColor
|
|
251
|
+
: getStatusColor(status, statusColors);
|
|
244
252
|
|
|
245
253
|
return {
|
|
246
254
|
outer: {
|
|
@@ -305,10 +313,14 @@ export const getDashboardStyle = (props: ProgressStyleProps) => {
|
|
|
305
313
|
const sizeValue = sizeMapping[size];
|
|
306
314
|
const strokeWidth = customStrokeWidth || strokeWidthMapping[size];
|
|
307
315
|
const mergedTheme = { ...defaultTheme, ...theme };
|
|
308
|
-
|
|
316
|
+
|
|
309
317
|
const dimensions = calculateCircleDimensions(sizeValue, strokeWidth);
|
|
310
318
|
const progressData = calculateDashboardProgress(dimensions, percent, gapDegree, gapPosition);
|
|
311
|
-
const color = strokeColor
|
|
319
|
+
const color = strokeColor
|
|
320
|
+
? typeof strokeColor === 'string'
|
|
321
|
+
? strokeColor
|
|
322
|
+
: mergedTheme.primaryColor
|
|
323
|
+
: getStatusColor(status, statusColors);
|
|
312
324
|
|
|
313
325
|
return {
|
|
314
326
|
outer: {
|
|
@@ -374,17 +386,14 @@ export const getInfoStyle = (size?: ProgressSize, customStyle?: CSSProperties):
|
|
|
374
386
|
};
|
|
375
387
|
|
|
376
388
|
// 获取容器样式
|
|
377
|
-
export const getContainerStyle = (
|
|
378
|
-
type?: ProgressType,
|
|
379
|
-
customStyle?: CSSProperties
|
|
380
|
-
): CSSProperties => {
|
|
389
|
+
export const getContainerStyle = (type?: ProgressType, customStyle?: CSSProperties): CSSProperties => {
|
|
381
390
|
if (type === 'line') {
|
|
382
391
|
return {
|
|
383
392
|
...progressStyles['lineContainer'],
|
|
384
393
|
...customStyle,
|
|
385
394
|
};
|
|
386
395
|
}
|
|
387
|
-
|
|
396
|
+
|
|
388
397
|
return {
|
|
389
398
|
...progressStyles['container'],
|
|
390
399
|
...customStyle,
|
|
@@ -457,4 +466,4 @@ export const ProgressCSSVariables = {
|
|
|
457
466
|
};
|
|
458
467
|
|
|
459
468
|
// 导出默认样式
|
|
460
|
-
export default progressStyles;
|
|
469
|
+
export default progressStyles;
|