@testing-library/user-event 14.6.1 → 14.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -16
- package/dist/cjs/clipboard/copy.js +2 -2
- package/dist/cjs/clipboard/cut.js +2 -2
- package/dist/cjs/clipboard/paste.js +3 -4
- package/dist/cjs/document/UI.js +5 -7
- package/dist/cjs/document/interceptor.js +4 -4
- package/dist/cjs/document/patchFocus.js +5 -3
- package/dist/cjs/document/trackValue.js +2 -2
- package/dist/cjs/event/behavior/keydown.js +4 -4
- package/dist/cjs/event/behavior/keypress.js +1 -1
- package/dist/cjs/event/behavior/keyup.js +1 -1
- package/dist/cjs/event/behavior/paste.js +1 -1
- package/dist/cjs/event/createEvent.js +25 -39
- package/dist/cjs/event/dispatchEvent.js +1 -1
- package/dist/cjs/event/focus.js +3 -3
- package/dist/cjs/event/input.js +3 -2
- package/dist/cjs/event/selection/getInputRange.js +1 -1
- package/dist/cjs/event/selection/getTargetTypeAndSelection.js +2 -2
- package/dist/cjs/event/selection/modifySelection.js +1 -1
- package/dist/cjs/event/selection/modifySelectionPerMouse.js +2 -2
- package/dist/cjs/event/selection/moveSelection.js +1 -1
- package/dist/cjs/event/selection/resolveCaretPosition.js +4 -5
- package/dist/cjs/event/selection/selectAll.js +5 -5
- package/dist/cjs/event/selection/setSelection.js +1 -1
- package/dist/cjs/event/selection/setSelectionPerMouse.js +9 -11
- package/dist/cjs/event/selection/setSelectionRange.js +1 -1
- package/dist/cjs/event/selection/updateSelectionOnFocus.js +2 -2
- package/dist/cjs/event/wrapEvent.js +2 -1
- package/dist/cjs/keyboard/index.js +1 -1
- package/dist/cjs/keyboard/parseKeyDef.js +4 -4
- package/dist/cjs/pointer/index.js +9 -9
- package/dist/cjs/setup/api.js +4 -4
- package/dist/cjs/setup/setup.js +10 -10
- package/dist/cjs/system/index.js +1 -3
- package/dist/cjs/system/keyboard.js +8 -11
- package/dist/cjs/system/pointer/buttons.js +1 -5
- package/dist/cjs/system/pointer/device.js +1 -3
- package/dist/cjs/system/pointer/index.js +19 -22
- package/dist/cjs/system/pointer/mouse.js +10 -13
- package/dist/cjs/system/pointer/pointer.js +6 -8
- package/dist/cjs/system/pointer/shared.js +1 -1
- package/dist/cjs/utility/type.js +1 -1
- package/dist/cjs/utility/upload.js +3 -3
- package/dist/cjs/utils/dataTransfer/Clipboard.js +14 -9
- package/dist/cjs/utils/dataTransfer/DataTransfer.js +5 -7
- package/dist/cjs/utils/edit/isContentEditable.js +1 -1
- package/dist/cjs/utils/edit/maxLength.js +1 -1
- package/dist/cjs/utils/edit/setFiles.js +2 -3
- package/dist/cjs/utils/focus/cursor.js +1 -1
- package/dist/cjs/utils/focus/getActiveElement.js +10 -8
- package/dist/cjs/utils/focus/selector.js +2 -1
- package/dist/cjs/utils/keyDef/readNextDescriptor.js +8 -9
- package/dist/cjs/utils/misc/getWindow.js +1 -1
- package/dist/cjs/utils/misc/isDisabled.js +1 -1
- package/dist/cjs/utils/misc/isVisible.js +1 -1
- package/dist/cjs/utils/pointer/cssPointerEvents.js +11 -12
- package/dist/esm/clipboard/copy.js +2 -2
- package/dist/esm/clipboard/cut.js +2 -2
- package/dist/esm/clipboard/paste.js +3 -4
- package/dist/esm/document/UI.js +5 -7
- package/dist/esm/document/interceptor.js +5 -5
- package/dist/esm/document/patchFocus.js +5 -3
- package/dist/esm/document/trackValue.js +3 -3
- package/dist/esm/event/behavior/keydown.js +5 -5
- package/dist/esm/event/behavior/keypress.js +1 -1
- package/dist/esm/event/behavior/keyup.js +1 -1
- package/dist/esm/event/behavior/paste.js +1 -1
- package/dist/esm/event/createEvent.js +25 -39
- package/dist/esm/event/dispatchEvent.js +1 -1
- package/dist/esm/event/focus.js +3 -3
- package/dist/esm/event/input.js +3 -2
- package/dist/esm/event/selection/getInputRange.js +1 -1
- package/dist/esm/event/selection/getTargetTypeAndSelection.js +2 -2
- package/dist/esm/event/selection/modifySelection.js +1 -1
- package/dist/esm/event/selection/modifySelectionPerMouse.js +2 -2
- package/dist/esm/event/selection/moveSelection.js +1 -1
- package/dist/esm/event/selection/resolveCaretPosition.js +4 -5
- package/dist/esm/event/selection/selectAll.js +6 -6
- package/dist/esm/event/selection/setSelection.js +1 -1
- package/dist/esm/event/selection/setSelectionPerMouse.js +9 -11
- package/dist/esm/event/selection/setSelectionRange.js +1 -1
- package/dist/esm/event/selection/updateSelectionOnFocus.js +2 -2
- package/dist/esm/event/wrapEvent.js +2 -1
- package/dist/esm/keyboard/index.js +1 -1
- package/dist/esm/keyboard/parseKeyDef.js +4 -4
- package/dist/esm/pointer/index.js +9 -9
- package/dist/esm/setup/api.js +3 -3
- package/dist/esm/setup/setup.js +11 -11
- package/dist/esm/system/index.js +1 -3
- package/dist/esm/system/keyboard.js +8 -11
- package/dist/esm/system/pointer/buttons.js +1 -5
- package/dist/esm/system/pointer/device.js +1 -3
- package/dist/esm/system/pointer/index.js +19 -22
- package/dist/esm/system/pointer/mouse.js +10 -13
- package/dist/esm/system/pointer/pointer.js +6 -8
- package/dist/esm/system/pointer/shared.js +1 -1
- package/dist/esm/utility/type.js +1 -1
- package/dist/esm/utility/upload.js +3 -3
- package/dist/esm/utils/dataTransfer/Clipboard.js +14 -9
- package/dist/esm/utils/dataTransfer/DataTransfer.js +5 -7
- package/dist/esm/utils/edit/isContentEditable.js +1 -1
- package/dist/esm/utils/edit/maxLength.js +1 -1
- package/dist/esm/utils/edit/setFiles.js +2 -3
- package/dist/esm/utils/focus/cursor.js +1 -1
- package/dist/esm/utils/focus/getActiveElement.js +10 -8
- package/dist/esm/utils/focus/selector.js +2 -1
- package/dist/esm/utils/keyDef/readNextDescriptor.js +8 -9
- package/dist/esm/utils/misc/getWindow.js +1 -1
- package/dist/esm/utils/misc/isDisabled.js +1 -1
- package/dist/esm/utils/misc/isVisible.js +1 -1
- package/dist/esm/utils/pointer/cssPointerEvents.js +11 -12
- package/dist/types/document/UI.d.ts +3 -3
- package/dist/types/event/behavior/registry.d.ts +1 -2
- package/dist/types/options.d.ts +1 -1
- package/dist/types/system/keyboard.d.ts +1 -1
- package/package.json +6 -3
|
@@ -4,7 +4,6 @@ var getWindow = require('../misc/getWindow.js');
|
|
|
4
4
|
var Blob = require('./Blob.js');
|
|
5
5
|
var DataTransfer = require('./DataTransfer.js');
|
|
6
6
|
|
|
7
|
-
// Clipboard is not available in jsdom
|
|
8
7
|
function _define_property(obj, key, value) {
|
|
9
8
|
if (key in obj) {
|
|
10
9
|
Object.defineProperty(obj, key, {
|
|
@@ -13,9 +12,7 @@ function _define_property(obj, key, value) {
|
|
|
13
12
|
configurable: true,
|
|
14
13
|
writable: true
|
|
15
14
|
});
|
|
16
|
-
} else
|
|
17
|
-
obj[key] = value;
|
|
18
|
-
}
|
|
15
|
+
} else obj[key] = value;
|
|
19
16
|
return obj;
|
|
20
17
|
}
|
|
21
18
|
// MDN lists string|Blob|Promise<Blob|string> as possible types in ClipboardItemData
|
|
@@ -46,7 +43,7 @@ function createClipboardItem(window, ...blobs) {
|
|
|
46
43
|
});
|
|
47
44
|
}
|
|
48
45
|
constructor(d){
|
|
49
|
-
_define_property(this, "data",
|
|
46
|
+
_define_property(this, "data", void 0);
|
|
50
47
|
this.data = d;
|
|
51
48
|
}
|
|
52
49
|
}(dataMap);
|
|
@@ -83,7 +80,7 @@ function createClipboardStub(window, control) {
|
|
|
83
80
|
});
|
|
84
81
|
}
|
|
85
82
|
function isClipboardStub(clipboard) {
|
|
86
|
-
return !!(clipboard === null || clipboard ===
|
|
83
|
+
return !!(clipboard === null || clipboard === void 0 ? void 0 : clipboard[ClipboardStubControl]);
|
|
87
84
|
}
|
|
88
85
|
function attachClipboardStubToView(window) {
|
|
89
86
|
if (isClipboardStub(window.navigator.clipboard)) {
|
|
@@ -125,7 +122,7 @@ function detachClipboardStubFromView(window) {
|
|
|
125
122
|
}
|
|
126
123
|
async function readDataTransferFromClipboard(document) {
|
|
127
124
|
const window = document.defaultView;
|
|
128
|
-
const clipboard = window === null || window ===
|
|
125
|
+
const clipboard = window === null || window === void 0 ? void 0 : window.navigator.clipboard;
|
|
129
126
|
const items = clipboard && await clipboard.read();
|
|
130
127
|
if (!items) {
|
|
131
128
|
throw new Error('The Clipboard API is unavailable.');
|
|
@@ -155,10 +152,18 @@ async function writeDataTransferToClipboard(document, clipboardData) {
|
|
|
155
152
|
}
|
|
156
153
|
const g = globalThis;
|
|
157
154
|
/* istanbul ignore else */ if (typeof g.afterEach === 'function') {
|
|
158
|
-
g.afterEach(()=>
|
|
155
|
+
g.afterEach(()=>{
|
|
156
|
+
if (typeof globalThis.window !== 'undefined') {
|
|
157
|
+
resetClipboardStubOnView(globalThis.window);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
159
160
|
}
|
|
160
161
|
/* istanbul ignore else */ if (typeof g.afterAll === 'function') {
|
|
161
|
-
g.afterAll(()=>
|
|
162
|
+
g.afterAll(()=>{
|
|
163
|
+
if (typeof globalThis.window !== 'undefined') {
|
|
164
|
+
detachClipboardStubFromView(globalThis.window);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
162
167
|
}
|
|
163
168
|
|
|
164
169
|
exports.attachClipboardStubToView = attachClipboardStubToView;
|
|
@@ -10,9 +10,7 @@ function _define_property(obj, key, value) {
|
|
|
10
10
|
configurable: true,
|
|
11
11
|
writable: true
|
|
12
12
|
});
|
|
13
|
-
} else
|
|
14
|
-
obj[key] = value;
|
|
15
|
-
}
|
|
13
|
+
} else obj[key] = value;
|
|
16
14
|
return obj;
|
|
17
15
|
}
|
|
18
16
|
// DataTransfer is not implemented in jsdom.
|
|
@@ -30,8 +28,8 @@ class DataTransferItemStub {
|
|
|
30
28
|
throw new Error('not implemented');
|
|
31
29
|
}
|
|
32
30
|
constructor(dataOrFile, type){
|
|
33
|
-
_define_property(this, "kind",
|
|
34
|
-
_define_property(this, "type",
|
|
31
|
+
_define_property(this, "kind", void 0);
|
|
32
|
+
_define_property(this, "type", void 0);
|
|
35
33
|
_define_property(this, "file", null);
|
|
36
34
|
_define_property(this, "data", undefined);
|
|
37
35
|
if (typeof dataOrFile === 'string') {
|
|
@@ -69,9 +67,9 @@ function createDataTransferStub(window) {
|
|
|
69
67
|
return new class DataTransferStub {
|
|
70
68
|
getData(format) {
|
|
71
69
|
var _this_items_find;
|
|
72
|
-
const match = (_this_items_find = this.items.find(getTypeMatcher(format, true))) !== null && _this_items_find !==
|
|
70
|
+
const match = (_this_items_find = this.items.find(getTypeMatcher(format, true))) !== null && _this_items_find !== void 0 ? _this_items_find : this.items.find(getTypeMatcher(format, false));
|
|
73
71
|
let text = '';
|
|
74
|
-
match === null || match ===
|
|
72
|
+
match === null || match === void 0 ? void 0 : match.getAsString((t)=>{
|
|
75
73
|
text = t;
|
|
76
74
|
});
|
|
77
75
|
return text;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
//jsdom is not supporting isContentEditable
|
|
3
|
+
// jsdom is not supporting isContentEditable
|
|
4
4
|
function isContentEditable(element) {
|
|
5
5
|
return element.hasAttribute('contenteditable') && (element.getAttribute('contenteditable') == 'true' || element.getAttribute('contenteditable') == '');
|
|
6
6
|
}
|
|
@@ -15,7 +15,7 @@ var maxLengthSupportedTypes = /*#__PURE__*/ function(maxLengthSupportedTypes) {
|
|
|
15
15
|
// https://github.com/jsdom/jsdom/issues/2927
|
|
16
16
|
function getMaxLength(element) {
|
|
17
17
|
var _element_getAttribute;
|
|
18
|
-
const attr = (_element_getAttribute = element.getAttribute('maxlength')) !== null && _element_getAttribute !==
|
|
18
|
+
const attr = (_element_getAttribute = element.getAttribute('maxlength')) !== null && _element_getAttribute !== void 0 ? _element_getAttribute : '';
|
|
19
19
|
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : undefined;
|
|
20
20
|
}
|
|
21
21
|
function supportsMaxLength(element) {
|
|
@@ -8,13 +8,12 @@ function restoreProperty(obj, prop, descriptor) {
|
|
|
8
8
|
if (descriptor) {
|
|
9
9
|
Object.defineProperty(obj, prop, descriptor);
|
|
10
10
|
} else {
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
12
11
|
delete obj[prop];
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
14
|
function setFiles(el, files) {
|
|
16
15
|
var _el_fakeFiles;
|
|
17
|
-
(_el_fakeFiles = el[fakeFiles]) === null || _el_fakeFiles ===
|
|
16
|
+
(_el_fakeFiles = el[fakeFiles]) === null || _el_fakeFiles === void 0 ? void 0 : _el_fakeFiles.restore();
|
|
18
17
|
const typeDescr = Object.getOwnPropertyDescriptor(el, 'type');
|
|
19
18
|
const valueDescr = Object.getOwnPropertyDescriptor(el, 'value');
|
|
20
19
|
const filesDescr = Object.getOwnPropertyDescriptor(el, 'files');
|
|
@@ -39,7 +38,7 @@ function setFiles(el, files) {
|
|
|
39
38
|
restore();
|
|
40
39
|
} else {
|
|
41
40
|
var _valueDescr_set;
|
|
42
|
-
valueDescr === null || valueDescr ===
|
|
41
|
+
valueDescr === null || valueDescr === void 0 ? void 0 : (_valueDescr_set = valueDescr.set) === null || _valueDescr_set === void 0 ? void 0 : _valueDescr_set.call(el, v);
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
44
|
},
|
|
@@ -109,7 +109,7 @@ function walkNodes(node, direction, callback) {
|
|
|
109
109
|
if (callback(node)) {
|
|
110
110
|
return node;
|
|
111
111
|
}
|
|
112
|
-
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable.isContentEditable(node.parentNode) && node.parentNode !== ((_node_ownerDocument = node.ownerDocument) === null || _node_ownerDocument ===
|
|
112
|
+
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable.isContentEditable(node.parentNode) && node.parentNode !== ((_node_ownerDocument = node.ownerDocument) === null || _node_ownerDocument === void 0 ? void 0 : _node_ownerDocument.body))) {
|
|
113
113
|
node = node.parentNode;
|
|
114
114
|
} else {
|
|
115
115
|
break;
|
|
@@ -4,19 +4,21 @@ var isDisabled = require('../misc/isDisabled.js');
|
|
|
4
4
|
|
|
5
5
|
function getActiveElement(document) {
|
|
6
6
|
const activeElement = document.activeElement;
|
|
7
|
-
if (activeElement === null || activeElement ===
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (isDisabled.isDisabled(activeElement)) {
|
|
12
|
-
return document.ownerDocument ? /* istanbul ignore next */ document.ownerDocument.body : document.body;
|
|
7
|
+
if (activeElement === null || activeElement === void 0 ? void 0 : activeElement.shadowRoot) {
|
|
8
|
+
const activeElementInShadowTree = getActiveElement(activeElement.shadowRoot);
|
|
9
|
+
if (activeElementInShadowTree) {
|
|
10
|
+
return activeElementInShadowTree;
|
|
13
11
|
}
|
|
14
|
-
return activeElement;
|
|
15
12
|
}
|
|
13
|
+
// Browser does not yield disabled elements as document.activeElement - jsdom does
|
|
14
|
+
if (isDisabled.isDisabled(activeElement)) {
|
|
15
|
+
return document.ownerDocument ? /* istanbul ignore next */ document.ownerDocument.body : document.body;
|
|
16
|
+
}
|
|
17
|
+
return activeElement;
|
|
16
18
|
}
|
|
17
19
|
function getActiveElementOrBody(document) {
|
|
18
20
|
var _getActiveElement;
|
|
19
|
-
return (_getActiveElement = getActiveElement(document)) !== null && _getActiveElement !==
|
|
21
|
+
return (_getActiveElement = getActiveElement(document)) !== null && _getActiveElement !== void 0 ? _getActiveElement : /* istanbul ignore next */ document.body;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
exports.getActiveElement = getActiveElement;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}(bracketDict || {});
|
|
3
|
+
const bracketDict = {
|
|
4
|
+
'{': '}',
|
|
5
|
+
'[': ']'
|
|
6
|
+
};
|
|
8
7
|
/**
|
|
9
8
|
* Read the next key definition from user input
|
|
10
9
|
*
|
|
@@ -39,16 +38,16 @@ function readPrintableChar(text, pos, context) {
|
|
|
39
38
|
};
|
|
40
39
|
}
|
|
41
40
|
function readTag(text, pos, startBracket, context) {
|
|
41
|
+
var _ref;
|
|
42
42
|
var _text_slice_match, _text_slice_match1;
|
|
43
43
|
const releasePreviousModifier = text[pos] === '/' ? '/' : '';
|
|
44
44
|
pos += releasePreviousModifier.length;
|
|
45
45
|
const escapedDescriptor = startBracket === '{' && text[pos] === '\\';
|
|
46
46
|
pos += Number(escapedDescriptor);
|
|
47
|
-
const descriptor = escapedDescriptor ? text[pos] : (_text_slice_match = text.slice(pos).match(startBracket === '{' ? /^\w+|^[^}>/]/ : /^\w+/)) === null || _text_slice_match ===
|
|
47
|
+
const descriptor = escapedDescriptor ? text[pos] : (_text_slice_match = text.slice(pos).match(startBracket === '{' ? /^\w+|^[^}>/]/ : /^\w+/)) === null || _text_slice_match === void 0 ? void 0 : _text_slice_match[0];
|
|
48
48
|
assertDescriptor(descriptor, text, pos, context);
|
|
49
49
|
pos += descriptor.length;
|
|
50
|
-
|
|
51
|
-
const repeatModifier = (_text_slice_match_ = (_text_slice_match1 = text.slice(pos).match(/^>\d+/)) === null || _text_slice_match1 === undefined ? undefined : _text_slice_match1[0]) !== null && _text_slice_match_ !== undefined ? _text_slice_match_ : '';
|
|
50
|
+
const repeatModifier = (_ref = (_text_slice_match1 = text.slice(pos).match(/^>\d+/)) === null || _text_slice_match1 === void 0 ? void 0 : _text_slice_match1[0]) !== null && _ref !== void 0 ? _ref : '';
|
|
52
51
|
pos += repeatModifier.length;
|
|
53
52
|
const releaseSelfModifier = text[pos] === '/' || !repeatModifier && text[pos] === '>' ? text[pos] : '';
|
|
54
53
|
pos += releaseSelfModifier.length;
|
|
@@ -84,7 +83,7 @@ function hasReleaseSelf(releaseSelfModifier, repeatModifier) {
|
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
85
|
function getErrorMessage(expected, found, text, context) {
|
|
87
|
-
return `Expected ${expected} but found "${found !== null && found !==
|
|
86
|
+
return `Expected ${expected} but found "${found !== null && found !== void 0 ? found : ''}" in "${text}"
|
|
88
87
|
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
88
|
for more information about how userEvent parses your input.`;
|
|
90
89
|
}
|
|
@@ -4,7 +4,7 @@ function getWindow(node) {
|
|
|
4
4
|
var _node_ownerDocument;
|
|
5
5
|
if (isDocument(node) && node.defaultView) {
|
|
6
6
|
return node.defaultView;
|
|
7
|
-
} else if ((_node_ownerDocument = node.ownerDocument) === null || _node_ownerDocument ===
|
|
7
|
+
} else if ((_node_ownerDocument = node.ownerDocument) === null || _node_ownerDocument === void 0 ? void 0 : _node_ownerDocument.defaultView) {
|
|
8
8
|
return node.ownerDocument.defaultView;
|
|
9
9
|
}
|
|
10
10
|
throw new Error(`Could not determine window of node. Node was ${describe(node)}`);
|
|
@@ -18,7 +18,7 @@ function isDisabled(element) {
|
|
|
18
18
|
}
|
|
19
19
|
} else if (isElementType.isElementType(el, 'fieldset')) {
|
|
20
20
|
var _el_querySelector;
|
|
21
|
-
if (el.hasAttribute('disabled') && !((_el_querySelector = el.querySelector(':scope > legend')) === null || _el_querySelector ===
|
|
21
|
+
if (el.hasAttribute('disabled') && !((_el_querySelector = el.querySelector(':scope > legend')) === null || _el_querySelector === void 0 ? void 0 : _el_querySelector.contains(element))) {
|
|
22
22
|
return true;
|
|
23
23
|
}
|
|
24
24
|
} else if (el.tagName.includes('-')) {
|
|
@@ -4,7 +4,7 @@ var getWindow = require('./getWindow.js');
|
|
|
4
4
|
|
|
5
5
|
function isVisible(element) {
|
|
6
6
|
const window = getWindow.getWindow(element);
|
|
7
|
-
for(let el = element; el === null || el ===
|
|
7
|
+
for(let el = element; el === null || el === void 0 ? void 0 : el.ownerDocument; el = el.parentElement){
|
|
8
8
|
const { display, visibility } = window.getComputedStyle(el);
|
|
9
9
|
if (display === 'none') {
|
|
10
10
|
return false;
|
|
@@ -7,11 +7,11 @@ var level = require('../misc/level.js');
|
|
|
7
7
|
|
|
8
8
|
function hasPointerEvents(instance, element) {
|
|
9
9
|
var _checkPointerEvents;
|
|
10
|
-
return ((_checkPointerEvents = checkPointerEvents(instance, element)) === null || _checkPointerEvents ===
|
|
10
|
+
return ((_checkPointerEvents = checkPointerEvents(instance, element)) === null || _checkPointerEvents === void 0 ? void 0 : _checkPointerEvents.pointerEvents) !== 'none';
|
|
11
11
|
}
|
|
12
12
|
function closestPointerEventsDeclaration(element) {
|
|
13
13
|
const window = getWindow.getWindow(element);
|
|
14
|
-
for(let el = element, tree = []; el === null || el ===
|
|
14
|
+
for(let el = element, tree = []; el === null || el === void 0 ? void 0 : el.ownerDocument; el = el.parentElement){
|
|
15
15
|
tree.push(el);
|
|
16
16
|
const pointerEvents = window.getComputedStyle(el).pointerEvents;
|
|
17
17
|
if (pointerEvents && ![
|
|
@@ -31,7 +31,7 @@ function checkPointerEvents(instance, element) {
|
|
|
31
31
|
const lastCheck = element[PointerEventsCheck];
|
|
32
32
|
const needsCheck = instance.config.pointerEventsCheck !== options.PointerEventsCheckLevel.Never && (!lastCheck || hasBitFlag(instance.config.pointerEventsCheck, options.PointerEventsCheckLevel.EachApiCall) && lastCheck[level.ApiLevel.Call] !== level.getLevelRef(instance, level.ApiLevel.Call) || hasBitFlag(instance.config.pointerEventsCheck, options.PointerEventsCheckLevel.EachTrigger) && lastCheck[level.ApiLevel.Trigger] !== level.getLevelRef(instance, level.ApiLevel.Trigger));
|
|
33
33
|
if (!needsCheck) {
|
|
34
|
-
return lastCheck === null || lastCheck ===
|
|
34
|
+
return lastCheck === null || lastCheck === void 0 ? void 0 : lastCheck.result;
|
|
35
35
|
}
|
|
36
36
|
const declaration = closestPointerEventsDeclaration(element);
|
|
37
37
|
element[PointerEventsCheck] = {
|
|
@@ -43,7 +43,7 @@ function checkPointerEvents(instance, element) {
|
|
|
43
43
|
}
|
|
44
44
|
function assertPointerEvents(instance, element) {
|
|
45
45
|
const declaration = checkPointerEvents(instance, element);
|
|
46
|
-
if ((declaration === null || declaration ===
|
|
46
|
+
if ((declaration === null || declaration === void 0 ? void 0 : declaration.pointerEvents) === 'none') {
|
|
47
47
|
throw new Error([
|
|
48
48
|
`Unable to perform pointer interaction as the element ${declaration.tree.length > 1 ? 'inherits' : 'has'} \`pointer-events: none\`:`,
|
|
49
49
|
'',
|
|
@@ -69,7 +69,7 @@ function getLabelDescr(element) {
|
|
|
69
69
|
label = element.getAttribute('aria-label');
|
|
70
70
|
} else if (element.hasAttribute('aria-labelledby')) {
|
|
71
71
|
var _element_ownerDocument_getElementById_textContent, _element_ownerDocument_getElementById;
|
|
72
|
-
label = (_element_ownerDocument_getElementById = element.ownerDocument.getElementById(element.getAttribute('aria-labelledby'))) === null || _element_ownerDocument_getElementById ===
|
|
72
|
+
label = (_element_ownerDocument_getElementById = element.ownerDocument.getElementById(element.getAttribute('aria-labelledby'))) === null || _element_ownerDocument_getElementById === void 0 ? void 0 : (_element_ownerDocument_getElementById_textContent = _element_ownerDocument_getElementById.textContent) === null || _element_ownerDocument_getElementById_textContent === void 0 ? void 0 : _element_ownerDocument_getElementById_textContent.trim();
|
|
73
73
|
} else if (isElementType.isElementType(element, [
|
|
74
74
|
'button',
|
|
75
75
|
'input',
|
|
@@ -78,24 +78,23 @@ function getLabelDescr(element) {
|
|
|
78
78
|
'progress',
|
|
79
79
|
'select',
|
|
80
80
|
'textarea'
|
|
81
|
-
]) && ((_element_labels = element.labels) === null || _element_labels ===
|
|
81
|
+
]) && ((_element_labels = element.labels) === null || _element_labels === void 0 ? void 0 : _element_labels.length)) {
|
|
82
82
|
label = Array.from(element.labels).map((el)=>{
|
|
83
83
|
var _el_textContent;
|
|
84
|
-
return (_el_textContent = el.textContent) === null || _el_textContent ===
|
|
84
|
+
return (_el_textContent = el.textContent) === null || _el_textContent === void 0 ? void 0 : _el_textContent.trim();
|
|
85
85
|
}).join('|');
|
|
86
86
|
} else if (isElementType.isElementType(element, 'button')) {
|
|
87
87
|
var _element_textContent;
|
|
88
|
-
label = (_element_textContent = element.textContent) === null || _element_textContent ===
|
|
88
|
+
label = (_element_textContent = element.textContent) === null || _element_textContent === void 0 ? void 0 : _element_textContent.trim();
|
|
89
89
|
}
|
|
90
|
-
label = label === null || label ===
|
|
91
|
-
if (Number(label === null || label ===
|
|
92
|
-
label = `${label === null || label ===
|
|
90
|
+
label = label === null || label === void 0 ? void 0 : label.replace(/\n/g, ' ');
|
|
91
|
+
if (Number(label === null || label === void 0 ? void 0 : label.length) > 30) {
|
|
92
|
+
label = `${label === null || label === void 0 ? void 0 : label.substring(0, 29)}…`;
|
|
93
93
|
}
|
|
94
94
|
return label ? `(label=${label})` : '';
|
|
95
95
|
}
|
|
96
96
|
// With the eslint rule and prettier the bitwise operation isn't nice to read
|
|
97
97
|
function hasBitFlag(conf, flag) {
|
|
98
|
-
// eslint-disable-next-line no-bitwise
|
|
99
98
|
return (conf & flag) > 0;
|
|
100
99
|
}
|
|
101
100
|
|
|
@@ -2,9 +2,9 @@ import { writeDataTransferToClipboard } from '../utils/dataTransfer/Clipboard.js
|
|
|
2
2
|
import { copySelection } from '../document/copySelection.js';
|
|
3
3
|
|
|
4
4
|
async function copy() {
|
|
5
|
-
const doc = this.config.document;
|
|
6
5
|
var _doc_activeElement;
|
|
7
|
-
const
|
|
6
|
+
const doc = this.config.document;
|
|
7
|
+
const target = (_doc_activeElement = doc.activeElement) !== null && _doc_activeElement !== void 0 ? _doc_activeElement : /* istanbul ignore next */ doc.body;
|
|
8
8
|
const clipboardData = copySelection(target);
|
|
9
9
|
if (clipboardData.items.length === 0) {
|
|
10
10
|
return;
|
|
@@ -2,9 +2,9 @@ import { writeDataTransferToClipboard } from '../utils/dataTransfer/Clipboard.js
|
|
|
2
2
|
import { copySelection } from '../document/copySelection.js';
|
|
3
3
|
|
|
4
4
|
async function cut() {
|
|
5
|
-
const doc = this.config.document;
|
|
6
5
|
var _doc_activeElement;
|
|
7
|
-
const
|
|
6
|
+
const doc = this.config.document;
|
|
7
|
+
const target = (_doc_activeElement = doc.activeElement) !== null && _doc_activeElement !== void 0 ? _doc_activeElement : /* istanbul ignore next */ doc.body;
|
|
8
8
|
const clipboardData = copySelection(target);
|
|
9
9
|
if (clipboardData.items.length === 0) {
|
|
10
10
|
return;
|
|
@@ -3,11 +3,10 @@ import { readDataTransferFromClipboard } from '../utils/dataTransfer/Clipboard.j
|
|
|
3
3
|
import { getWindow } from '../utils/misc/getWindow.js';
|
|
4
4
|
|
|
5
5
|
async function paste(clipboardData) {
|
|
6
|
+
var _doc_activeElement, _ref;
|
|
6
7
|
const doc = this.config.document;
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
var _ref;
|
|
10
|
-
const dataTransfer = (_ref = typeof clipboardData === 'string' ? getClipboardDataFromString(doc, clipboardData) : clipboardData) !== null && _ref !== undefined ? _ref : await readDataTransferFromClipboard(doc).catch(()=>{
|
|
8
|
+
const target = (_doc_activeElement = doc.activeElement) !== null && _doc_activeElement !== void 0 ? _doc_activeElement : /* istanbul ignore next */ doc.body;
|
|
9
|
+
const dataTransfer = (_ref = typeof clipboardData === 'string' ? getClipboardDataFromString(doc, clipboardData) : clipboardData) !== null && _ref !== void 0 ? _ref : await readDataTransferFromClipboard(doc).catch(()=>{
|
|
11
10
|
throw new Error('`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.');
|
|
12
11
|
});
|
|
13
12
|
this.dispatchUIEvent(target, 'paste', {
|
package/dist/esm/document/UI.js
CHANGED
|
@@ -12,7 +12,6 @@ function setUIValue(element, value) {
|
|
|
12
12
|
element[InitialValue] = element.value;
|
|
13
13
|
}
|
|
14
14
|
element[UIValue] = value;
|
|
15
|
-
// eslint-disable-next-line no-new-wrappers
|
|
16
15
|
element.value = Object.assign(new String(value), {
|
|
17
16
|
[UIValue]: true
|
|
18
17
|
});
|
|
@@ -20,7 +19,7 @@ function setUIValue(element, value) {
|
|
|
20
19
|
function getUIValue(element) {
|
|
21
20
|
return element[UIValue] === undefined ? element.value : String(element[UIValue]);
|
|
22
21
|
}
|
|
23
|
-
/** Flag the IDL value as clean. This does not change the value
|
|
22
|
+
/** Flag the IDL value as clean. This does not change the value. */ function setUIValueClean(element) {
|
|
24
23
|
element[UIValue] = undefined;
|
|
25
24
|
}
|
|
26
25
|
function clearInitialValue(element) {
|
|
@@ -46,7 +45,6 @@ function setUISelection(element, { focusOffset: focusOffsetParam, anchorOffset:
|
|
|
46
45
|
if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
|
|
47
46
|
return;
|
|
48
47
|
}
|
|
49
|
-
// eslint-disable-next-line no-new-wrappers
|
|
50
48
|
const startObj = Object.assign(new Number(startOffset), {
|
|
51
49
|
[UISelection]: true
|
|
52
50
|
});
|
|
@@ -58,10 +56,10 @@ function setUISelection(element, { focusOffset: focusOffsetParam, anchorOffset:
|
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
58
|
function getUISelection(element) {
|
|
61
|
-
var _element_selectionStart, _element_selectionEnd
|
|
62
|
-
const sel = (_element_UISelection = element[UISelection]) !== null && _element_UISelection !==
|
|
63
|
-
anchorOffset: (_element_selectionStart = element.selectionStart) !== null && _element_selectionStart !==
|
|
64
|
-
focusOffset: (_element_selectionEnd = element.selectionEnd) !== null && _element_selectionEnd !==
|
|
59
|
+
var _element_UISelection, _element_selectionStart, _element_selectionEnd;
|
|
60
|
+
const sel = (_element_UISelection = element[UISelection]) !== null && _element_UISelection !== void 0 ? _element_UISelection : {
|
|
61
|
+
anchorOffset: (_element_selectionStart = element.selectionStart) !== null && _element_selectionStart !== void 0 ? _element_selectionStart : 0,
|
|
62
|
+
focusOffset: (_element_selectionEnd = element.selectionEnd) !== null && _element_selectionEnd !== void 0 ? _element_selectionEnd : 0
|
|
65
63
|
};
|
|
66
64
|
return {
|
|
67
65
|
...sel,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { isElementType } from '../utils/misc/isElementType.js';
|
|
2
2
|
import '../utils/dataTransfer/Clipboard.js';
|
|
3
3
|
import { startTrackValue, trackOrSetValue } from './trackValue.js';
|
|
4
|
-
import { setUISelectionClean, setUISelectionRaw, getUIValue, setUIValueClean
|
|
4
|
+
import { isUIValue, setUISelectionClean, isUISelectionStart, setUISelectionRaw, getUIValue, setUIValueClean } from './UI.js';
|
|
5
5
|
|
|
6
6
|
const Interceptor = Symbol('Interceptor for programmatical calls');
|
|
7
7
|
function prepareInterceptor(element, propName, interceptorImpl) {
|
|
8
8
|
const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
9
9
|
const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
10
|
-
const target = (prototypeDescriptor === null || prototypeDescriptor ===
|
|
11
|
-
/* istanbul ignore if */ if (typeof (prototypeDescriptor === null || prototypeDescriptor ===
|
|
10
|
+
const target = (prototypeDescriptor === null || prototypeDescriptor === void 0 ? void 0 : prototypeDescriptor.set) ? 'set' : 'value';
|
|
11
|
+
/* istanbul ignore if */ if (typeof (prototypeDescriptor === null || prototypeDescriptor === void 0 ? void 0 : prototypeDescriptor[target]) !== 'function' || prototypeDescriptor[target][Interceptor]) {
|
|
12
12
|
throw new Error(`Element ${element.tagName} does not implement "${String(propName)}".`);
|
|
13
13
|
}
|
|
14
14
|
function intercept(...args) {
|
|
@@ -19,11 +19,11 @@ function prepareInterceptor(element, propName, interceptorImpl) {
|
|
|
19
19
|
} else {
|
|
20
20
|
realFunc.call(this, ...realArgs);
|
|
21
21
|
}
|
|
22
|
-
then === null || then ===
|
|
22
|
+
then === null || then === void 0 ? void 0 : then();
|
|
23
23
|
}
|
|
24
24
|
intercept[Interceptor] = Interceptor;
|
|
25
25
|
Object.defineProperty(element, propName, {
|
|
26
|
-
...objectDescriptor !== null && objectDescriptor !==
|
|
26
|
+
...objectDescriptor !== null && objectDescriptor !== void 0 ? objectDescriptor : prototypeDescriptor,
|
|
27
27
|
[target]: intercept
|
|
28
28
|
});
|
|
29
29
|
}
|
|
@@ -13,11 +13,13 @@ function patchFocus(HTMLElement) {
|
|
|
13
13
|
Object.defineProperties(HTMLElement.prototype, {
|
|
14
14
|
focus: {
|
|
15
15
|
configurable: true,
|
|
16
|
-
|
|
16
|
+
value: patchedFocus,
|
|
17
|
+
writable: true
|
|
17
18
|
},
|
|
18
19
|
blur: {
|
|
19
20
|
configurable: true,
|
|
20
|
-
|
|
21
|
+
value: patchedBlur,
|
|
22
|
+
writable: true
|
|
21
23
|
},
|
|
22
24
|
[patched]: {
|
|
23
25
|
configurable: true,
|
|
@@ -80,7 +82,7 @@ function patchFocus(HTMLElement) {
|
|
|
80
82
|
}
|
|
81
83
|
function getActiveTarget(document) {
|
|
82
84
|
const active = getActiveElement(document);
|
|
83
|
-
return (active === null || active ===
|
|
85
|
+
return (active === null || active === void 0 ? void 0 : active.tagName) === 'BODY' ? null : active;
|
|
84
86
|
}
|
|
85
87
|
function restoreFocus(HTMLElement) {
|
|
86
88
|
if (HTMLElement.prototype[patched]) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import '../utils/dataTransfer/Clipboard.js';
|
|
2
2
|
import { getWindow } from '../utils/misc/getWindow.js';
|
|
3
|
-
import { setUIValueClean,
|
|
3
|
+
import { setUIValueClean, hasUISelection, setUISelection } from './UI.js';
|
|
4
4
|
|
|
5
5
|
const TrackChanges = Symbol('Track programmatic changes for React workaround');
|
|
6
6
|
// When the input event happens in the browser, React executes all event handlers
|
|
@@ -24,7 +24,7 @@ function startTrackValue(element) {
|
|
|
24
24
|
}
|
|
25
25
|
function trackOrSetValue(element, v) {
|
|
26
26
|
var _element_TrackChanges_tracked, _element_TrackChanges;
|
|
27
|
-
(_element_TrackChanges = element[TrackChanges]) === null || _element_TrackChanges ===
|
|
27
|
+
(_element_TrackChanges = element[TrackChanges]) === null || _element_TrackChanges === void 0 ? void 0 : (_element_TrackChanges_tracked = _element_TrackChanges.tracked) === null || _element_TrackChanges_tracked === void 0 ? void 0 : _element_TrackChanges_tracked.push(v);
|
|
28
28
|
if (!element[TrackChanges]) {
|
|
29
29
|
setUIValueClean(element);
|
|
30
30
|
setUISelection(element, {
|
|
@@ -36,7 +36,7 @@ function commitValueAfterInput(element, cursorOffset) {
|
|
|
36
36
|
var _changes_tracked;
|
|
37
37
|
const changes = element[TrackChanges];
|
|
38
38
|
element[TrackChanges] = undefined;
|
|
39
|
-
if (!(changes === null || changes ===
|
|
39
|
+
if (!(changes === null || changes === void 0 ? void 0 : (_changes_tracked = changes.tracked) === null || _changes_tracked === void 0 ? void 0 : _changes_tracked.length)) {
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
42
|
const isJustReactStateUpdate = changes.tracked.length === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === element.value;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { setUISelection, getUIValue } from '../../document/UI.js';
|
|
2
2
|
import { getValueOrTextContent } from '../../document/getValueOrTextContent.js';
|
|
3
3
|
import { isElementType } from '../../utils/misc/isElementType.js';
|
|
4
4
|
import '../../utils/dataTransfer/Clipboard.js';
|
|
@@ -15,9 +15,9 @@ import { walkRadio } from '../radio.js';
|
|
|
15
15
|
import { behavior } from './registry.js';
|
|
16
16
|
|
|
17
17
|
behavior.keydown = (event, target, instance)=>{
|
|
18
|
+
var _ref;
|
|
18
19
|
var _keydownBehavior_event_key;
|
|
19
|
-
|
|
20
|
-
return (_keydownBehavior_event_key1 = (_keydownBehavior_event_key = keydownBehavior[event.key]) === null || _keydownBehavior_event_key === undefined ? undefined : _keydownBehavior_event_key.call(keydownBehavior, event, target, instance)) !== null && _keydownBehavior_event_key1 !== undefined ? _keydownBehavior_event_key1 : combinationBehavior(event, target, instance);
|
|
20
|
+
return (_ref = (_keydownBehavior_event_key = keydownBehavior[event.key]) === null || _keydownBehavior_event_key === void 0 ? void 0 : _keydownBehavior_event_key.call(keydownBehavior, event, target, instance)) !== null && _ref !== void 0 ? _ref : combinationBehavior(event, target, instance);
|
|
21
21
|
};
|
|
22
22
|
const keydownBehavior = {
|
|
23
23
|
ArrowDown: (event, target, instance)=>{
|
|
@@ -70,9 +70,9 @@ const keydownBehavior = {
|
|
|
70
70
|
'textarea'
|
|
71
71
|
]) || isContentEditable(target)) {
|
|
72
72
|
return ()=>{
|
|
73
|
+
var _ref;
|
|
73
74
|
var _getValueOrTextContent;
|
|
74
|
-
|
|
75
|
-
const newPos = (_getValueOrTextContent_length = (_getValueOrTextContent = getValueOrTextContent(target)) === null || _getValueOrTextContent === undefined ? undefined : _getValueOrTextContent.length) !== null && _getValueOrTextContent_length !== undefined ? _getValueOrTextContent_length : /* istanbul ignore next */ 0;
|
|
75
|
+
const newPos = (_ref = (_getValueOrTextContent = getValueOrTextContent(target)) === null || _getValueOrTextContent === void 0 ? void 0 : _getValueOrTextContent.length) !== null && _ref !== void 0 ? _ref : /* istanbul ignore next */ 0;
|
|
76
76
|
setSelectionRange(target, newPos, newPos);
|
|
77
77
|
};
|
|
78
78
|
}
|
|
@@ -13,7 +13,7 @@ behavior.keypress = (event, target, instance)=>{
|
|
|
13
13
|
};
|
|
14
14
|
} else if (isElementType(target, 'input')) {
|
|
15
15
|
const form = target.form;
|
|
16
|
-
const submit = form === null || form ===
|
|
16
|
+
const submit = form === null || form === void 0 ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
|
|
17
17
|
if (submit) {
|
|
18
18
|
return ()=>instance.dispatchUIEvent(submit, 'click');
|
|
19
19
|
} else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll('input').length === 1) {
|
|
@@ -4,7 +4,7 @@ import { behavior } from './registry.js';
|
|
|
4
4
|
|
|
5
5
|
behavior.keyup = (event, target, instance)=>{
|
|
6
6
|
var _keyupBehavior_event_key;
|
|
7
|
-
return (_keyupBehavior_event_key = keyupBehavior[event.key]) === null || _keyupBehavior_event_key ===
|
|
7
|
+
return (_keyupBehavior_event_key = keyupBehavior[event.key]) === null || _keyupBehavior_event_key === void 0 ? void 0 : _keyupBehavior_event_key.call(keyupBehavior, event, target, instance);
|
|
8
8
|
};
|
|
9
9
|
const keyupBehavior = {
|
|
10
10
|
' ': (event, target, instance)=>{
|
|
@@ -7,7 +7,7 @@ behavior.paste = (event, target, instance)=>{
|
|
|
7
7
|
if (isEditable(target)) {
|
|
8
8
|
return ()=>{
|
|
9
9
|
var _event_clipboardData;
|
|
10
|
-
const insertData = (_event_clipboardData = event.clipboardData) === null || _event_clipboardData ===
|
|
10
|
+
const insertData = (_event_clipboardData = event.clipboardData) === null || _event_clipboardData === void 0 ? void 0 : _event_clipboardData.getData('text');
|
|
11
11
|
if (insertData) {
|
|
12
12
|
input(instance, target, insertData, 'insertFromPaste');
|
|
13
13
|
}
|