@testing-library/user-event 14.4.2 → 14.5.0

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 (276) hide show
  1. package/dist/cjs/_interop/dtl.js +30 -0
  2. package/dist/cjs/_interop/dtlEventMap.js +30 -0
  3. package/dist/cjs/_interop/dtlHelpers.js +30 -0
  4. package/dist/cjs/clipboard/copy.js +6 -16
  5. package/dist/cjs/clipboard/cut.js +6 -16
  6. package/dist/cjs/clipboard/paste.js +6 -16
  7. package/dist/cjs/convenience/click.js +1 -4
  8. package/dist/cjs/convenience/hover.js +2 -12
  9. package/dist/cjs/convenience/tab.js +1 -1
  10. package/dist/cjs/document/UI.js +94 -0
  11. package/dist/cjs/document/copySelection.js +37 -0
  12. package/dist/cjs/document/getValueOrTextContent.js +27 -0
  13. package/dist/cjs/document/index.js +13 -68
  14. package/dist/cjs/document/interceptor.js +89 -4
  15. package/dist/cjs/document/prepareDocument.js +67 -0
  16. package/dist/cjs/document/trackValue.js +65 -0
  17. package/dist/cjs/event/behavior/click.js +8 -12
  18. package/dist/cjs/event/behavior/cut.js +5 -11
  19. package/dist/cjs/event/behavior/keydown.js +43 -47
  20. package/dist/cjs/event/behavior/keypress.js +12 -12
  21. package/dist/cjs/event/behavior/keyup.js +6 -8
  22. package/dist/cjs/event/behavior/paste.js +7 -13
  23. package/dist/cjs/event/createEvent.js +43 -50
  24. package/dist/cjs/event/dispatchEvent.js +21 -3
  25. package/dist/cjs/event/eventMap.js +2 -2
  26. package/dist/cjs/event/focus.js +44 -0
  27. package/dist/cjs/event/index.js +24 -17
  28. package/dist/cjs/{utils/edit → event}/input.js +52 -50
  29. package/dist/cjs/{utils/edit/walkRadio.js → event/radio.js} +13 -7
  30. package/dist/cjs/event/selection/getInputRange.js +20 -0
  31. package/dist/cjs/event/selection/getTargetTypeAndSelection.js +41 -0
  32. package/dist/cjs/event/selection/index.js +26 -0
  33. package/dist/cjs/event/selection/modifySelection.js +30 -0
  34. package/dist/cjs/event/selection/modifySelectionPerMouse.js +50 -0
  35. package/dist/cjs/event/selection/moveSelection.js +48 -0
  36. package/dist/cjs/{utils/focus → event/selection}/resolveCaretPosition.js +10 -18
  37. package/dist/cjs/event/selection/selectAll.js +48 -0
  38. package/dist/cjs/event/selection/setSelection.js +30 -0
  39. package/dist/cjs/event/selection/setSelectionPerMouse.js +91 -0
  40. package/dist/cjs/event/selection/setSelectionRange.js +40 -0
  41. package/dist/cjs/event/selection/updateSelectionOnFocus.js +46 -0
  42. package/dist/cjs/event/wrapEvent.js +3 -2
  43. package/dist/cjs/index.js +1 -0
  44. package/dist/cjs/keyboard/index.js +13 -23
  45. package/dist/cjs/keyboard/parseKeyDef.js +9 -17
  46. package/dist/cjs/options.js +0 -28
  47. package/dist/cjs/pointer/index.js +28 -38
  48. package/dist/cjs/pointer/keyMap.js +1 -1
  49. package/dist/cjs/pointer/parseKeyDef.js +2 -10
  50. package/dist/cjs/setup/api.js +19 -17
  51. package/dist/cjs/setup/directApi.js +6 -6
  52. package/dist/cjs/setup/index.js +0 -2
  53. package/dist/cjs/setup/setup.js +70 -42
  54. package/dist/cjs/setup/wrapAsync.js +3 -2
  55. package/dist/cjs/system/index.js +15 -2
  56. package/dist/cjs/system/keyboard.js +34 -21
  57. package/dist/cjs/system/pointer/buttons.js +14 -1
  58. package/dist/cjs/system/pointer/device.js +14 -1
  59. package/dist/cjs/system/pointer/index.js +60 -45
  60. package/dist/cjs/system/pointer/mouse.js +77 -56
  61. package/dist/cjs/system/pointer/pointer.js +56 -42
  62. package/dist/cjs/system/pointer/shared.js +10 -0
  63. package/dist/cjs/utility/clear.js +10 -11
  64. package/dist/cjs/utility/selectOptions.js +28 -29
  65. package/dist/cjs/utility/type.js +6 -15
  66. package/dist/cjs/utility/upload.js +9 -18
  67. package/dist/cjs/utils/dataTransfer/Clipboard.js +26 -24
  68. package/dist/cjs/utils/dataTransfer/DataTransfer.js +25 -9
  69. package/dist/cjs/utils/edit/isEditable.js +6 -10
  70. package/dist/cjs/utils/edit/maxLength.js +6 -17
  71. package/dist/cjs/utils/edit/setFiles.js +4 -4
  72. package/dist/cjs/utils/edit/{buildTimeValue.js → timeValue.js} +6 -0
  73. package/dist/cjs/utils/focus/cursor.js +2 -18
  74. package/dist/cjs/utils/focus/getActiveElement.js +4 -3
  75. package/dist/cjs/utils/focus/selection.js +1 -271
  76. package/dist/cjs/utils/focus/selector.js +1 -1
  77. package/dist/cjs/utils/index.js +7 -32
  78. package/dist/cjs/utils/keyDef/readNextDescriptor.js +5 -5
  79. package/dist/cjs/utils/misc/getTreeDiff.js +3 -3
  80. package/dist/cjs/utils/misc/getWindow.js +3 -2
  81. package/dist/cjs/utils/misc/isDisabled.js +3 -3
  82. package/dist/cjs/utils/misc/isVisible.js +3 -2
  83. package/dist/cjs/utils/misc/level.js +4 -9
  84. package/dist/cjs/utils/misc/wait.js +1 -1
  85. package/dist/cjs/utils/pointer/cssPointerEvents.js +31 -40
  86. package/dist/esm/_interop/dtl.js +6 -0
  87. package/dist/esm/_interop/dtlEventMap.js +6 -0
  88. package/dist/esm/_interop/dtlHelpers.js +6 -0
  89. package/dist/esm/clipboard/copy.js +6 -16
  90. package/dist/esm/clipboard/cut.js +6 -16
  91. package/dist/esm/clipboard/paste.js +6 -16
  92. package/dist/esm/convenience/click.js +1 -4
  93. package/dist/esm/convenience/hover.js +2 -12
  94. package/dist/esm/convenience/tab.js +1 -1
  95. package/dist/esm/document/UI.js +79 -0
  96. package/dist/esm/document/copySelection.js +33 -0
  97. package/dist/esm/document/getValueOrTextContent.js +23 -0
  98. package/dist/esm/document/index.js +4 -66
  99. package/dist/esm/document/interceptor.js +87 -5
  100. package/dist/esm/document/prepareDocument.js +63 -0
  101. package/dist/esm/document/trackValue.js +59 -0
  102. package/dist/esm/event/behavior/click.js +8 -12
  103. package/dist/esm/event/behavior/cut.js +5 -11
  104. package/dist/esm/event/behavior/keydown.js +36 -40
  105. package/dist/esm/event/behavior/keypress.js +12 -12
  106. package/dist/esm/event/behavior/keyup.js +6 -8
  107. package/dist/esm/event/behavior/paste.js +7 -13
  108. package/dist/esm/event/createEvent.js +43 -50
  109. package/dist/esm/event/dispatchEvent.js +20 -4
  110. package/dist/esm/event/eventMap.js +2 -2
  111. package/dist/esm/event/focus.js +39 -0
  112. package/dist/esm/event/index.js +14 -19
  113. package/dist/esm/{utils/edit → event}/input.js +39 -37
  114. package/dist/esm/{utils/edit/walkRadio.js → event/radio.js} +13 -7
  115. package/dist/esm/event/selection/getInputRange.js +16 -0
  116. package/dist/esm/event/selection/getTargetTypeAndSelection.js +37 -0
  117. package/dist/esm/event/selection/index.js +9 -0
  118. package/dist/esm/event/selection/modifySelection.js +26 -0
  119. package/dist/esm/event/selection/modifySelectionPerMouse.js +46 -0
  120. package/dist/esm/event/selection/moveSelection.js +44 -0
  121. package/dist/esm/{utils/focus → event/selection}/resolveCaretPosition.js +9 -17
  122. package/dist/esm/event/selection/selectAll.js +43 -0
  123. package/dist/esm/event/selection/setSelection.js +26 -0
  124. package/dist/esm/event/selection/setSelectionPerMouse.js +87 -0
  125. package/dist/esm/event/selection/setSelectionRange.js +36 -0
  126. package/dist/esm/event/selection/updateSelectionOnFocus.js +42 -0
  127. package/dist/esm/event/wrapEvent.js +2 -1
  128. package/dist/esm/index.js +1 -1
  129. package/dist/esm/keyboard/index.js +13 -23
  130. package/dist/esm/keyboard/parseKeyDef.js +9 -17
  131. package/dist/esm/options.js +1 -26
  132. package/dist/esm/pointer/index.js +28 -38
  133. package/dist/esm/pointer/keyMap.js +1 -1
  134. package/dist/esm/pointer/parseKeyDef.js +2 -10
  135. package/dist/esm/setup/api.js +33 -12
  136. package/dist/esm/setup/directApi.js +6 -6
  137. package/dist/esm/setup/index.js +0 -1
  138. package/dist/esm/setup/setup.js +66 -39
  139. package/dist/esm/setup/wrapAsync.js +2 -1
  140. package/dist/esm/system/index.js +15 -2
  141. package/dist/esm/system/keyboard.js +34 -21
  142. package/dist/esm/system/pointer/buttons.js +14 -1
  143. package/dist/esm/system/pointer/device.js +14 -1
  144. package/dist/esm/system/pointer/index.js +61 -45
  145. package/dist/esm/system/pointer/mouse.js +74 -53
  146. package/dist/esm/system/pointer/pointer.js +55 -41
  147. package/dist/esm/system/pointer/shared.js +6 -0
  148. package/dist/esm/utility/clear.js +10 -11
  149. package/dist/esm/utility/selectOptions.js +24 -25
  150. package/dist/esm/utility/type.js +5 -14
  151. package/dist/esm/utility/upload.js +9 -18
  152. package/dist/esm/utils/dataTransfer/Clipboard.js +26 -24
  153. package/dist/esm/utils/dataTransfer/DataTransfer.js +25 -9
  154. package/dist/esm/utils/edit/isEditable.js +4 -8
  155. package/dist/esm/utils/edit/maxLength.js +5 -17
  156. package/dist/esm/utils/edit/setFiles.js +4 -4
  157. package/dist/esm/utils/edit/{buildTimeValue.js → timeValue.js} +6 -1
  158. package/dist/esm/utils/focus/cursor.js +2 -18
  159. package/dist/esm/utils/focus/getActiveElement.js +4 -3
  160. package/dist/esm/utils/focus/selection.js +3 -265
  161. package/dist/esm/utils/focus/selector.js +1 -1
  162. package/dist/esm/utils/index.js +4 -11
  163. package/dist/esm/utils/keyDef/readNextDescriptor.js +5 -5
  164. package/dist/esm/utils/misc/getTreeDiff.js +3 -3
  165. package/dist/esm/utils/misc/getWindow.js +2 -1
  166. package/dist/esm/utils/misc/isDisabled.js +3 -3
  167. package/dist/esm/utils/misc/isVisible.js +3 -2
  168. package/dist/esm/utils/misc/level.js +4 -9
  169. package/dist/esm/utils/misc/wait.js +1 -1
  170. package/dist/esm/utils/pointer/cssPointerEvents.js +31 -40
  171. package/dist/types/_interop/dtl.d.ts +3 -0
  172. package/dist/types/_interop/dtlEventMap.d.ts +3 -0
  173. package/dist/types/_interop/dtlHelpers.d.ts +3 -0
  174. package/dist/types/clipboard/copy.d.ts +1 -1
  175. package/dist/types/clipboard/cut.d.ts +1 -1
  176. package/dist/types/clipboard/paste.d.ts +1 -1
  177. package/dist/types/convenience/click.d.ts +1 -1
  178. package/dist/types/convenience/hover.d.ts +1 -1
  179. package/dist/types/convenience/tab.d.ts +1 -1
  180. package/dist/types/document/UI.d.ts +42 -0
  181. package/dist/types/document/getValueOrTextContent.d.ts +1 -0
  182. package/dist/types/document/index.d.ts +5 -10
  183. package/dist/types/document/interceptor.d.ts +6 -3
  184. package/dist/types/document/prepareDocument.d.ts +8 -0
  185. package/dist/types/document/trackValue.d.ts +17 -0
  186. package/dist/types/event/behavior/registry.d.ts +2 -2
  187. package/dist/types/event/createEvent.d.ts +1 -1
  188. package/dist/types/event/dispatchEvent.d.ts +5 -2
  189. package/dist/types/event/eventMap.d.ts +8 -0
  190. package/dist/types/event/focus.d.ts +5 -0
  191. package/dist/types/event/index.d.ts +6 -4
  192. package/dist/types/event/input.d.ts +2 -0
  193. package/dist/types/event/radio.d.ts +4 -0
  194. package/dist/types/event/selection/getInputRange.d.ts +5 -0
  195. package/dist/types/event/selection/getTargetTypeAndSelection.d.ts +10 -0
  196. package/dist/types/event/selection/index.d.ts +15 -0
  197. package/dist/types/event/selection/modifySelection.d.ts +8 -0
  198. package/dist/types/event/selection/modifySelectionPerMouse.d.ts +7 -0
  199. package/dist/types/event/selection/moveSelection.d.ts +4 -0
  200. package/dist/types/event/selection/setSelection.d.ts +10 -0
  201. package/dist/types/event/selection/setSelectionPerMouse.d.ts +8 -0
  202. package/dist/types/event/selection/setSelectionRange.d.ts +6 -0
  203. package/dist/types/event/selection/updateSelectionOnFocus.d.ts +5 -0
  204. package/dist/types/event/types.d.ts +3 -3
  205. package/dist/types/index.d.ts +3 -1
  206. package/dist/types/keyboard/index.d.ts +2 -2
  207. package/dist/types/options.d.ts +2 -10
  208. package/dist/types/pointer/index.d.ts +7 -7
  209. package/dist/types/setup/api.d.ts +23 -5
  210. package/dist/types/setup/directApi.d.ts +5 -5
  211. package/dist/types/setup/index.d.ts +2 -15
  212. package/dist/types/setup/setup.d.ts +25 -7
  213. package/dist/types/system/keyboard.d.ts +4 -4
  214. package/dist/types/system/pointer/buttons.d.ts +2 -2
  215. package/dist/types/system/pointer/device.d.ts +1 -1
  216. package/dist/types/system/pointer/index.d.ts +7 -25
  217. package/dist/types/system/pointer/mouse.d.ts +6 -6
  218. package/dist/types/system/pointer/pointer.d.ts +8 -8
  219. package/dist/types/system/pointer/shared.d.ts +20 -0
  220. package/dist/types/utility/clear.d.ts +1 -1
  221. package/dist/types/utility/selectOptions.d.ts +1 -1
  222. package/dist/types/utility/type.d.ts +4 -4
  223. package/dist/types/utility/upload.d.ts +1 -1
  224. package/dist/types/utils/click/isClickableInput.d.ts +2 -2
  225. package/dist/types/utils/dataTransfer/Clipboard.d.ts +1 -1
  226. package/dist/types/utils/edit/isEditable.d.ts +6 -7
  227. package/dist/types/utils/edit/maxLength.d.ts +14 -1
  228. package/dist/types/utils/edit/{isValidDateOrTimeValue.d.ts → timeValue.d.ts} +1 -0
  229. package/dist/types/utils/focus/selection.d.ts +4 -69
  230. package/dist/types/utils/index.d.ts +2 -9
  231. package/dist/types/utils/keyDef/readNextDescriptor.d.ts +1 -1
  232. package/dist/types/utils/misc/isElementType.d.ts +1 -1
  233. package/dist/types/utils/misc/level.d.ts +4 -13
  234. package/dist/types/utils/misc/wait.d.ts +2 -2
  235. package/dist/types/utils/pointer/cssPointerEvents.d.ts +4 -4
  236. package/package.json +24 -12
  237. package/dist/cjs/document/selection.js +0 -108
  238. package/dist/cjs/document/setRangeText.js +0 -21
  239. package/dist/cjs/document/value.js +0 -127
  240. package/dist/cjs/setup/config.js +0 -7
  241. package/dist/cjs/utils/edit/getValue.js +0 -35
  242. package/dist/cjs/utils/edit/isValidDateOrTimeValue.js +0 -11
  243. package/dist/cjs/utils/focus/blur.js +0 -16
  244. package/dist/cjs/utils/focus/copySelection.js +0 -46
  245. package/dist/cjs/utils/focus/focus.js +0 -29
  246. package/dist/cjs/utils/focus/selectAll.js +0 -56
  247. package/dist/cjs/utils/misc/eventWrapper.js +0 -15
  248. package/dist/esm/document/selection.js +0 -100
  249. package/dist/esm/document/setRangeText.js +0 -17
  250. package/dist/esm/document/value.js +0 -117
  251. package/dist/esm/setup/config.js +0 -3
  252. package/dist/esm/utils/edit/getValue.js +0 -31
  253. package/dist/esm/utils/edit/isValidDateOrTimeValue.js +0 -7
  254. package/dist/esm/utils/focus/blur.js +0 -12
  255. package/dist/esm/utils/focus/copySelection.js +0 -42
  256. package/dist/esm/utils/focus/focus.js +0 -25
  257. package/dist/esm/utils/focus/selectAll.js +0 -51
  258. package/dist/esm/utils/misc/eventWrapper.js +0 -11
  259. package/dist/types/document/selection.d.ts +0 -29
  260. package/dist/types/document/setRangeText.d.ts +0 -1
  261. package/dist/types/document/value.d.ts +0 -26
  262. package/dist/types/setup/config.d.ts +0 -6
  263. package/dist/types/utils/edit/buildTimeValue.d.ts +0 -1
  264. package/dist/types/utils/edit/getValue.d.ts +0 -1
  265. package/dist/types/utils/edit/input.d.ts +0 -2
  266. package/dist/types/utils/edit/walkRadio.d.ts +0 -4
  267. package/dist/types/utils/focus/blur.d.ts +0 -2
  268. package/dist/types/utils/focus/focus.d.ts +0 -5
  269. package/dist/types/utils/misc/eventWrapper.d.ts +0 -1
  270. /package/dist/cjs/{event → _interop}/dom-events.d.js +0 -0
  271. /package/dist/cjs/{utils/misc → _interop}/dom-helpers.d.js +0 -0
  272. /package/dist/esm/{event → _interop}/dom-events.d.js +0 -0
  273. /package/dist/esm/{utils/misc → _interop}/dom-helpers.d.js +0 -0
  274. /package/dist/types/{utils/focus → document}/copySelection.d.ts +0 -0
  275. /package/dist/types/{utils/focus → event/selection}/resolveCaretPosition.d.ts +0 -0
  276. /package/dist/types/{utils/focus → event/selection}/selectAll.d.ts +0 -0
@@ -0,0 +1,6 @@
1
+ import * as def from '@testing-library/dom/dist/event-map.js';
2
+ import def__default from '@testing-library/dom/dist/event-map.js';
3
+
4
+ var dtlEvents = def__default !== null && def__default !== void 0 ? def__default : def;
5
+
6
+ export { dtlEvents as default };
@@ -0,0 +1,6 @@
1
+ import * as def from '@testing-library/dom/dist/helpers.js';
2
+ import def__default from '@testing-library/dom/dist/helpers.js';
3
+
4
+ var dtlHelpers = def__default !== null && def__default !== void 0 ? def__default : def;
5
+
6
+ export { dtlHelpers as default };
@@ -1,34 +1,24 @@
1
- import '../setup/index.js';
2
1
  import '../utils/click/isClickableInput.js';
3
2
  import { writeDataTransferToClipboard } from '../utils/dataTransfer/Clipboard.js';
4
- import '../event/eventMap.js';
5
- import '../event/behavior/click.js';
6
- import '../event/behavior/cut.js';
7
- import '../event/behavior/keydown.js';
8
- import '../event/behavior/keypress.js';
9
- import '../event/behavior/keyup.js';
10
- import '../event/behavior/paste.js';
11
- import '@testing-library/dom';
12
- import '../utils/edit/maxLength.js';
13
3
  import '../utils/edit/isEditable.js';
4
+ import '../utils/edit/maxLength.js';
14
5
  import '@testing-library/dom/dist/helpers.js';
15
- import { copySelection } from '../utils/focus/copySelection.js';
16
6
  import '../utils/keyDef/readNextDescriptor.js';
17
7
  import '../utils/misc/level.js';
18
8
  import '../options.js';
19
- import { Config } from '../setup/config.js';
9
+ import { copySelection } from '../document/copySelection.js';
20
10
 
21
11
  async function copy() {
22
- const doc = this[Config].document;
23
- var _activeElement;
24
- const target = (_activeElement = doc.activeElement) !== null && _activeElement !== void 0 ? _activeElement : /* istanbul ignore next */ doc.body;
12
+ const doc = this.config.document;
13
+ var _doc_activeElement;
14
+ const target = (_doc_activeElement = doc.activeElement) !== null && _doc_activeElement !== void 0 ? _doc_activeElement : /* istanbul ignore next */ doc.body;
25
15
  const clipboardData = copySelection(target);
26
16
  if (clipboardData.items.length === 0) {
27
17
  return;
28
18
  }
29
19
  if (this.dispatchUIEvent(target, 'copy', {
30
20
  clipboardData
31
- }) && this[Config].writeToClipboard) {
21
+ }) && this.config.writeToClipboard) {
32
22
  await writeDataTransferToClipboard(doc, clipboardData);
33
23
  }
34
24
  return clipboardData;
@@ -1,34 +1,24 @@
1
- import '../setup/index.js';
2
1
  import '../utils/click/isClickableInput.js';
3
2
  import { writeDataTransferToClipboard } from '../utils/dataTransfer/Clipboard.js';
4
- import '../event/eventMap.js';
5
- import '../event/behavior/click.js';
6
- import '../event/behavior/cut.js';
7
- import '../event/behavior/keydown.js';
8
- import '../event/behavior/keypress.js';
9
- import '../event/behavior/keyup.js';
10
- import '../event/behavior/paste.js';
11
- import '@testing-library/dom';
12
- import '../utils/edit/maxLength.js';
13
3
  import '../utils/edit/isEditable.js';
4
+ import '../utils/edit/maxLength.js';
14
5
  import '@testing-library/dom/dist/helpers.js';
15
- import { copySelection } from '../utils/focus/copySelection.js';
16
6
  import '../utils/keyDef/readNextDescriptor.js';
17
7
  import '../utils/misc/level.js';
18
8
  import '../options.js';
19
- import { Config } from '../setup/config.js';
9
+ import { copySelection } from '../document/copySelection.js';
20
10
 
21
11
  async function cut() {
22
- const doc = this[Config].document;
23
- var _activeElement;
24
- const target = (_activeElement = doc.activeElement) !== null && _activeElement !== void 0 ? _activeElement : /* istanbul ignore next */ doc.body;
12
+ const doc = this.config.document;
13
+ var _doc_activeElement;
14
+ const target = (_doc_activeElement = doc.activeElement) !== null && _doc_activeElement !== void 0 ? _doc_activeElement : /* istanbul ignore next */ doc.body;
25
15
  const clipboardData = copySelection(target);
26
16
  if (clipboardData.items.length === 0) {
27
17
  return;
28
18
  }
29
19
  if (this.dispatchUIEvent(target, 'cut', {
30
20
  clipboardData
31
- }) && this[Config].writeToClipboard) {
21
+ }) && this.config.writeToClipboard) {
32
22
  await writeDataTransferToClipboard(target.ownerDocument, clipboardData);
33
23
  }
34
24
  return clipboardData;
@@ -1,29 +1,19 @@
1
- import '../setup/index.js';
2
1
  import '../utils/click/isClickableInput.js';
3
2
  import { createDataTransfer } from '../utils/dataTransfer/DataTransfer.js';
4
3
  import { readDataTransferFromClipboard } from '../utils/dataTransfer/Clipboard.js';
5
- import '../event/eventMap.js';
6
- import '../event/behavior/click.js';
7
- import '../event/behavior/cut.js';
8
- import '../event/behavior/keydown.js';
9
- import '../event/behavior/keypress.js';
10
- import '../event/behavior/keyup.js';
11
- import '../event/behavior/paste.js';
12
- import '@testing-library/dom';
13
- import '../utils/edit/maxLength.js';
14
4
  import '../utils/edit/isEditable.js';
5
+ import '../utils/edit/maxLength.js';
15
6
  import { getWindow } from '../utils/misc/getWindow.js';
16
7
  import '../utils/keyDef/readNextDescriptor.js';
17
8
  import '../utils/misc/level.js';
18
9
  import '../options.js';
19
- import { Config } from '../setup/config.js';
20
10
 
21
11
  async function paste(clipboardData) {
22
- const doc = this[Config].document;
23
- var _activeElement;
24
- const target = (_activeElement = doc.activeElement) !== null && _activeElement !== void 0 ? _activeElement : /* istanbul ignore next */ doc.body;
25
- var ref;
26
- const dataTransfer = (ref = typeof clipboardData === 'string' ? getClipboardDataFromString(doc, clipboardData) : clipboardData) !== null && ref !== void 0 ? ref : await readDataTransferFromClipboard(doc).catch(()=>{
12
+ const doc = this.config.document;
13
+ var _doc_activeElement;
14
+ const target = (_doc_activeElement = doc.activeElement) !== null && _doc_activeElement !== void 0 ? _doc_activeElement : /* istanbul ignore next */ doc.body;
15
+ var _ref;
16
+ const dataTransfer = (_ref = typeof clipboardData === 'string' ? getClipboardDataFromString(doc, clipboardData) : clipboardData) !== null && _ref !== void 0 ? _ref : await readDataTransferFromClipboard(doc).catch(()=>{
27
17
  throw new Error('`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.');
28
18
  });
29
19
  this.dispatchUIEvent(target, 'paste', {
@@ -1,9 +1,6 @@
1
- import '../setup/index.js';
2
- import { Config } from '../setup/config.js';
3
-
4
1
  async function click(element) {
5
2
  const pointerIn = [];
6
- if (!this[Config].skipHover) {
3
+ if (!this.config.skipHover) {
7
4
  pointerIn.push({
8
5
  target: element
9
6
  });
@@ -1,21 +1,11 @@
1
- import '../setup/index.js';
2
1
  import '../utils/click/isClickableInput.js';
3
2
  import '../utils/dataTransfer/Clipboard.js';
4
- import '../event/eventMap.js';
5
- import '../event/behavior/click.js';
6
- import '../event/behavior/cut.js';
7
- import '../event/behavior/keydown.js';
8
- import '../event/behavior/keypress.js';
9
- import '../event/behavior/keyup.js';
10
- import '../event/behavior/paste.js';
11
- import '@testing-library/dom';
12
- import '../utils/edit/maxLength.js';
13
3
  import '../utils/edit/isEditable.js';
4
+ import '../utils/edit/maxLength.js';
14
5
  import '@testing-library/dom/dist/helpers.js';
15
6
  import '../utils/keyDef/readNextDescriptor.js';
16
7
  import '../utils/misc/level.js';
17
8
  import { assertPointerEvents } from '../utils/pointer/cssPointerEvents.js';
18
- import { Config } from '../setup/config.js';
19
9
 
20
10
  async function hover(element) {
21
11
  return this.pointer({
@@ -23,7 +13,7 @@ async function hover(element) {
23
13
  });
24
14
  }
25
15
  async function unhover(element) {
26
- assertPointerEvents(this[Config], this[Config].system.pointer.getMouseTarget(this[Config]));
16
+ assertPointerEvents(this, this.system.pointer.getMouseTarget(this));
27
17
  return this.pointer({
28
18
  target: element.ownerDocument.body
29
19
  });
@@ -1,4 +1,4 @@
1
- async function tab({ shift } = {}) {
1
+ async function tab({ shift } = {}) {
2
2
  return this.keyboard(shift === true ? '{Shift>}{Tab}{/Shift}' : shift === false ? '[/ShiftLeft][/ShiftRight]{Tab}' : '{Tab}');
3
3
  }
4
4
 
@@ -0,0 +1,79 @@
1
+ const UIValue = Symbol('Displayed value in UI');
2
+ const UISelection = Symbol('Displayed selection in UI');
3
+ const InitialValue = Symbol('Initial value to compare on blur');
4
+ function isUIValue(value) {
5
+ return typeof value === 'object' && UIValue in value;
6
+ }
7
+ function isUISelectionStart(start) {
8
+ return !!start && typeof start === 'object' && UISelection in start;
9
+ }
10
+ function setUIValue(element, value) {
11
+ if (element[InitialValue] === undefined) {
12
+ element[InitialValue] = element.value;
13
+ }
14
+ element[UIValue] = value;
15
+ // eslint-disable-next-line no-new-wrappers
16
+ element.value = Object.assign(new String(value), {
17
+ [UIValue]: true
18
+ });
19
+ }
20
+ function getUIValue(element) {
21
+ return element[UIValue] === undefined ? element.value : String(element[UIValue]);
22
+ }
23
+ /** Flag the IDL value as clean. This does not change the value.*/ function setUIValueClean(element) {
24
+ element[UIValue] = undefined;
25
+ }
26
+ function clearInitialValue(element) {
27
+ element[InitialValue] = undefined;
28
+ }
29
+ function getInitialValue(element) {
30
+ return element[InitialValue];
31
+ }
32
+ function setUISelectionRaw(element, selection) {
33
+ element[UISelection] = selection;
34
+ }
35
+ function setUISelection(element, { focusOffset: focusOffsetParam, anchorOffset: anchorOffsetParam = focusOffsetParam }, mode = 'replace') {
36
+ const valueLength = getUIValue(element).length;
37
+ const sanitizeOffset = (o)=>Math.max(0, Math.min(valueLength, o));
38
+ const anchorOffset = mode === 'replace' || element[UISelection] === undefined ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
39
+ const focusOffset = sanitizeOffset(focusOffsetParam);
40
+ const startOffset = Math.min(anchorOffset, focusOffset);
41
+ const endOffset = Math.max(anchorOffset, focusOffset);
42
+ element[UISelection] = {
43
+ anchorOffset,
44
+ focusOffset
45
+ };
46
+ if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
47
+ return;
48
+ }
49
+ // eslint-disable-next-line no-new-wrappers
50
+ const startObj = Object.assign(new Number(startOffset), {
51
+ [UISelection]: true
52
+ });
53
+ try {
54
+ element.setSelectionRange(startObj, endOffset);
55
+ } catch {
56
+ // DOMException for invalid state is expected when calling this
57
+ // on an element without support for setSelectionRange
58
+ }
59
+ }
60
+ function getUISelection(element) {
61
+ var _element_selectionStart, _element_selectionEnd, _element_UISelection;
62
+ const sel = (_element_UISelection = element[UISelection]) !== null && _element_UISelection !== void 0 ? _element_UISelection : {
63
+ anchorOffset: (_element_selectionStart = element.selectionStart) !== null && _element_selectionStart !== void 0 ? _element_selectionStart : 0,
64
+ focusOffset: (_element_selectionEnd = element.selectionEnd) !== null && _element_selectionEnd !== void 0 ? _element_selectionEnd : 0
65
+ };
66
+ return {
67
+ ...sel,
68
+ startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
69
+ endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
70
+ };
71
+ }
72
+ function hasUISelection(element) {
73
+ return !!element[UISelection];
74
+ }
75
+ /** Flag the IDL selection as clean. This does not change the selection. */ function setUISelectionClean(element) {
76
+ element[UISelection] = undefined;
77
+ }
78
+
79
+ export { clearInitialValue, getInitialValue, getUISelection, getUIValue, hasUISelection, isUISelectionStart, isUIValue, setUISelection, setUISelectionClean, setUISelectionRaw, setUIValue, setUIValueClean };
@@ -0,0 +1,33 @@
1
+ import '../utils/click/isClickableInput.js';
2
+ import { createDataTransfer } from '../utils/dataTransfer/DataTransfer.js';
3
+ import '../utils/dataTransfer/Clipboard.js';
4
+ import '../utils/edit/isEditable.js';
5
+ import '../utils/edit/maxLength.js';
6
+ import { getWindow } from '../utils/misc/getWindow.js';
7
+ import { hasOwnSelection } from '../utils/focus/selection.js';
8
+ import '../utils/keyDef/readNextDescriptor.js';
9
+ import '../utils/misc/level.js';
10
+ import '../options.js';
11
+ import { getUISelection, getUIValue } from './UI.js';
12
+
13
+ function copySelection(target) {
14
+ const data = hasOwnSelection(target) ? {
15
+ 'text/plain': readSelectedValueFromInput(target)
16
+ } : {
17
+ 'text/plain': String(target.ownerDocument.getSelection())
18
+ };
19
+ const dt = createDataTransfer(getWindow(target));
20
+ for(const type in data){
21
+ if (data[type]) {
22
+ dt.setData(type, data[type]);
23
+ }
24
+ }
25
+ return dt;
26
+ }
27
+ function readSelectedValueFromInput(target) {
28
+ const sel = getUISelection(target);
29
+ const val = getUIValue(target);
30
+ return val.substring(sel.startOffset, sel.endOffset);
31
+ }
32
+
33
+ export { copySelection };
@@ -0,0 +1,23 @@
1
+ import '../utils/click/isClickableInput.js';
2
+ import '../utils/dataTransfer/Clipboard.js';
3
+ import { isContentEditable } from '../utils/edit/isContentEditable.js';
4
+ import '../utils/edit/isEditable.js';
5
+ import '../utils/edit/maxLength.js';
6
+ import '@testing-library/dom/dist/helpers.js';
7
+ import '../utils/keyDef/readNextDescriptor.js';
8
+ import '../utils/misc/level.js';
9
+ import '../options.js';
10
+ import { getUIValue } from './UI.js';
11
+
12
+ function getValueOrTextContent(element) {
13
+ // istanbul ignore if
14
+ if (!element) {
15
+ return null;
16
+ }
17
+ if (isContentEditable(element)) {
18
+ return element.textContent;
19
+ }
20
+ return getUIValue(element);
21
+ }
22
+
23
+ export { getValueOrTextContent };
@@ -1,66 +1,4 @@
1
- import { dispatchUIEvent } from '../event/index.js';
2
- import '../utils/click/isClickableInput.js';
3
- import '../utils/dataTransfer/Clipboard.js';
4
- import '../utils/edit/maxLength.js';
5
- import '../utils/edit/isEditable.js';
6
- import '@testing-library/dom';
7
- import { isElementType } from '../utils/misc/isElementType.js';
8
- import '@testing-library/dom/dist/helpers.js';
9
- import '../utils/keyDef/readNextDescriptor.js';
10
- import '../utils/misc/level.js';
11
- import '../options.js';
12
- import { prepareSelectionInterceptor } from './selection.js';
13
- export { getUISelection, setUISelection } from './selection.js';
14
- import { prepareRangeTextInterceptor } from './setRangeText.js';
15
- import { getInitialValue, clearInitialValue, prepareValueInterceptor } from './value.js';
16
- export { clearInitialValue, commitValueAfterInput, getUIValue, setUIValue } from './value.js';
17
-
18
- const isPrepared = Symbol('Node prepared with document state workarounds');
19
- function prepareDocument(document) {
20
- if (document[isPrepared]) {
21
- return;
22
- }
23
- document.addEventListener('focus', (e)=>{
24
- const el = e.target;
25
- prepareElement(el);
26
- }, {
27
- capture: true,
28
- passive: true
29
- });
30
- // Our test environment defaults to `document.body` as `activeElement`.
31
- // In other environments this might be `null` when preparing.
32
- // istanbul ignore else
33
- if (document.activeElement) {
34
- prepareElement(document.activeElement);
35
- }
36
- document.addEventListener('blur', (e)=>{
37
- const el = e.target;
38
- const initialValue = getInitialValue(el);
39
- if (initialValue !== undefined) {
40
- if (el.value !== initialValue) {
41
- dispatchUIEvent({}, el, 'change');
42
- }
43
- clearInitialValue(el);
44
- }
45
- }, {
46
- capture: true,
47
- passive: true
48
- });
49
- document[isPrepared] = isPrepared;
50
- }
51
- function prepareElement(el) {
52
- if (el[isPrepared]) {
53
- return;
54
- }
55
- if (isElementType(el, [
56
- 'input',
57
- 'textarea'
58
- ])) {
59
- prepareValueInterceptor(el);
60
- prepareSelectionInterceptor(el);
61
- prepareRangeTextInterceptor(el);
62
- }
63
- el[isPrepared] = isPrepared;
64
- }
65
-
66
- export { prepareDocument };
1
+ export { clearInitialValue, getUISelection, getUIValue, setUISelection, setUIValue } from './UI.js';
2
+ export { getValueOrTextContent } from './getValueOrTextContent.js';
3
+ export { copySelection } from './copySelection.js';
4
+ export { commitValueAfterInput } from './trackValue.js';
@@ -1,20 +1,34 @@
1
+ import '../utils/click/isClickableInput.js';
2
+ import '../utils/dataTransfer/Clipboard.js';
3
+ import '../utils/edit/isEditable.js';
4
+ import '../utils/edit/maxLength.js';
5
+ import { isElementType } from '../utils/misc/isElementType.js';
6
+ import '@testing-library/dom/dist/helpers.js';
7
+ import '../utils/keyDef/readNextDescriptor.js';
8
+ import '../utils/misc/level.js';
9
+ import '../options.js';
10
+ import { startTrackValue, trackOrSetValue } from './trackValue.js';
11
+ import { setUISelectionClean, setUISelectionRaw, getUIValue, setUIValueClean, isUIValue, isUISelectionStart } from './UI.js';
12
+
1
13
  const Interceptor = Symbol('Interceptor for programmatical calls');
2
14
  function prepareInterceptor(element, propName, interceptorImpl) {
15
+ var _prototypeDescriptor, _prototypeDescriptor1;
3
16
  const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
4
17
  const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
5
- const target = (prototypeDescriptor === null || prototypeDescriptor === void 0 ? void 0 : prototypeDescriptor.set) ? 'set' : 'value';
6
- /* istanbul ignore if */ if (typeof (prototypeDescriptor === null || prototypeDescriptor === void 0 ? void 0 : prototypeDescriptor[target]) !== 'function' || prototypeDescriptor[target][Interceptor]) {
18
+ const target = ((_prototypeDescriptor = prototypeDescriptor) === null || _prototypeDescriptor === void 0 ? void 0 : _prototypeDescriptor.set) ? 'set' : 'value';
19
+ /* istanbul ignore if */ if (typeof ((_prototypeDescriptor1 = prototypeDescriptor) === null || _prototypeDescriptor1 === void 0 ? void 0 : _prototypeDescriptor1[target]) !== 'function' || prototypeDescriptor[target][Interceptor]) {
7
20
  throw new Error(`Element ${element.tagName} does not implement "${String(propName)}".`);
8
21
  }
9
22
  function intercept(...args) {
10
- const { applyNative =false , realArgs , then , } = interceptorImpl.call(this, ...args);
23
+ var _then;
24
+ const { applyNative = false, realArgs, then } = interceptorImpl.call(this, ...args);
11
25
  const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
12
26
  if (target === 'set') {
13
27
  realFunc.call(this, realArgs);
14
28
  } else {
15
29
  realFunc.call(this, ...realArgs);
16
30
  }
17
- then === null || then === void 0 ? void 0 : then();
31
+ (_then = then) === null || _then === void 0 ? void 0 : _then();
18
32
  }
19
33
  intercept[Interceptor] = Interceptor;
20
34
  Object.defineProperty(element, propName, {
@@ -22,5 +36,73 @@ function prepareInterceptor(element, propName, interceptorImpl) {
22
36
  [target]: intercept
23
37
  });
24
38
  }
39
+ function prepareValueInterceptor(element) {
40
+ prepareInterceptor(element, 'value', function interceptorImpl(v) {
41
+ const isUI = isUIValue(v);
42
+ if (isUI) {
43
+ startTrackValue(this);
44
+ }
45
+ return {
46
+ applyNative: !!isUI,
47
+ realArgs: sanitizeValue(this, v),
48
+ then: isUI ? undefined : ()=>trackOrSetValue(this, String(v))
49
+ };
50
+ });
51
+ }
52
+ function sanitizeValue(element, v) {
53
+ // Workaround for JSDOM
54
+ if (isElementType(element, 'input', {
55
+ type: 'number'
56
+ }) && String(v) !== '' && !Number.isNaN(Number(v))) {
57
+ // Setting value to "1." results in `null` in JSDOM
58
+ return String(Number(v));
59
+ }
60
+ return String(v);
61
+ }
62
+ function prepareSelectionInterceptor(element) {
63
+ prepareInterceptor(element, 'setSelectionRange', function interceptorImpl(start, ...others) {
64
+ const isUI = isUISelectionStart(start);
65
+ return {
66
+ applyNative: !!isUI,
67
+ realArgs: [
68
+ Number(start),
69
+ ...others
70
+ ],
71
+ then: ()=>isUI ? undefined : setUISelectionClean(element)
72
+ };
73
+ });
74
+ prepareInterceptor(element, 'selectionStart', function interceptorImpl(v) {
75
+ return {
76
+ realArgs: v,
77
+ then: ()=>setUISelectionClean(element)
78
+ };
79
+ });
80
+ prepareInterceptor(element, 'selectionEnd', function interceptorImpl(v) {
81
+ return {
82
+ realArgs: v,
83
+ then: ()=>setUISelectionClean(element)
84
+ };
85
+ });
86
+ prepareInterceptor(element, 'select', function interceptorImpl() {
87
+ return {
88
+ realArgs: [],
89
+ then: ()=>setUISelectionRaw(element, {
90
+ anchorOffset: 0,
91
+ focusOffset: getUIValue(element).length
92
+ })
93
+ };
94
+ });
95
+ }
96
+ function prepareRangeTextInterceptor(element) {
97
+ prepareInterceptor(element, 'setRangeText', function interceptorImpl(...realArgs) {
98
+ return {
99
+ realArgs,
100
+ then: ()=>{
101
+ setUIValueClean(element);
102
+ setUISelectionClean(element);
103
+ }
104
+ };
105
+ });
106
+ }
25
107
 
26
- export { prepareInterceptor };
108
+ export { prepareInterceptor, prepareRangeTextInterceptor, prepareSelectionInterceptor, prepareValueInterceptor };
@@ -0,0 +1,63 @@
1
+ import { dispatchDOMEvent } from '../event/dispatchEvent.js';
2
+ import '../utils/click/isClickableInput.js';
3
+ import '../utils/dataTransfer/Clipboard.js';
4
+ import '../utils/edit/isEditable.js';
5
+ import '../utils/edit/maxLength.js';
6
+ import { isElementType } from '../utils/misc/isElementType.js';
7
+ import '@testing-library/dom/dist/helpers.js';
8
+ import '../utils/keyDef/readNextDescriptor.js';
9
+ import '../utils/misc/level.js';
10
+ import '../options.js';
11
+ import { getInitialValue, clearInitialValue } from './UI.js';
12
+ import '@testing-library/dom';
13
+ import { prepareValueInterceptor, prepareSelectionInterceptor, prepareRangeTextInterceptor } from './interceptor.js';
14
+
15
+ const isPrepared = Symbol('Node prepared with document state workarounds');
16
+ function prepareDocument(document) {
17
+ if (document[isPrepared]) {
18
+ return;
19
+ }
20
+ document.addEventListener('focus', (e)=>{
21
+ const el = e.target;
22
+ prepareElement(el);
23
+ }, {
24
+ capture: true,
25
+ passive: true
26
+ });
27
+ // Our test environment defaults to `document.body` as `activeElement`.
28
+ // In other environments this might be `null` when preparing.
29
+ // istanbul ignore else
30
+ if (document.activeElement) {
31
+ prepareElement(document.activeElement);
32
+ }
33
+ document.addEventListener('blur', (e)=>{
34
+ const el = e.target;
35
+ const initialValue = getInitialValue(el);
36
+ if (initialValue !== undefined) {
37
+ if (el.value !== initialValue) {
38
+ dispatchDOMEvent(el, 'change');
39
+ }
40
+ clearInitialValue(el);
41
+ }
42
+ }, {
43
+ capture: true,
44
+ passive: true
45
+ });
46
+ document[isPrepared] = isPrepared;
47
+ }
48
+ function prepareElement(el) {
49
+ if (el[isPrepared]) {
50
+ return;
51
+ }
52
+ if (isElementType(el, [
53
+ 'input',
54
+ 'textarea'
55
+ ])) {
56
+ prepareValueInterceptor(el);
57
+ prepareSelectionInterceptor(el);
58
+ prepareRangeTextInterceptor(el);
59
+ }
60
+ el[isPrepared] = isPrepared;
61
+ }
62
+
63
+ export { prepareDocument };
@@ -0,0 +1,59 @@
1
+ import '../utils/click/isClickableInput.js';
2
+ import '../utils/dataTransfer/Clipboard.js';
3
+ import '../utils/edit/isEditable.js';
4
+ import '../utils/edit/maxLength.js';
5
+ import { getWindow } from '../utils/misc/getWindow.js';
6
+ import '../utils/keyDef/readNextDescriptor.js';
7
+ import '../utils/misc/level.js';
8
+ import '../options.js';
9
+ import { setUIValueClean, setUISelection, hasUISelection } from './UI.js';
10
+
11
+ const TrackChanges = Symbol('Track programmatic changes for React workaround');
12
+ // When the input event happens in the browser, React executes all event handlers
13
+ // and if they change state of a controlled value, nothing happens.
14
+ // But when we trigger the event handlers in test environment with React@17,
15
+ // the changes are rolled back before the state update is applied.
16
+ // This results in a reset cursor.
17
+ // There might be a better way to work around if we figure out
18
+ // why the batched update is executed differently in our test environment.
19
+ function isReact17Element(element) {
20
+ return Object.getOwnPropertyNames(element).some((k)=>k.startsWith('__react')) && getWindow(element).REACT_VERSION === 17;
21
+ }
22
+ function startTrackValue(element) {
23
+ if (!isReact17Element(element)) {
24
+ return;
25
+ }
26
+ element[TrackChanges] = {
27
+ previousValue: String(element.value),
28
+ tracked: []
29
+ };
30
+ }
31
+ function trackOrSetValue(element, v) {
32
+ var _element_TrackChanges_tracked, _element_TrackChanges;
33
+ (_element_TrackChanges = element[TrackChanges]) === null || _element_TrackChanges === void 0 ? void 0 : (_element_TrackChanges_tracked = _element_TrackChanges.tracked) === null || _element_TrackChanges_tracked === void 0 ? void 0 : _element_TrackChanges_tracked.push(v);
34
+ if (!element[TrackChanges]) {
35
+ setUIValueClean(element);
36
+ setUISelection(element, {
37
+ focusOffset: v.length
38
+ });
39
+ }
40
+ }
41
+ function commitValueAfterInput(element, cursorOffset) {
42
+ var _changes_tracked, _changes;
43
+ const changes = element[TrackChanges];
44
+ element[TrackChanges] = undefined;
45
+ if (!((_changes = changes) === null || _changes === void 0 ? void 0 : (_changes_tracked = _changes.tracked) === null || _changes_tracked === void 0 ? void 0 : _changes_tracked.length)) {
46
+ return;
47
+ }
48
+ const isJustReactStateUpdate = changes.tracked.length === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === element.value;
49
+ if (!isJustReactStateUpdate) {
50
+ setUIValueClean(element);
51
+ }
52
+ if (hasUISelection(element)) {
53
+ setUISelection(element, {
54
+ focusOffset: isJustReactStateUpdate ? cursorOffset : element.value.length
55
+ });
56
+ }
57
+ }
58
+
59
+ export { commitValueAfterInput, startTrackValue, trackOrSetValue };