@plexui/vue 0.12.0 → 0.14.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/es/components/ContextMenu/ContextMenu.js +217 -41
- package/dist/es/components/ContextMenu/ContextMenu.js.map +1 -1
- package/dist/es/components/ContextMenu/shared.js +182 -8
- package/dist/es/components/ContextMenu/shared.js.map +1 -1
- package/dist/es/components/Dialog/Dialog.js +66 -15
- package/dist/es/components/Dialog/Dialog.js.map +1 -1
- package/dist/es/components/Dialog/index.js +1 -1
- package/dist/es/components/Dialog/index.js.map +1 -1
- package/dist/es/components/Menu/Menu.js +5 -3
- package/dist/es/components/Menu/Menu.js.map +1 -1
- package/dist/es/lib/contextMenuHold.js +23 -0
- package/dist/es/lib/contextMenuHold.js.map +1 -0
- package/dist/es/lib/sortable.js +31 -2
- package/dist/es/lib/sortable.js.map +1 -1
- package/dist/types/components/ContextMenu/ContextMenu.d.ts +59 -10
- package/dist/types/components/ContextMenu/shared.d.ts +53 -8
- package/dist/types/components/DatePicker/DatePicker.d.ts +2 -2
- package/dist/types/components/DateRangePicker/DateRangePicker.d.ts +2 -2
- package/dist/types/components/Dialog/Dialog.d.ts +11 -1
- package/dist/types/components/Dialog/index.d.ts +1 -1
- package/dist/types/components/Menu/Menu.d.ts +16 -0
- package/dist/types/components/Tip/Tip.d.ts +1 -1
- package/dist/types/components/Tooltip/CopyTooltip.d.ts +1 -1
- package/dist/types/lib/contextMenuHold.d.ts +21 -0
- package/package.json +2 -2
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { cloneVNode, defineComponent, h, inject, onBeforeUnmount, onMounted, provide, shallowRef, Teleport, } from "vue";
|
|
1
|
+
import { cloneVNode, computed, defineComponent, h, inject, onBeforeUnmount, onMounted, provide, shallowRef, Teleport, watch, } from "vue";
|
|
2
2
|
import s from "@plexui/styles/components/ContextMenu/ContextMenu.module.css";
|
|
3
|
+
import { CONTEXT_MENU_TRIGGER, SORTABLE_HANDLE, SORTABLE_SOURCE, sendContextMenuHold } from "../../lib/contextMenuHold.js";
|
|
4
|
+
import { readMenuBoundaryRect } from "../../lib/menuSubmenuPlacement.js";
|
|
5
|
+
import { isPhoneLayout } from "../../lib/phoneLayout.js";
|
|
3
6
|
import { firstElementChild, mergeSlotProps } from "../Tooltip/slot.js";
|
|
4
|
-
import { Menu, MenuContent, MenuTrigger, useMenuContext } from "../Menu/Menu.js";
|
|
7
|
+
import { Menu, MenuContent, MenuTrigger, useMenuBoundary, useMenuContext, useMenuPhoneLayout } from "../Menu/Menu.js";
|
|
5
8
|
import { useMenuRootInternals } from "../Menu/internal.js";
|
|
6
9
|
import { TransitionGroup } from "../Transition/index.js";
|
|
7
10
|
import { overlayTiming } from "../Transition/shared.js";
|
|
8
|
-
import { CONTEXT_MENU_LONG_PRESS, CONTEXT_MENU_LONG_PRESS_SLOP, contextMenuHoleMask, contextMenuPlacement, contextMenuPreview, } from "./shared.js";
|
|
11
|
+
import { CONTEXT_MENU_LONG_PRESS, CONTEXT_MENU_LONG_PRESS_SLOP, contextMenuClipTop, contextMenuFrame, contextMenuHoleMask, contextMenuInFrame, contextMenuName, contextMenuNaturalHeight, contextMenuPlacement, contextMenuPreview, contextMenuPreviewShift, liftContextMenuPreview, } from "./shared.js";
|
|
9
12
|
const CONTEXT_MENU = Symbol("ContextMenu");
|
|
10
13
|
const useContextMenuContext = (part) => {
|
|
11
14
|
const context = inject(CONTEXT_MENU, null);
|
|
@@ -16,15 +19,74 @@ const useContextMenuContext = (part) => {
|
|
|
16
19
|
const ContextMenuComponent = defineComponent({
|
|
17
20
|
name: "ContextMenu",
|
|
18
21
|
inheritAttrs: false,
|
|
22
|
+
props: {
|
|
23
|
+
/**
|
|
24
|
+
* Holds the menu open (`true`) or closed (`false`). Held open without a press, it stands at the element: as the
|
|
25
|
+
* touch-and-hold preview on a phone, under the element elsewhere, and it follows the element as the page scrolls.
|
|
26
|
+
*/
|
|
27
|
+
forceOpen: { type: Boolean, default: undefined },
|
|
28
|
+
},
|
|
19
29
|
emits: {
|
|
20
30
|
/** The menu opened */
|
|
21
31
|
open: () => true,
|
|
22
32
|
/** The menu closed */
|
|
23
33
|
close: () => true,
|
|
24
34
|
},
|
|
25
|
-
setup(
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
setup(props, { emit, slots }) {
|
|
36
|
+
const presentation = shallowRef(null);
|
|
37
|
+
const frame = shallowRef(null);
|
|
38
|
+
const name = shallowRef("");
|
|
39
|
+
const region = shallowRef(null);
|
|
40
|
+
// Inside a PhoneLayout the anchor and the dimming lie in its box, as the menu does
|
|
41
|
+
const { container } = useMenuPhoneLayout();
|
|
42
|
+
let restore = null;
|
|
43
|
+
let held = false;
|
|
44
|
+
// Puts the element back; after a glide back the restore stays, so that a press or a close that follows stops it
|
|
45
|
+
const drop = (glide) => {
|
|
46
|
+
const current = restore;
|
|
47
|
+
current?.(glide);
|
|
48
|
+
restore = glide ? current : null;
|
|
49
|
+
};
|
|
50
|
+
// The content going away while the element stays: the element back in place, and measured anew when it returns
|
|
51
|
+
const release = () => {
|
|
52
|
+
drop(false);
|
|
53
|
+
const preview = presentation.value;
|
|
54
|
+
if (preview?.kind !== "preview" || preview.shift === undefined)
|
|
55
|
+
return;
|
|
56
|
+
presentation.value = { ...preview, rect: { ...preview.rect, y: preview.rect.y + preview.shift }, shift: undefined };
|
|
57
|
+
};
|
|
58
|
+
const present = (element, measure, still = false) => {
|
|
59
|
+
drop(false);
|
|
60
|
+
held = still;
|
|
61
|
+
region.value = element;
|
|
62
|
+
presentation.value = measure();
|
|
63
|
+
frame.value = contextMenuFrame(container.value);
|
|
64
|
+
name.value = contextMenuName(element);
|
|
65
|
+
};
|
|
66
|
+
const lift = (shift) => {
|
|
67
|
+
const element = region.value;
|
|
68
|
+
drop(false);
|
|
69
|
+
if (element && shift > 0)
|
|
70
|
+
restore = liftContextMenuPreview(element, shift, !held);
|
|
71
|
+
const preview = presentation.value;
|
|
72
|
+
if (preview?.kind !== "preview")
|
|
73
|
+
return;
|
|
74
|
+
presentation.value = { ...preview, rect: { ...preview.rect, y: preview.rect.y - shift }, shift };
|
|
75
|
+
};
|
|
76
|
+
onBeforeUnmount(() => drop(false));
|
|
77
|
+
provide(CONTEXT_MENU, {
|
|
78
|
+
presentation,
|
|
79
|
+
frame,
|
|
80
|
+
name,
|
|
81
|
+
region,
|
|
82
|
+
container,
|
|
83
|
+
forced: computed(() => props.forceOpen === true),
|
|
84
|
+
present,
|
|
85
|
+
lift,
|
|
86
|
+
drop,
|
|
87
|
+
release,
|
|
88
|
+
});
|
|
89
|
+
return () => h(Menu, { forceOpen: props.forceOpen, onOpen: () => emit("open"), onClose: () => emit("close") }, { default: () => slots.default?.() });
|
|
28
90
|
},
|
|
29
91
|
});
|
|
30
92
|
/**
|
|
@@ -59,6 +121,13 @@ const suppressNextClick = (doc) => {
|
|
|
59
121
|
doc.addEventListener("click", swallow, true);
|
|
60
122
|
doc.addEventListener("pointerdown", stop, true);
|
|
61
123
|
};
|
|
124
|
+
/** A menu held open without a press: the touch-and-hold preview on a phone, under the element elsewhere. */
|
|
125
|
+
const forcedPresentation = (element) => {
|
|
126
|
+
if (!isPhoneLayout(element))
|
|
127
|
+
return { kind: "keyboard", rect: element.getBoundingClientRect() };
|
|
128
|
+
const box = element.getBoundingClientRect();
|
|
129
|
+
return contextMenuPreview(element, box.left + box.width / 2);
|
|
130
|
+
};
|
|
62
131
|
const ContextMenuTriggerComponent = defineComponent({
|
|
63
132
|
name: "ContextMenuTrigger",
|
|
64
133
|
inheritAttrs: false,
|
|
@@ -69,7 +138,8 @@ const ContextMenuTriggerComponent = defineComponent({
|
|
|
69
138
|
setup(props, { attrs, slots }) {
|
|
70
139
|
const menu = useMenuContext();
|
|
71
140
|
const internals = useMenuRootInternals();
|
|
72
|
-
const {
|
|
141
|
+
const { present, drop, forced } = useContextMenuContext("ContextMenuTrigger");
|
|
142
|
+
const element = shallowRef(null);
|
|
73
143
|
let press = null;
|
|
74
144
|
const cancel = () => {
|
|
75
145
|
if (press)
|
|
@@ -77,26 +147,64 @@ const ContextMenuTriggerComponent = defineComponent({
|
|
|
77
147
|
press = null;
|
|
78
148
|
};
|
|
79
149
|
onBeforeUnmount(cancel);
|
|
80
|
-
|
|
81
|
-
|
|
150
|
+
// A menu held open stands at the element, and follows it as the page around it scrolls or the window changes
|
|
151
|
+
watch([forced, element], ([held, node], _, onCleanup) => {
|
|
152
|
+
if (!held || !node)
|
|
153
|
+
return;
|
|
154
|
+
const doc = node.ownerDocument;
|
|
155
|
+
const view = doc.defaultView;
|
|
156
|
+
const place = () => present(node, () => forcedPresentation(node), true);
|
|
157
|
+
place();
|
|
158
|
+
let frame = 0;
|
|
159
|
+
const follow = (event) => {
|
|
160
|
+
if (event.target instanceof Node && event.target !== doc && !event.target.contains(node))
|
|
161
|
+
return;
|
|
162
|
+
view?.cancelAnimationFrame(frame);
|
|
163
|
+
frame = view?.requestAnimationFrame(place) ?? 0;
|
|
164
|
+
};
|
|
165
|
+
view?.addEventListener("resize", follow);
|
|
166
|
+
doc.addEventListener("scroll", follow, { capture: true, passive: true });
|
|
167
|
+
onCleanup(() => {
|
|
168
|
+
view?.cancelAnimationFrame(frame);
|
|
169
|
+
view?.removeEventListener("resize", follow);
|
|
170
|
+
doc.removeEventListener("scroll", follow, { capture: true });
|
|
171
|
+
});
|
|
172
|
+
}, { immediate: true, flush: "post" });
|
|
173
|
+
const open = (node, measure) => {
|
|
174
|
+
present(node, measure);
|
|
82
175
|
menu.setOpen(true);
|
|
83
176
|
};
|
|
84
|
-
const openPreview = (
|
|
85
|
-
|
|
86
|
-
|
|
177
|
+
const openPreview = (node, x) => open(node, () => contextMenuPreview(node, x));
|
|
178
|
+
// A touch and hold opens the preview once, by the timer or by the browser's own context menu (Android)
|
|
179
|
+
const openHeld = (node, current) => {
|
|
180
|
+
// A Sortable list around the element already turned this hold into a drag
|
|
181
|
+
if (node.ownerDocument.querySelector(SORTABLE_SOURCE))
|
|
182
|
+
return cancel();
|
|
183
|
+
window.clearTimeout(current.timer);
|
|
184
|
+
current.opened = true;
|
|
185
|
+
openPreview(node, current.x);
|
|
186
|
+
// The same hold drags the element where it is a Sortable item: moving on, the finger closes the menu
|
|
187
|
+
sendContextMenuHold(node, {
|
|
188
|
+
pointerId: current.id,
|
|
189
|
+
close: () => {
|
|
190
|
+
drop(false);
|
|
191
|
+
menu.setOpen(false);
|
|
192
|
+
},
|
|
193
|
+
});
|
|
87
194
|
};
|
|
88
195
|
const handlers = {
|
|
89
196
|
onPointerdown: (event) => {
|
|
90
197
|
if (event.defaultPrevented || props.disabled || event.pointerType !== "touch" || !event.isPrimary)
|
|
91
198
|
return;
|
|
199
|
+
// The grip of a Sortable item drags at once
|
|
200
|
+
if (event.target instanceof Element && event.target.closest(SORTABLE_HANDLE))
|
|
201
|
+
return;
|
|
92
202
|
cancel();
|
|
93
|
-
const
|
|
203
|
+
const node = event.currentTarget;
|
|
94
204
|
const x = event.clientX;
|
|
95
205
|
const timer = window.setTimeout(() => {
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
press.opened = true;
|
|
99
|
-
openPreview(element, x);
|
|
206
|
+
if (press && press.timer === timer)
|
|
207
|
+
openHeld(node, press);
|
|
100
208
|
}, CONTEXT_MENU_LONG_PRESS);
|
|
101
209
|
press = { id: event.pointerId, x, y: event.clientY, timer, opened: false };
|
|
102
210
|
},
|
|
@@ -121,44 +229,52 @@ const ContextMenuTriggerComponent = defineComponent({
|
|
|
121
229
|
if (event.defaultPrevented || props.disabled)
|
|
122
230
|
return;
|
|
123
231
|
event.preventDefault();
|
|
124
|
-
const
|
|
125
|
-
region.value = element;
|
|
232
|
+
const node = event.currentTarget;
|
|
126
233
|
// A touch and hold that the browser reports as a context menu (Android) opens the preview once.
|
|
127
234
|
if (press) {
|
|
128
|
-
if (press.opened)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
press.opened = true;
|
|
132
|
-
return openPreview(element, press.x);
|
|
235
|
+
if (!press.opened)
|
|
236
|
+
openHeld(node, press);
|
|
237
|
+
return;
|
|
133
238
|
}
|
|
134
239
|
if (internals.isUsingKeyboard.current)
|
|
135
|
-
return open({ kind: "keyboard", rect:
|
|
136
|
-
|
|
240
|
+
return open(node, () => ({ kind: "keyboard", rect: node.getBoundingClientRect() }));
|
|
241
|
+
const { clientX, clientY } = event;
|
|
242
|
+
open(node, () => ({ kind: "pointer", rect: { x: clientX, y: clientY, width: 0, height: 0 } }));
|
|
137
243
|
},
|
|
138
244
|
};
|
|
245
|
+
// The element itself, also when the child is a component
|
|
246
|
+
const setElement = (node) => {
|
|
247
|
+
const found = node instanceof Element ? node : node?.$el;
|
|
248
|
+
element.value = found instanceof HTMLElement ? found : null;
|
|
249
|
+
};
|
|
139
250
|
return () => {
|
|
140
251
|
const child = firstElementChild(slots.default?.());
|
|
141
252
|
if (!child)
|
|
142
253
|
return null;
|
|
143
|
-
|
|
254
|
+
const own = { [CONTEXT_MENU_TRIGGER]: props.disabled ? undefined : "" };
|
|
255
|
+
// A component that changes its own root renders again without this trigger: its vnode hook follows the new root
|
|
256
|
+
return cloneVNode(mergeSlotProps(child, { ...attrs, ...own, class: [s.Trigger, attrs.class], ...handlers }), { ref: setElement, onVnodeUpdated: (vnode) => setElement(vnode.el) }, true);
|
|
144
257
|
};
|
|
145
258
|
},
|
|
146
259
|
});
|
|
147
260
|
/** The element the menu is for (React `ContextMenu.Trigger`): it renders its child, which keeps its own role and focus. */
|
|
148
261
|
export const ContextMenuTrigger = ContextMenuTriggerComponent;
|
|
149
262
|
/**
|
|
150
|
-
* Reaches the body once mounted, as Reka's own Teleport does for the menu. Each one is its own
|
|
151
|
-
* anchor, the dimming and the menu of a context menu land in that order, as React's portals, also
|
|
152
|
-
* several context menus.
|
|
263
|
+
* Reaches the body, or the PhoneLayout box, once mounted, as Reka's own Teleport does for the menu. Each one is its own
|
|
264
|
+
* component, so the anchor, the dimming and the menu of a context menu land in that order, as React's portals, also
|
|
265
|
+
* when a page has several context menus.
|
|
153
266
|
*/
|
|
154
267
|
const BodyTeleport = defineComponent({
|
|
155
268
|
name: "ContextMenuTeleport",
|
|
156
|
-
|
|
269
|
+
props: {
|
|
270
|
+
to: { type: Object, default: null },
|
|
271
|
+
},
|
|
272
|
+
setup(props, { slots }) {
|
|
157
273
|
const mounted = shallowRef(false);
|
|
158
274
|
onMounted(() => {
|
|
159
275
|
mounted.value = true;
|
|
160
276
|
});
|
|
161
|
-
return () => (mounted.value ? h(Teleport, { to: "body" }, slots.default?.() ?? []) : null);
|
|
277
|
+
return () => (mounted.value ? h(Teleport, { to: props.to ?? "body" }, slots.default?.() ?? []) : null);
|
|
162
278
|
},
|
|
163
279
|
});
|
|
164
280
|
const ContextMenuContentComponent = defineComponent({
|
|
@@ -173,40 +289,100 @@ const ContextMenuContentComponent = defineComponent({
|
|
|
173
289
|
maxHeight: Number,
|
|
174
290
|
/** Rounder list with fully rounded rows. */
|
|
175
291
|
pill: { type: Boolean, default: false },
|
|
292
|
+
/** Names the menu for assistive technology. Without it the menu takes the name of its element. */
|
|
293
|
+
ariaLabel: String,
|
|
176
294
|
},
|
|
177
295
|
setup(props, { slots }) {
|
|
178
296
|
const { open } = useMenuContext();
|
|
179
|
-
const { presentation, region } = useContextMenuContext("ContextMenuContent");
|
|
297
|
+
const { presentation, frame, name, region, container, lift, drop, release } = useContextMenuContext("ContextMenuContent");
|
|
298
|
+
const boundary = useMenuBoundary(() => open.value);
|
|
299
|
+
let anchor = null;
|
|
300
|
+
const setAnchor = (node) => {
|
|
301
|
+
anchor = node instanceof HTMLElement ? node : null;
|
|
302
|
+
};
|
|
180
303
|
// Focus goes back to the element only when the keyboard opened the menu; a pointer leaves it where it was.
|
|
181
304
|
const onCloseAutoFocus = (event) => {
|
|
182
305
|
event.preventDefault();
|
|
183
306
|
if (presentation.value?.kind === "keyboard")
|
|
184
307
|
region.value?.focus({ preventScroll: true });
|
|
185
308
|
};
|
|
309
|
+
// The preview moves up so that the menu stands whole below it, measured as the menu first lays out, before it shows
|
|
310
|
+
const pending = computed(() => {
|
|
311
|
+
const current = presentation.value;
|
|
312
|
+
return open.value && current?.kind === "preview" && current.shift === undefined;
|
|
313
|
+
});
|
|
314
|
+
let frameId = 0;
|
|
315
|
+
const measure = () => {
|
|
316
|
+
const current = presentation.value;
|
|
317
|
+
const element = region.value;
|
|
318
|
+
if (!open.value || current?.kind !== "preview" || current.shift !== undefined || !element)
|
|
319
|
+
return;
|
|
320
|
+
const content = anchor?.ownerDocument.getElementById(anchor.getAttribute("aria-controls") ?? "");
|
|
321
|
+
// The menu of a PhoneLayout mounts a frame later, with the box it portals into, and content mounted again while
|
|
322
|
+
// the menu is open finds its anchor (in a portal) a frame later too
|
|
323
|
+
if (!content) {
|
|
324
|
+
frameId = requestAnimationFrame(measure);
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const bounds = readMenuBoundaryRect(element.ownerDocument, boundary.value);
|
|
328
|
+
// On the screen, as the room is: a PhoneLayout drawn smaller draws the menu smaller too
|
|
329
|
+
const height = Math.min(contextMenuNaturalHeight(content), props.maxHeight ?? Infinity) * (frame.value?.scaleY ?? 1);
|
|
330
|
+
// A room not known yet (no layout) moves nothing
|
|
331
|
+
const known = bounds && bounds.bottom > bounds.top;
|
|
332
|
+
lift(known ? contextMenuPreviewShift(current.rect, height, bounds, contextMenuClipTop(element), frame.value?.scaleY ?? 1) : 0);
|
|
333
|
+
};
|
|
334
|
+
watch(pending, (now) => {
|
|
335
|
+
cancelAnimationFrame(frameId);
|
|
336
|
+
if (now)
|
|
337
|
+
measure();
|
|
338
|
+
}, { flush: "post" });
|
|
339
|
+
// Content mounted while a preview waits for its move (mounted again, the menu held open) measures it at once
|
|
340
|
+
onMounted(() => {
|
|
341
|
+
if (pending.value)
|
|
342
|
+
measure();
|
|
343
|
+
});
|
|
344
|
+
watch(open, (now) => {
|
|
345
|
+
if (!now)
|
|
346
|
+
drop(true);
|
|
347
|
+
}, { flush: "post" });
|
|
348
|
+
onBeforeUnmount(() => {
|
|
349
|
+
cancelAnimationFrame(frameId);
|
|
350
|
+
// The content going away while the element stays puts the element back
|
|
351
|
+
release();
|
|
352
|
+
});
|
|
186
353
|
return () => {
|
|
187
354
|
const current = presentation.value;
|
|
355
|
+
const box = frame.value;
|
|
188
356
|
const rect = current?.rect;
|
|
189
357
|
const preview = current?.kind === "preview" ? current : null;
|
|
190
358
|
const dimmed = open.value && preview !== null;
|
|
191
|
-
const
|
|
359
|
+
const local = (value) => contextMenuInFrame(value, box);
|
|
360
|
+
const place = rect ? local(rect) : undefined;
|
|
361
|
+
const hole = preview && { ...preview, rect: local(preview.rect), radius: preview.radius / (box?.scaleX ?? 1) };
|
|
362
|
+
const viewport = box ? { width: box.width, height: box.height } : undefined;
|
|
363
|
+
const label = props.ariaLabel ?? name.value;
|
|
364
|
+
const { ariaLabel: _label, ...menuProps } = props;
|
|
365
|
+
const contentProps = Object.fromEntries(Object.entries(menuProps).filter(([, value]) => value !== undefined));
|
|
192
366
|
return [
|
|
193
|
-
// The menu is placed against this invisible box: the pointer, or the element.
|
|
194
|
-
h(BodyTeleport,
|
|
367
|
+
// The menu is placed against this invisible box: the pointer, or the element. It names the menu.
|
|
368
|
+
h(BodyTeleport, { to: container.value }, () => [
|
|
195
369
|
h(MenuTrigger, null, () => h("span", {
|
|
370
|
+
"ref": setAnchor,
|
|
196
371
|
"aria-hidden": "true",
|
|
372
|
+
"aria-label": label || undefined,
|
|
197
373
|
"tabindex": -1,
|
|
198
374
|
"class": s.Anchor,
|
|
199
|
-
"style":
|
|
375
|
+
"style": place ? { left: `${place.x}px`, top: `${place.y}px`, width: `${place.width}px`, height: `${place.height}px` } : undefined,
|
|
200
376
|
})),
|
|
201
377
|
]),
|
|
202
|
-
h(BodyTeleport,
|
|
378
|
+
h(BodyTeleport, { to: container.value }, () => [
|
|
203
379
|
h(TransitionGroup, { class: s.Dimming, ...overlayTiming }, {
|
|
204
380
|
default: () => [
|
|
205
|
-
dimmed
|
|
206
|
-
? h("div", { "key": "dimming", "data-context-menu-dimming": "", "class": s.Overlay, "style": contextMenuHoleMask(
|
|
381
|
+
dimmed && hole
|
|
382
|
+
? h("div", { "key": "dimming", "data-context-menu-dimming": "", "class": s.Overlay, "style": contextMenuHoleMask(hole, viewport) }, [
|
|
207
383
|
h("div", {
|
|
208
384
|
class: s.Preview,
|
|
209
|
-
style: { left: `${
|
|
385
|
+
style: { left: `${hole.rect.x}px`, top: `${hole.rect.y}px`, width: `${hole.rect.width}px`, height: `${hole.rect.height}px`, borderRadius: `${hole.radius}px` },
|
|
210
386
|
}),
|
|
211
387
|
])
|
|
212
388
|
: null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextMenu.js","sourceRoot":"","sources":["../../../../src/components/ContextMenu/ContextMenu.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,eAAe,EACf,CAAC,EACD,MAAM,EACN,eAAe,EACf,SAAS,EACT,OAAO,EACP,UAAU,EACV,QAAQ,GAGT,MAAM,KAAK,CAAA;AACZ,OAAO,CAAC,MAAM,8DAA8D,CAAA;AAC5E,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACtE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EACL,uBAAuB,EACvB,4BAA4B,EAC5B,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,GAEnB,MAAM,aAAa,CAAA;AAUpB,MAAM,YAAY,GAAqC,MAAM,CAAC,aAAa,CAAC,CAAA;AAE5E,MAAM,qBAAqB,GAAG,CAAC,IAAY,EAAE,EAAE;IAC7C,MAAM,OAAO,GAAG,MAA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AAE;oCACzH,CAAC,CAAC,KAAK,EAAE;wCACP,KAAK,EAAE,CAAC,CAAC,OAAO;wCAChB,KAAK,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE;qCAC9K,CAAC;iCACH,CAAC;gCACJ,CAAC,CAAC,IAAI;yBACT;qBACF,CAAC;iBACH,CAAC;gBACF,CAAC,CAAC,WAAW,EAAE,EAAE,GAAG,YAAY,EAAE,GAAG,oBAAoB,CAAC,OAAO,CAAC,EAAE,gBAAgB,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,CAAC;aAC9H,CAAA;QACH,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA;AAKF,kHAAkH;AAClH,MAAM,CAAC,MAAM,kBAAkB,GAAG,2BAA2B,CAAA","sourcesContent":["import {\n cloneVNode,\n defineComponent,\n h,\n inject,\n onBeforeUnmount,\n onMounted,\n provide,\n shallowRef,\n Teleport,\n type InjectionKey,\n type ShallowRef,\n} from \"vue\"\nimport s from \"@plexui/styles/components/ContextMenu/ContextMenu.module.css\"\nimport { firstElementChild, mergeSlotProps } from \"../Tooltip/slot.js\"\nimport { Menu, MenuContent, MenuTrigger, useMenuContext } from \"../Menu/Menu.js\"\nimport { useMenuRootInternals } from \"../Menu/internal.js\"\nimport { TransitionGroup } from \"../Transition/index.js\"\nimport { overlayTiming } from \"../Transition/shared.js\"\nimport {\n CONTEXT_MENU_LONG_PRESS,\n CONTEXT_MENU_LONG_PRESS_SLOP,\n contextMenuHoleMask,\n contextMenuPlacement,\n contextMenuPreview,\n type ContextMenuPresentation,\n} from \"./shared.js\"\n\n// Vue port of packages/ui/src/components/ContextMenu/ContextMenu.tsx. Exports are flat (`ContextMenuTrigger` for\n// `ContextMenu.Trigger`); the items are the Menu ones (`MenuItem`, `MenuSeparator`, ...).\n\ntype ContextMenuContext = {\n presentation: ShallowRef<ContextMenuPresentation | null>\n region: ShallowRef<HTMLElement | null>\n}\n\nconst CONTEXT_MENU: InjectionKey<ContextMenuContext> = Symbol(\"ContextMenu\")\n\nconst useContextMenuContext = (part: string) => {\n const context = inject(CONTEXT_MENU, null)\n if (!context) throw new Error(`${part} must be used within ContextMenu`)\n return context\n}\n\nconst ContextMenuComponent = defineComponent({\n name: \"ContextMenu\",\n inheritAttrs: false,\n emits: {\n /** The menu opened */\n open: () => true,\n /** The menu closed */\n close: () => true,\n },\n setup(_, { emit, slots }) {\n provide(CONTEXT_MENU, { presentation: shallowRef(null), region: shallowRef(null) })\n return () => h(Menu, { onOpen: () => emit(\"open\"), onClose: () => emit(\"close\") }, { default: () => slots.default?.() })\n },\n})\n\n/** Props of `ContextMenu`. */\nexport type ContextMenuProps = InstanceType<typeof ContextMenuComponent>[\"$props\"]\n\n/**\n * A menu of actions for an element, after the iOS 26 kit Context Menu (507:25994): a secondary click opens it at\n * the pointer, a touch and hold opens it beside the element, which stays clear above a dimmed, blurred page, as\n * iOS lifts the preview. The items are the ones of `Menu`.\n */\nexport const ContextMenu = ContextMenuComponent\n\n/**\n * Swallows the mouse events a browser sends after the touch and hold that opened the menu: the compatibility mousedown\n * would focus the element under the finger, and focus leaving the menu closes it (inside a Dialog or a Sheet, whose\n * content takes the press), and the click would activate the element.\n */\nconst suppressNextClick = (doc: Document) => {\n const hold = (event: Event) => {\n event.preventDefault()\n event.stopPropagation()\n }\n const swallow = (event: Event) => {\n hold(event)\n stop()\n }\n const stop = () => {\n doc.removeEventListener(\"mousedown\", hold, true)\n doc.removeEventListener(\"click\", swallow, true)\n doc.removeEventListener(\"pointerdown\", stop, true)\n window.clearTimeout(timer)\n }\n // A browser that sends no click after the hold must not swallow the next tap: a new press ends the wait too.\n const timer = window.setTimeout(stop, 600)\n doc.addEventListener(\"mousedown\", hold, true)\n doc.addEventListener(\"click\", swallow, true)\n doc.addEventListener(\"pointerdown\", stop, true)\n}\n\ntype Press = { id: number; x: number; y: number; timer: number; opened: boolean }\n\nconst ContextMenuTriggerComponent = defineComponent({\n name: \"ContextMenuTrigger\",\n inheritAttrs: false,\n props: {\n /** When `true`, the element keeps the browser's own context menu. */\n disabled: { type: Boolean, default: false },\n },\n setup(props, { attrs, slots }) {\n const menu = useMenuContext()\n const internals = useMenuRootInternals()\n const { presentation, region } = useContextMenuContext(\"ContextMenuTrigger\")\n let press: Press | null = null\n\n const cancel = () => {\n if (press) window.clearTimeout(press.timer)\n press = null\n }\n onBeforeUnmount(cancel)\n\n const open = (next: ContextMenuPresentation) => {\n presentation.value = next\n menu.setOpen(true)\n }\n const openPreview = (element: HTMLElement, x: number) => {\n region.value = element\n open(contextMenuPreview(element, x))\n }\n\n const handlers = {\n onPointerdown: (event: PointerEvent) => {\n if (event.defaultPrevented || props.disabled || event.pointerType !== \"touch\" || !event.isPrimary) return\n cancel()\n const element = event.currentTarget as HTMLElement\n const x = event.clientX\n const timer = window.setTimeout(() => {\n if (!press || press.timer !== timer) return\n press.opened = true\n openPreview(element, x)\n }, CONTEXT_MENU_LONG_PRESS)\n press = { id: event.pointerId, x, y: event.clientY, timer, opened: false }\n },\n onPointermove: (event: PointerEvent) => {\n if (!press || press.id !== event.pointerId || press.opened) return\n if (Math.hypot(event.clientX - press.x, event.clientY - press.y) > CONTEXT_MENU_LONG_PRESS_SLOP) cancel()\n },\n onPointerup: (event: PointerEvent) => {\n if (!press || press.id !== event.pointerId) return\n if (press.opened) suppressNextClick((event.currentTarget as HTMLElement).ownerDocument)\n cancel()\n },\n onPointercancel: (event: PointerEvent) => {\n if (press?.id === event.pointerId) cancel()\n },\n onContextmenu: (event: MouseEvent) => {\n if (event.defaultPrevented || props.disabled) return\n event.preventDefault()\n const element = event.currentTarget as HTMLElement\n region.value = element\n // A touch and hold that the browser reports as a context menu (Android) opens the preview once.\n if (press) {\n if (press.opened) return\n window.clearTimeout(press.timer)\n press.opened = true\n return openPreview(element, press.x)\n }\n if (internals.isUsingKeyboard.current) return open({ kind: \"keyboard\", rect: element.getBoundingClientRect() })\n open({ kind: \"pointer\", rect: { x: event.clientX, y: event.clientY, width: 0, height: 0 } })\n },\n }\n\n return () => {\n const child = firstElementChild(slots.default?.())\n if (!child) return null\n return cloneVNode(mergeSlotProps(child, { ...attrs, class: [s.Trigger, attrs.class], ...handlers }), undefined, true)\n }\n },\n})\n\n/** Props of `ContextMenuTrigger`. */\nexport type ContextMenuTriggerProps = InstanceType<typeof ContextMenuTriggerComponent>[\"$props\"]\n\n/** The element the menu is for (React `ContextMenu.Trigger`): it renders its child, which keeps its own role and focus. */\nexport const ContextMenuTrigger = ContextMenuTriggerComponent\n\n/**\n * Reaches the body once mounted, as Reka's own Teleport does for the menu. Each one is its own component, so the\n * anchor, the dimming and the menu of a context menu land in that order, as React's portals, also when a page has\n * several context menus.\n */\nconst BodyTeleport = defineComponent({\n name: \"ContextMenuTeleport\",\n setup(_, { slots }) {\n const mounted = shallowRef(false)\n onMounted(() => {\n mounted.value = true\n })\n return () => (mounted.value ? h(Teleport, { to: \"body\" }, slots.default?.() ?? []) : null)\n },\n})\n\nconst ContextMenuContentComponent = defineComponent({\n name: \"ContextMenuContent\",\n inheritAttrs: false,\n props: {\n /** Defines the `width` property of the content */\n width: [Number, String],\n /** Defines the `min-width` property of the content, in pixels. */\n minWidth: [Number, String],\n /** Defines the `max-height` property of the content, in pixels. */\n maxHeight: Number,\n /** Rounder list with fully rounded rows. */\n pill: { type: Boolean, default: false },\n },\n setup(props, { slots }) {\n const { open } = useMenuContext()\n const { presentation, region } = useContextMenuContext(\"ContextMenuContent\")\n // Focus goes back to the element only when the keyboard opened the menu; a pointer leaves it where it was.\n const onCloseAutoFocus = (event: Event) => {\n event.preventDefault()\n if (presentation.value?.kind === \"keyboard\") region.value?.focus({ preventScroll: true })\n }\n\n return () => {\n const current = presentation.value\n const rect = current?.rect\n const preview = current?.kind === \"preview\" ? current : null\n const dimmed = open.value && preview !== null\n const contentProps = Object.fromEntries(Object.entries(props).filter(([, value]) => value !== undefined))\n return [\n // The menu is placed against this invisible box: the pointer, or the element.\n h(BodyTeleport, null, () => [\n h(MenuTrigger, null, () => h(\"span\", {\n \"aria-hidden\": \"true\",\n \"tabindex\": -1,\n \"class\": s.Anchor,\n \"style\": rect ? { left: `${rect.x}px`, top: `${rect.y}px`, width: `${rect.width}px`, height: `${rect.height}px` } : undefined,\n })),\n ]),\n h(BodyTeleport, null, () => [\n h(TransitionGroup, { class: s.Dimming, ...overlayTiming }, {\n default: () => [\n dimmed\n ? h(\"div\", { \"key\": \"dimming\", \"data-context-menu-dimming\": \"\", \"class\": s.Overlay, \"style\": contextMenuHoleMask(preview) }, [\n h(\"div\", {\n class: s.Preview,\n style: { left: `${preview.rect.x}px`, top: `${preview.rect.y}px`, width: `${preview.rect.width}px`, height: `${preview.rect.height}px`, borderRadius: `${preview.radius}px` },\n }),\n ])\n : null,\n ],\n }),\n ]),\n h(MenuContent, { ...contentProps, ...contextMenuPlacement(current), onCloseAutoFocus }, { default: () => slots.default?.() }),\n ]\n }\n },\n})\n\n/** Props of `ContextMenuContent`. */\nexport type ContextMenuContentProps = InstanceType<typeof ContextMenuContentComponent>[\"$props\"]\n\n/** The menu (React `ContextMenu.Content`); its items are `MenuItem`, `MenuSeparator` and the other Menu items. */\nexport const ContextMenuContent = ContextMenuContentComponent\n"]}
|
|
1
|
+
{"version":3,"file":"ContextMenu.js","sourceRoot":"","sources":["../../../../src/components/ContextMenu/ContextMenu.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,QAAQ,EACR,eAAe,EACf,CAAC,EACD,MAAM,EACN,eAAe,EACf,SAAS,EACT,OAAO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AK,EAAE;wCACP,KAAK,EAAE,CAAC,CAAC,OAAO;wCAChB,KAAK,EAAE,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE;qCAC/J,CAAC;iCACH,CAAC;gCACJ,CAAC,CAAC,IAAI;yBACT;qBACF,CAAC;iBACH,CAAC;gBACF,CAAC,CAAC,WAAW,EAAE,EAAE,GAAG,YAAY,EAAE,GAAG,oBAAoB,CAAC,OAAO,CAAC,EAAE,gBAAgB,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,CAAC;aAC9H,CAAA;QACH,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA;AAKF,kHAAkH;AAClH,MAAM,CAAC,MAAM,kBAAkB,GAAG,2BAA2B,CAAA","sourcesContent":["import {\n cloneVNode,\n computed,\n defineComponent,\n h,\n inject,\n onBeforeUnmount,\n onMounted,\n provide,\n shallowRef,\n Teleport,\n watch,\n type ComputedRef,\n type InjectionKey,\n type PropType,\n type ShallowRef,\n type VNode,\n} from \"vue\"\nimport s from \"@plexui/styles/components/ContextMenu/ContextMenu.module.css\"\nimport { CONTEXT_MENU_TRIGGER, SORTABLE_HANDLE, SORTABLE_SOURCE, sendContextMenuHold } from \"../../lib/contextMenuHold.js\"\nimport { readMenuBoundaryRect } from \"../../lib/menuSubmenuPlacement.js\"\nimport { isPhoneLayout } from \"../../lib/phoneLayout.js\"\nimport { firstElementChild, mergeSlotProps } from \"../Tooltip/slot.js\"\nimport { Menu, MenuContent, MenuTrigger, useMenuBoundary, useMenuContext, useMenuPhoneLayout } from \"../Menu/Menu.js\"\nimport { useMenuRootInternals } from \"../Menu/internal.js\"\nimport { TransitionGroup } from \"../Transition/index.js\"\nimport { overlayTiming } from \"../Transition/shared.js\"\nimport {\n CONTEXT_MENU_LONG_PRESS,\n CONTEXT_MENU_LONG_PRESS_SLOP,\n contextMenuClipTop,\n contextMenuFrame,\n contextMenuHoleMask,\n contextMenuInFrame,\n contextMenuName,\n contextMenuNaturalHeight,\n contextMenuPlacement,\n contextMenuPreview,\n contextMenuPreviewShift,\n liftContextMenuPreview,\n type ContextMenuFrame,\n type ContextMenuPresentation,\n} from \"./shared.js\"\n\n// Vue port of packages/ui/src/components/ContextMenu/ContextMenu.tsx. Exports are flat (`ContextMenuTrigger` for\n// `ContextMenu.Trigger`); the items are the Menu ones (`MenuItem`, `MenuSeparator`, ...).\n\ntype ContextMenuContext = {\n presentation: ShallowRef<ContextMenuPresentation | null>\n frame: ShallowRef<ContextMenuFrame | null>\n name: ShallowRef<string>\n region: ShallowRef<HTMLElement | null>\n container: ComputedRef<HTMLElement | null>\n forced: ComputedRef<boolean>\n /**\n * Shows the menu for the element as `measure` places it, once a raised preview is back in its place. A menu held\n * open is placed again as the page moves, and its preview moves up without gliding.\n */\n present: (element: HTMLElement, measure: () => ContextMenuPresentation, held?: boolean) => void\n /** Moves the preview up by `shift`, so that the menu stands whole below it */\n lift: (shift: number) => void\n /** Puts a raised preview back in its place, gliding or at once */\n drop: (glide: boolean) => void\n /** Puts a raised preview back at once and forgets its move, for content that goes away while the element stays */\n release: () => void\n}\n\nconst CONTEXT_MENU: InjectionKey<ContextMenuContext> = Symbol(\"ContextMenu\")\n\nconst useContextMenuContext = (part: string) => {\n const context = inject(CONTEXT_MENU, null)\n if (!context) throw new Error(`${part} must be used within ContextMenu`)\n return context\n}\n\nconst ContextMenuComponent = defineComponent({\n name: \"ContextMenu\",\n inheritAttrs: false,\n props: {\n /**\n * Holds the menu open (`true`) or closed (`false`). Held open without a press, it stands at the element: as the\n * touch-and-hold preview on a phone, under the element elsewhere, and it follows the element as the page scrolls.\n */\n forceOpen: { type: Boolean, default: undefined },\n },\n emits: {\n /** The menu opened */\n open: () => true,\n /** The menu closed */\n close: () => true,\n },\n setup(props, { emit, slots }) {\n const presentation = shallowRef<ContextMenuPresentation | null>(null)\n const frame = shallowRef<ContextMenuFrame | null>(null)\n const name = shallowRef(\"\")\n const region = shallowRef<HTMLElement | null>(null)\n // Inside a PhoneLayout the anchor and the dimming lie in its box, as the menu does\n const { container } = useMenuPhoneLayout()\n let restore: ((glide: boolean) => void) | null = null\n let held = false\n\n // Puts the element back; after a glide back the restore stays, so that a press or a close that follows stops it\n const drop = (glide: boolean) => {\n const current = restore\n current?.(glide)\n restore = glide ? current : null\n }\n // The content going away while the element stays: the element back in place, and measured anew when it returns\n const release = () => {\n drop(false)\n const preview = presentation.value\n if (preview?.kind !== \"preview\" || preview.shift === undefined) return\n presentation.value = { ...preview, rect: { ...preview.rect, y: preview.rect.y + preview.shift }, shift: undefined }\n }\n const present = (element: HTMLElement, measure: () => ContextMenuPresentation, still = false) => {\n drop(false)\n held = still\n region.value = element\n presentation.value = measure()\n frame.value = contextMenuFrame(container.value)\n name.value = contextMenuName(element)\n }\n const lift = (shift: number) => {\n const element = region.value\n drop(false)\n if (element && shift > 0) restore = liftContextMenuPreview(element, shift, !held)\n const preview = presentation.value\n if (preview?.kind !== \"preview\") return\n presentation.value = { ...preview, rect: { ...preview.rect, y: preview.rect.y - shift }, shift }\n }\n onBeforeUnmount(() => drop(false))\n\n provide(CONTEXT_MENU, {\n presentation,\n frame,\n name,\n region,\n container,\n forced: computed(() => props.forceOpen === true),\n present,\n lift,\n drop,\n release,\n })\n return () => h(Menu, { forceOpen: props.forceOpen, onOpen: () => emit(\"open\"), onClose: () => emit(\"close\") }, { default: () => slots.default?.() })\n },\n})\n\n/** Props of `ContextMenu`. */\nexport type ContextMenuProps = InstanceType<typeof ContextMenuComponent>[\"$props\"]\n\n/**\n * A menu of actions for an element, after the iOS 26 kit Context Menu (507:25994): a secondary click opens it at\n * the pointer, a touch and hold opens it beside the element, which stays clear above a dimmed, blurred page, as\n * iOS lifts the preview. The items are the ones of `Menu`.\n */\nexport const ContextMenu = ContextMenuComponent\n\n/**\n * Swallows the mouse events a browser sends after the touch and hold that opened the menu: the compatibility mousedown\n * would focus the element under the finger, and focus leaving the menu closes it (inside a Dialog or a Sheet, whose\n * content takes the press), and the click would activate the element.\n */\nconst suppressNextClick = (doc: Document) => {\n const hold = (event: Event) => {\n event.preventDefault()\n event.stopPropagation()\n }\n const swallow = (event: Event) => {\n hold(event)\n stop()\n }\n const stop = () => {\n doc.removeEventListener(\"mousedown\", hold, true)\n doc.removeEventListener(\"click\", swallow, true)\n doc.removeEventListener(\"pointerdown\", stop, true)\n window.clearTimeout(timer)\n }\n // A browser that sends no click after the hold must not swallow the next tap: a new press ends the wait too.\n const timer = window.setTimeout(stop, 600)\n doc.addEventListener(\"mousedown\", hold, true)\n doc.addEventListener(\"click\", swallow, true)\n doc.addEventListener(\"pointerdown\", stop, true)\n}\n\n/** A menu held open without a press: the touch-and-hold preview on a phone, under the element elsewhere. */\nconst forcedPresentation = (element: HTMLElement): ContextMenuPresentation => {\n if (!isPhoneLayout(element)) return { kind: \"keyboard\", rect: element.getBoundingClientRect() }\n const box = element.getBoundingClientRect()\n return contextMenuPreview(element, box.left + box.width / 2)\n}\n\ntype Press = { id: number; x: number; y: number; timer: number; opened: boolean }\n\nconst ContextMenuTriggerComponent = defineComponent({\n name: \"ContextMenuTrigger\",\n inheritAttrs: false,\n props: {\n /** When `true`, the element keeps the browser's own context menu. */\n disabled: { type: Boolean, default: false },\n },\n setup(props, { attrs, slots }) {\n const menu = useMenuContext()\n const internals = useMenuRootInternals()\n const { present, drop, forced } = useContextMenuContext(\"ContextMenuTrigger\")\n const element = shallowRef<HTMLElement | null>(null)\n let press: Press | null = null\n\n const cancel = () => {\n if (press) window.clearTimeout(press.timer)\n press = null\n }\n onBeforeUnmount(cancel)\n\n // A menu held open stands at the element, and follows it as the page around it scrolls or the window changes\n watch([forced, element], ([held, node], _, onCleanup) => {\n if (!held || !node) return\n const doc = node.ownerDocument\n const view = doc.defaultView\n const place = () => present(node, () => forcedPresentation(node), true)\n place()\n let frame = 0\n const follow = (event: Event) => {\n if (event.target instanceof Node && event.target !== doc && !event.target.contains(node)) return\n view?.cancelAnimationFrame(frame)\n frame = view?.requestAnimationFrame(place) ?? 0\n }\n view?.addEventListener(\"resize\", follow)\n doc.addEventListener(\"scroll\", follow, { capture: true, passive: true })\n onCleanup(() => {\n view?.cancelAnimationFrame(frame)\n view?.removeEventListener(\"resize\", follow)\n doc.removeEventListener(\"scroll\", follow, { capture: true })\n })\n }, { immediate: true, flush: \"post\" })\n\n const open = (node: HTMLElement, measure: () => ContextMenuPresentation) => {\n present(node, measure)\n menu.setOpen(true)\n }\n const openPreview = (node: HTMLElement, x: number) => open(node, () => contextMenuPreview(node, x))\n // A touch and hold opens the preview once, by the timer or by the browser's own context menu (Android)\n const openHeld = (node: HTMLElement, current: Press) => {\n // A Sortable list around the element already turned this hold into a drag\n if (node.ownerDocument.querySelector(SORTABLE_SOURCE)) return cancel()\n window.clearTimeout(current.timer)\n current.opened = true\n openPreview(node, current.x)\n // The same hold drags the element where it is a Sortable item: moving on, the finger closes the menu\n sendContextMenuHold(node, {\n pointerId: current.id,\n close: () => {\n drop(false)\n menu.setOpen(false)\n },\n })\n }\n\n const handlers = {\n onPointerdown: (event: PointerEvent) => {\n if (event.defaultPrevented || props.disabled || event.pointerType !== \"touch\" || !event.isPrimary) return\n // The grip of a Sortable item drags at once\n if (event.target instanceof Element && event.target.closest(SORTABLE_HANDLE)) return\n cancel()\n const node = event.currentTarget as HTMLElement\n const x = event.clientX\n const timer = window.setTimeout(() => {\n if (press && press.timer === timer) openHeld(node, press)\n }, CONTEXT_MENU_LONG_PRESS)\n press = { id: event.pointerId, x, y: event.clientY, timer, opened: false }\n },\n onPointermove: (event: PointerEvent) => {\n if (!press || press.id !== event.pointerId || press.opened) return\n if (Math.hypot(event.clientX - press.x, event.clientY - press.y) > CONTEXT_MENU_LONG_PRESS_SLOP) cancel()\n },\n onPointerup: (event: PointerEvent) => {\n if (!press || press.id !== event.pointerId) return\n if (press.opened) suppressNextClick((event.currentTarget as HTMLElement).ownerDocument)\n cancel()\n },\n onPointercancel: (event: PointerEvent) => {\n if (press?.id === event.pointerId) cancel()\n },\n onContextmenu: (event: MouseEvent) => {\n if (event.defaultPrevented || props.disabled) return\n event.preventDefault()\n const node = event.currentTarget as HTMLElement\n // A touch and hold that the browser reports as a context menu (Android) opens the preview once.\n if (press) {\n if (!press.opened) openHeld(node, press)\n return\n }\n if (internals.isUsingKeyboard.current) return open(node, () => ({ kind: \"keyboard\", rect: node.getBoundingClientRect() }))\n const { clientX, clientY } = event\n open(node, () => ({ kind: \"pointer\", rect: { x: clientX, y: clientY, width: 0, height: 0 } }))\n },\n }\n // The element itself, also when the child is a component\n const setElement = (node: unknown) => {\n const found = node instanceof Element ? node : (node as { $el?: unknown } | null)?.$el\n element.value = found instanceof HTMLElement ? found : null\n }\n\n return () => {\n const child = firstElementChild(slots.default?.())\n if (!child) return null\n const own = { [CONTEXT_MENU_TRIGGER]: props.disabled ? undefined : \"\" }\n // A component that changes its own root renders again without this trigger: its vnode hook follows the new root\n return cloneVNode(\n mergeSlotProps(child, { ...attrs, ...own, class: [s.Trigger, attrs.class], ...handlers }),\n { ref: setElement, onVnodeUpdated: (vnode: VNode) => setElement(vnode.el) },\n true,\n )\n }\n },\n})\n\n/** Props of `ContextMenuTrigger`. */\nexport type ContextMenuTriggerProps = InstanceType<typeof ContextMenuTriggerComponent>[\"$props\"]\n\n/** The element the menu is for (React `ContextMenu.Trigger`): it renders its child, which keeps its own role and focus. */\nexport const ContextMenuTrigger = ContextMenuTriggerComponent\n\n/**\n * Reaches the body, or the PhoneLayout box, once mounted, as Reka's own Teleport does for the menu. Each one is its own\n * component, so the anchor, the dimming and the menu of a context menu land in that order, as React's portals, also\n * when a page has several context menus.\n */\nconst BodyTeleport = defineComponent({\n name: \"ContextMenuTeleport\",\n props: {\n to: { type: Object as PropType<HTMLElement | null>, default: null },\n },\n setup(props, { slots }) {\n const mounted = shallowRef(false)\n onMounted(() => {\n mounted.value = true\n })\n return () => (mounted.value ? h(Teleport, { to: props.to ?? \"body\" }, slots.default?.() ?? []) : null)\n },\n})\n\nconst ContextMenuContentComponent = defineComponent({\n name: \"ContextMenuContent\",\n inheritAttrs: false,\n props: {\n /** Defines the `width` property of the content */\n width: [Number, String],\n /** Defines the `min-width` property of the content, in pixels. */\n minWidth: [Number, String],\n /** Defines the `max-height` property of the content, in pixels. */\n maxHeight: Number,\n /** Rounder list with fully rounded rows. */\n pill: { type: Boolean, default: false },\n /** Names the menu for assistive technology. Without it the menu takes the name of its element. */\n ariaLabel: String,\n },\n setup(props, { slots }) {\n const { open } = useMenuContext()\n const { presentation, frame, name, region, container, lift, drop, release } = useContextMenuContext(\"ContextMenuContent\")\n const boundary = useMenuBoundary(() => open.value)\n let anchor: HTMLElement | null = null\n const setAnchor = (node: unknown) => {\n anchor = node instanceof HTMLElement ? node : null\n }\n // Focus goes back to the element only when the keyboard opened the menu; a pointer leaves it where it was.\n const onCloseAutoFocus = (event: Event) => {\n event.preventDefault()\n if (presentation.value?.kind === \"keyboard\") region.value?.focus({ preventScroll: true })\n }\n\n // The preview moves up so that the menu stands whole below it, measured as the menu first lays out, before it shows\n const pending = computed(() => {\n const current = presentation.value\n return open.value && current?.kind === \"preview\" && current.shift === undefined\n })\n let frameId = 0\n const measure = () => {\n const current = presentation.value\n const element = region.value\n if (!open.value || current?.kind !== \"preview\" || current.shift !== undefined || !element) return\n const content = anchor?.ownerDocument.getElementById(anchor.getAttribute(\"aria-controls\") ?? \"\")\n // The menu of a PhoneLayout mounts a frame later, with the box it portals into, and content mounted again while\n // the menu is open finds its anchor (in a portal) a frame later too\n if (!content) {\n frameId = requestAnimationFrame(measure)\n return\n }\n const bounds = readMenuBoundaryRect(element.ownerDocument, boundary.value)\n // On the screen, as the room is: a PhoneLayout drawn smaller draws the menu smaller too\n const height = Math.min(contextMenuNaturalHeight(content), props.maxHeight ?? Infinity) * (frame.value?.scaleY ?? 1)\n // A room not known yet (no layout) moves nothing\n const known = bounds && bounds.bottom > bounds.top\n lift(known ? contextMenuPreviewShift(current.rect, height, bounds, contextMenuClipTop(element), frame.value?.scaleY ?? 1) : 0)\n }\n watch(pending, (now) => {\n cancelAnimationFrame(frameId)\n if (now) measure()\n }, { flush: \"post\" })\n // Content mounted while a preview waits for its move (mounted again, the menu held open) measures it at once\n onMounted(() => {\n if (pending.value) measure()\n })\n watch(open, (now) => {\n if (!now) drop(true)\n }, { flush: \"post\" })\n onBeforeUnmount(() => {\n cancelAnimationFrame(frameId)\n // The content going away while the element stays puts the element back\n release()\n })\n\n return () => {\n const current = presentation.value\n const box = frame.value\n const rect = current?.rect\n const preview = current?.kind === \"preview\" ? current : null\n const dimmed = open.value && preview !== null\n const local = (value: NonNullable<typeof rect>) => contextMenuInFrame(value, box)\n const place = rect ? local(rect) : undefined\n const hole = preview && { ...preview, rect: local(preview.rect), radius: preview.radius / (box?.scaleX ?? 1) }\n const viewport = box ? { width: box.width, height: box.height } : undefined\n const label = props.ariaLabel ?? name.value\n const { ariaLabel: _label, ...menuProps } = props\n const contentProps = Object.fromEntries(Object.entries(menuProps).filter(([, value]) => value !== undefined))\n return [\n // The menu is placed against this invisible box: the pointer, or the element. It names the menu.\n h(BodyTeleport, { to: container.value }, () => [\n h(MenuTrigger, null, () => h(\"span\", {\n \"ref\": setAnchor,\n \"aria-hidden\": \"true\",\n \"aria-label\": label || undefined,\n \"tabindex\": -1,\n \"class\": s.Anchor,\n \"style\": place ? { left: `${place.x}px`, top: `${place.y}px`, width: `${place.width}px`, height: `${place.height}px` } : undefined,\n })),\n ]),\n h(BodyTeleport, { to: container.value }, () => [\n h(TransitionGroup, { class: s.Dimming, ...overlayTiming }, {\n default: () => [\n dimmed && hole\n ? h(\"div\", { \"key\": \"dimming\", \"data-context-menu-dimming\": \"\", \"class\": s.Overlay, \"style\": contextMenuHoleMask(hole, viewport) }, [\n h(\"div\", {\n class: s.Preview,\n style: { left: `${hole.rect.x}px`, top: `${hole.rect.y}px`, width: `${hole.rect.width}px`, height: `${hole.rect.height}px`, borderRadius: `${hole.radius}px` },\n }),\n ])\n : null,\n ],\n }),\n ]),\n h(MenuContent, { ...contentProps, ...contextMenuPlacement(current), onCloseAutoFocus }, { default: () => slots.default?.() }),\n ]\n }\n },\n})\n\n/** Props of `ContextMenuContent`. */\nexport type ContextMenuContentProps = InstanceType<typeof ContextMenuContentComponent>[\"$props\"]\n\n/** The menu (React `ContextMenu.Content`); its items are `MenuItem`, `MenuSeparator` and the other Menu items. */\nexport const ContextMenuContent = ContextMenuContentComponent\n"]}
|