@plexui/vue 0.12.0 → 0.13.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 +49 -15
- package/dist/es/components/Dialog/Dialog.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 +3 -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,8 +1,5 @@
|
|
|
1
1
|
// Shared with packages/ui/src/components/ContextMenu/shared.ts: keep the two copies the same.
|
|
2
|
-
|
|
3
|
-
export const CONTEXT_MENU_LONG_PRESS = 500;
|
|
4
|
-
/** A touch that moves farther than this before then scrolls or drags instead. */
|
|
5
|
-
export const CONTEXT_MENU_LONG_PRESS_SLOP = 10;
|
|
2
|
+
export { CONTEXT_MENU_LONG_PRESS, CONTEXT_MENU_LONG_PRESS_SLOP } from "../../lib/contextMenuHold.js";
|
|
6
3
|
/** The kit's gap between the preview and the menu: iOS 27 Context Menu 125:58750, Alignment=Vertical, the menu at
|
|
7
4
|
* 176.5 under a content area that ends at 160.5 (the iOS 26 kit had 18). */
|
|
8
5
|
export const CONTEXT_MENU_PREVIEW_GAP = 16;
|
|
@@ -40,8 +37,10 @@ export function contextMenuPlacement(presentation) {
|
|
|
40
37
|
}
|
|
41
38
|
const round = (value) => Math.round(value * 100) / 100;
|
|
42
39
|
/**
|
|
43
|
-
* The dimming covers the page but the element:
|
|
44
|
-
* `--context-menu-hole
|
|
40
|
+
* The dimming covers the page but the element: the element's rounded box is cut out of it, so the element stays
|
|
41
|
+
* clear above the dimmed, blurred page. `--context-menu-hole` draws the cut (an SVG mask), and
|
|
42
|
+
* `--context-menu-hole-clip` the same shape as a clip path, through which a press reaches the element: a mask leaves
|
|
43
|
+
* the dimming pressable, a clip path does not.
|
|
45
44
|
*/
|
|
46
45
|
export function contextMenuHoleMask(preview, viewport) {
|
|
47
46
|
const width = round(viewport?.width ?? window.innerWidth);
|
|
@@ -52,7 +51,182 @@ export function contextMenuHoleMask(preview, viewport) {
|
|
|
52
51
|
const h = round(preview.rect.height);
|
|
53
52
|
const r = round(preview.radius);
|
|
54
53
|
const hole = `M${x + r} ${y}H${round(x + w - r)}A${r} ${r} 0 0 1 ${x + w} ${round(y + r)}V${round(y + h - r)}A${r} ${r} 0 0 1 ${round(x + w - r)} ${round(y + h)}H${round(x + r)}A${r} ${r} 0 0 1 ${x} ${round(y + h - r)}V${round(y + r)}A${r} ${r} 0 0 1 ${round(x + r)} ${y}Z`;
|
|
55
|
-
const
|
|
56
|
-
|
|
54
|
+
const path = `M0 0H${width}V${height}H0Z${hole}`;
|
|
55
|
+
const svg = `<svg xmlns='http://www.w3.org/2000/svg' width='${width}' height='${height}' viewBox='0 0 ${width} ${height}'><path fill-rule='evenodd' d='${path}'/></svg>`;
|
|
56
|
+
return {
|
|
57
|
+
"--context-menu-hole": `url("data:image/svg+xml,${encodeURIComponent(svg)}")`,
|
|
58
|
+
"--context-menu-hole-clip": `path(evenodd, "${path}")`,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* How far the preview moves up so that a menu `height` tall stands whole below it, as iOS moves a lifted preview:
|
|
63
|
+
* within `room` (the top and bottom the menu keeps to), and no higher than `ceiling`, the top of a box that clips
|
|
64
|
+
* the element. Nothing when the menu fits. When no move lets it stand whole below, nothing either if it stands whole
|
|
65
|
+
* above the element, where it then opens; else as far as the room above lets it, and the menu scrolls. All on the
|
|
66
|
+
* screen: `scale` is the one a PhoneLayout is drawn at, which the gap takes too.
|
|
67
|
+
*/
|
|
68
|
+
export function contextMenuPreviewShift(rect, height, room, ceiling = -Infinity, scale = 1) {
|
|
69
|
+
const gap = CONTEXT_MENU_PREVIEW_GAP * scale;
|
|
70
|
+
const missing = rect.y + rect.height + gap + height - room.bottom;
|
|
71
|
+
if (missing <= 0)
|
|
72
|
+
return 0;
|
|
73
|
+
const allowed = Math.max(0, rect.y - Math.max(room.top, ceiling));
|
|
74
|
+
if (missing <= allowed)
|
|
75
|
+
return round(missing);
|
|
76
|
+
return rect.y - gap - height >= room.top ? 0 : round(allowed);
|
|
77
|
+
}
|
|
78
|
+
/** The top of the nearest box that clips the element: moved above it, the element would not be seen. */
|
|
79
|
+
export function contextMenuClipTop(element) {
|
|
80
|
+
const view = element.ownerDocument.defaultView;
|
|
81
|
+
let top = -Infinity;
|
|
82
|
+
for (let node = element.parentElement; node && node !== element.ownerDocument.documentElement; node = node.parentElement) {
|
|
83
|
+
const style = view?.getComputedStyle(node);
|
|
84
|
+
if (style && (style.overflowX !== "visible" || style.overflowY !== "visible"))
|
|
85
|
+
top = Math.max(top, node.getBoundingClientRect().top + node.clientTop);
|
|
86
|
+
}
|
|
87
|
+
return top;
|
|
88
|
+
}
|
|
89
|
+
/** A menu's height without the limit of the room it is given: the panel, and what its items scroll out of sight. */
|
|
90
|
+
export function contextMenuNaturalHeight(content) {
|
|
91
|
+
const hidden = (element) => (element instanceof HTMLElement ? Math.max(0, element.scrollHeight - element.clientHeight) : 0);
|
|
92
|
+
return [...content.children].reduce((height, child) => height + hidden(child), content.offsetHeight + hidden(content));
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The name of the element a menu is for, which names the menu, in the order of accessible names: the text it is
|
|
96
|
+
* labelled by, its own label, its text, or the text of a picture it is or shows.
|
|
97
|
+
*/
|
|
98
|
+
export function contextMenuName(element) {
|
|
99
|
+
const text = (value) => (value ?? "").replace(/\s+/g, " ").trim();
|
|
100
|
+
const doc = element.ownerDocument;
|
|
101
|
+
const ids = text(element.getAttribute("aria-labelledby")).split(" ").filter(Boolean);
|
|
102
|
+
const labelled = text(ids.map((id) => doc.getElementById(id)?.textContent ?? "").join(" "));
|
|
103
|
+
if (labelled)
|
|
104
|
+
return labelled;
|
|
105
|
+
const label = text(element.getAttribute("aria-label"));
|
|
106
|
+
if (label)
|
|
107
|
+
return label;
|
|
108
|
+
const picture = element.matches("img[alt]") ? element : element.querySelector("img[alt]");
|
|
109
|
+
return text(element.textContent) || text(picture?.getAttribute("alt"));
|
|
110
|
+
}
|
|
111
|
+
export function contextMenuFrame(box) {
|
|
112
|
+
if (!box)
|
|
113
|
+
return null;
|
|
114
|
+
const rect = box.getBoundingClientRect();
|
|
115
|
+
const scaleX = box.offsetWidth > 0 ? rect.width / box.offsetWidth : 1;
|
|
116
|
+
const scaleY = box.offsetHeight > 0 ? rect.height / box.offsetHeight : 1;
|
|
117
|
+
return {
|
|
118
|
+
left: rect.left + box.clientLeft * scaleX,
|
|
119
|
+
top: rect.top + box.clientTop * scaleY,
|
|
120
|
+
scaleX,
|
|
121
|
+
scaleY,
|
|
122
|
+
width: box.clientWidth,
|
|
123
|
+
height: box.clientHeight,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/** A rectangle on the screen in the coordinates of the frame, or as it is for the window. */
|
|
127
|
+
export const contextMenuInFrame = (rect, frame) => frame
|
|
128
|
+
? {
|
|
129
|
+
x: round((rect.x - frame.left) / frame.scaleX),
|
|
130
|
+
y: round((rect.y - frame.top) / frame.scaleY),
|
|
131
|
+
width: round(rect.width / frame.scaleX),
|
|
132
|
+
height: round(rect.height / frame.scaleY),
|
|
133
|
+
}
|
|
134
|
+
: rect;
|
|
135
|
+
/** The duration and easing of a motion token (`--motion-enter` with `--cubic-enter`), 0 where motion is reduced. */
|
|
136
|
+
const motion = (element, name) => {
|
|
137
|
+
const style = getComputedStyle(element);
|
|
138
|
+
const value = style.getPropertyValue(`--motion-${name}`).trim();
|
|
139
|
+
const number = Number.parseFloat(value);
|
|
140
|
+
const duration = !Number.isFinite(number) ? 0 : value.endsWith("ms") ? number : value.endsWith("s") ? number * 1000 : 0;
|
|
141
|
+
return { duration, easing: style.getPropertyValue(`--cubic-${name}`).trim() || "ease" };
|
|
142
|
+
};
|
|
143
|
+
/** The parts of a computed `translate` (`none`, or x, y and z lengths, a `calc()` among them). */
|
|
144
|
+
const translateParts = (value) => {
|
|
145
|
+
const parts = [];
|
|
146
|
+
let depth = 0;
|
|
147
|
+
let part = "";
|
|
148
|
+
for (const char of value.trim()) {
|
|
149
|
+
if (char === "(")
|
|
150
|
+
depth += 1;
|
|
151
|
+
if (char === ")")
|
|
152
|
+
depth -= 1;
|
|
153
|
+
if (char === " " && depth === 0) {
|
|
154
|
+
if (part)
|
|
155
|
+
parts.push(part);
|
|
156
|
+
part = "";
|
|
157
|
+
}
|
|
158
|
+
else
|
|
159
|
+
part += char;
|
|
160
|
+
}
|
|
161
|
+
if (part)
|
|
162
|
+
parts.push(part);
|
|
163
|
+
return parts;
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* How large the element's pixels are drawn on the screen: the scale of the nearest box around it with a height, such
|
|
167
|
+
* as a PhoneLayout drawn smaller. Read from its parents, which a transition or animation of the element's own does not
|
|
168
|
+
* move.
|
|
169
|
+
*/
|
|
170
|
+
const screenScale = (element) => {
|
|
171
|
+
for (let node = element.parentElement; node; node = node.parentElement) {
|
|
172
|
+
if (node.offsetHeight > 0) {
|
|
173
|
+
const scale = node.getBoundingClientRect().height / node.offsetHeight;
|
|
174
|
+
return scale > 0 && Number.isFinite(scale) ? scale : 1;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return 1;
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Changes the element's `translate` without a transition of its own (`transition: all` or one on `translate`): the
|
|
181
|
+
* move has its own glide, and a drag measures the element right after it is put back. The transition the change
|
|
182
|
+
* starts is cancelled, which shows the new value at once and leaves the element's own style as it was.
|
|
183
|
+
*/
|
|
184
|
+
const withoutTransition = (element, change) => {
|
|
185
|
+
change();
|
|
186
|
+
// Reading the style starts the element's transition, if it has one
|
|
187
|
+
void getComputedStyle(element).getPropertyValue("translate");
|
|
188
|
+
for (const animation of element.getAnimations?.() ?? []) {
|
|
189
|
+
if ("transitionProperty" in animation && animation.transitionProperty === "translate")
|
|
190
|
+
animation.cancel();
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* Moves the element up by `shift` pixels of the screen while its preview stands, gliding there as the dimming comes in
|
|
195
|
+
* (or at once, for a menu held open that is placed again), and returns how to put it back: gliding as the dimming
|
|
196
|
+
* goes, or at once for a drag that measures where the element stands; called again at once, it stops that glide. An
|
|
197
|
+
* animation, not a transition, so the element's own styles stay; the move adds to a `translate` the element has.
|
|
198
|
+
*/
|
|
199
|
+
export function liftContextMenuPreview(element, shift, smooth = true) {
|
|
200
|
+
const previous = element.style.getPropertyValue("translate");
|
|
201
|
+
const computed = getComputedStyle(element).getPropertyValue("translate").trim();
|
|
202
|
+
const own = computed && computed !== "none" ? translateParts(computed) : [];
|
|
203
|
+
const rest = own.length > 0 ? computed : "none";
|
|
204
|
+
const by = round(shift / screenScale(element));
|
|
205
|
+
const raised = own.length > 0 ? [own[0], `calc(${own[1] ?? "0px"} - ${by}px)`, ...own.slice(2)].join(" ") : `0 ${-by}px`;
|
|
206
|
+
withoutTransition(element, () => element.style.setProperty("translate", raised));
|
|
207
|
+
const glide = (from, to, name) => {
|
|
208
|
+
const { duration, easing } = motion(element, name);
|
|
209
|
+
return duration > 0 && typeof element.animate === "function"
|
|
210
|
+
? element.animate([{ translate: from }, { translate: to }], { duration, easing })
|
|
211
|
+
: undefined;
|
|
212
|
+
};
|
|
213
|
+
let animation = smooth ? glide(rest, raised, "enter") : undefined;
|
|
214
|
+
let lifted = true;
|
|
215
|
+
return (back) => {
|
|
216
|
+
if (!lifted) {
|
|
217
|
+
if (!back)
|
|
218
|
+
animation?.cancel();
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
lifted = false;
|
|
222
|
+
animation?.cancel();
|
|
223
|
+
withoutTransition(element, () => {
|
|
224
|
+
if (previous)
|
|
225
|
+
element.style.setProperty("translate", previous);
|
|
226
|
+
else
|
|
227
|
+
element.style.removeProperty("translate");
|
|
228
|
+
});
|
|
229
|
+
animation = back ? glide(raised, rest, "exit") : undefined;
|
|
230
|
+
};
|
|
57
231
|
}
|
|
58
232
|
//# sourceMappingURL=shared.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../../src/components/ContextMenu/shared.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,4EAA4E;AAC5E,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAA;AAC1C,iFAAiF;AACjF,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,CAAA;AAC9C;4EAC4E;AAC5E,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,CAAA;AAC1C,qGAAqG;AACrG,MAAM,cAAc,GAAG,EAAE,CAAA;AAUzB,MAAM,EAAE,GAAG,CAAC,KAAa,EAAE,IAAY,EAAE,EAAE;IACzC,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;IACvC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,CAAC,CAAA;IACtC,OAAO,KAA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OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACpC,MAAM,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAA;IACjR,MAAM,GAAG,GAAG,kDAAkD,KAAK,aAAa,MAAM,kBAAkB,KAAK,IAAI,MAAM,uCAAuC,KAAK,IAAI,MAAM,MAAM,IAAI,WAAW,CAAA;IAClM,OAAO,EAAE,qBAAqB,EAAE,2BAA2B,kBAAkB,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;AAC1F,CAAC","sourcesContent":["// Shared with packages/ui/src/components/ContextMenu/shared.ts: keep the two copies the same.\n/** A touch held this long opens the menu, as a UIKit long press (0.5 s). */\nexport const CONTEXT_MENU_LONG_PRESS = 500\n/** A touch that moves farther than this before then scrolls or drags instead. */\nexport const CONTEXT_MENU_LONG_PRESS_SLOP = 10\n/** The kit's gap between the preview and the menu: iOS 27 Context Menu 125:58750, Alignment=Vertical, the menu at\n * 176.5 under a content area that ends at 160.5 (the iOS 26 kit had 18). */\nexport const CONTEXT_MENU_PREVIEW_GAP = 16\n/** The kit's preview corner (Content Area, radius 30), for an element without corners of its own. */\nconst PREVIEW_RADIUS = 30\n\ntype Rect = { x: number; y: number; width: number; height: number }\n\n/** Where the menu opens: at the pointer, under the element for the keyboard, or beside a touch-and-hold preview. */\nexport type ContextMenuPresentation =\n | { kind: \"pointer\"; rect: Rect }\n | { kind: \"keyboard\"; rect: Rect }\n | { kind: \"preview\"; rect: Rect; radius: number; align: \"start\" | \"end\" }\n\nconst px = (value: string, base: number) => {\n const number = Number.parseFloat(value)\n if (!Number.isFinite(number)) return 0\n return value.trim().endsWith(\"%\") ? (number / 100) * base : number\n}\n\n/**\n * The preview of a touch and hold: the element's box and corner (its own, or `--context-menu-preview-radius`), and\n * the edge the menu keeps to, the one on the side of the touch, as the kit's Side=Leading and Side=Trailing.\n */\nexport function contextMenuPreview(element: HTMLElement, touchX: number): ContextMenuPresentation {\n const box = element.getBoundingClientRect()\n const rect = { x: box.left, y: box.top, width: box.width, height: box.height }\n const style = getComputedStyle(element)\n const short = Math.min(rect.width, rect.height)\n const own = px(style.borderTopLeftRadius, short)\n const fallback = px(style.getPropertyValue(\"--context-menu-preview-radius\"), short) || PREVIEW_RADIUS\n const radius = Math.min(own > 0 ? own : fallback, short / 2)\n const width = element.ownerDocument.defaultView?.innerWidth ?? rect.x + rect.width\n return { kind: \"preview\", rect, radius, align: touchX < width / 2 ? \"start\" : \"end\" }\n}\n\n/** The menu's side, alignment and offsets for a presentation. */\nexport function contextMenuPlacement(presentation: ContextMenuPresentation | null) {\n if (presentation?.kind === \"preview\")\n return { side: \"bottom\" as const, align: presentation.align, sideOffset: CONTEXT_MENU_PREVIEW_GAP, alignOffset: 0 }\n if (presentation?.kind === \"keyboard\") return { side: \"bottom\" as const, align: \"start\" as const, sideOffset: 5, alignOffset: 0 }\n // As a desktop context menu, its corner at the pointer.\n return { side: \"bottom\" as const, align: \"start\" as const, sideOffset: 2, alignOffset: 0 }\n}\n\nconst round = (value: number) => Math.round(value * 100) / 100\n\n/**\n * The dimming covers the page but the element: an SVG mask with the element's rounded box cut out, written to\n * `--context-menu-hole`, so the element stays clear above the dimmed, blurred page.\n */\nexport function contextMenuHoleMask(preview: Extract<ContextMenuPresentation, { kind: \"preview\" }>, viewport?: { width: number; height: number }) {\n const width = round(viewport?.width ?? window.innerWidth)\n const height = round(viewport?.height ?? window.innerHeight)\n const x = round(preview.rect.x)\n const y = round(preview.rect.y)\n const w = round(preview.rect.width)\n const h = round(preview.rect.height)\n const r = round(preview.radius)\n const hole = `M${x + r} ${y}H${round(x + w - r)}A${r} ${r} 0 0 1 ${x + w} ${round(y + r)}V${round(y + h - r)}A${r} ${r} 0 0 1 ${round(x + w - r)} ${round(y + h)}H${round(x + r)}A${r} ${r} 0 0 1 ${x} ${round(y + h - r)}V${round(y + r)}A${r} ${r} 0 0 1 ${round(x + r)} ${y}Z`\n const svg = `<svg xmlns='http://www.w3.org/2000/svg' width='${width}' height='${height}' viewBox='0 0 ${width} ${height}'><path fill-rule='evenodd' d='M0 0H${width}V${height}H0Z${hole}'/></svg>`\n return { \"--context-menu-hole\": `url(\"data:image/svg+xml,${encodeURIComponent(svg)}\")` }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../../src/components/ContextMenu/shared.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,OAAO,EAAE,uBAAuB,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAA;AAEpG;4EAC4E;AAC5E,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,CAAA;AAC1C,qGAAqG;AACrG,MAAM,cAAc,GAAG,EAAE,CAAA;AAazB,MAAM,EAAE,GAAG,CAAC,KAAa,EAAE,IAAY,EAAE,EAAE;IACzC,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;IACvC,IAAI,CAAC,MAAM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AE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAC5D,CAAC,CAAA;AACH,CAAC","sourcesContent":["// Shared with packages/ui/src/components/ContextMenu/shared.ts: keep the two copies the same.\nexport { CONTEXT_MENU_LONG_PRESS, CONTEXT_MENU_LONG_PRESS_SLOP } from \"../../lib/contextMenuHold.js\"\n\n/** The kit's gap between the preview and the menu: iOS 27 Context Menu 125:58750, Alignment=Vertical, the menu at\n * 176.5 under a content area that ends at 160.5 (the iOS 26 kit had 18). */\nexport const CONTEXT_MENU_PREVIEW_GAP = 16\n/** The kit's preview corner (Content Area, radius 30), for an element without corners of its own. */\nconst PREVIEW_RADIUS = 30\n\ntype Rect = { x: number; y: number; width: number; height: number }\n\n/**\n * Where the menu opens: at the pointer, under the element for the keyboard, or beside a touch-and-hold preview. A\n * preview's `rect` is where it stands, `shift` how far it moved up so that the menu stands whole below it, once known.\n */\nexport type ContextMenuPresentation =\n | { kind: \"pointer\"; rect: Rect }\n | { kind: \"keyboard\"; rect: Rect }\n | { kind: \"preview\"; rect: Rect; radius: number; align: \"start\" | \"end\"; shift?: number }\n\nconst px = (value: string, base: number) => {\n const number = Number.parseFloat(value)\n if (!Number.isFinite(number)) return 0\n return value.trim().endsWith(\"%\") ? (number / 100) * base : number\n}\n\n/**\n * The preview of a touch and hold: the element's box and corner (its own, or `--context-menu-preview-radius`), and\n * the edge the menu keeps to, the one on the side of the touch, as the kit's Side=Leading and Side=Trailing.\n */\nexport function contextMenuPreview(element: HTMLElement, touchX: number): ContextMenuPresentation {\n const box = element.getBoundingClientRect()\n const rect = { x: box.left, y: box.top, width: box.width, height: box.height }\n const style = getComputedStyle(element)\n const short = Math.min(rect.width, rect.height)\n const own = px(style.borderTopLeftRadius, short)\n const fallback = px(style.getPropertyValue(\"--context-menu-preview-radius\"), short) || PREVIEW_RADIUS\n const radius = Math.min(own > 0 ? own : fallback, short / 2)\n const width = element.ownerDocument.defaultView?.innerWidth ?? rect.x + rect.width\n return { kind: \"preview\", rect, radius, align: touchX < width / 2 ? \"start\" : \"end\" }\n}\n\n/** The menu's side, alignment and offsets for a presentation. */\nexport function contextMenuPlacement(presentation: ContextMenuPresentation | null) {\n if (presentation?.kind === \"preview\")\n return { side: \"bottom\" as const, align: presentation.align, sideOffset: CONTEXT_MENU_PREVIEW_GAP, alignOffset: 0 }\n if (presentation?.kind === \"keyboard\") return { side: \"bottom\" as const, align: \"start\" as const, sideOffset: 5, alignOffset: 0 }\n // As a desktop context menu, its corner at the pointer.\n return { side: \"bottom\" as const, align: \"start\" as const, sideOffset: 2, alignOffset: 0 }\n}\n\nconst round = (value: number) => Math.round(value * 100) / 100\n\n/**\n * The dimming covers the page but the element: the element's rounded box is cut out of it, so the element stays\n * clear above the dimmed, blurred page. `--context-menu-hole` draws the cut (an SVG mask), and\n * `--context-menu-hole-clip` the same shape as a clip path, through which a press reaches the element: a mask leaves\n * the dimming pressable, a clip path does not.\n */\nexport function contextMenuHoleMask(preview: Extract<ContextMenuPresentation, { kind: \"preview\" }>, viewport?: { width: number; height: number }) {\n const width = round(viewport?.width ?? window.innerWidth)\n const height = round(viewport?.height ?? window.innerHeight)\n const x = round(preview.rect.x)\n const y = round(preview.rect.y)\n const w = round(preview.rect.width)\n const h = round(preview.rect.height)\n const r = round(preview.radius)\n const hole = `M${x + r} ${y}H${round(x + w - r)}A${r} ${r} 0 0 1 ${x + w} ${round(y + r)}V${round(y + h - r)}A${r} ${r} 0 0 1 ${round(x + w - r)} ${round(y + h)}H${round(x + r)}A${r} ${r} 0 0 1 ${x} ${round(y + h - r)}V${round(y + r)}A${r} ${r} 0 0 1 ${round(x + r)} ${y}Z`\n const path = `M0 0H${width}V${height}H0Z${hole}`\n const svg = `<svg xmlns='http://www.w3.org/2000/svg' width='${width}' height='${height}' viewBox='0 0 ${width} ${height}'><path fill-rule='evenodd' d='${path}'/></svg>`\n return {\n \"--context-menu-hole\": `url(\"data:image/svg+xml,${encodeURIComponent(svg)}\")`,\n \"--context-menu-hole-clip\": `path(evenodd, \"${path}\")`,\n }\n}\n\n/**\n * How far the preview moves up so that a menu `height` tall stands whole below it, as iOS moves a lifted preview:\n * within `room` (the top and bottom the menu keeps to), and no higher than `ceiling`, the top of a box that clips\n * the element. Nothing when the menu fits. When no move lets it stand whole below, nothing either if it stands whole\n * above the element, where it then opens; else as far as the room above lets it, and the menu scrolls. All on the\n * screen: `scale` is the one a PhoneLayout is drawn at, which the gap takes too.\n */\nexport function contextMenuPreviewShift(rect: Rect, height: number, room: { top: number; bottom: number }, ceiling = -Infinity, scale = 1) {\n const gap = CONTEXT_MENU_PREVIEW_GAP * scale\n const missing = rect.y + rect.height + gap + height - room.bottom\n if (missing <= 0) return 0\n const allowed = Math.max(0, rect.y - Math.max(room.top, ceiling))\n if (missing <= allowed) return round(missing)\n return rect.y - gap - height >= room.top ? 0 : round(allowed)\n}\n\n/** The top of the nearest box that clips the element: moved above it, the element would not be seen. */\nexport function contextMenuClipTop(element: HTMLElement) {\n const view = element.ownerDocument.defaultView\n let top = -Infinity\n for (let node = element.parentElement; node && node !== element.ownerDocument.documentElement; node = node.parentElement) {\n const style = view?.getComputedStyle(node)\n if (style && (style.overflowX !== \"visible\" || style.overflowY !== \"visible\"))\n top = Math.max(top, node.getBoundingClientRect().top + node.clientTop)\n }\n return top\n}\n\n/** A menu's height without the limit of the room it is given: the panel, and what its items scroll out of sight. */\nexport function contextMenuNaturalHeight(content: HTMLElement) {\n const hidden = (element: Element) => (element instanceof HTMLElement ? Math.max(0, element.scrollHeight - element.clientHeight) : 0)\n return [...content.children].reduce((height, child) => height + hidden(child), content.offsetHeight + hidden(content))\n}\n\n/**\n * The name of the element a menu is for, which names the menu, in the order of accessible names: the text it is\n * labelled by, its own label, its text, or the text of a picture it is or shows.\n */\nexport function contextMenuName(element: HTMLElement) {\n const text = (value: string | null | undefined) => (value ?? \"\").replace(/\\s+/g, \" \").trim()\n const doc = element.ownerDocument\n const ids = text(element.getAttribute(\"aria-labelledby\")).split(\" \").filter(Boolean)\n const labelled = text(ids.map((id) => doc.getElementById(id)?.textContent ?? \"\").join(\" \"))\n if (labelled) return labelled\n const label = text(element.getAttribute(\"aria-label\"))\n if (label) return label\n const picture = element.matches(\"img[alt]\") ? element : element.querySelector(\"img[alt]\")\n return text(element.textContent) || text(picture?.getAttribute(\"alt\"))\n}\n\n/**\n * The box the anchor and the dimming lie in when they portal into a PhoneLayout, which is their containing block:\n * its padding box on the screen, and its scale when the frame is drawn smaller or larger. Null for the window.\n */\nexport type ContextMenuFrame = { left: number; top: number; scaleX: number; scaleY: number; width: number; height: number }\n\nexport function contextMenuFrame(box: HTMLElement | null | undefined): ContextMenuFrame | null {\n if (!box) return null\n const rect = box.getBoundingClientRect()\n const scaleX = box.offsetWidth > 0 ? rect.width / box.offsetWidth : 1\n const scaleY = box.offsetHeight > 0 ? rect.height / box.offsetHeight : 1\n return {\n left: rect.left + box.clientLeft * scaleX,\n top: rect.top + box.clientTop * scaleY,\n scaleX,\n scaleY,\n width: box.clientWidth,\n height: box.clientHeight,\n }\n}\n\n/** A rectangle on the screen in the coordinates of the frame, or as it is for the window. */\nexport const contextMenuInFrame = (rect: Rect, frame: ContextMenuFrame | null): Rect =>\n frame\n ? {\n x: round((rect.x - frame.left) / frame.scaleX),\n y: round((rect.y - frame.top) / frame.scaleY),\n width: round(rect.width / frame.scaleX),\n height: round(rect.height / frame.scaleY),\n }\n : rect\n\n/** The duration and easing of a motion token (`--motion-enter` with `--cubic-enter`), 0 where motion is reduced. */\nconst motion = (element: HTMLElement, name: \"enter\" | \"exit\") => {\n const style = getComputedStyle(element)\n const value = style.getPropertyValue(`--motion-${name}`).trim()\n const number = Number.parseFloat(value)\n const duration = !Number.isFinite(number) ? 0 : value.endsWith(\"ms\") ? number : value.endsWith(\"s\") ? number * 1000 : 0\n return { duration, easing: style.getPropertyValue(`--cubic-${name}`).trim() || \"ease\" }\n}\n\n/** The parts of a computed `translate` (`none`, or x, y and z lengths, a `calc()` among them). */\nconst translateParts = (value: string) => {\n const parts: string[] = []\n let depth = 0\n let part = \"\"\n for (const char of value.trim()) {\n if (char === \"(\") depth += 1\n if (char === \")\") depth -= 1\n if (char === \" \" && depth === 0) {\n if (part) parts.push(part)\n part = \"\"\n } else part += char\n }\n if (part) parts.push(part)\n return parts\n}\n\n/**\n * How large the element's pixels are drawn on the screen: the scale of the nearest box around it with a height, such\n * as a PhoneLayout drawn smaller. Read from its parents, which a transition or animation of the element's own does not\n * move.\n */\nconst screenScale = (element: HTMLElement) => {\n for (let node = element.parentElement; node; node = node.parentElement) {\n if (node.offsetHeight > 0) {\n const scale = node.getBoundingClientRect().height / node.offsetHeight\n return scale > 0 && Number.isFinite(scale) ? scale : 1\n }\n }\n return 1\n}\n\n/**\n * Changes the element's `translate` without a transition of its own (`transition: all` or one on `translate`): the\n * move has its own glide, and a drag measures the element right after it is put back. The transition the change\n * starts is cancelled, which shows the new value at once and leaves the element's own style as it was.\n */\nconst withoutTransition = (element: HTMLElement, change: () => void) => {\n change()\n // Reading the style starts the element's transition, if it has one\n void getComputedStyle(element).getPropertyValue(\"translate\")\n for (const animation of element.getAnimations?.() ?? []) {\n if (\"transitionProperty\" in animation && animation.transitionProperty === \"translate\") animation.cancel()\n }\n}\n\n/**\n * Moves the element up by `shift` pixels of the screen while its preview stands, gliding there as the dimming comes in\n * (or at once, for a menu held open that is placed again), and returns how to put it back: gliding as the dimming\n * goes, or at once for a drag that measures where the element stands; called again at once, it stops that glide. An\n * animation, not a transition, so the element's own styles stay; the move adds to a `translate` the element has.\n */\nexport function liftContextMenuPreview(element: HTMLElement, shift: number, smooth = true): (glide: boolean) => void {\n const previous = element.style.getPropertyValue(\"translate\")\n const computed = getComputedStyle(element).getPropertyValue(\"translate\").trim()\n const own = computed && computed !== \"none\" ? translateParts(computed) : []\n const rest = own.length > 0 ? computed : \"none\"\n const by = round(shift / screenScale(element))\n const raised = own.length > 0 ? [own[0], `calc(${own[1] ?? \"0px\"} - ${by}px)`, ...own.slice(2)].join(\" \") : `0 ${-by}px`\n withoutTransition(element, () => element.style.setProperty(\"translate\", raised))\n const glide = (from: string, to: string, name: \"enter\" | \"exit\") => {\n const { duration, easing } = motion(element, name)\n return duration > 0 && typeof element.animate === \"function\"\n ? element.animate([{ translate: from }, { translate: to }], { duration, easing })\n : undefined\n }\n let animation = smooth ? glide(rest, raised, \"enter\") : undefined\n let lifted = true\n return (back) => {\n if (!lifted) {\n if (!back) animation?.cancel()\n return\n }\n lifted = false\n animation?.cancel()\n withoutTransition(element, () => {\n if (previous) element.style.setProperty(\"translate\", previous)\n else element.style.removeProperty(\"translate\")\n })\n animation = back ? glide(raised, rest, \"exit\") : undefined\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cloneVNode, computed, createCommentVNode, defineComponent, Fragment as FragmentVNode, h, inject, onBeforeUnmount, onMounted, onUnmounted, provide, ref, shallowRef, watch, isVNode, } from "vue";
|
|
1
|
+
import { cloneVNode, computed, createCommentVNode, defineComponent, Fragment as FragmentVNode, h, inject, onBeforeUnmount, onMounted, onUnmounted, provide, ref, shallowRef, Teleport, watch, isVNode, mergeProps, } from "vue";
|
|
2
2
|
import { DialogContent as RekaDialogContent, DialogDescription as RekaDialogDescription, DialogOverlay as RekaDialogOverlay, DialogPortal as RekaDialogPortal, DialogRoot as RekaDialogRoot, DialogTitle as RekaDialogTitle, FocusScope as RekaFocusScope, injectDialogRootContext, useForwardExpose, useId, } from "reka-ui";
|
|
3
3
|
import { useEscCloseStack } from "../../composables/useEscCloseStack.js";
|
|
4
4
|
import { inToastRegion } from "../../lib/toastRegion.js";
|
|
@@ -22,6 +22,8 @@ const DIALOG_SCROLL = Symbol("DialogScroll");
|
|
|
22
22
|
const DIALOG_SHEET = Symbol("DialogSheet");
|
|
23
23
|
// Inside that bar: the title, the description and the header actions take the Toolbar's parts
|
|
24
24
|
const DIALOG_BAR = Symbol("DialogBar");
|
|
25
|
+
// Where DialogBody takes a phone Sheet's description: the first text of the content, under the bar
|
|
26
|
+
const DIALOG_DESCRIPTION_SLOT = Symbol("DialogDescriptionSlot");
|
|
25
27
|
// The phone layout of the Dialog style sheet (its rules for the Sheet's bar use the same query). A dialog's content
|
|
26
28
|
// mounts on the client only (its portal waits for the document), so it reads the layout as it mounts, with nothing to
|
|
27
29
|
// swap after it.
|
|
@@ -196,6 +198,7 @@ export const DialogContent = defineComponent({
|
|
|
196
198
|
provide(DIALOG_SHEET, computed(() => (props.mobileVariant === "sheet" ? { showClose: props.showClose } : null)));
|
|
197
199
|
// A dialog opened from a header action is not inside that header's bar
|
|
198
200
|
provide(DIALOG_BAR, computed(() => false));
|
|
201
|
+
provide(DIALOG_DESCRIPTION_SLOT, shallowRef(null));
|
|
199
202
|
const mobilePlacement = computed(() => props.mobileVariant === "alert"
|
|
200
203
|
? "center"
|
|
201
204
|
: props.mobilePlacement ?? (props.mobileVariant === "sheet" ? "bottom" : undefined));
|
|
@@ -442,34 +445,54 @@ export const DialogContent = defineComponent({
|
|
|
442
445
|
// The header's own parts, fragments opened up, so its actions can stand at the end of the bar
|
|
443
446
|
const headerParts = (children) => (children ?? []).flatMap((part) => isVNode(part) && part.type === FragmentVNode ? headerParts(part.children) : Array.isArray(part) ? headerParts(part) : [part]);
|
|
444
447
|
const isHeaderAction = (part) => isVNode(part) && part.type === DialogHeaderAction;
|
|
448
|
+
const isDescription = (part) => isVNode(part) && part.type === DialogDescription;
|
|
449
|
+
// The parts it holds stand outside the header's bar, as React's descriptions stand outside the bar's provider
|
|
450
|
+
const OutsideBar = defineComponent({
|
|
451
|
+
name: "DialogOutsideBar",
|
|
452
|
+
setup(_props, { slots }) {
|
|
453
|
+
provide(DIALOG_BAR, computed(() => false));
|
|
454
|
+
return () => slots.default?.();
|
|
455
|
+
},
|
|
456
|
+
});
|
|
445
457
|
export const DialogHeader = defineComponent({
|
|
446
458
|
name: "DialogHeader",
|
|
459
|
+
// A phone Sheet's header is the bar and the description under it: its attributes go to the bar
|
|
460
|
+
inheritAttrs: false,
|
|
447
461
|
props: {
|
|
448
462
|
/** How the bar meets the content scrolled under it in a phone Sheet. @default "glass" */
|
|
449
463
|
background: { type: String, default: "glass" },
|
|
450
464
|
},
|
|
451
|
-
setup(props, { slots }) {
|
|
465
|
+
setup(props, { slots, attrs }) {
|
|
452
466
|
const scroll = inject(DIALOG_SCROLL, null);
|
|
453
467
|
const sheet = inject(DIALOG_SHEET, null);
|
|
468
|
+
const descriptionSlot = inject(DIALOG_DESCRIPTION_SLOT, null);
|
|
454
469
|
const phone = usePhoneLayout();
|
|
455
470
|
const bar = computed(() => !!sheet?.value && phone.value);
|
|
456
471
|
provide(DIALOG_BAR, bar);
|
|
457
472
|
return () => {
|
|
458
473
|
if (!bar.value)
|
|
459
|
-
return h("div", { class: s.Header, "data-background": props.background, "data-scrolled": scroll?.scrolled.value ? "" : undefined }, slots.default?.());
|
|
474
|
+
return h("div", mergeProps({ "class": s.Header, "data-background": props.background, "data-scrolled": scroll?.scrolled.value ? "" : undefined }, attrs), slots.default?.());
|
|
460
475
|
const parts = headerParts(slots.default?.());
|
|
476
|
+
const descriptions = parts.filter(isDescription);
|
|
477
|
+
const slot = descriptionSlot?.value ?? null;
|
|
461
478
|
// On a phone the header of a Sheet is its Toolbar (iOS 27 kit Sheets 507-24684, Toolbar - Top - iPhone
|
|
462
|
-
// 1-54520): Close at the leading edge, the title centered on the row of controls, the header actions
|
|
463
|
-
// trailing edge, all on one 44px row under the grabber.
|
|
464
|
-
return
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
h(
|
|
468
|
-
|
|
479
|
+
// 1-54520): Close at the leading edge, the title alone centered on the row of controls, the header actions
|
|
480
|
+
// at the trailing edge, all on one 44px row under the grabber.
|
|
481
|
+
return [
|
|
482
|
+
h(Toolbar, mergeProps({ "background": props.background, "data-dialog-bar": "" }, attrs), () => [
|
|
483
|
+
sheet?.value?.showClose
|
|
484
|
+
? h(ToolbarLeading, { class: s.BarClose }, () => [
|
|
485
|
+
h(DialogClose, null, { default: () => [h(NavigationButton, { "action": "close", "variant": "ghost", "aria-label": "Close dialog" })] }),
|
|
486
|
+
])
|
|
487
|
+
: null,
|
|
488
|
+
h("div", { class: [t.Heading, s.BarHeading] }, parts.filter((part) => !isHeaderAction(part) && !isDescription(part))),
|
|
489
|
+
...parts.filter(isHeaderAction),
|
|
490
|
+
]),
|
|
491
|
+
// The description reads as the first text of the content, at the top of DialogBody when there is one
|
|
492
|
+
descriptions.length > 0
|
|
493
|
+
? h(Teleport, { to: slot, disabled: !slot }, [h("div", { class: s.SheetDescription }, [h(OutsideBar, null, () => descriptions)])])
|
|
469
494
|
: null,
|
|
470
|
-
|
|
471
|
-
...parts.filter(isHeaderAction),
|
|
472
|
-
]);
|
|
495
|
+
];
|
|
473
496
|
};
|
|
474
497
|
},
|
|
475
498
|
});
|
|
@@ -486,6 +509,13 @@ export const DialogBody = defineComponent({
|
|
|
486
509
|
inheritAttrs: false,
|
|
487
510
|
setup(_props, { slots, attrs }) {
|
|
488
511
|
const scroll = inject(DIALOG_SCROLL, null);
|
|
512
|
+
const sheet = inject(DIALOG_SHEET, null);
|
|
513
|
+
const descriptionSlot = inject(DIALOG_DESCRIPTION_SLOT, null);
|
|
514
|
+
const phone = usePhoneLayout();
|
|
515
|
+
const setDescriptionSlot = (slot) => {
|
|
516
|
+
if (descriptionSlot)
|
|
517
|
+
descriptionSlot.value = slot instanceof HTMLElement ? slot : null;
|
|
518
|
+
};
|
|
489
519
|
const element = ref(null);
|
|
490
520
|
let stop;
|
|
491
521
|
onMounted(() => {
|
|
@@ -503,7 +533,10 @@ export const DialogBody = defineComponent({
|
|
|
503
533
|
scroll.contentBelow.value = false;
|
|
504
534
|
}
|
|
505
535
|
});
|
|
506
|
-
return () => h("div", { ref: element, class: [s.Body, attrs.class] },
|
|
536
|
+
return () => h("div", { ref: element, class: [s.Body, attrs.class] }, [
|
|
537
|
+
sheet?.value && phone.value ? h("div", { ref: setDescriptionSlot, class: s.SheetDescriptionSlot }) : null,
|
|
538
|
+
slots.default?.(),
|
|
539
|
+
]);
|
|
507
540
|
},
|
|
508
541
|
});
|
|
509
542
|
export const DialogFooter = defineComponent({
|
|
@@ -550,7 +583,8 @@ export const DialogDescription = defineComponent({
|
|
|
550
583
|
const bar = inject(DIALOG_BAR, null);
|
|
551
584
|
const element = ref(null);
|
|
552
585
|
const shown = ref(false);
|
|
553
|
-
//
|
|
586
|
+
// The header leaves its own descriptions out of the bar. One the bar still holds, inside a part of the
|
|
587
|
+
// header's own, is the title's second line (Toolbar's subtitle) when the reader sees it; one that is only
|
|
554
588
|
// read out, visually hidden, leaves the title on its one line.
|
|
555
589
|
const measure = () => {
|
|
556
590
|
const node = element.value instanceof Element ? element.value : element.value?.$el;
|