@testing-library/user-event 14.0.0-beta.3 → 14.0.0-beta.4
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/index.d.ts +1110 -3
- package/dist/index.js +2826 -8
- package/dist/package.json +1 -0
- package/package.json +6 -30
- package/dist/clipboard/copy.d.ts +0 -2
- package/dist/clipboard/copy.js +0 -36
- package/dist/clipboard/cut.d.ts +0 -2
- package/dist/clipboard/cut.js +0 -42
- package/dist/clipboard/index.d.ts +0 -3
- package/dist/clipboard/index.js +0 -44
- package/dist/clipboard/paste.d.ts +0 -2
- package/dist/clipboard/paste.js +0 -47
- package/dist/convenience/click.d.ts +0 -4
- package/dist/convenience/click.js +0 -52
- package/dist/convenience/hover.d.ts +0 -3
- package/dist/convenience/hover.js +0 -31
- package/dist/convenience/index.d.ts +0 -3
- package/dist/convenience/index.js +0 -44
- package/dist/convenience/tab.d.ts +0 -4
- package/dist/convenience/tab.js +0 -12
- package/dist/document/index.d.ts +0 -10
- package/dist/document/index.js +0 -100
- package/dist/document/interceptor.d.ts +0 -15
- package/dist/document/interceptor.js +0 -37
- package/dist/document/selection.d.ts +0 -27
- package/dist/document/selection.js +0 -90
- package/dist/document/value.d.ts +0 -18
- package/dist/document/value.js +0 -77
- package/dist/keyboard/getEventProps.d.ts +0 -15
- package/dist/keyboard/getEventProps.js +0 -27
- package/dist/keyboard/index.d.ts +0 -7
- package/dist/keyboard/index.js +0 -42
- package/dist/keyboard/keyMap.d.ts +0 -5
- package/dist/keyboard/keyMap.js +0 -119
- package/dist/keyboard/keyboardAction.d.ts +0 -10
- package/dist/keyboard/keyboardAction.js +0 -156
- package/dist/keyboard/parseKeyDef.d.ts +0 -17
- package/dist/keyboard/parseKeyDef.js +0 -61
- package/dist/keyboard/plugins/arrow.d.ts +0 -6
- package/dist/keyboard/plugins/arrow.js +0 -28
- package/dist/keyboard/plugins/character.d.ts +0 -5
- package/dist/keyboard/plugins/character.js +0 -173
- package/dist/keyboard/plugins/combination.d.ts +0 -5
- package/dist/keyboard/plugins/combination.js +0 -19
- package/dist/keyboard/plugins/control.d.ts +0 -6
- package/dist/keyboard/plugins/control.js +0 -52
- package/dist/keyboard/plugins/functional.d.ts +0 -11
- package/dist/keyboard/plugins/functional.js +0 -158
- package/dist/keyboard/plugins/index.d.ts +0 -7
- package/dist/keyboard/plugins/index.js +0 -33
- package/dist/keyboard/shared/fireChangeForInputTimeIfValid.d.ts +0 -3
- package/dist/keyboard/shared/fireChangeForInputTimeIfValid.js +0 -20
- package/dist/keyboard/shared/index.d.ts +0 -1
- package/dist/keyboard/shared/index.js +0 -18
- package/dist/keyboard/types.d.ts +0 -64
- package/dist/keyboard/types.js +0 -19
- package/dist/options.d.ts +0 -102
- package/dist/options.js +0 -36
- package/dist/pointer/index.d.ts +0 -10
- package/dist/pointer/index.js +0 -56
- package/dist/pointer/keyMap.d.ts +0 -2
- package/dist/pointer/keyMap.js +0 -29
- package/dist/pointer/parseKeyDef.d.ts +0 -6
- package/dist/pointer/parseKeyDef.js +0 -34
- package/dist/pointer/pointerAction.d.ts +0 -7
- package/dist/pointer/pointerAction.js +0 -46
- package/dist/pointer/pointerMove.d.ts +0 -6
- package/dist/pointer/pointerMove.js +0 -136
- package/dist/pointer/pointerPress.d.ts +0 -8
- package/dist/pointer/pointerPress.js +0 -327
- package/dist/pointer/resolveSelectionTarget.d.ts +0 -5
- package/dist/pointer/resolveSelectionTarget.js +0 -75
- package/dist/pointer/types.d.ts +0 -61
- package/dist/pointer/types.js +0 -1
- package/dist/setup/api.d.ts +0 -5
- package/dist/setup/api.js +0 -111
- package/dist/setup/config.d.ts +0 -10
- package/dist/setup/config.js +0 -8
- package/dist/setup/directApi.d.ts +0 -20
- package/dist/setup/directApi.js +0 -95
- package/dist/setup/index.d.ts +0 -30
- package/dist/setup/index.js +0 -27
- package/dist/setup/setup.d.ts +0 -74
- package/dist/setup/setup.js +0 -98
- package/dist/setup/wrapAsync.d.ts +0 -4
- package/dist/setup/wrapAsync.js +0 -15
- package/dist/utility/clear.d.ts +0 -2
- package/dist/utility/clear.js +0 -30
- package/dist/utility/index.d.ts +0 -4
- package/dist/utility/index.js +0 -57
- package/dist/utility/selectOptions.d.ts +0 -3
- package/dist/utility/selectOptions.js +0 -132
- package/dist/utility/type.d.ts +0 -9
- package/dist/utility/type.js +0 -37
- package/dist/utility/upload.d.ts +0 -5
- package/dist/utility/upload.js +0 -64
- package/dist/utils/click/isClickableInput.d.ts +0 -1
- package/dist/utils/click/isClickableInput.js +0 -14
- package/dist/utils/dataTransfer/Blob.d.ts +0 -1
- package/dist/utils/dataTransfer/Blob.js +0 -21
- package/dist/utils/dataTransfer/Clipboard.d.ts +0 -9
- package/dist/utils/dataTransfer/Clipboard.js +0 -188
- package/dist/utils/dataTransfer/DataTransfer.d.ts +0 -2
- package/dist/utils/dataTransfer/DataTransfer.js +0 -158
- package/dist/utils/dataTransfer/FileList.d.ts +0 -1
- package/dist/utils/dataTransfer/FileList.js +0 -23
- package/dist/utils/edit/buildTimeValue.d.ts +0 -1
- package/dist/utils/edit/buildTimeValue.js +0 -44
- package/dist/utils/edit/calculateNewValue.d.ts +0 -14
- package/dist/utils/edit/calculateNewValue.js +0 -46
- package/dist/utils/edit/editInputElement.d.ts +0 -16
- package/dist/utils/edit/editInputElement.js +0 -53
- package/dist/utils/edit/getValue.d.ts +0 -1
- package/dist/utils/edit/getValue.js +0 -23
- package/dist/utils/edit/isContentEditable.d.ts +0 -7
- package/dist/utils/edit/isContentEditable.js +0 -25
- package/dist/utils/edit/isEditable.d.ts +0 -25
- package/dist/utils/edit/isEditable.js +0 -42
- package/dist/utils/edit/isValidDateValue.d.ts +0 -3
- package/dist/utils/edit/isValidDateValue.js +0 -12
- package/dist/utils/edit/isValidInputTimeValue.d.ts +0 -3
- package/dist/utils/edit/isValidInputTimeValue.js +0 -12
- package/dist/utils/edit/maxLength.d.ts +0 -1
- package/dist/utils/edit/maxLength.js +0 -50
- package/dist/utils/edit/prepareInput.d.ts +0 -7
- package/dist/utils/edit/prepareInput.js +0 -77
- package/dist/utils/edit/setFiles.d.ts +0 -12
- package/dist/utils/edit/setFiles.js +0 -72
- package/dist/utils/focus/blur.d.ts +0 -2
- package/dist/utils/focus/blur.js +0 -19
- package/dist/utils/focus/copySelection.d.ts +0 -1
- package/dist/utils/focus/copySelection.js +0 -36
- package/dist/utils/focus/focus.d.ts +0 -2
- package/dist/utils/focus/focus.js +0 -22
- package/dist/utils/focus/getActiveElement.d.ts +0 -1
- package/dist/utils/focus/getActiveElement.js +0 -26
- package/dist/utils/focus/getTabDestination.d.ts +0 -1
- package/dist/utils/focus/getTabDestination.js +0 -84
- package/dist/utils/focus/isFocusable.d.ts +0 -1
- package/dist/utils/focus/isFocusable.js +0 -12
- package/dist/utils/focus/selectAll.d.ts +0 -5
- package/dist/utils/focus/selectAll.js +0 -51
- package/dist/utils/focus/selection.d.ts +0 -42
- package/dist/utils/focus/selection.js +0 -190
- package/dist/utils/focus/selector.d.ts +0 -1
- package/dist/utils/focus/selector.js +0 -8
- package/dist/utils/index.d.ts +0 -38
- package/dist/utils/index.js +0 -499
- package/dist/utils/keyDef/readNextDescriptor.d.ts +0 -19
- package/dist/utils/keyDef/readNextDescriptor.js +0 -102
- package/dist/utils/misc/eventWrapper.d.ts +0 -1
- package/dist/utils/misc/eventWrapper.js +0 -16
- package/dist/utils/misc/findClosest.d.ts +0 -1
- package/dist/utils/misc/findClosest.js +0 -20
- package/dist/utils/misc/getDocumentFromNode.d.ts +0 -1
- package/dist/utils/misc/getDocumentFromNode.js +0 -14
- package/dist/utils/misc/hasFormSubmit.d.ts +0 -1
- package/dist/utils/misc/hasFormSubmit.js +0 -10
- package/dist/utils/misc/hasPointerEvents.d.ts +0 -15
- package/dist/utils/misc/hasPointerEvents.js +0 -24
- package/dist/utils/misc/isDescendantOrSelf.d.ts +0 -1
- package/dist/utils/misc/isDescendantOrSelf.js +0 -20
- package/dist/utils/misc/isDisabled.d.ts +0 -1
- package/dist/utils/misc/isDisabled.js +0 -12
- package/dist/utils/misc/isElementType.d.ts +0 -5
- package/dist/utils/misc/isElementType.js +0 -24
- package/dist/utils/misc/isVisible.d.ts +0 -1
- package/dist/utils/misc/isVisible.js +0 -31
- package/dist/utils/misc/wait.d.ts +0 -1
- package/dist/utils/misc/wait.js +0 -10
- package/dist/utils/pointer/firePointerEvents.d.ts +0 -25
- package/dist/utils/pointer/firePointerEvents.js +0 -110
- package/dist/utils/pointer/mouseButtons.d.ts +0 -12
- package/dist/utils/pointer/mouseButtons.js +0 -45
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.pointerPress = pointerPress;
|
|
7
|
-
|
|
8
|
-
var _utils = require("../utils");
|
|
9
|
-
|
|
10
|
-
var _document = require("../document");
|
|
11
|
-
|
|
12
|
-
var _resolveSelectionTarget = require("./resolveSelectionTarget");
|
|
13
|
-
|
|
14
|
-
/* eslint-disable complexity */
|
|
15
|
-
async function pointerPress(action, state) {
|
|
16
|
-
const {
|
|
17
|
-
keyDef,
|
|
18
|
-
target,
|
|
19
|
-
releasePrevious,
|
|
20
|
-
releaseSelf
|
|
21
|
-
} = action;
|
|
22
|
-
const previous = state.pointerState.pressed.find(p => p.keyDef === keyDef);
|
|
23
|
-
const pointerName = keyDef.pointerType === 'touch' ? keyDef.name : keyDef.pointerType;
|
|
24
|
-
const targetIsDisabled = (0, _utils.isDisabled)(target);
|
|
25
|
-
|
|
26
|
-
if (previous) {
|
|
27
|
-
up(state, pointerName, action, previous, targetIsDisabled);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!releasePrevious) {
|
|
31
|
-
const press = down(state, pointerName, action, targetIsDisabled);
|
|
32
|
-
|
|
33
|
-
if (releaseSelf) {
|
|
34
|
-
up(state, pointerName, action, press, targetIsDisabled);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function getNextPointerId(state) {
|
|
40
|
-
state.pointerId = state.pointerId + 1;
|
|
41
|
-
return state.pointerId;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function down({
|
|
45
|
-
pointerState,
|
|
46
|
-
keyboardState
|
|
47
|
-
}, pointerName, {
|
|
48
|
-
keyDef,
|
|
49
|
-
node,
|
|
50
|
-
offset,
|
|
51
|
-
target,
|
|
52
|
-
coords
|
|
53
|
-
}, targetIsDisabled) {
|
|
54
|
-
var _pointerState$activeC, _pointerState$activeC2, _pointerState$activeC3;
|
|
55
|
-
|
|
56
|
-
const {
|
|
57
|
-
name,
|
|
58
|
-
pointerType,
|
|
59
|
-
button
|
|
60
|
-
} = keyDef;
|
|
61
|
-
const pointerId = pointerType === 'mouse' ? 1 : getNextPointerId(pointerState);
|
|
62
|
-
pointerState.position[pointerName] = { ...pointerState.position[pointerName],
|
|
63
|
-
pointerId,
|
|
64
|
-
pointerType,
|
|
65
|
-
target,
|
|
66
|
-
coords
|
|
67
|
-
};
|
|
68
|
-
let isMultiTouch = false;
|
|
69
|
-
let isPrimary = true;
|
|
70
|
-
|
|
71
|
-
if (pointerType !== 'mouse') {
|
|
72
|
-
for (const obj of pointerState.pressed) {
|
|
73
|
-
// TODO: test multi device input across browsers
|
|
74
|
-
// istanbul ignore else
|
|
75
|
-
if (obj.keyDef.pointerType === pointerType) {
|
|
76
|
-
obj.isMultiTouch = true;
|
|
77
|
-
isMultiTouch = true;
|
|
78
|
-
isPrimary = false;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (((_pointerState$activeC = pointerState.activeClickCount) == null ? void 0 : _pointerState$activeC[0]) !== name) {
|
|
84
|
-
delete pointerState.activeClickCount;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const clickCount = Number((_pointerState$activeC2 = (_pointerState$activeC3 = pointerState.activeClickCount) == null ? void 0 : _pointerState$activeC3[1]) != null ? _pointerState$activeC2 : 0) + 1;
|
|
88
|
-
pointerState.activeClickCount = [name, clickCount];
|
|
89
|
-
const pressObj = {
|
|
90
|
-
keyDef,
|
|
91
|
-
downTarget: target,
|
|
92
|
-
pointerId,
|
|
93
|
-
unpreventedDefault: true,
|
|
94
|
-
isMultiTouch,
|
|
95
|
-
isPrimary,
|
|
96
|
-
clickCount
|
|
97
|
-
};
|
|
98
|
-
pointerState.pressed.push(pressObj);
|
|
99
|
-
|
|
100
|
-
if (!targetIsDisabled) {
|
|
101
|
-
if (pointerType !== 'mouse') {
|
|
102
|
-
fire('pointerover');
|
|
103
|
-
fire('pointerenter');
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (pointerType !== 'mouse' || !pointerState.pressed.some(p => p.keyDef !== keyDef && p.keyDef.pointerType === pointerType)) {
|
|
107
|
-
fire('pointerdown');
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (pointerType === 'mouse') {
|
|
111
|
-
pressObj.unpreventedDefault = fire('mousedown');
|
|
112
|
-
} // TODO: touch...
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (pointerType === 'mouse' && pressObj.unpreventedDefault) {
|
|
117
|
-
mousedownDefaultBehavior({
|
|
118
|
-
target,
|
|
119
|
-
targetIsDisabled,
|
|
120
|
-
clickCount,
|
|
121
|
-
position: pointerState.position[pointerName],
|
|
122
|
-
node,
|
|
123
|
-
offset
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (pointerType === 'mouse' && button === 'secondary') {
|
|
128
|
-
fire('contextmenu');
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return pressObj;
|
|
132
|
-
|
|
133
|
-
function fire(type) {
|
|
134
|
-
return (0, _utils.firePointerEvent)(target, type, {
|
|
135
|
-
pointerState,
|
|
136
|
-
keyboardState,
|
|
137
|
-
button,
|
|
138
|
-
clickCount,
|
|
139
|
-
coords,
|
|
140
|
-
isPrimary,
|
|
141
|
-
pointerId,
|
|
142
|
-
pointerType
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function up({
|
|
148
|
-
pointerState,
|
|
149
|
-
keyboardState
|
|
150
|
-
}, pointerName, {
|
|
151
|
-
keyDef: {
|
|
152
|
-
pointerType,
|
|
153
|
-
button
|
|
154
|
-
},
|
|
155
|
-
target,
|
|
156
|
-
coords,
|
|
157
|
-
node,
|
|
158
|
-
offset
|
|
159
|
-
}, pressed, targetIsDisabled) {
|
|
160
|
-
pointerState.pressed = pointerState.pressed.filter(p => p !== pressed);
|
|
161
|
-
const {
|
|
162
|
-
isMultiTouch,
|
|
163
|
-
isPrimary,
|
|
164
|
-
pointerId,
|
|
165
|
-
clickCount
|
|
166
|
-
} = pressed;
|
|
167
|
-
let {
|
|
168
|
-
unpreventedDefault
|
|
169
|
-
} = pressed;
|
|
170
|
-
pointerState.position[pointerName] = { ...pointerState.position[pointerName],
|
|
171
|
-
target,
|
|
172
|
-
coords
|
|
173
|
-
}; // TODO: pointerleave for touch device
|
|
174
|
-
|
|
175
|
-
if (!targetIsDisabled) {
|
|
176
|
-
if (pointerType !== 'mouse' || !pointerState.pressed.filter(p => p.keyDef.pointerType === pointerType).length) {
|
|
177
|
-
fire('pointerup');
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (pointerType !== 'mouse') {
|
|
181
|
-
fire('pointerout');
|
|
182
|
-
fire('pointerleave');
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (pointerType !== 'mouse' && !isMultiTouch) {
|
|
186
|
-
if (clickCount === 1) {
|
|
187
|
-
fire('mouseover');
|
|
188
|
-
fire('mouseenter');
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
fire('mousemove');
|
|
192
|
-
unpreventedDefault = fire('mousedown') && unpreventedDefault;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (unpreventedDefault && pointerType !== 'mouse' && !isMultiTouch) {
|
|
197
|
-
mousedownDefaultBehavior({
|
|
198
|
-
target,
|
|
199
|
-
targetIsDisabled,
|
|
200
|
-
clickCount,
|
|
201
|
-
position: pointerState.position[pointerName],
|
|
202
|
-
node,
|
|
203
|
-
offset
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
delete pointerState.position[pointerName].selectionRange;
|
|
208
|
-
|
|
209
|
-
if (!targetIsDisabled) {
|
|
210
|
-
if (pointerType === 'mouse' || !isMultiTouch) {
|
|
211
|
-
unpreventedDefault = fire('mouseup') && unpreventedDefault;
|
|
212
|
-
const canClick = pointerType !== 'mouse' || button === 'primary';
|
|
213
|
-
|
|
214
|
-
if (canClick && target === pressed.downTarget) {
|
|
215
|
-
var _target$closest;
|
|
216
|
-
|
|
217
|
-
const unpreventedClick = fire('click');
|
|
218
|
-
|
|
219
|
-
if (clickCount === 2) {
|
|
220
|
-
fire('dblclick');
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const control = (_target$closest = target.closest('label')) == null ? void 0 : _target$closest.control;
|
|
224
|
-
|
|
225
|
-
if (unpreventedClick && control && (0, _utils.isFocusable)(control)) {
|
|
226
|
-
(0, _utils.focus)(control);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
function fire(type) {
|
|
233
|
-
return (0, _utils.firePointerEvent)(target, type, {
|
|
234
|
-
pointerState,
|
|
235
|
-
keyboardState,
|
|
236
|
-
button,
|
|
237
|
-
clickCount,
|
|
238
|
-
coords,
|
|
239
|
-
isPrimary,
|
|
240
|
-
pointerId,
|
|
241
|
-
pointerType
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function mousedownDefaultBehavior({
|
|
247
|
-
position,
|
|
248
|
-
target,
|
|
249
|
-
targetIsDisabled,
|
|
250
|
-
clickCount,
|
|
251
|
-
node,
|
|
252
|
-
offset
|
|
253
|
-
}) {
|
|
254
|
-
var _findClosest;
|
|
255
|
-
|
|
256
|
-
// The closest focusable element is focused when a `mousedown` would have been fired.
|
|
257
|
-
// Even if there was no `mousedown` because the element was disabled.
|
|
258
|
-
// A `mousedown` that preventsDefault cancels this though.
|
|
259
|
-
(0, _utils.focus)((_findClosest = (0, _utils.findClosest)(target, _utils.isFocusable)) != null ? _findClosest : target.ownerDocument.body); // TODO: What happens if a focus event handler interfers?
|
|
260
|
-
// An unprevented mousedown moves the cursor to the closest character.
|
|
261
|
-
// We try to approximate the behavior for a no-layout environment.
|
|
262
|
-
|
|
263
|
-
if (!targetIsDisabled) {
|
|
264
|
-
const hasValue = (0, _utils.isElementType)(target, ['input', 'textarea']); // On non-input elements the text selection per multiple click
|
|
265
|
-
// can extend beyond the target boundaries.
|
|
266
|
-
// The exact mechanism what is considered in the same line is unclear.
|
|
267
|
-
// Looks it might be every inline element.
|
|
268
|
-
// TODO: Check what might be considered part of the same line of text.
|
|
269
|
-
|
|
270
|
-
const text = String(hasValue ? (0, _document.getUIValue)(target) : target.textContent);
|
|
271
|
-
const [start, end] = node ? // As offset is describing a DOMOffset it is non-trivial to determine
|
|
272
|
-
// which elements might be considered in the same line of text.
|
|
273
|
-
// TODO: support expanding initial range on multiple clicks if node is given
|
|
274
|
-
[offset, offset] : getTextRange(text, offset, clickCount); // TODO: implement modifying selection per shift/ctrl+mouse
|
|
275
|
-
|
|
276
|
-
if (hasValue) {
|
|
277
|
-
(0, _document.setUISelection)(target, {
|
|
278
|
-
anchorOffset: start != null ? start : text.length,
|
|
279
|
-
focusOffset: end != null ? end : text.length
|
|
280
|
-
});
|
|
281
|
-
position.selectionRange = {
|
|
282
|
-
node: target,
|
|
283
|
-
start: start != null ? start : 0,
|
|
284
|
-
end: end != null ? end : text.length
|
|
285
|
-
};
|
|
286
|
-
} else {
|
|
287
|
-
const {
|
|
288
|
-
node: startNode,
|
|
289
|
-
offset: startOffset
|
|
290
|
-
} = (0, _resolveSelectionTarget.resolveSelectionTarget)({
|
|
291
|
-
target,
|
|
292
|
-
node,
|
|
293
|
-
offset: start
|
|
294
|
-
});
|
|
295
|
-
const {
|
|
296
|
-
node: endNode,
|
|
297
|
-
offset: endOffset
|
|
298
|
-
} = (0, _resolveSelectionTarget.resolveSelectionTarget)({
|
|
299
|
-
target,
|
|
300
|
-
node,
|
|
301
|
-
offset: end
|
|
302
|
-
});
|
|
303
|
-
const range = new Range();
|
|
304
|
-
range.setStart(startNode, startOffset);
|
|
305
|
-
range.setEnd(endNode, endOffset);
|
|
306
|
-
position.selectionRange = range;
|
|
307
|
-
const selection = target.ownerDocument.getSelection();
|
|
308
|
-
selection.removeAllRanges();
|
|
309
|
-
selection.addRange(range.cloneRange());
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
function getTextRange(text, pos, clickCount) {
|
|
315
|
-
if (clickCount % 3 === 1 || text.length === 0) {
|
|
316
|
-
return [pos, pos];
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
const textPos = pos != null ? pos : text.length;
|
|
320
|
-
|
|
321
|
-
if (clickCount % 3 === 2) {
|
|
322
|
-
return [textPos - text.substr(0, pos).match(/(\w+|\s+|\W)?$/)[0].length, pos === undefined ? pos : pos + text.substr(pos).match(/^(\w+|\s+|\W)?/)[0].length];
|
|
323
|
-
} // triple click
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
return [textPos - text.substr(0, pos).match(/[^\r\n]*$/)[0].length, pos === undefined ? pos : pos + text.substr(pos).match(/^[^\r\n]*/)[0].length];
|
|
327
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.resolveSelectionTarget = resolveSelectionTarget;
|
|
7
|
-
|
|
8
|
-
var _document = require("../document");
|
|
9
|
-
|
|
10
|
-
var _utils = require("../utils");
|
|
11
|
-
|
|
12
|
-
function resolveSelectionTarget({
|
|
13
|
-
target,
|
|
14
|
-
node,
|
|
15
|
-
offset
|
|
16
|
-
}) {
|
|
17
|
-
if ((0, _utils.isElementType)(target, ['input', 'textarea'])) {
|
|
18
|
-
return {
|
|
19
|
-
node: target,
|
|
20
|
-
offset: offset != null ? offset : (0, _document.getUIValue)(target).length
|
|
21
|
-
};
|
|
22
|
-
} else if (node) {
|
|
23
|
-
return {
|
|
24
|
-
node,
|
|
25
|
-
offset: offset != null ? offset : node.nodeType === 3 ? node.nodeValue.length : node.childNodes.length
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return findNodeAtTextOffset(target, offset);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function findNodeAtTextOffset(node, offset, isRoot = true) {
|
|
33
|
-
// When clicking after the content the browser behavior can be complicated:
|
|
34
|
-
// 1. If there is textContent after the last element child,
|
|
35
|
-
// the cursor is moved there.
|
|
36
|
-
// 2. If there is textContent in the last element child,
|
|
37
|
-
// the browser moves the cursor to the last non-empty text node inside this element.
|
|
38
|
-
// 3. Otherwise the cursor is moved to the end of the target.
|
|
39
|
-
let i = offset === undefined ? node.childNodes.length - 1 : 0;
|
|
40
|
-
const step = offset === undefined ? -1 : +1;
|
|
41
|
-
|
|
42
|
-
while (offset === undefined ? i >= (isRoot ? Math.max(node.childNodes.length - 1, 0) : 0) : i <= node.childNodes.length) {
|
|
43
|
-
const c = node.childNodes.item(i);
|
|
44
|
-
const text = String(c.textContent);
|
|
45
|
-
|
|
46
|
-
if (text.length) {
|
|
47
|
-
if (offset !== undefined && text.length < offset) {
|
|
48
|
-
offset -= text.length;
|
|
49
|
-
} else if (c.nodeType === 1) {
|
|
50
|
-
return findNodeAtTextOffset(c, offset, false);
|
|
51
|
-
} else {
|
|
52
|
-
// The pre-commit hooks keeps changing this
|
|
53
|
-
// See https://github.com/kentcdodds/kcd-scripts/issues/218
|
|
54
|
-
|
|
55
|
-
/* istanbul ignore else */
|
|
56
|
-
// eslint-disable-next-line no-lonely-if
|
|
57
|
-
if (c.nodeType === 3) {
|
|
58
|
-
var _offset;
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
node: c,
|
|
62
|
-
offset: (_offset = offset) != null ? _offset : c.nodeValue.length
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
i += step;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
node,
|
|
73
|
-
offset: node.childNodes.length
|
|
74
|
-
};
|
|
75
|
-
}
|
package/dist/pointer/types.d.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { PointerCoords, MouseButton } from '../utils';
|
|
2
|
-
/**
|
|
3
|
-
* @internal Do not create/alter this by yourself as this type might be subject to changes.
|
|
4
|
-
*/
|
|
5
|
-
export declare type pointerState = {
|
|
6
|
-
/**
|
|
7
|
-
All keys that have been pressed and not been lifted up yet.
|
|
8
|
-
*/
|
|
9
|
-
pressed: {
|
|
10
|
-
keyDef: pointerKey;
|
|
11
|
-
pointerId: number;
|
|
12
|
-
isMultiTouch: boolean;
|
|
13
|
-
isPrimary: boolean;
|
|
14
|
-
clickCount: number;
|
|
15
|
-
unpreventedDefault: boolean;
|
|
16
|
-
/** Target the key was pressed on */
|
|
17
|
-
downTarget: Element;
|
|
18
|
-
}[];
|
|
19
|
-
activeClickCount?: [string, number];
|
|
20
|
-
/**
|
|
21
|
-
* Position of each pointer.
|
|
22
|
-
* The mouse is always pointer 1 and keeps its position.
|
|
23
|
-
* Pen and touch devices receive a new pointerId for every interaction.
|
|
24
|
-
*/
|
|
25
|
-
position: Record<string, {
|
|
26
|
-
pointerId: number;
|
|
27
|
-
pointerType: 'mouse' | 'pen' | 'touch';
|
|
28
|
-
} & Partial<PointerTarget> & {
|
|
29
|
-
selectionRange?: Range | SelectionInputRange;
|
|
30
|
-
}>;
|
|
31
|
-
/**
|
|
32
|
-
* Last applied pointer id
|
|
33
|
-
*/
|
|
34
|
-
pointerId: number;
|
|
35
|
-
};
|
|
36
|
-
export interface pointerKey {
|
|
37
|
-
/** Name of the pointer key */
|
|
38
|
-
name: string;
|
|
39
|
-
/** Type of the pointer device */
|
|
40
|
-
pointerType: 'mouse' | 'pen' | 'touch';
|
|
41
|
-
/** Type of button */
|
|
42
|
-
button?: MouseButton;
|
|
43
|
-
}
|
|
44
|
-
export interface PointerTarget {
|
|
45
|
-
target: Element;
|
|
46
|
-
coords?: PointerCoords;
|
|
47
|
-
}
|
|
48
|
-
export interface SelectionTarget {
|
|
49
|
-
node?: Node;
|
|
50
|
-
/**
|
|
51
|
-
* If `node` is set, this is the DOM offset.
|
|
52
|
-
* Otherwise this is the `textContent`/`value` offset on the `target`.
|
|
53
|
-
*/
|
|
54
|
-
offset?: number;
|
|
55
|
-
}
|
|
56
|
-
/** Describes a selection inside `HTMLInputElement`/`HTMLTextareaElement` */
|
|
57
|
-
export interface SelectionInputRange {
|
|
58
|
-
node: HTMLInputElement | HTMLTextAreaElement;
|
|
59
|
-
start: number;
|
|
60
|
-
end: number;
|
|
61
|
-
}
|
package/dist/pointer/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/dist/setup/api.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { click, dblClick, tripleClick, hover, unhover, tab } from '../convenience';
|
|
2
|
-
export { keyboard } from '../keyboard';
|
|
3
|
-
export { copy, cut, paste } from '../clipboard';
|
|
4
|
-
export { pointer } from '../pointer';
|
|
5
|
-
export { clear, deselectOptions, selectOptions, type, upload } from '../utility';
|
package/dist/setup/api.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "clear", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _utility.clear;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "click", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _convenience.click;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(exports, "copy", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () {
|
|
21
|
-
return _clipboard.copy;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(exports, "cut", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function () {
|
|
27
|
-
return _clipboard.cut;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(exports, "dblClick", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
get: function () {
|
|
33
|
-
return _convenience.dblClick;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(exports, "deselectOptions", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
get: function () {
|
|
39
|
-
return _utility.deselectOptions;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(exports, "hover", {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
get: function () {
|
|
45
|
-
return _convenience.hover;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
Object.defineProperty(exports, "keyboard", {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
get: function () {
|
|
51
|
-
return _keyboard.keyboard;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
Object.defineProperty(exports, "paste", {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
get: function () {
|
|
57
|
-
return _clipboard.paste;
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
Object.defineProperty(exports, "pointer", {
|
|
61
|
-
enumerable: true,
|
|
62
|
-
get: function () {
|
|
63
|
-
return _pointer.pointer;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
Object.defineProperty(exports, "selectOptions", {
|
|
67
|
-
enumerable: true,
|
|
68
|
-
get: function () {
|
|
69
|
-
return _utility.selectOptions;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
Object.defineProperty(exports, "tab", {
|
|
73
|
-
enumerable: true,
|
|
74
|
-
get: function () {
|
|
75
|
-
return _convenience.tab;
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
Object.defineProperty(exports, "tripleClick", {
|
|
79
|
-
enumerable: true,
|
|
80
|
-
get: function () {
|
|
81
|
-
return _convenience.tripleClick;
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
Object.defineProperty(exports, "type", {
|
|
85
|
-
enumerable: true,
|
|
86
|
-
get: function () {
|
|
87
|
-
return _utility.type;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
Object.defineProperty(exports, "unhover", {
|
|
91
|
-
enumerable: true,
|
|
92
|
-
get: function () {
|
|
93
|
-
return _convenience.unhover;
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
Object.defineProperty(exports, "upload", {
|
|
97
|
-
enumerable: true,
|
|
98
|
-
get: function () {
|
|
99
|
-
return _utility.upload;
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
var _convenience = require("../convenience");
|
|
104
|
-
|
|
105
|
-
var _keyboard = require("../keyboard");
|
|
106
|
-
|
|
107
|
-
var _clipboard = require("../clipboard");
|
|
108
|
-
|
|
109
|
-
var _pointer = require("../pointer");
|
|
110
|
-
|
|
111
|
-
var _utility = require("../utility");
|
package/dist/setup/config.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { keyboardState } from '../keyboard/types';
|
|
2
|
-
import type { pointerState } from '../pointer/types';
|
|
3
|
-
import type { Options } from '../options';
|
|
4
|
-
export interface inputDeviceState {
|
|
5
|
-
pointerState: pointerState;
|
|
6
|
-
keyboardState: keyboardState;
|
|
7
|
-
}
|
|
8
|
-
export interface Config extends Required<Options>, inputDeviceState {
|
|
9
|
-
}
|
|
10
|
-
export declare const Config: unique symbol;
|
package/dist/setup/config.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { PointerOptions } from '../utils';
|
|
2
|
-
import type { PointerInput } from '../pointer';
|
|
3
|
-
import type { UserEventApi } from '.';
|
|
4
|
-
import { Config } from './config';
|
|
5
|
-
export declare function clear(element: Element): Promise<void>;
|
|
6
|
-
export declare function click(element: Element, options?: Partial<Config>): Promise<void>;
|
|
7
|
-
export declare function copy(options?: Partial<Config>): Promise<DataTransfer | undefined>;
|
|
8
|
-
export declare function cut(options?: Partial<Config>): Promise<DataTransfer | undefined>;
|
|
9
|
-
export declare function dblClick(element: Element, options?: Partial<Config>): Promise<void>;
|
|
10
|
-
export declare function deselectOptions(select: Element, values: HTMLElement | HTMLElement[] | string[] | string, options?: Partial<Config>): Promise<void>;
|
|
11
|
-
export declare function hover(element: Element, options?: Partial<Config>): Promise<void>;
|
|
12
|
-
export declare function keyboard(text: string, options?: Partial<Config>): Promise<import("../keyboard").keyboardState>;
|
|
13
|
-
export declare function pointer(input: PointerInput, options?: Partial<Config>): Promise<import("../pointer").pointerState>;
|
|
14
|
-
export declare function paste(clipboardData?: DataTransfer | string, options?: Partial<Config>): Promise<void>;
|
|
15
|
-
export declare function selectOptions(select: Element, values: HTMLElement | HTMLElement[] | string[] | string, options?: Partial<Config>): Promise<void>;
|
|
16
|
-
export declare function tripleClick(element: Element, options?: Partial<Config>): Promise<void>;
|
|
17
|
-
export declare function type(element: Element, text: string, options?: Partial<Config> & Parameters<UserEventApi['type']>[2]): Promise<void>;
|
|
18
|
-
export declare function unhover(element: Element, options?: PointerOptions): Promise<void>;
|
|
19
|
-
export declare function upload(element: HTMLElement, fileOrFiles: File | File[], options?: Partial<Config>): Promise<void>;
|
|
20
|
-
export declare function tab(options?: Partial<Config> & Parameters<UserEventApi['tab']>[0]): Promise<void>;
|