@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
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { pointerState } from '../../pointer/types';
|
|
2
|
+
import type { keyboardState } from '../../keyboard/types';
|
|
3
|
+
import { MouseButton } from './mouseButtons';
|
|
4
|
+
export declare function firePointerEvent(target: Element, type: string, { pointerState, keyboardState, pointerType, button, coords, pointerId, isPrimary, clickCount, }: {
|
|
5
|
+
pointerState: pointerState;
|
|
6
|
+
keyboardState: keyboardState;
|
|
7
|
+
pointerType?: 'mouse' | 'pen' | 'touch';
|
|
8
|
+
button?: MouseButton;
|
|
9
|
+
coords?: PointerCoords;
|
|
10
|
+
pointerId?: number;
|
|
11
|
+
isPrimary?: boolean;
|
|
12
|
+
clickCount?: number;
|
|
13
|
+
}): boolean;
|
|
14
|
+
export interface PointerCoords {
|
|
15
|
+
x?: number;
|
|
16
|
+
y?: number;
|
|
17
|
+
clientX?: number;
|
|
18
|
+
clientY?: number;
|
|
19
|
+
offsetX?: number;
|
|
20
|
+
offsetY?: number;
|
|
21
|
+
pageX?: number;
|
|
22
|
+
pageY?: number;
|
|
23
|
+
screenX?: number;
|
|
24
|
+
screenY?: number;
|
|
25
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.firePointerEvent = firePointerEvent;
|
|
7
|
+
|
|
8
|
+
var _dom = require("@testing-library/dom");
|
|
9
|
+
|
|
10
|
+
var _eventMap = require("@testing-library/dom/dist/event-map");
|
|
11
|
+
|
|
12
|
+
var _mouseButtons = require("./mouseButtons");
|
|
13
|
+
|
|
14
|
+
function firePointerEvent(target, type, {
|
|
15
|
+
pointerState,
|
|
16
|
+
keyboardState,
|
|
17
|
+
pointerType,
|
|
18
|
+
button,
|
|
19
|
+
coords,
|
|
20
|
+
pointerId,
|
|
21
|
+
isPrimary,
|
|
22
|
+
clickCount
|
|
23
|
+
}) {
|
|
24
|
+
const init = { ...coords,
|
|
25
|
+
altKey: keyboardState.modifiers.alt,
|
|
26
|
+
ctrlKey: keyboardState.modifiers.ctrl,
|
|
27
|
+
metaKey: keyboardState.modifiers.meta,
|
|
28
|
+
shiftKey: keyboardState.modifiers.shift
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
if (type === 'click' || type.startsWith('pointer')) {
|
|
32
|
+
init.pointerId = pointerId;
|
|
33
|
+
init.pointerType = pointerType;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (['pointerdown', 'pointerup'].includes(type)) {
|
|
37
|
+
init.isPrimary = isPrimary;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (['mousedown', 'mouseup', 'pointerdown', 'pointerup', 'click'].includes(type)) {
|
|
41
|
+
init.button = (0, _mouseButtons.getMouseButton)(button != null ? button : 0);
|
|
42
|
+
init.buttons = (0, _mouseButtons.getMouseButtons)(...pointerState.pressed.filter(p => p.keyDef.pointerType === pointerType).map(p => {
|
|
43
|
+
var _p$keyDef$button;
|
|
44
|
+
|
|
45
|
+
return (_p$keyDef$button = p.keyDef.button) != null ? _p$keyDef$button : 0;
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (['mousedown', 'mouseup', 'click', 'dblclick'].includes(type)) {
|
|
50
|
+
init.detail = clickCount;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const eventKey = Object.keys(_eventMap.eventMap).find(k => k.toLowerCase() === type);
|
|
54
|
+
|
|
55
|
+
const event = _dom.createEvent[eventKey](target, init); // see https://github.com/testing-library/react-testing-library/issues/268
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
assignPositionInit(event, init);
|
|
59
|
+
assignPointerInit(event, init);
|
|
60
|
+
return (0, _dom.fireEvent)(target, event);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function assignProps(obj, props) {
|
|
64
|
+
for (const [key, value] of Object.entries(props)) {
|
|
65
|
+
Object.defineProperty(obj, key, {
|
|
66
|
+
get: () => value
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function assignPositionInit(obj, {
|
|
72
|
+
x,
|
|
73
|
+
y,
|
|
74
|
+
clientX,
|
|
75
|
+
clientY,
|
|
76
|
+
offsetX,
|
|
77
|
+
offsetY,
|
|
78
|
+
pageX,
|
|
79
|
+
pageY,
|
|
80
|
+
screenX,
|
|
81
|
+
screenY
|
|
82
|
+
}) {
|
|
83
|
+
var _ref, _ref2, _ref3, _ref4;
|
|
84
|
+
|
|
85
|
+
assignProps(obj, {
|
|
86
|
+
/* istanbul ignore start */
|
|
87
|
+
x: (_ref = x != null ? x : clientX) != null ? _ref : 0,
|
|
88
|
+
y: (_ref2 = y != null ? y : clientY) != null ? _ref2 : 0,
|
|
89
|
+
clientX: (_ref3 = x != null ? x : clientX) != null ? _ref3 : 0,
|
|
90
|
+
clientY: (_ref4 = y != null ? y : clientY) != null ? _ref4 : 0,
|
|
91
|
+
offsetX: offsetX != null ? offsetX : 0,
|
|
92
|
+
offsetY: offsetY != null ? offsetY : 0,
|
|
93
|
+
pageX: pageX != null ? pageX : 0,
|
|
94
|
+
pageY: pageY != null ? pageY : 0,
|
|
95
|
+
screenX: screenX != null ? screenX : 0,
|
|
96
|
+
screenY: screenY != null ? screenY : 0
|
|
97
|
+
/* istanbul ignore end */
|
|
98
|
+
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function assignPointerInit(obj, {
|
|
103
|
+
isPrimary,
|
|
104
|
+
pointerId,
|
|
105
|
+
pointerType
|
|
106
|
+
}) {
|
|
107
|
+
assignProps(obj, {
|
|
108
|
+
isPrimary,
|
|
109
|
+
pointerId,
|
|
110
|
+
pointerType
|
|
111
|
+
});
|
|
112
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const MouseButton: {
|
|
2
|
+
readonly primary: 0;
|
|
3
|
+
readonly secondary: 1;
|
|
4
|
+
readonly auxiliary: 2;
|
|
5
|
+
readonly back: 3;
|
|
6
|
+
readonly X1: 3;
|
|
7
|
+
readonly forward: 4;
|
|
8
|
+
readonly X2: 4;
|
|
9
|
+
};
|
|
10
|
+
export declare type MouseButton = keyof typeof MouseButton | number;
|
|
11
|
+
export declare function getMouseButton(button: MouseButton): number;
|
|
12
|
+
export declare function getMouseButtons(...buttons: Array<MouseButton>): number;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MouseButton = void 0;
|
|
7
|
+
exports.getMouseButton = getMouseButton;
|
|
8
|
+
exports.getMouseButtons = getMouseButtons;
|
|
9
|
+
const MouseButton = {
|
|
10
|
+
primary: 0,
|
|
11
|
+
secondary: 1,
|
|
12
|
+
auxiliary: 2,
|
|
13
|
+
back: 3,
|
|
14
|
+
X1: 3,
|
|
15
|
+
forward: 4,
|
|
16
|
+
X2: 4
|
|
17
|
+
};
|
|
18
|
+
exports.MouseButton = MouseButton;
|
|
19
|
+
// Some legacy...
|
|
20
|
+
const MouseButtonFlip = {
|
|
21
|
+
auxiliary: 1,
|
|
22
|
+
secondary: 2,
|
|
23
|
+
1: 2,
|
|
24
|
+
2: 1
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function getMouseButton(button) {
|
|
28
|
+
if (button in MouseButtonFlip) {
|
|
29
|
+
return MouseButtonFlip[button];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return typeof button === 'number' ? button : MouseButton[button];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getMouseButtons(...buttons) {
|
|
36
|
+
let v = 0;
|
|
37
|
+
|
|
38
|
+
for (const t of buttons) {
|
|
39
|
+
const pos = typeof t === 'number' ? t : MouseButton[t]; // eslint-disable-next-line no-bitwise
|
|
40
|
+
|
|
41
|
+
v |= 2 ** pos;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return v;
|
|
45
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testing-library/user-event",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.0.0-alpha.12",
|
|
4
4
|
"description": "Fire events the same way the user does",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"author": "Giorgio Polvara <polvara@gmail.com>",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"engines": {
|
|
15
|
-
"node": ">=
|
|
15
|
+
"node": ">=12",
|
|
16
16
|
"npm": ">=6"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
|
-
"build": "kcd-scripts build",
|
|
30
|
+
"build": "kcd-scripts build --no-ts-defs && tsc -p tsconfig.build.json",
|
|
31
31
|
"lint": "kcd-scripts lint",
|
|
32
32
|
"setup": "npm install && npm run validate -s",
|
|
33
33
|
"test": "kcd-scripts test",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"@types/estree": "0.0.45",
|
|
47
47
|
"@types/jest-in-case": "^1.0.3",
|
|
48
48
|
"@types/react": "^17.0.3",
|
|
49
|
+
"eslint-import-resolver-typescript": "^2.5.0",
|
|
49
50
|
"is-ci": "^2.0.0",
|
|
50
51
|
"jest-in-case": "^1.0.2",
|
|
51
52
|
"jest-serializer-ansi": "^1.0.3",
|
package/dist/blur.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.blur = blur;
|
|
7
|
-
|
|
8
|
-
var _utils = require("./utils");
|
|
9
|
-
|
|
10
|
-
function blur(element) {
|
|
11
|
-
if (!(0, _utils.isFocusable)(element)) return;
|
|
12
|
-
const wasActive = (0, _utils.getActiveElement)(element.ownerDocument) === element;
|
|
13
|
-
if (!wasActive) return;
|
|
14
|
-
(0, _utils.eventWrapper)(() => element.blur());
|
|
15
|
-
}
|
package/dist/dom-helpers.d.ts
DELETED
package/dist/focus.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.focus = focus;
|
|
7
|
-
|
|
8
|
-
var _utils = require("./utils");
|
|
9
|
-
|
|
10
|
-
function focus(element) {
|
|
11
|
-
if (!(0, _utils.isFocusable)(element)) return;
|
|
12
|
-
const isAlreadyActive = (0, _utils.getActiveElement)(element.ownerDocument) === element;
|
|
13
|
-
if (isAlreadyActive) return;
|
|
14
|
-
(0, _utils.eventWrapper)(() => element.focus());
|
|
15
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.carryValue = carryValue;
|
|
7
|
-
|
|
8
|
-
var _utils = require("../../utils");
|
|
9
|
-
|
|
10
|
-
function carryValue(element, state, newValue) {
|
|
11
|
-
const value = (0, _utils.getValue)(element);
|
|
12
|
-
state.carryValue = value !== newValue && value === '' && (0, _utils.hasUnreliableEmptyValue)(element) ? newValue : undefined;
|
|
13
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { fireEvent } from '@testing-library/dom';
|
|
2
|
-
export declare function fireInputEvent(element: HTMLElement, { newValue, newSelectionStart, eventOverrides, }: {
|
|
3
|
-
newValue: string;
|
|
4
|
-
newSelectionStart: number;
|
|
5
|
-
eventOverrides: Partial<Parameters<typeof fireEvent>[1]> & {
|
|
6
|
-
[k: string]: unknown;
|
|
7
|
-
};
|
|
8
|
-
}): void;
|
|
9
|
-
declare const initial: unique symbol;
|
|
10
|
-
declare const onBlur: unique symbol;
|
|
11
|
-
declare global {
|
|
12
|
-
interface Element {
|
|
13
|
-
[initial]?: string;
|
|
14
|
-
[onBlur]?: EventListener;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
export {};
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.fireInputEvent = fireInputEvent;
|
|
7
|
-
|
|
8
|
-
var _dom = require("@testing-library/dom");
|
|
9
|
-
|
|
10
|
-
var _utils = require("../../utils");
|
|
11
|
-
|
|
12
|
-
function fireInputEvent(element, {
|
|
13
|
-
newValue,
|
|
14
|
-
newSelectionStart,
|
|
15
|
-
eventOverrides
|
|
16
|
-
}) {
|
|
17
|
-
// apply the changes before firing the input event, so that input handlers can access the altered dom and selection
|
|
18
|
-
if ((0, _utils.isContentEditable)(element)) {
|
|
19
|
-
applyNative(element, 'textContent', newValue);
|
|
20
|
-
} else
|
|
21
|
-
/* istanbul ignore else */
|
|
22
|
-
if ((0, _utils.isElementType)(element, ['input', 'textarea'])) {
|
|
23
|
-
applyNative(element, 'value', newValue);
|
|
24
|
-
} else {
|
|
25
|
-
// TODO: properly type guard
|
|
26
|
-
throw new Error('Invalid Element');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
setSelectionRangeAfterInput(element, newSelectionStart);
|
|
30
|
-
|
|
31
|
-
_dom.fireEvent.input(element, { ...eventOverrides
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
setSelectionRangeAfterInputHandler(element, newValue, newSelectionStart);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function setSelectionRangeAfterInput(element, newSelectionStart) {
|
|
38
|
-
(0, _utils.setSelectionRange)(element, newSelectionStart, newSelectionStart);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function setSelectionRangeAfterInputHandler(element, newValue, newSelectionStart) {
|
|
42
|
-
const value = (0, _utils.getValue)(element); // don't apply this workaround on elements that don't necessarily report the visible value - e.g. number
|
|
43
|
-
// TODO: this could probably be only applied when there is keyboardState.carryValue
|
|
44
|
-
|
|
45
|
-
const isUnreliableValue = value === '' && (0, _utils.hasUnreliableEmptyValue)(element);
|
|
46
|
-
|
|
47
|
-
if (!isUnreliableValue && value === newValue) {
|
|
48
|
-
const {
|
|
49
|
-
selectionStart
|
|
50
|
-
} = (0, _utils.getSelectionRange)(element);
|
|
51
|
-
|
|
52
|
-
if (selectionStart === value.length) {
|
|
53
|
-
// The value was changed as expected, but the cursor was moved to the end
|
|
54
|
-
// TODO: this could probably be only applied when we work around a framework setter on the element in applyNative
|
|
55
|
-
(0, _utils.setSelectionRange)(element, newSelectionStart, newSelectionStart);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const initial = Symbol('initial input value/textContent');
|
|
61
|
-
const onBlur = Symbol('onBlur');
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* React tracks the changes on element properties.
|
|
65
|
-
* This workaround tries to alter the DOM element without React noticing,
|
|
66
|
-
* so that it later picks up the change.
|
|
67
|
-
*
|
|
68
|
-
* @see https://github.com/facebook/react/blob/148f8e497c7d37a3c7ab99f01dec2692427272b1/packages/react-dom/src/client/inputValueTracking.js#L51-L104
|
|
69
|
-
*/
|
|
70
|
-
function applyNative(element, propName, propValue) {
|
|
71
|
-
const descriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
72
|
-
const nativeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
73
|
-
|
|
74
|
-
if (descriptor && nativeDescriptor) {
|
|
75
|
-
Object.defineProperty(element, propName, nativeDescriptor);
|
|
76
|
-
} // Keep track of the initial value to determine if a change event should be dispatched.
|
|
77
|
-
// CONSTRAINT: We can not determine what happened between focus event and our first API call.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (element[initial] === undefined) {
|
|
81
|
-
element[initial] = String(element[propName]);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
element[propName] = propValue; // Add an event listener for the blur event to the capture phase on the window.
|
|
85
|
-
// CONSTRAINT: Currently there is no cross-platform solution to unshift the event handler stack.
|
|
86
|
-
// Our change event might occur after other event handlers on the blur event have been processed.
|
|
87
|
-
|
|
88
|
-
if (!element[onBlur]) {
|
|
89
|
-
var _element$ownerDocumen;
|
|
90
|
-
|
|
91
|
-
(_element$ownerDocumen = element.ownerDocument.defaultView) == null ? void 0 : _element$ownerDocumen.addEventListener('blur', element[onBlur] = () => {
|
|
92
|
-
const initV = element[initial]; // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
93
|
-
|
|
94
|
-
delete element[onBlur]; // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
95
|
-
|
|
96
|
-
delete element[initial];
|
|
97
|
-
|
|
98
|
-
if (String(element[propName]) !== initV) {
|
|
99
|
-
_dom.fireEvent.change(element);
|
|
100
|
-
}
|
|
101
|
-
}, {
|
|
102
|
-
capture: true,
|
|
103
|
-
once: true
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (descriptor) {
|
|
108
|
-
Object.defineProperty(element, propName, descriptor);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deprecated This list of strings with special meaning is no longer necessary
|
|
3
|
-
* as we've introduced a standardized way to describe any keystroke for `userEvent`.
|
|
4
|
-
* @see https://testing-library.com/docs/ecosystem-user-event#keyboardtext-options
|
|
5
|
-
*/
|
|
6
|
-
export declare const specialCharMap: {
|
|
7
|
-
readonly arrowLeft: "{arrowleft}";
|
|
8
|
-
readonly arrowRight: "{arrowright}";
|
|
9
|
-
readonly arrowDown: "{arrowdown}";
|
|
10
|
-
readonly arrowUp: "{arrowup}";
|
|
11
|
-
readonly enter: "{enter}";
|
|
12
|
-
readonly escape: "{esc}";
|
|
13
|
-
readonly delete: "{del}";
|
|
14
|
-
readonly backspace: "{backspace}";
|
|
15
|
-
readonly home: "{home}";
|
|
16
|
-
readonly end: "{end}";
|
|
17
|
-
readonly selectAll: "{selectall}";
|
|
18
|
-
readonly space: "{space}";
|
|
19
|
-
readonly whitespace: " ";
|
|
20
|
-
readonly pageUp: "{pageUp}";
|
|
21
|
-
readonly pageDown: "{pageDown}";
|
|
22
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.specialCharMap = void 0;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @deprecated This list of strings with special meaning is no longer necessary
|
|
10
|
-
* as we've introduced a standardized way to describe any keystroke for `userEvent`.
|
|
11
|
-
* @see https://testing-library.com/docs/ecosystem-user-event#keyboardtext-options
|
|
12
|
-
*/
|
|
13
|
-
const specialCharMap = {
|
|
14
|
-
arrowLeft: '{arrowleft}',
|
|
15
|
-
arrowRight: '{arrowright}',
|
|
16
|
-
arrowDown: '{arrowdown}',
|
|
17
|
-
arrowUp: '{arrowup}',
|
|
18
|
-
enter: '{enter}',
|
|
19
|
-
escape: '{esc}',
|
|
20
|
-
delete: '{del}',
|
|
21
|
-
backspace: '{backspace}',
|
|
22
|
-
home: '{home}',
|
|
23
|
-
end: '{end}',
|
|
24
|
-
selectAll: '{selectall}',
|
|
25
|
-
space: '{space}',
|
|
26
|
-
whitespace: ' ',
|
|
27
|
-
pageUp: '{pageUp}',
|
|
28
|
-
pageDown: '{pageDown}'
|
|
29
|
-
};
|
|
30
|
-
exports.specialCharMap = specialCharMap;
|
package/dist/select-options.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { PointerOptions } from './utils';
|
|
2
|
-
declare const selectOptions: (args_0: Element, args_1: string | string[] | HTMLElement | HTMLElement[], args_2?: MouseEventInit | undefined, args_3?: PointerOptions | undefined) => void;
|
|
3
|
-
declare const deselectOptions: (args_0: Element, args_1: string | string[] | HTMLElement | HTMLElement[], args_2?: MouseEventInit | undefined, args_3?: PointerOptions | undefined) => void;
|
|
4
|
-
export { selectOptions, deselectOptions };
|
package/dist/type/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { typeOptions } from './typeImplementation';
|
|
2
|
-
export declare function type(element: Element, text: string, options?: typeOptions & {
|
|
3
|
-
delay?: 0;
|
|
4
|
-
}): void;
|
|
5
|
-
export declare function type(element: Element, text: string, options: typeOptions & {
|
|
6
|
-
delay: number;
|
|
7
|
-
}): Promise<void>;
|
package/dist/type/index.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.type = type;
|
|
7
|
-
|
|
8
|
-
var _dom = require("@testing-library/dom");
|
|
9
|
-
|
|
10
|
-
var _typeImplementation = require("./typeImplementation");
|
|
11
|
-
|
|
12
|
-
// this needs to be wrapped in the event/asyncWrapper for React's act and angular's change detection
|
|
13
|
-
// depending on whether it will be async.
|
|
14
|
-
function type(element, text, {
|
|
15
|
-
delay = 0,
|
|
16
|
-
...options
|
|
17
|
-
} = {}) {
|
|
18
|
-
// we do not want to wrap in the asyncWrapper if we're not
|
|
19
|
-
// going to actually be doing anything async, so we only wrap
|
|
20
|
-
// if the delay is greater than 0
|
|
21
|
-
if (delay > 0) {
|
|
22
|
-
return (0, _dom.getConfig)().asyncWrapper(() => (0, _typeImplementation.typeImplementation)(element, text, {
|
|
23
|
-
delay,
|
|
24
|
-
...options
|
|
25
|
-
}));
|
|
26
|
-
} else {
|
|
27
|
-
return void (0, _typeImplementation.typeImplementation)(element, text, {
|
|
28
|
-
delay,
|
|
29
|
-
...options
|
|
30
|
-
}) // prevents users from dealing with UnhandledPromiseRejectionWarning
|
|
31
|
-
.catch(console.error);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export interface typeOptions {
|
|
2
|
-
delay?: number;
|
|
3
|
-
skipClick?: boolean;
|
|
4
|
-
skipAutoClose?: boolean;
|
|
5
|
-
initialSelectionStart?: number;
|
|
6
|
-
initialSelectionEnd?: number;
|
|
7
|
-
}
|
|
8
|
-
export declare function typeImplementation(element: Element, text: string, { delay, skipClick, skipAutoClose, initialSelectionStart, initialSelectionEnd, }: typeOptions & {
|
|
9
|
-
delay: number;
|
|
10
|
-
}): Promise<void>;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.typeImplementation = typeImplementation;
|
|
7
|
-
|
|
8
|
-
var _utils = require("../utils");
|
|
9
|
-
|
|
10
|
-
var _click = require("../click");
|
|
11
|
-
|
|
12
|
-
var _keyboard = require("../keyboard");
|
|
13
|
-
|
|
14
|
-
async function typeImplementation(element, text, {
|
|
15
|
-
delay,
|
|
16
|
-
skipClick = false,
|
|
17
|
-
skipAutoClose = false,
|
|
18
|
-
initialSelectionStart = undefined,
|
|
19
|
-
initialSelectionEnd = undefined
|
|
20
|
-
}) {
|
|
21
|
-
// TODO: properly type guard
|
|
22
|
-
// we use this workaround for now to prevent changing behavior
|
|
23
|
-
if (element.disabled) return;
|
|
24
|
-
if (!skipClick) (0, _click.click)(element); // The focused element could change between each event, so get the currently active element each time
|
|
25
|
-
|
|
26
|
-
const currentElement = () => (0, _utils.getActiveElement)(element.ownerDocument); // by default, a new element has its selection start and end at 0
|
|
27
|
-
// but most of the time when people call "type", they expect it to type
|
|
28
|
-
// at the end of the current input value. So, if the selection start
|
|
29
|
-
// and end are both the default of 0, then we'll go ahead and change
|
|
30
|
-
// them to the length of the current value.
|
|
31
|
-
// the only time it would make sense to pass the initialSelectionStart or
|
|
32
|
-
// initialSelectionEnd is if you have an input with a value and want to
|
|
33
|
-
// explicitly start typing with the cursor at 0. Not super common.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const value = (0, _utils.getValue)(currentElement());
|
|
37
|
-
const {
|
|
38
|
-
selectionStart,
|
|
39
|
-
selectionEnd
|
|
40
|
-
} = (0, _utils.getSelectionRange)(element);
|
|
41
|
-
|
|
42
|
-
if (value != null && (selectionStart === null || selectionStart === 0) && (selectionEnd === null || selectionEnd === 0)) {
|
|
43
|
-
(0, _utils.setSelectionRange)(currentElement(), initialSelectionStart != null ? initialSelectionStart : value.length, initialSelectionEnd != null ? initialSelectionEnd : value.length);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const {
|
|
47
|
-
promise,
|
|
48
|
-
releaseAllKeys
|
|
49
|
-
} = (0, _keyboard.keyboardImplementationWrapper)(text, {
|
|
50
|
-
delay,
|
|
51
|
-
document: element.ownerDocument
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
if (delay > 0) {
|
|
55
|
-
await promise;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (!skipAutoClose) {
|
|
59
|
-
releaseAllKeys();
|
|
60
|
-
} // eslint-disable-next-line consistent-return -- we need to return the internal Promise so that it is catchable if we don't await
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return promise;
|
|
64
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export declare function getMouseEventOptions(event: string, init?: MouseEventInit, clickCount?: number): {
|
|
2
|
-
detail: number;
|
|
3
|
-
buttons: number;
|
|
4
|
-
button: number;
|
|
5
|
-
clientX?: number | undefined;
|
|
6
|
-
clientY?: number | undefined;
|
|
7
|
-
movementX?: number | undefined;
|
|
8
|
-
movementY?: number | undefined;
|
|
9
|
-
relatedTarget?: EventTarget | null | undefined;
|
|
10
|
-
screenX?: number | undefined;
|
|
11
|
-
screenY?: number | undefined;
|
|
12
|
-
altKey?: boolean | undefined;
|
|
13
|
-
ctrlKey?: boolean | undefined;
|
|
14
|
-
metaKey?: boolean | undefined;
|
|
15
|
-
modifierAltGraph?: boolean | undefined;
|
|
16
|
-
modifierCapsLock?: boolean | undefined;
|
|
17
|
-
modifierFn?: boolean | undefined;
|
|
18
|
-
modifierFnLock?: boolean | undefined;
|
|
19
|
-
modifierHyper?: boolean | undefined;
|
|
20
|
-
modifierNumLock?: boolean | undefined;
|
|
21
|
-
modifierScrollLock?: boolean | undefined;
|
|
22
|
-
modifierSuper?: boolean | undefined;
|
|
23
|
-
modifierSymbol?: boolean | undefined;
|
|
24
|
-
modifierSymbolLock?: boolean | undefined;
|
|
25
|
-
shiftKey?: boolean | undefined;
|
|
26
|
-
view?: Window | null | undefined;
|
|
27
|
-
which?: number | undefined;
|
|
28
|
-
bubbles?: boolean | undefined;
|
|
29
|
-
cancelable?: boolean | undefined;
|
|
30
|
-
composed?: boolean | undefined;
|
|
31
|
-
};
|