niuma-ui 2.0.4 → 2.1.0
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/CHANGELOG.md +67 -0
- package/NOTICE +0 -1
- package/README.md +3 -3
- package/README.zh-CN.md +3 -3
- package/dist/components/_shared/index.d.ts +2 -2
- package/dist/components/_shared/src/overlay-utils.d.ts +44 -1
- package/dist/components/_shared/src/overlay-utils.js +87 -2
- package/dist/components/alert/index.d.ts +1 -0
- package/dist/components/alert/src/RsAlert.css +120 -65
- package/dist/components/alert/src/RsAlert.d.ts +24 -5
- package/dist/components/alert/src/RsAlert.impl.js +108 -36
- package/dist/components/alert/src/RsAlert.js +1 -1
- package/dist/components/alert/src/alert-utils.d.ts +37 -0
- package/dist/components/alert/src/alert-utils.js +71 -0
- package/dist/components/auto-complete/src/RsAutoComplete.d.ts +1 -1
- package/dist/components/button/src/RsButton.css +75 -72
- package/dist/components/button/src/RsButton.d.ts +1 -4
- package/dist/components/button/src/RsButton.impl.js +3 -7
- package/dist/components/button/src/RsButton.js +1 -1
- package/dist/components/card/src/RsCard.d.ts +1 -1
- package/dist/components/code-block/index.d.ts +1 -0
- package/dist/components/code-block/src/RsCodeBlock.css +93 -52
- package/dist/components/code-block/src/RsCodeBlock.d.ts +36 -9
- package/dist/components/code-block/src/RsCodeBlock.impl.js +203 -84
- package/dist/components/code-block/src/RsCodeBlock.js +1 -1
- package/dist/components/code-block/src/code-block-highlight.d.ts +4 -0
- package/dist/components/code-block/src/code-block-highlight.js +34 -0
- package/dist/components/code-block/src/code-block-utils.d.ts +23 -0
- package/dist/components/code-block/src/code-block-utils.js +71 -0
- package/dist/components/code-editor/index.d.ts +1 -1
- package/dist/components/code-editor/src/RsCodeEditor.css +118 -92
- package/dist/components/code-editor/src/RsCodeEditor.d.ts +14 -3
- package/dist/components/code-editor/src/RsCodeEditor.impl.js +261 -94
- package/dist/components/code-editor/src/RsCodeEditor.js +1 -1
- package/dist/components/code-editor/src/code-editor-utils.d.ts +15 -0
- package/dist/components/code-editor/src/code-editor-utils.js +36 -1
- package/dist/components/code-editor/src/code-mirror-completion.d.ts +1 -1
- package/dist/components/code-editor/src/code-mirror-completion.js +8 -5
- package/dist/components/code-editor/src/code-mirror-diagnostics.d.ts +2 -3
- package/dist/components/code-editor/src/code-mirror-diagnostics.js +3 -4
- package/dist/components/code-editor/src/code-mirror-ghost.d.ts +1 -1
- package/dist/components/code-editor/src/code-mirror-ghost.js +12 -3
- package/dist/components/code-editor/src/code-mirror-inline-edit.js +8 -3
- package/dist/components/code-editor/src/code-mirror-intel.d.ts +2 -2
- package/dist/components/code-editor/src/code-mirror-intel.js +50 -39
- package/dist/components/code-editor/src/code-mirror-lang.js +4 -0
- package/dist/components/code-editor/src/code-mirror-session.d.ts +13 -0
- package/dist/components/code-editor/src/code-mirror-session.js +30 -0
- package/dist/components/config-provider/src/RsConfigProvider.css +1 -1
- package/dist/components/config-provider/src/RsConfigProvider.d.ts +2 -2
- package/dist/components/config-provider/src/RsConfigProvider.impl.js +7 -16
- package/dist/components/config-provider/src/RsConfigProvider.js +1 -1
- package/dist/components/context-menu/index.d.ts +1 -1
- package/dist/components/context-menu/src/RsContextMenu.css +115 -89
- package/dist/components/context-menu/src/RsContextMenu.d.ts +32 -11
- package/dist/components/context-menu/src/RsContextMenu.impl.js +795 -48
- package/dist/components/context-menu/src/RsContextMenuItems.d.ts +25 -1
- package/dist/components/context-menu/src/RsContextMenuItems.impl.js +110 -61
- package/dist/components/context-menu/src/context-menu-utils.d.ts +89 -3
- package/dist/components/context-menu/src/context-menu-utils.js +168 -3
- package/dist/components/date-picker/src/RsDatePicker.d.ts +2 -2
- package/dist/components/date-picker/src/RsDateTimePicker.d.ts +2 -2
- package/dist/components/descriptions/index.d.ts +1 -1
- package/dist/components/descriptions/src/RsDescriptions.css +38 -11
- package/dist/components/descriptions/src/RsDescriptions.d.ts +20 -4
- package/dist/components/descriptions/src/RsDescriptions.impl.js +89 -19
- package/dist/components/descriptions/src/RsDescriptionsItem.impl.js +13 -6
- package/dist/components/descriptions/src/descriptions-utils.d.ts +19 -0
- package/dist/components/descriptions/src/descriptions-utils.js +39 -1
- package/dist/components/dialog/index.d.ts +1 -1
- package/dist/components/dialog/src/RsConfirmDialog.css +47 -21
- package/dist/components/dialog/src/RsConfirmDialog.d.ts +19 -7
- package/dist/components/dialog/src/RsConfirmDialog.impl.js +349 -119
- package/dist/components/dialog/src/RsConfirmDialog.js +2 -1
- package/dist/components/dialog/src/RsDialog.css +102 -109
- package/dist/components/dialog/src/RsDialog.d.ts +34 -24
- package/dist/components/dialog/src/RsDialog.impl.js +410 -177
- package/dist/components/dialog/src/RsDialog.js +2 -1
- package/dist/components/dialog/src/dialog-utils.d.ts +40 -1
- package/dist/components/dialog/src/dialog-utils.js +152 -1
- package/dist/components/dialog/src/dialog-window.js +29 -8
- package/dist/components/drawer/index.d.ts +1 -1
- package/dist/components/drawer/src/RsDrawer.css +61 -29
- package/dist/components/drawer/src/RsDrawer.d.ts +37 -21
- package/dist/components/drawer/src/RsDrawer.impl.js +441 -223
- package/dist/components/drawer/src/drawer-utils.d.ts +35 -0
- package/dist/components/drawer/src/drawer-utils.js +131 -1
- package/dist/components/dropdown/index.d.ts +1 -1
- package/dist/components/dropdown/src/RsDropdown.css +140 -61
- package/dist/components/dropdown/src/RsDropdown.d.ts +39 -6
- package/dist/components/dropdown/src/RsDropdown.impl.js +693 -63
- package/dist/components/dropdown/src/RsDropdownItemView.impl.js +17 -7
- package/dist/components/dropdown/src/RsDropdownItems.d.ts +32 -3
- package/dist/components/dropdown/src/RsDropdownItems.impl.js +171 -59
- package/dist/components/dropdown/src/dropdown-utils.d.ts +50 -0
- package/dist/components/dropdown/src/dropdown-utils.js +103 -3
- package/dist/components/empty/index.d.ts +1 -0
- package/dist/components/empty/src/RsEmpty.css +105 -23
- package/dist/components/empty/src/RsEmpty.d.ts +27 -4
- package/dist/components/empty/src/RsEmpty.impl.js +154 -11
- package/dist/components/empty/src/RsEmpty.js +2 -1
- package/dist/components/empty/src/empty-utils.d.ts +28 -0
- package/dist/components/empty/src/empty-utils.js +55 -0
- package/dist/components/form/src/RsForm.d.ts +1 -1
- package/dist/components/input-number/src/RsInputNumber.d.ts +1 -1
- package/dist/components/label/src/RsLabel.d.ts +1 -1
- package/dist/components/loading/index.d.ts +1 -0
- package/dist/components/loading/src/RsLoading.css +13 -97
- package/dist/components/loading/src/RsLoading.d.ts +52 -2
- package/dist/components/loading/src/RsLoading.impl.js +216 -33
- package/dist/components/loading/src/RsLoading.js +2 -1
- package/dist/components/loading/src/loading-status.css +210 -0
- package/dist/components/loading/src/loading-status.d.ts +34 -0
- package/dist/components/loading/src/loading-status.impl.js +84 -0
- package/dist/components/loading/src/loading-status.js +8 -0
- package/dist/components/loading/src/loading-utils.d.ts +51 -4
- package/dist/components/loading/src/loading-utils.js +122 -0
- package/dist/components/loading-bar/index.d.ts +1 -0
- package/dist/components/loading-bar/src/RsLoadingBar.css +72 -8
- package/dist/components/loading-bar/src/RsLoadingBar.d.ts +55 -11
- package/dist/components/loading-bar/src/RsLoadingBar.impl.js +298 -57
- package/dist/components/loading-bar/src/RsLoadingBar.js +1 -1
- package/dist/components/loading-bar/src/loading-bar-utils.d.ts +69 -0
- package/dist/components/loading-bar/src/loading-bar-utils.js +97 -0
- package/dist/components/log/src/RsLog.css +52 -144
- package/dist/components/log/src/RsLog.d.ts +12 -11
- package/dist/components/log/src/RsLog.impl.js +181 -148
- package/dist/components/log/src/RsLog.js +1 -1
- package/dist/components/log/src/RsLogRow.css +152 -0
- package/dist/components/log/src/RsLogRow.d.ts +35 -0
- package/dist/components/log/src/RsLogRow.impl.js +91 -0
- package/dist/components/log/src/RsLogRow.js +8 -0
- package/dist/components/log/src/log-utils.d.ts +8 -0
- package/dist/components/log/src/log-utils.js +71 -10
- package/dist/components/markdown/index.d.ts +1 -1
- package/dist/components/markdown/src/RsMarkdown.css +75 -32
- package/dist/components/markdown/src/RsMarkdown.d.ts +6 -2
- package/dist/components/markdown/src/RsMarkdown.impl.js +185 -17
- package/dist/components/markdown/src/markdown-utils.d.ts +26 -0
- package/dist/components/markdown/src/markdown-utils.js +114 -12
- package/dist/components/mentions/src/RsMentions.d.ts +2 -2
- package/dist/components/menu/index.d.ts +1 -1
- package/dist/components/menu/src/RsMenu.css +70 -29
- package/dist/components/menu/src/RsMenu.d.ts +58 -4
- package/dist/components/menu/src/RsMenu.impl.js +93 -46
- package/dist/components/menu/src/RsMenuItems.d.ts +22 -5
- package/dist/components/menu/src/RsMenuItems.impl.js +506 -154
- package/dist/components/menu/src/menu-utils.d.ts +56 -0
- package/dist/components/menu/src/menu-utils.js +139 -6
- package/dist/components/monaco-editor/index.d.ts +1 -1
- package/dist/components/monaco-editor/src/RsMonacoEditor.css +28 -16
- package/dist/components/monaco-editor/src/RsMonacoEditor.d.ts +39 -41
- package/dist/components/monaco-editor/src/RsMonacoEditor.impl.js +212 -133
- package/dist/components/monaco-editor/src/RsMonacoEditor.js +1 -1
- package/dist/components/monaco-editor/src/monaco-editor-utils.d.ts +126 -0
- package/dist/components/monaco-editor/src/monaco-editor-utils.js +302 -0
- package/dist/components/pagination/index.d.ts +2 -2
- package/dist/components/pagination/src/RsPagination.css +93 -46
- package/dist/components/pagination/src/RsPagination.d.ts +68 -8
- package/dist/components/pagination/src/RsPagination.impl.js +229 -86
- package/dist/components/pagination/src/RsPagination.js +1 -1
- package/dist/components/pagination/src/pagination-utils.d.ts +59 -0
- package/dist/components/pagination/src/pagination-utils.js +105 -1
- package/dist/components/popover/index.d.ts +1 -0
- package/dist/components/popover/src/RsPopover.css +124 -14
- package/dist/components/popover/src/RsPopover.d.ts +38 -7
- package/dist/components/popover/src/RsPopover.impl.js +546 -35
- package/dist/components/popover/src/RsPopover.js +2 -1
- package/dist/components/popover/src/popover-utils.d.ts +24 -2
- package/dist/components/popover/src/popover-utils.js +55 -0
- package/dist/components/sidebar/index.d.ts +1 -0
- package/dist/components/sidebar/src/RsSidebar.css +91 -33
- package/dist/components/sidebar/src/RsSidebar.d.ts +17 -9
- package/dist/components/sidebar/src/RsSidebar.impl.js +124 -22
- package/dist/components/sidebar/src/RsSidebar.js +1 -1
- package/dist/components/sidebar/src/RsSidebarGroup.css +23 -6
- package/dist/components/sidebar/src/RsSidebarGroup.d.ts +6 -2
- package/dist/components/sidebar/src/RsSidebarGroup.impl.js +17 -4
- package/dist/components/sidebar/src/RsSidebarGroup.js +1 -1
- package/dist/components/sidebar/src/RsSidebarItem.css +50 -20
- package/dist/components/sidebar/src/RsSidebarItem.d.ts +21 -3
- package/dist/components/sidebar/src/RsSidebarItem.impl.js +71 -20
- package/dist/components/sidebar/src/RsSidebarItem.js +1 -1
- package/dist/components/sidebar/src/sidebar-utils.d.ts +47 -0
- package/dist/components/sidebar/src/sidebar-utils.js +72 -0
- package/dist/components/split-pane/index.d.ts +2 -2
- package/dist/components/split-pane/src/RsSplitPane.css +41 -30
- package/dist/components/split-pane/src/RsSplitPane.d.ts +6 -2
- package/dist/components/split-pane/src/RsSplitPane.impl.js +153 -45
- package/dist/components/split-pane/src/split-pane-utils.d.ts +23 -0
- package/dist/components/split-pane/src/split-pane-utils.js +18 -1
- package/dist/components/stat-card/index.d.ts +1 -0
- package/dist/components/stat-card/src/RsStatCard.css +129 -25
- package/dist/components/stat-card/src/RsStatCard.d.ts +40 -4
- package/dist/components/stat-card/src/RsStatCard.impl.js +106 -12
- package/dist/components/stat-card/src/RsStatCard.js +1 -1
- package/dist/components/stat-card/src/stat-card-utils.d.ts +39 -0
- package/dist/components/stat-card/src/stat-card-utils.js +113 -0
- package/dist/components/steps/index.d.ts +1 -1
- package/dist/components/steps/src/RsSteps.css +158 -37
- package/dist/components/steps/src/RsSteps.d.ts +69 -5
- package/dist/components/steps/src/RsSteps.impl.js +168 -28
- package/dist/components/steps/src/RsSteps.js +1 -1
- package/dist/components/steps/src/steps-utils.d.ts +51 -1
- package/dist/components/steps/src/steps-utils.js +67 -1
- package/dist/components/table/src/RsTable.impl.js +4 -2
- package/dist/components/table/src/composables/useRsTableContextMenu.d.ts +16 -0
- package/dist/components/table/src/composables/useRsTableContextMenu.js +1 -1
- package/dist/components/table/src/composables/useRsTableEngine.js +6 -2
- package/dist/components/table/src/composables/useRsTableScrollLayout.js +2 -0
- package/dist/components/table/src/composables/useRsTableShell.d.ts +16 -0
- package/dist/components/table/src/rs-table-props.d.ts +1 -1
- package/dist/components/table/src/rs-table-props.js +0 -1
- package/dist/components/table/src/table-body/RsTableBody.impl.js +1 -0
- package/dist/components/table/src/table-body/RsTableCell.impl.js +1 -1
- package/dist/components/table/src/table-body/RsTableCellEditor.impl.js +10 -2
- package/dist/components/table/src/table-body/RsTableColGroup.impl.js +1 -0
- package/dist/components/table/src/table-footer/RsTableSummaryRow.impl.js +1 -0
- package/dist/components/table/src/table-header/RsTableHeader.impl.js +1 -0
- package/dist/components/table/src/utils/table-utils.d.ts +10 -6
- package/dist/components/table/src/utils/table-utils.js +27 -25
- package/dist/components/table/style/rs-table.css +86 -28
- package/dist/components/tabs/index.d.ts +2 -2
- package/dist/components/tabs/src/RsTabs.css +225 -101
- package/dist/components/tabs/src/RsTabs.d.ts +37 -8
- package/dist/components/tabs/src/RsTabs.impl.js +400 -270
- package/dist/components/tabs/src/tabs-utils.d.ts +41 -2
- package/dist/components/tabs/src/tabs-utils.js +55 -1
- package/dist/components/terminal/index.d.ts +1 -1
- package/dist/components/terminal/src/RsTerminal.css +60 -37
- package/dist/components/terminal/src/RsTerminal.d.ts +36 -4
- package/dist/components/terminal/src/RsTerminal.impl.js +288 -68
- package/dist/components/terminal/src/RsTerminal.js +1 -1
- package/dist/components/terminal/src/terminal-utils.d.ts +42 -4
- package/dist/components/terminal/src/terminal-utils.js +113 -10
- package/dist/components/textarea/src/RsTextarea.d.ts +1 -1
- package/dist/components/time-picker/src/RsTimePicker.d.ts +2 -2
- package/dist/components/toaster/src/RsToaster.css +156 -203
- package/dist/components/toaster/src/RsToaster.d.ts +32 -2
- package/dist/components/toaster/src/RsToaster.impl.js +309 -34
- package/dist/components/toaster/src/toast-store.d.ts +95 -0
- package/dist/components/toaster/src/toast-store.js +177 -0
- package/dist/components/toaster/src/toast-utils.d.ts +60 -0
- package/dist/components/toaster/src/toast-utils.js +86 -0
- package/dist/components/toolbar/index.d.ts +1 -1
- package/dist/components/toolbar/src/RsToolbar.css +206 -32
- package/dist/components/toolbar/src/RsToolbar.d.ts +41 -16
- package/dist/components/toolbar/src/RsToolbar.impl.js +146 -18
- package/dist/components/toolbar/src/RsToolbar.js +2 -1
- package/dist/components/toolbar/src/toolbar-utils.d.ts +20 -0
- package/dist/components/toolbar/src/toolbar-utils.js +105 -0
- package/dist/components/tooltip/index.d.ts +1 -0
- package/dist/components/tooltip/src/RsTooltip.css +104 -26
- package/dist/components/tooltip/src/RsTooltip.d.ts +38 -16
- package/dist/components/tooltip/src/RsTooltip.impl.js +420 -51
- package/dist/components/tooltip/src/RsTooltip.js +2 -1
- package/dist/components/tooltip/src/RsTooltipProvider.d.ts +4 -4
- package/dist/components/tooltip/src/RsTooltipProvider.impl.js +51 -14
- package/dist/components/tooltip/src/tooltip-utils.d.ts +30 -0
- package/dist/components/tooltip/src/tooltip-utils.js +23 -0
- package/dist/components/tree/index.d.ts +2 -2
- package/dist/components/tree/src/RsTree.css +84 -75
- package/dist/components/tree/src/RsTree.d.ts +20 -20
- package/dist/components/tree/src/RsTree.impl.js +292 -66
- package/dist/components/tree/src/RsTree.js +1 -1
- package/dist/components/tree/src/tree-utils.d.ts +22 -0
- package/dist/components/tree/src/tree-utils.js +18 -4
- package/dist/components/tree-select/src/RsTreeSelect.d.ts +1 -1
- package/dist/components/virtual-list/index.d.ts +1 -1
- package/dist/components/virtual-list/src/RsVirtualList.css +64 -9
- package/dist/components/virtual-list/src/RsVirtualList.d.ts +31 -5
- package/dist/components/virtual-list/src/RsVirtualList.impl.js +425 -76
- package/dist/components/virtual-list/src/RsVirtualList.js +1 -1
- package/dist/components/virtual-list/src/virtual-list-utils.d.ts +64 -1
- package/dist/components/virtual-list/src/virtual-list-utils.js +215 -1
- package/dist/composables/useRsLoadingBar.d.ts +2 -5
- package/dist/composables/useRsLoadingBar.js +21 -5
- package/dist/composables/useRsTabsNav.d.ts +3 -1
- package/dist/composables/useRsTabsNav.js +96 -28
- package/dist/composables/useRsToast.d.ts +11 -13
- package/dist/composables/useRsToast.js +66 -17
- package/dist/index.d.ts +30 -21
- package/dist/index.js +14 -0
- package/dist/locale/apply.js +6 -1
- package/dist/locale/messages.js +128 -2
- package/dist/styles.css +465 -808
- package/dist/theme/brand.example.css +3 -2
- package/dist/vite-plugins/niuma-ui-host.js +1 -1
- package/package.json +2 -5
- package/dist/components/_shared/src/reka.d.ts +0 -2
- package/dist/components/_shared/src/reka.js +0 -2
|
@@ -1,17 +1,47 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type RsToastPosition } from '../../_shared/src/overlay-utils';
|
|
2
2
|
type __VLS_Props = {
|
|
3
|
+
/** 渠道。同一页面只挂一个同 id 的宿主。 */
|
|
4
|
+
toasterId?: string;
|
|
3
5
|
position?: RsToastPosition;
|
|
4
6
|
closeButton?: boolean;
|
|
5
7
|
richColors?: boolean;
|
|
8
|
+
/** 为 false 时叠成一摞,悬停、焦点或快捷键展开。 */
|
|
6
9
|
expand?: boolean;
|
|
10
|
+
/** 条间距(px)。 */
|
|
7
11
|
gap?: number;
|
|
12
|
+
/** 未在单条上指定时的自动关闭毫秒。0 表示不自动关闭。 */
|
|
13
|
+
duration?: number;
|
|
14
|
+
/** 同一方位最多同时显示几条。 */
|
|
15
|
+
visibleToasts?: number;
|
|
16
|
+
/** 离视口边缘的距离(px)。未传走 --rs-space-lg,并让出安全区。 */
|
|
17
|
+
offset?: number;
|
|
18
|
+
/** 滑动关闭。 */
|
|
19
|
+
swipe?: boolean;
|
|
20
|
+
/** 悬停或焦点暂停倒计时。 */
|
|
21
|
+
pauseOnHover?: boolean;
|
|
22
|
+
/** 例如 alt+t。空字符串关闭。按下后展开并聚焦通知区。 */
|
|
23
|
+
hotkey?: string;
|
|
24
|
+
/** 覆盖 toaster.region。 */
|
|
25
|
+
ariaLabel?: string;
|
|
26
|
+
teleportTo?: string | HTMLElement;
|
|
27
|
+
id?: string;
|
|
8
28
|
};
|
|
9
|
-
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
|
|
29
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
|
|
30
|
+
/** 供模板 ref 关闭。业务侧通常用 useRsToast().dismiss。 */
|
|
31
|
+
dismiss: (id?: string) => void;
|
|
32
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
10
33
|
gap: number;
|
|
11
34
|
expand: boolean;
|
|
12
35
|
position: RsToastPosition;
|
|
36
|
+
teleportTo: string | HTMLElement;
|
|
37
|
+
toasterId: string;
|
|
38
|
+
duration: number;
|
|
13
39
|
closeButton: boolean;
|
|
14
40
|
richColors: boolean;
|
|
41
|
+
visibleToasts: number;
|
|
42
|
+
swipe: boolean;
|
|
43
|
+
pauseOnHover: boolean;
|
|
44
|
+
hotkey: string;
|
|
15
45
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
16
46
|
declare const _default: typeof __VLS_export;
|
|
17
47
|
export default _default;
|
|
@@ -1,12 +1,65 @@
|
|
|
1
1
|
import { readResolvedTheme } from "../../../theme/apply.js";
|
|
2
2
|
import { rsConfigKey } from "../../../composables/useRsConfig.js";
|
|
3
|
+
import { resolveDirMode } from "../../../locale/apply.js";
|
|
4
|
+
import { useRsI18n } from "../../../composables/useRsI18n.js";
|
|
5
|
+
import RsIcon_default from "../../icon/src/RsIcon.js";
|
|
3
6
|
import { RS_TOAST_DEFAULT_POSITION } from "../../_shared/src/overlay-utils.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
7
|
+
import { RS_TOAST_DEFAULT_DURATION, clampToastGap, clampVisibleToasts, isToastTypingTarget, matchToastHotkey, resolveToastPosition, toastAriaLive, toastIconName, toastLiveRole } from "./toast-utils.js";
|
|
8
|
+
import { dismissRsToast, pauseRsToast, releaseRsToasterHost, resumeRsToast, rsToasts, syncRsToasterHost } from "./toast-store.js";
|
|
9
|
+
import { Fragment, Teleport, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, inject, normalizeClass, normalizeStyle, onUnmounted, openBlock, ref, renderList, toDisplayString, unref, watch } from "vue";
|
|
6
10
|
//#region src/components/toaster/src/RsToaster.vue?vue&type=script&setup=true&lang.ts
|
|
11
|
+
var _hoisted_1 = [
|
|
12
|
+
"id",
|
|
13
|
+
"aria-label",
|
|
14
|
+
"data-position",
|
|
15
|
+
"data-rs-theme",
|
|
16
|
+
"data-rs-dir",
|
|
17
|
+
"dir",
|
|
18
|
+
"lang"
|
|
19
|
+
];
|
|
20
|
+
var _hoisted_2 = [
|
|
21
|
+
"data-position",
|
|
22
|
+
"onMouseenter",
|
|
23
|
+
"onMouseleave",
|
|
24
|
+
"onFocusin",
|
|
25
|
+
"onFocusout"
|
|
26
|
+
];
|
|
27
|
+
var _hoisted_3 = [
|
|
28
|
+
"id",
|
|
29
|
+
"role",
|
|
30
|
+
"aria-live",
|
|
31
|
+
"data-type",
|
|
32
|
+
"data-visible",
|
|
33
|
+
"onKeydown",
|
|
34
|
+
"onPointerdown",
|
|
35
|
+
"onPointermove",
|
|
36
|
+
"onPointerup",
|
|
37
|
+
"onPointercancel"
|
|
38
|
+
];
|
|
39
|
+
var _hoisted_4 = {
|
|
40
|
+
class: "rs-toast__icon",
|
|
41
|
+
"data-icon": "",
|
|
42
|
+
"aria-hidden": "true"
|
|
43
|
+
};
|
|
44
|
+
var _hoisted_5 = {
|
|
45
|
+
class: "rs-toast__body",
|
|
46
|
+
"data-content": ""
|
|
47
|
+
};
|
|
48
|
+
var _hoisted_6 = ["id"];
|
|
49
|
+
var _hoisted_7 = ["id"];
|
|
50
|
+
var _hoisted_8 = {
|
|
51
|
+
key: 1,
|
|
52
|
+
class: "rs-toast__actions",
|
|
53
|
+
"data-button": ""
|
|
54
|
+
};
|
|
55
|
+
var _hoisted_9 = ["onClick"];
|
|
56
|
+
var _hoisted_10 = ["onClick"];
|
|
57
|
+
var _hoisted_11 = ["aria-label", "onClick"];
|
|
7
58
|
var RsToaster_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
59
|
+
name: "RsToaster",
|
|
8
60
|
__name: "RsToaster",
|
|
9
61
|
props: {
|
|
62
|
+
toasterId: { default: "default" },
|
|
10
63
|
position: { default: RS_TOAST_DEFAULT_POSITION },
|
|
11
64
|
closeButton: {
|
|
12
65
|
type: Boolean,
|
|
@@ -20,43 +73,265 @@ var RsToaster_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
20
73
|
type: Boolean,
|
|
21
74
|
default: true
|
|
22
75
|
},
|
|
23
|
-
gap: { default: 4 }
|
|
76
|
+
gap: { default: 4 },
|
|
77
|
+
duration: { default: RS_TOAST_DEFAULT_DURATION },
|
|
78
|
+
visibleToasts: { default: 3 },
|
|
79
|
+
offset: {},
|
|
80
|
+
swipe: {
|
|
81
|
+
type: Boolean,
|
|
82
|
+
default: true
|
|
83
|
+
},
|
|
84
|
+
pauseOnHover: {
|
|
85
|
+
type: Boolean,
|
|
86
|
+
default: true
|
|
87
|
+
},
|
|
88
|
+
hotkey: { default: "alt+t" },
|
|
89
|
+
ariaLabel: {},
|
|
90
|
+
teleportTo: { default: "body" },
|
|
91
|
+
id: {}
|
|
24
92
|
},
|
|
25
|
-
setup(__props) {
|
|
93
|
+
setup(__props, { expose: __expose }) {
|
|
94
|
+
const props = __props;
|
|
95
|
+
const { t, locale } = useRsI18n();
|
|
26
96
|
const config = inject(rsConfigKey, null);
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
97
|
+
const regionRef = ref(null);
|
|
98
|
+
const hotkeyExpanded = ref(false);
|
|
99
|
+
const openStack = ref(null);
|
|
100
|
+
const hostToken = Symbol("rs-toaster");
|
|
101
|
+
const swipes = /* @__PURE__ */ new Map();
|
|
102
|
+
const theme = computed(() => config?.resolvedTheme.value ?? readResolvedTheme());
|
|
103
|
+
const textDir = computed(() => {
|
|
104
|
+
if (config) return resolveDirMode(config.dir.value, config.locale.value);
|
|
105
|
+
if (typeof document === "undefined") return "ltr";
|
|
106
|
+
return document.documentElement.getAttribute("dir") === "rtl" ? "rtl" : "ltr";
|
|
107
|
+
});
|
|
108
|
+
const regionLabel = computed(() => props.ariaLabel || t("toaster.region"));
|
|
109
|
+
const closeLabel = computed(() => t("toaster.close"));
|
|
110
|
+
const visibleLimit = computed(() => clampVisibleToasts(props.visibleToasts));
|
|
111
|
+
const gapPx = computed(() => clampToastGap(props.gap));
|
|
112
|
+
const rootStyle = computed(() => {
|
|
113
|
+
const style = { "--rs-toaster-gap": `${gapPx.value}px` };
|
|
114
|
+
if (props.offset != null && Number.isFinite(props.offset) && props.offset >= 0) style["--rs-toaster-offset"] = `${props.offset}px`;
|
|
115
|
+
return style;
|
|
116
|
+
});
|
|
117
|
+
const groups = computed(() => {
|
|
118
|
+
const map = /* @__PURE__ */ new Map();
|
|
119
|
+
for (const item of rsToasts.value) {
|
|
120
|
+
if (item.toasterId !== props.toasterId) continue;
|
|
121
|
+
const position = resolveToastPosition(item.position, props.position);
|
|
122
|
+
const list = map.get(position);
|
|
123
|
+
if (list) list.push(item);
|
|
124
|
+
else map.set(position, [item]);
|
|
125
|
+
}
|
|
126
|
+
return [...map.entries()].map(([position, items]) => ({
|
|
127
|
+
position,
|
|
128
|
+
items: items.slice(0, visibleLimit.value)
|
|
129
|
+
}));
|
|
130
|
+
});
|
|
131
|
+
watch(() => ({
|
|
132
|
+
toasterId: props.toasterId,
|
|
133
|
+
position: props.position,
|
|
134
|
+
duration: props.duration,
|
|
135
|
+
closeButton: props.closeButton,
|
|
136
|
+
richColors: props.richColors
|
|
137
|
+
}), (options, _, onCleanup) => {
|
|
138
|
+
syncRsToasterHost(options.toasterId, hostToken, {
|
|
139
|
+
position: options.position,
|
|
140
|
+
duration: options.duration,
|
|
141
|
+
closeButton: options.closeButton,
|
|
142
|
+
richColors: options.richColors
|
|
143
|
+
});
|
|
144
|
+
onCleanup(() => releaseRsToasterHost(options.toasterId, hostToken));
|
|
145
|
+
}, { immediate: true });
|
|
146
|
+
watch(() => props.hotkey, (spec, _, onCleanup) => {
|
|
147
|
+
if (!spec || typeof window === "undefined") return;
|
|
148
|
+
const onKey = (event) => {
|
|
149
|
+
if (!matchToastHotkey(event, spec) || isToastTypingTarget(event.target)) return;
|
|
150
|
+
hotkeyExpanded.value = true;
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
regionRef.value?.focus();
|
|
153
|
+
};
|
|
154
|
+
window.addEventListener("keydown", onKey);
|
|
155
|
+
onCleanup(() => window.removeEventListener("keydown", onKey));
|
|
156
|
+
}, { immediate: true });
|
|
157
|
+
onUnmounted(() => {
|
|
158
|
+
for (const swipe of swipes.values()) swipe.el.style.transform = "";
|
|
159
|
+
swipes.clear();
|
|
30
160
|
});
|
|
161
|
+
function stackExpanded(position) {
|
|
162
|
+
return props.expand || hotkeyExpanded.value || openStack.value === position;
|
|
163
|
+
}
|
|
164
|
+
function idsIn(position) {
|
|
165
|
+
return groups.value.find((group) => group.position === position)?.items.map((item) => item.id) ?? [];
|
|
166
|
+
}
|
|
167
|
+
function hold(position) {
|
|
168
|
+
openStack.value = position;
|
|
169
|
+
if (!props.pauseOnHover) return;
|
|
170
|
+
for (const id of idsIn(position)) pauseRsToast(id, "hover");
|
|
171
|
+
}
|
|
172
|
+
function release(position) {
|
|
173
|
+
if (openStack.value === position) openStack.value = null;
|
|
174
|
+
hotkeyExpanded.value = false;
|
|
175
|
+
if (!props.pauseOnHover) return;
|
|
176
|
+
for (const id of idsIn(position)) resumeRsToast(id, "hover");
|
|
177
|
+
}
|
|
178
|
+
function onFocusOut(event, position) {
|
|
179
|
+
const next = event.relatedTarget;
|
|
180
|
+
const current = event.currentTarget;
|
|
181
|
+
if (next instanceof Node && current instanceof Node && current.contains(next)) return;
|
|
182
|
+
release(position);
|
|
183
|
+
}
|
|
184
|
+
function showClose(item) {
|
|
185
|
+
return item.closeButton && item.dismissible;
|
|
186
|
+
}
|
|
187
|
+
function onClose(item) {
|
|
188
|
+
if (!item.dismissible) return;
|
|
189
|
+
dismissRsToast(item.id);
|
|
190
|
+
}
|
|
191
|
+
function onAction(event, item, kind) {
|
|
192
|
+
const button = kind === "action" ? item.action : item.cancel;
|
|
193
|
+
try {
|
|
194
|
+
button?.onClick?.(event);
|
|
195
|
+
} finally {
|
|
196
|
+
if (item.dismissible) dismissRsToast(item.id);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function onToastKeydown(event, item) {
|
|
200
|
+
if (event.key !== "Escape" || !item.dismissible) return;
|
|
201
|
+
event.stopPropagation();
|
|
202
|
+
dismissRsToast(item.id);
|
|
203
|
+
}
|
|
204
|
+
function onPointerDown(event, item) {
|
|
205
|
+
if (!props.swipe || !item.dismissible || event.button !== 0) return;
|
|
206
|
+
const target = event.target;
|
|
207
|
+
if (target instanceof Element && target.closest("button, a")) return;
|
|
208
|
+
const el = event.currentTarget;
|
|
209
|
+
if (!(el instanceof HTMLElement)) return;
|
|
210
|
+
swipes.set(item.id, {
|
|
211
|
+
x: event.clientX,
|
|
212
|
+
y: event.clientY,
|
|
213
|
+
el
|
|
214
|
+
});
|
|
215
|
+
try {
|
|
216
|
+
el.setPointerCapture(event.pointerId);
|
|
217
|
+
} catch {}
|
|
218
|
+
el.style.willChange = "transform";
|
|
219
|
+
}
|
|
220
|
+
function onPointerMove(event, item) {
|
|
221
|
+
const swipe = swipes.get(item.id);
|
|
222
|
+
if (!swipe) return;
|
|
223
|
+
const dx = event.clientX - swipe.x;
|
|
224
|
+
const dy = event.clientY - swipe.y;
|
|
225
|
+
swipe.el.style.transform = `translate3d(${dx}px, ${dy}px, 0)`;
|
|
226
|
+
}
|
|
227
|
+
function endSwipe(item, dismiss) {
|
|
228
|
+
const swipe = swipes.get(item.id);
|
|
229
|
+
if (!swipe) return;
|
|
230
|
+
swipe.el.style.transform = "";
|
|
231
|
+
swipe.el.style.willChange = "";
|
|
232
|
+
swipes.delete(item.id);
|
|
233
|
+
if (dismiss && item.dismissible) dismissRsToast(item.id);
|
|
234
|
+
}
|
|
235
|
+
function onPointerUp(event, item) {
|
|
236
|
+
const swipe = swipes.get(item.id);
|
|
237
|
+
if (!swipe) return;
|
|
238
|
+
const dx = event.clientX - swipe.x;
|
|
239
|
+
const dy = event.clientY - swipe.y;
|
|
240
|
+
endSwipe(item, Math.hypot(dx, dy) >= 72);
|
|
241
|
+
}
|
|
242
|
+
function onPointerCancel(_event, item) {
|
|
243
|
+
endSwipe(item, false);
|
|
244
|
+
}
|
|
245
|
+
__expose({
|
|
246
|
+
/** 供模板 ref 关闭。业务侧通常用 useRsToast().dismiss。 */
|
|
247
|
+
dismiss: (id) => dismissRsToast(id) });
|
|
31
248
|
return (_ctx, _cache) => {
|
|
32
|
-
return openBlock(), createBlock(Teleport, { to:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
expand: __props.expand,
|
|
37
|
-
gap: __props.gap,
|
|
38
|
-
"close-button-position": "top-right",
|
|
39
|
-
"rich-colors": __props.richColors,
|
|
249
|
+
return openBlock(), createBlock(Teleport, { to: __props.teleportTo }, [createElementVNode("div", {
|
|
250
|
+
id: __props.id,
|
|
251
|
+
ref_key: "regionRef",
|
|
252
|
+
ref: regionRef,
|
|
40
253
|
class: "rs-toaster",
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
254
|
+
style: normalizeStyle(rootStyle.value),
|
|
255
|
+
role: "region",
|
|
256
|
+
tabindex: "-1",
|
|
257
|
+
"aria-label": regionLabel.value,
|
|
258
|
+
"data-position": __props.position,
|
|
259
|
+
"data-rs-theme": theme.value,
|
|
260
|
+
"data-rs-dir": textDir.value,
|
|
261
|
+
dir: textDir.value,
|
|
262
|
+
lang: unref(locale)
|
|
263
|
+
}, [(openBlock(true), createElementBlock(Fragment, null, renderList(groups.value, (group) => {
|
|
264
|
+
return openBlock(), createElementBlock("ol", {
|
|
265
|
+
key: group.position,
|
|
266
|
+
class: normalizeClass(["rs-toaster__viewport", [`rs-toaster__viewport--${group.position}`, { "rs-toaster__viewport--collapsed": !stackExpanded(group.position) }]]),
|
|
267
|
+
"data-position": group.position,
|
|
268
|
+
onMouseenter: ($event) => hold(group.position),
|
|
269
|
+
onMouseleave: ($event) => release(group.position),
|
|
270
|
+
onFocusin: ($event) => hold(group.position),
|
|
271
|
+
onFocusout: ($event) => onFocusOut($event, group.position)
|
|
272
|
+
}, [(openBlock(true), createElementBlock(Fragment, null, renderList(group.items, (item, index) => {
|
|
273
|
+
return openBlock(), createElementBlock("li", {
|
|
274
|
+
id: item.id,
|
|
275
|
+
key: item.id,
|
|
276
|
+
class: normalizeClass(["rs-toast", [`rs-toast--${item.type}`, {
|
|
277
|
+
"rs-toast--rich": item.richColors,
|
|
278
|
+
"rs-toast--leaving": item.leaving,
|
|
279
|
+
"rs-toast--front": index === 0
|
|
280
|
+
}]]),
|
|
281
|
+
style: normalizeStyle({ "--rs-toast-index": String(index) }),
|
|
282
|
+
role: unref(toastLiveRole)(item.type),
|
|
283
|
+
"aria-live": unref(toastAriaLive)(item.type),
|
|
284
|
+
"aria-atomic": "true",
|
|
285
|
+
"data-type": item.type,
|
|
286
|
+
"data-visible": item.leaving ? "false" : "true",
|
|
287
|
+
onKeydown: ($event) => onToastKeydown($event, item),
|
|
288
|
+
onPointerdown: ($event) => onPointerDown($event, item),
|
|
289
|
+
onPointermove: ($event) => onPointerMove($event, item),
|
|
290
|
+
onPointerup: ($event) => onPointerUp($event, item),
|
|
291
|
+
onPointercancel: ($event) => onPointerCancel($event, item)
|
|
292
|
+
}, [
|
|
293
|
+
createElementVNode("span", _hoisted_4, [createVNode(RsIcon_default, {
|
|
294
|
+
name: unref(toastIconName)(item.type),
|
|
295
|
+
size: 20,
|
|
296
|
+
spin: item.type === "loading"
|
|
297
|
+
}, null, 8, ["name", "spin"])]),
|
|
298
|
+
createElementVNode("div", _hoisted_5, [
|
|
299
|
+
createElementVNode("p", {
|
|
300
|
+
id: `${item.id}-title`,
|
|
301
|
+
class: "rs-toast__title"
|
|
302
|
+
}, toDisplayString(item.title), 9, _hoisted_6),
|
|
303
|
+
item.description ? (openBlock(), createElementBlock("p", {
|
|
304
|
+
key: 0,
|
|
305
|
+
id: `${item.id}-desc`,
|
|
306
|
+
class: "rs-toast__description",
|
|
307
|
+
"data-description": ""
|
|
308
|
+
}, toDisplayString(item.description), 9, _hoisted_7)) : createCommentVNode("", true),
|
|
309
|
+
item.action || item.cancel ? (openBlock(), createElementBlock("div", _hoisted_8, [item.action ? (openBlock(), createElementBlock("button", {
|
|
310
|
+
key: 0,
|
|
311
|
+
type: "button",
|
|
312
|
+
class: "rs-toast__action",
|
|
313
|
+
onClick: ($event) => onAction($event, item, "action")
|
|
314
|
+
}, toDisplayString(item.action.label), 9, _hoisted_9)) : createCommentVNode("", true), item.cancel ? (openBlock(), createElementBlock("button", {
|
|
315
|
+
key: 1,
|
|
316
|
+
type: "button",
|
|
317
|
+
class: "rs-toast__action rs-toast__action--secondary",
|
|
318
|
+
onClick: ($event) => onAction($event, item, "cancel")
|
|
319
|
+
}, toDisplayString(item.cancel.label), 9, _hoisted_10)) : createCommentVNode("", true)])) : createCommentVNode("", true)
|
|
320
|
+
]),
|
|
321
|
+
showClose(item) ? (openBlock(), createElementBlock("button", {
|
|
322
|
+
key: 0,
|
|
323
|
+
type: "button",
|
|
324
|
+
class: "rs-toast__close",
|
|
325
|
+
"data-close-button": "",
|
|
326
|
+
"aria-label": closeLabel.value,
|
|
327
|
+
onClick: ($event) => onClose(item)
|
|
328
|
+
}, [createVNode(RsIcon_default, {
|
|
329
|
+
name: "x",
|
|
330
|
+
size: 12
|
|
331
|
+
})], 8, _hoisted_11)) : createCommentVNode("", true)
|
|
332
|
+
], 46, _hoisted_3);
|
|
333
|
+
}), 128))], 42, _hoisted_2);
|
|
334
|
+
}), 128))], 12, _hoisted_1)], 8, ["to"]);
|
|
60
335
|
};
|
|
61
336
|
}
|
|
62
337
|
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { type RsToastPosition } from '../../_shared/src/overlay-utils';
|
|
2
|
+
import { type RsToastAction, type RsToastKind } from './toast-utils';
|
|
3
|
+
export interface RsToastRecord {
|
|
4
|
+
id: string;
|
|
5
|
+
toasterId: string;
|
|
6
|
+
type: RsToastKind;
|
|
7
|
+
title: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
position?: RsToastPosition;
|
|
10
|
+
duration: number;
|
|
11
|
+
dismissible: boolean;
|
|
12
|
+
closeButton: boolean;
|
|
13
|
+
richColors: boolean;
|
|
14
|
+
action?: RsToastAction;
|
|
15
|
+
cancel?: RsToastAction;
|
|
16
|
+
onDismiss?: (id: string) => void;
|
|
17
|
+
onAutoClose?: (id: string) => void;
|
|
18
|
+
leaving: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface RsToasterHostOptions {
|
|
21
|
+
position: RsToastPosition;
|
|
22
|
+
duration: number;
|
|
23
|
+
closeButton: boolean;
|
|
24
|
+
richColors: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface RsToastCreate {
|
|
27
|
+
type: RsToastKind;
|
|
28
|
+
title: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
position?: RsToastPosition;
|
|
31
|
+
duration?: number;
|
|
32
|
+
id?: string;
|
|
33
|
+
toasterId?: string;
|
|
34
|
+
dismissible?: boolean;
|
|
35
|
+
closeButton?: boolean;
|
|
36
|
+
richColors?: boolean;
|
|
37
|
+
action?: RsToastAction;
|
|
38
|
+
cancel?: RsToastAction;
|
|
39
|
+
onDismiss?: (id: string) => void;
|
|
40
|
+
onAutoClose?: (id: string) => void;
|
|
41
|
+
}
|
|
42
|
+
export declare const rsToasts: import("vue").Ref<{
|
|
43
|
+
id: string;
|
|
44
|
+
toasterId: string;
|
|
45
|
+
type: RsToastKind;
|
|
46
|
+
title: string;
|
|
47
|
+
description?: string | undefined;
|
|
48
|
+
position?: RsToastPosition | undefined;
|
|
49
|
+
duration: number;
|
|
50
|
+
dismissible: boolean;
|
|
51
|
+
closeButton: boolean;
|
|
52
|
+
richColors: boolean;
|
|
53
|
+
action?: {
|
|
54
|
+
label: string;
|
|
55
|
+
onClick?: ((event: MouseEvent) => void) | undefined;
|
|
56
|
+
} | undefined;
|
|
57
|
+
cancel?: {
|
|
58
|
+
label: string;
|
|
59
|
+
onClick?: ((event: MouseEvent) => void) | undefined;
|
|
60
|
+
} | undefined;
|
|
61
|
+
onDismiss?: ((id: string) => void) | undefined;
|
|
62
|
+
onAutoClose?: ((id: string) => void) | undefined;
|
|
63
|
+
leaving: boolean;
|
|
64
|
+
}[], RsToastRecord[] | {
|
|
65
|
+
id: string;
|
|
66
|
+
toasterId: string;
|
|
67
|
+
type: RsToastKind;
|
|
68
|
+
title: string;
|
|
69
|
+
description?: string | undefined;
|
|
70
|
+
position?: RsToastPosition | undefined;
|
|
71
|
+
duration: number;
|
|
72
|
+
dismissible: boolean;
|
|
73
|
+
closeButton: boolean;
|
|
74
|
+
richColors: boolean;
|
|
75
|
+
action?: {
|
|
76
|
+
label: string;
|
|
77
|
+
onClick?: ((event: MouseEvent) => void) | undefined;
|
|
78
|
+
} | undefined;
|
|
79
|
+
cancel?: {
|
|
80
|
+
label: string;
|
|
81
|
+
onClick?: ((event: MouseEvent) => void) | undefined;
|
|
82
|
+
} | undefined;
|
|
83
|
+
onDismiss?: ((id: string) => void) | undefined;
|
|
84
|
+
onAutoClose?: ((id: string) => void) | undefined;
|
|
85
|
+
leaving: boolean;
|
|
86
|
+
}[]>;
|
|
87
|
+
export declare function syncRsToasterHost(id: string, token: symbol, options: RsToasterHostOptions): void;
|
|
88
|
+
export declare function releaseRsToasterHost(id: string, token: symbol): void;
|
|
89
|
+
export declare function readRsToasterHost(id: string): RsToasterHostOptions;
|
|
90
|
+
export declare function pauseRsToast(id: string, reason: string): void;
|
|
91
|
+
export declare function resumeRsToast(id: string, reason: string): void;
|
|
92
|
+
export declare function pushRsToast(input: RsToastCreate): string;
|
|
93
|
+
export declare function dismissRsToast(id?: string): void;
|
|
94
|
+
/** 测试收尾:清定时器、摘 visibility、清空队列。不拆已挂载宿主的配置。 */
|
|
95
|
+
export declare function resetRsToastStore(): void;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { RS_TOAST_DEFAULT_POSITION } from "../../_shared/src/overlay-utils.js";
|
|
2
|
+
import { RS_TOAST_DEFAULT_DURATION, resolveRsToastDuration, shouldArmToastTimer, toastLeaveDelay, trimToastList } from "./toast-utils.js";
|
|
3
|
+
import { ref } from "vue";
|
|
4
|
+
//#region src/components/toaster/src/toast-store.ts
|
|
5
|
+
var DEFAULT_HOST = {
|
|
6
|
+
position: RS_TOAST_DEFAULT_POSITION,
|
|
7
|
+
duration: RS_TOAST_DEFAULT_DURATION,
|
|
8
|
+
closeButton: true,
|
|
9
|
+
richColors: false
|
|
10
|
+
};
|
|
11
|
+
var rsToasts = ref([]);
|
|
12
|
+
var hosts = /* @__PURE__ */ new Map();
|
|
13
|
+
var timers = /* @__PURE__ */ new Map();
|
|
14
|
+
var leaveTimers = /* @__PURE__ */ new Map();
|
|
15
|
+
var seq = 0;
|
|
16
|
+
var visibilityBound = false;
|
|
17
|
+
function syncRsToasterHost(id, token, options) {
|
|
18
|
+
hosts.set(id, {
|
|
19
|
+
token,
|
|
20
|
+
options
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function releaseRsToasterHost(id, token) {
|
|
24
|
+
if (hosts.get(id)?.token === token) hosts.delete(id);
|
|
25
|
+
}
|
|
26
|
+
function readRsToasterHost(id) {
|
|
27
|
+
return hosts.get(id)?.options ?? DEFAULT_HOST;
|
|
28
|
+
}
|
|
29
|
+
function nextId() {
|
|
30
|
+
seq += 1;
|
|
31
|
+
return `rs-toast-${seq}`;
|
|
32
|
+
}
|
|
33
|
+
function callListener(fn, id) {
|
|
34
|
+
if (!fn) return;
|
|
35
|
+
try {
|
|
36
|
+
fn(id);
|
|
37
|
+
} catch {}
|
|
38
|
+
}
|
|
39
|
+
function clearTimer(id) {
|
|
40
|
+
const state = timers.get(id);
|
|
41
|
+
if (state?.timeout) clearTimeout(state.timeout);
|
|
42
|
+
timers.delete(id);
|
|
43
|
+
}
|
|
44
|
+
function clearLeave(id) {
|
|
45
|
+
const timeout = leaveTimers.get(id);
|
|
46
|
+
if (timeout) clearTimeout(timeout);
|
|
47
|
+
leaveTimers.delete(id);
|
|
48
|
+
}
|
|
49
|
+
function syncVisibility() {
|
|
50
|
+
if (typeof document === "undefined") return;
|
|
51
|
+
if (rsToasts.value.length > 0 && !visibilityBound) {
|
|
52
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
53
|
+
visibilityBound = true;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (rsToasts.value.length === 0 && visibilityBound) {
|
|
57
|
+
document.removeEventListener("visibilitychange", onVisibility);
|
|
58
|
+
visibilityBound = false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function onVisibility() {
|
|
62
|
+
if (typeof document === "undefined") return;
|
|
63
|
+
if (document.hidden) {
|
|
64
|
+
for (const item of rsToasts.value) pauseRsToast(item.id, "hidden");
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
for (const item of rsToasts.value) resumeRsToast(item.id, "hidden");
|
|
68
|
+
}
|
|
69
|
+
function arm(id, duration) {
|
|
70
|
+
clearTimer(id);
|
|
71
|
+
if (!shouldArmToastTimer(duration, typeof window !== "undefined")) return;
|
|
72
|
+
const state = {
|
|
73
|
+
timeout: null,
|
|
74
|
+
remaining: duration,
|
|
75
|
+
startedAt: 0,
|
|
76
|
+
reasons: /* @__PURE__ */ new Set()
|
|
77
|
+
};
|
|
78
|
+
timers.set(id, state);
|
|
79
|
+
if (typeof document !== "undefined" && document.hidden) {
|
|
80
|
+
state.reasons.add("hidden");
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
state.startedAt = Date.now();
|
|
84
|
+
state.timeout = setTimeout(() => finish(id, "auto"), duration);
|
|
85
|
+
}
|
|
86
|
+
function pauseRsToast(id, reason) {
|
|
87
|
+
const state = timers.get(id);
|
|
88
|
+
if (!state || state.reasons.has(reason)) return;
|
|
89
|
+
const wasRunning = state.reasons.size === 0 && state.timeout != null;
|
|
90
|
+
state.reasons.add(reason);
|
|
91
|
+
if (!wasRunning || !state.timeout) return;
|
|
92
|
+
clearTimeout(state.timeout);
|
|
93
|
+
state.timeout = null;
|
|
94
|
+
state.remaining = Math.max(0, state.remaining - (Date.now() - state.startedAt));
|
|
95
|
+
}
|
|
96
|
+
function resumeRsToast(id, reason) {
|
|
97
|
+
const state = timers.get(id);
|
|
98
|
+
if (!state || !state.reasons.delete(reason) || state.reasons.size > 0) return;
|
|
99
|
+
if (state.remaining <= 0) {
|
|
100
|
+
finish(id, "auto");
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
state.startedAt = Date.now();
|
|
104
|
+
state.timeout = setTimeout(() => finish(id, "auto"), state.remaining);
|
|
105
|
+
}
|
|
106
|
+
function finish(id, reason) {
|
|
107
|
+
const record = rsToasts.value.find((item) => item.id === id);
|
|
108
|
+
if (!record || record.leaving) {
|
|
109
|
+
clearTimer(id);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
clearTimer(id);
|
|
113
|
+
record.leaving = true;
|
|
114
|
+
if (reason === "auto") callListener(record.onAutoClose, id);
|
|
115
|
+
else callListener(record.onDismiss, id);
|
|
116
|
+
const delay = toastLeaveDelay();
|
|
117
|
+
const remove = () => {
|
|
118
|
+
leaveTimers.delete(id);
|
|
119
|
+
rsToasts.value = rsToasts.value.filter((item) => item.id !== id);
|
|
120
|
+
syncVisibility();
|
|
121
|
+
};
|
|
122
|
+
if (delay <= 0 || typeof window === "undefined") {
|
|
123
|
+
remove();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
leaveTimers.set(id, setTimeout(remove, delay));
|
|
127
|
+
}
|
|
128
|
+
function dropOverflow(toasterId) {
|
|
129
|
+
const owned = rsToasts.value.filter((item) => item.toasterId === toasterId);
|
|
130
|
+
const kept = new Set(trimToastList(owned, 24));
|
|
131
|
+
if (kept.size === owned.length) return;
|
|
132
|
+
for (const item of owned) {
|
|
133
|
+
if (kept.has(item)) continue;
|
|
134
|
+
clearTimer(item.id);
|
|
135
|
+
clearLeave(item.id);
|
|
136
|
+
callListener(item.onDismiss, item.id);
|
|
137
|
+
}
|
|
138
|
+
rsToasts.value = rsToasts.value.filter((item) => item.toasterId !== toasterId || kept.has(item));
|
|
139
|
+
}
|
|
140
|
+
function pushRsToast(input) {
|
|
141
|
+
const toasterId = input.toasterId || "default";
|
|
142
|
+
const host = readRsToasterHost(toasterId);
|
|
143
|
+
const id = input.id || nextId();
|
|
144
|
+
const duration = resolveRsToastDuration(input.duration, host.duration);
|
|
145
|
+
const next = {
|
|
146
|
+
id,
|
|
147
|
+
toasterId,
|
|
148
|
+
type: input.type,
|
|
149
|
+
title: input.title,
|
|
150
|
+
description: input.description,
|
|
151
|
+
position: input.position,
|
|
152
|
+
duration,
|
|
153
|
+
dismissible: input.dismissible !== false,
|
|
154
|
+
closeButton: input.closeButton ?? host.closeButton,
|
|
155
|
+
richColors: input.richColors ?? host.richColors,
|
|
156
|
+
action: input.action,
|
|
157
|
+
cancel: input.cancel,
|
|
158
|
+
onDismiss: input.onDismiss,
|
|
159
|
+
onAutoClose: input.onAutoClose,
|
|
160
|
+
leaving: false
|
|
161
|
+
};
|
|
162
|
+
clearLeave(id);
|
|
163
|
+
rsToasts.value = [next, ...rsToasts.value.filter((item) => item.id !== id)];
|
|
164
|
+
dropOverflow(toasterId);
|
|
165
|
+
if (rsToasts.value.some((item) => item.id === id)) arm(id, duration);
|
|
166
|
+
syncVisibility();
|
|
167
|
+
return id;
|
|
168
|
+
}
|
|
169
|
+
function dismissRsToast(id) {
|
|
170
|
+
if (id == null || id === "") {
|
|
171
|
+
for (const item of [...rsToasts.value]) finish(item.id, "dismiss");
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
finish(id, "dismiss");
|
|
175
|
+
}
|
|
176
|
+
//#endregion
|
|
177
|
+
export { dismissRsToast, pauseRsToast, pushRsToast, readRsToasterHost, releaseRsToasterHost, resumeRsToast, rsToasts, syncRsToasterHost };
|