@testing-library/user-event 14.0.0-alpha.6 → 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.
- package/dist/clipboard/copy.d.ts +2 -0
- package/dist/clipboard/copy.js +36 -0
- package/dist/clipboard/cut.d.ts +2 -0
- package/dist/clipboard/cut.js +42 -0
- package/dist/clipboard/index.d.ts +3 -0
- package/dist/clipboard/index.js +44 -0
- package/dist/clipboard/paste.d.ts +2 -0
- package/dist/clipboard/paste.js +47 -0
- package/dist/convenience/click.d.ts +4 -0
- package/dist/convenience/click.js +52 -0
- package/dist/convenience/hover.d.ts +3 -0
- package/dist/convenience/hover.js +31 -0
- package/dist/convenience/index.d.ts +3 -0
- package/dist/convenience/index.js +44 -0
- package/dist/convenience/tab.d.ts +4 -0
- package/dist/convenience/tab.js +12 -0
- package/dist/document/index.d.ts +1 -0
- package/dist/document/selection.d.ts +17 -7
- package/dist/document/selection.js +33 -17
- package/dist/document/value.d.ts +1 -1
- package/dist/document/value.js +1 -1
- package/dist/index.d.ts +2 -7
- package/dist/index.js +3 -12
- package/dist/keyboard/getEventProps.d.ts +0 -2
- package/dist/keyboard/getEventProps.js +1 -7
- package/dist/keyboard/index.d.ts +6 -18
- package/dist/keyboard/index.js +9 -45
- package/dist/keyboard/keyMap.js +24 -48
- package/dist/keyboard/keyboardAction.d.ts +10 -0
- package/dist/keyboard/keyboardAction.js +156 -0
- package/dist/keyboard/{getNextKeyDef.d.ts → parseKeyDef.d.ts} +4 -6
- package/dist/keyboard/parseKeyDef.js +61 -0
- package/dist/keyboard/plugins/arrow.js +7 -12
- package/dist/keyboard/plugins/character.js +42 -54
- package/dist/keyboard/plugins/combination.d.ts +5 -0
- package/dist/keyboard/plugins/combination.js +19 -0
- package/dist/keyboard/plugins/control.js +4 -12
- package/dist/keyboard/plugins/functional.js +46 -33
- package/dist/keyboard/plugins/index.d.ts +0 -1
- package/dist/keyboard/plugins/index.js +4 -11
- package/dist/keyboard/types.d.ts +3 -19
- package/dist/options.d.ts +102 -0
- package/dist/options.js +36 -0
- package/dist/pointer/index.d.ts +6 -14
- package/dist/pointer/index.js +8 -42
- package/dist/pointer/parseKeyDef.d.ts +2 -2
- package/dist/pointer/parseKeyDef.js +1 -3
- package/dist/pointer/pointerAction.d.ts +3 -2
- package/dist/pointer/pointerAction.js +9 -15
- package/dist/pointer/pointerMove.d.ts +2 -1
- package/dist/pointer/pointerMove.js +28 -17
- package/dist/pointer/pointerPress.d.ts +2 -1
- package/dist/pointer/pointerPress.js +6 -4
- package/dist/pointer/resolveSelectionTarget.js +7 -6
- package/dist/pointer/types.d.ts +0 -11
- package/dist/setup/api.d.ts +5 -0
- package/dist/setup/api.js +111 -0
- package/dist/setup/config.d.ts +10 -0
- package/dist/setup/config.js +8 -0
- package/dist/setup/directApi.d.ts +20 -0
- package/dist/setup/directApi.js +95 -0
- package/dist/setup/index.d.ts +30 -0
- package/dist/setup/index.js +27 -0
- package/dist/setup/setup.d.ts +74 -0
- package/dist/setup/setup.js +98 -0
- package/dist/setup/wrapAsync.d.ts +4 -0
- package/dist/setup/wrapAsync.js +15 -0
- package/dist/{clear.d.ts → utility/clear.d.ts} +2 -2
- package/dist/utility/clear.js +30 -0
- package/dist/utility/index.d.ts +4 -0
- package/dist/utility/index.js +57 -0
- package/dist/utility/selectOptions.d.ts +3 -0
- package/dist/{selectOptions.js → utility/selectOptions.js} +31 -41
- package/dist/utility/type.d.ts +9 -0
- package/dist/utility/type.js +37 -0
- package/dist/utility/upload.d.ts +5 -0
- package/dist/{upload.js → utility/upload.js} +12 -40
- 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 +23 -0
- package/dist/utils/edit/calculateNewValue.d.ts +12 -5
- package/dist/utils/edit/calculateNewValue.js +19 -21
- package/dist/utils/edit/editInputElement.d.ts +16 -0
- package/dist/utils/edit/{fireInputEvent.js → editInputElement.js} +20 -26
- package/dist/utils/edit/isContentEditable.d.ts +4 -0
- package/dist/utils/edit/isContentEditable.js +14 -0
- package/dist/utils/edit/isEditable.d.ts +1 -0
- package/dist/utils/edit/prepareInput.d.ts +7 -0
- package/dist/utils/edit/prepareInput.js +77 -0
- package/dist/utils/edit/setFiles.d.ts +12 -0
- package/dist/utils/edit/setFiles.js +72 -0
- package/dist/utils/focus/copySelection.d.ts +1 -0
- package/dist/utils/focus/copySelection.js +36 -0
- package/dist/utils/focus/focus.js +3 -0
- package/dist/utils/focus/selectAll.d.ts +5 -0
- package/dist/utils/focus/selectAll.js +51 -0
- package/dist/utils/focus/selection.d.ts +42 -0
- package/dist/utils/focus/selection.js +190 -0
- package/dist/utils/index.d.ts +11 -4
- package/dist/utils/index.js +124 -33
- package/dist/utils/misc/getDocumentFromNode.d.ts +1 -0
- package/dist/utils/misc/getDocumentFromNode.js +14 -0
- package/dist/utils/pointer/firePointerEvents.d.ts +12 -1
- package/dist/utils/pointer/firePointerEvents.js +62 -5
- package/package.json +1 -1
- package/dist/clear.js +0 -46
- package/dist/click.d.ts +0 -9
- package/dist/click.js +0 -62
- package/dist/hover.d.ts +0 -4
- package/dist/hover.js +0 -43
- package/dist/keyboard/getNextKeyDef.js +0 -85
- package/dist/keyboard/keyboardImplementation.d.ts +0 -3
- package/dist/keyboard/keyboardImplementation.js +0 -169
- 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 -67
- package/dist/selectOptions.d.ts +0 -4
- package/dist/setup.d.ts +0 -92
- package/dist/setup.js +0 -203
- package/dist/tab.d.ts +0 -5
- package/dist/tab.js +0 -12
- package/dist/type.d.ts +0 -14
- package/dist/type.js +0 -74
- package/dist/upload.d.ts +0 -10
- package/dist/utils/edit/cursorPosition.d.ts +0 -2
- package/dist/utils/edit/cursorPosition.js +0 -35
- package/dist/utils/edit/fireInputEvent.d.ts +0 -8
- package/dist/utils/edit/selectionRange.d.ts +0 -5
- package/dist/utils/edit/selectionRange.js +0 -64
- package/dist/utils/pointer/fakeEvent.d.ts +0 -20
- package/dist/utils/pointer/fakeEvent.js +0 -91
|
@@ -0,0 +1,36 @@
|
|
|
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 _setup = require("../setup");
|
|
11
|
+
|
|
12
|
+
var _utils = require("../utils");
|
|
13
|
+
|
|
14
|
+
async function copy() {
|
|
15
|
+
var _doc$activeElement;
|
|
16
|
+
|
|
17
|
+
const doc = this[_setup.Config].document;
|
|
18
|
+
const target = (_doc$activeElement = doc.activeElement) != null ? _doc$activeElement :
|
|
19
|
+
/* istanbul ignore next */
|
|
20
|
+
doc.body;
|
|
21
|
+
const clipboardData = (0, _utils.copySelection)(target);
|
|
22
|
+
|
|
23
|
+
if (clipboardData.items.length === 0) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
_dom.fireEvent.copy(target, {
|
|
28
|
+
clipboardData
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (this[_setup.Config].writeToClipboard) {
|
|
32
|
+
await (0, _utils.writeDataTransferToClipboard)(doc, clipboardData);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return clipboardData;
|
|
36
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 _setup = require("../setup");
|
|
11
|
+
|
|
12
|
+
var _utils = require("../utils");
|
|
13
|
+
|
|
14
|
+
async function cut() {
|
|
15
|
+
var _doc$activeElement;
|
|
16
|
+
|
|
17
|
+
const doc = this[_setup.Config].document;
|
|
18
|
+
const target = (_doc$activeElement = doc.activeElement) != null ? _doc$activeElement :
|
|
19
|
+
/* istanbul ignore next */
|
|
20
|
+
doc.body;
|
|
21
|
+
const clipboardData = (0, _utils.copySelection)(target);
|
|
22
|
+
|
|
23
|
+
if (clipboardData.items.length === 0) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
_dom.fireEvent.cut(target, {
|
|
28
|
+
clipboardData
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if ((0, _utils.isEditable)(target)) {
|
|
32
|
+
var _prepareInput;
|
|
33
|
+
|
|
34
|
+
(_prepareInput = (0, _utils.prepareInput)('', target, 'deleteByCut')) == null ? void 0 : _prepareInput.commit();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (this[_setup.Config].writeToClipboard) {
|
|
38
|
+
await (0, _utils.writeDataTransferToClipboard)(doc, clipboardData);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return clipboardData;
|
|
42
|
+
}
|
|
@@ -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,47 @@
|
|
|
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 _setup = require("../setup");
|
|
11
|
+
|
|
12
|
+
var _utils = require("../utils");
|
|
13
|
+
|
|
14
|
+
async function paste(clipboardData) {
|
|
15
|
+
var _doc$activeElement, _ref;
|
|
16
|
+
|
|
17
|
+
const doc = this[_setup.Config].document;
|
|
18
|
+
const target = (_doc$activeElement = doc.activeElement) != null ? _doc$activeElement :
|
|
19
|
+
/* istanbul ignore next */
|
|
20
|
+
doc.body;
|
|
21
|
+
const data = (_ref = typeof clipboardData === 'string' ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _ref : await (0, _utils.readDataTransferFromClipboard)(doc).catch(() => {
|
|
22
|
+
throw new Error('`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.');
|
|
23
|
+
});
|
|
24
|
+
return pasteImpl(target, data);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function pasteImpl(target, clipboardData) {
|
|
28
|
+
_dom.fireEvent.paste(target, {
|
|
29
|
+
clipboardData
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if ((0, _utils.isEditable)(target)) {
|
|
33
|
+
const data = clipboardData.getData('text').substr(0, (0, _utils.getSpaceUntilMaxLength)(target));
|
|
34
|
+
|
|
35
|
+
if (data) {
|
|
36
|
+
var _prepareInput;
|
|
37
|
+
|
|
38
|
+
(_prepareInput = (0, _utils.prepareInput)(data, target, 'insertFromPaste')) == null ? void 0 : _prepareInput.commit();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getClipboardDataFromString(text) {
|
|
44
|
+
const dt = (0, _utils.createDataTransfer)();
|
|
45
|
+
dt.setData('text', text);
|
|
46
|
+
return dt;
|
|
47
|
+
}
|
|
@@ -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,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,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,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/document/index.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ declare global {
|
|
|
7
7
|
export declare function prepareDocument(document: Document): void;
|
|
8
8
|
export { getUIValue, setUIValue, startTrackValue, endTrackValue } from './value';
|
|
9
9
|
export { getUISelection, setUISelection } from './selection';
|
|
10
|
+
export type { UISelectionRange } from './selection';
|
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
declare const UISelection: unique symbol;
|
|
2
|
+
export interface UISelectionRange {
|
|
3
|
+
startOffset: number;
|
|
4
|
+
endOffset: number;
|
|
5
|
+
}
|
|
6
|
+
export interface UISelection {
|
|
7
|
+
anchorOffset: number;
|
|
8
|
+
focusOffset: number;
|
|
9
|
+
}
|
|
2
10
|
declare global {
|
|
3
11
|
interface Element {
|
|
4
|
-
[UISelection]?:
|
|
5
|
-
start: number;
|
|
6
|
-
end: number;
|
|
7
|
-
};
|
|
12
|
+
[UISelection]?: UISelection;
|
|
8
13
|
}
|
|
9
14
|
}
|
|
10
15
|
export declare function prepareSelectionInterceptor(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
11
|
-
export declare function setUISelection(element: HTMLInputElement | HTMLTextAreaElement,
|
|
16
|
+
export declare function setUISelection(element: HTMLInputElement | HTMLTextAreaElement, { focusOffset: focusOffsetParam, anchorOffset: anchorOffsetParam, }: {
|
|
17
|
+
anchorOffset?: number;
|
|
18
|
+
focusOffset: number;
|
|
19
|
+
}, mode?: 'replace' | 'modify'): void;
|
|
12
20
|
export declare function getUISelection(element: HTMLInputElement | HTMLTextAreaElement): {
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
startOffset: number;
|
|
22
|
+
endOffset: number;
|
|
23
|
+
anchorOffset: number;
|
|
24
|
+
focusOffset: number;
|
|
15
25
|
};
|
|
16
26
|
export declare function clearUISelection(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
17
27
|
export {};
|
|
@@ -8,6 +8,8 @@ exports.getUISelection = getUISelection;
|
|
|
8
8
|
exports.prepareSelectionInterceptor = prepareSelectionInterceptor;
|
|
9
9
|
exports.setUISelection = setUISelection;
|
|
10
10
|
|
|
11
|
+
var _ = require(".");
|
|
12
|
+
|
|
11
13
|
var _interceptor = require("./interceptor");
|
|
12
14
|
|
|
13
15
|
const UISelection = Symbol('Displayed selection in UI');
|
|
@@ -15,10 +17,11 @@ const UISelection = Symbol('Displayed selection in UI');
|
|
|
15
17
|
function prepareSelectionInterceptor(element) {
|
|
16
18
|
(0, _interceptor.prepareInterceptor)(element, 'setSelectionRange', function interceptorImpl(start, end, direction = 'none') {
|
|
17
19
|
const isUI = start && typeof start === 'object' && start[UISelection];
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
20
|
+
|
|
21
|
+
if (!isUI) {
|
|
22
|
+
this[UISelection] = undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
22
25
|
return {
|
|
23
26
|
realArgs: [Number(start), end, direction]
|
|
24
27
|
};
|
|
@@ -37,35 +40,48 @@ function prepareSelectionInterceptor(element) {
|
|
|
37
40
|
});
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
function setUISelection(element,
|
|
43
|
+
function setUISelection(element, {
|
|
44
|
+
focusOffset: focusOffsetParam,
|
|
45
|
+
anchorOffset: anchorOffsetParam = focusOffsetParam
|
|
46
|
+
}, mode = 'replace') {
|
|
47
|
+
const valueLength = (0, _.getUIValue)(element).length;
|
|
48
|
+
|
|
49
|
+
const sanitizeOffset = o => Math.max(0, Math.min(valueLength, o));
|
|
50
|
+
|
|
51
|
+
const anchorOffset = mode === 'replace' || element[UISelection] === undefined ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
|
|
52
|
+
const focusOffset = sanitizeOffset(focusOffsetParam);
|
|
53
|
+
const startOffset = Math.min(anchorOffset, focusOffset);
|
|
54
|
+
const endOffset = Math.max(anchorOffset, focusOffset);
|
|
41
55
|
element[UISelection] = {
|
|
42
|
-
|
|
43
|
-
|
|
56
|
+
anchorOffset,
|
|
57
|
+
focusOffset
|
|
44
58
|
};
|
|
45
59
|
|
|
46
|
-
if (element.selectionStart ===
|
|
60
|
+
if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
|
|
47
61
|
return;
|
|
48
62
|
} // eslint-disable-next-line no-new-wrappers
|
|
49
63
|
|
|
50
64
|
|
|
51
|
-
const startObj = new Number(
|
|
65
|
+
const startObj = new Number(startOffset);
|
|
52
66
|
startObj[UISelection] = UISelection;
|
|
53
67
|
|
|
54
68
|
try {
|
|
55
|
-
element.setSelectionRange(startObj,
|
|
69
|
+
element.setSelectionRange(startObj, endOffset);
|
|
56
70
|
} catch {// DOMException for invalid state is expected when calling this
|
|
57
71
|
// on an element without support for setSelectionRange
|
|
58
72
|
}
|
|
59
73
|
}
|
|
60
74
|
|
|
61
75
|
function getUISelection(element) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
76
|
+
var _element$UISelection, _element$selectionSta, _element$selectionEnd;
|
|
77
|
+
|
|
78
|
+
const sel = (_element$UISelection = element[UISelection]) != null ? _element$UISelection : {
|
|
79
|
+
anchorOffset: (_element$selectionSta = element.selectionStart) != null ? _element$selectionSta : 0,
|
|
80
|
+
focusOffset: (_element$selectionEnd = element.selectionEnd) != null ? _element$selectionEnd : 0
|
|
81
|
+
};
|
|
82
|
+
return { ...sel,
|
|
83
|
+
startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
|
|
84
|
+
endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
|
|
69
85
|
};
|
|
70
86
|
}
|
|
71
87
|
|
package/dist/document/value.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ declare global {
|
|
|
10
10
|
}
|
|
11
11
|
export declare function prepareValueInterceptor(element: HTMLInputElement): void;
|
|
12
12
|
export declare function setUIValue(element: HTMLInputElement | HTMLTextAreaElement, value: string): void;
|
|
13
|
-
export declare function getUIValue(element: HTMLInputElement | HTMLTextAreaElement): string
|
|
13
|
+
export declare function getUIValue(element: HTMLInputElement | HTMLTextAreaElement): string;
|
|
14
14
|
export declare function setInitialValue(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
15
15
|
export declare function getInitialValue(element: HTMLInputElement | HTMLTextAreaElement): string | undefined;
|
|
16
16
|
export declare function startTrackValue(element: HTMLInputElement | HTMLTextAreaElement): void;
|
package/dist/document/value.js
CHANGED
|
@@ -49,7 +49,7 @@ function setUIValue(element, value) {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
function getUIValue(element) {
|
|
52
|
-
return element[UIValue] === undefined ? element.value : element[UIValue];
|
|
52
|
+
return element[UIValue] === undefined ? element.value : String(element[UIValue]);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
function setInitialValue(element) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import { UserEventApis, setup } from './setup';
|
|
3
|
-
declare const userEvent: UserEventApis & {
|
|
4
|
-
setup: typeof setup;
|
|
5
|
-
};
|
|
6
|
-
export default userEvent;
|
|
7
|
-
export { specialCharMap as specialChars };
|
|
1
|
+
export { userEvent as default } from './setup';
|
|
8
2
|
export type { keyboardKey } from './keyboard';
|
|
3
|
+
export type { pointerKey } from './pointer';
|
package/dist/index.js
CHANGED
|
@@ -3,20 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
7
|
-
Object.defineProperty(exports, "specialChars", {
|
|
6
|
+
Object.defineProperty(exports, "default", {
|
|
8
7
|
enumerable: true,
|
|
9
8
|
get: function () {
|
|
10
|
-
return
|
|
9
|
+
return _setup.userEvent;
|
|
11
10
|
}
|
|
12
11
|
});
|
|
13
12
|
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
var _setup = require("./setup");
|
|
17
|
-
|
|
18
|
-
const userEvent = { ...Object.fromEntries(Object.entries(_setup.userEventApis).map(([k, f]) => [k, (...a) => f.apply(userEvent, a)])),
|
|
19
|
-
setup: _setup.setup
|
|
20
|
-
};
|
|
21
|
-
var _default = userEvent;
|
|
22
|
-
exports.default = _default;
|
|
13
|
+
var _setup = require("./setup");
|
|
@@ -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
|
|
package/dist/keyboard/index.d.ts
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}>): keyboardState;
|
|
8
|
-
export declare function keyboard(text: string, options: Partial<keyboardOptions & {
|
|
9
|
-
keyboardState: keyboardState;
|
|
10
|
-
delay: number;
|
|
11
|
-
}>): Promise<keyboardState>;
|
|
12
|
-
export declare function keyboardImplementationWrapper(text: string, config?: Partial<keyboardOptions & {
|
|
13
|
-
keyboardState: keyboardState;
|
|
14
|
-
}>): {
|
|
15
|
-
promise: Promise<void>;
|
|
16
|
-
state: keyboardState;
|
|
17
|
-
releaseAllKeys: () => void;
|
|
18
|
-
};
|
|
1
|
+
import { UserEvent } from '../setup';
|
|
2
|
+
import { releaseAllKeys } from './keyboardAction';
|
|
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>;
|
|
19
7
|
export declare function createKeyboardState(): keyboardState;
|
package/dist/keyboard/index.js
CHANGED
|
@@ -5,61 +5,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.createKeyboardState = createKeyboardState;
|
|
7
7
|
exports.keyboard = keyboard;
|
|
8
|
-
exports
|
|
9
|
-
Object.defineProperty(exports, "specialCharMap", {
|
|
8
|
+
Object.defineProperty(exports, "releaseAllKeys", {
|
|
10
9
|
enumerable: true,
|
|
11
10
|
get: function () {
|
|
12
|
-
return
|
|
11
|
+
return _keyboardAction.releaseAllKeys;
|
|
13
12
|
}
|
|
14
13
|
});
|
|
15
14
|
|
|
16
|
-
var
|
|
15
|
+
var _setup = require("../setup");
|
|
17
16
|
|
|
18
|
-
var
|
|
17
|
+
var _keyboardAction = require("./keyboardAction");
|
|
19
18
|
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
var _keyMap = require("./keyMap");
|
|
23
|
-
|
|
24
|
-
var _specialCharMap = require("./specialCharMap");
|
|
25
|
-
|
|
26
|
-
function keyboard(text, options) {
|
|
27
|
-
var _options$delay;
|
|
19
|
+
var _parseKeyDef = require("./parseKeyDef");
|
|
28
20
|
|
|
21
|
+
async function keyboard(text) {
|
|
29
22
|
const {
|
|
30
|
-
promise,
|
|
31
|
-
state
|
|
32
|
-
} = keyboardImplementationWrapper(text, options);
|
|
33
|
-
|
|
34
|
-
if (((_options$delay = options == null ? void 0 : options.delay) != null ? _options$delay : 0) > 0) {
|
|
35
|
-
return (0, _dom.getConfig)().asyncWrapper(() => promise.then(() => state));
|
|
36
|
-
} else {
|
|
37
|
-
// prevent users from dealing with UnhandledPromiseRejectionWarning in sync call
|
|
38
|
-
promise.catch(console.error);
|
|
39
|
-
return state;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function keyboardImplementationWrapper(text, config = {}) {
|
|
44
|
-
const {
|
|
45
|
-
keyboardState: state = createKeyboardState(),
|
|
46
|
-
delay = 0,
|
|
47
|
-
document: doc = document,
|
|
48
|
-
autoModify = false,
|
|
49
|
-
keyboardMap = _keyMap.defaultKeyMap
|
|
50
|
-
} = config;
|
|
51
|
-
const options = {
|
|
52
|
-
delay,
|
|
53
|
-
document: doc,
|
|
54
|
-
autoModify,
|
|
55
23
|
keyboardMap
|
|
56
|
-
};
|
|
57
|
-
(0,
|
|
58
|
-
return
|
|
59
|
-
promise: (0, _keyboardImplementation.keyboardImplementation)(text, options, state),
|
|
60
|
-
state,
|
|
61
|
-
releaseAllKeys: () => (0, _keyboardImplementation.releaseAllKeys)(options, state)
|
|
62
|
-
};
|
|
24
|
+
} = this[_setup.Config];
|
|
25
|
+
const actions = (0, _parseKeyDef.parseKeyDef)(keyboardMap, text);
|
|
26
|
+
return (0, _keyboardAction.keyboardAction)(this[_setup.Config], actions);
|
|
63
27
|
}
|
|
64
28
|
|
|
65
29
|
function createKeyboardState() {
|