@testing-library/user-event 13.4.2 → 14.0.0-alpha.11

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 (125) hide show
  1. package/README.md +4 -0
  2. package/dist/clear.d.ts +2 -2
  3. package/dist/clear.js +14 -29
  4. package/dist/click.d.ts +4 -3
  5. package/dist/click.js +29 -143
  6. package/dist/document/index.d.ts +10 -0
  7. package/dist/document/index.js +100 -0
  8. package/dist/document/interceptor.d.ts +15 -0
  9. package/dist/document/interceptor.js +37 -0
  10. package/dist/document/selection.d.ts +27 -0
  11. package/dist/document/selection.js +90 -0
  12. package/dist/document/value.d.ts +18 -0
  13. package/dist/document/value.js +77 -0
  14. package/dist/hover.d.ts +3 -3
  15. package/dist/hover.js +15 -57
  16. package/dist/index.d.ts +3 -22
  17. package/dist/index.js +3 -36
  18. package/dist/keyboard/getEventProps.d.ts +0 -2
  19. package/dist/keyboard/getEventProps.js +1 -7
  20. package/dist/keyboard/getNextKeyDef.d.ts +3 -0
  21. package/dist/keyboard/getNextKeyDef.js +59 -87
  22. package/dist/keyboard/index.d.ts +1 -1
  23. package/dist/keyboard/index.js +4 -8
  24. package/dist/keyboard/keyMap.js +26 -46
  25. package/dist/keyboard/keyboardImplementation.js +35 -19
  26. package/dist/keyboard/plugins/arrow.js +7 -12
  27. package/dist/keyboard/plugins/character.js +29 -57
  28. package/dist/keyboard/plugins/combination.d.ts +5 -0
  29. package/dist/keyboard/plugins/combination.js +17 -0
  30. package/dist/keyboard/plugins/control.js +5 -16
  31. package/dist/keyboard/plugins/functional.js +23 -14
  32. package/dist/keyboard/plugins/index.d.ts +0 -1
  33. package/dist/keyboard/plugins/index.js +4 -13
  34. package/dist/keyboard/shared/index.d.ts +0 -2
  35. package/dist/keyboard/shared/index.js +0 -26
  36. package/dist/keyboard/types.d.ts +8 -2
  37. package/dist/paste.d.ts +3 -2
  38. package/dist/paste.js +8 -15
  39. package/dist/pointer/index.d.ts +18 -0
  40. package/dist/pointer/index.js +90 -0
  41. package/dist/pointer/keyMap.d.ts +2 -0
  42. package/dist/pointer/keyMap.js +29 -0
  43. package/dist/pointer/parseKeyDef.d.ts +6 -0
  44. package/dist/pointer/parseKeyDef.js +36 -0
  45. package/dist/pointer/pointerAction.d.ts +6 -0
  46. package/dist/pointer/pointerAction.js +52 -0
  47. package/dist/pointer/pointerMove.d.ts +5 -0
  48. package/dist/pointer/pointerMove.js +136 -0
  49. package/dist/pointer/pointerPress.d.ts +7 -0
  50. package/dist/pointer/pointerPress.js +330 -0
  51. package/dist/pointer/resolveSelectionTarget.d.ts +5 -0
  52. package/dist/pointer/resolveSelectionTarget.js +75 -0
  53. package/dist/pointer/types.d.ts +72 -0
  54. package/dist/pointer/types.js +1 -0
  55. package/dist/selectOptions.d.ts +4 -0
  56. package/dist/{select-options.js → selectOptions.js} +18 -20
  57. package/dist/setup.d.ts +92 -0
  58. package/dist/setup.js +203 -0
  59. package/dist/tab.d.ts +3 -4
  60. package/dist/tab.js +3 -136
  61. package/dist/type.d.ts +14 -0
  62. package/dist/type.js +74 -0
  63. package/dist/upload.d.ts +4 -3
  64. package/dist/upload.js +3 -9
  65. package/dist/utils/edit/calculateNewValue.d.ts +12 -5
  66. package/dist/utils/edit/calculateNewValue.js +19 -21
  67. package/dist/utils/edit/editInputElement.d.ts +16 -0
  68. package/dist/utils/edit/editInputElement.js +53 -0
  69. package/dist/utils/edit/getValue.d.ts +1 -1
  70. package/dist/utils/edit/getValue.js +3 -1
  71. package/dist/utils/edit/isContentEditable.d.ts +4 -0
  72. package/dist/utils/edit/isContentEditable.js +14 -0
  73. package/dist/utils/edit/isEditable.d.ts +1 -0
  74. package/dist/utils/edit/prepareInput.d.ts +7 -0
  75. package/dist/utils/edit/prepareInput.js +77 -0
  76. package/dist/{blur.d.ts → utils/focus/blur.d.ts} +0 -0
  77. package/dist/utils/focus/blur.js +19 -0
  78. package/dist/{focus.d.ts → utils/focus/focus.d.ts} +0 -0
  79. package/dist/utils/focus/focus.js +22 -0
  80. package/dist/utils/focus/getTabDestination.d.ts +1 -0
  81. package/dist/utils/focus/getTabDestination.js +71 -0
  82. package/dist/utils/focus/isFocusable.js +1 -3
  83. package/dist/utils/focus/selectAll.d.ts +5 -0
  84. package/dist/utils/focus/selectAll.js +51 -0
  85. package/dist/utils/focus/selection.d.ts +42 -0
  86. package/dist/utils/focus/selection.js +190 -0
  87. package/dist/utils/index.d.ts +12 -6
  88. package/dist/utils/index.js +132 -54
  89. package/dist/utils/keyDef/readNextDescriptor.d.ts +19 -0
  90. package/dist/utils/keyDef/readNextDescriptor.js +102 -0
  91. package/dist/utils/misc/findClosest.d.ts +1 -0
  92. package/dist/utils/misc/findClosest.js +20 -0
  93. package/dist/utils/misc/isDescendantOrSelf.d.ts +1 -0
  94. package/dist/utils/misc/isDescendantOrSelf.js +20 -0
  95. package/dist/utils/pointer/firePointerEvents.d.ts +25 -0
  96. package/dist/utils/pointer/firePointerEvents.js +112 -0
  97. package/dist/utils/pointer/mouseButtons.d.ts +12 -0
  98. package/dist/utils/pointer/mouseButtons.js +45 -0
  99. package/package.json +4 -3
  100. package/dist/blur.js +0 -15
  101. package/dist/dom-helpers.d.ts +0 -3
  102. package/dist/focus.js +0 -15
  103. package/dist/keyboard/shared/carryValue.d.ts +0 -2
  104. package/dist/keyboard/shared/carryValue.js +0 -13
  105. package/dist/keyboard/shared/fireInputEvent.d.ts +0 -17
  106. package/dist/keyboard/shared/fireInputEvent.js +0 -110
  107. package/dist/keyboard/specialCharMap.d.ts +0 -22
  108. package/dist/keyboard/specialCharMap.js +0 -30
  109. package/dist/select-options.d.ts +0 -4
  110. package/dist/type/index.d.ts +0 -7
  111. package/dist/type/index.js +0 -33
  112. package/dist/type/typeImplementation.d.ts +0 -10
  113. package/dist/type/typeImplementation.js +0 -64
  114. package/dist/utils/click/getMouseEventOptions.d.ts +0 -31
  115. package/dist/utils/click/getMouseEventOptions.js +0 -61
  116. package/dist/utils/edit/cursorPosition.d.ts +0 -2
  117. package/dist/utils/edit/cursorPosition.js +0 -35
  118. package/dist/utils/edit/hasUnreliableEmptyValue.d.ts +0 -10
  119. package/dist/utils/edit/hasUnreliableEmptyValue.js +0 -21
  120. package/dist/utils/edit/selectionRange.d.ts +0 -16
  121. package/dist/utils/edit/selectionRange.js +0 -104
  122. package/dist/utils/misc/isDocument.d.ts +0 -1
  123. package/dist/utils/misc/isDocument.js +0 -10
  124. package/dist/utils/misc/isLabelWithInternallyDisabledControl.d.ts +0 -1
  125. package/dist/utils/misc/isLabelWithInternallyDisabledControl.js +0 -22
@@ -1,61 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getMouseEventOptions = getMouseEventOptions;
7
-
8
- function isMousePressEvent(event) {
9
- return event === 'mousedown' || event === 'mouseup' || event === 'click' || event === 'dblclick';
10
- } // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
11
-
12
-
13
- const BUTTONS_NAMES = {
14
- none: 0,
15
- primary: 1,
16
- secondary: 2,
17
- auxiliary: 4
18
- }; // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
19
-
20
- const BUTTON_NAMES = {
21
- primary: 0,
22
- auxiliary: 1,
23
- secondary: 2
24
- };
25
-
26
- function translateButtonNumber(value, from) {
27
- var _Object$entries$find;
28
-
29
- const [mapIn, mapOut] = from === 'button' ? [BUTTON_NAMES, BUTTONS_NAMES] : [BUTTONS_NAMES, BUTTON_NAMES];
30
- const name = (_Object$entries$find = Object.entries(mapIn).find(([, i]) => i === value)) == null ? void 0 : _Object$entries$find[0]; // istanbul ignore next
31
-
32
- return name && Object.prototype.hasOwnProperty.call(mapOut, name) ? mapOut[name] : 0;
33
- }
34
-
35
- function convertMouseButtons(event, init, property) {
36
- if (!isMousePressEvent(event)) {
37
- return 0;
38
- }
39
-
40
- if (typeof init[property] === 'number') {
41
- return init[property];
42
- } else if (property === 'button' && typeof init.buttons === 'number') {
43
- return translateButtonNumber(init.buttons, 'buttons');
44
- } else if (property === 'buttons' && typeof init.button === 'number') {
45
- return translateButtonNumber(init.button, 'button');
46
- }
47
-
48
- return property != 'button' && isMousePressEvent(event) ? 1 : 0;
49
- }
50
-
51
- function getMouseEventOptions(event, init, clickCount = 0) {
52
- var _init;
53
-
54
- init = (_init = init) != null ? _init : {};
55
- return { ...init,
56
- // https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail
57
- detail: event === 'mousedown' || event === 'mouseup' || event === 'click' ? 1 + clickCount : clickCount,
58
- buttons: convertMouseButtons(event, init, 'buttons'),
59
- button: convertMouseButtons(event, init, 'button')
60
- };
61
- }
@@ -1,2 +0,0 @@
1
- export declare function isCursorAtEnd(element: Element): boolean;
2
- export declare function isCursorAtStart(element: Element): boolean;
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isCursorAtEnd = isCursorAtEnd;
7
- exports.isCursorAtStart = isCursorAtStart;
8
-
9
- var _selectionRange = require("./selectionRange");
10
-
11
- var _getValue2 = require("./getValue");
12
-
13
- function isCursorAtEnd(element) {
14
- var _getValue;
15
-
16
- const {
17
- selectionStart,
18
- selectionEnd
19
- } = (0, _selectionRange.getSelectionRange)(element);
20
- return selectionStart === selectionEnd && (selectionStart != null ? selectionStart :
21
- /* istanbul ignore next */
22
- 0) === ((_getValue = (0, _getValue2.getValue)(element)) != null ? _getValue :
23
- /* istanbul ignore next */
24
- '').length;
25
- }
26
-
27
- function isCursorAtStart(element) {
28
- const {
29
- selectionStart,
30
- selectionEnd
31
- } = (0, _selectionRange.getSelectionRange)(element);
32
- return selectionStart === selectionEnd && (selectionStart != null ? selectionStart :
33
- /* istanbul ignore next */
34
- 0) === 0;
35
- }
@@ -1,10 +0,0 @@
1
- declare enum unreliableValueInputTypes {
2
- 'number' = "number"
3
- }
4
- /**
5
- * Check if an empty IDL value on the element could mean a derivation of displayed value and IDL value
6
- */
7
- export declare function hasUnreliableEmptyValue(element: Element): element is HTMLInputElement & {
8
- type: unreliableValueInputTypes;
9
- };
10
- export {};
@@ -1,21 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.hasUnreliableEmptyValue = hasUnreliableEmptyValue;
7
-
8
- var _isElementType = require("../misc/isElementType");
9
-
10
- var unreliableValueInputTypes;
11
- /**
12
- * Check if an empty IDL value on the element could mean a derivation of displayed value and IDL value
13
- */
14
-
15
- (function (unreliableValueInputTypes) {
16
- unreliableValueInputTypes["number"] = "number";
17
- })(unreliableValueInputTypes || (unreliableValueInputTypes = {}));
18
-
19
- function hasUnreliableEmptyValue(element) {
20
- return (0, _isElementType.isElementType)(element, 'input') && Boolean(unreliableValueInputTypes[element.type]);
21
- }
@@ -1,16 +0,0 @@
1
- declare enum selectionSupportType {
2
- 'text' = "text",
3
- 'search' = "search",
4
- 'url' = "url",
5
- 'tel' = "tel",
6
- 'password' = "password"
7
- }
8
- export declare function hasSelectionSupport(element: Element): element is HTMLTextAreaElement | (HTMLInputElement & {
9
- type: selectionSupportType;
10
- });
11
- export declare function getSelectionRange(element: Element): {
12
- selectionStart: number | null;
13
- selectionEnd: number | null;
14
- };
15
- export declare function setSelectionRange(element: Element, newSelectionStart: number, newSelectionEnd: number): void;
16
- export {};
@@ -1,104 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getSelectionRange = getSelectionRange;
7
- exports.hasSelectionSupport = hasSelectionSupport;
8
- exports.setSelectionRange = setSelectionRange;
9
-
10
- var _isElementType = require("../misc/isElementType");
11
-
12
- // https://github.com/jsdom/jsdom/blob/c2fb8ff94917a4d45e2398543f5dd2a8fed0bdab/lib/jsdom/living/nodes/HTMLInputElement-impl.js#L45
13
- var selectionSupportType;
14
-
15
- (function (selectionSupportType) {
16
- selectionSupportType["text"] = "text";
17
- selectionSupportType["search"] = "search";
18
- selectionSupportType["url"] = "url";
19
- selectionSupportType["tel"] = "tel";
20
- selectionSupportType["password"] = "password";
21
- })(selectionSupportType || (selectionSupportType = {}));
22
-
23
- const InputSelection = Symbol('inputSelection');
24
-
25
- function hasSelectionSupport(element) {
26
- return (0, _isElementType.isElementType)(element, 'textarea') || (0, _isElementType.isElementType)(element, 'input') && Boolean(selectionSupportType[element.type]);
27
- }
28
-
29
- function getSelectionRange(element) {
30
- if (hasSelectionSupport(element)) {
31
- return {
32
- selectionStart: element.selectionStart,
33
- selectionEnd: element.selectionEnd
34
- };
35
- }
36
-
37
- if ((0, _isElementType.isElementType)(element, 'input')) {
38
- var _InputSelection;
39
-
40
- return (_InputSelection = element[InputSelection]) != null ? _InputSelection : {
41
- selectionStart: null,
42
- selectionEnd: null
43
- };
44
- }
45
-
46
- const selection = element.ownerDocument.getSelection(); // there should be no editing if the focusNode is outside of element
47
- // TODO: properly handle selection ranges
48
-
49
- if (selection != null && selection.rangeCount && element.contains(selection.focusNode)) {
50
- const range = selection.getRangeAt(0);
51
- return {
52
- selectionStart: range.startOffset,
53
- selectionEnd: range.endOffset
54
- };
55
- } else {
56
- return {
57
- selectionStart: null,
58
- selectionEnd: null
59
- };
60
- }
61
- }
62
-
63
- function setSelectionRange(element, newSelectionStart, newSelectionEnd) {
64
- const {
65
- selectionStart,
66
- selectionEnd
67
- } = getSelectionRange(element);
68
-
69
- if (selectionStart === newSelectionStart && selectionEnd === newSelectionEnd) {
70
- return;
71
- }
72
-
73
- if (hasSelectionSupport(element)) {
74
- element.setSelectionRange(newSelectionStart, newSelectionEnd);
75
- }
76
-
77
- if ((0, _isElementType.isElementType)(element, 'input')) {
78
- ;
79
- element[InputSelection] = {
80
- selectionStart: newSelectionStart,
81
- selectionEnd: newSelectionEnd
82
- };
83
- } // Moving the selection inside <input> or <textarea> does not alter the document Selection.
84
-
85
-
86
- if ((0, _isElementType.isElementType)(element, 'input') || (0, _isElementType.isElementType)(element, 'textarea')) {
87
- return;
88
- }
89
-
90
- const range = element.ownerDocument.createRange();
91
- range.selectNodeContents(element); // istanbul ignore else
92
-
93
- if (element.firstChild) {
94
- range.setStart(element.firstChild, newSelectionStart);
95
- range.setEnd(element.firstChild, newSelectionEnd);
96
- }
97
-
98
- const selection = element.ownerDocument.getSelection(); // istanbul ignore else
99
-
100
- if (selection) {
101
- selection.removeAllRanges();
102
- selection.addRange(range);
103
- }
104
- }
@@ -1 +0,0 @@
1
- export declare function isDocument(el: Document | Element): el is Document;
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isDocument = isDocument;
7
-
8
- function isDocument(el) {
9
- return el.nodeType === el.DOCUMENT_NODE;
10
- }
@@ -1 +0,0 @@
1
- export declare function isLabelWithInternallyDisabledControl(element: Element): boolean;
@@ -1,22 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isLabelWithInternallyDisabledControl = isLabelWithInternallyDisabledControl;
7
-
8
- var _isDisabled = require("./isDisabled");
9
-
10
- var _isElementType = require("./isElementType");
11
-
12
- // Absolutely NO events fire on label elements that contain their control
13
- // if that control is disabled. NUTS!
14
- // no joke. There are NO events for: <label><input disabled /><label>
15
- function isLabelWithInternallyDisabledControl(element) {
16
- if (!(0, _isElementType.isElementType)(element, 'label')) {
17
- return false;
18
- }
19
-
20
- const control = element.control;
21
- return Boolean(control && element.contains(control) && (0, _isDisabled.isDisabled)(control));
22
- }