@testing-library/user-event 14.4.0 → 14.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/clipboard/copy.js +6 -15
- package/dist/cjs/clipboard/cut.js +6 -15
- package/dist/cjs/clipboard/paste.js +6 -14
- package/dist/cjs/convenience/click.js +1 -4
- package/dist/cjs/convenience/hover.js +2 -12
- package/dist/cjs/document/UI.js +94 -0
- package/dist/cjs/document/copySelection.js +37 -0
- package/dist/cjs/document/getValueOrTextContent.js +27 -0
- package/dist/cjs/document/index.js +13 -68
- package/dist/cjs/document/interceptor.js +87 -4
- package/dist/cjs/document/prepareDocument.js +67 -0
- package/dist/cjs/document/trackValue.js +65 -0
- package/dist/cjs/event/behavior/click.js +8 -12
- package/dist/cjs/event/behavior/cut.js +5 -11
- package/dist/cjs/event/behavior/keydown.js +43 -43
- package/dist/cjs/event/behavior/keypress.js +9 -10
- package/dist/cjs/event/behavior/keyup.js +6 -7
- package/dist/cjs/event/behavior/paste.js +7 -12
- package/dist/cjs/event/createEvent.js +37 -28
- package/dist/cjs/event/dispatchEvent.js +21 -2
- package/dist/cjs/event/focus.js +44 -0
- package/dist/cjs/event/index.js +24 -17
- package/dist/cjs/{utils/edit → event}/input.js +50 -47
- package/dist/cjs/{utils/edit/walkRadio.js → event/radio.js} +13 -7
- package/dist/cjs/event/selection/getInputRange.js +20 -0
- package/dist/cjs/event/selection/getTargetTypeAndSelection.js +40 -0
- package/dist/cjs/event/selection/index.js +26 -0
- package/dist/cjs/event/selection/modifySelection.js +30 -0
- package/dist/cjs/event/selection/modifySelectionPerMouse.js +49 -0
- package/dist/cjs/event/selection/moveSelection.js +47 -0
- package/dist/cjs/{utils/focus → event/selection}/resolveCaretPosition.js +11 -19
- package/dist/cjs/event/selection/selectAll.js +47 -0
- package/dist/cjs/event/selection/setSelection.js +30 -0
- package/dist/cjs/event/selection/setSelectionPerMouse.js +90 -0
- package/dist/cjs/event/selection/setSelectionRange.js +40 -0
- package/dist/cjs/event/selection/updateSelectionOnFocus.js +45 -0
- package/dist/cjs/keyboard/index.js +13 -23
- package/dist/cjs/keyboard/parseKeyDef.js +8 -13
- package/dist/cjs/options.js +0 -28
- package/dist/cjs/pointer/index.js +28 -34
- package/dist/cjs/pointer/parseKeyDef.js +1 -9
- package/dist/cjs/setup/directApi.js +6 -6
- package/dist/cjs/setup/index.js +0 -2
- package/dist/cjs/setup/setup.js +69 -38
- package/dist/cjs/system/index.js +4 -2
- package/dist/cjs/system/keyboard.js +32 -32
- package/dist/cjs/system/pointer/buttons.js +3 -1
- package/dist/cjs/system/pointer/device.js +3 -1
- package/dist/cjs/system/pointer/index.js +82 -79
- package/dist/cjs/system/pointer/mouse.js +97 -81
- package/dist/cjs/system/pointer/pointer.js +45 -46
- package/dist/cjs/system/pointer/shared.js +10 -0
- package/dist/cjs/utility/clear.js +10 -11
- package/dist/cjs/utility/selectOptions.js +17 -19
- package/dist/cjs/utility/type.js +6 -15
- package/dist/cjs/utility/upload.js +9 -15
- package/dist/cjs/utils/dataTransfer/Clipboard.js +11 -21
- package/dist/cjs/utils/dataTransfer/DataTransfer.js +22 -19
- package/dist/cjs/utils/edit/isEditable.js +6 -10
- package/dist/cjs/utils/edit/maxLength.js +6 -16
- package/dist/cjs/utils/edit/setFiles.js +4 -2
- package/dist/cjs/utils/edit/{buildTimeValue.js → timeValue.js} +6 -0
- package/dist/cjs/utils/focus/cursor.js +2 -17
- package/dist/cjs/utils/focus/getActiveElement.js +3 -2
- package/dist/cjs/utils/focus/selection.js +1 -266
- package/dist/cjs/utils/index.js +7 -32
- package/dist/cjs/utils/keyDef/readNextDescriptor.js +5 -3
- package/dist/cjs/utils/misc/isDisabled.js +2 -1
- package/dist/cjs/utils/misc/isVisible.js +1 -1
- package/dist/cjs/utils/misc/level.js +4 -6
- package/dist/cjs/utils/pointer/cssPointerEvents.js +26 -32
- package/dist/esm/clipboard/copy.js +6 -15
- package/dist/esm/clipboard/cut.js +6 -15
- package/dist/esm/clipboard/paste.js +6 -14
- package/dist/esm/convenience/click.js +1 -4
- package/dist/esm/convenience/hover.js +2 -12
- package/dist/esm/document/UI.js +79 -0
- package/dist/esm/document/copySelection.js +33 -0
- package/dist/esm/document/getValueOrTextContent.js +23 -0
- package/dist/esm/document/index.js +4 -66
- package/dist/esm/document/interceptor.js +85 -5
- package/dist/esm/document/prepareDocument.js +63 -0
- package/dist/esm/document/trackValue.js +59 -0
- package/dist/esm/event/behavior/click.js +8 -12
- package/dist/esm/event/behavior/cut.js +5 -11
- package/dist/esm/event/behavior/keydown.js +36 -36
- package/dist/esm/event/behavior/keypress.js +9 -10
- package/dist/esm/event/behavior/keyup.js +6 -7
- package/dist/esm/event/behavior/paste.js +7 -12
- package/dist/esm/event/createEvent.js +37 -28
- package/dist/esm/event/dispatchEvent.js +20 -3
- package/dist/esm/event/focus.js +39 -0
- package/dist/esm/event/index.js +14 -19
- package/dist/esm/{utils/edit → event}/input.js +37 -34
- package/dist/esm/{utils/edit/walkRadio.js → event/radio.js} +13 -7
- package/dist/esm/event/selection/getInputRange.js +16 -0
- package/dist/esm/event/selection/getTargetTypeAndSelection.js +36 -0
- package/dist/esm/event/selection/index.js +9 -0
- package/dist/esm/event/selection/modifySelection.js +26 -0
- package/dist/esm/event/selection/modifySelectionPerMouse.js +45 -0
- package/dist/esm/event/selection/moveSelection.js +43 -0
- package/dist/esm/{utils/focus → event/selection}/resolveCaretPosition.js +11 -19
- package/dist/esm/event/selection/selectAll.js +42 -0
- package/dist/esm/event/selection/setSelection.js +26 -0
- package/dist/esm/event/selection/setSelectionPerMouse.js +86 -0
- package/dist/esm/event/selection/setSelectionRange.js +36 -0
- package/dist/esm/event/selection/updateSelectionOnFocus.js +41 -0
- package/dist/esm/keyboard/index.js +13 -23
- package/dist/esm/keyboard/parseKeyDef.js +8 -13
- package/dist/esm/options.js +1 -26
- package/dist/esm/pointer/index.js +28 -34
- package/dist/esm/pointer/parseKeyDef.js +1 -9
- package/dist/esm/setup/directApi.js +6 -6
- package/dist/esm/setup/index.js +0 -1
- package/dist/esm/setup/setup.js +63 -33
- package/dist/esm/system/index.js +4 -2
- package/dist/esm/system/keyboard.js +32 -32
- package/dist/esm/system/pointer/buttons.js +3 -1
- package/dist/esm/system/pointer/device.js +3 -1
- package/dist/esm/system/pointer/index.js +83 -79
- package/dist/esm/system/pointer/mouse.js +95 -79
- package/dist/esm/system/pointer/pointer.js +44 -45
- package/dist/esm/system/pointer/shared.js +6 -0
- package/dist/esm/utility/clear.js +10 -11
- package/dist/esm/utility/selectOptions.js +17 -19
- package/dist/esm/utility/type.js +6 -15
- package/dist/esm/utility/upload.js +9 -15
- package/dist/esm/utils/dataTransfer/Clipboard.js +11 -21
- package/dist/esm/utils/dataTransfer/DataTransfer.js +22 -19
- package/dist/esm/utils/edit/isEditable.js +4 -8
- package/dist/esm/utils/edit/maxLength.js +5 -16
- package/dist/esm/utils/edit/setFiles.js +4 -2
- package/dist/esm/utils/edit/{buildTimeValue.js → timeValue.js} +6 -1
- package/dist/esm/utils/focus/cursor.js +2 -17
- package/dist/esm/utils/focus/getActiveElement.js +3 -2
- package/dist/esm/utils/focus/selection.js +3 -260
- package/dist/esm/utils/index.js +4 -11
- package/dist/esm/utils/keyDef/readNextDescriptor.js +5 -3
- package/dist/esm/utils/misc/isDisabled.js +2 -1
- package/dist/esm/utils/misc/isVisible.js +1 -1
- package/dist/esm/utils/misc/level.js +4 -6
- package/dist/esm/utils/pointer/cssPointerEvents.js +26 -32
- 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/document/UI.d.ts +42 -0
- package/dist/types/{utils/focus → document}/copySelection.d.ts +0 -0
- package/dist/types/document/getValueOrTextContent.d.ts +1 -0
- package/dist/types/document/index.d.ts +5 -10
- package/dist/types/document/interceptor.d.ts +3 -0
- package/dist/types/document/prepareDocument.d.ts +8 -0
- package/dist/types/document/trackValue.d.ts +17 -0
- package/dist/types/event/behavior/registry.d.ts +2 -2
- package/dist/types/event/dispatchEvent.d.ts +5 -2
- package/dist/types/event/focus.d.ts +5 -0
- package/dist/types/event/index.d.ts +6 -4
- package/dist/types/event/input.d.ts +2 -0
- package/dist/types/event/radio.d.ts +4 -0
- package/dist/types/event/selection/getInputRange.d.ts +5 -0
- package/dist/types/event/selection/getTargetTypeAndSelection.d.ts +10 -0
- package/dist/types/event/selection/index.d.ts +15 -0
- package/dist/types/event/selection/modifySelection.d.ts +8 -0
- package/dist/types/event/selection/modifySelectionPerMouse.d.ts +7 -0
- package/dist/types/event/selection/moveSelection.d.ts +4 -0
- package/dist/types/{utils/focus → event/selection}/resolveCaretPosition.d.ts +0 -0
- package/dist/types/{utils/focus → event/selection}/selectAll.d.ts +0 -0
- package/dist/types/event/selection/setSelection.d.ts +10 -0
- package/dist/types/event/selection/setSelectionPerMouse.d.ts +8 -0
- package/dist/types/event/selection/setSelectionRange.d.ts +6 -0
- package/dist/types/event/selection/updateSelectionOnFocus.d.ts +5 -0
- package/dist/types/keyboard/index.d.ts +2 -2
- package/dist/types/options.d.ts +0 -8
- package/dist/types/pointer/index.d.ts +3 -3
- package/dist/types/setup/directApi.d.ts +1 -1
- package/dist/types/setup/index.d.ts +2 -15
- package/dist/types/setup/setup.d.ts +25 -7
- package/dist/types/system/keyboard.d.ts +3 -3
- package/dist/types/system/pointer/buttons.d.ts +1 -1
- package/dist/types/system/pointer/index.d.ts +7 -25
- package/dist/types/system/pointer/mouse.d.ts +5 -5
- package/dist/types/system/pointer/pointer.d.ts +7 -7
- package/dist/types/system/pointer/shared.d.ts +20 -0
- 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 +3 -3
- package/dist/types/utility/upload.d.ts +1 -1
- package/dist/types/utils/click/isClickableInput.d.ts +2 -2
- package/dist/types/utils/edit/isEditable.d.ts +5 -6
- package/dist/types/utils/edit/maxLength.d.ts +14 -1
- package/dist/types/utils/edit/{isValidDateOrTimeValue.d.ts → timeValue.d.ts} +1 -0
- package/dist/types/utils/focus/selection.d.ts +4 -69
- package/dist/types/utils/index.d.ts +2 -9
- package/dist/types/utils/misc/level.d.ts +4 -13
- package/dist/types/utils/misc/wait.d.ts +2 -2
- package/dist/types/utils/pointer/cssPointerEvents.d.ts +4 -4
- package/package.json +29 -4
- package/dist/cjs/document/selection.js +0 -107
- package/dist/cjs/document/setRangeText.js +0 -21
- package/dist/cjs/document/value.js +0 -125
- package/dist/cjs/setup/config.js +0 -7
- package/dist/cjs/utils/edit/getValue.js +0 -35
- package/dist/cjs/utils/edit/isValidDateOrTimeValue.js +0 -11
- package/dist/cjs/utils/focus/blur.js +0 -16
- package/dist/cjs/utils/focus/copySelection.js +0 -46
- package/dist/cjs/utils/focus/focus.js +0 -26
- package/dist/cjs/utils/focus/selectAll.js +0 -54
- package/dist/cjs/utils/misc/eventWrapper.js +0 -15
- package/dist/esm/document/selection.js +0 -99
- package/dist/esm/document/setRangeText.js +0 -17
- package/dist/esm/document/value.js +0 -115
- package/dist/esm/setup/config.js +0 -3
- package/dist/esm/utils/edit/getValue.js +0 -31
- package/dist/esm/utils/edit/isValidDateOrTimeValue.js +0 -7
- package/dist/esm/utils/focus/blur.js +0 -12
- package/dist/esm/utils/focus/copySelection.js +0 -42
- package/dist/esm/utils/focus/focus.js +0 -22
- package/dist/esm/utils/focus/selectAll.js +0 -49
- package/dist/esm/utils/misc/eventWrapper.js +0 -11
- package/dist/types/document/selection.d.ts +0 -29
- package/dist/types/document/setRangeText.d.ts +0 -1
- package/dist/types/document/value.d.ts +0 -26
- package/dist/types/setup/config.d.ts +0 -6
- package/dist/types/utils/edit/buildTimeValue.d.ts +0 -1
- package/dist/types/utils/edit/getValue.d.ts +0 -1
- package/dist/types/utils/edit/input.d.ts +0 -2
- package/dist/types/utils/edit/walkRadio.d.ts +0 -4
- package/dist/types/utils/focus/blur.d.ts +0 -2
- package/dist/types/utils/focus/focus.d.ts +0 -5
- package/dist/types/utils/misc/eventWrapper.d.ts +0 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { getUIValue, getUISelection } from '../../document/UI.js';
|
|
2
|
+
import '../../utils/click/isClickableInput.js';
|
|
3
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
4
|
+
import { getContentEditable } from '../../utils/edit/isContentEditable.js';
|
|
5
|
+
import '../../utils/edit/isEditable.js';
|
|
6
|
+
import '../../utils/edit/maxLength.js';
|
|
7
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
8
|
+
import { hasOwnSelection } from '../../utils/focus/selection.js';
|
|
9
|
+
import '../../utils/keyDef/readNextDescriptor.js';
|
|
10
|
+
import '../../utils/misc/level.js';
|
|
11
|
+
import '../../options.js';
|
|
12
|
+
import { setSelection } from './setSelection.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Expand a selection like the browser does when pressing Ctrl+A.
|
|
16
|
+
*/ function selectAll(target) {
|
|
17
|
+
if (hasOwnSelection(target)) {
|
|
18
|
+
return setSelection({
|
|
19
|
+
focusNode: target,
|
|
20
|
+
anchorOffset: 0,
|
|
21
|
+
focusOffset: getUIValue(target).length
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
var ref;
|
|
25
|
+
const focusNode = (ref = getContentEditable(target)) !== null && ref !== void 0 ? ref : target.ownerDocument.body;
|
|
26
|
+
setSelection({
|
|
27
|
+
focusNode,
|
|
28
|
+
anchorOffset: 0,
|
|
29
|
+
focusOffset: focusNode.childNodes.length
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function isAllSelected(target) {
|
|
33
|
+
if (hasOwnSelection(target)) {
|
|
34
|
+
return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
|
|
35
|
+
}
|
|
36
|
+
var ref;
|
|
37
|
+
const focusNode = (ref = getContentEditable(target)) !== null && ref !== void 0 ? ref : target.ownerDocument.body;
|
|
38
|
+
const selection = target.ownerDocument.getSelection();
|
|
39
|
+
return (selection === null || selection === void 0 ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { isAllSelected, selectAll };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { setUISelection } from '../../document/UI.js';
|
|
2
|
+
import '../../utils/click/isClickableInput.js';
|
|
3
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
4
|
+
import '../../utils/edit/isEditable.js';
|
|
5
|
+
import '../../utils/edit/maxLength.js';
|
|
6
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
7
|
+
import '../../utils/keyDef/readNextDescriptor.js';
|
|
8
|
+
import '../../utils/misc/level.js';
|
|
9
|
+
import '../../options.js';
|
|
10
|
+
import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Set the selection
|
|
14
|
+
*/ function setSelection({ focusNode , focusOffset , anchorNode =focusNode , anchorOffset =focusOffset }) {
|
|
15
|
+
var ref, ref1;
|
|
16
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
17
|
+
if (typeAndSelection.type === 'input') {
|
|
18
|
+
return setUISelection(focusNode, {
|
|
19
|
+
anchorOffset,
|
|
20
|
+
focusOffset
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
(ref1 = (ref = anchorNode.ownerDocument) === null || ref === void 0 ? void 0 : ref.getSelection()) === null || ref1 === void 0 ? void 0 : ref1.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { setSelection };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { getUIValue, setUISelection } from '../../document/UI.js';
|
|
2
|
+
import '../../utils/click/isClickableInput.js';
|
|
3
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
4
|
+
import '../../utils/edit/isEditable.js';
|
|
5
|
+
import '../../utils/edit/maxLength.js';
|
|
6
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
7
|
+
import { hasNoSelection, hasOwnSelection } from '../../utils/focus/selection.js';
|
|
8
|
+
import '../../utils/keyDef/readNextDescriptor.js';
|
|
9
|
+
import '../../utils/misc/level.js';
|
|
10
|
+
import '../../options.js';
|
|
11
|
+
import { resolveCaretPosition } from './resolveCaretPosition.js';
|
|
12
|
+
|
|
13
|
+
function setSelectionPerMouseDown({ document , target , clickCount , node , offset }) {
|
|
14
|
+
if (hasNoSelection(target)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const targetHasOwnSelection = hasOwnSelection(target);
|
|
18
|
+
// On non-input elements the text selection per multiple click
|
|
19
|
+
// can extend beyond the target boundaries.
|
|
20
|
+
// The exact mechanism what is considered in the same line is unclear.
|
|
21
|
+
// Looks it might be every inline element.
|
|
22
|
+
// TODO: Check what might be considered part of the same line of text.
|
|
23
|
+
const text = String(targetHasOwnSelection ? getUIValue(target) : target.textContent);
|
|
24
|
+
const [start, end] = node ? // which elements might be considered in the same line of text.
|
|
25
|
+
// TODO: support expanding initial range on multiple clicks if node is given
|
|
26
|
+
[
|
|
27
|
+
offset,
|
|
28
|
+
offset
|
|
29
|
+
] : getTextRange(text, offset, clickCount);
|
|
30
|
+
// TODO: implement modifying selection per shift/ctrl+mouse
|
|
31
|
+
if (targetHasOwnSelection) {
|
|
32
|
+
setUISelection(target, {
|
|
33
|
+
anchorOffset: start !== null && start !== void 0 ? start : text.length,
|
|
34
|
+
focusOffset: end !== null && end !== void 0 ? end : text.length
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
node: target,
|
|
38
|
+
start: start !== null && start !== void 0 ? start : 0,
|
|
39
|
+
end: end !== null && end !== void 0 ? end : text.length
|
|
40
|
+
};
|
|
41
|
+
} else {
|
|
42
|
+
const { node: startNode , offset: startOffset } = resolveCaretPosition({
|
|
43
|
+
target,
|
|
44
|
+
node,
|
|
45
|
+
offset: start
|
|
46
|
+
});
|
|
47
|
+
const { node: endNode , offset: endOffset } = resolveCaretPosition({
|
|
48
|
+
target,
|
|
49
|
+
node,
|
|
50
|
+
offset: end
|
|
51
|
+
});
|
|
52
|
+
const range = target.ownerDocument.createRange();
|
|
53
|
+
try {
|
|
54
|
+
range.setStart(startNode, startOffset);
|
|
55
|
+
range.setEnd(endNode, endOffset);
|
|
56
|
+
} catch (e) {
|
|
57
|
+
throw new Error('The given offset is out of bounds.');
|
|
58
|
+
}
|
|
59
|
+
const selection = document.getSelection();
|
|
60
|
+
selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
|
|
61
|
+
selection === null || selection === void 0 ? void 0 : selection.addRange(range.cloneRange());
|
|
62
|
+
return range;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function getTextRange(text, pos, clickCount) {
|
|
66
|
+
if (clickCount % 3 === 1 || text.length === 0) {
|
|
67
|
+
return [
|
|
68
|
+
pos,
|
|
69
|
+
pos
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
const textPos = pos !== null && pos !== void 0 ? pos : text.length;
|
|
73
|
+
if (clickCount % 3 === 2) {
|
|
74
|
+
return [
|
|
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,
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
// triple click
|
|
80
|
+
return [
|
|
81
|
+
textPos - text.substr(0, pos).match(/[^\r\n]*$/)[0].length,
|
|
82
|
+
pos === undefined ? pos : pos + text.substr(pos).match(/^[^\r\n]*/)[0].length,
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { setSelectionPerMouseDown };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import '../../utils/click/isClickableInput.js';
|
|
2
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
3
|
+
import { isContentEditable } from '../../utils/edit/isContentEditable.js';
|
|
4
|
+
import '../../utils/edit/isEditable.js';
|
|
5
|
+
import '../../utils/edit/maxLength.js';
|
|
6
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
7
|
+
import { hasOwnSelection } from '../../utils/focus/selection.js';
|
|
8
|
+
import '../../utils/keyDef/readNextDescriptor.js';
|
|
9
|
+
import '../../utils/misc/level.js';
|
|
10
|
+
import '../../options.js';
|
|
11
|
+
import { setSelection } from './setSelection.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Backward-compatible selection.
|
|
15
|
+
*
|
|
16
|
+
* Handles input elements and contenteditable if it only contains a single text node.
|
|
17
|
+
*/ function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
18
|
+
var ref;
|
|
19
|
+
if (hasOwnSelection(element)) {
|
|
20
|
+
return setSelection({
|
|
21
|
+
focusNode: element,
|
|
22
|
+
anchorOffset,
|
|
23
|
+
focusOffset
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/* istanbul ignore else */ if (isContentEditable(element) && ((ref = element.firstChild) === null || ref === void 0 ? void 0 : ref.nodeType) === 3) {
|
|
27
|
+
return setSelection({
|
|
28
|
+
focusNode: element.firstChild,
|
|
29
|
+
anchorOffset,
|
|
30
|
+
focusOffset
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/* istanbul ignore next */ throw new Error('Not implemented. The result of this interaction is unreliable.');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { setSelectionRange };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import '../../utils/click/isClickableInput.js';
|
|
2
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
3
|
+
import { getContentEditable } from '../../utils/edit/isContentEditable.js';
|
|
4
|
+
import '../../utils/edit/isEditable.js';
|
|
5
|
+
import '../../utils/edit/maxLength.js';
|
|
6
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
7
|
+
import { hasOwnSelection } from '../../utils/focus/selection.js';
|
|
8
|
+
import '../../utils/keyDef/readNextDescriptor.js';
|
|
9
|
+
import '../../utils/misc/level.js';
|
|
10
|
+
import '../../options.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Reset the Document Selection when moving focus into an element
|
|
14
|
+
* with own selection implementation.
|
|
15
|
+
*/ function updateSelectionOnFocus(element) {
|
|
16
|
+
const selection = element.ownerDocument.getSelection();
|
|
17
|
+
/* istanbul ignore if */ if (!(selection === null || selection === void 0 ? void 0 : selection.focusNode)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
// If the focus moves inside an element with own selection implementation,
|
|
21
|
+
// the document selection will be this element.
|
|
22
|
+
// But if the focused element is inside a contenteditable,
|
|
23
|
+
// 1) a collapsed selection will be retained.
|
|
24
|
+
// 2) other selections will be replaced by a cursor
|
|
25
|
+
// 2.a) at the start of the first child if it is a text node
|
|
26
|
+
// 2.b) at the start of the contenteditable.
|
|
27
|
+
if (hasOwnSelection(element)) {
|
|
28
|
+
const contenteditable = getContentEditable(selection.focusNode);
|
|
29
|
+
if (contenteditable) {
|
|
30
|
+
if (!selection.isCollapsed) {
|
|
31
|
+
var ref;
|
|
32
|
+
const focusNode = ((ref = contenteditable.firstChild) === null || ref === void 0 ? void 0 : ref.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
33
|
+
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
selection.setBaseAndExtent(element, 0, element, 0);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { updateSelectionOnFocus };
|
|
@@ -1,53 +1,43 @@
|
|
|
1
|
-
import '../setup/index.js';
|
|
2
1
|
import '../utils/click/isClickableInput.js';
|
|
3
2
|
import '../utils/dataTransfer/Clipboard.js';
|
|
4
|
-
import '../event/eventMap.js';
|
|
5
|
-
import '../event/behavior/click.js';
|
|
6
|
-
import '../event/behavior/cut.js';
|
|
7
|
-
import '../event/behavior/keydown.js';
|
|
8
|
-
import '../event/behavior/keypress.js';
|
|
9
|
-
import '../event/behavior/keyup.js';
|
|
10
|
-
import '../event/behavior/paste.js';
|
|
11
|
-
import '@testing-library/dom';
|
|
12
|
-
import '../utils/edit/maxLength.js';
|
|
13
3
|
import '../utils/edit/isEditable.js';
|
|
4
|
+
import '../utils/edit/maxLength.js';
|
|
14
5
|
import '@testing-library/dom/dist/helpers.js';
|
|
15
6
|
import '../utils/keyDef/readNextDescriptor.js';
|
|
16
7
|
import '../utils/misc/level.js';
|
|
17
8
|
import { wait } from '../utils/misc/wait.js';
|
|
18
9
|
import '../options.js';
|
|
19
10
|
import { parseKeyDef } from './parseKeyDef.js';
|
|
20
|
-
import { Config } from '../setup/config.js';
|
|
21
11
|
|
|
22
12
|
async function keyboard(text) {
|
|
23
|
-
const actions = parseKeyDef(this
|
|
13
|
+
const actions = parseKeyDef(this.config.keyboardMap, text);
|
|
24
14
|
for(let i = 0; i < actions.length; i++){
|
|
25
|
-
await wait(this
|
|
26
|
-
await keyboardAction(this
|
|
15
|
+
await wait(this.config);
|
|
16
|
+
await keyboardAction(this, actions[i]);
|
|
27
17
|
}
|
|
28
18
|
}
|
|
29
|
-
async function keyboardAction(
|
|
30
|
-
const { system } =
|
|
19
|
+
async function keyboardAction(instance, { keyDef , releasePrevious , releaseSelf , repeat }) {
|
|
20
|
+
const { system } = instance;
|
|
31
21
|
// Release the key automatically if it was pressed before.
|
|
32
22
|
if (system.keyboard.isKeyPressed(keyDef)) {
|
|
33
|
-
await system.keyboard.keyup(
|
|
23
|
+
await system.keyboard.keyup(instance, keyDef);
|
|
34
24
|
}
|
|
35
25
|
if (!releasePrevious) {
|
|
36
26
|
for(let i = 1; i <= repeat; i++){
|
|
37
|
-
await system.keyboard.keydown(
|
|
27
|
+
await system.keyboard.keydown(instance, keyDef);
|
|
38
28
|
if (i < repeat) {
|
|
39
|
-
await wait(config);
|
|
29
|
+
await wait(instance.config);
|
|
40
30
|
}
|
|
41
31
|
}
|
|
42
32
|
// Release the key only on the last iteration on `state.repeatKey`.
|
|
43
33
|
if (releaseSelf) {
|
|
44
|
-
await system.keyboard.keyup(
|
|
34
|
+
await system.keyboard.keyup(instance, keyDef);
|
|
45
35
|
}
|
|
46
36
|
}
|
|
47
37
|
}
|
|
48
|
-
async function releaseAllKeys(
|
|
49
|
-
for (const k of
|
|
50
|
-
await
|
|
38
|
+
async function releaseAllKeys(instance) {
|
|
39
|
+
for (const k of instance.system.keyboard.getPressedKeys()){
|
|
40
|
+
await instance.system.keyboard.keyup(instance, k);
|
|
51
41
|
}
|
|
52
42
|
}
|
|
53
43
|
|
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import '../utils/click/isClickableInput.js';
|
|
2
2
|
import '../utils/dataTransfer/Clipboard.js';
|
|
3
|
-
import '../event/eventMap.js';
|
|
4
|
-
import '../event/behavior/click.js';
|
|
5
|
-
import '../event/behavior/cut.js';
|
|
6
|
-
import '../event/behavior/keydown.js';
|
|
7
|
-
import '../event/behavior/keypress.js';
|
|
8
|
-
import '../event/behavior/keyup.js';
|
|
9
|
-
import '../event/behavior/paste.js';
|
|
10
|
-
import '@testing-library/dom';
|
|
11
|
-
import '../utils/edit/maxLength.js';
|
|
12
3
|
import '../utils/edit/isEditable.js';
|
|
4
|
+
import '../utils/edit/maxLength.js';
|
|
13
5
|
import '@testing-library/dom/dist/helpers.js';
|
|
14
6
|
import { readNextDescriptor } from '../utils/keyDef/readNextDescriptor.js';
|
|
15
7
|
import '../utils/misc/level.js';
|
|
@@ -28,14 +20,17 @@ import '../options.js';
|
|
|
28
20
|
const defs = [];
|
|
29
21
|
do {
|
|
30
22
|
const { type , descriptor , consumedLength , releasePrevious , releaseSelf =true , repeat , } = readNextDescriptor(text, 'keyboard');
|
|
31
|
-
|
|
23
|
+
var ref;
|
|
24
|
+
const keyDef = (ref = keyboardMap.find((def)=>{
|
|
32
25
|
if (type === '[') {
|
|
33
|
-
|
|
26
|
+
var ref;
|
|
27
|
+
return ((ref = def.code) === null || ref === void 0 ? void 0 : ref.toLowerCase()) === descriptor.toLowerCase();
|
|
34
28
|
} else if (type === '{') {
|
|
35
|
-
|
|
29
|
+
var ref1;
|
|
30
|
+
return ((ref1 = def.key) === null || ref1 === void 0 ? void 0 : ref1.toLowerCase()) === descriptor.toLowerCase();
|
|
36
31
|
}
|
|
37
32
|
return def.key === descriptor;
|
|
38
|
-
})
|
|
33
|
+
})) !== null && ref !== void 0 ? ref : {
|
|
39
34
|
key: 'Unknown',
|
|
40
35
|
code: 'Unknown',
|
|
41
36
|
[type === '[' ? 'code' : 'key']: descriptor
|
package/dist/esm/options.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { defaultKeyMap } from './keyboard/keyMap.js';
|
|
2
|
-
import { defaultKeyMap as defaultKeyMap$1 } from './pointer/keyMap.js';
|
|
3
|
-
|
|
4
1
|
var PointerEventsCheckLevel;
|
|
5
2
|
(function(PointerEventsCheckLevel) {
|
|
6
3
|
PointerEventsCheckLevel[PointerEventsCheckLevel[/**
|
|
@@ -11,27 +8,5 @@ var PointerEventsCheckLevel;
|
|
|
11
8
|
PointerEventsCheckLevel[PointerEventsCheckLevel[/** Check each event target once */ "EachTarget"] = 1] = "EachTarget";
|
|
12
9
|
PointerEventsCheckLevel[PointerEventsCheckLevel[/** No pointer events check */ "Never"] = 0] = "Never";
|
|
13
10
|
})(PointerEventsCheckLevel || (PointerEventsCheckLevel = {}));
|
|
14
|
-
/**
|
|
15
|
-
* Default options applied when API is called per `userEvent.anyApi()`
|
|
16
|
-
*/ const defaultOptionsDirect = {
|
|
17
|
-
applyAccept: true,
|
|
18
|
-
autoModify: true,
|
|
19
|
-
delay: 0,
|
|
20
|
-
document: globalThis.document,
|
|
21
|
-
keyboardMap: defaultKeyMap,
|
|
22
|
-
pointerMap: defaultKeyMap$1,
|
|
23
|
-
pointerEventsCheck: PointerEventsCheckLevel.EachApiCall,
|
|
24
|
-
skipAutoClose: false,
|
|
25
|
-
skipClick: false,
|
|
26
|
-
skipHover: false,
|
|
27
|
-
writeToClipboard: false,
|
|
28
|
-
advanceTimers: ()=>Promise.resolve()
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Default options applied when API is called per `userEvent().anyApi()`
|
|
32
|
-
*/ const defaultOptionsSetup = {
|
|
33
|
-
...defaultOptionsDirect,
|
|
34
|
-
writeToClipboard: true
|
|
35
|
-
};
|
|
36
11
|
|
|
37
|
-
export { PointerEventsCheckLevel
|
|
12
|
+
export { PointerEventsCheckLevel };
|
|
@@ -1,26 +1,16 @@
|
|
|
1
|
-
import '../setup/index.js';
|
|
2
1
|
import '../utils/click/isClickableInput.js';
|
|
3
2
|
import '../utils/dataTransfer/Clipboard.js';
|
|
4
|
-
import '../event/eventMap.js';
|
|
5
|
-
import '../event/behavior/click.js';
|
|
6
|
-
import '../event/behavior/cut.js';
|
|
7
|
-
import '../event/behavior/keydown.js';
|
|
8
|
-
import '../event/behavior/keypress.js';
|
|
9
|
-
import '../event/behavior/keyup.js';
|
|
10
|
-
import '../event/behavior/paste.js';
|
|
11
|
-
import '@testing-library/dom';
|
|
12
|
-
import '../utils/edit/maxLength.js';
|
|
13
3
|
import '../utils/edit/isEditable.js';
|
|
4
|
+
import '../utils/edit/maxLength.js';
|
|
14
5
|
import '@testing-library/dom/dist/helpers.js';
|
|
15
6
|
import '../utils/keyDef/readNextDescriptor.js';
|
|
16
7
|
import { setLevelRef, ApiLevel } from '../utils/misc/level.js';
|
|
17
8
|
import { wait } from '../utils/misc/wait.js';
|
|
18
9
|
import '../options.js';
|
|
19
10
|
import { parseKeyDef } from './parseKeyDef.js';
|
|
20
|
-
import { Config } from '../setup/config.js';
|
|
21
11
|
|
|
22
12
|
async function pointer(input) {
|
|
23
|
-
const { pointerMap } = this
|
|
13
|
+
const { pointerMap } = this.config;
|
|
24
14
|
const actions = [];
|
|
25
15
|
(Array.isArray(input) ? input : [
|
|
26
16
|
input
|
|
@@ -37,48 +27,52 @@ async function pointer(input) {
|
|
|
37
27
|
}
|
|
38
28
|
});
|
|
39
29
|
for(let i = 0; i < actions.length; i++){
|
|
40
|
-
await wait(this
|
|
41
|
-
await pointerAction(this
|
|
30
|
+
await wait(this.config);
|
|
31
|
+
await pointerAction(this, actions[i]);
|
|
42
32
|
}
|
|
43
|
-
this
|
|
33
|
+
this.system.pointer.resetClickCount();
|
|
44
34
|
}
|
|
45
|
-
async function pointerAction(
|
|
46
|
-
|
|
47
|
-
const
|
|
35
|
+
async function pointerAction(instance, action) {
|
|
36
|
+
var ref, ref1;
|
|
37
|
+
const pointerName = 'pointerName' in action && action.pointerName ? action.pointerName : 'keyDef' in action ? instance.system.pointer.getPointerName(action.keyDef) : 'mouse';
|
|
38
|
+
const previousPosition = instance.system.pointer.getPreviousPosition(pointerName);
|
|
39
|
+
var _target, _coords, _node, _offset;
|
|
48
40
|
const position = {
|
|
49
|
-
target: action.target
|
|
50
|
-
coords: action.coords
|
|
41
|
+
target: (_target = action.target) !== null && _target !== void 0 ? _target : getPrevTarget(instance, previousPosition),
|
|
42
|
+
coords: (_coords = action.coords) !== null && _coords !== void 0 ? _coords : previousPosition === null || previousPosition === void 0 ? void 0 : previousPosition.coords,
|
|
51
43
|
caret: {
|
|
52
|
-
node: action.node
|
|
53
|
-
offset: action.offset
|
|
44
|
+
node: (_node = action.node) !== null && _node !== void 0 ? _node : hasCaretPosition(action) ? undefined : previousPosition === null || previousPosition === void 0 ? void 0 : (ref = previousPosition.caret) === null || ref === void 0 ? void 0 : ref.node,
|
|
45
|
+
offset: (_offset = action.offset) !== null && _offset !== void 0 ? _offset : hasCaretPosition(action) ? undefined : previousPosition === null || previousPosition === void 0 ? void 0 : (ref1 = previousPosition.caret) === null || ref1 === void 0 ? void 0 : ref1.offset
|
|
54
46
|
}
|
|
55
47
|
};
|
|
56
48
|
if ('keyDef' in action) {
|
|
57
|
-
if (
|
|
58
|
-
setLevelRef(
|
|
59
|
-
await
|
|
49
|
+
if (instance.system.pointer.isKeyPressed(action.keyDef)) {
|
|
50
|
+
setLevelRef(instance, ApiLevel.Trigger);
|
|
51
|
+
await instance.system.pointer.release(instance, action.keyDef, position);
|
|
60
52
|
}
|
|
61
53
|
if (!action.releasePrevious) {
|
|
62
|
-
setLevelRef(
|
|
63
|
-
await
|
|
54
|
+
setLevelRef(instance, ApiLevel.Trigger);
|
|
55
|
+
await instance.system.pointer.press(instance, action.keyDef, position);
|
|
64
56
|
if (action.releaseSelf) {
|
|
65
|
-
setLevelRef(
|
|
66
|
-
await
|
|
57
|
+
setLevelRef(instance, ApiLevel.Trigger);
|
|
58
|
+
await instance.system.pointer.release(instance, action.keyDef, position);
|
|
67
59
|
}
|
|
68
60
|
}
|
|
69
61
|
} else {
|
|
70
|
-
setLevelRef(
|
|
71
|
-
await
|
|
62
|
+
setLevelRef(instance, ApiLevel.Trigger);
|
|
63
|
+
await instance.system.pointer.move(instance, pointerName, position);
|
|
72
64
|
}
|
|
73
65
|
}
|
|
74
66
|
function hasCaretPosition(action) {
|
|
75
|
-
|
|
67
|
+
var _target, ref;
|
|
68
|
+
return !!((ref = (_target = action.target) !== null && _target !== void 0 ? _target : action.node) !== null && ref !== void 0 ? ref : action.offset !== undefined);
|
|
76
69
|
}
|
|
77
|
-
function getPrevTarget(
|
|
70
|
+
function getPrevTarget(instance, position) {
|
|
78
71
|
if (!position) {
|
|
79
72
|
throw new Error('This pointer has no previous position. Provide a target property!');
|
|
80
73
|
}
|
|
81
|
-
|
|
74
|
+
var _target;
|
|
75
|
+
return (_target = position.target) !== null && _target !== void 0 ? _target : instance.config.document.body;
|
|
82
76
|
}
|
|
83
77
|
|
|
84
78
|
export { pointer };
|
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import '../utils/click/isClickableInput.js';
|
|
2
2
|
import '../utils/dataTransfer/Clipboard.js';
|
|
3
|
-
import '../event/eventMap.js';
|
|
4
|
-
import '../event/behavior/click.js';
|
|
5
|
-
import '../event/behavior/cut.js';
|
|
6
|
-
import '../event/behavior/keydown.js';
|
|
7
|
-
import '../event/behavior/keypress.js';
|
|
8
|
-
import '../event/behavior/keyup.js';
|
|
9
|
-
import '../event/behavior/paste.js';
|
|
10
|
-
import '@testing-library/dom';
|
|
11
|
-
import '../utils/edit/maxLength.js';
|
|
12
3
|
import '../utils/edit/isEditable.js';
|
|
4
|
+
import '../utils/edit/maxLength.js';
|
|
13
5
|
import '@testing-library/dom/dist/helpers.js';
|
|
14
6
|
import { readNextDescriptor } from '../utils/keyDef/readNextDescriptor.js';
|
|
15
7
|
import '../utils/misc/level.js';
|
|
@@ -22,12 +22,12 @@ function hover(element, options = {}) {
|
|
|
22
22
|
return setupDirect(options).api.hover(element);
|
|
23
23
|
}
|
|
24
24
|
async function keyboard(text, options = {}) {
|
|
25
|
-
const {
|
|
26
|
-
return api.keyboard(text).then(()=>
|
|
25
|
+
const { api , system } = setupDirect(options);
|
|
26
|
+
return api.keyboard(text).then(()=>system);
|
|
27
27
|
}
|
|
28
28
|
async function pointer(input, options = {}) {
|
|
29
|
-
const {
|
|
30
|
-
return api.pointer(input).then(()=>
|
|
29
|
+
const { api , system } = setupDirect(options);
|
|
30
|
+
return api.pointer(input).then(()=>system);
|
|
31
31
|
}
|
|
32
32
|
function paste(clipboardData, options) {
|
|
33
33
|
return setupDirect(options).api.paste(clipboardData);
|
|
@@ -42,8 +42,8 @@ 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 {
|
|
46
|
-
|
|
45
|
+
const { api , system } = setupDirect(options);
|
|
46
|
+
system.pointer.setMousePosition({
|
|
47
47
|
target: element
|
|
48
48
|
});
|
|
49
49
|
return api.unhover(element);
|