@testing-library/user-event 14.4.0 → 14.4.3

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 (231) hide show
  1. package/dist/cjs/clipboard/copy.js +6 -15
  2. package/dist/cjs/clipboard/cut.js +6 -15
  3. package/dist/cjs/clipboard/paste.js +6 -14
  4. package/dist/cjs/convenience/click.js +1 -4
  5. package/dist/cjs/convenience/hover.js +2 -12
  6. package/dist/cjs/document/UI.js +94 -0
  7. package/dist/cjs/document/copySelection.js +37 -0
  8. package/dist/cjs/document/getValueOrTextContent.js +27 -0
  9. package/dist/cjs/document/index.js +13 -68
  10. package/dist/cjs/document/interceptor.js +87 -4
  11. package/dist/cjs/document/prepareDocument.js +67 -0
  12. package/dist/cjs/document/trackValue.js +65 -0
  13. package/dist/cjs/event/behavior/click.js +8 -12
  14. package/dist/cjs/event/behavior/cut.js +5 -11
  15. package/dist/cjs/event/behavior/keydown.js +43 -43
  16. package/dist/cjs/event/behavior/keypress.js +9 -10
  17. package/dist/cjs/event/behavior/keyup.js +6 -7
  18. package/dist/cjs/event/behavior/paste.js +7 -12
  19. package/dist/cjs/event/createEvent.js +37 -28
  20. package/dist/cjs/event/dispatchEvent.js +21 -2
  21. package/dist/cjs/event/focus.js +44 -0
  22. package/dist/cjs/event/index.js +24 -17
  23. package/dist/cjs/{utils/edit → event}/input.js +50 -47
  24. package/dist/cjs/{utils/edit/walkRadio.js → event/radio.js} +13 -7
  25. package/dist/cjs/event/selection/getInputRange.js +20 -0
  26. package/dist/cjs/event/selection/getTargetTypeAndSelection.js +40 -0
  27. package/dist/cjs/event/selection/index.js +26 -0
  28. package/dist/cjs/event/selection/modifySelection.js +30 -0
  29. package/dist/cjs/event/selection/modifySelectionPerMouse.js +49 -0
  30. package/dist/cjs/event/selection/moveSelection.js +47 -0
  31. package/dist/cjs/{utils/focus → event/selection}/resolveCaretPosition.js +11 -19
  32. package/dist/cjs/event/selection/selectAll.js +47 -0
  33. package/dist/cjs/event/selection/setSelection.js +30 -0
  34. package/dist/cjs/event/selection/setSelectionPerMouse.js +90 -0
  35. package/dist/cjs/event/selection/setSelectionRange.js +40 -0
  36. package/dist/cjs/event/selection/updateSelectionOnFocus.js +45 -0
  37. package/dist/cjs/keyboard/index.js +13 -23
  38. package/dist/cjs/keyboard/parseKeyDef.js +8 -13
  39. package/dist/cjs/options.js +0 -28
  40. package/dist/cjs/pointer/index.js +28 -34
  41. package/dist/cjs/pointer/parseKeyDef.js +1 -9
  42. package/dist/cjs/setup/directApi.js +6 -6
  43. package/dist/cjs/setup/index.js +0 -2
  44. package/dist/cjs/setup/setup.js +69 -38
  45. package/dist/cjs/system/index.js +4 -2
  46. package/dist/cjs/system/keyboard.js +32 -32
  47. package/dist/cjs/system/pointer/buttons.js +3 -1
  48. package/dist/cjs/system/pointer/device.js +3 -1
  49. package/dist/cjs/system/pointer/index.js +82 -79
  50. package/dist/cjs/system/pointer/mouse.js +97 -81
  51. package/dist/cjs/system/pointer/pointer.js +45 -46
  52. package/dist/cjs/system/pointer/shared.js +10 -0
  53. package/dist/cjs/utility/clear.js +10 -11
  54. package/dist/cjs/utility/selectOptions.js +17 -19
  55. package/dist/cjs/utility/type.js +6 -15
  56. package/dist/cjs/utility/upload.js +9 -15
  57. package/dist/cjs/utils/dataTransfer/Clipboard.js +11 -21
  58. package/dist/cjs/utils/dataTransfer/DataTransfer.js +22 -19
  59. package/dist/cjs/utils/edit/isEditable.js +6 -10
  60. package/dist/cjs/utils/edit/maxLength.js +6 -16
  61. package/dist/cjs/utils/edit/setFiles.js +4 -2
  62. package/dist/cjs/utils/edit/{buildTimeValue.js → timeValue.js} +6 -0
  63. package/dist/cjs/utils/focus/cursor.js +2 -17
  64. package/dist/cjs/utils/focus/getActiveElement.js +3 -2
  65. package/dist/cjs/utils/focus/selection.js +1 -266
  66. package/dist/cjs/utils/index.js +7 -32
  67. package/dist/cjs/utils/keyDef/readNextDescriptor.js +5 -3
  68. package/dist/cjs/utils/misc/isDisabled.js +2 -1
  69. package/dist/cjs/utils/misc/isVisible.js +1 -1
  70. package/dist/cjs/utils/misc/level.js +4 -6
  71. package/dist/cjs/utils/pointer/cssPointerEvents.js +26 -32
  72. package/dist/esm/clipboard/copy.js +6 -15
  73. package/dist/esm/clipboard/cut.js +6 -15
  74. package/dist/esm/clipboard/paste.js +6 -14
  75. package/dist/esm/convenience/click.js +1 -4
  76. package/dist/esm/convenience/hover.js +2 -12
  77. package/dist/esm/document/UI.js +79 -0
  78. package/dist/esm/document/copySelection.js +33 -0
  79. package/dist/esm/document/getValueOrTextContent.js +23 -0
  80. package/dist/esm/document/index.js +4 -66
  81. package/dist/esm/document/interceptor.js +85 -5
  82. package/dist/esm/document/prepareDocument.js +63 -0
  83. package/dist/esm/document/trackValue.js +59 -0
  84. package/dist/esm/event/behavior/click.js +8 -12
  85. package/dist/esm/event/behavior/cut.js +5 -11
  86. package/dist/esm/event/behavior/keydown.js +36 -36
  87. package/dist/esm/event/behavior/keypress.js +9 -10
  88. package/dist/esm/event/behavior/keyup.js +6 -7
  89. package/dist/esm/event/behavior/paste.js +7 -12
  90. package/dist/esm/event/createEvent.js +37 -28
  91. package/dist/esm/event/dispatchEvent.js +20 -3
  92. package/dist/esm/event/focus.js +39 -0
  93. package/dist/esm/event/index.js +14 -19
  94. package/dist/esm/{utils/edit → event}/input.js +37 -34
  95. package/dist/esm/{utils/edit/walkRadio.js → event/radio.js} +13 -7
  96. package/dist/esm/event/selection/getInputRange.js +16 -0
  97. package/dist/esm/event/selection/getTargetTypeAndSelection.js +36 -0
  98. package/dist/esm/event/selection/index.js +9 -0
  99. package/dist/esm/event/selection/modifySelection.js +26 -0
  100. package/dist/esm/event/selection/modifySelectionPerMouse.js +45 -0
  101. package/dist/esm/event/selection/moveSelection.js +43 -0
  102. package/dist/esm/{utils/focus → event/selection}/resolveCaretPosition.js +11 -19
  103. package/dist/esm/event/selection/selectAll.js +42 -0
  104. package/dist/esm/event/selection/setSelection.js +26 -0
  105. package/dist/esm/event/selection/setSelectionPerMouse.js +86 -0
  106. package/dist/esm/event/selection/setSelectionRange.js +36 -0
  107. package/dist/esm/event/selection/updateSelectionOnFocus.js +41 -0
  108. package/dist/esm/keyboard/index.js +13 -23
  109. package/dist/esm/keyboard/parseKeyDef.js +8 -13
  110. package/dist/esm/options.js +1 -26
  111. package/dist/esm/pointer/index.js +28 -34
  112. package/dist/esm/pointer/parseKeyDef.js +1 -9
  113. package/dist/esm/setup/directApi.js +6 -6
  114. package/dist/esm/setup/index.js +0 -1
  115. package/dist/esm/setup/setup.js +63 -33
  116. package/dist/esm/system/index.js +4 -2
  117. package/dist/esm/system/keyboard.js +32 -32
  118. package/dist/esm/system/pointer/buttons.js +3 -1
  119. package/dist/esm/system/pointer/device.js +3 -1
  120. package/dist/esm/system/pointer/index.js +83 -79
  121. package/dist/esm/system/pointer/mouse.js +95 -79
  122. package/dist/esm/system/pointer/pointer.js +44 -45
  123. package/dist/esm/system/pointer/shared.js +6 -0
  124. package/dist/esm/utility/clear.js +10 -11
  125. package/dist/esm/utility/selectOptions.js +17 -19
  126. package/dist/esm/utility/type.js +6 -15
  127. package/dist/esm/utility/upload.js +9 -15
  128. package/dist/esm/utils/dataTransfer/Clipboard.js +11 -21
  129. package/dist/esm/utils/dataTransfer/DataTransfer.js +22 -19
  130. package/dist/esm/utils/edit/isEditable.js +4 -8
  131. package/dist/esm/utils/edit/maxLength.js +5 -16
  132. package/dist/esm/utils/edit/setFiles.js +4 -2
  133. package/dist/esm/utils/edit/{buildTimeValue.js → timeValue.js} +6 -1
  134. package/dist/esm/utils/focus/cursor.js +2 -17
  135. package/dist/esm/utils/focus/getActiveElement.js +3 -2
  136. package/dist/esm/utils/focus/selection.js +3 -260
  137. package/dist/esm/utils/index.js +4 -11
  138. package/dist/esm/utils/keyDef/readNextDescriptor.js +5 -3
  139. package/dist/esm/utils/misc/isDisabled.js +2 -1
  140. package/dist/esm/utils/misc/isVisible.js +1 -1
  141. package/dist/esm/utils/misc/level.js +4 -6
  142. package/dist/esm/utils/pointer/cssPointerEvents.js +26 -32
  143. package/dist/types/clipboard/copy.d.ts +1 -1
  144. package/dist/types/clipboard/cut.d.ts +1 -1
  145. package/dist/types/clipboard/paste.d.ts +1 -1
  146. package/dist/types/convenience/click.d.ts +1 -1
  147. package/dist/types/convenience/hover.d.ts +1 -1
  148. package/dist/types/document/UI.d.ts +42 -0
  149. package/dist/types/{utils/focus → document}/copySelection.d.ts +0 -0
  150. package/dist/types/document/getValueOrTextContent.d.ts +1 -0
  151. package/dist/types/document/index.d.ts +5 -10
  152. package/dist/types/document/interceptor.d.ts +3 -0
  153. package/dist/types/document/prepareDocument.d.ts +8 -0
  154. package/dist/types/document/trackValue.d.ts +17 -0
  155. package/dist/types/event/behavior/registry.d.ts +2 -2
  156. package/dist/types/event/dispatchEvent.d.ts +5 -2
  157. package/dist/types/event/focus.d.ts +5 -0
  158. package/dist/types/event/index.d.ts +6 -4
  159. package/dist/types/event/input.d.ts +2 -0
  160. package/dist/types/event/radio.d.ts +4 -0
  161. package/dist/types/event/selection/getInputRange.d.ts +5 -0
  162. package/dist/types/event/selection/getTargetTypeAndSelection.d.ts +10 -0
  163. package/dist/types/event/selection/index.d.ts +15 -0
  164. package/dist/types/event/selection/modifySelection.d.ts +8 -0
  165. package/dist/types/event/selection/modifySelectionPerMouse.d.ts +7 -0
  166. package/dist/types/event/selection/moveSelection.d.ts +4 -0
  167. package/dist/types/{utils/focus → event/selection}/resolveCaretPosition.d.ts +0 -0
  168. package/dist/types/{utils/focus → event/selection}/selectAll.d.ts +0 -0
  169. package/dist/types/event/selection/setSelection.d.ts +10 -0
  170. package/dist/types/event/selection/setSelectionPerMouse.d.ts +8 -0
  171. package/dist/types/event/selection/setSelectionRange.d.ts +6 -0
  172. package/dist/types/event/selection/updateSelectionOnFocus.d.ts +5 -0
  173. package/dist/types/keyboard/index.d.ts +2 -2
  174. package/dist/types/options.d.ts +0 -8
  175. package/dist/types/pointer/index.d.ts +3 -3
  176. package/dist/types/setup/directApi.d.ts +1 -1
  177. package/dist/types/setup/index.d.ts +2 -15
  178. package/dist/types/setup/setup.d.ts +25 -7
  179. package/dist/types/system/keyboard.d.ts +3 -3
  180. package/dist/types/system/pointer/buttons.d.ts +1 -1
  181. package/dist/types/system/pointer/index.d.ts +7 -25
  182. package/dist/types/system/pointer/mouse.d.ts +5 -5
  183. package/dist/types/system/pointer/pointer.d.ts +7 -7
  184. package/dist/types/system/pointer/shared.d.ts +20 -0
  185. package/dist/types/utility/clear.d.ts +1 -1
  186. package/dist/types/utility/selectOptions.d.ts +1 -1
  187. package/dist/types/utility/type.d.ts +3 -3
  188. package/dist/types/utility/upload.d.ts +1 -1
  189. package/dist/types/utils/click/isClickableInput.d.ts +2 -2
  190. package/dist/types/utils/edit/isEditable.d.ts +5 -6
  191. package/dist/types/utils/edit/maxLength.d.ts +14 -1
  192. package/dist/types/utils/edit/{isValidDateOrTimeValue.d.ts → timeValue.d.ts} +1 -0
  193. package/dist/types/utils/focus/selection.d.ts +4 -69
  194. package/dist/types/utils/index.d.ts +2 -9
  195. package/dist/types/utils/misc/level.d.ts +4 -13
  196. package/dist/types/utils/misc/wait.d.ts +2 -2
  197. package/dist/types/utils/pointer/cssPointerEvents.d.ts +4 -4
  198. package/package.json +29 -4
  199. package/dist/cjs/document/selection.js +0 -107
  200. package/dist/cjs/document/setRangeText.js +0 -21
  201. package/dist/cjs/document/value.js +0 -125
  202. package/dist/cjs/setup/config.js +0 -7
  203. package/dist/cjs/utils/edit/getValue.js +0 -35
  204. package/dist/cjs/utils/edit/isValidDateOrTimeValue.js +0 -11
  205. package/dist/cjs/utils/focus/blur.js +0 -16
  206. package/dist/cjs/utils/focus/copySelection.js +0 -46
  207. package/dist/cjs/utils/focus/focus.js +0 -26
  208. package/dist/cjs/utils/focus/selectAll.js +0 -54
  209. package/dist/cjs/utils/misc/eventWrapper.js +0 -15
  210. package/dist/esm/document/selection.js +0 -99
  211. package/dist/esm/document/setRangeText.js +0 -17
  212. package/dist/esm/document/value.js +0 -115
  213. package/dist/esm/setup/config.js +0 -3
  214. package/dist/esm/utils/edit/getValue.js +0 -31
  215. package/dist/esm/utils/edit/isValidDateOrTimeValue.js +0 -7
  216. package/dist/esm/utils/focus/blur.js +0 -12
  217. package/dist/esm/utils/focus/copySelection.js +0 -42
  218. package/dist/esm/utils/focus/focus.js +0 -22
  219. package/dist/esm/utils/focus/selectAll.js +0 -49
  220. package/dist/esm/utils/misc/eventWrapper.js +0 -11
  221. package/dist/types/document/selection.d.ts +0 -29
  222. package/dist/types/document/setRangeText.d.ts +0 -1
  223. package/dist/types/document/value.d.ts +0 -26
  224. package/dist/types/setup/config.d.ts +0 -6
  225. package/dist/types/utils/edit/buildTimeValue.d.ts +0 -1
  226. package/dist/types/utils/edit/getValue.d.ts +0 -1
  227. package/dist/types/utils/edit/input.d.ts +0 -2
  228. package/dist/types/utils/edit/walkRadio.d.ts +0 -4
  229. package/dist/types/utils/focus/blur.d.ts +0 -2
  230. package/dist/types/utils/focus/focus.d.ts +0 -5
  231. package/dist/types/utils/misc/eventWrapper.d.ts +0 -1
@@ -1,9 +1,21 @@
1
+ import '../utils/click/isClickableInput.js';
2
+ import '../utils/dataTransfer/Clipboard.js';
3
+ import '../utils/edit/isEditable.js';
4
+ import '../utils/edit/maxLength.js';
5
+ import { isElementType } from '../utils/misc/isElementType.js';
6
+ import '@testing-library/dom/dist/helpers.js';
7
+ import '../utils/keyDef/readNextDescriptor.js';
8
+ import '../utils/misc/level.js';
9
+ import '../options.js';
10
+ import { startTrackValue, trackOrSetValue } from './trackValue.js';
11
+ import { setUISelectionClean, setUISelectionRaw, getUIValue, setUIValueClean, isUIValue, isUISelectionStart } from './UI.js';
12
+
1
13
  const Interceptor = Symbol('Interceptor for programmatical calls');
2
14
  function prepareInterceptor(element, propName, interceptorImpl) {
3
15
  const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
4
16
  const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
5
- const target = prototypeDescriptor?.set ? 'set' : 'value';
6
- /* istanbul ignore if */ if (typeof prototypeDescriptor?.[target] !== 'function' || prototypeDescriptor[target][Interceptor]) {
17
+ const target = (prototypeDescriptor === null || prototypeDescriptor === void 0 ? void 0 : prototypeDescriptor.set) ? 'set' : 'value';
18
+ /* istanbul ignore if */ if (typeof (prototypeDescriptor === null || prototypeDescriptor === void 0 ? void 0 : prototypeDescriptor[target]) !== 'function' || prototypeDescriptor[target][Interceptor]) {
7
19
  throw new Error(`Element ${element.tagName} does not implement "${String(propName)}".`);
8
20
  }
9
21
  function intercept(...args) {
@@ -14,13 +26,81 @@ function prepareInterceptor(element, propName, interceptorImpl) {
14
26
  } else {
15
27
  realFunc.call(this, ...realArgs);
16
28
  }
17
- then?.();
29
+ then === null || then === void 0 ? void 0 : then();
18
30
  }
19
31
  intercept[Interceptor] = Interceptor;
20
32
  Object.defineProperty(element, propName, {
21
- ...objectDescriptor ?? prototypeDescriptor,
33
+ ...objectDescriptor !== null && objectDescriptor !== void 0 ? objectDescriptor : prototypeDescriptor,
22
34
  [target]: intercept
23
35
  });
24
36
  }
37
+ function prepareValueInterceptor(element) {
38
+ prepareInterceptor(element, 'value', function interceptorImpl(v) {
39
+ const isUI = isUIValue(v);
40
+ if (isUI) {
41
+ startTrackValue(this);
42
+ }
43
+ return {
44
+ applyNative: !!isUI,
45
+ realArgs: sanitizeValue(this, v),
46
+ then: isUI ? undefined : ()=>trackOrSetValue(this, String(v))
47
+ };
48
+ });
49
+ }
50
+ function sanitizeValue(element, v) {
51
+ // Workaround for JSDOM
52
+ if (isElementType(element, 'input', {
53
+ type: 'number'
54
+ }) && String(v) !== '' && !Number.isNaN(Number(v))) {
55
+ // Setting value to "1." results in `null` in JSDOM
56
+ return String(Number(v));
57
+ }
58
+ return String(v);
59
+ }
60
+ function prepareSelectionInterceptor(element) {
61
+ prepareInterceptor(element, 'setSelectionRange', function interceptorImpl(start, ...others) {
62
+ const isUI = isUISelectionStart(start);
63
+ return {
64
+ applyNative: !!isUI,
65
+ realArgs: [
66
+ Number(start),
67
+ ...others
68
+ ],
69
+ then: ()=>isUI ? undefined : setUISelectionClean(element)
70
+ };
71
+ });
72
+ prepareInterceptor(element, 'selectionStart', function interceptorImpl(v) {
73
+ return {
74
+ realArgs: v,
75
+ then: ()=>setUISelectionClean(element)
76
+ };
77
+ });
78
+ prepareInterceptor(element, 'selectionEnd', function interceptorImpl(v) {
79
+ return {
80
+ realArgs: v,
81
+ then: ()=>setUISelectionClean(element)
82
+ };
83
+ });
84
+ prepareInterceptor(element, 'select', function interceptorImpl() {
85
+ return {
86
+ realArgs: [],
87
+ then: ()=>setUISelectionRaw(element, {
88
+ anchorOffset: 0,
89
+ focusOffset: getUIValue(element).length
90
+ })
91
+ };
92
+ });
93
+ }
94
+ function prepareRangeTextInterceptor(element) {
95
+ prepareInterceptor(element, 'setRangeText', function interceptorImpl(...realArgs) {
96
+ return {
97
+ realArgs,
98
+ then: ()=>{
99
+ setUIValueClean(element);
100
+ setUISelectionClean(element);
101
+ }
102
+ };
103
+ });
104
+ }
25
105
 
26
- export { prepareInterceptor };
106
+ export { prepareInterceptor, prepareRangeTextInterceptor, prepareSelectionInterceptor, prepareValueInterceptor };
@@ -0,0 +1,63 @@
1
+ import { dispatchDOMEvent } from '../event/dispatchEvent.js';
2
+ import '../utils/click/isClickableInput.js';
3
+ import '../utils/dataTransfer/Clipboard.js';
4
+ import '../utils/edit/isEditable.js';
5
+ import '../utils/edit/maxLength.js';
6
+ import { isElementType } from '../utils/misc/isElementType.js';
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 { getInitialValue, clearInitialValue } from './UI.js';
12
+ import '@testing-library/dom';
13
+ import { prepareValueInterceptor, prepareSelectionInterceptor, prepareRangeTextInterceptor } from './interceptor.js';
14
+
15
+ const isPrepared = Symbol('Node prepared with document state workarounds');
16
+ function prepareDocument(document) {
17
+ if (document[isPrepared]) {
18
+ return;
19
+ }
20
+ document.addEventListener('focus', (e)=>{
21
+ const el = e.target;
22
+ prepareElement(el);
23
+ }, {
24
+ capture: true,
25
+ passive: true
26
+ });
27
+ // Our test environment defaults to `document.body` as `activeElement`.
28
+ // In other environments this might be `null` when preparing.
29
+ // istanbul ignore else
30
+ if (document.activeElement) {
31
+ prepareElement(document.activeElement);
32
+ }
33
+ document.addEventListener('blur', (e)=>{
34
+ const el = e.target;
35
+ const initialValue = getInitialValue(el);
36
+ if (initialValue !== undefined) {
37
+ if (el.value !== initialValue) {
38
+ dispatchDOMEvent(el, 'change');
39
+ }
40
+ clearInitialValue(el);
41
+ }
42
+ }, {
43
+ capture: true,
44
+ passive: true
45
+ });
46
+ document[isPrepared] = isPrepared;
47
+ }
48
+ function prepareElement(el) {
49
+ if (el[isPrepared]) {
50
+ return;
51
+ }
52
+ if (isElementType(el, [
53
+ 'input',
54
+ 'textarea'
55
+ ])) {
56
+ prepareValueInterceptor(el);
57
+ prepareSelectionInterceptor(el);
58
+ prepareRangeTextInterceptor(el);
59
+ }
60
+ el[isPrepared] = isPrepared;
61
+ }
62
+
63
+ export { prepareDocument };
@@ -0,0 +1,59 @@
1
+ import '../utils/click/isClickableInput.js';
2
+ import '../utils/dataTransfer/Clipboard.js';
3
+ import '../utils/edit/isEditable.js';
4
+ import '../utils/edit/maxLength.js';
5
+ import { getWindow } from '../utils/misc/getWindow.js';
6
+ import '../utils/keyDef/readNextDescriptor.js';
7
+ import '../utils/misc/level.js';
8
+ import '../options.js';
9
+ import { setUIValueClean, setUISelection, hasUISelection } from './UI.js';
10
+
11
+ const TrackChanges = Symbol('Track programmatic changes for React workaround');
12
+ // When the input event happens in the browser, React executes all event handlers
13
+ // and if they change state of a controlled value, nothing happens.
14
+ // But when we trigger the event handlers in test environment with React@17,
15
+ // the changes are rolled back before the state update is applied.
16
+ // This results in a reset cursor.
17
+ // There might be a better way to work around if we figure out
18
+ // why the batched update is executed differently in our test environment.
19
+ function isReact17Element(element) {
20
+ return Object.getOwnPropertyNames(element).some((k)=>k.startsWith('__react')) && getWindow(element).REACT_VERSION === 17;
21
+ }
22
+ function startTrackValue(element) {
23
+ if (!isReact17Element(element)) {
24
+ return;
25
+ }
26
+ element[TrackChanges] = {
27
+ previousValue: String(element.value),
28
+ tracked: []
29
+ };
30
+ }
31
+ function trackOrSetValue(element, v) {
32
+ var ref, ref1;
33
+ (ref = element[TrackChanges]) === null || ref === void 0 ? void 0 : (ref1 = ref.tracked) === null || ref1 === void 0 ? void 0 : ref1.push(v);
34
+ if (!element[TrackChanges]) {
35
+ setUIValueClean(element);
36
+ setUISelection(element, {
37
+ focusOffset: v.length
38
+ });
39
+ }
40
+ }
41
+ function commitValueAfterInput(element, cursorOffset) {
42
+ var ref;
43
+ const changes = element[TrackChanges];
44
+ element[TrackChanges] = undefined;
45
+ if (!(changes === null || changes === void 0 ? void 0 : (ref = changes.tracked) === null || ref === void 0 ? void 0 : ref.length)) {
46
+ return;
47
+ }
48
+ const isJustReactStateUpdate = changes.tracked.length === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === element.value;
49
+ if (!isJustReactStateUpdate) {
50
+ setUIValueClean(element);
51
+ }
52
+ if (hasUISelection(element)) {
53
+ setUISelection(element, {
54
+ focusOffset: isJustReactStateUpdate ? cursorOffset : element.value.length
55
+ });
56
+ }
57
+ }
58
+
59
+ export { commitValueAfterInput, startTrackValue, trackOrSetValue };
@@ -1,40 +1,36 @@
1
1
  import '../../utils/click/isClickableInput.js';
2
2
  import '../../utils/dataTransfer/Clipboard.js';
3
- import '../eventMap.js';
4
- import { dispatchEvent } from '../dispatchEvent.js';
5
- import '../../utils/edit/maxLength.js';
6
3
  import '../../utils/edit/isEditable.js';
7
- import { focus } from '../../utils/focus/focus.js';
8
- import { getWindow } from '../../utils/misc/getWindow.js';
4
+ import '../../utils/edit/maxLength.js';
9
5
  import { isElementType } from '../../utils/misc/isElementType.js';
10
- import { blur } from '../../utils/focus/blur.js';
6
+ import { getWindow } from '../../utils/misc/getWindow.js';
11
7
  import { isFocusable } from '../../utils/focus/isFocusable.js';
12
8
  import '../../utils/keyDef/readNextDescriptor.js';
13
9
  import { cloneEvent } from '../../utils/misc/cloneEvent.js';
14
- import '@testing-library/dom';
15
10
  import '../../utils/misc/level.js';
16
11
  import '../../options.js';
12
+ import { focusElement, blurElement } from '../focus.js';
17
13
  import { behavior } from './registry.js';
18
14
 
19
- behavior.click = (event, target, config)=>{
15
+ behavior.click = (event, target, instance)=>{
20
16
  const context = target.closest('button,input,label,select,textarea');
21
17
  const control = context && isElementType(context, 'label') && context.control;
22
18
  if (control) {
23
19
  return ()=>{
24
20
  if (isFocusable(control)) {
25
- focus(control);
21
+ focusElement(control);
26
22
  }
27
- dispatchEvent(config, control, cloneEvent(event));
23
+ instance.dispatchEvent(control, cloneEvent(event));
28
24
  };
29
25
  } else if (isElementType(target, 'input', {
30
26
  type: 'file'
31
27
  })) {
32
28
  return ()=>{
33
29
  // blur fires when the file selector pops up
34
- blur(target);
30
+ blurElement(target);
35
31
  target.dispatchEvent(new (getWindow(target)).Event('fileDialog'));
36
32
  // focus fires after the file selector has been closed
37
- focus(target);
33
+ focusElement(target);
38
34
  };
39
35
  }
40
36
  };
@@ -1,24 +1,18 @@
1
1
  import '../../utils/click/isClickableInput.js';
2
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
3
  import { isEditable } from '../../utils/edit/isEditable.js';
4
+ import '../../utils/edit/maxLength.js';
13
5
  import '@testing-library/dom/dist/helpers.js';
14
6
  import '../../utils/keyDef/readNextDescriptor.js';
15
7
  import '../../utils/misc/level.js';
16
8
  import '../../options.js';
9
+ import { input } from '../input.js';
10
+ import { behavior } from './registry.js';
17
11
 
18
- behavior.cut = (event, target, config)=>{
12
+ behavior.cut = (event, target, instance)=>{
19
13
  return ()=>{
20
14
  if (isEditable(target)) {
21
- input(config, target, '', 'deleteByCut');
15
+ input(instance, target, '', 'deleteByCut');
22
16
  }
23
17
  };
24
18
  };
@@ -1,74 +1,72 @@
1
+ import { getUIValue, setUISelection } from '../../document/UI.js';
2
+ import { getValueOrTextContent } from '../../document/getValueOrTextContent.js';
1
3
  import '../../utils/click/isClickableInput.js';
2
4
  import '../../utils/dataTransfer/Clipboard.js';
3
- import { getValue } from '../../utils/edit/getValue.js';
4
- import { input } from '../../utils/edit/input.js';
5
5
  import { isContentEditable } from '../../utils/edit/isContentEditable.js';
6
6
  import { isEditable } from '../../utils/edit/isEditable.js';
7
- import { walkRadio } from '../../utils/edit/walkRadio.js';
8
- import '@testing-library/dom';
7
+ import '../../utils/edit/maxLength.js';
9
8
  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
9
  import { getTabDestination } from '../../utils/focus/getTabDestination.js';
14
- import { selectAll } from '../../utils/focus/selectAll.js';
10
+ import { hasOwnSelection } from '../../utils/focus/selection.js';
15
11
  import '../../utils/keyDef/readNextDescriptor.js';
12
+ import '@testing-library/dom/dist/helpers.js';
16
13
  import '../../utils/misc/level.js';
17
14
  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';
15
+ import { focusElement } from '../focus.js';
16
+ import { input } from '../input.js';
17
+ import { moveSelection } from '../selection/moveSelection.js';
18
+ import { selectAll } from '../selection/selectAll.js';
19
+ import { setSelectionRange } from '../selection/setSelectionRange.js';
20
+ import { walkRadio } from '../radio.js';
24
21
  import { behavior } from './registry.js';
25
- import { setUISelection } from '../../document/selection.js';
26
22
 
27
- behavior.keydown = (event, target, config)=>{
28
- return keydownBehavior[event.key]?.(event, target, config) ?? combinationBehavior(event, target, config);
23
+ behavior.keydown = (event, target, instance)=>{
24
+ var ref;
25
+ var ref1;
26
+ return (ref1 = (ref = keydownBehavior[event.key]) === null || ref === void 0 ? void 0 : ref.call(keydownBehavior, event, target, instance)) !== null && ref1 !== void 0 ? ref1 : combinationBehavior(event, target, instance);
29
27
  };
30
28
  const keydownBehavior = {
31
- ArrowDown: (event, target, config)=>{
29
+ ArrowDown: (event, target, instance)=>{
32
30
  /* istanbul ignore else */ if (isElementType(target, 'input', {
33
31
  type: 'radio'
34
32
  })) {
35
- return ()=>walkRadio(config, target, -1);
33
+ return ()=>walkRadio(instance, target, -1);
36
34
  }
37
35
  },
38
- ArrowLeft: (event, target, config)=>{
36
+ ArrowLeft: (event, target, instance)=>{
39
37
  if (isElementType(target, 'input', {
40
38
  type: 'radio'
41
39
  })) {
42
- return ()=>walkRadio(config, target, -1);
40
+ return ()=>walkRadio(instance, target, -1);
43
41
  }
44
42
  return ()=>moveSelection(target, -1);
45
43
  },
46
- ArrowRight: (event, target, config)=>{
44
+ ArrowRight: (event, target, instance)=>{
47
45
  if (isElementType(target, 'input', {
48
46
  type: 'radio'
49
47
  })) {
50
- return ()=>walkRadio(config, target, 1);
48
+ return ()=>walkRadio(instance, target, 1);
51
49
  }
52
50
  return ()=>moveSelection(target, 1);
53
51
  },
54
- ArrowUp: (event, target, config)=>{
52
+ ArrowUp: (event, target, instance)=>{
55
53
  /* istanbul ignore else */ if (isElementType(target, 'input', {
56
54
  type: 'radio'
57
55
  })) {
58
- return ()=>walkRadio(config, target, 1);
56
+ return ()=>walkRadio(instance, target, 1);
59
57
  }
60
58
  },
61
- Backspace: (event, target, config)=>{
59
+ Backspace: (event, target, instance)=>{
62
60
  if (isEditable(target)) {
63
61
  return ()=>{
64
- input(config, target, '', 'deleteContentBackward');
62
+ input(instance, target, '', 'deleteContentBackward');
65
63
  };
66
64
  }
67
65
  },
68
- Delete: (event, target, config)=>{
66
+ Delete: (event, target, instance)=>{
69
67
  if (isEditable(target)) {
70
68
  return ()=>{
71
- input(config, target, '', 'deleteContentForward');
69
+ input(instance, target, '', 'deleteContentForward');
72
70
  };
73
71
  }
74
72
  },
@@ -78,7 +76,9 @@ const keydownBehavior = {
78
76
  'textarea'
79
77
  ]) || isContentEditable(target)) {
80
78
  return ()=>{
81
- const newPos = getValue(target)?.length ?? /* istanbul ignore next */ 0;
79
+ var ref;
80
+ var ref1;
81
+ const newPos = (ref1 = (ref = getValueOrTextContent(target)) === null || ref === void 0 ? void 0 : ref.length) !== null && ref1 !== void 0 ? ref1 : /* istanbul ignore next */ 0;
82
82
  setSelectionRange(target, newPos, newPos);
83
83
  };
84
84
  }
@@ -98,7 +98,7 @@ const keydownBehavior = {
98
98
  'input'
99
99
  ])) {
100
100
  return ()=>{
101
- const newPos = getValue(target).length;
101
+ const newPos = getUIValue(target).length;
102
102
  setSelectionRange(target, newPos, newPos);
103
103
  };
104
104
  }
@@ -112,10 +112,10 @@ const keydownBehavior = {
112
112
  };
113
113
  }
114
114
  },
115
- Tab: (event, target, config)=>{
115
+ Tab: (event, target, instance)=>{
116
116
  return ()=>{
117
- const dest = getTabDestination(target, config.system.keyboard.modifiers.Shift);
118
- focus(dest);
117
+ const dest = getTabDestination(target, instance.system.keyboard.modifiers.Shift);
118
+ focusElement(dest);
119
119
  if (hasOwnSelection(dest)) {
120
120
  setUISelection(dest, {
121
121
  anchorOffset: 0,
@@ -125,8 +125,8 @@ const keydownBehavior = {
125
125
  };
126
126
  }
127
127
  };
128
- const combinationBehavior = (event, target, config)=>{
129
- if (event.code === 'KeyA' && config.system.keyboard.modifiers.Control) {
128
+ const combinationBehavior = (event, target, instance)=>{
129
+ if (event.code === 'KeyA' && instance.system.keyboard.modifiers.Control) {
130
130
  return ()=>selectAll(target);
131
131
  }
132
132
  };
@@ -1,39 +1,38 @@
1
- import { dispatchUIEvent } from '../index.js';
2
1
  import '../../utils/click/isClickableInput.js';
3
2
  import '../../utils/dataTransfer/Clipboard.js';
4
3
  import { isContentEditable } from '../../utils/edit/isContentEditable.js';
5
- import { input } from '../../utils/edit/input.js';
6
4
  import { isEditable } from '../../utils/edit/isEditable.js';
7
- import '@testing-library/dom';
5
+ import '../../utils/edit/maxLength.js';
8
6
  import { isElementType } from '../../utils/misc/isElementType.js';
9
7
  import '@testing-library/dom/dist/helpers.js';
10
8
  import '../../utils/keyDef/readNextDescriptor.js';
11
9
  import '../../utils/misc/level.js';
12
10
  import '../../options.js';
11
+ import { input } from '../input.js';
13
12
  import { behavior } from './registry.js';
14
13
 
15
- behavior.keypress = (event, target, config)=>{
14
+ behavior.keypress = (event, target, instance)=>{
16
15
  if (event.key === 'Enter') {
17
16
  if (isElementType(target, 'button') || isElementType(target, 'input') && ClickInputOnEnter.includes(target.type) || isElementType(target, 'a') && Boolean(target.href)) {
18
17
  return ()=>{
19
- dispatchUIEvent(config, target, 'click');
18
+ instance.dispatchUIEvent(target, 'click');
20
19
  };
21
20
  } else if (isElementType(target, 'input')) {
22
21
  const form = target.form;
23
- const submit = form?.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
22
+ const submit = form === null || form === void 0 ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
24
23
  if (submit) {
25
- return ()=>dispatchUIEvent(config, submit, 'click');
24
+ return ()=>instance.dispatchUIEvent(submit, 'click');
26
25
  } else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll('input').length === 1) {
27
- return ()=>dispatchUIEvent(config, form, 'submit');
26
+ return ()=>instance.dispatchUIEvent(form, 'submit');
28
27
  } else {
29
28
  return;
30
29
  }
31
30
  }
32
31
  }
33
32
  if (isEditable(target)) {
34
- const inputType = event.key === 'Enter' ? isContentEditable(target) && !config.system.keyboard.modifiers.Shift ? 'insertParagraph' : 'insertLineBreak' : 'insertText';
33
+ const inputType = event.key === 'Enter' ? isContentEditable(target) && !instance.system.keyboard.modifiers.Shift ? 'insertParagraph' : 'insertLineBreak' : 'insertText';
35
34
  const inputData = event.key === 'Enter' ? '\n' : event.key;
36
- return ()=>input(config, target, inputData, inputType);
35
+ return ()=>input(instance, target, inputData, inputType);
37
36
  }
38
37
  };
39
38
  const ClickInputOnEnter = [
@@ -1,22 +1,21 @@
1
1
  import { isClickableInput } from '../../utils/click/isClickableInput.js';
2
2
  import '../../utils/dataTransfer/Clipboard.js';
3
- import { dispatchUIEvent } from '../index.js';
4
- import '../../utils/edit/maxLength.js';
5
3
  import '../../utils/edit/isEditable.js';
6
- import '@testing-library/dom';
4
+ import '../../utils/edit/maxLength.js';
7
5
  import '@testing-library/dom/dist/helpers.js';
8
6
  import '../../utils/keyDef/readNextDescriptor.js';
9
7
  import '../../utils/misc/level.js';
10
8
  import '../../options.js';
11
9
  import { behavior } from './registry.js';
12
10
 
13
- behavior.keyup = (event, target, config)=>{
14
- return keyupBehavior[event.key]?.(event, target, config);
11
+ behavior.keyup = (event, target, instance)=>{
12
+ var ref;
13
+ return (ref = keyupBehavior[event.key]) === null || ref === void 0 ? void 0 : ref.call(keyupBehavior, event, target, instance);
15
14
  };
16
15
  const keyupBehavior = {
17
- ' ': (event, target, config)=>{
16
+ ' ': (event, target, instance)=>{
18
17
  if (isClickableInput(target)) {
19
- return ()=>dispatchUIEvent(config, target, 'click');
18
+ return ()=>instance.dispatchUIEvent(target, 'click');
20
19
  }
21
20
  }
22
21
  };
@@ -1,26 +1,21 @@
1
1
  import '../../utils/click/isClickableInput.js';
2
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
3
  import { isEditable } from '../../utils/edit/isEditable.js';
4
+ import '../../utils/edit/maxLength.js';
13
5
  import '@testing-library/dom/dist/helpers.js';
14
6
  import '../../utils/keyDef/readNextDescriptor.js';
15
7
  import '../../utils/misc/level.js';
16
8
  import '../../options.js';
9
+ import { input } from '../input.js';
10
+ import { behavior } from './registry.js';
17
11
 
18
- behavior.paste = (event, target, config)=>{
12
+ behavior.paste = (event, target, instance)=>{
19
13
  if (isEditable(target)) {
20
14
  return ()=>{
21
- const insertData = event.clipboardData?.getData('text');
15
+ var ref;
16
+ const insertData = (ref = event.clipboardData) === null || ref === void 0 ? void 0 : ref.getData('text');
22
17
  if (insertData) {
23
- input(config, target, insertData, 'insertFromPaste');
18
+ input(instance, target, insertData, 'insertFromPaste');
24
19
  }
25
20
  };
26
21
  }