@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,117 @@
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 { hasUISelection, setUISelection } from './selection.js';
12
+ import { prepareInterceptor } from './interceptor.js';
13
+ import '../utils/edit/maxLength.js';
14
+ import '../utils/edit/isEditable.js';
15
+ import { isElementType } from '../utils/misc/isElementType.js';
16
+ import { getWindow } from '../utils/misc/getWindow.js';
17
+ import '../utils/keyDef/readNextDescriptor.js';
18
+ import '../utils/misc/level.js';
19
+ import '../options.js';
20
+
21
+ const UIValue = Symbol('Displayed value in UI');
22
+ const InitialValue = Symbol('Initial value to compare on blur');
23
+ const TrackChanges = Symbol('Track programmatic changes for React workaround');
24
+ function valueInterceptor(v) {
25
+ const isUI = typeof v === 'object' && v[UIValue];
26
+ if (isUI) {
27
+ this[UIValue] = String(v);
28
+ startTrackValue(this);
29
+ }
30
+ return {
31
+ applyNative: !!isUI,
32
+ realArgs: sanitizeValue(this, v),
33
+ then: isUI ? undefined : ()=>trackOrSetValue(this, String(v))
34
+ };
35
+ }
36
+ function sanitizeValue(element, v) {
37
+ // Workaround for JSDOM
38
+ if (isElementType(element, 'input', {
39
+ type: 'number'
40
+ }) && String(v) !== '' && !Number.isNaN(Number(v))) {
41
+ // Setting value to "1." results in `null` in JSDOM
42
+ return String(Number(v));
43
+ }
44
+ return String(v);
45
+ }
46
+ function prepareValueInterceptor(element) {
47
+ prepareInterceptor(element, 'value', valueInterceptor);
48
+ }
49
+ function setUIValue(element, value) {
50
+ if (element[InitialValue] === undefined) {
51
+ element[InitialValue] = element.value;
52
+ }
53
+ element.value = {
54
+ [UIValue]: UIValue,
55
+ toString: ()=>value
56
+ };
57
+ }
58
+ function getUIValue(element) {
59
+ return element[UIValue] === undefined ? element.value : String(element[UIValue]);
60
+ }
61
+ /** Flag the IDL value as clean. This does not change the value.*/ function setUIValueClean(element) {
62
+ element[UIValue] = undefined;
63
+ }
64
+ function clearInitialValue(element) {
65
+ element[InitialValue] = undefined;
66
+ }
67
+ function getInitialValue(element) {
68
+ return element[InitialValue];
69
+ }
70
+ // When the input event happens in the browser, React executes all event handlers
71
+ // and if they change state of a controlled value, nothing happens.
72
+ // But when we trigger the event handlers in test environment with React@17,
73
+ // the changes are rolled back before the state update is applied.
74
+ // This results in a reset cursor.
75
+ // There might be a better way to work around if we figure out
76
+ // why the batched update is executed differently in our test environment.
77
+ function isReact17Element(element) {
78
+ return Object.getOwnPropertyNames(element).some((k)=>k.startsWith('__react')) && getWindow(element).REACT_VERSION === 17;
79
+ }
80
+ function startTrackValue(element) {
81
+ if (!isReact17Element(element)) {
82
+ return;
83
+ }
84
+ element[TrackChanges] = {
85
+ previousValue: String(element.value),
86
+ tracked: []
87
+ };
88
+ }
89
+ function trackOrSetValue(element, v) {
90
+ var ref, ref1;
91
+ (ref = element[TrackChanges]) === null || ref === void 0 ? void 0 : (ref1 = ref.tracked) === null || ref1 === void 0 ? void 0 : ref1.push(v);
92
+ if (!element[TrackChanges]) {
93
+ setUIValueClean(element);
94
+ setUISelection(element, {
95
+ focusOffset: v.length
96
+ });
97
+ }
98
+ }
99
+ function commitValueAfterInput(element, cursorOffset) {
100
+ var ref;
101
+ const changes = element[TrackChanges];
102
+ element[TrackChanges] = undefined;
103
+ if (!(changes === null || changes === void 0 ? void 0 : (ref = changes.tracked) === null || ref === void 0 ? void 0 : ref.length)) {
104
+ return;
105
+ }
106
+ const isJustReactStateUpdate = changes.tracked.length === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === element.value;
107
+ if (!isJustReactStateUpdate) {
108
+ setUIValueClean(element);
109
+ }
110
+ if (hasUISelection(element)) {
111
+ setUISelection(element, {
112
+ focusOffset: isJustReactStateUpdate ? cursorOffset : element.value.length
113
+ });
114
+ }
115
+ }
116
+
117
+ export { clearInitialValue, commitValueAfterInput, getInitialValue, getUIValue, prepareValueInterceptor, setUIValue, setUIValueClean };
@@ -0,0 +1,40 @@
1
+ import '../../utils/click/isClickableInput.js';
2
+ import '../../utils/dataTransfer/Clipboard.js';
3
+ import '../eventMap.js';
4
+ import { dispatchEvent } from '../dispatchEvent.js';
5
+ import '../../utils/edit/maxLength.js';
6
+ import '../../utils/edit/isEditable.js';
7
+ import { focus } from '../../utils/focus/focus.js';
8
+ import { getWindow } from '../../utils/misc/getWindow.js';
9
+ import { isElementType } from '../../utils/misc/isElementType.js';
10
+ import { blur } from '../../utils/focus/blur.js';
11
+ import { isFocusable } from '../../utils/focus/isFocusable.js';
12
+ import '../../utils/keyDef/readNextDescriptor.js';
13
+ import { cloneEvent } from '../../utils/misc/cloneEvent.js';
14
+ import '@testing-library/dom';
15
+ import '../../utils/misc/level.js';
16
+ import '../../options.js';
17
+ import { behavior } from './registry.js';
18
+
19
+ behavior.click = (event, target, config)=>{
20
+ const context = target.closest('button,input,label,select,textarea');
21
+ const control = context && isElementType(context, 'label') && context.control;
22
+ if (control) {
23
+ return ()=>{
24
+ if (isFocusable(control)) {
25
+ focus(control);
26
+ }
27
+ dispatchEvent(config, control, cloneEvent(event));
28
+ };
29
+ } else if (isElementType(target, 'input', {
30
+ type: 'file'
31
+ })) {
32
+ return ()=>{
33
+ // blur fires when the file selector pops up
34
+ blur(target);
35
+ target.dispatchEvent(new (getWindow(target)).Event('fileDialog'));
36
+ // focus fires after the file selector has been closed
37
+ focus(target);
38
+ };
39
+ }
40
+ };
@@ -0,0 +1,24 @@
1
+ import '../../utils/click/isClickableInput.js';
2
+ import '../../utils/dataTransfer/Clipboard.js';
3
+ import '../eventMap.js';
4
+ import './click.js';
5
+ import './keydown.js';
6
+ import './keypress.js';
7
+ import './keyup.js';
8
+ import './paste.js';
9
+ import { behavior } from './registry.js';
10
+ import '@testing-library/dom';
11
+ import { input } from '../../utils/edit/input.js';
12
+ import { isEditable } from '../../utils/edit/isEditable.js';
13
+ import '@testing-library/dom/dist/helpers.js';
14
+ import '../../utils/keyDef/readNextDescriptor.js';
15
+ import '../../utils/misc/level.js';
16
+ import '../../options.js';
17
+
18
+ behavior.cut = (event, target, config)=>{
19
+ return ()=>{
20
+ if (isEditable(target)) {
21
+ input(config, target, '', 'deleteByCut');
22
+ }
23
+ };
24
+ };
@@ -0,0 +1,7 @@
1
+ import './click.js';
2
+ import './cut.js';
3
+ import './keydown.js';
4
+ import './keypress.js';
5
+ import './keyup.js';
6
+ import './paste.js';
7
+ export { behavior } from './registry.js';
@@ -0,0 +1,136 @@
1
+ import '../../utils/click/isClickableInput.js';
2
+ import '../../utils/dataTransfer/Clipboard.js';
3
+ import { getValue } from '../../utils/edit/getValue.js';
4
+ import { input } from '../../utils/edit/input.js';
5
+ import { isContentEditable } from '../../utils/edit/isContentEditable.js';
6
+ import { isEditable } from '../../utils/edit/isEditable.js';
7
+ import { walkRadio } from '../../utils/edit/walkRadio.js';
8
+ import '@testing-library/dom';
9
+ import { isElementType } from '../../utils/misc/isElementType.js';
10
+ import '@testing-library/dom/dist/helpers.js';
11
+ import { moveSelection, setSelectionRange, hasOwnSelection } from '../../utils/focus/selection.js';
12
+ import { focus } from '../../utils/focus/focus.js';
13
+ import { getTabDestination } from '../../utils/focus/getTabDestination.js';
14
+ import { selectAll } from '../../utils/focus/selectAll.js';
15
+ import '../../utils/keyDef/readNextDescriptor.js';
16
+ import '../../utils/misc/level.js';
17
+ import '../../options.js';
18
+ import '../eventMap.js';
19
+ import './click.js';
20
+ import './cut.js';
21
+ import './keypress.js';
22
+ import './keyup.js';
23
+ import './paste.js';
24
+ import { behavior } from './registry.js';
25
+ import { setUISelection } from '../../document/selection.js';
26
+
27
+ behavior.keydown = (event, target, config)=>{
28
+ var ref;
29
+ var ref1;
30
+ return (ref1 = (ref = keydownBehavior[event.key]) === null || ref === void 0 ? void 0 : ref.call(keydownBehavior, event, target, config)) !== null && ref1 !== void 0 ? ref1 : combinationBehavior(event, target, config);
31
+ };
32
+ const keydownBehavior = {
33
+ ArrowDown: (event, target, config)=>{
34
+ /* istanbul ignore else */ if (isElementType(target, 'input', {
35
+ type: 'radio'
36
+ })) {
37
+ return ()=>walkRadio(config, target, -1);
38
+ }
39
+ },
40
+ ArrowLeft: (event, target, config)=>{
41
+ if (isElementType(target, 'input', {
42
+ type: 'radio'
43
+ })) {
44
+ return ()=>walkRadio(config, target, -1);
45
+ }
46
+ return ()=>moveSelection(target, -1);
47
+ },
48
+ ArrowRight: (event, target, config)=>{
49
+ if (isElementType(target, 'input', {
50
+ type: 'radio'
51
+ })) {
52
+ return ()=>walkRadio(config, target, 1);
53
+ }
54
+ return ()=>moveSelection(target, 1);
55
+ },
56
+ ArrowUp: (event, target, config)=>{
57
+ /* istanbul ignore else */ if (isElementType(target, 'input', {
58
+ type: 'radio'
59
+ })) {
60
+ return ()=>walkRadio(config, target, 1);
61
+ }
62
+ },
63
+ Backspace: (event, target, config)=>{
64
+ if (isEditable(target)) {
65
+ return ()=>{
66
+ input(config, target, '', 'deleteContentBackward');
67
+ };
68
+ }
69
+ },
70
+ Delete: (event, target, config)=>{
71
+ if (isEditable(target)) {
72
+ return ()=>{
73
+ input(config, target, '', 'deleteContentForward');
74
+ };
75
+ }
76
+ },
77
+ End: (event, target)=>{
78
+ if (isElementType(target, [
79
+ 'input',
80
+ 'textarea'
81
+ ]) || isContentEditable(target)) {
82
+ return ()=>{
83
+ var ref;
84
+ var ref1;
85
+ const newPos = (ref1 = (ref = getValue(target)) === null || ref === void 0 ? void 0 : ref.length) !== null && ref1 !== void 0 ? ref1 : /* istanbul ignore next */ 0;
86
+ setSelectionRange(target, newPos, newPos);
87
+ };
88
+ }
89
+ },
90
+ Home: (event, target)=>{
91
+ if (isElementType(target, [
92
+ 'input',
93
+ 'textarea'
94
+ ]) || isContentEditable(target)) {
95
+ return ()=>{
96
+ setSelectionRange(target, 0, 0);
97
+ };
98
+ }
99
+ },
100
+ PageDown: (event, target)=>{
101
+ if (isElementType(target, [
102
+ 'input'
103
+ ])) {
104
+ return ()=>{
105
+ const newPos = getValue(target).length;
106
+ setSelectionRange(target, newPos, newPos);
107
+ };
108
+ }
109
+ },
110
+ PageUp: (event, target)=>{
111
+ if (isElementType(target, [
112
+ 'input'
113
+ ])) {
114
+ return ()=>{
115
+ setSelectionRange(target, 0, 0);
116
+ };
117
+ }
118
+ },
119
+ Tab: (event, target, config)=>{
120
+ return ()=>{
121
+ const dest = getTabDestination(target, config.system.keyboard.modifiers.Shift);
122
+ focus(dest);
123
+ if (hasOwnSelection(dest)) {
124
+ setUISelection(dest, {
125
+ anchorOffset: 0,
126
+ focusOffset: dest.value.length
127
+ });
128
+ }
129
+ };
130
+ }
131
+ };
132
+ const combinationBehavior = (event, target, config)=>{
133
+ if (event.code === 'KeyA' && config.system.keyboard.modifiers.Control) {
134
+ return ()=>selectAll(target);
135
+ }
136
+ };
@@ -0,0 +1,56 @@
1
+ import { dispatchUIEvent } from '../index.js';
2
+ import '../../utils/click/isClickableInput.js';
3
+ import '../../utils/dataTransfer/Clipboard.js';
4
+ import { isContentEditable } from '../../utils/edit/isContentEditable.js';
5
+ import { input } from '../../utils/edit/input.js';
6
+ import { isEditable } from '../../utils/edit/isEditable.js';
7
+ import '@testing-library/dom';
8
+ import { isElementType } from '../../utils/misc/isElementType.js';
9
+ import '@testing-library/dom/dist/helpers.js';
10
+ import '../../utils/keyDef/readNextDescriptor.js';
11
+ import '../../utils/misc/level.js';
12
+ import '../../options.js';
13
+ import { behavior } from './registry.js';
14
+
15
+ behavior.keypress = (event, target, config)=>{
16
+ if (event.key === 'Enter') {
17
+ if (isElementType(target, 'button') || isElementType(target, 'input') && ClickInputOnEnter.includes(target.type) || isElementType(target, 'a') && Boolean(target.href)) {
18
+ return ()=>{
19
+ dispatchUIEvent(config, target, 'click');
20
+ };
21
+ } else if (isElementType(target, 'input')) {
22
+ const form = target.form;
23
+ const submit = form === null || form === void 0 ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
24
+ if (submit) {
25
+ return ()=>dispatchUIEvent(config, submit, 'click');
26
+ } else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll('input').length === 1) {
27
+ return ()=>dispatchUIEvent(config, form, 'submit');
28
+ } else {
29
+ return;
30
+ }
31
+ }
32
+ }
33
+ if (isEditable(target)) {
34
+ const inputType = event.key === 'Enter' ? isContentEditable(target) && !config.system.keyboard.modifiers.Shift ? 'insertParagraph' : 'insertLineBreak' : 'insertText';
35
+ const inputData = event.key === 'Enter' ? '\n' : event.key;
36
+ return ()=>input(config, target, inputData, inputType);
37
+ }
38
+ };
39
+ const ClickInputOnEnter = [
40
+ 'button',
41
+ 'color',
42
+ 'file',
43
+ 'image',
44
+ 'reset',
45
+ 'submit',
46
+ ];
47
+ const SubmitSingleInputOnEnter = [
48
+ 'email',
49
+ 'month',
50
+ 'password',
51
+ 'search',
52
+ 'tel',
53
+ 'text',
54
+ 'url',
55
+ 'week',
56
+ ];
@@ -0,0 +1,23 @@
1
+ import { isClickableInput } from '../../utils/click/isClickableInput.js';
2
+ import '../../utils/dataTransfer/Clipboard.js';
3
+ import { dispatchUIEvent } from '../index.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 '../../utils/misc/level.js';
10
+ import '../../options.js';
11
+ import { behavior } from './registry.js';
12
+
13
+ behavior.keyup = (event, target, config)=>{
14
+ var ref;
15
+ return (ref = keyupBehavior[event.key]) === null || ref === void 0 ? void 0 : ref.call(keyupBehavior, event, target, config);
16
+ };
17
+ const keyupBehavior = {
18
+ ' ': (event, target, config)=>{
19
+ if (isClickableInput(target)) {
20
+ return ()=>dispatchUIEvent(config, target, 'click');
21
+ }
22
+ }
23
+ };
@@ -0,0 +1,28 @@
1
+ import '../../utils/click/isClickableInput.js';
2
+ import '../../utils/dataTransfer/Clipboard.js';
3
+ import '../eventMap.js';
4
+ import './click.js';
5
+ import './cut.js';
6
+ import './keydown.js';
7
+ import './keypress.js';
8
+ import './keyup.js';
9
+ import { behavior } from './registry.js';
10
+ import '@testing-library/dom';
11
+ import { input } from '../../utils/edit/input.js';
12
+ import { isEditable } from '../../utils/edit/isEditable.js';
13
+ import '@testing-library/dom/dist/helpers.js';
14
+ import '../../utils/keyDef/readNextDescriptor.js';
15
+ import '../../utils/misc/level.js';
16
+ import '../../options.js';
17
+
18
+ behavior.paste = (event, target, config)=>{
19
+ if (isEditable(target)) {
20
+ return ()=>{
21
+ var ref;
22
+ const insertData = (ref = event.clipboardData) === null || ref === void 0 ? void 0 : ref.getData('text');
23
+ if (insertData) {
24
+ input(config, target, insertData, 'insertFromPaste');
25
+ }
26
+ };
27
+ }
28
+ };
@@ -0,0 +1,3 @@
1
+ const behavior = {};
2
+
3
+ export { behavior };
@@ -0,0 +1,205 @@
1
+ import '../utils/click/isClickableInput.js';
2
+ import '../utils/dataTransfer/Clipboard.js';
3
+ import './behavior/click.js';
4
+ import './behavior/cut.js';
5
+ import './behavior/keydown.js';
6
+ import './behavior/keypress.js';
7
+ import './behavior/keyup.js';
8
+ import './behavior/paste.js';
9
+ import '@testing-library/dom';
10
+ import { eventMap, eventMapKeys } from './eventMap.js';
11
+ import '../utils/edit/maxLength.js';
12
+ import '../utils/edit/isEditable.js';
13
+ import { getWindow } from '../utils/misc/getWindow.js';
14
+ import '../utils/keyDef/readNextDescriptor.js';
15
+ import '../utils/misc/level.js';
16
+ import '../options.js';
17
+
18
+ const eventInitializer = {
19
+ ClipboardEvent: [
20
+ initClipboardEvent
21
+ ],
22
+ InputEvent: [
23
+ initUIEvent,
24
+ initInputEvent
25
+ ],
26
+ MouseEvent: [
27
+ initUIEvent,
28
+ initUIEventModififiers,
29
+ initMouseEvent
30
+ ],
31
+ PointerEvent: [
32
+ initUIEvent,
33
+ initUIEventModififiers,
34
+ initMouseEvent,
35
+ initPointerEvent,
36
+ ],
37
+ KeyboardEvent: [
38
+ initUIEvent,
39
+ initUIEventModififiers,
40
+ initKeyboardEvent
41
+ ]
42
+ };
43
+ function createEvent(type, target, init) {
44
+ var ref;
45
+ const window = getWindow(target);
46
+ const { EventType , defaultInit } = eventMap[eventMapKeys[type]];
47
+ const event = new (getEventConstructors(window))[EventType](type, defaultInit);
48
+ (ref = eventInitializer[EventType]) === null || ref === void 0 ? void 0 : ref.forEach((f)=>f(event, init !== null && init !== void 0 ? init : {}));
49
+ return event;
50
+ }
51
+ /* istanbul ignore next */ function getEventConstructors(window) {
52
+ var _Event;
53
+ /* eslint-disable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-extraneous-class */ const Event = (_Event = window.Event) !== null && _Event !== void 0 ? _Event : class Event {
54
+ };
55
+ var _AnimationEvent;
56
+ const AnimationEvent = (_AnimationEvent = window.AnimationEvent) !== null && _AnimationEvent !== void 0 ? _AnimationEvent : class AnimationEvent extends Event {
57
+ };
58
+ var _ClipboardEvent;
59
+ const ClipboardEvent = (_ClipboardEvent = window.ClipboardEvent) !== null && _ClipboardEvent !== void 0 ? _ClipboardEvent : class ClipboardEvent extends Event {
60
+ };
61
+ var _PopStateEvent;
62
+ const PopStateEvent = (_PopStateEvent = window.PopStateEvent) !== null && _PopStateEvent !== void 0 ? _PopStateEvent : class PopStateEvent extends Event {
63
+ };
64
+ var _ProgressEvent;
65
+ const ProgressEvent = (_ProgressEvent = window.ProgressEvent) !== null && _ProgressEvent !== void 0 ? _ProgressEvent : class ProgressEvent extends Event {
66
+ };
67
+ var _TransitionEvent;
68
+ const TransitionEvent = (_TransitionEvent = window.TransitionEvent) !== null && _TransitionEvent !== void 0 ? _TransitionEvent : class TransitionEvent extends Event {
69
+ };
70
+ var _UIEvent;
71
+ const UIEvent = (_UIEvent = window.UIEvent) !== null && _UIEvent !== void 0 ? _UIEvent : class UIEvent extends Event {
72
+ };
73
+ var _CompositionEvent;
74
+ const CompositionEvent = (_CompositionEvent = window.CompositionEvent) !== null && _CompositionEvent !== void 0 ? _CompositionEvent : class CompositionEvent extends UIEvent {
75
+ };
76
+ var _FocusEvent;
77
+ const FocusEvent = (_FocusEvent = window.FocusEvent) !== null && _FocusEvent !== void 0 ? _FocusEvent : class FocusEvent extends UIEvent {
78
+ };
79
+ var _InputEvent;
80
+ const InputEvent = (_InputEvent = window.InputEvent) !== null && _InputEvent !== void 0 ? _InputEvent : class InputEvent extends UIEvent {
81
+ };
82
+ var _KeyboardEvent;
83
+ const KeyboardEvent = (_KeyboardEvent = window.KeyboardEvent) !== null && _KeyboardEvent !== void 0 ? _KeyboardEvent : class KeyboardEvent extends UIEvent {
84
+ };
85
+ var _MouseEvent;
86
+ const MouseEvent = (_MouseEvent = window.MouseEvent) !== null && _MouseEvent !== void 0 ? _MouseEvent : class MouseEvent extends UIEvent {
87
+ };
88
+ var _DragEvent;
89
+ const DragEvent = (_DragEvent = window.DragEvent) !== null && _DragEvent !== void 0 ? _DragEvent : class DragEvent extends MouseEvent {
90
+ };
91
+ var _PointerEvent;
92
+ const PointerEvent = (_PointerEvent = window.PointerEvent) !== null && _PointerEvent !== void 0 ? _PointerEvent : class PointerEvent extends MouseEvent {
93
+ };
94
+ var _TouchEvent;
95
+ const TouchEvent = (_TouchEvent = window.TouchEvent) !== null && _TouchEvent !== void 0 ? _TouchEvent : class TouchEvent extends UIEvent {
96
+ };
97
+ /* eslint-enable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-extraneous-class */ return {
98
+ Event,
99
+ AnimationEvent,
100
+ ClipboardEvent,
101
+ PopStateEvent,
102
+ ProgressEvent,
103
+ TransitionEvent,
104
+ UIEvent,
105
+ CompositionEvent,
106
+ FocusEvent,
107
+ InputEvent,
108
+ KeyboardEvent,
109
+ MouseEvent,
110
+ DragEvent,
111
+ PointerEvent,
112
+ TouchEvent
113
+ };
114
+ }
115
+ function assignProps(obj, props) {
116
+ for (const [key, value] of Object.entries(props)){
117
+ Object.defineProperty(obj, key, {
118
+ get: ()=>value !== null && value !== void 0 ? value : null
119
+ });
120
+ }
121
+ }
122
+ function sanitizeNumber(n) {
123
+ return Number(n !== null && n !== void 0 ? n : 0);
124
+ }
125
+ function initClipboardEvent(event, { clipboardData }) {
126
+ assignProps(event, {
127
+ clipboardData
128
+ });
129
+ }
130
+ function initInputEvent(event, { data , inputType , isComposing }) {
131
+ assignProps(event, {
132
+ data,
133
+ isComposing: Boolean(isComposing),
134
+ inputType: String(inputType)
135
+ });
136
+ }
137
+ function initUIEvent(event, { view , detail }) {
138
+ assignProps(event, {
139
+ view,
140
+ detail: sanitizeNumber(detail !== null && detail !== void 0 ? detail : 0)
141
+ });
142
+ }
143
+ function initUIEventModififiers(event, { altKey , ctrlKey , metaKey , shiftKey , modifierAltGraph , modifierCapsLock , modifierFn , modifierFnLock , modifierNumLock , modifierScrollLock , modifierSymbol , modifierSymbolLock }) {
144
+ assignProps(event, {
145
+ altKey: Boolean(altKey),
146
+ ctrlKey: Boolean(ctrlKey),
147
+ metaKey: Boolean(metaKey),
148
+ shiftKey: Boolean(shiftKey),
149
+ getModifierState (k) {
150
+ return Boolean({
151
+ Alt: altKey,
152
+ AltGraph: modifierAltGraph,
153
+ CapsLock: modifierCapsLock,
154
+ Control: ctrlKey,
155
+ Fn: modifierFn,
156
+ FnLock: modifierFnLock,
157
+ Meta: metaKey,
158
+ NumLock: modifierNumLock,
159
+ ScrollLock: modifierScrollLock,
160
+ Shift: shiftKey,
161
+ Symbol: modifierSymbol,
162
+ SymbolLock: modifierSymbolLock
163
+ }[k]);
164
+ }
165
+ });
166
+ }
167
+ function initKeyboardEvent(event, { key , code , location , repeat , isComposing , charCode }) {
168
+ assignProps(event, {
169
+ key: String(key),
170
+ code: String(code),
171
+ location: sanitizeNumber(location),
172
+ repeat: Boolean(repeat),
173
+ isComposing: Boolean(isComposing),
174
+ charCode
175
+ });
176
+ }
177
+ function initMouseEvent(event, { x , y , screenX , screenY , clientX =x , clientY =y , button , buttons , relatedTarget }) {
178
+ assignProps(event, {
179
+ screenX: sanitizeNumber(screenX),
180
+ screenY: sanitizeNumber(screenY),
181
+ clientX: sanitizeNumber(clientX),
182
+ x: sanitizeNumber(clientX),
183
+ clientY: sanitizeNumber(clientY),
184
+ y: sanitizeNumber(clientY),
185
+ button: sanitizeNumber(button),
186
+ buttons: sanitizeNumber(buttons),
187
+ relatedTarget
188
+ });
189
+ }
190
+ function initPointerEvent(event, { pointerId , width , height , pressure , tangentialPressure , tiltX , tiltY , twist , pointerType , isPrimary }) {
191
+ assignProps(event, {
192
+ pointerId: sanitizeNumber(pointerId),
193
+ width: sanitizeNumber(width),
194
+ height: sanitizeNumber(height),
195
+ pressure: sanitizeNumber(pressure),
196
+ tangentialPressure: sanitizeNumber(tangentialPressure),
197
+ tiltX: sanitizeNumber(tiltX),
198
+ tiltY: sanitizeNumber(tiltY),
199
+ twist: sanitizeNumber(twist),
200
+ pointerType: String(pointerType),
201
+ isPrimary: Boolean(isPrimary)
202
+ });
203
+ }
204
+
205
+ export { createEvent };
@@ -0,0 +1,34 @@
1
+ import './behavior/click.js';
2
+ import './behavior/cut.js';
3
+ import './behavior/keydown.js';
4
+ import './behavior/keypress.js';
5
+ import './behavior/keyup.js';
6
+ import './behavior/paste.js';
7
+ import { behavior } from './behavior/registry.js';
8
+ import { wrapEvent } from './wrapEvent.js';
9
+
10
+ function dispatchEvent(config, target, event, preventDefault = false) {
11
+ var ref;
12
+ const type = event.type;
13
+ const behaviorImplementation = preventDefault ? ()=>{} : (ref = behavior[type]) === null || ref === void 0 ? void 0 : ref(event, target, config);
14
+ if (behaviorImplementation) {
15
+ event.preventDefault();
16
+ let defaultPrevented = false;
17
+ Object.defineProperty(event, 'defaultPrevented', {
18
+ get: ()=>defaultPrevented
19
+ });
20
+ Object.defineProperty(event, 'preventDefault', {
21
+ value: ()=>{
22
+ defaultPrevented = event.cancelable;
23
+ }
24
+ });
25
+ wrapEvent(()=>target.dispatchEvent(event));
26
+ if (!defaultPrevented) {
27
+ behaviorImplementation();
28
+ }
29
+ return !defaultPrevented;
30
+ }
31
+ return wrapEvent(()=>target.dispatchEvent(event));
32
+ }
33
+
34
+ export { dispatchEvent };