@testing-library/user-event 14.3.0 → 14.4.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 (237) hide show
  1. package/dist/cjs/clipboard/copy.js +40 -0
  2. package/dist/cjs/clipboard/cut.js +40 -0
  3. package/dist/cjs/clipboard/index.js +13 -0
  4. package/dist/cjs/clipboard/paste.js +41 -0
  5. package/dist/cjs/convenience/click.js +40 -0
  6. package/dist/cjs/convenience/hover.js +37 -0
  7. package/dist/cjs/convenience/index.js +16 -0
  8. package/dist/cjs/convenience/tab.js +9 -0
  9. package/dist/cjs/document/index.js +74 -0
  10. package/dist/cjs/document/interceptor.js +30 -0
  11. package/dist/cjs/document/selection.js +107 -0
  12. package/dist/cjs/document/setRangeText.js +21 -0
  13. package/dist/cjs/document/value.js +125 -0
  14. package/dist/cjs/event/behavior/click.js +42 -0
  15. package/dist/cjs/event/behavior/cut.js +26 -0
  16. package/dist/cjs/event/behavior/index.js +15 -0
  17. package/dist/cjs/event/behavior/keydown.js +134 -0
  18. package/dist/cjs/event/behavior/keypress.js +58 -0
  19. package/dist/cjs/event/behavior/keyup.js +24 -0
  20. package/dist/cjs/event/behavior/paste.js +29 -0
  21. package/dist/cjs/event/behavior/registry.js +7 -0
  22. package/dist/cjs/event/createEvent.js +193 -0
  23. package/dist/cjs/event/dispatchEvent.js +37 -0
  24. package/dist/cjs/event/dom-events.d.js +2 -0
  25. package/dist/cjs/event/eventMap.js +64 -0
  26. package/dist/cjs/event/index.js +24 -0
  27. package/dist/cjs/event/types.js +2 -0
  28. package/dist/cjs/event/wrapEvent.js +11 -0
  29. package/dist/cjs/index.js +14 -0
  30. package/dist/cjs/keyboard/index.js +59 -0
  31. package/dist/cjs/keyboard/keyMap.js +158 -0
  32. package/dist/cjs/keyboard/parseKeyDef.js +58 -0
  33. package/dist/cjs/options.js +42 -0
  34. package/dist/cjs/package.json +3 -0
  35. package/dist/cjs/pointer/index.js +88 -0
  36. package/dist/cjs/pointer/keyMap.js +35 -0
  37. package/dist/cjs/pointer/parseKeyDef.js +39 -0
  38. package/dist/cjs/setup/api.js +35 -0
  39. package/dist/cjs/setup/config.js +7 -0
  40. package/dist/cjs/setup/directApi.js +77 -0
  41. package/dist/cjs/setup/index.js +15 -0
  42. package/dist/cjs/setup/setup.js +97 -0
  43. package/dist/cjs/setup/wrapAsync.js +13 -0
  44. package/dist/cjs/system/index.js +31 -0
  45. package/dist/cjs/system/keyboard.js +135 -0
  46. package/dist/cjs/system/pointer/buttons.js +71 -0
  47. package/dist/cjs/system/pointer/device.js +21 -0
  48. package/dist/cjs/system/pointer/index.js +146 -0
  49. package/dist/cjs/system/pointer/mouse.js +186 -0
  50. package/dist/cjs/system/pointer/pointer.js +114 -0
  51. package/dist/cjs/utility/clear.js +42 -0
  52. package/dist/cjs/utility/index.js +16 -0
  53. package/dist/cjs/utility/selectOptions.js +125 -0
  54. package/dist/cjs/utility/type.js +41 -0
  55. package/dist/cjs/utility/upload.js +72 -0
  56. package/dist/cjs/utils/click/isClickableInput.js +22 -0
  57. package/dist/cjs/utils/dataTransfer/Blob.js +18 -0
  58. package/dist/cjs/utils/dataTransfer/Clipboard.js +168 -0
  59. package/dist/cjs/utils/dataTransfer/DataTransfer.js +124 -0
  60. package/dist/cjs/utils/dataTransfer/FileList.js +26 -0
  61. package/dist/cjs/utils/edit/buildTimeValue.js +36 -0
  62. package/dist/cjs/utils/edit/getValue.js +35 -0
  63. package/dist/cjs/utils/edit/input.js +162 -0
  64. package/dist/cjs/utils/edit/isContentEditable.js +20 -0
  65. package/dist/cjs/utils/edit/isEditable.js +35 -0
  66. package/dist/cjs/utils/edit/isValidDateOrTimeValue.js +11 -0
  67. package/dist/cjs/utils/edit/maxLength.js +38 -0
  68. package/dist/cjs/utils/edit/setFiles.js +59 -0
  69. package/dist/cjs/utils/edit/walkRadio.js +28 -0
  70. package/dist/cjs/utils/focus/blur.js +16 -0
  71. package/dist/cjs/utils/focus/copySelection.js +46 -0
  72. package/dist/cjs/utils/focus/cursor.js +143 -0
  73. package/dist/cjs/utils/focus/focus.js +26 -0
  74. package/dist/cjs/utils/focus/getActiveElement.js +24 -0
  75. package/dist/cjs/utils/focus/getTabDestination.js +82 -0
  76. package/dist/cjs/utils/focus/isFocusable.js +11 -0
  77. package/dist/cjs/utils/focus/resolveCaretPosition.js +78 -0
  78. package/dist/cjs/utils/focus/selectAll.js +54 -0
  79. package/dist/cjs/utils/focus/selection.js +287 -0
  80. package/dist/cjs/utils/focus/selector.js +16 -0
  81. package/dist/cjs/utils/index.js +108 -0
  82. package/dist/cjs/utils/keyDef/readNextDescriptor.js +92 -0
  83. package/dist/cjs/utils/misc/cloneEvent.js +9 -0
  84. package/dist/cjs/utils/misc/dom-helpers.d.js +2 -0
  85. package/dist/cjs/utils/misc/eventWrapper.js +15 -0
  86. package/dist/cjs/utils/misc/findClosest.js +16 -0
  87. package/dist/cjs/utils/misc/getDocumentFromNode.js +12 -0
  88. package/dist/cjs/utils/misc/getTreeDiff.js +27 -0
  89. package/dist/cjs/utils/misc/getWindow.js +11 -0
  90. package/dist/cjs/utils/misc/isDescendantOrSelf.js +16 -0
  91. package/dist/cjs/utils/misc/isDisabled.js +34 -0
  92. package/dist/cjs/utils/misc/isElementType.js +22 -0
  93. package/dist/cjs/utils/misc/isVisible.js +21 -0
  94. package/dist/cjs/utils/misc/level.js +20 -0
  95. package/dist/cjs/utils/misc/wait.js +16 -0
  96. package/dist/cjs/utils/pointer/cssPointerEvents.js +111 -0
  97. package/dist/esm/clipboard/copy.js +36 -0
  98. package/dist/esm/clipboard/cut.js +36 -0
  99. package/dist/esm/clipboard/index.js +3 -0
  100. package/dist/esm/clipboard/paste.js +37 -0
  101. package/dist/esm/convenience/click.js +34 -0
  102. package/dist/esm/convenience/hover.js +32 -0
  103. package/dist/esm/convenience/index.js +3 -0
  104. package/dist/esm/convenience/tab.js +5 -0
  105. package/dist/esm/document/index.js +66 -0
  106. package/dist/esm/document/interceptor.js +26 -0
  107. package/dist/esm/document/selection.js +99 -0
  108. package/dist/esm/document/setRangeText.js +17 -0
  109. package/dist/esm/document/value.js +115 -0
  110. package/dist/esm/event/behavior/click.js +40 -0
  111. package/dist/esm/event/behavior/cut.js +24 -0
  112. package/dist/esm/event/behavior/index.js +7 -0
  113. package/dist/esm/event/behavior/keydown.js +132 -0
  114. package/dist/esm/event/behavior/keypress.js +56 -0
  115. package/dist/esm/event/behavior/keyup.js +22 -0
  116. package/dist/esm/event/behavior/paste.js +27 -0
  117. package/dist/esm/event/behavior/registry.js +3 -0
  118. package/dist/esm/event/createEvent.js +189 -0
  119. package/dist/esm/event/dispatchEvent.js +33 -0
  120. package/dist/esm/event/dom-events.d.js +1 -0
  121. package/dist/esm/event/eventMap.js +57 -0
  122. package/dist/esm/event/index.js +19 -0
  123. package/dist/esm/event/types.js +1 -0
  124. package/dist/esm/event/wrapEvent.js +7 -0
  125. package/dist/esm/index.js +2 -0
  126. package/dist/esm/keyboard/index.js +54 -0
  127. package/dist/esm/keyboard/keyMap.js +154 -0
  128. package/dist/esm/keyboard/parseKeyDef.js +54 -0
  129. package/dist/esm/options.js +37 -0
  130. package/dist/esm/package.json +3 -0
  131. package/dist/esm/pointer/index.js +84 -0
  132. package/dist/esm/pointer/keyMap.js +31 -0
  133. package/dist/esm/pointer/parseKeyDef.js +35 -0
  134. package/dist/esm/setup/api.js +12 -0
  135. package/dist/esm/setup/config.js +3 -0
  136. package/dist/esm/setup/directApi.js +58 -0
  137. package/dist/esm/setup/index.js +10 -0
  138. package/dist/esm/setup/setup.js +90 -0
  139. package/dist/esm/setup/wrapAsync.js +9 -0
  140. package/dist/esm/system/index.js +27 -0
  141. package/dist/esm/system/keyboard.js +131 -0
  142. package/dist/esm/system/pointer/buttons.js +63 -0
  143. package/dist/esm/system/pointer/device.js +17 -0
  144. package/dist/esm/system/pointer/index.js +141 -0
  145. package/dist/esm/system/pointer/mouse.js +182 -0
  146. package/dist/esm/system/pointer/pointer.js +110 -0
  147. package/dist/esm/utility/clear.js +38 -0
  148. package/dist/esm/utility/index.js +4 -0
  149. package/dist/esm/utility/selectOptions.js +120 -0
  150. package/dist/esm/utility/type.js +37 -0
  151. package/dist/esm/utility/upload.js +68 -0
  152. package/dist/esm/utils/click/isClickableInput.js +18 -0
  153. package/dist/esm/utils/dataTransfer/Blob.js +14 -0
  154. package/dist/esm/utils/dataTransfer/Clipboard.js +159 -0
  155. package/dist/esm/utils/dataTransfer/DataTransfer.js +119 -0
  156. package/dist/esm/utils/dataTransfer/FileList.js +22 -0
  157. package/dist/esm/utils/edit/buildTimeValue.js +32 -0
  158. package/dist/esm/utils/edit/getValue.js +31 -0
  159. package/dist/esm/utils/edit/input.js +158 -0
  160. package/dist/esm/utils/edit/isContentEditable.js +15 -0
  161. package/dist/esm/utils/edit/isEditable.js +30 -0
  162. package/dist/esm/utils/edit/isValidDateOrTimeValue.js +7 -0
  163. package/dist/esm/utils/edit/maxLength.js +34 -0
  164. package/dist/esm/utils/edit/setFiles.js +55 -0
  165. package/dist/esm/utils/edit/walkRadio.js +24 -0
  166. package/dist/esm/utils/focus/blur.js +12 -0
  167. package/dist/esm/utils/focus/copySelection.js +42 -0
  168. package/dist/esm/utils/focus/cursor.js +139 -0
  169. package/dist/esm/utils/focus/focus.js +22 -0
  170. package/dist/esm/utils/focus/getActiveElement.js +19 -0
  171. package/dist/esm/utils/focus/getTabDestination.js +78 -0
  172. package/dist/esm/utils/focus/isFocusable.js +7 -0
  173. package/dist/esm/utils/focus/resolveCaretPosition.js +74 -0
  174. package/dist/esm/utils/focus/selectAll.js +49 -0
  175. package/dist/esm/utils/focus/selection.js +274 -0
  176. package/dist/esm/utils/focus/selector.js +12 -0
  177. package/dist/esm/utils/index.js +36 -0
  178. package/dist/esm/utils/keyDef/readNextDescriptor.js +88 -0
  179. package/dist/esm/utils/misc/cloneEvent.js +5 -0
  180. package/dist/esm/utils/misc/dom-helpers.d.js +1 -0
  181. package/dist/esm/utils/misc/eventWrapper.js +11 -0
  182. package/dist/esm/utils/misc/findClosest.js +12 -0
  183. package/dist/esm/utils/misc/getDocumentFromNode.js +8 -0
  184. package/dist/esm/utils/misc/getTreeDiff.js +23 -0
  185. package/dist/esm/utils/misc/getWindow.js +7 -0
  186. package/dist/esm/utils/misc/isDescendantOrSelf.js +12 -0
  187. package/dist/esm/utils/misc/isDisabled.js +30 -0
  188. package/dist/esm/utils/misc/isElementType.js +18 -0
  189. package/dist/esm/utils/misc/isVisible.js +17 -0
  190. package/dist/esm/utils/misc/level.js +15 -0
  191. package/dist/esm/utils/misc/wait.js +12 -0
  192. package/dist/esm/utils/pointer/cssPointerEvents.js +106 -0
  193. package/dist/types/event/createEvent.d.ts +2 -8
  194. package/dist/types/event/eventMap.d.ts +204 -181
  195. package/dist/types/event/index.d.ts +1 -2
  196. package/dist/types/event/types.d.ts +6 -0
  197. package/dist/types/index.d.ts +2 -2
  198. package/dist/types/keyboard/index.d.ts +2 -6
  199. package/dist/types/keyboard/keyMap.d.ts +1 -1
  200. package/dist/types/keyboard/parseKeyDef.d.ts +1 -1
  201. package/dist/types/options.d.ts +4 -4
  202. package/dist/types/pointer/index.d.ts +23 -5
  203. package/dist/types/pointer/keyMap.d.ts +1 -1
  204. package/dist/types/pointer/parseKeyDef.d.ts +1 -1
  205. package/dist/types/setup/config.d.ts +3 -7
  206. package/dist/types/setup/directApi.d.ts +21 -16
  207. package/dist/types/setup/index.d.ts +1 -2
  208. package/dist/types/setup/setup.d.ts +7 -1
  209. package/dist/types/system/index.d.ts +10 -0
  210. package/dist/types/system/keyboard.d.ts +53 -0
  211. package/dist/types/system/pointer/buttons.d.ts +23 -0
  212. package/dist/types/system/pointer/device.d.ts +8 -0
  213. package/dist/types/system/pointer/index.d.ts +39 -0
  214. package/dist/types/system/pointer/mouse.d.ts +26 -0
  215. package/dist/types/system/pointer/pointer.d.ts +30 -0
  216. package/dist/types/utils/click/isClickableInput.d.ts +15 -1
  217. package/dist/types/utils/focus/getActiveElement.d.ts +1 -0
  218. package/dist/types/utils/focus/resolveCaretPosition.d.ts +8 -0
  219. package/dist/types/utils/focus/selection.d.ts +28 -1
  220. package/dist/types/utils/index.d.ts +2 -3
  221. package/dist/types/utils/misc/getTreeDiff.d.ts +1 -0
  222. package/package.json +9 -15
  223. package/dist/index.cjs +0 -3104
  224. package/dist/index.mjs +0 -3155
  225. package/dist/types/event/eventTypes.d.ts +0 -2
  226. package/dist/types/keyboard/keyboardAction.d.ts +0 -10
  227. package/dist/types/keyboard/modifiers.d.ts +0 -9
  228. package/dist/types/keyboard/types.d.ts +0 -73
  229. package/dist/types/pointer/firePointerEvents.d.ts +0 -11
  230. package/dist/types/pointer/pointerAction.d.ts +0 -7
  231. package/dist/types/pointer/pointerMove.d.ts +0 -6
  232. package/dist/types/pointer/pointerPress.d.ts +0 -8
  233. package/dist/types/pointer/resolveSelectionTarget.d.ts +0 -5
  234. package/dist/types/pointer/types.d.ts +0 -62
  235. package/dist/types/utils/keyboard/getKeyEventProps.d.ts +0 -5
  236. package/dist/types/utils/keyboard/getUIEventModifiers.d.ts +0 -15
  237. package/dist/types/utils/pointer/mouseButtons.d.ts +0 -12
@@ -0,0 +1,57 @@
1
+ import { eventMap as eventMap$1 } from '@testing-library/dom/dist/event-map.js';
2
+
3
+ const eventMap = {
4
+ ...eventMap$1,
5
+ click: {
6
+ EventType: 'PointerEvent',
7
+ defaultInit: {
8
+ bubbles: true,
9
+ cancelable: true,
10
+ composed: true
11
+ }
12
+ },
13
+ auxclick: {
14
+ EventType: 'PointerEvent',
15
+ defaultInit: {
16
+ bubbles: true,
17
+ cancelable: true,
18
+ composed: true
19
+ }
20
+ },
21
+ contextmenu: {
22
+ EventType: 'PointerEvent',
23
+ defaultInit: {
24
+ bubbles: true,
25
+ cancelable: true,
26
+ composed: true
27
+ }
28
+ },
29
+ beforeInput: {
30
+ EventType: 'InputEvent',
31
+ defaultInit: {
32
+ bubbles: true,
33
+ cancelable: true,
34
+ composed: true
35
+ }
36
+ }
37
+ };
38
+ const eventMapKeys = Object.fromEntries(Object.keys(eventMap).map((k)=>[
39
+ k.toLowerCase(),
40
+ k
41
+ ]));
42
+ function getEventClass(type) {
43
+ const k = eventMapKeys[type];
44
+ return k && eventMap[k].EventType;
45
+ }
46
+ const mouseEvents = [
47
+ 'MouseEvent',
48
+ 'PointerEvent'
49
+ ];
50
+ function isMouseEvent(type) {
51
+ return mouseEvents.includes(getEventClass(type));
52
+ }
53
+ function isKeyboardEvent(type) {
54
+ return getEventClass(type) === 'KeyboardEvent';
55
+ }
56
+
57
+ export { eventMap, eventMapKeys, isKeyboardEvent, isMouseEvent };
@@ -0,0 +1,19 @@
1
+ import { createEvent } from './createEvent.js';
2
+ import { dispatchEvent } from './dispatchEvent.js';
3
+ import { isMouseEvent, isKeyboardEvent } from './eventMap.js';
4
+
5
+ function dispatchUIEvent(config, target, type, init, preventDefault = false) {
6
+ if (isMouseEvent(type) || isKeyboardEvent(type)) {
7
+ init = {
8
+ ...init,
9
+ ...config.system.getUIEventModifiers()
10
+ };
11
+ }
12
+ const event = createEvent(type, target, init);
13
+ return dispatchEvent(config, target, event, preventDefault);
14
+ }
15
+ function bindDispatchUIEvent(config) {
16
+ return dispatchUIEvent.bind(undefined, config);
17
+ }
18
+
19
+ export { bindDispatchUIEvent, dispatchUIEvent };
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,7 @@
1
+ import { getConfig } from '@testing-library/dom';
2
+
3
+ function wrapEvent(cb, _element) {
4
+ return getConfig().eventWrapper(cb);
5
+ }
6
+
7
+ export { wrapEvent };
@@ -0,0 +1,2 @@
1
+ export { userEvent as default } from './setup/index.js';
2
+ export { PointerEventsCheckLevel } from './options.js';
@@ -0,0 +1,54 @@
1
+ import '../setup/index.js';
2
+ import '../utils/click/isClickableInput.js';
3
+ 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
+ import '../utils/edit/isEditable.js';
14
+ import '@testing-library/dom/dist/helpers.js';
15
+ import '../utils/keyDef/readNextDescriptor.js';
16
+ import '../utils/misc/level.js';
17
+ import { wait } from '../utils/misc/wait.js';
18
+ import '../options.js';
19
+ import { parseKeyDef } from './parseKeyDef.js';
20
+ import { Config } from '../setup/config.js';
21
+
22
+ async function keyboard(text) {
23
+ const actions = parseKeyDef(this[Config].keyboardMap, text);
24
+ for(let i = 0; i < actions.length; i++){
25
+ await wait(this[Config]);
26
+ await keyboardAction(this[Config], actions[i]);
27
+ }
28
+ }
29
+ async function keyboardAction(config, { keyDef , releasePrevious , releaseSelf , repeat }) {
30
+ const { system } = config;
31
+ // Release the key automatically if it was pressed before.
32
+ if (system.keyboard.isKeyPressed(keyDef)) {
33
+ await system.keyboard.keyup(config, keyDef);
34
+ }
35
+ if (!releasePrevious) {
36
+ for(let i = 1; i <= repeat; i++){
37
+ await system.keyboard.keydown(config, keyDef);
38
+ if (i < repeat) {
39
+ await wait(config);
40
+ }
41
+ }
42
+ // Release the key only on the last iteration on `state.repeatKey`.
43
+ if (releaseSelf) {
44
+ await system.keyboard.keyup(config, keyDef);
45
+ }
46
+ }
47
+ }
48
+ async function releaseAllKeys(config) {
49
+ for (const k of config.system.keyboard.getPressedKeys()){
50
+ await config.system.keyboard.keyup(config, k);
51
+ }
52
+ }
53
+
54
+ export { keyboard, releaseAllKeys };
@@ -0,0 +1,154 @@
1
+ import { DOM_KEY_LOCATION } from '../system/keyboard.js';
2
+
3
+ /**
4
+ * Mapping for a default US-104-QWERTY keyboard
5
+ */ const defaultKeyMap = [
6
+ // alphanumeric keys
7
+ ...'0123456789'.split('').map((c)=>({
8
+ code: `Digit${c}`,
9
+ key: c
10
+ })),
11
+ ...')!@#$%^&*('.split('').map((c, i)=>({
12
+ code: `Digit${i}`,
13
+ key: c,
14
+ shiftKey: true
15
+ })),
16
+ ...'abcdefghijklmnopqrstuvwxyz'.split('').map((c)=>({
17
+ code: `Key${c.toUpperCase()}`,
18
+ key: c
19
+ })),
20
+ ...'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('').map((c)=>({
21
+ code: `Key${c}`,
22
+ key: c,
23
+ shiftKey: true
24
+ })),
25
+ // alphanumeric block - functional
26
+ {
27
+ code: 'Space',
28
+ key: ' '
29
+ },
30
+ {
31
+ code: 'AltLeft',
32
+ key: 'Alt',
33
+ location: DOM_KEY_LOCATION.LEFT
34
+ },
35
+ {
36
+ code: 'AltRight',
37
+ key: 'Alt',
38
+ location: DOM_KEY_LOCATION.RIGHT
39
+ },
40
+ {
41
+ code: 'ShiftLeft',
42
+ key: 'Shift',
43
+ location: DOM_KEY_LOCATION.LEFT
44
+ },
45
+ {
46
+ code: 'ShiftRight',
47
+ key: 'Shift',
48
+ location: DOM_KEY_LOCATION.RIGHT
49
+ },
50
+ {
51
+ code: 'ControlLeft',
52
+ key: 'Control',
53
+ location: DOM_KEY_LOCATION.LEFT
54
+ },
55
+ {
56
+ code: 'ControlRight',
57
+ key: 'Control',
58
+ location: DOM_KEY_LOCATION.RIGHT
59
+ },
60
+ {
61
+ code: 'MetaLeft',
62
+ key: 'Meta',
63
+ location: DOM_KEY_LOCATION.LEFT
64
+ },
65
+ {
66
+ code: 'MetaRight',
67
+ key: 'Meta',
68
+ location: DOM_KEY_LOCATION.RIGHT
69
+ },
70
+ {
71
+ code: 'OSLeft',
72
+ key: 'OS',
73
+ location: DOM_KEY_LOCATION.LEFT
74
+ },
75
+ {
76
+ code: 'OSRight',
77
+ key: 'OS',
78
+ location: DOM_KEY_LOCATION.RIGHT
79
+ },
80
+ {
81
+ code: 'Tab',
82
+ key: 'Tab'
83
+ },
84
+ {
85
+ code: 'CapsLock',
86
+ key: 'CapsLock'
87
+ },
88
+ {
89
+ code: 'Backspace',
90
+ key: 'Backspace'
91
+ },
92
+ {
93
+ code: 'Enter',
94
+ key: 'Enter'
95
+ },
96
+ // function
97
+ {
98
+ code: 'Escape',
99
+ key: 'Escape'
100
+ },
101
+ // arrows
102
+ {
103
+ code: 'ArrowUp',
104
+ key: 'ArrowUp'
105
+ },
106
+ {
107
+ code: 'ArrowDown',
108
+ key: 'ArrowDown'
109
+ },
110
+ {
111
+ code: 'ArrowLeft',
112
+ key: 'ArrowLeft'
113
+ },
114
+ {
115
+ code: 'ArrowRight',
116
+ key: 'ArrowRight'
117
+ },
118
+ // control pad
119
+ {
120
+ code: 'Home',
121
+ key: 'Home'
122
+ },
123
+ {
124
+ code: 'End',
125
+ key: 'End'
126
+ },
127
+ {
128
+ code: 'Delete',
129
+ key: 'Delete'
130
+ },
131
+ {
132
+ code: 'PageUp',
133
+ key: 'PageUp'
134
+ },
135
+ {
136
+ code: 'PageDown',
137
+ key: 'PageDown'
138
+ },
139
+ // Special keys that are not part of a default US-layout but included for specific behavior
140
+ {
141
+ code: 'Fn',
142
+ key: 'Fn'
143
+ },
144
+ {
145
+ code: 'Symbol',
146
+ key: 'Symbol'
147
+ },
148
+ {
149
+ code: 'AltRight',
150
+ key: 'AltGraph'
151
+ }
152
+ ];
153
+
154
+ export { defaultKeyMap };
@@ -0,0 +1,54 @@
1
+ import '../utils/click/isClickableInput.js';
2
+ import '../utils/dataTransfer/Clipboard.js';
3
+ import '../event/eventMap.js';
4
+ import '../event/behavior/click.js';
5
+ import '../event/behavior/cut.js';
6
+ import '../event/behavior/keydown.js';
7
+ import '../event/behavior/keypress.js';
8
+ import '../event/behavior/keyup.js';
9
+ import '../event/behavior/paste.js';
10
+ import '@testing-library/dom';
11
+ import '../utils/edit/maxLength.js';
12
+ import '../utils/edit/isEditable.js';
13
+ import '@testing-library/dom/dist/helpers.js';
14
+ import { readNextDescriptor } from '../utils/keyDef/readNextDescriptor.js';
15
+ import '../utils/misc/level.js';
16
+ import '../options.js';
17
+
18
+ /**
19
+ * Parse key defintions per `keyboardMap`
20
+ *
21
+ * Keys can be referenced by `{key}` or `{special}` as well as physical locations per `[code]`.
22
+ * Everything else will be interpreted as a typed character - e.g. `a`.
23
+ * Brackets `{` and `[` can be escaped by doubling - e.g. `foo[[bar` translates to `foo[bar`.
24
+ * Keeping the key pressed can be written as `{key>}`.
25
+ * When keeping the key pressed you can choose how long (how many keydown and keypress) the key is pressed `{key>3}`.
26
+ * You can then release the key per `{key>3/}` or keep it pressed and continue with the next key.
27
+ */ function parseKeyDef(keyboardMap, text) {
28
+ const defs = [];
29
+ do {
30
+ const { type , descriptor , consumedLength , releasePrevious , releaseSelf =true , repeat , } = readNextDescriptor(text, 'keyboard');
31
+ const keyDef = keyboardMap.find((def)=>{
32
+ if (type === '[') {
33
+ return def.code?.toLowerCase() === descriptor.toLowerCase();
34
+ } else if (type === '{') {
35
+ return def.key?.toLowerCase() === descriptor.toLowerCase();
36
+ }
37
+ return def.key === descriptor;
38
+ }) ?? {
39
+ key: 'Unknown',
40
+ code: 'Unknown',
41
+ [type === '[' ? 'code' : 'key']: descriptor
42
+ };
43
+ defs.push({
44
+ keyDef,
45
+ releasePrevious,
46
+ releaseSelf,
47
+ repeat
48
+ });
49
+ text = text.slice(consumedLength);
50
+ }while (text)
51
+ return defs;
52
+ }
53
+
54
+ export { parseKeyDef };
@@ -0,0 +1,37 @@
1
+ import { defaultKeyMap } from './keyboard/keyMap.js';
2
+ import { defaultKeyMap as defaultKeyMap$1 } from './pointer/keyMap.js';
3
+
4
+ var PointerEventsCheckLevel;
5
+ (function(PointerEventsCheckLevel) {
6
+ PointerEventsCheckLevel[PointerEventsCheckLevel[/**
7
+ * Check pointer events on every user interaction that triggers a bunch of events.
8
+ * E.g. once for releasing a mouse button even though this triggers `pointerup`, `mouseup`, `click`, etc...
9
+ */ "EachTrigger"] = 4] = "EachTrigger";
10
+ PointerEventsCheckLevel[PointerEventsCheckLevel[/** Check each target once per call to pointer (related) API */ "EachApiCall"] = 2] = "EachApiCall";
11
+ PointerEventsCheckLevel[PointerEventsCheckLevel[/** Check each event target once */ "EachTarget"] = 1] = "EachTarget";
12
+ PointerEventsCheckLevel[PointerEventsCheckLevel[/** No pointer events check */ "Never"] = 0] = "Never";
13
+ })(PointerEventsCheckLevel || (PointerEventsCheckLevel = {}));
14
+ /**
15
+ * Default options applied when API is called per `userEvent.anyApi()`
16
+ */ const defaultOptionsDirect = {
17
+ applyAccept: true,
18
+ autoModify: true,
19
+ delay: 0,
20
+ document: globalThis.document,
21
+ keyboardMap: defaultKeyMap,
22
+ pointerMap: defaultKeyMap$1,
23
+ pointerEventsCheck: PointerEventsCheckLevel.EachApiCall,
24
+ skipAutoClose: false,
25
+ skipClick: false,
26
+ skipHover: false,
27
+ writeToClipboard: false,
28
+ advanceTimers: ()=>Promise.resolve()
29
+ };
30
+ /**
31
+ * Default options applied when API is called per `userEvent().anyApi()`
32
+ */ const defaultOptionsSetup = {
33
+ ...defaultOptionsDirect,
34
+ writeToClipboard: true
35
+ };
36
+
37
+ export { PointerEventsCheckLevel, defaultOptionsDirect, defaultOptionsSetup };
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,84 @@
1
+ import '../setup/index.js';
2
+ import '../utils/click/isClickableInput.js';
3
+ 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
+ import '../utils/edit/isEditable.js';
14
+ import '@testing-library/dom/dist/helpers.js';
15
+ import '../utils/keyDef/readNextDescriptor.js';
16
+ import { setLevelRef, ApiLevel } from '../utils/misc/level.js';
17
+ import { wait } from '../utils/misc/wait.js';
18
+ import '../options.js';
19
+ import { parseKeyDef } from './parseKeyDef.js';
20
+ import { Config } from '../setup/config.js';
21
+
22
+ async function pointer(input) {
23
+ const { pointerMap } = this[Config];
24
+ const actions = [];
25
+ (Array.isArray(input) ? input : [
26
+ input
27
+ ]).forEach((actionInput)=>{
28
+ if (typeof actionInput === 'string') {
29
+ actions.push(...parseKeyDef(pointerMap, actionInput));
30
+ } else if ('keys' in actionInput) {
31
+ actions.push(...parseKeyDef(pointerMap, actionInput.keys).map((i)=>({
32
+ ...actionInput,
33
+ ...i
34
+ })));
35
+ } else {
36
+ actions.push(actionInput);
37
+ }
38
+ });
39
+ for(let i = 0; i < actions.length; i++){
40
+ await wait(this[Config]);
41
+ await pointerAction(this[Config], actions[i]);
42
+ }
43
+ this[Config].system.pointer.resetClickCount();
44
+ }
45
+ async function pointerAction(config, action) {
46
+ const pointerName = 'pointerName' in action && action.pointerName ? action.pointerName : 'keyDef' in action ? config.system.pointer.getPointerName(action.keyDef) : 'mouse';
47
+ const previousPosition = config.system.pointer.getPreviousPosition(pointerName);
48
+ const position = {
49
+ target: action.target ?? getPrevTarget(config, previousPosition),
50
+ coords: action.coords ?? previousPosition?.coords,
51
+ caret: {
52
+ node: action.node ?? (hasCaretPosition(action) ? undefined : previousPosition?.caret?.node),
53
+ offset: action.offset ?? (hasCaretPosition(action) ? undefined : previousPosition?.caret?.offset)
54
+ }
55
+ };
56
+ if ('keyDef' in action) {
57
+ if (config.system.pointer.isKeyPressed(action.keyDef)) {
58
+ setLevelRef(config, ApiLevel.Trigger);
59
+ await config.system.pointer.release(config, action.keyDef, position);
60
+ }
61
+ if (!action.releasePrevious) {
62
+ setLevelRef(config, ApiLevel.Trigger);
63
+ await config.system.pointer.press(config, action.keyDef, position);
64
+ if (action.releaseSelf) {
65
+ setLevelRef(config, ApiLevel.Trigger);
66
+ await config.system.pointer.release(config, action.keyDef, position);
67
+ }
68
+ }
69
+ } else {
70
+ setLevelRef(config, ApiLevel.Trigger);
71
+ await config.system.pointer.move(config, pointerName, position);
72
+ }
73
+ }
74
+ function hasCaretPosition(action) {
75
+ return !!((action.target ?? action.node) ?? action.offset !== undefined);
76
+ }
77
+ function getPrevTarget(config, position) {
78
+ if (!position) {
79
+ throw new Error('This pointer has no previous position. Provide a target property!');
80
+ }
81
+ return position.target ?? config.document.body;
82
+ }
83
+
84
+ export { pointer };
@@ -0,0 +1,31 @@
1
+ const defaultKeyMap = [
2
+ {
3
+ name: 'MouseLeft',
4
+ pointerType: 'mouse',
5
+ button: 'primary'
6
+ },
7
+ {
8
+ name: 'MouseRight',
9
+ pointerType: 'mouse',
10
+ button: 'secondary'
11
+ },
12
+ {
13
+ name: 'MouseMiddle',
14
+ pointerType: 'mouse',
15
+ button: 'auxiliary'
16
+ },
17
+ {
18
+ name: 'TouchA',
19
+ pointerType: 'touch'
20
+ },
21
+ {
22
+ name: 'TouchB',
23
+ pointerType: 'touch'
24
+ },
25
+ {
26
+ name: 'TouchC',
27
+ pointerType: 'touch'
28
+ },
29
+ ];
30
+
31
+ export { defaultKeyMap };
@@ -0,0 +1,35 @@
1
+ import '../utils/click/isClickableInput.js';
2
+ import '../utils/dataTransfer/Clipboard.js';
3
+ import '../event/eventMap.js';
4
+ import '../event/behavior/click.js';
5
+ import '../event/behavior/cut.js';
6
+ import '../event/behavior/keydown.js';
7
+ import '../event/behavior/keypress.js';
8
+ import '../event/behavior/keyup.js';
9
+ import '../event/behavior/paste.js';
10
+ import '@testing-library/dom';
11
+ import '../utils/edit/maxLength.js';
12
+ import '../utils/edit/isEditable.js';
13
+ import '@testing-library/dom/dist/helpers.js';
14
+ import { readNextDescriptor } from '../utils/keyDef/readNextDescriptor.js';
15
+ import '../utils/misc/level.js';
16
+ import '../options.js';
17
+
18
+ function parseKeyDef(pointerMap, keys) {
19
+ const defs = [];
20
+ do {
21
+ const { descriptor , consumedLength , releasePrevious , releaseSelf =true , } = readNextDescriptor(keys, 'pointer');
22
+ const keyDef = pointerMap.find((p)=>p.name === descriptor);
23
+ if (keyDef) {
24
+ defs.push({
25
+ keyDef,
26
+ releasePrevious,
27
+ releaseSelf
28
+ });
29
+ }
30
+ keys = keys.slice(consumedLength);
31
+ }while (keys)
32
+ return defs;
33
+ }
34
+
35
+ export { parseKeyDef };
@@ -0,0 +1,12 @@
1
+ export { click, dblClick, tripleClick } from '../convenience/click.js';
2
+ export { hover, unhover } from '../convenience/hover.js';
3
+ export { tab } from '../convenience/tab.js';
4
+ export { keyboard } from '../keyboard/index.js';
5
+ export { copy } from '../clipboard/copy.js';
6
+ export { cut } from '../clipboard/cut.js';
7
+ export { paste } from '../clipboard/paste.js';
8
+ export { pointer } from '../pointer/index.js';
9
+ export { clear } from '../utility/clear.js';
10
+ export { deselectOptions, selectOptions } from '../utility/selectOptions.js';
11
+ export { type } from '../utility/type.js';
12
+ export { upload } from '../utility/upload.js';
@@ -0,0 +1,3 @@
1
+ const Config = Symbol('Config');
2
+
3
+ export { Config };
@@ -0,0 +1,58 @@
1
+ import { setupDirect } from './setup.js';
2
+
3
+ function clear(element) {
4
+ return setupDirect().api.clear(element);
5
+ }
6
+ function click(element, options = {}) {
7
+ return setupDirect(options, element).api.click(element);
8
+ }
9
+ function copy(options = {}) {
10
+ return setupDirect(options).api.copy();
11
+ }
12
+ function cut(options = {}) {
13
+ return setupDirect(options).api.cut();
14
+ }
15
+ function dblClick(element, options = {}) {
16
+ return setupDirect(options).api.dblClick(element);
17
+ }
18
+ function deselectOptions(select, values, options = {}) {
19
+ return setupDirect(options).api.deselectOptions(select, values);
20
+ }
21
+ function hover(element, options = {}) {
22
+ return setupDirect(options).api.hover(element);
23
+ }
24
+ async function keyboard(text, options = {}) {
25
+ const { config , api } = setupDirect(options);
26
+ return api.keyboard(text).then(()=>config.system);
27
+ }
28
+ async function pointer(input, options = {}) {
29
+ const { config , api } = setupDirect(options);
30
+ return api.pointer(input).then(()=>config.system);
31
+ }
32
+ function paste(clipboardData, options) {
33
+ return setupDirect(options).api.paste(clipboardData);
34
+ }
35
+ function selectOptions(select, values, options = {}) {
36
+ return setupDirect(options).api.selectOptions(select, values);
37
+ }
38
+ function tripleClick(element, options = {}) {
39
+ return setupDirect(options).api.tripleClick(element);
40
+ }
41
+ function type(element, text, options = {}) {
42
+ return setupDirect(options, element).api.type(element, text, options);
43
+ }
44
+ function unhover(element, options = {}) {
45
+ const { config , api } = setupDirect(options);
46
+ config.system.pointer.setMousePosition({
47
+ target: element
48
+ });
49
+ return api.unhover(element);
50
+ }
51
+ function upload(element, fileOrFiles, options = {}) {
52
+ return setupDirect(options).api.upload(element, fileOrFiles);
53
+ }
54
+ function tab(options = {}) {
55
+ return setupDirect().api.tab(options);
56
+ }
57
+
58
+ export { clear, click, copy, cut, dblClick, deselectOptions, hover, keyboard, paste, pointer, selectOptions, tab, tripleClick, type, unhover, upload };
@@ -0,0 +1,10 @@
1
+ import { setupMain } from './setup.js';
2
+ export { Config } from './config.js';
3
+ import * as directApi from './directApi.js';
4
+
5
+ const userEvent = {
6
+ ...directApi,
7
+ setup: setupMain
8
+ };
9
+
10
+ export { userEvent };