@testing-library/user-event 13.4.1 → 14.0.0-alpha.10
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/README.md +4 -0
- package/dist/clear.d.ts +2 -2
- package/dist/clear.js +14 -29
- package/dist/click.d.ts +4 -3
- package/dist/click.js +29 -143
- package/dist/document/index.d.ts +10 -0
- package/dist/document/index.js +100 -0
- package/dist/document/interceptor.d.ts +15 -0
- package/dist/document/interceptor.js +37 -0
- package/dist/document/selection.d.ts +27 -0
- package/dist/document/selection.js +90 -0
- package/dist/document/value.d.ts +18 -0
- package/dist/document/value.js +77 -0
- package/dist/hover.d.ts +3 -3
- package/dist/hover.js +15 -57
- package/dist/index.d.ts +4 -21
- package/dist/index.js +4 -29
- package/dist/keyboard/getNextKeyDef.d.ts +3 -0
- package/dist/keyboard/getNextKeyDef.js +59 -87
- package/dist/keyboard/index.d.ts +1 -0
- package/dist/keyboard/index.js +4 -0
- package/dist/keyboard/keyMap.js +4 -0
- package/dist/keyboard/keyboardImplementation.js +28 -8
- package/dist/keyboard/plugins/arrow.js +7 -12
- package/dist/keyboard/plugins/character.js +29 -57
- package/dist/keyboard/plugins/combination.d.ts +5 -0
- package/dist/keyboard/plugins/combination.js +17 -0
- package/dist/keyboard/plugins/control.js +5 -16
- package/dist/keyboard/plugins/functional.js +33 -15
- package/dist/keyboard/plugins/index.js +5 -5
- package/dist/keyboard/shared/index.d.ts +0 -2
- package/dist/keyboard/shared/index.js +0 -26
- package/dist/keyboard/types.d.ts +8 -0
- package/dist/paste.d.ts +3 -2
- package/dist/paste.js +8 -15
- package/dist/pointer/index.d.ts +18 -0
- package/dist/pointer/index.js +90 -0
- package/dist/pointer/keyMap.d.ts +2 -0
- package/dist/pointer/keyMap.js +29 -0
- package/dist/pointer/parseKeyDef.d.ts +6 -0
- package/dist/pointer/parseKeyDef.js +36 -0
- package/dist/pointer/pointerAction.d.ts +6 -0
- package/dist/pointer/pointerAction.js +52 -0
- package/dist/pointer/pointerMove.d.ts +5 -0
- package/dist/pointer/pointerMove.js +136 -0
- package/dist/pointer/pointerPress.d.ts +7 -0
- package/dist/pointer/pointerPress.js +330 -0
- package/dist/pointer/resolveSelectionTarget.d.ts +5 -0
- package/dist/pointer/resolveSelectionTarget.js +75 -0
- package/dist/pointer/types.d.ts +72 -0
- package/dist/pointer/types.js +1 -0
- package/dist/selectOptions.d.ts +4 -0
- package/dist/{select-options.js → selectOptions.js} +18 -20
- package/dist/setup.d.ts +92 -0
- package/dist/setup.js +203 -0
- package/dist/tab.d.ts +3 -4
- package/dist/tab.js +3 -136
- package/dist/type.d.ts +14 -0
- package/dist/type.js +74 -0
- package/dist/upload.d.ts +4 -3
- package/dist/upload.js +3 -9
- 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/editInputElement.js +53 -0
- package/dist/utils/edit/getValue.d.ts +1 -1
- package/dist/utils/edit/getValue.js +3 -1
- 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/{blur.d.ts → utils/focus/blur.d.ts} +0 -0
- package/dist/utils/focus/blur.js +19 -0
- package/dist/{focus.d.ts → utils/focus/focus.d.ts} +0 -0
- package/dist/utils/focus/focus.js +22 -0
- package/dist/utils/focus/getTabDestination.d.ts +1 -0
- package/dist/utils/focus/getTabDestination.js +71 -0
- package/dist/utils/focus/isFocusable.js +1 -3
- 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 +13 -6
- package/dist/utils/index.js +145 -54
- package/dist/utils/keyDef/readNextDescriptor.d.ts +19 -0
- package/dist/utils/keyDef/readNextDescriptor.js +102 -0
- package/dist/utils/misc/findClosest.d.ts +1 -0
- package/dist/utils/misc/findClosest.js +20 -0
- package/dist/utils/misc/hasFormSubmit.d.ts +1 -0
- package/dist/utils/misc/hasFormSubmit.js +10 -0
- package/dist/utils/misc/isDescendantOrSelf.d.ts +1 -0
- package/dist/utils/misc/isDescendantOrSelf.js +20 -0
- package/dist/utils/pointer/firePointerEvents.d.ts +25 -0
- package/dist/utils/pointer/firePointerEvents.js +112 -0
- package/dist/utils/pointer/mouseButtons.d.ts +12 -0
- package/dist/utils/pointer/mouseButtons.js +45 -0
- package/package.json +4 -3
- package/dist/blur.js +0 -15
- package/dist/dom-helpers.d.ts +0 -3
- package/dist/focus.js +0 -15
- package/dist/keyboard/shared/carryValue.d.ts +0 -2
- package/dist/keyboard/shared/carryValue.js +0 -13
- package/dist/keyboard/shared/fireInputEvent.d.ts +0 -17
- package/dist/keyboard/shared/fireInputEvent.js +0 -110
- package/dist/select-options.d.ts +0 -4
- package/dist/type/index.d.ts +0 -7
- package/dist/type/index.js +0 -33
- package/dist/type/typeImplementation.d.ts +0 -10
- package/dist/type/typeImplementation.js +0 -64
- package/dist/utils/click/getMouseEventOptions.d.ts +0 -31
- package/dist/utils/click/getMouseEventOptions.js +0 -61
- package/dist/utils/edit/cursorPosition.d.ts +0 -2
- package/dist/utils/edit/cursorPosition.js +0 -35
- package/dist/utils/edit/hasUnreliableEmptyValue.d.ts +0 -10
- package/dist/utils/edit/hasUnreliableEmptyValue.js +0 -21
- package/dist/utils/edit/selectionRange.d.ts +0 -16
- package/dist/utils/edit/selectionRange.js +0 -104
- package/dist/utils/misc/isDocument.d.ts +0 -1
- package/dist/utils/misc/isDocument.js +0 -10
- package/dist/utils/misc/isLabelWithInternallyDisabledControl.d.ts +0 -1
- package/dist/utils/misc/isLabelWithInternallyDisabledControl.js +0 -22
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testing-library/user-event",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.0.0-alpha.10",
|
|
4
4
|
"description": "Fire events the same way the user does",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"author": "Giorgio Polvara <polvara@gmail.com>",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"engines": {
|
|
15
|
-
"node": ">=
|
|
15
|
+
"node": ">=12",
|
|
16
16
|
"npm": ">=6"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
|
-
"build": "kcd-scripts build",
|
|
30
|
+
"build": "kcd-scripts build --no-ts-defs && tsc -p tsconfig.build.json",
|
|
31
31
|
"lint": "kcd-scripts lint",
|
|
32
32
|
"setup": "npm install && npm run validate -s",
|
|
33
33
|
"test": "kcd-scripts test",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"@types/estree": "0.0.45",
|
|
47
47
|
"@types/jest-in-case": "^1.0.3",
|
|
48
48
|
"@types/react": "^17.0.3",
|
|
49
|
+
"eslint-import-resolver-typescript": "^2.5.0",
|
|
49
50
|
"is-ci": "^2.0.0",
|
|
50
51
|
"jest-in-case": "^1.0.2",
|
|
51
52
|
"jest-serializer-ansi": "^1.0.3",
|
package/dist/blur.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.blur = blur;
|
|
7
|
-
|
|
8
|
-
var _utils = require("./utils");
|
|
9
|
-
|
|
10
|
-
function blur(element) {
|
|
11
|
-
if (!(0, _utils.isFocusable)(element)) return;
|
|
12
|
-
const wasActive = (0, _utils.getActiveElement)(element.ownerDocument) === element;
|
|
13
|
-
if (!wasActive) return;
|
|
14
|
-
(0, _utils.eventWrapper)(() => element.blur());
|
|
15
|
-
}
|
package/dist/dom-helpers.d.ts
DELETED
package/dist/focus.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.focus = focus;
|
|
7
|
-
|
|
8
|
-
var _utils = require("./utils");
|
|
9
|
-
|
|
10
|
-
function focus(element) {
|
|
11
|
-
if (!(0, _utils.isFocusable)(element)) return;
|
|
12
|
-
const isAlreadyActive = (0, _utils.getActiveElement)(element.ownerDocument) === element;
|
|
13
|
-
if (isAlreadyActive) return;
|
|
14
|
-
(0, _utils.eventWrapper)(() => element.focus());
|
|
15
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.carryValue = carryValue;
|
|
7
|
-
|
|
8
|
-
var _utils = require("../../utils");
|
|
9
|
-
|
|
10
|
-
function carryValue(element, state, newValue) {
|
|
11
|
-
const value = (0, _utils.getValue)(element);
|
|
12
|
-
state.carryValue = value !== newValue && value === '' && (0, _utils.hasUnreliableEmptyValue)(element) ? newValue : undefined;
|
|
13
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { fireEvent } from '@testing-library/dom';
|
|
2
|
-
export declare function fireInputEvent(element: HTMLElement, { newValue, newSelectionStart, eventOverrides, }: {
|
|
3
|
-
newValue: string;
|
|
4
|
-
newSelectionStart: number;
|
|
5
|
-
eventOverrides: Partial<Parameters<typeof fireEvent>[1]> & {
|
|
6
|
-
[k: string]: unknown;
|
|
7
|
-
};
|
|
8
|
-
}): void;
|
|
9
|
-
declare const initial: unique symbol;
|
|
10
|
-
declare const onBlur: unique symbol;
|
|
11
|
-
declare global {
|
|
12
|
-
interface Element {
|
|
13
|
-
[initial]?: string;
|
|
14
|
-
[onBlur]?: EventListener;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
export {};
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.fireInputEvent = fireInputEvent;
|
|
7
|
-
|
|
8
|
-
var _dom = require("@testing-library/dom");
|
|
9
|
-
|
|
10
|
-
var _utils = require("../../utils");
|
|
11
|
-
|
|
12
|
-
function fireInputEvent(element, {
|
|
13
|
-
newValue,
|
|
14
|
-
newSelectionStart,
|
|
15
|
-
eventOverrides
|
|
16
|
-
}) {
|
|
17
|
-
// apply the changes before firing the input event, so that input handlers can access the altered dom and selection
|
|
18
|
-
if ((0, _utils.isContentEditable)(element)) {
|
|
19
|
-
applyNative(element, 'textContent', newValue);
|
|
20
|
-
} else
|
|
21
|
-
/* istanbul ignore else */
|
|
22
|
-
if ((0, _utils.isElementType)(element, ['input', 'textarea'])) {
|
|
23
|
-
applyNative(element, 'value', newValue);
|
|
24
|
-
} else {
|
|
25
|
-
// TODO: properly type guard
|
|
26
|
-
throw new Error('Invalid Element');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
setSelectionRangeAfterInput(element, newSelectionStart);
|
|
30
|
-
|
|
31
|
-
_dom.fireEvent.input(element, { ...eventOverrides
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
setSelectionRangeAfterInputHandler(element, newValue, newSelectionStart);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function setSelectionRangeAfterInput(element, newSelectionStart) {
|
|
38
|
-
(0, _utils.setSelectionRange)(element, newSelectionStart, newSelectionStart);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function setSelectionRangeAfterInputHandler(element, newValue, newSelectionStart) {
|
|
42
|
-
const value = (0, _utils.getValue)(element); // don't apply this workaround on elements that don't necessarily report the visible value - e.g. number
|
|
43
|
-
// TODO: this could probably be only applied when there is keyboardState.carryValue
|
|
44
|
-
|
|
45
|
-
const isUnreliableValue = value === '' && (0, _utils.hasUnreliableEmptyValue)(element);
|
|
46
|
-
|
|
47
|
-
if (!isUnreliableValue && value === newValue) {
|
|
48
|
-
const {
|
|
49
|
-
selectionStart
|
|
50
|
-
} = (0, _utils.getSelectionRange)(element);
|
|
51
|
-
|
|
52
|
-
if (selectionStart === value.length) {
|
|
53
|
-
// The value was changed as expected, but the cursor was moved to the end
|
|
54
|
-
// TODO: this could probably be only applied when we work around a framework setter on the element in applyNative
|
|
55
|
-
(0, _utils.setSelectionRange)(element, newSelectionStart, newSelectionStart);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const initial = Symbol('initial input value/textContent');
|
|
61
|
-
const onBlur = Symbol('onBlur');
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* React tracks the changes on element properties.
|
|
65
|
-
* This workaround tries to alter the DOM element without React noticing,
|
|
66
|
-
* so that it later picks up the change.
|
|
67
|
-
*
|
|
68
|
-
* @see https://github.com/facebook/react/blob/148f8e497c7d37a3c7ab99f01dec2692427272b1/packages/react-dom/src/client/inputValueTracking.js#L51-L104
|
|
69
|
-
*/
|
|
70
|
-
function applyNative(element, propName, propValue) {
|
|
71
|
-
const descriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
72
|
-
const nativeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
73
|
-
|
|
74
|
-
if (descriptor && nativeDescriptor) {
|
|
75
|
-
Object.defineProperty(element, propName, nativeDescriptor);
|
|
76
|
-
} // Keep track of the initial value to determine if a change event should be dispatched.
|
|
77
|
-
// CONSTRAINT: We can not determine what happened between focus event and our first API call.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (element[initial] === undefined) {
|
|
81
|
-
element[initial] = String(element[propName]);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
element[propName] = propValue; // Add an event listener for the blur event to the capture phase on the window.
|
|
85
|
-
// CONSTRAINT: Currently there is no cross-platform solution to unshift the event handler stack.
|
|
86
|
-
// Our change event might occur after other event handlers on the blur event have been processed.
|
|
87
|
-
|
|
88
|
-
if (!element[onBlur]) {
|
|
89
|
-
var _element$ownerDocumen;
|
|
90
|
-
|
|
91
|
-
(_element$ownerDocumen = element.ownerDocument.defaultView) == null ? void 0 : _element$ownerDocumen.addEventListener('blur', element[onBlur] = () => {
|
|
92
|
-
const initV = element[initial]; // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
93
|
-
|
|
94
|
-
delete element[onBlur]; // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
95
|
-
|
|
96
|
-
delete element[initial];
|
|
97
|
-
|
|
98
|
-
if (String(element[propName]) !== initV) {
|
|
99
|
-
_dom.fireEvent.change(element);
|
|
100
|
-
}
|
|
101
|
-
}, {
|
|
102
|
-
capture: true,
|
|
103
|
-
once: true
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (descriptor) {
|
|
108
|
-
Object.defineProperty(element, propName, descriptor);
|
|
109
|
-
}
|
|
110
|
-
}
|
package/dist/select-options.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { PointerOptions } from './utils';
|
|
2
|
-
declare const selectOptions: (args_0: Element, args_1: string | string[] | HTMLElement | HTMLElement[], args_2?: MouseEventInit | undefined, args_3?: PointerOptions | undefined) => void;
|
|
3
|
-
declare const deselectOptions: (args_0: Element, args_1: string | string[] | HTMLElement | HTMLElement[], args_2?: MouseEventInit | undefined, args_3?: PointerOptions | undefined) => void;
|
|
4
|
-
export { selectOptions, deselectOptions };
|
package/dist/type/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { typeOptions } from './typeImplementation';
|
|
2
|
-
export declare function type(element: Element, text: string, options?: typeOptions & {
|
|
3
|
-
delay?: 0;
|
|
4
|
-
}): void;
|
|
5
|
-
export declare function type(element: Element, text: string, options: typeOptions & {
|
|
6
|
-
delay: number;
|
|
7
|
-
}): Promise<void>;
|
package/dist/type/index.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.type = type;
|
|
7
|
-
|
|
8
|
-
var _dom = require("@testing-library/dom");
|
|
9
|
-
|
|
10
|
-
var _typeImplementation = require("./typeImplementation");
|
|
11
|
-
|
|
12
|
-
// this needs to be wrapped in the event/asyncWrapper for React's act and angular's change detection
|
|
13
|
-
// depending on whether it will be async.
|
|
14
|
-
function type(element, text, {
|
|
15
|
-
delay = 0,
|
|
16
|
-
...options
|
|
17
|
-
} = {}) {
|
|
18
|
-
// we do not want to wrap in the asyncWrapper if we're not
|
|
19
|
-
// going to actually be doing anything async, so we only wrap
|
|
20
|
-
// if the delay is greater than 0
|
|
21
|
-
if (delay > 0) {
|
|
22
|
-
return (0, _dom.getConfig)().asyncWrapper(() => (0, _typeImplementation.typeImplementation)(element, text, {
|
|
23
|
-
delay,
|
|
24
|
-
...options
|
|
25
|
-
}));
|
|
26
|
-
} else {
|
|
27
|
-
return void (0, _typeImplementation.typeImplementation)(element, text, {
|
|
28
|
-
delay,
|
|
29
|
-
...options
|
|
30
|
-
}) // prevents users from dealing with UnhandledPromiseRejectionWarning
|
|
31
|
-
.catch(console.error);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export interface typeOptions {
|
|
2
|
-
delay?: number;
|
|
3
|
-
skipClick?: boolean;
|
|
4
|
-
skipAutoClose?: boolean;
|
|
5
|
-
initialSelectionStart?: number;
|
|
6
|
-
initialSelectionEnd?: number;
|
|
7
|
-
}
|
|
8
|
-
export declare function typeImplementation(element: Element, text: string, { delay, skipClick, skipAutoClose, initialSelectionStart, initialSelectionEnd, }: typeOptions & {
|
|
9
|
-
delay: number;
|
|
10
|
-
}): Promise<void>;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.typeImplementation = typeImplementation;
|
|
7
|
-
|
|
8
|
-
var _utils = require("../utils");
|
|
9
|
-
|
|
10
|
-
var _click = require("../click");
|
|
11
|
-
|
|
12
|
-
var _keyboard = require("../keyboard");
|
|
13
|
-
|
|
14
|
-
async function typeImplementation(element, text, {
|
|
15
|
-
delay,
|
|
16
|
-
skipClick = false,
|
|
17
|
-
skipAutoClose = false,
|
|
18
|
-
initialSelectionStart = undefined,
|
|
19
|
-
initialSelectionEnd = undefined
|
|
20
|
-
}) {
|
|
21
|
-
// TODO: properly type guard
|
|
22
|
-
// we use this workaround for now to prevent changing behavior
|
|
23
|
-
if (element.disabled) return;
|
|
24
|
-
if (!skipClick) (0, _click.click)(element); // The focused element could change between each event, so get the currently active element each time
|
|
25
|
-
|
|
26
|
-
const currentElement = () => (0, _utils.getActiveElement)(element.ownerDocument); // by default, a new element has its selection start and end at 0
|
|
27
|
-
// but most of the time when people call "type", they expect it to type
|
|
28
|
-
// at the end of the current input value. So, if the selection start
|
|
29
|
-
// and end are both the default of 0, then we'll go ahead and change
|
|
30
|
-
// them to the length of the current value.
|
|
31
|
-
// the only time it would make sense to pass the initialSelectionStart or
|
|
32
|
-
// initialSelectionEnd is if you have an input with a value and want to
|
|
33
|
-
// explicitly start typing with the cursor at 0. Not super common.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const value = (0, _utils.getValue)(currentElement());
|
|
37
|
-
const {
|
|
38
|
-
selectionStart,
|
|
39
|
-
selectionEnd
|
|
40
|
-
} = (0, _utils.getSelectionRange)(element);
|
|
41
|
-
|
|
42
|
-
if (value != null && (selectionStart === null || selectionStart === 0) && (selectionEnd === null || selectionEnd === 0)) {
|
|
43
|
-
(0, _utils.setSelectionRange)(currentElement(), initialSelectionStart != null ? initialSelectionStart : value.length, initialSelectionEnd != null ? initialSelectionEnd : value.length);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const {
|
|
47
|
-
promise,
|
|
48
|
-
releaseAllKeys
|
|
49
|
-
} = (0, _keyboard.keyboardImplementationWrapper)(text, {
|
|
50
|
-
delay,
|
|
51
|
-
document: element.ownerDocument
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
if (delay > 0) {
|
|
55
|
-
await promise;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (!skipAutoClose) {
|
|
59
|
-
releaseAllKeys();
|
|
60
|
-
} // eslint-disable-next-line consistent-return -- we need to return the internal Promise so that it is catchable if we don't await
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return promise;
|
|
64
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export declare function getMouseEventOptions(event: string, init?: MouseEventInit, clickCount?: number): {
|
|
2
|
-
detail: number;
|
|
3
|
-
buttons: number;
|
|
4
|
-
button: number;
|
|
5
|
-
clientX?: number | undefined;
|
|
6
|
-
clientY?: number | undefined;
|
|
7
|
-
movementX?: number | undefined;
|
|
8
|
-
movementY?: number | undefined;
|
|
9
|
-
relatedTarget?: EventTarget | null | undefined;
|
|
10
|
-
screenX?: number | undefined;
|
|
11
|
-
screenY?: number | undefined;
|
|
12
|
-
altKey?: boolean | undefined;
|
|
13
|
-
ctrlKey?: boolean | undefined;
|
|
14
|
-
metaKey?: boolean | undefined;
|
|
15
|
-
modifierAltGraph?: boolean | undefined;
|
|
16
|
-
modifierCapsLock?: boolean | undefined;
|
|
17
|
-
modifierFn?: boolean | undefined;
|
|
18
|
-
modifierFnLock?: boolean | undefined;
|
|
19
|
-
modifierHyper?: boolean | undefined;
|
|
20
|
-
modifierNumLock?: boolean | undefined;
|
|
21
|
-
modifierScrollLock?: boolean | undefined;
|
|
22
|
-
modifierSuper?: boolean | undefined;
|
|
23
|
-
modifierSymbol?: boolean | undefined;
|
|
24
|
-
modifierSymbolLock?: boolean | undefined;
|
|
25
|
-
shiftKey?: boolean | undefined;
|
|
26
|
-
view?: Window | null | undefined;
|
|
27
|
-
which?: number | undefined;
|
|
28
|
-
bubbles?: boolean | undefined;
|
|
29
|
-
cancelable?: boolean | undefined;
|
|
30
|
-
composed?: boolean | undefined;
|
|
31
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getMouseEventOptions = getMouseEventOptions;
|
|
7
|
-
|
|
8
|
-
function isMousePressEvent(event) {
|
|
9
|
-
return event === 'mousedown' || event === 'mouseup' || event === 'click' || event === 'dblclick';
|
|
10
|
-
} // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const BUTTONS_NAMES = {
|
|
14
|
-
none: 0,
|
|
15
|
-
primary: 1,
|
|
16
|
-
secondary: 2,
|
|
17
|
-
auxiliary: 4
|
|
18
|
-
}; // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
|
|
19
|
-
|
|
20
|
-
const BUTTON_NAMES = {
|
|
21
|
-
primary: 0,
|
|
22
|
-
auxiliary: 1,
|
|
23
|
-
secondary: 2
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
function translateButtonNumber(value, from) {
|
|
27
|
-
var _Object$entries$find;
|
|
28
|
-
|
|
29
|
-
const [mapIn, mapOut] = from === 'button' ? [BUTTON_NAMES, BUTTONS_NAMES] : [BUTTONS_NAMES, BUTTON_NAMES];
|
|
30
|
-
const name = (_Object$entries$find = Object.entries(mapIn).find(([, i]) => i === value)) == null ? void 0 : _Object$entries$find[0]; // istanbul ignore next
|
|
31
|
-
|
|
32
|
-
return name && Object.prototype.hasOwnProperty.call(mapOut, name) ? mapOut[name] : 0;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function convertMouseButtons(event, init, property) {
|
|
36
|
-
if (!isMousePressEvent(event)) {
|
|
37
|
-
return 0;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (typeof init[property] === 'number') {
|
|
41
|
-
return init[property];
|
|
42
|
-
} else if (property === 'button' && typeof init.buttons === 'number') {
|
|
43
|
-
return translateButtonNumber(init.buttons, 'buttons');
|
|
44
|
-
} else if (property === 'buttons' && typeof init.button === 'number') {
|
|
45
|
-
return translateButtonNumber(init.button, 'button');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return property != 'button' && isMousePressEvent(event) ? 1 : 0;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function getMouseEventOptions(event, init, clickCount = 0) {
|
|
52
|
-
var _init;
|
|
53
|
-
|
|
54
|
-
init = (_init = init) != null ? _init : {};
|
|
55
|
-
return { ...init,
|
|
56
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail
|
|
57
|
-
detail: event === 'mousedown' || event === 'mouseup' || event === 'click' ? 1 + clickCount : clickCount,
|
|
58
|
-
buttons: convertMouseButtons(event, init, 'buttons'),
|
|
59
|
-
button: convertMouseButtons(event, init, 'button')
|
|
60
|
-
};
|
|
61
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isCursorAtEnd = isCursorAtEnd;
|
|
7
|
-
exports.isCursorAtStart = isCursorAtStart;
|
|
8
|
-
|
|
9
|
-
var _selectionRange = require("./selectionRange");
|
|
10
|
-
|
|
11
|
-
var _getValue2 = require("./getValue");
|
|
12
|
-
|
|
13
|
-
function isCursorAtEnd(element) {
|
|
14
|
-
var _getValue;
|
|
15
|
-
|
|
16
|
-
const {
|
|
17
|
-
selectionStart,
|
|
18
|
-
selectionEnd
|
|
19
|
-
} = (0, _selectionRange.getSelectionRange)(element);
|
|
20
|
-
return selectionStart === selectionEnd && (selectionStart != null ? selectionStart :
|
|
21
|
-
/* istanbul ignore next */
|
|
22
|
-
0) === ((_getValue = (0, _getValue2.getValue)(element)) != null ? _getValue :
|
|
23
|
-
/* istanbul ignore next */
|
|
24
|
-
'').length;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function isCursorAtStart(element) {
|
|
28
|
-
const {
|
|
29
|
-
selectionStart,
|
|
30
|
-
selectionEnd
|
|
31
|
-
} = (0, _selectionRange.getSelectionRange)(element);
|
|
32
|
-
return selectionStart === selectionEnd && (selectionStart != null ? selectionStart :
|
|
33
|
-
/* istanbul ignore next */
|
|
34
|
-
0) === 0;
|
|
35
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
declare enum unreliableValueInputTypes {
|
|
2
|
-
'number' = "number"
|
|
3
|
-
}
|
|
4
|
-
/**
|
|
5
|
-
* Check if an empty IDL value on the element could mean a derivation of displayed value and IDL value
|
|
6
|
-
*/
|
|
7
|
-
export declare function hasUnreliableEmptyValue(element: Element): element is HTMLInputElement & {
|
|
8
|
-
type: unreliableValueInputTypes;
|
|
9
|
-
};
|
|
10
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.hasUnreliableEmptyValue = hasUnreliableEmptyValue;
|
|
7
|
-
|
|
8
|
-
var _isElementType = require("../misc/isElementType");
|
|
9
|
-
|
|
10
|
-
var unreliableValueInputTypes;
|
|
11
|
-
/**
|
|
12
|
-
* Check if an empty IDL value on the element could mean a derivation of displayed value and IDL value
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
(function (unreliableValueInputTypes) {
|
|
16
|
-
unreliableValueInputTypes["number"] = "number";
|
|
17
|
-
})(unreliableValueInputTypes || (unreliableValueInputTypes = {}));
|
|
18
|
-
|
|
19
|
-
function hasUnreliableEmptyValue(element) {
|
|
20
|
-
return (0, _isElementType.isElementType)(element, 'input') && Boolean(unreliableValueInputTypes[element.type]);
|
|
21
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
declare enum selectionSupportType {
|
|
2
|
-
'text' = "text",
|
|
3
|
-
'search' = "search",
|
|
4
|
-
'url' = "url",
|
|
5
|
-
'tel' = "tel",
|
|
6
|
-
'password' = "password"
|
|
7
|
-
}
|
|
8
|
-
export declare function hasSelectionSupport(element: Element): element is HTMLTextAreaElement | (HTMLInputElement & {
|
|
9
|
-
type: selectionSupportType;
|
|
10
|
-
});
|
|
11
|
-
export declare function getSelectionRange(element: Element): {
|
|
12
|
-
selectionStart: number | null;
|
|
13
|
-
selectionEnd: number | null;
|
|
14
|
-
};
|
|
15
|
-
export declare function setSelectionRange(element: Element, newSelectionStart: number, newSelectionEnd: number): void;
|
|
16
|
-
export {};
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getSelectionRange = getSelectionRange;
|
|
7
|
-
exports.hasSelectionSupport = hasSelectionSupport;
|
|
8
|
-
exports.setSelectionRange = setSelectionRange;
|
|
9
|
-
|
|
10
|
-
var _isElementType = require("../misc/isElementType");
|
|
11
|
-
|
|
12
|
-
// https://github.com/jsdom/jsdom/blob/c2fb8ff94917a4d45e2398543f5dd2a8fed0bdab/lib/jsdom/living/nodes/HTMLInputElement-impl.js#L45
|
|
13
|
-
var selectionSupportType;
|
|
14
|
-
|
|
15
|
-
(function (selectionSupportType) {
|
|
16
|
-
selectionSupportType["text"] = "text";
|
|
17
|
-
selectionSupportType["search"] = "search";
|
|
18
|
-
selectionSupportType["url"] = "url";
|
|
19
|
-
selectionSupportType["tel"] = "tel";
|
|
20
|
-
selectionSupportType["password"] = "password";
|
|
21
|
-
})(selectionSupportType || (selectionSupportType = {}));
|
|
22
|
-
|
|
23
|
-
const InputSelection = Symbol('inputSelection');
|
|
24
|
-
|
|
25
|
-
function hasSelectionSupport(element) {
|
|
26
|
-
return (0, _isElementType.isElementType)(element, 'textarea') || (0, _isElementType.isElementType)(element, 'input') && Boolean(selectionSupportType[element.type]);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function getSelectionRange(element) {
|
|
30
|
-
if (hasSelectionSupport(element)) {
|
|
31
|
-
return {
|
|
32
|
-
selectionStart: element.selectionStart,
|
|
33
|
-
selectionEnd: element.selectionEnd
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if ((0, _isElementType.isElementType)(element, 'input')) {
|
|
38
|
-
var _InputSelection;
|
|
39
|
-
|
|
40
|
-
return (_InputSelection = element[InputSelection]) != null ? _InputSelection : {
|
|
41
|
-
selectionStart: null,
|
|
42
|
-
selectionEnd: null
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const selection = element.ownerDocument.getSelection(); // there should be no editing if the focusNode is outside of element
|
|
47
|
-
// TODO: properly handle selection ranges
|
|
48
|
-
|
|
49
|
-
if (selection != null && selection.rangeCount && element.contains(selection.focusNode)) {
|
|
50
|
-
const range = selection.getRangeAt(0);
|
|
51
|
-
return {
|
|
52
|
-
selectionStart: range.startOffset,
|
|
53
|
-
selectionEnd: range.endOffset
|
|
54
|
-
};
|
|
55
|
-
} else {
|
|
56
|
-
return {
|
|
57
|
-
selectionStart: null,
|
|
58
|
-
selectionEnd: null
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function setSelectionRange(element, newSelectionStart, newSelectionEnd) {
|
|
64
|
-
const {
|
|
65
|
-
selectionStart,
|
|
66
|
-
selectionEnd
|
|
67
|
-
} = getSelectionRange(element);
|
|
68
|
-
|
|
69
|
-
if (selectionStart === newSelectionStart && selectionEnd === newSelectionEnd) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (hasSelectionSupport(element)) {
|
|
74
|
-
element.setSelectionRange(newSelectionStart, newSelectionEnd);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if ((0, _isElementType.isElementType)(element, 'input')) {
|
|
78
|
-
;
|
|
79
|
-
element[InputSelection] = {
|
|
80
|
-
selectionStart: newSelectionStart,
|
|
81
|
-
selectionEnd: newSelectionEnd
|
|
82
|
-
};
|
|
83
|
-
} // Moving the selection inside <input> or <textarea> does not alter the document Selection.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if ((0, _isElementType.isElementType)(element, 'input') || (0, _isElementType.isElementType)(element, 'textarea')) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const range = element.ownerDocument.createRange();
|
|
91
|
-
range.selectNodeContents(element); // istanbul ignore else
|
|
92
|
-
|
|
93
|
-
if (element.firstChild) {
|
|
94
|
-
range.setStart(element.firstChild, newSelectionStart);
|
|
95
|
-
range.setEnd(element.firstChild, newSelectionEnd);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const selection = element.ownerDocument.getSelection(); // istanbul ignore else
|
|
99
|
-
|
|
100
|
-
if (selection) {
|
|
101
|
-
selection.removeAllRanges();
|
|
102
|
-
selection.addRange(range);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isDocument(el: Document | Element): el is Document;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isLabelWithInternallyDisabledControl(element: Element): boolean;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isLabelWithInternallyDisabledControl = isLabelWithInternallyDisabledControl;
|
|
7
|
-
|
|
8
|
-
var _isDisabled = require("./isDisabled");
|
|
9
|
-
|
|
10
|
-
var _isElementType = require("./isElementType");
|
|
11
|
-
|
|
12
|
-
// Absolutely NO events fire on label elements that contain their control
|
|
13
|
-
// if that control is disabled. NUTS!
|
|
14
|
-
// no joke. There are NO events for: <label><input disabled /><label>
|
|
15
|
-
function isLabelWithInternallyDisabledControl(element) {
|
|
16
|
-
if (!(0, _isElementType.isElementType)(element, 'label')) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const control = element.control;
|
|
21
|
-
return Boolean(control && element.contains(control) && (0, _isDisabled.isDisabled)(control));
|
|
22
|
-
}
|