@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.cjs
CHANGED
|
@@ -72,7 +72,7 @@ function isClickableInput(element) {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
// src/utils/dataTransfer/Blob.ts
|
|
75
|
-
function readBlobText(blob) {
|
|
75
|
+
function readBlobText(blob, FileReader) {
|
|
76
76
|
return new Promise((res, rej) => {
|
|
77
77
|
const fr = new FileReader();
|
|
78
78
|
fr.onerror = rej;
|
|
@@ -156,8 +156,8 @@ var DataTransferStub = class {
|
|
|
156
156
|
this.files = createFileList([]);
|
|
157
157
|
}
|
|
158
158
|
getData(format) {
|
|
159
|
-
var
|
|
160
|
-
const match = (
|
|
159
|
+
var _a3;
|
|
160
|
+
const match = (_a3 = this.items.find(getTypeMatcher(format, true))) != null ? _a3 : this.items.find(getTypeMatcher(format, false));
|
|
161
161
|
let text = "";
|
|
162
162
|
match == null ? void 0 : match.getAsString((t) => {
|
|
163
163
|
text = t;
|
|
@@ -195,12 +195,12 @@ var DataTransferStub = class {
|
|
|
195
195
|
setDragImage() {
|
|
196
196
|
}
|
|
197
197
|
};
|
|
198
|
-
function createDataTransfer(files = []) {
|
|
199
|
-
const dt = typeof DataTransfer === "undefined" ? new DataTransferStub() : new DataTransfer();
|
|
198
|
+
function createDataTransfer(window2, files = []) {
|
|
199
|
+
const dt = typeof window2.DataTransfer === "undefined" ? new DataTransferStub() : new window2.DataTransfer();
|
|
200
200
|
Object.defineProperty(dt, "files", { get: () => createFileList(files) });
|
|
201
201
|
return dt;
|
|
202
202
|
}
|
|
203
|
-
function getBlobFromDataTransferItem(item) {
|
|
203
|
+
function getBlobFromDataTransferItem(window2, item) {
|
|
204
204
|
if (item.kind === "file") {
|
|
205
205
|
return item.getAsFile();
|
|
206
206
|
}
|
|
@@ -208,12 +208,21 @@ function getBlobFromDataTransferItem(item) {
|
|
|
208
208
|
item.getAsString((s) => {
|
|
209
209
|
data = s;
|
|
210
210
|
});
|
|
211
|
-
return new Blob([data], { type: item.type });
|
|
211
|
+
return new window2.Blob([data], { type: item.type });
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// src/utils/misc/getWindow.ts
|
|
215
|
+
var import_helpers = require("@testing-library/dom/dist/helpers.js");
|
|
216
|
+
function getWindow(node) {
|
|
217
|
+
return (0, import_helpers.getWindowFromNode)(node);
|
|
212
218
|
}
|
|
213
219
|
|
|
214
220
|
// src/utils/dataTransfer/Clipboard.ts
|
|
221
|
+
var Window = Symbol("Window reference");
|
|
222
|
+
var _a;
|
|
215
223
|
var ClipboardItemStub = class {
|
|
216
224
|
constructor(data) {
|
|
225
|
+
this[_a] = window;
|
|
217
226
|
this.data = data;
|
|
218
227
|
}
|
|
219
228
|
get types() {
|
|
@@ -224,14 +233,17 @@ var ClipboardItemStub = class {
|
|
|
224
233
|
if (!data) {
|
|
225
234
|
throw new Error(`${type3} is not one of the available MIME types on this item.`);
|
|
226
235
|
}
|
|
227
|
-
return data instanceof Blob ? data : new Blob([data], { type: type3 });
|
|
236
|
+
return data instanceof this[Window].Blob ? data : new this[Window].Blob([data], { type: type3 });
|
|
228
237
|
}
|
|
229
238
|
};
|
|
239
|
+
_a = Window;
|
|
230
240
|
var ClipboardStubControl = Symbol("Manage ClipboardSub");
|
|
231
|
-
var
|
|
241
|
+
var _a2;
|
|
242
|
+
var ClipboardStub = class extends window.EventTarget {
|
|
232
243
|
constructor() {
|
|
233
244
|
super(...arguments);
|
|
234
245
|
this.items = [];
|
|
246
|
+
this[_a2] = window;
|
|
235
247
|
}
|
|
236
248
|
async read() {
|
|
237
249
|
return Array.from(this.items);
|
|
@@ -241,7 +253,7 @@ var ClipboardStub = class extends EventTarget {
|
|
|
241
253
|
for (const item of this.items) {
|
|
242
254
|
const type3 = item.types.includes("text/plain") ? "text/plain" : item.types.find((t) => t.startsWith("text/"));
|
|
243
255
|
if (type3) {
|
|
244
|
-
text += await item.getType(type3).then((b) => readBlobText(b));
|
|
256
|
+
text += await item.getType(type3).then((b) => readBlobText(b, this[Window].FileReader));
|
|
245
257
|
}
|
|
246
258
|
}
|
|
247
259
|
return text;
|
|
@@ -250,16 +262,22 @@ var ClipboardStub = class extends EventTarget {
|
|
|
250
262
|
this.items = data;
|
|
251
263
|
}
|
|
252
264
|
async writeText(text) {
|
|
253
|
-
this.items = [createClipboardItem(text)];
|
|
265
|
+
this.items = [createClipboardItem(this[Window], text)];
|
|
254
266
|
}
|
|
255
267
|
};
|
|
256
|
-
ClipboardStubControl;
|
|
257
|
-
function createClipboardItem(...blobs) {
|
|
258
|
-
const
|
|
259
|
-
return new constructor(Object.fromEntries(blobs.map((b) => [
|
|
268
|
+
_a2 = Window, ClipboardStubControl;
|
|
269
|
+
function createClipboardItem(window2, ...blobs) {
|
|
270
|
+
const data = Object.fromEntries(blobs.map((b) => [
|
|
260
271
|
typeof b === "string" ? "text/plain" : b.type,
|
|
261
272
|
Promise.resolve(b)
|
|
262
|
-
]))
|
|
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
|
+
}
|
|
263
281
|
}
|
|
264
282
|
function attachClipboardStubToView(window2) {
|
|
265
283
|
if (window2.navigator.clipboard instanceof ClipboardStub) {
|
|
@@ -267,9 +285,11 @@ function attachClipboardStubToView(window2) {
|
|
|
267
285
|
}
|
|
268
286
|
const realClipboard = Object.getOwnPropertyDescriptor(window2.navigator, "clipboard");
|
|
269
287
|
let stub = new ClipboardStub();
|
|
288
|
+
stub[Window] = window2;
|
|
270
289
|
const control = {
|
|
271
290
|
resetClipboardStub: () => {
|
|
272
291
|
stub = new ClipboardStub();
|
|
292
|
+
stub[Window] = window2;
|
|
273
293
|
stub[ClipboardStubControl] = control;
|
|
274
294
|
},
|
|
275
295
|
detachClipboardStub: () => {
|
|
@@ -301,28 +321,28 @@ function detachClipboardStubFromView(window2) {
|
|
|
301
321
|
}
|
|
302
322
|
}
|
|
303
323
|
async function readDataTransferFromClipboard(document2) {
|
|
304
|
-
|
|
305
|
-
const clipboard =
|
|
324
|
+
const window2 = document2.defaultView;
|
|
325
|
+
const clipboard = window2 == null ? void 0 : window2.navigator.clipboard;
|
|
306
326
|
const items = clipboard && await clipboard.read();
|
|
307
327
|
if (!items) {
|
|
308
328
|
throw new Error("The Clipboard API is unavailable.");
|
|
309
329
|
}
|
|
310
|
-
const dt = createDataTransfer();
|
|
330
|
+
const dt = createDataTransfer(window2);
|
|
311
331
|
for (const item of items) {
|
|
312
332
|
for (const type3 of item.types) {
|
|
313
|
-
dt.setData(type3, await item.getType(type3).then((b) => readBlobText(b)));
|
|
333
|
+
dt.setData(type3, await item.getType(type3).then((b) => readBlobText(b, window2.FileReader)));
|
|
314
334
|
}
|
|
315
335
|
}
|
|
316
336
|
return dt;
|
|
317
337
|
}
|
|
318
338
|
async function writeDataTransferToClipboard(document2, clipboardData) {
|
|
319
|
-
|
|
320
|
-
const clipboard =
|
|
339
|
+
const window2 = getWindow(document2);
|
|
340
|
+
const clipboard = window2.navigator.clipboard;
|
|
321
341
|
const items = [];
|
|
322
342
|
for (let i = 0; i < clipboardData.items.length; i++) {
|
|
323
343
|
const dtItem = clipboardData.items[i];
|
|
324
|
-
const blob = getBlobFromDataTransferItem(dtItem);
|
|
325
|
-
items.push(createClipboardItem(blob));
|
|
344
|
+
const blob = getBlobFromDataTransferItem(window2, dtItem);
|
|
345
|
+
items.push(createClipboardItem(window2, blob));
|
|
326
346
|
}
|
|
327
347
|
const written = clipboard && await clipboard.write(items).then(() => true, () => false);
|
|
328
348
|
if (!written) {
|
|
@@ -416,11 +436,11 @@ function getSpaceUntilMaxLength(element) {
|
|
|
416
436
|
return maxLength ? maxLength - value.length : void 0;
|
|
417
437
|
}
|
|
418
438
|
function getSanitizedMaxLength(element) {
|
|
419
|
-
var
|
|
439
|
+
var _a3;
|
|
420
440
|
if (!supportsMaxLength(element)) {
|
|
421
441
|
return void 0;
|
|
422
442
|
}
|
|
423
|
-
const attr = (
|
|
443
|
+
const attr = (_a3 = element.getAttribute("maxlength")) != null ? _a3 : "";
|
|
424
444
|
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
|
|
425
445
|
}
|
|
426
446
|
function supportsMaxLength(element) {
|
|
@@ -511,11 +531,11 @@ function editInputElement(config, element, inputRange, data, inputType) {
|
|
|
511
531
|
});
|
|
512
532
|
if (isDateOrTime(element)) {
|
|
513
533
|
if (isValidDateOrTimeValue(element, newValue)) {
|
|
514
|
-
commitInput(config, element,
|
|
534
|
+
commitInput(config, element, newOffset, {});
|
|
515
535
|
dispatchUIEvent(config, element, "change");
|
|
516
536
|
}
|
|
517
537
|
} else {
|
|
518
|
-
commitInput(config, element,
|
|
538
|
+
commitInput(config, element, newOffset, {
|
|
519
539
|
data,
|
|
520
540
|
inputType
|
|
521
541
|
});
|
|
@@ -545,11 +565,10 @@ function calculateNewValue(inputData, node, {
|
|
|
545
565
|
newOffset
|
|
546
566
|
};
|
|
547
567
|
}
|
|
548
|
-
function commitInput(config, element,
|
|
568
|
+
function commitInput(config, element, newOffset, inputInit) {
|
|
549
569
|
startTrackValue(element);
|
|
550
570
|
dispatchUIEvent(config, element, "input", inputInit);
|
|
551
|
-
|
|
552
|
-
if ((tracked == null ? void 0 : tracked.length) === 2 && tracked[0] === oldValue && tracked[1] === newValue) {
|
|
571
|
+
if (endTrackValue(element)) {
|
|
553
572
|
setSelection({
|
|
554
573
|
focusNode: element,
|
|
555
574
|
anchorOffset: newOffset,
|
|
@@ -558,9 +577,9 @@ function commitInput(config, element, oldValue, newValue, newOffset, inputInit)
|
|
|
558
577
|
}
|
|
559
578
|
}
|
|
560
579
|
function isValidNumberInput(value) {
|
|
561
|
-
var
|
|
580
|
+
var _a3, _b;
|
|
562
581
|
const valueParts = value.split("e", 2);
|
|
563
|
-
return !(/[^\d.\-e]/.test(value) || Number((
|
|
582
|
+
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]));
|
|
564
583
|
}
|
|
565
584
|
|
|
566
585
|
// src/utils/edit/isEditable.ts
|
|
@@ -589,8 +608,8 @@ function isEditableInput(element) {
|
|
|
589
608
|
// src/utils/edit/setFiles.ts
|
|
590
609
|
var fakeFiles = Symbol("files and value properties are mocked");
|
|
591
610
|
function setFiles(el, files) {
|
|
592
|
-
var
|
|
593
|
-
(
|
|
611
|
+
var _a3;
|
|
612
|
+
(_a3 = el[fakeFiles]) == null ? void 0 : _a3.restore();
|
|
594
613
|
const objectDescriptors = Object.getOwnPropertyDescriptors(el);
|
|
595
614
|
const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
|
|
596
615
|
function restore() {
|
|
@@ -608,11 +627,11 @@ function setFiles(el, files) {
|
|
|
608
627
|
value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
|
|
609
628
|
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
610
629
|
set(v) {
|
|
611
|
-
var
|
|
630
|
+
var _a4;
|
|
612
631
|
if (v === "") {
|
|
613
632
|
restore();
|
|
614
633
|
} else {
|
|
615
|
-
(
|
|
634
|
+
(_a4 = objectDescriptors.value.set) == null ? void 0 : _a4.call(el, v);
|
|
616
635
|
}
|
|
617
636
|
}
|
|
618
637
|
}),
|
|
@@ -639,7 +658,7 @@ function eventWrapper(cb) {
|
|
|
639
658
|
|
|
640
659
|
// src/utils/misc/isDisabled.ts
|
|
641
660
|
function isDisabled(element) {
|
|
642
|
-
var
|
|
661
|
+
var _a3;
|
|
643
662
|
for (let el = element; el; el = el.parentElement) {
|
|
644
663
|
if (isElementType(el, [
|
|
645
664
|
"button",
|
|
@@ -653,7 +672,7 @@ function isDisabled(element) {
|
|
|
653
672
|
return true;
|
|
654
673
|
}
|
|
655
674
|
} else if (isElementType(el, "fieldset")) {
|
|
656
|
-
if (el.hasAttribute("disabled") && !((
|
|
675
|
+
if (el.hasAttribute("disabled") && !((_a3 = el.querySelector(":scope > legend")) == null ? void 0 : _a3.contains(element))) {
|
|
657
676
|
return true;
|
|
658
677
|
}
|
|
659
678
|
} else if (el.tagName.includes("-")) {
|
|
@@ -786,7 +805,7 @@ function isTextNode(node) {
|
|
|
786
805
|
return node.nodeType === 3;
|
|
787
806
|
}
|
|
788
807
|
function walkNodes(node, direction, callback) {
|
|
789
|
-
var
|
|
808
|
+
var _a3;
|
|
790
809
|
for (; ; ) {
|
|
791
810
|
const sibling = node[`${direction}Sibling`];
|
|
792
811
|
if (sibling) {
|
|
@@ -794,7 +813,7 @@ function walkNodes(node, direction, callback) {
|
|
|
794
813
|
if (callback(node)) {
|
|
795
814
|
return node;
|
|
796
815
|
}
|
|
797
|
-
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((
|
|
816
|
+
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a3 = node.ownerDocument) == null ? void 0 : _a3.body))) {
|
|
798
817
|
node = node.parentNode;
|
|
799
818
|
} else {
|
|
800
819
|
break;
|
|
@@ -810,7 +829,7 @@ function getDescendant(node, direction) {
|
|
|
810
829
|
|
|
811
830
|
// src/utils/focus/selection.ts
|
|
812
831
|
function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
813
|
-
var
|
|
832
|
+
var _a3;
|
|
814
833
|
if (hasOwnSelection(element)) {
|
|
815
834
|
return setSelection({
|
|
816
835
|
focusNode: element,
|
|
@@ -818,7 +837,7 @@ function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
|
818
837
|
focusOffset
|
|
819
838
|
});
|
|
820
839
|
}
|
|
821
|
-
if (isContentEditable(element) && ((
|
|
840
|
+
if (isContentEditable(element) && ((_a3 = element.firstChild) == null ? void 0 : _a3.nodeType) === 3) {
|
|
822
841
|
return setSelection({
|
|
823
842
|
focusNode: element.firstChild,
|
|
824
843
|
anchorOffset,
|
|
@@ -852,7 +871,7 @@ function getElement2(node) {
|
|
|
852
871
|
return node.nodeType === 1 ? node : node.parentElement;
|
|
853
872
|
}
|
|
854
873
|
function updateSelectionOnFocus(element) {
|
|
855
|
-
var
|
|
874
|
+
var _a3;
|
|
856
875
|
const selection = element.ownerDocument.getSelection();
|
|
857
876
|
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
858
877
|
return;
|
|
@@ -861,7 +880,7 @@ function updateSelectionOnFocus(element) {
|
|
|
861
880
|
const contenteditable = getContentEditable(selection.focusNode);
|
|
862
881
|
if (contenteditable) {
|
|
863
882
|
if (!selection.isCollapsed) {
|
|
864
|
-
const focusNode = ((
|
|
883
|
+
const focusNode = ((_a3 = contenteditable.firstChild) == null ? void 0 : _a3.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
865
884
|
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
866
885
|
}
|
|
867
886
|
} else {
|
|
@@ -870,12 +889,12 @@ function updateSelectionOnFocus(element) {
|
|
|
870
889
|
}
|
|
871
890
|
}
|
|
872
891
|
function getInputRange(focusNode) {
|
|
873
|
-
var
|
|
892
|
+
var _a3;
|
|
874
893
|
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
875
894
|
if (typeAndSelection.type === "input") {
|
|
876
895
|
return typeAndSelection.selection;
|
|
877
896
|
} else if (typeAndSelection.type === "contenteditable") {
|
|
878
|
-
return (
|
|
897
|
+
return (_a3 = typeAndSelection.selection) == null ? void 0 : _a3.getRangeAt(0);
|
|
879
898
|
}
|
|
880
899
|
}
|
|
881
900
|
function setSelection({
|
|
@@ -884,7 +903,7 @@ function setSelection({
|
|
|
884
903
|
anchorNode = focusNode,
|
|
885
904
|
anchorOffset = focusOffset
|
|
886
905
|
}) {
|
|
887
|
-
var
|
|
906
|
+
var _a3, _b;
|
|
888
907
|
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
889
908
|
if (typeAndSelection.type === "input") {
|
|
890
909
|
return setUISelection(focusNode, {
|
|
@@ -892,7 +911,7 @@ function setSelection({
|
|
|
892
911
|
focusOffset
|
|
893
912
|
});
|
|
894
913
|
}
|
|
895
|
-
(_b = (
|
|
914
|
+
(_b = (_a3 = anchorNode.ownerDocument) == null ? void 0 : _a3.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
896
915
|
}
|
|
897
916
|
function moveSelection(node, direction) {
|
|
898
917
|
if (hasOwnSelection(node)) {
|
|
@@ -923,7 +942,7 @@ function moveSelection(node, direction) {
|
|
|
923
942
|
// src/utils/focus/copySelection.ts
|
|
924
943
|
function copySelection(target) {
|
|
925
944
|
const data = hasOwnSelection(target) ? { "text/plain": readSelectedValueFromInput(target) } : { "text/plain": String(target.ownerDocument.getSelection()) };
|
|
926
|
-
const dt = createDataTransfer();
|
|
945
|
+
const dt = createDataTransfer(getWindow(target));
|
|
927
946
|
for (const type3 in data) {
|
|
928
947
|
if (data[type3]) {
|
|
929
948
|
dt.setData(type3, data[type3]);
|
|
@@ -964,9 +983,8 @@ function focus(element) {
|
|
|
964
983
|
}
|
|
965
984
|
|
|
966
985
|
// src/utils/misc/isVisible.ts
|
|
967
|
-
var import_helpers = require("@testing-library/dom/dist/helpers.js");
|
|
968
986
|
function isVisible(element) {
|
|
969
|
-
const window2 = (
|
|
987
|
+
const window2 = getWindow(element);
|
|
970
988
|
for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
971
989
|
const { display, visibility } = window2.getComputedStyle(el);
|
|
972
990
|
if (display === "none") {
|
|
@@ -1032,7 +1050,7 @@ function getTabDestination(activeElement, shift) {
|
|
|
1032
1050
|
|
|
1033
1051
|
// src/utils/focus/selectAll.ts
|
|
1034
1052
|
function selectAll(target) {
|
|
1035
|
-
var
|
|
1053
|
+
var _a3;
|
|
1036
1054
|
if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
|
|
1037
1055
|
return setSelection({
|
|
1038
1056
|
focusNode: target,
|
|
@@ -1040,7 +1058,7 @@ function selectAll(target) {
|
|
|
1040
1058
|
focusOffset: getUIValue(target).length
|
|
1041
1059
|
});
|
|
1042
1060
|
}
|
|
1043
|
-
const focusNode = (
|
|
1061
|
+
const focusNode = (_a3 = getContentEditable(target)) != null ? _a3 : target.ownerDocument.body;
|
|
1044
1062
|
setSelection({
|
|
1045
1063
|
focusNode,
|
|
1046
1064
|
anchorOffset: 0,
|
|
@@ -1048,11 +1066,11 @@ function selectAll(target) {
|
|
|
1048
1066
|
});
|
|
1049
1067
|
}
|
|
1050
1068
|
function isAllSelected(target) {
|
|
1051
|
-
var
|
|
1069
|
+
var _a3;
|
|
1052
1070
|
if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
|
|
1053
1071
|
return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
|
|
1054
1072
|
}
|
|
1055
|
-
const focusNode = (
|
|
1073
|
+
const focusNode = (_a3 = getContentEditable(target)) != null ? _a3 : target.ownerDocument.body;
|
|
1056
1074
|
const selection = target.ownerDocument.getSelection();
|
|
1057
1075
|
return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
1058
1076
|
}
|
|
@@ -1112,12 +1130,12 @@ function readPrintableChar(text, pos, context) {
|
|
|
1112
1130
|
};
|
|
1113
1131
|
}
|
|
1114
1132
|
function readTag(text, pos, startBracket, context) {
|
|
1115
|
-
var
|
|
1133
|
+
var _a3, _b, _c;
|
|
1116
1134
|
const releasePreviousModifier = text[pos] === "/" ? "/" : "";
|
|
1117
1135
|
pos += releasePreviousModifier.length;
|
|
1118
1136
|
const escapedDescriptor = startBracket === "{" && text[pos] === "\\";
|
|
1119
1137
|
pos += Number(escapedDescriptor);
|
|
1120
|
-
const descriptor = escapedDescriptor ? text[pos] : (
|
|
1138
|
+
const descriptor = escapedDescriptor ? text[pos] : (_a3 = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a3[0];
|
|
1121
1139
|
assertDescriptor(descriptor, text, pos, context);
|
|
1122
1140
|
pos += descriptor.length;
|
|
1123
1141
|
const repeatModifier = (_c = (_b = text.slice(pos).match(/^>\d+/)) == null ? void 0 : _b[0]) != null ? _c : "";
|
|
@@ -1189,13 +1207,13 @@ function isDescendantOrSelf(potentialDescendant, potentialAncestor) {
|
|
|
1189
1207
|
// src/utils/misc/level.ts
|
|
1190
1208
|
var Level = Symbol("Api level refs");
|
|
1191
1209
|
function setLevelRef(config, level) {
|
|
1192
|
-
var
|
|
1193
|
-
(
|
|
1210
|
+
var _a3;
|
|
1211
|
+
(_a3 = config[Level]) != null ? _a3 : config[Level] = {};
|
|
1194
1212
|
config[Level][level] = {};
|
|
1195
1213
|
}
|
|
1196
1214
|
function getLevelRef(config, level) {
|
|
1197
|
-
var
|
|
1198
|
-
return (
|
|
1215
|
+
var _a3;
|
|
1216
|
+
return (_a3 = config[Level]) == null ? void 0 : _a3[level];
|
|
1199
1217
|
}
|
|
1200
1218
|
|
|
1201
1219
|
// src/utils/misc/wait.ts
|
|
@@ -1203,9 +1221,6 @@ function wait(time) {
|
|
|
1203
1221
|
return new Promise((resolve) => setTimeout(() => resolve(), time));
|
|
1204
1222
|
}
|
|
1205
1223
|
|
|
1206
|
-
// src/utils/pointer/cssPointerEvents.ts
|
|
1207
|
-
var import_helpers2 = require("@testing-library/dom/dist/helpers.js");
|
|
1208
|
-
|
|
1209
1224
|
// src/keyboard/keyMap.ts
|
|
1210
1225
|
var defaultKeyMap = [
|
|
1211
1226
|
..."0123456789".split("").map((c) => ({ code: `Digit${c}`, key: c })),
|
|
@@ -1299,7 +1314,7 @@ var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect)
|
|
|
1299
1314
|
|
|
1300
1315
|
// src/utils/pointer/cssPointerEvents.ts
|
|
1301
1316
|
function hasPointerEvents(element) {
|
|
1302
|
-
const window2 = (
|
|
1317
|
+
const window2 = getWindow(element);
|
|
1303
1318
|
for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
1304
1319
|
const pointerEvents = window2.getComputedStyle(el).pointerEvents;
|
|
1305
1320
|
if (pointerEvents && !["inherit", "unset"].includes(pointerEvents)) {
|
|
@@ -1413,9 +1428,9 @@ function assignPositionInit(obj, {
|
|
|
1413
1428
|
screenX,
|
|
1414
1429
|
screenY
|
|
1415
1430
|
}) {
|
|
1416
|
-
var
|
|
1431
|
+
var _a3, _b, _c, _d;
|
|
1417
1432
|
assignProps(obj, {
|
|
1418
|
-
x: (
|
|
1433
|
+
x: (_a3 = x != null ? x : clientX) != null ? _a3 : 0,
|
|
1419
1434
|
y: (_b = y != null ? y : clientY) != null ? _b : 0,
|
|
1420
1435
|
clientX: (_c = x != null ? x : clientX) != null ? _c : 0,
|
|
1421
1436
|
clientY: (_d = y != null ? y : clientY) != null ? _d : 0,
|
|
@@ -1440,7 +1455,7 @@ var behavior = {};
|
|
|
1440
1455
|
|
|
1441
1456
|
// src/event/behavior/click.ts
|
|
1442
1457
|
behavior.click = (event, target, config) => {
|
|
1443
|
-
const context = target.closest("button,input,label,textarea");
|
|
1458
|
+
const context = target.closest("button,input,label,select,textarea");
|
|
1444
1459
|
const control = context && isElementType(context, "label") && context.control;
|
|
1445
1460
|
if (control) {
|
|
1446
1461
|
return () => {
|
|
@@ -1452,7 +1467,7 @@ behavior.click = (event, target, config) => {
|
|
|
1452
1467
|
} else if (isElementType(target, "input", { type: "file" })) {
|
|
1453
1468
|
return () => {
|
|
1454
1469
|
blur(target);
|
|
1455
|
-
target.dispatchEvent(new Event("fileDialog"));
|
|
1470
|
+
target.dispatchEvent(new (getWindow(target)).Event("fileDialog"));
|
|
1456
1471
|
focus(target);
|
|
1457
1472
|
};
|
|
1458
1473
|
}
|
|
@@ -1469,8 +1484,8 @@ behavior.cut = (event, target, config) => {
|
|
|
1469
1484
|
|
|
1470
1485
|
// src/event/behavior/keydown.ts
|
|
1471
1486
|
behavior.keydown = (event, target, config) => {
|
|
1472
|
-
var
|
|
1473
|
-
return (_b = (
|
|
1487
|
+
var _a3, _b;
|
|
1488
|
+
return (_b = (_a3 = keydownBehavior[event.key]) == null ? void 0 : _a3.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(event, target, config);
|
|
1474
1489
|
};
|
|
1475
1490
|
var keydownBehavior = {
|
|
1476
1491
|
ArrowLeft: (event, target) => () => moveSelection(target, -1),
|
|
@@ -1492,8 +1507,8 @@ var keydownBehavior = {
|
|
|
1492
1507
|
End: (event, target) => {
|
|
1493
1508
|
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1494
1509
|
return () => {
|
|
1495
|
-
var
|
|
1496
|
-
const newPos = (_b = (
|
|
1510
|
+
var _a3, _b;
|
|
1511
|
+
const newPos = (_b = (_a3 = getValue(target)) == null ? void 0 : _a3.length) != null ? _b : 0;
|
|
1497
1512
|
setSelectionRange(target, newPos, newPos);
|
|
1498
1513
|
};
|
|
1499
1514
|
}
|
|
@@ -1585,8 +1600,8 @@ var SubmitSingleInputOnEnter = [
|
|
|
1585
1600
|
|
|
1586
1601
|
// src/event/behavior/keyup.ts
|
|
1587
1602
|
behavior.keyup = (event, target, config) => {
|
|
1588
|
-
var
|
|
1589
|
-
return (
|
|
1603
|
+
var _a3;
|
|
1604
|
+
return (_a3 = keyupBehavior[event.key]) == null ? void 0 : _a3.call(keyupBehavior, event, target, config);
|
|
1590
1605
|
};
|
|
1591
1606
|
var keyupBehavior = {
|
|
1592
1607
|
" ": (event, target, config) => {
|
|
@@ -1600,8 +1615,8 @@ var keyupBehavior = {
|
|
|
1600
1615
|
behavior.paste = (event, target, config) => {
|
|
1601
1616
|
if (isEditable(target)) {
|
|
1602
1617
|
return () => {
|
|
1603
|
-
var
|
|
1604
|
-
const insertData = (
|
|
1618
|
+
var _a3;
|
|
1619
|
+
const insertData = (_a3 = event.clipboardData) == null ? void 0 : _a3.getData("text");
|
|
1605
1620
|
if (insertData) {
|
|
1606
1621
|
input(config, target, insertData, "insertFromPaste");
|
|
1607
1622
|
}
|
|
@@ -1617,10 +1632,10 @@ function wrapEvent(cb, _element) {
|
|
|
1617
1632
|
|
|
1618
1633
|
// src/event/dispatchEvent.ts
|
|
1619
1634
|
function dispatchEvent(config, target, event, preventDefault = false) {
|
|
1620
|
-
var
|
|
1635
|
+
var _a3, _b;
|
|
1621
1636
|
const type3 = event.type;
|
|
1622
1637
|
const behaviorImplementation = preventDefault ? () => {
|
|
1623
|
-
} : (_b = (
|
|
1638
|
+
} : (_b = (_a3 = behavior)[type3]) == null ? void 0 : _b.call(_a3, event, target, config);
|
|
1624
1639
|
if (behaviorImplementation) {
|
|
1625
1640
|
event.preventDefault();
|
|
1626
1641
|
let defaultPrevented = false;
|
|
@@ -1724,9 +1739,9 @@ function setUISelection(element, {
|
|
|
1724
1739
|
}
|
|
1725
1740
|
}
|
|
1726
1741
|
function getUISelection(element) {
|
|
1727
|
-
var
|
|
1742
|
+
var _a3, _b, _c;
|
|
1728
1743
|
const sel = (_c = element[UISelection]) != null ? _c : {
|
|
1729
|
-
anchorOffset: (
|
|
1744
|
+
anchorOffset: (_a3 = element.selectionStart) != null ? _a3 : 0,
|
|
1730
1745
|
focusOffset: (_b = element.selectionEnd) != null ? _b : 0
|
|
1731
1746
|
};
|
|
1732
1747
|
return __spreadProps(__spreadValues({}, sel), {
|
|
@@ -1734,9 +1749,6 @@ function getUISelection(element) {
|
|
|
1734
1749
|
endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
|
|
1735
1750
|
});
|
|
1736
1751
|
}
|
|
1737
|
-
function clearUISelection(element) {
|
|
1738
|
-
element[UISelection] = void 0;
|
|
1739
|
-
}
|
|
1740
1752
|
|
|
1741
1753
|
// src/document/value.ts
|
|
1742
1754
|
var UIValue = Symbol("Displayed value in UI");
|
|
@@ -1744,17 +1756,23 @@ var InitialValue = Symbol("Initial value to compare on blur");
|
|
|
1744
1756
|
var TrackChanges = Symbol("Track programmatic changes for React workaround");
|
|
1745
1757
|
function valueInterceptor(v) {
|
|
1746
1758
|
const isUI = typeof v === "object" && v[UIValue];
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1759
|
+
if (isUI) {
|
|
1760
|
+
this[UIValue] = String(v);
|
|
1761
|
+
setPreviousValue(this, String(this.value));
|
|
1762
|
+
} else {
|
|
1763
|
+
trackOrSetValue(this, String(v));
|
|
1752
1764
|
}
|
|
1753
1765
|
return {
|
|
1754
1766
|
applyNative: !!isUI,
|
|
1755
|
-
realArgs:
|
|
1767
|
+
realArgs: sanitizeValue(this, v)
|
|
1756
1768
|
};
|
|
1757
1769
|
}
|
|
1770
|
+
function sanitizeValue(element, v) {
|
|
1771
|
+
if (isElementType(element, "input", { type: "number" }) && String(v) !== "" && !Number.isNaN(Number(v))) {
|
|
1772
|
+
return String(Number(v));
|
|
1773
|
+
}
|
|
1774
|
+
return String(v);
|
|
1775
|
+
}
|
|
1758
1776
|
function prepareValueInterceptor(element) {
|
|
1759
1777
|
prepareInterceptor(element, "value", valueInterceptor);
|
|
1760
1778
|
}
|
|
@@ -1773,17 +1791,36 @@ function setInitialValue(element) {
|
|
|
1773
1791
|
function getInitialValue(element) {
|
|
1774
1792
|
return element[InitialValue];
|
|
1775
1793
|
}
|
|
1794
|
+
function setPreviousValue(element, v) {
|
|
1795
|
+
element[TrackChanges] = __spreadProps(__spreadValues({}, element[TrackChanges]), { previousValue: v });
|
|
1796
|
+
}
|
|
1776
1797
|
function startTrackValue(element) {
|
|
1777
|
-
element[TrackChanges] = []
|
|
1798
|
+
element[TrackChanges] = __spreadProps(__spreadValues({}, element[TrackChanges]), {
|
|
1799
|
+
nextValue: String(element.value),
|
|
1800
|
+
tracked: []
|
|
1801
|
+
});
|
|
1778
1802
|
}
|
|
1779
|
-
function
|
|
1780
|
-
var
|
|
1781
|
-
(
|
|
1803
|
+
function trackOrSetValue(element, v) {
|
|
1804
|
+
var _a3, _b, _c;
|
|
1805
|
+
(_b = (_a3 = element[TrackChanges]) == null ? void 0 : _a3.tracked) == null ? void 0 : _b.push(v);
|
|
1806
|
+
if (!((_c = element[TrackChanges]) == null ? void 0 : _c.tracked)) {
|
|
1807
|
+
setCleanValue(element, v);
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
function setCleanValue(element, v) {
|
|
1811
|
+
element[UIValue] = void 0;
|
|
1812
|
+
element[InitialValue] = v;
|
|
1813
|
+
setUISelection(element, { focusOffset: v.length });
|
|
1782
1814
|
}
|
|
1783
1815
|
function endTrackValue(element) {
|
|
1784
|
-
|
|
1816
|
+
var _a3, _b;
|
|
1817
|
+
const changes = element[TrackChanges];
|
|
1785
1818
|
element[TrackChanges] = void 0;
|
|
1786
|
-
|
|
1819
|
+
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
|
+
if (((_b = changes == null ? void 0 : changes.tracked) == null ? void 0 : _b.length) && !isJustReactStateUpdate) {
|
|
1821
|
+
setCleanValue(element, changes.tracked[changes.tracked.length - 1]);
|
|
1822
|
+
}
|
|
1823
|
+
return isJustReactStateUpdate;
|
|
1787
1824
|
}
|
|
1788
1825
|
|
|
1789
1826
|
// src/document/index.ts
|
|
@@ -1852,11 +1889,11 @@ function isModifierLock(key) {
|
|
|
1852
1889
|
return modifierLocks.includes(key);
|
|
1853
1890
|
}
|
|
1854
1891
|
function preKeydownBehavior(config, { key }, element) {
|
|
1855
|
-
var
|
|
1892
|
+
var _a3;
|
|
1856
1893
|
if (isModifierKey(key)) {
|
|
1857
1894
|
config.keyboardState.modifiers[key] = true;
|
|
1858
1895
|
if (key === "AltGraph") {
|
|
1859
|
-
const ctrlKeyDef = (
|
|
1896
|
+
const ctrlKeyDef = (_a3 = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a3 : { key: "Control", code: "Control" };
|
|
1860
1897
|
dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
|
|
1861
1898
|
}
|
|
1862
1899
|
} else if (isModifierLock(key)) {
|
|
@@ -1876,9 +1913,9 @@ function preKeyupBehavior(config, { key }) {
|
|
|
1876
1913
|
}
|
|
1877
1914
|
}
|
|
1878
1915
|
function postKeyupBehavior(config, { key }, element) {
|
|
1879
|
-
var
|
|
1916
|
+
var _a3;
|
|
1880
1917
|
if (key === "AltGraph") {
|
|
1881
|
-
const ctrlKeyDef = (
|
|
1918
|
+
const ctrlKeyDef = (_a3 = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a3 : { key: "Control", code: "Control" };
|
|
1882
1919
|
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1883
1920
|
}
|
|
1884
1921
|
}
|
|
@@ -1916,8 +1953,8 @@ async function keyboardKeyAction(config, { keyDef, releasePrevious, releaseSelf,
|
|
|
1916
1953
|
}
|
|
1917
1954
|
}
|
|
1918
1955
|
function getActive(document2) {
|
|
1919
|
-
var
|
|
1920
|
-
return (
|
|
1956
|
+
var _a3;
|
|
1957
|
+
return (_a3 = getActiveElement(document2)) != null ? _a3 : document2.body;
|
|
1921
1958
|
}
|
|
1922
1959
|
async function releaseAllKeys(config) {
|
|
1923
1960
|
const getCurrentElement = () => getActive(config.document);
|
|
@@ -1951,13 +1988,13 @@ async function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
|
1951
1988
|
postKeyupBehavior(config, keyDef, element);
|
|
1952
1989
|
}
|
|
1953
1990
|
function hasKeyPress(keyDef, config) {
|
|
1954
|
-
var
|
|
1955
|
-
return (((
|
|
1991
|
+
var _a3;
|
|
1992
|
+
return (((_a3 = keyDef.key) == null ? void 0 : _a3.length) === 1 || keyDef.key === "Enter") && !config.keyboardState.modifiers.Control && !config.keyboardState.modifiers.Alt;
|
|
1956
1993
|
}
|
|
1957
1994
|
|
|
1958
1995
|
// src/keyboard/parseKeyDef.ts
|
|
1959
1996
|
function parseKeyDef(keyboardMap, text) {
|
|
1960
|
-
var
|
|
1997
|
+
var _a3;
|
|
1961
1998
|
const defs = [];
|
|
1962
1999
|
do {
|
|
1963
2000
|
const {
|
|
@@ -1968,15 +2005,15 @@ function parseKeyDef(keyboardMap, text) {
|
|
|
1968
2005
|
releaseSelf = true,
|
|
1969
2006
|
repeat
|
|
1970
2007
|
} = readNextDescriptor(text, "keyboard");
|
|
1971
|
-
const keyDef = (
|
|
1972
|
-
var
|
|
2008
|
+
const keyDef = (_a3 = keyboardMap.find((def) => {
|
|
2009
|
+
var _a4, _b;
|
|
1973
2010
|
if (type3 === "[") {
|
|
1974
|
-
return ((
|
|
2011
|
+
return ((_a4 = def.code) == null ? void 0 : _a4.toLowerCase()) === descriptor.toLowerCase();
|
|
1975
2012
|
} else if (type3 === "{") {
|
|
1976
2013
|
return ((_b = def.key) == null ? void 0 : _b.toLowerCase()) === descriptor.toLowerCase();
|
|
1977
2014
|
}
|
|
1978
2015
|
return def.key === descriptor;
|
|
1979
|
-
})) != null ?
|
|
2016
|
+
})) != null ? _a3 : {
|
|
1980
2017
|
key: "Unknown",
|
|
1981
2018
|
code: "Unknown",
|
|
1982
2019
|
[type3 === "[" ? "code" : "key"]: descriptor
|
|
@@ -2053,8 +2090,8 @@ function firePointerEvent(config, target, type3, {
|
|
|
2053
2090
|
}
|
|
2054
2091
|
init.button = getMouseButton(button != null ? button : 0);
|
|
2055
2092
|
init.buttons = getMouseButtons(...config.pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
|
|
2056
|
-
var
|
|
2057
|
-
return (
|
|
2093
|
+
var _a3;
|
|
2094
|
+
return (_a3 = p.keyDef.button) != null ? _a3 : 0;
|
|
2058
2095
|
}));
|
|
2059
2096
|
if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
|
|
2060
2097
|
init.detail = clickCount;
|
|
@@ -2212,7 +2249,7 @@ function getNextPointerId(state) {
|
|
|
2212
2249
|
return state.pointerId;
|
|
2213
2250
|
}
|
|
2214
2251
|
function down(config, pointerName, { keyDef, node, offset, target, coords }, targetIsDisabled) {
|
|
2215
|
-
var
|
|
2252
|
+
var _a3, _b, _c;
|
|
2216
2253
|
setLevelRef(config, 2 /* Trigger */);
|
|
2217
2254
|
assertPointerEvents(config, target);
|
|
2218
2255
|
const { pointerState } = config;
|
|
@@ -2235,7 +2272,7 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
|
|
|
2235
2272
|
}
|
|
2236
2273
|
}
|
|
2237
2274
|
}
|
|
2238
|
-
if (((
|
|
2275
|
+
if (((_a3 = pointerState.activeClickCount) == null ? void 0 : _a3[0]) !== name) {
|
|
2239
2276
|
delete pointerState.activeClickCount;
|
|
2240
2277
|
}
|
|
2241
2278
|
const clickCount = Number((_c = (_b = pointerState.activeClickCount) == null ? void 0 : _b[1]) != null ? _c : 0) + 1;
|
|
@@ -2363,7 +2400,6 @@ function mousedownDefaultBehavior({
|
|
|
2363
2400
|
node,
|
|
2364
2401
|
offset
|
|
2365
2402
|
}) {
|
|
2366
|
-
focus(target);
|
|
2367
2403
|
if (!targetIsDisabled) {
|
|
2368
2404
|
const hasValue = isElementType(target, ["input", "textarea"]);
|
|
2369
2405
|
const text = String(hasValue ? getUIValue(target) : target.textContent);
|
|
@@ -2389,7 +2425,7 @@ function mousedownDefaultBehavior({
|
|
|
2389
2425
|
node,
|
|
2390
2426
|
offset: end
|
|
2391
2427
|
});
|
|
2392
|
-
const range =
|
|
2428
|
+
const range = target.ownerDocument.createRange();
|
|
2393
2429
|
range.setStart(startNode, startOffset);
|
|
2394
2430
|
range.setEnd(endNode, endOffset);
|
|
2395
2431
|
position.selectionRange = range;
|
|
@@ -2398,6 +2434,7 @@ function mousedownDefaultBehavior({
|
|
|
2398
2434
|
selection.addRange(range.cloneRange());
|
|
2399
2435
|
}
|
|
2400
2436
|
}
|
|
2437
|
+
focus(target);
|
|
2401
2438
|
}
|
|
2402
2439
|
function getTextRange(text, pos, clickCount) {
|
|
2403
2440
|
if (clickCount % 3 === 1 || text.length === 0) {
|
|
@@ -2418,11 +2455,11 @@ function getTextRange(text, pos, clickCount) {
|
|
|
2418
2455
|
|
|
2419
2456
|
// src/pointer/pointerAction.ts
|
|
2420
2457
|
async function pointerAction(config, actions) {
|
|
2421
|
-
var
|
|
2458
|
+
var _a3, _b;
|
|
2422
2459
|
for (let i = 0; i < actions.length; i++) {
|
|
2423
2460
|
const action = actions[i];
|
|
2424
2461
|
const pointerName = "pointerName" in action && action.pointerName ? action.pointerName : "keyDef" in action ? action.keyDef.pointerType === "touch" ? action.keyDef.name : action.keyDef.pointerType : "mouse";
|
|
2425
|
-
const target = (
|
|
2462
|
+
const target = (_a3 = action.target) != null ? _a3 : getPrevTarget(pointerName, config.pointerState);
|
|
2426
2463
|
const coords = (_b = action.coords) != null ? _b : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : void 0;
|
|
2427
2464
|
await ("keyDef" in action ? pointerPress(config, __spreadProps(__spreadValues({}, action), { target, coords })) : pointerMove(config, __spreadProps(__spreadValues({}, action), { target, coords })));
|
|
2428
2465
|
if (typeof config.delay === "number") {
|
|
@@ -2536,9 +2573,9 @@ async function tab({
|
|
|
2536
2573
|
|
|
2537
2574
|
// src/clipboard/copy.ts
|
|
2538
2575
|
async function copy() {
|
|
2539
|
-
var
|
|
2576
|
+
var _a3;
|
|
2540
2577
|
const doc = this[Config].document;
|
|
2541
|
-
const target = (
|
|
2578
|
+
const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
|
|
2542
2579
|
const clipboardData = copySelection(target);
|
|
2543
2580
|
if (clipboardData.items.length === 0) {
|
|
2544
2581
|
return;
|
|
@@ -2553,9 +2590,9 @@ async function copy() {
|
|
|
2553
2590
|
|
|
2554
2591
|
// src/clipboard/cut.ts
|
|
2555
2592
|
async function cut() {
|
|
2556
|
-
var
|
|
2593
|
+
var _a3;
|
|
2557
2594
|
const doc = this[Config].document;
|
|
2558
|
-
const target = (
|
|
2595
|
+
const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
|
|
2559
2596
|
const clipboardData = copySelection(target);
|
|
2560
2597
|
if (clipboardData.items.length === 0) {
|
|
2561
2598
|
return;
|
|
@@ -2570,18 +2607,18 @@ async function cut() {
|
|
|
2570
2607
|
|
|
2571
2608
|
// src/clipboard/paste.ts
|
|
2572
2609
|
async function paste(clipboardData) {
|
|
2573
|
-
var
|
|
2610
|
+
var _a3, _b;
|
|
2574
2611
|
const doc = this[Config].document;
|
|
2575
|
-
const target = (
|
|
2576
|
-
const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _b : await readDataTransferFromClipboard(doc).catch(() => {
|
|
2612
|
+
const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
|
|
2613
|
+
const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(doc, clipboardData) : clipboardData) != null ? _b : await readDataTransferFromClipboard(doc).catch(() => {
|
|
2577
2614
|
throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
|
|
2578
2615
|
});
|
|
2579
2616
|
this.dispatchUIEvent(target, "paste", {
|
|
2580
2617
|
clipboardData: dataTransfer
|
|
2581
2618
|
});
|
|
2582
2619
|
}
|
|
2583
|
-
function getClipboardDataFromString(text) {
|
|
2584
|
-
const dt = createDataTransfer();
|
|
2620
|
+
function getClipboardDataFromString(doc, text) {
|
|
2621
|
+
const dt = createDataTransfer(getWindow(doc));
|
|
2585
2622
|
dt.setData("text", text);
|
|
2586
2623
|
return dt;
|
|
2587
2624
|
}
|
|
@@ -2724,10 +2761,10 @@ async function upload(element, fileOrFiles) {
|
|
|
2724
2761
|
return;
|
|
2725
2762
|
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input2.accept)).slice(0, input2.multiple ? void 0 : 1);
|
|
2726
2763
|
const fileDialog = () => {
|
|
2727
|
-
var
|
|
2728
|
-
if (files.length === ((
|
|
2729
|
-
var
|
|
2730
|
-
return f === ((
|
|
2764
|
+
var _a3;
|
|
2765
|
+
if (files.length === ((_a3 = input2.files) == null ? void 0 : _a3.length) && files.every((f, i) => {
|
|
2766
|
+
var _a4;
|
|
2767
|
+
return f === ((_a4 = input2.files) == null ? void 0 : _a4.item(i));
|
|
2731
2768
|
})) {
|
|
2732
2769
|
return;
|
|
2733
2770
|
}
|
|
@@ -2774,10 +2811,10 @@ function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
|
|
|
2774
2811
|
});
|
|
2775
2812
|
}
|
|
2776
2813
|
function setupMain(options = {}) {
|
|
2777
|
-
var
|
|
2814
|
+
var _a3;
|
|
2778
2815
|
const config = createConfig(options);
|
|
2779
2816
|
prepareDocument(config.document);
|
|
2780
|
-
const view = (
|
|
2817
|
+
const view = (_a3 = config.document.defaultView) != null ? _a3 : window;
|
|
2781
2818
|
attachClipboardStubToView(view);
|
|
2782
2819
|
return doSetup(config);
|
|
2783
2820
|
}
|
|
@@ -2813,8 +2850,8 @@ function doSetup(config) {
|
|
|
2813
2850
|
});
|
|
2814
2851
|
}
|
|
2815
2852
|
function getDocument(options, node) {
|
|
2816
|
-
var
|
|
2817
|
-
return (_b = (
|
|
2853
|
+
var _a3, _b;
|
|
2854
|
+
return (_b = (_a3 = options.document) != null ? _a3 : node && getDocumentFromNode(node)) != null ? _b : document;
|
|
2818
2855
|
}
|
|
2819
2856
|
|
|
2820
2857
|
// src/setup/directApi.ts
|