@testing-library/user-event 14.0.0-alpha.9 → 14.0.0-beta.1

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 (112) hide show
  1. package/dist/clipboard/copy.d.ts +2 -0
  2. package/dist/clipboard/copy.js +36 -0
  3. package/dist/clipboard/cut.d.ts +2 -0
  4. package/dist/clipboard/cut.js +42 -0
  5. package/dist/clipboard/index.d.ts +3 -0
  6. package/dist/clipboard/index.js +44 -0
  7. package/dist/clipboard/paste.d.ts +2 -0
  8. package/dist/clipboard/paste.js +47 -0
  9. package/dist/convenience/click.d.ts +4 -0
  10. package/dist/convenience/click.js +52 -0
  11. package/dist/convenience/hover.d.ts +3 -0
  12. package/dist/convenience/hover.js +31 -0
  13. package/dist/convenience/index.d.ts +3 -0
  14. package/dist/convenience/index.js +44 -0
  15. package/dist/convenience/tab.d.ts +4 -0
  16. package/dist/convenience/tab.js +12 -0
  17. package/dist/index.d.ts +2 -7
  18. package/dist/index.js +3 -12
  19. package/dist/keyboard/getEventProps.d.ts +0 -2
  20. package/dist/keyboard/getEventProps.js +1 -7
  21. package/dist/keyboard/index.d.ts +6 -18
  22. package/dist/keyboard/index.js +9 -45
  23. package/dist/keyboard/keyMap.js +24 -48
  24. package/dist/keyboard/keyboardAction.d.ts +10 -0
  25. package/dist/keyboard/keyboardAction.js +156 -0
  26. package/dist/keyboard/{getNextKeyDef.d.ts → parseKeyDef.d.ts} +4 -6
  27. package/dist/keyboard/parseKeyDef.js +61 -0
  28. package/dist/keyboard/plugins/character.js +21 -14
  29. package/dist/keyboard/plugins/combination.js +3 -1
  30. package/dist/keyboard/plugins/functional.js +38 -20
  31. package/dist/keyboard/plugins/index.d.ts +0 -1
  32. package/dist/keyboard/plugins/index.js +1 -10
  33. package/dist/keyboard/types.d.ts +3 -19
  34. package/dist/options.d.ts +102 -0
  35. package/dist/options.js +36 -0
  36. package/dist/pointer/index.d.ts +6 -14
  37. package/dist/pointer/index.js +8 -42
  38. package/dist/pointer/parseKeyDef.d.ts +2 -2
  39. package/dist/pointer/parseKeyDef.js +1 -3
  40. package/dist/pointer/pointerAction.d.ts +3 -2
  41. package/dist/pointer/pointerAction.js +9 -15
  42. package/dist/pointer/pointerMove.d.ts +2 -1
  43. package/dist/pointer/pointerPress.d.ts +2 -1
  44. package/dist/pointer/types.d.ts +0 -11
  45. package/dist/setup/api.d.ts +5 -0
  46. package/dist/setup/api.js +111 -0
  47. package/dist/setup/config.d.ts +10 -0
  48. package/dist/setup/config.js +8 -0
  49. package/dist/setup/directApi.d.ts +20 -0
  50. package/dist/setup/directApi.js +95 -0
  51. package/dist/setup/index.d.ts +30 -0
  52. package/dist/setup/index.js +27 -0
  53. package/dist/setup/setup.d.ts +74 -0
  54. package/dist/setup/setup.js +98 -0
  55. package/dist/setup/wrapAsync.d.ts +4 -0
  56. package/dist/setup/wrapAsync.js +15 -0
  57. package/dist/{clear.d.ts → utility/clear.d.ts} +2 -2
  58. package/dist/utility/clear.js +30 -0
  59. package/dist/utility/index.d.ts +4 -0
  60. package/dist/utility/index.js +57 -0
  61. package/dist/utility/selectOptions.d.ts +3 -0
  62. package/dist/{selectOptions.js → utility/selectOptions.js} +31 -41
  63. package/dist/utility/type.d.ts +9 -0
  64. package/dist/utility/type.js +37 -0
  65. package/dist/utility/upload.d.ts +5 -0
  66. package/dist/{upload.js → utility/upload.js} +12 -40
  67. package/dist/utils/dataTransfer/Blob.d.ts +1 -0
  68. package/dist/utils/dataTransfer/Blob.js +21 -0
  69. package/dist/utils/dataTransfer/Clipboard.d.ts +9 -0
  70. package/dist/utils/dataTransfer/Clipboard.js +188 -0
  71. package/dist/utils/dataTransfer/DataTransfer.d.ts +2 -0
  72. package/dist/utils/dataTransfer/DataTransfer.js +158 -0
  73. package/dist/utils/dataTransfer/FileList.d.ts +1 -0
  74. package/dist/utils/dataTransfer/FileList.js +23 -0
  75. package/dist/utils/edit/calculateNewValue.d.ts +1 -3
  76. package/dist/utils/edit/calculateNewValue.js +1 -5
  77. package/dist/utils/edit/editInputElement.d.ts +16 -0
  78. package/dist/utils/edit/{fireInputEvent.js → editInputElement.js} +8 -20
  79. package/dist/utils/edit/prepareInput.d.ts +4 -1
  80. package/dist/utils/edit/prepareInput.js +56 -39
  81. package/dist/utils/edit/setFiles.d.ts +12 -0
  82. package/dist/utils/edit/setFiles.js +72 -0
  83. package/dist/utils/focus/copySelection.d.ts +1 -0
  84. package/dist/utils/focus/copySelection.js +36 -0
  85. package/dist/utils/focus/selectAll.d.ts +1 -0
  86. package/dist/utils/focus/selectAll.js +13 -0
  87. package/dist/utils/index.d.ts +8 -1
  88. package/dist/utils/index.js +95 -4
  89. package/dist/utils/misc/getDocumentFromNode.d.ts +1 -0
  90. package/dist/utils/misc/getDocumentFromNode.js +14 -0
  91. package/package.json +1 -1
  92. package/dist/clear.js +0 -46
  93. package/dist/click.d.ts +0 -9
  94. package/dist/click.js +0 -62
  95. package/dist/hover.d.ts +0 -4
  96. package/dist/hover.js +0 -43
  97. package/dist/keyboard/getNextKeyDef.js +0 -85
  98. package/dist/keyboard/keyboardImplementation.d.ts +0 -3
  99. package/dist/keyboard/keyboardImplementation.js +0 -169
  100. package/dist/keyboard/specialCharMap.d.ts +0 -22
  101. package/dist/keyboard/specialCharMap.js +0 -30
  102. package/dist/paste.d.ts +0 -7
  103. package/dist/paste.js +0 -60
  104. package/dist/selectOptions.d.ts +0 -4
  105. package/dist/setup.d.ts +0 -92
  106. package/dist/setup.js +0 -203
  107. package/dist/tab.d.ts +0 -5
  108. package/dist/tab.js +0 -12
  109. package/dist/type.d.ts +0 -14
  110. package/dist/type.js +0 -74
  111. package/dist/upload.d.ts +0 -10
  112. package/dist/utils/edit/fireInputEvent.d.ts +0 -11
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.copySelection = copySelection;
7
+
8
+ var _document = require("../../document");
9
+
10
+ var _DataTransfer = require("../dataTransfer/DataTransfer");
11
+
12
+ var _selection = require("./selection");
13
+
14
+ function copySelection(target) {
15
+ const data = (0, _selection.hasOwnSelection)(target) ? {
16
+ 'text/plain': readSelectedValueFromInput(target)
17
+ } : // TODO: We could implement text/html copying of DOM nodes here
18
+ {
19
+ 'text/plain': String(target.ownerDocument.getSelection())
20
+ };
21
+ const dt = (0, _DataTransfer.createDataTransfer)();
22
+
23
+ for (const type in data) {
24
+ if (data[type]) {
25
+ dt.setData(type, data[type]);
26
+ }
27
+ }
28
+
29
+ return dt;
30
+ }
31
+
32
+ function readSelectedValueFromInput(target) {
33
+ const sel = (0, _document.getUISelection)(target);
34
+ const val = (0, _document.getUIValue)(target);
35
+ return val.substring(sel.startOffset, sel.endOffset);
36
+ }
@@ -2,3 +2,4 @@
2
2
  * Expand a selection like the browser does when pressing Ctrl+A.
3
3
  */
4
4
  export declare function selectAll(target: Element): void;
5
+ export declare function isAllSelected(target: Element): boolean;
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.isAllSelected = isAllSelected;
6
7
  exports.selectAll = selectAll;
7
8
 
8
9
  var _document = require("../../document");
@@ -35,4 +36,16 @@ function selectAll(target) {
35
36
  anchorOffset: 0,
36
37
  focusOffset: focusNode.childNodes.length
37
38
  });
39
+ }
40
+
41
+ function isAllSelected(target) {
42
+ var _getContentEditable2;
43
+
44
+ if ((0, _isElementType.isElementType)(target, 'textarea') || (0, _isElementType.isElementType)(target, 'input') && target.type in _isEditable.editableInputTypes) {
45
+ return (0, _document.getUISelection)(target).startOffset === 0 && (0, _document.getUISelection)(target).endOffset === (0, _document.getUIValue)(target).length;
46
+ }
47
+
48
+ const focusNode = (_getContentEditable2 = (0, _isContentEditable.getContentEditable)(target)) != null ? _getContentEditable2 : target.ownerDocument.body;
49
+ const selection = target.ownerDocument.getSelection();
50
+ return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
38
51
  }
@@ -1,7 +1,11 @@
1
1
  export * from './click/isClickableInput';
2
+ export * from './dataTransfer/Blob';
3
+ export * from './dataTransfer/DataTransfer';
4
+ export * from './dataTransfer/FileList';
5
+ export * from './dataTransfer/Clipboard';
2
6
  export * from './edit/buildTimeValue';
3
7
  export * from './edit/calculateNewValue';
4
- export * from './edit/fireInputEvent';
8
+ export * from './edit/editInputElement';
5
9
  export * from './edit/getValue';
6
10
  export * from './edit/isContentEditable';
7
11
  export * from './edit/isEditable';
@@ -9,7 +13,9 @@ export * from './edit/isValidDateValue';
9
13
  export * from './edit/isValidInputTimeValue';
10
14
  export * from './edit/maxLength';
11
15
  export * from './edit/prepareInput';
16
+ export * from './edit/setFiles';
12
17
  export * from './focus/blur';
18
+ export * from './focus/copySelection';
13
19
  export * from './focus/focus';
14
20
  export * from './focus/getActiveElement';
15
21
  export * from './focus/getTabDestination';
@@ -20,6 +26,7 @@ export * from './focus/selector';
20
26
  export * from './keyDef/readNextDescriptor';
21
27
  export * from './misc/eventWrapper';
22
28
  export * from './misc/findClosest';
29
+ export * from './misc/getDocumentFromNode';
23
30
  export * from './misc/isDescendantOrSelf';
24
31
  export * from './misc/isElementType';
25
32
  export * from './misc/isVisible';
@@ -17,6 +17,58 @@ Object.keys(_isClickableInput).forEach(function (key) {
17
17
  });
18
18
  });
19
19
 
20
+ var _Blob = require("./dataTransfer/Blob");
21
+
22
+ Object.keys(_Blob).forEach(function (key) {
23
+ if (key === "default" || key === "__esModule") return;
24
+ if (key in exports && exports[key] === _Blob[key]) return;
25
+ Object.defineProperty(exports, key, {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _Blob[key];
29
+ }
30
+ });
31
+ });
32
+
33
+ var _DataTransfer = require("./dataTransfer/DataTransfer");
34
+
35
+ Object.keys(_DataTransfer).forEach(function (key) {
36
+ if (key === "default" || key === "__esModule") return;
37
+ if (key in exports && exports[key] === _DataTransfer[key]) return;
38
+ Object.defineProperty(exports, key, {
39
+ enumerable: true,
40
+ get: function () {
41
+ return _DataTransfer[key];
42
+ }
43
+ });
44
+ });
45
+
46
+ var _FileList = require("./dataTransfer/FileList");
47
+
48
+ Object.keys(_FileList).forEach(function (key) {
49
+ if (key === "default" || key === "__esModule") return;
50
+ if (key in exports && exports[key] === _FileList[key]) return;
51
+ Object.defineProperty(exports, key, {
52
+ enumerable: true,
53
+ get: function () {
54
+ return _FileList[key];
55
+ }
56
+ });
57
+ });
58
+
59
+ var _Clipboard = require("./dataTransfer/Clipboard");
60
+
61
+ Object.keys(_Clipboard).forEach(function (key) {
62
+ if (key === "default" || key === "__esModule") return;
63
+ if (key in exports && exports[key] === _Clipboard[key]) return;
64
+ Object.defineProperty(exports, key, {
65
+ enumerable: true,
66
+ get: function () {
67
+ return _Clipboard[key];
68
+ }
69
+ });
70
+ });
71
+
20
72
  var _buildTimeValue = require("./edit/buildTimeValue");
21
73
 
22
74
  Object.keys(_buildTimeValue).forEach(function (key) {
@@ -43,15 +95,15 @@ Object.keys(_calculateNewValue).forEach(function (key) {
43
95
  });
44
96
  });
45
97
 
46
- var _fireInputEvent = require("./edit/fireInputEvent");
98
+ var _editInputElement = require("./edit/editInputElement");
47
99
 
48
- Object.keys(_fireInputEvent).forEach(function (key) {
100
+ Object.keys(_editInputElement).forEach(function (key) {
49
101
  if (key === "default" || key === "__esModule") return;
50
- if (key in exports && exports[key] === _fireInputEvent[key]) return;
102
+ if (key in exports && exports[key] === _editInputElement[key]) return;
51
103
  Object.defineProperty(exports, key, {
52
104
  enumerable: true,
53
105
  get: function () {
54
- return _fireInputEvent[key];
106
+ return _editInputElement[key];
55
107
  }
56
108
  });
57
109
  });
@@ -147,6 +199,19 @@ Object.keys(_prepareInput).forEach(function (key) {
147
199
  });
148
200
  });
149
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
+
150
215
  var _blur = require("./focus/blur");
151
216
 
152
217
  Object.keys(_blur).forEach(function (key) {
@@ -160,6 +225,19 @@ Object.keys(_blur).forEach(function (key) {
160
225
  });
161
226
  });
162
227
 
228
+ var _copySelection = require("./focus/copySelection");
229
+
230
+ Object.keys(_copySelection).forEach(function (key) {
231
+ if (key === "default" || key === "__esModule") return;
232
+ if (key in exports && exports[key] === _copySelection[key]) return;
233
+ Object.defineProperty(exports, key, {
234
+ enumerable: true,
235
+ get: function () {
236
+ return _copySelection[key];
237
+ }
238
+ });
239
+ });
240
+
163
241
  var _focus = require("./focus/focus");
164
242
 
165
243
  Object.keys(_focus).forEach(function (key) {
@@ -290,6 +368,19 @@ Object.keys(_findClosest).forEach(function (key) {
290
368
  });
291
369
  });
292
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
+
293
384
  var _isDescendantOrSelf = require("./misc/isDescendantOrSelf");
294
385
 
295
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.9",
3
+ "version": "14.0.0-beta.1",
4
4
  "description": "Fire events the same way the user does",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [
package/dist/clear.js DELETED
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.clear = clear;
7
-
8
- var _utils = require("./utils");
9
-
10
- function clear(element) {
11
- var _element$selectionSta, _element$selectionEnd;
12
-
13
- if (!(0, _utils.isElementType)(element, ['input', 'textarea'])) {
14
- // TODO: support contenteditable
15
- throw new Error('clear currently only supports input and textarea elements.');
16
- }
17
-
18
- if ((0, _utils.isDisabled)(element)) {
19
- return;
20
- } // TODO: track the selection range ourselves so we don't have to do this input "type" trickery
21
- // just like cypress does: https://github.com/cypress-io/cypress/blob/8d7f1a0bedc3c45a2ebf1ff50324b34129fdc683/packages/driver/src/dom/selection.ts#L16-L37
22
-
23
-
24
- const elementType = element.type;
25
-
26
- if (elementType !== 'textarea') {
27
- // setSelectionRange is not supported on certain types of inputs, e.g. "number" or "email"
28
- ;
29
- element.type = 'text';
30
- }
31
-
32
- this.type(element, '{selectall}{del}', {
33
- delay: 0,
34
- initialSelectionStart: (_element$selectionSta = element.selectionStart) != null ? _element$selectionSta :
35
- /* istanbul ignore next */
36
- undefined,
37
- initialSelectionEnd: (_element$selectionEnd = element.selectionEnd) != null ? _element$selectionEnd :
38
- /* istanbul ignore next */
39
- undefined
40
- });
41
-
42
- if (elementType !== 'textarea') {
43
- ;
44
- element.type = elementType;
45
- }
46
- }
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, init?: MouseEventInit, { skipHover, skipPointerEventsCheck, }?: clickOptions & PointerOptions): void;
8
- export declare function dblClick(this: UserEvent, element: Element, init?: MouseEventInit, { skipPointerEventsCheck }?: clickOptions & PointerOptions): void;
9
- export declare function tripleClick(this: UserEvent, element: Element, init?: MouseEventInit, { skipPointerEventsCheck }?: clickOptions & PointerOptions): void;
package/dist/click.js DELETED
@@ -1,62 +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, init, {
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, init, {
23
- skipPointerEventsCheck: true
24
- });
25
- const keys = (init == null ? void 0 : init.button) === 2 || (init == null ? void 0 : init.buttons) === 2 ? '[MouseRight]' : '[MouseLeft]';
26
- this.pointer({
27
- keys,
28
- target: element
29
- });
30
- }
31
-
32
- function dblClick(element, init, {
33
- skipPointerEventsCheck = false
34
- } = {}) {
35
- if (!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
- this.hover(element, init, {
40
- skipPointerEventsCheck
41
- });
42
- this.pointer({
43
- keys: '[MouseLeft][MouseLeft]',
44
- target: element
45
- });
46
- }
47
-
48
- function tripleClick(element, init, {
49
- skipPointerEventsCheck = false
50
- } = {}) {
51
- if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
52
- throw new Error('unable to triple-click element as it has or inherits pointer-events set to "none".');
53
- }
54
-
55
- this.hover(element, init, {
56
- skipPointerEventsCheck: true
57
- });
58
- this.pointer({
59
- keys: '[MouseLeft][MouseLeft][MouseLeft]',
60
- target: element
61
- });
62
- }
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, init?: MouseEventInit, { skipPointerEventsCheck }?: PointerOptions): void;
4
- export declare function unhover(this: UserEvent, element: Element, init?: MouseEventInit, { 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, init, {
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, init, {
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,85 +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
- var legacyModifiers;
11
-
12
- (function (legacyModifiers) {
13
- legacyModifiers["alt"] = "alt";
14
- legacyModifiers["ctrl"] = "ctrl";
15
- legacyModifiers["meta"] = "meta";
16
- legacyModifiers["shift"] = "shift";
17
- })(legacyModifiers || (legacyModifiers = {}));
18
-
19
- var legacyKeyMap;
20
- /**
21
- * Get the next key from keyMap
22
- *
23
- * Keys can be referenced by `{key}` or `{special}` as well as physical locations per `[code]`.
24
- * Everything else will be interpreted as a typed character - e.g. `a`.
25
- * Brackets `{` and `[` can be escaped by doubling - e.g. `foo[[bar` translates to `foo[bar`.
26
- * Keeping the key pressed can be written as `{key>}`.
27
- * When keeping the key pressed you can choose how long (how many keydown and keypress) the key is pressed `{key>3}`.
28
- * You can then release the key per `{key>3/}` or keep it pressed and continue with the next key.
29
- * Modifiers like `{shift}` imply being kept pressed. This can be turned of per `{shift/}`.
30
- */
31
-
32
- (function (legacyKeyMap) {
33
- legacyKeyMap["ctrl"] = "Control";
34
- legacyKeyMap["del"] = "Delete";
35
- legacyKeyMap["esc"] = "Escape";
36
- legacyKeyMap["space"] = " ";
37
- })(legacyKeyMap || (legacyKeyMap = {}));
38
-
39
- function getNextKeyDef(text, options) {
40
- var _options$keyboardMap$;
41
-
42
- const {
43
- type,
44
- descriptor,
45
- consumedLength,
46
- releasePrevious,
47
- releaseSelf = !(type === '{' && getEnumValue(legacyModifiers, descriptor.toLowerCase())),
48
- repeat
49
- } = (0, _utils.readNextDescriptor)(text);
50
- const keyDef = (_options$keyboardMap$ = options.keyboardMap.find(def => {
51
- if (type === '[') {
52
- var _def$code;
53
-
54
- return ((_def$code = def.code) == null ? void 0 : _def$code.toLowerCase()) === descriptor.toLowerCase();
55
- } else if (type === '{') {
56
- var _def$key;
57
-
58
- const key = mapLegacyKey(descriptor);
59
- return ((_def$key = def.key) == null ? void 0 : _def$key.toLowerCase()) === key.toLowerCase();
60
- }
61
-
62
- return def.key === descriptor;
63
- })) != null ? _options$keyboardMap$ : {
64
- key: 'Unknown',
65
- code: 'Unknown',
66
- [type === '[' ? 'code' : 'key']: descriptor
67
- };
68
- return {
69
- keyDef,
70
- consumedLength,
71
- releasePrevious,
72
- releaseSelf,
73
- repeat
74
- };
75
- }
76
-
77
- function getEnumValue(f, key) {
78
- return f[key];
79
- }
80
-
81
- function mapLegacyKey(descriptor) {
82
- var _getEnumValue;
83
-
84
- return (_getEnumValue = getEnumValue(legacyKeyMap, descriptor)) != null ? _getEnumValue : descriptor;
85
- }
@@ -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;