@testing-library/user-event 13.5.0 → 14.0.0-alpha.12
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/README.md +3 -0
- package/dist/clear.d.ts +2 -2
- package/dist/clear.js +14 -29
- package/dist/click.d.ts +4 -3
- package/dist/click.js +30 -145
- package/dist/document/index.d.ts +10 -0
- package/dist/document/index.js +100 -0
- package/dist/document/interceptor.d.ts +15 -0
- package/dist/document/interceptor.js +37 -0
- package/dist/document/selection.d.ts +27 -0
- package/dist/document/selection.js +90 -0
- package/dist/document/value.d.ts +18 -0
- package/dist/document/value.js +77 -0
- package/dist/hover.d.ts +3 -3
- package/dist/hover.js +17 -59
- package/dist/index.d.ts +3 -22
- package/dist/index.js +3 -36
- package/dist/keyboard/getEventProps.d.ts +0 -2
- package/dist/keyboard/getEventProps.js +1 -7
- package/dist/keyboard/getNextKeyDef.d.ts +0 -1
- package/dist/keyboard/getNextKeyDef.js +4 -123
- package/dist/keyboard/index.d.ts +1 -1
- package/dist/keyboard/index.js +4 -8
- package/dist/keyboard/keyMap.js +26 -46
- package/dist/keyboard/keyboardImplementation.js +15 -17
- package/dist/keyboard/plugins/arrow.js +7 -12
- package/dist/keyboard/plugins/character.js +29 -57
- package/dist/keyboard/plugins/combination.d.ts +5 -0
- package/dist/keyboard/plugins/combination.js +17 -0
- package/dist/keyboard/plugins/control.js +5 -16
- package/dist/keyboard/plugins/functional.js +23 -14
- package/dist/keyboard/plugins/index.d.ts +0 -1
- package/dist/keyboard/plugins/index.js +4 -13
- package/dist/keyboard/shared/index.d.ts +0 -2
- package/dist/keyboard/shared/index.js +0 -26
- package/dist/keyboard/types.d.ts +3 -2
- package/dist/paste.d.ts +3 -2
- package/dist/paste.js +8 -15
- package/dist/pointer/index.d.ts +18 -0
- package/dist/pointer/index.js +90 -0
- package/dist/pointer/keyMap.d.ts +2 -0
- package/dist/pointer/keyMap.js +29 -0
- package/dist/pointer/parseKeyDef.d.ts +6 -0
- package/dist/pointer/parseKeyDef.js +36 -0
- package/dist/pointer/pointerAction.d.ts +6 -0
- package/dist/pointer/pointerAction.js +52 -0
- package/dist/pointer/pointerMove.d.ts +5 -0
- package/dist/pointer/pointerMove.js +136 -0
- package/dist/pointer/pointerPress.d.ts +7 -0
- package/dist/pointer/pointerPress.js +330 -0
- package/dist/pointer/resolveSelectionTarget.d.ts +5 -0
- package/dist/pointer/resolveSelectionTarget.js +75 -0
- package/dist/pointer/types.d.ts +72 -0
- package/dist/pointer/types.js +1 -0
- package/dist/selectOptions.d.ts +4 -0
- package/dist/{select-options.js → selectOptions.js} +35 -38
- package/dist/setup.d.ts +92 -0
- package/dist/setup.js +203 -0
- package/dist/tab.d.ts +3 -4
- package/dist/tab.js +3 -136
- package/dist/type.d.ts +14 -0
- package/dist/type.js +74 -0
- package/dist/upload.d.ts +4 -4
- package/dist/upload.js +3 -9
- package/dist/utils/edit/calculateNewValue.d.ts +12 -5
- 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/utils/edit/getValue.d.ts +1 -1
- package/dist/utils/edit/getValue.js +3 -1
- package/dist/utils/edit/isContentEditable.d.ts +4 -0
- package/dist/utils/edit/isContentEditable.js +14 -0
- package/dist/utils/edit/isEditable.d.ts +1 -0
- package/dist/utils/edit/prepareInput.d.ts +7 -0
- package/dist/utils/edit/prepareInput.js +77 -0
- package/dist/{blur.d.ts → utils/focus/blur.d.ts} +0 -0
- package/dist/utils/focus/blur.js +19 -0
- package/dist/{focus.d.ts → utils/focus/focus.d.ts} +0 -0
- package/dist/utils/focus/focus.js +22 -0
- package/dist/utils/focus/getTabDestination.d.ts +1 -0
- package/dist/utils/focus/getTabDestination.js +71 -0
- package/dist/utils/focus/isFocusable.js +1 -3
- 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/utils/index.d.ts +12 -6
- package/dist/utils/index.js +132 -54
- package/dist/utils/keyDef/readNextDescriptor.d.ts +19 -0
- package/dist/utils/keyDef/readNextDescriptor.js +102 -0
- package/dist/utils/misc/findClosest.d.ts +1 -0
- package/dist/utils/misc/findClosest.js +20 -0
- package/dist/utils/misc/isDescendantOrSelf.d.ts +1 -0
- package/dist/utils/misc/isDescendantOrSelf.js +20 -0
- package/dist/utils/pointer/firePointerEvents.d.ts +25 -0
- package/dist/utils/pointer/firePointerEvents.js +112 -0
- package/dist/utils/pointer/mouseButtons.d.ts +12 -0
- package/dist/utils/pointer/mouseButtons.js +45 -0
- package/package.json +4 -3
- package/dist/blur.js +0 -15
- package/dist/dom-helpers.d.ts +0 -3
- package/dist/focus.js +0 -15
- package/dist/keyboard/shared/carryValue.d.ts +0 -2
- package/dist/keyboard/shared/carryValue.js +0 -13
- package/dist/keyboard/shared/fireInputEvent.d.ts +0 -17
- package/dist/keyboard/shared/fireInputEvent.js +0 -110
- package/dist/keyboard/specialCharMap.d.ts +0 -22
- package/dist/keyboard/specialCharMap.js +0 -30
- package/dist/select-options.d.ts +0 -4
- package/dist/type/index.d.ts +0 -7
- package/dist/type/index.js +0 -33
- package/dist/type/typeImplementation.d.ts +0 -10
- package/dist/type/typeImplementation.js +0 -64
- package/dist/utils/click/getMouseEventOptions.d.ts +0 -31
- package/dist/utils/click/getMouseEventOptions.js +0 -61
- package/dist/utils/edit/cursorPosition.d.ts +0 -2
- package/dist/utils/edit/cursorPosition.js +0 -35
- package/dist/utils/edit/hasUnreliableEmptyValue.d.ts +0 -10
- package/dist/utils/edit/hasUnreliableEmptyValue.js +0 -21
- package/dist/utils/edit/selectionRange.d.ts +0 -16
- package/dist/utils/edit/selectionRange.js +0 -104
- package/dist/utils/misc/isDocument.d.ts +0 -1
- package/dist/utils/misc/isDocument.js +0 -10
- package/dist/utils/misc/isLabelWithInternallyDisabledControl.d.ts +0 -1
- package/dist/utils/misc/isLabelWithInternallyDisabledControl.js +0 -22
package/dist/hover.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
import type { UserEvent } from './setup';
|
|
1
2
|
import { PointerOptions } from './utils';
|
|
2
|
-
declare function hover(
|
|
3
|
-
declare function unhover(
|
|
4
|
-
export { hover, unhover };
|
|
3
|
+
export declare function hover(this: UserEvent, element: Element, { skipPointerEventsCheck }?: PointerOptions): void;
|
|
4
|
+
export declare function unhover(this: UserEvent, element: Element, { skipPointerEventsCheck }?: PointerOptions): void;
|
package/dist/hover.js
CHANGED
|
@@ -6,80 +6,38 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.hover = hover;
|
|
7
7
|
exports.unhover = unhover;
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _pointer = require("./pointer");
|
|
10
10
|
|
|
11
11
|
var _utils = require("./utils");
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
function getParentElements(element) {
|
|
15
|
-
const parentElements = [element];
|
|
16
|
-
let currentElement = element;
|
|
17
|
-
|
|
18
|
-
while ((currentElement = currentElement.parentElement) != null) {
|
|
19
|
-
parentElements.push(currentElement);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return parentElements;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function hover(element, init, {
|
|
13
|
+
function hover(element, {
|
|
26
14
|
skipPointerEventsCheck = false
|
|
27
15
|
} = {}) {
|
|
28
16
|
if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
|
|
29
17
|
throw new Error('unable to hover element as it has or inherits pointer-events set to "none".');
|
|
30
18
|
}
|
|
31
19
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (!(0, _utils.isDisabled)(element)) {
|
|
42
|
-
_dom.fireEvent.mouseOver(element, (0, _utils.getMouseEventOptions)('mouseover', init));
|
|
43
|
-
|
|
44
|
-
for (const el of parentElements) {
|
|
45
|
-
_dom.fireEvent.mouseEnter(el, (0, _utils.getMouseEventOptions)('mouseenter', init));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
_dom.fireEvent.pointerMove(element, init);
|
|
50
|
-
|
|
51
|
-
if (!(0, _utils.isDisabled)(element)) {
|
|
52
|
-
_dom.fireEvent.mouseMove(element, (0, _utils.getMouseEventOptions)('mousemove', init));
|
|
53
|
-
}
|
|
20
|
+
const pointerState = (0, _pointer.createPointerState)();
|
|
21
|
+
pointerState.position.mouse.target = element.ownerDocument.body;
|
|
22
|
+
this.pointer({
|
|
23
|
+
target: element
|
|
24
|
+
}, {
|
|
25
|
+
pointerState
|
|
26
|
+
});
|
|
54
27
|
}
|
|
55
28
|
|
|
56
|
-
function unhover(element,
|
|
29
|
+
function unhover(element, {
|
|
57
30
|
skipPointerEventsCheck = false
|
|
58
31
|
} = {}) {
|
|
59
32
|
if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
|
|
60
33
|
throw new Error('unable to unhover element as it has or inherits pointer-events set to "none".');
|
|
61
34
|
}
|
|
62
35
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
_dom.fireEvent.pointerOut(element, init);
|
|
73
|
-
|
|
74
|
-
for (const el of parentElements) {
|
|
75
|
-
_dom.fireEvent.pointerLeave(el, init);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (!(0, _utils.isDisabled)(element)) {
|
|
79
|
-
_dom.fireEvent.mouseOut(element, (0, _utils.getMouseEventOptions)('mouseout', init));
|
|
80
|
-
|
|
81
|
-
for (const el of parentElements) {
|
|
82
|
-
_dom.fireEvent.mouseLeave(el, (0, _utils.getMouseEventOptions)('mouseleave', init));
|
|
83
|
-
}
|
|
84
|
-
}
|
|
36
|
+
const pointerState = (0, _pointer.createPointerState)();
|
|
37
|
+
pointerState.position.mouse.target = element;
|
|
38
|
+
this.pointer({
|
|
39
|
+
target: element.ownerDocument.body
|
|
40
|
+
}, {
|
|
41
|
+
pointerState
|
|
42
|
+
});
|
|
85
43
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,25 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { tab } from './tab';
|
|
5
|
-
import { hover, unhover } from './hover';
|
|
6
|
-
import { upload } from './upload';
|
|
7
|
-
import { paste } from './paste';
|
|
8
|
-
import { keyboard, specialCharMap } from './keyboard';
|
|
9
|
-
declare const userEvent: {
|
|
10
|
-
click: typeof click;
|
|
11
|
-
dblClick: typeof dblClick;
|
|
12
|
-
type: typeof type;
|
|
13
|
-
clear: typeof clear;
|
|
14
|
-
tab: typeof tab;
|
|
15
|
-
hover: typeof hover;
|
|
16
|
-
unhover: typeof unhover;
|
|
17
|
-
upload: typeof upload;
|
|
18
|
-
selectOptions: (args_0: Element, args_1: string | string[] | HTMLElement | HTMLElement[], args_2?: MouseEventInit | undefined, args_3?: import("./utils").PointerOptions | undefined) => void;
|
|
19
|
-
deselectOptions: (args_0: Element, args_1: string | string[] | HTMLElement | HTMLElement[], args_2?: MouseEventInit | undefined, args_3?: import("./utils").PointerOptions | undefined) => void;
|
|
20
|
-
paste: typeof paste;
|
|
21
|
-
keyboard: typeof keyboard;
|
|
1
|
+
import { UserEventApis, setup } from './setup';
|
|
2
|
+
declare const userEvent: UserEventApis & {
|
|
3
|
+
setup: typeof setup;
|
|
22
4
|
};
|
|
23
5
|
export default userEvent;
|
|
24
|
-
export { specialCharMap as specialChars };
|
|
25
6
|
export type { keyboardKey } from './keyboard';
|
package/dist/index.js
CHANGED
|
@@ -4,44 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
Object.defineProperty(exports, "specialChars", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () {
|
|
10
|
-
return _keyboard.specialCharMap;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
var _click = require("./click");
|
|
15
|
-
|
|
16
|
-
var _type = require("./type");
|
|
17
|
-
|
|
18
|
-
var _clear = require("./clear");
|
|
19
|
-
|
|
20
|
-
var _tab = require("./tab");
|
|
21
|
-
|
|
22
|
-
var _hover = require("./hover");
|
|
23
|
-
|
|
24
|
-
var _upload = require("./upload");
|
|
25
|
-
|
|
26
|
-
var _selectOptions = require("./select-options");
|
|
27
|
-
|
|
28
|
-
var _paste = require("./paste");
|
|
29
7
|
|
|
30
|
-
var
|
|
8
|
+
var _setup = require("./setup");
|
|
31
9
|
|
|
32
|
-
const userEvent = {
|
|
33
|
-
|
|
34
|
-
dblClick: _click.dblClick,
|
|
35
|
-
type: _type.type,
|
|
36
|
-
clear: _clear.clear,
|
|
37
|
-
tab: _tab.tab,
|
|
38
|
-
hover: _hover.hover,
|
|
39
|
-
unhover: _hover.unhover,
|
|
40
|
-
upload: _upload.upload,
|
|
41
|
-
selectOptions: _selectOptions.selectOptions,
|
|
42
|
-
deselectOptions: _selectOptions.deselectOptions,
|
|
43
|
-
paste: _paste.paste,
|
|
44
|
-
keyboard: _keyboard.keyboard
|
|
10
|
+
const userEvent = { ...Object.fromEntries(Object.entries(_setup.userEventApis).map(([k, f]) => [k, (...a) => f.apply(userEvent, a)])),
|
|
11
|
+
setup: _setup.setup
|
|
45
12
|
};
|
|
46
13
|
var _default = userEvent;
|
|
47
14
|
exports.default = _default;
|
|
@@ -6,8 +6,6 @@ export declare function getKeyEventProps(keyDef: keyboardKey, state: keyboardSta
|
|
|
6
6
|
ctrlKey: boolean;
|
|
7
7
|
metaKey: boolean;
|
|
8
8
|
shiftKey: boolean;
|
|
9
|
-
/** @deprecated use code instead */
|
|
10
|
-
keyCode: number | undefined;
|
|
11
9
|
};
|
|
12
10
|
export declare function getMouseEventProps(state: keyboardState): {
|
|
13
11
|
altKey: boolean;
|
|
@@ -7,19 +7,13 @@ exports.getKeyEventProps = getKeyEventProps;
|
|
|
7
7
|
exports.getMouseEventProps = getMouseEventProps;
|
|
8
8
|
|
|
9
9
|
function getKeyEventProps(keyDef, state) {
|
|
10
|
-
var _keyDef$keyCode, _keyDef$key;
|
|
11
|
-
|
|
12
10
|
return {
|
|
13
11
|
key: keyDef.key,
|
|
14
12
|
code: keyDef.code,
|
|
15
13
|
altKey: state.modifiers.alt,
|
|
16
14
|
ctrlKey: state.modifiers.ctrl,
|
|
17
15
|
metaKey: state.modifiers.meta,
|
|
18
|
-
shiftKey: state.modifiers.shift
|
|
19
|
-
|
|
20
|
-
/** @deprecated use code instead */
|
|
21
|
-
keyCode: (_keyDef$keyCode = keyDef.keyCode) != null ? _keyDef$keyCode : // istanbul ignore next
|
|
22
|
-
((_keyDef$key = keyDef.key) == null ? void 0 : _keyDef$key.length) === 1 ? keyDef.key.charCodeAt(0) : undefined
|
|
16
|
+
shiftKey: state.modifiers.shift
|
|
23
17
|
};
|
|
24
18
|
}
|
|
25
19
|
|
|
@@ -8,7 +8,6 @@ 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
12
|
export declare function getNextKeyDef(text: string, options: keyboardOptions): {
|
|
14
13
|
keyDef: keyboardKey;
|
|
@@ -4,23 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getNextKeyDef = getNextKeyDef;
|
|
7
|
-
var bracketDict;
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
bracketDict["{"] = "}";
|
|
11
|
-
bracketDict["["] = "]";
|
|
12
|
-
})(bracketDict || (bracketDict = {}));
|
|
8
|
+
var _utils = require("../utils");
|
|
13
9
|
|
|
14
|
-
var legacyModifiers;
|
|
15
|
-
|
|
16
|
-
(function (legacyModifiers) {
|
|
17
|
-
legacyModifiers["alt"] = "alt";
|
|
18
|
-
legacyModifiers["ctrl"] = "ctrl";
|
|
19
|
-
legacyModifiers["meta"] = "meta";
|
|
20
|
-
legacyModifiers["shift"] = "shift";
|
|
21
|
-
})(legacyModifiers || (legacyModifiers = {}));
|
|
22
|
-
|
|
23
|
-
var legacyKeyMap;
|
|
24
10
|
/**
|
|
25
11
|
* Get the next key from keyMap
|
|
26
12
|
*
|
|
@@ -30,16 +16,7 @@ var legacyKeyMap;
|
|
|
30
16
|
* Keeping the key pressed can be written as `{key>}`.
|
|
31
17
|
* When keeping the key pressed you can choose how long (how many keydown and keypress) the key is pressed `{key>3}`.
|
|
32
18
|
* You can then release the key per `{key>3/}` or keep it pressed and continue with the next key.
|
|
33
|
-
* Modifiers like `{shift}` imply being kept pressed. This can be turned of per `{shift/}`.
|
|
34
19
|
*/
|
|
35
|
-
|
|
36
|
-
(function (legacyKeyMap) {
|
|
37
|
-
legacyKeyMap["ctrl"] = "Control";
|
|
38
|
-
legacyKeyMap["del"] = "Delete";
|
|
39
|
-
legacyKeyMap["esc"] = "Escape";
|
|
40
|
-
legacyKeyMap["space"] = " ";
|
|
41
|
-
})(legacyKeyMap || (legacyKeyMap = {}));
|
|
42
|
-
|
|
43
20
|
function getNextKeyDef(text, options) {
|
|
44
21
|
var _options$keyboardMap$;
|
|
45
22
|
|
|
@@ -48,9 +25,9 @@ function getNextKeyDef(text, options) {
|
|
|
48
25
|
descriptor,
|
|
49
26
|
consumedLength,
|
|
50
27
|
releasePrevious,
|
|
51
|
-
releaseSelf,
|
|
28
|
+
releaseSelf = true,
|
|
52
29
|
repeat
|
|
53
|
-
} = readNextDescriptor(text);
|
|
30
|
+
} = (0, _utils.readNextDescriptor)(text);
|
|
54
31
|
const keyDef = (_options$keyboardMap$ = options.keyboardMap.find(def => {
|
|
55
32
|
if (type === '[') {
|
|
56
33
|
var _def$code;
|
|
@@ -59,8 +36,7 @@ function getNextKeyDef(text, options) {
|
|
|
59
36
|
} else if (type === '{') {
|
|
60
37
|
var _def$key;
|
|
61
38
|
|
|
62
|
-
|
|
63
|
-
return ((_def$key = def.key) == null ? void 0 : _def$key.toLowerCase()) === key.toLowerCase();
|
|
39
|
+
return ((_def$key = def.key) == null ? void 0 : _def$key.toLowerCase()) === descriptor.toLowerCase();
|
|
64
40
|
}
|
|
65
41
|
|
|
66
42
|
return def.key === descriptor;
|
|
@@ -76,99 +52,4 @@ function getNextKeyDef(text, options) {
|
|
|
76
52
|
releaseSelf,
|
|
77
53
|
repeat
|
|
78
54
|
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function readNextDescriptor(text) {
|
|
82
|
-
let pos = 0;
|
|
83
|
-
const startBracket = text[pos] in bracketDict ? text[pos] : '';
|
|
84
|
-
pos += startBracket.length; // `foo{{bar` is an escaped char at position 3,
|
|
85
|
-
// but `foo{{{>5}bar` should be treated as `{` pressed down for 5 keydowns.
|
|
86
|
-
|
|
87
|
-
const startBracketRepeated = startBracket ? text.match(new RegExp(`^\\${startBracket}+`))[0].length : 0;
|
|
88
|
-
const isEscapedChar = startBracketRepeated === 2 || startBracket === '{' && startBracketRepeated > 3;
|
|
89
|
-
const type = isEscapedChar ? '' : startBracket;
|
|
90
|
-
return {
|
|
91
|
-
type,
|
|
92
|
-
...(type === '' ? readPrintableChar(text, pos) : readTag(text, pos, type))
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function readPrintableChar(text, pos) {
|
|
97
|
-
const descriptor = text[pos];
|
|
98
|
-
assertDescriptor(descriptor, text, pos);
|
|
99
|
-
pos += descriptor.length;
|
|
100
|
-
return {
|
|
101
|
-
consumedLength: pos,
|
|
102
|
-
descriptor,
|
|
103
|
-
releasePrevious: false,
|
|
104
|
-
releaseSelf: true,
|
|
105
|
-
repeat: 1
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function readTag(text, pos, startBracket) {
|
|
110
|
-
var _text$slice$match, _text$slice$match$, _text$slice$match2;
|
|
111
|
-
|
|
112
|
-
const releasePreviousModifier = text[pos] === '/' ? '/' : '';
|
|
113
|
-
pos += releasePreviousModifier.length;
|
|
114
|
-
const descriptor = (_text$slice$match = text.slice(pos).match(/^\w+/)) == null ? void 0 : _text$slice$match[0];
|
|
115
|
-
assertDescriptor(descriptor, text, pos);
|
|
116
|
-
pos += descriptor.length;
|
|
117
|
-
const repeatModifier = (_text$slice$match$ = (_text$slice$match2 = text.slice(pos).match(/^>\d+/)) == null ? void 0 : _text$slice$match2[0]) != null ? _text$slice$match$ : '';
|
|
118
|
-
pos += repeatModifier.length;
|
|
119
|
-
const releaseSelfModifier = text[pos] === '/' || !repeatModifier && text[pos] === '>' ? text[pos] : '';
|
|
120
|
-
pos += releaseSelfModifier.length;
|
|
121
|
-
const expectedEndBracket = bracketDict[startBracket];
|
|
122
|
-
const endBracket = text[pos] === expectedEndBracket ? expectedEndBracket : '';
|
|
123
|
-
|
|
124
|
-
if (!endBracket) {
|
|
125
|
-
throw new Error(getErrorMessage([!repeatModifier && 'repeat modifier', !releaseSelfModifier && 'release modifier', `"${expectedEndBracket}"`].filter(Boolean).join(' or '), text[pos], text));
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
pos += endBracket.length;
|
|
129
|
-
return {
|
|
130
|
-
consumedLength: pos,
|
|
131
|
-
descriptor,
|
|
132
|
-
releasePrevious: !!releasePreviousModifier,
|
|
133
|
-
repeat: repeatModifier ? Math.max(Number(repeatModifier.substr(1)), 1) : 1,
|
|
134
|
-
releaseSelf: hasReleaseSelf(startBracket, descriptor, releaseSelfModifier, repeatModifier)
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function assertDescriptor(descriptor, text, pos) {
|
|
139
|
-
if (!descriptor) {
|
|
140
|
-
throw new Error(getErrorMessage('key descriptor', text[pos], text));
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function getEnumValue(f, key) {
|
|
145
|
-
return f[key];
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function hasReleaseSelf(startBracket, descriptor, releaseSelfModifier, repeatModifier) {
|
|
149
|
-
if (releaseSelfModifier) {
|
|
150
|
-
return releaseSelfModifier === '/';
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (repeatModifier) {
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (startBracket === '{' && getEnumValue(legacyModifiers, descriptor.toLowerCase())) {
|
|
158
|
-
return false;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return true;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function mapLegacyKey(descriptor) {
|
|
165
|
-
var _getEnumValue;
|
|
166
|
-
|
|
167
|
-
return (_getEnumValue = getEnumValue(legacyKeyMap, descriptor)) != null ? _getEnumValue : descriptor;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function getErrorMessage(expected, found, text) {
|
|
171
|
-
return `Expected ${expected} but found "${found != null ? found : ''}" in "${text}"
|
|
172
|
-
See https://github.com/testing-library/user-event/blob/main/README.md#keyboardtext-options
|
|
173
|
-
for more information about how userEvent parses your input.`;
|
|
174
55
|
}
|
package/dist/keyboard/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { keyboardState, keyboardOptions, keyboardKey } from './types';
|
|
2
|
-
export { specialCharMap } from './specialCharMap';
|
|
3
2
|
export type { keyboardOptions, keyboardKey };
|
|
4
3
|
export declare function keyboard(text: string, options?: Partial<keyboardOptions & {
|
|
5
4
|
keyboardState: keyboardState;
|
|
@@ -16,3 +15,4 @@ export declare function keyboardImplementationWrapper(text: string, config?: Par
|
|
|
16
15
|
state: keyboardState;
|
|
17
16
|
releaseAllKeys: () => void;
|
|
18
17
|
};
|
|
18
|
+
export declare function createKeyboardState(): keyboardState;
|
package/dist/keyboard/index.js
CHANGED
|
@@ -3,23 +3,18 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.createKeyboardState = createKeyboardState;
|
|
6
7
|
exports.keyboard = keyboard;
|
|
7
8
|
exports.keyboardImplementationWrapper = keyboardImplementationWrapper;
|
|
8
|
-
Object.defineProperty(exports, "specialCharMap", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function () {
|
|
11
|
-
return _specialCharMap.specialCharMap;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
9
|
|
|
15
10
|
var _dom = require("@testing-library/dom");
|
|
16
11
|
|
|
12
|
+
var _document = require("../document");
|
|
13
|
+
|
|
17
14
|
var _keyboardImplementation = require("./keyboardImplementation");
|
|
18
15
|
|
|
19
16
|
var _keyMap = require("./keyMap");
|
|
20
17
|
|
|
21
|
-
var _specialCharMap = require("./specialCharMap");
|
|
22
|
-
|
|
23
18
|
function keyboard(text, options) {
|
|
24
19
|
var _options$delay;
|
|
25
20
|
|
|
@@ -51,6 +46,7 @@ function keyboardImplementationWrapper(text, config = {}) {
|
|
|
51
46
|
autoModify,
|
|
52
47
|
keyboardMap
|
|
53
48
|
};
|
|
49
|
+
(0, _document.prepareDocument)(document);
|
|
54
50
|
return {
|
|
55
51
|
promise: (0, _keyboardImplementation.keyboardImplementation)(text, options, state),
|
|
56
52
|
state,
|
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;
|
|
@@ -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);
|
|
@@ -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;
|