@testing-library/user-event 14.0.0-beta.2 → 14.0.0-beta.6

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