@testing-library/user-event 14.0.0-alpha.12 → 14.0.0-alpha.16
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 +21 -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} +6 -6
- 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 +6 -0
- package/dist/utils/index.js +78 -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 -7
- package/dist/paste.js +0 -60
- 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 -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,11 @@ 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
|
+
async function upload(element, fileOrFiles, init) {
|
|
15
15
|
var _input$files;
|
|
16
16
|
|
|
17
17
|
const input = (0, _utils.isElementType)(element, 'label') ? element.control : element;
|
|
@@ -23,8 +23,8 @@ function upload(element, fileOrFiles, init, {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
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
|
|
26
|
+
await this.click(element);
|
|
27
|
+
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
28
|
|
|
29
29
|
(0, _utils.blur)(element); // focus fires when they make their selection
|
|
30
30
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function readBlobText(blob: Blob): Promise<string>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.readBlobText = readBlobText;
|
|
7
|
+
|
|
8
|
+
// jsdom does not implement Blob.text()
|
|
9
|
+
function readBlobText(blob) {
|
|
10
|
+
return new Promise((res, rej) => {
|
|
11
|
+
const fr = new FileReader();
|
|
12
|
+
fr.onerror = rej;
|
|
13
|
+
fr.onabort = rej;
|
|
14
|
+
|
|
15
|
+
fr.onload = () => {
|
|
16
|
+
res(String(fr.result));
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
fr.readAsText(blob);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function createClipboardItem(...blobs: Array<Blob | string>): ClipboardItem;
|
|
2
|
+
export declare function attachClipboardStubToView(window: Window & typeof globalThis): {
|
|
3
|
+
resetClipboardStub: () => void;
|
|
4
|
+
detachClipboardStub: () => void;
|
|
5
|
+
};
|
|
6
|
+
export declare function resetClipboardStubOnView(window: Window & typeof globalThis): void;
|
|
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>;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.attachClipboardStubToView = attachClipboardStubToView;
|
|
7
|
+
exports.createClipboardItem = createClipboardItem;
|
|
8
|
+
exports.detachClipboardStubFromView = detachClipboardStubFromView;
|
|
9
|
+
exports.readDataTransferFromClipboard = readDataTransferFromClipboard;
|
|
10
|
+
exports.resetClipboardStubOnView = resetClipboardStubOnView;
|
|
11
|
+
exports.writeDataTransferToClipboard = writeDataTransferToClipboard;
|
|
12
|
+
|
|
13
|
+
var _ = require("..");
|
|
14
|
+
|
|
15
|
+
// Clipboard is not available in jsdom
|
|
16
|
+
class ClipboardItemStub {
|
|
17
|
+
constructor(data) {
|
|
18
|
+
this.data = void 0;
|
|
19
|
+
this.data = data;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get types() {
|
|
23
|
+
return Array.from(Object.keys(this.data));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async getType(type) {
|
|
27
|
+
const data = await this.data[type];
|
|
28
|
+
|
|
29
|
+
if (!data) {
|
|
30
|
+
throw new Error(`${type} is not one of the available MIME types on this item.`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return data instanceof Blob ? data : new Blob([data], {
|
|
34
|
+
type
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const ClipboardStubControl = Symbol('Manage ClipboardSub');
|
|
41
|
+
|
|
42
|
+
class ClipboardStub extends EventTarget {
|
|
43
|
+
constructor(...args) {
|
|
44
|
+
super(...args);
|
|
45
|
+
this.items = [];
|
|
46
|
+
this[ClipboardStubControl] = void 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async read() {
|
|
50
|
+
return Array.from(this.items);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async readText() {
|
|
54
|
+
let text = '';
|
|
55
|
+
|
|
56
|
+
for (const item of this.items) {
|
|
57
|
+
const type = item.types.includes('text/plain') ? 'text/plain' : item.types.find(t => t.startsWith('text/'));
|
|
58
|
+
|
|
59
|
+
if (type) {
|
|
60
|
+
text += await item.getType(type).then(b => (0, _.readBlobText)(b));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return text;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async write(data) {
|
|
68
|
+
this.items = data;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async writeText(text) {
|
|
72
|
+
this.items = [createClipboardItem(text)];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
} // MDN lists string|Blob|Promise<Blob|string> as possible types in ClipboardItemData
|
|
76
|
+
// lib.dom.d.ts lists only Promise<Blob|string>
|
|
77
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem/ClipboardItem#syntax
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
function createClipboardItem(...blobs) {
|
|
81
|
+
// use real ClipboardItem if available
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
83
|
+
const constructor = typeof ClipboardItem === 'undefined' ? ClipboardItemStub :
|
|
84
|
+
/* istanbul ignore next */
|
|
85
|
+
ClipboardItem;
|
|
86
|
+
return new constructor(Object.fromEntries(blobs.map(b => [typeof b === 'string' ? 'text/plain' : b.type, Promise.resolve(b)])));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function attachClipboardStubToView(window) {
|
|
90
|
+
if (window.navigator.clipboard instanceof ClipboardStub) {
|
|
91
|
+
return window.navigator.clipboard[ClipboardStubControl];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const realClipboard = Object.getOwnPropertyDescriptor(window.navigator, 'clipboard');
|
|
95
|
+
let stub = new ClipboardStub();
|
|
96
|
+
const control = {
|
|
97
|
+
resetClipboardStub: () => {
|
|
98
|
+
stub = new ClipboardStub();
|
|
99
|
+
stub[ClipboardStubControl] = control;
|
|
100
|
+
},
|
|
101
|
+
detachClipboardStub: () => {
|
|
102
|
+
/* istanbul ignore if */
|
|
103
|
+
if (realClipboard) {
|
|
104
|
+
Object.defineProperty(window.navigator, 'clipboard', realClipboard);
|
|
105
|
+
} else {
|
|
106
|
+
Object.defineProperty(window.navigator, 'clipboard', {
|
|
107
|
+
value: undefined,
|
|
108
|
+
configurable: true
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
stub[ClipboardStubControl] = control;
|
|
114
|
+
Object.defineProperty(window.navigator, 'clipboard', {
|
|
115
|
+
get: () => stub,
|
|
116
|
+
configurable: true
|
|
117
|
+
});
|
|
118
|
+
return stub[ClipboardStubControl];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function resetClipboardStubOnView(window) {
|
|
122
|
+
if (window.navigator.clipboard instanceof ClipboardStub) {
|
|
123
|
+
window.navigator.clipboard[ClipboardStubControl].resetClipboardStub();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function detachClipboardStubFromView(window) {
|
|
128
|
+
if (window.navigator.clipboard instanceof ClipboardStub) {
|
|
129
|
+
window.navigator.clipboard[ClipboardStubControl].detachClipboardStub();
|
|
130
|
+
}
|
|
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
|
+
}
|
|
175
|
+
/* istanbul ignore else */
|
|
176
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
if (afterEach) {
|
|
180
|
+
afterEach(() => resetClipboardStubOnView(window));
|
|
181
|
+
}
|
|
182
|
+
/* istanbul ignore else */
|
|
183
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
if (afterAll) {
|
|
187
|
+
afterAll(() => detachClipboardStubFromView(window));
|
|
188
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createDataTransfer = createDataTransfer;
|
|
7
|
+
exports.getBlobFromDataTransferItem = getBlobFromDataTransferItem;
|
|
8
|
+
|
|
9
|
+
var _FileList = require("./FileList");
|
|
10
|
+
|
|
11
|
+
// DataTransfer is not implemented in jsdom.
|
|
12
|
+
// DataTransfer with FileList is being created by the browser on certain events.
|
|
13
|
+
class DataTransferItemStub {
|
|
14
|
+
constructor(dataOrFile, type) {
|
|
15
|
+
this.kind = void 0;
|
|
16
|
+
this.type = void 0;
|
|
17
|
+
this.file = null;
|
|
18
|
+
this.data = undefined;
|
|
19
|
+
|
|
20
|
+
if (typeof dataOrFile === 'string') {
|
|
21
|
+
this.kind = 'string';
|
|
22
|
+
this.type = String(type);
|
|
23
|
+
this.data = dataOrFile;
|
|
24
|
+
} else {
|
|
25
|
+
this.kind = 'file';
|
|
26
|
+
this.type = dataOrFile.type;
|
|
27
|
+
this.file = dataOrFile;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getAsFile() {
|
|
32
|
+
return this.file;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
getAsString(callback) {
|
|
36
|
+
if (typeof this.data === 'string') {
|
|
37
|
+
callback(this.data);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/* istanbul ignore next */
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
webkitGetAsEntry() {
|
|
44
|
+
throw new Error('not implemented');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
class DataTransferItemListStub extends Array {
|
|
50
|
+
add(...args) {
|
|
51
|
+
const item = new DataTransferItemStub(args[0], args[1]);
|
|
52
|
+
this.push(item);
|
|
53
|
+
return item;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
clear() {
|
|
57
|
+
this.splice(0, this.length);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
remove(index) {
|
|
61
|
+
this.splice(index, 1);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getTypeMatcher(type, exact) {
|
|
67
|
+
const [group, sub] = type.split('/');
|
|
68
|
+
const isGroup = !sub || sub === '*';
|
|
69
|
+
return item => {
|
|
70
|
+
return exact ? item.type === (isGroup ? group : type) : isGroup ? item.type.startsWith(`${group}/`) : item.type === group;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
class DataTransferStub {
|
|
75
|
+
constructor() {
|
|
76
|
+
this.dropEffect = 'none';
|
|
77
|
+
this.effectAllowed = 'uninitialized';
|
|
78
|
+
this.items = new DataTransferItemListStub();
|
|
79
|
+
this.files = (0, _FileList.createFileList)([]);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
getData(format) {
|
|
83
|
+
var _this$items$find;
|
|
84
|
+
|
|
85
|
+
const match = (_this$items$find = this.items.find(getTypeMatcher(format, true))) != null ? _this$items$find : this.items.find(getTypeMatcher(format, false));
|
|
86
|
+
let text = '';
|
|
87
|
+
match == null ? void 0 : match.getAsString(t => {
|
|
88
|
+
text = t;
|
|
89
|
+
});
|
|
90
|
+
return text;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
setData(format, data) {
|
|
94
|
+
const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
|
|
95
|
+
const item = new DataTransferItemStub(data, format);
|
|
96
|
+
|
|
97
|
+
if (matchIndex >= 0) {
|
|
98
|
+
this.items.splice(matchIndex, 1, item);
|
|
99
|
+
} else {
|
|
100
|
+
this.items.push(item);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
clearData(format) {
|
|
105
|
+
if (format) {
|
|
106
|
+
const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
|
|
107
|
+
|
|
108
|
+
if (matchIndex >= 0) {
|
|
109
|
+
this.items.remove(matchIndex);
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
this.items.clear();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
get types() {
|
|
117
|
+
const t = [];
|
|
118
|
+
|
|
119
|
+
if (this.files.length) {
|
|
120
|
+
t.push('Files');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
this.items.forEach(i => t.push(i.type));
|
|
124
|
+
Object.freeze(t);
|
|
125
|
+
return t;
|
|
126
|
+
}
|
|
127
|
+
/* istanbul ignore next */
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
setDragImage() {}
|
|
131
|
+
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function createDataTransfer(files = []) {
|
|
135
|
+
// Use real DataTransfer if available
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
137
|
+
const dt = typeof DataTransfer === 'undefined' ? new DataTransferStub() :
|
|
138
|
+
/* istanbul ignore next */
|
|
139
|
+
new DataTransfer();
|
|
140
|
+
Object.defineProperty(dt, 'files', {
|
|
141
|
+
get: () => (0, _FileList.createFileList)(files)
|
|
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
|
+
});
|
|
158
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createFileList(files: File[]): FileList;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createFileList = createFileList;
|
|
7
|
+
|
|
8
|
+
// FileList can not be created per constructor.
|
|
9
|
+
function createFileList(files) {
|
|
10
|
+
const f = [...files];
|
|
11
|
+
Object.setPrototypeOf(f, FileList.prototype);
|
|
12
|
+
return f;
|
|
13
|
+
}
|
|
@@ -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
|
@@ -1,4 +1,8 @@
|
|
|
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
8
|
export * from './edit/editInputElement';
|
|
@@ -10,6 +14,7 @@ export * from './edit/isValidInputTimeValue';
|
|
|
10
14
|
export * from './edit/maxLength';
|
|
11
15
|
export * from './edit/prepareInput';
|
|
12
16
|
export * from './focus/blur';
|
|
17
|
+
export * from './focus/copySelection';
|
|
13
18
|
export * from './focus/focus';
|
|
14
19
|
export * from './focus/getActiveElement';
|
|
15
20
|
export * from './focus/getTabDestination';
|
|
@@ -20,6 +25,7 @@ export * from './focus/selector';
|
|
|
20
25
|
export * from './keyDef/readNextDescriptor';
|
|
21
26
|
export * from './misc/eventWrapper';
|
|
22
27
|
export * from './misc/findClosest';
|
|
28
|
+
export * from './misc/getDocumentFromNode';
|
|
23
29
|
export * from './misc/isDescendantOrSelf';
|
|
24
30
|
export * from './misc/isElementType';
|
|
25
31
|
export * from './misc/isVisible';
|
package/dist/utils/index.js
CHANGED
|
@@ -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) {
|
|
@@ -160,6 +212,19 @@ Object.keys(_blur).forEach(function (key) {
|
|
|
160
212
|
});
|
|
161
213
|
});
|
|
162
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
|
+
|
|
163
228
|
var _focus = require("./focus/focus");
|
|
164
229
|
|
|
165
230
|
Object.keys(_focus).forEach(function (key) {
|
|
@@ -290,6 +355,19 @@ Object.keys(_findClosest).forEach(function (key) {
|
|
|
290
355
|
});
|
|
291
356
|
});
|
|
292
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
|
+
|
|
293
371
|
var _isDescendantOrSelf = require("./misc/isDescendantOrSelf");
|
|
294
372
|
|
|
295
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;
|