@ariakit/test 0.2.5 → 0.3.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 +26 -0
- package/cjs/__chunks/473V5JUA.cjs +19 -0
- package/cjs/__chunks/645PZZGM.cjs +13 -0
- package/cjs/__chunks/6PJ6QG4X.cjs +204 -0
- package/cjs/__chunks/6WHWNYHF.cjs +56 -0
- package/cjs/__chunks/CR7E273F.cjs +70 -0
- package/cjs/__chunks/{2V5PIRJZ.cjs → CVZQHCPZ.cjs} +67 -67
- package/cjs/__chunks/HNXGMK5P.cjs +35 -0
- package/cjs/__chunks/J6ZZZ7OL.cjs +12 -0
- package/cjs/__chunks/{LUIPCXQX.cjs → MWZXO7MI.cjs} +45 -42
- package/cjs/__chunks/NUOZZLPY.cjs +29 -0
- package/cjs/__chunks/OUXW5FPV.cjs +125 -0
- package/cjs/__chunks/R25SVNFL.cjs +94 -0
- package/cjs/__chunks/R7VOUI26.cjs +32 -0
- package/cjs/__chunks/SSTGZXPB.cjs +57 -0
- package/cjs/__chunks/YJVLDF2F.cjs +68 -0
- package/cjs/__utils.d.ts +6 -3
- package/cjs/blur.cjs +4 -6
- package/cjs/blur.d.ts +1 -2
- package/cjs/click.cjs +10 -12
- package/cjs/click.d.ts +1 -2
- package/cjs/dispatch.cjs +8 -0
- package/cjs/dispatch.d.ts +9 -0
- package/cjs/focus.cjs +4 -6
- package/cjs/focus.d.ts +1 -2
- package/cjs/hover.cjs +5 -7
- package/cjs/hover.d.ts +1 -2
- package/cjs/index.cjs +17 -75
- package/cjs/index.d.ts +2 -5
- package/cjs/mouse-down.cjs +6 -8
- package/cjs/mouse-down.d.ts +1 -2
- package/cjs/mouse-up.cjs +4 -5
- package/cjs/mouse-up.d.ts +1 -2
- package/cjs/press.cjs +8 -10
- package/cjs/press.d.ts +0 -1
- package/cjs/query.cjs +9 -0
- package/cjs/query.d.ts +3989 -0
- package/cjs/react.cjs +89 -0
- package/cjs/react.d.ts +7 -0
- package/cjs/select.cjs +10 -12
- package/cjs/select.d.ts +1 -2
- package/cjs/sleep.cjs +3 -4
- package/cjs/tap.cjs +11 -13
- package/cjs/tap.d.ts +1 -2
- package/cjs/tsconfig.build.tsbuildinfo +1 -1
- package/cjs/type.cjs +6 -8
- package/cjs/type.d.ts +0 -1
- package/cjs/wait-for.cjs +3 -2
- package/cjs/wait-for.d.ts +2 -1
- package/dispatch/package.json +8 -0
- package/esm/__chunks/{6PY4HXVO.js → 2YBPSAHP.js} +69 -69
- package/esm/__chunks/33MQDYWJ.js +125 -0
- package/esm/__chunks/45H4QFE4.js +94 -0
- package/esm/__chunks/4NZZR22G.js +35 -0
- package/esm/__chunks/7I22ZP6R.js +13 -0
- package/esm/__chunks/BKSZ7WES.js +204 -0
- package/esm/__chunks/MOHPNQYM.js +70 -0
- package/esm/__chunks/PGGOW3IT.js +57 -0
- package/esm/__chunks/SKXK6BOG.js +29 -0
- package/esm/__chunks/WWAF2MEB.js +12 -0
- package/esm/__chunks/{SWUQE4WB.js → X5N4V7NJ.js} +46 -43
- package/esm/__chunks/Y4VDXWJ6.js +32 -0
- package/esm/__chunks/YXZMMBB6.js +19 -0
- package/esm/__chunks/ZJJNX53K.js +68 -0
- package/esm/__chunks/ZU6UY6LZ.js +56 -0
- package/esm/__utils.d.ts +6 -3
- package/esm/blur.d.ts +1 -2
- package/esm/blur.js +3 -5
- package/esm/click.d.ts +1 -2
- package/esm/click.js +9 -11
- package/esm/dispatch.d.ts +9 -0
- package/esm/dispatch.js +8 -0
- package/esm/focus.d.ts +1 -2
- package/esm/focus.js +3 -5
- package/esm/hover.d.ts +1 -2
- package/esm/hover.js +4 -6
- package/esm/index.d.ts +2 -5
- package/esm/index.js +29 -87
- package/esm/mouse-down.d.ts +1 -2
- package/esm/mouse-down.js +5 -7
- package/esm/mouse-up.d.ts +1 -2
- package/esm/mouse-up.js +3 -4
- package/esm/press.d.ts +0 -1
- package/esm/press.js +7 -9
- package/esm/query.d.ts +3989 -0
- package/esm/query.js +9 -0
- package/esm/react.d.ts +7 -0
- package/esm/react.js +89 -0
- package/esm/select.d.ts +1 -2
- package/esm/select.js +9 -11
- package/esm/sleep.js +2 -3
- package/esm/tap.d.ts +1 -2
- package/esm/tap.js +10 -12
- package/esm/tsconfig.build.tsbuildinfo +1 -1
- package/esm/type.d.ts +0 -1
- package/esm/type.js +5 -7
- package/esm/wait-for.d.ts +2 -1
- package/esm/wait-for.js +2 -1
- package/package.json +21 -24
- package/query/package.json +8 -0
- package/react/package.json +8 -0
- package/act/package.json +0 -8
- package/cjs/__chunks/3NIZQX5J.cjs +0 -6
- package/cjs/__chunks/3WW644T7.cjs +0 -20
- package/cjs/__chunks/5F5PNQCC.cjs +0 -22
- package/cjs/__chunks/7BZFO6FC.cjs +0 -12
- package/cjs/__chunks/7RUXTAPP.cjs +0 -16
- package/cjs/__chunks/B4VP2LEU.cjs +0 -28
- package/cjs/__chunks/BHNBCXUN.cjs +0 -33
- package/cjs/__chunks/EGF4KWUK.cjs +0 -64
- package/cjs/__chunks/HGTTGPFK.cjs +0 -54
- package/cjs/__chunks/JY5DGPUE.cjs +0 -14
- package/cjs/__chunks/KRQVK4KQ.cjs +0 -38
- package/cjs/__chunks/LFNIGEB6.cjs +0 -50
- package/cjs/__chunks/MQA5IB4L.cjs +0 -6
- package/cjs/__chunks/Q7PN3HIB.cjs +0 -121
- package/cjs/__chunks/SYQ5J5KP.cjs +0 -32
- package/cjs/__chunks/VIKUJSTX.cjs +0 -83
- package/cjs/act.cjs +0 -8
- package/cjs/act.d.ts +0 -1
- package/cjs/fire-event.cjs +0 -9
- package/cjs/fire-event.d.ts +0 -3
- package/cjs/polyfills.cjs +0 -3
- package/cjs/polyfills.d.ts +0 -1
- package/cjs/render.cjs +0 -9
- package/cjs/render.d.ts +0 -5
- package/cjs/screen.cjs +0 -55
- package/cjs/screen.d.ts +0 -26
- package/cjs/within.cjs +0 -7
- package/cjs/within.d.ts +0 -1
- package/esm/__chunks/2OZA4WAZ.js +0 -50
- package/esm/__chunks/2RHTJFSK.js +0 -38
- package/esm/__chunks/3C72DPE2.js +0 -54
- package/esm/__chunks/4A3YKZRA.js +0 -121
- package/esm/__chunks/5JPM5LQX.js +0 -6
- package/esm/__chunks/5PINJ4MD.js +0 -16
- package/esm/__chunks/AEOE57TZ.js +0 -33
- package/esm/__chunks/EVYPE6ZJ.js +0 -32
- package/esm/__chunks/EX5WPJOU.js +0 -64
- package/esm/__chunks/JTFRQL3H.js +0 -83
- package/esm/__chunks/LJWZLI6L.js +0 -14
- package/esm/__chunks/OQYWQML5.js +0 -12
- package/esm/__chunks/OSCTTZUZ.js +0 -28
- package/esm/__chunks/QA3ZS6S2.js +0 -6
- package/esm/__chunks/R7IYW63J.js +0 -22
- package/esm/__chunks/ZEO5Q6UD.js +0 -20
- package/esm/act.d.ts +0 -1
- package/esm/act.js +0 -8
- package/esm/fire-event.d.ts +0 -3
- package/esm/fire-event.js +0 -9
- package/esm/polyfills.d.ts +0 -1
- package/esm/polyfills.js +0 -3
- package/esm/render.d.ts +0 -5
- package/esm/render.js +0 -9
- package/esm/screen.d.ts +0 -26
- package/esm/screen.js +0 -55
- package/esm/within.d.ts +0 -1
- package/esm/within.js +0 -7
- package/fire-event/package.json +0 -8
- package/polyfills/package.json +0 -8
- package/render/package.json +0 -8
- package/screen/package.json +0 -8
- package/within/package.json +0 -8
- /package/cjs/__chunks/{AYRPODWR.cjs → IDMD7IDF.cjs} +0 -0
- /package/esm/__chunks/{PNBZ5NXH.js → 36HVAQ4Z.js} +0 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__spreadProps,
|
|
3
|
+
__spreadValues
|
|
4
|
+
} from "./6XO5G2QR.js";
|
|
5
|
+
|
|
6
|
+
// src/query.ts
|
|
7
|
+
import { queries as baseQueries } from "@testing-library/dom";
|
|
8
|
+
var roles = [
|
|
9
|
+
"alert",
|
|
10
|
+
"alertdialog",
|
|
11
|
+
"application",
|
|
12
|
+
"article",
|
|
13
|
+
"banner",
|
|
14
|
+
"blockquote",
|
|
15
|
+
"button",
|
|
16
|
+
"caption",
|
|
17
|
+
"cell",
|
|
18
|
+
"checkbox",
|
|
19
|
+
"code",
|
|
20
|
+
"columnheader",
|
|
21
|
+
"combobox",
|
|
22
|
+
"complementary",
|
|
23
|
+
"contentinfo",
|
|
24
|
+
"definition",
|
|
25
|
+
"deletion",
|
|
26
|
+
"dialog",
|
|
27
|
+
"directory",
|
|
28
|
+
"document",
|
|
29
|
+
"emphasis",
|
|
30
|
+
"feed",
|
|
31
|
+
"figure",
|
|
32
|
+
"form",
|
|
33
|
+
"generic",
|
|
34
|
+
"grid",
|
|
35
|
+
"gridcell",
|
|
36
|
+
"group",
|
|
37
|
+
"heading",
|
|
38
|
+
"img",
|
|
39
|
+
"insertion",
|
|
40
|
+
"link",
|
|
41
|
+
"list",
|
|
42
|
+
"listbox",
|
|
43
|
+
"listitem",
|
|
44
|
+
"log",
|
|
45
|
+
"main",
|
|
46
|
+
"marquee",
|
|
47
|
+
"math",
|
|
48
|
+
"menu",
|
|
49
|
+
"menubar",
|
|
50
|
+
"menuitem",
|
|
51
|
+
"menuitemcheckbox",
|
|
52
|
+
"menuitemradio",
|
|
53
|
+
"meter",
|
|
54
|
+
"navigation",
|
|
55
|
+
"none",
|
|
56
|
+
"note",
|
|
57
|
+
"option",
|
|
58
|
+
"paragraph",
|
|
59
|
+
"presentation",
|
|
60
|
+
"progressbar",
|
|
61
|
+
"radio",
|
|
62
|
+
"radiogroup",
|
|
63
|
+
"region",
|
|
64
|
+
"row",
|
|
65
|
+
"rowgroup",
|
|
66
|
+
"rowheader",
|
|
67
|
+
"scrollbar",
|
|
68
|
+
"search",
|
|
69
|
+
"searchbox",
|
|
70
|
+
"separator",
|
|
71
|
+
"slider",
|
|
72
|
+
"spinbutton",
|
|
73
|
+
"status",
|
|
74
|
+
"strong",
|
|
75
|
+
"subscript",
|
|
76
|
+
"superscript",
|
|
77
|
+
"switch",
|
|
78
|
+
"tab",
|
|
79
|
+
"table",
|
|
80
|
+
"tablist",
|
|
81
|
+
"tabpanel",
|
|
82
|
+
"term",
|
|
83
|
+
"textbox",
|
|
84
|
+
"time",
|
|
85
|
+
"timer",
|
|
86
|
+
"toolbar",
|
|
87
|
+
"tooltip",
|
|
88
|
+
"tree",
|
|
89
|
+
"treegrid",
|
|
90
|
+
"treeitem"
|
|
91
|
+
];
|
|
92
|
+
var queries = Object.entries(baseQueries).reduce((queries2, [key, query2]) => {
|
|
93
|
+
queries2[key] = (...args) => query2(document.body, ...args);
|
|
94
|
+
return queries2;
|
|
95
|
+
}, {});
|
|
96
|
+
function matchName(name, accessibleName) {
|
|
97
|
+
if (accessibleName == null)
|
|
98
|
+
return false;
|
|
99
|
+
if (typeof name === "string") {
|
|
100
|
+
return accessibleName === name;
|
|
101
|
+
}
|
|
102
|
+
return name.test(accessibleName);
|
|
103
|
+
}
|
|
104
|
+
function getNameOption(name) {
|
|
105
|
+
return (accessibleName, element) => {
|
|
106
|
+
if (matchName(name, accessibleName))
|
|
107
|
+
return true;
|
|
108
|
+
if (element.getAttribute("aria-label"))
|
|
109
|
+
return false;
|
|
110
|
+
const labeledBy = element.getAttribute("aria-labelledby");
|
|
111
|
+
if (!labeledBy) {
|
|
112
|
+
const content = "placeholder" in element && element.placeholder != null ? element.placeholder : element.textContent;
|
|
113
|
+
return matchName(name, content);
|
|
114
|
+
}
|
|
115
|
+
const label = document.getElementById(labeledBy);
|
|
116
|
+
if (!(label == null ? void 0 : label.textContent))
|
|
117
|
+
return false;
|
|
118
|
+
return matchName(name, label.textContent);
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function createRoleQuery(role) {
|
|
122
|
+
const createQuery = (query3) => {
|
|
123
|
+
return (name, options) => {
|
|
124
|
+
if (!name) {
|
|
125
|
+
return query3(role, options);
|
|
126
|
+
}
|
|
127
|
+
return query3(role, __spreadValues({ name: getNameOption(name) }, options));
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
const createIncludesHidden = (query3) => (name, options) => query3(name, __spreadValues({ hidden: true }, options));
|
|
131
|
+
const query2 = createQuery(queries.queryByRole);
|
|
132
|
+
const allQuery = createQuery(queries.queryAllByRole);
|
|
133
|
+
const waitQuery = createQuery(queries.findByRole);
|
|
134
|
+
const waitAllQuery = createQuery(queries.findAllByRole);
|
|
135
|
+
const ensureQuery = createQuery(queries.getByRole);
|
|
136
|
+
const ensureAllQuery = createQuery(queries.getAllByRole);
|
|
137
|
+
const all = Object.assign(allQuery, {
|
|
138
|
+
includesHidden: createIncludesHidden(allQuery),
|
|
139
|
+
wait: Object.assign(waitAllQuery, {
|
|
140
|
+
includesHidden: createIncludesHidden(waitAllQuery)
|
|
141
|
+
}),
|
|
142
|
+
ensure: Object.assign(ensureAllQuery, {
|
|
143
|
+
includesHidden: createIncludesHidden(ensureAllQuery)
|
|
144
|
+
})
|
|
145
|
+
});
|
|
146
|
+
const wait = Object.assign(waitQuery, {
|
|
147
|
+
includesHidden: createIncludesHidden(waitQuery),
|
|
148
|
+
all: Object.assign(waitAllQuery, {
|
|
149
|
+
includesHidden: createIncludesHidden(waitAllQuery)
|
|
150
|
+
})
|
|
151
|
+
});
|
|
152
|
+
const ensure = Object.assign(ensureQuery, {
|
|
153
|
+
includesHidden: createIncludesHidden(ensureQuery),
|
|
154
|
+
all: Object.assign(ensureAllQuery, {
|
|
155
|
+
includesHidden: createIncludesHidden(ensureAllQuery)
|
|
156
|
+
})
|
|
157
|
+
});
|
|
158
|
+
return Object.assign(query2, {
|
|
159
|
+
includesHidden: createIncludesHidden(query2),
|
|
160
|
+
all,
|
|
161
|
+
wait,
|
|
162
|
+
ensure
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
function createTextQuery() {
|
|
166
|
+
const all = Object.assign(queries.queryAllByText, {
|
|
167
|
+
wait: queries.findAllByText,
|
|
168
|
+
ensure: queries.getAllByText
|
|
169
|
+
});
|
|
170
|
+
const wait = Object.assign(queries.findByText, {
|
|
171
|
+
all: queries.findAllByText
|
|
172
|
+
});
|
|
173
|
+
const ensure = Object.assign(queries.getByText, {
|
|
174
|
+
all: queries.getAllByText
|
|
175
|
+
});
|
|
176
|
+
return Object.assign(queries.queryByText, { all, wait, ensure });
|
|
177
|
+
}
|
|
178
|
+
function createLabeledQuery() {
|
|
179
|
+
const all = Object.assign(queries.queryAllByLabelText, {
|
|
180
|
+
wait: queries.findAllByLabelText,
|
|
181
|
+
ensure: queries.getAllByLabelText
|
|
182
|
+
});
|
|
183
|
+
const wait = Object.assign(queries.findByLabelText, {
|
|
184
|
+
all: queries.findAllByLabelText
|
|
185
|
+
});
|
|
186
|
+
const ensure = Object.assign(queries.getByLabelText, {
|
|
187
|
+
all: queries.getAllByLabelText
|
|
188
|
+
});
|
|
189
|
+
return Object.assign(queries.queryByLabelText, { all, wait, ensure });
|
|
190
|
+
}
|
|
191
|
+
var roleQueries = roles.reduce((acc, role) => {
|
|
192
|
+
acc[role] = createRoleQuery(role);
|
|
193
|
+
return acc;
|
|
194
|
+
}, {});
|
|
195
|
+
var query = __spreadProps(__spreadValues({}, roleQueries), {
|
|
196
|
+
text: createTextQuery(),
|
|
197
|
+
labeled: createLabeledQuery()
|
|
198
|
+
});
|
|
199
|
+
var q = query;
|
|
200
|
+
|
|
201
|
+
export {
|
|
202
|
+
query,
|
|
203
|
+
q
|
|
204
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// src/__utils.ts
|
|
2
|
+
import { isFocusable } from "@ariakit/core/utils/focus";
|
|
3
|
+
import { noop } from "@ariakit/core/utils/misc";
|
|
4
|
+
var isBrowser = typeof navigator !== "undefined" && !navigator.userAgent.includes("jsdom") && typeof window !== "undefined" && !("happyDOM" in window);
|
|
5
|
+
async function flushMicrotasks() {
|
|
6
|
+
await Promise.resolve();
|
|
7
|
+
await Promise.resolve();
|
|
8
|
+
await Promise.resolve();
|
|
9
|
+
}
|
|
10
|
+
function nextFrame() {
|
|
11
|
+
return new Promise(requestAnimationFrame);
|
|
12
|
+
}
|
|
13
|
+
function setActEnvironment(value) {
|
|
14
|
+
const scope = globalThis;
|
|
15
|
+
const previousValue = scope.IS_REACT_ACT_ENVIRONMENT;
|
|
16
|
+
scope.IS_REACT_ACT_ENVIRONMENT = value;
|
|
17
|
+
const restoreActEnvironment = () => {
|
|
18
|
+
scope.IS_REACT_ACT_ENVIRONMENT = previousValue;
|
|
19
|
+
};
|
|
20
|
+
return restoreActEnvironment;
|
|
21
|
+
}
|
|
22
|
+
function applyBrowserPolyfills() {
|
|
23
|
+
if (isBrowser)
|
|
24
|
+
return noop;
|
|
25
|
+
const originalFocus = HTMLElement.prototype.focus;
|
|
26
|
+
HTMLElement.prototype.focus = function focus(options) {
|
|
27
|
+
if (!isFocusable(this))
|
|
28
|
+
return;
|
|
29
|
+
return originalFocus.call(this, options);
|
|
30
|
+
};
|
|
31
|
+
const originalGetClientRects = Element.prototype.getClientRects;
|
|
32
|
+
Element.prototype.getClientRects = function getClientRects() {
|
|
33
|
+
const isHidden = (element) => {
|
|
34
|
+
if (!element.isConnected)
|
|
35
|
+
return true;
|
|
36
|
+
if (element.parentElement && isHidden(element.parentElement))
|
|
37
|
+
return true;
|
|
38
|
+
if (!(element instanceof HTMLElement))
|
|
39
|
+
return false;
|
|
40
|
+
if (element.hidden)
|
|
41
|
+
return true;
|
|
42
|
+
const style = getComputedStyle(element);
|
|
43
|
+
return style.display === "none" || style.visibility === "hidden";
|
|
44
|
+
};
|
|
45
|
+
if (isHidden(this))
|
|
46
|
+
return [];
|
|
47
|
+
return [{ width: 1, height: 1 }];
|
|
48
|
+
};
|
|
49
|
+
return () => {
|
|
50
|
+
HTMLElement.prototype.focus = originalFocus;
|
|
51
|
+
Element.prototype.getClientRects = originalGetClientRects;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
async function wrapAsync(fn) {
|
|
55
|
+
const restoreActEnvironment = setActEnvironment(false);
|
|
56
|
+
const removeBrowserPolyfills = applyBrowserPolyfills();
|
|
57
|
+
try {
|
|
58
|
+
return await fn();
|
|
59
|
+
} finally {
|
|
60
|
+
restoreActEnvironment();
|
|
61
|
+
removeBrowserPolyfills();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
isBrowser,
|
|
67
|
+
flushMicrotasks,
|
|
68
|
+
nextFrame,
|
|
69
|
+
wrapAsync
|
|
70
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
blur
|
|
3
|
+
} from "./4NZZR22G.js";
|
|
4
|
+
import {
|
|
5
|
+
focus
|
|
6
|
+
} from "./Y4VDXWJ6.js";
|
|
7
|
+
import {
|
|
8
|
+
dispatch
|
|
9
|
+
} from "./ZU6UY6LZ.js";
|
|
10
|
+
import {
|
|
11
|
+
wrapAsync
|
|
12
|
+
} from "./MOHPNQYM.js";
|
|
13
|
+
import {
|
|
14
|
+
__spreadValues
|
|
15
|
+
} from "./6XO5G2QR.js";
|
|
16
|
+
|
|
17
|
+
// src/mouse-down.ts
|
|
18
|
+
import { getDocument, isVisible } from "@ariakit/core/utils/dom";
|
|
19
|
+
import { getClosestFocusable, isFocusable } from "@ariakit/core/utils/focus";
|
|
20
|
+
import { invariant } from "@ariakit/core/utils/misc";
|
|
21
|
+
function mouseDown(element, options) {
|
|
22
|
+
return wrapAsync(async () => {
|
|
23
|
+
invariant(element, "Unable to mouseDown on null element");
|
|
24
|
+
if (!isVisible(element))
|
|
25
|
+
return;
|
|
26
|
+
const { disabled } = element;
|
|
27
|
+
let defaultAllowed = await dispatch.pointerDown(element, options);
|
|
28
|
+
if (!disabled) {
|
|
29
|
+
if (!await dispatch.mouseDown(element, __spreadValues({ detail: 1 }, options))) {
|
|
30
|
+
defaultAllowed = false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (defaultAllowed) {
|
|
34
|
+
const selection = getDocument(element).getSelection();
|
|
35
|
+
if (selection && selection.rangeCount) {
|
|
36
|
+
const range = selection.getRangeAt(0);
|
|
37
|
+
if (!range.collapsed) {
|
|
38
|
+
selection.removeAllRanges();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (isFocusable(element) && getComputedStyle(element).pointerEvents !== "none") {
|
|
42
|
+
await focus(element);
|
|
43
|
+
} else if (element.parentElement) {
|
|
44
|
+
const closestFocusable = getClosestFocusable(element.parentElement);
|
|
45
|
+
if (closestFocusable) {
|
|
46
|
+
await focus(closestFocusable);
|
|
47
|
+
} else {
|
|
48
|
+
await blur();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
mouseDown
|
|
57
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
dispatch
|
|
3
|
+
} from "./ZU6UY6LZ.js";
|
|
4
|
+
import {
|
|
5
|
+
wrapAsync
|
|
6
|
+
} from "./MOHPNQYM.js";
|
|
7
|
+
import {
|
|
8
|
+
__spreadValues
|
|
9
|
+
} from "./6XO5G2QR.js";
|
|
10
|
+
|
|
11
|
+
// src/mouse-up.ts
|
|
12
|
+
import { isVisible } from "@ariakit/core/utils/dom";
|
|
13
|
+
import { invariant } from "@ariakit/core/utils/misc";
|
|
14
|
+
function mouseUp(element, options) {
|
|
15
|
+
return wrapAsync(async () => {
|
|
16
|
+
invariant(element, "Unable to mouseUp on null element");
|
|
17
|
+
if (!isVisible(element))
|
|
18
|
+
return;
|
|
19
|
+
const { disabled } = element;
|
|
20
|
+
await dispatch.pointerUp(element, options);
|
|
21
|
+
if (disabled)
|
|
22
|
+
return;
|
|
23
|
+
await dispatch.mouseUp(element, __spreadValues({ detail: 1 }, options));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
mouseUp
|
|
29
|
+
};
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
2
|
mouseUp
|
|
3
|
-
} from "./
|
|
3
|
+
} from "./SKXK6BOG.js";
|
|
4
4
|
import {
|
|
5
5
|
mouseDown
|
|
6
|
-
} from "./
|
|
6
|
+
} from "./PGGOW3IT.js";
|
|
7
7
|
import {
|
|
8
8
|
hover
|
|
9
|
-
} from "./
|
|
9
|
+
} from "./ZJJNX53K.js";
|
|
10
10
|
import {
|
|
11
11
|
focus
|
|
12
|
-
} from "./
|
|
12
|
+
} from "./Y4VDXWJ6.js";
|
|
13
13
|
import {
|
|
14
|
-
|
|
15
|
-
} from "./
|
|
14
|
+
dispatch
|
|
15
|
+
} from "./ZU6UY6LZ.js";
|
|
16
16
|
import {
|
|
17
17
|
sleep
|
|
18
|
-
} from "./
|
|
18
|
+
} from "./YXZMMBB6.js";
|
|
19
19
|
import {
|
|
20
|
-
|
|
21
|
-
} from "./
|
|
20
|
+
wrapAsync
|
|
21
|
+
} from "./MOHPNQYM.js";
|
|
22
22
|
import {
|
|
23
23
|
__spreadValues
|
|
24
24
|
} from "./6XO5G2QR.js";
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
// src/click.ts
|
|
27
27
|
import { closest, isVisible } from "@ariakit/core/utils/dom";
|
|
28
28
|
import { isFocusable } from "@ariakit/core/utils/focus";
|
|
29
|
+
import { invariant } from "@ariakit/core/utils/misc";
|
|
29
30
|
function getClosestLabel(element) {
|
|
30
31
|
if (!isFocusable(element)) {
|
|
31
32
|
return closest(element, "label");
|
|
@@ -37,18 +38,18 @@ function getInputFromLabel(element) {
|
|
|
37
38
|
const input = element.htmlFor ? (_a = element.ownerDocument) == null ? void 0 : _a.getElementById(element.htmlFor) : element.querySelector("input,textarea,select");
|
|
38
39
|
return input;
|
|
39
40
|
}
|
|
40
|
-
function clickLabel(element, options) {
|
|
41
|
+
async function clickLabel(element, options) {
|
|
41
42
|
const input = getInputFromLabel(element);
|
|
42
43
|
const isInputDisabled = Boolean(input == null ? void 0 : input.disabled);
|
|
43
44
|
if (input) {
|
|
44
45
|
input.disabled = true;
|
|
45
46
|
}
|
|
46
|
-
const defaultAllowed =
|
|
47
|
+
const defaultAllowed = await dispatch.click(element, options);
|
|
47
48
|
if (input) {
|
|
48
49
|
input.disabled = isInputDisabled;
|
|
49
50
|
if (defaultAllowed && isFocusable(input)) {
|
|
50
|
-
focus(input);
|
|
51
|
-
|
|
51
|
+
await focus(input);
|
|
52
|
+
await dispatch.click(input);
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
}
|
|
@@ -56,10 +57,10 @@ function setSelected(element, selected) {
|
|
|
56
57
|
element.setAttribute("selected", selected ? "selected" : "");
|
|
57
58
|
element.selected = selected;
|
|
58
59
|
}
|
|
59
|
-
function clickOption(element, eventOptions) {
|
|
60
|
+
async function clickOption(element, eventOptions) {
|
|
60
61
|
const select = closest(element, "select");
|
|
61
62
|
if (!select) {
|
|
62
|
-
|
|
63
|
+
await dispatch.click(element, eventOptions);
|
|
63
64
|
return;
|
|
64
65
|
}
|
|
65
66
|
if (select.multiple) {
|
|
@@ -94,37 +95,39 @@ function clickOption(element, eventOptions) {
|
|
|
94
95
|
} else {
|
|
95
96
|
setSelected(element, true);
|
|
96
97
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
await dispatch.input(select);
|
|
99
|
+
await dispatch.change(select);
|
|
100
|
+
await dispatch.click(element, eventOptions);
|
|
100
101
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
mouseDown(element, options);
|
|
106
|
-
await queuedMicrotasks();
|
|
107
|
-
while (!isVisible(element)) {
|
|
108
|
-
if (!element.parentElement)
|
|
102
|
+
function click(element, options, tap = false) {
|
|
103
|
+
return wrapAsync(async () => {
|
|
104
|
+
invariant(element, "Unable to click on null element");
|
|
105
|
+
if (!isVisible(element))
|
|
109
106
|
return;
|
|
110
|
-
element
|
|
111
|
-
|
|
112
|
-
|
|
107
|
+
await hover(element, options);
|
|
108
|
+
await mouseDown(element, options);
|
|
109
|
+
while (!isVisible(element)) {
|
|
110
|
+
if (!element.parentElement)
|
|
111
|
+
return;
|
|
112
|
+
element = element.parentElement;
|
|
113
|
+
}
|
|
114
|
+
if (!tap) {
|
|
115
|
+
await sleep();
|
|
116
|
+
}
|
|
117
|
+
await mouseUp(element, options);
|
|
118
|
+
const { disabled } = element;
|
|
119
|
+
if (disabled)
|
|
120
|
+
return;
|
|
121
|
+
const label = getClosestLabel(element);
|
|
122
|
+
if (label) {
|
|
123
|
+
await clickLabel(label, __spreadValues({ detail: 1 }, options));
|
|
124
|
+
} else if (element instanceof HTMLOptionElement) {
|
|
125
|
+
await clickOption(element, __spreadValues({ detail: 1 }, options));
|
|
126
|
+
} else {
|
|
127
|
+
await dispatch.click(element, __spreadValues({ detail: 1 }, options));
|
|
128
|
+
}
|
|
113
129
|
await sleep();
|
|
114
|
-
}
|
|
115
|
-
mouseUp(element, options);
|
|
116
|
-
const { disabled } = element;
|
|
117
|
-
if (disabled)
|
|
118
|
-
return;
|
|
119
|
-
const label = getClosestLabel(element);
|
|
120
|
-
if (label) {
|
|
121
|
-
clickLabel(label, __spreadValues({ detail: 1 }, options));
|
|
122
|
-
} else if (element instanceof HTMLOptionElement) {
|
|
123
|
-
clickOption(element, __spreadValues({ detail: 1 }, options));
|
|
124
|
-
} else {
|
|
125
|
-
fireEvent.click(element, __spreadValues({ detail: 1 }, options));
|
|
126
|
-
}
|
|
127
|
-
await sleep();
|
|
130
|
+
});
|
|
128
131
|
}
|
|
129
132
|
|
|
130
133
|
export {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
dispatch
|
|
3
|
+
} from "./ZU6UY6LZ.js";
|
|
4
|
+
import {
|
|
5
|
+
flushMicrotasks,
|
|
6
|
+
wrapAsync
|
|
7
|
+
} from "./MOHPNQYM.js";
|
|
8
|
+
|
|
9
|
+
// src/focus.ts
|
|
10
|
+
import { getActiveElement } from "@ariakit/core/utils/dom";
|
|
11
|
+
import { isFocusable } from "@ariakit/core/utils/focus";
|
|
12
|
+
import { invariant } from "@ariakit/core/utils/misc";
|
|
13
|
+
function focus(element) {
|
|
14
|
+
return wrapAsync(async () => {
|
|
15
|
+
invariant(element, "Unable to focus on null element");
|
|
16
|
+
if (getActiveElement(element) === element)
|
|
17
|
+
return;
|
|
18
|
+
if (!isFocusable(element))
|
|
19
|
+
return;
|
|
20
|
+
const activeElement = getActiveElement(element);
|
|
21
|
+
if (activeElement == null ? void 0 : activeElement.dirty) {
|
|
22
|
+
await dispatch.change(activeElement);
|
|
23
|
+
activeElement.dirty = false;
|
|
24
|
+
}
|
|
25
|
+
element.focus();
|
|
26
|
+
await flushMicrotasks();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
focus
|
|
32
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isBrowser,
|
|
3
|
+
nextFrame,
|
|
4
|
+
wrapAsync
|
|
5
|
+
} from "./MOHPNQYM.js";
|
|
6
|
+
|
|
7
|
+
// src/sleep.ts
|
|
8
|
+
var defaultMs = isBrowser ? 150 : 10;
|
|
9
|
+
function sleep(ms = defaultMs) {
|
|
10
|
+
return wrapAsync(async () => {
|
|
11
|
+
await nextFrame();
|
|
12
|
+
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
13
|
+
await nextFrame();
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
sleep
|
|
19
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
dispatch
|
|
3
|
+
} from "./ZU6UY6LZ.js";
|
|
4
|
+
import {
|
|
5
|
+
sleep
|
|
6
|
+
} from "./YXZMMBB6.js";
|
|
7
|
+
import {
|
|
8
|
+
wrapAsync
|
|
9
|
+
} from "./MOHPNQYM.js";
|
|
10
|
+
import {
|
|
11
|
+
__spreadProps,
|
|
12
|
+
__spreadValues
|
|
13
|
+
} from "./6XO5G2QR.js";
|
|
14
|
+
|
|
15
|
+
// src/hover.ts
|
|
16
|
+
import { isVisible } from "@ariakit/core/utils/dom";
|
|
17
|
+
import { invariant } from "@ariakit/core/utils/misc";
|
|
18
|
+
function isPointerEventsEnabled(element) {
|
|
19
|
+
return getComputedStyle(element).pointerEvents !== "none";
|
|
20
|
+
}
|
|
21
|
+
function hover(element, options) {
|
|
22
|
+
return wrapAsync(async () => {
|
|
23
|
+
invariant(element, "Unable to hover on null element");
|
|
24
|
+
if (!isVisible(element))
|
|
25
|
+
return;
|
|
26
|
+
const document = element.ownerDocument;
|
|
27
|
+
const { lastHovered } = document;
|
|
28
|
+
const { disabled } = element;
|
|
29
|
+
const pointerEventsEnabled = isPointerEventsEnabled(element);
|
|
30
|
+
if (lastHovered && lastHovered !== element && isVisible(lastHovered)) {
|
|
31
|
+
await dispatch.pointerMove(lastHovered, options);
|
|
32
|
+
await dispatch.mouseMove(lastHovered, options);
|
|
33
|
+
if (isPointerEventsEnabled(lastHovered)) {
|
|
34
|
+
const isElementWithinLastHovered = lastHovered.contains(element);
|
|
35
|
+
const relatedTarget = pointerEventsEnabled ? element : null;
|
|
36
|
+
const leaveOptions = __spreadProps(__spreadValues({}, options), { relatedTarget });
|
|
37
|
+
await dispatch.pointerOut(lastHovered, leaveOptions);
|
|
38
|
+
if (!isElementWithinLastHovered) {
|
|
39
|
+
await dispatch.pointerLeave(lastHovered, leaveOptions);
|
|
40
|
+
}
|
|
41
|
+
await dispatch.mouseOut(lastHovered, leaveOptions);
|
|
42
|
+
if (!isElementWithinLastHovered) {
|
|
43
|
+
await dispatch.mouseLeave(lastHovered, leaveOptions);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
await sleep();
|
|
48
|
+
if (pointerEventsEnabled) {
|
|
49
|
+
const enterOptions = lastHovered ? __spreadValues({ relatedTarget: lastHovered }, options) : options;
|
|
50
|
+
await dispatch.pointerOver(element, enterOptions);
|
|
51
|
+
await dispatch.pointerEnter(element, enterOptions);
|
|
52
|
+
if (!disabled) {
|
|
53
|
+
await dispatch.mouseOver(element, enterOptions);
|
|
54
|
+
await dispatch.mouseEnter(element, enterOptions);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
await dispatch.pointerMove(element, options);
|
|
58
|
+
if (!disabled) {
|
|
59
|
+
await dispatch.mouseMove(element, options);
|
|
60
|
+
}
|
|
61
|
+
document.lastHovered = element;
|
|
62
|
+
await sleep();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export {
|
|
67
|
+
hover
|
|
68
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
flushMicrotasks,
|
|
3
|
+
wrapAsync
|
|
4
|
+
} from "./MOHPNQYM.js";
|
|
5
|
+
|
|
6
|
+
// src/dispatch.ts
|
|
7
|
+
import { getKeys, invariant } from "@ariakit/core/utils/misc";
|
|
8
|
+
import { createEvent, fireEvent } from "@testing-library/dom";
|
|
9
|
+
var pointerEvents = [
|
|
10
|
+
"mousemove",
|
|
11
|
+
"mouseover",
|
|
12
|
+
"mouseenter",
|
|
13
|
+
"mouseout",
|
|
14
|
+
"mouseleave",
|
|
15
|
+
"mousedown",
|
|
16
|
+
"mouseup",
|
|
17
|
+
"pointermove",
|
|
18
|
+
"pointerover",
|
|
19
|
+
"pointerenter",
|
|
20
|
+
"pointerout",
|
|
21
|
+
"pointerleave",
|
|
22
|
+
"pointerdown",
|
|
23
|
+
"pointerup",
|
|
24
|
+
"click"
|
|
25
|
+
];
|
|
26
|
+
function baseDispatch(element, event) {
|
|
27
|
+
return wrapAsync(async () => {
|
|
28
|
+
invariant(element, `Unable to dispatch ${event.type} on null element`);
|
|
29
|
+
const eventName = event.type.toLowerCase();
|
|
30
|
+
if (pointerEvents.includes(eventName) && "classList" in element) {
|
|
31
|
+
const { pointerEvents: pointerEvents2 } = getComputedStyle(element);
|
|
32
|
+
if (pointerEvents2 === "none") {
|
|
33
|
+
if (element.parentElement) {
|
|
34
|
+
return baseDispatch(element.parentElement, event);
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const defaultAllowed = fireEvent(element, event);
|
|
40
|
+
await flushMicrotasks();
|
|
41
|
+
return defaultAllowed;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
var events = getKeys(fireEvent).reduce((events2, eventName) => {
|
|
45
|
+
events2[eventName] = (element, options) => {
|
|
46
|
+
invariant(element, `Unable to dispatch ${eventName} on null element`);
|
|
47
|
+
const event = createEvent[eventName](element, options);
|
|
48
|
+
return baseDispatch(element, event);
|
|
49
|
+
};
|
|
50
|
+
return events2;
|
|
51
|
+
}, {});
|
|
52
|
+
var dispatch = Object.assign(baseDispatch, events);
|
|
53
|
+
|
|
54
|
+
export {
|
|
55
|
+
dispatch
|
|
56
|
+
};
|