@testing-library/user-event 14.2.6 → 14.4.1

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 (238) 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/edit/walkRadio.d.ts +4 -0
  218. package/dist/types/utils/focus/getActiveElement.d.ts +1 -0
  219. package/dist/types/utils/focus/resolveCaretPosition.d.ts +8 -0
  220. package/dist/types/utils/focus/selection.d.ts +28 -1
  221. package/dist/types/utils/index.d.ts +3 -3
  222. package/dist/types/utils/misc/getTreeDiff.d.ts +1 -0
  223. package/package.json +9 -15
  224. package/dist/index.cjs +0 -3065
  225. package/dist/index.mjs +0 -3116
  226. package/dist/types/event/eventTypes.d.ts +0 -2
  227. package/dist/types/keyboard/keyboardAction.d.ts +0 -10
  228. package/dist/types/keyboard/modifiers.d.ts +0 -9
  229. package/dist/types/keyboard/types.d.ts +0 -73
  230. package/dist/types/pointer/firePointerEvents.d.ts +0 -11
  231. package/dist/types/pointer/pointerAction.d.ts +0 -7
  232. package/dist/types/pointer/pointerMove.d.ts +0 -6
  233. package/dist/types/pointer/pointerPress.d.ts +0 -8
  234. package/dist/types/pointer/resolveSelectionTarget.d.ts +0 -5
  235. package/dist/types/pointer/types.d.ts +0 -62
  236. package/dist/types/utils/keyboard/getKeyEventProps.d.ts +0 -5
  237. package/dist/types/utils/keyboard/getUIEventModifiers.d.ts +0 -15
  238. package/dist/types/utils/pointer/mouseButtons.d.ts +0 -12
@@ -0,0 +1,279 @@
1
+ import { isElementType } from '../misc/isElementType.js';
2
+ import { isClickableInput } from '../click/isClickableInput.js';
3
+ import '../dataTransfer/Clipboard.js';
4
+ import { isContentEditable, getContentEditable } from '../edit/isContentEditable.js';
5
+ import '../edit/maxLength.js';
6
+ import { editableInputTypes } from '../edit/isEditable.js';
7
+ import '@testing-library/dom';
8
+ import '@testing-library/dom/dist/helpers.js';
9
+ import { getNextCursorPosition } from './cursor.js';
10
+ import { resolveCaretPosition } from './resolveCaretPosition.js';
11
+ import '../keyDef/readNextDescriptor.js';
12
+ import '../misc/level.js';
13
+ import '../../options.js';
14
+ import '../../event/eventMap.js';
15
+ import '../../event/behavior/click.js';
16
+ import '../../event/behavior/cut.js';
17
+ import '../../event/behavior/keydown.js';
18
+ import '../../event/behavior/keypress.js';
19
+ import '../../event/behavior/keyup.js';
20
+ import '../../event/behavior/paste.js';
21
+ import { setUISelection, getUISelection } from '../../document/selection.js';
22
+ import { getUIValue } from '../../document/value.js';
23
+
24
+ /**
25
+ * Backward-compatible selection.
26
+ *
27
+ * Handles input elements and contenteditable if it only contains a single text node.
28
+ */ function setSelectionRange(element, anchorOffset, focusOffset) {
29
+ var ref;
30
+ if (hasOwnSelection(element)) {
31
+ return setSelection({
32
+ focusNode: element,
33
+ anchorOffset,
34
+ focusOffset
35
+ });
36
+ }
37
+ /* istanbul ignore else */ if (isContentEditable(element) && ((ref = element.firstChild) === null || ref === void 0 ? void 0 : ref.nodeType) === 3) {
38
+ return setSelection({
39
+ focusNode: element.firstChild,
40
+ anchorOffset,
41
+ focusOffset
42
+ });
43
+ }
44
+ /* istanbul ignore next */ throw new Error('Not implemented. The result of this interaction is unreliable.');
45
+ }
46
+ /**
47
+ * Determine if the element has its own selection implementation
48
+ * and does not interact with the Document Selection API.
49
+ */ function hasOwnSelection(node) {
50
+ return isElement(node) && (isElementType(node, 'textarea') || isElementType(node, 'input') && node.type in editableInputTypes);
51
+ }
52
+ function hasNoSelection(node) {
53
+ return isElement(node) && isClickableInput(node);
54
+ }
55
+ function isElement(node) {
56
+ return node.nodeType === 1;
57
+ }
58
+ /**
59
+ * Determine which selection logic and selection ranges to consider.
60
+ */ function getTargetTypeAndSelection(node) {
61
+ const element = getElement(node);
62
+ if (element && hasOwnSelection(element)) {
63
+ return {
64
+ type: 'input',
65
+ selection: getUISelection(element)
66
+ };
67
+ }
68
+ const selection = element === null || element === void 0 ? void 0 : element.ownerDocument.getSelection();
69
+ // It is possible to extend a single-range selection into a contenteditable.
70
+ // This results in the range acting like a range outside of contenteditable.
71
+ const isCE = getContentEditable(node) && (selection === null || selection === void 0 ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode);
72
+ return {
73
+ type: isCE ? 'contenteditable' : 'default',
74
+ selection
75
+ };
76
+ }
77
+ function getElement(node) {
78
+ return node.nodeType === 1 ? node : node.parentElement;
79
+ }
80
+ /**
81
+ * Reset the Document Selection when moving focus into an element
82
+ * with own selection implementation.
83
+ */ function updateSelectionOnFocus(element) {
84
+ const selection = element.ownerDocument.getSelection();
85
+ /* istanbul ignore if */ if (!(selection === null || selection === void 0 ? void 0 : selection.focusNode)) {
86
+ return;
87
+ }
88
+ // If the focus moves inside an element with own selection implementation,
89
+ // the document selection will be this element.
90
+ // But if the focused element is inside a contenteditable,
91
+ // 1) a collapsed selection will be retained.
92
+ // 2) other selections will be replaced by a cursor
93
+ // 2.a) at the start of the first child if it is a text node
94
+ // 2.b) at the start of the contenteditable.
95
+ if (hasOwnSelection(element)) {
96
+ const contenteditable = getContentEditable(selection.focusNode);
97
+ if (contenteditable) {
98
+ if (!selection.isCollapsed) {
99
+ var ref;
100
+ const focusNode = ((ref = contenteditable.firstChild) === null || ref === void 0 ? void 0 : ref.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
101
+ selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
102
+ }
103
+ } else {
104
+ selection.setBaseAndExtent(element, 0, element, 0);
105
+ }
106
+ }
107
+ }
108
+ /**
109
+ * Get the range that would be overwritten by input.
110
+ */ function getInputRange(focusNode) {
111
+ const typeAndSelection = getTargetTypeAndSelection(focusNode);
112
+ if (typeAndSelection.type === 'input') {
113
+ return typeAndSelection.selection;
114
+ } else if (typeAndSelection.type === 'contenteditable') {
115
+ var ref;
116
+ // Multi-range on contenteditable edits the first selection instead of the last
117
+ return (ref = typeAndSelection.selection) === null || ref === void 0 ? void 0 : ref.getRangeAt(0);
118
+ }
119
+ }
120
+ /**
121
+ * Extend/shrink the selection like with Shift+Arrows or Shift+Mouse
122
+ */ function modifySelection({ focusNode , focusOffset }) {
123
+ var ref, ref1;
124
+ const typeAndSelection = getTargetTypeAndSelection(focusNode);
125
+ if (typeAndSelection.type === 'input') {
126
+ return setUISelection(focusNode, {
127
+ anchorOffset: typeAndSelection.selection.anchorOffset,
128
+ focusOffset
129
+ }, 'modify');
130
+ }
131
+ (ref1 = (ref = focusNode.ownerDocument) === null || ref === void 0 ? void 0 : ref.getSelection()) === null || ref1 === void 0 ? void 0 : ref1.extend(focusNode, focusOffset);
132
+ }
133
+ /**
134
+ * Set the selection
135
+ */ function setSelection({ focusNode , focusOffset , anchorNode =focusNode , anchorOffset =focusOffset }) {
136
+ var ref, ref1;
137
+ const typeAndSelection = getTargetTypeAndSelection(focusNode);
138
+ if (typeAndSelection.type === 'input') {
139
+ return setUISelection(focusNode, {
140
+ anchorOffset,
141
+ focusOffset
142
+ });
143
+ }
144
+ (ref1 = (ref = anchorNode.ownerDocument) === null || ref === void 0 ? void 0 : ref.getSelection()) === null || ref1 === void 0 ? void 0 : ref1.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
145
+ }
146
+ /**
147
+ * Move the selection
148
+ */ function moveSelection(node, direction) {
149
+ // TODO: implement shift
150
+ if (hasOwnSelection(node)) {
151
+ const selection = getUISelection(node);
152
+ setSelection({
153
+ focusNode: node,
154
+ focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + direction : direction < 0 ? selection.startOffset : selection.endOffset
155
+ });
156
+ } else {
157
+ const selection1 = node.ownerDocument.getSelection();
158
+ if (!(selection1 === null || selection1 === void 0 ? void 0 : selection1.focusNode)) {
159
+ return;
160
+ }
161
+ if (selection1.isCollapsed) {
162
+ const nextPosition = getNextCursorPosition(selection1.focusNode, selection1.focusOffset, direction);
163
+ if (nextPosition) {
164
+ setSelection({
165
+ focusNode: nextPosition.node,
166
+ focusOffset: nextPosition.offset
167
+ });
168
+ }
169
+ } else {
170
+ selection1[direction < 0 ? 'collapseToStart' : 'collapseToEnd']();
171
+ }
172
+ }
173
+ }
174
+ function setSelectionPerMouseDown({ document , target , clickCount , node , offset }) {
175
+ if (hasNoSelection(target)) {
176
+ return;
177
+ }
178
+ const targetHasOwnSelection = hasOwnSelection(target);
179
+ // On non-input elements the text selection per multiple click
180
+ // can extend beyond the target boundaries.
181
+ // The exact mechanism what is considered in the same line is unclear.
182
+ // Looks it might be every inline element.
183
+ // TODO: Check what might be considered part of the same line of text.
184
+ const text = String(targetHasOwnSelection ? getUIValue(target) : target.textContent);
185
+ const [start, end] = node ? // which elements might be considered in the same line of text.
186
+ // TODO: support expanding initial range on multiple clicks if node is given
187
+ [
188
+ offset,
189
+ offset
190
+ ] : getTextRange(text, offset, clickCount);
191
+ // TODO: implement modifying selection per shift/ctrl+mouse
192
+ if (targetHasOwnSelection) {
193
+ setUISelection(target, {
194
+ anchorOffset: start !== null && start !== void 0 ? start : text.length,
195
+ focusOffset: end !== null && end !== void 0 ? end : text.length
196
+ });
197
+ return {
198
+ node: target,
199
+ start: start !== null && start !== void 0 ? start : 0,
200
+ end: end !== null && end !== void 0 ? end : text.length
201
+ };
202
+ } else {
203
+ const { node: startNode , offset: startOffset } = resolveCaretPosition({
204
+ target,
205
+ node,
206
+ offset: start
207
+ });
208
+ const { node: endNode , offset: endOffset } = resolveCaretPosition({
209
+ target,
210
+ node,
211
+ offset: end
212
+ });
213
+ const range = target.ownerDocument.createRange();
214
+ try {
215
+ range.setStart(startNode, startOffset);
216
+ range.setEnd(endNode, endOffset);
217
+ } catch (e) {
218
+ throw new Error('The given offset is out of bounds.');
219
+ }
220
+ const selection = document.getSelection();
221
+ selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
222
+ selection === null || selection === void 0 ? void 0 : selection.addRange(range.cloneRange());
223
+ return range;
224
+ }
225
+ }
226
+ function getTextRange(text, pos, clickCount) {
227
+ if (clickCount % 3 === 1 || text.length === 0) {
228
+ return [
229
+ pos,
230
+ pos
231
+ ];
232
+ }
233
+ const textPos = pos !== null && pos !== void 0 ? pos : text.length;
234
+ if (clickCount % 3 === 2) {
235
+ return [
236
+ textPos - text.substr(0, pos).match(/(\w+|\s+|\W)?$/)[0].length,
237
+ pos === undefined ? pos : pos + text.substr(pos).match(/^(\w+|\s+|\W)?/)[0].length,
238
+ ];
239
+ }
240
+ // triple click
241
+ return [
242
+ textPos - text.substr(0, pos).match(/[^\r\n]*$/)[0].length,
243
+ pos === undefined ? pos : pos + text.substr(pos).match(/^[^\r\n]*/)[0].length,
244
+ ];
245
+ }
246
+ function modifySelectionPerMouseMove(selectionRange, { document , target , node , offset }) {
247
+ const selectionFocus = resolveCaretPosition({
248
+ target,
249
+ node,
250
+ offset
251
+ });
252
+ if ('node' in selectionRange) {
253
+ // When the mouse is dragged outside of an input/textarea,
254
+ // the selection is extended to the beginning or end of the input
255
+ // depending on pointer position.
256
+ // TODO: extend selection according to pointer position
257
+ /* istanbul ignore else */ if (selectionFocus.node === selectionRange.node) {
258
+ const anchorOffset = selectionFocus.offset < selectionRange.start ? selectionRange.end : selectionRange.start;
259
+ const focusOffset = selectionFocus.offset > selectionRange.end || selectionFocus.offset < selectionRange.start ? selectionFocus.offset : selectionRange.end;
260
+ setUISelection(selectionRange.node, {
261
+ anchorOffset,
262
+ focusOffset
263
+ });
264
+ }
265
+ } else {
266
+ const range = selectionRange.cloneRange();
267
+ const cmp = range.comparePoint(selectionFocus.node, selectionFocus.offset);
268
+ if (cmp < 0) {
269
+ range.setStart(selectionFocus.node, selectionFocus.offset);
270
+ } else if (cmp > 0) {
271
+ range.setEnd(selectionFocus.node, selectionFocus.offset);
272
+ }
273
+ const selection = document.getSelection();
274
+ selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
275
+ selection === null || selection === void 0 ? void 0 : selection.addRange(range.cloneRange());
276
+ }
277
+ }
278
+
279
+ export { getInputRange, hasNoSelection, hasOwnSelection, modifySelection, modifySelectionPerMouseMove, moveSelection, setSelection, setSelectionPerMouseDown, setSelectionRange, updateSelectionOnFocus };
@@ -0,0 +1,12 @@
1
+ const FOCUSABLE_SELECTOR = [
2
+ 'input:not([type=hidden]):not([disabled])',
3
+ 'button:not([disabled])',
4
+ 'select:not([disabled])',
5
+ 'textarea:not([disabled])',
6
+ '[contenteditable=""]',
7
+ '[contenteditable="true"]',
8
+ 'a[href]',
9
+ '[tabindex]:not([disabled])',
10
+ ].join(', ');
11
+
12
+ export { FOCUSABLE_SELECTOR };
@@ -0,0 +1,36 @@
1
+ export { isClickableInput } from './click/isClickableInput.js';
2
+ export { readBlobText } from './dataTransfer/Blob.js';
3
+ export { createDataTransfer, getBlobFromDataTransferItem } from './dataTransfer/DataTransfer.js';
4
+ export { createFileList } from './dataTransfer/FileList.js';
5
+ export { attachClipboardStubToView, createClipboardItem, detachClipboardStubFromView, readDataTransferFromClipboard, resetClipboardStubOnView, writeDataTransferToClipboard } from './dataTransfer/Clipboard.js';
6
+ export { getValue } from './edit/getValue.js';
7
+ export { input } from './edit/input.js';
8
+ export { getContentEditable, isContentEditable } from './edit/isContentEditable.js';
9
+ export { editableInputTypes, isEditable, isEditableInput } from './edit/isEditable.js';
10
+ export { setFiles } from './edit/setFiles.js';
11
+ export { walkRadio } from './edit/walkRadio.js';
12
+ export { blur } from './focus/blur.js';
13
+ export { copySelection } from './focus/copySelection.js';
14
+ export { getNextCursorPosition } from './focus/cursor.js';
15
+ export { focus } from './focus/focus.js';
16
+ export { getActiveElement, getActiveElementOrBody } from './focus/getActiveElement.js';
17
+ export { getTabDestination } from './focus/getTabDestination.js';
18
+ export { isFocusable } from './focus/isFocusable.js';
19
+ export { isAllSelected, selectAll } from './focus/selectAll.js';
20
+ export { resolveCaretPosition } from './focus/resolveCaretPosition.js';
21
+ export { getInputRange, hasNoSelection, hasOwnSelection, modifySelection, modifySelectionPerMouseMove, moveSelection, setSelection, setSelectionPerMouseDown, setSelectionRange, updateSelectionOnFocus } from './focus/selection.js';
22
+ export { FOCUSABLE_SELECTOR } from './focus/selector.js';
23
+ export { readNextDescriptor } from './keyDef/readNextDescriptor.js';
24
+ export { cloneEvent } from './misc/cloneEvent.js';
25
+ export { eventWrapper } from './misc/eventWrapper.js';
26
+ export { findClosest } from './misc/findClosest.js';
27
+ export { getDocumentFromNode } from './misc/getDocumentFromNode.js';
28
+ export { getTreeDiff } from './misc/getTreeDiff.js';
29
+ export { getWindow } from './misc/getWindow.js';
30
+ export { isDescendantOrSelf } from './misc/isDescendantOrSelf.js';
31
+ export { isElementType } from './misc/isElementType.js';
32
+ export { isVisible } from './misc/isVisible.js';
33
+ export { isDisabled } from './misc/isDisabled.js';
34
+ export { ApiLevel, getLevelRef, setLevelRef } from './misc/level.js';
35
+ export { wait } from './misc/wait.js';
36
+ export { assertPointerEvents, hasPointerEvents } from './pointer/cssPointerEvents.js';
@@ -0,0 +1,90 @@
1
+ var bracketDict;
2
+ (function(bracketDict) {
3
+ bracketDict['{'] = '}';
4
+ bracketDict['['] = ']';
5
+ })(bracketDict || (bracketDict = {}));
6
+ /**
7
+ * Read the next key definition from user input
8
+ *
9
+ * Describe key per `{descriptor}` or `[descriptor]`.
10
+ * Everything else will be interpreted as a single character as descriptor - e.g. `a`.
11
+ * Brackets `{` and `[` can be escaped by doubling - e.g. `foo[[bar` translates to `foo[bar`.
12
+ * A previously pressed key can be released per `{/descriptor}`.
13
+ * Keeping the key pressed can be written as `{descriptor>}`.
14
+ * When keeping the key pressed you can choose how long the key is pressed `{descriptor>3}`.
15
+ * You can then release the key per `{descriptor>3/}` or keep it pressed and continue with the next key.
16
+ */ function readNextDescriptor(text, context) {
17
+ let pos = 0;
18
+ const startBracket = text[pos] in bracketDict ? text[pos] : '';
19
+ pos += startBracket.length;
20
+ const isEscapedChar = new RegExp(`^\\${startBracket}{2}`).test(text);
21
+ const type = isEscapedChar ? '' : startBracket;
22
+ return {
23
+ type,
24
+ ...type === '' ? readPrintableChar(text, pos, context) : readTag(text, pos, type, context)
25
+ };
26
+ }
27
+ function readPrintableChar(text, pos, context) {
28
+ const descriptor = text[pos];
29
+ assertDescriptor(descriptor, text, pos, context);
30
+ pos += descriptor.length;
31
+ return {
32
+ consumedLength: pos,
33
+ descriptor,
34
+ releasePrevious: false,
35
+ releaseSelf: true,
36
+ repeat: 1
37
+ };
38
+ }
39
+ function readTag(text, pos, startBracket, context) {
40
+ var ref, ref1;
41
+ const releasePreviousModifier = text[pos] === '/' ? '/' : '';
42
+ pos += releasePreviousModifier.length;
43
+ const escapedDescriptor = startBracket === '{' && text[pos] === '\\';
44
+ pos += Number(escapedDescriptor);
45
+ const descriptor = escapedDescriptor ? text[pos] : (ref = text.slice(pos).match(startBracket === '{' ? /^\w+|^[^}>/]/ : /^\w+/)) === null || ref === void 0 ? void 0 : ref[0];
46
+ assertDescriptor(descriptor, text, pos, context);
47
+ pos += descriptor.length;
48
+ var ref2;
49
+ const repeatModifier = (ref2 = (ref1 = text.slice(pos).match(/^>\d+/)) === null || ref1 === void 0 ? void 0 : ref1[0]) !== null && ref2 !== void 0 ? ref2 : '';
50
+ pos += repeatModifier.length;
51
+ const releaseSelfModifier = text[pos] === '/' || !repeatModifier && text[pos] === '>' ? text[pos] : '';
52
+ pos += releaseSelfModifier.length;
53
+ const expectedEndBracket = bracketDict[startBracket];
54
+ const endBracket = text[pos] === expectedEndBracket ? expectedEndBracket : '';
55
+ if (!endBracket) {
56
+ throw new Error(getErrorMessage([
57
+ !repeatModifier && 'repeat modifier',
58
+ !releaseSelfModifier && 'release modifier',
59
+ `"${expectedEndBracket}"`,
60
+ ].filter(Boolean).join(' or '), text[pos], text, context));
61
+ }
62
+ pos += endBracket.length;
63
+ return {
64
+ consumedLength: pos,
65
+ descriptor,
66
+ releasePrevious: !!releasePreviousModifier,
67
+ repeat: repeatModifier ? Math.max(Number(repeatModifier.substr(1)), 1) : 1,
68
+ releaseSelf: hasReleaseSelf(releaseSelfModifier, repeatModifier)
69
+ };
70
+ }
71
+ function assertDescriptor(descriptor, text, pos, context) {
72
+ if (!descriptor) {
73
+ throw new Error(getErrorMessage('key descriptor', text[pos], text, context));
74
+ }
75
+ }
76
+ function hasReleaseSelf(releaseSelfModifier, repeatModifier) {
77
+ if (releaseSelfModifier) {
78
+ return releaseSelfModifier === '/';
79
+ }
80
+ if (repeatModifier) {
81
+ return false;
82
+ }
83
+ }
84
+ function getErrorMessage(expected, found, text, context) {
85
+ return `Expected ${expected} but found "${found !== null && found !== void 0 ? found : ''}" in "${text}"
86
+ See ${context === 'pointer' ? `https://testing-library.com/docs/user-event/pointer#pressing-a-button-or-touching-the-screen` : `https://testing-library.com/docs/user-event/keyboard`}
87
+ for more information about how userEvent parses your input.`;
88
+ }
89
+
90
+ export { readNextDescriptor };
@@ -0,0 +1,5 @@
1
+ function cloneEvent(event) {
2
+ return new event.constructor(event.type, event);
3
+ }
4
+
5
+ export { cloneEvent };
@@ -0,0 +1,11 @@
1
+ import { getConfig } from '@testing-library/dom';
2
+
3
+ function eventWrapper(cb) {
4
+ let result;
5
+ getConfig().eventWrapper(()=>{
6
+ result = cb();
7
+ });
8
+ return result;
9
+ }
10
+
11
+ export { eventWrapper };
@@ -0,0 +1,12 @@
1
+ function findClosest(element, callback) {
2
+ let el = element;
3
+ do {
4
+ if (callback(el)) {
5
+ return el;
6
+ }
7
+ el = el.parentElement;
8
+ }while (el && el !== element.ownerDocument.body)
9
+ return undefined;
10
+ }
11
+
12
+ export { findClosest };
@@ -0,0 +1,8 @@
1
+ function getDocumentFromNode(el) {
2
+ return isDocument(el) ? el : el.ownerDocument;
3
+ }
4
+ function isDocument(node) {
5
+ return node.nodeType === 9;
6
+ }
7
+
8
+ export { getDocumentFromNode };
@@ -0,0 +1,23 @@
1
+ function getTreeDiff(a, b) {
2
+ const treeA = [];
3
+ for(let el = a; el; el = el.parentElement){
4
+ treeA.push(el);
5
+ }
6
+ const treeB = [];
7
+ for(let el1 = b; el1; el1 = el1.parentElement){
8
+ treeB.push(el1);
9
+ }
10
+ let i = 0;
11
+ for(;; i++){
12
+ if (i >= treeA.length || i >= treeB.length || treeA[treeA.length - 1 - i] !== treeB[treeB.length - 1 - i]) {
13
+ break;
14
+ }
15
+ }
16
+ return [
17
+ treeA.slice(0, treeA.length - i),
18
+ treeB.slice(0, treeB.length - i),
19
+ treeB.slice(treeB.length - i),
20
+ ];
21
+ }
22
+
23
+ export { getTreeDiff };
@@ -0,0 +1,7 @@
1
+ import { getWindowFromNode } from '@testing-library/dom/dist/helpers.js';
2
+
3
+ function getWindow(node) {
4
+ return getWindowFromNode(node);
5
+ }
6
+
7
+ export { getWindow };
@@ -0,0 +1,12 @@
1
+ function isDescendantOrSelf(potentialDescendant, potentialAncestor) {
2
+ let el = potentialDescendant;
3
+ do {
4
+ if (el === potentialAncestor) {
5
+ return true;
6
+ }
7
+ el = el.parentElement;
8
+ }while (el)
9
+ return false;
10
+ }
11
+
12
+ export { isDescendantOrSelf };
@@ -0,0 +1,31 @@
1
+ import { isElementType } from './isElementType.js';
2
+
3
+ // This should probably just rely on the :disabled pseudo-class, but JSDOM doesn't implement it properly.
4
+ function isDisabled(element) {
5
+ for(let el = element; el; el = el.parentElement){
6
+ if (isElementType(el, [
7
+ 'button',
8
+ 'input',
9
+ 'select',
10
+ 'textarea',
11
+ 'optgroup',
12
+ 'option',
13
+ ])) {
14
+ if (el.hasAttribute('disabled')) {
15
+ return true;
16
+ }
17
+ } else if (isElementType(el, 'fieldset')) {
18
+ var ref;
19
+ if (el.hasAttribute('disabled') && !((ref = el.querySelector(':scope > legend')) === null || ref === void 0 ? void 0 : ref.contains(element))) {
20
+ return true;
21
+ }
22
+ } else if (el.tagName.includes('-')) {
23
+ if (el.constructor.formAssociated && el.hasAttribute('disabled')) {
24
+ return true;
25
+ }
26
+ }
27
+ }
28
+ return false;
29
+ }
30
+
31
+ export { isDisabled };
@@ -0,0 +1,18 @@
1
+ function isElementType(element, tag, props) {
2
+ if (element.namespaceURI && element.namespaceURI !== 'http://www.w3.org/1999/xhtml') {
3
+ return false;
4
+ }
5
+ tag = Array.isArray(tag) ? tag : [
6
+ tag
7
+ ];
8
+ // tagName is uppercase in HTMLDocument and lowercase in XMLDocument
9
+ if (!tag.includes(element.tagName.toLowerCase())) {
10
+ return false;
11
+ }
12
+ if (props) {
13
+ return Object.entries(props).every(([k, v])=>element[k] === v);
14
+ }
15
+ return true;
16
+ }
17
+
18
+ export { isElementType };
@@ -0,0 +1,17 @@
1
+ import { getWindow } from './getWindow.js';
2
+
3
+ function isVisible(element) {
4
+ const window = getWindow(element);
5
+ for(let el = element; el === null || el === void 0 ? void 0 : el.ownerDocument; el = el.parentElement){
6
+ const { display , visibility } = window.getComputedStyle(el);
7
+ if (display === 'none') {
8
+ return false;
9
+ }
10
+ if (visibility === 'hidden') {
11
+ return false;
12
+ }
13
+ }
14
+ return true;
15
+ }
16
+
17
+ export { isVisible };
@@ -0,0 +1,18 @@
1
+ var _config, _Level;
2
+ var ApiLevel;
3
+ (function(ApiLevel) {
4
+ ApiLevel[ApiLevel["Trigger"] = 2] = "Trigger";
5
+ ApiLevel[ApiLevel["Call"] = 1] = "Call";
6
+ })(ApiLevel || (ApiLevel = {}));
7
+ const Level = Symbol('Api level refs');
8
+ function setLevelRef(config, level) {
9
+ var ref;
10
+ (ref = (_config = config)[_Level = Level]) !== null && ref !== void 0 ? ref : _config[_Level] = {};
11
+ config[Level][level] = {};
12
+ }
13
+ function getLevelRef(config, level) {
14
+ var ref;
15
+ return (ref = config[Level]) === null || ref === void 0 ? void 0 : ref[level];
16
+ }
17
+
18
+ export { ApiLevel, getLevelRef, setLevelRef };
@@ -0,0 +1,12 @@
1
+ function wait(config) {
2
+ const delay = config.delay;
3
+ if (typeof delay !== 'number') {
4
+ return;
5
+ }
6
+ return Promise.all([
7
+ new Promise((resolve)=>globalThis.setTimeout(()=>resolve(), delay)),
8
+ config.advanceTimers(delay),
9
+ ]);
10
+ }
11
+
12
+ export { wait };