@passui/react 0.1.44 → 0.1.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -46
- package/dist/types/src/components/accordion/accordion.d.ts +1 -1
- package/dist/types/src/components/breadcrumb/breadcrumb.d.ts +1 -1
- package/dist/types/src/components/inline-disclosure/inline-disclosure.d.ts +1 -1
- package/dist/types/src/components/popover/anchored-surface.d.ts +5 -1
- package/dist/types/src/components/popover/index.d.ts +41 -0
- package/dist/types/src/components/popover/popover-content.d.ts +32 -0
- package/dist/types/src/components/popover/popover-root.d.ts +22 -0
- package/dist/types/src/components/popover/popover-trigger.d.ts +23 -0
- package/dist/types/src/components/stepper/rolling-digit.d.ts +1 -1
- package/dist/types/src/components/table/table.d.ts +1 -1
- package/dist/types/src/components/view-controller/view-controller.d.ts +2 -2
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/machines/popover.machine.d.ts +30 -0
- package/package.json +307 -307
- package/src/appearance/index.ts +2 -2
- package/src/appearance/platform.tsx +76 -60
- package/src/appearance/theme.tsx +409 -377
- package/src/components/accordion/accordion.tsx +58 -49
- package/src/components/ambient/ambient.tsx +25 -25
- package/src/components/ambient/index.ts +1 -1
- package/src/components/aspect-ratio/aspect-ratio.tsx +21 -16
- package/src/components/breadcrumb/breadcrumb.tsx +63 -57
- package/src/components/button/button-styles.ts +39 -32
- package/src/components/button/button.tsx +91 -84
- package/src/components/button/icon-button.tsx +27 -25
- package/src/components/button/pending-spinner.tsx +8 -8
- package/src/components/button/use-pending-indicator.ts +11 -11
- package/src/components/chip/chip.tsx +35 -30
- package/src/components/code-block/code-block.tsx +40 -39
- package/src/components/combo-box/combo-box.tsx +5 -5
- package/src/components/command/command.tsx +124 -94
- package/src/components/compact-date-picker/calendar-month.ts +75 -53
- package/src/components/compact-date-picker/compact-date-picker.tsx +308 -289
- package/src/components/compact-time-picker/compact-time-picker.tsx +288 -281
- package/src/components/compact-time-picker/time-value.ts +32 -29
- package/src/components/content-unavailable-view/content-unavailable-view.tsx +64 -48
- package/src/components/content-view/content-view.tsx +168 -159
- package/src/components/content-view/index.ts +1 -1
- package/src/components/context-menu/conceal-menu-source.ts +25 -25
- package/src/components/context-menu/context-menu-host.tsx +439 -398
- package/src/components/context-menu/context-menu-store.ts +125 -123
- package/src/components/context-menu/menu-navigation.ts +25 -18
- package/src/components/context-menu/menu-position.ts +33 -29
- package/src/components/context-menu/menu-reveal.ts +32 -32
- package/src/components/context-menu/use-context-menu.ts +63 -56
- package/src/components/conversation/conversation.tsx +265 -263
- package/src/components/conversation/index.ts +1 -1
- package/src/components/date-picker/date-picker.tsx +95 -94
- package/src/components/date-picker/date-value.ts +20 -10
- package/src/components/dialog/dialog-host.tsx +105 -103
- package/src/components/dialog/dialog-store.ts +37 -36
- package/src/components/dialog/dialog.tsx +192 -179
- package/src/components/dialog/index.ts +1 -1
- package/src/components/disclosure-group/disclosure-group.tsx +93 -86
- package/src/components/divider/divider.tsx +24 -22
- package/src/components/inline-disclosure/inline-disclosure.tsx +40 -36
- package/src/components/keyboard-shortcut/keyboard-shortcut.tsx +23 -19
- package/src/components/labeled-content/labeled-content.tsx +68 -68
- package/src/components/locale-switcher/index.ts +1 -1
- package/src/components/locale-switcher/locale-switcher.tsx +279 -251
- package/src/components/menu/menu.tsx +75 -58
- package/src/components/morph/index.ts +2 -2
- package/src/components/morph/morph.tsx +227 -201
- package/src/components/morph/use-morph-disclosure.ts +19 -19
- package/src/components/one-time-code/one-time-code.tsx +216 -200
- package/src/components/picker/picker-trigger.ts +16 -13
- package/src/components/picker/picker.tsx +371 -345
- package/src/components/popover/anchored-surface.tsx +253 -229
- package/src/components/popover/index.ts +50 -0
- package/src/components/popover/popover-content.tsx +334 -0
- package/src/components/popover/popover-fit.ts +58 -53
- package/src/components/popover/popover-root.tsx +97 -0
- package/src/components/popover/popover-trigger.tsx +71 -0
- package/src/components/profile-image/profile-image.tsx +80 -64
- package/src/components/progress-view/progress-view.tsx +61 -59
- package/src/components/progress-view/use-liquid-progress.ts +38 -38
- package/src/components/radio-group/radio-group.tsx +71 -68
- package/src/components/search-field/expanding-search-field.tsx +191 -177
- package/src/components/search-field/search-field.tsx +59 -50
- package/src/components/search-list/search-list.tsx +246 -236
- package/src/components/section/section.tsx +58 -58
- package/src/components/secure-field/secure-field.tsx +3 -3
- package/src/components/segmented-control/segmented-control.tsx +136 -136
- package/src/components/sheet/modal-environment.ts +71 -64
- package/src/components/sheet/sheet-portal.tsx +58 -53
- package/src/components/sheet/sheet.tsx +146 -141
- package/src/components/sheet/use-sheet-focus.ts +97 -82
- package/src/components/sidebar/sidebar.tsx +78 -78
- package/src/components/skeleton/skeleton.tsx +30 -21
- package/src/components/slider/slider.tsx +113 -104
- package/src/components/slosh-slider/liquid-step.ts +32 -31
- package/src/components/slosh-slider/slosh-slider.tsx +265 -228
- package/src/components/stat-tile/index.ts +1 -1
- package/src/components/stat-tile/stat-tile.tsx +79 -68
- package/src/components/status-indicator/status-indicator.tsx +40 -37
- package/src/components/stepper/rolling-digit.tsx +82 -68
- package/src/components/stepper/stepper.tsx +122 -113
- package/src/components/swatch-picker/swatch-picker.tsx +120 -120
- package/src/components/tab-bar/tab-bar.tsx +149 -148
- package/src/components/tab-view/tab-view.tsx +140 -137
- package/src/components/table/table.tsx +117 -98
- package/src/components/text-editor/text-editor.tsx +34 -29
- package/src/components/text-field/text-field.tsx +182 -180
- package/src/components/toast/toast-store.ts +127 -115
- package/src/components/toast/toaster.tsx +361 -347
- package/src/components/toggle/toggle.tsx +297 -282
- package/src/components/tooltip/tooltip-host.tsx +157 -150
- package/src/components/view-controller/index.ts +1 -1
- package/src/components/view-controller/view-controller.tsx +64 -53
- package/src/components/wake-slider/wake-slider.tsx +220 -205
- package/src/hooks/scroll/minimize-decision.ts +11 -7
- package/src/hooks/use-anchored-disclosure.ts +19 -19
- package/src/hooks/use-anchored-placement.ts +29 -25
- package/src/hooks/use-dismiss.ts +33 -29
- package/src/hooks/use-floating-dismiss.ts +24 -22
- package/src/hooks/use-media-query.ts +67 -60
- package/src/hooks/use-minimize-on-scroll.ts +69 -60
- package/src/hooks/use-visual-viewport.ts +63 -63
- package/src/hooks/viewport/types.ts +16 -16
- package/src/hooks/viewport/viewport-metrics.ts +16 -10
- package/src/icons/icons.tsx +440 -328
- package/src/index.ts +91 -91
- package/src/lib/anchored-placement.ts +70 -65
- package/src/lib/class-names.ts +14 -13
- package/src/lib/clipboard.ts +8 -7
- package/src/lib/date.ts +61 -60
- package/src/lib/floating-layers.ts +39 -24
- package/src/lib/haptics.ts +10 -10
- package/src/lib/language.ts +9 -9
- package/src/lib/range-value.ts +27 -21
- package/src/lib/screen-edges.ts +33 -30
- package/src/lib/shapes.ts +38 -34
- package/src/machines/popover.machine.ts +51 -0
- package/src/motion/transitions.ts +46 -43
- package/src/styles/code-block.css +69 -43
- package/src/styles/motion-controls.css +393 -191
- package/src/tokens.ts +1 -1
- package/dist/types/src/components/popover/popover.d.ts +0 -21
- package/src/components/popover/popover.tsx +0 -322
|
@@ -1,418 +1,459 @@
|
|
|
1
|
-
import { AnimatePresence, motion, useIsPresent, useReducedMotion } from "motion/react"
|
|
2
|
-
import { useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react"
|
|
3
|
-
import { FLOATING_LAYER } from "../../hooks/use-dismiss"
|
|
4
|
-
import { CheckIcon } from "../../icons/icons"
|
|
5
|
-
import { cn } from "../../lib/class-names"
|
|
6
|
-
import { belongsToFloatingSurface, registerFloatingLayer } from "../../lib/floating-layers"
|
|
7
|
-
import { screenEdges } from "../../lib/screen-edges"
|
|
8
|
-
import { spring, fluidOvershoot } from "../../motion/transitions"
|
|
9
|
-
import { concealMenuSource } from "./conceal-menu-source"
|
|
10
|
-
import { findMenuTypeaheadIndex, isMenuNavigationKey, nextMenuIndex } from "./menu-navigation"
|
|
11
|
-
import { menuPosition } from "./menu-position"
|
|
12
|
-
import { menuSurfaceExit, menuSurfaceReveal } from "./menu-reveal"
|
|
13
1
|
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
2
|
+
AnimatePresence,
|
|
3
|
+
motion,
|
|
4
|
+
useIsPresent,
|
|
5
|
+
useReducedMotion,
|
|
6
|
+
} from "motion/react";
|
|
7
|
+
import {
|
|
8
|
+
useEffect,
|
|
9
|
+
useLayoutEffect,
|
|
10
|
+
useRef,
|
|
11
|
+
useState,
|
|
12
|
+
useSyncExternalStore,
|
|
13
|
+
} from "react";
|
|
14
|
+
import { FLOATING_LAYER } from "../../hooks/use-dismiss";
|
|
15
|
+
import { CheckIcon } from "../../icons/icons";
|
|
16
|
+
import { cn } from "../../lib/class-names";
|
|
17
|
+
import {
|
|
18
|
+
belongsToFloatingSurface,
|
|
19
|
+
registerFloatingLayer,
|
|
20
|
+
} from "../../lib/floating-layers";
|
|
21
|
+
import { screenEdges } from "../../lib/screen-edges";
|
|
22
|
+
import { fluidOvershoot } from "../../motion/transitions";
|
|
23
|
+
import { concealMenuSource } from "./conceal-menu-source";
|
|
24
|
+
import {
|
|
25
|
+
findMenuTypeaheadIndex,
|
|
26
|
+
isMenuNavigationKey,
|
|
27
|
+
nextMenuIndex,
|
|
28
|
+
} from "./menu-navigation";
|
|
29
|
+
import { menuPosition } from "./menu-position";
|
|
30
|
+
import { menuSurfaceExit, menuSurfaceReveal } from "./menu-reveal";
|
|
31
|
+
import {
|
|
32
|
+
closeContextMenu,
|
|
33
|
+
getContextMenu,
|
|
34
|
+
type ContextMenuSize,
|
|
35
|
+
subscribeContextMenu,
|
|
36
|
+
} from "./context-menu-store";
|
|
37
|
+
import type { OpenMenu } from "./context-menu-store";
|
|
24
38
|
|
|
25
39
|
const surfaceSizes: Record<ContextMenuSize, string> = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
40
|
+
sm: "min-w-44 max-w-[min(240px,calc(100vw-24px))] rounded-2xl p-1",
|
|
41
|
+
md: "min-w-50 max-w-[min(280px,calc(100vw-24px))] rounded-3xl p-1.5",
|
|
42
|
+
lg: "min-w-56 max-w-[min(320px,calc(100vw-24px))] rounded-3xl p-2",
|
|
43
|
+
};
|
|
30
44
|
const itemSizes: Record<ContextMenuSize, string> = {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
45
|
+
sm: "flex items-center gap-2 rounded-md px-2 py-1 text-start text-caption transition-colors disabled:opacity-40",
|
|
46
|
+
md: "flex items-center gap-2.5 rounded-lg px-2.5 text-start text-subheadline transition-colors disabled:opacity-40",
|
|
47
|
+
lg: "flex items-center gap-3 rounded-lg px-3 py-2 text-start text-body transition-colors disabled:opacity-40",
|
|
48
|
+
};
|
|
35
49
|
const headingSizes: Record<ContextMenuSize, string> = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
50
|
+
sm: "px-2 pt-1 pb-0.5 text-caption2 font-semibold text-label-tertiary",
|
|
51
|
+
md: "px-2.5 pt-1.5 pb-0.5 text-caption2 font-semibold text-label-tertiary",
|
|
52
|
+
lg: "px-3 pt-2 pb-1 text-caption font-semibold text-label-tertiary",
|
|
53
|
+
};
|
|
40
54
|
const dividerSizes: Record<ContextMenuSize, string> = {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
55
|
+
sm: "mx-1.5 my-0.5 h-px bg-separator/80",
|
|
56
|
+
md: "mx-2 my-1 h-px bg-separator/80",
|
|
57
|
+
lg: "mx-2.5 my-1.5 h-px bg-separator/80",
|
|
58
|
+
};
|
|
45
59
|
const iconSlotSizes: Record<ContextMenuSize, string> = {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
60
|
+
sm: "flex w-3.5 shrink-0 justify-center text-label-secondary",
|
|
61
|
+
md: "flex w-4 shrink-0 justify-center text-label-secondary",
|
|
62
|
+
lg: "flex w-5 shrink-0 justify-center text-label-secondary",
|
|
63
|
+
};
|
|
50
64
|
const checkIconSizes: Record<ContextMenuSize, number> = {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
65
|
+
sm: 13,
|
|
66
|
+
md: 15,
|
|
67
|
+
lg: 17,
|
|
68
|
+
};
|
|
55
69
|
|
|
56
70
|
/** Renders the open context menu. Mount once, near the app root. */
|
|
57
71
|
export function ContextMenuHost() {
|
|
58
|
-
|
|
59
|
-
|
|
72
|
+
const menu = useSyncExternalStore(
|
|
73
|
+
subscribeContextMenu,
|
|
74
|
+
getContextMenu,
|
|
75
|
+
() => null,
|
|
76
|
+
);
|
|
77
|
+
return (
|
|
78
|
+
<AnimatePresence>
|
|
79
|
+
{menu && <Menu key={menu.id} menu={menu} />}
|
|
80
|
+
</AnimatePresence>
|
|
81
|
+
);
|
|
60
82
|
}
|
|
61
83
|
|
|
62
84
|
function Menu({ menu }: { menu: OpenMenu }) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
85
|
+
const present = useIsPresent();
|
|
86
|
+
const reducedMotion = useReducedMotion();
|
|
87
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
88
|
+
const content = useRef<HTMLDivElement>(null);
|
|
89
|
+
const [position, setPosition] = useState({
|
|
90
|
+
left: menu.x,
|
|
91
|
+
top: menu.y,
|
|
92
|
+
originX: 0,
|
|
93
|
+
originY: 0,
|
|
94
|
+
maxHeight: undefined as number | undefined,
|
|
95
|
+
width: 0,
|
|
96
|
+
height: 0,
|
|
97
|
+
radius: 0,
|
|
98
|
+
ready: false,
|
|
99
|
+
});
|
|
100
|
+
const [focused, setFocused] = useState(-1);
|
|
101
|
+
const typeahead = useRef({ query: "", at: 0 });
|
|
80
102
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
useLayoutEffect(() => {
|
|
104
|
+
if (
|
|
105
|
+
!present ||
|
|
106
|
+
(!menu.source && !menu.toolbar) ||
|
|
107
|
+
!position.ready ||
|
|
108
|
+
!(menu.anchor instanceof HTMLElement)
|
|
109
|
+
)
|
|
110
|
+
return;
|
|
111
|
+
const anchor = menu.toolbar ?? menu.anchor;
|
|
112
|
+
const surface = ref.current;
|
|
113
|
+
const restore = concealMenuSource(anchor, Boolean(menu.toolbar));
|
|
114
|
+
return () => {
|
|
115
|
+
const restored = restore();
|
|
116
|
+
if (
|
|
117
|
+
restored &&
|
|
118
|
+
menu.toolbar &&
|
|
119
|
+
menu.restoreFocus &&
|
|
120
|
+
menu.anchor instanceof HTMLElement &&
|
|
121
|
+
(document.activeElement === document.body ||
|
|
122
|
+
surface?.contains(document.activeElement))
|
|
123
|
+
)
|
|
124
|
+
menu.anchor.focus({ preventScroll: true });
|
|
125
|
+
};
|
|
126
|
+
}, [menu, position.ready, present]);
|
|
105
127
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
128
|
+
useLayoutEffect(() => {
|
|
129
|
+
const surface = ref.current;
|
|
130
|
+
if (!surface || !present || !position.ready) return;
|
|
131
|
+
const unregister = menu.anchor
|
|
132
|
+
? registerFloatingLayer(surface, menu.anchor)
|
|
133
|
+
: undefined;
|
|
134
|
+
surface.focus();
|
|
135
|
+
return unregister;
|
|
136
|
+
}, [menu.anchor, present, position.ready]);
|
|
113
137
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
138
|
+
// Keep the whole menu on screen, opening up or left when near an edge. The
|
|
139
|
+
// layout size, not the on-screen one: the menu is still mid-scale here.
|
|
140
|
+
useLayoutEffect(() => {
|
|
141
|
+
if (!ref.current || !present) return;
|
|
142
|
+
const viewport = window.visualViewport;
|
|
143
|
+
let frame = 0;
|
|
144
|
+
const refit = () => {
|
|
145
|
+
const element = ref.current;
|
|
146
|
+
if (!element) return;
|
|
147
|
+
const edges = screenEdges();
|
|
148
|
+
const left = viewport?.offsetLeft ?? 0;
|
|
149
|
+
const top = viewport?.offsetTop ?? 0;
|
|
150
|
+
const next = {
|
|
151
|
+
...menuPosition(
|
|
152
|
+
menu,
|
|
153
|
+
{
|
|
154
|
+
width: element.offsetWidth,
|
|
155
|
+
height: Math.max(
|
|
156
|
+
element.offsetHeight,
|
|
157
|
+
(content.current?.scrollHeight ?? 0) + 12,
|
|
158
|
+
),
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
left: left + edges.left,
|
|
162
|
+
top: top + edges.top,
|
|
163
|
+
right: left + (viewport?.width ?? window.innerWidth) - edges.right,
|
|
164
|
+
bottom:
|
|
165
|
+
top + (viewport?.height ?? window.innerHeight) - edges.bottom,
|
|
166
|
+
},
|
|
167
|
+
),
|
|
168
|
+
radius:
|
|
169
|
+
Number.parseFloat(getComputedStyle(element).borderTopLeftRadius) || 0,
|
|
170
|
+
ready: true,
|
|
171
|
+
};
|
|
172
|
+
setPosition((current) =>
|
|
173
|
+
current.left === next.left &&
|
|
174
|
+
current.top === next.top &&
|
|
175
|
+
current.originX === next.originX &&
|
|
176
|
+
current.originY === next.originY &&
|
|
177
|
+
current.maxHeight === next.maxHeight &&
|
|
178
|
+
current.width === next.width &&
|
|
179
|
+
current.height === next.height &&
|
|
180
|
+
current.radius === next.radius &&
|
|
181
|
+
current.ready === next.ready
|
|
182
|
+
? current
|
|
183
|
+
: next,
|
|
184
|
+
);
|
|
185
|
+
};
|
|
186
|
+
const schedule = () => {
|
|
187
|
+
cancelAnimationFrame(frame);
|
|
188
|
+
frame = requestAnimationFrame(refit);
|
|
189
|
+
};
|
|
190
|
+
refit();
|
|
191
|
+
viewport?.addEventListener("resize", schedule);
|
|
192
|
+
viewport?.addEventListener("scroll", schedule);
|
|
193
|
+
window.addEventListener("resize", schedule);
|
|
194
|
+
return () => {
|
|
195
|
+
cancelAnimationFrame(frame);
|
|
196
|
+
viewport?.removeEventListener("resize", schedule);
|
|
197
|
+
viewport?.removeEventListener("scroll", schedule);
|
|
198
|
+
window.removeEventListener("resize", schedule);
|
|
199
|
+
};
|
|
200
|
+
}, [menu, present]);
|
|
175
201
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
202
|
+
useEffect(() => {
|
|
203
|
+
if (!present) return;
|
|
204
|
+
const onPointer = (event: PointerEvent) => {
|
|
205
|
+
if (
|
|
206
|
+
!ref.current ||
|
|
207
|
+
!belongsToFloatingSurface(ref.current, event.target as Element)
|
|
208
|
+
)
|
|
209
|
+
closeContextMenu(false);
|
|
210
|
+
};
|
|
211
|
+
const close = () => closeContextMenu(false);
|
|
212
|
+
let scrollIntentUntil = 0;
|
|
213
|
+
const markScroll = () => {
|
|
214
|
+
scrollIntentUntil = performance.now() + 2000;
|
|
215
|
+
};
|
|
216
|
+
const onScrollKey = (event: KeyboardEvent) => {
|
|
217
|
+
if (
|
|
218
|
+
!ref.current?.contains(event.target as Node) &&
|
|
219
|
+
["PageDown", "PageUp", "Home", "End", " "].includes(event.key)
|
|
220
|
+
)
|
|
221
|
+
markScroll();
|
|
222
|
+
};
|
|
223
|
+
const onScroll = (event: Event) => {
|
|
224
|
+
if (
|
|
225
|
+
performance.now() < scrollIntentUntil &&
|
|
226
|
+
!ref.current?.contains(event.target as Node)
|
|
227
|
+
)
|
|
228
|
+
close();
|
|
229
|
+
};
|
|
230
|
+
// Opened by a long-press: ignore the finger lifting off.
|
|
231
|
+
const timer = setTimeout(() => {
|
|
232
|
+
window.addEventListener("pointerdown", onPointer, true);
|
|
233
|
+
}, 0);
|
|
234
|
+
window.addEventListener("blur", close);
|
|
235
|
+
window.addEventListener("wheel", markScroll, {
|
|
236
|
+
capture: true,
|
|
237
|
+
passive: true,
|
|
238
|
+
});
|
|
239
|
+
window.addEventListener("touchmove", markScroll, {
|
|
240
|
+
capture: true,
|
|
241
|
+
passive: true,
|
|
242
|
+
});
|
|
243
|
+
window.addEventListener("keydown", onScrollKey, true);
|
|
244
|
+
window.addEventListener("scroll", onScroll, true);
|
|
245
|
+
return () => {
|
|
246
|
+
clearTimeout(timer);
|
|
247
|
+
window.removeEventListener("pointerdown", onPointer, true);
|
|
248
|
+
window.removeEventListener("blur", close);
|
|
249
|
+
window.removeEventListener("wheel", markScroll, true);
|
|
250
|
+
window.removeEventListener("touchmove", markScroll, true);
|
|
251
|
+
window.removeEventListener("keydown", onScrollKey, true);
|
|
252
|
+
window.removeEventListener("scroll", onScroll, true);
|
|
253
|
+
};
|
|
254
|
+
}, [present]);
|
|
226
255
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
256
|
+
const source = menuSurfaceReveal(
|
|
257
|
+
position.ready ? (menu.toolbarRect ?? menu.source) : undefined,
|
|
258
|
+
position,
|
|
259
|
+
);
|
|
260
|
+
let actionIndex = -1;
|
|
261
|
+
let dividerIndex = 0;
|
|
262
|
+
let headingIndex = 0;
|
|
263
|
+
return (
|
|
264
|
+
<div
|
|
265
|
+
ref={ref}
|
|
266
|
+
role="menu"
|
|
267
|
+
tabIndex={-1}
|
|
268
|
+
onKeyDown={(event) => {
|
|
269
|
+
if (!present) return;
|
|
270
|
+
if (event.key === "Escape") {
|
|
271
|
+
event.preventDefault();
|
|
272
|
+
event.stopPropagation();
|
|
273
|
+
closeContextMenu();
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
if (event.key === "Tab") {
|
|
277
|
+
closeContextMenu();
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
const controls = Array.from(
|
|
281
|
+
ref.current?.querySelectorAll<HTMLButtonElement>(
|
|
282
|
+
"[role=menuitem]:not(:disabled)",
|
|
283
|
+
) ?? [],
|
|
284
|
+
);
|
|
285
|
+
if (!isMenuNavigationKey(event.key)) {
|
|
286
|
+
if (
|
|
287
|
+
event.key.length !== 1 ||
|
|
288
|
+
!event.key.trim() ||
|
|
289
|
+
event.altKey ||
|
|
290
|
+
event.ctrlKey ||
|
|
291
|
+
event.metaKey ||
|
|
292
|
+
event.nativeEvent.isComposing
|
|
293
|
+
)
|
|
294
|
+
return;
|
|
295
|
+
const now = performance.now();
|
|
296
|
+
const query =
|
|
297
|
+
(now - typeahead.current.at < 700 ? typeahead.current.query : "") +
|
|
298
|
+
event.key;
|
|
299
|
+
typeahead.current = { query, at: now };
|
|
300
|
+
const labels = controls.map((control) => control.textContent ?? "");
|
|
301
|
+
const current = controls.indexOf(
|
|
302
|
+
document.activeElement as HTMLButtonElement,
|
|
303
|
+
);
|
|
304
|
+
let next = findMenuTypeaheadIndex(labels, query, current);
|
|
305
|
+
if (next < 0) {
|
|
306
|
+
typeahead.current.query = event.key;
|
|
307
|
+
next = findMenuTypeaheadIndex(labels, event.key, current);
|
|
308
|
+
}
|
|
309
|
+
if (next >= 0) {
|
|
310
|
+
event.preventDefault();
|
|
311
|
+
controls[next]?.focus();
|
|
312
|
+
}
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
event.preventDefault();
|
|
316
|
+
if (!controls.length) return;
|
|
317
|
+
const current = controls.indexOf(
|
|
318
|
+
document.activeElement as HTMLButtonElement,
|
|
319
|
+
);
|
|
320
|
+
const next = nextMenuIndex(event.key, current, controls.length);
|
|
321
|
+
controls[next]?.focus();
|
|
322
|
+
}}
|
|
323
|
+
{...{ [FLOATING_LAYER]: "" }}
|
|
324
|
+
className={cn(
|
|
325
|
+
"fixed isolate z-75 flex flex-col outline-none",
|
|
326
|
+
surfaceSizes[menu.size],
|
|
327
|
+
menu.touch && "min-w-60",
|
|
328
|
+
!present && "pointer-events-none",
|
|
329
|
+
)}
|
|
330
|
+
style={{
|
|
331
|
+
left: position.left,
|
|
332
|
+
top: position.top,
|
|
333
|
+
maxHeight: position.maxHeight,
|
|
334
|
+
minWidth: menu.toolbarRect
|
|
335
|
+
? Math.min(
|
|
336
|
+
Math.max(200, menu.toolbarRect.width),
|
|
337
|
+
window.innerWidth - 24,
|
|
338
|
+
)
|
|
339
|
+
: undefined,
|
|
340
|
+
visibility: position.ready ? undefined : "hidden",
|
|
341
|
+
}}
|
|
342
|
+
onContextMenu={(event) => event.preventDefault()}
|
|
343
|
+
>
|
|
344
|
+
{position.ready && (
|
|
345
|
+
<motion.div
|
|
346
|
+
aria-hidden="true"
|
|
347
|
+
className="glass-menu pointer-events-none absolute top-0 left-0 -z-10 rounded-3xl"
|
|
348
|
+
style={{ width: "100%", height: "100%" }}
|
|
349
|
+
initial={reducedMotion || !position.ready ? false : source}
|
|
350
|
+
animate={
|
|
351
|
+
position.ready
|
|
352
|
+
? {
|
|
353
|
+
x: 0,
|
|
354
|
+
y: 0,
|
|
355
|
+
width: position.width,
|
|
356
|
+
height: position.height,
|
|
357
|
+
opacity: 1,
|
|
358
|
+
borderRadius: position.radius,
|
|
359
|
+
}
|
|
360
|
+
: undefined
|
|
361
|
+
}
|
|
362
|
+
exit={reducedMotion ? { opacity: 0 } : menuSurfaceExit(source)}
|
|
363
|
+
transition={
|
|
364
|
+
reducedMotion
|
|
365
|
+
? { duration: 0 }
|
|
366
|
+
: { ...fluidOvershoot, opacity: { duration: 0.16 } }
|
|
367
|
+
}
|
|
368
|
+
/>
|
|
369
|
+
)}
|
|
370
|
+
<motion.div
|
|
371
|
+
ref={content}
|
|
372
|
+
className="flex flex-col overflow-y-auto overscroll-contain"
|
|
373
|
+
style={{
|
|
374
|
+
maxHeight: position.maxHeight
|
|
375
|
+
? Math.max(0, position.maxHeight - 12)
|
|
376
|
+
: undefined,
|
|
377
|
+
}}
|
|
378
|
+
initial={
|
|
379
|
+
reducedMotion
|
|
380
|
+
? false
|
|
381
|
+
: {
|
|
382
|
+
opacity: 0,
|
|
383
|
+
scale: 0.96,
|
|
384
|
+
y: menu.source && menu.source.top > position.top ? 4 : -4,
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
animate={{ opacity: 1, scale: 1, y: 0 }}
|
|
388
|
+
exit={{
|
|
389
|
+
opacity: 0,
|
|
390
|
+
scale: 0.98,
|
|
391
|
+
transition: {
|
|
392
|
+
duration: reducedMotion ? 0 : 0.06,
|
|
393
|
+
},
|
|
394
|
+
}}
|
|
395
|
+
transition={{
|
|
396
|
+
duration: reducedMotion ? 0 : 0.2,
|
|
397
|
+
ease: reducedMotion
|
|
398
|
+
? undefined
|
|
399
|
+
: ([0.4, 0, 0.2, 1] as [number, number, number, number]),
|
|
400
|
+
delay: reducedMotion || !menu.source ? 0 : 0.06,
|
|
401
|
+
}}
|
|
402
|
+
>
|
|
403
|
+
{menu.items.map((item) => {
|
|
404
|
+
if (item === "divider") {
|
|
405
|
+
const key = `divider-${dividerIndex++}`;
|
|
406
|
+
return <div key={key} className={dividerSizes[menu.size]} />;
|
|
407
|
+
}
|
|
408
|
+
if ("heading" in item) {
|
|
409
|
+
const key = `heading-${headingIndex++}`;
|
|
410
|
+
return (
|
|
411
|
+
<span key={key} className={headingSizes[menu.size]}>
|
|
412
|
+
{item.heading}
|
|
413
|
+
</span>
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
if (!item.disabled) actionIndex += 1;
|
|
417
|
+
const current = actionIndex;
|
|
418
|
+
const key = `item-${current}`;
|
|
419
|
+
return (
|
|
420
|
+
<button
|
|
421
|
+
key={key}
|
|
422
|
+
type="button"
|
|
423
|
+
role="menuitem"
|
|
424
|
+
tabIndex={-1}
|
|
425
|
+
disabled={item.disabled}
|
|
426
|
+
onFocus={() => setFocused(current)}
|
|
427
|
+
onPointerEnter={() => !item.disabled && setFocused(current)}
|
|
428
|
+
onClick={() => {
|
|
429
|
+
closeContextMenu();
|
|
430
|
+
item.onSelect();
|
|
431
|
+
}}
|
|
432
|
+
className={cn(
|
|
433
|
+
itemSizes[menu.size],
|
|
434
|
+
menu.touch ? "py-2.5" : "py-1.5",
|
|
435
|
+
item.destructive ? "text-danger" : "text-label",
|
|
436
|
+
focused === current &&
|
|
437
|
+
!item.disabled &&
|
|
438
|
+
(item.destructive ? "bg-danger/10" : "bg-fill"),
|
|
439
|
+
)}
|
|
440
|
+
>
|
|
441
|
+
<span className={iconSlotSizes[menu.size]}>
|
|
442
|
+
{item.checked ? (
|
|
443
|
+
<CheckIcon
|
|
444
|
+
size={checkIconSizes[menu.size]}
|
|
445
|
+
strokeWidth={2.4}
|
|
446
|
+
className="text-accent-text"
|
|
447
|
+
/>
|
|
448
|
+
) : (
|
|
449
|
+
item.icon
|
|
450
|
+
)}
|
|
451
|
+
</span>
|
|
452
|
+
<span className="grow truncate">{item.label}</span>
|
|
453
|
+
</button>
|
|
454
|
+
);
|
|
455
|
+
})}
|
|
456
|
+
</motion.div>
|
|
457
|
+
</div>
|
|
458
|
+
);
|
|
418
459
|
}
|