index.js
1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.keyboard = keyboard;
exports.keyboardImplementationWrapper = keyboardImplementationWrapper;
Object.defineProperty(exports, "specialCharMap", {
enumerable: true,
get: function () {
return _specialCharMap.specialCharMap;
}
});
var _dom = require("@testing-library/dom");
var _keyboardImplementation = require("./keyboardImplementation");
var _keyMap = require("./keyMap");
var _specialCharMap = require("./specialCharMap");
function keyboard(text, options) {
var _options$delay;
const {
promise,
state
} = keyboardImplementationWrapper(text, options);
if (((_options$delay = options == null ? void 0 : options.delay) != null ? _options$delay : 0) > 0) {
return (0, _dom.getConfig)().asyncWrapper(() => promise.then(() => state));
} else {
// prevent users from dealing with UnhandledPromiseRejectionWarning in sync call
promise.catch(console.error);
return state;
}
}
function keyboardImplementationWrapper(text, config = {}) {
const {
keyboardState: state = createKeyboardState(),
delay = 0,
document: doc = document,
autoModify = false,
keyboardMap = _keyMap.defaultKeyMap
} = config;
const options = {
delay,
document: doc,
autoModify,
keyboardMap
};
return {
promise: (0, _keyboardImplementation.keyboardImplementation)(text, options, state),
state,
releaseAllKeys: () => (0, _keyboardImplementation.releaseAllKeys)(options, state)
};
}
function createKeyboardState() {
return {
activeElement: null,
pressed: [],
carryChar: '',
modifiers: {
alt: false,
caps: false,
ctrl: false,
meta: false,
shift: false
}
};
}