@testing-library/user-event 14.0.0 → 14.0.3
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 +172 -135
- package/dist/index.mjs +172 -135
- package/dist/types/document/selection.d.ts +0 -1
- package/dist/types/document/value.d.ts +9 -2
- 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) {
|
|
@@ -527,11 +547,11 @@ function editInputElement(config, element, inputRange, data, inputType) {
|
|
|
527
547
|
});
|
|
528
548
|
if (isDateOrTime(element)) {
|
|
529
549
|
if (isValidDateOrTimeValue(element, newValue)) {
|
|
530
|
-
commitInput(config, element,
|
|
550
|
+
commitInput(config, element, newOffset, {});
|
|
531
551
|
dispatchUIEvent(config, element, "change");
|
|
532
552
|
}
|
|
533
553
|
} else {
|
|
534
|
-
commitInput(config, element,
|
|
554
|
+
commitInput(config, element, newOffset, {
|
|
535
555
|
data,
|
|
536
556
|
inputType
|
|
537
557
|
});
|
|
@@ -561,11 +581,10 @@ function calculateNewValue(inputData, node, {
|
|
|
561
581
|
newOffset
|
|
562
582
|
};
|
|
563
583
|
}
|
|
564
|
-
function commitInput(config, element,
|
|
584
|
+
function commitInput(config, element, newOffset, inputInit) {
|
|
565
585
|
startTrackValue(element);
|
|
566
586
|
dispatchUIEvent(config, element, "input", inputInit);
|
|
567
|
-
|
|
568
|
-
if ((tracked == null ? void 0 : tracked.length) === 2 && tracked[0] === oldValue && tracked[1] === newValue) {
|
|
587
|
+
if (endTrackValue(element)) {
|
|
569
588
|
setSelection({
|
|
570
589
|
focusNode: element,
|
|
571
590
|
anchorOffset: newOffset,
|
|
@@ -574,9 +593,9 @@ function commitInput(config, element, oldValue, newValue, newOffset, inputInit)
|
|
|
574
593
|
}
|
|
575
594
|
}
|
|
576
595
|
function isValidNumberInput(value) {
|
|
577
|
-
var
|
|
596
|
+
var _a3, _b;
|
|
578
597
|
const valueParts = value.split("e", 2);
|
|
579
|
-
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]));
|
|
580
599
|
}
|
|
581
600
|
|
|
582
601
|
// src/utils/edit/isEditable.ts
|
|
@@ -605,8 +624,8 @@ function isEditableInput(element) {
|
|
|
605
624
|
// src/utils/edit/setFiles.ts
|
|
606
625
|
var fakeFiles = Symbol("files and value properties are mocked");
|
|
607
626
|
function setFiles(el, files) {
|
|
608
|
-
var
|
|
609
|
-
(
|
|
627
|
+
var _a3;
|
|
628
|
+
(_a3 = el[fakeFiles]) == null ? void 0 : _a3.restore();
|
|
610
629
|
const objectDescriptors = Object.getOwnPropertyDescriptors(el);
|
|
611
630
|
const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
|
|
612
631
|
function restore() {
|
|
@@ -624,11 +643,11 @@ function setFiles(el, files) {
|
|
|
624
643
|
value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
|
|
625
644
|
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
626
645
|
set(v) {
|
|
627
|
-
var
|
|
646
|
+
var _a4;
|
|
628
647
|
if (v === "") {
|
|
629
648
|
restore();
|
|
630
649
|
} else {
|
|
631
|
-
(
|
|
650
|
+
(_a4 = objectDescriptors.value.set) == null ? void 0 : _a4.call(el, v);
|
|
632
651
|
}
|
|
633
652
|
}
|
|
634
653
|
}),
|
|
@@ -655,7 +674,7 @@ function eventWrapper(cb) {
|
|
|
655
674
|
|
|
656
675
|
// src/utils/misc/isDisabled.ts
|
|
657
676
|
function isDisabled(element) {
|
|
658
|
-
var
|
|
677
|
+
var _a3;
|
|
659
678
|
for (let el = element; el; el = el.parentElement) {
|
|
660
679
|
if (isElementType(el, [
|
|
661
680
|
"button",
|
|
@@ -669,7 +688,7 @@ function isDisabled(element) {
|
|
|
669
688
|
return true;
|
|
670
689
|
}
|
|
671
690
|
} else if (isElementType(el, "fieldset")) {
|
|
672
|
-
if (el.hasAttribute("disabled") && !((
|
|
691
|
+
if (el.hasAttribute("disabled") && !((_a3 = el.querySelector(":scope > legend")) == null ? void 0 : _a3.contains(element))) {
|
|
673
692
|
return true;
|
|
674
693
|
}
|
|
675
694
|
} else if (el.tagName.includes("-")) {
|
|
@@ -802,7 +821,7 @@ function isTextNode(node) {
|
|
|
802
821
|
return node.nodeType === 3;
|
|
803
822
|
}
|
|
804
823
|
function walkNodes(node, direction, callback) {
|
|
805
|
-
var
|
|
824
|
+
var _a3;
|
|
806
825
|
for (; ; ) {
|
|
807
826
|
const sibling = node[`${direction}Sibling`];
|
|
808
827
|
if (sibling) {
|
|
@@ -810,7 +829,7 @@ function walkNodes(node, direction, callback) {
|
|
|
810
829
|
if (callback(node)) {
|
|
811
830
|
return node;
|
|
812
831
|
}
|
|
813
|
-
} 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))) {
|
|
814
833
|
node = node.parentNode;
|
|
815
834
|
} else {
|
|
816
835
|
break;
|
|
@@ -826,7 +845,7 @@ function getDescendant(node, direction) {
|
|
|
826
845
|
|
|
827
846
|
// src/utils/focus/selection.ts
|
|
828
847
|
function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
829
|
-
var
|
|
848
|
+
var _a3;
|
|
830
849
|
if (hasOwnSelection(element)) {
|
|
831
850
|
return setSelection({
|
|
832
851
|
focusNode: element,
|
|
@@ -834,7 +853,7 @@ function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
|
834
853
|
focusOffset
|
|
835
854
|
});
|
|
836
855
|
}
|
|
837
|
-
if (isContentEditable(element) && ((
|
|
856
|
+
if (isContentEditable(element) && ((_a3 = element.firstChild) == null ? void 0 : _a3.nodeType) === 3) {
|
|
838
857
|
return setSelection({
|
|
839
858
|
focusNode: element.firstChild,
|
|
840
859
|
anchorOffset,
|
|
@@ -868,7 +887,7 @@ function getElement2(node) {
|
|
|
868
887
|
return node.nodeType === 1 ? node : node.parentElement;
|
|
869
888
|
}
|
|
870
889
|
function updateSelectionOnFocus(element) {
|
|
871
|
-
var
|
|
890
|
+
var _a3;
|
|
872
891
|
const selection = element.ownerDocument.getSelection();
|
|
873
892
|
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
874
893
|
return;
|
|
@@ -877,7 +896,7 @@ function updateSelectionOnFocus(element) {
|
|
|
877
896
|
const contenteditable = getContentEditable(selection.focusNode);
|
|
878
897
|
if (contenteditable) {
|
|
879
898
|
if (!selection.isCollapsed) {
|
|
880
|
-
const focusNode = ((
|
|
899
|
+
const focusNode = ((_a3 = contenteditable.firstChild) == null ? void 0 : _a3.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
881
900
|
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
882
901
|
}
|
|
883
902
|
} else {
|
|
@@ -886,12 +905,12 @@ function updateSelectionOnFocus(element) {
|
|
|
886
905
|
}
|
|
887
906
|
}
|
|
888
907
|
function getInputRange(focusNode) {
|
|
889
|
-
var
|
|
908
|
+
var _a3;
|
|
890
909
|
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
891
910
|
if (typeAndSelection.type === "input") {
|
|
892
911
|
return typeAndSelection.selection;
|
|
893
912
|
} else if (typeAndSelection.type === "contenteditable") {
|
|
894
|
-
return (
|
|
913
|
+
return (_a3 = typeAndSelection.selection) == null ? void 0 : _a3.getRangeAt(0);
|
|
895
914
|
}
|
|
896
915
|
}
|
|
897
916
|
function setSelection({
|
|
@@ -900,7 +919,7 @@ function setSelection({
|
|
|
900
919
|
anchorNode = focusNode,
|
|
901
920
|
anchorOffset = focusOffset
|
|
902
921
|
}) {
|
|
903
|
-
var
|
|
922
|
+
var _a3, _b;
|
|
904
923
|
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
905
924
|
if (typeAndSelection.type === "input") {
|
|
906
925
|
return setUISelection(focusNode, {
|
|
@@ -908,7 +927,7 @@ function setSelection({
|
|
|
908
927
|
focusOffset
|
|
909
928
|
});
|
|
910
929
|
}
|
|
911
|
-
(_b = (
|
|
930
|
+
(_b = (_a3 = anchorNode.ownerDocument) == null ? void 0 : _a3.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
912
931
|
}
|
|
913
932
|
function moveSelection(node, direction) {
|
|
914
933
|
if (hasOwnSelection(node)) {
|
|
@@ -939,7 +958,7 @@ function moveSelection(node, direction) {
|
|
|
939
958
|
// src/utils/focus/copySelection.ts
|
|
940
959
|
function copySelection(target) {
|
|
941
960
|
const data = hasOwnSelection(target) ? { "text/plain": readSelectedValueFromInput(target) } : { "text/plain": String(target.ownerDocument.getSelection()) };
|
|
942
|
-
const dt = createDataTransfer();
|
|
961
|
+
const dt = createDataTransfer(getWindow(target));
|
|
943
962
|
for (const type3 in data) {
|
|
944
963
|
if (data[type3]) {
|
|
945
964
|
dt.setData(type3, data[type3]);
|
|
@@ -980,9 +999,8 @@ function focus(element) {
|
|
|
980
999
|
}
|
|
981
1000
|
|
|
982
1001
|
// src/utils/misc/isVisible.ts
|
|
983
|
-
import { getWindowFromNode } from "@testing-library/dom/dist/helpers.js";
|
|
984
1002
|
function isVisible(element) {
|
|
985
|
-
const window2 =
|
|
1003
|
+
const window2 = getWindow(element);
|
|
986
1004
|
for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
987
1005
|
const { display, visibility } = window2.getComputedStyle(el);
|
|
988
1006
|
if (display === "none") {
|
|
@@ -1048,7 +1066,7 @@ function getTabDestination(activeElement, shift) {
|
|
|
1048
1066
|
|
|
1049
1067
|
// src/utils/focus/selectAll.ts
|
|
1050
1068
|
function selectAll(target) {
|
|
1051
|
-
var
|
|
1069
|
+
var _a3;
|
|
1052
1070
|
if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
|
|
1053
1071
|
return setSelection({
|
|
1054
1072
|
focusNode: target,
|
|
@@ -1056,7 +1074,7 @@ function selectAll(target) {
|
|
|
1056
1074
|
focusOffset: getUIValue(target).length
|
|
1057
1075
|
});
|
|
1058
1076
|
}
|
|
1059
|
-
const focusNode = (
|
|
1077
|
+
const focusNode = (_a3 = getContentEditable(target)) != null ? _a3 : target.ownerDocument.body;
|
|
1060
1078
|
setSelection({
|
|
1061
1079
|
focusNode,
|
|
1062
1080
|
anchorOffset: 0,
|
|
@@ -1064,11 +1082,11 @@ function selectAll(target) {
|
|
|
1064
1082
|
});
|
|
1065
1083
|
}
|
|
1066
1084
|
function isAllSelected(target) {
|
|
1067
|
-
var
|
|
1085
|
+
var _a3;
|
|
1068
1086
|
if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
|
|
1069
1087
|
return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
|
|
1070
1088
|
}
|
|
1071
|
-
const focusNode = (
|
|
1089
|
+
const focusNode = (_a3 = getContentEditable(target)) != null ? _a3 : target.ownerDocument.body;
|
|
1072
1090
|
const selection = target.ownerDocument.getSelection();
|
|
1073
1091
|
return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
1074
1092
|
}
|
|
@@ -1128,12 +1146,12 @@ function readPrintableChar(text, pos, context) {
|
|
|
1128
1146
|
};
|
|
1129
1147
|
}
|
|
1130
1148
|
function readTag(text, pos, startBracket, context) {
|
|
1131
|
-
var
|
|
1149
|
+
var _a3, _b, _c;
|
|
1132
1150
|
const releasePreviousModifier = text[pos] === "/" ? "/" : "";
|
|
1133
1151
|
pos += releasePreviousModifier.length;
|
|
1134
1152
|
const escapedDescriptor = startBracket === "{" && text[pos] === "\\";
|
|
1135
1153
|
pos += Number(escapedDescriptor);
|
|
1136
|
-
const descriptor = escapedDescriptor ? text[pos] : (
|
|
1154
|
+
const descriptor = escapedDescriptor ? text[pos] : (_a3 = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a3[0];
|
|
1137
1155
|
assertDescriptor(descriptor, text, pos, context);
|
|
1138
1156
|
pos += descriptor.length;
|
|
1139
1157
|
const repeatModifier = (_c = (_b = text.slice(pos).match(/^>\d+/)) == null ? void 0 : _b[0]) != null ? _c : "";
|
|
@@ -1205,13 +1223,13 @@ function isDescendantOrSelf(potentialDescendant, potentialAncestor) {
|
|
|
1205
1223
|
// src/utils/misc/level.ts
|
|
1206
1224
|
var Level = Symbol("Api level refs");
|
|
1207
1225
|
function setLevelRef(config, level) {
|
|
1208
|
-
var
|
|
1209
|
-
(
|
|
1226
|
+
var _a3;
|
|
1227
|
+
(_a3 = config[Level]) != null ? _a3 : config[Level] = {};
|
|
1210
1228
|
config[Level][level] = {};
|
|
1211
1229
|
}
|
|
1212
1230
|
function getLevelRef(config, level) {
|
|
1213
|
-
var
|
|
1214
|
-
return (
|
|
1231
|
+
var _a3;
|
|
1232
|
+
return (_a3 = config[Level]) == null ? void 0 : _a3[level];
|
|
1215
1233
|
}
|
|
1216
1234
|
|
|
1217
1235
|
// src/utils/misc/wait.ts
|
|
@@ -1219,9 +1237,6 @@ function wait(time) {
|
|
|
1219
1237
|
return new Promise((resolve) => setTimeout(() => resolve(), time));
|
|
1220
1238
|
}
|
|
1221
1239
|
|
|
1222
|
-
// src/utils/pointer/cssPointerEvents.ts
|
|
1223
|
-
import { getWindowFromNode as getWindowFromNode2 } from "@testing-library/dom/dist/helpers.js";
|
|
1224
|
-
|
|
1225
1240
|
// src/keyboard/keyMap.ts
|
|
1226
1241
|
var defaultKeyMap = [
|
|
1227
1242
|
..."0123456789".split("").map((c) => ({ code: `Digit${c}`, key: c })),
|
|
@@ -1315,7 +1330,7 @@ var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect)
|
|
|
1315
1330
|
|
|
1316
1331
|
// src/utils/pointer/cssPointerEvents.ts
|
|
1317
1332
|
function hasPointerEvents(element) {
|
|
1318
|
-
const window2 =
|
|
1333
|
+
const window2 = getWindow(element);
|
|
1319
1334
|
for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
1320
1335
|
const pointerEvents = window2.getComputedStyle(el).pointerEvents;
|
|
1321
1336
|
if (pointerEvents && !["inherit", "unset"].includes(pointerEvents)) {
|
|
@@ -1429,9 +1444,9 @@ function assignPositionInit(obj, {
|
|
|
1429
1444
|
screenX,
|
|
1430
1445
|
screenY
|
|
1431
1446
|
}) {
|
|
1432
|
-
var
|
|
1447
|
+
var _a3, _b, _c, _d;
|
|
1433
1448
|
assignProps(obj, {
|
|
1434
|
-
x: (
|
|
1449
|
+
x: (_a3 = x != null ? x : clientX) != null ? _a3 : 0,
|
|
1435
1450
|
y: (_b = y != null ? y : clientY) != null ? _b : 0,
|
|
1436
1451
|
clientX: (_c = x != null ? x : clientX) != null ? _c : 0,
|
|
1437
1452
|
clientY: (_d = y != null ? y : clientY) != null ? _d : 0,
|
|
@@ -1456,7 +1471,7 @@ var behavior = {};
|
|
|
1456
1471
|
|
|
1457
1472
|
// src/event/behavior/click.ts
|
|
1458
1473
|
behavior.click = (event, target, config) => {
|
|
1459
|
-
const context = target.closest("button,input,label,textarea");
|
|
1474
|
+
const context = target.closest("button,input,label,select,textarea");
|
|
1460
1475
|
const control = context && isElementType(context, "label") && context.control;
|
|
1461
1476
|
if (control) {
|
|
1462
1477
|
return () => {
|
|
@@ -1468,7 +1483,7 @@ behavior.click = (event, target, config) => {
|
|
|
1468
1483
|
} else if (isElementType(target, "input", { type: "file" })) {
|
|
1469
1484
|
return () => {
|
|
1470
1485
|
blur(target);
|
|
1471
|
-
target.dispatchEvent(new Event("fileDialog"));
|
|
1486
|
+
target.dispatchEvent(new (getWindow(target)).Event("fileDialog"));
|
|
1472
1487
|
focus(target);
|
|
1473
1488
|
};
|
|
1474
1489
|
}
|
|
@@ -1485,8 +1500,8 @@ behavior.cut = (event, target, config) => {
|
|
|
1485
1500
|
|
|
1486
1501
|
// src/event/behavior/keydown.ts
|
|
1487
1502
|
behavior.keydown = (event, target, config) => {
|
|
1488
|
-
var
|
|
1489
|
-
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);
|
|
1490
1505
|
};
|
|
1491
1506
|
var keydownBehavior = {
|
|
1492
1507
|
ArrowLeft: (event, target) => () => moveSelection(target, -1),
|
|
@@ -1508,8 +1523,8 @@ var keydownBehavior = {
|
|
|
1508
1523
|
End: (event, target) => {
|
|
1509
1524
|
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1510
1525
|
return () => {
|
|
1511
|
-
var
|
|
1512
|
-
const newPos = (_b = (
|
|
1526
|
+
var _a3, _b;
|
|
1527
|
+
const newPos = (_b = (_a3 = getValue(target)) == null ? void 0 : _a3.length) != null ? _b : 0;
|
|
1513
1528
|
setSelectionRange(target, newPos, newPos);
|
|
1514
1529
|
};
|
|
1515
1530
|
}
|
|
@@ -1601,8 +1616,8 @@ var SubmitSingleInputOnEnter = [
|
|
|
1601
1616
|
|
|
1602
1617
|
// src/event/behavior/keyup.ts
|
|
1603
1618
|
behavior.keyup = (event, target, config) => {
|
|
1604
|
-
var
|
|
1605
|
-
return (
|
|
1619
|
+
var _a3;
|
|
1620
|
+
return (_a3 = keyupBehavior[event.key]) == null ? void 0 : _a3.call(keyupBehavior, event, target, config);
|
|
1606
1621
|
};
|
|
1607
1622
|
var keyupBehavior = {
|
|
1608
1623
|
" ": (event, target, config) => {
|
|
@@ -1616,8 +1631,8 @@ var keyupBehavior = {
|
|
|
1616
1631
|
behavior.paste = (event, target, config) => {
|
|
1617
1632
|
if (isEditable(target)) {
|
|
1618
1633
|
return () => {
|
|
1619
|
-
var
|
|
1620
|
-
const insertData = (
|
|
1634
|
+
var _a3;
|
|
1635
|
+
const insertData = (_a3 = event.clipboardData) == null ? void 0 : _a3.getData("text");
|
|
1621
1636
|
if (insertData) {
|
|
1622
1637
|
input(config, target, insertData, "insertFromPaste");
|
|
1623
1638
|
}
|
|
@@ -1633,10 +1648,10 @@ function wrapEvent(cb, _element) {
|
|
|
1633
1648
|
|
|
1634
1649
|
// src/event/dispatchEvent.ts
|
|
1635
1650
|
function dispatchEvent(config, target, event, preventDefault = false) {
|
|
1636
|
-
var
|
|
1651
|
+
var _a3, _b;
|
|
1637
1652
|
const type3 = event.type;
|
|
1638
1653
|
const behaviorImplementation = preventDefault ? () => {
|
|
1639
|
-
} : (_b = (
|
|
1654
|
+
} : (_b = (_a3 = behavior)[type3]) == null ? void 0 : _b.call(_a3, event, target, config);
|
|
1640
1655
|
if (behaviorImplementation) {
|
|
1641
1656
|
event.preventDefault();
|
|
1642
1657
|
let defaultPrevented = false;
|
|
@@ -1740,9 +1755,9 @@ function setUISelection(element, {
|
|
|
1740
1755
|
}
|
|
1741
1756
|
}
|
|
1742
1757
|
function getUISelection(element) {
|
|
1743
|
-
var
|
|
1758
|
+
var _a3, _b, _c;
|
|
1744
1759
|
const sel = (_c = element[UISelection]) != null ? _c : {
|
|
1745
|
-
anchorOffset: (
|
|
1760
|
+
anchorOffset: (_a3 = element.selectionStart) != null ? _a3 : 0,
|
|
1746
1761
|
focusOffset: (_b = element.selectionEnd) != null ? _b : 0
|
|
1747
1762
|
};
|
|
1748
1763
|
return __spreadProps(__spreadValues({}, sel), {
|
|
@@ -1750,9 +1765,6 @@ function getUISelection(element) {
|
|
|
1750
1765
|
endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
|
|
1751
1766
|
});
|
|
1752
1767
|
}
|
|
1753
|
-
function clearUISelection(element) {
|
|
1754
|
-
element[UISelection] = void 0;
|
|
1755
|
-
}
|
|
1756
1768
|
|
|
1757
1769
|
// src/document/value.ts
|
|
1758
1770
|
var UIValue = Symbol("Displayed value in UI");
|
|
@@ -1760,17 +1772,23 @@ var InitialValue = Symbol("Initial value to compare on blur");
|
|
|
1760
1772
|
var TrackChanges = Symbol("Track programmatic changes for React workaround");
|
|
1761
1773
|
function valueInterceptor(v) {
|
|
1762
1774
|
const isUI = typeof v === "object" && v[UIValue];
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1775
|
+
if (isUI) {
|
|
1776
|
+
this[UIValue] = String(v);
|
|
1777
|
+
setPreviousValue(this, String(this.value));
|
|
1778
|
+
} else {
|
|
1779
|
+
trackOrSetValue(this, String(v));
|
|
1768
1780
|
}
|
|
1769
1781
|
return {
|
|
1770
1782
|
applyNative: !!isUI,
|
|
1771
|
-
realArgs:
|
|
1783
|
+
realArgs: sanitizeValue(this, v)
|
|
1772
1784
|
};
|
|
1773
1785
|
}
|
|
1786
|
+
function sanitizeValue(element, v) {
|
|
1787
|
+
if (isElementType(element, "input", { type: "number" }) && String(v) !== "" && !Number.isNaN(Number(v))) {
|
|
1788
|
+
return String(Number(v));
|
|
1789
|
+
}
|
|
1790
|
+
return String(v);
|
|
1791
|
+
}
|
|
1774
1792
|
function prepareValueInterceptor(element) {
|
|
1775
1793
|
prepareInterceptor(element, "value", valueInterceptor);
|
|
1776
1794
|
}
|
|
@@ -1789,17 +1807,36 @@ function setInitialValue(element) {
|
|
|
1789
1807
|
function getInitialValue(element) {
|
|
1790
1808
|
return element[InitialValue];
|
|
1791
1809
|
}
|
|
1810
|
+
function setPreviousValue(element, v) {
|
|
1811
|
+
element[TrackChanges] = __spreadProps(__spreadValues({}, element[TrackChanges]), { previousValue: v });
|
|
1812
|
+
}
|
|
1792
1813
|
function startTrackValue(element) {
|
|
1793
|
-
element[TrackChanges] = []
|
|
1814
|
+
element[TrackChanges] = __spreadProps(__spreadValues({}, element[TrackChanges]), {
|
|
1815
|
+
nextValue: String(element.value),
|
|
1816
|
+
tracked: []
|
|
1817
|
+
});
|
|
1794
1818
|
}
|
|
1795
|
-
function
|
|
1796
|
-
var
|
|
1797
|
-
(
|
|
1819
|
+
function trackOrSetValue(element, v) {
|
|
1820
|
+
var _a3, _b, _c;
|
|
1821
|
+
(_b = (_a3 = element[TrackChanges]) == null ? void 0 : _a3.tracked) == null ? void 0 : _b.push(v);
|
|
1822
|
+
if (!((_c = element[TrackChanges]) == null ? void 0 : _c.tracked)) {
|
|
1823
|
+
setCleanValue(element, v);
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
function setCleanValue(element, v) {
|
|
1827
|
+
element[UIValue] = void 0;
|
|
1828
|
+
element[InitialValue] = v;
|
|
1829
|
+
setUISelection(element, { focusOffset: v.length });
|
|
1798
1830
|
}
|
|
1799
1831
|
function endTrackValue(element) {
|
|
1800
|
-
|
|
1832
|
+
var _a3, _b;
|
|
1833
|
+
const changes = element[TrackChanges];
|
|
1801
1834
|
element[TrackChanges] = void 0;
|
|
1802
|
-
|
|
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;
|
|
1836
|
+
if (((_b = changes == null ? void 0 : changes.tracked) == null ? void 0 : _b.length) && !isJustReactStateUpdate) {
|
|
1837
|
+
setCleanValue(element, changes.tracked[changes.tracked.length - 1]);
|
|
1838
|
+
}
|
|
1839
|
+
return isJustReactStateUpdate;
|
|
1803
1840
|
}
|
|
1804
1841
|
|
|
1805
1842
|
// src/document/index.ts
|
|
@@ -1868,11 +1905,11 @@ function isModifierLock(key) {
|
|
|
1868
1905
|
return modifierLocks.includes(key);
|
|
1869
1906
|
}
|
|
1870
1907
|
function preKeydownBehavior(config, { key }, element) {
|
|
1871
|
-
var
|
|
1908
|
+
var _a3;
|
|
1872
1909
|
if (isModifierKey(key)) {
|
|
1873
1910
|
config.keyboardState.modifiers[key] = true;
|
|
1874
1911
|
if (key === "AltGraph") {
|
|
1875
|
-
const ctrlKeyDef = (
|
|
1912
|
+
const ctrlKeyDef = (_a3 = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a3 : { key: "Control", code: "Control" };
|
|
1876
1913
|
dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
|
|
1877
1914
|
}
|
|
1878
1915
|
} else if (isModifierLock(key)) {
|
|
@@ -1892,9 +1929,9 @@ function preKeyupBehavior(config, { key }) {
|
|
|
1892
1929
|
}
|
|
1893
1930
|
}
|
|
1894
1931
|
function postKeyupBehavior(config, { key }, element) {
|
|
1895
|
-
var
|
|
1932
|
+
var _a3;
|
|
1896
1933
|
if (key === "AltGraph") {
|
|
1897
|
-
const ctrlKeyDef = (
|
|
1934
|
+
const ctrlKeyDef = (_a3 = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a3 : { key: "Control", code: "Control" };
|
|
1898
1935
|
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1899
1936
|
}
|
|
1900
1937
|
}
|
|
@@ -1936,8 +1973,8 @@ function keyboardKeyAction(_0, _1) {
|
|
|
1936
1973
|
});
|
|
1937
1974
|
}
|
|
1938
1975
|
function getActive(document2) {
|
|
1939
|
-
var
|
|
1940
|
-
return (
|
|
1976
|
+
var _a3;
|
|
1977
|
+
return (_a3 = getActiveElement(document2)) != null ? _a3 : document2.body;
|
|
1941
1978
|
}
|
|
1942
1979
|
function releaseAllKeys(config) {
|
|
1943
1980
|
return __async(this, null, function* () {
|
|
@@ -1979,13 +2016,13 @@ function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
|
1979
2016
|
});
|
|
1980
2017
|
}
|
|
1981
2018
|
function hasKeyPress(keyDef, config) {
|
|
1982
|
-
var
|
|
1983
|
-
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;
|
|
1984
2021
|
}
|
|
1985
2022
|
|
|
1986
2023
|
// src/keyboard/parseKeyDef.ts
|
|
1987
2024
|
function parseKeyDef(keyboardMap, text) {
|
|
1988
|
-
var
|
|
2025
|
+
var _a3;
|
|
1989
2026
|
const defs = [];
|
|
1990
2027
|
do {
|
|
1991
2028
|
const {
|
|
@@ -1996,15 +2033,15 @@ function parseKeyDef(keyboardMap, text) {
|
|
|
1996
2033
|
releaseSelf = true,
|
|
1997
2034
|
repeat
|
|
1998
2035
|
} = readNextDescriptor(text, "keyboard");
|
|
1999
|
-
const keyDef = (
|
|
2000
|
-
var
|
|
2036
|
+
const keyDef = (_a3 = keyboardMap.find((def) => {
|
|
2037
|
+
var _a4, _b;
|
|
2001
2038
|
if (type3 === "[") {
|
|
2002
|
-
return ((
|
|
2039
|
+
return ((_a4 = def.code) == null ? void 0 : _a4.toLowerCase()) === descriptor.toLowerCase();
|
|
2003
2040
|
} else if (type3 === "{") {
|
|
2004
2041
|
return ((_b = def.key) == null ? void 0 : _b.toLowerCase()) === descriptor.toLowerCase();
|
|
2005
2042
|
}
|
|
2006
2043
|
return def.key === descriptor;
|
|
2007
|
-
})) != null ?
|
|
2044
|
+
})) != null ? _a3 : {
|
|
2008
2045
|
key: "Unknown",
|
|
2009
2046
|
code: "Unknown",
|
|
2010
2047
|
[type3 === "[" ? "code" : "key"]: descriptor
|
|
@@ -2083,8 +2120,8 @@ function firePointerEvent(config, target, type3, {
|
|
|
2083
2120
|
}
|
|
2084
2121
|
init.button = getMouseButton(button != null ? button : 0);
|
|
2085
2122
|
init.buttons = getMouseButtons(...config.pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
|
|
2086
|
-
var
|
|
2087
|
-
return (
|
|
2123
|
+
var _a3;
|
|
2124
|
+
return (_a3 = p.keyDef.button) != null ? _a3 : 0;
|
|
2088
2125
|
}));
|
|
2089
2126
|
if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
|
|
2090
2127
|
init.detail = clickCount;
|
|
@@ -2246,7 +2283,7 @@ function getNextPointerId(state) {
|
|
|
2246
2283
|
return state.pointerId;
|
|
2247
2284
|
}
|
|
2248
2285
|
function down(config, pointerName, { keyDef, node, offset, target, coords }, targetIsDisabled) {
|
|
2249
|
-
var
|
|
2286
|
+
var _a3, _b, _c;
|
|
2250
2287
|
setLevelRef(config, 2 /* Trigger */);
|
|
2251
2288
|
assertPointerEvents(config, target);
|
|
2252
2289
|
const { pointerState } = config;
|
|
@@ -2269,7 +2306,7 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
|
|
|
2269
2306
|
}
|
|
2270
2307
|
}
|
|
2271
2308
|
}
|
|
2272
|
-
if (((
|
|
2309
|
+
if (((_a3 = pointerState.activeClickCount) == null ? void 0 : _a3[0]) !== name) {
|
|
2273
2310
|
delete pointerState.activeClickCount;
|
|
2274
2311
|
}
|
|
2275
2312
|
const clickCount = Number((_c = (_b = pointerState.activeClickCount) == null ? void 0 : _b[1]) != null ? _c : 0) + 1;
|
|
@@ -2397,7 +2434,6 @@ function mousedownDefaultBehavior({
|
|
|
2397
2434
|
node,
|
|
2398
2435
|
offset
|
|
2399
2436
|
}) {
|
|
2400
|
-
focus(target);
|
|
2401
2437
|
if (!targetIsDisabled) {
|
|
2402
2438
|
const hasValue = isElementType(target, ["input", "textarea"]);
|
|
2403
2439
|
const text = String(hasValue ? getUIValue(target) : target.textContent);
|
|
@@ -2423,7 +2459,7 @@ function mousedownDefaultBehavior({
|
|
|
2423
2459
|
node,
|
|
2424
2460
|
offset: end
|
|
2425
2461
|
});
|
|
2426
|
-
const range =
|
|
2462
|
+
const range = target.ownerDocument.createRange();
|
|
2427
2463
|
range.setStart(startNode, startOffset);
|
|
2428
2464
|
range.setEnd(endNode, endOffset);
|
|
2429
2465
|
position.selectionRange = range;
|
|
@@ -2432,6 +2468,7 @@ function mousedownDefaultBehavior({
|
|
|
2432
2468
|
selection.addRange(range.cloneRange());
|
|
2433
2469
|
}
|
|
2434
2470
|
}
|
|
2471
|
+
focus(target);
|
|
2435
2472
|
}
|
|
2436
2473
|
function getTextRange(text, pos, clickCount) {
|
|
2437
2474
|
if (clickCount % 3 === 1 || text.length === 0) {
|
|
@@ -2453,11 +2490,11 @@ function getTextRange(text, pos, clickCount) {
|
|
|
2453
2490
|
// src/pointer/pointerAction.ts
|
|
2454
2491
|
function pointerAction(config, actions) {
|
|
2455
2492
|
return __async(this, null, function* () {
|
|
2456
|
-
var
|
|
2493
|
+
var _a3, _b;
|
|
2457
2494
|
for (let i = 0; i < actions.length; i++) {
|
|
2458
2495
|
const action = actions[i];
|
|
2459
2496
|
const pointerName = "pointerName" in action && action.pointerName ? action.pointerName : "keyDef" in action ? action.keyDef.pointerType === "touch" ? action.keyDef.name : action.keyDef.pointerType : "mouse";
|
|
2460
|
-
const target = (
|
|
2497
|
+
const target = (_a3 = action.target) != null ? _a3 : getPrevTarget(pointerName, config.pointerState);
|
|
2461
2498
|
const coords = (_b = action.coords) != null ? _b : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : void 0;
|
|
2462
2499
|
yield "keyDef" in action ? pointerPress(config, __spreadProps(__spreadValues({}, action), { target, coords })) : pointerMove(config, __spreadProps(__spreadValues({}, action), { target, coords }));
|
|
2463
2500
|
if (typeof config.delay === "number") {
|
|
@@ -2587,9 +2624,9 @@ function tab() {
|
|
|
2587
2624
|
// src/clipboard/copy.ts
|
|
2588
2625
|
function copy() {
|
|
2589
2626
|
return __async(this, null, function* () {
|
|
2590
|
-
var
|
|
2627
|
+
var _a3;
|
|
2591
2628
|
const doc = this[Config].document;
|
|
2592
|
-
const target = (
|
|
2629
|
+
const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
|
|
2593
2630
|
const clipboardData = copySelection(target);
|
|
2594
2631
|
if (clipboardData.items.length === 0) {
|
|
2595
2632
|
return;
|
|
@@ -2606,9 +2643,9 @@ function copy() {
|
|
|
2606
2643
|
// src/clipboard/cut.ts
|
|
2607
2644
|
function cut() {
|
|
2608
2645
|
return __async(this, null, function* () {
|
|
2609
|
-
var
|
|
2646
|
+
var _a3;
|
|
2610
2647
|
const doc = this[Config].document;
|
|
2611
|
-
const target = (
|
|
2648
|
+
const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
|
|
2612
2649
|
const clipboardData = copySelection(target);
|
|
2613
2650
|
if (clipboardData.items.length === 0) {
|
|
2614
2651
|
return;
|
|
@@ -2625,10 +2662,10 @@ function cut() {
|
|
|
2625
2662
|
// src/clipboard/paste.ts
|
|
2626
2663
|
function paste(clipboardData) {
|
|
2627
2664
|
return __async(this, null, function* () {
|
|
2628
|
-
var
|
|
2665
|
+
var _a3, _b;
|
|
2629
2666
|
const doc = this[Config].document;
|
|
2630
|
-
const target = (
|
|
2631
|
-
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(() => {
|
|
2632
2669
|
throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
|
|
2633
2670
|
});
|
|
2634
2671
|
this.dispatchUIEvent(target, "paste", {
|
|
@@ -2636,8 +2673,8 @@ function paste(clipboardData) {
|
|
|
2636
2673
|
});
|
|
2637
2674
|
});
|
|
2638
2675
|
}
|
|
2639
|
-
function getClipboardDataFromString(text) {
|
|
2640
|
-
const dt = createDataTransfer();
|
|
2676
|
+
function getClipboardDataFromString(doc, text) {
|
|
2677
|
+
const dt = createDataTransfer(getWindow(doc));
|
|
2641
2678
|
dt.setData("text", text);
|
|
2642
2679
|
return dt;
|
|
2643
2680
|
}
|
|
@@ -2791,10 +2828,10 @@ function upload(element, fileOrFiles) {
|
|
|
2791
2828
|
return;
|
|
2792
2829
|
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input2.accept)).slice(0, input2.multiple ? void 0 : 1);
|
|
2793
2830
|
const fileDialog = () => {
|
|
2794
|
-
var
|
|
2795
|
-
if (files.length === ((
|
|
2796
|
-
var
|
|
2797
|
-
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));
|
|
2798
2835
|
})) {
|
|
2799
2836
|
return;
|
|
2800
2837
|
}
|
|
@@ -2842,10 +2879,10 @@ function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
|
|
|
2842
2879
|
});
|
|
2843
2880
|
}
|
|
2844
2881
|
function setupMain(options = {}) {
|
|
2845
|
-
var
|
|
2882
|
+
var _a3;
|
|
2846
2883
|
const config = createConfig(options);
|
|
2847
2884
|
prepareDocument(config.document);
|
|
2848
|
-
const view = (
|
|
2885
|
+
const view = (_a3 = config.document.defaultView) != null ? _a3 : window;
|
|
2849
2886
|
attachClipboardStubToView(view);
|
|
2850
2887
|
return doSetup(config);
|
|
2851
2888
|
}
|
|
@@ -2881,8 +2918,8 @@ function doSetup(config) {
|
|
|
2881
2918
|
});
|
|
2882
2919
|
}
|
|
2883
2920
|
function getDocument(options, node) {
|
|
2884
|
-
var
|
|
2885
|
-
return (_b = (
|
|
2921
|
+
var _a3, _b;
|
|
2922
|
+
return (_b = (_a3 = options.document) != null ? _a3 : node && getDocumentFromNode(node)) != null ? _b : document;
|
|
2886
2923
|
}
|
|
2887
2924
|
|
|
2888
2925
|
// src/setup/directApi.ts
|