@testing-library/user-event 14.4.2 → 14.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/dist/cjs/clipboard/copy.js +4 -14
  2. package/dist/cjs/clipboard/cut.js +4 -14
  3. package/dist/cjs/clipboard/paste.js +2 -12
  4. package/dist/cjs/convenience/click.js +1 -4
  5. package/dist/cjs/convenience/hover.js +2 -12
  6. package/dist/cjs/document/{selection.js → UI.js} +43 -57
  7. package/dist/cjs/document/copySelection.js +37 -0
  8. package/dist/cjs/document/getValueOrTextContent.js +27 -0
  9. package/dist/cjs/document/index.js +13 -68
  10. package/dist/cjs/document/interceptor.js +83 -0
  11. package/dist/cjs/document/prepareDocument.js +67 -0
  12. package/dist/cjs/document/trackValue.js +65 -0
  13. package/dist/cjs/event/behavior/click.js +8 -12
  14. package/dist/cjs/event/behavior/cut.js +5 -11
  15. package/dist/cjs/event/behavior/keydown.js +39 -43
  16. package/dist/cjs/event/behavior/keypress.js +8 -9
  17. package/dist/cjs/event/behavior/keyup.js +5 -7
  18. package/dist/cjs/event/behavior/paste.js +5 -11
  19. package/dist/cjs/event/createEvent.js +2 -9
  20. package/dist/cjs/event/dispatchEvent.js +20 -2
  21. package/dist/cjs/event/focus.js +44 -0
  22. package/dist/cjs/event/index.js +24 -17
  23. package/dist/cjs/{utils/edit → event}/input.js +48 -46
  24. package/dist/cjs/{utils/edit/walkRadio.js → event/radio.js} +13 -7
  25. package/dist/cjs/event/selection/getInputRange.js +20 -0
  26. package/dist/cjs/event/selection/getTargetTypeAndSelection.js +40 -0
  27. package/dist/cjs/event/selection/index.js +26 -0
  28. package/dist/cjs/event/selection/modifySelection.js +30 -0
  29. package/dist/cjs/event/selection/modifySelectionPerMouse.js +49 -0
  30. package/dist/cjs/event/selection/moveSelection.js +47 -0
  31. package/dist/cjs/{utils/focus → event/selection}/resolveCaretPosition.js +9 -17
  32. package/dist/cjs/event/selection/selectAll.js +47 -0
  33. package/dist/cjs/event/selection/setSelection.js +30 -0
  34. package/dist/cjs/event/selection/setSelectionPerMouse.js +90 -0
  35. package/dist/cjs/event/selection/setSelectionRange.js +40 -0
  36. package/dist/cjs/event/selection/updateSelectionOnFocus.js +45 -0
  37. package/dist/cjs/keyboard/index.js +13 -23
  38. package/dist/cjs/keyboard/parseKeyDef.js +1 -9
  39. package/dist/cjs/options.js +0 -28
  40. package/dist/cjs/pointer/index.js +20 -30
  41. package/dist/cjs/pointer/parseKeyDef.js +1 -9
  42. package/dist/cjs/setup/directApi.js +6 -6
  43. package/dist/cjs/setup/index.js +0 -2
  44. package/dist/cjs/setup/setup.js +65 -37
  45. package/dist/cjs/system/keyboard.js +7 -9
  46. package/dist/cjs/system/pointer/index.js +16 -21
  47. package/dist/cjs/system/pointer/mouse.js +45 -38
  48. package/dist/cjs/system/pointer/pointer.js +33 -35
  49. package/dist/cjs/system/pointer/shared.js +10 -0
  50. package/dist/cjs/utility/clear.js +10 -11
  51. package/dist/cjs/utility/selectOptions.js +17 -19
  52. package/dist/cjs/utility/type.js +6 -15
  53. package/dist/cjs/utility/upload.js +3 -13
  54. package/dist/cjs/utils/dataTransfer/Clipboard.js +1 -15
  55. package/dist/cjs/utils/edit/isEditable.js +6 -10
  56. package/dist/cjs/utils/edit/maxLength.js +4 -15
  57. package/dist/cjs/utils/edit/{buildTimeValue.js → timeValue.js} +6 -0
  58. package/dist/cjs/utils/focus/cursor.js +0 -16
  59. package/dist/cjs/utils/focus/selection.js +1 -271
  60. package/dist/cjs/utils/index.js +7 -32
  61. package/dist/cjs/utils/misc/level.js +4 -9
  62. package/dist/cjs/utils/pointer/cssPointerEvents.js +9 -22
  63. package/dist/esm/clipboard/copy.js +4 -14
  64. package/dist/esm/clipboard/cut.js +4 -14
  65. package/dist/esm/clipboard/paste.js +2 -12
  66. package/dist/esm/convenience/click.js +1 -4
  67. package/dist/esm/convenience/hover.js +2 -12
  68. package/dist/esm/document/{selection.js → UI.js} +35 -56
  69. package/dist/esm/document/copySelection.js +33 -0
  70. package/dist/esm/document/getValueOrTextContent.js +23 -0
  71. package/dist/esm/document/index.js +4 -66
  72. package/dist/esm/document/interceptor.js +81 -1
  73. package/dist/esm/document/prepareDocument.js +63 -0
  74. package/dist/esm/document/{value.js → trackValue.js} +3 -61
  75. package/dist/esm/event/behavior/click.js +8 -12
  76. package/dist/esm/event/behavior/cut.js +5 -11
  77. package/dist/esm/event/behavior/keydown.js +32 -36
  78. package/dist/esm/event/behavior/keypress.js +8 -9
  79. package/dist/esm/event/behavior/keyup.js +5 -7
  80. package/dist/esm/event/behavior/paste.js +5 -11
  81. package/dist/esm/event/createEvent.js +2 -9
  82. package/dist/esm/event/dispatchEvent.js +19 -3
  83. package/dist/esm/event/focus.js +39 -0
  84. package/dist/esm/event/index.js +14 -19
  85. package/dist/esm/{utils/edit → event}/input.js +35 -33
  86. package/dist/esm/{utils/edit/walkRadio.js → event/radio.js} +13 -7
  87. package/dist/esm/event/selection/getInputRange.js +16 -0
  88. package/dist/esm/event/selection/getTargetTypeAndSelection.js +36 -0
  89. package/dist/esm/event/selection/index.js +9 -0
  90. package/dist/esm/event/selection/modifySelection.js +26 -0
  91. package/dist/esm/event/selection/modifySelectionPerMouse.js +45 -0
  92. package/dist/esm/event/selection/moveSelection.js +43 -0
  93. package/dist/esm/{utils/focus → event/selection}/resolveCaretPosition.js +8 -16
  94. package/dist/esm/{utils/focus → event/selection}/selectAll.js +12 -21
  95. package/dist/esm/event/selection/setSelection.js +26 -0
  96. package/dist/esm/event/selection/setSelectionPerMouse.js +86 -0
  97. package/dist/esm/event/selection/setSelectionRange.js +36 -0
  98. package/dist/esm/event/selection/updateSelectionOnFocus.js +41 -0
  99. package/dist/esm/keyboard/index.js +13 -23
  100. package/dist/esm/keyboard/parseKeyDef.js +1 -9
  101. package/dist/esm/options.js +1 -26
  102. package/dist/esm/pointer/index.js +20 -30
  103. package/dist/esm/pointer/parseKeyDef.js +1 -9
  104. package/dist/esm/setup/directApi.js +6 -6
  105. package/dist/esm/setup/index.js +0 -1
  106. package/dist/esm/setup/setup.js +59 -32
  107. package/dist/esm/system/keyboard.js +7 -9
  108. package/dist/esm/system/pointer/index.js +17 -21
  109. package/dist/esm/system/pointer/mouse.js +42 -35
  110. package/dist/esm/system/pointer/pointer.js +32 -34
  111. package/dist/esm/system/pointer/shared.js +6 -0
  112. package/dist/esm/utility/clear.js +10 -11
  113. package/dist/esm/utility/selectOptions.js +17 -19
  114. package/dist/esm/utility/type.js +5 -14
  115. package/dist/esm/utility/upload.js +3 -13
  116. package/dist/esm/utils/dataTransfer/Clipboard.js +1 -15
  117. package/dist/esm/utils/edit/isEditable.js +4 -8
  118. package/dist/esm/utils/edit/maxLength.js +3 -15
  119. package/dist/esm/utils/edit/{buildTimeValue.js → timeValue.js} +6 -1
  120. package/dist/esm/utils/focus/cursor.js +0 -16
  121. package/dist/esm/utils/focus/selection.js +3 -265
  122. package/dist/esm/utils/index.js +4 -11
  123. package/dist/esm/utils/misc/level.js +4 -9
  124. package/dist/esm/utils/pointer/cssPointerEvents.js +9 -22
  125. package/dist/types/clipboard/copy.d.ts +1 -1
  126. package/dist/types/clipboard/cut.d.ts +1 -1
  127. package/dist/types/clipboard/paste.d.ts +1 -1
  128. package/dist/types/convenience/click.d.ts +1 -1
  129. package/dist/types/convenience/hover.d.ts +1 -1
  130. package/dist/types/document/UI.d.ts +42 -0
  131. package/dist/types/{utils/focus → document}/copySelection.d.ts +0 -0
  132. package/dist/types/document/getValueOrTextContent.d.ts +1 -0
  133. package/dist/types/document/index.d.ts +5 -10
  134. package/dist/types/document/interceptor.d.ts +3 -0
  135. package/dist/types/document/prepareDocument.d.ts +8 -0
  136. package/dist/types/document/trackValue.d.ts +17 -0
  137. package/dist/types/event/behavior/registry.d.ts +2 -2
  138. package/dist/types/event/dispatchEvent.d.ts +5 -2
  139. package/dist/types/event/focus.d.ts +5 -0
  140. package/dist/types/event/index.d.ts +6 -4
  141. package/dist/types/event/input.d.ts +2 -0
  142. package/dist/types/event/radio.d.ts +4 -0
  143. package/dist/types/event/selection/getInputRange.d.ts +5 -0
  144. package/dist/types/event/selection/getTargetTypeAndSelection.d.ts +10 -0
  145. package/dist/types/event/selection/index.d.ts +15 -0
  146. package/dist/types/event/selection/modifySelection.d.ts +8 -0
  147. package/dist/types/event/selection/modifySelectionPerMouse.d.ts +7 -0
  148. package/dist/types/event/selection/moveSelection.d.ts +4 -0
  149. package/dist/types/{utils/focus → event/selection}/resolveCaretPosition.d.ts +0 -0
  150. package/dist/types/{utils/focus → event/selection}/selectAll.d.ts +0 -0
  151. package/dist/types/event/selection/setSelection.d.ts +10 -0
  152. package/dist/types/event/selection/setSelectionPerMouse.d.ts +8 -0
  153. package/dist/types/event/selection/setSelectionRange.d.ts +6 -0
  154. package/dist/types/event/selection/updateSelectionOnFocus.d.ts +5 -0
  155. package/dist/types/keyboard/index.d.ts +2 -2
  156. package/dist/types/options.d.ts +0 -8
  157. package/dist/types/pointer/index.d.ts +3 -3
  158. package/dist/types/setup/directApi.d.ts +1 -1
  159. package/dist/types/setup/index.d.ts +2 -15
  160. package/dist/types/setup/setup.d.ts +25 -7
  161. package/dist/types/system/keyboard.d.ts +3 -3
  162. package/dist/types/system/pointer/buttons.d.ts +1 -1
  163. package/dist/types/system/pointer/index.d.ts +7 -25
  164. package/dist/types/system/pointer/mouse.d.ts +5 -5
  165. package/dist/types/system/pointer/pointer.d.ts +7 -7
  166. package/dist/types/system/pointer/shared.d.ts +20 -0
  167. package/dist/types/utility/clear.d.ts +1 -1
  168. package/dist/types/utility/selectOptions.d.ts +1 -1
  169. package/dist/types/utility/type.d.ts +3 -3
  170. package/dist/types/utility/upload.d.ts +1 -1
  171. package/dist/types/utils/click/isClickableInput.d.ts +2 -2
  172. package/dist/types/utils/edit/isEditable.d.ts +5 -6
  173. package/dist/types/utils/edit/maxLength.d.ts +14 -1
  174. package/dist/types/utils/edit/{isValidDateOrTimeValue.d.ts → timeValue.d.ts} +1 -0
  175. package/dist/types/utils/focus/selection.d.ts +4 -69
  176. package/dist/types/utils/index.d.ts +2 -9
  177. package/dist/types/utils/misc/level.d.ts +4 -13
  178. package/dist/types/utils/misc/wait.d.ts +2 -2
  179. package/dist/types/utils/pointer/cssPointerEvents.d.ts +4 -4
  180. package/package.json +3 -2
  181. package/dist/cjs/document/setRangeText.js +0 -21
  182. package/dist/cjs/document/value.js +0 -127
  183. package/dist/cjs/setup/config.js +0 -7
  184. package/dist/cjs/utils/edit/getValue.js +0 -35
  185. package/dist/cjs/utils/edit/isValidDateOrTimeValue.js +0 -11
  186. package/dist/cjs/utils/focus/blur.js +0 -16
  187. package/dist/cjs/utils/focus/copySelection.js +0 -46
  188. package/dist/cjs/utils/focus/focus.js +0 -29
  189. package/dist/cjs/utils/focus/selectAll.js +0 -56
  190. package/dist/cjs/utils/misc/eventWrapper.js +0 -15
  191. package/dist/esm/document/setRangeText.js +0 -17
  192. package/dist/esm/setup/config.js +0 -3
  193. package/dist/esm/utils/edit/getValue.js +0 -31
  194. package/dist/esm/utils/edit/isValidDateOrTimeValue.js +0 -7
  195. package/dist/esm/utils/focus/blur.js +0 -12
  196. package/dist/esm/utils/focus/copySelection.js +0 -42
  197. package/dist/esm/utils/focus/focus.js +0 -25
  198. package/dist/esm/utils/misc/eventWrapper.js +0 -11
  199. package/dist/types/document/selection.d.ts +0 -29
  200. package/dist/types/document/setRangeText.d.ts +0 -1
  201. package/dist/types/document/value.d.ts +0 -26
  202. package/dist/types/setup/config.d.ts +0 -6
  203. package/dist/types/utils/edit/buildTimeValue.d.ts +0 -1
  204. package/dist/types/utils/edit/getValue.d.ts +0 -1
  205. package/dist/types/utils/edit/input.d.ts +0 -2
  206. package/dist/types/utils/edit/walkRadio.d.ts +0 -4
  207. package/dist/types/utils/focus/blur.d.ts +0 -2
  208. package/dist/types/utils/focus/focus.d.ts +0 -5
  209. package/dist/types/utils/misc/eventWrapper.d.ts +0 -1
@@ -1,25 +1,23 @@
1
1
  import { getConfig } from '@testing-library/dom';
2
2
  import '../utils/click/isClickableInput.js';
3
3
  import '../utils/dataTransfer/Clipboard.js';
4
- import '../event/eventMap.js';
5
- import '../event/behavior/click.js';
6
- import '../event/behavior/cut.js';
7
- import '../event/behavior/keydown.js';
8
- import '../event/behavior/keypress.js';
9
- import '../event/behavior/keyup.js';
10
- import '../event/behavior/paste.js';
11
- import '../utils/edit/maxLength.js';
12
4
  import '../utils/edit/isEditable.js';
13
- import { focus } from '../utils/focus/focus.js';
14
- import '@testing-library/dom/dist/helpers.js';
15
- import { isDisabled } from '../utils/misc/isDisabled.js';
5
+ import '../utils/edit/maxLength.js';
16
6
  import { isElementType } from '../utils/misc/isElementType.js';
7
+ import { isDisabled } from '../utils/misc/isDisabled.js';
8
+ import '@testing-library/dom/dist/helpers.js';
17
9
  import '../utils/keyDef/readNextDescriptor.js';
18
10
  import '../utils/misc/level.js';
19
11
  import { wait } from '../utils/misc/wait.js';
20
12
  import { hasPointerEvents } from '../utils/pointer/cssPointerEvents.js';
21
- import '../setup/index.js';
22
- import { Config } from '../setup/config.js';
13
+ import '../event/behavior/click.js';
14
+ import '../event/behavior/cut.js';
15
+ import '../event/behavior/keydown.js';
16
+ import '../event/behavior/keypress.js';
17
+ import '../event/behavior/keyup.js';
18
+ import '../event/behavior/paste.js';
19
+ import '../event/eventMap.js';
20
+ import { focusElement } from '../event/focus.js';
23
21
 
24
22
  async function selectOptions(select, values) {
25
23
  return selectOptionsBase.call(this, true, select, values);
@@ -60,7 +58,7 @@ async function selectOptionsBase(newValue, select, values) {
60
58
  if (isElementType(select, 'select')) {
61
59
  if (select.multiple) {
62
60
  for (const option of selectedOptions){
63
- const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(this[Config], option);
61
+ const withPointerEvents = this.config.pointerEventsCheck === 0 ? true : hasPointerEvents(this, option);
64
62
  // events fired for multiple select are weird. Can't use hover...
65
63
  if (withPointerEvents) {
66
64
  this.dispatchUIEvent(option, 'pointerover');
@@ -72,7 +70,7 @@ async function selectOptionsBase(newValue, select, values) {
72
70
  this.dispatchUIEvent(option, 'pointerdown');
73
71
  this.dispatchUIEvent(option, 'mousedown');
74
72
  }
75
- focus(select);
73
+ focusElement(select);
76
74
  if (withPointerEvents) {
77
75
  this.dispatchUIEvent(option, 'pointerup');
78
76
  this.dispatchUIEvent(option, 'mouseup');
@@ -81,15 +79,15 @@ async function selectOptionsBase(newValue, select, values) {
81
79
  if (withPointerEvents) {
82
80
  this.dispatchUIEvent(option, 'click');
83
81
  }
84
- await wait(this[Config]);
82
+ await wait(this.config);
85
83
  }
86
84
  } else if (selectedOptions.length === 1) {
87
- const withPointerEvents1 = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(this[Config], select);
85
+ const withPointerEvents1 = this.config.pointerEventsCheck === 0 ? true : hasPointerEvents(this, select);
88
86
  // the click to open the select options
89
87
  if (withPointerEvents1) {
90
88
  await this.click(select);
91
89
  } else {
92
- focus(select);
90
+ focusElement(select);
93
91
  }
94
92
  selectOption(selectedOptions[0]);
95
93
  if (withPointerEvents1) {
@@ -103,7 +101,7 @@ async function selectOptionsBase(newValue, select, values) {
103
101
  this.dispatchUIEvent(select, 'mouseup');
104
102
  this.dispatchUIEvent(select, 'click');
105
103
  }
106
- await wait(this[Config]);
104
+ await wait(this.config);
107
105
  } else {
108
106
  throw getConfig().getElementError(`Cannot select multiple options on a non-multiple select`, select);
109
107
  }
@@ -1,24 +1,15 @@
1
+ import { releaseAllKeys } from '../keyboard/index.js';
1
2
  import '../utils/click/isClickableInput.js';
2
3
  import '../utils/dataTransfer/Clipboard.js';
3
- import '../event/eventMap.js';
4
- import '../event/behavior/click.js';
5
- import '../event/behavior/cut.js';
6
- import '../event/behavior/keydown.js';
7
- import '../event/behavior/keypress.js';
8
- import '../event/behavior/keyup.js';
9
- import '../event/behavior/paste.js';
10
- import '@testing-library/dom';
11
- import '../utils/edit/maxLength.js';
12
4
  import '../utils/edit/isEditable.js';
13
- import { setSelectionRange } from '../utils/focus/selection.js';
5
+ import '../utils/edit/maxLength.js';
14
6
  import '@testing-library/dom/dist/helpers.js';
15
7
  import '../utils/keyDef/readNextDescriptor.js';
16
8
  import '../utils/misc/level.js';
17
9
  import '../options.js';
18
- import { releaseAllKeys } from '../keyboard/index.js';
19
- import { Config } from '../setup/config.js';
10
+ import { setSelectionRange } from '../event/selection/setSelectionRange.js';
20
11
 
21
- async function type(element, text, { skipClick =this[Config].skipClick , skipAutoClose =this[Config].skipAutoClose , initialSelectionStart , initialSelectionEnd } = {}) {
12
+ async function type(element, text, { skipClick =this.config.skipClick , skipAutoClose =this.config.skipAutoClose , initialSelectionStart , initialSelectionEnd } = {}) {
22
13
  // TODO: properly type guard
23
14
  // we use this workaround for now to prevent changing behavior
24
15
  if (element.disabled) return;
@@ -30,7 +21,7 @@ async function type(element, text, { skipClick =this[Config].skipClick , skipAut
30
21
  }
31
22
  await this.keyboard(text);
32
23
  if (!skipAutoClose) {
33
- await releaseAllKeys(this[Config]);
24
+ await releaseAllKeys(this);
34
25
  }
35
26
  }
36
27
 
@@ -1,25 +1,15 @@
1
1
  import '../utils/click/isClickableInput.js';
2
2
  import { createFileList } from '../utils/dataTransfer/FileList.js';
3
3
  import '../utils/dataTransfer/Clipboard.js';
4
- import '../event/eventMap.js';
5
- import '../event/behavior/click.js';
6
- import '../event/behavior/cut.js';
7
- import '../event/behavior/keydown.js';
8
- import '../event/behavior/keypress.js';
9
- import '../event/behavior/keyup.js';
10
- import '../event/behavior/paste.js';
11
- import '@testing-library/dom';
12
- import '../utils/edit/maxLength.js';
13
4
  import '../utils/edit/isEditable.js';
5
+ import '../utils/edit/maxLength.js';
14
6
  import { setFiles } from '../utils/edit/setFiles.js';
15
- import { isDisabled } from '../utils/misc/isDisabled.js';
16
7
  import { isElementType } from '../utils/misc/isElementType.js';
8
+ import { isDisabled } from '../utils/misc/isDisabled.js';
17
9
  import { getWindow } from '../utils/misc/getWindow.js';
18
10
  import '../utils/keyDef/readNextDescriptor.js';
19
11
  import '../utils/misc/level.js';
20
12
  import '../options.js';
21
- import '../setup/index.js';
22
- import { Config } from '../setup/config.js';
23
13
 
24
14
  async function upload(element, fileOrFiles) {
25
15
  const input = isElementType(element, 'label') ? element.control : element;
@@ -31,7 +21,7 @@ async function upload(element, fileOrFiles) {
31
21
  if (isDisabled(element)) return;
32
22
  const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [
33
23
  fileOrFiles
34
- ]).filter((file)=>!this[Config].applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? undefined : 1);
24
+ ]).filter((file)=>!this.config.applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? undefined : 1);
35
25
  const fileDialog = ()=>{
36
26
  var ref;
37
27
  // do not fire an input event if the file selection does not change
@@ -1,20 +1,6 @@
1
- import '../click/isClickableInput.js';
1
+ import { getWindow } from '../misc/getWindow.js';
2
2
  import { readBlobText } from './Blob.js';
3
3
  import { createDataTransfer, getBlobFromDataTransferItem } from './DataTransfer.js';
4
- import '../../event/eventMap.js';
5
- import '../../event/behavior/click.js';
6
- import '../../event/behavior/cut.js';
7
- import '../../event/behavior/keydown.js';
8
- import '../../event/behavior/keypress.js';
9
- import '../../event/behavior/keyup.js';
10
- import '../../event/behavior/paste.js';
11
- import '@testing-library/dom';
12
- import '../edit/maxLength.js';
13
- import '../edit/isEditable.js';
14
- import { getWindow } from '../misc/getWindow.js';
15
- import '../keyDef/readNextDescriptor.js';
16
- import '../misc/level.js';
17
- import '../../options.js';
18
4
 
19
5
  // Clipboard is not available in jsdom
20
6
  // MDN lists string|Blob|Promise<Blob|string> as possible types in ClipboardItemData
@@ -2,9 +2,7 @@ import { isElementType } from '../misc/isElementType.js';
2
2
  import { isContentEditable } from './isContentEditable.js';
3
3
 
4
4
  function isEditable(element) {
5
- return isEditableInput(element) || isElementType(element, 'textarea', {
6
- readOnly: false
7
- }) || isContentEditable(element);
5
+ return isEditableInputOrTextArea(element) && !element.readOnly || isContentEditable(element);
8
6
  }
9
7
  var editableInputTypes;
10
8
  (function(editableInputTypes) {
@@ -21,10 +19,8 @@ var editableInputTypes;
21
19
  editableInputTypes['url'] = 'url';
22
20
  editableInputTypes['week'] = 'week';
23
21
  })(editableInputTypes || (editableInputTypes = {}));
24
- function isEditableInput(element) {
25
- return isElementType(element, 'input', {
26
- readOnly: false
27
- }) && Boolean(editableInputTypes[element.type]);
22
+ function isEditableInputOrTextArea(element) {
23
+ return isElementType(element, 'textarea') || isElementType(element, 'input') && element.type in editableInputTypes;
28
24
  }
29
25
 
30
- export { editableInputTypes, isEditable, isEditableInput };
26
+ export { isEditable, isEditableInputOrTextArea };
@@ -1,5 +1,4 @@
1
1
  import { isElementType } from '../misc/isElementType.js';
2
- import { getValue } from './getValue.js';
3
2
 
4
3
  var maxLengthSupportedTypes;
5
4
  (function(maxLengthSupportedTypes) {
@@ -10,26 +9,15 @@ var maxLengthSupportedTypes;
10
9
  maxLengthSupportedTypes['text'] = 'text';
11
10
  maxLengthSupportedTypes['url'] = 'url';
12
11
  })(maxLengthSupportedTypes || (maxLengthSupportedTypes = {}));
13
- function getSpaceUntilMaxLength(element) {
14
- const value = getValue(element);
15
- /* istanbul ignore if */ if (value === null) {
16
- return undefined;
17
- }
18
- const maxLength = getSanitizedMaxLength(element);
19
- return maxLength ? maxLength - value.length : undefined;
20
- }
21
12
  // can't use .maxLength property because of a jsdom bug:
22
13
  // https://github.com/jsdom/jsdom/issues/2927
23
- function getSanitizedMaxLength(element) {
24
- if (!supportsMaxLength(element)) {
25
- return undefined;
26
- }
14
+ function getMaxLength(element) {
27
15
  var ref;
28
16
  const attr = (ref = element.getAttribute('maxlength')) !== null && ref !== void 0 ? ref : '';
29
17
  return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : undefined;
30
18
  }
31
19
  function supportsMaxLength(element) {
32
- return isElementType(element, 'textarea') || isElementType(element, 'input') && Boolean(maxLengthSupportedTypes[element.type]);
20
+ return isElementType(element, 'textarea') || isElementType(element, 'input') && element.type in maxLengthSupportedTypes;
33
21
  }
34
22
 
35
- export { getSpaceUntilMaxLength };
23
+ export { getMaxLength, supportsMaxLength };
@@ -28,5 +28,10 @@ function build(onlyDigitsValue, index) {
28
28
  const validMinutes = Math.min(parsedMinutes, 59);
29
29
  return `${validHours.toString().padStart(2, '0')}:${validMinutes.toString().padStart(2, '0')}`;
30
30
  }
31
+ function isValidDateOrTimeValue(element, value) {
32
+ const clone = element.cloneNode();
33
+ clone.value = value;
34
+ return clone.value === value;
35
+ }
31
36
 
32
- export { buildTimeValue };
37
+ export { buildTimeValue, isValidDateOrTimeValue };
@@ -1,21 +1,5 @@
1
- import '../click/isClickableInput.js';
2
- import '../dataTransfer/Clipboard.js';
3
- import '../../event/eventMap.js';
4
- import '../../event/behavior/click.js';
5
- import '../../event/behavior/cut.js';
6
- import '../../event/behavior/keydown.js';
7
- import '../../event/behavior/keypress.js';
8
- import '../../event/behavior/keyup.js';
9
- import '../../event/behavior/paste.js';
10
- import '@testing-library/dom';
11
1
  import { isContentEditable } from '../edit/isContentEditable.js';
12
- import '../edit/maxLength.js';
13
- import '../edit/isEditable.js';
14
2
  import { isElementType } from '../misc/isElementType.js';
15
- import '@testing-library/dom/dist/helpers.js';
16
- import '../keyDef/readNextDescriptor.js';
17
- import '../misc/level.js';
18
- import '../../options.js';
19
3
 
20
4
  function getNextCursorPosition(node, offset, direction, inputType) {
21
5
  // The behavior at text node zero offset is inconsistent.
@@ -1,53 +1,11 @@
1
- import { isElementType } from '../misc/isElementType.js';
2
1
  import { isClickableInput } from '../click/isClickableInput.js';
3
- import '../dataTransfer/Clipboard.js';
4
- import { isContentEditable, getContentEditable } from '../edit/isContentEditable.js';
5
- import '../edit/maxLength.js';
6
- import { editableInputTypes } from '../edit/isEditable.js';
7
- import '@testing-library/dom';
8
- import '@testing-library/dom/dist/helpers.js';
9
- import { getNextCursorPosition } from './cursor.js';
10
- import { resolveCaretPosition } from './resolveCaretPosition.js';
11
- import '../keyDef/readNextDescriptor.js';
12
- import '../misc/level.js';
13
- import '../../options.js';
14
- import '../../event/eventMap.js';
15
- import '../../event/behavior/click.js';
16
- import '../../event/behavior/cut.js';
17
- import '../../event/behavior/keydown.js';
18
- import '../../event/behavior/keypress.js';
19
- import '../../event/behavior/keyup.js';
20
- import '../../event/behavior/paste.js';
21
- import { setUISelection, getUISelection } from '../../document/selection.js';
22
- import { getUIValue } from '../../document/value.js';
2
+ import { isEditableInputOrTextArea } from '../edit/isEditable.js';
23
3
 
24
- /**
25
- * Backward-compatible selection.
26
- *
27
- * Handles input elements and contenteditable if it only contains a single text node.
28
- */ function setSelectionRange(element, anchorOffset, focusOffset) {
29
- var ref;
30
- if (hasOwnSelection(element)) {
31
- return setSelection({
32
- focusNode: element,
33
- anchorOffset,
34
- focusOffset
35
- });
36
- }
37
- /* istanbul ignore else */ if (isContentEditable(element) && ((ref = element.firstChild) === null || ref === void 0 ? void 0 : ref.nodeType) === 3) {
38
- return setSelection({
39
- focusNode: element.firstChild,
40
- anchorOffset,
41
- focusOffset
42
- });
43
- }
44
- /* istanbul ignore next */ throw new Error('Not implemented. The result of this interaction is unreliable.');
45
- }
46
4
  /**
47
5
  * Determine if the element has its own selection implementation
48
6
  * and does not interact with the Document Selection API.
49
7
  */ function hasOwnSelection(node) {
50
- return isElement(node) && (isElementType(node, 'textarea') || isElementType(node, 'input') && node.type in editableInputTypes);
8
+ return isElement(node) && isEditableInputOrTextArea(node);
51
9
  }
52
10
  function hasNoSelection(node) {
53
11
  return isElement(node) && isClickableInput(node);
@@ -55,225 +13,5 @@ function hasNoSelection(node) {
55
13
  function isElement(node) {
56
14
  return node.nodeType === 1;
57
15
  }
58
- /**
59
- * Determine which selection logic and selection ranges to consider.
60
- */ function getTargetTypeAndSelection(node) {
61
- const element = getElement(node);
62
- if (element && hasOwnSelection(element)) {
63
- return {
64
- type: 'input',
65
- selection: getUISelection(element)
66
- };
67
- }
68
- const selection = element === null || element === void 0 ? void 0 : element.ownerDocument.getSelection();
69
- // It is possible to extend a single-range selection into a contenteditable.
70
- // This results in the range acting like a range outside of contenteditable.
71
- const isCE = getContentEditable(node) && (selection === null || selection === void 0 ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode);
72
- return {
73
- type: isCE ? 'contenteditable' : 'default',
74
- selection
75
- };
76
- }
77
- function getElement(node) {
78
- return node.nodeType === 1 ? node : node.parentElement;
79
- }
80
- /**
81
- * Reset the Document Selection when moving focus into an element
82
- * with own selection implementation.
83
- */ function updateSelectionOnFocus(element) {
84
- const selection = element.ownerDocument.getSelection();
85
- /* istanbul ignore if */ if (!(selection === null || selection === void 0 ? void 0 : selection.focusNode)) {
86
- return;
87
- }
88
- // If the focus moves inside an element with own selection implementation,
89
- // the document selection will be this element.
90
- // But if the focused element is inside a contenteditable,
91
- // 1) a collapsed selection will be retained.
92
- // 2) other selections will be replaced by a cursor
93
- // 2.a) at the start of the first child if it is a text node
94
- // 2.b) at the start of the contenteditable.
95
- if (hasOwnSelection(element)) {
96
- const contenteditable = getContentEditable(selection.focusNode);
97
- if (contenteditable) {
98
- if (!selection.isCollapsed) {
99
- var ref;
100
- const focusNode = ((ref = contenteditable.firstChild) === null || ref === void 0 ? void 0 : ref.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
101
- selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
102
- }
103
- } else {
104
- selection.setBaseAndExtent(element, 0, element, 0);
105
- }
106
- }
107
- }
108
- /**
109
- * Get the range that would be overwritten by input.
110
- */ function getInputRange(focusNode) {
111
- const typeAndSelection = getTargetTypeAndSelection(focusNode);
112
- if (typeAndSelection.type === 'input') {
113
- return typeAndSelection.selection;
114
- } else if (typeAndSelection.type === 'contenteditable') {
115
- var ref;
116
- // Multi-range on contenteditable edits the first selection instead of the last
117
- return (ref = typeAndSelection.selection) === null || ref === void 0 ? void 0 : ref.getRangeAt(0);
118
- }
119
- }
120
- /**
121
- * Extend/shrink the selection like with Shift+Arrows or Shift+Mouse
122
- */ function modifySelection({ focusNode , focusOffset }) {
123
- var ref, ref1;
124
- const typeAndSelection = getTargetTypeAndSelection(focusNode);
125
- if (typeAndSelection.type === 'input') {
126
- return setUISelection(focusNode, {
127
- anchorOffset: typeAndSelection.selection.anchorOffset,
128
- focusOffset
129
- }, 'modify');
130
- }
131
- (ref1 = (ref = focusNode.ownerDocument) === null || ref === void 0 ? void 0 : ref.getSelection()) === null || ref1 === void 0 ? void 0 : ref1.extend(focusNode, focusOffset);
132
- }
133
- /**
134
- * Set the selection
135
- */ function setSelection({ focusNode , focusOffset , anchorNode =focusNode , anchorOffset =focusOffset }) {
136
- var ref, ref1;
137
- const typeAndSelection = getTargetTypeAndSelection(focusNode);
138
- if (typeAndSelection.type === 'input') {
139
- return setUISelection(focusNode, {
140
- anchorOffset,
141
- focusOffset
142
- });
143
- }
144
- (ref1 = (ref = anchorNode.ownerDocument) === null || ref === void 0 ? void 0 : ref.getSelection()) === null || ref1 === void 0 ? void 0 : ref1.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
145
- }
146
- /**
147
- * Move the selection
148
- */ function moveSelection(node, direction) {
149
- // TODO: implement shift
150
- if (hasOwnSelection(node)) {
151
- const selection = getUISelection(node);
152
- setSelection({
153
- focusNode: node,
154
- focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + direction : direction < 0 ? selection.startOffset : selection.endOffset
155
- });
156
- } else {
157
- const selection1 = node.ownerDocument.getSelection();
158
- if (!(selection1 === null || selection1 === void 0 ? void 0 : selection1.focusNode)) {
159
- return;
160
- }
161
- if (selection1.isCollapsed) {
162
- const nextPosition = getNextCursorPosition(selection1.focusNode, selection1.focusOffset, direction);
163
- if (nextPosition) {
164
- setSelection({
165
- focusNode: nextPosition.node,
166
- focusOffset: nextPosition.offset
167
- });
168
- }
169
- } else {
170
- selection1[direction < 0 ? 'collapseToStart' : 'collapseToEnd']();
171
- }
172
- }
173
- }
174
- function setSelectionPerMouseDown({ document , target , clickCount , node , offset }) {
175
- if (hasNoSelection(target)) {
176
- return;
177
- }
178
- const targetHasOwnSelection = hasOwnSelection(target);
179
- // On non-input elements the text selection per multiple click
180
- // can extend beyond the target boundaries.
181
- // The exact mechanism what is considered in the same line is unclear.
182
- // Looks it might be every inline element.
183
- // TODO: Check what might be considered part of the same line of text.
184
- const text = String(targetHasOwnSelection ? getUIValue(target) : target.textContent);
185
- const [start, end] = node ? // which elements might be considered in the same line of text.
186
- // TODO: support expanding initial range on multiple clicks if node is given
187
- [
188
- offset,
189
- offset
190
- ] : getTextRange(text, offset, clickCount);
191
- // TODO: implement modifying selection per shift/ctrl+mouse
192
- if (targetHasOwnSelection) {
193
- setUISelection(target, {
194
- anchorOffset: start !== null && start !== void 0 ? start : text.length,
195
- focusOffset: end !== null && end !== void 0 ? end : text.length
196
- });
197
- return {
198
- node: target,
199
- start: start !== null && start !== void 0 ? start : 0,
200
- end: end !== null && end !== void 0 ? end : text.length
201
- };
202
- } else {
203
- const { node: startNode , offset: startOffset } = resolveCaretPosition({
204
- target,
205
- node,
206
- offset: start
207
- });
208
- const { node: endNode , offset: endOffset } = resolveCaretPosition({
209
- target,
210
- node,
211
- offset: end
212
- });
213
- const range = target.ownerDocument.createRange();
214
- try {
215
- range.setStart(startNode, startOffset);
216
- range.setEnd(endNode, endOffset);
217
- } catch (e) {
218
- throw new Error('The given offset is out of bounds.');
219
- }
220
- const selection = document.getSelection();
221
- selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
222
- selection === null || selection === void 0 ? void 0 : selection.addRange(range.cloneRange());
223
- return range;
224
- }
225
- }
226
- function getTextRange(text, pos, clickCount) {
227
- if (clickCount % 3 === 1 || text.length === 0) {
228
- return [
229
- pos,
230
- pos
231
- ];
232
- }
233
- const textPos = pos !== null && pos !== void 0 ? pos : text.length;
234
- if (clickCount % 3 === 2) {
235
- return [
236
- textPos - text.substr(0, pos).match(/(\w+|\s+|\W)?$/)[0].length,
237
- pos === undefined ? pos : pos + text.substr(pos).match(/^(\w+|\s+|\W)?/)[0].length,
238
- ];
239
- }
240
- // triple click
241
- return [
242
- textPos - text.substr(0, pos).match(/[^\r\n]*$/)[0].length,
243
- pos === undefined ? pos : pos + text.substr(pos).match(/^[^\r\n]*/)[0].length,
244
- ];
245
- }
246
- function modifySelectionPerMouseMove(selectionRange, { document , target , node , offset }) {
247
- const selectionFocus = resolveCaretPosition({
248
- target,
249
- node,
250
- offset
251
- });
252
- if ('node' in selectionRange) {
253
- // When the mouse is dragged outside of an input/textarea,
254
- // the selection is extended to the beginning or end of the input
255
- // depending on pointer position.
256
- // TODO: extend selection according to pointer position
257
- /* istanbul ignore else */ if (selectionFocus.node === selectionRange.node) {
258
- const anchorOffset = selectionFocus.offset < selectionRange.start ? selectionRange.end : selectionRange.start;
259
- const focusOffset = selectionFocus.offset > selectionRange.end || selectionFocus.offset < selectionRange.start ? selectionFocus.offset : selectionRange.end;
260
- setUISelection(selectionRange.node, {
261
- anchorOffset,
262
- focusOffset
263
- });
264
- }
265
- } else {
266
- const range = selectionRange.cloneRange();
267
- const cmp = range.comparePoint(selectionFocus.node, selectionFocus.offset);
268
- if (cmp < 0) {
269
- range.setStart(selectionFocus.node, selectionFocus.offset);
270
- } else if (cmp > 0) {
271
- range.setEnd(selectionFocus.node, selectionFocus.offset);
272
- }
273
- const selection = document.getSelection();
274
- selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
275
- selection === null || selection === void 0 ? void 0 : selection.addRange(range.cloneRange());
276
- }
277
- }
278
16
 
279
- export { getInputRange, hasNoSelection, hasOwnSelection, modifySelection, modifySelectionPerMouseMove, moveSelection, setSelection, setSelectionPerMouseDown, setSelectionRange, updateSelectionOnFocus };
17
+ export { hasNoSelection, hasOwnSelection };
@@ -3,26 +3,19 @@ export { readBlobText } from './dataTransfer/Blob.js';
3
3
  export { createDataTransfer, getBlobFromDataTransferItem } from './dataTransfer/DataTransfer.js';
4
4
  export { createFileList } from './dataTransfer/FileList.js';
5
5
  export { attachClipboardStubToView, createClipboardItem, detachClipboardStubFromView, readDataTransferFromClipboard, resetClipboardStubOnView, writeDataTransferToClipboard } from './dataTransfer/Clipboard.js';
6
- export { getValue } from './edit/getValue.js';
7
- export { input } from './edit/input.js';
6
+ export { buildTimeValue, isValidDateOrTimeValue } from './edit/timeValue.js';
8
7
  export { getContentEditable, isContentEditable } from './edit/isContentEditable.js';
9
- export { editableInputTypes, isEditable, isEditableInput } from './edit/isEditable.js';
8
+ export { isEditable, isEditableInputOrTextArea } from './edit/isEditable.js';
9
+ export { getMaxLength, supportsMaxLength } from './edit/maxLength.js';
10
10
  export { setFiles } from './edit/setFiles.js';
11
- export { walkRadio } from './edit/walkRadio.js';
12
- export { blur } from './focus/blur.js';
13
- export { copySelection } from './focus/copySelection.js';
14
11
  export { getNextCursorPosition } from './focus/cursor.js';
15
- export { focus } from './focus/focus.js';
16
12
  export { getActiveElement, getActiveElementOrBody } from './focus/getActiveElement.js';
17
13
  export { getTabDestination } from './focus/getTabDestination.js';
18
14
  export { isFocusable } from './focus/isFocusable.js';
19
- export { isAllSelected, selectAll } from './focus/selectAll.js';
20
- export { resolveCaretPosition } from './focus/resolveCaretPosition.js';
21
- export { getInputRange, hasNoSelection, hasOwnSelection, modifySelection, modifySelectionPerMouseMove, moveSelection, setSelection, setSelectionPerMouseDown, setSelectionRange, updateSelectionOnFocus } from './focus/selection.js';
15
+ export { hasNoSelection, hasOwnSelection } from './focus/selection.js';
22
16
  export { FOCUSABLE_SELECTOR } from './focus/selector.js';
23
17
  export { readNextDescriptor } from './keyDef/readNextDescriptor.js';
24
18
  export { cloneEvent } from './misc/cloneEvent.js';
25
- export { eventWrapper } from './misc/eventWrapper.js';
26
19
  export { findClosest } from './misc/findClosest.js';
27
20
  export { getDocumentFromNode } from './misc/getDocumentFromNode.js';
28
21
  export { getTreeDiff } from './misc/getTreeDiff.js';
@@ -1,18 +1,13 @@
1
- var _config, _Level;
2
1
  var ApiLevel;
3
2
  (function(ApiLevel) {
4
3
  ApiLevel[ApiLevel["Trigger"] = 2] = "Trigger";
5
4
  ApiLevel[ApiLevel["Call"] = 1] = "Call";
6
5
  })(ApiLevel || (ApiLevel = {}));
7
- const Level = Symbol('Api level refs');
8
- function setLevelRef(config, level) {
9
- var ref;
10
- (ref = (_config = config)[_Level = Level]) !== null && ref !== void 0 ? ref : _config[_Level] = {};
11
- config[Level][level] = {};
6
+ function setLevelRef(instance, level) {
7
+ instance.levelRefs[level] = {};
12
8
  }
13
- function getLevelRef(config, level) {
14
- var ref;
15
- return (ref = config[Level]) === null || ref === void 0 ? void 0 : ref[level];
9
+ function getLevelRef(instance, level) {
10
+ return instance.levelRefs[level];
16
11
  }
17
12
 
18
13
  export { ApiLevel, getLevelRef, setLevelRef };