@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
|
@@ -0,0 +1,1692 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component AiTableEditor
|
|
3
|
+
=============================================================================
|
|
4
|
+
@h-ai/ui - AiTableEditor 组件
|
|
5
|
+
=============================================================================
|
|
6
|
+
面向 AI 场景的可编辑表格查看器,支持:
|
|
7
|
+
- 从结构化数据或 JSON 文本渲染表格
|
|
8
|
+
- 流式残缺 JSON 的增量容错解析(列/行可分段出现)
|
|
9
|
+
- 单元格编辑、行新增、行删除、拖拽排序
|
|
10
|
+
- 复制表格(TSV)与下载表格(CSV)
|
|
11
|
+
|
|
12
|
+
使用 Svelte 5 Runes ($props, $state, $derived, $effect)
|
|
13
|
+
=============================================================================
|
|
14
|
+
|
|
15
|
+
@example
|
|
16
|
+
```ts
|
|
17
|
+
import { mount, unmount } from 'svelte'
|
|
18
|
+
import type { ComponentProps } from 'svelte'
|
|
19
|
+
import { AiTableEditor } from '@h-ai/ui'
|
|
20
|
+
const props: ComponentProps<typeof AiTableEditor> = { title: '销量', tableData: { table_columns: [{ key: 'sales', label: '销量', type: 'number' }], table_rows: [{ row_id: 'r1', sales: 42 }] } }
|
|
21
|
+
const component = mount(AiTableEditor, { target: document.body, props })
|
|
22
|
+
await unmount(component)
|
|
23
|
+
```
|
|
24
|
+
-->
|
|
25
|
+
<script lang='ts'>
|
|
26
|
+
import type { DataAttributes } from '../../../../types.js'
|
|
27
|
+
import type { MarkdownToolbarDownloadAction } from '../document-types.js'
|
|
28
|
+
import type {
|
|
29
|
+
AiTableColumn,
|
|
30
|
+
AiTableColumnType,
|
|
31
|
+
AiTableData,
|
|
32
|
+
AiTableDownloadPayload,
|
|
33
|
+
AiTableEditorChangePayload,
|
|
34
|
+
AiTableEditorProps,
|
|
35
|
+
} from './table-types.js'
|
|
36
|
+
import { SvelteSet } from 'svelte/reactivity'
|
|
37
|
+
import { writeTextToClipboard } from '../../../../internal/browser-safety.js'
|
|
38
|
+
import { uiM } from '../../../../messages.js'
|
|
39
|
+
import { cn, getDataAttributes } from '../../../../utils.js'
|
|
40
|
+
import AiDocumentDownloadMenu from '../AiDocumentDownloadMenu.svelte'
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 流式表格 JSON 中提取的数组片段;complete=false 时不能当作完整最终数据。
|
|
44
|
+
*
|
|
45
|
+
* @example 模块内部上下文
|
|
46
|
+
* ```ts
|
|
47
|
+
* const example: ExtractedArrayChunk = { source: '[{"row_id":"r1"}]', complete: true }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
interface ExtractedArrayChunk {
|
|
51
|
+
/** 从原始字符串里截取到的数组片段(可能是不完整数组)。 */
|
|
52
|
+
source: string
|
|
53
|
+
/** 是否已经拿到完整闭合的 `[...]`。 */
|
|
54
|
+
complete: boolean
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 拖放行相对目标行的插入方向。
|
|
59
|
+
*
|
|
60
|
+
* @example 模块内部上下文
|
|
61
|
+
* ```ts
|
|
62
|
+
* const example: AiTableRowDropPosition = 'before'
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
type AiTableRowDropPosition = 'before' | 'after'
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 表格拖放产生的新快照和前后索引;未变更时 nextData 为 null。
|
|
69
|
+
*
|
|
70
|
+
* @example 模块内部上下文
|
|
71
|
+
* ```ts
|
|
72
|
+
* const example: ReorderedTableResult = { nextData: { table_columns: [{ key: 'sales', label: '销量', type: 'number' }], table_rows: [{ row_id: 'r1', sales: 42 }] }, fromIndex: 1, toIndex: 0 }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
interface ReorderedTableResult {
|
|
76
|
+
/** 重排后的完整表格快照;未真正变更顺序时为 `null`。 */
|
|
77
|
+
nextData: AiTableData | null
|
|
78
|
+
/** 被拖动行原本所在的索引。 */
|
|
79
|
+
fromIndex: number
|
|
80
|
+
/** 被拖动行落位后的索引;无变化时与 `fromIndex` 相同。 */
|
|
81
|
+
toIndex: number
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 顶部复制按钮在“复制成功”态和默认态之间切换时复用内联 SVG,避免重复拼接 DOM 片段。
|
|
85
|
+
const COPY_ICON = `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 9a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2h-9a2 2 0 0 1-2-2v-9Zm2 0v9h9v-9h-9Z"></path><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1h-2V4H4v9h1v2Z"></path></svg>`
|
|
86
|
+
const CHECK_ICON = `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="m9.55 18.35-5.2-5.2 1.42-1.41 3.78 3.78 8.68-8.68 1.42 1.41-10.1 10.1Z"></path></svg>`
|
|
87
|
+
const CLOSE_ICON = `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M18.3 5.7 12 12l6.3 6.3-1.4 1.4L10.6 13.4 4.3 19.7l-1.4-1.4L9.2 12 2.9 5.7l1.4-1.4 6.3 6.3 6.3-6.3 1.4 1.4Z"></path></svg>`
|
|
88
|
+
const DELETE_ICON = `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6.72 6.72a.75.75 0 0 1 1.06 0L12 10.94l4.22-4.22a.75.75 0 1 1 1.06 1.06L13.06 12l4.22 4.22a.75.75 0 1 1-1.06 1.06L12 13.06l-4.22 4.22a.75.75 0 1 1-1.06-1.06L10.94 12 6.72 7.78a.75.75 0 0 1 0-1.06Z"></path></svg>`
|
|
89
|
+
const PLUS_ICON = `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M11 5h2v6h6v2h-6v6h-2v-6H5v-2h6V5Z"></path></svg>`
|
|
90
|
+
const DRAG_HANDLE_ICON = `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M8 5.75a1.25 1.25 0 1 1 0 2.5 1.25 1.25 0 0 1 0-2.5Zm0 5a1.25 1.25 0 1 1 0 2.5 1.25 1.25 0 0 1 0-2.5Zm0 5a1.25 1.25 0 1 1 0 2.5 1.25 1.25 0 0 1 0-2.5ZM16 5.75a1.25 1.25 0 1 1 0 2.5 1.25 1.25 0 0 1 0-2.5Zm0 5a1.25 1.25 0 1 1 0 2.5 1.25 1.25 0 0 1 0-2.5Zm0 5a1.25 1.25 0 1 1 0 2.5 1.25 1.25 0 0 1 0-2.5Z"></path></svg>`
|
|
91
|
+
const TABLE_DOWNLOAD_ACTION_ID = 'table-csv'
|
|
92
|
+
// 文件名过滤正则,避免下载时包含平台不兼容字符。
|
|
93
|
+
const INVALID_FILENAME_CHARS_REGEX = /[<>:"/\\|?*]+/g
|
|
94
|
+
// 单元格值中的双引号需要按 CSV 规范转义为两个双引号。
|
|
95
|
+
const CSV_DOUBLE_QUOTE_REGEX = /"/g
|
|
96
|
+
const CANONICAL_TABLE_CONTENT_HINTS = ['table/v1', '"columns"', '"rows"'] as const
|
|
97
|
+
const EDITOR_TABLE_CONTENT_HINTS = ['"table_columns"', '"table_rows"'] as const
|
|
98
|
+
// 单元格输入对外回调统一防抖 2 秒,避免父层每次敲字都触发保存链路。
|
|
99
|
+
const TABLE_CELL_CHANGE_DEBOUNCE_MS = 2000
|
|
100
|
+
|
|
101
|
+
let {
|
|
102
|
+
// 暴露给外层的滚动容器引用,用于流式自动滚动。
|
|
103
|
+
editorScrollHost = $bindable<HTMLDivElement | null>(null),
|
|
104
|
+
// 原始表格内容,通常是 JSON 字符串,可能是流式中间态。
|
|
105
|
+
content = '',
|
|
106
|
+
// 结构化表格数据;存在时优先用于渲染和编辑。
|
|
107
|
+
tableData,
|
|
108
|
+
// 头部标题。
|
|
109
|
+
title = '',
|
|
110
|
+
// 外层自定义类名。
|
|
111
|
+
class: className = '',
|
|
112
|
+
// 头部状态文案。
|
|
113
|
+
statusText = '',
|
|
114
|
+
// 头部辅助文案。
|
|
115
|
+
metaText = '',
|
|
116
|
+
// 头部保存状态文案。
|
|
117
|
+
saveState = '',
|
|
118
|
+
// 是否允许编辑表格。
|
|
119
|
+
editable = true,
|
|
120
|
+
// 关闭按钮是否禁用。
|
|
121
|
+
closeDisabled = false,
|
|
122
|
+
// 关闭回调。
|
|
123
|
+
onclose,
|
|
124
|
+
// 表格编辑回调。
|
|
125
|
+
ontablechange,
|
|
126
|
+
// 表格滚动回调。
|
|
127
|
+
ondocumentscroll,
|
|
128
|
+
// 表格复制回调。
|
|
129
|
+
oncopytable,
|
|
130
|
+
// 表格下载回调。
|
|
131
|
+
ondownloadtable,
|
|
132
|
+
...restProps
|
|
133
|
+
}: AiTableEditorProps & DataAttributes = $props()
|
|
134
|
+
|
|
135
|
+
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
136
|
+
// 复制反馈只影响右上角复制按钮,不和业务数据混用。
|
|
137
|
+
let copied = $state(false)
|
|
138
|
+
// 连续复制时按最后一次点击重新计时。
|
|
139
|
+
let copyFeedbackTimer: number | undefined = $state()
|
|
140
|
+
// draggingRowId 只在原生拖拽生命周期内存在,用来确定当前正在移动哪一行。
|
|
141
|
+
let draggingRowId = $state<string | null>(null)
|
|
142
|
+
// dragTargetRowId 记录当前悬停的参考行,配合插入方向绘制拖拽指示线。
|
|
143
|
+
let dragTargetRowId = $state<string | null>(null)
|
|
144
|
+
// dragTargetPosition 标识应插入到参考行前面还是后面。
|
|
145
|
+
let dragTargetPosition = $state<AiTableRowDropPosition | null>(null)
|
|
146
|
+
// 本地表格草稿让输入中的单元格先在组件内即时生效,再按防抖节奏同步给外层。
|
|
147
|
+
let localDraftTableData = $state<AiTableData | null>(null)
|
|
148
|
+
// pendingCellChangePayload 保存尚未对外发出的最后一次单元格修改。
|
|
149
|
+
let pendingCellChangePayload = $state<AiTableEditorChangePayload | null>(null)
|
|
150
|
+
// 单元格修改回调的防抖计时器。
|
|
151
|
+
let cellChangeTimer: number | undefined = $state()
|
|
152
|
+
// 用上一版入参快照判断当前是“父层追平本地草稿”还是“切到了另一份表格”。
|
|
153
|
+
let lastIncomingTableSignature = $state('')
|
|
154
|
+
|
|
155
|
+
// 当上层没传结构化表格时,尝试从 `content` 里做容错解析。
|
|
156
|
+
const parsedTableData = $derived(parseTableDataFromSource(content))
|
|
157
|
+
// 输入源统一先归一化,方便后续比较父层快照与本地草稿是否已对齐。
|
|
158
|
+
const sourceTableData = $derived(
|
|
159
|
+
normalizeTableData(
|
|
160
|
+
tableData ?? parsedTableData ?? {
|
|
161
|
+
table_columns: [],
|
|
162
|
+
table_rows: [],
|
|
163
|
+
},
|
|
164
|
+
),
|
|
165
|
+
)
|
|
166
|
+
// 渲染时优先展示本地草稿;父层追平后再回退到受控值。
|
|
167
|
+
const resolvedTableData = $derived(localDraftTableData ?? sourceTableData)
|
|
168
|
+
// 表格列定义,保持单独派生避免模板重复读取深层对象。
|
|
169
|
+
const tableColumns = $derived(resolvedTableData.table_columns)
|
|
170
|
+
// 表格行定义,保持单独派生避免模板重复读取深层对象。
|
|
171
|
+
const tableRows = $derived(resolvedTableData.table_rows)
|
|
172
|
+
// 表格主体容器类名,避免样式拼接散落在模板中。
|
|
173
|
+
const tablePaneClass = $derived(cn('hai-ai-table-pane', className))
|
|
174
|
+
|
|
175
|
+
$effect(() => {
|
|
176
|
+
return () => {
|
|
177
|
+
clearScheduledCellChange()
|
|
178
|
+
if (copyFeedbackTimer) {
|
|
179
|
+
window.clearTimeout(copyFeedbackTimer)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
$effect(() => {
|
|
185
|
+
const incomingSignature = serializeTableDataForComparison(sourceTableData)
|
|
186
|
+
const previousIncomingSignature = lastIncomingTableSignature
|
|
187
|
+
lastIncomingTableSignature = incomingSignature
|
|
188
|
+
|
|
189
|
+
if (!localDraftTableData) {
|
|
190
|
+
return
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const localSignature = serializeTableDataForComparison(localDraftTableData)
|
|
194
|
+
if (incomingSignature === localSignature) {
|
|
195
|
+
localDraftTableData = null
|
|
196
|
+
pendingCellChangePayload = null
|
|
197
|
+
clearScheduledCellChange()
|
|
198
|
+
return
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// 父层切到了另一份表格时,本地未提交的输入不能继续覆盖新表格。
|
|
202
|
+
if (previousIncomingSignature && incomingSignature !== previousIncomingSignature) {
|
|
203
|
+
localDraftTableData = null
|
|
204
|
+
pendingCellChangePayload = null
|
|
205
|
+
clearScheduledCellChange()
|
|
206
|
+
}
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
$effect(() => {
|
|
210
|
+
const currentTableRows = tableRows
|
|
211
|
+
|
|
212
|
+
if (!editable || currentTableRows.length < 2) {
|
|
213
|
+
resetRowDragState()
|
|
214
|
+
return
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (draggingRowId && !currentTableRows.some(row => row.row_id === draggingRowId)) {
|
|
218
|
+
resetRowDragState()
|
|
219
|
+
return
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (dragTargetRowId && !currentTableRows.some(row => row.row_id === dragTargetRowId)) {
|
|
223
|
+
dragTargetRowId = null
|
|
224
|
+
dragTargetPosition = null
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
229
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function normalizeColumnType(value: unknown): AiTableColumnType {
|
|
233
|
+
return value === 'number' || value === 'tag' ? value : 'text'
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function serializeTableDataForComparison(
|
|
237
|
+
data: AiTableData | null | undefined,
|
|
238
|
+
): string {
|
|
239
|
+
if (!data) {
|
|
240
|
+
return ''
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
try {
|
|
244
|
+
return JSON.stringify(data)
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
return ''
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* 列定义归一化:
|
|
253
|
+
* - 过滤非对象项和空 key
|
|
254
|
+
* - 自动填充 label/type 缺省值
|
|
255
|
+
* - 基于 `key` 去重,避免流式增量里重复列导致渲染抖动
|
|
256
|
+
*/
|
|
257
|
+
function normalizeTableColumns(items: unknown[]): AiTableColumn[] {
|
|
258
|
+
const usedKeys = new SvelteSet<string>()
|
|
259
|
+
const columns: AiTableColumn[] = []
|
|
260
|
+
|
|
261
|
+
for (const item of items) {
|
|
262
|
+
if (!isRecord(item)) {
|
|
263
|
+
continue
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const key = typeof item.key === 'string' && item.key.trim()
|
|
267
|
+
? item.key.trim()
|
|
268
|
+
: (typeof item.name === 'string' ? item.name.trim() : '')
|
|
269
|
+
if (!key || usedKeys.has(key)) {
|
|
270
|
+
continue
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const label = typeof item.label === 'string' && item.label.trim()
|
|
274
|
+
? item.label.trim()
|
|
275
|
+
: (typeof item.name === 'string' && item.name.trim()
|
|
276
|
+
? item.name.trim()
|
|
277
|
+
: key)
|
|
278
|
+
|
|
279
|
+
columns.push({
|
|
280
|
+
key,
|
|
281
|
+
label,
|
|
282
|
+
type: normalizeColumnType(item.type),
|
|
283
|
+
})
|
|
284
|
+
usedKeys.add(key)
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return columns
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* 行定义归一化:
|
|
292
|
+
* - 过滤非对象项
|
|
293
|
+
* - 兜底生成 row_id,保证模板 key 稳定
|
|
294
|
+
*/
|
|
295
|
+
function normalizeTableRows(items: unknown[]): AiTableData['table_rows'] {
|
|
296
|
+
const rows: AiTableData['table_rows'] = []
|
|
297
|
+
|
|
298
|
+
for (const [index, item] of items.entries()) {
|
|
299
|
+
if (!isRecord(item)) {
|
|
300
|
+
continue
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const rowId = typeof item.row_id === 'string' && item.row_id.trim()
|
|
304
|
+
? item.row_id.trim()
|
|
305
|
+
: `row_${index + 1}`
|
|
306
|
+
|
|
307
|
+
rows.push({
|
|
308
|
+
...item,
|
|
309
|
+
row_id: rowId,
|
|
310
|
+
})
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return rows
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* 表格对象统一归一,避免模板层处理结构健壮性。
|
|
318
|
+
*/
|
|
319
|
+
function normalizeTableData(data: AiTableData): AiTableData {
|
|
320
|
+
return {
|
|
321
|
+
table_columns: normalizeTableColumns(data.table_columns),
|
|
322
|
+
table_rows: normalizeTableRows(data.table_rows),
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function tryParseJson(value: string): unknown {
|
|
327
|
+
try {
|
|
328
|
+
return JSON.parse(value)
|
|
329
|
+
}
|
|
330
|
+
catch {
|
|
331
|
+
return undefined
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* 从 JSON 字符串中提取指定 key 的数组片段。
|
|
337
|
+
* 该函数支持“流式未闭合数组”场景:拿不到 `]` 时也会返回已截取片段并标记 `complete=false`。
|
|
338
|
+
*/
|
|
339
|
+
function extractArrayChunkByKey(
|
|
340
|
+
source: string,
|
|
341
|
+
key: 'columns' | 'rows' | 'table_columns' | 'table_rows',
|
|
342
|
+
): ExtractedArrayChunk | null {
|
|
343
|
+
const keyIndex = source.indexOf(`"${key}"`)
|
|
344
|
+
if (keyIndex < 0) {
|
|
345
|
+
return null
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const arrayStart = source.indexOf('[', keyIndex)
|
|
349
|
+
if (arrayStart < 0) {
|
|
350
|
+
return null
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
let depth = 0
|
|
354
|
+
let escaped = false
|
|
355
|
+
let inString = false
|
|
356
|
+
|
|
357
|
+
for (let index = arrayStart; index < source.length; index += 1) {
|
|
358
|
+
const char = source[index]
|
|
359
|
+
|
|
360
|
+
if (inString) {
|
|
361
|
+
if (escaped) {
|
|
362
|
+
escaped = false
|
|
363
|
+
continue
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (char === '\\') {
|
|
367
|
+
escaped = true
|
|
368
|
+
continue
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
if (char === '"') {
|
|
372
|
+
inString = false
|
|
373
|
+
}
|
|
374
|
+
continue
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (char === '"') {
|
|
378
|
+
inString = true
|
|
379
|
+
continue
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (char === '[') {
|
|
383
|
+
depth += 1
|
|
384
|
+
continue
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (char === ']') {
|
|
388
|
+
depth -= 1
|
|
389
|
+
if (depth === 0) {
|
|
390
|
+
return {
|
|
391
|
+
source: source.slice(arrayStart, index + 1),
|
|
392
|
+
complete: true,
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
return {
|
|
399
|
+
source: source.slice(arrayStart),
|
|
400
|
+
complete: false,
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* 当数组尚未闭合时,从片段中逐个提取已闭合对象。
|
|
406
|
+
* 这样能保证“行一条条流出来”时,已完成的行可以先展示。
|
|
407
|
+
*/
|
|
408
|
+
function parseObjectListFromArrayChunk(
|
|
409
|
+
source: string,
|
|
410
|
+
): Array<Record<string, unknown>> {
|
|
411
|
+
const objects: Array<Record<string, unknown>> = []
|
|
412
|
+
let objectDepth = 0
|
|
413
|
+
let objectStart = -1
|
|
414
|
+
let escaped = false
|
|
415
|
+
let inString = false
|
|
416
|
+
|
|
417
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
418
|
+
const char = source[index]
|
|
419
|
+
|
|
420
|
+
if (inString) {
|
|
421
|
+
if (escaped) {
|
|
422
|
+
escaped = false
|
|
423
|
+
continue
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (char === '\\') {
|
|
427
|
+
escaped = true
|
|
428
|
+
continue
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if (char === '"') {
|
|
432
|
+
inString = false
|
|
433
|
+
}
|
|
434
|
+
continue
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
if (char === '"') {
|
|
438
|
+
inString = true
|
|
439
|
+
continue
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
if (char === '{') {
|
|
443
|
+
if (objectDepth === 0) {
|
|
444
|
+
objectStart = index
|
|
445
|
+
}
|
|
446
|
+
objectDepth += 1
|
|
447
|
+
continue
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if (char === '}') {
|
|
451
|
+
objectDepth -= 1
|
|
452
|
+
if (objectDepth === 0 && objectStart >= 0) {
|
|
453
|
+
const chunk = source.slice(objectStart, index + 1)
|
|
454
|
+
const parsed = tryParseJson(chunk)
|
|
455
|
+
if (isRecord(parsed)) {
|
|
456
|
+
objects.push(parsed)
|
|
457
|
+
}
|
|
458
|
+
objectStart = -1
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return objects
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function parseTableColumnsFromChunk(
|
|
467
|
+
chunk: ExtractedArrayChunk,
|
|
468
|
+
): AiTableColumn[] {
|
|
469
|
+
if (chunk.complete) {
|
|
470
|
+
const parsed = tryParseJson(chunk.source)
|
|
471
|
+
if (Array.isArray(parsed)) {
|
|
472
|
+
return normalizeTableColumns(parsed)
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
return normalizeTableColumns(parseObjectListFromArrayChunk(chunk.source))
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function parseTableRowsFromChunk(
|
|
480
|
+
chunk: ExtractedArrayChunk,
|
|
481
|
+
): AiTableData['table_rows'] {
|
|
482
|
+
if (chunk.complete) {
|
|
483
|
+
const parsed = tryParseJson(chunk.source)
|
|
484
|
+
if (Array.isArray(parsed)) {
|
|
485
|
+
return normalizeTableRows(parsed)
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
return normalizeTableRows(parseObjectListFromArrayChunk(chunk.source))
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* 容错解析表格数据:
|
|
494
|
+
* 1. 优先尝试完整 JSON;
|
|
495
|
+
* 2. 失败后按 key 提取数组片段,支持流式中间态;
|
|
496
|
+
* 3. 仅当列和行都无法解析时返回 `null`。
|
|
497
|
+
*/
|
|
498
|
+
function parseTableDataFromSource(source: string): AiTableData | null {
|
|
499
|
+
const trimmed = source.trim()
|
|
500
|
+
if (!trimmed) {
|
|
501
|
+
return null
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
const matchesCanonicalContent = CANONICAL_TABLE_CONTENT_HINTS.some(
|
|
505
|
+
marker => trimmed.includes(marker),
|
|
506
|
+
)
|
|
507
|
+
const matchesEditorContent = EDITOR_TABLE_CONTENT_HINTS.some(
|
|
508
|
+
marker => trimmed.includes(marker),
|
|
509
|
+
)
|
|
510
|
+
if (!matchesCanonicalContent && !matchesEditorContent) {
|
|
511
|
+
return null
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
const parsedWhole = tryParseJson(trimmed)
|
|
515
|
+
if (isRecord(parsedWhole)) {
|
|
516
|
+
const columns = Array.isArray(parsedWhole.table_columns)
|
|
517
|
+
? normalizeTableColumns(parsedWhole.table_columns)
|
|
518
|
+
: (Array.isArray(parsedWhole.columns) ? normalizeTableColumns(parsedWhole.columns) : [])
|
|
519
|
+
const rows = Array.isArray(parsedWhole.table_rows)
|
|
520
|
+
? normalizeTableRows(parsedWhole.table_rows)
|
|
521
|
+
: (Array.isArray(parsedWhole.rows) ? normalizeTableRows(parsedWhole.rows) : [])
|
|
522
|
+
|
|
523
|
+
if (columns.length > 0 || rows.length > 0) {
|
|
524
|
+
return {
|
|
525
|
+
table_columns: columns,
|
|
526
|
+
table_rows: rows,
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
const columnsChunk = extractArrayChunkByKey(
|
|
532
|
+
trimmed,
|
|
533
|
+
matchesEditorContent ? 'table_columns' : 'columns',
|
|
534
|
+
)
|
|
535
|
+
const rowsChunk = extractArrayChunkByKey(
|
|
536
|
+
trimmed,
|
|
537
|
+
matchesEditorContent ? 'table_rows' : 'rows',
|
|
538
|
+
)
|
|
539
|
+
if (!columnsChunk && !rowsChunk) {
|
|
540
|
+
return null
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
const columns = columnsChunk ? parseTableColumnsFromChunk(columnsChunk) : []
|
|
544
|
+
const rows = rowsChunk ? parseTableRowsFromChunk(rowsChunk) : []
|
|
545
|
+
if (columns.length === 0 && rows.length === 0) {
|
|
546
|
+
return null
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
return {
|
|
550
|
+
table_columns: columns,
|
|
551
|
+
table_rows: rows,
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
function getCellValue(row: AiTableData['table_rows'][number], key: string): string {
|
|
556
|
+
const value = row[key]
|
|
557
|
+
if (typeof value === 'number') {
|
|
558
|
+
return `${value}`
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
if (typeof value === 'string') {
|
|
562
|
+
return value
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
if (typeof value === 'boolean') {
|
|
566
|
+
return `${value}`
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
if (value === null || value === undefined) {
|
|
570
|
+
return ''
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
try {
|
|
574
|
+
return JSON.stringify(value)
|
|
575
|
+
}
|
|
576
|
+
catch {
|
|
577
|
+
return ''
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
function getCellInputValue(row: AiTableData['table_rows'][number], key: string): string {
|
|
582
|
+
return getCellValue(row, key)
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
function getCellExportValue(row: AiTableData['table_rows'][number], key: string): string {
|
|
586
|
+
return getCellValue(row, key)
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
function createGeneratedRowId(): string {
|
|
590
|
+
return `row_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
function buildNextTableDataWithCellUpdate(
|
|
594
|
+
data: AiTableData,
|
|
595
|
+
rowId: string,
|
|
596
|
+
columnKey: string,
|
|
597
|
+
value: string,
|
|
598
|
+
): AiTableData {
|
|
599
|
+
return {
|
|
600
|
+
table_columns: data.table_columns,
|
|
601
|
+
table_rows: data.table_rows.map((row) => {
|
|
602
|
+
if (row.row_id !== rowId) {
|
|
603
|
+
return row
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
return {
|
|
607
|
+
...row,
|
|
608
|
+
[columnKey]: value,
|
|
609
|
+
}
|
|
610
|
+
}),
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function buildNextTableDataWithRowAdd(data: AiTableData): AiTableData {
|
|
615
|
+
const newRow: AiTableData['table_rows'][number] = {
|
|
616
|
+
row_id: createGeneratedRowId(),
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
for (const column of data.table_columns) {
|
|
620
|
+
newRow[column.key] = ''
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
return {
|
|
624
|
+
table_columns: data.table_columns,
|
|
625
|
+
table_rows: [...data.table_rows, newRow],
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
function buildNextTableDataWithRowDelete(
|
|
630
|
+
data: AiTableData,
|
|
631
|
+
rowId: string,
|
|
632
|
+
): AiTableData {
|
|
633
|
+
return {
|
|
634
|
+
table_columns: data.table_columns,
|
|
635
|
+
table_rows: data.table_rows.filter(row => row.row_id !== rowId),
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* 行重排时先把拖动行临时移出数组,再按悬停位置重新插回。
|
|
641
|
+
* 这样可以统一处理“向上拖”和“向下拖”,避免索引在删除后发生偏移。
|
|
642
|
+
*/
|
|
643
|
+
function buildNextTableDataWithRowReorder(
|
|
644
|
+
data: AiTableData,
|
|
645
|
+
rowId: string,
|
|
646
|
+
targetRowId: string,
|
|
647
|
+
position: AiTableRowDropPosition,
|
|
648
|
+
): ReorderedTableResult {
|
|
649
|
+
const fromIndex = data.table_rows.findIndex(row => row.row_id === rowId)
|
|
650
|
+
const targetIndex = data.table_rows.findIndex(row => row.row_id === targetRowId)
|
|
651
|
+
|
|
652
|
+
if (fromIndex < 0 || targetIndex < 0 || fromIndex === targetIndex) {
|
|
653
|
+
return {
|
|
654
|
+
nextData: null,
|
|
655
|
+
fromIndex,
|
|
656
|
+
toIndex: fromIndex,
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
const nextRows = [...data.table_rows]
|
|
661
|
+
const [movedRow] = nextRows.splice(fromIndex, 1)
|
|
662
|
+
if (!movedRow) {
|
|
663
|
+
return {
|
|
664
|
+
nextData: null,
|
|
665
|
+
fromIndex,
|
|
666
|
+
toIndex: fromIndex,
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
const targetIndexAfterRemoval = nextRows.findIndex(row => row.row_id === targetRowId)
|
|
671
|
+
if (targetIndexAfterRemoval < 0) {
|
|
672
|
+
return {
|
|
673
|
+
nextData: null,
|
|
674
|
+
fromIndex,
|
|
675
|
+
toIndex: fromIndex,
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
const insertionIndex = position === 'before'
|
|
680
|
+
? targetIndexAfterRemoval
|
|
681
|
+
: targetIndexAfterRemoval + 1
|
|
682
|
+
|
|
683
|
+
nextRows.splice(insertionIndex, 0, movedRow)
|
|
684
|
+
const toIndex = nextRows.findIndex(row => row.row_id === rowId)
|
|
685
|
+
if (toIndex === fromIndex) {
|
|
686
|
+
return {
|
|
687
|
+
nextData: null,
|
|
688
|
+
fromIndex,
|
|
689
|
+
toIndex,
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
return {
|
|
694
|
+
nextData: {
|
|
695
|
+
table_columns: data.table_columns,
|
|
696
|
+
table_rows: nextRows,
|
|
697
|
+
},
|
|
698
|
+
fromIndex,
|
|
699
|
+
toIndex,
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
function clearScheduledCellChange(): void {
|
|
704
|
+
if (typeof window === 'undefined' || !cellChangeTimer) {
|
|
705
|
+
return
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
window.clearTimeout(cellChangeTimer)
|
|
709
|
+
cellChangeTimer = undefined
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
function emitTableChange(payload: AiTableEditorChangePayload): void {
|
|
713
|
+
void ontablechange?.(payload)
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
function discardPendingCellChange(): void {
|
|
717
|
+
pendingCellChangePayload = null
|
|
718
|
+
clearScheduledCellChange()
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* 立即交付尚在防抖窗口中的单元格修改,关闭或保存前可通过组件引用调用。
|
|
723
|
+
* @returns 无返回值;立即交付最后一份待发送的单元格修改。
|
|
724
|
+
*
|
|
725
|
+
* @example
|
|
726
|
+
* ```ts
|
|
727
|
+
* import { mount, unmount } from 'svelte'
|
|
728
|
+
* import { AiTableEditor } from '@h-ai/ui'
|
|
729
|
+
* const editor = mount(AiTableEditor, { target: document.body, props: { tableData: { table_columns: [{ key: 'sales', label: '销量', type: 'number' }], table_rows: [{ row_id: 'r1', sales: 42 }] } } })
|
|
730
|
+
* editor.flushPendingTableChange()
|
|
731
|
+
* await unmount(editor)
|
|
732
|
+
* ```
|
|
733
|
+
*/
|
|
734
|
+
export function flushPendingTableChange(): void {
|
|
735
|
+
const pendingPayload = pendingCellChangePayload
|
|
736
|
+
if (!pendingPayload) {
|
|
737
|
+
return
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
discardPendingCellChange()
|
|
741
|
+
emitTableChange(pendingPayload)
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
function queueCellChange(payload: AiTableEditorChangePayload): void {
|
|
745
|
+
localDraftTableData = payload.nextData
|
|
746
|
+
pendingCellChangePayload = payload
|
|
747
|
+
|
|
748
|
+
if (!ontablechange) {
|
|
749
|
+
clearScheduledCellChange()
|
|
750
|
+
return
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
if (typeof window === 'undefined') {
|
|
754
|
+
flushPendingTableChange()
|
|
755
|
+
return
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
clearScheduledCellChange()
|
|
759
|
+
cellChangeTimer = window.setTimeout(() => {
|
|
760
|
+
cellChangeTimer = undefined
|
|
761
|
+
flushPendingTableChange()
|
|
762
|
+
}, TABLE_CELL_CHANGE_DEBOUNCE_MS)
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
function emitImmediateTableChange(payload: AiTableEditorChangePayload): void {
|
|
766
|
+
localDraftTableData = payload.nextData
|
|
767
|
+
discardPendingCellChange()
|
|
768
|
+
emitTableChange(payload)
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
function resetRowDragState(): void {
|
|
772
|
+
draggingRowId = null
|
|
773
|
+
dragTargetRowId = null
|
|
774
|
+
dragTargetPosition = null
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
function resolveRowDropPosition(event: DragEvent): AiTableRowDropPosition | null {
|
|
778
|
+
const currentTarget = event.currentTarget
|
|
779
|
+
if (!(currentTarget instanceof HTMLTableRowElement)) {
|
|
780
|
+
return null
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
const rowBounds = currentTarget.getBoundingClientRect()
|
|
784
|
+
return event.clientY < rowBounds.top + rowBounds.height / 2 ? 'before' : 'after'
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
function updateRowDropHint(rowId: string, event: DragEvent): void {
|
|
788
|
+
if (!draggingRowId || draggingRowId === rowId) {
|
|
789
|
+
dragTargetRowId = null
|
|
790
|
+
dragTargetPosition = null
|
|
791
|
+
return
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
const position = resolveRowDropPosition(event)
|
|
795
|
+
if (!position) {
|
|
796
|
+
return
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
dragTargetRowId = rowId
|
|
800
|
+
dragTargetPosition = position
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
function handleCellInput(
|
|
804
|
+
rowId: string,
|
|
805
|
+
column: AiTableColumn,
|
|
806
|
+
event: Event,
|
|
807
|
+
): void {
|
|
808
|
+
const target = event.currentTarget
|
|
809
|
+
if (!(target instanceof HTMLInputElement)) {
|
|
810
|
+
return
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
const value = target.value
|
|
814
|
+
const nextData = buildNextTableDataWithCellUpdate(
|
|
815
|
+
resolvedTableData,
|
|
816
|
+
rowId,
|
|
817
|
+
column.key,
|
|
818
|
+
value,
|
|
819
|
+
)
|
|
820
|
+
|
|
821
|
+
queueCellChange({
|
|
822
|
+
action: 'cell-update',
|
|
823
|
+
rowId,
|
|
824
|
+
columnKey: column.key,
|
|
825
|
+
value,
|
|
826
|
+
nextData,
|
|
827
|
+
})
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
function handleAddRow(): void {
|
|
831
|
+
const nextData = buildNextTableDataWithRowAdd(resolvedTableData)
|
|
832
|
+
const rowId = nextData.table_rows.at(-1)?.row_id
|
|
833
|
+
|
|
834
|
+
emitImmediateTableChange({
|
|
835
|
+
action: 'row-add',
|
|
836
|
+
rowId,
|
|
837
|
+
nextData,
|
|
838
|
+
})
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
function handleDeleteRow(rowId: string): void {
|
|
842
|
+
const nextData = buildNextTableDataWithRowDelete(resolvedTableData, rowId)
|
|
843
|
+
|
|
844
|
+
emitImmediateTableChange({
|
|
845
|
+
action: 'row-delete',
|
|
846
|
+
rowId,
|
|
847
|
+
nextData,
|
|
848
|
+
})
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
function handleRowDragStart(rowId: string, event: DragEvent): void {
|
|
852
|
+
if (!editable || tableRows.length < 2) {
|
|
853
|
+
event.preventDefault()
|
|
854
|
+
return
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
draggingRowId = rowId
|
|
858
|
+
dragTargetRowId = null
|
|
859
|
+
dragTargetPosition = null
|
|
860
|
+
|
|
861
|
+
if (event.dataTransfer) {
|
|
862
|
+
event.dataTransfer.effectAllowed = 'move'
|
|
863
|
+
// Firefox 需要至少写入一份文本数据,拖拽事件链才能正常继续。
|
|
864
|
+
event.dataTransfer.setData('text/plain', rowId)
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
function handleRowDragOver(rowId: string, event: DragEvent): void {
|
|
869
|
+
if (!draggingRowId) {
|
|
870
|
+
return
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
event.preventDefault()
|
|
874
|
+
updateRowDropHint(rowId, event)
|
|
875
|
+
|
|
876
|
+
if (event.dataTransfer) {
|
|
877
|
+
event.dataTransfer.dropEffect = 'move'
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
function handleRowDrop(rowId: string, event: DragEvent): void {
|
|
882
|
+
if (!draggingRowId) {
|
|
883
|
+
return
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
event.preventDefault()
|
|
887
|
+
const position = resolveRowDropPosition(event)
|
|
888
|
+
if (!position) {
|
|
889
|
+
resetRowDragState()
|
|
890
|
+
return
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
const draggedRowId = draggingRowId
|
|
894
|
+
const result = buildNextTableDataWithRowReorder(
|
|
895
|
+
resolvedTableData,
|
|
896
|
+
draggedRowId,
|
|
897
|
+
rowId,
|
|
898
|
+
position,
|
|
899
|
+
)
|
|
900
|
+
|
|
901
|
+
resetRowDragState()
|
|
902
|
+
if (!result.nextData) {
|
|
903
|
+
return
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
emitImmediateTableChange({
|
|
907
|
+
action: 'row-reorder',
|
|
908
|
+
rowId: draggedRowId,
|
|
909
|
+
targetRowId: rowId,
|
|
910
|
+
fromIndex: result.fromIndex,
|
|
911
|
+
toIndex: result.toIndex,
|
|
912
|
+
nextData: result.nextData,
|
|
913
|
+
})
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
function isDropIndicatorVisible(
|
|
917
|
+
rowId: string,
|
|
918
|
+
position: AiTableRowDropPosition,
|
|
919
|
+
): boolean {
|
|
920
|
+
return dragTargetRowId === rowId && dragTargetPosition === position
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
function serializeTableAsTsv(data: AiTableData): string {
|
|
924
|
+
const header = data.table_columns.map(column => column.label).join('\t')
|
|
925
|
+
const body = data.table_rows.map((row) => {
|
|
926
|
+
return data.table_columns
|
|
927
|
+
.map(column => getCellExportValue(row, column.key).replace(/\t/g, ' '))
|
|
928
|
+
.join('\t')
|
|
929
|
+
})
|
|
930
|
+
|
|
931
|
+
return [header, ...body].filter(Boolean).join('\n')
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
function escapeCsvCell(value: string): string {
|
|
935
|
+
return `"${value.replace(CSV_DOUBLE_QUOTE_REGEX, '""')}"`
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
function serializeTableAsCsv(data: AiTableData): string {
|
|
939
|
+
const header = data.table_columns
|
|
940
|
+
.map(column => escapeCsvCell(column.label))
|
|
941
|
+
.join(',')
|
|
942
|
+
|
|
943
|
+
const body = data.table_rows.map((row) => {
|
|
944
|
+
return data.table_columns
|
|
945
|
+
.map(column => escapeCsvCell(getCellExportValue(row, column.key)))
|
|
946
|
+
.join(',')
|
|
947
|
+
})
|
|
948
|
+
|
|
949
|
+
return [header, ...body].filter(Boolean).join('\n')
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
function sanitizeFilename(value: string): string {
|
|
953
|
+
const normalized = value
|
|
954
|
+
.trim()
|
|
955
|
+
.replace(INVALID_FILENAME_CHARS_REGEX, ' ')
|
|
956
|
+
.replace(/\s+/g, ' ')
|
|
957
|
+
.replace(/[. ]+$/g, '')
|
|
958
|
+
.trim()
|
|
959
|
+
|
|
960
|
+
return normalized || 'ai-table'
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
function resolveDownloadFilename(): string {
|
|
964
|
+
return `${sanitizeFilename(title || 'ai-table')}.csv`
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
function resolveTableDownloadActions(): MarkdownToolbarDownloadAction[] {
|
|
968
|
+
return [
|
|
969
|
+
{
|
|
970
|
+
id: TABLE_DOWNLOAD_ACTION_ID,
|
|
971
|
+
label: uiM('table_download'),
|
|
972
|
+
badgeLabel: 'CSV',
|
|
973
|
+
},
|
|
974
|
+
]
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
function triggerCopiedFeedback(): void {
|
|
978
|
+
copied = true
|
|
979
|
+
if (copyFeedbackTimer) {
|
|
980
|
+
window.clearTimeout(copyFeedbackTimer)
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
copyFeedbackTimer = window.setTimeout(() => {
|
|
984
|
+
copied = false
|
|
985
|
+
copyFeedbackTimer = undefined
|
|
986
|
+
}, 1800)
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
function downloadBlob(content: string, filename: string): void {
|
|
990
|
+
if (typeof document === 'undefined') {
|
|
991
|
+
return
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
const blob = new Blob([content], { type: 'text/csv;charset=utf-8' })
|
|
995
|
+
const url = URL.createObjectURL(blob)
|
|
996
|
+
const anchor = document.createElement('a')
|
|
997
|
+
anchor.href = url
|
|
998
|
+
anchor.download = filename
|
|
999
|
+
anchor.rel = 'noopener'
|
|
1000
|
+
anchor.click()
|
|
1001
|
+
window.setTimeout(() => {
|
|
1002
|
+
URL.revokeObjectURL(url)
|
|
1003
|
+
}, 1000)
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
async function handleCopyTable(): Promise<void> {
|
|
1007
|
+
const text = serializeTableAsTsv(resolvedTableData)
|
|
1008
|
+
if (!text) {
|
|
1009
|
+
return
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
if (oncopytable) {
|
|
1013
|
+
await oncopytable({
|
|
1014
|
+
data: resolvedTableData,
|
|
1015
|
+
text,
|
|
1016
|
+
})
|
|
1017
|
+
triggerCopiedFeedback()
|
|
1018
|
+
return
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
if (await writeTextToClipboard(text)) {
|
|
1022
|
+
triggerCopiedFeedback()
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
async function handleDownloadTable(): Promise<void> {
|
|
1027
|
+
const csv = serializeTableAsCsv(resolvedTableData)
|
|
1028
|
+
if (!csv) {
|
|
1029
|
+
return
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
const filename = resolveDownloadFilename()
|
|
1033
|
+
const payload: AiTableDownloadPayload = {
|
|
1034
|
+
data: resolvedTableData,
|
|
1035
|
+
csv,
|
|
1036
|
+
filename,
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
if (ondownloadtable) {
|
|
1040
|
+
await ondownloadtable(payload)
|
|
1041
|
+
return
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
downloadBlob(csv, filename)
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
async function handleDownloadAction(actionId: string): Promise<void> {
|
|
1048
|
+
if (actionId !== TABLE_DOWNLOAD_ACTION_ID) {
|
|
1049
|
+
return
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
await handleDownloadTable()
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
function resolveCellInputClass(type: AiTableColumnType): string {
|
|
1056
|
+
if (type === 'tag') {
|
|
1057
|
+
return 'hai-ai-table-cell-input hai-ai-table-cell-input--tag'
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
if (type === 'number') {
|
|
1061
|
+
return 'hai-ai-table-cell-input hai-ai-table-cell-input--number'
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
return 'hai-ai-table-cell-input'
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
function resolveBodyRowClass(rowId: string): string {
|
|
1068
|
+
return cn(
|
|
1069
|
+
'hai-ai-table-body-row',
|
|
1070
|
+
draggingRowId === rowId ? 'hai-ai-table-body-row--dragging' : '',
|
|
1071
|
+
isDropIndicatorVisible(rowId, 'before')
|
|
1072
|
+
? 'hai-ai-table-body-row--drop-before'
|
|
1073
|
+
: '',
|
|
1074
|
+
isDropIndicatorVisible(rowId, 'after')
|
|
1075
|
+
? 'hai-ai-table-body-row--drop-after'
|
|
1076
|
+
: '',
|
|
1077
|
+
)
|
|
1078
|
+
}
|
|
1079
|
+
</script>
|
|
1080
|
+
|
|
1081
|
+
<section {...dataAttributes} class={tablePaneClass}>
|
|
1082
|
+
<header class='hai-ai-table-header'>
|
|
1083
|
+
<div class='hai-ai-table-heading'>
|
|
1084
|
+
<div class='hai-ai-table-eyebrow'>
|
|
1085
|
+
{metaText || uiM('table_editor_eyebrow')}
|
|
1086
|
+
</div>
|
|
1087
|
+
<h2 class='hai-ai-table-title' title={title || uiM('data_table_empty')}>
|
|
1088
|
+
{title || uiM('data_table_empty')}
|
|
1089
|
+
</h2>
|
|
1090
|
+
{#if statusText}
|
|
1091
|
+
<p class='hai-ai-table-status'>{statusText}</p>
|
|
1092
|
+
{/if}
|
|
1093
|
+
</div>
|
|
1094
|
+
|
|
1095
|
+
<div class='hai-ai-table-toolbar'>
|
|
1096
|
+
{#if saveState}
|
|
1097
|
+
<span class='hai-ai-table-save-state'>{saveState}</span>
|
|
1098
|
+
{/if}
|
|
1099
|
+
|
|
1100
|
+
<button
|
|
1101
|
+
type='button'
|
|
1102
|
+
class='hai-ai-table-toolbar-btn'
|
|
1103
|
+
title={uiM('table_copy')}
|
|
1104
|
+
aria-label={uiM('table_copy')}
|
|
1105
|
+
onclick={() => {
|
|
1106
|
+
void handleCopyTable()
|
|
1107
|
+
}}
|
|
1108
|
+
>
|
|
1109
|
+
<!-- eslint-disable-next-line svelte/no-at-html-tags -- 受控 SVG 图标渲染 -->
|
|
1110
|
+
{@html copied ? CHECK_ICON : COPY_ICON}
|
|
1111
|
+
</button>
|
|
1112
|
+
|
|
1113
|
+
<AiDocumentDownloadMenu
|
|
1114
|
+
actions={resolveTableDownloadActions()}
|
|
1115
|
+
ondownload={handleDownloadAction}
|
|
1116
|
+
triggerTitle={uiM('table_download')}
|
|
1117
|
+
triggerClass='hai-ai-table-toolbar-btn hai-ai-table-toolbar-btn--download'
|
|
1118
|
+
menuClass='hai-ai-table-download-menu-panel'
|
|
1119
|
+
/>
|
|
1120
|
+
|
|
1121
|
+
{#if onclose}
|
|
1122
|
+
<button
|
|
1123
|
+
type='button'
|
|
1124
|
+
class='hai-ai-table-toolbar-btn'
|
|
1125
|
+
title={uiM('table_close')}
|
|
1126
|
+
aria-label={uiM('table_close')}
|
|
1127
|
+
disabled={closeDisabled}
|
|
1128
|
+
onclick={() => {
|
|
1129
|
+
flushPendingTableChange()
|
|
1130
|
+
onclose?.()
|
|
1131
|
+
}}
|
|
1132
|
+
>
|
|
1133
|
+
<!-- eslint-disable-next-line svelte/no-at-html-tags -- 受控 SVG 图标渲染 -->
|
|
1134
|
+
{@html CLOSE_ICON}
|
|
1135
|
+
</button>
|
|
1136
|
+
{/if}
|
|
1137
|
+
</div>
|
|
1138
|
+
</header>
|
|
1139
|
+
|
|
1140
|
+
<div
|
|
1141
|
+
class='hai-ai-table-scroll'
|
|
1142
|
+
bind:this={editorScrollHost}
|
|
1143
|
+
onscroll={ondocumentscroll}
|
|
1144
|
+
>
|
|
1145
|
+
<table class='hai-ai-table-grid'>
|
|
1146
|
+
<thead>
|
|
1147
|
+
<tr>
|
|
1148
|
+
{#each tableColumns as column (column.key)}
|
|
1149
|
+
<th title={column.label}>{column.label}</th>
|
|
1150
|
+
{/each}
|
|
1151
|
+
{#if editable}
|
|
1152
|
+
<th class='hai-ai-table-action-head'>{uiM('data_table_actions')}</th>
|
|
1153
|
+
{/if}
|
|
1154
|
+
</tr>
|
|
1155
|
+
</thead>
|
|
1156
|
+
<tbody>
|
|
1157
|
+
{#if tableRows.length === 0}
|
|
1158
|
+
<tr>
|
|
1159
|
+
<td
|
|
1160
|
+
class='hai-ai-table-empty'
|
|
1161
|
+
colspan={tableColumns.length + (editable ? 1 : 0)}
|
|
1162
|
+
>
|
|
1163
|
+
{uiM('data_table_empty')}
|
|
1164
|
+
</td>
|
|
1165
|
+
</tr>
|
|
1166
|
+
{:else}
|
|
1167
|
+
{#each tableRows as row (row.row_id)}
|
|
1168
|
+
<tr
|
|
1169
|
+
class={resolveBodyRowClass(row.row_id)}
|
|
1170
|
+
ondragover={event => handleRowDragOver(row.row_id, event)}
|
|
1171
|
+
ondrop={event => handleRowDrop(row.row_id, event)}
|
|
1172
|
+
>
|
|
1173
|
+
{#each tableColumns as column (column.key)}
|
|
1174
|
+
{@const cellInputValue = getCellInputValue(row, column.key)}
|
|
1175
|
+
<td>
|
|
1176
|
+
<input
|
|
1177
|
+
class={resolveCellInputClass(column.type)}
|
|
1178
|
+
type={column.type === 'number' ? 'number' : 'text'}
|
|
1179
|
+
value={cellInputValue}
|
|
1180
|
+
title={cellInputValue}
|
|
1181
|
+
disabled={!editable}
|
|
1182
|
+
oninput={event => handleCellInput(row.row_id, column, event)}
|
|
1183
|
+
/>
|
|
1184
|
+
</td>
|
|
1185
|
+
{/each}
|
|
1186
|
+
{#if editable}
|
|
1187
|
+
<td class='hai-ai-table-row-action'>
|
|
1188
|
+
<div class='hai-ai-table-row-actions'>
|
|
1189
|
+
<button
|
|
1190
|
+
type='button'
|
|
1191
|
+
class='hai-ai-table-row-handle'
|
|
1192
|
+
title={uiM('table_reorder_row')}
|
|
1193
|
+
aria-label={uiM('table_reorder_row')}
|
|
1194
|
+
aria-grabbed={draggingRowId === row.row_id}
|
|
1195
|
+
disabled={tableRows.length < 2}
|
|
1196
|
+
draggable={tableRows.length > 1}
|
|
1197
|
+
ondragstart={event => handleRowDragStart(row.row_id, event)}
|
|
1198
|
+
ondragend={resetRowDragState}
|
|
1199
|
+
>
|
|
1200
|
+
<!-- eslint-disable-next-line svelte/no-at-html-tags -- 受控 SVG 图标渲染 -->
|
|
1201
|
+
{@html DRAG_HANDLE_ICON}
|
|
1202
|
+
</button>
|
|
1203
|
+
|
|
1204
|
+
<button
|
|
1205
|
+
type='button'
|
|
1206
|
+
class='hai-ai-table-row-delete'
|
|
1207
|
+
title={uiM('table_delete_row')}
|
|
1208
|
+
aria-label={uiM('table_delete_row')}
|
|
1209
|
+
onclick={() => handleDeleteRow(row.row_id)}
|
|
1210
|
+
>
|
|
1211
|
+
<!-- eslint-disable-next-line svelte/no-at-html-tags -- 受控 SVG 图标渲染 -->
|
|
1212
|
+
{@html DELETE_ICON}
|
|
1213
|
+
</button>
|
|
1214
|
+
</div>
|
|
1215
|
+
</td>
|
|
1216
|
+
{/if}
|
|
1217
|
+
</tr>
|
|
1218
|
+
{/each}
|
|
1219
|
+
{/if}
|
|
1220
|
+
|
|
1221
|
+
{#if editable}
|
|
1222
|
+
<tr class='hai-ai-table-add-row'>
|
|
1223
|
+
<td colspan={tableColumns.length + 1}>
|
|
1224
|
+
<button
|
|
1225
|
+
type='button'
|
|
1226
|
+
class='hai-ai-table-add-btn'
|
|
1227
|
+
title={uiM('table_add_row')}
|
|
1228
|
+
aria-label={uiM('table_add_row')}
|
|
1229
|
+
onclick={handleAddRow}
|
|
1230
|
+
>
|
|
1231
|
+
<!-- eslint-disable-next-line svelte/no-at-html-tags -- 受控 SVG 图标渲染 -->
|
|
1232
|
+
{@html PLUS_ICON}
|
|
1233
|
+
<span>{uiM('table_add_row')}</span>
|
|
1234
|
+
</button>
|
|
1235
|
+
</td>
|
|
1236
|
+
</tr>
|
|
1237
|
+
{/if}
|
|
1238
|
+
</tbody>
|
|
1239
|
+
</table>
|
|
1240
|
+
</div>
|
|
1241
|
+
</section>
|
|
1242
|
+
|
|
1243
|
+
<style>
|
|
1244
|
+
.hai-ai-table-pane {
|
|
1245
|
+
/*
|
|
1246
|
+
主题变量兼容层:
|
|
1247
|
+
- hai-mate Web 端主要使用 daisyUI v5 的 `--color-*` 语义变量;
|
|
1248
|
+
- 组件库内部分场景仍可能提供旧版 `--b1/--bc/--p` 通道变量;
|
|
1249
|
+
- 这里统一抽象为 AiTableEditor 私有变量,确保在两套主题体系下都能稳定着色。
|
|
1250
|
+
*/
|
|
1251
|
+
--hai-ai-table-bg: var(--color-base-100, var(--color-base-100, oklch(1 0 0)));
|
|
1252
|
+
--hai-ai-table-bg-soft: var(--color-base-200, var(--color-base-200, oklch(0.97 0 0)));
|
|
1253
|
+
--hai-ai-table-fg: var(--color-base-content, var(--color-base-content, oklch(0.22 0 0)));
|
|
1254
|
+
--hai-ai-table-primary: var(--color-primary, var(--color-primary, oklch(0.62 0.2 258)));
|
|
1255
|
+
--hai-ai-table-error: var(--color-error, var(--color-error, oklch(0.64 0.2 25)));
|
|
1256
|
+
|
|
1257
|
+
display: flex;
|
|
1258
|
+
min-height: 0;
|
|
1259
|
+
height: 100%;
|
|
1260
|
+
flex-direction: column;
|
|
1261
|
+
border: 1px solid color-mix(in srgb, var(--hai-ai-table-fg) 8%, transparent);
|
|
1262
|
+
border-radius: 1.5rem;
|
|
1263
|
+
background: linear-gradient(
|
|
1264
|
+
180deg,
|
|
1265
|
+
var(--hai-ai-table-bg) 0%,
|
|
1266
|
+
color-mix(in srgb, var(--hai-ai-table-bg) 92%, var(--color-base-100) 8%) 100%
|
|
1267
|
+
);
|
|
1268
|
+
overflow: hidden;
|
|
1269
|
+
box-shadow: 0 14px 40px color-mix(in srgb, var(--hai-ai-table-fg) 6%, transparent);
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
.hai-ai-table-header {
|
|
1273
|
+
display: flex;
|
|
1274
|
+
align-items: center;
|
|
1275
|
+
justify-content: space-between;
|
|
1276
|
+
gap: 1rem;
|
|
1277
|
+
padding: 1rem 1.25rem;
|
|
1278
|
+
border-bottom: 1px solid color-mix(in srgb, var(--hai-ai-table-fg) 8%, transparent);
|
|
1279
|
+
background: color-mix(in srgb, var(--hai-ai-table-bg) 90%, var(--color-base-100) 10%);
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
.hai-ai-table-heading {
|
|
1283
|
+
min-width: 0;
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
.hai-ai-table-eyebrow {
|
|
1287
|
+
font-size: 0.73rem;
|
|
1288
|
+
font-weight: 600;
|
|
1289
|
+
color: color-mix(in srgb, var(--hai-ai-table-fg) 58%, transparent);
|
|
1290
|
+
letter-spacing: 0.06em;
|
|
1291
|
+
text-transform: uppercase;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
.hai-ai-table-title {
|
|
1295
|
+
margin: 0.25rem 0 0;
|
|
1296
|
+
font-size: 1.05rem;
|
|
1297
|
+
font-weight: 700;
|
|
1298
|
+
color: var(--hai-ai-table-fg);
|
|
1299
|
+
line-height: 1.35;
|
|
1300
|
+
max-width: min(52vw, 36rem);
|
|
1301
|
+
overflow: hidden;
|
|
1302
|
+
text-overflow: ellipsis;
|
|
1303
|
+
white-space: nowrap;
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
.hai-ai-table-status {
|
|
1307
|
+
margin: 0.2rem 0 0;
|
|
1308
|
+
font-size: 0.78rem;
|
|
1309
|
+
color: color-mix(in srgb, var(--hai-ai-table-fg) 58%, transparent);
|
|
1310
|
+
white-space: nowrap;
|
|
1311
|
+
overflow: hidden;
|
|
1312
|
+
text-overflow: ellipsis;
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
.hai-ai-table-toolbar {
|
|
1316
|
+
display: flex;
|
|
1317
|
+
align-items: center;
|
|
1318
|
+
gap: 0.55rem;
|
|
1319
|
+
flex-shrink: 0;
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
.hai-ai-table-save-state {
|
|
1323
|
+
display: inline-flex;
|
|
1324
|
+
align-items: center;
|
|
1325
|
+
min-height: 2.2rem;
|
|
1326
|
+
padding: 0 0.82rem;
|
|
1327
|
+
border-radius: 9999px;
|
|
1328
|
+
border: 1px solid color-mix(in srgb, var(--hai-ai-table-primary) 16%, var(--hai-ai-table-bg) 84%);
|
|
1329
|
+
background: color-mix(in srgb, var(--hai-ai-table-primary) 10%, var(--hai-ai-table-bg) 90%);
|
|
1330
|
+
color: var(--hai-ai-table-primary);
|
|
1331
|
+
font-size: 0.78rem;
|
|
1332
|
+
font-weight: 600;
|
|
1333
|
+
white-space: nowrap;
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
.hai-ai-table-toolbar-btn {
|
|
1337
|
+
width: 2.2rem;
|
|
1338
|
+
height: 2.2rem;
|
|
1339
|
+
display: inline-flex;
|
|
1340
|
+
align-items: center;
|
|
1341
|
+
justify-content: center;
|
|
1342
|
+
border-radius: 0.82rem;
|
|
1343
|
+
border: 1px solid color-mix(in srgb, var(--hai-ai-table-fg) 10%, transparent);
|
|
1344
|
+
background: var(--hai-ai-table-bg);
|
|
1345
|
+
color: color-mix(in srgb, var(--hai-ai-table-fg) 82%, transparent);
|
|
1346
|
+
cursor: pointer;
|
|
1347
|
+
transition:
|
|
1348
|
+
transform 0.15s ease,
|
|
1349
|
+
box-shadow 0.15s ease,
|
|
1350
|
+
border-color 0.15s ease,
|
|
1351
|
+
background-color 0.15s ease,
|
|
1352
|
+
color 0.15s ease;
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
.hai-ai-table-toolbar-btn :global(svg) {
|
|
1356
|
+
width: 1.02rem;
|
|
1357
|
+
height: 1.02rem;
|
|
1358
|
+
fill: currentColor;
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
.hai-ai-table-toolbar-btn:hover:not(:disabled) {
|
|
1362
|
+
transform: translateY(-1px);
|
|
1363
|
+
color: var(--hai-ai-table-fg);
|
|
1364
|
+
border-color: color-mix(in srgb, var(--hai-ai-table-fg) 18%, transparent);
|
|
1365
|
+
background: color-mix(in srgb, var(--hai-ai-table-bg-soft) 70%, var(--hai-ai-table-bg) 30%);
|
|
1366
|
+
box-shadow: 0 14px 24px -20px color-mix(in srgb, var(--hai-ai-table-fg) 42%, transparent);
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
.hai-ai-table-toolbar-btn:disabled {
|
|
1370
|
+
cursor: not-allowed;
|
|
1371
|
+
opacity: 0.6;
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
:global(.hai-ai-download-menu__trigger.hai-ai-table-toolbar-btn) {
|
|
1375
|
+
width: 2.2rem;
|
|
1376
|
+
min-width: 2.2rem;
|
|
1377
|
+
height: 2.2rem;
|
|
1378
|
+
min-height: 0;
|
|
1379
|
+
padding: 0;
|
|
1380
|
+
display: inline-flex;
|
|
1381
|
+
align-items: center;
|
|
1382
|
+
justify-content: center;
|
|
1383
|
+
border-radius: 0.82rem;
|
|
1384
|
+
border-color: color-mix(in srgb, var(--hai-ai-table-fg) 10%, transparent);
|
|
1385
|
+
background: var(--hai-ai-table-bg);
|
|
1386
|
+
color: color-mix(in srgb, var(--hai-ai-table-fg) 82%, transparent);
|
|
1387
|
+
box-shadow: none;
|
|
1388
|
+
box-sizing: border-box;
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
:global(.hai-ai-download-menu__trigger.hai-ai-table-toolbar-btn:hover) {
|
|
1392
|
+
transform: translateY(-1px);
|
|
1393
|
+
color: var(--hai-ai-table-fg);
|
|
1394
|
+
border-color: color-mix(in srgb, var(--hai-ai-table-fg) 18%, transparent);
|
|
1395
|
+
background: color-mix(in srgb, var(--hai-ai-table-bg-soft) 70%, var(--hai-ai-table-bg) 30%);
|
|
1396
|
+
box-shadow: 0 14px 24px -20px color-mix(in srgb, var(--hai-ai-table-fg) 42%, transparent);
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
:global(.hai-ai-download-menu__trigger.hai-ai-table-toolbar-btn:focus-visible) {
|
|
1400
|
+
outline: 2px solid color-mix(in srgb, var(--hai-ai-table-primary) 28%, transparent);
|
|
1401
|
+
outline-offset: 2px;
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
:global(.hai-ai-download-menu__trigger.hai-ai-table-toolbar-btn .hai-ai-download-menu__trigger-icon) {
|
|
1405
|
+
width: 1.02rem;
|
|
1406
|
+
height: 1.02rem;
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
:global(.hai-ai-table-download-menu-panel) {
|
|
1410
|
+
border-color: color-mix(in srgb, var(--hai-ai-table-fg) 10%, var(--hai-ai-table-bg) 90%);
|
|
1411
|
+
border-radius: 1.2rem;
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
.hai-ai-table-scroll {
|
|
1415
|
+
min-height: 0;
|
|
1416
|
+
flex: 1;
|
|
1417
|
+
overflow: auto;
|
|
1418
|
+
padding: 1rem 1.15rem 1.25rem;
|
|
1419
|
+
background:
|
|
1420
|
+
radial-gradient(
|
|
1421
|
+
circle at 12% 6%,
|
|
1422
|
+
color-mix(in srgb, var(--hai-ai-table-primary) 10%, transparent) 0%,
|
|
1423
|
+
transparent 46%
|
|
1424
|
+
),
|
|
1425
|
+
var(--hai-ai-table-bg);
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
.hai-ai-table-grid {
|
|
1429
|
+
width: 100%;
|
|
1430
|
+
min-width: 46rem;
|
|
1431
|
+
border-collapse: collapse;
|
|
1432
|
+
border-spacing: 0;
|
|
1433
|
+
/* 先提供稳定回退色,再叠加 color-mix,避免低版本浏览器整条规则失效。 */
|
|
1434
|
+
border: 1px solid color-mix(in srgb, var(--hai-ai-table-fg) 20%, transparent);
|
|
1435
|
+
border: 1px solid color-mix(in srgb, var(--hai-ai-table-fg) 14%, var(--hai-ai-table-bg) 86%);
|
|
1436
|
+
border-radius: 1rem;
|
|
1437
|
+
overflow: hidden;
|
|
1438
|
+
background: var(--hai-ai-table-bg);
|
|
1439
|
+
box-shadow: 0 1px 0 color-mix(in srgb, var(--hai-ai-table-fg) 6%, transparent);
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
.hai-ai-table-grid thead th {
|
|
1443
|
+
position: sticky;
|
|
1444
|
+
top: 0;
|
|
1445
|
+
z-index: 1;
|
|
1446
|
+
text-align: left;
|
|
1447
|
+
font-size: 0.82rem;
|
|
1448
|
+
font-weight: 700;
|
|
1449
|
+
color: color-mix(in srgb, var(--hai-ai-table-fg) 84%, transparent);
|
|
1450
|
+
background: var(--hai-ai-table-bg-soft);
|
|
1451
|
+
background: color-mix(in srgb, var(--hai-ai-table-primary) 14%, var(--hai-ai-table-bg-soft) 86%);
|
|
1452
|
+
padding: 0.76rem 0.78rem;
|
|
1453
|
+
border-bottom: 1px solid color-mix(in srgb, var(--hai-ai-table-fg) 18%, transparent);
|
|
1454
|
+
border-bottom: 1px solid color-mix(in srgb, var(--hai-ai-table-fg) 14%, var(--hai-ai-table-bg) 86%);
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
.hai-ai-table-grid thead th + th {
|
|
1458
|
+
border-left: 1px solid color-mix(in srgb, var(--hai-ai-table-fg) 15%, transparent);
|
|
1459
|
+
border-left: 1px solid color-mix(in srgb, var(--hai-ai-table-fg) 11%, var(--hai-ai-table-bg) 89%);
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
.hai-ai-table-grid tbody td {
|
|
1463
|
+
border-bottom: 1px solid color-mix(in srgb, var(--hai-ai-table-fg) 14%, transparent);
|
|
1464
|
+
border-bottom: 1px solid color-mix(in srgb, var(--hai-ai-table-fg) 11%, var(--hai-ai-table-bg) 89%);
|
|
1465
|
+
border-left: 1px solid color-mix(in srgb, var(--hai-ai-table-fg) 14%, transparent);
|
|
1466
|
+
border-left: 1px solid color-mix(in srgb, var(--hai-ai-table-fg) 11%, var(--hai-ai-table-bg) 89%);
|
|
1467
|
+
padding: 0.48rem 0.56rem;
|
|
1468
|
+
background: var(--hai-ai-table-bg);
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
.hai-ai-table-grid tbody td:first-child {
|
|
1472
|
+
border-left: none;
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
.hai-ai-table-grid tbody tr:last-child td {
|
|
1476
|
+
border-bottom: none;
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
.hai-ai-table-cell-input {
|
|
1480
|
+
width: 100%;
|
|
1481
|
+
border: 1px solid transparent;
|
|
1482
|
+
border-radius: 0.65rem;
|
|
1483
|
+
padding: 0.42rem 0.5rem;
|
|
1484
|
+
font-size: 0.88rem;
|
|
1485
|
+
line-height: 1.4;
|
|
1486
|
+
color: color-mix(in srgb, var(--hai-ai-table-fg) 90%, transparent);
|
|
1487
|
+
background: transparent;
|
|
1488
|
+
transition:
|
|
1489
|
+
border-color 0.15s ease,
|
|
1490
|
+
background-color 0.15s ease,
|
|
1491
|
+
box-shadow 0.15s ease;
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
.hai-ai-table-cell-input:hover:enabled {
|
|
1495
|
+
border-color: color-mix(in srgb, var(--hai-ai-table-fg) 12%, var(--hai-ai-table-bg) 88%);
|
|
1496
|
+
background: color-mix(in srgb, var(--hai-ai-table-bg-soft) 70%, var(--hai-ai-table-bg) 30%);
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
.hai-ai-table-cell-input:focus-visible {
|
|
1500
|
+
outline: none;
|
|
1501
|
+
border-color: color-mix(in srgb, var(--hai-ai-table-primary) 58%, var(--hai-ai-table-bg) 42%);
|
|
1502
|
+
box-shadow: 0 0 0 3px color-mix(in srgb, var(--hai-ai-table-primary) 18%, transparent);
|
|
1503
|
+
background: color-mix(in srgb, var(--hai-ai-table-bg) 88%, var(--color-base-100) 12%);
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
.hai-ai-table-cell-input:disabled {
|
|
1507
|
+
cursor: default;
|
|
1508
|
+
color: color-mix(in srgb, var(--hai-ai-table-fg) 72%, transparent);
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
.hai-ai-table-cell-input--tag {
|
|
1512
|
+
background: color-mix(in srgb, var(--hai-ai-table-primary) 10%, var(--hai-ai-table-bg) 90%);
|
|
1513
|
+
color: var(--hai-ai-table-primary);
|
|
1514
|
+
font-weight: 600;
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
.hai-ai-table-cell-input--number {
|
|
1518
|
+
text-align: right;
|
|
1519
|
+
font-variant-numeric: tabular-nums;
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
.hai-ai-table-body-row {
|
|
1523
|
+
transition: background-color 0.15s ease, opacity 0.15s ease;
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
.hai-ai-table-body-row--dragging td {
|
|
1527
|
+
background: color-mix(in srgb, var(--hai-ai-table-bg-soft) 72%, var(--hai-ai-table-bg) 28%);
|
|
1528
|
+
opacity: 0.7;
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
.hai-ai-table-body-row--drop-before td {
|
|
1532
|
+
box-shadow: inset 0 3px 0 color-mix(in srgb, var(--hai-ai-table-primary) 50%, transparent);
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
.hai-ai-table-body-row--drop-after td {
|
|
1536
|
+
box-shadow: inset 0 -3px 0 color-mix(in srgb, var(--hai-ai-table-primary) 50%, transparent);
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
.hai-ai-table-action-head,
|
|
1540
|
+
.hai-ai-table-row-action {
|
|
1541
|
+
width: 5.2rem;
|
|
1542
|
+
min-width: 5.2rem;
|
|
1543
|
+
text-align: center;
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
.hai-ai-table-row-actions {
|
|
1547
|
+
display: inline-flex;
|
|
1548
|
+
align-items: center;
|
|
1549
|
+
justify-content: center;
|
|
1550
|
+
gap: 0.38rem;
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
.hai-ai-table-row-handle,
|
|
1554
|
+
.hai-ai-table-row-delete {
|
|
1555
|
+
width: 1.95rem;
|
|
1556
|
+
height: 1.95rem;
|
|
1557
|
+
display: inline-flex;
|
|
1558
|
+
align-items: center;
|
|
1559
|
+
justify-content: center;
|
|
1560
|
+
border-radius: 9999px;
|
|
1561
|
+
border: 1px solid color-mix(in srgb, var(--hai-ai-table-fg) 18%, var(--hai-ai-table-bg) 82%);
|
|
1562
|
+
color: color-mix(in srgb, var(--hai-ai-table-fg) 66%, transparent);
|
|
1563
|
+
background: color-mix(in srgb, var(--hai-ai-table-bg) 80%, var(--hai-ai-table-bg-soft) 20%);
|
|
1564
|
+
cursor: pointer;
|
|
1565
|
+
transition:
|
|
1566
|
+
opacity 0.12s ease,
|
|
1567
|
+
transform 0.12s ease,
|
|
1568
|
+
color 0.15s ease,
|
|
1569
|
+
border-color 0.15s ease,
|
|
1570
|
+
background-color 0.15s ease;
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
.hai-ai-table-row-handle {
|
|
1574
|
+
cursor: grab;
|
|
1575
|
+
opacity: 0.82;
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
.hai-ai-table-row-handle:active {
|
|
1579
|
+
cursor: grabbing;
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
.hai-ai-table-row-handle:disabled {
|
|
1583
|
+
cursor: not-allowed;
|
|
1584
|
+
opacity: 0.45;
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
.hai-ai-table-row-handle :global(svg),
|
|
1588
|
+
.hai-ai-table-row-delete :global(svg) {
|
|
1589
|
+
width: 0.86rem;
|
|
1590
|
+
height: 0.86rem;
|
|
1591
|
+
fill: currentColor;
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
.hai-ai-table-body-row:hover .hai-ai-table-row-handle:not(:disabled) {
|
|
1595
|
+
opacity: 1;
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
.hai-ai-table-body-row:hover .hai-ai-table-row-delete {
|
|
1599
|
+
opacity: 1;
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
.hai-ai-table-row-actions:focus-within .hai-ai-table-row-delete {
|
|
1603
|
+
opacity: 1;
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
.hai-ai-table-row-handle:hover:not(:disabled),
|
|
1607
|
+
.hai-ai-table-row-delete:hover {
|
|
1608
|
+
transform: translateY(-1px);
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
.hai-ai-table-row-handle:focus-visible,
|
|
1612
|
+
.hai-ai-table-row-delete:focus-visible {
|
|
1613
|
+
outline: 2px solid color-mix(in srgb, var(--hai-ai-table-primary) 26%, transparent);
|
|
1614
|
+
outline-offset: 2px;
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
.hai-ai-table-row-handle:hover:not(:disabled) {
|
|
1618
|
+
color: var(--hai-ai-table-fg);
|
|
1619
|
+
border-color: color-mix(in srgb, var(--hai-ai-table-primary) 24%, var(--hai-ai-table-bg) 76%);
|
|
1620
|
+
background: color-mix(in srgb, var(--hai-ai-table-primary) 8%, var(--hai-ai-table-bg) 92%);
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
.hai-ai-table-row-delete {
|
|
1624
|
+
opacity: 0.38;
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
.hai-ai-table-row-delete:hover {
|
|
1628
|
+
color: var(--hai-ai-table-error);
|
|
1629
|
+
border-color: color-mix(in srgb, var(--hai-ai-table-error) 42%, var(--hai-ai-table-bg) 58%);
|
|
1630
|
+
background: color-mix(in srgb, var(--hai-ai-table-error) 9%, var(--hai-ai-table-bg) 91%);
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
.hai-ai-table-empty {
|
|
1634
|
+
text-align: center;
|
|
1635
|
+
color: color-mix(in srgb, var(--hai-ai-table-fg) 52%, transparent);
|
|
1636
|
+
font-size: 0.84rem;
|
|
1637
|
+
padding: 1.15rem 0.75rem;
|
|
1638
|
+
background: color-mix(in srgb, var(--hai-ai-table-bg-soft) 52%, var(--hai-ai-table-bg) 48%);
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
.hai-ai-table-add-row td {
|
|
1642
|
+
padding: 0.58rem 0.62rem;
|
|
1643
|
+
background: color-mix(in srgb, var(--hai-ai-table-bg-soft) 45%, var(--hai-ai-table-bg) 55%);
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
.hai-ai-table-add-btn {
|
|
1647
|
+
width: 100%;
|
|
1648
|
+
height: 2rem;
|
|
1649
|
+
display: inline-flex;
|
|
1650
|
+
align-items: center;
|
|
1651
|
+
justify-content: center;
|
|
1652
|
+
gap: 0.45rem;
|
|
1653
|
+
border: 1px dashed color-mix(in srgb, var(--hai-ai-table-primary) 35%, var(--hai-ai-table-bg) 65%);
|
|
1654
|
+
border-radius: 0.66rem;
|
|
1655
|
+
color: var(--hai-ai-table-primary);
|
|
1656
|
+
font-size: 0.82rem;
|
|
1657
|
+
font-weight: 600;
|
|
1658
|
+
background: color-mix(in srgb, var(--hai-ai-table-primary) 7%, var(--hai-ai-table-bg) 93%);
|
|
1659
|
+
cursor: pointer;
|
|
1660
|
+
transition:
|
|
1661
|
+
border-color 0.15s ease,
|
|
1662
|
+
background-color 0.15s ease,
|
|
1663
|
+
transform 0.15s ease;
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
.hai-ai-table-add-btn :global(svg) {
|
|
1667
|
+
width: 0.92rem;
|
|
1668
|
+
height: 0.92rem;
|
|
1669
|
+
fill: currentColor;
|
|
1670
|
+
}
|
|
1671
|
+
|
|
1672
|
+
.hai-ai-table-add-btn:hover {
|
|
1673
|
+
transform: translateY(-1px);
|
|
1674
|
+
border-color: color-mix(in srgb, var(--hai-ai-table-primary) 52%, var(--hai-ai-table-bg) 48%);
|
|
1675
|
+
background: color-mix(in srgb, var(--hai-ai-table-primary) 11%, var(--hai-ai-table-bg) 89%);
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
@media (max-width: 768px) {
|
|
1679
|
+
.hai-ai-table-header {
|
|
1680
|
+
flex-wrap: wrap;
|
|
1681
|
+
align-items: flex-start;
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
.hai-ai-table-title {
|
|
1685
|
+
max-width: min(76vw, 22rem);
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
.hai-ai-table-grid {
|
|
1689
|
+
min-width: 36rem;
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
</style>
|