@k2b/ui 0.53.0 → 0.55.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/dist/base.css +103 -0
- package/dist/browser/actions/SortableList.js +174 -0
- package/dist/browser/actions/SortableList.js.map +1 -0
- package/dist/browser/actions/Toolbar.js +186 -101
- package/dist/browser/actions/Toolbar.js.map +1 -1
- package/dist/browser/actions/drag-and-drop.js +2 -1
- package/dist/browser/actions/drag-and-drop.js.map +1 -1
- package/dist/browser/actions/index.js +1 -0
- package/dist/browser/actions/index.js.map +1 -1
- package/dist/browser/actions/sortable-list-messages.js +35 -0
- package/dist/browser/actions/sortable-list-messages.js.map +1 -0
- package/dist/browser/chart-inspection.js +2 -1
- package/dist/browser/chart-inspection.js.map +1 -1
- package/dist/browser/charts/core/balance-flow-data.js +93 -0
- package/dist/browser/charts/core/balance-flow-data.js.map +1 -0
- package/dist/browser/charts/core/balance-flow-fields.js +19 -0
- package/dist/browser/charts/core/balance-flow-fields.js.map +1 -0
- package/dist/browser/charts/core/balance-flow-frame.js +44 -0
- package/dist/browser/charts/core/balance-flow-frame.js.map +1 -0
- package/dist/browser/charts/core/balance-flow-messages.js +49 -0
- package/dist/browser/charts/core/balance-flow-messages.js.map +1 -0
- package/dist/browser/charts/core/balance-flow-size.js +42 -0
- package/dist/browser/charts/core/balance-flow-size.js.map +1 -0
- package/dist/browser/charts/core/balance-flow.js +195 -0
- package/dist/browser/charts/core/balance-flow.js.map +1 -0
- package/dist/browser/charts/core/calendar-layout.js +105 -0
- package/dist/browser/charts/core/calendar-layout.js.map +1 -0
- package/dist/browser/charts/core/calendar.js +2 -104
- package/dist/browser/charts/core/calendar.js.map +1 -1
- package/dist/browser/charts/core/index.js +9 -1
- package/dist/browser/charts/core/index.js.map +1 -1
- package/dist/browser/charts/core/inspection.js +2 -1
- package/dist/browser/charts/core/inspection.js.map +1 -1
- package/dist/browser/charts/core/number-format.js +53 -0
- package/dist/browser/charts/core/number-format.js.map +1 -0
- package/dist/browser/charts/core/registry.js +3 -1
- package/dist/browser/charts/core/registry.js.map +1 -1
- package/dist/browser/charts/core/render-size.js +2 -0
- package/dist/browser/charts/core/render-size.js.map +1 -1
- package/dist/browser/charts/core/render.js +8 -1
- package/dist/browser/charts/core/render.js.map +1 -1
- package/dist/browser/charts/core/snapshot.js +3 -3
- package/dist/browser/charts/core/snapshot.js.map +1 -1
- package/dist/browser/charts/core/types.js.map +1 -1
- package/dist/browser/charts/description.js.map +1 -1
- package/dist/browser/charts.js +2 -0
- package/dist/browser/charts.js.map +1 -1
- package/dist/browser/content/Chart.js +3 -1
- package/dist/browser/content/Chart.js.map +1 -1
- package/dist/browser/content/ChartBalanceFlow.js +90 -0
- package/dist/browser/content/ChartBalanceFlow.js.map +1 -0
- package/dist/browser/content/ChartExplorer.js +1 -1
- package/dist/browser/content/ChartExplorer.js.map +1 -1
- package/dist/browser/content/ChartRoot.js +1 -1
- package/dist/browser/content/ChartRoot.js.map +1 -1
- package/dist/browser/content/DataTable.js +212 -261
- package/dist/browser/content/DataTable.js.map +1 -1
- package/dist/browser/content/FileView.js +70 -99
- package/dist/browser/content/FileView.js.map +1 -1
- package/dist/browser/content/LoadMore.js +185 -0
- package/dist/browser/content/LoadMore.js.map +1 -0
- package/dist/browser/content/MapDialog.js +686 -0
- package/dist/browser/content/MapDialog.js.map +1 -0
- package/dist/browser/content/MapTile.js +139 -0
- package/dist/browser/content/MapTile.js.map +1 -0
- package/dist/browser/content/MapView.js +19 -8
- package/dist/browser/content/MapView.js.map +1 -1
- package/dist/browser/content/PdfPages.js +638 -0
- package/dist/browser/content/PdfPages.js.map +1 -0
- package/dist/browser/content/PdfViewer.js +264 -553
- package/dist/browser/content/PdfViewer.js.map +1 -1
- package/dist/browser/content/VirtualFeed.js +379 -89
- package/dist/browser/content/VirtualFeed.js.map +1 -1
- package/dist/browser/content/chart-balance-flow-controller.js +184 -0
- package/dist/browser/content/chart-balance-flow-controller.js.map +1 -0
- package/dist/browser/content/chart-balance-flow.js +6 -0
- package/dist/browser/content/chart-balance-flow.js.map +1 -0
- package/dist/browser/content/chart-inspection-core.js +1 -73
- package/dist/browser/content/chart-inspection-core.js.map +1 -1
- package/dist/browser/content/chart-inspection-mount.js +75 -0
- package/dist/browser/content/chart-inspection-mount.js.map +1 -0
- package/dist/browser/content/chart-svg.js +1 -1
- package/dist/browser/content/chart-svg.js.map +1 -1
- package/dist/browser/content/feed-messages.js +22 -2
- package/dist/browser/content/feed-messages.js.map +1 -1
- package/dist/browser/content/index.js +4 -1
- package/dist/browser/content/index.js.map +1 -1
- package/dist/browser/content/map-dialog-messages.js +47 -0
- package/dist/browser/content/map-dialog-messages.js.map +1 -0
- package/dist/browser/content/map-navigation.js +15 -0
- package/dist/browser/content/map-navigation.js.map +1 -0
- package/dist/browser/content/map-view-messages.js +4 -0
- package/dist/browser/content/map-view-messages.js.map +1 -1
- package/dist/browser/content/map-view-types.js.map +1 -1
- package/dist/browser/content/pdf-messages.js +8 -8
- package/dist/browser/content/pdf-messages.js.map +1 -1
- package/dist/browser/feedback/dialog-core.js +22 -10
- package/dist/browser/feedback/dialog-core.js.map +1 -1
- package/dist/browser/feedback/index.js.map +1 -1
- package/dist/browser/feedback/prompt-confirm.js +25 -14
- package/dist/browser/feedback/prompt-confirm.js.map +1 -1
- package/dist/browser/feedback/prompts.js +46 -38
- package/dist/browser/feedback/prompts.js.map +1 -1
- package/dist/browser/feedback/success-check.js +60 -0
- package/dist/browser/feedback/success-check.js.map +1 -0
- package/dist/browser/feedback/toast-hit.js +16 -0
- package/dist/browser/feedback/toast-hit.js.map +1 -0
- package/dist/browser/feedback/toast-messages.js +6 -2
- package/dist/browser/feedback/toast-messages.js.map +1 -1
- package/dist/browser/feedback/toast.js +609 -98
- package/dist/browser/feedback/toast.js.map +1 -1
- package/dist/browser/intl/messages.js +4 -0
- package/dist/browser/intl/messages.js.map +1 -1
- package/dist/browser/layout/AppWorkspace.js +58 -21
- package/dist/browser/layout/AppWorkspace.js.map +1 -1
- package/dist/browser/layout/BottomSheet.js +58 -40
- package/dist/browser/layout/BottomSheet.js.map +1 -1
- package/dist/browser/layout/Breadcrumbs.js +97 -0
- package/dist/browser/layout/Breadcrumbs.js.map +1 -0
- package/dist/browser/layout/DetailPanel.js +27 -27
- package/dist/browser/layout/DetailPanel.js.map +1 -1
- package/dist/browser/layout/Discussion.js +119 -160
- package/dist/browser/layout/Discussion.js.map +1 -1
- package/dist/browser/layout/PanelDialog.js +130 -116
- package/dist/browser/layout/PanelDialog.js.map +1 -1
- package/dist/browser/layout/index.js +1 -0
- package/dist/browser/layout/index.js.map +1 -1
- package/dist/browser/layout/sheet-motion.js +479 -0
- package/dist/browser/layout/sheet-motion.js.map +1 -0
- package/dist/browser/surfaces/NoticeCard.js +68 -47
- package/dist/browser/surfaces/NoticeCard.js.map +1 -1
- package/dist/browser/surfaces/Skeleton.js +32 -0
- package/dist/browser/surfaces/Skeleton.js.map +1 -1
- package/dist/browser/surfaces/index.js +1 -1
- package/dist/browser/surfaces/index.js.map +1 -1
- package/dist/browser/text-editor/TextEditor.js +7 -3
- package/dist/browser/text-editor/TextEditor.js.map +1 -1
- package/dist/browser/text-editor/clipboard-html.js +62 -26
- package/dist/browser/text-editor/clipboard-html.js.map +1 -1
- package/dist/browser/text-editor/clipboard-loading.js +44 -15
- package/dist/browser/text-editor/clipboard-loading.js.map +1 -1
- package/dist/browser/text-editor/engine.js +9 -4
- package/dist/browser/text-editor/engine.js.map +1 -1
- package/dist/browser/text-editor/format.js +37 -1
- package/dist/browser/text-editor/format.js.map +1 -1
- package/dist/browser/text-editor/paste.js +2 -1
- package/dist/browser/text-editor/paste.js.map +1 -1
- package/dist/ssr/actions/SortableList.js +116 -0
- package/dist/ssr/actions/SortableList.js.map +1 -0
- package/dist/ssr/actions/Toolbar.js +89 -35
- package/dist/ssr/actions/Toolbar.js.map +1 -1
- package/dist/ssr/actions/drag-and-drop.js +2 -1
- package/dist/ssr/actions/drag-and-drop.js.map +1 -1
- package/dist/ssr/actions/index.js +1 -0
- package/dist/ssr/actions/index.js.map +1 -1
- package/dist/ssr/actions/sortable-list-messages.js +35 -0
- package/dist/ssr/actions/sortable-list-messages.js.map +1 -0
- package/dist/ssr/chart-inspection.js +2 -1
- package/dist/ssr/chart-inspection.js.map +1 -1
- package/dist/ssr/charts/core/balance-flow-data.js +93 -0
- package/dist/ssr/charts/core/balance-flow-data.js.map +1 -0
- package/dist/ssr/charts/core/balance-flow-fields.js +19 -0
- package/dist/ssr/charts/core/balance-flow-fields.js.map +1 -0
- package/dist/ssr/charts/core/balance-flow-frame.js +44 -0
- package/dist/ssr/charts/core/balance-flow-frame.js.map +1 -0
- package/dist/ssr/charts/core/balance-flow-messages.js +49 -0
- package/dist/ssr/charts/core/balance-flow-messages.js.map +1 -0
- package/dist/ssr/charts/core/balance-flow-size.js +42 -0
- package/dist/ssr/charts/core/balance-flow-size.js.map +1 -0
- package/dist/ssr/charts/core/balance-flow.js +195 -0
- package/dist/ssr/charts/core/balance-flow.js.map +1 -0
- package/dist/ssr/charts/core/calendar-layout.js +105 -0
- package/dist/ssr/charts/core/calendar-layout.js.map +1 -0
- package/dist/ssr/charts/core/calendar.js +2 -104
- package/dist/ssr/charts/core/calendar.js.map +1 -1
- package/dist/ssr/charts/core/index.js +9 -1
- package/dist/ssr/charts/core/index.js.map +1 -1
- package/dist/ssr/charts/core/inspection.js +2 -1
- package/dist/ssr/charts/core/inspection.js.map +1 -1
- package/dist/ssr/charts/core/number-format.js +53 -0
- package/dist/ssr/charts/core/number-format.js.map +1 -0
- package/dist/ssr/charts/core/registry.js +3 -1
- package/dist/ssr/charts/core/registry.js.map +1 -1
- package/dist/ssr/charts/core/render-size.js +2 -0
- package/dist/ssr/charts/core/render-size.js.map +1 -1
- package/dist/ssr/charts/core/render.js +8 -1
- package/dist/ssr/charts/core/render.js.map +1 -1
- package/dist/ssr/charts/core/snapshot.js +3 -3
- package/dist/ssr/charts/core/snapshot.js.map +1 -1
- package/dist/ssr/charts/core/types.js.map +1 -1
- package/dist/ssr/charts/description.js.map +1 -1
- package/dist/ssr/charts.js +2 -0
- package/dist/ssr/charts.js.map +1 -1
- package/dist/ssr/content/Chart.js +3 -1
- package/dist/ssr/content/Chart.js.map +1 -1
- package/dist/ssr/content/ChartBalanceFlow.js +69 -0
- package/dist/ssr/content/ChartBalanceFlow.js.map +1 -0
- package/dist/ssr/content/ChartExplorer.js +1 -1
- package/dist/ssr/content/ChartExplorer.js.map +1 -1
- package/dist/ssr/content/ChartRoot.js +1 -1
- package/dist/ssr/content/ChartRoot.js.map +1 -1
- package/dist/ssr/content/DataTable.js +72 -118
- package/dist/ssr/content/DataTable.js.map +1 -1
- package/dist/ssr/content/FileView.js +39 -50
- package/dist/ssr/content/FileView.js.map +1 -1
- package/dist/ssr/content/LoadMore.js +146 -0
- package/dist/ssr/content/LoadMore.js.map +1 -0
- package/dist/ssr/content/MapDialog.js +469 -0
- package/dist/ssr/content/MapDialog.js.map +1 -0
- package/dist/ssr/content/MapTile.js +92 -0
- package/dist/ssr/content/MapTile.js.map +1 -0
- package/dist/ssr/content/MapView.js +12 -8
- package/dist/ssr/content/MapView.js.map +1 -1
- package/dist/ssr/content/PdfPages.js +538 -0
- package/dist/ssr/content/PdfPages.js.map +1 -0
- package/dist/ssr/content/PdfViewer.js +226 -457
- package/dist/ssr/content/PdfViewer.js.map +1 -1
- package/dist/ssr/content/VirtualFeed.js +292 -44
- package/dist/ssr/content/VirtualFeed.js.map +1 -1
- package/dist/ssr/content/chart-balance-flow-controller.js +184 -0
- package/dist/ssr/content/chart-balance-flow-controller.js.map +1 -0
- package/dist/ssr/content/chart-balance-flow.js +6 -0
- package/dist/ssr/content/chart-balance-flow.js.map +1 -0
- package/dist/ssr/content/chart-inspection-core.js +1 -73
- package/dist/ssr/content/chart-inspection-core.js.map +1 -1
- package/dist/ssr/content/chart-inspection-mount.js +75 -0
- package/dist/ssr/content/chart-inspection-mount.js.map +1 -0
- package/dist/ssr/content/chart-svg.js +1 -1
- package/dist/ssr/content/chart-svg.js.map +1 -1
- package/dist/ssr/content/feed-messages.js +22 -2
- package/dist/ssr/content/feed-messages.js.map +1 -1
- package/dist/ssr/content/index.js +4 -1
- package/dist/ssr/content/index.js.map +1 -1
- package/dist/ssr/content/map-dialog-messages.js +47 -0
- package/dist/ssr/content/map-dialog-messages.js.map +1 -0
- package/dist/ssr/content/map-navigation.js +15 -0
- package/dist/ssr/content/map-navigation.js.map +1 -0
- package/dist/ssr/content/map-view-messages.js +4 -0
- package/dist/ssr/content/map-view-messages.js.map +1 -1
- package/dist/ssr/content/map-view-types.js.map +1 -1
- package/dist/ssr/content/pdf-messages.js +8 -8
- package/dist/ssr/content/pdf-messages.js.map +1 -1
- package/dist/ssr/feedback/dialog-core.js +22 -10
- package/dist/ssr/feedback/dialog-core.js.map +1 -1
- package/dist/ssr/feedback/index.js.map +1 -1
- package/dist/ssr/feedback/prompt-confirm.js +13 -2
- package/dist/ssr/feedback/prompt-confirm.js.map +1 -1
- package/dist/ssr/feedback/prompts.js +32 -24
- package/dist/ssr/feedback/prompts.js.map +1 -1
- package/dist/ssr/feedback/success-check.js +47 -0
- package/dist/ssr/feedback/success-check.js.map +1 -0
- package/dist/ssr/feedback/toast-hit.js +16 -0
- package/dist/ssr/feedback/toast-hit.js.map +1 -0
- package/dist/ssr/feedback/toast-messages.js +6 -2
- package/dist/ssr/feedback/toast-messages.js.map +1 -1
- package/dist/ssr/feedback/toast.js +609 -98
- package/dist/ssr/feedback/toast.js.map +1 -1
- package/dist/ssr/intl/messages.js +4 -0
- package/dist/ssr/intl/messages.js.map +1 -1
- package/dist/ssr/layout/AppWorkspace.js +39 -5
- package/dist/ssr/layout/AppWorkspace.js.map +1 -1
- package/dist/ssr/layout/BottomSheet.js +32 -4
- package/dist/ssr/layout/BottomSheet.js.map +1 -1
- package/dist/ssr/layout/Breadcrumbs.js +62 -0
- package/dist/ssr/layout/Breadcrumbs.js.map +1 -0
- package/dist/ssr/layout/DetailPanel.js +10 -10
- package/dist/ssr/layout/DetailPanel.js.map +1 -1
- package/dist/ssr/layout/Discussion.js +39 -65
- package/dist/ssr/layout/Discussion.js.map +1 -1
- package/dist/ssr/layout/PanelDialog.js +54 -35
- package/dist/ssr/layout/PanelDialog.js.map +1 -1
- package/dist/ssr/layout/index.js +1 -0
- package/dist/ssr/layout/index.js.map +1 -1
- package/dist/ssr/layout/sheet-motion.js +479 -0
- package/dist/ssr/layout/sheet-motion.js.map +1 -0
- package/dist/ssr/surfaces/NoticeCard.js +33 -17
- package/dist/ssr/surfaces/NoticeCard.js.map +1 -1
- package/dist/ssr/surfaces/Skeleton.js +32 -0
- package/dist/ssr/surfaces/Skeleton.js.map +1 -1
- package/dist/ssr/surfaces/index.js +1 -1
- package/dist/ssr/surfaces/index.js.map +1 -1
- package/dist/ssr/text-editor/TextEditor.js +7 -3
- package/dist/ssr/text-editor/TextEditor.js.map +1 -1
- package/dist/ssr/text-editor/clipboard-html.js +62 -26
- package/dist/ssr/text-editor/clipboard-html.js.map +1 -1
- package/dist/ssr/text-editor/clipboard-loading.js +44 -15
- package/dist/ssr/text-editor/clipboard-loading.js.map +1 -1
- package/dist/ssr/text-editor/engine.js +9 -4
- package/dist/ssr/text-editor/engine.js.map +1 -1
- package/dist/ssr/text-editor/format.js +37 -1
- package/dist/ssr/text-editor/format.js.map +1 -1
- package/dist/ssr/text-editor/paste.js +2 -1
- package/dist/ssr/text-editor/paste.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/types/actions/SortableList.d.ts +26 -0
- package/dist/types/actions/Toolbar.d.ts +11 -0
- package/dist/types/actions/drag-and-drop.d.ts +2 -0
- package/dist/types/actions/index.d.ts +2 -0
- package/dist/types/actions/sortable-list-messages.d.ts +15 -0
- package/dist/types/chart-inspection.d.ts +2 -1
- package/dist/types/charts/core/balance-flow-data.d.ts +37 -0
- package/dist/types/charts/core/balance-flow-fields.d.ts +13 -0
- package/dist/types/charts/core/balance-flow-frame.d.ts +4 -0
- package/dist/types/charts/core/balance-flow-messages.d.ts +97 -0
- package/dist/types/charts/core/balance-flow-size.d.ts +21 -0
- package/dist/types/charts/core/balance-flow.d.ts +70 -0
- package/dist/types/charts/core/calendar-layout.d.ts +67 -0
- package/dist/types/charts/core/calendar.d.ts +2 -64
- package/dist/types/charts/core/index.d.ts +9 -1
- package/dist/types/charts/core/number-format.d.ts +28 -0
- package/dist/types/charts/core/registry.d.ts +2 -0
- package/dist/types/charts/core/types.d.ts +1 -0
- package/dist/types/charts/description.d.ts +17 -0
- package/dist/types/charts.d.ts +2 -0
- package/dist/types/content/ChartBalanceFlow.d.ts +17 -0
- package/dist/types/content/ChartRoot.d.ts +2 -1
- package/dist/types/content/DataTable.d.ts +7 -1
- package/dist/types/content/LoadMore.d.ts +41 -0
- package/dist/types/content/MapDialog.d.ts +105 -0
- package/dist/types/content/MapTile.d.ts +37 -0
- package/dist/types/content/PdfPages.d.ts +57 -0
- package/dist/types/content/PdfViewer.d.ts +35 -19
- package/dist/types/content/VirtualFeed.d.ts +57 -18
- package/dist/types/content/chart-balance-flow-controller.d.ts +12 -0
- package/dist/types/content/chart-balance-flow.d.ts +4 -0
- package/dist/types/content/chart-inspection-core.d.ts +0 -17
- package/dist/types/content/chart-inspection-mount.d.ts +21 -0
- package/dist/types/content/feed-messages.d.ts +10 -0
- package/dist/types/content/index.d.ts +6 -3
- package/dist/types/content/map-dialog-messages.d.ts +19 -0
- package/dist/types/content/map-navigation.d.ts +13 -0
- package/dist/types/content/map-view-messages.d.ts +2 -0
- package/dist/types/content/map-view-types.d.ts +5 -0
- package/dist/types/content/pdf-messages.d.ts +2 -2
- package/dist/types/feedback/dialog-core.d.ts +6 -0
- package/dist/types/feedback/index.d.ts +2 -2
- package/dist/types/feedback/prompt-confirm.d.ts +2 -0
- package/dist/types/feedback/prompts.d.ts +5 -1
- package/dist/types/feedback/success-check.d.ts +4 -0
- package/dist/types/feedback/toast-hit.d.ts +5 -0
- package/dist/types/feedback/toast-messages.d.ts +3 -1
- package/dist/types/feedback/toast.d.ts +42 -5
- package/dist/types/intl/messages.d.ts +2 -0
- package/dist/types/layout/AppWorkspace.d.ts +10 -0
- package/dist/types/layout/BottomSheet.d.ts +6 -0
- package/dist/types/layout/Breadcrumbs.d.ts +19 -0
- package/dist/types/layout/DetailPanel.d.ts +4 -1
- package/dist/types/layout/PanelDialog.d.ts +5 -0
- package/dist/types/layout/index.d.ts +2 -1
- package/dist/types/layout/sheet-motion.d.ts +32 -0
- package/dist/types/surfaces/NoticeCard.d.ts +14 -1
- package/dist/types/surfaces/Skeleton.d.ts +13 -1
- package/dist/types/surfaces/index.d.ts +1 -1
- package/dist/types/text-editor/TextEditor.d.ts +5 -0
- package/dist/types/text-editor/clipboard-loading.d.ts +2 -3
- package/dist/types/text-editor/engine.d.ts +6 -1
- package/dist/types/text-editor/format.d.ts +3 -1
- package/package.json +2 -2
- package/dist/browser/content/PdfPreview.js +0 -448
- package/dist/browser/content/PdfPreview.js.map +0 -1
- package/dist/ssr/content/PdfPreview.js +0 -300
- package/dist/ssr/content/PdfPreview.js.map +0 -1
- package/dist/types/content/PdfPreview.d.ts +0 -26
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
import { getK2bPortalRoot } from "../internal/portal";
|
|
2
2
|
import { resolveUiMessages } from "../intl/messages";
|
|
3
3
|
import { announce, ensureLiveRegions } from "./announce";
|
|
4
|
+
import { createSuccessCheck } from "./success-check";
|
|
4
5
|
import { resolveToastMessages } from "./toast-messages";
|
|
5
|
-
|
|
6
|
+
|
|
7
|
+
/** A link at the end of the message, such as "Open settings". Following it closes the toast. */
|
|
8
|
+
|
|
9
|
+
/** Toasts in the stack at every width; older ones leave by the eviction rule below. */
|
|
6
10
|
const MAX_VISIBLE_TOASTS = 3;
|
|
7
|
-
const MAX_VISIBLE_TOASTS_NARROW = 2;
|
|
8
11
|
/** The same media query that moves the rail to the top edge in the stylesheet. */
|
|
9
12
|
const NARROW_RAIL_QUERY = "(max-width: 47.999rem), (max-height: 29.999rem)";
|
|
13
|
+
/** A leaving toast fades in this time, then leaves the document. */
|
|
10
14
|
const ANIMATION_MS = 200;
|
|
15
|
+
/** Folded, each older toast shows this much of its edge behind the newer one and is this much smaller. */
|
|
16
|
+
const STACK_PEEK_PX = 10;
|
|
17
|
+
const STACK_SCALE_STEP = 0.05;
|
|
18
|
+
/** Fanned out, the toasts and the pinned custom slots keep this gap. */
|
|
19
|
+
const STACK_GAP_PX = 10;
|
|
20
|
+
/** A toast arrives from, and leaves towards, the rail's edge by this distance. */
|
|
21
|
+
const STACK_TRAVEL_PX = 18;
|
|
22
|
+
/** A swipe locks its axis after this distance, and dismisses past the distance or above the speed (px/ms). */
|
|
23
|
+
const SWIPE_AXIS_PX = 4;
|
|
24
|
+
const SWIPE_DISMISS_PX = 45;
|
|
25
|
+
const SWIPE_DISMISS_SPEED = 0.11;
|
|
26
|
+
/** After a swipe, the click that ends it does not reach the toast's controls. */
|
|
27
|
+
const SWIPE_CLICK_GUARD_MS = 350;
|
|
28
|
+
/** Focuses the stack from anywhere on the page. */
|
|
29
|
+
const STACK_SHORTCUT = "Alt+T";
|
|
30
|
+
/** Option+T types "†" on Apple keyboards. Read inline: the shortcut formatter's catalog would grow every island with a toast. */
|
|
31
|
+
const appleKeyboard = () => typeof navigator !== "undefined" && /Mac|iPhone|iPad|iPod/.test(navigator.platform || navigator.userAgent);
|
|
11
32
|
/** Reading time: a short message stays 4 s, longer text about 1 s more per 30 characters, up to 12 s. */
|
|
12
33
|
const READ_BASE_MS = 4_000;
|
|
13
34
|
const READ_FREE_CHARACTERS = 40;
|
|
@@ -26,7 +47,11 @@ const VARIANT_STYLES = {
|
|
|
26
47
|
},
|
|
27
48
|
success: {
|
|
28
49
|
tone: "success",
|
|
29
|
-
iconClass: "ti-
|
|
50
|
+
iconClass: "ti-check"
|
|
51
|
+
},
|
|
52
|
+
warning: {
|
|
53
|
+
tone: "warning",
|
|
54
|
+
iconClass: "ti-alert-triangle"
|
|
30
55
|
},
|
|
31
56
|
error: {
|
|
32
57
|
tone: "danger",
|
|
@@ -40,6 +65,22 @@ const defaultDuration = (variant, text, hasAction) => {
|
|
|
40
65
|
const reading = Math.min(READ_MAX_MS, READ_BASE_MS + Math.max(0, text.length - READ_FREE_CHARACTERS) * READ_MS_PER_CHARACTER);
|
|
41
66
|
return variant === "error" || hasAction ? Math.max(REACHABLE_MS, reading) : reading;
|
|
42
67
|
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Links in a toast go to web pages, mail, and phone numbers only. A caller's `javascript:` or `data:` URL never runs
|
|
71
|
+
* from a toast: the link is left out, and an action with such a URL becomes a button that only closes the toast.
|
|
72
|
+
*/
|
|
73
|
+
const SAFE_PROTOCOLS = new Set(["http:", "https:", "mailto:", "tel:"]);
|
|
74
|
+
const safeHref = href => {
|
|
75
|
+
try {
|
|
76
|
+
// Resolved like the browser resolves it, so a disguised scheme shows; the link keeps the caller's own, often
|
|
77
|
+
// relative, address.
|
|
78
|
+
const url = new URL(href, document.baseURI);
|
|
79
|
+
return SAFE_PROTOCOLS.has(url.protocol) ? href : null;
|
|
80
|
+
} catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
43
84
|
const normalizedIconClass = iconClass => {
|
|
44
85
|
const tokens = iconClass.split(/\s+/).filter(Boolean).filter(token => token !== "ti");
|
|
45
86
|
return ["ti", ...tokens].join(" ");
|
|
@@ -50,12 +91,16 @@ const applyIconClass = (icon, iconClass) => {
|
|
|
50
91
|
const liveToasts = new Set();
|
|
51
92
|
|
|
52
93
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
94
|
+
* What keeps the stack fanned out and every timer paused: a card under a mouse or pen, keyboard focus in a card or
|
|
95
|
+
* on the rail, or a tap on a touch screen. A swipe in progress pauses the timers without fanning the stack out.
|
|
96
|
+
* While anything holds the rail, no toast times out, so nothing moves under the pointer or out from under focus.
|
|
55
97
|
*/
|
|
56
98
|
const pointerHolds = new Set();
|
|
57
99
|
const focusHolds = new Set();
|
|
58
|
-
const
|
|
100
|
+
const tapHolds = new Set();
|
|
101
|
+
const gestureHolds = new Set();
|
|
102
|
+
const stackOpen = () => pointerHolds.size + focusHolds.size + tapHolds.size > 0;
|
|
103
|
+
const railHeld = () => stackOpen() || gestureHolds.size > 0;
|
|
59
104
|
|
|
60
105
|
/**
|
|
61
106
|
* Firefox and WebKit fire no focusout when a focused element leaves the document, and WebKit no pointerleave when
|
|
@@ -66,6 +111,7 @@ const railHeld = () => pointerHolds.size + focusHolds.size > 0;
|
|
|
66
111
|
const releaseStaleHolds = pointerTarget => {
|
|
67
112
|
for (const card of Array.from(pointerHolds)) if (!card.isConnected || pointerTarget !== undefined && !card.contains(pointerTarget)) setHold(pointerHolds, card, false);
|
|
68
113
|
for (const card of Array.from(focusHolds)) if (!card.isConnected || !card.contains(card.ownerDocument.activeElement)) setHold(focusHolds, card, false);
|
|
114
|
+
for (const holds of [tapHolds, gestureHolds]) for (const element of Array.from(holds)) if (!element.isConnected) setHold(holds, element, false);
|
|
69
115
|
};
|
|
70
116
|
const watchStaleHolds = doc => {
|
|
71
117
|
const observer = new MutationObserver(() => releaseStaleHolds());
|
|
@@ -81,35 +127,122 @@ const watchStaleHolds = doc => {
|
|
|
81
127
|
};
|
|
82
128
|
};
|
|
83
129
|
let unwatchStaleHolds = null;
|
|
84
|
-
function setHold(holds,
|
|
130
|
+
function setHold(holds, element, held) {
|
|
131
|
+
if (holds.has(element) === held) return;
|
|
85
132
|
const wasHeld = railHeld();
|
|
86
|
-
|
|
133
|
+
const wasOpen = stackOpen();
|
|
134
|
+
if (held) holds.add(element);else holds.delete(element);
|
|
87
135
|
if (railHeld() !== wasHeld) {
|
|
88
136
|
for (const item of Array.from(liveToasts)) (wasHeld ? item.resume : item.pause)();
|
|
89
137
|
unwatchStaleHolds?.();
|
|
90
|
-
unwatchStaleHolds = wasHeld ? null : watchStaleHolds(
|
|
138
|
+
unwatchStaleHolds = wasHeld ? null : watchStaleHolds(element.ownerDocument);
|
|
91
139
|
}
|
|
140
|
+
if (stackOpen() !== wasOpen) scheduleLayout(element.ownerDocument);
|
|
92
141
|
// A released card may be the one the rail limit had to wait for.
|
|
93
142
|
if (!held) enforceCap();
|
|
94
143
|
}
|
|
144
|
+
const rails = doc => Array.from(doc.querySelectorAll(`[${CONTAINER_ATTRIBUTE}]`));
|
|
145
|
+
|
|
146
|
+
/** The rail that shows at least one open toast or custom slot. */
|
|
147
|
+
const shownRail = doc => rails(doc).find(rail => Array.from(rail.children).some(slot => slot instanceof HTMLElement && slot.dataset.state !== "closing")) ?? null;
|
|
148
|
+
|
|
149
|
+
/** Where focus was before the shortcut moved it to the stack; Escape on the stack returns it. */
|
|
150
|
+
let shortcutOrigin = null;
|
|
151
|
+
|
|
152
|
+
/** Escape on the focused stack: it folds, unless the pointer still rests on it, and focus goes back. */
|
|
153
|
+
const foldStack = rail => {
|
|
154
|
+
const doc = rail.ownerDocument;
|
|
155
|
+
for (const element of Array.from(tapHolds)) setHold(tapHolds, element, false);
|
|
156
|
+
if (rail.contains(doc.activeElement)) {
|
|
157
|
+
const origin = shortcutOrigin?.isConnected ? shortcutOrigin : null;
|
|
158
|
+
if (origin) origin.focus({
|
|
159
|
+
preventScroll: true
|
|
160
|
+
});else doc.activeElement?.blur();
|
|
161
|
+
}
|
|
162
|
+
setHold(focusHolds, rail, false);
|
|
163
|
+
shortcutOrigin = null;
|
|
164
|
+
};
|
|
165
|
+
const isTextEntry = target => target instanceof HTMLElement && (target.isContentEditable || target.matches("input, textarea, select"));
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* One listener set per document: the shortcut, a tap beside an open stack, and the edge moving between the top and
|
|
169
|
+
* the bottom (a rotated phone, a modal dialog in a phone shell). They outlive a rail, which moves into a new element
|
|
170
|
+
* whenever it returns to the top layer.
|
|
171
|
+
*/
|
|
172
|
+
const wiredDocuments = new WeakSet();
|
|
173
|
+
const wireDocument = doc => {
|
|
174
|
+
if (wiredDocuments.has(doc)) return;
|
|
175
|
+
wiredDocuments.add(doc);
|
|
176
|
+
doc.addEventListener("keydown", event => {
|
|
177
|
+
if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.code !== "KeyT" || event.defaultPrevented) return;
|
|
178
|
+
const rail = shownRail(doc);
|
|
179
|
+
if (!rail) return;
|
|
180
|
+
// Option+T types a character on Apple keyboards; there the shortcut leaves text entry alone.
|
|
181
|
+
if (isTextEntry(event.target) && appleKeyboard()) return;
|
|
182
|
+
event.preventDefault();
|
|
183
|
+
const active = doc.activeElement;
|
|
184
|
+
if (active instanceof HTMLElement && !active.closest(`[${CONTAINER_ATTRIBUTE}]`) && active !== doc.body) shortcutOrigin = active;
|
|
185
|
+
rail.focus({
|
|
186
|
+
preventScroll: true
|
|
187
|
+
});
|
|
188
|
+
// Behind a modal dialog the rail is inert and takes no focus; then nothing holds the stack open.
|
|
189
|
+
if (doc.activeElement === rail) setHold(focusHolds, rail, true);
|
|
190
|
+
});
|
|
191
|
+
doc.addEventListener("pointerdown", event => {
|
|
192
|
+
if (event.pointerType === "mouse" || tapHolds.size === 0) return;
|
|
193
|
+
if (event.target instanceof Element && event.target.closest(`[${CONTAINER_ATTRIBUTE}]`)) return;
|
|
194
|
+
for (const rail of Array.from(tapHolds)) setHold(tapHolds, rail, false);
|
|
195
|
+
}, true);
|
|
196
|
+
const view = doc.defaultView;
|
|
197
|
+
const relayout = () => scheduleLayout(doc);
|
|
198
|
+
view?.addEventListener("resize", relayout);
|
|
199
|
+
if (typeof view?.matchMedia === "function") view.matchMedia(NARROW_RAIL_QUERY).addEventListener?.("change", relayout);
|
|
200
|
+
new MutationObserver(relayout).observe(doc.documentElement, {
|
|
201
|
+
attributes: true,
|
|
202
|
+
attributeFilter: ["data-k2b-mobile-shell", "data-k2b-mobile-shell-modal"]
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/** Listeners on the rail element itself; a rail that returns to the top layer is a new element and is wired again. */
|
|
207
|
+
const wiredRails = new WeakSet();
|
|
208
|
+
const wireRail = rail => {
|
|
209
|
+
if (wiredRails.has(rail)) return rail;
|
|
210
|
+
wiredRails.add(rail);
|
|
211
|
+
rail.addEventListener("keydown", event => {
|
|
212
|
+
if (event.key !== "Escape" || event.target !== rail || event.defaultPrevented) return;
|
|
213
|
+
event.preventDefault();
|
|
214
|
+
event.stopPropagation();
|
|
215
|
+
foldStack(rail);
|
|
216
|
+
});
|
|
217
|
+
rail.addEventListener("focusout", event => {
|
|
218
|
+
if (event.target === rail) setHold(focusHolds, rail, false);
|
|
219
|
+
});
|
|
220
|
+
return rail;
|
|
221
|
+
};
|
|
95
222
|
const ensureContainer = () => {
|
|
96
223
|
if (typeof document === "undefined") return null;
|
|
97
224
|
// The shared live regions exist before the first toast's text arrives.
|
|
98
225
|
ensureLiveRegions(document);
|
|
226
|
+
wireDocument(document);
|
|
99
227
|
const root = getK2bPortalRoot();
|
|
100
228
|
let container = root.querySelector(`[${CONTAINER_ATTRIBUTE}]`);
|
|
101
229
|
if (container) return container;
|
|
230
|
+
const messages = resolveToastMessages();
|
|
102
231
|
container = document.createElement("div");
|
|
103
232
|
container.id = K2B_TOAST_CONTAINER_ID;
|
|
104
233
|
container.setAttribute(CONTAINER_ATTRIBUTE, "");
|
|
105
234
|
container.setAttribute("popover", "manual");
|
|
106
235
|
container.setAttribute("role", "region");
|
|
107
|
-
container.setAttribute("aria-label",
|
|
236
|
+
container.setAttribute("aria-label", `${messages.notifications}, ${STACK_SHORTCUT}`);
|
|
237
|
+
container.setAttribute("aria-keyshortcuts", STACK_SHORTCUT);
|
|
238
|
+
container.tabIndex = -1;
|
|
108
239
|
// Keep the source rail geometry inline: it must defeat UA popover defaults
|
|
109
240
|
// even when a consumer has not loaded the optional package stylesheet yet.
|
|
110
241
|
// The stylesheet only moves the rail to the top edge, and to the full width
|
|
111
|
-
// of a phone, through the rail variables.
|
|
112
|
-
|
|
242
|
+
// of a phone, through the rail variables. The toasts lie on top of each
|
|
243
|
+
// other inside it; the stack sets the rail's height to what they cover, so
|
|
244
|
+
// nothing clips their shadows or the close buttons over their corners.
|
|
245
|
+
container.style.cssText = "position:fixed;left:var(--k2b-toast-rail-left,auto);right:env(safe-area-inset-right,0px);" + "top:var(--k2b-toast-rail-top,auto);bottom:var(--k2b-toast-rail-bottom,env(safe-area-inset-bottom,0px));" + "z-index:50;box-sizing:border-box;display:block;" + "width:var(--k2b-toast-rail-width,min(25.5rem,calc(100vw - env(safe-area-inset-left,0px) - env(safe-area-inset-right,0px))));" + "height:0px;max-width:100vw;max-height:none;" + "margin:0;padding:var(--k2b-toast-rail-padding,0.75rem 1rem 1rem);border:0;background:transparent;overflow:visible;" + "pointer-events:none;";
|
|
113
246
|
root.appendChild(container);
|
|
114
247
|
return container;
|
|
115
248
|
};
|
|
@@ -118,20 +251,25 @@ const ensureContainer = () => {
|
|
|
118
251
|
const captureViewState = container => {
|
|
119
252
|
const focused = document.activeElement instanceof HTMLElement && container.contains(document.activeElement) ? document.activeElement : null;
|
|
120
253
|
const scrolled = Array.from(container.querySelectorAll("*")).filter(element => element.scrollTop || element.scrollLeft).map(element => [element, element.scrollTop, element.scrollLeft]);
|
|
121
|
-
const railTop = container.scrollTop;
|
|
122
254
|
return rail => {
|
|
123
|
-
rail.scrollTop = railTop;
|
|
124
255
|
for (const [element, top, left] of scrolled) {
|
|
125
256
|
element.scrollTop = top;
|
|
126
257
|
element.scrollLeft = left;
|
|
127
258
|
}
|
|
128
|
-
|
|
259
|
+
// The rail itself held focus after Alt+T: the new rail takes it over.
|
|
260
|
+
const target = focused === container ? rail : focused;
|
|
261
|
+
if (target?.isConnected && rail.contains(target)) target.focus({
|
|
129
262
|
preventScroll: true
|
|
130
263
|
});
|
|
131
264
|
};
|
|
132
265
|
};
|
|
266
|
+
|
|
267
|
+
/** A tap or the shortcut that holds the stack open holds the rail that replaces it in the top layer. */
|
|
268
|
+
const handOverHolds = (from, to) => {
|
|
269
|
+
for (const holds of [focusHolds, tapHolds]) if (holds.delete(from)) holds.add(to);
|
|
270
|
+
};
|
|
133
271
|
const promoteToTopLayer = container => {
|
|
134
|
-
if (typeof container.showPopover !== "function" || !container.isConnected) return container;
|
|
272
|
+
if (typeof container.showPopover !== "function" || !container.isConnected) return wireRail(container);
|
|
135
273
|
let active = container;
|
|
136
274
|
let restore = null;
|
|
137
275
|
try {
|
|
@@ -139,6 +277,7 @@ const promoteToTopLayer = container => {
|
|
|
139
277
|
restore = captureViewState(container);
|
|
140
278
|
const next = container.cloneNode(false);
|
|
141
279
|
while (container.firstChild) next.appendChild(container.firstChild);
|
|
280
|
+
handOverHolds(container, next);
|
|
142
281
|
const root = container.parentElement ?? getK2bPortalRoot();
|
|
143
282
|
container.remove();
|
|
144
283
|
root.appendChild(next);
|
|
@@ -150,7 +289,7 @@ const promoteToTopLayer = container => {
|
|
|
150
289
|
}
|
|
151
290
|
// Offsets apply only once the rail is rendered again, so after it is shown.
|
|
152
291
|
restore?.(active);
|
|
153
|
-
return active;
|
|
292
|
+
return wireRail(active);
|
|
154
293
|
};
|
|
155
294
|
|
|
156
295
|
/** Close every empty rail so an emptied container does not linger in the top
|
|
@@ -159,7 +298,7 @@ const promoteToTopLayer = container => {
|
|
|
159
298
|
* was created can already be detached by the time the toast is dismissed. */
|
|
160
299
|
const hideEmptyContainers = () => {
|
|
161
300
|
if (typeof document === "undefined") return;
|
|
162
|
-
for (const container of
|
|
301
|
+
for (const container of rails(document)) {
|
|
163
302
|
if (container.childElementCount > 0 || typeof container.hidePopover !== "function") continue;
|
|
164
303
|
try {
|
|
165
304
|
if (container.matches(":popover-open")) container.hidePopover();
|
|
@@ -169,14 +308,138 @@ const hideEmptyContainers = () => {
|
|
|
169
308
|
}
|
|
170
309
|
};
|
|
171
310
|
|
|
311
|
+
/* ------------------------------------------------------------------ stack */
|
|
312
|
+
|
|
313
|
+
/** Where layout last placed each slot, away from the edge in px; a leaving slot travels on from there. */
|
|
314
|
+
const placedAt = new WeakMap();
|
|
315
|
+
|
|
316
|
+
/** One pending layout frame per document; every change before it lands in the same layout. */
|
|
317
|
+
const layoutFrames = new WeakMap();
|
|
318
|
+
function scheduleLayout(doc) {
|
|
319
|
+
const view = doc.defaultView;
|
|
320
|
+
if (!view || layoutFrames.has(doc) || typeof view.requestAnimationFrame !== "function") return;
|
|
321
|
+
layoutFrames.set(doc, view.requestAnimationFrame(() => {
|
|
322
|
+
layoutFrames.delete(doc);
|
|
323
|
+
for (const rail of rails(doc)) layoutRail(rail);
|
|
324
|
+
}));
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/** A card that grows or shrinks, as when `update()` changes its text, moves the cards around it. */
|
|
328
|
+
const resizeObservers = new WeakMap();
|
|
329
|
+
const observeSize = (card, observed) => {
|
|
330
|
+
const doc = card.ownerDocument;
|
|
331
|
+
if (!resizeObservers.has(doc)) {
|
|
332
|
+
const Observer = doc.defaultView?.ResizeObserver;
|
|
333
|
+
resizeObservers.set(doc, typeof Observer === "function" ? new Observer(() => scheduleLayout(doc)) : null);
|
|
334
|
+
}
|
|
335
|
+
const observer = resizeObservers.get(doc);
|
|
336
|
+
if (observed) observer?.observe(card);else observer?.unobserve(card);
|
|
337
|
+
};
|
|
338
|
+
const slotCard = slot => slot.firstElementChild instanceof HTMLElement ? slot.firstElementChild : null;
|
|
339
|
+
|
|
340
|
+
/** The rail's edge: the stylesheet moves it to the top on narrow and short viewports. */
|
|
341
|
+
const railAtTop = style => style.getPropertyValue("--k2b-toast-rail-direction").trim() === "column-reverse";
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Places every slot of a rail. Custom slots are pinned at the edge in the order they came; the toasts stack in front
|
|
345
|
+
* of them, newest nearest the edge. Folded, older toasts show only their edge; fanned out, every toast shows whole,
|
|
346
|
+
* with a gap. Only transform and opacity move, so nothing reflows the page while the stack moves.
|
|
347
|
+
*/
|
|
348
|
+
const layoutRail = rail => {
|
|
349
|
+
if (!rail.isConnected) return;
|
|
350
|
+
const style = getComputedStyle(rail);
|
|
351
|
+
const top = railAtTop(style);
|
|
352
|
+
const sign = top ? 1 : -1;
|
|
353
|
+
const open = stackOpen() && shownRail(rail.ownerDocument) === rail;
|
|
354
|
+
rail.dataset.edge = top ? "top" : "bottom";
|
|
355
|
+
rail.dataset.expanded = String(open);
|
|
356
|
+
const padTop = Number.parseFloat(style.paddingTop) || 0;
|
|
357
|
+
const padBottom = Number.parseFloat(style.paddingBottom) || 0;
|
|
358
|
+
const slots = Array.from(rail.children).filter(child => child instanceof HTMLElement && child.matches(".k2b-toast-slot"));
|
|
359
|
+
const present = slots.filter(slot => slot.dataset.state !== "closing");
|
|
360
|
+
// Natural heights, read in one go before anything is written.
|
|
361
|
+
const heights = new Map(present.map(slot => [slot, slotCard(slot)?.offsetHeight ?? 0]));
|
|
362
|
+
// A message too long for its toast scrolls inside it; there a finger scrolls it instead of swiping vertically.
|
|
363
|
+
const overflowing = present.map(slot => {
|
|
364
|
+
const description = slotCard(slot)?.querySelector(":scope > .k2b-toast__content > .k2b-toast__description");
|
|
365
|
+
return [slot, !!description && description.scrollHeight > description.clientHeight + 1];
|
|
366
|
+
});
|
|
367
|
+
// Fanned out, the stack stays on screen: when it is taller than the room up to the far edge, the older toasts move
|
|
368
|
+
// closer and overlap, each still showing its top with its close button and title.
|
|
369
|
+
const railBox = rail.getBoundingClientRect();
|
|
370
|
+
const viewHeight = rail.ownerDocument.documentElement.clientHeight;
|
|
371
|
+
const room = (top ? viewHeight - railBox.top : railBox.bottom) - padTop - padBottom;
|
|
372
|
+
const place = (slot, y, options) => {
|
|
373
|
+
const entering = slot.dataset.state === "entering";
|
|
374
|
+
const travelled = entering ? y - STACK_TRAVEL_PX : y;
|
|
375
|
+
placedAt.set(slot, y);
|
|
376
|
+
slot.style.left = style.paddingLeft;
|
|
377
|
+
slot.style.right = style.paddingRight;
|
|
378
|
+
slot.style.top = top ? `${padTop}px` : "auto";
|
|
379
|
+
slot.style.bottom = top ? "auto" : `${padBottom}px`;
|
|
380
|
+
slot.style.height = `${options.height}px`;
|
|
381
|
+
slot.style.zIndex = String(options.layer);
|
|
382
|
+
slot.style.setProperty("--k2b-toast-y", `${sign * travelled}px`);
|
|
383
|
+
slot.style.setProperty("--k2b-toast-scale", String(options.scale ?? 1));
|
|
384
|
+
slot.style.setProperty("--k2b-toast-opacity", entering ? "0" : String(options.opacity ?? 1));
|
|
385
|
+
slot.toggleAttribute("data-behind", options.behind === true);
|
|
386
|
+
// A folded toast behind the front one is out of reach until the stack fans out; no hidden focus target.
|
|
387
|
+
slot.inert = options.behind === true;
|
|
388
|
+
};
|
|
389
|
+
let base = 0;
|
|
390
|
+
const sockets = present.filter(slot => slot.dataset.custom === "true");
|
|
391
|
+
for (const slot of sockets) {
|
|
392
|
+
const height = heights.get(slot) ?? 0;
|
|
393
|
+
place(slot, base, {
|
|
394
|
+
height,
|
|
395
|
+
layer: 200
|
|
396
|
+
});
|
|
397
|
+
base += height + STACK_GAP_PX;
|
|
398
|
+
}
|
|
399
|
+
const stack = present.filter(slot => slot.dataset.custom !== "true").reverse();
|
|
400
|
+
const frontHeight = stack[0] ? heights.get(stack[0]) ?? 0 : 0;
|
|
401
|
+
let offset = 0;
|
|
402
|
+
let previous = 0;
|
|
403
|
+
let extent = 0;
|
|
404
|
+
stack.forEach((slot, index) => {
|
|
405
|
+
const height = heights.get(slot) ?? 0;
|
|
406
|
+
if (open) {
|
|
407
|
+
const natural = base + offset;
|
|
408
|
+
const y = index === 0 ? natural : Math.max(previous + STACK_PEEK_PX, Math.min(natural, room - height));
|
|
409
|
+
place(slot, y, {
|
|
410
|
+
height,
|
|
411
|
+
layer: 100 - index
|
|
412
|
+
});
|
|
413
|
+
offset += height + STACK_GAP_PX;
|
|
414
|
+
previous = y;
|
|
415
|
+
extent = Math.max(extent, y + height);
|
|
416
|
+
} else {
|
|
417
|
+
place(slot, base + index * STACK_PEEK_PX, {
|
|
418
|
+
scale: 1 - index * STACK_SCALE_STEP,
|
|
419
|
+
opacity: index < MAX_VISIBLE_TOASTS ? 1 : 0,
|
|
420
|
+
height: index === 0 ? height : frontHeight,
|
|
421
|
+
behind: index > 0,
|
|
422
|
+
layer: 100 - index
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
const covered = stack.length === 0 ? Math.max(0, base - STACK_GAP_PX) : open ? extent : base + frontHeight + Math.min(stack.length - 1, MAX_VISIBLE_TOASTS - 1) * STACK_PEEK_PX;
|
|
427
|
+
for (const [slot, scrolls] of overflowing) slot.toggleAttribute("data-scrolls", scrolls);
|
|
428
|
+
rail.style.height = covered > 0 ? `${covered + padTop + padBottom}px` : "0px";
|
|
429
|
+
};
|
|
430
|
+
|
|
172
431
|
/**
|
|
173
|
-
* Every toast and custom slot sits in a slot that
|
|
174
|
-
*
|
|
432
|
+
* Every toast and custom slot sits in a slot that the stack places. The card carries the chrome and `data-open` /
|
|
433
|
+
* `data-closing`; the slot carries the motion.
|
|
175
434
|
*/
|
|
176
435
|
|
|
177
436
|
const railItem = card => {
|
|
178
|
-
card.addEventListener("pointerenter",
|
|
179
|
-
|
|
437
|
+
card.addEventListener("pointerenter", event => {
|
|
438
|
+
if (event.pointerType !== "touch") setHold(pointerHolds, card, true);
|
|
439
|
+
});
|
|
440
|
+
card.addEventListener("pointerleave", event => {
|
|
441
|
+
if (event.pointerType !== "touch") setHold(pointerHolds, card, false);
|
|
442
|
+
});
|
|
180
443
|
card.addEventListener("focusin", () => setHold(focusHolds, card, true));
|
|
181
444
|
card.addEventListener("focusout", event => {
|
|
182
445
|
if (!card.contains(event.relatedTarget)) setHold(focusHolds, card, false);
|
|
@@ -184,50 +447,169 @@ const railItem = card => {
|
|
|
184
447
|
const slot = document.createElement("div");
|
|
185
448
|
slot.className = "k2b-toast-slot";
|
|
186
449
|
slot.dataset.state = "entering";
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
slot.appendChild(clip);
|
|
450
|
+
if (card.dataset.custom) slot.dataset.custom = card.dataset.custom;
|
|
451
|
+
slot.style.setProperty("--k2b-toast-opacity", "0");
|
|
452
|
+
slot.appendChild(card);
|
|
191
453
|
return {
|
|
192
454
|
slot,
|
|
193
455
|
open: () => {
|
|
194
|
-
|
|
456
|
+
observeSize(card, true);
|
|
457
|
+
const rail = slot.parentElement;
|
|
458
|
+
// The entering place must be laid out once before it changes, or nothing transitions.
|
|
459
|
+
if (rail) layoutRail(rail);
|
|
195
460
|
slot.getBoundingClientRect();
|
|
196
461
|
requestAnimationFrame(() => {
|
|
197
462
|
if (card.dataset.closing) return;
|
|
198
463
|
slot.dataset.state = "open";
|
|
199
464
|
card.dataset.open = "true";
|
|
465
|
+
// In the same frame as the state, so the arrival moves from its first frame on.
|
|
466
|
+
if (slot.parentElement) layoutRail(slot.parentElement);
|
|
200
467
|
});
|
|
201
468
|
},
|
|
202
|
-
close:
|
|
469
|
+
close: options => {
|
|
470
|
+
const wasEntering = slot.dataset.state === "entering";
|
|
203
471
|
slot.dataset.state = "closing";
|
|
204
472
|
card.dataset.closing = "true";
|
|
473
|
+
observeSize(card, false);
|
|
474
|
+
// Unswiped, it fades out towards the edge from where it was.
|
|
475
|
+
if (!options?.swiped && !wasEntering) {
|
|
476
|
+
const sign = slot.parentElement?.dataset.edge === "top" ? 1 : -1;
|
|
477
|
+
slot.style.setProperty("--k2b-toast-y", `${sign * ((placedAt.get(slot) ?? 0) - STACK_TRAVEL_PX)}px`);
|
|
478
|
+
}
|
|
479
|
+
slot.style.setProperty("--k2b-toast-opacity", "0");
|
|
480
|
+
slot.inert = true;
|
|
205
481
|
// A card that leaves under the pointer or with focus no longer holds the rail.
|
|
206
482
|
if (pointerHolds.has(card)) setHold(pointerHolds, card, false);
|
|
207
483
|
if (focusHolds.has(card)) setHold(focusHolds, card, false);
|
|
484
|
+
scheduleLayout(card.ownerDocument);
|
|
208
485
|
setTimeout(() => {
|
|
209
486
|
slot.remove();
|
|
210
487
|
hideEmptyContainers();
|
|
211
|
-
|
|
488
|
+
scheduleLayout(card.ownerDocument);
|
|
212
489
|
}, ANIMATION_MS);
|
|
213
490
|
}
|
|
214
491
|
};
|
|
215
492
|
};
|
|
216
493
|
|
|
494
|
+
/** A click that only ends a swipe or a tap does not press the control under the finger. */
|
|
495
|
+
const swallowNextClick = card => {
|
|
496
|
+
const stop = event => {
|
|
497
|
+
event.preventDefault();
|
|
498
|
+
event.stopPropagation();
|
|
499
|
+
};
|
|
500
|
+
card.addEventListener("click", stop, {
|
|
501
|
+
capture: true,
|
|
502
|
+
once: true
|
|
503
|
+
});
|
|
504
|
+
setTimeout(() => card.removeEventListener("click", stop, {
|
|
505
|
+
capture: true
|
|
506
|
+
}), SWIPE_CLICK_GUARD_MS);
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
/** Wrong-direction travel follows the finger less and less, so the toast resists instead of moving away. */
|
|
510
|
+
const resisted = distance => distance / (1.5 + Math.abs(distance) / 20);
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Swiping towards the nearest screen edge dismisses a toast: down or right at the bottom edge, up or sideways at the
|
|
514
|
+
* top. A tap on a touch screen fans the stack out or folds it. Swiping is a shortcut; the close button stays.
|
|
515
|
+
*/
|
|
516
|
+
const attachGestures = (item, card, dismiss, custom) => {
|
|
517
|
+
let gesture = null;
|
|
518
|
+
const slot = item.slot;
|
|
519
|
+
const rail = () => slot.parentElement;
|
|
520
|
+
const allowed = direction => rail()?.dataset.edge === "top" ? direction !== "down" : direction === "right" || direction === "down";
|
|
521
|
+
card.addEventListener("pointerdown", event => {
|
|
522
|
+
if (event.button !== 0 || card.dataset.closing) return;
|
|
523
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
524
|
+
// A mouse selects the message and presses the controls; a finger can start a swipe anywhere.
|
|
525
|
+
if (event.pointerType === "mouse" && target?.closest("a, button, .k2b-toast__content")) return;
|
|
526
|
+
// A custom slot is swiped only by a finger, only once its owner lets it close, and never from a list it scrolls.
|
|
527
|
+
if (custom && (event.pointerType === "mouse" || !custom.swipeable() || target?.closest("ol, ul, [role='region'], a, button, input"))) return;
|
|
528
|
+
gesture = {
|
|
529
|
+
id: event.pointerId,
|
|
530
|
+
x: event.clientX,
|
|
531
|
+
y: event.clientY,
|
|
532
|
+
at: event.timeStamp,
|
|
533
|
+
axis: null,
|
|
534
|
+
dx: 0,
|
|
535
|
+
dy: 0
|
|
536
|
+
};
|
|
537
|
+
setHold(gestureHolds, card, true);
|
|
538
|
+
});
|
|
539
|
+
card.addEventListener("pointermove", event => {
|
|
540
|
+
if (!gesture || event.pointerId !== gesture.id) return;
|
|
541
|
+
const dx = event.clientX - gesture.x;
|
|
542
|
+
const dy = event.clientY - gesture.y;
|
|
543
|
+
if (!gesture.axis) {
|
|
544
|
+
if (Math.abs(dx) < SWIPE_AXIS_PX && Math.abs(dy) < SWIPE_AXIS_PX) return;
|
|
545
|
+
gesture.axis = Math.abs(dx) > Math.abs(dy) ? "x" : "y";
|
|
546
|
+
card.setPointerCapture?.(event.pointerId);
|
|
547
|
+
slot.dataset.swiping = "true";
|
|
548
|
+
}
|
|
549
|
+
gesture.dx = dx;
|
|
550
|
+
gesture.dy = dy;
|
|
551
|
+
const x = gesture.axis === "x" ? allowed(dx > 0 ? "right" : "left") ? dx : resisted(dx) : 0;
|
|
552
|
+
const y = gesture.axis === "y" ? allowed(dy > 0 ? "down" : "up") ? dy : resisted(dy) : 0;
|
|
553
|
+
slot.style.setProperty("--k2b-toast-swipe-x", `${x}px`);
|
|
554
|
+
slot.style.setProperty("--k2b-toast-swipe-y", `${y}px`);
|
|
555
|
+
slot.style.setProperty("--k2b-toast-fade", String(Math.max(0.35, 1 - Math.hypot(x, y) / 220)));
|
|
556
|
+
});
|
|
557
|
+
const release = () => {
|
|
558
|
+
gesture = null;
|
|
559
|
+
delete slot.dataset.swiping;
|
|
560
|
+
slot.style.setProperty("--k2b-toast-fade", "1");
|
|
561
|
+
setHold(gestureHolds, card, false);
|
|
562
|
+
};
|
|
563
|
+
const end = (event, cancelled) => {
|
|
564
|
+
if (!gesture || event.pointerId !== gesture.id) return;
|
|
565
|
+
const ended = gesture;
|
|
566
|
+
release();
|
|
567
|
+
const owner = rail();
|
|
568
|
+
if (ended.axis && !cancelled) {
|
|
569
|
+
swallowNextClick(card);
|
|
570
|
+
const distance = ended.axis === "x" ? ended.dx : ended.dy;
|
|
571
|
+
const direction = ended.axis === "x" ? distance > 0 ? "right" : "left" : distance > 0 ? "down" : "up";
|
|
572
|
+
const speed = Math.abs(distance) / Math.max(1, event.timeStamp - ended.at);
|
|
573
|
+
if (allowed(direction) && (Math.abs(distance) >= SWIPE_DISMISS_PX || speed > SWIPE_DISMISS_SPEED)) {
|
|
574
|
+
slot.style.setProperty(ended.axis === "x" ? "--k2b-toast-swipe-x" : "--k2b-toast-swipe-y", `${Math.sign(distance) * (ended.axis === "x" ? 110 : 140)}%`);
|
|
575
|
+
dismiss(true);
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
} else if (!ended.axis && !cancelled && event.pointerType !== "mouse" && owner && !custom) {
|
|
579
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
580
|
+
if (!target?.closest("a, button")) setHold(tapHolds, owner, !tapHolds.has(owner));
|
|
581
|
+
}
|
|
582
|
+
slot.style.setProperty("--k2b-toast-swipe-x", "0px");
|
|
583
|
+
slot.style.setProperty("--k2b-toast-swipe-y", "0px");
|
|
584
|
+
};
|
|
585
|
+
card.addEventListener("pointerup", event => end(event, false));
|
|
586
|
+
card.addEventListener("pointercancel", event => end(event, true));
|
|
587
|
+
card.addEventListener("lostpointercapture", event => end(event, true));
|
|
588
|
+
// Before its axis locks, a gesture has no pointer capture: a pointer that leaves the card ends it, so it never pauses the timers for good.
|
|
589
|
+
card.addEventListener("pointerleave", event => {
|
|
590
|
+
if (gesture && !gesture.axis) end(event, true);
|
|
591
|
+
});
|
|
592
|
+
// A toast that closes in the middle of a gesture, by its timer's neighbour, an update, or the rail limit, lets go.
|
|
593
|
+
return () => {
|
|
594
|
+
if (gesture) release();
|
|
595
|
+
};
|
|
596
|
+
};
|
|
597
|
+
|
|
217
598
|
/**
|
|
218
599
|
* The rail is full: older timed confirmations leave first, then older errors and sticky toasts. Running progress, the
|
|
219
600
|
* newest toast, and a toast under the pointer or with focus stay; the rail waits until they are released.
|
|
220
601
|
*/
|
|
221
602
|
function enforceCap() {
|
|
222
|
-
|
|
223
|
-
const cap = narrow ? MAX_VISIBLE_TOASTS_NARROW : MAX_VISIBLE_TOASTS;
|
|
224
|
-
while (liveToasts.size > cap) {
|
|
603
|
+
while (liveToasts.size > MAX_VISIBLE_TOASTS) {
|
|
225
604
|
const older = Array.from(liveToasts).slice(0, -1).filter(item => !item.held());
|
|
226
605
|
const victim = older.find(item => !item.keep()) ?? older.find(item => !item.progress());
|
|
227
606
|
if (!victim) return;
|
|
228
607
|
victim.dismiss();
|
|
229
608
|
}
|
|
230
609
|
}
|
|
610
|
+
|
|
611
|
+
/** The kind of button an action becomes in its place. */
|
|
612
|
+
const actionVariant = (action, paired, first) => paired ? first ? "primary" : "secondary" : action.variant ?? "secondary";
|
|
231
613
|
const showToast = (description, options) => {
|
|
232
614
|
const initialContainer = ensureContainer();
|
|
233
615
|
if (!initialContainer) {
|
|
@@ -245,7 +627,13 @@ const showToast = (description, options) => {
|
|
|
245
627
|
let dismissTimer = null;
|
|
246
628
|
let currentVariant = options?.variant ?? "default";
|
|
247
629
|
let currentProgress = options?.progress ?? null;
|
|
630
|
+
let currentCelebrate = options?.celebrate ?? false;
|
|
248
631
|
let currentAction = options?.action ?? null;
|
|
632
|
+
let currentSecondary = options?.secondaryAction ?? null;
|
|
633
|
+
let currentLink = options?.link ?? null;
|
|
634
|
+
let currentTitle = options?.title;
|
|
635
|
+
let currentDescription = description;
|
|
636
|
+
let dismissLabel = options?.dismissLabel;
|
|
249
637
|
let explicitDuration = options?.duration;
|
|
250
638
|
let remainingDuration = 0;
|
|
251
639
|
let timerStartedAt = 0;
|
|
@@ -254,8 +642,17 @@ const showToast = (description, options) => {
|
|
|
254
642
|
toastElement.className = "k2b-toast";
|
|
255
643
|
toastElement.dataset.tone = VARIANT_STYLES[currentVariant].tone;
|
|
256
644
|
toastElement.dataset.k2bToast = "";
|
|
645
|
+
|
|
646
|
+
// The first control in the toast: a round button over its top-left corner.
|
|
647
|
+
const closeButton = doc.createElement("button");
|
|
648
|
+
closeButton.type = "button";
|
|
649
|
+
closeButton.className = "k2b-toast__close";
|
|
650
|
+
const closeIcon = doc.createElement("i");
|
|
651
|
+
closeIcon.className = "ti ti-x";
|
|
652
|
+
closeIcon.setAttribute("aria-hidden", "true");
|
|
653
|
+
closeButton.appendChild(closeIcon);
|
|
257
654
|
const leadElement = doc.createElement("div");
|
|
258
|
-
leadElement.className = "k2b-toast__icon";
|
|
655
|
+
leadElement.className = "k2b-toast__icon k2b-icon-tile";
|
|
259
656
|
leadElement.setAttribute("aria-hidden", "true");
|
|
260
657
|
const leadIconElement = doc.createElement("i");
|
|
261
658
|
leadElement.appendChild(leadIconElement);
|
|
@@ -264,38 +661,40 @@ const showToast = (description, options) => {
|
|
|
264
661
|
applyIconClass(leadIconElement, iconClassOverride ?? VARIANT_STYLES[currentVariant].iconClass);
|
|
265
662
|
};
|
|
266
663
|
renderLead(options?.iconClass);
|
|
664
|
+
// The check takes the glyph's place and draws as it enters; updates that keep it leave it still.
|
|
665
|
+
let checkElement = null;
|
|
666
|
+
const renderCheck = () => {
|
|
667
|
+
const celebrating = currentCelebrate && currentVariant === "success" && currentProgress === null;
|
|
668
|
+
if (!celebrating) {
|
|
669
|
+
if (checkElement?.isConnected) checkElement.replaceWith(leadIconElement);
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
checkElement ??= createSuccessCheck(doc);
|
|
673
|
+
if (!checkElement.isConnected) leadIconElement.replaceWith(checkElement);
|
|
674
|
+
};
|
|
675
|
+
renderCheck();
|
|
267
676
|
const contentElement = doc.createElement("div");
|
|
268
677
|
contentElement.className = "k2b-toast__content";
|
|
269
678
|
const titleElement = doc.createElement("div");
|
|
270
679
|
titleElement.className = "k2b-toast__title";
|
|
271
|
-
const renderTitle = title => {
|
|
272
|
-
titleElement.textContent = title ?? "";
|
|
273
|
-
titleElement.hidden = !title;
|
|
274
|
-
};
|
|
275
|
-
renderTitle(options?.title);
|
|
276
680
|
const descriptionElement = doc.createElement("div");
|
|
277
681
|
descriptionElement.className = "k2b-toast__description";
|
|
278
|
-
|
|
279
|
-
contentElement.append(titleElement, descriptionElement);
|
|
280
|
-
const closeButton = doc.createElement("button");
|
|
281
|
-
closeButton.type = "button";
|
|
282
|
-
closeButton.className = "k2b-toast__close";
|
|
283
|
-
closeButton.setAttribute("aria-label", options?.dismissLabel ?? toastMessages.dismissNotification);
|
|
284
|
-
const closeIcon = doc.createElement("i");
|
|
285
|
-
closeIcon.className = "ti ti-x";
|
|
286
|
-
closeIcon.setAttribute("aria-hidden", "true");
|
|
287
|
-
closeButton.appendChild(closeIcon);
|
|
288
|
-
|
|
289
|
-
// Inside the content, so a titled progress toast can place the bar between its title and its summary line.
|
|
682
|
+
// A titled progress toast places the bar between its title and its summary line.
|
|
290
683
|
const progressElement = doc.createElement("progress");
|
|
291
684
|
progressElement.className = "k2b-toast__progress";
|
|
292
685
|
progressElement.max = 1;
|
|
293
|
-
contentElement.
|
|
294
|
-
|
|
686
|
+
contentElement.append(titleElement, descriptionElement, progressElement);
|
|
687
|
+
|
|
688
|
+
// One action stays beside the message; two go to a row under it.
|
|
689
|
+
const endElement = doc.createElement("div");
|
|
690
|
+
endElement.className = "k2b-toast__end";
|
|
691
|
+
const actionsElement = doc.createElement("div");
|
|
692
|
+
actionsElement.className = "k2b-toast__actions";
|
|
693
|
+
toastElement.append(closeButton, leadElement, contentElement, endElement, actionsElement);
|
|
295
694
|
const item = railItem(toastElement);
|
|
296
|
-
const text = () => [
|
|
297
|
-
const effectiveDuration = () => explicitDuration ?? defaultDuration(currentVariant, text(), currentAction !== null);
|
|
298
|
-
/** The error word is read before the message; the
|
|
695
|
+
const text = () => [currentTitle, currentDescription].filter(Boolean).join(". ");
|
|
696
|
+
const effectiveDuration = () => explicitDuration ?? defaultDuration(currentVariant, text(), currentAction !== null || currentSecondary !== null);
|
|
697
|
+
/** The error word is read before the message; the actions and the link are left out. */
|
|
299
698
|
const spoken = () => currentVariant === "error" ? `${resolveUiMessages().error}: ${text()}` : text();
|
|
300
699
|
const say = () => {
|
|
301
700
|
lastAnnouncement = spoken();
|
|
@@ -303,6 +702,38 @@ const showToast = (description, options) => {
|
|
|
303
702
|
politeness: currentVariant === "error" ? "assertive" : "polite"
|
|
304
703
|
});
|
|
305
704
|
};
|
|
705
|
+
const renderClose = () => {
|
|
706
|
+
closeButton.setAttribute("aria-label", dismissLabel ?? toastMessages.dismissNamed({
|
|
707
|
+
name: currentTitle || currentDescription
|
|
708
|
+
}));
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
// The message is one text node; the link after it is one element kept across updates, so focus on it survives them.
|
|
712
|
+
const descriptionText = doc.createTextNode("");
|
|
713
|
+
const linkElement = doc.createElement("a");
|
|
714
|
+
linkElement.className = "k2b-toast__link";
|
|
715
|
+
linkElement.addEventListener("click", () => dismiss());
|
|
716
|
+
descriptionElement.append(descriptionText);
|
|
717
|
+
const renderText = () => {
|
|
718
|
+
titleElement.textContent = currentTitle ?? "";
|
|
719
|
+
titleElement.hidden = !currentTitle;
|
|
720
|
+
descriptionText.data = currentDescription;
|
|
721
|
+
const href = currentLink ? safeHref(currentLink.href) : null;
|
|
722
|
+
if (currentLink && href !== null) {
|
|
723
|
+
linkElement.href = href;
|
|
724
|
+
linkElement.textContent = currentLink.label;
|
|
725
|
+
if (!linkElement.isConnected) descriptionElement.append(" ", linkElement);
|
|
726
|
+
} else if (linkElement.isConnected) {
|
|
727
|
+
// A removed link hands its focus to the close button, so the keyboard stays in the toast.
|
|
728
|
+
const focused = linkElement.contains(doc.activeElement);
|
|
729
|
+
descriptionElement.replaceChildren(descriptionText);
|
|
730
|
+
if (focused) closeButton.focus({
|
|
731
|
+
preventScroll: true
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
renderClose();
|
|
735
|
+
};
|
|
736
|
+
renderText();
|
|
306
737
|
const clearDismissTimer = () => {
|
|
307
738
|
if (dismissTimer === null) return;
|
|
308
739
|
clearTimeout(dismissTimer);
|
|
@@ -346,60 +777,74 @@ const showToast = (description, options) => {
|
|
|
346
777
|
preventScroll: true
|
|
347
778
|
});else doc.activeElement?.blur();
|
|
348
779
|
};
|
|
349
|
-
const dismiss = () => {
|
|
780
|
+
const dismiss = (swiped = false) => {
|
|
350
781
|
if (dismissed) return;
|
|
351
782
|
dismissed = true;
|
|
352
783
|
clearDismissTimer();
|
|
353
784
|
liveToasts.delete(live);
|
|
354
785
|
doc.removeEventListener("visibilitychange", onVisibilityChange);
|
|
355
786
|
moveFocusAway();
|
|
356
|
-
|
|
787
|
+
cancelGesture();
|
|
788
|
+
item.close({
|
|
789
|
+
swiped
|
|
790
|
+
});
|
|
357
791
|
};
|
|
358
792
|
const renderProgress = () => {
|
|
359
|
-
|
|
793
|
+
// Work of unknown length shows the spinner in the tile instead of a bar, so its result keeps the same rows.
|
|
794
|
+
progressElement.hidden = typeof currentProgress !== "number";
|
|
360
795
|
toastElement.dataset.progress = String(currentProgress !== null);
|
|
361
|
-
|
|
362
|
-
const summary = descriptionElement.textContent ?? "";
|
|
363
|
-
progressElement.setAttribute("aria-label", title || summary);
|
|
796
|
+
progressElement.setAttribute("aria-label", currentTitle || currentDescription);
|
|
364
797
|
// With a title, the message is the summary line under the bar ("6 of 12 files"), read instead of a bare percentage.
|
|
365
|
-
if (typeof currentProgress === "number" &&
|
|
798
|
+
if (typeof currentProgress === "number" && currentTitle && currentDescription) progressElement.setAttribute("aria-valuetext", currentDescription);else progressElement.removeAttribute("aria-valuetext");
|
|
366
799
|
if (typeof currentProgress === "number") progressElement.value = Number.isFinite(currentProgress) ? Math.max(0, Math.min(1, currentProgress)) : 0;else progressElement.removeAttribute("value");
|
|
367
800
|
};
|
|
368
801
|
renderProgress();
|
|
369
|
-
|
|
370
|
-
const createAction = action => {
|
|
802
|
+
const createAction = (action, variant) => {
|
|
371
803
|
let element;
|
|
372
|
-
|
|
804
|
+
const href = "href" in action ? safeHref(action.href) : null;
|
|
805
|
+
if (href !== null) {
|
|
373
806
|
element = doc.createElement("a");
|
|
374
|
-
element.href =
|
|
807
|
+
element.href = href;
|
|
375
808
|
} else {
|
|
376
809
|
element = doc.createElement("button");
|
|
377
810
|
element.type = "button";
|
|
378
811
|
}
|
|
379
812
|
element.className = "k2b-toast__action";
|
|
813
|
+
element.dataset.variant = variant;
|
|
380
814
|
element.textContent = action.label;
|
|
381
815
|
element.addEventListener("click", () => {
|
|
382
816
|
if ("onClick" in action) action.onClick();else dismiss();
|
|
383
817
|
});
|
|
384
818
|
return element;
|
|
385
819
|
};
|
|
386
|
-
const
|
|
387
|
-
const previous =
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
820
|
+
const renderActions = () => {
|
|
821
|
+
const previous = Array.from(toastElement.querySelectorAll(".k2b-toast__action"));
|
|
822
|
+
const focusedIndex = previous.findIndex(element => element.contains(doc.activeElement));
|
|
823
|
+
const actions = [currentAction, currentSecondary].filter(action => action !== null);
|
|
824
|
+
const paired = actions.length > 1;
|
|
825
|
+
const elements = actions.map((action, index) => createAction(action, actionVariant(action, paired, index === 0)));
|
|
826
|
+
(paired ? actionsElement : endElement).append(...elements);
|
|
827
|
+
endElement.hidden = paired || elements.length === 0;
|
|
828
|
+
actionsElement.hidden = !paired;
|
|
829
|
+
// The keyboard stays in the toast, on the new action in the same place or the close button, instead of falling to the page.
|
|
830
|
+
if (focusedIndex >= 0) (elements[focusedIndex] ?? elements.at(-1) ?? closeButton).focus({
|
|
393
831
|
preventScroll: true
|
|
394
832
|
});
|
|
395
|
-
previous
|
|
833
|
+
for (const element of previous) element.remove();
|
|
834
|
+
};
|
|
835
|
+
renderActions();
|
|
836
|
+
|
|
837
|
+
/** A result that replaces the message in place fades in, so the change is seen without the toast moving. */
|
|
838
|
+
const markSwap = () => {
|
|
839
|
+
delete contentElement.dataset.swap;
|
|
840
|
+
void contentElement.offsetWidth;
|
|
841
|
+
contentElement.dataset.swap = "true";
|
|
396
842
|
};
|
|
397
|
-
renderAction(options?.action);
|
|
398
843
|
const update = (nextDescription, nextOptions) => {
|
|
399
844
|
if (dismissed) return;
|
|
400
845
|
const has = key => nextOptions !== undefined && Object.prototype.hasOwnProperty.call(nextOptions, key);
|
|
401
846
|
const previousProgress = currentProgress;
|
|
402
|
-
|
|
847
|
+
currentDescription = nextDescription;
|
|
403
848
|
const variantChanged = nextOptions?.variant !== undefined && nextOptions.variant !== currentVariant;
|
|
404
849
|
if (variantChanged) {
|
|
405
850
|
currentVariant = nextOptions.variant;
|
|
@@ -408,13 +853,22 @@ const showToast = (description, options) => {
|
|
|
408
853
|
} else if (nextOptions?.iconClass !== undefined) {
|
|
409
854
|
applyIconClass(leadIconElement, nextOptions.iconClass);
|
|
410
855
|
}
|
|
411
|
-
if (has("title"))
|
|
412
|
-
if (has("
|
|
856
|
+
if (has("title")) currentTitle = nextOptions.title;
|
|
857
|
+
if (has("link")) currentLink = nextOptions.link ?? null;
|
|
858
|
+
if (nextOptions?.dismissLabel) dismissLabel = nextOptions.dismissLabel;
|
|
859
|
+
renderText();
|
|
860
|
+
if (has("action") || has("secondaryAction")) {
|
|
861
|
+
if (has("action")) currentAction = nextOptions.action ?? null;
|
|
862
|
+
if (has("secondaryAction")) currentSecondary = nextOptions.secondaryAction ?? null;
|
|
863
|
+
renderActions();
|
|
864
|
+
}
|
|
413
865
|
if (has("duration")) explicitDuration = nextOptions.duration;
|
|
414
866
|
if (has("progress")) currentProgress = nextOptions.progress ?? null;
|
|
415
|
-
if (
|
|
867
|
+
if (has("celebrate")) currentCelebrate = nextOptions.celebrate ?? false;
|
|
416
868
|
renderProgress();
|
|
869
|
+
renderCheck();
|
|
417
870
|
resetDismissTimer();
|
|
871
|
+
if (variantChanged || previousProgress !== null && currentProgress === null) markSwap();
|
|
418
872
|
|
|
419
873
|
// Progress is announced at its start, half way, and its end, never at every step, and only with something new to say.
|
|
420
874
|
// The comparison includes the error word, so a change to an error with the same text is still announced.
|
|
@@ -432,12 +886,13 @@ const showToast = (description, options) => {
|
|
|
432
886
|
dismiss();
|
|
433
887
|
});
|
|
434
888
|
doc.addEventListener("visibilitychange", onVisibilityChange);
|
|
889
|
+
const cancelGesture = attachGestures(item, toastElement, swiped => dismiss(swiped));
|
|
435
890
|
const handle = {
|
|
436
|
-
dismiss,
|
|
891
|
+
dismiss: () => dismiss(),
|
|
437
892
|
update
|
|
438
893
|
};
|
|
439
894
|
const live = {
|
|
440
|
-
dismiss,
|
|
895
|
+
dismiss: () => dismiss(),
|
|
441
896
|
keep: () => currentVariant === "error" || currentProgress !== null || effectiveDuration() === 0,
|
|
442
897
|
progress: () => currentProgress !== null,
|
|
443
898
|
held: () => pointerHolds.has(toastElement) || focusHolds.has(toastElement),
|
|
@@ -454,17 +909,21 @@ const showToast = (description, options) => {
|
|
|
454
909
|
};
|
|
455
910
|
|
|
456
911
|
/*
|
|
457
|
-
* A custom slot shares the rail, chrome, and
|
|
458
|
-
*
|
|
459
|
-
* toast limit nor `dismissAll` removes it: the application that placed it decides when it goes.
|
|
912
|
+
* A custom slot shares the rail, chrome, and motion with toasts, and is pinned at the rail's edge: toasts stack in
|
|
913
|
+
* front of it instead of covering it. It has no timer, close button, swipe, or live region of its own, and neither
|
|
914
|
+
* the toast limit nor `dismissAll` removes it: the application that placed it decides when it goes.
|
|
460
915
|
*/
|
|
461
|
-
const showCustom = content => {
|
|
916
|
+
const showCustom = (content, options) => {
|
|
462
917
|
const initialContainer = ensureContainer();
|
|
463
918
|
if (!initialContainer) return {
|
|
464
|
-
dismiss: () => {}
|
|
919
|
+
dismiss: () => {},
|
|
920
|
+
update: () => {}
|
|
465
921
|
};
|
|
922
|
+
const doc = initialContainer.ownerDocument;
|
|
466
923
|
let dismissed = false;
|
|
467
|
-
|
|
924
|
+
let label = options?.label;
|
|
925
|
+
let closable = options?.closable === true;
|
|
926
|
+
const slotElement = doc.createElement("div");
|
|
468
927
|
slotElement.className = "k2b-toast";
|
|
469
928
|
slotElement.dataset.k2bToast = "";
|
|
470
929
|
slotElement.dataset.custom = "true";
|
|
@@ -472,25 +931,77 @@ const showCustom = content => {
|
|
|
472
931
|
slotElement.dataset.persistent = "true";
|
|
473
932
|
slotElement.append(content);
|
|
474
933
|
const item = railItem(slotElement);
|
|
475
|
-
const dismiss = () => {
|
|
934
|
+
const dismiss = (swiped = false) => {
|
|
476
935
|
if (dismissed) return;
|
|
477
936
|
dismissed = true;
|
|
478
|
-
|
|
937
|
+
cancelGesture();
|
|
938
|
+
item.close({
|
|
939
|
+
swiped
|
|
940
|
+
});
|
|
941
|
+
};
|
|
942
|
+
const requestClose = (swiped = false) => {
|
|
943
|
+
if (options?.onClose) options.onClose();else dismiss(swiped);
|
|
944
|
+
};
|
|
945
|
+
|
|
946
|
+
// While its owner keeps it open, the slot has no close button at all, so no hidden or dead control is in reach.
|
|
947
|
+
let closeButton = null;
|
|
948
|
+
const render = () => {
|
|
949
|
+
slotElement.dataset.closable = String(closable);
|
|
950
|
+
if (closable && !closeButton) {
|
|
951
|
+
closeButton = doc.createElement("button");
|
|
952
|
+
closeButton.type = "button";
|
|
953
|
+
closeButton.className = "k2b-toast__close";
|
|
954
|
+
const icon = doc.createElement("i");
|
|
955
|
+
icon.className = "ti ti-x";
|
|
956
|
+
icon.setAttribute("aria-hidden", "true");
|
|
957
|
+
closeButton.append(icon);
|
|
958
|
+
closeButton.addEventListener("click", () => requestClose());
|
|
959
|
+
slotElement.prepend(closeButton);
|
|
960
|
+
} else if (!closable && closeButton) {
|
|
961
|
+
const focused = closeButton.contains(doc.activeElement);
|
|
962
|
+
closeButton.remove();
|
|
963
|
+
closeButton = null;
|
|
964
|
+
if (focused) (content.querySelector("button, a[href], [tabindex]:not([tabindex='-1'])") ?? content).focus?.({
|
|
965
|
+
preventScroll: true
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
closeButton?.setAttribute("aria-label", resolveToastMessages().dismissNamed({
|
|
969
|
+
name: label ?? resolveToastMessages().notifications
|
|
970
|
+
}));
|
|
971
|
+
};
|
|
972
|
+
render();
|
|
973
|
+
|
|
974
|
+
// Escape closes a slot that may close; on running work it folds the stack and gives focus back.
|
|
975
|
+
slotElement.addEventListener("keydown", event => {
|
|
976
|
+
if (event.key !== "Escape" || event.defaultPrevented) return;
|
|
977
|
+
event.preventDefault();
|
|
978
|
+
event.stopPropagation();
|
|
979
|
+
if (closable) requestClose();else {
|
|
980
|
+
const rail = item.slot.parentElement;
|
|
981
|
+
if (rail) foldStack(rail);
|
|
982
|
+
}
|
|
983
|
+
});
|
|
984
|
+
const cancelGesture = attachGestures(item, slotElement, swiped => swiped ? dismissSwiped() : requestClose(), {
|
|
985
|
+
swipeable: () => closable
|
|
986
|
+
});
|
|
987
|
+
// A swipe has already flown the slot out; the owner still decides, so it closes the slot the same way.
|
|
988
|
+
const dismissSwiped = () => {
|
|
989
|
+
dismiss(true);
|
|
990
|
+
options?.onClose?.();
|
|
479
991
|
};
|
|
480
992
|
promoteToTopLayer(initialContainer).appendChild(item.slot);
|
|
481
993
|
item.open();
|
|
482
994
|
return {
|
|
483
|
-
dismiss
|
|
995
|
+
dismiss: () => dismiss(),
|
|
996
|
+
update: next => {
|
|
997
|
+
if (dismissed) return;
|
|
998
|
+
if (Object.prototype.hasOwnProperty.call(next, "label")) label = next.label;
|
|
999
|
+
if (next.closable !== undefined) closable = next.closable;
|
|
1000
|
+
render();
|
|
1001
|
+
}
|
|
484
1002
|
};
|
|
485
1003
|
};
|
|
486
|
-
export
|
|
487
|
-
if (typeof document === "undefined") return false;
|
|
488
|
-
for (const card of Array.from(document.querySelectorAll(`[${CONTAINER_ATTRIBUTE}] [data-k2b-toast]`))) {
|
|
489
|
-
const rect = card.getBoundingClientRect();
|
|
490
|
-
if (x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom) return true;
|
|
491
|
-
}
|
|
492
|
-
return false;
|
|
493
|
-
};
|
|
1004
|
+
export { isPointInsideToast } from "./toast-hit";
|
|
494
1005
|
const toastFn = (description, options) => showToast(description, options);
|
|
495
1006
|
toastFn.success = (description, options) => showToast(description, {
|
|
496
1007
|
...options,
|