@testing-library/user-event 14.5.2 → 14.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/dist/cjs/clipboard/copy.js +1 -7
  2. package/dist/cjs/clipboard/cut.js +1 -7
  3. package/dist/cjs/clipboard/paste.js +2 -8
  4. package/dist/cjs/convenience/hover.js +0 -5
  5. package/dist/cjs/document/UI.js +3 -3
  6. package/dist/cjs/document/copySelection.js +0 -6
  7. package/dist/cjs/document/getValueOrTextContent.js +0 -6
  8. package/dist/cjs/document/interceptor.js +5 -11
  9. package/dist/cjs/document/patchFocus.js +104 -0
  10. package/dist/cjs/document/prepareDocument.js +1 -7
  11. package/dist/cjs/document/trackValue.js +2 -8
  12. package/dist/cjs/event/behavior/click.js +3 -9
  13. package/dist/cjs/event/behavior/cut.js +0 -5
  14. package/dist/cjs/event/behavior/keydown.js +5 -10
  15. package/dist/cjs/event/behavior/keypress.js +2 -7
  16. package/dist/cjs/event/behavior/keyup.js +1 -6
  17. package/dist/cjs/event/behavior/paste.js +1 -6
  18. package/dist/cjs/event/createEvent.js +40 -33
  19. package/dist/cjs/event/dispatchEvent.js +1 -1
  20. package/dist/cjs/event/eventMap.js +32 -0
  21. package/dist/cjs/event/focus.js +5 -9
  22. package/dist/cjs/event/index.js +0 -6
  23. package/dist/cjs/event/input.js +2 -7
  24. package/dist/cjs/event/radio.js +1 -6
  25. package/dist/cjs/event/selection/getInputRange.js +1 -1
  26. package/dist/cjs/event/selection/getTargetTypeAndSelection.js +2 -8
  27. package/dist/cjs/event/selection/modifySelection.js +1 -7
  28. package/dist/cjs/event/selection/modifySelectionPerMouse.js +2 -8
  29. package/dist/cjs/event/selection/moveSelection.js +1 -7
  30. package/dist/cjs/event/selection/resolveCaretPosition.js +4 -10
  31. package/dist/cjs/event/selection/selectAll.js +3 -9
  32. package/dist/cjs/event/selection/setSelection.js +1 -7
  33. package/dist/cjs/event/selection/setSelectionPerMouse.js +7 -13
  34. package/dist/cjs/event/selection/setSelectionRange.js +1 -7
  35. package/dist/cjs/event/selection/updateSelectionOnFocus.js +6 -8
  36. package/dist/cjs/index.js +1 -4
  37. package/dist/cjs/keyboard/index.js +0 -6
  38. package/dist/cjs/keyboard/keyMap.js +23 -1
  39. package/dist/cjs/keyboard/parseKeyDef.js +4 -9
  40. package/dist/cjs/options.js +5 -3
  41. package/dist/cjs/pointer/index.js +6 -11
  42. package/dist/cjs/pointer/parseKeyDef.js +0 -5
  43. package/dist/cjs/setup/setup.js +7 -7
  44. package/dist/cjs/system/keyboard.js +47 -25
  45. package/dist/cjs/system/pointer/index.js +45 -50
  46. package/dist/cjs/system/pointer/mouse.js +24 -29
  47. package/dist/cjs/system/pointer/pointer.js +24 -19
  48. package/dist/cjs/system/pointer/shared.js +2 -2
  49. package/dist/cjs/utility/clear.js +0 -5
  50. package/dist/cjs/utility/selectOptions.js +1 -6
  51. package/dist/cjs/utility/type.js +1 -7
  52. package/dist/cjs/utility/upload.js +13 -15
  53. package/dist/cjs/utils/click/isClickableInput.js +3 -3
  54. package/dist/cjs/utils/dataTransfer/Clipboard.js +5 -6
  55. package/dist/cjs/utils/dataTransfer/DataTransfer.js +6 -10
  56. package/dist/cjs/utils/edit/isEditable.js +3 -3
  57. package/dist/cjs/utils/edit/maxLength.js +4 -4
  58. package/dist/cjs/utils/edit/setFiles.js +2 -2
  59. package/dist/cjs/utils/focus/cursor.js +2 -2
  60. package/dist/cjs/utils/focus/getActiveElement.js +2 -2
  61. package/dist/cjs/utils/index.js +1 -4
  62. package/dist/cjs/utils/keyDef/readNextDescriptor.js +6 -6
  63. package/dist/cjs/utils/misc/getWindow.js +1 -1
  64. package/dist/cjs/utils/misc/isDisabled.js +1 -1
  65. package/dist/cjs/utils/misc/isVisible.js +1 -1
  66. package/dist/cjs/utils/misc/level.js +4 -3
  67. package/dist/cjs/utils/pointer/cssPointerEvents.js +11 -11
  68. package/dist/esm/clipboard/copy.js +1 -7
  69. package/dist/esm/clipboard/cut.js +1 -7
  70. package/dist/esm/clipboard/paste.js +2 -8
  71. package/dist/esm/convenience/hover.js +0 -5
  72. package/dist/esm/document/UI.js +3 -3
  73. package/dist/esm/document/copySelection.js +0 -6
  74. package/dist/esm/document/getValueOrTextContent.js +0 -6
  75. package/dist/esm/document/interceptor.js +5 -11
  76. package/dist/esm/document/patchFocus.js +101 -0
  77. package/dist/esm/document/prepareDocument.js +1 -7
  78. package/dist/esm/document/trackValue.js +2 -8
  79. package/dist/esm/event/behavior/click.js +3 -9
  80. package/dist/esm/event/behavior/cut.js +0 -5
  81. package/dist/esm/event/behavior/keydown.js +5 -10
  82. package/dist/esm/event/behavior/keypress.js +2 -7
  83. package/dist/esm/event/behavior/keyup.js +1 -6
  84. package/dist/esm/event/behavior/paste.js +1 -6
  85. package/dist/esm/event/createEvent.js +40 -33
  86. package/dist/esm/event/dispatchEvent.js +1 -1
  87. package/dist/esm/event/eventMap.js +32 -0
  88. package/dist/esm/event/focus.js +5 -9
  89. package/dist/esm/event/index.js +0 -6
  90. package/dist/esm/event/input.js +2 -7
  91. package/dist/esm/event/radio.js +1 -6
  92. package/dist/esm/event/selection/getInputRange.js +1 -1
  93. package/dist/esm/event/selection/getTargetTypeAndSelection.js +2 -8
  94. package/dist/esm/event/selection/modifySelection.js +1 -7
  95. package/dist/esm/event/selection/modifySelectionPerMouse.js +2 -8
  96. package/dist/esm/event/selection/moveSelection.js +1 -7
  97. package/dist/esm/event/selection/resolveCaretPosition.js +4 -10
  98. package/dist/esm/event/selection/selectAll.js +3 -9
  99. package/dist/esm/event/selection/setSelection.js +1 -7
  100. package/dist/esm/event/selection/setSelectionPerMouse.js +7 -13
  101. package/dist/esm/event/selection/setSelectionRange.js +1 -7
  102. package/dist/esm/event/selection/updateSelectionOnFocus.js +6 -8
  103. package/dist/esm/keyboard/index.js +0 -6
  104. package/dist/esm/keyboard/keyMap.js +23 -1
  105. package/dist/esm/keyboard/parseKeyDef.js +4 -9
  106. package/dist/esm/options.js +3 -3
  107. package/dist/esm/pointer/index.js +6 -11
  108. package/dist/esm/pointer/parseKeyDef.js +0 -5
  109. package/dist/esm/setup/setup.js +7 -7
  110. package/dist/esm/system/keyboard.js +46 -25
  111. package/dist/esm/system/pointer/index.js +45 -50
  112. package/dist/esm/system/pointer/mouse.js +24 -29
  113. package/dist/esm/system/pointer/pointer.js +24 -19
  114. package/dist/esm/system/pointer/shared.js +2 -2
  115. package/dist/esm/utility/clear.js +0 -5
  116. package/dist/esm/utility/selectOptions.js +1 -6
  117. package/dist/esm/utility/type.js +1 -7
  118. package/dist/esm/utility/upload.js +13 -15
  119. package/dist/esm/utils/click/isClickableInput.js +3 -3
  120. package/dist/esm/utils/dataTransfer/Clipboard.js +5 -6
  121. package/dist/esm/utils/dataTransfer/DataTransfer.js +6 -10
  122. package/dist/esm/utils/edit/isEditable.js +3 -3
  123. package/dist/esm/utils/edit/maxLength.js +4 -4
  124. package/dist/esm/utils/edit/setFiles.js +2 -2
  125. package/dist/esm/utils/focus/cursor.js +2 -2
  126. package/dist/esm/utils/focus/getActiveElement.js +2 -2
  127. package/dist/esm/utils/keyDef/readNextDescriptor.js +6 -6
  128. package/dist/esm/utils/misc/getWindow.js +1 -1
  129. package/dist/esm/utils/misc/isDisabled.js +1 -1
  130. package/dist/esm/utils/misc/isVisible.js +1 -1
  131. package/dist/esm/utils/misc/level.js +3 -3
  132. package/dist/esm/utils/pointer/cssPointerEvents.js +11 -11
  133. package/dist/types/document/patchFocus.d.ts +9 -0
  134. package/dist/types/event/eventMap.d.ts +32 -0
  135. package/dist/types/event/types.d.ts +1 -1
  136. package/dist/types/keyboard/parseKeyDef.d.ts +1 -1
  137. package/dist/types/options.d.ts +1 -1
  138. package/dist/types/system/keyboard.d.ts +1 -4
  139. package/dist/types/system/pointer/mouse.d.ts +9 -4
  140. package/dist/types/system/pointer/pointer.d.ts +7 -5
  141. package/dist/types/utils/dataTransfer/DataTransfer.d.ts +1 -1
  142. package/package.json +3 -3
@@ -1,11 +1,5 @@
1
- import '../utils/click/isClickableInput.js';
2
1
  import '../utils/dataTransfer/Clipboard.js';
3
- import '../utils/edit/isEditable.js';
4
- import '../utils/edit/maxLength.js';
5
2
  import { getWindow } from '../utils/misc/getWindow.js';
6
- import '../utils/keyDef/readNextDescriptor.js';
7
- import '../utils/misc/level.js';
8
- import '../options.js';
9
3
  import { eventMap } from './eventMap.js';
10
4
 
11
5
  const eventInitializer = {
@@ -13,24 +7,28 @@ const eventInitializer = {
13
7
  initClipboardEvent
14
8
  ],
15
9
  Event: [],
10
+ FocusEvent: [
11
+ initUIEvent,
12
+ initFocusEvent
13
+ ],
16
14
  InputEvent: [
17
15
  initUIEvent,
18
16
  initInputEvent
19
17
  ],
20
18
  MouseEvent: [
21
19
  initUIEvent,
22
- initUIEventModififiers,
20
+ initUIEventModifiers,
23
21
  initMouseEvent
24
22
  ],
25
23
  PointerEvent: [
26
24
  initUIEvent,
27
- initUIEventModififiers,
25
+ initUIEventModifiers,
28
26
  initMouseEvent,
29
27
  initPointerEvent
30
28
  ],
31
29
  KeyboardEvent: [
32
30
  initUIEvent,
33
- initUIEventModififiers,
31
+ initUIEventModifiers,
34
32
  initKeyboardEvent
35
33
  ]
36
34
  };
@@ -38,54 +36,54 @@ function createEvent(type, target, init) {
38
36
  const window = getWindow(target);
39
37
  const { EventType, defaultInit } = eventMap[type];
40
38
  const event = new (getEventConstructors(window))[EventType](type, defaultInit);
41
- eventInitializer[EventType].forEach((f)=>f(event, init !== null && init !== void 0 ? init : {}));
39
+ eventInitializer[EventType].forEach((f)=>f(event, init !== null && init !== undefined ? init : {}));
42
40
  return event;
43
41
  }
44
42
  /* istanbul ignore next */ function getEventConstructors(window) {
45
43
  var _window_Event;
46
- /* eslint-disable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-extraneous-class */ const Event = (_window_Event = window.Event) !== null && _window_Event !== void 0 ? _window_Event : class 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 {
47
45
  };
48
46
  var _window_AnimationEvent;
49
- const AnimationEvent = (_window_AnimationEvent = window.AnimationEvent) !== null && _window_AnimationEvent !== void 0 ? _window_AnimationEvent : class AnimationEvent extends Event {
47
+ const AnimationEvent = (_window_AnimationEvent = window.AnimationEvent) !== null && _window_AnimationEvent !== undefined ? _window_AnimationEvent : class AnimationEvent extends Event {
50
48
  };
51
49
  var _window_ClipboardEvent;
52
- const ClipboardEvent = (_window_ClipboardEvent = window.ClipboardEvent) !== null && _window_ClipboardEvent !== void 0 ? _window_ClipboardEvent : class ClipboardEvent extends Event {
50
+ const ClipboardEvent = (_window_ClipboardEvent = window.ClipboardEvent) !== null && _window_ClipboardEvent !== undefined ? _window_ClipboardEvent : class ClipboardEvent extends Event {
53
51
  };
54
52
  var _window_PopStateEvent;
55
- const PopStateEvent = (_window_PopStateEvent = window.PopStateEvent) !== null && _window_PopStateEvent !== void 0 ? _window_PopStateEvent : class PopStateEvent extends Event {
53
+ const PopStateEvent = (_window_PopStateEvent = window.PopStateEvent) !== null && _window_PopStateEvent !== undefined ? _window_PopStateEvent : class PopStateEvent extends Event {
56
54
  };
57
55
  var _window_ProgressEvent;
58
- const ProgressEvent = (_window_ProgressEvent = window.ProgressEvent) !== null && _window_ProgressEvent !== void 0 ? _window_ProgressEvent : class ProgressEvent extends Event {
56
+ const ProgressEvent = (_window_ProgressEvent = window.ProgressEvent) !== null && _window_ProgressEvent !== undefined ? _window_ProgressEvent : class ProgressEvent extends Event {
59
57
  };
60
58
  var _window_TransitionEvent;
61
- const TransitionEvent = (_window_TransitionEvent = window.TransitionEvent) !== null && _window_TransitionEvent !== void 0 ? _window_TransitionEvent : class TransitionEvent extends Event {
59
+ const TransitionEvent = (_window_TransitionEvent = window.TransitionEvent) !== null && _window_TransitionEvent !== undefined ? _window_TransitionEvent : class TransitionEvent extends Event {
62
60
  };
63
61
  var _window_UIEvent;
64
- const UIEvent = (_window_UIEvent = window.UIEvent) !== null && _window_UIEvent !== void 0 ? _window_UIEvent : class UIEvent extends Event {
62
+ const UIEvent = (_window_UIEvent = window.UIEvent) !== null && _window_UIEvent !== undefined ? _window_UIEvent : class UIEvent extends Event {
65
63
  };
66
64
  var _window_CompositionEvent;
67
- const CompositionEvent = (_window_CompositionEvent = window.CompositionEvent) !== null && _window_CompositionEvent !== void 0 ? _window_CompositionEvent : class CompositionEvent extends UIEvent {
65
+ const CompositionEvent = (_window_CompositionEvent = window.CompositionEvent) !== null && _window_CompositionEvent !== undefined ? _window_CompositionEvent : class CompositionEvent extends UIEvent {
68
66
  };
69
67
  var _window_FocusEvent;
70
- const FocusEvent = (_window_FocusEvent = window.FocusEvent) !== null && _window_FocusEvent !== void 0 ? _window_FocusEvent : class FocusEvent extends UIEvent {
68
+ const FocusEvent = (_window_FocusEvent = window.FocusEvent) !== null && _window_FocusEvent !== undefined ? _window_FocusEvent : class FocusEvent extends UIEvent {
71
69
  };
72
70
  var _window_InputEvent;
73
- const InputEvent = (_window_InputEvent = window.InputEvent) !== null && _window_InputEvent !== void 0 ? _window_InputEvent : class InputEvent extends UIEvent {
71
+ const InputEvent = (_window_InputEvent = window.InputEvent) !== null && _window_InputEvent !== undefined ? _window_InputEvent : class InputEvent extends UIEvent {
74
72
  };
75
73
  var _window_KeyboardEvent;
76
- const KeyboardEvent = (_window_KeyboardEvent = window.KeyboardEvent) !== null && _window_KeyboardEvent !== void 0 ? _window_KeyboardEvent : class KeyboardEvent extends UIEvent {
74
+ const KeyboardEvent = (_window_KeyboardEvent = window.KeyboardEvent) !== null && _window_KeyboardEvent !== undefined ? _window_KeyboardEvent : class KeyboardEvent extends UIEvent {
77
75
  };
78
76
  var _window_MouseEvent;
79
- const MouseEvent = (_window_MouseEvent = window.MouseEvent) !== null && _window_MouseEvent !== void 0 ? _window_MouseEvent : class MouseEvent extends UIEvent {
77
+ const MouseEvent = (_window_MouseEvent = window.MouseEvent) !== null && _window_MouseEvent !== undefined ? _window_MouseEvent : class MouseEvent extends UIEvent {
80
78
  };
81
79
  var _window_DragEvent;
82
- const DragEvent = (_window_DragEvent = window.DragEvent) !== null && _window_DragEvent !== void 0 ? _window_DragEvent : class DragEvent extends MouseEvent {
80
+ const DragEvent = (_window_DragEvent = window.DragEvent) !== null && _window_DragEvent !== undefined ? _window_DragEvent : class DragEvent extends MouseEvent {
83
81
  };
84
82
  var _window_PointerEvent;
85
- const PointerEvent = (_window_PointerEvent = window.PointerEvent) !== null && _window_PointerEvent !== void 0 ? _window_PointerEvent : class PointerEvent extends MouseEvent {
83
+ const PointerEvent = (_window_PointerEvent = window.PointerEvent) !== null && _window_PointerEvent !== undefined ? _window_PointerEvent : class PointerEvent extends MouseEvent {
86
84
  };
87
85
  var _window_TouchEvent;
88
- const TouchEvent = (_window_TouchEvent = window.TouchEvent) !== null && _window_TouchEvent !== void 0 ? _window_TouchEvent : class TouchEvent extends UIEvent {
86
+ const TouchEvent = (_window_TouchEvent = window.TouchEvent) !== null && _window_TouchEvent !== undefined ? _window_TouchEvent : class TouchEvent extends UIEvent {
89
87
  };
90
88
  /* eslint-enable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-extraneous-class */ return {
91
89
  Event,
@@ -108,18 +106,23 @@ function createEvent(type, target, init) {
108
106
  function assignProps(obj, props) {
109
107
  for (const [key, value] of Object.entries(props)){
110
108
  Object.defineProperty(obj, key, {
111
- get: ()=>value !== null && value !== void 0 ? value : null
109
+ get: ()=>value !== null && value !== undefined ? value : null
112
110
  });
113
111
  }
114
112
  }
115
113
  function sanitizeNumber(n) {
116
- return Number(n !== null && n !== void 0 ? n : 0);
114
+ return Number(n !== null && n !== undefined ? n : 0);
117
115
  }
118
116
  function initClipboardEvent(event, { clipboardData }) {
119
117
  assignProps(event, {
120
118
  clipboardData
121
119
  });
122
120
  }
121
+ function initFocusEvent(event, { relatedTarget }) {
122
+ assignProps(event, {
123
+ relatedTarget
124
+ });
125
+ }
123
126
  function initInputEvent(event, { data, inputType, isComposing }) {
124
127
  assignProps(event, {
125
128
  data,
@@ -130,10 +133,10 @@ function initInputEvent(event, { data, inputType, isComposing }) {
130
133
  function initUIEvent(event, { view, detail }) {
131
134
  assignProps(event, {
132
135
  view,
133
- detail: sanitizeNumber(detail !== null && detail !== void 0 ? detail : 0)
136
+ detail: sanitizeNumber(detail !== null && detail !== undefined ? detail : 0)
134
137
  });
135
138
  }
136
- function initUIEventModififiers(event, { altKey, ctrlKey, metaKey, shiftKey, modifierAltGraph, modifierCapsLock, modifierFn, modifierFnLock, modifierNumLock, modifierScrollLock, modifierSymbol, modifierSymbolLock }) {
139
+ function initUIEventModifiers(event, { altKey, ctrlKey, metaKey, shiftKey, modifierAltGraph, modifierCapsLock, modifierFn, modifierFnLock, modifierNumLock, modifierScrollLock, modifierSymbol, modifierSymbolLock }) {
137
140
  assignProps(event, {
138
141
  altKey: Boolean(altKey),
139
142
  ctrlKey: Boolean(ctrlKey),
@@ -167,7 +170,7 @@ function initKeyboardEvent(event, { key, code, location, repeat, isComposing, ch
167
170
  charCode
168
171
  });
169
172
  }
170
- function initMouseEvent(event, { x, y, screenX, screenY, clientX = x, clientY = y, button, buttons, relatedTarget }) {
173
+ function initMouseEvent(event, { x, y, screenX, screenY, clientX = x, clientY = y, button, buttons, relatedTarget, offsetX, offsetY, pageX, pageY }) {
171
174
  assignProps(event, {
172
175
  screenX: sanitizeNumber(screenX),
173
176
  screenY: sanitizeNumber(screenY),
@@ -177,14 +180,18 @@ function initMouseEvent(event, { x, y, screenX, screenY, clientX = x, clientY =
177
180
  y: sanitizeNumber(clientY),
178
181
  button: sanitizeNumber(button),
179
182
  buttons: sanitizeNumber(buttons),
180
- relatedTarget
183
+ relatedTarget,
184
+ offsetX: sanitizeNumber(offsetX),
185
+ offsetY: sanitizeNumber(offsetY),
186
+ pageX: sanitizeNumber(pageX),
187
+ pageY: sanitizeNumber(pageY)
181
188
  });
182
189
  }
183
190
  function initPointerEvent(event, { pointerId, width, height, pressure, tangentialPressure, tiltX, tiltY, twist, pointerType, isPrimary }) {
184
191
  assignProps(event, {
185
192
  pointerId: sanitizeNumber(pointerId),
186
- width: sanitizeNumber(width),
187
- height: sanitizeNumber(height),
193
+ width: sanitizeNumber(width !== null && width !== undefined ? width : 1),
194
+ height: sanitizeNumber(height !== null && height !== undefined ? height : 1),
188
195
  pressure: sanitizeNumber(pressure),
189
196
  tangentialPressure: sanitizeNumber(tangentialPressure),
190
197
  tiltX: sanitizeNumber(tiltX),
@@ -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 === void 0 ? void 0 : _behavior_type.call(behavior, event, target, this);
25
+ const behaviorImplementation = preventDefault ? ()=>{} : (_behavior_type = behavior[type]) === null || _behavior_type === undefined ? undefined : _behavior_type.call(behavior, event, target, this);
26
26
  if (behaviorImplementation) {
27
27
  event.preventDefault();
28
28
  let defaultPrevented = false;
@@ -15,6 +15,14 @@ const eventMap = {
15
15
  composed: true
16
16
  }
17
17
  },
18
+ blur: {
19
+ EventType: 'FocusEvent',
20
+ defaultInit: {
21
+ bubbles: false,
22
+ cancelable: false,
23
+ composed: true
24
+ }
25
+ },
18
26
  click: {
19
27
  EventType: 'PointerEvent',
20
28
  defaultInit: {
@@ -62,6 +70,30 @@ const eventMap = {
62
70
  composed: true
63
71
  }
64
72
  },
73
+ focus: {
74
+ EventType: 'FocusEvent',
75
+ defaultInit: {
76
+ bubbles: false,
77
+ cancelable: false,
78
+ composed: true
79
+ }
80
+ },
81
+ focusin: {
82
+ EventType: 'FocusEvent',
83
+ defaultInit: {
84
+ bubbles: true,
85
+ cancelable: false,
86
+ composed: true
87
+ }
88
+ },
89
+ focusout: {
90
+ EventType: 'FocusEvent',
91
+ defaultInit: {
92
+ bubbles: true,
93
+ cancelable: false,
94
+ composed: true
95
+ }
96
+ },
65
97
  keydown: {
66
98
  EventType: 'KeyboardEvent',
67
99
  defaultInit: {
@@ -1,29 +1,25 @@
1
- import '../utils/click/isClickableInput.js';
2
1
  import '../utils/dataTransfer/Clipboard.js';
3
- import '../utils/edit/isEditable.js';
4
- import '../utils/edit/maxLength.js';
5
2
  import { getActiveElement } from '../utils/focus/getActiveElement.js';
6
3
  import { isFocusable } from '../utils/focus/isFocusable.js';
7
- import '../utils/keyDef/readNextDescriptor.js';
8
4
  import { findClosest } from '../utils/misc/findClosest.js';
9
- import '../utils/misc/level.js';
10
- import '../options.js';
11
5
  import { updateSelectionOnFocus } from './selection/updateSelectionOnFocus.js';
12
6
  import { wrapEvent } from './wrapEvent.js';
13
7
 
8
+ // Browsers do not dispatch FocusEvent if the document does not have focus.
9
+ // TODO: simulate FocusEvent in browsers
14
10
  /**
15
11
  * Focus closest focusable element.
16
12
  */ function focusElement(element) {
17
13
  const target = findClosest(element, isFocusable);
18
14
  const activeElement = getActiveElement(element.ownerDocument);
19
- if ((target !== null && target !== void 0 ? target : element.ownerDocument.body) === activeElement) {
15
+ if ((target !== null && target !== undefined ? target : element.ownerDocument.body) === activeElement) {
20
16
  return;
21
17
  } else if (target) {
22
18
  wrapEvent(()=>target.focus());
23
19
  } else {
24
- wrapEvent(()=>activeElement === null || activeElement === void 0 ? void 0 : activeElement.blur());
20
+ wrapEvent(()=>activeElement === null || activeElement === undefined ? undefined : activeElement.blur());
25
21
  }
26
- updateSelectionOnFocus(target !== null && target !== void 0 ? target : element.ownerDocument.body);
22
+ updateSelectionOnFocus(target !== null && target !== undefined ? target : element.ownerDocument.body);
27
23
  }
28
24
  function blurElement(element) {
29
25
  if (!isFocusable(element)) return;
@@ -1,13 +1,7 @@
1
1
  export { dispatchDOMEvent, dispatchEvent, dispatchUIEvent } from './dispatchEvent.js';
2
2
  export { blurElement, focusElement } from './focus.js';
3
3
  export { input } from './input.js';
4
- import '../utils/click/isClickableInput.js';
5
4
  import '../utils/dataTransfer/Clipboard.js';
6
- import '../utils/edit/isEditable.js';
7
- import '../utils/edit/maxLength.js';
8
- import '../utils/keyDef/readNextDescriptor.js';
9
- import '../utils/misc/level.js';
10
- import '../options.js';
11
5
  export { setSelectionPerMouseDown } from './selection/setSelectionPerMouse.js';
12
6
  export { modifySelectionPerMouseMove } from './selection/modifySelectionPerMouse.js';
13
7
  export { isAllSelected, selectAll } from './selection/selectAll.js';
@@ -1,14 +1,9 @@
1
1
  import { setUIValue, clearInitialValue, getUIValue } from '../document/UI.js';
2
- import '../utils/click/isClickableInput.js';
2
+ import { isElementType } from '../utils/misc/isElementType.js';
3
3
  import '../utils/dataTransfer/Clipboard.js';
4
4
  import { isValidDateOrTimeValue, buildTimeValue } from '../utils/edit/timeValue.js';
5
- import '../utils/edit/isEditable.js';
6
5
  import { supportsMaxLength, getMaxLength } from '../utils/edit/maxLength.js';
7
6
  import { getNextCursorPosition } from '../utils/focus/cursor.js';
8
- import { isElementType } from '../utils/misc/isElementType.js';
9
- import '../utils/keyDef/readNextDescriptor.js';
10
- import '../utils/misc/level.js';
11
- import '../options.js';
12
7
  import { commitValueAfterInput } from '../document/trackValue.js';
13
8
  import { getInputRange } from './selection/getInputRange.js';
14
9
  import { setSelection } from './selection/setSelection.js';
@@ -154,7 +149,7 @@ function isValidNumberInput(value) {
154
149
  // it allows up to two '-' at any place before any 'e' or one directly following 'e'
155
150
  // it allows one '.' at any place before e
156
151
  const valueParts = value.split('e', 2);
157
- 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]));
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]));
158
153
  }
159
154
 
160
155
  export { input };
@@ -1,12 +1,6 @@
1
- import '../utils/click/isClickableInput.js';
2
1
  import '../utils/dataTransfer/Clipboard.js';
3
- import '../utils/edit/isEditable.js';
4
- import '../utils/edit/maxLength.js';
5
2
  import { isDisabled } from '../utils/misc/isDisabled.js';
6
3
  import { getWindow } from '../utils/misc/getWindow.js';
7
- import '../utils/keyDef/readNextDescriptor.js';
8
- import '../utils/misc/level.js';
9
- import '../options.js';
10
4
  import { focusElement } from './focus.js';
11
5
 
12
6
  function walkRadio(instance, el, direction) {
@@ -24,6 +18,7 @@ function walkRadio(instance, el, direction) {
24
18
  }
25
19
  focusElement(group[i]);
26
20
  instance.dispatchUIEvent(group[i], 'click');
21
+ return;
27
22
  }
28
23
  }
29
24
 
@@ -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 === void 0 ? void 0 : _typeAndSelection_selection.getRangeAt(0);
12
+ return (_typeAndSelection_selection = typeAndSelection.selection) === null || _typeAndSelection_selection === undefined ? undefined : _typeAndSelection_selection.getRangeAt(0);
13
13
  }
14
14
  }
15
15
 
@@ -1,13 +1,7 @@
1
1
  import { getUISelection } from '../../document/UI.js';
2
- import '../../utils/click/isClickableInput.js';
3
2
  import '../../utils/dataTransfer/Clipboard.js';
4
3
  import { getContentEditable } from '../../utils/edit/isContentEditable.js';
5
- import '../../utils/edit/isEditable.js';
6
- import '../../utils/edit/maxLength.js';
7
4
  import { hasOwnSelection } from '../../utils/focus/selection.js';
8
- import '../../utils/keyDef/readNextDescriptor.js';
9
- import '../../utils/misc/level.js';
10
- import '../../options.js';
11
5
 
12
6
  /**
13
7
  * Determine which selection logic and selection ranges to consider.
@@ -19,10 +13,10 @@ import '../../options.js';
19
13
  selection: getUISelection(element)
20
14
  };
21
15
  }
22
- const selection = element === null || element === void 0 ? void 0 : element.ownerDocument.getSelection();
16
+ const selection = element === null || element === undefined ? undefined : element.ownerDocument.getSelection();
23
17
  // It is possible to extend a single-range selection into a contenteditable.
24
18
  // This results in the range acting like a range outside of contenteditable.
25
- const isCE = getContentEditable(node) && (selection === null || selection === void 0 ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode);
19
+ const isCE = getContentEditable(node) && (selection === null || selection === undefined ? undefined : selection.anchorNode) && getContentEditable(selection.anchorNode);
26
20
  return {
27
21
  type: isCE ? 'contenteditable' : 'default',
28
22
  selection
@@ -1,11 +1,5 @@
1
1
  import { setUISelection } from '../../document/UI.js';
2
- import '../../utils/click/isClickableInput.js';
3
2
  import '../../utils/dataTransfer/Clipboard.js';
4
- import '../../utils/edit/isEditable.js';
5
- import '../../utils/edit/maxLength.js';
6
- import '../../utils/keyDef/readNextDescriptor.js';
7
- import '../../utils/misc/level.js';
8
- import '../../options.js';
9
3
  import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
10
4
 
11
5
  /**
@@ -19,7 +13,7 @@ import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
19
13
  focusOffset
20
14
  }, 'modify');
21
15
  }
22
- (_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);
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);
23
17
  }
24
18
 
25
19
  export { modifySelection };
@@ -1,11 +1,5 @@
1
1
  import { setUISelection } from '../../document/UI.js';
2
- import '../../utils/click/isClickableInput.js';
3
2
  import '../../utils/dataTransfer/Clipboard.js';
4
- import '../../utils/edit/isEditable.js';
5
- import '../../utils/edit/maxLength.js';
6
- import '../../utils/keyDef/readNextDescriptor.js';
7
- import '../../utils/misc/level.js';
8
- import '../../options.js';
9
3
  import { resolveCaretPosition } from './resolveCaretPosition.js';
10
4
 
11
5
  function modifySelectionPerMouseMove(selectionRange, { document, target, node, offset }) {
@@ -36,8 +30,8 @@ function modifySelectionPerMouseMove(selectionRange, { document, target, node, o
36
30
  range.setEnd(selectionFocus.node, selectionFocus.offset);
37
31
  }
38
32
  const selection = document.getSelection();
39
- selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
40
- selection === null || selection === void 0 ? void 0 : selection.addRange(range.cloneRange());
33
+ selection === null || selection === undefined ? undefined : selection.removeAllRanges();
34
+ selection === null || selection === undefined ? undefined : selection.addRange(range.cloneRange());
41
35
  }
42
36
  }
43
37
 
@@ -1,13 +1,7 @@
1
1
  import { getUISelection } from '../../document/UI.js';
2
- import '../../utils/click/isClickableInput.js';
3
2
  import '../../utils/dataTransfer/Clipboard.js';
4
- import '../../utils/edit/isEditable.js';
5
- import '../../utils/edit/maxLength.js';
6
3
  import { getNextCursorPosition } from '../../utils/focus/cursor.js';
7
4
  import { hasOwnSelection } from '../../utils/focus/selection.js';
8
- import '../../utils/keyDef/readNextDescriptor.js';
9
- import '../../utils/misc/level.js';
10
- import '../../options.js';
11
5
  import { setSelection } from './setSelection.js';
12
6
 
13
7
  /**
@@ -22,7 +16,7 @@ import { setSelection } from './setSelection.js';
22
16
  });
23
17
  } else {
24
18
  const selection = node.ownerDocument.getSelection();
25
- if (!(selection === null || selection === void 0 ? void 0 : selection.focusNode)) {
19
+ if (!(selection === null || selection === undefined ? undefined : selection.focusNode)) {
26
20
  return;
27
21
  }
28
22
  if (selection.isCollapsed) {
@@ -1,23 +1,17 @@
1
1
  import { getUIValue } from '../../document/UI.js';
2
- import '../../utils/click/isClickableInput.js';
3
2
  import '../../utils/dataTransfer/Clipboard.js';
4
- import '../../utils/edit/isEditable.js';
5
- import '../../utils/edit/maxLength.js';
6
3
  import { hasOwnSelection } from '../../utils/focus/selection.js';
7
- import '../../utils/keyDef/readNextDescriptor.js';
8
- import '../../utils/misc/level.js';
9
- import '../../options.js';
10
4
 
11
5
  function resolveCaretPosition({ target, node, offset }) {
12
6
  if (hasOwnSelection(target)) {
13
7
  return {
14
8
  node: target,
15
- offset: offset !== null && offset !== void 0 ? offset : getUIValue(target).length
9
+ offset: offset !== null && offset !== undefined ? offset : getUIValue(target).length
16
10
  };
17
11
  } else if (node) {
18
12
  return {
19
13
  node,
20
- offset: offset !== null && offset !== void 0 ? offset : node.nodeType === 3 ? node.nodeValue.length : node.childNodes.length
14
+ offset: offset !== null && offset !== undefined ? offset : node.nodeType === 3 ? node.nodeValue.length : node.childNodes.length
21
15
  };
22
16
  }
23
17
  return findNodeAtTextOffset(target, offset);
@@ -30,7 +24,7 @@ function findNodeAtTextOffset(node, offset, isRoot = true) {
30
24
  // the browser moves the cursor to the last non-empty text node inside this element.
31
25
  // 3. Otherwise the cursor is moved to the end of the target.
32
26
  let i = offset === undefined ? node.childNodes.length - 1 : 0;
33
- const step = offset === undefined ? -1 : +1;
27
+ const step = offset === undefined ? -1 : 1;
34
28
  while(offset === undefined ? i >= (isRoot ? Math.max(node.childNodes.length - 1, 0) : 0) : i <= node.childNodes.length){
35
29
  if (offset && i === node.childNodes.length) {
36
30
  throw new Error('The given offset is out of bounds.');
@@ -49,7 +43,7 @@ function findNodeAtTextOffset(node, offset, isRoot = true) {
49
43
  if (c.nodeType === 3) {
50
44
  return {
51
45
  node: c,
52
- offset: offset !== null && offset !== void 0 ? offset : c.nodeValue.length
46
+ offset: offset !== null && offset !== undefined ? offset : c.nodeValue.length
53
47
  };
54
48
  }
55
49
  }
@@ -1,13 +1,7 @@
1
1
  import { getUIValue, getUISelection } from '../../document/UI.js';
2
- import '../../utils/click/isClickableInput.js';
3
2
  import '../../utils/dataTransfer/Clipboard.js';
4
3
  import { getContentEditable } from '../../utils/edit/isContentEditable.js';
5
- import '../../utils/edit/isEditable.js';
6
- import '../../utils/edit/maxLength.js';
7
4
  import { hasOwnSelection } from '../../utils/focus/selection.js';
8
- import '../../utils/keyDef/readNextDescriptor.js';
9
- import '../../utils/misc/level.js';
10
- import '../../options.js';
11
5
  import { setSelection } from './setSelection.js';
12
6
 
13
7
  /**
@@ -21,7 +15,7 @@ import { setSelection } from './setSelection.js';
21
15
  });
22
16
  }
23
17
  var _getContentEditable;
24
- const focusNode = (_getContentEditable = getContentEditable(target)) !== null && _getContentEditable !== void 0 ? _getContentEditable : target.ownerDocument.body;
18
+ const focusNode = (_getContentEditable = getContentEditable(target)) !== null && _getContentEditable !== undefined ? _getContentEditable : target.ownerDocument.body;
25
19
  setSelection({
26
20
  focusNode,
27
21
  anchorOffset: 0,
@@ -33,9 +27,9 @@ function isAllSelected(target) {
33
27
  return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
34
28
  }
35
29
  var _getContentEditable;
36
- const focusNode = (_getContentEditable = getContentEditable(target)) !== null && _getContentEditable !== void 0 ? _getContentEditable : target.ownerDocument.body;
30
+ const focusNode = (_getContentEditable = getContentEditable(target)) !== null && _getContentEditable !== undefined ? _getContentEditable : target.ownerDocument.body;
37
31
  const selection = target.ownerDocument.getSelection();
38
- return (selection === null || selection === void 0 ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
32
+ return (selection === null || selection === undefined ? undefined : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
39
33
  }
40
34
 
41
35
  export { isAllSelected, selectAll };
@@ -1,11 +1,5 @@
1
1
  import { setUISelection } from '../../document/UI.js';
2
- import '../../utils/click/isClickableInput.js';
3
2
  import '../../utils/dataTransfer/Clipboard.js';
4
- import '../../utils/edit/isEditable.js';
5
- import '../../utils/edit/maxLength.js';
6
- import '../../utils/keyDef/readNextDescriptor.js';
7
- import '../../utils/misc/level.js';
8
- import '../../options.js';
9
3
  import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
10
4
 
11
5
  /**
@@ -19,7 +13,7 @@ import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
19
13
  focusOffset
20
14
  });
21
15
  }
22
- (_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);
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);
23
17
  }
24
18
 
25
19
  export { setSelection };
@@ -1,12 +1,6 @@
1
1
  import { getUIValue, setUISelection } from '../../document/UI.js';
2
- import '../../utils/click/isClickableInput.js';
3
2
  import '../../utils/dataTransfer/Clipboard.js';
4
- import '../../utils/edit/isEditable.js';
5
- import '../../utils/edit/maxLength.js';
6
3
  import { hasNoSelection, hasOwnSelection } from '../../utils/focus/selection.js';
7
- import '../../utils/keyDef/readNextDescriptor.js';
8
- import '../../utils/misc/level.js';
9
- import '../../options.js';
10
4
  import { resolveCaretPosition } from './resolveCaretPosition.js';
11
5
 
12
6
  function setSelectionPerMouseDown({ document, target, clickCount, node, offset }) {
@@ -29,13 +23,13 @@ function setSelectionPerMouseDown({ document, target, clickCount, node, offset }
29
23
  // TODO: implement modifying selection per shift/ctrl+mouse
30
24
  if (targetHasOwnSelection) {
31
25
  setUISelection(target, {
32
- anchorOffset: start !== null && start !== void 0 ? start : text.length,
33
- focusOffset: end !== null && end !== void 0 ? end : text.length
26
+ anchorOffset: start !== null && start !== undefined ? start : text.length,
27
+ focusOffset: end !== null && end !== undefined ? end : text.length
34
28
  });
35
29
  return {
36
30
  node: target,
37
- start: start !== null && start !== void 0 ? start : 0,
38
- end: end !== null && end !== void 0 ? end : text.length
31
+ start: start !== null && start !== undefined ? start : 0,
32
+ end: end !== null && end !== undefined ? end : text.length
39
33
  };
40
34
  } else {
41
35
  const { node: startNode, offset: startOffset } = resolveCaretPosition({
@@ -56,8 +50,8 @@ function setSelectionPerMouseDown({ document, target, clickCount, node, offset }
56
50
  throw new Error('The given offset is out of bounds.');
57
51
  }
58
52
  const selection = document.getSelection();
59
- selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
60
- selection === null || selection === void 0 ? void 0 : selection.addRange(range.cloneRange());
53
+ selection === null || selection === undefined ? undefined : selection.removeAllRanges();
54
+ selection === null || selection === undefined ? undefined : selection.addRange(range.cloneRange());
61
55
  return range;
62
56
  }
63
57
  }
@@ -68,7 +62,7 @@ function getTextRange(text, pos, clickCount) {
68
62
  pos
69
63
  ];
70
64
  }
71
- const textPos = pos !== null && pos !== void 0 ? pos : text.length;
65
+ const textPos = pos !== null && pos !== undefined ? pos : text.length;
72
66
  if (clickCount % 3 === 2) {
73
67
  return [
74
68
  textPos - text.substr(0, pos).match(/(\w+|\s+|\W)?$/)[0].length,
@@ -1,12 +1,6 @@
1
- import '../../utils/click/isClickableInput.js';
2
1
  import '../../utils/dataTransfer/Clipboard.js';
3
2
  import { isContentEditable } from '../../utils/edit/isContentEditable.js';
4
- import '../../utils/edit/isEditable.js';
5
- import '../../utils/edit/maxLength.js';
6
3
  import { hasOwnSelection } from '../../utils/focus/selection.js';
7
- import '../../utils/keyDef/readNextDescriptor.js';
8
- import '../../utils/misc/level.js';
9
- import '../../options.js';
10
4
  import { setSelection } from './setSelection.js';
11
5
 
12
6
  /**
@@ -22,7 +16,7 @@ import { setSelection } from './setSelection.js';
22
16
  focusOffset
23
17
  });
24
18
  }
25
- /* istanbul ignore else */ if (isContentEditable(element) && ((_element_firstChild = element.firstChild) === null || _element_firstChild === void 0 ? void 0 : _element_firstChild.nodeType) === 3) {
19
+ /* istanbul ignore else */ if (isContentEditable(element) && ((_element_firstChild = element.firstChild) === null || _element_firstChild === undefined ? undefined : _element_firstChild.nodeType) === 3) {
26
20
  return setSelection({
27
21
  focusNode: element.firstChild,
28
22
  anchorOffset,