stimeo-ui 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +178 -0
- package/README.md +120 -0
- package/dist/cable/index.js +63 -15
- package/dist/cable/index.js.map +1 -1
- package/dist/controllers/accordion_controller.d.ts +30 -3
- package/dist/controllers/accordion_controller.js +98 -9
- package/dist/controllers/accordion_controller.js.map +1 -1
- package/dist/controllers/alert_dialog_controller.d.ts +8 -7
- package/dist/controllers/alert_dialog_controller.js.map +1 -1
- package/dist/controllers/announcer_controller.d.ts +3 -2
- package/dist/controllers/announcer_controller.js +8 -1
- package/dist/controllers/announcer_controller.js.map +1 -1
- package/dist/controllers/auto_submit_controller.js +43 -2
- package/dist/controllers/auto_submit_controller.js.map +1 -1
- package/dist/controllers/avatar_controller.js +1 -1
- package/dist/controllers/avatar_controller.js.map +1 -1
- package/dist/controllers/breadcrumb_controller.d.ts +10 -7
- package/dist/controllers/breadcrumb_controller.js +9 -8
- package/dist/controllers/breadcrumb_controller.js.map +1 -1
- package/dist/controllers/bulk_select_controller.d.ts +4 -4
- package/dist/controllers/bulk_select_controller.js +7 -6
- package/dist/controllers/bulk_select_controller.js.map +1 -1
- package/dist/controllers/calendar_controller.d.ts +85 -23
- package/dist/controllers/calendar_controller.js +323 -123
- package/dist/controllers/calendar_controller.js.map +1 -1
- package/dist/controllers/carousel_controller.d.ts +67 -22
- package/dist/controllers/carousel_controller.js +263 -38
- package/dist/controllers/carousel_controller.js.map +1 -1
- package/dist/controllers/character_counter_controller.d.ts +1 -1
- package/dist/controllers/character_counter_controller.js +40 -2
- package/dist/controllers/character_counter_controller.js.map +1 -1
- package/dist/controllers/checkbox_controller.js +54 -10
- package/dist/controllers/checkbox_controller.js.map +1 -1
- package/dist/controllers/clipboard_controller.d.ts +28 -2
- package/dist/controllers/clipboard_controller.js +63 -5
- package/dist/controllers/clipboard_controller.js.map +1 -1
- package/dist/controllers/collapsible_controller.d.ts +25 -1
- package/dist/controllers/collapsible_controller.js +99 -14
- package/dist/controllers/collapsible_controller.js.map +1 -1
- package/dist/controllers/color_picker_controller.d.ts +29 -8
- package/dist/controllers/color_picker_controller.js +80 -34
- package/dist/controllers/color_picker_controller.js.map +1 -1
- package/dist/controllers/combobox_controller.d.ts +10 -1
- package/dist/controllers/combobox_controller.js +106 -16
- package/dist/controllers/combobox_controller.js.map +1 -1
- package/dist/controllers/command_palette_controller.d.ts +3 -3
- package/dist/controllers/command_palette_controller.js +35 -3
- package/dist/controllers/command_palette_controller.js.map +1 -1
- package/dist/controllers/conditional_fields_controller.js +56 -11
- package/dist/controllers/conditional_fields_controller.js.map +1 -1
- package/dist/controllers/confirm_controller.js +3 -0
- package/dist/controllers/confirm_controller.js.map +1 -1
- package/dist/controllers/context_menu_controller.d.ts +6 -0
- package/dist/controllers/context_menu_controller.js +32 -12
- package/dist/controllers/context_menu_controller.js.map +1 -1
- package/dist/controllers/countdown_controller.d.ts +30 -1
- package/dist/controllers/countdown_controller.js +129 -26
- package/dist/controllers/countdown_controller.js.map +1 -1
- package/dist/controllers/currency_input_controller.d.ts +74 -15
- package/dist/controllers/currency_input_controller.js +205 -58
- package/dist/controllers/currency_input_controller.js.map +1 -1
- package/dist/controllers/data_grid_controller.d.ts +63 -18
- package/dist/controllers/data_grid_controller.js +195 -29
- package/dist/controllers/data_grid_controller.js.map +1 -1
- package/dist/controllers/date_range_picker_controller.d.ts +34 -6
- package/dist/controllers/date_range_picker_controller.js +139 -27
- package/dist/controllers/date_range_picker_controller.js.map +1 -1
- package/dist/controllers/dialog_controller.d.ts +10 -3
- package/dist/controllers/dialog_controller.js +35 -8
- package/dist/controllers/dialog_controller.js.map +1 -1
- package/dist/controllers/direct_upload_controller.js +22 -4
- package/dist/controllers/direct_upload_controller.js.map +1 -1
- package/dist/controllers/dirty_form_controller.d.ts +2 -2
- package/dist/controllers/dirty_form_controller.js +14 -1
- package/dist/controllers/dirty_form_controller.js.map +1 -1
- package/dist/controllers/dismissible_controller.js +1 -0
- package/dist/controllers/dismissible_controller.js.map +1 -1
- package/dist/controllers/drawer_controller.d.ts +18 -10
- package/dist/controllers/drawer_controller.js +54 -19
- package/dist/controllers/drawer_controller.js.map +1 -1
- package/dist/controllers/dropdown_controller.d.ts +9 -3
- package/dist/controllers/dropdown_controller.js +36 -9
- package/dist/controllers/dropdown_controller.js.map +1 -1
- package/dist/controllers/editable_controller.js +34 -0
- package/dist/controllers/editable_controller.js.map +1 -1
- package/dist/controllers/file_dropzone_controller.js +144 -51
- package/dist/controllers/file_dropzone_controller.js.map +1 -1
- package/dist/controllers/filter_controller.d.ts +10 -4
- package/dist/controllers/filter_controller.js +20 -6
- package/dist/controllers/filter_controller.js.map +1 -1
- package/dist/controllers/flash_controller.d.ts +26 -6
- package/dist/controllers/flash_controller.js +305 -46
- package/dist/controllers/flash_controller.js.map +1 -1
- package/dist/controllers/focus_controller.js +1 -0
- package/dist/controllers/focus_controller.js.map +1 -1
- package/dist/controllers/form_field_controller.js +7 -5
- package/dist/controllers/form_field_controller.js.map +1 -1
- package/dist/controllers/form_validation_controller.js +19 -13
- package/dist/controllers/form_validation_controller.js.map +1 -1
- package/dist/controllers/frame_loading_controller.js +16 -2
- package/dist/controllers/frame_loading_controller.js.map +1 -1
- package/dist/controllers/highlight_controller.js +19 -2
- package/dist/controllers/highlight_controller.js.map +1 -1
- package/dist/controllers/hover_card_controller.d.ts +10 -2
- package/dist/controllers/hover_card_controller.js +40 -14
- package/dist/controllers/hover_card_controller.js.map +1 -1
- package/dist/controllers/idle_controller.d.ts +16 -3
- package/dist/controllers/idle_controller.js +90 -5
- package/dist/controllers/idle_controller.js.map +1 -1
- package/dist/controllers/input_mask_controller.d.ts +5 -2
- package/dist/controllers/input_mask_controller.js +65 -9
- package/dist/controllers/input_mask_controller.js.map +1 -1
- package/dist/controllers/intersection_controller.js +3 -0
- package/dist/controllers/intersection_controller.js.map +1 -1
- package/dist/controllers/lazy_frame_controller.js +11 -2
- package/dist/controllers/lazy_frame_controller.js.map +1 -1
- package/dist/controllers/listbox_controller.d.ts +50 -8
- package/dist/controllers/listbox_controller.js +203 -45
- package/dist/controllers/listbox_controller.js.map +1 -1
- package/dist/controllers/masonry_controller.js +0 -2
- package/dist/controllers/masonry_controller.js.map +1 -1
- package/dist/controllers/menu_controller.d.ts +9 -3
- package/dist/controllers/menu_controller.js +45 -16
- package/dist/controllers/menu_controller.js.map +1 -1
- package/dist/controllers/menubar_controller.d.ts +11 -0
- package/dist/controllers/menubar_controller.js +58 -24
- package/dist/controllers/menubar_controller.js.map +1 -1
- package/dist/controllers/meter_controller.js +9 -5
- package/dist/controllers/meter_controller.js.map +1 -1
- package/dist/controllers/multi_select_controller.d.ts +18 -3
- package/dist/controllers/multi_select_controller.js +278 -104
- package/dist/controllers/multi_select_controller.js.map +1 -1
- package/dist/controllers/navigation_menu_controller.d.ts +11 -0
- package/dist/controllers/navigation_menu_controller.js +48 -15
- package/dist/controllers/navigation_menu_controller.js.map +1 -1
- package/dist/controllers/nested_form_controller.js +37 -8
- package/dist/controllers/nested_form_controller.js.map +1 -1
- package/dist/controllers/network_status_controller.js +9 -1
- package/dist/controllers/network_status_controller.js.map +1 -1
- package/dist/controllers/number_input_controller.d.ts +36 -8
- package/dist/controllers/number_input_controller.js +124 -21
- package/dist/controllers/number_input_controller.js.map +1 -1
- package/dist/controllers/optimistic_controller.js +14 -1
- package/dist/controllers/optimistic_controller.js.map +1 -1
- package/dist/controllers/otp_controller.d.ts +22 -7
- package/dist/controllers/otp_controller.js +198 -55
- package/dist/controllers/otp_controller.js.map +1 -1
- package/dist/controllers/overflow_indicator_controller.d.ts +8 -12
- package/dist/controllers/overflow_indicator_controller.js +84 -13
- package/dist/controllers/overflow_indicator_controller.js.map +1 -1
- package/dist/controllers/overflow_menu_controller.d.ts +26 -6
- package/dist/controllers/overflow_menu_controller.js +112 -41
- package/dist/controllers/overflow_menu_controller.js.map +1 -1
- package/dist/controllers/pagination_controller.d.ts +19 -11
- package/dist/controllers/pagination_controller.js +74 -28
- package/dist/controllers/pagination_controller.js.map +1 -1
- package/dist/controllers/password_reveal_controller.d.ts +15 -1
- package/dist/controllers/password_reveal_controller.js +59 -2
- package/dist/controllers/password_reveal_controller.js.map +1 -1
- package/dist/controllers/persist_controller.js +30 -8
- package/dist/controllers/persist_controller.js.map +1 -1
- package/dist/controllers/pointer_drag_controller.js +131 -52
- package/dist/controllers/pointer_drag_controller.js.map +1 -1
- package/dist/controllers/popover_controller.d.ts +9 -3
- package/dist/controllers/popover_controller.js +45 -11
- package/dist/controllers/popover_controller.js.map +1 -1
- package/dist/controllers/portal_controller.d.ts +1 -1
- package/dist/controllers/portal_controller.js +6 -2
- package/dist/controllers/portal_controller.js.map +1 -1
- package/dist/controllers/preview_guard_controller.js +16 -1
- package/dist/controllers/preview_guard_controller.js.map +1 -1
- package/dist/controllers/progress_controller.js +8 -4
- package/dist/controllers/progress_controller.js.map +1 -1
- package/dist/controllers/radio_group_controller.d.ts +6 -4
- package/dist/controllers/radio_group_controller.js +42 -17
- package/dist/controllers/radio_group_controller.js.map +1 -1
- package/dist/controllers/range_slider_controller.d.ts +49 -1
- package/dist/controllers/range_slider_controller.js +88 -42
- package/dist/controllers/range_slider_controller.js.map +1 -1
- package/dist/controllers/rating_controller.d.ts +14 -3
- package/dist/controllers/rating_controller.js +39 -15
- package/dist/controllers/rating_controller.js.map +1 -1
- package/dist/controllers/read_more_controller.d.ts +24 -2
- package/dist/controllers/read_more_controller.js +69 -2
- package/dist/controllers/read_more_controller.js.map +1 -1
- package/dist/controllers/resizable_controller.d.ts +16 -2
- package/dist/controllers/resizable_controller.js +82 -22
- package/dist/controllers/resizable_controller.js.map +1 -1
- package/dist/controllers/scroll_area_controller.js +5 -1
- package/dist/controllers/scroll_area_controller.js.map +1 -1
- package/dist/controllers/scroll_visibility_controller.js +0 -1
- package/dist/controllers/scroll_visibility_controller.js.map +1 -1
- package/dist/controllers/scrollspy_controller.d.ts +3 -2
- package/dist/controllers/scrollspy_controller.js +6 -0
- package/dist/controllers/scrollspy_controller.js.map +1 -1
- package/dist/controllers/separator_controller.d.ts +41 -14
- package/dist/controllers/separator_controller.js +66 -37
- package/dist/controllers/separator_controller.js.map +1 -1
- package/dist/controllers/sidebar_controller.d.ts +20 -3
- package/dist/controllers/sidebar_controller.js +77 -18
- package/dist/controllers/sidebar_controller.js.map +1 -1
- package/dist/controllers/skeleton_controller.js +6 -1
- package/dist/controllers/skeleton_controller.js.map +1 -1
- package/dist/controllers/slider_controller.d.ts +45 -7
- package/dist/controllers/slider_controller.js +82 -47
- package/dist/controllers/slider_controller.js.map +1 -1
- package/dist/controllers/smart_sticky_header_controller.js +11 -1
- package/dist/controllers/smart_sticky_header_controller.js.map +1 -1
- package/dist/controllers/sortable_controller.js +17 -2
- package/dist/controllers/sortable_controller.js.map +1 -1
- package/dist/controllers/spinner_controller.js +10 -2
- package/dist/controllers/spinner_controller.js.map +1 -1
- package/dist/controllers/step_indicator_controller.d.ts +19 -17
- package/dist/controllers/step_indicator_controller.js +18 -17
- package/dist/controllers/step_indicator_controller.js.map +1 -1
- package/dist/controllers/stepper_controller.d.ts +34 -9
- package/dist/controllers/stepper_controller.js +101 -19
- package/dist/controllers/stepper_controller.js.map +1 -1
- package/dist/controllers/stick_to_bottom_controller.d.ts +19 -0
- package/dist/controllers/stick_to_bottom_controller.js +75 -5
- package/dist/controllers/stick_to_bottom_controller.js.map +1 -1
- package/dist/controllers/submit_once_controller.d.ts +3 -2
- package/dist/controllers/submit_once_controller.js +16 -3
- package/dist/controllers/submit_once_controller.js.map +1 -1
- package/dist/controllers/switch_controller.d.ts +29 -7
- package/dist/controllers/switch_controller.js +101 -10
- package/dist/controllers/switch_controller.js.map +1 -1
- package/dist/controllers/tabs_controller.d.ts +12 -0
- package/dist/controllers/tabs_controller.js +21 -2
- package/dist/controllers/tabs_controller.js.map +1 -1
- package/dist/controllers/tags_input_controller.d.ts +15 -3
- package/dist/controllers/tags_input_controller.js +209 -59
- package/dist/controllers/tags_input_controller.js.map +1 -1
- package/dist/controllers/theme_controller.d.ts +20 -3
- package/dist/controllers/theme_controller.js +64 -14
- package/dist/controllers/theme_controller.js.map +1 -1
- package/dist/controllers/time_picker_controller.js +23 -8
- package/dist/controllers/time_picker_controller.js.map +1 -1
- package/dist/controllers/toast_controller.d.ts +52 -15
- package/dist/controllers/toast_controller.js +337 -54
- package/dist/controllers/toast_controller.js.map +1 -1
- package/dist/controllers/toggle_group_controller.d.ts +49 -7
- package/dist/controllers/toggle_group_controller.js +159 -23
- package/dist/controllers/toggle_group_controller.js.map +1 -1
- package/dist/controllers/toolbar_controller.js +32 -0
- package/dist/controllers/toolbar_controller.js.map +1 -1
- package/dist/controllers/tooltip_controller.d.ts +8 -0
- package/dist/controllers/tooltip_controller.js +39 -13
- package/dist/controllers/tooltip_controller.js.map +1 -1
- package/dist/controllers/transition_controller.js +4 -0
- package/dist/controllers/transition_controller.js.map +1 -1
- package/dist/controllers/tree_view_controller.d.ts +39 -8
- package/dist/controllers/tree_view_controller.js +169 -16
- package/dist/controllers/tree_view_controller.js.map +1 -1
- package/dist/index.d.ts +28 -1
- package/dist/index.js +4588 -1535
- package/dist/index.js.map +1 -1
- package/dist/inspector/cli.d.ts +72 -6
- package/dist/inspector/cli.js +262 -51
- package/dist/inspector/cli.js.map +1 -1
- package/dist/inspector/cli_bin.js +309 -51
- package/dist/inspector/cli_bin.js.map +1 -1
- package/dist/inspector/examples.json +40 -40
- package/dist/inspector/manifest.json +525 -59
- package/dist/positioning/index.js +2 -0
- package/dist/positioning/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -160,6 +160,16 @@ var SafeTimeout = class extends TimerRegistry {
|
|
|
160
160
|
}
|
|
161
161
|
};
|
|
162
162
|
|
|
163
|
+
// src/utils/state_reason.ts
|
|
164
|
+
var FOCUS_EVENTS = /* @__PURE__ */ new Set(["blur", "focus", "focusin", "focusout"]);
|
|
165
|
+
var POINTER_EVENTS = /* @__PURE__ */ new Set(["mouseenter", "mouseleave", "pointerenter", "pointerleave"]);
|
|
166
|
+
function stateReasonFor(event) {
|
|
167
|
+
if (!event) return "api";
|
|
168
|
+
if (FOCUS_EVENTS.has(event.type)) return "focus";
|
|
169
|
+
if (POINTER_EVENTS.has(event.type)) return "pointer";
|
|
170
|
+
return "user";
|
|
171
|
+
}
|
|
172
|
+
|
|
163
173
|
// src/controllers/menu_controller.ts
|
|
164
174
|
var MenuController = class extends Controller {
|
|
165
175
|
static targets = ["trigger", "menu", "item"];
|
|
@@ -171,6 +181,7 @@ var MenuController = class extends Controller {
|
|
|
171
181
|
"open",
|
|
172
182
|
"toggle"
|
|
173
183
|
];
|
|
184
|
+
static events = ["close", "open"];
|
|
174
185
|
#timers = new SafeTimeout();
|
|
175
186
|
/** Escape-stack membership while open; the shared resolver dismisses via it. */
|
|
176
187
|
#escapeLayer = new EscapeLayer();
|
|
@@ -182,16 +193,20 @@ var MenuController = class extends Controller {
|
|
|
182
193
|
#clickOwner = null;
|
|
183
194
|
/** Clicks already turned into an activation, so the two paths run it once. */
|
|
184
195
|
#activated = /* @__PURE__ */ new WeakSet();
|
|
196
|
+
/** Whether state moves are reported: set once `connect()` settled the baseline. */
|
|
197
|
+
#reporting = false;
|
|
185
198
|
/** Starts closed and registers activation / outside-click listeners. */
|
|
186
199
|
connect() {
|
|
187
|
-
this
|
|
200
|
+
this.#close("api");
|
|
188
201
|
this.element.addEventListener("click", this.#onItemClickCapture, true);
|
|
189
202
|
this.element.addEventListener("click", this.#onDelegatedItemClick);
|
|
190
203
|
this.element.addEventListener("keydown", this.#onDelegatedItemKeydown);
|
|
191
204
|
document.addEventListener("click", this.#onOutsideClick, true);
|
|
205
|
+
this.#reporting = true;
|
|
192
206
|
}
|
|
193
207
|
/** Releases the listeners, stack membership, and any pending Tab-close task. */
|
|
194
208
|
disconnect() {
|
|
209
|
+
this.#reporting = false;
|
|
195
210
|
this.#timers.clearAll();
|
|
196
211
|
this.#escapeLayer.deactivate();
|
|
197
212
|
this.element.removeEventListener("click", this.#onItemClickCapture, true);
|
|
@@ -200,32 +215,44 @@ var MenuController = class extends Controller {
|
|
|
200
215
|
document.removeEventListener("click", this.#onOutsideClick, true);
|
|
201
216
|
}
|
|
202
217
|
/** Toggles the menu open/closed. Bound via `data-action` (click). */
|
|
203
|
-
toggle() {
|
|
218
|
+
toggle(event) {
|
|
204
219
|
if (this.#isOpen) {
|
|
205
|
-
this.close();
|
|
220
|
+
this.close(event);
|
|
206
221
|
} else {
|
|
207
|
-
this.open();
|
|
222
|
+
this.open(event);
|
|
208
223
|
this.#focusFirst();
|
|
209
224
|
}
|
|
210
225
|
}
|
|
211
226
|
/** Opens the menu and reflects the expanded state on the trigger. */
|
|
212
|
-
open() {
|
|
227
|
+
open(event) {
|
|
228
|
+
this.#open(stateReasonFor(event));
|
|
229
|
+
}
|
|
230
|
+
/** Closes the menu and reflects the collapsed state on the trigger. */
|
|
231
|
+
close(event) {
|
|
232
|
+
this.#close(stateReasonFor(event));
|
|
233
|
+
}
|
|
234
|
+
/** Opens the menu, reflects the expanded state, and reports a move. */
|
|
235
|
+
#open(reason) {
|
|
213
236
|
this.#timers.clearAll();
|
|
214
237
|
if (!this.hasMenuTarget) return;
|
|
238
|
+
const was = this.#isOpen;
|
|
215
239
|
this.#escapeLayer.activate(document, {
|
|
216
|
-
onDismiss: () => this.#closeAndRestore(),
|
|
240
|
+
onDismiss: () => this.#closeAndRestore("escape"),
|
|
217
241
|
claims: claimsWhileFocusWithin(this.element)
|
|
218
242
|
});
|
|
219
243
|
this.menuTarget.hidden = false;
|
|
220
244
|
if (this.hasTriggerTarget) this.triggerTarget.setAttribute("aria-expanded", "true");
|
|
245
|
+
if (!was && this.#reporting) this.dispatch("open", { detail: { reason }, cancelable: false });
|
|
221
246
|
}
|
|
222
|
-
/** Closes the menu
|
|
223
|
-
close() {
|
|
247
|
+
/** Closes the menu, reflects the collapsed state, and reports a move. */
|
|
248
|
+
#close(reason) {
|
|
224
249
|
this.#timers.clearAll();
|
|
225
250
|
this.#escapeLayer.deactivate();
|
|
226
251
|
if (!this.hasMenuTarget) return;
|
|
252
|
+
const was = this.#isOpen;
|
|
227
253
|
this.menuTarget.hidden = true;
|
|
228
254
|
if (this.hasTriggerTarget) this.triggerTarget.setAttribute("aria-expanded", "false");
|
|
255
|
+
if (was && this.#reporting) this.dispatch("close", { detail: { reason }, cancelable: false });
|
|
229
256
|
}
|
|
230
257
|
/**
|
|
231
258
|
* Opens the menu with the keyboard per the APG (Down → first, Up → last).
|
|
@@ -240,11 +267,11 @@ var MenuController = class extends Controller {
|
|
|
240
267
|
if (isReservedArrowChord(event)) return;
|
|
241
268
|
if (event.key === "ArrowDown") {
|
|
242
269
|
event.preventDefault();
|
|
243
|
-
this.open();
|
|
270
|
+
this.open(event);
|
|
244
271
|
this.#focusFirst();
|
|
245
272
|
} else if (event.key === "ArrowUp") {
|
|
246
273
|
event.preventDefault();
|
|
247
|
-
this.open();
|
|
274
|
+
this.open(event);
|
|
248
275
|
this.#focusLast();
|
|
249
276
|
}
|
|
250
277
|
}
|
|
@@ -281,7 +308,7 @@ var MenuController = class extends Controller {
|
|
|
281
308
|
break;
|
|
282
309
|
case "Tab":
|
|
283
310
|
this.#timers.clearAll();
|
|
284
|
-
this.#timers.set(() => this
|
|
311
|
+
this.#timers.set(() => this.#close("focus"), 0);
|
|
285
312
|
break;
|
|
286
313
|
}
|
|
287
314
|
}
|
|
@@ -302,21 +329,21 @@ var MenuController = class extends Controller {
|
|
|
302
329
|
if (this.#activated.has(event)) return;
|
|
303
330
|
this.#activated.add(event);
|
|
304
331
|
}
|
|
305
|
-
this.#closeAndRestore();
|
|
332
|
+
this.#closeAndRestore("select");
|
|
306
333
|
}
|
|
307
334
|
/** Closes and returns focus to the trigger (Escape / item-activation path). */
|
|
308
|
-
#closeAndRestore() {
|
|
309
|
-
this
|
|
335
|
+
#closeAndRestore(reason) {
|
|
336
|
+
this.#close(reason);
|
|
310
337
|
if (this.hasTriggerTarget) this.triggerTarget.focus();
|
|
311
338
|
}
|
|
312
339
|
/** Closes the menu when a click lands outside the controller's element. */
|
|
313
340
|
#onOutsideClick = (event) => {
|
|
314
|
-
if (this.#isOpen && !this.element.contains(event.target)) this
|
|
341
|
+
if (this.#isOpen && !this.element.contains(event.target)) this.#close("outside");
|
|
315
342
|
};
|
|
316
343
|
/**
|
|
317
344
|
* Delegated twin of {@link onItemKeydown}, bound on the controller element.
|
|
318
345
|
*
|
|
319
|
-
* An item that arrives *after* connect —
|
|
346
|
+
* An item that arrives *after* connect — `stimeo--overflow-menu` moves toolbar controls
|
|
320
347
|
* into this menu at runtime — carries whatever `data-action` its author wrote,
|
|
321
348
|
* and that is exactly the binding a consumer forgets, because the markup that
|
|
322
349
|
* declares the item lives nowhere near the menu. Listening on the container
|
|
@@ -371,10 +398,12 @@ var MenuController = class extends Controller {
|
|
|
371
398
|
};
|
|
372
399
|
/** Moves focus to the first navigable item (no-op if none). */
|
|
373
400
|
#focusFirst() {
|
|
401
|
+
if (!this.#isOpen) return;
|
|
374
402
|
this.#navigableItems[0]?.focus();
|
|
375
403
|
}
|
|
376
404
|
/** Moves focus to the last navigable item (no-op if none). */
|
|
377
405
|
#focusLast() {
|
|
406
|
+
if (!this.#isOpen) return;
|
|
378
407
|
const items = this.#navigableItems;
|
|
379
408
|
items[items.length - 1]?.focus();
|
|
380
409
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/arrow_step.ts","../../src/utils/escape_layer.ts","../../src/utils/event_owner.ts","../../src/utils/safe_timeout.ts","../../src/controllers/menu_controller.ts"],"names":[],"mappings":";;;;;AA+FO,SAAS,oBAAA,CACd,KAAA,EACA,KAAA,GAAkC,EAAC,EAC1B;AACT,EAAA,IAAI,CAAC,KAAA,CAAM,GAAA,CAAI,UAAA,CAAW,OAAO,GAAG,OAAO,KAAA;AAC3C,EAAA,OACG,KAAA,CAAM,MAAA,IAAU,CAAC,KAAA,CAAM,QAAA,CAAS,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GA,WAAA,GAAoB;AAClB,IAAA,IAAA,CAAK,eAAA,CAAgB,CAAC,CAAA,EAAG,KAAA,EAAM;AAAA,EACjC;AAAA;AAAA,EAGA,UAAA,GAAmB;AACjB,IAAA,MAAM,QAAQ,IAAA,CAAK,eAAA;AACnB,IAAA,KAAA,CAAM,KAAA,CAAM,MAAA,GAAS,CAAC,CAAA,EAAG,KAAA,EAAM;AAAA,EACjC;AAAA;AAAA,EAGA,IAAI,eAAA,GAAuC;AACzC,IAAA,OAAO,IAAA,CAAK,YAAY,MAAA,CAAO,CAAC,SAAS,IAAA,CAAK,YAAA,CAAa,IAAI,CAAC,CAAA;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,aAAa,IAAA,EAAkC;AAC7C,IAAA,IAAI,IAAA,CAAK,YAAA,CAAa,QAAQ,CAAA,EAAG,OAAO,KAAA;AACxC,IAAA,OAAO,CAAC,IAAA,CAAK,QAAA;AAAA,EACf;AAAA;AAAA,EAGA,IAAI,OAAA,GAAmB;AACrB,IAAA,OAAO,IAAA,CAAK,aAAA,IAAiB,CAAC,IAAA,CAAK,UAAA,CAAW,MAAA;AAAA,EAChD;AACF","file":"menu_controller.js","sourcesContent":["import { isRtl } from \"./logical_scroll\";\n\n/**\n * Turns an arrow key into a **logical** step: `+1` for \"next\", `-1` for\n * \"previous\", `0` when the key names neither.\n *\n * APG defines the horizontal pair as *next / previous* and says a vertical\n * arrangement swaps in Down/Up for the same meaning — so the pair is one axis's\n * spelling of an order, and the order reverses with the writing direction. Only\n * the horizontal pair reverses. Down/Up name an axis the writing direction does\n * not mirror, and returning them unchanged is the point: many controllers fold\n * both pairs into one branch, where swapping the branches under RTL would flip\n * the vertical axis too — a bug that reads as \"the arrows work\" until someone\n * presses Down.\n *\n * **Direction is read from the element the caller passes, which should be the\n * container that lays the items out** — not the focused child. A child may carry\n * its own `dir` (an LTR input inside an RTL form is ordinary authoring), and\n * probing per handler makes two handlers disagree at the boundary between them.\n *\n * This decides direction only. Whether the axis is even active (an\n * `orientation=\"horizontal\"` widget ignoring Down/Up), how far the step lands,\n * and what wrapping does all stay with the caller.\n *\n * **It encodes the list-order convention: `ArrowDown` is *next*.** Widgets that\n * pair the arrows by *value* instead — `ArrowUp` meaning \"more\", as a rating or a\n * slider does — must not use this, or their vertical axis inverts. Reverse the\n * horizontal pair on its own there.\n *\n * @example\n * ```ts\n * const step = logicalArrowStep(event.key, this.element);\n * if (step === 0) return;\n * this.#roving.setActive(rovingMove(current, length, step, \"wrap\"), { focus: true });\n * ```\n */\nexport function logicalArrowStep(key: string, element: Element): 1 | -1 | 0 {\n if (key === \"ArrowDown\") return 1;\n if (key === \"ArrowUp\") return -1;\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return 0;\n const forward = isRtl(element) ? \"ArrowLeft\" : \"ArrowRight\";\n return key === forward ? 1 : -1;\n}\n\n/**\n * Rewrites `key` so an existing LTR-shaped branch keeps working under RTL:\n * `ArrowRight` and `ArrowLeft` trade places, everything else passes through.\n *\n * The alternative — negating a delta — silently breaks handlers whose two\n * horizontal branches are **not mirror images**. A grid that clamps one edge but\n * not the other, or a segmented field guarding `index > 0` on one side and\n * `index < length - 1` on the other, ends up applying the wrong guard to the\n * wrong direction. Swapping the key leaves each branch, guards and all, exactly\n * where its author put it.\n *\n * Same rule as {@link logicalArrowStep} about which element to read: pass the\n * container that lays the items out, not the focused child.\n *\n * @example\n * ```ts\n * switch (logicalArrowKey(event.key, this.element)) {\n * case \"ArrowLeft\": // \"previous\" — whatever direction that is on screen\n * ```\n */\nexport function logicalArrowKey(key: string, element: Element): string {\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return key;\n if (!isRtl(element)) return key;\n return key === \"ArrowRight\" ? \"ArrowLeft\" : \"ArrowRight\";\n}\n\n/** Modifiers a widget may claim on an arrow key, named for the `allow` list. */\nexport type ArrowModifier = \"alt\" | \"ctrl\" | \"meta\" | \"shift\";\n\n/**\n * True when an arrow key arrived carrying a modifier the widget must leave to\n * the browser: return without calling `preventDefault()` and without moving any\n * state.\n *\n * A bare arrow belongs to the widget; a chorded one usually does not.\n * `Alt`/`Meta` plus a horizontal arrow is history back/forward on every desktop\n * browser, and a widget that swallows it makes the shortcut work or not\n * depending on where focus happens to sit — a coin-flip the user cannot see.\n *\n * `allow` is for the combinations APG assigns to a pattern **and the widget\n * actually implements** — today only Combobox's optional `Alt+Down`/`Alt+Up`.\n * Listing one the widget does not implement defeats the point: the chord then\n * runs the plain-arrow branch, which is exactly what this guard exists to stop.\n * Non-arrow keys return `false`, so chorded letters and\n * `Control+Home`/`Control+End` are untouched.\n *\n * @example\n * ```ts\n * if (isReservedArrowChord(event)) return;\n * ```\n */\nexport function isReservedArrowChord(\n event: KeyboardEvent,\n allow: readonly ArrowModifier[] = [],\n): boolean {\n if (!event.key.startsWith(\"Arrow\")) return false;\n return (\n (event.altKey && !allow.includes(\"alt\")) ||\n (event.ctrlKey && !allow.includes(\"ctrl\")) ||\n (event.metaKey && !allow.includes(\"meta\")) ||\n (event.shiftKey && !allow.includes(\"shift\"))\n );\n}\n\n/**\n * True when a press arrived carrying any modifier, for the keys the browser and\n * the OS own outright: return without calling `preventDefault()` and without\n * moving any state.\n *\n * `Control+Home` and `Control+End` jump the document to its ends, and a widget\n * that swallows them makes the shortcut work or not depending on where focus\n * happens to sit. {@link isReservedArrowChord} answers the same question for the\n * arrows, but returns `false` for every other key so that this one can decide.\n *\n * There is no `allow` list here on purpose. APG assigns no modifier chord to\n * `Home`/`End`, so a widget that wanted one would be claiming a combination the\n * pattern never gave it.\n *\n * @example\n * ```ts\n * case \"Home\":\n * case \"End\":\n * if (hasModifierChord(event)) return;\n * ```\n */\nexport function hasModifierChord(event: KeyboardEvent): boolean {\n return event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;\n}\n","/**\n * Single resolver for layered Escape dismissal.\n *\n * Every Escape-dismissable overlay layer (modal focus traps, disclosure\n * overlays like dropdown/popover/menu, and hover-triggered transient layers)\n * registers here while it is open. One document-level listener per document\n * resolves each press to exactly one owner and invokes that layer's\n * {@link EscapeLayerOptions.onDismiss} — controllers never listen for a\n * dismissing Escape themselves.\n *\n * @remarks\n * Each document owns an activation-ordered stack. The owner of a press is the\n * **topmost layer whose {@link EscapeLayerOptions.claims} passes**; a layer\n * that declines is transparent, so a background overlay opened behind a modal\n * never blocks it. Because a layer opened from within another is necessarily\n * activated later, LIFO order is also inner-first for nested layers — no DOM\n * inspection is needed.\n *\n * The shared listener runs in the document bubble phase and honors\n * `event.defaultPrevented`, so an element-level widget handler that consumes\n * Escape first (an editor cancelling its edit, a combobox closing its list)\n * always wins over every registered layer — the deepest handler resolves the\n * press. A keydown that is part of an IME composition (`event.isComposing`)\n * cancels the composition, never a layer, and is ignored here for every layer\n * at once.\n *\n * A WeakMap keeps documents collectible; the listener is installed only while\n * a document's stack is non-empty, and controller lifecycle hooks guarantee\n * that disconnected layers never remain registered.\n */\n\n/** Behavior a layer registers when it activates. */\nexport interface EscapeLayerOptions {\n /**\n * Dismisses the layer. Called by the shared resolver when this layer owns a\n * press; the resolver has already consumed the event (`preventDefault()`),\n * so the callback only needs to close and place focus per the widget's\n * contract.\n */\n onDismiss: () => void;\n /**\n * Whether the layer claims the current press. Evaluated per press, so it can\n * depend on live state (e.g. \"focus is inside me or fell to the body\"). A\n * declining layer is skipped and the next layer down is consulted; omitting\n * it means the layer always claims while active.\n */\n claims?: () => boolean;\n}\n\n/** A document's stack plus the one shared listener bound to it. */\ninterface EscapeLayerRegistry {\n stack: EscapeLayer[];\n onKeydown: (event: KeyboardEvent) => void;\n}\n\n/**\n * Claims predicate shared by the click-opened disclosure overlays (dropdown /\n * popover / navigation-menu / menu / context-menu / menubar): the layer claims\n * a press while focus is inside `element`, or after focus fell to the body —\n * a click on non-focusable overlay content blurs to `<body>`, and Escape must\n * still close the overlay (the \"body-focus rescue\"). A press made after focus\n * moved to another interactive element is declined, so closing never yanks\n * focus away from where the user deliberately went.\n */\nexport function claimsWhileFocusWithin(element: Element): () => boolean {\n return () => {\n const active = element.ownerDocument.activeElement;\n return active === null || active === element.ownerDocument.body || element.contains(active);\n };\n}\n\nexport class EscapeLayer {\n static readonly #registries = new WeakMap<Document, EscapeLayerRegistry>();\n\n #ownerDocument: Document | null = null;\n /** Dismissal callback while active; `null` when inactive. */\n #onDismiss: (() => void) | null = null;\n /** Live predicate deciding whether the layer claims a press; `null` = always. */\n #claims: (() => boolean) | null = null;\n\n /**\n * Activates this layer at the top of its document's Escape stack, installing\n * the document's shared resolver listener if this is its first layer.\n * Re-activating an already-active layer moves it to the top.\n */\n activate(ownerDocument: Document = document, options: EscapeLayerOptions): void {\n this.deactivate();\n let registry = EscapeLayer.#registries.get(ownerDocument);\n if (!registry) {\n registry = EscapeLayer.#createRegistry();\n EscapeLayer.#registries.set(ownerDocument, registry);\n ownerDocument.addEventListener(\"keydown\", registry.onKeydown);\n }\n registry.stack.push(this);\n this.#ownerDocument = ownerDocument;\n this.#onDismiss = options.onDismiss;\n this.#claims = options.claims ?? null;\n }\n\n /**\n * Removes this layer from its document's Escape stack, uninstalling the\n * shared listener when the stack empties. Safe to call when inactive.\n */\n deactivate(): void {\n const ownerDocument = this.#ownerDocument;\n if (!ownerDocument) return;\n\n const registry = EscapeLayer.#registries.get(ownerDocument);\n if (registry) {\n const index = registry.stack.lastIndexOf(this);\n if (index >= 0) registry.stack.splice(index, 1);\n if (registry.stack.length === 0) {\n ownerDocument.removeEventListener(\"keydown\", registry.onKeydown);\n EscapeLayer.#registries.delete(ownerDocument);\n }\n }\n this.#ownerDocument = null;\n this.#onDismiss = null;\n this.#claims = null;\n }\n\n /**\n * Whether this active layer would own a press right now: it is the topmost\n * layer whose {@link EscapeLayerOptions.claims} passes. Exposed for tests\n * and diagnostics — production dismissal goes through the shared listener.\n */\n get ownsEscape(): boolean {\n const ownerDocument = this.#ownerDocument;\n if (!ownerDocument) return false;\n const registry = EscapeLayer.#registries.get(ownerDocument);\n if (!registry) return false;\n return EscapeLayer.#resolveOwner(registry.stack) === this;\n }\n\n /** Builds a document's registry with its shared resolver listener. */\n static #createRegistry(): EscapeLayerRegistry {\n const registry: EscapeLayerRegistry = {\n stack: [],\n onKeydown: (event: KeyboardEvent): void => {\n if (event.key !== \"Escape\" || event.defaultPrevented || event.isComposing) return;\n const owner = EscapeLayer.#resolveOwner(registry.stack);\n if (!owner) return;\n event.preventDefault();\n owner.#onDismiss?.();\n },\n };\n return registry;\n }\n\n /** The topmost stack layer whose claims predicate passes, or `null`. */\n static #resolveOwner(stack: EscapeLayer[]): EscapeLayer | null {\n for (let index = stack.length - 1; index >= 0; index--) {\n const layer = stack[index];\n if (!layer) continue;\n if (layer.#claims && !layer.#claims()) continue;\n return layer;\n }\n return null;\n }\n}\n","/**\n * Resolves which of a controller's elements owns a node.\n *\n * A delegated listener hears events from a whole subtree, so the handler's first\n * job is almost always the same question: which item, handle, or control does\n * this `event.target` belong to? The same question comes up for a\n * `MutationRecord.target`, for `document.activeElement`, and for a\n * `relatedTarget` on the way out of a hover region.\n *\n * The answer is `Node.contains()`, which is **inclusive** — an element contains\n * itself — so testing the candidate for identity as well would be redundant.\n *\n * **The guard is what makes this safe to call with a raw event target.**\n * `event.target` is typed `EventTarget | null`, and `contains()` takes a `Node?`:\n * browsers throw `TypeError` for anything else, and `window` — the everyday\n * `EventTarget` that is not a `Node` — is what an event dispatched at it carries.\n * Narrowing here means a caller never has to cast, and the rule cannot drift\n * between the places that ask the question.\n *\n * Scope stays with the caller. These helpers say *which candidate owns the node*,\n * not *whether the node belongs to this controller at all* — a component with\n * nested instances of itself decides that first (by comparing the closest\n * annotated ancestor) and passes the candidates it owns.\n */\n\n/**\n * Index in `candidates` of the first one that is, or contains, `node`.\n *\n * `-1` when none does, when `node` is absent, and when it is an `EventTarget`\n * that is not a `Node`. Candidates are tested in array order, so a nested pair\n * resolves to whichever the caller listed first.\n */\nexport function ownerIndex<T extends Element>(\n candidates: readonly T[],\n node: EventTarget | null | undefined,\n): number {\n if (!(node instanceof Node)) return -1;\n return candidates.findIndex((candidate) => candidate.contains(node));\n}\n\n/**\n * The first candidate that is, or contains, `node`; `null` when none does.\n *\n * A miss indexes the array at `-1`, which reads as `undefined` and lands on the\n * same `null` the absent cases produce.\n */\nexport function ownerOf<T extends Element>(\n candidates: readonly T[],\n node: EventTarget | null | undefined,\n): T | null {\n return candidates[ownerIndex(candidates, node)] ?? null;\n}\n","/**\n * Self-cleaning timer registries shared by Stimeo controllers.\n *\n * Stimulus controllers frequently schedule `setTimeout` / `setInterval` work\n * (auto-dismiss, debouncing, polling). When the element leaves the DOM — a\n * Turbo Drive navigation, a Turbo Stream replacement, or any `disconnect()` —\n * orphaned timers keep firing against a detached controller, leaking memory and\n * mutating stale state. {@link SafeTimeout} and {@link SafeInterval} track every\n * timer they create so a single {@link TimerRegistry.clearAll | clearAll()} call\n * in `disconnect()` tears them all down.\n *\n * These are intentionally low-level primitives: they own *registration and\n * cleanup only*. Higher-level policy (pause/resume, remaining-time accounting)\n * stays in the individual controllers so per-widget semantics are not flattened\n * into a lowest-common-denominator helper.\n */\n\n/**\n * Largest delay a timer can hold: the platform stores it in a 32-bit signed\n * integer, and anything larger overflows to `1`, so a delay meant to be far in\n * the future fires almost immediately. A declared delay above this bound names\n * no delay at all, and a controller reading one falls back to its default.\n */\nexport const MAX_TIMER_DELAY_MS = 2_147_483_647;\n\n/**\n * Shared registry bookkeeping for the timeout/interval variants.\n *\n * Subclasses provide the scheduling primitive ({@link schedule}) and its matching\n * canceller ({@link cancel}); this base owns the set of live ids plus the\n * per-id and bulk teardown shared by both.\n */\nabstract class TimerRegistry {\n /** Live timer ids that have not yet been cleared (or, for timeouts, fired). */\n protected readonly ids = new Set<number>();\n\n /** Schedules the underlying platform timer and returns its id. */\n protected abstract schedule(callback: () => void, delay: number): number;\n\n /** Cancels the underlying platform timer for `id`. */\n protected abstract cancel(id: number): void;\n\n /**\n * Cancels a single tracked timer.\n *\n * No-ops if the id is unknown (already cleared, fired, or never owned by this\n * registry), so callers can clear defensively without guarding.\n */\n clear(id: number): void {\n if (this.ids.delete(id)) {\n this.cancel(id);\n }\n }\n\n /**\n * Cancels every tracked timer. Call this from a controller's `disconnect()`\n * to guarantee no timer outlives the element.\n */\n clearAll(): void {\n for (const id of this.ids) {\n this.cancel(id);\n }\n this.ids.clear();\n }\n\n /** Number of timers currently tracked (pending). */\n get size(): number {\n return this.ids.size;\n }\n}\n\n/**\n * `setTimeout` wrapper that auto-forgets each timer once it fires and supports\n * bulk teardown on disconnect.\n *\n * @example\n * ```ts\n * #timers = new SafeTimeout();\n *\n * connect() {\n * this.#timers.set(() => this.dismiss(), 5000);\n * }\n *\n * disconnect() {\n * this.#timers.clearAll();\n * }\n * ```\n */\nexport class SafeTimeout extends TimerRegistry {\n /**\n * Schedules `callback` after `delay` ms and returns the timer id.\n *\n * The id is removed from the registry automatically when the timeout fires,\n * so {@link TimerRegistry.size | size} reflects only still-pending timers.\n */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(() => {\n this.ids.delete(id);\n callback();\n }, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setTimeout(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearTimeout(id);\n }\n}\n\n/**\n * `setInterval` wrapper that tracks every interval for bulk teardown on\n * disconnect. Unlike {@link SafeTimeout}, intervals are retained until they are\n * explicitly cleared because they fire repeatedly.\n *\n * @example\n * ```ts\n * #intervals = new SafeInterval();\n *\n * connect() {\n * this.#intervals.set(() => this.tick(), 1000);\n * }\n *\n * disconnect() {\n * this.#intervals.clearAll();\n * }\n * ```\n */\nexport class SafeInterval extends TimerRegistry {\n /** Schedules a repeating `callback` every `delay` ms and returns the timer id. */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(callback, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setInterval(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearInterval(id);\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { isReservedArrowChord } from \"../utils/arrow_step\";\nimport { claimsWhileFocusWithin, EscapeLayer } from \"../utils/escape_layer\";\nimport { ownerOf } from \"../utils/event_owner\";\nimport { SafeTimeout } from \"../utils/safe_timeout\";\n\n/**\n * Headless, accessible menu button behavior.\n *\n * Markup contract (identifier: `stimeo--menu`):\n * <div data-controller=\"stimeo--menu\">\n * <button id=\"menu-trigger\" data-stimeo--menu-target=\"trigger\"\n * data-action=\"click->stimeo--menu#toggle\n * keydown->stimeo--menu#onTriggerKeydown\"\n * aria-haspopup=\"menu\" aria-expanded=\"false\" aria-controls=\"menu\">\n * Actions\n * </button>\n * <ul id=\"menu\" role=\"menu\" aria-labelledby=\"menu-trigger\"\n * data-stimeo--menu-target=\"menu\" hidden>\n * <li role=\"none\">\n * <button role=\"menuitem\" tabindex=\"-1\"\n * data-stimeo--menu-target=\"item\">…</button>\n * </li>\n * </ul>\n * </div>\n *\n * The trigger's two actions are required. Items need none: their click and key\n * handling is delegated from the controller element, so an item added, moved, or\n * server-rendered after connect works without the consumer wiring anything onto\n * it. The per-element form (`click->stimeo--menu#activate` /\n * `keydown->stimeo--menu#onItemKeydown`) is supported alongside it. A\n * focus-moving key runs once (the action claims it and the delegate stands\n * down), and `activate`, reachable on both paths, claims the click so one\n * gesture activates once. See the delegated click listener below.\n *\n * Implements the WAI-ARIA APG **Menu Button** pattern (a button that opens a menu\n * of commands). Unlike `stimeo--dropdown` (a disclosure for arbitrary content),\n * this is a true `role=\"menu\"` widget with roving focus across `role=\"menuitem\"`\n * children.\n *\n * @remarks\n * Behavior only — the core controller owns no placement. Consumers can use static\n * CSS or compose the menu with the opt-in `stimeo-ui/positioning` entrypoint for\n * viewport-aware placement. State is exposed via `aria-expanded` and the menu's\n * `hidden` attribute.\n *\n * Behavior provided:\n * - Click the trigger to toggle; `ArrowDown`/`ArrowUp` open and focus the\n * first/last item.\n * - Within the menu, `ArrowDown`/`ArrowUp` move focus (wrapping), `Home`/`End`\n * jump to the first/last item, `Tab` lets the browser move focus first and\n * then closes on the next task, and activating an enabled item closes the menu.\n * - `Escape` closes and returns focus to the trigger. While open the menu is a\n * layer on the shared `EscapeLayer` stack; it claims a press only while\n * focus is inside the controller or fell to the body, so one keypress closes\n * exactly one layer and a newer layer (e.g. a tooltip shown over an item) is\n * dismissed first.\n * - A click outside the controller closes the menu without moving focus away\n * from the clicked element.\n *\n * Roving focus skips `hidden` and natively `disabled` items. An\n * `aria-disabled=\"true\"` item remains discoverable by arrow-key focus, while its\n * activation is suppressed in the capture phase.\n */\nexport class MenuController extends Controller<HTMLElement> {\n static override targets = [\"trigger\", \"menu\", \"item\"];\n static actions = [\n \"activate\",\n \"close\",\n \"onItemKeydown\",\n \"onTriggerKeydown\",\n \"open\",\n \"toggle\",\n ] as const;\n\n declare readonly triggerTarget: HTMLButtonElement;\n declare readonly menuTarget: HTMLElement;\n declare readonly itemTargets: HTMLButtonElement[];\n declare readonly hasTriggerTarget: boolean;\n declare readonly hasMenuTarget: boolean;\n\n readonly #timers = new SafeTimeout();\n\n /** Escape-stack membership while open; the shared resolver dismisses via it. */\n readonly #escapeLayer = new EscapeLayer();\n\n /**\n * The item a click started on, recorded in the capture pass. Read once by the\n * delegated bubble listener, which must not re-derive it: consumer handlers run\n * in between and may detach the item.\n */\n #clickOwner: HTMLButtonElement | null = null;\n\n /** Clicks already turned into an activation, so the two paths run it once. */\n readonly #activated = new WeakSet<Event>();\n\n /** Starts closed and registers activation / outside-click listeners. */\n override connect(): void {\n this.close();\n this.element.addEventListener(\"click\", this.#onItemClickCapture, true);\n this.element.addEventListener(\"click\", this.#onDelegatedItemClick);\n this.element.addEventListener(\"keydown\", this.#onDelegatedItemKeydown);\n document.addEventListener(\"click\", this.#onOutsideClick, true);\n }\n\n /** Releases the listeners, stack membership, and any pending Tab-close task. */\n override disconnect(): void {\n this.#timers.clearAll();\n this.#escapeLayer.deactivate();\n this.element.removeEventListener(\"click\", this.#onItemClickCapture, true);\n this.element.removeEventListener(\"click\", this.#onDelegatedItemClick);\n this.element.removeEventListener(\"keydown\", this.#onDelegatedItemKeydown);\n document.removeEventListener(\"click\", this.#onOutsideClick, true);\n }\n\n /** Toggles the menu open/closed. Bound via `data-action` (click). */\n toggle(): void {\n if (this.#isOpen) {\n this.close();\n } else {\n this.open();\n this.#focusFirst();\n }\n }\n\n /** Opens the menu and reflects the expanded state on the trigger. */\n open(): void {\n // A reopen must discard a pending Tab close, or the stale task would slam\n // the freshly opened menu shut on the next tick.\n this.#timers.clearAll();\n if (!this.hasMenuTarget) return;\n this.#escapeLayer.activate(document, {\n onDismiss: () => this.#closeAndRestore(),\n claims: claimsWhileFocusWithin(this.element),\n });\n this.menuTarget.hidden = false;\n if (this.hasTriggerTarget) this.triggerTarget.setAttribute(\"aria-expanded\", \"true\");\n }\n\n /** Closes the menu and reflects the collapsed state on the trigger. */\n close(): void {\n this.#timers.clearAll();\n this.#escapeLayer.deactivate();\n if (!this.hasMenuTarget) return;\n this.menuTarget.hidden = true;\n if (this.hasTriggerTarget) this.triggerTarget.setAttribute(\"aria-expanded\", \"false\");\n }\n\n /**\n * Opens the menu with the keyboard per the APG (Down → first, Up → last).\n *\n * Enter/Space are intentionally not handled here: on a native `<button>`\n * trigger the browser turns them into a click, which already runs\n * {@link toggle} (open + focus first item). Handling them again here would\n * open and then immediately re-toggle the menu.\n */\n onTriggerKeydown(event: KeyboardEvent): void {\n if (event.defaultPrevented) return;\n if (isReservedArrowChord(event)) return;\n if (event.key === \"ArrowDown\") {\n event.preventDefault();\n this.open();\n this.#focusFirst();\n } else if (event.key === \"ArrowUp\") {\n event.preventDefault();\n this.open();\n this.#focusLast();\n }\n }\n\n /** Implements roving focus and closing keys inside the menu. */\n onItemKeydown(event: KeyboardEvent): void {\n this.#handleItemKeydown(event, event.currentTarget);\n }\n\n /**\n * The roving-focus body, shared by the per-element action and its delegated\n * twin. `from` is the item the key belongs to: the bound element for the\n * action, the resolved owner of the event target for the delegate.\n */\n #handleItemKeydown(event: KeyboardEvent, from: EventTarget | null): void {\n // A descendant widget that already claimed the key must not also move the\n // menu's roving focus — composition depends on this yield. It is also what\n // makes the per-element action and the delegated listener idempotent:\n // whichever runs first calls `preventDefault()`, and the other one bows out.\n if (event.defaultPrevented) return;\n if (isReservedArrowChord(event)) return;\n const items = this.#navigableItems;\n const currentIndex = items.indexOf(from as HTMLButtonElement);\n\n switch (event.key) {\n case \"ArrowDown\":\n event.preventDefault();\n if (items.length > 0) items[(currentIndex + 1) % items.length]?.focus();\n break;\n case \"ArrowUp\":\n event.preventDefault();\n if (items.length > 0) items[(currentIndex - 1 + items.length) % items.length]?.focus();\n break;\n case \"Home\":\n event.preventDefault();\n items[0]?.focus();\n break;\n case \"End\":\n event.preventDefault();\n items[items.length - 1]?.focus();\n break;\n case \"Tab\":\n // Per APG, Tab closes the menu but focus moves on naturally (it is not\n // returned to the trigger — that is Escape's job). Closing synchronously\n // would remove the focused item before the browser's default Tab action,\n // which can restart traversal at the document head, so the close is\n // deferred to the next task. The key is deliberately left unclaimed, so\n // this is the one branch both handlers can run: rescheduling the same\n // one-shot close is idempotent.\n this.#timers.clearAll();\n this.#timers.set(() => this.close(), 0);\n break;\n default:\n break;\n }\n }\n\n /**\n * Closes the menu after an item is activated. Bound via `data-action`, and\n * also reached from the delegated listener.\n *\n * Markup that carries the per-element action *and* gets the delegate would run\n * this twice for one gesture. `close()` writes the state hooks (`hidden`,\n * `aria-expanded`), and an identical reassign still queues a MutationRecord,\n * so a second pass is observable to anyone watching them. The event is\n * therefore claimed: the path that gets there first does the work, the other\n * one finds it claimed and returns. A programmatic call with no event always\n * runs.\n */\n activate(event?: Event): void {\n if (event !== undefined) {\n if (this.#activated.has(event)) return;\n this.#activated.add(event);\n }\n this.#closeAndRestore();\n }\n\n /** Closes and returns focus to the trigger (Escape / item-activation path). */\n #closeAndRestore(): void {\n this.close();\n if (this.hasTriggerTarget) this.triggerTarget.focus();\n }\n\n /** Closes the menu when a click lands outside the controller's element. */\n readonly #onOutsideClick = (event: MouseEvent): void => {\n if (this.#isOpen && !this.element.contains(event.target as Node)) this.close();\n };\n\n /**\n * Delegated twin of {@link onItemKeydown}, bound on the controller element.\n *\n * An item that arrives *after* connect — Overflow Menu moves toolbar controls\n * into this menu at runtime — carries whatever `data-action` its author wrote,\n * and that is exactly the binding a consumer forgets, because the markup that\n * declares the item lives nowhere near the menu. Listening on the container\n * makes membership in the `item` target enough to be operable. The per-element\n * action stays supported and is not double-handled: see\n * {@link #handleItemKeydown}.\n */\n readonly #onDelegatedItemKeydown = (event: KeyboardEvent): void => {\n const item = this.#itemFrom(event.target);\n if (item === null) return; // the trigger and menu chrome own their own keys\n this.#handleItemKeydown(event, item);\n };\n\n /**\n * Delegated twin of {@link activate}, for the same reason as the keydown one.\n *\n * It works from the item the capture pass recorded, not from a fresh lookup:\n * by the time a click bubbles up here, a consumer handler may already have\n * detached the row it lives in, and `itemTargets` is a live query that would\n * then resolve nothing — the activation would be lost and the menu left open\n * over an item that no longer exists. `aria-disabled` items never reach this\n * listener at all: the capture pass stops the click outright.\n */\n readonly #onDelegatedItemClick = (event: MouseEvent): void => {\n const item = this.#clickOwner;\n this.#clickOwner = null;\n if (item === null) return;\n this.activate(event);\n };\n\n /** The item target that is, or contains, `node`; `null` when it is neither. */\n #itemFrom(node: EventTarget | null): HTMLButtonElement | null {\n return ownerOf(this.itemTargets, node);\n }\n\n /**\n * First look at every click inside the controller, and the only point at which\n * the DOM is still the one the user clicked. Two jobs: record which item owns\n * the click for the delegate above, and stop an `aria-disabled` command before\n * it reaches consumer handlers (native Enter/Space activation synthesizes a\n * click and is blocked here too).\n */\n readonly #onItemClickCapture = (event: MouseEvent): void => {\n const target = event.target;\n if (!(target instanceof Node)) {\n this.#clickOwner = null;\n return;\n }\n const item = this.#itemFrom(target);\n this.#clickOwner = item;\n if (item === null || item.getAttribute(\"aria-disabled\") !== \"true\") return;\n this.#clickOwner = null;\n event.preventDefault();\n event.stopImmediatePropagation();\n };\n\n /** Moves focus to the first navigable item (no-op if none). */\n #focusFirst(): void {\n this.#navigableItems[0]?.focus();\n }\n\n /** Moves focus to the last navigable item (no-op if none). */\n #focusLast(): void {\n const items = this.#navigableItems;\n items[items.length - 1]?.focus();\n }\n\n /** Menu items eligible for roving focus (excludes disabled / hidden). */\n get #navigableItems(): HTMLButtonElement[] {\n return this.itemTargets.filter((item) => this.#isNavigable(item));\n }\n\n /**\n * An item can take roving focus unless it is `hidden` or a natively `disabled`\n * form control. `aria-disabled` remains focusable for discoverability; capture\n * suppresses activation. CSS-only visibility is the consumer's responsibility.\n */\n #isNavigable(item: HTMLButtonElement): boolean {\n if (item.hasAttribute(\"hidden\")) return false;\n return !item.disabled;\n }\n\n /** Whether the menu is currently visible. */\n get #isOpen(): boolean {\n return this.hasMenuTarget && !this.menuTarget.hidden;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/arrow_step.ts","../../src/utils/escape_layer.ts","../../src/utils/event_owner.ts","../../src/utils/safe_timeout.ts","../../src/utils/state_reason.ts","../../src/controllers/menu_controller.ts"],"names":[],"mappings":";;;;;AA+FO,SAAS,oBAAA,CACd,KAAA,EACA,KAAA,GAAkC,EAAC,EAC1B;AACT,EAAA,IAAI,CAAC,KAAA,CAAM,GAAA,CAAI,UAAA,CAAW,OAAO,GAAG,OAAO,KAAA;AAC3C,EAAA,OACG,KAAA,CAAM,MAAA,IAAU,CAAC,KAAA,CAAM,QAAA,CAAS,KAAK,CAAA,IACrC,KAAA,CAAM,OAAA,IAAW,CAAC,KAAA,CAAM,QAAA,CAAS,MAAM,KACvC,KAAA,CAAM,OAAA,IAAW,CAAC,KAAA,CAAM,QAAA,CAAS,MAAM,CAAA,IACvC,KAAA,CAAM,QAAA,IAAY,CAAC,KAAA,CAAM,QAAA,CAAS,OAAO,CAAA;AAE9C;;;AC1CO,SAAS,uBAAuB,OAAA,EAAiC;AACtE,EAAA,OAAO,MAAM;AACX,IAAA,MAAM,MAAA,GAAS,QAAQ,aAAA,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A,IAAI,CAAC,KAAK,OAAA,EAAS;AACnB,IAAA,MAAM,QAAQ,IAAA,CAAK,eAAA;AACnB,IAAA,KAAA,CAAM,KAAA,CAAM,MAAA,GAAS,CAAC,CAAA,EAAG,KAAA,EAAM;AAAA,EACjC;AAAA;AAAA,EAGA,IAAI,eAAA,GAAuC;AACzC,IAAA,OAAO,IAAA,CAAK,YAAY,MAAA,CAAO,CAAC,SAAS,IAAA,CAAK,YAAA,CAAa,IAAI,CAAC,CAAA;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,aAAa,IAAA,EAAkC;AAC7C,IAAA,IAAI,IAAA,CAAK,YAAA,CAAa,QAAQ,CAAA,EAAG,OAAO,KAAA;AACxC,IAAA,OAAO,CAAC,IAAA,CAAK,QAAA;AAAA,EACf;AAAA;AAAA,EAGA,IAAI,OAAA,GAAmB;AACrB,IAAA,OAAO,IAAA,CAAK,aAAA,IAAiB,CAAC,IAAA,CAAK,UAAA,CAAW,MAAA;AAAA,EAChD;AACF","file":"menu_controller.js","sourcesContent":["import { isRtl } from \"./logical_scroll\";\n\n/**\n * Turns an arrow key into a **logical** step: `+1` for \"next\", `-1` for\n * \"previous\", `0` when the key names neither.\n *\n * APG defines the horizontal pair as *next / previous* and says a vertical\n * arrangement swaps in Down/Up for the same meaning — so the pair is one axis's\n * spelling of an order, and the order reverses with the writing direction. Only\n * the horizontal pair reverses. Down/Up name an axis the writing direction does\n * not mirror, and returning them unchanged is the point: many controllers fold\n * both pairs into one branch, where swapping the branches under RTL would flip\n * the vertical axis too — a bug that reads as \"the arrows work\" until someone\n * presses Down.\n *\n * **Direction is read from the element the caller passes, which should be the\n * container that lays the items out** — not the focused child. A child may carry\n * its own `dir` (an LTR input inside an RTL form is ordinary authoring), and\n * probing per handler makes two handlers disagree at the boundary between them.\n *\n * This decides direction only. Whether the axis is even active (an\n * `orientation=\"horizontal\"` widget ignoring Down/Up), how far the step lands,\n * and what wrapping does all stay with the caller.\n *\n * **It encodes the list-order convention: `ArrowDown` is *next*.** Widgets that\n * pair the arrows by *value* instead — `ArrowUp` meaning \"more\", as a rating or a\n * slider does — must not use this, or their vertical axis inverts. Reverse the\n * horizontal pair on its own there.\n *\n * @example\n * ```ts\n * const step = logicalArrowStep(event.key, this.element);\n * if (step === 0) return;\n * this.#roving.setActive(rovingMove(current, length, step, \"wrap\"), { focus: true });\n * ```\n */\nexport function logicalArrowStep(key: string, element: Element): 1 | -1 | 0 {\n if (key === \"ArrowDown\") return 1;\n if (key === \"ArrowUp\") return -1;\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return 0;\n const forward = isRtl(element) ? \"ArrowLeft\" : \"ArrowRight\";\n return key === forward ? 1 : -1;\n}\n\n/**\n * Rewrites `key` so an existing LTR-shaped branch keeps working under RTL:\n * `ArrowRight` and `ArrowLeft` trade places, everything else passes through.\n *\n * The alternative — negating a delta — silently breaks handlers whose two\n * horizontal branches are **not mirror images**. A grid that clamps one edge but\n * not the other, or a segmented field guarding `index > 0` on one side and\n * `index < length - 1` on the other, ends up applying the wrong guard to the\n * wrong direction. Swapping the key leaves each branch, guards and all, exactly\n * where its author put it.\n *\n * Same rule as {@link logicalArrowStep} about which element to read: pass the\n * container that lays the items out, not the focused child.\n *\n * @example\n * ```ts\n * switch (logicalArrowKey(event.key, this.element)) {\n * case \"ArrowLeft\": // \"previous\" — whatever direction that is on screen\n * ```\n */\nexport function logicalArrowKey(key: string, element: Element): string {\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return key;\n if (!isRtl(element)) return key;\n return key === \"ArrowRight\" ? \"ArrowLeft\" : \"ArrowRight\";\n}\n\n/** Modifiers a widget may claim on an arrow key, named for the `allow` list. */\nexport type ArrowModifier = \"alt\" | \"ctrl\" | \"meta\" | \"shift\";\n\n/**\n * True when an arrow key arrived carrying a modifier the widget must leave to\n * the browser: return without calling `preventDefault()` and without moving any\n * state.\n *\n * A bare arrow belongs to the widget; a chorded one usually does not.\n * `Alt`/`Meta` plus a horizontal arrow is history back/forward on every desktop\n * browser, and a widget that swallows it makes the shortcut work or not\n * depending on where focus happens to sit — a coin-flip the user cannot see.\n *\n * `allow` is for the combinations APG assigns to a pattern **and the widget\n * actually implements** — today only Combobox's optional `Alt+Down`/`Alt+Up`.\n * Listing one the widget does not implement defeats the point: the chord then\n * runs the plain-arrow branch, which is exactly what this guard exists to stop.\n * Non-arrow keys return `false`, so chorded letters and\n * `Control+Home`/`Control+End` are untouched.\n *\n * @example\n * ```ts\n * if (isReservedArrowChord(event)) return;\n * ```\n */\nexport function isReservedArrowChord(\n event: KeyboardEvent,\n allow: readonly ArrowModifier[] = [],\n): boolean {\n if (!event.key.startsWith(\"Arrow\")) return false;\n return (\n (event.altKey && !allow.includes(\"alt\")) ||\n (event.ctrlKey && !allow.includes(\"ctrl\")) ||\n (event.metaKey && !allow.includes(\"meta\")) ||\n (event.shiftKey && !allow.includes(\"shift\"))\n );\n}\n\n/**\n * True when a press arrived carrying any modifier, for the keys the browser and\n * the OS own outright: return without calling `preventDefault()` and without\n * moving any state.\n *\n * `Control+Home` and `Control+End` jump the document to its ends, and a widget\n * that swallows them makes the shortcut work or not depending on where focus\n * happens to sit. {@link isReservedArrowChord} answers the same question for the\n * arrows, but returns `false` for every other key so that this one can decide.\n *\n * There is no `allow` list here on purpose. APG assigns no modifier chord to\n * `Home`/`End`, so a widget that wanted one would be claiming a combination the\n * pattern never gave it.\n *\n * @example\n * ```ts\n * case \"Home\":\n * case \"End\":\n * if (hasModifierChord(event)) return;\n * ```\n */\nexport function hasModifierChord(event: KeyboardEvent): boolean {\n return event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;\n}\n","/**\n * Single resolver for layered Escape dismissal.\n *\n * Every Escape-dismissable overlay layer (modal focus traps, disclosure\n * overlays like dropdown/popover/menu, and hover-triggered transient layers)\n * registers here while it is open. One document-level listener per document\n * resolves each press to exactly one owner and invokes that layer's\n * {@link EscapeLayerOptions.onDismiss} — controllers never listen for a\n * dismissing Escape themselves.\n *\n * @remarks\n * Each document owns an activation-ordered stack. The owner of a press is the\n * **topmost layer whose {@link EscapeLayerOptions.claims} passes**; a layer\n * that declines is transparent, so a background overlay opened behind a modal\n * never blocks it. Because a layer opened from within another is necessarily\n * activated later, LIFO order is also inner-first for nested layers — no DOM\n * inspection is needed.\n *\n * The shared listener runs in the document bubble phase and honors\n * `event.defaultPrevented`, so an element-level widget handler that consumes\n * Escape first (an editor cancelling its edit, a combobox closing its list)\n * always wins over every registered layer — the deepest handler resolves the\n * press. A keydown that is part of an IME composition (`event.isComposing`)\n * cancels the composition, never a layer, and is ignored here for every layer\n * at once.\n *\n * A WeakMap keeps documents collectible; the listener is installed only while\n * a document's stack is non-empty, and controller lifecycle hooks guarantee\n * that disconnected layers never remain registered.\n */\n\n/** Behavior a layer registers when it activates. */\nexport interface EscapeLayerOptions {\n /**\n * Dismisses the layer. Called by the shared resolver when this layer owns a\n * press; the resolver has already consumed the event (`preventDefault()`),\n * so the callback only needs to close and place focus per the widget's\n * contract.\n */\n onDismiss: () => void;\n /**\n * Whether the layer claims the current press. Evaluated per press, so it can\n * depend on live state (e.g. \"focus is inside me or fell to the body\"). A\n * declining layer is skipped and the next layer down is consulted; omitting\n * it means the layer always claims while active.\n */\n claims?: () => boolean;\n}\n\n/** A document's stack plus the one shared listener bound to it. */\ninterface EscapeLayerRegistry {\n stack: EscapeLayer[];\n onKeydown: (event: KeyboardEvent) => void;\n}\n\n/**\n * Claims predicate shared by the click-opened disclosure overlays (dropdown /\n * popover / navigation-menu / menu / context-menu / menubar): the layer claims\n * a press while focus is inside `element`, or after focus fell to the body —\n * a click on non-focusable overlay content blurs to `<body>`, and Escape must\n * still close the overlay (the \"body-focus rescue\"). A press made after focus\n * moved to another interactive element is declined, so closing never yanks\n * focus away from where the user deliberately went.\n */\nexport function claimsWhileFocusWithin(element: Element): () => boolean {\n return () => {\n const active = element.ownerDocument.activeElement;\n return active === null || active === element.ownerDocument.body || element.contains(active);\n };\n}\n\nexport class EscapeLayer {\n static readonly #registries = new WeakMap<Document, EscapeLayerRegistry>();\n\n #ownerDocument: Document | null = null;\n /** Dismissal callback while active; `null` when inactive. */\n #onDismiss: (() => void) | null = null;\n /** Live predicate deciding whether the layer claims a press; `null` = always. */\n #claims: (() => boolean) | null = null;\n\n /**\n * Activates this layer at the top of its document's Escape stack, installing\n * the document's shared resolver listener if this is its first layer.\n * Re-activating an already-active layer moves it to the top.\n */\n activate(ownerDocument: Document = document, options: EscapeLayerOptions): void {\n this.deactivate();\n let registry = EscapeLayer.#registries.get(ownerDocument);\n if (!registry) {\n registry = EscapeLayer.#createRegistry();\n EscapeLayer.#registries.set(ownerDocument, registry);\n ownerDocument.addEventListener(\"keydown\", registry.onKeydown);\n }\n registry.stack.push(this);\n this.#ownerDocument = ownerDocument;\n this.#onDismiss = options.onDismiss;\n this.#claims = options.claims ?? null;\n }\n\n /**\n * Removes this layer from its document's Escape stack, uninstalling the\n * shared listener when the stack empties. Safe to call when inactive.\n */\n deactivate(): void {\n const ownerDocument = this.#ownerDocument;\n if (!ownerDocument) return;\n\n const registry = EscapeLayer.#registries.get(ownerDocument);\n if (registry) {\n const index = registry.stack.lastIndexOf(this);\n if (index >= 0) registry.stack.splice(index, 1);\n if (registry.stack.length === 0) {\n ownerDocument.removeEventListener(\"keydown\", registry.onKeydown);\n EscapeLayer.#registries.delete(ownerDocument);\n }\n }\n this.#ownerDocument = null;\n this.#onDismiss = null;\n this.#claims = null;\n }\n\n /**\n * Whether this active layer would own a press right now: it is the topmost\n * layer whose {@link EscapeLayerOptions.claims} passes. Exposed for tests\n * and diagnostics — production dismissal goes through the shared listener.\n */\n get ownsEscape(): boolean {\n const ownerDocument = this.#ownerDocument;\n if (!ownerDocument) return false;\n const registry = EscapeLayer.#registries.get(ownerDocument);\n if (!registry) return false;\n return EscapeLayer.#resolveOwner(registry.stack) === this;\n }\n\n /** Builds a document's registry with its shared resolver listener. */\n static #createRegistry(): EscapeLayerRegistry {\n const registry: EscapeLayerRegistry = {\n stack: [],\n onKeydown: (event: KeyboardEvent): void => {\n if (event.key !== \"Escape\" || event.defaultPrevented || event.isComposing) return;\n const owner = EscapeLayer.#resolveOwner(registry.stack);\n if (!owner) return;\n event.preventDefault();\n owner.#onDismiss?.();\n },\n };\n return registry;\n }\n\n /** The topmost stack layer whose claims predicate passes, or `null`. */\n static #resolveOwner(stack: EscapeLayer[]): EscapeLayer | null {\n for (let index = stack.length - 1; index >= 0; index--) {\n const layer = stack[index];\n if (!layer) continue;\n if (layer.#claims && !layer.#claims()) continue;\n return layer;\n }\n return null;\n }\n}\n","/**\n * Resolves which of a controller's elements owns a node.\n *\n * A delegated listener hears events from a whole subtree, so the handler's first\n * job is almost always the same question: which item, handle, or control does\n * this `event.target` belong to? The same question comes up for a\n * `MutationRecord.target`, for `document.activeElement`, and for a\n * `relatedTarget` on the way out of a hover region.\n *\n * The answer is `Node.contains()`, which is **inclusive** — an element contains\n * itself — so testing the candidate for identity as well would be redundant.\n *\n * **The guard is what makes this safe to call with a raw event target.**\n * `event.target` is typed `EventTarget | null`, and `contains()` takes a `Node?`:\n * browsers throw `TypeError` for anything else, and `window` — the everyday\n * `EventTarget` that is not a `Node` — is what an event dispatched at it carries.\n * Narrowing here means a caller never has to cast, and the rule cannot drift\n * between the places that ask the question.\n *\n * Scope stays with the caller. These helpers say *which candidate owns the node*,\n * not *whether the node belongs to this controller at all* — a component with\n * nested instances of itself decides that first (by comparing the closest\n * annotated ancestor) and passes the candidates it owns.\n */\n\n/**\n * Index in `candidates` of the first one that is, or contains, `node`.\n *\n * `-1` when none does, when `node` is absent, and when it is an `EventTarget`\n * that is not a `Node`. Candidates are tested in array order, so a nested pair\n * resolves to whichever the caller listed first.\n */\nexport function ownerIndex<T extends Element>(\n candidates: readonly T[],\n node: EventTarget | null | undefined,\n): number {\n if (!(node instanceof Node)) return -1;\n return candidates.findIndex((candidate) => candidate.contains(node));\n}\n\n/**\n * The first candidate that is, or contains, `node`; `null` when none does.\n *\n * A miss indexes the array at `-1`, which reads as `undefined` and lands on the\n * same `null` the absent cases produce.\n */\nexport function ownerOf<T extends Element>(\n candidates: readonly T[],\n node: EventTarget | null | undefined,\n): T | null {\n return candidates[ownerIndex(candidates, node)] ?? null;\n}\n","/**\n * Self-cleaning timer registries shared by Stimeo controllers.\n *\n * Stimulus controllers frequently schedule `setTimeout` / `setInterval` work\n * (auto-dismiss, debouncing, polling). When the element leaves the DOM — a\n * Turbo Drive navigation, a Turbo Stream replacement, or any `disconnect()` —\n * orphaned timers keep firing against a detached controller, leaking memory and\n * mutating stale state. {@link SafeTimeout} and {@link SafeInterval} track every\n * timer they create so a single {@link TimerRegistry.clearAll | clearAll()} call\n * in `disconnect()` tears them all down.\n *\n * These are intentionally low-level primitives: they own *registration and\n * cleanup only*. Higher-level policy (pause/resume, remaining-time accounting)\n * stays in the individual controllers so per-widget semantics are not flattened\n * into a lowest-common-denominator helper.\n */\n\n/**\n * Largest delay a timer can hold: the platform stores it in a 32-bit signed\n * integer, and anything larger overflows to `1`, so a delay meant to be far in\n * the future fires almost immediately. A declared delay above this bound names\n * no delay at all, and a controller reading one falls back to its default.\n */\nexport const MAX_TIMER_DELAY_MS = 2_147_483_647;\n\n/**\n * Shared registry bookkeeping for the timeout/interval variants.\n *\n * Subclasses provide the scheduling primitive ({@link schedule}) and its matching\n * canceller ({@link cancel}); this base owns the set of live ids plus the\n * per-id and bulk teardown shared by both.\n */\nabstract class TimerRegistry {\n /** Live timer ids that have not yet been cleared (or, for timeouts, fired). */\n protected readonly ids = new Set<number>();\n\n /** Schedules the underlying platform timer and returns its id. */\n protected abstract schedule(callback: () => void, delay: number): number;\n\n /** Cancels the underlying platform timer for `id`. */\n protected abstract cancel(id: number): void;\n\n /**\n * Cancels a single tracked timer.\n *\n * No-ops if the id is unknown (already cleared, fired, or never owned by this\n * registry), so callers can clear defensively without guarding.\n */\n clear(id: number): void {\n if (this.ids.delete(id)) {\n this.cancel(id);\n }\n }\n\n /**\n * Cancels every tracked timer. Call this from a controller's `disconnect()`\n * to guarantee no timer outlives the element.\n */\n clearAll(): void {\n for (const id of this.ids) {\n this.cancel(id);\n }\n this.ids.clear();\n }\n\n /** Number of timers currently tracked (pending). */\n get size(): number {\n return this.ids.size;\n }\n}\n\n/**\n * `setTimeout` wrapper that auto-forgets each timer once it fires and supports\n * bulk teardown on disconnect.\n *\n * @example\n * ```ts\n * #timers = new SafeTimeout();\n *\n * connect() {\n * this.#timers.set(() => this.dismiss(), 5000);\n * }\n *\n * disconnect() {\n * this.#timers.clearAll();\n * }\n * ```\n */\nexport class SafeTimeout extends TimerRegistry {\n /**\n * Schedules `callback` after `delay` ms and returns the timer id.\n *\n * The id is removed from the registry automatically when the timeout fires,\n * so {@link TimerRegistry.size | size} reflects only still-pending timers.\n */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(() => {\n this.ids.delete(id);\n callback();\n }, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setTimeout(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearTimeout(id);\n }\n}\n\n/**\n * `setInterval` wrapper that tracks every interval for bulk teardown on\n * disconnect. Unlike {@link SafeTimeout}, intervals are retained until they are\n * explicitly cleared because they fire repeatedly.\n *\n * @example\n * ```ts\n * #intervals = new SafeInterval();\n *\n * connect() {\n * this.#intervals.set(() => this.tick(), 1000);\n * }\n *\n * disconnect() {\n * this.#intervals.clearAll();\n * }\n * ```\n */\nexport class SafeInterval extends TimerRegistry {\n /** Schedules a repeating `callback` every `delay` ms and returns the timer id. */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(callback, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setInterval(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearInterval(id);\n }\n}\n","/**\n * Why a component's public open/closed state moved, carried as `detail.reason`\n * on the state event that reports the move.\n *\n * The attribute a component publishes (`aria-expanded`, `hidden`, `data-state`)\n * only says *what* the state is now. A subscriber that mirrors the state\n * elsewhere, or reports it, needs *why*: closing on `Escape` and closing because\n * the consumer called the action are the same attribute write and different\n * events to the page around it.\n *\n * `\"api\"` is the one every subscriber has to look at. A close the consumer asked\n * for arrives back at their own listener, so a listener that closes something\n * else on `close` loops unless it ignores its own calls.\n *\n * | Reason | The state moved because |\n * | --- | --- |\n * | `\"user\"` | a control of this component was operated |\n * | `\"select\"` | an item inside it was activated |\n * | `\"escape\"` | `Escape` was pressed and this layer owned it |\n * | `\"outside\"` | a pointer landed outside it, or on its backdrop |\n * | `\"focus\"` | focus entered or left it |\n * | `\"pointer\"` | the pointer entered or left it |\n * | `\"scroll\"` | a tracked scroll container scrolled |\n * | `\"api\"` | a public action was called with no DOM event |\n */\nexport type StateReason =\n | \"user\"\n | \"select\"\n | \"escape\"\n | \"outside\"\n | \"focus\"\n | \"pointer\"\n | \"scroll\"\n | \"api\";\n\n/** Focus modality: the events a focus move delivers to an action. */\nconst FOCUS_EVENTS = new Set([\"blur\", \"focus\", \"focusin\", \"focusout\"]);\n\n/** Pointer modality: the crossing events an action is bound to for hover. */\nconst POINTER_EVENTS = new Set([\"mouseenter\", \"mouseleave\", \"pointerenter\", \"pointerleave\"]);\n\n/**\n * Reads the interaction behind a **public action** from the DOM event it was\n * handed.\n *\n * Stimulus always passes the event to an action it invoked from `data-action`,\n * and a consumer calling the method themselves passes nothing — which is what\n * separates `\"api\"` from the rest.\n *\n * Only an action entry may resolve a reason this way. Inside the component the\n * event type no longer identifies the interaction: one `click` is the trigger\n * being pressed, the page outside being pressed, and an item being activated,\n * and those paths pass their own reason instead.\n *\n * @param event - The event the action received, if any.\n * @returns `\"api\"` with no event, else the modality the event type names, else\n * `\"user\"`.\n *\n * @example\n * ```ts\n * toggle(event?: Event): void {\n * this.#apply(!this.#isOpen, stateReasonFor(event));\n * }\n * ```\n */\nexport function stateReasonFor(event?: Event | null): \"user\" | \"focus\" | \"pointer\" | \"api\" {\n if (!event) return \"api\";\n if (FOCUS_EVENTS.has(event.type)) return \"focus\";\n if (POINTER_EVENTS.has(event.type)) return \"pointer\";\n return \"user\";\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { isReservedArrowChord } from \"../utils/arrow_step\";\nimport { claimsWhileFocusWithin, EscapeLayer } from \"../utils/escape_layer\";\nimport { ownerOf } from \"../utils/event_owner\";\nimport { SafeTimeout } from \"../utils/safe_timeout\";\nimport { type StateReason, stateReasonFor } from \"../utils/state_reason\";\n\n/**\n * Headless, accessible menu button behavior.\n *\n * Markup contract (identifier: `stimeo--menu`):\n * <div data-controller=\"stimeo--menu\">\n * <button id=\"menu-trigger\" data-stimeo--menu-target=\"trigger\"\n * data-action=\"click->stimeo--menu#toggle\n * keydown->stimeo--menu#onTriggerKeydown\"\n * aria-haspopup=\"menu\" aria-expanded=\"false\" aria-controls=\"menu\">\n * Actions\n * </button>\n * <ul id=\"menu\" role=\"menu\" aria-labelledby=\"menu-trigger\"\n * data-stimeo--menu-target=\"menu\" hidden>\n * <li role=\"none\">\n * <button role=\"menuitem\" tabindex=\"-1\"\n * data-stimeo--menu-target=\"item\">…</button>\n * </li>\n * </ul>\n * </div>\n *\n * The trigger's two actions are required. Items need none: their click and key\n * handling is delegated from the controller element, so an item added, moved, or\n * server-rendered after connect works without the consumer wiring anything onto\n * it. The per-element form (`click->stimeo--menu#activate` /\n * `keydown->stimeo--menu#onItemKeydown`) is supported alongside it. A\n * focus-moving key runs once (the action claims it and the delegate stands\n * down), and `activate`, reachable on both paths, claims the click so one\n * gesture activates once. See the delegated click listener below.\n *\n * Implements the WAI-ARIA APG **Menu Button** pattern (a button that opens a menu\n * of commands). Unlike `stimeo--dropdown` (a disclosure for arbitrary content),\n * this is a true `role=\"menu\"` widget with roving focus across `role=\"menuitem\"`\n * children.\n *\n * @remarks\n * Behavior only — the core controller owns no placement. Consumers can use static\n * CSS or compose the menu with the opt-in `stimeo-ui/positioning` entrypoint for\n * viewport-aware placement. State is exposed via `aria-expanded` and the menu's\n * `hidden` attribute.\n *\n * Behavior provided:\n * - Click the trigger to toggle; `ArrowDown`/`ArrowUp` open and focus the\n * first/last item.\n * - Within the menu, `ArrowDown`/`ArrowUp` move focus (wrapping), `Home`/`End`\n * jump to the first/last item, `Tab` lets the browser move focus first and\n * then closes on the next task, and activating an enabled item closes the menu.\n * - `Escape` closes and returns focus to the trigger. While open the menu is a\n * layer on the shared `EscapeLayer` stack; it claims a press only while\n * focus is inside the controller or fell to the body, so one keypress closes\n * exactly one layer and a newer layer (e.g. a tooltip shown over an item) is\n * dismissed first.\n * - A click outside the controller closes the menu without moving focus away\n * from the clicked element.\n * - Each move of the open state is reported: `stimeo--menu:open` and\n * `stimeo--menu:close` dispatch `{ reason: StateReason }`, after the state\n * attributes are written. Both are informational, so neither is cancelable. A\n * call that leaves the state where it already was, the normalization in\n * {@link connect}, and {@link disconnect} are all silent.\n *\n * Roving focus skips `hidden` and natively `disabled` items. An\n * `aria-disabled=\"true\"` item remains discoverable by arrow-key focus, while its\n * activation is suppressed in the capture phase.\n */\nexport class MenuController extends Controller<HTMLElement> {\n static override targets = [\"trigger\", \"menu\", \"item\"];\n static actions = [\n \"activate\",\n \"close\",\n \"onItemKeydown\",\n \"onTriggerKeydown\",\n \"open\",\n \"toggle\",\n ] as const;\n static events = [\"close\", \"open\"] as const;\n\n declare readonly triggerTarget: HTMLButtonElement;\n declare readonly menuTarget: HTMLElement;\n declare readonly itemTargets: HTMLButtonElement[];\n declare readonly hasTriggerTarget: boolean;\n declare readonly hasMenuTarget: boolean;\n\n readonly #timers = new SafeTimeout();\n\n /** Escape-stack membership while open; the shared resolver dismisses via it. */\n readonly #escapeLayer = new EscapeLayer();\n\n /**\n * The item a click started on, recorded in the capture pass. Read once by the\n * delegated bubble listener, which must not re-derive it: consumer handlers run\n * in between and may detach the item.\n */\n #clickOwner: HTMLButtonElement | null = null;\n\n /** Clicks already turned into an activation, so the two paths run it once. */\n readonly #activated = new WeakSet<Event>();\n\n /** Whether state moves are reported: set once `connect()` settled the baseline. */\n #reporting = false;\n\n /** Starts closed and registers activation / outside-click listeners. */\n override connect(): void {\n this.#close(\"api\");\n this.element.addEventListener(\"click\", this.#onItemClickCapture, true);\n this.element.addEventListener(\"click\", this.#onDelegatedItemClick);\n this.element.addEventListener(\"keydown\", this.#onDelegatedItemKeydown);\n document.addEventListener(\"click\", this.#onOutsideClick, true);\n this.#reporting = true;\n }\n\n /** Releases the listeners, stack membership, and any pending Tab-close task. */\n override disconnect(): void {\n this.#reporting = false;\n this.#timers.clearAll();\n this.#escapeLayer.deactivate();\n this.element.removeEventListener(\"click\", this.#onItemClickCapture, true);\n this.element.removeEventListener(\"click\", this.#onDelegatedItemClick);\n this.element.removeEventListener(\"keydown\", this.#onDelegatedItemKeydown);\n document.removeEventListener(\"click\", this.#onOutsideClick, true);\n }\n\n /** Toggles the menu open/closed. Bound via `data-action` (click). */\n toggle(event?: Event): void {\n if (this.#isOpen) {\n this.close(event);\n } else {\n this.open(event);\n this.#focusFirst();\n }\n }\n\n /** Opens the menu and reflects the expanded state on the trigger. */\n open(event?: Event): void {\n this.#open(stateReasonFor(event));\n }\n\n /** Closes the menu and reflects the collapsed state on the trigger. */\n close(event?: Event): void {\n this.#close(stateReasonFor(event));\n }\n\n /** Opens the menu, reflects the expanded state, and reports a move. */\n #open(reason: StateReason): void {\n // A reopen must discard a pending Tab close, or the stale task would slam\n // the freshly opened menu shut on the next tick.\n this.#timers.clearAll();\n if (!this.hasMenuTarget) return;\n const was = this.#isOpen;\n this.#escapeLayer.activate(document, {\n onDismiss: () => this.#closeAndRestore(\"escape\"),\n claims: claimsWhileFocusWithin(this.element),\n });\n this.menuTarget.hidden = false;\n if (this.hasTriggerTarget) this.triggerTarget.setAttribute(\"aria-expanded\", \"true\");\n if (!was && this.#reporting) this.dispatch(\"open\", { detail: { reason }, cancelable: false });\n }\n\n /** Closes the menu, reflects the collapsed state, and reports a move. */\n #close(reason: StateReason): void {\n this.#timers.clearAll();\n this.#escapeLayer.deactivate();\n if (!this.hasMenuTarget) return;\n const was = this.#isOpen;\n this.menuTarget.hidden = true;\n if (this.hasTriggerTarget) this.triggerTarget.setAttribute(\"aria-expanded\", \"false\");\n if (was && this.#reporting) this.dispatch(\"close\", { detail: { reason }, cancelable: false });\n }\n\n /**\n * Opens the menu with the keyboard per the APG (Down → first, Up → last).\n *\n * Enter/Space are intentionally not handled here: on a native `<button>`\n * trigger the browser turns them into a click, which already runs\n * {@link toggle} (open + focus first item). Handling them again here would\n * open and then immediately re-toggle the menu.\n */\n onTriggerKeydown(event: KeyboardEvent): void {\n if (event.defaultPrevented) return;\n if (isReservedArrowChord(event)) return;\n if (event.key === \"ArrowDown\") {\n event.preventDefault();\n this.open(event);\n this.#focusFirst();\n } else if (event.key === \"ArrowUp\") {\n event.preventDefault();\n this.open(event);\n this.#focusLast();\n }\n }\n\n /** Implements roving focus and closing keys inside the menu. */\n onItemKeydown(event: KeyboardEvent): void {\n this.#handleItemKeydown(event, event.currentTarget);\n }\n\n /**\n * The roving-focus body, shared by the per-element action and its delegated\n * twin. `from` is the item the key belongs to: the bound element for the\n * action, the resolved owner of the event target for the delegate.\n */\n #handleItemKeydown(event: KeyboardEvent, from: EventTarget | null): void {\n // A descendant widget that already claimed the key must not also move the\n // menu's roving focus — composition depends on this yield. It is also what\n // makes the per-element action and the delegated listener idempotent:\n // whichever runs first calls `preventDefault()`, and the other one bows out.\n if (event.defaultPrevented) return;\n if (isReservedArrowChord(event)) return;\n const items = this.#navigableItems;\n const currentIndex = items.indexOf(from as HTMLButtonElement);\n\n switch (event.key) {\n case \"ArrowDown\":\n event.preventDefault();\n if (items.length > 0) items[(currentIndex + 1) % items.length]?.focus();\n break;\n case \"ArrowUp\":\n event.preventDefault();\n if (items.length > 0) items[(currentIndex - 1 + items.length) % items.length]?.focus();\n break;\n case \"Home\":\n event.preventDefault();\n items[0]?.focus();\n break;\n case \"End\":\n event.preventDefault();\n items[items.length - 1]?.focus();\n break;\n case \"Tab\":\n // Per APG, Tab closes the menu but focus moves on naturally (it is not\n // returned to the trigger — that is Escape's job). Closing synchronously\n // would remove the focused item before the browser's default Tab action,\n // which can restart traversal at the document head, so the close is\n // deferred to the next task. The key is deliberately left unclaimed, so\n // this is the one branch both handlers can run: rescheduling the same\n // one-shot close is idempotent.\n this.#timers.clearAll();\n this.#timers.set(() => this.#close(\"focus\"), 0);\n break;\n default:\n break;\n }\n }\n\n /**\n * Closes the menu after an item is activated. Bound via `data-action`, and\n * also reached from the delegated listener.\n *\n * Markup that carries the per-element action *and* gets the delegate would run\n * this twice for one gesture. `close()` writes the state hooks (`hidden`,\n * `aria-expanded`), and an identical reassign still queues a MutationRecord,\n * so a second pass is observable to anyone watching them. The event is\n * therefore claimed: the path that gets there first does the work, the other\n * one finds it claimed and returns. A programmatic call with no event always\n * runs.\n */\n activate(event?: Event): void {\n if (event !== undefined) {\n if (this.#activated.has(event)) return;\n this.#activated.add(event);\n }\n this.#closeAndRestore(\"select\");\n }\n\n /** Closes and returns focus to the trigger (Escape / item-activation path). */\n #closeAndRestore(reason: StateReason): void {\n this.#close(reason);\n if (this.hasTriggerTarget) this.triggerTarget.focus();\n }\n\n /** Closes the menu when a click lands outside the controller's element. */\n readonly #onOutsideClick = (event: MouseEvent): void => {\n if (this.#isOpen && !this.element.contains(event.target as Node)) this.#close(\"outside\");\n };\n\n /**\n * Delegated twin of {@link onItemKeydown}, bound on the controller element.\n *\n * An item that arrives *after* connect — `stimeo--overflow-menu` moves toolbar controls\n * into this menu at runtime — carries whatever `data-action` its author wrote,\n * and that is exactly the binding a consumer forgets, because the markup that\n * declares the item lives nowhere near the menu. Listening on the container\n * makes membership in the `item` target enough to be operable. The per-element\n * action stays supported and is not double-handled: see\n * {@link #handleItemKeydown}.\n */\n readonly #onDelegatedItemKeydown = (event: KeyboardEvent): void => {\n const item = this.#itemFrom(event.target);\n if (item === null) return; // the trigger and menu chrome own their own keys\n this.#handleItemKeydown(event, item);\n };\n\n /**\n * Delegated twin of {@link activate}, for the same reason as the keydown one.\n *\n * It works from the item the capture pass recorded, not from a fresh lookup:\n * by the time a click bubbles up here, a consumer handler may already have\n * detached the row it lives in, and `itemTargets` is a live query that would\n * then resolve nothing — the activation would be lost and the menu left open\n * over an item that no longer exists. `aria-disabled` items never reach this\n * listener at all: the capture pass stops the click outright.\n */\n readonly #onDelegatedItemClick = (event: MouseEvent): void => {\n const item = this.#clickOwner;\n this.#clickOwner = null;\n if (item === null) return;\n this.activate(event);\n };\n\n /** The item target that is, or contains, `node`; `null` when it is neither. */\n #itemFrom(node: EventTarget | null): HTMLButtonElement | null {\n return ownerOf(this.itemTargets, node);\n }\n\n /**\n * First look at every click inside the controller, and the only point at which\n * the DOM is still the one the user clicked. Two jobs: record which item owns\n * the click for the delegate above, and stop an `aria-disabled` command before\n * it reaches consumer handlers (native Enter/Space activation synthesizes a\n * click and is blocked here too).\n */\n readonly #onItemClickCapture = (event: MouseEvent): void => {\n const target = event.target;\n if (!(target instanceof Node)) {\n this.#clickOwner = null;\n return;\n }\n const item = this.#itemFrom(target);\n this.#clickOwner = item;\n if (item === null || item.getAttribute(\"aria-disabled\") !== \"true\") return;\n this.#clickOwner = null;\n event.preventDefault();\n event.stopImmediatePropagation();\n };\n\n /** Moves focus to the first navigable item (no-op if none). */\n #focusFirst(): void {\n // A subscriber may close the menu from the `open` handler; focusing then puts\n // the caret on an item nobody can see.\n if (!this.#isOpen) return;\n this.#navigableItems[0]?.focus();\n }\n\n /** Moves focus to the last navigable item (no-op if none). */\n #focusLast(): void {\n // See {@link MenuController.#focusFirst}.\n if (!this.#isOpen) return;\n const items = this.#navigableItems;\n items[items.length - 1]?.focus();\n }\n\n /** Menu items eligible for roving focus (excludes disabled / hidden). */\n get #navigableItems(): HTMLButtonElement[] {\n return this.itemTargets.filter((item) => this.#isNavigable(item));\n }\n\n /**\n * An item can take roving focus unless it is `hidden` or a natively `disabled`\n * form control. `aria-disabled` remains focusable for discoverability; capture\n * suppresses activation. CSS-only visibility is the consumer's responsibility.\n */\n #isNavigable(item: HTMLButtonElement): boolean {\n if (item.hasAttribute(\"hidden\")) return false;\n return !item.disabled;\n }\n\n /** Whether the menu is currently visible. */\n get #isOpen(): boolean {\n return this.hasMenuTarget && !this.menuTarget.hidden;\n }\n}\n"]}
|
|
@@ -78,11 +78,22 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
78
78
|
* from the live targets: expanded flags, menu visibility, the single Tab stop, and
|
|
79
79
|
* Escape-stack membership are re-derived whenever a top/menu target is added or
|
|
80
80
|
* removed, and whenever `disabled`/`hidden` changes under the menubar.
|
|
81
|
+
*
|
|
82
|
+
* Each move of a menu's open state is reported: `stimeo--menubar:open` and
|
|
83
|
+
* `stimeo--menubar:close` dispatch
|
|
84
|
+
* `{ reason: StateReason, index: number, menu: HTMLElement }` — `index` is the
|
|
85
|
+
* top item's position in `topTargets` — after the state attributes are written.
|
|
86
|
+
* Both are informational, so neither is cancelable. Moving along the menubar
|
|
87
|
+
* with a menu open reports the outgoing `close` before the incoming `open`. A
|
|
88
|
+
* call that leaves a menu where it already was, the normalization in
|
|
89
|
+
* {@link connect}, the reconciliation that follows target churn, and
|
|
90
|
+
* {@link disconnect} are all silent.
|
|
81
91
|
*/
|
|
82
92
|
declare class MenubarController extends Controller<HTMLElement> {
|
|
83
93
|
#private;
|
|
84
94
|
static targets: string[];
|
|
85
95
|
static actions: readonly ["activate", "onItemKeydown", "onTopKeydown", "toggle"];
|
|
96
|
+
static events: readonly ["close", "open"];
|
|
86
97
|
readonly topTargets: HTMLButtonElement[];
|
|
87
98
|
readonly menuTargets: HTMLElement[];
|
|
88
99
|
readonly itemTargets: HTMLButtonElement[];
|
|
@@ -200,6 +200,16 @@ var SafeTimeout = class extends TimerRegistry {
|
|
|
200
200
|
}
|
|
201
201
|
};
|
|
202
202
|
|
|
203
|
+
// src/utils/state_reason.ts
|
|
204
|
+
var FOCUS_EVENTS = /* @__PURE__ */ new Set(["blur", "focus", "focusin", "focusout"]);
|
|
205
|
+
var POINTER_EVENTS = /* @__PURE__ */ new Set(["mouseenter", "mouseleave", "pointerenter", "pointerleave"]);
|
|
206
|
+
function stateReasonFor(event) {
|
|
207
|
+
if (!event) return "api";
|
|
208
|
+
if (FOCUS_EVENTS.has(event.type)) return "focus";
|
|
209
|
+
if (POINTER_EVENTS.has(event.type)) return "pointer";
|
|
210
|
+
return "user";
|
|
211
|
+
}
|
|
212
|
+
|
|
203
213
|
// src/utils/typeahead.ts
|
|
204
214
|
var TYPEAHEAD_RESET_MS = 500;
|
|
205
215
|
var Typeahead = class {
|
|
@@ -263,6 +273,7 @@ var STATE_ATTRIBUTES = ["disabled", "hidden"];
|
|
|
263
273
|
var MenubarController = class extends Controller {
|
|
264
274
|
static targets = ["top", "menu", "item"];
|
|
265
275
|
static actions = ["activate", "onItemKeydown", "onTopKeydown", "toggle"];
|
|
276
|
+
static events = ["close", "open"];
|
|
266
277
|
/** Roving tabindex across the top-level menuitems (one Tab stop). */
|
|
267
278
|
#roving = new RovingTabindex(() => this.topTargets);
|
|
268
279
|
/** Typeahead query and its idle-reset timer (scoped to the open menu). */
|
|
@@ -281,6 +292,8 @@ var MenubarController = class extends Controller {
|
|
|
281
292
|
* stop on mount and from resurrecting one after teardown.
|
|
282
293
|
*/
|
|
283
294
|
#connected = false;
|
|
295
|
+
/** Whether state moves are reported: set once `connect()` settled the baseline. */
|
|
296
|
+
#reporting = false;
|
|
284
297
|
/** The element inside the menubar that last took DOM focus, if any. */
|
|
285
298
|
#focused = null;
|
|
286
299
|
/**
|
|
@@ -314,7 +327,7 @@ var MenubarController = class extends Controller {
|
|
|
314
327
|
* close the menu.
|
|
315
328
|
*/
|
|
316
329
|
connect() {
|
|
317
|
-
this.#closeAllMenus();
|
|
330
|
+
this.#closeAllMenus("api");
|
|
318
331
|
this.#reconcile();
|
|
319
332
|
this.element.addEventListener("click", this.#onDisabledClickCapture, true);
|
|
320
333
|
this.element.addEventListener("focusin", this.#onFocusIn);
|
|
@@ -330,10 +343,12 @@ var MenubarController = class extends Controller {
|
|
|
330
343
|
});
|
|
331
344
|
}
|
|
332
345
|
this.#connected = true;
|
|
346
|
+
this.#reporting = true;
|
|
333
347
|
}
|
|
334
348
|
/** Removes the listeners, stack membership, and any pending timer (typeahead / Tab close). */
|
|
335
349
|
disconnect() {
|
|
336
350
|
this.#connected = false;
|
|
351
|
+
this.#reporting = false;
|
|
337
352
|
this.#escapeLayer.deactivate();
|
|
338
353
|
this.#layerActive = false;
|
|
339
354
|
this.element.removeEventListener("click", this.#onDisabledClickCapture, true);
|
|
@@ -395,10 +410,11 @@ var MenubarController = class extends Controller {
|
|
|
395
410
|
/** Toggles a top item's menu. Bound via `data-action` (click on the top item). */
|
|
396
411
|
toggle(event) {
|
|
397
412
|
const top = event.currentTarget;
|
|
413
|
+
const reason = stateReasonFor(event);
|
|
398
414
|
if (this.#isExpanded(top)) {
|
|
399
|
-
this.#closeMenu(top);
|
|
415
|
+
this.#closeMenu(top, reason);
|
|
400
416
|
} else {
|
|
401
|
-
this.#openMenu(top, "first");
|
|
417
|
+
this.#openMenu(top, "first", reason);
|
|
402
418
|
}
|
|
403
419
|
}
|
|
404
420
|
/** Keyboard handling while focus is on a top item. */
|
|
@@ -414,27 +430,27 @@ var MenubarController = class extends Controller {
|
|
|
414
430
|
switch (event.key) {
|
|
415
431
|
case "ArrowRight":
|
|
416
432
|
event.preventDefault();
|
|
417
|
-
this.#gotoTop(tops[(index + step + length) % length], anyOpen);
|
|
433
|
+
this.#gotoTop(tops[(index + step + length) % length], anyOpen, "user");
|
|
418
434
|
break;
|
|
419
435
|
case "ArrowLeft":
|
|
420
436
|
event.preventDefault();
|
|
421
|
-
this.#gotoTop(tops[(index - step + length) % length], anyOpen);
|
|
437
|
+
this.#gotoTop(tops[(index - step + length) % length], anyOpen, "user");
|
|
422
438
|
break;
|
|
423
439
|
case "ArrowDown":
|
|
424
440
|
event.preventDefault();
|
|
425
|
-
this.#openMenu(tops[index], "first");
|
|
441
|
+
this.#openMenu(tops[index], "first", "user");
|
|
426
442
|
break;
|
|
427
443
|
case "ArrowUp":
|
|
428
444
|
event.preventDefault();
|
|
429
|
-
this.#openMenu(tops[index], "last");
|
|
445
|
+
this.#openMenu(tops[index], "last", "user");
|
|
430
446
|
break;
|
|
431
447
|
case "Home":
|
|
432
448
|
event.preventDefault();
|
|
433
|
-
this.#gotoTop(tops[0], anyOpen);
|
|
449
|
+
this.#gotoTop(tops[0], anyOpen, "user");
|
|
434
450
|
break;
|
|
435
451
|
case "End":
|
|
436
452
|
event.preventDefault();
|
|
437
|
-
this.#gotoTop(tops[length - 1], anyOpen);
|
|
453
|
+
this.#gotoTop(tops[length - 1], anyOpen, "user");
|
|
438
454
|
break;
|
|
439
455
|
case "Tab":
|
|
440
456
|
this.#closeMenusSoon();
|
|
@@ -492,14 +508,14 @@ var MenubarController = class extends Controller {
|
|
|
492
508
|
const item = event.currentTarget;
|
|
493
509
|
const menu = item.closest("[role='menu']");
|
|
494
510
|
const top = this.#topFor(menu);
|
|
495
|
-
this.#closeAllMenus();
|
|
511
|
+
this.#closeAllMenus("select");
|
|
496
512
|
this.#focusTop(top);
|
|
497
513
|
}
|
|
498
514
|
/** Moves the roving focus to `top`, opening its menu when one was open. */
|
|
499
|
-
#gotoTop(top, reopen) {
|
|
515
|
+
#gotoTop(top, reopen, reason) {
|
|
500
516
|
if (!top) return;
|
|
501
517
|
if (reopen) {
|
|
502
|
-
this.#openMenu(top, "first");
|
|
518
|
+
this.#openMenu(top, "first", reason);
|
|
503
519
|
} else {
|
|
504
520
|
this.#roving.setActive(this.topTargets.indexOf(top), { focus: true });
|
|
505
521
|
}
|
|
@@ -526,20 +542,23 @@ var MenubarController = class extends Controller {
|
|
|
526
542
|
* this "open a menu" path. A dangling top is still an ordinary roving
|
|
527
543
|
* destination while nothing is open.
|
|
528
544
|
*/
|
|
529
|
-
#openMenu(top, focus) {
|
|
545
|
+
#openMenu(top, focus, reason) {
|
|
530
546
|
if (!top) return;
|
|
531
547
|
const menu = this.#menuFor(top);
|
|
532
548
|
if (!menu || this.#isActivationBlocked(top)) {
|
|
533
549
|
if (menu || !top.hasAttribute("aria-controls")) {
|
|
534
|
-
this.#closeAllMenus();
|
|
550
|
+
this.#closeAllMenus(reason);
|
|
535
551
|
this.#focusTop(top);
|
|
536
552
|
}
|
|
537
553
|
return;
|
|
538
554
|
}
|
|
539
555
|
this.#timers.clearAll();
|
|
540
|
-
this.#
|
|
556
|
+
const was = this.#isExpanded(top);
|
|
557
|
+
this.#closeAllMenus(reason, top);
|
|
541
558
|
menu.hidden = false;
|
|
542
559
|
top.setAttribute("aria-expanded", "true");
|
|
560
|
+
if (!was) this.#report("open", top, menu, reason);
|
|
561
|
+
if (!this.#isExpanded(top)) return;
|
|
543
562
|
this.#escapeLayer.activate(document, {
|
|
544
563
|
onDismiss: () => this.#dismissOpenMenu(),
|
|
545
564
|
claims: claimsWhileFocusWithin(this.element)
|
|
@@ -554,19 +573,32 @@ var MenubarController = class extends Controller {
|
|
|
554
573
|
* no menu (a plain command in an otherwise popup-bearing menubar) is left alone
|
|
555
574
|
* — stamping `aria-expanded="false"` on it would announce a popup it lacks.
|
|
556
575
|
*/
|
|
557
|
-
#closeMenu(top) {
|
|
576
|
+
#closeMenu(top, reason, silent = false) {
|
|
558
577
|
if (!top) return;
|
|
559
578
|
const menu = this.#menuFor(top);
|
|
560
579
|
if (!menu) return;
|
|
580
|
+
const was = this.#isExpanded(top);
|
|
561
581
|
menu.hidden = true;
|
|
562
582
|
top.setAttribute("aria-expanded", "false");
|
|
583
|
+
if (was && !silent) this.#report("close", top, menu, reason);
|
|
563
584
|
this.#syncEscapeLayer();
|
|
564
585
|
}
|
|
565
|
-
/**
|
|
566
|
-
|
|
567
|
-
|
|
586
|
+
/**
|
|
587
|
+
* Closes every menu and resets the typeahead query. `except` still has its
|
|
588
|
+
* attributes rewritten — the caller is about to reopen it — but its move is
|
|
589
|
+
* left for that caller to report.
|
|
590
|
+
*/
|
|
591
|
+
#closeAllMenus(reason, except = null) {
|
|
592
|
+
for (const top of this.topTargets) this.#closeMenu(top, reason, top === except);
|
|
568
593
|
this.#typeahead.reset();
|
|
569
594
|
}
|
|
595
|
+
/** Names the menu that moved, so a subscriber does not have to re-derive it. */
|
|
596
|
+
#report(name, top, menu, reason) {
|
|
597
|
+
if (!this.#reporting) return;
|
|
598
|
+
const detail = { reason, index: this.topTargets.indexOf(top), menu };
|
|
599
|
+
if (name === "open") this.dispatch("open", { detail, cancelable: false });
|
|
600
|
+
else this.dispatch("close", { detail, cancelable: false });
|
|
601
|
+
}
|
|
570
602
|
/**
|
|
571
603
|
* Closes every menu on the next task instead of synchronously.
|
|
572
604
|
*
|
|
@@ -577,7 +609,7 @@ var MenubarController = class extends Controller {
|
|
|
577
609
|
#closeMenusSoon() {
|
|
578
610
|
if (!this.#isAnyOpen) return;
|
|
579
611
|
this.#timers.clearAll();
|
|
580
|
-
this.#timers.set(() => this.#closeAllMenus(), 0);
|
|
612
|
+
this.#timers.set(() => this.#closeAllMenus("focus"), 0);
|
|
581
613
|
}
|
|
582
614
|
/**
|
|
583
615
|
* Escape path, invoked by the shared resolver: pressed inside an open menu it
|
|
@@ -589,11 +621,11 @@ var MenubarController = class extends Controller {
|
|
|
589
621
|
const menu = ownerOf(this.menuTargets, document.activeElement);
|
|
590
622
|
if (menu) {
|
|
591
623
|
const top = this.#topFor(menu);
|
|
592
|
-
this.#closeMenu(top);
|
|
624
|
+
this.#closeMenu(top, "escape");
|
|
593
625
|
this.#focusTop(top);
|
|
594
626
|
return;
|
|
595
627
|
}
|
|
596
|
-
this.#closeAllMenus();
|
|
628
|
+
this.#closeAllMenus("escape");
|
|
597
629
|
}
|
|
598
630
|
/** Opens the menu of the navigable top item `delta` steps from `menu`'s owner. */
|
|
599
631
|
#moveToAdjacentMenu(menu, delta) {
|
|
@@ -603,7 +635,7 @@ var MenubarController = class extends Controller {
|
|
|
603
635
|
const current = tops.indexOf(top);
|
|
604
636
|
if (current === -1) return;
|
|
605
637
|
const next = (current + delta + tops.length) % tops.length;
|
|
606
|
-
this.#openMenu(tops[next], "first");
|
|
638
|
+
this.#openMenu(tops[next], "first", "user");
|
|
607
639
|
}
|
|
608
640
|
/**
|
|
609
641
|
* Closes when a click lands outside the controller's element. Focus is left on
|
|
@@ -611,7 +643,9 @@ var MenubarController = class extends Controller {
|
|
|
611
643
|
* docs.
|
|
612
644
|
*/
|
|
613
645
|
#onOutsideClick = (event) => {
|
|
614
|
-
if (this.#isAnyOpen && !this.element.contains(event.target))
|
|
646
|
+
if (this.#isAnyOpen && !this.element.contains(event.target)) {
|
|
647
|
+
this.#closeAllMenus("outside");
|
|
648
|
+
}
|
|
615
649
|
};
|
|
616
650
|
/**
|
|
617
651
|
* Captures clicks so `aria-disabled` top items and commands cannot reach
|