@testing-library/user-event 14.0.0-alpha.13 → 14.0.0-alpha.17
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/index.d.ts +2 -5
- package/dist/index.js +7 -8
- package/dist/keyboard/index.d.ts +6 -17
- package/dist/keyboard/index.js +13 -41
- 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 -5
- package/dist/keyboard/parseKeyDef.js +61 -0
- package/dist/keyboard/plugins/character.js +16 -10
- package/dist/keyboard/plugins/combination.js +3 -1
- package/dist/keyboard/plugins/functional.js +38 -20
- package/dist/keyboard/types.d.ts +3 -17
- 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/pointerPress.d.ts +2 -1
- 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/{clear.js → utility/clear.js} +2 -5
- 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} +15 -24
- 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} +14 -40
- package/dist/utils/dataTransfer/Clipboard.d.ts +2 -0
- package/dist/utils/dataTransfer/Clipboard.js +45 -0
- package/dist/utils/dataTransfer/DataTransfer.d.ts +1 -0
- package/dist/utils/dataTransfer/DataTransfer.js +15 -0
- package/dist/utils/dataTransfer/FileList.js +13 -3
- 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/index.d.ts +2 -0
- package/dist/utils/index.js +26 -0
- package/dist/utils/misc/getDocumentFromNode.d.ts +1 -0
- package/dist/utils/misc/getDocumentFromNode.js +14 -0
- package/package.json +1 -1
- package/dist/click.d.ts +0 -9
- package/dist/click.js +0 -61
- package/dist/hover.d.ts +0 -4
- package/dist/hover.js +0 -43
- package/dist/keyboard/getNextKeyDef.js +0 -55
- package/dist/keyboard/keyboardImplementation.d.ts +0 -3
- package/dist/keyboard/keyboardImplementation.js +0 -165
- package/dist/paste.d.ts +0 -6
- package/dist/paste.js +0 -64
- package/dist/selectOptions.d.ts +0 -4
- package/dist/setup.d.ts +0 -92
- package/dist/setup.js +0 -217
- 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 -9
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { UserEvent } from '../setup';
|
|
2
|
+
import { Config } from '../setup/config';
|
|
3
|
+
export interface typeOptions {
|
|
4
|
+
skipClick?: Config['skipClick'];
|
|
5
|
+
skipAutoClose?: Config['skipClick'];
|
|
6
|
+
initialSelectionStart?: number;
|
|
7
|
+
initialSelectionEnd?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function type(this: UserEvent, element: Element, text: string, { skipClick, skipAutoClose, initialSelectionStart, initialSelectionEnd, }?: typeOptions): Promise<void>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.type = type;
|
|
7
|
+
|
|
8
|
+
var _utils = require("../utils");
|
|
9
|
+
|
|
10
|
+
var _keyboard = require("../keyboard");
|
|
11
|
+
|
|
12
|
+
var _config = require("../setup/config");
|
|
13
|
+
|
|
14
|
+
async function type(element, text, {
|
|
15
|
+
skipClick = this[_config.Config].skipClick,
|
|
16
|
+
skipAutoClose = this[_config.Config].skipAutoClose,
|
|
17
|
+
initialSelectionStart,
|
|
18
|
+
initialSelectionEnd
|
|
19
|
+
} = {}) {
|
|
20
|
+
// TODO: properly type guard
|
|
21
|
+
// we use this workaround for now to prevent changing behavior
|
|
22
|
+
if (element.disabled) return;
|
|
23
|
+
|
|
24
|
+
if (!skipClick) {
|
|
25
|
+
await this.click(element);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (initialSelectionStart !== undefined) {
|
|
29
|
+
(0, _utils.setSelectionRange)(element, initialSelectionStart, initialSelectionEnd != null ? initialSelectionEnd : initialSelectionStart);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
await this.keyboard(text);
|
|
33
|
+
|
|
34
|
+
if (!skipAutoClose) {
|
|
35
|
+
await (0, _keyboard.releaseAllKeys)(this[_config.Config]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -7,11 +7,13 @@ exports.upload = upload;
|
|
|
7
7
|
|
|
8
8
|
var _dom = require("@testing-library/dom");
|
|
9
9
|
|
|
10
|
-
var _utils = require("
|
|
10
|
+
var _utils = require("../utils");
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
var _setup = require("../setup");
|
|
13
|
+
|
|
14
|
+
var _setFiles = require("#src/utils/edit/setFiles");
|
|
15
|
+
|
|
16
|
+
async function upload(element, fileOrFiles) {
|
|
15
17
|
var _input$files;
|
|
16
18
|
|
|
17
19
|
const input = (0, _utils.isElementType)(element, 'label') ? element.control : element;
|
|
@@ -23,8 +25,8 @@ function upload(element, fileOrFiles, init, {
|
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
if ((0, _utils.isDisabled)(element)) return;
|
|
26
|
-
this.click(element);
|
|
27
|
-
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter(file => !applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? undefined : 1); // blur fires when the file selector pops up
|
|
28
|
+
await this.click(element);
|
|
29
|
+
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter(file => !this[_setup.Config].applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? undefined : 1); // blur fires when the file selector pops up
|
|
28
30
|
|
|
29
31
|
(0, _utils.blur)(element); // focus fires when they make their selection
|
|
30
32
|
|
|
@@ -36,41 +38,13 @@ function upload(element, fileOrFiles, init, {
|
|
|
36
38
|
return f === ((_input$files2 = input.files) == null ? void 0 : _input$files2.item(i));
|
|
37
39
|
})) {
|
|
38
40
|
return;
|
|
39
|
-
}
|
|
40
|
-
// but a new Event with a type set to "input" and "change"
|
|
41
|
-
// Kinda odd...
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const inputFiles = { ...files,
|
|
45
|
-
length: files.length,
|
|
46
|
-
item: index => files[index],
|
|
47
|
-
|
|
48
|
-
[Symbol.iterator]() {
|
|
49
|
-
let i = 0;
|
|
50
|
-
return {
|
|
51
|
-
next: () => ({
|
|
52
|
-
done: i >= files.length,
|
|
53
|
-
value: files[i++]
|
|
54
|
-
})
|
|
55
|
-
};
|
|
56
|
-
}
|
|
41
|
+
}
|
|
57
42
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
bubbles: true,
|
|
64
|
-
cancelable: false,
|
|
65
|
-
composed: true
|
|
66
|
-
}));
|
|
67
|
-
|
|
68
|
-
_dom.fireEvent.change(input, {
|
|
69
|
-
target: {
|
|
70
|
-
files: inputFiles
|
|
71
|
-
},
|
|
72
|
-
...(init == null ? void 0 : init.changeInit)
|
|
73
|
-
});
|
|
43
|
+
(0, _setFiles.setFiles)(input, (0, _utils.createFileList)(files));
|
|
44
|
+
|
|
45
|
+
_dom.fireEvent.input(input);
|
|
46
|
+
|
|
47
|
+
_dom.fireEvent.change(input);
|
|
74
48
|
}
|
|
75
49
|
|
|
76
50
|
function isAcceptableFile(file, accept) {
|
|
@@ -5,3 +5,5 @@ export declare function attachClipboardStubToView(window: Window & typeof global
|
|
|
5
5
|
};
|
|
6
6
|
export declare function resetClipboardStubOnView(window: Window & typeof globalThis): void;
|
|
7
7
|
export declare function detachClipboardStubFromView(window: Window & typeof globalThis): void;
|
|
8
|
+
export declare function readDataTransferFromClipboard(document: Document): Promise<DataTransfer>;
|
|
9
|
+
export declare function writeDataTransferToClipboard(document: Document, clipboardData: DataTransfer): Promise<void>;
|
|
@@ -6,7 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.attachClipboardStubToView = attachClipboardStubToView;
|
|
7
7
|
exports.createClipboardItem = createClipboardItem;
|
|
8
8
|
exports.detachClipboardStubFromView = detachClipboardStubFromView;
|
|
9
|
+
exports.readDataTransferFromClipboard = readDataTransferFromClipboard;
|
|
9
10
|
exports.resetClipboardStubOnView = resetClipboardStubOnView;
|
|
11
|
+
exports.writeDataTransferToClipboard = writeDataTransferToClipboard;
|
|
10
12
|
|
|
11
13
|
var _ = require("..");
|
|
12
14
|
|
|
@@ -127,6 +129,49 @@ function detachClipboardStubFromView(window) {
|
|
|
127
129
|
window.navigator.clipboard[ClipboardStubControl].detachClipboardStub();
|
|
128
130
|
}
|
|
129
131
|
}
|
|
132
|
+
|
|
133
|
+
async function readDataTransferFromClipboard(document) {
|
|
134
|
+
var _document$defaultView;
|
|
135
|
+
|
|
136
|
+
const clipboard = (_document$defaultView = document.defaultView) == null ? void 0 : _document$defaultView.navigator.clipboard;
|
|
137
|
+
const items = clipboard && (await clipboard.read());
|
|
138
|
+
|
|
139
|
+
if (!items) {
|
|
140
|
+
throw new Error('The Clipboard API is unavailable.');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const dt = (0, _.createDataTransfer)();
|
|
144
|
+
|
|
145
|
+
for (const item of items) {
|
|
146
|
+
for (const type of item.types) {
|
|
147
|
+
dt.setData(type, await item.getType(type).then(b => (0, _.readBlobText)(b)));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return dt;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function writeDataTransferToClipboard(document, clipboardData) {
|
|
155
|
+
var _document$defaultView2;
|
|
156
|
+
|
|
157
|
+
const clipboard = (_document$defaultView2 = document.defaultView) == null ? void 0 : _document$defaultView2.navigator.clipboard;
|
|
158
|
+
const items = [];
|
|
159
|
+
|
|
160
|
+
for (let i = 0; i < clipboardData.items.length; i++) {
|
|
161
|
+
const dtItem = clipboardData.items[i];
|
|
162
|
+
const blob = (0, _.getBlobFromDataTransferItem)(dtItem);
|
|
163
|
+
items.push(createClipboardItem(blob));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const written = clipboard && (await clipboard.write(items).then(() => true, // Can happen with other implementations that e.g. require permissions
|
|
167
|
+
|
|
168
|
+
/* istanbul ignore next */
|
|
169
|
+
() => false));
|
|
170
|
+
|
|
171
|
+
if (!written) {
|
|
172
|
+
throw new Error('The Clipboard API is unavailable.');
|
|
173
|
+
}
|
|
174
|
+
}
|
|
130
175
|
/* istanbul ignore else */
|
|
131
176
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
132
177
|
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createDataTransfer = createDataTransfer;
|
|
7
|
+
exports.getBlobFromDataTransferItem = getBlobFromDataTransferItem;
|
|
7
8
|
|
|
8
9
|
var _FileList = require("./FileList");
|
|
9
10
|
|
|
@@ -140,4 +141,18 @@ function createDataTransfer(files = []) {
|
|
|
140
141
|
get: () => (0, _FileList.createFileList)(files)
|
|
141
142
|
});
|
|
142
143
|
return dt;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function getBlobFromDataTransferItem(item) {
|
|
147
|
+
if (item.kind === 'file') {
|
|
148
|
+
return item.getAsFile();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
let data = '';
|
|
152
|
+
item.getAsString(s => {
|
|
153
|
+
data = s;
|
|
154
|
+
});
|
|
155
|
+
return new Blob([data], {
|
|
156
|
+
type: item.type
|
|
157
|
+
});
|
|
143
158
|
}
|
|
@@ -7,7 +7,17 @@ exports.createFileList = createFileList;
|
|
|
7
7
|
|
|
8
8
|
// FileList can not be created per constructor.
|
|
9
9
|
function createFileList(files) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const list = { ...files,
|
|
11
|
+
length: files.length,
|
|
12
|
+
item: index => list[index],
|
|
13
|
+
[Symbol.iterator]: function* nextFile() {
|
|
14
|
+
for (let i = 0; i < list.length; i++) {
|
|
15
|
+
yield list[i];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
list.constructor = FileList;
|
|
20
|
+
Object.setPrototypeOf(list, FileList.prototype);
|
|
21
|
+
Object.freeze(list);
|
|
22
|
+
return list;
|
|
13
23
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare const fakeFiles: unique symbol;
|
|
2
|
+
declare global {
|
|
3
|
+
interface HTMLInputElement {
|
|
4
|
+
[fakeFiles]?: {
|
|
5
|
+
restore: () => void;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export declare function setFiles(el: HTMLInputElement & {
|
|
10
|
+
type: 'file';
|
|
11
|
+
}, files: FileList): void;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.setFiles = setFiles;
|
|
7
|
+
// It is not possible to create a real FileList programmatically.
|
|
8
|
+
// Therefore assigning `files` property with a programmatically created FileList results in an error.
|
|
9
|
+
// Just assigning the property (as per fireEvent) breaks the interweaving with the `value` property.
|
|
10
|
+
const fakeFiles = Symbol('files and value properties are mocked');
|
|
11
|
+
|
|
12
|
+
function setFiles(el, files) {
|
|
13
|
+
var _el$fakeFiles;
|
|
14
|
+
|
|
15
|
+
(_el$fakeFiles = el[fakeFiles]) == null ? void 0 : _el$fakeFiles.restore();
|
|
16
|
+
const objectDescriptors = Object.getOwnPropertyDescriptors(el);
|
|
17
|
+
const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
|
|
18
|
+
|
|
19
|
+
function restore() {
|
|
20
|
+
Object.defineProperties(el, {
|
|
21
|
+
files: { ...prototypeDescriptors.files,
|
|
22
|
+
...objectDescriptors.files
|
|
23
|
+
},
|
|
24
|
+
value: { ...prototypeDescriptors.value,
|
|
25
|
+
...objectDescriptors.value
|
|
26
|
+
},
|
|
27
|
+
type: { ...prototypeDescriptors.type,
|
|
28
|
+
...objectDescriptors.type
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
el[fakeFiles] = {
|
|
34
|
+
restore
|
|
35
|
+
};
|
|
36
|
+
Object.defineProperties(el, {
|
|
37
|
+
files: { ...prototypeDescriptors.files,
|
|
38
|
+
...objectDescriptors.files,
|
|
39
|
+
get: () => files
|
|
40
|
+
},
|
|
41
|
+
value: { ...prototypeDescriptors.value,
|
|
42
|
+
...objectDescriptors.value,
|
|
43
|
+
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : '',
|
|
44
|
+
|
|
45
|
+
set(v) {
|
|
46
|
+
if (v === '') {
|
|
47
|
+
restore();
|
|
48
|
+
} else {
|
|
49
|
+
var _objectDescriptors$va;
|
|
50
|
+
|
|
51
|
+
(_objectDescriptors$va = objectDescriptors.value.set) == null ? void 0 : _objectDescriptors$va.call(el, v);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
},
|
|
56
|
+
// eslint-disable-next-line accessor-pairs
|
|
57
|
+
type: { ...prototypeDescriptors.type,
|
|
58
|
+
...objectDescriptors.type,
|
|
59
|
+
|
|
60
|
+
set(v) {
|
|
61
|
+
if (v !== 'file') {
|
|
62
|
+
restore() // In the browser the value will be empty.
|
|
63
|
+
// In Jsdom the value will be the same as
|
|
64
|
+
// before this element became file input - which might be empty.
|
|
65
|
+
;
|
|
66
|
+
el.type = v;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function copySelection(target: Element): DataTransfer;
|
|
@@ -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
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export * from './edit/isValidInputTimeValue';
|
|
|
14
14
|
export * from './edit/maxLength';
|
|
15
15
|
export * from './edit/prepareInput';
|
|
16
16
|
export * from './focus/blur';
|
|
17
|
+
export * from './focus/copySelection';
|
|
17
18
|
export * from './focus/focus';
|
|
18
19
|
export * from './focus/getActiveElement';
|
|
19
20
|
export * from './focus/getTabDestination';
|
|
@@ -24,6 +25,7 @@ export * from './focus/selector';
|
|
|
24
25
|
export * from './keyDef/readNextDescriptor';
|
|
25
26
|
export * from './misc/eventWrapper';
|
|
26
27
|
export * from './misc/findClosest';
|
|
28
|
+
export * from './misc/getDocumentFromNode';
|
|
27
29
|
export * from './misc/isDescendantOrSelf';
|
|
28
30
|
export * from './misc/isElementType';
|
|
29
31
|
export * from './misc/isVisible';
|
package/dist/utils/index.js
CHANGED
|
@@ -212,6 +212,19 @@ Object.keys(_blur).forEach(function (key) {
|
|
|
212
212
|
});
|
|
213
213
|
});
|
|
214
214
|
|
|
215
|
+
var _copySelection = require("./focus/copySelection");
|
|
216
|
+
|
|
217
|
+
Object.keys(_copySelection).forEach(function (key) {
|
|
218
|
+
if (key === "default" || key === "__esModule") return;
|
|
219
|
+
if (key in exports && exports[key] === _copySelection[key]) return;
|
|
220
|
+
Object.defineProperty(exports, key, {
|
|
221
|
+
enumerable: true,
|
|
222
|
+
get: function () {
|
|
223
|
+
return _copySelection[key];
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
215
228
|
var _focus = require("./focus/focus");
|
|
216
229
|
|
|
217
230
|
Object.keys(_focus).forEach(function (key) {
|
|
@@ -342,6 +355,19 @@ Object.keys(_findClosest).forEach(function (key) {
|
|
|
342
355
|
});
|
|
343
356
|
});
|
|
344
357
|
|
|
358
|
+
var _getDocumentFromNode = require("./misc/getDocumentFromNode");
|
|
359
|
+
|
|
360
|
+
Object.keys(_getDocumentFromNode).forEach(function (key) {
|
|
361
|
+
if (key === "default" || key === "__esModule") return;
|
|
362
|
+
if (key in exports && exports[key] === _getDocumentFromNode[key]) return;
|
|
363
|
+
Object.defineProperty(exports, key, {
|
|
364
|
+
enumerable: true,
|
|
365
|
+
get: function () {
|
|
366
|
+
return _getDocumentFromNode[key];
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
|
|
345
371
|
var _isDescendantOrSelf = require("./misc/isDescendantOrSelf");
|
|
346
372
|
|
|
347
373
|
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
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, { 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
DELETED
|
@@ -1,61 +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, {
|
|
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, {
|
|
23
|
-
skipPointerEventsCheck: true
|
|
24
|
-
});
|
|
25
|
-
this.pointer({
|
|
26
|
-
keys: '[MouseLeft]',
|
|
27
|
-
target: element
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function dblClick(element, {
|
|
32
|
-
skipPointerEventsCheck = false
|
|
33
|
-
} = {}) {
|
|
34
|
-
if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
|
|
35
|
-
throw new Error('unable to double-click element as it has or inherits pointer-events set to "none".');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
this.hover(element, {
|
|
39
|
-
skipPointerEventsCheck: true
|
|
40
|
-
});
|
|
41
|
-
this.pointer({
|
|
42
|
-
keys: '[MouseLeft][MouseLeft]',
|
|
43
|
-
target: element
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function tripleClick(element, {
|
|
48
|
-
skipPointerEventsCheck = false
|
|
49
|
-
} = {}) {
|
|
50
|
-
if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
|
|
51
|
-
throw new Error('unable to triple-click element as it has or inherits pointer-events set to "none".');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
this.hover(element, {
|
|
55
|
-
skipPointerEventsCheck: true
|
|
56
|
-
});
|
|
57
|
-
this.pointer({
|
|
58
|
-
keys: '[MouseLeft][MouseLeft][MouseLeft]',
|
|
59
|
-
target: element
|
|
60
|
-
});
|
|
61
|
-
}
|
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, { skipPointerEventsCheck }?: PointerOptions): void;
|
|
4
|
-
export declare function unhover(this: UserEvent, element: Element, { 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, {
|
|
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, {
|
|
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,55 +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
|
-
/**
|
|
11
|
-
* Get the next key from keyMap
|
|
12
|
-
*
|
|
13
|
-
* Keys can be referenced by `{key}` or `{special}` as well as physical locations per `[code]`.
|
|
14
|
-
* Everything else will be interpreted as a typed character - e.g. `a`.
|
|
15
|
-
* Brackets `{` and `[` can be escaped by doubling - e.g. `foo[[bar` translates to `foo[bar`.
|
|
16
|
-
* Keeping the key pressed can be written as `{key>}`.
|
|
17
|
-
* When keeping the key pressed you can choose how long (how many keydown and keypress) the key is pressed `{key>3}`.
|
|
18
|
-
* You can then release the key per `{key>3/}` or keep it pressed and continue with the next key.
|
|
19
|
-
*/
|
|
20
|
-
function getNextKeyDef(text, options) {
|
|
21
|
-
var _options$keyboardMap$;
|
|
22
|
-
|
|
23
|
-
const {
|
|
24
|
-
type,
|
|
25
|
-
descriptor,
|
|
26
|
-
consumedLength,
|
|
27
|
-
releasePrevious,
|
|
28
|
-
releaseSelf = true,
|
|
29
|
-
repeat
|
|
30
|
-
} = (0, _utils.readNextDescriptor)(text);
|
|
31
|
-
const keyDef = (_options$keyboardMap$ = options.keyboardMap.find(def => {
|
|
32
|
-
if (type === '[') {
|
|
33
|
-
var _def$code;
|
|
34
|
-
|
|
35
|
-
return ((_def$code = def.code) == null ? void 0 : _def$code.toLowerCase()) === descriptor.toLowerCase();
|
|
36
|
-
} else if (type === '{') {
|
|
37
|
-
var _def$key;
|
|
38
|
-
|
|
39
|
-
return ((_def$key = def.key) == null ? void 0 : _def$key.toLowerCase()) === descriptor.toLowerCase();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return def.key === descriptor;
|
|
43
|
-
})) != null ? _options$keyboardMap$ : {
|
|
44
|
-
key: 'Unknown',
|
|
45
|
-
code: 'Unknown',
|
|
46
|
-
[type === '[' ? 'code' : 'key']: descriptor
|
|
47
|
-
};
|
|
48
|
-
return {
|
|
49
|
-
keyDef,
|
|
50
|
-
consumedLength,
|
|
51
|
-
releasePrevious,
|
|
52
|
-
releaseSelf,
|
|
53
|
-
repeat
|
|
54
|
-
};
|
|
55
|
-
}
|
|
@@ -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;
|