@testing-library/user-event 14.0.0-alpha.8 → 14.0.0-beta.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/clipboard/copy.d.ts +2 -0
- package/dist/clipboard/copy.js +36 -0
- package/dist/clipboard/cut.d.ts +2 -0
- package/dist/clipboard/cut.js +42 -0
- package/dist/clipboard/index.d.ts +3 -0
- package/dist/clipboard/index.js +44 -0
- package/dist/clipboard/paste.d.ts +2 -0
- package/dist/clipboard/paste.js +47 -0
- package/dist/convenience/click.d.ts +4 -0
- package/dist/convenience/click.js +52 -0
- package/dist/convenience/hover.d.ts +3 -0
- package/dist/convenience/hover.js +31 -0
- package/dist/convenience/index.d.ts +3 -0
- package/dist/convenience/index.js +44 -0
- package/dist/convenience/tab.d.ts +4 -0
- package/dist/convenience/tab.js +12 -0
- package/dist/index.d.ts +2 -7
- package/dist/index.js +3 -12
- package/dist/keyboard/getEventProps.d.ts +0 -2
- package/dist/keyboard/getEventProps.js +1 -7
- package/dist/keyboard/index.d.ts +6 -18
- package/dist/keyboard/index.js +9 -45
- package/dist/keyboard/keyMap.js +24 -48
- package/dist/keyboard/keyboardAction.d.ts +10 -0
- package/dist/keyboard/keyboardAction.js +156 -0
- package/dist/keyboard/{getNextKeyDef.d.ts → parseKeyDef.d.ts} +4 -6
- package/dist/keyboard/parseKeyDef.js +61 -0
- package/dist/keyboard/plugins/character.js +21 -14
- package/dist/keyboard/plugins/combination.js +3 -1
- package/dist/keyboard/plugins/functional.js +38 -20
- package/dist/keyboard/plugins/index.d.ts +0 -1
- package/dist/keyboard/plugins/index.js +1 -10
- package/dist/keyboard/types.d.ts +3 -19
- package/dist/options.d.ts +102 -0
- package/dist/options.js +36 -0
- package/dist/pointer/index.d.ts +6 -14
- package/dist/pointer/index.js +8 -42
- package/dist/pointer/parseKeyDef.d.ts +2 -2
- package/dist/pointer/parseKeyDef.js +1 -3
- package/dist/pointer/pointerAction.d.ts +3 -2
- package/dist/pointer/pointerAction.js +9 -15
- package/dist/pointer/pointerMove.d.ts +2 -1
- package/dist/pointer/pointerPress.d.ts +2 -1
- package/dist/pointer/pointerPress.js +13 -16
- package/dist/pointer/types.d.ts +0 -11
- package/dist/setup/api.d.ts +5 -0
- package/dist/setup/api.js +111 -0
- package/dist/setup/config.d.ts +10 -0
- package/dist/setup/config.js +8 -0
- package/dist/setup/directApi.d.ts +20 -0
- package/dist/setup/directApi.js +95 -0
- package/dist/setup/index.d.ts +30 -0
- package/dist/setup/index.js +27 -0
- package/dist/setup/setup.d.ts +74 -0
- package/dist/setup/setup.js +98 -0
- package/dist/setup/wrapAsync.d.ts +4 -0
- package/dist/setup/wrapAsync.js +15 -0
- package/dist/{clear.d.ts → utility/clear.d.ts} +2 -2
- package/dist/utility/clear.js +30 -0
- package/dist/utility/index.d.ts +4 -0
- package/dist/utility/index.js +57 -0
- package/dist/utility/selectOptions.d.ts +3 -0
- package/dist/{selectOptions.js → utility/selectOptions.js} +31 -41
- package/dist/utility/type.d.ts +9 -0
- package/dist/utility/type.js +37 -0
- package/dist/utility/upload.d.ts +5 -0
- package/dist/{upload.js → utility/upload.js} +12 -40
- package/dist/utils/dataTransfer/Blob.d.ts +1 -0
- package/dist/utils/dataTransfer/Blob.js +21 -0
- package/dist/utils/dataTransfer/Clipboard.d.ts +9 -0
- package/dist/utils/dataTransfer/Clipboard.js +188 -0
- package/dist/utils/dataTransfer/DataTransfer.d.ts +2 -0
- package/dist/utils/dataTransfer/DataTransfer.js +158 -0
- package/dist/utils/dataTransfer/FileList.d.ts +1 -0
- package/dist/utils/dataTransfer/FileList.js +23 -0
- package/dist/utils/edit/calculateNewValue.d.ts +1 -3
- package/dist/utils/edit/calculateNewValue.js +1 -5
- package/dist/utils/edit/editInputElement.d.ts +16 -0
- package/dist/utils/edit/{fireInputEvent.js → editInputElement.js} +8 -20
- package/dist/utils/edit/prepareInput.d.ts +4 -1
- package/dist/utils/edit/prepareInput.js +56 -39
- package/dist/utils/edit/setFiles.d.ts +12 -0
- package/dist/utils/edit/setFiles.js +72 -0
- package/dist/utils/focus/copySelection.d.ts +1 -0
- package/dist/utils/focus/copySelection.js +36 -0
- package/dist/utils/focus/getTabDestination.js +14 -1
- package/dist/utils/focus/selectAll.d.ts +1 -0
- package/dist/utils/focus/selectAll.js +13 -0
- package/dist/utils/index.d.ts +8 -2
- package/dist/utils/index.js +95 -17
- package/dist/utils/misc/getDocumentFromNode.d.ts +1 -0
- package/dist/utils/misc/getDocumentFromNode.js +14 -0
- package/dist/utils/misc/hasFormSubmit.js +1 -1
- package/dist/utils/misc/isVisible.js +8 -1
- package/dist/utils/pointer/firePointerEvents.d.ts +12 -1
- package/dist/utils/pointer/firePointerEvents.js +67 -12
- package/package.json +1 -1
- package/dist/clear.js +0 -46
- package/dist/click.d.ts +0 -9
- package/dist/click.js +0 -62
- package/dist/hover.d.ts +0 -4
- package/dist/hover.js +0 -43
- package/dist/keyboard/getNextKeyDef.js +0 -85
- package/dist/keyboard/keyboardImplementation.d.ts +0 -3
- package/dist/keyboard/keyboardImplementation.js +0 -169
- package/dist/keyboard/specialCharMap.d.ts +0 -22
- package/dist/keyboard/specialCharMap.js +0 -30
- package/dist/paste.d.ts +0 -7
- package/dist/paste.js +0 -60
- package/dist/selectOptions.d.ts +0 -4
- package/dist/setup.d.ts +0 -92
- package/dist/setup.js +0 -203
- package/dist/tab.d.ts +0 -5
- package/dist/tab.js +0 -12
- package/dist/type.d.ts +0 -14
- package/dist/type.js +0 -74
- package/dist/upload.d.ts +0 -10
- package/dist/utils/edit/fireInputEvent.d.ts +0 -11
- package/dist/utils/pointer/fakeEvent.d.ts +0 -20
- package/dist/utils/pointer/fakeEvent.js +0 -91
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.keyboardAction = keyboardAction;
|
|
7
|
+
exports.releaseAllKeys = releaseAllKeys;
|
|
8
|
+
|
|
9
|
+
var _dom = require("@testing-library/dom");
|
|
10
|
+
|
|
11
|
+
var _utils = require("../utils");
|
|
12
|
+
|
|
13
|
+
var plugins = _interopRequireWildcard(require("./plugins"));
|
|
14
|
+
|
|
15
|
+
var _getEventProps = require("./getEventProps");
|
|
16
|
+
|
|
17
|
+
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); }
|
|
18
|
+
|
|
19
|
+
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; }
|
|
20
|
+
|
|
21
|
+
async function keyboardAction(config, actions) {
|
|
22
|
+
for (let i = 0; i < actions.length; i++) {
|
|
23
|
+
await keyboardKeyAction(config, actions[i]);
|
|
24
|
+
|
|
25
|
+
if (typeof config.delay === 'number' && i < actions.length - 1) {
|
|
26
|
+
await (0, _utils.wait)(config.delay);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function keyboardKeyAction(config, {
|
|
32
|
+
keyDef,
|
|
33
|
+
releasePrevious,
|
|
34
|
+
releaseSelf,
|
|
35
|
+
repeat
|
|
36
|
+
}) {
|
|
37
|
+
const {
|
|
38
|
+
document,
|
|
39
|
+
keyboardState,
|
|
40
|
+
delay
|
|
41
|
+
} = config;
|
|
42
|
+
|
|
43
|
+
const getCurrentElement = () => getActive(document); // Release the key automatically if it was pressed before.
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
const pressed = keyboardState.pressed.find(p => p.keyDef === keyDef);
|
|
47
|
+
|
|
48
|
+
if (pressed) {
|
|
49
|
+
await keyup(keyDef, getCurrentElement, config, pressed.unpreventedDefault);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!releasePrevious) {
|
|
53
|
+
let unpreventedDefault = true;
|
|
54
|
+
|
|
55
|
+
for (let i = 1; i <= repeat; i++) {
|
|
56
|
+
unpreventedDefault = await keydown(keyDef, getCurrentElement, config);
|
|
57
|
+
|
|
58
|
+
if (unpreventedDefault && hasKeyPress(keyDef, config)) {
|
|
59
|
+
await keypress(keyDef, getCurrentElement, config);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (typeof delay === 'number' && i < repeat) {
|
|
63
|
+
await (0, _utils.wait)(delay);
|
|
64
|
+
}
|
|
65
|
+
} // Release the key only on the last iteration on `state.repeatKey`.
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if (releaseSelf) {
|
|
69
|
+
await keyup(keyDef, getCurrentElement, config, unpreventedDefault);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function getActive(document) {
|
|
75
|
+
var _getActiveElement;
|
|
76
|
+
|
|
77
|
+
return (_getActiveElement = (0, _utils.getActiveElement)(document)) != null ? _getActiveElement :
|
|
78
|
+
/* istanbul ignore next */
|
|
79
|
+
document.body;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function releaseAllKeys(config) {
|
|
83
|
+
const getCurrentElement = () => getActive(config.document);
|
|
84
|
+
|
|
85
|
+
for (const k of config.keyboardState.pressed) {
|
|
86
|
+
await keyup(k.keyDef, getCurrentElement, config, k.unpreventedDefault);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function keydown(keyDef, getCurrentElement, config) {
|
|
91
|
+
const element = getCurrentElement(); // clear carried characters when focus is moved
|
|
92
|
+
|
|
93
|
+
if (element !== config.keyboardState.activeElement) {
|
|
94
|
+
config.keyboardState.carryValue = undefined;
|
|
95
|
+
config.keyboardState.carryChar = '';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
config.keyboardState.activeElement = element;
|
|
99
|
+
applyPlugins(plugins.preKeydownBehavior, keyDef, element, config);
|
|
100
|
+
|
|
101
|
+
const unpreventedDefault = _dom.fireEvent.keyDown(element, (0, _getEventProps.getKeyEventProps)(keyDef, config.keyboardState));
|
|
102
|
+
|
|
103
|
+
config.keyboardState.pressed.push({
|
|
104
|
+
keyDef,
|
|
105
|
+
unpreventedDefault
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
if (unpreventedDefault) {
|
|
109
|
+
// all default behavior like keypress/submit etc is applied to the currentElement
|
|
110
|
+
applyPlugins(plugins.keydownBehavior, keyDef, getCurrentElement(), config);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return unpreventedDefault;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function keypress(keyDef, getCurrentElement, config) {
|
|
117
|
+
const element = getCurrentElement();
|
|
118
|
+
|
|
119
|
+
const unpreventedDefault = _dom.fireEvent.keyPress(element, { ...(0, _getEventProps.getKeyEventProps)(keyDef, config.keyboardState),
|
|
120
|
+
charCode: keyDef.key === 'Enter' ? 13 : String(keyDef.key).charCodeAt(0)
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
if (unpreventedDefault) {
|
|
124
|
+
applyPlugins(plugins.keypressBehavior, keyDef, getCurrentElement(), config);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
129
|
+
const element = getCurrentElement();
|
|
130
|
+
applyPlugins(plugins.preKeyupBehavior, keyDef, element, config);
|
|
131
|
+
|
|
132
|
+
const unpreventedDefault = _dom.fireEvent.keyUp(element, (0, _getEventProps.getKeyEventProps)(keyDef, config.keyboardState));
|
|
133
|
+
|
|
134
|
+
if (unprevented && unpreventedDefault) {
|
|
135
|
+
applyPlugins(plugins.keyupBehavior, keyDef, getCurrentElement(), config);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
config.keyboardState.pressed = config.keyboardState.pressed.filter(k => k.keyDef !== keyDef);
|
|
139
|
+
applyPlugins(plugins.postKeyupBehavior, keyDef, element, config);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function applyPlugins(pluginCollection, keyDef, element, config) {
|
|
143
|
+
const plugin = pluginCollection.find(p => p.matches(keyDef, element, config));
|
|
144
|
+
|
|
145
|
+
if (plugin) {
|
|
146
|
+
plugin.handle(keyDef, element, config);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return !!plugin;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function hasKeyPress(keyDef, config) {
|
|
153
|
+
var _keyDef$key;
|
|
154
|
+
|
|
155
|
+
return (((_keyDef$key = keyDef.key) == null ? void 0 : _keyDef$key.length) === 1 || keyDef.key === 'Enter') && !config.keyboardState.modifiers.ctrl && !config.keyboardState.modifiers.alt;
|
|
156
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { keyboardKey
|
|
1
|
+
import { keyboardKey } from './types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Parse key defintions per `keyboardMap`
|
|
4
4
|
*
|
|
5
5
|
* Keys can be referenced by `{key}` or `{special}` as well as physical locations per `[code]`.
|
|
6
6
|
* Everything else will be interpreted as a typed character - e.g. `a`.
|
|
@@ -8,12 +8,10 @@ import { keyboardKey, keyboardOptions } from './types';
|
|
|
8
8
|
* Keeping the key pressed can be written as `{key>}`.
|
|
9
9
|
* When keeping the key pressed you can choose how long (how many keydown and keypress) the key is pressed `{key>3}`.
|
|
10
10
|
* You can then release the key per `{key>3/}` or keep it pressed and continue with the next key.
|
|
11
|
-
* Modifiers like `{shift}` imply being kept pressed. This can be turned of per `{shift/}`.
|
|
12
11
|
*/
|
|
13
|
-
export declare function
|
|
12
|
+
export declare function parseKeyDef(keyboardMap: keyboardKey[], text: string): {
|
|
14
13
|
keyDef: keyboardKey;
|
|
15
|
-
consumedLength: number;
|
|
16
14
|
releasePrevious: boolean;
|
|
17
15
|
releaseSelf: boolean;
|
|
18
16
|
repeat: number;
|
|
19
|
-
};
|
|
17
|
+
}[];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.parseKeyDef = parseKeyDef;
|
|
7
|
+
|
|
8
|
+
var _utils = require("../utils");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Parse key defintions per `keyboardMap`
|
|
12
|
+
*
|
|
13
|
+
* Keys can be referenced by `{key}` or `{special}` as well as physical locations per `[code]`.
|
|
14
|
+
* Everything else will be interpreted as a typed character - e.g. `a`.
|
|
15
|
+
* Brackets `{` and `[` can be escaped by doubling - e.g. `foo[[bar` translates to `foo[bar`.
|
|
16
|
+
* Keeping the key pressed can be written as `{key>}`.
|
|
17
|
+
* When keeping the key pressed you can choose how long (how many keydown and keypress) the key is pressed `{key>3}`.
|
|
18
|
+
* You can then release the key per `{key>3/}` or keep it pressed and continue with the next key.
|
|
19
|
+
*/
|
|
20
|
+
function parseKeyDef(keyboardMap, text) {
|
|
21
|
+
const defs = [];
|
|
22
|
+
|
|
23
|
+
do {
|
|
24
|
+
var _keyboardMap$find;
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
type,
|
|
28
|
+
descriptor,
|
|
29
|
+
consumedLength,
|
|
30
|
+
releasePrevious,
|
|
31
|
+
releaseSelf = true,
|
|
32
|
+
repeat
|
|
33
|
+
} = (0, _utils.readNextDescriptor)(text);
|
|
34
|
+
const keyDef = (_keyboardMap$find = keyboardMap.find(def => {
|
|
35
|
+
if (type === '[') {
|
|
36
|
+
var _def$code;
|
|
37
|
+
|
|
38
|
+
return ((_def$code = def.code) == null ? void 0 : _def$code.toLowerCase()) === descriptor.toLowerCase();
|
|
39
|
+
} else if (type === '{') {
|
|
40
|
+
var _def$key;
|
|
41
|
+
|
|
42
|
+
return ((_def$key = def.key) == null ? void 0 : _def$key.toLowerCase()) === descriptor.toLowerCase();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return def.key === descriptor;
|
|
46
|
+
})) != null ? _keyboardMap$find : {
|
|
47
|
+
key: 'Unknown',
|
|
48
|
+
code: 'Unknown',
|
|
49
|
+
[type === '[' ? 'code' : 'key']: descriptor
|
|
50
|
+
};
|
|
51
|
+
defs.push({
|
|
52
|
+
keyDef,
|
|
53
|
+
releasePrevious,
|
|
54
|
+
releaseSelf,
|
|
55
|
+
repeat
|
|
56
|
+
});
|
|
57
|
+
text = text.slice(consumedLength);
|
|
58
|
+
} while (text);
|
|
59
|
+
|
|
60
|
+
return defs;
|
|
61
|
+
}
|
|
@@ -23,11 +23,13 @@ const keypressBehavior = [{
|
|
|
23
23
|
readOnly: false
|
|
24
24
|
});
|
|
25
25
|
},
|
|
26
|
-
handle: (keyDef, element,
|
|
27
|
-
|
|
26
|
+
handle: (keyDef, element, {
|
|
27
|
+
keyboardState
|
|
28
|
+
}) => {
|
|
29
|
+
var _keyboardState$carryV;
|
|
28
30
|
|
|
29
31
|
let newEntry = keyDef.key;
|
|
30
|
-
const textToBeTyped = ((
|
|
32
|
+
const textToBeTyped = ((_keyboardState$carryV = keyboardState.carryValue) != null ? _keyboardState$carryV : '') + newEntry;
|
|
31
33
|
const timeNewEntry = (0, _utils.buildTimeValue)(textToBeTyped);
|
|
32
34
|
|
|
33
35
|
if ((0, _utils.isValidInputTimeValue)(element, timeNewEntry)) {
|
|
@@ -42,7 +44,7 @@ const keypressBehavior = [{
|
|
|
42
44
|
// TODO: verify if it is even needed by this handler
|
|
43
45
|
|
|
44
46
|
if (prevValue !== newValue) {
|
|
45
|
-
(0, _utils.
|
|
47
|
+
(0, _utils.editInputElement)(element, {
|
|
46
48
|
newValue,
|
|
47
49
|
newSelection: {
|
|
48
50
|
node: element,
|
|
@@ -56,7 +58,7 @@ const keypressBehavior = [{
|
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
(0, _shared.fireChangeForInputTimeIfValid)(element, prevValue, timeNewEntry);
|
|
59
|
-
|
|
61
|
+
keyboardState.carryValue = textToBeTyped;
|
|
60
62
|
}
|
|
61
63
|
}, {
|
|
62
64
|
matches: (keyDef, element) => {
|
|
@@ -67,11 +69,13 @@ const keypressBehavior = [{
|
|
|
67
69
|
readOnly: false
|
|
68
70
|
});
|
|
69
71
|
},
|
|
70
|
-
handle: (keyDef, element,
|
|
71
|
-
|
|
72
|
+
handle: (keyDef, element, {
|
|
73
|
+
keyboardState
|
|
74
|
+
}) => {
|
|
75
|
+
var _keyboardState$carryV2;
|
|
72
76
|
|
|
73
77
|
let newEntry = keyDef.key;
|
|
74
|
-
const textToBeTyped = ((
|
|
78
|
+
const textToBeTyped = ((_keyboardState$carryV2 = keyboardState.carryValue) != null ? _keyboardState$carryV2 : '') + newEntry;
|
|
75
79
|
const isValidToBeTyped = (0, _utils.isValidDateValue)(element, textToBeTyped);
|
|
76
80
|
|
|
77
81
|
if (isValidToBeTyped) {
|
|
@@ -86,7 +90,7 @@ const keypressBehavior = [{
|
|
|
86
90
|
// TODO: verify if it is even needed by this handler
|
|
87
91
|
|
|
88
92
|
if (prevValue !== newValue) {
|
|
89
|
-
(0, _utils.
|
|
93
|
+
(0, _utils.editInputElement)(element, {
|
|
90
94
|
newValue,
|
|
91
95
|
newSelection: {
|
|
92
96
|
node: element,
|
|
@@ -107,7 +111,7 @@ const keypressBehavior = [{
|
|
|
107
111
|
});
|
|
108
112
|
}
|
|
109
113
|
|
|
110
|
-
|
|
114
|
+
keyboardState.carryValue = textToBeTyped;
|
|
111
115
|
}
|
|
112
116
|
}, {
|
|
113
117
|
matches: (keyDef, element) => {
|
|
@@ -126,9 +130,10 @@ const keypressBehavior = [{
|
|
|
126
130
|
}
|
|
127
131
|
|
|
128
132
|
const {
|
|
129
|
-
|
|
133
|
+
getNewValue,
|
|
130
134
|
commit
|
|
131
|
-
} = (0, _utils.prepareInput)(keyDef.key, element);
|
|
135
|
+
} = (0, _utils.prepareInput)(keyDef.key, element);
|
|
136
|
+
const newValue = getNewValue(); // the browser allows some invalid input but not others
|
|
132
137
|
// it allows up to two '-' at any place before any 'e' or one directly following 'e'
|
|
133
138
|
// it allows one '.' at any place before e
|
|
134
139
|
|
|
@@ -157,10 +162,12 @@ const keypressBehavior = [{
|
|
|
157
162
|
matches: (keyDef, element) => keyDef.key === 'Enter' && ((0, _utils.isElementType)(element, 'textarea', {
|
|
158
163
|
readOnly: false
|
|
159
164
|
}) || (0, _utils.isContentEditable)(element)) && (0, _utils.getSpaceUntilMaxLength)(element) !== 0,
|
|
160
|
-
handle: (keyDef, element,
|
|
165
|
+
handle: (keyDef, element, {
|
|
166
|
+
keyboardState
|
|
167
|
+
}) => {
|
|
161
168
|
var _prepareInput2;
|
|
162
169
|
|
|
163
|
-
(_prepareInput2 = (0, _utils.prepareInput)('\n', element, (0, _utils.isContentEditable)(element) && !
|
|
170
|
+
(_prepareInput2 = (0, _utils.prepareInput)('\n', element, (0, _utils.isContentEditable)(element) && !keyboardState.modifiers.shift ? 'insertParagraph' : 'insertLineBreak')) == null ? void 0 : _prepareInput2.commit();
|
|
164
171
|
}
|
|
165
172
|
}];
|
|
166
173
|
exports.keypressBehavior = keypressBehavior;
|
|
@@ -11,7 +11,9 @@ var _utils = require("../../utils");
|
|
|
11
11
|
* Default behavior for key combinations
|
|
12
12
|
*/
|
|
13
13
|
const keydownBehavior = [{
|
|
14
|
-
matches: (keyDef, element,
|
|
14
|
+
matches: (keyDef, element, {
|
|
15
|
+
keyboardState
|
|
16
|
+
}) => keyDef.code === 'KeyA' && keyboardState.modifiers.ctrl,
|
|
15
17
|
handle: (keyDef, element) => (0, _utils.selectAll)(element)
|
|
16
18
|
}];
|
|
17
19
|
exports.keydownBehavior = keydownBehavior;
|
|
@@ -26,31 +26,38 @@ const modifierKeys = {
|
|
|
26
26
|
const preKeydownBehavior = [// modifierKeys switch on the modifier BEFORE the keydown event
|
|
27
27
|
...Object.entries(modifierKeys).map(([key, modKey]) => ({
|
|
28
28
|
matches: keyDef => keyDef.key === key,
|
|
29
|
-
handle: (keyDef, element,
|
|
30
|
-
|
|
29
|
+
handle: (keyDef, element, {
|
|
30
|
+
keyboardState
|
|
31
|
+
}) => {
|
|
32
|
+
keyboardState.modifiers[modKey] = true;
|
|
31
33
|
}
|
|
32
34
|
})), // AltGraph produces an extra keydown for Control
|
|
33
35
|
// The modifier does not change
|
|
34
36
|
{
|
|
35
37
|
matches: keyDef => keyDef.key === 'AltGraph',
|
|
36
|
-
handle: (keyDef, element,
|
|
37
|
-
|
|
38
|
+
handle: (keyDef, element, {
|
|
39
|
+
keyboardMap,
|
|
40
|
+
keyboardState
|
|
41
|
+
}) => {
|
|
42
|
+
var _keyboardMap$find;
|
|
38
43
|
|
|
39
|
-
const ctrlKeyDef = (
|
|
44
|
+
const ctrlKeyDef = (_keyboardMap$find = keyboardMap.find(k => k.key === 'Control')) != null ? _keyboardMap$find :
|
|
40
45
|
/* istanbul ignore next */
|
|
41
46
|
{
|
|
42
47
|
key: 'Control',
|
|
43
48
|
code: 'Control'
|
|
44
49
|
};
|
|
45
50
|
|
|
46
|
-
_dom.fireEvent.keyDown(element, (0, _getEventProps.getKeyEventProps)(ctrlKeyDef,
|
|
51
|
+
_dom.fireEvent.keyDown(element, (0, _getEventProps.getKeyEventProps)(ctrlKeyDef, keyboardState));
|
|
47
52
|
}
|
|
48
53
|
}];
|
|
49
54
|
exports.preKeydownBehavior = preKeydownBehavior;
|
|
50
55
|
const keydownBehavior = [{
|
|
51
56
|
matches: keyDef => keyDef.key === 'CapsLock',
|
|
52
|
-
handle: (keyDef, element,
|
|
53
|
-
|
|
57
|
+
handle: (keyDef, element, {
|
|
58
|
+
keyboardState
|
|
59
|
+
}) => {
|
|
60
|
+
keyboardState.modifiers.caps = !keyboardState.modifiers.caps;
|
|
54
61
|
}
|
|
55
62
|
}, {
|
|
56
63
|
matches: (keyDef, element) => keyDef.key === 'Backspace' && (0, _utils.isEditable)(element),
|
|
@@ -61,8 +68,10 @@ const keydownBehavior = [{
|
|
|
61
68
|
}
|
|
62
69
|
}, {
|
|
63
70
|
matches: keyDef => keyDef.key === 'Tab',
|
|
64
|
-
handle: (keyDef, element,
|
|
65
|
-
|
|
71
|
+
handle: (keyDef, element, {
|
|
72
|
+
keyboardState
|
|
73
|
+
}) => {
|
|
74
|
+
const dest = (0, _utils.getTabDestination)(element, keyboardState.modifiers.shift);
|
|
66
75
|
|
|
67
76
|
if (dest === element.ownerDocument.body) {
|
|
68
77
|
(0, _utils.blur)(element);
|
|
@@ -91,8 +100,10 @@ const keypressBehavior = [{
|
|
|
91
100
|
}, {
|
|
92
101
|
matches: (keyDef, element) => keyDef.key === 'Enter' && ((0, _utils.isClickableInput)(element) || // Links with href defined should handle Enter the same as a click
|
|
93
102
|
(0, _utils.isElementType)(element, 'a') && Boolean(element.href)),
|
|
94
|
-
handle: (keyDef, element,
|
|
95
|
-
|
|
103
|
+
handle: (keyDef, element, {
|
|
104
|
+
keyboardState
|
|
105
|
+
}) => {
|
|
106
|
+
_dom.fireEvent.click(element, (0, _getEventProps.getMouseEventProps)(keyboardState));
|
|
96
107
|
}
|
|
97
108
|
}, {
|
|
98
109
|
matches: (keyDef, element) => keyDef.key === 'Enter' && (0, _utils.isElementType)(element, 'input'),
|
|
@@ -108,15 +119,19 @@ exports.keypressBehavior = keypressBehavior;
|
|
|
108
119
|
const preKeyupBehavior = [// modifierKeys switch off the modifier BEFORE the keyup event
|
|
109
120
|
...Object.entries(modifierKeys).map(([key, modKey]) => ({
|
|
110
121
|
matches: keyDef => keyDef.key === key,
|
|
111
|
-
handle: (keyDef, element,
|
|
112
|
-
|
|
122
|
+
handle: (keyDef, element, {
|
|
123
|
+
keyboardState
|
|
124
|
+
}) => {
|
|
125
|
+
keyboardState.modifiers[modKey] = false;
|
|
113
126
|
}
|
|
114
127
|
}))];
|
|
115
128
|
exports.preKeyupBehavior = preKeyupBehavior;
|
|
116
129
|
const keyupBehavior = [{
|
|
117
130
|
matches: (keyDef, element) => keyDef.key === ' ' && (0, _utils.isClickableInput)(element),
|
|
118
|
-
handle: (keyDef, element,
|
|
119
|
-
|
|
131
|
+
handle: (keyDef, element, {
|
|
132
|
+
keyboardState
|
|
133
|
+
}) => {
|
|
134
|
+
_dom.fireEvent.click(element, (0, _getEventProps.getMouseEventProps)(keyboardState));
|
|
120
135
|
}
|
|
121
136
|
}];
|
|
122
137
|
exports.keyupBehavior = keyupBehavior;
|
|
@@ -124,17 +139,20 @@ const postKeyupBehavior = [// AltGraph produces an extra keyup for Control
|
|
|
124
139
|
// The modifier does not change
|
|
125
140
|
{
|
|
126
141
|
matches: keyDef => keyDef.key === 'AltGraph',
|
|
127
|
-
handle: (keyDef, element,
|
|
128
|
-
|
|
142
|
+
handle: (keyDef, element, {
|
|
143
|
+
keyboardMap,
|
|
144
|
+
keyboardState
|
|
145
|
+
}) => {
|
|
146
|
+
var _keyboardMap$find2;
|
|
129
147
|
|
|
130
|
-
const ctrlKeyDef = (
|
|
148
|
+
const ctrlKeyDef = (_keyboardMap$find2 = keyboardMap.find(k => k.key === 'Control')) != null ? _keyboardMap$find2 :
|
|
131
149
|
/* istanbul ignore next */
|
|
132
150
|
{
|
|
133
151
|
key: 'Control',
|
|
134
152
|
code: 'Control'
|
|
135
153
|
};
|
|
136
154
|
|
|
137
|
-
_dom.fireEvent.keyUp(element, (0, _getEventProps.getKeyEventProps)(ctrlKeyDef,
|
|
155
|
+
_dom.fireEvent.keyUp(element, (0, _getEventProps.getKeyEventProps)(ctrlKeyDef, keyboardState));
|
|
138
156
|
}
|
|
139
157
|
}];
|
|
140
158
|
exports.postKeyupBehavior = postKeyupBehavior;
|
|
@@ -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
|
|
|
@@ -21,13 +19,6 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
21
19
|
|
|
22
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; }
|
|
23
21
|
|
|
24
|
-
const replaceBehavior = [{
|
|
25
|
-
matches: (keyDef, element) => keyDef.key === 'selectall' && (0, _utils.isElementType)(element, ['input', 'textarea']),
|
|
26
|
-
handle: (keyDef, element) => {
|
|
27
|
-
(0, _utils.setSelectionRange)(element, 0, (0, _utils.getValue)(element).length);
|
|
28
|
-
}
|
|
29
|
-
}];
|
|
30
|
-
exports.replaceBehavior = replaceBehavior;
|
|
31
22
|
const preKeydownBehavior = [...functionalKeys.preKeydownBehavior];
|
|
32
23
|
exports.preKeydownBehavior = preKeydownBehavior;
|
|
33
24
|
const keydownBehavior = [...arrowKeys.keydownBehavior, ...controlKeys.keydownBehavior, ...functionalKeys.keydownBehavior, ...combination.keydownBehavior];
|
package/dist/keyboard/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Config } from '../setup';
|
|
2
2
|
/**
|
|
3
3
|
* @internal Do not create/alter this by yourself as this type might be subject to changes.
|
|
4
4
|
*/
|
|
@@ -39,20 +39,6 @@ export declare type keyboardState = {
|
|
|
39
39
|
E.g. ^1
|
|
40
40
|
*/
|
|
41
41
|
carryChar: string;
|
|
42
|
-
/**
|
|
43
|
-
Repeat keydown and keypress event
|
|
44
|
-
*/
|
|
45
|
-
repeatKey?: ReturnType<typeof getNextKeyDef>;
|
|
46
|
-
};
|
|
47
|
-
export declare type keyboardOptions = {
|
|
48
|
-
/** Document in which to perform the events */
|
|
49
|
-
document: Document;
|
|
50
|
-
/** Delay between keystrokes */
|
|
51
|
-
delay: number;
|
|
52
|
-
/** Add modifiers for given keys - not implemented yet */
|
|
53
|
-
autoModify: boolean;
|
|
54
|
-
/** Keyboard layout to use */
|
|
55
|
-
keyboardMap: keyboardKey[];
|
|
56
42
|
};
|
|
57
43
|
export declare enum DOM_KEY_LOCATION {
|
|
58
44
|
STANDARD = 0,
|
|
@@ -67,14 +53,12 @@ export interface keyboardKey {
|
|
|
67
53
|
key?: string;
|
|
68
54
|
/** Location on the keyboard for keys with multiple representation */
|
|
69
55
|
location?: DOM_KEY_LOCATION;
|
|
70
|
-
/** keyCode for legacy support */
|
|
71
|
-
keyCode?: number;
|
|
72
56
|
/** Does the character in `key` require/imply AltRight to be pressed? */
|
|
73
57
|
altGr?: boolean;
|
|
74
58
|
/** Does the character in `key` require/imply a shiftKey to be pressed? */
|
|
75
59
|
shift?: boolean;
|
|
76
60
|
}
|
|
77
61
|
export interface behaviorPlugin {
|
|
78
|
-
matches: (keyDef: keyboardKey, element: Element,
|
|
79
|
-
handle: (keyDef: keyboardKey, element: Element,
|
|
62
|
+
matches: (keyDef: keyboardKey, element: Element, config: Config) => boolean;
|
|
63
|
+
handle: (keyDef: keyboardKey, element: Element, config: Config) => void;
|
|
80
64
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { keyboardKey } from './keyboard/types';
|
|
2
|
+
import type { pointerKey } from './pointer/types';
|
|
3
|
+
export interface Options {
|
|
4
|
+
/**
|
|
5
|
+
* When using `userEvent.upload`, automatically discard files
|
|
6
|
+
* that don't match an `accept` property if it exists.
|
|
7
|
+
*
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
applyAccept?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* We intend to automatically apply modifier keys for printable characters in the future.
|
|
13
|
+
* I.e. `A` implying `{Shift>}a{/Shift}` if caps lock is not active.
|
|
14
|
+
*
|
|
15
|
+
* This options allows you to opt out of this change in foresight.
|
|
16
|
+
* The feature therefore will not constitute a breaking change.
|
|
17
|
+
*
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
20
|
+
autoModify?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Between some subsequent inputs like typing a series of characters
|
|
23
|
+
* the code execution is delayed per `setTimeout` for (at least) `delay` seconds.
|
|
24
|
+
* This moves the next changes at least to next macro task
|
|
25
|
+
* and allows other (asynchronous) code to run between events.
|
|
26
|
+
*
|
|
27
|
+
* `null` prevents `setTimeout` from being called.
|
|
28
|
+
*
|
|
29
|
+
* @default 0
|
|
30
|
+
*/
|
|
31
|
+
delay?: number | null;
|
|
32
|
+
/**
|
|
33
|
+
* The document.
|
|
34
|
+
*
|
|
35
|
+
* This defaults to the owner document of an element if an API is called directly with an element and without setup.
|
|
36
|
+
* Otherwise it falls back to the global document.
|
|
37
|
+
*
|
|
38
|
+
* @default element.ownerDocument??global.document
|
|
39
|
+
*/
|
|
40
|
+
document?: Document;
|
|
41
|
+
/**
|
|
42
|
+
* An array of keyboard keys the keyboard device consists of.
|
|
43
|
+
*
|
|
44
|
+
* This allows to plug in different layouts / localizations.
|
|
45
|
+
*
|
|
46
|
+
* Defaults to a "standard" US-104-QWERTY keyboard.
|
|
47
|
+
*/
|
|
48
|
+
keyboardMap?: keyboardKey[];
|
|
49
|
+
/**
|
|
50
|
+
* An array of available pointer keys.
|
|
51
|
+
*
|
|
52
|
+
* This allows to plug in different pointer devices.
|
|
53
|
+
*/
|
|
54
|
+
pointerMap?: pointerKey[];
|
|
55
|
+
/**
|
|
56
|
+
* `userEvent.type` automatically releases any keys still pressed at the end of the call.
|
|
57
|
+
* This option allows to opt out of this feature.
|
|
58
|
+
*
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
skipAutoClose?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* `userEvent.type` implys a click at the end of the element content/value.
|
|
64
|
+
* This option allows to opt out of this feature.
|
|
65
|
+
*
|
|
66
|
+
* @default false
|
|
67
|
+
*/
|
|
68
|
+
skipClick?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* `userEvent.click` implys moving the cursor to the target element first.
|
|
71
|
+
* This options allows to opt out of this feature.
|
|
72
|
+
*
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
skipHover?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Calling pointer related APIs on an element triggers a check if that element can receive pointer events.
|
|
78
|
+
* This check is known to be expensive.
|
|
79
|
+
* This option allows to skip the check.
|
|
80
|
+
*
|
|
81
|
+
* @default false
|
|
82
|
+
*/
|
|
83
|
+
skipPointerEventsCheck?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Write selected data to Clipboard API when a `cut` or `copy` is triggered.
|
|
86
|
+
*
|
|
87
|
+
* The Clipboard API is usually not available to test code.
|
|
88
|
+
* Our `setup` replaces the `navigator.clipboard` property with a stub.
|
|
89
|
+
*
|
|
90
|
+
* Defaults to `false` when calling the APIs directly.
|
|
91
|
+
* Defaults to `true` when calling the APIs per `setup`.
|
|
92
|
+
*/
|
|
93
|
+
writeToClipboard?: boolean;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Default options applied when API is called per `userEvent.anyApi()`
|
|
97
|
+
*/
|
|
98
|
+
export declare const defaultOptionsDirect: Required<Options>;
|
|
99
|
+
/**
|
|
100
|
+
* Default options applied when API is called per `userEvent().anyApi()`
|
|
101
|
+
*/
|
|
102
|
+
export declare const defaultOptionsSetup: Required<Options>;
|