@h-ai/ui 0.1.0-alpha9 → 1.0.0-beta.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.en.md +1036 -0
- package/README.ja.md +1036 -0
- package/README.md +670 -119
- package/auto-import.d.ts +45 -0
- package/auto-import.js +46 -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 +386 -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 +296 -77
- 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 +215 -0
- package/dist/components/scenes/ai/highlight.d.ts +37 -0
- package/dist/components/scenes/ai/highlight.js +162 -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 +42 -31
- 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 +163 -0
- package/dist/components/scenes/charts/Chart.svelte.d.ts +25 -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 +153 -0
- package/dist/components/scenes/charts/chart-types.js +7 -0
- package/dist/components/scenes/charts/index.d.ts +8 -0
- package/dist/components/scenes/charts/index.js +7 -0
- package/dist/components/scenes/charts/renderers/AreaChart.svelte +18 -0
- package/dist/components/scenes/charts/renderers/AreaChart.svelte.d.ts +5 -0
- package/dist/components/scenes/charts/renderers/BarChart.svelte +18 -0
- package/dist/components/scenes/charts/renderers/BarChart.svelte.d.ts +5 -0
- package/dist/components/scenes/charts/renderers/LineChart.svelte +624 -0
- package/dist/components/scenes/charts/renderers/LineChart.svelte.d.ts +32 -0
- package/dist/components/scenes/charts/renderers/PieChart.svelte +18 -0
- package/dist/components/scenes/charts/renderers/PieChart.svelte.d.ts +5 -0
- package/dist/components/scenes/charts/renderers/ScatterChart.svelte +18 -0
- package/dist/components/scenes/charts/renderers/ScatterChart.svelte.d.ts +5 -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 +297 -16
- package/dist/messages/ja-JP.json +523 -0
- package/dist/messages/zh-CN.json +297 -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/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 +42 -0
- package/dist/theme-config.d.ts +263 -10
- package/dist/theme-config.js +252 -17
- package/dist/toast.svelte.d.ts +210 -2
- package/dist/toast.svelte.js +296 -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
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 生成当前请求使用的单次证明;不缓存,不持久化,也不执行网络请求。
|
|
3
|
+
* @param input - 已由认证动作取得的可公开挑战。
|
|
4
|
+
* @param input.id - 服务端签发的挑战编号。
|
|
5
|
+
* @param input.challenge - 原始公开挑战,包含算法参数与签名。
|
|
6
|
+
* @param controller - 当前交互生命周期的取消控制器。
|
|
7
|
+
* @returns 求解成功时返回证明;超过求解期限时返回 null。
|
|
8
|
+
* @throws 取消或底层计算失败时抛错,由组件转换为安全的交互错误。
|
|
9
|
+
* @example 模块内部上下文
|
|
10
|
+
* ```ts
|
|
11
|
+
* async function prove(challenge: Challenge) {
|
|
12
|
+
* return solveAuthCaptcha({ id: 'challenge-id', challenge }, new AbortController())
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export async function solveAuthCaptcha(input, controller) {
|
|
17
|
+
controller.signal.throwIfAborted();
|
|
18
|
+
const { solveChallenge, pbkdf2 } = await import('altcha/lib');
|
|
19
|
+
controller.signal.throwIfAborted();
|
|
20
|
+
const solution = await solveChallenge({ challenge: input.challenge, deriveKey: pbkdf2.deriveKey, controller, timeout: 20000 });
|
|
21
|
+
controller.signal.throwIfAborted();
|
|
22
|
+
return solution ? JSON.stringify({ id: input.id, solution }) : null;
|
|
23
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HaiError } from '@h-ai/core';
|
|
2
|
+
/**
|
|
3
|
+
* 将 IAM 错误映射为当前语言的安全认证提示;未知错误和服务异常使用通用提示。
|
|
4
|
+
* @param error - 待显示的安全错误对象或消息。
|
|
5
|
+
* @returns 本地化提示及有效 traceId,不包含原始异常、账户字段原因或其他内部信息。
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { authErrorMessage } from '@h-ai/ui/components/scenes/iam/index'
|
|
10
|
+
* const message = authErrorMessage({ code: 'hai:iam:020', message: '登录失败' })
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare function authErrorMessage(error: Pick<HaiError, 'code' | 'message' | 'traceId' | 'httpStatus'>): string;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { core } from '@h-ai/core';
|
|
2
|
+
import { uiM } from '../../../messages.js';
|
|
3
|
+
const messages = {
|
|
4
|
+
'hai:common:104': 'request_access_denied',
|
|
5
|
+
'hai:iam:001': 'auth_error_credentials',
|
|
6
|
+
'hai:iam:002': 'auth_error_credentials',
|
|
7
|
+
'hai:iam:003': 'auth_error_credentials',
|
|
8
|
+
'hai:iam:004': 'auth_error_account_unavailable',
|
|
9
|
+
'hai:iam:005': 'auth_error_locked',
|
|
10
|
+
'hai:iam:006': 'auth_error_duplicate',
|
|
11
|
+
'hai:iam:007': 'auth_error_password_expired',
|
|
12
|
+
'hai:iam:008': 'auth_error_password_policy',
|
|
13
|
+
'hai:iam:009': 'auth_error_otp',
|
|
14
|
+
'hai:iam:010': 'auth_error_service',
|
|
15
|
+
'hai:iam:011': 'auth_error_otp_wait',
|
|
16
|
+
'hai:iam:012': 'auth_unavailable',
|
|
17
|
+
'hai:iam:013': 'auth_unavailable',
|
|
18
|
+
'hai:iam:014': 'auth_unavailable',
|
|
19
|
+
'hai:iam:019': 'auth_error_reset_token',
|
|
20
|
+
'hai:iam:020': 'auth_error_reset_token',
|
|
21
|
+
'hai:iam:021': 'auth_error_reset_token',
|
|
22
|
+
'hai:iam:022': 'auth_error_otp',
|
|
23
|
+
'hai:iam:023': 'auth_error_busy',
|
|
24
|
+
'hai:iam:024': 'auth_unavailable',
|
|
25
|
+
'hai:iam:025': 'auth_error_password_initial',
|
|
26
|
+
'hai:iam:026': 'auth_error_access',
|
|
27
|
+
'hai:iam:027': 'auth_error_reauthentication',
|
|
28
|
+
'hai:iam:030': 'auth_captcha_error',
|
|
29
|
+
'hai:iam:031': 'auth_captcha_error',
|
|
30
|
+
'hai:iam:032': 'auth_captcha_error',
|
|
31
|
+
'hai:iam:033': 'auth_captcha_error',
|
|
32
|
+
'hai:iam:034': 'auth_error_password_same',
|
|
33
|
+
'hai:iam:101': 'auth_error_session',
|
|
34
|
+
'hai:iam:102': 'auth_error_session',
|
|
35
|
+
'hai:iam:103': 'auth_error_session',
|
|
36
|
+
'hai:iam:104': 'auth_error_service',
|
|
37
|
+
'hai:iam:105': 'auth_error_session',
|
|
38
|
+
'hai:iam:106': 'auth_error_session',
|
|
39
|
+
'hai:iam:107': 'auth_error_session',
|
|
40
|
+
'hai:iam:108': 'auth_error_session_limit',
|
|
41
|
+
'hai:iam:110': 'auth_error_reauthentication',
|
|
42
|
+
'hai:iam:111': 'auth_error_reauthentication',
|
|
43
|
+
'hai:iam:201': 'auth_error_access',
|
|
44
|
+
'hai:iam:301': 'auth_error_service',
|
|
45
|
+
'hai:iam:302': 'auth_error_credentials',
|
|
46
|
+
'hai:iam:303': 'auth_error_service',
|
|
47
|
+
'hai:iam:401': 'auth_error_service',
|
|
48
|
+
'hai:iam:901': 'auth_error_service',
|
|
49
|
+
'hai:iam:999': 'auth_error_service',
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* 将 IAM 错误映射为当前语言的安全认证提示;未知错误和服务异常使用通用提示。
|
|
53
|
+
* @param error - 待显示的安全错误对象或消息。
|
|
54
|
+
* @returns 本地化提示及有效 traceId,不包含原始异常、账户字段原因或其他内部信息。
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { authErrorMessage } from '@h-ai/ui/components/scenes/iam/index'
|
|
59
|
+
* const message = authErrorMessage({ code: 'hai:iam:020', message: '登录失败' })
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export function authErrorMessage(error) {
|
|
63
|
+
const key = (error.httpStatus ?? 400) >= 500 || !Object.hasOwn(messages, error.code) ? 'auth_error_service' : messages[error.code] ?? 'auth_error_service';
|
|
64
|
+
return core.error.formatMessage({ message: uiM(key), traceId: error.traceId });
|
|
65
|
+
}
|
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
* 身份认证相关的场景化组件
|
|
5
5
|
* @module index
|
|
6
6
|
*/
|
|
7
|
+
export { authErrorMessage } from './auth-error-message.js';
|
|
8
|
+
export { default as AuthPanel } from './AuthPanel.svelte';
|
|
9
|
+
export { default as AuthShell } from './AuthShell.svelte';
|
|
7
10
|
export { default as ChangePasswordForm } from './ChangePasswordForm.svelte';
|
|
8
11
|
export { default as ForgotPasswordForm } from './ForgotPasswordForm.svelte';
|
|
9
12
|
export { default as LoginForm } from './LoginForm.svelte';
|
|
@@ -11,6 +14,13 @@ export { default as PasswordInput } from './PasswordInput.svelte';
|
|
|
11
14
|
export { default as PermGuard } from './PermGuard.svelte';
|
|
12
15
|
export { matchPermission, setPermissionContext, usePermission, } from './permission-context.svelte.js';
|
|
13
16
|
export type { PermissionContext } from './permission-context.svelte.js';
|
|
17
|
+
export { default as ReauthenticationDialog } from './ReauthenticationDialog.svelte';
|
|
14
18
|
export { default as RegisterForm } from './RegisterForm.svelte';
|
|
15
19
|
export { default as ResetPasswordForm } from './ResetPasswordForm.svelte';
|
|
20
|
+
export { createSensitiveActions } from './sensitive-actions.svelte.js';
|
|
21
|
+
export type { SensitiveActions, SensitiveActionsOptions } from './sensitive-actions.svelte.js';
|
|
22
|
+
export { default as SensitiveOperationsForm } from './SensitiveOperationsForm.svelte';
|
|
23
|
+
export { createSessionRecovery } from './session-recovery.svelte.js';
|
|
24
|
+
export type { SessionRecovery } from './session-recovery.svelte.js';
|
|
25
|
+
export { default as SessionRecoveryDialog } from './SessionRecoveryDialog.svelte';
|
|
16
26
|
export { default as UserProfile } from './UserProfile.svelte';
|
|
@@ -4,15 +4,23 @@
|
|
|
4
4
|
* 身份认证相关的场景化组件
|
|
5
5
|
* @module index
|
|
6
6
|
*/
|
|
7
|
+
export { authErrorMessage } from './auth-error-message.js';
|
|
8
|
+
export { default as AuthPanel } from './AuthPanel.svelte';
|
|
9
|
+
// 认证表单
|
|
10
|
+
export { default as AuthShell } from './AuthShell.svelte';
|
|
7
11
|
export { default as ChangePasswordForm } from './ChangePasswordForm.svelte';
|
|
8
12
|
export { default as ForgotPasswordForm } from './ForgotPasswordForm.svelte';
|
|
9
|
-
// 认证表单
|
|
10
13
|
export { default as LoginForm } from './LoginForm.svelte';
|
|
11
14
|
export { default as PasswordInput } from './PasswordInput.svelte';
|
|
12
15
|
// 权限控制
|
|
13
16
|
export { default as PermGuard } from './PermGuard.svelte';
|
|
14
17
|
export { matchPermission, setPermissionContext, usePermission, } from './permission-context.svelte.js';
|
|
18
|
+
export { default as ReauthenticationDialog } from './ReauthenticationDialog.svelte';
|
|
15
19
|
export { default as RegisterForm } from './RegisterForm.svelte';
|
|
16
20
|
export { default as ResetPasswordForm } from './ResetPasswordForm.svelte';
|
|
21
|
+
export { createSensitiveActions } from './sensitive-actions.svelte.js';
|
|
22
|
+
export { default as SensitiveOperationsForm } from './SensitiveOperationsForm.svelte';
|
|
23
|
+
export { createSessionRecovery } from './session-recovery.svelte.js';
|
|
24
|
+
export { default as SessionRecoveryDialog } from './SessionRecoveryDialog.svelte';
|
|
17
25
|
// 用户信息
|
|
18
26
|
export { default as UserProfile } from './UserProfile.svelte';
|
|
@@ -1,15 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @h-ai/ui — IAM 密码工具
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 密码原始字符串比较及策略提示工具
|
|
5
5
|
* @module password-utils
|
|
6
6
|
*/
|
|
7
|
+
import type { PasswordPolicy } from '../types.js';
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
-
* -
|
|
9
|
+
* 与服务端一致,逐字符比较两次密码;不归一化、裁剪空白或改写凭据。
|
|
10
|
+
* @param password - 用户输入的密码,不能持久化为 UI 偏好。
|
|
11
|
+
* @param confirmPassword - 再次输入的确认密码。
|
|
12
|
+
* @returns 两次密码的原始字符串是否完全一致。
|
|
13
|
+
*
|
|
14
|
+
* @example 模块内部上下文
|
|
15
|
+
* ```ts
|
|
16
|
+
* const same = arePasswordsEqual('Abcd1234!', 'Abcd1234!')
|
|
17
|
+
* ```
|
|
10
18
|
*/
|
|
11
|
-
export declare function
|
|
19
|
+
export declare function arePasswordsEqual(password: string, confirmPassword: string): boolean;
|
|
12
20
|
/**
|
|
13
|
-
*
|
|
21
|
+
* 与 IAM 密码策略一致的前端提示;服务端仍执行最终校验。
|
|
22
|
+
* @param password - 用户输入的密码,不能持久化为 UI 偏好。
|
|
23
|
+
* @param policy - 服务端公开的密码策略。
|
|
24
|
+
* @returns 第一项未满足策略的提示,全部满足时为空字符串。
|
|
25
|
+
*
|
|
26
|
+
* @example 模块内部上下文
|
|
27
|
+
* ```ts
|
|
28
|
+
* const message = passwordPolicyError('Example-pass-42!', { minLength: 12, maxLength: 128, requireUppercase: true, requireLowercase: true, requireNumber: true, requireSpecialChar: true })
|
|
29
|
+
* ```
|
|
14
30
|
*/
|
|
15
|
-
export declare function
|
|
31
|
+
export declare function passwordPolicyError(password: string, policy: PasswordPolicy): string;
|
|
32
|
+
/**
|
|
33
|
+
* 按当前 UI 语言说明服务端公开的密码策略。
|
|
34
|
+
* @param policy - 服务端公开的密码策略。
|
|
35
|
+
* @returns 按当前 UI 语言拼接的密码策略说明。
|
|
36
|
+
*
|
|
37
|
+
* @example 模块内部上下文
|
|
38
|
+
* ```ts
|
|
39
|
+
* const hint = passwordPolicyHint({ minLength: 12, maxLength: 128, requireUppercase: true, requireLowercase: true, requireNumber: true, requireSpecialChar: true })
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function passwordPolicyHint(policy: PasswordPolicy): string;
|
|
@@ -1,19 +1,72 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @h-ai/ui — IAM 密码工具
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 密码原始字符串比较及策略提示工具
|
|
5
5
|
* @module password-utils
|
|
6
6
|
*/
|
|
7
|
+
import { uiM } from '../../../messages.js';
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
-
* -
|
|
9
|
+
* 与服务端一致,逐字符比较两次密码;不归一化、裁剪空白或改写凭据。
|
|
10
|
+
* @param password - 用户输入的密码,不能持久化为 UI 偏好。
|
|
11
|
+
* @param confirmPassword - 再次输入的确认密码。
|
|
12
|
+
* @returns 两次密码的原始字符串是否完全一致。
|
|
13
|
+
*
|
|
14
|
+
* @example 模块内部上下文
|
|
15
|
+
* ```ts
|
|
16
|
+
* const same = arePasswordsEqual('Abcd1234!', 'Abcd1234!')
|
|
17
|
+
* ```
|
|
10
18
|
*/
|
|
11
|
-
export function
|
|
12
|
-
return
|
|
19
|
+
export function arePasswordsEqual(password, confirmPassword) {
|
|
20
|
+
return password === confirmPassword;
|
|
13
21
|
}
|
|
14
22
|
/**
|
|
15
|
-
*
|
|
23
|
+
* 与 IAM 密码策略一致的前端提示;服务端仍执行最终校验。
|
|
24
|
+
* @param password - 用户输入的密码,不能持久化为 UI 偏好。
|
|
25
|
+
* @param policy - 服务端公开的密码策略。
|
|
26
|
+
* @returns 第一项未满足策略的提示,全部满足时为空字符串。
|
|
27
|
+
*
|
|
28
|
+
* @example 模块内部上下文
|
|
29
|
+
* ```ts
|
|
30
|
+
* const message = passwordPolicyError('Example-pass-42!', { minLength: 12, maxLength: 128, requireUppercase: true, requireLowercase: true, requireNumber: true, requireSpecialChar: true })
|
|
31
|
+
* ```
|
|
16
32
|
*/
|
|
17
|
-
export function
|
|
18
|
-
|
|
33
|
+
export function passwordPolicyError(password, policy) {
|
|
34
|
+
if (password.length < policy.minLength || password.length > policy.maxLength)
|
|
35
|
+
return uiM('password_policy_length', { min: policy.minLength, max: policy.maxLength });
|
|
36
|
+
if (policy.requireUppercase && !/[A-Z]/.test(password))
|
|
37
|
+
return uiM('password_policy_uppercase');
|
|
38
|
+
if (policy.requireLowercase && !/[a-z]/.test(password))
|
|
39
|
+
return uiM('password_policy_lowercase');
|
|
40
|
+
if (policy.requireNumber && !/\d/.test(password))
|
|
41
|
+
return uiM('password_policy_number');
|
|
42
|
+
if (policy.requireSpecialChar && !/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(password))
|
|
43
|
+
return uiM('password_policy_special');
|
|
44
|
+
const classes = [/[A-Z]/, /[a-z]/, /\d/, /[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/].filter(pattern => pattern.test(password)).length;
|
|
45
|
+
if (classes < (policy.minCharacterClasses ?? 0))
|
|
46
|
+
return uiM('password_policy_classes', { count: policy.minCharacterClasses ?? 0 });
|
|
47
|
+
return '';
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 按当前 UI 语言说明服务端公开的密码策略。
|
|
51
|
+
* @param policy - 服务端公开的密码策略。
|
|
52
|
+
* @returns 按当前 UI 语言拼接的密码策略说明。
|
|
53
|
+
*
|
|
54
|
+
* @example 模块内部上下文
|
|
55
|
+
* ```ts
|
|
56
|
+
* const hint = passwordPolicyHint({ minLength: 12, maxLength: 128, requireUppercase: true, requireLowercase: true, requireNumber: true, requireSpecialChar: true })
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export function passwordPolicyHint(policy) {
|
|
60
|
+
const requirements = [uiM('password_policy_length', { min: policy.minLength, max: policy.maxLength })];
|
|
61
|
+
if (policy.requireUppercase)
|
|
62
|
+
requirements.push(uiM('password_policy_uppercase'));
|
|
63
|
+
if (policy.requireLowercase)
|
|
64
|
+
requirements.push(uiM('password_policy_lowercase'));
|
|
65
|
+
if (policy.requireNumber)
|
|
66
|
+
requirements.push(uiM('password_policy_number'));
|
|
67
|
+
if (policy.requireSpecialChar)
|
|
68
|
+
requirements.push(uiM('password_policy_special'));
|
|
69
|
+
if (policy.minCharacterClasses)
|
|
70
|
+
requirements.push(uiM('password_policy_classes', { count: policy.minCharacterClasses }));
|
|
71
|
+
return requirements.join(' · ');
|
|
19
72
|
}
|
|
@@ -6,20 +6,12 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```svelte
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* setPermissionContext(() =>
|
|
13
|
-
* </script>
|
|
14
|
-
*
|
|
15
|
-
* <!-- 子组件 -->
|
|
16
|
-
* <script>
|
|
17
|
-
* import { usePermission } from '@h-ai/ui'
|
|
18
|
-
* const { hasPerm, hasAnyPerm, hasAllPerms } = usePermission()
|
|
9
|
+
* <script lang="ts">
|
|
10
|
+
* import { setPermissionContext, PermGuard } from '@h-ai/ui'
|
|
11
|
+
* const permissions = ['user:create']
|
|
12
|
+
* setPermissionContext(() => permissions)
|
|
19
13
|
* </script>
|
|
20
|
-
*
|
|
21
|
-
* <button>新建用户</button>
|
|
22
|
-
* {/if}
|
|
14
|
+
* <PermGuard permission="user:create"><button type="button">新建用户</button></PermGuard>
|
|
23
15
|
* ```
|
|
24
16
|
*
|
|
25
17
|
* @module permission-context.svelte
|
|
@@ -35,9 +27,28 @@
|
|
|
35
27
|
* @param required - 需要检查的权限码
|
|
36
28
|
* @param userPermissions - 用户拥有的权限列表
|
|
37
29
|
* @returns 是否匹配
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { matchPermission } from '@h-ai/ui'
|
|
34
|
+
* const canRead = matchPermission('user:read', ['user:*'])
|
|
35
|
+
* const canDelete = matchPermission('user:delete', ['user:read'])
|
|
36
|
+
* ```
|
|
38
37
|
*/
|
|
39
38
|
export declare function matchPermission(required: string, userPermissions: string[]): boolean;
|
|
40
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* 权限上下文消费接口
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```svelte
|
|
44
|
+
* <script lang="ts">
|
|
45
|
+
* import { usePermission } from '@h-ai/ui'
|
|
46
|
+
* import type { PermissionContext } from '@h-ai/ui'
|
|
47
|
+
* const permission: PermissionContext = usePermission()
|
|
48
|
+
* </script>
|
|
49
|
+
* {#if permission.hasPerm('user:read')}<span>用户列表</span>{/if}
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
41
52
|
export interface PermissionContext {
|
|
42
53
|
/** 当前用户权限列表(响应式) */
|
|
43
54
|
readonly permissions: string[];
|
|
@@ -56,15 +67,16 @@ export interface PermissionContext {
|
|
|
56
67
|
* 以便权限变化时自动触发子组件更新。
|
|
57
68
|
*
|
|
58
69
|
* @param getPermissions - 返回当前用户权限列表的函数
|
|
70
|
+
* @returns {void} 无返回值;注册当前组件树的权限读取函数。
|
|
59
71
|
*
|
|
60
72
|
* @example
|
|
61
73
|
* ```svelte
|
|
62
|
-
* <script>
|
|
74
|
+
* <script lang="ts">
|
|
63
75
|
* import { setPermissionContext } from '@h-ai/ui'
|
|
64
|
-
* let
|
|
65
|
-
*
|
|
66
|
-
* setPermissionContext(() => userPermissions)
|
|
76
|
+
* let permissions = $state(['user:read'])
|
|
77
|
+
* setPermissionContext(() => permissions)
|
|
67
78
|
* </script>
|
|
79
|
+
* <main>在此渲染需要权限上下文的子组件。</main>
|
|
68
80
|
* ```
|
|
69
81
|
*/
|
|
70
82
|
export declare function setPermissionContext(getPermissions: () => string[]): void;
|
|
@@ -78,13 +90,11 @@ export declare function setPermissionContext(getPermissions: () => string[]): vo
|
|
|
78
90
|
*
|
|
79
91
|
* @example
|
|
80
92
|
* ```svelte
|
|
81
|
-
* <script>
|
|
93
|
+
* <script lang="ts">
|
|
82
94
|
* import { usePermission } from '@h-ai/ui'
|
|
83
|
-
* const
|
|
95
|
+
* const permission = usePermission()
|
|
84
96
|
* </script>
|
|
85
|
-
* {#if
|
|
86
|
-
* <button>创建角色</button>
|
|
87
|
-
* {/if}
|
|
97
|
+
* {#if permission.hasAnyPerm('user:read', 'user:update')}<span>用户管理</span>{/if}
|
|
88
98
|
* ```
|
|
89
99
|
*/
|
|
90
100
|
export declare function usePermission(): PermissionContext;
|
|
@@ -6,20 +6,12 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```svelte
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* setPermissionContext(() =>
|
|
13
|
-
* </script>
|
|
14
|
-
*
|
|
15
|
-
* <!-- 子组件 -->
|
|
16
|
-
* <script>
|
|
17
|
-
* import { usePermission } from '@h-ai/ui'
|
|
18
|
-
* const { hasPerm, hasAnyPerm, hasAllPerms } = usePermission()
|
|
9
|
+
* <script lang="ts">
|
|
10
|
+
* import { setPermissionContext, PermGuard } from '@h-ai/ui'
|
|
11
|
+
* const permissions = ['user:create']
|
|
12
|
+
* setPermissionContext(() => permissions)
|
|
19
13
|
* </script>
|
|
20
|
-
*
|
|
21
|
-
* <button>新建用户</button>
|
|
22
|
-
* {/if}
|
|
14
|
+
* <PermGuard permission="user:create"><button type="button">新建用户</button></PermGuard>
|
|
23
15
|
* ```
|
|
24
16
|
*
|
|
25
17
|
* @module permission-context.svelte
|
|
@@ -39,6 +31,13 @@ const PERMISSION_CONTEXT_KEY = Symbol('hai-permission-context');
|
|
|
39
31
|
* @param required - 需要检查的权限码
|
|
40
32
|
* @param userPermissions - 用户拥有的权限列表
|
|
41
33
|
* @returns 是否匹配
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { matchPermission } from '@h-ai/ui'
|
|
38
|
+
* const canRead = matchPermission('user:read', ['user:*'])
|
|
39
|
+
* const canDelete = matchPermission('user:delete', ['user:read'])
|
|
40
|
+
* ```
|
|
42
41
|
*/
|
|
43
42
|
export function matchPermission(required, userPermissions) {
|
|
44
43
|
for (const userPerm of userPermissions) {
|
|
@@ -58,15 +57,16 @@ export function matchPermission(required, userPermissions) {
|
|
|
58
57
|
* 以便权限变化时自动触发子组件更新。
|
|
59
58
|
*
|
|
60
59
|
* @param getPermissions - 返回当前用户权限列表的函数
|
|
60
|
+
* @returns {void} 无返回值;注册当前组件树的权限读取函数。
|
|
61
61
|
*
|
|
62
62
|
* @example
|
|
63
63
|
* ```svelte
|
|
64
|
-
* <script>
|
|
64
|
+
* <script lang="ts">
|
|
65
65
|
* import { setPermissionContext } from '@h-ai/ui'
|
|
66
|
-
* let
|
|
67
|
-
*
|
|
68
|
-
* setPermissionContext(() => userPermissions)
|
|
66
|
+
* let permissions = $state(['user:read'])
|
|
67
|
+
* setPermissionContext(() => permissions)
|
|
69
68
|
* </script>
|
|
69
|
+
* <main>在此渲染需要权限上下文的子组件。</main>
|
|
70
70
|
* ```
|
|
71
71
|
*/
|
|
72
72
|
export function setPermissionContext(getPermissions) {
|
|
@@ -82,13 +82,11 @@ export function setPermissionContext(getPermissions) {
|
|
|
82
82
|
*
|
|
83
83
|
* @example
|
|
84
84
|
* ```svelte
|
|
85
|
-
* <script>
|
|
85
|
+
* <script lang="ts">
|
|
86
86
|
* import { usePermission } from '@h-ai/ui'
|
|
87
|
-
* const
|
|
87
|
+
* const permission = usePermission()
|
|
88
88
|
* </script>
|
|
89
|
-
* {#if
|
|
90
|
-
* <button>创建角色</button>
|
|
91
|
-
* {/if}
|
|
89
|
+
* {#if permission.hasAnyPerm('user:read', 'user:update')}<span>用户管理</span>{/if}
|
|
92
90
|
* ```
|
|
93
91
|
*/
|
|
94
92
|
export function usePermission() {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** 敏感操作密码确认的页面级状态;网络传输及业务动作仍由宿主提供。 */
|
|
2
|
+
import type { HaiResult } from '@h-ai/core';
|
|
3
|
+
/**
|
|
4
|
+
* 二次认证动作;直接接受 Kit/API client 的 createAuthActions() 返回值。
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import type { SensitiveActionsOptions } from '@h-ai/ui'
|
|
8
|
+
* import { kit } from '@h-ai/kit'
|
|
9
|
+
* const options: SensitiveActionsOptions = kit.client.createAuthActions()
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export interface SensitiveActionsOptions {
|
|
13
|
+
/** 验证当前账号密码,取得仅供指定操作使用的短期单次凭据。 */
|
|
14
|
+
reauthenticate: (password: string, operation: string) => Promise<HaiResult<{
|
|
15
|
+
ticket: string;
|
|
16
|
+
}>>;
|
|
17
|
+
/** 标准动作可提供实时公开策略,权限表变更无需等待重新加载页面。 */
|
|
18
|
+
publicConfig?: () => Promise<HaiResult<{
|
|
19
|
+
reauthentication?: {
|
|
20
|
+
enabled: boolean;
|
|
21
|
+
operations: string[];
|
|
22
|
+
};
|
|
23
|
+
} | null>>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 绑定 ReauthenticationDialog 的状态与动作;每个应用根布局创建一份。
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { createSensitiveActions } from '@h-ai/ui'
|
|
30
|
+
* import { kit } from '@h-ai/kit'
|
|
31
|
+
* const confirmation = createSensitiveActions(kit.client.createAuthActions())
|
|
32
|
+
* confirmation.configure({ enabled: true, operations: ['orders.approve'] })
|
|
33
|
+
* confirmation.cancel()
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export interface SensitiveActions {
|
|
37
|
+
readonly open: boolean;
|
|
38
|
+
readonly loading: boolean;
|
|
39
|
+
readonly error: string;
|
|
40
|
+
/** 设置服务端公开策略;撤销当前操作时取消待确认动作。 */
|
|
41
|
+
configure: (policy: {
|
|
42
|
+
enabled: boolean;
|
|
43
|
+
operations: readonly string[];
|
|
44
|
+
}) => void;
|
|
45
|
+
/** undefined 表示无需确认,null 表示取消/忙,字符串为本次操作证明。 */
|
|
46
|
+
authorize: (operation: string) => Promise<string | null | undefined>;
|
|
47
|
+
/** 提交当前密码;错误在弹窗内显示,重复点击不会重复请求。 */
|
|
48
|
+
submit: (password: string) => Promise<void>;
|
|
49
|
+
/** 关闭弹窗或布局卸载时调用;迟到响应不能放行其他动作。 */
|
|
50
|
+
cancel: () => void;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 创建可跨业务复用的敏感动作确认状态,与 ReauthenticationDialog 配套。
|
|
54
|
+
* 密码不写入状态或存储;证明仅返回给 authorize 的对应调用者,不设置全局请求头。
|
|
55
|
+
* @param options - Kit/API client 的标准认证动作,或同签名自定义动作。
|
|
56
|
+
* @returns 页面级确认控制器;业务授权和凭据消费始终由服务端执行。
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { createSensitiveActions } from '@h-ai/ui'
|
|
60
|
+
* import { kit } from '@h-ai/kit'
|
|
61
|
+
* const confirmation = createSensitiveActions(kit.client.createAuthActions())
|
|
62
|
+
* confirmation.configure({ enabled: false, operations: [] })
|
|
63
|
+
* const ticket = await confirmation.authorize('orders.approve')
|
|
64
|
+
* // null 时中止;有 ticket 时仅传给这一笔请求。
|
|
65
|
+
* void ticket
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function createSensitiveActions(options: SensitiveActionsOptions): SensitiveActions;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { untrack } from 'svelte';
|
|
2
|
+
import { uiM } from '../../../messages.js';
|
|
3
|
+
import { authErrorMessage } from './auth-error-message.js';
|
|
4
|
+
/**
|
|
5
|
+
* 创建可跨业务复用的敏感动作确认状态,与 ReauthenticationDialog 配套。
|
|
6
|
+
* 密码不写入状态或存储;证明仅返回给 authorize 的对应调用者,不设置全局请求头。
|
|
7
|
+
* @param options - Kit/API client 的标准认证动作,或同签名自定义动作。
|
|
8
|
+
* @returns 页面级确认控制器;业务授权和凭据消费始终由服务端执行。
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { createSensitiveActions } from '@h-ai/ui'
|
|
12
|
+
* import { kit } from '@h-ai/kit'
|
|
13
|
+
* const confirmation = createSensitiveActions(kit.client.createAuthActions())
|
|
14
|
+
* confirmation.configure({ enabled: false, operations: [] })
|
|
15
|
+
* const ticket = await confirmation.authorize('orders.approve')
|
|
16
|
+
* // null 时中止;有 ticket 时仅传给这一笔请求。
|
|
17
|
+
* void ticket
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function createSensitiveActions(options) {
|
|
21
|
+
class Confirmation {
|
|
22
|
+
open = $state(false);
|
|
23
|
+
loading = $state(false);
|
|
24
|
+
error = $state('');
|
|
25
|
+
policy = { enabled: false, operations: [] };
|
|
26
|
+
operation = '';
|
|
27
|
+
generation = 0;
|
|
28
|
+
resolve;
|
|
29
|
+
configure(policy) {
|
|
30
|
+
this.policy = { enabled: policy.enabled, operations: [...policy.operations] };
|
|
31
|
+
// configure 通常从宿主 $effect 调用;不要把弹窗状态变成该 effect 的依赖。
|
|
32
|
+
untrack(() => {
|
|
33
|
+
if (this.open && (!policy.enabled || !policy.operations.includes(this.operation)))
|
|
34
|
+
this.cancel();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async authorize(operation) {
|
|
38
|
+
if (this.open)
|
|
39
|
+
return null;
|
|
40
|
+
if (this.policy.enabled && options.publicConfig) {
|
|
41
|
+
const current = await options.publicConfig();
|
|
42
|
+
if (!current.success || !current.data)
|
|
43
|
+
return null;
|
|
44
|
+
if (current.data.reauthentication)
|
|
45
|
+
this.configure(current.data.reauthentication);
|
|
46
|
+
}
|
|
47
|
+
if (!this.policy.enabled || !this.policy.operations.includes(operation))
|
|
48
|
+
return undefined;
|
|
49
|
+
if (this.open)
|
|
50
|
+
return null;
|
|
51
|
+
this.operation = operation;
|
|
52
|
+
this.generation++;
|
|
53
|
+
this.error = '';
|
|
54
|
+
this.open = true;
|
|
55
|
+
return new Promise((resolve) => {
|
|
56
|
+
this.resolve = resolve;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async submit(password) {
|
|
60
|
+
if (!this.open || this.loading)
|
|
61
|
+
return;
|
|
62
|
+
this.loading = true;
|
|
63
|
+
this.error = '';
|
|
64
|
+
const operation = this.operation;
|
|
65
|
+
const generation = this.generation;
|
|
66
|
+
const pending = this.resolve;
|
|
67
|
+
try {
|
|
68
|
+
const proof = await options.reauthenticate(password, operation);
|
|
69
|
+
if (generation !== this.generation)
|
|
70
|
+
return;
|
|
71
|
+
if (!proof.success) {
|
|
72
|
+
this.error = authErrorMessage(proof.error);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
this.resolve = undefined;
|
|
76
|
+
this.operation = '';
|
|
77
|
+
this.open = false;
|
|
78
|
+
pending?.(proof.data.ticket);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
if (generation === this.generation)
|
|
82
|
+
this.error = uiM('auth_network_error');
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
if (generation === this.generation)
|
|
86
|
+
this.loading = false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
cancel() {
|
|
90
|
+
this.generation++;
|
|
91
|
+
const resolve = this.resolve;
|
|
92
|
+
this.resolve = undefined;
|
|
93
|
+
this.operation = '';
|
|
94
|
+
this.open = false;
|
|
95
|
+
this.loading = false;
|
|
96
|
+
this.error = '';
|
|
97
|
+
resolve?.(null);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return new Confirmation();
|
|
101
|
+
}
|