@testing-library/user-event 13.0.10 → 13.0.14
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/clear.js +7 -9
- package/dist/click.js +5 -7
- package/dist/keyboard/plugins/arrow.js +3 -3
- package/dist/keyboard/plugins/character.js +51 -34
- package/dist/keyboard/plugins/control.js +14 -10
- package/dist/keyboard/plugins/functional.js +7 -13
- package/dist/keyboard/plugins/index.js +5 -4
- package/dist/keyboard/shared/carryValue.d.ts +2 -0
- package/dist/keyboard/shared/carryValue.js +13 -0
- package/dist/keyboard/shared/{fireInputEventIfNeeded.d.ts → fireInputEvent.d.ts} +2 -5
- package/dist/keyboard/shared/fireInputEvent.js +59 -0
- package/dist/keyboard/shared/index.d.ts +2 -2
- package/dist/keyboard/shared/index.js +12 -12
- package/dist/paste.js +22 -19
- package/dist/select-options.js +1 -1
- package/dist/type/typeImplementation.js +3 -15
- package/dist/upload.js +1 -1
- package/dist/utils/click/isClickableInput.js +2 -2
- package/dist/utils/edit/calculateNewValue.d.ts +2 -2
- package/dist/utils/edit/calculateNewValue.js +21 -73
- package/dist/utils/edit/cursorPosition.d.ts +2 -0
- package/dist/utils/edit/cursorPosition.js +35 -0
- package/dist/utils/edit/hasUnreliableEmptyValue.d.ts +10 -0
- package/dist/utils/edit/hasUnreliableEmptyValue.js +21 -0
- package/dist/utils/edit/isContentEditable.d.ts +3 -1
- package/dist/utils/edit/isEditable.d.ts +24 -0
- package/dist/utils/edit/isEditable.js +40 -0
- package/dist/utils/edit/maxLength.d.ts +1 -0
- package/dist/utils/edit/maxLength.js +50 -0
- package/dist/utils/edit/selectionRange.d.ts +16 -0
- package/dist/utils/edit/selectionRange.js +99 -0
- package/dist/utils/index.d.ts +6 -3
- package/dist/utils/index.js +51 -12
- package/dist/utils/misc/isElementType.d.ts +5 -0
- package/dist/utils/misc/isElementType.js +24 -0
- package/dist/utils/misc/isLabelWithInternallyDisabledControl.js +2 -2
- package/package.json +1 -1
- package/dist/keyboard/plugins/control/calculateNewDeleteValue.d.ts +0 -4
- package/dist/keyboard/plugins/control/calculateNewDeleteValue.js +0 -46
- package/dist/keyboard/plugins/functional/calculateBackspaceValue.d.ts +0 -4
- package/dist/keyboard/plugins/functional/calculateBackspaceValue.js +0 -57
- package/dist/keyboard/shared/fireInputEventIfNeeded.js +0 -58
- package/dist/keyboard/shared/setSelectionRange.d.ts +0 -5
- package/dist/keyboard/shared/setSelectionRange.js +0 -32
- package/dist/utils/edit/getSelectionRange.d.ts +0 -4
- package/dist/utils/edit/getSelectionRange.js +0 -32
- package/dist/utils/edit/setSelectionRangeIfNecessary.d.ts +0 -1
- package/dist/utils/edit/setSelectionRangeIfNecessary.js +0 -44
- package/dist/utils/misc/isInstanceOfElement.d.ts +0 -7
- package/dist/utils/misc/isInstanceOfElement.js +0 -38
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export declare function calculateNewValue(newEntry: string, element: HTMLElement, value?: string
|
|
1
|
+
export declare function calculateNewValue(newEntry: string, element: HTMLElement, value?: string, selectionRange?: {
|
|
2
2
|
selectionStart: number | null;
|
|
3
3
|
selectionEnd: number | null;
|
|
4
|
-
}): {
|
|
4
|
+
}, deleteContent?: 'backward' | 'forward'): {
|
|
5
5
|
newValue: string;
|
|
6
6
|
newSelectionStart: number;
|
|
7
7
|
};
|
|
@@ -5,45 +5,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.calculateNewValue = calculateNewValue;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _selectionRange = require("./selectionRange");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _getValue2 = require("./getValue");
|
|
11
11
|
|
|
12
12
|
var _isValidDateValue = require("./isValidDateValue");
|
|
13
13
|
|
|
14
14
|
var _isValidInputTimeValue = require("./isValidInputTimeValue");
|
|
15
15
|
|
|
16
|
-
function calculateNewValue(newEntry, element, value = (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
newValue = `${newEntry}${value}`;
|
|
32
|
-
} else if (selectionStart === (value == null ? void 0 : value.length)) {
|
|
33
|
-
// at the end of the input
|
|
34
|
-
newValue = `${value}${newEntry}`;
|
|
35
|
-
} else {
|
|
36
|
-
// in the middle of the input
|
|
37
|
-
newValue = `${value == null ? void 0 : value.slice(0, selectionStart)}${newEntry}${value == null ? void 0 : value.slice(selectionEnd)}`;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
newSelectionStart = selectionStart + newEntry.length;
|
|
41
|
-
} else {
|
|
42
|
-
// we have something selected
|
|
43
|
-
const firstPart = `${value == null ? void 0 : value.slice(0, selectionStart)}${newEntry}`;
|
|
44
|
-
newValue = `${firstPart}${value == null ? void 0 : value.slice(selectionEnd)}`;
|
|
45
|
-
newSelectionStart = firstPart.length;
|
|
46
|
-
}
|
|
16
|
+
function calculateNewValue(newEntry, element, value = (() => {
|
|
17
|
+
var _getValue;
|
|
18
|
+
|
|
19
|
+
return (_getValue = (0, _getValue2.getValue)(element)) != null ? _getValue :
|
|
20
|
+
/* istanbul ignore next */
|
|
21
|
+
'';
|
|
22
|
+
})(), selectionRange = (0, _selectionRange.getSelectionRange)(element), deleteContent) {
|
|
23
|
+
const selectionStart = selectionRange.selectionStart === null ? value.length : selectionRange.selectionStart;
|
|
24
|
+
const selectionEnd = selectionRange.selectionEnd === null ? value.length : selectionRange.selectionEnd;
|
|
25
|
+
const prologEnd = Math.max(0, selectionStart === selectionEnd && deleteContent === 'backward' ? selectionStart - 1 : selectionStart);
|
|
26
|
+
const prolog = value.substring(0, prologEnd);
|
|
27
|
+
const epilogStart = Math.min(value.length, selectionStart === selectionEnd && deleteContent === 'forward' ? selectionEnd + 1 : selectionEnd);
|
|
28
|
+
const epilog = value.substring(epilogStart, value.length);
|
|
29
|
+
let newValue = `${prolog}${newEntry}${epilog}`;
|
|
30
|
+
const newSelectionStart = prologEnd + newEntry.length;
|
|
47
31
|
|
|
48
32
|
if (element.type === 'date' && !(0, _isValidDateValue.isValidDateValue)(element, newValue)) {
|
|
49
33
|
newValue = value;
|
|
@@ -55,46 +39,10 @@ function calculateNewValue(newEntry, element, value = (0, _getValue.getValue)(el
|
|
|
55
39
|
} else {
|
|
56
40
|
newValue = value;
|
|
57
41
|
}
|
|
58
|
-
} // can't use .maxLength property because of a jsdom bug:
|
|
59
|
-
// https://github.com/jsdom/jsdom/issues/2927
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const maxLength = getSanitizedMaxLength(element);
|
|
63
|
-
|
|
64
|
-
if (maxLength === undefined) {
|
|
65
|
-
return {
|
|
66
|
-
newValue,
|
|
67
|
-
newSelectionStart
|
|
68
|
-
};
|
|
69
|
-
} else {
|
|
70
|
-
return {
|
|
71
|
-
newValue: newValue.slice(0, maxLength),
|
|
72
|
-
newSelectionStart: newSelectionStart > maxLength ? maxLength : newSelectionStart
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function getSanitizedMaxLength(element) {
|
|
78
|
-
var _element$getAttribute;
|
|
79
|
-
|
|
80
|
-
if (!supportsMaxLength(element)) {
|
|
81
|
-
return undefined;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const attr = (_element$getAttribute = element.getAttribute('maxlength')) != null ? _element$getAttribute : '';
|
|
85
|
-
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : undefined;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function supportsMaxLength(element) {
|
|
89
|
-
if (element.tagName === 'TEXTAREA') return true;
|
|
90
|
-
|
|
91
|
-
if (element.tagName === 'INPUT') {
|
|
92
|
-
const type = element.getAttribute('type'); // Missing value default is "text"
|
|
93
|
-
|
|
94
|
-
if (!type) return true; // https://html.spec.whatwg.org/multipage/input.html#concept-input-apply
|
|
95
|
-
|
|
96
|
-
if (type.match(/email|password|search|telephone|text|url/)) return true;
|
|
97
42
|
}
|
|
98
43
|
|
|
99
|
-
return
|
|
44
|
+
return {
|
|
45
|
+
newValue,
|
|
46
|
+
newSelectionStart
|
|
47
|
+
};
|
|
100
48
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isContentEditable } from './isContentEditable';
|
|
2
|
+
declare type GuardedType<T> = T extends (x: any) => x is (infer R) ? R : never;
|
|
3
|
+
export declare function isEditable(element: Element): element is GuardedType<typeof isContentEditable> | GuardedType<typeof isEditableInput> | HTMLTextAreaElement & {
|
|
4
|
+
readOnly: false;
|
|
5
|
+
};
|
|
6
|
+
declare enum editableInputTypes {
|
|
7
|
+
'text' = "text",
|
|
8
|
+
'date' = "date",
|
|
9
|
+
'datetime-local' = "datetime-local",
|
|
10
|
+
'email' = "email",
|
|
11
|
+
'month' = "month",
|
|
12
|
+
'number' = "number",
|
|
13
|
+
'password' = "password",
|
|
14
|
+
'search' = "search",
|
|
15
|
+
'tel' = "tel",
|
|
16
|
+
'time' = "time",
|
|
17
|
+
'url' = "url",
|
|
18
|
+
'week' = "week"
|
|
19
|
+
}
|
|
20
|
+
export declare function isEditableInput(element: Element): element is HTMLInputElement & {
|
|
21
|
+
readOnly: false;
|
|
22
|
+
type: editableInputTypes;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isEditable = isEditable;
|
|
7
|
+
exports.isEditableInput = isEditableInput;
|
|
8
|
+
|
|
9
|
+
var _isElementType = require("../misc/isElementType");
|
|
10
|
+
|
|
11
|
+
var _isContentEditable = require("./isContentEditable");
|
|
12
|
+
|
|
13
|
+
function isEditable(element) {
|
|
14
|
+
return isEditableInput(element) || (0, _isElementType.isElementType)(element, 'textarea', {
|
|
15
|
+
readOnly: false
|
|
16
|
+
}) || (0, _isContentEditable.isContentEditable)(element);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
var editableInputTypes;
|
|
20
|
+
|
|
21
|
+
(function (editableInputTypes) {
|
|
22
|
+
editableInputTypes["text"] = "text";
|
|
23
|
+
editableInputTypes["date"] = "date";
|
|
24
|
+
editableInputTypes["datetime-local"] = "datetime-local";
|
|
25
|
+
editableInputTypes["email"] = "email";
|
|
26
|
+
editableInputTypes["month"] = "month";
|
|
27
|
+
editableInputTypes["number"] = "number";
|
|
28
|
+
editableInputTypes["password"] = "password";
|
|
29
|
+
editableInputTypes["search"] = "search";
|
|
30
|
+
editableInputTypes["tel"] = "tel";
|
|
31
|
+
editableInputTypes["time"] = "time";
|
|
32
|
+
editableInputTypes["url"] = "url";
|
|
33
|
+
editableInputTypes["week"] = "week";
|
|
34
|
+
})(editableInputTypes || (editableInputTypes = {}));
|
|
35
|
+
|
|
36
|
+
function isEditableInput(element) {
|
|
37
|
+
return (0, _isElementType.isElementType)(element, 'input', {
|
|
38
|
+
readOnly: false
|
|
39
|
+
}) && Boolean(editableInputTypes[element.type]);
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getSpaceUntilMaxLength(element: Element): number | undefined;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSpaceUntilMaxLength = getSpaceUntilMaxLength;
|
|
7
|
+
|
|
8
|
+
var _isElementType = require("../misc/isElementType");
|
|
9
|
+
|
|
10
|
+
var _getValue = require("./getValue");
|
|
11
|
+
|
|
12
|
+
var maxLengthSupportedTypes;
|
|
13
|
+
|
|
14
|
+
(function (maxLengthSupportedTypes) {
|
|
15
|
+
maxLengthSupportedTypes["email"] = "email";
|
|
16
|
+
maxLengthSupportedTypes["password"] = "password";
|
|
17
|
+
maxLengthSupportedTypes["search"] = "search";
|
|
18
|
+
maxLengthSupportedTypes["telephone"] = "telephone";
|
|
19
|
+
maxLengthSupportedTypes["text"] = "text";
|
|
20
|
+
maxLengthSupportedTypes["url"] = "url";
|
|
21
|
+
})(maxLengthSupportedTypes || (maxLengthSupportedTypes = {}));
|
|
22
|
+
|
|
23
|
+
function getSpaceUntilMaxLength(element) {
|
|
24
|
+
const value = (0, _getValue.getValue)(element);
|
|
25
|
+
/* istanbul ignore if */
|
|
26
|
+
|
|
27
|
+
if (value === null) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const maxLength = getSanitizedMaxLength(element);
|
|
32
|
+
return maxLength ? maxLength - value.length : undefined;
|
|
33
|
+
} // can't use .maxLength property because of a jsdom bug:
|
|
34
|
+
// https://github.com/jsdom/jsdom/issues/2927
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
function getSanitizedMaxLength(element) {
|
|
38
|
+
var _element$getAttribute;
|
|
39
|
+
|
|
40
|
+
if (!supportsMaxLength(element)) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const attr = (_element$getAttribute = element.getAttribute('maxlength')) != null ? _element$getAttribute : '';
|
|
45
|
+
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function supportsMaxLength(element) {
|
|
49
|
+
return (0, _isElementType.isElementType)(element, 'textarea') || (0, _isElementType.isElementType)(element, 'input') && Boolean(maxLengthSupportedTypes[element.type]);
|
|
50
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.hasSelectionSupport = hasSelectionSupport;
|
|
7
|
+
exports.getSelectionRange = getSelectionRange;
|
|
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
|
+
}
|
|
84
|
+
|
|
85
|
+
const range = element.ownerDocument.createRange();
|
|
86
|
+
range.selectNodeContents(element); // istanbul ignore else
|
|
87
|
+
|
|
88
|
+
if (element.firstChild) {
|
|
89
|
+
range.setStart(element.firstChild, newSelectionStart);
|
|
90
|
+
range.setEnd(element.firstChild, newSelectionEnd);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const selection = element.ownerDocument.getSelection(); // istanbul ignore else
|
|
94
|
+
|
|
95
|
+
if (selection) {
|
|
96
|
+
selection.removeAllRanges();
|
|
97
|
+
selection.addRange(range);
|
|
98
|
+
}
|
|
99
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -2,17 +2,20 @@ export * from './click/getMouseEventOptions';
|
|
|
2
2
|
export * from './click/isClickableInput';
|
|
3
3
|
export * from './edit/buildTimeValue';
|
|
4
4
|
export * from './edit/calculateNewValue';
|
|
5
|
-
export * from './edit/
|
|
5
|
+
export * from './edit/cursorPosition';
|
|
6
6
|
export * from './edit/getValue';
|
|
7
|
+
export * from './edit/hasUnreliableEmptyValue';
|
|
7
8
|
export * from './edit/isContentEditable';
|
|
9
|
+
export * from './edit/isEditable';
|
|
8
10
|
export * from './edit/isValidDateValue';
|
|
9
11
|
export * from './edit/isValidInputTimeValue';
|
|
10
|
-
export * from './edit/
|
|
12
|
+
export * from './edit/maxLength';
|
|
13
|
+
export * from './edit/selectionRange';
|
|
11
14
|
export * from './focus/getActiveElement';
|
|
12
15
|
export * from './focus/isFocusable';
|
|
13
16
|
export * from './focus/selector';
|
|
14
17
|
export * from './misc/eventWrapper';
|
|
15
|
-
export * from './misc/
|
|
18
|
+
export * from './misc/isElementType';
|
|
16
19
|
export * from './misc/isLabelWithInternallyDisabledControl';
|
|
17
20
|
export * from './misc/isVisible';
|
|
18
21
|
export * from './misc/isDisabled';
|
package/dist/utils/index.js
CHANGED
|
@@ -56,15 +56,15 @@ Object.keys(_calculateNewValue).forEach(function (key) {
|
|
|
56
56
|
});
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
-
var
|
|
59
|
+
var _cursorPosition = require("./edit/cursorPosition");
|
|
60
60
|
|
|
61
|
-
Object.keys(
|
|
61
|
+
Object.keys(_cursorPosition).forEach(function (key) {
|
|
62
62
|
if (key === "default" || key === "__esModule") return;
|
|
63
|
-
if (key in exports && exports[key] ===
|
|
63
|
+
if (key in exports && exports[key] === _cursorPosition[key]) return;
|
|
64
64
|
Object.defineProperty(exports, key, {
|
|
65
65
|
enumerable: true,
|
|
66
66
|
get: function () {
|
|
67
|
-
return
|
|
67
|
+
return _cursorPosition[key];
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
70
|
});
|
|
@@ -82,6 +82,19 @@ Object.keys(_getValue).forEach(function (key) {
|
|
|
82
82
|
});
|
|
83
83
|
});
|
|
84
84
|
|
|
85
|
+
var _hasUnreliableEmptyValue = require("./edit/hasUnreliableEmptyValue");
|
|
86
|
+
|
|
87
|
+
Object.keys(_hasUnreliableEmptyValue).forEach(function (key) {
|
|
88
|
+
if (key === "default" || key === "__esModule") return;
|
|
89
|
+
if (key in exports && exports[key] === _hasUnreliableEmptyValue[key]) return;
|
|
90
|
+
Object.defineProperty(exports, key, {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
get: function () {
|
|
93
|
+
return _hasUnreliableEmptyValue[key];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
85
98
|
var _isContentEditable = require("./edit/isContentEditable");
|
|
86
99
|
|
|
87
100
|
Object.keys(_isContentEditable).forEach(function (key) {
|
|
@@ -95,6 +108,19 @@ Object.keys(_isContentEditable).forEach(function (key) {
|
|
|
95
108
|
});
|
|
96
109
|
});
|
|
97
110
|
|
|
111
|
+
var _isEditable = require("./edit/isEditable");
|
|
112
|
+
|
|
113
|
+
Object.keys(_isEditable).forEach(function (key) {
|
|
114
|
+
if (key === "default" || key === "__esModule") return;
|
|
115
|
+
if (key in exports && exports[key] === _isEditable[key]) return;
|
|
116
|
+
Object.defineProperty(exports, key, {
|
|
117
|
+
enumerable: true,
|
|
118
|
+
get: function () {
|
|
119
|
+
return _isEditable[key];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
98
124
|
var _isValidDateValue = require("./edit/isValidDateValue");
|
|
99
125
|
|
|
100
126
|
Object.keys(_isValidDateValue).forEach(function (key) {
|
|
@@ -121,15 +147,28 @@ Object.keys(_isValidInputTimeValue).forEach(function (key) {
|
|
|
121
147
|
});
|
|
122
148
|
});
|
|
123
149
|
|
|
124
|
-
var
|
|
150
|
+
var _maxLength = require("./edit/maxLength");
|
|
151
|
+
|
|
152
|
+
Object.keys(_maxLength).forEach(function (key) {
|
|
153
|
+
if (key === "default" || key === "__esModule") return;
|
|
154
|
+
if (key in exports && exports[key] === _maxLength[key]) return;
|
|
155
|
+
Object.defineProperty(exports, key, {
|
|
156
|
+
enumerable: true,
|
|
157
|
+
get: function () {
|
|
158
|
+
return _maxLength[key];
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
var _selectionRange = require("./edit/selectionRange");
|
|
125
164
|
|
|
126
|
-
Object.keys(
|
|
165
|
+
Object.keys(_selectionRange).forEach(function (key) {
|
|
127
166
|
if (key === "default" || key === "__esModule") return;
|
|
128
|
-
if (key in exports && exports[key] ===
|
|
167
|
+
if (key in exports && exports[key] === _selectionRange[key]) return;
|
|
129
168
|
Object.defineProperty(exports, key, {
|
|
130
169
|
enumerable: true,
|
|
131
170
|
get: function () {
|
|
132
|
-
return
|
|
171
|
+
return _selectionRange[key];
|
|
133
172
|
}
|
|
134
173
|
});
|
|
135
174
|
});
|
|
@@ -186,15 +225,15 @@ Object.keys(_eventWrapper).forEach(function (key) {
|
|
|
186
225
|
});
|
|
187
226
|
});
|
|
188
227
|
|
|
189
|
-
var
|
|
228
|
+
var _isElementType = require("./misc/isElementType");
|
|
190
229
|
|
|
191
|
-
Object.keys(
|
|
230
|
+
Object.keys(_isElementType).forEach(function (key) {
|
|
192
231
|
if (key === "default" || key === "__esModule") return;
|
|
193
|
-
if (key in exports && exports[key] ===
|
|
232
|
+
if (key in exports && exports[key] === _isElementType[key]) return;
|
|
194
233
|
Object.defineProperty(exports, key, {
|
|
195
234
|
enumerable: true,
|
|
196
235
|
get: function () {
|
|
197
|
-
return
|
|
236
|
+
return _isElementType[key];
|
|
198
237
|
}
|
|
199
238
|
});
|
|
200
239
|
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare type tag = keyof HTMLElementTagNameMap;
|
|
2
|
+
export declare function isElementType<T extends tag, P extends {
|
|
3
|
+
[k: string]: unknown;
|
|
4
|
+
} | undefined = undefined>(element: Element, tag: T | T[], props?: P): element is P extends undefined ? HTMLElementTagNameMap[T] : HTMLElementTagNameMap[T] & P;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isElementType = isElementType;
|
|
7
|
+
|
|
8
|
+
function isElementType(element, tag, props) {
|
|
9
|
+
if (element.namespaceURI && element.namespaceURI !== 'http://www.w3.org/1999/xhtml') {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
tag = Array.isArray(tag) ? tag : [tag]; // tagName is uppercase in HTMLDocument and lowercase in XMLDocument
|
|
14
|
+
|
|
15
|
+
if (!tag.includes(element.tagName.toLowerCase())) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (props) {
|
|
20
|
+
return Object.entries(props).every(([k, v]) => element[k] === v);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
@@ -7,13 +7,13 @@ exports.isLabelWithInternallyDisabledControl = isLabelWithInternallyDisabledCont
|
|
|
7
7
|
|
|
8
8
|
var _isDisabled = require("./isDisabled");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _isElementType = require("./isElementType");
|
|
11
11
|
|
|
12
12
|
// Absolutely NO events fire on label elements that contain their control
|
|
13
13
|
// if that control is disabled. NUTS!
|
|
14
14
|
// no joke. There are NO events for: <label><input disabled /><label>
|
|
15
15
|
function isLabelWithInternallyDisabledControl(element) {
|
|
16
|
-
if (!(0,
|
|
16
|
+
if (!(0, _isElementType.isElementType)(element, 'label')) {
|
|
17
17
|
return false;
|
|
18
18
|
}
|
|
19
19
|
|
package/package.json
CHANGED