@testing-library/user-event 14.0.0-alpha.10 → 14.0.0-alpha.14
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.
- package/dist/click.d.ts +3 -3
- package/dist/click.js +8 -9
- package/dist/clipboard/copy.d.ts +11 -0
- package/dist/clipboard/copy.js +30 -0
- package/dist/clipboard/cut.d.ts +11 -0
- package/dist/clipboard/cut.js +36 -0
- package/dist/clipboard/index.d.ts +3 -0
- package/dist/clipboard/index.js +44 -0
- package/dist/clipboard/paste.d.ts +6 -0
- package/dist/clipboard/paste.js +45 -0
- package/dist/hover.d.ts +2 -2
- package/dist/hover.js +2 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -8
- package/dist/keyboard/getEventProps.d.ts +0 -2
- package/dist/keyboard/getEventProps.js +1 -7
- package/dist/keyboard/getNextKeyDef.d.ts +0 -1
- package/dist/keyboard/getNextKeyDef.js +2 -32
- package/dist/keyboard/index.d.ts +0 -1
- package/dist/keyboard/index.js +0 -8
- package/dist/keyboard/keyMap.js +24 -48
- package/dist/keyboard/keyboardImplementation.js +12 -16
- package/dist/keyboard/plugins/index.d.ts +0 -1
- package/dist/keyboard/plugins/index.js +1 -10
- package/dist/keyboard/types.d.ts +0 -2
- package/dist/selectOptions.d.ts +2 -2
- package/dist/selectOptions.js +25 -26
- package/dist/setup.d.ts +11 -3
- package/dist/setup.js +57 -19
- package/dist/upload.d.ts +0 -1
- package/dist/upload.js +1 -1
- package/dist/utils/dataTransfer/Blob.d.ts +1 -0
- package/dist/utils/dataTransfer/Blob.js +21 -0
- package/dist/utils/dataTransfer/Clipboard.d.ts +9 -0
- package/dist/utils/dataTransfer/Clipboard.js +188 -0
- package/dist/utils/dataTransfer/DataTransfer.d.ts +2 -0
- package/dist/utils/dataTransfer/DataTransfer.js +158 -0
- package/dist/utils/dataTransfer/FileList.d.ts +1 -0
- package/dist/utils/dataTransfer/FileList.js +13 -0
- package/dist/utils/focus/copySelection.d.ts +1 -0
- package/dist/utils/focus/copySelection.js +36 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +65 -0
- package/package.json +1 -1
- package/dist/keyboard/specialCharMap.d.ts +0 -22
- package/dist/keyboard/specialCharMap.js +0 -30
- package/dist/paste.d.ts +0 -7
- package/dist/paste.js +0 -60
package/dist/click.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ export declare interface clickOptions {
|
|
|
4
4
|
skipHover?: boolean;
|
|
5
5
|
clickCount?: number;
|
|
6
6
|
}
|
|
7
|
-
export declare function click(this: UserEvent, element: Element,
|
|
8
|
-
export declare function dblClick(this: UserEvent, element: Element,
|
|
9
|
-
export declare function tripleClick(this: UserEvent, element: Element,
|
|
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
CHANGED
|
@@ -9,7 +9,7 @@ exports.tripleClick = tripleClick;
|
|
|
9
9
|
|
|
10
10
|
var _utils = require("./utils");
|
|
11
11
|
|
|
12
|
-
function click(element,
|
|
12
|
+
function click(element, {
|
|
13
13
|
skipHover = false,
|
|
14
14
|
skipPointerEventsCheck = false
|
|
15
15
|
} = {}) {
|
|
@@ -19,25 +19,24 @@ function click(element, init, {
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
if (!skipHover) // We just checked for `pointerEvents`. We can always skip this one in `hover`.
|
|
22
|
-
this.hover(element,
|
|
22
|
+
this.hover(element, {
|
|
23
23
|
skipPointerEventsCheck: true
|
|
24
24
|
});
|
|
25
|
-
const keys = (init == null ? void 0 : init.button) === 2 || (init == null ? void 0 : init.buttons) === 2 ? '[MouseRight]' : '[MouseLeft]';
|
|
26
25
|
this.pointer({
|
|
27
|
-
keys,
|
|
26
|
+
keys: '[MouseLeft]',
|
|
28
27
|
target: element
|
|
29
28
|
});
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
function dblClick(element,
|
|
31
|
+
function dblClick(element, {
|
|
33
32
|
skipPointerEventsCheck = false
|
|
34
33
|
} = {}) {
|
|
35
34
|
if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
|
|
36
35
|
throw new Error('unable to double-click element as it has or inherits pointer-events set to "none".');
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
this.hover(element,
|
|
40
|
-
skipPointerEventsCheck
|
|
38
|
+
this.hover(element, {
|
|
39
|
+
skipPointerEventsCheck: true
|
|
41
40
|
});
|
|
42
41
|
this.pointer({
|
|
43
42
|
keys: '[MouseLeft][MouseLeft]',
|
|
@@ -45,14 +44,14 @@ function dblClick(element, init, {
|
|
|
45
44
|
});
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
function tripleClick(element,
|
|
47
|
+
function tripleClick(element, {
|
|
49
48
|
skipPointerEventsCheck = false
|
|
50
49
|
} = {}) {
|
|
51
50
|
if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
|
|
52
51
|
throw new Error('unable to triple-click element as it has or inherits pointer-events set to "none".');
|
|
53
52
|
}
|
|
54
53
|
|
|
55
|
-
this.hover(element,
|
|
54
|
+
this.hover(element, {
|
|
56
55
|
skipPointerEventsCheck: true
|
|
57
56
|
});
|
|
58
57
|
this.pointer({
|
|
@@ -0,0 +1,11 @@
|
|
|
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;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.copy = copy;
|
|
7
|
+
|
|
8
|
+
var _dom = require("@testing-library/dom");
|
|
9
|
+
|
|
10
|
+
var _utils = require("../utils");
|
|
11
|
+
|
|
12
|
+
function copy(options) {
|
|
13
|
+
var _options$document, _doc$activeElement;
|
|
14
|
+
|
|
15
|
+
const doc = (_options$document = options == null ? void 0 : options.document) != null ? _options$document : document;
|
|
16
|
+
const target = (_doc$activeElement = doc.activeElement) != null ? _doc$activeElement :
|
|
17
|
+
/* istanbul ignore next */
|
|
18
|
+
doc.body;
|
|
19
|
+
const clipboardData = (0, _utils.copySelection)(target);
|
|
20
|
+
|
|
21
|
+
if (clipboardData.items.length === 0) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
_dom.fireEvent.copy(target, {
|
|
26
|
+
clipboardData
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return options != null && options.writeToClipboard ? (0, _utils.writeDataTransferToClipboard)(doc, clipboardData).then(() => clipboardData) : clipboardData;
|
|
30
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.cut = cut;
|
|
7
|
+
|
|
8
|
+
var _dom = require("@testing-library/dom");
|
|
9
|
+
|
|
10
|
+
var _utils = require("../utils");
|
|
11
|
+
|
|
12
|
+
function cut(options) {
|
|
13
|
+
var _options$document, _doc$activeElement;
|
|
14
|
+
|
|
15
|
+
const doc = (_options$document = options == null ? void 0 : options.document) != null ? _options$document : document;
|
|
16
|
+
const target = (_doc$activeElement = doc.activeElement) != null ? _doc$activeElement :
|
|
17
|
+
/* istanbul ignore next */
|
|
18
|
+
doc.body;
|
|
19
|
+
const clipboardData = (0, _utils.copySelection)(target);
|
|
20
|
+
|
|
21
|
+
if (clipboardData.items.length === 0) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
_dom.fireEvent.cut(target, {
|
|
26
|
+
clipboardData
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
if ((0, _utils.isEditable)(target)) {
|
|
30
|
+
var _prepareInput;
|
|
31
|
+
|
|
32
|
+
(_prepareInput = (0, _utils.prepareInput)('', target, 'deleteByCut')) == null ? void 0 : _prepareInput.commit();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return options != null && options.writeToClipboard ? (0, _utils.writeDataTransferToClipboard)(doc, clipboardData).then(() => clipboardData) : clipboardData;
|
|
36
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _copy = require("./copy");
|
|
8
|
+
|
|
9
|
+
Object.keys(_copy).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _copy[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _copy[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
var _cut = require("./cut");
|
|
21
|
+
|
|
22
|
+
Object.keys(_cut).forEach(function (key) {
|
|
23
|
+
if (key === "default" || key === "__esModule") return;
|
|
24
|
+
if (key in exports && exports[key] === _cut[key]) return;
|
|
25
|
+
Object.defineProperty(exports, key, {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _cut[key];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
var _paste = require("./paste");
|
|
34
|
+
|
|
35
|
+
Object.keys(_paste).forEach(function (key) {
|
|
36
|
+
if (key === "default" || key === "__esModule") return;
|
|
37
|
+
if (key in exports && exports[key] === _paste[key]) return;
|
|
38
|
+
Object.defineProperty(exports, key, {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () {
|
|
41
|
+
return _paste[key];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
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;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.paste = paste;
|
|
7
|
+
|
|
8
|
+
var _dom = require("@testing-library/dom");
|
|
9
|
+
|
|
10
|
+
var _utils = require("../utils");
|
|
11
|
+
|
|
12
|
+
function paste(clipboardData, options) {
|
|
13
|
+
var _options$document, _doc$activeElement;
|
|
14
|
+
|
|
15
|
+
const doc = (_options$document = options == null ? void 0 : options.document) != null ? _options$document : document;
|
|
16
|
+
const target = (_doc$activeElement = doc.activeElement) != null ? _doc$activeElement :
|
|
17
|
+
/* istanbul ignore next */
|
|
18
|
+
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
|
+
throw new Error('`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.');
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function pasteImpl(target, clipboardData) {
|
|
26
|
+
_dom.fireEvent.paste(target, {
|
|
27
|
+
clipboardData
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if ((0, _utils.isEditable)(target)) {
|
|
31
|
+
const data = clipboardData.getData('text').substr(0, (0, _utils.getSpaceUntilMaxLength)(target));
|
|
32
|
+
|
|
33
|
+
if (data) {
|
|
34
|
+
var _prepareInput;
|
|
35
|
+
|
|
36
|
+
(_prepareInput = (0, _utils.prepareInput)(data, target, 'insertFromPaste')) == null ? void 0 : _prepareInput.commit();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getClipboardDataFromString(text) {
|
|
42
|
+
const dt = (0, _utils.createDataTransfer)();
|
|
43
|
+
dt.setData('text', text);
|
|
44
|
+
return dt;
|
|
45
|
+
}
|
package/dist/hover.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { UserEvent } from './setup';
|
|
2
2
|
import { PointerOptions } from './utils';
|
|
3
|
-
export declare function hover(this: UserEvent, element: Element,
|
|
4
|
-
export declare function unhover(this: UserEvent, element: Element,
|
|
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
CHANGED
|
@@ -10,7 +10,7 @@ var _pointer = require("./pointer");
|
|
|
10
10
|
|
|
11
11
|
var _utils = require("./utils");
|
|
12
12
|
|
|
13
|
-
function hover(element,
|
|
13
|
+
function hover(element, {
|
|
14
14
|
skipPointerEventsCheck = false
|
|
15
15
|
} = {}) {
|
|
16
16
|
if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
|
|
@@ -26,7 +26,7 @@ function hover(element, init, {
|
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
function unhover(element,
|
|
29
|
+
function unhover(element, {
|
|
30
30
|
skipPointerEventsCheck = false
|
|
31
31
|
} = {}) {
|
|
32
32
|
if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { specialCharMap } from './keyboard';
|
|
2
1
|
import { UserEventApis, setup } from './setup';
|
|
3
2
|
declare const userEvent: UserEventApis & {
|
|
4
3
|
setup: typeof setup;
|
|
5
4
|
};
|
|
6
5
|
export default userEvent;
|
|
7
|
-
export { specialCharMap as specialChars };
|
|
8
6
|
export type { keyboardKey } from './keyboard';
|
package/dist/index.js
CHANGED
|
@@ -4,14 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
Object.defineProperty(exports, "specialChars", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () {
|
|
10
|
-
return _keyboard.specialCharMap;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
var _keyboard = require("./keyboard");
|
|
15
7
|
|
|
16
8
|
var _setup = require("./setup");
|
|
17
9
|
|
|
@@ -6,8 +6,6 @@ export declare function getKeyEventProps(keyDef: keyboardKey, state: keyboardSta
|
|
|
6
6
|
ctrlKey: boolean;
|
|
7
7
|
metaKey: boolean;
|
|
8
8
|
shiftKey: boolean;
|
|
9
|
-
/** @deprecated use code instead */
|
|
10
|
-
keyCode: number | undefined;
|
|
11
9
|
};
|
|
12
10
|
export declare function getMouseEventProps(state: keyboardState): {
|
|
13
11
|
altKey: boolean;
|
|
@@ -7,19 +7,13 @@ exports.getKeyEventProps = getKeyEventProps;
|
|
|
7
7
|
exports.getMouseEventProps = getMouseEventProps;
|
|
8
8
|
|
|
9
9
|
function getKeyEventProps(keyDef, state) {
|
|
10
|
-
var _keyDef$keyCode, _keyDef$key;
|
|
11
|
-
|
|
12
10
|
return {
|
|
13
11
|
key: keyDef.key,
|
|
14
12
|
code: keyDef.code,
|
|
15
13
|
altKey: state.modifiers.alt,
|
|
16
14
|
ctrlKey: state.modifiers.ctrl,
|
|
17
15
|
metaKey: state.modifiers.meta,
|
|
18
|
-
shiftKey: state.modifiers.shift
|
|
19
|
-
|
|
20
|
-
/** @deprecated use code instead */
|
|
21
|
-
keyCode: (_keyDef$keyCode = keyDef.keyCode) != null ? _keyDef$keyCode : // istanbul ignore next
|
|
22
|
-
((_keyDef$key = keyDef.key) == null ? void 0 : _keyDef$key.length) === 1 ? keyDef.key.charCodeAt(0) : undefined
|
|
16
|
+
shiftKey: state.modifiers.shift
|
|
23
17
|
};
|
|
24
18
|
}
|
|
25
19
|
|
|
@@ -8,7 +8,6 @@ import { keyboardKey, keyboardOptions } from './types';
|
|
|
8
8
|
* Keeping the key pressed can be written as `{key>}`.
|
|
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
|
-
* Modifiers like `{shift}` imply being kept pressed. This can be turned of per `{shift/}`.
|
|
12
11
|
*/
|
|
13
12
|
export declare function getNextKeyDef(text: string, options: keyboardOptions): {
|
|
14
13
|
keyDef: keyboardKey;
|
|
@@ -7,16 +7,6 @@ exports.getNextKeyDef = getNextKeyDef;
|
|
|
7
7
|
|
|
8
8
|
var _utils = require("../utils");
|
|
9
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
10
|
/**
|
|
21
11
|
* Get the next key from keyMap
|
|
22
12
|
*
|
|
@@ -26,16 +16,7 @@ var legacyKeyMap;
|
|
|
26
16
|
* Keeping the key pressed can be written as `{key>}`.
|
|
27
17
|
* When keeping the key pressed you can choose how long (how many keydown and keypress) the key is pressed `{key>3}`.
|
|
28
18
|
* 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
19
|
*/
|
|
31
|
-
|
|
32
|
-
(function (legacyKeyMap) {
|
|
33
|
-
legacyKeyMap["ctrl"] = "Control";
|
|
34
|
-
legacyKeyMap["del"] = "Delete";
|
|
35
|
-
legacyKeyMap["esc"] = "Escape";
|
|
36
|
-
legacyKeyMap["space"] = " ";
|
|
37
|
-
})(legacyKeyMap || (legacyKeyMap = {}));
|
|
38
|
-
|
|
39
20
|
function getNextKeyDef(text, options) {
|
|
40
21
|
var _options$keyboardMap$;
|
|
41
22
|
|
|
@@ -44,7 +25,7 @@ function getNextKeyDef(text, options) {
|
|
|
44
25
|
descriptor,
|
|
45
26
|
consumedLength,
|
|
46
27
|
releasePrevious,
|
|
47
|
-
releaseSelf =
|
|
28
|
+
releaseSelf = true,
|
|
48
29
|
repeat
|
|
49
30
|
} = (0, _utils.readNextDescriptor)(text);
|
|
50
31
|
const keyDef = (_options$keyboardMap$ = options.keyboardMap.find(def => {
|
|
@@ -55,8 +36,7 @@ function getNextKeyDef(text, options) {
|
|
|
55
36
|
} else if (type === '{') {
|
|
56
37
|
var _def$key;
|
|
57
38
|
|
|
58
|
-
|
|
59
|
-
return ((_def$key = def.key) == null ? void 0 : _def$key.toLowerCase()) === key.toLowerCase();
|
|
39
|
+
return ((_def$key = def.key) == null ? void 0 : _def$key.toLowerCase()) === descriptor.toLowerCase();
|
|
60
40
|
}
|
|
61
41
|
|
|
62
42
|
return def.key === descriptor;
|
|
@@ -72,14 +52,4 @@ function getNextKeyDef(text, options) {
|
|
|
72
52
|
releaseSelf,
|
|
73
53
|
repeat
|
|
74
54
|
};
|
|
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
55
|
}
|
package/dist/keyboard/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { keyboardState, keyboardOptions, keyboardKey } from './types';
|
|
2
|
-
export { specialCharMap } from './specialCharMap';
|
|
3
2
|
export type { keyboardOptions, keyboardKey };
|
|
4
3
|
export declare function keyboard(text: string, options?: Partial<keyboardOptions & {
|
|
5
4
|
keyboardState: keyboardState;
|
package/dist/keyboard/index.js
CHANGED
|
@@ -6,12 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.createKeyboardState = createKeyboardState;
|
|
7
7
|
exports.keyboard = keyboard;
|
|
8
8
|
exports.keyboardImplementationWrapper = keyboardImplementationWrapper;
|
|
9
|
-
Object.defineProperty(exports, "specialCharMap", {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function () {
|
|
12
|
-
return _specialCharMap.specialCharMap;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
9
|
|
|
16
10
|
var _dom = require("@testing-library/dom");
|
|
17
11
|
|
|
@@ -21,8 +15,6 @@ var _keyboardImplementation = require("./keyboardImplementation");
|
|
|
21
15
|
|
|
22
16
|
var _keyMap = require("./keyMap");
|
|
23
17
|
|
|
24
|
-
var _specialCharMap = require("./specialCharMap");
|
|
25
|
-
|
|
26
18
|
function keyboard(text, options) {
|
|
27
19
|
var _options$delay;
|
|
28
20
|
|
package/dist/keyboard/keyMap.js
CHANGED
|
@@ -32,112 +32,88 @@ const defaultKeyMap = [// alphanumeric keys
|
|
|
32
32
|
}, {
|
|
33
33
|
code: 'AltLeft',
|
|
34
34
|
key: 'Alt',
|
|
35
|
-
location: _types.DOM_KEY_LOCATION.LEFT
|
|
36
|
-
keyCode: 18
|
|
35
|
+
location: _types.DOM_KEY_LOCATION.LEFT
|
|
37
36
|
}, {
|
|
38
37
|
code: 'AltRight',
|
|
39
38
|
key: 'Alt',
|
|
40
|
-
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
41
|
-
keyCode: 18
|
|
39
|
+
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
42
40
|
}, {
|
|
43
41
|
code: 'ShiftLeft',
|
|
44
42
|
key: 'Shift',
|
|
45
|
-
location: _types.DOM_KEY_LOCATION.LEFT
|
|
46
|
-
keyCode: 16
|
|
43
|
+
location: _types.DOM_KEY_LOCATION.LEFT
|
|
47
44
|
}, {
|
|
48
45
|
code: 'ShiftRight',
|
|
49
46
|
key: 'Shift',
|
|
50
|
-
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
51
|
-
keyCode: 16
|
|
47
|
+
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
52
48
|
}, {
|
|
53
49
|
code: 'ControlLeft',
|
|
54
50
|
key: 'Control',
|
|
55
|
-
location: _types.DOM_KEY_LOCATION.LEFT
|
|
56
|
-
keyCode: 17
|
|
51
|
+
location: _types.DOM_KEY_LOCATION.LEFT
|
|
57
52
|
}, {
|
|
58
53
|
code: 'ControlRight',
|
|
59
54
|
key: 'Control',
|
|
60
|
-
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
61
|
-
keyCode: 17
|
|
55
|
+
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
62
56
|
}, {
|
|
63
57
|
code: 'MetaLeft',
|
|
64
58
|
key: 'Meta',
|
|
65
|
-
location: _types.DOM_KEY_LOCATION.LEFT
|
|
66
|
-
keyCode: 93
|
|
59
|
+
location: _types.DOM_KEY_LOCATION.LEFT
|
|
67
60
|
}, {
|
|
68
61
|
code: 'MetaRight',
|
|
69
62
|
key: 'Meta',
|
|
70
|
-
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
71
|
-
keyCode: 93
|
|
63
|
+
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
72
64
|
}, {
|
|
73
65
|
code: 'OSLeft',
|
|
74
66
|
key: 'OS',
|
|
75
|
-
location: _types.DOM_KEY_LOCATION.LEFT
|
|
76
|
-
keyCode: 91
|
|
67
|
+
location: _types.DOM_KEY_LOCATION.LEFT
|
|
77
68
|
}, {
|
|
78
69
|
code: 'OSRight',
|
|
79
70
|
key: 'OS',
|
|
80
|
-
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
81
|
-
keyCode: 91
|
|
71
|
+
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
82
72
|
}, {
|
|
83
73
|
code: 'Tab',
|
|
84
|
-
key: 'Tab'
|
|
85
|
-
keyCode: 9
|
|
74
|
+
key: 'Tab'
|
|
86
75
|
}, {
|
|
87
76
|
code: 'CapsLock',
|
|
88
|
-
key: 'CapsLock'
|
|
89
|
-
keyCode: 20
|
|
77
|
+
key: 'CapsLock'
|
|
90
78
|
}, {
|
|
91
79
|
code: 'Backspace',
|
|
92
|
-
key: 'Backspace'
|
|
93
|
-
keyCode: 8
|
|
80
|
+
key: 'Backspace'
|
|
94
81
|
}, {
|
|
95
82
|
code: 'Enter',
|
|
96
|
-
key: 'Enter'
|
|
97
|
-
keyCode: 13
|
|
83
|
+
key: 'Enter'
|
|
98
84
|
}, // function
|
|
99
85
|
{
|
|
100
86
|
code: 'Escape',
|
|
101
|
-
key: 'Escape'
|
|
102
|
-
keyCode: 27
|
|
87
|
+
key: 'Escape'
|
|
103
88
|
}, // arrows
|
|
104
89
|
{
|
|
105
90
|
code: 'ArrowUp',
|
|
106
|
-
key: 'ArrowUp'
|
|
107
|
-
keyCode: 38
|
|
91
|
+
key: 'ArrowUp'
|
|
108
92
|
}, {
|
|
109
93
|
code: 'ArrowDown',
|
|
110
|
-
key: 'ArrowDown'
|
|
111
|
-
keyCode: 40
|
|
94
|
+
key: 'ArrowDown'
|
|
112
95
|
}, {
|
|
113
96
|
code: 'ArrowLeft',
|
|
114
|
-
key: 'ArrowLeft'
|
|
115
|
-
keyCode: 37
|
|
97
|
+
key: 'ArrowLeft'
|
|
116
98
|
}, {
|
|
117
99
|
code: 'ArrowRight',
|
|
118
|
-
key: 'ArrowRight'
|
|
119
|
-
keyCode: 39
|
|
100
|
+
key: 'ArrowRight'
|
|
120
101
|
}, // control pad
|
|
121
102
|
{
|
|
122
103
|
code: 'Home',
|
|
123
|
-
key: 'Home'
|
|
124
|
-
keyCode: 36
|
|
104
|
+
key: 'Home'
|
|
125
105
|
}, {
|
|
126
106
|
code: 'End',
|
|
127
|
-
key: 'End'
|
|
128
|
-
keyCode: 35
|
|
107
|
+
key: 'End'
|
|
129
108
|
}, {
|
|
130
109
|
code: 'Delete',
|
|
131
|
-
key: 'Delete'
|
|
132
|
-
keyCode: 46
|
|
110
|
+
key: 'Delete'
|
|
133
111
|
}, {
|
|
134
112
|
code: 'PageUp',
|
|
135
|
-
key: 'PageUp'
|
|
136
|
-
keyCode: 33
|
|
113
|
+
key: 'PageUp'
|
|
137
114
|
}, {
|
|
138
115
|
code: 'PageDown',
|
|
139
|
-
key: 'PageDown'
|
|
140
|
-
keyCode: 34
|
|
116
|
+
key: 'PageDown'
|
|
141
117
|
} // TODO: add mappings
|
|
142
118
|
];
|
|
143
119
|
exports.defaultKeyMap = defaultKeyMap;
|
|
@@ -36,27 +36,23 @@ async function keyboardImplementation(text, options, state) {
|
|
|
36
36
|
releaseSelf,
|
|
37
37
|
repeat
|
|
38
38
|
} = (_state$repeatKey = state.repeatKey) != null ? _state$repeatKey : (0, _getNextKeyDef.getNextKeyDef)(text, options);
|
|
39
|
-
const
|
|
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`.
|
|
40
41
|
|
|
41
|
-
if (!
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (pressed && !state.repeatKey) {
|
|
46
|
-
keyup(keyDef, getCurrentElement, options, state, pressed.unpreventedDefault);
|
|
47
|
-
}
|
|
42
|
+
if (pressed && !state.repeatKey) {
|
|
43
|
+
keyup(keyDef, getCurrentElement, options, state, pressed.unpreventedDefault);
|
|
44
|
+
}
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
if (!releasePrevious) {
|
|
47
|
+
const unpreventedDefault = keydown(keyDef, getCurrentElement, options, state);
|
|
51
48
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
if (unpreventedDefault && hasKeyPress(keyDef, state)) {
|
|
50
|
+
keypress(keyDef, getCurrentElement, options, state);
|
|
51
|
+
} // Release the key only on the last iteration on `state.repeatKey`.
|
|
55
52
|
|
|
56
53
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
54
|
+
if (releaseSelf && repeat <= 1) {
|
|
55
|
+
keyup(keyDef, getCurrentElement, options, state, unpreventedDefault);
|
|
60
56
|
}
|
|
61
57
|
}
|
|
62
58
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { behaviorPlugin } from '../types';
|
|
2
|
-
export declare const replaceBehavior: behaviorPlugin[];
|
|
3
2
|
export declare const preKeydownBehavior: behaviorPlugin[];
|
|
4
3
|
export declare const keydownBehavior: behaviorPlugin[];
|
|
5
4
|
export declare const keypressBehavior: behaviorPlugin[];
|
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
var _utils = require("../../utils");
|
|
6
|
+
exports.preKeyupBehavior = exports.preKeydownBehavior = exports.postKeyupBehavior = exports.keyupBehavior = exports.keypressBehavior = exports.keydownBehavior = void 0;
|
|
9
7
|
|
|
10
8
|
var arrowKeys = _interopRequireWildcard(require("./arrow"));
|
|
11
9
|
|
|
@@ -21,13 +19,6 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
21
19
|
|
|
22
20
|
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; }
|
|
23
21
|
|
|
24
|
-
const replaceBehavior = [{
|
|
25
|
-
matches: (keyDef, element) => keyDef.key === 'selectall' && (0, _utils.isElementType)(element, ['input', 'textarea']),
|
|
26
|
-
handle: (keyDef, element) => {
|
|
27
|
-
(0, _utils.setSelectionRange)(element, 0, (0, _utils.getValue)(element).length);
|
|
28
|
-
}
|
|
29
|
-
}];
|
|
30
|
-
exports.replaceBehavior = replaceBehavior;
|
|
31
22
|
const preKeydownBehavior = [...functionalKeys.preKeydownBehavior];
|
|
32
23
|
exports.preKeydownBehavior = preKeydownBehavior;
|
|
33
24
|
const keydownBehavior = [...arrowKeys.keydownBehavior, ...controlKeys.keydownBehavior, ...functionalKeys.keydownBehavior, ...combination.keydownBehavior];
|