@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.
- package/README.md +5 -192
- package/dist/index.cjs +860 -617
- package/dist/index.mjs +861 -618
- package/dist/types/clipboard/copy.d.ts +2 -2
- package/dist/types/clipboard/cut.d.ts +2 -2
- package/dist/types/clipboard/paste.d.ts +2 -2
- package/dist/types/convenience/click.d.ts +4 -4
- package/dist/types/convenience/hover.d.ts +3 -3
- package/dist/types/convenience/tab.d.ts +2 -2
- package/dist/types/event/behavior/click.d.ts +1 -0
- package/dist/types/event/behavior/index.d.ts +3 -0
- package/dist/types/event/behavior/registry.d.ts +9 -0
- package/dist/types/event/createEvent.d.ts +8 -0
- package/dist/types/event/dispatchEvent.d.ts +2 -0
- package/dist/types/event/eventTypes.d.ts +2 -0
- package/dist/types/event/index.d.ts +6 -0
- package/dist/types/event/types.d.ts +13 -0
- package/dist/types/event/wrapEvent.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/keyboard/index.d.ts +2 -2
- package/dist/types/keyboard/shared/fireChangeForInputTimeIfValid.d.ts +2 -1
- package/dist/types/options.d.ts +23 -8
- package/dist/types/pointer/firePointerEvents.d.ts +11 -0
- package/dist/types/pointer/index.d.ts +2 -2
- package/dist/types/pointer/pointerMove.d.ts +2 -2
- package/dist/types/pointer/pointerPress.d.ts +2 -2
- package/dist/types/pointer/types.d.ts +2 -1
- package/dist/types/setup/directApi.d.ts +1 -2
- package/dist/types/setup/index.d.ts +8 -2
- package/dist/types/setup/setup.d.ts +6 -60
- package/dist/types/utility/clear.d.ts +2 -2
- package/dist/types/utility/selectOptions.d.ts +3 -3
- package/dist/types/utility/type.d.ts +2 -2
- package/dist/types/utility/upload.d.ts +2 -2
- package/dist/types/utils/edit/editInputElement.d.ts +3 -5
- package/dist/types/utils/edit/prepareInput.d.ts +2 -1
- package/dist/types/utils/focus/cursor.d.ts +9 -0
- package/dist/types/utils/focus/focus.d.ts +3 -0
- package/dist/types/utils/index.d.ts +4 -2
- package/dist/types/utils/keyboard/getKeyEventProps.d.ts +2 -14
- package/dist/types/utils/misc/cloneEvent.d.ts +1 -0
- package/dist/types/utils/misc/findClosest.d.ts +1 -1
- package/dist/types/utils/misc/level.d.ts +17 -0
- package/dist/types/utils/pointer/cssPointerEvents.d.ts +15 -0
- package/package.json +1 -1
- package/CHANGELOG.md +0 -5
- package/dist/types/utils/misc/hasPointerEvents.d.ts +0 -15
- package/dist/types/utils/pointer/firePointerEvents.d.ts +0 -25
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
|
-
|
|
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,111 @@ function supportsMaxLength(element) {
|
|
|
798
614
|
return isElementType(element, "textarea") || isElementType(element, "input") && Boolean(maxLengthSupportedTypes[element.type]);
|
|
799
615
|
}
|
|
800
616
|
|
|
617
|
+
// src/utils/focus/cursor.ts
|
|
618
|
+
function getNextCursorPosition(node, offset, direction, inputType) {
|
|
619
|
+
if (isTextNode(node) && offset + direction >= 0 && offset + direction <= node.nodeValue.length) {
|
|
620
|
+
return { node, offset: offset + direction };
|
|
621
|
+
}
|
|
622
|
+
const nextNode = getNextCharacterContentNode(node, offset, direction);
|
|
623
|
+
if (nextNode) {
|
|
624
|
+
if (isTextNode(nextNode)) {
|
|
625
|
+
return {
|
|
626
|
+
node: nextNode,
|
|
627
|
+
offset: direction > 0 ? Math.min(1, nextNode.nodeValue.length) : Math.max(nextNode.nodeValue.length - 1, 0)
|
|
628
|
+
};
|
|
629
|
+
} else if (isElementType(nextNode, "br")) {
|
|
630
|
+
const nextPlusOne = getNextCharacterContentNode(nextNode, void 0, direction);
|
|
631
|
+
if (!nextPlusOne) {
|
|
632
|
+
if (direction < 0 && inputType === "deleteContentBackward") {
|
|
633
|
+
return {
|
|
634
|
+
node: nextNode.parentNode,
|
|
635
|
+
offset: getOffset(nextNode)
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
return void 0;
|
|
639
|
+
} else if (isTextNode(nextPlusOne)) {
|
|
640
|
+
return {
|
|
641
|
+
node: nextPlusOne,
|
|
642
|
+
offset: direction > 0 ? 0 : nextPlusOne.nodeValue.length
|
|
643
|
+
};
|
|
644
|
+
} else if (direction < 0 && isElementType(nextPlusOne, "br")) {
|
|
645
|
+
return {
|
|
646
|
+
node: nextNode.parentNode,
|
|
647
|
+
offset: getOffset(nextNode)
|
|
648
|
+
};
|
|
649
|
+
} else {
|
|
650
|
+
return {
|
|
651
|
+
node: nextPlusOne.parentNode,
|
|
652
|
+
offset: getOffset(nextPlusOne) + (direction > 0 ? 0 : 1)
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
} else {
|
|
656
|
+
return {
|
|
657
|
+
node: nextNode.parentNode,
|
|
658
|
+
offset: getOffset(nextNode) + (direction > 0 ? 1 : 0)
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
function getNextCharacterContentNode(node, offset, direction) {
|
|
664
|
+
const nextOffset = Number(offset) + (direction < 0 ? -1 : 0);
|
|
665
|
+
if (offset !== void 0 && isElement2(node) && nextOffset >= 0 && nextOffset < node.children.length) {
|
|
666
|
+
node = node.children[nextOffset];
|
|
667
|
+
}
|
|
668
|
+
return walkNodes(node, direction === 1 ? "next" : "previous", isTreatedAsCharacterContent);
|
|
669
|
+
}
|
|
670
|
+
function isTreatedAsCharacterContent(node) {
|
|
671
|
+
if (isTextNode(node)) {
|
|
672
|
+
return true;
|
|
673
|
+
}
|
|
674
|
+
if (isElement2(node)) {
|
|
675
|
+
if (isElementType(node, ["input", "textarea"])) {
|
|
676
|
+
return node.type !== "hidden";
|
|
677
|
+
} else if (isElementType(node, "br")) {
|
|
678
|
+
return true;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
return false;
|
|
682
|
+
}
|
|
683
|
+
function getOffset(node) {
|
|
684
|
+
let i = 0;
|
|
685
|
+
while (node.previousSibling) {
|
|
686
|
+
i++;
|
|
687
|
+
node = node.previousSibling;
|
|
688
|
+
}
|
|
689
|
+
return i;
|
|
690
|
+
}
|
|
691
|
+
function isElement2(node) {
|
|
692
|
+
return node.nodeType === 1;
|
|
693
|
+
}
|
|
694
|
+
function isTextNode(node) {
|
|
695
|
+
return node.nodeType === 3;
|
|
696
|
+
}
|
|
697
|
+
function walkNodes(node, direction, callback) {
|
|
698
|
+
var _a;
|
|
699
|
+
for (; ; ) {
|
|
700
|
+
const sibling = node[`${direction}Sibling`];
|
|
701
|
+
if (sibling) {
|
|
702
|
+
node = getDescendant(sibling, direction === "next" ? "first" : "last");
|
|
703
|
+
if (callback(node)) {
|
|
704
|
+
return node;
|
|
705
|
+
}
|
|
706
|
+
} else if (node.parentNode && (!isElement2(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a = node.ownerDocument) == null ? void 0 : _a.body))) {
|
|
707
|
+
node = node.parentNode;
|
|
708
|
+
} else {
|
|
709
|
+
break;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
function getDescendant(node, direction) {
|
|
714
|
+
while (node.hasChildNodes()) {
|
|
715
|
+
node = node[`${direction}Child`];
|
|
716
|
+
}
|
|
717
|
+
return node;
|
|
718
|
+
}
|
|
719
|
+
|
|
801
720
|
// src/utils/edit/prepareInput.ts
|
|
802
|
-
|
|
803
|
-
function prepareInput(data, element, inputType = "insertText") {
|
|
721
|
+
function prepareInput(config, data, element, inputType = "insertText") {
|
|
804
722
|
const inputRange = getInputRange(element);
|
|
805
723
|
if (!inputRange) {
|
|
806
724
|
return;
|
|
@@ -808,9 +726,22 @@ function prepareInput(data, element, inputType = "insertText") {
|
|
|
808
726
|
if ("startContainer" in inputRange) {
|
|
809
727
|
return {
|
|
810
728
|
commit: () => {
|
|
811
|
-
|
|
812
|
-
if (
|
|
729
|
+
let del = false;
|
|
730
|
+
if (!inputRange.collapsed) {
|
|
731
|
+
del = true;
|
|
813
732
|
inputRange.deleteContents();
|
|
733
|
+
} else if (["deleteContentBackward", "deleteContentForward"].includes(inputType)) {
|
|
734
|
+
const nextPosition = getNextCursorPosition(inputRange.startContainer, inputRange.startOffset, inputType === "deleteContentBackward" ? -1 : 1, inputType);
|
|
735
|
+
if (nextPosition) {
|
|
736
|
+
del = true;
|
|
737
|
+
const delRange = inputRange.cloneRange();
|
|
738
|
+
if (delRange.comparePoint(nextPosition.node, nextPosition.offset) < 0) {
|
|
739
|
+
delRange.setStart(nextPosition.node, nextPosition.offset);
|
|
740
|
+
} else {
|
|
741
|
+
delRange.setEnd(nextPosition.node, nextPosition.offset);
|
|
742
|
+
}
|
|
743
|
+
delRange.deleteContents();
|
|
744
|
+
}
|
|
814
745
|
}
|
|
815
746
|
if (data) {
|
|
816
747
|
if (inputRange.endContainer.nodeType === 3) {
|
|
@@ -826,7 +757,7 @@ function prepareInput(data, element, inputType = "insertText") {
|
|
|
826
757
|
}
|
|
827
758
|
}
|
|
828
759
|
if (del || data) {
|
|
829
|
-
|
|
760
|
+
dispatchUIEvent(config, element, "input", { inputType });
|
|
830
761
|
}
|
|
831
762
|
}
|
|
832
763
|
};
|
|
@@ -838,7 +769,7 @@ function prepareInput(data, element, inputType = "insertText") {
|
|
|
838
769
|
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
|
|
839
770
|
return;
|
|
840
771
|
}
|
|
841
|
-
editInputElement(element, {
|
|
772
|
+
editInputElement(config, element, {
|
|
842
773
|
newValue,
|
|
843
774
|
newSelection: {
|
|
844
775
|
node: element,
|
|
@@ -966,15 +897,30 @@ function readSelectedValueFromInput(target) {
|
|
|
966
897
|
return val.substring(sel.startOffset, sel.endOffset);
|
|
967
898
|
}
|
|
968
899
|
|
|
900
|
+
// src/utils/misc/findClosest.ts
|
|
901
|
+
function findClosest(element, callback) {
|
|
902
|
+
let el = element;
|
|
903
|
+
do {
|
|
904
|
+
if (callback(el)) {
|
|
905
|
+
return el;
|
|
906
|
+
}
|
|
907
|
+
el = el.parentElement;
|
|
908
|
+
} while (el && el !== element.ownerDocument.body);
|
|
909
|
+
return void 0;
|
|
910
|
+
}
|
|
911
|
+
|
|
969
912
|
// src/utils/focus/focus.ts
|
|
970
913
|
function focus(element) {
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
if (isAlreadyActive)
|
|
914
|
+
const target = findClosest(element, isFocusable);
|
|
915
|
+
const activeElement = getActiveElement(element.ownerDocument);
|
|
916
|
+
if ((target != null ? target : element.ownerDocument.body) === activeElement) {
|
|
975
917
|
return;
|
|
976
|
-
|
|
977
|
-
|
|
918
|
+
} else if (target) {
|
|
919
|
+
eventWrapper(() => target.focus());
|
|
920
|
+
} else {
|
|
921
|
+
eventWrapper(() => activeElement == null ? void 0 : activeElement.blur());
|
|
922
|
+
}
|
|
923
|
+
updateSelectionOnFocus(target != null ? target : element.ownerDocument.body);
|
|
978
924
|
}
|
|
979
925
|
|
|
980
926
|
// src/utils/misc/isVisible.ts
|
|
@@ -1071,6 +1017,14 @@ function isAllSelected(target) {
|
|
|
1071
1017
|
return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
1072
1018
|
}
|
|
1073
1019
|
|
|
1020
|
+
// src/utils/keyboard/getKeyEventProps.ts
|
|
1021
|
+
function getKeyEventProps(keyDef) {
|
|
1022
|
+
return {
|
|
1023
|
+
key: keyDef.key,
|
|
1024
|
+
code: keyDef.code
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1074
1028
|
// src/utils/keyboard/getUIEventModifiers.ts
|
|
1075
1029
|
function getUIEventModifiers(keyboardState) {
|
|
1076
1030
|
return {
|
|
@@ -1089,14 +1043,6 @@ function getUIEventModifiers(keyboardState) {
|
|
|
1089
1043
|
};
|
|
1090
1044
|
}
|
|
1091
1045
|
|
|
1092
|
-
// src/utils/keyboard/getKeyEventProps.ts
|
|
1093
|
-
function getKeyEventProps(keyDef, state) {
|
|
1094
|
-
return __spreadValues({
|
|
1095
|
-
key: keyDef.key,
|
|
1096
|
-
code: keyDef.code
|
|
1097
|
-
}, getUIEventModifiers(state));
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
1046
|
// src/utils/keyDef/readNextDescriptor.ts
|
|
1101
1047
|
var bracketDict = /* @__PURE__ */ ((bracketDict2) => {
|
|
1102
1048
|
bracketDict2["{"] = "}";
|
|
@@ -1175,16 +1121,9 @@ function getErrorMessage(expected, found, text) {
|
|
|
1175
1121
|
for more information about how userEvent parses your input.`;
|
|
1176
1122
|
}
|
|
1177
1123
|
|
|
1178
|
-
// src/utils/misc/
|
|
1179
|
-
function
|
|
1180
|
-
|
|
1181
|
-
do {
|
|
1182
|
-
if (callback(el)) {
|
|
1183
|
-
return el;
|
|
1184
|
-
}
|
|
1185
|
-
el = el.parentElement;
|
|
1186
|
-
} while (el && el !== element.ownerDocument.body);
|
|
1187
|
-
return void 0;
|
|
1124
|
+
// src/utils/misc/cloneEvent.ts
|
|
1125
|
+
function cloneEvent(event) {
|
|
1126
|
+
return new event.constructor(event.type, event);
|
|
1188
1127
|
}
|
|
1189
1128
|
|
|
1190
1129
|
// src/utils/misc/getDocumentFromNode.ts
|
|
@@ -1207,13 +1146,121 @@ function isDescendantOrSelf(potentialDescendant, potentialAncestor) {
|
|
|
1207
1146
|
return false;
|
|
1208
1147
|
}
|
|
1209
1148
|
|
|
1210
|
-
// src/utils/misc/
|
|
1149
|
+
// src/utils/misc/level.ts
|
|
1150
|
+
var Level = Symbol("Api level refs");
|
|
1151
|
+
function setLevelRef(config, level) {
|
|
1152
|
+
var _a;
|
|
1153
|
+
(_a = config[Level]) != null ? _a : config[Level] = {};
|
|
1154
|
+
config[Level][level] = {};
|
|
1155
|
+
}
|
|
1156
|
+
function getLevelRef(config, level) {
|
|
1157
|
+
var _a;
|
|
1158
|
+
return (_a = config[Level]) == null ? void 0 : _a[level];
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
// src/utils/misc/wait.ts
|
|
1211
1162
|
function wait(time) {
|
|
1212
1163
|
return new Promise((resolve) => setTimeout(() => resolve(), time));
|
|
1213
1164
|
}
|
|
1214
1165
|
|
|
1215
|
-
// src/utils/misc/
|
|
1166
|
+
// src/utils/misc/hasFormSubmit.ts
|
|
1167
|
+
var hasFormSubmit = (form) => !!(form == null ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]'));
|
|
1168
|
+
|
|
1169
|
+
// src/utils/pointer/cssPointerEvents.ts
|
|
1216
1170
|
import { getWindowFromNode as getWindowFromNode2 } from "@testing-library/dom/dist/helpers.js";
|
|
1171
|
+
|
|
1172
|
+
// src/keyboard/keyMap.ts
|
|
1173
|
+
var defaultKeyMap = [
|
|
1174
|
+
..."0123456789".split("").map((c) => ({ code: `Digit${c}`, key: c })),
|
|
1175
|
+
...")!@#$%^&*(".split("").map((c, i) => ({ code: `Digit${i}`, key: c, shiftKey: true })),
|
|
1176
|
+
..."abcdefghijklmnopqrstuvwxyz".split("").map((c) => ({ code: `Key${c.toUpperCase()}`, key: c })),
|
|
1177
|
+
..."ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("").map((c) => ({ code: `Key${c}`, key: c, shiftKey: true })),
|
|
1178
|
+
{ code: "Space", key: " " },
|
|
1179
|
+
{ code: "AltLeft", key: "Alt", location: 1 /* LEFT */ },
|
|
1180
|
+
{ code: "AltRight", key: "Alt", location: 2 /* RIGHT */ },
|
|
1181
|
+
{
|
|
1182
|
+
code: "ShiftLeft",
|
|
1183
|
+
key: "Shift",
|
|
1184
|
+
location: 1 /* LEFT */
|
|
1185
|
+
},
|
|
1186
|
+
{
|
|
1187
|
+
code: "ShiftRight",
|
|
1188
|
+
key: "Shift",
|
|
1189
|
+
location: 2 /* RIGHT */
|
|
1190
|
+
},
|
|
1191
|
+
{
|
|
1192
|
+
code: "ControlLeft",
|
|
1193
|
+
key: "Control",
|
|
1194
|
+
location: 1 /* LEFT */
|
|
1195
|
+
},
|
|
1196
|
+
{
|
|
1197
|
+
code: "ControlRight",
|
|
1198
|
+
key: "Control",
|
|
1199
|
+
location: 2 /* RIGHT */
|
|
1200
|
+
},
|
|
1201
|
+
{ code: "MetaLeft", key: "Meta", location: 1 /* LEFT */ },
|
|
1202
|
+
{
|
|
1203
|
+
code: "MetaRight",
|
|
1204
|
+
key: "Meta",
|
|
1205
|
+
location: 2 /* RIGHT */
|
|
1206
|
+
},
|
|
1207
|
+
{ code: "OSLeft", key: "OS", location: 1 /* LEFT */ },
|
|
1208
|
+
{ code: "OSRight", key: "OS", location: 2 /* RIGHT */ },
|
|
1209
|
+
{ code: "Tab", key: "Tab" },
|
|
1210
|
+
{ code: "CapsLock", key: "CapsLock" },
|
|
1211
|
+
{ code: "Backspace", key: "Backspace" },
|
|
1212
|
+
{ code: "Enter", key: "Enter" },
|
|
1213
|
+
{ code: "Escape", key: "Escape" },
|
|
1214
|
+
{ code: "ArrowUp", key: "ArrowUp" },
|
|
1215
|
+
{ code: "ArrowDown", key: "ArrowDown" },
|
|
1216
|
+
{ code: "ArrowLeft", key: "ArrowLeft" },
|
|
1217
|
+
{ code: "ArrowRight", key: "ArrowRight" },
|
|
1218
|
+
{ code: "Home", key: "Home" },
|
|
1219
|
+
{ code: "End", key: "End" },
|
|
1220
|
+
{ code: "Delete", key: "Delete" },
|
|
1221
|
+
{ code: "PageUp", key: "PageUp" },
|
|
1222
|
+
{ code: "PageDown", key: "PageDown" },
|
|
1223
|
+
{ code: "Fn", key: "Fn" },
|
|
1224
|
+
{ code: "Symbol", key: "Symbol" },
|
|
1225
|
+
{ code: "AltRight", key: "AltGraph" }
|
|
1226
|
+
];
|
|
1227
|
+
|
|
1228
|
+
// src/pointer/keyMap.ts
|
|
1229
|
+
var defaultKeyMap2 = [
|
|
1230
|
+
{ name: "MouseLeft", pointerType: "mouse", button: "primary" },
|
|
1231
|
+
{ name: "MouseRight", pointerType: "mouse", button: "secondary" },
|
|
1232
|
+
{ name: "MouseMiddle", pointerType: "mouse", button: "auxiliary" },
|
|
1233
|
+
{ name: "TouchA", pointerType: "touch" },
|
|
1234
|
+
{ name: "TouchB", pointerType: "touch" },
|
|
1235
|
+
{ name: "TouchC", pointerType: "touch" }
|
|
1236
|
+
];
|
|
1237
|
+
|
|
1238
|
+
// src/options.ts
|
|
1239
|
+
var PointerEventsCheckLevel = /* @__PURE__ */ ((PointerEventsCheckLevel2) => {
|
|
1240
|
+
PointerEventsCheckLevel2[PointerEventsCheckLevel2["EachTrigger"] = 4] = "EachTrigger";
|
|
1241
|
+
PointerEventsCheckLevel2[PointerEventsCheckLevel2["EachApiCall"] = 2] = "EachApiCall";
|
|
1242
|
+
PointerEventsCheckLevel2[PointerEventsCheckLevel2["EachTarget"] = 1] = "EachTarget";
|
|
1243
|
+
PointerEventsCheckLevel2[PointerEventsCheckLevel2["Never"] = 0] = "Never";
|
|
1244
|
+
return PointerEventsCheckLevel2;
|
|
1245
|
+
})(PointerEventsCheckLevel || {});
|
|
1246
|
+
var defaultOptionsDirect = {
|
|
1247
|
+
applyAccept: true,
|
|
1248
|
+
autoModify: true,
|
|
1249
|
+
delay: 0,
|
|
1250
|
+
document: global.document,
|
|
1251
|
+
keyboardMap: defaultKeyMap,
|
|
1252
|
+
pointerMap: defaultKeyMap2,
|
|
1253
|
+
pointerEventsCheck: 2 /* EachApiCall */,
|
|
1254
|
+
skipAutoClose: false,
|
|
1255
|
+
skipClick: false,
|
|
1256
|
+
skipHover: false,
|
|
1257
|
+
writeToClipboard: false
|
|
1258
|
+
};
|
|
1259
|
+
var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect), {
|
|
1260
|
+
writeToClipboard: true
|
|
1261
|
+
});
|
|
1262
|
+
|
|
1263
|
+
// src/utils/pointer/cssPointerEvents.ts
|
|
1217
1264
|
function hasPointerEvents(element) {
|
|
1218
1265
|
const window2 = getWindowFromNode2(element);
|
|
1219
1266
|
for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
@@ -1224,13 +1271,26 @@ function hasPointerEvents(element) {
|
|
|
1224
1271
|
}
|
|
1225
1272
|
return true;
|
|
1226
1273
|
}
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1274
|
+
var PointerEventsCheck = Symbol("Last check for pointer-events");
|
|
1275
|
+
function assertPointerEvents(config, element) {
|
|
1276
|
+
const lastCheck = element[PointerEventsCheck];
|
|
1277
|
+
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 */));
|
|
1278
|
+
if (!needsCheck) {
|
|
1279
|
+
return;
|
|
1280
|
+
}
|
|
1281
|
+
const result = hasPointerEvents(element);
|
|
1282
|
+
element[PointerEventsCheck] = {
|
|
1283
|
+
[1 /* Call */]: getLevelRef(config, 1 /* Call */),
|
|
1284
|
+
[2 /* Trigger */]: getLevelRef(config, 2 /* Trigger */),
|
|
1285
|
+
result
|
|
1286
|
+
};
|
|
1287
|
+
if (!result) {
|
|
1288
|
+
throw new Error('Unable to perform pointer interaction as the element has or inherits pointer-events set to "none".');
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
function hasBitFlag(conf, flag) {
|
|
1292
|
+
return (conf & flag) > 0;
|
|
1293
|
+
}
|
|
1234
1294
|
|
|
1235
1295
|
// src/utils/pointer/mouseButtons.ts
|
|
1236
1296
|
var MouseButton = {
|
|
@@ -1263,88 +1323,342 @@ function getMouseButtons(...buttons) {
|
|
|
1263
1323
|
return v;
|
|
1264
1324
|
}
|
|
1265
1325
|
|
|
1266
|
-
// src/
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
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);
|
|
1351
|
+
}
|
|
1352
|
+
return event;
|
|
1353
|
+
}
|
|
1354
|
+
function assignProps(obj, props) {
|
|
1355
|
+
for (const [key, value] of Object.entries(props)) {
|
|
1356
|
+
Object.defineProperty(obj, key, { get: () => value });
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
function assignPositionInit(obj, {
|
|
1360
|
+
x,
|
|
1361
|
+
y,
|
|
1362
|
+
clientX,
|
|
1363
|
+
clientY,
|
|
1364
|
+
offsetX,
|
|
1365
|
+
offsetY,
|
|
1366
|
+
pageX,
|
|
1367
|
+
pageY,
|
|
1368
|
+
screenX,
|
|
1369
|
+
screenY
|
|
1276
1370
|
}) {
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1371
|
+
var _a, _b, _c, _d;
|
|
1372
|
+
assignProps(obj, {
|
|
1373
|
+
x: (_a = x != null ? x : clientX) != null ? _a : 0,
|
|
1374
|
+
y: (_b = y != null ? y : clientY) != null ? _b : 0,
|
|
1375
|
+
clientX: (_c = x != null ? x : clientX) != null ? _c : 0,
|
|
1376
|
+
clientY: (_d = y != null ? y : clientY) != null ? _d : 0,
|
|
1377
|
+
offsetX: offsetX != null ? offsetX : 0,
|
|
1378
|
+
offsetY: offsetY != null ? offsetY : 0,
|
|
1379
|
+
pageX: pageX != null ? pageX : 0,
|
|
1380
|
+
pageY: pageY != null ? pageY : 0,
|
|
1381
|
+
screenX: screenX != null ? screenX : 0,
|
|
1382
|
+
screenY: screenY != null ? screenY : 0
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
function assignPointerInit(obj, { isPrimary, pointerId, pointerType }) {
|
|
1386
|
+
assignProps(obj, {
|
|
1387
|
+
isPrimary,
|
|
1388
|
+
pointerId,
|
|
1389
|
+
pointerType
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
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
|
+
};
|
|
1281
1413
|
}
|
|
1282
|
-
|
|
1283
|
-
|
|
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;
|
|
1284
1437
|
}
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
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
|
|
1289
1481
|
}));
|
|
1290
|
-
|
|
1291
|
-
|
|
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) {
|
|
1292
1527
|
}
|
|
1293
|
-
const eventKey = Object.keys(eventMap).find((k) => k.toLowerCase() === type3);
|
|
1294
|
-
const event = createEvent[eventKey](target, init);
|
|
1295
|
-
assignPositionInit(event, init);
|
|
1296
|
-
assignPointerInit(event, init);
|
|
1297
|
-
return fireEvent4(target, event);
|
|
1298
1528
|
}
|
|
1299
|
-
function
|
|
1300
|
-
|
|
1301
|
-
|
|
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);
|
|
1302
1607
|
}
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
pageY,
|
|
1313
|
-
screenX,
|
|
1314
|
-
screenY
|
|
1315
|
-
}) {
|
|
1316
|
-
var _a, _b, _c, _d;
|
|
1317
|
-
assignProps(obj, {
|
|
1318
|
-
x: (_a = x != null ? x : clientX) != null ? _a : 0,
|
|
1319
|
-
y: (_b = y != null ? y : clientY) != null ? _b : 0,
|
|
1320
|
-
clientX: (_c = x != null ? x : clientX) != null ? _c : 0,
|
|
1321
|
-
clientY: (_d = y != null ? y : clientY) != null ? _d : 0,
|
|
1322
|
-
offsetX: offsetX != null ? offsetX : 0,
|
|
1323
|
-
offsetY: offsetY != null ? offsetY : 0,
|
|
1324
|
-
pageX: pageX != null ? pageX : 0,
|
|
1325
|
-
pageY: pageY != null ? pageY : 0,
|
|
1326
|
-
screenX: screenX != null ? screenX : 0,
|
|
1327
|
-
screenY: screenY != null ? screenY : 0
|
|
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
|
|
1328
1617
|
});
|
|
1618
|
+
document2[isPrepared] = isPrepared;
|
|
1329
1619
|
}
|
|
1330
|
-
function
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
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;
|
|
1336
1632
|
}
|
|
1337
1633
|
|
|
1338
1634
|
// src/keyboard/plugins/arrow.ts
|
|
1339
1635
|
var keydownBehavior = [
|
|
1340
1636
|
{
|
|
1341
|
-
matches: (keyDef
|
|
1637
|
+
matches: (keyDef) => keyDef.key === "ArrowLeft" || keyDef.key === "ArrowRight",
|
|
1342
1638
|
handle: (keyDef, element) => {
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1639
|
+
if (hasOwnSelection(element)) {
|
|
1640
|
+
const selection = getUISelection(element);
|
|
1641
|
+
setSelection({
|
|
1642
|
+
focusNode: element,
|
|
1643
|
+
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + (keyDef.key === "ArrowLeft" ? -1 : 1) : keyDef.key === "ArrowLeft" ? selection.startOffset : selection.endOffset
|
|
1644
|
+
});
|
|
1645
|
+
} else {
|
|
1646
|
+
const selection = element.ownerDocument.getSelection();
|
|
1647
|
+
if (!selection) {
|
|
1648
|
+
return;
|
|
1649
|
+
}
|
|
1650
|
+
if (selection.isCollapsed) {
|
|
1651
|
+
const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, keyDef.key === "ArrowLeft" ? -1 : 1);
|
|
1652
|
+
if (nextPosition) {
|
|
1653
|
+
setSelection({
|
|
1654
|
+
focusNode: nextPosition.node,
|
|
1655
|
+
focusOffset: nextPosition.offset
|
|
1656
|
+
});
|
|
1657
|
+
}
|
|
1658
|
+
} else {
|
|
1659
|
+
selection[keyDef.key === "ArrowLeft" ? "collapseToStart" : "collapseToEnd"]();
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1348
1662
|
}
|
|
1349
1663
|
}
|
|
1350
1664
|
];
|
|
@@ -1377,21 +1691,18 @@ var keydownBehavior2 = [
|
|
|
1377
1691
|
},
|
|
1378
1692
|
{
|
|
1379
1693
|
matches: (keyDef, element) => keyDef.key === "Delete" && isEditable(element),
|
|
1380
|
-
handle: (keDef, element) => {
|
|
1694
|
+
handle: (keDef, element, config) => {
|
|
1381
1695
|
var _a;
|
|
1382
|
-
(_a = prepareInput("", element, "deleteContentForward")) == null ? void 0 : _a.commit();
|
|
1696
|
+
(_a = prepareInput(config, "", element, "deleteContentForward")) == null ? void 0 : _a.commit();
|
|
1383
1697
|
}
|
|
1384
1698
|
}
|
|
1385
1699
|
];
|
|
1386
1700
|
|
|
1387
|
-
// src/keyboard/plugins/character.ts
|
|
1388
|
-
import { fireEvent as fireEvent6 } from "@testing-library/dom";
|
|
1389
|
-
|
|
1390
1701
|
// src/keyboard/shared/fireChangeForInputTimeIfValid.ts
|
|
1391
|
-
|
|
1392
|
-
function fireChangeForInputTimeIfValid(el, prevValue, timeNewEntry) {
|
|
1702
|
+
function fireChangeForInputTimeIfValid(config, el, prevValue, timeNewEntry) {
|
|
1393
1703
|
if (isValidInputTimeValue(el, timeNewEntry) && prevValue !== timeNewEntry) {
|
|
1394
|
-
|
|
1704
|
+
setUIValue(el, timeNewEntry);
|
|
1705
|
+
dispatchUIEvent(config, el, "change");
|
|
1395
1706
|
}
|
|
1396
1707
|
}
|
|
1397
1708
|
|
|
@@ -1402,10 +1713,10 @@ var keypressBehavior = [
|
|
|
1402
1713
|
var _a;
|
|
1403
1714
|
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "time", readOnly: false });
|
|
1404
1715
|
},
|
|
1405
|
-
handle: (keyDef, element,
|
|
1716
|
+
handle: (keyDef, element, config) => {
|
|
1406
1717
|
var _a;
|
|
1407
1718
|
let newEntry = keyDef.key;
|
|
1408
|
-
const textToBeTyped = ((_a = keyboardState.carryValue) != null ? _a : "") + newEntry;
|
|
1719
|
+
const textToBeTyped = ((_a = config.keyboardState.carryValue) != null ? _a : "") + newEntry;
|
|
1409
1720
|
const timeNewEntry = buildTimeValue(textToBeTyped);
|
|
1410
1721
|
if (isValidInputTimeValue(element, timeNewEntry)) {
|
|
1411
1722
|
newEntry = timeNewEntry;
|
|
@@ -1413,7 +1724,7 @@ var keypressBehavior = [
|
|
|
1413
1724
|
const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
|
|
1414
1725
|
const prevValue = getValue(element);
|
|
1415
1726
|
if (prevValue !== newValue) {
|
|
1416
|
-
editInputElement(element, {
|
|
1727
|
+
editInputElement(config, element, {
|
|
1417
1728
|
newValue,
|
|
1418
1729
|
newSelection: {
|
|
1419
1730
|
node: element,
|
|
@@ -1425,8 +1736,8 @@ var keypressBehavior = [
|
|
|
1425
1736
|
}
|
|
1426
1737
|
});
|
|
1427
1738
|
}
|
|
1428
|
-
fireChangeForInputTimeIfValid(element, prevValue, timeNewEntry);
|
|
1429
|
-
keyboardState.carryValue = textToBeTyped;
|
|
1739
|
+
fireChangeForInputTimeIfValid(config, element, prevValue, timeNewEntry);
|
|
1740
|
+
config.keyboardState.carryValue = textToBeTyped;
|
|
1430
1741
|
}
|
|
1431
1742
|
},
|
|
1432
1743
|
{
|
|
@@ -1434,10 +1745,10 @@ var keypressBehavior = [
|
|
|
1434
1745
|
var _a;
|
|
1435
1746
|
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "date", readOnly: false });
|
|
1436
1747
|
},
|
|
1437
|
-
handle: (keyDef, element,
|
|
1748
|
+
handle: (keyDef, element, config) => {
|
|
1438
1749
|
var _a;
|
|
1439
1750
|
let newEntry = keyDef.key;
|
|
1440
|
-
const textToBeTyped = ((_a = keyboardState.carryValue) != null ? _a : "") + newEntry;
|
|
1751
|
+
const textToBeTyped = ((_a = config.keyboardState.carryValue) != null ? _a : "") + newEntry;
|
|
1441
1752
|
const isValidToBeTyped = isValidDateValue(element, textToBeTyped);
|
|
1442
1753
|
if (isValidToBeTyped) {
|
|
1443
1754
|
newEntry = textToBeTyped;
|
|
@@ -1445,7 +1756,7 @@ var keypressBehavior = [
|
|
|
1445
1756
|
const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
|
|
1446
1757
|
const prevValue = getValue(element);
|
|
1447
1758
|
if (prevValue !== newValue) {
|
|
1448
|
-
editInputElement(element, {
|
|
1759
|
+
editInputElement(config, element, {
|
|
1449
1760
|
newValue,
|
|
1450
1761
|
newSelection: {
|
|
1451
1762
|
node: element,
|
|
@@ -1458,11 +1769,10 @@ var keypressBehavior = [
|
|
|
1458
1769
|
});
|
|
1459
1770
|
}
|
|
1460
1771
|
if (isValidToBeTyped) {
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
});
|
|
1772
|
+
setUIValue(element, textToBeTyped);
|
|
1773
|
+
dispatchUIEvent(config, element, "change");
|
|
1464
1774
|
}
|
|
1465
|
-
keyboardState.carryValue = textToBeTyped;
|
|
1775
|
+
config.keyboardState.carryValue = textToBeTyped;
|
|
1466
1776
|
}
|
|
1467
1777
|
},
|
|
1468
1778
|
{
|
|
@@ -1470,12 +1780,12 @@ var keypressBehavior = [
|
|
|
1470
1780
|
var _a;
|
|
1471
1781
|
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "number", readOnly: false });
|
|
1472
1782
|
},
|
|
1473
|
-
handle: (keyDef, element) => {
|
|
1783
|
+
handle: (keyDef, element, config) => {
|
|
1474
1784
|
var _a, _b;
|
|
1475
1785
|
if (!/[\d.\-e]/.test(keyDef.key)) {
|
|
1476
1786
|
return;
|
|
1477
1787
|
}
|
|
1478
|
-
const { getNewValue, commit } = prepareInput(keyDef.key, element);
|
|
1788
|
+
const { getNewValue, commit } = prepareInput(config, keyDef.key, element);
|
|
1479
1789
|
const newValue = getNewValue();
|
|
1480
1790
|
const valueParts = newValue.split("e", 2);
|
|
1481
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])) {
|
|
@@ -1489,28 +1799,27 @@ var keypressBehavior = [
|
|
|
1489
1799
|
var _a;
|
|
1490
1800
|
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && (isEditableInput(element) || isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0;
|
|
1491
1801
|
},
|
|
1492
|
-
handle: (keyDef, element) => {
|
|
1802
|
+
handle: (keyDef, element, config) => {
|
|
1493
1803
|
var _a;
|
|
1494
|
-
(_a = prepareInput(keyDef.key, element)) == null ? void 0 : _a.commit();
|
|
1804
|
+
(_a = prepareInput(config, keyDef.key, element)) == null ? void 0 : _a.commit();
|
|
1495
1805
|
}
|
|
1496
1806
|
},
|
|
1497
1807
|
{
|
|
1498
1808
|
matches: (keyDef, element) => keyDef.key === "Enter" && (isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0,
|
|
1499
|
-
handle: (keyDef, element,
|
|
1809
|
+
handle: (keyDef, element, config) => {
|
|
1500
1810
|
var _a;
|
|
1501
|
-
(_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();
|
|
1502
1812
|
}
|
|
1503
1813
|
}
|
|
1504
1814
|
];
|
|
1505
1815
|
|
|
1506
1816
|
// src/keyboard/plugins/functional.ts
|
|
1507
|
-
import { fireEvent as fireEvent7 } from "@testing-library/dom";
|
|
1508
1817
|
var keydownBehavior3 = [
|
|
1509
1818
|
{
|
|
1510
1819
|
matches: (keyDef, element) => keyDef.key === "Backspace" && isEditable(element),
|
|
1511
|
-
handle: (keyDef, element) => {
|
|
1820
|
+
handle: (keyDef, element, config) => {
|
|
1512
1821
|
var _a;
|
|
1513
|
-
(_a = prepareInput("", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
|
|
1822
|
+
(_a = prepareInput(config, "", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
|
|
1514
1823
|
}
|
|
1515
1824
|
},
|
|
1516
1825
|
{
|
|
@@ -1534,25 +1843,25 @@ var keydownBehavior3 = [
|
|
|
1534
1843
|
var keypressBehavior2 = [
|
|
1535
1844
|
{
|
|
1536
1845
|
matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input") && ["checkbox", "radio"].includes(element.type),
|
|
1537
|
-
handle: (keyDef, element) => {
|
|
1846
|
+
handle: (keyDef, element, config) => {
|
|
1538
1847
|
const form = element.form;
|
|
1539
1848
|
if (hasFormSubmit(form)) {
|
|
1540
|
-
|
|
1849
|
+
dispatchUIEvent(config, form, "submit");
|
|
1541
1850
|
}
|
|
1542
1851
|
}
|
|
1543
1852
|
},
|
|
1544
1853
|
{
|
|
1545
1854
|
matches: (keyDef, element) => keyDef.key === "Enter" && (isClickableInput(element) || isElementType(element, "a") && Boolean(element.href)),
|
|
1546
|
-
handle: (keyDef, element,
|
|
1547
|
-
|
|
1855
|
+
handle: (keyDef, element, config) => {
|
|
1856
|
+
dispatchUIEvent(config, element, "click");
|
|
1548
1857
|
}
|
|
1549
1858
|
},
|
|
1550
1859
|
{
|
|
1551
1860
|
matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input"),
|
|
1552
|
-
handle: (keyDef, element) => {
|
|
1861
|
+
handle: (keyDef, element, config) => {
|
|
1553
1862
|
const form = element.form;
|
|
1554
1863
|
if (form && (form.querySelectorAll("input").length === 1 || hasFormSubmit(form))) {
|
|
1555
|
-
|
|
1864
|
+
dispatchUIEvent(config, form, "submit");
|
|
1556
1865
|
}
|
|
1557
1866
|
}
|
|
1558
1867
|
}
|
|
@@ -1560,8 +1869,8 @@ var keypressBehavior2 = [
|
|
|
1560
1869
|
var keyupBehavior = [
|
|
1561
1870
|
{
|
|
1562
1871
|
matches: (keyDef, element) => keyDef.key === " " && isClickableInput(element),
|
|
1563
|
-
handle: (keyDef, element,
|
|
1564
|
-
|
|
1872
|
+
handle: (keyDef, element, config) => {
|
|
1873
|
+
dispatchUIEvent(config, element, "click");
|
|
1565
1874
|
}
|
|
1566
1875
|
}
|
|
1567
1876
|
];
|
|
@@ -1575,7 +1884,6 @@ var keydownBehavior4 = [
|
|
|
1575
1884
|
];
|
|
1576
1885
|
|
|
1577
1886
|
// src/keyboard/plugins/modifiers.ts
|
|
1578
|
-
import { fireEvent as fireEvent8 } from "@testing-library/dom";
|
|
1579
1887
|
var modifierKeys = [
|
|
1580
1888
|
"Alt",
|
|
1581
1889
|
"AltGraph",
|
|
@@ -1595,12 +1903,12 @@ var modifierLocks = [
|
|
|
1595
1903
|
var preKeydownBehavior = [
|
|
1596
1904
|
{
|
|
1597
1905
|
matches: (keyDef) => modifierKeys.includes(keyDef.key),
|
|
1598
|
-
handle: (keyDef, element,
|
|
1906
|
+
handle: (keyDef, element, config) => {
|
|
1599
1907
|
var _a;
|
|
1600
|
-
keyboardState.modifiers[keyDef.key] = true;
|
|
1908
|
+
config.keyboardState.modifiers[keyDef.key] = true;
|
|
1601
1909
|
if (keyDef.key === "AltGraph") {
|
|
1602
|
-
const ctrlKeyDef = (_a = keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1603
|
-
|
|
1910
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1911
|
+
dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
|
|
1604
1912
|
}
|
|
1605
1913
|
}
|
|
1606
1914
|
},
|
|
@@ -1635,10 +1943,10 @@ var preKeyupBehavior = [
|
|
|
1635
1943
|
var postKeyupBehavior = [
|
|
1636
1944
|
{
|
|
1637
1945
|
matches: (keyDef) => keyDef.key === "AltGraph",
|
|
1638
|
-
handle: (keyDef, element,
|
|
1946
|
+
handle: (keyDef, element, config) => {
|
|
1639
1947
|
var _a;
|
|
1640
|
-
const ctrlKeyDef = (_a = keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1641
|
-
|
|
1948
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1949
|
+
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1642
1950
|
}
|
|
1643
1951
|
}
|
|
1644
1952
|
];
|
|
@@ -1722,7 +2030,7 @@ function keydown(keyDef, getCurrentElement, config) {
|
|
|
1722
2030
|
}
|
|
1723
2031
|
config.keyboardState.activeElement = element;
|
|
1724
2032
|
applyPlugins(preKeydownBehavior2, keyDef, element, config);
|
|
1725
|
-
const unpreventedDefault =
|
|
2033
|
+
const unpreventedDefault = dispatchUIEvent(config, element, "keydown", getKeyEventProps(keyDef));
|
|
1726
2034
|
config.keyboardState.pressed.push({ keyDef, unpreventedDefault });
|
|
1727
2035
|
if (unpreventedDefault) {
|
|
1728
2036
|
applyPlugins(keydownBehavior5, keyDef, getCurrentElement(), config);
|
|
@@ -1733,7 +2041,7 @@ function keydown(keyDef, getCurrentElement, config) {
|
|
|
1733
2041
|
function keypress(keyDef, getCurrentElement, config) {
|
|
1734
2042
|
return __async(this, null, function* () {
|
|
1735
2043
|
const element = getCurrentElement();
|
|
1736
|
-
const unpreventedDefault =
|
|
2044
|
+
const unpreventedDefault = dispatchUIEvent(config, element, "keypress", __spreadProps(__spreadValues({}, getKeyEventProps(keyDef)), {
|
|
1737
2045
|
charCode: keyDef.key === "Enter" ? 13 : String(keyDef.key).charCodeAt(0)
|
|
1738
2046
|
}));
|
|
1739
2047
|
if (unpreventedDefault) {
|
|
@@ -1745,7 +2053,7 @@ function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
|
1745
2053
|
return __async(this, null, function* () {
|
|
1746
2054
|
const element = getCurrentElement();
|
|
1747
2055
|
applyPlugins(preKeyupBehavior2, keyDef, element, config);
|
|
1748
|
-
const unpreventedDefault =
|
|
2056
|
+
const unpreventedDefault = dispatchUIEvent(config, element, "keyup", getKeyEventProps(keyDef));
|
|
1749
2057
|
if (unprevented && unpreventedDefault) {
|
|
1750
2058
|
applyPlugins(keyupBehavior2, keyDef, getCurrentElement(), config);
|
|
1751
2059
|
}
|
|
@@ -1800,8 +2108,7 @@ function parseKeyDef(keyboardMap, text) {
|
|
|
1800
2108
|
// src/keyboard/index.ts
|
|
1801
2109
|
function keyboard(text) {
|
|
1802
2110
|
return __async(this, null, function* () {
|
|
1803
|
-
const
|
|
1804
|
-
const actions = parseKeyDef(keyboardMap, text);
|
|
2111
|
+
const actions = parseKeyDef(this[Config].keyboardMap, text);
|
|
1805
2112
|
return keyboardAction(this[Config], actions);
|
|
1806
2113
|
});
|
|
1807
2114
|
}
|
|
@@ -1847,6 +2154,34 @@ function parseKeyDef2(pointerMap, keys) {
|
|
|
1847
2154
|
return defs;
|
|
1848
2155
|
}
|
|
1849
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
|
+
|
|
1850
2185
|
// src/pointer/resolveSelectionTarget.ts
|
|
1851
2186
|
function resolveSelectionTarget({
|
|
1852
2187
|
target,
|
|
@@ -1893,7 +2228,8 @@ function findNodeAtTextOffset(node, offset, isRoot = true) {
|
|
|
1893
2228
|
|
|
1894
2229
|
// src/pointer/pointerMove.ts
|
|
1895
2230
|
function pointerMove(_0, _1) {
|
|
1896
|
-
return __async(this, arguments, function* ({ pointerName = "mouse", target, coords, node, offset }
|
|
2231
|
+
return __async(this, arguments, function* (config, { pointerName = "mouse", target, coords, node, offset }) {
|
|
2232
|
+
const { pointerState } = config;
|
|
1897
2233
|
if (!(pointerName in pointerState.position)) {
|
|
1898
2234
|
throw new Error(`Trying to move pointer "${pointerName}" which does not exist.`);
|
|
1899
2235
|
}
|
|
@@ -1905,11 +2241,15 @@ function pointerMove(_0, _1) {
|
|
|
1905
2241
|
selectionRange
|
|
1906
2242
|
} = pointerState.position[pointerName];
|
|
1907
2243
|
if (prevTarget && prevTarget !== target) {
|
|
2244
|
+
setLevelRef(config, 2 /* Trigger */);
|
|
2245
|
+
assertPointerEvents(config, prevTarget);
|
|
1908
2246
|
fireMove(prevTarget, prevCoords);
|
|
1909
2247
|
if (!isDescendantOrSelf(target, prevTarget)) {
|
|
1910
2248
|
fireLeave(prevTarget, prevCoords);
|
|
1911
2249
|
}
|
|
1912
2250
|
}
|
|
2251
|
+
setLevelRef(config, 2 /* Trigger */);
|
|
2252
|
+
assertPointerEvents(config, target);
|
|
1913
2253
|
pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
|
|
1914
2254
|
target,
|
|
1915
2255
|
coords
|
|
@@ -1964,9 +2304,7 @@ function pointerMove(_0, _1) {
|
|
|
1964
2304
|
}
|
|
1965
2305
|
}
|
|
1966
2306
|
function fire(eventTarget, type3, eventCoords) {
|
|
1967
|
-
return firePointerEvent(eventTarget, type3, {
|
|
1968
|
-
pointerState,
|
|
1969
|
-
keyboardState,
|
|
2307
|
+
return firePointerEvent(config, eventTarget, type3, {
|
|
1970
2308
|
coords: eventCoords,
|
|
1971
2309
|
pointerId,
|
|
1972
2310
|
pointerType
|
|
@@ -1976,19 +2314,19 @@ function pointerMove(_0, _1) {
|
|
|
1976
2314
|
}
|
|
1977
2315
|
|
|
1978
2316
|
// src/pointer/pointerPress.ts
|
|
1979
|
-
function pointerPress(
|
|
2317
|
+
function pointerPress(config, action) {
|
|
1980
2318
|
return __async(this, null, function* () {
|
|
1981
2319
|
const { keyDef, target, releasePrevious, releaseSelf } = action;
|
|
1982
|
-
const previous =
|
|
2320
|
+
const previous = config.pointerState.pressed.find((p) => p.keyDef === keyDef);
|
|
1983
2321
|
const pointerName = keyDef.pointerType === "touch" ? keyDef.name : keyDef.pointerType;
|
|
1984
2322
|
const targetIsDisabled = isDisabled(target);
|
|
1985
2323
|
if (previous) {
|
|
1986
|
-
up(
|
|
2324
|
+
up(config, pointerName, action, previous, targetIsDisabled);
|
|
1987
2325
|
}
|
|
1988
2326
|
if (!releasePrevious) {
|
|
1989
|
-
const press = down(
|
|
2327
|
+
const press = down(config, pointerName, action, targetIsDisabled);
|
|
1990
2328
|
if (releaseSelf) {
|
|
1991
|
-
up(
|
|
2329
|
+
up(config, pointerName, action, press, targetIsDisabled);
|
|
1992
2330
|
}
|
|
1993
2331
|
}
|
|
1994
2332
|
});
|
|
@@ -1997,8 +2335,11 @@ function getNextPointerId(state) {
|
|
|
1997
2335
|
state.pointerId = state.pointerId + 1;
|
|
1998
2336
|
return state.pointerId;
|
|
1999
2337
|
}
|
|
2000
|
-
function down(
|
|
2338
|
+
function down(config, pointerName, { keyDef, node, offset, target, coords }, targetIsDisabled) {
|
|
2001
2339
|
var _a, _b, _c;
|
|
2340
|
+
setLevelRef(config, 2 /* Trigger */);
|
|
2341
|
+
assertPointerEvents(config, target);
|
|
2342
|
+
const { pointerState } = config;
|
|
2002
2343
|
const { name, pointerType, button } = keyDef;
|
|
2003
2344
|
const pointerId = pointerType === "mouse" ? 1 : getNextPointerId(pointerState);
|
|
2004
2345
|
pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
|
|
@@ -2033,36 +2374,34 @@ function down({ pointerState, keyboardState }, pointerName, { keyDef, node, offs
|
|
|
2033
2374
|
clickCount
|
|
2034
2375
|
};
|
|
2035
2376
|
pointerState.pressed.push(pressObj);
|
|
2036
|
-
if (
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2377
|
+
if (pointerType !== "mouse") {
|
|
2378
|
+
fire("pointerover");
|
|
2379
|
+
fire("pointerenter");
|
|
2380
|
+
}
|
|
2381
|
+
if (pointerType !== "mouse" || !pointerState.pressed.some((p) => p.keyDef !== keyDef && p.keyDef.pointerType === pointerType)) {
|
|
2382
|
+
fire("pointerdown");
|
|
2383
|
+
}
|
|
2384
|
+
if (pointerType === "mouse") {
|
|
2385
|
+
if (!targetIsDisabled) {
|
|
2386
|
+
pressObj.unpreventedDefault = fire("mousedown");
|
|
2040
2387
|
}
|
|
2041
|
-
if (
|
|
2042
|
-
|
|
2388
|
+
if (pressObj.unpreventedDefault) {
|
|
2389
|
+
mousedownDefaultBehavior({
|
|
2390
|
+
target,
|
|
2391
|
+
targetIsDisabled,
|
|
2392
|
+
clickCount,
|
|
2393
|
+
position: pointerState.position[pointerName],
|
|
2394
|
+
node,
|
|
2395
|
+
offset
|
|
2396
|
+
});
|
|
2043
2397
|
}
|
|
2044
|
-
if (
|
|
2045
|
-
|
|
2398
|
+
if (button === "secondary") {
|
|
2399
|
+
fire("contextmenu");
|
|
2046
2400
|
}
|
|
2047
2401
|
}
|
|
2048
|
-
if (pointerType === "mouse" && pressObj.unpreventedDefault) {
|
|
2049
|
-
mousedownDefaultBehavior({
|
|
2050
|
-
target,
|
|
2051
|
-
targetIsDisabled,
|
|
2052
|
-
clickCount,
|
|
2053
|
-
position: pointerState.position[pointerName],
|
|
2054
|
-
node,
|
|
2055
|
-
offset
|
|
2056
|
-
});
|
|
2057
|
-
}
|
|
2058
|
-
if (pointerType === "mouse" && button === "secondary") {
|
|
2059
|
-
fire("contextmenu");
|
|
2060
|
-
}
|
|
2061
2402
|
return pressObj;
|
|
2062
2403
|
function fire(type3) {
|
|
2063
|
-
return firePointerEvent(target, type3, {
|
|
2064
|
-
pointerState,
|
|
2065
|
-
keyboardState,
|
|
2404
|
+
return firePointerEvent(config, target, type3, {
|
|
2066
2405
|
button,
|
|
2067
2406
|
clickCount,
|
|
2068
2407
|
coords,
|
|
@@ -2072,14 +2411,16 @@ function down({ pointerState, keyboardState }, pointerName, { keyDef, node, offs
|
|
|
2072
2411
|
});
|
|
2073
2412
|
}
|
|
2074
2413
|
}
|
|
2075
|
-
function up(
|
|
2414
|
+
function up(config, pointerName, {
|
|
2076
2415
|
keyDef: { pointerType, button },
|
|
2077
2416
|
target,
|
|
2078
2417
|
coords,
|
|
2079
2418
|
node,
|
|
2080
2419
|
offset
|
|
2081
2420
|
}, pressed, targetIsDisabled) {
|
|
2082
|
-
|
|
2421
|
+
setLevelRef(config, 2 /* Trigger */);
|
|
2422
|
+
assertPointerEvents(config, target);
|
|
2423
|
+
const { pointerState } = config;
|
|
2083
2424
|
pointerState.pressed = pointerState.pressed.filter((p) => p !== pressed);
|
|
2084
2425
|
const { isMultiTouch, isPrimary, pointerId, clickCount } = pressed;
|
|
2085
2426
|
let { unpreventedDefault } = pressed;
|
|
@@ -2087,15 +2428,15 @@ function up({ pointerState, keyboardState }, pointerName, {
|
|
|
2087
2428
|
target,
|
|
2088
2429
|
coords
|
|
2089
2430
|
});
|
|
2090
|
-
if (!
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
if (
|
|
2431
|
+
if (pointerType !== "mouse" || !pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).length) {
|
|
2432
|
+
fire("pointerup");
|
|
2433
|
+
}
|
|
2434
|
+
if (pointerType !== "mouse") {
|
|
2435
|
+
fire("pointerout");
|
|
2436
|
+
fire("pointerleave");
|
|
2437
|
+
}
|
|
2438
|
+
if (pointerType !== "mouse" && !isMultiTouch) {
|
|
2439
|
+
if (!targetIsDisabled) {
|
|
2099
2440
|
if (clickCount === 1) {
|
|
2100
2441
|
fire("mouseover");
|
|
2101
2442
|
fire("mouseenter");
|
|
@@ -2103,16 +2444,16 @@ function up({ pointerState, keyboardState }, pointerName, {
|
|
|
2103
2444
|
fire("mousemove");
|
|
2104
2445
|
unpreventedDefault = fire("mousedown") && unpreventedDefault;
|
|
2105
2446
|
}
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
}
|
|
2447
|
+
if (unpreventedDefault) {
|
|
2448
|
+
mousedownDefaultBehavior({
|
|
2449
|
+
target,
|
|
2450
|
+
targetIsDisabled,
|
|
2451
|
+
clickCount,
|
|
2452
|
+
position: pointerState.position[pointerName],
|
|
2453
|
+
node,
|
|
2454
|
+
offset
|
|
2455
|
+
});
|
|
2456
|
+
}
|
|
2116
2457
|
}
|
|
2117
2458
|
delete pointerState.position[pointerName].selectionRange;
|
|
2118
2459
|
if (!targetIsDisabled) {
|
|
@@ -2120,21 +2461,15 @@ function up({ pointerState, keyboardState }, pointerName, {
|
|
|
2120
2461
|
unpreventedDefault = fire("mouseup") && unpreventedDefault;
|
|
2121
2462
|
const canClick = pointerType !== "mouse" || button === "primary";
|
|
2122
2463
|
if (canClick && target === pressed.downTarget) {
|
|
2123
|
-
|
|
2464
|
+
fire("click");
|
|
2124
2465
|
if (clickCount === 2) {
|
|
2125
2466
|
fire("dblclick");
|
|
2126
2467
|
}
|
|
2127
|
-
const control = (_a = target.closest("label")) == null ? void 0 : _a.control;
|
|
2128
|
-
if (unpreventedClick && control && isFocusable(control)) {
|
|
2129
|
-
focus(control);
|
|
2130
|
-
}
|
|
2131
2468
|
}
|
|
2132
2469
|
}
|
|
2133
2470
|
}
|
|
2134
2471
|
function fire(type3) {
|
|
2135
|
-
return firePointerEvent(target, type3, {
|
|
2136
|
-
pointerState,
|
|
2137
|
-
keyboardState,
|
|
2472
|
+
return firePointerEvent(config, target, type3, {
|
|
2138
2473
|
button,
|
|
2139
2474
|
clickCount,
|
|
2140
2475
|
coords,
|
|
@@ -2152,8 +2487,7 @@ function mousedownDefaultBehavior({
|
|
|
2152
2487
|
node,
|
|
2153
2488
|
offset
|
|
2154
2489
|
}) {
|
|
2155
|
-
|
|
2156
|
-
focus((_a = findClosest(target, isFocusable)) != null ? _a : target.ownerDocument.body);
|
|
2490
|
+
focus(target);
|
|
2157
2491
|
if (!targetIsDisabled) {
|
|
2158
2492
|
const hasValue = isElementType(target, ["input", "textarea"]);
|
|
2159
2493
|
const text = String(hasValue ? getUIValue(target) : target.textContent);
|
|
@@ -2215,7 +2549,7 @@ function pointerAction(config, actions) {
|
|
|
2215
2549
|
const pointerName = "pointerName" in action && action.pointerName ? action.pointerName : "keyDef" in action ? action.keyDef.pointerType === "touch" ? action.keyDef.name : action.keyDef.pointerType : "mouse";
|
|
2216
2550
|
const target = (_a = action.target) != null ? _a : getPrevTarget(pointerName, config.pointerState);
|
|
2217
2551
|
const coords = (_b = action.coords) != null ? _b : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : void 0;
|
|
2218
|
-
yield "keyDef" in action ? pointerPress(__spreadProps(__spreadValues({}, action), { target, coords })
|
|
2552
|
+
yield "keyDef" in action ? pointerPress(config, __spreadProps(__spreadValues({}, action), { target, coords })) : pointerMove(config, __spreadProps(__spreadValues({}, action), { target, coords }));
|
|
2219
2553
|
if (typeof config.delay === "number") {
|
|
2220
2554
|
if (i < actions.length - 1) {
|
|
2221
2555
|
yield wait(config.delay);
|
|
@@ -2273,90 +2607,6 @@ function createPointerState(document2) {
|
|
|
2273
2607
|
};
|
|
2274
2608
|
}
|
|
2275
2609
|
|
|
2276
|
-
// src/keyboard/keyMap.ts
|
|
2277
|
-
var defaultKeyMap = [
|
|
2278
|
-
..."0123456789".split("").map((c) => ({ code: `Digit${c}`, key: c })),
|
|
2279
|
-
...")!@#$%^&*(".split("").map((c, i) => ({ code: `Digit${i}`, key: c, shiftKey: true })),
|
|
2280
|
-
..."abcdefghijklmnopqrstuvwxyz".split("").map((c) => ({ code: `Key${c.toUpperCase()}`, key: c })),
|
|
2281
|
-
..."ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("").map((c) => ({ code: `Key${c}`, key: c, shiftKey: true })),
|
|
2282
|
-
{ code: "Space", key: " " },
|
|
2283
|
-
{ code: "AltLeft", key: "Alt", location: 1 /* LEFT */ },
|
|
2284
|
-
{ code: "AltRight", key: "Alt", location: 2 /* RIGHT */ },
|
|
2285
|
-
{
|
|
2286
|
-
code: "ShiftLeft",
|
|
2287
|
-
key: "Shift",
|
|
2288
|
-
location: 1 /* LEFT */
|
|
2289
|
-
},
|
|
2290
|
-
{
|
|
2291
|
-
code: "ShiftRight",
|
|
2292
|
-
key: "Shift",
|
|
2293
|
-
location: 2 /* RIGHT */
|
|
2294
|
-
},
|
|
2295
|
-
{
|
|
2296
|
-
code: "ControlLeft",
|
|
2297
|
-
key: "Control",
|
|
2298
|
-
location: 1 /* LEFT */
|
|
2299
|
-
},
|
|
2300
|
-
{
|
|
2301
|
-
code: "ControlRight",
|
|
2302
|
-
key: "Control",
|
|
2303
|
-
location: 2 /* RIGHT */
|
|
2304
|
-
},
|
|
2305
|
-
{ code: "MetaLeft", key: "Meta", location: 1 /* LEFT */ },
|
|
2306
|
-
{
|
|
2307
|
-
code: "MetaRight",
|
|
2308
|
-
key: "Meta",
|
|
2309
|
-
location: 2 /* RIGHT */
|
|
2310
|
-
},
|
|
2311
|
-
{ code: "OSLeft", key: "OS", location: 1 /* LEFT */ },
|
|
2312
|
-
{ code: "OSRight", key: "OS", location: 2 /* RIGHT */ },
|
|
2313
|
-
{ code: "Tab", key: "Tab" },
|
|
2314
|
-
{ code: "CapsLock", key: "CapsLock" },
|
|
2315
|
-
{ code: "Backspace", key: "Backspace" },
|
|
2316
|
-
{ code: "Enter", key: "Enter" },
|
|
2317
|
-
{ code: "Escape", key: "Escape" },
|
|
2318
|
-
{ code: "ArrowUp", key: "ArrowUp" },
|
|
2319
|
-
{ code: "ArrowDown", key: "ArrowDown" },
|
|
2320
|
-
{ code: "ArrowLeft", key: "ArrowLeft" },
|
|
2321
|
-
{ code: "ArrowRight", key: "ArrowRight" },
|
|
2322
|
-
{ code: "Home", key: "Home" },
|
|
2323
|
-
{ code: "End", key: "End" },
|
|
2324
|
-
{ code: "Delete", key: "Delete" },
|
|
2325
|
-
{ code: "PageUp", key: "PageUp" },
|
|
2326
|
-
{ code: "PageDown", key: "PageDown" },
|
|
2327
|
-
{ code: "Fn", key: "Fn" },
|
|
2328
|
-
{ code: "Symbol", key: "Symbol" },
|
|
2329
|
-
{ code: "AltRight", key: "AltGraph" }
|
|
2330
|
-
];
|
|
2331
|
-
|
|
2332
|
-
// src/pointer/keyMap.ts
|
|
2333
|
-
var defaultKeyMap2 = [
|
|
2334
|
-
{ name: "MouseLeft", pointerType: "mouse", button: "primary" },
|
|
2335
|
-
{ name: "MouseRight", pointerType: "mouse", button: "secondary" },
|
|
2336
|
-
{ name: "MouseMiddle", pointerType: "mouse", button: "auxiliary" },
|
|
2337
|
-
{ name: "TouchA", pointerType: "touch" },
|
|
2338
|
-
{ name: "TouchB", pointerType: "touch" },
|
|
2339
|
-
{ name: "TouchC", pointerType: "touch" }
|
|
2340
|
-
];
|
|
2341
|
-
|
|
2342
|
-
// src/options.ts
|
|
2343
|
-
var defaultOptionsDirect = {
|
|
2344
|
-
applyAccept: true,
|
|
2345
|
-
autoModify: true,
|
|
2346
|
-
delay: 0,
|
|
2347
|
-
document: global.document,
|
|
2348
|
-
keyboardMap: defaultKeyMap,
|
|
2349
|
-
pointerMap: defaultKeyMap2,
|
|
2350
|
-
skipAutoClose: false,
|
|
2351
|
-
skipClick: false,
|
|
2352
|
-
skipHover: false,
|
|
2353
|
-
skipPointerEventsCheck: false,
|
|
2354
|
-
writeToClipboard: false
|
|
2355
|
-
};
|
|
2356
|
-
var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect), {
|
|
2357
|
-
writeToClipboard: true
|
|
2358
|
-
});
|
|
2359
|
-
|
|
2360
2610
|
// src/setup/config.ts
|
|
2361
2611
|
var Config = Symbol("Config");
|
|
2362
2612
|
|
|
@@ -2384,9 +2634,6 @@ __export(api_exports, {
|
|
|
2384
2634
|
// src/convenience/click.ts
|
|
2385
2635
|
function click(element) {
|
|
2386
2636
|
return __async(this, null, function* () {
|
|
2387
|
-
if (!this[Config].skipPointerEventsCheck && !hasPointerEvents(element)) {
|
|
2388
|
-
throw new Error('unable to click element as it has or inherits pointer-events set to "none".');
|
|
2389
|
-
}
|
|
2390
2637
|
const pointerIn = [];
|
|
2391
2638
|
if (!this[Config].skipHover) {
|
|
2392
2639
|
pointerIn.push({ target: element });
|
|
@@ -2397,17 +2644,11 @@ function click(element) {
|
|
|
2397
2644
|
}
|
|
2398
2645
|
function dblClick(element) {
|
|
2399
2646
|
return __async(this, null, function* () {
|
|
2400
|
-
if (!this[Config].skipPointerEventsCheck && !hasPointerEvents(element)) {
|
|
2401
|
-
throw new Error('unable to double-click element as it has or inherits pointer-events set to "none".');
|
|
2402
|
-
}
|
|
2403
2647
|
return this.pointer([{ target: element }, "[MouseLeft][MouseLeft]"]);
|
|
2404
2648
|
});
|
|
2405
2649
|
}
|
|
2406
2650
|
function tripleClick(element) {
|
|
2407
2651
|
return __async(this, null, function* () {
|
|
2408
|
-
if (!this[Config].skipPointerEventsCheck && !hasPointerEvents(element)) {
|
|
2409
|
-
throw new Error('unable to triple-click element as it has or inherits pointer-events set to "none".');
|
|
2410
|
-
}
|
|
2411
2652
|
return this.pointer([{ target: element }, "[MouseLeft][MouseLeft][MouseLeft]"]);
|
|
2412
2653
|
});
|
|
2413
2654
|
}
|
|
@@ -2415,17 +2656,11 @@ function tripleClick(element) {
|
|
|
2415
2656
|
// src/convenience/hover.ts
|
|
2416
2657
|
function hover(element) {
|
|
2417
2658
|
return __async(this, null, function* () {
|
|
2418
|
-
if (!this[Config].skipPointerEventsCheck && !hasPointerEvents(element)) {
|
|
2419
|
-
throw new Error('unable to hover element as it has or inherits pointer-events set to "none".');
|
|
2420
|
-
}
|
|
2421
2659
|
return this.pointer({ target: element });
|
|
2422
2660
|
});
|
|
2423
2661
|
}
|
|
2424
2662
|
function unhover(element) {
|
|
2425
2663
|
return __async(this, null, function* () {
|
|
2426
|
-
if (!this[Config].skipPointerEventsCheck && !hasPointerEvents(element)) {
|
|
2427
|
-
throw new Error('unable to unhover element as it has or inherits pointer-events set to "none".');
|
|
2428
|
-
}
|
|
2429
2664
|
return this.pointer({ target: element.ownerDocument.body });
|
|
2430
2665
|
});
|
|
2431
2666
|
}
|
|
@@ -2440,7 +2675,6 @@ function tab() {
|
|
|
2440
2675
|
}
|
|
2441
2676
|
|
|
2442
2677
|
// src/clipboard/copy.ts
|
|
2443
|
-
import { fireEvent as fireEvent10 } from "@testing-library/dom";
|
|
2444
2678
|
function copy() {
|
|
2445
2679
|
return __async(this, null, function* () {
|
|
2446
2680
|
var _a;
|
|
@@ -2450,7 +2684,7 @@ function copy() {
|
|
|
2450
2684
|
if (clipboardData.items.length === 0) {
|
|
2451
2685
|
return;
|
|
2452
2686
|
}
|
|
2453
|
-
|
|
2687
|
+
this.dispatchUIEvent(target, "copy", {
|
|
2454
2688
|
clipboardData
|
|
2455
2689
|
});
|
|
2456
2690
|
if (this[Config].writeToClipboard) {
|
|
@@ -2461,7 +2695,6 @@ function copy() {
|
|
|
2461
2695
|
}
|
|
2462
2696
|
|
|
2463
2697
|
// src/clipboard/cut.ts
|
|
2464
|
-
import { fireEvent as fireEvent11 } from "@testing-library/dom";
|
|
2465
2698
|
function cut() {
|
|
2466
2699
|
return __async(this, null, function* () {
|
|
2467
2700
|
var _a, _b;
|
|
@@ -2471,11 +2704,11 @@ function cut() {
|
|
|
2471
2704
|
if (clipboardData.items.length === 0) {
|
|
2472
2705
|
return;
|
|
2473
2706
|
}
|
|
2474
|
-
|
|
2707
|
+
this.dispatchUIEvent(target, "cut", {
|
|
2475
2708
|
clipboardData
|
|
2476
2709
|
});
|
|
2477
2710
|
if (isEditable(target)) {
|
|
2478
|
-
(_b = prepareInput("", target, "deleteByCut")) == null ? void 0 : _b.commit();
|
|
2711
|
+
(_b = prepareInput(this[Config], "", target, "deleteByCut")) == null ? void 0 : _b.commit();
|
|
2479
2712
|
}
|
|
2480
2713
|
if (this[Config].writeToClipboard) {
|
|
2481
2714
|
yield writeDataTransferToClipboard(doc, clipboardData);
|
|
@@ -2485,29 +2718,24 @@ function cut() {
|
|
|
2485
2718
|
}
|
|
2486
2719
|
|
|
2487
2720
|
// src/clipboard/paste.ts
|
|
2488
|
-
import { fireEvent as fireEvent12 } from "@testing-library/dom";
|
|
2489
2721
|
function paste(clipboardData) {
|
|
2490
2722
|
return __async(this, null, function* () {
|
|
2491
|
-
var _a, _b;
|
|
2723
|
+
var _a, _b, _c;
|
|
2492
2724
|
const doc = this[Config].document;
|
|
2493
2725
|
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2494
|
-
const
|
|
2726
|
+
const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _b : yield readDataTransferFromClipboard(doc).catch(() => {
|
|
2495
2727
|
throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
|
|
2496
2728
|
});
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
}
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
if (isEditable(target)) {
|
|
2506
|
-
const data = clipboardData.getData("text").substr(0, getSpaceUntilMaxLength(target));
|
|
2507
|
-
if (data) {
|
|
2508
|
-
(_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
|
+
}
|
|
2509
2737
|
}
|
|
2510
|
-
}
|
|
2738
|
+
});
|
|
2511
2739
|
}
|
|
2512
2740
|
function getClipboardDataFromString(text) {
|
|
2513
2741
|
const dt = createDataTransfer();
|
|
@@ -2530,12 +2758,12 @@ function clear(element) {
|
|
|
2530
2758
|
if (!isAllSelected(element)) {
|
|
2531
2759
|
throw new Error("The element content to be cleared could not be selected.");
|
|
2532
2760
|
}
|
|
2533
|
-
(_a = prepareInput("", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
|
|
2761
|
+
(_a = prepareInput(this[Config], "", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
|
|
2534
2762
|
});
|
|
2535
2763
|
}
|
|
2536
2764
|
|
|
2537
2765
|
// src/utility/selectOptions.ts
|
|
2538
|
-
import {
|
|
2766
|
+
import { getConfig as getConfig3 } from "@testing-library/dom";
|
|
2539
2767
|
function selectOptions(select, values) {
|
|
2540
2768
|
return __async(this, null, function* () {
|
|
2541
2769
|
return selectOptionsBase.call(this, true, select, values);
|
|
@@ -2549,7 +2777,7 @@ function deselectOptions(select, values) {
|
|
|
2549
2777
|
function selectOptionsBase(newValue, select, values) {
|
|
2550
2778
|
return __async(this, null, function* () {
|
|
2551
2779
|
if (!newValue && !select.multiple) {
|
|
2552
|
-
throw
|
|
2780
|
+
throw getConfig3().getElementError(`Unable to deselect an option in a non-multiple select. Use selectOptions to change the selection instead.`, select);
|
|
2553
2781
|
}
|
|
2554
2782
|
const valArray = Array.isArray(values) ? values : [values];
|
|
2555
2783
|
const allOptions = Array.from(select.querySelectorAll('option, [role="option"]'));
|
|
@@ -2561,38 +2789,47 @@ function selectOptionsBase(newValue, select, values) {
|
|
|
2561
2789
|
if (matchingOption) {
|
|
2562
2790
|
return matchingOption;
|
|
2563
2791
|
} else {
|
|
2564
|
-
throw
|
|
2792
|
+
throw getConfig3().getElementError(`Value "${String(val)}" not found in options`, select);
|
|
2565
2793
|
}
|
|
2566
2794
|
}
|
|
2567
2795
|
}).filter((option) => !isDisabled(option));
|
|
2568
2796
|
if (isDisabled(select) || !selectedOptions.length)
|
|
2569
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
|
+
};
|
|
2570
2807
|
if (isElementType(select, "select")) {
|
|
2571
2808
|
if (select.multiple) {
|
|
2572
2809
|
for (const option of selectedOptions) {
|
|
2573
|
-
const withPointerEvents = this[Config].
|
|
2810
|
+
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(option);
|
|
2574
2811
|
if (withPointerEvents) {
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
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");
|
|
2583
2820
|
}
|
|
2584
2821
|
focus(select);
|
|
2585
2822
|
if (withPointerEvents) {
|
|
2586
|
-
|
|
2587
|
-
|
|
2823
|
+
this.dispatchUIEvent(option, "pointerup");
|
|
2824
|
+
this.dispatchUIEvent(option, "mouseup");
|
|
2588
2825
|
}
|
|
2589
2826
|
selectOption(option);
|
|
2590
2827
|
if (withPointerEvents) {
|
|
2591
|
-
|
|
2828
|
+
this.dispatchUIEvent(option, "click");
|
|
2592
2829
|
}
|
|
2593
2830
|
}
|
|
2594
2831
|
} else if (selectedOptions.length === 1) {
|
|
2595
|
-
const withPointerEvents = this[Config].
|
|
2832
|
+
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(select);
|
|
2596
2833
|
if (withPointerEvents) {
|
|
2597
2834
|
yield this.click(select);
|
|
2598
2835
|
} else {
|
|
@@ -2600,16 +2837,16 @@ function selectOptionsBase(newValue, select, values) {
|
|
|
2600
2837
|
}
|
|
2601
2838
|
selectOption(selectedOptions[0]);
|
|
2602
2839
|
if (withPointerEvents) {
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
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");
|
|
2610
2847
|
}
|
|
2611
2848
|
} else {
|
|
2612
|
-
throw
|
|
2849
|
+
throw getConfig3().getElementError(`Cannot select multiple options on a non-multiple select`, select);
|
|
2613
2850
|
}
|
|
2614
2851
|
} else if (select.getAttribute("role") === "listbox") {
|
|
2615
2852
|
for (const option of selectedOptions) {
|
|
@@ -2617,16 +2854,7 @@ function selectOptionsBase(newValue, select, values) {
|
|
|
2617
2854
|
yield this.unhover(option);
|
|
2618
2855
|
}
|
|
2619
2856
|
} else {
|
|
2620
|
-
throw
|
|
2621
|
-
}
|
|
2622
|
-
function selectOption(option) {
|
|
2623
|
-
option.selected = newValue;
|
|
2624
|
-
fireEvent13(select, createEvent2("input", select, {
|
|
2625
|
-
bubbles: true,
|
|
2626
|
-
cancelable: false,
|
|
2627
|
-
composed: true
|
|
2628
|
-
}));
|
|
2629
|
-
fireEvent13.change(select);
|
|
2857
|
+
throw getConfig3().getElementError(`Cannot select options on elements that are neither select nor listbox elements`, select);
|
|
2630
2858
|
}
|
|
2631
2859
|
});
|
|
2632
2860
|
}
|
|
@@ -2655,29 +2883,30 @@ function type(_0, _1) {
|
|
|
2655
2883
|
}
|
|
2656
2884
|
|
|
2657
2885
|
// src/utility/upload.ts
|
|
2658
|
-
import { fireEvent as fireEvent14 } from "@testing-library/dom";
|
|
2659
2886
|
function upload(element, fileOrFiles) {
|
|
2660
2887
|
return __async(this, null, function* () {
|
|
2661
|
-
var _a;
|
|
2662
2888
|
const input = isElementType(element, "label") ? element.control : element;
|
|
2663
2889
|
if (!input || !isElementType(input, "input", { type: "file" })) {
|
|
2664
2890
|
throw new TypeError(`The ${input === element ? "given" : "associated"} ${input == null ? void 0 : input.tagName} element does not accept file uploads`);
|
|
2665
2891
|
}
|
|
2666
2892
|
if (isDisabled(element))
|
|
2667
2893
|
return;
|
|
2668
|
-
yield this.click(element);
|
|
2669
2894
|
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? void 0 : 1);
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
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);
|
|
2681
2910
|
});
|
|
2682
2911
|
}
|
|
2683
2912
|
function isAcceptableFile(file, accept) {
|
|
@@ -2702,40 +2931,55 @@ function wrapAsync(implementation) {
|
|
|
2702
2931
|
}
|
|
2703
2932
|
|
|
2704
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
|
+
}
|
|
2705
2946
|
function setupMain(options = {}) {
|
|
2706
2947
|
var _a;
|
|
2707
|
-
const
|
|
2708
|
-
prepareDocument(
|
|
2709
|
-
const view = (_a =
|
|
2948
|
+
const config = createConfig(options);
|
|
2949
|
+
prepareDocument(config.document);
|
|
2950
|
+
const view = (_a = config.document.defaultView) != null ? _a : window;
|
|
2710
2951
|
attachClipboardStubToView(view);
|
|
2711
|
-
return doSetup(
|
|
2712
|
-
keyboardState: createKeyboardState(),
|
|
2713
|
-
pointerState: createPointerState(doc)
|
|
2714
|
-
}));
|
|
2952
|
+
return doSetup(config);
|
|
2715
2953
|
}
|
|
2716
2954
|
function setupDirect(options = {}, node) {
|
|
2717
|
-
const
|
|
2718
|
-
prepareDocument(
|
|
2719
|
-
return
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
}
|
|
2955
|
+
const config = createConfig(options, defaultOptionsDirect, node);
|
|
2956
|
+
prepareDocument(config.document);
|
|
2957
|
+
return {
|
|
2958
|
+
config,
|
|
2959
|
+
api: doSetup(config)
|
|
2960
|
+
};
|
|
2723
2961
|
}
|
|
2724
2962
|
function setupSub(options) {
|
|
2725
2963
|
return doSetup(__spreadValues(__spreadValues({}, this[Config]), options));
|
|
2726
2964
|
}
|
|
2727
|
-
function
|
|
2965
|
+
function wrapAndBindImpl(instance, impl) {
|
|
2728
2966
|
function method(...args) {
|
|
2729
|
-
|
|
2967
|
+
setLevelRef(instance[Config], 1 /* Call */);
|
|
2968
|
+
return wrapAsync(() => impl.apply(instance, args));
|
|
2730
2969
|
}
|
|
2731
2970
|
Object.defineProperty(method, "name", { get: () => impl.name });
|
|
2732
2971
|
return method;
|
|
2733
2972
|
}
|
|
2734
|
-
var wrappedApis = Object.fromEntries(Object.entries(api_exports).map(([name, impl]) => [name, wrapImpl(impl)]));
|
|
2735
2973
|
function doSetup(config) {
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2974
|
+
const instance = __spreadValues({
|
|
2975
|
+
[Config]: config,
|
|
2976
|
+
dispatchUIEvent: bindDispatchUIEvent(config)
|
|
2977
|
+
}, api_exports);
|
|
2978
|
+
return __spreadProps(__spreadValues({}, Object.fromEntries(Object.entries(api_exports).map(([name, api]) => [
|
|
2979
|
+
name,
|
|
2980
|
+
wrapAndBindImpl(instance, api)
|
|
2981
|
+
]))), {
|
|
2982
|
+
setup: setupSub.bind(instance)
|
|
2739
2983
|
});
|
|
2740
2984
|
}
|
|
2741
2985
|
function getDocument(options, node) {
|
|
@@ -2764,62 +3008,60 @@ __export(directApi_exports, {
|
|
|
2764
3008
|
upload: () => upload2
|
|
2765
3009
|
});
|
|
2766
3010
|
function clear2(element) {
|
|
2767
|
-
return setupDirect().clear(element);
|
|
3011
|
+
return setupDirect().api.clear(element);
|
|
2768
3012
|
}
|
|
2769
3013
|
function click2(element, options = {}) {
|
|
2770
|
-
return setupDirect(options, element).click(element);
|
|
3014
|
+
return setupDirect(options, element).api.click(element);
|
|
2771
3015
|
}
|
|
2772
3016
|
function copy2(options = {}) {
|
|
2773
|
-
return setupDirect(options).copy();
|
|
3017
|
+
return setupDirect(options).api.copy();
|
|
2774
3018
|
}
|
|
2775
3019
|
function cut2(options = {}) {
|
|
2776
|
-
return setupDirect(options).cut();
|
|
3020
|
+
return setupDirect(options).api.cut();
|
|
2777
3021
|
}
|
|
2778
3022
|
function dblClick2(element, options = {}) {
|
|
2779
|
-
return setupDirect(options).dblClick(element);
|
|
3023
|
+
return setupDirect(options).api.dblClick(element);
|
|
2780
3024
|
}
|
|
2781
3025
|
function deselectOptions2(select, values, options = {}) {
|
|
2782
|
-
return setupDirect(options).deselectOptions(select, values);
|
|
3026
|
+
return setupDirect(options).api.deselectOptions(select, values);
|
|
2783
3027
|
}
|
|
2784
3028
|
function hover2(element, options = {}) {
|
|
2785
|
-
return setupDirect(options).hover(element);
|
|
3029
|
+
return setupDirect(options).api.hover(element);
|
|
2786
3030
|
}
|
|
2787
3031
|
function keyboard2(_0) {
|
|
2788
3032
|
return __async(this, arguments, function* (text, options = {}) {
|
|
2789
|
-
const
|
|
2790
|
-
|
|
2791
|
-
return promise.then(() => instance[Config].keyboardState);
|
|
3033
|
+
const { config, api } = setupDirect(options);
|
|
3034
|
+
return api.keyboard(text).then(() => config.keyboardState);
|
|
2792
3035
|
});
|
|
2793
3036
|
}
|
|
2794
3037
|
function pointer2(_0) {
|
|
2795
3038
|
return __async(this, arguments, function* (input, options = {}) {
|
|
2796
|
-
const
|
|
2797
|
-
|
|
2798
|
-
return promise.then(() => instance[Config].pointerState);
|
|
3039
|
+
const { config, api } = setupDirect(options);
|
|
3040
|
+
return api.pointer(input).then(() => config.pointerState);
|
|
2799
3041
|
});
|
|
2800
3042
|
}
|
|
2801
3043
|
function paste2(clipboardData, options) {
|
|
2802
|
-
return setupDirect(options).paste(clipboardData);
|
|
3044
|
+
return setupDirect(options).api.paste(clipboardData);
|
|
2803
3045
|
}
|
|
2804
3046
|
function selectOptions2(select, values, options = {}) {
|
|
2805
|
-
return setupDirect(options).selectOptions(select, values);
|
|
3047
|
+
return setupDirect(options).api.selectOptions(select, values);
|
|
2806
3048
|
}
|
|
2807
3049
|
function tripleClick2(element, options = {}) {
|
|
2808
|
-
return setupDirect(options).tripleClick(element);
|
|
3050
|
+
return setupDirect(options).api.tripleClick(element);
|
|
2809
3051
|
}
|
|
2810
3052
|
function type2(element, text, options = {}) {
|
|
2811
|
-
return setupDirect(options, element).type(element, text, options);
|
|
3053
|
+
return setupDirect(options, element).api.type(element, text, options);
|
|
2812
3054
|
}
|
|
2813
3055
|
function unhover2(element, options = {}) {
|
|
2814
|
-
const
|
|
2815
|
-
|
|
2816
|
-
return
|
|
3056
|
+
const { config, api } = setupDirect(options);
|
|
3057
|
+
config.pointerState.position.mouse.target = element;
|
|
3058
|
+
return api.unhover(element);
|
|
2817
3059
|
}
|
|
2818
3060
|
function upload2(element, fileOrFiles, options = {}) {
|
|
2819
|
-
return setupDirect(options).upload(element, fileOrFiles);
|
|
3061
|
+
return setupDirect(options).api.upload(element, fileOrFiles);
|
|
2820
3062
|
}
|
|
2821
3063
|
function tab2(options = {}) {
|
|
2822
|
-
return setupDirect().tab(options);
|
|
3064
|
+
return setupDirect().api.tab(options);
|
|
2823
3065
|
}
|
|
2824
3066
|
|
|
2825
3067
|
// src/setup/index.ts
|
|
@@ -2827,5 +3069,6 @@ var userEvent = __spreadProps(__spreadValues({}, directApi_exports), {
|
|
|
2827
3069
|
setup: setupMain
|
|
2828
3070
|
});
|
|
2829
3071
|
export {
|
|
3072
|
+
PointerEventsCheckLevel,
|
|
2830
3073
|
userEvent as default
|
|
2831
3074
|
};
|