@plexui/ui 0.31.0 → 0.33.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.
@@ -1,3 +1,4 @@
1
+ import { isPhoneLayout } from "./phoneLayout.js";
1
2
  const clamp = (value, minimum, maximum) => Math.max(minimum, Math.min(maximum, value));
2
3
  const round = (value) => Math.round(value * 1000) / 1000;
3
4
  export function solvePhoneSubmenuPlacement({ boundary, trigger, parent, reference = trigger, width, height, paddingTop, direction, }) {
@@ -120,8 +121,59 @@ export function samePhoneSubmenuState(a, b) {
120
121
  return a.mobile === b.mobile && (!a.mobile || !b.mobile ||
121
122
  (a.ready === b.ready && a.unavailable === b.unavailable && a.label === b.label && a.sideOffset === b.sideOffset && a.alignOffset === b.alignOffset));
122
123
  }
123
- /** Own only these Phone attributes/variables. Primitive focus and dismissal stay intact. */
124
- export function observePhoneSubmenu(trigger, content, boundary, update) {
124
+ /**
125
+ * Cancels the release of a press that a phone submenu's parent took to collapse the submenu. The parent's rows take
126
+ * presses again a frame after it collapses, and a release over one of them would choose it, as a touch dragged through
127
+ * a menu does (Radix and Reka items click on a release that did not start on them). Only that press's release and the
128
+ * click right after it: a press whose release never comes ends with the next press or when the window loses focus.
129
+ */
130
+ function swallowRelease(view, pointerId) {
131
+ let timer;
132
+ const stop = (event) => {
133
+ event.preventDefault();
134
+ event.stopPropagation();
135
+ };
136
+ const click = (event) => {
137
+ stop(event);
138
+ done();
139
+ };
140
+ const end = (event) => {
141
+ if (event.pointerId !== pointerId)
142
+ return;
143
+ view.removeEventListener("pointerup", end, true);
144
+ view.removeEventListener("pointercancel", end, true);
145
+ // None comes after a cancelled press
146
+ if (event.type !== "pointerup")
147
+ return done();
148
+ stop(event);
149
+ // The click of that release comes right after it
150
+ view.addEventListener("click", click, true);
151
+ timer = setTimeout(done, 400);
152
+ };
153
+ const done = () => {
154
+ if (timer !== undefined)
155
+ clearTimeout(timer);
156
+ view.removeEventListener("pointerup", end, true);
157
+ view.removeEventListener("pointercancel", end, true);
158
+ view.removeEventListener("click", click, true);
159
+ view.removeEventListener("pointerdown", done, true);
160
+ view.removeEventListener("blur", done);
161
+ };
162
+ view.addEventListener("pointerup", end, true);
163
+ view.addEventListener("pointercancel", end, true);
164
+ // Added while that press's own pointerdown is past the window, so only a later press ends it
165
+ view.addEventListener("pointerdown", done, true);
166
+ view.addEventListener("blur", done);
167
+ }
168
+ /**
169
+ * Own only these Phone attributes/variables. Primitive focus and dismissal stay intact.
170
+ *
171
+ * While a phone submenu stands over its parent the parent is behind it, as in iOS 26 (owner, plan 176): a press on it
172
+ * collapses the submenu (`onParentPress`) and chooses none of its rows, which take no presses (Menu.module.css), and
173
+ * it is hidden from a screen reader. Focus left in it by the press that opened the submenu moves into the submenu, as
174
+ * VoiceOver's moves into an iOS submenu, and a focus that returns to it (the submenu collapsing) shows it again.
175
+ */
176
+ export function observePhoneSubmenu(trigger, content, boundary, update, onParentPress) {
125
177
  const view = content.ownerDocument.defaultView;
126
178
  if (!view || trigger.ownerDocument !== content.ownerDocument)
127
179
  return { refresh: () => { }, dispose: () => { } };
@@ -131,7 +183,61 @@ export function observePhoneSubmenu(trigger, content, boundary, update) {
131
183
  const media = typeof view.matchMedia === "function" ? view.matchMedia("(max-width: 767px)") : null;
132
184
  let disposed = false;
133
185
  let frame;
186
+ let focusFrame;
187
+ // Whether the submenu has found its place or found there is none, and the focus it found then
188
+ let settled = false;
189
+ let focusAtOpen = null;
134
190
  let references = [];
191
+ const covered = () => parent.hasAttribute("data-submenu-over");
192
+ const showParent = () => {
193
+ if (parent.getAttribute("data-submenu-hidden") === null)
194
+ return;
195
+ parent.removeAttribute("data-submenu-hidden");
196
+ parent.removeAttribute("aria-hidden");
197
+ };
198
+ // A frame after the submenu stands over the parent, once the primitive's focus scopes have taken it as a branch of a
199
+ // modal menu: focus the press left on the row that opened it moves into the submenu, then the parent is hidden
200
+ const hideParent = () => {
201
+ if (focusFrame !== undefined)
202
+ return;
203
+ focusFrame = view.requestAnimationFrame(() => {
204
+ focusFrame = undefined;
205
+ if (disposed || !covered())
206
+ return;
207
+ const focused = content.ownerDocument.activeElement;
208
+ // Only the focus the submenu found as it first stood over the parent, untouched since: a keyboard entry, a
209
+ // collapse or a later return to the parent own focus, and a submenu that first had no room does not take it
210
+ if (focusAtOpen && focused === focusAtOpen && parent.contains(focused))
211
+ content.focus({ preventScroll: true });
212
+ focusAtOpen = null;
213
+ // A hidden element must not hold focus; a parent focused again stays shown
214
+ if (parent.contains(content.ownerDocument.activeElement))
215
+ return;
216
+ parent.setAttribute("data-submenu-hidden", "");
217
+ parent.setAttribute("aria-hidden", "true");
218
+ });
219
+ };
220
+ const pressParent = (event) => {
221
+ // A primary press, a touch or a pen: a secondary button chooses nothing behind the submenu anyway
222
+ if (event.button !== 0 || !covered() || content.contains(event.target))
223
+ return;
224
+ // It goes on to the primitives' layers, which mark a press inside a menu until it reaches the document; its rows
225
+ // take no pointer, and the release and click that would choose one are cancelled
226
+ event.preventDefault();
227
+ swallowRelease(view, event.pointerId);
228
+ onParentPress?.();
229
+ };
230
+ const focusParent = () => showParent();
231
+ // Its rows take no pointer (Menu.module.css), so the pointer leaves the row that opened the submenu once the submenu
232
+ // covers it: that leave must not move focus back to the parent, which would close the submenu
233
+ const leaveParent = (event) => {
234
+ if (covered() && !content.contains(event.target))
235
+ event.stopPropagation();
236
+ };
237
+ parent.addEventListener("pointerdown", pressParent, true);
238
+ parent.addEventListener("focusin", focusParent, true);
239
+ parent.addEventListener("pointerout", leaveParent, true);
240
+ parent.addEventListener("pointerleave", leaveParent, true);
135
241
  const setVariable = (name, value) => {
136
242
  const next = `${round(Math.max(0, value))}px`;
137
243
  if (content.style.getPropertyValue(name) !== next)
@@ -161,9 +267,11 @@ export function observePhoneSubmenu(trigger, content, boundary, update) {
161
267
  const refresh = () => {
162
268
  if (disposed)
163
269
  return;
164
- if (!(media?.matches ?? view.innerWidth <= 767)) {
270
+ // A narrow window, or a PhoneLayout or phone Dialog at any width
271
+ if (!isPhoneLayout(content)) {
165
272
  clearPhone();
166
273
  parent.removeAttribute("data-submenu-over");
274
+ showParent();
167
275
  update({ mobile: false });
168
276
  return;
169
277
  }
@@ -205,10 +313,19 @@ export function observePhoneSubmenu(trigger, content, boundary, update) {
205
313
  else
206
314
  content.removeAttribute("data-submenu-unavailable");
207
315
  // The parent steps back while the submenu stands over it (Menu.module.css), not while it has nowhere to stand
208
- if (ready)
316
+ if ((ready || unavailable) && !settled) {
317
+ settled = true;
318
+ if (ready)
319
+ focusAtOpen = content.ownerDocument.activeElement;
320
+ }
321
+ if (ready) {
209
322
  parent.setAttribute("data-submenu-over", "");
210
- else
323
+ hideParent();
324
+ }
325
+ else {
211
326
  parent.removeAttribute("data-submenu-over");
327
+ showParent();
328
+ }
212
329
  update({ mobile: true, ready, unavailable, label, ...(placement ?? { sideOffset: 0, alignOffset: 0 }) });
213
330
  // A parent's enter transform moves its child trigger without resizing it.
214
331
  // Follow only that running transition, not an idle menu forever.
@@ -240,6 +357,13 @@ export function observePhoneSubmenu(trigger, content, boundary, update) {
240
357
  disposed = true;
241
358
  if (frame !== undefined)
242
359
  view.cancelAnimationFrame(frame);
360
+ if (focusFrame !== undefined)
361
+ view.cancelAnimationFrame(focusFrame);
362
+ parent.removeEventListener("pointerdown", pressParent, true);
363
+ parent.removeEventListener("focusin", focusParent, true);
364
+ parent.removeEventListener("pointerout", leaveParent, true);
365
+ parent.removeEventListener("pointerleave", leaveParent, true);
366
+ showParent();
243
367
  resize?.disconnect();
244
368
  mutations.disconnect();
245
369
  labelObserver.disconnect();
@@ -1 +1 @@
1
- {"version":3,"file":"menuSubmenuPlacement.js","sourceRoot":"","sources":["../../../src/lib/menuSubmenuPlacement.ts"],"names":[],"mappings":"AASA,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,OAAe,EAAE,OAAe,EAAE,EAAE,CAChE,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE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zD,IAAI,CAAC,cAAc,EAAE,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;IACzD,OAAO,EAAE,CAAA;IACT,OAAO;QACL,OAAO;QACP,OAAO,EAAE,GAAG,EAAE;YACZ,QAAQ,GAAG,IAAI,CAAA;YACf,IAAI,KAAK,KAAK,SAAS;gBAAE,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAA;YACzD,MAAM,EAAE,UAAU,EAAE,CAAA;YACpB,SAAS,CAAC,UAAU,EAAE,CAAA;YACtB,aAAa,CAAC,UAAU,EAAE,CAAA;YAC1B,KAAK,EAAE,mBAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;YAC7C,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;YAClD,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;YAC5C,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;YAC5D,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;YAC5D,6GAA6G;YAC7G,8GAA8G;YAC9G,uGAAuG;YACvG,IAAI,CAAC,qBAAqB,CAAC,GAAG,EAAE;gBAC9B,IAAI,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,MAAM,CAAC,YAAY,CAAC,YAAY,CAAC,KAAK,QAAQ;oBAAE,OAAM;gBAC9F,IAAI,MAAM,CAAC,aAAa,CAAC,wBAAwB,CAAC;oBAAE,OAAM;gBAC1D,MAAM,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAA;YAC7C,CAAC,CAAC,CAAA;QACJ,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["/** Phone submenu geometry; desktop continues to use the primitive's cascade. */\nexport type MenuRect = { left: number; top: number; right: number; bottom: number }\nexport type MenuCollisionPadding = Partial<Record<\"top\" | \"right\" | \"bottom\" | \"left\", number>>\nexport type MenuFloatingBoundary = { collisionBoundary?: HTMLElement; collisionPadding: MenuCollisionPadding }\nexport type PhoneSubmenuPlacement = { sideOffset: number; alignOffset: number }\nexport type PhoneSubmenuState =\n | { mobile: false }\n | ({ mobile: true; ready: boolean; unavailable: boolean; label: string } & PhoneSubmenuPlacement)\n\nconst clamp = (value: number, minimum: number, maximum: number) =>\n Math.max(minimum, Math.min(maximum, value))\nconst round = (value: number) => Math.round(value * 1000) / 1000\n\nexport function solvePhoneSubmenuPlacement({\n boundary, trigger, parent, reference = trigger, width, height, paddingTop, direction,\n}: {\n boundary: MenuRect\n trigger: MenuRect\n parent: MenuRect\n /** The row's box as the primitive measures it, when the parent steps back (`readRestingMenuRects`) */\n reference?: MenuRect\n width: number\n height: number\n paddingTop: number\n direction: \"ltr\" | \"rtl\"\n}): PhoneSubmenuPlacement | null {\n if (width <= 0 || height <= 0 || boundary.right <= boundary.left || boundary.bottom <= boundary.top) return null\n // CSS caps the measured panel against this same rectangle. Do not paint an\n // oversized panel if that contract has not reached layout yet.\n if (width > boundary.right - boundary.left + 1 || height > boundary.bottom - boundary.top + 1) return null\n const left = clamp(direction === \"rtl\" ? parent.right - width : parent.left, boundary.left, Math.max(boundary.left, boundary.right - width))\n const top = clamp(trigger.top - paddingTop, boundary.top, Math.max(boundary.top, boundary.bottom - height))\n return {\n sideOffset: round(direction === \"rtl\" ? reference.left - width - left : left - reference.right),\n alignOffset: round(top - reference.top),\n }\n}\n\n/**\n * The boxes of a parent menu and of the row that opened a submenu at rest. While a phone submenu stands over it the\n * parent steps back with the CSS `scale` property (Menu.module.css, iOS-menu IMG_5677), and the submenu keeps the\n * parent's resting box, as the native one does: undo that scale around the parent's transform origin, at whatever\n * value its transition has reached.\n */\nexport function readRestingMenuRects(parent: HTMLElement, trigger: HTMLElement): { parent: MenuRect; trigger: MenuRect; reference: MenuRect } {\n const parentRect = parent.getBoundingClientRect()\n const triggerRect = trigger.getBoundingClientRect()\n const view = parent.ownerDocument.defaultView\n const style = view?.getComputedStyle(parent)\n const scale = Number.parseFloat(style?.scale ?? \"\")\n if (!style || !Number.isFinite(scale) || scale <= 0 || scale === 1) return { parent: parentRect, trigger: triggerRect, reference: triggerRect }\n const [originX = 0, originY = 0] = style.transformOrigin.split(\" \").map((value) => Number.parseFloat(value) || 0)\n const x = parentRect.left + originX * scale\n const y = parentRect.top + originY * scale\n const rest = (rect: MenuRect): MenuRect => ({\n left: x + (rect.left - x) / scale,\n top: y + (rect.top - y) / scale,\n right: x + (rect.right - x) / scale,\n bottom: y + (rect.bottom - y) / scale,\n })\n return { parent: rest(parentRect), trigger: rest(triggerRect), reference: triggerRect }\n}\n\n/** Consume boundary91's resolved footer padding; never subtract the footer again. */\nexport function readMenuBoundaryRect(document: Document, boundary: MenuFloatingBoundary): MenuRect | null {\n const view = document.defaultView\n if (!view) return null\n const viewport = view.visualViewport\n let left = viewport?.offsetLeft ?? 0\n let top = viewport?.offsetTop ?? 0\n let right = left + (viewport?.width ?? document.documentElement.clientWidth)\n let bottom = top + (viewport?.height ?? document.documentElement.clientHeight)\n const element = boundary.collisionBoundary\n if (element?.isConnected && element.ownerDocument === document) {\n const rect = element.getBoundingClientRect()\n const scaleX = element.offsetWidth > 0 ? rect.width / element.offsetWidth : 1\n const scaleY = element.offsetHeight > 0 ? rect.height / element.offsetHeight : 1\n const clientLeft = rect.left + element.clientLeft * scaleX\n const clientTop = rect.top + element.clientTop * scaleY\n left = Math.max(left, clientLeft)\n top = Math.max(top, clientTop)\n right = Math.min(right, clientLeft + element.clientWidth * scaleX)\n bottom = Math.min(bottom, clientTop + element.clientHeight * scaleY)\n }\n const padding = boundary.collisionPadding\n return {\n left: left + (padding.left ?? 0),\n top: top + (padding.top ?? 0),\n right: right - (padding.right ?? 0),\n bottom: bottom - (padding.bottom ?? 0),\n }\n}\n\nconst normalizeLabel = (value: string) => value.replace(/\\s+/g, \" \").trim()\n\nfunction visibleText(element: Element, includeHidden = false): string {\n const view = element.ownerDocument.defaultView\n if (!view) return \"\"\n // Explicit aria-labelledby targets can supply a name while visually hidden.\n if (!includeHidden && (element.hasAttribute(\"hidden\") || element.getAttribute(\"aria-hidden\") === \"true\")) return \"\"\n if ([\"SCRIPT\", \"STYLE\", \"TEMPLATE\"].includes(element.tagName)) return \"\"\n // A row's second line (Sort By over \"Manual\") is its value, not its name\n if (element.hasAttribute(\"data-menu-description\")) return \"\"\n const style = view.getComputedStyle(element)\n if (!includeHidden && (style.display === \"none\" || style.visibility === \"hidden\" || style.visibility === \"collapse\")) return \"\"\n const ownLabel = element.getAttribute(\"aria-label\")\n if (ownLabel?.trim()) return ownLabel\n if (element.tagName === \"IMG\") return element.getAttribute(\"alt\") ?? \"\"\n return Array.from(element.childNodes).map((node) => {\n if (node.nodeType === 3) return node.textContent ?? \"\"\n return node instanceof view.Element ? visibleText(node, includeHidden) : \"\"\n }).join(\"\")\n}\n\nfunction labelReferences(trigger: HTMLElement): Element[] {\n return (trigger.getAttribute(\"aria-labelledby\") ?? \"\").split(/\\s+/).filter(Boolean)\n .map((id) => trigger.ownerDocument.getElementById(id)).filter((element): element is HTMLElement => element !== null)\n}\n\n/** A text snapshot, never a clone of a consumer's rich children or their IDs. */\nexport function readMenuTriggerLabel(trigger: HTMLElement): string {\n const referenced = normalizeLabel(labelReferences(trigger).map((element) => visibleText(element, true)).join(\" \"))\n if (referenced) return referenced\n const labelled = normalizeLabel(trigger.getAttribute(\"aria-label\") ?? \"\")\n if (labelled) return labelled\n return normalizeLabel(visibleText(trigger)) || \"Collapse submenu\"\n}\n\nexport function focusPhoneSubmenuEntry(content: HTMLElement): void {\n const items = Array.from(content.querySelectorAll<HTMLElement>('[role=\"menuitem\"], [role=\"menuitemcheckbox\"], [role=\"menuitemradio\"]'))\n .filter((item) => item.closest('[role=\"menu\"]') === content && !item.hasAttribute(\"data-disabled\") && item.getAttribute(\"aria-disabled\") !== \"true\")\n const target = items.find((item) => !item.hasAttribute(\"data-submenu-collapse\")) ?? items[0]\n target?.focus({ preventScroll: true })\n}\n\nexport function samePhoneSubmenuState(a: PhoneSubmenuState, b: PhoneSubmenuState): boolean {\n return a.mobile === b.mobile && (!a.mobile || !b.mobile ||\n (a.ready === b.ready && a.unavailable === b.unavailable && a.label === b.label && a.sideOffset === b.sideOffset && a.alignOffset === b.alignOffset))\n}\n\n/** Own only these Phone attributes/variables. Primitive focus and dismissal stay intact. */\nexport function observePhoneSubmenu(\n trigger: HTMLElement,\n content: HTMLElement,\n boundary: MenuFloatingBoundary,\n update: (state: PhoneSubmenuState) => void,\n): { refresh: () => void; dispose: () => void } {\n const view = content.ownerDocument.defaultView\n if (!view || trigger.ownerDocument !== content.ownerDocument) return { refresh: () => {}, dispose: () => {} }\n const parent = trigger.closest('[role=\"menu\"]')\n if (!(parent instanceof view.HTMLElement)) return { refresh: () => {}, dispose: () => {} }\n const media = typeof view.matchMedia === \"function\" ? view.matchMedia(\"(max-width: 767px)\") : null\n let disposed = false\n let frame: number | undefined\n let references: Element[] = []\n const setVariable = (name: string, value: number) => {\n const next = `${round(Math.max(0, value))}px`\n if (content.style.getPropertyValue(name) !== next) content.style.setProperty(name, next)\n }\n const clearPhone = () => {\n content.removeAttribute(\"data-submenu-phone\")\n content.removeAttribute(\"data-submenu-positioned\")\n content.removeAttribute(\"data-submenu-unavailable\")\n content.style.removeProperty(\"--menu-phone-max-width\")\n content.style.removeProperty(\"--menu-phone-max-height\")\n }\n const labelObserver = new view.MutationObserver(() => schedule())\n const updateLabelTargets = () => {\n const next = labelReferences(trigger)\n if (next.length === references.length && next.every((element, index) => element === references[index])) return\n references = next\n labelObserver.disconnect()\n for (const element of references) {\n labelObserver.observe(element, { childList: true, characterData: true, subtree: true, attributes: true })\n // A localized label can be replaced while retaining its public ID.\n if (element.parentElement) labelObserver.observe(element.parentElement, { childList: true })\n }\n }\n const refresh = () => {\n if (disposed) return\n if (!(media?.matches ?? view.innerWidth <= 767)) {\n clearPhone()\n parent.removeAttribute(\"data-submenu-over\")\n update({ mobile: false })\n return\n }\n content.setAttribute(\"data-submenu-phone\", \"\")\n updateLabelTargets()\n const label = readMenuTriggerLabel(trigger)\n const available = readMenuBoundaryRect(content.ownerDocument, boundary)\n if (!available) return\n setVariable(\"--menu-phone-max-width\", available.right - available.left)\n setVariable(\"--menu-phone-max-height\", available.bottom - available.top)\n const style = view.getComputedStyle(content)\n const width = content.offsetWidth\n const height = content.offsetHeight\n const hasHeader = !!content.querySelector(\"[data-submenu-collapse]\")\n const resting = readRestingMenuRects(parent, trigger)\n const placement = solvePhoneSubmenuPlacement({\n boundary: available,\n trigger: resting.trigger,\n parent: resting.parent,\n reference: resting.reference,\n width,\n height,\n paddingTop: Number.parseFloat(style.paddingTop) || 0,\n direction: style.direction === \"rtl\" ? \"rtl\" : \"ltr\",\n })\n // Wait for the header and real geometry, never flash the desktop cascade.\n const ready = !!placement && hasHeader\n // Header/zero-layout are still pending. After the CSS caps and header are\n // present, an empty boundary or measured overflow has no valid placement.\n const emptyBoundary = available.right <= available.left || available.bottom <= available.top\n const unavailable = hasHeader && !placement && (emptyBoundary || (width > 0 && height > 0))\n if (ready) content.setAttribute(\"data-submenu-positioned\", \"\")\n else content.removeAttribute(\"data-submenu-positioned\")\n if (unavailable) content.setAttribute(\"data-submenu-unavailable\", \"\")\n else content.removeAttribute(\"data-submenu-unavailable\")\n // The parent steps back while the submenu stands over it (Menu.module.css), not while it has nowhere to stand\n if (ready) parent.setAttribute(\"data-submenu-over\", \"\")\n else parent.removeAttribute(\"data-submenu-over\")\n update({ mobile: true, ready, unavailable, label, ...(placement ?? { sideOffset: 0, alignOffset: 0 }) })\n // A parent's enter transform moves its child trigger without resizing it.\n // Follow only that running transition, not an idle menu forever.\n if (typeof parent.getAnimations === \"function\" && parent.getAnimations().some((animation) => animation.playState === \"running\")) schedule()\n }\n const schedule = () => {\n if (!disposed && frame === undefined) frame = view.requestAnimationFrame(() => { frame = undefined; refresh() })\n }\n const resize = typeof view.ResizeObserver === \"function\" ? new view.ResizeObserver(schedule) : undefined\n for (const element of [trigger, parent, content, boundary.collisionBoundary]) if (element) resize?.observe(element)\n const mutations = new view.MutationObserver(schedule)\n mutations.observe(trigger, { attributes: true, characterData: true, childList: true, subtree: true })\n mutations.observe(parent, { attributes: true, attributeFilter: [\"class\", \"style\"] })\n if (parent.parentElement) mutations.observe(parent.parentElement, { attributes: true, attributeFilter: [\"class\", \"style\", \"data-entering\", \"data-entering-active\"] })\n media?.addEventListener(\"change\", refresh)\n view.addEventListener(\"scroll\", schedule, true)\n view.addEventListener(\"resize\", schedule)\n view.visualViewport?.addEventListener(\"scroll\", schedule)\n view.visualViewport?.addEventListener(\"resize\", schedule)\n refresh()\n return {\n refresh,\n dispose: () => {\n disposed = true\n if (frame !== undefined) view.cancelAnimationFrame(frame)\n resize?.disconnect()\n mutations.disconnect()\n labelObserver.disconnect()\n media?.removeEventListener(\"change\", refresh)\n view.removeEventListener(\"scroll\", schedule, true)\n view.removeEventListener(\"resize\", schedule)\n view.visualViewport?.removeEventListener(\"scroll\", schedule)\n view.visualViewport?.removeEventListener(\"resize\", schedule)\n // Retained transition nodes keep their last geometry through exit, and a parent that leaves with its submenu\n // leaves stepped back. A choice in the submenu closes it before the whole menu starts to leave, so the parent\n // steps forward a frame later, unless by then it is leaving or another of its submenus stands over it.\n view.requestAnimationFrame(() => {\n if (parent.closest(\"[data-exiting]\") || parent.getAttribute(\"data-state\") === \"closed\") return\n if (parent.querySelector('[aria-expanded=\"true\"]')) return\n parent.removeAttribute(\"data-submenu-over\")\n })\n },\n }\n}\n"]}
1
+ {"version":3,"file":"menuSubmenuPlacement.js","sourceRoot":"","sources":["../../../src/lib/menuSubmenuPlacement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAW7C,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,OAAe,EAAE,OAAe,EAAE,EAAE,CAChE,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE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AAE,CAAA;YACtB,aAAa,CAAC,UAAU,EAAE,CAAA;YAC1B,KAAK,EAAE,mBAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;YAC7C,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;YAClD,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;YAC5C,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;YAC5D,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;YAC5D,6GAA6G;YAC7G,8GAA8G;YAC9G,uGAAuG;YACvG,IAAI,CAAC,qBAAqB,CAAC,GAAG,EAAE;gBAC9B,IAAI,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,MAAM,CAAC,YAAY,CAAC,YAAY,CAAC,KAAK,QAAQ;oBAAE,OAAM;gBAC9F,IAAI,MAAM,CAAC,aAAa,CAAC,wBAAwB,CAAC;oBAAE,OAAM;gBAC1D,MAAM,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAA;YAC7C,CAAC,CAAC,CAAA;QACJ,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["import { isPhoneLayout } from \"./phoneLayout\"\n\n/** Phone submenu geometry; desktop continues to use the primitive's cascade. */\nexport type MenuRect = { left: number; top: number; right: number; bottom: number }\nexport type MenuCollisionPadding = Partial<Record<\"top\" | \"right\" | \"bottom\" | \"left\", number>>\nexport type MenuFloatingBoundary = { collisionBoundary?: HTMLElement; collisionPadding: MenuCollisionPadding }\nexport type PhoneSubmenuPlacement = { sideOffset: number; alignOffset: number }\nexport type PhoneSubmenuState =\n | { mobile: false }\n | ({ mobile: true; ready: boolean; unavailable: boolean; label: string } & PhoneSubmenuPlacement)\n\nconst clamp = (value: number, minimum: number, maximum: number) =>\n Math.max(minimum, Math.min(maximum, value))\nconst round = (value: number) => Math.round(value * 1000) / 1000\n\nexport function solvePhoneSubmenuPlacement({\n boundary, trigger, parent, reference = trigger, width, height, paddingTop, direction,\n}: {\n boundary: MenuRect\n trigger: MenuRect\n parent: MenuRect\n /** The row's box as the primitive measures it, when the parent steps back (`readRestingMenuRects`) */\n reference?: MenuRect\n width: number\n height: number\n paddingTop: number\n direction: \"ltr\" | \"rtl\"\n}): PhoneSubmenuPlacement | null {\n if (width <= 0 || height <= 0 || boundary.right <= boundary.left || boundary.bottom <= boundary.top) return null\n // CSS caps the measured panel against this same rectangle. Do not paint an\n // oversized panel if that contract has not reached layout yet.\n if (width > boundary.right - boundary.left + 1 || height > boundary.bottom - boundary.top + 1) return null\n const left = clamp(direction === \"rtl\" ? parent.right - width : parent.left, boundary.left, Math.max(boundary.left, boundary.right - width))\n const top = clamp(trigger.top - paddingTop, boundary.top, Math.max(boundary.top, boundary.bottom - height))\n return {\n sideOffset: round(direction === \"rtl\" ? reference.left - width - left : left - reference.right),\n alignOffset: round(top - reference.top),\n }\n}\n\n/**\n * The boxes of a parent menu and of the row that opened a submenu at rest. While a phone submenu stands over it the\n * parent steps back with the CSS `scale` property (Menu.module.css, iOS-menu IMG_5677), and the submenu keeps the\n * parent's resting box, as the native one does: undo that scale around the parent's transform origin, at whatever\n * value its transition has reached.\n */\nexport function readRestingMenuRects(parent: HTMLElement, trigger: HTMLElement): { parent: MenuRect; trigger: MenuRect; reference: MenuRect } {\n const parentRect = parent.getBoundingClientRect()\n const triggerRect = trigger.getBoundingClientRect()\n const view = parent.ownerDocument.defaultView\n const style = view?.getComputedStyle(parent)\n const scale = Number.parseFloat(style?.scale ?? \"\")\n if (!style || !Number.isFinite(scale) || scale <= 0 || scale === 1) return { parent: parentRect, trigger: triggerRect, reference: triggerRect }\n const [originX = 0, originY = 0] = style.transformOrigin.split(\" \").map((value) => Number.parseFloat(value) || 0)\n const x = parentRect.left + originX * scale\n const y = parentRect.top + originY * scale\n const rest = (rect: MenuRect): MenuRect => ({\n left: x + (rect.left - x) / scale,\n top: y + (rect.top - y) / scale,\n right: x + (rect.right - x) / scale,\n bottom: y + (rect.bottom - y) / scale,\n })\n return { parent: rest(parentRect), trigger: rest(triggerRect), reference: triggerRect }\n}\n\n/** Consume boundary91's resolved footer padding; never subtract the footer again. */\nexport function readMenuBoundaryRect(document: Document, boundary: MenuFloatingBoundary): MenuRect | null {\n const view = document.defaultView\n if (!view) return null\n const viewport = view.visualViewport\n let left = viewport?.offsetLeft ?? 0\n let top = viewport?.offsetTop ?? 0\n let right = left + (viewport?.width ?? document.documentElement.clientWidth)\n let bottom = top + (viewport?.height ?? document.documentElement.clientHeight)\n const element = boundary.collisionBoundary\n if (element?.isConnected && element.ownerDocument === document) {\n const rect = element.getBoundingClientRect()\n const scaleX = element.offsetWidth > 0 ? rect.width / element.offsetWidth : 1\n const scaleY = element.offsetHeight > 0 ? rect.height / element.offsetHeight : 1\n const clientLeft = rect.left + element.clientLeft * scaleX\n const clientTop = rect.top + element.clientTop * scaleY\n left = Math.max(left, clientLeft)\n top = Math.max(top, clientTop)\n right = Math.min(right, clientLeft + element.clientWidth * scaleX)\n bottom = Math.min(bottom, clientTop + element.clientHeight * scaleY)\n }\n const padding = boundary.collisionPadding\n return {\n left: left + (padding.left ?? 0),\n top: top + (padding.top ?? 0),\n right: right - (padding.right ?? 0),\n bottom: bottom - (padding.bottom ?? 0),\n }\n}\n\nconst normalizeLabel = (value: string) => value.replace(/\\s+/g, \" \").trim()\n\nfunction visibleText(element: Element, includeHidden = false): string {\n const view = element.ownerDocument.defaultView\n if (!view) return \"\"\n // Explicit aria-labelledby targets can supply a name while visually hidden.\n if (!includeHidden && (element.hasAttribute(\"hidden\") || element.getAttribute(\"aria-hidden\") === \"true\")) return \"\"\n if ([\"SCRIPT\", \"STYLE\", \"TEMPLATE\"].includes(element.tagName)) return \"\"\n // A row's second line (Sort By over \"Manual\") is its value, not its name\n if (element.hasAttribute(\"data-menu-description\")) return \"\"\n const style = view.getComputedStyle(element)\n if (!includeHidden && (style.display === \"none\" || style.visibility === \"hidden\" || style.visibility === \"collapse\")) return \"\"\n const ownLabel = element.getAttribute(\"aria-label\")\n if (ownLabel?.trim()) return ownLabel\n if (element.tagName === \"IMG\") return element.getAttribute(\"alt\") ?? \"\"\n return Array.from(element.childNodes).map((node) => {\n if (node.nodeType === 3) return node.textContent ?? \"\"\n return node instanceof view.Element ? visibleText(node, includeHidden) : \"\"\n }).join(\"\")\n}\n\nfunction labelReferences(trigger: HTMLElement): Element[] {\n return (trigger.getAttribute(\"aria-labelledby\") ?? \"\").split(/\\s+/).filter(Boolean)\n .map((id) => trigger.ownerDocument.getElementById(id)).filter((element): element is HTMLElement => element !== null)\n}\n\n/** A text snapshot, never a clone of a consumer's rich children or their IDs. */\nexport function readMenuTriggerLabel(trigger: HTMLElement): string {\n const referenced = normalizeLabel(labelReferences(trigger).map((element) => visibleText(element, true)).join(\" \"))\n if (referenced) return referenced\n const labelled = normalizeLabel(trigger.getAttribute(\"aria-label\") ?? \"\")\n if (labelled) return labelled\n return normalizeLabel(visibleText(trigger)) || \"Collapse submenu\"\n}\n\nexport function focusPhoneSubmenuEntry(content: HTMLElement): void {\n const items = Array.from(content.querySelectorAll<HTMLElement>('[role=\"menuitem\"], [role=\"menuitemcheckbox\"], [role=\"menuitemradio\"]'))\n .filter((item) => item.closest('[role=\"menu\"]') === content && !item.hasAttribute(\"data-disabled\") && item.getAttribute(\"aria-disabled\") !== \"true\")\n const target = items.find((item) => !item.hasAttribute(\"data-submenu-collapse\")) ?? items[0]\n target?.focus({ preventScroll: true })\n}\n\nexport function samePhoneSubmenuState(a: PhoneSubmenuState, b: PhoneSubmenuState): boolean {\n return a.mobile === b.mobile && (!a.mobile || !b.mobile ||\n (a.ready === b.ready && a.unavailable === b.unavailable && a.label === b.label && a.sideOffset === b.sideOffset && a.alignOffset === b.alignOffset))\n}\n\n/**\n * Cancels the release of a press that a phone submenu's parent took to collapse the submenu. The parent's rows take\n * presses again a frame after it collapses, and a release over one of them would choose it, as a touch dragged through\n * a menu does (Radix and Reka items click on a release that did not start on them). Only that press's release and the\n * click right after it: a press whose release never comes ends with the next press or when the window loses focus.\n */\nfunction swallowRelease(view: Window, pointerId: number): void {\n let timer: ReturnType<typeof setTimeout> | undefined\n const stop = (event: Event) => {\n event.preventDefault()\n event.stopPropagation()\n }\n const click = (event: Event) => {\n stop(event)\n done()\n }\n const end = (event: PointerEvent) => {\n if (event.pointerId !== pointerId) return\n view.removeEventListener(\"pointerup\", end, true)\n view.removeEventListener(\"pointercancel\", end, true)\n // None comes after a cancelled press\n if (event.type !== \"pointerup\") return done()\n stop(event)\n // The click of that release comes right after it\n view.addEventListener(\"click\", click, true)\n timer = setTimeout(done, 400)\n }\n const done = () => {\n if (timer !== undefined) clearTimeout(timer)\n view.removeEventListener(\"pointerup\", end, true)\n view.removeEventListener(\"pointercancel\", end, true)\n view.removeEventListener(\"click\", click, true)\n view.removeEventListener(\"pointerdown\", done, true)\n view.removeEventListener(\"blur\", done)\n }\n view.addEventListener(\"pointerup\", end, true)\n view.addEventListener(\"pointercancel\", end, true)\n // Added while that press's own pointerdown is past the window, so only a later press ends it\n view.addEventListener(\"pointerdown\", done, true)\n view.addEventListener(\"blur\", done)\n}\n\n/**\n * Own only these Phone attributes/variables. Primitive focus and dismissal stay intact.\n *\n * While a phone submenu stands over its parent the parent is behind it, as in iOS 26 (owner, plan 176): a press on it\n * collapses the submenu (`onParentPress`) and chooses none of its rows, which take no presses (Menu.module.css), and\n * it is hidden from a screen reader. Focus left in it by the press that opened the submenu moves into the submenu, as\n * VoiceOver's moves into an iOS submenu, and a focus that returns to it (the submenu collapsing) shows it again.\n */\nexport function observePhoneSubmenu(\n trigger: HTMLElement,\n content: HTMLElement,\n boundary: MenuFloatingBoundary,\n update: (state: PhoneSubmenuState) => void,\n onParentPress?: () => void,\n): { refresh: () => void; dispose: () => void } {\n const view = content.ownerDocument.defaultView\n if (!view || trigger.ownerDocument !== content.ownerDocument) return { refresh: () => {}, dispose: () => {} }\n const parent = trigger.closest('[role=\"menu\"]')\n if (!(parent instanceof view.HTMLElement)) return { refresh: () => {}, dispose: () => {} }\n const media = typeof view.matchMedia === \"function\" ? view.matchMedia(\"(max-width: 767px)\") : null\n let disposed = false\n let frame: number | undefined\n let focusFrame: number | undefined\n // Whether the submenu has found its place or found there is none, and the focus it found then\n let settled = false\n let focusAtOpen: Element | null = null\n let references: Element[] = []\n const covered = () => parent.hasAttribute(\"data-submenu-over\")\n const showParent = () => {\n if (parent.getAttribute(\"data-submenu-hidden\") === null) return\n parent.removeAttribute(\"data-submenu-hidden\")\n parent.removeAttribute(\"aria-hidden\")\n }\n // A frame after the submenu stands over the parent, once the primitive's focus scopes have taken it as a branch of a\n // modal menu: focus the press left on the row that opened it moves into the submenu, then the parent is hidden\n const hideParent = () => {\n if (focusFrame !== undefined) return\n focusFrame = view.requestAnimationFrame(() => {\n focusFrame = undefined\n if (disposed || !covered()) return\n const focused = content.ownerDocument.activeElement\n // Only the focus the submenu found as it first stood over the parent, untouched since: a keyboard entry, a\n // collapse or a later return to the parent own focus, and a submenu that first had no room does not take it\n if (focusAtOpen && focused === focusAtOpen && parent.contains(focused)) content.focus({ preventScroll: true })\n focusAtOpen = null\n // A hidden element must not hold focus; a parent focused again stays shown\n if (parent.contains(content.ownerDocument.activeElement)) return\n parent.setAttribute(\"data-submenu-hidden\", \"\")\n parent.setAttribute(\"aria-hidden\", \"true\")\n })\n }\n const pressParent = (event: PointerEvent) => {\n // A primary press, a touch or a pen: a secondary button chooses nothing behind the submenu anyway\n if (event.button !== 0 || !covered() || content.contains(event.target as Node)) return\n // It goes on to the primitives' layers, which mark a press inside a menu until it reaches the document; its rows\n // take no pointer, and the release and click that would choose one are cancelled\n event.preventDefault()\n swallowRelease(view, event.pointerId)\n onParentPress?.()\n }\n const focusParent = () => showParent()\n // Its rows take no pointer (Menu.module.css), so the pointer leaves the row that opened the submenu once the submenu\n // covers it: that leave must not move focus back to the parent, which would close the submenu\n const leaveParent = (event: PointerEvent) => {\n if (covered() && !content.contains(event.target as Node)) event.stopPropagation()\n }\n parent.addEventListener(\"pointerdown\", pressParent, true)\n parent.addEventListener(\"focusin\", focusParent, true)\n parent.addEventListener(\"pointerout\", leaveParent, true)\n parent.addEventListener(\"pointerleave\", leaveParent, true)\n const setVariable = (name: string, value: number) => {\n const next = `${round(Math.max(0, value))}px`\n if (content.style.getPropertyValue(name) !== next) content.style.setProperty(name, next)\n }\n const clearPhone = () => {\n content.removeAttribute(\"data-submenu-phone\")\n content.removeAttribute(\"data-submenu-positioned\")\n content.removeAttribute(\"data-submenu-unavailable\")\n content.style.removeProperty(\"--menu-phone-max-width\")\n content.style.removeProperty(\"--menu-phone-max-height\")\n }\n const labelObserver = new view.MutationObserver(() => schedule())\n const updateLabelTargets = () => {\n const next = labelReferences(trigger)\n if (next.length === references.length && next.every((element, index) => element === references[index])) return\n references = next\n labelObserver.disconnect()\n for (const element of references) {\n labelObserver.observe(element, { childList: true, characterData: true, subtree: true, attributes: true })\n // A localized label can be replaced while retaining its public ID.\n if (element.parentElement) labelObserver.observe(element.parentElement, { childList: true })\n }\n }\n const refresh = () => {\n if (disposed) return\n // A narrow window, or a PhoneLayout or phone Dialog at any width\n if (!isPhoneLayout(content)) {\n clearPhone()\n parent.removeAttribute(\"data-submenu-over\")\n showParent()\n update({ mobile: false })\n return\n }\n content.setAttribute(\"data-submenu-phone\", \"\")\n updateLabelTargets()\n const label = readMenuTriggerLabel(trigger)\n const available = readMenuBoundaryRect(content.ownerDocument, boundary)\n if (!available) return\n setVariable(\"--menu-phone-max-width\", available.right - available.left)\n setVariable(\"--menu-phone-max-height\", available.bottom - available.top)\n const style = view.getComputedStyle(content)\n const width = content.offsetWidth\n const height = content.offsetHeight\n const hasHeader = !!content.querySelector(\"[data-submenu-collapse]\")\n const resting = readRestingMenuRects(parent, trigger)\n const placement = solvePhoneSubmenuPlacement({\n boundary: available,\n trigger: resting.trigger,\n parent: resting.parent,\n reference: resting.reference,\n width,\n height,\n paddingTop: Number.parseFloat(style.paddingTop) || 0,\n direction: style.direction === \"rtl\" ? \"rtl\" : \"ltr\",\n })\n // Wait for the header and real geometry, never flash the desktop cascade.\n const ready = !!placement && hasHeader\n // Header/zero-layout are still pending. After the CSS caps and header are\n // present, an empty boundary or measured overflow has no valid placement.\n const emptyBoundary = available.right <= available.left || available.bottom <= available.top\n const unavailable = hasHeader && !placement && (emptyBoundary || (width > 0 && height > 0))\n if (ready) content.setAttribute(\"data-submenu-positioned\", \"\")\n else content.removeAttribute(\"data-submenu-positioned\")\n if (unavailable) content.setAttribute(\"data-submenu-unavailable\", \"\")\n else content.removeAttribute(\"data-submenu-unavailable\")\n // The parent steps back while the submenu stands over it (Menu.module.css), not while it has nowhere to stand\n if ((ready || unavailable) && !settled) {\n settled = true\n if (ready) focusAtOpen = content.ownerDocument.activeElement\n }\n if (ready) {\n parent.setAttribute(\"data-submenu-over\", \"\")\n hideParent()\n } else {\n parent.removeAttribute(\"data-submenu-over\")\n showParent()\n }\n update({ mobile: true, ready, unavailable, label, ...(placement ?? { sideOffset: 0, alignOffset: 0 }) })\n // A parent's enter transform moves its child trigger without resizing it.\n // Follow only that running transition, not an idle menu forever.\n if (typeof parent.getAnimations === \"function\" && parent.getAnimations().some((animation) => animation.playState === \"running\")) schedule()\n }\n const schedule = () => {\n if (!disposed && frame === undefined) frame = view.requestAnimationFrame(() => { frame = undefined; refresh() })\n }\n const resize = typeof view.ResizeObserver === \"function\" ? new view.ResizeObserver(schedule) : undefined\n for (const element of [trigger, parent, content, boundary.collisionBoundary]) if (element) resize?.observe(element)\n const mutations = new view.MutationObserver(schedule)\n mutations.observe(trigger, { attributes: true, characterData: true, childList: true, subtree: true })\n mutations.observe(parent, { attributes: true, attributeFilter: [\"class\", \"style\"] })\n if (parent.parentElement) mutations.observe(parent.parentElement, { attributes: true, attributeFilter: [\"class\", \"style\", \"data-entering\", \"data-entering-active\"] })\n media?.addEventListener(\"change\", refresh)\n view.addEventListener(\"scroll\", schedule, true)\n view.addEventListener(\"resize\", schedule)\n view.visualViewport?.addEventListener(\"scroll\", schedule)\n view.visualViewport?.addEventListener(\"resize\", schedule)\n refresh()\n return {\n refresh,\n dispose: () => {\n disposed = true\n if (frame !== undefined) view.cancelAnimationFrame(frame)\n if (focusFrame !== undefined) view.cancelAnimationFrame(focusFrame)\n parent.removeEventListener(\"pointerdown\", pressParent, true)\n parent.removeEventListener(\"focusin\", focusParent, true)\n parent.removeEventListener(\"pointerout\", leaveParent, true)\n parent.removeEventListener(\"pointerleave\", leaveParent, true)\n showParent()\n resize?.disconnect()\n mutations.disconnect()\n labelObserver.disconnect()\n media?.removeEventListener(\"change\", refresh)\n view.removeEventListener(\"scroll\", schedule, true)\n view.removeEventListener(\"resize\", schedule)\n view.visualViewport?.removeEventListener(\"scroll\", schedule)\n view.visualViewport?.removeEventListener(\"resize\", schedule)\n // Retained transition nodes keep their last geometry through exit, and a parent that leaves with its submenu\n // leaves stepped back. A choice in the submenu closes it before the whole menu starts to leave, so the parent\n // steps forward a frame later, unless by then it is leaving or another of its submenus stands over it.\n view.requestAnimationFrame(() => {\n if (parent.closest(\"[data-exiting]\") || parent.getAttribute(\"data-state\") === \"closed\") return\n if (parent.querySelector('[aria-expanded=\"true\"]')) return\n parent.removeAttribute(\"data-submenu-over\")\n })\n },\n }\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { isPhoneLayout, PHONE_LAYOUT_SCOPE } from "./phoneLayout.js";
1
2
  /**
2
3
  * On a phone a menu grows out of the control that opens it and covers it, as iOS 26 menus do: the panel's top is the
3
4
  * control's top, or its bottom when the menu opens upward, and its aligned edge is the control's edge (iOS-menu
@@ -18,11 +19,16 @@ export function observeMenuTriggerCover(trigger, onChange) {
18
19
  let last;
19
20
  const measure = () => {
20
21
  let cover = null;
21
- if (media.matches) {
22
+ // A narrow window, or a PhoneLayout or phone Dialog at any width
23
+ if (isPhoneLayout(trigger)) {
22
24
  const rect = trigger.getBoundingClientRect();
23
- // The visible part of the screen: the layout viewport less a keyboard or a pinch zoom
25
+ // The visible part of the screen: the layout viewport less a keyboard or a pinch zoom, or the box of a
26
+ // PhoneLayout, which is the phone's screen (a phone Dialog's own scope has no box: the window is its screen)
24
27
  const viewport = view.visualViewport;
25
- const middle = (viewport?.offsetTop ?? 0) + (viewport?.height ?? view.innerHeight) / 2;
28
+ const screen = trigger.closest(PHONE_LAYOUT_SCOPE)?.getBoundingClientRect();
29
+ const middle = screen && screen.height > 0
30
+ ? Math.max(screen.top, viewport?.offsetTop ?? 0) / 2 + Math.min(screen.bottom, (viewport?.offsetTop ?? 0) + (viewport?.height ?? view.innerHeight)) / 2
31
+ : (viewport?.offsetTop ?? 0) + (viewport?.height ?? view.innerHeight) / 2;
26
32
  // The layout height: a pressed control may be scaled, and the panel covers its resting box
27
33
  cover = { sideOffset: -trigger.offsetHeight, side: rect.top + rect.height / 2 > middle ? "top" : "bottom" };
28
34
  }
@@ -50,7 +56,7 @@ export function observeMenuTriggerCover(trigger, onChange) {
50
56
  export function ignoreReleaseOverTrigger(trigger, pointerId) {
51
57
  const view = trigger.ownerDocument.defaultView;
52
58
  // Only a phone menu covers its trigger; elsewhere the gap keeps the items clear of the pointer
53
- if (!view || typeof view.matchMedia !== "function" || !view.matchMedia("(max-width: 767px)").matches)
59
+ if (!view || !isPhoneLayout(trigger))
54
60
  return;
55
61
  const release = (event) => {
56
62
  if (event.pointerId !== pointerId)
@@ -1 +1 @@
1
- {"version":3,"file":"menuTriggerCover.js","sourceRoot":"","sources":["../../../src/lib/menuTriggerCover.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAAoB,EAAE,QAAkD;IAC9G,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,WAAW,CAAA;IAC9C,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;QACnD,QAAQ,CAAC,IAAI,CAAC,C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AAI,CAAC,gBAAgB,CAAC,eAAe,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;AACvD,CAAC","sourcesContent":["/** Where a phone menu stands over its trigger: the side offset that covers it, and the side it opens to. */\nexport type MenuTriggerCover = { sideOffset: number; side: \"top\" | \"bottom\" }\n\n/**\n * On a phone a menu grows out of the control that opens it and covers it, as iOS 26 menus do: the panel's top is the\n * control's top, or its bottom when the menu opens upward, and its aligned edge is the control's edge (iOS-menu\n * IMG_5657 and IMG_5654, the More button of a top bar; IMG_5658, a button of a group; IMG_5649, the value of a form\n * row; IMG_5675 opens upward over its row). It opens toward the larger part of the screen: downward from a control in\n * the upper half, upward from one in the lower half even when it would fit below (IMG_5688, the Icon and List Size\n * row of Files' View Options; IMG_5687, IMG_5689, and IMG_5693 from a bottom bar). Reports the side offset that puts\n * the panel there, minus the control's height, and that side, while the screen is a phone, and `null` on a larger one,\n * where the menu keeps its gap below the control.\n */\nexport function observeMenuTriggerCover(trigger: HTMLElement, onChange: (cover: MenuTriggerCover | null) => void): () => void {\n const view = trigger.ownerDocument.defaultView\n if (!view || typeof view.matchMedia !== \"function\") {\n onChange(null)\n return () => undefined\n }\n const media = view.matchMedia(\"(max-width: 767px)\")\n let last: string | undefined\n const measure = () => {\n let cover: MenuTriggerCover | null = null\n if (media.matches) {\n const rect = trigger.getBoundingClientRect()\n // The visible part of the screen: the layout viewport less a keyboard or a pinch zoom\n const viewport = view.visualViewport\n const middle = (viewport?.offsetTop ?? 0) + (viewport?.height ?? view.innerHeight) / 2\n // The layout height: a pressed control may be scaled, and the panel covers its resting box\n cover = { sideOffset: -trigger.offsetHeight, side: rect.top + rect.height / 2 > middle ? \"top\" : \"bottom\" }\n }\n const key = cover ? `${cover.sideOffset} ${cover.side}` : \"\"\n if (key === last) return\n last = key\n onChange(cover)\n }\n measure()\n const resize = typeof ResizeObserver === \"undefined\" ? undefined : new ResizeObserver(measure)\n resize?.observe(trigger)\n media.addEventListener?.(\"change\", measure)\n return () => {\n resize?.disconnect()\n media.removeEventListener?.(\"change\", measure)\n }\n}\n\n/**\n * A mouse opens a menu when its button goes down, so on a phone-wide window the menu that covers the trigger is under\n * the pointer when the button comes up, and that release would choose the item there. Cancels the release of the press\n * that opened the menu while it is still over the trigger; a press dragged off the trigger onto an item still chooses\n * it, as a touch dragged through an iOS menu does.\n */\nexport function ignoreReleaseOverTrigger(trigger: HTMLElement, pointerId: number): void {\n const view = trigger.ownerDocument.defaultView\n // Only a phone menu covers its trigger; elsewhere the gap keeps the items clear of the pointer\n if (!view || typeof view.matchMedia !== \"function\" || !view.matchMedia(\"(max-width: 767px)\").matches) return\n const release = (event: PointerEvent) => {\n if (event.pointerId !== pointerId) return\n view.removeEventListener(\"pointerup\", release, true)\n view.removeEventListener(\"pointercancel\", release, true)\n if (event.type !== \"pointerup\") return\n const rect = trigger.getBoundingClientRect()\n if (event.clientX >= rect.left && event.clientX <= rect.right && event.clientY >= rect.top && event.clientY <= rect.bottom) {\n event.preventDefault()\n }\n }\n view.addEventListener(\"pointerup\", release, true)\n view.addEventListener(\"pointercancel\", release, true)\n}\n"]}
1
+ {"version":3,"file":"menuTriggerCover.js","sourceRoot":"","sources":["../../../src/lib/menuTriggerCover.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAKjE;;;;;;;;;GASG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAAoB,EAAE,QAAkD;IAC9G,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,WAAW,CAAA;IAC9C,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;QACnD,QAAQ,CAAC,IAAI,CAAC,CAAA;QACd,OAAO,GAAG,EAAE,CAAC,SAAS,CAAA;IACxB,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAA;IACnD,IAAI,IAAwB,CAAA;IAC5B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AAK,IAAI,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,GAAG,IAAI,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAC3H,KAAK,CAAC,cAAc,EAAE,CAAA;QACxB,CAAC;IACH,CAAC,CAAA;IACD,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;IACjD,IAAI,CAAC,gBAAgB,CAAC,eAAe,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;AACvD,CAAC","sourcesContent":["import { isPhoneLayout, PHONE_LAYOUT_SCOPE } from \"./phoneLayout\"\n\n/** Where a phone menu stands over its trigger: the side offset that covers it, and the side it opens to. */\nexport type MenuTriggerCover = { sideOffset: number; side: \"top\" | \"bottom\" }\n\n/**\n * On a phone a menu grows out of the control that opens it and covers it, as iOS 26 menus do: the panel's top is the\n * control's top, or its bottom when the menu opens upward, and its aligned edge is the control's edge (iOS-menu\n * IMG_5657 and IMG_5654, the More button of a top bar; IMG_5658, a button of a group; IMG_5649, the value of a form\n * row; IMG_5675 opens upward over its row). It opens toward the larger part of the screen: downward from a control in\n * the upper half, upward from one in the lower half even when it would fit below (IMG_5688, the Icon and List Size\n * row of Files' View Options; IMG_5687, IMG_5689, and IMG_5693 from a bottom bar). Reports the side offset that puts\n * the panel there, minus the control's height, and that side, while the screen is a phone, and `null` on a larger one,\n * where the menu keeps its gap below the control.\n */\nexport function observeMenuTriggerCover(trigger: HTMLElement, onChange: (cover: MenuTriggerCover | null) => void): () => void {\n const view = trigger.ownerDocument.defaultView\n if (!view || typeof view.matchMedia !== \"function\") {\n onChange(null)\n return () => undefined\n }\n const media = view.matchMedia(\"(max-width: 767px)\")\n let last: string | undefined\n const measure = () => {\n let cover: MenuTriggerCover | null = null\n // A narrow window, or a PhoneLayout or phone Dialog at any width\n if (isPhoneLayout(trigger)) {\n const rect = trigger.getBoundingClientRect()\n // The visible part of the screen: the layout viewport less a keyboard or a pinch zoom, or the box of a\n // PhoneLayout, which is the phone's screen (a phone Dialog's own scope has no box: the window is its screen)\n const viewport = view.visualViewport\n const screen = trigger.closest(PHONE_LAYOUT_SCOPE)?.getBoundingClientRect()\n const middle = screen && screen.height > 0\n ? Math.max(screen.top, viewport?.offsetTop ?? 0) / 2 + Math.min(screen.bottom, (viewport?.offsetTop ?? 0) + (viewport?.height ?? view.innerHeight)) / 2\n : (viewport?.offsetTop ?? 0) + (viewport?.height ?? view.innerHeight) / 2\n // The layout height: a pressed control may be scaled, and the panel covers its resting box\n cover = { sideOffset: -trigger.offsetHeight, side: rect.top + rect.height / 2 > middle ? \"top\" : \"bottom\" }\n }\n const key = cover ? `${cover.sideOffset} ${cover.side}` : \"\"\n if (key === last) return\n last = key\n onChange(cover)\n }\n measure()\n const resize = typeof ResizeObserver === \"undefined\" ? undefined : new ResizeObserver(measure)\n resize?.observe(trigger)\n media.addEventListener?.(\"change\", measure)\n return () => {\n resize?.disconnect()\n media.removeEventListener?.(\"change\", measure)\n }\n}\n\n/**\n * A mouse opens a menu when its button goes down, so on a phone-wide window the menu that covers the trigger is under\n * the pointer when the button comes up, and that release would choose the item there. Cancels the release of the press\n * that opened the menu while it is still over the trigger; a press dragged off the trigger onto an item still chooses\n * it, as a touch dragged through an iOS menu does.\n */\nexport function ignoreReleaseOverTrigger(trigger: HTMLElement, pointerId: number): void {\n const view = trigger.ownerDocument.defaultView\n // Only a phone menu covers its trigger; elsewhere the gap keeps the items clear of the pointer\n if (!view || !isPhoneLayout(trigger)) return\n const release = (event: PointerEvent) => {\n if (event.pointerId !== pointerId) return\n view.removeEventListener(\"pointerup\", release, true)\n view.removeEventListener(\"pointercancel\", release, true)\n if (event.type !== \"pointerup\") return\n const rect = trigger.getBoundingClientRect()\n if (event.clientX >= rect.left && event.clientX <= rect.right && event.clientY >= rect.top && event.clientY <= rect.bottom) {\n event.preventDefault()\n }\n }\n view.addEventListener(\"pointerup\", release, true)\n view.addEventListener(\"pointercancel\", release, true)\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import s from "@plexui/styles/components/Sortable/Sortable.module.css";
2
+ import { CONTEXT_MENU_HOLD, CONTEXT_MENU_LONG_PRESS_SLOP, heldContextMenu } from "./contextMenuHold.js";
2
3
  const START_DISTANCE = 4;
3
4
  const TOUCH_HOLD = 200;
4
5
  // Long enough to pass over a target on the way to another
@@ -217,7 +218,11 @@ function startDrag(event, list, source, layout, immediate, commit, link) {
217
218
  const touch = event.pointerType === "touch" && !immediate;
218
219
  const origin = { x: event.clientX, y: event.clientY };
219
220
  const pointer = { ...origin };
220
- const holdTimer = touch ? setTimeout(begin, TOUCH_HOLD) : undefined;
221
+ // An item with a context menu shares one hold with it, as an iOS preview: the drag waits for the menu, and once
222
+ // the menu stands the finger moving on closes it and drags the item
223
+ const menu = touch ? heldContextMenu(event.target, source) : undefined;
224
+ let lifted;
225
+ const holdTimer = touch && !menu ? setTimeout(begin, TOUCH_HOLD) : undefined;
221
226
  const style = getComputedStyle(list);
222
227
  const part = parseFloat(layout === "grid" ? style.columnGap : style.rowGap) ? PART : 0;
223
228
  const scroller = scrollParent(list);
@@ -228,6 +233,15 @@ function startDrag(event, list, source, layout, immediate, commit, link) {
228
233
  window.addEventListener("pointerup", onUp);
229
234
  window.addEventListener("pointercancel", onCancel);
230
235
  window.addEventListener("blur", cancel);
236
+ menu?.addEventListener(CONTEXT_MENU_HOLD, onMenuHold);
237
+ function onMenuHold(holdEvent) {
238
+ const hold = holdEvent.detail;
239
+ if (hold.pointerId !== pointerId || lifted || drag)
240
+ return;
241
+ lifted = { x: pointer.x, y: pointer.y, close: hold.close };
242
+ // The finger now holds the preview: moving it drags, the page under it stays
243
+ window.addEventListener("touchmove", blockScroll, { passive: false });
244
+ }
231
245
  function onMove(event) {
232
246
  if (event.pointerId !== pointerId)
233
247
  return;
@@ -240,7 +254,21 @@ function startDrag(event, list, source, layout, immediate, commit, link) {
240
254
  pointer.y = clientY;
241
255
  if (drag)
242
256
  return;
243
- const moved = Math.hypot(clientX - origin.x, clientY - origin.y) >= START_DISTANCE;
257
+ if (lifted) {
258
+ if (Math.hypot(clientX - lifted.x, clientY - lifted.y) < START_DISTANCE)
259
+ return;
260
+ lifted.close();
261
+ begin();
262
+ return;
263
+ }
264
+ const travel = Math.hypot(clientX - origin.x, clientY - origin.y);
265
+ // Before the menu opens, a touch that moves as far as the menu lets it scrolls
266
+ if (menu) {
267
+ if (travel > CONTEXT_MENU_LONG_PRESS_SLOP)
268
+ stopListening();
269
+ return;
270
+ }
271
+ const moved = travel >= START_DISTANCE;
244
272
  if (moved && touch)
245
273
  stopListening();
246
274
  else if (moved)
@@ -265,6 +293,7 @@ function startDrag(event, list, source, layout, immediate, commit, link) {
265
293
  }
266
294
  function stopListening() {
267
295
  clearTimeout(holdTimer);
296
+ menu?.removeEventListener(CONTEXT_MENU_HOLD, onMenuHold);
268
297
  window.removeEventListener("pointermove", onMove);
269
298
  window.removeEventListener("pointerup", onUp);
270
299
  window.removeEventListener("pointercancel", onCancel);