@h-ai/ui 0.1.0-alpha.67 → 0.1.0-alpha.68
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.en.md +31 -5
- package/README.ja.md +31 -5
- package/README.md +64 -38
- package/dist/components/compounds/Accordion.svelte +24 -0
- package/dist/components/compounds/Accordion.svelte.d.ts +34 -0
- package/dist/components/compounds/ActionSheet.svelte +24 -0
- package/dist/components/compounds/ActionSheet.svelte.d.ts +38 -0
- package/dist/components/compounds/Alert.svelte +15 -4
- package/dist/components/compounds/Alert.svelte.d.ts +10 -0
- package/dist/components/compounds/AppBar.svelte +24 -0
- package/dist/components/compounds/AppBar.svelte.d.ts +33 -0
- package/dist/components/compounds/BottomNav.svelte +37 -0
- package/dist/components/compounds/BottomNav.svelte.d.ts +43 -0
- package/dist/components/compounds/Breadcrumb.svelte +11 -0
- package/dist/components/compounds/Breadcrumb.svelte.d.ts +20 -0
- package/dist/components/compounds/Calendar.svelte +20 -6
- package/dist/components/compounds/Calendar.svelte.d.ts +20 -6
- package/dist/components/compounds/Card.svelte +10 -0
- package/dist/components/compounds/Card.svelte.d.ts +10 -0
- package/dist/components/compounds/Combobox.svelte +35 -18
- package/dist/components/compounds/Combobox.svelte.d.ts +35 -18
- package/dist/components/compounds/Confirm.svelte +11 -0
- package/dist/components/compounds/Confirm.svelte.d.ts +21 -0
- package/dist/components/compounds/DataTable.svelte +40 -17
- package/dist/components/compounds/DataTable.svelte.d.ts +9 -13
- package/dist/components/compounds/DatePicker.svelte +20 -6
- package/dist/components/compounds/DatePicker.svelte.d.ts +20 -6
- package/dist/components/compounds/Drawer.svelte +11 -0
- package/dist/components/compounds/Drawer.svelte.d.ts +21 -0
- package/dist/components/compounds/Dropdown.svelte +10 -0
- package/dist/components/compounds/Dropdown.svelte.d.ts +10 -0
- package/dist/components/compounds/Empty.svelte +16 -5
- package/dist/components/compounds/Empty.svelte.d.ts +20 -0
- package/dist/components/compounds/Form.svelte +37 -2
- package/dist/components/compounds/Form.svelte.d.ts +20 -0
- package/dist/components/compounds/FormField.svelte +11 -0
- package/dist/components/compounds/FormField.svelte.d.ts +20 -0
- package/dist/components/compounds/FormLayout.svelte +13 -1
- package/dist/components/compounds/FormLayout.svelte.d.ts +13 -0
- package/dist/components/compounds/InfiniteScroll.svelte +24 -0
- package/dist/components/compounds/InfiniteScroll.svelte.d.ts +34 -0
- package/dist/components/compounds/MessageBoxContainer.svelte +11 -0
- package/dist/components/compounds/MessageBoxContainer.svelte.d.ts +21 -0
- package/dist/components/compounds/MessageBoxDialog.svelte +14 -0
- package/dist/components/compounds/MessageBoxDialog.svelte.d.ts +21 -0
- package/dist/components/compounds/MessageContainer.svelte +11 -0
- package/dist/components/compounds/MessageContainer.svelte.d.ts +21 -0
- package/dist/components/compounds/Modal.svelte +10 -0
- package/dist/components/compounds/Modal.svelte.d.ts +10 -0
- package/dist/components/compounds/PageHeader.svelte +21 -8
- package/dist/components/compounds/PageHeader.svelte.d.ts +21 -8
- package/dist/components/compounds/Pagination.svelte +34 -8
- package/dist/components/compounds/Pagination.svelte.d.ts +20 -0
- package/dist/components/compounds/Popover.svelte +11 -0
- package/dist/components/compounds/Popover.svelte.d.ts +20 -0
- package/dist/components/compounds/PullRefresh.svelte +24 -0
- package/dist/components/compounds/PullRefresh.svelte.d.ts +32 -0
- package/dist/components/compounds/Result.svelte +11 -0
- package/dist/components/compounds/Result.svelte.d.ts +20 -0
- package/dist/components/compounds/SafeArea.svelte +24 -0
- package/dist/components/compounds/SafeArea.svelte.d.ts +32 -0
- package/dist/components/compounds/Skeleton.svelte +10 -0
- package/dist/components/compounds/Skeleton.svelte.d.ts +10 -0
- package/dist/components/compounds/Steps.svelte +11 -0
- package/dist/components/compounds/Steps.svelte.d.ts +20 -0
- package/dist/components/compounds/SwipeCell.svelte +24 -0
- package/dist/components/compounds/SwipeCell.svelte.d.ts +37 -0
- package/dist/components/compounds/TableToolbar.svelte +66 -28
- package/dist/components/compounds/TableToolbar.svelte.d.ts +29 -19
- package/dist/components/compounds/Tabs.svelte +58 -10
- package/dist/components/compounds/Tabs.svelte.d.ts +10 -0
- package/dist/components/compounds/TagInput.svelte +11 -0
- package/dist/components/compounds/TagInput.svelte.d.ts +20 -0
- package/dist/components/compounds/Timeline.svelte +24 -0
- package/dist/components/compounds/Timeline.svelte.d.ts +34 -0
- package/dist/components/compounds/ToastContainer.svelte +11 -0
- package/dist/components/compounds/ToastContainer.svelte.d.ts +26 -0
- package/dist/components/compounds/Tooltip.svelte +11 -0
- package/dist/components/compounds/Tooltip.svelte.d.ts +22 -0
- package/dist/components/compounds/accordion-types.d.ts +10 -1
- package/dist/components/compounds/action-sheet-types.d.ts +9 -0
- package/dist/components/compounds/bottom-nav-types.d.ts +9 -0
- package/dist/components/compounds/swipe-cell-types.d.ts +9 -0
- package/dist/components/compounds/timeline-types.d.ts +9 -0
- package/dist/components/control-size.d.ts +17 -0
- package/dist/components/control-size.js +8 -0
- package/dist/components/primitives/Avatar.svelte +10 -0
- package/dist/components/primitives/Avatar.svelte.d.ts +10 -0
- package/dist/components/primitives/Badge.svelte +10 -0
- package/dist/components/primitives/Badge.svelte.d.ts +10 -0
- package/dist/components/primitives/BareButton.svelte +11 -0
- package/dist/components/primitives/BareButton.svelte.d.ts +20 -0
- package/dist/components/primitives/BareInput.svelte +11 -0
- package/dist/components/primitives/BareInput.svelte.d.ts +20 -0
- package/dist/components/primitives/Button.svelte +10 -0
- package/dist/components/primitives/Button.svelte.d.ts +10 -0
- package/dist/components/primitives/Checkbox.svelte +11 -0
- package/dist/components/primitives/Checkbox.svelte.d.ts +20 -0
- package/dist/components/primitives/IconButton.svelte +11 -0
- package/dist/components/primitives/IconButton.svelte.d.ts +20 -0
- package/dist/components/primitives/Input.svelte +10 -0
- package/dist/components/primitives/Input.svelte.d.ts +10 -0
- package/dist/components/primitives/Progress.svelte +11 -0
- package/dist/components/primitives/Progress.svelte.d.ts +20 -0
- package/dist/components/primitives/Radio.svelte +11 -0
- package/dist/components/primitives/Radio.svelte.d.ts +20 -0
- package/dist/components/primitives/Range.svelte +24 -0
- package/dist/components/primitives/Range.svelte.d.ts +34 -0
- package/dist/components/primitives/Rating.svelte +24 -0
- package/dist/components/primitives/Rating.svelte.d.ts +34 -0
- package/dist/components/primitives/Select.svelte +11 -0
- package/dist/components/primitives/Select.svelte.d.ts +21 -0
- package/dist/components/primitives/Spinner.svelte +11 -0
- package/dist/components/primitives/Spinner.svelte.d.ts +20 -0
- package/dist/components/primitives/Switch.svelte +11 -0
- package/dist/components/primitives/Switch.svelte.d.ts +20 -0
- package/dist/components/primitives/Tag.svelte +11 -0
- package/dist/components/primitives/Tag.svelte.d.ts +20 -0
- package/dist/components/primitives/Textarea.svelte +11 -0
- package/dist/components/primitives/Textarea.svelte.d.ts +21 -0
- package/dist/components/primitives/ToggleCheckbox.svelte +11 -0
- package/dist/components/primitives/ToggleCheckbox.svelte.d.ts +20 -0
- package/dist/components/primitives/ToggleInput.svelte +11 -0
- package/dist/components/primitives/ToggleInput.svelte.d.ts +20 -0
- package/dist/components/primitives/ToggleRadio.svelte +11 -0
- package/dist/components/primitives/ToggleRadio.svelte.d.ts +20 -0
- package/dist/components/scenes/ai/AiDocumentDownloadMenu.svelte +27 -0
- package/dist/components/scenes/ai/AiDocumentDownloadMenu.svelte.d.ts +27 -0
- package/dist/components/scenes/ai/AiDocumentEditor.svelte +79 -0
- package/dist/components/scenes/ai/AiDocumentEditor.svelte.d.ts +23 -0
- package/dist/components/scenes/ai/MarkdownRenderer.svelte +11 -0
- package/dist/components/scenes/ai/MarkdownRenderer.svelte.d.ts +28 -0
- package/dist/components/scenes/ai/code-preview.d.ts +28 -0
- package/dist/components/scenes/ai/code-preview.js +20 -0
- package/dist/components/scenes/ai/document-download.d.ts +52 -0
- package/dist/components/scenes/ai/document-download.js +30 -2
- package/dist/components/scenes/ai/document-parse.d.ts +71 -14
- package/dist/components/scenes/ai/document-parse.js +19 -9
- package/dist/components/scenes/ai/document-types.d.ts +222 -88
- package/dist/components/scenes/ai/editor-markdown-extensions.d.ts +16 -0
- package/dist/components/scenes/ai/editor-markdown-extensions.js +16 -0
- package/dist/components/scenes/ai/highlight.d.ts +11 -0
- package/dist/components/scenes/ai/highlight.js +11 -0
- package/dist/components/scenes/ai/markdown-parse.d.ts +8 -2
- package/dist/components/scenes/ai/markdown-parse.js +2 -2
- package/dist/components/scenes/ai/mermaid-host-sync.d.ts +38 -0
- package/dist/components/scenes/ai/mermaid-host-sync.js +30 -0
- package/dist/components/scenes/ai/mermaid-render.d.ts +23 -0
- package/dist/components/scenes/ai/mermaid-render.js +23 -0
- package/dist/components/scenes/ai/safe-html.d.ts +54 -6
- package/dist/components/scenes/ai/safe-html.js +54 -6
- package/dist/components/scenes/ai/table/AiTableEditor.svelte +48 -0
- package/dist/components/scenes/ai/table/AiTableEditor.svelte.d.ts +24 -0
- package/dist/components/scenes/ai/table/table-types.d.ts +79 -0
- package/dist/components/scenes/app/FeedbackModal.svelte +45 -5
- package/dist/components/scenes/app/FeedbackModal.svelte.d.ts +45 -5
- package/dist/components/scenes/app/LanguageSwitch.svelte +29 -19
- package/dist/components/scenes/app/LanguageSwitch.svelte.d.ts +28 -19
- package/dist/components/scenes/app/SettingsLayout.svelte +21 -9
- package/dist/components/scenes/app/SettingsLayout.svelte.d.ts +21 -9
- package/dist/components/scenes/app/SettingsModal.svelte +23 -0
- package/dist/components/scenes/app/SettingsModal.svelte.d.ts +23 -0
- package/dist/components/scenes/app/ThemeColorPicker.svelte +31 -0
- package/dist/components/scenes/app/ThemeColorPicker.svelte.d.ts +31 -0
- package/dist/components/scenes/app/ThemeSelector.svelte +21 -6
- package/dist/components/scenes/app/ThemeSelector.svelte.d.ts +21 -6
- package/dist/components/scenes/app/ThemeToggle.svelte +21 -4
- package/dist/components/scenes/app/ThemeToggle.svelte.d.ts +21 -4
- package/dist/components/scenes/app/index.d.ts +1 -1
- package/dist/components/scenes/app/index.js +1 -1
- package/dist/components/scenes/charts/Chart.svelte +11 -0
- package/dist/components/scenes/charts/Chart.svelte.d.ts +20 -0
- package/dist/components/scenes/charts/chart-theme.d.ts +25 -1
- package/dist/components/scenes/charts/chart-theme.js +25 -1
- package/dist/components/scenes/charts/chart-types.d.ts +83 -7
- package/dist/components/scenes/charts/renderers/LineChart.svelte +53 -0
- package/dist/components/scenes/charts/renderers/LineChart.svelte.d.ts +13 -0
- package/dist/components/scenes/crud/CrudDeleteConfirm.svelte +10 -0
- package/dist/components/scenes/crud/CrudDeleteConfirm.svelte.d.ts +10 -0
- package/dist/components/scenes/crud/CrudDetailDrawer.svelte +8 -0
- package/dist/components/scenes/crud/CrudDetailDrawer.svelte.d.ts +8 -0
- package/dist/components/scenes/crud/CrudDetailPanel.svelte +18 -0
- package/dist/components/scenes/crud/CrudDetailPanel.svelte.d.ts +18 -0
- package/dist/components/scenes/crud/CrudEditPanel.svelte +10 -0
- package/dist/components/scenes/crud/CrudEditPanel.svelte.d.ts +10 -0
- package/dist/components/scenes/crud/CrudFilterBar.svelte +18 -0
- package/dist/components/scenes/crud/CrudFilterBar.svelte.d.ts +18 -0
- package/dist/components/scenes/crud/CrudPage.svelte +37 -5
- package/dist/components/scenes/crud/CrudPage.svelte.d.ts +35 -3
- package/dist/components/scenes/crud/crud-controller.svelte.d.ts +142 -23
- package/dist/components/scenes/crud/crud-controller.svelte.js +22 -11
- package/dist/components/scenes/crud/crud-form-validation.d.ts +12 -0
- package/dist/components/scenes/crud/crud-form-validation.js +12 -0
- package/dist/components/scenes/crud/crud-types.d.ts +79 -8
- package/dist/components/scenes/crud/nav-adapter.d.ts +14 -0
- package/dist/components/scenes/crud/nav-adapter.js +8 -0
- package/dist/components/scenes/crypto/EncryptedInput.svelte +24 -0
- package/dist/components/scenes/crypto/EncryptedInput.svelte.d.ts +34 -0
- package/dist/components/scenes/crypto/HashDisplay.svelte +11 -0
- package/dist/components/scenes/crypto/HashDisplay.svelte.d.ts +21 -0
- package/dist/components/scenes/crypto/SignatureDisplay.svelte +11 -0
- package/dist/components/scenes/crypto/SignatureDisplay.svelte.d.ts +21 -0
- package/dist/components/scenes/error/ErrorPage.svelte +8 -1
- package/dist/components/scenes/error/ErrorPage.svelte.d.ts +8 -1
- package/dist/components/scenes/error/error-presets.d.ts +40 -4
- package/dist/components/scenes/error/error-presets.js +22 -2
- package/dist/components/scenes/guide/GuideHost.svelte +27 -0
- package/dist/components/scenes/guide/GuideHost.svelte.d.ts +27 -0
- package/dist/components/scenes/guide/HelpCenter.svelte +27 -0
- package/dist/components/scenes/guide/HelpCenter.svelte.d.ts +27 -0
- package/dist/components/scenes/iam/AuthPanel.svelte +26 -2
- package/dist/components/scenes/iam/AuthPanel.svelte.d.ts +25 -0
- package/dist/components/scenes/iam/AuthShell.svelte +8 -3
- package/dist/components/scenes/iam/AuthShell.svelte.d.ts +8 -3
- package/dist/components/scenes/iam/ChangePasswordForm.svelte +10 -0
- package/dist/components/scenes/iam/ChangePasswordForm.svelte.d.ts +10 -0
- package/dist/components/scenes/iam/ForgotPasswordForm.svelte +11 -0
- package/dist/components/scenes/iam/ForgotPasswordForm.svelte.d.ts +21 -0
- package/dist/components/scenes/iam/LoginForm.svelte +24 -31
- package/dist/components/scenes/iam/LoginForm.svelte.d.ts +10 -0
- package/dist/components/scenes/iam/PasswordInput.svelte +23 -0
- package/dist/components/scenes/iam/PasswordInput.svelte.d.ts +23 -0
- package/dist/components/scenes/iam/PermGuard.svelte +21 -11
- package/dist/components/scenes/iam/PermGuard.svelte.d.ts +30 -0
- package/dist/components/scenes/iam/RegisterForm.svelte +10 -0
- package/dist/components/scenes/iam/RegisterForm.svelte.d.ts +10 -0
- package/dist/components/scenes/iam/ResetPasswordForm.svelte +10 -0
- package/dist/components/scenes/iam/ResetPasswordForm.svelte.d.ts +10 -0
- package/dist/components/scenes/iam/UserProfile.svelte +11 -0
- package/dist/components/scenes/iam/UserProfile.svelte.d.ts +21 -0
- package/dist/components/scenes/iam/auth-error-message.d.ts +10 -0
- package/dist/components/scenes/iam/auth-error-message.js +10 -0
- package/dist/components/scenes/iam/password-utils.d.ts +39 -1
- package/dist/components/scenes/iam/password-utils.js +39 -1
- package/dist/components/scenes/iam/permission-context.svelte.d.ts +33 -23
- package/dist/components/scenes/iam/permission-context.svelte.js +20 -22
- package/dist/components/scenes/storage/AvatarUpload.svelte +11 -0
- package/dist/components/scenes/storage/AvatarUpload.svelte.d.ts +20 -0
- package/dist/components/scenes/storage/FileList.svelte +13 -2
- package/dist/components/scenes/storage/FileList.svelte.d.ts +20 -0
- package/dist/components/scenes/storage/FileUpload.svelte +37 -2
- package/dist/components/scenes/storage/FileUpload.svelte.d.ts +21 -0
- package/dist/components/scenes/storage/ImageUpload.svelte +11 -0
- package/dist/components/scenes/storage/ImageUpload.svelte.d.ts +21 -0
- package/dist/components/scenes/types.d.ts +352 -11
- package/dist/guide-storage.d.ts +13 -1
- package/dist/guide-storage.js +13 -1
- package/dist/guide-types.d.ts +67 -2
- package/dist/guide.svelte.d.ts +22 -1
- package/dist/guide.svelte.js +22 -1
- package/dist/i18n.svelte.d.ts +64 -3
- package/dist/i18n.svelte.js +99 -18
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -2
- package/dist/internal/browser-safety.d.ts +51 -2
- package/dist/internal/browser-safety.js +45 -7
- package/dist/internal/form-context.d.ts +73 -0
- package/dist/internal/form-context.js +57 -0
- package/dist/internal/form-validation.svelte.d.ts +42 -0
- package/dist/internal/form-validation.svelte.js +26 -0
- package/dist/internal/icon-safety.d.ts +7 -0
- package/dist/internal/icon-safety.js +7 -0
- package/dist/internal/locale.d.ts +19 -0
- package/dist/internal/locale.js +21 -0
- package/dist/message.svelte.d.ts +90 -0
- package/dist/message.svelte.js +84 -0
- package/dist/messagebox.svelte.d.ts +61 -13
- package/dist/messagebox.svelte.js +55 -13
- package/dist/messages/en-US.json +6 -1
- package/dist/messages/ja-JP.json +389 -0
- package/dist/messages/zh-CN.json +6 -1
- package/dist/messages.d.ts +24 -3
- package/dist/messages.js +18 -3
- package/dist/styles/design-tokens.css +4 -2
- package/dist/styles/global.css +28 -8
- package/dist/styles/theme.css +2 -0
- package/dist/theme-config.d.ts +173 -0
- package/dist/theme-config.js +143 -0
- package/dist/toast.svelte.d.ts +114 -4
- package/dist/toast.svelte.js +108 -4
- package/dist/types.d.ts +526 -9
- package/dist/utils/platform.svelte.d.ts +28 -15
- package/dist/utils/platform.svelte.js +19 -14
- package/dist/utils.d.ts +102 -0
- package/dist/utils.js +93 -0
- package/package.json +66 -6
package/dist/theme-config.js
CHANGED
|
@@ -7,6 +7,12 @@
|
|
|
7
7
|
import { readStoredValue, writeStoredValue } from './internal/browser-safety.js';
|
|
8
8
|
/**
|
|
9
9
|
* DaisyUI 内置主题配置(精选)
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { THEMES } from '@h-ai/ui'
|
|
14
|
+
* const choices = THEMES.map(theme => ({ value: theme.id, label: theme.name }))
|
|
15
|
+
* ```
|
|
10
16
|
*/
|
|
11
17
|
export const THEMES = [
|
|
12
18
|
// 亮色主题
|
|
@@ -29,6 +35,13 @@ export const THEMES = [
|
|
|
29
35
|
];
|
|
30
36
|
/**
|
|
31
37
|
* 主题分组配置
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { THEME_GROUPS } from '@h-ai/ui'
|
|
42
|
+
* const light = THEME_GROUPS.find(group => group.id === 'light')
|
|
43
|
+
* const choices = light?.themes
|
|
44
|
+
* ```
|
|
32
45
|
*/
|
|
33
46
|
export const THEME_GROUPS = [
|
|
34
47
|
{
|
|
@@ -44,22 +57,52 @@ export const THEME_GROUPS = [
|
|
|
44
57
|
];
|
|
45
58
|
/**
|
|
46
59
|
* 暗色主题列表
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { DARK_THEMES } from '@h-ai/ui'
|
|
64
|
+
* const dark = DARK_THEMES.includes('dark')
|
|
65
|
+
* ```
|
|
47
66
|
*/
|
|
48
67
|
export const DARK_THEMES = THEMES.filter(t => t.dark).map(t => t.id);
|
|
49
68
|
/**
|
|
50
69
|
* 支持的主题 ID 列表
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { SUPPORTED_THEME_IDS } from '@h-ai/ui'
|
|
74
|
+
* const supported = SUPPORTED_THEME_IDS.includes('light')
|
|
75
|
+
* ```
|
|
51
76
|
*/
|
|
52
77
|
export const SUPPORTED_THEME_IDS = THEMES.map(theme => theme.id);
|
|
53
78
|
/**
|
|
54
79
|
* 默认主题色
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* import { DEFAULT_THEME_COLOR } from '@h-ai/ui'
|
|
84
|
+
* const style = { '--brand-color': DEFAULT_THEME_COLOR }
|
|
85
|
+
* ```
|
|
55
86
|
*/
|
|
56
87
|
export const DEFAULT_THEME_COLOR = '#5765f0';
|
|
57
88
|
/**
|
|
58
89
|
* 主题色 CSS 变量名
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { DEFAULT_THEME_COLOR_CSS_VAR } from '@h-ai/ui'
|
|
94
|
+
* document.documentElement.style.setProperty(DEFAULT_THEME_COLOR_CSS_VAR, '#2563eb')
|
|
95
|
+
* ```
|
|
59
96
|
*/
|
|
60
97
|
export const DEFAULT_THEME_COLOR_CSS_VAR = '--hai-theme-color-default';
|
|
61
98
|
/**
|
|
62
99
|
* 内置主题色预设
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* import { THEME_COLOR_PRESETS } from '@h-ai/ui'
|
|
104
|
+
* const options = THEME_COLOR_PRESETS.map(preset => ({ value: preset.value, labelKey: preset.labelKey }))
|
|
105
|
+
* ```
|
|
63
106
|
*/
|
|
64
107
|
export const THEME_COLOR_PRESETS = [
|
|
65
108
|
{ value: DEFAULT_THEME_COLOR, labelKey: 'theme_color_tech_purple' },
|
|
@@ -71,26 +114,65 @@ const SHORT_HEX_COLOR_REGEX = /^#[0-9a-f]{3}$/i;
|
|
|
71
114
|
const SUPPORTED_THEME_ID_SET = new Set(SUPPORTED_THEME_IDS);
|
|
72
115
|
/**
|
|
73
116
|
* 默认主题
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { DEFAULT_THEME, applyTheme } from '@h-ai/ui'
|
|
121
|
+
* applyTheme(DEFAULT_THEME, false)
|
|
122
|
+
* ```
|
|
74
123
|
*/
|
|
75
124
|
export const DEFAULT_THEME = 'light';
|
|
76
125
|
/**
|
|
77
126
|
* 主题存储键名
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* import { THEME_STORAGE_KEY, getSavedTheme } from '@h-ai/ui'
|
|
131
|
+
* const preference = { key: THEME_STORAGE_KEY, value: getSavedTheme('light') }
|
|
132
|
+
* // 通过公开安全读取函数消费偏好,不直接访问受限存储。
|
|
133
|
+
* ```
|
|
78
134
|
*/
|
|
79
135
|
export const THEME_STORAGE_KEY = 'theme';
|
|
80
136
|
/**
|
|
81
137
|
* 获取主题信息
|
|
138
|
+
* @param themeId - 主题候选 ID。
|
|
139
|
+
* @returns 匹配的主题元数据,不存在时返回 undefined。
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* import { getThemeInfo } from '@h-ai/ui'
|
|
144
|
+
* const theme = getThemeInfo('light')
|
|
145
|
+
* const background = theme?.bgColor
|
|
146
|
+
* ```
|
|
82
147
|
*/
|
|
83
148
|
export function getThemeInfo(themeId) {
|
|
84
149
|
return THEMES.find(t => t.id === themeId);
|
|
85
150
|
}
|
|
86
151
|
/**
|
|
87
152
|
* 检查是否为暗色主题
|
|
153
|
+
* @param themeId - 主题候选 ID。
|
|
154
|
+
* @returns 是否属于内置暗色主题。
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* import { isDarkTheme } from '@h-ai/ui'
|
|
159
|
+
* const dark = isDarkTheme('dark')
|
|
160
|
+
* ```
|
|
88
161
|
*/
|
|
89
162
|
export function isDarkTheme(themeId) {
|
|
90
163
|
return DARK_THEMES.includes(themeId);
|
|
91
164
|
}
|
|
92
165
|
/**
|
|
93
166
|
* 归一化主题 ID,不支持的值回退到默认主题。
|
|
167
|
+
* @param themeId - 主题候选 ID。
|
|
168
|
+
* @param fallbackThemeId - 候选不支持时尝试的主题。
|
|
169
|
+
* @returns 支持的主题 ID;无效输入按候选和默认主题回退。
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* import { normalizeThemeId } from '@h-ai/ui'
|
|
174
|
+
* const theme = normalizeThemeId('unknown-theme', 'light')
|
|
175
|
+
* ```
|
|
94
176
|
*/
|
|
95
177
|
export function normalizeThemeId(themeId, fallbackThemeId = DEFAULT_THEME) {
|
|
96
178
|
const normalized = `${themeId ?? ''}`;
|
|
@@ -101,6 +183,14 @@ export function normalizeThemeId(themeId, fallbackThemeId = DEFAULT_THEME) {
|
|
|
101
183
|
}
|
|
102
184
|
/**
|
|
103
185
|
* 归一化 Hex 颜色;无效值返回 null。
|
|
186
|
+
* @param value - 待处理或校验的值。
|
|
187
|
+
* @returns 小写六位 Hex 颜色;无效输入返回 null。
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* import { normalizeHexColor } from '@h-ai/ui'
|
|
192
|
+
* const color = normalizeHexColor('#abc')
|
|
193
|
+
* ```
|
|
104
194
|
*/
|
|
105
195
|
export function normalizeHexColor(value) {
|
|
106
196
|
const normalized = value?.trim().toLowerCase() ?? '';
|
|
@@ -114,6 +204,14 @@ export function normalizeHexColor(value) {
|
|
|
114
204
|
}
|
|
115
205
|
/**
|
|
116
206
|
* 解析主题对应的浏览器色调。
|
|
207
|
+
* @param themeId - 主题候选 ID。
|
|
208
|
+
* @returns 供浏览器控件配色使用的 light/dark 值。
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```ts
|
|
212
|
+
* import { resolveThemeTone } from '@h-ai/ui'
|
|
213
|
+
* const tone = resolveThemeTone('dark')
|
|
214
|
+
* ```
|
|
117
215
|
*/
|
|
118
216
|
export function resolveThemeTone(themeId) {
|
|
119
217
|
return isDarkTheme(themeId) ? 'dark' : 'light';
|
|
@@ -127,6 +225,15 @@ function escapeJsonForScript(value) {
|
|
|
127
225
|
}
|
|
128
226
|
/**
|
|
129
227
|
* 生成首屏主题恢复脚本,适合注入到 SvelteKit `app.html` 的 `<script>` 中。
|
|
228
|
+
* @param options - 本次操作的行为与显示选项。
|
|
229
|
+
* @returns 可放入受控 HTML shell 的初始化脚本文本。
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```ts
|
|
233
|
+
* import { createThemeBootstrapScript } from '@h-ai/ui'
|
|
234
|
+
* const script = createThemeBootstrapScript({ storageKey: 'demo-theme', defaultThemeId: 'light' })
|
|
235
|
+
* // 在应用 HTML shell 中作为受控脚本使用,避免首屏主题闪烁。
|
|
236
|
+
* ```
|
|
130
237
|
*/
|
|
131
238
|
export function createThemeBootstrapScript(options) {
|
|
132
239
|
const defaultThemeId = normalizeThemeId(options.defaultThemeId ?? DEFAULT_THEME);
|
|
@@ -156,6 +263,13 @@ export function createThemeBootstrapScript(options) {
|
|
|
156
263
|
*
|
|
157
264
|
* 返回值是“脚本标签内的文本内容”,适合宿主在构建阶段或服务端模板中注入。
|
|
158
265
|
* 对于 SvelteKit `app.html`,请直接粘贴这段脚本字符串的内容,不能写 `{@html getThemeInitScript()}`。
|
|
266
|
+
* @returns 使用默认存储约定的主题初始化脚本。
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```ts
|
|
270
|
+
* import { getThemeInitScript } from '@h-ai/ui'
|
|
271
|
+
* const script = getThemeInitScript()
|
|
272
|
+
* ```
|
|
159
273
|
*/
|
|
160
274
|
export function getThemeInitScript() {
|
|
161
275
|
return createThemeBootstrapScript({
|
|
@@ -167,6 +281,14 @@ export function getThemeInitScript() {
|
|
|
167
281
|
* 应用主题
|
|
168
282
|
* @param theme - 主题 ID
|
|
169
283
|
* @param persist - 是否持久化到 localStorage
|
|
284
|
+
* @returns {void} 无返回值;更新当前文档,并按 persist 决定是否保存偏好。
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```ts
|
|
288
|
+
* import { applyTheme } from '@h-ai/ui'
|
|
289
|
+
* applyTheme('dark', false)
|
|
290
|
+
* // false 仅更新当前 DOM,不写入持久化偏好。
|
|
291
|
+
* ```
|
|
170
292
|
*/
|
|
171
293
|
export function applyTheme(theme, persist = true) {
|
|
172
294
|
if (typeof document === 'undefined')
|
|
@@ -178,6 +300,13 @@ export function applyTheme(theme, persist = true) {
|
|
|
178
300
|
}
|
|
179
301
|
/**
|
|
180
302
|
* 获取当前主题
|
|
303
|
+
* @returns 当前文档主题;无 DOM 时使用默认值。
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* ```ts
|
|
307
|
+
* import { getCurrentTheme } from '@h-ai/ui'
|
|
308
|
+
* const theme = getCurrentTheme()
|
|
309
|
+
* ```
|
|
181
310
|
*/
|
|
182
311
|
export function getCurrentTheme() {
|
|
183
312
|
if (typeof document === 'undefined')
|
|
@@ -188,6 +317,13 @@ export function getCurrentTheme() {
|
|
|
188
317
|
* 获取保存的主题;存储为空或不可用时使用宿主默认主题。
|
|
189
318
|
*
|
|
190
319
|
* @param fallbackTheme - 未保存主题时的默认值,默认 light
|
|
320
|
+
* @returns 安全读取并归一化的主题偏好。
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* ```ts
|
|
324
|
+
* import { getSavedTheme } from '@h-ai/ui'
|
|
325
|
+
* const theme = getSavedTheme('light')
|
|
326
|
+
* ```
|
|
191
327
|
*/
|
|
192
328
|
export function getSavedTheme(fallbackTheme = DEFAULT_THEME) {
|
|
193
329
|
return readStoredValue(THEME_STORAGE_KEY) ?? fallbackTheme;
|
|
@@ -201,6 +337,13 @@ export function getSavedTheme(fallbackTheme = DEFAULT_THEME) {
|
|
|
201
337
|
* @plugin "daisyui" {
|
|
202
338
|
* themes: light --default, dark --prefersdark, cupcake, bumblebee, ...
|
|
203
339
|
* }
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```ts
|
|
343
|
+
* import { DAISYUI_THEMES_CONFIG } from '@h-ai/ui'
|
|
344
|
+
* const css = '@plugin "daisyui" { themes: ' + DAISYUI_THEMES_CONFIG + '; }'
|
|
345
|
+
* // 将生成的配置用于构建时 CSS,不在浏览器动态安装主题。
|
|
346
|
+
* ```
|
|
204
347
|
*/
|
|
205
348
|
export const DAISYUI_THEMES_CONFIG = THEMES.map((t, i) => {
|
|
206
349
|
if (i === 0)
|
package/dist/toast.svelte.d.ts
CHANGED
|
@@ -7,6 +7,12 @@
|
|
|
7
7
|
import type { ToastProps } from './types.js';
|
|
8
8
|
/**
|
|
9
9
|
* Toast 项
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import type { ToastItem } from '@h-ai/ui'
|
|
14
|
+
* const example: ToastItem = { id: 'toast-1', message: '保存完成', variant: 'success', duration: 3000 }
|
|
15
|
+
* ```
|
|
10
16
|
*/
|
|
11
17
|
export interface ToastItem extends ToastProps {
|
|
12
18
|
id: string;
|
|
@@ -20,26 +26,110 @@ declare class ToastState {
|
|
|
20
26
|
private timers;
|
|
21
27
|
/**
|
|
22
28
|
* 添加 Toast
|
|
29
|
+
* @param props - 组件的属性对象。
|
|
30
|
+
* @returns 新条目的 ID,可用于提前移除。
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { toast } from '@h-ai/ui'
|
|
34
|
+
* // 布局中需挂载 ToastContainer。
|
|
35
|
+
* const id = toast.add({ message: '保存完成', variant: 'success', duration: 3000 })
|
|
36
|
+
* toast.remove(id)
|
|
37
|
+
* ```
|
|
23
38
|
*/
|
|
24
39
|
add(props: Omit<ToastProps, 'onclose'>): string;
|
|
25
40
|
/**
|
|
26
41
|
* 移除 Toast
|
|
42
|
+
* @param id - 待移除的条目 ID。
|
|
43
|
+
* @returns {void} 无返回值;同时清理对应的自动关闭定时器。
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { toast } from '@h-ai/ui'
|
|
47
|
+
* // 布局中需挂载 ToastContainer。
|
|
48
|
+
* const id = toast.info('同步中', 0)
|
|
49
|
+
* toast.remove(id)
|
|
50
|
+
* ```
|
|
27
51
|
*/
|
|
28
52
|
remove(id: string): void;
|
|
29
53
|
/**
|
|
30
54
|
* 清空所有 Toast
|
|
55
|
+
* @returns {void} 无返回值;同时清理对应的自动关闭定时器。
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { toast } from '@h-ai/ui'
|
|
59
|
+
* // 布局中需挂载 ToastContainer。
|
|
60
|
+
* toast.info('同步中', 0)
|
|
61
|
+
* toast.clear()
|
|
62
|
+
* ```
|
|
31
63
|
*/
|
|
32
64
|
clear(): void;
|
|
33
65
|
/**
|
|
34
66
|
* 快捷方法
|
|
67
|
+
* @param message - 已经本地化的用户提示。
|
|
68
|
+
* @param duration - 提示持续时间,单位毫秒。
|
|
69
|
+
* @returns 新条目的 ID,可用于提前移除。
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* import { toast } from '@h-ai/ui'
|
|
73
|
+
* // 布局中需挂载 ToastContainer。
|
|
74
|
+
* const id = toast.success('操作结果', 3000)
|
|
75
|
+
* toast.remove(id)
|
|
76
|
+
* ```
|
|
35
77
|
*/
|
|
36
78
|
success(message: string, duration?: number): string;
|
|
79
|
+
/**
|
|
80
|
+
* 处理 error 操作。
|
|
81
|
+
* @param message - 已经本地化的用户提示。
|
|
82
|
+
* @param duration - 提示持续时间,单位毫秒。
|
|
83
|
+
* @returns 新条目的 ID,可用于提前移除。
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* import { toast } from '@h-ai/ui'
|
|
87
|
+
* // 布局中需挂载 ToastContainer。
|
|
88
|
+
* const id = toast.error('操作结果', 3000)
|
|
89
|
+
* toast.remove(id)
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
37
92
|
error(message: string, duration?: number): string;
|
|
93
|
+
/**
|
|
94
|
+
* 处理 warning 操作。
|
|
95
|
+
* @param message - 已经本地化的用户提示。
|
|
96
|
+
* @param duration - 提示持续时间,单位毫秒。
|
|
97
|
+
* @returns 新条目的 ID,可用于提前移除。
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { toast } from '@h-ai/ui'
|
|
101
|
+
* // 布局中需挂载 ToastContainer。
|
|
102
|
+
* const id = toast.warning('操作结果', 3000)
|
|
103
|
+
* toast.remove(id)
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
38
106
|
warning(message: string, duration?: number): string;
|
|
107
|
+
/**
|
|
108
|
+
* 处理 info 操作。
|
|
109
|
+
* @param message - 已经本地化的用户提示。
|
|
110
|
+
* @param duration - 提示持续时间,单位毫秒。
|
|
111
|
+
* @returns 新条目的 ID,可用于提前移除。
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* import { toast } from '@h-ai/ui'
|
|
115
|
+
* // 布局中需挂载 ToastContainer。
|
|
116
|
+
* const id = toast.info('操作结果', 3000)
|
|
117
|
+
* toast.remove(id)
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
39
120
|
info(message: string, duration?: number): string;
|
|
40
121
|
}
|
|
41
122
|
/**
|
|
42
123
|
* Toast 单例
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* import { toast } from '@h-ai/ui'
|
|
128
|
+
* // 页面布局需挂载 ToastContainer。
|
|
129
|
+
* const id = toast.success('保存完成', 3000)
|
|
130
|
+
* toast.remove(id)
|
|
131
|
+
* toast.clear()
|
|
132
|
+
* ```
|
|
43
133
|
*/
|
|
44
134
|
export declare const toast: ToastState;
|
|
45
135
|
/**
|
|
@@ -49,9 +139,14 @@ export declare const toast: ToastState;
|
|
|
49
139
|
*
|
|
50
140
|
* @param message - 用户可见的成功文案(已本地化)。
|
|
51
141
|
* @param duration - 可选停留时长(毫秒),默认 3000。
|
|
142
|
+
* @returns 新通知的 ID,可交给 toast.remove 提前移除。
|
|
52
143
|
*
|
|
53
144
|
* @example
|
|
54
|
-
*
|
|
145
|
+
* ```ts
|
|
146
|
+
* import { notifySuccess, toast } from '@h-ai/ui'
|
|
147
|
+
* const id = notifySuccess('保存完成', 3000)
|
|
148
|
+
* toast.remove(id)
|
|
149
|
+
* ```
|
|
55
150
|
*/
|
|
56
151
|
export declare function notifySuccess(message: string, duration?: number): string;
|
|
57
152
|
/**
|
|
@@ -63,9 +158,14 @@ export declare function notifySuccess(message: string, duration?: number): strin
|
|
|
63
158
|
* @param error - 错误对象或已本地化的错误文案。
|
|
64
159
|
* @param fallback - 当 error 非 Error 且为空时使用的兜底文案。
|
|
65
160
|
* @param duration - 可选停留时长(毫秒),默认 5000。
|
|
161
|
+
* @returns 新错误通知的 ID,可交给 toast.remove 提前移除。
|
|
66
162
|
*
|
|
67
163
|
* @example
|
|
68
|
-
*
|
|
164
|
+
* ```ts
|
|
165
|
+
* import { notifyError, toast } from '@h-ai/ui'
|
|
166
|
+
* const id = notifyError(new Error('提交失败'), '请稍后重试', 5000)
|
|
167
|
+
* toast.remove(id)
|
|
168
|
+
* ```
|
|
69
169
|
*/
|
|
70
170
|
export declare function notifyError(error: unknown, fallback?: string, duration?: number): string;
|
|
71
171
|
/**
|
|
@@ -73,9 +173,14 @@ export declare function notifyError(error: unknown, fallback?: string, duration?
|
|
|
73
173
|
*
|
|
74
174
|
* @param message - 用户可见文案(已本地化)。
|
|
75
175
|
* @param duration - 可选停留时长(毫秒),默认 3000。
|
|
176
|
+
* @returns 新提示的 ID。
|
|
76
177
|
*
|
|
77
178
|
* @example
|
|
78
|
-
*
|
|
179
|
+
* ```ts
|
|
180
|
+
* import { notifyInfo, toast } from '@h-ai/ui'
|
|
181
|
+
* const id = notifyInfo('正在同步', 3000)
|
|
182
|
+
* toast.remove(id)
|
|
183
|
+
* ```
|
|
79
184
|
*/
|
|
80
185
|
export declare function notifyInfo(message: string, duration?: number): string;
|
|
81
186
|
/**
|
|
@@ -83,9 +188,14 @@ export declare function notifyInfo(message: string, duration?: number): string;
|
|
|
83
188
|
*
|
|
84
189
|
* @param message - 用户可见文案(已本地化)。
|
|
85
190
|
* @param duration - 可选停留时长(毫秒),默认 5000。
|
|
191
|
+
* @returns 新警告的 ID。
|
|
86
192
|
*
|
|
87
193
|
* @example
|
|
88
|
-
*
|
|
194
|
+
* ```ts
|
|
195
|
+
* import { notifyWarning, toast } from '@h-ai/ui'
|
|
196
|
+
* const id = notifyWarning('请先保存修改', 5000)
|
|
197
|
+
* toast.remove(id)
|
|
198
|
+
* ```
|
|
89
199
|
*/
|
|
90
200
|
export declare function notifyWarning(message: string, duration?: number): string;
|
|
91
201
|
export {};
|
package/dist/toast.svelte.js
CHANGED
|
@@ -13,6 +13,15 @@ class ToastState {
|
|
|
13
13
|
timers = new Map();
|
|
14
14
|
/**
|
|
15
15
|
* 添加 Toast
|
|
16
|
+
* @param props - 组件的属性对象。
|
|
17
|
+
* @returns 新条目的 ID,可用于提前移除。
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { toast } from '@h-ai/ui'
|
|
21
|
+
* // 布局中需挂载 ToastContainer。
|
|
22
|
+
* const id = toast.add({ message: '保存完成', variant: 'success', duration: 3000 })
|
|
23
|
+
* toast.remove(id)
|
|
24
|
+
* ```
|
|
16
25
|
*/
|
|
17
26
|
add(props) {
|
|
18
27
|
const id = Math.random().toString(36).slice(2, 9);
|
|
@@ -36,6 +45,15 @@ class ToastState {
|
|
|
36
45
|
}
|
|
37
46
|
/**
|
|
38
47
|
* 移除 Toast
|
|
48
|
+
* @param id - 待移除的条目 ID。
|
|
49
|
+
* @returns {void} 无返回值;同时清理对应的自动关闭定时器。
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { toast } from '@h-ai/ui'
|
|
53
|
+
* // 布局中需挂载 ToastContainer。
|
|
54
|
+
* const id = toast.info('同步中', 0)
|
|
55
|
+
* toast.remove(id)
|
|
56
|
+
* ```
|
|
39
57
|
*/
|
|
40
58
|
remove(id) {
|
|
41
59
|
const timer = this.timers.get(id);
|
|
@@ -47,6 +65,14 @@ class ToastState {
|
|
|
47
65
|
}
|
|
48
66
|
/**
|
|
49
67
|
* 清空所有 Toast
|
|
68
|
+
* @returns {void} 无返回值;同时清理对应的自动关闭定时器。
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* import { toast } from '@h-ai/ui'
|
|
72
|
+
* // 布局中需挂载 ToastContainer。
|
|
73
|
+
* toast.info('同步中', 0)
|
|
74
|
+
* toast.clear()
|
|
75
|
+
* ```
|
|
50
76
|
*/
|
|
51
77
|
clear() {
|
|
52
78
|
for (const timer of this.timers.values()) {
|
|
@@ -57,22 +83,80 @@ class ToastState {
|
|
|
57
83
|
}
|
|
58
84
|
/**
|
|
59
85
|
* 快捷方法
|
|
86
|
+
* @param message - 已经本地化的用户提示。
|
|
87
|
+
* @param duration - 提示持续时间,单位毫秒。
|
|
88
|
+
* @returns 新条目的 ID,可用于提前移除。
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* import { toast } from '@h-ai/ui'
|
|
92
|
+
* // 布局中需挂载 ToastContainer。
|
|
93
|
+
* const id = toast.success('操作结果', 3000)
|
|
94
|
+
* toast.remove(id)
|
|
95
|
+
* ```
|
|
60
96
|
*/
|
|
61
97
|
success(message, duration) {
|
|
62
98
|
return this.add({ message, variant: 'success', duration });
|
|
63
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* 处理 error 操作。
|
|
102
|
+
* @param message - 已经本地化的用户提示。
|
|
103
|
+
* @param duration - 提示持续时间,单位毫秒。
|
|
104
|
+
* @returns 新条目的 ID,可用于提前移除。
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* import { toast } from '@h-ai/ui'
|
|
108
|
+
* // 布局中需挂载 ToastContainer。
|
|
109
|
+
* const id = toast.error('操作结果', 3000)
|
|
110
|
+
* toast.remove(id)
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
64
113
|
error(message, duration) {
|
|
65
114
|
return this.add({ message, variant: 'error', duration });
|
|
66
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* 处理 warning 操作。
|
|
118
|
+
* @param message - 已经本地化的用户提示。
|
|
119
|
+
* @param duration - 提示持续时间,单位毫秒。
|
|
120
|
+
* @returns 新条目的 ID,可用于提前移除。
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* import { toast } from '@h-ai/ui'
|
|
124
|
+
* // 布局中需挂载 ToastContainer。
|
|
125
|
+
* const id = toast.warning('操作结果', 3000)
|
|
126
|
+
* toast.remove(id)
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
67
129
|
warning(message, duration) {
|
|
68
130
|
return this.add({ message, variant: 'warning', duration });
|
|
69
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* 处理 info 操作。
|
|
134
|
+
* @param message - 已经本地化的用户提示。
|
|
135
|
+
* @param duration - 提示持续时间,单位毫秒。
|
|
136
|
+
* @returns 新条目的 ID,可用于提前移除。
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* import { toast } from '@h-ai/ui'
|
|
140
|
+
* // 布局中需挂载 ToastContainer。
|
|
141
|
+
* const id = toast.info('操作结果', 3000)
|
|
142
|
+
* toast.remove(id)
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
70
145
|
info(message, duration) {
|
|
71
146
|
return this.add({ message, variant: 'info', duration });
|
|
72
147
|
}
|
|
73
148
|
}
|
|
74
149
|
/**
|
|
75
150
|
* Toast 单例
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* import { toast } from '@h-ai/ui'
|
|
155
|
+
* // 页面布局需挂载 ToastContainer。
|
|
156
|
+
* const id = toast.success('保存完成', 3000)
|
|
157
|
+
* toast.remove(id)
|
|
158
|
+
* toast.clear()
|
|
159
|
+
* ```
|
|
76
160
|
*/
|
|
77
161
|
export const toast = new ToastState();
|
|
78
162
|
/** 成功提示默认停留时长(毫秒)。 */
|
|
@@ -86,9 +170,14 @@ const ERROR_DURATION = 5000;
|
|
|
86
170
|
*
|
|
87
171
|
* @param message - 用户可见的成功文案(已本地化)。
|
|
88
172
|
* @param duration - 可选停留时长(毫秒),默认 3000。
|
|
173
|
+
* @returns 新通知的 ID,可交给 toast.remove 提前移除。
|
|
89
174
|
*
|
|
90
175
|
* @example
|
|
91
|
-
*
|
|
176
|
+
* ```ts
|
|
177
|
+
* import { notifySuccess, toast } from '@h-ai/ui'
|
|
178
|
+
* const id = notifySuccess('保存完成', 3000)
|
|
179
|
+
* toast.remove(id)
|
|
180
|
+
* ```
|
|
92
181
|
*/
|
|
93
182
|
export function notifySuccess(message, duration = SUCCESS_DURATION) {
|
|
94
183
|
return toast.success(message, duration);
|
|
@@ -102,9 +191,14 @@ export function notifySuccess(message, duration = SUCCESS_DURATION) {
|
|
|
102
191
|
* @param error - 错误对象或已本地化的错误文案。
|
|
103
192
|
* @param fallback - 当 error 非 Error 且为空时使用的兜底文案。
|
|
104
193
|
* @param duration - 可选停留时长(毫秒),默认 5000。
|
|
194
|
+
* @returns 新错误通知的 ID,可交给 toast.remove 提前移除。
|
|
105
195
|
*
|
|
106
196
|
* @example
|
|
107
|
-
*
|
|
197
|
+
* ```ts
|
|
198
|
+
* import { notifyError, toast } from '@h-ai/ui'
|
|
199
|
+
* const id = notifyError(new Error('提交失败'), '请稍后重试', 5000)
|
|
200
|
+
* toast.remove(id)
|
|
201
|
+
* ```
|
|
108
202
|
*/
|
|
109
203
|
export function notifyError(error, fallback = '', duration = ERROR_DURATION) {
|
|
110
204
|
const message = error instanceof Error
|
|
@@ -117,9 +211,14 @@ export function notifyError(error, fallback = '', duration = ERROR_DURATION) {
|
|
|
117
211
|
*
|
|
118
212
|
* @param message - 用户可见文案(已本地化)。
|
|
119
213
|
* @param duration - 可选停留时长(毫秒),默认 3000。
|
|
214
|
+
* @returns 新提示的 ID。
|
|
120
215
|
*
|
|
121
216
|
* @example
|
|
122
|
-
*
|
|
217
|
+
* ```ts
|
|
218
|
+
* import { notifyInfo, toast } from '@h-ai/ui'
|
|
219
|
+
* const id = notifyInfo('正在同步', 3000)
|
|
220
|
+
* toast.remove(id)
|
|
221
|
+
* ```
|
|
123
222
|
*/
|
|
124
223
|
export function notifyInfo(message, duration = SUCCESS_DURATION) {
|
|
125
224
|
return toast.info(message, duration);
|
|
@@ -129,9 +228,14 @@ export function notifyInfo(message, duration = SUCCESS_DURATION) {
|
|
|
129
228
|
*
|
|
130
229
|
* @param message - 用户可见文案(已本地化)。
|
|
131
230
|
* @param duration - 可选停留时长(毫秒),默认 5000。
|
|
231
|
+
* @returns 新警告的 ID。
|
|
132
232
|
*
|
|
133
233
|
* @example
|
|
134
|
-
*
|
|
234
|
+
* ```ts
|
|
235
|
+
* import { notifyWarning, toast } from '@h-ai/ui'
|
|
236
|
+
* const id = notifyWarning('请先保存修改', 5000)
|
|
237
|
+
* toast.remove(id)
|
|
238
|
+
* ```
|
|
135
239
|
*/
|
|
136
240
|
export function notifyWarning(message, duration = ERROR_DURATION) {
|
|
137
241
|
return toast.warning(message, duration);
|