@depup/testing-library__user-event 14.6.3-depup.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 (309) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +25 -0
  3. package/changes.json +5 -0
  4. package/dist/cjs/clipboard/copy.js +22 -0
  5. package/dist/cjs/clipboard/cut.js +22 -0
  6. package/dist/cjs/clipboard/index.js +11 -0
  7. package/dist/cjs/clipboard/paste.js +24 -0
  8. package/dist/cjs/convenience/click.js +35 -0
  9. package/dist/cjs/convenience/hover.js +19 -0
  10. package/dist/cjs/convenience/index.js +14 -0
  11. package/dist/cjs/convenience/tab.js +7 -0
  12. package/dist/cjs/document/UI.js +90 -0
  13. package/dist/cjs/document/copySelection.js +29 -0
  14. package/dist/cjs/document/getValueOrTextContent.js +18 -0
  15. package/dist/cjs/document/index.js +17 -0
  16. package/dist/cjs/document/interceptor.js +104 -0
  17. package/dist/cjs/document/patchFocus.js +106 -0
  18. package/dist/cjs/document/prepareDocument.js +58 -0
  19. package/dist/cjs/document/trackValue.js +57 -0
  20. package/dist/cjs/event/behavior/click.js +32 -0
  21. package/dist/cjs/event/behavior/cut.js +14 -0
  22. package/dist/cjs/event/behavior/index.js +13 -0
  23. package/dist/cjs/event/behavior/keydown.js +128 -0
  24. package/dist/cjs/event/behavior/keypress.js +51 -0
  25. package/dist/cjs/event/behavior/keyup.js +17 -0
  26. package/dist/cjs/event/behavior/paste.js +18 -0
  27. package/dist/cjs/event/behavior/registry.js +5 -0
  28. package/dist/cjs/event/createEvent.js +193 -0
  29. package/dist/cjs/event/dispatchEvent.js +54 -0
  30. package/dist/cjs/event/eventMap.js +281 -0
  31. package/dist/cjs/event/focus.js +34 -0
  32. package/dist/cjs/event/index.js +22 -0
  33. package/dist/cjs/event/input.js +158 -0
  34. package/dist/cjs/event/radio.js +27 -0
  35. package/dist/cjs/event/selection/getInputRange.js +18 -0
  36. package/dist/cjs/event/selection/getTargetTypeAndSelection.js +31 -0
  37. package/dist/cjs/event/selection/index.js +24 -0
  38. package/dist/cjs/event/selection/modifySelection.js +21 -0
  39. package/dist/cjs/event/selection/modifySelectionPerMouse.js +40 -0
  40. package/dist/cjs/event/selection/moveSelection.js +38 -0
  41. package/dist/cjs/event/selection/resolveCaretPosition.js +60 -0
  42. package/dist/cjs/event/selection/selectAll.js +38 -0
  43. package/dist/cjs/event/selection/setSelection.js +21 -0
  44. package/dist/cjs/event/selection/setSelectionPerMouse.js +79 -0
  45. package/dist/cjs/event/selection/setSelectionRange.js +31 -0
  46. package/dist/cjs/event/selection/updateSelectionOnFocus.js +40 -0
  47. package/dist/cjs/event/types.js +2 -0
  48. package/dist/cjs/event/wrapEvent.js +10 -0
  49. package/dist/cjs/index.js +12 -0
  50. package/dist/cjs/keyboard/index.js +40 -0
  51. package/dist/cjs/keyboard/keyMap.js +178 -0
  52. package/dist/cjs/keyboard/parseKeyDef.js +45 -0
  53. package/dist/cjs/options.js +14 -0
  54. package/dist/cjs/package.json +3 -0
  55. package/dist/cjs/pointer/index.js +74 -0
  56. package/dist/cjs/pointer/keyMap.js +33 -0
  57. package/dist/cjs/pointer/parseKeyDef.js +23 -0
  58. package/dist/cjs/setup/api.js +35 -0
  59. package/dist/cjs/setup/directApi.js +75 -0
  60. package/dist/cjs/setup/index.js +11 -0
  61. package/dist/cjs/setup/setup.js +125 -0
  62. package/dist/cjs/setup/wrapAsync.js +11 -0
  63. package/dist/cjs/system/index.js +42 -0
  64. package/dist/cjs/system/keyboard.js +165 -0
  65. package/dist/cjs/system/pointer/buttons.js +80 -0
  66. package/dist/cjs/system/pointer/device.js +32 -0
  67. package/dist/cjs/system/pointer/index.js +156 -0
  68. package/dist/cjs/system/pointer/mouse.js +204 -0
  69. package/dist/cjs/system/pointer/pointer.js +129 -0
  70. package/dist/cjs/system/pointer/shared.js +8 -0
  71. package/dist/cjs/utility/clear.js +32 -0
  72. package/dist/cjs/utility/index.js +14 -0
  73. package/dist/cjs/utility/selectOptions.js +114 -0
  74. package/dist/cjs/utility/type.js +23 -0
  75. package/dist/cjs/utility/upload.js +62 -0
  76. package/dist/cjs/utils/click/isClickableInput.js +20 -0
  77. package/dist/cjs/utils/dataTransfer/Blob.js +16 -0
  78. package/dist/cjs/utils/dataTransfer/Clipboard.js +174 -0
  79. package/dist/cjs/utils/dataTransfer/DataTransfer.js +134 -0
  80. package/dist/cjs/utils/dataTransfer/FileList.js +24 -0
  81. package/dist/cjs/utils/edit/isContentEditable.js +18 -0
  82. package/dist/cjs/utils/edit/isEditable.js +29 -0
  83. package/dist/cjs/utils/edit/maxLength.js +26 -0
  84. package/dist/cjs/utils/edit/setFiles.js +58 -0
  85. package/dist/cjs/utils/edit/timeValue.js +40 -0
  86. package/dist/cjs/utils/focus/cursor.js +126 -0
  87. package/dist/cjs/utils/focus/getActiveElement.js +25 -0
  88. package/dist/cjs/utils/focus/getTabDestination.js +80 -0
  89. package/dist/cjs/utils/focus/isFocusable.js +9 -0
  90. package/dist/cjs/utils/focus/selection.js +20 -0
  91. package/dist/cjs/utils/focus/selector.js +15 -0
  92. package/dist/cjs/utils/index.js +78 -0
  93. package/dist/cjs/utils/keyDef/readNextDescriptor.js +91 -0
  94. package/dist/cjs/utils/misc/cloneEvent.js +7 -0
  95. package/dist/cjs/utils/misc/findClosest.js +14 -0
  96. package/dist/cjs/utils/misc/getDocumentFromNode.js +10 -0
  97. package/dist/cjs/utils/misc/getTreeDiff.js +25 -0
  98. package/dist/cjs/utils/misc/getWindow.js +19 -0
  99. package/dist/cjs/utils/misc/isDescendantOrSelf.js +14 -0
  100. package/dist/cjs/utils/misc/isDisabled.js +33 -0
  101. package/dist/cjs/utils/misc/isElementType.js +20 -0
  102. package/dist/cjs/utils/misc/isVisible.js +19 -0
  103. package/dist/cjs/utils/misc/level.js +17 -0
  104. package/dist/cjs/utils/misc/wait.js +14 -0
  105. package/dist/cjs/utils/pointer/cssPointerEvents.js +102 -0
  106. package/dist/esm/clipboard/copy.js +20 -0
  107. package/dist/esm/clipboard/cut.js +20 -0
  108. package/dist/esm/clipboard/index.js +3 -0
  109. package/dist/esm/clipboard/paste.js +22 -0
  110. package/dist/esm/convenience/click.js +31 -0
  111. package/dist/esm/convenience/hover.js +16 -0
  112. package/dist/esm/convenience/index.js +3 -0
  113. package/dist/esm/convenience/tab.js +5 -0
  114. package/dist/esm/document/UI.js +77 -0
  115. package/dist/esm/document/copySelection.js +27 -0
  116. package/dist/esm/document/getValueOrTextContent.js +16 -0
  117. package/dist/esm/document/index.js +4 -0
  118. package/dist/esm/document/interceptor.js +99 -0
  119. package/dist/esm/document/patchFocus.js +103 -0
  120. package/dist/esm/document/prepareDocument.js +56 -0
  121. package/dist/esm/document/trackValue.js +53 -0
  122. package/dist/esm/event/behavior/click.js +30 -0
  123. package/dist/esm/event/behavior/cut.js +12 -0
  124. package/dist/esm/event/behavior/index.js +7 -0
  125. package/dist/esm/event/behavior/keydown.js +126 -0
  126. package/dist/esm/event/behavior/keypress.js +49 -0
  127. package/dist/esm/event/behavior/keyup.js +15 -0
  128. package/dist/esm/event/behavior/paste.js +16 -0
  129. package/dist/esm/event/behavior/registry.js +3 -0
  130. package/dist/esm/event/createEvent.js +191 -0
  131. package/dist/esm/event/dispatchEvent.js +50 -0
  132. package/dist/esm/event/eventMap.js +277 -0
  133. package/dist/esm/event/focus.js +31 -0
  134. package/dist/esm/event/index.js +7 -0
  135. package/dist/esm/event/input.js +156 -0
  136. package/dist/esm/event/radio.js +25 -0
  137. package/dist/esm/event/selection/getInputRange.js +16 -0
  138. package/dist/esm/event/selection/getTargetTypeAndSelection.js +29 -0
  139. package/dist/esm/event/selection/index.js +9 -0
  140. package/dist/esm/event/selection/modifySelection.js +19 -0
  141. package/dist/esm/event/selection/modifySelectionPerMouse.js +38 -0
  142. package/dist/esm/event/selection/moveSelection.js +36 -0
  143. package/dist/esm/event/selection/resolveCaretPosition.js +58 -0
  144. package/dist/esm/event/selection/selectAll.js +35 -0
  145. package/dist/esm/event/selection/setSelection.js +19 -0
  146. package/dist/esm/event/selection/setSelectionPerMouse.js +77 -0
  147. package/dist/esm/event/selection/setSelectionRange.js +29 -0
  148. package/dist/esm/event/selection/updateSelectionOnFocus.js +38 -0
  149. package/dist/esm/event/types.js +1 -0
  150. package/dist/esm/event/wrapEvent.js +8 -0
  151. package/dist/esm/index.js +2 -0
  152. package/dist/esm/keyboard/index.js +37 -0
  153. package/dist/esm/keyboard/keyMap.js +176 -0
  154. package/dist/esm/keyboard/parseKeyDef.js +43 -0
  155. package/dist/esm/options.js +12 -0
  156. package/dist/esm/package.json +3 -0
  157. package/dist/esm/pointer/index.js +72 -0
  158. package/dist/esm/pointer/keyMap.js +31 -0
  159. package/dist/esm/pointer/parseKeyDef.js +21 -0
  160. package/dist/esm/setup/api.js +33 -0
  161. package/dist/esm/setup/directApi.js +58 -0
  162. package/dist/esm/setup/index.js +9 -0
  163. package/dist/esm/setup/setup.js +119 -0
  164. package/dist/esm/setup/wrapAsync.js +9 -0
  165. package/dist/esm/system/index.js +40 -0
  166. package/dist/esm/system/keyboard.js +162 -0
  167. package/dist/esm/system/pointer/buttons.js +74 -0
  168. package/dist/esm/system/pointer/device.js +30 -0
  169. package/dist/esm/system/pointer/index.js +154 -0
  170. package/dist/esm/system/pointer/mouse.js +202 -0
  171. package/dist/esm/system/pointer/pointer.js +127 -0
  172. package/dist/esm/system/pointer/shared.js +6 -0
  173. package/dist/esm/utility/clear.js +30 -0
  174. package/dist/esm/utility/index.js +4 -0
  175. package/dist/esm/utility/selectOptions.js +111 -0
  176. package/dist/esm/utility/type.js +21 -0
  177. package/dist/esm/utility/upload.js +60 -0
  178. package/dist/esm/utils/click/isClickableInput.js +18 -0
  179. package/dist/esm/utils/dataTransfer/Blob.js +14 -0
  180. package/dist/esm/utils/dataTransfer/Clipboard.js +167 -0
  181. package/dist/esm/utils/dataTransfer/DataTransfer.js +131 -0
  182. package/dist/esm/utils/dataTransfer/FileList.js +22 -0
  183. package/dist/esm/utils/edit/isContentEditable.js +15 -0
  184. package/dist/esm/utils/edit/isEditable.js +26 -0
  185. package/dist/esm/utils/edit/maxLength.js +23 -0
  186. package/dist/esm/utils/edit/setFiles.js +56 -0
  187. package/dist/esm/utils/edit/timeValue.js +37 -0
  188. package/dist/esm/utils/focus/cursor.js +124 -0
  189. package/dist/esm/utils/focus/getActiveElement.js +22 -0
  190. package/dist/esm/utils/focus/getTabDestination.js +78 -0
  191. package/dist/esm/utils/focus/isFocusable.js +7 -0
  192. package/dist/esm/utils/focus/selection.js +17 -0
  193. package/dist/esm/utils/focus/selector.js +13 -0
  194. package/dist/esm/utils/index.js +29 -0
  195. package/dist/esm/utils/keyDef/readNextDescriptor.js +89 -0
  196. package/dist/esm/utils/misc/cloneEvent.js +5 -0
  197. package/dist/esm/utils/misc/findClosest.js +12 -0
  198. package/dist/esm/utils/misc/getDocumentFromNode.js +8 -0
  199. package/dist/esm/utils/misc/getTreeDiff.js +23 -0
  200. package/dist/esm/utils/misc/getWindow.js +17 -0
  201. package/dist/esm/utils/misc/isDescendantOrSelf.js +12 -0
  202. package/dist/esm/utils/misc/isDisabled.js +31 -0
  203. package/dist/esm/utils/misc/isElementType.js +18 -0
  204. package/dist/esm/utils/misc/isVisible.js +17 -0
  205. package/dist/esm/utils/misc/level.js +13 -0
  206. package/dist/esm/utils/misc/wait.js +12 -0
  207. package/dist/esm/utils/pointer/cssPointerEvents.js +99 -0
  208. package/dist/types/clipboard/copy.d.ts +2 -0
  209. package/dist/types/clipboard/cut.d.ts +2 -0
  210. package/dist/types/clipboard/index.d.ts +3 -0
  211. package/dist/types/clipboard/paste.d.ts +2 -0
  212. package/dist/types/convenience/click.d.ts +4 -0
  213. package/dist/types/convenience/hover.d.ts +3 -0
  214. package/dist/types/convenience/index.d.ts +3 -0
  215. package/dist/types/convenience/tab.d.ts +4 -0
  216. package/dist/types/document/UI.d.ts +42 -0
  217. package/dist/types/document/copySelection.d.ts +1 -0
  218. package/dist/types/document/getValueOrTextContent.d.ts +1 -0
  219. package/dist/types/document/index.d.ts +5 -0
  220. package/dist/types/document/interceptor.d.ts +19 -0
  221. package/dist/types/document/patchFocus.d.ts +9 -0
  222. package/dist/types/document/prepareDocument.d.ts +8 -0
  223. package/dist/types/document/trackValue.d.ts +17 -0
  224. package/dist/types/event/behavior/click.d.ts +1 -0
  225. package/dist/types/event/behavior/cut.d.ts +1 -0
  226. package/dist/types/event/behavior/index.d.ts +8 -0
  227. package/dist/types/event/behavior/keydown.d.ts +1 -0
  228. package/dist/types/event/behavior/keypress.d.ts +1 -0
  229. package/dist/types/event/behavior/keyup.d.ts +1 -0
  230. package/dist/types/event/behavior/paste.d.ts +1 -0
  231. package/dist/types/event/behavior/registry.d.ts +8 -0
  232. package/dist/types/event/createEvent.d.ts +2 -0
  233. package/dist/types/event/dispatchEvent.d.ts +5 -0
  234. package/dist/types/event/eventMap.d.ts +265 -0
  235. package/dist/types/event/focus.d.ts +5 -0
  236. package/dist/types/event/index.d.ts +7 -0
  237. package/dist/types/event/input.d.ts +2 -0
  238. package/dist/types/event/radio.d.ts +4 -0
  239. package/dist/types/event/selection/getInputRange.d.ts +5 -0
  240. package/dist/types/event/selection/getTargetTypeAndSelection.d.ts +10 -0
  241. package/dist/types/event/selection/index.d.ts +15 -0
  242. package/dist/types/event/selection/modifySelection.d.ts +8 -0
  243. package/dist/types/event/selection/modifySelectionPerMouse.d.ts +7 -0
  244. package/dist/types/event/selection/moveSelection.d.ts +4 -0
  245. package/dist/types/event/selection/resolveCaretPosition.d.ts +8 -0
  246. package/dist/types/event/selection/selectAll.d.ts +5 -0
  247. package/dist/types/event/selection/setSelection.d.ts +10 -0
  248. package/dist/types/event/selection/setSelectionPerMouse.d.ts +8 -0
  249. package/dist/types/event/selection/setSelectionRange.d.ts +6 -0
  250. package/dist/types/event/selection/updateSelectionOnFocus.d.ts +5 -0
  251. package/dist/types/event/types.d.ts +20 -0
  252. package/dist/types/event/wrapEvent.d.ts +1 -0
  253. package/dist/types/index.d.ts +6 -0
  254. package/dist/types/keyboard/index.d.ts +3 -0
  255. package/dist/types/keyboard/keyMap.d.ts +5 -0
  256. package/dist/types/keyboard/parseKeyDef.d.ts +17 -0
  257. package/dist/types/options.d.ts +115 -0
  258. package/dist/types/pointer/index.d.ts +28 -0
  259. package/dist/types/pointer/keyMap.d.ts +2 -0
  260. package/dist/types/pointer/parseKeyDef.d.ts +6 -0
  261. package/dist/types/setup/api.d.ts +23 -0
  262. package/dist/types/setup/directApi.d.ts +24 -0
  263. package/dist/types/setup/index.d.ts +22 -0
  264. package/dist/types/setup/setup.d.ts +44 -0
  265. package/dist/types/setup/wrapAsync.d.ts +4 -0
  266. package/dist/types/system/index.d.ts +10 -0
  267. package/dist/types/system/keyboard.d.ts +50 -0
  268. package/dist/types/system/pointer/buttons.d.ts +23 -0
  269. package/dist/types/system/pointer/device.d.ts +8 -0
  270. package/dist/types/system/pointer/index.d.ts +21 -0
  271. package/dist/types/system/pointer/mouse.d.ts +31 -0
  272. package/dist/types/system/pointer/pointer.d.ts +32 -0
  273. package/dist/types/system/pointer/shared.d.ts +20 -0
  274. package/dist/types/utility/clear.d.ts +2 -0
  275. package/dist/types/utility/index.d.ts +4 -0
  276. package/dist/types/utility/selectOptions.d.ts +3 -0
  277. package/dist/types/utility/type.d.ts +9 -0
  278. package/dist/types/utility/upload.d.ts +5 -0
  279. package/dist/types/utils/click/isClickableInput.d.ts +15 -0
  280. package/dist/types/utils/dataTransfer/Blob.d.ts +3 -0
  281. package/dist/types/utils/dataTransfer/Clipboard.d.ts +11 -0
  282. package/dist/types/utils/dataTransfer/DataTransfer.d.ts +2 -0
  283. package/dist/types/utils/dataTransfer/FileList.d.ts +1 -0
  284. package/dist/types/utils/edit/isContentEditable.d.ts +7 -0
  285. package/dist/types/utils/edit/isEditable.d.ts +24 -0
  286. package/dist/types/utils/edit/maxLength.d.ts +14 -0
  287. package/dist/types/utils/edit/setFiles.d.ts +12 -0
  288. package/dist/types/utils/edit/timeValue.d.ts +4 -0
  289. package/dist/types/utils/focus/cursor.d.ts +9 -0
  290. package/dist/types/utils/focus/getActiveElement.d.ts +2 -0
  291. package/dist/types/utils/focus/getTabDestination.d.ts +1 -0
  292. package/dist/types/utils/focus/isFocusable.d.ts +1 -0
  293. package/dist/types/utils/focus/selection.d.ts +8 -0
  294. package/dist/types/utils/focus/selector.d.ts +1 -0
  295. package/dist/types/utils/index.d.ts +29 -0
  296. package/dist/types/utils/keyDef/readNextDescriptor.d.ts +21 -0
  297. package/dist/types/utils/misc/cloneEvent.d.ts +1 -0
  298. package/dist/types/utils/misc/findClosest.d.ts +1 -0
  299. package/dist/types/utils/misc/getDocumentFromNode.d.ts +1 -0
  300. package/dist/types/utils/misc/getTreeDiff.d.ts +1 -0
  301. package/dist/types/utils/misc/getWindow.d.ts +1 -0
  302. package/dist/types/utils/misc/isDescendantOrSelf.d.ts +1 -0
  303. package/dist/types/utils/misc/isDisabled.d.ts +1 -0
  304. package/dist/types/utils/misc/isElementType.d.ts +5 -0
  305. package/dist/types/utils/misc/isVisible.d.ts +1 -0
  306. package/dist/types/utils/misc/level.d.ts +8 -0
  307. package/dist/types/utils/misc/wait.d.ts +2 -0
  308. package/dist/types/utils/pointer/cssPointerEvents.d.ts +19 -0
  309. package/package.json +131 -0
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ var UI = require('../../document/UI.js');
4
+ require('../../utils/dataTransfer/Clipboard.js');
5
+ var cursor = require('../../utils/focus/cursor.js');
6
+ var selection = require('../../utils/focus/selection.js');
7
+ var setSelection = require('./setSelection.js');
8
+
9
+ /**
10
+ * Move the selection
11
+ */ function moveSelection(node, direction) {
12
+ // TODO: implement shift
13
+ if (selection.hasOwnSelection(node)) {
14
+ const selection = UI.getUISelection(node);
15
+ setSelection.setSelection({
16
+ focusNode: node,
17
+ focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + direction : direction < 0 ? selection.startOffset : selection.endOffset
18
+ });
19
+ } else {
20
+ const selection = node.ownerDocument.getSelection();
21
+ if (!(selection === null || selection === void 0 ? void 0 : selection.focusNode)) {
22
+ return;
23
+ }
24
+ if (selection.isCollapsed) {
25
+ const nextPosition = cursor.getNextCursorPosition(selection.focusNode, selection.focusOffset, direction);
26
+ if (nextPosition) {
27
+ setSelection.setSelection({
28
+ focusNode: nextPosition.node,
29
+ focusOffset: nextPosition.offset
30
+ });
31
+ }
32
+ } else {
33
+ selection[direction < 0 ? 'collapseToStart' : 'collapseToEnd']();
34
+ }
35
+ }
36
+ }
37
+
38
+ exports.moveSelection = moveSelection;
@@ -0,0 +1,60 @@
1
+ 'use strict';
2
+
3
+ var UI = require('../../document/UI.js');
4
+ require('../../utils/dataTransfer/Clipboard.js');
5
+ var selection = require('../../utils/focus/selection.js');
6
+
7
+ function resolveCaretPosition({ target, node, offset }) {
8
+ if (selection.hasOwnSelection(target)) {
9
+ return {
10
+ node: target,
11
+ offset: offset !== null && offset !== void 0 ? offset : UI.getUIValue(target).length
12
+ };
13
+ } else if (node) {
14
+ return {
15
+ node,
16
+ offset: offset !== null && offset !== void 0 ? offset : node.nodeType === 3 ? node.nodeValue.length : node.childNodes.length
17
+ };
18
+ }
19
+ return findNodeAtTextOffset(target, offset);
20
+ }
21
+ function findNodeAtTextOffset(node, offset, isRoot = true) {
22
+ // When clicking after the content the browser behavior can be complicated:
23
+ // 1. If there is textContent after the last element child,
24
+ // the cursor is moved there.
25
+ // 2. If there is textContent in the last element child,
26
+ // the browser moves the cursor to the last non-empty text node inside this element.
27
+ // 3. Otherwise the cursor is moved to the end of the target.
28
+ let i = offset === undefined ? node.childNodes.length - 1 : 0;
29
+ const step = offset === undefined ? -1 : 1;
30
+ while(offset === undefined ? i >= (isRoot ? Math.max(node.childNodes.length - 1, 0) : 0) : i <= node.childNodes.length){
31
+ if (offset && i === node.childNodes.length) {
32
+ throw new Error('The given offset is out of bounds.');
33
+ }
34
+ const c = node.childNodes.item(i);
35
+ const text = String(c.textContent);
36
+ if (text.length) {
37
+ if (offset !== undefined && text.length < offset) {
38
+ offset -= text.length;
39
+ } else if (c.nodeType === 1) {
40
+ return findNodeAtTextOffset(c, offset, false);
41
+ } else {
42
+ // The pre-commit hooks keeps changing this
43
+ // See https://github.com/kentcdodds/kcd-scripts/issues/218
44
+ /* istanbul ignore else */ if (c.nodeType === 3) {
45
+ return {
46
+ node: c,
47
+ offset: offset !== null && offset !== void 0 ? offset : c.nodeValue.length
48
+ };
49
+ }
50
+ }
51
+ }
52
+ i += step;
53
+ }
54
+ return {
55
+ node,
56
+ offset: node.childNodes.length
57
+ };
58
+ }
59
+
60
+ exports.resolveCaretPosition = resolveCaretPosition;
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ var UI = require('../../document/UI.js');
4
+ require('../../utils/dataTransfer/Clipboard.js');
5
+ var isContentEditable = require('../../utils/edit/isContentEditable.js');
6
+ var selection = require('../../utils/focus/selection.js');
7
+ var setSelection = require('./setSelection.js');
8
+
9
+ /**
10
+ * Expand a selection like the browser does when pressing Ctrl+A.
11
+ */ function selectAll(target) {
12
+ var _getContentEditable;
13
+ if (selection.hasOwnSelection(target)) {
14
+ return setSelection.setSelection({
15
+ focusNode: target,
16
+ anchorOffset: 0,
17
+ focusOffset: UI.getUIValue(target).length
18
+ });
19
+ }
20
+ const focusNode = (_getContentEditable = isContentEditable.getContentEditable(target)) !== null && _getContentEditable !== void 0 ? _getContentEditable : target.ownerDocument.body;
21
+ setSelection.setSelection({
22
+ focusNode,
23
+ anchorOffset: 0,
24
+ focusOffset: focusNode.childNodes.length
25
+ });
26
+ }
27
+ function isAllSelected(target) {
28
+ var _getContentEditable;
29
+ if (selection.hasOwnSelection(target)) {
30
+ return UI.getUISelection(target).startOffset === 0 && UI.getUISelection(target).endOffset === UI.getUIValue(target).length;
31
+ }
32
+ const focusNode = (_getContentEditable = isContentEditable.getContentEditable(target)) !== null && _getContentEditable !== void 0 ? _getContentEditable : target.ownerDocument.body;
33
+ const selection$1 = target.ownerDocument.getSelection();
34
+ return (selection$1 === null || selection$1 === void 0 ? void 0 : selection$1.anchorNode) === focusNode && selection$1.focusNode === focusNode && selection$1.anchorOffset === 0 && selection$1.focusOffset === focusNode.childNodes.length;
35
+ }
36
+
37
+ exports.isAllSelected = isAllSelected;
38
+ exports.selectAll = selectAll;
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ var UI = require('../../document/UI.js');
4
+ require('../../utils/dataTransfer/Clipboard.js');
5
+ var getTargetTypeAndSelection = require('./getTargetTypeAndSelection.js');
6
+
7
+ /**
8
+ * Set the selection
9
+ */ function setSelection({ focusNode, focusOffset, anchorNode = focusNode, anchorOffset = focusOffset }) {
10
+ var _anchorNode_ownerDocument_getSelection, _anchorNode_ownerDocument;
11
+ const typeAndSelection = getTargetTypeAndSelection.getTargetTypeAndSelection(focusNode);
12
+ if (typeAndSelection.type === 'input') {
13
+ return UI.setUISelection(focusNode, {
14
+ anchorOffset,
15
+ focusOffset
16
+ });
17
+ }
18
+ (_anchorNode_ownerDocument = anchorNode.ownerDocument) === null || _anchorNode_ownerDocument === void 0 ? void 0 : (_anchorNode_ownerDocument_getSelection = _anchorNode_ownerDocument.getSelection()) === null || _anchorNode_ownerDocument_getSelection === void 0 ? void 0 : _anchorNode_ownerDocument_getSelection.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
19
+ }
20
+
21
+ exports.setSelection = setSelection;
@@ -0,0 +1,79 @@
1
+ 'use strict';
2
+
3
+ var UI = require('../../document/UI.js');
4
+ require('../../utils/dataTransfer/Clipboard.js');
5
+ var selection = require('../../utils/focus/selection.js');
6
+ var resolveCaretPosition = require('./resolveCaretPosition.js');
7
+
8
+ function setSelectionPerMouseDown({ document, target, clickCount, node, offset }) {
9
+ if (selection.hasNoSelection(target)) {
10
+ return;
11
+ }
12
+ const targetHasOwnSelection = selection.hasOwnSelection(target);
13
+ // On non-input elements the text selection per multiple click
14
+ // can extend beyond the target boundaries.
15
+ // The exact mechanism what is considered in the same line is unclear.
16
+ // Looks it might be every inline element.
17
+ // TODO: Check what might be considered part of the same line of text.
18
+ const text = String(targetHasOwnSelection ? UI.getUIValue(target) : target.textContent);
19
+ const [start, end] = node ? [
20
+ offset,
21
+ offset
22
+ ] : getTextRange(text, offset, clickCount);
23
+ // TODO: implement modifying selection per shift/ctrl+mouse
24
+ if (targetHasOwnSelection) {
25
+ UI.setUISelection(target, {
26
+ anchorOffset: start !== null && start !== void 0 ? start : text.length,
27
+ focusOffset: end !== null && end !== void 0 ? end : text.length
28
+ });
29
+ return {
30
+ node: target,
31
+ start: start !== null && start !== void 0 ? start : 0,
32
+ end: end !== null && end !== void 0 ? end : text.length
33
+ };
34
+ } else {
35
+ const { node: startNode, offset: startOffset } = resolveCaretPosition.resolveCaretPosition({
36
+ target,
37
+ node,
38
+ offset: start
39
+ });
40
+ const { node: endNode, offset: endOffset } = resolveCaretPosition.resolveCaretPosition({
41
+ target,
42
+ node,
43
+ offset: end
44
+ });
45
+ const range = target.ownerDocument.createRange();
46
+ try {
47
+ range.setStart(startNode, startOffset);
48
+ range.setEnd(endNode, endOffset);
49
+ } catch {
50
+ throw new Error('The given offset is out of bounds.');
51
+ }
52
+ const selection = document.getSelection();
53
+ selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
54
+ selection === null || selection === void 0 ? void 0 : selection.addRange(range.cloneRange());
55
+ return range;
56
+ }
57
+ }
58
+ function getTextRange(text, pos, clickCount) {
59
+ if (clickCount % 3 === 1 || text.length === 0) {
60
+ return [
61
+ pos,
62
+ pos
63
+ ];
64
+ }
65
+ const textPos = pos !== null && pos !== void 0 ? pos : text.length;
66
+ if (clickCount % 3 === 2) {
67
+ return [
68
+ textPos - text.substr(0, pos).match(/(\w+|\s+|\W)?$/)[0].length,
69
+ pos === undefined ? pos : pos + text.substr(pos).match(/^(\w+|\s+|\W)?/)[0].length
70
+ ];
71
+ }
72
+ // triple click
73
+ return [
74
+ textPos - text.substr(0, pos).match(/[^\r\n]*$/)[0].length,
75
+ pos === undefined ? pos : pos + text.substr(pos).match(/^[^\r\n]*/)[0].length
76
+ ];
77
+ }
78
+
79
+ exports.setSelectionPerMouseDown = setSelectionPerMouseDown;
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ require('../../utils/dataTransfer/Clipboard.js');
4
+ var isContentEditable = require('../../utils/edit/isContentEditable.js');
5
+ var selection = require('../../utils/focus/selection.js');
6
+ var setSelection = require('./setSelection.js');
7
+
8
+ /**
9
+ * Backward-compatible selection.
10
+ *
11
+ * Handles input elements and contenteditable if it only contains a single text node.
12
+ */ function setSelectionRange(element, anchorOffset, focusOffset) {
13
+ var _element_firstChild;
14
+ if (selection.hasOwnSelection(element)) {
15
+ return setSelection.setSelection({
16
+ focusNode: element,
17
+ anchorOffset,
18
+ focusOffset
19
+ });
20
+ }
21
+ /* istanbul ignore else */ if (isContentEditable.isContentEditable(element) && ((_element_firstChild = element.firstChild) === null || _element_firstChild === void 0 ? void 0 : _element_firstChild.nodeType) === 3) {
22
+ return setSelection.setSelection({
23
+ focusNode: element.firstChild,
24
+ anchorOffset,
25
+ focusOffset
26
+ });
27
+ }
28
+ /* istanbul ignore next */ throw new Error('Not implemented. The result of this interaction is unreliable.');
29
+ }
30
+
31
+ exports.setSelectionRange = setSelectionRange;
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ require('../../utils/dataTransfer/Clipboard.js');
4
+ var isContentEditable = require('../../utils/edit/isContentEditable.js');
5
+ var selection = require('../../utils/focus/selection.js');
6
+
7
+ // The browser implementation seems to have changed.
8
+ // When focus is inside <input type="text"/>,
9
+ // Chrome updates Selection to be collapsed at the position of the input element.
10
+ // TODO: update implementation to match that of current browsers
11
+ /**
12
+ * Reset the Document Selection when moving focus into an element
13
+ * with own selection implementation.
14
+ */ function updateSelectionOnFocus(element) {
15
+ const selection$1 = element.ownerDocument.getSelection();
16
+ /* istanbul ignore if */ if (!(selection$1 === null || selection$1 === void 0 ? void 0 : selection$1.focusNode)) {
17
+ return;
18
+ }
19
+ // If the focus moves inside an element with own selection implementation,
20
+ // the document selection will be this element.
21
+ // But if the focused element is inside a contenteditable,
22
+ // 1) a collapsed selection will be retained.
23
+ // 2) other selections will be replaced by a cursor
24
+ // 2.a) at the start of the first child if it is a text node
25
+ // 2.b) at the start of the contenteditable.
26
+ if (selection.hasOwnSelection(element)) {
27
+ const contenteditable = isContentEditable.getContentEditable(selection$1.focusNode);
28
+ if (contenteditable) {
29
+ if (!selection$1.isCollapsed) {
30
+ var _contenteditable_firstChild;
31
+ const focusNode = ((_contenteditable_firstChild = contenteditable.firstChild) === null || _contenteditable_firstChild === void 0 ? void 0 : _contenteditable_firstChild.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
32
+ selection$1.setBaseAndExtent(focusNode, 0, focusNode, 0);
33
+ }
34
+ } else {
35
+ selection$1.setBaseAndExtent(element, 0, element, 0);
36
+ }
37
+ }
38
+ }
39
+
40
+ exports.updateSelectionOnFocus = updateSelectionOnFocus;
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ var dom = require('@testing-library/dom');
4
+
5
+ function wrapEvent(cb, // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
+ _element) {
7
+ return dom.getConfig().eventWrapper(cb);
8
+ }
9
+
10
+ exports.wrapEvent = wrapEvent;
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var index = require('./setup/index.js');
6
+ var options = require('./options.js');
7
+
8
+
9
+
10
+ exports.default = index.userEvent;
11
+ exports.userEvent = index.userEvent;
12
+ exports.PointerEventsCheckLevel = options.PointerEventsCheckLevel;
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ require('../utils/dataTransfer/Clipboard.js');
4
+ var wait = require('../utils/misc/wait.js');
5
+ var parseKeyDef = require('./parseKeyDef.js');
6
+
7
+ async function keyboard(text) {
8
+ const actions = parseKeyDef.parseKeyDef(this.config.keyboardMap, text);
9
+ for(let i = 0; i < actions.length; i++){
10
+ await wait.wait(this.config);
11
+ await keyboardAction(this, actions[i]);
12
+ }
13
+ }
14
+ async function keyboardAction(instance, { keyDef, releasePrevious, releaseSelf, repeat }) {
15
+ const { system } = instance;
16
+ // Release the key automatically if it was pressed before.
17
+ if (system.keyboard.isKeyPressed(keyDef)) {
18
+ await system.keyboard.keyup(instance, keyDef);
19
+ }
20
+ if (!releasePrevious) {
21
+ for(let i = 1; i <= repeat; i++){
22
+ await system.keyboard.keydown(instance, keyDef);
23
+ if (i < repeat) {
24
+ await wait.wait(instance.config);
25
+ }
26
+ }
27
+ // Release the key only on the last iteration on `state.repeatKey`.
28
+ if (releaseSelf) {
29
+ await system.keyboard.keyup(instance, keyDef);
30
+ }
31
+ }
32
+ }
33
+ async function releaseAllKeys(instance) {
34
+ for (const k of instance.system.keyboard.getPressedKeys()){
35
+ await instance.system.keyboard.keyup(instance, k);
36
+ }
37
+ }
38
+
39
+ exports.keyboard = keyboard;
40
+ exports.releaseAllKeys = releaseAllKeys;
@@ -0,0 +1,178 @@
1
+ 'use strict';
2
+
3
+ var keyboard = require('../system/keyboard.js');
4
+
5
+ /**
6
+ * Mapping for a default US-104-QWERTY keyboard
7
+ */ const defaultKeyMap = [
8
+ // alphanumeric block - writing system
9
+ ...'0123456789'.split('').map((c)=>({
10
+ code: `Digit${c}`,
11
+ key: c
12
+ })),
13
+ ...')!@#$%^&*('.split('').map((c, i)=>({
14
+ code: `Digit${i}`,
15
+ key: c,
16
+ shiftKey: true
17
+ })),
18
+ ...'abcdefghijklmnopqrstuvwxyz'.split('').map((c)=>({
19
+ code: `Key${c.toUpperCase()}`,
20
+ key: c
21
+ })),
22
+ ...'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('').map((c)=>({
23
+ code: `Key${c}`,
24
+ key: c,
25
+ shiftKey: true
26
+ })),
27
+ {
28
+ code: 'BracketLeft',
29
+ key: '['
30
+ },
31
+ {
32
+ code: 'BracketLeft',
33
+ key: '{',
34
+ shiftKey: true
35
+ },
36
+ {
37
+ code: 'BracketRight',
38
+ key: ']'
39
+ },
40
+ {
41
+ code: 'BracketRight',
42
+ key: '}',
43
+ shiftKey: true
44
+ },
45
+ // alphanumeric block - functional
46
+ {
47
+ code: 'Space',
48
+ key: ' '
49
+ },
50
+ {
51
+ code: 'AltLeft',
52
+ key: 'Alt',
53
+ location: keyboard.DOM_KEY_LOCATION.LEFT
54
+ },
55
+ {
56
+ code: 'AltRight',
57
+ key: 'Alt',
58
+ location: keyboard.DOM_KEY_LOCATION.RIGHT
59
+ },
60
+ {
61
+ code: 'ShiftLeft',
62
+ key: 'Shift',
63
+ location: keyboard.DOM_KEY_LOCATION.LEFT
64
+ },
65
+ {
66
+ code: 'ShiftRight',
67
+ key: 'Shift',
68
+ location: keyboard.DOM_KEY_LOCATION.RIGHT
69
+ },
70
+ {
71
+ code: 'ControlLeft',
72
+ key: 'Control',
73
+ location: keyboard.DOM_KEY_LOCATION.LEFT
74
+ },
75
+ {
76
+ code: 'ControlRight',
77
+ key: 'Control',
78
+ location: keyboard.DOM_KEY_LOCATION.RIGHT
79
+ },
80
+ {
81
+ code: 'MetaLeft',
82
+ key: 'Meta',
83
+ location: keyboard.DOM_KEY_LOCATION.LEFT
84
+ },
85
+ {
86
+ code: 'MetaRight',
87
+ key: 'Meta',
88
+ location: keyboard.DOM_KEY_LOCATION.RIGHT
89
+ },
90
+ {
91
+ code: 'OSLeft',
92
+ key: 'OS',
93
+ location: keyboard.DOM_KEY_LOCATION.LEFT
94
+ },
95
+ {
96
+ code: 'OSRight',
97
+ key: 'OS',
98
+ location: keyboard.DOM_KEY_LOCATION.RIGHT
99
+ },
100
+ {
101
+ code: 'ContextMenu',
102
+ key: 'ContextMenu'
103
+ },
104
+ {
105
+ code: 'Tab',
106
+ key: 'Tab'
107
+ },
108
+ {
109
+ code: 'CapsLock',
110
+ key: 'CapsLock'
111
+ },
112
+ {
113
+ code: 'Backspace',
114
+ key: 'Backspace'
115
+ },
116
+ {
117
+ code: 'Enter',
118
+ key: 'Enter'
119
+ },
120
+ // function
121
+ {
122
+ code: 'Escape',
123
+ key: 'Escape'
124
+ },
125
+ // arrows
126
+ {
127
+ code: 'ArrowUp',
128
+ key: 'ArrowUp'
129
+ },
130
+ {
131
+ code: 'ArrowDown',
132
+ key: 'ArrowDown'
133
+ },
134
+ {
135
+ code: 'ArrowLeft',
136
+ key: 'ArrowLeft'
137
+ },
138
+ {
139
+ code: 'ArrowRight',
140
+ key: 'ArrowRight'
141
+ },
142
+ // control pad
143
+ {
144
+ code: 'Home',
145
+ key: 'Home'
146
+ },
147
+ {
148
+ code: 'End',
149
+ key: 'End'
150
+ },
151
+ {
152
+ code: 'Delete',
153
+ key: 'Delete'
154
+ },
155
+ {
156
+ code: 'PageUp',
157
+ key: 'PageUp'
158
+ },
159
+ {
160
+ code: 'PageDown',
161
+ key: 'PageDown'
162
+ },
163
+ // Special keys that are not part of a default US-layout but included for specific behavior
164
+ {
165
+ code: 'Fn',
166
+ key: 'Fn'
167
+ },
168
+ {
169
+ code: 'Symbol',
170
+ key: 'Symbol'
171
+ },
172
+ {
173
+ code: 'AltRight',
174
+ key: 'AltGraph'
175
+ }
176
+ ];
177
+
178
+ exports.defaultKeyMap = defaultKeyMap;
@@ -0,0 +1,45 @@
1
+ 'use strict';
2
+
3
+ require('../utils/dataTransfer/Clipboard.js');
4
+ var readNextDescriptor = require('../utils/keyDef/readNextDescriptor.js');
5
+
6
+ /**
7
+ * Parse key definitions per `keyboardMap`
8
+ *
9
+ * Keys can be referenced by `{key}` or `{special}` as well as physical locations per `[code]`.
10
+ * Everything else will be interpreted as a typed character - e.g. `a`.
11
+ * Brackets `{` and `[` can be escaped by doubling - e.g. `foo[[bar` translates to `foo[bar`.
12
+ * Keeping the key pressed can be written as `{key>}`.
13
+ * When keeping the key pressed you can choose how long (how many keydown and keypress) the key is pressed `{key>3}`.
14
+ * You can then release the key per `{key>3/}` or keep it pressed and continue with the next key.
15
+ */ function parseKeyDef(keyboardMap, text) {
16
+ const defs = [];
17
+ do {
18
+ var _keyboardMap_find;
19
+ const { type, descriptor, consumedLength, releasePrevious, releaseSelf = true, repeat } = readNextDescriptor.readNextDescriptor(text, 'keyboard');
20
+ const keyDef = (_keyboardMap_find = keyboardMap.find((def)=>{
21
+ if (type === '[') {
22
+ var _def_code;
23
+ return ((_def_code = def.code) === null || _def_code === void 0 ? void 0 : _def_code.toLowerCase()) === descriptor.toLowerCase();
24
+ } else if (type === '{') {
25
+ var _def_key;
26
+ return ((_def_key = def.key) === null || _def_key === void 0 ? void 0 : _def_key.toLowerCase()) === descriptor.toLowerCase();
27
+ }
28
+ return def.key === descriptor;
29
+ })) !== null && _keyboardMap_find !== void 0 ? _keyboardMap_find : {
30
+ key: 'Unknown',
31
+ code: 'Unknown',
32
+ [type === '[' ? 'code' : 'key']: descriptor
33
+ };
34
+ defs.push({
35
+ keyDef,
36
+ releasePrevious,
37
+ releaseSelf,
38
+ repeat
39
+ });
40
+ text = text.slice(consumedLength);
41
+ }while (text)
42
+ return defs;
43
+ }
44
+
45
+ exports.parseKeyDef = parseKeyDef;
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ var PointerEventsCheckLevel = /*#__PURE__*/ function(PointerEventsCheckLevel) {
4
+ /**
5
+ * Check pointer events on every user interaction that triggers a bunch of events.
6
+ * E.g. once for releasing a mouse button even though this triggers `pointerup`, `mouseup`, `click`, etc...
7
+ */ PointerEventsCheckLevel[PointerEventsCheckLevel["EachTrigger"] = 4] = "EachTrigger";
8
+ /** Check each target once per call to pointer (related) API */ PointerEventsCheckLevel[PointerEventsCheckLevel["EachApiCall"] = 2] = "EachApiCall";
9
+ /** Check each event target once */ PointerEventsCheckLevel[PointerEventsCheckLevel["EachTarget"] = 1] = "EachTarget";
10
+ /** No pointer events check */ PointerEventsCheckLevel[PointerEventsCheckLevel["Never"] = 0] = "Never";
11
+ return PointerEventsCheckLevel;
12
+ }({});
13
+
14
+ exports.PointerEventsCheckLevel = PointerEventsCheckLevel;
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }