@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,59 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('../setup/index.js');
6
+ require('../utils/click/isClickableInput.js');
7
+ require('../utils/dataTransfer/Clipboard.js');
8
+ require('../event/eventMap.js');
9
+ require('../event/behavior/click.js');
10
+ require('../event/behavior/cut.js');
11
+ require('../event/behavior/keydown.js');
12
+ require('../event/behavior/keypress.js');
13
+ require('../event/behavior/keyup.js');
14
+ require('../event/behavior/paste.js');
15
+ require('@testing-library/dom');
16
+ require('../utils/edit/maxLength.js');
17
+ require('../utils/edit/isEditable.js');
18
+ require('@testing-library/dom/dist/helpers.js');
19
+ require('../utils/keyDef/readNextDescriptor.js');
20
+ require('../utils/misc/level.js');
21
+ var wait = require('../utils/misc/wait.js');
22
+ require('../options.js');
23
+ var parseKeyDef = require('./parseKeyDef.js');
24
+ var config = require('../setup/config.js');
25
+
26
+ async function keyboard(text) {
27
+ const actions = parseKeyDef.parseKeyDef(this[config.Config].keyboardMap, text);
28
+ for(let i = 0; i < actions.length; i++){
29
+ await wait.wait(this[config.Config]);
30
+ await keyboardAction(this[config.Config], actions[i]);
31
+ }
32
+ }
33
+ async function keyboardAction(config, { keyDef , releasePrevious , releaseSelf , repeat }) {
34
+ const { system } = config;
35
+ // Release the key automatically if it was pressed before.
36
+ if (system.keyboard.isKeyPressed(keyDef)) {
37
+ await system.keyboard.keyup(config, keyDef);
38
+ }
39
+ if (!releasePrevious) {
40
+ for(let i = 1; i <= repeat; i++){
41
+ await system.keyboard.keydown(config, keyDef);
42
+ if (i < repeat) {
43
+ await wait.wait(config);
44
+ }
45
+ }
46
+ // Release the key only on the last iteration on `state.repeatKey`.
47
+ if (releaseSelf) {
48
+ await system.keyboard.keyup(config, keyDef);
49
+ }
50
+ }
51
+ }
52
+ async function releaseAllKeys(config) {
53
+ for (const k of config.system.keyboard.getPressedKeys()){
54
+ await config.system.keyboard.keyup(config, k);
55
+ }
56
+ }
57
+
58
+ exports.keyboard = keyboard;
59
+ exports.releaseAllKeys = releaseAllKeys;
@@ -0,0 +1,158 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var keyboard = require('../system/keyboard.js');
6
+
7
+ /**
8
+ * Mapping for a default US-104-QWERTY keyboard
9
+ */ const defaultKeyMap = [
10
+ // alphanumeric keys
11
+ ...'0123456789'.split('').map((c)=>({
12
+ code: `Digit${c}`,
13
+ key: c
14
+ })),
15
+ ...')!@#$%^&*('.split('').map((c, i)=>({
16
+ code: `Digit${i}`,
17
+ key: c,
18
+ shiftKey: true
19
+ })),
20
+ ...'abcdefghijklmnopqrstuvwxyz'.split('').map((c)=>({
21
+ code: `Key${c.toUpperCase()}`,
22
+ key: c
23
+ })),
24
+ ...'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('').map((c)=>({
25
+ code: `Key${c}`,
26
+ key: c,
27
+ shiftKey: true
28
+ })),
29
+ // alphanumeric block - functional
30
+ {
31
+ code: 'Space',
32
+ key: ' '
33
+ },
34
+ {
35
+ code: 'AltLeft',
36
+ key: 'Alt',
37
+ location: keyboard.DOM_KEY_LOCATION.LEFT
38
+ },
39
+ {
40
+ code: 'AltRight',
41
+ key: 'Alt',
42
+ location: keyboard.DOM_KEY_LOCATION.RIGHT
43
+ },
44
+ {
45
+ code: 'ShiftLeft',
46
+ key: 'Shift',
47
+ location: keyboard.DOM_KEY_LOCATION.LEFT
48
+ },
49
+ {
50
+ code: 'ShiftRight',
51
+ key: 'Shift',
52
+ location: keyboard.DOM_KEY_LOCATION.RIGHT
53
+ },
54
+ {
55
+ code: 'ControlLeft',
56
+ key: 'Control',
57
+ location: keyboard.DOM_KEY_LOCATION.LEFT
58
+ },
59
+ {
60
+ code: 'ControlRight',
61
+ key: 'Control',
62
+ location: keyboard.DOM_KEY_LOCATION.RIGHT
63
+ },
64
+ {
65
+ code: 'MetaLeft',
66
+ key: 'Meta',
67
+ location: keyboard.DOM_KEY_LOCATION.LEFT
68
+ },
69
+ {
70
+ code: 'MetaRight',
71
+ key: 'Meta',
72
+ location: keyboard.DOM_KEY_LOCATION.RIGHT
73
+ },
74
+ {
75
+ code: 'OSLeft',
76
+ key: 'OS',
77
+ location: keyboard.DOM_KEY_LOCATION.LEFT
78
+ },
79
+ {
80
+ code: 'OSRight',
81
+ key: 'OS',
82
+ location: keyboard.DOM_KEY_LOCATION.RIGHT
83
+ },
84
+ {
85
+ code: 'Tab',
86
+ key: 'Tab'
87
+ },
88
+ {
89
+ code: 'CapsLock',
90
+ key: 'CapsLock'
91
+ },
92
+ {
93
+ code: 'Backspace',
94
+ key: 'Backspace'
95
+ },
96
+ {
97
+ code: 'Enter',
98
+ key: 'Enter'
99
+ },
100
+ // function
101
+ {
102
+ code: 'Escape',
103
+ key: 'Escape'
104
+ },
105
+ // arrows
106
+ {
107
+ code: 'ArrowUp',
108
+ key: 'ArrowUp'
109
+ },
110
+ {
111
+ code: 'ArrowDown',
112
+ key: 'ArrowDown'
113
+ },
114
+ {
115
+ code: 'ArrowLeft',
116
+ key: 'ArrowLeft'
117
+ },
118
+ {
119
+ code: 'ArrowRight',
120
+ key: 'ArrowRight'
121
+ },
122
+ // control pad
123
+ {
124
+ code: 'Home',
125
+ key: 'Home'
126
+ },
127
+ {
128
+ code: 'End',
129
+ key: 'End'
130
+ },
131
+ {
132
+ code: 'Delete',
133
+ key: 'Delete'
134
+ },
135
+ {
136
+ code: 'PageUp',
137
+ key: 'PageUp'
138
+ },
139
+ {
140
+ code: 'PageDown',
141
+ key: 'PageDown'
142
+ },
143
+ // Special keys that are not part of a default US-layout but included for specific behavior
144
+ {
145
+ code: 'Fn',
146
+ key: 'Fn'
147
+ },
148
+ {
149
+ code: 'Symbol',
150
+ key: 'Symbol'
151
+ },
152
+ {
153
+ code: 'AltRight',
154
+ key: 'AltGraph'
155
+ }
156
+ ];
157
+
158
+ exports.defaultKeyMap = defaultKeyMap;
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('../utils/click/isClickableInput.js');
6
+ require('../utils/dataTransfer/Clipboard.js');
7
+ require('../event/eventMap.js');
8
+ require('../event/behavior/click.js');
9
+ require('../event/behavior/cut.js');
10
+ require('../event/behavior/keydown.js');
11
+ require('../event/behavior/keypress.js');
12
+ require('../event/behavior/keyup.js');
13
+ require('../event/behavior/paste.js');
14
+ require('@testing-library/dom');
15
+ require('../utils/edit/maxLength.js');
16
+ require('../utils/edit/isEditable.js');
17
+ require('@testing-library/dom/dist/helpers.js');
18
+ var readNextDescriptor = require('../utils/keyDef/readNextDescriptor.js');
19
+ require('../utils/misc/level.js');
20
+ require('../options.js');
21
+
22
+ /**
23
+ * Parse key defintions per `keyboardMap`
24
+ *
25
+ * Keys can be referenced by `{key}` or `{special}` as well as physical locations per `[code]`.
26
+ * Everything else will be interpreted as a typed character - e.g. `a`.
27
+ * Brackets `{` and `[` can be escaped by doubling - e.g. `foo[[bar` translates to `foo[bar`.
28
+ * Keeping the key pressed can be written as `{key>}`.
29
+ * When keeping the key pressed you can choose how long (how many keydown and keypress) the key is pressed `{key>3}`.
30
+ * You can then release the key per `{key>3/}` or keep it pressed and continue with the next key.
31
+ */ function parseKeyDef(keyboardMap, text) {
32
+ const defs = [];
33
+ do {
34
+ const { type , descriptor , consumedLength , releasePrevious , releaseSelf =true , repeat , } = readNextDescriptor.readNextDescriptor(text, 'keyboard');
35
+ const keyDef = keyboardMap.find((def)=>{
36
+ if (type === '[') {
37
+ return def.code?.toLowerCase() === descriptor.toLowerCase();
38
+ } else if (type === '{') {
39
+ return def.key?.toLowerCase() === descriptor.toLowerCase();
40
+ }
41
+ return def.key === descriptor;
42
+ }) ?? {
43
+ key: 'Unknown',
44
+ code: 'Unknown',
45
+ [type === '[' ? 'code' : 'key']: descriptor
46
+ };
47
+ defs.push({
48
+ keyDef,
49
+ releasePrevious,
50
+ releaseSelf,
51
+ repeat
52
+ });
53
+ text = text.slice(consumedLength);
54
+ }while (text)
55
+ return defs;
56
+ }
57
+
58
+ exports.parseKeyDef = parseKeyDef;
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var keyMap = require('./keyboard/keyMap.js');
6
+ var keyMap$1 = require('./pointer/keyMap.js');
7
+
8
+ exports.PointerEventsCheckLevel = void 0;
9
+ (function(PointerEventsCheckLevel) {
10
+ PointerEventsCheckLevel[PointerEventsCheckLevel[/**
11
+ * Check pointer events on every user interaction that triggers a bunch of events.
12
+ * E.g. once for releasing a mouse button even though this triggers `pointerup`, `mouseup`, `click`, etc...
13
+ */ "EachTrigger"] = 4] = "EachTrigger";
14
+ PointerEventsCheckLevel[PointerEventsCheckLevel[/** Check each target once per call to pointer (related) API */ "EachApiCall"] = 2] = "EachApiCall";
15
+ PointerEventsCheckLevel[PointerEventsCheckLevel[/** Check each event target once */ "EachTarget"] = 1] = "EachTarget";
16
+ PointerEventsCheckLevel[PointerEventsCheckLevel[/** No pointer events check */ "Never"] = 0] = "Never";
17
+ })(exports.PointerEventsCheckLevel || (exports.PointerEventsCheckLevel = {}));
18
+ /**
19
+ * Default options applied when API is called per `userEvent.anyApi()`
20
+ */ const defaultOptionsDirect = {
21
+ applyAccept: true,
22
+ autoModify: true,
23
+ delay: 0,
24
+ document: globalThis.document,
25
+ keyboardMap: keyMap.defaultKeyMap,
26
+ pointerMap: keyMap$1.defaultKeyMap,
27
+ pointerEventsCheck: exports.PointerEventsCheckLevel.EachApiCall,
28
+ skipAutoClose: false,
29
+ skipClick: false,
30
+ skipHover: false,
31
+ writeToClipboard: false,
32
+ advanceTimers: ()=>Promise.resolve()
33
+ };
34
+ /**
35
+ * Default options applied when API is called per `userEvent().anyApi()`
36
+ */ const defaultOptionsSetup = {
37
+ ...defaultOptionsDirect,
38
+ writeToClipboard: true
39
+ };
40
+
41
+ exports.defaultOptionsDirect = defaultOptionsDirect;
42
+ exports.defaultOptionsSetup = defaultOptionsSetup;
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,88 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('../setup/index.js');
6
+ require('../utils/click/isClickableInput.js');
7
+ require('../utils/dataTransfer/Clipboard.js');
8
+ require('../event/eventMap.js');
9
+ require('../event/behavior/click.js');
10
+ require('../event/behavior/cut.js');
11
+ require('../event/behavior/keydown.js');
12
+ require('../event/behavior/keypress.js');
13
+ require('../event/behavior/keyup.js');
14
+ require('../event/behavior/paste.js');
15
+ require('@testing-library/dom');
16
+ require('../utils/edit/maxLength.js');
17
+ require('../utils/edit/isEditable.js');
18
+ require('@testing-library/dom/dist/helpers.js');
19
+ require('../utils/keyDef/readNextDescriptor.js');
20
+ var level = require('../utils/misc/level.js');
21
+ var wait = require('../utils/misc/wait.js');
22
+ require('../options.js');
23
+ var parseKeyDef = require('./parseKeyDef.js');
24
+ var config = require('../setup/config.js');
25
+
26
+ async function pointer(input) {
27
+ const { pointerMap } = this[config.Config];
28
+ const actions = [];
29
+ (Array.isArray(input) ? input : [
30
+ input
31
+ ]).forEach((actionInput)=>{
32
+ if (typeof actionInput === 'string') {
33
+ actions.push(...parseKeyDef.parseKeyDef(pointerMap, actionInput));
34
+ } else if ('keys' in actionInput) {
35
+ actions.push(...parseKeyDef.parseKeyDef(pointerMap, actionInput.keys).map((i)=>({
36
+ ...actionInput,
37
+ ...i
38
+ })));
39
+ } else {
40
+ actions.push(actionInput);
41
+ }
42
+ });
43
+ for(let i = 0; i < actions.length; i++){
44
+ await wait.wait(this[config.Config]);
45
+ await pointerAction(this[config.Config], actions[i]);
46
+ }
47
+ this[config.Config].system.pointer.resetClickCount();
48
+ }
49
+ async function pointerAction(config, action) {
50
+ const pointerName = 'pointerName' in action && action.pointerName ? action.pointerName : 'keyDef' in action ? config.system.pointer.getPointerName(action.keyDef) : 'mouse';
51
+ const previousPosition = config.system.pointer.getPreviousPosition(pointerName);
52
+ const position = {
53
+ target: action.target ?? getPrevTarget(config, previousPosition),
54
+ coords: action.coords ?? previousPosition?.coords,
55
+ caret: {
56
+ node: action.node ?? (hasCaretPosition(action) ? undefined : previousPosition?.caret?.node),
57
+ offset: action.offset ?? (hasCaretPosition(action) ? undefined : previousPosition?.caret?.offset)
58
+ }
59
+ };
60
+ if ('keyDef' in action) {
61
+ if (config.system.pointer.isKeyPressed(action.keyDef)) {
62
+ level.setLevelRef(config, level.ApiLevel.Trigger);
63
+ await config.system.pointer.release(config, action.keyDef, position);
64
+ }
65
+ if (!action.releasePrevious) {
66
+ level.setLevelRef(config, level.ApiLevel.Trigger);
67
+ await config.system.pointer.press(config, action.keyDef, position);
68
+ if (action.releaseSelf) {
69
+ level.setLevelRef(config, level.ApiLevel.Trigger);
70
+ await config.system.pointer.release(config, action.keyDef, position);
71
+ }
72
+ }
73
+ } else {
74
+ level.setLevelRef(config, level.ApiLevel.Trigger);
75
+ await config.system.pointer.move(config, pointerName, position);
76
+ }
77
+ }
78
+ function hasCaretPosition(action) {
79
+ return !!((action.target ?? action.node) ?? action.offset !== undefined);
80
+ }
81
+ function getPrevTarget(config, position) {
82
+ if (!position) {
83
+ throw new Error('This pointer has no previous position. Provide a target property!');
84
+ }
85
+ return position.target ?? config.document.body;
86
+ }
87
+
88
+ exports.pointer = pointer;
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const defaultKeyMap = [
6
+ {
7
+ name: 'MouseLeft',
8
+ pointerType: 'mouse',
9
+ button: 'primary'
10
+ },
11
+ {
12
+ name: 'MouseRight',
13
+ pointerType: 'mouse',
14
+ button: 'secondary'
15
+ },
16
+ {
17
+ name: 'MouseMiddle',
18
+ pointerType: 'mouse',
19
+ button: 'auxiliary'
20
+ },
21
+ {
22
+ name: 'TouchA',
23
+ pointerType: 'touch'
24
+ },
25
+ {
26
+ name: 'TouchB',
27
+ pointerType: 'touch'
28
+ },
29
+ {
30
+ name: 'TouchC',
31
+ pointerType: 'touch'
32
+ },
33
+ ];
34
+
35
+ exports.defaultKeyMap = defaultKeyMap;
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('../utils/click/isClickableInput.js');
6
+ require('../utils/dataTransfer/Clipboard.js');
7
+ require('../event/eventMap.js');
8
+ require('../event/behavior/click.js');
9
+ require('../event/behavior/cut.js');
10
+ require('../event/behavior/keydown.js');
11
+ require('../event/behavior/keypress.js');
12
+ require('../event/behavior/keyup.js');
13
+ require('../event/behavior/paste.js');
14
+ require('@testing-library/dom');
15
+ require('../utils/edit/maxLength.js');
16
+ require('../utils/edit/isEditable.js');
17
+ require('@testing-library/dom/dist/helpers.js');
18
+ var readNextDescriptor = require('../utils/keyDef/readNextDescriptor.js');
19
+ require('../utils/misc/level.js');
20
+ require('../options.js');
21
+
22
+ function parseKeyDef(pointerMap, keys) {
23
+ const defs = [];
24
+ do {
25
+ const { descriptor , consumedLength , releasePrevious , releaseSelf =true , } = readNextDescriptor.readNextDescriptor(keys, 'pointer');
26
+ const keyDef = pointerMap.find((p)=>p.name === descriptor);
27
+ if (keyDef) {
28
+ defs.push({
29
+ keyDef,
30
+ releasePrevious,
31
+ releaseSelf
32
+ });
33
+ }
34
+ keys = keys.slice(consumedLength);
35
+ }while (keys)
36
+ return defs;
37
+ }
38
+
39
+ exports.parseKeyDef = parseKeyDef;
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var click = require('../convenience/click.js');
6
+ var hover = require('../convenience/hover.js');
7
+ var tab = require('../convenience/tab.js');
8
+ var index = require('../keyboard/index.js');
9
+ var copy = require('../clipboard/copy.js');
10
+ var cut = require('../clipboard/cut.js');
11
+ var paste = require('../clipboard/paste.js');
12
+ var index$1 = require('../pointer/index.js');
13
+ var clear = require('../utility/clear.js');
14
+ var selectOptions = require('../utility/selectOptions.js');
15
+ var type = require('../utility/type.js');
16
+ var upload = require('../utility/upload.js');
17
+
18
+
19
+
20
+ exports.click = click.click;
21
+ exports.dblClick = click.dblClick;
22
+ exports.tripleClick = click.tripleClick;
23
+ exports.hover = hover.hover;
24
+ exports.unhover = hover.unhover;
25
+ exports.tab = tab.tab;
26
+ exports.keyboard = index.keyboard;
27
+ exports.copy = copy.copy;
28
+ exports.cut = cut.cut;
29
+ exports.paste = paste.paste;
30
+ exports.pointer = index$1.pointer;
31
+ exports.clear = clear.clear;
32
+ exports.deselectOptions = selectOptions.deselectOptions;
33
+ exports.selectOptions = selectOptions.selectOptions;
34
+ exports.type = type.type;
35
+ exports.upload = upload.upload;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const Config = Symbol('Config');
6
+
7
+ exports.Config = Config;
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var setup = require('./setup.js');
6
+
7
+ function clear(element) {
8
+ return setup.setupDirect().api.clear(element);
9
+ }
10
+ function click(element, options = {}) {
11
+ return setup.setupDirect(options, element).api.click(element);
12
+ }
13
+ function copy(options = {}) {
14
+ return setup.setupDirect(options).api.copy();
15
+ }
16
+ function cut(options = {}) {
17
+ return setup.setupDirect(options).api.cut();
18
+ }
19
+ function dblClick(element, options = {}) {
20
+ return setup.setupDirect(options).api.dblClick(element);
21
+ }
22
+ function deselectOptions(select, values, options = {}) {
23
+ return setup.setupDirect(options).api.deselectOptions(select, values);
24
+ }
25
+ function hover(element, options = {}) {
26
+ return setup.setupDirect(options).api.hover(element);
27
+ }
28
+ async function keyboard(text, options = {}) {
29
+ const { config , api } = setup.setupDirect(options);
30
+ return api.keyboard(text).then(()=>config.system);
31
+ }
32
+ async function pointer(input, options = {}) {
33
+ const { config , api } = setup.setupDirect(options);
34
+ return api.pointer(input).then(()=>config.system);
35
+ }
36
+ function paste(clipboardData, options) {
37
+ return setup.setupDirect(options).api.paste(clipboardData);
38
+ }
39
+ function selectOptions(select, values, options = {}) {
40
+ return setup.setupDirect(options).api.selectOptions(select, values);
41
+ }
42
+ function tripleClick(element, options = {}) {
43
+ return setup.setupDirect(options).api.tripleClick(element);
44
+ }
45
+ function type(element, text, options = {}) {
46
+ return setup.setupDirect(options, element).api.type(element, text, options);
47
+ }
48
+ function unhover(element, options = {}) {
49
+ const { config , api } = setup.setupDirect(options);
50
+ config.system.pointer.setMousePosition({
51
+ target: element
52
+ });
53
+ return api.unhover(element);
54
+ }
55
+ function upload(element, fileOrFiles, options = {}) {
56
+ return setup.setupDirect(options).api.upload(element, fileOrFiles);
57
+ }
58
+ function tab(options = {}) {
59
+ return setup.setupDirect().api.tab(options);
60
+ }
61
+
62
+ exports.clear = clear;
63
+ exports.click = click;
64
+ exports.copy = copy;
65
+ exports.cut = cut;
66
+ exports.dblClick = dblClick;
67
+ exports.deselectOptions = deselectOptions;
68
+ exports.hover = hover;
69
+ exports.keyboard = keyboard;
70
+ exports.paste = paste;
71
+ exports.pointer = pointer;
72
+ exports.selectOptions = selectOptions;
73
+ exports.tab = tab;
74
+ exports.tripleClick = tripleClick;
75
+ exports.type = type;
76
+ exports.unhover = unhover;
77
+ exports.upload = upload;
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var setup = require('./setup.js');
6
+ var config = require('./config.js');
7
+ var directApi = require('./directApi.js');
8
+
9
+ const userEvent = {
10
+ ...directApi,
11
+ setup: setup.setupMain
12
+ };
13
+
14
+ exports.Config = config.Config;
15
+ exports.userEvent = userEvent;