@h-ai/ui 0.1.0-alpha9 → 1.0.0-beta.10
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 +1062 -0
- package/README.ja.md +1062 -0
- package/README.md +696 -119
- package/auto-import.d.ts +49 -0
- package/auto-import.js +51 -69
- package/dist/components/compounds/Accordion.svelte +30 -3
- package/dist/components/compounds/Accordion.svelte.d.ts +37 -1
- package/dist/components/compounds/ActionSheet.svelte +35 -8
- package/dist/components/compounds/ActionSheet.svelte.d.ts +41 -1
- package/dist/components/compounds/Alert.svelte +24 -15
- package/dist/components/compounds/Alert.svelte.d.ts +14 -3
- package/dist/components/compounds/AppBar.svelte +37 -9
- package/dist/components/compounds/AppBar.svelte.d.ts +36 -1
- package/dist/components/compounds/BottomNav.svelte +68 -8
- package/dist/components/compounds/BottomNav.svelte.d.ts +51 -1
- package/dist/components/compounds/Breadcrumb.svelte +18 -5
- package/dist/components/compounds/Breadcrumb.svelte.d.ts +23 -2
- package/dist/components/compounds/Calendar.svelte +31 -12
- package/dist/components/compounds/Calendar.svelte.d.ts +23 -7
- package/dist/components/compounds/Card.svelte +17 -5
- package/dist/components/compounds/Card.svelte.d.ts +13 -2
- package/dist/components/compounds/Combobox.svelte +124 -42
- package/dist/components/compounds/Combobox.svelte.d.ts +42 -20
- package/dist/components/compounds/Confirm.svelte +32 -9
- package/dist/components/compounds/Confirm.svelte.d.ts +24 -2
- package/dist/components/compounds/DataTable.svelte +317 -33
- package/dist/components/compounds/DataTable.svelte.d.ts +28 -14
- package/dist/components/compounds/DatePicker.svelte +62 -18
- package/dist/components/compounds/DatePicker.svelte.d.ts +27 -8
- package/dist/components/compounds/Drawer.svelte +179 -22
- package/dist/components/compounds/Drawer.svelte.d.ts +24 -2
- package/dist/components/compounds/Dropdown.svelte +19 -5
- package/dist/components/compounds/Dropdown.svelte.d.ts +13 -2
- package/dist/components/compounds/Empty.svelte +22 -9
- package/dist/components/compounds/Empty.svelte.d.ts +23 -2
- package/dist/components/compounds/FilterBar.svelte +82 -0
- package/dist/components/compounds/FilterBar.svelte.d.ts +39 -0
- package/dist/components/compounds/Form.svelte +59 -16
- package/dist/components/compounds/Form.svelte.d.ts +23 -2
- package/dist/components/compounds/FormField.svelte +99 -16
- package/dist/components/compounds/FormField.svelte.d.ts +23 -2
- package/dist/components/compounds/FormLayout.svelte +71 -0
- package/dist/components/compounds/FormLayout.svelte.d.ts +17 -0
- package/dist/components/compounds/InfiniteScroll.svelte +34 -7
- package/dist/components/compounds/InfiniteScroll.svelte.d.ts +37 -1
- package/dist/components/compounds/JsonViewer.svelte +214 -0
- package/dist/components/compounds/JsonViewer.svelte.d.ts +26 -0
- package/dist/components/compounds/MessageBoxContainer.svelte +34 -0
- package/dist/components/compounds/MessageBoxContainer.svelte.d.ts +25 -0
- package/dist/components/compounds/MessageBoxDialog.svelte +209 -0
- package/dist/components/compounds/MessageBoxDialog.svelte.d.ts +29 -0
- package/dist/components/compounds/MessageContainer.svelte +24 -0
- package/dist/components/compounds/MessageContainer.svelte.d.ts +18 -0
- package/dist/components/compounds/Modal.svelte +348 -73
- package/dist/components/compounds/Modal.svelte.d.ts +13 -2
- package/dist/components/compounds/PageHeader.svelte +44 -20
- package/dist/components/compounds/PageHeader.svelte.d.ts +24 -9
- package/dist/components/compounds/Pagination.svelte +139 -105
- package/dist/components/compounds/Pagination.svelte.d.ts +23 -2
- package/dist/components/compounds/Popover.svelte +124 -25
- package/dist/components/compounds/Popover.svelte.d.ts +23 -2
- package/dist/components/compounds/PullRefresh.svelte +35 -8
- package/dist/components/compounds/PullRefresh.svelte.d.ts +35 -1
- package/dist/components/compounds/Result.svelte +17 -4
- package/dist/components/compounds/Result.svelte.d.ts +23 -2
- package/dist/components/compounds/SafeArea.svelte +30 -3
- package/dist/components/compounds/SafeArea.svelte.d.ts +35 -1
- package/dist/components/compounds/Skeleton.svelte +19 -7
- package/dist/components/compounds/Skeleton.svelte.d.ts +13 -2
- package/dist/components/compounds/Steps.svelte +17 -4
- package/dist/components/compounds/Steps.svelte.d.ts +23 -2
- package/dist/components/compounds/SwipeCell.svelte +30 -3
- package/dist/components/compounds/SwipeCell.svelte.d.ts +40 -1
- package/dist/components/compounds/TableToolbar.svelte +289 -0
- package/dist/components/compounds/TableToolbar.svelte.d.ts +69 -0
- package/dist/components/compounds/Tabs.svelte +84 -14
- package/dist/components/compounds/Tabs.svelte.d.ts +13 -2
- package/dist/components/compounds/TagInput.svelte +51 -33
- package/dist/components/compounds/TagInput.svelte.d.ts +23 -2
- package/dist/components/compounds/Timeline.svelte +30 -3
- package/dist/components/compounds/Timeline.svelte.d.ts +37 -1
- package/dist/components/compounds/ToastContainer.svelte +397 -28
- package/dist/components/compounds/ToastContainer.svelte.d.ts +27 -1
- package/dist/components/compounds/Tooltip.svelte +143 -9
- package/dist/components/compounds/Tooltip.svelte.d.ts +25 -2
- 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/index.d.ts +7 -0
- package/dist/components/compounds/index.js +11 -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 +35 -0
- package/dist/components/control-size.js +26 -0
- package/dist/components/primitives/Avatar.svelte +19 -5
- package/dist/components/primitives/Avatar.svelte.d.ts +13 -2
- package/dist/components/primitives/Badge.svelte +16 -4
- package/dist/components/primitives/Badge.svelte.d.ts +13 -2
- package/dist/components/primitives/BareButton.svelte +26 -12
- package/dist/components/primitives/BareButton.svelte.d.ts +23 -2
- package/dist/components/primitives/BareInput.svelte +57 -35
- package/dist/components/primitives/BareInput.svelte.d.ts +23 -2
- package/dist/components/primitives/Button.svelte +30 -9
- package/dist/components/primitives/Button.svelte.d.ts +13 -2
- package/dist/components/primitives/Checkbox.svelte +24 -5
- package/dist/components/primitives/Checkbox.svelte.d.ts +23 -2
- package/dist/components/primitives/IconButton.svelte +35 -10
- package/dist/components/primitives/IconButton.svelte.d.ts +23 -2
- package/dist/components/primitives/Input.svelte +56 -26
- package/dist/components/primitives/Input.svelte.d.ts +13 -2
- package/dist/components/primitives/Progress.svelte +17 -4
- package/dist/components/primitives/Progress.svelte.d.ts +23 -2
- package/dist/components/primitives/Radio.svelte +17 -4
- package/dist/components/primitives/Radio.svelte.d.ts +22 -2
- package/dist/components/primitives/Range.svelte +31 -4
- package/dist/components/primitives/Range.svelte.d.ts +37 -1
- package/dist/components/primitives/Rating.svelte +32 -5
- package/dist/components/primitives/Rating.svelte.d.ts +37 -1
- package/dist/components/primitives/Select.svelte +404 -47
- package/dist/components/primitives/Select.svelte.d.ts +23 -2
- package/dist/components/primitives/Spinner.svelte +17 -4
- package/dist/components/primitives/Spinner.svelte.d.ts +23 -2
- package/dist/components/primitives/Switch.svelte +22 -4
- package/dist/components/primitives/Switch.svelte.d.ts +23 -2
- package/dist/components/primitives/Tag.svelte +17 -4
- package/dist/components/primitives/Tag.svelte.d.ts +23 -2
- package/dist/components/primitives/Textarea.svelte +75 -30
- package/dist/components/primitives/Textarea.svelte.d.ts +24 -2
- package/dist/components/primitives/ToggleCheckbox.svelte +24 -10
- package/dist/components/primitives/ToggleCheckbox.svelte.d.ts +23 -2
- package/dist/components/primitives/ToggleInput.svelte +24 -10
- package/dist/components/primitives/ToggleInput.svelte.d.ts +23 -2
- package/dist/components/primitives/ToggleRadio.svelte +24 -10
- package/dist/components/primitives/ToggleRadio.svelte.d.ts +23 -2
- package/dist/components/scenes/ai/AiDocumentDownloadMenu.svelte +54 -23
- package/dist/components/scenes/ai/AiDocumentDownloadMenu.svelte.d.ts +30 -1
- package/dist/components/scenes/ai/AiDocumentEditor.svelte +3428 -693
- package/dist/components/scenes/ai/AiDocumentEditor.svelte.d.ts +26 -1
- package/dist/components/scenes/ai/MarkdownRenderer.svelte +119 -116
- package/dist/components/scenes/ai/MarkdownRenderer.svelte.d.ts +31 -1
- package/dist/components/scenes/ai/code-preview.d.ts +46 -0
- package/dist/components/scenes/ai/code-preview.js +141 -0
- package/dist/components/scenes/ai/document-download.d.ts +52 -0
- package/dist/components/scenes/ai/document-download.js +300 -79
- package/dist/components/scenes/ai/document-parse.d.ts +101 -11
- package/dist/components/scenes/ai/document-parse.js +212 -48
- package/dist/components/scenes/ai/document-types.d.ts +292 -75
- package/dist/components/scenes/ai/editor-markdown-extensions.d.ts +27 -0
- package/dist/components/scenes/ai/editor-markdown-extensions.js +216 -0
- package/dist/components/scenes/ai/highlight.d.ts +37 -0
- package/dist/components/scenes/ai/highlight.js +177 -0
- package/dist/components/scenes/ai/index.d.ts +5 -2
- package/dist/components/scenes/ai/index.js +3 -0
- package/dist/components/scenes/ai/markdown-parse.d.ts +11 -3
- package/dist/components/scenes/ai/markdown-parse.js +85 -47
- package/dist/components/scenes/ai/mermaid-host-sync.d.ts +72 -0
- package/dist/components/scenes/ai/mermaid-host-sync.js +65 -0
- package/dist/components/scenes/ai/mermaid-render.d.ts +30 -0
- package/dist/components/scenes/ai/mermaid-render.js +61 -0
- package/dist/components/scenes/ai/safe-html.d.ts +64 -0
- package/dist/components/scenes/ai/safe-html.js +345 -0
- package/dist/components/scenes/ai/table/AiTableEditor.svelte +1692 -0
- package/dist/components/scenes/ai/table/AiTableEditor.svelte.d.ts +32 -0
- package/dist/components/scenes/ai/table/table-types.d.ts +181 -0
- package/dist/components/scenes/ai/table/table-types.js +1 -0
- package/dist/components/scenes/app/FeedbackDetail.svelte +236 -0
- package/dist/components/scenes/app/FeedbackDetail.svelte.d.ts +40 -0
- package/dist/components/scenes/app/FeedbackForm.svelte +337 -0
- package/dist/components/scenes/app/FeedbackForm.svelte.d.ts +72 -0
- package/dist/components/scenes/app/FeedbackList.svelte +150 -0
- package/dist/components/scenes/app/FeedbackList.svelte.d.ts +28 -0
- package/dist/components/scenes/app/FeedbackModal.svelte +65 -139
- package/dist/components/scenes/app/FeedbackModal.svelte.d.ts +14 -39
- package/dist/components/scenes/app/FeedbackRecorder.svelte +154 -0
- package/dist/components/scenes/app/FeedbackRecorder.svelte.d.ts +9 -0
- package/dist/components/scenes/app/FeedbackReplay.svelte +142 -0
- package/dist/components/scenes/app/FeedbackReplay.svelte.d.ts +7 -0
- package/dist/components/scenes/app/FeedbackScreenshot.svelte +120 -0
- package/dist/components/scenes/app/FeedbackScreenshot.svelte.d.ts +8 -0
- package/dist/components/scenes/app/LanguageSwitch.svelte +38 -21
- package/dist/components/scenes/app/LanguageSwitch.svelte.d.ts +33 -20
- package/dist/components/scenes/app/SettingsLayout.svelte +115 -0
- package/dist/components/scenes/app/SettingsLayout.svelte.d.ts +54 -0
- package/dist/components/scenes/app/SettingsModal.svelte +33 -7
- package/dist/components/scenes/app/SettingsModal.svelte.d.ts +27 -1
- package/dist/components/scenes/app/ThemeColorPicker.svelte +240 -0
- package/dist/components/scenes/app/ThemeColorPicker.svelte.d.ts +57 -0
- package/dist/components/scenes/app/ThemeSelector.svelte +87 -26
- package/dist/components/scenes/app/ThemeSelector.svelte.d.ts +26 -7
- package/dist/components/scenes/app/ThemeToggle.svelte +27 -6
- package/dist/components/scenes/app/ThemeToggle.svelte.d.ts +24 -5
- package/dist/components/scenes/app/WorkspaceLayout.svelte +64 -0
- package/dist/components/scenes/app/WorkspaceLayout.svelte.d.ts +36 -0
- package/dist/components/scenes/app/feedback-functions.d.ts +57 -0
- package/dist/components/scenes/app/feedback-functions.js +107 -0
- package/dist/components/scenes/app/feedback-types.d.ts +224 -0
- package/dist/components/scenes/app/feedback-types.js +1 -0
- package/dist/components/scenes/app/index.d.ts +8 -1
- package/dist/components/scenes/app/index.js +7 -1
- package/dist/components/scenes/charts/Chart.svelte +186 -0
- package/dist/components/scenes/charts/Chart.svelte.d.ts +24 -0
- package/dist/components/scenes/charts/ChartLoadError.svelte +13 -0
- package/dist/components/scenes/charts/ChartLoadError.svelte.d.ts +6 -0
- package/dist/components/scenes/charts/DashboardGrid.svelte +34 -0
- package/dist/components/scenes/charts/DashboardGrid.svelte.d.ts +15 -0
- package/dist/components/scenes/charts/MetricCard.svelte +52 -0
- package/dist/components/scenes/charts/MetricCard.svelte.d.ts +15 -0
- package/dist/components/scenes/charts/ReportCard.svelte +48 -0
- package/dist/components/scenes/charts/ReportCard.svelte.d.ts +15 -0
- package/dist/components/scenes/charts/chart-presets.d.ts +15 -0
- package/dist/components/scenes/charts/chart-presets.js +19 -0
- package/dist/components/scenes/charts/chart-theme.d.ts +47 -0
- package/dist/components/scenes/charts/chart-theme.js +68 -0
- package/dist/components/scenes/charts/chart-types.d.ts +164 -0
- package/dist/components/scenes/charts/chart-types.js +7 -0
- package/dist/components/scenes/charts/dashboard-types.d.ts +79 -0
- package/dist/components/scenes/charts/dashboard-types.js +1 -0
- package/dist/components/scenes/charts/index.d.ts +12 -0
- package/dist/components/scenes/charts/index.js +10 -0
- package/dist/components/scenes/charts/renderers/AreaChart.svelte +19 -0
- package/dist/components/scenes/charts/renderers/AreaChart.svelte.d.ts +6 -0
- package/dist/components/scenes/charts/renderers/BarChart.svelte +19 -0
- package/dist/components/scenes/charts/renderers/BarChart.svelte.d.ts +6 -0
- package/dist/components/scenes/charts/renderers/LineChart.svelte +625 -0
- package/dist/components/scenes/charts/renderers/LineChart.svelte.d.ts +33 -0
- package/dist/components/scenes/charts/renderers/PieChart.svelte +19 -0
- package/dist/components/scenes/charts/renderers/PieChart.svelte.d.ts +6 -0
- package/dist/components/scenes/charts/renderers/ScatterChart.svelte +19 -0
- package/dist/components/scenes/charts/renderers/ScatterChart.svelte.d.ts +6 -0
- package/dist/components/scenes/crud/CrudDeleteConfirm.svelte +29 -11
- package/dist/components/scenes/crud/CrudDeleteConfirm.svelte.d.ts +13 -1
- package/dist/components/scenes/crud/CrudDetailDrawer.svelte +77 -22
- package/dist/components/scenes/crud/CrudDetailDrawer.svelte.d.ts +19 -4
- package/dist/components/scenes/crud/CrudDetailPanel.svelte +242 -0
- package/dist/components/scenes/crud/CrudDetailPanel.svelte.d.ts +66 -0
- package/dist/components/scenes/crud/CrudEditPanel.svelte +365 -0
- package/dist/components/scenes/crud/CrudEditPanel.svelte.d.ts +48 -0
- package/dist/components/scenes/crud/CrudFilterBar.svelte +17 -85
- package/dist/components/scenes/crud/CrudFilterBar.svelte.d.ts +13 -25
- package/dist/components/scenes/crud/CrudPage.svelte +564 -185
- package/dist/components/scenes/crud/CrudPage.svelte.d.ts +137 -51
- package/dist/components/scenes/crud/crud-controller.svelte.d.ts +335 -0
- package/dist/components/scenes/crud/crud-controller.svelte.js +276 -0
- package/dist/components/scenes/crud/crud-form-validation.d.ts +16 -0
- package/dist/components/scenes/crud/crud-form-validation.js +51 -0
- package/dist/components/scenes/crud/crud-types.d.ts +136 -43
- package/dist/components/scenes/crud/index.d.ts +9 -3
- package/dist/components/scenes/crud/index.js +8 -3
- package/dist/components/scenes/crud/nav-adapter.d.ts +50 -0
- package/dist/components/scenes/crud/nav-adapter.js +39 -0
- package/dist/components/scenes/crypto/EncryptedInput.svelte +63 -28
- package/dist/components/scenes/crypto/EncryptedInput.svelte.d.ts +38 -3
- package/dist/components/scenes/crypto/HashDisplay.svelte +30 -22
- package/dist/components/scenes/crypto/HashDisplay.svelte.d.ts +24 -1
- package/dist/components/scenes/crypto/SignatureDisplay.svelte +41 -40
- package/dist/components/scenes/crypto/SignatureDisplay.svelte.d.ts +24 -1
- package/dist/components/scenes/error/ErrorPage.svelte +135 -0
- package/dist/components/scenes/error/ErrorPage.svelte.d.ts +50 -0
- package/dist/components/scenes/error/error-presets.d.ts +60 -0
- package/dist/components/scenes/error/error-presets.js +51 -0
- package/dist/components/scenes/error/index.d.ts +8 -0
- package/dist/components/scenes/error/index.js +8 -0
- package/dist/components/scenes/guide/GuideHost.svelte +56 -0
- package/dist/components/scenes/guide/GuideHost.svelte.d.ts +35 -0
- package/dist/components/scenes/guide/GuideHostContent.svelte +136 -0
- package/dist/components/scenes/guide/GuideHostContent.svelte.d.ts +43 -0
- package/dist/components/scenes/guide/HelpCenter.svelte +135 -0
- package/dist/components/scenes/guide/HelpCenter.svelte.d.ts +40 -0
- package/dist/components/scenes/guide/index.d.ts +2 -0
- package/dist/components/scenes/guide/index.js +2 -0
- package/dist/components/scenes/iam/AgreementNotice.svelte +48 -0
- package/dist/components/scenes/iam/AgreementNotice.svelte.d.ts +7 -0
- package/dist/components/scenes/iam/AuthPanel.svelte +226 -0
- package/dist/components/scenes/iam/AuthPanel.svelte.d.ts +29 -0
- package/dist/components/scenes/iam/AuthShell.svelte +160 -0
- package/dist/components/scenes/iam/AuthShell.svelte.d.ts +56 -0
- package/dist/components/scenes/iam/ChangePasswordForm.svelte +84 -63
- package/dist/components/scenes/iam/ChangePasswordForm.svelte.d.ts +13 -1
- package/dist/components/scenes/iam/ForgotPasswordForm.svelte +113 -89
- package/dist/components/scenes/iam/ForgotPasswordForm.svelte.d.ts +24 -1
- package/dist/components/scenes/iam/LoginForm.svelte +215 -117
- package/dist/components/scenes/iam/LoginForm.svelte.d.ts +13 -1
- package/dist/components/scenes/iam/PasswordInput.svelte +79 -32
- package/dist/components/scenes/iam/PasswordInput.svelte.d.ts +30 -4
- 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/ReauthenticationDialog.svelte +68 -0
- package/dist/components/scenes/iam/ReauthenticationDialog.svelte.d.ts +17 -0
- package/dist/components/scenes/iam/RegisterForm.svelte +129 -116
- package/dist/components/scenes/iam/RegisterForm.svelte.d.ts +13 -1
- package/dist/components/scenes/iam/ResetPasswordForm.svelte +101 -88
- package/dist/components/scenes/iam/ResetPasswordForm.svelte.d.ts +13 -1
- package/dist/components/scenes/iam/SensitiveOperationsForm.svelte +76 -0
- package/dist/components/scenes/iam/SensitiveOperationsForm.svelte.d.ts +21 -0
- package/dist/components/scenes/iam/SessionRecoveryDialog.svelte +64 -0
- package/dist/components/scenes/iam/SessionRecoveryDialog.svelte.d.ts +22 -0
- package/dist/components/scenes/iam/UserProfile.svelte +47 -21
- package/dist/components/scenes/iam/UserProfile.svelte.d.ts +24 -1
- package/dist/components/scenes/iam/auth-captcha.d.ts +21 -0
- package/dist/components/scenes/iam/auth-captcha.js +23 -0
- package/dist/components/scenes/iam/auth-error-message.d.ts +13 -0
- package/dist/components/scenes/iam/auth-error-message.js +65 -0
- package/dist/components/scenes/iam/index.d.ts +10 -0
- package/dist/components/scenes/iam/index.js +9 -1
- package/dist/components/scenes/iam/password-utils.d.ts +33 -6
- package/dist/components/scenes/iam/password-utils.js +61 -8
- 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/iam/sensitive-actions.svelte.d.ts +68 -0
- package/dist/components/scenes/iam/sensitive-actions.svelte.js +101 -0
- package/dist/components/scenes/iam/session-recovery.svelte.d.ts +44 -0
- package/dist/components/scenes/iam/session-recovery.svelte.js +57 -0
- package/dist/components/scenes/index.d.ts +3 -0
- package/dist/components/scenes/index.js +5 -0
- package/dist/components/scenes/storage/AvatarUpload.svelte +82 -68
- package/dist/components/scenes/storage/AvatarUpload.svelte.d.ts +23 -1
- package/dist/components/scenes/storage/FileList.svelte +19 -5
- package/dist/components/scenes/storage/FileList.svelte.d.ts +23 -1
- package/dist/components/scenes/storage/FileUpload.svelte +151 -96
- package/dist/components/scenes/storage/FileUpload.svelte.d.ts +24 -1
- package/dist/components/scenes/storage/ImageUpload.svelte +93 -94
- package/dist/components/scenes/storage/ImageUpload.svelte.d.ts +24 -1
- package/dist/components/scenes/types.d.ts +574 -42
- package/dist/guide-storage.d.ts +18 -0
- package/dist/guide-storage.js +79 -0
- package/dist/guide-types.d.ts +143 -0
- package/dist/guide-types.js +1 -0
- package/dist/guide.d.ts +3 -0
- package/dist/guide.js +3 -0
- package/dist/guide.svelte.d.ts +29 -0
- package/dist/guide.svelte.js +506 -0
- package/dist/i18n.svelte.d.ts +67 -4
- package/dist/i18n.svelte.js +106 -21
- package/dist/index.d.ts +6 -0
- package/dist/index.js +7 -0
- package/dist/internal/browser-safety.d.ts +88 -0
- package/dist/internal/browser-safety.js +140 -0
- package/dist/internal/dialog-focus.d.ts +21 -0
- package/dist/internal/dialog-focus.js +77 -0
- package/dist/internal/form-context.d.ts +92 -0
- package/dist/internal/form-context.js +70 -0
- package/dist/internal/form-validation.svelte.d.ts +70 -0
- package/dist/internal/form-validation.svelte.js +142 -0
- package/dist/internal/icon-safety.d.ts +14 -0
- package/dist/internal/icon-safety.js +40 -0
- package/dist/internal/locale.d.ts +21 -0
- package/dist/internal/locale.js +43 -0
- package/dist/message.svelte.d.ts +138 -0
- package/dist/message.svelte.js +149 -0
- package/dist/messagebox.svelte.d.ts +130 -0
- package/dist/messagebox.svelte.js +171 -0
- package/dist/messages/en-US.json +303 -16
- package/dist/messages/ja-JP.json +529 -0
- package/dist/messages/zh-CN.json +303 -16
- package/dist/messages.d.ts +25 -3
- package/dist/messages.js +23 -6
- package/dist/styles/design-tokens.css +4 -2
- package/dist/styles/eye-care.css +55 -0
- package/dist/styles/formal.css +55 -0
- package/dist/styles/global.css +86 -18
- package/dist/styles/guide.css +88 -0
- package/dist/styles/high-contrast.css +64 -0
- package/dist/styles/mobile.css +28 -0
- package/dist/styles/theme.css +43 -0
- package/dist/theme-config.d.ts +263 -10
- package/dist/theme-config.js +253 -17
- package/dist/toast.svelte.d.ts +210 -2
- package/dist/toast.svelte.js +305 -19
- package/dist/types.d.ts +787 -63
- package/dist/utils/platform.svelte.d.ts +28 -15
- package/dist/utils/platform.svelte.js +23 -16
- package/dist/utils.d.ts +121 -1
- package/dist/utils.js +208 -13
- package/dist/workspace-context.d.ts +20 -0
- package/dist/workspace-context.js +9 -0
- package/package.json +120 -24
- package/vite.d.ts +13 -0
- package/vite.js +96 -0
- package/dist/components/scenes/crud/CrudEditDrawer.svelte +0 -225
- package/dist/components/scenes/crud/CrudEditDrawer.svelte.d.ts +0 -48
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;
|
|
@@ -16,30 +22,232 @@ export interface ToastItem extends ToastProps {
|
|
|
16
22
|
*/
|
|
17
23
|
declare class ToastState {
|
|
18
24
|
items: ToastItem[];
|
|
19
|
-
/**
|
|
20
|
-
private
|
|
25
|
+
/** 仅队首计时,等待项在展示后才开始计算停留时间。 */
|
|
26
|
+
private timer;
|
|
27
|
+
private deadline;
|
|
28
|
+
private remaining;
|
|
29
|
+
private paused;
|
|
30
|
+
private startTimer;
|
|
31
|
+
/**
|
|
32
|
+
* 暂停当前提示的自动关闭,供阅读和交互期间使用;等待项不受影响。
|
|
33
|
+
* @param id - 当前提示 ID。
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const id = toast.info('同步中')
|
|
37
|
+
* toast.pause(id)
|
|
38
|
+
* toast.resume(id)
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
pause(id: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* 从剩余时间恢复当前提示的自动关闭;手工关闭或清空后不会恢复旧计时器。
|
|
44
|
+
* @param id - 当前提示 ID。
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* const id = toast.info('同步中')
|
|
48
|
+
* toast.pause(id)
|
|
49
|
+
* toast.resume(id)
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
resume(id: string): void;
|
|
21
53
|
/**
|
|
22
54
|
* 添加 Toast
|
|
55
|
+
* @param props - 组件的属性对象。
|
|
56
|
+
* @returns 新条目的 ID,可用于提前移除。
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { toast } from '@h-ai/ui'
|
|
60
|
+
* // 布局中需挂载 ToastContainer。
|
|
61
|
+
* const id = toast.add({ message: '保存完成', variant: 'success', duration: 3000 })
|
|
62
|
+
* toast.remove(id)
|
|
63
|
+
* ```
|
|
23
64
|
*/
|
|
24
65
|
add(props: Omit<ToastProps, 'onclose'>): string;
|
|
25
66
|
/**
|
|
26
67
|
* 移除 Toast
|
|
68
|
+
* @param id - 待移除的条目 ID。
|
|
69
|
+
* @returns {void} 无返回值;同时清理对应的自动关闭定时器。
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* import { toast } from '@h-ai/ui'
|
|
73
|
+
* // 布局中需挂载 ToastContainer。
|
|
74
|
+
* const id = toast.info('同步中', 0)
|
|
75
|
+
* toast.remove(id)
|
|
76
|
+
* ```
|
|
27
77
|
*/
|
|
28
78
|
remove(id: string): void;
|
|
29
79
|
/**
|
|
30
80
|
* 清空所有 Toast
|
|
81
|
+
* @returns {void} 无返回值;同时清理对应的自动关闭定时器。
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* import { toast } from '@h-ai/ui'
|
|
85
|
+
* // 布局中需挂载 ToastContainer。
|
|
86
|
+
* toast.info('同步中', 0)
|
|
87
|
+
* toast.clear()
|
|
88
|
+
* ```
|
|
31
89
|
*/
|
|
32
90
|
clear(): void;
|
|
33
91
|
/**
|
|
34
92
|
* 快捷方法
|
|
93
|
+
* @param message - 已经本地化的用户提示。
|
|
94
|
+
* @param duration - 提示持续时间,单位毫秒。
|
|
95
|
+
* @returns 新条目的 ID,可用于提前移除。
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* import { toast } from '@h-ai/ui'
|
|
99
|
+
* // 布局中需挂载 ToastContainer。
|
|
100
|
+
* const id = toast.success('操作结果', 3000)
|
|
101
|
+
* toast.remove(id)
|
|
102
|
+
* ```
|
|
35
103
|
*/
|
|
36
104
|
success(message: string, duration?: number): string;
|
|
105
|
+
/**
|
|
106
|
+
* 处理 error 操作。
|
|
107
|
+
* @param message - 已经本地化的用户提示。
|
|
108
|
+
* @param duration - 提示持续时间,单位毫秒。
|
|
109
|
+
* @returns 新条目的 ID,可用于提前移除。
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* import { toast } from '@h-ai/ui'
|
|
113
|
+
* // 布局中需挂载 ToastContainer。
|
|
114
|
+
* const id = toast.error('操作结果', 3000)
|
|
115
|
+
* toast.remove(id)
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
37
118
|
error(message: string, duration?: number): string;
|
|
119
|
+
/**
|
|
120
|
+
* 处理 warning 操作。
|
|
121
|
+
* @param message - 已经本地化的用户提示。
|
|
122
|
+
* @param duration - 提示持续时间,单位毫秒。
|
|
123
|
+
* @returns 新条目的 ID,可用于提前移除。
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* import { toast } from '@h-ai/ui'
|
|
127
|
+
* // 布局中需挂载 ToastContainer。
|
|
128
|
+
* const id = toast.warning('操作结果', 3000)
|
|
129
|
+
* toast.remove(id)
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
38
132
|
warning(message: string, duration?: number): string;
|
|
133
|
+
/**
|
|
134
|
+
* 处理 info 操作。
|
|
135
|
+
* @param message - 已经本地化的用户提示。
|
|
136
|
+
* @param duration - 提示持续时间,单位毫秒。
|
|
137
|
+
* @returns 新条目的 ID,可用于提前移除。
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* import { toast } from '@h-ai/ui'
|
|
141
|
+
* // 布局中需挂载 ToastContainer。
|
|
142
|
+
* const id = toast.info('操作结果', 3000)
|
|
143
|
+
* toast.remove(id)
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
39
146
|
info(message: string, duration?: number): string;
|
|
40
147
|
}
|
|
41
148
|
/**
|
|
42
149
|
* Toast 单例
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* import { toast } from '@h-ai/ui'
|
|
154
|
+
* // 页面布局需挂载 ToastContainer。
|
|
155
|
+
* const id = toast.success('保存完成', 3000)
|
|
156
|
+
* toast.remove(id)
|
|
157
|
+
* toast.clear()
|
|
158
|
+
* ```
|
|
43
159
|
*/
|
|
44
160
|
export declare const toast: ToastState;
|
|
161
|
+
/**
|
|
162
|
+
* 在组件初始化时订阅操作提示,统一交给根布局的 ToastContainer 展示。
|
|
163
|
+
* 只跟踪消息来源,不订阅 Toast 队列;同一消息已在队列中时合并,避免父子组件重复提示。
|
|
164
|
+
* 字段校验保留控件关联和定位,提示统一由此入口展示;文案应已经完成安全映射和本地化。
|
|
165
|
+
* 订阅随组件销毁结束,已发出的通知继续由根容器管理。
|
|
166
|
+
* @param message - 响应式消息读取函数;空值表示没有待提示的操作结果。
|
|
167
|
+
* @param variant - 通知类型,默认 error。
|
|
168
|
+
* @example
|
|
169
|
+
* ```svelte
|
|
170
|
+
* <script lang="ts">
|
|
171
|
+
* import { useToastFeedback } from '@h-ai/ui/toast'
|
|
172
|
+
* let error = $state('')
|
|
173
|
+
* useToastFeedback(() => error)
|
|
174
|
+
* </script>
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
export declare function useToastFeedback(message: () => string | undefined | null, variant?: NonNullable<ToastProps['variant']>): void;
|
|
178
|
+
/**
|
|
179
|
+
* 弹出操作成功提示(默认右下角)。
|
|
180
|
+
*
|
|
181
|
+
* @description 统一封装 toast 单例,业务应用无需自建 toast 工具文件即可获得一致的成功反馈。
|
|
182
|
+
*
|
|
183
|
+
* @param message - 用户可见的成功文案(已本地化)。
|
|
184
|
+
* @param duration - 可选停留时长(毫秒),默认 3000。
|
|
185
|
+
* @returns 新通知的 ID,可交给 toast.remove 提前移除。
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```ts
|
|
189
|
+
* import { notifySuccess, toast } from '@h-ai/ui'
|
|
190
|
+
* const id = notifySuccess('保存完成', 3000)
|
|
191
|
+
* toast.remove(id)
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export declare function notifySuccess(message: string, duration?: number): string;
|
|
195
|
+
/**
|
|
196
|
+
* 弹出操作失败提示(默认右下角)。
|
|
197
|
+
*
|
|
198
|
+
* @description 接受完整错误对象或已本地化的安全字符串;普通 Error 隐藏原文,
|
|
199
|
+
* 使用 fallback 或通用错误并保留 traceId。不要把未知 Error.message 转成字符串传入。
|
|
200
|
+
*
|
|
201
|
+
* @param error - 错误对象或已本地化的错误文案。
|
|
202
|
+
* @param fallback - 未识别的异常或缺少错误文案时使用的安全兜底说明。
|
|
203
|
+
* @param duration - 可选停留时长(毫秒),默认 5000。
|
|
204
|
+
* @returns 新错误通知的 ID,可交给 toast.remove 提前移除。
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```ts
|
|
208
|
+
* import { notifyError, toast } from '@h-ai/ui'
|
|
209
|
+
* const id = notifyError(new Error('提交失败'), '请稍后重试', 5000)
|
|
210
|
+
* toast.remove(id)
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
export declare function notifyError(error: unknown, fallback?: string, duration?: number): string;
|
|
214
|
+
/**
|
|
215
|
+
* 生成安全错误提示;日志保留脱敏原因,字符串携带追踪编号供 ToastContainer 分离展示。
|
|
216
|
+
* @example
|
|
217
|
+
* ```ts
|
|
218
|
+
* import { errorMessage } from '@h-ai/ui'
|
|
219
|
+
* const text = errorMessage(new Error('Internal detail'), '保存失败')
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
export declare function errorMessage(error: unknown, fallback?: string): string;
|
|
223
|
+
/**
|
|
224
|
+
* 弹出信息提示(默认右下角)。
|
|
225
|
+
*
|
|
226
|
+
* @param message - 用户可见文案(已本地化)。
|
|
227
|
+
* @param duration - 可选停留时长(毫秒),默认 3000。
|
|
228
|
+
* @returns 新提示的 ID。
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```ts
|
|
232
|
+
* import { notifyInfo, toast } from '@h-ai/ui'
|
|
233
|
+
* const id = notifyInfo('正在同步', 3000)
|
|
234
|
+
* toast.remove(id)
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
export declare function notifyInfo(message: string, duration?: number): string;
|
|
238
|
+
/**
|
|
239
|
+
* 弹出警告提示(默认右下角)。
|
|
240
|
+
*
|
|
241
|
+
* @param message - 用户可见文案(已本地化)。
|
|
242
|
+
* @param duration - 可选停留时长(毫秒),默认 5000。
|
|
243
|
+
* @returns 新警告的 ID。
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```ts
|
|
247
|
+
* import { notifyWarning, toast } from '@h-ai/ui'
|
|
248
|
+
* const id = notifyWarning('请先保存修改', 5000)
|
|
249
|
+
* toast.remove(id)
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
export declare function notifyWarning(message: string, duration?: number): string;
|
|
45
253
|
export {};
|
package/dist/toast.svelte.js
CHANGED
|
@@ -4,74 +4,360 @@
|
|
|
4
4
|
* Toast 通知的状态管理,使用 Svelte 5 Runes
|
|
5
5
|
* @module toast.svelte
|
|
6
6
|
*/
|
|
7
|
+
import { core } from '@h-ai/core';
|
|
8
|
+
import { untrack } from 'svelte';
|
|
9
|
+
/** 兼容安全错误消息中的追踪编号,将排查信息从用户说明中分离。 */
|
|
10
|
+
function normalizeMessage(message, explicitTraceId) {
|
|
11
|
+
let traceId = explicitTraceId && /^[\w.:-]{1,128}$/.test(explicitTraceId) ? explicitTraceId : undefined;
|
|
12
|
+
const parts = [];
|
|
13
|
+
let cursor = 0;
|
|
14
|
+
// 先找固定标记,再移除相邻空白;无标记的长空白不会从每个字符重新回溯。
|
|
15
|
+
for (const match of message.matchAll(/\(traceId: ([\w.:-]{1,128})\)/g)) {
|
|
16
|
+
let end = match.index;
|
|
17
|
+
while (end > cursor && message[end - 1].trim() === '')
|
|
18
|
+
end--;
|
|
19
|
+
parts.push(message.slice(cursor, end));
|
|
20
|
+
cursor = match.index + match[0].length;
|
|
21
|
+
traceId ??= match[1];
|
|
22
|
+
}
|
|
23
|
+
parts.push(message.slice(cursor));
|
|
24
|
+
const readable = parts.join('').trim();
|
|
25
|
+
return { message: readable || core.i18n.coreM('core_errorInternal'), traceId };
|
|
26
|
+
}
|
|
7
27
|
/**
|
|
8
28
|
* Toast 状态
|
|
9
29
|
*/
|
|
10
30
|
class ToastState {
|
|
11
31
|
items = $state([]);
|
|
12
|
-
/**
|
|
13
|
-
|
|
32
|
+
/** 仅队首计时,等待项在展示后才开始计算停留时间。 */
|
|
33
|
+
timer;
|
|
34
|
+
deadline = 0;
|
|
35
|
+
remaining = 0;
|
|
36
|
+
paused = false;
|
|
37
|
+
startTimer(duration = this.items[0]?.duration ?? 0) {
|
|
38
|
+
const item = this.items[0];
|
|
39
|
+
if (item && (item.duration ?? 0) > 0) {
|
|
40
|
+
this.remaining = duration;
|
|
41
|
+
this.deadline = Date.now() + duration;
|
|
42
|
+
this.timer = setTimeout(() => this.remove(item.id), duration);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 暂停当前提示的自动关闭,供阅读和交互期间使用;等待项不受影响。
|
|
47
|
+
* @param id - 当前提示 ID。
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* const id = toast.info('同步中')
|
|
51
|
+
* toast.pause(id)
|
|
52
|
+
* toast.resume(id)
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
pause(id) {
|
|
56
|
+
if (this.items[0]?.id !== id || this.paused)
|
|
57
|
+
return;
|
|
58
|
+
this.paused = true;
|
|
59
|
+
this.remaining = Math.max(0, this.deadline - Date.now());
|
|
60
|
+
clearTimeout(this.timer);
|
|
61
|
+
this.timer = undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 从剩余时间恢复当前提示的自动关闭;手工关闭或清空后不会恢复旧计时器。
|
|
65
|
+
* @param id - 当前提示 ID。
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* const id = toast.info('同步中')
|
|
69
|
+
* toast.pause(id)
|
|
70
|
+
* toast.resume(id)
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
resume(id) {
|
|
74
|
+
if (this.items[0]?.id !== id || !this.paused)
|
|
75
|
+
return;
|
|
76
|
+
this.paused = false;
|
|
77
|
+
this.startTimer(this.remaining);
|
|
78
|
+
}
|
|
14
79
|
/**
|
|
15
80
|
* 添加 Toast
|
|
81
|
+
* @param props - 组件的属性对象。
|
|
82
|
+
* @returns 新条目的 ID,可用于提前移除。
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { toast } from '@h-ai/ui'
|
|
86
|
+
* // 布局中需挂载 ToastContainer。
|
|
87
|
+
* const id = toast.add({ message: '保存完成', variant: 'success', duration: 3000 })
|
|
88
|
+
* toast.remove(id)
|
|
89
|
+
* ```
|
|
16
90
|
*/
|
|
17
91
|
add(props) {
|
|
18
92
|
const id = Math.random().toString(36).slice(2, 9);
|
|
19
93
|
const item = {
|
|
20
94
|
...props,
|
|
95
|
+
...normalizeMessage(props.message, props.traceId),
|
|
21
96
|
id,
|
|
22
97
|
duration: props.duration ?? 3000,
|
|
23
|
-
position: props.position ?? '
|
|
98
|
+
position: props.position ?? 'bottom-right',
|
|
24
99
|
dismissible: props.dismissible ?? true,
|
|
25
100
|
};
|
|
26
101
|
this.items = [...this.items, item];
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const timer = setTimeout(() => {
|
|
30
|
-
this.timers.delete(id);
|
|
31
|
-
this.remove(id);
|
|
32
|
-
}, item.duration);
|
|
33
|
-
this.timers.set(id, timer);
|
|
34
|
-
}
|
|
102
|
+
if (this.items.length === 1)
|
|
103
|
+
this.startTimer();
|
|
35
104
|
return id;
|
|
36
105
|
}
|
|
37
106
|
/**
|
|
38
107
|
* 移除 Toast
|
|
108
|
+
* @param id - 待移除的条目 ID。
|
|
109
|
+
* @returns {void} 无返回值;同时清理对应的自动关闭定时器。
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* import { toast } from '@h-ai/ui'
|
|
113
|
+
* // 布局中需挂载 ToastContainer。
|
|
114
|
+
* const id = toast.info('同步中', 0)
|
|
115
|
+
* toast.remove(id)
|
|
116
|
+
* ```
|
|
39
117
|
*/
|
|
40
118
|
remove(id) {
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
clearTimeout(timer);
|
|
44
|
-
this.
|
|
119
|
+
const isCurrent = this.items[0]?.id === id;
|
|
120
|
+
if (isCurrent) {
|
|
121
|
+
clearTimeout(this.timer);
|
|
122
|
+
this.timer = undefined;
|
|
123
|
+
this.paused = false;
|
|
45
124
|
}
|
|
46
125
|
this.items = this.items.filter(item => item.id !== id);
|
|
126
|
+
if (isCurrent)
|
|
127
|
+
this.startTimer();
|
|
47
128
|
}
|
|
48
129
|
/**
|
|
49
130
|
* 清空所有 Toast
|
|
131
|
+
* @returns {void} 无返回值;同时清理对应的自动关闭定时器。
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* import { toast } from '@h-ai/ui'
|
|
135
|
+
* // 布局中需挂载 ToastContainer。
|
|
136
|
+
* toast.info('同步中', 0)
|
|
137
|
+
* toast.clear()
|
|
138
|
+
* ```
|
|
50
139
|
*/
|
|
51
140
|
clear() {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this.timers.clear();
|
|
141
|
+
clearTimeout(this.timer);
|
|
142
|
+
this.timer = undefined;
|
|
143
|
+
this.paused = false;
|
|
56
144
|
this.items = [];
|
|
57
145
|
}
|
|
58
146
|
/**
|
|
59
147
|
* 快捷方法
|
|
148
|
+
* @param message - 已经本地化的用户提示。
|
|
149
|
+
* @param duration - 提示持续时间,单位毫秒。
|
|
150
|
+
* @returns 新条目的 ID,可用于提前移除。
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* import { toast } from '@h-ai/ui'
|
|
154
|
+
* // 布局中需挂载 ToastContainer。
|
|
155
|
+
* const id = toast.success('操作结果', 3000)
|
|
156
|
+
* toast.remove(id)
|
|
157
|
+
* ```
|
|
60
158
|
*/
|
|
61
159
|
success(message, duration) {
|
|
62
160
|
return this.add({ message, variant: 'success', duration });
|
|
63
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* 处理 error 操作。
|
|
164
|
+
* @param message - 已经本地化的用户提示。
|
|
165
|
+
* @param duration - 提示持续时间,单位毫秒。
|
|
166
|
+
* @returns 新条目的 ID,可用于提前移除。
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* import { toast } from '@h-ai/ui'
|
|
170
|
+
* // 布局中需挂载 ToastContainer。
|
|
171
|
+
* const id = toast.error('操作结果', 3000)
|
|
172
|
+
* toast.remove(id)
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
64
175
|
error(message, duration) {
|
|
65
176
|
return this.add({ message, variant: 'error', duration });
|
|
66
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* 处理 warning 操作。
|
|
180
|
+
* @param message - 已经本地化的用户提示。
|
|
181
|
+
* @param duration - 提示持续时间,单位毫秒。
|
|
182
|
+
* @returns 新条目的 ID,可用于提前移除。
|
|
183
|
+
* @example
|
|
184
|
+
* ```ts
|
|
185
|
+
* import { toast } from '@h-ai/ui'
|
|
186
|
+
* // 布局中需挂载 ToastContainer。
|
|
187
|
+
* const id = toast.warning('操作结果', 3000)
|
|
188
|
+
* toast.remove(id)
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
67
191
|
warning(message, duration) {
|
|
68
192
|
return this.add({ message, variant: 'warning', duration });
|
|
69
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* 处理 info 操作。
|
|
196
|
+
* @param message - 已经本地化的用户提示。
|
|
197
|
+
* @param duration - 提示持续时间,单位毫秒。
|
|
198
|
+
* @returns 新条目的 ID,可用于提前移除。
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* import { toast } from '@h-ai/ui'
|
|
202
|
+
* // 布局中需挂载 ToastContainer。
|
|
203
|
+
* const id = toast.info('操作结果', 3000)
|
|
204
|
+
* toast.remove(id)
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
70
207
|
info(message, duration) {
|
|
71
208
|
return this.add({ message, variant: 'info', duration });
|
|
72
209
|
}
|
|
73
210
|
}
|
|
74
211
|
/**
|
|
75
212
|
* Toast 单例
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```ts
|
|
216
|
+
* import { toast } from '@h-ai/ui'
|
|
217
|
+
* // 页面布局需挂载 ToastContainer。
|
|
218
|
+
* const id = toast.success('保存完成', 3000)
|
|
219
|
+
* toast.remove(id)
|
|
220
|
+
* toast.clear()
|
|
221
|
+
* ```
|
|
76
222
|
*/
|
|
77
223
|
export const toast = new ToastState();
|
|
224
|
+
/**
|
|
225
|
+
* 在组件初始化时订阅操作提示,统一交给根布局的 ToastContainer 展示。
|
|
226
|
+
* 只跟踪消息来源,不订阅 Toast 队列;同一消息已在队列中时合并,避免父子组件重复提示。
|
|
227
|
+
* 字段校验保留控件关联和定位,提示统一由此入口展示;文案应已经完成安全映射和本地化。
|
|
228
|
+
* 订阅随组件销毁结束,已发出的通知继续由根容器管理。
|
|
229
|
+
* @param message - 响应式消息读取函数;空值表示没有待提示的操作结果。
|
|
230
|
+
* @param variant - 通知类型,默认 error。
|
|
231
|
+
* @example
|
|
232
|
+
* ```svelte
|
|
233
|
+
* <script lang="ts">
|
|
234
|
+
* import { useToastFeedback } from '@h-ai/ui/toast'
|
|
235
|
+
* let error = $state('')
|
|
236
|
+
* useToastFeedback(() => error)
|
|
237
|
+
* </script>
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
export function useToastFeedback(message, variant = 'error') {
|
|
241
|
+
let ownId;
|
|
242
|
+
$effect(() => {
|
|
243
|
+
const value = message();
|
|
244
|
+
untrack(() => {
|
|
245
|
+
if (ownId)
|
|
246
|
+
toast.remove(ownId);
|
|
247
|
+
ownId = undefined;
|
|
248
|
+
if (!value)
|
|
249
|
+
return;
|
|
250
|
+
const normalized = normalizeMessage(value);
|
|
251
|
+
if (!toast.items.some(item => item.message === normalized.message && item.traceId === normalized.traceId && item.variant === variant))
|
|
252
|
+
ownId = toast.add({ message: value, variant });
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
/** 成功提示默认停留时长(毫秒)。 */
|
|
257
|
+
const SUCCESS_DURATION = 3000;
|
|
258
|
+
/** 失败提示默认停留时长(毫秒),比成功略长便于阅读错误信息。 */
|
|
259
|
+
const ERROR_DURATION = 5000;
|
|
260
|
+
/**
|
|
261
|
+
* 弹出操作成功提示(默认右下角)。
|
|
262
|
+
*
|
|
263
|
+
* @description 统一封装 toast 单例,业务应用无需自建 toast 工具文件即可获得一致的成功反馈。
|
|
264
|
+
*
|
|
265
|
+
* @param message - 用户可见的成功文案(已本地化)。
|
|
266
|
+
* @param duration - 可选停留时长(毫秒),默认 3000。
|
|
267
|
+
* @returns 新通知的 ID,可交给 toast.remove 提前移除。
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```ts
|
|
271
|
+
* import { notifySuccess, toast } from '@h-ai/ui'
|
|
272
|
+
* const id = notifySuccess('保存完成', 3000)
|
|
273
|
+
* toast.remove(id)
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
export function notifySuccess(message, duration = SUCCESS_DURATION) {
|
|
277
|
+
return toast.success(message, duration);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* 弹出操作失败提示(默认右下角)。
|
|
281
|
+
*
|
|
282
|
+
* @description 接受完整错误对象或已本地化的安全字符串;普通 Error 隐藏原文,
|
|
283
|
+
* 使用 fallback 或通用错误并保留 traceId。不要把未知 Error.message 转成字符串传入。
|
|
284
|
+
*
|
|
285
|
+
* @param error - 错误对象或已本地化的错误文案。
|
|
286
|
+
* @param fallback - 未识别的异常或缺少错误文案时使用的安全兜底说明。
|
|
287
|
+
* @param duration - 可选停留时长(毫秒),默认 5000。
|
|
288
|
+
* @returns 新错误通知的 ID,可交给 toast.remove 提前移除。
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* ```ts
|
|
292
|
+
* import { notifyError, toast } from '@h-ai/ui'
|
|
293
|
+
* const id = notifyError(new Error('提交失败'), '请稍后重试', 5000)
|
|
294
|
+
* toast.remove(id)
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
export function notifyError(error, fallback = '', duration = ERROR_DURATION) {
|
|
298
|
+
return toast.error(errorMessage(error, fallback), duration);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* 生成安全错误提示;日志保留脱敏原因,字符串携带追踪编号供 ToastContainer 分离展示。
|
|
302
|
+
* @example
|
|
303
|
+
* ```ts
|
|
304
|
+
* import { errorMessage } from '@h-ai/ui'
|
|
305
|
+
* const text = errorMessage(new Error('Internal detail'), '保存失败')
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
export function errorMessage(error, fallback = '') {
|
|
309
|
+
let known;
|
|
310
|
+
// Promise 回调可用原生 Error 携带 HaiError;保留业务原因和追踪信息,同时防止 cause 环。
|
|
311
|
+
let candidate = error;
|
|
312
|
+
const visited = [];
|
|
313
|
+
while (candidate instanceof Error && !visited.includes(candidate) && visited.length < 8) {
|
|
314
|
+
visited.push(candidate);
|
|
315
|
+
candidate = candidate.cause;
|
|
316
|
+
}
|
|
317
|
+
if (candidate && typeof candidate === 'object' && !(candidate instanceof Error) && Object.hasOwn(candidate, 'code') && Object.hasOwn(candidate, 'message') && 'code' in candidate && typeof candidate.code === 'string' && 'message' in candidate && typeof candidate.message === 'string')
|
|
318
|
+
known = candidate;
|
|
319
|
+
const receivedMessage = error instanceof Error ? error.message : typeof error === 'string' ? error : '';
|
|
320
|
+
const embeddedTraceId = /\(traceId: ([\w.:-]{1,128})\)$/.exec(receivedMessage)?.[1];
|
|
321
|
+
const traceId = known?.traceId ?? embeddedTraceId ?? core.context.get().traceId ?? core.context.get().requestId ?? core.id.uuid();
|
|
322
|
+
core.logger.error('User operation failed', { traceId, error });
|
|
323
|
+
let message = fallback || core.i18n.coreM('core_errorInternal');
|
|
324
|
+
if (known)
|
|
325
|
+
message = core.error.toPublic(known, traceId).message;
|
|
326
|
+
else if (typeof error === 'string')
|
|
327
|
+
message = receivedMessage;
|
|
328
|
+
return core.error.formatMessage({ message, traceId: /\(traceId: [\w.:-]{1,128}\)$/.test(message) ? undefined : traceId });
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* 弹出信息提示(默认右下角)。
|
|
332
|
+
*
|
|
333
|
+
* @param message - 用户可见文案(已本地化)。
|
|
334
|
+
* @param duration - 可选停留时长(毫秒),默认 3000。
|
|
335
|
+
* @returns 新提示的 ID。
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* ```ts
|
|
339
|
+
* import { notifyInfo, toast } from '@h-ai/ui'
|
|
340
|
+
* const id = notifyInfo('正在同步', 3000)
|
|
341
|
+
* toast.remove(id)
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
344
|
+
export function notifyInfo(message, duration = SUCCESS_DURATION) {
|
|
345
|
+
return toast.info(message, duration);
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* 弹出警告提示(默认右下角)。
|
|
349
|
+
*
|
|
350
|
+
* @param message - 用户可见文案(已本地化)。
|
|
351
|
+
* @param duration - 可选停留时长(毫秒),默认 5000。
|
|
352
|
+
* @returns 新警告的 ID。
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```ts
|
|
356
|
+
* import { notifyWarning, toast } from '@h-ai/ui'
|
|
357
|
+
* const id = notifyWarning('请先保存修改', 5000)
|
|
358
|
+
* toast.remove(id)
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
export function notifyWarning(message, duration = ERROR_DURATION) {
|
|
362
|
+
return toast.warning(message, duration);
|
|
363
|
+
}
|