@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
|
@@ -3,9 +3,23 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.getContentEditable = getContentEditable;
|
|
6
7
|
exports.isContentEditable = isContentEditable;
|
|
7
8
|
|
|
8
9
|
//jsdom is not supporting isContentEditable
|
|
9
10
|
function isContentEditable(element) {
|
|
10
11
|
return element.hasAttribute('contenteditable') && (element.getAttribute('contenteditable') == 'true' || element.getAttribute('contenteditable') == '');
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* If a node is a contenteditable or inside one, return that element.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
function getContentEditable(node) {
|
|
19
|
+
const element = getElement(node);
|
|
20
|
+
return element && (element.closest('[contenteditable=""]') || element.closest('[contenteditable="true"]'));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getElement(node) {
|
|
24
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
11
25
|
}
|
|
@@ -17,6 +17,7 @@ export declare enum editableInputTypes {
|
|
|
17
17
|
'url' = "url",
|
|
18
18
|
'week' = "week"
|
|
19
19
|
}
|
|
20
|
+
export declare type EditableInputType = keyof typeof editableInputTypes;
|
|
20
21
|
export declare function isEditableInput(element: Element): element is HTMLInputElement & {
|
|
21
22
|
readOnly: false;
|
|
22
23
|
type: editableInputTypes;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.prepareInput = prepareInput;
|
|
7
|
+
|
|
8
|
+
var _dom = require("@testing-library/dom");
|
|
9
|
+
|
|
10
|
+
var _utils = require("../../utils");
|
|
11
|
+
|
|
12
|
+
function prepareInput(data, element, inputType = 'insertText') {
|
|
13
|
+
const inputRange = (0, _utils.getInputRange)(element);
|
|
14
|
+
/* istanbul ignore if */
|
|
15
|
+
|
|
16
|
+
if (!inputRange) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if ('startContainer' in inputRange) {
|
|
21
|
+
return {
|
|
22
|
+
commit: () => {
|
|
23
|
+
const del = !inputRange.collapsed;
|
|
24
|
+
|
|
25
|
+
if (del) {
|
|
26
|
+
inputRange.deleteContents();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (data) {
|
|
30
|
+
if (inputRange.endContainer.nodeType === 3) {
|
|
31
|
+
const offset = inputRange.endOffset;
|
|
32
|
+
inputRange.endContainer.insertData(offset, data);
|
|
33
|
+
inputRange.setStart(inputRange.endContainer, offset + data.length);
|
|
34
|
+
inputRange.setEnd(inputRange.endContainer, offset + data.length);
|
|
35
|
+
} else {
|
|
36
|
+
const text = element.ownerDocument.createTextNode(data);
|
|
37
|
+
inputRange.insertNode(text);
|
|
38
|
+
inputRange.setStart(text, data.length);
|
|
39
|
+
inputRange.setEnd(text, data.length);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (del || data) {
|
|
44
|
+
_dom.fireEvent.input(element, {
|
|
45
|
+
inputType
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
} else {
|
|
51
|
+
return {
|
|
52
|
+
getNewValue: () => (0, _utils.calculateNewValue)(data, element, inputRange, inputType).newValue,
|
|
53
|
+
commit: () => {
|
|
54
|
+
const {
|
|
55
|
+
newValue,
|
|
56
|
+
newOffset,
|
|
57
|
+
oldValue
|
|
58
|
+
} = (0, _utils.calculateNewValue)(data, element, inputRange, inputType);
|
|
59
|
+
|
|
60
|
+
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
(0, _utils.editInputElement)(element, {
|
|
65
|
+
newValue,
|
|
66
|
+
newSelection: {
|
|
67
|
+
node: element,
|
|
68
|
+
offset: newOffset
|
|
69
|
+
},
|
|
70
|
+
eventOverrides: {
|
|
71
|
+
inputType
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.blur = blur;
|
|
7
|
+
|
|
8
|
+
var _eventWrapper = require("../misc/eventWrapper");
|
|
9
|
+
|
|
10
|
+
var _getActiveElement = require("./getActiveElement");
|
|
11
|
+
|
|
12
|
+
var _isFocusable = require("./isFocusable");
|
|
13
|
+
|
|
14
|
+
function blur(element) {
|
|
15
|
+
if (!(0, _isFocusable.isFocusable)(element)) return;
|
|
16
|
+
const wasActive = (0, _getActiveElement.getActiveElement)(element.ownerDocument) === element;
|
|
17
|
+
if (!wasActive) return;
|
|
18
|
+
(0, _eventWrapper.eventWrapper)(() => element.blur());
|
|
19
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.focus = focus;
|
|
7
|
+
|
|
8
|
+
var _eventWrapper = require("../misc/eventWrapper");
|
|
9
|
+
|
|
10
|
+
var _getActiveElement = require("./getActiveElement");
|
|
11
|
+
|
|
12
|
+
var _isFocusable = require("./isFocusable");
|
|
13
|
+
|
|
14
|
+
var _selection = require("./selection");
|
|
15
|
+
|
|
16
|
+
function focus(element) {
|
|
17
|
+
if (!(0, _isFocusable.isFocusable)(element)) return;
|
|
18
|
+
const isAlreadyActive = (0, _getActiveElement.getActiveElement)(element.ownerDocument) === element;
|
|
19
|
+
if (isAlreadyActive) return;
|
|
20
|
+
(0, _eventWrapper.eventWrapper)(() => element.focus());
|
|
21
|
+
(0, _selection.updateSelectionOnFocus)(element);
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getTabDestination(activeElement: Element, shift: boolean): HTMLElement;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getTabDestination = getTabDestination;
|
|
7
|
+
|
|
8
|
+
var _isDisabled = require("../misc/isDisabled");
|
|
9
|
+
|
|
10
|
+
var _isElementType = require("../misc/isElementType");
|
|
11
|
+
|
|
12
|
+
var _isVisible = require("../misc/isVisible");
|
|
13
|
+
|
|
14
|
+
var _selector = require("./selector");
|
|
15
|
+
|
|
16
|
+
function getTabDestination(activeElement, shift) {
|
|
17
|
+
const document = activeElement.ownerDocument;
|
|
18
|
+
const focusableElements = document.querySelectorAll(_selector.FOCUSABLE_SELECTOR);
|
|
19
|
+
const enabledElements = Array.from(focusableElements).filter(el => el === activeElement || el.getAttribute('tabindex') !== '-1' && !(0, _isDisabled.isDisabled)(el) && // Hidden elements are not tabable
|
|
20
|
+
(0, _isVisible.isVisible)(el));
|
|
21
|
+
|
|
22
|
+
if (activeElement.getAttribute('tabindex') !== '-1') {
|
|
23
|
+
// tabindex has no effect if the active element has tabindex="-1"
|
|
24
|
+
enabledElements.sort((a, b) => Number(a.getAttribute('tabindex')) - Number(b.getAttribute('tabindex')));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const checkedRadio = {};
|
|
28
|
+
let prunedElements = [document.body];
|
|
29
|
+
const activeRadioGroup = (0, _isElementType.isElementType)(activeElement, 'input', {
|
|
30
|
+
type: 'radio'
|
|
31
|
+
}) ? activeElement.name : undefined;
|
|
32
|
+
enabledElements.forEach(currentElement => {
|
|
33
|
+
const el = currentElement; // For radio groups keep only the active radio
|
|
34
|
+
// If there is no active radio, keep only the checked radio
|
|
35
|
+
// If there is no checked radio, treat like everything else
|
|
36
|
+
|
|
37
|
+
if ((0, _isElementType.isElementType)(el, 'input', {
|
|
38
|
+
type: 'radio'
|
|
39
|
+
}) && el.name) {
|
|
40
|
+
// If the active element is part of the group, add only that
|
|
41
|
+
if (el === activeElement) {
|
|
42
|
+
prunedElements.push(el);
|
|
43
|
+
return;
|
|
44
|
+
} else if (el.name === activeRadioGroup) {
|
|
45
|
+
return;
|
|
46
|
+
} // If we stumble upon a checked radio, remove the others
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
if (el.checked) {
|
|
50
|
+
prunedElements = prunedElements.filter(e => !(0, _isElementType.isElementType)(e, 'input', {
|
|
51
|
+
type: 'radio',
|
|
52
|
+
name: el.name
|
|
53
|
+
}));
|
|
54
|
+
prunedElements.push(el);
|
|
55
|
+
checkedRadio[el.name] = el;
|
|
56
|
+
return;
|
|
57
|
+
} // If we already found the checked one, skip
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
if (typeof checkedRadio[el.name] !== 'undefined') {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
prunedElements.push(el);
|
|
66
|
+
});
|
|
67
|
+
const currentIndex = prunedElements.findIndex(el => el === activeElement);
|
|
68
|
+
const nextIndex = shift ? currentIndex - 1 : currentIndex + 1;
|
|
69
|
+
const defaultIndex = shift ? prunedElements.length - 1 : 0;
|
|
70
|
+
return prunedElements[nextIndex] || prunedElements[defaultIndex];
|
|
71
|
+
}
|
|
@@ -5,10 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.isFocusable = isFocusable;
|
|
7
7
|
|
|
8
|
-
var _isLabelWithInternallyDisabledControl = require("../misc/isLabelWithInternallyDisabledControl");
|
|
9
|
-
|
|
10
8
|
var _selector = require("./selector");
|
|
11
9
|
|
|
12
10
|
function isFocusable(element) {
|
|
13
|
-
return
|
|
11
|
+
return element.matches(_selector.FOCUSABLE_SELECTOR);
|
|
14
12
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isAllSelected = isAllSelected;
|
|
7
|
+
exports.selectAll = selectAll;
|
|
8
|
+
|
|
9
|
+
var _document = require("../../document");
|
|
10
|
+
|
|
11
|
+
var _isContentEditable = require("../edit/isContentEditable");
|
|
12
|
+
|
|
13
|
+
var _isEditable = require("../edit/isEditable");
|
|
14
|
+
|
|
15
|
+
var _isElementType = require("../misc/isElementType");
|
|
16
|
+
|
|
17
|
+
var _selection = require("./selection");
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Expand a selection like the browser does when pressing Ctrl+A.
|
|
21
|
+
*/
|
|
22
|
+
function selectAll(target) {
|
|
23
|
+
var _getContentEditable;
|
|
24
|
+
|
|
25
|
+
if ((0, _isElementType.isElementType)(target, 'textarea') || (0, _isElementType.isElementType)(target, 'input') && target.type in _isEditable.editableInputTypes) {
|
|
26
|
+
return (0, _selection.setSelection)({
|
|
27
|
+
focusNode: target,
|
|
28
|
+
anchorOffset: 0,
|
|
29
|
+
focusOffset: (0, _document.getUIValue)(target).length
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const focusNode = (_getContentEditable = (0, _isContentEditable.getContentEditable)(target)) != null ? _getContentEditable : target.ownerDocument.body;
|
|
34
|
+
(0, _selection.setSelection)({
|
|
35
|
+
focusNode,
|
|
36
|
+
anchorOffset: 0,
|
|
37
|
+
focusOffset: focusNode.childNodes.length
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function isAllSelected(target) {
|
|
42
|
+
var _getContentEditable2;
|
|
43
|
+
|
|
44
|
+
if ((0, _isElementType.isElementType)(target, 'textarea') || (0, _isElementType.isElementType)(target, 'input') && target.type in _isEditable.editableInputTypes) {
|
|
45
|
+
return (0, _document.getUISelection)(target).startOffset === 0 && (0, _document.getUISelection)(target).endOffset === (0, _document.getUIValue)(target).length;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const focusNode = (_getContentEditable2 = (0, _isContentEditable.getContentEditable)(target)) != null ? _getContentEditable2 : target.ownerDocument.body;
|
|
49
|
+
const selection = target.ownerDocument.getSelection();
|
|
50
|
+
return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
51
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { UISelectionRange } from '../../document';
|
|
2
|
+
import { editableInputTypes } from '../edit/isEditable';
|
|
3
|
+
/**
|
|
4
|
+
* Backward-compatible selection.
|
|
5
|
+
*
|
|
6
|
+
* Handles input elements and contenteditable if it only contains a single text node.
|
|
7
|
+
*/
|
|
8
|
+
export declare function setSelectionRange(element: Element, anchorOffset: number, focusOffset: number): void;
|
|
9
|
+
/**
|
|
10
|
+
* Determine if the element has its own selection implementation
|
|
11
|
+
* and does not interact with the Document Selection API.
|
|
12
|
+
*/
|
|
13
|
+
export declare function hasOwnSelection(node: Node): node is HTMLTextAreaElement | (HTMLInputElement & {
|
|
14
|
+
type: editableInputTypes;
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* Reset the Document Selection when moving focus into an element
|
|
18
|
+
* with own selection implementation.
|
|
19
|
+
*/
|
|
20
|
+
export declare function updateSelectionOnFocus(element: Element): void;
|
|
21
|
+
/**
|
|
22
|
+
* Get the range that would be overwritten by input.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getInputRange(focusNode: Node): UISelectionRange | Range | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Extend/shrink the selection like with Shift+Arrows or Shift+Mouse
|
|
27
|
+
*/
|
|
28
|
+
export declare function modifySelection({ focusNode, focusOffset, }: {
|
|
29
|
+
focusNode: Node;
|
|
30
|
+
/** DOM Offset */
|
|
31
|
+
focusOffset: number;
|
|
32
|
+
}): void;
|
|
33
|
+
/**
|
|
34
|
+
* Set the selection
|
|
35
|
+
*/
|
|
36
|
+
export declare function setSelection({ focusNode, focusOffset, anchorNode, anchorOffset, }: {
|
|
37
|
+
anchorNode?: Node;
|
|
38
|
+
/** DOM offset */
|
|
39
|
+
anchorOffset?: number;
|
|
40
|
+
focusNode: Node;
|
|
41
|
+
focusOffset: number;
|
|
42
|
+
}): void;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getInputRange = getInputRange;
|
|
7
|
+
exports.hasOwnSelection = hasOwnSelection;
|
|
8
|
+
exports.modifySelection = modifySelection;
|
|
9
|
+
exports.setSelection = setSelection;
|
|
10
|
+
exports.setSelectionRange = setSelectionRange;
|
|
11
|
+
exports.updateSelectionOnFocus = updateSelectionOnFocus;
|
|
12
|
+
|
|
13
|
+
var _isElementType = require("../misc/isElementType");
|
|
14
|
+
|
|
15
|
+
var _document = require("../../document");
|
|
16
|
+
|
|
17
|
+
var _isEditable = require("../edit/isEditable");
|
|
18
|
+
|
|
19
|
+
var _isContentEditable = require("../edit/isContentEditable");
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Backward-compatible selection.
|
|
23
|
+
*
|
|
24
|
+
* Handles input elements and contenteditable if it only contains a single text node.
|
|
25
|
+
*/
|
|
26
|
+
function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
27
|
+
var _element$firstChild;
|
|
28
|
+
|
|
29
|
+
if (hasOwnSelection(element)) {
|
|
30
|
+
return setSelection({
|
|
31
|
+
focusNode: element,
|
|
32
|
+
anchorOffset,
|
|
33
|
+
focusOffset
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/* istanbul ignore else */
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
if ((0, _isContentEditable.isContentEditable)(element) && ((_element$firstChild = element.firstChild) == null ? void 0 : _element$firstChild.nodeType) === 3) {
|
|
40
|
+
return setSelection({
|
|
41
|
+
focusNode: element.firstChild,
|
|
42
|
+
anchorOffset,
|
|
43
|
+
focusOffset
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/* istanbul ignore next */
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
throw new Error('Not implemented. The result of this interaction is unreliable.');
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Determine if the element has its own selection implementation
|
|
53
|
+
* and does not interact with the Document Selection API.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
function hasOwnSelection(node) {
|
|
58
|
+
return isElement(node) && ((0, _isElementType.isElementType)(node, 'textarea') || (0, _isElementType.isElementType)(node, 'input') && node.type in _isEditable.editableInputTypes);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function isElement(node) {
|
|
62
|
+
return node.nodeType === 1;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Determine which selection logic and selection ranges to consider.
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
function getTargetTypeAndSelection(node) {
|
|
70
|
+
const element = getElement(node);
|
|
71
|
+
|
|
72
|
+
if (element && hasOwnSelection(element)) {
|
|
73
|
+
return {
|
|
74
|
+
type: 'input',
|
|
75
|
+
selection: (0, _document.getUISelection)(element)
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const selection = element == null ? void 0 : element.ownerDocument.getSelection(); // It is possible to extend a single-range selection into a contenteditable.
|
|
80
|
+
// This results in the range acting like a range outside of contenteditable.
|
|
81
|
+
|
|
82
|
+
const isCE = (0, _isContentEditable.getContentEditable)(node) && (selection == null ? void 0 : selection.anchorNode) && (0, _isContentEditable.getContentEditable)(selection.anchorNode);
|
|
83
|
+
return {
|
|
84
|
+
type: isCE ? 'contenteditable' : 'default',
|
|
85
|
+
selection
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function getElement(node) {
|
|
90
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Reset the Document Selection when moving focus into an element
|
|
94
|
+
* with own selection implementation.
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
function updateSelectionOnFocus(element) {
|
|
99
|
+
const selection = element.ownerDocument.getSelection();
|
|
100
|
+
/* istanbul ignore if */
|
|
101
|
+
|
|
102
|
+
if (!(selection != null && selection.focusNode)) {
|
|
103
|
+
return;
|
|
104
|
+
} // If the focus moves inside an element with own selection implementation,
|
|
105
|
+
// the document selection will be this element.
|
|
106
|
+
// But if the focused element is inside a contenteditable,
|
|
107
|
+
// 1) a collapsed selection will be retained.
|
|
108
|
+
// 2) other selections will be replaced by a cursor
|
|
109
|
+
// 2.a) at the start of the first child if it is a text node
|
|
110
|
+
// 2.b) at the start of the contenteditable.
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
if (hasOwnSelection(element)) {
|
|
114
|
+
const contenteditable = (0, _isContentEditable.getContentEditable)(selection.focusNode);
|
|
115
|
+
|
|
116
|
+
if (contenteditable) {
|
|
117
|
+
if (!selection.isCollapsed) {
|
|
118
|
+
var _contenteditable$firs;
|
|
119
|
+
|
|
120
|
+
const focusNode = ((_contenteditable$firs = contenteditable.firstChild) == null ? void 0 : _contenteditable$firs.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
121
|
+
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
selection.setBaseAndExtent(element, 0, element, 0);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get the range that would be overwritten by input.
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
function getInputRange(focusNode) {
|
|
134
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
135
|
+
|
|
136
|
+
if (typeAndSelection.type === 'input') {
|
|
137
|
+
return typeAndSelection.selection;
|
|
138
|
+
} else if (typeAndSelection.type === 'contenteditable') {
|
|
139
|
+
var _typeAndSelection$sel;
|
|
140
|
+
|
|
141
|
+
// Multi-range on contenteditable edits the first selection instead of the last
|
|
142
|
+
return (_typeAndSelection$sel = typeAndSelection.selection) == null ? void 0 : _typeAndSelection$sel.getRangeAt(0);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Extend/shrink the selection like with Shift+Arrows or Shift+Mouse
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
function modifySelection({
|
|
151
|
+
focusNode,
|
|
152
|
+
focusOffset
|
|
153
|
+
}) {
|
|
154
|
+
var _focusNode$ownerDocum, _focusNode$ownerDocum2;
|
|
155
|
+
|
|
156
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
157
|
+
|
|
158
|
+
if (typeAndSelection.type === 'input') {
|
|
159
|
+
return (0, _document.setUISelection)(focusNode, {
|
|
160
|
+
anchorOffset: typeAndSelection.selection.anchorOffset,
|
|
161
|
+
focusOffset
|
|
162
|
+
}, 'modify');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
(_focusNode$ownerDocum = focusNode.ownerDocument) == null ? void 0 : (_focusNode$ownerDocum2 = _focusNode$ownerDocum.getSelection()) == null ? void 0 : _focusNode$ownerDocum2.extend(focusNode, focusOffset);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Set the selection
|
|
169
|
+
*/
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
function setSelection({
|
|
173
|
+
focusNode,
|
|
174
|
+
focusOffset,
|
|
175
|
+
anchorNode = focusNode,
|
|
176
|
+
anchorOffset = focusOffset
|
|
177
|
+
}) {
|
|
178
|
+
var _anchorNode$ownerDocu, _anchorNode$ownerDocu2;
|
|
179
|
+
|
|
180
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
181
|
+
|
|
182
|
+
if (typeAndSelection.type === 'input') {
|
|
183
|
+
return (0, _document.setUISelection)(focusNode, {
|
|
184
|
+
anchorOffset,
|
|
185
|
+
focusOffset
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
(_anchorNode$ownerDocu = anchorNode.ownerDocument) == null ? void 0 : (_anchorNode$ownerDocu2 = _anchorNode$ownerDocu.getSelection()) == null ? void 0 : _anchorNode$ownerDocu2.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
190
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,24 +1,31 @@
|
|
|
1
|
-
export * from './click/getMouseEventOptions';
|
|
2
1
|
export * from './click/isClickableInput';
|
|
3
2
|
export * from './edit/buildTimeValue';
|
|
4
3
|
export * from './edit/calculateNewValue';
|
|
5
|
-
export * from './edit/
|
|
4
|
+
export * from './edit/editInputElement';
|
|
6
5
|
export * from './edit/getValue';
|
|
7
|
-
export * from './edit/hasUnreliableEmptyValue';
|
|
8
6
|
export * from './edit/isContentEditable';
|
|
9
7
|
export * from './edit/isEditable';
|
|
10
8
|
export * from './edit/isValidDateValue';
|
|
11
9
|
export * from './edit/isValidInputTimeValue';
|
|
12
10
|
export * from './edit/maxLength';
|
|
13
|
-
export * from './edit/
|
|
11
|
+
export * from './edit/prepareInput';
|
|
12
|
+
export * from './focus/blur';
|
|
13
|
+
export * from './focus/focus';
|
|
14
14
|
export * from './focus/getActiveElement';
|
|
15
|
+
export * from './focus/getTabDestination';
|
|
15
16
|
export * from './focus/isFocusable';
|
|
17
|
+
export * from './focus/selectAll';
|
|
18
|
+
export * from './focus/selection';
|
|
16
19
|
export * from './focus/selector';
|
|
20
|
+
export * from './keyDef/readNextDescriptor';
|
|
17
21
|
export * from './misc/eventWrapper';
|
|
22
|
+
export * from './misc/findClosest';
|
|
23
|
+
export * from './misc/isDescendantOrSelf';
|
|
18
24
|
export * from './misc/isElementType';
|
|
19
|
-
export * from './misc/isLabelWithInternallyDisabledControl';
|
|
20
25
|
export * from './misc/isVisible';
|
|
21
26
|
export * from './misc/isDisabled';
|
|
22
|
-
export * from './misc/isDocument';
|
|
23
27
|
export * from './misc/wait';
|
|
24
28
|
export * from './misc/hasPointerEvents';
|
|
29
|
+
export * from './misc/hasFormSubmit';
|
|
30
|
+
export * from './pointer/firePointerEvents';
|
|
31
|
+
export * from './pointer/mouseButtons';
|