You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2026/08/24 16:10:02 UTC
(juneau) branch master updated: Land card-grid observers that stop polls when an ancestor tab panel is hidden, and wire header/avatar MENU onto the shared views pushLayer stack.
This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new ef3a8b08c4 Land card-grid observers that stop polls when an ancestor tab panel is hidden, and wire header/avatar MENU onto the shared views pushLayer stack.
ef3a8b08c4 is described below
commit ef3a8b08c4dbf3ee07bb24e35f78e66c3bafd3b6
Author: James Bognar <ja...@apache.org>
AuthorDate: Mon Aug 24 12:09:51 2026 -0400
Land card-grid observers that stop polls when an ancestor tab panel is hidden, and wire header/avatar MENU onto the shared views pushLayer stack.
Menus were still disabled stubs; they now emit working lists that portal through 445h's one layer stack instead of a chrome-local overlay.
---
.../resources/org/apache/juneau/console/chrome.css | 35 +++-
.../juneau/rest/server/views/AppHeaderTable.java | 96 +++++++++--
.../org/apache/juneau/views/juneau-cards.js | 42 ++++-
.../org/apache/juneau/views/juneau-chrome.js | 158 ++++++++++++++++--
.../server/views/AppHeaderTable_Emit_Test.java | 67 +++++---
.../rest/server/views/ViewsJs_Cards_Test.java | 22 +++
.../rest/server/views/ViewsJs_ChromeMenu_Test.java | 183 +++++++++++++++++++++
.../rest/server/views/ViewsJs_Chrome_Test.java | 44 +++--
.../src/test/js/cards-browser.cjs | 24 +++
.../src/test/js/chrome-menu.cjs | 150 +++++++++++++++++
.../src/test/js/header.cjs | 44 ++++-
11 files changed, 790 insertions(+), 75 deletions(-)
diff --git a/juneau-rest/juneau-rest-server-console-ui/src/main/resources/org/apache/juneau/console/chrome.css b/juneau-rest/juneau-rest-server-console-ui/src/main/resources/org/apache/juneau/console/chrome.css
index 18105465fc..26d59e96dd 100644
--- a/juneau-rest/juneau-rest-server-console-ui/src/main/resources/org/apache/juneau/console/chrome.css
+++ b/juneau-rest/juneau-rest-server-console-ui/src/main/resources/org/apache/juneau/console/chrome.css
@@ -239,7 +239,8 @@ a:hover { text-decoration: underline; }
.jc-avatar-status-busy::after { background-color: var(--jc-tag-red-text); }
.jc-avatar-status-offline::after { background-color: var(--jc-tag-neutral-text); }
-/* Menu surface skeleton - kept hidden; the trigger stays disabled until 445h flips this on via the shared layer. */
+/* Menu surface - display:none until juneau-chrome.js portals it onto the shared views layer stack (445h), which
+ sets position:fixed + the cell-anchored top/left and toggles display back on. Inert with JS off. */
.jc-menu {
display: none;
min-width: 160px;
@@ -248,6 +249,38 @@ a:hover { text-decoration: underline; }
color: var(--jc-text);
border: 1px solid var(--jc-border);
border-radius: var(--jc-radius);
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
+}
+
+/* A single row: a same-origin <a href> link or a SAFE host-dispatch <button>; both share this chrome. */
+.jc-menu-item {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ width: 100%;
+ box-sizing: border-box;
+ padding: 6px 14px;
+ font-size: 0.8125rem;
+ text-align: left;
+ color: var(--jc-text);
+ background-color: transparent;
+ border: none;
+ cursor: pointer;
+ text-decoration: none;
+}
+
+.jc-menu-item:hover,
+.jc-menu-item:focus {
+ background-color: var(--jc-accent-wash);
+ text-decoration: none;
+ outline: none;
+}
+
+/* An inert separator between item groups. */
+.jc-menu-divider {
+ height: 1px;
+ margin: 4px 0;
+ background-color: var(--jc-border);
}
/* ==========================================================================
diff --git a/juneau-rest/juneau-rest-server-views/src/main/java/org/apache/juneau/rest/server/views/AppHeaderTable.java b/juneau-rest/juneau-rest-server-views/src/main/java/org/apache/juneau/rest/server/views/AppHeaderTable.java
index 4a8c0c3d61..f0cff88991 100644
--- a/juneau-rest/juneau-rest-server-views/src/main/java/org/apache/juneau/rest/server/views/AppHeaderTable.java
+++ b/juneau-rest/juneau-rest-server-views/src/main/java/org/apache/juneau/rest/server/views/AppHeaderTable.java
@@ -43,12 +43,18 @@ import org.apache.juneau.rest.server.widgets.*;
* hydrates the trusted first-party SVG client-side (the single allow-listed {@code innerHTML} sink). This emitter
* never emits {@code .jc-nav}/{@code .jc-nav-tab} (445f standing nav rule).
*
- * <h5 class='section'>Menus wait on {@code [TODO-445h]} (M1 B):</h5>
+ * <h5 class='section'>Working menus on the shared views layer stack:</h5>
* <p>
- * A {@link Behavior#MENU} trigger is emitted <b>disabled</b> ({@code disabled} + {@code aria-disabled="true"}) and its
- * item list is <b>omitted</b> — no {@code <details>} disclosure, no fake {@code role="menu"} ARIA that would
- * require the (not-yet-shipped) layer manager. Chips / {@link Behavior#LINK} / {@link Behavior#SAFE} are fully
- * functional.
+ * A {@link Behavior#MENU} trigger (a header action or an avatar chip) is emitted as an <b>enabled</b>
+ * {@code <button type="button">} carrying real menu ARIA ({@code aria-haspopup="menu"}, {@code aria-expanded="false"},
+ * {@code aria-controls="<menuId>"}), and its single-level item list is emitted as a hidden sibling
+ * {@code <div class="jc-menu" role="menu">} of {@code .jc-menu-item} rows ({@code <a>} for {@link MenuItem#href}
+ * links, {@code <button>} for {@link MenuItem#safe} host-dispatch items) and {@code .jc-menu-divider}
+ * {@code role="separator"} rows. There is <b>no</b> {@code <details>} disclosure: {@code juneau-chrome.js} portals the
+ * list onto the shared {@code juneau-views.js} {@code pushLayer} stack on open (nested popups / z-index / Escape /
+ * light-dismiss are owned by that one stack — this emitter invents no chrome-local overlay scheme). The list is
+ * inert with JS off (it is {@code display:none} chrome, never a working fake disclosure). Chips /
+ * {@link Behavior#LINK} / {@link Behavior#SAFE} are fully functional.
*
* @since 10.0.0
*/
@@ -84,6 +90,13 @@ public class AppHeaderTable {
/** Marker attribute on the avatar trigger. */
public static final String AVATAR_MARKER = "data-juneau-avatar";
+ /**
+ * Prefix of a menu list's element id ({@code juneau-menu:<headerId>:<actionId>}, or
+ * {@code juneau-menu:<headerId>:avatar} for the avatar chip's menu). The MENU trigger's {@code aria-controls}
+ * points at this id, and {@code juneau-chrome.js} resolves the list to portal onto the shared views layer stack.
+ */
+ public static final String MENU_ID_PREFIX = "juneau-menu:";
+
/**
* Attribute carrying the header's same-origin demand-refresh endpoint (emitted only when {@code refreshUrl} is set).
*
@@ -119,10 +132,16 @@ public class AppHeaderTable {
children.add(emitBrand(header.brand));
var actionKids = new ArrayList<>();
if (header.actions != null)
- for (var a : header.actions)
- actionKids.add(emitAction(a));
- if (header.avatar != null)
- actionKids.add(emitAvatar(header.avatar));
+ for (var a : header.actions) {
+ actionKids.add(emitAction(a, header.id));
+ if (a.behavior == Behavior.MENU)
+ actionKids.add(emitMenu(menuId(header.id, a.id), a.menu));
+ }
+ if (header.avatar != null) {
+ actionKids.add(emitAvatar(header.avatar, header.id));
+ if (header.avatar.menu != null && ! header.avatar.menu.isEmpty())
+ actionKids.add(emitMenu(menuId(header.id, "avatar"), header.avatar.menu));
+ }
if (! actionKids.isEmpty())
children.add(div(actionKids.toArray()).class_("jc-header-actions"));
@@ -171,7 +190,7 @@ public class AppHeaderTable {
return div(kids.toArray()).class_("jc-brand");
}
- private static HtmlElement emitAction(HeaderAction a) {
+ private static HtmlElement emitAction(HeaderAction a, String headerId) {
var behavior = a.behavior.name().toLowerCase(Locale.ROOT);
var inner = new ArrayList<>();
inner.add(span().class_("jc-icon").attr("aria-hidden", "true"));
@@ -199,8 +218,10 @@ public class AppHeaderTable {
if (a.behavior == Behavior.SAFE)
el.attr(SAFE_ATTR, a.safe);
if (a.behavior == Behavior.MENU) {
- // M1 B: menus wait on 445h - disable the trigger and omit the list (no fake disclosure).
- el.attr("disabled", "disabled").attr("aria-disabled", "true");
+ // A working, enabled MENU trigger: juneau-chrome.js portals the aria-controls'd list onto the views stack.
+ el.attr("aria-haspopup", "menu")
+ .attr("aria-expanded", "false")
+ .attr("aria-controls", menuId(headerId, a.id));
}
return el;
}
@@ -228,7 +249,7 @@ public class AppHeaderTable {
return Integer.toString(count);
}
- private static HtmlElement emitAvatar(AvatarChip avatar) {
+ private static HtmlElement emitAvatar(AvatarChip avatar, String headerId) {
var cls = new StringBuilder("jc-avatar");
if (avatar.status != null)
cls.append(" jc-avatar-status-").append(avatar.status.name().toLowerCase(Locale.ROOT));
@@ -243,13 +264,14 @@ public class AppHeaderTable {
}
if (avatar.menu != null && ! avatar.menu.isEmpty()) {
- // M1 B: an avatar with a menu is a menu trigger - disabled until 445h, list omitted (never a dead button).
+ // An avatar with a menu is an enabled menu trigger; juneau-chrome.js portals its list onto the views stack.
return button("button", kids.toArray()).class_(cls.toString())
.attr(AVATAR_MARKER, "1")
.attr(BEHAVIOR_ATTR, "menu")
.attr("aria-label", avatar.displayName)
- .attr("disabled", "disabled")
- .attr("aria-disabled", "true");
+ .attr("aria-haspopup", "menu")
+ .attr("aria-expanded", "false")
+ .attr("aria-controls", menuId(headerId, "avatar"));
}
// No menu: a non-interactive identity chip, not a dead <button>.
return span(kids.toArray()).class_(cls.toString())
@@ -257,4 +279,46 @@ public class AppHeaderTable {
.attr("role", "img")
.attr("aria-label", avatar.displayName);
}
+
+ /** The stable element id of an action's / the avatar's attached menu list ({@code juneau-menu:<headerId>:<key>}). */
+ private static String menuId(String headerId, String key) {
+ return MENU_ID_PREFIX + headerId + ":" + key;
+ }
+
+ /**
+ * Emits a single-level attached menu as a hidden {@code <div class="jc-menu" role="menu">} of {@code .jc-menu-item}
+ * rows and {@code .jc-menu-divider} separators. The list ships {@code display:none} (chrome CSS) and inert with JS
+ * off; {@code juneau-chrome.js} portals it onto the shared views layer stack when its trigger opens it. Every human
+ * label is a text child (serializer entity-escapes it); no label or token is ever concatenated into markup.
+ */
+ private static Div emitMenu(String menuId, List<MenuItem> items) {
+ var rows = new ArrayList<>();
+ for (var mi : items)
+ rows.add(emitMenuItem(mi));
+ return div(rows.toArray()).class_("jc-menu").id(menuId).attr("role", "menu");
+ }
+
+ /** Emits one menu row: a divider separator, a link {@code <a href>}, or a SAFE host-dispatch {@code <button>}. */
+ private static HtmlElement emitMenuItem(MenuItem mi) {
+ if (mi.isDivider())
+ return div().class_("jc-menu-divider").attr("role", "separator");
+
+ var kids = new ArrayList<>();
+ if (mi.icon != null && ! mi.icon.isBlank())
+ kids.add(span().class_("jc-icon").attr("aria-hidden", "true"));
+ kids.add(mi.label); // plain text child - serializer entity-escapes it
+
+ if (mi.href != null && ! mi.href.isBlank()) {
+ var el = a(mi.href, kids.toArray()).class_("jc-menu-item").attr("role", "menuitem");
+ if (mi.icon != null && ! mi.icon.isBlank())
+ el.attr(ICON_ATTR, mi.icon);
+ return el;
+ }
+ var el = button("button", kids.toArray()).class_("jc-menu-item")
+ .attr("role", "menuitem")
+ .attr(SAFE_ATTR, mi.safe);
+ if (mi.icon != null && ! mi.icon.isBlank())
+ el.attr(ICON_ATTR, mi.icon);
+ return el;
+ }
}
diff --git a/juneau-rest/juneau-rest-server-views/src/main/resources/org/apache/juneau/views/juneau-cards.js b/juneau-rest/juneau-rest-server-views/src/main/resources/org/apache/juneau/views/juneau-cards.js
index a41a39c77a..e7cdcaeabb 100644
--- a/juneau-rest/juneau-rest-server-views/src/main/resources/org/apache/juneau/views/juneau-cards.js
+++ b/juneau-rest/juneau-rest-server-views/src/main/resources/org/apache/juneau/views/juneau-cards.js
@@ -164,18 +164,47 @@
banner.hidden = false;
}
- /** True when the element is hidden by its own `hidden`/`display:none` or by an enclosing pages tab that is (in-page tab hiding is not document.hidden). */
+ /** True when `cls` is present in the element's space-separated class attribute (classList-free so it also works against the Node harness DOM). */
+ function hasClass(n, cls) {
+ if (!n || !n.getAttribute) return false;
+ return (" " + (n.getAttribute("class") || "") + " ").indexOf(" " + cls + " ") >= 0;
+ }
+
+ /**
+ * True when the card is hidden by ANY of: its own `hidden` / inline `display:none`; an enclosing pages tab panel
+ * (`.jc-panel` / `.jc-subpanel`) that LACKS `.jc-active` - juneau-pages.js toggles `.jc-active` on the ancestor
+ * panel and juneau-views.css keeps an inactive panel at `display:none`, and that toggle never touches this card's
+ * own subtree; or a computed `display:none` on any ancestor (defense for other CSS-hidden cases, skipped where
+ * getComputedStyle is absent, e.g. the Node harness). In-page tab hiding is NOT document.hidden, so it is
+ * checked here rather than via the visibilitychange path.
+ */
function isElementHidden(node) {
let n = node;
while (n && n.nodeType === 1) {
if (n.hidden === true) return true;
const style = n.getAttribute && n.getAttribute("style");
if (style && /display\s*:\s*none/i.test(style)) return true;
+ if ((hasClass(n, "jc-panel") || hasClass(n, "jc-subpanel")) && !hasClass(n, "jc-active")) return true;
+ if (window.getComputedStyle) {
+ const cs = window.getComputedStyle(n);
+ if (cs && cs.display === "none") return true;
+ }
n = n.parentNode;
}
return false;
}
+ /** The ancestor pages tab panels (`.jc-panel` / `.jc-subpanel`) above a node, nearest first - the elements juneau-pages.js toggles `.jc-active` on. */
+ function ancestorPanels(node) {
+ const panels = [];
+ let n = node ? node.parentNode : null;
+ while (n && n.nodeType === 1) {
+ if (hasClass(n, "jc-panel") || hasClass(n, "jc-subpanel")) panels.push(n);
+ n = n.parentNode;
+ }
+ return panels;
+ }
+
/** Renders the header status chip: an "ok" staleness age or a distinct "error" state that does NOT reset the last-success clock. */
function renderStatus(status, state, nowMs) {
if (!status) return;
@@ -283,7 +312,13 @@
return ctl;
}
- /** Installs a MutationObserver on the grid so a card's poll timers stop when it is hidden/removed and restart on re-show (no juneau-pages.js hook). */
+ /**
+ * Installs a MutationObserver so a card's poll timers stop when it is hidden/removed and restart on re-show (no
+ * juneau-pages.js hook). It watches the grid subtree (own `hidden` / `style` / `class`) AND every ancestor pages
+ * tab panel's `class`: a pages tab hide toggles `.jc-active` on an ancestor `.jc-panel` / `.jc-subpanel` that sits
+ * ABOVE the grid, so a grid-subtree-only observer would never see it. With no panel ancestor the grid watch is the
+ * sole fallback (a card hidden by its own `hidden` / inline `style`).
+ */
function observeGrid(grid, controls) {
if (typeof window.MutationObserver === "undefined") return null;
const obs = new window.MutationObserver(function () {
@@ -295,6 +330,9 @@
}
});
obs.observe(grid, { attributes: true, attributeFilter: ["hidden", "style", "class"], subtree: true, childList: true });
+ const panels = ancestorPanels(grid);
+ for (let i = 0; i < panels.length; i++)
+ obs.observe(panels[i], { attributes: true, attributeFilter: ["class"] });
return obs;
}
diff --git a/juneau-rest/juneau-rest-server-views/src/main/resources/org/apache/juneau/views/juneau-chrome.js b/juneau-rest/juneau-rest-server-views/src/main/resources/org/apache/juneau/views/juneau-chrome.js
index 4956f46edc..d01b8a54d1 100644
--- a/juneau-rest/juneau-rest-server-views/src/main/resources/org/apache/juneau/views/juneau-chrome.js
+++ b/juneau-rest/juneau-rest-server-views/src/main/resources/org/apache/juneau/views/juneau-chrome.js
@@ -24,13 +24,16 @@
*
* On DOMContentLoaded it scans [data-juneau-app-header] and [data-juneau-bar-slot] regions and, per region, performs
* a fail-loud contract-version handshake against the baked-in JUNEAU_HEADER_CONTRACT_VERSION /
- * JUNEAU_BAR_CONTRACT_VERSION before hydrating action glyphs, wiring an avatar image fallback, dispatching SAFE
- * host-events, and (only when the host explicitly calls refresh(root)) re-applying same-origin counts.
+ * JUNEAU_BAR_CONTRACT_VERSION before hydrating action glyphs, wiring an avatar image fallback, wiring menu triggers,
+ * dispatching SAFE host-events, and (only when the host explicitly calls refresh(root)) re-applying same-origin counts.
*
- * Menus WAIT on [TODO-445h] (M1 B): a Behavior.MENU trigger arrives DISABLED with its list OMITTED, so this runtime
- * never opens one. It also does NOT define a layer manager: pushLayer(...) here is a THIN FORWARD to
- * window.JuneauViews.init.pushLayer (445h/juneau-views.js) when present, else a no-op - it never competes with the
- * views layer stack. Nothing internally calls it under M1 B.
+ * Menus ride the ONE shared layer stack (window.JuneauViews.init) that 445h/juneau-views.js owns. This runtime does
+ * NOT define pushLayer/popLayer (Pass 5 M-P5-B1) and carries no competing popup-layer stack of its own: a Behavior.MENU trigger's
+ * aria-controls'd .jc-menu list is portalled to document.body (position:fixed) as a kind:"menu" light-dismiss layer,
+ * positioned under the trigger, and its Escape / outside-click dismissal + z-index depth are owned by that shared
+ * stack - exactly as the harvested row-action menus do. With the stack absent (views not loaded) a MENU trigger is
+ * inert and its list stays display:none - never a fake <details>/role=menu disclosure. Menus are single-level (445h
+ * owns nested popups).
*
* The "PURE LOGIC LAYER" is DOM-free (plain data in, plain data out) and independently node-testable; the "DOM
* BINDING LAYER" is the thin shim that scans, handshakes, hydrates and binds. There is NO poller: refresh is
@@ -56,6 +59,11 @@
const BADGE_MAX_ATTR = "data-juneau-badge-max";
const AVATAR_MARKER = "data-juneau-avatar";
const REFRESH_ATTR = "data-juneau-refresh";
+ // A menu trigger's aria-controls points at its .jc-menu list; a marker records that a trigger is already wired.
+ const MENU_CLASS = "jc-menu";
+ const MENU_ITEM_CLASS = "jc-menu-item";
+ const MENU_WIRED_ATTR = "data-juneau-menu-wired";
+ const MENU_ITEMS_WIRED_ATTR = "data-juneau-menu-items-wired";
const HEADER_SIDECAR_PREFIX = "juneau-header:";
const BAR_SIDECAR_PREFIX = "juneau-bar:";
@@ -178,15 +186,128 @@
}
/**
- * THIN FORWARD to the shared 445h/juneau-views.js layer manager (window.JuneauViews.init.pushLayer) when present,
- * else a no-op returning null. This runtime deliberately does NOT define its own layer stack (m3 B): menus wait on
- * 445h, so nothing here calls it yet - it exists only so a later menu build forwards to the ONE shared manager.
+ * Resolves the ONE shared layer stack (window.JuneauViews.init, 445h/juneau-views.js) or null when views is not
+ * loaded. This runtime NEVER defines pushLayer/popLayer of its own (Pass 5 M-P5-B1): it is strictly a client of
+ * the shared stack, so a chrome menu shares the same z-index / Escape / light-dismiss depth as views dialogs.
*/
- function pushLayer(el, opts) {
+ function viewsLayerStack() {
const views = window.JuneauViews && window.JuneauViews.init;
- if (views && typeof views.pushLayer === "function")
- return views.pushLayer(el, opts);
- return null; // 445h layer manager absent - no-op (menus wait)
+ return views && typeof views.pushLayer === "function" && typeof views.popLayer === "function" ? views : null;
+ }
+
+ /**
+ * chrome-local positioner: sets top/left (and shows) an ALREADY-portalled menu node under its trigger. views'
+ * pushLayer already reparented it to body and set position:fixed; this only computes the cell-anchored offset (with
+ * a light viewport clamp), never re-parents. positionCellPopover is not exported by views, so chrome carries this
+ * tiny helper rather than reaching into the views internals.
+ */
+ function positionMenuUnderTrigger(menu, trigger) {
+ if (!menu || !menu.style || !trigger || typeof trigger.getBoundingClientRect !== "function") return;
+ const rect = trigger.getBoundingClientRect();
+ const vw = (typeof window !== "undefined" && window.innerWidth) ? window.innerWidth : 1024;
+ menu.style.display = "block";
+ const w = menu.offsetWidth || 0;
+ let left = rect.left;
+ const top = rect.bottom + 4;
+ if (left + w > vw - 4) left = Math.max(4, vw - w - 4);
+ if (left < 4) left = 4;
+ menu.style.left = left + "px";
+ menu.style.top = top + "px";
+ }
+
+ /** Resolves a trigger's aria-controls'd .jc-menu list node (compared by id via getElementById, never interpolated). */
+ function menuForTrigger(trigger) {
+ const id = trigger && trigger.getAttribute ? trigger.getAttribute("aria-controls") : null;
+ if (!id || typeof document === "undefined" || typeof document.getElementById !== "function") return null;
+ const el = document.getElementById(id);
+ return el && el.classList && Array.prototype.indexOf.call(el.classList, MENU_CLASS) >= 0 ? el : null;
+ }
+
+ // Single-open tracking: chrome menus are one-at-a-time (a new open closes any other), matching the row-action menus.
+ let openMenuRec = null;
+
+ /**
+ * Wires SAFE .jc-menu-item buttons in a list to dispatch the SAME host CustomEvent a top-level SAFE action uses
+ * (from the owning TRIGGER, which stays in the header, so the event bubbles through the header even though the list
+ * is portalled to body), then close the menu. A format-invalid token is refused loud (hand-edited attribute only).
+ * LINK items are plain same-origin anchors (native navigation) - closing the menu on their click keeps no orphan
+ * open if navigation is intercepted. Dividers are inert. Idempotent per list.
+ */
+ function wireMenuItems(menu, trigger, root) {
+ if (!menu || !menu.querySelectorAll || menu.getAttribute(MENU_ITEMS_WIRED_ATTR) === "1") return;
+ menu.setAttribute(MENU_ITEMS_WIRED_ATTR, "1");
+ const safeItems = menu.querySelectorAll("." + MENU_ITEM_CLASS + "[" + SAFE_ATTR + "]");
+ for (let i = 0; i < safeItems.length; i++) {
+ const item = safeItems[i];
+ const token = item.getAttribute(SAFE_ATTR);
+ if (!isSafeToken(token)) {
+ (window.console && console.error) && console.error(
+ "juneau-chrome.js: refusing to wire SAFE menu item with malformed token '" + token + "'.");
+ continue;
+ }
+ if (!item.addEventListener) continue;
+ item.addEventListener("click", function (ev) {
+ if (ev && ev.preventDefault) ev.preventDefault();
+ dispatchSafe(trigger, token, root);
+ closeMenu();
+ });
+ }
+ const links = menu.querySelectorAll("a." + MENU_ITEM_CLASS);
+ for (let j = 0; j < links.length; j++)
+ if (links[j].addEventListener) links[j].addEventListener("click", function () { closeMenu(); });
+ }
+
+ /** Opens a trigger's menu on the shared views stack (no stack / no list -> inert, never a fake disclosure). */
+ function openMenu(trigger, root) {
+ const views = viewsLayerStack();
+ const menu = menuForTrigger(trigger);
+ if (!views || !menu) return;
+ wireMenuItems(menu, trigger, root);
+ views.pushLayer(menu, {
+ kind: "menu", portal: true, lightDismiss: true, trapFocus: false, detachOnPop: false,
+ returnFocusTo: trigger,
+ onDismiss: function () {
+ if (trigger.setAttribute) trigger.setAttribute("aria-expanded", "false");
+ if (menu.style) menu.style.display = "none";
+ if (openMenuRec && openMenuRec.menu === menu) openMenuRec = null;
+ }
+ });
+ positionMenuUnderTrigger(menu, trigger);
+ if (trigger.setAttribute) trigger.setAttribute("aria-expanded", "true");
+ openMenuRec = { trigger: trigger, menu: menu };
+ }
+
+ /** Closes the open chrome menu (if any) by popping its layer off the shared views stack; onDismiss resets ARIA. */
+ function closeMenu() {
+ const views = viewsLayerStack();
+ if (views && openMenuRec) views.popLayer(openMenuRec.menu);
+ }
+
+ /** Toggles a trigger's menu: a re-click on the open trigger closes it; opening one first closes any other. */
+ function toggleMenu(trigger, root) {
+ if (openMenuRec && openMenuRec.trigger === trigger) { closeMenu(); return; }
+ if (openMenuRec) closeMenu();
+ openMenu(trigger, root);
+ }
+
+ /**
+ * Wires each enabled Behavior.MENU trigger (header action or avatar chip) to toggle its .jc-menu list on the shared
+ * views layer stack. Idempotent per trigger. A trigger with no resolvable list / no views stack stays inert.
+ */
+ function wireMenus(root) {
+ if (!root || !root.querySelectorAll) return;
+ const triggers = root.querySelectorAll("[" + BEHAVIOR_ATTR + "='menu']");
+ for (let i = 0; i < triggers.length; i++) {
+ const trigger = triggers[i];
+ if (trigger.getAttribute(MENU_WIRED_ATTR) === "1" || !trigger.addEventListener) continue;
+ trigger.setAttribute(MENU_WIRED_ATTR, "1");
+ (function (t) {
+ t.addEventListener("click", function (ev) {
+ if (ev && ev.preventDefault) ev.preventDefault();
+ toggleMenu(t, root);
+ });
+ })(trigger);
+ }
}
/** Wires an avatar's image so a broken same-origin image falls back to the hidden initials chip (no dead avatar). */
@@ -207,8 +328,9 @@
/**
* Wires each fully-functional SAFE action to dispatch a bubbling CustomEvent the host listens for; the host does
* the work (there is no built-in navigation and no new token type). A format-invalid token is refused loud - it
- * can only be a hand-edited attribute, since the server already format-validates it. MENU triggers arrive
- * disabled (menus wait on 445h) so they are never wired; LINK actions are plain anchors needing no wiring.
+ * can only be a hand-edited attribute, since the server already format-validates it. This selects only top-level
+ * SAFE actions (data-juneau-header-action + behavior=safe); MENU triggers are wired separately by wireMenus, and
+ * SAFE items INSIDE a menu list by wireMenuItems. LINK actions are plain anchors needing no wiring.
*/
function wireSafeActions(root) {
if (!root || !root.querySelectorAll) return;
@@ -272,6 +394,7 @@
hydrateIcons(header);
wireAvatarFallback(header);
wireSafeActions(header);
+ wireMenus(header);
if (sidecar) applyCounts(header, envelopeBadges(sidecar));
return { root: header, refresh: function () { return refresh(header); } };
}
@@ -319,9 +442,12 @@
hydrateIcons: hydrateIcons,
applyCounts: applyCounts,
readSidecar: readSidecar,
- pushLayer: pushLayer,
wireAvatarFallback: wireAvatarFallback,
wireSafeActions: wireSafeActions,
+ wireMenus: wireMenus,
+ openMenu: openMenu,
+ closeMenu: closeMenu,
+ positionMenuUnderTrigger: positionMenuUnderTrigger,
dispatchSafe: dispatchSafe,
refresh: refresh,
initHeader: initHeader,
diff --git a/juneau-rest/juneau-rest-server-views/src/test/java/org/apache/juneau/rest/server/views/AppHeaderTable_Emit_Test.java b/juneau-rest/juneau-rest-server-views/src/test/java/org/apache/juneau/rest/server/views/AppHeaderTable_Emit_Test.java
index e0d1cc8721..1b10713501 100644
--- a/juneau-rest/juneau-rest-server-views/src/test/java/org/apache/juneau/rest/server/views/AppHeaderTable_Emit_Test.java
+++ b/juneau-rest/juneau-rest-server-views/src/test/java/org/apache/juneau/rest/server/views/AppHeaderTable_Emit_Test.java
@@ -28,11 +28,13 @@ import org.junit.jupiter.api.*;
* chrome the {@code juneau-chrome.js} runtime enhances.
*
* <p>
- * Pins the {@code data-juneau-*} DOM contract the runtime depends on, and the locked behavior of TODO-445m M1 B:
- * chips / {@link Behavior#LINK} / {@link Behavior#SAFE} are fully functional, a {@link Behavior#MENU} trigger is
- * emitted <b>disabled with its list omitted</b> (menus wait on 445h; no {@code <details>} fake disclosure, no
- * {@code role="menu"}), no {@code .jc-nav}/{@code .jc-nav-tab} is ever emitted (445f standing nav rule), and every
- * human string is entity-escaped.
+ * Pins the {@code data-juneau-*} DOM contract the runtime depends on, and the locked behavior of 445m now that
+ * the shared views layer stack (445h) has shipped: chips / {@link Behavior#LINK} / {@link Behavior#SAFE} are fully
+ * functional, and a {@link Behavior#MENU} trigger is emitted <b>enabled</b> with real menu ARIA
+ * ({@code aria-haspopup="menu"}, {@code aria-expanded="false"}, {@code aria-controls}) and its
+ * {@code .jc-menu}/{@code .jc-menu-item}/{@code .jc-menu-divider} list markup emitted (hidden until opened via the
+ * views {@code pushLayer} stack) — no {@code <details>} fake disclosure. No {@code .jc-nav}/{@code .jc-nav-tab}
+ * is ever emitted (445f standing nav rule), and every human string is entity-escaped.
*/
class AppHeaderTable_Emit_Test extends TestBase {
@@ -132,25 +134,47 @@ class AppHeaderTable_Emit_Test extends TestBase {
}
//------------------------------------------------------------------------------------------------------------------
- // MENU action -> DISABLED trigger, list OMITTED (menus wait on 445h; M1 B)
+ // MENU action -> ENABLED trigger with real menu ARIA + emitted list (wired to the views layer stack)
//------------------------------------------------------------------------------------------------------------------
- @Test void a08_menuTriggerDisabled_listOmitted() {
+ @Test void a08_menuTriggerEnabled_withMenuAria() {
var h = html(header());
assertTrue(h.contains("data-juneau-header-action=\"more\""), h);
assertTrue(h.contains("data-juneau-behavior=\"menu\""), h);
var menuFrag = h.substring(h.indexOf("data-juneau-header-action=\"more\""));
menuFrag = menuFrag.substring(0, menuFrag.indexOf("</button>"));
- assertTrue(menuFrag.contains("disabled"), "MENU trigger must be disabled until 445h");
- assertTrue(menuFrag.contains("aria-disabled=\"true\""), h);
+ // A working MENU trigger is a live button - never disabled / aria-disabled.
+ assertFalse(menuFrag.contains("disabled"), "a working MENU trigger must not be disabled");
+ assertFalse(menuFrag.contains("aria-disabled"), "a working MENU trigger must not be aria-disabled");
+ assertTrue(menuFrag.contains("aria-haspopup=\"menu\""), h);
+ assertTrue(menuFrag.contains("aria-expanded=\"false\""), h);
+ assertTrue(menuFrag.contains("aria-controls=\"juneau-menu:app:more\""), h);
}
- @Test void a09_noFakeMenuDisclosureOrItems() {
+ @Test void a09_menuListEmittedWithRealAria_noDetails() {
var h = html(header());
- assertFalse(h.contains("<details"), "no <details> fake disclosure");
- assertFalse(h.contains("role=\"menu\""), "no fake role=menu ARIA");
- assertFalse(h.contains(">Item A<"), "menu item label must be omitted until 445h");
- assertFalse(h.contains("href=\"/a\""), "menu item href must be omitted until 445h");
+ assertFalse(h.contains("<details"), "no <details> fake disclosure - the views layer stack owns opening");
+ assertTrue(h.contains("class=\"jc-menu\""), "the menu list markup is emitted");
+ assertTrue(h.contains("id=\"juneau-menu:app:more\""), h);
+ assertTrue(h.contains("role=\"menu\""), "real menu ARIA now that the JS layer manager exists");
+ assertTrue(h.contains("class=\"jc-menu-item\""), h);
+ assertTrue(h.contains("role=\"menuitem\""), h);
+ assertTrue(h.contains(">Item A<"), "menu item label emitted");
+ assertTrue(h.contains("href=\"/a\""), "menu item link href emitted");
+ }
+
+ @Test void a09b_menuSafeItemAndDivider() {
+ var h = html(AppHeaderDef.create("app")
+ .actions(HeaderAction.menu("more", "tune", "More")
+ .menu(MenuItem.link("a", "Item A", "/a"), MenuItem.divider(), MenuItem.safe("b", "Do It", "do-it")))
+ .build());
+ assertTrue(h.contains("class=\"jc-menu-divider\""), h);
+ assertTrue(h.contains("role=\"separator\""), "a divider is an inert separator row");
+ assertTrue(h.contains("data-juneau-safe=\"do-it\""), "a SAFE menu item carries its dispatch token");
+ assertTrue(h.contains(">Do It<"), h);
+ // The SAFE item is a real <button> (host-dispatch); the link item is an <a href> (same-origin navigation).
+ assertTrue(h.contains("<button type=\"button\" class=\"jc-menu-item\""), h);
+ assertTrue(h.contains("<a href=\"/a\" class=\"jc-menu-item\""), h);
}
//------------------------------------------------------------------------------------------------------------------
@@ -166,13 +190,18 @@ class AppHeaderTable_Emit_Test extends TestBase {
assertTrue(h.contains(">AL<"), "initials rendered as escaped text");
}
- @Test void a11_avatarWithMenuIsDisabledButton() {
+ @Test void a11_avatarWithMenuIsEnabledTrigger() {
var h = html(AppHeaderDef.create("app")
.avatar(AvatarChip.of("Ada").initials("A").menu(MenuItem.link("p", "Profile", "/p"))).build());
- var frag = h.substring(h.indexOf("data-juneau-avatar"));
- assertTrue(frag.contains("disabled"), "an avatar with a menu is a disabled trigger until 445h");
- assertTrue(frag.contains("aria-disabled=\"true\""), h);
- assertFalse(h.contains(">Profile<"), "avatar menu item omitted until 445h");
+ var btn = h.substring(h.indexOf("data-juneau-avatar"));
+ btn = btn.substring(0, btn.indexOf("</button>"));
+ assertFalse(btn.contains("disabled"), "an avatar with a menu is now a live trigger (menus shipped)");
+ assertFalse(btn.contains("aria-disabled"), h);
+ assertTrue(btn.contains("aria-haspopup=\"menu\""), h);
+ assertTrue(btn.contains("aria-expanded=\"false\""), h);
+ assertTrue(btn.contains("aria-controls=\"juneau-menu:app:avatar\""), h);
+ assertTrue(h.contains(">Profile<"), "avatar menu item now emitted");
+ assertTrue(h.contains("href=\"/p\""), h);
}
@Test void a12_avatarImageWithHiddenInitialsFallback() {
diff --git a/juneau-rest/juneau-rest-server-views/src/test/java/org/apache/juneau/rest/server/views/ViewsJs_Cards_Test.java b/juneau-rest/juneau-rest-server-views/src/test/java/org/apache/juneau/rest/server/views/ViewsJs_Cards_Test.java
index 497949e39e..aa9fc0dc82 100644
--- a/juneau-rest/juneau-rest-server-views/src/test/java/org/apache/juneau/rest/server/views/ViewsJs_Cards_Test.java
+++ b/juneau-rest/juneau-rest-server-views/src/test/java/org/apache/juneau/rest/server/views/ViewsJs_Cards_Test.java
@@ -88,6 +88,15 @@ class ViewsJs_Cards_Test extends TestBase {
"card contract must be a distinct constant from the VIEW_META contract");
}
+ @Test void a04_hiddenCheckKnowsPagesTabPanels() throws Exception {
+ // The poll-teardown path must recognize the juneau-pages.js tab-hide markers (an inactive .jc-panel/.jc-subpanel
+ // that lacks .jc-active is CSS-hidden above the grid). A light wiring pin - not a whole-file string match.
+ var body = cardsJs();
+ assertTrue(body.contains("jc-panel"), "hidden-check must recognize the pages tab panel class");
+ assertTrue(body.contains("jc-subpanel"), "hidden-check must recognize the pages tab subpanel class");
+ assertTrue(body.contains("jc-active"), "hidden-check must recognize the pages tab active marker");
+ }
+
//------------------------------------------------------------------------------------------------------------------
// Behavioral: run both node harnesses once, gated on node availability
//------------------------------------------------------------------------------------------------------------------
@@ -324,4 +333,17 @@ class ViewsJs_Cards_Test extends TestBase {
assertEquals(true, r.get("h_hiddenViaAncestor"));
assertEquals(true, r.get("h_shown"));
}
+
+ @Test void c09_pagesTabHide_inactivePanelStopsAndRestartsPoll() {
+ // The real juneau-pages.js hide path: a card inside an ancestor .jc-panel that lacks .jc-active is CSS-hidden,
+ // and pages toggles .jc-active on that ancestor panel (never the card subtree). isElementHidden must see it,
+ // the poll must not start there, and the observer must stop/restart timers as .jc-active toggles.
+ var r = dom();
+ assertEquals(true, r.get("i_hiddenInInactivePanel")); // ancestor .jc-panel without .jc-active => hidden
+ assertEquals(true, r.get("i_notStartedInInactivePanel")); // poll never starts under a hidden tab
+ assertEquals(true, r.get("i_observerInstalled"));
+ assertEquals(true, r.get("i_startedWhenActivated")); // pages adds .jc-active -> timers restart
+ assertEquals(true, r.get("i_shownWhenActive"));
+ assertEquals(true, r.get("i_stoppedWhenDeactivated")); // pages removes .jc-active -> timers stop
+ }
}
diff --git a/juneau-rest/juneau-rest-server-views/src/test/java/org/apache/juneau/rest/server/views/ViewsJs_ChromeMenu_Test.java b/juneau-rest/juneau-rest-server-views/src/test/java/org/apache/juneau/rest/server/views/ViewsJs_ChromeMenu_Test.java
new file mode 100644
index 0000000000..b958292263
--- /dev/null
+++ b/juneau-rest/juneau-rest-server-views/src/test/java/org/apache/juneau/rest/server/views/ViewsJs_ChromeMenu_Test.java
@@ -0,0 +1,183 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.juneau.rest.server.views;
+
+import static java.nio.charset.StandardCharsets.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assumptions.*;
+
+import java.io.*;
+import java.nio.file.*;
+import java.util.*;
+import java.util.concurrent.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.marshall.marshaller.*;
+import org.junit.jupiter.api.*;
+
+/**
+ * Integration coverage for 445m: the {@code juneau-chrome.js} MENU wiring driving the ONE shared
+ * {@code juneau-views.js} layer stack (445h) — renders + views + chrome loaded into a single Node sandbox so a
+ * real {@link org.apache.juneau.rest.server.widgets.Behavior#MENU} trigger opens its {@code .jc-menu} list on the
+ * shared stack, not on a chrome-local mock.
+ *
+ * <p>
+ * Pins the locked rules that only show up when the two runtimes run together: on open the trigger's
+ * {@code aria-controls}'d list is portalled to {@code document.body} ({@code position:fixed}, escaping any
+ * overflow-clip ancestor) as a {@code kind:"menu"} light-dismiss layer that never inflates the dialog-kind depth cap;
+ * Escape / outside-click dismissal and the {@code aria-expanded} reset all run through that ONE stack; and a chrome
+ * menu opened <b>over</b> a views dialog pops off cleanly on Escape while the dialog beneath it survives. Gated on
+ * {@code node} being on {@code PATH} (skipped otherwise — no {@code -Pjs-tests} required).
+ */
+class ViewsJs_ChromeMenu_Test extends TestBase {
+
+ private static String resource(String name) throws IOException {
+ try (var in = ViewsMixin.class.getResourceAsStream(name)) {
+ assertNotNull(in, () -> "missing classpath resource: " + name);
+ return new String(in.readAllBytes(), UTF_8);
+ }
+ }
+
+ private static Map<?,?> report;
+
+ @BeforeAll
+ static void probeIfNodeAvailable() throws Exception {
+ if (!nodeAvailable())
+ return;
+ var harness = locateHarness();
+ if (harness == null)
+ return;
+ var rendersFile = Files.createTempFile("juneau-renders-", ".js");
+ var viewsFile = Files.createTempFile("juneau-views-", ".js");
+ var chromeFile = Files.createTempFile("juneau-chrome-", ".js");
+ try {
+ Files.writeString(rendersFile, resource(ViewsMixin.RENDERS_JS_RESOURCE), UTF_8);
+ Files.writeString(viewsFile, resource(ViewsMixin.VIEWS_JS_RESOURCE), UTF_8);
+ Files.writeString(chromeFile, resource(ViewsMixin.CHROME_JS_RESOURCE), UTF_8);
+ report = Json.to(runNode(harness, rendersFile, viewsFile, chromeFile), Map.class);
+ } finally {
+ Files.deleteIfExists(rendersFile);
+ Files.deleteIfExists(viewsFile);
+ Files.deleteIfExists(chromeFile);
+ }
+ }
+
+ private static boolean nodeAvailable() {
+ try {
+ var p = new ProcessBuilder("node", "--version").redirectErrorStream(true).start();
+ if (!p.waitFor(5, TimeUnit.SECONDS)) {
+ p.destroyForcibly();
+ return false;
+ }
+ return p.exitValue() == 0;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ private static Path locateHarness() {
+ var basedir = System.getProperty("basedir");
+ if (basedir != null) {
+ var p = Path.of(basedir, "src/test/js/chrome-menu.cjs");
+ if (Files.isRegularFile(p)) return p.toAbsolutePath().normalize();
+ }
+ for (var rel : List.of(
+ "src/test/js/chrome-menu.cjs",
+ "juneau-rest/juneau-rest-server-views/src/test/js/chrome-menu.cjs"
+ )) {
+ var p = Path.of(rel);
+ if (Files.isRegularFile(p)) return p.toAbsolutePath().normalize();
+ }
+ return null;
+ }
+
+ private static String runNode(Path harness, Path renders, Path views, Path chrome) throws Exception {
+ var stdout = Files.createTempFile("chrome-menu-stdout-", ".json");
+ var stderr = Files.createTempFile("chrome-menu-stderr-", ".txt");
+ try {
+ var pb = new ProcessBuilder(List.of(
+ "node", harness.toString(), renders.toString(), views.toString(), chrome.toString()))
+ .redirectOutput(stdout.toFile())
+ .redirectError(stderr.toFile());
+ var p = pb.start();
+ if (!p.waitFor(30, TimeUnit.SECONDS)) {
+ p.destroyForcibly();
+ fail("chrome-menu.cjs did not finish within 30s; stderr:\n" + quietRead(stderr));
+ }
+ if (p.exitValue() != 0)
+ fail("chrome-menu.cjs exited " + p.exitValue() + "; stderr:\n" + quietRead(stderr)
+ + "\nstdout:\n" + quietRead(stdout));
+ return Files.readString(stdout, UTF_8);
+ } finally {
+ Files.deleteIfExists(stdout);
+ Files.deleteIfExists(stderr);
+ }
+ }
+
+ private static String quietRead(Path p) {
+ try { return Files.readString(p, UTF_8); }
+ catch (IOException e) { return "(unreadable: " + e.getMessage() + ")"; }
+ }
+
+ private static Map<?,?> r() {
+ assumeTrue(report != null, "node not available or chrome-menu.cjs not found — integration layer skipped");
+ return report;
+ }
+
+ @Test void a01_harnessLoadedBothRuntimesIntoOneSandbox() {
+ var r = r();
+ assertEquals(true, r.get("hasViews"), "juneau-views.js must publish the shared layer stack");
+ assertEquals(true, r.get("hasChrome"), "juneau-chrome.js must publish its MENU wiring");
+ }
+
+ @Test void a02_menuOpensAsPortalledFixedMenuLayerOnTheSharedStack() {
+ var r = r();
+ assertEquals(true, r.get("open_topIsMenu"), () -> "top layer is not a menu: " + r);
+ assertEquals(true, r.get("open_menuOnBody"), () -> "the list was not portalled to body: " + r);
+ assertEquals(true, r.get("open_escapedHeader"), () -> "the list is still clipped inside the header: " + r);
+ assertEquals(true, r.get("open_positionFixed"), () -> "the list is not position:fixed: " + r);
+ assertEquals(true, r.get("open_displayShown"), () -> "the list was not shown on open: " + r);
+ assertEquals(true, r.get("open_zIndexSet"), () -> "the stack did not stamp a z-index: " + r);
+ assertEquals(true, r.get("open_notADialog"), () -> "a menu inflated the dialog-kind depth cap: " + r);
+ assertEquals("true", r.get("open_ariaExpanded"), () -> "aria-expanded did not flip to true: " + r);
+ }
+
+ @Test void a03_escapeDismissesThroughTheSharedStack_ariaResetNodeKept() {
+ var r = r();
+ assertEquals(true, r.get("esc_closed"), () -> "Escape did not pop the menu off the stack: " + r);
+ assertEquals("false", r.get("esc_ariaReset"), () -> "onDismiss did not reset aria-expanded: " + r);
+ assertEquals(true, r.get("esc_menuHidden"), () -> "onDismiss did not hide the list: " + r);
+ assertEquals(true, r.get("esc_menuKeptInBody"), () -> "detachOnPop:false must keep the node for reuse: " + r);
+ }
+
+ @Test void a04_outsideClickLightDismissesThroughTheSharedStack() {
+ var r = r();
+ assertEquals(true, r.get("reopen_topIsMenu"), () -> "the menu did not reopen: " + r);
+ assertEquals(true, r.get("light_closed"), () -> "an outside pointerdown did not light-dismiss the menu: " + r);
+ }
+
+ @Test void a05_chromeMenuStackedOverADialogPopsCleanly() {
+ var r = r();
+ assertEquals(true, r.get("stack_dialogFirst"), () -> "the dialog did not open first: " + r);
+ assertEquals(true, r.get("stack_menuOverDialog"), () -> "the menu did not stack over the dialog: " + r);
+ assertEquals(true, r.get("stack_dialogCountUnchanged"), () -> "the menu touched the dialog-kind depth cap: " + r);
+ assertEquals(true, r.get("stack_menuPoppedDialogRemains"),
+ () -> "Escape did not pop only the menu, leaving the dialog: " + r);
+ assertEquals(true, r.get("stack_dialogSurvives"), () -> "the dialog beneath did not survive: " + r);
+ assertEquals("false", r.get("stack_ariaReset"), () -> "the trigger's aria-expanded was not reset: " + r);
+ }
+}
diff --git a/juneau-rest/juneau-rest-server-views/src/test/java/org/apache/juneau/rest/server/views/ViewsJs_Chrome_Test.java b/juneau-rest/juneau-rest-server-views/src/test/java/org/apache/juneau/rest/server/views/ViewsJs_Chrome_Test.java
index db0dde51ce..7335af7171 100644
--- a/juneau-rest/juneau-rest-server-views/src/test/java/org/apache/juneau/rest/server/views/ViewsJs_Chrome_Test.java
+++ b/juneau-rest/juneau-rest-server-views/src/test/java/org/apache/juneau/rest/server/views/ViewsJs_Chrome_Test.java
@@ -36,11 +36,13 @@ import org.junit.jupiter.api.*;
* — no {@code -Pjs-tests} required).
*
* <p>
- * Pins the TODO-445m locked rules on the client side: two <b>distinct</b> baked contract constants
+ * Pins the 445m locked rules on the client side: two <b>distinct</b> baked contract constants
* ({@code JUNEAU_HEADER_CONTRACT_VERSION}/{@code JUNEAU_BAR_CONTRACT_VERSION}) kept in lockstep with the server bean
- * constants, {@code window.JuneauChrome} namespacing, a thin {@code pushLayer} <b>forward</b> to
- * {@code window.JuneauViews.init.pushLayer} (never a competing definition — m3 B), textContent-only count
- * apply, same-origin/non-templated refresh endpoints, format-validated SAFE tokens (L11), and no poller.
+ * constants, {@code window.JuneauChrome} namespacing, working {@code Behavior.MENU} triggers that ride the ONE shared
+ * {@code window.JuneauViews.init} layer stack (445h) as {@code kind:"menu"} light-dismiss layers — this runtime
+ * <b>never defines its own</b> {@code pushLayer}/{@code popLayer} and carries no competing {@code popupLayerStack}
+ * (Pass 5 M-P5-B1) and no fake {@code <details>}/{@code role=menu} disclosure — textContent-only count apply,
+ * same-origin/non-templated refresh endpoints, format-validated SAFE tokens (L11), and no poller.
*/
class ViewsJs_Chrome_Test extends TestBase {
@@ -73,11 +75,13 @@ class ViewsJs_Chrome_Test extends TestBase {
assertNotSame(ViewsMixin.CONTRACT_VERSION, ViewsMixin.BAR_CONTRACT_VERSION);
}
- @Test void a03_pushLayerIsForwardNotCompetingDefinition() throws Exception {
+ @Test void a03_callsSharedStack_neverDefinesOrCompetesWithIt() throws Exception {
var body = chromeJs();
- // m3 B: must CALL window.JuneauViews.init.pushLayer (thin forward), never define its own layer stack.
- assertTrue(body.contains("window.JuneauViews.init.pushLayer") || body.contains("views.pushLayer"),
- "pushLayer must forward to the shared views layer manager");
+ // M-P5-B1: chrome must CALL the shared views stack (window.JuneauViews.init) - never DEFINE pushLayer/popLayer.
+ assertTrue(body.contains("window.JuneauViews.init"), "chrome must resolve the shared window.JuneauViews.init stack");
+ assertTrue(body.contains("views.pushLayer("), "chrome must open menus via the shared stack's pushLayer");
+ assertFalse(body.contains("function pushLayer("), "chrome must NOT define its own pushLayer");
+ assertFalse(body.contains("function popLayer("), "chrome must NOT define its own popLayer");
assertFalse(body.contains("popupLayerStack"), "chrome.js must not carry a competing layer stack");
}
@@ -87,10 +91,13 @@ class ViewsJs_Chrome_Test extends TestBase {
assertTrue(body.contains("b.textContent = clampCount("), "counts painted via textContent, never innerHTML");
}
- @Test void a05_menusWaitOn445h_noFakeDisclosure() throws Exception {
+ @Test void a05_menusOpenOnSharedStack_noFakeDisclosure() throws Exception {
var body = chromeJs();
- // The runtime never opens a menu (server emits MENU triggers disabled); no <details>/role=menu construction.
- assertFalse(body.contains("role=\"menu\""), "no fake role=menu construction");
+ // Menus now WORK, but only by riding the shared stack as kind:"menu" layers - never a chrome-fabricated overlay.
+ assertTrue(body.contains("kind: \"menu\""), "a chrome menu opens as a kind:\"menu\" layer on the shared stack");
+ assertTrue(body.contains("viewsLayerStack"), "menu open/close is gated on resolving the shared views stack");
+ // The runtime never fabricates menu markup client-side: the server emits role=menu; there is no fake disclosure.
+ assertFalse(body.contains("role=\"menu\""), "no client-fabricated role=menu construction (server emits it)");
assertFalse(body.contains("createElement(\"details\")"), "no fake <details> disclosure");
}
@@ -248,10 +255,19 @@ class ViewsJs_Chrome_Test extends TestBase {
assertEquals(true, r.get("avatar_initialsShown"));
}
- @Test void b09_pushLayerForwardsElseNoop() {
+ @Test void b09_menuOpensAndClosesOnSharedStack() {
var r = r();
- assertEquals(true, r.get("push_forwarded")); // forwards to window.JuneauViews.init.pushLayer when present
- assertEquals(true, r.get("push_noop")); // else a null no-op (never a competing layer manager)
+ // Open: the trigger's aria-controls'd list is pushed onto the shared stack as a light-dismiss kind:"menu" layer.
+ assertEquals(true, r.get("menu_pushedList")); // the resolved .jc-menu list is what gets pushed
+ assertEquals("menu", r.get("menu_kind")); // shares the row-action menu's stack kind
+ assertEquals(true, r.get("menu_portal")); // portalled to body (escapes any overflow-clip ancestor)
+ assertEquals(true, r.get("menu_lightDismiss")); // outside-click / Escape dismissal owned by the stack
+ assertEquals(true, r.get("menu_returnFocusToTrigger")); // focus returns to the trigger on pop
+ assertEquals("true", r.get("menu_ariaExpandedOnOpen")); // ARIA reflects the open state
+ // A SAFE menu item dispatches the host event FROM THE TRIGGER (bubbles through the header), then closes the menu.
+ assertEquals(true, r.get("menu_safeDispatchedFromTrigger"));
+ assertEquals(true, r.get("menu_closedOnSafe")); // popLayer runs on the SAME list node
+ assertEquals("false", r.get("menu_ariaExpandedAfterClose")); // onDismiss (shared teardown) resets ARIA
}
@Test void b10_initHeaderHandshake() {
diff --git a/juneau-rest/juneau-rest-server-views/src/test/js/cards-browser.cjs b/juneau-rest/juneau-rest-server-views/src/test/js/cards-browser.cjs
index 73fcd6c035..422824ee64 100644
--- a/juneau-rest/juneau-rest-server-views/src/test/js/cards-browser.cjs
+++ b/juneau-rest/juneau-rest-server-views/src/test/js/cards-browser.cjs
@@ -242,5 +242,29 @@ const out = { hasInit: !!(I && typeof I.initCard === 'function') };
const shown = el('div'); const kid = el('div'); shown.appendChild(kid);
out.h_shown = I.isElementHidden(kid) === false;
+ // I) The real pages tab-hide path: a card inside a .jc-panel that LACKS .jc-active is CSS-hidden (juneau-views.css
+ // keeps an inactive panel at display:none); juneau-pages.js toggles .jc-active on that ANCESTOR panel, never on
+ // the card subtree. isElementHidden must report hidden, the poll must not start there, and the observer must
+ // stop/restart the timers as .jc-active is toggled on the ancestor panel.
+ fetchCalls = [];
+ window.fetch = makeFetch({ contractVersion: '1', fields: { k: 'P' } });
+ observerCallback = null;
+ const panel = el('div'); panel.setAttribute('class', 'jc-panel'); // inactive tab panel: CSS display:none
+ const cardI = buildCard({ contract: '1', refresh: '/data/summary', poll: 10000 });
+ const gridI = el('section'); gridI.setAttribute('data-juneau-card-grid', '1'); gridI.appendChild(cardI);
+ panel.appendChild(gridI);
+ out.i_hiddenInInactivePanel = I.isElementHidden(cardI) === true;
+ const ctlI = I.initCard(cardI);
+ out.i_notStartedInInactivePanel = ctlI.running === false; // start() bails while the ancestor tab is hidden
+ const obsI = I.observeGrid(gridI, [ctlI]);
+ out.i_observerInstalled = obsI != null && observerCallback != null;
+ panel.setAttribute('class', 'jc-panel jc-active'); // pages shows this tab
+ observerCallback();
+ out.i_startedWhenActivated = ctlI.running === true;
+ out.i_shownWhenActive = I.isElementHidden(cardI) === false;
+ panel.setAttribute('class', 'jc-panel'); // pages hides this tab again
+ observerCallback();
+ out.i_stoppedWhenDeactivated = ctlI.running === false;
+
process.stdout.write(JSON.stringify(out));
})();
diff --git a/juneau-rest/juneau-rest-server-views/src/test/js/chrome-menu.cjs b/juneau-rest/juneau-rest-server-views/src/test/js/chrome-menu.cjs
new file mode 100644
index 0000000000..4ea2e1c9c3
--- /dev/null
+++ b/juneau-rest/juneau-rest-server-views/src/test/js/chrome-menu.cjs
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * chrome-menu.cjs - always-on Node INTEGRATION harness for TODO-445m: juneau-renders.js + juneau-views.js (the ONE
+ * 445h layer stack) + juneau-chrome.js loaded into a SINGLE sandbox, so a real Behavior.MENU trigger opens its
+ * .jc-menu list on the shared stack - not on a chrome-local mock. Proves the list is portalled to document.body
+ * (position:fixed, escaping any overflow-clip ancestor) as a kind:"menu" light-dismiss layer, that Escape /
+ * outside-click dismissal runs through that ONE stack, and - the stacking case - that a chrome menu opened OVER a
+ * views dialog pops off cleanly on Escape without disturbing the dialog beneath it (a menu never inflates the
+ * dialog-kind depth cap).
+ *
+ * Usage: node chrome-menu.cjs <juneau-renders.js> <juneau-views.js> <juneau-chrome.js>
+ *
+ * Prints ONE JSON object to stdout; every assertion lives in the Java test.
+ */
+'use strict';
+
+const fs = require('node:fs');
+const path = require('node:path');
+const vm = require('node:vm');
+const { makeEnv } = require(path.join(__dirname, 'views-dom-shim.cjs'));
+
+const rendersJsPath = process.argv[2];
+const viewsJsPath = process.argv[3];
+const chromeJsPath = process.argv[4];
+if (!rendersJsPath || !viewsJsPath || !chromeJsPath) {
+ console.error('usage: node chrome-menu.cjs <juneau-renders.js> <juneau-views.js> <juneau-chrome.js>');
+ process.exit(2);
+}
+
+const env = makeEnv();
+// CustomEvent so chrome's SAFE dispatch path does not bail (these stack assertions do not exercise the host event
+// itself - header.cjs covers SAFE dispatch - but the constructor must exist for wiring to run cleanly).
+env.window.CustomEvent = function (type, init) {
+ this.type = type;
+ this.detail = init && init.detail;
+ this.bubbles = !!(init && init.bubbles);
+ this.defaultPrevented = false;
+ this.preventDefault = function () { this.defaultPrevented = true; };
+};
+
+const sandbox = {
+ window: env.window, document: env.document, console: console,
+ setTimeout: function (fn) { if (typeof fn === 'function') fn(); return 0; },
+ clearTimeout: function () {}, setInterval: function () { return 0; }, clearInterval: function () {},
+ Promise: Promise,
+ fetch: function () { return env.callFetch.apply(env, arguments); }
+};
+
+// ONE sandbox: views.js publishes window.JuneauViews.init (the shared stack); chrome.js then CALLS it (never defines it).
+vm.runInNewContext(fs.readFileSync(path.resolve(rendersJsPath), 'utf8'), sandbox, { filename: 'juneau-renders.js' });
+vm.runInNewContext(fs.readFileSync(path.resolve(viewsJsPath), 'utf8'), sandbox, { filename: 'juneau-views.js' });
+vm.runInNewContext(fs.readFileSync(path.resolve(chromeJsPath), 'utf8'), sandbox, { filename: 'juneau-chrome.js' });
+
+const V = env.window.JuneauViews && env.window.JuneauViews.init;
+const C = env.window.JuneauChrome && env.window.JuneauChrome.init;
+const out = {
+ hasViews: !!(V && typeof V.pushLayer === 'function' && typeof V.topLayer === 'function'),
+ hasChrome: !!(C && typeof C.wireMenus === 'function')
+};
+if (!out.hasViews || !out.hasChrome) { process.stdout.write(JSON.stringify(out)); process.exit(0); }
+
+// The shared shim element lacks classList (chrome's menuForTrigger reads it); add a live getter over className.
+function mkEl(tag, className, attrs) {
+ const n = env.el(tag);
+ if (className) n.setAttribute('class', className);
+ if (attrs) for (const k in attrs) if (Object.hasOwn(attrs, k)) n.setAttribute(k, attrs[k]);
+ Object.defineProperty(n, 'classList', {
+ configurable: true,
+ get: function () { return this.className ? this.className.split(/\s+/) : []; }
+ });
+ return n;
+}
+
+function clickEv() { return { type: 'click', preventDefault: function () { this.defaultPrevented = true; } }; }
+function drain() { while (V.topLayer()) V.popLayer(); }
+
+// Build the server-shaped app-header: <header data-juneau-app-header> > .jc-header-actions > (trigger + .jc-menu list).
+// The MENU trigger's aria-controls points at the list id, exactly as AppHeaderTable emits it.
+const header = mkEl('header', 'jc-header', { 'data-juneau-app-header': 'app' });
+env.body.appendChild(header);
+const actions = mkEl('div', 'jc-header-actions');
+header.appendChild(actions);
+const trigger = mkEl('button', 'jc-icon-btn', {
+ 'data-juneau-header-action': 'more', 'data-juneau-behavior': 'menu',
+ 'aria-haspopup': 'menu', 'aria-expanded': 'false', 'aria-controls': 'juneau-menu:app:more'
+});
+actions.appendChild(trigger);
+const menu = mkEl('div', 'jc-menu', { 'id': 'juneau-menu:app:more', 'role': 'menu' });
+menu.appendChild(mkEl('a', 'jc-menu-item', { 'href': '/a', 'role': 'menuitem' }));
+menu.appendChild(mkEl('button', 'jc-menu-item', { 'role': 'menuitem', 'data-juneau-safe': 'do-it' }));
+actions.appendChild(menu);
+
+C.wireMenus(header);
+
+// --- open: the list is pushed onto the shared stack, portalled to body, position:fixed, as a kind:"menu" layer ------
+trigger.dispatch('click', clickEv());
+out.open_topIsMenu = V.topLayer() != null && V.topLayer().kind === 'menu';
+out.open_menuOnBody = menu.parentNode === env.body;
+out.open_escapedHeader = ! header.contains(menu); // no longer clipped by any header/actions ancestor
+out.open_positionFixed = menu.style.position === 'fixed';
+out.open_displayShown = menu.style.display === 'block';
+out.open_zIndexSet = !! menu.style.zIndex;
+out.open_notADialog = V.dialogLayerCount() === 0; // a menu must not inflate the dialog-kind depth cap
+out.open_ariaExpanded = trigger.getAttribute('aria-expanded');
+
+// --- Escape pops the menu THROUGH the shared stack; onDismiss (shared teardown) resets ARIA + hides (kept for reuse) -
+env.dispatchDocument('keydown', { key: 'Escape' });
+out.esc_closed = V.topLayer() === null;
+out.esc_ariaReset = trigger.getAttribute('aria-expanded'); // 'false'
+out.esc_menuHidden = menu.style.display === 'none';
+out.esc_menuKeptInBody = menu.parentNode === env.body; // detachOnPop:false -> node persists, reused on reopen
+
+// --- reopen, then an OUTSIDE pointerdown light-dismisses the top menu layer via the shared stack -------------------
+trigger.dispatch('click', clickEv());
+out.reopen_topIsMenu = V.topLayer() != null && V.topLayer().kind === 'menu';
+const outside = mkEl('div', ''); env.body.appendChild(outside);
+env.dispatchDocument('pointerdown', { target: outside });
+out.light_closed = V.topLayer() === null && trigger.getAttribute('aria-expanded') === 'false';
+
+// --- stacking: a chrome menu opened OVER a views dialog pops off on Escape WITHOUT disturbing the dialog beneath ----
+drain();
+const table = mkEl('table', ''); const tr = mkEl('tr', '');
+V.showActionDialog({ title: 'Details' }, { id: 'd', label: 'Details' }, table, tr, {});
+out.stack_dialogFirst = V.dialogLayerCount() === 1 && V.topLayer().kind === 'dialog';
+trigger.dispatch('click', clickEv());
+out.stack_menuOverDialog = V.topLayer() != null && V.topLayer().kind === 'menu';
+out.stack_dialogCountUnchanged = V.dialogLayerCount() === 1; // the menu stacks ABOVE without touching the dialog cap
+env.dispatchDocument('keydown', { key: 'Escape' }); // Escape pops ONLY the top (the menu)
+out.stack_menuPoppedDialogRemains = V.topLayer() != null && V.topLayer().kind === 'dialog';
+out.stack_dialogSurvives = V.dialogLayerCount() === 1;
+out.stack_ariaReset = trigger.getAttribute('aria-expanded'); // 'false'
+drain();
+
+process.stdout.write(JSON.stringify(out));
diff --git a/juneau-rest/juneau-rest-server-views/src/test/js/header.cjs b/juneau-rest/juneau-rest-server-views/src/test/js/header.cjs
index bf670c109c..41ceeb584f 100644
--- a/juneau-rest/juneau-rest-server-views/src/test/js/header.cjs
+++ b/juneau-rest/juneau-rest-server-views/src/test/js/header.cjs
@@ -231,13 +231,43 @@ if (!out.hasInit) {
out.avatar_imgHidden = img.hidden === true;
out.avatar_initialsShown = initials.hidden === false;
- // ---- DOM: pushLayer is a THIN FORWARD to JuneauViews.init.pushLayer, else no-op ----
- const sentinel = { rec: true };
- window.JuneauViews.init = { pushLayer: function (el, opts) { pushCall = { el: el, opts: opts }; return sentinel; } };
- const someEl = makeEl('div', {});
- out.push_forwarded = I.pushLayer(someEl, { kind: 'menu' }) === sentinel && pushCall !== null && pushCall.el === someEl;
- delete window.JuneauViews.init;
- out.push_noop = I.pushLayer(someEl, {}) === null;
+ // ---- DOM: a MENU trigger opens/closes its .jc-menu list on the SHARED views stack (chrome defines NO stack) ----
+ // The mock stands in for window.JuneauViews.init (445h): it records push/pop and runs onDismiss on pop, exactly as
+ // the real stack does - so aria-expanded round-trips through the shared teardown, not a chrome-local closer.
+ let menuPushCall = null, menuPopCall = null, lastMenuOpts = null;
+ window.JuneauViews = window.JuneauViews || {};
+ window.JuneauViews.init = {
+ pushLayer: function (el, opts) { menuPushCall = { el: el, opts: opts }; lastMenuOpts = opts; return { el: el }; },
+ popLayer: function (el) {
+ menuPopCall = { el: el };
+ if (lastMenuOpts && typeof lastMenuOpts.onDismiss === 'function') lastMenuOpts.onDismiss();
+ }
+ };
+ const miLink = makeEl('a', { 'class': 'jc-menu-item', 'href': '/a', 'role': 'menuitem' });
+ const miSafe = makeEl('button', { 'class': 'jc-menu-item', 'role': 'menuitem', 'data-juneau-safe': 'do-it' });
+ const menuList = makeEl('div', { 'class': 'jc-menu', 'id': 'juneau-menu:app:more', 'role': 'menu' }, [miLink, miSafe]);
+ documentAll.push(menuList);
+ const menuTrigger = makeEl('button', {
+ 'data-juneau-header-action': 'more', 'data-juneau-behavior': 'menu', 'aria-haspopup': 'menu',
+ 'aria-expanded': 'false', 'aria-controls': 'juneau-menu:app:more'
+ });
+ const menuHeader = makeEl('header', { 'data-juneau-app-header': 'app' }, [menuTrigger]);
+ I.wireMenus(menuHeader);
+ menuTrigger.dispatchEvent({ type: 'click', preventDefault: function () { this.defaultPrevented = true; } });
+ out.menu_pushedList = menuPushCall !== null && menuPushCall.el === menuList;
+ out.menu_kind = menuPushCall && menuPushCall.opts ? menuPushCall.opts.kind : null;
+ out.menu_portal = !!(menuPushCall && menuPushCall.opts && menuPushCall.opts.portal === true);
+ out.menu_lightDismiss = !!(menuPushCall && menuPushCall.opts && menuPushCall.opts.lightDismiss === true);
+ out.menu_returnFocusToTrigger = !!(menuPushCall && menuPushCall.opts && menuPushCall.opts.returnFocusTo === menuTrigger);
+ out.menu_ariaExpandedOnOpen = menuTrigger.getAttribute('aria-expanded');
+ // A SAFE menu item dispatches the host event FROM THE TRIGGER (so it bubbles through the header), then closes.
+ let menuSafeCaptured = null;
+ menuTrigger.addEventListener(I.SAFE_EVENT, function (ev) { menuSafeCaptured = ev; });
+ miSafe.dispatchEvent({ type: 'click', preventDefault: function () { this.defaultPrevented = true; } });
+ out.menu_safeDispatchedFromTrigger = !!menuSafeCaptured
+ && menuSafeCaptured.detail.token === 'do-it' && menuSafeCaptured.detail.actionId === 'more';
+ out.menu_closedOnSafe = menuPopCall !== null && menuPopCall.el === menuList;
+ out.menu_ariaExpandedAfterClose = menuTrigger.getAttribute('aria-expanded');
// ---- DOM: initHeader handshake (mismatch -> null, no apply; ok -> counts applied from sidecar) ----
const badBadge = makeEl('span', { 'data-juneau-badge': 'header:reload' });