@testing-library/user-event 14.0.0-alpha.14 → 14.0.0-alpha.18

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 (82) hide show
  1. package/dist/clipboard/copy.d.ts +2 -11
  2. package/dist/clipboard/copy.js +10 -4
  3. package/dist/clipboard/cut.d.ts +2 -11
  4. package/dist/clipboard/cut.js +10 -4
  5. package/dist/clipboard/paste.d.ts +2 -6
  6. package/dist/clipboard/paste.js +7 -5
  7. package/dist/convenience/click.d.ts +4 -0
  8. package/dist/convenience/click.js +52 -0
  9. package/dist/convenience/hover.d.ts +3 -0
  10. package/dist/convenience/hover.js +31 -0
  11. package/dist/convenience/index.d.ts +3 -0
  12. package/dist/convenience/index.js +44 -0
  13. package/dist/convenience/tab.d.ts +4 -0
  14. package/dist/convenience/tab.js +12 -0
  15. package/dist/index.d.ts +2 -5
  16. package/dist/index.js +7 -8
  17. package/dist/keyboard/index.d.ts +6 -17
  18. package/dist/keyboard/index.js +13 -41
  19. package/dist/keyboard/keyboardAction.d.ts +10 -0
  20. package/dist/keyboard/keyboardAction.js +156 -0
  21. package/dist/keyboard/{getNextKeyDef.d.ts → parseKeyDef.d.ts} +4 -5
  22. package/dist/keyboard/parseKeyDef.js +61 -0
  23. package/dist/keyboard/plugins/character.js +16 -10
  24. package/dist/keyboard/plugins/combination.js +3 -1
  25. package/dist/keyboard/plugins/functional.js +38 -20
  26. package/dist/keyboard/types.d.ts +3 -17
  27. package/dist/options.d.ts +102 -0
  28. package/dist/options.js +36 -0
  29. package/dist/pointer/index.d.ts +6 -14
  30. package/dist/pointer/index.js +8 -42
  31. package/dist/pointer/parseKeyDef.d.ts +2 -2
  32. package/dist/pointer/parseKeyDef.js +1 -3
  33. package/dist/pointer/pointerAction.d.ts +3 -2
  34. package/dist/pointer/pointerAction.js +9 -15
  35. package/dist/pointer/pointerMove.d.ts +2 -1
  36. package/dist/pointer/pointerPress.d.ts +2 -1
  37. package/dist/pointer/types.d.ts +0 -11
  38. package/dist/setup/api.d.ts +5 -0
  39. package/dist/setup/api.js +111 -0
  40. package/dist/setup/config.d.ts +10 -0
  41. package/dist/setup/config.js +8 -0
  42. package/dist/setup/directApi.d.ts +20 -0
  43. package/dist/setup/directApi.js +95 -0
  44. package/dist/setup/index.d.ts +30 -0
  45. package/dist/setup/index.js +27 -0
  46. package/dist/setup/setup.d.ts +74 -0
  47. package/dist/setup/setup.js +98 -0
  48. package/dist/setup/wrapAsync.d.ts +4 -0
  49. package/dist/setup/wrapAsync.js +15 -0
  50. package/dist/{clear.d.ts → utility/clear.d.ts} +2 -2
  51. package/dist/{clear.js → utility/clear.js} +2 -5
  52. package/dist/utility/index.d.ts +4 -0
  53. package/dist/utility/index.js +57 -0
  54. package/dist/utility/selectOptions.d.ts +3 -0
  55. package/dist/{selectOptions.js → utility/selectOptions.js} +15 -24
  56. package/dist/utility/type.d.ts +9 -0
  57. package/dist/utility/type.js +37 -0
  58. package/dist/utility/upload.d.ts +5 -0
  59. package/dist/{upload.js → utility/upload.js} +12 -40
  60. package/dist/utils/dataTransfer/FileList.js +13 -3
  61. package/dist/utils/edit/setFiles.d.ts +12 -0
  62. package/dist/utils/edit/setFiles.js +72 -0
  63. package/dist/utils/index.d.ts +2 -0
  64. package/dist/utils/index.js +26 -0
  65. package/dist/utils/misc/getDocumentFromNode.d.ts +1 -0
  66. package/dist/utils/misc/getDocumentFromNode.js +14 -0
  67. package/package.json +1 -1
  68. package/dist/click.d.ts +0 -9
  69. package/dist/click.js +0 -61
  70. package/dist/hover.d.ts +0 -4
  71. package/dist/hover.js +0 -43
  72. package/dist/keyboard/getNextKeyDef.js +0 -55
  73. package/dist/keyboard/keyboardImplementation.d.ts +0 -3
  74. package/dist/keyboard/keyboardImplementation.js +0 -165
  75. package/dist/selectOptions.d.ts +0 -4
  76. package/dist/setup.d.ts +0 -100
  77. package/dist/setup.js +0 -241
  78. package/dist/tab.d.ts +0 -5
  79. package/dist/tab.js +0 -12
  80. package/dist/type.d.ts +0 -14
  81. package/dist/type.js +0 -74
  82. package/dist/upload.d.ts +0 -9
@@ -0,0 +1,9 @@
1
+ import type { UserEvent } from '../setup';
2
+ import { Config } from '../setup/config';
3
+ export interface typeOptions {
4
+ skipClick?: Config['skipClick'];
5
+ skipAutoClose?: Config['skipClick'];
6
+ initialSelectionStart?: number;
7
+ initialSelectionEnd?: number;
8
+ }
9
+ export declare function type(this: UserEvent, element: Element, text: string, { skipClick, skipAutoClose, initialSelectionStart, initialSelectionEnd, }?: typeOptions): Promise<void>;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.type = type;
7
+
8
+ var _utils = require("../utils");
9
+
10
+ var _keyboard = require("../keyboard");
11
+
12
+ var _config = require("../setup/config");
13
+
14
+ async function type(element, text, {
15
+ skipClick = this[_config.Config].skipClick,
16
+ skipAutoClose = this[_config.Config].skipAutoClose,
17
+ initialSelectionStart,
18
+ initialSelectionEnd
19
+ } = {}) {
20
+ // TODO: properly type guard
21
+ // we use this workaround for now to prevent changing behavior
22
+ if (element.disabled) return;
23
+
24
+ if (!skipClick) {
25
+ await this.click(element);
26
+ }
27
+
28
+ if (initialSelectionStart !== undefined) {
29
+ (0, _utils.setSelectionRange)(element, initialSelectionStart, initialSelectionEnd != null ? initialSelectionEnd : initialSelectionStart);
30
+ }
31
+
32
+ await this.keyboard(text);
33
+
34
+ if (!skipAutoClose) {
35
+ await (0, _keyboard.releaseAllKeys)(this[_config.Config]);
36
+ }
37
+ }
@@ -0,0 +1,5 @@
1
+ import { UserEvent } from '../setup';
2
+ export interface uploadInit {
3
+ changeInit?: EventInit;
4
+ }
5
+ export declare function upload(this: UserEvent, element: HTMLElement, fileOrFiles: File | File[]): Promise<void>;
@@ -7,11 +7,11 @@ exports.upload = upload;
7
7
 
8
8
  var _dom = require("@testing-library/dom");
9
9
 
10
- var _utils = require("./utils");
10
+ var _utils = require("../utils");
11
11
 
12
- function upload(element, fileOrFiles, init, {
13
- applyAccept = false
14
- } = {}) {
12
+ var _setup = require("../setup");
13
+
14
+ async function upload(element, fileOrFiles) {
15
15
  var _input$files;
16
16
 
17
17
  const input = (0, _utils.isElementType)(element, 'label') ? element.control : element;
@@ -23,8 +23,8 @@ function upload(element, fileOrFiles, init, {
23
23
  }
24
24
 
25
25
  if ((0, _utils.isDisabled)(element)) return;
26
- this.click(element);
27
- const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter(file => !applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? undefined : 1); // blur fires when the file selector pops up
26
+ await this.click(element);
27
+ const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter(file => !this[_setup.Config].applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? undefined : 1); // blur fires when the file selector pops up
28
28
 
29
29
  (0, _utils.blur)(element); // focus fires when they make their selection
30
30
 
@@ -36,41 +36,13 @@ function upload(element, fileOrFiles, init, {
36
36
  return f === ((_input$files2 = input.files) == null ? void 0 : _input$files2.item(i));
37
37
  })) {
38
38
  return;
39
- } // the event fired in the browser isn't actually an "input" or "change" event
40
- // but a new Event with a type set to "input" and "change"
41
- // Kinda odd...
42
-
43
-
44
- const inputFiles = { ...files,
45
- length: files.length,
46
- item: index => files[index],
47
-
48
- [Symbol.iterator]() {
49
- let i = 0;
50
- return {
51
- next: () => ({
52
- done: i >= files.length,
53
- value: files[i++]
54
- })
55
- };
56
- }
39
+ }
57
40
 
58
- };
59
- (0, _dom.fireEvent)(input, (0, _dom.createEvent)('input', input, {
60
- target: {
61
- files: inputFiles
62
- },
63
- bubbles: true,
64
- cancelable: false,
65
- composed: true
66
- }));
67
-
68
- _dom.fireEvent.change(input, {
69
- target: {
70
- files: inputFiles
71
- },
72
- ...(init == null ? void 0 : init.changeInit)
73
- });
41
+ (0, _utils.setFiles)(input, (0, _utils.createFileList)(files));
42
+
43
+ _dom.fireEvent.input(input);
44
+
45
+ _dom.fireEvent.change(input);
74
46
  }
75
47
 
76
48
  function isAcceptableFile(file, accept) {
@@ -7,7 +7,17 @@ exports.createFileList = createFileList;
7
7
 
8
8
  // FileList can not be created per constructor.
9
9
  function createFileList(files) {
10
- const f = [...files];
11
- Object.setPrototypeOf(f, FileList.prototype);
12
- return f;
10
+ const list = { ...files,
11
+ length: files.length,
12
+ item: index => list[index],
13
+ [Symbol.iterator]: function* nextFile() {
14
+ for (let i = 0; i < list.length; i++) {
15
+ yield list[i];
16
+ }
17
+ }
18
+ };
19
+ list.constructor = FileList;
20
+ Object.setPrototypeOf(list, FileList.prototype);
21
+ Object.freeze(list);
22
+ return list;
13
23
  }
@@ -0,0 +1,12 @@
1
+ declare const fakeFiles: unique symbol;
2
+ declare global {
3
+ interface HTMLInputElement {
4
+ [fakeFiles]?: {
5
+ restore: () => void;
6
+ };
7
+ }
8
+ }
9
+ export declare function setFiles(el: HTMLInputElement & {
10
+ type: 'file';
11
+ }, files: FileList): void;
12
+ export {};
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setFiles = setFiles;
7
+ // It is not possible to create a real FileList programmatically.
8
+ // Therefore assigning `files` property with a programmatically created FileList results in an error.
9
+ // Just assigning the property (as per fireEvent) breaks the interweaving with the `value` property.
10
+ const fakeFiles = Symbol('files and value properties are mocked');
11
+
12
+ function setFiles(el, files) {
13
+ var _el$fakeFiles;
14
+
15
+ (_el$fakeFiles = el[fakeFiles]) == null ? void 0 : _el$fakeFiles.restore();
16
+ const objectDescriptors = Object.getOwnPropertyDescriptors(el);
17
+ const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
18
+
19
+ function restore() {
20
+ Object.defineProperties(el, {
21
+ files: { ...prototypeDescriptors.files,
22
+ ...objectDescriptors.files
23
+ },
24
+ value: { ...prototypeDescriptors.value,
25
+ ...objectDescriptors.value
26
+ },
27
+ type: { ...prototypeDescriptors.type,
28
+ ...objectDescriptors.type
29
+ }
30
+ });
31
+ }
32
+
33
+ el[fakeFiles] = {
34
+ restore
35
+ };
36
+ Object.defineProperties(el, {
37
+ files: { ...prototypeDescriptors.files,
38
+ ...objectDescriptors.files,
39
+ get: () => files
40
+ },
41
+ value: { ...prototypeDescriptors.value,
42
+ ...objectDescriptors.value,
43
+ get: () => files.length ? `C:\\fakepath\\${files[0].name}` : '',
44
+
45
+ set(v) {
46
+ if (v === '') {
47
+ restore();
48
+ } else {
49
+ var _objectDescriptors$va;
50
+
51
+ (_objectDescriptors$va = objectDescriptors.value.set) == null ? void 0 : _objectDescriptors$va.call(el, v);
52
+ }
53
+ }
54
+
55
+ },
56
+ // eslint-disable-next-line accessor-pairs
57
+ type: { ...prototypeDescriptors.type,
58
+ ...objectDescriptors.type,
59
+
60
+ set(v) {
61
+ if (v !== 'file') {
62
+ restore() // In the browser the value will be empty.
63
+ // In Jsdom the value will be the same as
64
+ // before this element became file input - which might be empty.
65
+ ;
66
+ el.type = v;
67
+ }
68
+ }
69
+
70
+ }
71
+ });
72
+ }
@@ -13,6 +13,7 @@ export * from './edit/isValidDateValue';
13
13
  export * from './edit/isValidInputTimeValue';
14
14
  export * from './edit/maxLength';
15
15
  export * from './edit/prepareInput';
16
+ export * from './edit/setFiles';
16
17
  export * from './focus/blur';
17
18
  export * from './focus/copySelection';
18
19
  export * from './focus/focus';
@@ -25,6 +26,7 @@ export * from './focus/selector';
25
26
  export * from './keyDef/readNextDescriptor';
26
27
  export * from './misc/eventWrapper';
27
28
  export * from './misc/findClosest';
29
+ export * from './misc/getDocumentFromNode';
28
30
  export * from './misc/isDescendantOrSelf';
29
31
  export * from './misc/isElementType';
30
32
  export * from './misc/isVisible';
@@ -199,6 +199,19 @@ Object.keys(_prepareInput).forEach(function (key) {
199
199
  });
200
200
  });
201
201
 
202
+ var _setFiles = require("./edit/setFiles");
203
+
204
+ Object.keys(_setFiles).forEach(function (key) {
205
+ if (key === "default" || key === "__esModule") return;
206
+ if (key in exports && exports[key] === _setFiles[key]) return;
207
+ Object.defineProperty(exports, key, {
208
+ enumerable: true,
209
+ get: function () {
210
+ return _setFiles[key];
211
+ }
212
+ });
213
+ });
214
+
202
215
  var _blur = require("./focus/blur");
203
216
 
204
217
  Object.keys(_blur).forEach(function (key) {
@@ -355,6 +368,19 @@ Object.keys(_findClosest).forEach(function (key) {
355
368
  });
356
369
  });
357
370
 
371
+ var _getDocumentFromNode = require("./misc/getDocumentFromNode");
372
+
373
+ Object.keys(_getDocumentFromNode).forEach(function (key) {
374
+ if (key === "default" || key === "__esModule") return;
375
+ if (key in exports && exports[key] === _getDocumentFromNode[key]) return;
376
+ Object.defineProperty(exports, key, {
377
+ enumerable: true,
378
+ get: function () {
379
+ return _getDocumentFromNode[key];
380
+ }
381
+ });
382
+ });
383
+
358
384
  var _isDescendantOrSelf = require("./misc/isDescendantOrSelf");
359
385
 
360
386
  Object.keys(_isDescendantOrSelf).forEach(function (key) {
@@ -0,0 +1 @@
1
+ export declare function getDocumentFromNode(el: Node): Document | null;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getDocumentFromNode = getDocumentFromNode;
7
+
8
+ function getDocumentFromNode(el) {
9
+ return isDocument(el) ? el : el.ownerDocument;
10
+ }
11
+
12
+ function isDocument(node) {
13
+ return node.nodeType === 9;
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/user-event",
3
- "version": "14.0.0-alpha.14",
3
+ "version": "14.0.0-alpha.18",
4
4
  "description": "Fire events the same way the user does",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [
package/dist/click.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import { PointerOptions } from './utils';
2
- import type { UserEvent } from './setup';
3
- export declare interface clickOptions {
4
- skipHover?: boolean;
5
- clickCount?: number;
6
- }
7
- export declare function click(this: UserEvent, element: Element, { skipHover, skipPointerEventsCheck, }?: clickOptions & PointerOptions): void;
8
- export declare function dblClick(this: UserEvent, element: Element, { skipPointerEventsCheck }?: clickOptions & PointerOptions): void;
9
- export declare function tripleClick(this: UserEvent, element: Element, { skipPointerEventsCheck }?: clickOptions & PointerOptions): void;
package/dist/click.js DELETED
@@ -1,61 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.click = click;
7
- exports.dblClick = dblClick;
8
- exports.tripleClick = tripleClick;
9
-
10
- var _utils = require("./utils");
11
-
12
- function click(element, {
13
- skipHover = false,
14
- skipPointerEventsCheck = false
15
- } = {}) {
16
- if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
17
- throw new Error('unable to click element as it has or inherits pointer-events set to "none".');
18
- } // istanbul ignore else
19
-
20
-
21
- if (!skipHover) // We just checked for `pointerEvents`. We can always skip this one in `hover`.
22
- this.hover(element, {
23
- skipPointerEventsCheck: true
24
- });
25
- this.pointer({
26
- keys: '[MouseLeft]',
27
- target: element
28
- });
29
- }
30
-
31
- function dblClick(element, {
32
- skipPointerEventsCheck = false
33
- } = {}) {
34
- if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
35
- throw new Error('unable to double-click element as it has or inherits pointer-events set to "none".');
36
- }
37
-
38
- this.hover(element, {
39
- skipPointerEventsCheck: true
40
- });
41
- this.pointer({
42
- keys: '[MouseLeft][MouseLeft]',
43
- target: element
44
- });
45
- }
46
-
47
- function tripleClick(element, {
48
- skipPointerEventsCheck = false
49
- } = {}) {
50
- if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
51
- throw new Error('unable to triple-click element as it has or inherits pointer-events set to "none".');
52
- }
53
-
54
- this.hover(element, {
55
- skipPointerEventsCheck: true
56
- });
57
- this.pointer({
58
- keys: '[MouseLeft][MouseLeft][MouseLeft]',
59
- target: element
60
- });
61
- }
package/dist/hover.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import type { UserEvent } from './setup';
2
- import { PointerOptions } from './utils';
3
- export declare function hover(this: UserEvent, element: Element, { skipPointerEventsCheck }?: PointerOptions): void;
4
- export declare function unhover(this: UserEvent, element: Element, { skipPointerEventsCheck }?: PointerOptions): void;
package/dist/hover.js DELETED
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.hover = hover;
7
- exports.unhover = unhover;
8
-
9
- var _pointer = require("./pointer");
10
-
11
- var _utils = require("./utils");
12
-
13
- function hover(element, {
14
- skipPointerEventsCheck = false
15
- } = {}) {
16
- if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
17
- throw new Error('unable to hover element as it has or inherits pointer-events set to "none".');
18
- }
19
-
20
- const pointerState = (0, _pointer.createPointerState)();
21
- pointerState.position.mouse.target = element.ownerDocument.body;
22
- this.pointer({
23
- target: element
24
- }, {
25
- pointerState
26
- });
27
- }
28
-
29
- function unhover(element, {
30
- skipPointerEventsCheck = false
31
- } = {}) {
32
- if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
33
- throw new Error('unable to unhover element as it has or inherits pointer-events set to "none".');
34
- }
35
-
36
- const pointerState = (0, _pointer.createPointerState)();
37
- pointerState.position.mouse.target = element;
38
- this.pointer({
39
- target: element.ownerDocument.body
40
- }, {
41
- pointerState
42
- });
43
- }
@@ -1,55 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getNextKeyDef = getNextKeyDef;
7
-
8
- var _utils = require("../utils");
9
-
10
- /**
11
- * Get the next key from keyMap
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 getNextKeyDef(text, options) {
21
- var _options$keyboardMap$;
22
-
23
- const {
24
- type,
25
- descriptor,
26
- consumedLength,
27
- releasePrevious,
28
- releaseSelf = true,
29
- repeat
30
- } = (0, _utils.readNextDescriptor)(text);
31
- const keyDef = (_options$keyboardMap$ = options.keyboardMap.find(def => {
32
- if (type === '[') {
33
- var _def$code;
34
-
35
- return ((_def$code = def.code) == null ? void 0 : _def$code.toLowerCase()) === descriptor.toLowerCase();
36
- } else if (type === '{') {
37
- var _def$key;
38
-
39
- return ((_def$key = def.key) == null ? void 0 : _def$key.toLowerCase()) === descriptor.toLowerCase();
40
- }
41
-
42
- return def.key === descriptor;
43
- })) != null ? _options$keyboardMap$ : {
44
- key: 'Unknown',
45
- code: 'Unknown',
46
- [type === '[' ? 'code' : 'key']: descriptor
47
- };
48
- return {
49
- keyDef,
50
- consumedLength,
51
- releasePrevious,
52
- releaseSelf,
53
- repeat
54
- };
55
- }
@@ -1,3 +0,0 @@
1
- import { keyboardState, keyboardOptions } from './types';
2
- export declare function keyboardImplementation(text: string, options: keyboardOptions, state: keyboardState): Promise<void>;
3
- export declare function releaseAllKeys(options: keyboardOptions, state: keyboardState): void;
@@ -1,165 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.keyboardImplementation = keyboardImplementation;
7
- exports.releaseAllKeys = releaseAllKeys;
8
-
9
- var _dom = require("@testing-library/dom");
10
-
11
- var _utils = require("../utils");
12
-
13
- var _getNextKeyDef = require("./getNextKeyDef");
14
-
15
- var plugins = _interopRequireWildcard(require("./plugins"));
16
-
17
- var _getEventProps = require("./getEventProps");
18
-
19
- 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); }
20
-
21
- 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; }
22
-
23
- async function keyboardImplementation(text, options, state) {
24
- var _state$repeatKey;
25
-
26
- const {
27
- document
28
- } = options;
29
-
30
- const getCurrentElement = () => getActive(document);
31
-
32
- const {
33
- keyDef,
34
- consumedLength,
35
- releasePrevious,
36
- releaseSelf,
37
- repeat
38
- } = (_state$repeatKey = state.repeatKey) != null ? _state$repeatKey : (0, _getNextKeyDef.getNextKeyDef)(text, options);
39
- const pressed = state.pressed.find(p => p.keyDef === keyDef); // Release the key automatically if it was pressed before.
40
- // Do not release the key on iterations on `state.repeatKey`.
41
-
42
- if (pressed && !state.repeatKey) {
43
- keyup(keyDef, getCurrentElement, options, state, pressed.unpreventedDefault);
44
- }
45
-
46
- if (!releasePrevious) {
47
- const unpreventedDefault = keydown(keyDef, getCurrentElement, options, state);
48
-
49
- if (unpreventedDefault && hasKeyPress(keyDef, state)) {
50
- keypress(keyDef, getCurrentElement, options, state);
51
- } // Release the key only on the last iteration on `state.repeatKey`.
52
-
53
-
54
- if (releaseSelf && repeat <= 1) {
55
- keyup(keyDef, getCurrentElement, options, state, unpreventedDefault);
56
- }
57
- }
58
-
59
- if (repeat > 1) {
60
- state.repeatKey = {
61
- // don't consume again on the next iteration
62
- consumedLength: 0,
63
- keyDef,
64
- releasePrevious,
65
- releaseSelf,
66
- repeat: repeat - 1
67
- };
68
- } else {
69
- delete state.repeatKey;
70
- }
71
-
72
- if (text.length > consumedLength || repeat > 1) {
73
- if (options.delay > 0) {
74
- await (0, _utils.wait)(options.delay);
75
- }
76
-
77
- return keyboardImplementation(text.slice(consumedLength), options, state);
78
- }
79
-
80
- return void undefined;
81
- }
82
-
83
- function getActive(document) {
84
- var _getActiveElement;
85
-
86
- return (_getActiveElement = (0, _utils.getActiveElement)(document)) != null ? _getActiveElement :
87
- /* istanbul ignore next */
88
- document.body;
89
- }
90
-
91
- function releaseAllKeys(options, state) {
92
- const getCurrentElement = () => getActive(options.document);
93
-
94
- for (const k of state.pressed) {
95
- keyup(k.keyDef, getCurrentElement, options, state, k.unpreventedDefault);
96
- }
97
- }
98
-
99
- function keydown(keyDef, getCurrentElement, options, state) {
100
- const element = getCurrentElement(); // clear carried characters when focus is moved
101
-
102
- if (element !== state.activeElement) {
103
- state.carryValue = undefined;
104
- state.carryChar = '';
105
- }
106
-
107
- state.activeElement = element;
108
- applyPlugins(plugins.preKeydownBehavior, keyDef, element, options, state);
109
-
110
- const unpreventedDefault = _dom.fireEvent.keyDown(element, (0, _getEventProps.getKeyEventProps)(keyDef, state));
111
-
112
- state.pressed.push({
113
- keyDef,
114
- unpreventedDefault
115
- });
116
-
117
- if (unpreventedDefault) {
118
- // all default behavior like keypress/submit etc is applied to the currentElement
119
- applyPlugins(plugins.keydownBehavior, keyDef, getCurrentElement(), options, state);
120
- }
121
-
122
- return unpreventedDefault;
123
- }
124
-
125
- function keypress(keyDef, getCurrentElement, options, state) {
126
- const element = getCurrentElement();
127
-
128
- const unpreventedDefault = _dom.fireEvent.keyPress(element, { ...(0, _getEventProps.getKeyEventProps)(keyDef, state),
129
- charCode: keyDef.key === 'Enter' ? 13 : String(keyDef.key).charCodeAt(0)
130
- });
131
-
132
- if (unpreventedDefault) {
133
- applyPlugins(plugins.keypressBehavior, keyDef, getCurrentElement(), options, state);
134
- }
135
- }
136
-
137
- function keyup(keyDef, getCurrentElement, options, state, unprevented) {
138
- const element = getCurrentElement();
139
- applyPlugins(plugins.preKeyupBehavior, keyDef, element, options, state);
140
-
141
- const unpreventedDefault = _dom.fireEvent.keyUp(element, (0, _getEventProps.getKeyEventProps)(keyDef, state));
142
-
143
- if (unprevented && unpreventedDefault) {
144
- applyPlugins(plugins.keyupBehavior, keyDef, getCurrentElement(), options, state);
145
- }
146
-
147
- state.pressed = state.pressed.filter(k => k.keyDef !== keyDef);
148
- applyPlugins(plugins.postKeyupBehavior, keyDef, element, options, state);
149
- }
150
-
151
- function applyPlugins(pluginCollection, keyDef, element, options, state) {
152
- const plugin = pluginCollection.find(p => p.matches(keyDef, element, options, state));
153
-
154
- if (plugin) {
155
- plugin.handle(keyDef, element, options, state);
156
- }
157
-
158
- return !!plugin;
159
- }
160
-
161
- function hasKeyPress(keyDef, state) {
162
- var _keyDef$key;
163
-
164
- return (((_keyDef$key = keyDef.key) == null ? void 0 : _keyDef$key.length) === 1 || keyDef.key === 'Enter') && !state.modifiers.ctrl && !state.modifiers.alt;
165
- }
@@ -1,4 +0,0 @@
1
- import { PointerOptions } from './utils';
2
- import type { UserEvent } from './setup';
3
- export declare function selectOptions(this: UserEvent, select: Element, values: HTMLElement | HTMLElement[] | string[] | string, options?: PointerOptions): void;
4
- export declare function deselectOptions(this: UserEvent, select: Element, values: HTMLElement | HTMLElement[] | string[] | string, options?: PointerOptions): void;