@testing-library/user-event 14.4.3 → 14.5.0
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 +30 -0
- package/dist/cjs/_interop/dtlEventMap.js +30 -0
- package/dist/cjs/_interop/dtlHelpers.js +30 -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 +6 -4
- package/dist/cjs/document/trackValue.js +4 -4
- package/dist/cjs/event/behavior/keydown.js +6 -6
- package/dist/cjs/event/behavior/keypress.js +4 -3
- 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 +2 -2
- package/dist/cjs/event/focus.js +2 -2
- package/dist/cjs/event/input.js +4 -4
- package/dist/cjs/event/selection/getInputRange.js +2 -2
- package/dist/cjs/event/selection/getTargetTypeAndSelection.js +3 -2
- package/dist/cjs/event/selection/modifySelection.js +3 -3
- package/dist/cjs/event/selection/modifySelectionPerMouse.js +4 -3
- package/dist/cjs/event/selection/moveSelection.js +6 -5
- package/dist/cjs/event/selection/resolveCaretPosition.js +1 -1
- package/dist/cjs/event/selection/selectAll.js +6 -5
- package/dist/cjs/event/selection/setSelection.js +3 -3
- package/dist/cjs/event/selection/setSelectionPerMouse.js +8 -7
- package/dist/cjs/event/selection/setSelectionRange.js +2 -2
- package/dist/cjs/event/selection/updateSelectionOnFocus.js +4 -3
- package/dist/cjs/event/wrapEvent.js +3 -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 +3 -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 +46 -26
- 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 +12 -11
- package/dist/cjs/utility/type.js +1 -1
- package/dist/cjs/utility/upload.js +6 -5
- package/dist/cjs/utils/dataTransfer/Clipboard.js +25 -9
- package/dist/cjs/utils/dataTransfer/DataTransfer.js +25 -9
- 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 +4 -3
- 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 +3 -2
- package/dist/cjs/utils/misc/isDisabled.js +3 -3
- package/dist/cjs/utils/misc/isVisible.js +3 -2
- package/dist/cjs/utils/misc/wait.js +1 -1
- package/dist/cjs/utils/pointer/cssPointerEvents.js +23 -19
- package/dist/esm/_interop/dtl.js +6 -0
- package/dist/esm/_interop/dtlEventMap.js +6 -0
- package/dist/esm/_interop/dtlHelpers.js +6 -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 +6 -4
- package/dist/esm/document/trackValue.js +4 -4
- package/dist/esm/event/behavior/keydown.js +6 -6
- package/dist/esm/event/behavior/keypress.js +4 -3
- 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 +2 -2
- package/dist/esm/event/input.js +4 -4
- package/dist/esm/event/selection/getInputRange.js +2 -2
- package/dist/esm/event/selection/getTargetTypeAndSelection.js +3 -2
- package/dist/esm/event/selection/modifySelection.js +3 -3
- package/dist/esm/event/selection/modifySelectionPerMouse.js +4 -3
- package/dist/esm/event/selection/moveSelection.js +6 -5
- package/dist/esm/event/selection/resolveCaretPosition.js +1 -1
- package/dist/esm/event/selection/selectAll.js +6 -5
- package/dist/esm/event/selection/setSelection.js +3 -3
- package/dist/esm/event/selection/setSelectionPerMouse.js +8 -7
- package/dist/esm/event/selection/setSelectionRange.js +2 -2
- package/dist/esm/event/selection/updateSelectionOnFocus.js +4 -3
- 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 +46 -26
- 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 +6 -5
- package/dist/esm/utils/dataTransfer/Clipboard.js +25 -9
- package/dist/esm/utils/dataTransfer/DataTransfer.js +25 -9
- 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 +4 -3
- 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 +3 -2
- package/dist/esm/utils/misc/wait.js +1 -1
- package/dist/esm/utils/pointer/cssPointerEvents.js +23 -19
- package/dist/types/_interop/dtl.d.ts +3 -0
- package/dist/types/_interop/dtlEventMap.d.ts +3 -0
- package/dist/types/_interop/dtlHelpers.d.ts +3 -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
package/dist/esm/event/focus.js
CHANGED
|
@@ -23,8 +23,8 @@ import { wrapEvent } from './wrapEvent.js';
|
|
|
23
23
|
wrapEvent(()=>target.focus());
|
|
24
24
|
} else {
|
|
25
25
|
wrapEvent(()=>{
|
|
26
|
-
var
|
|
27
|
-
return (
|
|
26
|
+
var _activeElement;
|
|
27
|
+
return (_activeElement = activeElement) === null || _activeElement === void 0 ? void 0 : _activeElement.blur();
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
updateSelectionOnFocus(target !== null && target !== void 0 ? target : element.ownerDocument.body);
|
package/dist/esm/event/input.js
CHANGED
|
@@ -94,7 +94,7 @@ function editInputElement(instance, element, inputRange, data, inputType) {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
const { newValue
|
|
97
|
+
const { newValue, newOffset, oldValue } = calculateNewValue(dataToInsert, element, inputRange, inputType);
|
|
98
98
|
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
@@ -122,7 +122,7 @@ function editInputElement(instance, element, inputRange, data, inputType) {
|
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
function calculateNewValue(inputData, node, { startOffset
|
|
125
|
+
function calculateNewValue(inputData, node, { startOffset, endOffset }, inputType) {
|
|
126
126
|
const value = getUIValue(node);
|
|
127
127
|
const prologEnd = Math.max(0, startOffset === endOffset && inputType === 'deleteContentBackward' ? startOffset - 1 : startOffset);
|
|
128
128
|
const prolog = value.substring(0, prologEnd);
|
|
@@ -150,12 +150,12 @@ function commitInput(instance, element, newOffset, inputInit) {
|
|
|
150
150
|
commitValueAfterInput(element, newOffset);
|
|
151
151
|
}
|
|
152
152
|
function isValidNumberInput(value) {
|
|
153
|
-
var
|
|
153
|
+
var _value_match, _value_match1;
|
|
154
154
|
// the browser allows some invalid input but not others
|
|
155
155
|
// it allows up to two '-' at any place before any 'e' or one directly following 'e'
|
|
156
156
|
// it allows one '.' at any place before e
|
|
157
157
|
const valueParts = value.split('e', 2);
|
|
158
|
-
return !(/[^\d.\-e]/.test(value) || Number((
|
|
158
|
+
return !(/[^\d.\-e]/.test(value) || Number((_value_match = value.match(/-/g)) === null || _value_match === void 0 ? void 0 : _value_match.length) > 2 || Number((_value_match1 = value.match(/\./g)) === null || _value_match1 === void 0 ? void 0 : _value_match1.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1]));
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
export { input };
|
|
@@ -7,9 +7,9 @@ import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
|
|
|
7
7
|
if (typeAndSelection.type === 'input') {
|
|
8
8
|
return typeAndSelection.selection;
|
|
9
9
|
} else if (typeAndSelection.type === 'contenteditable') {
|
|
10
|
-
var
|
|
10
|
+
var _typeAndSelection_selection;
|
|
11
11
|
// Multi-range on contenteditable edits the first selection instead of the last
|
|
12
|
-
return (
|
|
12
|
+
return (_typeAndSelection_selection = typeAndSelection.selection) === null || _typeAndSelection_selection === void 0 ? void 0 : _typeAndSelection_selection.getRangeAt(0);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -13,6 +13,7 @@ import '../../options.js';
|
|
|
13
13
|
/**
|
|
14
14
|
* Determine which selection logic and selection ranges to consider.
|
|
15
15
|
*/ function getTargetTypeAndSelection(node) {
|
|
16
|
+
var _element, _selection;
|
|
16
17
|
const element = getElement(node);
|
|
17
18
|
if (element && hasOwnSelection(element)) {
|
|
18
19
|
return {
|
|
@@ -20,10 +21,10 @@ import '../../options.js';
|
|
|
20
21
|
selection: getUISelection(element)
|
|
21
22
|
};
|
|
22
23
|
}
|
|
23
|
-
const selection = element === null ||
|
|
24
|
+
const selection = (_element = element) === null || _element === void 0 ? void 0 : _element.ownerDocument.getSelection();
|
|
24
25
|
// It is possible to extend a single-range selection into a contenteditable.
|
|
25
26
|
// This results in the range acting like a range outside of contenteditable.
|
|
26
|
-
const isCE = getContentEditable(node) && (selection === null ||
|
|
27
|
+
const isCE = getContentEditable(node) && ((_selection = selection) === null || _selection === void 0 ? void 0 : _selection.anchorNode) && getContentEditable(selection.anchorNode);
|
|
27
28
|
return {
|
|
28
29
|
type: isCE ? 'contenteditable' : 'default',
|
|
29
30
|
selection
|
|
@@ -11,8 +11,8 @@ import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Extend/shrink the selection like with Shift+Arrows or Shift+Mouse
|
|
14
|
-
*/ function modifySelection({ focusNode
|
|
15
|
-
var
|
|
14
|
+
*/ function modifySelection({ focusNode, focusOffset }) {
|
|
15
|
+
var _focusNode_ownerDocument_getSelection, _focusNode_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
|
}, 'modify');
|
|
22
22
|
}
|
|
23
|
-
(
|
|
23
|
+
(_focusNode_ownerDocument = focusNode.ownerDocument) === null || _focusNode_ownerDocument === void 0 ? void 0 : (_focusNode_ownerDocument_getSelection = _focusNode_ownerDocument.getSelection()) === null || _focusNode_ownerDocument_getSelection === void 0 ? void 0 : _focusNode_ownerDocument_getSelection.extend(focusNode, focusOffset);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export { modifySelection };
|
|
@@ -9,7 +9,7 @@ import '../../utils/misc/level.js';
|
|
|
9
9
|
import '../../options.js';
|
|
10
10
|
import { resolveCaretPosition } from './resolveCaretPosition.js';
|
|
11
11
|
|
|
12
|
-
function modifySelectionPerMouseMove(selectionRange, { document
|
|
12
|
+
function modifySelectionPerMouseMove(selectionRange, { document, target, node, offset }) {
|
|
13
13
|
const selectionFocus = resolveCaretPosition({
|
|
14
14
|
target,
|
|
15
15
|
node,
|
|
@@ -29,6 +29,7 @@ function modifySelectionPerMouseMove(selectionRange, { document , target , node
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
} else {
|
|
32
|
+
var _selection, _selection1;
|
|
32
33
|
const range = selectionRange.cloneRange();
|
|
33
34
|
const cmp = range.comparePoint(selectionFocus.node, selectionFocus.offset);
|
|
34
35
|
if (cmp < 0) {
|
|
@@ -37,8 +38,8 @@ function modifySelectionPerMouseMove(selectionRange, { document , target , node
|
|
|
37
38
|
range.setEnd(selectionFocus.node, selectionFocus.offset);
|
|
38
39
|
}
|
|
39
40
|
const selection = document.getSelection();
|
|
40
|
-
selection === null ||
|
|
41
|
-
selection === null ||
|
|
41
|
+
(_selection = selection) === null || _selection === void 0 ? void 0 : _selection.removeAllRanges();
|
|
42
|
+
(_selection1 = selection) === null || _selection1 === void 0 ? void 0 : _selection1.addRange(range.cloneRange());
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
|
|
@@ -22,12 +22,13 @@ 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
|
-
|
|
26
|
-
|
|
25
|
+
var _selection;
|
|
26
|
+
const selection = node.ownerDocument.getSelection();
|
|
27
|
+
if (!((_selection = selection) === null || _selection === void 0 ? void 0 : _selection.focusNode)) {
|
|
27
28
|
return;
|
|
28
29
|
}
|
|
29
|
-
if (
|
|
30
|
-
const nextPosition = getNextCursorPosition(
|
|
30
|
+
if (selection.isCollapsed) {
|
|
31
|
+
const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, direction);
|
|
31
32
|
if (nextPosition) {
|
|
32
33
|
setSelection({
|
|
33
34
|
focusNode: nextPosition.node,
|
|
@@ -35,7 +36,7 @@ import { setSelection } from './setSelection.js';
|
|
|
35
36
|
});
|
|
36
37
|
}
|
|
37
38
|
} else {
|
|
38
|
-
|
|
39
|
+
selection[direction < 0 ? 'collapseToStart' : 'collapseToEnd']();
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
}
|
|
@@ -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,
|
|
@@ -30,13 +30,14 @@ import { setSelection } from './setSelection.js';
|
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
function isAllSelected(target) {
|
|
33
|
+
var _selection;
|
|
33
34
|
if (hasOwnSelection(target)) {
|
|
34
35
|
return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
|
|
35
36
|
}
|
|
36
|
-
var
|
|
37
|
-
const focusNode = (
|
|
37
|
+
var _getContentEditable;
|
|
38
|
+
const focusNode = (_getContentEditable = getContentEditable(target)) !== null && _getContentEditable !== void 0 ? _getContentEditable : target.ownerDocument.body;
|
|
38
39
|
const selection = target.ownerDocument.getSelection();
|
|
39
|
-
return (selection === null ||
|
|
40
|
+
return ((_selection = selection) === null || _selection === void 0 ? void 0 : _selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
export { isAllSelected, selectAll };
|
|
@@ -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,13 @@ function setSelectionPerMouseDown({ document , target , clickCount , node , offs
|
|
|
39
39
|
end: end !== null && end !== void 0 ? end : text.length
|
|
40
40
|
};
|
|
41
41
|
} else {
|
|
42
|
-
|
|
42
|
+
var _selection, _selection1;
|
|
43
|
+
const { node: startNode, offset: startOffset } = resolveCaretPosition({
|
|
43
44
|
target,
|
|
44
45
|
node,
|
|
45
46
|
offset: start
|
|
46
47
|
});
|
|
47
|
-
const { node: endNode
|
|
48
|
+
const { node: endNode, offset: endOffset } = resolveCaretPosition({
|
|
48
49
|
target,
|
|
49
50
|
node,
|
|
50
51
|
offset: end
|
|
@@ -57,8 +58,8 @@ function setSelectionPerMouseDown({ document , target , clickCount , node , offs
|
|
|
57
58
|
throw new Error('The given offset is out of bounds.');
|
|
58
59
|
}
|
|
59
60
|
const selection = document.getSelection();
|
|
60
|
-
selection === null ||
|
|
61
|
-
selection === null ||
|
|
61
|
+
(_selection = selection) === null || _selection === void 0 ? void 0 : _selection.removeAllRanges();
|
|
62
|
+
(_selection1 = selection) === null || _selection1 === void 0 ? void 0 : _selection1.addRange(range.cloneRange());
|
|
62
63
|
return range;
|
|
63
64
|
}
|
|
64
65
|
}
|
|
@@ -73,13 +74,13 @@ function getTextRange(text, pos, clickCount) {
|
|
|
73
74
|
if (clickCount % 3 === 2) {
|
|
74
75
|
return [
|
|
75
76
|
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
|
|
77
|
+
pos === undefined ? pos : pos + text.substr(pos).match(/^(\w+|\s+|\W)?/)[0].length
|
|
77
78
|
];
|
|
78
79
|
}
|
|
79
80
|
// triple click
|
|
80
81
|
return [
|
|
81
82
|
textPos - text.substr(0, pos).match(/[^\r\n]*$/)[0].length,
|
|
82
|
-
pos === undefined ? pos : pos + text.substr(pos).match(/^[^\r\n]*/)[0].length
|
|
83
|
+
pos === undefined ? pos : pos + text.substr(pos).match(/^[^\r\n]*/)[0].length
|
|
83
84
|
];
|
|
84
85
|
}
|
|
85
86
|
|
|
@@ -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,
|
|
@@ -13,8 +13,9 @@ import '../../options.js';
|
|
|
13
13
|
* Reset the Document Selection when moving focus into an element
|
|
14
14
|
* with own selection implementation.
|
|
15
15
|
*/ function updateSelectionOnFocus(element) {
|
|
16
|
+
var _selection;
|
|
16
17
|
const selection = element.ownerDocument.getSelection();
|
|
17
|
-
/* istanbul ignore if */ if (!(selection === null ||
|
|
18
|
+
/* istanbul ignore if */ if (!((_selection = selection) === null || _selection === void 0 ? void 0 : _selection.focusNode)) {
|
|
18
19
|
return;
|
|
19
20
|
}
|
|
20
21
|
// If the focus moves inside an element with own selection implementation,
|
|
@@ -28,8 +29,8 @@ import '../../options.js';
|
|
|
28
29
|
const contenteditable = getContentEditable(selection.focusNode);
|
|
29
30
|
if (contenteditable) {
|
|
30
31
|
if (!selection.isCollapsed) {
|
|
31
|
-
var
|
|
32
|
-
const focusNode = ((
|
|
32
|
+
var _contenteditable_firstChild;
|
|
33
|
+
const focusNode = ((_contenteditable_firstChild = contenteditable.firstChild) === null || _contenteditable_firstChild === void 0 ? void 0 : _contenteditable_firstChild.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
33
34
|
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
34
35
|
}
|
|
35
36
|
} 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, _previousPosition_caret, _previousPosition1, _previousPosition_caret1, _previousPosition2;
|
|
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 = 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 : (_previousPosition1 = previousPosition) === null || _previousPosition1 === void 0 ? void 0 : (_previousPosition_caret = _previousPosition1.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 : (_previousPosition2 = previousPosition) === null || _previousPosition2 === void 0 ? void 0 : (_previousPosition_caret1 = _previousPosition2.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
|
|