@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.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __defProps = Object.defineProperties;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -156,8 +157,8 @@ var DataTransferStub = class {
|
|
|
156
157
|
this.files = createFileList([]);
|
|
157
158
|
}
|
|
158
159
|
getData(format) {
|
|
159
|
-
var
|
|
160
|
-
const match = (
|
|
160
|
+
var _a;
|
|
161
|
+
const match = (_a = this.items.find(getTypeMatcher(format, true))) != null ? _a : this.items.find(getTypeMatcher(format, false));
|
|
161
162
|
let text = "";
|
|
162
163
|
match == null ? void 0 : match.getAsString((t) => {
|
|
163
164
|
text = t;
|
|
@@ -195,12 +196,12 @@ var DataTransferStub = class {
|
|
|
195
196
|
setDragImage() {
|
|
196
197
|
}
|
|
197
198
|
};
|
|
198
|
-
function createDataTransfer(
|
|
199
|
-
const dt = typeof
|
|
199
|
+
function createDataTransfer(window, files = []) {
|
|
200
|
+
const dt = typeof window.DataTransfer === "undefined" ? new DataTransferStub() : new window.DataTransfer();
|
|
200
201
|
Object.defineProperty(dt, "files", { get: () => createFileList(files) });
|
|
201
202
|
return dt;
|
|
202
203
|
}
|
|
203
|
-
function getBlobFromDataTransferItem(
|
|
204
|
+
function getBlobFromDataTransferItem(window, item) {
|
|
204
205
|
if (item.kind === "file") {
|
|
205
206
|
return item.getAsFile();
|
|
206
207
|
}
|
|
@@ -208,7 +209,7 @@ function getBlobFromDataTransferItem(window2, item) {
|
|
|
208
209
|
item.getAsString((s) => {
|
|
209
210
|
data = s;
|
|
210
211
|
});
|
|
211
|
-
return new
|
|
212
|
+
return new window.Blob([data], { type: item.type });
|
|
212
213
|
}
|
|
213
214
|
|
|
214
215
|
// src/utils/misc/getWindow.ts
|
|
@@ -218,142 +219,135 @@ function getWindow(node) {
|
|
|
218
219
|
}
|
|
219
220
|
|
|
220
221
|
// src/utils/dataTransfer/Clipboard.ts
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
get types() {
|
|
229
|
-
return Array.from(Object.keys(this.data));
|
|
222
|
+
function createClipboardItem(window, ...blobs) {
|
|
223
|
+
const dataMap = Object.fromEntries(blobs.map((b) => [
|
|
224
|
+
typeof b === "string" ? "text/plain" : b.type,
|
|
225
|
+
Promise.resolve(b)
|
|
226
|
+
]));
|
|
227
|
+
if (typeof window.ClipboardItem !== "undefined") {
|
|
228
|
+
return new window.ClipboardItem(dataMap);
|
|
230
229
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
throw new Error(`${type3} is not one of the available MIME types on this item.`);
|
|
230
|
+
return new class ClipboardItem {
|
|
231
|
+
constructor(d) {
|
|
232
|
+
this.data = d;
|
|
235
233
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
|
|
234
|
+
get types() {
|
|
235
|
+
return Array.from(Object.keys(this.data));
|
|
236
|
+
}
|
|
237
|
+
async getType(type3) {
|
|
238
|
+
const value = await this.data[type3];
|
|
239
|
+
if (!value) {
|
|
240
|
+
throw new Error(`${type3} is not one of the available MIME types on this item.`);
|
|
241
|
+
}
|
|
242
|
+
return value instanceof window.Blob ? value : new window.Blob([value], { type: type3 });
|
|
243
|
+
}
|
|
244
|
+
}(dataMap);
|
|
245
|
+
}
|
|
240
246
|
var ClipboardStubControl = Symbol("Manage ClipboardSub");
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
247
|
+
function createClipboardStub(window, control) {
|
|
248
|
+
return Object.assign(new class Clipboard extends window.EventTarget {
|
|
249
|
+
constructor() {
|
|
250
|
+
super(...arguments);
|
|
251
|
+
this.items = [];
|
|
252
|
+
}
|
|
253
|
+
async read() {
|
|
254
|
+
return Array.from(this.items);
|
|
255
|
+
}
|
|
256
|
+
async readText() {
|
|
257
|
+
let text = "";
|
|
258
|
+
for (const item of this.items) {
|
|
259
|
+
const type3 = item.types.includes("text/plain") ? "text/plain" : item.types.find((t) => t.startsWith("text/"));
|
|
260
|
+
if (type3) {
|
|
261
|
+
text += await item.getType(type3).then((b) => readBlobText(b, window.FileReader));
|
|
262
|
+
}
|
|
257
263
|
}
|
|
264
|
+
return text;
|
|
258
265
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
function
|
|
270
|
-
|
|
271
|
-
typeof b === "string" ? "text/plain" : b.type,
|
|
272
|
-
Promise.resolve(b)
|
|
273
|
-
]));
|
|
274
|
-
if (typeof window2.ClipboardItem === "undefined") {
|
|
275
|
-
const item = new ClipboardItemStub(data);
|
|
276
|
-
item[Window] = window2;
|
|
277
|
-
return item;
|
|
278
|
-
} else {
|
|
279
|
-
return new window2.ClipboardItem(data);
|
|
280
|
-
}
|
|
266
|
+
async write(data) {
|
|
267
|
+
this.items = data;
|
|
268
|
+
}
|
|
269
|
+
async writeText(text) {
|
|
270
|
+
this.items = [createClipboardItem(window, text)];
|
|
271
|
+
}
|
|
272
|
+
}(), {
|
|
273
|
+
[ClipboardStubControl]: control
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
function isClipboardStub(clipboard) {
|
|
277
|
+
return !!(clipboard == null ? void 0 : clipboard[ClipboardStubControl]);
|
|
281
278
|
}
|
|
282
|
-
function attachClipboardStubToView(
|
|
283
|
-
if (
|
|
284
|
-
return
|
|
279
|
+
function attachClipboardStubToView(window) {
|
|
280
|
+
if (isClipboardStub(window.navigator.clipboard)) {
|
|
281
|
+
return window.navigator.clipboard[ClipboardStubControl];
|
|
285
282
|
}
|
|
286
|
-
const realClipboard = Object.getOwnPropertyDescriptor(
|
|
287
|
-
let stub
|
|
288
|
-
stub[Window] = window2;
|
|
283
|
+
const realClipboard = Object.getOwnPropertyDescriptor(window.navigator, "clipboard");
|
|
284
|
+
let stub;
|
|
289
285
|
const control = {
|
|
290
286
|
resetClipboardStub: () => {
|
|
291
|
-
stub =
|
|
292
|
-
stub[Window] = window2;
|
|
293
|
-
stub[ClipboardStubControl] = control;
|
|
287
|
+
stub = createClipboardStub(window, control);
|
|
294
288
|
},
|
|
295
289
|
detachClipboardStub: () => {
|
|
296
290
|
if (realClipboard) {
|
|
297
|
-
Object.defineProperty(
|
|
291
|
+
Object.defineProperty(window.navigator, "clipboard", realClipboard);
|
|
298
292
|
} else {
|
|
299
|
-
Object.defineProperty(
|
|
293
|
+
Object.defineProperty(window.navigator, "clipboard", {
|
|
300
294
|
value: void 0,
|
|
301
295
|
configurable: true
|
|
302
296
|
});
|
|
303
297
|
}
|
|
304
298
|
}
|
|
305
299
|
};
|
|
306
|
-
stub
|
|
307
|
-
Object.defineProperty(
|
|
300
|
+
stub = createClipboardStub(window, control);
|
|
301
|
+
Object.defineProperty(window.navigator, "clipboard", {
|
|
308
302
|
get: () => stub,
|
|
309
303
|
configurable: true
|
|
310
304
|
});
|
|
311
305
|
return stub[ClipboardStubControl];
|
|
312
306
|
}
|
|
313
|
-
function resetClipboardStubOnView(
|
|
314
|
-
if (
|
|
315
|
-
|
|
307
|
+
function resetClipboardStubOnView(window) {
|
|
308
|
+
if (isClipboardStub(window.navigator.clipboard)) {
|
|
309
|
+
window.navigator.clipboard[ClipboardStubControl].resetClipboardStub();
|
|
316
310
|
}
|
|
317
311
|
}
|
|
318
|
-
function detachClipboardStubFromView(
|
|
319
|
-
if (
|
|
320
|
-
|
|
312
|
+
function detachClipboardStubFromView(window) {
|
|
313
|
+
if (isClipboardStub(window.navigator.clipboard)) {
|
|
314
|
+
window.navigator.clipboard[ClipboardStubControl].detachClipboardStub();
|
|
321
315
|
}
|
|
322
316
|
}
|
|
323
|
-
async function readDataTransferFromClipboard(
|
|
324
|
-
const
|
|
325
|
-
const clipboard =
|
|
317
|
+
async function readDataTransferFromClipboard(document) {
|
|
318
|
+
const window = document.defaultView;
|
|
319
|
+
const clipboard = window == null ? void 0 : window.navigator.clipboard;
|
|
326
320
|
const items = clipboard && await clipboard.read();
|
|
327
321
|
if (!items) {
|
|
328
322
|
throw new Error("The Clipboard API is unavailable.");
|
|
329
323
|
}
|
|
330
|
-
const dt = createDataTransfer(
|
|
324
|
+
const dt = createDataTransfer(window);
|
|
331
325
|
for (const item of items) {
|
|
332
326
|
for (const type3 of item.types) {
|
|
333
|
-
dt.setData(type3, await item.getType(type3).then((b) => readBlobText(b,
|
|
327
|
+
dt.setData(type3, await item.getType(type3).then((b) => readBlobText(b, window.FileReader)));
|
|
334
328
|
}
|
|
335
329
|
}
|
|
336
330
|
return dt;
|
|
337
331
|
}
|
|
338
|
-
async function writeDataTransferToClipboard(
|
|
339
|
-
const
|
|
340
|
-
const clipboard =
|
|
332
|
+
async function writeDataTransferToClipboard(document, clipboardData) {
|
|
333
|
+
const window = getWindow(document);
|
|
334
|
+
const clipboard = window.navigator.clipboard;
|
|
341
335
|
const items = [];
|
|
342
336
|
for (let i = 0; i < clipboardData.items.length; i++) {
|
|
343
337
|
const dtItem = clipboardData.items[i];
|
|
344
|
-
const blob = getBlobFromDataTransferItem(
|
|
345
|
-
items.push(createClipboardItem(
|
|
338
|
+
const blob = getBlobFromDataTransferItem(window, dtItem);
|
|
339
|
+
items.push(createClipboardItem(window, blob));
|
|
346
340
|
}
|
|
347
341
|
const written = clipboard && await clipboard.write(items).then(() => true, () => false);
|
|
348
342
|
if (!written) {
|
|
349
343
|
throw new Error("The Clipboard API is unavailable.");
|
|
350
344
|
}
|
|
351
345
|
}
|
|
352
|
-
if (typeof afterEach === "function") {
|
|
353
|
-
afterEach(() => resetClipboardStubOnView(window));
|
|
346
|
+
if (typeof globalThis.afterEach === "function") {
|
|
347
|
+
globalThis.afterEach(() => resetClipboardStubOnView(globalThis.window));
|
|
354
348
|
}
|
|
355
|
-
if (typeof afterAll === "function") {
|
|
356
|
-
afterAll(() => detachClipboardStubFromView(window));
|
|
349
|
+
if (typeof globalThis.afterAll === "function") {
|
|
350
|
+
globalThis.afterAll(() => detachClipboardStubFromView(globalThis.window));
|
|
357
351
|
}
|
|
358
352
|
|
|
359
353
|
// src/utils/edit/isContentEditable.ts
|
|
@@ -380,6 +374,7 @@ function getValue(element) {
|
|
|
380
374
|
}
|
|
381
375
|
|
|
382
376
|
// src/utils/edit/buildTimeValue.ts
|
|
377
|
+
var parseInt = globalThis.parseInt;
|
|
383
378
|
function buildTimeValue(value) {
|
|
384
379
|
const onlyDigitsValue = value.replace(/\D/g, "");
|
|
385
380
|
if (onlyDigitsValue.length < 2) {
|
|
@@ -436,11 +431,11 @@ function getSpaceUntilMaxLength(element) {
|
|
|
436
431
|
return maxLength ? maxLength - value.length : void 0;
|
|
437
432
|
}
|
|
438
433
|
function getSanitizedMaxLength(element) {
|
|
439
|
-
var
|
|
434
|
+
var _a;
|
|
440
435
|
if (!supportsMaxLength(element)) {
|
|
441
436
|
return void 0;
|
|
442
437
|
}
|
|
443
|
-
const attr = (
|
|
438
|
+
const attr = (_a = element.getAttribute("maxlength")) != null ? _a : "";
|
|
444
439
|
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
|
|
445
440
|
}
|
|
446
441
|
function supportsMaxLength(element) {
|
|
@@ -578,9 +573,9 @@ function commitInput(config, element, newOffset, inputInit) {
|
|
|
578
573
|
}
|
|
579
574
|
}
|
|
580
575
|
function isValidNumberInput(value) {
|
|
581
|
-
var
|
|
576
|
+
var _a, _b;
|
|
582
577
|
const valueParts = value.split("e", 2);
|
|
583
|
-
return !(/[^\d.\-e]/.test(value) || Number((
|
|
578
|
+
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]));
|
|
584
579
|
}
|
|
585
580
|
|
|
586
581
|
// src/utils/edit/isEditable.ts
|
|
@@ -609,8 +604,8 @@ function isEditableInput(element) {
|
|
|
609
604
|
// src/utils/edit/setFiles.ts
|
|
610
605
|
var fakeFiles = Symbol("files and value properties are mocked");
|
|
611
606
|
function setFiles(el, files) {
|
|
612
|
-
var
|
|
613
|
-
(
|
|
607
|
+
var _a;
|
|
608
|
+
(_a = el[fakeFiles]) == null ? void 0 : _a.restore();
|
|
614
609
|
const objectDescriptors = Object.getOwnPropertyDescriptors(el);
|
|
615
610
|
const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
|
|
616
611
|
function restore() {
|
|
@@ -628,11 +623,11 @@ function setFiles(el, files) {
|
|
|
628
623
|
value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
|
|
629
624
|
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
630
625
|
set(v) {
|
|
631
|
-
var
|
|
626
|
+
var _a2;
|
|
632
627
|
if (v === "") {
|
|
633
628
|
restore();
|
|
634
629
|
} else {
|
|
635
|
-
(
|
|
630
|
+
(_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
|
|
636
631
|
}
|
|
637
632
|
}
|
|
638
633
|
}),
|
|
@@ -659,7 +654,7 @@ function eventWrapper(cb) {
|
|
|
659
654
|
|
|
660
655
|
// src/utils/misc/isDisabled.ts
|
|
661
656
|
function isDisabled(element) {
|
|
662
|
-
var
|
|
657
|
+
var _a;
|
|
663
658
|
for (let el = element; el; el = el.parentElement) {
|
|
664
659
|
if (isElementType(el, [
|
|
665
660
|
"button",
|
|
@@ -673,7 +668,7 @@ function isDisabled(element) {
|
|
|
673
668
|
return true;
|
|
674
669
|
}
|
|
675
670
|
} else if (isElementType(el, "fieldset")) {
|
|
676
|
-
if (el.hasAttribute("disabled") && !((
|
|
671
|
+
if (el.hasAttribute("disabled") && !((_a = el.querySelector(":scope > legend")) == null ? void 0 : _a.contains(element))) {
|
|
677
672
|
return true;
|
|
678
673
|
}
|
|
679
674
|
} else if (el.tagName.includes("-")) {
|
|
@@ -686,13 +681,13 @@ function isDisabled(element) {
|
|
|
686
681
|
}
|
|
687
682
|
|
|
688
683
|
// src/utils/focus/getActiveElement.ts
|
|
689
|
-
function getActiveElement(
|
|
690
|
-
const activeElement =
|
|
684
|
+
function getActiveElement(document) {
|
|
685
|
+
const activeElement = document.activeElement;
|
|
691
686
|
if (activeElement == null ? void 0 : activeElement.shadowRoot) {
|
|
692
687
|
return getActiveElement(activeElement.shadowRoot);
|
|
693
688
|
} else {
|
|
694
689
|
if (isDisabled(activeElement)) {
|
|
695
|
-
return
|
|
690
|
+
return document.ownerDocument ? document.ownerDocument.body : document.body;
|
|
696
691
|
}
|
|
697
692
|
return activeElement;
|
|
698
693
|
}
|
|
@@ -806,7 +801,7 @@ function isTextNode(node) {
|
|
|
806
801
|
return node.nodeType === 3;
|
|
807
802
|
}
|
|
808
803
|
function walkNodes(node, direction, callback) {
|
|
809
|
-
var
|
|
804
|
+
var _a;
|
|
810
805
|
for (; ; ) {
|
|
811
806
|
const sibling = node[`${direction}Sibling`];
|
|
812
807
|
if (sibling) {
|
|
@@ -814,7 +809,7 @@ function walkNodes(node, direction, callback) {
|
|
|
814
809
|
if (callback(node)) {
|
|
815
810
|
return node;
|
|
816
811
|
}
|
|
817
|
-
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((
|
|
812
|
+
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a = node.ownerDocument) == null ? void 0 : _a.body))) {
|
|
818
813
|
node = node.parentNode;
|
|
819
814
|
} else {
|
|
820
815
|
break;
|
|
@@ -830,7 +825,7 @@ function getDescendant(node, direction) {
|
|
|
830
825
|
|
|
831
826
|
// src/utils/focus/selection.ts
|
|
832
827
|
function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
833
|
-
var
|
|
828
|
+
var _a;
|
|
834
829
|
if (hasOwnSelection(element)) {
|
|
835
830
|
return setSelection({
|
|
836
831
|
focusNode: element,
|
|
@@ -838,7 +833,7 @@ function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
|
838
833
|
focusOffset
|
|
839
834
|
});
|
|
840
835
|
}
|
|
841
|
-
if (isContentEditable(element) && ((
|
|
836
|
+
if (isContentEditable(element) && ((_a = element.firstChild) == null ? void 0 : _a.nodeType) === 3) {
|
|
842
837
|
return setSelection({
|
|
843
838
|
focusNode: element.firstChild,
|
|
844
839
|
anchorOffset,
|
|
@@ -872,7 +867,7 @@ function getElement2(node) {
|
|
|
872
867
|
return node.nodeType === 1 ? node : node.parentElement;
|
|
873
868
|
}
|
|
874
869
|
function updateSelectionOnFocus(element) {
|
|
875
|
-
var
|
|
870
|
+
var _a;
|
|
876
871
|
const selection = element.ownerDocument.getSelection();
|
|
877
872
|
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
878
873
|
return;
|
|
@@ -881,7 +876,7 @@ function updateSelectionOnFocus(element) {
|
|
|
881
876
|
const contenteditable = getContentEditable(selection.focusNode);
|
|
882
877
|
if (contenteditable) {
|
|
883
878
|
if (!selection.isCollapsed) {
|
|
884
|
-
const focusNode = ((
|
|
879
|
+
const focusNode = ((_a = contenteditable.firstChild) == null ? void 0 : _a.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
885
880
|
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
886
881
|
}
|
|
887
882
|
} else {
|
|
@@ -890,12 +885,12 @@ function updateSelectionOnFocus(element) {
|
|
|
890
885
|
}
|
|
891
886
|
}
|
|
892
887
|
function getInputRange(focusNode) {
|
|
893
|
-
var
|
|
888
|
+
var _a;
|
|
894
889
|
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
895
890
|
if (typeAndSelection.type === "input") {
|
|
896
891
|
return typeAndSelection.selection;
|
|
897
892
|
} else if (typeAndSelection.type === "contenteditable") {
|
|
898
|
-
return (
|
|
893
|
+
return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
|
|
899
894
|
}
|
|
900
895
|
}
|
|
901
896
|
function setSelection({
|
|
@@ -904,7 +899,7 @@ function setSelection({
|
|
|
904
899
|
anchorNode = focusNode,
|
|
905
900
|
anchorOffset = focusOffset
|
|
906
901
|
}) {
|
|
907
|
-
var
|
|
902
|
+
var _a, _b;
|
|
908
903
|
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
909
904
|
if (typeAndSelection.type === "input") {
|
|
910
905
|
return setUISelection(focusNode, {
|
|
@@ -912,7 +907,7 @@ function setSelection({
|
|
|
912
907
|
focusOffset
|
|
913
908
|
});
|
|
914
909
|
}
|
|
915
|
-
(_b = (
|
|
910
|
+
(_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
916
911
|
}
|
|
917
912
|
function moveSelection(node, direction) {
|
|
918
913
|
if (hasOwnSelection(node)) {
|
|
@@ -923,7 +918,7 @@ function moveSelection(node, direction) {
|
|
|
923
918
|
});
|
|
924
919
|
} else {
|
|
925
920
|
const selection = node.ownerDocument.getSelection();
|
|
926
|
-
if (!selection) {
|
|
921
|
+
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
927
922
|
return;
|
|
928
923
|
}
|
|
929
924
|
if (selection.isCollapsed) {
|
|
@@ -985,9 +980,9 @@ function focus(element) {
|
|
|
985
980
|
|
|
986
981
|
// src/utils/misc/isVisible.ts
|
|
987
982
|
function isVisible(element) {
|
|
988
|
-
const
|
|
983
|
+
const window = getWindow(element);
|
|
989
984
|
for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
990
|
-
const { display, visibility } =
|
|
985
|
+
const { display, visibility } = window.getComputedStyle(el);
|
|
991
986
|
if (display === "none") {
|
|
992
987
|
return false;
|
|
993
988
|
}
|
|
@@ -1000,10 +995,10 @@ function isVisible(element) {
|
|
|
1000
995
|
|
|
1001
996
|
// src/utils/focus/getTabDestination.ts
|
|
1002
997
|
function getTabDestination(activeElement, shift) {
|
|
1003
|
-
const
|
|
1004
|
-
const focusableElements =
|
|
1005
|
-
const enabledElements = Array.from(focusableElements).filter((el) => el === activeElement || el.getAttribute("tabindex")
|
|
1006
|
-
if (activeElement.getAttribute("tabindex")
|
|
998
|
+
const document = activeElement.ownerDocument;
|
|
999
|
+
const focusableElements = document.querySelectorAll(FOCUSABLE_SELECTOR);
|
|
1000
|
+
const enabledElements = Array.from(focusableElements).filter((el) => el === activeElement || !(Number(el.getAttribute("tabindex")) < 0 || isDisabled(el)));
|
|
1001
|
+
if (Number(activeElement.getAttribute("tabindex")) >= 0) {
|
|
1007
1002
|
enabledElements.sort((a, b) => {
|
|
1008
1003
|
const i = Number(a.getAttribute("tabindex"));
|
|
1009
1004
|
const j = Number(b.getAttribute("tabindex"));
|
|
@@ -1018,7 +1013,7 @@ function getTabDestination(activeElement, shift) {
|
|
|
1018
1013
|
});
|
|
1019
1014
|
}
|
|
1020
1015
|
const checkedRadio = {};
|
|
1021
|
-
let prunedElements = [
|
|
1016
|
+
let prunedElements = [document.body];
|
|
1022
1017
|
const activeRadioGroup = isElementType(activeElement, "input", {
|
|
1023
1018
|
type: "radio"
|
|
1024
1019
|
}) ? activeElement.name : void 0;
|
|
@@ -1043,15 +1038,22 @@ function getTabDestination(activeElement, shift) {
|
|
|
1043
1038
|
}
|
|
1044
1039
|
prunedElements.push(el);
|
|
1045
1040
|
});
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1041
|
+
for (let index = prunedElements.findIndex((el) => el === activeElement); ; ) {
|
|
1042
|
+
index += shift ? -1 : 1;
|
|
1043
|
+
if (index === prunedElements.length) {
|
|
1044
|
+
index = 0;
|
|
1045
|
+
} else if (index === -1) {
|
|
1046
|
+
index = prunedElements.length - 1;
|
|
1047
|
+
}
|
|
1048
|
+
if (prunedElements[index] === activeElement || prunedElements[index] === document.body || isVisible(prunedElements[index])) {
|
|
1049
|
+
return prunedElements[index];
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1050
1052
|
}
|
|
1051
1053
|
|
|
1052
1054
|
// src/utils/focus/selectAll.ts
|
|
1053
1055
|
function selectAll(target) {
|
|
1054
|
-
var
|
|
1056
|
+
var _a;
|
|
1055
1057
|
if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
|
|
1056
1058
|
return setSelection({
|
|
1057
1059
|
focusNode: target,
|
|
@@ -1059,7 +1061,7 @@ function selectAll(target) {
|
|
|
1059
1061
|
focusOffset: getUIValue(target).length
|
|
1060
1062
|
});
|
|
1061
1063
|
}
|
|
1062
|
-
const focusNode = (
|
|
1064
|
+
const focusNode = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
|
|
1063
1065
|
setSelection({
|
|
1064
1066
|
focusNode,
|
|
1065
1067
|
anchorOffset: 0,
|
|
@@ -1067,11 +1069,11 @@ function selectAll(target) {
|
|
|
1067
1069
|
});
|
|
1068
1070
|
}
|
|
1069
1071
|
function isAllSelected(target) {
|
|
1070
|
-
var
|
|
1072
|
+
var _a;
|
|
1071
1073
|
if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
|
|
1072
1074
|
return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
|
|
1073
1075
|
}
|
|
1074
|
-
const focusNode = (
|
|
1076
|
+
const focusNode = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
|
|
1075
1077
|
const selection = target.ownerDocument.getSelection();
|
|
1076
1078
|
return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
1077
1079
|
}
|
|
@@ -1131,12 +1133,12 @@ function readPrintableChar(text, pos, context) {
|
|
|
1131
1133
|
};
|
|
1132
1134
|
}
|
|
1133
1135
|
function readTag(text, pos, startBracket, context) {
|
|
1134
|
-
var
|
|
1136
|
+
var _a, _b, _c;
|
|
1135
1137
|
const releasePreviousModifier = text[pos] === "/" ? "/" : "";
|
|
1136
1138
|
pos += releasePreviousModifier.length;
|
|
1137
1139
|
const escapedDescriptor = startBracket === "{" && text[pos] === "\\";
|
|
1138
1140
|
pos += Number(escapedDescriptor);
|
|
1139
|
-
const descriptor = escapedDescriptor ? text[pos] : (
|
|
1141
|
+
const descriptor = escapedDescriptor ? text[pos] : (_a = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a[0];
|
|
1140
1142
|
assertDescriptor(descriptor, text, pos, context);
|
|
1141
1143
|
pos += descriptor.length;
|
|
1142
1144
|
const repeatModifier = (_c = (_b = text.slice(pos).match(/^>\d+/)) == null ? void 0 : _b[0]) != null ? _c : "";
|
|
@@ -1208,13 +1210,13 @@ function isDescendantOrSelf(potentialDescendant, potentialAncestor) {
|
|
|
1208
1210
|
// src/utils/misc/level.ts
|
|
1209
1211
|
var Level = Symbol("Api level refs");
|
|
1210
1212
|
function setLevelRef(config, level) {
|
|
1211
|
-
var
|
|
1212
|
-
(
|
|
1213
|
+
var _a;
|
|
1214
|
+
(_a = config[Level]) != null ? _a : config[Level] = {};
|
|
1213
1215
|
config[Level][level] = {};
|
|
1214
1216
|
}
|
|
1215
1217
|
function getLevelRef(config, level) {
|
|
1216
|
-
var
|
|
1217
|
-
return (
|
|
1218
|
+
var _a;
|
|
1219
|
+
return (_a = config[Level]) == null ? void 0 : _a[level];
|
|
1218
1220
|
}
|
|
1219
1221
|
|
|
1220
1222
|
// src/utils/misc/wait.ts
|
|
@@ -1224,7 +1226,7 @@ function wait(config) {
|
|
|
1224
1226
|
return;
|
|
1225
1227
|
}
|
|
1226
1228
|
return Promise.all([
|
|
1227
|
-
new Promise((resolve) => setTimeout(() => resolve(), delay)),
|
|
1229
|
+
new Promise((resolve) => globalThis.setTimeout(() => resolve(), delay)),
|
|
1228
1230
|
config.advanceTimers(delay)
|
|
1229
1231
|
]);
|
|
1230
1232
|
}
|
|
@@ -1307,7 +1309,7 @@ var defaultOptionsDirect = {
|
|
|
1307
1309
|
applyAccept: true,
|
|
1308
1310
|
autoModify: true,
|
|
1309
1311
|
delay: 0,
|
|
1310
|
-
document:
|
|
1312
|
+
document: globalThis.document,
|
|
1311
1313
|
keyboardMap: defaultKeyMap,
|
|
1312
1314
|
pointerMap: defaultKeyMap2,
|
|
1313
1315
|
pointerEventsCheck: 2 /* EachApiCall */,
|
|
@@ -1323,14 +1325,19 @@ var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect)
|
|
|
1323
1325
|
|
|
1324
1326
|
// src/utils/pointer/cssPointerEvents.ts
|
|
1325
1327
|
function hasPointerEvents(element) {
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1328
|
+
var _a;
|
|
1329
|
+
return ((_a = closestPointerEventsDeclaration(element)) == null ? void 0 : _a.pointerEvents) !== "none";
|
|
1330
|
+
}
|
|
1331
|
+
function closestPointerEventsDeclaration(element) {
|
|
1332
|
+
const window = getWindow(element);
|
|
1333
|
+
for (let el = element, tree = []; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
1334
|
+
tree.push(el);
|
|
1335
|
+
const pointerEvents = window.getComputedStyle(el).pointerEvents;
|
|
1329
1336
|
if (pointerEvents && !["inherit", "unset"].includes(pointerEvents)) {
|
|
1330
|
-
return pointerEvents
|
|
1337
|
+
return { pointerEvents, tree };
|
|
1331
1338
|
}
|
|
1332
1339
|
}
|
|
1333
|
-
return
|
|
1340
|
+
return void 0;
|
|
1334
1341
|
}
|
|
1335
1342
|
var PointerEventsCheck = Symbol("Last check for pointer-events");
|
|
1336
1343
|
function assertPointerEvents(config, element) {
|
|
@@ -1339,15 +1346,59 @@ function assertPointerEvents(config, element) {
|
|
|
1339
1346
|
if (!needsCheck) {
|
|
1340
1347
|
return;
|
|
1341
1348
|
}
|
|
1342
|
-
const
|
|
1349
|
+
const declaration = closestPointerEventsDeclaration(element);
|
|
1343
1350
|
element[PointerEventsCheck] = {
|
|
1344
1351
|
[1 /* Call */]: getLevelRef(config, 1 /* Call */),
|
|
1345
1352
|
[2 /* Trigger */]: getLevelRef(config, 2 /* Trigger */),
|
|
1346
|
-
result
|
|
1353
|
+
result: (declaration == null ? void 0 : declaration.pointerEvents) !== "none"
|
|
1347
1354
|
};
|
|
1348
|
-
if (
|
|
1349
|
-
throw new Error(
|
|
1350
|
-
|
|
1355
|
+
if ((declaration == null ? void 0 : declaration.pointerEvents) === "none") {
|
|
1356
|
+
throw new Error([
|
|
1357
|
+
`Unable to perform pointer interaction as the element ${declaration.tree.length > 1 ? "inherits" : "has"} \`pointer-events: none\`:`,
|
|
1358
|
+
"",
|
|
1359
|
+
printTree(declaration.tree)
|
|
1360
|
+
].join("\n"));
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
function printTree(tree) {
|
|
1364
|
+
return tree.reverse().map((el, i) => [
|
|
1365
|
+
"".padEnd(i),
|
|
1366
|
+
el.tagName,
|
|
1367
|
+
el.id && `#${el.id}`,
|
|
1368
|
+
el.hasAttribute("data-testid") && `(testId=${el.getAttribute("data-testid")})`,
|
|
1369
|
+
getLabelDescr(el),
|
|
1370
|
+
tree.length > 1 && i === 0 && " <-- This element declared `pointer-events: none`",
|
|
1371
|
+
tree.length > 1 && i === tree.length - 1 && " <-- Asserted pointer events here"
|
|
1372
|
+
].filter(Boolean).join("")).join("\n");
|
|
1373
|
+
}
|
|
1374
|
+
function getLabelDescr(element) {
|
|
1375
|
+
var _a, _b, _c, _d;
|
|
1376
|
+
let label;
|
|
1377
|
+
if (element.hasAttribute("aria-label")) {
|
|
1378
|
+
label = element.getAttribute("aria-label");
|
|
1379
|
+
} else if (element.hasAttribute("aria-labelledby")) {
|
|
1380
|
+
label = (_b = (_a = element.ownerDocument.getElementById(element.getAttribute("aria-labelledby"))) == null ? void 0 : _a.textContent) == null ? void 0 : _b.trim();
|
|
1381
|
+
} else if (isElementType(element, [
|
|
1382
|
+
"button",
|
|
1383
|
+
"input",
|
|
1384
|
+
"meter",
|
|
1385
|
+
"output",
|
|
1386
|
+
"progress",
|
|
1387
|
+
"select",
|
|
1388
|
+
"textarea"
|
|
1389
|
+
]) && ((_c = element.labels) == null ? void 0 : _c.length)) {
|
|
1390
|
+
label = Array.from(element.labels).map((el) => {
|
|
1391
|
+
var _a2;
|
|
1392
|
+
return (_a2 = el.textContent) == null ? void 0 : _a2.trim();
|
|
1393
|
+
}).join("|");
|
|
1394
|
+
} else if (isElementType(element, "button")) {
|
|
1395
|
+
label = (_d = element.textContent) == null ? void 0 : _d.trim();
|
|
1396
|
+
}
|
|
1397
|
+
label = label == null ? void 0 : label.replace(/\n/g, " ");
|
|
1398
|
+
if (Number(label == null ? void 0 : label.length) > 30) {
|
|
1399
|
+
label = `${label == null ? void 0 : label.substring(0, 29)}\u2026`;
|
|
1400
|
+
}
|
|
1401
|
+
return label ? `(label=${label})` : "";
|
|
1351
1402
|
}
|
|
1352
1403
|
function hasBitFlag(conf, flag) {
|
|
1353
1404
|
return (conf & flag) > 0;
|
|
@@ -1437,9 +1488,9 @@ function assignPositionInit(obj, {
|
|
|
1437
1488
|
screenX,
|
|
1438
1489
|
screenY
|
|
1439
1490
|
}) {
|
|
1440
|
-
var
|
|
1491
|
+
var _a, _b, _c, _d;
|
|
1441
1492
|
assignProps(obj, {
|
|
1442
|
-
x: (
|
|
1493
|
+
x: (_a = x != null ? x : clientX) != null ? _a : 0,
|
|
1443
1494
|
y: (_b = y != null ? y : clientY) != null ? _b : 0,
|
|
1444
1495
|
clientX: (_c = x != null ? x : clientX) != null ? _c : 0,
|
|
1445
1496
|
clientY: (_d = y != null ? y : clientY) != null ? _d : 0,
|
|
@@ -1493,8 +1544,8 @@ behavior.cut = (event, target, config) => {
|
|
|
1493
1544
|
|
|
1494
1545
|
// src/event/behavior/keydown.ts
|
|
1495
1546
|
behavior.keydown = (event, target, config) => {
|
|
1496
|
-
var
|
|
1497
|
-
return (_b = (
|
|
1547
|
+
var _a, _b;
|
|
1548
|
+
return (_b = (_a = keydownBehavior[event.key]) == null ? void 0 : _a.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(event, target, config);
|
|
1498
1549
|
};
|
|
1499
1550
|
var keydownBehavior = {
|
|
1500
1551
|
ArrowLeft: (event, target) => () => moveSelection(target, -1),
|
|
@@ -1516,8 +1567,8 @@ var keydownBehavior = {
|
|
|
1516
1567
|
End: (event, target) => {
|
|
1517
1568
|
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1518
1569
|
return () => {
|
|
1519
|
-
var
|
|
1520
|
-
const newPos = (_b = (
|
|
1570
|
+
var _a, _b;
|
|
1571
|
+
const newPos = (_b = (_a = getValue(target)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
1521
1572
|
setSelectionRange(target, newPos, newPos);
|
|
1522
1573
|
};
|
|
1523
1574
|
}
|
|
@@ -1609,8 +1660,8 @@ var SubmitSingleInputOnEnter = [
|
|
|
1609
1660
|
|
|
1610
1661
|
// src/event/behavior/keyup.ts
|
|
1611
1662
|
behavior.keyup = (event, target, config) => {
|
|
1612
|
-
var
|
|
1613
|
-
return (
|
|
1663
|
+
var _a;
|
|
1664
|
+
return (_a = keyupBehavior[event.key]) == null ? void 0 : _a.call(keyupBehavior, event, target, config);
|
|
1614
1665
|
};
|
|
1615
1666
|
var keyupBehavior = {
|
|
1616
1667
|
" ": (event, target, config) => {
|
|
@@ -1624,8 +1675,8 @@ var keyupBehavior = {
|
|
|
1624
1675
|
behavior.paste = (event, target, config) => {
|
|
1625
1676
|
if (isEditable(target)) {
|
|
1626
1677
|
return () => {
|
|
1627
|
-
var
|
|
1628
|
-
const insertData = (
|
|
1678
|
+
var _a;
|
|
1679
|
+
const insertData = (_a = event.clipboardData) == null ? void 0 : _a.getData("text");
|
|
1629
1680
|
if (insertData) {
|
|
1630
1681
|
input(config, target, insertData, "insertFromPaste");
|
|
1631
1682
|
}
|
|
@@ -1641,10 +1692,10 @@ function wrapEvent(cb, _element) {
|
|
|
1641
1692
|
|
|
1642
1693
|
// src/event/dispatchEvent.ts
|
|
1643
1694
|
function dispatchEvent(config, target, event, preventDefault = false) {
|
|
1644
|
-
var
|
|
1695
|
+
var _a, _b;
|
|
1645
1696
|
const type3 = event.type;
|
|
1646
1697
|
const behaviorImplementation = preventDefault ? () => {
|
|
1647
|
-
} : (_b = (
|
|
1698
|
+
} : (_b = (_a = behavior)[type3]) == null ? void 0 : _b.call(_a, event, target, config);
|
|
1648
1699
|
if (behaviorImplementation) {
|
|
1649
1700
|
event.preventDefault();
|
|
1650
1701
|
let defaultPrevented = false;
|
|
@@ -1760,9 +1811,9 @@ function setUISelection(element, {
|
|
|
1760
1811
|
}
|
|
1761
1812
|
}
|
|
1762
1813
|
function getUISelection(element) {
|
|
1763
|
-
var
|
|
1814
|
+
var _a, _b, _c;
|
|
1764
1815
|
const sel = (_c = element[UISelection]) != null ? _c : {
|
|
1765
|
-
anchorOffset: (
|
|
1816
|
+
anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
|
|
1766
1817
|
focusOffset: (_b = element.selectionEnd) != null ? _b : 0
|
|
1767
1818
|
};
|
|
1768
1819
|
return __spreadProps(__spreadValues({}, sel), {
|
|
@@ -1824,8 +1875,8 @@ function startTrackValue(element) {
|
|
|
1824
1875
|
});
|
|
1825
1876
|
}
|
|
1826
1877
|
function trackOrSetValue(element, v) {
|
|
1827
|
-
var
|
|
1828
|
-
(_b = (
|
|
1878
|
+
var _a, _b, _c;
|
|
1879
|
+
(_b = (_a = element[TrackChanges]) == null ? void 0 : _a.tracked) == null ? void 0 : _b.push(v);
|
|
1829
1880
|
if (!((_c = element[TrackChanges]) == null ? void 0 : _c.tracked)) {
|
|
1830
1881
|
setCleanValue(element, v);
|
|
1831
1882
|
}
|
|
@@ -1835,10 +1886,10 @@ function setCleanValue(element, v) {
|
|
|
1835
1886
|
setUISelection(element, { focusOffset: v.length });
|
|
1836
1887
|
}
|
|
1837
1888
|
function endTrackValue(element) {
|
|
1838
|
-
var
|
|
1889
|
+
var _a, _b;
|
|
1839
1890
|
const changes = element[TrackChanges];
|
|
1840
1891
|
element[TrackChanges] = void 0;
|
|
1841
|
-
const isJustReactStateUpdate = ((
|
|
1892
|
+
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;
|
|
1842
1893
|
if (((_b = changes == null ? void 0 : changes.tracked) == null ? void 0 : _b.length) && !isJustReactStateUpdate) {
|
|
1843
1894
|
setCleanValue(element, changes.tracked[changes.tracked.length - 1]);
|
|
1844
1895
|
}
|
|
@@ -1847,21 +1898,21 @@ function endTrackValue(element) {
|
|
|
1847
1898
|
|
|
1848
1899
|
// src/document/index.ts
|
|
1849
1900
|
var isPrepared = Symbol("Node prepared with document state workarounds");
|
|
1850
|
-
function prepareDocument(
|
|
1851
|
-
if (
|
|
1901
|
+
function prepareDocument(document) {
|
|
1902
|
+
if (document[isPrepared]) {
|
|
1852
1903
|
return;
|
|
1853
1904
|
}
|
|
1854
|
-
|
|
1905
|
+
document.addEventListener("focus", (e) => {
|
|
1855
1906
|
const el = e.target;
|
|
1856
1907
|
prepareElement(el);
|
|
1857
1908
|
}, {
|
|
1858
1909
|
capture: true,
|
|
1859
1910
|
passive: true
|
|
1860
1911
|
});
|
|
1861
|
-
if (
|
|
1862
|
-
prepareElement(
|
|
1912
|
+
if (document.activeElement) {
|
|
1913
|
+
prepareElement(document.activeElement);
|
|
1863
1914
|
}
|
|
1864
|
-
|
|
1915
|
+
document.addEventListener("blur", (e) => {
|
|
1865
1916
|
const el = e.target;
|
|
1866
1917
|
const initialValue = getInitialValue(el);
|
|
1867
1918
|
if (initialValue !== void 0) {
|
|
@@ -1874,7 +1925,7 @@ function prepareDocument(document2) {
|
|
|
1874
1925
|
capture: true,
|
|
1875
1926
|
passive: true
|
|
1876
1927
|
});
|
|
1877
|
-
|
|
1928
|
+
document[isPrepared] = isPrepared;
|
|
1878
1929
|
}
|
|
1879
1930
|
function prepareElement(el) {
|
|
1880
1931
|
if (el[isPrepared]) {
|
|
@@ -1911,11 +1962,11 @@ function isModifierLock(key) {
|
|
|
1911
1962
|
return modifierLocks.includes(key);
|
|
1912
1963
|
}
|
|
1913
1964
|
function preKeydownBehavior(config, { key }, element) {
|
|
1914
|
-
var
|
|
1965
|
+
var _a;
|
|
1915
1966
|
if (isModifierKey(key)) {
|
|
1916
1967
|
config.keyboardState.modifiers[key] = true;
|
|
1917
1968
|
if (key === "AltGraph") {
|
|
1918
|
-
const ctrlKeyDef = (
|
|
1969
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1919
1970
|
dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
|
|
1920
1971
|
}
|
|
1921
1972
|
} else if (isModifierLock(key)) {
|
|
@@ -1935,9 +1986,9 @@ function preKeyupBehavior(config, { key }) {
|
|
|
1935
1986
|
}
|
|
1936
1987
|
}
|
|
1937
1988
|
function postKeyupBehavior(config, { key }, element) {
|
|
1938
|
-
var
|
|
1989
|
+
var _a;
|
|
1939
1990
|
if (key === "AltGraph") {
|
|
1940
|
-
const ctrlKeyDef = (
|
|
1991
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1941
1992
|
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1942
1993
|
}
|
|
1943
1994
|
}
|
|
@@ -1952,8 +2003,8 @@ async function keyboardAction(config, actions) {
|
|
|
1952
2003
|
}
|
|
1953
2004
|
}
|
|
1954
2005
|
async function keyboardKeyAction(config, { keyDef, releasePrevious, releaseSelf, repeat }) {
|
|
1955
|
-
const { document
|
|
1956
|
-
const getCurrentElement = () => getActive(
|
|
2006
|
+
const { document, keyboardState } = config;
|
|
2007
|
+
const getCurrentElement = () => getActive(document);
|
|
1957
2008
|
const pressed = keyboardState.pressed.find((p) => p.keyDef === keyDef);
|
|
1958
2009
|
if (pressed) {
|
|
1959
2010
|
await keyup(keyDef, getCurrentElement, config, pressed.unpreventedDefault);
|
|
@@ -1974,9 +2025,9 @@ async function keyboardKeyAction(config, { keyDef, releasePrevious, releaseSelf,
|
|
|
1974
2025
|
}
|
|
1975
2026
|
}
|
|
1976
2027
|
}
|
|
1977
|
-
function getActive(
|
|
1978
|
-
var
|
|
1979
|
-
return (
|
|
2028
|
+
function getActive(document) {
|
|
2029
|
+
var _a;
|
|
2030
|
+
return (_a = getActiveElement(document)) != null ? _a : document.body;
|
|
1980
2031
|
}
|
|
1981
2032
|
async function releaseAllKeys(config) {
|
|
1982
2033
|
const getCurrentElement = () => getActive(config.document);
|
|
@@ -2010,13 +2061,13 @@ async function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
|
2010
2061
|
postKeyupBehavior(config, keyDef, element);
|
|
2011
2062
|
}
|
|
2012
2063
|
function hasKeyPress(keyDef, config) {
|
|
2013
|
-
var
|
|
2014
|
-
return (((
|
|
2064
|
+
var _a;
|
|
2065
|
+
return (((_a = keyDef.key) == null ? void 0 : _a.length) === 1 || keyDef.key === "Enter") && !config.keyboardState.modifiers.Control && !config.keyboardState.modifiers.Alt;
|
|
2015
2066
|
}
|
|
2016
2067
|
|
|
2017
2068
|
// src/keyboard/parseKeyDef.ts
|
|
2018
2069
|
function parseKeyDef(keyboardMap, text) {
|
|
2019
|
-
var
|
|
2070
|
+
var _a;
|
|
2020
2071
|
const defs = [];
|
|
2021
2072
|
do {
|
|
2022
2073
|
const {
|
|
@@ -2027,15 +2078,15 @@ function parseKeyDef(keyboardMap, text) {
|
|
|
2027
2078
|
releaseSelf = true,
|
|
2028
2079
|
repeat
|
|
2029
2080
|
} = readNextDescriptor(text, "keyboard");
|
|
2030
|
-
const keyDef = (
|
|
2031
|
-
var
|
|
2081
|
+
const keyDef = (_a = keyboardMap.find((def) => {
|
|
2082
|
+
var _a2, _b;
|
|
2032
2083
|
if (type3 === "[") {
|
|
2033
|
-
return ((
|
|
2084
|
+
return ((_a2 = def.code) == null ? void 0 : _a2.toLowerCase()) === descriptor.toLowerCase();
|
|
2034
2085
|
} else if (type3 === "{") {
|
|
2035
2086
|
return ((_b = def.key) == null ? void 0 : _b.toLowerCase()) === descriptor.toLowerCase();
|
|
2036
2087
|
}
|
|
2037
2088
|
return def.key === descriptor;
|
|
2038
|
-
})) != null ?
|
|
2089
|
+
})) != null ? _a : {
|
|
2039
2090
|
key: "Unknown",
|
|
2040
2091
|
code: "Unknown",
|
|
2041
2092
|
[type3 === "[" ? "code" : "key"]: descriptor
|
|
@@ -2112,8 +2163,8 @@ function firePointerEvent(config, target, type3, {
|
|
|
2112
2163
|
}
|
|
2113
2164
|
init.button = getMouseButton(button != null ? button : 0);
|
|
2114
2165
|
init.buttons = getMouseButtons(...config.pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
|
|
2115
|
-
var
|
|
2116
|
-
return (
|
|
2166
|
+
var _a;
|
|
2167
|
+
return (_a = p.keyDef.button) != null ? _a : 0;
|
|
2117
2168
|
}));
|
|
2118
2169
|
if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
|
|
2119
2170
|
init.detail = clickCount;
|
|
@@ -2271,7 +2322,7 @@ function getNextPointerId(state) {
|
|
|
2271
2322
|
return state.pointerId;
|
|
2272
2323
|
}
|
|
2273
2324
|
function down(config, pointerName, { keyDef, node, offset, target, coords }, targetIsDisabled) {
|
|
2274
|
-
var
|
|
2325
|
+
var _a, _b, _c;
|
|
2275
2326
|
setLevelRef(config, 2 /* Trigger */);
|
|
2276
2327
|
assertPointerEvents(config, target);
|
|
2277
2328
|
const { pointerState } = config;
|
|
@@ -2294,7 +2345,7 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
|
|
|
2294
2345
|
}
|
|
2295
2346
|
}
|
|
2296
2347
|
}
|
|
2297
|
-
if (((
|
|
2348
|
+
if (((_a = pointerState.activeClickCount) == null ? void 0 : _a[0]) !== name) {
|
|
2298
2349
|
delete pointerState.activeClickCount;
|
|
2299
2350
|
}
|
|
2300
2351
|
const clickCount = Number((_c = (_b = pointerState.activeClickCount) == null ? void 0 : _b[1]) != null ? _c : 0) + 1;
|
|
@@ -2477,11 +2528,11 @@ function getTextRange(text, pos, clickCount) {
|
|
|
2477
2528
|
|
|
2478
2529
|
// src/pointer/pointerAction.ts
|
|
2479
2530
|
async function pointerAction(config, actions) {
|
|
2480
|
-
var
|
|
2531
|
+
var _a, _b;
|
|
2481
2532
|
for (let i = 0; i < actions.length; i++) {
|
|
2482
2533
|
const action = actions[i];
|
|
2483
2534
|
const pointerName = "pointerName" in action && action.pointerName ? action.pointerName : "keyDef" in action ? action.keyDef.pointerType === "touch" ? action.keyDef.name : action.keyDef.pointerType : "mouse";
|
|
2484
|
-
const target = (
|
|
2535
|
+
const target = (_a = action.target) != null ? _a : getPrevTarget(pointerName, config.pointerState);
|
|
2485
2536
|
const coords = (_b = action.coords) != null ? _b : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : void 0;
|
|
2486
2537
|
await ("keyDef" in action ? pointerPress(config, __spreadProps(__spreadValues({}, action), { target, coords })) : pointerMove(config, __spreadProps(__spreadValues({}, action), { target, coords })));
|
|
2487
2538
|
if (i < actions.length - 1) {
|
|
@@ -2512,14 +2563,14 @@ async function pointer(input2) {
|
|
|
2512
2563
|
});
|
|
2513
2564
|
return pointerAction(this[Config], actions).then(() => void 0);
|
|
2514
2565
|
}
|
|
2515
|
-
function createPointerState(
|
|
2566
|
+
function createPointerState(document) {
|
|
2516
2567
|
return {
|
|
2517
2568
|
pointerId: 1,
|
|
2518
2569
|
position: {
|
|
2519
2570
|
mouse: {
|
|
2520
2571
|
pointerType: "mouse",
|
|
2521
2572
|
pointerId: 1,
|
|
2522
|
-
target:
|
|
2573
|
+
target: document.body,
|
|
2523
2574
|
coords: {
|
|
2524
2575
|
clientX: 0,
|
|
2525
2576
|
clientY: 0,
|
|
@@ -2593,9 +2644,9 @@ async function tab({
|
|
|
2593
2644
|
|
|
2594
2645
|
// src/clipboard/copy.ts
|
|
2595
2646
|
async function copy() {
|
|
2596
|
-
var
|
|
2647
|
+
var _a;
|
|
2597
2648
|
const doc = this[Config].document;
|
|
2598
|
-
const target = (
|
|
2649
|
+
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2599
2650
|
const clipboardData = copySelection(target);
|
|
2600
2651
|
if (clipboardData.items.length === 0) {
|
|
2601
2652
|
return;
|
|
@@ -2610,9 +2661,9 @@ async function copy() {
|
|
|
2610
2661
|
|
|
2611
2662
|
// src/clipboard/cut.ts
|
|
2612
2663
|
async function cut() {
|
|
2613
|
-
var
|
|
2664
|
+
var _a;
|
|
2614
2665
|
const doc = this[Config].document;
|
|
2615
|
-
const target = (
|
|
2666
|
+
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2616
2667
|
const clipboardData = copySelection(target);
|
|
2617
2668
|
if (clipboardData.items.length === 0) {
|
|
2618
2669
|
return;
|
|
@@ -2627,9 +2678,9 @@ async function cut() {
|
|
|
2627
2678
|
|
|
2628
2679
|
// src/clipboard/paste.ts
|
|
2629
2680
|
async function paste(clipboardData) {
|
|
2630
|
-
var
|
|
2681
|
+
var _a, _b;
|
|
2631
2682
|
const doc = this[Config].document;
|
|
2632
|
-
const target = (
|
|
2683
|
+
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2633
2684
|
const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(doc, clipboardData) : clipboardData) != null ? _b : await readDataTransferFromClipboard(doc).catch(() => {
|
|
2634
2685
|
throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
|
|
2635
2686
|
});
|
|
@@ -2719,6 +2770,7 @@ async function selectOptionsBase(newValue, select, values) {
|
|
|
2719
2770
|
if (withPointerEvents) {
|
|
2720
2771
|
this.dispatchUIEvent(option, "click");
|
|
2721
2772
|
}
|
|
2773
|
+
await wait(this[Config]);
|
|
2722
2774
|
}
|
|
2723
2775
|
} else if (selectedOptions.length === 1) {
|
|
2724
2776
|
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(select);
|
|
@@ -2737,6 +2789,7 @@ async function selectOptionsBase(newValue, select, values) {
|
|
|
2737
2789
|
this.dispatchUIEvent(select, "mouseup");
|
|
2738
2790
|
this.dispatchUIEvent(select, "click");
|
|
2739
2791
|
}
|
|
2792
|
+
await wait(this[Config]);
|
|
2740
2793
|
} else {
|
|
2741
2794
|
throw (0, import_dom4.getConfig)().getElementError(`Cannot select multiple options on a non-multiple select`, select);
|
|
2742
2795
|
}
|
|
@@ -2781,10 +2834,10 @@ async function upload(element, fileOrFiles) {
|
|
|
2781
2834
|
return;
|
|
2782
2835
|
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input2.accept)).slice(0, input2.multiple ? void 0 : 1);
|
|
2783
2836
|
const fileDialog = () => {
|
|
2784
|
-
var
|
|
2785
|
-
if (files.length === ((
|
|
2786
|
-
var
|
|
2787
|
-
return f === ((
|
|
2837
|
+
var _a;
|
|
2838
|
+
if (files.length === ((_a = input2.files) == null ? void 0 : _a.length) && files.every((f, i) => {
|
|
2839
|
+
var _a2;
|
|
2840
|
+
return f === ((_a2 = input2.files) == null ? void 0 : _a2.item(i));
|
|
2788
2841
|
})) {
|
|
2789
2842
|
return;
|
|
2790
2843
|
}
|
|
@@ -2819,22 +2872,22 @@ function wrapAsync(implementation) {
|
|
|
2819
2872
|
|
|
2820
2873
|
// src/setup/setup.ts
|
|
2821
2874
|
function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
|
|
2822
|
-
const
|
|
2875
|
+
const document = getDocument(options, node, defaults);
|
|
2823
2876
|
const {
|
|
2824
2877
|
keyboardState = createKeyboardState(),
|
|
2825
|
-
pointerState = createPointerState(
|
|
2878
|
+
pointerState = createPointerState(document)
|
|
2826
2879
|
} = options;
|
|
2827
2880
|
return __spreadProps(__spreadValues(__spreadValues({}, defaults), options), {
|
|
2828
|
-
document
|
|
2881
|
+
document,
|
|
2829
2882
|
keyboardState,
|
|
2830
2883
|
pointerState
|
|
2831
2884
|
});
|
|
2832
2885
|
}
|
|
2833
2886
|
function setupMain(options = {}) {
|
|
2834
|
-
var
|
|
2887
|
+
var _a;
|
|
2835
2888
|
const config = createConfig(options);
|
|
2836
2889
|
prepareDocument(config.document);
|
|
2837
|
-
const view = (
|
|
2890
|
+
const view = (_a = config.document.defaultView) != null ? _a : globalThis.window;
|
|
2838
2891
|
attachClipboardStubToView(view);
|
|
2839
2892
|
return doSetup(config);
|
|
2840
2893
|
}
|
|
@@ -2852,7 +2905,10 @@ function setupSub(options) {
|
|
|
2852
2905
|
function wrapAndBindImpl(instance, impl) {
|
|
2853
2906
|
function method(...args) {
|
|
2854
2907
|
setLevelRef(instance[Config], 1 /* Call */);
|
|
2855
|
-
return wrapAsync(() => impl.apply(instance, args))
|
|
2908
|
+
return wrapAsync(() => impl.apply(instance, args).then(async (ret) => {
|
|
2909
|
+
await wait(instance[Config]);
|
|
2910
|
+
return ret;
|
|
2911
|
+
}));
|
|
2856
2912
|
}
|
|
2857
2913
|
Object.defineProperty(method, "name", { get: () => impl.name });
|
|
2858
2914
|
return method;
|
|
@@ -2869,9 +2925,9 @@ function doSetup(config) {
|
|
|
2869
2925
|
setup: setupSub.bind(instance)
|
|
2870
2926
|
});
|
|
2871
2927
|
}
|
|
2872
|
-
function getDocument(options, node) {
|
|
2873
|
-
var
|
|
2874
|
-
return (_b = (
|
|
2928
|
+
function getDocument(options, node, defaults) {
|
|
2929
|
+
var _a, _b;
|
|
2930
|
+
return (_b = (_a = options.document) != null ? _a : node && getDocumentFromNode(node)) != null ? _b : defaults.document;
|
|
2875
2931
|
}
|
|
2876
2932
|
|
|
2877
2933
|
// src/setup/directApi.ts
|