@testing-library/user-event 14.0.0-alpha.1 → 14.0.0-alpha.13
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/{src/clear.d.ts → clear.d.ts} +0 -0
- package/dist/clear.js +14 -27
- package/dist/{src/click.d.ts → click.d.ts} +3 -2
- package/dist/click.js +23 -7
- package/dist/document/index.d.ts +10 -0
- package/dist/document/index.js +8 -10
- package/dist/document/interceptor.d.ts +15 -0
- package/dist/document/interceptor.js +7 -4
- package/dist/document/selection.d.ts +27 -0
- package/dist/document/selection.js +51 -28
- package/dist/{src/document → document}/value.d.ts +5 -1
- package/dist/document/value.js +27 -6
- package/dist/{src/hover.d.ts → hover.d.ts} +2 -2
- package/dist/hover.js +2 -2
- package/dist/{src/index.d.ts → index.d.ts} +0 -2
- package/dist/index.js +0 -8
- package/dist/{src/keyboard → keyboard}/getEventProps.d.ts +0 -2
- package/dist/keyboard/getEventProps.js +1 -7
- package/dist/{src/keyboard → keyboard}/getNextKeyDef.d.ts +0 -1
- package/dist/keyboard/getNextKeyDef.js +2 -32
- package/dist/{src/keyboard → keyboard}/index.d.ts +0 -1
- package/dist/keyboard/index.js +0 -8
- package/dist/{src/keyboard → keyboard}/keyMap.d.ts +0 -0
- package/dist/keyboard/keyMap.js +26 -46
- package/dist/{src/keyboard → keyboard}/keyboardImplementation.d.ts +0 -0
- package/dist/keyboard/keyboardImplementation.js +15 -17
- package/dist/{src/keyboard → keyboard}/plugins/arrow.d.ts +0 -0
- package/dist/keyboard/plugins/arrow.js +7 -12
- package/dist/{src/keyboard → keyboard}/plugins/character.d.ts +0 -0
- package/dist/keyboard/plugins/character.js +27 -45
- package/dist/keyboard/plugins/combination.d.ts +5 -0
- package/dist/keyboard/plugins/combination.js +17 -0
- package/dist/{src/keyboard → keyboard}/plugins/control.d.ts +0 -0
- package/dist/keyboard/plugins/control.js +4 -12
- package/dist/{src/keyboard → keyboard}/plugins/functional.d.ts +0 -0
- package/dist/keyboard/plugins/functional.js +23 -11
- package/dist/{src/keyboard → keyboard}/plugins/index.d.ts +0 -1
- package/dist/keyboard/plugins/index.js +4 -11
- package/dist/{src/keyboard → keyboard}/shared/fireChangeForInputTimeIfValid.d.ts +0 -0
- package/dist/{src/keyboard → keyboard}/shared/index.d.ts +0 -0
- package/dist/{src/keyboard → keyboard}/types.d.ts +0 -2
- package/dist/paste.d.ts +6 -0
- package/dist/paste.js +40 -43
- package/dist/{src/pointer → pointer}/index.d.ts +0 -0
- package/dist/{src/pointer → pointer}/keyMap.d.ts +0 -0
- package/dist/{src/pointer → pointer}/parseKeyDef.d.ts +0 -0
- package/dist/{src/pointer → pointer}/pointerAction.d.ts +2 -6
- package/dist/pointer/pointerAction.js +2 -26
- package/dist/pointer/pointerMove.d.ts +5 -0
- package/dist/pointer/pointerMove.js +49 -5
- package/dist/pointer/pointerPress.d.ts +7 -0
- package/dist/pointer/pointerPress.js +135 -29
- package/dist/pointer/resolveSelectionTarget.d.ts +5 -0
- package/dist/pointer/resolveSelectionTarget.js +75 -0
- package/dist/{src/pointer → pointer}/types.d.ts +18 -4
- package/dist/{src/selectOptions.d.ts → selectOptions.d.ts} +2 -2
- package/dist/selectOptions.js +25 -26
- package/dist/{src/setup.d.ts → setup.d.ts} +5 -2
- package/dist/setup.js +32 -21
- package/dist/tab.d.ts +5 -0
- package/dist/tab.js +3 -132
- package/dist/{src/type.d.ts → type.d.ts} +0 -0
- package/dist/type.js +3 -19
- package/dist/{src/upload.d.ts → upload.d.ts} +0 -1
- package/dist/upload.js +1 -1
- package/dist/{src/utils → utils}/click/isClickableInput.d.ts +0 -0
- package/dist/utils/dataTransfer/Blob.d.ts +1 -0
- package/dist/utils/dataTransfer/Blob.js +21 -0
- package/dist/utils/dataTransfer/Clipboard.d.ts +7 -0
- package/dist/utils/dataTransfer/Clipboard.js +143 -0
- package/dist/utils/dataTransfer/DataTransfer.d.ts +1 -0
- package/dist/utils/dataTransfer/DataTransfer.js +143 -0
- package/dist/utils/dataTransfer/FileList.d.ts +1 -0
- package/dist/utils/dataTransfer/FileList.js +13 -0
- package/dist/{src/utils → utils}/edit/buildTimeValue.d.ts +0 -0
- package/dist/utils/edit/calculateNewValue.d.ts +14 -0
- package/dist/utils/edit/calculateNewValue.js +19 -21
- package/dist/utils/edit/editInputElement.d.ts +16 -0
- package/dist/utils/edit/editInputElement.js +53 -0
- package/dist/{src/utils → utils}/edit/getValue.d.ts +0 -0
- package/dist/utils/edit/getValue.js +1 -3
- package/dist/utils/edit/isContentEditable.d.ts +7 -0
- package/dist/utils/edit/isContentEditable.js +14 -0
- package/dist/{src/utils → utils}/edit/isEditable.d.ts +1 -0
- package/dist/{src/utils → utils}/edit/isValidDateValue.d.ts +0 -0
- package/dist/{src/utils → utils}/edit/isValidInputTimeValue.d.ts +0 -0
- package/dist/{src/utils → utils}/edit/maxLength.d.ts +0 -0
- package/dist/utils/edit/prepareInput.d.ts +7 -0
- package/dist/utils/edit/prepareInput.js +77 -0
- package/dist/{src/utils → utils}/focus/blur.d.ts +0 -0
- package/dist/{src/utils → utils}/focus/focus.d.ts +0 -0
- package/dist/utils/focus/focus.js +3 -0
- package/dist/{src/utils → utils}/focus/getActiveElement.d.ts +0 -0
- package/dist/utils/focus/getTabDestination.d.ts +1 -0
- package/dist/utils/focus/getTabDestination.js +71 -0
- package/dist/{src/utils → utils}/focus/isFocusable.d.ts +0 -0
- package/dist/utils/focus/selectAll.d.ts +5 -0
- package/dist/utils/focus/selectAll.js +51 -0
- package/dist/utils/focus/selection.d.ts +42 -0
- package/dist/utils/focus/selection.js +190 -0
- package/dist/{src/utils → utils}/focus/selector.d.ts +0 -0
- package/dist/{src/utils → utils}/index.d.ts +9 -5
- package/dist/utils/index.js +98 -46
- package/dist/{src/utils → utils}/keyDef/readNextDescriptor.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/eventWrapper.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/findClosest.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/hasFormSubmit.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/hasPointerEvents.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/isDescendantOrSelf.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/isDisabled.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/isElementType.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/isVisible.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/wait.d.ts +0 -0
- package/dist/{src/utils → utils}/pointer/firePointerEvents.d.ts +13 -11
- package/dist/utils/pointer/firePointerEvents.js +62 -5
- package/dist/{src/utils → utils}/pointer/mouseButtons.d.ts +0 -0
- package/package.json +2 -2
- package/dist/document/applyNative.js +0 -28
- package/dist/keyboard/specialCharMap.js +0 -30
- package/dist/src/document/applyNative.d.ts +0 -8
- package/dist/src/document/index.d.ts +0 -10
- package/dist/src/document/interceptor.d.ts +0 -5
- package/dist/src/document/selection.d.ts +0 -18
- package/dist/src/keyboard/specialCharMap.d.ts +0 -22
- package/dist/src/paste.d.ts +0 -7
- package/dist/src/pointer/pointerMove.d.ts +0 -5
- package/dist/src/pointer/pointerPress.d.ts +0 -7
- package/dist/src/tab.d.ts +0 -6
- package/dist/src/utils/edit/calculateNewValue.d.ts +0 -7
- package/dist/src/utils/edit/cursorPosition.d.ts +0 -2
- package/dist/src/utils/edit/fireInputEvent.d.ts +0 -8
- package/dist/src/utils/edit/isContentEditable.d.ts +0 -3
- package/dist/src/utils/edit/selectionRange.d.ts +0 -5
- package/dist/src/utils/misc/isDocument.d.ts +0 -1
- package/dist/src/utils/pointer/fakeEvent.d.ts +0 -16
- package/dist/tests/_helpers/custom-element.d.ts +0 -8
- package/dist/tests/_helpers/utils.d.ts +0 -73
- package/dist/tests/_setup-env.d.ts +0 -1
- package/dist/tests/clear.d.ts +0 -1
- package/dist/tests/click/click.d.ts +0 -1
- package/dist/tests/click/dblclick.d.ts +0 -1
- package/dist/tests/document/index.d.ts +0 -1
- package/dist/tests/document/selectionRange.d.ts +0 -1
- package/dist/tests/hover/hover.d.ts +0 -1
- package/dist/tests/hover/unhover.d.ts +0 -1
- package/dist/tests/keyboard/getNextKeyDef.d.ts +0 -1
- package/dist/tests/keyboard/index.d.ts +0 -1
- package/dist/tests/keyboard/keyboardImplementation.d.ts +0 -1
- package/dist/tests/keyboard/plugin/arrow.d.ts +0 -1
- package/dist/tests/keyboard/plugin/character.d.ts +0 -1
- package/dist/tests/keyboard/plugin/control.d.ts +0 -1
- package/dist/tests/keyboard/plugin/functional.d.ts +0 -1
- package/dist/tests/keyboard/shared/fireInputEvent.d.ts +0 -1
- package/dist/tests/paste.d.ts +0 -1
- package/dist/tests/pointer/index.d.ts +0 -1
- package/dist/tests/react/keyboard.d.ts +0 -1
- package/dist/tests/react/type.d.ts +0 -1
- package/dist/tests/selectOptions/deselect.d.ts +0 -1
- package/dist/tests/selectOptions/select.d.ts +0 -1
- package/dist/tests/setup.d.ts +0 -10
- package/dist/tests/tab.d.ts +0 -1
- package/dist/tests/type/index.d.ts +0 -1
- package/dist/tests/type/modifiers.d.ts +0 -1
- package/dist/tests/upload.d.ts +0 -1
- package/dist/tests/utils/edit/calculateNewValue.d.ts +0 -1
- package/dist/tests/utils/edit/isContentEditable.d.ts +0 -1
- package/dist/tests/utils/focus/blur.d.ts +0 -1
- package/dist/tests/utils/focus/focus.d.ts +0 -1
- package/dist/tests/utils/misc/hasPointerEvents.d.ts +0 -1
- package/dist/tests/utils/misc/isDescendantOrSelf.d.ts +0 -1
- package/dist/tests/utils/misc/isElementType.d.ts +0 -1
- package/dist/tests/utils/misc/isVisible.d.ts +0 -1
- package/dist/utils/edit/cursorPosition.js +0 -35
- package/dist/utils/edit/fireInputEvent.js +0 -55
- package/dist/utils/edit/selectionRange.js +0 -64
- package/dist/utils/misc/dom-helpers.d.ts +0 -3
- package/dist/utils/misc/isDocument.js +0 -10
- package/dist/utils/pointer/fakeEvent.js +0 -82
package/dist/keyboard/index.js
CHANGED
|
@@ -6,12 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.createKeyboardState = createKeyboardState;
|
|
7
7
|
exports.keyboard = keyboard;
|
|
8
8
|
exports.keyboardImplementationWrapper = keyboardImplementationWrapper;
|
|
9
|
-
Object.defineProperty(exports, "specialCharMap", {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function () {
|
|
12
|
-
return _specialCharMap.specialCharMap;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
9
|
|
|
16
10
|
var _dom = require("@testing-library/dom");
|
|
17
11
|
|
|
@@ -21,8 +15,6 @@ var _keyboardImplementation = require("./keyboardImplementation");
|
|
|
21
15
|
|
|
22
16
|
var _keyMap = require("./keyMap");
|
|
23
17
|
|
|
24
|
-
var _specialCharMap = require("./specialCharMap");
|
|
25
|
-
|
|
26
18
|
function keyboard(text, options) {
|
|
27
19
|
var _options$delay;
|
|
28
20
|
|
|
File without changes
|
package/dist/keyboard/keyMap.js
CHANGED
|
@@ -32,108 +32,88 @@ const defaultKeyMap = [// alphanumeric keys
|
|
|
32
32
|
}, {
|
|
33
33
|
code: 'AltLeft',
|
|
34
34
|
key: 'Alt',
|
|
35
|
-
location: _types.DOM_KEY_LOCATION.LEFT
|
|
36
|
-
keyCode: 18
|
|
35
|
+
location: _types.DOM_KEY_LOCATION.LEFT
|
|
37
36
|
}, {
|
|
38
37
|
code: 'AltRight',
|
|
39
38
|
key: 'Alt',
|
|
40
|
-
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
41
|
-
keyCode: 18
|
|
39
|
+
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
42
40
|
}, {
|
|
43
41
|
code: 'ShiftLeft',
|
|
44
42
|
key: 'Shift',
|
|
45
|
-
location: _types.DOM_KEY_LOCATION.LEFT
|
|
46
|
-
keyCode: 16
|
|
43
|
+
location: _types.DOM_KEY_LOCATION.LEFT
|
|
47
44
|
}, {
|
|
48
45
|
code: 'ShiftRight',
|
|
49
46
|
key: 'Shift',
|
|
50
|
-
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
51
|
-
keyCode: 16
|
|
47
|
+
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
52
48
|
}, {
|
|
53
49
|
code: 'ControlLeft',
|
|
54
50
|
key: 'Control',
|
|
55
|
-
location: _types.DOM_KEY_LOCATION.LEFT
|
|
56
|
-
keyCode: 17
|
|
51
|
+
location: _types.DOM_KEY_LOCATION.LEFT
|
|
57
52
|
}, {
|
|
58
53
|
code: 'ControlRight',
|
|
59
54
|
key: 'Control',
|
|
60
|
-
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
61
|
-
keyCode: 17
|
|
55
|
+
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
62
56
|
}, {
|
|
63
57
|
code: 'MetaLeft',
|
|
64
58
|
key: 'Meta',
|
|
65
|
-
location: _types.DOM_KEY_LOCATION.LEFT
|
|
66
|
-
keyCode: 93
|
|
59
|
+
location: _types.DOM_KEY_LOCATION.LEFT
|
|
67
60
|
}, {
|
|
68
61
|
code: 'MetaRight',
|
|
69
62
|
key: 'Meta',
|
|
70
|
-
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
71
|
-
keyCode: 93
|
|
63
|
+
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
72
64
|
}, {
|
|
73
65
|
code: 'OSLeft',
|
|
74
66
|
key: 'OS',
|
|
75
|
-
location: _types.DOM_KEY_LOCATION.LEFT
|
|
76
|
-
keyCode: 91
|
|
67
|
+
location: _types.DOM_KEY_LOCATION.LEFT
|
|
77
68
|
}, {
|
|
78
69
|
code: 'OSRight',
|
|
79
70
|
key: 'OS',
|
|
80
|
-
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
81
|
-
|
|
71
|
+
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
72
|
+
}, {
|
|
73
|
+
code: 'Tab',
|
|
74
|
+
key: 'Tab'
|
|
82
75
|
}, {
|
|
83
76
|
code: 'CapsLock',
|
|
84
|
-
key: 'CapsLock'
|
|
85
|
-
keyCode: 20
|
|
77
|
+
key: 'CapsLock'
|
|
86
78
|
}, {
|
|
87
79
|
code: 'Backspace',
|
|
88
|
-
key: 'Backspace'
|
|
89
|
-
keyCode: 8
|
|
80
|
+
key: 'Backspace'
|
|
90
81
|
}, {
|
|
91
82
|
code: 'Enter',
|
|
92
|
-
key: 'Enter'
|
|
93
|
-
keyCode: 13
|
|
83
|
+
key: 'Enter'
|
|
94
84
|
}, // function
|
|
95
85
|
{
|
|
96
86
|
code: 'Escape',
|
|
97
|
-
key: 'Escape'
|
|
98
|
-
keyCode: 27
|
|
87
|
+
key: 'Escape'
|
|
99
88
|
}, // arrows
|
|
100
89
|
{
|
|
101
90
|
code: 'ArrowUp',
|
|
102
|
-
key: 'ArrowUp'
|
|
103
|
-
keyCode: 38
|
|
91
|
+
key: 'ArrowUp'
|
|
104
92
|
}, {
|
|
105
93
|
code: 'ArrowDown',
|
|
106
|
-
key: 'ArrowDown'
|
|
107
|
-
keyCode: 40
|
|
94
|
+
key: 'ArrowDown'
|
|
108
95
|
}, {
|
|
109
96
|
code: 'ArrowLeft',
|
|
110
|
-
key: 'ArrowLeft'
|
|
111
|
-
keyCode: 37
|
|
97
|
+
key: 'ArrowLeft'
|
|
112
98
|
}, {
|
|
113
99
|
code: 'ArrowRight',
|
|
114
|
-
key: 'ArrowRight'
|
|
115
|
-
keyCode: 39
|
|
100
|
+
key: 'ArrowRight'
|
|
116
101
|
}, // control pad
|
|
117
102
|
{
|
|
118
103
|
code: 'Home',
|
|
119
|
-
key: 'Home'
|
|
120
|
-
keyCode: 36
|
|
104
|
+
key: 'Home'
|
|
121
105
|
}, {
|
|
122
106
|
code: 'End',
|
|
123
|
-
key: 'End'
|
|
124
|
-
keyCode: 35
|
|
107
|
+
key: 'End'
|
|
125
108
|
}, {
|
|
126
109
|
code: 'Delete',
|
|
127
|
-
key: 'Delete'
|
|
128
|
-
keyCode: 46
|
|
110
|
+
key: 'Delete'
|
|
129
111
|
}, {
|
|
130
112
|
code: 'PageUp',
|
|
131
|
-
key: 'PageUp'
|
|
132
|
-
keyCode: 33
|
|
113
|
+
key: 'PageUp'
|
|
133
114
|
}, {
|
|
134
115
|
code: 'PageDown',
|
|
135
|
-
key: 'PageDown'
|
|
136
|
-
keyCode: 34
|
|
116
|
+
key: 'PageDown'
|
|
137
117
|
} // TODO: add mappings
|
|
138
118
|
];
|
|
139
119
|
exports.defaultKeyMap = defaultKeyMap;
|
|
File without changes
|
|
@@ -36,27 +36,23 @@ async function keyboardImplementation(text, options, state) {
|
|
|
36
36
|
releaseSelf,
|
|
37
37
|
repeat
|
|
38
38
|
} = (_state$repeatKey = state.repeatKey) != null ? _state$repeatKey : (0, _getNextKeyDef.getNextKeyDef)(text, options);
|
|
39
|
-
const
|
|
39
|
+
const pressed = state.pressed.find(p => p.keyDef === keyDef); // Release the key automatically if it was pressed before.
|
|
40
|
+
// Do not release the key on iterations on `state.repeatKey`.
|
|
40
41
|
|
|
41
|
-
if (!
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (pressed && !state.repeatKey) {
|
|
46
|
-
keyup(keyDef, getCurrentElement, options, state, pressed.unpreventedDefault);
|
|
47
|
-
}
|
|
42
|
+
if (pressed && !state.repeatKey) {
|
|
43
|
+
keyup(keyDef, getCurrentElement, options, state, pressed.unpreventedDefault);
|
|
44
|
+
}
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
if (!releasePrevious) {
|
|
47
|
+
const unpreventedDefault = keydown(keyDef, getCurrentElement, options, state);
|
|
51
48
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
if (unpreventedDefault && hasKeyPress(keyDef, state)) {
|
|
50
|
+
keypress(keyDef, getCurrentElement, options, state);
|
|
51
|
+
} // Release the key only on the last iteration on `state.repeatKey`.
|
|
55
52
|
|
|
56
53
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
54
|
+
if (releaseSelf && repeat <= 1) {
|
|
55
|
+
keyup(keyDef, getCurrentElement, options, state, unpreventedDefault);
|
|
60
56
|
}
|
|
61
57
|
}
|
|
62
58
|
|
|
@@ -129,7 +125,9 @@ function keydown(keyDef, getCurrentElement, options, state) {
|
|
|
129
125
|
function keypress(keyDef, getCurrentElement, options, state) {
|
|
130
126
|
const element = getCurrentElement();
|
|
131
127
|
|
|
132
|
-
const unpreventedDefault = _dom.fireEvent.keyPress(element, (0, _getEventProps.getKeyEventProps)(keyDef, state)
|
|
128
|
+
const unpreventedDefault = _dom.fireEvent.keyPress(element, { ...(0, _getEventProps.getKeyEventProps)(keyDef, state),
|
|
129
|
+
charCode: keyDef.key === 'Enter' ? 13 : String(keyDef.key).charCodeAt(0)
|
|
130
|
+
});
|
|
133
131
|
|
|
134
132
|
if (unpreventedDefault) {
|
|
135
133
|
applyPlugins(plugins.keypressBehavior, keyDef, getCurrentElement(), options, state);
|
|
File without changes
|
|
@@ -7,6 +7,8 @@ exports.keydownBehavior = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _utils = require("../../utils");
|
|
9
9
|
|
|
10
|
+
var _document = require("../../document");
|
|
11
|
+
|
|
10
12
|
/**
|
|
11
13
|
* This file should contain behavior for arrow keys as described here:
|
|
12
14
|
* https://w3c.github.io/uievents-code/#key-arrowpad-section
|
|
@@ -15,19 +17,12 @@ const keydownBehavior = [{
|
|
|
15
17
|
// TODO: implement for contentEditable
|
|
16
18
|
matches: (keyDef, element) => (keyDef.key === 'ArrowLeft' || keyDef.key === 'ArrowRight') && (0, _utils.isElementType)(element, ['input', 'textarea']),
|
|
17
19
|
handle: (keyDef, element) => {
|
|
18
|
-
|
|
20
|
+
const selection = (0, _document.getUISelection)(element); // TODO: implement shift/ctrl
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
const direction = keyDef.key === 'ArrowLeft' ? -1 : 1;
|
|
25
|
-
const newPos = (_ref = selectionStart === selectionEnd ? (selectionStart != null ? selectionStart :
|
|
26
|
-
/* istanbul ignore next */
|
|
27
|
-
0) + direction : direction < 0 ? selectionStart : selectionEnd) != null ? _ref :
|
|
28
|
-
/* istanbul ignore next */
|
|
29
|
-
0;
|
|
30
|
-
(0, _utils.setSelectionRange)(element, newPos, newPos);
|
|
22
|
+
(0, _utils.setSelection)({
|
|
23
|
+
focusNode: element,
|
|
24
|
+
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + (keyDef.key === 'ArrowLeft' ? -1 : 1) : keyDef.key === 'ArrowLeft' ? selection.startOffset : selection.endOffset
|
|
25
|
+
});
|
|
31
26
|
}
|
|
32
27
|
}];
|
|
33
28
|
exports.keydownBehavior = keydownBehavior;
|
|
File without changes
|
|
@@ -36,15 +36,18 @@ const keypressBehavior = [{
|
|
|
36
36
|
|
|
37
37
|
const {
|
|
38
38
|
newValue,
|
|
39
|
-
|
|
40
|
-
} = (0, _utils.calculateNewValue)(newEntry, element);
|
|
39
|
+
newOffset
|
|
40
|
+
} = (0, _utils.calculateNewValue)(newEntry, element, (0, _utils.getInputRange)(element));
|
|
41
41
|
const prevValue = (0, _utils.getValue)(element); // this check was provided by fireInputEventIfNeeded
|
|
42
42
|
// TODO: verify if it is even needed by this handler
|
|
43
43
|
|
|
44
44
|
if (prevValue !== newValue) {
|
|
45
|
-
(0, _utils.
|
|
45
|
+
(0, _utils.editInputElement)(element, {
|
|
46
46
|
newValue,
|
|
47
|
-
|
|
47
|
+
newSelection: {
|
|
48
|
+
node: element,
|
|
49
|
+
offset: newOffset
|
|
50
|
+
},
|
|
48
51
|
eventOverrides: {
|
|
49
52
|
data: keyDef.key,
|
|
50
53
|
inputType: 'insertText'
|
|
@@ -77,15 +80,18 @@ const keypressBehavior = [{
|
|
|
77
80
|
|
|
78
81
|
const {
|
|
79
82
|
newValue,
|
|
80
|
-
|
|
81
|
-
} = (0, _utils.calculateNewValue)(newEntry, element);
|
|
83
|
+
newOffset
|
|
84
|
+
} = (0, _utils.calculateNewValue)(newEntry, element, (0, _utils.getInputRange)(element));
|
|
82
85
|
const prevValue = (0, _utils.getValue)(element); // this check was provided by fireInputEventIfNeeded
|
|
83
86
|
// TODO: verify if it is even needed by this handler
|
|
84
87
|
|
|
85
88
|
if (prevValue !== newValue) {
|
|
86
|
-
(0, _utils.
|
|
89
|
+
(0, _utils.editInputElement)(element, {
|
|
87
90
|
newValue,
|
|
88
|
-
|
|
91
|
+
newSelection: {
|
|
92
|
+
node: element,
|
|
93
|
+
offset: newOffset
|
|
94
|
+
},
|
|
89
95
|
eventOverrides: {
|
|
90
96
|
data: keyDef.key,
|
|
91
97
|
inputType: 'insertText'
|
|
@@ -120,9 +126,10 @@ const keypressBehavior = [{
|
|
|
120
126
|
}
|
|
121
127
|
|
|
122
128
|
const {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
} = (0, _utils.
|
|
129
|
+
getNewValue,
|
|
130
|
+
commit
|
|
131
|
+
} = (0, _utils.prepareInput)(keyDef.key, element);
|
|
132
|
+
const newValue = getNewValue(); // the browser allows some invalid input but not others
|
|
126
133
|
// it allows up to two '-' at any place before any 'e' or one directly following 'e'
|
|
127
134
|
// it allows one '.' at any place before e
|
|
128
135
|
|
|
@@ -132,54 +139,29 @@ const keypressBehavior = [{
|
|
|
132
139
|
return;
|
|
133
140
|
}
|
|
134
141
|
|
|
135
|
-
(
|
|
136
|
-
newValue,
|
|
137
|
-
newSelectionStart,
|
|
138
|
-
eventOverrides: {
|
|
139
|
-
data: keyDef.key,
|
|
140
|
-
inputType: 'insertText'
|
|
141
|
-
}
|
|
142
|
-
});
|
|
142
|
+
commit();
|
|
143
143
|
}
|
|
144
144
|
}, {
|
|
145
145
|
matches: (keyDef, element) => {
|
|
146
146
|
var _keyDef$key4;
|
|
147
147
|
|
|
148
|
-
return ((_keyDef$key4 = keyDef.key) == null ? void 0 : _keyDef$key4.length) === 1 && ((0, _utils.
|
|
148
|
+
return ((_keyDef$key4 = keyDef.key) == null ? void 0 : _keyDef$key4.length) === 1 && ((0, _utils.isEditableInput)(element) || (0, _utils.isElementType)(element, 'textarea', {
|
|
149
149
|
readOnly: false
|
|
150
|
-
})
|
|
150
|
+
}) || (0, _utils.isContentEditable)(element)) && (0, _utils.getSpaceUntilMaxLength)(element) !== 0;
|
|
151
151
|
},
|
|
152
152
|
handle: (keyDef, element) => {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
} = (0, _utils.calculateNewValue)(keyDef.key, element);
|
|
157
|
-
(0, _utils.fireInputEvent)(element, {
|
|
158
|
-
newValue,
|
|
159
|
-
newSelectionStart,
|
|
160
|
-
eventOverrides: {
|
|
161
|
-
data: keyDef.key,
|
|
162
|
-
inputType: 'insertText'
|
|
163
|
-
}
|
|
164
|
-
});
|
|
153
|
+
var _prepareInput;
|
|
154
|
+
|
|
155
|
+
(_prepareInput = (0, _utils.prepareInput)(keyDef.key, element)) == null ? void 0 : _prepareInput.commit();
|
|
165
156
|
}
|
|
166
157
|
}, {
|
|
167
158
|
matches: (keyDef, element) => keyDef.key === 'Enter' && ((0, _utils.isElementType)(element, 'textarea', {
|
|
168
159
|
readOnly: false
|
|
169
160
|
}) || (0, _utils.isContentEditable)(element)) && (0, _utils.getSpaceUntilMaxLength)(element) !== 0,
|
|
170
161
|
handle: (keyDef, element, options, state) => {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
} = (0, _utils.calculateNewValue)('\n', element);
|
|
175
|
-
const inputType = (0, _utils.isContentEditable)(element) && !state.modifiers.shift ? 'insertParagraph' : 'insertLineBreak';
|
|
176
|
-
(0, _utils.fireInputEvent)(element, {
|
|
177
|
-
newValue,
|
|
178
|
-
newSelectionStart,
|
|
179
|
-
eventOverrides: {
|
|
180
|
-
inputType
|
|
181
|
-
}
|
|
182
|
-
});
|
|
162
|
+
var _prepareInput2;
|
|
163
|
+
|
|
164
|
+
(_prepareInput2 = (0, _utils.prepareInput)('\n', element, (0, _utils.isContentEditable)(element) && !state.modifiers.shift ? 'insertParagraph' : 'insertLineBreak')) == null ? void 0 : _prepareInput2.commit();
|
|
183
165
|
}
|
|
184
166
|
}];
|
|
185
167
|
exports.keypressBehavior = keypressBehavior;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.keydownBehavior = void 0;
|
|
7
|
+
|
|
8
|
+
var _utils = require("../../utils");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Default behavior for key combinations
|
|
12
|
+
*/
|
|
13
|
+
const keydownBehavior = [{
|
|
14
|
+
matches: (keyDef, element, options, state) => keyDef.code === 'KeyA' && state.modifiers.ctrl,
|
|
15
|
+
handle: (keyDef, element) => (0, _utils.selectAll)(element)
|
|
16
|
+
}];
|
|
17
|
+
exports.keydownBehavior = keydownBehavior;
|
|
File without changes
|
|
@@ -42,19 +42,11 @@ const keydownBehavior = [{
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}, {
|
|
45
|
-
matches: (keyDef, element) => keyDef.key === 'Delete' && (0, _utils.isEditable)(element)
|
|
45
|
+
matches: (keyDef, element) => keyDef.key === 'Delete' && (0, _utils.isEditable)(element),
|
|
46
46
|
handle: (keDef, element) => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
} = (0, _utils.calculateNewValue)('', element, undefined, undefined, 'forward');
|
|
51
|
-
(0, _utils.fireInputEvent)(element, {
|
|
52
|
-
newValue,
|
|
53
|
-
newSelectionStart,
|
|
54
|
-
eventOverrides: {
|
|
55
|
-
inputType: 'deleteContentForward'
|
|
56
|
-
}
|
|
57
|
-
});
|
|
47
|
+
var _prepareInput;
|
|
48
|
+
|
|
49
|
+
(_prepareInput = (0, _utils.prepareInput)('', element, 'deleteContentForward')) == null ? void 0 : _prepareInput.commit();
|
|
58
50
|
}
|
|
59
51
|
}];
|
|
60
52
|
exports.keydownBehavior = keydownBehavior;
|
|
File without changes
|
|
@@ -7,6 +7,8 @@ exports.preKeyupBehavior = exports.preKeydownBehavior = exports.postKeyupBehavio
|
|
|
7
7
|
|
|
8
8
|
var _dom = require("@testing-library/dom");
|
|
9
9
|
|
|
10
|
+
var _document = require("../../document");
|
|
11
|
+
|
|
10
12
|
var _utils = require("../../utils");
|
|
11
13
|
|
|
12
14
|
var _getEventProps = require("../getEventProps");
|
|
@@ -51,19 +53,29 @@ const keydownBehavior = [{
|
|
|
51
53
|
state.modifiers.caps = !state.modifiers.caps;
|
|
52
54
|
}
|
|
53
55
|
}, {
|
|
54
|
-
matches: (keyDef, element) => keyDef.key === 'Backspace' && (0, _utils.isEditable)(element)
|
|
56
|
+
matches: (keyDef, element) => keyDef.key === 'Backspace' && (0, _utils.isEditable)(element),
|
|
55
57
|
handle: (keyDef, element) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
var _prepareInput;
|
|
59
|
+
|
|
60
|
+
(_prepareInput = (0, _utils.prepareInput)('', element, 'deleteContentBackward')) == null ? void 0 : _prepareInput.commit();
|
|
61
|
+
}
|
|
62
|
+
}, {
|
|
63
|
+
matches: keyDef => keyDef.key === 'Tab',
|
|
64
|
+
handle: (keyDef, element, options, state) => {
|
|
65
|
+
const dest = (0, _utils.getTabDestination)(element, state.modifiers.shift);
|
|
66
|
+
|
|
67
|
+
if (dest === element.ownerDocument.body) {
|
|
68
|
+
(0, _utils.blur)(element);
|
|
69
|
+
} else {
|
|
70
|
+
(0, _utils.focus)(dest);
|
|
71
|
+
|
|
72
|
+
if ((0, _utils.isElementType)(dest, ['input', 'textarea'])) {
|
|
73
|
+
(0, _document.setUISelection)(dest, {
|
|
74
|
+
anchorOffset: 0,
|
|
75
|
+
focusOffset: dest.value.length
|
|
76
|
+
});
|
|
65
77
|
}
|
|
66
|
-
}
|
|
78
|
+
}
|
|
67
79
|
}
|
|
68
80
|
}];
|
|
69
81
|
exports.keydownBehavior = keydownBehavior;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { behaviorPlugin } from '../types';
|
|
2
|
-
export declare const replaceBehavior: behaviorPlugin[];
|
|
3
2
|
export declare const preKeydownBehavior: behaviorPlugin[];
|
|
4
3
|
export declare const keydownBehavior: behaviorPlugin[];
|
|
5
4
|
export declare const keypressBehavior: behaviorPlugin[];
|
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
var _utils = require("../../utils");
|
|
6
|
+
exports.preKeyupBehavior = exports.preKeydownBehavior = exports.postKeyupBehavior = exports.keyupBehavior = exports.keypressBehavior = exports.keydownBehavior = void 0;
|
|
9
7
|
|
|
10
8
|
var arrowKeys = _interopRequireWildcard(require("./arrow"));
|
|
11
9
|
|
|
@@ -15,20 +13,15 @@ var characterKeys = _interopRequireWildcard(require("./character"));
|
|
|
15
13
|
|
|
16
14
|
var functionalKeys = _interopRequireWildcard(require("./functional"));
|
|
17
15
|
|
|
16
|
+
var combination = _interopRequireWildcard(require("./combination"));
|
|
17
|
+
|
|
18
18
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
19
|
|
|
20
20
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
21
|
|
|
22
|
-
const replaceBehavior = [{
|
|
23
|
-
matches: (keyDef, element) => keyDef.key === 'selectall' && (0, _utils.isElementType)(element, ['input', 'textarea']),
|
|
24
|
-
handle: (keyDef, element) => {
|
|
25
|
-
(0, _utils.setSelectionRange)(element, 0, (0, _utils.getValue)(element).length);
|
|
26
|
-
}
|
|
27
|
-
}];
|
|
28
|
-
exports.replaceBehavior = replaceBehavior;
|
|
29
22
|
const preKeydownBehavior = [...functionalKeys.preKeydownBehavior];
|
|
30
23
|
exports.preKeydownBehavior = preKeydownBehavior;
|
|
31
|
-
const keydownBehavior = [...arrowKeys.keydownBehavior, ...controlKeys.keydownBehavior, ...functionalKeys.keydownBehavior];
|
|
24
|
+
const keydownBehavior = [...arrowKeys.keydownBehavior, ...controlKeys.keydownBehavior, ...functionalKeys.keydownBehavior, ...combination.keydownBehavior];
|
|
32
25
|
exports.keydownBehavior = keydownBehavior;
|
|
33
26
|
const keypressBehavior = [...functionalKeys.keypressBehavior, ...characterKeys.keypressBehavior];
|
|
34
27
|
exports.keypressBehavior = keypressBehavior;
|
|
File without changes
|
|
File without changes
|
|
@@ -67,8 +67,6 @@ export interface keyboardKey {
|
|
|
67
67
|
key?: string;
|
|
68
68
|
/** Location on the keyboard for keys with multiple representation */
|
|
69
69
|
location?: DOM_KEY_LOCATION;
|
|
70
|
-
/** keyCode for legacy support */
|
|
71
|
-
keyCode?: number;
|
|
72
70
|
/** Does the character in `key` require/imply AltRight to be pressed? */
|
|
73
71
|
altGr?: boolean;
|
|
74
72
|
/** Does the character in `key` require/imply a shiftKey to be pressed? */
|
package/dist/paste.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { UserEvent } from './setup';
|
|
2
|
+
export interface pasteOptions {
|
|
3
|
+
document?: Document;
|
|
4
|
+
}
|
|
5
|
+
export declare function paste(this: UserEvent, clipboardData?: undefined, options?: pasteOptions): Promise<void>;
|
|
6
|
+
export declare function paste(this: UserEvent, clipboardData: DataTransfer | string, options?: pasteOptions): void;
|
package/dist/paste.js
CHANGED
|
@@ -9,59 +9,56 @@ var _dom = require("@testing-library/dom");
|
|
|
9
9
|
|
|
10
10
|
var _utils = require("./utils");
|
|
11
11
|
|
|
12
|
-
function
|
|
13
|
-
|
|
12
|
+
function paste(clipboardData, options) {
|
|
13
|
+
var _options$document, _doc$activeElement;
|
|
14
|
+
|
|
15
|
+
const doc = (_options$document = options == null ? void 0 : options.document) != null ? _options$document : document;
|
|
16
|
+
const target = (_doc$activeElement = doc.activeElement) != null ? _doc$activeElement :
|
|
17
|
+
/* istanbul ignore next */
|
|
18
|
+
doc.body;
|
|
19
|
+
const data = typeof clipboardData === 'string' ? getClipboardDataFromString(clipboardData) : clipboardData;
|
|
20
|
+
return data ? pasteImpl(target, data) : readClipboardDataFromClipboardApi(doc).then(dt => pasteImpl(target, dt));
|
|
14
21
|
}
|
|
15
22
|
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
// TODO: implement for contenteditable
|
|
21
|
-
if (!isSupportedElement(element)) {
|
|
22
|
-
throw new TypeError(`The given ${element.tagName} element is currently unsupported.
|
|
23
|
-
A PR extending this implementation would be very much welcome at https://github.com/testing-library/user-event`);
|
|
24
|
-
}
|
|
23
|
+
function pasteImpl(target, clipboardData) {
|
|
24
|
+
_dom.fireEvent.paste(target, {
|
|
25
|
+
clipboardData
|
|
26
|
+
});
|
|
25
27
|
|
|
26
|
-
if ((0, _utils.
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
if ((0, _utils.isEditable)(target)) {
|
|
29
|
+
const data = clipboardData.getData('text').substr(0, (0, _utils.getSpaceUntilMaxLength)(target));
|
|
30
|
+
|
|
31
|
+
if (data) {
|
|
32
|
+
var _prepareInput;
|
|
29
33
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// at the end of the current input value. So, if the selection start
|
|
33
|
-
// and end are both the default of 0, then we'll go ahead and change
|
|
34
|
-
// them to the length of the current value.
|
|
35
|
-
// the only time it would make sense to pass the initialSelectionStart or
|
|
36
|
-
// initialSelectionEnd is if you have an input with a value and want to
|
|
37
|
-
// explicitely start typing with the cursor at 0. Not super common.
|
|
38
|
-
|
|
39
|
-
if (element.selectionStart === 0 && element.selectionEnd === 0) {
|
|
40
|
-
(0, _utils.setSelectionRange)(element, initialSelectionStart != null ? initialSelectionStart : element.value.length, initialSelectionEnd != null ? initialSelectionEnd : element.value.length);
|
|
34
|
+
(_prepareInput = (0, _utils.prepareInput)(data, target, 'insertFromPaste')) == null ? void 0 : _prepareInput.commit();
|
|
35
|
+
}
|
|
41
36
|
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getClipboardDataFromString(text) {
|
|
40
|
+
const dt = (0, _utils.createDataTransfer)();
|
|
41
|
+
dt.setData('text', text);
|
|
42
|
+
return dt;
|
|
43
|
+
}
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
async function readClipboardDataFromClipboardApi(document) {
|
|
46
|
+
var _document$defaultView;
|
|
44
47
|
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
const clipboard = (_document$defaultView = document.defaultView) == null ? void 0 : _document$defaultView.navigator.clipboard;
|
|
49
|
+
const items = clipboard && (await clipboard.read());
|
|
50
|
+
|
|
51
|
+
if (!items) {
|
|
52
|
+
throw new Error('`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.');
|
|
47
53
|
}
|
|
48
54
|
|
|
49
|
-
|
|
50
|
-
const {
|
|
51
|
-
newValue,
|
|
52
|
-
newSelectionStart
|
|
53
|
-
} = (0, _utils.calculateNewValue)(text, element);
|
|
55
|
+
const dt = (0, _utils.createDataTransfer)();
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
value: newValue
|
|
57
|
+
for (const item of items) {
|
|
58
|
+
for (const type of item.types) {
|
|
59
|
+
dt.setData(type, await item.getType(type).then(b => (0, _utils.readBlobText)(b)));
|
|
59
60
|
}
|
|
60
|
-
}
|
|
61
|
+
}
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
{
|
|
64
|
-
newSelectionStart,
|
|
65
|
-
selectionEnd: newSelectionStart
|
|
66
|
-
}, {});
|
|
63
|
+
return dt;
|
|
67
64
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|