@testing-library/user-event 14.4.2 → 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 (209) hide show
  1. package/dist/cjs/clipboard/copy.js +4 -14
  2. package/dist/cjs/clipboard/cut.js +4 -14
  3. package/dist/cjs/clipboard/paste.js +2 -12
  4. package/dist/cjs/convenience/click.js +1 -4
  5. package/dist/cjs/convenience/hover.js +2 -12
  6. package/dist/cjs/document/{selection.js → UI.js} +43 -57
  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 +83 -0
  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 +39 -43
  16. package/dist/cjs/event/behavior/keypress.js +8 -9
  17. package/dist/cjs/event/behavior/keyup.js +5 -7
  18. package/dist/cjs/event/behavior/paste.js +5 -11
  19. package/dist/cjs/event/createEvent.js +2 -9
  20. package/dist/cjs/event/dispatchEvent.js +20 -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 +48 -46
  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 +9 -17
  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 +1 -9
  39. package/dist/cjs/options.js +0 -28
  40. package/dist/cjs/pointer/index.js +20 -30
  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 +65 -37
  45. package/dist/cjs/system/keyboard.js +7 -9
  46. package/dist/cjs/system/pointer/index.js +16 -21
  47. package/dist/cjs/system/pointer/mouse.js +45 -38
  48. package/dist/cjs/system/pointer/pointer.js +33 -35
  49. package/dist/cjs/system/pointer/shared.js +10 -0
  50. package/dist/cjs/utility/clear.js +10 -11
  51. package/dist/cjs/utility/selectOptions.js +17 -19
  52. package/dist/cjs/utility/type.js +6 -15
  53. package/dist/cjs/utility/upload.js +3 -13
  54. package/dist/cjs/utils/dataTransfer/Clipboard.js +1 -15
  55. package/dist/cjs/utils/edit/isEditable.js +6 -10
  56. package/dist/cjs/utils/edit/maxLength.js +4 -15
  57. package/dist/cjs/utils/edit/{buildTimeValue.js → timeValue.js} +6 -0
  58. package/dist/cjs/utils/focus/cursor.js +0 -16
  59. package/dist/cjs/utils/focus/selection.js +1 -271
  60. package/dist/cjs/utils/index.js +7 -32
  61. package/dist/cjs/utils/misc/level.js +4 -9
  62. package/dist/cjs/utils/pointer/cssPointerEvents.js +9 -22
  63. package/dist/esm/clipboard/copy.js +4 -14
  64. package/dist/esm/clipboard/cut.js +4 -14
  65. package/dist/esm/clipboard/paste.js +2 -12
  66. package/dist/esm/convenience/click.js +1 -4
  67. package/dist/esm/convenience/hover.js +2 -12
  68. package/dist/esm/document/{selection.js → UI.js} +35 -56
  69. package/dist/esm/document/copySelection.js +33 -0
  70. package/dist/esm/document/getValueOrTextContent.js +23 -0
  71. package/dist/esm/document/index.js +4 -66
  72. package/dist/esm/document/interceptor.js +81 -1
  73. package/dist/esm/document/prepareDocument.js +63 -0
  74. package/dist/esm/document/{value.js → trackValue.js} +3 -61
  75. package/dist/esm/event/behavior/click.js +8 -12
  76. package/dist/esm/event/behavior/cut.js +5 -11
  77. package/dist/esm/event/behavior/keydown.js +32 -36
  78. package/dist/esm/event/behavior/keypress.js +8 -9
  79. package/dist/esm/event/behavior/keyup.js +5 -7
  80. package/dist/esm/event/behavior/paste.js +5 -11
  81. package/dist/esm/event/createEvent.js +2 -9
  82. package/dist/esm/event/dispatchEvent.js +19 -3
  83. package/dist/esm/event/focus.js +39 -0
  84. package/dist/esm/event/index.js +14 -19
  85. package/dist/esm/{utils/edit → event}/input.js +35 -33
  86. package/dist/esm/{utils/edit/walkRadio.js → event/radio.js} +13 -7
  87. package/dist/esm/event/selection/getInputRange.js +16 -0
  88. package/dist/esm/event/selection/getTargetTypeAndSelection.js +36 -0
  89. package/dist/esm/event/selection/index.js +9 -0
  90. package/dist/esm/event/selection/modifySelection.js +26 -0
  91. package/dist/esm/event/selection/modifySelectionPerMouse.js +45 -0
  92. package/dist/esm/event/selection/moveSelection.js +43 -0
  93. package/dist/esm/{utils/focus → event/selection}/resolveCaretPosition.js +8 -16
  94. package/dist/esm/{utils/focus → event/selection}/selectAll.js +12 -21
  95. package/dist/esm/event/selection/setSelection.js +26 -0
  96. package/dist/esm/event/selection/setSelectionPerMouse.js +86 -0
  97. package/dist/esm/event/selection/setSelectionRange.js +36 -0
  98. package/dist/esm/event/selection/updateSelectionOnFocus.js +41 -0
  99. package/dist/esm/keyboard/index.js +13 -23
  100. package/dist/esm/keyboard/parseKeyDef.js +1 -9
  101. package/dist/esm/options.js +1 -26
  102. package/dist/esm/pointer/index.js +20 -30
  103. package/dist/esm/pointer/parseKeyDef.js +1 -9
  104. package/dist/esm/setup/directApi.js +6 -6
  105. package/dist/esm/setup/index.js +0 -1
  106. package/dist/esm/setup/setup.js +59 -32
  107. package/dist/esm/system/keyboard.js +7 -9
  108. package/dist/esm/system/pointer/index.js +17 -21
  109. package/dist/esm/system/pointer/mouse.js +42 -35
  110. package/dist/esm/system/pointer/pointer.js +32 -34
  111. package/dist/esm/system/pointer/shared.js +6 -0
  112. package/dist/esm/utility/clear.js +10 -11
  113. package/dist/esm/utility/selectOptions.js +17 -19
  114. package/dist/esm/utility/type.js +5 -14
  115. package/dist/esm/utility/upload.js +3 -13
  116. package/dist/esm/utils/dataTransfer/Clipboard.js +1 -15
  117. package/dist/esm/utils/edit/isEditable.js +4 -8
  118. package/dist/esm/utils/edit/maxLength.js +3 -15
  119. package/dist/esm/utils/edit/{buildTimeValue.js → timeValue.js} +6 -1
  120. package/dist/esm/utils/focus/cursor.js +0 -16
  121. package/dist/esm/utils/focus/selection.js +3 -265
  122. package/dist/esm/utils/index.js +4 -11
  123. package/dist/esm/utils/misc/level.js +4 -9
  124. package/dist/esm/utils/pointer/cssPointerEvents.js +9 -22
  125. package/dist/types/clipboard/copy.d.ts +1 -1
  126. package/dist/types/clipboard/cut.d.ts +1 -1
  127. package/dist/types/clipboard/paste.d.ts +1 -1
  128. package/dist/types/convenience/click.d.ts +1 -1
  129. package/dist/types/convenience/hover.d.ts +1 -1
  130. package/dist/types/document/UI.d.ts +42 -0
  131. package/dist/types/{utils/focus → document}/copySelection.d.ts +0 -0
  132. package/dist/types/document/getValueOrTextContent.d.ts +1 -0
  133. package/dist/types/document/index.d.ts +5 -10
  134. package/dist/types/document/interceptor.d.ts +3 -0
  135. package/dist/types/document/prepareDocument.d.ts +8 -0
  136. package/dist/types/document/trackValue.d.ts +17 -0
  137. package/dist/types/event/behavior/registry.d.ts +2 -2
  138. package/dist/types/event/dispatchEvent.d.ts +5 -2
  139. package/dist/types/event/focus.d.ts +5 -0
  140. package/dist/types/event/index.d.ts +6 -4
  141. package/dist/types/event/input.d.ts +2 -0
  142. package/dist/types/event/radio.d.ts +4 -0
  143. package/dist/types/event/selection/getInputRange.d.ts +5 -0
  144. package/dist/types/event/selection/getTargetTypeAndSelection.d.ts +10 -0
  145. package/dist/types/event/selection/index.d.ts +15 -0
  146. package/dist/types/event/selection/modifySelection.d.ts +8 -0
  147. package/dist/types/event/selection/modifySelectionPerMouse.d.ts +7 -0
  148. package/dist/types/event/selection/moveSelection.d.ts +4 -0
  149. package/dist/types/{utils/focus → event/selection}/resolveCaretPosition.d.ts +0 -0
  150. package/dist/types/{utils/focus → event/selection}/selectAll.d.ts +0 -0
  151. package/dist/types/event/selection/setSelection.d.ts +10 -0
  152. package/dist/types/event/selection/setSelectionPerMouse.d.ts +8 -0
  153. package/dist/types/event/selection/setSelectionRange.d.ts +6 -0
  154. package/dist/types/event/selection/updateSelectionOnFocus.d.ts +5 -0
  155. package/dist/types/keyboard/index.d.ts +2 -2
  156. package/dist/types/options.d.ts +0 -8
  157. package/dist/types/pointer/index.d.ts +3 -3
  158. package/dist/types/setup/directApi.d.ts +1 -1
  159. package/dist/types/setup/index.d.ts +2 -15
  160. package/dist/types/setup/setup.d.ts +25 -7
  161. package/dist/types/system/keyboard.d.ts +3 -3
  162. package/dist/types/system/pointer/buttons.d.ts +1 -1
  163. package/dist/types/system/pointer/index.d.ts +7 -25
  164. package/dist/types/system/pointer/mouse.d.ts +5 -5
  165. package/dist/types/system/pointer/pointer.d.ts +7 -7
  166. package/dist/types/system/pointer/shared.d.ts +20 -0
  167. package/dist/types/utility/clear.d.ts +1 -1
  168. package/dist/types/utility/selectOptions.d.ts +1 -1
  169. package/dist/types/utility/type.d.ts +3 -3
  170. package/dist/types/utility/upload.d.ts +1 -1
  171. package/dist/types/utils/click/isClickableInput.d.ts +2 -2
  172. package/dist/types/utils/edit/isEditable.d.ts +5 -6
  173. package/dist/types/utils/edit/maxLength.d.ts +14 -1
  174. package/dist/types/utils/edit/{isValidDateOrTimeValue.d.ts → timeValue.d.ts} +1 -0
  175. package/dist/types/utils/focus/selection.d.ts +4 -69
  176. package/dist/types/utils/index.d.ts +2 -9
  177. package/dist/types/utils/misc/level.d.ts +4 -13
  178. package/dist/types/utils/misc/wait.d.ts +2 -2
  179. package/dist/types/utils/pointer/cssPointerEvents.d.ts +4 -4
  180. package/package.json +3 -2
  181. package/dist/cjs/document/setRangeText.js +0 -21
  182. package/dist/cjs/document/value.js +0 -127
  183. package/dist/cjs/setup/config.js +0 -7
  184. package/dist/cjs/utils/edit/getValue.js +0 -35
  185. package/dist/cjs/utils/edit/isValidDateOrTimeValue.js +0 -11
  186. package/dist/cjs/utils/focus/blur.js +0 -16
  187. package/dist/cjs/utils/focus/copySelection.js +0 -46
  188. package/dist/cjs/utils/focus/focus.js +0 -29
  189. package/dist/cjs/utils/focus/selectAll.js +0 -56
  190. package/dist/cjs/utils/misc/eventWrapper.js +0 -15
  191. package/dist/esm/document/setRangeText.js +0 -17
  192. package/dist/esm/setup/config.js +0 -3
  193. package/dist/esm/utils/edit/getValue.js +0 -31
  194. package/dist/esm/utils/edit/isValidDateOrTimeValue.js +0 -7
  195. package/dist/esm/utils/focus/blur.js +0 -12
  196. package/dist/esm/utils/focus/copySelection.js +0 -42
  197. package/dist/esm/utils/focus/focus.js +0 -25
  198. package/dist/esm/utils/misc/eventWrapper.js +0 -11
  199. package/dist/types/document/selection.d.ts +0 -29
  200. package/dist/types/document/setRangeText.d.ts +0 -1
  201. package/dist/types/document/value.d.ts +0 -26
  202. package/dist/types/setup/config.d.ts +0 -6
  203. package/dist/types/utils/edit/buildTimeValue.d.ts +0 -1
  204. package/dist/types/utils/edit/getValue.d.ts +0 -1
  205. package/dist/types/utils/edit/input.d.ts +0 -2
  206. package/dist/types/utils/edit/walkRadio.d.ts +0 -4
  207. package/dist/types/utils/focus/blur.d.ts +0 -2
  208. package/dist/types/utils/focus/focus.d.ts +0 -5
  209. package/dist/types/utils/misc/eventWrapper.d.ts +0 -1
@@ -1,24 +1,11 @@
1
1
  import { PointerEventsCheckLevel } from '../../options.js';
2
- import '../click/isClickableInput.js';
3
- import '../dataTransfer/Clipboard.js';
4
- import '../../event/eventMap.js';
5
- import '../../event/behavior/click.js';
6
- import '../../event/behavior/cut.js';
7
- import '../../event/behavior/keydown.js';
8
- import '../../event/behavior/keypress.js';
9
- import '../../event/behavior/keyup.js';
10
- import '../../event/behavior/paste.js';
11
- import '@testing-library/dom';
12
- import '../edit/maxLength.js';
13
- import '../edit/isEditable.js';
14
- import { isElementType } from '../misc/isElementType.js';
15
2
  import { getWindow } from '../misc/getWindow.js';
16
- import '../keyDef/readNextDescriptor.js';
3
+ import { isElementType } from '../misc/isElementType.js';
17
4
  import { ApiLevel, getLevelRef } from '../misc/level.js';
18
5
 
19
- function hasPointerEvents(config, element) {
6
+ function hasPointerEvents(instance, element) {
20
7
  var ref;
21
- return ((ref = checkPointerEvents(config, element)) === null || ref === void 0 ? void 0 : ref.pointerEvents) !== 'none';
8
+ return ((ref = checkPointerEvents(instance, element)) === null || ref === void 0 ? void 0 : ref.pointerEvents) !== 'none';
22
9
  }
23
10
  function closestPointerEventsDeclaration(element) {
24
11
  const window = getWindow(element);
@@ -38,22 +25,22 @@ function closestPointerEventsDeclaration(element) {
38
25
  return undefined;
39
26
  }
40
27
  const PointerEventsCheck = Symbol('Last check for pointer-events');
41
- function checkPointerEvents(config, element) {
28
+ function checkPointerEvents(instance, element) {
42
29
  const lastCheck = element[PointerEventsCheck];
43
- const needsCheck = config.pointerEventsCheck !== PointerEventsCheckLevel.Never && (!lastCheck || hasBitFlag(config.pointerEventsCheck, PointerEventsCheckLevel.EachApiCall) && lastCheck[ApiLevel.Call] !== getLevelRef(config, ApiLevel.Call) || hasBitFlag(config.pointerEventsCheck, PointerEventsCheckLevel.EachTrigger) && lastCheck[ApiLevel.Trigger] !== getLevelRef(config, ApiLevel.Trigger));
30
+ const needsCheck = instance.config.pointerEventsCheck !== PointerEventsCheckLevel.Never && (!lastCheck || hasBitFlag(instance.config.pointerEventsCheck, PointerEventsCheckLevel.EachApiCall) && lastCheck[ApiLevel.Call] !== getLevelRef(instance, ApiLevel.Call) || hasBitFlag(instance.config.pointerEventsCheck, PointerEventsCheckLevel.EachTrigger) && lastCheck[ApiLevel.Trigger] !== getLevelRef(instance, ApiLevel.Trigger));
44
31
  if (!needsCheck) {
45
32
  return lastCheck === null || lastCheck === void 0 ? void 0 : lastCheck.result;
46
33
  }
47
34
  const declaration = closestPointerEventsDeclaration(element);
48
35
  element[PointerEventsCheck] = {
49
- [ApiLevel.Call]: getLevelRef(config, ApiLevel.Call),
50
- [ApiLevel.Trigger]: getLevelRef(config, ApiLevel.Trigger),
36
+ [ApiLevel.Call]: getLevelRef(instance, ApiLevel.Call),
37
+ [ApiLevel.Trigger]: getLevelRef(instance, ApiLevel.Trigger),
51
38
  result: declaration
52
39
  };
53
40
  return declaration;
54
41
  }
55
- function assertPointerEvents(config, element) {
56
- const declaration = checkPointerEvents(config, element);
42
+ function assertPointerEvents(instance, element) {
43
+ const declaration = checkPointerEvents(instance, element);
57
44
  if ((declaration === null || declaration === void 0 ? void 0 : declaration.pointerEvents) === 'none') {
58
45
  throw new Error([
59
46
  `Unable to perform pointer interaction as the element ${declaration.tree.length > 1 ? 'inherits' : 'has'} \`pointer-events: none\`:`,
@@ -1,2 +1,2 @@
1
- import { Instance } from '../setup';
1
+ import type { Instance } from '../setup';
2
2
  export declare function copy(this: Instance): Promise<DataTransfer | undefined>;
@@ -1,2 +1,2 @@
1
- import { Instance } from '../setup';
1
+ import type { Instance } from '../setup';
2
2
  export declare function cut(this: Instance): Promise<DataTransfer | undefined>;
@@ -1,2 +1,2 @@
1
- import { Instance } from '../setup';
1
+ import type { Instance } from '../setup';
2
2
  export declare function paste(this: Instance, clipboardData?: DataTransfer | string): Promise<void>;
@@ -1,4 +1,4 @@
1
- import { Instance } from '../setup';
1
+ import type { Instance } from '../setup';
2
2
  export declare function click(this: Instance, element: Element): Promise<void>;
3
3
  export declare function dblClick(this: Instance, element: Element): Promise<void>;
4
4
  export declare function tripleClick(this: Instance, element: Element): Promise<void>;
@@ -1,3 +1,3 @@
1
- import { Instance } from '../setup';
1
+ import type { Instance } from '../setup';
2
2
  export declare function hover(this: Instance, element: Element): Promise<void>;
3
3
  export declare function unhover(this: Instance, element: Element): Promise<void>;
@@ -0,0 +1,42 @@
1
+ declare const UIValue: unique symbol;
2
+ declare const UISelection: unique symbol;
3
+ declare const InitialValue: unique symbol;
4
+ declare global {
5
+ interface Element {
6
+ [UIValue]?: string;
7
+ [InitialValue]?: string;
8
+ [UISelection]?: UISelection;
9
+ }
10
+ }
11
+ interface UISelection {
12
+ anchorOffset: number;
13
+ focusOffset: number;
14
+ }
15
+ export declare type UIValueString = String & {
16
+ [UIValue]: true;
17
+ };
18
+ export declare type UISelectionStart = Number & {
19
+ [UISelection]: true;
20
+ };
21
+ export declare function isUIValue(value: string | UIValueString): value is UIValueString;
22
+ export declare function isUISelectionStart(start: number | UISelectionStart | null): start is UISelectionStart;
23
+ export declare function setUIValue(element: HTMLInputElement | HTMLTextAreaElement, value: string): void;
24
+ export declare function getUIValue(element: HTMLInputElement | HTMLTextAreaElement): string;
25
+ /** Flag the IDL value as clean. This does not change the value.*/
26
+ export declare function setUIValueClean(element: HTMLInputElement | HTMLTextAreaElement): void;
27
+ export declare function clearInitialValue(element: HTMLInputElement | HTMLTextAreaElement): void;
28
+ export declare function getInitialValue(element: HTMLInputElement | HTMLTextAreaElement): string | undefined;
29
+ export declare function setUISelectionRaw(element: HTMLInputElement | HTMLTextAreaElement, selection: UISelection): void;
30
+ export declare function setUISelection(element: HTMLInputElement | HTMLTextAreaElement, { focusOffset: focusOffsetParam, anchorOffset: anchorOffsetParam, }: {
31
+ anchorOffset?: number;
32
+ focusOffset: number;
33
+ }, mode?: 'replace' | 'modify'): void;
34
+ export declare type UISelectionRange = UISelection & {
35
+ startOffset: number;
36
+ endOffset: number;
37
+ };
38
+ export declare function getUISelection(element: HTMLInputElement | HTMLTextAreaElement): UISelectionRange;
39
+ export declare function hasUISelection(element: HTMLInputElement | HTMLTextAreaElement): boolean;
40
+ /** Flag the IDL selection as clean. This does not change the selection. */
41
+ export declare function setUISelectionClean(element: HTMLInputElement | HTMLTextAreaElement): void;
42
+ export {};
@@ -0,0 +1 @@
1
+ export declare function getValueOrTextContent<T extends Element | null>(element: T): T extends HTMLInputElement | HTMLTextAreaElement ? string : string | null;
@@ -1,10 +1,5 @@
1
- declare const isPrepared: unique symbol;
2
- declare global {
3
- interface Node {
4
- [isPrepared]?: typeof isPrepared;
5
- }
6
- }
7
- export declare function prepareDocument(document: Document): void;
8
- export { getUIValue, setUIValue, commitValueAfterInput, clearInitialValue, } from './value';
9
- export { getUISelection, setUISelection } from './selection';
10
- export type { UISelectionRange } from './selection';
1
+ export { getUISelection, getUIValue, setUISelection, setUIValue, clearInitialValue, } from './UI';
2
+ export type { UISelectionRange } from './UI';
3
+ export { getValueOrTextContent } from './getValueOrTextContent';
4
+ export { copySelection } from './copySelection';
5
+ export { commitValueAfterInput } from './trackValue';
@@ -13,4 +13,7 @@ export declare function prepareInterceptor<ElementType extends Element, PropName
13
13
  realArgs?: ImplReturn<ElementType[PropName]>;
14
14
  then?: () => void;
15
15
  }): void;
16
+ export declare function prepareValueInterceptor(element: HTMLInputElement | HTMLTextAreaElement): void;
17
+ export declare function prepareSelectionInterceptor(element: HTMLInputElement | HTMLTextAreaElement): void;
18
+ export declare function prepareRangeTextInterceptor(element: HTMLInputElement | HTMLTextAreaElement): void;
16
19
  export {};
@@ -0,0 +1,8 @@
1
+ declare const isPrepared: unique symbol;
2
+ declare global {
3
+ interface Node {
4
+ [isPrepared]?: typeof isPrepared;
5
+ }
6
+ }
7
+ export declare function prepareDocument(document: Document): void;
8
+ export {};
@@ -0,0 +1,17 @@
1
+ declare const TrackChanges: unique symbol;
2
+ declare global {
3
+ interface Window {
4
+ REACT_VERSION?: number;
5
+ }
6
+ interface Element {
7
+ [TrackChanges]?: {
8
+ previousValue?: string;
9
+ tracked?: string[];
10
+ nextValue?: string;
11
+ };
12
+ }
13
+ }
14
+ export declare function startTrackValue(element: HTMLInputElement | HTMLTextAreaElement): void;
15
+ export declare function trackOrSetValue(element: HTMLInputElement | HTMLTextAreaElement, v: string): void;
16
+ export declare function commitValueAfterInput(element: HTMLInputElement | HTMLTextAreaElement, cursorOffset: number): void;
17
+ export {};
@@ -1,7 +1,7 @@
1
- import { Config } from '../../setup';
1
+ import type { Instance } from '../../setup';
2
2
  import { EventType } from '../types';
3
3
  export interface BehaviorPlugin<Type extends EventType> {
4
- (event: DocumentEventMap[Type], target: Element, config: Config): // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
4
+ (event: DocumentEventMap[Type], target: Element, instance: Instance): // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
5
5
  void | (() => void);
6
6
  }
7
7
  export declare const behavior: {
@@ -1,2 +1,5 @@
1
- import { Config } from '../setup';
2
- export declare function dispatchEvent(config: Config, target: Element, event: Event, preventDefault?: boolean): boolean;
1
+ import type { Instance } from '../setup';
2
+ import { EventType, EventTypeInit } from './types';
3
+ export declare function dispatchUIEvent<K extends EventType>(this: Instance, target: Element, type: K, init?: EventTypeInit<K>, preventDefault?: boolean): boolean;
4
+ export declare function dispatchEvent(this: Instance, target: Element, event: Event, preventDefault?: boolean): boolean;
5
+ export declare function dispatchDOMEvent<K extends EventType>(target: Element, type: K, init?: EventTypeInit<K>): void;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Focus closest focusable element.
3
+ */
4
+ export declare function focusElement(element: Element): void;
5
+ export declare function blurElement(element: Element): void;
@@ -1,5 +1,7 @@
1
- import { Config } from '../setup';
2
- import { EventType, EventTypeInit, PointerCoords } from './types';
1
+ import { EventType, PointerCoords } from './types';
3
2
  export type { EventType, PointerCoords };
4
- export declare function dispatchUIEvent<K extends EventType>(config: Config, target: Element, type: K, init?: EventTypeInit<K>, preventDefault?: boolean): boolean;
5
- export declare function bindDispatchUIEvent(config: Config): (target: Element, type: keyof DocumentEventMap, init?: InputEventInit | UIEventInit | EventInit | ClipboardEventInit | MouseEventInit | PointerEventInit | KeyboardEventInit | undefined, preventDefault?: boolean | undefined) => boolean;
3
+ export { dispatchEvent, dispatchUIEvent, dispatchDOMEvent } from './dispatchEvent';
4
+ export { blurElement, focusElement } from './focus';
5
+ export { input } from './input';
6
+ export type { SelectionRange } from './selection';
7
+ export { isAllSelected, modifySelectionPerMouseMove, setSelectionPerMouseDown, selectAll, } from './selection';
@@ -0,0 +1,2 @@
1
+ import type { Instance } from '../setup';
2
+ export declare function input(instance: Instance, element: Element, data: string, inputType?: string): void;
@@ -0,0 +1,4 @@
1
+ import type { Instance } from '../setup';
2
+ export declare function walkRadio(instance: Instance, el: HTMLInputElement & {
3
+ type: 'radio';
4
+ }, direction: -1 | 1): void;
@@ -0,0 +1,5 @@
1
+ import { UISelectionRange } from '../../document';
2
+ /**
3
+ * Get the range that would be overwritten by input.
4
+ */
5
+ export declare function getInputRange(focusNode: Node): UISelectionRange | Range | undefined;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Determine which selection logic and selection ranges to consider.
3
+ */
4
+ export declare function getTargetTypeAndSelection(node: Node): {
5
+ readonly type: "input";
6
+ readonly selection: import("../../document").UISelectionRange;
7
+ } | {
8
+ readonly type: "contenteditable" | "default";
9
+ readonly selection: Selection | null | undefined;
10
+ };
@@ -0,0 +1,15 @@
1
+ import type { EditableInputOrTextarea } from '../../utils';
2
+ export { getInputRange } from './getInputRange';
3
+ export { modifySelection } from './modifySelection';
4
+ export { moveSelection } from './moveSelection';
5
+ export { setSelectionPerMouseDown } from './setSelectionPerMouse';
6
+ export { modifySelectionPerMouseMove } from './modifySelectionPerMouse';
7
+ export { isAllSelected, selectAll } from './selectAll';
8
+ export { setSelectionRange } from './setSelectionRange';
9
+ export { setSelection } from './setSelection';
10
+ export { updateSelectionOnFocus } from './updateSelectionOnFocus';
11
+ export declare type SelectionRange = {
12
+ node: EditableInputOrTextarea;
13
+ start: number;
14
+ end: number;
15
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Extend/shrink the selection like with Shift+Arrows or Shift+Mouse
3
+ */
4
+ export declare function modifySelection({ focusNode, focusOffset, }: {
5
+ focusNode: Node;
6
+ /** DOM Offset */
7
+ focusOffset: number;
8
+ }): void;
@@ -0,0 +1,7 @@
1
+ import type { SelectionRange } from '.';
2
+ export declare function modifySelectionPerMouseMove(selectionRange: Range | SelectionRange, { document, target, node, offset, }: {
3
+ document: Document;
4
+ target: Element;
5
+ node?: Node;
6
+ offset?: number;
7
+ }): void;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Move the selection
3
+ */
4
+ export declare function moveSelection(node: Element, direction: -1 | 1): void;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Set the selection
3
+ */
4
+ export declare function setSelection({ focusNode, focusOffset, anchorNode, anchorOffset, }: {
5
+ anchorNode?: Node;
6
+ /** DOM offset */
7
+ anchorOffset?: number;
8
+ focusNode: Node;
9
+ focusOffset: number;
10
+ }): void;
@@ -0,0 +1,8 @@
1
+ import type { SelectionRange } from '.';
2
+ export declare function setSelectionPerMouseDown({ document, target, clickCount, node, offset, }: {
3
+ document: Document;
4
+ target: Element;
5
+ clickCount: number;
6
+ node?: Node;
7
+ offset?: number;
8
+ }): Range | SelectionRange | undefined;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Backward-compatible selection.
3
+ *
4
+ * Handles input elements and contenteditable if it only contains a single text node.
5
+ */
6
+ export declare function setSelectionRange(element: Element, anchorOffset: number, focusOffset: number): void;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Reset the Document Selection when moving focus into an element
3
+ * with own selection implementation.
4
+ */
5
+ export declare function updateSelectionOnFocus(element: Element): void;
@@ -1,3 +1,3 @@
1
- import { Config, Instance } from '../setup';
1
+ import type { Instance } from '../setup';
2
2
  export declare function keyboard(this: Instance, text: string): Promise<void>;
3
- export declare function releaseAllKeys(config: Config): Promise<void>;
3
+ export declare function releaseAllKeys(instance: Instance): Promise<void>;
@@ -113,11 +113,3 @@ export interface Options {
113
113
  */
114
114
  advanceTimers?: ((delay: number) => Promise<void>) | ((delay: number) => void);
115
115
  }
116
- /**
117
- * Default options applied when API is called per `userEvent.anyApi()`
118
- */
119
- export declare const defaultOptionsDirect: Required<Options>;
120
- /**
121
- * Default options applied when API is called per `userEvent().anyApi()`
122
- */
123
- export declare const defaultOptionsSetup: Required<Options>;
@@ -1,6 +1,6 @@
1
- import { PointerCoords } from '../event';
2
- import { Instance } from '../setup';
3
- import { pointerKey } from '../system/pointer';
1
+ import type { PointerCoords } from '../event';
2
+ import type { Instance } from '../setup';
3
+ import type { pointerKey } from '../system/pointer';
4
4
  declare type PointerActionInput = string | ({
5
5
  keys: string;
6
6
  } & PointerActionPosition) | PointerAction;
@@ -1,7 +1,7 @@
1
1
  import type { Options } from '../options';
2
2
  import type { PointerInput } from '../pointer';
3
3
  import type { System } from '../system';
4
- import type { UserEventApi } from '.';
4
+ import type { UserEventApi } from './setup';
5
5
  export declare type DirectOptions = Options & {
6
6
  keyboardState?: System;
7
7
  pointerState?: System;
@@ -1,19 +1,6 @@
1
- import type { bindDispatchUIEvent } from '../event';
2
- import type * as userEventApi from './api';
3
- import { setupMain, setupSub } from './setup';
4
- import { Config } from './config';
1
+ import { setupMain } from './setup';
5
2
  import * as directApi from './directApi';
6
- export { Config };
7
- export declare type UserEventApi = typeof userEventApi;
8
- export declare type Instance = UserEventApi & {
9
- [Config]: Config;
10
- dispatchUIEvent: ReturnType<typeof bindDispatchUIEvent>;
11
- };
12
- export declare type UserEvent = {
13
- readonly setup: (...args: Parameters<typeof setupSub>) => UserEvent;
14
- } & {
15
- readonly [k in keyof UserEventApi]: (...args: Parameters<UserEventApi[k]>) => ReturnType<UserEventApi[k]>;
16
- };
3
+ export type { Instance } from './setup';
17
4
  export declare const userEvent: {
18
5
  readonly setup: typeof setupMain;
19
6
  readonly clear: typeof directApi.clear;
@@ -1,9 +1,23 @@
1
+ import { dispatchEvent, dispatchUIEvent } from '../event';
1
2
  import { Options } from '../options';
2
3
  import { System } from '../system';
3
- import type { Instance, UserEvent } from './index';
4
- import { Config } from './config';
4
+ import * as userEventApi from './api';
5
5
  import { DirectOptions } from './directApi';
6
- export declare function createConfig(options?: Partial<Config>, defaults?: Required<Options>, node?: Node): Config;
6
+ export declare type UserEventApi = typeof userEventApi;
7
+ export declare type UserEvent = {
8
+ readonly setup: (...args: Parameters<typeof setupSub>) => UserEvent;
9
+ } & {
10
+ readonly [k in keyof UserEventApi]: (...args: Parameters<UserEventApi[k]>) => ReturnType<UserEventApi[k]>;
11
+ };
12
+ export declare type Instance = UserEventApi & {
13
+ config: Config;
14
+ dispatchEvent: OmitThisParameter<typeof dispatchEvent>;
15
+ dispatchUIEvent: OmitThisParameter<typeof dispatchUIEvent>;
16
+ system: System;
17
+ levelRefs: Record<number, object | undefined>;
18
+ };
19
+ export declare type Config = Required<Options>;
20
+ export declare function createConfig(options?: Options, defaults?: Required<Options>, node?: Node): Config;
7
21
  /**
8
22
  * Start a "session" with userEvent.
9
23
  * All APIs returned by this function share an input device state and a default configuration.
@@ -12,15 +26,19 @@ export declare function setupMain(options?: Options): UserEvent;
12
26
  /**
13
27
  * Setup in direct call per `userEvent.anyApi()`
14
28
  */
15
- export declare function setupDirect({ keyboardState, pointerState, ...options }?: DirectOptions & // backward-compatibility
16
- {
29
+ export declare function setupDirect({ keyboardState, pointerState, ...options }?: DirectOptions & {
17
30
  keyboardState?: System;
18
31
  pointerState?: System;
19
- }, node?: Node): {
20
- config: Config;
32
+ }, // backward-compatibility
33
+ node?: Node): {
21
34
  api: UserEvent;
35
+ system: System;
22
36
  };
23
37
  /**
24
38
  * Create a set of callbacks with different default settings but the same state.
25
39
  */
26
40
  export declare function setupSub(this: Instance, options: Options): UserEvent;
41
+ export declare function createInstance(config: Config, system?: System): {
42
+ instance: Instance;
43
+ api: UserEvent;
44
+ };
@@ -1,4 +1,4 @@
1
- import { Config } from '../setup';
1
+ import type { Instance } from '../setup';
2
2
  import type { System } from '.';
3
3
  export declare enum DOM_KEY_LOCATION {
4
4
  STANDARD = 0,
@@ -45,9 +45,9 @@ export declare class KeyboardHost {
45
45
  isKeyPressed(keyDef: keyboardKey): boolean;
46
46
  getPressedKeys(): keyboardKey[];
47
47
  /** Press a key */
48
- keydown(config: Config, keyDef: keyboardKey): Promise<void>;
48
+ keydown(instance: Instance, keyDef: keyboardKey): Promise<void>;
49
49
  /** Release a key */
50
- keyup(config: Config, keyDef: keyboardKey): Promise<void>;
50
+ keyup(instance: Instance, keyDef: keyboardKey): Promise<void>;
51
51
  private setKeydownTarget;
52
52
  private hasKeyPress;
53
53
  }
@@ -1,4 +1,4 @@
1
- import type { pointerKey } from '.';
1
+ import type { pointerKey } from './shared';
2
2
  export declare class Buttons {
3
3
  private readonly pressed;
4
4
  getButtons(): number;
@@ -1,24 +1,7 @@
1
1
  import { System } from '..';
2
- import { PointerCoords } from '../../event';
3
- import { Config } from '../../setup';
4
- import { MouseButton } from './buttons';
5
- export interface pointerKey {
6
- /** Name of the pointer key */
7
- name: string;
8
- /** Type of the pointer device */
9
- pointerType: 'mouse' | 'pen' | 'touch';
10
- /** Type of button */
11
- button?: MouseButton;
12
- }
13
- export interface PointerPosition {
14
- target?: Element;
15
- coords?: PointerCoords;
16
- caret?: CaretPosition;
17
- }
18
- export interface CaretPosition {
19
- node?: Node;
20
- offset?: number;
21
- }
2
+ import { Instance } from '../../setup';
3
+ import { pointerKey, PointerPosition } from './shared';
4
+ export type { pointerKey, PointerPosition } from './shared';
22
5
  export declare class PointerHost {
23
6
  readonly system: System;
24
7
  constructor(system: System);
@@ -27,13 +10,12 @@ export declare class PointerHost {
27
10
  private readonly devices;
28
11
  private readonly pointers;
29
12
  isKeyPressed(keyDef: pointerKey): boolean;
30
- press(config: Config, keyDef: pointerKey, position: PointerPosition): Promise<void>;
31
- move(config: Config, pointerName: string, position: PointerPosition): Promise<void>;
32
- release(config: Config, keyDef: pointerKey, position: PointerPosition): Promise<void>;
13
+ press(instance: Instance, keyDef: pointerKey, position: PointerPosition): Promise<void>;
14
+ move(instance: Instance, pointerName: string, position: PointerPosition): Promise<void>;
15
+ release(instance: Instance, keyDef: pointerKey, position: PointerPosition): Promise<void>;
33
16
  getPointerName(keyDef: pointerKey): string;
34
17
  getPreviousPosition(pointerName: string): PointerPosition | undefined;
35
18
  resetClickCount(): void;
36
- getMouseTarget(config: Config): Element;
19
+ getMouseTarget(instance: Instance): Element;
37
20
  setMousePosition(position: PointerPosition): void;
38
21
  }
39
- export declare function isDifferentPointerPosition(positionA: PointerPosition, positionB: PointerPosition): boolean;
@@ -1,6 +1,6 @@
1
- import { Config } from '../../setup';
2
- import { pointerKey, PointerPosition } from '.';
1
+ import type { Instance } from '../../setup';
3
2
  import type { Pointer } from './pointer';
3
+ import { pointerKey, PointerPosition } from './shared';
4
4
  /**
5
5
  * This object is the single "virtual" mouse that might be controlled by multiple different pointer devices.
6
6
  */
@@ -10,13 +10,13 @@ export declare class Mouse {
10
10
  private selecting?;
11
11
  private buttonDownTarget;
12
12
  private readonly clickCount;
13
- move(config: Config, position: PointerPosition): {
13
+ move(instance: Instance, position: PointerPosition): {
14
14
  leave: () => void;
15
15
  enter: () => void;
16
16
  move: () => void;
17
17
  } | undefined;
18
- down(config: Config, keyDef: pointerKey, pointer: Pointer): void;
19
- up(config: Config, keyDef: pointerKey, pointer: Pointer): void;
18
+ down(instance: Instance, keyDef: pointerKey, pointer: Pointer): void;
19
+ up(instance: Instance, keyDef: pointerKey, pointer: Pointer): void;
20
20
  resetClickCount(): void;
21
21
  private getEventInit;
22
22
  private getTarget;
@@ -1,5 +1,5 @@
1
- import { Config } from '../../setup';
2
- import { pointerKey, PointerPosition } from '.';
1
+ import type { Instance } from '../../setup';
2
+ import { pointerKey, PointerPosition } from './shared';
3
3
  declare type PointerInit = {
4
4
  pointerId: number;
5
5
  pointerType: string;
@@ -15,15 +15,15 @@ export declare class Pointer {
15
15
  isDown: boolean;
16
16
  isPrevented: boolean;
17
17
  position: PointerPosition;
18
- init(config: Config, position: PointerPosition): this;
19
- move(config: Config, position: PointerPosition): {
18
+ init(instance: Instance, position: PointerPosition): this;
19
+ move(instance: Instance, position: PointerPosition): {
20
20
  leave: () => void;
21
21
  enter: () => void;
22
22
  move: () => void;
23
23
  } | undefined;
24
- down(config: Config, _keyDef: pointerKey): void;
25
- up(config: Config, _keyDef: pointerKey): void;
26
- release(config: Config): void;
24
+ down(instance: Instance, _keyDef: pointerKey): void;
25
+ up(instance: Instance, _keyDef: pointerKey): void;
26
+ release(instance: Instance): void;
27
27
  private getTarget;
28
28
  private getEventInit;
29
29
  }
@@ -0,0 +1,20 @@
1
+ import { PointerCoords } from '../../event';
2
+ import { MouseButton } from './buttons';
3
+ export interface pointerKey {
4
+ /** Name of the pointer key */
5
+ name: string;
6
+ /** Type of the pointer device */
7
+ pointerType: 'mouse' | 'pen' | 'touch';
8
+ /** Type of button */
9
+ button?: MouseButton;
10
+ }
11
+ export interface PointerPosition {
12
+ target?: Element;
13
+ coords?: PointerCoords;
14
+ caret?: CaretPosition;
15
+ }
16
+ export interface CaretPosition {
17
+ node?: Node;
18
+ offset?: number;
19
+ }
20
+ export declare function isDifferentPointerPosition(positionA: PointerPosition, positionB: PointerPosition): boolean;
@@ -1,2 +1,2 @@
1
- import { Instance } from '../setup';
1
+ import type { Instance } from '../setup';
2
2
  export declare function clear(this: Instance, element: Element): Promise<void>;
@@ -1,3 +1,3 @@
1
- import { Instance } from '../setup';
1
+ import type { Instance } from '../setup';
2
2
  export declare function selectOptions(this: Instance, select: Element, values: HTMLElement | HTMLElement[] | string[] | string): Promise<void>;
3
3
  export declare function deselectOptions(this: Instance, select: Element, values: HTMLElement | HTMLElement[] | string[] | string): Promise<void>;