@testing-library/user-event 14.0.0-beta.3 → 14.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/dist/index.d.ts +1110 -3
  2. package/dist/index.js +2826 -8
  3. package/dist/package.json +1 -0
  4. package/package.json +6 -30
  5. package/dist/clipboard/copy.d.ts +0 -2
  6. package/dist/clipboard/copy.js +0 -36
  7. package/dist/clipboard/cut.d.ts +0 -2
  8. package/dist/clipboard/cut.js +0 -42
  9. package/dist/clipboard/index.d.ts +0 -3
  10. package/dist/clipboard/index.js +0 -44
  11. package/dist/clipboard/paste.d.ts +0 -2
  12. package/dist/clipboard/paste.js +0 -47
  13. package/dist/convenience/click.d.ts +0 -4
  14. package/dist/convenience/click.js +0 -52
  15. package/dist/convenience/hover.d.ts +0 -3
  16. package/dist/convenience/hover.js +0 -31
  17. package/dist/convenience/index.d.ts +0 -3
  18. package/dist/convenience/index.js +0 -44
  19. package/dist/convenience/tab.d.ts +0 -4
  20. package/dist/convenience/tab.js +0 -12
  21. package/dist/document/index.d.ts +0 -10
  22. package/dist/document/index.js +0 -100
  23. package/dist/document/interceptor.d.ts +0 -15
  24. package/dist/document/interceptor.js +0 -37
  25. package/dist/document/selection.d.ts +0 -27
  26. package/dist/document/selection.js +0 -90
  27. package/dist/document/value.d.ts +0 -18
  28. package/dist/document/value.js +0 -77
  29. package/dist/keyboard/getEventProps.d.ts +0 -15
  30. package/dist/keyboard/getEventProps.js +0 -27
  31. package/dist/keyboard/index.d.ts +0 -7
  32. package/dist/keyboard/index.js +0 -42
  33. package/dist/keyboard/keyMap.d.ts +0 -5
  34. package/dist/keyboard/keyMap.js +0 -119
  35. package/dist/keyboard/keyboardAction.d.ts +0 -10
  36. package/dist/keyboard/keyboardAction.js +0 -156
  37. package/dist/keyboard/parseKeyDef.d.ts +0 -17
  38. package/dist/keyboard/parseKeyDef.js +0 -61
  39. package/dist/keyboard/plugins/arrow.d.ts +0 -6
  40. package/dist/keyboard/plugins/arrow.js +0 -28
  41. package/dist/keyboard/plugins/character.d.ts +0 -5
  42. package/dist/keyboard/plugins/character.js +0 -173
  43. package/dist/keyboard/plugins/combination.d.ts +0 -5
  44. package/dist/keyboard/plugins/combination.js +0 -19
  45. package/dist/keyboard/plugins/control.d.ts +0 -6
  46. package/dist/keyboard/plugins/control.js +0 -52
  47. package/dist/keyboard/plugins/functional.d.ts +0 -11
  48. package/dist/keyboard/plugins/functional.js +0 -158
  49. package/dist/keyboard/plugins/index.d.ts +0 -7
  50. package/dist/keyboard/plugins/index.js +0 -33
  51. package/dist/keyboard/shared/fireChangeForInputTimeIfValid.d.ts +0 -3
  52. package/dist/keyboard/shared/fireChangeForInputTimeIfValid.js +0 -20
  53. package/dist/keyboard/shared/index.d.ts +0 -1
  54. package/dist/keyboard/shared/index.js +0 -18
  55. package/dist/keyboard/types.d.ts +0 -64
  56. package/dist/keyboard/types.js +0 -19
  57. package/dist/options.d.ts +0 -102
  58. package/dist/options.js +0 -36
  59. package/dist/pointer/index.d.ts +0 -10
  60. package/dist/pointer/index.js +0 -56
  61. package/dist/pointer/keyMap.d.ts +0 -2
  62. package/dist/pointer/keyMap.js +0 -29
  63. package/dist/pointer/parseKeyDef.d.ts +0 -6
  64. package/dist/pointer/parseKeyDef.js +0 -34
  65. package/dist/pointer/pointerAction.d.ts +0 -7
  66. package/dist/pointer/pointerAction.js +0 -46
  67. package/dist/pointer/pointerMove.d.ts +0 -6
  68. package/dist/pointer/pointerMove.js +0 -136
  69. package/dist/pointer/pointerPress.d.ts +0 -8
  70. package/dist/pointer/pointerPress.js +0 -327
  71. package/dist/pointer/resolveSelectionTarget.d.ts +0 -5
  72. package/dist/pointer/resolveSelectionTarget.js +0 -75
  73. package/dist/pointer/types.d.ts +0 -61
  74. package/dist/pointer/types.js +0 -1
  75. package/dist/setup/api.d.ts +0 -5
  76. package/dist/setup/api.js +0 -111
  77. package/dist/setup/config.d.ts +0 -10
  78. package/dist/setup/config.js +0 -8
  79. package/dist/setup/directApi.d.ts +0 -20
  80. package/dist/setup/directApi.js +0 -95
  81. package/dist/setup/index.d.ts +0 -30
  82. package/dist/setup/index.js +0 -27
  83. package/dist/setup/setup.d.ts +0 -74
  84. package/dist/setup/setup.js +0 -98
  85. package/dist/setup/wrapAsync.d.ts +0 -4
  86. package/dist/setup/wrapAsync.js +0 -15
  87. package/dist/utility/clear.d.ts +0 -2
  88. package/dist/utility/clear.js +0 -30
  89. package/dist/utility/index.d.ts +0 -4
  90. package/dist/utility/index.js +0 -57
  91. package/dist/utility/selectOptions.d.ts +0 -3
  92. package/dist/utility/selectOptions.js +0 -132
  93. package/dist/utility/type.d.ts +0 -9
  94. package/dist/utility/type.js +0 -37
  95. package/dist/utility/upload.d.ts +0 -5
  96. package/dist/utility/upload.js +0 -64
  97. package/dist/utils/click/isClickableInput.d.ts +0 -1
  98. package/dist/utils/click/isClickableInput.js +0 -14
  99. package/dist/utils/dataTransfer/Blob.d.ts +0 -1
  100. package/dist/utils/dataTransfer/Blob.js +0 -21
  101. package/dist/utils/dataTransfer/Clipboard.d.ts +0 -9
  102. package/dist/utils/dataTransfer/Clipboard.js +0 -188
  103. package/dist/utils/dataTransfer/DataTransfer.d.ts +0 -2
  104. package/dist/utils/dataTransfer/DataTransfer.js +0 -158
  105. package/dist/utils/dataTransfer/FileList.d.ts +0 -1
  106. package/dist/utils/dataTransfer/FileList.js +0 -23
  107. package/dist/utils/edit/buildTimeValue.d.ts +0 -1
  108. package/dist/utils/edit/buildTimeValue.js +0 -44
  109. package/dist/utils/edit/calculateNewValue.d.ts +0 -14
  110. package/dist/utils/edit/calculateNewValue.js +0 -46
  111. package/dist/utils/edit/editInputElement.d.ts +0 -16
  112. package/dist/utils/edit/editInputElement.js +0 -53
  113. package/dist/utils/edit/getValue.d.ts +0 -1
  114. package/dist/utils/edit/getValue.js +0 -23
  115. package/dist/utils/edit/isContentEditable.d.ts +0 -7
  116. package/dist/utils/edit/isContentEditable.js +0 -25
  117. package/dist/utils/edit/isEditable.d.ts +0 -25
  118. package/dist/utils/edit/isEditable.js +0 -42
  119. package/dist/utils/edit/isValidDateValue.d.ts +0 -3
  120. package/dist/utils/edit/isValidDateValue.js +0 -12
  121. package/dist/utils/edit/isValidInputTimeValue.d.ts +0 -3
  122. package/dist/utils/edit/isValidInputTimeValue.js +0 -12
  123. package/dist/utils/edit/maxLength.d.ts +0 -1
  124. package/dist/utils/edit/maxLength.js +0 -50
  125. package/dist/utils/edit/prepareInput.d.ts +0 -7
  126. package/dist/utils/edit/prepareInput.js +0 -77
  127. package/dist/utils/edit/setFiles.d.ts +0 -12
  128. package/dist/utils/edit/setFiles.js +0 -72
  129. package/dist/utils/focus/blur.d.ts +0 -2
  130. package/dist/utils/focus/blur.js +0 -19
  131. package/dist/utils/focus/copySelection.d.ts +0 -1
  132. package/dist/utils/focus/copySelection.js +0 -36
  133. package/dist/utils/focus/focus.d.ts +0 -2
  134. package/dist/utils/focus/focus.js +0 -22
  135. package/dist/utils/focus/getActiveElement.d.ts +0 -1
  136. package/dist/utils/focus/getActiveElement.js +0 -26
  137. package/dist/utils/focus/getTabDestination.d.ts +0 -1
  138. package/dist/utils/focus/getTabDestination.js +0 -84
  139. package/dist/utils/focus/isFocusable.d.ts +0 -1
  140. package/dist/utils/focus/isFocusable.js +0 -12
  141. package/dist/utils/focus/selectAll.d.ts +0 -5
  142. package/dist/utils/focus/selectAll.js +0 -51
  143. package/dist/utils/focus/selection.d.ts +0 -42
  144. package/dist/utils/focus/selection.js +0 -190
  145. package/dist/utils/focus/selector.d.ts +0 -1
  146. package/dist/utils/focus/selector.js +0 -8
  147. package/dist/utils/index.d.ts +0 -38
  148. package/dist/utils/index.js +0 -499
  149. package/dist/utils/keyDef/readNextDescriptor.d.ts +0 -19
  150. package/dist/utils/keyDef/readNextDescriptor.js +0 -102
  151. package/dist/utils/misc/eventWrapper.d.ts +0 -1
  152. package/dist/utils/misc/eventWrapper.js +0 -16
  153. package/dist/utils/misc/findClosest.d.ts +0 -1
  154. package/dist/utils/misc/findClosest.js +0 -20
  155. package/dist/utils/misc/getDocumentFromNode.d.ts +0 -1
  156. package/dist/utils/misc/getDocumentFromNode.js +0 -14
  157. package/dist/utils/misc/hasFormSubmit.d.ts +0 -1
  158. package/dist/utils/misc/hasFormSubmit.js +0 -10
  159. package/dist/utils/misc/hasPointerEvents.d.ts +0 -15
  160. package/dist/utils/misc/hasPointerEvents.js +0 -24
  161. package/dist/utils/misc/isDescendantOrSelf.d.ts +0 -1
  162. package/dist/utils/misc/isDescendantOrSelf.js +0 -20
  163. package/dist/utils/misc/isDisabled.d.ts +0 -1
  164. package/dist/utils/misc/isDisabled.js +0 -12
  165. package/dist/utils/misc/isElementType.d.ts +0 -5
  166. package/dist/utils/misc/isElementType.js +0 -24
  167. package/dist/utils/misc/isVisible.d.ts +0 -1
  168. package/dist/utils/misc/isVisible.js +0 -31
  169. package/dist/utils/misc/wait.d.ts +0 -1
  170. package/dist/utils/misc/wait.js +0 -10
  171. package/dist/utils/pointer/firePointerEvents.d.ts +0 -25
  172. package/dist/utils/pointer/firePointerEvents.js +0 -110
  173. package/dist/utils/pointer/mouseButtons.d.ts +0 -12
  174. package/dist/utils/pointer/mouseButtons.js +0 -45
@@ -1,90 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.clearUISelection = clearUISelection;
7
- exports.getUISelection = getUISelection;
8
- exports.prepareSelectionInterceptor = prepareSelectionInterceptor;
9
- exports.setUISelection = setUISelection;
10
-
11
- var _ = require(".");
12
-
13
- var _interceptor = require("./interceptor");
14
-
15
- const UISelection = Symbol('Displayed selection in UI');
16
-
17
- function prepareSelectionInterceptor(element) {
18
- (0, _interceptor.prepareInterceptor)(element, 'setSelectionRange', function interceptorImpl(start, end, direction = 'none') {
19
- const isUI = start && typeof start === 'object' && start[UISelection];
20
-
21
- if (!isUI) {
22
- this[UISelection] = undefined;
23
- }
24
-
25
- return {
26
- realArgs: [Number(start), end, direction]
27
- };
28
- });
29
- (0, _interceptor.prepareInterceptor)(element, 'selectionStart', function interceptorImpl(v) {
30
- this[UISelection] = undefined;
31
- return {
32
- realArgs: v
33
- };
34
- });
35
- (0, _interceptor.prepareInterceptor)(element, 'selectionEnd', function interceptorImpl(v) {
36
- this[UISelection] = undefined;
37
- return {
38
- realArgs: v
39
- };
40
- });
41
- }
42
-
43
- function setUISelection(element, {
44
- focusOffset: focusOffsetParam,
45
- anchorOffset: anchorOffsetParam = focusOffsetParam
46
- }, mode = 'replace') {
47
- const valueLength = (0, _.getUIValue)(element).length;
48
-
49
- const sanitizeOffset = o => Math.max(0, Math.min(valueLength, o));
50
-
51
- const anchorOffset = mode === 'replace' || element[UISelection] === undefined ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
52
- const focusOffset = sanitizeOffset(focusOffsetParam);
53
- const startOffset = Math.min(anchorOffset, focusOffset);
54
- const endOffset = Math.max(anchorOffset, focusOffset);
55
- element[UISelection] = {
56
- anchorOffset,
57
- focusOffset
58
- };
59
-
60
- if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
61
- return;
62
- } // eslint-disable-next-line no-new-wrappers
63
-
64
-
65
- const startObj = new Number(startOffset);
66
- startObj[UISelection] = UISelection;
67
-
68
- try {
69
- element.setSelectionRange(startObj, endOffset);
70
- } catch {// DOMException for invalid state is expected when calling this
71
- // on an element without support for setSelectionRange
72
- }
73
- }
74
-
75
- function getUISelection(element) {
76
- var _element$UISelection, _element$selectionSta, _element$selectionEnd;
77
-
78
- const sel = (_element$UISelection = element[UISelection]) != null ? _element$UISelection : {
79
- anchorOffset: (_element$selectionSta = element.selectionStart) != null ? _element$selectionSta : 0,
80
- focusOffset: (_element$selectionEnd = element.selectionEnd) != null ? _element$selectionEnd : 0
81
- };
82
- return { ...sel,
83
- startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
84
- endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
85
- };
86
- }
87
-
88
- function clearUISelection(element) {
89
- element[UISelection] = undefined;
90
- }
@@ -1,18 +0,0 @@
1
- declare const UIValue: unique symbol;
2
- declare const InitialValue: unique symbol;
3
- declare const TrackChanges: unique symbol;
4
- declare global {
5
- interface Element {
6
- [UIValue]?: string;
7
- [InitialValue]?: string;
8
- [TrackChanges]?: string[];
9
- }
10
- }
11
- export declare function prepareValueInterceptor(element: HTMLInputElement): void;
12
- export declare function setUIValue(element: HTMLInputElement | HTMLTextAreaElement, value: string): void;
13
- export declare function getUIValue(element: HTMLInputElement | HTMLTextAreaElement): string;
14
- export declare function setInitialValue(element: HTMLInputElement | HTMLTextAreaElement): void;
15
- export declare function getInitialValue(element: HTMLInputElement | HTMLTextAreaElement): string | undefined;
16
- export declare function startTrackValue(element: HTMLInputElement | HTMLTextAreaElement): void;
17
- export declare function endTrackValue(element: HTMLInputElement | HTMLTextAreaElement): string[] | undefined;
18
- export {};
@@ -1,77 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.endTrackValue = endTrackValue;
7
- exports.getInitialValue = getInitialValue;
8
- exports.getUIValue = getUIValue;
9
- exports.prepareValueInterceptor = prepareValueInterceptor;
10
- exports.setInitialValue = setInitialValue;
11
- exports.setUIValue = setUIValue;
12
- exports.startTrackValue = startTrackValue;
13
-
14
- var _interceptor = require("./interceptor");
15
-
16
- var _selection = require("./selection");
17
-
18
- const UIValue = Symbol('Displayed value in UI');
19
- const InitialValue = Symbol('Initial value to compare on blur');
20
- const TrackChanges = Symbol('Track programmatic changes for React workaround');
21
-
22
- function valueInterceptor(v) {
23
- const isUI = typeof v === 'object' && v[UIValue];
24
- this[UIValue] = isUI ? String(v) : undefined;
25
-
26
- if (!isUI) {
27
- trackValue(this, String(v));
28
- this[InitialValue] = String(v); // Programmatically setting the value property
29
- // moves the cursor to the end of the input.
30
-
31
- (0, _selection.clearUISelection)(this);
32
- }
33
-
34
- return {
35
- applyNative: !!isUI,
36
- realArgs: String(v)
37
- };
38
- }
39
-
40
- function prepareValueInterceptor(element) {
41
- (0, _interceptor.prepareInterceptor)(element, 'value', valueInterceptor);
42
- }
43
-
44
- function setUIValue(element, value) {
45
- element.value = {
46
- [UIValue]: UIValue,
47
- toString: () => value
48
- };
49
- }
50
-
51
- function getUIValue(element) {
52
- return element[UIValue] === undefined ? element.value : String(element[UIValue]);
53
- }
54
-
55
- function setInitialValue(element) {
56
- element[InitialValue] = element.value;
57
- }
58
-
59
- function getInitialValue(element) {
60
- return element[InitialValue];
61
- }
62
-
63
- function startTrackValue(element) {
64
- element[TrackChanges] = [];
65
- }
66
-
67
- function trackValue(element, v) {
68
- var _element$TrackChanges;
69
-
70
- (_element$TrackChanges = element[TrackChanges]) == null ? void 0 : _element$TrackChanges.push(v);
71
- }
72
-
73
- function endTrackValue(element) {
74
- const tracked = element[TrackChanges];
75
- element[TrackChanges] = undefined;
76
- return tracked;
77
- }
@@ -1,15 +0,0 @@
1
- import { keyboardKey, keyboardState } from './types';
2
- export declare function getKeyEventProps(keyDef: keyboardKey, state: keyboardState): {
3
- key: string | undefined;
4
- code: string | undefined;
5
- altKey: boolean;
6
- ctrlKey: boolean;
7
- metaKey: boolean;
8
- shiftKey: boolean;
9
- };
10
- export declare function getMouseEventProps(state: keyboardState): {
11
- altKey: boolean;
12
- ctrlKey: boolean;
13
- metaKey: boolean;
14
- shiftKey: boolean;
15
- };
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getKeyEventProps = getKeyEventProps;
7
- exports.getMouseEventProps = getMouseEventProps;
8
-
9
- function getKeyEventProps(keyDef, state) {
10
- return {
11
- key: keyDef.key,
12
- code: keyDef.code,
13
- altKey: state.modifiers.alt,
14
- ctrlKey: state.modifiers.ctrl,
15
- metaKey: state.modifiers.meta,
16
- shiftKey: state.modifiers.shift
17
- };
18
- }
19
-
20
- function getMouseEventProps(state) {
21
- return {
22
- altKey: state.modifiers.alt,
23
- ctrlKey: state.modifiers.ctrl,
24
- metaKey: state.modifiers.meta,
25
- shiftKey: state.modifiers.shift
26
- };
27
- }
@@ -1,7 +0,0 @@
1
- import { UserEvent } from '../setup';
2
- import { releaseAllKeys } from './keyboardAction';
3
- import type { keyboardState, keyboardKey } from './types';
4
- export { releaseAllKeys };
5
- export type { keyboardKey, keyboardState };
6
- export declare function keyboard(this: UserEvent, text: string): Promise<void>;
7
- export declare function createKeyboardState(): keyboardState;
@@ -1,42 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createKeyboardState = createKeyboardState;
7
- exports.keyboard = keyboard;
8
- Object.defineProperty(exports, "releaseAllKeys", {
9
- enumerable: true,
10
- get: function () {
11
- return _keyboardAction.releaseAllKeys;
12
- }
13
- });
14
-
15
- var _setup = require("../setup");
16
-
17
- var _keyboardAction = require("./keyboardAction");
18
-
19
- var _parseKeyDef = require("./parseKeyDef");
20
-
21
- async function keyboard(text) {
22
- const {
23
- keyboardMap
24
- } = this[_setup.Config];
25
- const actions = (0, _parseKeyDef.parseKeyDef)(keyboardMap, text);
26
- return (0, _keyboardAction.keyboardAction)(this[_setup.Config], actions);
27
- }
28
-
29
- function createKeyboardState() {
30
- return {
31
- activeElement: null,
32
- pressed: [],
33
- carryChar: '',
34
- modifiers: {
35
- alt: false,
36
- caps: false,
37
- ctrl: false,
38
- meta: false,
39
- shift: false
40
- }
41
- };
42
- }
@@ -1,5 +0,0 @@
1
- import { keyboardKey } from './types';
2
- /**
3
- * Mapping for a default US-104-QWERTY keyboard
4
- */
5
- export declare const defaultKeyMap: keyboardKey[];
@@ -1,119 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.defaultKeyMap = void 0;
7
-
8
- var _types = require("./types");
9
-
10
- /**
11
- * Mapping for a default US-104-QWERTY keyboard
12
- */
13
- const defaultKeyMap = [// alphanumeric keys
14
- ...'0123456789'.split('').map(c => ({
15
- code: `Digit${c}`,
16
- key: c
17
- })), ...')!@#$%^&*('.split('').map((c, i) => ({
18
- code: `Digit${i}`,
19
- key: c,
20
- shiftKey: true
21
- })), ...'abcdefghijklmnopqrstuvwxyz'.split('').map(c => ({
22
- code: `Key${c.toUpperCase()}`,
23
- key: c
24
- })), ...'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('').map(c => ({
25
- code: `Key${c}`,
26
- key: c,
27
- shiftKey: true
28
- })), // alphanumeric block - functional
29
- {
30
- code: 'Space',
31
- key: ' '
32
- }, {
33
- code: 'AltLeft',
34
- key: 'Alt',
35
- location: _types.DOM_KEY_LOCATION.LEFT
36
- }, {
37
- code: 'AltRight',
38
- key: 'Alt',
39
- location: _types.DOM_KEY_LOCATION.RIGHT
40
- }, {
41
- code: 'ShiftLeft',
42
- key: 'Shift',
43
- location: _types.DOM_KEY_LOCATION.LEFT
44
- }, {
45
- code: 'ShiftRight',
46
- key: 'Shift',
47
- location: _types.DOM_KEY_LOCATION.RIGHT
48
- }, {
49
- code: 'ControlLeft',
50
- key: 'Control',
51
- location: _types.DOM_KEY_LOCATION.LEFT
52
- }, {
53
- code: 'ControlRight',
54
- key: 'Control',
55
- location: _types.DOM_KEY_LOCATION.RIGHT
56
- }, {
57
- code: 'MetaLeft',
58
- key: 'Meta',
59
- location: _types.DOM_KEY_LOCATION.LEFT
60
- }, {
61
- code: 'MetaRight',
62
- key: 'Meta',
63
- location: _types.DOM_KEY_LOCATION.RIGHT
64
- }, {
65
- code: 'OSLeft',
66
- key: 'OS',
67
- location: _types.DOM_KEY_LOCATION.LEFT
68
- }, {
69
- code: 'OSRight',
70
- key: 'OS',
71
- location: _types.DOM_KEY_LOCATION.RIGHT
72
- }, {
73
- code: 'Tab',
74
- key: 'Tab'
75
- }, {
76
- code: 'CapsLock',
77
- key: 'CapsLock'
78
- }, {
79
- code: 'Backspace',
80
- key: 'Backspace'
81
- }, {
82
- code: 'Enter',
83
- key: 'Enter'
84
- }, // function
85
- {
86
- code: 'Escape',
87
- key: 'Escape'
88
- }, // arrows
89
- {
90
- code: 'ArrowUp',
91
- key: 'ArrowUp'
92
- }, {
93
- code: 'ArrowDown',
94
- key: 'ArrowDown'
95
- }, {
96
- code: 'ArrowLeft',
97
- key: 'ArrowLeft'
98
- }, {
99
- code: 'ArrowRight',
100
- key: 'ArrowRight'
101
- }, // control pad
102
- {
103
- code: 'Home',
104
- key: 'Home'
105
- }, {
106
- code: 'End',
107
- key: 'End'
108
- }, {
109
- code: 'Delete',
110
- key: 'Delete'
111
- }, {
112
- code: 'PageUp',
113
- key: 'PageUp'
114
- }, {
115
- code: 'PageDown',
116
- key: 'PageDown'
117
- } // TODO: add mappings
118
- ];
119
- exports.defaultKeyMap = defaultKeyMap;
@@ -1,10 +0,0 @@
1
- import { Config } from '../setup';
2
- import { keyboardKey } from './types';
3
- export interface KeyboardAction {
4
- keyDef: keyboardKey;
5
- releasePrevious: boolean;
6
- releaseSelf: boolean;
7
- repeat: number;
8
- }
9
- export declare function keyboardAction(config: Config, actions: KeyboardAction[]): Promise<void>;
10
- export declare function releaseAllKeys(config: Config): Promise<void>;
@@ -1,156 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.keyboardAction = keyboardAction;
7
- exports.releaseAllKeys = releaseAllKeys;
8
-
9
- var _dom = require("@testing-library/dom");
10
-
11
- var _utils = require("../utils");
12
-
13
- var plugins = _interopRequireWildcard(require("./plugins"));
14
-
15
- var _getEventProps = require("./getEventProps");
16
-
17
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
18
-
19
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
20
-
21
- async function keyboardAction(config, actions) {
22
- for (let i = 0; i < actions.length; i++) {
23
- await keyboardKeyAction(config, actions[i]);
24
-
25
- if (typeof config.delay === 'number' && i < actions.length - 1) {
26
- await (0, _utils.wait)(config.delay);
27
- }
28
- }
29
- }
30
-
31
- async function keyboardKeyAction(config, {
32
- keyDef,
33
- releasePrevious,
34
- releaseSelf,
35
- repeat
36
- }) {
37
- const {
38
- document,
39
- keyboardState,
40
- delay
41
- } = config;
42
-
43
- const getCurrentElement = () => getActive(document); // Release the key automatically if it was pressed before.
44
-
45
-
46
- const pressed = keyboardState.pressed.find(p => p.keyDef === keyDef);
47
-
48
- if (pressed) {
49
- await keyup(keyDef, getCurrentElement, config, pressed.unpreventedDefault);
50
- }
51
-
52
- if (!releasePrevious) {
53
- let unpreventedDefault = true;
54
-
55
- for (let i = 1; i <= repeat; i++) {
56
- unpreventedDefault = await keydown(keyDef, getCurrentElement, config);
57
-
58
- if (unpreventedDefault && hasKeyPress(keyDef, config)) {
59
- await keypress(keyDef, getCurrentElement, config);
60
- }
61
-
62
- if (typeof delay === 'number' && i < repeat) {
63
- await (0, _utils.wait)(delay);
64
- }
65
- } // Release the key only on the last iteration on `state.repeatKey`.
66
-
67
-
68
- if (releaseSelf) {
69
- await keyup(keyDef, getCurrentElement, config, unpreventedDefault);
70
- }
71
- }
72
- }
73
-
74
- function getActive(document) {
75
- var _getActiveElement;
76
-
77
- return (_getActiveElement = (0, _utils.getActiveElement)(document)) != null ? _getActiveElement :
78
- /* istanbul ignore next */
79
- document.body;
80
- }
81
-
82
- async function releaseAllKeys(config) {
83
- const getCurrentElement = () => getActive(config.document);
84
-
85
- for (const k of config.keyboardState.pressed) {
86
- await keyup(k.keyDef, getCurrentElement, config, k.unpreventedDefault);
87
- }
88
- }
89
-
90
- async function keydown(keyDef, getCurrentElement, config) {
91
- const element = getCurrentElement(); // clear carried characters when focus is moved
92
-
93
- if (element !== config.keyboardState.activeElement) {
94
- config.keyboardState.carryValue = undefined;
95
- config.keyboardState.carryChar = '';
96
- }
97
-
98
- config.keyboardState.activeElement = element;
99
- applyPlugins(plugins.preKeydownBehavior, keyDef, element, config);
100
-
101
- const unpreventedDefault = _dom.fireEvent.keyDown(element, (0, _getEventProps.getKeyEventProps)(keyDef, config.keyboardState));
102
-
103
- config.keyboardState.pressed.push({
104
- keyDef,
105
- unpreventedDefault
106
- });
107
-
108
- if (unpreventedDefault) {
109
- // all default behavior like keypress/submit etc is applied to the currentElement
110
- applyPlugins(plugins.keydownBehavior, keyDef, getCurrentElement(), config);
111
- }
112
-
113
- return unpreventedDefault;
114
- }
115
-
116
- async function keypress(keyDef, getCurrentElement, config) {
117
- const element = getCurrentElement();
118
-
119
- const unpreventedDefault = _dom.fireEvent.keyPress(element, { ...(0, _getEventProps.getKeyEventProps)(keyDef, config.keyboardState),
120
- charCode: keyDef.key === 'Enter' ? 13 : String(keyDef.key).charCodeAt(0)
121
- });
122
-
123
- if (unpreventedDefault) {
124
- applyPlugins(plugins.keypressBehavior, keyDef, getCurrentElement(), config);
125
- }
126
- }
127
-
128
- async function keyup(keyDef, getCurrentElement, config, unprevented) {
129
- const element = getCurrentElement();
130
- applyPlugins(plugins.preKeyupBehavior, keyDef, element, config);
131
-
132
- const unpreventedDefault = _dom.fireEvent.keyUp(element, (0, _getEventProps.getKeyEventProps)(keyDef, config.keyboardState));
133
-
134
- if (unprevented && unpreventedDefault) {
135
- applyPlugins(plugins.keyupBehavior, keyDef, getCurrentElement(), config);
136
- }
137
-
138
- config.keyboardState.pressed = config.keyboardState.pressed.filter(k => k.keyDef !== keyDef);
139
- applyPlugins(plugins.postKeyupBehavior, keyDef, element, config);
140
- }
141
-
142
- function applyPlugins(pluginCollection, keyDef, element, config) {
143
- const plugin = pluginCollection.find(p => p.matches(keyDef, element, config));
144
-
145
- if (plugin) {
146
- plugin.handle(keyDef, element, config);
147
- }
148
-
149
- return !!plugin;
150
- }
151
-
152
- function hasKeyPress(keyDef, config) {
153
- var _keyDef$key;
154
-
155
- return (((_keyDef$key = keyDef.key) == null ? void 0 : _keyDef$key.length) === 1 || keyDef.key === 'Enter') && !config.keyboardState.modifiers.ctrl && !config.keyboardState.modifiers.alt;
156
- }
@@ -1,17 +0,0 @@
1
- import { keyboardKey } from './types';
2
- /**
3
- * Parse key defintions per `keyboardMap`
4
- *
5
- * Keys can be referenced by `{key}` or `{special}` as well as physical locations per `[code]`.
6
- * Everything else will be interpreted as a typed character - e.g. `a`.
7
- * Brackets `{` and `[` can be escaped by doubling - e.g. `foo[[bar` translates to `foo[bar`.
8
- * Keeping the key pressed can be written as `{key>}`.
9
- * When keeping the key pressed you can choose how long (how many keydown and keypress) the key is pressed `{key>3}`.
10
- * You can then release the key per `{key>3/}` or keep it pressed and continue with the next key.
11
- */
12
- export declare function parseKeyDef(keyboardMap: keyboardKey[], text: string): {
13
- keyDef: keyboardKey;
14
- releasePrevious: boolean;
15
- releaseSelf: boolean;
16
- repeat: number;
17
- }[];
@@ -1,61 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.parseKeyDef = parseKeyDef;
7
-
8
- var _utils = require("../utils");
9
-
10
- /**
11
- * Parse key defintions per `keyboardMap`
12
- *
13
- * Keys can be referenced by `{key}` or `{special}` as well as physical locations per `[code]`.
14
- * Everything else will be interpreted as a typed character - e.g. `a`.
15
- * Brackets `{` and `[` can be escaped by doubling - e.g. `foo[[bar` translates to `foo[bar`.
16
- * Keeping the key pressed can be written as `{key>}`.
17
- * When keeping the key pressed you can choose how long (how many keydown and keypress) the key is pressed `{key>3}`.
18
- * You can then release the key per `{key>3/}` or keep it pressed and continue with the next key.
19
- */
20
- function parseKeyDef(keyboardMap, text) {
21
- const defs = [];
22
-
23
- do {
24
- var _keyboardMap$find;
25
-
26
- const {
27
- type,
28
- descriptor,
29
- consumedLength,
30
- releasePrevious,
31
- releaseSelf = true,
32
- repeat
33
- } = (0, _utils.readNextDescriptor)(text);
34
- const keyDef = (_keyboardMap$find = keyboardMap.find(def => {
35
- if (type === '[') {
36
- var _def$code;
37
-
38
- return ((_def$code = def.code) == null ? void 0 : _def$code.toLowerCase()) === descriptor.toLowerCase();
39
- } else if (type === '{') {
40
- var _def$key;
41
-
42
- return ((_def$key = def.key) == null ? void 0 : _def$key.toLowerCase()) === descriptor.toLowerCase();
43
- }
44
-
45
- return def.key === descriptor;
46
- })) != null ? _keyboardMap$find : {
47
- key: 'Unknown',
48
- code: 'Unknown',
49
- [type === '[' ? 'code' : 'key']: descriptor
50
- };
51
- defs.push({
52
- keyDef,
53
- releasePrevious,
54
- releaseSelf,
55
- repeat
56
- });
57
- text = text.slice(consumedLength);
58
- } while (text);
59
-
60
- return defs;
61
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * This file should contain behavior for arrow keys as described here:
3
- * https://w3c.github.io/uievents-code/#key-arrowpad-section
4
- */
5
- import { behaviorPlugin } from '../types';
6
- export declare const keydownBehavior: behaviorPlugin[];
@@ -1,28 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.keydownBehavior = void 0;
7
-
8
- var _utils = require("../../utils");
9
-
10
- var _document = require("../../document");
11
-
12
- /**
13
- * This file should contain behavior for arrow keys as described here:
14
- * https://w3c.github.io/uievents-code/#key-arrowpad-section
15
- */
16
- const keydownBehavior = [{
17
- // TODO: implement for contentEditable
18
- matches: (keyDef, element) => (keyDef.key === 'ArrowLeft' || keyDef.key === 'ArrowRight') && (0, _utils.isElementType)(element, ['input', 'textarea']),
19
- handle: (keyDef, element) => {
20
- const selection = (0, _document.getUISelection)(element); // TODO: implement shift/ctrl
21
-
22
- (0, _utils.setSelection)({
23
- focusNode: element,
24
- focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + (keyDef.key === 'ArrowLeft' ? -1 : 1) : keyDef.key === 'ArrowLeft' ? selection.startOffset : selection.endOffset
25
- });
26
- }
27
- }];
28
- exports.keydownBehavior = keydownBehavior;