@testing-library/user-event 14.1.0 → 14.2.1
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/dist/index.cjs +275 -219
- package/dist/index.mjs +286 -230
- package/dist/types/options.d.ts +1 -1
- package/dist/types/utils/dataTransfer/Clipboard.d.ts +3 -1
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __defProps = Object.defineProperties;
|
|
3
4
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
@@ -158,8 +159,8 @@ var DataTransferStub = class {
|
|
|
158
159
|
this.files = createFileList([]);
|
|
159
160
|
}
|
|
160
161
|
getData(format) {
|
|
161
|
-
var
|
|
162
|
-
const match = (
|
|
162
|
+
var _a;
|
|
163
|
+
const match = (_a = this.items.find(getTypeMatcher(format, true))) != null ? _a : this.items.find(getTypeMatcher(format, false));
|
|
163
164
|
let text = "";
|
|
164
165
|
match == null ? void 0 : match.getAsString((t) => {
|
|
165
166
|
text = t;
|
|
@@ -197,12 +198,12 @@ var DataTransferStub = class {
|
|
|
197
198
|
setDragImage() {
|
|
198
199
|
}
|
|
199
200
|
};
|
|
200
|
-
function createDataTransfer(
|
|
201
|
-
const dt = typeof
|
|
201
|
+
function createDataTransfer(window, files = []) {
|
|
202
|
+
const dt = typeof window.DataTransfer === "undefined" ? new DataTransferStub() : new window.DataTransfer();
|
|
202
203
|
Object.defineProperty(dt, "files", { get: () => createFileList(files) });
|
|
203
204
|
return dt;
|
|
204
205
|
}
|
|
205
|
-
function getBlobFromDataTransferItem(
|
|
206
|
+
function getBlobFromDataTransferItem(window, item) {
|
|
206
207
|
if (item.kind === "file") {
|
|
207
208
|
return item.getAsFile();
|
|
208
209
|
}
|
|
@@ -210,7 +211,7 @@ function getBlobFromDataTransferItem(window2, item) {
|
|
|
210
211
|
item.getAsString((s) => {
|
|
211
212
|
data = s;
|
|
212
213
|
});
|
|
213
|
-
return new
|
|
214
|
+
return new window.Blob([data], { type: item.type });
|
|
214
215
|
}
|
|
215
216
|
|
|
216
217
|
// src/utils/misc/getWindow.ts
|
|
@@ -220,144 +221,137 @@ function getWindow(node) {
|
|
|
220
221
|
}
|
|
221
222
|
|
|
222
223
|
// src/utils/dataTransfer/Clipboard.ts
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
var ClipboardItemStub = class {
|
|
226
|
-
constructor(data) {
|
|
227
|
-
this[_a] = window;
|
|
228
|
-
this.data = data;
|
|
229
|
-
}
|
|
230
|
-
get types() {
|
|
231
|
-
return Array.from(Object.keys(this.data));
|
|
232
|
-
}
|
|
233
|
-
getType(type3) {
|
|
234
|
-
return __async(this, null, function* () {
|
|
235
|
-
const data = yield this.data[type3];
|
|
236
|
-
if (!data) {
|
|
237
|
-
throw new Error(`${type3} is not one of the available MIME types on this item.`);
|
|
238
|
-
}
|
|
239
|
-
return data instanceof this[Window].Blob ? data : new this[Window].Blob([data], { type: type3 });
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
_a = Window;
|
|
244
|
-
var ClipboardStubControl = Symbol("Manage ClipboardSub");
|
|
245
|
-
var _a2;
|
|
246
|
-
var ClipboardStub = class extends window.EventTarget {
|
|
247
|
-
constructor() {
|
|
248
|
-
super(...arguments);
|
|
249
|
-
this.items = [];
|
|
250
|
-
this[_a2] = window;
|
|
251
|
-
}
|
|
252
|
-
read() {
|
|
253
|
-
return __async(this, null, function* () {
|
|
254
|
-
return Array.from(this.items);
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
readText() {
|
|
258
|
-
return __async(this, null, function* () {
|
|
259
|
-
let text = "";
|
|
260
|
-
for (const item of this.items) {
|
|
261
|
-
const type3 = item.types.includes("text/plain") ? "text/plain" : item.types.find((t) => t.startsWith("text/"));
|
|
262
|
-
if (type3) {
|
|
263
|
-
text += yield item.getType(type3).then((b) => readBlobText(b, this[Window].FileReader));
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
return text;
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
write(data) {
|
|
270
|
-
return __async(this, null, function* () {
|
|
271
|
-
this.items = data;
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
writeText(text) {
|
|
275
|
-
return __async(this, null, function* () {
|
|
276
|
-
this.items = [createClipboardItem(this[Window], text)];
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
};
|
|
280
|
-
_a2 = Window, ClipboardStubControl;
|
|
281
|
-
function createClipboardItem(window2, ...blobs) {
|
|
282
|
-
const data = Object.fromEntries(blobs.map((b) => [
|
|
224
|
+
function createClipboardItem(window, ...blobs) {
|
|
225
|
+
const dataMap = Object.fromEntries(blobs.map((b) => [
|
|
283
226
|
typeof b === "string" ? "text/plain" : b.type,
|
|
284
227
|
Promise.resolve(b)
|
|
285
228
|
]));
|
|
286
|
-
if (typeof
|
|
287
|
-
|
|
288
|
-
item[Window] = window2;
|
|
289
|
-
return item;
|
|
290
|
-
} else {
|
|
291
|
-
return new window2.ClipboardItem(data);
|
|
229
|
+
if (typeof window.ClipboardItem !== "undefined") {
|
|
230
|
+
return new window.ClipboardItem(dataMap);
|
|
292
231
|
}
|
|
232
|
+
return new class ClipboardItem {
|
|
233
|
+
constructor(d) {
|
|
234
|
+
this.data = d;
|
|
235
|
+
}
|
|
236
|
+
get types() {
|
|
237
|
+
return Array.from(Object.keys(this.data));
|
|
238
|
+
}
|
|
239
|
+
getType(type3) {
|
|
240
|
+
return __async(this, null, function* () {
|
|
241
|
+
const value = yield this.data[type3];
|
|
242
|
+
if (!value) {
|
|
243
|
+
throw new Error(`${type3} is not one of the available MIME types on this item.`);
|
|
244
|
+
}
|
|
245
|
+
return value instanceof window.Blob ? value : new window.Blob([value], { type: type3 });
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}(dataMap);
|
|
249
|
+
}
|
|
250
|
+
var ClipboardStubControl = Symbol("Manage ClipboardSub");
|
|
251
|
+
function createClipboardStub(window, control) {
|
|
252
|
+
return Object.assign(new class Clipboard extends window.EventTarget {
|
|
253
|
+
constructor() {
|
|
254
|
+
super(...arguments);
|
|
255
|
+
this.items = [];
|
|
256
|
+
}
|
|
257
|
+
read() {
|
|
258
|
+
return __async(this, null, function* () {
|
|
259
|
+
return Array.from(this.items);
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
readText() {
|
|
263
|
+
return __async(this, null, function* () {
|
|
264
|
+
let text = "";
|
|
265
|
+
for (const item of this.items) {
|
|
266
|
+
const type3 = item.types.includes("text/plain") ? "text/plain" : item.types.find((t) => t.startsWith("text/"));
|
|
267
|
+
if (type3) {
|
|
268
|
+
text += yield item.getType(type3).then((b) => readBlobText(b, window.FileReader));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return text;
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
write(data) {
|
|
275
|
+
return __async(this, null, function* () {
|
|
276
|
+
this.items = data;
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
writeText(text) {
|
|
280
|
+
return __async(this, null, function* () {
|
|
281
|
+
this.items = [createClipboardItem(window, text)];
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}(), {
|
|
285
|
+
[ClipboardStubControl]: control
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
function isClipboardStub(clipboard) {
|
|
289
|
+
return !!(clipboard == null ? void 0 : clipboard[ClipboardStubControl]);
|
|
293
290
|
}
|
|
294
|
-
function attachClipboardStubToView(
|
|
295
|
-
if (
|
|
296
|
-
return
|
|
291
|
+
function attachClipboardStubToView(window) {
|
|
292
|
+
if (isClipboardStub(window.navigator.clipboard)) {
|
|
293
|
+
return window.navigator.clipboard[ClipboardStubControl];
|
|
297
294
|
}
|
|
298
|
-
const realClipboard = Object.getOwnPropertyDescriptor(
|
|
299
|
-
let stub
|
|
300
|
-
stub[Window] = window2;
|
|
295
|
+
const realClipboard = Object.getOwnPropertyDescriptor(window.navigator, "clipboard");
|
|
296
|
+
let stub;
|
|
301
297
|
const control = {
|
|
302
298
|
resetClipboardStub: () => {
|
|
303
|
-
stub =
|
|
304
|
-
stub[Window] = window2;
|
|
305
|
-
stub[ClipboardStubControl] = control;
|
|
299
|
+
stub = createClipboardStub(window, control);
|
|
306
300
|
},
|
|
307
301
|
detachClipboardStub: () => {
|
|
308
302
|
if (realClipboard) {
|
|
309
|
-
Object.defineProperty(
|
|
303
|
+
Object.defineProperty(window.navigator, "clipboard", realClipboard);
|
|
310
304
|
} else {
|
|
311
|
-
Object.defineProperty(
|
|
305
|
+
Object.defineProperty(window.navigator, "clipboard", {
|
|
312
306
|
value: void 0,
|
|
313
307
|
configurable: true
|
|
314
308
|
});
|
|
315
309
|
}
|
|
316
310
|
}
|
|
317
311
|
};
|
|
318
|
-
stub
|
|
319
|
-
Object.defineProperty(
|
|
312
|
+
stub = createClipboardStub(window, control);
|
|
313
|
+
Object.defineProperty(window.navigator, "clipboard", {
|
|
320
314
|
get: () => stub,
|
|
321
315
|
configurable: true
|
|
322
316
|
});
|
|
323
317
|
return stub[ClipboardStubControl];
|
|
324
318
|
}
|
|
325
|
-
function resetClipboardStubOnView(
|
|
326
|
-
if (
|
|
327
|
-
|
|
319
|
+
function resetClipboardStubOnView(window) {
|
|
320
|
+
if (isClipboardStub(window.navigator.clipboard)) {
|
|
321
|
+
window.navigator.clipboard[ClipboardStubControl].resetClipboardStub();
|
|
328
322
|
}
|
|
329
323
|
}
|
|
330
|
-
function detachClipboardStubFromView(
|
|
331
|
-
if (
|
|
332
|
-
|
|
324
|
+
function detachClipboardStubFromView(window) {
|
|
325
|
+
if (isClipboardStub(window.navigator.clipboard)) {
|
|
326
|
+
window.navigator.clipboard[ClipboardStubControl].detachClipboardStub();
|
|
333
327
|
}
|
|
334
328
|
}
|
|
335
|
-
function readDataTransferFromClipboard(
|
|
329
|
+
function readDataTransferFromClipboard(document) {
|
|
336
330
|
return __async(this, null, function* () {
|
|
337
|
-
const
|
|
338
|
-
const clipboard =
|
|
331
|
+
const window = document.defaultView;
|
|
332
|
+
const clipboard = window == null ? void 0 : window.navigator.clipboard;
|
|
339
333
|
const items = clipboard && (yield clipboard.read());
|
|
340
334
|
if (!items) {
|
|
341
335
|
throw new Error("The Clipboard API is unavailable.");
|
|
342
336
|
}
|
|
343
|
-
const dt = createDataTransfer(
|
|
337
|
+
const dt = createDataTransfer(window);
|
|
344
338
|
for (const item of items) {
|
|
345
339
|
for (const type3 of item.types) {
|
|
346
|
-
dt.setData(type3, yield item.getType(type3).then((b) => readBlobText(b,
|
|
340
|
+
dt.setData(type3, yield item.getType(type3).then((b) => readBlobText(b, window.FileReader)));
|
|
347
341
|
}
|
|
348
342
|
}
|
|
349
343
|
return dt;
|
|
350
344
|
});
|
|
351
345
|
}
|
|
352
|
-
function writeDataTransferToClipboard(
|
|
346
|
+
function writeDataTransferToClipboard(document, clipboardData) {
|
|
353
347
|
return __async(this, null, function* () {
|
|
354
|
-
const
|
|
355
|
-
const clipboard =
|
|
348
|
+
const window = getWindow(document);
|
|
349
|
+
const clipboard = window.navigator.clipboard;
|
|
356
350
|
const items = [];
|
|
357
351
|
for (let i = 0; i < clipboardData.items.length; i++) {
|
|
358
352
|
const dtItem = clipboardData.items[i];
|
|
359
|
-
const blob = getBlobFromDataTransferItem(
|
|
360
|
-
items.push(createClipboardItem(
|
|
353
|
+
const blob = getBlobFromDataTransferItem(window, dtItem);
|
|
354
|
+
items.push(createClipboardItem(window, blob));
|
|
361
355
|
}
|
|
362
356
|
const written = clipboard && (yield clipboard.write(items).then(() => true, () => false));
|
|
363
357
|
if (!written) {
|
|
@@ -365,11 +359,11 @@ function writeDataTransferToClipboard(document2, clipboardData) {
|
|
|
365
359
|
}
|
|
366
360
|
});
|
|
367
361
|
}
|
|
368
|
-
if (typeof afterEach === "function") {
|
|
369
|
-
afterEach(() => resetClipboardStubOnView(window));
|
|
362
|
+
if (typeof globalThis.afterEach === "function") {
|
|
363
|
+
globalThis.afterEach(() => resetClipboardStubOnView(globalThis.window));
|
|
370
364
|
}
|
|
371
|
-
if (typeof afterAll === "function") {
|
|
372
|
-
afterAll(() => detachClipboardStubFromView(window));
|
|
365
|
+
if (typeof globalThis.afterAll === "function") {
|
|
366
|
+
globalThis.afterAll(() => detachClipboardStubFromView(globalThis.window));
|
|
373
367
|
}
|
|
374
368
|
|
|
375
369
|
// src/utils/edit/isContentEditable.ts
|
|
@@ -396,6 +390,7 @@ function getValue(element) {
|
|
|
396
390
|
}
|
|
397
391
|
|
|
398
392
|
// src/utils/edit/buildTimeValue.ts
|
|
393
|
+
var parseInt = globalThis.parseInt;
|
|
399
394
|
function buildTimeValue(value) {
|
|
400
395
|
const onlyDigitsValue = value.replace(/\D/g, "");
|
|
401
396
|
if (onlyDigitsValue.length < 2) {
|
|
@@ -452,11 +447,11 @@ function getSpaceUntilMaxLength(element) {
|
|
|
452
447
|
return maxLength ? maxLength - value.length : void 0;
|
|
453
448
|
}
|
|
454
449
|
function getSanitizedMaxLength(element) {
|
|
455
|
-
var
|
|
450
|
+
var _a;
|
|
456
451
|
if (!supportsMaxLength(element)) {
|
|
457
452
|
return void 0;
|
|
458
453
|
}
|
|
459
|
-
const attr = (
|
|
454
|
+
const attr = (_a = element.getAttribute("maxlength")) != null ? _a : "";
|
|
460
455
|
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
|
|
461
456
|
}
|
|
462
457
|
function supportsMaxLength(element) {
|
|
@@ -594,9 +589,9 @@ function commitInput(config, element, newOffset, inputInit) {
|
|
|
594
589
|
}
|
|
595
590
|
}
|
|
596
591
|
function isValidNumberInput(value) {
|
|
597
|
-
var
|
|
592
|
+
var _a, _b;
|
|
598
593
|
const valueParts = value.split("e", 2);
|
|
599
|
-
return !(/[^\d.\-e]/.test(value) || Number((
|
|
594
|
+
return !(/[^\d.\-e]/.test(value) || Number((_a = value.match(/-/g)) == null ? void 0 : _a.length) > 2 || Number((_b = value.match(/\./g)) == null ? void 0 : _b.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1]));
|
|
600
595
|
}
|
|
601
596
|
|
|
602
597
|
// src/utils/edit/isEditable.ts
|
|
@@ -625,8 +620,8 @@ function isEditableInput(element) {
|
|
|
625
620
|
// src/utils/edit/setFiles.ts
|
|
626
621
|
var fakeFiles = Symbol("files and value properties are mocked");
|
|
627
622
|
function setFiles(el, files) {
|
|
628
|
-
var
|
|
629
|
-
(
|
|
623
|
+
var _a;
|
|
624
|
+
(_a = el[fakeFiles]) == null ? void 0 : _a.restore();
|
|
630
625
|
const objectDescriptors = Object.getOwnPropertyDescriptors(el);
|
|
631
626
|
const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
|
|
632
627
|
function restore() {
|
|
@@ -644,11 +639,11 @@ function setFiles(el, files) {
|
|
|
644
639
|
value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
|
|
645
640
|
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
646
641
|
set(v) {
|
|
647
|
-
var
|
|
642
|
+
var _a2;
|
|
648
643
|
if (v === "") {
|
|
649
644
|
restore();
|
|
650
645
|
} else {
|
|
651
|
-
(
|
|
646
|
+
(_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
|
|
652
647
|
}
|
|
653
648
|
}
|
|
654
649
|
}),
|
|
@@ -675,7 +670,7 @@ function eventWrapper(cb) {
|
|
|
675
670
|
|
|
676
671
|
// src/utils/misc/isDisabled.ts
|
|
677
672
|
function isDisabled(element) {
|
|
678
|
-
var
|
|
673
|
+
var _a;
|
|
679
674
|
for (let el = element; el; el = el.parentElement) {
|
|
680
675
|
if (isElementType(el, [
|
|
681
676
|
"button",
|
|
@@ -689,7 +684,7 @@ function isDisabled(element) {
|
|
|
689
684
|
return true;
|
|
690
685
|
}
|
|
691
686
|
} else if (isElementType(el, "fieldset")) {
|
|
692
|
-
if (el.hasAttribute("disabled") && !((
|
|
687
|
+
if (el.hasAttribute("disabled") && !((_a = el.querySelector(":scope > legend")) == null ? void 0 : _a.contains(element))) {
|
|
693
688
|
return true;
|
|
694
689
|
}
|
|
695
690
|
} else if (el.tagName.includes("-")) {
|
|
@@ -702,13 +697,13 @@ function isDisabled(element) {
|
|
|
702
697
|
}
|
|
703
698
|
|
|
704
699
|
// src/utils/focus/getActiveElement.ts
|
|
705
|
-
function getActiveElement(
|
|
706
|
-
const activeElement =
|
|
700
|
+
function getActiveElement(document) {
|
|
701
|
+
const activeElement = document.activeElement;
|
|
707
702
|
if (activeElement == null ? void 0 : activeElement.shadowRoot) {
|
|
708
703
|
return getActiveElement(activeElement.shadowRoot);
|
|
709
704
|
} else {
|
|
710
705
|
if (isDisabled(activeElement)) {
|
|
711
|
-
return
|
|
706
|
+
return document.ownerDocument ? document.ownerDocument.body : document.body;
|
|
712
707
|
}
|
|
713
708
|
return activeElement;
|
|
714
709
|
}
|
|
@@ -822,7 +817,7 @@ function isTextNode(node) {
|
|
|
822
817
|
return node.nodeType === 3;
|
|
823
818
|
}
|
|
824
819
|
function walkNodes(node, direction, callback) {
|
|
825
|
-
var
|
|
820
|
+
var _a;
|
|
826
821
|
for (; ; ) {
|
|
827
822
|
const sibling = node[`${direction}Sibling`];
|
|
828
823
|
if (sibling) {
|
|
@@ -830,7 +825,7 @@ function walkNodes(node, direction, callback) {
|
|
|
830
825
|
if (callback(node)) {
|
|
831
826
|
return node;
|
|
832
827
|
}
|
|
833
|
-
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((
|
|
828
|
+
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a = node.ownerDocument) == null ? void 0 : _a.body))) {
|
|
834
829
|
node = node.parentNode;
|
|
835
830
|
} else {
|
|
836
831
|
break;
|
|
@@ -846,7 +841,7 @@ function getDescendant(node, direction) {
|
|
|
846
841
|
|
|
847
842
|
// src/utils/focus/selection.ts
|
|
848
843
|
function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
849
|
-
var
|
|
844
|
+
var _a;
|
|
850
845
|
if (hasOwnSelection(element)) {
|
|
851
846
|
return setSelection({
|
|
852
847
|
focusNode: element,
|
|
@@ -854,7 +849,7 @@ function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
|
854
849
|
focusOffset
|
|
855
850
|
});
|
|
856
851
|
}
|
|
857
|
-
if (isContentEditable(element) && ((
|
|
852
|
+
if (isContentEditable(element) && ((_a = element.firstChild) == null ? void 0 : _a.nodeType) === 3) {
|
|
858
853
|
return setSelection({
|
|
859
854
|
focusNode: element.firstChild,
|
|
860
855
|
anchorOffset,
|
|
@@ -888,7 +883,7 @@ function getElement2(node) {
|
|
|
888
883
|
return node.nodeType === 1 ? node : node.parentElement;
|
|
889
884
|
}
|
|
890
885
|
function updateSelectionOnFocus(element) {
|
|
891
|
-
var
|
|
886
|
+
var _a;
|
|
892
887
|
const selection = element.ownerDocument.getSelection();
|
|
893
888
|
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
894
889
|
return;
|
|
@@ -897,7 +892,7 @@ function updateSelectionOnFocus(element) {
|
|
|
897
892
|
const contenteditable = getContentEditable(selection.focusNode);
|
|
898
893
|
if (contenteditable) {
|
|
899
894
|
if (!selection.isCollapsed) {
|
|
900
|
-
const focusNode = ((
|
|
895
|
+
const focusNode = ((_a = contenteditable.firstChild) == null ? void 0 : _a.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
901
896
|
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
902
897
|
}
|
|
903
898
|
} else {
|
|
@@ -906,12 +901,12 @@ function updateSelectionOnFocus(element) {
|
|
|
906
901
|
}
|
|
907
902
|
}
|
|
908
903
|
function getInputRange(focusNode) {
|
|
909
|
-
var
|
|
904
|
+
var _a;
|
|
910
905
|
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
911
906
|
if (typeAndSelection.type === "input") {
|
|
912
907
|
return typeAndSelection.selection;
|
|
913
908
|
} else if (typeAndSelection.type === "contenteditable") {
|
|
914
|
-
return (
|
|
909
|
+
return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
|
|
915
910
|
}
|
|
916
911
|
}
|
|
917
912
|
function setSelection({
|
|
@@ -920,7 +915,7 @@ function setSelection({
|
|
|
920
915
|
anchorNode = focusNode,
|
|
921
916
|
anchorOffset = focusOffset
|
|
922
917
|
}) {
|
|
923
|
-
var
|
|
918
|
+
var _a, _b;
|
|
924
919
|
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
925
920
|
if (typeAndSelection.type === "input") {
|
|
926
921
|
return setUISelection(focusNode, {
|
|
@@ -928,7 +923,7 @@ function setSelection({
|
|
|
928
923
|
focusOffset
|
|
929
924
|
});
|
|
930
925
|
}
|
|
931
|
-
(_b = (
|
|
926
|
+
(_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
932
927
|
}
|
|
933
928
|
function moveSelection(node, direction) {
|
|
934
929
|
if (hasOwnSelection(node)) {
|
|
@@ -939,7 +934,7 @@ function moveSelection(node, direction) {
|
|
|
939
934
|
});
|
|
940
935
|
} else {
|
|
941
936
|
const selection = node.ownerDocument.getSelection();
|
|
942
|
-
if (!selection) {
|
|
937
|
+
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
943
938
|
return;
|
|
944
939
|
}
|
|
945
940
|
if (selection.isCollapsed) {
|
|
@@ -1001,9 +996,9 @@ function focus(element) {
|
|
|
1001
996
|
|
|
1002
997
|
// src/utils/misc/isVisible.ts
|
|
1003
998
|
function isVisible(element) {
|
|
1004
|
-
const
|
|
999
|
+
const window = getWindow(element);
|
|
1005
1000
|
for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
1006
|
-
const { display, visibility } =
|
|
1001
|
+
const { display, visibility } = window.getComputedStyle(el);
|
|
1007
1002
|
if (display === "none") {
|
|
1008
1003
|
return false;
|
|
1009
1004
|
}
|
|
@@ -1016,10 +1011,10 @@ function isVisible(element) {
|
|
|
1016
1011
|
|
|
1017
1012
|
// src/utils/focus/getTabDestination.ts
|
|
1018
1013
|
function getTabDestination(activeElement, shift) {
|
|
1019
|
-
const
|
|
1020
|
-
const focusableElements =
|
|
1021
|
-
const enabledElements = Array.from(focusableElements).filter((el) => el === activeElement || el.getAttribute("tabindex")
|
|
1022
|
-
if (activeElement.getAttribute("tabindex")
|
|
1014
|
+
const document = activeElement.ownerDocument;
|
|
1015
|
+
const focusableElements = document.querySelectorAll(FOCUSABLE_SELECTOR);
|
|
1016
|
+
const enabledElements = Array.from(focusableElements).filter((el) => el === activeElement || !(Number(el.getAttribute("tabindex")) < 0 || isDisabled(el)));
|
|
1017
|
+
if (Number(activeElement.getAttribute("tabindex")) >= 0) {
|
|
1023
1018
|
enabledElements.sort((a, b) => {
|
|
1024
1019
|
const i = Number(a.getAttribute("tabindex"));
|
|
1025
1020
|
const j = Number(b.getAttribute("tabindex"));
|
|
@@ -1034,7 +1029,7 @@ function getTabDestination(activeElement, shift) {
|
|
|
1034
1029
|
});
|
|
1035
1030
|
}
|
|
1036
1031
|
const checkedRadio = {};
|
|
1037
|
-
let prunedElements = [
|
|
1032
|
+
let prunedElements = [document.body];
|
|
1038
1033
|
const activeRadioGroup = isElementType(activeElement, "input", {
|
|
1039
1034
|
type: "radio"
|
|
1040
1035
|
}) ? activeElement.name : void 0;
|
|
@@ -1059,15 +1054,22 @@ function getTabDestination(activeElement, shift) {
|
|
|
1059
1054
|
}
|
|
1060
1055
|
prunedElements.push(el);
|
|
1061
1056
|
});
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1057
|
+
for (let index = prunedElements.findIndex((el) => el === activeElement); ; ) {
|
|
1058
|
+
index += shift ? -1 : 1;
|
|
1059
|
+
if (index === prunedElements.length) {
|
|
1060
|
+
index = 0;
|
|
1061
|
+
} else if (index === -1) {
|
|
1062
|
+
index = prunedElements.length - 1;
|
|
1063
|
+
}
|
|
1064
|
+
if (prunedElements[index] === activeElement || prunedElements[index] === document.body || isVisible(prunedElements[index])) {
|
|
1065
|
+
return prunedElements[index];
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1066
1068
|
}
|
|
1067
1069
|
|
|
1068
1070
|
// src/utils/focus/selectAll.ts
|
|
1069
1071
|
function selectAll(target) {
|
|
1070
|
-
var
|
|
1072
|
+
var _a;
|
|
1071
1073
|
if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
|
|
1072
1074
|
return setSelection({
|
|
1073
1075
|
focusNode: target,
|
|
@@ -1075,7 +1077,7 @@ function selectAll(target) {
|
|
|
1075
1077
|
focusOffset: getUIValue(target).length
|
|
1076
1078
|
});
|
|
1077
1079
|
}
|
|
1078
|
-
const focusNode = (
|
|
1080
|
+
const focusNode = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
|
|
1079
1081
|
setSelection({
|
|
1080
1082
|
focusNode,
|
|
1081
1083
|
anchorOffset: 0,
|
|
@@ -1083,11 +1085,11 @@ function selectAll(target) {
|
|
|
1083
1085
|
});
|
|
1084
1086
|
}
|
|
1085
1087
|
function isAllSelected(target) {
|
|
1086
|
-
var
|
|
1088
|
+
var _a;
|
|
1087
1089
|
if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
|
|
1088
1090
|
return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
|
|
1089
1091
|
}
|
|
1090
|
-
const focusNode = (
|
|
1092
|
+
const focusNode = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
|
|
1091
1093
|
const selection = target.ownerDocument.getSelection();
|
|
1092
1094
|
return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
1093
1095
|
}
|
|
@@ -1147,12 +1149,12 @@ function readPrintableChar(text, pos, context) {
|
|
|
1147
1149
|
};
|
|
1148
1150
|
}
|
|
1149
1151
|
function readTag(text, pos, startBracket, context) {
|
|
1150
|
-
var
|
|
1152
|
+
var _a, _b, _c;
|
|
1151
1153
|
const releasePreviousModifier = text[pos] === "/" ? "/" : "";
|
|
1152
1154
|
pos += releasePreviousModifier.length;
|
|
1153
1155
|
const escapedDescriptor = startBracket === "{" && text[pos] === "\\";
|
|
1154
1156
|
pos += Number(escapedDescriptor);
|
|
1155
|
-
const descriptor = escapedDescriptor ? text[pos] : (
|
|
1157
|
+
const descriptor = escapedDescriptor ? text[pos] : (_a = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a[0];
|
|
1156
1158
|
assertDescriptor(descriptor, text, pos, context);
|
|
1157
1159
|
pos += descriptor.length;
|
|
1158
1160
|
const repeatModifier = (_c = (_b = text.slice(pos).match(/^>\d+/)) == null ? void 0 : _b[0]) != null ? _c : "";
|
|
@@ -1224,13 +1226,13 @@ function isDescendantOrSelf(potentialDescendant, potentialAncestor) {
|
|
|
1224
1226
|
// src/utils/misc/level.ts
|
|
1225
1227
|
var Level = Symbol("Api level refs");
|
|
1226
1228
|
function setLevelRef(config, level) {
|
|
1227
|
-
var
|
|
1228
|
-
(
|
|
1229
|
+
var _a;
|
|
1230
|
+
(_a = config[Level]) != null ? _a : config[Level] = {};
|
|
1229
1231
|
config[Level][level] = {};
|
|
1230
1232
|
}
|
|
1231
1233
|
function getLevelRef(config, level) {
|
|
1232
|
-
var
|
|
1233
|
-
return (
|
|
1234
|
+
var _a;
|
|
1235
|
+
return (_a = config[Level]) == null ? void 0 : _a[level];
|
|
1234
1236
|
}
|
|
1235
1237
|
|
|
1236
1238
|
// src/utils/misc/wait.ts
|
|
@@ -1240,7 +1242,7 @@ function wait(config) {
|
|
|
1240
1242
|
return;
|
|
1241
1243
|
}
|
|
1242
1244
|
return Promise.all([
|
|
1243
|
-
new Promise((resolve) => setTimeout(() => resolve(), delay)),
|
|
1245
|
+
new Promise((resolve) => globalThis.setTimeout(() => resolve(), delay)),
|
|
1244
1246
|
config.advanceTimers(delay)
|
|
1245
1247
|
]);
|
|
1246
1248
|
}
|
|
@@ -1323,7 +1325,7 @@ var defaultOptionsDirect = {
|
|
|
1323
1325
|
applyAccept: true,
|
|
1324
1326
|
autoModify: true,
|
|
1325
1327
|
delay: 0,
|
|
1326
|
-
document:
|
|
1328
|
+
document: globalThis.document,
|
|
1327
1329
|
keyboardMap: defaultKeyMap,
|
|
1328
1330
|
pointerMap: defaultKeyMap2,
|
|
1329
1331
|
pointerEventsCheck: 2 /* EachApiCall */,
|
|
@@ -1339,14 +1341,19 @@ var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect)
|
|
|
1339
1341
|
|
|
1340
1342
|
// src/utils/pointer/cssPointerEvents.ts
|
|
1341
1343
|
function hasPointerEvents(element) {
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1344
|
+
var _a;
|
|
1345
|
+
return ((_a = closestPointerEventsDeclaration(element)) == null ? void 0 : _a.pointerEvents) !== "none";
|
|
1346
|
+
}
|
|
1347
|
+
function closestPointerEventsDeclaration(element) {
|
|
1348
|
+
const window = getWindow(element);
|
|
1349
|
+
for (let el = element, tree = []; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
1350
|
+
tree.push(el);
|
|
1351
|
+
const pointerEvents = window.getComputedStyle(el).pointerEvents;
|
|
1345
1352
|
if (pointerEvents && !["inherit", "unset"].includes(pointerEvents)) {
|
|
1346
|
-
return pointerEvents
|
|
1353
|
+
return { pointerEvents, tree };
|
|
1347
1354
|
}
|
|
1348
1355
|
}
|
|
1349
|
-
return
|
|
1356
|
+
return void 0;
|
|
1350
1357
|
}
|
|
1351
1358
|
var PointerEventsCheck = Symbol("Last check for pointer-events");
|
|
1352
1359
|
function assertPointerEvents(config, element) {
|
|
@@ -1355,15 +1362,59 @@ function assertPointerEvents(config, element) {
|
|
|
1355
1362
|
if (!needsCheck) {
|
|
1356
1363
|
return;
|
|
1357
1364
|
}
|
|
1358
|
-
const
|
|
1365
|
+
const declaration = closestPointerEventsDeclaration(element);
|
|
1359
1366
|
element[PointerEventsCheck] = {
|
|
1360
1367
|
[1 /* Call */]: getLevelRef(config, 1 /* Call */),
|
|
1361
1368
|
[2 /* Trigger */]: getLevelRef(config, 2 /* Trigger */),
|
|
1362
|
-
result
|
|
1369
|
+
result: (declaration == null ? void 0 : declaration.pointerEvents) !== "none"
|
|
1363
1370
|
};
|
|
1364
|
-
if (
|
|
1365
|
-
throw new Error(
|
|
1366
|
-
|
|
1371
|
+
if ((declaration == null ? void 0 : declaration.pointerEvents) === "none") {
|
|
1372
|
+
throw new Error([
|
|
1373
|
+
`Unable to perform pointer interaction as the element ${declaration.tree.length > 1 ? "inherits" : "has"} \`pointer-events: none\`:`,
|
|
1374
|
+
"",
|
|
1375
|
+
printTree(declaration.tree)
|
|
1376
|
+
].join("\n"));
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
function printTree(tree) {
|
|
1380
|
+
return tree.reverse().map((el, i) => [
|
|
1381
|
+
"".padEnd(i),
|
|
1382
|
+
el.tagName,
|
|
1383
|
+
el.id && `#${el.id}`,
|
|
1384
|
+
el.hasAttribute("data-testid") && `(testId=${el.getAttribute("data-testid")})`,
|
|
1385
|
+
getLabelDescr(el),
|
|
1386
|
+
tree.length > 1 && i === 0 && " <-- This element declared `pointer-events: none`",
|
|
1387
|
+
tree.length > 1 && i === tree.length - 1 && " <-- Asserted pointer events here"
|
|
1388
|
+
].filter(Boolean).join("")).join("\n");
|
|
1389
|
+
}
|
|
1390
|
+
function getLabelDescr(element) {
|
|
1391
|
+
var _a, _b, _c, _d;
|
|
1392
|
+
let label;
|
|
1393
|
+
if (element.hasAttribute("aria-label")) {
|
|
1394
|
+
label = element.getAttribute("aria-label");
|
|
1395
|
+
} else if (element.hasAttribute("aria-labelledby")) {
|
|
1396
|
+
label = (_b = (_a = element.ownerDocument.getElementById(element.getAttribute("aria-labelledby"))) == null ? void 0 : _a.textContent) == null ? void 0 : _b.trim();
|
|
1397
|
+
} else if (isElementType(element, [
|
|
1398
|
+
"button",
|
|
1399
|
+
"input",
|
|
1400
|
+
"meter",
|
|
1401
|
+
"output",
|
|
1402
|
+
"progress",
|
|
1403
|
+
"select",
|
|
1404
|
+
"textarea"
|
|
1405
|
+
]) && ((_c = element.labels) == null ? void 0 : _c.length)) {
|
|
1406
|
+
label = Array.from(element.labels).map((el) => {
|
|
1407
|
+
var _a2;
|
|
1408
|
+
return (_a2 = el.textContent) == null ? void 0 : _a2.trim();
|
|
1409
|
+
}).join("|");
|
|
1410
|
+
} else if (isElementType(element, "button")) {
|
|
1411
|
+
label = (_d = element.textContent) == null ? void 0 : _d.trim();
|
|
1412
|
+
}
|
|
1413
|
+
label = label == null ? void 0 : label.replace(/\n/g, " ");
|
|
1414
|
+
if (Number(label == null ? void 0 : label.length) > 30) {
|
|
1415
|
+
label = `${label == null ? void 0 : label.substring(0, 29)}\u2026`;
|
|
1416
|
+
}
|
|
1417
|
+
return label ? `(label=${label})` : "";
|
|
1367
1418
|
}
|
|
1368
1419
|
function hasBitFlag(conf, flag) {
|
|
1369
1420
|
return (conf & flag) > 0;
|
|
@@ -1453,9 +1504,9 @@ function assignPositionInit(obj, {
|
|
|
1453
1504
|
screenX,
|
|
1454
1505
|
screenY
|
|
1455
1506
|
}) {
|
|
1456
|
-
var
|
|
1507
|
+
var _a, _b, _c, _d;
|
|
1457
1508
|
assignProps(obj, {
|
|
1458
|
-
x: (
|
|
1509
|
+
x: (_a = x != null ? x : clientX) != null ? _a : 0,
|
|
1459
1510
|
y: (_b = y != null ? y : clientY) != null ? _b : 0,
|
|
1460
1511
|
clientX: (_c = x != null ? x : clientX) != null ? _c : 0,
|
|
1461
1512
|
clientY: (_d = y != null ? y : clientY) != null ? _d : 0,
|
|
@@ -1509,8 +1560,8 @@ behavior.cut = (event, target, config) => {
|
|
|
1509
1560
|
|
|
1510
1561
|
// src/event/behavior/keydown.ts
|
|
1511
1562
|
behavior.keydown = (event, target, config) => {
|
|
1512
|
-
var
|
|
1513
|
-
return (_b = (
|
|
1563
|
+
var _a, _b;
|
|
1564
|
+
return (_b = (_a = keydownBehavior[event.key]) == null ? void 0 : _a.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(event, target, config);
|
|
1514
1565
|
};
|
|
1515
1566
|
var keydownBehavior = {
|
|
1516
1567
|
ArrowLeft: (event, target) => () => moveSelection(target, -1),
|
|
@@ -1532,8 +1583,8 @@ var keydownBehavior = {
|
|
|
1532
1583
|
End: (event, target) => {
|
|
1533
1584
|
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1534
1585
|
return () => {
|
|
1535
|
-
var
|
|
1536
|
-
const newPos = (_b = (
|
|
1586
|
+
var _a, _b;
|
|
1587
|
+
const newPos = (_b = (_a = getValue(target)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
1537
1588
|
setSelectionRange(target, newPos, newPos);
|
|
1538
1589
|
};
|
|
1539
1590
|
}
|
|
@@ -1625,8 +1676,8 @@ var SubmitSingleInputOnEnter = [
|
|
|
1625
1676
|
|
|
1626
1677
|
// src/event/behavior/keyup.ts
|
|
1627
1678
|
behavior.keyup = (event, target, config) => {
|
|
1628
|
-
var
|
|
1629
|
-
return (
|
|
1679
|
+
var _a;
|
|
1680
|
+
return (_a = keyupBehavior[event.key]) == null ? void 0 : _a.call(keyupBehavior, event, target, config);
|
|
1630
1681
|
};
|
|
1631
1682
|
var keyupBehavior = {
|
|
1632
1683
|
" ": (event, target, config) => {
|
|
@@ -1640,8 +1691,8 @@ var keyupBehavior = {
|
|
|
1640
1691
|
behavior.paste = (event, target, config) => {
|
|
1641
1692
|
if (isEditable(target)) {
|
|
1642
1693
|
return () => {
|
|
1643
|
-
var
|
|
1644
|
-
const insertData = (
|
|
1694
|
+
var _a;
|
|
1695
|
+
const insertData = (_a = event.clipboardData) == null ? void 0 : _a.getData("text");
|
|
1645
1696
|
if (insertData) {
|
|
1646
1697
|
input(config, target, insertData, "insertFromPaste");
|
|
1647
1698
|
}
|
|
@@ -1657,10 +1708,10 @@ function wrapEvent(cb, _element) {
|
|
|
1657
1708
|
|
|
1658
1709
|
// src/event/dispatchEvent.ts
|
|
1659
1710
|
function dispatchEvent(config, target, event, preventDefault = false) {
|
|
1660
|
-
var
|
|
1711
|
+
var _a, _b;
|
|
1661
1712
|
const type3 = event.type;
|
|
1662
1713
|
const behaviorImplementation = preventDefault ? () => {
|
|
1663
|
-
} : (_b = (
|
|
1714
|
+
} : (_b = (_a = behavior)[type3]) == null ? void 0 : _b.call(_a, event, target, config);
|
|
1664
1715
|
if (behaviorImplementation) {
|
|
1665
1716
|
event.preventDefault();
|
|
1666
1717
|
let defaultPrevented = false;
|
|
@@ -1776,9 +1827,9 @@ function setUISelection(element, {
|
|
|
1776
1827
|
}
|
|
1777
1828
|
}
|
|
1778
1829
|
function getUISelection(element) {
|
|
1779
|
-
var
|
|
1830
|
+
var _a, _b, _c;
|
|
1780
1831
|
const sel = (_c = element[UISelection]) != null ? _c : {
|
|
1781
|
-
anchorOffset: (
|
|
1832
|
+
anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
|
|
1782
1833
|
focusOffset: (_b = element.selectionEnd) != null ? _b : 0
|
|
1783
1834
|
};
|
|
1784
1835
|
return __spreadProps(__spreadValues({}, sel), {
|
|
@@ -1840,8 +1891,8 @@ function startTrackValue(element) {
|
|
|
1840
1891
|
});
|
|
1841
1892
|
}
|
|
1842
1893
|
function trackOrSetValue(element, v) {
|
|
1843
|
-
var
|
|
1844
|
-
(_b = (
|
|
1894
|
+
var _a, _b, _c;
|
|
1895
|
+
(_b = (_a = element[TrackChanges]) == null ? void 0 : _a.tracked) == null ? void 0 : _b.push(v);
|
|
1845
1896
|
if (!((_c = element[TrackChanges]) == null ? void 0 : _c.tracked)) {
|
|
1846
1897
|
setCleanValue(element, v);
|
|
1847
1898
|
}
|
|
@@ -1851,10 +1902,10 @@ function setCleanValue(element, v) {
|
|
|
1851
1902
|
setUISelection(element, { focusOffset: v.length });
|
|
1852
1903
|
}
|
|
1853
1904
|
function endTrackValue(element) {
|
|
1854
|
-
var
|
|
1905
|
+
var _a, _b;
|
|
1855
1906
|
const changes = element[TrackChanges];
|
|
1856
1907
|
element[TrackChanges] = void 0;
|
|
1857
|
-
const isJustReactStateUpdate = ((
|
|
1908
|
+
const isJustReactStateUpdate = ((_a = changes == null ? void 0 : changes.tracked) == null ? void 0 : _a.length) === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === changes.nextValue;
|
|
1858
1909
|
if (((_b = changes == null ? void 0 : changes.tracked) == null ? void 0 : _b.length) && !isJustReactStateUpdate) {
|
|
1859
1910
|
setCleanValue(element, changes.tracked[changes.tracked.length - 1]);
|
|
1860
1911
|
}
|
|
@@ -1863,21 +1914,21 @@ function endTrackValue(element) {
|
|
|
1863
1914
|
|
|
1864
1915
|
// src/document/index.ts
|
|
1865
1916
|
var isPrepared = Symbol("Node prepared with document state workarounds");
|
|
1866
|
-
function prepareDocument(
|
|
1867
|
-
if (
|
|
1917
|
+
function prepareDocument(document) {
|
|
1918
|
+
if (document[isPrepared]) {
|
|
1868
1919
|
return;
|
|
1869
1920
|
}
|
|
1870
|
-
|
|
1921
|
+
document.addEventListener("focus", (e) => {
|
|
1871
1922
|
const el = e.target;
|
|
1872
1923
|
prepareElement(el);
|
|
1873
1924
|
}, {
|
|
1874
1925
|
capture: true,
|
|
1875
1926
|
passive: true
|
|
1876
1927
|
});
|
|
1877
|
-
if (
|
|
1878
|
-
prepareElement(
|
|
1928
|
+
if (document.activeElement) {
|
|
1929
|
+
prepareElement(document.activeElement);
|
|
1879
1930
|
}
|
|
1880
|
-
|
|
1931
|
+
document.addEventListener("blur", (e) => {
|
|
1881
1932
|
const el = e.target;
|
|
1882
1933
|
const initialValue = getInitialValue(el);
|
|
1883
1934
|
if (initialValue !== void 0) {
|
|
@@ -1890,7 +1941,7 @@ function prepareDocument(document2) {
|
|
|
1890
1941
|
capture: true,
|
|
1891
1942
|
passive: true
|
|
1892
1943
|
});
|
|
1893
|
-
|
|
1944
|
+
document[isPrepared] = isPrepared;
|
|
1894
1945
|
}
|
|
1895
1946
|
function prepareElement(el) {
|
|
1896
1947
|
if (el[isPrepared]) {
|
|
@@ -1927,11 +1978,11 @@ function isModifierLock(key) {
|
|
|
1927
1978
|
return modifierLocks.includes(key);
|
|
1928
1979
|
}
|
|
1929
1980
|
function preKeydownBehavior(config, { key }, element) {
|
|
1930
|
-
var
|
|
1981
|
+
var _a;
|
|
1931
1982
|
if (isModifierKey(key)) {
|
|
1932
1983
|
config.keyboardState.modifiers[key] = true;
|
|
1933
1984
|
if (key === "AltGraph") {
|
|
1934
|
-
const ctrlKeyDef = (
|
|
1985
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1935
1986
|
dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
|
|
1936
1987
|
}
|
|
1937
1988
|
} else if (isModifierLock(key)) {
|
|
@@ -1951,9 +2002,9 @@ function preKeyupBehavior(config, { key }) {
|
|
|
1951
2002
|
}
|
|
1952
2003
|
}
|
|
1953
2004
|
function postKeyupBehavior(config, { key }, element) {
|
|
1954
|
-
var
|
|
2005
|
+
var _a;
|
|
1955
2006
|
if (key === "AltGraph") {
|
|
1956
|
-
const ctrlKeyDef = (
|
|
2007
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1957
2008
|
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1958
2009
|
}
|
|
1959
2010
|
}
|
|
@@ -1971,8 +2022,8 @@ function keyboardAction(config, actions) {
|
|
|
1971
2022
|
}
|
|
1972
2023
|
function keyboardKeyAction(_0, _1) {
|
|
1973
2024
|
return __async(this, arguments, function* (config, { keyDef, releasePrevious, releaseSelf, repeat }) {
|
|
1974
|
-
const { document
|
|
1975
|
-
const getCurrentElement = () => getActive(
|
|
2025
|
+
const { document, keyboardState } = config;
|
|
2026
|
+
const getCurrentElement = () => getActive(document);
|
|
1976
2027
|
const pressed = keyboardState.pressed.find((p) => p.keyDef === keyDef);
|
|
1977
2028
|
if (pressed) {
|
|
1978
2029
|
yield keyup(keyDef, getCurrentElement, config, pressed.unpreventedDefault);
|
|
@@ -1994,9 +2045,9 @@ function keyboardKeyAction(_0, _1) {
|
|
|
1994
2045
|
}
|
|
1995
2046
|
});
|
|
1996
2047
|
}
|
|
1997
|
-
function getActive(
|
|
1998
|
-
var
|
|
1999
|
-
return (
|
|
2048
|
+
function getActive(document) {
|
|
2049
|
+
var _a;
|
|
2050
|
+
return (_a = getActiveElement(document)) != null ? _a : document.body;
|
|
2000
2051
|
}
|
|
2001
2052
|
function releaseAllKeys(config) {
|
|
2002
2053
|
return __async(this, null, function* () {
|
|
@@ -2038,13 +2089,13 @@ function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
|
2038
2089
|
});
|
|
2039
2090
|
}
|
|
2040
2091
|
function hasKeyPress(keyDef, config) {
|
|
2041
|
-
var
|
|
2042
|
-
return (((
|
|
2092
|
+
var _a;
|
|
2093
|
+
return (((_a = keyDef.key) == null ? void 0 : _a.length) === 1 || keyDef.key === "Enter") && !config.keyboardState.modifiers.Control && !config.keyboardState.modifiers.Alt;
|
|
2043
2094
|
}
|
|
2044
2095
|
|
|
2045
2096
|
// src/keyboard/parseKeyDef.ts
|
|
2046
2097
|
function parseKeyDef(keyboardMap, text) {
|
|
2047
|
-
var
|
|
2098
|
+
var _a;
|
|
2048
2099
|
const defs = [];
|
|
2049
2100
|
do {
|
|
2050
2101
|
const {
|
|
@@ -2055,15 +2106,15 @@ function parseKeyDef(keyboardMap, text) {
|
|
|
2055
2106
|
releaseSelf = true,
|
|
2056
2107
|
repeat
|
|
2057
2108
|
} = readNextDescriptor(text, "keyboard");
|
|
2058
|
-
const keyDef = (
|
|
2059
|
-
var
|
|
2109
|
+
const keyDef = (_a = keyboardMap.find((def) => {
|
|
2110
|
+
var _a2, _b;
|
|
2060
2111
|
if (type3 === "[") {
|
|
2061
|
-
return ((
|
|
2112
|
+
return ((_a2 = def.code) == null ? void 0 : _a2.toLowerCase()) === descriptor.toLowerCase();
|
|
2062
2113
|
} else if (type3 === "{") {
|
|
2063
2114
|
return ((_b = def.key) == null ? void 0 : _b.toLowerCase()) === descriptor.toLowerCase();
|
|
2064
2115
|
}
|
|
2065
2116
|
return def.key === descriptor;
|
|
2066
|
-
})) != null ?
|
|
2117
|
+
})) != null ? _a : {
|
|
2067
2118
|
key: "Unknown",
|
|
2068
2119
|
code: "Unknown",
|
|
2069
2120
|
[type3 === "[" ? "code" : "key"]: descriptor
|
|
@@ -2142,8 +2193,8 @@ function firePointerEvent(config, target, type3, {
|
|
|
2142
2193
|
}
|
|
2143
2194
|
init.button = getMouseButton(button != null ? button : 0);
|
|
2144
2195
|
init.buttons = getMouseButtons(...config.pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
|
|
2145
|
-
var
|
|
2146
|
-
return (
|
|
2196
|
+
var _a;
|
|
2197
|
+
return (_a = p.keyDef.button) != null ? _a : 0;
|
|
2147
2198
|
}));
|
|
2148
2199
|
if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
|
|
2149
2200
|
init.detail = clickCount;
|
|
@@ -2305,7 +2356,7 @@ function getNextPointerId(state) {
|
|
|
2305
2356
|
return state.pointerId;
|
|
2306
2357
|
}
|
|
2307
2358
|
function down(config, pointerName, { keyDef, node, offset, target, coords }, targetIsDisabled) {
|
|
2308
|
-
var
|
|
2359
|
+
var _a, _b, _c;
|
|
2309
2360
|
setLevelRef(config, 2 /* Trigger */);
|
|
2310
2361
|
assertPointerEvents(config, target);
|
|
2311
2362
|
const { pointerState } = config;
|
|
@@ -2328,7 +2379,7 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
|
|
|
2328
2379
|
}
|
|
2329
2380
|
}
|
|
2330
2381
|
}
|
|
2331
|
-
if (((
|
|
2382
|
+
if (((_a = pointerState.activeClickCount) == null ? void 0 : _a[0]) !== name) {
|
|
2332
2383
|
delete pointerState.activeClickCount;
|
|
2333
2384
|
}
|
|
2334
2385
|
const clickCount = Number((_c = (_b = pointerState.activeClickCount) == null ? void 0 : _b[1]) != null ? _c : 0) + 1;
|
|
@@ -2512,11 +2563,11 @@ function getTextRange(text, pos, clickCount) {
|
|
|
2512
2563
|
// src/pointer/pointerAction.ts
|
|
2513
2564
|
function pointerAction(config, actions) {
|
|
2514
2565
|
return __async(this, null, function* () {
|
|
2515
|
-
var
|
|
2566
|
+
var _a, _b;
|
|
2516
2567
|
for (let i = 0; i < actions.length; i++) {
|
|
2517
2568
|
const action = actions[i];
|
|
2518
2569
|
const pointerName = "pointerName" in action && action.pointerName ? action.pointerName : "keyDef" in action ? action.keyDef.pointerType === "touch" ? action.keyDef.name : action.keyDef.pointerType : "mouse";
|
|
2519
|
-
const target = (
|
|
2570
|
+
const target = (_a = action.target) != null ? _a : getPrevTarget(pointerName, config.pointerState);
|
|
2520
2571
|
const coords = (_b = action.coords) != null ? _b : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : void 0;
|
|
2521
2572
|
yield "keyDef" in action ? pointerPress(config, __spreadProps(__spreadValues({}, action), { target, coords })) : pointerMove(config, __spreadProps(__spreadValues({}, action), { target, coords }));
|
|
2522
2573
|
if (i < actions.length - 1) {
|
|
@@ -2550,14 +2601,14 @@ function pointer(input2) {
|
|
|
2550
2601
|
return pointerAction(this[Config], actions).then(() => void 0);
|
|
2551
2602
|
});
|
|
2552
2603
|
}
|
|
2553
|
-
function createPointerState(
|
|
2604
|
+
function createPointerState(document) {
|
|
2554
2605
|
return {
|
|
2555
2606
|
pointerId: 1,
|
|
2556
2607
|
position: {
|
|
2557
2608
|
mouse: {
|
|
2558
2609
|
pointerType: "mouse",
|
|
2559
2610
|
pointerId: 1,
|
|
2560
|
-
target:
|
|
2611
|
+
target: document.body,
|
|
2561
2612
|
coords: {
|
|
2562
2613
|
clientX: 0,
|
|
2563
2614
|
clientY: 0,
|
|
@@ -2644,9 +2695,9 @@ function tab() {
|
|
|
2644
2695
|
// src/clipboard/copy.ts
|
|
2645
2696
|
function copy() {
|
|
2646
2697
|
return __async(this, null, function* () {
|
|
2647
|
-
var
|
|
2698
|
+
var _a;
|
|
2648
2699
|
const doc = this[Config].document;
|
|
2649
|
-
const target = (
|
|
2700
|
+
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2650
2701
|
const clipboardData = copySelection(target);
|
|
2651
2702
|
if (clipboardData.items.length === 0) {
|
|
2652
2703
|
return;
|
|
@@ -2663,9 +2714,9 @@ function copy() {
|
|
|
2663
2714
|
// src/clipboard/cut.ts
|
|
2664
2715
|
function cut() {
|
|
2665
2716
|
return __async(this, null, function* () {
|
|
2666
|
-
var
|
|
2717
|
+
var _a;
|
|
2667
2718
|
const doc = this[Config].document;
|
|
2668
|
-
const target = (
|
|
2719
|
+
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2669
2720
|
const clipboardData = copySelection(target);
|
|
2670
2721
|
if (clipboardData.items.length === 0) {
|
|
2671
2722
|
return;
|
|
@@ -2682,9 +2733,9 @@ function cut() {
|
|
|
2682
2733
|
// src/clipboard/paste.ts
|
|
2683
2734
|
function paste(clipboardData) {
|
|
2684
2735
|
return __async(this, null, function* () {
|
|
2685
|
-
var
|
|
2736
|
+
var _a, _b;
|
|
2686
2737
|
const doc = this[Config].document;
|
|
2687
|
-
const target = (
|
|
2738
|
+
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2688
2739
|
const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(doc, clipboardData) : clipboardData) != null ? _b : yield readDataTransferFromClipboard(doc).catch(() => {
|
|
2689
2740
|
throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
|
|
2690
2741
|
});
|
|
@@ -2782,6 +2833,7 @@ function selectOptionsBase(newValue, select, values) {
|
|
|
2782
2833
|
if (withPointerEvents) {
|
|
2783
2834
|
this.dispatchUIEvent(option, "click");
|
|
2784
2835
|
}
|
|
2836
|
+
yield wait(this[Config]);
|
|
2785
2837
|
}
|
|
2786
2838
|
} else if (selectedOptions.length === 1) {
|
|
2787
2839
|
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(select);
|
|
@@ -2800,6 +2852,7 @@ function selectOptionsBase(newValue, select, values) {
|
|
|
2800
2852
|
this.dispatchUIEvent(select, "mouseup");
|
|
2801
2853
|
this.dispatchUIEvent(select, "click");
|
|
2802
2854
|
}
|
|
2855
|
+
yield wait(this[Config]);
|
|
2803
2856
|
} else {
|
|
2804
2857
|
throw getConfig3().getElementError(`Cannot select multiple options on a non-multiple select`, select);
|
|
2805
2858
|
}
|
|
@@ -2848,10 +2901,10 @@ function upload(element, fileOrFiles) {
|
|
|
2848
2901
|
return;
|
|
2849
2902
|
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input2.accept)).slice(0, input2.multiple ? void 0 : 1);
|
|
2850
2903
|
const fileDialog = () => {
|
|
2851
|
-
var
|
|
2852
|
-
if (files.length === ((
|
|
2853
|
-
var
|
|
2854
|
-
return f === ((
|
|
2904
|
+
var _a;
|
|
2905
|
+
if (files.length === ((_a = input2.files) == null ? void 0 : _a.length) && files.every((f, i) => {
|
|
2906
|
+
var _a2;
|
|
2907
|
+
return f === ((_a2 = input2.files) == null ? void 0 : _a2.item(i));
|
|
2855
2908
|
})) {
|
|
2856
2909
|
return;
|
|
2857
2910
|
}
|
|
@@ -2887,22 +2940,22 @@ function wrapAsync(implementation) {
|
|
|
2887
2940
|
|
|
2888
2941
|
// src/setup/setup.ts
|
|
2889
2942
|
function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
|
|
2890
|
-
const
|
|
2943
|
+
const document = getDocument(options, node, defaults);
|
|
2891
2944
|
const {
|
|
2892
2945
|
keyboardState = createKeyboardState(),
|
|
2893
|
-
pointerState = createPointerState(
|
|
2946
|
+
pointerState = createPointerState(document)
|
|
2894
2947
|
} = options;
|
|
2895
2948
|
return __spreadProps(__spreadValues(__spreadValues({}, defaults), options), {
|
|
2896
|
-
document
|
|
2949
|
+
document,
|
|
2897
2950
|
keyboardState,
|
|
2898
2951
|
pointerState
|
|
2899
2952
|
});
|
|
2900
2953
|
}
|
|
2901
2954
|
function setupMain(options = {}) {
|
|
2902
|
-
var
|
|
2955
|
+
var _a;
|
|
2903
2956
|
const config = createConfig(options);
|
|
2904
2957
|
prepareDocument(config.document);
|
|
2905
|
-
const view = (
|
|
2958
|
+
const view = (_a = config.document.defaultView) != null ? _a : globalThis.window;
|
|
2906
2959
|
attachClipboardStubToView(view);
|
|
2907
2960
|
return doSetup(config);
|
|
2908
2961
|
}
|
|
@@ -2920,7 +2973,10 @@ function setupSub(options) {
|
|
|
2920
2973
|
function wrapAndBindImpl(instance, impl) {
|
|
2921
2974
|
function method(...args) {
|
|
2922
2975
|
setLevelRef(instance[Config], 1 /* Call */);
|
|
2923
|
-
return wrapAsync(() => impl.apply(instance, args))
|
|
2976
|
+
return wrapAsync(() => impl.apply(instance, args).then((ret) => __async(this, null, function* () {
|
|
2977
|
+
yield wait(instance[Config]);
|
|
2978
|
+
return ret;
|
|
2979
|
+
})));
|
|
2924
2980
|
}
|
|
2925
2981
|
Object.defineProperty(method, "name", { get: () => impl.name });
|
|
2926
2982
|
return method;
|
|
@@ -2937,9 +2993,9 @@ function doSetup(config) {
|
|
|
2937
2993
|
setup: setupSub.bind(instance)
|
|
2938
2994
|
});
|
|
2939
2995
|
}
|
|
2940
|
-
function getDocument(options, node) {
|
|
2941
|
-
var
|
|
2942
|
-
return (_b = (
|
|
2996
|
+
function getDocument(options, node, defaults) {
|
|
2997
|
+
var _a, _b;
|
|
2998
|
+
return (_b = (_a = options.document) != null ? _a : node && getDocumentFromNode(node)) != null ? _b : defaults.document;
|
|
2943
2999
|
}
|
|
2944
3000
|
|
|
2945
3001
|
// src/setup/directApi.ts
|