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

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 (76) 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/getNextKeyDef.d.ts +2 -2
  18. package/dist/keyboard/getNextKeyDef.js +4 -4
  19. package/dist/keyboard/index.d.ts +6 -17
  20. package/dist/keyboard/index.js +9 -43
  21. package/dist/keyboard/keyboardImplementation.d.ts +3 -3
  22. package/dist/keyboard/keyboardImplementation.js +47 -44
  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 -12
  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 +21 -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} +6 -6
  60. package/dist/utils/index.d.ts +1 -0
  61. package/dist/utils/index.js +13 -0
  62. package/dist/utils/misc/getDocumentFromNode.d.ts +1 -0
  63. package/dist/utils/misc/getDocumentFromNode.js +14 -0
  64. package/package.json +1 -1
  65. package/dist/click.d.ts +0 -9
  66. package/dist/click.js +0 -61
  67. package/dist/hover.d.ts +0 -4
  68. package/dist/hover.js +0 -43
  69. package/dist/selectOptions.d.ts +0 -4
  70. package/dist/setup.d.ts +0 -100
  71. package/dist/setup.js +0 -241
  72. package/dist/tab.d.ts +0 -5
  73. package/dist/tab.js +0 -12
  74. package/dist/type.d.ts +0 -14
  75. package/dist/type.js +0 -74
  76. package/dist/upload.d.ts +0 -9
@@ -1,11 +1,2 @@
1
- import type { UserEvent } from '../setup';
2
- export interface copyOptions {
3
- document?: Document;
4
- writeToClipboard?: boolean;
5
- }
6
- export declare function copy(this: UserEvent, options: Omit<copyOptions, 'writeToClipboard'> & {
7
- writeToClipboard: true;
8
- }): Promise<DataTransfer>;
9
- export declare function copy(this: UserEvent, options?: Omit<copyOptions, 'writeToClipboard'> & {
10
- writeToClipboard?: boolean;
11
- }): DataTransfer;
1
+ import { UserEvent } from '../setup';
2
+ export declare function copy(this: UserEvent): Promise<DataTransfer | undefined>;
@@ -7,12 +7,14 @@ exports.copy = copy;
7
7
 
8
8
  var _dom = require("@testing-library/dom");
9
9
 
10
+ var _setup = require("../setup");
11
+
10
12
  var _utils = require("../utils");
11
13
 
12
- function copy(options) {
13
- var _options$document, _doc$activeElement;
14
+ async function copy() {
15
+ var _doc$activeElement;
14
16
 
15
- const doc = (_options$document = options == null ? void 0 : options.document) != null ? _options$document : document;
17
+ const doc = this[_setup.Config].document;
16
18
  const target = (_doc$activeElement = doc.activeElement) != null ? _doc$activeElement :
17
19
  /* istanbul ignore next */
18
20
  doc.body;
@@ -26,5 +28,9 @@ function copy(options) {
26
28
  clipboardData
27
29
  });
28
30
 
29
- return options != null && options.writeToClipboard ? (0, _utils.writeDataTransferToClipboard)(doc, clipboardData).then(() => clipboardData) : clipboardData;
31
+ if (this[_setup.Config].writeToClipboard) {
32
+ await (0, _utils.writeDataTransferToClipboard)(doc, clipboardData);
33
+ }
34
+
35
+ return clipboardData;
30
36
  }
@@ -1,11 +1,2 @@
1
- import type { UserEvent } from '../setup';
2
- export interface cutOptions {
3
- document?: Document;
4
- writeToClipboard?: boolean;
5
- }
6
- export declare function cut(this: UserEvent, options: Omit<cutOptions, 'writeToClipboard'> & {
7
- writeToClipboard: true;
8
- }): Promise<DataTransfer>;
9
- export declare function cut(this: UserEvent, options?: Omit<cutOptions, 'writeToClipboard'> & {
10
- writeToClipboard?: boolean;
11
- }): DataTransfer;
1
+ import { UserEvent } from '../setup';
2
+ export declare function cut(this: UserEvent): Promise<DataTransfer | undefined>;
@@ -7,12 +7,14 @@ exports.cut = cut;
7
7
 
8
8
  var _dom = require("@testing-library/dom");
9
9
 
10
+ var _setup = require("../setup");
11
+
10
12
  var _utils = require("../utils");
11
13
 
12
- function cut(options) {
13
- var _options$document, _doc$activeElement;
14
+ async function cut() {
15
+ var _doc$activeElement;
14
16
 
15
- const doc = (_options$document = options == null ? void 0 : options.document) != null ? _options$document : document;
17
+ const doc = this[_setup.Config].document;
16
18
  const target = (_doc$activeElement = doc.activeElement) != null ? _doc$activeElement :
17
19
  /* istanbul ignore next */
18
20
  doc.body;
@@ -32,5 +34,9 @@ function cut(options) {
32
34
  (_prepareInput = (0, _utils.prepareInput)('', target, 'deleteByCut')) == null ? void 0 : _prepareInput.commit();
33
35
  }
34
36
 
35
- return options != null && options.writeToClipboard ? (0, _utils.writeDataTransferToClipboard)(doc, clipboardData).then(() => clipboardData) : clipboardData;
37
+ if (this[_setup.Config].writeToClipboard) {
38
+ await (0, _utils.writeDataTransferToClipboard)(doc, clipboardData);
39
+ }
40
+
41
+ return clipboardData;
36
42
  }
@@ -1,6 +1,2 @@
1
- import type { UserEvent } from '../setup';
2
- export interface pasteOptions {
3
- document?: Document;
4
- }
5
- export declare function paste(this: UserEvent, clipboardData?: undefined, options?: pasteOptions): Promise<void>;
6
- export declare function paste(this: UserEvent, clipboardData: DataTransfer | string, options?: pasteOptions): void;
1
+ import { UserEvent } from '../setup';
2
+ export declare function paste(this: UserEvent, clipboardData?: DataTransfer | string): Promise<void>;
@@ -7,19 +7,21 @@ exports.paste = paste;
7
7
 
8
8
  var _dom = require("@testing-library/dom");
9
9
 
10
+ var _setup = require("../setup");
11
+
10
12
  var _utils = require("../utils");
11
13
 
12
- function paste(clipboardData, options) {
13
- var _options$document, _doc$activeElement;
14
+ async function paste(clipboardData) {
15
+ var _doc$activeElement, _ref;
14
16
 
15
- const doc = (_options$document = options == null ? void 0 : options.document) != null ? _options$document : document;
17
+ const doc = this[_setup.Config].document;
16
18
  const target = (_doc$activeElement = doc.activeElement) != null ? _doc$activeElement :
17
19
  /* istanbul ignore next */
18
20
  doc.body;
19
- const data = typeof clipboardData === 'string' ? getClipboardDataFromString(clipboardData) : clipboardData;
20
- return data ? pasteImpl(target, data) : (0, _utils.readDataTransferFromClipboard)(doc).then(dt => pasteImpl(target, dt), () => {
21
+ const data = (_ref = typeof clipboardData === 'string' ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _ref : await (0, _utils.readDataTransferFromClipboard)(doc).catch(() => {
21
22
  throw new Error('`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.');
22
23
  });
24
+ return pasteImpl(target, data);
23
25
  }
24
26
 
25
27
  function pasteImpl(target, clipboardData) {
@@ -0,0 +1,4 @@
1
+ import { UserEvent } from '../setup';
2
+ export declare function click(this: UserEvent, element: Element): Promise<void>;
3
+ export declare function dblClick(this: UserEvent, element: Element): Promise<void>;
4
+ export declare function tripleClick(this: UserEvent, element: Element): Promise<void>;
@@ -0,0 +1,52 @@
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
+ var _setup = require("../setup");
13
+
14
+ async function click(element) {
15
+ if (!this[_setup.Config].skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
16
+ throw new Error('unable to click element as it has or inherits pointer-events set to "none".');
17
+ }
18
+
19
+ const pointerIn = [];
20
+
21
+ if (!this[_setup.Config].skipHover) {
22
+ pointerIn.push({
23
+ target: element
24
+ });
25
+ }
26
+
27
+ pointerIn.push({
28
+ keys: '[MouseLeft]',
29
+ target: element
30
+ });
31
+ return this.pointer(pointerIn);
32
+ }
33
+
34
+ async function dblClick(element) {
35
+ if (!this[_setup.Config].skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
36
+ throw new Error('unable to double-click element as it has or inherits pointer-events set to "none".');
37
+ }
38
+
39
+ return this.pointer([{
40
+ target: element
41
+ }, '[MouseLeft][MouseLeft]']);
42
+ }
43
+
44
+ async function tripleClick(element) {
45
+ if (!this[_setup.Config].skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
46
+ throw new Error('unable to triple-click element as it has or inherits pointer-events set to "none".');
47
+ }
48
+
49
+ return this.pointer([{
50
+ target: element
51
+ }, '[MouseLeft][MouseLeft][MouseLeft]']);
52
+ }
@@ -0,0 +1,3 @@
1
+ import { UserEvent } from '../setup';
2
+ export declare function hover(this: UserEvent, element: Element): Promise<void>;
3
+ export declare function unhover(this: UserEvent, element: Element): Promise<void>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.hover = hover;
7
+ exports.unhover = unhover;
8
+
9
+ var _setup = require("../setup");
10
+
11
+ var _utils = require("../utils");
12
+
13
+ async function hover(element) {
14
+ if (!this[_setup.Config].skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
15
+ throw new Error('unable to hover element as it has or inherits pointer-events set to "none".');
16
+ }
17
+
18
+ return this.pointer({
19
+ target: element
20
+ });
21
+ }
22
+
23
+ async function unhover(element) {
24
+ if (!this[_setup.Config].skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
25
+ throw new Error('unable to unhover element as it has or inherits pointer-events set to "none".');
26
+ }
27
+
28
+ return this.pointer({
29
+ target: element.ownerDocument.body
30
+ });
31
+ }
@@ -0,0 +1,3 @@
1
+ export * from './click';
2
+ export * from './hover';
3
+ export * from './tab';
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _click = require("./click");
8
+
9
+ Object.keys(_click).forEach(function (key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ if (key in exports && exports[key] === _click[key]) return;
12
+ Object.defineProperty(exports, key, {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _click[key];
16
+ }
17
+ });
18
+ });
19
+
20
+ var _hover = require("./hover");
21
+
22
+ Object.keys(_hover).forEach(function (key) {
23
+ if (key === "default" || key === "__esModule") return;
24
+ if (key in exports && exports[key] === _hover[key]) return;
25
+ Object.defineProperty(exports, key, {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _hover[key];
29
+ }
30
+ });
31
+ });
32
+
33
+ var _tab = require("./tab");
34
+
35
+ Object.keys(_tab).forEach(function (key) {
36
+ if (key === "default" || key === "__esModule") return;
37
+ if (key in exports && exports[key] === _tab[key]) return;
38
+ Object.defineProperty(exports, key, {
39
+ enumerable: true,
40
+ get: function () {
41
+ return _tab[key];
42
+ }
43
+ });
44
+ });
@@ -0,0 +1,4 @@
1
+ import type { UserEvent } from '../setup';
2
+ export declare function tab(this: UserEvent, { shift, }?: {
3
+ shift?: boolean;
4
+ }): Promise<void>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.tab = tab;
7
+
8
+ async function tab({
9
+ shift
10
+ } = {}) {
11
+ return this.keyboard(shift === true ? '{Shift>}{Tab}{/Shift}' : shift === false ? '[/ShiftLeft][/ShiftRight]{Tab}' : '{Tab}');
12
+ }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- import { UserEventApis, setup } from './setup';
2
- declare const userEvent: UserEventApis & {
3
- setup: typeof setup;
4
- };
5
- export default userEvent;
1
+ export { userEvent as default } from './setup';
6
2
  export type { keyboardKey } from './keyboard';
3
+ export type { pointerKey } from './pointer';
package/dist/index.js CHANGED
@@ -3,12 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
7
-
8
- var _setup = require("./setup");
6
+ Object.defineProperty(exports, "default", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _setup.userEvent;
10
+ }
11
+ });
9
12
 
10
- const userEvent = { ...Object.fromEntries(Object.entries(_setup.userEventApis).map(([k, f]) => [k, (...a) => f.apply(userEvent, a)])),
11
- setup: _setup.setup
12
- };
13
- var _default = userEvent;
14
- exports.default = _default;
13
+ var _setup = require("./setup");
@@ -1,4 +1,4 @@
1
- import { keyboardKey, keyboardOptions } from './types';
1
+ import { keyboardKey } from './types';
2
2
  /**
3
3
  * Get the next key from keyMap
4
4
  *
@@ -9,7 +9,7 @@ import { keyboardKey, keyboardOptions } from './types';
9
9
  * When keeping the key pressed you can choose how long (how many keydown and keypress) the key is pressed `{key>3}`.
10
10
  * You can then release the key per `{key>3/}` or keep it pressed and continue with the next key.
11
11
  */
12
- export declare function getNextKeyDef(text: string, options: keyboardOptions): {
12
+ export declare function getNextKeyDef(keyboardMap: keyboardKey[], text: string): {
13
13
  keyDef: keyboardKey;
14
14
  consumedLength: number;
15
15
  releasePrevious: boolean;
@@ -17,8 +17,8 @@ var _utils = require("../utils");
17
17
  * When keeping the key pressed you can choose how long (how many keydown and keypress) the key is pressed `{key>3}`.
18
18
  * You can then release the key per `{key>3/}` or keep it pressed and continue with the next key.
19
19
  */
20
- function getNextKeyDef(text, options) {
21
- var _options$keyboardMap$;
20
+ function getNextKeyDef(keyboardMap, text) {
21
+ var _keyboardMap$find;
22
22
 
23
23
  const {
24
24
  type,
@@ -28,7 +28,7 @@ function getNextKeyDef(text, options) {
28
28
  releaseSelf = true,
29
29
  repeat
30
30
  } = (0, _utils.readNextDescriptor)(text);
31
- const keyDef = (_options$keyboardMap$ = options.keyboardMap.find(def => {
31
+ const keyDef = (_keyboardMap$find = keyboardMap.find(def => {
32
32
  if (type === '[') {
33
33
  var _def$code;
34
34
 
@@ -40,7 +40,7 @@ function getNextKeyDef(text, options) {
40
40
  }
41
41
 
42
42
  return def.key === descriptor;
43
- })) != null ? _options$keyboardMap$ : {
43
+ })) != null ? _keyboardMap$find : {
44
44
  key: 'Unknown',
45
45
  code: 'Unknown',
46
46
  [type === '[' ? 'code' : 'key']: descriptor
@@ -1,18 +1,7 @@
1
- import { keyboardState, keyboardOptions, keyboardKey } from './types';
2
- export type { keyboardOptions, keyboardKey };
3
- export declare function keyboard(text: string, options?: Partial<keyboardOptions & {
4
- keyboardState: keyboardState;
5
- delay: 0;
6
- }>): keyboardState;
7
- export declare function keyboard(text: string, options: Partial<keyboardOptions & {
8
- keyboardState: keyboardState;
9
- delay: number;
10
- }>): Promise<keyboardState>;
11
- export declare function keyboardImplementationWrapper(text: string, config?: Partial<keyboardOptions & {
12
- keyboardState: keyboardState;
13
- }>): {
14
- promise: Promise<void>;
15
- state: keyboardState;
16
- releaseAllKeys: () => void;
17
- };
1
+ import { UserEvent } from '../setup';
2
+ import { releaseAllKeys } from './keyboardImplementation';
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>;
18
7
  export declare function createKeyboardState(): keyboardState;
@@ -5,53 +5,19 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.createKeyboardState = createKeyboardState;
7
7
  exports.keyboard = keyboard;
8
- exports.keyboardImplementationWrapper = keyboardImplementationWrapper;
9
-
10
- var _dom = require("@testing-library/dom");
8
+ Object.defineProperty(exports, "releaseAllKeys", {
9
+ enumerable: true,
10
+ get: function () {
11
+ return _keyboardImplementation.releaseAllKeys;
12
+ }
13
+ });
11
14
 
12
- var _document = require("../document");
15
+ var _setup = require("../setup");
13
16
 
14
17
  var _keyboardImplementation = require("./keyboardImplementation");
15
18
 
16
- var _keyMap = require("./keyMap");
17
-
18
- function keyboard(text, options) {
19
- var _options$delay;
20
-
21
- const {
22
- promise,
23
- state
24
- } = keyboardImplementationWrapper(text, options);
25
-
26
- if (((_options$delay = options == null ? void 0 : options.delay) != null ? _options$delay : 0) > 0) {
27
- return (0, _dom.getConfig)().asyncWrapper(() => promise.then(() => state));
28
- } else {
29
- // prevent users from dealing with UnhandledPromiseRejectionWarning in sync call
30
- promise.catch(console.error);
31
- return state;
32
- }
33
- }
34
-
35
- function keyboardImplementationWrapper(text, config = {}) {
36
- const {
37
- keyboardState: state = createKeyboardState(),
38
- delay = 0,
39
- document: doc = document,
40
- autoModify = false,
41
- keyboardMap = _keyMap.defaultKeyMap
42
- } = config;
43
- const options = {
44
- delay,
45
- document: doc,
46
- autoModify,
47
- keyboardMap
48
- };
49
- (0, _document.prepareDocument)(document);
50
- return {
51
- promise: (0, _keyboardImplementation.keyboardImplementation)(text, options, state),
52
- state,
53
- releaseAllKeys: () => (0, _keyboardImplementation.releaseAllKeys)(options, state)
54
- };
19
+ async function keyboard(text) {
20
+ return (0, _keyboardImplementation.keyboardImplementation)(this[_setup.Config], text);
55
21
  }
56
22
 
57
23
  function createKeyboardState() {
@@ -1,3 +1,3 @@
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
+ import { Config } from '../setup';
2
+ export declare function keyboardImplementation(config: Config, text: string): Promise<void>;
3
+ export declare function releaseAllKeys(config: Config): Promise<void>;
@@ -20,12 +20,15 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
20
20
 
21
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
22
 
23
- async function keyboardImplementation(text, options, state) {
24
- var _state$repeatKey;
23
+ async function keyboardImplementation(config, text) {
24
+ var _keyboardState$repeat;
25
25
 
26
26
  const {
27
- document
28
- } = options;
27
+ document,
28
+ keyboardState,
29
+ keyboardMap,
30
+ delay
31
+ } = config;
29
32
 
30
33
  const getCurrentElement = () => getActive(document);
31
34
 
@@ -35,29 +38,29 @@ async function keyboardImplementation(text, options, state) {
35
38
  releasePrevious,
36
39
  releaseSelf,
37
40
  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.
41
+ } = (_keyboardState$repeat = keyboardState.repeatKey) != null ? _keyboardState$repeat : (0, _getNextKeyDef.getNextKeyDef)(keyboardMap, text);
42
+ const pressed = keyboardState.pressed.find(p => p.keyDef === keyDef); // Release the key automatically if it was pressed before.
40
43
  // Do not release the key on iterations on `state.repeatKey`.
41
44
 
42
- if (pressed && !state.repeatKey) {
43
- keyup(keyDef, getCurrentElement, options, state, pressed.unpreventedDefault);
45
+ if (pressed && !keyboardState.repeatKey) {
46
+ await keyup(keyDef, getCurrentElement, config, pressed.unpreventedDefault);
44
47
  }
45
48
 
46
49
  if (!releasePrevious) {
47
- const unpreventedDefault = keydown(keyDef, getCurrentElement, options, state);
50
+ const unpreventedDefault = await keydown(keyDef, getCurrentElement, config);
48
51
 
49
- if (unpreventedDefault && hasKeyPress(keyDef, state)) {
50
- keypress(keyDef, getCurrentElement, options, state);
52
+ if (unpreventedDefault && hasKeyPress(keyDef, config)) {
53
+ await keypress(keyDef, getCurrentElement, config);
51
54
  } // Release the key only on the last iteration on `state.repeatKey`.
52
55
 
53
56
 
54
57
  if (releaseSelf && repeat <= 1) {
55
- keyup(keyDef, getCurrentElement, options, state, unpreventedDefault);
58
+ await keyup(keyDef, getCurrentElement, config, unpreventedDefault);
56
59
  }
57
60
  }
58
61
 
59
62
  if (repeat > 1) {
60
- state.repeatKey = {
63
+ keyboardState.repeatKey = {
61
64
  // don't consume again on the next iteration
62
65
  consumedLength: 0,
63
66
  keyDef,
@@ -66,15 +69,15 @@ async function keyboardImplementation(text, options, state) {
66
69
  repeat: repeat - 1
67
70
  };
68
71
  } else {
69
- delete state.repeatKey;
72
+ delete keyboardState.repeatKey;
70
73
  }
71
74
 
72
75
  if (text.length > consumedLength || repeat > 1) {
73
- if (options.delay > 0) {
74
- await (0, _utils.wait)(options.delay);
76
+ if (typeof delay === 'number') {
77
+ await (0, _utils.wait)(delay);
75
78
  }
76
79
 
77
- return keyboardImplementation(text.slice(consumedLength), options, state);
80
+ return keyboardImplementation(config, text.slice(consumedLength));
78
81
  }
79
82
 
80
83
  return void undefined;
@@ -88,78 +91,78 @@ function getActive(document) {
88
91
  document.body;
89
92
  }
90
93
 
91
- function releaseAllKeys(options, state) {
92
- const getCurrentElement = () => getActive(options.document);
94
+ async function releaseAllKeys(config) {
95
+ const getCurrentElement = () => getActive(config.document);
93
96
 
94
- for (const k of state.pressed) {
95
- keyup(k.keyDef, getCurrentElement, options, state, k.unpreventedDefault);
97
+ for (const k of config.keyboardState.pressed) {
98
+ await keyup(k.keyDef, getCurrentElement, config, k.unpreventedDefault);
96
99
  }
97
100
  }
98
101
 
99
- function keydown(keyDef, getCurrentElement, options, state) {
102
+ async function keydown(keyDef, getCurrentElement, config) {
100
103
  const element = getCurrentElement(); // clear carried characters when focus is moved
101
104
 
102
- if (element !== state.activeElement) {
103
- state.carryValue = undefined;
104
- state.carryChar = '';
105
+ if (element !== config.keyboardState.activeElement) {
106
+ config.keyboardState.carryValue = undefined;
107
+ config.keyboardState.carryChar = '';
105
108
  }
106
109
 
107
- state.activeElement = element;
108
- applyPlugins(plugins.preKeydownBehavior, keyDef, element, options, state);
110
+ config.keyboardState.activeElement = element;
111
+ applyPlugins(plugins.preKeydownBehavior, keyDef, element, config);
109
112
 
110
- const unpreventedDefault = _dom.fireEvent.keyDown(element, (0, _getEventProps.getKeyEventProps)(keyDef, state));
113
+ const unpreventedDefault = _dom.fireEvent.keyDown(element, (0, _getEventProps.getKeyEventProps)(keyDef, config.keyboardState));
111
114
 
112
- state.pressed.push({
115
+ config.keyboardState.pressed.push({
113
116
  keyDef,
114
117
  unpreventedDefault
115
118
  });
116
119
 
117
120
  if (unpreventedDefault) {
118
121
  // all default behavior like keypress/submit etc is applied to the currentElement
119
- applyPlugins(plugins.keydownBehavior, keyDef, getCurrentElement(), options, state);
122
+ applyPlugins(plugins.keydownBehavior, keyDef, getCurrentElement(), config);
120
123
  }
121
124
 
122
125
  return unpreventedDefault;
123
126
  }
124
127
 
125
- function keypress(keyDef, getCurrentElement, options, state) {
128
+ async function keypress(keyDef, getCurrentElement, config) {
126
129
  const element = getCurrentElement();
127
130
 
128
- const unpreventedDefault = _dom.fireEvent.keyPress(element, { ...(0, _getEventProps.getKeyEventProps)(keyDef, state),
131
+ const unpreventedDefault = _dom.fireEvent.keyPress(element, { ...(0, _getEventProps.getKeyEventProps)(keyDef, config.keyboardState),
129
132
  charCode: keyDef.key === 'Enter' ? 13 : String(keyDef.key).charCodeAt(0)
130
133
  });
131
134
 
132
135
  if (unpreventedDefault) {
133
- applyPlugins(plugins.keypressBehavior, keyDef, getCurrentElement(), options, state);
136
+ applyPlugins(plugins.keypressBehavior, keyDef, getCurrentElement(), config);
134
137
  }
135
138
  }
136
139
 
137
- function keyup(keyDef, getCurrentElement, options, state, unprevented) {
140
+ async function keyup(keyDef, getCurrentElement, config, unprevented) {
138
141
  const element = getCurrentElement();
139
- applyPlugins(plugins.preKeyupBehavior, keyDef, element, options, state);
142
+ applyPlugins(plugins.preKeyupBehavior, keyDef, element, config);
140
143
 
141
- const unpreventedDefault = _dom.fireEvent.keyUp(element, (0, _getEventProps.getKeyEventProps)(keyDef, state));
144
+ const unpreventedDefault = _dom.fireEvent.keyUp(element, (0, _getEventProps.getKeyEventProps)(keyDef, config.keyboardState));
142
145
 
143
146
  if (unprevented && unpreventedDefault) {
144
- applyPlugins(plugins.keyupBehavior, keyDef, getCurrentElement(), options, state);
147
+ applyPlugins(plugins.keyupBehavior, keyDef, getCurrentElement(), config);
145
148
  }
146
149
 
147
- state.pressed = state.pressed.filter(k => k.keyDef !== keyDef);
148
- applyPlugins(plugins.postKeyupBehavior, keyDef, element, options, state);
150
+ config.keyboardState.pressed = config.keyboardState.pressed.filter(k => k.keyDef !== keyDef);
151
+ applyPlugins(plugins.postKeyupBehavior, keyDef, element, config);
149
152
  }
150
153
 
151
- function applyPlugins(pluginCollection, keyDef, element, options, state) {
152
- const plugin = pluginCollection.find(p => p.matches(keyDef, element, options, state));
154
+ function applyPlugins(pluginCollection, keyDef, element, config) {
155
+ const plugin = pluginCollection.find(p => p.matches(keyDef, element, config));
153
156
 
154
157
  if (plugin) {
155
- plugin.handle(keyDef, element, options, state);
158
+ plugin.handle(keyDef, element, config);
156
159
  }
157
160
 
158
161
  return !!plugin;
159
162
  }
160
163
 
161
- function hasKeyPress(keyDef, state) {
164
+ function hasKeyPress(keyDef, config) {
162
165
  var _keyDef$key;
163
166
 
164
- return (((_keyDef$key = keyDef.key) == null ? void 0 : _keyDef$key.length) === 1 || keyDef.key === 'Enter') && !state.modifiers.ctrl && !state.modifiers.alt;
167
+ return (((_keyDef$key = keyDef.key) == null ? void 0 : _keyDef$key.length) === 1 || keyDef.key === 'Enter') && !config.keyboardState.modifiers.ctrl && !config.keyboardState.modifiers.alt;
165
168
  }