@testing-library/user-event 14.4.3 → 14.5.0

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 (183) hide show
  1. package/dist/cjs/_interop/dtl.js +30 -0
  2. package/dist/cjs/_interop/dtlEventMap.js +30 -0
  3. package/dist/cjs/_interop/dtlHelpers.js +30 -0
  4. package/dist/cjs/clipboard/copy.js +2 -2
  5. package/dist/cjs/clipboard/cut.js +2 -2
  6. package/dist/cjs/clipboard/paste.js +4 -4
  7. package/dist/cjs/convenience/tab.js +1 -1
  8. package/dist/cjs/document/UI.js +5 -5
  9. package/dist/cjs/document/interceptor.js +6 -4
  10. package/dist/cjs/document/trackValue.js +4 -4
  11. package/dist/cjs/event/behavior/keydown.js +6 -6
  12. package/dist/cjs/event/behavior/keypress.js +4 -3
  13. package/dist/cjs/event/behavior/keyup.js +2 -2
  14. package/dist/cjs/event/behavior/paste.js +2 -2
  15. package/dist/cjs/event/createEvent.js +41 -41
  16. package/dist/cjs/event/dispatchEvent.js +2 -2
  17. package/dist/cjs/event/eventMap.js +2 -2
  18. package/dist/cjs/event/focus.js +2 -2
  19. package/dist/cjs/event/input.js +4 -4
  20. package/dist/cjs/event/selection/getInputRange.js +2 -2
  21. package/dist/cjs/event/selection/getTargetTypeAndSelection.js +3 -2
  22. package/dist/cjs/event/selection/modifySelection.js +3 -3
  23. package/dist/cjs/event/selection/modifySelectionPerMouse.js +4 -3
  24. package/dist/cjs/event/selection/moveSelection.js +6 -5
  25. package/dist/cjs/event/selection/resolveCaretPosition.js +1 -1
  26. package/dist/cjs/event/selection/selectAll.js +6 -5
  27. package/dist/cjs/event/selection/setSelection.js +3 -3
  28. package/dist/cjs/event/selection/setSelectionPerMouse.js +8 -7
  29. package/dist/cjs/event/selection/setSelectionRange.js +2 -2
  30. package/dist/cjs/event/selection/updateSelectionOnFocus.js +4 -3
  31. package/dist/cjs/event/wrapEvent.js +3 -2
  32. package/dist/cjs/index.js +1 -0
  33. package/dist/cjs/keyboard/index.js +2 -2
  34. package/dist/cjs/keyboard/parseKeyDef.js +8 -8
  35. package/dist/cjs/pointer/index.js +11 -11
  36. package/dist/cjs/pointer/keyMap.js +1 -1
  37. package/dist/cjs/pointer/parseKeyDef.js +1 -1
  38. package/dist/cjs/setup/api.js +19 -17
  39. package/dist/cjs/setup/directApi.js +3 -3
  40. package/dist/cjs/setup/setup.js +10 -10
  41. package/dist/cjs/setup/wrapAsync.js +3 -2
  42. package/dist/cjs/system/index.js +15 -2
  43. package/dist/cjs/system/keyboard.js +27 -12
  44. package/dist/cjs/system/pointer/buttons.js +14 -1
  45. package/dist/cjs/system/pointer/device.js +14 -1
  46. package/dist/cjs/system/pointer/index.js +46 -26
  47. package/dist/cjs/system/pointer/mouse.js +33 -19
  48. package/dist/cjs/system/pointer/pointer.js +24 -8
  49. package/dist/cjs/system/pointer/shared.js +2 -2
  50. package/dist/cjs/utility/selectOptions.js +12 -11
  51. package/dist/cjs/utility/type.js +1 -1
  52. package/dist/cjs/utility/upload.js +6 -5
  53. package/dist/cjs/utils/dataTransfer/Clipboard.js +25 -9
  54. package/dist/cjs/utils/dataTransfer/DataTransfer.js +25 -9
  55. package/dist/cjs/utils/edit/maxLength.js +2 -2
  56. package/dist/cjs/utils/edit/setFiles.js +4 -4
  57. package/dist/cjs/utils/focus/cursor.js +2 -2
  58. package/dist/cjs/utils/focus/getActiveElement.js +4 -3
  59. package/dist/cjs/utils/focus/selector.js +1 -1
  60. package/dist/cjs/utils/keyDef/readNextDescriptor.js +5 -5
  61. package/dist/cjs/utils/misc/getTreeDiff.js +3 -3
  62. package/dist/cjs/utils/misc/getWindow.js +3 -2
  63. package/dist/cjs/utils/misc/isDisabled.js +3 -3
  64. package/dist/cjs/utils/misc/isVisible.js +3 -2
  65. package/dist/cjs/utils/misc/wait.js +1 -1
  66. package/dist/cjs/utils/pointer/cssPointerEvents.js +23 -19
  67. package/dist/esm/_interop/dtl.js +6 -0
  68. package/dist/esm/_interop/dtlEventMap.js +6 -0
  69. package/dist/esm/_interop/dtlHelpers.js +6 -0
  70. package/dist/esm/clipboard/copy.js +2 -2
  71. package/dist/esm/clipboard/cut.js +2 -2
  72. package/dist/esm/clipboard/paste.js +4 -4
  73. package/dist/esm/convenience/tab.js +1 -1
  74. package/dist/esm/document/UI.js +5 -5
  75. package/dist/esm/document/interceptor.js +6 -4
  76. package/dist/esm/document/trackValue.js +4 -4
  77. package/dist/esm/event/behavior/keydown.js +6 -6
  78. package/dist/esm/event/behavior/keypress.js +4 -3
  79. package/dist/esm/event/behavior/keyup.js +2 -2
  80. package/dist/esm/event/behavior/paste.js +2 -2
  81. package/dist/esm/event/createEvent.js +41 -41
  82. package/dist/esm/event/dispatchEvent.js +2 -2
  83. package/dist/esm/event/eventMap.js +2 -2
  84. package/dist/esm/event/focus.js +2 -2
  85. package/dist/esm/event/input.js +4 -4
  86. package/dist/esm/event/selection/getInputRange.js +2 -2
  87. package/dist/esm/event/selection/getTargetTypeAndSelection.js +3 -2
  88. package/dist/esm/event/selection/modifySelection.js +3 -3
  89. package/dist/esm/event/selection/modifySelectionPerMouse.js +4 -3
  90. package/dist/esm/event/selection/moveSelection.js +6 -5
  91. package/dist/esm/event/selection/resolveCaretPosition.js +1 -1
  92. package/dist/esm/event/selection/selectAll.js +6 -5
  93. package/dist/esm/event/selection/setSelection.js +3 -3
  94. package/dist/esm/event/selection/setSelectionPerMouse.js +8 -7
  95. package/dist/esm/event/selection/setSelectionRange.js +2 -2
  96. package/dist/esm/event/selection/updateSelectionOnFocus.js +4 -3
  97. package/dist/esm/event/wrapEvent.js +2 -1
  98. package/dist/esm/index.js +1 -1
  99. package/dist/esm/keyboard/index.js +2 -2
  100. package/dist/esm/keyboard/parseKeyDef.js +8 -8
  101. package/dist/esm/pointer/index.js +11 -11
  102. package/dist/esm/pointer/keyMap.js +1 -1
  103. package/dist/esm/pointer/parseKeyDef.js +1 -1
  104. package/dist/esm/setup/api.js +33 -12
  105. package/dist/esm/setup/directApi.js +3 -3
  106. package/dist/esm/setup/setup.js +11 -11
  107. package/dist/esm/setup/wrapAsync.js +2 -1
  108. package/dist/esm/system/index.js +15 -2
  109. package/dist/esm/system/keyboard.js +27 -12
  110. package/dist/esm/system/pointer/buttons.js +14 -1
  111. package/dist/esm/system/pointer/device.js +14 -1
  112. package/dist/esm/system/pointer/index.js +46 -26
  113. package/dist/esm/system/pointer/mouse.js +33 -19
  114. package/dist/esm/system/pointer/pointer.js +24 -8
  115. package/dist/esm/system/pointer/shared.js +2 -2
  116. package/dist/esm/utility/selectOptions.js +8 -7
  117. package/dist/esm/utility/type.js +1 -1
  118. package/dist/esm/utility/upload.js +6 -5
  119. package/dist/esm/utils/dataTransfer/Clipboard.js +25 -9
  120. package/dist/esm/utils/dataTransfer/DataTransfer.js +25 -9
  121. package/dist/esm/utils/edit/maxLength.js +2 -2
  122. package/dist/esm/utils/edit/setFiles.js +4 -4
  123. package/dist/esm/utils/focus/cursor.js +2 -2
  124. package/dist/esm/utils/focus/getActiveElement.js +4 -3
  125. package/dist/esm/utils/focus/selector.js +1 -1
  126. package/dist/esm/utils/keyDef/readNextDescriptor.js +5 -5
  127. package/dist/esm/utils/misc/getTreeDiff.js +3 -3
  128. package/dist/esm/utils/misc/getWindow.js +2 -1
  129. package/dist/esm/utils/misc/isDisabled.js +3 -3
  130. package/dist/esm/utils/misc/isVisible.js +3 -2
  131. package/dist/esm/utils/misc/wait.js +1 -1
  132. package/dist/esm/utils/pointer/cssPointerEvents.js +23 -19
  133. package/dist/types/_interop/dtl.d.ts +3 -0
  134. package/dist/types/_interop/dtlEventMap.d.ts +3 -0
  135. package/dist/types/_interop/dtlHelpers.d.ts +3 -0
  136. package/dist/types/clipboard/copy.d.ts +1 -1
  137. package/dist/types/clipboard/cut.d.ts +1 -1
  138. package/dist/types/clipboard/paste.d.ts +1 -1
  139. package/dist/types/convenience/click.d.ts +1 -1
  140. package/dist/types/convenience/hover.d.ts +1 -1
  141. package/dist/types/convenience/tab.d.ts +1 -1
  142. package/dist/types/document/UI.d.ts +3 -3
  143. package/dist/types/document/interceptor.d.ts +3 -3
  144. package/dist/types/event/behavior/registry.d.ts +1 -1
  145. package/dist/types/event/createEvent.d.ts +1 -1
  146. package/dist/types/event/dispatchEvent.d.ts +1 -1
  147. package/dist/types/event/eventMap.d.ts +8 -0
  148. package/dist/types/event/input.d.ts +1 -1
  149. package/dist/types/event/radio.d.ts +1 -1
  150. package/dist/types/event/selection/index.d.ts +2 -2
  151. package/dist/types/event/selection/modifySelectionPerMouse.d.ts +1 -1
  152. package/dist/types/event/selection/setSelectionPerMouse.d.ts +1 -1
  153. package/dist/types/event/types.d.ts +3 -3
  154. package/dist/types/index.d.ts +3 -1
  155. package/dist/types/keyboard/index.d.ts +1 -1
  156. package/dist/types/options.d.ts +2 -2
  157. package/dist/types/pointer/index.d.ts +7 -7
  158. package/dist/types/setup/api.d.ts +23 -5
  159. package/dist/types/setup/directApi.d.ts +5 -5
  160. package/dist/types/setup/setup.d.ts +5 -5
  161. package/dist/types/system/keyboard.d.ts +2 -2
  162. package/dist/types/system/pointer/buttons.d.ts +2 -2
  163. package/dist/types/system/pointer/device.d.ts +1 -1
  164. package/dist/types/system/pointer/mouse.d.ts +2 -2
  165. package/dist/types/system/pointer/pointer.d.ts +2 -2
  166. package/dist/types/utility/clear.d.ts +1 -1
  167. package/dist/types/utility/selectOptions.d.ts +1 -1
  168. package/dist/types/utility/type.d.ts +2 -2
  169. package/dist/types/utility/upload.d.ts +1 -1
  170. package/dist/types/utils/click/isClickableInput.d.ts +1 -1
  171. package/dist/types/utils/dataTransfer/Clipboard.d.ts +1 -1
  172. package/dist/types/utils/edit/isEditable.d.ts +2 -2
  173. package/dist/types/utils/edit/maxLength.d.ts +1 -1
  174. package/dist/types/utils/keyDef/readNextDescriptor.d.ts +1 -1
  175. package/dist/types/utils/misc/isElementType.d.ts +1 -1
  176. package/dist/types/utils/misc/level.d.ts +2 -2
  177. package/dist/types/utils/misc/wait.d.ts +1 -1
  178. package/dist/types/utils/pointer/cssPointerEvents.d.ts +1 -1
  179. package/package.json +22 -11
  180. /package/dist/cjs/{event → _interop}/dom-events.d.js +0 -0
  181. /package/dist/cjs/{utils/misc → _interop}/dom-helpers.d.js +0 -0
  182. /package/dist/esm/{event → _interop}/dom-events.d.js +0 -0
  183. /package/dist/esm/{utils/misc → _interop}/dom-helpers.d.js +0 -0
@@ -1,7 +1,7 @@
1
- import { eventMap as eventMap$1 } from '@testing-library/dom/dist/event-map.js';
1
+ import dtlEvents from '../_interop/dtlEventMap.js';
2
2
 
3
3
  const eventMap = {
4
- ...eventMap$1,
4
+ ...dtlEvents.eventMap,
5
5
  click: {
6
6
  EventType: 'PointerEvent',
7
7
  defaultInit: {
@@ -23,8 +23,8 @@ import { wrapEvent } from './wrapEvent.js';
23
23
  wrapEvent(()=>target.focus());
24
24
  } else {
25
25
  wrapEvent(()=>{
26
- var ref;
27
- return (ref = activeElement) === null || ref === void 0 ? void 0 : ref.blur();
26
+ var _activeElement;
27
+ return (_activeElement = activeElement) === null || _activeElement === void 0 ? void 0 : _activeElement.blur();
28
28
  });
29
29
  }
30
30
  updateSelectionOnFocus(target !== null && target !== void 0 ? target : element.ownerDocument.body);
@@ -94,7 +94,7 @@ function editInputElement(instance, element, inputRange, data, inputType) {
94
94
  }
95
95
  }
96
96
  }
97
- const { newValue , newOffset , oldValue } = calculateNewValue(dataToInsert, element, inputRange, inputType);
97
+ const { newValue, newOffset, oldValue } = calculateNewValue(dataToInsert, element, inputRange, inputType);
98
98
  if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
99
99
  return;
100
100
  }
@@ -122,7 +122,7 @@ function editInputElement(instance, element, inputRange, data, inputType) {
122
122
  });
123
123
  }
124
124
  }
125
- function calculateNewValue(inputData, node, { startOffset , endOffset }, inputType) {
125
+ function calculateNewValue(inputData, node, { startOffset, endOffset }, inputType) {
126
126
  const value = getUIValue(node);
127
127
  const prologEnd = Math.max(0, startOffset === endOffset && inputType === 'deleteContentBackward' ? startOffset - 1 : startOffset);
128
128
  const prolog = value.substring(0, prologEnd);
@@ -150,12 +150,12 @@ function commitInput(instance, element, newOffset, inputInit) {
150
150
  commitValueAfterInput(element, newOffset);
151
151
  }
152
152
  function isValidNumberInput(value) {
153
- var ref, ref1;
153
+ var _value_match, _value_match1;
154
154
  // the browser allows some invalid input but not others
155
155
  // it allows up to two '-' at any place before any 'e' or one directly following 'e'
156
156
  // it allows one '.' at any place before e
157
157
  const valueParts = value.split('e', 2);
158
- return !(/[^\d.\-e]/.test(value) || Number((ref = value.match(/-/g)) === null || ref === void 0 ? void 0 : ref.length) > 2 || Number((ref1 = value.match(/\./g)) === null || ref1 === void 0 ? void 0 : ref1.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1]));
158
+ return !(/[^\d.\-e]/.test(value) || Number((_value_match = value.match(/-/g)) === null || _value_match === void 0 ? void 0 : _value_match.length) > 2 || Number((_value_match1 = value.match(/\./g)) === null || _value_match1 === void 0 ? void 0 : _value_match1.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1]));
159
159
  }
160
160
 
161
161
  export { input };
@@ -7,9 +7,9 @@ import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
7
7
  if (typeAndSelection.type === 'input') {
8
8
  return typeAndSelection.selection;
9
9
  } else if (typeAndSelection.type === 'contenteditable') {
10
- var ref;
10
+ var _typeAndSelection_selection;
11
11
  // Multi-range on contenteditable edits the first selection instead of the last
12
- return (ref = typeAndSelection.selection) === null || ref === void 0 ? void 0 : ref.getRangeAt(0);
12
+ return (_typeAndSelection_selection = typeAndSelection.selection) === null || _typeAndSelection_selection === void 0 ? void 0 : _typeAndSelection_selection.getRangeAt(0);
13
13
  }
14
14
  }
15
15
 
@@ -13,6 +13,7 @@ import '../../options.js';
13
13
  /**
14
14
  * Determine which selection logic and selection ranges to consider.
15
15
  */ function getTargetTypeAndSelection(node) {
16
+ var _element, _selection;
16
17
  const element = getElement(node);
17
18
  if (element && hasOwnSelection(element)) {
18
19
  return {
@@ -20,10 +21,10 @@ import '../../options.js';
20
21
  selection: getUISelection(element)
21
22
  };
22
23
  }
23
- const selection = element === null || element === void 0 ? void 0 : element.ownerDocument.getSelection();
24
+ const selection = (_element = element) === null || _element === void 0 ? void 0 : _element.ownerDocument.getSelection();
24
25
  // It is possible to extend a single-range selection into a contenteditable.
25
26
  // This results in the range acting like a range outside of contenteditable.
26
- const isCE = getContentEditable(node) && (selection === null || selection === void 0 ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode);
27
+ const isCE = getContentEditable(node) && ((_selection = selection) === null || _selection === void 0 ? void 0 : _selection.anchorNode) && getContentEditable(selection.anchorNode);
27
28
  return {
28
29
  type: isCE ? 'contenteditable' : 'default',
29
30
  selection
@@ -11,8 +11,8 @@ import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
11
11
 
12
12
  /**
13
13
  * Extend/shrink the selection like with Shift+Arrows or Shift+Mouse
14
- */ function modifySelection({ focusNode , focusOffset }) {
15
- var ref, ref1;
14
+ */ function modifySelection({ focusNode, focusOffset }) {
15
+ var _focusNode_ownerDocument_getSelection, _focusNode_ownerDocument;
16
16
  const typeAndSelection = getTargetTypeAndSelection(focusNode);
17
17
  if (typeAndSelection.type === 'input') {
18
18
  return setUISelection(focusNode, {
@@ -20,7 +20,7 @@ import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
20
20
  focusOffset
21
21
  }, 'modify');
22
22
  }
23
- (ref1 = (ref = focusNode.ownerDocument) === null || ref === void 0 ? void 0 : ref.getSelection()) === null || ref1 === void 0 ? void 0 : ref1.extend(focusNode, focusOffset);
23
+ (_focusNode_ownerDocument = focusNode.ownerDocument) === null || _focusNode_ownerDocument === void 0 ? void 0 : (_focusNode_ownerDocument_getSelection = _focusNode_ownerDocument.getSelection()) === null || _focusNode_ownerDocument_getSelection === void 0 ? void 0 : _focusNode_ownerDocument_getSelection.extend(focusNode, focusOffset);
24
24
  }
25
25
 
26
26
  export { modifySelection };
@@ -9,7 +9,7 @@ import '../../utils/misc/level.js';
9
9
  import '../../options.js';
10
10
  import { resolveCaretPosition } from './resolveCaretPosition.js';
11
11
 
12
- function modifySelectionPerMouseMove(selectionRange, { document , target , node , offset }) {
12
+ function modifySelectionPerMouseMove(selectionRange, { document, target, node, offset }) {
13
13
  const selectionFocus = resolveCaretPosition({
14
14
  target,
15
15
  node,
@@ -29,6 +29,7 @@ function modifySelectionPerMouseMove(selectionRange, { document , target , node
29
29
  });
30
30
  }
31
31
  } else {
32
+ var _selection, _selection1;
32
33
  const range = selectionRange.cloneRange();
33
34
  const cmp = range.comparePoint(selectionFocus.node, selectionFocus.offset);
34
35
  if (cmp < 0) {
@@ -37,8 +38,8 @@ function modifySelectionPerMouseMove(selectionRange, { document , target , node
37
38
  range.setEnd(selectionFocus.node, selectionFocus.offset);
38
39
  }
39
40
  const selection = document.getSelection();
40
- selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
41
- selection === null || selection === void 0 ? void 0 : selection.addRange(range.cloneRange());
41
+ (_selection = selection) === null || _selection === void 0 ? void 0 : _selection.removeAllRanges();
42
+ (_selection1 = selection) === null || _selection1 === void 0 ? void 0 : _selection1.addRange(range.cloneRange());
42
43
  }
43
44
  }
44
45
 
@@ -22,12 +22,13 @@ import { setSelection } from './setSelection.js';
22
22
  focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + direction : direction < 0 ? selection.startOffset : selection.endOffset
23
23
  });
24
24
  } else {
25
- const selection1 = node.ownerDocument.getSelection();
26
- if (!(selection1 === null || selection1 === void 0 ? void 0 : selection1.focusNode)) {
25
+ var _selection;
26
+ const selection = node.ownerDocument.getSelection();
27
+ if (!((_selection = selection) === null || _selection === void 0 ? void 0 : _selection.focusNode)) {
27
28
  return;
28
29
  }
29
- if (selection1.isCollapsed) {
30
- const nextPosition = getNextCursorPosition(selection1.focusNode, selection1.focusOffset, direction);
30
+ if (selection.isCollapsed) {
31
+ const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, direction);
31
32
  if (nextPosition) {
32
33
  setSelection({
33
34
  focusNode: nextPosition.node,
@@ -35,7 +36,7 @@ import { setSelection } from './setSelection.js';
35
36
  });
36
37
  }
37
38
  } else {
38
- selection1[direction < 0 ? 'collapseToStart' : 'collapseToEnd']();
39
+ selection[direction < 0 ? 'collapseToStart' : 'collapseToEnd']();
39
40
  }
40
41
  }
41
42
  }
@@ -9,7 +9,7 @@ import '../../utils/keyDef/readNextDescriptor.js';
9
9
  import '../../utils/misc/level.js';
10
10
  import '../../options.js';
11
11
 
12
- function resolveCaretPosition({ target , node , offset }) {
12
+ function resolveCaretPosition({ target, node, offset }) {
13
13
  if (hasOwnSelection(target)) {
14
14
  return {
15
15
  node: target,
@@ -21,8 +21,8 @@ import { setSelection } from './setSelection.js';
21
21
  focusOffset: getUIValue(target).length
22
22
  });
23
23
  }
24
- var ref;
25
- const focusNode = (ref = getContentEditable(target)) !== null && ref !== void 0 ? ref : target.ownerDocument.body;
24
+ var _getContentEditable;
25
+ const focusNode = (_getContentEditable = getContentEditable(target)) !== null && _getContentEditable !== void 0 ? _getContentEditable : target.ownerDocument.body;
26
26
  setSelection({
27
27
  focusNode,
28
28
  anchorOffset: 0,
@@ -30,13 +30,14 @@ import { setSelection } from './setSelection.js';
30
30
  });
31
31
  }
32
32
  function isAllSelected(target) {
33
+ var _selection;
33
34
  if (hasOwnSelection(target)) {
34
35
  return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
35
36
  }
36
- var ref;
37
- const focusNode = (ref = getContentEditable(target)) !== null && ref !== void 0 ? ref : target.ownerDocument.body;
37
+ var _getContentEditable;
38
+ const focusNode = (_getContentEditable = getContentEditable(target)) !== null && _getContentEditable !== void 0 ? _getContentEditable : target.ownerDocument.body;
38
39
  const selection = target.ownerDocument.getSelection();
39
- return (selection === null || selection === void 0 ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
40
+ return ((_selection = selection) === null || _selection === void 0 ? void 0 : _selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
40
41
  }
41
42
 
42
43
  export { isAllSelected, selectAll };
@@ -11,8 +11,8 @@ import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
11
11
 
12
12
  /**
13
13
  * Set the selection
14
- */ function setSelection({ focusNode , focusOffset , anchorNode =focusNode , anchorOffset =focusOffset }) {
15
- var ref, ref1;
14
+ */ function setSelection({ focusNode, focusOffset, anchorNode = focusNode, anchorOffset = focusOffset }) {
15
+ var _anchorNode_ownerDocument_getSelection, _anchorNode_ownerDocument;
16
16
  const typeAndSelection = getTargetTypeAndSelection(focusNode);
17
17
  if (typeAndSelection.type === 'input') {
18
18
  return setUISelection(focusNode, {
@@ -20,7 +20,7 @@ import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
20
20
  focusOffset
21
21
  });
22
22
  }
23
- (ref1 = (ref = anchorNode.ownerDocument) === null || ref === void 0 ? void 0 : ref.getSelection()) === null || ref1 === void 0 ? void 0 : ref1.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
23
+ (_anchorNode_ownerDocument = anchorNode.ownerDocument) === null || _anchorNode_ownerDocument === void 0 ? void 0 : (_anchorNode_ownerDocument_getSelection = _anchorNode_ownerDocument.getSelection()) === null || _anchorNode_ownerDocument_getSelection === void 0 ? void 0 : _anchorNode_ownerDocument_getSelection.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
24
24
  }
25
25
 
26
26
  export { setSelection };
@@ -10,7 +10,7 @@ import '../../utils/misc/level.js';
10
10
  import '../../options.js';
11
11
  import { resolveCaretPosition } from './resolveCaretPosition.js';
12
12
 
13
- function setSelectionPerMouseDown({ document , target , clickCount , node , offset }) {
13
+ function setSelectionPerMouseDown({ document, target, clickCount, node, offset }) {
14
14
  if (hasNoSelection(target)) {
15
15
  return;
16
16
  }
@@ -39,12 +39,13 @@ function setSelectionPerMouseDown({ document , target , clickCount , node , offs
39
39
  end: end !== null && end !== void 0 ? end : text.length
40
40
  };
41
41
  } else {
42
- const { node: startNode , offset: startOffset } = resolveCaretPosition({
42
+ var _selection, _selection1;
43
+ const { node: startNode, offset: startOffset } = resolveCaretPosition({
43
44
  target,
44
45
  node,
45
46
  offset: start
46
47
  });
47
- const { node: endNode , offset: endOffset } = resolveCaretPosition({
48
+ const { node: endNode, offset: endOffset } = resolveCaretPosition({
48
49
  target,
49
50
  node,
50
51
  offset: end
@@ -57,8 +58,8 @@ function setSelectionPerMouseDown({ document , target , clickCount , node , offs
57
58
  throw new Error('The given offset is out of bounds.');
58
59
  }
59
60
  const selection = document.getSelection();
60
- selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
61
- selection === null || selection === void 0 ? void 0 : selection.addRange(range.cloneRange());
61
+ (_selection = selection) === null || _selection === void 0 ? void 0 : _selection.removeAllRanges();
62
+ (_selection1 = selection) === null || _selection1 === void 0 ? void 0 : _selection1.addRange(range.cloneRange());
62
63
  return range;
63
64
  }
64
65
  }
@@ -73,13 +74,13 @@ function getTextRange(text, pos, clickCount) {
73
74
  if (clickCount % 3 === 2) {
74
75
  return [
75
76
  textPos - text.substr(0, pos).match(/(\w+|\s+|\W)?$/)[0].length,
76
- pos === undefined ? pos : pos + text.substr(pos).match(/^(\w+|\s+|\W)?/)[0].length,
77
+ pos === undefined ? pos : pos + text.substr(pos).match(/^(\w+|\s+|\W)?/)[0].length
77
78
  ];
78
79
  }
79
80
  // triple click
80
81
  return [
81
82
  textPos - text.substr(0, pos).match(/[^\r\n]*$/)[0].length,
82
- pos === undefined ? pos : pos + text.substr(pos).match(/^[^\r\n]*/)[0].length,
83
+ pos === undefined ? pos : pos + text.substr(pos).match(/^[^\r\n]*/)[0].length
83
84
  ];
84
85
  }
85
86
 
@@ -15,7 +15,7 @@ import { setSelection } from './setSelection.js';
15
15
  *
16
16
  * Handles input elements and contenteditable if it only contains a single text node.
17
17
  */ function setSelectionRange(element, anchorOffset, focusOffset) {
18
- var ref;
18
+ var _element_firstChild;
19
19
  if (hasOwnSelection(element)) {
20
20
  return setSelection({
21
21
  focusNode: element,
@@ -23,7 +23,7 @@ import { setSelection } from './setSelection.js';
23
23
  focusOffset
24
24
  });
25
25
  }
26
- /* istanbul ignore else */ if (isContentEditable(element) && ((ref = element.firstChild) === null || ref === void 0 ? void 0 : ref.nodeType) === 3) {
26
+ /* istanbul ignore else */ if (isContentEditable(element) && ((_element_firstChild = element.firstChild) === null || _element_firstChild === void 0 ? void 0 : _element_firstChild.nodeType) === 3) {
27
27
  return setSelection({
28
28
  focusNode: element.firstChild,
29
29
  anchorOffset,
@@ -13,8 +13,9 @@ import '../../options.js';
13
13
  * Reset the Document Selection when moving focus into an element
14
14
  * with own selection implementation.
15
15
  */ function updateSelectionOnFocus(element) {
16
+ var _selection;
16
17
  const selection = element.ownerDocument.getSelection();
17
- /* istanbul ignore if */ if (!(selection === null || selection === void 0 ? void 0 : selection.focusNode)) {
18
+ /* istanbul ignore if */ if (!((_selection = selection) === null || _selection === void 0 ? void 0 : _selection.focusNode)) {
18
19
  return;
19
20
  }
20
21
  // If the focus moves inside an element with own selection implementation,
@@ -28,8 +29,8 @@ import '../../options.js';
28
29
  const contenteditable = getContentEditable(selection.focusNode);
29
30
  if (contenteditable) {
30
31
  if (!selection.isCollapsed) {
31
- var ref;
32
- const focusNode = ((ref = contenteditable.firstChild) === null || ref === void 0 ? void 0 : ref.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
32
+ var _contenteditable_firstChild;
33
+ const focusNode = ((_contenteditable_firstChild = contenteditable.firstChild) === null || _contenteditable_firstChild === void 0 ? void 0 : _contenteditable_firstChild.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
33
34
  selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
34
35
  }
35
36
  } else {
@@ -1,5 +1,6 @@
1
- import { getConfig } from '@testing-library/dom';
1
+ import dtl from '../_interop/dtl.js';
2
2
 
3
+ const { getConfig } = dtl;
3
4
  function wrapEvent(cb, _element) {
4
5
  return getConfig().eventWrapper(cb);
5
6
  }
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { userEvent as default } from './setup/index.js';
1
+ export { userEvent as default, userEvent } from './setup/index.js';
2
2
  export { PointerEventsCheckLevel } from './options.js';
@@ -16,8 +16,8 @@ async function keyboard(text) {
16
16
  await keyboardAction(this, actions[i]);
17
17
  }
18
18
  }
19
- async function keyboardAction(instance, { keyDef , releasePrevious , releaseSelf , repeat }) {
20
- const { system } = instance;
19
+ async function keyboardAction(instance, { keyDef, releasePrevious, releaseSelf, repeat }) {
20
+ const { system } = instance;
21
21
  // Release the key automatically if it was pressed before.
22
22
  if (system.keyboard.isKeyPressed(keyDef)) {
23
23
  await system.keyboard.keyup(instance, keyDef);
@@ -19,18 +19,18 @@ import '../options.js';
19
19
  */ function parseKeyDef(keyboardMap, text) {
20
20
  const defs = [];
21
21
  do {
22
- const { type , descriptor , consumedLength , releasePrevious , releaseSelf =true , repeat , } = readNextDescriptor(text, 'keyboard');
23
- var ref;
24
- const keyDef = (ref = keyboardMap.find((def)=>{
22
+ const { type, descriptor, consumedLength, releasePrevious, releaseSelf = true, repeat } = readNextDescriptor(text, 'keyboard');
23
+ var _keyboardMap_find;
24
+ const keyDef = (_keyboardMap_find = keyboardMap.find((def)=>{
25
25
  if (type === '[') {
26
- var ref;
27
- return ((ref = def.code) === null || ref === void 0 ? void 0 : ref.toLowerCase()) === descriptor.toLowerCase();
26
+ var _def_code;
27
+ return ((_def_code = def.code) === null || _def_code === void 0 ? void 0 : _def_code.toLowerCase()) === descriptor.toLowerCase();
28
28
  } else if (type === '{') {
29
- var ref1;
30
- return ((ref1 = def.key) === null || ref1 === void 0 ? void 0 : ref1.toLowerCase()) === descriptor.toLowerCase();
29
+ var _def_key;
30
+ return ((_def_key = def.key) === null || _def_key === void 0 ? void 0 : _def_key.toLowerCase()) === descriptor.toLowerCase();
31
31
  }
32
32
  return def.key === descriptor;
33
- })) !== null && ref !== void 0 ? ref : {
33
+ })) !== null && _keyboardMap_find !== void 0 ? _keyboardMap_find : {
34
34
  key: 'Unknown',
35
35
  code: 'Unknown',
36
36
  [type === '[' ? 'code' : 'key']: descriptor
@@ -10,7 +10,7 @@ import '../options.js';
10
10
  import { parseKeyDef } from './parseKeyDef.js';
11
11
 
12
12
  async function pointer(input) {
13
- const { pointerMap } = this.config;
13
+ const { pointerMap } = this.config;
14
14
  const actions = [];
15
15
  (Array.isArray(input) ? input : [
16
16
  input
@@ -33,16 +33,16 @@ async function pointer(input) {
33
33
  this.system.pointer.resetClickCount();
34
34
  }
35
35
  async function pointerAction(instance, action) {
36
- var ref, ref1;
36
+ var _previousPosition, _previousPosition_caret, _previousPosition1, _previousPosition_caret1, _previousPosition2;
37
37
  const pointerName = 'pointerName' in action && action.pointerName ? action.pointerName : 'keyDef' in action ? instance.system.pointer.getPointerName(action.keyDef) : 'mouse';
38
38
  const previousPosition = instance.system.pointer.getPreviousPosition(pointerName);
39
- var _target, _coords, _node, _offset;
39
+ var _action_target, _action_coords, _action_node, _action_offset;
40
40
  const position = {
41
- target: (_target = action.target) !== null && _target !== void 0 ? _target : getPrevTarget(instance, previousPosition),
42
- coords: (_coords = action.coords) !== null && _coords !== void 0 ? _coords : previousPosition === null || previousPosition === void 0 ? void 0 : previousPosition.coords,
41
+ target: (_action_target = action.target) !== null && _action_target !== void 0 ? _action_target : getPrevTarget(instance, previousPosition),
42
+ coords: (_action_coords = action.coords) !== null && _action_coords !== void 0 ? _action_coords : (_previousPosition = previousPosition) === null || _previousPosition === void 0 ? void 0 : _previousPosition.coords,
43
43
  caret: {
44
- node: (_node = action.node) !== null && _node !== void 0 ? _node : hasCaretPosition(action) ? undefined : previousPosition === null || previousPosition === void 0 ? void 0 : (ref = previousPosition.caret) === null || ref === void 0 ? void 0 : ref.node,
45
- offset: (_offset = action.offset) !== null && _offset !== void 0 ? _offset : hasCaretPosition(action) ? undefined : previousPosition === null || previousPosition === void 0 ? void 0 : (ref1 = previousPosition.caret) === null || ref1 === void 0 ? void 0 : ref1.offset
44
+ node: (_action_node = action.node) !== null && _action_node !== void 0 ? _action_node : hasCaretPosition(action) ? undefined : (_previousPosition1 = previousPosition) === null || _previousPosition1 === void 0 ? void 0 : (_previousPosition_caret = _previousPosition1.caret) === null || _previousPosition_caret === void 0 ? void 0 : _previousPosition_caret.node,
45
+ offset: (_action_offset = action.offset) !== null && _action_offset !== void 0 ? _action_offset : hasCaretPosition(action) ? undefined : (_previousPosition2 = previousPosition) === null || _previousPosition2 === void 0 ? void 0 : (_previousPosition_caret1 = _previousPosition2.caret) === null || _previousPosition_caret1 === void 0 ? void 0 : _previousPosition_caret1.offset
46
46
  }
47
47
  };
48
48
  if ('keyDef' in action) {
@@ -64,15 +64,15 @@ async function pointerAction(instance, action) {
64
64
  }
65
65
  }
66
66
  function hasCaretPosition(action) {
67
- var _target, ref;
68
- return !!((ref = (_target = action.target) !== null && _target !== void 0 ? _target : action.node) !== null && ref !== void 0 ? ref : action.offset !== undefined);
67
+ var _action_target, _ref;
68
+ return !!((_ref = (_action_target = action.target) !== null && _action_target !== void 0 ? _action_target : action.node) !== null && _ref !== void 0 ? _ref : action.offset !== undefined);
69
69
  }
70
70
  function getPrevTarget(instance, position) {
71
71
  if (!position) {
72
72
  throw new Error('This pointer has no previous position. Provide a target property!');
73
73
  }
74
- var _target;
75
- return (_target = position.target) !== null && _target !== void 0 ? _target : instance.config.document.body;
74
+ var _position_target;
75
+ return (_position_target = position.target) !== null && _position_target !== void 0 ? _position_target : instance.config.document.body;
76
76
  }
77
77
 
78
78
  export { pointer };
@@ -25,7 +25,7 @@ const defaultKeyMap = [
25
25
  {
26
26
  name: 'TouchC',
27
27
  pointerType: 'touch'
28
- },
28
+ }
29
29
  ];
30
30
 
31
31
  export { defaultKeyMap };
@@ -10,7 +10,7 @@ import '../options.js';
10
10
  function parseKeyDef(pointerMap, keys) {
11
11
  const defs = [];
12
12
  do {
13
- const { descriptor , consumedLength , releasePrevious , releaseSelf =true , } = readNextDescriptor(keys, 'pointer');
13
+ const { descriptor, consumedLength, releasePrevious, releaseSelf = true } = readNextDescriptor(keys, 'pointer');
14
14
  const keyDef = pointerMap.find((p)=>p.name === descriptor);
15
15
  if (keyDef) {
16
16
  defs.push({
@@ -1,12 +1,33 @@
1
- export { click, dblClick, tripleClick } from '../convenience/click.js';
2
- export { hover, unhover } from '../convenience/hover.js';
3
- export { tab } from '../convenience/tab.js';
4
- export { keyboard } from '../keyboard/index.js';
5
- export { copy } from '../clipboard/copy.js';
6
- export { cut } from '../clipboard/cut.js';
7
- export { paste } from '../clipboard/paste.js';
8
- export { pointer } from '../pointer/index.js';
9
- export { clear } from '../utility/clear.js';
10
- export { deselectOptions, selectOptions } from '../utility/selectOptions.js';
11
- export { type } from '../utility/type.js';
12
- export { upload } from '../utility/upload.js';
1
+ import { click, dblClick, tripleClick } from '../convenience/click.js';
2
+ import { hover, unhover } from '../convenience/hover.js';
3
+ import { tab } from '../convenience/tab.js';
4
+ import { keyboard } from '../keyboard/index.js';
5
+ import { copy } from '../clipboard/copy.js';
6
+ import { cut } from '../clipboard/cut.js';
7
+ import { paste } from '../clipboard/paste.js';
8
+ import { pointer } from '../pointer/index.js';
9
+ import { clear } from '../utility/clear.js';
10
+ import { deselectOptions, selectOptions } from '../utility/selectOptions.js';
11
+ import { type } from '../utility/type.js';
12
+ import { upload } from '../utility/upload.js';
13
+
14
+ const userEventApi = {
15
+ click,
16
+ dblClick,
17
+ tripleClick,
18
+ hover,
19
+ unhover,
20
+ tab,
21
+ keyboard,
22
+ copy,
23
+ cut,
24
+ paste,
25
+ pointer,
26
+ clear,
27
+ deselectOptions,
28
+ selectOptions,
29
+ type,
30
+ upload
31
+ };
32
+
33
+ export { userEventApi };
@@ -22,11 +22,11 @@ function hover(element, options = {}) {
22
22
  return setupDirect(options).api.hover(element);
23
23
  }
24
24
  async function keyboard(text, options = {}) {
25
- const { api , system } = setupDirect(options);
25
+ const { api, system } = setupDirect(options);
26
26
  return api.keyboard(text).then(()=>system);
27
27
  }
28
28
  async function pointer(input, options = {}) {
29
- const { api , system } = setupDirect(options);
29
+ const { api, system } = setupDirect(options);
30
30
  return api.pointer(input).then(()=>system);
31
31
  }
32
32
  function paste(clipboardData, options) {
@@ -42,7 +42,7 @@ function type(element, text, options = {}) {
42
42
  return setupDirect(options, element).api.type(element, text, options);
43
43
  }
44
44
  function unhover(element, options = {}) {
45
- const { api , system } = setupDirect(options);
45
+ const { api, system } = setupDirect(options);
46
46
  system.pointer.setMousePosition({
47
47
  target: element
48
48
  });
@@ -14,7 +14,7 @@ import '@testing-library/dom';
14
14
  import { defaultKeyMap } from '../keyboard/keyMap.js';
15
15
  import { defaultKeyMap as defaultKeyMap$1 } from '../pointer/keyMap.js';
16
16
  import { System } from '../system/index.js';
17
- import * as api from './api.js';
17
+ import { userEventApi } from './api.js';
18
18
  import { wrapAsync } from './wrapAsync.js';
19
19
 
20
20
  /**
@@ -53,18 +53,18 @@ function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
53
53
  */ function setupMain(options = {}) {
54
54
  const config = createConfig(options);
55
55
  prepareDocument(config.document);
56
- var _defaultView;
57
- const view = (_defaultView = config.document.defaultView) !== null && _defaultView !== void 0 ? _defaultView : /* istanbul ignore next */ globalThis.window;
56
+ var _config_document_defaultView;
57
+ const view = (_config_document_defaultView = config.document.defaultView) !== null && _config_document_defaultView !== void 0 ? _config_document_defaultView : /* istanbul ignore next */ globalThis.window;
58
58
  attachClipboardStubToView(view);
59
59
  return createInstance(config).api;
60
60
  }
61
61
  /**
62
62
  * Setup in direct call per `userEvent.anyApi()`
63
- */ function setupDirect({ keyboardState , pointerState , ...options } = {}, node) {
63
+ */ function setupDirect({ keyboardState, pointerState, ...options } = {}, node) {
64
64
  const config = createConfig(options, defaultOptionsDirect, node);
65
65
  prepareDocument(config.document);
66
- var ref;
67
- const system = (ref = pointerState !== null && pointerState !== void 0 ? pointerState : keyboardState) !== null && ref !== void 0 ? ref : new System();
66
+ var _ref;
67
+ const system = (_ref = pointerState !== null && pointerState !== void 0 ? pointerState : keyboardState) !== null && _ref !== void 0 ? _ref : new System();
68
68
  return {
69
69
  api: createInstance(config, system).api,
70
70
  system
@@ -99,22 +99,22 @@ function createInstance(config, system = new System()) {
99
99
  dispatchUIEvent: dispatchUIEvent.bind(instance),
100
100
  system,
101
101
  levelRefs: {},
102
- ...api
102
+ ...userEventApi
103
103
  });
104
104
  return {
105
105
  instance,
106
106
  api: {
107
- ...Object.fromEntries(Object.entries(api).map(([name, api])=>[
107
+ ...Object.fromEntries(Object.entries(userEventApi).map(([name, api])=>[
108
108
  name,
109
- wrapAndBindImpl(instance, api),
109
+ wrapAndBindImpl(instance, api)
110
110
  ])),
111
111
  setup: setupSub.bind(instance)
112
112
  }
113
113
  };
114
114
  }
115
115
  function getDocument(options, node, defaults) {
116
- var _document, ref;
117
- return (ref = (_document = options.document) !== null && _document !== void 0 ? _document : node && getDocumentFromNode(node)) !== null && ref !== void 0 ? ref : defaults.document;
116
+ var _options_document, _ref;
117
+ return (_ref = (_options_document = options.document) !== null && _options_document !== void 0 ? _options_document : node && getDocumentFromNode(node)) !== null && _ref !== void 0 ? _ref : defaults.document;
118
118
  }
119
119
 
120
120
  export { createConfig, createInstance, setupDirect, setupMain, setupSub };
@@ -1,5 +1,6 @@
1
- import { getConfig } from '@testing-library/dom';
1
+ import dtl from '../_interop/dtl.js';
2
2
 
3
+ const { getConfig } = dtl;
3
4
  /**
4
5
  * Wrap an internal Promise
5
6
  */ function wrapAsync(implementation) {
@@ -1,6 +1,19 @@
1
1
  import { KeyboardHost } from './keyboard.js';
2
2
  import { PointerHost } from './pointer/index.js';
3
3
 
4
+ function _define_property(obj, key, value) {
5
+ if (key in obj) {
6
+ Object.defineProperty(obj, key, {
7
+ value: value,
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true
11
+ });
12
+ } else {
13
+ obj[key] = value;
14
+ }
15
+ return obj;
16
+ }
4
17
  /**
5
18
  * @internal Do not create/alter this by yourself as this type might be subject to changes.
6
19
  */ class System {
@@ -21,8 +34,8 @@ import { PointerHost } from './pointer/index.js';
21
34
  };
22
35
  }
23
36
  constructor(){
24
- this.keyboard = new KeyboardHost(this);
25
- this.pointer = new PointerHost(this);
37
+ _define_property(this, "keyboard", new KeyboardHost(this));
38
+ _define_property(this, "pointer", new PointerHost(this));
26
39
  }
27
40
  }
28
41