@testing-library/user-event 14.4.2 → 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 (276) 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 +6 -16
  5. package/dist/cjs/clipboard/cut.js +6 -16
  6. package/dist/cjs/clipboard/paste.js +6 -16
  7. package/dist/cjs/convenience/click.js +1 -4
  8. package/dist/cjs/convenience/hover.js +2 -12
  9. package/dist/cjs/convenience/tab.js +1 -1
  10. package/dist/cjs/document/UI.js +94 -0
  11. package/dist/cjs/document/copySelection.js +37 -0
  12. package/dist/cjs/document/getValueOrTextContent.js +27 -0
  13. package/dist/cjs/document/index.js +13 -68
  14. package/dist/cjs/document/interceptor.js +89 -4
  15. package/dist/cjs/document/prepareDocument.js +67 -0
  16. package/dist/cjs/document/trackValue.js +65 -0
  17. package/dist/cjs/event/behavior/click.js +8 -12
  18. package/dist/cjs/event/behavior/cut.js +5 -11
  19. package/dist/cjs/event/behavior/keydown.js +43 -47
  20. package/dist/cjs/event/behavior/keypress.js +12 -12
  21. package/dist/cjs/event/behavior/keyup.js +6 -8
  22. package/dist/cjs/event/behavior/paste.js +7 -13
  23. package/dist/cjs/event/createEvent.js +43 -50
  24. package/dist/cjs/event/dispatchEvent.js +21 -3
  25. package/dist/cjs/event/eventMap.js +2 -2
  26. package/dist/cjs/event/focus.js +44 -0
  27. package/dist/cjs/event/index.js +24 -17
  28. package/dist/cjs/{utils/edit → event}/input.js +52 -50
  29. package/dist/cjs/{utils/edit/walkRadio.js → event/radio.js} +13 -7
  30. package/dist/cjs/event/selection/getInputRange.js +20 -0
  31. package/dist/cjs/event/selection/getTargetTypeAndSelection.js +41 -0
  32. package/dist/cjs/event/selection/index.js +26 -0
  33. package/dist/cjs/event/selection/modifySelection.js +30 -0
  34. package/dist/cjs/event/selection/modifySelectionPerMouse.js +50 -0
  35. package/dist/cjs/event/selection/moveSelection.js +48 -0
  36. package/dist/cjs/{utils/focus → event/selection}/resolveCaretPosition.js +10 -18
  37. package/dist/cjs/event/selection/selectAll.js +48 -0
  38. package/dist/cjs/event/selection/setSelection.js +30 -0
  39. package/dist/cjs/event/selection/setSelectionPerMouse.js +91 -0
  40. package/dist/cjs/event/selection/setSelectionRange.js +40 -0
  41. package/dist/cjs/event/selection/updateSelectionOnFocus.js +46 -0
  42. package/dist/cjs/event/wrapEvent.js +3 -2
  43. package/dist/cjs/index.js +1 -0
  44. package/dist/cjs/keyboard/index.js +13 -23
  45. package/dist/cjs/keyboard/parseKeyDef.js +9 -17
  46. package/dist/cjs/options.js +0 -28
  47. package/dist/cjs/pointer/index.js +28 -38
  48. package/dist/cjs/pointer/keyMap.js +1 -1
  49. package/dist/cjs/pointer/parseKeyDef.js +2 -10
  50. package/dist/cjs/setup/api.js +19 -17
  51. package/dist/cjs/setup/directApi.js +6 -6
  52. package/dist/cjs/setup/index.js +0 -2
  53. package/dist/cjs/setup/setup.js +70 -42
  54. package/dist/cjs/setup/wrapAsync.js +3 -2
  55. package/dist/cjs/system/index.js +15 -2
  56. package/dist/cjs/system/keyboard.js +34 -21
  57. package/dist/cjs/system/pointer/buttons.js +14 -1
  58. package/dist/cjs/system/pointer/device.js +14 -1
  59. package/dist/cjs/system/pointer/index.js +60 -45
  60. package/dist/cjs/system/pointer/mouse.js +77 -56
  61. package/dist/cjs/system/pointer/pointer.js +56 -42
  62. package/dist/cjs/system/pointer/shared.js +10 -0
  63. package/dist/cjs/utility/clear.js +10 -11
  64. package/dist/cjs/utility/selectOptions.js +28 -29
  65. package/dist/cjs/utility/type.js +6 -15
  66. package/dist/cjs/utility/upload.js +9 -18
  67. package/dist/cjs/utils/dataTransfer/Clipboard.js +26 -24
  68. package/dist/cjs/utils/dataTransfer/DataTransfer.js +25 -9
  69. package/dist/cjs/utils/edit/isEditable.js +6 -10
  70. package/dist/cjs/utils/edit/maxLength.js +6 -17
  71. package/dist/cjs/utils/edit/setFiles.js +4 -4
  72. package/dist/cjs/utils/edit/{buildTimeValue.js → timeValue.js} +6 -0
  73. package/dist/cjs/utils/focus/cursor.js +2 -18
  74. package/dist/cjs/utils/focus/getActiveElement.js +4 -3
  75. package/dist/cjs/utils/focus/selection.js +1 -271
  76. package/dist/cjs/utils/focus/selector.js +1 -1
  77. package/dist/cjs/utils/index.js +7 -32
  78. package/dist/cjs/utils/keyDef/readNextDescriptor.js +5 -5
  79. package/dist/cjs/utils/misc/getTreeDiff.js +3 -3
  80. package/dist/cjs/utils/misc/getWindow.js +3 -2
  81. package/dist/cjs/utils/misc/isDisabled.js +3 -3
  82. package/dist/cjs/utils/misc/isVisible.js +3 -2
  83. package/dist/cjs/utils/misc/level.js +4 -9
  84. package/dist/cjs/utils/misc/wait.js +1 -1
  85. package/dist/cjs/utils/pointer/cssPointerEvents.js +31 -40
  86. package/dist/esm/_interop/dtl.js +6 -0
  87. package/dist/esm/_interop/dtlEventMap.js +6 -0
  88. package/dist/esm/_interop/dtlHelpers.js +6 -0
  89. package/dist/esm/clipboard/copy.js +6 -16
  90. package/dist/esm/clipboard/cut.js +6 -16
  91. package/dist/esm/clipboard/paste.js +6 -16
  92. package/dist/esm/convenience/click.js +1 -4
  93. package/dist/esm/convenience/hover.js +2 -12
  94. package/dist/esm/convenience/tab.js +1 -1
  95. package/dist/esm/document/UI.js +79 -0
  96. package/dist/esm/document/copySelection.js +33 -0
  97. package/dist/esm/document/getValueOrTextContent.js +23 -0
  98. package/dist/esm/document/index.js +4 -66
  99. package/dist/esm/document/interceptor.js +87 -5
  100. package/dist/esm/document/prepareDocument.js +63 -0
  101. package/dist/esm/document/trackValue.js +59 -0
  102. package/dist/esm/event/behavior/click.js +8 -12
  103. package/dist/esm/event/behavior/cut.js +5 -11
  104. package/dist/esm/event/behavior/keydown.js +36 -40
  105. package/dist/esm/event/behavior/keypress.js +12 -12
  106. package/dist/esm/event/behavior/keyup.js +6 -8
  107. package/dist/esm/event/behavior/paste.js +7 -13
  108. package/dist/esm/event/createEvent.js +43 -50
  109. package/dist/esm/event/dispatchEvent.js +20 -4
  110. package/dist/esm/event/eventMap.js +2 -2
  111. package/dist/esm/event/focus.js +39 -0
  112. package/dist/esm/event/index.js +14 -19
  113. package/dist/esm/{utils/edit → event}/input.js +39 -37
  114. package/dist/esm/{utils/edit/walkRadio.js → event/radio.js} +13 -7
  115. package/dist/esm/event/selection/getInputRange.js +16 -0
  116. package/dist/esm/event/selection/getTargetTypeAndSelection.js +37 -0
  117. package/dist/esm/event/selection/index.js +9 -0
  118. package/dist/esm/event/selection/modifySelection.js +26 -0
  119. package/dist/esm/event/selection/modifySelectionPerMouse.js +46 -0
  120. package/dist/esm/event/selection/moveSelection.js +44 -0
  121. package/dist/esm/{utils/focus → event/selection}/resolveCaretPosition.js +9 -17
  122. package/dist/esm/event/selection/selectAll.js +43 -0
  123. package/dist/esm/event/selection/setSelection.js +26 -0
  124. package/dist/esm/event/selection/setSelectionPerMouse.js +87 -0
  125. package/dist/esm/event/selection/setSelectionRange.js +36 -0
  126. package/dist/esm/event/selection/updateSelectionOnFocus.js +42 -0
  127. package/dist/esm/event/wrapEvent.js +2 -1
  128. package/dist/esm/index.js +1 -1
  129. package/dist/esm/keyboard/index.js +13 -23
  130. package/dist/esm/keyboard/parseKeyDef.js +9 -17
  131. package/dist/esm/options.js +1 -26
  132. package/dist/esm/pointer/index.js +28 -38
  133. package/dist/esm/pointer/keyMap.js +1 -1
  134. package/dist/esm/pointer/parseKeyDef.js +2 -10
  135. package/dist/esm/setup/api.js +33 -12
  136. package/dist/esm/setup/directApi.js +6 -6
  137. package/dist/esm/setup/index.js +0 -1
  138. package/dist/esm/setup/setup.js +66 -39
  139. package/dist/esm/setup/wrapAsync.js +2 -1
  140. package/dist/esm/system/index.js +15 -2
  141. package/dist/esm/system/keyboard.js +34 -21
  142. package/dist/esm/system/pointer/buttons.js +14 -1
  143. package/dist/esm/system/pointer/device.js +14 -1
  144. package/dist/esm/system/pointer/index.js +61 -45
  145. package/dist/esm/system/pointer/mouse.js +74 -53
  146. package/dist/esm/system/pointer/pointer.js +55 -41
  147. package/dist/esm/system/pointer/shared.js +6 -0
  148. package/dist/esm/utility/clear.js +10 -11
  149. package/dist/esm/utility/selectOptions.js +24 -25
  150. package/dist/esm/utility/type.js +5 -14
  151. package/dist/esm/utility/upload.js +9 -18
  152. package/dist/esm/utils/dataTransfer/Clipboard.js +26 -24
  153. package/dist/esm/utils/dataTransfer/DataTransfer.js +25 -9
  154. package/dist/esm/utils/edit/isEditable.js +4 -8
  155. package/dist/esm/utils/edit/maxLength.js +5 -17
  156. package/dist/esm/utils/edit/setFiles.js +4 -4
  157. package/dist/esm/utils/edit/{buildTimeValue.js → timeValue.js} +6 -1
  158. package/dist/esm/utils/focus/cursor.js +2 -18
  159. package/dist/esm/utils/focus/getActiveElement.js +4 -3
  160. package/dist/esm/utils/focus/selection.js +3 -265
  161. package/dist/esm/utils/focus/selector.js +1 -1
  162. package/dist/esm/utils/index.js +4 -11
  163. package/dist/esm/utils/keyDef/readNextDescriptor.js +5 -5
  164. package/dist/esm/utils/misc/getTreeDiff.js +3 -3
  165. package/dist/esm/utils/misc/getWindow.js +2 -1
  166. package/dist/esm/utils/misc/isDisabled.js +3 -3
  167. package/dist/esm/utils/misc/isVisible.js +3 -2
  168. package/dist/esm/utils/misc/level.js +4 -9
  169. package/dist/esm/utils/misc/wait.js +1 -1
  170. package/dist/esm/utils/pointer/cssPointerEvents.js +31 -40
  171. package/dist/types/_interop/dtl.d.ts +3 -0
  172. package/dist/types/_interop/dtlEventMap.d.ts +3 -0
  173. package/dist/types/_interop/dtlHelpers.d.ts +3 -0
  174. package/dist/types/clipboard/copy.d.ts +1 -1
  175. package/dist/types/clipboard/cut.d.ts +1 -1
  176. package/dist/types/clipboard/paste.d.ts +1 -1
  177. package/dist/types/convenience/click.d.ts +1 -1
  178. package/dist/types/convenience/hover.d.ts +1 -1
  179. package/dist/types/convenience/tab.d.ts +1 -1
  180. package/dist/types/document/UI.d.ts +42 -0
  181. package/dist/types/document/getValueOrTextContent.d.ts +1 -0
  182. package/dist/types/document/index.d.ts +5 -10
  183. package/dist/types/document/interceptor.d.ts +6 -3
  184. package/dist/types/document/prepareDocument.d.ts +8 -0
  185. package/dist/types/document/trackValue.d.ts +17 -0
  186. package/dist/types/event/behavior/registry.d.ts +2 -2
  187. package/dist/types/event/createEvent.d.ts +1 -1
  188. package/dist/types/event/dispatchEvent.d.ts +5 -2
  189. package/dist/types/event/eventMap.d.ts +8 -0
  190. package/dist/types/event/focus.d.ts +5 -0
  191. package/dist/types/event/index.d.ts +6 -4
  192. package/dist/types/event/input.d.ts +2 -0
  193. package/dist/types/event/radio.d.ts +4 -0
  194. package/dist/types/event/selection/getInputRange.d.ts +5 -0
  195. package/dist/types/event/selection/getTargetTypeAndSelection.d.ts +10 -0
  196. package/dist/types/event/selection/index.d.ts +15 -0
  197. package/dist/types/event/selection/modifySelection.d.ts +8 -0
  198. package/dist/types/event/selection/modifySelectionPerMouse.d.ts +7 -0
  199. package/dist/types/event/selection/moveSelection.d.ts +4 -0
  200. package/dist/types/event/selection/setSelection.d.ts +10 -0
  201. package/dist/types/event/selection/setSelectionPerMouse.d.ts +8 -0
  202. package/dist/types/event/selection/setSelectionRange.d.ts +6 -0
  203. package/dist/types/event/selection/updateSelectionOnFocus.d.ts +5 -0
  204. package/dist/types/event/types.d.ts +3 -3
  205. package/dist/types/index.d.ts +3 -1
  206. package/dist/types/keyboard/index.d.ts +2 -2
  207. package/dist/types/options.d.ts +2 -10
  208. package/dist/types/pointer/index.d.ts +7 -7
  209. package/dist/types/setup/api.d.ts +23 -5
  210. package/dist/types/setup/directApi.d.ts +5 -5
  211. package/dist/types/setup/index.d.ts +2 -15
  212. package/dist/types/setup/setup.d.ts +25 -7
  213. package/dist/types/system/keyboard.d.ts +4 -4
  214. package/dist/types/system/pointer/buttons.d.ts +2 -2
  215. package/dist/types/system/pointer/device.d.ts +1 -1
  216. package/dist/types/system/pointer/index.d.ts +7 -25
  217. package/dist/types/system/pointer/mouse.d.ts +6 -6
  218. package/dist/types/system/pointer/pointer.d.ts +8 -8
  219. package/dist/types/system/pointer/shared.d.ts +20 -0
  220. package/dist/types/utility/clear.d.ts +1 -1
  221. package/dist/types/utility/selectOptions.d.ts +1 -1
  222. package/dist/types/utility/type.d.ts +4 -4
  223. package/dist/types/utility/upload.d.ts +1 -1
  224. package/dist/types/utils/click/isClickableInput.d.ts +2 -2
  225. package/dist/types/utils/dataTransfer/Clipboard.d.ts +1 -1
  226. package/dist/types/utils/edit/isEditable.d.ts +6 -7
  227. package/dist/types/utils/edit/maxLength.d.ts +14 -1
  228. package/dist/types/utils/edit/{isValidDateOrTimeValue.d.ts → timeValue.d.ts} +1 -0
  229. package/dist/types/utils/focus/selection.d.ts +4 -69
  230. package/dist/types/utils/index.d.ts +2 -9
  231. package/dist/types/utils/keyDef/readNextDescriptor.d.ts +1 -1
  232. package/dist/types/utils/misc/isElementType.d.ts +1 -1
  233. package/dist/types/utils/misc/level.d.ts +4 -13
  234. package/dist/types/utils/misc/wait.d.ts +2 -2
  235. package/dist/types/utils/pointer/cssPointerEvents.d.ts +4 -4
  236. package/package.json +24 -12
  237. package/dist/cjs/document/selection.js +0 -108
  238. package/dist/cjs/document/setRangeText.js +0 -21
  239. package/dist/cjs/document/value.js +0 -127
  240. package/dist/cjs/setup/config.js +0 -7
  241. package/dist/cjs/utils/edit/getValue.js +0 -35
  242. package/dist/cjs/utils/edit/isValidDateOrTimeValue.js +0 -11
  243. package/dist/cjs/utils/focus/blur.js +0 -16
  244. package/dist/cjs/utils/focus/copySelection.js +0 -46
  245. package/dist/cjs/utils/focus/focus.js +0 -29
  246. package/dist/cjs/utils/focus/selectAll.js +0 -56
  247. package/dist/cjs/utils/misc/eventWrapper.js +0 -15
  248. package/dist/esm/document/selection.js +0 -100
  249. package/dist/esm/document/setRangeText.js +0 -17
  250. package/dist/esm/document/value.js +0 -117
  251. package/dist/esm/setup/config.js +0 -3
  252. package/dist/esm/utils/edit/getValue.js +0 -31
  253. package/dist/esm/utils/edit/isValidDateOrTimeValue.js +0 -7
  254. package/dist/esm/utils/focus/blur.js +0 -12
  255. package/dist/esm/utils/focus/copySelection.js +0 -42
  256. package/dist/esm/utils/focus/focus.js +0 -25
  257. package/dist/esm/utils/focus/selectAll.js +0 -51
  258. package/dist/esm/utils/misc/eventWrapper.js +0 -11
  259. package/dist/types/document/selection.d.ts +0 -29
  260. package/dist/types/document/setRangeText.d.ts +0 -1
  261. package/dist/types/document/value.d.ts +0 -26
  262. package/dist/types/setup/config.d.ts +0 -6
  263. package/dist/types/utils/edit/buildTimeValue.d.ts +0 -1
  264. package/dist/types/utils/edit/getValue.d.ts +0 -1
  265. package/dist/types/utils/edit/input.d.ts +0 -2
  266. package/dist/types/utils/edit/walkRadio.d.ts +0 -4
  267. package/dist/types/utils/focus/blur.d.ts +0 -2
  268. package/dist/types/utils/focus/focus.d.ts +0 -5
  269. package/dist/types/utils/misc/eventWrapper.d.ts +0 -1
  270. /package/dist/cjs/{event → _interop}/dom-events.d.js +0 -0
  271. /package/dist/cjs/{utils/misc → _interop}/dom-helpers.d.js +0 -0
  272. /package/dist/esm/{event → _interop}/dom-events.d.js +0 -0
  273. /package/dist/esm/{utils/misc → _interop}/dom-helpers.d.js +0 -0
  274. /package/dist/types/{utils/focus → document}/copySelection.d.ts +0 -0
  275. /package/dist/types/{utils/focus → event/selection}/resolveCaretPosition.d.ts +0 -0
  276. /package/dist/types/{utils/focus → event/selection}/selectAll.d.ts +0 -0
@@ -1,19 +1,14 @@
1
- import { createEvent } from './createEvent.js';
2
- import { dispatchEvent } from './dispatchEvent.js';
3
- import { isMouseEvent, isKeyboardEvent } from './eventMap.js';
4
-
5
- function dispatchUIEvent(config, target, type, init, preventDefault = false) {
6
- if (isMouseEvent(type) || isKeyboardEvent(type)) {
7
- init = {
8
- ...init,
9
- ...config.system.getUIEventModifiers()
10
- };
11
- }
12
- const event = createEvent(type, target, init);
13
- return dispatchEvent(config, target, event, preventDefault);
14
- }
15
- function bindDispatchUIEvent(config) {
16
- return dispatchUIEvent.bind(undefined, config);
17
- }
18
-
19
- export { bindDispatchUIEvent, dispatchUIEvent };
1
+ export { dispatchDOMEvent, dispatchEvent, dispatchUIEvent } from './dispatchEvent.js';
2
+ export { blurElement, focusElement } from './focus.js';
3
+ export { input } from './input.js';
4
+ import '../utils/click/isClickableInput.js';
5
+ import '../utils/dataTransfer/Clipboard.js';
6
+ import '../utils/edit/isEditable.js';
7
+ import '../utils/edit/maxLength.js';
8
+ import '@testing-library/dom/dist/helpers.js';
9
+ import '../utils/keyDef/readNextDescriptor.js';
10
+ import '../utils/misc/level.js';
11
+ import '../options.js';
12
+ export { setSelectionPerMouseDown } from './selection/setSelectionPerMouse.js';
13
+ export { modifySelectionPerMouseMove } from './selection/modifySelectionPerMouse.js';
14
+ export { isAllSelected, selectAll } from './selection/selectAll.js';
@@ -1,19 +1,18 @@
1
- import { dispatchUIEvent } from '../../event/index.js';
2
- import '../click/isClickableInput.js';
3
- import '../dataTransfer/Clipboard.js';
4
- import './isEditable.js';
5
- import '@testing-library/dom';
6
- import { isElementType } from '../misc/isElementType.js';
7
- import { getInputRange, setSelection } from '../focus/selection.js';
1
+ import { setUIValue, clearInitialValue, getUIValue } from '../document/UI.js';
2
+ import '../utils/click/isClickableInput.js';
3
+ import '../utils/dataTransfer/Clipboard.js';
4
+ import { isValidDateOrTimeValue, buildTimeValue } from '../utils/edit/timeValue.js';
5
+ import '../utils/edit/isEditable.js';
6
+ import { supportsMaxLength, getMaxLength } from '../utils/edit/maxLength.js';
7
+ import { getNextCursorPosition } from '../utils/focus/cursor.js';
8
+ import { isElementType } from '../utils/misc/isElementType.js';
8
9
  import '@testing-library/dom/dist/helpers.js';
9
- import { getNextCursorPosition } from '../focus/cursor.js';
10
- import '../keyDef/readNextDescriptor.js';
11
- import '../misc/level.js';
12
- import '../../options.js';
13
- import { setUIValue, clearInitialValue, getUIValue, commitValueAfterInput } from '../../document/value.js';
14
- import { buildTimeValue } from './buildTimeValue.js';
15
- import { isValidDateOrTimeValue } from './isValidDateOrTimeValue.js';
16
- import { getSpaceUntilMaxLength } from './maxLength.js';
10
+ import '../utils/keyDef/readNextDescriptor.js';
11
+ import '../utils/misc/level.js';
12
+ import '../options.js';
13
+ import { commitValueAfterInput } from '../document/trackValue.js';
14
+ import { getInputRange } from './selection/getInputRange.js';
15
+ import { setSelection } from './selection/setSelection.js';
17
16
 
18
17
  function isDateOrTime(element) {
19
18
  return isElementType(element, 'input') && [
@@ -21,14 +20,14 @@ function isDateOrTime(element) {
21
20
  'time'
22
21
  ].includes(element.type);
23
22
  }
24
- function input(config, element, data, inputType = 'insertText') {
23
+ function input(instance, element, data, inputType = 'insertText') {
25
24
  const inputRange = getInputRange(element);
26
25
  /* istanbul ignore if */ if (!inputRange) {
27
26
  return;
28
27
  }
29
28
  // There is no `beforeinput` event on `date` and `time` input
30
29
  if (!isDateOrTime(element)) {
31
- const unprevented = dispatchUIEvent(config, element, 'beforeinput', {
30
+ const unprevented = instance.dispatchUIEvent(element, 'beforeinput', {
32
31
  inputType,
33
32
  data
34
33
  });
@@ -37,12 +36,12 @@ function input(config, element, data, inputType = 'insertText') {
37
36
  }
38
37
  }
39
38
  if ('startContainer' in inputRange) {
40
- editContenteditable(config, element, inputRange, data, inputType);
39
+ editContenteditable(instance, element, inputRange, data, inputType);
41
40
  } else {
42
- editInputElement(config, element, inputRange, data, inputType);
41
+ editInputElement(instance, element, inputRange, data, inputType);
43
42
  }
44
43
  }
45
- function editContenteditable(config, element, inputRange, data, inputType) {
44
+ function editContenteditable(instance, element, inputRange, data, inputType) {
46
45
  let del = false;
47
46
  if (!inputRange.collapsed) {
48
47
  del = true;
@@ -77,22 +76,25 @@ function editContenteditable(config, element, inputRange, data, inputType) {
77
76
  }
78
77
  }
79
78
  if (del || data) {
80
- dispatchUIEvent(config, element, 'input', {
79
+ instance.dispatchUIEvent(element, 'input', {
81
80
  inputType
82
81
  });
83
82
  }
84
83
  }
85
- function editInputElement(config, element, inputRange, data, inputType) {
84
+ function editInputElement(instance, element, inputRange, data, inputType) {
86
85
  let dataToInsert = data;
87
- const spaceUntilMaxLength = getSpaceUntilMaxLength(element);
88
- if (spaceUntilMaxLength !== undefined && data.length > 0) {
89
- if (spaceUntilMaxLength > 0) {
90
- dataToInsert = data.substring(0, spaceUntilMaxLength);
91
- } else {
92
- return;
86
+ if (supportsMaxLength(element)) {
87
+ const maxLength = getMaxLength(element);
88
+ if (maxLength !== undefined && data.length > 0) {
89
+ const spaceUntilMaxLength = maxLength - element.value.length;
90
+ if (spaceUntilMaxLength > 0) {
91
+ dataToInsert = data.substring(0, spaceUntilMaxLength);
92
+ } else {
93
+ return;
94
+ }
93
95
  }
94
96
  }
95
- const { newValue , newOffset , oldValue } = calculateNewValue(dataToInsert, element, inputRange, inputType);
97
+ const { newValue, newOffset, oldValue } = calculateNewValue(dataToInsert, element, inputRange, inputType);
96
98
  if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
97
99
  return;
98
100
  }
@@ -109,18 +111,18 @@ function editInputElement(config, element, inputRange, data, inputType) {
109
111
  });
110
112
  if (isDateOrTime(element)) {
111
113
  if (isValidDateOrTimeValue(element, newValue)) {
112
- commitInput(config, element, newOffset, {});
113
- dispatchUIEvent(config, element, 'change');
114
+ commitInput(instance, element, newOffset, {});
115
+ instance.dispatchUIEvent(element, 'change');
114
116
  clearInitialValue(element);
115
117
  }
116
118
  } else {
117
- commitInput(config, element, newOffset, {
119
+ commitInput(instance, element, newOffset, {
118
120
  data,
119
121
  inputType
120
122
  });
121
123
  }
122
124
  }
123
- function calculateNewValue(inputData, node, { startOffset , endOffset }, inputType) {
125
+ function calculateNewValue(inputData, node, { startOffset, endOffset }, inputType) {
124
126
  const value = getUIValue(node);
125
127
  const prologEnd = Math.max(0, startOffset === endOffset && inputType === 'deleteContentBackward' ? startOffset - 1 : startOffset);
126
128
  const prolog = value.substring(0, prologEnd);
@@ -143,17 +145,17 @@ function calculateNewValue(inputData, node, { startOffset , endOffset }, inputT
143
145
  newOffset
144
146
  };
145
147
  }
146
- function commitInput(config, element, newOffset, inputInit) {
147
- dispatchUIEvent(config, element, 'input', inputInit);
148
+ function commitInput(instance, element, newOffset, inputInit) {
149
+ instance.dispatchUIEvent(element, 'input', inputInit);
148
150
  commitValueAfterInput(element, newOffset);
149
151
  }
150
152
  function isValidNumberInput(value) {
151
- var ref, ref1;
153
+ var _value_match, _value_match1;
152
154
  // the browser allows some invalid input but not others
153
155
  // it allows up to two '-' at any place before any 'e' or one directly following 'e'
154
156
  // it allows one '.' at any place before e
155
157
  const valueParts = value.split('e', 2);
156
- 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]));
157
159
  }
158
160
 
159
161
  export { input };
@@ -1,9 +1,15 @@
1
- import { dispatchUIEvent } from '../../event/index.js';
2
- import { focus } from '../focus/focus.js';
3
- import { getWindow } from '../misc/getWindow.js';
4
- import { isDisabled } from '../misc/isDisabled.js';
1
+ import '../utils/click/isClickableInput.js';
2
+ import '../utils/dataTransfer/Clipboard.js';
3
+ import '../utils/edit/isEditable.js';
4
+ import '../utils/edit/maxLength.js';
5
+ import { isDisabled } from '../utils/misc/isDisabled.js';
6
+ import { getWindow } from '../utils/misc/getWindow.js';
7
+ import '../utils/keyDef/readNextDescriptor.js';
8
+ import '../utils/misc/level.js';
9
+ import '../options.js';
10
+ import { focusElement } from './focus.js';
5
11
 
6
- function walkRadio(config, el, direction) {
12
+ function walkRadio(instance, el, direction) {
7
13
  const window = getWindow(el);
8
14
  const group = Array.from(el.ownerDocument.querySelectorAll(el.name ? `input[type="radio"][name="${window.CSS.escape(el.name)}"]` : `input[type="radio"][name=""], input[type="radio"]:not([name])`));
9
15
  for(let i = group.findIndex((e)=>e === el) + direction;; i += direction){
@@ -16,8 +22,8 @@ function walkRadio(config, el, direction) {
16
22
  if (isDisabled(group[i])) {
17
23
  continue;
18
24
  }
19
- focus(group[i]);
20
- dispatchUIEvent(config, group[i], 'click');
25
+ focusElement(group[i]);
26
+ instance.dispatchUIEvent(group[i], 'click');
21
27
  }
22
28
  }
23
29
 
@@ -0,0 +1,16 @@
1
+ import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
2
+
3
+ /**
4
+ * Get the range that would be overwritten by input.
5
+ */ function getInputRange(focusNode) {
6
+ const typeAndSelection = getTargetTypeAndSelection(focusNode);
7
+ if (typeAndSelection.type === 'input') {
8
+ return typeAndSelection.selection;
9
+ } else if (typeAndSelection.type === 'contenteditable') {
10
+ var _typeAndSelection_selection;
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);
13
+ }
14
+ }
15
+
16
+ export { getInputRange };
@@ -0,0 +1,37 @@
1
+ import { getUISelection } from '../../document/UI.js';
2
+ import '../../utils/click/isClickableInput.js';
3
+ import '../../utils/dataTransfer/Clipboard.js';
4
+ import { getContentEditable } from '../../utils/edit/isContentEditable.js';
5
+ import '../../utils/edit/isEditable.js';
6
+ import '../../utils/edit/maxLength.js';
7
+ import '@testing-library/dom/dist/helpers.js';
8
+ import { hasOwnSelection } from '../../utils/focus/selection.js';
9
+ import '../../utils/keyDef/readNextDescriptor.js';
10
+ import '../../utils/misc/level.js';
11
+ import '../../options.js';
12
+
13
+ /**
14
+ * Determine which selection logic and selection ranges to consider.
15
+ */ function getTargetTypeAndSelection(node) {
16
+ var _element, _selection;
17
+ const element = getElement(node);
18
+ if (element && hasOwnSelection(element)) {
19
+ return {
20
+ type: 'input',
21
+ selection: getUISelection(element)
22
+ };
23
+ }
24
+ const selection = (_element = element) === null || _element === void 0 ? void 0 : _element.ownerDocument.getSelection();
25
+ // It is possible to extend a single-range selection into a contenteditable.
26
+ // This results in the range acting like a range outside of contenteditable.
27
+ const isCE = getContentEditable(node) && ((_selection = selection) === null || _selection === void 0 ? void 0 : _selection.anchorNode) && getContentEditable(selection.anchorNode);
28
+ return {
29
+ type: isCE ? 'contenteditable' : 'default',
30
+ selection
31
+ };
32
+ }
33
+ function getElement(node) {
34
+ return node.nodeType === 1 ? node : node.parentElement;
35
+ }
36
+
37
+ export { getTargetTypeAndSelection };
@@ -0,0 +1,9 @@
1
+ export { getInputRange } from './getInputRange.js';
2
+ export { modifySelection } from './modifySelection.js';
3
+ export { moveSelection } from './moveSelection.js';
4
+ export { setSelectionPerMouseDown } from './setSelectionPerMouse.js';
5
+ export { modifySelectionPerMouseMove } from './modifySelectionPerMouse.js';
6
+ export { isAllSelected, selectAll } from './selectAll.js';
7
+ export { setSelectionRange } from './setSelectionRange.js';
8
+ export { setSelection } from './setSelection.js';
9
+ export { updateSelectionOnFocus } from './updateSelectionOnFocus.js';
@@ -0,0 +1,26 @@
1
+ import { setUISelection } from '../../document/UI.js';
2
+ import '../../utils/click/isClickableInput.js';
3
+ import '../../utils/dataTransfer/Clipboard.js';
4
+ import '../../utils/edit/isEditable.js';
5
+ import '../../utils/edit/maxLength.js';
6
+ import '@testing-library/dom/dist/helpers.js';
7
+ import '../../utils/keyDef/readNextDescriptor.js';
8
+ import '../../utils/misc/level.js';
9
+ import '../../options.js';
10
+ import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
11
+
12
+ /**
13
+ * Extend/shrink the selection like with Shift+Arrows or Shift+Mouse
14
+ */ function modifySelection({ focusNode, focusOffset }) {
15
+ var _focusNode_ownerDocument_getSelection, _focusNode_ownerDocument;
16
+ const typeAndSelection = getTargetTypeAndSelection(focusNode);
17
+ if (typeAndSelection.type === 'input') {
18
+ return setUISelection(focusNode, {
19
+ anchorOffset: typeAndSelection.selection.anchorOffset,
20
+ focusOffset
21
+ }, 'modify');
22
+ }
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
+ }
25
+
26
+ export { modifySelection };
@@ -0,0 +1,46 @@
1
+ import { setUISelection } from '../../document/UI.js';
2
+ import '../../utils/click/isClickableInput.js';
3
+ import '../../utils/dataTransfer/Clipboard.js';
4
+ import '../../utils/edit/isEditable.js';
5
+ import '../../utils/edit/maxLength.js';
6
+ import '@testing-library/dom/dist/helpers.js';
7
+ import '../../utils/keyDef/readNextDescriptor.js';
8
+ import '../../utils/misc/level.js';
9
+ import '../../options.js';
10
+ import { resolveCaretPosition } from './resolveCaretPosition.js';
11
+
12
+ function modifySelectionPerMouseMove(selectionRange, { document, target, node, offset }) {
13
+ const selectionFocus = resolveCaretPosition({
14
+ target,
15
+ node,
16
+ offset
17
+ });
18
+ if ('node' in selectionRange) {
19
+ // When the mouse is dragged outside of an input/textarea,
20
+ // the selection is extended to the beginning or end of the input
21
+ // depending on pointer position.
22
+ // TODO: extend selection according to pointer position
23
+ /* istanbul ignore else */ if (selectionFocus.node === selectionRange.node) {
24
+ const anchorOffset = selectionFocus.offset < selectionRange.start ? selectionRange.end : selectionRange.start;
25
+ const focusOffset = selectionFocus.offset > selectionRange.end || selectionFocus.offset < selectionRange.start ? selectionFocus.offset : selectionRange.end;
26
+ setUISelection(selectionRange.node, {
27
+ anchorOffset,
28
+ focusOffset
29
+ });
30
+ }
31
+ } else {
32
+ var _selection, _selection1;
33
+ const range = selectionRange.cloneRange();
34
+ const cmp = range.comparePoint(selectionFocus.node, selectionFocus.offset);
35
+ if (cmp < 0) {
36
+ range.setStart(selectionFocus.node, selectionFocus.offset);
37
+ } else if (cmp > 0) {
38
+ range.setEnd(selectionFocus.node, selectionFocus.offset);
39
+ }
40
+ const selection = document.getSelection();
41
+ (_selection = selection) === null || _selection === void 0 ? void 0 : _selection.removeAllRanges();
42
+ (_selection1 = selection) === null || _selection1 === void 0 ? void 0 : _selection1.addRange(range.cloneRange());
43
+ }
44
+ }
45
+
46
+ export { modifySelectionPerMouseMove };
@@ -0,0 +1,44 @@
1
+ import { getUISelection } from '../../document/UI.js';
2
+ import '../../utils/click/isClickableInput.js';
3
+ import '../../utils/dataTransfer/Clipboard.js';
4
+ import '../../utils/edit/isEditable.js';
5
+ import '../../utils/edit/maxLength.js';
6
+ import { getNextCursorPosition } from '../../utils/focus/cursor.js';
7
+ import '@testing-library/dom/dist/helpers.js';
8
+ import { hasOwnSelection } from '../../utils/focus/selection.js';
9
+ import '../../utils/keyDef/readNextDescriptor.js';
10
+ import '../../utils/misc/level.js';
11
+ import '../../options.js';
12
+ import { setSelection } from './setSelection.js';
13
+
14
+ /**
15
+ * Move the selection
16
+ */ function moveSelection(node, direction) {
17
+ // TODO: implement shift
18
+ if (hasOwnSelection(node)) {
19
+ const selection = getUISelection(node);
20
+ setSelection({
21
+ focusNode: node,
22
+ focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + direction : direction < 0 ? selection.startOffset : selection.endOffset
23
+ });
24
+ } else {
25
+ var _selection;
26
+ const selection = node.ownerDocument.getSelection();
27
+ if (!((_selection = selection) === null || _selection === void 0 ? void 0 : _selection.focusNode)) {
28
+ return;
29
+ }
30
+ if (selection.isCollapsed) {
31
+ const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, direction);
32
+ if (nextPosition) {
33
+ setSelection({
34
+ focusNode: nextPosition.node,
35
+ focusOffset: nextPosition.offset
36
+ });
37
+ }
38
+ } else {
39
+ selection[direction < 0 ? 'collapseToStart' : 'collapseToEnd']();
40
+ }
41
+ }
42
+ }
43
+
44
+ export { moveSelection };
@@ -1,23 +1,15 @@
1
- import '../click/isClickableInput.js';
2
- import '../dataTransfer/Clipboard.js';
3
- import '../edit/maxLength.js';
4
- import '../edit/isEditable.js';
5
- import '@testing-library/dom';
6
- import { hasOwnSelection } from './selection.js';
1
+ import { getUIValue } from '../../document/UI.js';
2
+ import '../../utils/click/isClickableInput.js';
3
+ import '../../utils/dataTransfer/Clipboard.js';
4
+ import '../../utils/edit/isEditable.js';
5
+ import '../../utils/edit/maxLength.js';
7
6
  import '@testing-library/dom/dist/helpers.js';
8
- import '../keyDef/readNextDescriptor.js';
9
- import '../misc/level.js';
7
+ import { hasOwnSelection } from '../../utils/focus/selection.js';
8
+ import '../../utils/keyDef/readNextDescriptor.js';
9
+ import '../../utils/misc/level.js';
10
10
  import '../../options.js';
11
- import '../../event/eventMap.js';
12
- import '../../event/behavior/click.js';
13
- import '../../event/behavior/cut.js';
14
- import '../../event/behavior/keydown.js';
15
- import '../../event/behavior/keypress.js';
16
- import '../../event/behavior/keyup.js';
17
- import '../../event/behavior/paste.js';
18
- import { getUIValue } from '../../document/value.js';
19
11
 
20
- function resolveCaretPosition({ target , node , offset }) {
12
+ function resolveCaretPosition({ target, node, offset }) {
21
13
  if (hasOwnSelection(target)) {
22
14
  return {
23
15
  node: target,
@@ -0,0 +1,43 @@
1
+ import { getUIValue, getUISelection } from '../../document/UI.js';
2
+ import '../../utils/click/isClickableInput.js';
3
+ import '../../utils/dataTransfer/Clipboard.js';
4
+ import { getContentEditable } from '../../utils/edit/isContentEditable.js';
5
+ import '../../utils/edit/isEditable.js';
6
+ import '../../utils/edit/maxLength.js';
7
+ import '@testing-library/dom/dist/helpers.js';
8
+ import { hasOwnSelection } from '../../utils/focus/selection.js';
9
+ import '../../utils/keyDef/readNextDescriptor.js';
10
+ import '../../utils/misc/level.js';
11
+ import '../../options.js';
12
+ import { setSelection } from './setSelection.js';
13
+
14
+ /**
15
+ * Expand a selection like the browser does when pressing Ctrl+A.
16
+ */ function selectAll(target) {
17
+ if (hasOwnSelection(target)) {
18
+ return setSelection({
19
+ focusNode: target,
20
+ anchorOffset: 0,
21
+ focusOffset: getUIValue(target).length
22
+ });
23
+ }
24
+ var _getContentEditable;
25
+ const focusNode = (_getContentEditable = getContentEditable(target)) !== null && _getContentEditable !== void 0 ? _getContentEditable : target.ownerDocument.body;
26
+ setSelection({
27
+ focusNode,
28
+ anchorOffset: 0,
29
+ focusOffset: focusNode.childNodes.length
30
+ });
31
+ }
32
+ function isAllSelected(target) {
33
+ var _selection;
34
+ if (hasOwnSelection(target)) {
35
+ return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
36
+ }
37
+ var _getContentEditable;
38
+ const focusNode = (_getContentEditable = getContentEditable(target)) !== null && _getContentEditable !== void 0 ? _getContentEditable : target.ownerDocument.body;
39
+ const selection = target.ownerDocument.getSelection();
40
+ return ((_selection = selection) === null || _selection === void 0 ? void 0 : _selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
41
+ }
42
+
43
+ export { isAllSelected, selectAll };
@@ -0,0 +1,26 @@
1
+ import { setUISelection } from '../../document/UI.js';
2
+ import '../../utils/click/isClickableInput.js';
3
+ import '../../utils/dataTransfer/Clipboard.js';
4
+ import '../../utils/edit/isEditable.js';
5
+ import '../../utils/edit/maxLength.js';
6
+ import '@testing-library/dom/dist/helpers.js';
7
+ import '../../utils/keyDef/readNextDescriptor.js';
8
+ import '../../utils/misc/level.js';
9
+ import '../../options.js';
10
+ import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
11
+
12
+ /**
13
+ * Set the selection
14
+ */ function setSelection({ focusNode, focusOffset, anchorNode = focusNode, anchorOffset = focusOffset }) {
15
+ var _anchorNode_ownerDocument_getSelection, _anchorNode_ownerDocument;
16
+ const typeAndSelection = getTargetTypeAndSelection(focusNode);
17
+ if (typeAndSelection.type === 'input') {
18
+ return setUISelection(focusNode, {
19
+ anchorOffset,
20
+ focusOffset
21
+ });
22
+ }
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
+ }
25
+
26
+ export { setSelection };
@@ -0,0 +1,87 @@
1
+ import { getUIValue, setUISelection } from '../../document/UI.js';
2
+ import '../../utils/click/isClickableInput.js';
3
+ import '../../utils/dataTransfer/Clipboard.js';
4
+ import '../../utils/edit/isEditable.js';
5
+ import '../../utils/edit/maxLength.js';
6
+ import '@testing-library/dom/dist/helpers.js';
7
+ import { hasNoSelection, hasOwnSelection } from '../../utils/focus/selection.js';
8
+ import '../../utils/keyDef/readNextDescriptor.js';
9
+ import '../../utils/misc/level.js';
10
+ import '../../options.js';
11
+ import { resolveCaretPosition } from './resolveCaretPosition.js';
12
+
13
+ function setSelectionPerMouseDown({ document, target, clickCount, node, offset }) {
14
+ if (hasNoSelection(target)) {
15
+ return;
16
+ }
17
+ const targetHasOwnSelection = hasOwnSelection(target);
18
+ // On non-input elements the text selection per multiple click
19
+ // can extend beyond the target boundaries.
20
+ // The exact mechanism what is considered in the same line is unclear.
21
+ // Looks it might be every inline element.
22
+ // TODO: Check what might be considered part of the same line of text.
23
+ const text = String(targetHasOwnSelection ? getUIValue(target) : target.textContent);
24
+ const [start, end] = node ? // which elements might be considered in the same line of text.
25
+ // TODO: support expanding initial range on multiple clicks if node is given
26
+ [
27
+ offset,
28
+ offset
29
+ ] : getTextRange(text, offset, clickCount);
30
+ // TODO: implement modifying selection per shift/ctrl+mouse
31
+ if (targetHasOwnSelection) {
32
+ setUISelection(target, {
33
+ anchorOffset: start !== null && start !== void 0 ? start : text.length,
34
+ focusOffset: end !== null && end !== void 0 ? end : text.length
35
+ });
36
+ return {
37
+ node: target,
38
+ start: start !== null && start !== void 0 ? start : 0,
39
+ end: end !== null && end !== void 0 ? end : text.length
40
+ };
41
+ } else {
42
+ var _selection, _selection1;
43
+ const { node: startNode, offset: startOffset } = resolveCaretPosition({
44
+ target,
45
+ node,
46
+ offset: start
47
+ });
48
+ const { node: endNode, offset: endOffset } = resolveCaretPosition({
49
+ target,
50
+ node,
51
+ offset: end
52
+ });
53
+ const range = target.ownerDocument.createRange();
54
+ try {
55
+ range.setStart(startNode, startOffset);
56
+ range.setEnd(endNode, endOffset);
57
+ } catch (e) {
58
+ throw new Error('The given offset is out of bounds.');
59
+ }
60
+ const selection = document.getSelection();
61
+ (_selection = selection) === null || _selection === void 0 ? void 0 : _selection.removeAllRanges();
62
+ (_selection1 = selection) === null || _selection1 === void 0 ? void 0 : _selection1.addRange(range.cloneRange());
63
+ return range;
64
+ }
65
+ }
66
+ function getTextRange(text, pos, clickCount) {
67
+ if (clickCount % 3 === 1 || text.length === 0) {
68
+ return [
69
+ pos,
70
+ pos
71
+ ];
72
+ }
73
+ const textPos = pos !== null && pos !== void 0 ? pos : text.length;
74
+ if (clickCount % 3 === 2) {
75
+ return [
76
+ textPos - text.substr(0, pos).match(/(\w+|\s+|\W)?$/)[0].length,
77
+ pos === undefined ? pos : pos + text.substr(pos).match(/^(\w+|\s+|\W)?/)[0].length
78
+ ];
79
+ }
80
+ // triple click
81
+ return [
82
+ textPos - text.substr(0, pos).match(/[^\r\n]*$/)[0].length,
83
+ pos === undefined ? pos : pos + text.substr(pos).match(/^[^\r\n]*/)[0].length
84
+ ];
85
+ }
86
+
87
+ export { setSelectionPerMouseDown };
@@ -0,0 +1,36 @@
1
+ import '../../utils/click/isClickableInput.js';
2
+ import '../../utils/dataTransfer/Clipboard.js';
3
+ import { isContentEditable } from '../../utils/edit/isContentEditable.js';
4
+ import '../../utils/edit/isEditable.js';
5
+ import '../../utils/edit/maxLength.js';
6
+ import '@testing-library/dom/dist/helpers.js';
7
+ import { hasOwnSelection } from '../../utils/focus/selection.js';
8
+ import '../../utils/keyDef/readNextDescriptor.js';
9
+ import '../../utils/misc/level.js';
10
+ import '../../options.js';
11
+ import { setSelection } from './setSelection.js';
12
+
13
+ /**
14
+ * Backward-compatible selection.
15
+ *
16
+ * Handles input elements and contenteditable if it only contains a single text node.
17
+ */ function setSelectionRange(element, anchorOffset, focusOffset) {
18
+ var _element_firstChild;
19
+ if (hasOwnSelection(element)) {
20
+ return setSelection({
21
+ focusNode: element,
22
+ anchorOffset,
23
+ focusOffset
24
+ });
25
+ }
26
+ /* istanbul ignore else */ if (isContentEditable(element) && ((_element_firstChild = element.firstChild) === null || _element_firstChild === void 0 ? void 0 : _element_firstChild.nodeType) === 3) {
27
+ return setSelection({
28
+ focusNode: element.firstChild,
29
+ anchorOffset,
30
+ focusOffset
31
+ });
32
+ }
33
+ /* istanbul ignore next */ throw new Error('Not implemented. The result of this interaction is unreliable.');
34
+ }
35
+
36
+ export { setSelectionRange };