@testing-library/user-event 14.0.1 → 14.0.2
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 +133 -117
- package/dist/index.mjs +133 -117
- package/dist/types/utils/dataTransfer/Blob.d.ts +3 -1
- package/dist/types/utils/dataTransfer/Clipboard.d.ts +1 -1
- package/dist/types/utils/dataTransfer/DataTransfer.d.ts +2 -2
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/misc/getWindow.d.ts +1 -0
- package/package.json +8 -5
package/dist/index.mjs
CHANGED
|
@@ -74,7 +74,7 @@ function isClickableInput(element) {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// src/utils/dataTransfer/Blob.ts
|
|
77
|
-
function readBlobText(blob) {
|
|
77
|
+
function readBlobText(blob, FileReader) {
|
|
78
78
|
return new Promise((res, rej) => {
|
|
79
79
|
const fr = new FileReader();
|
|
80
80
|
fr.onerror = rej;
|
|
@@ -158,8 +158,8 @@ var DataTransferStub = class {
|
|
|
158
158
|
this.files = createFileList([]);
|
|
159
159
|
}
|
|
160
160
|
getData(format) {
|
|
161
|
-
var
|
|
162
|
-
const match = (
|
|
161
|
+
var _a3;
|
|
162
|
+
const match = (_a3 = this.items.find(getTypeMatcher(format, true))) != null ? _a3 : this.items.find(getTypeMatcher(format, false));
|
|
163
163
|
let text = "";
|
|
164
164
|
match == null ? void 0 : match.getAsString((t) => {
|
|
165
165
|
text = t;
|
|
@@ -197,12 +197,12 @@ var DataTransferStub = class {
|
|
|
197
197
|
setDragImage() {
|
|
198
198
|
}
|
|
199
199
|
};
|
|
200
|
-
function createDataTransfer(files = []) {
|
|
201
|
-
const dt = typeof DataTransfer === "undefined" ? new DataTransferStub() : new DataTransfer();
|
|
200
|
+
function createDataTransfer(window2, files = []) {
|
|
201
|
+
const dt = typeof window2.DataTransfer === "undefined" ? new DataTransferStub() : new window2.DataTransfer();
|
|
202
202
|
Object.defineProperty(dt, "files", { get: () => createFileList(files) });
|
|
203
203
|
return dt;
|
|
204
204
|
}
|
|
205
|
-
function getBlobFromDataTransferItem(item) {
|
|
205
|
+
function getBlobFromDataTransferItem(window2, item) {
|
|
206
206
|
if (item.kind === "file") {
|
|
207
207
|
return item.getAsFile();
|
|
208
208
|
}
|
|
@@ -210,12 +210,21 @@ function getBlobFromDataTransferItem(item) {
|
|
|
210
210
|
item.getAsString((s) => {
|
|
211
211
|
data = s;
|
|
212
212
|
});
|
|
213
|
-
return new Blob([data], { type: item.type });
|
|
213
|
+
return new window2.Blob([data], { type: item.type });
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/utils/misc/getWindow.ts
|
|
217
|
+
import { getWindowFromNode } from "@testing-library/dom/dist/helpers.js";
|
|
218
|
+
function getWindow(node) {
|
|
219
|
+
return getWindowFromNode(node);
|
|
214
220
|
}
|
|
215
221
|
|
|
216
222
|
// src/utils/dataTransfer/Clipboard.ts
|
|
223
|
+
var Window = Symbol("Window reference");
|
|
224
|
+
var _a;
|
|
217
225
|
var ClipboardItemStub = class {
|
|
218
226
|
constructor(data) {
|
|
227
|
+
this[_a] = window;
|
|
219
228
|
this.data = data;
|
|
220
229
|
}
|
|
221
230
|
get types() {
|
|
@@ -227,15 +236,18 @@ var ClipboardItemStub = class {
|
|
|
227
236
|
if (!data) {
|
|
228
237
|
throw new Error(`${type3} is not one of the available MIME types on this item.`);
|
|
229
238
|
}
|
|
230
|
-
return data instanceof Blob ? data : new Blob([data], { type: type3 });
|
|
239
|
+
return data instanceof this[Window].Blob ? data : new this[Window].Blob([data], { type: type3 });
|
|
231
240
|
});
|
|
232
241
|
}
|
|
233
242
|
};
|
|
243
|
+
_a = Window;
|
|
234
244
|
var ClipboardStubControl = Symbol("Manage ClipboardSub");
|
|
235
|
-
var
|
|
245
|
+
var _a2;
|
|
246
|
+
var ClipboardStub = class extends window.EventTarget {
|
|
236
247
|
constructor() {
|
|
237
248
|
super(...arguments);
|
|
238
249
|
this.items = [];
|
|
250
|
+
this[_a2] = window;
|
|
239
251
|
}
|
|
240
252
|
read() {
|
|
241
253
|
return __async(this, null, function* () {
|
|
@@ -248,7 +260,7 @@ var ClipboardStub = class extends EventTarget {
|
|
|
248
260
|
for (const item of this.items) {
|
|
249
261
|
const type3 = item.types.includes("text/plain") ? "text/plain" : item.types.find((t) => t.startsWith("text/"));
|
|
250
262
|
if (type3) {
|
|
251
|
-
text += yield item.getType(type3).then((b) => readBlobText(b));
|
|
263
|
+
text += yield item.getType(type3).then((b) => readBlobText(b, this[Window].FileReader));
|
|
252
264
|
}
|
|
253
265
|
}
|
|
254
266
|
return text;
|
|
@@ -261,17 +273,23 @@ var ClipboardStub = class extends EventTarget {
|
|
|
261
273
|
}
|
|
262
274
|
writeText(text) {
|
|
263
275
|
return __async(this, null, function* () {
|
|
264
|
-
this.items = [createClipboardItem(text)];
|
|
276
|
+
this.items = [createClipboardItem(this[Window], text)];
|
|
265
277
|
});
|
|
266
278
|
}
|
|
267
279
|
};
|
|
268
|
-
ClipboardStubControl;
|
|
269
|
-
function createClipboardItem(...blobs) {
|
|
270
|
-
const
|
|
271
|
-
return new constructor(Object.fromEntries(blobs.map((b) => [
|
|
280
|
+
_a2 = Window, ClipboardStubControl;
|
|
281
|
+
function createClipboardItem(window2, ...blobs) {
|
|
282
|
+
const data = Object.fromEntries(blobs.map((b) => [
|
|
272
283
|
typeof b === "string" ? "text/plain" : b.type,
|
|
273
284
|
Promise.resolve(b)
|
|
274
|
-
]))
|
|
285
|
+
]));
|
|
286
|
+
if (typeof window2.ClipboardItem === "undefined") {
|
|
287
|
+
const item = new ClipboardItemStub(data);
|
|
288
|
+
item[Window] = window2;
|
|
289
|
+
return item;
|
|
290
|
+
} else {
|
|
291
|
+
return new window2.ClipboardItem(data);
|
|
292
|
+
}
|
|
275
293
|
}
|
|
276
294
|
function attachClipboardStubToView(window2) {
|
|
277
295
|
if (window2.navigator.clipboard instanceof ClipboardStub) {
|
|
@@ -279,9 +297,11 @@ function attachClipboardStubToView(window2) {
|
|
|
279
297
|
}
|
|
280
298
|
const realClipboard = Object.getOwnPropertyDescriptor(window2.navigator, "clipboard");
|
|
281
299
|
let stub = new ClipboardStub();
|
|
300
|
+
stub[Window] = window2;
|
|
282
301
|
const control = {
|
|
283
302
|
resetClipboardStub: () => {
|
|
284
303
|
stub = new ClipboardStub();
|
|
304
|
+
stub[Window] = window2;
|
|
285
305
|
stub[ClipboardStubControl] = control;
|
|
286
306
|
},
|
|
287
307
|
detachClipboardStub: () => {
|
|
@@ -314,16 +334,16 @@ function detachClipboardStubFromView(window2) {
|
|
|
314
334
|
}
|
|
315
335
|
function readDataTransferFromClipboard(document2) {
|
|
316
336
|
return __async(this, null, function* () {
|
|
317
|
-
|
|
318
|
-
const clipboard =
|
|
337
|
+
const window2 = document2.defaultView;
|
|
338
|
+
const clipboard = window2 == null ? void 0 : window2.navigator.clipboard;
|
|
319
339
|
const items = clipboard && (yield clipboard.read());
|
|
320
340
|
if (!items) {
|
|
321
341
|
throw new Error("The Clipboard API is unavailable.");
|
|
322
342
|
}
|
|
323
|
-
const dt = createDataTransfer();
|
|
343
|
+
const dt = createDataTransfer(window2);
|
|
324
344
|
for (const item of items) {
|
|
325
345
|
for (const type3 of item.types) {
|
|
326
|
-
dt.setData(type3, yield item.getType(type3).then((b) => readBlobText(b)));
|
|
346
|
+
dt.setData(type3, yield item.getType(type3).then((b) => readBlobText(b, window2.FileReader)));
|
|
327
347
|
}
|
|
328
348
|
}
|
|
329
349
|
return dt;
|
|
@@ -331,13 +351,13 @@ function readDataTransferFromClipboard(document2) {
|
|
|
331
351
|
}
|
|
332
352
|
function writeDataTransferToClipboard(document2, clipboardData) {
|
|
333
353
|
return __async(this, null, function* () {
|
|
334
|
-
|
|
335
|
-
const clipboard =
|
|
354
|
+
const window2 = getWindow(document2);
|
|
355
|
+
const clipboard = window2.navigator.clipboard;
|
|
336
356
|
const items = [];
|
|
337
357
|
for (let i = 0; i < clipboardData.items.length; i++) {
|
|
338
358
|
const dtItem = clipboardData.items[i];
|
|
339
|
-
const blob = getBlobFromDataTransferItem(dtItem);
|
|
340
|
-
items.push(createClipboardItem(blob));
|
|
359
|
+
const blob = getBlobFromDataTransferItem(window2, dtItem);
|
|
360
|
+
items.push(createClipboardItem(window2, blob));
|
|
341
361
|
}
|
|
342
362
|
const written = clipboard && (yield clipboard.write(items).then(() => true, () => false));
|
|
343
363
|
if (!written) {
|
|
@@ -432,11 +452,11 @@ function getSpaceUntilMaxLength(element) {
|
|
|
432
452
|
return maxLength ? maxLength - value.length : void 0;
|
|
433
453
|
}
|
|
434
454
|
function getSanitizedMaxLength(element) {
|
|
435
|
-
var
|
|
455
|
+
var _a3;
|
|
436
456
|
if (!supportsMaxLength(element)) {
|
|
437
457
|
return void 0;
|
|
438
458
|
}
|
|
439
|
-
const attr = (
|
|
459
|
+
const attr = (_a3 = element.getAttribute("maxlength")) != null ? _a3 : "";
|
|
440
460
|
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
|
|
441
461
|
}
|
|
442
462
|
function supportsMaxLength(element) {
|
|
@@ -573,9 +593,9 @@ function commitInput(config, element, newOffset, inputInit) {
|
|
|
573
593
|
}
|
|
574
594
|
}
|
|
575
595
|
function isValidNumberInput(value) {
|
|
576
|
-
var
|
|
596
|
+
var _a3, _b;
|
|
577
597
|
const valueParts = value.split("e", 2);
|
|
578
|
-
return !(/[^\d.\-e]/.test(value) || Number((
|
|
598
|
+
return !(/[^\d.\-e]/.test(value) || Number((_a3 = value.match(/-/g)) == null ? void 0 : _a3.length) > 2 || Number((_b = value.match(/\./g)) == null ? void 0 : _b.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1]));
|
|
579
599
|
}
|
|
580
600
|
|
|
581
601
|
// src/utils/edit/isEditable.ts
|
|
@@ -604,8 +624,8 @@ function isEditableInput(element) {
|
|
|
604
624
|
// src/utils/edit/setFiles.ts
|
|
605
625
|
var fakeFiles = Symbol("files and value properties are mocked");
|
|
606
626
|
function setFiles(el, files) {
|
|
607
|
-
var
|
|
608
|
-
(
|
|
627
|
+
var _a3;
|
|
628
|
+
(_a3 = el[fakeFiles]) == null ? void 0 : _a3.restore();
|
|
609
629
|
const objectDescriptors = Object.getOwnPropertyDescriptors(el);
|
|
610
630
|
const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
|
|
611
631
|
function restore() {
|
|
@@ -623,11 +643,11 @@ function setFiles(el, files) {
|
|
|
623
643
|
value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
|
|
624
644
|
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
625
645
|
set(v) {
|
|
626
|
-
var
|
|
646
|
+
var _a4;
|
|
627
647
|
if (v === "") {
|
|
628
648
|
restore();
|
|
629
649
|
} else {
|
|
630
|
-
(
|
|
650
|
+
(_a4 = objectDescriptors.value.set) == null ? void 0 : _a4.call(el, v);
|
|
631
651
|
}
|
|
632
652
|
}
|
|
633
653
|
}),
|
|
@@ -654,7 +674,7 @@ function eventWrapper(cb) {
|
|
|
654
674
|
|
|
655
675
|
// src/utils/misc/isDisabled.ts
|
|
656
676
|
function isDisabled(element) {
|
|
657
|
-
var
|
|
677
|
+
var _a3;
|
|
658
678
|
for (let el = element; el; el = el.parentElement) {
|
|
659
679
|
if (isElementType(el, [
|
|
660
680
|
"button",
|
|
@@ -668,7 +688,7 @@ function isDisabled(element) {
|
|
|
668
688
|
return true;
|
|
669
689
|
}
|
|
670
690
|
} else if (isElementType(el, "fieldset")) {
|
|
671
|
-
if (el.hasAttribute("disabled") && !((
|
|
691
|
+
if (el.hasAttribute("disabled") && !((_a3 = el.querySelector(":scope > legend")) == null ? void 0 : _a3.contains(element))) {
|
|
672
692
|
return true;
|
|
673
693
|
}
|
|
674
694
|
} else if (el.tagName.includes("-")) {
|
|
@@ -801,7 +821,7 @@ function isTextNode(node) {
|
|
|
801
821
|
return node.nodeType === 3;
|
|
802
822
|
}
|
|
803
823
|
function walkNodes(node, direction, callback) {
|
|
804
|
-
var
|
|
824
|
+
var _a3;
|
|
805
825
|
for (; ; ) {
|
|
806
826
|
const sibling = node[`${direction}Sibling`];
|
|
807
827
|
if (sibling) {
|
|
@@ -809,7 +829,7 @@ function walkNodes(node, direction, callback) {
|
|
|
809
829
|
if (callback(node)) {
|
|
810
830
|
return node;
|
|
811
831
|
}
|
|
812
|
-
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((
|
|
832
|
+
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a3 = node.ownerDocument) == null ? void 0 : _a3.body))) {
|
|
813
833
|
node = node.parentNode;
|
|
814
834
|
} else {
|
|
815
835
|
break;
|
|
@@ -825,7 +845,7 @@ function getDescendant(node, direction) {
|
|
|
825
845
|
|
|
826
846
|
// src/utils/focus/selection.ts
|
|
827
847
|
function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
828
|
-
var
|
|
848
|
+
var _a3;
|
|
829
849
|
if (hasOwnSelection(element)) {
|
|
830
850
|
return setSelection({
|
|
831
851
|
focusNode: element,
|
|
@@ -833,7 +853,7 @@ function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
|
833
853
|
focusOffset
|
|
834
854
|
});
|
|
835
855
|
}
|
|
836
|
-
if (isContentEditable(element) && ((
|
|
856
|
+
if (isContentEditable(element) && ((_a3 = element.firstChild) == null ? void 0 : _a3.nodeType) === 3) {
|
|
837
857
|
return setSelection({
|
|
838
858
|
focusNode: element.firstChild,
|
|
839
859
|
anchorOffset,
|
|
@@ -867,7 +887,7 @@ function getElement2(node) {
|
|
|
867
887
|
return node.nodeType === 1 ? node : node.parentElement;
|
|
868
888
|
}
|
|
869
889
|
function updateSelectionOnFocus(element) {
|
|
870
|
-
var
|
|
890
|
+
var _a3;
|
|
871
891
|
const selection = element.ownerDocument.getSelection();
|
|
872
892
|
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
873
893
|
return;
|
|
@@ -876,7 +896,7 @@ function updateSelectionOnFocus(element) {
|
|
|
876
896
|
const contenteditable = getContentEditable(selection.focusNode);
|
|
877
897
|
if (contenteditable) {
|
|
878
898
|
if (!selection.isCollapsed) {
|
|
879
|
-
const focusNode = ((
|
|
899
|
+
const focusNode = ((_a3 = contenteditable.firstChild) == null ? void 0 : _a3.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
880
900
|
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
881
901
|
}
|
|
882
902
|
} else {
|
|
@@ -885,12 +905,12 @@ function updateSelectionOnFocus(element) {
|
|
|
885
905
|
}
|
|
886
906
|
}
|
|
887
907
|
function getInputRange(focusNode) {
|
|
888
|
-
var
|
|
908
|
+
var _a3;
|
|
889
909
|
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
890
910
|
if (typeAndSelection.type === "input") {
|
|
891
911
|
return typeAndSelection.selection;
|
|
892
912
|
} else if (typeAndSelection.type === "contenteditable") {
|
|
893
|
-
return (
|
|
913
|
+
return (_a3 = typeAndSelection.selection) == null ? void 0 : _a3.getRangeAt(0);
|
|
894
914
|
}
|
|
895
915
|
}
|
|
896
916
|
function setSelection({
|
|
@@ -899,7 +919,7 @@ function setSelection({
|
|
|
899
919
|
anchorNode = focusNode,
|
|
900
920
|
anchorOffset = focusOffset
|
|
901
921
|
}) {
|
|
902
|
-
var
|
|
922
|
+
var _a3, _b;
|
|
903
923
|
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
904
924
|
if (typeAndSelection.type === "input") {
|
|
905
925
|
return setUISelection(focusNode, {
|
|
@@ -907,7 +927,7 @@ function setSelection({
|
|
|
907
927
|
focusOffset
|
|
908
928
|
});
|
|
909
929
|
}
|
|
910
|
-
(_b = (
|
|
930
|
+
(_b = (_a3 = anchorNode.ownerDocument) == null ? void 0 : _a3.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
911
931
|
}
|
|
912
932
|
function moveSelection(node, direction) {
|
|
913
933
|
if (hasOwnSelection(node)) {
|
|
@@ -938,7 +958,7 @@ function moveSelection(node, direction) {
|
|
|
938
958
|
// src/utils/focus/copySelection.ts
|
|
939
959
|
function copySelection(target) {
|
|
940
960
|
const data = hasOwnSelection(target) ? { "text/plain": readSelectedValueFromInput(target) } : { "text/plain": String(target.ownerDocument.getSelection()) };
|
|
941
|
-
const dt = createDataTransfer();
|
|
961
|
+
const dt = createDataTransfer(getWindow(target));
|
|
942
962
|
for (const type3 in data) {
|
|
943
963
|
if (data[type3]) {
|
|
944
964
|
dt.setData(type3, data[type3]);
|
|
@@ -979,9 +999,8 @@ function focus(element) {
|
|
|
979
999
|
}
|
|
980
1000
|
|
|
981
1001
|
// src/utils/misc/isVisible.ts
|
|
982
|
-
import { getWindowFromNode } from "@testing-library/dom/dist/helpers.js";
|
|
983
1002
|
function isVisible(element) {
|
|
984
|
-
const window2 =
|
|
1003
|
+
const window2 = getWindow(element);
|
|
985
1004
|
for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
986
1005
|
const { display, visibility } = window2.getComputedStyle(el);
|
|
987
1006
|
if (display === "none") {
|
|
@@ -1047,7 +1066,7 @@ function getTabDestination(activeElement, shift) {
|
|
|
1047
1066
|
|
|
1048
1067
|
// src/utils/focus/selectAll.ts
|
|
1049
1068
|
function selectAll(target) {
|
|
1050
|
-
var
|
|
1069
|
+
var _a3;
|
|
1051
1070
|
if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
|
|
1052
1071
|
return setSelection({
|
|
1053
1072
|
focusNode: target,
|
|
@@ -1055,7 +1074,7 @@ function selectAll(target) {
|
|
|
1055
1074
|
focusOffset: getUIValue(target).length
|
|
1056
1075
|
});
|
|
1057
1076
|
}
|
|
1058
|
-
const focusNode = (
|
|
1077
|
+
const focusNode = (_a3 = getContentEditable(target)) != null ? _a3 : target.ownerDocument.body;
|
|
1059
1078
|
setSelection({
|
|
1060
1079
|
focusNode,
|
|
1061
1080
|
anchorOffset: 0,
|
|
@@ -1063,11 +1082,11 @@ function selectAll(target) {
|
|
|
1063
1082
|
});
|
|
1064
1083
|
}
|
|
1065
1084
|
function isAllSelected(target) {
|
|
1066
|
-
var
|
|
1085
|
+
var _a3;
|
|
1067
1086
|
if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
|
|
1068
1087
|
return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
|
|
1069
1088
|
}
|
|
1070
|
-
const focusNode = (
|
|
1089
|
+
const focusNode = (_a3 = getContentEditable(target)) != null ? _a3 : target.ownerDocument.body;
|
|
1071
1090
|
const selection = target.ownerDocument.getSelection();
|
|
1072
1091
|
return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
1073
1092
|
}
|
|
@@ -1127,12 +1146,12 @@ function readPrintableChar(text, pos, context) {
|
|
|
1127
1146
|
};
|
|
1128
1147
|
}
|
|
1129
1148
|
function readTag(text, pos, startBracket, context) {
|
|
1130
|
-
var
|
|
1149
|
+
var _a3, _b, _c;
|
|
1131
1150
|
const releasePreviousModifier = text[pos] === "/" ? "/" : "";
|
|
1132
1151
|
pos += releasePreviousModifier.length;
|
|
1133
1152
|
const escapedDescriptor = startBracket === "{" && text[pos] === "\\";
|
|
1134
1153
|
pos += Number(escapedDescriptor);
|
|
1135
|
-
const descriptor = escapedDescriptor ? text[pos] : (
|
|
1154
|
+
const descriptor = escapedDescriptor ? text[pos] : (_a3 = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a3[0];
|
|
1136
1155
|
assertDescriptor(descriptor, text, pos, context);
|
|
1137
1156
|
pos += descriptor.length;
|
|
1138
1157
|
const repeatModifier = (_c = (_b = text.slice(pos).match(/^>\d+/)) == null ? void 0 : _b[0]) != null ? _c : "";
|
|
@@ -1204,13 +1223,13 @@ function isDescendantOrSelf(potentialDescendant, potentialAncestor) {
|
|
|
1204
1223
|
// src/utils/misc/level.ts
|
|
1205
1224
|
var Level = Symbol("Api level refs");
|
|
1206
1225
|
function setLevelRef(config, level) {
|
|
1207
|
-
var
|
|
1208
|
-
(
|
|
1226
|
+
var _a3;
|
|
1227
|
+
(_a3 = config[Level]) != null ? _a3 : config[Level] = {};
|
|
1209
1228
|
config[Level][level] = {};
|
|
1210
1229
|
}
|
|
1211
1230
|
function getLevelRef(config, level) {
|
|
1212
|
-
var
|
|
1213
|
-
return (
|
|
1231
|
+
var _a3;
|
|
1232
|
+
return (_a3 = config[Level]) == null ? void 0 : _a3[level];
|
|
1214
1233
|
}
|
|
1215
1234
|
|
|
1216
1235
|
// src/utils/misc/wait.ts
|
|
@@ -1218,9 +1237,6 @@ function wait(time) {
|
|
|
1218
1237
|
return new Promise((resolve) => setTimeout(() => resolve(), time));
|
|
1219
1238
|
}
|
|
1220
1239
|
|
|
1221
|
-
// src/utils/pointer/cssPointerEvents.ts
|
|
1222
|
-
import { getWindowFromNode as getWindowFromNode2 } from "@testing-library/dom/dist/helpers.js";
|
|
1223
|
-
|
|
1224
1240
|
// src/keyboard/keyMap.ts
|
|
1225
1241
|
var defaultKeyMap = [
|
|
1226
1242
|
..."0123456789".split("").map((c) => ({ code: `Digit${c}`, key: c })),
|
|
@@ -1314,7 +1330,7 @@ var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect)
|
|
|
1314
1330
|
|
|
1315
1331
|
// src/utils/pointer/cssPointerEvents.ts
|
|
1316
1332
|
function hasPointerEvents(element) {
|
|
1317
|
-
const window2 =
|
|
1333
|
+
const window2 = getWindow(element);
|
|
1318
1334
|
for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
1319
1335
|
const pointerEvents = window2.getComputedStyle(el).pointerEvents;
|
|
1320
1336
|
if (pointerEvents && !["inherit", "unset"].includes(pointerEvents)) {
|
|
@@ -1428,9 +1444,9 @@ function assignPositionInit(obj, {
|
|
|
1428
1444
|
screenX,
|
|
1429
1445
|
screenY
|
|
1430
1446
|
}) {
|
|
1431
|
-
var
|
|
1447
|
+
var _a3, _b, _c, _d;
|
|
1432
1448
|
assignProps(obj, {
|
|
1433
|
-
x: (
|
|
1449
|
+
x: (_a3 = x != null ? x : clientX) != null ? _a3 : 0,
|
|
1434
1450
|
y: (_b = y != null ? y : clientY) != null ? _b : 0,
|
|
1435
1451
|
clientX: (_c = x != null ? x : clientX) != null ? _c : 0,
|
|
1436
1452
|
clientY: (_d = y != null ? y : clientY) != null ? _d : 0,
|
|
@@ -1467,7 +1483,7 @@ behavior.click = (event, target, config) => {
|
|
|
1467
1483
|
} else if (isElementType(target, "input", { type: "file" })) {
|
|
1468
1484
|
return () => {
|
|
1469
1485
|
blur(target);
|
|
1470
|
-
target.dispatchEvent(new Event("fileDialog"));
|
|
1486
|
+
target.dispatchEvent(new (getWindow(target)).Event("fileDialog"));
|
|
1471
1487
|
focus(target);
|
|
1472
1488
|
};
|
|
1473
1489
|
}
|
|
@@ -1484,8 +1500,8 @@ behavior.cut = (event, target, config) => {
|
|
|
1484
1500
|
|
|
1485
1501
|
// src/event/behavior/keydown.ts
|
|
1486
1502
|
behavior.keydown = (event, target, config) => {
|
|
1487
|
-
var
|
|
1488
|
-
return (_b = (
|
|
1503
|
+
var _a3, _b;
|
|
1504
|
+
return (_b = (_a3 = keydownBehavior[event.key]) == null ? void 0 : _a3.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(event, target, config);
|
|
1489
1505
|
};
|
|
1490
1506
|
var keydownBehavior = {
|
|
1491
1507
|
ArrowLeft: (event, target) => () => moveSelection(target, -1),
|
|
@@ -1507,8 +1523,8 @@ var keydownBehavior = {
|
|
|
1507
1523
|
End: (event, target) => {
|
|
1508
1524
|
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1509
1525
|
return () => {
|
|
1510
|
-
var
|
|
1511
|
-
const newPos = (_b = (
|
|
1526
|
+
var _a3, _b;
|
|
1527
|
+
const newPos = (_b = (_a3 = getValue(target)) == null ? void 0 : _a3.length) != null ? _b : 0;
|
|
1512
1528
|
setSelectionRange(target, newPos, newPos);
|
|
1513
1529
|
};
|
|
1514
1530
|
}
|
|
@@ -1600,8 +1616,8 @@ var SubmitSingleInputOnEnter = [
|
|
|
1600
1616
|
|
|
1601
1617
|
// src/event/behavior/keyup.ts
|
|
1602
1618
|
behavior.keyup = (event, target, config) => {
|
|
1603
|
-
var
|
|
1604
|
-
return (
|
|
1619
|
+
var _a3;
|
|
1620
|
+
return (_a3 = keyupBehavior[event.key]) == null ? void 0 : _a3.call(keyupBehavior, event, target, config);
|
|
1605
1621
|
};
|
|
1606
1622
|
var keyupBehavior = {
|
|
1607
1623
|
" ": (event, target, config) => {
|
|
@@ -1615,8 +1631,8 @@ var keyupBehavior = {
|
|
|
1615
1631
|
behavior.paste = (event, target, config) => {
|
|
1616
1632
|
if (isEditable(target)) {
|
|
1617
1633
|
return () => {
|
|
1618
|
-
var
|
|
1619
|
-
const insertData = (
|
|
1634
|
+
var _a3;
|
|
1635
|
+
const insertData = (_a3 = event.clipboardData) == null ? void 0 : _a3.getData("text");
|
|
1620
1636
|
if (insertData) {
|
|
1621
1637
|
input(config, target, insertData, "insertFromPaste");
|
|
1622
1638
|
}
|
|
@@ -1632,10 +1648,10 @@ function wrapEvent(cb, _element) {
|
|
|
1632
1648
|
|
|
1633
1649
|
// src/event/dispatchEvent.ts
|
|
1634
1650
|
function dispatchEvent(config, target, event, preventDefault = false) {
|
|
1635
|
-
var
|
|
1651
|
+
var _a3, _b;
|
|
1636
1652
|
const type3 = event.type;
|
|
1637
1653
|
const behaviorImplementation = preventDefault ? () => {
|
|
1638
|
-
} : (_b = (
|
|
1654
|
+
} : (_b = (_a3 = behavior)[type3]) == null ? void 0 : _b.call(_a3, event, target, config);
|
|
1639
1655
|
if (behaviorImplementation) {
|
|
1640
1656
|
event.preventDefault();
|
|
1641
1657
|
let defaultPrevented = false;
|
|
@@ -1739,9 +1755,9 @@ function setUISelection(element, {
|
|
|
1739
1755
|
}
|
|
1740
1756
|
}
|
|
1741
1757
|
function getUISelection(element) {
|
|
1742
|
-
var
|
|
1758
|
+
var _a3, _b, _c;
|
|
1743
1759
|
const sel = (_c = element[UISelection]) != null ? _c : {
|
|
1744
|
-
anchorOffset: (
|
|
1760
|
+
anchorOffset: (_a3 = element.selectionStart) != null ? _a3 : 0,
|
|
1745
1761
|
focusOffset: (_b = element.selectionEnd) != null ? _b : 0
|
|
1746
1762
|
};
|
|
1747
1763
|
return __spreadProps(__spreadValues({}, sel), {
|
|
@@ -1801,8 +1817,8 @@ function startTrackValue(element) {
|
|
|
1801
1817
|
});
|
|
1802
1818
|
}
|
|
1803
1819
|
function trackOrSetValue(element, v) {
|
|
1804
|
-
var
|
|
1805
|
-
(_b = (
|
|
1820
|
+
var _a3, _b, _c;
|
|
1821
|
+
(_b = (_a3 = element[TrackChanges]) == null ? void 0 : _a3.tracked) == null ? void 0 : _b.push(v);
|
|
1806
1822
|
if (!((_c = element[TrackChanges]) == null ? void 0 : _c.tracked)) {
|
|
1807
1823
|
setCleanValue(element, v);
|
|
1808
1824
|
}
|
|
@@ -1813,10 +1829,10 @@ function setCleanValue(element, v) {
|
|
|
1813
1829
|
setUISelection(element, { focusOffset: v.length });
|
|
1814
1830
|
}
|
|
1815
1831
|
function endTrackValue(element) {
|
|
1816
|
-
var
|
|
1832
|
+
var _a3, _b;
|
|
1817
1833
|
const changes = element[TrackChanges];
|
|
1818
1834
|
element[TrackChanges] = void 0;
|
|
1819
|
-
const isJustReactStateUpdate = ((
|
|
1835
|
+
const isJustReactStateUpdate = ((_a3 = changes == null ? void 0 : changes.tracked) == null ? void 0 : _a3.length) === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === changes.nextValue;
|
|
1820
1836
|
if (((_b = changes == null ? void 0 : changes.tracked) == null ? void 0 : _b.length) && !isJustReactStateUpdate) {
|
|
1821
1837
|
setCleanValue(element, changes.tracked[changes.tracked.length - 1]);
|
|
1822
1838
|
}
|
|
@@ -1889,11 +1905,11 @@ function isModifierLock(key) {
|
|
|
1889
1905
|
return modifierLocks.includes(key);
|
|
1890
1906
|
}
|
|
1891
1907
|
function preKeydownBehavior(config, { key }, element) {
|
|
1892
|
-
var
|
|
1908
|
+
var _a3;
|
|
1893
1909
|
if (isModifierKey(key)) {
|
|
1894
1910
|
config.keyboardState.modifiers[key] = true;
|
|
1895
1911
|
if (key === "AltGraph") {
|
|
1896
|
-
const ctrlKeyDef = (
|
|
1912
|
+
const ctrlKeyDef = (_a3 = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a3 : { key: "Control", code: "Control" };
|
|
1897
1913
|
dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
|
|
1898
1914
|
}
|
|
1899
1915
|
} else if (isModifierLock(key)) {
|
|
@@ -1913,9 +1929,9 @@ function preKeyupBehavior(config, { key }) {
|
|
|
1913
1929
|
}
|
|
1914
1930
|
}
|
|
1915
1931
|
function postKeyupBehavior(config, { key }, element) {
|
|
1916
|
-
var
|
|
1932
|
+
var _a3;
|
|
1917
1933
|
if (key === "AltGraph") {
|
|
1918
|
-
const ctrlKeyDef = (
|
|
1934
|
+
const ctrlKeyDef = (_a3 = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a3 : { key: "Control", code: "Control" };
|
|
1919
1935
|
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1920
1936
|
}
|
|
1921
1937
|
}
|
|
@@ -1957,8 +1973,8 @@ function keyboardKeyAction(_0, _1) {
|
|
|
1957
1973
|
});
|
|
1958
1974
|
}
|
|
1959
1975
|
function getActive(document2) {
|
|
1960
|
-
var
|
|
1961
|
-
return (
|
|
1976
|
+
var _a3;
|
|
1977
|
+
return (_a3 = getActiveElement(document2)) != null ? _a3 : document2.body;
|
|
1962
1978
|
}
|
|
1963
1979
|
function releaseAllKeys(config) {
|
|
1964
1980
|
return __async(this, null, function* () {
|
|
@@ -2000,13 +2016,13 @@ function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
|
2000
2016
|
});
|
|
2001
2017
|
}
|
|
2002
2018
|
function hasKeyPress(keyDef, config) {
|
|
2003
|
-
var
|
|
2004
|
-
return (((
|
|
2019
|
+
var _a3;
|
|
2020
|
+
return (((_a3 = keyDef.key) == null ? void 0 : _a3.length) === 1 || keyDef.key === "Enter") && !config.keyboardState.modifiers.Control && !config.keyboardState.modifiers.Alt;
|
|
2005
2021
|
}
|
|
2006
2022
|
|
|
2007
2023
|
// src/keyboard/parseKeyDef.ts
|
|
2008
2024
|
function parseKeyDef(keyboardMap, text) {
|
|
2009
|
-
var
|
|
2025
|
+
var _a3;
|
|
2010
2026
|
const defs = [];
|
|
2011
2027
|
do {
|
|
2012
2028
|
const {
|
|
@@ -2017,15 +2033,15 @@ function parseKeyDef(keyboardMap, text) {
|
|
|
2017
2033
|
releaseSelf = true,
|
|
2018
2034
|
repeat
|
|
2019
2035
|
} = readNextDescriptor(text, "keyboard");
|
|
2020
|
-
const keyDef = (
|
|
2021
|
-
var
|
|
2036
|
+
const keyDef = (_a3 = keyboardMap.find((def) => {
|
|
2037
|
+
var _a4, _b;
|
|
2022
2038
|
if (type3 === "[") {
|
|
2023
|
-
return ((
|
|
2039
|
+
return ((_a4 = def.code) == null ? void 0 : _a4.toLowerCase()) === descriptor.toLowerCase();
|
|
2024
2040
|
} else if (type3 === "{") {
|
|
2025
2041
|
return ((_b = def.key) == null ? void 0 : _b.toLowerCase()) === descriptor.toLowerCase();
|
|
2026
2042
|
}
|
|
2027
2043
|
return def.key === descriptor;
|
|
2028
|
-
})) != null ?
|
|
2044
|
+
})) != null ? _a3 : {
|
|
2029
2045
|
key: "Unknown",
|
|
2030
2046
|
code: "Unknown",
|
|
2031
2047
|
[type3 === "[" ? "code" : "key"]: descriptor
|
|
@@ -2104,8 +2120,8 @@ function firePointerEvent(config, target, type3, {
|
|
|
2104
2120
|
}
|
|
2105
2121
|
init.button = getMouseButton(button != null ? button : 0);
|
|
2106
2122
|
init.buttons = getMouseButtons(...config.pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
|
|
2107
|
-
var
|
|
2108
|
-
return (
|
|
2123
|
+
var _a3;
|
|
2124
|
+
return (_a3 = p.keyDef.button) != null ? _a3 : 0;
|
|
2109
2125
|
}));
|
|
2110
2126
|
if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
|
|
2111
2127
|
init.detail = clickCount;
|
|
@@ -2267,7 +2283,7 @@ function getNextPointerId(state) {
|
|
|
2267
2283
|
return state.pointerId;
|
|
2268
2284
|
}
|
|
2269
2285
|
function down(config, pointerName, { keyDef, node, offset, target, coords }, targetIsDisabled) {
|
|
2270
|
-
var
|
|
2286
|
+
var _a3, _b, _c;
|
|
2271
2287
|
setLevelRef(config, 2 /* Trigger */);
|
|
2272
2288
|
assertPointerEvents(config, target);
|
|
2273
2289
|
const { pointerState } = config;
|
|
@@ -2290,7 +2306,7 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
|
|
|
2290
2306
|
}
|
|
2291
2307
|
}
|
|
2292
2308
|
}
|
|
2293
|
-
if (((
|
|
2309
|
+
if (((_a3 = pointerState.activeClickCount) == null ? void 0 : _a3[0]) !== name) {
|
|
2294
2310
|
delete pointerState.activeClickCount;
|
|
2295
2311
|
}
|
|
2296
2312
|
const clickCount = Number((_c = (_b = pointerState.activeClickCount) == null ? void 0 : _b[1]) != null ? _c : 0) + 1;
|
|
@@ -2444,7 +2460,7 @@ function mousedownDefaultBehavior({
|
|
|
2444
2460
|
node,
|
|
2445
2461
|
offset: end
|
|
2446
2462
|
});
|
|
2447
|
-
const range =
|
|
2463
|
+
const range = target.ownerDocument.createRange();
|
|
2448
2464
|
range.setStart(startNode, startOffset);
|
|
2449
2465
|
range.setEnd(endNode, endOffset);
|
|
2450
2466
|
position.selectionRange = range;
|
|
@@ -2474,11 +2490,11 @@ function getTextRange(text, pos, clickCount) {
|
|
|
2474
2490
|
// src/pointer/pointerAction.ts
|
|
2475
2491
|
function pointerAction(config, actions) {
|
|
2476
2492
|
return __async(this, null, function* () {
|
|
2477
|
-
var
|
|
2493
|
+
var _a3, _b;
|
|
2478
2494
|
for (let i = 0; i < actions.length; i++) {
|
|
2479
2495
|
const action = actions[i];
|
|
2480
2496
|
const pointerName = "pointerName" in action && action.pointerName ? action.pointerName : "keyDef" in action ? action.keyDef.pointerType === "touch" ? action.keyDef.name : action.keyDef.pointerType : "mouse";
|
|
2481
|
-
const target = (
|
|
2497
|
+
const target = (_a3 = action.target) != null ? _a3 : getPrevTarget(pointerName, config.pointerState);
|
|
2482
2498
|
const coords = (_b = action.coords) != null ? _b : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : void 0;
|
|
2483
2499
|
yield "keyDef" in action ? pointerPress(config, __spreadProps(__spreadValues({}, action), { target, coords })) : pointerMove(config, __spreadProps(__spreadValues({}, action), { target, coords }));
|
|
2484
2500
|
if (typeof config.delay === "number") {
|
|
@@ -2608,9 +2624,9 @@ function tab() {
|
|
|
2608
2624
|
// src/clipboard/copy.ts
|
|
2609
2625
|
function copy() {
|
|
2610
2626
|
return __async(this, null, function* () {
|
|
2611
|
-
var
|
|
2627
|
+
var _a3;
|
|
2612
2628
|
const doc = this[Config].document;
|
|
2613
|
-
const target = (
|
|
2629
|
+
const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
|
|
2614
2630
|
const clipboardData = copySelection(target);
|
|
2615
2631
|
if (clipboardData.items.length === 0) {
|
|
2616
2632
|
return;
|
|
@@ -2627,9 +2643,9 @@ function copy() {
|
|
|
2627
2643
|
// src/clipboard/cut.ts
|
|
2628
2644
|
function cut() {
|
|
2629
2645
|
return __async(this, null, function* () {
|
|
2630
|
-
var
|
|
2646
|
+
var _a3;
|
|
2631
2647
|
const doc = this[Config].document;
|
|
2632
|
-
const target = (
|
|
2648
|
+
const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
|
|
2633
2649
|
const clipboardData = copySelection(target);
|
|
2634
2650
|
if (clipboardData.items.length === 0) {
|
|
2635
2651
|
return;
|
|
@@ -2646,10 +2662,10 @@ function cut() {
|
|
|
2646
2662
|
// src/clipboard/paste.ts
|
|
2647
2663
|
function paste(clipboardData) {
|
|
2648
2664
|
return __async(this, null, function* () {
|
|
2649
|
-
var
|
|
2665
|
+
var _a3, _b;
|
|
2650
2666
|
const doc = this[Config].document;
|
|
2651
|
-
const target = (
|
|
2652
|
-
const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _b : yield readDataTransferFromClipboard(doc).catch(() => {
|
|
2667
|
+
const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
|
|
2668
|
+
const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(doc, clipboardData) : clipboardData) != null ? _b : yield readDataTransferFromClipboard(doc).catch(() => {
|
|
2653
2669
|
throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
|
|
2654
2670
|
});
|
|
2655
2671
|
this.dispatchUIEvent(target, "paste", {
|
|
@@ -2657,8 +2673,8 @@ function paste(clipboardData) {
|
|
|
2657
2673
|
});
|
|
2658
2674
|
});
|
|
2659
2675
|
}
|
|
2660
|
-
function getClipboardDataFromString(text) {
|
|
2661
|
-
const dt = createDataTransfer();
|
|
2676
|
+
function getClipboardDataFromString(doc, text) {
|
|
2677
|
+
const dt = createDataTransfer(getWindow(doc));
|
|
2662
2678
|
dt.setData("text", text);
|
|
2663
2679
|
return dt;
|
|
2664
2680
|
}
|
|
@@ -2812,10 +2828,10 @@ function upload(element, fileOrFiles) {
|
|
|
2812
2828
|
return;
|
|
2813
2829
|
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input2.accept)).slice(0, input2.multiple ? void 0 : 1);
|
|
2814
2830
|
const fileDialog = () => {
|
|
2815
|
-
var
|
|
2816
|
-
if (files.length === ((
|
|
2817
|
-
var
|
|
2818
|
-
return f === ((
|
|
2831
|
+
var _a3;
|
|
2832
|
+
if (files.length === ((_a3 = input2.files) == null ? void 0 : _a3.length) && files.every((f, i) => {
|
|
2833
|
+
var _a4;
|
|
2834
|
+
return f === ((_a4 = input2.files) == null ? void 0 : _a4.item(i));
|
|
2819
2835
|
})) {
|
|
2820
2836
|
return;
|
|
2821
2837
|
}
|
|
@@ -2863,10 +2879,10 @@ function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
|
|
|
2863
2879
|
});
|
|
2864
2880
|
}
|
|
2865
2881
|
function setupMain(options = {}) {
|
|
2866
|
-
var
|
|
2882
|
+
var _a3;
|
|
2867
2883
|
const config = createConfig(options);
|
|
2868
2884
|
prepareDocument(config.document);
|
|
2869
|
-
const view = (
|
|
2885
|
+
const view = (_a3 = config.document.defaultView) != null ? _a3 : window;
|
|
2870
2886
|
attachClipboardStubToView(view);
|
|
2871
2887
|
return doSetup(config);
|
|
2872
2888
|
}
|
|
@@ -2902,8 +2918,8 @@ function doSetup(config) {
|
|
|
2902
2918
|
});
|
|
2903
2919
|
}
|
|
2904
2920
|
function getDocument(options, node) {
|
|
2905
|
-
var
|
|
2906
|
-
return (_b = (
|
|
2921
|
+
var _a3, _b;
|
|
2922
|
+
return (_b = (_a3 = options.document) != null ? _a3 : node && getDocumentFromNode(node)) != null ? _b : document;
|
|
2907
2923
|
}
|
|
2908
2924
|
|
|
2909
2925
|
// src/setup/directApi.ts
|