import * as _angular_core from '@angular/core'; import { InjectionToken, Signal, OutputEmitterRef, Provider } from '@angular/core'; import { WritingDirection, CollectionHandle, ListNavigationAction, VetoableNativeEvent, VetoableEvent, RovingTabindex } from 'forty-cdk/core'; import { MenuSiblingNavigator, FloatingSide, FloatingAlign, FloatingFallbackAxisSideDirection, MenuActivationModality, ForMenuContext, ForMenuCloseReason, ForMenuItemHandle, AnchoredOverlayPositioningBase, AnchoredPositioningSeedDefaults } from 'forty-cdk/core-overlay'; import { ReferenceElement } from '@floating-ui/dom'; import * as forty_cdk_menubar from 'forty-cdk/menubar'; /** * Per-trigger configuration that the menubar root reads when its menu is the * one currently open. Each `[forMenubarTrigger]` registers one of these so * the menubar's multiplexed `ForMenuContext` (which `[forMenuContent]` * injects) can pull side / align, ids, anchor, and per-menu inputs from * the matching trigger. */ interface ForMenubarTriggerHandle extends CollectionHandle { /** * Narrowed from {@link CollectionHandle}'s `Node`: the menubar focuses the * trigger and anchors the open menu's floating surface to it. */ readonly host: HTMLElement; readonly value: Signal; readonly disabled: Signal; readonly triggerId: Signal; readonly contentId: Signal; readonly side: Signal; readonly align: Signal; readonly sideOffset: Signal; readonly alignOffset: Signal; readonly avoidCollisions: Signal; readonly fallbackAxisSideDirection: Signal; readonly collisionPadding: Signal; readonly sticky: Signal<'partial' | 'always' | false>; readonly hideWhenDetached: Signal; readonly clipUntilPositioned: Signal; readonly ariaLabel: Signal; /** * Adopts a consumer-set static `id` on the mounted `[forMenuContent]` host * into this trigger's {@link ForMenubarTriggerHandle.contentId}, so the * surface's `[id]` binding re-emits the consumer id instead of clobbering it. * Invoked by the menubar's multiplexed menu context on content registration. */ adoptContentId(el: HTMLElement): void; } /** * Coordination contract owned by `[forMenubar]`. Sibling triggers register * here so the bar can run cross-trigger navigation, roving tabindex, * typeahead, and the "first open is intentional, subsequent are hover" * (skip-delay) model — and so the multiplexed `ForMenuContext` can route * `[forMenuContent]` to whichever trigger is currently active. */ interface ForMenubarContext extends MenuSiblingNavigator { /** * The value of the open trigger, or `null` for none, as a read-only signal. * Mutate it through `openTrigger` / `closeOpen` or the root's `[(value)]` * binding — a direct write would bypass the bar's open / close coordination. */ readonly value: Signal; readonly orientation: Signal<'horizontal' | 'vertical'>; readonly dir: Signal; readonly loop: Signal; readonly disabled: Signal; readonly ariaLabel: Signal; /** * Consumer-set static `id` of a `[forMenuContent]` surface that belongs to no * single trigger — either mounted unconditionally (it registered while no * trigger was active) or shared by every trigger through one * `@if (value() !== null)` (it registered under a trigger, but outlived that * trigger's active window). Each trigger prefers it over its own generated seed * in {@link ForMenubarTriggerHandle.contentId}, so `aria-controls` resolves to * the consumer's id whichever menu opens. `null` for the `@if`-per-trigger * composition (the surface is destroyed with its trigger's menu, and that * trigger adopted its id directly on registration) and for any surface with no * static `id`. */ readonly sharedContentId: Signal; registerTrigger(handle: ForMenubarTriggerHandle): void; unregisterTrigger(handle: ForMenubarTriggerHandle): void; /** All registered triggers in DOM order. */ readonly triggers: Signal; /** Returns the trigger handle for `value`, or `null` if none matches. */ triggerFor(value: string): ForMenubarTriggerHandle | null; /** Currently-open trigger handle, or `null` when no menu is open. */ readonly activeTrigger: Signal; /** * Returns `0` for the trigger element that should be in the tab sequence * and `-1` for the rest. The active stop is the open trigger, or the * most-recently-focused trigger, or the first enabled trigger when * nothing has been focused yet. Wire into a host binding on each trigger. */ tabindexFor(el: HTMLElement): 0 | -1; /** * Promote `el` to the focused trigger so the roving tab stop follows * keyboard navigation. Called from each trigger's `(focus)` handler. */ setFocusedTrigger(el: HTMLElement | null): void; /** Cross-trigger navigation. Used by triggers when no menu is open. */ navigateTriggers(currentTrigger: HTMLElement, action: ListNavigationAction): void; /** * Open the trigger identified by `value`, focus its first or last item. * Called by the trigger itself (Enter/Space/click/ArrowDown/ArrowUp). * `modality` (default `'keyboard'`) records how the open was activated: a * `'pointer'` open (click, hover-after-open) keeps the programmatic * initial focus from reflecting `data-highlighted`, while a `'keyboard'` * open highlights the focused item. * * When `value` is already the open trigger there is no state transition (and * therefore no `(valueChange)` emit): focus moves straight to the requested * first / last enabled item instead, so an APG open key pressed on a trigger * whose menu is already mounted is never a dead key. Closing from the trigger * is the click toggle's job, not the open keys'. * * The other three menu roots get the same already-open branch from core * `MenuOverlay.openMenu`. The bar keeps its own: its open path is keyed by a * trigger `value` and runs through the multiplexed `MenubarMenuContext`, which * is not a `MenuOverlay`, so there is no shared entry point to inherit it from. */ openTrigger(value: string, initialFocus: 'first' | 'last', modality?: MenuActivationModality): void; /** Close the currently-open menu, if any. Returns focus to the trigger. */ closeOpen(): void; /** * Hover-after-open. When some menu is open and pointer enters a sibling * trigger, that sibling's menu opens immediately. No-op while no menu * is open (first open requires keyboard / click). * * Unlike every other open path, this one moves DOM focus to the **hovered * trigger** rather than into the opening menu, mirroring the APG menubar * reference implementation's `onMenuitemPointerover`. The incoming surface's * `(autoFocusOnOpen)` move is suppressed accordingly, so sweeping the pointer * across the bar never drags focus through each popup in turn. Hovering the * already-open trigger is not a switch and is left alone. */ pointerEnterTrigger(value: string): void; /** * Typeahead at the trigger row: focuses the sibling trigger whose label * matches the buffered keys, anchored on the currently-focused trigger and * cycling to the next match (per the APG typeahead behaviour). */ handleTriggerTypeahead(event: KeyboardEvent): void; } declare const FOR_MENUBAR_CONTEXT: InjectionToken; /** * Per-scope positioning seeds (`provideForMenubarDefaults`) the multiplexed * context falls back to while no trigger is active, keeping them identical to * the values `[forMenubarTrigger]` seeds its own inputs from. */ interface MenubarPositioningSeeds { readonly side: FloatingSide; readonly align: FloatingAlign; readonly sideOffset: number; readonly collisionPadding: number; readonly fallbackAxisSideDirection: FloatingFallbackAxisSideDirection; } /** * The slice of `[forMenubar]` the multiplexed `ForMenuContext` reads. Passed to * {@link MenubarMenuContext} so the context implementation stays a plain class * (testable, no `inject()`) while still reading the bar's reactive state. */ interface MenubarMenuHost extends MenuSiblingNavigator { readonly value: Signal; readonly disabled: Signal; readonly dismissible: Signal; readonly dir: ForMenuContext['dir']; readonly loop: Signal; /** Bar-level `(escapeKeyDown)` output the multiplexed context emits through. */ readonly escapeKeyDown: OutputEmitterRef>; /** Bar-level `(pointerDownOutside)` output the multiplexed context emits through. */ readonly pointerDownOutside: OutputEmitterRef>; /** Bar-level `(focusOutside)` output the multiplexed context emits through. */ readonly focusOutside: OutputEmitterRef>; /** Bar-level `(interactOutside)` output the multiplexed context emits through. */ readonly interactOutside: OutputEmitterRef>; /** Bar-level `(autoFocusOnOpen)` output the multiplexed context emits through. */ readonly autoFocusOnOpen: OutputEmitterRef; /** Bar-level `(autoFocusOnClose)` output the multiplexed context emits through. */ readonly autoFocusOnClose: OutputEmitterRef; /** Currently-open trigger handle, or `null` when no menu is open. */ readonly activeTrigger: Signal; /** All registered triggers in DOM order; their hosts are the dismissible exemptions. */ readonly triggers: Signal; /** * The most-recently-active trigger handle — survives past close so the * still-mounted surface keeps its ids and accessible name for the whole close * transition. */ readonly lastTrigger: Signal; /** * The most-recently-active trigger host — survives past close so the * content's destroy hook can still return focus to the trigger. */ readonly lastTriggerHost: Signal; /** Close the currently-open menu by clearing `value`. */ closeOpen(): void; } /** * Single concrete `ForMenuContext` the `[forMenubar]` root provides to its * descendant `[forMenuContent]` and items. It is the one place the bar's * "which trigger's menu is open" multiplexing lives: open / anchor / side / * placement are all derived from the host's `activeTrigger`, so the same * context shape transparently covers whichever trigger's menu is mounted. * * Item navigation and the open / close / dismiss machine are the same shared code `MenuOverlay` * composes — `MenuItemList` and {@link OverlayController} — so this class covers only the * `activeTrigger`-derived multiplexing on top of them. Both of the controller's element sides are * supplied here rather than minted: every id the bar exposes lives on one of its triggers, so the * shared machine mints none and this class needs no injection context. * * Ids and the accessible name are the exception: they derive from `lastTrigger`, because the * surface outlives the trigger's active window. `activeTrigger()` is already `null` while the * content is still mounted for its exit frame, so deriving from it would render `id=""` and drop * the `aria-labelledby` wiring mid-close. With no trigger association at all, `triggerId` and * `ariaLabel` resolve to `''` / `null` — which `[forMenuContent]` emits as no attribute — while * `contentId` falls back to {@link MenubarMenuContext.sharedContentId}. * * The dismiss and auto-focus channels forward to the bar-level outputs on `[forMenubar]`, so the * same markup keeps the full shell contract and its vetoes under a menubar. Switching between * sibling triggers is not a close: the outgoing surface's `autoFocusOnClose` and return-focus are * suppressed, and a hover switch additionally arms a one-shot suppression of the incoming surface's * `autoFocusOnOpen` move. Trigger registration stays inert here — triggers register with the bar * directly. */ declare class MenubarMenuContext implements ForMenuContext { #private; readonly open: Signal; readonly allowsUnconditionalMount = true; readonly disabled: Signal; readonly dismissible: Signal; readonly returnFocus: Signal; readonly dir: ForMenuContext['dir']; readonly side: Signal; readonly align: Signal; readonly sideOffset: Signal; readonly alignOffset: Signal; readonly avoidCollisions: Signal; readonly fallbackAxisSideDirection: Signal; readonly collisionPadding: Signal; readonly sticky: Signal; readonly hideWhenDetached: Signal; readonly clipUntilPositioned: Signal; readonly loop: Signal; readonly initialFocus: Signal<'first' | 'last'>; readonly lastCloseReason: Signal; readonly triggerId: Signal; readonly contentId: Signal; readonly ariaLabel: Signal; readonly anchor: Signal; readonly trigger: Signal; readonly content: Signal; /** * Consumer-set static `id` of a `[forMenuContent]` surface that belongs to no * single trigger. Every trigger's `contentId` prefers it, so `aria-controls` * resolves to the consumer's id whichever menu opens, and this context's own * `contentId` falls back to it so an unconditionally mounted surface keeps * emitting the id before any trigger has ever been active. * * Two compositions are trigger-agnostic, told apart by when that becomes observable: * * - **Unconditionally mounted** — registers with no active trigger, so it is shared from mount. * - **Shared by one `@if (value() !== null)`** — registers under whichever trigger opened the * bar, so at registration it is indistinguishable from a per-trigger surface. What separates * them is survival: it is still the registered content after the bar switches triggers, whereas * a per-trigger surface is destroyed and replaced. Hence the `lastTrigger() !== owner` test * rather than a flag set at registration. * * `null` while the surface is still the one its registering trigger owns, and for any surface * carrying no static `id`. */ readonly sharedContentId: Signal; readonly parentMenu: null; readonly menubar: MenuSiblingNavigator; /** * Exempt every menubar trigger element so clicking another trigger doesn't * fire `pointerDownOutside` (the trigger's own click handler routes the * close + open). */ readonly dismissibleExemptions: Signal; constructor(host: MenubarMenuHost, positioning: MenubarPositioningSeeds); setInitialFocus(target: 'first' | 'last'): void; /** * Read by the bar's `openTrigger` so the next open seeds the resolved * initial-focus target and clears the prior close reason. A `'pointer'` * `modality` keeps the upcoming programmatic initial focus from reflecting * `data-highlighted` on the focused item. * * It arms the shared machine's open without flipping any state: the bar owns * the flip, because the open state is derived from a `value` only the bar knows * (see the controller's `setOpen`). * * `suppressOpenFocus` arms a one-shot veto of the incoming surface's * `(autoFocusOnOpen)` focus move — the hover-switch path, where the bar has * already placed DOM focus on the hovered trigger and the menu must not pull * it back in. Every call re-arms the flag (defaulting it to `false`), so a * suppression that no surface ever consumed cannot leak into the next open. */ prepareOpen(initialFocus: 'first' | 'last', modality?: MenuActivationModality, { suppressOpenFocus }?: { readonly suppressOpenFocus?: boolean; }): void; registerTrigger(el: HTMLElement): void; unregisterTrigger(el: HTMLElement): void; registerContent(el: HTMLElement): void; unregisterContent(el: HTMLElement): void; registerItem(handle: ForMenuItemHandle): void; unregisterItem(handle: ForMenuItemHandle): void; navigate(currentItem: HTMLElement, action: ListNavigationAction): void; handleTypeahead(event: KeyboardEvent): boolean; clearItemHighlights(): void; focusInitialEnabledItem(target: 'first' | 'last'): boolean; /** * Closes the open menu, recording `'programmatic'` — the reason the shared * machine's own `toggle` records on the same path. Without a trigger value the * bar context can only close; triggers drive the open path through the bar's * `openTrigger`. */ toggle(): void; /** No-op: opening requires a trigger value — see the bar's `openTrigger`. */ openMenu(): void; closeMenu(reason: ForMenuCloseReason): void; emitEscapeKeyDown(event: KeyboardEvent): void; emitPointerDownOutside(veto: VetoableNativeEvent): void; emitFocusOutside(veto: VetoableNativeEvent): void; emitInteractOutside(veto: VetoableNativeEvent): void; requestClose(reason: 'pointerDownOutside' | 'focusOutside'): void; emitAutoFocusOnOpen(): boolean; /** * `(autoFocusOnClose)` is a close hook, and a switch between sibling triggers * is not a close — the bar unmounts the outgoing surface while `value` already * names the incoming trigger, so nothing was dismissed and focus never leaves * the widget. Emitting there would announce a close that did not happen and * hand the consumer a veto over a focus move that is redundant anyway: the * target resolves through `lastTrigger`, which the incoming `value` has * already advanced, so it lands on the trigger the user is switching *to*. * Returning `true` therefore vetoes the whole return-focus without consulting * the consumer whenever a menu is still open, and the emission is reserved for * a real close, where `value` is already `null` by the time the surface is * destroyed. * * Derived from the open state rather than from a marker armed on the switching * path: every switch modality (hover, cross-menu arrows, a click on a sibling * trigger while another menu is open) is covered by construction, and no armed * flag can go stale on a composition whose surface outlives the switch instead * of unmounting. */ emitAutoFocusOnClose(): boolean; } /** * Headless implementation of the * [WAI-ARIA Menubar pattern](https://www.w3.org/WAI/ARIA/apg/patterns/menubar/). * * A horizontal (or vertical) bar of triggers, each opening a dropdown menu. * The bar owns "which child menu is open" — opening another implicitly * closes the previous. Cross-menu ArrowLeft / ArrowRight navigation, * hover-after-first-open (switch siblings instantly), and roving tabindex * among triggers are wired automatically. Per the APG Menubar pattern the * pointer leaving the bar does not dismiss the open menu. * * Surface composition: * * ```html *
* * @if (open() === 'file') { *
* *
* } * * * @if (open() === 'edit') { *
…
* } *
* ``` * * `[forMenuContent]` is the same directive used by `[forDropdownMenu]` / * `[forContextMenu]`. The bar provides a multiplexed `ForMenuContext` * whose anchor / placement / ids are pulled from whichever trigger is * currently active, so the content directive needs no menubar-specific * code path. */ declare class ForMenubar implements ForMenubarContext { #private; /** * Two-way bindable. The value of the open trigger, or `null` when none. * The `model()` change emitter (`(valueChange)`) fires only on internal * transitions (trigger interaction, item activation, Escape, outside * dismissal, cross-menu nav), never on consumer writes via `[(value)]`. */ readonly value: _angular_core.ModelSignal; /** * Axis the arrow keys navigate between triggers. Reflected as `data-orientation`. */ readonly orientation: _angular_core.InputSignal<"horizontal" | "vertical">; /** * Writing direction. When unset (default `null`), the inherited ambient * direction is resolved from the nearest ancestor carrying a `dir` attribute * (or ``), defaulting to `'ltr'`. An explicit `[dir]` always wins. * The resolved value is reflected to the host `dir` attribute, swaps * cross-menu ArrowLeft / ArrowRight, and is inherited by descendant menus. */ readonly _dirInput: _angular_core.InputSignal; readonly dir: _angular_core.Signal; /** * Whether arrow navigation wraps past the first / last enabled trigger. */ readonly loop: _angular_core.InputSignalWithTransform; /** * Whether every trigger in the bar is disabled, so no menu can be opened. */ readonly disabled: _angular_core.InputSignalWithTransform; /** * Whether the open menu closes on Escape or an outside interaction. When * `false`, the menu stays open until the consumer flips `value` (or a * trigger / item interaction switches it). Matches the dismiss contract of * `[forDropdownMenu]` / `[forContextMenu]`. Default `true`. */ readonly dismissible: _angular_core.InputSignalWithTransform; /** Optional accessible name for the menubar. */ readonly ariaLabel: _angular_core.InputSignal; protected readonly resolvedAriaLabel: _angular_core.Signal; /** * Fires when Escape is pressed while one of the bar's menus is the topmost * dismissible layer, just before it closes. Call `preventDefault()` on the * emitted veto to keep the menu open and suppress the Escape-driven close. * Bar-level: the same output covers whichever trigger's menu is open. */ readonly escapeKeyDown: _angular_core.OutputEmitterRef>; /** * Fires on a pointer-down outside the open menu and outside every menubar * trigger, just before the menu closes. Call `preventDefault()` on the veto * to keep it open. */ readonly pointerDownOutside: _angular_core.OutputEmitterRef>; /** * Fires when focus moves outside the open menu and outside every menubar * trigger, just before the menu closes. Call `preventDefault()` on the veto * to keep it open. */ readonly focusOutside: _angular_core.OutputEmitterRef>; /** * Composite outside-interaction channel: fires for either a * pointer-down-outside or a focus-outside, just before the menu closes, and * shares the veto state of the specific channel. Call `preventDefault()` on * the veto to keep the menu open regardless of which interaction fired. */ readonly interactOutside: _angular_core.OutputEmitterRef>; /** * Fires just before an opening menu sends focus to its first / last enabled * item on mount. Call `preventDefault()` on the emitted veto to skip the * imperative focus move. A hover-switch between sibling triggers does **not** * fire it: that open leaves DOM focus on the hovered trigger, so the incoming * surface makes no focus move to veto. */ readonly autoFocusOnOpen: _angular_core.OutputEmitterRef; /** * Fires just before focus returns to the trigger on unmount. Call * `preventDefault()` on the veto to suppress the return-focus. Not fired * when the close already moved focus on purpose (Tab, or an outside * pointer-down / focus), and not fired when the outgoing menu is replaced by a * sibling's — a switch is not a close, so the outgoing surface makes no * return-focus move to veto and focus goes straight to wherever the incoming * open puts it. */ readonly autoFocusOnClose: _angular_core.OutputEmitterRef; readonly triggers: _angular_core.Signal; readonly activeTrigger: _angular_core.Signal; /** * The most-recently-active trigger handle. Identical to `activeTrigger` while * a menu is open, and persists past close (resolving `#lastValue`) so the * still-mounted surface keeps the ids and accessible name it was rendered with * for the whole close transition. Consumed by {@link MenubarMenuContext} for * `contentId` / `triggerId` / `ariaLabel`; `null` only while no trigger has * ever been active. */ readonly lastTrigger: _angular_core.Signal; /** * The most-recently-active trigger host. Persists past close so the * multiplexed `[forMenuContent]` destroy hook can still target the trigger * (by then `value()` is already `null`). Consumed by {@link MenubarMenuContext} * as its return-focus `trigger`. */ readonly lastTriggerHost: _angular_core.Signal; /** * Roving-tabindex tracker shared by every menubar trigger, mirroring * `ForToolbar` / `ForTabs`. Triggers promote themselves to active on * `(focus)` (via {@link setFocusedTrigger}) and read `active()` through * {@link tabindexFor}, so re-entry restores the last focused trigger. Before * any focus — and on every close — `active()` is `null`/stale and the tab * stop falls back to the first enabled trigger. The active pointer is * self-healing (a detached / disabled trigger no longer owns the stop). */ readonly roving: RovingTabindex; /** * Single `ForMenuContext` provided to descendant `[forMenuContent]` and * items, implemented by the dedicated {@link MenubarMenuContext} class. Its * open / anchor / side / ids fields are derived from `activeTrigger`, so the * same context shape transparently covers whichever trigger's menu is * mounted. The bar's menu-item navigation reuses the shared `MenuItemList` * (the same mechanics that back `MenuOverlay`), so the multiplexing only * covers the parts the single-owner overlay can't. */ readonly menuCtx: MenubarMenuContext; /** * Consumer-set static `id` of a `[forMenuContent]` shared across triggers — * mounted unconditionally, or held by one `@if (value() !== null)` — surfaced * from {@link MenubarMenuContext.sharedContentId} so each trigger's `contentId` * can prefer it over its own generated seed. */ readonly sharedContentId: _angular_core.Signal; registerTrigger(handle: ForMenubarTriggerHandle): void; unregisterTrigger(handle: ForMenubarTriggerHandle): void; triggerFor(value: string): ForMenubarTriggerHandle | null; tabindexFor(el: HTMLElement): 0 | -1; setFocusedTrigger(el: HTMLElement | null): void; navigateTriggers(currentTrigger: HTMLElement, action: ListNavigationAction): void; openTrigger(value: string, initialFocus: 'first' | 'last', modality?: MenuActivationModality): void; closeOpen(): void; switchToSibling(direction: 'next' | 'prev'): boolean; pointerEnterTrigger(value: string): void; handleTriggerTypeahead(event: KeyboardEvent): void; static ɵfac: _angular_core.ɵɵFactoryDeclaration; static ɵdir: _angular_core.ɵɵDirectiveDeclaration; } /** * One trigger inside `[forMenubar]`. Apply on a `