@testing-library/user-event 14.4.0 → 14.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/clipboard/copy.js +2 -1
- package/dist/cjs/clipboard/cut.js +2 -1
- package/dist/cjs/clipboard/paste.js +4 -2
- package/dist/cjs/document/interceptor.js +4 -4
- package/dist/cjs/document/selection.js +4 -3
- package/dist/cjs/document/value.js +4 -2
- package/dist/cjs/event/behavior/keydown.js +6 -2
- package/dist/cjs/event/behavior/keypress.js +1 -1
- package/dist/cjs/event/behavior/keyup.js +2 -1
- package/dist/cjs/event/behavior/paste.js +2 -1
- package/dist/cjs/event/createEvent.js +35 -19
- package/dist/cjs/event/dispatchEvent.js +2 -1
- package/dist/cjs/keyboard/parseKeyDef.js +7 -4
- package/dist/cjs/pointer/index.js +10 -6
- package/dist/cjs/setup/setup.js +7 -4
- package/dist/cjs/system/index.js +4 -2
- package/dist/cjs/system/keyboard.js +25 -23
- package/dist/cjs/system/pointer/buttons.js +3 -1
- package/dist/cjs/system/pointer/device.js +3 -1
- package/dist/cjs/system/pointer/index.js +69 -61
- package/dist/cjs/system/pointer/mouse.js +53 -44
- package/dist/cjs/system/pointer/pointer.js +13 -12
- package/dist/cjs/utility/type.js +1 -1
- package/dist/cjs/utility/upload.js +6 -2
- package/dist/cjs/utils/dataTransfer/Clipboard.js +10 -6
- package/dist/cjs/utils/dataTransfer/DataTransfer.js +22 -19
- package/dist/cjs/utils/edit/input.js +2 -1
- package/dist/cjs/utils/edit/maxLength.js +2 -1
- package/dist/cjs/utils/edit/setFiles.js +4 -2
- package/dist/cjs/utils/focus/cursor.js +2 -1
- package/dist/cjs/utils/focus/focus.js +6 -3
- package/dist/cjs/utils/focus/getActiveElement.js +3 -2
- package/dist/cjs/utils/focus/resolveCaretPosition.js +3 -3
- package/dist/cjs/utils/focus/selectAll.js +5 -3
- package/dist/cjs/utils/focus/selection.js +23 -18
- package/dist/cjs/utils/keyDef/readNextDescriptor.js +5 -3
- package/dist/cjs/utils/misc/isDisabled.js +2 -1
- package/dist/cjs/utils/misc/isVisible.js +1 -1
- package/dist/cjs/utils/misc/level.js +5 -2
- package/dist/cjs/utils/pointer/cssPointerEvents.js +18 -11
- package/dist/esm/clipboard/copy.js +2 -1
- package/dist/esm/clipboard/cut.js +2 -1
- package/dist/esm/clipboard/paste.js +4 -2
- package/dist/esm/document/interceptor.js +4 -4
- package/dist/esm/document/selection.js +4 -3
- package/dist/esm/document/value.js +4 -2
- package/dist/esm/event/behavior/keydown.js +6 -2
- package/dist/esm/event/behavior/keypress.js +1 -1
- package/dist/esm/event/behavior/keyup.js +2 -1
- package/dist/esm/event/behavior/paste.js +2 -1
- package/dist/esm/event/createEvent.js +35 -19
- package/dist/esm/event/dispatchEvent.js +2 -1
- package/dist/esm/keyboard/parseKeyDef.js +7 -4
- package/dist/esm/pointer/index.js +10 -6
- package/dist/esm/setup/setup.js +7 -4
- package/dist/esm/system/index.js +4 -2
- package/dist/esm/system/keyboard.js +25 -23
- package/dist/esm/system/pointer/buttons.js +3 -1
- package/dist/esm/system/pointer/device.js +3 -1
- package/dist/esm/system/pointer/index.js +69 -61
- package/dist/esm/system/pointer/mouse.js +54 -45
- package/dist/esm/system/pointer/pointer.js +13 -12
- package/dist/esm/utility/type.js +1 -1
- package/dist/esm/utility/upload.js +6 -2
- package/dist/esm/utils/dataTransfer/Clipboard.js +10 -6
- package/dist/esm/utils/dataTransfer/DataTransfer.js +22 -19
- package/dist/esm/utils/edit/input.js +2 -1
- package/dist/esm/utils/edit/maxLength.js +2 -1
- package/dist/esm/utils/edit/setFiles.js +4 -2
- package/dist/esm/utils/focus/cursor.js +2 -1
- package/dist/esm/utils/focus/focus.js +6 -3
- package/dist/esm/utils/focus/getActiveElement.js +3 -2
- package/dist/esm/utils/focus/resolveCaretPosition.js +3 -3
- package/dist/esm/utils/focus/selectAll.js +5 -3
- package/dist/esm/utils/focus/selection.js +23 -18
- package/dist/esm/utils/keyDef/readNextDescriptor.js +5 -3
- package/dist/esm/utils/misc/isDisabled.js +2 -1
- package/dist/esm/utils/misc/isVisible.js +1 -1
- package/dist/esm/utils/misc/level.js +5 -2
- package/dist/esm/utils/pointer/cssPointerEvents.js +18 -11
- package/package.json +3 -3
|
@@ -30,6 +30,7 @@ var value = require('../../document/value.js');
|
|
|
30
30
|
*
|
|
31
31
|
* Handles input elements and contenteditable if it only contains a single text node.
|
|
32
32
|
*/ function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
33
|
+
var ref;
|
|
33
34
|
if (hasOwnSelection(element)) {
|
|
34
35
|
return setSelection({
|
|
35
36
|
focusNode: element,
|
|
@@ -37,7 +38,7 @@ var value = require('../../document/value.js');
|
|
|
37
38
|
focusOffset
|
|
38
39
|
});
|
|
39
40
|
}
|
|
40
|
-
/* istanbul ignore else */ if (isContentEditable.isContentEditable(element) && element.firstChild
|
|
41
|
+
/* istanbul ignore else */ if (isContentEditable.isContentEditable(element) && ((ref = element.firstChild) === null || ref === void 0 ? void 0 : ref.nodeType) === 3) {
|
|
41
42
|
return setSelection({
|
|
42
43
|
focusNode: element.firstChild,
|
|
43
44
|
anchorOffset,
|
|
@@ -68,10 +69,10 @@ function isElement(node) {
|
|
|
68
69
|
selection: selection.getUISelection(element)
|
|
69
70
|
};
|
|
70
71
|
}
|
|
71
|
-
const selection$1 = element
|
|
72
|
+
const selection$1 = element === null || element === void 0 ? void 0 : element.ownerDocument.getSelection();
|
|
72
73
|
// It is possible to extend a single-range selection into a contenteditable.
|
|
73
74
|
// This results in the range acting like a range outside of contenteditable.
|
|
74
|
-
const isCE = isContentEditable.getContentEditable(node) && selection$1
|
|
75
|
+
const isCE = isContentEditable.getContentEditable(node) && (selection$1 === null || selection$1 === void 0 ? void 0 : selection$1.anchorNode) && isContentEditable.getContentEditable(selection$1.anchorNode);
|
|
75
76
|
return {
|
|
76
77
|
type: isCE ? 'contenteditable' : 'default',
|
|
77
78
|
selection: selection$1
|
|
@@ -85,7 +86,7 @@ function getElement(node) {
|
|
|
85
86
|
* with own selection implementation.
|
|
86
87
|
*/ function updateSelectionOnFocus(element) {
|
|
87
88
|
const selection = element.ownerDocument.getSelection();
|
|
88
|
-
/* istanbul ignore if */ if (!selection
|
|
89
|
+
/* istanbul ignore if */ if (!(selection === null || selection === void 0 ? void 0 : selection.focusNode)) {
|
|
89
90
|
return;
|
|
90
91
|
}
|
|
91
92
|
// If the focus moves inside an element with own selection implementation,
|
|
@@ -99,7 +100,8 @@ function getElement(node) {
|
|
|
99
100
|
const contenteditable = isContentEditable.getContentEditable(selection.focusNode);
|
|
100
101
|
if (contenteditable) {
|
|
101
102
|
if (!selection.isCollapsed) {
|
|
102
|
-
|
|
103
|
+
var ref;
|
|
104
|
+
const focusNode = ((ref = contenteditable.firstChild) === null || ref === void 0 ? void 0 : ref.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
103
105
|
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
104
106
|
}
|
|
105
107
|
} else {
|
|
@@ -114,13 +116,15 @@ function getElement(node) {
|
|
|
114
116
|
if (typeAndSelection.type === 'input') {
|
|
115
117
|
return typeAndSelection.selection;
|
|
116
118
|
} else if (typeAndSelection.type === 'contenteditable') {
|
|
119
|
+
var ref;
|
|
117
120
|
// Multi-range on contenteditable edits the first selection instead of the last
|
|
118
|
-
return typeAndSelection.selection
|
|
121
|
+
return (ref = typeAndSelection.selection) === null || ref === void 0 ? void 0 : ref.getRangeAt(0);
|
|
119
122
|
}
|
|
120
123
|
}
|
|
121
124
|
/**
|
|
122
125
|
* Extend/shrink the selection like with Shift+Arrows or Shift+Mouse
|
|
123
126
|
*/ function modifySelection({ focusNode , focusOffset }) {
|
|
127
|
+
var ref, ref1;
|
|
124
128
|
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
125
129
|
if (typeAndSelection.type === 'input') {
|
|
126
130
|
return selection.setUISelection(focusNode, {
|
|
@@ -128,11 +132,12 @@ function getElement(node) {
|
|
|
128
132
|
focusOffset
|
|
129
133
|
}, 'modify');
|
|
130
134
|
}
|
|
131
|
-
focusNode.ownerDocument
|
|
135
|
+
(ref1 = (ref = focusNode.ownerDocument) === null || ref === void 0 ? void 0 : ref.getSelection()) === null || ref1 === void 0 ? void 0 : ref1.extend(focusNode, focusOffset);
|
|
132
136
|
}
|
|
133
137
|
/**
|
|
134
138
|
* Set the selection
|
|
135
139
|
*/ function setSelection({ focusNode , focusOffset , anchorNode =focusNode , anchorOffset =focusOffset }) {
|
|
140
|
+
var ref, ref1;
|
|
136
141
|
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
137
142
|
if (typeAndSelection.type === 'input') {
|
|
138
143
|
return selection.setUISelection(focusNode, {
|
|
@@ -140,7 +145,7 @@ function getElement(node) {
|
|
|
140
145
|
focusOffset
|
|
141
146
|
});
|
|
142
147
|
}
|
|
143
|
-
anchorNode.ownerDocument
|
|
148
|
+
(ref1 = (ref = anchorNode.ownerDocument) === null || ref === void 0 ? void 0 : ref.getSelection()) === null || ref1 === void 0 ? void 0 : ref1.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
144
149
|
}
|
|
145
150
|
/**
|
|
146
151
|
* Move the selection
|
|
@@ -154,7 +159,7 @@ function getElement(node) {
|
|
|
154
159
|
});
|
|
155
160
|
} else {
|
|
156
161
|
const selection1 = node.ownerDocument.getSelection();
|
|
157
|
-
if (!selection1
|
|
162
|
+
if (!(selection1 === null || selection1 === void 0 ? void 0 : selection1.focusNode)) {
|
|
158
163
|
return;
|
|
159
164
|
}
|
|
160
165
|
if (selection1.isCollapsed) {
|
|
@@ -190,13 +195,13 @@ function setSelectionPerMouseDown({ document , target , clickCount , node , offs
|
|
|
190
195
|
// TODO: implement modifying selection per shift/ctrl+mouse
|
|
191
196
|
if (targetHasOwnSelection) {
|
|
192
197
|
selection.setUISelection(target, {
|
|
193
|
-
anchorOffset: start
|
|
194
|
-
focusOffset: end
|
|
198
|
+
anchorOffset: start !== null && start !== void 0 ? start : text.length,
|
|
199
|
+
focusOffset: end !== null && end !== void 0 ? end : text.length
|
|
195
200
|
});
|
|
196
201
|
return {
|
|
197
202
|
node: target,
|
|
198
|
-
start: start
|
|
199
|
-
end: end
|
|
203
|
+
start: start !== null && start !== void 0 ? start : 0,
|
|
204
|
+
end: end !== null && end !== void 0 ? end : text.length
|
|
200
205
|
};
|
|
201
206
|
} else {
|
|
202
207
|
const { node: startNode , offset: startOffset } = resolveCaretPosition.resolveCaretPosition({
|
|
@@ -217,8 +222,8 @@ function setSelectionPerMouseDown({ document , target , clickCount , node , offs
|
|
|
217
222
|
throw new Error('The given offset is out of bounds.');
|
|
218
223
|
}
|
|
219
224
|
const selection = document.getSelection();
|
|
220
|
-
selection
|
|
221
|
-
selection
|
|
225
|
+
selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
|
|
226
|
+
selection === null || selection === void 0 ? void 0 : selection.addRange(range.cloneRange());
|
|
222
227
|
return range;
|
|
223
228
|
}
|
|
224
229
|
}
|
|
@@ -229,7 +234,7 @@ function getTextRange(text, pos, clickCount) {
|
|
|
229
234
|
pos
|
|
230
235
|
];
|
|
231
236
|
}
|
|
232
|
-
const textPos = pos
|
|
237
|
+
const textPos = pos !== null && pos !== void 0 ? pos : text.length;
|
|
233
238
|
if (clickCount % 3 === 2) {
|
|
234
239
|
return [
|
|
235
240
|
textPos - text.substr(0, pos).match(/(\w+|\s+|\W)?$/)[0].length,
|
|
@@ -270,8 +275,8 @@ function modifySelectionPerMouseMove(selectionRange, { document , target , node
|
|
|
270
275
|
range.setEnd(selectionFocus.node, selectionFocus.offset);
|
|
271
276
|
}
|
|
272
277
|
const selection = document.getSelection();
|
|
273
|
-
selection
|
|
274
|
-
selection
|
|
278
|
+
selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
|
|
279
|
+
selection === null || selection === void 0 ? void 0 : selection.addRange(range.cloneRange());
|
|
275
280
|
}
|
|
276
281
|
}
|
|
277
282
|
|
|
@@ -41,14 +41,16 @@ function readPrintableChar(text, pos, context) {
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
function readTag(text, pos, startBracket, context) {
|
|
44
|
+
var ref, ref1;
|
|
44
45
|
const releasePreviousModifier = text[pos] === '/' ? '/' : '';
|
|
45
46
|
pos += releasePreviousModifier.length;
|
|
46
47
|
const escapedDescriptor = startBracket === '{' && text[pos] === '\\';
|
|
47
48
|
pos += Number(escapedDescriptor);
|
|
48
|
-
const descriptor = escapedDescriptor ? text[pos] : text.slice(pos).match(startBracket === '{' ? /^\w+|^[^}>/]/ : /^\w+/)
|
|
49
|
+
const descriptor = escapedDescriptor ? text[pos] : (ref = text.slice(pos).match(startBracket === '{' ? /^\w+|^[^}>/]/ : /^\w+/)) === null || ref === void 0 ? void 0 : ref[0];
|
|
49
50
|
assertDescriptor(descriptor, text, pos, context);
|
|
50
51
|
pos += descriptor.length;
|
|
51
|
-
|
|
52
|
+
var ref2;
|
|
53
|
+
const repeatModifier = (ref2 = (ref1 = text.slice(pos).match(/^>\d+/)) === null || ref1 === void 0 ? void 0 : ref1[0]) !== null && ref2 !== void 0 ? ref2 : '';
|
|
52
54
|
pos += repeatModifier.length;
|
|
53
55
|
const releaseSelfModifier = text[pos] === '/' || !repeatModifier && text[pos] === '>' ? text[pos] : '';
|
|
54
56
|
pos += releaseSelfModifier.length;
|
|
@@ -84,7 +86,7 @@ function hasReleaseSelf(releaseSelfModifier, repeatModifier) {
|
|
|
84
86
|
}
|
|
85
87
|
}
|
|
86
88
|
function getErrorMessage(expected, found, text, context) {
|
|
87
|
-
return `Expected ${expected} but found "${found
|
|
89
|
+
return `Expected ${expected} but found "${found !== null && found !== void 0 ? found : ''}" in "${text}"
|
|
88
90
|
See ${context === 'pointer' ? `https://testing-library.com/docs/user-event/pointer#pressing-a-button-or-touching-the-screen` : `https://testing-library.com/docs/user-event/keyboard`}
|
|
89
91
|
for more information about how userEvent parses your input.`;
|
|
90
92
|
}
|
|
@@ -19,7 +19,8 @@ function isDisabled(element) {
|
|
|
19
19
|
return true;
|
|
20
20
|
}
|
|
21
21
|
} else if (isElementType.isElementType(el, 'fieldset')) {
|
|
22
|
-
|
|
22
|
+
var ref;
|
|
23
|
+
if (el.hasAttribute('disabled') && !((ref = el.querySelector(':scope > legend')) === null || ref === void 0 ? void 0 : ref.contains(element))) {
|
|
23
24
|
return true;
|
|
24
25
|
}
|
|
25
26
|
} else if (el.tagName.includes('-')) {
|
|
@@ -6,7 +6,7 @@ var getWindow = require('./getWindow.js');
|
|
|
6
6
|
|
|
7
7
|
function isVisible(element) {
|
|
8
8
|
const window = getWindow.getWindow(element);
|
|
9
|
-
for(let el = element; el
|
|
9
|
+
for(let el = element; el === null || el === void 0 ? void 0 : el.ownerDocument; el = el.parentElement){
|
|
10
10
|
const { display , visibility } = window.getComputedStyle(el);
|
|
11
11
|
if (display === 'none') {
|
|
12
12
|
return false;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var _config, _Level;
|
|
5
6
|
exports.ApiLevel = void 0;
|
|
6
7
|
(function(ApiLevel) {
|
|
7
8
|
ApiLevel[ApiLevel["Trigger"] = 2] = "Trigger";
|
|
@@ -9,11 +10,13 @@ exports.ApiLevel = void 0;
|
|
|
9
10
|
})(exports.ApiLevel || (exports.ApiLevel = {}));
|
|
10
11
|
const Level = Symbol('Api level refs');
|
|
11
12
|
function setLevelRef(config, level) {
|
|
12
|
-
|
|
13
|
+
var ref;
|
|
14
|
+
(ref = (_config = config)[_Level = Level]) !== null && ref !== void 0 ? ref : _config[_Level] = {};
|
|
13
15
|
config[Level][level] = {};
|
|
14
16
|
}
|
|
15
17
|
function getLevelRef(config, level) {
|
|
16
|
-
|
|
18
|
+
var ref;
|
|
19
|
+
return (ref = config[Level]) === null || ref === void 0 ? void 0 : ref[level];
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
exports.getLevelRef = getLevelRef;
|
|
@@ -21,11 +21,12 @@ require('../keyDef/readNextDescriptor.js');
|
|
|
21
21
|
var level = require('../misc/level.js');
|
|
22
22
|
|
|
23
23
|
function hasPointerEvents(config, element) {
|
|
24
|
-
|
|
24
|
+
var ref;
|
|
25
|
+
return ((ref = checkPointerEvents(config, element)) === null || ref === void 0 ? void 0 : ref.pointerEvents) !== 'none';
|
|
25
26
|
}
|
|
26
27
|
function closestPointerEventsDeclaration(element) {
|
|
27
28
|
const window = getWindow.getWindow(element);
|
|
28
|
-
for(let el = element, tree = []; el
|
|
29
|
+
for(let el = element, tree = []; el === null || el === void 0 ? void 0 : el.ownerDocument; el = el.parentElement){
|
|
29
30
|
tree.push(el);
|
|
30
31
|
const pointerEvents = window.getComputedStyle(el).pointerEvents;
|
|
31
32
|
if (pointerEvents && ![
|
|
@@ -45,7 +46,7 @@ function checkPointerEvents(config, element) {
|
|
|
45
46
|
const lastCheck = element[PointerEventsCheck];
|
|
46
47
|
const needsCheck = config.pointerEventsCheck !== options.PointerEventsCheckLevel.Never && (!lastCheck || hasBitFlag(config.pointerEventsCheck, options.PointerEventsCheckLevel.EachApiCall) && lastCheck[level.ApiLevel.Call] !== level.getLevelRef(config, level.ApiLevel.Call) || hasBitFlag(config.pointerEventsCheck, options.PointerEventsCheckLevel.EachTrigger) && lastCheck[level.ApiLevel.Trigger] !== level.getLevelRef(config, level.ApiLevel.Trigger));
|
|
47
48
|
if (!needsCheck) {
|
|
48
|
-
return lastCheck
|
|
49
|
+
return lastCheck === null || lastCheck === void 0 ? void 0 : lastCheck.result;
|
|
49
50
|
}
|
|
50
51
|
const declaration = closestPointerEventsDeclaration(element);
|
|
51
52
|
element[PointerEventsCheck] = {
|
|
@@ -57,7 +58,7 @@ function checkPointerEvents(config, element) {
|
|
|
57
58
|
}
|
|
58
59
|
function assertPointerEvents(config, element) {
|
|
59
60
|
const declaration = checkPointerEvents(config, element);
|
|
60
|
-
if (declaration
|
|
61
|
+
if ((declaration === null || declaration === void 0 ? void 0 : declaration.pointerEvents) === 'none') {
|
|
61
62
|
throw new Error([
|
|
62
63
|
`Unable to perform pointer interaction as the element ${declaration.tree.length > 1 ? 'inherits' : 'has'} \`pointer-events: none\`:`,
|
|
63
64
|
'',
|
|
@@ -77,11 +78,13 @@ function printTree(tree) {
|
|
|
77
78
|
].filter(Boolean).join('')).join('\n');
|
|
78
79
|
}
|
|
79
80
|
function getLabelDescr(element) {
|
|
81
|
+
var ref;
|
|
80
82
|
let label;
|
|
81
83
|
if (element.hasAttribute('aria-label')) {
|
|
82
84
|
label = element.getAttribute('aria-label');
|
|
83
85
|
} else if (element.hasAttribute('aria-labelledby')) {
|
|
84
|
-
|
|
86
|
+
var ref1, ref2;
|
|
87
|
+
label = (ref1 = element.ownerDocument.getElementById(element.getAttribute('aria-labelledby'))) === null || ref1 === void 0 ? void 0 : (ref2 = ref1.textContent) === null || ref2 === void 0 ? void 0 : ref2.trim();
|
|
85
88
|
} else if (isElementType.isElementType(element, [
|
|
86
89
|
'button',
|
|
87
90
|
'input',
|
|
@@ -90,14 +93,18 @@ function getLabelDescr(element) {
|
|
|
90
93
|
'progress',
|
|
91
94
|
'select',
|
|
92
95
|
'textarea',
|
|
93
|
-
]) && element.labels
|
|
94
|
-
label = Array.from(element.labels).map((el)=>
|
|
96
|
+
]) && ((ref = element.labels) === null || ref === void 0 ? void 0 : ref.length)) {
|
|
97
|
+
label = Array.from(element.labels).map((el)=>{
|
|
98
|
+
var ref;
|
|
99
|
+
return (ref = el.textContent) === null || ref === void 0 ? void 0 : ref.trim();
|
|
100
|
+
}).join('|');
|
|
95
101
|
} else if (isElementType.isElementType(element, 'button')) {
|
|
96
|
-
|
|
102
|
+
var ref3;
|
|
103
|
+
label = (ref3 = element.textContent) === null || ref3 === void 0 ? void 0 : ref3.trim();
|
|
97
104
|
}
|
|
98
|
-
label = label
|
|
99
|
-
if (Number(label
|
|
100
|
-
label = `${label
|
|
105
|
+
label = label === null || label === void 0 ? void 0 : label.replace(/\n/g, ' ');
|
|
106
|
+
if (Number(label === null || label === void 0 ? void 0 : label.length) > 30) {
|
|
107
|
+
label = `${label === null || label === void 0 ? void 0 : label.substring(0, 29)}…`;
|
|
101
108
|
}
|
|
102
109
|
return label ? `(label=${label})` : '';
|
|
103
110
|
}
|
|
@@ -20,7 +20,8 @@ import { Config } from '../setup/config.js';
|
|
|
20
20
|
|
|
21
21
|
async function copy() {
|
|
22
22
|
const doc = this[Config].document;
|
|
23
|
-
|
|
23
|
+
var _activeElement;
|
|
24
|
+
const target = (_activeElement = doc.activeElement) !== null && _activeElement !== void 0 ? _activeElement : /* istanbul ignore next */ doc.body;
|
|
24
25
|
const clipboardData = copySelection(target);
|
|
25
26
|
if (clipboardData.items.length === 0) {
|
|
26
27
|
return;
|
|
@@ -20,7 +20,8 @@ import { Config } from '../setup/config.js';
|
|
|
20
20
|
|
|
21
21
|
async function cut() {
|
|
22
22
|
const doc = this[Config].document;
|
|
23
|
-
|
|
23
|
+
var _activeElement;
|
|
24
|
+
const target = (_activeElement = doc.activeElement) !== null && _activeElement !== void 0 ? _activeElement : /* istanbul ignore next */ doc.body;
|
|
24
25
|
const clipboardData = copySelection(target);
|
|
25
26
|
if (clipboardData.items.length === 0) {
|
|
26
27
|
return;
|
|
@@ -20,8 +20,10 @@ import { Config } from '../setup/config.js';
|
|
|
20
20
|
|
|
21
21
|
async function paste(clipboardData) {
|
|
22
22
|
const doc = this[Config].document;
|
|
23
|
-
|
|
24
|
-
const
|
|
23
|
+
var _activeElement;
|
|
24
|
+
const target = (_activeElement = doc.activeElement) !== null && _activeElement !== void 0 ? _activeElement : /* istanbul ignore next */ doc.body;
|
|
25
|
+
var ref;
|
|
26
|
+
const dataTransfer = (ref = typeof clipboardData === 'string' ? getClipboardDataFromString(doc, clipboardData) : clipboardData) !== null && ref !== void 0 ? ref : await readDataTransferFromClipboard(doc).catch(()=>{
|
|
25
27
|
throw new Error('`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.');
|
|
26
28
|
});
|
|
27
29
|
this.dispatchUIEvent(target, 'paste', {
|
|
@@ -2,8 +2,8 @@ const Interceptor = Symbol('Interceptor for programmatical calls');
|
|
|
2
2
|
function prepareInterceptor(element, propName, interceptorImpl) {
|
|
3
3
|
const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
4
4
|
const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
5
|
-
const target = prototypeDescriptor
|
|
6
|
-
/* istanbul ignore if */ if (typeof prototypeDescriptor
|
|
5
|
+
const target = (prototypeDescriptor === null || prototypeDescriptor === void 0 ? void 0 : prototypeDescriptor.set) ? 'set' : 'value';
|
|
6
|
+
/* istanbul ignore if */ if (typeof (prototypeDescriptor === null || prototypeDescriptor === void 0 ? void 0 : prototypeDescriptor[target]) !== 'function' || prototypeDescriptor[target][Interceptor]) {
|
|
7
7
|
throw new Error(`Element ${element.tagName} does not implement "${String(propName)}".`);
|
|
8
8
|
}
|
|
9
9
|
function intercept(...args) {
|
|
@@ -14,11 +14,11 @@ function prepareInterceptor(element, propName, interceptorImpl) {
|
|
|
14
14
|
} else {
|
|
15
15
|
realFunc.call(this, ...realArgs);
|
|
16
16
|
}
|
|
17
|
-
then
|
|
17
|
+
then === null || then === void 0 ? void 0 : then();
|
|
18
18
|
}
|
|
19
19
|
intercept[Interceptor] = Interceptor;
|
|
20
20
|
Object.defineProperty(element, propName, {
|
|
21
|
-
...objectDescriptor
|
|
21
|
+
...objectDescriptor !== null && objectDescriptor !== void 0 ? objectDescriptor : prototypeDescriptor,
|
|
22
22
|
[target]: intercept
|
|
23
23
|
});
|
|
24
24
|
}
|
|
@@ -79,9 +79,10 @@ function setUISelection(element, { focusOffset: focusOffsetParam , anchorOffset:
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
function getUISelection(element) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
var _selectionStart, _selectionEnd, _UISelection;
|
|
83
|
+
const sel = (_UISelection = element[UISelection]) !== null && _UISelection !== void 0 ? _UISelection : {
|
|
84
|
+
anchorOffset: (_selectionStart = element.selectionStart) !== null && _selectionStart !== void 0 ? _selectionStart : 0,
|
|
85
|
+
focusOffset: (_selectionEnd = element.selectionEnd) !== null && _selectionEnd !== void 0 ? _selectionEnd : 0
|
|
85
86
|
};
|
|
86
87
|
return {
|
|
87
88
|
...sel,
|
|
@@ -87,7 +87,8 @@ function startTrackValue(element) {
|
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
89
|
function trackOrSetValue(element, v) {
|
|
90
|
-
|
|
90
|
+
var ref, ref1;
|
|
91
|
+
(ref = element[TrackChanges]) === null || ref === void 0 ? void 0 : (ref1 = ref.tracked) === null || ref1 === void 0 ? void 0 : ref1.push(v);
|
|
91
92
|
if (!element[TrackChanges]) {
|
|
92
93
|
setUIValueClean(element);
|
|
93
94
|
setUISelection(element, {
|
|
@@ -96,9 +97,10 @@ function trackOrSetValue(element, v) {
|
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
function commitValueAfterInput(element, cursorOffset) {
|
|
100
|
+
var ref;
|
|
99
101
|
const changes = element[TrackChanges];
|
|
100
102
|
element[TrackChanges] = undefined;
|
|
101
|
-
if (!changes
|
|
103
|
+
if (!(changes === null || changes === void 0 ? void 0 : (ref = changes.tracked) === null || ref === void 0 ? void 0 : ref.length)) {
|
|
102
104
|
return;
|
|
103
105
|
}
|
|
104
106
|
const isJustReactStateUpdate = changes.tracked.length === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === element.value;
|
|
@@ -25,7 +25,9 @@ import { behavior } from './registry.js';
|
|
|
25
25
|
import { setUISelection } from '../../document/selection.js';
|
|
26
26
|
|
|
27
27
|
behavior.keydown = (event, target, config)=>{
|
|
28
|
-
|
|
28
|
+
var ref;
|
|
29
|
+
var ref1;
|
|
30
|
+
return (ref1 = (ref = keydownBehavior[event.key]) === null || ref === void 0 ? void 0 : ref.call(keydownBehavior, event, target, config)) !== null && ref1 !== void 0 ? ref1 : combinationBehavior(event, target, config);
|
|
29
31
|
};
|
|
30
32
|
const keydownBehavior = {
|
|
31
33
|
ArrowDown: (event, target, config)=>{
|
|
@@ -78,7 +80,9 @@ const keydownBehavior = {
|
|
|
78
80
|
'textarea'
|
|
79
81
|
]) || isContentEditable(target)) {
|
|
80
82
|
return ()=>{
|
|
81
|
-
|
|
83
|
+
var ref;
|
|
84
|
+
var ref1;
|
|
85
|
+
const newPos = (ref1 = (ref = getValue(target)) === null || ref === void 0 ? void 0 : ref.length) !== null && ref1 !== void 0 ? ref1 : /* istanbul ignore next */ 0;
|
|
82
86
|
setSelectionRange(target, newPos, newPos);
|
|
83
87
|
};
|
|
84
88
|
}
|
|
@@ -20,7 +20,7 @@ behavior.keypress = (event, target, config)=>{
|
|
|
20
20
|
};
|
|
21
21
|
} else if (isElementType(target, 'input')) {
|
|
22
22
|
const form = target.form;
|
|
23
|
-
const submit = form
|
|
23
|
+
const submit = form === null || form === void 0 ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
|
|
24
24
|
if (submit) {
|
|
25
25
|
return ()=>dispatchUIEvent(config, submit, 'click');
|
|
26
26
|
} else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll('input').length === 1) {
|
|
@@ -11,7 +11,8 @@ import '../../options.js';
|
|
|
11
11
|
import { behavior } from './registry.js';
|
|
12
12
|
|
|
13
13
|
behavior.keyup = (event, target, config)=>{
|
|
14
|
-
|
|
14
|
+
var ref;
|
|
15
|
+
return (ref = keyupBehavior[event.key]) === null || ref === void 0 ? void 0 : ref.call(keyupBehavior, event, target, config);
|
|
15
16
|
};
|
|
16
17
|
const keyupBehavior = {
|
|
17
18
|
' ': (event, target, config)=>{
|
|
@@ -18,7 +18,8 @@ import '../../options.js';
|
|
|
18
18
|
behavior.paste = (event, target, config)=>{
|
|
19
19
|
if (isEditable(target)) {
|
|
20
20
|
return ()=>{
|
|
21
|
-
|
|
21
|
+
var ref;
|
|
22
|
+
const insertData = (ref = event.clipboardData) === null || ref === void 0 ? void 0 : ref.getData('text');
|
|
22
23
|
if (insertData) {
|
|
23
24
|
input(config, target, insertData, 'insertFromPaste');
|
|
24
25
|
}
|
|
@@ -41,42 +41,58 @@ const eventInitializer = {
|
|
|
41
41
|
]
|
|
42
42
|
};
|
|
43
43
|
function createEvent(type, target, init) {
|
|
44
|
+
var ref;
|
|
44
45
|
const window = getWindow(target);
|
|
45
46
|
const { EventType , defaultInit } = eventMap[eventMapKeys[type]];
|
|
46
47
|
const event = new (getEventConstructors(window))[EventType](type, defaultInit);
|
|
47
|
-
eventInitializer[EventType]
|
|
48
|
+
(ref = eventInitializer[EventType]) === null || ref === void 0 ? void 0 : ref.forEach((f)=>f(event, init !== null && init !== void 0 ? init : {}));
|
|
48
49
|
return event;
|
|
49
50
|
}
|
|
50
51
|
/* istanbul ignore next */ function getEventConstructors(window) {
|
|
51
|
-
|
|
52
|
+
var _Event;
|
|
53
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-extraneous-class */ const Event = (_Event = window.Event) !== null && _Event !== void 0 ? _Event : class Event {
|
|
52
54
|
};
|
|
53
|
-
|
|
55
|
+
var _AnimationEvent;
|
|
56
|
+
const AnimationEvent = (_AnimationEvent = window.AnimationEvent) !== null && _AnimationEvent !== void 0 ? _AnimationEvent : class AnimationEvent extends Event {
|
|
54
57
|
};
|
|
55
|
-
|
|
58
|
+
var _ClipboardEvent;
|
|
59
|
+
const ClipboardEvent = (_ClipboardEvent = window.ClipboardEvent) !== null && _ClipboardEvent !== void 0 ? _ClipboardEvent : class ClipboardEvent extends Event {
|
|
56
60
|
};
|
|
57
|
-
|
|
61
|
+
var _PopStateEvent;
|
|
62
|
+
const PopStateEvent = (_PopStateEvent = window.PopStateEvent) !== null && _PopStateEvent !== void 0 ? _PopStateEvent : class PopStateEvent extends Event {
|
|
58
63
|
};
|
|
59
|
-
|
|
64
|
+
var _ProgressEvent;
|
|
65
|
+
const ProgressEvent = (_ProgressEvent = window.ProgressEvent) !== null && _ProgressEvent !== void 0 ? _ProgressEvent : class ProgressEvent extends Event {
|
|
60
66
|
};
|
|
61
|
-
|
|
67
|
+
var _TransitionEvent;
|
|
68
|
+
const TransitionEvent = (_TransitionEvent = window.TransitionEvent) !== null && _TransitionEvent !== void 0 ? _TransitionEvent : class TransitionEvent extends Event {
|
|
62
69
|
};
|
|
63
|
-
|
|
70
|
+
var _UIEvent;
|
|
71
|
+
const UIEvent = (_UIEvent = window.UIEvent) !== null && _UIEvent !== void 0 ? _UIEvent : class UIEvent extends Event {
|
|
64
72
|
};
|
|
65
|
-
|
|
73
|
+
var _CompositionEvent;
|
|
74
|
+
const CompositionEvent = (_CompositionEvent = window.CompositionEvent) !== null && _CompositionEvent !== void 0 ? _CompositionEvent : class CompositionEvent extends UIEvent {
|
|
66
75
|
};
|
|
67
|
-
|
|
76
|
+
var _FocusEvent;
|
|
77
|
+
const FocusEvent = (_FocusEvent = window.FocusEvent) !== null && _FocusEvent !== void 0 ? _FocusEvent : class FocusEvent extends UIEvent {
|
|
68
78
|
};
|
|
69
|
-
|
|
79
|
+
var _InputEvent;
|
|
80
|
+
const InputEvent = (_InputEvent = window.InputEvent) !== null && _InputEvent !== void 0 ? _InputEvent : class InputEvent extends UIEvent {
|
|
70
81
|
};
|
|
71
|
-
|
|
82
|
+
var _KeyboardEvent;
|
|
83
|
+
const KeyboardEvent = (_KeyboardEvent = window.KeyboardEvent) !== null && _KeyboardEvent !== void 0 ? _KeyboardEvent : class KeyboardEvent extends UIEvent {
|
|
72
84
|
};
|
|
73
|
-
|
|
85
|
+
var _MouseEvent;
|
|
86
|
+
const MouseEvent = (_MouseEvent = window.MouseEvent) !== null && _MouseEvent !== void 0 ? _MouseEvent : class MouseEvent extends UIEvent {
|
|
74
87
|
};
|
|
75
|
-
|
|
88
|
+
var _DragEvent;
|
|
89
|
+
const DragEvent = (_DragEvent = window.DragEvent) !== null && _DragEvent !== void 0 ? _DragEvent : class DragEvent extends MouseEvent {
|
|
76
90
|
};
|
|
77
|
-
|
|
91
|
+
var _PointerEvent;
|
|
92
|
+
const PointerEvent = (_PointerEvent = window.PointerEvent) !== null && _PointerEvent !== void 0 ? _PointerEvent : class PointerEvent extends MouseEvent {
|
|
78
93
|
};
|
|
79
|
-
|
|
94
|
+
var _TouchEvent;
|
|
95
|
+
const TouchEvent = (_TouchEvent = window.TouchEvent) !== null && _TouchEvent !== void 0 ? _TouchEvent : class TouchEvent extends UIEvent {
|
|
80
96
|
};
|
|
81
97
|
/* eslint-enable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-extraneous-class */ return {
|
|
82
98
|
Event,
|
|
@@ -99,12 +115,12 @@ function createEvent(type, target, init) {
|
|
|
99
115
|
function assignProps(obj, props) {
|
|
100
116
|
for (const [key, value] of Object.entries(props)){
|
|
101
117
|
Object.defineProperty(obj, key, {
|
|
102
|
-
get: ()=>value
|
|
118
|
+
get: ()=>value !== null && value !== void 0 ? value : null
|
|
103
119
|
});
|
|
104
120
|
}
|
|
105
121
|
}
|
|
106
122
|
function sanitizeNumber(n) {
|
|
107
|
-
return Number(n
|
|
123
|
+
return Number(n !== null && n !== void 0 ? n : 0);
|
|
108
124
|
}
|
|
109
125
|
function initClipboardEvent(event, { clipboardData }) {
|
|
110
126
|
assignProps(event, {
|
|
@@ -121,7 +137,7 @@ function initInputEvent(event, { data , inputType , isComposing }) {
|
|
|
121
137
|
function initUIEvent(event, { view , detail }) {
|
|
122
138
|
assignProps(event, {
|
|
123
139
|
view,
|
|
124
|
-
detail: sanitizeNumber(detail
|
|
140
|
+
detail: sanitizeNumber(detail !== null && detail !== void 0 ? detail : 0)
|
|
125
141
|
});
|
|
126
142
|
}
|
|
127
143
|
function initUIEventModififiers(event, { altKey , ctrlKey , metaKey , shiftKey , modifierAltGraph , modifierCapsLock , modifierFn , modifierFnLock , modifierNumLock , modifierScrollLock , modifierSymbol , modifierSymbolLock }) {
|
|
@@ -8,8 +8,9 @@ import { behavior } from './behavior/registry.js';
|
|
|
8
8
|
import { wrapEvent } from './wrapEvent.js';
|
|
9
9
|
|
|
10
10
|
function dispatchEvent(config, target, event, preventDefault = false) {
|
|
11
|
+
var ref;
|
|
11
12
|
const type = event.type;
|
|
12
|
-
const behaviorImplementation = preventDefault ? ()=>{} : behavior[type]
|
|
13
|
+
const behaviorImplementation = preventDefault ? ()=>{} : (ref = behavior[type]) === null || ref === void 0 ? void 0 : ref(event, target, config);
|
|
13
14
|
if (behaviorImplementation) {
|
|
14
15
|
event.preventDefault();
|
|
15
16
|
let defaultPrevented = false;
|
|
@@ -28,14 +28,17 @@ import '../options.js';
|
|
|
28
28
|
const defs = [];
|
|
29
29
|
do {
|
|
30
30
|
const { type , descriptor , consumedLength , releasePrevious , releaseSelf =true , repeat , } = readNextDescriptor(text, 'keyboard');
|
|
31
|
-
|
|
31
|
+
var ref;
|
|
32
|
+
const keyDef = (ref = keyboardMap.find((def)=>{
|
|
32
33
|
if (type === '[') {
|
|
33
|
-
|
|
34
|
+
var ref;
|
|
35
|
+
return ((ref = def.code) === null || ref === void 0 ? void 0 : ref.toLowerCase()) === descriptor.toLowerCase();
|
|
34
36
|
} else if (type === '{') {
|
|
35
|
-
|
|
37
|
+
var ref1;
|
|
38
|
+
return ((ref1 = def.key) === null || ref1 === void 0 ? void 0 : ref1.toLowerCase()) === descriptor.toLowerCase();
|
|
36
39
|
}
|
|
37
40
|
return def.key === descriptor;
|
|
38
|
-
})
|
|
41
|
+
})) !== null && ref !== void 0 ? ref : {
|
|
39
42
|
key: 'Unknown',
|
|
40
43
|
code: 'Unknown',
|
|
41
44
|
[type === '[' ? 'code' : 'key']: descriptor
|
|
@@ -43,14 +43,16 @@ async function pointer(input) {
|
|
|
43
43
|
this[Config].system.pointer.resetClickCount();
|
|
44
44
|
}
|
|
45
45
|
async function pointerAction(config, action) {
|
|
46
|
+
var ref, ref1;
|
|
46
47
|
const pointerName = 'pointerName' in action && action.pointerName ? action.pointerName : 'keyDef' in action ? config.system.pointer.getPointerName(action.keyDef) : 'mouse';
|
|
47
48
|
const previousPosition = config.system.pointer.getPreviousPosition(pointerName);
|
|
49
|
+
var _target, _coords, _node, _offset;
|
|
48
50
|
const position = {
|
|
49
|
-
target: action.target
|
|
50
|
-
coords: action.coords
|
|
51
|
+
target: (_target = action.target) !== null && _target !== void 0 ? _target : getPrevTarget(config, previousPosition),
|
|
52
|
+
coords: (_coords = action.coords) !== null && _coords !== void 0 ? _coords : previousPosition === null || previousPosition === void 0 ? void 0 : previousPosition.coords,
|
|
51
53
|
caret: {
|
|
52
|
-
node: action.node
|
|
53
|
-
offset: action.offset
|
|
54
|
+
node: (_node = action.node) !== null && _node !== void 0 ? _node : hasCaretPosition(action) ? undefined : previousPosition === null || previousPosition === void 0 ? void 0 : (ref = previousPosition.caret) === null || ref === void 0 ? void 0 : ref.node,
|
|
55
|
+
offset: (_offset = action.offset) !== null && _offset !== void 0 ? _offset : hasCaretPosition(action) ? undefined : previousPosition === null || previousPosition === void 0 ? void 0 : (ref1 = previousPosition.caret) === null || ref1 === void 0 ? void 0 : ref1.offset
|
|
54
56
|
}
|
|
55
57
|
};
|
|
56
58
|
if ('keyDef' in action) {
|
|
@@ -72,13 +74,15 @@ async function pointerAction(config, action) {
|
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
function hasCaretPosition(action) {
|
|
75
|
-
|
|
77
|
+
var _target, ref;
|
|
78
|
+
return !!((ref = (_target = action.target) !== null && _target !== void 0 ? _target : action.node) !== null && ref !== void 0 ? ref : action.offset !== undefined);
|
|
76
79
|
}
|
|
77
80
|
function getPrevTarget(config, position) {
|
|
78
81
|
if (!position) {
|
|
79
82
|
throw new Error('This pointer has no previous position. Provide a target property!');
|
|
80
83
|
}
|
|
81
|
-
|
|
84
|
+
var _target;
|
|
85
|
+
return (_target = position.target) !== null && _target !== void 0 ? _target : config.document.body;
|
|
82
86
|
}
|
|
83
87
|
|
|
84
88
|
export { pointer };
|