@ember-joinery/test-support 0.0.0-stage → 1.1.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 +574 -0
- package/LICENSE.md +9 -0
- package/NOTICE +532 -0
- package/README.md +356 -2
- package/addon-main.cjs +4 -0
- package/dist/-private/checkable.d.ts +21 -0
- package/dist/-private/checkable.d.ts.map +1 -0
- package/dist/-private/checkable.js +80 -0
- package/dist/-private/control.d.ts +18 -0
- package/dist/-private/control.d.ts.map +1 -0
- package/dist/-private/control.js +55 -0
- package/dist/-private/menu.d.ts +145 -0
- package/dist/-private/menu.d.ts.map +1 -0
- package/dist/-private/menu.js +322 -0
- package/dist/-private/overlay.d.ts +9 -0
- package/dist/-private/overlay.d.ts.map +1 -0
- package/dist/-private/overlay.js +39 -0
- package/dist/-private/showing.d.ts +7 -0
- package/dist/-private/showing.d.ts.map +1 -0
- package/dist/-private/showing.js +10 -0
- package/dist/-private/size.d.ts +10 -0
- package/dist/-private/size.d.ts.map +1 -0
- package/dist/-private/size.js +24 -0
- package/dist/-private/tree.d.ts +34 -0
- package/dist/-private/tree.d.ts.map +1 -0
- package/dist/-private/tree.js +80 -0
- package/dist/accordion.d.ts +62 -0
- package/dist/accordion.d.ts.map +1 -0
- package/dist/accordion.js +112 -0
- package/dist/alert-dialog.d.ts +24 -0
- package/dist/alert-dialog.d.ts.map +1 -0
- package/dist/alert-dialog.js +37 -0
- package/dist/alert.d.ts +27 -0
- package/dist/alert.d.ts.map +1 -0
- package/dist/alert.js +43 -0
- package/dist/app-shell.d.ts +43 -0
- package/dist/app-shell.d.ts.map +1 -0
- package/dist/app-shell.js +78 -0
- package/dist/aspect-ratio.d.ts +21 -0
- package/dist/aspect-ratio.d.ts.map +1 -0
- package/dist/aspect-ratio.js +30 -0
- package/dist/attachment.d.ts +86 -0
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +156 -0
- package/dist/avatar.d.ts +65 -0
- package/dist/avatar.d.ts.map +1 -0
- package/dist/avatar.js +106 -0
- package/dist/badge.d.ts +29 -0
- package/dist/badge.d.ts.map +1 -0
- package/dist/badge.js +49 -0
- package/dist/breadcrumb.d.ts +36 -0
- package/dist/breadcrumb.d.ts.map +1 -0
- package/dist/breadcrumb.js +80 -0
- package/dist/bubble.d.ts +56 -0
- package/dist/bubble.d.ts.map +1 -0
- package/dist/bubble.js +94 -0
- package/dist/button-group.d.ts +34 -0
- package/dist/button-group.d.ts.map +1 -0
- package/dist/button-group.js +62 -0
- package/dist/button.d.ts +37 -0
- package/dist/button.d.ts.map +1 -0
- package/dist/button.js +77 -0
- package/dist/calendar.d.ts +115 -0
- package/dist/calendar.d.ts.map +1 -0
- package/dist/calendar.js +276 -0
- package/dist/card.d.ts +31 -0
- package/dist/card.d.ts.map +1 -0
- package/dist/card.js +49 -0
- package/dist/checkbox.d.ts +46 -0
- package/dist/checkbox.d.ts.map +1 -0
- package/dist/checkbox.js +84 -0
- package/dist/child.d.ts +29 -0
- package/dist/child.d.ts.map +1 -0
- package/dist/child.js +27 -0
- package/dist/collapsible.d.ts +44 -0
- package/dist/collapsible.d.ts.map +1 -0
- package/dist/collapsible.js +83 -0
- package/dist/color-scheme.d.ts +44 -0
- package/dist/color-scheme.d.ts.map +1 -0
- package/dist/color-scheme.js +123 -0
- package/dist/combobox.d.ts +114 -0
- package/dist/combobox.d.ts.map +1 -0
- package/dist/combobox.js +293 -0
- package/dist/command.d.ts +92 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +183 -0
- package/dist/context-menu.d.ts +37 -0
- package/dist/context-menu.d.ts.map +1 -0
- package/dist/context-menu.js +59 -0
- package/dist/date-picker.d.ts +48 -0
- package/dist/date-picker.d.ts.map +1 -0
- package/dist/date-picker.js +136 -0
- package/dist/dialog.d.ts +64 -0
- package/dist/dialog.d.ts.map +1 -0
- package/dist/dialog.js +142 -0
- package/dist/drawer.d.ts +63 -0
- package/dist/drawer.d.ts.map +1 -0
- package/dist/drawer.js +136 -0
- package/dist/dropdown-menu.d.ts +35 -0
- package/dist/dropdown-menu.d.ts.map +1 -0
- package/dist/dropdown-menu.js +49 -0
- package/dist/empty.d.ts +29 -0
- package/dist/empty.d.ts.map +1 -0
- package/dist/empty.js +47 -0
- package/dist/field.d.ts +86 -0
- package/dist/field.d.ts.map +1 -0
- package/dist/field.js +150 -0
- package/dist/file-drop.d.ts +74 -0
- package/dist/file-drop.d.ts.map +1 -0
- package/dist/file-drop.js +137 -0
- package/dist/focus.d.ts +54 -0
- package/dist/focus.d.ts.map +1 -0
- package/dist/focus.js +174 -0
- package/dist/harness.d.ts +90 -0
- package/dist/harness.d.ts.map +1 -0
- package/dist/harness.js +189 -0
- package/dist/heading.d.ts +16 -0
- package/dist/heading.d.ts.map +1 -0
- package/dist/heading.js +19 -0
- package/dist/hero.d.ts +21 -0
- package/dist/hero.d.ts.map +1 -0
- package/dist/hero.js +28 -0
- package/dist/hover-card.d.ts +46 -0
- package/dist/hover-card.d.ts.map +1 -0
- package/dist/hover-card.js +85 -0
- package/dist/icon.d.ts +10 -0
- package/dist/icon.d.ts.map +1 -0
- package/dist/icon.js +13 -0
- package/dist/index.d.ts +98 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +99 -0
- package/dist/input-group.d.ts +55 -0
- package/dist/input-group.d.ts.map +1 -0
- package/dist/input-group.js +103 -0
- package/dist/input-otp.d.ts +103 -0
- package/dist/input-otp.d.ts.map +1 -0
- package/dist/input-otp.js +293 -0
- package/dist/input.d.ts +53 -0
- package/dist/input.d.ts.map +1 -0
- package/dist/input.js +90 -0
- package/dist/inspector.d.ts +47 -0
- package/dist/inspector.d.ts.map +1 -0
- package/dist/inspector.js +97 -0
- package/dist/item.d.ts +63 -0
- package/dist/item.d.ts.map +1 -0
- package/dist/item.js +104 -0
- package/dist/kbd.d.ts +28 -0
- package/dist/kbd.d.ts.map +1 -0
- package/dist/kbd.js +36 -0
- package/dist/keys.d.ts +20 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +32 -0
- package/dist/label.d.ts +24 -0
- package/dist/label.d.ts.map +1 -0
- package/dist/label.js +39 -0
- package/dist/layers.d.ts +42 -0
- package/dist/layers.d.ts.map +1 -0
- package/dist/layers.js +70 -0
- package/dist/link.d.ts +44 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +60 -0
- package/dist/marker.d.ts +42 -0
- package/dist/marker.d.ts.map +1 -0
- package/dist/marker.js +73 -0
- package/dist/menubar.d.ts +76 -0
- package/dist/menubar.d.ts.map +1 -0
- package/dist/menubar.js +139 -0
- package/dist/message-scroller.d.ts +101 -0
- package/dist/message-scroller.d.ts.map +1 -0
- package/dist/message-scroller.js +215 -0
- package/dist/message.d.ts +48 -0
- package/dist/message.d.ts.map +1 -0
- package/dist/message.js +72 -0
- package/dist/native-form.d.ts +44 -0
- package/dist/native-form.d.ts.map +1 -0
- package/dist/native-form.js +111 -0
- package/dist/native-select.d.ts +56 -0
- package/dist/native-select.d.ts.map +1 -0
- package/dist/native-select.js +100 -0
- package/dist/navigation-bar.d.ts +30 -0
- package/dist/navigation-bar.d.ts.map +1 -0
- package/dist/navigation-bar.js +52 -0
- package/dist/navigation-menu.d.ts +97 -0
- package/dist/navigation-menu.d.ts.map +1 -0
- package/dist/navigation-menu.js +207 -0
- package/dist/navigation-stack.d.ts +36 -0
- package/dist/navigation-stack.d.ts.map +1 -0
- package/dist/navigation-stack.js +67 -0
- package/dist/observers.d.ts +21 -0
- package/dist/observers.d.ts.map +1 -0
- package/dist/observers.js +34 -0
- package/dist/page.d.ts +38 -0
- package/dist/page.d.ts.map +1 -0
- package/dist/page.js +68 -0
- package/dist/pagination.d.ts +39 -0
- package/dist/pagination.d.ts.map +1 -0
- package/dist/pagination.js +71 -0
- package/dist/pointer.d.ts +38 -0
- package/dist/pointer.d.ts.map +1 -0
- package/dist/pointer.js +82 -0
- package/dist/popover.d.ts +50 -0
- package/dist/popover.d.ts.map +1 -0
- package/dist/popover.js +90 -0
- package/dist/progress.d.ts +38 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +81 -0
- package/dist/pull-to-refresh.d.ts +40 -0
- package/dist/pull-to-refresh.d.ts.map +1 -0
- package/dist/pull-to-refresh.js +65 -0
- package/dist/questionnaire.d.ts +117 -0
- package/dist/questionnaire.d.ts.map +1 -0
- package/dist/questionnaire.js +240 -0
- package/dist/radio-group.d.ts +53 -0
- package/dist/radio-group.d.ts.map +1 -0
- package/dist/radio-group.js +95 -0
- package/dist/rating.d.ts +67 -0
- package/dist/rating.d.ts.map +1 -0
- package/dist/rating.js +160 -0
- package/dist/resizable.d.ts +76 -0
- package/dist/resizable.d.ts.map +1 -0
- package/dist/resizable.js +138 -0
- package/dist/routing.d.ts +36 -0
- package/dist/routing.d.ts.map +1 -0
- package/dist/routing.js +50 -0
- package/dist/roving-focus.d.ts +38 -0
- package/dist/roving-focus.d.ts.map +1 -0
- package/dist/roving-focus.js +60 -0
- package/dist/scroll-area.d.ts +58 -0
- package/dist/scroll-area.d.ts.map +1 -0
- package/dist/scroll-area.js +153 -0
- package/dist/scroller.d.ts +41 -0
- package/dist/scroller.d.ts.map +1 -0
- package/dist/scroller.js +65 -0
- package/dist/select.d.ts +98 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/select.js +203 -0
- package/dist/selectors.d.ts +44 -0
- package/dist/selectors.d.ts.map +1 -0
- package/dist/selectors.js +63 -0
- package/dist/send-pointer.d.ts +17 -0
- package/dist/send-pointer.d.ts.map +1 -0
- package/dist/send-pointer.js +35 -0
- package/dist/separator.d.ts +26 -0
- package/dist/separator.d.ts.map +1 -0
- package/dist/separator.js +40 -0
- package/dist/shadowed.d.ts +55 -0
- package/dist/shadowed.d.ts.map +1 -0
- package/dist/shadowed.js +97 -0
- package/dist/sheet.d.ts +14 -0
- package/dist/sheet.d.ts.map +1 -0
- package/dist/sheet.js +15 -0
- package/dist/sidebar.d.ts +159 -0
- package/dist/sidebar.d.ts.map +1 -0
- package/dist/sidebar.js +299 -0
- package/dist/skeleton.d.ts +18 -0
- package/dist/skeleton.d.ts.map +1 -0
- package/dist/skeleton.js +25 -0
- package/dist/slider.d.ts +66 -0
- package/dist/slider.d.ts.map +1 -0
- package/dist/slider.js +155 -0
- package/dist/spinner.d.ts +10 -0
- package/dist/spinner.d.ts.map +1 -0
- package/dist/spinner.js +13 -0
- package/dist/split-view.d.ts +77 -0
- package/dist/split-view.d.ts.map +1 -0
- package/dist/split-view.js +145 -0
- package/dist/status-bar.d.ts +25 -0
- package/dist/status-bar.d.ts.map +1 -0
- package/dist/status-bar.js +42 -0
- package/dist/sticky-footer.d.ts +33 -0
- package/dist/sticky-footer.d.ts.map +1 -0
- package/dist/sticky-footer.js +65 -0
- package/dist/switch.d.ts +44 -0
- package/dist/switch.d.ts.map +1 -0
- package/dist/switch.js +77 -0
- package/dist/tab-bar.d.ts +38 -0
- package/dist/tab-bar.d.ts.map +1 -0
- package/dist/tab-bar.js +78 -0
- package/dist/table.d.ts +41 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.js +100 -0
- package/dist/tabs.d.ts +66 -0
- package/dist/tabs.d.ts.map +1 -0
- package/dist/tabs.js +149 -0
- package/dist/test-hooks.d.ts +9 -0
- package/dist/test-hooks.d.ts.map +1 -0
- package/dist/test-hooks.js +1 -0
- package/dist/textarea.d.ts +47 -0
- package/dist/textarea.d.ts.map +1 -0
- package/dist/textarea.js +78 -0
- package/dist/title-bar.d.ts +43 -0
- package/dist/title-bar.d.ts.map +1 -0
- package/dist/title-bar.js +74 -0
- package/dist/toaster.d.ts +172 -0
- package/dist/toaster.d.ts.map +1 -0
- package/dist/toaster.js +307 -0
- package/dist/toggle-group.d.ts +51 -0
- package/dist/toggle-group.d.ts.map +1 -0
- package/dist/toggle-group.js +97 -0
- package/dist/toggle.d.ts +21 -0
- package/dist/toggle.d.ts.map +1 -0
- package/dist/toggle.js +26 -0
- package/dist/toolbar.d.ts +40 -0
- package/dist/toolbar.d.ts.map +1 -0
- package/dist/toolbar.js +67 -0
- package/dist/tooltip.d.ts +48 -0
- package/dist/tooltip.d.ts.map +1 -0
- package/dist/tooltip.js +91 -0
- package/dist/trace.d.ts +118 -0
- package/dist/trace.d.ts.map +1 -0
- package/dist/trace.js +196 -0
- package/dist/translator.d.ts +34 -0
- package/dist/translator.d.ts.map +1 -0
- package/dist/translator.js +75 -0
- package/dist/window-frame.d.ts +40 -0
- package/dist/window-frame.d.ts.map +1 -0
- package/dist/window-frame.js +66 -0
- package/dist/zoetrope.d.ts +51 -0
- package/dist/zoetrope.d.ts.map +1 -0
- package/dist/zoetrope.js +94 -0
- package/package.json +68 -3
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Harness } from '../harness.ts';
|
|
2
|
+
import { type PointerOptions } from '../layers.ts';
|
|
3
|
+
export interface PressOptions extends PointerOptions {
|
|
4
|
+
/** The button: 0 (the main one, the default) or 2 (the secondary one, a right click). */
|
|
5
|
+
button?: number;
|
|
6
|
+
/** Whether Ctrl is held, as a Mac's Ctrl+click for a right click. */
|
|
7
|
+
ctrlKey?: boolean;
|
|
8
|
+
/** Where, in the viewport. Default: the element's centre. */
|
|
9
|
+
point?: {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A press as a browser makes one: `pointerdown`, then, unless the page cancelled it, `mousedown`
|
|
16
|
+
* and focus moving to what was pressed; `pointerup`, `mouseup` and, for the main button, `click`
|
|
17
|
+
* (a right click sends `contextmenu` after the `mousedown` instead). A menu's trigger cancels
|
|
18
|
+
* the `pointerdown` that opens it, so focus never lands on the trigger, as in a browser:
|
|
19
|
+
* `click()` from `@ember/test-helpers` would focus it regardless.
|
|
20
|
+
*/
|
|
21
|
+
export declare function pressAsBrowser(target: Element, options?: PressOptions): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* An item's label: its text, whitespace collapsed, with its shortcut and its check mark (the
|
|
24
|
+
* item indicator) left out.
|
|
25
|
+
*/
|
|
26
|
+
export declare function itemText(item: Element): string;
|
|
27
|
+
/**
|
|
28
|
+
* One level of a menu: its content (the root's, or a submenu's) and its own items, not those of
|
|
29
|
+
* the submenus inside it. Items are found by their text, the shortcut left out.
|
|
30
|
+
*/
|
|
31
|
+
export declare class MenuLevel {
|
|
32
|
+
#private;
|
|
33
|
+
constructor(content: () => HTMLElement | null);
|
|
34
|
+
/** The content, or `null` while it isn't rendered. */
|
|
35
|
+
get content(): HTMLElement | null;
|
|
36
|
+
/** Whether the content is showing in the browser's top layer. */
|
|
37
|
+
get isShown(): boolean;
|
|
38
|
+
/** Its items, in order: plain, checkbox and radio items, and the triggers of its submenus. */
|
|
39
|
+
get itemElements(): HTMLElement[];
|
|
40
|
+
/** Each item's text, in order. */
|
|
41
|
+
get items(): string[];
|
|
42
|
+
/** Each label's text, in order. */
|
|
43
|
+
get labels(): string[];
|
|
44
|
+
/** How many separators it has. */
|
|
45
|
+
get separators(): number;
|
|
46
|
+
/** The text of the item that has focus, or `null` (focus on the content itself, or elsewhere). */
|
|
47
|
+
get highlighted(): string | null;
|
|
48
|
+
/** The side the content was placed on, after any flip (`data-side`). */
|
|
49
|
+
get side(): string | null;
|
|
50
|
+
/** The content's alignment along that side (`data-align`). */
|
|
51
|
+
get align(): string | null;
|
|
52
|
+
/** The item whose text is `label`. Throws when there is none. */
|
|
53
|
+
item(label: string): HTMLElement;
|
|
54
|
+
/** Whether the item is disabled (`aria-disabled`). */
|
|
55
|
+
isDisabled(label: string): boolean;
|
|
56
|
+
/** Whether a checkbox or radio item is checked (`aria-checked="true"`). */
|
|
57
|
+
isChecked(label: string): boolean;
|
|
58
|
+
/** A checkbox or radio item's `aria-checked`: `true`, `false` or `mixed`. */
|
|
59
|
+
checked(label: string): string | null;
|
|
60
|
+
/** The item's role: `menuitem`, `menuitemcheckbox` or `menuitemradio`. */
|
|
61
|
+
role(label: string): string | null;
|
|
62
|
+
/** The item's shortcut text, or `null`. */
|
|
63
|
+
shortcut(label: string): string | null;
|
|
64
|
+
/** The item's `data-variant`, such as `destructive`, or `null`. */
|
|
65
|
+
variant(label: string): string | null;
|
|
66
|
+
/** Clicks the item: selecting it closes the menu, unless its `@onSelect` prevents that. */
|
|
67
|
+
select(label: string): Promise<void>;
|
|
68
|
+
/** Rests the pointer on the item, which focuses it (and opens a submenu after a moment). */
|
|
69
|
+
hover(label: string): Promise<void>;
|
|
70
|
+
/** The submenu the item named `label` opens. */
|
|
71
|
+
sub(label: string): SubMenu;
|
|
72
|
+
}
|
|
73
|
+
/** A submenu: its trigger, an item of the menu it is in, and its own content and items. */
|
|
74
|
+
export declare class SubMenu extends MenuLevel {
|
|
75
|
+
#private;
|
|
76
|
+
constructor(trigger: () => HTMLElement);
|
|
77
|
+
/** The item that opens it. */
|
|
78
|
+
get trigger(): HTMLElement;
|
|
79
|
+
/** Whether it is open, from its trigger's `aria-expanded`. */
|
|
80
|
+
get isOpen(): boolean;
|
|
81
|
+
/** Its accessible name: its trigger's text. */
|
|
82
|
+
get label(): string;
|
|
83
|
+
/** Opens it as a mouse does: resting on its trigger, which opens it after a moment. */
|
|
84
|
+
open(): Promise<void>;
|
|
85
|
+
/** Opens it from the keyboard: focus on its trigger, and the arrow pointing into it. */
|
|
86
|
+
openWithKeyboard(): Promise<void>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* What the dropdown and context menu harnesses share: the root content, read as a `MenuLevel`,
|
|
90
|
+
* and the keys and presses that close it.
|
|
91
|
+
*/
|
|
92
|
+
export declare abstract class MenuHarness extends Harness {
|
|
93
|
+
#private;
|
|
94
|
+
/** The trigger: the `Trigger` part, or your own element with the `trigger` modifier. */
|
|
95
|
+
get trigger(): HTMLElement;
|
|
96
|
+
/** The menu's content, or `null` while it isn't rendered. */
|
|
97
|
+
get content(): HTMLElement | null;
|
|
98
|
+
/** Whether it is open. */
|
|
99
|
+
abstract get isOpen(): boolean;
|
|
100
|
+
/** Whether the content is showing in the browser's top layer. */
|
|
101
|
+
get isShown(): boolean;
|
|
102
|
+
/** The content's accessible name (a dropdown menu's trigger names it), or `''`. */
|
|
103
|
+
get label(): string;
|
|
104
|
+
/** The content's text, whitespace collapsed. */
|
|
105
|
+
get text(): string;
|
|
106
|
+
/** The side the content was placed on, after any flip (`data-side`). */
|
|
107
|
+
get side(): string | null;
|
|
108
|
+
/** The content's alignment along that side (`data-align`). */
|
|
109
|
+
get align(): string | null;
|
|
110
|
+
/** The content's items (not its submenus'), as elements, in order. */
|
|
111
|
+
get itemElements(): HTMLElement[];
|
|
112
|
+
/** Each item's text, its shortcut left out. */
|
|
113
|
+
get items(): string[];
|
|
114
|
+
/** Each label's text. */
|
|
115
|
+
get labels(): string[];
|
|
116
|
+
/** How many separators the content has. */
|
|
117
|
+
get separators(): number;
|
|
118
|
+
/** The text of the item that has focus, or `null`. */
|
|
119
|
+
get highlighted(): string | null;
|
|
120
|
+
/** The item whose text is `label`. */
|
|
121
|
+
item(label: string): HTMLElement;
|
|
122
|
+
/** Whether the item is disabled. */
|
|
123
|
+
isDisabled(label: string): boolean;
|
|
124
|
+
/** Whether a checkbox or radio item is checked. */
|
|
125
|
+
isChecked(label: string): boolean;
|
|
126
|
+
/** A checkbox or radio item's `aria-checked`: `true`, `false` or `mixed`. */
|
|
127
|
+
checked(label: string): string | null;
|
|
128
|
+
/** The item's role. */
|
|
129
|
+
role(label: string): string | null;
|
|
130
|
+
/** The item's shortcut text, or `null`. */
|
|
131
|
+
shortcut(label: string): string | null;
|
|
132
|
+
/** The item's `data-variant`, or `null`. */
|
|
133
|
+
variant(label: string): string | null;
|
|
134
|
+
/** Clicks the item, which selects it. */
|
|
135
|
+
select(label: string): Promise<void>;
|
|
136
|
+
/** Rests the pointer on the item. */
|
|
137
|
+
hover(label: string): Promise<void>;
|
|
138
|
+
/** The submenu the item named `label` opens, with the same members as this harness's menu. */
|
|
139
|
+
sub(label: string): SubMenu;
|
|
140
|
+
/** Presses Escape where focus is: it closes the whole menu. */
|
|
141
|
+
pressEscape(): Promise<void>;
|
|
142
|
+
/** A press outside the menu, as a user dismissing it makes. */
|
|
143
|
+
pressOutside(): Promise<void>;
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=menu.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../../src/-private/menu.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAA6B,KAAK,cAAc,EAAE,MAAM,cAAc,CAAA;AAgB7E,MAAM,WAAW,YAAa,SAAQ,cAAc;IAClD,yFAAyF;IACzF,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,qEAAqE;IACrE,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,6DAA6D;IAC7D,KAAK,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CACjC;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CA4B/F;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAe9C;AAED;;;GAGG;AACH,qBAAa,SAAS;;gBAGR,OAAO,EAAE,MAAM,WAAW,GAAG,IAAI;IAI7C,sDAAsD;IACtD,IAAI,OAAO,IAAI,WAAW,GAAG,IAAI,CAEhC;IAED,iEAAiE;IACjE,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,8FAA8F;IAC9F,IAAI,YAAY,IAAI,WAAW,EAAE,CAMhC;IAED,kCAAkC;IAClC,IAAI,KAAK,IAAI,MAAM,EAAE,CAEpB;IAED,mCAAmC;IACnC,IAAI,MAAM,IAAI,MAAM,EAAE,CAErB;IAED,kCAAkC;IAClC,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,kGAAkG;IAClG,IAAI,WAAW,IAAI,MAAM,GAAG,IAAI,CAI/B;IAED,wEAAwE;IACxE,IAAI,IAAI,IAAI,MAAM,GAAG,IAAI,CAExB;IAED,8DAA8D;IAC9D,IAAI,KAAK,IAAI,MAAM,GAAG,IAAI,CAEzB;IAED,iEAAiE;IACjE,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW;IAUhC,sDAAsD;IACtD,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIlC,2EAA2E;IAC3E,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIjC,6EAA6E;IAC7E,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIrC,0EAA0E;IAC1E,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIlC,2CAA2C;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAKtC,mEAAmE;IACnE,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIrC,2FAA2F;IACrF,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1C,4FAA4F;IACtF,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC,gDAAgD;IAChD,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAY5B;AAED,2FAA2F;AAC3F,qBAAa,OAAQ,SAAQ,SAAS;;gBAGxB,OAAO,EAAE,MAAM,WAAW;IAQtC,8BAA8B;IAC9B,IAAI,OAAO,IAAI,WAAW,CAEzB;IAED,8DAA8D;IAC9D,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,+CAA+C;IAC/C,IAAI,KAAK,IAAI,MAAM,CAGlB;IAED,uFAAuF;IACjF,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,wFAAwF;IAClF,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;CAKxC;AAED;;;GAGG;AACH,8BAAsB,WAAY,SAAQ,OAAO;;IAG/C,wFAAwF;IACxF,IAAI,OAAO,IAAI,WAAW,CAEzB;IAED,6DAA6D;IAC7D,IAAI,OAAO,IAAI,WAAW,GAAG,IAAI,CAEhC;IAED,0BAA0B;IAC1B,QAAQ,KAAK,MAAM,IAAI,OAAO,CAAA;IAE9B,iEAAiE;IACjE,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,mFAAmF;IACnF,IAAI,KAAK,IAAI,MAAM,CAGlB;IAED,gDAAgD;IAChD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,wEAAwE;IACxE,IAAI,IAAI,IAAI,MAAM,GAAG,IAAI,CAExB;IAED,8DAA8D;IAC9D,IAAI,KAAK,IAAI,MAAM,GAAG,IAAI,CAEzB;IAED,sEAAsE;IACtE,IAAI,YAAY,IAAI,WAAW,EAAE,CAEhC;IAED,+CAA+C;IAC/C,IAAI,KAAK,IAAI,MAAM,EAAE,CAEpB;IAED,yBAAyB;IACzB,IAAI,MAAM,IAAI,MAAM,EAAE,CAErB;IAED,2CAA2C;IAC3C,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,sDAAsD;IACtD,IAAI,WAAW,IAAI,MAAM,GAAG,IAAI,CAE/B;IAED,sCAAsC;IACtC,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW;IAIhC,oCAAoC;IACpC,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIlC,mDAAmD;IACnD,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIjC,6EAA6E;IAC7E,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIrC,uBAAuB;IACvB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIlC,2CAA2C;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAItC,4CAA4C;IAC5C,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIrC,yCAAyC;IACnC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1C,qCAAqC;IAC/B,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC,8FAA8F;IAC9F,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAI3B,+DAA+D;IACzD,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAIlC,+DAA+D;IACzD,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CAGpC"}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
// What the menu harnesses (dropdown menu, context menu) share: a press as a browser makes one,
|
|
2
|
+
// and a menu level (the root content or a submenu's), read through its DOM and ARIA.
|
|
3
|
+
import { click, focus, settled } from '@ember/test-helpers';
|
|
4
|
+
import { Harness } from "../harness.js";
|
|
5
|
+
import { pressEscape, pressOutside } from "../layers.js";
|
|
6
|
+
import { hover } from "../pointer.js";
|
|
7
|
+
import { pressKey } from "../focus.js";
|
|
8
|
+
import { NotFoundError } from "./tree.js";
|
|
9
|
+
import { accessibleName, shownInTopLayer, text } from "./overlay.js";
|
|
10
|
+
const ITEM = '[role="menuitem"], [role="menuitemcheckbox"], [role="menuitemradio"]';
|
|
11
|
+
const MENU = '[role="menu"]';
|
|
12
|
+
const FOCUSABLE = 'a[href], button, input, select, textarea, [tabindex], [contenteditable]';
|
|
13
|
+
/** Where a pointer event lands: the element's centre, unless a point is given. */
|
|
14
|
+
function centre(element) {
|
|
15
|
+
const rect = element.getBoundingClientRect();
|
|
16
|
+
return { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 };
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A press as a browser makes one: `pointerdown`, then, unless the page cancelled it, `mousedown`
|
|
20
|
+
* and focus moving to what was pressed; `pointerup`, `mouseup` and, for the main button, `click`
|
|
21
|
+
* (a right click sends `contextmenu` after the `mousedown` instead). A menu's trigger cancels
|
|
22
|
+
* the `pointerdown` that opens it, so focus never lands on the trigger, as in a browser:
|
|
23
|
+
* `click()` from `@ember/test-helpers` would focus it regardless.
|
|
24
|
+
*/
|
|
25
|
+
export async function pressAsBrowser(target, options = {}) {
|
|
26
|
+
const { button = 0, ctrlKey = false, pointerType = 'mouse' } = options;
|
|
27
|
+
const { x, y } = options.point ?? centre(target);
|
|
28
|
+
const init = {
|
|
29
|
+
bubbles: true,
|
|
30
|
+
cancelable: true,
|
|
31
|
+
composed: true,
|
|
32
|
+
view: window,
|
|
33
|
+
clientX: x,
|
|
34
|
+
clientY: y,
|
|
35
|
+
button,
|
|
36
|
+
buttons: button === 2 ? 2 : 1,
|
|
37
|
+
ctrlKey,
|
|
38
|
+
};
|
|
39
|
+
const pointer = { ...init, pointerType, pointerId: 1, isPrimary: true };
|
|
40
|
+
const down = new PointerEvent('pointerdown', pointer);
|
|
41
|
+
target.dispatchEvent(down);
|
|
42
|
+
if (!down.defaultPrevented) {
|
|
43
|
+
const mousedown = new MouseEvent('mousedown', init);
|
|
44
|
+
target.dispatchEvent(mousedown);
|
|
45
|
+
if (!mousedown.defaultPrevented)
|
|
46
|
+
target.closest(FOCUSABLE)?.focus();
|
|
47
|
+
}
|
|
48
|
+
if (button === 2 || ctrlKey)
|
|
49
|
+
target.dispatchEvent(new MouseEvent('contextmenu', init));
|
|
50
|
+
await settled();
|
|
51
|
+
target.dispatchEvent(new PointerEvent('pointerup', { ...pointer, buttons: 0 }));
|
|
52
|
+
if (!down.defaultPrevented)
|
|
53
|
+
target.dispatchEvent(new MouseEvent('mouseup', init));
|
|
54
|
+
if (button === 0 && !ctrlKey)
|
|
55
|
+
target.dispatchEvent(new MouseEvent('click', init));
|
|
56
|
+
await settled();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* An item's label: its text, whitespace collapsed, with its shortcut and its check mark (the
|
|
60
|
+
* item indicator) left out.
|
|
61
|
+
*/
|
|
62
|
+
export function itemText(item) {
|
|
63
|
+
let label = '';
|
|
64
|
+
const walk = (node) => {
|
|
65
|
+
for (const child of node.childNodes) {
|
|
66
|
+
if (child.nodeType === Node.TEXT_NODE)
|
|
67
|
+
label += child.textContent ?? '';
|
|
68
|
+
else if (child instanceof Element) {
|
|
69
|
+
const part = child.getAttribute('data-test-jn-part');
|
|
70
|
+
if (part === 'shortcut' || part === 'item-indicator')
|
|
71
|
+
continue;
|
|
72
|
+
if (child.getAttribute('role') === 'menu')
|
|
73
|
+
continue;
|
|
74
|
+
walk(child);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
walk(item);
|
|
79
|
+
return label.replace(/\s+/g, ' ').trim();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* One level of a menu: its content (the root's, or a submenu's) and its own items, not those of
|
|
83
|
+
* the submenus inside it. Items are found by their text, the shortcut left out.
|
|
84
|
+
*/
|
|
85
|
+
export class MenuLevel {
|
|
86
|
+
#content;
|
|
87
|
+
constructor(content) {
|
|
88
|
+
this.#content = content;
|
|
89
|
+
}
|
|
90
|
+
/** The content, or `null` while it isn't rendered. */
|
|
91
|
+
get content() {
|
|
92
|
+
return this.#content();
|
|
93
|
+
}
|
|
94
|
+
/** Whether the content is showing in the browser's top layer. */
|
|
95
|
+
get isShown() {
|
|
96
|
+
return shownInTopLayer(this.content);
|
|
97
|
+
}
|
|
98
|
+
/** Its items, in order: plain, checkbox and radio items, and the triggers of its submenus. */
|
|
99
|
+
get itemElements() {
|
|
100
|
+
const content = this.content;
|
|
101
|
+
if (!content)
|
|
102
|
+
return [];
|
|
103
|
+
return [...content.querySelectorAll(ITEM)].filter(item => item.closest(MENU) === content);
|
|
104
|
+
}
|
|
105
|
+
/** Each item's text, in order. */
|
|
106
|
+
get items() {
|
|
107
|
+
return this.itemElements.map(itemText);
|
|
108
|
+
}
|
|
109
|
+
/** Each label's text, in order. */
|
|
110
|
+
get labels() {
|
|
111
|
+
return this.#own('[data-test-jn-part="label"]').map(text);
|
|
112
|
+
}
|
|
113
|
+
/** How many separators it has. */
|
|
114
|
+
get separators() {
|
|
115
|
+
return this.#own('[role="separator"]').length;
|
|
116
|
+
}
|
|
117
|
+
/** The text of the item that has focus, or `null` (focus on the content itself, or elsewhere). */
|
|
118
|
+
get highlighted() {
|
|
119
|
+
const active = document.activeElement;
|
|
120
|
+
const item = this.itemElements.find(element => element === active);
|
|
121
|
+
return item ? itemText(item) : null;
|
|
122
|
+
}
|
|
123
|
+
/** The side the content was placed on, after any flip (`data-side`). */
|
|
124
|
+
get side() {
|
|
125
|
+
return this.content?.getAttribute('data-side') ?? null;
|
|
126
|
+
}
|
|
127
|
+
/** The content's alignment along that side (`data-align`). */
|
|
128
|
+
get align() {
|
|
129
|
+
return this.content?.getAttribute('data-align') ?? null;
|
|
130
|
+
}
|
|
131
|
+
/** The item whose text is `label`. Throws when there is none. */
|
|
132
|
+
item(label) {
|
|
133
|
+
const item = this.itemElements.find(element => itemText(element) === label);
|
|
134
|
+
if (!item) {
|
|
135
|
+
throw new NotFoundError(`no menu item "${label}" (there are: ${this.items.map(each => `"${each}"`).join(', ')})`);
|
|
136
|
+
}
|
|
137
|
+
return item;
|
|
138
|
+
}
|
|
139
|
+
/** Whether the item is disabled (`aria-disabled`). */
|
|
140
|
+
isDisabled(label) {
|
|
141
|
+
return this.item(label).getAttribute('aria-disabled') === 'true';
|
|
142
|
+
}
|
|
143
|
+
/** Whether a checkbox or radio item is checked (`aria-checked="true"`). */
|
|
144
|
+
isChecked(label) {
|
|
145
|
+
return this.item(label).getAttribute('aria-checked') === 'true';
|
|
146
|
+
}
|
|
147
|
+
/** A checkbox or radio item's `aria-checked`: `true`, `false` or `mixed`. */
|
|
148
|
+
checked(label) {
|
|
149
|
+
return this.item(label).getAttribute('aria-checked');
|
|
150
|
+
}
|
|
151
|
+
/** The item's role: `menuitem`, `menuitemcheckbox` or `menuitemradio`. */
|
|
152
|
+
role(label) {
|
|
153
|
+
return this.item(label).getAttribute('role');
|
|
154
|
+
}
|
|
155
|
+
/** The item's shortcut text, or `null`. */
|
|
156
|
+
shortcut(label) {
|
|
157
|
+
const shortcut = this.item(label).querySelector('[data-test-jn-part="shortcut"]');
|
|
158
|
+
return shortcut ? text(shortcut) : null;
|
|
159
|
+
}
|
|
160
|
+
/** The item's `data-variant`, such as `destructive`, or `null`. */
|
|
161
|
+
variant(label) {
|
|
162
|
+
return this.item(label).getAttribute('data-variant');
|
|
163
|
+
}
|
|
164
|
+
/** Clicks the item: selecting it closes the menu, unless its `@onSelect` prevents that. */
|
|
165
|
+
async select(label) {
|
|
166
|
+
await click(this.item(label));
|
|
167
|
+
}
|
|
168
|
+
/** Rests the pointer on the item, which focuses it (and opens a submenu after a moment). */
|
|
169
|
+
async hover(label) {
|
|
170
|
+
await hover(this.item(label));
|
|
171
|
+
}
|
|
172
|
+
/** The submenu the item named `label` opens. */
|
|
173
|
+
sub(label) {
|
|
174
|
+
return new SubMenu(() => this.item(label));
|
|
175
|
+
}
|
|
176
|
+
/** The elements matching `selector` that are this level's own, not a submenu's. */
|
|
177
|
+
#own(selector) {
|
|
178
|
+
const content = this.content;
|
|
179
|
+
if (!content)
|
|
180
|
+
return [];
|
|
181
|
+
return [...content.querySelectorAll(selector)].filter(element => element.closest(MENU) === content);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/** A submenu: its trigger, an item of the menu it is in, and its own content and items. */
|
|
185
|
+
export class SubMenu extends MenuLevel {
|
|
186
|
+
#trigger;
|
|
187
|
+
constructor(trigger) {
|
|
188
|
+
super(() => {
|
|
189
|
+
const id = trigger().getAttribute('aria-controls');
|
|
190
|
+
return id ? document.getElementById(id) : null;
|
|
191
|
+
});
|
|
192
|
+
this.#trigger = trigger;
|
|
193
|
+
}
|
|
194
|
+
/** The item that opens it. */
|
|
195
|
+
get trigger() {
|
|
196
|
+
return this.#trigger();
|
|
197
|
+
}
|
|
198
|
+
/** Whether it is open, from its trigger's `aria-expanded`. */
|
|
199
|
+
get isOpen() {
|
|
200
|
+
return this.trigger.getAttribute('aria-expanded') === 'true';
|
|
201
|
+
}
|
|
202
|
+
/** Its accessible name: its trigger's text. */
|
|
203
|
+
get label() {
|
|
204
|
+
const content = this.content;
|
|
205
|
+
return content ? accessibleName(content) : '';
|
|
206
|
+
}
|
|
207
|
+
/** Opens it as a mouse does: resting on its trigger, which opens it after a moment. */
|
|
208
|
+
async open() {
|
|
209
|
+
if (!this.isOpen)
|
|
210
|
+
await hover(this.trigger);
|
|
211
|
+
}
|
|
212
|
+
/** Opens it from the keyboard: focus on its trigger, and the arrow pointing into it. */
|
|
213
|
+
async openWithKeyboard() {
|
|
214
|
+
await focus(this.trigger);
|
|
215
|
+
const rtl = getComputedStyle(this.trigger).direction === 'rtl';
|
|
216
|
+
await pressKey(rtl ? 'ArrowLeft' : 'ArrowRight');
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* What the dropdown and context menu harnesses share: the root content, read as a `MenuLevel`,
|
|
221
|
+
* and the keys and presses that close it.
|
|
222
|
+
*/
|
|
223
|
+
export class MenuHarness extends Harness {
|
|
224
|
+
#menu = new MenuLevel(() => this.content);
|
|
225
|
+
/** The trigger: the `Trigger` part, or your own element with the `trigger` modifier. */
|
|
226
|
+
get trigger() {
|
|
227
|
+
return this.part('trigger');
|
|
228
|
+
}
|
|
229
|
+
/** The menu's content, or `null` while it isn't rendered. */
|
|
230
|
+
get content() {
|
|
231
|
+
return this.queryPart('content');
|
|
232
|
+
}
|
|
233
|
+
/** Whether the content is showing in the browser's top layer. */
|
|
234
|
+
get isShown() {
|
|
235
|
+
return this.#menu.isShown;
|
|
236
|
+
}
|
|
237
|
+
/** The content's accessible name (a dropdown menu's trigger names it), or `''`. */
|
|
238
|
+
get label() {
|
|
239
|
+
const content = this.content;
|
|
240
|
+
return content ? accessibleName(content) : '';
|
|
241
|
+
}
|
|
242
|
+
/** The content's text, whitespace collapsed. */
|
|
243
|
+
get text() {
|
|
244
|
+
return text(this.content);
|
|
245
|
+
}
|
|
246
|
+
/** The side the content was placed on, after any flip (`data-side`). */
|
|
247
|
+
get side() {
|
|
248
|
+
return this.#menu.side;
|
|
249
|
+
}
|
|
250
|
+
/** The content's alignment along that side (`data-align`). */
|
|
251
|
+
get align() {
|
|
252
|
+
return this.#menu.align;
|
|
253
|
+
}
|
|
254
|
+
/** The content's items (not its submenus'), as elements, in order. */
|
|
255
|
+
get itemElements() {
|
|
256
|
+
return this.#menu.itemElements;
|
|
257
|
+
}
|
|
258
|
+
/** Each item's text, its shortcut left out. */
|
|
259
|
+
get items() {
|
|
260
|
+
return this.#menu.items;
|
|
261
|
+
}
|
|
262
|
+
/** Each label's text. */
|
|
263
|
+
get labels() {
|
|
264
|
+
return this.#menu.labels;
|
|
265
|
+
}
|
|
266
|
+
/** How many separators the content has. */
|
|
267
|
+
get separators() {
|
|
268
|
+
return this.#menu.separators;
|
|
269
|
+
}
|
|
270
|
+
/** The text of the item that has focus, or `null`. */
|
|
271
|
+
get highlighted() {
|
|
272
|
+
return this.#menu.highlighted;
|
|
273
|
+
}
|
|
274
|
+
/** The item whose text is `label`. */
|
|
275
|
+
item(label) {
|
|
276
|
+
return this.#menu.item(label);
|
|
277
|
+
}
|
|
278
|
+
/** Whether the item is disabled. */
|
|
279
|
+
isDisabled(label) {
|
|
280
|
+
return this.#menu.isDisabled(label);
|
|
281
|
+
}
|
|
282
|
+
/** Whether a checkbox or radio item is checked. */
|
|
283
|
+
isChecked(label) {
|
|
284
|
+
return this.#menu.isChecked(label);
|
|
285
|
+
}
|
|
286
|
+
/** A checkbox or radio item's `aria-checked`: `true`, `false` or `mixed`. */
|
|
287
|
+
checked(label) {
|
|
288
|
+
return this.#menu.checked(label);
|
|
289
|
+
}
|
|
290
|
+
/** The item's role. */
|
|
291
|
+
role(label) {
|
|
292
|
+
return this.#menu.role(label);
|
|
293
|
+
}
|
|
294
|
+
/** The item's shortcut text, or `null`. */
|
|
295
|
+
shortcut(label) {
|
|
296
|
+
return this.#menu.shortcut(label);
|
|
297
|
+
}
|
|
298
|
+
/** The item's `data-variant`, or `null`. */
|
|
299
|
+
variant(label) {
|
|
300
|
+
return this.#menu.variant(label);
|
|
301
|
+
}
|
|
302
|
+
/** Clicks the item, which selects it. */
|
|
303
|
+
async select(label) {
|
|
304
|
+
await this.#menu.select(label);
|
|
305
|
+
}
|
|
306
|
+
/** Rests the pointer on the item. */
|
|
307
|
+
async hover(label) {
|
|
308
|
+
await this.#menu.hover(label);
|
|
309
|
+
}
|
|
310
|
+
/** The submenu the item named `label` opens, with the same members as this harness's menu. */
|
|
311
|
+
sub(label) {
|
|
312
|
+
return this.#menu.sub(label);
|
|
313
|
+
}
|
|
314
|
+
/** Presses Escape where focus is: it closes the whole menu. */
|
|
315
|
+
async pressEscape() {
|
|
316
|
+
await pressEscape();
|
|
317
|
+
}
|
|
318
|
+
/** A press outside the menu, as a user dismissing it makes. */
|
|
319
|
+
async pressOutside() {
|
|
320
|
+
await pressOutside();
|
|
321
|
+
}
|
|
322
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** An element's text, whitespace collapsed. */
|
|
2
|
+
export declare function text(element: Element | null | undefined): string;
|
|
3
|
+
/** An element's accessible name: `aria-labelledby`'s text, else `aria-label`, else its text. */
|
|
4
|
+
export declare function accessibleName(element: Element): string;
|
|
5
|
+
/** An element's accessible description: the text `aria-describedby` names, or `''`. */
|
|
6
|
+
export declare function accessibleDescription(element: Element): string;
|
|
7
|
+
/** Whether an element is shown in the browser's top layer: an open popover. */
|
|
8
|
+
export declare function shownInTopLayer(element: Element | null | undefined): boolean;
|
|
9
|
+
//# sourceMappingURL=overlay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../../src/-private/overlay.ts"],"names":[],"mappings":"AAGA,+CAA+C;AAC/C,wBAAgB,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAEhE;AAcD,gGAAgG;AAChG,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAMvD;AAED,uFAAuF;AACvF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAE9D;AAED,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAO5E"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// What the floating parts' harnesses (popover, tooltip, hover card) read the same way: text,
|
|
2
|
+
// names and descriptions through ARIA, and where the anchoring put a part.
|
|
3
|
+
/** An element's text, whitespace collapsed. */
|
|
4
|
+
export function text(element) {
|
|
5
|
+
return (element?.textContent ?? '').replace(/\s+/g, ' ').trim();
|
|
6
|
+
}
|
|
7
|
+
/** The text of the elements an `aria-labelledby` or `aria-describedby` names, joined. */
|
|
8
|
+
function referenced(element, attribute) {
|
|
9
|
+
const ids = element.getAttribute(attribute);
|
|
10
|
+
if (!ids)
|
|
11
|
+
return undefined;
|
|
12
|
+
return ids
|
|
13
|
+
.split(/\s+/)
|
|
14
|
+
.map(id => element.ownerDocument.getElementById(id))
|
|
15
|
+
.filter((found) => Boolean(found))
|
|
16
|
+
.map(found => found.getAttribute('aria-label')?.trim() || text(found))
|
|
17
|
+
.join(' ');
|
|
18
|
+
}
|
|
19
|
+
/** An element's accessible name: `aria-labelledby`'s text, else `aria-label`, else its text. */
|
|
20
|
+
export function accessibleName(element) {
|
|
21
|
+
return (referenced(element, 'aria-labelledby') ??
|
|
22
|
+
element.getAttribute('aria-label')?.trim() ??
|
|
23
|
+
text(element));
|
|
24
|
+
}
|
|
25
|
+
/** An element's accessible description: the text `aria-describedby` names, or `''`. */
|
|
26
|
+
export function accessibleDescription(element) {
|
|
27
|
+
return referenced(element, 'aria-describedby') ?? '';
|
|
28
|
+
}
|
|
29
|
+
/** Whether an element is shown in the browser's top layer: an open popover. */
|
|
30
|
+
export function shownInTopLayer(element) {
|
|
31
|
+
if (!element)
|
|
32
|
+
return false;
|
|
33
|
+
try {
|
|
34
|
+
return element.matches(':popover-open');
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a part is showing: rendered, and laid out. `hidden` hides it only while no CSS gives
|
|
3
|
+
* it another `display`, so this reads the computed `display` rather than the attribute: a part
|
|
4
|
+
* that CSS lays out though it is `hidden` counts as showing.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isShowing(element: HTMLElement | null): boolean;
|
|
7
|
+
//# sourceMappingURL=showing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"showing.d.ts","sourceRoot":"","sources":["../../src/-private/showing.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,GAAG,OAAO,CAG9D"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a part is showing: rendered, and laid out. `hidden` hides it only while no CSS gives
|
|
3
|
+
* it another `display`, so this reads the computed `display` rather than the attribute: a part
|
|
4
|
+
* that CSS lays out though it is `hidden` counts as showing.
|
|
5
|
+
*/
|
|
6
|
+
export function isShowing(element) {
|
|
7
|
+
if (!element?.isConnected)
|
|
8
|
+
return false;
|
|
9
|
+
return getComputedStyle(element).display !== 'none';
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An element's border box, in CSS pixels, as its styles lay it out: unlike
|
|
3
|
+
* `getBoundingClientRect()`, a transform on the page (the test container's `scale(0.5)`)
|
|
4
|
+
* doesn't change it, and unlike `offsetWidth`, it isn't rounded.
|
|
5
|
+
*/
|
|
6
|
+
export declare function borderBox(element: Element): {
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=size.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"size.d.ts","sourceRoot":"","sources":["../../src/-private/size.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAkB7E"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An element's border box, in CSS pixels, as its styles lay it out: unlike
|
|
3
|
+
* `getBoundingClientRect()`, a transform on the page (the test container's `scale(0.5)`)
|
|
4
|
+
* doesn't change it, and unlike `offsetWidth`, it isn't rounded.
|
|
5
|
+
*/
|
|
6
|
+
export function borderBox(element) {
|
|
7
|
+
const style = getComputedStyle(element);
|
|
8
|
+
const px = (value) => Number.parseFloat(value) || 0;
|
|
9
|
+
let width = px(style.width);
|
|
10
|
+
let height = px(style.height);
|
|
11
|
+
if (style.boxSizing !== 'border-box') {
|
|
12
|
+
width +=
|
|
13
|
+
px(style.paddingLeft) +
|
|
14
|
+
px(style.paddingRight) +
|
|
15
|
+
px(style.borderLeftWidth) +
|
|
16
|
+
px(style.borderRightWidth);
|
|
17
|
+
height +=
|
|
18
|
+
px(style.paddingTop) +
|
|
19
|
+
px(style.paddingBottom) +
|
|
20
|
+
px(style.borderTopWidth) +
|
|
21
|
+
px(style.borderBottomWidth);
|
|
22
|
+
}
|
|
23
|
+
return { width, height };
|
|
24
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Where a lookup runs: an element (usually a component's root) or the whole document. */
|
|
2
|
+
export type Scope = Element | Document;
|
|
3
|
+
/** Thrown when a lookup finds nothing, so `exists` can tell absence from a mistake. */
|
|
4
|
+
export declare class NotFoundError extends Error {
|
|
5
|
+
constructor(message: string);
|
|
6
|
+
}
|
|
7
|
+
/** Thrown when a lookup finds the wrong thing, such as a harness pointed at another component. */
|
|
8
|
+
export declare class HarnessError extends Error {
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The element's parent in the component tree. A portalled or top-layer part names its root in
|
|
13
|
+
* `data-test-jn-owner`, so it hangs under that root wherever it sits in the document; every
|
|
14
|
+
* other element hangs under its DOM parent. An owner id that matches nothing falls back to the
|
|
15
|
+
* DOM parent.
|
|
16
|
+
*/
|
|
17
|
+
export declare function logicalParent(element: Element): Element | null;
|
|
18
|
+
/** Whether `element` is inside `scope` in the component tree. An element isn't inside itself. */
|
|
19
|
+
export declare function isWithin(element: Element, scope: Scope): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The root of the component instance an element belongs to: its nearest `data-test-jn`
|
|
22
|
+
* ancestor. A wrapper's root (`data-test-jn-wrapper`: a scroller, a layout, a heading) is
|
|
23
|
+
* passed over, so what the caller puts inside a wrapper stays the part of the component around
|
|
24
|
+
* it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function componentOf(element: Element): Element | null;
|
|
27
|
+
/**
|
|
28
|
+
* The elements matching `selector` inside `scope` in the component tree, in document order.
|
|
29
|
+
* The search covers the whole document, because a portalled part can be anywhere in it.
|
|
30
|
+
*/
|
|
31
|
+
export declare function findWithin(scope: Scope, selector: string): Element[];
|
|
32
|
+
/** `<div id="x" class="a b">` as `div#x.a.b`, for error messages. */
|
|
33
|
+
export declare function describeElement(element: Element): string;
|
|
34
|
+
//# sourceMappingURL=tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["../../src/-private/tree.ts"],"names":[],"mappings":"AAEA,0FAA0F;AAC1F,MAAM,MAAM,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAA;AAEtC,uFAAuF;AACvF,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM;CAI5B;AAED,kGAAkG;AAClG,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;CAI5B;AAMD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,GAAG,IAAI,CAO9D;AAaD,iGAAiG;AACjG,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAMhE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,GAAG,IAAI,CAM5D;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,EAAE,CAGpE;AAED,qEAAqE;AACrE,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAIxD"}
|