@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
@@ -23,11 +23,13 @@ const keypressBehavior = [{
23
23
  readOnly: false
24
24
  });
25
25
  },
26
- handle: (keyDef, element, options, state) => {
27
- var _state$carryValue;
26
+ handle: (keyDef, element, {
27
+ keyboardState
28
+ }) => {
29
+ var _keyboardState$carryV;
28
30
 
29
31
  let newEntry = keyDef.key;
30
- const textToBeTyped = ((_state$carryValue = state.carryValue) != null ? _state$carryValue : '') + newEntry;
32
+ const textToBeTyped = ((_keyboardState$carryV = keyboardState.carryValue) != null ? _keyboardState$carryV : '') + newEntry;
31
33
  const timeNewEntry = (0, _utils.buildTimeValue)(textToBeTyped);
32
34
 
33
35
  if ((0, _utils.isValidInputTimeValue)(element, timeNewEntry)) {
@@ -56,7 +58,7 @@ const keypressBehavior = [{
56
58
  }
57
59
 
58
60
  (0, _shared.fireChangeForInputTimeIfValid)(element, prevValue, timeNewEntry);
59
- state.carryValue = textToBeTyped;
61
+ keyboardState.carryValue = textToBeTyped;
60
62
  }
61
63
  }, {
62
64
  matches: (keyDef, element) => {
@@ -67,11 +69,13 @@ const keypressBehavior = [{
67
69
  readOnly: false
68
70
  });
69
71
  },
70
- handle: (keyDef, element, options, state) => {
71
- var _state$carryValue2;
72
+ handle: (keyDef, element, {
73
+ keyboardState
74
+ }) => {
75
+ var _keyboardState$carryV2;
72
76
 
73
77
  let newEntry = keyDef.key;
74
- const textToBeTyped = ((_state$carryValue2 = state.carryValue) != null ? _state$carryValue2 : '') + newEntry;
78
+ const textToBeTyped = ((_keyboardState$carryV2 = keyboardState.carryValue) != null ? _keyboardState$carryV2 : '') + newEntry;
75
79
  const isValidToBeTyped = (0, _utils.isValidDateValue)(element, textToBeTyped);
76
80
 
77
81
  if (isValidToBeTyped) {
@@ -107,7 +111,7 @@ const keypressBehavior = [{
107
111
  });
108
112
  }
109
113
 
110
- state.carryValue = textToBeTyped;
114
+ keyboardState.carryValue = textToBeTyped;
111
115
  }
112
116
  }, {
113
117
  matches: (keyDef, element) => {
@@ -158,10 +162,12 @@ const keypressBehavior = [{
158
162
  matches: (keyDef, element) => keyDef.key === 'Enter' && ((0, _utils.isElementType)(element, 'textarea', {
159
163
  readOnly: false
160
164
  }) || (0, _utils.isContentEditable)(element)) && (0, _utils.getSpaceUntilMaxLength)(element) !== 0,
161
- handle: (keyDef, element, options, state) => {
165
+ handle: (keyDef, element, {
166
+ keyboardState
167
+ }) => {
162
168
  var _prepareInput2;
163
169
 
164
- (_prepareInput2 = (0, _utils.prepareInput)('\n', element, (0, _utils.isContentEditable)(element) && !state.modifiers.shift ? 'insertParagraph' : 'insertLineBreak')) == null ? void 0 : _prepareInput2.commit();
170
+ (_prepareInput2 = (0, _utils.prepareInput)('\n', element, (0, _utils.isContentEditable)(element) && !keyboardState.modifiers.shift ? 'insertParagraph' : 'insertLineBreak')) == null ? void 0 : _prepareInput2.commit();
165
171
  }
166
172
  }];
167
173
  exports.keypressBehavior = keypressBehavior;
@@ -11,7 +11,9 @@ var _utils = require("../../utils");
11
11
  * Default behavior for key combinations
12
12
  */
13
13
  const keydownBehavior = [{
14
- matches: (keyDef, element, options, state) => keyDef.code === 'KeyA' && state.modifiers.ctrl,
14
+ matches: (keyDef, element, {
15
+ keyboardState
16
+ }) => keyDef.code === 'KeyA' && keyboardState.modifiers.ctrl,
15
17
  handle: (keyDef, element) => (0, _utils.selectAll)(element)
16
18
  }];
17
19
  exports.keydownBehavior = keydownBehavior;
@@ -26,31 +26,38 @@ const modifierKeys = {
26
26
  const preKeydownBehavior = [// modifierKeys switch on the modifier BEFORE the keydown event
27
27
  ...Object.entries(modifierKeys).map(([key, modKey]) => ({
28
28
  matches: keyDef => keyDef.key === key,
29
- handle: (keyDef, element, options, state) => {
30
- state.modifiers[modKey] = true;
29
+ handle: (keyDef, element, {
30
+ keyboardState
31
+ }) => {
32
+ keyboardState.modifiers[modKey] = true;
31
33
  }
32
34
  })), // AltGraph produces an extra keydown for Control
33
35
  // The modifier does not change
34
36
  {
35
37
  matches: keyDef => keyDef.key === 'AltGraph',
36
- handle: (keyDef, element, options, state) => {
37
- var _options$keyboardMap$;
38
+ handle: (keyDef, element, {
39
+ keyboardMap,
40
+ keyboardState
41
+ }) => {
42
+ var _keyboardMap$find;
38
43
 
39
- const ctrlKeyDef = (_options$keyboardMap$ = options.keyboardMap.find(k => k.key === 'Control')) != null ? _options$keyboardMap$ :
44
+ const ctrlKeyDef = (_keyboardMap$find = keyboardMap.find(k => k.key === 'Control')) != null ? _keyboardMap$find :
40
45
  /* istanbul ignore next */
41
46
  {
42
47
  key: 'Control',
43
48
  code: 'Control'
44
49
  };
45
50
 
46
- _dom.fireEvent.keyDown(element, (0, _getEventProps.getKeyEventProps)(ctrlKeyDef, state));
51
+ _dom.fireEvent.keyDown(element, (0, _getEventProps.getKeyEventProps)(ctrlKeyDef, keyboardState));
47
52
  }
48
53
  }];
49
54
  exports.preKeydownBehavior = preKeydownBehavior;
50
55
  const keydownBehavior = [{
51
56
  matches: keyDef => keyDef.key === 'CapsLock',
52
- handle: (keyDef, element, options, state) => {
53
- state.modifiers.caps = !state.modifiers.caps;
57
+ handle: (keyDef, element, {
58
+ keyboardState
59
+ }) => {
60
+ keyboardState.modifiers.caps = !keyboardState.modifiers.caps;
54
61
  }
55
62
  }, {
56
63
  matches: (keyDef, element) => keyDef.key === 'Backspace' && (0, _utils.isEditable)(element),
@@ -61,8 +68,10 @@ const keydownBehavior = [{
61
68
  }
62
69
  }, {
63
70
  matches: keyDef => keyDef.key === 'Tab',
64
- handle: (keyDef, element, options, state) => {
65
- const dest = (0, _utils.getTabDestination)(element, state.modifiers.shift);
71
+ handle: (keyDef, element, {
72
+ keyboardState
73
+ }) => {
74
+ const dest = (0, _utils.getTabDestination)(element, keyboardState.modifiers.shift);
66
75
 
67
76
  if (dest === element.ownerDocument.body) {
68
77
  (0, _utils.blur)(element);
@@ -91,8 +100,10 @@ const keypressBehavior = [{
91
100
  }, {
92
101
  matches: (keyDef, element) => keyDef.key === 'Enter' && ((0, _utils.isClickableInput)(element) || // Links with href defined should handle Enter the same as a click
93
102
  (0, _utils.isElementType)(element, 'a') && Boolean(element.href)),
94
- handle: (keyDef, element, options, state) => {
95
- _dom.fireEvent.click(element, (0, _getEventProps.getMouseEventProps)(state));
103
+ handle: (keyDef, element, {
104
+ keyboardState
105
+ }) => {
106
+ _dom.fireEvent.click(element, (0, _getEventProps.getMouseEventProps)(keyboardState));
96
107
  }
97
108
  }, {
98
109
  matches: (keyDef, element) => keyDef.key === 'Enter' && (0, _utils.isElementType)(element, 'input'),
@@ -108,15 +119,19 @@ exports.keypressBehavior = keypressBehavior;
108
119
  const preKeyupBehavior = [// modifierKeys switch off the modifier BEFORE the keyup event
109
120
  ...Object.entries(modifierKeys).map(([key, modKey]) => ({
110
121
  matches: keyDef => keyDef.key === key,
111
- handle: (keyDef, element, options, state) => {
112
- state.modifiers[modKey] = false;
122
+ handle: (keyDef, element, {
123
+ keyboardState
124
+ }) => {
125
+ keyboardState.modifiers[modKey] = false;
113
126
  }
114
127
  }))];
115
128
  exports.preKeyupBehavior = preKeyupBehavior;
116
129
  const keyupBehavior = [{
117
130
  matches: (keyDef, element) => keyDef.key === ' ' && (0, _utils.isClickableInput)(element),
118
- handle: (keyDef, element, options, state) => {
119
- _dom.fireEvent.click(element, (0, _getEventProps.getMouseEventProps)(state));
131
+ handle: (keyDef, element, {
132
+ keyboardState
133
+ }) => {
134
+ _dom.fireEvent.click(element, (0, _getEventProps.getMouseEventProps)(keyboardState));
120
135
  }
121
136
  }];
122
137
  exports.keyupBehavior = keyupBehavior;
@@ -124,17 +139,20 @@ const postKeyupBehavior = [// AltGraph produces an extra keyup for Control
124
139
  // The modifier does not change
125
140
  {
126
141
  matches: keyDef => keyDef.key === 'AltGraph',
127
- handle: (keyDef, element, options, state) => {
128
- var _options$keyboardMap$2;
142
+ handle: (keyDef, element, {
143
+ keyboardMap,
144
+ keyboardState
145
+ }) => {
146
+ var _keyboardMap$find2;
129
147
 
130
- const ctrlKeyDef = (_options$keyboardMap$2 = options.keyboardMap.find(k => k.key === 'Control')) != null ? _options$keyboardMap$2 :
148
+ const ctrlKeyDef = (_keyboardMap$find2 = keyboardMap.find(k => k.key === 'Control')) != null ? _keyboardMap$find2 :
131
149
  /* istanbul ignore next */
132
150
  {
133
151
  key: 'Control',
134
152
  code: 'Control'
135
153
  };
136
154
 
137
- _dom.fireEvent.keyUp(element, (0, _getEventProps.getKeyEventProps)(ctrlKeyDef, state));
155
+ _dom.fireEvent.keyUp(element, (0, _getEventProps.getKeyEventProps)(ctrlKeyDef, keyboardState));
138
156
  }
139
157
  }];
140
158
  exports.postKeyupBehavior = postKeyupBehavior;
@@ -1,3 +1,4 @@
1
+ import { Config } from '../setup';
1
2
  import { getNextKeyDef } from './getNextKeyDef';
2
3
  /**
3
4
  * @internal Do not create/alter this by yourself as this type might be subject to changes.
@@ -44,16 +45,6 @@ export declare type keyboardState = {
44
45
  */
45
46
  repeatKey?: ReturnType<typeof getNextKeyDef>;
46
47
  };
47
- export declare type keyboardOptions = {
48
- /** Document in which to perform the events */
49
- document: Document;
50
- /** Delay between keystrokes */
51
- delay: number;
52
- /** Add modifiers for given keys - not implemented yet */
53
- autoModify: boolean;
54
- /** Keyboard layout to use */
55
- keyboardMap: keyboardKey[];
56
- };
57
48
  export declare enum DOM_KEY_LOCATION {
58
49
  STANDARD = 0,
59
50
  LEFT = 1,
@@ -73,6 +64,6 @@ export interface keyboardKey {
73
64
  shift?: boolean;
74
65
  }
75
66
  export interface behaviorPlugin {
76
- matches: (keyDef: keyboardKey, element: Element, options: keyboardOptions, state: keyboardState) => boolean;
77
- handle: (keyDef: keyboardKey, element: Element, options: keyboardOptions, state: keyboardState) => void;
67
+ matches: (keyDef: keyboardKey, element: Element, config: Config) => boolean;
68
+ handle: (keyDef: keyboardKey, element: Element, config: Config) => void;
78
69
  }
@@ -0,0 +1,102 @@
1
+ import type { keyboardKey } from './keyboard/types';
2
+ import type { pointerKey } from './pointer/types';
3
+ export interface Options {
4
+ /**
5
+ * When using `userEvent.upload`, automatically discard files
6
+ * that don't match an `accept` property if it exists.
7
+ *
8
+ * @default true
9
+ */
10
+ applyAccept?: boolean;
11
+ /**
12
+ * We intend to automatically apply modifier keys for printable characters in the future.
13
+ * I.e. `A` implying `{Shift>}a{/Shift}` if caps lock is not active.
14
+ *
15
+ * This options allows you to opt out of this change in foresight.
16
+ * The feature therefore will not constitute a breaking change.
17
+ *
18
+ * @default true
19
+ */
20
+ autoModify?: boolean;
21
+ /**
22
+ * Between some subsequent inputs like typing a series of characters
23
+ * the code execution is delayed per `setTimeout` for (at least) `delay` seconds.
24
+ * This moves the next changes at least to next macro task
25
+ * and allows other (asynchronous) code to run between events.
26
+ *
27
+ * `null` prevents `setTimeout` from being called.
28
+ *
29
+ * @default 0
30
+ */
31
+ delay?: number | null;
32
+ /**
33
+ * The document.
34
+ *
35
+ * This defaults to the owner document of an element if an API is called directly with an element and without setup.
36
+ * Otherwise it falls back to the global document.
37
+ *
38
+ * @default element.ownerDocument??global.document
39
+ */
40
+ document?: Document;
41
+ /**
42
+ * An array of keyboard keys the keyboard device consists of.
43
+ *
44
+ * This allows to plug in different layouts / localizations.
45
+ *
46
+ * Defaults to a "standard" US-104-QWERTY keyboard.
47
+ */
48
+ keyboardMap?: keyboardKey[];
49
+ /**
50
+ * An array of available pointer keys.
51
+ *
52
+ * This allows to plug in different pointer devices.
53
+ */
54
+ pointerMap?: pointerKey[];
55
+ /**
56
+ * `userEvent.type` automatically releases any keys still pressed at the end of the call.
57
+ * This option allows to opt out of this feature.
58
+ *
59
+ * @default false
60
+ */
61
+ skipAutoClose?: boolean;
62
+ /**
63
+ * `userEvent.type` implys a click at the end of the element content/value.
64
+ * This option allows to opt out of this feature.
65
+ *
66
+ * @default false
67
+ */
68
+ skipClick?: boolean;
69
+ /**
70
+ * `userEvent.click` implys moving the cursor to the target element first.
71
+ * This options allows to opt out of this feature.
72
+ *
73
+ * @default false
74
+ */
75
+ skipHover?: boolean;
76
+ /**
77
+ * Calling pointer related APIs on an element triggers a check if that element can receive pointer events.
78
+ * This check is known to be expensive.
79
+ * This option allows to skip the check.
80
+ *
81
+ * @default false
82
+ */
83
+ skipPointerEventsCheck?: boolean;
84
+ /**
85
+ * Write selected data to Clipboard API when a `cut` or `copy` is triggered.
86
+ *
87
+ * The Clipboard API is usually not available to test code.
88
+ * Our `setup` replaces the `navigator.clipboard` property with a stub.
89
+ *
90
+ * Defaults to `false` when calling the APIs directly.
91
+ * Defaults to `true` when calling the APIs per `setup`.
92
+ */
93
+ writeToClipboard?: boolean;
94
+ }
95
+ /**
96
+ * Default options applied when API is called per `userEvent.anyApi()`
97
+ */
98
+ export declare const defaultOptionsDirect: Required<Options>;
99
+ /**
100
+ * Default options applied when API is called per `userEvent().anyApi()`
101
+ */
102
+ export declare const defaultOptionsSetup: Required<Options>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.defaultOptionsSetup = exports.defaultOptionsDirect = void 0;
7
+
8
+ var _keyMap = require("./keyboard/keyMap");
9
+
10
+ var _keyMap2 = require("./pointer/keyMap");
11
+
12
+ /**
13
+ * Default options applied when API is called per `userEvent.anyApi()`
14
+ */
15
+ const defaultOptionsDirect = {
16
+ applyAccept: true,
17
+ autoModify: true,
18
+ delay: 0,
19
+ document: global.document,
20
+ keyboardMap: _keyMap.defaultKeyMap,
21
+ pointerMap: _keyMap2.defaultKeyMap,
22
+ skipAutoClose: false,
23
+ skipClick: false,
24
+ skipHover: false,
25
+ skipPointerEventsCheck: false,
26
+ writeToClipboard: false
27
+ };
28
+ /**
29
+ * Default options applied when API is called per `userEvent().anyApi()`
30
+ */
31
+
32
+ exports.defaultOptionsDirect = defaultOptionsDirect;
33
+ const defaultOptionsSetup = { ...defaultOptionsDirect,
34
+ writeToClipboard: true
35
+ };
36
+ exports.defaultOptionsSetup = defaultOptionsSetup;
@@ -1,18 +1,10 @@
1
+ import { UserEvent } from '../setup';
1
2
  import { PointerAction, PointerActionTarget } from './pointerAction';
2
- import type { inputDeviceState, pointerOptions, pointerState } from './types';
3
- export declare function pointer(input: PointerInput, options?: Partial<pointerOptions & {
4
- delay: 0;
5
- } & inputDeviceState>): pointerState;
6
- export declare function pointer(input: PointerInput, options: Partial<pointerOptions & {
7
- delay: number;
8
- } & inputDeviceState>): Promise<pointerState>;
3
+ import type { pointerState, pointerKey } from './types';
4
+ export type { pointerState, pointerKey };
9
5
  declare type PointerActionInput = string | ({
10
6
  keys: string;
11
7
  } & PointerActionTarget) | PointerAction;
12
- declare type PointerInput = PointerActionInput | Array<PointerActionInput>;
13
- export declare function pointerImplementationWrapper(input: PointerInput, config: Partial<pointerOptions & inputDeviceState>): {
14
- promise: Promise<unknown[]>;
15
- pointerState: pointerState;
16
- };
17
- export declare function createPointerState(): pointerState;
18
- export {};
8
+ export declare type PointerInput = PointerActionInput | Array<PointerActionInput>;
9
+ export declare function pointer(this: UserEvent, input: PointerInput): Promise<void>;
10
+ export declare function createPointerState(document: Document): pointerState;
@@ -5,74 +5,40 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.createPointerState = createPointerState;
7
7
  exports.pointer = pointer;
8
- exports.pointerImplementationWrapper = pointerImplementationWrapper;
9
8
 
10
- var _dom = require("@testing-library/dom");
11
-
12
- var _keyboard = require("../keyboard");
9
+ var _setup = require("../setup");
13
10
 
14
11
  var _parseKeyDef = require("./parseKeyDef");
15
12
 
16
- var _keyMap = require("./keyMap");
17
-
18
13
  var _pointerAction = require("./pointerAction");
19
14
 
20
- function pointer(input, options = {}) {
21
- var _options$delay;
22
-
23
- const {
24
- promise,
25
- pointerState
26
- } = pointerImplementationWrapper(input, options);
27
-
28
- if (((_options$delay = options.delay) != null ? _options$delay : 0) > 0) {
29
- return (0, _dom.getConfig)().asyncWrapper(() => promise.then(() => pointerState));
30
- } else {
31
- // prevent users from dealing with UnhandledPromiseRejectionWarning in sync call
32
- promise.catch(console.error);
33
- return pointerState;
34
- }
35
- }
36
-
37
- function pointerImplementationWrapper(input, config) {
15
+ async function pointer(input) {
38
16
  const {
39
- pointerState = createPointerState(),
40
- keyboardState = (0, _keyboard.createKeyboardState)(),
41
- delay = 0,
42
- pointerMap = _keyMap.defaultKeyMap
43
- } = config;
44
- const options = {
45
- delay,
46
17
  pointerMap
47
- };
18
+ } = this[_setup.Config];
48
19
  const actions = [];
49
20
  (Array.isArray(input) ? input : [input]).forEach(actionInput => {
50
21
  if (typeof actionInput === 'string') {
51
- actions.push(...(0, _parseKeyDef.parseKeyDef)(actionInput, options));
22
+ actions.push(...(0, _parseKeyDef.parseKeyDef)(pointerMap, actionInput));
52
23
  } else if ('keys' in actionInput) {
53
- actions.push(...(0, _parseKeyDef.parseKeyDef)(actionInput.keys, options).map(i => ({ ...actionInput,
24
+ actions.push(...(0, _parseKeyDef.parseKeyDef)(pointerMap, actionInput.keys).map(i => ({ ...actionInput,
54
25
  ...i
55
26
  })));
56
27
  } else {
57
28
  actions.push(actionInput);
58
29
  }
59
30
  });
60
- return {
61
- promise: (0, _pointerAction.pointerAction)(actions, options, {
62
- pointerState,
63
- keyboardState
64
- }),
65
- pointerState
66
- };
31
+ return (0, _pointerAction.pointerAction)(this[_setup.Config], actions).then(() => undefined);
67
32
  }
68
33
 
69
- function createPointerState() {
34
+ function createPointerState(document) {
70
35
  return {
71
36
  pointerId: 1,
72
37
  position: {
73
38
  mouse: {
74
39
  pointerType: 'mouse',
75
40
  pointerId: 1,
41
+ target: document.body,
76
42
  coords: {
77
43
  clientX: 0,
78
44
  clientY: 0,
@@ -1,5 +1,5 @@
1
- import { pointerKey, pointerOptions } from './types';
2
- export declare function parseKeyDef(keys: string, { pointerMap }: pointerOptions): {
1
+ import { pointerKey } from './types';
2
+ export declare function parseKeyDef(pointerMap: pointerKey[], keys: string): {
3
3
  keyDef: pointerKey;
4
4
  releasePrevious: boolean;
5
5
  releaseSelf: boolean;
@@ -7,9 +7,7 @@ exports.parseKeyDef = parseKeyDef;
7
7
 
8
8
  var _utils = require("../utils");
9
9
 
10
- function parseKeyDef(keys, {
11
- pointerMap
12
- }) {
10
+ function parseKeyDef(pointerMap, keys) {
13
11
  const defs = [];
14
12
 
15
13
  do {
@@ -1,6 +1,7 @@
1
+ import { Config } from '../setup';
1
2
  import { PointerMoveAction } from './pointerMove';
2
3
  import { PointerPressAction } from './pointerPress';
3
- import { inputDeviceState, pointerOptions, PointerTarget, SelectionTarget } from './types';
4
+ import { PointerTarget, SelectionTarget } from './types';
4
5
  export declare type PointerActionTarget = Partial<PointerTarget> & Partial<SelectionTarget>;
5
6
  export declare type PointerAction = PointerActionTarget & (Omit<PointerPressAction, 'target' | 'coords'> | Omit<PointerMoveAction, 'target' | 'coords'>);
6
- export declare function pointerAction(actions: PointerAction[], options: pointerOptions, state: inputDeviceState): Promise<unknown[]>;
7
+ export declare function pointerAction(config: Config, actions: PointerAction[]): Promise<void>;
@@ -11,36 +11,30 @@ var _pointerMove = require("./pointerMove");
11
11
 
12
12
  var _pointerPress = require("./pointerPress");
13
13
 
14
- async function pointerAction(actions, options, state) {
15
- const ret = [];
16
-
14
+ async function pointerAction(config, actions) {
17
15
  for (let i = 0; i < actions.length; i++) {
18
16
  var _action$target, _action$coords;
19
17
 
20
18
  const action = actions[i];
21
19
  const pointerName = 'pointerName' in action && action.pointerName ? action.pointerName : 'keyDef' in action ? action.keyDef.pointerType === 'touch' ? action.keyDef.name : action.keyDef.pointerType : 'mouse';
22
- const target = (_action$target = action.target) != null ? _action$target : getPrevTarget(pointerName, state.pointerState);
23
- const coords = (_action$coords = action.coords) != null ? _action$coords : pointerName in state.pointerState.position ? state.pointerState.position[pointerName].coords : undefined;
24
- const promise = 'keyDef' in action ? (0, _pointerPress.pointerPress)({ ...action,
20
+ const target = (_action$target = action.target) != null ? _action$target : getPrevTarget(pointerName, config.pointerState);
21
+ const coords = (_action$coords = action.coords) != null ? _action$coords : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : undefined;
22
+ await ('keyDef' in action ? (0, _pointerPress.pointerPress)({ ...action,
25
23
  target,
26
24
  coords
27
- }, state) : (0, _pointerMove.pointerMove)({ ...action,
25
+ }, config) : (0, _pointerMove.pointerMove)({ ...action,
28
26
  target,
29
27
  coords
30
- }, state);
31
- ret.push(promise);
32
-
33
- if (options.delay > 0) {
34
- await promise;
28
+ }, config));
35
29
 
30
+ if (typeof config.delay === 'number') {
36
31
  if (i < actions.length - 1) {
37
- await (0, _utils.wait)(options.delay);
32
+ await (0, _utils.wait)(config.delay);
38
33
  }
39
34
  }
40
35
  }
41
36
 
42
- delete state.pointerState.activeClickCount;
43
- return Promise.all(ret);
37
+ delete config.pointerState.activeClickCount;
44
38
  }
45
39
 
46
40
  function getPrevTarget(pointerName, state) {
@@ -1,4 +1,5 @@
1
- import { inputDeviceState, PointerTarget, SelectionTarget } from './types';
1
+ import { inputDeviceState } from '../setup';
2
+ import { PointerTarget, SelectionTarget } from './types';
2
3
  export interface PointerMoveAction extends PointerTarget, SelectionTarget {
3
4
  pointerName?: string;
4
5
  }
@@ -1,4 +1,5 @@
1
- import type { inputDeviceState, pointerKey, PointerTarget, SelectionTarget } from './types';
1
+ import { inputDeviceState } from '../setup';
2
+ import type { pointerKey, PointerTarget, SelectionTarget } from './types';
2
3
  export interface PointerPressAction extends PointerTarget, SelectionTarget {
3
4
  keyDef: pointerKey;
4
5
  releasePrevious: boolean;
@@ -1,4 +1,3 @@
1
- import { keyboardState } from '../keyboard/types';
2
1
  import { PointerCoords, MouseButton } from '../utils';
3
2
  /**
4
3
  * @internal Do not create/alter this by yourself as this type might be subject to changes.
@@ -34,12 +33,6 @@ export declare type pointerState = {
34
33
  */
35
34
  pointerId: number;
36
35
  };
37
- export declare type pointerOptions = {
38
- /** Delay between keystrokes */
39
- delay: number;
40
- /** Available pointer keys */
41
- pointerMap: pointerKey[];
42
- };
43
36
  export interface pointerKey {
44
37
  /** Name of the pointer key */
45
38
  name: string;
@@ -66,7 +59,3 @@ export interface SelectionInputRange {
66
59
  start: number;
67
60
  end: number;
68
61
  }
69
- export interface inputDeviceState {
70
- pointerState: pointerState;
71
- keyboardState: keyboardState;
72
- }
@@ -0,0 +1,5 @@
1
+ export { click, dblClick, tripleClick, hover, unhover, tab } from '../convenience';
2
+ export { keyboard } from '../keyboard';
3
+ export { copy, cut, paste } from '../clipboard';
4
+ export { pointer } from '../pointer';
5
+ export { clear, deselectOptions, selectOptions, type, upload } from '../utility';