@testing-library/user-event 14.0.0-beta.8 → 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.
package/dist/index.mjs CHANGED
@@ -43,187 +43,6 @@ var __async = (__this, __arguments, generator) => {
43
43
  });
44
44
  };
45
45
 
46
- // src/document/index.ts
47
- import { fireEvent } from "@testing-library/dom";
48
-
49
- // src/document/interceptor.ts
50
- var Interceptor = Symbol("Interceptor for programmatical calls");
51
- function prepareInterceptor(element, propName, interceptorImpl) {
52
- const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
53
- const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
54
- const target = (prototypeDescriptor == null ? void 0 : prototypeDescriptor.set) ? "set" : "value";
55
- if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== "function" || prototypeDescriptor[target][Interceptor]) {
56
- return;
57
- }
58
- function intercept(...args) {
59
- const { applyNative = true, realArgs } = interceptorImpl.call(this, ...args);
60
- const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
61
- if (target === "set") {
62
- realFunc.call(this, realArgs);
63
- } else {
64
- realFunc.call(this, ...realArgs);
65
- }
66
- }
67
- ;
68
- intercept[Interceptor] = Interceptor;
69
- Object.defineProperty(element, propName, __spreadProps(__spreadValues({}, objectDescriptor != null ? objectDescriptor : prototypeDescriptor), {
70
- [target]: intercept
71
- }));
72
- }
73
-
74
- // src/document/selection.ts
75
- var UISelection = Symbol("Displayed selection in UI");
76
- function prepareSelectionInterceptor(element) {
77
- prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, end, direction = "none") {
78
- const isUI = start && typeof start === "object" && start[UISelection];
79
- if (!isUI) {
80
- this[UISelection] = void 0;
81
- }
82
- return {
83
- realArgs: [Number(start), end, direction]
84
- };
85
- });
86
- prepareInterceptor(element, "selectionStart", function interceptorImpl(v) {
87
- this[UISelection] = void 0;
88
- return { realArgs: v };
89
- });
90
- prepareInterceptor(element, "selectionEnd", function interceptorImpl(v) {
91
- this[UISelection] = void 0;
92
- return { realArgs: v };
93
- });
94
- }
95
- function setUISelection(element, {
96
- focusOffset: focusOffsetParam,
97
- anchorOffset: anchorOffsetParam = focusOffsetParam
98
- }, mode = "replace") {
99
- const valueLength = getUIValue(element).length;
100
- const sanitizeOffset = (o) => Math.max(0, Math.min(valueLength, o));
101
- const anchorOffset = mode === "replace" || element[UISelection] === void 0 ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
102
- const focusOffset = sanitizeOffset(focusOffsetParam);
103
- const startOffset = Math.min(anchorOffset, focusOffset);
104
- const endOffset = Math.max(anchorOffset, focusOffset);
105
- element[UISelection] = {
106
- anchorOffset,
107
- focusOffset
108
- };
109
- if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
110
- return;
111
- }
112
- const startObj = new Number(startOffset);
113
- startObj[UISelection] = UISelection;
114
- try {
115
- element.setSelectionRange(startObj, endOffset);
116
- } catch (e) {
117
- }
118
- }
119
- function getUISelection(element) {
120
- var _a, _b, _c;
121
- const sel = (_c = element[UISelection]) != null ? _c : {
122
- anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
123
- focusOffset: (_b = element.selectionEnd) != null ? _b : 0
124
- };
125
- return __spreadProps(__spreadValues({}, sel), {
126
- startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
127
- endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
128
- });
129
- }
130
- function clearUISelection(element) {
131
- element[UISelection] = void 0;
132
- }
133
-
134
- // src/document/value.ts
135
- var UIValue = Symbol("Displayed value in UI");
136
- var InitialValue = Symbol("Initial value to compare on blur");
137
- var TrackChanges = Symbol("Track programmatic changes for React workaround");
138
- function valueInterceptor(v) {
139
- const isUI = typeof v === "object" && v[UIValue];
140
- this[UIValue] = isUI ? String(v) : void 0;
141
- if (!isUI) {
142
- trackValue(this, String(v));
143
- this[InitialValue] = String(v);
144
- clearUISelection(this);
145
- }
146
- return {
147
- applyNative: !!isUI,
148
- realArgs: String(v)
149
- };
150
- }
151
- function prepareValueInterceptor(element) {
152
- prepareInterceptor(element, "value", valueInterceptor);
153
- }
154
- function setUIValue(element, value) {
155
- element.value = {
156
- [UIValue]: UIValue,
157
- toString: () => value
158
- };
159
- }
160
- function getUIValue(element) {
161
- return element[UIValue] === void 0 ? element.value : String(element[UIValue]);
162
- }
163
- function setInitialValue(element) {
164
- element[InitialValue] = element.value;
165
- }
166
- function getInitialValue(element) {
167
- return element[InitialValue];
168
- }
169
- function startTrackValue(element) {
170
- element[TrackChanges] = [];
171
- }
172
- function trackValue(element, v) {
173
- var _a;
174
- (_a = element[TrackChanges]) == null ? void 0 : _a.push(v);
175
- }
176
- function endTrackValue(element) {
177
- const tracked = element[TrackChanges];
178
- element[TrackChanges] = void 0;
179
- return tracked;
180
- }
181
-
182
- // src/document/index.ts
183
- var isPrepared = Symbol("Node prepared with document state workarounds");
184
- function prepareDocument(document2) {
185
- if (document2[isPrepared]) {
186
- return;
187
- }
188
- document2.addEventListener("focus", (e) => {
189
- const el = e.target;
190
- prepareElement(el);
191
- }, {
192
- capture: true,
193
- passive: true
194
- });
195
- if (document2.activeElement) {
196
- prepareElement(document2.activeElement);
197
- }
198
- document2.addEventListener("blur", (e) => {
199
- const el = e.target;
200
- const initialValue = getInitialValue(el);
201
- if (typeof initialValue === "string" && el.value !== initialValue) {
202
- fireEvent.change(el);
203
- }
204
- }, {
205
- capture: true,
206
- passive: true
207
- });
208
- document2[isPrepared] = isPrepared;
209
- }
210
- function prepareElement(el) {
211
- if ("value" in el) {
212
- setInitialValue(el);
213
- }
214
- if (el[isPrepared]) {
215
- return;
216
- }
217
- if ("value" in el) {
218
- prepareValueInterceptor(el);
219
- prepareSelectionInterceptor(el);
220
- }
221
- el[isPrepared] = isPrepared;
222
- }
223
-
224
- // src/keyboard/keyboardAction.ts
225
- import { fireEvent as fireEvent9 } from "@testing-library/dom";
226
-
227
46
  // src/utils/misc/isElementType.ts
228
47
  function isElementType(element, tag, props) {
229
48
  if (element.namespaceURI && element.namespaceURI !== "http://www.w3.org/1999/xhtml") {
@@ -607,9 +426,6 @@ function calculateNewValue(inputData, node, {
607
426
  };
608
427
  }
609
428
 
610
- // src/utils/edit/editInputElement.ts
611
- import { fireEvent as fireEvent2 } from "@testing-library/dom";
612
-
613
429
  // src/utils/edit/isContentEditable.ts
614
430
  function isContentEditable(element) {
615
431
  return element.hasAttribute("contenteditable") && (element.getAttribute("contenteditable") == "true" || element.getAttribute("contenteditable") == "");
@@ -733,7 +549,7 @@ function setSelection({
733
549
  }
734
550
 
735
551
  // src/utils/edit/editInputElement.ts
736
- function editInputElement(element, {
552
+ function editInputElement(config, element, {
737
553
  newValue,
738
554
  newSelection,
739
555
  eventOverrides
@@ -746,7 +562,7 @@ function editInputElement(element, {
746
562
  focusOffset: newSelection.offset
747
563
  });
748
564
  startTrackValue(element);
749
- fireEvent2.input(element, __spreadValues({}, eventOverrides));
565
+ dispatchUIEvent(config, element, "input", eventOverrides);
750
566
  const tracked = endTrackValue(element);
751
567
  if ((tracked == null ? void 0 : tracked.length) === 2 && tracked[0] === oldValue && tracked[1] === newValue) {
752
568
  setSelection({
@@ -798,9 +614,6 @@ function supportsMaxLength(element) {
798
614
  return isElementType(element, "textarea") || isElementType(element, "input") && Boolean(maxLengthSupportedTypes[element.type]);
799
615
  }
800
616
 
801
- // src/utils/edit/prepareInput.ts
802
- import { fireEvent as fireEvent3 } from "@testing-library/dom";
803
-
804
617
  // src/utils/focus/cursor.ts
805
618
  function getNextCursorPosition(node, offset, direction, inputType) {
806
619
  if (isTextNode(node) && offset + direction >= 0 && offset + direction <= node.nodeValue.length) {
@@ -905,7 +718,7 @@ function getDescendant(node, direction) {
905
718
  }
906
719
 
907
720
  // src/utils/edit/prepareInput.ts
908
- function prepareInput(data, element, inputType = "insertText") {
721
+ function prepareInput(config, data, element, inputType = "insertText") {
909
722
  const inputRange = getInputRange(element);
910
723
  if (!inputRange) {
911
724
  return;
@@ -944,7 +757,7 @@ function prepareInput(data, element, inputType = "insertText") {
944
757
  }
945
758
  }
946
759
  if (del || data) {
947
- fireEvent3.input(element, { inputType });
760
+ dispatchUIEvent(config, element, "input", { inputType });
948
761
  }
949
762
  }
950
763
  };
@@ -956,7 +769,7 @@ function prepareInput(data, element, inputType = "insertText") {
956
769
  if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
957
770
  return;
958
771
  }
959
- editInputElement(element, {
772
+ editInputElement(config, element, {
960
773
  newValue,
961
774
  newSelection: {
962
775
  node: element,
@@ -1204,6 +1017,14 @@ function isAllSelected(target) {
1204
1017
  return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
1205
1018
  }
1206
1019
 
1020
+ // src/utils/keyboard/getKeyEventProps.ts
1021
+ function getKeyEventProps(keyDef) {
1022
+ return {
1023
+ key: keyDef.key,
1024
+ code: keyDef.code
1025
+ };
1026
+ }
1027
+
1207
1028
  // src/utils/keyboard/getUIEventModifiers.ts
1208
1029
  function getUIEventModifiers(keyboardState) {
1209
1030
  return {
@@ -1222,14 +1043,6 @@ function getUIEventModifiers(keyboardState) {
1222
1043
  };
1223
1044
  }
1224
1045
 
1225
- // src/utils/keyboard/getKeyEventProps.ts
1226
- function getKeyEventProps(keyDef, state) {
1227
- return __spreadValues({
1228
- key: keyDef.key,
1229
- code: keyDef.code
1230
- }, getUIEventModifiers(state));
1231
- }
1232
-
1233
1046
  // src/utils/keyDef/readNextDescriptor.ts
1234
1047
  var bracketDict = /* @__PURE__ */ ((bracketDict2) => {
1235
1048
  bracketDict2["{"] = "}";
@@ -1308,6 +1121,11 @@ function getErrorMessage(expected, found, text) {
1308
1121
  for more information about how userEvent parses your input.`;
1309
1122
  }
1310
1123
 
1124
+ // src/utils/misc/cloneEvent.ts
1125
+ function cloneEvent(event) {
1126
+ return new event.constructor(event.type, event);
1127
+ }
1128
+
1311
1129
  // src/utils/misc/getDocumentFromNode.ts
1312
1130
  function getDocumentFromNode(el) {
1313
1131
  return isDocument(el) ? el : el.ownerDocument;
@@ -1474,10 +1292,6 @@ function hasBitFlag(conf, flag) {
1474
1292
  return (conf & flag) > 0;
1475
1293
  }
1476
1294
 
1477
- // src/utils/pointer/firePointerEvents.ts
1478
- import { createEvent, fireEvent as fireEvent4 } from "@testing-library/dom";
1479
- import { eventMap } from "@testing-library/dom/dist/event-map.js";
1480
-
1481
1295
  // src/utils/pointer/mouseButtons.ts
1482
1296
  var MouseButton = {
1483
1297
  primary: 0,
@@ -1509,38 +1323,33 @@ function getMouseButtons(...buttons) {
1509
1323
  return v;
1510
1324
  }
1511
1325
 
1512
- // src/utils/pointer/firePointerEvents.ts
1513
- function firePointerEvent(target, type3, {
1514
- pointerState,
1515
- keyboardState,
1516
- pointerType,
1517
- button,
1518
- coords,
1519
- pointerId,
1520
- isPrimary,
1521
- clickCount
1522
- }) {
1523
- const init = __spreadValues(__spreadValues({}, coords), getUIEventModifiers(keyboardState));
1524
- if (type3 === "click" || type3.startsWith("pointer")) {
1525
- init.pointerId = pointerId;
1526
- init.pointerType = pointerType;
1527
- }
1528
- if (["pointerdown", "pointerup"].includes(type3)) {
1529
- init.isPrimary = isPrimary;
1530
- }
1531
- init.button = getMouseButton(button != null ? button : 0);
1532
- init.buttons = getMouseButtons(...pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
1533
- var _a;
1534
- return (_a = p.keyDef.button) != null ? _a : 0;
1535
- }));
1536
- if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
1537
- init.detail = clickCount;
1326
+ // src/event/createEvent.ts
1327
+ import { createEvent as createEventBase } from "@testing-library/dom";
1328
+ import { eventMap as eventMap2 } from "@testing-library/dom/dist/event-map.js";
1329
+
1330
+ // src/event/eventTypes.ts
1331
+ import { eventMap } from "@testing-library/dom/dist/event-map.js";
1332
+ var eventKeys = Object.fromEntries(Object.keys(eventMap).map((k) => [k.toLowerCase(), k]));
1333
+ function getEventClass(type3) {
1334
+ return eventMap[eventKeys[type3]].EventType;
1335
+ }
1336
+ var mouseEvents = ["MouseEvent", "PointerEvent"];
1337
+ function isMouseEvent(type3) {
1338
+ return mouseEvents.includes(getEventClass(type3));
1339
+ }
1340
+ function isKeyboardEvent(type3) {
1341
+ return getEventClass(type3) === "KeyboardEvent";
1342
+ }
1343
+
1344
+ // src/event/createEvent.ts
1345
+ function createEvent(type3, target, init) {
1346
+ const eventKey = Object.keys(eventMap2).find((k) => k.toLowerCase() === type3);
1347
+ const event = createEventBase[eventKey](target, init);
1348
+ if (isMouseEvent(type3) && init) {
1349
+ assignPositionInit(event, init);
1350
+ assignPointerInit(event, init);
1538
1351
  }
1539
- const eventKey = Object.keys(eventMap).find((k) => k.toLowerCase() === type3);
1540
- const event = createEvent[eventKey](target, init);
1541
- assignPositionInit(event, init);
1542
- assignPointerInit(event, init);
1543
- return fireEvent4(target, event);
1352
+ return event;
1544
1353
  }
1545
1354
  function assignProps(obj, props) {
1546
1355
  for (const [key, value] of Object.entries(props)) {
@@ -1581,6 +1390,247 @@ function assignPointerInit(obj, { isPrimary, pointerId, pointerType }) {
1581
1390
  });
1582
1391
  }
1583
1392
 
1393
+ // src/event/behavior/registry.ts
1394
+ var behavior = {};
1395
+
1396
+ // src/event/behavior/click.ts
1397
+ behavior.click = (event, target, config) => {
1398
+ var _a;
1399
+ const control = (_a = target.closest("label")) == null ? void 0 : _a.control;
1400
+ if (control) {
1401
+ return () => {
1402
+ if (isFocusable(control)) {
1403
+ focus(control);
1404
+ }
1405
+ dispatchEvent(config, control, cloneEvent(event));
1406
+ };
1407
+ } else if (isElementType(target, "input", { type: "file" })) {
1408
+ return () => {
1409
+ blur(target);
1410
+ target.dispatchEvent(new Event("fileDialog"));
1411
+ focus(target);
1412
+ };
1413
+ }
1414
+ };
1415
+
1416
+ // src/event/dispatchEvent.ts
1417
+ function dispatchEvent(config, target, event) {
1418
+ var _a, _b;
1419
+ const type3 = event.type;
1420
+ const behaviorImplementation = (_b = (_a = behavior)[type3]) == null ? void 0 : _b.call(_a, event, target, config);
1421
+ if (behaviorImplementation) {
1422
+ event.preventDefault();
1423
+ let defaultPrevented = false;
1424
+ Object.defineProperty(event, "defaultPrevented", {
1425
+ get: () => defaultPrevented
1426
+ });
1427
+ Object.defineProperty(event, "preventDefault", {
1428
+ value: () => {
1429
+ defaultPrevented = event.cancelable;
1430
+ }
1431
+ });
1432
+ target.dispatchEvent(event);
1433
+ if (!defaultPrevented) {
1434
+ behaviorImplementation();
1435
+ }
1436
+ return !defaultPrevented;
1437
+ }
1438
+ return target.dispatchEvent(event);
1439
+ }
1440
+
1441
+ // src/event/wrapEvent.ts
1442
+ import { getConfig as getConfig2 } from "@testing-library/dom";
1443
+ function wrapEvent(cb, _element) {
1444
+ return getConfig2().eventWrapper(cb);
1445
+ }
1446
+
1447
+ // src/event/index.ts
1448
+ function dispatchUIEvent(config, target, type3, init) {
1449
+ if (isMouseEvent(type3) || isKeyboardEvent(type3)) {
1450
+ init = __spreadValues(__spreadValues({}, init), getUIEventModifiers(config.keyboardState));
1451
+ }
1452
+ const event = createEvent(type3, target, init);
1453
+ return wrapEvent(() => dispatchEvent(config, target, event), target);
1454
+ }
1455
+ function bindDispatchUIEvent(config) {
1456
+ return dispatchUIEvent.bind(void 0, config);
1457
+ }
1458
+
1459
+ // src/document/interceptor.ts
1460
+ var Interceptor = Symbol("Interceptor for programmatical calls");
1461
+ function prepareInterceptor(element, propName, interceptorImpl) {
1462
+ const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
1463
+ const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
1464
+ const target = (prototypeDescriptor == null ? void 0 : prototypeDescriptor.set) ? "set" : "value";
1465
+ if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== "function" || prototypeDescriptor[target][Interceptor]) {
1466
+ return;
1467
+ }
1468
+ function intercept(...args) {
1469
+ const { applyNative = true, realArgs } = interceptorImpl.call(this, ...args);
1470
+ const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
1471
+ if (target === "set") {
1472
+ realFunc.call(this, realArgs);
1473
+ } else {
1474
+ realFunc.call(this, ...realArgs);
1475
+ }
1476
+ }
1477
+ ;
1478
+ intercept[Interceptor] = Interceptor;
1479
+ Object.defineProperty(element, propName, __spreadProps(__spreadValues({}, objectDescriptor != null ? objectDescriptor : prototypeDescriptor), {
1480
+ [target]: intercept
1481
+ }));
1482
+ }
1483
+
1484
+ // src/document/selection.ts
1485
+ var UISelection = Symbol("Displayed selection in UI");
1486
+ function prepareSelectionInterceptor(element) {
1487
+ prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, end, direction = "none") {
1488
+ const isUI = start && typeof start === "object" && start[UISelection];
1489
+ if (!isUI) {
1490
+ this[UISelection] = void 0;
1491
+ }
1492
+ return {
1493
+ realArgs: [Number(start), end, direction]
1494
+ };
1495
+ });
1496
+ prepareInterceptor(element, "selectionStart", function interceptorImpl(v) {
1497
+ this[UISelection] = void 0;
1498
+ return { realArgs: v };
1499
+ });
1500
+ prepareInterceptor(element, "selectionEnd", function interceptorImpl(v) {
1501
+ this[UISelection] = void 0;
1502
+ return { realArgs: v };
1503
+ });
1504
+ }
1505
+ function setUISelection(element, {
1506
+ focusOffset: focusOffsetParam,
1507
+ anchorOffset: anchorOffsetParam = focusOffsetParam
1508
+ }, mode = "replace") {
1509
+ const valueLength = getUIValue(element).length;
1510
+ const sanitizeOffset = (o) => Math.max(0, Math.min(valueLength, o));
1511
+ const anchorOffset = mode === "replace" || element[UISelection] === void 0 ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
1512
+ const focusOffset = sanitizeOffset(focusOffsetParam);
1513
+ const startOffset = Math.min(anchorOffset, focusOffset);
1514
+ const endOffset = Math.max(anchorOffset, focusOffset);
1515
+ element[UISelection] = {
1516
+ anchorOffset,
1517
+ focusOffset
1518
+ };
1519
+ if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
1520
+ return;
1521
+ }
1522
+ const startObj = new Number(startOffset);
1523
+ startObj[UISelection] = UISelection;
1524
+ try {
1525
+ element.setSelectionRange(startObj, endOffset);
1526
+ } catch (e) {
1527
+ }
1528
+ }
1529
+ function getUISelection(element) {
1530
+ var _a, _b, _c;
1531
+ const sel = (_c = element[UISelection]) != null ? _c : {
1532
+ anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
1533
+ focusOffset: (_b = element.selectionEnd) != null ? _b : 0
1534
+ };
1535
+ return __spreadProps(__spreadValues({}, sel), {
1536
+ startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
1537
+ endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
1538
+ });
1539
+ }
1540
+ function clearUISelection(element) {
1541
+ element[UISelection] = void 0;
1542
+ }
1543
+
1544
+ // src/document/value.ts
1545
+ var UIValue = Symbol("Displayed value in UI");
1546
+ var InitialValue = Symbol("Initial value to compare on blur");
1547
+ var TrackChanges = Symbol("Track programmatic changes for React workaround");
1548
+ function valueInterceptor(v) {
1549
+ const isUI = typeof v === "object" && v[UIValue];
1550
+ this[UIValue] = isUI ? String(v) : void 0;
1551
+ if (!isUI) {
1552
+ trackValue(this, String(v));
1553
+ this[InitialValue] = String(v);
1554
+ clearUISelection(this);
1555
+ }
1556
+ return {
1557
+ applyNative: !!isUI,
1558
+ realArgs: String(v)
1559
+ };
1560
+ }
1561
+ function prepareValueInterceptor(element) {
1562
+ prepareInterceptor(element, "value", valueInterceptor);
1563
+ }
1564
+ function setUIValue(element, value) {
1565
+ element.value = {
1566
+ [UIValue]: UIValue,
1567
+ toString: () => value
1568
+ };
1569
+ }
1570
+ function getUIValue(element) {
1571
+ return element[UIValue] === void 0 ? element.value : String(element[UIValue]);
1572
+ }
1573
+ function setInitialValue(element) {
1574
+ element[InitialValue] = element.value;
1575
+ }
1576
+ function getInitialValue(element) {
1577
+ return element[InitialValue];
1578
+ }
1579
+ function startTrackValue(element) {
1580
+ element[TrackChanges] = [];
1581
+ }
1582
+ function trackValue(element, v) {
1583
+ var _a;
1584
+ (_a = element[TrackChanges]) == null ? void 0 : _a.push(v);
1585
+ }
1586
+ function endTrackValue(element) {
1587
+ const tracked = element[TrackChanges];
1588
+ element[TrackChanges] = void 0;
1589
+ return tracked;
1590
+ }
1591
+
1592
+ // src/document/index.ts
1593
+ var isPrepared = Symbol("Node prepared with document state workarounds");
1594
+ function prepareDocument(document2) {
1595
+ if (document2[isPrepared]) {
1596
+ return;
1597
+ }
1598
+ document2.addEventListener("focus", (e) => {
1599
+ const el = e.target;
1600
+ prepareElement(el);
1601
+ }, {
1602
+ capture: true,
1603
+ passive: true
1604
+ });
1605
+ if (document2.activeElement) {
1606
+ prepareElement(document2.activeElement);
1607
+ }
1608
+ document2.addEventListener("blur", (e) => {
1609
+ const el = e.target;
1610
+ const initialValue = getInitialValue(el);
1611
+ if (typeof initialValue === "string" && el.value !== initialValue) {
1612
+ dispatchUIEvent({}, el, "change");
1613
+ }
1614
+ }, {
1615
+ capture: true,
1616
+ passive: true
1617
+ });
1618
+ document2[isPrepared] = isPrepared;
1619
+ }
1620
+ function prepareElement(el) {
1621
+ if ("value" in el) {
1622
+ setInitialValue(el);
1623
+ }
1624
+ if (el[isPrepared]) {
1625
+ return;
1626
+ }
1627
+ if ("value" in el) {
1628
+ prepareValueInterceptor(el);
1629
+ prepareSelectionInterceptor(el);
1630
+ }
1631
+ el[isPrepared] = isPrepared;
1632
+ }
1633
+
1584
1634
  // src/keyboard/plugins/arrow.ts
1585
1635
  var keydownBehavior = [
1586
1636
  {
@@ -1641,21 +1691,18 @@ var keydownBehavior2 = [
1641
1691
  },
1642
1692
  {
1643
1693
  matches: (keyDef, element) => keyDef.key === "Delete" && isEditable(element),
1644
- handle: (keDef, element) => {
1694
+ handle: (keDef, element, config) => {
1645
1695
  var _a;
1646
- (_a = prepareInput("", element, "deleteContentForward")) == null ? void 0 : _a.commit();
1696
+ (_a = prepareInput(config, "", element, "deleteContentForward")) == null ? void 0 : _a.commit();
1647
1697
  }
1648
1698
  }
1649
1699
  ];
1650
1700
 
1651
- // src/keyboard/plugins/character.ts
1652
- import { fireEvent as fireEvent6 } from "@testing-library/dom";
1653
-
1654
1701
  // src/keyboard/shared/fireChangeForInputTimeIfValid.ts
1655
- import { fireEvent as fireEvent5 } from "@testing-library/dom";
1656
- function fireChangeForInputTimeIfValid(el, prevValue, timeNewEntry) {
1702
+ function fireChangeForInputTimeIfValid(config, el, prevValue, timeNewEntry) {
1657
1703
  if (isValidInputTimeValue(el, timeNewEntry) && prevValue !== timeNewEntry) {
1658
- fireEvent5.change(el, { target: { value: timeNewEntry } });
1704
+ setUIValue(el, timeNewEntry);
1705
+ dispatchUIEvent(config, el, "change");
1659
1706
  }
1660
1707
  }
1661
1708
 
@@ -1666,10 +1713,10 @@ var keypressBehavior = [
1666
1713
  var _a;
1667
1714
  return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "time", readOnly: false });
1668
1715
  },
1669
- handle: (keyDef, element, { keyboardState }) => {
1716
+ handle: (keyDef, element, config) => {
1670
1717
  var _a;
1671
1718
  let newEntry = keyDef.key;
1672
- const textToBeTyped = ((_a = keyboardState.carryValue) != null ? _a : "") + newEntry;
1719
+ const textToBeTyped = ((_a = config.keyboardState.carryValue) != null ? _a : "") + newEntry;
1673
1720
  const timeNewEntry = buildTimeValue(textToBeTyped);
1674
1721
  if (isValidInputTimeValue(element, timeNewEntry)) {
1675
1722
  newEntry = timeNewEntry;
@@ -1677,7 +1724,7 @@ var keypressBehavior = [
1677
1724
  const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
1678
1725
  const prevValue = getValue(element);
1679
1726
  if (prevValue !== newValue) {
1680
- editInputElement(element, {
1727
+ editInputElement(config, element, {
1681
1728
  newValue,
1682
1729
  newSelection: {
1683
1730
  node: element,
@@ -1689,8 +1736,8 @@ var keypressBehavior = [
1689
1736
  }
1690
1737
  });
1691
1738
  }
1692
- fireChangeForInputTimeIfValid(element, prevValue, timeNewEntry);
1693
- keyboardState.carryValue = textToBeTyped;
1739
+ fireChangeForInputTimeIfValid(config, element, prevValue, timeNewEntry);
1740
+ config.keyboardState.carryValue = textToBeTyped;
1694
1741
  }
1695
1742
  },
1696
1743
  {
@@ -1698,10 +1745,10 @@ var keypressBehavior = [
1698
1745
  var _a;
1699
1746
  return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "date", readOnly: false });
1700
1747
  },
1701
- handle: (keyDef, element, { keyboardState }) => {
1748
+ handle: (keyDef, element, config) => {
1702
1749
  var _a;
1703
1750
  let newEntry = keyDef.key;
1704
- const textToBeTyped = ((_a = keyboardState.carryValue) != null ? _a : "") + newEntry;
1751
+ const textToBeTyped = ((_a = config.keyboardState.carryValue) != null ? _a : "") + newEntry;
1705
1752
  const isValidToBeTyped = isValidDateValue(element, textToBeTyped);
1706
1753
  if (isValidToBeTyped) {
1707
1754
  newEntry = textToBeTyped;
@@ -1709,7 +1756,7 @@ var keypressBehavior = [
1709
1756
  const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
1710
1757
  const prevValue = getValue(element);
1711
1758
  if (prevValue !== newValue) {
1712
- editInputElement(element, {
1759
+ editInputElement(config, element, {
1713
1760
  newValue,
1714
1761
  newSelection: {
1715
1762
  node: element,
@@ -1722,11 +1769,10 @@ var keypressBehavior = [
1722
1769
  });
1723
1770
  }
1724
1771
  if (isValidToBeTyped) {
1725
- fireEvent6.change(element, {
1726
- target: { value: textToBeTyped }
1727
- });
1772
+ setUIValue(element, textToBeTyped);
1773
+ dispatchUIEvent(config, element, "change");
1728
1774
  }
1729
- keyboardState.carryValue = textToBeTyped;
1775
+ config.keyboardState.carryValue = textToBeTyped;
1730
1776
  }
1731
1777
  },
1732
1778
  {
@@ -1734,12 +1780,12 @@ var keypressBehavior = [
1734
1780
  var _a;
1735
1781
  return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "number", readOnly: false });
1736
1782
  },
1737
- handle: (keyDef, element) => {
1783
+ handle: (keyDef, element, config) => {
1738
1784
  var _a, _b;
1739
1785
  if (!/[\d.\-e]/.test(keyDef.key)) {
1740
1786
  return;
1741
1787
  }
1742
- const { getNewValue, commit } = prepareInput(keyDef.key, element);
1788
+ const { getNewValue, commit } = prepareInput(config, keyDef.key, element);
1743
1789
  const newValue = getNewValue();
1744
1790
  const valueParts = newValue.split("e", 2);
1745
1791
  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])) {
@@ -1753,28 +1799,27 @@ var keypressBehavior = [
1753
1799
  var _a;
1754
1800
  return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && (isEditableInput(element) || isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0;
1755
1801
  },
1756
- handle: (keyDef, element) => {
1802
+ handle: (keyDef, element, config) => {
1757
1803
  var _a;
1758
- (_a = prepareInput(keyDef.key, element)) == null ? void 0 : _a.commit();
1804
+ (_a = prepareInput(config, keyDef.key, element)) == null ? void 0 : _a.commit();
1759
1805
  }
1760
1806
  },
1761
1807
  {
1762
1808
  matches: (keyDef, element) => keyDef.key === "Enter" && (isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0,
1763
- handle: (keyDef, element, { keyboardState }) => {
1809
+ handle: (keyDef, element, config) => {
1764
1810
  var _a;
1765
- (_a = prepareInput("\n", element, isContentEditable(element) && !keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak")) == null ? void 0 : _a.commit();
1811
+ (_a = prepareInput(config, "\n", element, isContentEditable(element) && !config.keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak")) == null ? void 0 : _a.commit();
1766
1812
  }
1767
1813
  }
1768
1814
  ];
1769
1815
 
1770
1816
  // src/keyboard/plugins/functional.ts
1771
- import { fireEvent as fireEvent7 } from "@testing-library/dom";
1772
1817
  var keydownBehavior3 = [
1773
1818
  {
1774
1819
  matches: (keyDef, element) => keyDef.key === "Backspace" && isEditable(element),
1775
- handle: (keyDef, element) => {
1820
+ handle: (keyDef, element, config) => {
1776
1821
  var _a;
1777
- (_a = prepareInput("", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
1822
+ (_a = prepareInput(config, "", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
1778
1823
  }
1779
1824
  },
1780
1825
  {
@@ -1798,25 +1843,25 @@ var keydownBehavior3 = [
1798
1843
  var keypressBehavior2 = [
1799
1844
  {
1800
1845
  matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input") && ["checkbox", "radio"].includes(element.type),
1801
- handle: (keyDef, element) => {
1846
+ handle: (keyDef, element, config) => {
1802
1847
  const form = element.form;
1803
1848
  if (hasFormSubmit(form)) {
1804
- fireEvent7.submit(form);
1849
+ dispatchUIEvent(config, form, "submit");
1805
1850
  }
1806
1851
  }
1807
1852
  },
1808
1853
  {
1809
1854
  matches: (keyDef, element) => keyDef.key === "Enter" && (isClickableInput(element) || isElementType(element, "a") && Boolean(element.href)),
1810
- handle: (keyDef, element, { keyboardState }) => {
1811
- fireEvent7.click(element, getUIEventModifiers(keyboardState));
1855
+ handle: (keyDef, element, config) => {
1856
+ dispatchUIEvent(config, element, "click");
1812
1857
  }
1813
1858
  },
1814
1859
  {
1815
1860
  matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input"),
1816
- handle: (keyDef, element) => {
1861
+ handle: (keyDef, element, config) => {
1817
1862
  const form = element.form;
1818
1863
  if (form && (form.querySelectorAll("input").length === 1 || hasFormSubmit(form))) {
1819
- fireEvent7.submit(form);
1864
+ dispatchUIEvent(config, form, "submit");
1820
1865
  }
1821
1866
  }
1822
1867
  }
@@ -1824,8 +1869,8 @@ var keypressBehavior2 = [
1824
1869
  var keyupBehavior = [
1825
1870
  {
1826
1871
  matches: (keyDef, element) => keyDef.key === " " && isClickableInput(element),
1827
- handle: (keyDef, element, { keyboardState }) => {
1828
- fireEvent7.click(element, getUIEventModifiers(keyboardState));
1872
+ handle: (keyDef, element, config) => {
1873
+ dispatchUIEvent(config, element, "click");
1829
1874
  }
1830
1875
  }
1831
1876
  ];
@@ -1839,7 +1884,6 @@ var keydownBehavior4 = [
1839
1884
  ];
1840
1885
 
1841
1886
  // src/keyboard/plugins/modifiers.ts
1842
- import { fireEvent as fireEvent8 } from "@testing-library/dom";
1843
1887
  var modifierKeys = [
1844
1888
  "Alt",
1845
1889
  "AltGraph",
@@ -1859,12 +1903,12 @@ var modifierLocks = [
1859
1903
  var preKeydownBehavior = [
1860
1904
  {
1861
1905
  matches: (keyDef) => modifierKeys.includes(keyDef.key),
1862
- handle: (keyDef, element, { keyboardMap, keyboardState }) => {
1906
+ handle: (keyDef, element, config) => {
1863
1907
  var _a;
1864
- keyboardState.modifiers[keyDef.key] = true;
1908
+ config.keyboardState.modifiers[keyDef.key] = true;
1865
1909
  if (keyDef.key === "AltGraph") {
1866
- const ctrlKeyDef = (_a = keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
1867
- fireEvent8.keyDown(element, getKeyEventProps(ctrlKeyDef, keyboardState));
1910
+ const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
1911
+ dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
1868
1912
  }
1869
1913
  }
1870
1914
  },
@@ -1899,10 +1943,10 @@ var preKeyupBehavior = [
1899
1943
  var postKeyupBehavior = [
1900
1944
  {
1901
1945
  matches: (keyDef) => keyDef.key === "AltGraph",
1902
- handle: (keyDef, element, { keyboardMap, keyboardState }) => {
1946
+ handle: (keyDef, element, config) => {
1903
1947
  var _a;
1904
- const ctrlKeyDef = (_a = keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
1905
- fireEvent8.keyUp(element, getKeyEventProps(ctrlKeyDef, keyboardState));
1948
+ const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
1949
+ dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
1906
1950
  }
1907
1951
  }
1908
1952
  ];
@@ -1986,7 +2030,7 @@ function keydown(keyDef, getCurrentElement, config) {
1986
2030
  }
1987
2031
  config.keyboardState.activeElement = element;
1988
2032
  applyPlugins(preKeydownBehavior2, keyDef, element, config);
1989
- const unpreventedDefault = fireEvent9.keyDown(element, getKeyEventProps(keyDef, config.keyboardState));
2033
+ const unpreventedDefault = dispatchUIEvent(config, element, "keydown", getKeyEventProps(keyDef));
1990
2034
  config.keyboardState.pressed.push({ keyDef, unpreventedDefault });
1991
2035
  if (unpreventedDefault) {
1992
2036
  applyPlugins(keydownBehavior5, keyDef, getCurrentElement(), config);
@@ -1997,7 +2041,7 @@ function keydown(keyDef, getCurrentElement, config) {
1997
2041
  function keypress(keyDef, getCurrentElement, config) {
1998
2042
  return __async(this, null, function* () {
1999
2043
  const element = getCurrentElement();
2000
- const unpreventedDefault = fireEvent9.keyPress(element, __spreadProps(__spreadValues({}, getKeyEventProps(keyDef, config.keyboardState)), {
2044
+ const unpreventedDefault = dispatchUIEvent(config, element, "keypress", __spreadProps(__spreadValues({}, getKeyEventProps(keyDef)), {
2001
2045
  charCode: keyDef.key === "Enter" ? 13 : String(keyDef.key).charCodeAt(0)
2002
2046
  }));
2003
2047
  if (unpreventedDefault) {
@@ -2009,7 +2053,7 @@ function keyup(keyDef, getCurrentElement, config, unprevented) {
2009
2053
  return __async(this, null, function* () {
2010
2054
  const element = getCurrentElement();
2011
2055
  applyPlugins(preKeyupBehavior2, keyDef, element, config);
2012
- const unpreventedDefault = fireEvent9.keyUp(element, getKeyEventProps(keyDef, config.keyboardState));
2056
+ const unpreventedDefault = dispatchUIEvent(config, element, "keyup", getKeyEventProps(keyDef));
2013
2057
  if (unprevented && unpreventedDefault) {
2014
2058
  applyPlugins(keyupBehavior2, keyDef, getCurrentElement(), config);
2015
2059
  }
@@ -2064,8 +2108,7 @@ function parseKeyDef(keyboardMap, text) {
2064
2108
  // src/keyboard/index.ts
2065
2109
  function keyboard(text) {
2066
2110
  return __async(this, null, function* () {
2067
- const { keyboardMap } = this[Config];
2068
- const actions = parseKeyDef(keyboardMap, text);
2111
+ const actions = parseKeyDef(this[Config].keyboardMap, text);
2069
2112
  return keyboardAction(this[Config], actions);
2070
2113
  });
2071
2114
  }
@@ -2111,6 +2154,34 @@ function parseKeyDef2(pointerMap, keys) {
2111
2154
  return defs;
2112
2155
  }
2113
2156
 
2157
+ // src/pointer/firePointerEvents.ts
2158
+ function firePointerEvent(config, target, type3, {
2159
+ pointerType,
2160
+ button,
2161
+ coords,
2162
+ pointerId,
2163
+ isPrimary,
2164
+ clickCount
2165
+ }) {
2166
+ const init = __spreadValues({}, coords);
2167
+ if (type3 === "click" || type3.startsWith("pointer")) {
2168
+ init.pointerId = pointerId;
2169
+ init.pointerType = pointerType;
2170
+ }
2171
+ if (["pointerdown", "pointerup"].includes(type3)) {
2172
+ init.isPrimary = isPrimary;
2173
+ }
2174
+ init.button = getMouseButton(button != null ? button : 0);
2175
+ init.buttons = getMouseButtons(...config.pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
2176
+ var _a;
2177
+ return (_a = p.keyDef.button) != null ? _a : 0;
2178
+ }));
2179
+ if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
2180
+ init.detail = clickCount;
2181
+ }
2182
+ return dispatchUIEvent(config, target, type3, init);
2183
+ }
2184
+
2114
2185
  // src/pointer/resolveSelectionTarget.ts
2115
2186
  function resolveSelectionTarget({
2116
2187
  target,
@@ -2158,7 +2229,7 @@ function findNodeAtTextOffset(node, offset, isRoot = true) {
2158
2229
  // src/pointer/pointerMove.ts
2159
2230
  function pointerMove(_0, _1) {
2160
2231
  return __async(this, arguments, function* (config, { pointerName = "mouse", target, coords, node, offset }) {
2161
- const { pointerState, keyboardState } = config;
2232
+ const { pointerState } = config;
2162
2233
  if (!(pointerName in pointerState.position)) {
2163
2234
  throw new Error(`Trying to move pointer "${pointerName}" which does not exist.`);
2164
2235
  }
@@ -2233,9 +2304,7 @@ function pointerMove(_0, _1) {
2233
2304
  }
2234
2305
  }
2235
2306
  function fire(eventTarget, type3, eventCoords) {
2236
- return firePointerEvent(eventTarget, type3, {
2237
- pointerState,
2238
- keyboardState,
2307
+ return firePointerEvent(config, eventTarget, type3, {
2239
2308
  coords: eventCoords,
2240
2309
  pointerId,
2241
2310
  pointerType
@@ -2270,7 +2339,7 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
2270
2339
  var _a, _b, _c;
2271
2340
  setLevelRef(config, 2 /* Trigger */);
2272
2341
  assertPointerEvents(config, target);
2273
- const { pointerState, keyboardState } = config;
2342
+ const { pointerState } = config;
2274
2343
  const { name, pointerType, button } = keyDef;
2275
2344
  const pointerId = pointerType === "mouse" ? 1 : getNextPointerId(pointerState);
2276
2345
  pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
@@ -2332,9 +2401,7 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
2332
2401
  }
2333
2402
  return pressObj;
2334
2403
  function fire(type3) {
2335
- return firePointerEvent(target, type3, {
2336
- pointerState,
2337
- keyboardState,
2404
+ return firePointerEvent(config, target, type3, {
2338
2405
  button,
2339
2406
  clickCount,
2340
2407
  coords,
@@ -2351,10 +2418,9 @@ function up(config, pointerName, {
2351
2418
  node,
2352
2419
  offset
2353
2420
  }, pressed, targetIsDisabled) {
2354
- var _a;
2355
2421
  setLevelRef(config, 2 /* Trigger */);
2356
2422
  assertPointerEvents(config, target);
2357
- const { pointerState, keyboardState } = config;
2423
+ const { pointerState } = config;
2358
2424
  pointerState.pressed = pointerState.pressed.filter((p) => p !== pressed);
2359
2425
  const { isMultiTouch, isPrimary, pointerId, clickCount } = pressed;
2360
2426
  let { unpreventedDefault } = pressed;
@@ -2395,21 +2461,15 @@ function up(config, pointerName, {
2395
2461
  unpreventedDefault = fire("mouseup") && unpreventedDefault;
2396
2462
  const canClick = pointerType !== "mouse" || button === "primary";
2397
2463
  if (canClick && target === pressed.downTarget) {
2398
- const unpreventedClick = fire("click");
2464
+ fire("click");
2399
2465
  if (clickCount === 2) {
2400
2466
  fire("dblclick");
2401
2467
  }
2402
- const control = (_a = target.closest("label")) == null ? void 0 : _a.control;
2403
- if (unpreventedClick && control && isFocusable(control)) {
2404
- focus(control);
2405
- }
2406
2468
  }
2407
2469
  }
2408
2470
  }
2409
2471
  function fire(type3) {
2410
- return firePointerEvent(target, type3, {
2411
- pointerState,
2412
- keyboardState,
2472
+ return firePointerEvent(config, target, type3, {
2413
2473
  button,
2414
2474
  clickCount,
2415
2475
  coords,
@@ -2615,7 +2675,6 @@ function tab() {
2615
2675
  }
2616
2676
 
2617
2677
  // src/clipboard/copy.ts
2618
- import { fireEvent as fireEvent10 } from "@testing-library/dom";
2619
2678
  function copy() {
2620
2679
  return __async(this, null, function* () {
2621
2680
  var _a;
@@ -2625,7 +2684,7 @@ function copy() {
2625
2684
  if (clipboardData.items.length === 0) {
2626
2685
  return;
2627
2686
  }
2628
- fireEvent10.copy(target, {
2687
+ this.dispatchUIEvent(target, "copy", {
2629
2688
  clipboardData
2630
2689
  });
2631
2690
  if (this[Config].writeToClipboard) {
@@ -2636,7 +2695,6 @@ function copy() {
2636
2695
  }
2637
2696
 
2638
2697
  // src/clipboard/cut.ts
2639
- import { fireEvent as fireEvent11 } from "@testing-library/dom";
2640
2698
  function cut() {
2641
2699
  return __async(this, null, function* () {
2642
2700
  var _a, _b;
@@ -2646,11 +2704,11 @@ function cut() {
2646
2704
  if (clipboardData.items.length === 0) {
2647
2705
  return;
2648
2706
  }
2649
- fireEvent11.cut(target, {
2707
+ this.dispatchUIEvent(target, "cut", {
2650
2708
  clipboardData
2651
2709
  });
2652
2710
  if (isEditable(target)) {
2653
- (_b = prepareInput("", target, "deleteByCut")) == null ? void 0 : _b.commit();
2711
+ (_b = prepareInput(this[Config], "", target, "deleteByCut")) == null ? void 0 : _b.commit();
2654
2712
  }
2655
2713
  if (this[Config].writeToClipboard) {
2656
2714
  yield writeDataTransferToClipboard(doc, clipboardData);
@@ -2660,29 +2718,24 @@ function cut() {
2660
2718
  }
2661
2719
 
2662
2720
  // src/clipboard/paste.ts
2663
- import { fireEvent as fireEvent12 } from "@testing-library/dom";
2664
2721
  function paste(clipboardData) {
2665
2722
  return __async(this, null, function* () {
2666
- var _a, _b;
2723
+ var _a, _b, _c;
2667
2724
  const doc = this[Config].document;
2668
2725
  const target = (_a = doc.activeElement) != null ? _a : doc.body;
2669
- const data = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _b : yield readDataTransferFromClipboard(doc).catch(() => {
2726
+ const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _b : yield readDataTransferFromClipboard(doc).catch(() => {
2670
2727
  throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
2671
2728
  });
2672
- return pasteImpl(target, data);
2673
- });
2674
- }
2675
- function pasteImpl(target, clipboardData) {
2676
- var _a;
2677
- fireEvent12.paste(target, {
2678
- clipboardData
2679
- });
2680
- if (isEditable(target)) {
2681
- const data = clipboardData.getData("text").substr(0, getSpaceUntilMaxLength(target));
2682
- if (data) {
2683
- (_a = prepareInput(data, target, "insertFromPaste")) == null ? void 0 : _a.commit();
2729
+ this.dispatchUIEvent(target, "paste", {
2730
+ clipboardData: dataTransfer
2731
+ });
2732
+ if (isEditable(target)) {
2733
+ const textData = dataTransfer.getData("text").substr(0, getSpaceUntilMaxLength(target));
2734
+ if (textData) {
2735
+ (_c = prepareInput(this[Config], textData, target, "insertFromPaste")) == null ? void 0 : _c.commit();
2736
+ }
2684
2737
  }
2685
- }
2738
+ });
2686
2739
  }
2687
2740
  function getClipboardDataFromString(text) {
2688
2741
  const dt = createDataTransfer();
@@ -2705,12 +2758,12 @@ function clear(element) {
2705
2758
  if (!isAllSelected(element)) {
2706
2759
  throw new Error("The element content to be cleared could not be selected.");
2707
2760
  }
2708
- (_a = prepareInput("", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
2761
+ (_a = prepareInput(this[Config], "", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
2709
2762
  });
2710
2763
  }
2711
2764
 
2712
2765
  // src/utility/selectOptions.ts
2713
- import { createEvent as createEvent2, getConfig as getConfig2, fireEvent as fireEvent13 } from "@testing-library/dom";
2766
+ import { getConfig as getConfig3 } from "@testing-library/dom";
2714
2767
  function selectOptions(select, values) {
2715
2768
  return __async(this, null, function* () {
2716
2769
  return selectOptionsBase.call(this, true, select, values);
@@ -2724,7 +2777,7 @@ function deselectOptions(select, values) {
2724
2777
  function selectOptionsBase(newValue, select, values) {
2725
2778
  return __async(this, null, function* () {
2726
2779
  if (!newValue && !select.multiple) {
2727
- throw getConfig2().getElementError(`Unable to deselect an option in a non-multiple select. Use selectOptions to change the selection instead.`, select);
2780
+ throw getConfig3().getElementError(`Unable to deselect an option in a non-multiple select. Use selectOptions to change the selection instead.`, select);
2728
2781
  }
2729
2782
  const valArray = Array.isArray(values) ? values : [values];
2730
2783
  const allOptions = Array.from(select.querySelectorAll('option, [role="option"]'));
@@ -2736,34 +2789,43 @@ function selectOptionsBase(newValue, select, values) {
2736
2789
  if (matchingOption) {
2737
2790
  return matchingOption;
2738
2791
  } else {
2739
- throw getConfig2().getElementError(`Value "${String(val)}" not found in options`, select);
2792
+ throw getConfig3().getElementError(`Value "${String(val)}" not found in options`, select);
2740
2793
  }
2741
2794
  }
2742
2795
  }).filter((option) => !isDisabled(option));
2743
2796
  if (isDisabled(select) || !selectedOptions.length)
2744
2797
  return;
2798
+ const selectOption = (option) => {
2799
+ option.selected = newValue;
2800
+ this.dispatchUIEvent(select, "input", {
2801
+ bubbles: true,
2802
+ cancelable: false,
2803
+ composed: true
2804
+ });
2805
+ this.dispatchUIEvent(select, "change");
2806
+ };
2745
2807
  if (isElementType(select, "select")) {
2746
2808
  if (select.multiple) {
2747
2809
  for (const option of selectedOptions) {
2748
2810
  const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(option);
2749
2811
  if (withPointerEvents) {
2750
- fireEvent13.pointerOver(option);
2751
- fireEvent13.pointerEnter(select);
2752
- fireEvent13.mouseOver(option);
2753
- fireEvent13.mouseEnter(select);
2754
- fireEvent13.pointerMove(option);
2755
- fireEvent13.mouseMove(option);
2756
- fireEvent13.pointerDown(option);
2757
- fireEvent13.mouseDown(option);
2812
+ this.dispatchUIEvent(option, "pointerover");
2813
+ this.dispatchUIEvent(select, "pointerenter");
2814
+ this.dispatchUIEvent(option, "mouseover");
2815
+ this.dispatchUIEvent(select, "mouseenter");
2816
+ this.dispatchUIEvent(option, "pointermove");
2817
+ this.dispatchUIEvent(option, "mousemove");
2818
+ this.dispatchUIEvent(option, "pointerdown");
2819
+ this.dispatchUIEvent(option, "mousedown");
2758
2820
  }
2759
2821
  focus(select);
2760
2822
  if (withPointerEvents) {
2761
- fireEvent13.pointerUp(option);
2762
- fireEvent13.mouseUp(option);
2823
+ this.dispatchUIEvent(option, "pointerup");
2824
+ this.dispatchUIEvent(option, "mouseup");
2763
2825
  }
2764
2826
  selectOption(option);
2765
2827
  if (withPointerEvents) {
2766
- fireEvent13.click(option);
2828
+ this.dispatchUIEvent(option, "click");
2767
2829
  }
2768
2830
  }
2769
2831
  } else if (selectedOptions.length === 1) {
@@ -2775,16 +2837,16 @@ function selectOptionsBase(newValue, select, values) {
2775
2837
  }
2776
2838
  selectOption(selectedOptions[0]);
2777
2839
  if (withPointerEvents) {
2778
- fireEvent13.pointerOver(select);
2779
- fireEvent13.pointerEnter(select);
2780
- fireEvent13.mouseOver(select);
2781
- fireEvent13.mouseEnter(select);
2782
- fireEvent13.pointerUp(select);
2783
- fireEvent13.mouseUp(select);
2784
- fireEvent13.click(select);
2840
+ this.dispatchUIEvent(select, "pointerover");
2841
+ this.dispatchUIEvent(select, "pointerenter");
2842
+ this.dispatchUIEvent(select, "mouseover");
2843
+ this.dispatchUIEvent(select, "mouseenter");
2844
+ this.dispatchUIEvent(select, "pointerup");
2845
+ this.dispatchUIEvent(select, "mouseup");
2846
+ this.dispatchUIEvent(select, "click");
2785
2847
  }
2786
2848
  } else {
2787
- throw getConfig2().getElementError(`Cannot select multiple options on a non-multiple select`, select);
2849
+ throw getConfig3().getElementError(`Cannot select multiple options on a non-multiple select`, select);
2788
2850
  }
2789
2851
  } else if (select.getAttribute("role") === "listbox") {
2790
2852
  for (const option of selectedOptions) {
@@ -2792,16 +2854,7 @@ function selectOptionsBase(newValue, select, values) {
2792
2854
  yield this.unhover(option);
2793
2855
  }
2794
2856
  } else {
2795
- throw getConfig2().getElementError(`Cannot select options on elements that are neither select nor listbox elements`, select);
2796
- }
2797
- function selectOption(option) {
2798
- option.selected = newValue;
2799
- fireEvent13(select, createEvent2("input", select, {
2800
- bubbles: true,
2801
- cancelable: false,
2802
- composed: true
2803
- }));
2804
- fireEvent13.change(select);
2857
+ throw getConfig3().getElementError(`Cannot select options on elements that are neither select nor listbox elements`, select);
2805
2858
  }
2806
2859
  });
2807
2860
  }
@@ -2830,29 +2883,30 @@ function type(_0, _1) {
2830
2883
  }
2831
2884
 
2832
2885
  // src/utility/upload.ts
2833
- import { fireEvent as fireEvent14 } from "@testing-library/dom";
2834
2886
  function upload(element, fileOrFiles) {
2835
2887
  return __async(this, null, function* () {
2836
- var _a;
2837
2888
  const input = isElementType(element, "label") ? element.control : element;
2838
2889
  if (!input || !isElementType(input, "input", { type: "file" })) {
2839
2890
  throw new TypeError(`The ${input === element ? "given" : "associated"} ${input == null ? void 0 : input.tagName} element does not accept file uploads`);
2840
2891
  }
2841
2892
  if (isDisabled(element))
2842
2893
  return;
2843
- yield this.click(element);
2844
2894
  const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? void 0 : 1);
2845
- blur(input);
2846
- focus(input);
2847
- if (files.length === ((_a = input.files) == null ? void 0 : _a.length) && files.every((f, i) => {
2848
- var _a2;
2849
- return f === ((_a2 = input.files) == null ? void 0 : _a2.item(i));
2850
- })) {
2851
- return;
2852
- }
2853
- setFiles(input, createFileList(files));
2854
- fireEvent14.input(input);
2855
- fireEvent14.change(input);
2895
+ const fileDialog = () => {
2896
+ var _a;
2897
+ if (files.length === ((_a = input.files) == null ? void 0 : _a.length) && files.every((f, i) => {
2898
+ var _a2;
2899
+ return f === ((_a2 = input.files) == null ? void 0 : _a2.item(i));
2900
+ })) {
2901
+ return;
2902
+ }
2903
+ setFiles(input, createFileList(files));
2904
+ this.dispatchUIEvent(input, "input");
2905
+ this.dispatchUIEvent(input, "change");
2906
+ };
2907
+ input.addEventListener("fileDialog", fileDialog);
2908
+ yield this.click(element);
2909
+ input.removeEventListener("fileDialog", fileDialog);
2856
2910
  });
2857
2911
  }
2858
2912
  function isAcceptableFile(file, accept) {
@@ -2877,24 +2931,29 @@ function wrapAsync(implementation) {
2877
2931
  }
2878
2932
 
2879
2933
  // src/setup/setup.ts
2934
+ function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
2935
+ const document2 = getDocument(options, node);
2936
+ const {
2937
+ keyboardState = createKeyboardState(),
2938
+ pointerState = createPointerState(document2)
2939
+ } = options;
2940
+ return __spreadProps(__spreadValues(__spreadValues({}, defaults), options), {
2941
+ document: document2,
2942
+ keyboardState,
2943
+ pointerState
2944
+ });
2945
+ }
2880
2946
  function setupMain(options = {}) {
2881
2947
  var _a;
2882
- const doc = getDocument(options);
2883
- prepareDocument(doc);
2884
- const view = (_a = doc.defaultView) != null ? _a : window;
2948
+ const config = createConfig(options);
2949
+ prepareDocument(config.document);
2950
+ const view = (_a = config.document.defaultView) != null ? _a : window;
2885
2951
  attachClipboardStubToView(view);
2886
- return doSetup(__spreadProps(__spreadValues(__spreadValues({}, defaultOptionsSetup), options), {
2887
- keyboardState: createKeyboardState(),
2888
- pointerState: createPointerState(doc)
2889
- }));
2952
+ return doSetup(config);
2890
2953
  }
2891
2954
  function setupDirect(options = {}, node) {
2892
- const doc = getDocument(options, node);
2893
- prepareDocument(doc);
2894
- const config = __spreadValues(__spreadValues({
2895
- keyboardState: createKeyboardState(),
2896
- pointerState: createPointerState(doc)
2897
- }, defaultOptionsDirect), options);
2955
+ const config = createConfig(options, defaultOptionsDirect, node);
2956
+ prepareDocument(config.document);
2898
2957
  return {
2899
2958
  config,
2900
2959
  api: doSetup(config)
@@ -2913,7 +2972,8 @@ function wrapAndBindImpl(instance, impl) {
2913
2972
  }
2914
2973
  function doSetup(config) {
2915
2974
  const instance = __spreadValues({
2916
- [Config]: config
2975
+ [Config]: config,
2976
+ dispatchUIEvent: bindDispatchUIEvent(config)
2917
2977
  }, api_exports);
2918
2978
  return __spreadProps(__spreadValues({}, Object.fromEntries(Object.entries(api_exports).map(([name, api]) => [
2919
2979
  name,