@testing-library/user-event 14.6.1 → 14.6.4

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 (116) hide show
  1. package/README.md +19 -16
  2. package/dist/cjs/clipboard/copy.js +2 -2
  3. package/dist/cjs/clipboard/cut.js +2 -2
  4. package/dist/cjs/clipboard/paste.js +3 -4
  5. package/dist/cjs/document/UI.js +5 -7
  6. package/dist/cjs/document/interceptor.js +4 -4
  7. package/dist/cjs/document/patchFocus.js +5 -3
  8. package/dist/cjs/document/trackValue.js +2 -2
  9. package/dist/cjs/event/behavior/keydown.js +4 -4
  10. package/dist/cjs/event/behavior/keypress.js +1 -1
  11. package/dist/cjs/event/behavior/keyup.js +1 -1
  12. package/dist/cjs/event/behavior/paste.js +1 -1
  13. package/dist/cjs/event/createEvent.js +25 -39
  14. package/dist/cjs/event/dispatchEvent.js +1 -1
  15. package/dist/cjs/event/focus.js +3 -3
  16. package/dist/cjs/event/input.js +3 -2
  17. package/dist/cjs/event/selection/getInputRange.js +1 -1
  18. package/dist/cjs/event/selection/getTargetTypeAndSelection.js +2 -2
  19. package/dist/cjs/event/selection/modifySelection.js +1 -1
  20. package/dist/cjs/event/selection/modifySelectionPerMouse.js +2 -2
  21. package/dist/cjs/event/selection/moveSelection.js +1 -1
  22. package/dist/cjs/event/selection/resolveCaretPosition.js +4 -5
  23. package/dist/cjs/event/selection/selectAll.js +5 -5
  24. package/dist/cjs/event/selection/setSelection.js +1 -1
  25. package/dist/cjs/event/selection/setSelectionPerMouse.js +9 -11
  26. package/dist/cjs/event/selection/setSelectionRange.js +1 -1
  27. package/dist/cjs/event/selection/updateSelectionOnFocus.js +2 -2
  28. package/dist/cjs/event/wrapEvent.js +2 -1
  29. package/dist/cjs/keyboard/index.js +1 -1
  30. package/dist/cjs/keyboard/parseKeyDef.js +4 -4
  31. package/dist/cjs/pointer/index.js +9 -9
  32. package/dist/cjs/setup/api.js +4 -4
  33. package/dist/cjs/setup/setup.js +10 -10
  34. package/dist/cjs/system/index.js +1 -3
  35. package/dist/cjs/system/keyboard.js +8 -11
  36. package/dist/cjs/system/pointer/buttons.js +1 -5
  37. package/dist/cjs/system/pointer/device.js +1 -3
  38. package/dist/cjs/system/pointer/index.js +19 -22
  39. package/dist/cjs/system/pointer/mouse.js +10 -13
  40. package/dist/cjs/system/pointer/pointer.js +6 -8
  41. package/dist/cjs/system/pointer/shared.js +1 -1
  42. package/dist/cjs/utility/type.js +1 -1
  43. package/dist/cjs/utility/upload.js +3 -3
  44. package/dist/cjs/utils/dataTransfer/Clipboard.js +14 -9
  45. package/dist/cjs/utils/dataTransfer/DataTransfer.js +5 -7
  46. package/dist/cjs/utils/edit/isContentEditable.js +1 -1
  47. package/dist/cjs/utils/edit/maxLength.js +1 -1
  48. package/dist/cjs/utils/edit/setFiles.js +2 -3
  49. package/dist/cjs/utils/focus/cursor.js +1 -1
  50. package/dist/cjs/utils/focus/getActiveElement.js +10 -8
  51. package/dist/cjs/utils/focus/selector.js +2 -1
  52. package/dist/cjs/utils/keyDef/readNextDescriptor.js +8 -9
  53. package/dist/cjs/utils/misc/getWindow.js +1 -1
  54. package/dist/cjs/utils/misc/isDisabled.js +1 -1
  55. package/dist/cjs/utils/misc/isVisible.js +1 -1
  56. package/dist/cjs/utils/pointer/cssPointerEvents.js +11 -12
  57. package/dist/esm/clipboard/copy.js +2 -2
  58. package/dist/esm/clipboard/cut.js +2 -2
  59. package/dist/esm/clipboard/paste.js +3 -4
  60. package/dist/esm/document/UI.js +5 -7
  61. package/dist/esm/document/interceptor.js +5 -5
  62. package/dist/esm/document/patchFocus.js +5 -3
  63. package/dist/esm/document/trackValue.js +3 -3
  64. package/dist/esm/event/behavior/keydown.js +5 -5
  65. package/dist/esm/event/behavior/keypress.js +1 -1
  66. package/dist/esm/event/behavior/keyup.js +1 -1
  67. package/dist/esm/event/behavior/paste.js +1 -1
  68. package/dist/esm/event/createEvent.js +25 -39
  69. package/dist/esm/event/dispatchEvent.js +1 -1
  70. package/dist/esm/event/focus.js +3 -3
  71. package/dist/esm/event/input.js +3 -2
  72. package/dist/esm/event/selection/getInputRange.js +1 -1
  73. package/dist/esm/event/selection/getTargetTypeAndSelection.js +2 -2
  74. package/dist/esm/event/selection/modifySelection.js +1 -1
  75. package/dist/esm/event/selection/modifySelectionPerMouse.js +2 -2
  76. package/dist/esm/event/selection/moveSelection.js +1 -1
  77. package/dist/esm/event/selection/resolveCaretPosition.js +4 -5
  78. package/dist/esm/event/selection/selectAll.js +6 -6
  79. package/dist/esm/event/selection/setSelection.js +1 -1
  80. package/dist/esm/event/selection/setSelectionPerMouse.js +9 -11
  81. package/dist/esm/event/selection/setSelectionRange.js +1 -1
  82. package/dist/esm/event/selection/updateSelectionOnFocus.js +2 -2
  83. package/dist/esm/event/wrapEvent.js +2 -1
  84. package/dist/esm/keyboard/index.js +1 -1
  85. package/dist/esm/keyboard/parseKeyDef.js +4 -4
  86. package/dist/esm/pointer/index.js +9 -9
  87. package/dist/esm/setup/api.js +3 -3
  88. package/dist/esm/setup/setup.js +11 -11
  89. package/dist/esm/system/index.js +1 -3
  90. package/dist/esm/system/keyboard.js +8 -11
  91. package/dist/esm/system/pointer/buttons.js +1 -5
  92. package/dist/esm/system/pointer/device.js +1 -3
  93. package/dist/esm/system/pointer/index.js +19 -22
  94. package/dist/esm/system/pointer/mouse.js +10 -13
  95. package/dist/esm/system/pointer/pointer.js +6 -8
  96. package/dist/esm/system/pointer/shared.js +1 -1
  97. package/dist/esm/utility/type.js +1 -1
  98. package/dist/esm/utility/upload.js +3 -3
  99. package/dist/esm/utils/dataTransfer/Clipboard.js +14 -9
  100. package/dist/esm/utils/dataTransfer/DataTransfer.js +5 -7
  101. package/dist/esm/utils/edit/isContentEditable.js +1 -1
  102. package/dist/esm/utils/edit/maxLength.js +1 -1
  103. package/dist/esm/utils/edit/setFiles.js +2 -3
  104. package/dist/esm/utils/focus/cursor.js +1 -1
  105. package/dist/esm/utils/focus/getActiveElement.js +10 -8
  106. package/dist/esm/utils/focus/selector.js +2 -1
  107. package/dist/esm/utils/keyDef/readNextDescriptor.js +8 -9
  108. package/dist/esm/utils/misc/getWindow.js +1 -1
  109. package/dist/esm/utils/misc/isDisabled.js +1 -1
  110. package/dist/esm/utils/misc/isVisible.js +1 -1
  111. package/dist/esm/utils/pointer/cssPointerEvents.js +11 -12
  112. package/dist/types/document/UI.d.ts +3 -3
  113. package/dist/types/event/behavior/registry.d.ts +1 -2
  114. package/dist/types/options.d.ts +1 -1
  115. package/dist/types/system/keyboard.d.ts +1 -1
  116. package/package.json +6 -3
@@ -36,56 +36,42 @@ function createEvent(type, target, init) {
36
36
  const window = getWindow(target);
37
37
  const { EventType, defaultInit } = eventMap[type];
38
38
  const event = new (getEventConstructors(window))[EventType](type, defaultInit);
39
- eventInitializer[EventType].forEach((f)=>f(event, init !== null && init !== undefined ? init : {}));
39
+ eventInitializer[EventType].forEach((f)=>f(event, init !== null && init !== void 0 ? init : {}));
40
40
  return event;
41
41
  }
42
42
  /* istanbul ignore next */ function getEventConstructors(window) {
43
- var _window_Event;
44
- /* eslint-disable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-extraneous-class */ const Event = (_window_Event = window.Event) !== null && _window_Event !== undefined ? _window_Event : class Event {
43
+ var _window_Event, _window_AnimationEvent, _window_ClipboardEvent, _window_PopStateEvent, _window_ProgressEvent, _window_TransitionEvent, _window_UIEvent, _window_CompositionEvent, _window_FocusEvent, _window_InputEvent, _window_KeyboardEvent, _window_MouseEvent, _window_DragEvent, _window_PointerEvent, _window_TouchEvent;
44
+ const Event = (_window_Event = window.Event) !== null && _window_Event !== void 0 ? _window_Event : class Event {
45
45
  };
46
- var _window_AnimationEvent;
47
- const AnimationEvent = (_window_AnimationEvent = window.AnimationEvent) !== null && _window_AnimationEvent !== undefined ? _window_AnimationEvent : class AnimationEvent extends Event {
46
+ const AnimationEvent = (_window_AnimationEvent = window.AnimationEvent) !== null && _window_AnimationEvent !== void 0 ? _window_AnimationEvent : class AnimationEvent extends Event {
48
47
  };
49
- var _window_ClipboardEvent;
50
- const ClipboardEvent = (_window_ClipboardEvent = window.ClipboardEvent) !== null && _window_ClipboardEvent !== undefined ? _window_ClipboardEvent : class ClipboardEvent extends Event {
48
+ const ClipboardEvent = (_window_ClipboardEvent = window.ClipboardEvent) !== null && _window_ClipboardEvent !== void 0 ? _window_ClipboardEvent : class ClipboardEvent extends Event {
51
49
  };
52
- var _window_PopStateEvent;
53
- const PopStateEvent = (_window_PopStateEvent = window.PopStateEvent) !== null && _window_PopStateEvent !== undefined ? _window_PopStateEvent : class PopStateEvent extends Event {
50
+ const PopStateEvent = (_window_PopStateEvent = window.PopStateEvent) !== null && _window_PopStateEvent !== void 0 ? _window_PopStateEvent : class PopStateEvent extends Event {
54
51
  };
55
- var _window_ProgressEvent;
56
- const ProgressEvent = (_window_ProgressEvent = window.ProgressEvent) !== null && _window_ProgressEvent !== undefined ? _window_ProgressEvent : class ProgressEvent extends Event {
52
+ const ProgressEvent = (_window_ProgressEvent = window.ProgressEvent) !== null && _window_ProgressEvent !== void 0 ? _window_ProgressEvent : class ProgressEvent extends Event {
57
53
  };
58
- var _window_TransitionEvent;
59
- const TransitionEvent = (_window_TransitionEvent = window.TransitionEvent) !== null && _window_TransitionEvent !== undefined ? _window_TransitionEvent : class TransitionEvent extends Event {
54
+ const TransitionEvent = (_window_TransitionEvent = window.TransitionEvent) !== null && _window_TransitionEvent !== void 0 ? _window_TransitionEvent : class TransitionEvent extends Event {
60
55
  };
61
- var _window_UIEvent;
62
- const UIEvent = (_window_UIEvent = window.UIEvent) !== null && _window_UIEvent !== undefined ? _window_UIEvent : class UIEvent extends Event {
56
+ const UIEvent = (_window_UIEvent = window.UIEvent) !== null && _window_UIEvent !== void 0 ? _window_UIEvent : class UIEvent extends Event {
63
57
  };
64
- var _window_CompositionEvent;
65
- const CompositionEvent = (_window_CompositionEvent = window.CompositionEvent) !== null && _window_CompositionEvent !== undefined ? _window_CompositionEvent : class CompositionEvent extends UIEvent {
58
+ const CompositionEvent = (_window_CompositionEvent = window.CompositionEvent) !== null && _window_CompositionEvent !== void 0 ? _window_CompositionEvent : class CompositionEvent extends UIEvent {
66
59
  };
67
- var _window_FocusEvent;
68
- const FocusEvent = (_window_FocusEvent = window.FocusEvent) !== null && _window_FocusEvent !== undefined ? _window_FocusEvent : class FocusEvent extends UIEvent {
60
+ const FocusEvent = (_window_FocusEvent = window.FocusEvent) !== null && _window_FocusEvent !== void 0 ? _window_FocusEvent : class FocusEvent extends UIEvent {
69
61
  };
70
- var _window_InputEvent;
71
- const InputEvent = (_window_InputEvent = window.InputEvent) !== null && _window_InputEvent !== undefined ? _window_InputEvent : class InputEvent extends UIEvent {
62
+ const InputEvent = (_window_InputEvent = window.InputEvent) !== null && _window_InputEvent !== void 0 ? _window_InputEvent : class InputEvent extends UIEvent {
72
63
  };
73
- var _window_KeyboardEvent;
74
- const KeyboardEvent = (_window_KeyboardEvent = window.KeyboardEvent) !== null && _window_KeyboardEvent !== undefined ? _window_KeyboardEvent : class KeyboardEvent extends UIEvent {
64
+ const KeyboardEvent = (_window_KeyboardEvent = window.KeyboardEvent) !== null && _window_KeyboardEvent !== void 0 ? _window_KeyboardEvent : class KeyboardEvent extends UIEvent {
75
65
  };
76
- var _window_MouseEvent;
77
- const MouseEvent = (_window_MouseEvent = window.MouseEvent) !== null && _window_MouseEvent !== undefined ? _window_MouseEvent : class MouseEvent extends UIEvent {
66
+ const MouseEvent = (_window_MouseEvent = window.MouseEvent) !== null && _window_MouseEvent !== void 0 ? _window_MouseEvent : class MouseEvent extends UIEvent {
78
67
  };
79
- var _window_DragEvent;
80
- const DragEvent = (_window_DragEvent = window.DragEvent) !== null && _window_DragEvent !== undefined ? _window_DragEvent : class DragEvent extends MouseEvent {
68
+ const DragEvent = (_window_DragEvent = window.DragEvent) !== null && _window_DragEvent !== void 0 ? _window_DragEvent : class DragEvent extends MouseEvent {
81
69
  };
82
- var _window_PointerEvent;
83
- const PointerEvent = (_window_PointerEvent = window.PointerEvent) !== null && _window_PointerEvent !== undefined ? _window_PointerEvent : class PointerEvent extends MouseEvent {
70
+ const PointerEvent = (_window_PointerEvent = window.PointerEvent) !== null && _window_PointerEvent !== void 0 ? _window_PointerEvent : class PointerEvent extends MouseEvent {
84
71
  };
85
- var _window_TouchEvent;
86
- const TouchEvent = (_window_TouchEvent = window.TouchEvent) !== null && _window_TouchEvent !== undefined ? _window_TouchEvent : class TouchEvent extends UIEvent {
72
+ const TouchEvent = (_window_TouchEvent = window.TouchEvent) !== null && _window_TouchEvent !== void 0 ? _window_TouchEvent : class TouchEvent extends UIEvent {
87
73
  };
88
- /* eslint-enable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-extraneous-class */ return {
74
+ return {
89
75
  Event,
90
76
  AnimationEvent,
91
77
  ClipboardEvent,
@@ -106,12 +92,12 @@ function createEvent(type, target, init) {
106
92
  function assignProps(obj, props) {
107
93
  for (const [key, value] of Object.entries(props)){
108
94
  Object.defineProperty(obj, key, {
109
- get: ()=>value !== null && value !== undefined ? value : null
95
+ get: ()=>value !== null && value !== void 0 ? value : null
110
96
  });
111
97
  }
112
98
  }
113
99
  function sanitizeNumber(n) {
114
- return Number(n !== null && n !== undefined ? n : 0);
100
+ return Number(n !== null && n !== void 0 ? n : 0);
115
101
  }
116
102
  function initClipboardEvent(event, { clipboardData }) {
117
103
  assignProps(event, {
@@ -133,7 +119,7 @@ function initInputEvent(event, { data, inputType, isComposing }) {
133
119
  function initUIEvent(event, { view, detail }) {
134
120
  assignProps(event, {
135
121
  view,
136
- detail: sanitizeNumber(detail !== null && detail !== undefined ? detail : 0)
122
+ detail: sanitizeNumber(detail !== null && detail !== void 0 ? detail : 0)
137
123
  });
138
124
  }
139
125
  function initUIEventModifiers(event, { altKey, ctrlKey, metaKey, shiftKey, modifierAltGraph, modifierCapsLock, modifierFn, modifierFnLock, modifierNumLock, modifierScrollLock, modifierSymbol, modifierSymbolLock }) {
@@ -187,12 +173,12 @@ function initMouseEvent(event, { x, y, screenX, screenY, clientX = x, clientY =
187
173
  pageY: sanitizeNumber(pageY)
188
174
  });
189
175
  }
190
- function initPointerEvent(event, { pointerId, width, height, pressure, tangentialPressure, tiltX, tiltY, twist, pointerType, isPrimary }) {
176
+ function initPointerEvent(event, { pointerId, width, height, pressure, tangentialPressure, tiltX, tiltY, twist, pointerType, isPrimary, buttons }) {
191
177
  assignProps(event, {
192
178
  pointerId: sanitizeNumber(pointerId),
193
- width: sanitizeNumber(width !== null && width !== undefined ? width : 1),
194
- height: sanitizeNumber(height !== null && height !== undefined ? height : 1),
195
- pressure: sanitizeNumber(pressure),
179
+ width: sanitizeNumber(width !== null && width !== void 0 ? width : 1),
180
+ height: sanitizeNumber(height !== null && height !== void 0 ? height : 1),
181
+ pressure: sanitizeNumber(pressure !== null && pressure !== void 0 ? pressure : buttons ? 0.5 : 0),
196
182
  tangentialPressure: sanitizeNumber(tangentialPressure),
197
183
  tiltX: sanitizeNumber(tiltX),
198
184
  tiltY: sanitizeNumber(tiltY),
@@ -22,7 +22,7 @@ function dispatchUIEvent(target, type, init, preventDefault = false) {
22
22
  function dispatchEvent(target, event, preventDefault = false) {
23
23
  var _behavior_type;
24
24
  const type = event.type;
25
- const behaviorImplementation = preventDefault ? ()=>{} : (_behavior_type = behavior[type]) === null || _behavior_type === undefined ? undefined : _behavior_type.call(behavior, event, target, this);
25
+ const behaviorImplementation = preventDefault ? ()=>{} : (_behavior_type = behavior[type]) === null || _behavior_type === void 0 ? void 0 : _behavior_type.call(behavior, event, target, this);
26
26
  if (behaviorImplementation) {
27
27
  event.preventDefault();
28
28
  let defaultPrevented = false;
@@ -12,14 +12,14 @@ import { wrapEvent } from './wrapEvent.js';
12
12
  */ function focusElement(element) {
13
13
  const target = findClosest(element, isFocusable);
14
14
  const activeElement = getActiveElement(element.ownerDocument);
15
- if ((target !== null && target !== undefined ? target : element.ownerDocument.body) === activeElement) {
15
+ if ((target !== null && target !== void 0 ? target : element.ownerDocument.body) === activeElement) {
16
16
  return;
17
17
  } else if (target) {
18
18
  wrapEvent(()=>target.focus());
19
19
  } else {
20
- wrapEvent(()=>activeElement === null || activeElement === undefined ? undefined : activeElement.blur());
20
+ wrapEvent(()=>activeElement === null || activeElement === void 0 ? void 0 : activeElement.blur());
21
21
  }
22
- updateSelectionOnFocus(target !== null && target !== undefined ? target : element.ownerDocument.body);
22
+ updateSelectionOnFocus(target !== null && target !== void 0 ? target : element.ownerDocument.body);
23
23
  }
24
24
  function blurElement(element) {
25
25
  if (!isFocusable(element)) return;
@@ -80,7 +80,8 @@ function editInputElement(instance, element, inputRange, data, inputType) {
80
80
  if (supportsMaxLength(element)) {
81
81
  const maxLength = getMaxLength(element);
82
82
  if (maxLength !== undefined && data.length > 0) {
83
- const spaceUntilMaxLength = maxLength - element.value.length;
83
+ const selectionLength = inputRange.endOffset - inputRange.startOffset;
84
+ const spaceUntilMaxLength = maxLength - element.value.length + selectionLength;
84
85
  if (spaceUntilMaxLength > 0) {
85
86
  dataToInsert = data.substring(0, spaceUntilMaxLength);
86
87
  } else {
@@ -149,7 +150,7 @@ function isValidNumberInput(value) {
149
150
  // it allows up to two '-' at any place before any 'e' or one directly following 'e'
150
151
  // it allows one '.' at any place before e
151
152
  const valueParts = value.split('e', 2);
152
- return !(/[^\d.\-e]/.test(value) || Number((_value_match = value.match(/-/g)) === null || _value_match === undefined ? undefined : _value_match.length) > 2 || Number((_value_match1 = value.match(/\./g)) === null || _value_match1 === undefined ? undefined : _value_match1.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1]));
153
+ 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]));
153
154
  }
154
155
 
155
156
  export { input };
@@ -9,7 +9,7 @@ import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
9
9
  } else if (typeAndSelection.type === 'contenteditable') {
10
10
  var _typeAndSelection_selection;
11
11
  // Multi-range on contenteditable edits the first selection instead of the last
12
- return (_typeAndSelection_selection = typeAndSelection.selection) === null || _typeAndSelection_selection === undefined ? undefined : _typeAndSelection_selection.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,10 +13,10 @@ import { hasOwnSelection } from '../../utils/focus/selection.js';
13
13
  selection: getUISelection(element)
14
14
  };
15
15
  }
16
- const selection = element === null || element === undefined ? undefined : element.ownerDocument.getSelection();
16
+ const selection = element === null || element === void 0 ? void 0 : element.ownerDocument.getSelection();
17
17
  // It is possible to extend a single-range selection into a contenteditable.
18
18
  // This results in the range acting like a range outside of contenteditable.
19
- const isCE = getContentEditable(node) && (selection === null || selection === undefined ? undefined : selection.anchorNode) && getContentEditable(selection.anchorNode);
19
+ const isCE = getContentEditable(node) && (selection === null || selection === void 0 ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode);
20
20
  return {
21
21
  type: isCE ? 'contenteditable' : 'default',
22
22
  selection
@@ -13,7 +13,7 @@ import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
13
13
  focusOffset
14
14
  }, 'modify');
15
15
  }
16
- (_focusNode_ownerDocument = focusNode.ownerDocument) === null || _focusNode_ownerDocument === undefined ? undefined : (_focusNode_ownerDocument_getSelection = _focusNode_ownerDocument.getSelection()) === null || _focusNode_ownerDocument_getSelection === undefined ? undefined : _focusNode_ownerDocument_getSelection.extend(focusNode, focusOffset);
16
+ (_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);
17
17
  }
18
18
 
19
19
  export { modifySelection };
@@ -30,8 +30,8 @@ function modifySelectionPerMouseMove(selectionRange, { document, target, node, o
30
30
  range.setEnd(selectionFocus.node, selectionFocus.offset);
31
31
  }
32
32
  const selection = document.getSelection();
33
- selection === null || selection === undefined ? undefined : selection.removeAllRanges();
34
- selection === null || selection === undefined ? undefined : selection.addRange(range.cloneRange());
33
+ selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
34
+ selection === null || selection === void 0 ? void 0 : selection.addRange(range.cloneRange());
35
35
  }
36
36
  }
37
37
 
@@ -16,7 +16,7 @@ import { setSelection } from './setSelection.js';
16
16
  });
17
17
  } else {
18
18
  const selection = node.ownerDocument.getSelection();
19
- if (!(selection === null || selection === undefined ? undefined : selection.focusNode)) {
19
+ if (!(selection === null || selection === void 0 ? void 0 : selection.focusNode)) {
20
20
  return;
21
21
  }
22
22
  if (selection.isCollapsed) {
@@ -6,12 +6,12 @@ function resolveCaretPosition({ target, node, offset }) {
6
6
  if (hasOwnSelection(target)) {
7
7
  return {
8
8
  node: target,
9
- offset: offset !== null && offset !== undefined ? offset : getUIValue(target).length
9
+ offset: offset !== null && offset !== void 0 ? offset : getUIValue(target).length
10
10
  };
11
11
  } else if (node) {
12
12
  return {
13
13
  node,
14
- offset: offset !== null && offset !== undefined ? offset : node.nodeType === 3 ? node.nodeValue.length : node.childNodes.length
14
+ offset: offset !== null && offset !== void 0 ? offset : node.nodeType === 3 ? node.nodeValue.length : node.childNodes.length
15
15
  };
16
16
  }
17
17
  return findNodeAtTextOffset(target, offset);
@@ -39,11 +39,10 @@ function findNodeAtTextOffset(node, offset, isRoot = true) {
39
39
  } else {
40
40
  // The pre-commit hooks keeps changing this
41
41
  // See https://github.com/kentcdodds/kcd-scripts/issues/218
42
- /* istanbul ignore else */ // eslint-disable-next-line no-lonely-if
43
- if (c.nodeType === 3) {
42
+ /* istanbul ignore else */ if (c.nodeType === 3) {
44
43
  return {
45
44
  node: c,
46
- offset: offset !== null && offset !== undefined ? offset : c.nodeValue.length
45
+ offset: offset !== null && offset !== void 0 ? offset : c.nodeValue.length
47
46
  };
48
47
  }
49
48
  }
@@ -1,4 +1,4 @@
1
- import { getUIValue, getUISelection } from '../../document/UI.js';
1
+ import { getUISelection, getUIValue } from '../../document/UI.js';
2
2
  import '../../utils/dataTransfer/Clipboard.js';
3
3
  import { getContentEditable } from '../../utils/edit/isContentEditable.js';
4
4
  import { hasOwnSelection } from '../../utils/focus/selection.js';
@@ -7,6 +7,7 @@ import { setSelection } from './setSelection.js';
7
7
  /**
8
8
  * Expand a selection like the browser does when pressing Ctrl+A.
9
9
  */ function selectAll(target) {
10
+ var _getContentEditable;
10
11
  if (hasOwnSelection(target)) {
11
12
  return setSelection({
12
13
  focusNode: target,
@@ -14,8 +15,7 @@ import { setSelection } from './setSelection.js';
14
15
  focusOffset: getUIValue(target).length
15
16
  });
16
17
  }
17
- var _getContentEditable;
18
- const focusNode = (_getContentEditable = getContentEditable(target)) !== null && _getContentEditable !== undefined ? _getContentEditable : target.ownerDocument.body;
18
+ const focusNode = (_getContentEditable = getContentEditable(target)) !== null && _getContentEditable !== void 0 ? _getContentEditable : target.ownerDocument.body;
19
19
  setSelection({
20
20
  focusNode,
21
21
  anchorOffset: 0,
@@ -23,13 +23,13 @@ import { setSelection } from './setSelection.js';
23
23
  });
24
24
  }
25
25
  function isAllSelected(target) {
26
+ var _getContentEditable;
26
27
  if (hasOwnSelection(target)) {
27
28
  return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
28
29
  }
29
- var _getContentEditable;
30
- const focusNode = (_getContentEditable = getContentEditable(target)) !== null && _getContentEditable !== undefined ? _getContentEditable : target.ownerDocument.body;
30
+ const focusNode = (_getContentEditable = getContentEditable(target)) !== null && _getContentEditable !== void 0 ? _getContentEditable : target.ownerDocument.body;
31
31
  const selection = target.ownerDocument.getSelection();
32
- return (selection === null || selection === undefined ? undefined : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
32
+ return (selection === null || selection === void 0 ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
33
33
  }
34
34
 
35
35
  export { isAllSelected, selectAll };
@@ -13,7 +13,7 @@ import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
13
13
  focusOffset
14
14
  });
15
15
  }
16
- (_anchorNode_ownerDocument = anchorNode.ownerDocument) === null || _anchorNode_ownerDocument === undefined ? undefined : (_anchorNode_ownerDocument_getSelection = _anchorNode_ownerDocument.getSelection()) === null || _anchorNode_ownerDocument_getSelection === undefined ? undefined : _anchorNode_ownerDocument_getSelection.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
16
+ (_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);
17
17
  }
18
18
 
19
19
  export { setSelection };
@@ -14,22 +14,20 @@ function setSelectionPerMouseDown({ document, target, clickCount, node, offset }
14
14
  // Looks it might be every inline element.
15
15
  // TODO: Check what might be considered part of the same line of text.
16
16
  const text = String(targetHasOwnSelection ? getUIValue(target) : target.textContent);
17
- const [start, end] = node ? // which elements might be considered in the same line of text.
18
- // TODO: support expanding initial range on multiple clicks if node is given
19
- [
17
+ const [start, end] = node ? [
20
18
  offset,
21
19
  offset
22
20
  ] : getTextRange(text, offset, clickCount);
23
21
  // TODO: implement modifying selection per shift/ctrl+mouse
24
22
  if (targetHasOwnSelection) {
25
23
  setUISelection(target, {
26
- anchorOffset: start !== null && start !== undefined ? start : text.length,
27
- focusOffset: end !== null && end !== undefined ? end : text.length
24
+ anchorOffset: start !== null && start !== void 0 ? start : text.length,
25
+ focusOffset: end !== null && end !== void 0 ? end : text.length
28
26
  });
29
27
  return {
30
28
  node: target,
31
- start: start !== null && start !== undefined ? start : 0,
32
- end: end !== null && end !== undefined ? end : text.length
29
+ start: start !== null && start !== void 0 ? start : 0,
30
+ end: end !== null && end !== void 0 ? end : text.length
33
31
  };
34
32
  } else {
35
33
  const { node: startNode, offset: startOffset } = resolveCaretPosition({
@@ -46,12 +44,12 @@ function setSelectionPerMouseDown({ document, target, clickCount, node, offset }
46
44
  try {
47
45
  range.setStart(startNode, startOffset);
48
46
  range.setEnd(endNode, endOffset);
49
- } catch (e) {
47
+ } catch {
50
48
  throw new Error('The given offset is out of bounds.');
51
49
  }
52
50
  const selection = document.getSelection();
53
- selection === null || selection === undefined ? undefined : selection.removeAllRanges();
54
- selection === null || selection === undefined ? undefined : selection.addRange(range.cloneRange());
51
+ selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
52
+ selection === null || selection === void 0 ? void 0 : selection.addRange(range.cloneRange());
55
53
  return range;
56
54
  }
57
55
  }
@@ -62,7 +60,7 @@ function getTextRange(text, pos, clickCount) {
62
60
  pos
63
61
  ];
64
62
  }
65
- const textPos = pos !== null && pos !== undefined ? pos : text.length;
63
+ const textPos = pos !== null && pos !== void 0 ? pos : text.length;
66
64
  if (clickCount % 3 === 2) {
67
65
  return [
68
66
  textPos - text.substr(0, pos).match(/(\w+|\s+|\W)?$/)[0].length,
@@ -16,7 +16,7 @@ import { setSelection } from './setSelection.js';
16
16
  focusOffset
17
17
  });
18
18
  }
19
- /* istanbul ignore else */ if (isContentEditable(element) && ((_element_firstChild = element.firstChild) === null || _element_firstChild === undefined ? undefined : _element_firstChild.nodeType) === 3) {
19
+ /* istanbul ignore else */ if (isContentEditable(element) && ((_element_firstChild = element.firstChild) === null || _element_firstChild === void 0 ? void 0 : _element_firstChild.nodeType) === 3) {
20
20
  return setSelection({
21
21
  focusNode: element.firstChild,
22
22
  anchorOffset,
@@ -11,7 +11,7 @@ import { hasOwnSelection } from '../../utils/focus/selection.js';
11
11
  * with own selection implementation.
12
12
  */ function updateSelectionOnFocus(element) {
13
13
  const selection = element.ownerDocument.getSelection();
14
- /* istanbul ignore if */ if (!(selection === null || selection === undefined ? undefined : selection.focusNode)) {
14
+ /* istanbul ignore if */ if (!(selection === null || selection === void 0 ? void 0 : selection.focusNode)) {
15
15
  return;
16
16
  }
17
17
  // If the focus moves inside an element with own selection implementation,
@@ -26,7 +26,7 @@ import { hasOwnSelection } from '../../utils/focus/selection.js';
26
26
  if (contenteditable) {
27
27
  if (!selection.isCollapsed) {
28
28
  var _contenteditable_firstChild;
29
- const focusNode = ((_contenteditable_firstChild = contenteditable.firstChild) === null || _contenteditable_firstChild === undefined ? undefined : _contenteditable_firstChild.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
29
+ const focusNode = ((_contenteditable_firstChild = contenteditable.firstChild) === null || _contenteditable_firstChild === void 0 ? void 0 : _contenteditable_firstChild.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
30
30
  selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
31
31
  }
32
32
  } else {
@@ -1,6 +1,7 @@
1
1
  import { getConfig } from '@testing-library/dom';
2
2
 
3
- function wrapEvent(cb, _element) {
3
+ function wrapEvent(cb, // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
+ _element) {
4
5
  return getConfig().eventWrapper(cb);
5
6
  }
6
7
 
@@ -17,7 +17,7 @@ async function keyboardAction(instance, { keyDef, releasePrevious, releaseSelf,
17
17
  }
18
18
  if (!releasePrevious) {
19
19
  for(let i = 1; i <= repeat; i++){
20
- await system.keyboard.keydown(instance, keyDef);
20
+ await system.keyboard.keydown(instance, keyDef, i > 1);
21
21
  if (i < repeat) {
22
22
  await wait(instance.config);
23
23
  }
@@ -13,18 +13,18 @@ import { readNextDescriptor } from '../utils/keyDef/readNextDescriptor.js';
13
13
  */ function parseKeyDef(keyboardMap, text) {
14
14
  const defs = [];
15
15
  do {
16
- const { type, descriptor, consumedLength, releasePrevious, releaseSelf = true, repeat } = readNextDescriptor(text, 'keyboard');
17
16
  var _keyboardMap_find;
17
+ const { type, descriptor, consumedLength, releasePrevious, releaseSelf = true, repeat } = readNextDescriptor(text, 'keyboard');
18
18
  const keyDef = (_keyboardMap_find = keyboardMap.find((def)=>{
19
19
  if (type === '[') {
20
20
  var _def_code;
21
- return ((_def_code = def.code) === null || _def_code === undefined ? undefined : _def_code.toLowerCase()) === descriptor.toLowerCase();
21
+ return ((_def_code = def.code) === null || _def_code === void 0 ? void 0 : _def_code.toLowerCase()) === descriptor.toLowerCase();
22
22
  } else if (type === '{') {
23
23
  var _def_key;
24
- return ((_def_key = def.key) === null || _def_key === undefined ? undefined : _def_key.toLowerCase()) === descriptor.toLowerCase();
24
+ return ((_def_key = def.key) === null || _def_key === void 0 ? void 0 : _def_key.toLowerCase()) === descriptor.toLowerCase();
25
25
  }
26
26
  return def.key === descriptor;
27
- })) !== null && _keyboardMap_find !== undefined ? _keyboardMap_find : {
27
+ })) !== null && _keyboardMap_find !== void 0 ? _keyboardMap_find : {
28
28
  key: 'Unknown',
29
29
  code: 'Unknown',
30
30
  [type === '[' ? 'code' : 'key']: descriptor
@@ -27,16 +27,16 @@ async function pointer(input) {
27
27
  this.system.pointer.resetClickCount();
28
28
  }
29
29
  async function pointerAction(instance, action) {
30
+ var _action_target, _action_coords, _action_node, _action_offset;
30
31
  var _previousPosition_caret, _previousPosition_caret1;
31
32
  const pointerName = 'pointerName' in action && action.pointerName ? action.pointerName : 'keyDef' in action ? instance.system.pointer.getPointerName(action.keyDef) : 'mouse';
32
33
  const previousPosition = instance.system.pointer.getPreviousPosition(pointerName);
33
- var _action_target, _action_coords, _action_node, _action_offset;
34
34
  const position = {
35
- target: (_action_target = action.target) !== null && _action_target !== undefined ? _action_target : getPrevTarget(instance, previousPosition),
36
- coords: (_action_coords = action.coords) !== null && _action_coords !== undefined ? _action_coords : previousPosition === null || previousPosition === undefined ? undefined : previousPosition.coords,
35
+ target: (_action_target = action.target) !== null && _action_target !== void 0 ? _action_target : getPrevTarget(instance, previousPosition),
36
+ coords: (_action_coords = action.coords) !== null && _action_coords !== void 0 ? _action_coords : previousPosition === null || previousPosition === void 0 ? void 0 : previousPosition.coords,
37
37
  caret: {
38
- node: (_action_node = action.node) !== null && _action_node !== undefined ? _action_node : hasCaretPosition(action) ? undefined : previousPosition === null || previousPosition === undefined ? undefined : (_previousPosition_caret = previousPosition.caret) === null || _previousPosition_caret === undefined ? undefined : _previousPosition_caret.node,
39
- offset: (_action_offset = action.offset) !== null && _action_offset !== undefined ? _action_offset : hasCaretPosition(action) ? undefined : previousPosition === null || previousPosition === undefined ? undefined : (_previousPosition_caret1 = previousPosition.caret) === null || _previousPosition_caret1 === undefined ? undefined : _previousPosition_caret1.offset
38
+ node: (_action_node = action.node) !== null && _action_node !== void 0 ? _action_node : hasCaretPosition(action) ? undefined : previousPosition === null || previousPosition === void 0 ? void 0 : (_previousPosition_caret = previousPosition.caret) === null || _previousPosition_caret === void 0 ? void 0 : _previousPosition_caret.node,
39
+ offset: (_action_offset = action.offset) !== null && _action_offset !== void 0 ? _action_offset : hasCaretPosition(action) ? undefined : previousPosition === null || previousPosition === void 0 ? void 0 : (_previousPosition_caret1 = previousPosition.caret) === null || _previousPosition_caret1 === void 0 ? void 0 : _previousPosition_caret1.offset
40
40
  }
41
41
  };
42
42
  if ('keyDef' in action) {
@@ -58,15 +58,15 @@ async function pointerAction(instance, action) {
58
58
  }
59
59
  }
60
60
  function hasCaretPosition(action) {
61
- var _action_target, _ref;
62
- return !!((_ref = (_action_target = action.target) !== null && _action_target !== undefined ? _action_target : action.node) !== null && _ref !== undefined ? _ref : action.offset !== undefined);
61
+ var _ref, _action_target;
62
+ return !!((_ref = (_action_target = action.target) !== null && _action_target !== void 0 ? _action_target : action.node) !== null && _ref !== void 0 ? _ref : action.offset !== undefined);
63
63
  }
64
64
  function getPrevTarget(instance, position) {
65
+ var _position_target;
65
66
  if (!position) {
66
67
  throw new Error('This pointer has no previous position. Provide a target property!');
67
68
  }
68
- var _position_target;
69
- return (_position_target = position.target) !== null && _position_target !== undefined ? _position_target : instance.config.document.body;
69
+ return (_position_target = position.target) !== null && _position_target !== void 0 ? _position_target : instance.config.document.body;
70
70
  }
71
71
 
72
72
  export { pointer };
@@ -1,5 +1,5 @@
1
- import { click, dblClick, tripleClick } from '../convenience/click.js';
2
- import { hover, unhover } from '../convenience/hover.js';
1
+ import { tripleClick, dblClick, click } from '../convenience/click.js';
2
+ import { unhover, hover } from '../convenience/hover.js';
3
3
  import { tab } from '../convenience/tab.js';
4
4
  import { keyboard } from '../keyboard/index.js';
5
5
  import { copy } from '../clipboard/copy.js';
@@ -7,7 +7,7 @@ import { cut } from '../clipboard/cut.js';
7
7
  import { paste } from '../clipboard/paste.js';
8
8
  import { pointer } from '../pointer/index.js';
9
9
  import { clear } from '../utility/clear.js';
10
- import { deselectOptions, selectOptions } from '../utility/selectOptions.js';
10
+ import { selectOptions, deselectOptions } from '../utility/selectOptions.js';
11
11
  import { type } from '../utility/type.js';
12
12
  import { upload } from '../utility/upload.js';
13
13
 
@@ -1,6 +1,6 @@
1
1
  import { patchFocus } from '../document/patchFocus.js';
2
2
  import { prepareDocument } from '../document/prepareDocument.js';
3
- import { dispatchEvent, dispatchUIEvent } from '../event/dispatchEvent.js';
3
+ import { dispatchUIEvent, dispatchEvent } from '../event/dispatchEvent.js';
4
4
  import { attachClipboardStubToView } from '../utils/dataTransfer/Clipboard.js';
5
5
  import { getWindow } from '../utils/misc/getWindow.js';
6
6
  import { getDocumentFromNode } from '../utils/misc/getDocumentFromNode.js';
@@ -8,8 +8,8 @@ import { setLevelRef, ApiLevel } from '../utils/misc/level.js';
8
8
  import { wait } from '../utils/misc/wait.js';
9
9
  import { PointerEventsCheckLevel } from '../options.js';
10
10
  import '@testing-library/dom';
11
- import { defaultKeyMap } from '../keyboard/keyMap.js';
12
- import { defaultKeyMap as defaultKeyMap$1 } from '../pointer/keyMap.js';
11
+ import { defaultKeyMap as defaultKeyMap$1 } from '../keyboard/keyMap.js';
12
+ import { defaultKeyMap } from '../pointer/keyMap.js';
13
13
  import { System } from '../system/index.js';
14
14
  import { userEventApi } from './api.js';
15
15
  import { wrapAsync } from './wrapAsync.js';
@@ -21,8 +21,8 @@ import { wrapAsync } from './wrapAsync.js';
21
21
  autoModify: true,
22
22
  delay: 0,
23
23
  document: globalThis.document,
24
- keyboardMap: defaultKeyMap,
25
- pointerMap: defaultKeyMap$1,
24
+ keyboardMap: defaultKeyMap$1,
25
+ pointerMap: defaultKeyMap,
26
26
  pointerEventsCheck: PointerEventsCheckLevel.EachApiCall,
27
27
  skipAutoClose: false,
28
28
  skipClick: false,
@@ -48,22 +48,22 @@ function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
48
48
  * Start a "session" with userEvent.
49
49
  * All APIs returned by this function share an input device state and a default configuration.
50
50
  */ function setupMain(options = {}) {
51
+ var _config_document_defaultView;
51
52
  const config = createConfig(options);
52
53
  prepareDocument(config.document);
53
54
  patchFocus(getWindow(config.document).HTMLElement);
54
- var _config_document_defaultView;
55
- const view = (_config_document_defaultView = config.document.defaultView) !== null && _config_document_defaultView !== undefined ? _config_document_defaultView : /* istanbul ignore next */ globalThis.window;
55
+ const view = (_config_document_defaultView = config.document.defaultView) !== null && _config_document_defaultView !== void 0 ? _config_document_defaultView : /* istanbul ignore next */ globalThis.window;
56
56
  attachClipboardStubToView(view);
57
57
  return createInstance(config).api;
58
58
  }
59
59
  /**
60
60
  * Setup in direct call per `userEvent.anyApi()`
61
61
  */ function setupDirect({ keyboardState, pointerState, ...options } = {}, node) {
62
+ var _ref;
62
63
  const config = createConfig(options, defaultOptionsDirect, node);
63
64
  prepareDocument(config.document);
64
65
  patchFocus(getWindow(config.document).HTMLElement);
65
- var _ref;
66
- const system = (_ref = pointerState !== null && pointerState !== undefined ? pointerState : keyboardState) !== null && _ref !== undefined ? _ref : new System();
66
+ const system = (_ref = pointerState !== null && pointerState !== void 0 ? pointerState : keyboardState) !== null && _ref !== void 0 ? _ref : new System();
67
67
  return {
68
68
  api: createInstance(config, system).api,
69
69
  system
@@ -112,8 +112,8 @@ function createInstance(config, system = new System()) {
112
112
  };
113
113
  }
114
114
  function getDocument(options, node, defaults) {
115
- var _options_document, _ref;
116
- return (_ref = (_options_document = options.document) !== null && _options_document !== undefined ? _options_document : node && getDocumentFromNode(node)) !== null && _ref !== undefined ? _ref : defaults.document;
115
+ var _ref, _options_document;
116
+ return (_ref = (_options_document = options.document) !== null && _options_document !== void 0 ? _options_document : node && getDocumentFromNode(node)) !== null && _ref !== void 0 ? _ref : defaults.document;
117
117
  }
118
118
 
119
119
  export { createConfig, createInstance, setupDirect, setupMain, setupSub };
@@ -9,9 +9,7 @@ function _define_property(obj, key, value) {
9
9
  configurable: true,
10
10
  writable: true
11
11
  });
12
- } else {
13
- obj[key] = value;
14
- }
12
+ } else obj[key] = value;
15
13
  return obj;
16
14
  }
17
15
  /**