@testing-library/user-event 14.0.0-beta.5 → 14.0.0-beta.9

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.
Files changed (48) hide show
  1. package/README.md +5 -192
  2. package/dist/index.cjs +860 -617
  3. package/dist/index.mjs +861 -618
  4. package/dist/types/clipboard/copy.d.ts +2 -2
  5. package/dist/types/clipboard/cut.d.ts +2 -2
  6. package/dist/types/clipboard/paste.d.ts +2 -2
  7. package/dist/types/convenience/click.d.ts +4 -4
  8. package/dist/types/convenience/hover.d.ts +3 -3
  9. package/dist/types/convenience/tab.d.ts +2 -2
  10. package/dist/types/event/behavior/click.d.ts +1 -0
  11. package/dist/types/event/behavior/index.d.ts +3 -0
  12. package/dist/types/event/behavior/registry.d.ts +9 -0
  13. package/dist/types/event/createEvent.d.ts +8 -0
  14. package/dist/types/event/dispatchEvent.d.ts +2 -0
  15. package/dist/types/event/eventTypes.d.ts +2 -0
  16. package/dist/types/event/index.d.ts +6 -0
  17. package/dist/types/event/types.d.ts +13 -0
  18. package/dist/types/event/wrapEvent.d.ts +1 -0
  19. package/dist/types/index.d.ts +1 -0
  20. package/dist/types/keyboard/index.d.ts +2 -2
  21. package/dist/types/keyboard/shared/fireChangeForInputTimeIfValid.d.ts +2 -1
  22. package/dist/types/options.d.ts +23 -8
  23. package/dist/types/pointer/firePointerEvents.d.ts +11 -0
  24. package/dist/types/pointer/index.d.ts +2 -2
  25. package/dist/types/pointer/pointerMove.d.ts +2 -2
  26. package/dist/types/pointer/pointerPress.d.ts +2 -2
  27. package/dist/types/pointer/types.d.ts +2 -1
  28. package/dist/types/setup/directApi.d.ts +1 -2
  29. package/dist/types/setup/index.d.ts +8 -2
  30. package/dist/types/setup/setup.d.ts +6 -60
  31. package/dist/types/utility/clear.d.ts +2 -2
  32. package/dist/types/utility/selectOptions.d.ts +3 -3
  33. package/dist/types/utility/type.d.ts +2 -2
  34. package/dist/types/utility/upload.d.ts +2 -2
  35. package/dist/types/utils/edit/editInputElement.d.ts +3 -5
  36. package/dist/types/utils/edit/prepareInput.d.ts +2 -1
  37. package/dist/types/utils/focus/cursor.d.ts +9 -0
  38. package/dist/types/utils/focus/focus.d.ts +3 -0
  39. package/dist/types/utils/index.d.ts +4 -2
  40. package/dist/types/utils/keyboard/getKeyEventProps.d.ts +2 -14
  41. package/dist/types/utils/misc/cloneEvent.d.ts +1 -0
  42. package/dist/types/utils/misc/findClosest.d.ts +1 -1
  43. package/dist/types/utils/misc/level.d.ts +17 -0
  44. package/dist/types/utils/pointer/cssPointerEvents.d.ts +15 -0
  45. package/package.json +1 -1
  46. package/CHANGELOG.md +0 -5
  47. package/dist/types/utils/misc/hasPointerEvents.d.ts +0 -15
  48. package/dist/types/utils/pointer/firePointerEvents.d.ts +0 -25
package/dist/index.cjs CHANGED
@@ -41,190 +41,10 @@ var __toCommonJS = /* @__PURE__ */ ((cache) => {
41
41
  // src/index.ts
42
42
  var src_exports = {};
43
43
  __export(src_exports, {
44
+ PointerEventsCheckLevel: () => PointerEventsCheckLevel,
44
45
  default: () => userEvent
45
46
  });
46
47
 
47
- // src/document/index.ts
48
- var import_dom = require("@testing-library/dom");
49
-
50
- // src/document/interceptor.ts
51
- var Interceptor = Symbol("Interceptor for programmatical calls");
52
- function prepareInterceptor(element, propName, interceptorImpl) {
53
- const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
54
- const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
55
- const target = (prototypeDescriptor == null ? void 0 : prototypeDescriptor.set) ? "set" : "value";
56
- if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== "function" || prototypeDescriptor[target][Interceptor]) {
57
- return;
58
- }
59
- function intercept(...args) {
60
- const { applyNative = true, realArgs } = interceptorImpl.call(this, ...args);
61
- const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
62
- if (target === "set") {
63
- realFunc.call(this, realArgs);
64
- } else {
65
- realFunc.call(this, ...realArgs);
66
- }
67
- }
68
- ;
69
- intercept[Interceptor] = Interceptor;
70
- Object.defineProperty(element, propName, __spreadProps(__spreadValues({}, objectDescriptor != null ? objectDescriptor : prototypeDescriptor), {
71
- [target]: intercept
72
- }));
73
- }
74
-
75
- // src/document/selection.ts
76
- var UISelection = Symbol("Displayed selection in UI");
77
- function prepareSelectionInterceptor(element) {
78
- prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, end, direction = "none") {
79
- const isUI = start && typeof start === "object" && start[UISelection];
80
- if (!isUI) {
81
- this[UISelection] = void 0;
82
- }
83
- return {
84
- realArgs: [Number(start), end, direction]
85
- };
86
- });
87
- prepareInterceptor(element, "selectionStart", function interceptorImpl(v) {
88
- this[UISelection] = void 0;
89
- return { realArgs: v };
90
- });
91
- prepareInterceptor(element, "selectionEnd", function interceptorImpl(v) {
92
- this[UISelection] = void 0;
93
- return { realArgs: v };
94
- });
95
- }
96
- function setUISelection(element, {
97
- focusOffset: focusOffsetParam,
98
- anchorOffset: anchorOffsetParam = focusOffsetParam
99
- }, mode = "replace") {
100
- const valueLength = getUIValue(element).length;
101
- const sanitizeOffset = (o) => Math.max(0, Math.min(valueLength, o));
102
- const anchorOffset = mode === "replace" || element[UISelection] === void 0 ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
103
- const focusOffset = sanitizeOffset(focusOffsetParam);
104
- const startOffset = Math.min(anchorOffset, focusOffset);
105
- const endOffset = Math.max(anchorOffset, focusOffset);
106
- element[UISelection] = {
107
- anchorOffset,
108
- focusOffset
109
- };
110
- if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
111
- return;
112
- }
113
- const startObj = new Number(startOffset);
114
- startObj[UISelection] = UISelection;
115
- try {
116
- element.setSelectionRange(startObj, endOffset);
117
- } catch {
118
- }
119
- }
120
- function getUISelection(element) {
121
- var _a, _b, _c;
122
- const sel = (_c = element[UISelection]) != null ? _c : {
123
- anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
124
- focusOffset: (_b = element.selectionEnd) != null ? _b : 0
125
- };
126
- return __spreadProps(__spreadValues({}, sel), {
127
- startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
128
- endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
129
- });
130
- }
131
- function clearUISelection(element) {
132
- element[UISelection] = void 0;
133
- }
134
-
135
- // src/document/value.ts
136
- var UIValue = Symbol("Displayed value in UI");
137
- var InitialValue = Symbol("Initial value to compare on blur");
138
- var TrackChanges = Symbol("Track programmatic changes for React workaround");
139
- function valueInterceptor(v) {
140
- const isUI = typeof v === "object" && v[UIValue];
141
- this[UIValue] = isUI ? String(v) : void 0;
142
- if (!isUI) {
143
- trackValue(this, String(v));
144
- this[InitialValue] = String(v);
145
- clearUISelection(this);
146
- }
147
- return {
148
- applyNative: !!isUI,
149
- realArgs: String(v)
150
- };
151
- }
152
- function prepareValueInterceptor(element) {
153
- prepareInterceptor(element, "value", valueInterceptor);
154
- }
155
- function setUIValue(element, value) {
156
- element.value = {
157
- [UIValue]: UIValue,
158
- toString: () => value
159
- };
160
- }
161
- function getUIValue(element) {
162
- return element[UIValue] === void 0 ? element.value : String(element[UIValue]);
163
- }
164
- function setInitialValue(element) {
165
- element[InitialValue] = element.value;
166
- }
167
- function getInitialValue(element) {
168
- return element[InitialValue];
169
- }
170
- function startTrackValue(element) {
171
- element[TrackChanges] = [];
172
- }
173
- function trackValue(element, v) {
174
- var _a;
175
- (_a = element[TrackChanges]) == null ? void 0 : _a.push(v);
176
- }
177
- function endTrackValue(element) {
178
- const tracked = element[TrackChanges];
179
- element[TrackChanges] = void 0;
180
- return tracked;
181
- }
182
-
183
- // src/document/index.ts
184
- var isPrepared = Symbol("Node prepared with document state workarounds");
185
- function prepareDocument(document2) {
186
- if (document2[isPrepared]) {
187
- return;
188
- }
189
- document2.addEventListener("focus", (e) => {
190
- const el = e.target;
191
- prepareElement(el);
192
- }, {
193
- capture: true,
194
- passive: true
195
- });
196
- if (document2.activeElement) {
197
- prepareElement(document2.activeElement);
198
- }
199
- document2.addEventListener("blur", (e) => {
200
- const el = e.target;
201
- const initialValue = getInitialValue(el);
202
- if (typeof initialValue === "string" && el.value !== initialValue) {
203
- import_dom.fireEvent.change(el);
204
- }
205
- }, {
206
- capture: true,
207
- passive: true
208
- });
209
- document2[isPrepared] = isPrepared;
210
- }
211
- function prepareElement(el) {
212
- if ("value" in el) {
213
- setInitialValue(el);
214
- }
215
- if (el[isPrepared]) {
216
- return;
217
- }
218
- if ("value" in el) {
219
- prepareValueInterceptor(el);
220
- prepareSelectionInterceptor(el);
221
- }
222
- el[isPrepared] = isPrepared;
223
- }
224
-
225
- // src/keyboard/keyboardAction.ts
226
- var import_dom10 = require("@testing-library/dom");
227
-
228
48
  // src/utils/misc/isElementType.ts
229
49
  function isElementType(element, tag, props) {
230
50
  if (element.namespaceURI && element.namespaceURI !== "http://www.w3.org/1999/xhtml") {
@@ -594,9 +414,6 @@ function calculateNewValue(inputData, node, {
594
414
  };
595
415
  }
596
416
 
597
- // src/utils/edit/editInputElement.ts
598
- var import_dom2 = require("@testing-library/dom");
599
-
600
417
  // src/utils/edit/isContentEditable.ts
601
418
  function isContentEditable(element) {
602
419
  return element.hasAttribute("contenteditable") && (element.getAttribute("contenteditable") == "true" || element.getAttribute("contenteditable") == "");
@@ -720,7 +537,7 @@ function setSelection({
720
537
  }
721
538
 
722
539
  // src/utils/edit/editInputElement.ts
723
- function editInputElement(element, {
540
+ function editInputElement(config, element, {
724
541
  newValue,
725
542
  newSelection,
726
543
  eventOverrides
@@ -733,7 +550,7 @@ function editInputElement(element, {
733
550
  focusOffset: newSelection.offset
734
551
  });
735
552
  startTrackValue(element);
736
- import_dom2.fireEvent.input(element, __spreadValues({}, eventOverrides));
553
+ dispatchUIEvent(config, element, "input", eventOverrides);
737
554
  const tracked = endTrackValue(element);
738
555
  if ((tracked == null ? void 0 : tracked.length) === 2 && tracked[0] === oldValue && tracked[1] === newValue) {
739
556
  setSelection({
@@ -785,9 +602,111 @@ function supportsMaxLength(element) {
785
602
  return isElementType(element, "textarea") || isElementType(element, "input") && Boolean(maxLengthSupportedTypes[element.type]);
786
603
  }
787
604
 
605
+ // src/utils/focus/cursor.ts
606
+ function getNextCursorPosition(node, offset, direction, inputType) {
607
+ if (isTextNode(node) && offset + direction >= 0 && offset + direction <= node.nodeValue.length) {
608
+ return { node, offset: offset + direction };
609
+ }
610
+ const nextNode = getNextCharacterContentNode(node, offset, direction);
611
+ if (nextNode) {
612
+ if (isTextNode(nextNode)) {
613
+ return {
614
+ node: nextNode,
615
+ offset: direction > 0 ? Math.min(1, nextNode.nodeValue.length) : Math.max(nextNode.nodeValue.length - 1, 0)
616
+ };
617
+ } else if (isElementType(nextNode, "br")) {
618
+ const nextPlusOne = getNextCharacterContentNode(nextNode, void 0, direction);
619
+ if (!nextPlusOne) {
620
+ if (direction < 0 && inputType === "deleteContentBackward") {
621
+ return {
622
+ node: nextNode.parentNode,
623
+ offset: getOffset(nextNode)
624
+ };
625
+ }
626
+ return void 0;
627
+ } else if (isTextNode(nextPlusOne)) {
628
+ return {
629
+ node: nextPlusOne,
630
+ offset: direction > 0 ? 0 : nextPlusOne.nodeValue.length
631
+ };
632
+ } else if (direction < 0 && isElementType(nextPlusOne, "br")) {
633
+ return {
634
+ node: nextNode.parentNode,
635
+ offset: getOffset(nextNode)
636
+ };
637
+ } else {
638
+ return {
639
+ node: nextPlusOne.parentNode,
640
+ offset: getOffset(nextPlusOne) + (direction > 0 ? 0 : 1)
641
+ };
642
+ }
643
+ } else {
644
+ return {
645
+ node: nextNode.parentNode,
646
+ offset: getOffset(nextNode) + (direction > 0 ? 1 : 0)
647
+ };
648
+ }
649
+ }
650
+ }
651
+ function getNextCharacterContentNode(node, offset, direction) {
652
+ const nextOffset = Number(offset) + (direction < 0 ? -1 : 0);
653
+ if (offset !== void 0 && isElement2(node) && nextOffset >= 0 && nextOffset < node.children.length) {
654
+ node = node.children[nextOffset];
655
+ }
656
+ return walkNodes(node, direction === 1 ? "next" : "previous", isTreatedAsCharacterContent);
657
+ }
658
+ function isTreatedAsCharacterContent(node) {
659
+ if (isTextNode(node)) {
660
+ return true;
661
+ }
662
+ if (isElement2(node)) {
663
+ if (isElementType(node, ["input", "textarea"])) {
664
+ return node.type !== "hidden";
665
+ } else if (isElementType(node, "br")) {
666
+ return true;
667
+ }
668
+ }
669
+ return false;
670
+ }
671
+ function getOffset(node) {
672
+ let i = 0;
673
+ while (node.previousSibling) {
674
+ i++;
675
+ node = node.previousSibling;
676
+ }
677
+ return i;
678
+ }
679
+ function isElement2(node) {
680
+ return node.nodeType === 1;
681
+ }
682
+ function isTextNode(node) {
683
+ return node.nodeType === 3;
684
+ }
685
+ function walkNodes(node, direction, callback) {
686
+ var _a;
687
+ for (; ; ) {
688
+ const sibling = node[`${direction}Sibling`];
689
+ if (sibling) {
690
+ node = getDescendant(sibling, direction === "next" ? "first" : "last");
691
+ if (callback(node)) {
692
+ return node;
693
+ }
694
+ } else if (node.parentNode && (!isElement2(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a = node.ownerDocument) == null ? void 0 : _a.body))) {
695
+ node = node.parentNode;
696
+ } else {
697
+ break;
698
+ }
699
+ }
700
+ }
701
+ function getDescendant(node, direction) {
702
+ while (node.hasChildNodes()) {
703
+ node = node[`${direction}Child`];
704
+ }
705
+ return node;
706
+ }
707
+
788
708
  // src/utils/edit/prepareInput.ts
789
- var import_dom3 = require("@testing-library/dom");
790
- function prepareInput(data, element, inputType = "insertText") {
709
+ function prepareInput(config, data, element, inputType = "insertText") {
791
710
  const inputRange = getInputRange(element);
792
711
  if (!inputRange) {
793
712
  return;
@@ -795,9 +714,22 @@ function prepareInput(data, element, inputType = "insertText") {
795
714
  if ("startContainer" in inputRange) {
796
715
  return {
797
716
  commit: () => {
798
- const del = !inputRange.collapsed;
799
- if (del) {
717
+ let del = false;
718
+ if (!inputRange.collapsed) {
719
+ del = true;
800
720
  inputRange.deleteContents();
721
+ } else if (["deleteContentBackward", "deleteContentForward"].includes(inputType)) {
722
+ const nextPosition = getNextCursorPosition(inputRange.startContainer, inputRange.startOffset, inputType === "deleteContentBackward" ? -1 : 1, inputType);
723
+ if (nextPosition) {
724
+ del = true;
725
+ const delRange = inputRange.cloneRange();
726
+ if (delRange.comparePoint(nextPosition.node, nextPosition.offset) < 0) {
727
+ delRange.setStart(nextPosition.node, nextPosition.offset);
728
+ } else {
729
+ delRange.setEnd(nextPosition.node, nextPosition.offset);
730
+ }
731
+ delRange.deleteContents();
732
+ }
801
733
  }
802
734
  if (data) {
803
735
  if (inputRange.endContainer.nodeType === 3) {
@@ -813,7 +745,7 @@ function prepareInput(data, element, inputType = "insertText") {
813
745
  }
814
746
  }
815
747
  if (del || data) {
816
- import_dom3.fireEvent.input(element, { inputType });
748
+ dispatchUIEvent(config, element, "input", { inputType });
817
749
  }
818
750
  }
819
751
  };
@@ -825,7 +757,7 @@ function prepareInput(data, element, inputType = "insertText") {
825
757
  if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
826
758
  return;
827
759
  }
828
- editInputElement(element, {
760
+ editInputElement(config, element, {
829
761
  newValue,
830
762
  newSelection: {
831
763
  node: element,
@@ -882,10 +814,10 @@ function setFiles(el, files) {
882
814
  }
883
815
 
884
816
  // src/utils/misc/eventWrapper.ts
885
- var import_dom4 = require("@testing-library/dom");
817
+ var import_dom = require("@testing-library/dom");
886
818
  function eventWrapper(cb) {
887
819
  let result;
888
- (0, import_dom4.getConfig)().eventWrapper(() => {
820
+ (0, import_dom.getConfig)().eventWrapper(() => {
889
821
  result = cb();
890
822
  });
891
823
  return result;
@@ -953,15 +885,30 @@ function readSelectedValueFromInput(target) {
953
885
  return val.substring(sel.startOffset, sel.endOffset);
954
886
  }
955
887
 
888
+ // src/utils/misc/findClosest.ts
889
+ function findClosest(element, callback) {
890
+ let el = element;
891
+ do {
892
+ if (callback(el)) {
893
+ return el;
894
+ }
895
+ el = el.parentElement;
896
+ } while (el && el !== element.ownerDocument.body);
897
+ return void 0;
898
+ }
899
+
956
900
  // src/utils/focus/focus.ts
957
901
  function focus(element) {
958
- if (!isFocusable(element))
902
+ const target = findClosest(element, isFocusable);
903
+ const activeElement = getActiveElement(element.ownerDocument);
904
+ if ((target != null ? target : element.ownerDocument.body) === activeElement) {
959
905
  return;
960
- const isAlreadyActive = getActiveElement(element.ownerDocument) === element;
961
- if (isAlreadyActive)
962
- return;
963
- eventWrapper(() => element.focus());
964
- updateSelectionOnFocus(element);
906
+ } else if (target) {
907
+ eventWrapper(() => target.focus());
908
+ } else {
909
+ eventWrapper(() => activeElement == null ? void 0 : activeElement.blur());
910
+ }
911
+ updateSelectionOnFocus(target != null ? target : element.ownerDocument.body);
965
912
  }
966
913
 
967
914
  // src/utils/misc/isVisible.ts
@@ -1058,6 +1005,14 @@ function isAllSelected(target) {
1058
1005
  return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
1059
1006
  }
1060
1007
 
1008
+ // src/utils/keyboard/getKeyEventProps.ts
1009
+ function getKeyEventProps(keyDef) {
1010
+ return {
1011
+ key: keyDef.key,
1012
+ code: keyDef.code
1013
+ };
1014
+ }
1015
+
1061
1016
  // src/utils/keyboard/getUIEventModifiers.ts
1062
1017
  function getUIEventModifiers(keyboardState) {
1063
1018
  return {
@@ -1076,14 +1031,6 @@ function getUIEventModifiers(keyboardState) {
1076
1031
  };
1077
1032
  }
1078
1033
 
1079
- // src/utils/keyboard/getKeyEventProps.ts
1080
- function getKeyEventProps(keyDef, state) {
1081
- return __spreadValues({
1082
- key: keyDef.key,
1083
- code: keyDef.code
1084
- }, getUIEventModifiers(state));
1085
- }
1086
-
1087
1034
  // src/utils/keyDef/readNextDescriptor.ts
1088
1035
  var bracketDict = /* @__PURE__ */ ((bracketDict2) => {
1089
1036
  bracketDict2["{"] = "}";
@@ -1162,16 +1109,9 @@ function getErrorMessage(expected, found, text) {
1162
1109
  for more information about how userEvent parses your input.`;
1163
1110
  }
1164
1111
 
1165
- // src/utils/misc/findClosest.ts
1166
- function findClosest(element, callback) {
1167
- let el = element;
1168
- do {
1169
- if (callback(el)) {
1170
- return el;
1171
- }
1172
- el = el.parentElement;
1173
- } while (el && el !== element.ownerDocument.body);
1174
- return void 0;
1112
+ // src/utils/misc/cloneEvent.ts
1113
+ function cloneEvent(event) {
1114
+ return new event.constructor(event.type, event);
1175
1115
  }
1176
1116
 
1177
1117
  // src/utils/misc/getDocumentFromNode.ts
@@ -1194,13 +1134,121 @@ function isDescendantOrSelf(potentialDescendant, potentialAncestor) {
1194
1134
  return false;
1195
1135
  }
1196
1136
 
1137
+ // src/utils/misc/level.ts
1138
+ var Level = Symbol("Api level refs");
1139
+ function setLevelRef(config, level) {
1140
+ var _a;
1141
+ (_a = config[Level]) != null ? _a : config[Level] = {};
1142
+ config[Level][level] = {};
1143
+ }
1144
+ function getLevelRef(config, level) {
1145
+ var _a;
1146
+ return (_a = config[Level]) == null ? void 0 : _a[level];
1147
+ }
1148
+
1197
1149
  // src/utils/misc/wait.ts
1198
1150
  function wait(time) {
1199
1151
  return new Promise((resolve) => setTimeout(() => resolve(), time));
1200
1152
  }
1201
1153
 
1202
- // src/utils/misc/hasPointerEvents.ts
1154
+ // src/utils/misc/hasFormSubmit.ts
1155
+ var hasFormSubmit = (form) => !!(form == null ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]'));
1156
+
1157
+ // src/utils/pointer/cssPointerEvents.ts
1203
1158
  var import_helpers2 = require("@testing-library/dom/dist/helpers.js");
1159
+
1160
+ // src/keyboard/keyMap.ts
1161
+ var defaultKeyMap = [
1162
+ ..."0123456789".split("").map((c) => ({ code: `Digit${c}`, key: c })),
1163
+ ...")!@#$%^&*(".split("").map((c, i) => ({ code: `Digit${i}`, key: c, shiftKey: true })),
1164
+ ..."abcdefghijklmnopqrstuvwxyz".split("").map((c) => ({ code: `Key${c.toUpperCase()}`, key: c })),
1165
+ ..."ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("").map((c) => ({ code: `Key${c}`, key: c, shiftKey: true })),
1166
+ { code: "Space", key: " " },
1167
+ { code: "AltLeft", key: "Alt", location: 1 /* LEFT */ },
1168
+ { code: "AltRight", key: "Alt", location: 2 /* RIGHT */ },
1169
+ {
1170
+ code: "ShiftLeft",
1171
+ key: "Shift",
1172
+ location: 1 /* LEFT */
1173
+ },
1174
+ {
1175
+ code: "ShiftRight",
1176
+ key: "Shift",
1177
+ location: 2 /* RIGHT */
1178
+ },
1179
+ {
1180
+ code: "ControlLeft",
1181
+ key: "Control",
1182
+ location: 1 /* LEFT */
1183
+ },
1184
+ {
1185
+ code: "ControlRight",
1186
+ key: "Control",
1187
+ location: 2 /* RIGHT */
1188
+ },
1189
+ { code: "MetaLeft", key: "Meta", location: 1 /* LEFT */ },
1190
+ {
1191
+ code: "MetaRight",
1192
+ key: "Meta",
1193
+ location: 2 /* RIGHT */
1194
+ },
1195
+ { code: "OSLeft", key: "OS", location: 1 /* LEFT */ },
1196
+ { code: "OSRight", key: "OS", location: 2 /* RIGHT */ },
1197
+ { code: "Tab", key: "Tab" },
1198
+ { code: "CapsLock", key: "CapsLock" },
1199
+ { code: "Backspace", key: "Backspace" },
1200
+ { code: "Enter", key: "Enter" },
1201
+ { code: "Escape", key: "Escape" },
1202
+ { code: "ArrowUp", key: "ArrowUp" },
1203
+ { code: "ArrowDown", key: "ArrowDown" },
1204
+ { code: "ArrowLeft", key: "ArrowLeft" },
1205
+ { code: "ArrowRight", key: "ArrowRight" },
1206
+ { code: "Home", key: "Home" },
1207
+ { code: "End", key: "End" },
1208
+ { code: "Delete", key: "Delete" },
1209
+ { code: "PageUp", key: "PageUp" },
1210
+ { code: "PageDown", key: "PageDown" },
1211
+ { code: "Fn", key: "Fn" },
1212
+ { code: "Symbol", key: "Symbol" },
1213
+ { code: "AltRight", key: "AltGraph" }
1214
+ ];
1215
+
1216
+ // src/pointer/keyMap.ts
1217
+ var defaultKeyMap2 = [
1218
+ { name: "MouseLeft", pointerType: "mouse", button: "primary" },
1219
+ { name: "MouseRight", pointerType: "mouse", button: "secondary" },
1220
+ { name: "MouseMiddle", pointerType: "mouse", button: "auxiliary" },
1221
+ { name: "TouchA", pointerType: "touch" },
1222
+ { name: "TouchB", pointerType: "touch" },
1223
+ { name: "TouchC", pointerType: "touch" }
1224
+ ];
1225
+
1226
+ // src/options.ts
1227
+ var PointerEventsCheckLevel = /* @__PURE__ */ ((PointerEventsCheckLevel2) => {
1228
+ PointerEventsCheckLevel2[PointerEventsCheckLevel2["EachTrigger"] = 4] = "EachTrigger";
1229
+ PointerEventsCheckLevel2[PointerEventsCheckLevel2["EachApiCall"] = 2] = "EachApiCall";
1230
+ PointerEventsCheckLevel2[PointerEventsCheckLevel2["EachTarget"] = 1] = "EachTarget";
1231
+ PointerEventsCheckLevel2[PointerEventsCheckLevel2["Never"] = 0] = "Never";
1232
+ return PointerEventsCheckLevel2;
1233
+ })(PointerEventsCheckLevel || {});
1234
+ var defaultOptionsDirect = {
1235
+ applyAccept: true,
1236
+ autoModify: true,
1237
+ delay: 0,
1238
+ document: global.document,
1239
+ keyboardMap: defaultKeyMap,
1240
+ pointerMap: defaultKeyMap2,
1241
+ pointerEventsCheck: 2 /* EachApiCall */,
1242
+ skipAutoClose: false,
1243
+ skipClick: false,
1244
+ skipHover: false,
1245
+ writeToClipboard: false
1246
+ };
1247
+ var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect), {
1248
+ writeToClipboard: true
1249
+ });
1250
+
1251
+ // src/utils/pointer/cssPointerEvents.ts
1204
1252
  function hasPointerEvents(element) {
1205
1253
  const window2 = (0, import_helpers2.getWindowFromNode)(element);
1206
1254
  for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
@@ -1211,13 +1259,26 @@ function hasPointerEvents(element) {
1211
1259
  }
1212
1260
  return true;
1213
1261
  }
1214
-
1215
- // src/utils/misc/hasFormSubmit.ts
1216
- var hasFormSubmit = (form) => !!(form == null ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]'));
1217
-
1218
- // src/utils/pointer/firePointerEvents.ts
1219
- var import_dom5 = require("@testing-library/dom");
1220
- var import_event_map = require("@testing-library/dom/dist/event-map.js");
1262
+ var PointerEventsCheck = Symbol("Last check for pointer-events");
1263
+ function assertPointerEvents(config, element) {
1264
+ const lastCheck = element[PointerEventsCheck];
1265
+ const needsCheck = config.pointerEventsCheck !== 0 /* Never */ && (!lastCheck || hasBitFlag(config.pointerEventsCheck, 2 /* EachApiCall */) && lastCheck[1 /* Call */] !== getLevelRef(config, 1 /* Call */) || hasBitFlag(config.pointerEventsCheck, 4 /* EachTrigger */) && lastCheck[2 /* Trigger */] !== getLevelRef(config, 2 /* Trigger */));
1266
+ if (!needsCheck) {
1267
+ return;
1268
+ }
1269
+ const result = hasPointerEvents(element);
1270
+ element[PointerEventsCheck] = {
1271
+ [1 /* Call */]: getLevelRef(config, 1 /* Call */),
1272
+ [2 /* Trigger */]: getLevelRef(config, 2 /* Trigger */),
1273
+ result
1274
+ };
1275
+ if (!result) {
1276
+ throw new Error('Unable to perform pointer interaction as the element has or inherits pointer-events set to "none".');
1277
+ }
1278
+ }
1279
+ function hasBitFlag(conf, flag) {
1280
+ return (conf & flag) > 0;
1281
+ }
1221
1282
 
1222
1283
  // src/utils/pointer/mouseButtons.ts
1223
1284
  var MouseButton = {
@@ -1250,88 +1311,342 @@ function getMouseButtons(...buttons) {
1250
1311
  return v;
1251
1312
  }
1252
1313
 
1253
- // src/utils/pointer/firePointerEvents.ts
1254
- function firePointerEvent(target, type3, {
1255
- pointerState,
1256
- keyboardState,
1257
- pointerType,
1258
- button,
1259
- coords,
1260
- pointerId,
1261
- isPrimary,
1262
- clickCount
1314
+ // src/event/createEvent.ts
1315
+ var import_dom2 = require("@testing-library/dom");
1316
+ var import_event_map2 = require("@testing-library/dom/dist/event-map.js");
1317
+
1318
+ // src/event/eventTypes.ts
1319
+ var import_event_map = require("@testing-library/dom/dist/event-map.js");
1320
+ var eventKeys = Object.fromEntries(Object.keys(import_event_map.eventMap).map((k) => [k.toLowerCase(), k]));
1321
+ function getEventClass(type3) {
1322
+ return import_event_map.eventMap[eventKeys[type3]].EventType;
1323
+ }
1324
+ var mouseEvents = ["MouseEvent", "PointerEvent"];
1325
+ function isMouseEvent(type3) {
1326
+ return mouseEvents.includes(getEventClass(type3));
1327
+ }
1328
+ function isKeyboardEvent(type3) {
1329
+ return getEventClass(type3) === "KeyboardEvent";
1330
+ }
1331
+
1332
+ // src/event/createEvent.ts
1333
+ function createEvent(type3, target, init) {
1334
+ const eventKey = Object.keys(import_event_map2.eventMap).find((k) => k.toLowerCase() === type3);
1335
+ const event = import_dom2.createEvent[eventKey](target, init);
1336
+ if (isMouseEvent(type3) && init) {
1337
+ assignPositionInit(event, init);
1338
+ assignPointerInit(event, init);
1339
+ }
1340
+ return event;
1341
+ }
1342
+ function assignProps(obj, props) {
1343
+ for (const [key, value] of Object.entries(props)) {
1344
+ Object.defineProperty(obj, key, { get: () => value });
1345
+ }
1346
+ }
1347
+ function assignPositionInit(obj, {
1348
+ x,
1349
+ y,
1350
+ clientX,
1351
+ clientY,
1352
+ offsetX,
1353
+ offsetY,
1354
+ pageX,
1355
+ pageY,
1356
+ screenX,
1357
+ screenY
1263
1358
  }) {
1264
- const init = __spreadValues(__spreadValues({}, coords), getUIEventModifiers(keyboardState));
1265
- if (type3 === "click" || type3.startsWith("pointer")) {
1266
- init.pointerId = pointerId;
1267
- init.pointerType = pointerType;
1359
+ var _a, _b, _c, _d;
1360
+ assignProps(obj, {
1361
+ x: (_a = x != null ? x : clientX) != null ? _a : 0,
1362
+ y: (_b = y != null ? y : clientY) != null ? _b : 0,
1363
+ clientX: (_c = x != null ? x : clientX) != null ? _c : 0,
1364
+ clientY: (_d = y != null ? y : clientY) != null ? _d : 0,
1365
+ offsetX: offsetX != null ? offsetX : 0,
1366
+ offsetY: offsetY != null ? offsetY : 0,
1367
+ pageX: pageX != null ? pageX : 0,
1368
+ pageY: pageY != null ? pageY : 0,
1369
+ screenX: screenX != null ? screenX : 0,
1370
+ screenY: screenY != null ? screenY : 0
1371
+ });
1372
+ }
1373
+ function assignPointerInit(obj, { isPrimary, pointerId, pointerType }) {
1374
+ assignProps(obj, {
1375
+ isPrimary,
1376
+ pointerId,
1377
+ pointerType
1378
+ });
1379
+ }
1380
+
1381
+ // src/event/behavior/registry.ts
1382
+ var behavior = {};
1383
+
1384
+ // src/event/behavior/click.ts
1385
+ behavior.click = (event, target, config) => {
1386
+ var _a;
1387
+ const control = (_a = target.closest("label")) == null ? void 0 : _a.control;
1388
+ if (control) {
1389
+ return () => {
1390
+ if (isFocusable(control)) {
1391
+ focus(control);
1392
+ }
1393
+ dispatchEvent(config, control, cloneEvent(event));
1394
+ };
1395
+ } else if (isElementType(target, "input", { type: "file" })) {
1396
+ return () => {
1397
+ blur(target);
1398
+ target.dispatchEvent(new Event("fileDialog"));
1399
+ focus(target);
1400
+ };
1268
1401
  }
1269
- if (["pointerdown", "pointerup"].includes(type3)) {
1270
- init.isPrimary = isPrimary;
1402
+ };
1403
+
1404
+ // src/event/dispatchEvent.ts
1405
+ function dispatchEvent(config, target, event) {
1406
+ var _a, _b;
1407
+ const type3 = event.type;
1408
+ const behaviorImplementation = (_b = (_a = behavior)[type3]) == null ? void 0 : _b.call(_a, event, target, config);
1409
+ if (behaviorImplementation) {
1410
+ event.preventDefault();
1411
+ let defaultPrevented = false;
1412
+ Object.defineProperty(event, "defaultPrevented", {
1413
+ get: () => defaultPrevented
1414
+ });
1415
+ Object.defineProperty(event, "preventDefault", {
1416
+ value: () => {
1417
+ defaultPrevented = event.cancelable;
1418
+ }
1419
+ });
1420
+ target.dispatchEvent(event);
1421
+ if (!defaultPrevented) {
1422
+ behaviorImplementation();
1423
+ }
1424
+ return !defaultPrevented;
1271
1425
  }
1272
- init.button = getMouseButton(button != null ? button : 0);
1273
- init.buttons = getMouseButtons(...pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
1274
- var _a;
1275
- return (_a = p.keyDef.button) != null ? _a : 0;
1426
+ return target.dispatchEvent(event);
1427
+ }
1428
+
1429
+ // src/event/wrapEvent.ts
1430
+ var import_dom3 = require("@testing-library/dom");
1431
+ function wrapEvent(cb, _element) {
1432
+ return (0, import_dom3.getConfig)().eventWrapper(cb);
1433
+ }
1434
+
1435
+ // src/event/index.ts
1436
+ function dispatchUIEvent(config, target, type3, init) {
1437
+ if (isMouseEvent(type3) || isKeyboardEvent(type3)) {
1438
+ init = __spreadValues(__spreadValues({}, init), getUIEventModifiers(config.keyboardState));
1439
+ }
1440
+ const event = createEvent(type3, target, init);
1441
+ return wrapEvent(() => dispatchEvent(config, target, event), target);
1442
+ }
1443
+ function bindDispatchUIEvent(config) {
1444
+ return dispatchUIEvent.bind(void 0, config);
1445
+ }
1446
+
1447
+ // src/document/interceptor.ts
1448
+ var Interceptor = Symbol("Interceptor for programmatical calls");
1449
+ function prepareInterceptor(element, propName, interceptorImpl) {
1450
+ const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
1451
+ const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
1452
+ const target = (prototypeDescriptor == null ? void 0 : prototypeDescriptor.set) ? "set" : "value";
1453
+ if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== "function" || prototypeDescriptor[target][Interceptor]) {
1454
+ return;
1455
+ }
1456
+ function intercept(...args) {
1457
+ const { applyNative = true, realArgs } = interceptorImpl.call(this, ...args);
1458
+ const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
1459
+ if (target === "set") {
1460
+ realFunc.call(this, realArgs);
1461
+ } else {
1462
+ realFunc.call(this, ...realArgs);
1463
+ }
1464
+ }
1465
+ ;
1466
+ intercept[Interceptor] = Interceptor;
1467
+ Object.defineProperty(element, propName, __spreadProps(__spreadValues({}, objectDescriptor != null ? objectDescriptor : prototypeDescriptor), {
1468
+ [target]: intercept
1276
1469
  }));
1277
- if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
1278
- init.detail = clickCount;
1470
+ }
1471
+
1472
+ // src/document/selection.ts
1473
+ var UISelection = Symbol("Displayed selection in UI");
1474
+ function prepareSelectionInterceptor(element) {
1475
+ prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, end, direction = "none") {
1476
+ const isUI = start && typeof start === "object" && start[UISelection];
1477
+ if (!isUI) {
1478
+ this[UISelection] = void 0;
1479
+ }
1480
+ return {
1481
+ realArgs: [Number(start), end, direction]
1482
+ };
1483
+ });
1484
+ prepareInterceptor(element, "selectionStart", function interceptorImpl(v) {
1485
+ this[UISelection] = void 0;
1486
+ return { realArgs: v };
1487
+ });
1488
+ prepareInterceptor(element, "selectionEnd", function interceptorImpl(v) {
1489
+ this[UISelection] = void 0;
1490
+ return { realArgs: v };
1491
+ });
1492
+ }
1493
+ function setUISelection(element, {
1494
+ focusOffset: focusOffsetParam,
1495
+ anchorOffset: anchorOffsetParam = focusOffsetParam
1496
+ }, mode = "replace") {
1497
+ const valueLength = getUIValue(element).length;
1498
+ const sanitizeOffset = (o) => Math.max(0, Math.min(valueLength, o));
1499
+ const anchorOffset = mode === "replace" || element[UISelection] === void 0 ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
1500
+ const focusOffset = sanitizeOffset(focusOffsetParam);
1501
+ const startOffset = Math.min(anchorOffset, focusOffset);
1502
+ const endOffset = Math.max(anchorOffset, focusOffset);
1503
+ element[UISelection] = {
1504
+ anchorOffset,
1505
+ focusOffset
1506
+ };
1507
+ if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
1508
+ return;
1509
+ }
1510
+ const startObj = new Number(startOffset);
1511
+ startObj[UISelection] = UISelection;
1512
+ try {
1513
+ element.setSelectionRange(startObj, endOffset);
1514
+ } catch {
1279
1515
  }
1280
- const eventKey = Object.keys(import_event_map.eventMap).find((k) => k.toLowerCase() === type3);
1281
- const event = import_dom5.createEvent[eventKey](target, init);
1282
- assignPositionInit(event, init);
1283
- assignPointerInit(event, init);
1284
- return (0, import_dom5.fireEvent)(target, event);
1285
1516
  }
1286
- function assignProps(obj, props) {
1287
- for (const [key, value] of Object.entries(props)) {
1288
- Object.defineProperty(obj, key, { get: () => value });
1517
+ function getUISelection(element) {
1518
+ var _a, _b, _c;
1519
+ const sel = (_c = element[UISelection]) != null ? _c : {
1520
+ anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
1521
+ focusOffset: (_b = element.selectionEnd) != null ? _b : 0
1522
+ };
1523
+ return __spreadProps(__spreadValues({}, sel), {
1524
+ startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
1525
+ endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
1526
+ });
1527
+ }
1528
+ function clearUISelection(element) {
1529
+ element[UISelection] = void 0;
1530
+ }
1531
+
1532
+ // src/document/value.ts
1533
+ var UIValue = Symbol("Displayed value in UI");
1534
+ var InitialValue = Symbol("Initial value to compare on blur");
1535
+ var TrackChanges = Symbol("Track programmatic changes for React workaround");
1536
+ function valueInterceptor(v) {
1537
+ const isUI = typeof v === "object" && v[UIValue];
1538
+ this[UIValue] = isUI ? String(v) : void 0;
1539
+ if (!isUI) {
1540
+ trackValue(this, String(v));
1541
+ this[InitialValue] = String(v);
1542
+ clearUISelection(this);
1543
+ }
1544
+ return {
1545
+ applyNative: !!isUI,
1546
+ realArgs: String(v)
1547
+ };
1548
+ }
1549
+ function prepareValueInterceptor(element) {
1550
+ prepareInterceptor(element, "value", valueInterceptor);
1551
+ }
1552
+ function setUIValue(element, value) {
1553
+ element.value = {
1554
+ [UIValue]: UIValue,
1555
+ toString: () => value
1556
+ };
1557
+ }
1558
+ function getUIValue(element) {
1559
+ return element[UIValue] === void 0 ? element.value : String(element[UIValue]);
1560
+ }
1561
+ function setInitialValue(element) {
1562
+ element[InitialValue] = element.value;
1563
+ }
1564
+ function getInitialValue(element) {
1565
+ return element[InitialValue];
1566
+ }
1567
+ function startTrackValue(element) {
1568
+ element[TrackChanges] = [];
1569
+ }
1570
+ function trackValue(element, v) {
1571
+ var _a;
1572
+ (_a = element[TrackChanges]) == null ? void 0 : _a.push(v);
1573
+ }
1574
+ function endTrackValue(element) {
1575
+ const tracked = element[TrackChanges];
1576
+ element[TrackChanges] = void 0;
1577
+ return tracked;
1578
+ }
1579
+
1580
+ // src/document/index.ts
1581
+ var isPrepared = Symbol("Node prepared with document state workarounds");
1582
+ function prepareDocument(document2) {
1583
+ if (document2[isPrepared]) {
1584
+ return;
1585
+ }
1586
+ document2.addEventListener("focus", (e) => {
1587
+ const el = e.target;
1588
+ prepareElement(el);
1589
+ }, {
1590
+ capture: true,
1591
+ passive: true
1592
+ });
1593
+ if (document2.activeElement) {
1594
+ prepareElement(document2.activeElement);
1289
1595
  }
1290
- }
1291
- function assignPositionInit(obj, {
1292
- x,
1293
- y,
1294
- clientX,
1295
- clientY,
1296
- offsetX,
1297
- offsetY,
1298
- pageX,
1299
- pageY,
1300
- screenX,
1301
- screenY
1302
- }) {
1303
- var _a, _b, _c, _d;
1304
- assignProps(obj, {
1305
- x: (_a = x != null ? x : clientX) != null ? _a : 0,
1306
- y: (_b = y != null ? y : clientY) != null ? _b : 0,
1307
- clientX: (_c = x != null ? x : clientX) != null ? _c : 0,
1308
- clientY: (_d = y != null ? y : clientY) != null ? _d : 0,
1309
- offsetX: offsetX != null ? offsetX : 0,
1310
- offsetY: offsetY != null ? offsetY : 0,
1311
- pageX: pageX != null ? pageX : 0,
1312
- pageY: pageY != null ? pageY : 0,
1313
- screenX: screenX != null ? screenX : 0,
1314
- screenY: screenY != null ? screenY : 0
1596
+ document2.addEventListener("blur", (e) => {
1597
+ const el = e.target;
1598
+ const initialValue = getInitialValue(el);
1599
+ if (typeof initialValue === "string" && el.value !== initialValue) {
1600
+ dispatchUIEvent({}, el, "change");
1601
+ }
1602
+ }, {
1603
+ capture: true,
1604
+ passive: true
1315
1605
  });
1606
+ document2[isPrepared] = isPrepared;
1316
1607
  }
1317
- function assignPointerInit(obj, { isPrimary, pointerId, pointerType }) {
1318
- assignProps(obj, {
1319
- isPrimary,
1320
- pointerId,
1321
- pointerType
1322
- });
1608
+ function prepareElement(el) {
1609
+ if ("value" in el) {
1610
+ setInitialValue(el);
1611
+ }
1612
+ if (el[isPrepared]) {
1613
+ return;
1614
+ }
1615
+ if ("value" in el) {
1616
+ prepareValueInterceptor(el);
1617
+ prepareSelectionInterceptor(el);
1618
+ }
1619
+ el[isPrepared] = isPrepared;
1323
1620
  }
1324
1621
 
1325
1622
  // src/keyboard/plugins/arrow.ts
1326
1623
  var keydownBehavior = [
1327
1624
  {
1328
- matches: (keyDef, element) => (keyDef.key === "ArrowLeft" || keyDef.key === "ArrowRight") && isElementType(element, ["input", "textarea"]),
1625
+ matches: (keyDef) => keyDef.key === "ArrowLeft" || keyDef.key === "ArrowRight",
1329
1626
  handle: (keyDef, element) => {
1330
- const selection = getUISelection(element);
1331
- setSelection({
1332
- focusNode: element,
1333
- focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + (keyDef.key === "ArrowLeft" ? -1 : 1) : keyDef.key === "ArrowLeft" ? selection.startOffset : selection.endOffset
1334
- });
1627
+ if (hasOwnSelection(element)) {
1628
+ const selection = getUISelection(element);
1629
+ setSelection({
1630
+ focusNode: element,
1631
+ focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + (keyDef.key === "ArrowLeft" ? -1 : 1) : keyDef.key === "ArrowLeft" ? selection.startOffset : selection.endOffset
1632
+ });
1633
+ } else {
1634
+ const selection = element.ownerDocument.getSelection();
1635
+ if (!selection) {
1636
+ return;
1637
+ }
1638
+ if (selection.isCollapsed) {
1639
+ const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, keyDef.key === "ArrowLeft" ? -1 : 1);
1640
+ if (nextPosition) {
1641
+ setSelection({
1642
+ focusNode: nextPosition.node,
1643
+ focusOffset: nextPosition.offset
1644
+ });
1645
+ }
1646
+ } else {
1647
+ selection[keyDef.key === "ArrowLeft" ? "collapseToStart" : "collapseToEnd"]();
1648
+ }
1649
+ }
1335
1650
  }
1336
1651
  }
1337
1652
  ];
@@ -1364,21 +1679,18 @@ var keydownBehavior2 = [
1364
1679
  },
1365
1680
  {
1366
1681
  matches: (keyDef, element) => keyDef.key === "Delete" && isEditable(element),
1367
- handle: (keDef, element) => {
1682
+ handle: (keDef, element, config) => {
1368
1683
  var _a;
1369
- (_a = prepareInput("", element, "deleteContentForward")) == null ? void 0 : _a.commit();
1684
+ (_a = prepareInput(config, "", element, "deleteContentForward")) == null ? void 0 : _a.commit();
1370
1685
  }
1371
1686
  }
1372
1687
  ];
1373
1688
 
1374
- // src/keyboard/plugins/character.ts
1375
- var import_dom7 = require("@testing-library/dom");
1376
-
1377
1689
  // src/keyboard/shared/fireChangeForInputTimeIfValid.ts
1378
- var import_dom6 = require("@testing-library/dom");
1379
- function fireChangeForInputTimeIfValid(el, prevValue, timeNewEntry) {
1690
+ function fireChangeForInputTimeIfValid(config, el, prevValue, timeNewEntry) {
1380
1691
  if (isValidInputTimeValue(el, timeNewEntry) && prevValue !== timeNewEntry) {
1381
- import_dom6.fireEvent.change(el, { target: { value: timeNewEntry } });
1692
+ setUIValue(el, timeNewEntry);
1693
+ dispatchUIEvent(config, el, "change");
1382
1694
  }
1383
1695
  }
1384
1696
 
@@ -1389,10 +1701,10 @@ var keypressBehavior = [
1389
1701
  var _a;
1390
1702
  return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "time", readOnly: false });
1391
1703
  },
1392
- handle: (keyDef, element, { keyboardState }) => {
1704
+ handle: (keyDef, element, config) => {
1393
1705
  var _a;
1394
1706
  let newEntry = keyDef.key;
1395
- const textToBeTyped = ((_a = keyboardState.carryValue) != null ? _a : "") + newEntry;
1707
+ const textToBeTyped = ((_a = config.keyboardState.carryValue) != null ? _a : "") + newEntry;
1396
1708
  const timeNewEntry = buildTimeValue(textToBeTyped);
1397
1709
  if (isValidInputTimeValue(element, timeNewEntry)) {
1398
1710
  newEntry = timeNewEntry;
@@ -1400,7 +1712,7 @@ var keypressBehavior = [
1400
1712
  const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
1401
1713
  const prevValue = getValue(element);
1402
1714
  if (prevValue !== newValue) {
1403
- editInputElement(element, {
1715
+ editInputElement(config, element, {
1404
1716
  newValue,
1405
1717
  newSelection: {
1406
1718
  node: element,
@@ -1412,8 +1724,8 @@ var keypressBehavior = [
1412
1724
  }
1413
1725
  });
1414
1726
  }
1415
- fireChangeForInputTimeIfValid(element, prevValue, timeNewEntry);
1416
- keyboardState.carryValue = textToBeTyped;
1727
+ fireChangeForInputTimeIfValid(config, element, prevValue, timeNewEntry);
1728
+ config.keyboardState.carryValue = textToBeTyped;
1417
1729
  }
1418
1730
  },
1419
1731
  {
@@ -1421,10 +1733,10 @@ var keypressBehavior = [
1421
1733
  var _a;
1422
1734
  return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "date", readOnly: false });
1423
1735
  },
1424
- handle: (keyDef, element, { keyboardState }) => {
1736
+ handle: (keyDef, element, config) => {
1425
1737
  var _a;
1426
1738
  let newEntry = keyDef.key;
1427
- const textToBeTyped = ((_a = keyboardState.carryValue) != null ? _a : "") + newEntry;
1739
+ const textToBeTyped = ((_a = config.keyboardState.carryValue) != null ? _a : "") + newEntry;
1428
1740
  const isValidToBeTyped = isValidDateValue(element, textToBeTyped);
1429
1741
  if (isValidToBeTyped) {
1430
1742
  newEntry = textToBeTyped;
@@ -1432,7 +1744,7 @@ var keypressBehavior = [
1432
1744
  const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
1433
1745
  const prevValue = getValue(element);
1434
1746
  if (prevValue !== newValue) {
1435
- editInputElement(element, {
1747
+ editInputElement(config, element, {
1436
1748
  newValue,
1437
1749
  newSelection: {
1438
1750
  node: element,
@@ -1445,11 +1757,10 @@ var keypressBehavior = [
1445
1757
  });
1446
1758
  }
1447
1759
  if (isValidToBeTyped) {
1448
- import_dom7.fireEvent.change(element, {
1449
- target: { value: textToBeTyped }
1450
- });
1760
+ setUIValue(element, textToBeTyped);
1761
+ dispatchUIEvent(config, element, "change");
1451
1762
  }
1452
- keyboardState.carryValue = textToBeTyped;
1763
+ config.keyboardState.carryValue = textToBeTyped;
1453
1764
  }
1454
1765
  },
1455
1766
  {
@@ -1457,12 +1768,12 @@ var keypressBehavior = [
1457
1768
  var _a;
1458
1769
  return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "number", readOnly: false });
1459
1770
  },
1460
- handle: (keyDef, element) => {
1771
+ handle: (keyDef, element, config) => {
1461
1772
  var _a, _b;
1462
1773
  if (!/[\d.\-e]/.test(keyDef.key)) {
1463
1774
  return;
1464
1775
  }
1465
- const { getNewValue, commit } = prepareInput(keyDef.key, element);
1776
+ const { getNewValue, commit } = prepareInput(config, keyDef.key, element);
1466
1777
  const newValue = getNewValue();
1467
1778
  const valueParts = newValue.split("e", 2);
1468
1779
  if (Number((_a = newValue.match(/-/g)) == null ? void 0 : _a.length) > 2 || Number((_b = newValue.match(/\./g)) == null ? void 0 : _b.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1])) {
@@ -1476,28 +1787,27 @@ var keypressBehavior = [
1476
1787
  var _a;
1477
1788
  return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && (isEditableInput(element) || isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0;
1478
1789
  },
1479
- handle: (keyDef, element) => {
1790
+ handle: (keyDef, element, config) => {
1480
1791
  var _a;
1481
- (_a = prepareInput(keyDef.key, element)) == null ? void 0 : _a.commit();
1792
+ (_a = prepareInput(config, keyDef.key, element)) == null ? void 0 : _a.commit();
1482
1793
  }
1483
1794
  },
1484
1795
  {
1485
1796
  matches: (keyDef, element) => keyDef.key === "Enter" && (isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0,
1486
- handle: (keyDef, element, { keyboardState }) => {
1797
+ handle: (keyDef, element, config) => {
1487
1798
  var _a;
1488
- (_a = prepareInput("\n", element, isContentEditable(element) && !keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak")) == null ? void 0 : _a.commit();
1799
+ (_a = prepareInput(config, "\n", element, isContentEditable(element) && !config.keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak")) == null ? void 0 : _a.commit();
1489
1800
  }
1490
1801
  }
1491
1802
  ];
1492
1803
 
1493
1804
  // src/keyboard/plugins/functional.ts
1494
- var import_dom8 = require("@testing-library/dom");
1495
1805
  var keydownBehavior3 = [
1496
1806
  {
1497
1807
  matches: (keyDef, element) => keyDef.key === "Backspace" && isEditable(element),
1498
- handle: (keyDef, element) => {
1808
+ handle: (keyDef, element, config) => {
1499
1809
  var _a;
1500
- (_a = prepareInput("", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
1810
+ (_a = prepareInput(config, "", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
1501
1811
  }
1502
1812
  },
1503
1813
  {
@@ -1521,25 +1831,25 @@ var keydownBehavior3 = [
1521
1831
  var keypressBehavior2 = [
1522
1832
  {
1523
1833
  matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input") && ["checkbox", "radio"].includes(element.type),
1524
- handle: (keyDef, element) => {
1834
+ handle: (keyDef, element, config) => {
1525
1835
  const form = element.form;
1526
1836
  if (hasFormSubmit(form)) {
1527
- import_dom8.fireEvent.submit(form);
1837
+ dispatchUIEvent(config, form, "submit");
1528
1838
  }
1529
1839
  }
1530
1840
  },
1531
1841
  {
1532
1842
  matches: (keyDef, element) => keyDef.key === "Enter" && (isClickableInput(element) || isElementType(element, "a") && Boolean(element.href)),
1533
- handle: (keyDef, element, { keyboardState }) => {
1534
- import_dom8.fireEvent.click(element, getUIEventModifiers(keyboardState));
1843
+ handle: (keyDef, element, config) => {
1844
+ dispatchUIEvent(config, element, "click");
1535
1845
  }
1536
1846
  },
1537
1847
  {
1538
1848
  matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input"),
1539
- handle: (keyDef, element) => {
1849
+ handle: (keyDef, element, config) => {
1540
1850
  const form = element.form;
1541
1851
  if (form && (form.querySelectorAll("input").length === 1 || hasFormSubmit(form))) {
1542
- import_dom8.fireEvent.submit(form);
1852
+ dispatchUIEvent(config, form, "submit");
1543
1853
  }
1544
1854
  }
1545
1855
  }
@@ -1547,8 +1857,8 @@ var keypressBehavior2 = [
1547
1857
  var keyupBehavior = [
1548
1858
  {
1549
1859
  matches: (keyDef, element) => keyDef.key === " " && isClickableInput(element),
1550
- handle: (keyDef, element, { keyboardState }) => {
1551
- import_dom8.fireEvent.click(element, getUIEventModifiers(keyboardState));
1860
+ handle: (keyDef, element, config) => {
1861
+ dispatchUIEvent(config, element, "click");
1552
1862
  }
1553
1863
  }
1554
1864
  ];
@@ -1562,7 +1872,6 @@ var keydownBehavior4 = [
1562
1872
  ];
1563
1873
 
1564
1874
  // src/keyboard/plugins/modifiers.ts
1565
- var import_dom9 = require("@testing-library/dom");
1566
1875
  var modifierKeys = [
1567
1876
  "Alt",
1568
1877
  "AltGraph",
@@ -1582,12 +1891,12 @@ var modifierLocks = [
1582
1891
  var preKeydownBehavior = [
1583
1892
  {
1584
1893
  matches: (keyDef) => modifierKeys.includes(keyDef.key),
1585
- handle: (keyDef, element, { keyboardMap, keyboardState }) => {
1894
+ handle: (keyDef, element, config) => {
1586
1895
  var _a;
1587
- keyboardState.modifiers[keyDef.key] = true;
1896
+ config.keyboardState.modifiers[keyDef.key] = true;
1588
1897
  if (keyDef.key === "AltGraph") {
1589
- const ctrlKeyDef = (_a = keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
1590
- import_dom9.fireEvent.keyDown(element, getKeyEventProps(ctrlKeyDef, keyboardState));
1898
+ const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
1899
+ dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
1591
1900
  }
1592
1901
  }
1593
1902
  },
@@ -1622,10 +1931,10 @@ var preKeyupBehavior = [
1622
1931
  var postKeyupBehavior = [
1623
1932
  {
1624
1933
  matches: (keyDef) => keyDef.key === "AltGraph",
1625
- handle: (keyDef, element, { keyboardMap, keyboardState }) => {
1934
+ handle: (keyDef, element, config) => {
1626
1935
  var _a;
1627
- const ctrlKeyDef = (_a = keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
1628
- import_dom9.fireEvent.keyUp(element, getKeyEventProps(ctrlKeyDef, keyboardState));
1936
+ const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
1937
+ dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
1629
1938
  }
1630
1939
  }
1631
1940
  ];
@@ -1702,7 +2011,7 @@ async function keydown(keyDef, getCurrentElement, config) {
1702
2011
  }
1703
2012
  config.keyboardState.activeElement = element;
1704
2013
  applyPlugins(preKeydownBehavior2, keyDef, element, config);
1705
- const unpreventedDefault = import_dom10.fireEvent.keyDown(element, getKeyEventProps(keyDef, config.keyboardState));
2014
+ const unpreventedDefault = dispatchUIEvent(config, element, "keydown", getKeyEventProps(keyDef));
1706
2015
  config.keyboardState.pressed.push({ keyDef, unpreventedDefault });
1707
2016
  if (unpreventedDefault) {
1708
2017
  applyPlugins(keydownBehavior5, keyDef, getCurrentElement(), config);
@@ -1711,7 +2020,7 @@ async function keydown(keyDef, getCurrentElement, config) {
1711
2020
  }
1712
2021
  async function keypress(keyDef, getCurrentElement, config) {
1713
2022
  const element = getCurrentElement();
1714
- const unpreventedDefault = import_dom10.fireEvent.keyPress(element, __spreadProps(__spreadValues({}, getKeyEventProps(keyDef, config.keyboardState)), {
2023
+ const unpreventedDefault = dispatchUIEvent(config, element, "keypress", __spreadProps(__spreadValues({}, getKeyEventProps(keyDef)), {
1715
2024
  charCode: keyDef.key === "Enter" ? 13 : String(keyDef.key).charCodeAt(0)
1716
2025
  }));
1717
2026
  if (unpreventedDefault) {
@@ -1721,7 +2030,7 @@ async function keypress(keyDef, getCurrentElement, config) {
1721
2030
  async function keyup(keyDef, getCurrentElement, config, unprevented) {
1722
2031
  const element = getCurrentElement();
1723
2032
  applyPlugins(preKeyupBehavior2, keyDef, element, config);
1724
- const unpreventedDefault = import_dom10.fireEvent.keyUp(element, getKeyEventProps(keyDef, config.keyboardState));
2033
+ const unpreventedDefault = dispatchUIEvent(config, element, "keyup", getKeyEventProps(keyDef));
1725
2034
  if (unprevented && unpreventedDefault) {
1726
2035
  applyPlugins(keyupBehavior2, keyDef, getCurrentElement(), config);
1727
2036
  }
@@ -1774,8 +2083,7 @@ function parseKeyDef(keyboardMap, text) {
1774
2083
 
1775
2084
  // src/keyboard/index.ts
1776
2085
  async function keyboard(text) {
1777
- const { keyboardMap } = this[Config];
1778
- const actions = parseKeyDef(keyboardMap, text);
2086
+ const actions = parseKeyDef(this[Config].keyboardMap, text);
1779
2087
  return keyboardAction(this[Config], actions);
1780
2088
  }
1781
2089
  function createKeyboardState() {
@@ -1820,6 +2128,34 @@ function parseKeyDef2(pointerMap, keys) {
1820
2128
  return defs;
1821
2129
  }
1822
2130
 
2131
+ // src/pointer/firePointerEvents.ts
2132
+ function firePointerEvent(config, target, type3, {
2133
+ pointerType,
2134
+ button,
2135
+ coords,
2136
+ pointerId,
2137
+ isPrimary,
2138
+ clickCount
2139
+ }) {
2140
+ const init = __spreadValues({}, coords);
2141
+ if (type3 === "click" || type3.startsWith("pointer")) {
2142
+ init.pointerId = pointerId;
2143
+ init.pointerType = pointerType;
2144
+ }
2145
+ if (["pointerdown", "pointerup"].includes(type3)) {
2146
+ init.isPrimary = isPrimary;
2147
+ }
2148
+ init.button = getMouseButton(button != null ? button : 0);
2149
+ init.buttons = getMouseButtons(...config.pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
2150
+ var _a;
2151
+ return (_a = p.keyDef.button) != null ? _a : 0;
2152
+ }));
2153
+ if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
2154
+ init.detail = clickCount;
2155
+ }
2156
+ return dispatchUIEvent(config, target, type3, init);
2157
+ }
2158
+
1823
2159
  // src/pointer/resolveSelectionTarget.ts
1824
2160
  function resolveSelectionTarget({
1825
2161
  target,
@@ -1865,7 +2201,8 @@ function findNodeAtTextOffset(node, offset, isRoot = true) {
1865
2201
  }
1866
2202
 
1867
2203
  // src/pointer/pointerMove.ts
1868
- async function pointerMove({ pointerName = "mouse", target, coords, node, offset }, { pointerState, keyboardState }) {
2204
+ async function pointerMove(config, { pointerName = "mouse", target, coords, node, offset }) {
2205
+ const { pointerState } = config;
1869
2206
  if (!(pointerName in pointerState.position)) {
1870
2207
  throw new Error(`Trying to move pointer "${pointerName}" which does not exist.`);
1871
2208
  }
@@ -1877,11 +2214,15 @@ async function pointerMove({ pointerName = "mouse", target, coords, node, offset
1877
2214
  selectionRange
1878
2215
  } = pointerState.position[pointerName];
1879
2216
  if (prevTarget && prevTarget !== target) {
2217
+ setLevelRef(config, 2 /* Trigger */);
2218
+ assertPointerEvents(config, prevTarget);
1880
2219
  fireMove(prevTarget, prevCoords);
1881
2220
  if (!isDescendantOrSelf(target, prevTarget)) {
1882
2221
  fireLeave(prevTarget, prevCoords);
1883
2222
  }
1884
2223
  }
2224
+ setLevelRef(config, 2 /* Trigger */);
2225
+ assertPointerEvents(config, target);
1885
2226
  pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
1886
2227
  target,
1887
2228
  coords
@@ -1936,9 +2277,7 @@ async function pointerMove({ pointerName = "mouse", target, coords, node, offset
1936
2277
  }
1937
2278
  }
1938
2279
  function fire(eventTarget, type3, eventCoords) {
1939
- return firePointerEvent(eventTarget, type3, {
1940
- pointerState,
1941
- keyboardState,
2280
+ return firePointerEvent(config, eventTarget, type3, {
1942
2281
  coords: eventCoords,
1943
2282
  pointerId,
1944
2283
  pointerType
@@ -1947,18 +2286,18 @@ async function pointerMove({ pointerName = "mouse", target, coords, node, offset
1947
2286
  }
1948
2287
 
1949
2288
  // src/pointer/pointerPress.ts
1950
- async function pointerPress(action, state) {
2289
+ async function pointerPress(config, action) {
1951
2290
  const { keyDef, target, releasePrevious, releaseSelf } = action;
1952
- const previous = state.pointerState.pressed.find((p) => p.keyDef === keyDef);
2291
+ const previous = config.pointerState.pressed.find((p) => p.keyDef === keyDef);
1953
2292
  const pointerName = keyDef.pointerType === "touch" ? keyDef.name : keyDef.pointerType;
1954
2293
  const targetIsDisabled = isDisabled(target);
1955
2294
  if (previous) {
1956
- up(state, pointerName, action, previous, targetIsDisabled);
2295
+ up(config, pointerName, action, previous, targetIsDisabled);
1957
2296
  }
1958
2297
  if (!releasePrevious) {
1959
- const press = down(state, pointerName, action, targetIsDisabled);
2298
+ const press = down(config, pointerName, action, targetIsDisabled);
1960
2299
  if (releaseSelf) {
1961
- up(state, pointerName, action, press, targetIsDisabled);
2300
+ up(config, pointerName, action, press, targetIsDisabled);
1962
2301
  }
1963
2302
  }
1964
2303
  }
@@ -1966,8 +2305,11 @@ function getNextPointerId(state) {
1966
2305
  state.pointerId = state.pointerId + 1;
1967
2306
  return state.pointerId;
1968
2307
  }
1969
- function down({ pointerState, keyboardState }, pointerName, { keyDef, node, offset, target, coords }, targetIsDisabled) {
2308
+ function down(config, pointerName, { keyDef, node, offset, target, coords }, targetIsDisabled) {
1970
2309
  var _a, _b, _c;
2310
+ setLevelRef(config, 2 /* Trigger */);
2311
+ assertPointerEvents(config, target);
2312
+ const { pointerState } = config;
1971
2313
  const { name, pointerType, button } = keyDef;
1972
2314
  const pointerId = pointerType === "mouse" ? 1 : getNextPointerId(pointerState);
1973
2315
  pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
@@ -2002,36 +2344,34 @@ function down({ pointerState, keyboardState }, pointerName, { keyDef, node, offs
2002
2344
  clickCount
2003
2345
  };
2004
2346
  pointerState.pressed.push(pressObj);
2005
- if (!targetIsDisabled) {
2006
- if (pointerType !== "mouse") {
2007
- fire("pointerover");
2008
- fire("pointerenter");
2347
+ if (pointerType !== "mouse") {
2348
+ fire("pointerover");
2349
+ fire("pointerenter");
2350
+ }
2351
+ if (pointerType !== "mouse" || !pointerState.pressed.some((p) => p.keyDef !== keyDef && p.keyDef.pointerType === pointerType)) {
2352
+ fire("pointerdown");
2353
+ }
2354
+ if (pointerType === "mouse") {
2355
+ if (!targetIsDisabled) {
2356
+ pressObj.unpreventedDefault = fire("mousedown");
2009
2357
  }
2010
- if (pointerType !== "mouse" || !pointerState.pressed.some((p) => p.keyDef !== keyDef && p.keyDef.pointerType === pointerType)) {
2011
- fire("pointerdown");
2358
+ if (pressObj.unpreventedDefault) {
2359
+ mousedownDefaultBehavior({
2360
+ target,
2361
+ targetIsDisabled,
2362
+ clickCount,
2363
+ position: pointerState.position[pointerName],
2364
+ node,
2365
+ offset
2366
+ });
2012
2367
  }
2013
- if (pointerType === "mouse") {
2014
- pressObj.unpreventedDefault = fire("mousedown");
2368
+ if (button === "secondary") {
2369
+ fire("contextmenu");
2015
2370
  }
2016
2371
  }
2017
- if (pointerType === "mouse" && pressObj.unpreventedDefault) {
2018
- mousedownDefaultBehavior({
2019
- target,
2020
- targetIsDisabled,
2021
- clickCount,
2022
- position: pointerState.position[pointerName],
2023
- node,
2024
- offset
2025
- });
2026
- }
2027
- if (pointerType === "mouse" && button === "secondary") {
2028
- fire("contextmenu");
2029
- }
2030
2372
  return pressObj;
2031
2373
  function fire(type3) {
2032
- return firePointerEvent(target, type3, {
2033
- pointerState,
2034
- keyboardState,
2374
+ return firePointerEvent(config, target, type3, {
2035
2375
  button,
2036
2376
  clickCount,
2037
2377
  coords,
@@ -2041,14 +2381,16 @@ function down({ pointerState, keyboardState }, pointerName, { keyDef, node, offs
2041
2381
  });
2042
2382
  }
2043
2383
  }
2044
- function up({ pointerState, keyboardState }, pointerName, {
2384
+ function up(config, pointerName, {
2045
2385
  keyDef: { pointerType, button },
2046
2386
  target,
2047
2387
  coords,
2048
2388
  node,
2049
2389
  offset
2050
2390
  }, pressed, targetIsDisabled) {
2051
- var _a;
2391
+ setLevelRef(config, 2 /* Trigger */);
2392
+ assertPointerEvents(config, target);
2393
+ const { pointerState } = config;
2052
2394
  pointerState.pressed = pointerState.pressed.filter((p) => p !== pressed);
2053
2395
  const { isMultiTouch, isPrimary, pointerId, clickCount } = pressed;
2054
2396
  let { unpreventedDefault } = pressed;
@@ -2056,15 +2398,15 @@ function up({ pointerState, keyboardState }, pointerName, {
2056
2398
  target,
2057
2399
  coords
2058
2400
  });
2059
- if (!targetIsDisabled) {
2060
- if (pointerType !== "mouse" || !pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).length) {
2061
- fire("pointerup");
2062
- }
2063
- if (pointerType !== "mouse") {
2064
- fire("pointerout");
2065
- fire("pointerleave");
2066
- }
2067
- if (pointerType !== "mouse" && !isMultiTouch) {
2401
+ if (pointerType !== "mouse" || !pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).length) {
2402
+ fire("pointerup");
2403
+ }
2404
+ if (pointerType !== "mouse") {
2405
+ fire("pointerout");
2406
+ fire("pointerleave");
2407
+ }
2408
+ if (pointerType !== "mouse" && !isMultiTouch) {
2409
+ if (!targetIsDisabled) {
2068
2410
  if (clickCount === 1) {
2069
2411
  fire("mouseover");
2070
2412
  fire("mouseenter");
@@ -2072,16 +2414,16 @@ function up({ pointerState, keyboardState }, pointerName, {
2072
2414
  fire("mousemove");
2073
2415
  unpreventedDefault = fire("mousedown") && unpreventedDefault;
2074
2416
  }
2075
- }
2076
- if (unpreventedDefault && pointerType !== "mouse" && !isMultiTouch) {
2077
- mousedownDefaultBehavior({
2078
- target,
2079
- targetIsDisabled,
2080
- clickCount,
2081
- position: pointerState.position[pointerName],
2082
- node,
2083
- offset
2084
- });
2417
+ if (unpreventedDefault) {
2418
+ mousedownDefaultBehavior({
2419
+ target,
2420
+ targetIsDisabled,
2421
+ clickCount,
2422
+ position: pointerState.position[pointerName],
2423
+ node,
2424
+ offset
2425
+ });
2426
+ }
2085
2427
  }
2086
2428
  delete pointerState.position[pointerName].selectionRange;
2087
2429
  if (!targetIsDisabled) {
@@ -2089,21 +2431,15 @@ function up({ pointerState, keyboardState }, pointerName, {
2089
2431
  unpreventedDefault = fire("mouseup") && unpreventedDefault;
2090
2432
  const canClick = pointerType !== "mouse" || button === "primary";
2091
2433
  if (canClick && target === pressed.downTarget) {
2092
- const unpreventedClick = fire("click");
2434
+ fire("click");
2093
2435
  if (clickCount === 2) {
2094
2436
  fire("dblclick");
2095
2437
  }
2096
- const control = (_a = target.closest("label")) == null ? void 0 : _a.control;
2097
- if (unpreventedClick && control && isFocusable(control)) {
2098
- focus(control);
2099
- }
2100
2438
  }
2101
2439
  }
2102
2440
  }
2103
2441
  function fire(type3) {
2104
- return firePointerEvent(target, type3, {
2105
- pointerState,
2106
- keyboardState,
2442
+ return firePointerEvent(config, target, type3, {
2107
2443
  button,
2108
2444
  clickCount,
2109
2445
  coords,
@@ -2121,8 +2457,7 @@ function mousedownDefaultBehavior({
2121
2457
  node,
2122
2458
  offset
2123
2459
  }) {
2124
- var _a;
2125
- focus((_a = findClosest(target, isFocusable)) != null ? _a : target.ownerDocument.body);
2460
+ focus(target);
2126
2461
  if (!targetIsDisabled) {
2127
2462
  const hasValue = isElementType(target, ["input", "textarea"]);
2128
2463
  const text = String(hasValue ? getUIValue(target) : target.textContent);
@@ -2183,7 +2518,7 @@ async function pointerAction(config, actions) {
2183
2518
  const pointerName = "pointerName" in action && action.pointerName ? action.pointerName : "keyDef" in action ? action.keyDef.pointerType === "touch" ? action.keyDef.name : action.keyDef.pointerType : "mouse";
2184
2519
  const target = (_a = action.target) != null ? _a : getPrevTarget(pointerName, config.pointerState);
2185
2520
  const coords = (_b = action.coords) != null ? _b : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : void 0;
2186
- await ("keyDef" in action ? pointerPress(__spreadProps(__spreadValues({}, action), { target, coords }), config) : pointerMove(__spreadProps(__spreadValues({}, action), { target, coords }), config));
2521
+ await ("keyDef" in action ? pointerPress(config, __spreadProps(__spreadValues({}, action), { target, coords })) : pointerMove(config, __spreadProps(__spreadValues({}, action), { target, coords })));
2187
2522
  if (typeof config.delay === "number") {
2188
2523
  if (i < actions.length - 1) {
2189
2524
  await wait(config.delay);
@@ -2238,90 +2573,6 @@ function createPointerState(document2) {
2238
2573
  };
2239
2574
  }
2240
2575
 
2241
- // src/keyboard/keyMap.ts
2242
- var defaultKeyMap = [
2243
- ..."0123456789".split("").map((c) => ({ code: `Digit${c}`, key: c })),
2244
- ...")!@#$%^&*(".split("").map((c, i) => ({ code: `Digit${i}`, key: c, shiftKey: true })),
2245
- ..."abcdefghijklmnopqrstuvwxyz".split("").map((c) => ({ code: `Key${c.toUpperCase()}`, key: c })),
2246
- ..."ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("").map((c) => ({ code: `Key${c}`, key: c, shiftKey: true })),
2247
- { code: "Space", key: " " },
2248
- { code: "AltLeft", key: "Alt", location: 1 /* LEFT */ },
2249
- { code: "AltRight", key: "Alt", location: 2 /* RIGHT */ },
2250
- {
2251
- code: "ShiftLeft",
2252
- key: "Shift",
2253
- location: 1 /* LEFT */
2254
- },
2255
- {
2256
- code: "ShiftRight",
2257
- key: "Shift",
2258
- location: 2 /* RIGHT */
2259
- },
2260
- {
2261
- code: "ControlLeft",
2262
- key: "Control",
2263
- location: 1 /* LEFT */
2264
- },
2265
- {
2266
- code: "ControlRight",
2267
- key: "Control",
2268
- location: 2 /* RIGHT */
2269
- },
2270
- { code: "MetaLeft", key: "Meta", location: 1 /* LEFT */ },
2271
- {
2272
- code: "MetaRight",
2273
- key: "Meta",
2274
- location: 2 /* RIGHT */
2275
- },
2276
- { code: "OSLeft", key: "OS", location: 1 /* LEFT */ },
2277
- { code: "OSRight", key: "OS", location: 2 /* RIGHT */ },
2278
- { code: "Tab", key: "Tab" },
2279
- { code: "CapsLock", key: "CapsLock" },
2280
- { code: "Backspace", key: "Backspace" },
2281
- { code: "Enter", key: "Enter" },
2282
- { code: "Escape", key: "Escape" },
2283
- { code: "ArrowUp", key: "ArrowUp" },
2284
- { code: "ArrowDown", key: "ArrowDown" },
2285
- { code: "ArrowLeft", key: "ArrowLeft" },
2286
- { code: "ArrowRight", key: "ArrowRight" },
2287
- { code: "Home", key: "Home" },
2288
- { code: "End", key: "End" },
2289
- { code: "Delete", key: "Delete" },
2290
- { code: "PageUp", key: "PageUp" },
2291
- { code: "PageDown", key: "PageDown" },
2292
- { code: "Fn", key: "Fn" },
2293
- { code: "Symbol", key: "Symbol" },
2294
- { code: "AltRight", key: "AltGraph" }
2295
- ];
2296
-
2297
- // src/pointer/keyMap.ts
2298
- var defaultKeyMap2 = [
2299
- { name: "MouseLeft", pointerType: "mouse", button: "primary" },
2300
- { name: "MouseRight", pointerType: "mouse", button: "secondary" },
2301
- { name: "MouseMiddle", pointerType: "mouse", button: "auxiliary" },
2302
- { name: "TouchA", pointerType: "touch" },
2303
- { name: "TouchB", pointerType: "touch" },
2304
- { name: "TouchC", pointerType: "touch" }
2305
- ];
2306
-
2307
- // src/options.ts
2308
- var defaultOptionsDirect = {
2309
- applyAccept: true,
2310
- autoModify: true,
2311
- delay: 0,
2312
- document: global.document,
2313
- keyboardMap: defaultKeyMap,
2314
- pointerMap: defaultKeyMap2,
2315
- skipAutoClose: false,
2316
- skipClick: false,
2317
- skipHover: false,
2318
- skipPointerEventsCheck: false,
2319
- writeToClipboard: false
2320
- };
2321
- var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect), {
2322
- writeToClipboard: true
2323
- });
2324
-
2325
2576
  // src/setup/config.ts
2326
2577
  var Config = Symbol("Config");
2327
2578
 
@@ -2348,9 +2599,6 @@ __export(api_exports, {
2348
2599
 
2349
2600
  // src/convenience/click.ts
2350
2601
  async function click(element) {
2351
- if (!this[Config].skipPointerEventsCheck && !hasPointerEvents(element)) {
2352
- throw new Error('unable to click element as it has or inherits pointer-events set to "none".');
2353
- }
2354
2602
  const pointerIn = [];
2355
2603
  if (!this[Config].skipHover) {
2356
2604
  pointerIn.push({ target: element });
@@ -2359,29 +2607,17 @@ async function click(element) {
2359
2607
  return this.pointer(pointerIn);
2360
2608
  }
2361
2609
  async function dblClick(element) {
2362
- if (!this[Config].skipPointerEventsCheck && !hasPointerEvents(element)) {
2363
- throw new Error('unable to double-click element as it has or inherits pointer-events set to "none".');
2364
- }
2365
2610
  return this.pointer([{ target: element }, "[MouseLeft][MouseLeft]"]);
2366
2611
  }
2367
2612
  async function tripleClick(element) {
2368
- if (!this[Config].skipPointerEventsCheck && !hasPointerEvents(element)) {
2369
- throw new Error('unable to triple-click element as it has or inherits pointer-events set to "none".');
2370
- }
2371
2613
  return this.pointer([{ target: element }, "[MouseLeft][MouseLeft][MouseLeft]"]);
2372
2614
  }
2373
2615
 
2374
2616
  // src/convenience/hover.ts
2375
2617
  async function hover(element) {
2376
- if (!this[Config].skipPointerEventsCheck && !hasPointerEvents(element)) {
2377
- throw new Error('unable to hover element as it has or inherits pointer-events set to "none".');
2378
- }
2379
2618
  return this.pointer({ target: element });
2380
2619
  }
2381
2620
  async function unhover(element) {
2382
- if (!this[Config].skipPointerEventsCheck && !hasPointerEvents(element)) {
2383
- throw new Error('unable to unhover element as it has or inherits pointer-events set to "none".');
2384
- }
2385
2621
  return this.pointer({ target: element.ownerDocument.body });
2386
2622
  }
2387
2623
 
@@ -2393,7 +2629,6 @@ async function tab({
2393
2629
  }
2394
2630
 
2395
2631
  // src/clipboard/copy.ts
2396
- var import_dom11 = require("@testing-library/dom");
2397
2632
  async function copy() {
2398
2633
  var _a;
2399
2634
  const doc = this[Config].document;
@@ -2402,7 +2637,7 @@ async function copy() {
2402
2637
  if (clipboardData.items.length === 0) {
2403
2638
  return;
2404
2639
  }
2405
- import_dom11.fireEvent.copy(target, {
2640
+ this.dispatchUIEvent(target, "copy", {
2406
2641
  clipboardData
2407
2642
  });
2408
2643
  if (this[Config].writeToClipboard) {
@@ -2412,7 +2647,6 @@ async function copy() {
2412
2647
  }
2413
2648
 
2414
2649
  // src/clipboard/cut.ts
2415
- var import_dom12 = require("@testing-library/dom");
2416
2650
  async function cut() {
2417
2651
  var _a, _b;
2418
2652
  const doc = this[Config].document;
@@ -2421,11 +2655,11 @@ async function cut() {
2421
2655
  if (clipboardData.items.length === 0) {
2422
2656
  return;
2423
2657
  }
2424
- import_dom12.fireEvent.cut(target, {
2658
+ this.dispatchUIEvent(target, "cut", {
2425
2659
  clipboardData
2426
2660
  });
2427
2661
  if (isEditable(target)) {
2428
- (_b = prepareInput("", target, "deleteByCut")) == null ? void 0 : _b.commit();
2662
+ (_b = prepareInput(this[Config], "", target, "deleteByCut")) == null ? void 0 : _b.commit();
2429
2663
  }
2430
2664
  if (this[Config].writeToClipboard) {
2431
2665
  await writeDataTransferToClipboard(doc, clipboardData);
@@ -2434,25 +2668,20 @@ async function cut() {
2434
2668
  }
2435
2669
 
2436
2670
  // src/clipboard/paste.ts
2437
- var import_dom13 = require("@testing-library/dom");
2438
2671
  async function paste(clipboardData) {
2439
- var _a, _b;
2672
+ var _a, _b, _c;
2440
2673
  const doc = this[Config].document;
2441
2674
  const target = (_a = doc.activeElement) != null ? _a : doc.body;
2442
- const data = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _b : await readDataTransferFromClipboard(doc).catch(() => {
2675
+ const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _b : await readDataTransferFromClipboard(doc).catch(() => {
2443
2676
  throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
2444
2677
  });
2445
- return pasteImpl(target, data);
2446
- }
2447
- function pasteImpl(target, clipboardData) {
2448
- var _a;
2449
- import_dom13.fireEvent.paste(target, {
2450
- clipboardData
2678
+ this.dispatchUIEvent(target, "paste", {
2679
+ clipboardData: dataTransfer
2451
2680
  });
2452
2681
  if (isEditable(target)) {
2453
- const data = clipboardData.getData("text").substr(0, getSpaceUntilMaxLength(target));
2454
- if (data) {
2455
- (_a = prepareInput(data, target, "insertFromPaste")) == null ? void 0 : _a.commit();
2682
+ const textData = dataTransfer.getData("text").substr(0, getSpaceUntilMaxLength(target));
2683
+ if (textData) {
2684
+ (_c = prepareInput(this[Config], textData, target, "insertFromPaste")) == null ? void 0 : _c.commit();
2456
2685
  }
2457
2686
  }
2458
2687
  }
@@ -2476,11 +2705,11 @@ async function clear(element) {
2476
2705
  if (!isAllSelected(element)) {
2477
2706
  throw new Error("The element content to be cleared could not be selected.");
2478
2707
  }
2479
- (_a = prepareInput("", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
2708
+ (_a = prepareInput(this[Config], "", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
2480
2709
  }
2481
2710
 
2482
2711
  // src/utility/selectOptions.ts
2483
- var import_dom14 = require("@testing-library/dom");
2712
+ var import_dom4 = require("@testing-library/dom");
2484
2713
  async function selectOptions(select, values) {
2485
2714
  return selectOptionsBase.call(this, true, select, values);
2486
2715
  }
@@ -2489,7 +2718,7 @@ async function deselectOptions(select, values) {
2489
2718
  }
2490
2719
  async function selectOptionsBase(newValue, select, values) {
2491
2720
  if (!newValue && !select.multiple) {
2492
- throw (0, import_dom14.getConfig)().getElementError(`Unable to deselect an option in a non-multiple select. Use selectOptions to change the selection instead.`, select);
2721
+ throw (0, import_dom4.getConfig)().getElementError(`Unable to deselect an option in a non-multiple select. Use selectOptions to change the selection instead.`, select);
2493
2722
  }
2494
2723
  const valArray = Array.isArray(values) ? values : [values];
2495
2724
  const allOptions = Array.from(select.querySelectorAll('option, [role="option"]'));
@@ -2501,38 +2730,47 @@ async function selectOptionsBase(newValue, select, values) {
2501
2730
  if (matchingOption) {
2502
2731
  return matchingOption;
2503
2732
  } else {
2504
- throw (0, import_dom14.getConfig)().getElementError(`Value "${String(val)}" not found in options`, select);
2733
+ throw (0, import_dom4.getConfig)().getElementError(`Value "${String(val)}" not found in options`, select);
2505
2734
  }
2506
2735
  }
2507
2736
  }).filter((option) => !isDisabled(option));
2508
2737
  if (isDisabled(select) || !selectedOptions.length)
2509
2738
  return;
2739
+ const selectOption = (option) => {
2740
+ option.selected = newValue;
2741
+ this.dispatchUIEvent(select, "input", {
2742
+ bubbles: true,
2743
+ cancelable: false,
2744
+ composed: true
2745
+ });
2746
+ this.dispatchUIEvent(select, "change");
2747
+ };
2510
2748
  if (isElementType(select, "select")) {
2511
2749
  if (select.multiple) {
2512
2750
  for (const option of selectedOptions) {
2513
- const withPointerEvents = this[Config].skipPointerEventsCheck ? true : hasPointerEvents(option);
2751
+ const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(option);
2514
2752
  if (withPointerEvents) {
2515
- import_dom14.fireEvent.pointerOver(option);
2516
- import_dom14.fireEvent.pointerEnter(select);
2517
- import_dom14.fireEvent.mouseOver(option);
2518
- import_dom14.fireEvent.mouseEnter(select);
2519
- import_dom14.fireEvent.pointerMove(option);
2520
- import_dom14.fireEvent.mouseMove(option);
2521
- import_dom14.fireEvent.pointerDown(option);
2522
- import_dom14.fireEvent.mouseDown(option);
2753
+ this.dispatchUIEvent(option, "pointerover");
2754
+ this.dispatchUIEvent(select, "pointerenter");
2755
+ this.dispatchUIEvent(option, "mouseover");
2756
+ this.dispatchUIEvent(select, "mouseenter");
2757
+ this.dispatchUIEvent(option, "pointermove");
2758
+ this.dispatchUIEvent(option, "mousemove");
2759
+ this.dispatchUIEvent(option, "pointerdown");
2760
+ this.dispatchUIEvent(option, "mousedown");
2523
2761
  }
2524
2762
  focus(select);
2525
2763
  if (withPointerEvents) {
2526
- import_dom14.fireEvent.pointerUp(option);
2527
- import_dom14.fireEvent.mouseUp(option);
2764
+ this.dispatchUIEvent(option, "pointerup");
2765
+ this.dispatchUIEvent(option, "mouseup");
2528
2766
  }
2529
2767
  selectOption(option);
2530
2768
  if (withPointerEvents) {
2531
- import_dom14.fireEvent.click(option);
2769
+ this.dispatchUIEvent(option, "click");
2532
2770
  }
2533
2771
  }
2534
2772
  } else if (selectedOptions.length === 1) {
2535
- const withPointerEvents = this[Config].skipPointerEventsCheck ? true : hasPointerEvents(select);
2773
+ const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(select);
2536
2774
  if (withPointerEvents) {
2537
2775
  await this.click(select);
2538
2776
  } else {
@@ -2540,16 +2778,16 @@ async function selectOptionsBase(newValue, select, values) {
2540
2778
  }
2541
2779
  selectOption(selectedOptions[0]);
2542
2780
  if (withPointerEvents) {
2543
- import_dom14.fireEvent.pointerOver(select);
2544
- import_dom14.fireEvent.pointerEnter(select);
2545
- import_dom14.fireEvent.mouseOver(select);
2546
- import_dom14.fireEvent.mouseEnter(select);
2547
- import_dom14.fireEvent.pointerUp(select);
2548
- import_dom14.fireEvent.mouseUp(select);
2549
- import_dom14.fireEvent.click(select);
2781
+ this.dispatchUIEvent(select, "pointerover");
2782
+ this.dispatchUIEvent(select, "pointerenter");
2783
+ this.dispatchUIEvent(select, "mouseover");
2784
+ this.dispatchUIEvent(select, "mouseenter");
2785
+ this.dispatchUIEvent(select, "pointerup");
2786
+ this.dispatchUIEvent(select, "mouseup");
2787
+ this.dispatchUIEvent(select, "click");
2550
2788
  }
2551
2789
  } else {
2552
- throw (0, import_dom14.getConfig)().getElementError(`Cannot select multiple options on a non-multiple select`, select);
2790
+ throw (0, import_dom4.getConfig)().getElementError(`Cannot select multiple options on a non-multiple select`, select);
2553
2791
  }
2554
2792
  } else if (select.getAttribute("role") === "listbox") {
2555
2793
  for (const option of selectedOptions) {
@@ -2557,16 +2795,7 @@ async function selectOptionsBase(newValue, select, values) {
2557
2795
  await this.unhover(option);
2558
2796
  }
2559
2797
  } else {
2560
- throw (0, import_dom14.getConfig)().getElementError(`Cannot select options on elements that are neither select nor listbox elements`, select);
2561
- }
2562
- function selectOption(option) {
2563
- option.selected = newValue;
2564
- (0, import_dom14.fireEvent)(select, (0, import_dom14.createEvent)("input", select, {
2565
- bubbles: true,
2566
- cancelable: false,
2567
- composed: true
2568
- }));
2569
- import_dom14.fireEvent.change(select);
2798
+ throw (0, import_dom4.getConfig)().getElementError(`Cannot select options on elements that are neither select nor listbox elements`, select);
2570
2799
  }
2571
2800
  }
2572
2801
 
@@ -2592,28 +2821,29 @@ async function type(element, text, {
2592
2821
  }
2593
2822
 
2594
2823
  // src/utility/upload.ts
2595
- var import_dom15 = require("@testing-library/dom");
2596
2824
  async function upload(element, fileOrFiles) {
2597
- var _a;
2598
2825
  const input = isElementType(element, "label") ? element.control : element;
2599
2826
  if (!input || !isElementType(input, "input", { type: "file" })) {
2600
2827
  throw new TypeError(`The ${input === element ? "given" : "associated"} ${input == null ? void 0 : input.tagName} element does not accept file uploads`);
2601
2828
  }
2602
2829
  if (isDisabled(element))
2603
2830
  return;
2604
- await this.click(element);
2605
2831
  const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? void 0 : 1);
2606
- blur(element);
2607
- focus(element);
2608
- if (files.length === ((_a = input.files) == null ? void 0 : _a.length) && files.every((f, i) => {
2609
- var _a2;
2610
- return f === ((_a2 = input.files) == null ? void 0 : _a2.item(i));
2611
- })) {
2612
- return;
2613
- }
2614
- setFiles(input, createFileList(files));
2615
- import_dom15.fireEvent.input(input);
2616
- import_dom15.fireEvent.change(input);
2832
+ const fileDialog = () => {
2833
+ var _a;
2834
+ if (files.length === ((_a = input.files) == null ? void 0 : _a.length) && files.every((f, i) => {
2835
+ var _a2;
2836
+ return f === ((_a2 = input.files) == null ? void 0 : _a2.item(i));
2837
+ })) {
2838
+ return;
2839
+ }
2840
+ setFiles(input, createFileList(files));
2841
+ this.dispatchUIEvent(input, "input");
2842
+ this.dispatchUIEvent(input, "change");
2843
+ };
2844
+ input.addEventListener("fileDialog", fileDialog);
2845
+ await this.click(element);
2846
+ input.removeEventListener("fileDialog", fileDialog);
2617
2847
  }
2618
2848
  function isAcceptableFile(file, accept) {
2619
2849
  if (!accept) {
@@ -2631,46 +2861,61 @@ function isAcceptableFile(file, accept) {
2631
2861
  }
2632
2862
 
2633
2863
  // src/setup/wrapAsync.ts
2634
- var import_dom16 = require("@testing-library/dom");
2864
+ var import_dom5 = require("@testing-library/dom");
2635
2865
  function wrapAsync(implementation) {
2636
- return (0, import_dom16.getConfig)().asyncWrapper(implementation);
2866
+ return (0, import_dom5.getConfig)().asyncWrapper(implementation);
2637
2867
  }
2638
2868
 
2639
2869
  // src/setup/setup.ts
2870
+ function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
2871
+ const document2 = getDocument(options, node);
2872
+ const {
2873
+ keyboardState = createKeyboardState(),
2874
+ pointerState = createPointerState(document2)
2875
+ } = options;
2876
+ return __spreadProps(__spreadValues(__spreadValues({}, defaults), options), {
2877
+ document: document2,
2878
+ keyboardState,
2879
+ pointerState
2880
+ });
2881
+ }
2640
2882
  function setupMain(options = {}) {
2641
2883
  var _a;
2642
- const doc = getDocument(options);
2643
- prepareDocument(doc);
2644
- const view = (_a = doc.defaultView) != null ? _a : window;
2884
+ const config = createConfig(options);
2885
+ prepareDocument(config.document);
2886
+ const view = (_a = config.document.defaultView) != null ? _a : window;
2645
2887
  attachClipboardStubToView(view);
2646
- return doSetup(__spreadProps(__spreadValues({}, defaultOptionsSetup), {
2647
- keyboardState: createKeyboardState(),
2648
- pointerState: createPointerState(doc)
2649
- }));
2888
+ return doSetup(config);
2650
2889
  }
2651
2890
  function setupDirect(options = {}, node) {
2652
- const doc = getDocument(options, node);
2653
- prepareDocument(doc);
2654
- return doSetup(__spreadValues(__spreadValues({
2655
- keyboardState: createKeyboardState(),
2656
- pointerState: createPointerState(doc)
2657
- }, defaultOptionsDirect), options));
2891
+ const config = createConfig(options, defaultOptionsDirect, node);
2892
+ prepareDocument(config.document);
2893
+ return {
2894
+ config,
2895
+ api: doSetup(config)
2896
+ };
2658
2897
  }
2659
2898
  function setupSub(options) {
2660
2899
  return doSetup(__spreadValues(__spreadValues({}, this[Config]), options));
2661
2900
  }
2662
- function wrapImpl(impl) {
2901
+ function wrapAndBindImpl(instance, impl) {
2663
2902
  function method(...args) {
2664
- return wrapAsync(() => impl.apply(this, args));
2903
+ setLevelRef(instance[Config], 1 /* Call */);
2904
+ return wrapAsync(() => impl.apply(instance, args));
2665
2905
  }
2666
2906
  Object.defineProperty(method, "name", { get: () => impl.name });
2667
2907
  return method;
2668
2908
  }
2669
- var wrappedApis = Object.fromEntries(Object.entries(api_exports).map(([name, impl]) => [name, wrapImpl(impl)]));
2670
2909
  function doSetup(config) {
2671
- return __spreadProps(__spreadValues({}, wrappedApis), {
2672
- setup: setupSub,
2673
- [Config]: config
2910
+ const instance = __spreadValues({
2911
+ [Config]: config,
2912
+ dispatchUIEvent: bindDispatchUIEvent(config)
2913
+ }, api_exports);
2914
+ return __spreadProps(__spreadValues({}, Object.fromEntries(Object.entries(api_exports).map(([name, api]) => [
2915
+ name,
2916
+ wrapAndBindImpl(instance, api)
2917
+ ]))), {
2918
+ setup: setupSub.bind(instance)
2674
2919
  });
2675
2920
  }
2676
2921
  function getDocument(options, node) {
@@ -2699,58 +2944,56 @@ __export(directApi_exports, {
2699
2944
  upload: () => upload2
2700
2945
  });
2701
2946
  function clear2(element) {
2702
- return setupDirect().clear(element);
2947
+ return setupDirect().api.clear(element);
2703
2948
  }
2704
2949
  function click2(element, options = {}) {
2705
- return setupDirect(options, element).click(element);
2950
+ return setupDirect(options, element).api.click(element);
2706
2951
  }
2707
2952
  function copy2(options = {}) {
2708
- return setupDirect(options).copy();
2953
+ return setupDirect(options).api.copy();
2709
2954
  }
2710
2955
  function cut2(options = {}) {
2711
- return setupDirect(options).cut();
2956
+ return setupDirect(options).api.cut();
2712
2957
  }
2713
2958
  function dblClick2(element, options = {}) {
2714
- return setupDirect(options).dblClick(element);
2959
+ return setupDirect(options).api.dblClick(element);
2715
2960
  }
2716
2961
  function deselectOptions2(select, values, options = {}) {
2717
- return setupDirect(options).deselectOptions(select, values);
2962
+ return setupDirect(options).api.deselectOptions(select, values);
2718
2963
  }
2719
2964
  function hover2(element, options = {}) {
2720
- return setupDirect(options).hover(element);
2965
+ return setupDirect(options).api.hover(element);
2721
2966
  }
2722
2967
  async function keyboard2(text, options = {}) {
2723
- const instance = setupDirect(options);
2724
- const promise = instance.keyboard(text);
2725
- return promise.then(() => instance[Config].keyboardState);
2968
+ const { config, api } = setupDirect(options);
2969
+ return api.keyboard(text).then(() => config.keyboardState);
2726
2970
  }
2727
2971
  async function pointer2(input, options = {}) {
2728
- const instance = setupDirect(options);
2729
- const promise = instance.pointer(input);
2730
- return promise.then(() => instance[Config].pointerState);
2972
+ const { config, api } = setupDirect(options);
2973
+ return api.pointer(input).then(() => config.pointerState);
2731
2974
  }
2732
2975
  function paste2(clipboardData, options) {
2733
- return setupDirect(options).paste(clipboardData);
2976
+ return setupDirect(options).api.paste(clipboardData);
2734
2977
  }
2735
2978
  function selectOptions2(select, values, options = {}) {
2736
- return setupDirect(options).selectOptions(select, values);
2979
+ return setupDirect(options).api.selectOptions(select, values);
2737
2980
  }
2738
2981
  function tripleClick2(element, options = {}) {
2739
- return setupDirect(options).tripleClick(element);
2982
+ return setupDirect(options).api.tripleClick(element);
2740
2983
  }
2741
2984
  function type2(element, text, options = {}) {
2742
- return setupDirect(options, element).type(element, text, options);
2985
+ return setupDirect(options, element).api.type(element, text, options);
2743
2986
  }
2744
2987
  function unhover2(element, options = {}) {
2745
- const instance = setupDirect(options);
2746
- instance[Config].pointerState.position.mouse.target = element;
2747
- return instance.unhover(element);
2988
+ const { config, api } = setupDirect(options);
2989
+ config.pointerState.position.mouse.target = element;
2990
+ return api.unhover(element);
2748
2991
  }
2749
2992
  function upload2(element, fileOrFiles, options = {}) {
2750
- return setupDirect(options).upload(element, fileOrFiles);
2993
+ return setupDirect(options).api.upload(element, fileOrFiles);
2751
2994
  }
2752
2995
  function tab2(options = {}) {
2753
- return setupDirect().tab(options);
2996
+ return setupDirect().api.tab(options);
2754
2997
  }
2755
2998
 
2756
2999
  // src/setup/index.ts