@testing-library/user-event 14.0.1 → 14.0.4

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.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 _a;
162
- const match = (_a = this.items.find(getTypeMatcher(format, true))) != null ? _a : this.items.find(getTypeMatcher(format, false));
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 ClipboardStub = class extends EventTarget {
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 constructor = typeof ClipboardItem === "undefined" ? ClipboardItemStub : ClipboardItem;
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
- var _a;
318
- const clipboard = (_a = document2.defaultView) == null ? void 0 : _a.navigator.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
- var _a;
335
- const clipboard = (_a = document2.defaultView) == null ? void 0 : _a.navigator.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 _a;
455
+ var _a3;
436
456
  if (!supportsMaxLength(element)) {
437
457
  return void 0;
438
458
  }
439
- const attr = (_a = element.getAttribute("maxlength")) != null ? _a : "";
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 _a, _b;
596
+ var _a3, _b;
577
597
  const valueParts = value.split("e", 2);
578
- return !(/[^\d.\-e]/.test(value) || Number((_a = value.match(/-/g)) == null ? void 0 : _a.length) > 2 || Number((_b = value.match(/\./g)) == null ? void 0 : _b.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1]));
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 _a;
608
- (_a = el[fakeFiles]) == null ? void 0 : _a.restore();
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 _a2;
646
+ var _a4;
627
647
  if (v === "") {
628
648
  restore();
629
649
  } else {
630
- (_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
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 _a;
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") && !((_a = el.querySelector(":scope > legend")) == null ? void 0 : _a.contains(element))) {
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 _a;
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 !== ((_a = node.ownerDocument) == null ? void 0 : _a.body))) {
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 _a;
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) && ((_a = element.firstChild) == null ? void 0 : _a.nodeType) === 3) {
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 _a;
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 = ((_a = contenteditable.firstChild) == null ? void 0 : _a.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
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 _a;
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 (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
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 _a, _b;
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 = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
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 = getWindowFromNode(element);
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 _a;
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 = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
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 _a;
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 = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
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 _a, _b, _c;
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] : (_a = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a[0];
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 _a;
1208
- (_a = config[Level]) != null ? _a : config[Level] = {};
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 _a;
1213
- return (_a = config[Level]) == null ? void 0 : _a[level];
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 = getWindowFromNode2(element);
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 _a, _b, _c, _d;
1447
+ var _a3, _b, _c, _d;
1432
1448
  assignProps(obj, {
1433
- x: (_a = x != null ? x : clientX) != null ? _a : 0,
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 _a, _b;
1488
- return (_b = (_a = keydownBehavior[event.key]) == null ? void 0 : _a.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(event, target, config);
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 _a, _b;
1511
- const newPos = (_b = (_a = getValue(target)) == null ? void 0 : _a.length) != null ? _b : 0;
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 _a;
1604
- return (_a = keyupBehavior[event.key]) == null ? void 0 : _a.call(keyupBehavior, event, target, config);
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 _a;
1619
- const insertData = (_a = event.clipboardData) == null ? void 0 : _a.getData("text");
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 _a, _b;
1651
+ var _a3, _b;
1636
1652
  const type3 = event.type;
1637
1653
  const behaviorImplementation = preventDefault ? () => {
1638
- } : (_b = (_a = behavior)[type3]) == null ? void 0 : _b.call(_a, event, target, config);
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;
@@ -1713,6 +1729,13 @@ function prepareSelectionInterceptor(element) {
1713
1729
  this[UISelection] = void 0;
1714
1730
  return { realArgs: v };
1715
1731
  });
1732
+ prepareInterceptor(element, "select", function interceptorImpl() {
1733
+ this[UISelection] = {
1734
+ anchorOffset: 0,
1735
+ focusOffset: getUIValue(element).length
1736
+ };
1737
+ return { realArgs: [] };
1738
+ });
1716
1739
  }
1717
1740
  function setUISelection(element, {
1718
1741
  focusOffset: focusOffsetParam,
@@ -1739,9 +1762,9 @@ function setUISelection(element, {
1739
1762
  }
1740
1763
  }
1741
1764
  function getUISelection(element) {
1742
- var _a, _b, _c;
1765
+ var _a3, _b, _c;
1743
1766
  const sel = (_c = element[UISelection]) != null ? _c : {
1744
- anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
1767
+ anchorOffset: (_a3 = element.selectionStart) != null ? _a3 : 0,
1745
1768
  focusOffset: (_b = element.selectionEnd) != null ? _b : 0
1746
1769
  };
1747
1770
  return __spreadProps(__spreadValues({}, sel), {
@@ -1801,8 +1824,8 @@ function startTrackValue(element) {
1801
1824
  });
1802
1825
  }
1803
1826
  function trackOrSetValue(element, v) {
1804
- var _a, _b, _c;
1805
- (_b = (_a = element[TrackChanges]) == null ? void 0 : _a.tracked) == null ? void 0 : _b.push(v);
1827
+ var _a3, _b, _c;
1828
+ (_b = (_a3 = element[TrackChanges]) == null ? void 0 : _a3.tracked) == null ? void 0 : _b.push(v);
1806
1829
  if (!((_c = element[TrackChanges]) == null ? void 0 : _c.tracked)) {
1807
1830
  setCleanValue(element, v);
1808
1831
  }
@@ -1813,10 +1836,10 @@ function setCleanValue(element, v) {
1813
1836
  setUISelection(element, { focusOffset: v.length });
1814
1837
  }
1815
1838
  function endTrackValue(element) {
1816
- var _a, _b;
1839
+ var _a3, _b;
1817
1840
  const changes = element[TrackChanges];
1818
1841
  element[TrackChanges] = void 0;
1819
- const isJustReactStateUpdate = ((_a = changes == null ? void 0 : changes.tracked) == null ? void 0 : _a.length) === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === changes.nextValue;
1842
+ 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
1843
  if (((_b = changes == null ? void 0 : changes.tracked) == null ? void 0 : _b.length) && !isJustReactStateUpdate) {
1821
1844
  setCleanValue(element, changes.tracked[changes.tracked.length - 1]);
1822
1845
  }
@@ -1889,11 +1912,11 @@ function isModifierLock(key) {
1889
1912
  return modifierLocks.includes(key);
1890
1913
  }
1891
1914
  function preKeydownBehavior(config, { key }, element) {
1892
- var _a;
1915
+ var _a3;
1893
1916
  if (isModifierKey(key)) {
1894
1917
  config.keyboardState.modifiers[key] = true;
1895
1918
  if (key === "AltGraph") {
1896
- const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
1919
+ const ctrlKeyDef = (_a3 = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a3 : { key: "Control", code: "Control" };
1897
1920
  dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
1898
1921
  }
1899
1922
  } else if (isModifierLock(key)) {
@@ -1913,9 +1936,9 @@ function preKeyupBehavior(config, { key }) {
1913
1936
  }
1914
1937
  }
1915
1938
  function postKeyupBehavior(config, { key }, element) {
1916
- var _a;
1939
+ var _a3;
1917
1940
  if (key === "AltGraph") {
1918
- const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
1941
+ const ctrlKeyDef = (_a3 = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a3 : { key: "Control", code: "Control" };
1919
1942
  dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
1920
1943
  }
1921
1944
  }
@@ -1957,8 +1980,8 @@ function keyboardKeyAction(_0, _1) {
1957
1980
  });
1958
1981
  }
1959
1982
  function getActive(document2) {
1960
- var _a;
1961
- return (_a = getActiveElement(document2)) != null ? _a : document2.body;
1983
+ var _a3;
1984
+ return (_a3 = getActiveElement(document2)) != null ? _a3 : document2.body;
1962
1985
  }
1963
1986
  function releaseAllKeys(config) {
1964
1987
  return __async(this, null, function* () {
@@ -2000,13 +2023,13 @@ function keyup(keyDef, getCurrentElement, config, unprevented) {
2000
2023
  });
2001
2024
  }
2002
2025
  function hasKeyPress(keyDef, config) {
2003
- var _a;
2004
- return (((_a = keyDef.key) == null ? void 0 : _a.length) === 1 || keyDef.key === "Enter") && !config.keyboardState.modifiers.Control && !config.keyboardState.modifiers.Alt;
2026
+ var _a3;
2027
+ return (((_a3 = keyDef.key) == null ? void 0 : _a3.length) === 1 || keyDef.key === "Enter") && !config.keyboardState.modifiers.Control && !config.keyboardState.modifiers.Alt;
2005
2028
  }
2006
2029
 
2007
2030
  // src/keyboard/parseKeyDef.ts
2008
2031
  function parseKeyDef(keyboardMap, text) {
2009
- var _a;
2032
+ var _a3;
2010
2033
  const defs = [];
2011
2034
  do {
2012
2035
  const {
@@ -2017,15 +2040,15 @@ function parseKeyDef(keyboardMap, text) {
2017
2040
  releaseSelf = true,
2018
2041
  repeat
2019
2042
  } = readNextDescriptor(text, "keyboard");
2020
- const keyDef = (_a = keyboardMap.find((def) => {
2021
- var _a2, _b;
2043
+ const keyDef = (_a3 = keyboardMap.find((def) => {
2044
+ var _a4, _b;
2022
2045
  if (type3 === "[") {
2023
- return ((_a2 = def.code) == null ? void 0 : _a2.toLowerCase()) === descriptor.toLowerCase();
2046
+ return ((_a4 = def.code) == null ? void 0 : _a4.toLowerCase()) === descriptor.toLowerCase();
2024
2047
  } else if (type3 === "{") {
2025
2048
  return ((_b = def.key) == null ? void 0 : _b.toLowerCase()) === descriptor.toLowerCase();
2026
2049
  }
2027
2050
  return def.key === descriptor;
2028
- })) != null ? _a : {
2051
+ })) != null ? _a3 : {
2029
2052
  key: "Unknown",
2030
2053
  code: "Unknown",
2031
2054
  [type3 === "[" ? "code" : "key"]: descriptor
@@ -2104,8 +2127,8 @@ function firePointerEvent(config, target, type3, {
2104
2127
  }
2105
2128
  init.button = getMouseButton(button != null ? button : 0);
2106
2129
  init.buttons = getMouseButtons(...config.pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
2107
- var _a;
2108
- return (_a = p.keyDef.button) != null ? _a : 0;
2130
+ var _a3;
2131
+ return (_a3 = p.keyDef.button) != null ? _a3 : 0;
2109
2132
  }));
2110
2133
  if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
2111
2134
  init.detail = clickCount;
@@ -2267,7 +2290,7 @@ function getNextPointerId(state) {
2267
2290
  return state.pointerId;
2268
2291
  }
2269
2292
  function down(config, pointerName, { keyDef, node, offset, target, coords }, targetIsDisabled) {
2270
- var _a, _b, _c;
2293
+ var _a3, _b, _c;
2271
2294
  setLevelRef(config, 2 /* Trigger */);
2272
2295
  assertPointerEvents(config, target);
2273
2296
  const { pointerState } = config;
@@ -2290,7 +2313,7 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
2290
2313
  }
2291
2314
  }
2292
2315
  }
2293
- if (((_a = pointerState.activeClickCount) == null ? void 0 : _a[0]) !== name) {
2316
+ if (((_a3 = pointerState.activeClickCount) == null ? void 0 : _a3[0]) !== name) {
2294
2317
  delete pointerState.activeClickCount;
2295
2318
  }
2296
2319
  const clickCount = Number((_c = (_b = pointerState.activeClickCount) == null ? void 0 : _b[1]) != null ? _c : 0) + 1;
@@ -2418,7 +2441,6 @@ function mousedownDefaultBehavior({
2418
2441
  node,
2419
2442
  offset
2420
2443
  }) {
2421
- focus(target);
2422
2444
  if (!targetIsDisabled) {
2423
2445
  const hasValue = isElementType(target, ["input", "textarea"]);
2424
2446
  const text = String(hasValue ? getUIValue(target) : target.textContent);
@@ -2444,7 +2466,7 @@ function mousedownDefaultBehavior({
2444
2466
  node,
2445
2467
  offset: end
2446
2468
  });
2447
- const range = new Range();
2469
+ const range = target.ownerDocument.createRange();
2448
2470
  range.setStart(startNode, startOffset);
2449
2471
  range.setEnd(endNode, endOffset);
2450
2472
  position.selectionRange = range;
@@ -2453,6 +2475,7 @@ function mousedownDefaultBehavior({
2453
2475
  selection.addRange(range.cloneRange());
2454
2476
  }
2455
2477
  }
2478
+ focus(target);
2456
2479
  }
2457
2480
  function getTextRange(text, pos, clickCount) {
2458
2481
  if (clickCount % 3 === 1 || text.length === 0) {
@@ -2474,11 +2497,11 @@ function getTextRange(text, pos, clickCount) {
2474
2497
  // src/pointer/pointerAction.ts
2475
2498
  function pointerAction(config, actions) {
2476
2499
  return __async(this, null, function* () {
2477
- var _a, _b;
2500
+ var _a3, _b;
2478
2501
  for (let i = 0; i < actions.length; i++) {
2479
2502
  const action = actions[i];
2480
2503
  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 = (_a = action.target) != null ? _a : getPrevTarget(pointerName, config.pointerState);
2504
+ const target = (_a3 = action.target) != null ? _a3 : getPrevTarget(pointerName, config.pointerState);
2482
2505
  const coords = (_b = action.coords) != null ? _b : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : void 0;
2483
2506
  yield "keyDef" in action ? pointerPress(config, __spreadProps(__spreadValues({}, action), { target, coords })) : pointerMove(config, __spreadProps(__spreadValues({}, action), { target, coords }));
2484
2507
  if (typeof config.delay === "number") {
@@ -2608,9 +2631,9 @@ function tab() {
2608
2631
  // src/clipboard/copy.ts
2609
2632
  function copy() {
2610
2633
  return __async(this, null, function* () {
2611
- var _a;
2634
+ var _a3;
2612
2635
  const doc = this[Config].document;
2613
- const target = (_a = doc.activeElement) != null ? _a : doc.body;
2636
+ const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
2614
2637
  const clipboardData = copySelection(target);
2615
2638
  if (clipboardData.items.length === 0) {
2616
2639
  return;
@@ -2627,9 +2650,9 @@ function copy() {
2627
2650
  // src/clipboard/cut.ts
2628
2651
  function cut() {
2629
2652
  return __async(this, null, function* () {
2630
- var _a;
2653
+ var _a3;
2631
2654
  const doc = this[Config].document;
2632
- const target = (_a = doc.activeElement) != null ? _a : doc.body;
2655
+ const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
2633
2656
  const clipboardData = copySelection(target);
2634
2657
  if (clipboardData.items.length === 0) {
2635
2658
  return;
@@ -2646,10 +2669,10 @@ function cut() {
2646
2669
  // src/clipboard/paste.ts
2647
2670
  function paste(clipboardData) {
2648
2671
  return __async(this, null, function* () {
2649
- var _a, _b;
2672
+ var _a3, _b;
2650
2673
  const doc = this[Config].document;
2651
- const target = (_a = doc.activeElement) != null ? _a : doc.body;
2652
- const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _b : yield readDataTransferFromClipboard(doc).catch(() => {
2674
+ const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
2675
+ const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(doc, clipboardData) : clipboardData) != null ? _b : yield readDataTransferFromClipboard(doc).catch(() => {
2653
2676
  throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
2654
2677
  });
2655
2678
  this.dispatchUIEvent(target, "paste", {
@@ -2657,8 +2680,8 @@ function paste(clipboardData) {
2657
2680
  });
2658
2681
  });
2659
2682
  }
2660
- function getClipboardDataFromString(text) {
2661
- const dt = createDataTransfer();
2683
+ function getClipboardDataFromString(doc, text) {
2684
+ const dt = createDataTransfer(getWindow(doc));
2662
2685
  dt.setData("text", text);
2663
2686
  return dt;
2664
2687
  }
@@ -2812,10 +2835,10 @@ function upload(element, fileOrFiles) {
2812
2835
  return;
2813
2836
  const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input2.accept)).slice(0, input2.multiple ? void 0 : 1);
2814
2837
  const fileDialog = () => {
2815
- var _a;
2816
- if (files.length === ((_a = input2.files) == null ? void 0 : _a.length) && files.every((f, i) => {
2817
- var _a2;
2818
- return f === ((_a2 = input2.files) == null ? void 0 : _a2.item(i));
2838
+ var _a3;
2839
+ if (files.length === ((_a3 = input2.files) == null ? void 0 : _a3.length) && files.every((f, i) => {
2840
+ var _a4;
2841
+ return f === ((_a4 = input2.files) == null ? void 0 : _a4.item(i));
2819
2842
  })) {
2820
2843
  return;
2821
2844
  }
@@ -2863,10 +2886,10 @@ function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
2863
2886
  });
2864
2887
  }
2865
2888
  function setupMain(options = {}) {
2866
- var _a;
2889
+ var _a3;
2867
2890
  const config = createConfig(options);
2868
2891
  prepareDocument(config.document);
2869
- const view = (_a = config.document.defaultView) != null ? _a : window;
2892
+ const view = (_a3 = config.document.defaultView) != null ? _a3 : window;
2870
2893
  attachClipboardStubToView(view);
2871
2894
  return doSetup(config);
2872
2895
  }
@@ -2902,8 +2925,8 @@ function doSetup(config) {
2902
2925
  });
2903
2926
  }
2904
2927
  function getDocument(options, node) {
2905
- var _a, _b;
2906
- return (_b = (_a = options.document) != null ? _a : node && getDocumentFromNode(node)) != null ? _b : document;
2928
+ var _a3, _b;
2929
+ return (_b = (_a3 = options.document) != null ? _a3 : node && getDocumentFromNode(node)) != null ? _b : document;
2907
2930
  }
2908
2931
 
2909
2932
  // src/setup/directApi.ts