@testing-library/user-event 14.0.0-alpha.5 → 14.0.0-alpha.9
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/click.d.ts +1 -0
- package/dist/click.js +17 -0
- package/dist/document/index.d.ts +1 -0
- package/dist/document/selection.d.ts +17 -7
- package/dist/document/selection.js +33 -17
- package/dist/document/value.d.ts +1 -1
- package/dist/document/value.js +1 -1
- package/dist/keyboard/plugins/arrow.js +7 -12
- package/dist/keyboard/plugins/character.js +23 -42
- package/dist/keyboard/plugins/combination.d.ts +5 -0
- package/dist/keyboard/plugins/combination.js +17 -0
- package/dist/keyboard/plugins/control.js +4 -12
- package/dist/keyboard/plugins/functional.js +8 -13
- package/dist/keyboard/plugins/index.js +3 -1
- package/dist/paste.js +8 -15
- package/dist/pointer/pointerMove.js +28 -17
- package/dist/pointer/pointerPress.js +6 -4
- package/dist/pointer/resolveSelectionTarget.js +7 -6
- package/dist/setup.d.ts +4 -1
- package/dist/setup.js +4 -0
- package/dist/utils/edit/calculateNewValue.d.ts +14 -5
- package/dist/utils/edit/calculateNewValue.js +23 -21
- package/dist/utils/edit/fireInputEvent.d.ts +5 -2
- package/dist/utils/edit/fireInputEvent.js +17 -11
- 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 +4 -0
- package/dist/utils/edit/prepareInput.js +60 -0
- package/dist/utils/focus/focus.js +3 -0
- package/dist/utils/focus/selectAll.d.ts +4 -0
- package/dist/utils/focus/selectAll.js +38 -0
- package/dist/utils/focus/selection.d.ts +42 -0
- package/dist/utils/focus/selection.js +190 -0
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/index.js +30 -30
- package/dist/utils/pointer/firePointerEvents.d.ts +12 -1
- package/dist/utils/pointer/firePointerEvents.js +62 -5
- package/package.json +1 -1
- package/dist/utils/edit/cursorPosition.d.ts +0 -2
- package/dist/utils/edit/cursorPosition.js +0 -35
- package/dist/utils/edit/selectionRange.d.ts +0 -5
- package/dist/utils/edit/selectionRange.js +0 -64
- package/dist/utils/pointer/fakeEvent.d.ts +0 -20
- package/dist/utils/pointer/fakeEvent.js +0 -91
package/dist/utils/index.js
CHANGED
|
@@ -43,19 +43,6 @@ Object.keys(_calculateNewValue).forEach(function (key) {
|
|
|
43
43
|
});
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
var _cursorPosition = require("./edit/cursorPosition");
|
|
47
|
-
|
|
48
|
-
Object.keys(_cursorPosition).forEach(function (key) {
|
|
49
|
-
if (key === "default" || key === "__esModule") return;
|
|
50
|
-
if (key in exports && exports[key] === _cursorPosition[key]) return;
|
|
51
|
-
Object.defineProperty(exports, key, {
|
|
52
|
-
enumerable: true,
|
|
53
|
-
get: function () {
|
|
54
|
-
return _cursorPosition[key];
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
46
|
var _fireInputEvent = require("./edit/fireInputEvent");
|
|
60
47
|
|
|
61
48
|
Object.keys(_fireInputEvent).forEach(function (key) {
|
|
@@ -147,15 +134,15 @@ Object.keys(_maxLength).forEach(function (key) {
|
|
|
147
134
|
});
|
|
148
135
|
});
|
|
149
136
|
|
|
150
|
-
var
|
|
137
|
+
var _prepareInput = require("./edit/prepareInput");
|
|
151
138
|
|
|
152
|
-
Object.keys(
|
|
139
|
+
Object.keys(_prepareInput).forEach(function (key) {
|
|
153
140
|
if (key === "default" || key === "__esModule") return;
|
|
154
|
-
if (key in exports && exports[key] ===
|
|
141
|
+
if (key in exports && exports[key] === _prepareInput[key]) return;
|
|
155
142
|
Object.defineProperty(exports, key, {
|
|
156
143
|
enumerable: true,
|
|
157
144
|
get: function () {
|
|
158
|
-
return
|
|
145
|
+
return _prepareInput[key];
|
|
159
146
|
}
|
|
160
147
|
});
|
|
161
148
|
});
|
|
@@ -225,6 +212,32 @@ Object.keys(_isFocusable).forEach(function (key) {
|
|
|
225
212
|
});
|
|
226
213
|
});
|
|
227
214
|
|
|
215
|
+
var _selectAll = require("./focus/selectAll");
|
|
216
|
+
|
|
217
|
+
Object.keys(_selectAll).forEach(function (key) {
|
|
218
|
+
if (key === "default" || key === "__esModule") return;
|
|
219
|
+
if (key in exports && exports[key] === _selectAll[key]) return;
|
|
220
|
+
Object.defineProperty(exports, key, {
|
|
221
|
+
enumerable: true,
|
|
222
|
+
get: function () {
|
|
223
|
+
return _selectAll[key];
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
var _selection = require("./focus/selection");
|
|
229
|
+
|
|
230
|
+
Object.keys(_selection).forEach(function (key) {
|
|
231
|
+
if (key === "default" || key === "__esModule") return;
|
|
232
|
+
if (key in exports && exports[key] === _selection[key]) return;
|
|
233
|
+
Object.defineProperty(exports, key, {
|
|
234
|
+
enumerable: true,
|
|
235
|
+
get: function () {
|
|
236
|
+
return _selection[key];
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
|
|
228
241
|
var _selector = require("./focus/selector");
|
|
229
242
|
|
|
230
243
|
Object.keys(_selector).forEach(function (key) {
|
|
@@ -368,19 +381,6 @@ Object.keys(_hasFormSubmit).forEach(function (key) {
|
|
|
368
381
|
});
|
|
369
382
|
});
|
|
370
383
|
|
|
371
|
-
var _fakeEvent = require("./pointer/fakeEvent");
|
|
372
|
-
|
|
373
|
-
Object.keys(_fakeEvent).forEach(function (key) {
|
|
374
|
-
if (key === "default" || key === "__esModule") return;
|
|
375
|
-
if (key in exports && exports[key] === _fakeEvent[key]) return;
|
|
376
|
-
Object.defineProperty(exports, key, {
|
|
377
|
-
enumerable: true,
|
|
378
|
-
get: function () {
|
|
379
|
-
return _fakeEvent[key];
|
|
380
|
-
}
|
|
381
|
-
});
|
|
382
|
-
});
|
|
383
|
-
|
|
384
384
|
var _firePointerEvents = require("./pointer/firePointerEvents");
|
|
385
385
|
|
|
386
386
|
Object.keys(_firePointerEvents).forEach(function (key) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { pointerState } from '../../pointer/types';
|
|
2
2
|
import type { keyboardState } from '../../keyboard/types';
|
|
3
|
-
import { PointerCoords } from './fakeEvent';
|
|
4
3
|
import { MouseButton } from './mouseButtons';
|
|
5
4
|
export declare function firePointerEvent(target: Element, type: string, { pointerState, keyboardState, pointerType, button, coords, pointerId, isPrimary, clickCount, }: {
|
|
6
5
|
pointerState: pointerState;
|
|
@@ -12,3 +11,15 @@ export declare function firePointerEvent(target: Element, type: string, { pointe
|
|
|
12
11
|
isPrimary?: boolean;
|
|
13
12
|
clickCount?: number;
|
|
14
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
|
+
}
|
|
@@ -7,7 +7,7 @@ exports.firePointerEvent = firePointerEvent;
|
|
|
7
7
|
|
|
8
8
|
var _dom = require("@testing-library/dom");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _eventMap = require("@testing-library/dom/dist/event-map");
|
|
11
11
|
|
|
12
12
|
var _mouseButtons = require("./mouseButtons");
|
|
13
13
|
|
|
@@ -21,7 +21,6 @@ function firePointerEvent(target, type, {
|
|
|
21
21
|
isPrimary,
|
|
22
22
|
clickCount
|
|
23
23
|
}) {
|
|
24
|
-
const Event = type === 'click' || type.startsWith('mouse') ? _fakeEvent.FakeMouseEvent : _fakeEvent.FakePointerEvent;
|
|
25
24
|
const init = { ...coords,
|
|
26
25
|
altKey: keyboardState.modifiers.alt,
|
|
27
26
|
ctrlKey: keyboardState.modifiers.ctrl,
|
|
@@ -29,7 +28,7 @@ function firePointerEvent(target, type, {
|
|
|
29
28
|
shiftKey: keyboardState.modifiers.shift
|
|
30
29
|
};
|
|
31
30
|
|
|
32
|
-
if (
|
|
31
|
+
if (type === 'click' || type.startsWith('pointer')) {
|
|
33
32
|
init.pointerId = pointerId;
|
|
34
33
|
init.pointerType = pointerType;
|
|
35
34
|
}
|
|
@@ -47,9 +46,67 @@ function firePointerEvent(target, type, {
|
|
|
47
46
|
}));
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
if (['mousedown', 'mouseup', 'click'].includes(type)) {
|
|
49
|
+
if (['mousedown', 'mouseup', 'click', 'dblclick'].includes(type)) {
|
|
51
50
|
init.detail = clickCount;
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
|
|
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
|
+
});
|
|
55
112
|
}
|
package/package.json
CHANGED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isCursorAtEnd = isCursorAtEnd;
|
|
7
|
-
exports.isCursorAtStart = isCursorAtStart;
|
|
8
|
-
|
|
9
|
-
var _selectionRange = require("./selectionRange");
|
|
10
|
-
|
|
11
|
-
var _getValue2 = require("./getValue");
|
|
12
|
-
|
|
13
|
-
function isCursorAtEnd(element) {
|
|
14
|
-
var _getValue;
|
|
15
|
-
|
|
16
|
-
const {
|
|
17
|
-
selectionStart,
|
|
18
|
-
selectionEnd
|
|
19
|
-
} = (0, _selectionRange.getSelectionRange)(element);
|
|
20
|
-
return selectionStart === selectionEnd && (selectionStart != null ? selectionStart :
|
|
21
|
-
/* istanbul ignore next */
|
|
22
|
-
0) === ((_getValue = (0, _getValue2.getValue)(element)) != null ? _getValue :
|
|
23
|
-
/* istanbul ignore next */
|
|
24
|
-
'').length;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function isCursorAtStart(element) {
|
|
28
|
-
const {
|
|
29
|
-
selectionStart,
|
|
30
|
-
selectionEnd
|
|
31
|
-
} = (0, _selectionRange.getSelectionRange)(element);
|
|
32
|
-
return selectionStart === selectionEnd && (selectionStart != null ? selectionStart :
|
|
33
|
-
/* istanbul ignore next */
|
|
34
|
-
0) === 0;
|
|
35
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getSelectionRange = getSelectionRange;
|
|
7
|
-
exports.setSelectionRange = setSelectionRange;
|
|
8
|
-
|
|
9
|
-
var _isElementType = require("../misc/isElementType");
|
|
10
|
-
|
|
11
|
-
var _document = require("../../document");
|
|
12
|
-
|
|
13
|
-
function getSelectionRange(element) {
|
|
14
|
-
if ((0, _isElementType.isElementType)(element, ['input', 'textarea'])) {
|
|
15
|
-
return (0, _document.getUISelection)(element);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const selection = element.ownerDocument.getSelection(); // there should be no editing if the focusNode is outside of element
|
|
19
|
-
// TODO: properly handle selection ranges
|
|
20
|
-
|
|
21
|
-
if (selection != null && selection.rangeCount && element.contains(selection.focusNode)) {
|
|
22
|
-
const range = selection.getRangeAt(0);
|
|
23
|
-
return {
|
|
24
|
-
selectionStart: range.startOffset,
|
|
25
|
-
selectionEnd: range.endOffset
|
|
26
|
-
};
|
|
27
|
-
} else {
|
|
28
|
-
return {
|
|
29
|
-
selectionStart: null,
|
|
30
|
-
selectionEnd: null
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function setSelectionRange(element, newSelectionStart, newSelectionEnd) {
|
|
36
|
-
if ((0, _isElementType.isElementType)(element, ['input', 'textarea'])) {
|
|
37
|
-
return (0, _document.setUISelection)(element, newSelectionStart, newSelectionEnd);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const {
|
|
41
|
-
selectionStart,
|
|
42
|
-
selectionEnd
|
|
43
|
-
} = getSelectionRange(element); // Prevent unnecessary select events
|
|
44
|
-
// istanbul ignore next
|
|
45
|
-
|
|
46
|
-
if (selectionStart === newSelectionStart && selectionEnd === newSelectionEnd) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const range = element.ownerDocument.createRange();
|
|
51
|
-
range.selectNodeContents(element); // istanbul ignore else
|
|
52
|
-
|
|
53
|
-
if (element.firstChild) {
|
|
54
|
-
range.setStart(element.firstChild, newSelectionStart);
|
|
55
|
-
range.setEnd(element.firstChild, newSelectionEnd);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const selection = element.ownerDocument.getSelection(); // istanbul ignore else
|
|
59
|
-
|
|
60
|
-
if (selection) {
|
|
61
|
-
selection.removeAllRanges();
|
|
62
|
-
selection.addRange(range);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export interface PointerCoords {
|
|
2
|
-
x?: number;
|
|
3
|
-
y?: number;
|
|
4
|
-
clientX?: number;
|
|
5
|
-
clientY?: number;
|
|
6
|
-
offsetX?: number;
|
|
7
|
-
offsetY?: number;
|
|
8
|
-
pageX?: number;
|
|
9
|
-
pageY?: number;
|
|
10
|
-
screenX?: number;
|
|
11
|
-
screenY?: number;
|
|
12
|
-
}
|
|
13
|
-
export interface FakePointerEventInit extends MouseEventInit, PointerEventInit, PointerCoords {
|
|
14
|
-
}
|
|
15
|
-
export declare class FakeMouseEvent extends MouseEvent {
|
|
16
|
-
constructor(type: string, init: FakePointerEventInit);
|
|
17
|
-
}
|
|
18
|
-
export declare class FakePointerEvent extends MouseEvent {
|
|
19
|
-
constructor(type: string, init: FakePointerEventInit);
|
|
20
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.FakePointerEvent = exports.FakeMouseEvent = void 0;
|
|
7
|
-
|
|
8
|
-
// See : https://github.com/testing-library/react-testing-library/issues/268
|
|
9
|
-
function assignProps(obj, props) {
|
|
10
|
-
for (const [key, value] of Object.entries(props)) {
|
|
11
|
-
Object.defineProperty(obj, key, {
|
|
12
|
-
get: () => value
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function assignPositionInit(obj, {
|
|
18
|
-
x,
|
|
19
|
-
y,
|
|
20
|
-
clientX,
|
|
21
|
-
clientY,
|
|
22
|
-
offsetX,
|
|
23
|
-
offsetY,
|
|
24
|
-
pageX,
|
|
25
|
-
pageY,
|
|
26
|
-
screenX,
|
|
27
|
-
screenY
|
|
28
|
-
}) {
|
|
29
|
-
var _ref, _ref2, _ref3, _ref4;
|
|
30
|
-
|
|
31
|
-
assignProps(obj, {
|
|
32
|
-
/* istanbul ignore start */
|
|
33
|
-
x: (_ref = x != null ? x : clientX) != null ? _ref : 0,
|
|
34
|
-
y: (_ref2 = y != null ? y : clientY) != null ? _ref2 : 0,
|
|
35
|
-
clientX: (_ref3 = x != null ? x : clientX) != null ? _ref3 : 0,
|
|
36
|
-
clientY: (_ref4 = y != null ? y : clientY) != null ? _ref4 : 0,
|
|
37
|
-
offsetX: offsetX != null ? offsetX : 0,
|
|
38
|
-
offsetY: offsetY != null ? offsetY : 0,
|
|
39
|
-
pageX: pageX != null ? pageX : 0,
|
|
40
|
-
pageY: pageY != null ? pageY : 0,
|
|
41
|
-
screenX: screenX != null ? screenX : 0,
|
|
42
|
-
screenY: screenY != null ? screenY : 0
|
|
43
|
-
/* istanbul ignore end */
|
|
44
|
-
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function assignPointerInit(obj, {
|
|
49
|
-
isPrimary,
|
|
50
|
-
pointerId,
|
|
51
|
-
pointerType
|
|
52
|
-
}) {
|
|
53
|
-
assignProps(obj, {
|
|
54
|
-
isPrimary,
|
|
55
|
-
pointerId,
|
|
56
|
-
pointerType
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const notBubbling = ['mouseenter', 'mouseleave', 'pointerenter', 'pointerleave'];
|
|
61
|
-
|
|
62
|
-
function getInitDefaults(type, init) {
|
|
63
|
-
return {
|
|
64
|
-
bubbles: !notBubbling.includes(type),
|
|
65
|
-
cancelable: true,
|
|
66
|
-
composed: true,
|
|
67
|
-
...init
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
class FakeMouseEvent extends MouseEvent {
|
|
72
|
-
constructor(type, init) {
|
|
73
|
-
super(type, getInitDefaults(type, init));
|
|
74
|
-
assignPositionInit(this, init);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
} // Should extend PointerEvent, but... https://github.com/jsdom/jsdom/issues/2527
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
exports.FakeMouseEvent = FakeMouseEvent;
|
|
81
|
-
|
|
82
|
-
class FakePointerEvent extends MouseEvent {
|
|
83
|
-
constructor(type, init) {
|
|
84
|
-
super(type, getInitDefaults(type, init));
|
|
85
|
-
assignPositionInit(this, init);
|
|
86
|
-
assignPointerInit(this, init);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
exports.FakePointerEvent = FakePointerEvent;
|