@k2b/ui 0.57.1 → 0.59.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 +1 -0
- package/dist/browser/actions/ContextMenu.js +5 -2
- package/dist/browser/actions/ContextMenu.js.map +1 -1
- package/dist/browser/actions/Dropdown.js +4 -3
- package/dist/browser/actions/Dropdown.js.map +1 -1
- package/dist/browser/actions/Tabs.js +58 -19
- package/dist/browser/actions/Tabs.js.map +1 -1
- package/dist/browser/actions/Toolbar.js +66 -60
- package/dist/browser/actions/Toolbar.js.map +1 -1
- package/dist/browser/actions/ViewTabs.js +89 -73
- package/dist/browser/actions/ViewTabs.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/menu-rows.js +1 -1
- package/dist/browser/actions/menu-rows.js.map +1 -1
- package/dist/browser/charts/core/snapshot.js +3 -1
- package/dist/browser/charts/core/snapshot.js.map +1 -1
- package/dist/browser/chat/ChatComposer.js +832 -679
- package/dist/browser/chat/ChatComposer.js.map +1 -1
- package/dist/browser/chat/ChatContextPopup.js +34 -4
- package/dist/browser/chat/ChatContextPopup.js.map +1 -1
- package/dist/browser/chat/ChatPrimitives.js +471 -284
- package/dist/browser/chat/ChatPrimitives.js.map +1 -1
- package/dist/browser/chat/ChatTasks.js +218 -80
- package/dist/browser/chat/ChatTasks.js.map +1 -1
- package/dist/browser/chat/ChatTimeline.js +5 -3
- package/dist/browser/chat/ChatTimeline.js.map +1 -1
- package/dist/browser/chat/chat-behavior.js +12 -0
- package/dist/browser/chat/chat-behavior.js.map +1 -1
- package/dist/browser/chat/chat-messages.js +50 -2
- package/dist/browser/chat/chat-messages.js.map +1 -1
- package/dist/browser/chat/index.js +2 -1
- package/dist/browser/chat/index.js.map +1 -1
- package/dist/browser/chat/types.js.map +1 -1
- package/dist/browser/content/Calendar.js +2 -2
- package/dist/browser/content/Calendar.js.map +1 -1
- package/dist/browser/content/CalendarWeekView.js +9 -2
- package/dist/browser/content/CalendarWeekView.js.map +1 -1
- package/dist/browser/content/ChartRoot.js +4 -1
- package/dist/browser/content/ChartRoot.js.map +1 -1
- package/dist/browser/content/DataTable.js +9 -0
- package/dist/browser/content/DataTable.js.map +1 -1
- package/dist/browser/content/Lightbox.js +2 -2
- package/dist/browser/content/Lightbox.js.map +1 -1
- package/dist/browser/content/PdfPages.js +160 -44
- package/dist/browser/content/PdfPages.js.map +1 -1
- package/dist/browser/content/PdfViewer.js +59 -21
- package/dist/browser/content/PdfViewer.js.map +1 -1
- package/dist/browser/content/ProgressPath.js +101 -0
- package/dist/browser/content/ProgressPath.js.map +1 -0
- package/dist/browser/content/Timeline.js +1 -1
- package/dist/browser/content/Timeline.js.map +1 -1
- package/dist/browser/content/chart-tick-room.js +59 -0
- package/dist/browser/content/chart-tick-room.js.map +1 -0
- package/dist/browser/content/index.js +1 -0
- package/dist/browser/content/index.js.map +1 -1
- package/dist/browser/content/pdf-viewer-engine.js +1 -1
- package/dist/browser/feedback/HoverCard.js +535 -0
- package/dist/browser/feedback/HoverCard.js.map +1 -0
- package/dist/browser/feedback/Tooltip.js +5 -2
- package/dist/browser/feedback/Tooltip.js.map +1 -1
- package/dist/browser/feedback/dialog-core.js +12 -8
- package/dist/browser/feedback/dialog-core.js.map +1 -1
- package/dist/browser/feedback/index.js +1 -0
- package/dist/browser/feedback/index.js.map +1 -1
- package/dist/browser/feedback/prompt-confirm.js +3 -17
- package/dist/browser/feedback/prompt-confirm.js.map +1 -1
- package/dist/browser/feedback/prompt-sheet-view.js +95 -0
- package/dist/browser/feedback/prompt-sheet-view.js.map +1 -0
- package/dist/browser/feedback/prompt-sheet.js +36 -0
- package/dist/browser/feedback/prompt-sheet.js.map +1 -0
- package/dist/browser/feedback/prompts.js +14 -38
- package/dist/browser/feedback/prompts.js.map +1 -1
- package/dist/browser/feedback/toast.js +17 -12
- package/dist/browser/feedback/toast.js.map +1 -1
- package/dist/browser/internal/anchor-placement.js +38 -0
- package/dist/browser/internal/anchor-placement.js.map +1 -0
- package/dist/browser/internal/portal-scope.js +36 -0
- package/dist/browser/internal/portal-scope.js.map +1 -0
- package/dist/browser/internal/portal.js +13 -10
- package/dist/browser/internal/portal.js.map +1 -1
- package/dist/browser/intl/messages.js +10 -0
- package/dist/browser/intl/messages.js.map +1 -1
- package/dist/browser/layout/AnchoredPopover.js +10 -25
- package/dist/browser/layout/AnchoredPopover.js.map +1 -1
- package/dist/browser/layout/BottomSheet.js +1 -12
- package/dist/browser/layout/BottomSheet.js.map +1 -1
- package/dist/browser/layout/Discussion.js +298 -3
- package/dist/browser/layout/Discussion.js.map +1 -1
- package/dist/browser/layout/FloatingWindow.js +124 -75
- package/dist/browser/layout/FloatingWindow.js.map +1 -1
- package/dist/browser/layout/Panes.js +643 -212
- package/dist/browser/layout/Panes.js.map +1 -1
- package/dist/browser/layout/index.js +1 -1
- package/dist/browser/layout/index.js.map +1 -1
- package/dist/browser/layout/panes-layout.js +169 -0
- package/dist/browser/layout/panes-layout.js.map +1 -1
- package/dist/browser/layout/panes-messages.js +108 -2
- package/dist/browser/layout/panes-messages.js.map +1 -1
- package/dist/browser/layout/panes-preview-scope.js +9 -0
- package/dist/browser/layout/panes-preview-scope.js.map +1 -0
- package/dist/browser/layout/sheet-handle.js +173 -37
- package/dist/browser/layout/sheet-handle.js.map +1 -1
- package/dist/browser/layout/sheet-motion.js +38 -5
- package/dist/browser/layout/sheet-motion.js.map +1 -1
- package/dist/browser/panes.js +3 -0
- package/dist/browser/panes.js.map +1 -0
- package/dist/browser/surfaces/ChangeList.js +78 -16
- package/dist/browser/surfaces/ChangeList.js.map +1 -1
- package/dist/browser/surfaces/DotStrip.js +126 -41
- package/dist/browser/surfaces/DotStrip.js.map +1 -1
- package/dist/browser/surfaces/LinkCard.js +69 -16
- package/dist/browser/surfaces/LinkCard.js.map +1 -1
- package/dist/ssr/actions/ContextMenu.js +1 -0
- package/dist/ssr/actions/ContextMenu.js.map +1 -1
- package/dist/ssr/actions/Dropdown.js +4 -4
- package/dist/ssr/actions/Dropdown.js.map +1 -1
- package/dist/ssr/actions/Tabs.js +21 -6
- package/dist/ssr/actions/Tabs.js.map +1 -1
- package/dist/ssr/actions/Toolbar.js +24 -18
- package/dist/ssr/actions/Toolbar.js.map +1 -1
- package/dist/ssr/actions/ViewTabs.js +27 -20
- package/dist/ssr/actions/ViewTabs.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/menu-rows.js +1 -1
- package/dist/ssr/actions/menu-rows.js.map +1 -1
- package/dist/ssr/charts/core/snapshot.js +3 -1
- package/dist/ssr/charts/core/snapshot.js.map +1 -1
- package/dist/ssr/chat/ChatComposer.js +250 -142
- package/dist/ssr/chat/ChatComposer.js.map +1 -1
- package/dist/ssr/chat/ChatContextPopup.js +17 -1
- package/dist/ssr/chat/ChatContextPopup.js.map +1 -1
- package/dist/ssr/chat/ChatPrimitives.js +179 -51
- package/dist/ssr/chat/ChatPrimitives.js.map +1 -1
- package/dist/ssr/chat/ChatTasks.js +117 -27
- package/dist/ssr/chat/ChatTasks.js.map +1 -1
- package/dist/ssr/chat/ChatTimeline.js +5 -3
- package/dist/ssr/chat/ChatTimeline.js.map +1 -1
- package/dist/ssr/chat/chat-behavior.js +12 -0
- package/dist/ssr/chat/chat-behavior.js.map +1 -1
- package/dist/ssr/chat/chat-messages.js +50 -2
- package/dist/ssr/chat/chat-messages.js.map +1 -1
- package/dist/ssr/chat/index.js +2 -1
- package/dist/ssr/chat/index.js.map +1 -1
- package/dist/ssr/chat/types.js.map +1 -1
- package/dist/ssr/content/Calendar.js +2 -2
- package/dist/ssr/content/Calendar.js.map +1 -1
- package/dist/ssr/content/CalendarWeekView.js +9 -2
- package/dist/ssr/content/CalendarWeekView.js.map +1 -1
- package/dist/ssr/content/ChartRoot.js +4 -1
- package/dist/ssr/content/ChartRoot.js.map +1 -1
- package/dist/ssr/content/DataTable.js +9 -0
- package/dist/ssr/content/DataTable.js.map +1 -1
- package/dist/ssr/content/Lightbox.js +2 -2
- package/dist/ssr/content/Lightbox.js.map +1 -1
- package/dist/ssr/content/PdfPages.js +160 -44
- package/dist/ssr/content/PdfPages.js.map +1 -1
- package/dist/ssr/content/PdfViewer.js +40 -8
- package/dist/ssr/content/PdfViewer.js.map +1 -1
- package/dist/ssr/content/ProgressPath.js +51 -0
- package/dist/ssr/content/ProgressPath.js.map +1 -0
- package/dist/ssr/content/Timeline.js +1 -1
- package/dist/ssr/content/Timeline.js.map +1 -1
- package/dist/ssr/content/chart-tick-room.js +59 -0
- package/dist/ssr/content/chart-tick-room.js.map +1 -0
- package/dist/ssr/content/index.js +1 -0
- package/dist/ssr/content/index.js.map +1 -1
- package/dist/ssr/feedback/HoverCard.js +473 -0
- package/dist/ssr/feedback/HoverCard.js.map +1 -0
- package/dist/ssr/feedback/Tooltip.js +5 -2
- package/dist/ssr/feedback/Tooltip.js.map +1 -1
- package/dist/ssr/feedback/dialog-core.js +12 -8
- package/dist/ssr/feedback/dialog-core.js.map +1 -1
- package/dist/ssr/feedback/index.js +1 -0
- package/dist/ssr/feedback/index.js.map +1 -1
- package/dist/ssr/feedback/prompt-confirm.js +3 -17
- package/dist/ssr/feedback/prompt-confirm.js.map +1 -1
- package/dist/ssr/feedback/prompt-sheet-view.js +61 -0
- package/dist/ssr/feedback/prompt-sheet-view.js.map +1 -0
- package/dist/ssr/feedback/prompt-sheet.js +36 -0
- package/dist/ssr/feedback/prompt-sheet.js.map +1 -0
- package/dist/ssr/feedback/prompts.js +14 -38
- package/dist/ssr/feedback/prompts.js.map +1 -1
- package/dist/ssr/feedback/toast.js +17 -12
- package/dist/ssr/feedback/toast.js.map +1 -1
- package/dist/ssr/internal/anchor-placement.js +38 -0
- package/dist/ssr/internal/anchor-placement.js.map +1 -0
- package/dist/ssr/internal/portal-scope.js +36 -0
- package/dist/ssr/internal/portal-scope.js.map +1 -0
- package/dist/ssr/internal/portal.js +13 -10
- package/dist/ssr/internal/portal.js.map +1 -1
- package/dist/ssr/intl/messages.js +10 -0
- package/dist/ssr/intl/messages.js.map +1 -1
- package/dist/ssr/layout/AnchoredPopover.js +10 -25
- package/dist/ssr/layout/AnchoredPopover.js.map +1 -1
- package/dist/ssr/layout/BottomSheet.js +1 -12
- package/dist/ssr/layout/BottomSheet.js.map +1 -1
- package/dist/ssr/layout/Discussion.js +168 -2
- package/dist/ssr/layout/Discussion.js.map +1 -1
- package/dist/ssr/layout/FloatingWindow.js +39 -15
- package/dist/ssr/layout/FloatingWindow.js.map +1 -1
- package/dist/ssr/layout/Panes.js +399 -41
- package/dist/ssr/layout/Panes.js.map +1 -1
- package/dist/ssr/layout/index.js +1 -1
- package/dist/ssr/layout/index.js.map +1 -1
- package/dist/ssr/layout/panes-layout.js +169 -0
- package/dist/ssr/layout/panes-layout.js.map +1 -1
- package/dist/ssr/layout/panes-messages.js +108 -2
- package/dist/ssr/layout/panes-messages.js.map +1 -1
- package/dist/ssr/layout/panes-preview-scope.js +9 -0
- package/dist/ssr/layout/panes-preview-scope.js.map +1 -0
- package/dist/ssr/layout/sheet-handle.js +173 -37
- package/dist/ssr/layout/sheet-handle.js.map +1 -1
- package/dist/ssr/layout/sheet-motion.js +38 -5
- package/dist/ssr/layout/sheet-motion.js.map +1 -1
- package/dist/ssr/panes.js +3 -0
- package/dist/ssr/panes.js.map +1 -0
- package/dist/ssr/surfaces/ChangeList.js +37 -5
- package/dist/ssr/surfaces/ChangeList.js.map +1 -1
- package/dist/ssr/surfaces/DotStrip.js +75 -12
- package/dist/ssr/surfaces/DotStrip.js.map +1 -1
- package/dist/ssr/surfaces/LinkCard.js +46 -7
- package/dist/ssr/surfaces/LinkCard.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/types/actions/Dropdown.d.ts +4 -3
- package/dist/types/actions/Tabs.d.ts +9 -0
- package/dist/types/actions/ViewTabs.d.ts +2 -0
- package/dist/types/chat/ChatComposer.d.ts +24 -2
- package/dist/types/chat/ChatPrimitives.d.ts +6 -1
- package/dist/types/chat/ChatTasks.d.ts +14 -1
- package/dist/types/chat/chat-behavior.d.ts +14 -0
- package/dist/types/chat/chat-messages.d.ts +24 -0
- package/dist/types/chat/index.d.ts +5 -4
- package/dist/types/chat/types.d.ts +27 -0
- package/dist/types/content/PdfPages.d.ts +8 -3
- package/dist/types/content/PdfViewer.d.ts +12 -4
- package/dist/types/content/ProgressPath.d.ts +25 -0
- package/dist/types/content/chart-tick-room.d.ts +15 -0
- package/dist/types/content/index.d.ts +1 -0
- package/dist/types/feedback/HoverCard.d.ts +44 -0
- package/dist/types/feedback/Tooltip.d.ts +5 -0
- package/dist/types/feedback/index.d.ts +2 -0
- package/dist/types/feedback/prompt-confirm.d.ts +0 -2
- package/dist/types/feedback/prompt-sheet-view.d.ts +3 -0
- package/dist/types/feedback/prompt-sheet.d.ts +20 -0
- package/dist/types/feedback/toast.d.ts +5 -1
- package/dist/types/internal/anchor-placement.d.ts +23 -0
- package/dist/types/internal/portal-scope.d.ts +11 -0
- package/dist/types/internal/portal.d.ts +1 -1
- package/dist/types/intl/messages.d.ts +5 -0
- package/dist/types/layout/BottomSheet.d.ts +1 -5
- package/dist/types/layout/Discussion.d.ts +25 -0
- package/dist/types/layout/FloatingWindow.d.ts +6 -0
- package/dist/types/layout/Panes.d.ts +21 -0
- package/dist/types/layout/index.d.ts +3 -3
- package/dist/types/layout/panes-layout.d.ts +51 -0
- package/dist/types/layout/panes-messages.d.ts +55 -0
- package/dist/types/layout/panes-preview-scope.d.ts +2 -0
- package/dist/types/layout/sheet-handle.d.ts +17 -8
- package/dist/types/layout/sheet-motion.d.ts +5 -0
- package/dist/types/panes.d.ts +2 -0
- package/dist/types/surfaces/ChangeList.d.ts +23 -4
- package/dist/types/surfaces/DotStrip.d.ts +25 -5
- package/dist/types/surfaces/LinkCard.d.ts +13 -0
- package/package.json +8 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { suppressTextSelection } from "../internal/text-selection";
|
|
2
|
+
import { prefersReducedMotion } from "../motion";
|
|
2
3
|
/** Below this distance a press stays a press and the click after it moves the sheet. */
|
|
3
4
|
const DRAG_THRESHOLD = 6;
|
|
4
5
|
/** How far ahead the release projects the pointer's speed, so a short flick reaches the next detent. */
|
|
@@ -7,14 +8,22 @@ const PROJECTION_MS = 120;
|
|
|
7
8
|
const REST_MS = 80;
|
|
8
9
|
/** A release below this share of the lowest detent dismisses, when the sheet may be dismissed. */
|
|
9
10
|
const DISMISS_SHARE = 0.6;
|
|
11
|
+
/** Gliding to a detent and out, as `BottomSheet` does. */
|
|
12
|
+
const MOVE_MS = 280;
|
|
13
|
+
const CLOSE_MS = 220;
|
|
14
|
+
/** `--k2b-ease-out`: lands without overshoot. */
|
|
15
|
+
const EASE = "cubic-bezier(0.23, 1, 0.32, 1)";
|
|
10
16
|
|
|
11
17
|
/**
|
|
12
18
|
* Lets a sheet's handle drag it between detents. The handle stays a button: a press, by pointer, Enter or Space,
|
|
13
|
-
* moves the sheet to the next detent up, and from the highest back to the lowest.
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
19
|
+
* moves the sheet to the next detent up, and from the highest back to the lowest.
|
|
20
|
+
*
|
|
21
|
+
* The sheet moves by transform only, like `BottomSheet`. When a drag or a glide starts, its layout height is pinned
|
|
22
|
+
* at the highest detent and a transform shows the visible part; the content inside does not lay out again on every
|
|
23
|
+
* frame. A release glides to the detent nearest to where the pointer's speed would carry it; then the stylesheet's
|
|
24
|
+
* height for that detent takes over in one step that looks the same. Reduced motion makes every glide instant. The
|
|
25
|
+
* stylesheet owns every resting height, which keeps the server's first frame and a rotation correct without script;
|
|
26
|
+
* it must not transition `height`.
|
|
18
27
|
*/
|
|
19
28
|
export function attachSheetHandle(handle, options) {
|
|
20
29
|
const {
|
|
@@ -30,64 +39,173 @@ export function attachSheetHandle(handle, options) {
|
|
|
30
39
|
sheet.dataset.sheetDetent = detent;
|
|
31
40
|
if (changed) options.onChange?.(detent);
|
|
32
41
|
};
|
|
33
|
-
|
|
42
|
+
/** The painted height; an environment without layout, such as a test DOM, reports 0 and every move is instant. */
|
|
43
|
+
const heightOf = () => Number(sheet.getBoundingClientRect().height) || 0;
|
|
44
|
+
// Each detent's height as the stylesheet draws it now, while the transition is off.
|
|
34
45
|
const measure = () => {
|
|
35
46
|
const shown = sheet.dataset.sheetDetent;
|
|
36
47
|
const heights = detents.map(detent => {
|
|
37
48
|
sheet.dataset.sheetDetent = detent;
|
|
38
|
-
return
|
|
49
|
+
return heightOf();
|
|
39
50
|
});
|
|
40
51
|
if (shown === undefined) delete sheet.dataset.sheetDetent;else sheet.dataset.sheetDetent = shown;
|
|
41
52
|
return heights;
|
|
42
53
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
|
|
55
|
+
/** While the sheet moves: its pinned layout height and how much of it shows above the edge. */
|
|
56
|
+
let pinned;
|
|
57
|
+
let animation;
|
|
58
|
+
/** The detent the running glide lands on; a press that catches it lets it land there. */
|
|
59
|
+
let goal;
|
|
60
|
+
const offset = (highest, visible) => `translate3d(0, ${highest - visible}px, 0)`;
|
|
61
|
+
const put = visible => {
|
|
62
|
+
if (!pinned) return;
|
|
63
|
+
pinned.visible = visible;
|
|
64
|
+
sheet.style.transform = offset(pinned.highest, visible);
|
|
65
|
+
};
|
|
66
|
+
/** Holds a gliding sheet where the eye sees it. */
|
|
67
|
+
const stop = () => {
|
|
68
|
+
const running = animation;
|
|
69
|
+
if (!running || !pinned) return;
|
|
70
|
+
const at = typeof DOMMatrixReadOnly === "function" ? new DOMMatrixReadOnly(getComputedStyle(sheet).transform).m42 : 0;
|
|
71
|
+
animation = undefined;
|
|
72
|
+
running.cancel();
|
|
73
|
+
put(pinned.highest - at);
|
|
74
|
+
};
|
|
75
|
+
// When the owner hides the sheet while it moves, as a close button or navigation does, the move ends without
|
|
76
|
+
// landing: no detent, no `onDismiss`, nothing left for the next opening.
|
|
77
|
+
const hidden = typeof ResizeObserver === "function" ? new ResizeObserver(() => {
|
|
78
|
+
if (pinned && sheet.getClientRects().length === 0) unpin();
|
|
79
|
+
}) : undefined;
|
|
80
|
+
const pin = () => {
|
|
81
|
+
if (pinned) {
|
|
82
|
+
stop();
|
|
83
|
+
return pinned;
|
|
84
|
+
}
|
|
85
|
+
const visible = heightOf();
|
|
86
|
+
sheet.style.transition = "none";
|
|
87
|
+
const heights = measure();
|
|
88
|
+
pinned = {
|
|
89
|
+
heights,
|
|
90
|
+
highest: Math.max(visible, ...heights),
|
|
91
|
+
visible
|
|
92
|
+
};
|
|
93
|
+
sheet.style.height = `${pinned.highest}px`;
|
|
94
|
+
put(visible);
|
|
95
|
+
hidden?.observe(sheet);
|
|
96
|
+
return pinned;
|
|
97
|
+
};
|
|
98
|
+
const unpin = () => {
|
|
99
|
+
animation?.cancel();
|
|
100
|
+
animation = undefined;
|
|
101
|
+
goal = undefined;
|
|
102
|
+
delete sheet.dataset.sheetDragging;
|
|
103
|
+
if (!pinned) return;
|
|
104
|
+
pinned = undefined;
|
|
105
|
+
hidden?.unobserve(sheet);
|
|
47
106
|
sheet.style.removeProperty("height");
|
|
107
|
+
sheet.style.removeProperty("transform");
|
|
108
|
+
// The stylesheet's resting height arrives in this one layout, not through a transition.
|
|
109
|
+
void sheet.offsetHeight;
|
|
48
110
|
sheet.style.removeProperty("transition");
|
|
49
|
-
delete sheet.dataset.sheetDragging;
|
|
50
111
|
};
|
|
112
|
+
const glide = (to, ms, done) => {
|
|
113
|
+
const state = pinned;
|
|
114
|
+
if (!state) {
|
|
115
|
+
done();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
stop();
|
|
119
|
+
const from = state.visible;
|
|
120
|
+
const duration = prefersReducedMotion() || typeof sheet.animate !== "function" ? 0 : ms;
|
|
121
|
+
if (!duration || Math.abs(from - to) < 0.5) {
|
|
122
|
+
put(to);
|
|
123
|
+
done();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const running = sheet.animate([{
|
|
127
|
+
transform: offset(state.highest, from)
|
|
128
|
+
}, {
|
|
129
|
+
transform: offset(state.highest, to)
|
|
130
|
+
}], {
|
|
131
|
+
duration,
|
|
132
|
+
easing: EASE,
|
|
133
|
+
fill: "forwards"
|
|
134
|
+
});
|
|
135
|
+
animation = running;
|
|
136
|
+
// A cancelled glide rejects `finished`; nothing waits on it.
|
|
137
|
+
running.finished.catch(() => {});
|
|
138
|
+
running.onfinish = () => {
|
|
139
|
+
if (animation !== running) return;
|
|
140
|
+
animation = undefined;
|
|
141
|
+
put(to);
|
|
142
|
+
running.cancel();
|
|
143
|
+
done();
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
// The detent and its name change when the move starts, so assistive technology hears the press at once; the pinned
|
|
147
|
+
// height keeps the stylesheet's new height from showing until the glide lands.
|
|
148
|
+
const moveTo = detent => {
|
|
149
|
+
const state = pin();
|
|
150
|
+
goal = detent;
|
|
151
|
+
set(detent);
|
|
152
|
+
glide(state.heights[detents.indexOf(detent)] ?? state.visible, MOVE_MS, unpin);
|
|
153
|
+
};
|
|
154
|
+
const dismiss = () => {
|
|
155
|
+
goal = undefined;
|
|
156
|
+
glide(0, CLOSE_MS, () => {
|
|
157
|
+
options.onDismiss?.();
|
|
158
|
+
// The owner kept the sheet on screen: it returns to its lowest detent.
|
|
159
|
+
if (sheet.isConnected && sheet.getClientRects().length > 0) moveTo(detents[0] ?? options.initial);else unpin();
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
let drag;
|
|
163
|
+
let suppressClick = false;
|
|
164
|
+
let resume;
|
|
51
165
|
const finish = (commit, time) => {
|
|
52
166
|
const ended = drag;
|
|
53
167
|
if (!ended) return;
|
|
54
168
|
drag = undefined;
|
|
55
169
|
ended.releaseSelection();
|
|
56
170
|
if (handle.hasPointerCapture?.(ended.id)) handle.releasePointerCapture(ended.id);
|
|
57
|
-
// A cancelled gesture sends no click
|
|
58
|
-
if (!
|
|
59
|
-
|
|
171
|
+
// A cancelled gesture sends no click: a cancelled drag returns, and a caught glide lands where it was going.
|
|
172
|
+
if (!commit) {
|
|
173
|
+
if (pinned) moveTo(ended.moved ? current() : goal ?? current());
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
// A press that caught a glide waits for its click, which switches as every press does; without one, as when the
|
|
177
|
+
// pointer left the handle, the glide lands where it was going.
|
|
178
|
+
if (!ended.moved) {
|
|
179
|
+
if (pinned) resume = setTimeout(() => {
|
|
180
|
+
if (pinned && !animation) moveTo(goal ?? current());
|
|
181
|
+
});
|
|
60
182
|
return;
|
|
61
183
|
}
|
|
62
184
|
suppressClick = true;
|
|
185
|
+
const state = pinned;
|
|
186
|
+
if (!state) return;
|
|
187
|
+
delete sheet.dataset.sheetDragging;
|
|
63
188
|
const speed = time !== undefined && time - ended.time > REST_MS ? 0 : ended.speed;
|
|
64
|
-
const target =
|
|
65
|
-
const lowest =
|
|
66
|
-
if (options.onDismiss &&
|
|
67
|
-
|
|
68
|
-
options.onDismiss();
|
|
189
|
+
const target = state.visible - speed * PROJECTION_MS;
|
|
190
|
+
const lowest = state.heights[0] ?? 0;
|
|
191
|
+
if (options.onDismiss && state.visible < lowest && target < lowest * DISMISS_SHARE) {
|
|
192
|
+
dismiss();
|
|
69
193
|
return;
|
|
70
194
|
}
|
|
71
195
|
let nearest = 0;
|
|
72
|
-
for (const [index, height] of
|
|
73
|
-
|
|
74
|
-
set(detents[nearest] ?? options.initial);
|
|
196
|
+
for (const [index, height] of state.heights.entries()) if (Math.abs(height - target) < Math.abs((state.heights[nearest] ?? 0) - target)) nearest = index;
|
|
197
|
+
moveTo(detents[nearest] ?? options.initial);
|
|
75
198
|
};
|
|
76
199
|
const down = event => {
|
|
77
200
|
if (event.button !== 0 || event.isPrimary === false || drag) return;
|
|
78
201
|
suppressClick = false;
|
|
79
|
-
// A press during a
|
|
80
|
-
|
|
81
|
-
sheet.style.transition = "none";
|
|
82
|
-
const heights = measure();
|
|
83
|
-
sheet.style.height = `${startHeight}px`;
|
|
202
|
+
// A press during a glide catches the sheet where it is now.
|
|
203
|
+
stop();
|
|
84
204
|
handle.setPointerCapture?.(event.pointerId);
|
|
85
205
|
drag = {
|
|
86
206
|
id: event.pointerId,
|
|
87
207
|
startY: event.clientY,
|
|
88
|
-
|
|
89
|
-
heights,
|
|
90
|
-
height: startHeight,
|
|
208
|
+
from: 0,
|
|
91
209
|
moved: false,
|
|
92
210
|
y: event.clientY,
|
|
93
211
|
time: event.timeStamp,
|
|
@@ -97,22 +215,24 @@ export function attachSheetHandle(handle, options) {
|
|
|
97
215
|
};
|
|
98
216
|
const move = event => {
|
|
99
217
|
if (!drag || event.pointerId !== drag.id) return;
|
|
100
|
-
// A move without a change of
|
|
218
|
+
// A move without a change of position, such as one a release sends first, is no speed.
|
|
101
219
|
if (event.clientY === drag.y) return;
|
|
102
220
|
const distance = event.clientY - drag.startY;
|
|
103
221
|
if (!drag.moved && Math.abs(distance) < DRAG_THRESHOLD) return;
|
|
104
222
|
if (!drag.moved) {
|
|
105
223
|
drag.moved = true;
|
|
224
|
+
goal = undefined;
|
|
225
|
+
drag.from = pin().visible;
|
|
106
226
|
sheet.dataset.sheetDragging = "";
|
|
107
227
|
}
|
|
108
228
|
const elapsed = event.timeStamp - drag.time;
|
|
109
229
|
if (elapsed > 0) drag.speed = drag.speed * 0.4 + (event.clientY - drag.y) / elapsed * 0.6;
|
|
110
230
|
drag.y = event.clientY;
|
|
111
231
|
drag.time = event.timeStamp;
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
232
|
+
const state = pinned;
|
|
233
|
+
if (!state) return;
|
|
234
|
+
const lowest = options.onDismiss ? 0 : Math.min(...state.heights);
|
|
235
|
+
put(Math.min(state.highest, Math.max(lowest, drag.from - distance)));
|
|
116
236
|
};
|
|
117
237
|
const up = event => {
|
|
118
238
|
if (drag && event.pointerId === drag.id) finish(true, event.timeStamp);
|
|
@@ -129,8 +249,9 @@ export function attachSheetHandle(handle, options) {
|
|
|
129
249
|
return;
|
|
130
250
|
}
|
|
131
251
|
suppressClick = false;
|
|
252
|
+
clearTimeout(resume);
|
|
132
253
|
const index = detents.indexOf(current());
|
|
133
|
-
|
|
254
|
+
moveTo(detents[index + 1 < detents.length ? index + 1 : 0] ?? options.initial);
|
|
134
255
|
};
|
|
135
256
|
const touchAction = handle.style.touchAction;
|
|
136
257
|
// The browser must not take the drag for a scroll or a page swipe.
|
|
@@ -141,8 +262,23 @@ export function attachSheetHandle(handle, options) {
|
|
|
141
262
|
handle.addEventListener("pointercancel", cancel);
|
|
142
263
|
handle.addEventListener("lostpointercapture", cancel);
|
|
143
264
|
handle.addEventListener("click", click);
|
|
265
|
+
// An owner that sets the detent itself while the sheet moves, as the map dialog does for a picked place, takes over:
|
|
266
|
+
// the sheet glides there from where it is instead of landing on the old detent and then jumping.
|
|
267
|
+
const external = typeof MutationObserver === "function" ? new MutationObserver(() => {
|
|
268
|
+
const at = sheet.dataset.sheetDetent;
|
|
269
|
+
if (!pinned || drag?.moved || !at || !detents.includes(at) || at === goal) return;
|
|
270
|
+
moveTo(at);
|
|
271
|
+
}) : undefined;
|
|
272
|
+
external?.observe(sheet, {
|
|
273
|
+
attributes: true,
|
|
274
|
+
attributeFilter: ["data-sheet-detent"]
|
|
275
|
+
});
|
|
144
276
|
return () => {
|
|
277
|
+
external?.disconnect();
|
|
145
278
|
finish(false);
|
|
279
|
+
clearTimeout(resume);
|
|
280
|
+
unpin();
|
|
281
|
+
hidden?.disconnect();
|
|
146
282
|
handle.style.touchAction = touchAction;
|
|
147
283
|
handle.removeEventListener("pointerdown", down);
|
|
148
284
|
handle.removeEventListener("pointermove", move);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["layout/sheet-handle.ts"],"sourcesContent":["import { suppressTextSelection } from \"../internal/text-selection\";\n\nexport type SheetHandleOptions = {\n /** The sheet the handle sits on. It carries the current detent in `data-sheet-detent`. */\n sheet: HTMLElement;\n /** The detents' names, lowest first. The stylesheet gives each `[data-sheet-detent=\"…\"]` its height. */\n detents: readonly string[];\n /** The detent the stylesheet draws while the sheet has no `data-sheet-detent`, such as in the server's markup. */\n initial: string;\n /** After a drag or a press moved the sheet to another detent, for example to rename the handle. */\n onChange?: (detent: string) => void;\n /** Without it, a drag stops at the lowest detent; with it, a drag well below that detent asks to close. */\n onDismiss?: () => void;\n};\n\n/** Below this distance a press stays a press and the click after it moves the sheet. */\nconst DRAG_THRESHOLD = 6;\n/** How far ahead the release projects the pointer's speed, so a short flick reaches the next detent. */\nconst PROJECTION_MS = 120;\n/** A pointer that rested this long before it lifted carries no speed into the snap. */\nconst REST_MS = 80;\n/** A release below this share of the lowest detent dismisses, when the sheet may be dismissed. */\nconst DISMISS_SHARE = 0.6;\n\n/**\n * Lets a sheet's handle drag it between detents. The handle stays a button: a press, by pointer, Enter or Space,\n * moves the sheet to the next detent up, and from the highest back to the lowest. A drag follows the pointer with an\n * inline height and, on release, snaps to the detent nearest to where the pointer's speed would carry it. The snap\n * animates with the sheet's own height transition, so reduced motion makes it instant. The stylesheet owns every\n * resting height, which keeps the server's first frame and a rotation correct without script; the handle measures\n * them when a drag starts.\n */\nexport function attachSheetHandle(handle: HTMLElement, options: SheetHandleOptions): () => void {\n const { sheet, detents } = options;\n const current = () => {\n const detent = sheet.dataset.sheetDetent;\n return detent && detents.includes(detent) ? detent : options.initial;\n };\n const set = (detent: string) => {\n const changed = detent !== current();\n sheet.dataset.sheetDetent = detent;\n if (changed) options.onChange?.(detent);\n };\n // Each detent's height as the stylesheet draws it now; the caller has turned the transition off.\n const measure = () => {\n const shown = sheet.dataset.sheetDetent;\n const heights = detents.map((detent) => {\n sheet.dataset.sheetDetent = detent;\n return sheet.getBoundingClientRect().height;\n });\n if (shown === undefined) delete sheet.dataset.sheetDetent;\n else sheet.dataset.sheetDetent = shown;\n return heights;\n };\n let drag:\n | {\n id: number;\n startY: number;\n startHeight: number;\n heights: number[];\n height: number;\n moved: boolean;\n y: number;\n time: number;\n /** Downward speed in px per ms. */\n speed: number;\n releaseSelection: () => void;\n }\n | undefined;\n let suppressClick = false;\n // Dropping the inline height and transition together lets the stylesheet's transition carry the sheet to its detent.\n const release = () => {\n sheet.style.removeProperty(\"height\");\n sheet.style.removeProperty(\"transition\");\n delete sheet.dataset.sheetDragging;\n };\n const finish = (commit: boolean, time?: number) => {\n const ended = drag;\n if (!ended) return;\n drag = undefined;\n ended.releaseSelection();\n if (handle.hasPointerCapture?.(ended.id)) handle.releasePointerCapture(ended.id);\n // A cancelled gesture sends no click; only a finished drag's click must not move the sheet again.\n if (!ended.moved || !commit) {\n release();\n return;\n }\n suppressClick = true;\n const speed = time !== undefined && time - ended.time > REST_MS ? 0 : ended.speed;\n const target = ended.height - speed * PROJECTION_MS;\n const lowest = ended.heights[0] ?? 0;\n if (options.onDismiss && ended.height < lowest && target < lowest * DISMISS_SHARE) {\n release();\n options.onDismiss();\n return;\n }\n let nearest = 0;\n for (const [index, height] of ended.heights.entries())\n if (Math.abs(height - target) < Math.abs((ended.heights[nearest] ?? 0) - target)) nearest = index;\n release();\n set(detents[nearest] ?? options.initial);\n };\n const down = (event: PointerEvent) => {\n if (event.button !== 0 || event.isPrimary === false || drag) return;\n suppressClick = false;\n // A press during a snap starts from where the sheet is now.\n const startHeight = sheet.getBoundingClientRect().height;\n sheet.style.transition = \"none\";\n const heights = measure();\n sheet.style.height = `${startHeight}px`;\n handle.setPointerCapture?.(event.pointerId);\n drag = {\n id: event.pointerId,\n startY: event.clientY,\n startHeight,\n heights,\n height: startHeight,\n moved: false,\n y: event.clientY,\n time: event.timeStamp,\n speed: 0,\n releaseSelection: suppressTextSelection(event.pointerId),\n };\n };\n const move = (event: PointerEvent) => {\n if (!drag || event.pointerId !== drag.id) return;\n // A move without a change of height, such as one a release sends first, is no speed.\n if (event.clientY === drag.y) return;\n const distance = event.clientY - drag.startY;\n if (!drag.moved && Math.abs(distance) < DRAG_THRESHOLD) return;\n if (!drag.moved) {\n drag.moved = true;\n sheet.dataset.sheetDragging = \"\";\n }\n const elapsed = event.timeStamp - drag.time;\n if (elapsed > 0) drag.speed = drag.speed * 0.4 + ((event.clientY - drag.y) / elapsed) * 0.6;\n drag.y = event.clientY;\n drag.time = event.timeStamp;\n const highest = Math.max(...drag.heights);\n const lowest = options.onDismiss ? 0 : Math.min(...drag.heights);\n drag.height = Math.min(highest, Math.max(lowest, drag.startHeight - distance));\n sheet.style.height = `${drag.height}px`;\n };\n const up = (event: PointerEvent) => {\n if (drag && event.pointerId === drag.id) finish(true, event.timeStamp);\n };\n const cancel = (event: PointerEvent) => {\n if (drag && event.pointerId === drag.id) finish(false);\n };\n const click = (event: MouseEvent) => {\n // The click a drag's release produces does not move the sheet again; a keyboard click has no detail.\n if (suppressClick && event.detail !== 0) {\n suppressClick = false;\n event.preventDefault();\n event.stopImmediatePropagation();\n return;\n }\n suppressClick = false;\n const index = detents.indexOf(current());\n set(detents[index + 1 < detents.length ? index + 1 : 0] ?? options.initial);\n };\n const touchAction = handle.style.touchAction;\n // The browser must not take the drag for a scroll or a page swipe.\n handle.style.touchAction = \"none\";\n handle.addEventListener(\"pointerdown\", down);\n handle.addEventListener(\"pointermove\", move);\n handle.addEventListener(\"pointerup\", up);\n handle.addEventListener(\"pointercancel\", cancel);\n handle.addEventListener(\"lostpointercapture\", cancel);\n handle.addEventListener(\"click\", click);\n return () => {\n finish(false);\n handle.style.touchAction = touchAction;\n handle.removeEventListener(\"pointerdown\", down);\n handle.removeEventListener(\"pointermove\", move);\n handle.removeEventListener(\"pointerup\", up);\n handle.removeEventListener(\"pointercancel\", cancel);\n handle.removeEventListener(\"lostpointercapture\", cancel);\n handle.removeEventListener(\"click\", click);\n };\n}\n"],"mappings":"AAAA,SAAS,qBAAqB,QAAQ,4BAA4B;AAelE;AACA,MAAM,cAAc,GAAG,CAAC;AACxB;AACA,MAAM,aAAa,GAAG,GAAG;AACzB;AAC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C,oBAAoB,EAAE,MAAM,CAAC;IACxD,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC;EAC5C,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["layout/sheet-handle.ts"],"sourcesContent":["import { suppressTextSelection } from \"../internal/text-selection\";\nimport { prefersReducedMotion } from \"../motion\";\n\nexport type SheetHandleOptions = {\n /**\n * The sheet the handle sits on, anchored at its bottom edge. It carries the current detent in `data-sheet-detent`.\n * Its container clips with `overflow: clip`, so the part that slides below the edge never scrolls into view.\n */\n sheet: HTMLElement;\n /** The detents' names, lowest first. The stylesheet gives each `[data-sheet-detent=\"…\"]` its height. */\n detents: readonly string[];\n /** The detent the stylesheet draws while the sheet has no `data-sheet-detent`, such as in the server's markup. */\n initial: string;\n /** When a drag or a press sends the sheet to another detent, as it starts to glide, for example to rename the handle. */\n onChange?: (detent: string) => void;\n /**\n * Without it, a drag stops at the lowest detent; with it, a drag well below that detent slides the sheet out and\n * then asks to close. When the sheet is still shown afterwards, as when the owner asks first, it returns.\n */\n onDismiss?: () => void;\n};\n\n/** Below this distance a press stays a press and the click after it moves the sheet. */\nconst DRAG_THRESHOLD = 6;\n/** How far ahead the release projects the pointer's speed, so a short flick reaches the next detent. */\nconst PROJECTION_MS = 120;\n/** A pointer that rested this long before it lifted carries no speed into the snap. */\nconst REST_MS = 80;\n/** A release below this share of the lowest detent dismisses, when the sheet may be dismissed. */\nconst DISMISS_SHARE = 0.6;\n/** Gliding to a detent and out, as `BottomSheet` does. */\nconst MOVE_MS = 280;\nconst CLOSE_MS = 220;\n/** `--k2b-ease-out`: lands without overshoot. */\nconst EASE = \"cubic-bezier(0.23, 1, 0.32, 1)\";\n\n/**\n * Lets a sheet's handle drag it between detents. The handle stays a button: a press, by pointer, Enter or Space,\n * moves the sheet to the next detent up, and from the highest back to the lowest.\n *\n * The sheet moves by transform only, like `BottomSheet`. When a drag or a glide starts, its layout height is pinned\n * at the highest detent and a transform shows the visible part; the content inside does not lay out again on every\n * frame. A release glides to the detent nearest to where the pointer's speed would carry it; then the stylesheet's\n * height for that detent takes over in one step that looks the same. Reduced motion makes every glide instant. The\n * stylesheet owns every resting height, which keeps the server's first frame and a rotation correct without script;\n * it must not transition `height`.\n */\nexport function attachSheetHandle(handle: HTMLElement, options: SheetHandleOptions): () => void {\n const { sheet, detents } = options;\n const current = () => {\n const detent = sheet.dataset.sheetDetent;\n return detent && detents.includes(detent) ? detent : options.initial;\n };\n const set = (detent: string) => {\n const changed = detent !== current();\n sheet.dataset.sheetDetent = detent;\n if (changed) options.onChange?.(detent);\n };\n /** The painted height; an environment without layout, such as a test DOM, reports 0 and every move is instant. */\n const heightOf = () => Number(sheet.getBoundingClientRect().height) || 0;\n // Each detent's height as the stylesheet draws it now, while the transition is off.\n const measure = () => {\n const shown = sheet.dataset.sheetDetent;\n const heights = detents.map((detent) => {\n sheet.dataset.sheetDetent = detent;\n return heightOf();\n });\n if (shown === undefined) delete sheet.dataset.sheetDetent;\n else sheet.dataset.sheetDetent = shown;\n return heights;\n };\n\n /** While the sheet moves: its pinned layout height and how much of it shows above the edge. */\n let pinned: { heights: number[]; highest: number; visible: number } | undefined;\n let animation: Animation | undefined;\n /** The detent the running glide lands on; a press that catches it lets it land there. */\n let goal: string | undefined;\n const offset = (highest: number, visible: number) => `translate3d(0, ${highest - visible}px, 0)`;\n const put = (visible: number) => {\n if (!pinned) return;\n pinned.visible = visible;\n sheet.style.transform = offset(pinned.highest, visible);\n };\n /** Holds a gliding sheet where the eye sees it. */\n const stop = () => {\n const running = animation;\n if (!running || !pinned) return;\n const at = typeof DOMMatrixReadOnly === \"function\" ? new DOMMatrixReadOnly(getComputedStyle(sheet).transform).m42 : 0;\n animation = undefined;\n running.cancel();\n put(pinned.highest - at);\n };\n // When the owner hides the sheet while it moves, as a close button or navigation does, the move ends without\n // landing: no detent, no `onDismiss`, nothing left for the next opening.\n const hidden =\n typeof ResizeObserver === \"function\"\n ? new ResizeObserver(() => {\n if (pinned && sheet.getClientRects().length === 0) unpin();\n })\n : undefined;\n const pin = () => {\n if (pinned) {\n stop();\n return pinned;\n }\n const visible = heightOf();\n sheet.style.transition = \"none\";\n const heights = measure();\n pinned = { heights, highest: Math.max(visible, ...heights), visible };\n sheet.style.height = `${pinned.highest}px`;\n put(visible);\n hidden?.observe(sheet);\n return pinned;\n };\n const unpin = () => {\n animation?.cancel();\n animation = undefined;\n goal = undefined;\n delete sheet.dataset.sheetDragging;\n if (!pinned) return;\n pinned = undefined;\n hidden?.unobserve(sheet);\n sheet.style.removeProperty(\"height\");\n sheet.style.removeProperty(\"transform\");\n // The stylesheet's resting height arrives in this one layout, not through a transition.\n void sheet.offsetHeight;\n sheet.style.removeProperty(\"transition\");\n };\n const glide = (to: number, ms: number, done: () => void) => {\n const state = pinned;\n if (!state) {\n done();\n return;\n }\n stop();\n const from = state.visible;\n const duration = prefersReducedMotion() || typeof sheet.animate !== \"function\" ? 0 : ms;\n if (!duration || Math.abs(from - to) < 0.5) {\n put(to);\n done();\n return;\n }\n const running = sheet.animate([{ transform: offset(state.highest, from) }, { transform: offset(state.highest, to) }], {\n duration,\n easing: EASE,\n fill: \"forwards\",\n });\n animation = running;\n // A cancelled glide rejects `finished`; nothing waits on it.\n running.finished.catch(() => {});\n running.onfinish = () => {\n if (animation !== running) return;\n animation = undefined;\n put(to);\n running.cancel();\n done();\n };\n };\n // The detent and its name change when the move starts, so assistive technology hears the press at once; the pinned\n // height keeps the stylesheet's new height from showing until the glide lands.\n const moveTo = (detent: string) => {\n const state = pin();\n goal = detent;\n set(detent);\n glide(state.heights[detents.indexOf(detent)] ?? state.visible, MOVE_MS, unpin);\n };\n const dismiss = () => {\n goal = undefined;\n glide(0, CLOSE_MS, () => {\n options.onDismiss?.();\n // The owner kept the sheet on screen: it returns to its lowest detent.\n if (sheet.isConnected && sheet.getClientRects().length > 0) moveTo(detents[0] ?? options.initial);\n else unpin();\n });\n };\n\n let drag:\n | {\n id: number;\n startY: number;\n /** The visible height when the drag took the sheet. */\n from: number;\n moved: boolean;\n y: number;\n time: number;\n /** Downward speed in px per ms. */\n speed: number;\n releaseSelection: () => void;\n }\n | undefined;\n let suppressClick = false;\n let resume: ReturnType<typeof setTimeout> | undefined;\n const finish = (commit: boolean, time?: number) => {\n const ended = drag;\n if (!ended) return;\n drag = undefined;\n ended.releaseSelection();\n if (handle.hasPointerCapture?.(ended.id)) handle.releasePointerCapture(ended.id);\n // A cancelled gesture sends no click: a cancelled drag returns, and a caught glide lands where it was going.\n if (!commit) {\n if (pinned) moveTo(ended.moved ? current() : (goal ?? current()));\n return;\n }\n // A press that caught a glide waits for its click, which switches as every press does; without one, as when the\n // pointer left the handle, the glide lands where it was going.\n if (!ended.moved) {\n if (pinned)\n resume = setTimeout(() => {\n if (pinned && !animation) moveTo(goal ?? current());\n });\n return;\n }\n suppressClick = true;\n const state = pinned;\n if (!state) return;\n delete sheet.dataset.sheetDragging;\n const speed = time !== undefined && time - ended.time > REST_MS ? 0 : ended.speed;\n const target = state.visible - speed * PROJECTION_MS;\n const lowest = state.heights[0] ?? 0;\n if (options.onDismiss && state.visible < lowest && target < lowest * DISMISS_SHARE) {\n dismiss();\n return;\n }\n let nearest = 0;\n for (const [index, height] of state.heights.entries())\n if (Math.abs(height - target) < Math.abs((state.heights[nearest] ?? 0) - target)) nearest = index;\n moveTo(detents[nearest] ?? options.initial);\n };\n const down = (event: PointerEvent) => {\n if (event.button !== 0 || event.isPrimary === false || drag) return;\n suppressClick = false;\n // A press during a glide catches the sheet where it is now.\n stop();\n handle.setPointerCapture?.(event.pointerId);\n drag = {\n id: event.pointerId,\n startY: event.clientY,\n from: 0,\n moved: false,\n y: event.clientY,\n time: event.timeStamp,\n speed: 0,\n releaseSelection: suppressTextSelection(event.pointerId),\n };\n };\n const move = (event: PointerEvent) => {\n if (!drag || event.pointerId !== drag.id) return;\n // A move without a change of position, such as one a release sends first, is no speed.\n if (event.clientY === drag.y) return;\n const distance = event.clientY - drag.startY;\n if (!drag.moved && Math.abs(distance) < DRAG_THRESHOLD) return;\n if (!drag.moved) {\n drag.moved = true;\n goal = undefined;\n drag.from = pin().visible;\n sheet.dataset.sheetDragging = \"\";\n }\n const elapsed = event.timeStamp - drag.time;\n if (elapsed > 0) drag.speed = drag.speed * 0.4 + ((event.clientY - drag.y) / elapsed) * 0.6;\n drag.y = event.clientY;\n drag.time = event.timeStamp;\n const state = pinned;\n if (!state) return;\n const lowest = options.onDismiss ? 0 : Math.min(...state.heights);\n put(Math.min(state.highest, Math.max(lowest, drag.from - distance)));\n };\n const up = (event: PointerEvent) => {\n if (drag && event.pointerId === drag.id) finish(true, event.timeStamp);\n };\n const cancel = (event: PointerEvent) => {\n if (drag && event.pointerId === drag.id) finish(false);\n };\n const click = (event: MouseEvent) => {\n // The click a drag's release produces does not move the sheet again; a keyboard click has no detail.\n if (suppressClick && event.detail !== 0) {\n suppressClick = false;\n event.preventDefault();\n event.stopImmediatePropagation();\n return;\n }\n suppressClick = false;\n clearTimeout(resume);\n const index = detents.indexOf(current());\n moveTo(detents[index + 1 < detents.length ? index + 1 : 0] ?? options.initial);\n };\n const touchAction = handle.style.touchAction;\n // The browser must not take the drag for a scroll or a page swipe.\n handle.style.touchAction = \"none\";\n handle.addEventListener(\"pointerdown\", down);\n handle.addEventListener(\"pointermove\", move);\n handle.addEventListener(\"pointerup\", up);\n handle.addEventListener(\"pointercancel\", cancel);\n handle.addEventListener(\"lostpointercapture\", cancel);\n handle.addEventListener(\"click\", click);\n // An owner that sets the detent itself while the sheet moves, as the map dialog does for a picked place, takes over:\n // the sheet glides there from where it is instead of landing on the old detent and then jumping.\n const external =\n typeof MutationObserver === \"function\"\n ? new MutationObserver(() => {\n const at = sheet.dataset.sheetDetent;\n if (!pinned || drag?.moved || !at || !detents.includes(at) || at === goal) return;\n moveTo(at);\n })\n : undefined;\n external?.observe(sheet, { attributes: true, attributeFilter: [\"data-sheet-detent\"] });\n return () => {\n external?.disconnect();\n finish(false);\n clearTimeout(resume);\n unpin();\n hidden?.disconnect();\n handle.style.touchAction = touchAction;\n handle.removeEventListener(\"pointerdown\", down);\n handle.removeEventListener(\"pointermove\", move);\n handle.removeEventListener(\"pointerup\", up);\n handle.removeEventListener(\"pointercancel\", cancel);\n handle.removeEventListener(\"lostpointercapture\", cancel);\n handle.removeEventListener(\"click\", click);\n };\n}\n"],"mappings":"AAAA,SAAS,qBAAqB,QAAQ,4BAA4B;AAClE,SAAS,oBAAoB,QAAQ,WAAW;AAqBhD;AACA,MAAM,cAAc,GAAG,CAAC;AACxB;AACA,MAAM,aAAa,GAAG,GAAG;AACzB;AACA,MAAM,OAAO,GAAG,EAAE;AAClB;AACA,MAAM,aAAa,GAAG,GAAG;AACzB;AACA,MAAM,OAAO,GAAG,GAAG;AACnB,MAAM,QAAQ,GAAG,GAAG;AACpB;AACA,MAAM,IAAI,GAAG,gCAAgC;;AAE7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS,iBAAiB,CAAC,MAAmB,EAAE,OAA2B,EAAc;EAC9F,MAAM;IAAE,KAAK;IAAE;EAAQ,CAAC,GAAG,OAAO;EAClC,MAAM,OAAO,GAAG,MAAM;IACpB,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW;IACxC,OAAO,MAAM,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,OAAO,CAAC,OAAO;EACtE,CAAC;EACD,MAAM,GAAG,GAAI,MAAc,IAAK;IAC9B,MAAM,OAAO,GAAG,MAAM,KAAK,OAAO,CAAC,CAAC;IACpC,KAAK,CAAC,OAAO,CAAC,WAAW,GAAG,MAAM;IAClC,IAAI,OAAO,EAAE,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC;EACzC,CAAC;EACD;EACA,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC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C5C,CAAC;AACH","ignoreList":[]}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { prefersReducedMotion } from "../motion";
|
|
2
|
+
/** Initial focus goes to the first input of the top sheet, otherwise to the
|
|
3
|
+
* dialog element itself. Native `showModal()` focuses the first focusable
|
|
4
|
+
* descendant, which is the drag handle; iOS shows a ring for that programmatic
|
|
5
|
+
* focus, so the sheet moves it to the ring-less dialog before the next paint. */
|
|
6
|
+
export const sheetInitialFocus = dialog => {
|
|
7
|
+
const input = dialog.lastElementChild?.querySelector("input:not([type='hidden']):not([disabled]), textarea:not([disabled]), select:not([disabled]), [role='combobox']:not([disabled]):not([aria-disabled='true'])");
|
|
8
|
+
if (input) return input;
|
|
9
|
+
dialog.tabIndex = -1;
|
|
10
|
+
return dialog;
|
|
11
|
+
};
|
|
12
|
+
|
|
2
13
|
/** Opening and moving between detents, and closing, as in the approved prototype. */
|
|
3
14
|
const MOVE_MS = 280;
|
|
4
15
|
const CLOSE_MS = 220;
|
|
@@ -20,6 +31,8 @@ const CLOSE_SHARE = 0.25;
|
|
|
20
31
|
const PROJECTION_MS = 150;
|
|
21
32
|
/** A pointer that rested this long before it lifted carries no speed. */
|
|
22
33
|
const REST_MS = 80;
|
|
34
|
+
/** Pulled past full height, the sheet gives like a rubber band: `RUBBER_PX × ln(1 + overshoot / RUBBER_PX)`. */
|
|
35
|
+
const RUBBER_PX = 28;
|
|
23
36
|
/** A finger that scrolled a list this recently keeps scrolling instead of dragging the sheet. */
|
|
24
37
|
const SCROLL_LOCK_MS = 100;
|
|
25
38
|
/** From this width an adaptive sheet is a centred dialog and does not move. */
|
|
@@ -72,7 +85,9 @@ export function attachSheetMotion(options) {
|
|
|
72
85
|
suspend: () => suspend(),
|
|
73
86
|
resume: () => resume()
|
|
74
87
|
};
|
|
75
|
-
|
|
88
|
+
/** A level that is no sheet, such as a full-screen prompt, covers this one in the same dialog element. */
|
|
89
|
+
let covered = false;
|
|
90
|
+
const owning = () => !disposed && !covered && owners.at(-1) === owner;
|
|
76
91
|
const claim = () => {
|
|
77
92
|
frame.dataset.sheetMotion = "";
|
|
78
93
|
if (detents) frame.dataset.sheetDetents = "";else delete frame.dataset.sheetDetents;
|
|
@@ -94,8 +109,8 @@ export function attachSheetMotion(options) {
|
|
|
94
109
|
};
|
|
95
110
|
const rest = at => at === "half" ? half : layoutHeight;
|
|
96
111
|
const lowest = () => detents ? half : layoutHeight;
|
|
97
|
-
/** Between half and full height the footer stays on the screen's edge; below half it rides along. */
|
|
98
|
-
const footerAt = seen => Math.max(0, half - seen) - (layoutHeight - seen);
|
|
112
|
+
/** Between half and full height the footer stays on the screen's edge; below half and past full it rides along. */
|
|
113
|
+
const footerAt = seen => Math.min(0, Math.max(0, half - seen) - (layoutHeight - seen));
|
|
99
114
|
const dimAt = seen => lowest() > 0 ? Math.max(0, Math.min(1, seen / lowest())) : 1;
|
|
100
115
|
const frameTransform = seen => `translate3d(-50%, ${layoutHeight - seen}px, 0)`;
|
|
101
116
|
const footerTransform = seen => `translate3d(0, ${footerAt(seen)}px, 0)`;
|
|
@@ -235,7 +250,8 @@ export function attachSheetMotion(options) {
|
|
|
235
250
|
drag.y = y;
|
|
236
251
|
drag.time = time;
|
|
237
252
|
const floor = options.canDismiss() ? -OFFSCREEN_PX : lowest();
|
|
238
|
-
|
|
253
|
+
const wanted = drag.from + distance;
|
|
254
|
+
put(Math.max(floor, wanted > layoutHeight ? layoutHeight + RUBBER_PX * Math.log1p((wanted - layoutHeight) / RUBBER_PX) : wanted));
|
|
239
255
|
};
|
|
240
256
|
/** Returns whether the gesture was a drag, so its click is not a press. */
|
|
241
257
|
const release = (time, cancelled) => {
|
|
@@ -277,7 +293,7 @@ export function attachSheetMotion(options) {
|
|
|
277
293
|
|
|
278
294
|
// A mouse or a pen drags by the handle or the header; a finger uses the touch events below.
|
|
279
295
|
let suppressClick = false;
|
|
280
|
-
const header = panel.querySelector(":scope > .k2b-panel-dialog__header");
|
|
296
|
+
const header = panel.querySelector(":scope > .k2b-panel-dialog__header, :scope > .k2b-dialog__panel > .k2b-dialog__header");
|
|
281
297
|
for (const zone of [handle, header]) {
|
|
282
298
|
if (!zone) continue;
|
|
283
299
|
let pointer = null;
|
|
@@ -434,6 +450,23 @@ export function attachSheetMotion(options) {
|
|
|
434
450
|
});
|
|
435
451
|
}
|
|
436
452
|
|
|
453
|
+
// dialogCore shows only its top level, the dialog element's last child; any other level on top takes the element.
|
|
454
|
+
const levels = typeof MutationObserver === "function" ? new MutationObserver(() => {
|
|
455
|
+
if (disposed || owners.at(-1) !== owner) return;
|
|
456
|
+
const top = frame.lastElementChild?.contains(panel) ?? true;
|
|
457
|
+
if (!top && !covered) {
|
|
458
|
+
suspend();
|
|
459
|
+
covered = true;
|
|
460
|
+
} else if (top && covered) {
|
|
461
|
+
covered = false;
|
|
462
|
+
resume();
|
|
463
|
+
}
|
|
464
|
+
}) : undefined;
|
|
465
|
+
levels?.observe(frame, {
|
|
466
|
+
childList: true
|
|
467
|
+
});
|
|
468
|
+
cleanups.push(() => levels?.disconnect());
|
|
469
|
+
|
|
437
470
|
// Set before the dialog opens, so the stylesheet's own entry animation never starts.
|
|
438
471
|
owners.at(-1)?.suspend();
|
|
439
472
|
owners.push(owner);
|