@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
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;
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.keyboardImplementation = keyboardImplementation;
|
|
7
|
-
exports.releaseAllKeys = releaseAllKeys;
|
|
8
|
-
|
|
9
|
-
var _dom = require("@testing-library/dom");
|
|
10
|
-
|
|
11
|
-
var _utils = require("../utils");
|
|
12
|
-
|
|
13
|
-
var _getNextKeyDef = require("./getNextKeyDef");
|
|
14
|
-
|
|
15
|
-
var plugins = _interopRequireWildcard(require("./plugins"));
|
|
16
|
-
|
|
17
|
-
var _getEventProps = require("./getEventProps");
|
|
18
|
-
|
|
19
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
20
|
-
|
|
21
|
-
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; }
|
|
22
|
-
|
|
23
|
-
async function keyboardImplementation(text, options, state) {
|
|
24
|
-
var _state$repeatKey;
|
|
25
|
-
|
|
26
|
-
const {
|
|
27
|
-
document
|
|
28
|
-
} = options;
|
|
29
|
-
|
|
30
|
-
const getCurrentElement = () => getActive(document);
|
|
31
|
-
|
|
32
|
-
const {
|
|
33
|
-
keyDef,
|
|
34
|
-
consumedLength,
|
|
35
|
-
releasePrevious,
|
|
36
|
-
releaseSelf,
|
|
37
|
-
repeat
|
|
38
|
-
} = (_state$repeatKey = state.repeatKey) != null ? _state$repeatKey : (0, _getNextKeyDef.getNextKeyDef)(text, options);
|
|
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`.
|
|
41
|
-
|
|
42
|
-
if (pressed && !state.repeatKey) {
|
|
43
|
-
keyup(keyDef, getCurrentElement, options, state, pressed.unpreventedDefault);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (!releasePrevious) {
|
|
47
|
-
const unpreventedDefault = keydown(keyDef, getCurrentElement, options, state);
|
|
48
|
-
|
|
49
|
-
if (unpreventedDefault && hasKeyPress(keyDef, state)) {
|
|
50
|
-
keypress(keyDef, getCurrentElement, options, state);
|
|
51
|
-
} // Release the key only on the last iteration on `state.repeatKey`.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (releaseSelf && repeat <= 1) {
|
|
55
|
-
keyup(keyDef, getCurrentElement, options, state, unpreventedDefault);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (repeat > 1) {
|
|
60
|
-
state.repeatKey = {
|
|
61
|
-
// don't consume again on the next iteration
|
|
62
|
-
consumedLength: 0,
|
|
63
|
-
keyDef,
|
|
64
|
-
releasePrevious,
|
|
65
|
-
releaseSelf,
|
|
66
|
-
repeat: repeat - 1
|
|
67
|
-
};
|
|
68
|
-
} else {
|
|
69
|
-
delete state.repeatKey;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (text.length > consumedLength || repeat > 1) {
|
|
73
|
-
if (options.delay > 0) {
|
|
74
|
-
await (0, _utils.wait)(options.delay);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return keyboardImplementation(text.slice(consumedLength), options, state);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return void undefined;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function getActive(document) {
|
|
84
|
-
var _getActiveElement;
|
|
85
|
-
|
|
86
|
-
return (_getActiveElement = (0, _utils.getActiveElement)(document)) != null ? _getActiveElement :
|
|
87
|
-
/* istanbul ignore next */
|
|
88
|
-
document.body;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function releaseAllKeys(options, state) {
|
|
92
|
-
const getCurrentElement = () => getActive(options.document);
|
|
93
|
-
|
|
94
|
-
for (const k of state.pressed) {
|
|
95
|
-
keyup(k.keyDef, getCurrentElement, options, state, k.unpreventedDefault);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function keydown(keyDef, getCurrentElement, options, state) {
|
|
100
|
-
const element = getCurrentElement(); // clear carried characters when focus is moved
|
|
101
|
-
|
|
102
|
-
if (element !== state.activeElement) {
|
|
103
|
-
state.carryValue = undefined;
|
|
104
|
-
state.carryChar = '';
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
state.activeElement = element;
|
|
108
|
-
applyPlugins(plugins.preKeydownBehavior, keyDef, element, options, state);
|
|
109
|
-
|
|
110
|
-
const unpreventedDefault = _dom.fireEvent.keyDown(element, (0, _getEventProps.getKeyEventProps)(keyDef, state));
|
|
111
|
-
|
|
112
|
-
state.pressed.push({
|
|
113
|
-
keyDef,
|
|
114
|
-
unpreventedDefault
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
if (unpreventedDefault) {
|
|
118
|
-
// all default behavior like keypress/submit etc is applied to the currentElement
|
|
119
|
-
applyPlugins(plugins.keydownBehavior, keyDef, getCurrentElement(), options, state);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return unpreventedDefault;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function keypress(keyDef, getCurrentElement, options, state) {
|
|
126
|
-
const element = getCurrentElement();
|
|
127
|
-
|
|
128
|
-
const unpreventedDefault = _dom.fireEvent.keyPress(element, { ...(0, _getEventProps.getKeyEventProps)(keyDef, state),
|
|
129
|
-
charCode: keyDef.key === 'Enter' ? 13 : String(keyDef.key).charCodeAt(0)
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
if (unpreventedDefault) {
|
|
133
|
-
applyPlugins(plugins.keypressBehavior, keyDef, getCurrentElement(), options, state);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function keyup(keyDef, getCurrentElement, options, state, unprevented) {
|
|
138
|
-
const element = getCurrentElement();
|
|
139
|
-
applyPlugins(plugins.preKeyupBehavior, keyDef, element, options, state);
|
|
140
|
-
|
|
141
|
-
const unpreventedDefault = _dom.fireEvent.keyUp(element, (0, _getEventProps.getKeyEventProps)(keyDef, state));
|
|
142
|
-
|
|
143
|
-
if (unprevented && unpreventedDefault) {
|
|
144
|
-
applyPlugins(plugins.keyupBehavior, keyDef, getCurrentElement(), options, state);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
state.pressed = state.pressed.filter(k => k.keyDef !== keyDef);
|
|
148
|
-
applyPlugins(plugins.postKeyupBehavior, keyDef, element, options, state);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function applyPlugins(pluginCollection, keyDef, element, options, state) {
|
|
152
|
-
const plugin = pluginCollection.find(p => p.matches(keyDef, element, options, state));
|
|
153
|
-
|
|
154
|
-
if (plugin) {
|
|
155
|
-
plugin.handle(keyDef, element, options, state);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return !!plugin;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function hasKeyPress(keyDef, state) {
|
|
162
|
-
var _keyDef$key;
|
|
163
|
-
|
|
164
|
-
return (((_keyDef$key = keyDef.key) == null ? void 0 : _keyDef$key.length) === 1 || keyDef.key === 'Enter') && !state.modifiers.ctrl && !state.modifiers.alt;
|
|
165
|
-
}
|
package/dist/paste.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { UserEvent } from './setup';
|
|
2
|
-
interface pasteOptions {
|
|
3
|
-
initialSelectionStart?: number;
|
|
4
|
-
initialSelectionEnd?: number;
|
|
5
|
-
}
|
|
6
|
-
export declare function paste(this: UserEvent, element: HTMLElement, text: string, init?: ClipboardEventInit, { initialSelectionStart, initialSelectionEnd }?: pasteOptions): void;
|
|
7
|
-
export {};
|
package/dist/paste.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
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 isSupportedElement(element) {
|
|
13
|
-
return (0, _utils.isElementType)(element, 'input') && Boolean(_utils.editableInputTypes[element.type]) || (0, _utils.isElementType)(element, 'textarea');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function paste(element, text, init, {
|
|
17
|
-
initialSelectionStart,
|
|
18
|
-
initialSelectionEnd
|
|
19
|
-
} = {}) {
|
|
20
|
-
var _prepareInput;
|
|
21
|
-
|
|
22
|
-
// TODO: implement for contenteditable
|
|
23
|
-
if (!isSupportedElement(element)) {
|
|
24
|
-
throw new TypeError(`The given ${element.tagName} element is currently unsupported.
|
|
25
|
-
A PR extending this implementation would be very much welcome at https://github.com/testing-library/user-event`);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if ((0, _utils.isDisabled)(element)) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
(0, _utils.eventWrapper)(() => element.focus()); // by default, a new element has it's selection start and end at 0
|
|
33
|
-
// but most of the time when people call "paste", they expect it to paste
|
|
34
|
-
// at the end of the current input value. So, if the selection start
|
|
35
|
-
// and end are both the default of 0, then we'll go ahead and change
|
|
36
|
-
// them to the length of the current value.
|
|
37
|
-
// the only time it would make sense to pass the initialSelectionStart or
|
|
38
|
-
// initialSelectionEnd is if you have an input with a value and want to
|
|
39
|
-
// explicitely start typing with the cursor at 0. Not super common.
|
|
40
|
-
|
|
41
|
-
if (element.selectionStart === 0 && element.selectionEnd === 0) {
|
|
42
|
-
(0, _utils.setSelectionRange)(element, initialSelectionStart != null ? initialSelectionStart : element.value.length, initialSelectionEnd != null ? initialSelectionEnd : element.value.length);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
_dom.fireEvent.paste(element, init);
|
|
46
|
-
|
|
47
|
-
if (element.readOnly) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
text = text.substr(0, (0, _utils.getSpaceUntilMaxLength)(element));
|
|
52
|
-
const inputRange = (0, _utils.getInputRange)(element);
|
|
53
|
-
/* istanbul ignore if */
|
|
54
|
-
|
|
55
|
-
if (!inputRange) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
(_prepareInput = (0, _utils.prepareInput)(text, element, 'insertFromPaste')) == null ? void 0 : _prepareInput.commit();
|
|
60
|
-
}
|
package/dist/selectOptions.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { PointerOptions } from './utils';
|
|
2
|
-
import type { UserEvent } from './setup';
|
|
3
|
-
export declare function selectOptions(this: UserEvent, select: Element, values: HTMLElement | HTMLElement[] | string[] | string, options?: PointerOptions): void;
|
|
4
|
-
export declare function deselectOptions(this: UserEvent, select: Element, values: HTMLElement | HTMLElement[] | string[] | string, options?: PointerOptions): void;
|
package/dist/setup.d.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { clear } from './clear';
|
|
2
|
-
import { click, clickOptions, dblClick, tripleClick } from './click';
|
|
3
|
-
import { hover, unhover } from './hover';
|
|
4
|
-
import { keyboard, keyboardOptions } from './keyboard';
|
|
5
|
-
import type { keyboardState } from './keyboard/types';
|
|
6
|
-
import { paste } from './paste';
|
|
7
|
-
import { pointer } from './pointer';
|
|
8
|
-
import type { pointerOptions, pointerState } from './pointer/types';
|
|
9
|
-
import { deselectOptions, selectOptions } from './selectOptions';
|
|
10
|
-
import { tab, tabOptions } from './tab';
|
|
11
|
-
import { type, typeOptions } from './type';
|
|
12
|
-
import { upload, uploadOptions } from './upload';
|
|
13
|
-
import { PointerOptions } from './utils';
|
|
14
|
-
export declare const userEventApis: {
|
|
15
|
-
clear: typeof clear;
|
|
16
|
-
click: typeof click;
|
|
17
|
-
dblClick: typeof dblClick;
|
|
18
|
-
deselectOptions: typeof deselectOptions;
|
|
19
|
-
hover: typeof hover;
|
|
20
|
-
keyboard: typeof keyboard;
|
|
21
|
-
paste: typeof paste;
|
|
22
|
-
pointer: typeof pointer;
|
|
23
|
-
selectOptions: typeof selectOptions;
|
|
24
|
-
tab: typeof tab;
|
|
25
|
-
tripleClick: typeof tripleClick;
|
|
26
|
-
type: typeof type;
|
|
27
|
-
unhover: typeof unhover;
|
|
28
|
-
upload: typeof upload;
|
|
29
|
-
};
|
|
30
|
-
export declare type UserEventApis = typeof userEventApis;
|
|
31
|
-
declare type setup = ReturnType<typeof _setup>['setup'];
|
|
32
|
-
export declare type UserEvent = UserEventApis & {
|
|
33
|
-
setup: setup;
|
|
34
|
-
};
|
|
35
|
-
declare type ClickOptions = Omit<clickOptions, 'clickCount'>;
|
|
36
|
-
declare type KeyboardOptions = Partial<keyboardOptions>;
|
|
37
|
-
declare type PointerApiOptions = Partial<pointerOptions>;
|
|
38
|
-
declare type TabOptions = Omit<tabOptions, 'shift'>;
|
|
39
|
-
declare type TypeOptions = Omit<typeOptions, 'initialSelectionStart' | 'initialSelectionEnd'>;
|
|
40
|
-
declare type UploadOptions = uploadOptions;
|
|
41
|
-
interface SetupOptions extends ClickOptions, KeyboardOptions, PointerOptions, PointerApiOptions, TabOptions, TypeOptions, UploadOptions {
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Start a "session" with userEvent.
|
|
45
|
-
* All APIs returned by this function share an input device state and a default configuration.
|
|
46
|
-
*/
|
|
47
|
-
export declare function setup(options?: SetupOptions): {
|
|
48
|
-
clear: typeof clear;
|
|
49
|
-
click: typeof click;
|
|
50
|
-
dblClick: typeof dblClick;
|
|
51
|
-
deselectOptions: typeof deselectOptions;
|
|
52
|
-
hover: typeof hover;
|
|
53
|
-
keyboard: typeof keyboard;
|
|
54
|
-
paste: typeof paste;
|
|
55
|
-
pointer: typeof pointer;
|
|
56
|
-
selectOptions: typeof selectOptions;
|
|
57
|
-
tab: typeof tab;
|
|
58
|
-
tripleClick: typeof tripleClick;
|
|
59
|
-
type: typeof type;
|
|
60
|
-
unhover: typeof unhover;
|
|
61
|
-
upload: typeof upload;
|
|
62
|
-
} & {
|
|
63
|
-
/**
|
|
64
|
-
* Create a set of callbacks with different default settings but the same state.
|
|
65
|
-
*/
|
|
66
|
-
setup(options: SetupOptions): {
|
|
67
|
-
clear: typeof clear;
|
|
68
|
-
click: typeof click;
|
|
69
|
-
dblClick: typeof dblClick;
|
|
70
|
-
deselectOptions: typeof deselectOptions;
|
|
71
|
-
hover: typeof hover;
|
|
72
|
-
keyboard: typeof keyboard;
|
|
73
|
-
paste: typeof paste;
|
|
74
|
-
pointer: typeof pointer;
|
|
75
|
-
selectOptions: typeof selectOptions;
|
|
76
|
-
tab: typeof tab;
|
|
77
|
-
tripleClick: typeof tripleClick;
|
|
78
|
-
type: typeof type;
|
|
79
|
-
unhover: typeof unhover;
|
|
80
|
-
upload: typeof upload;
|
|
81
|
-
} & any;
|
|
82
|
-
};
|
|
83
|
-
declare function _setup({ applyAccept, autoModify, delay, document, keyboardMap, pointerMap, skipAutoClose, skipClick, skipHover, skipPointerEventsCheck, }: SetupOptions, { keyboardState, pointerState, }: {
|
|
84
|
-
keyboardState: keyboardState;
|
|
85
|
-
pointerState: pointerState;
|
|
86
|
-
}): UserEventApis & {
|
|
87
|
-
/**
|
|
88
|
-
* Create a set of callbacks with different default settings but the same state.
|
|
89
|
-
*/
|
|
90
|
-
setup(options: SetupOptions): ReturnType<typeof _setup>;
|
|
91
|
-
};
|
|
92
|
-
export {};
|