@testing-library/user-event 14.3.0 → 14.4.2

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 +41 -0
  2. package/dist/cjs/clipboard/cut.js +41 -0
  3. package/dist/cjs/clipboard/index.js +13 -0
  4. package/dist/cjs/clipboard/paste.js +43 -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 +108 -0
  12. package/dist/cjs/document/setRangeText.js +21 -0
  13. package/dist/cjs/document/value.js +127 -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 +138 -0
  18. package/dist/cjs/event/behavior/keypress.js +58 -0
  19. package/dist/cjs/event/behavior/keyup.js +25 -0
  20. package/dist/cjs/event/behavior/paste.js +30 -0
  21. package/dist/cjs/event/behavior/registry.js +7 -0
  22. package/dist/cjs/event/createEvent.js +209 -0
  23. package/dist/cjs/event/dispatchEvent.js +38 -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 +61 -0
  33. package/dist/cjs/options.js +42 -0
  34. package/dist/cjs/package.json +3 -0
  35. package/dist/cjs/pointer/index.js +92 -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 +100 -0
  43. package/dist/cjs/setup/wrapAsync.js +13 -0
  44. package/dist/cjs/system/index.js +33 -0
  45. package/dist/cjs/system/keyboard.js +137 -0
  46. package/dist/cjs/system/pointer/buttons.js +73 -0
  47. package/dist/cjs/system/pointer/device.js +23 -0
  48. package/dist/cjs/system/pointer/index.js +154 -0
  49. package/dist/cjs/system/pointer/mouse.js +195 -0
  50. package/dist/cjs/system/pointer/pointer.js +115 -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 +76 -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 +172 -0
  59. package/dist/cjs/utils/dataTransfer/DataTransfer.js +127 -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 +163 -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 +39 -0
  68. package/dist/cjs/utils/edit/setFiles.js +61 -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 +144 -0
  73. package/dist/cjs/utils/focus/focus.js +29 -0
  74. package/dist/cjs/utils/focus/getActiveElement.js +25 -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 +56 -0
  79. package/dist/cjs/utils/focus/selection.js +292 -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 +94 -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 +35 -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 +23 -0
  95. package/dist/cjs/utils/misc/wait.js +16 -0
  96. package/dist/cjs/utils/pointer/cssPointerEvents.js +118 -0
  97. package/dist/esm/clipboard/copy.js +37 -0
  98. package/dist/esm/clipboard/cut.js +37 -0
  99. package/dist/esm/clipboard/index.js +3 -0
  100. package/dist/esm/clipboard/paste.js +39 -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 +100 -0
  108. package/dist/esm/document/setRangeText.js +17 -0
  109. package/dist/esm/document/value.js +117 -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 +136 -0
  114. package/dist/esm/event/behavior/keypress.js +56 -0
  115. package/dist/esm/event/behavior/keyup.js +23 -0
  116. package/dist/esm/event/behavior/paste.js +28 -0
  117. package/dist/esm/event/behavior/registry.js +3 -0
  118. package/dist/esm/event/createEvent.js +205 -0
  119. package/dist/esm/event/dispatchEvent.js +34 -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 +57 -0
  129. package/dist/esm/options.js +37 -0
  130. package/dist/esm/package.json +3 -0
  131. package/dist/esm/pointer/index.js +88 -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 +93 -0
  139. package/dist/esm/setup/wrapAsync.js +9 -0
  140. package/dist/esm/system/index.js +29 -0
  141. package/dist/esm/system/keyboard.js +133 -0
  142. package/dist/esm/system/pointer/buttons.js +65 -0
  143. package/dist/esm/system/pointer/device.js +19 -0
  144. package/dist/esm/system/pointer/index.js +149 -0
  145. package/dist/esm/system/pointer/mouse.js +191 -0
  146. package/dist/esm/system/pointer/pointer.js +111 -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 +72 -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 +163 -0
  155. package/dist/esm/utils/dataTransfer/DataTransfer.js +122 -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 +159 -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 +35 -0
  164. package/dist/esm/utils/edit/setFiles.js +57 -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 +140 -0
  169. package/dist/esm/utils/focus/focus.js +25 -0
  170. package/dist/esm/utils/focus/getActiveElement.js +20 -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 +51 -0
  175. package/dist/esm/utils/focus/selection.js +279 -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 +90 -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 +31 -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 +18 -0
  191. package/dist/esm/utils/misc/wait.js +12 -0
  192. package/dist/esm/utils/pointer/cssPointerEvents.js +113 -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 +32 -14
  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,191 @@
1
+ import { dispatchUIEvent } from '../../event/index.js';
2
+ import '../../utils/click/isClickableInput.js';
3
+ import '../../utils/dataTransfer/Clipboard.js';
4
+ import '../../utils/edit/maxLength.js';
5
+ import '../../utils/edit/isEditable.js';
6
+ import { focus } from '../../utils/focus/focus.js';
7
+ import '@testing-library/dom/dist/helpers.js';
8
+ import { isDisabled } from '../../utils/misc/isDisabled.js';
9
+ import '@testing-library/dom';
10
+ import { setSelectionPerMouseDown, modifySelectionPerMouseMove } from '../../utils/focus/selection.js';
11
+ import '../../utils/keyDef/readNextDescriptor.js';
12
+ import { getTreeDiff } from '../../utils/misc/getTreeDiff.js';
13
+ import '../../utils/misc/level.js';
14
+ import '../../options.js';
15
+ import { isDifferentPointerPosition } from './index.js';
16
+ import { getMouseEventButton, Buttons } from './buttons.js';
17
+
18
+ /**
19
+ * This object is the single "virtual" mouse that might be controlled by multiple different pointer devices.
20
+ */ class Mouse {
21
+ move(config, position) {
22
+ const prevPosition = this.position;
23
+ const prevTarget = this.getTarget(config);
24
+ this.position = position;
25
+ if (!isDifferentPointerPosition(prevPosition, position)) {
26
+ return;
27
+ }
28
+ const nextTarget = this.getTarget(config);
29
+ const init = this.getEventInit('mousemove');
30
+ const [leave, enter] = getTreeDiff(prevTarget, nextTarget);
31
+ return {
32
+ leave: ()=>{
33
+ if (prevTarget !== nextTarget) {
34
+ dispatchUIEvent(config, prevTarget, 'mouseout', init);
35
+ leave.forEach((el)=>dispatchUIEvent(config, el, 'mouseleave', init));
36
+ }
37
+ },
38
+ enter: ()=>{
39
+ if (prevTarget !== nextTarget) {
40
+ dispatchUIEvent(config, nextTarget, 'mouseover', init);
41
+ enter.forEach((el)=>dispatchUIEvent(config, el, 'mouseenter', init));
42
+ }
43
+ },
44
+ move: ()=>{
45
+ dispatchUIEvent(config, nextTarget, 'mousemove', init);
46
+ this.modifySelecting(config);
47
+ }
48
+ };
49
+ }
50
+ down(config, keyDef, pointer) {
51
+ const button = this.buttons.down(keyDef);
52
+ if (button === undefined) {
53
+ return;
54
+ }
55
+ const target = this.getTarget(config);
56
+ this.buttonDownTarget[button] = target;
57
+ const disabled = isDisabled(target);
58
+ const init = this.getEventInit('mousedown', keyDef.button);
59
+ if (disabled || dispatchUIEvent(config, target, 'mousedown', init)) {
60
+ this.startSelecting(config, init.detail);
61
+ focus(target);
62
+ }
63
+ if (!disabled && getMouseEventButton(keyDef.button) === 2) {
64
+ dispatchUIEvent(config, target, 'contextmenu', this.getEventInit('contextmenu', keyDef.button, pointer));
65
+ }
66
+ }
67
+ up(config, keyDef, pointer) {
68
+ const button = this.buttons.up(keyDef);
69
+ if (button === undefined) {
70
+ return;
71
+ }
72
+ const target = this.getTarget(config);
73
+ if (!isDisabled(target)) {
74
+ dispatchUIEvent(config, target, 'mouseup', this.getEventInit('mouseup', keyDef.button));
75
+ this.endSelecting();
76
+ const clickTarget = getTreeDiff(this.buttonDownTarget[button], target)[2][0];
77
+ if (clickTarget) {
78
+ const init = this.getEventInit('click', keyDef.button, pointer);
79
+ if (init.detail) {
80
+ dispatchUIEvent(config, clickTarget, init.button === 0 ? 'click' : 'auxclick', init);
81
+ if (init.button === 0 && init.detail === 2) {
82
+ dispatchUIEvent(config, clickTarget, 'dblclick', {
83
+ ...this.getEventInit('dblclick', keyDef.button),
84
+ detail: init.detail
85
+ });
86
+ }
87
+ }
88
+ }
89
+ }
90
+ }
91
+ resetClickCount() {
92
+ this.clickCount.reset();
93
+ }
94
+ getEventInit(type, button, pointer) {
95
+ const init = {
96
+ ...this.position.coords
97
+ };
98
+ if (pointer) {
99
+ init.pointerId = pointer.pointerId;
100
+ init.pointerType = pointer.pointerType;
101
+ init.isPrimary = pointer.isPrimary;
102
+ }
103
+ init.button = getMouseEventButton(button);
104
+ init.buttons = this.buttons.getButtons();
105
+ if (type === 'mousedown') {
106
+ init.detail = this.clickCount.getOnDown(init.button);
107
+ } else if (type === 'mouseup') {
108
+ init.detail = this.clickCount.getOnUp(init.button);
109
+ } else if (type === 'click' || type === 'auxclick') {
110
+ init.detail = this.clickCount.incOnClick(init.button);
111
+ }
112
+ return init;
113
+ }
114
+ getTarget(config) {
115
+ var _target;
116
+ return (_target = this.position.target) !== null && _target !== void 0 ? _target : config.document.body;
117
+ }
118
+ startSelecting(config, clickCount) {
119
+ var ref, ref1;
120
+ // TODO: support extending range (shift)
121
+ this.selecting = setSelectionPerMouseDown({
122
+ document: config.document,
123
+ target: this.getTarget(config),
124
+ node: (ref = this.position.caret) === null || ref === void 0 ? void 0 : ref.node,
125
+ offset: (ref1 = this.position.caret) === null || ref1 === void 0 ? void 0 : ref1.offset,
126
+ clickCount
127
+ });
128
+ }
129
+ modifySelecting(config) {
130
+ var ref, ref1;
131
+ if (!this.selecting) {
132
+ return;
133
+ }
134
+ modifySelectionPerMouseMove(this.selecting, {
135
+ document: config.document,
136
+ target: this.getTarget(config),
137
+ node: (ref = this.position.caret) === null || ref === void 0 ? void 0 : ref.node,
138
+ offset: (ref1 = this.position.caret) === null || ref1 === void 0 ? void 0 : ref1.offset
139
+ });
140
+ }
141
+ endSelecting() {
142
+ this.selecting = undefined;
143
+ }
144
+ constructor(){
145
+ this.position = {};
146
+ this.buttons = new Buttons();
147
+ this.buttonDownTarget = {};
148
+ // According to spec the `detail` on click events should be the number
149
+ // of *consecutive* clicks with a specific button.
150
+ // On `mousedown` and `mouseup` it should be this number increased by one.
151
+ // But the browsers don't implement it this way.
152
+ // If another button is pressed,
153
+ // in Webkit: the `mouseup` on the previously pressed button has `detail: 0` and no `click`/`auxclick`.
154
+ // in Gecko: the `mouseup` and click events have the same detail as the `mousedown`.
155
+ // If there is a delay while a button is pressed,
156
+ // the `mouseup` and `click` are normal, but a following `mousedown` starts a new click count.
157
+ // We'll follow the minimal implementation of Webkit.
158
+ this.clickCount = new class {
159
+ incOnClick(button) {
160
+ const current = this.down[button] === undefined ? undefined : Number(this.down[button]) + 1;
161
+ this.count = this.count[button] === undefined ? {} : {
162
+ [button]: Number(this.count[button]) + 1
163
+ };
164
+ return current;
165
+ }
166
+ getOnDown(button) {
167
+ var _button;
168
+ this.down = {
169
+ [button]: (_button = this.count[button]) !== null && _button !== void 0 ? _button : 0
170
+ };
171
+ var _button1;
172
+ this.count = {
173
+ [button]: (_button1 = this.count[button]) !== null && _button1 !== void 0 ? _button1 : 0
174
+ };
175
+ return Number(this.count[button]) + 1;
176
+ }
177
+ getOnUp(button) {
178
+ return this.down[button] === undefined ? undefined : Number(this.down[button]) + 1;
179
+ }
180
+ reset() {
181
+ this.count = {};
182
+ }
183
+ constructor(){
184
+ this.down = {};
185
+ this.count = {};
186
+ }
187
+ }();
188
+ }
189
+ }
190
+
191
+ export { Mouse };
@@ -0,0 +1,111 @@
1
+ import { dispatchUIEvent } from '../../event/index.js';
2
+ import '../../utils/click/isClickableInput.js';
3
+ import '../../utils/dataTransfer/Clipboard.js';
4
+ import '../../utils/edit/maxLength.js';
5
+ import '../../utils/edit/isEditable.js';
6
+ import '@testing-library/dom';
7
+ import '@testing-library/dom/dist/helpers.js';
8
+ import '../../utils/keyDef/readNextDescriptor.js';
9
+ import { getTreeDiff } from '../../utils/misc/getTreeDiff.js';
10
+ import '../../utils/misc/level.js';
11
+ import { assertPointerEvents, hasPointerEvents } from '../../utils/pointer/cssPointerEvents.js';
12
+ import { isDifferentPointerPosition } from './index.js';
13
+
14
+ class Pointer {
15
+ init(config, position) {
16
+ this.position = position;
17
+ const target = this.getTarget(config);
18
+ const [, enter] = getTreeDiff(null, target);
19
+ const init = this.getEventInit();
20
+ assertPointerEvents(config, target);
21
+ dispatchUIEvent(config, target, 'pointerover', init);
22
+ enter.forEach((el)=>dispatchUIEvent(config, el, 'pointerenter', init));
23
+ return this;
24
+ }
25
+ move(config, position) {
26
+ const prevPosition = this.position;
27
+ const prevTarget = this.getTarget(config);
28
+ this.position = position;
29
+ if (!isDifferentPointerPosition(prevPosition, position)) {
30
+ return;
31
+ }
32
+ const nextTarget = this.getTarget(config);
33
+ const init = this.getEventInit();
34
+ const [leave, enter] = getTreeDiff(prevTarget, nextTarget);
35
+ return {
36
+ leave: ()=>{
37
+ if (hasPointerEvents(config, prevTarget)) {
38
+ if (prevTarget !== nextTarget) {
39
+ dispatchUIEvent(config, prevTarget, 'pointerout', init);
40
+ leave.forEach((el)=>dispatchUIEvent(config, el, 'pointerleave', init));
41
+ }
42
+ }
43
+ },
44
+ enter: ()=>{
45
+ assertPointerEvents(config, nextTarget);
46
+ if (prevTarget !== nextTarget) {
47
+ dispatchUIEvent(config, nextTarget, 'pointerover', init);
48
+ enter.forEach((el)=>dispatchUIEvent(config, el, 'pointerenter', init));
49
+ }
50
+ },
51
+ move: ()=>{
52
+ dispatchUIEvent(config, nextTarget, 'pointermove', init);
53
+ }
54
+ };
55
+ }
56
+ down(config, _keyDef) {
57
+ if (this.isDown) {
58
+ return;
59
+ }
60
+ const target = this.getTarget(config);
61
+ assertPointerEvents(config, target);
62
+ this.isDown = true;
63
+ this.isPrevented = !dispatchUIEvent(config, target, 'pointerdown', this.getEventInit());
64
+ }
65
+ up(config, _keyDef) {
66
+ if (!this.isDown) {
67
+ return;
68
+ }
69
+ const target = this.getTarget(config);
70
+ assertPointerEvents(config, target);
71
+ this.isDown = false;
72
+ dispatchUIEvent(config, target, 'pointerup', this.getEventInit());
73
+ }
74
+ release(config) {
75
+ const target = this.getTarget(config);
76
+ const [leave] = getTreeDiff(target, null);
77
+ const init = this.getEventInit();
78
+ // Currently there is no PointerEventsCheckLevel that would
79
+ // make this check not use the *asserted* cached value from `up`.
80
+ /* istanbul ignore else */ if (hasPointerEvents(config, target)) {
81
+ dispatchUIEvent(config, target, 'pointerout', init);
82
+ leave.forEach((el)=>dispatchUIEvent(config, el, 'pointerleave', init));
83
+ }
84
+ this.isCancelled = true;
85
+ }
86
+ getTarget(config) {
87
+ var _target;
88
+ return (_target = this.position.target) !== null && _target !== void 0 ? _target : config.document.body;
89
+ }
90
+ getEventInit() {
91
+ return {
92
+ ...this.position.coords,
93
+ pointerId: this.pointerId,
94
+ pointerType: this.pointerType,
95
+ isPrimary: this.isPrimary
96
+ };
97
+ }
98
+ constructor({ pointerId , pointerType , isPrimary }){
99
+ this.isMultitouch = false;
100
+ this.isCancelled = false;
101
+ this.isDown = false;
102
+ this.isPrevented = false;
103
+ this.position = {};
104
+ this.pointerId = pointerId;
105
+ this.pointerType = pointerType;
106
+ this.isPrimary = isPrimary;
107
+ this.isMultitouch = !isPrimary;
108
+ }
109
+ }
110
+
111
+ export { Pointer };
@@ -0,0 +1,38 @@
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 { input } from '../utils/edit/input.js';
13
+ import { isEditable } from '../utils/edit/isEditable.js';
14
+ import { focus } from '../utils/focus/focus.js';
15
+ import '@testing-library/dom/dist/helpers.js';
16
+ import { isDisabled } from '../utils/misc/isDisabled.js';
17
+ import { selectAll, isAllSelected } from '../utils/focus/selectAll.js';
18
+ import '../utils/keyDef/readNextDescriptor.js';
19
+ import '../utils/misc/level.js';
20
+ import '../options.js';
21
+ import { Config } from '../setup/config.js';
22
+
23
+ async function clear(element) {
24
+ if (!isEditable(element) || isDisabled(element)) {
25
+ throw new Error('clear()` is only supported on editable elements.');
26
+ }
27
+ focus(element);
28
+ if (element.ownerDocument.activeElement !== element) {
29
+ throw new Error('The element to be cleared could not be focused.');
30
+ }
31
+ selectAll(element);
32
+ if (!isAllSelected(element)) {
33
+ throw new Error('The element content to be cleared could not be selected.');
34
+ }
35
+ input(this[Config], element, '', 'deleteContentBackward');
36
+ }
37
+
38
+ export { clear };
@@ -0,0 +1,4 @@
1
+ export { clear } from './clear.js';
2
+ export { deselectOptions, selectOptions } from './selectOptions.js';
3
+ export { type } from './type.js';
4
+ export { upload } from './upload.js';
@@ -0,0 +1,120 @@
1
+ import { getConfig } from '@testing-library/dom';
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 '../utils/edit/maxLength.js';
12
+ import '../utils/edit/isEditable.js';
13
+ import { focus } from '../utils/focus/focus.js';
14
+ import '@testing-library/dom/dist/helpers.js';
15
+ import { isDisabled } from '../utils/misc/isDisabled.js';
16
+ import { isElementType } from '../utils/misc/isElementType.js';
17
+ import '../utils/keyDef/readNextDescriptor.js';
18
+ import '../utils/misc/level.js';
19
+ import { wait } from '../utils/misc/wait.js';
20
+ import { hasPointerEvents } from '../utils/pointer/cssPointerEvents.js';
21
+ import '../setup/index.js';
22
+ import { Config } from '../setup/config.js';
23
+
24
+ async function selectOptions(select, values) {
25
+ return selectOptionsBase.call(this, true, select, values);
26
+ }
27
+ async function deselectOptions(select, values) {
28
+ return selectOptionsBase.call(this, false, select, values);
29
+ }
30
+ async function selectOptionsBase(newValue, select, values) {
31
+ if (!newValue && !select.multiple) {
32
+ throw getConfig().getElementError(`Unable to deselect an option in a non-multiple select. Use selectOptions to change the selection instead.`, select);
33
+ }
34
+ const valArray = Array.isArray(values) ? values : [
35
+ values
36
+ ];
37
+ const allOptions = Array.from(select.querySelectorAll('option, [role="option"]'));
38
+ const selectedOptions = valArray.map((val)=>{
39
+ if (typeof val !== 'string' && allOptions.includes(val)) {
40
+ return val;
41
+ } else {
42
+ const matchingOption = allOptions.find((o)=>o.value === val || o.innerHTML === val);
43
+ if (matchingOption) {
44
+ return matchingOption;
45
+ } else {
46
+ throw getConfig().getElementError(`Value "${String(val)}" not found in options`, select);
47
+ }
48
+ }
49
+ }).filter((option)=>!isDisabled(option));
50
+ if (isDisabled(select) || !selectedOptions.length) return;
51
+ const selectOption = (option)=>{
52
+ option.selected = newValue;
53
+ this.dispatchUIEvent(select, 'input', {
54
+ bubbles: true,
55
+ cancelable: false,
56
+ composed: true
57
+ });
58
+ this.dispatchUIEvent(select, 'change');
59
+ };
60
+ if (isElementType(select, 'select')) {
61
+ if (select.multiple) {
62
+ for (const option of selectedOptions){
63
+ const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(this[Config], option);
64
+ // events fired for multiple select are weird. Can't use hover...
65
+ if (withPointerEvents) {
66
+ this.dispatchUIEvent(option, 'pointerover');
67
+ this.dispatchUIEvent(select, 'pointerenter');
68
+ this.dispatchUIEvent(option, 'mouseover');
69
+ this.dispatchUIEvent(select, 'mouseenter');
70
+ this.dispatchUIEvent(option, 'pointermove');
71
+ this.dispatchUIEvent(option, 'mousemove');
72
+ this.dispatchUIEvent(option, 'pointerdown');
73
+ this.dispatchUIEvent(option, 'mousedown');
74
+ }
75
+ focus(select);
76
+ if (withPointerEvents) {
77
+ this.dispatchUIEvent(option, 'pointerup');
78
+ this.dispatchUIEvent(option, 'mouseup');
79
+ }
80
+ selectOption(option);
81
+ if (withPointerEvents) {
82
+ this.dispatchUIEvent(option, 'click');
83
+ }
84
+ await wait(this[Config]);
85
+ }
86
+ } else if (selectedOptions.length === 1) {
87
+ const withPointerEvents1 = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(this[Config], select);
88
+ // the click to open the select options
89
+ if (withPointerEvents1) {
90
+ await this.click(select);
91
+ } else {
92
+ focus(select);
93
+ }
94
+ selectOption(selectedOptions[0]);
95
+ if (withPointerEvents1) {
96
+ // the browser triggers another click event on the select for the click on the option
97
+ // this second click has no 'down' phase
98
+ this.dispatchUIEvent(select, 'pointerover');
99
+ this.dispatchUIEvent(select, 'pointerenter');
100
+ this.dispatchUIEvent(select, 'mouseover');
101
+ this.dispatchUIEvent(select, 'mouseenter');
102
+ this.dispatchUIEvent(select, 'pointerup');
103
+ this.dispatchUIEvent(select, 'mouseup');
104
+ this.dispatchUIEvent(select, 'click');
105
+ }
106
+ await wait(this[Config]);
107
+ } else {
108
+ throw getConfig().getElementError(`Cannot select multiple options on a non-multiple select`, select);
109
+ }
110
+ } else if (select.getAttribute('role') === 'listbox') {
111
+ for (const option1 of selectedOptions){
112
+ await this.click(option1);
113
+ await this.unhover(option1);
114
+ }
115
+ } else {
116
+ throw getConfig().getElementError(`Cannot select options on elements that are neither select nor listbox elements`, select);
117
+ }
118
+ }
119
+
120
+ export { deselectOptions, selectOptions };
@@ -0,0 +1,37 @@
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 { setSelectionRange } from '../utils/focus/selection.js';
14
+ import '@testing-library/dom/dist/helpers.js';
15
+ import '../utils/keyDef/readNextDescriptor.js';
16
+ import '../utils/misc/level.js';
17
+ import '../options.js';
18
+ import { releaseAllKeys } from '../keyboard/index.js';
19
+ import { Config } from '../setup/config.js';
20
+
21
+ async function type(element, text, { skipClick =this[Config].skipClick , skipAutoClose =this[Config].skipAutoClose , initialSelectionStart , initialSelectionEnd } = {}) {
22
+ // TODO: properly type guard
23
+ // we use this workaround for now to prevent changing behavior
24
+ if (element.disabled) return;
25
+ if (!skipClick) {
26
+ await this.click(element);
27
+ }
28
+ if (initialSelectionStart !== undefined) {
29
+ setSelectionRange(element, initialSelectionStart, initialSelectionEnd !== null && initialSelectionEnd !== void 0 ? initialSelectionEnd : initialSelectionStart);
30
+ }
31
+ await this.keyboard(text);
32
+ if (!skipAutoClose) {
33
+ await releaseAllKeys(this[Config]);
34
+ }
35
+ }
36
+
37
+ export { type };
@@ -0,0 +1,72 @@
1
+ import '../utils/click/isClickableInput.js';
2
+ import { createFileList } from '../utils/dataTransfer/FileList.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 { setFiles } from '../utils/edit/setFiles.js';
15
+ import { isDisabled } from '../utils/misc/isDisabled.js';
16
+ import { isElementType } from '../utils/misc/isElementType.js';
17
+ import { getWindow } from '../utils/misc/getWindow.js';
18
+ import '../utils/keyDef/readNextDescriptor.js';
19
+ import '../utils/misc/level.js';
20
+ import '../options.js';
21
+ import '../setup/index.js';
22
+ import { Config } from '../setup/config.js';
23
+
24
+ async function upload(element, fileOrFiles) {
25
+ const input = isElementType(element, 'label') ? element.control : element;
26
+ if (!input || !isElementType(input, 'input', {
27
+ type: 'file'
28
+ })) {
29
+ throw new TypeError(`The ${input === element ? 'given' : 'associated'} ${input === null || input === void 0 ? void 0 : input.tagName} element does not accept file uploads`);
30
+ }
31
+ if (isDisabled(element)) return;
32
+ const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [
33
+ fileOrFiles
34
+ ]).filter((file)=>!this[Config].applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? undefined : 1);
35
+ const fileDialog = ()=>{
36
+ var ref;
37
+ // do not fire an input event if the file selection does not change
38
+ if (files.length === ((ref = input.files) === null || ref === void 0 ? void 0 : ref.length) && files.every((f, i)=>{
39
+ var ref;
40
+ return f === ((ref = input.files) === null || ref === void 0 ? void 0 : ref.item(i));
41
+ })) {
42
+ return;
43
+ }
44
+ setFiles(input, createFileList(getWindow(element), files));
45
+ this.dispatchUIEvent(input, 'input');
46
+ this.dispatchUIEvent(input, 'change');
47
+ };
48
+ input.addEventListener('fileDialog', fileDialog);
49
+ await this.click(element);
50
+ input.removeEventListener('fileDialog', fileDialog);
51
+ }
52
+ function isAcceptableFile(file, accept) {
53
+ if (!accept) {
54
+ return true;
55
+ }
56
+ const wildcards = [
57
+ 'audio/*',
58
+ 'image/*',
59
+ 'video/*'
60
+ ];
61
+ return accept.split(',').some((acceptToken)=>{
62
+ if (acceptToken.startsWith('.')) {
63
+ // tokens starting with a dot represent a file extension
64
+ return file.name.endsWith(acceptToken);
65
+ } else if (wildcards.includes(acceptToken)) {
66
+ return file.type.startsWith(acceptToken.substr(0, acceptToken.length - 1));
67
+ }
68
+ return file.type === acceptToken;
69
+ });
70
+ }
71
+
72
+ export { upload };
@@ -0,0 +1,18 @@
1
+ import { isElementType } from '../misc/isElementType.js';
2
+
3
+ var clickableInputTypes;
4
+ (function(clickableInputTypes) {
5
+ clickableInputTypes['button'] = 'button';
6
+ clickableInputTypes['color'] = 'color';
7
+ clickableInputTypes['file'] = 'file';
8
+ clickableInputTypes['image'] = 'image';
9
+ clickableInputTypes['reset'] = 'reset';
10
+ clickableInputTypes['submit'] = 'submit';
11
+ clickableInputTypes['checkbox'] = 'checkbox';
12
+ clickableInputTypes['radio'] = 'radio';
13
+ })(clickableInputTypes || (clickableInputTypes = {}));
14
+ function isClickableInput(element) {
15
+ return isElementType(element, 'button') || isElementType(element, 'input') && element.type in clickableInputTypes;
16
+ }
17
+
18
+ export { isClickableInput };
@@ -0,0 +1,14 @@
1
+ // jsdom does not implement Blob.text()
2
+ function readBlobText(blob, FileReader) {
3
+ return new Promise((res, rej)=>{
4
+ const fr = new FileReader();
5
+ fr.onerror = rej;
6
+ fr.onabort = rej;
7
+ fr.onload = ()=>{
8
+ res(String(fr.result));
9
+ };
10
+ fr.readAsText(blob);
11
+ });
12
+ }
13
+
14
+ export { readBlobText };