@testing-library/user-event 14.4.3 → 14.5.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/_interop/dtl.js +27 -0
- package/dist/cjs/_interop/dtlEventMap.js +27 -0
- package/dist/cjs/_interop/dtlHelpers.js +27 -0
- package/dist/cjs/clipboard/copy.js +2 -2
- package/dist/cjs/clipboard/cut.js +2 -2
- package/dist/cjs/clipboard/paste.js +4 -4
- package/dist/cjs/convenience/tab.js +1 -1
- package/dist/cjs/document/UI.js +5 -5
- package/dist/cjs/document/interceptor.js +1 -1
- package/dist/cjs/document/trackValue.js +4 -4
- package/dist/cjs/event/behavior/keydown.js +6 -6
- package/dist/cjs/event/behavior/keypress.js +2 -2
- package/dist/cjs/event/behavior/keyup.js +2 -2
- package/dist/cjs/event/behavior/paste.js +2 -2
- package/dist/cjs/event/createEvent.js +41 -41
- package/dist/cjs/event/dispatchEvent.js +2 -2
- package/dist/cjs/event/eventMap.js +22 -2
- package/dist/cjs/event/focus.js +1 -4
- package/dist/cjs/event/input.js +4 -4
- package/dist/cjs/event/selection/getInputRange.js +2 -2
- package/dist/cjs/event/selection/modifySelection.js +3 -3
- package/dist/cjs/event/selection/modifySelectionPerMouse.js +1 -1
- package/dist/cjs/event/selection/moveSelection.js +5 -5
- package/dist/cjs/event/selection/resolveCaretPosition.js +1 -1
- package/dist/cjs/event/selection/selectAll.js +4 -4
- package/dist/cjs/event/selection/setSelection.js +3 -3
- package/dist/cjs/event/selection/setSelectionPerMouse.js +5 -5
- package/dist/cjs/event/selection/setSelectionRange.js +2 -2
- package/dist/cjs/event/selection/updateSelectionOnFocus.js +2 -2
- package/dist/cjs/event/wrapEvent.js +23 -2
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/keyboard/index.js +2 -2
- package/dist/cjs/keyboard/parseKeyDef.js +8 -8
- package/dist/cjs/pointer/index.js +11 -11
- package/dist/cjs/pointer/keyMap.js +1 -1
- package/dist/cjs/pointer/parseKeyDef.js +1 -1
- package/dist/cjs/setup/api.js +19 -17
- package/dist/cjs/setup/directApi.js +3 -3
- package/dist/cjs/setup/setup.js +10 -10
- package/dist/cjs/setup/wrapAsync.js +23 -2
- package/dist/cjs/system/index.js +15 -2
- package/dist/cjs/system/keyboard.js +27 -12
- package/dist/cjs/system/pointer/buttons.js +14 -1
- package/dist/cjs/system/pointer/device.js +14 -1
- package/dist/cjs/system/pointer/index.js +34 -17
- package/dist/cjs/system/pointer/mouse.js +33 -19
- package/dist/cjs/system/pointer/pointer.js +24 -8
- package/dist/cjs/system/pointer/shared.js +2 -2
- package/dist/cjs/utility/selectOptions.js +32 -11
- package/dist/cjs/utility/type.js +1 -1
- package/dist/cjs/utility/upload.js +4 -4
- package/dist/cjs/utils/dataTransfer/Clipboard.js +22 -8
- package/dist/cjs/utils/dataTransfer/DataTransfer.js +23 -8
- package/dist/cjs/utils/edit/maxLength.js +2 -2
- package/dist/cjs/utils/edit/setFiles.js +4 -4
- package/dist/cjs/utils/focus/cursor.js +2 -2
- package/dist/cjs/utils/focus/getActiveElement.js +2 -2
- package/dist/cjs/utils/focus/selector.js +1 -1
- package/dist/cjs/utils/keyDef/readNextDescriptor.js +5 -5
- package/dist/cjs/utils/misc/getTreeDiff.js +3 -3
- package/dist/cjs/utils/misc/getWindow.js +23 -2
- package/dist/cjs/utils/misc/isDisabled.js +3 -3
- package/dist/cjs/utils/misc/isVisible.js +1 -1
- package/dist/cjs/utils/misc/wait.js +1 -1
- package/dist/cjs/utils/pointer/cssPointerEvents.js +13 -13
- package/dist/esm/_interop/dtl.js +2 -0
- package/dist/esm/_interop/dtlEventMap.js +2 -0
- package/dist/esm/_interop/dtlHelpers.js +2 -0
- package/dist/esm/clipboard/copy.js +2 -2
- package/dist/esm/clipboard/cut.js +2 -2
- package/dist/esm/clipboard/paste.js +4 -4
- package/dist/esm/convenience/tab.js +1 -1
- package/dist/esm/document/UI.js +5 -5
- package/dist/esm/document/interceptor.js +1 -1
- package/dist/esm/document/trackValue.js +4 -4
- package/dist/esm/event/behavior/keydown.js +6 -6
- package/dist/esm/event/behavior/keypress.js +2 -2
- package/dist/esm/event/behavior/keyup.js +2 -2
- package/dist/esm/event/behavior/paste.js +2 -2
- package/dist/esm/event/createEvent.js +41 -41
- package/dist/esm/event/dispatchEvent.js +2 -2
- package/dist/esm/event/eventMap.js +2 -2
- package/dist/esm/event/focus.js +1 -4
- package/dist/esm/event/input.js +4 -4
- package/dist/esm/event/selection/getInputRange.js +2 -2
- package/dist/esm/event/selection/modifySelection.js +3 -3
- package/dist/esm/event/selection/modifySelectionPerMouse.js +1 -1
- package/dist/esm/event/selection/moveSelection.js +5 -5
- package/dist/esm/event/selection/resolveCaretPosition.js +1 -1
- package/dist/esm/event/selection/selectAll.js +4 -4
- package/dist/esm/event/selection/setSelection.js +3 -3
- package/dist/esm/event/selection/setSelectionPerMouse.js +5 -5
- package/dist/esm/event/selection/setSelectionRange.js +2 -2
- package/dist/esm/event/selection/updateSelectionOnFocus.js +2 -2
- package/dist/esm/event/wrapEvent.js +2 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/keyboard/index.js +2 -2
- package/dist/esm/keyboard/parseKeyDef.js +8 -8
- package/dist/esm/pointer/index.js +11 -11
- package/dist/esm/pointer/keyMap.js +1 -1
- package/dist/esm/pointer/parseKeyDef.js +1 -1
- package/dist/esm/setup/api.js +33 -12
- package/dist/esm/setup/directApi.js +3 -3
- package/dist/esm/setup/setup.js +11 -11
- package/dist/esm/setup/wrapAsync.js +2 -1
- package/dist/esm/system/index.js +15 -2
- package/dist/esm/system/keyboard.js +27 -12
- package/dist/esm/system/pointer/buttons.js +14 -1
- package/dist/esm/system/pointer/device.js +14 -1
- package/dist/esm/system/pointer/index.js +34 -17
- package/dist/esm/system/pointer/mouse.js +33 -19
- package/dist/esm/system/pointer/pointer.js +24 -8
- package/dist/esm/system/pointer/shared.js +2 -2
- package/dist/esm/utility/selectOptions.js +8 -7
- package/dist/esm/utility/type.js +1 -1
- package/dist/esm/utility/upload.js +4 -4
- package/dist/esm/utils/dataTransfer/Clipboard.js +22 -8
- package/dist/esm/utils/dataTransfer/DataTransfer.js +23 -8
- package/dist/esm/utils/edit/maxLength.js +2 -2
- package/dist/esm/utils/edit/setFiles.js +4 -4
- package/dist/esm/utils/focus/cursor.js +2 -2
- package/dist/esm/utils/focus/getActiveElement.js +2 -2
- package/dist/esm/utils/focus/selector.js +1 -1
- package/dist/esm/utils/keyDef/readNextDescriptor.js +5 -5
- package/dist/esm/utils/misc/getTreeDiff.js +3 -3
- package/dist/esm/utils/misc/getWindow.js +2 -1
- package/dist/esm/utils/misc/isDisabled.js +3 -3
- package/dist/esm/utils/misc/isVisible.js +1 -1
- package/dist/esm/utils/misc/wait.js +1 -1
- package/dist/esm/utils/pointer/cssPointerEvents.js +13 -13
- package/dist/types/_interop/dtl.d.ts +2 -0
- package/dist/types/_interop/dtlEventMap.d.ts +2 -0
- package/dist/types/_interop/dtlHelpers.d.ts +2 -0
- package/dist/types/clipboard/copy.d.ts +1 -1
- package/dist/types/clipboard/cut.d.ts +1 -1
- package/dist/types/clipboard/paste.d.ts +1 -1
- package/dist/types/convenience/click.d.ts +1 -1
- package/dist/types/convenience/hover.d.ts +1 -1
- package/dist/types/convenience/tab.d.ts +1 -1
- package/dist/types/document/UI.d.ts +3 -3
- package/dist/types/document/interceptor.d.ts +3 -3
- package/dist/types/event/behavior/registry.d.ts +1 -1
- package/dist/types/event/createEvent.d.ts +1 -1
- package/dist/types/event/dispatchEvent.d.ts +1 -1
- package/dist/types/event/eventMap.d.ts +8 -0
- package/dist/types/event/input.d.ts +1 -1
- package/dist/types/event/radio.d.ts +1 -1
- package/dist/types/event/selection/index.d.ts +2 -2
- package/dist/types/event/selection/modifySelectionPerMouse.d.ts +1 -1
- package/dist/types/event/selection/setSelectionPerMouse.d.ts +1 -1
- package/dist/types/event/types.d.ts +3 -3
- package/dist/types/index.d.ts +3 -1
- package/dist/types/keyboard/index.d.ts +1 -1
- package/dist/types/options.d.ts +2 -2
- package/dist/types/pointer/index.d.ts +7 -7
- package/dist/types/setup/api.d.ts +23 -5
- package/dist/types/setup/directApi.d.ts +5 -5
- package/dist/types/setup/setup.d.ts +5 -5
- package/dist/types/system/keyboard.d.ts +2 -2
- package/dist/types/system/pointer/buttons.d.ts +2 -2
- package/dist/types/system/pointer/device.d.ts +1 -1
- package/dist/types/system/pointer/mouse.d.ts +2 -2
- package/dist/types/system/pointer/pointer.d.ts +2 -2
- package/dist/types/utility/clear.d.ts +1 -1
- package/dist/types/utility/selectOptions.d.ts +1 -1
- package/dist/types/utility/type.d.ts +2 -2
- package/dist/types/utility/upload.d.ts +1 -1
- package/dist/types/utils/click/isClickableInput.d.ts +1 -1
- package/dist/types/utils/dataTransfer/Clipboard.d.ts +1 -1
- package/dist/types/utils/edit/isEditable.d.ts +2 -2
- package/dist/types/utils/edit/maxLength.d.ts +1 -1
- package/dist/types/utils/keyDef/readNextDescriptor.d.ts +1 -1
- package/dist/types/utils/misc/isElementType.d.ts +1 -1
- package/dist/types/utils/misc/level.d.ts +2 -2
- package/dist/types/utils/misc/wait.d.ts +1 -1
- package/dist/types/utils/pointer/cssPointerEvents.d.ts +1 -1
- package/package.json +22 -11
- /package/dist/cjs/{event → _interop}/dom-events.d.js +0 -0
- /package/dist/cjs/{utils/misc → _interop}/dom-helpers.d.js +0 -0
- /package/dist/esm/{event → _interop}/dom-events.d.js +0 -0
- /package/dist/esm/{utils/misc → _interop}/dom-helpers.d.js +0 -0
|
@@ -22,12 +22,12 @@ import { setSelection } from './setSelection.js';
|
|
|
22
22
|
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + direction : direction < 0 ? selection.startOffset : selection.endOffset
|
|
23
23
|
});
|
|
24
24
|
} else {
|
|
25
|
-
const
|
|
26
|
-
if (!(
|
|
25
|
+
const selection = node.ownerDocument.getSelection();
|
|
26
|
+
if (!(selection === null || selection === void 0 ? void 0 : selection.focusNode)) {
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
|
-
if (
|
|
30
|
-
const nextPosition = getNextCursorPosition(
|
|
29
|
+
if (selection.isCollapsed) {
|
|
30
|
+
const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, direction);
|
|
31
31
|
if (nextPosition) {
|
|
32
32
|
setSelection({
|
|
33
33
|
focusNode: nextPosition.node,
|
|
@@ -35,7 +35,7 @@ import { setSelection } from './setSelection.js';
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
} else {
|
|
38
|
-
|
|
38
|
+
selection[direction < 0 ? 'collapseToStart' : 'collapseToEnd']();
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -9,7 +9,7 @@ import '../../utils/keyDef/readNextDescriptor.js';
|
|
|
9
9
|
import '../../utils/misc/level.js';
|
|
10
10
|
import '../../options.js';
|
|
11
11
|
|
|
12
|
-
function resolveCaretPosition({ target
|
|
12
|
+
function resolveCaretPosition({ target, node, offset }) {
|
|
13
13
|
if (hasOwnSelection(target)) {
|
|
14
14
|
return {
|
|
15
15
|
node: target,
|
|
@@ -21,8 +21,8 @@ import { setSelection } from './setSelection.js';
|
|
|
21
21
|
focusOffset: getUIValue(target).length
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
-
var
|
|
25
|
-
const focusNode = (
|
|
24
|
+
var _getContentEditable;
|
|
25
|
+
const focusNode = (_getContentEditable = getContentEditable(target)) !== null && _getContentEditable !== void 0 ? _getContentEditable : target.ownerDocument.body;
|
|
26
26
|
setSelection({
|
|
27
27
|
focusNode,
|
|
28
28
|
anchorOffset: 0,
|
|
@@ -33,8 +33,8 @@ function isAllSelected(target) {
|
|
|
33
33
|
if (hasOwnSelection(target)) {
|
|
34
34
|
return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
|
|
35
35
|
}
|
|
36
|
-
var
|
|
37
|
-
const focusNode = (
|
|
36
|
+
var _getContentEditable;
|
|
37
|
+
const focusNode = (_getContentEditable = getContentEditable(target)) !== null && _getContentEditable !== void 0 ? _getContentEditable : target.ownerDocument.body;
|
|
38
38
|
const selection = target.ownerDocument.getSelection();
|
|
39
39
|
return (selection === null || selection === void 0 ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
40
40
|
}
|
|
@@ -11,8 +11,8 @@ import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Set the selection
|
|
14
|
-
*/ function setSelection({ focusNode
|
|
15
|
-
var
|
|
14
|
+
*/ function setSelection({ focusNode, focusOffset, anchorNode = focusNode, anchorOffset = focusOffset }) {
|
|
15
|
+
var _anchorNode_ownerDocument_getSelection, _anchorNode_ownerDocument;
|
|
16
16
|
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
17
17
|
if (typeAndSelection.type === 'input') {
|
|
18
18
|
return setUISelection(focusNode, {
|
|
@@ -20,7 +20,7 @@ import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
|
|
|
20
20
|
focusOffset
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
-
(
|
|
23
|
+
(_anchorNode_ownerDocument = anchorNode.ownerDocument) === null || _anchorNode_ownerDocument === void 0 ? void 0 : (_anchorNode_ownerDocument_getSelection = _anchorNode_ownerDocument.getSelection()) === null || _anchorNode_ownerDocument_getSelection === void 0 ? void 0 : _anchorNode_ownerDocument_getSelection.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export { setSelection };
|
|
@@ -10,7 +10,7 @@ import '../../utils/misc/level.js';
|
|
|
10
10
|
import '../../options.js';
|
|
11
11
|
import { resolveCaretPosition } from './resolveCaretPosition.js';
|
|
12
12
|
|
|
13
|
-
function setSelectionPerMouseDown({ document
|
|
13
|
+
function setSelectionPerMouseDown({ document, target, clickCount, node, offset }) {
|
|
14
14
|
if (hasNoSelection(target)) {
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
@@ -39,12 +39,12 @@ function setSelectionPerMouseDown({ document , target , clickCount , node , offs
|
|
|
39
39
|
end: end !== null && end !== void 0 ? end : text.length
|
|
40
40
|
};
|
|
41
41
|
} else {
|
|
42
|
-
const { node: startNode
|
|
42
|
+
const { node: startNode, offset: startOffset } = resolveCaretPosition({
|
|
43
43
|
target,
|
|
44
44
|
node,
|
|
45
45
|
offset: start
|
|
46
46
|
});
|
|
47
|
-
const { node: endNode
|
|
47
|
+
const { node: endNode, offset: endOffset } = resolveCaretPosition({
|
|
48
48
|
target,
|
|
49
49
|
node,
|
|
50
50
|
offset: end
|
|
@@ -73,13 +73,13 @@ function getTextRange(text, pos, clickCount) {
|
|
|
73
73
|
if (clickCount % 3 === 2) {
|
|
74
74
|
return [
|
|
75
75
|
textPos - text.substr(0, pos).match(/(\w+|\s+|\W)?$/)[0].length,
|
|
76
|
-
pos === undefined ? pos : pos + text.substr(pos).match(/^(\w+|\s+|\W)?/)[0].length
|
|
76
|
+
pos === undefined ? pos : pos + text.substr(pos).match(/^(\w+|\s+|\W)?/)[0].length
|
|
77
77
|
];
|
|
78
78
|
}
|
|
79
79
|
// triple click
|
|
80
80
|
return [
|
|
81
81
|
textPos - text.substr(0, pos).match(/[^\r\n]*$/)[0].length,
|
|
82
|
-
pos === undefined ? pos : pos + text.substr(pos).match(/^[^\r\n]*/)[0].length
|
|
82
|
+
pos === undefined ? pos : pos + text.substr(pos).match(/^[^\r\n]*/)[0].length
|
|
83
83
|
];
|
|
84
84
|
}
|
|
85
85
|
|
|
@@ -15,7 +15,7 @@ import { setSelection } from './setSelection.js';
|
|
|
15
15
|
*
|
|
16
16
|
* Handles input elements and contenteditable if it only contains a single text node.
|
|
17
17
|
*/ function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
18
|
-
var
|
|
18
|
+
var _element_firstChild;
|
|
19
19
|
if (hasOwnSelection(element)) {
|
|
20
20
|
return setSelection({
|
|
21
21
|
focusNode: element,
|
|
@@ -23,7 +23,7 @@ import { setSelection } from './setSelection.js';
|
|
|
23
23
|
focusOffset
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
-
/* istanbul ignore else */ if (isContentEditable(element) && ((
|
|
26
|
+
/* istanbul ignore else */ if (isContentEditable(element) && ((_element_firstChild = element.firstChild) === null || _element_firstChild === void 0 ? void 0 : _element_firstChild.nodeType) === 3) {
|
|
27
27
|
return setSelection({
|
|
28
28
|
focusNode: element.firstChild,
|
|
29
29
|
anchorOffset,
|
|
@@ -28,8 +28,8 @@ import '../../options.js';
|
|
|
28
28
|
const contenteditable = getContentEditable(selection.focusNode);
|
|
29
29
|
if (contenteditable) {
|
|
30
30
|
if (!selection.isCollapsed) {
|
|
31
|
-
var
|
|
32
|
-
const focusNode = ((
|
|
31
|
+
var _contenteditable_firstChild;
|
|
32
|
+
const focusNode = ((_contenteditable_firstChild = contenteditable.firstChild) === null || _contenteditable_firstChild === void 0 ? void 0 : _contenteditable_firstChild.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
33
33
|
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
34
34
|
}
|
|
35
35
|
} else {
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { userEvent as default } from './setup/index.js';
|
|
1
|
+
export { userEvent as default, userEvent } from './setup/index.js';
|
|
2
2
|
export { PointerEventsCheckLevel } from './options.js';
|
|
@@ -16,8 +16,8 @@ async function keyboard(text) {
|
|
|
16
16
|
await keyboardAction(this, actions[i]);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
async function keyboardAction(instance, { keyDef
|
|
20
|
-
const { system
|
|
19
|
+
async function keyboardAction(instance, { keyDef, releasePrevious, releaseSelf, repeat }) {
|
|
20
|
+
const { system } = instance;
|
|
21
21
|
// Release the key automatically if it was pressed before.
|
|
22
22
|
if (system.keyboard.isKeyPressed(keyDef)) {
|
|
23
23
|
await system.keyboard.keyup(instance, keyDef);
|
|
@@ -19,18 +19,18 @@ import '../options.js';
|
|
|
19
19
|
*/ function parseKeyDef(keyboardMap, text) {
|
|
20
20
|
const defs = [];
|
|
21
21
|
do {
|
|
22
|
-
const { type
|
|
23
|
-
var
|
|
24
|
-
const keyDef = (
|
|
22
|
+
const { type, descriptor, consumedLength, releasePrevious, releaseSelf = true, repeat } = readNextDescriptor(text, 'keyboard');
|
|
23
|
+
var _keyboardMap_find;
|
|
24
|
+
const keyDef = (_keyboardMap_find = keyboardMap.find((def)=>{
|
|
25
25
|
if (type === '[') {
|
|
26
|
-
var
|
|
27
|
-
return ((
|
|
26
|
+
var _def_code;
|
|
27
|
+
return ((_def_code = def.code) === null || _def_code === void 0 ? void 0 : _def_code.toLowerCase()) === descriptor.toLowerCase();
|
|
28
28
|
} else if (type === '{') {
|
|
29
|
-
var
|
|
30
|
-
return ((
|
|
29
|
+
var _def_key;
|
|
30
|
+
return ((_def_key = def.key) === null || _def_key === void 0 ? void 0 : _def_key.toLowerCase()) === descriptor.toLowerCase();
|
|
31
31
|
}
|
|
32
32
|
return def.key === descriptor;
|
|
33
|
-
})) !== null &&
|
|
33
|
+
})) !== null && _keyboardMap_find !== void 0 ? _keyboardMap_find : {
|
|
34
34
|
key: 'Unknown',
|
|
35
35
|
code: 'Unknown',
|
|
36
36
|
[type === '[' ? 'code' : 'key']: descriptor
|
|
@@ -10,7 +10,7 @@ import '../options.js';
|
|
|
10
10
|
import { parseKeyDef } from './parseKeyDef.js';
|
|
11
11
|
|
|
12
12
|
async function pointer(input) {
|
|
13
|
-
const { pointerMap
|
|
13
|
+
const { pointerMap } = this.config;
|
|
14
14
|
const actions = [];
|
|
15
15
|
(Array.isArray(input) ? input : [
|
|
16
16
|
input
|
|
@@ -33,16 +33,16 @@ async function pointer(input) {
|
|
|
33
33
|
this.system.pointer.resetClickCount();
|
|
34
34
|
}
|
|
35
35
|
async function pointerAction(instance, action) {
|
|
36
|
-
var
|
|
36
|
+
var _previousPosition_caret, _previousPosition_caret1;
|
|
37
37
|
const pointerName = 'pointerName' in action && action.pointerName ? action.pointerName : 'keyDef' in action ? instance.system.pointer.getPointerName(action.keyDef) : 'mouse';
|
|
38
38
|
const previousPosition = instance.system.pointer.getPreviousPosition(pointerName);
|
|
39
|
-
var
|
|
39
|
+
var _action_target, _action_coords, _action_node, _action_offset;
|
|
40
40
|
const position = {
|
|
41
|
-
target: (
|
|
42
|
-
coords: (
|
|
41
|
+
target: (_action_target = action.target) !== null && _action_target !== void 0 ? _action_target : getPrevTarget(instance, previousPosition),
|
|
42
|
+
coords: (_action_coords = action.coords) !== null && _action_coords !== void 0 ? _action_coords : previousPosition === null || previousPosition === void 0 ? void 0 : previousPosition.coords,
|
|
43
43
|
caret: {
|
|
44
|
-
node: (
|
|
45
|
-
offset: (
|
|
44
|
+
node: (_action_node = action.node) !== null && _action_node !== void 0 ? _action_node : hasCaretPosition(action) ? undefined : previousPosition === null || previousPosition === void 0 ? void 0 : (_previousPosition_caret = previousPosition.caret) === null || _previousPosition_caret === void 0 ? void 0 : _previousPosition_caret.node,
|
|
45
|
+
offset: (_action_offset = action.offset) !== null && _action_offset !== void 0 ? _action_offset : hasCaretPosition(action) ? undefined : previousPosition === null || previousPosition === void 0 ? void 0 : (_previousPosition_caret1 = previousPosition.caret) === null || _previousPosition_caret1 === void 0 ? void 0 : _previousPosition_caret1.offset
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
48
|
if ('keyDef' in action) {
|
|
@@ -64,15 +64,15 @@ async function pointerAction(instance, action) {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
function hasCaretPosition(action) {
|
|
67
|
-
var
|
|
68
|
-
return !!((
|
|
67
|
+
var _action_target, _ref;
|
|
68
|
+
return !!((_ref = (_action_target = action.target) !== null && _action_target !== void 0 ? _action_target : action.node) !== null && _ref !== void 0 ? _ref : action.offset !== undefined);
|
|
69
69
|
}
|
|
70
70
|
function getPrevTarget(instance, position) {
|
|
71
71
|
if (!position) {
|
|
72
72
|
throw new Error('This pointer has no previous position. Provide a target property!');
|
|
73
73
|
}
|
|
74
|
-
var
|
|
75
|
-
return (
|
|
74
|
+
var _position_target;
|
|
75
|
+
return (_position_target = position.target) !== null && _position_target !== void 0 ? _position_target : instance.config.document.body;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
export { pointer };
|
|
@@ -10,7 +10,7 @@ import '../options.js';
|
|
|
10
10
|
function parseKeyDef(pointerMap, keys) {
|
|
11
11
|
const defs = [];
|
|
12
12
|
do {
|
|
13
|
-
const { descriptor
|
|
13
|
+
const { descriptor, consumedLength, releasePrevious, releaseSelf = true } = readNextDescriptor(keys, 'pointer');
|
|
14
14
|
const keyDef = pointerMap.find((p)=>p.name === descriptor);
|
|
15
15
|
if (keyDef) {
|
|
16
16
|
defs.push({
|
package/dist/esm/setup/api.js
CHANGED
|
@@ -1,12 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { click, dblClick, tripleClick } from '../convenience/click.js';
|
|
2
|
+
import { hover, unhover } from '../convenience/hover.js';
|
|
3
|
+
import { tab } from '../convenience/tab.js';
|
|
4
|
+
import { keyboard } from '../keyboard/index.js';
|
|
5
|
+
import { copy } from '../clipboard/copy.js';
|
|
6
|
+
import { cut } from '../clipboard/cut.js';
|
|
7
|
+
import { paste } from '../clipboard/paste.js';
|
|
8
|
+
import { pointer } from '../pointer/index.js';
|
|
9
|
+
import { clear } from '../utility/clear.js';
|
|
10
|
+
import { deselectOptions, selectOptions } from '../utility/selectOptions.js';
|
|
11
|
+
import { type } from '../utility/type.js';
|
|
12
|
+
import { upload } from '../utility/upload.js';
|
|
13
|
+
|
|
14
|
+
const userEventApi = {
|
|
15
|
+
click,
|
|
16
|
+
dblClick,
|
|
17
|
+
tripleClick,
|
|
18
|
+
hover,
|
|
19
|
+
unhover,
|
|
20
|
+
tab,
|
|
21
|
+
keyboard,
|
|
22
|
+
copy,
|
|
23
|
+
cut,
|
|
24
|
+
paste,
|
|
25
|
+
pointer,
|
|
26
|
+
clear,
|
|
27
|
+
deselectOptions,
|
|
28
|
+
selectOptions,
|
|
29
|
+
type,
|
|
30
|
+
upload
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { userEventApi };
|
|
@@ -22,11 +22,11 @@ function hover(element, options = {}) {
|
|
|
22
22
|
return setupDirect(options).api.hover(element);
|
|
23
23
|
}
|
|
24
24
|
async function keyboard(text, options = {}) {
|
|
25
|
-
const { api
|
|
25
|
+
const { api, system } = setupDirect(options);
|
|
26
26
|
return api.keyboard(text).then(()=>system);
|
|
27
27
|
}
|
|
28
28
|
async function pointer(input, options = {}) {
|
|
29
|
-
const { api
|
|
29
|
+
const { api, system } = setupDirect(options);
|
|
30
30
|
return api.pointer(input).then(()=>system);
|
|
31
31
|
}
|
|
32
32
|
function paste(clipboardData, options) {
|
|
@@ -42,7 +42,7 @@ function type(element, text, options = {}) {
|
|
|
42
42
|
return setupDirect(options, element).api.type(element, text, options);
|
|
43
43
|
}
|
|
44
44
|
function unhover(element, options = {}) {
|
|
45
|
-
const { api
|
|
45
|
+
const { api, system } = setupDirect(options);
|
|
46
46
|
system.pointer.setMousePosition({
|
|
47
47
|
target: element
|
|
48
48
|
});
|
package/dist/esm/setup/setup.js
CHANGED
|
@@ -14,7 +14,7 @@ import '@testing-library/dom';
|
|
|
14
14
|
import { defaultKeyMap } from '../keyboard/keyMap.js';
|
|
15
15
|
import { defaultKeyMap as defaultKeyMap$1 } from '../pointer/keyMap.js';
|
|
16
16
|
import { System } from '../system/index.js';
|
|
17
|
-
import
|
|
17
|
+
import { userEventApi } from './api.js';
|
|
18
18
|
import { wrapAsync } from './wrapAsync.js';
|
|
19
19
|
|
|
20
20
|
/**
|
|
@@ -53,18 +53,18 @@ function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
|
|
|
53
53
|
*/ function setupMain(options = {}) {
|
|
54
54
|
const config = createConfig(options);
|
|
55
55
|
prepareDocument(config.document);
|
|
56
|
-
var
|
|
57
|
-
const view = (
|
|
56
|
+
var _config_document_defaultView;
|
|
57
|
+
const view = (_config_document_defaultView = config.document.defaultView) !== null && _config_document_defaultView !== void 0 ? _config_document_defaultView : /* istanbul ignore next */ globalThis.window;
|
|
58
58
|
attachClipboardStubToView(view);
|
|
59
59
|
return createInstance(config).api;
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
62
|
* Setup in direct call per `userEvent.anyApi()`
|
|
63
|
-
*/ function setupDirect({ keyboardState
|
|
63
|
+
*/ function setupDirect({ keyboardState, pointerState, ...options } = {}, node) {
|
|
64
64
|
const config = createConfig(options, defaultOptionsDirect, node);
|
|
65
65
|
prepareDocument(config.document);
|
|
66
|
-
var
|
|
67
|
-
const system = (
|
|
66
|
+
var _ref;
|
|
67
|
+
const system = (_ref = pointerState !== null && pointerState !== void 0 ? pointerState : keyboardState) !== null && _ref !== void 0 ? _ref : new System();
|
|
68
68
|
return {
|
|
69
69
|
api: createInstance(config, system).api,
|
|
70
70
|
system
|
|
@@ -99,22 +99,22 @@ function createInstance(config, system = new System()) {
|
|
|
99
99
|
dispatchUIEvent: dispatchUIEvent.bind(instance),
|
|
100
100
|
system,
|
|
101
101
|
levelRefs: {},
|
|
102
|
-
...
|
|
102
|
+
...userEventApi
|
|
103
103
|
});
|
|
104
104
|
return {
|
|
105
105
|
instance,
|
|
106
106
|
api: {
|
|
107
|
-
...Object.fromEntries(Object.entries(
|
|
107
|
+
...Object.fromEntries(Object.entries(userEventApi).map(([name, api])=>[
|
|
108
108
|
name,
|
|
109
|
-
wrapAndBindImpl(instance, api)
|
|
109
|
+
wrapAndBindImpl(instance, api)
|
|
110
110
|
])),
|
|
111
111
|
setup: setupSub.bind(instance)
|
|
112
112
|
}
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
115
|
function getDocument(options, node, defaults) {
|
|
116
|
-
var
|
|
117
|
-
return (
|
|
116
|
+
var _options_document, _ref;
|
|
117
|
+
return (_ref = (_options_document = options.document) !== null && _options_document !== void 0 ? _options_document : node && getDocumentFromNode(node)) !== null && _ref !== void 0 ? _ref : defaults.document;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
export { createConfig, createInstance, setupDirect, setupMain, setupSub };
|
package/dist/esm/system/index.js
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { KeyboardHost } from './keyboard.js';
|
|
2
2
|
import { PointerHost } from './pointer/index.js';
|
|
3
3
|
|
|
4
|
+
function _define_property(obj, key, value) {
|
|
5
|
+
if (key in obj) {
|
|
6
|
+
Object.defineProperty(obj, key, {
|
|
7
|
+
value: value,
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true
|
|
11
|
+
});
|
|
12
|
+
} else {
|
|
13
|
+
obj[key] = value;
|
|
14
|
+
}
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
4
17
|
/**
|
|
5
18
|
* @internal Do not create/alter this by yourself as this type might be subject to changes.
|
|
6
19
|
*/ class System {
|
|
@@ -21,8 +34,8 @@ import { PointerHost } from './pointer/index.js';
|
|
|
21
34
|
};
|
|
22
35
|
}
|
|
23
36
|
constructor(){
|
|
24
|
-
this
|
|
25
|
-
this
|
|
37
|
+
_define_property(this, "keyboard", new KeyboardHost(this));
|
|
38
|
+
_define_property(this, "pointer", new PointerHost(this));
|
|
26
39
|
}
|
|
27
40
|
}
|
|
28
41
|
|
|
@@ -8,7 +8,19 @@ import '../utils/keyDef/readNextDescriptor.js';
|
|
|
8
8
|
import '../utils/misc/level.js';
|
|
9
9
|
import '../options.js';
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
function _define_property(obj, key, value) {
|
|
12
|
+
if (key in obj) {
|
|
13
|
+
Object.defineProperty(obj, key, {
|
|
14
|
+
value: value,
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true
|
|
18
|
+
});
|
|
19
|
+
} else {
|
|
20
|
+
obj[key] = value;
|
|
21
|
+
}
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
|
12
24
|
var DOM_KEY_LOCATION;
|
|
13
25
|
(function(DOM_KEY_LOCATION) {
|
|
14
26
|
DOM_KEY_LOCATION[DOM_KEY_LOCATION["STANDARD"] = 0] = "STANDARD";
|
|
@@ -23,7 +35,7 @@ const modifierKeys = [
|
|
|
23
35
|
'Fn',
|
|
24
36
|
'Meta',
|
|
25
37
|
'Shift',
|
|
26
|
-
'Symbol'
|
|
38
|
+
'Symbol'
|
|
27
39
|
];
|
|
28
40
|
function isModifierKey(key) {
|
|
29
41
|
return modifierKeys.includes(key);
|
|
@@ -33,7 +45,7 @@ const modifierLocks = [
|
|
|
33
45
|
'FnLock',
|
|
34
46
|
'NumLock',
|
|
35
47
|
'ScrollLock',
|
|
36
|
-
'SymbolLock'
|
|
48
|
+
'SymbolLock'
|
|
37
49
|
];
|
|
38
50
|
function isModifierLock(key) {
|
|
39
51
|
return modifierLocks.includes(key);
|
|
@@ -46,12 +58,14 @@ class KeyboardHost {
|
|
|
46
58
|
return Object.values(this.pressed).map((p)=>p.keyDef);
|
|
47
59
|
}
|
|
48
60
|
/** Press a key */ async keydown(instance, keyDef) {
|
|
61
|
+
var // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
62
|
+
_this_pressed, _code, _this_pressed_code;
|
|
49
63
|
const key = String(keyDef.key);
|
|
50
64
|
const code = String(keyDef.code);
|
|
51
65
|
const target = getActiveElementOrBody(instance.config.document);
|
|
52
66
|
this.setKeydownTarget(target);
|
|
53
|
-
var
|
|
54
|
-
(
|
|
67
|
+
var _;
|
|
68
|
+
(_ = (_this_pressed = this.pressed)[_code = code]) !== null && _ !== void 0 ? _ : _this_pressed[_code] = {
|
|
55
69
|
keyDef,
|
|
56
70
|
unpreventedDefault: false
|
|
57
71
|
};
|
|
@@ -66,7 +80,7 @@ class KeyboardHost {
|
|
|
66
80
|
this.modifiers[key] = true;
|
|
67
81
|
this.modifierLockStart[key] = true;
|
|
68
82
|
}
|
|
69
|
-
(
|
|
83
|
+
(_this_pressed_code = this.pressed[code]).unpreventedDefault || (_this_pressed_code.unpreventedDefault = unprevented);
|
|
70
84
|
if (unprevented && this.hasKeyPress(key)) {
|
|
71
85
|
instance.dispatchUIEvent(getActiveElementOrBody(instance.config.document), 'keypress', {
|
|
72
86
|
key,
|
|
@@ -106,7 +120,8 @@ class KeyboardHost {
|
|
|
106
120
|
return (key.length === 1 || key === 'Enter') && !this.modifiers.Control && !this.modifiers.Alt;
|
|
107
121
|
}
|
|
108
122
|
constructor(system){
|
|
109
|
-
this
|
|
123
|
+
_define_property(this, "system", void 0);
|
|
124
|
+
_define_property(this, "modifiers", {
|
|
110
125
|
Alt: false,
|
|
111
126
|
AltGraph: false,
|
|
112
127
|
CapsLock: false,
|
|
@@ -119,11 +134,11 @@ class KeyboardHost {
|
|
|
119
134
|
Shift: false,
|
|
120
135
|
Symbol: false,
|
|
121
136
|
SymbolLock: false
|
|
122
|
-
};
|
|
123
|
-
this
|
|
124
|
-
this
|
|
125
|
-
this
|
|
126
|
-
this
|
|
137
|
+
});
|
|
138
|
+
_define_property(this, "pressed", {});
|
|
139
|
+
_define_property(this, "carryChar", '');
|
|
140
|
+
_define_property(this, "lastKeydownTarget", undefined);
|
|
141
|
+
_define_property(this, "modifierLockStart", {});
|
|
127
142
|
this.system = system;
|
|
128
143
|
}
|
|
129
144
|
}
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
1
14
|
class Buttons {
|
|
2
15
|
getButtons() {
|
|
3
16
|
let v = 0;
|
|
@@ -31,7 +44,7 @@ class Buttons {
|
|
|
31
44
|
return undefined;
|
|
32
45
|
}
|
|
33
46
|
constructor(){
|
|
34
|
-
this
|
|
47
|
+
_define_property(this, "pressed", {});
|
|
35
48
|
}
|
|
36
49
|
}
|
|
37
50
|
const MouseButton = {
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
1
14
|
class Device {
|
|
2
15
|
get countPressed() {
|
|
3
16
|
return this.pressedKeys.size;
|
|
@@ -12,7 +25,7 @@ class Device {
|
|
|
12
25
|
return this.pressedKeys.delete(keyDef.name);
|
|
13
26
|
}
|
|
14
27
|
constructor(){
|
|
15
|
-
this
|
|
28
|
+
_define_property(this, "pressedKeys", new Set());
|
|
16
29
|
}
|
|
17
30
|
}
|
|
18
31
|
|