@testing-library/user-event 14.0.0-alpha.3 → 14.0.0-alpha.7
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/click.d.ts +1 -0
- package/dist/click.js +17 -0
- package/dist/document/index.d.ts +3 -3
- package/dist/document/index.js +8 -10
- package/dist/document/interceptor.d.ts +11 -1
- package/dist/document/interceptor.js +7 -4
- package/dist/document/selection.d.ts +17 -8
- package/dist/document/selection.js +51 -28
- package/dist/document/value.d.ts +5 -1
- package/dist/document/value.js +27 -6
- package/dist/keyboard/keyMap.js +4 -0
- package/dist/keyboard/keyboardImplementation.js +3 -1
- package/dist/keyboard/plugins/arrow.js +7 -12
- package/dist/keyboard/plugins/character.js +23 -42
- package/dist/keyboard/plugins/control.js +4 -12
- package/dist/keyboard/plugins/functional.js +23 -11
- package/dist/paste.js +8 -15
- package/dist/pointer/pointerMove.js +28 -17
- package/dist/pointer/pointerPress.js +6 -4
- package/dist/pointer/resolveSelectionTarget.js +7 -6
- package/dist/setup.d.ts +5 -2
- package/dist/setup.js +4 -7
- package/dist/tab.d.ts +1 -2
- package/dist/tab.js +3 -132
- package/dist/utils/edit/calculateNewValue.d.ts +14 -5
- package/dist/utils/edit/calculateNewValue.js +23 -21
- package/dist/utils/edit/fireInputEvent.d.ts +5 -2
- package/dist/utils/edit/fireInputEvent.js +35 -25
- 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 +4 -0
- package/dist/utils/edit/prepareInput.js +60 -0
- package/dist/utils/focus/focus.js +3 -0
- package/dist/utils/focus/getTabDestination.d.ts +1 -0
- package/dist/utils/focus/getTabDestination.js +71 -0
- package/dist/utils/focus/selection.d.ts +42 -0
- package/dist/utils/focus/selection.js +190 -0
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/index.js +30 -30
- package/package.json +1 -1
- package/dist/document/applyNative.d.ts +0 -8
- package/dist/document/applyNative.js +0 -28
- package/dist/utils/edit/cursorPosition.d.ts +0 -2
- package/dist/utils/edit/cursorPosition.js +0 -35
- package/dist/utils/edit/selectionRange.d.ts +0 -5
- package/dist/utils/edit/selectionRange.js +0 -64
- package/dist/utils/misc/isDocument.d.ts +0 -1
- package/dist/utils/misc/isDocument.js +0 -10
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.prepareInput = prepareInput;
|
|
7
|
+
|
|
8
|
+
var _utils = require("../../utils");
|
|
9
|
+
|
|
10
|
+
function prepareInput(data, element, inputType = 'insertText') {
|
|
11
|
+
const inputRange = (0, _utils.getInputRange)(element); // TODO: implement for ranges on multiple nodes
|
|
12
|
+
|
|
13
|
+
/* istanbul ignore if */
|
|
14
|
+
|
|
15
|
+
if (!inputRange || 'startContainer' in inputRange && inputRange.startContainer !== inputRange.endContainer) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const node = getNode(element, inputRange);
|
|
20
|
+
const {
|
|
21
|
+
newValue,
|
|
22
|
+
newOffset,
|
|
23
|
+
oldValue
|
|
24
|
+
} = (0, _utils.calculateNewValue)(data, node, inputRange, inputType);
|
|
25
|
+
|
|
26
|
+
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
newValue,
|
|
32
|
+
commit: () => (0, _utils.fireInputEvent)(element, {
|
|
33
|
+
newValue,
|
|
34
|
+
newSelection: {
|
|
35
|
+
node,
|
|
36
|
+
offset: newOffset
|
|
37
|
+
},
|
|
38
|
+
eventOverrides: {
|
|
39
|
+
inputType
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getNode(element, inputRange) {
|
|
46
|
+
if ('startContainer' in inputRange) {
|
|
47
|
+
if (inputRange.startContainer.nodeType === 3) {
|
|
48
|
+
return inputRange.startContainer;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
return inputRange.startContainer.insertBefore(element.ownerDocument.createTextNode(''), inputRange.startContainer.childNodes.item(inputRange.startOffset));
|
|
53
|
+
} catch {
|
|
54
|
+
/* istanbul ignore next */
|
|
55
|
+
throw new Error('Invalid operation. Can not insert text at this position. The behavior is not implemented yet.');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return element;
|
|
60
|
+
}
|
|
@@ -11,9 +11,12 @@ var _getActiveElement = require("./getActiveElement");
|
|
|
11
11
|
|
|
12
12
|
var _isFocusable = require("./isFocusable");
|
|
13
13
|
|
|
14
|
+
var _selection = require("./selection");
|
|
15
|
+
|
|
14
16
|
function focus(element) {
|
|
15
17
|
if (!(0, _isFocusable.isFocusable)(element)) return;
|
|
16
18
|
const isAlreadyActive = (0, _getActiveElement.getActiveElement)(element.ownerDocument) === element;
|
|
17
19
|
if (isAlreadyActive) return;
|
|
18
20
|
(0, _eventWrapper.eventWrapper)(() => element.focus());
|
|
21
|
+
(0, _selection.updateSelectionOnFocus)(element);
|
|
19
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
|
+
}
|
|
@@ -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,7 +1,6 @@
|
|
|
1
1
|
export * from './click/isClickableInput';
|
|
2
2
|
export * from './edit/buildTimeValue';
|
|
3
3
|
export * from './edit/calculateNewValue';
|
|
4
|
-
export * from './edit/cursorPosition';
|
|
5
4
|
export * from './edit/fireInputEvent';
|
|
6
5
|
export * from './edit/getValue';
|
|
7
6
|
export * from './edit/isContentEditable';
|
|
@@ -9,11 +8,13 @@ export * from './edit/isEditable';
|
|
|
9
8
|
export * from './edit/isValidDateValue';
|
|
10
9
|
export * from './edit/isValidInputTimeValue';
|
|
11
10
|
export * from './edit/maxLength';
|
|
12
|
-
export * from './edit/
|
|
11
|
+
export * from './edit/prepareInput';
|
|
13
12
|
export * from './focus/blur';
|
|
14
13
|
export * from './focus/focus';
|
|
15
14
|
export * from './focus/getActiveElement';
|
|
15
|
+
export * from './focus/getTabDestination';
|
|
16
16
|
export * from './focus/isFocusable';
|
|
17
|
+
export * from './focus/selection';
|
|
17
18
|
export * from './focus/selector';
|
|
18
19
|
export * from './keyDef/readNextDescriptor';
|
|
19
20
|
export * from './misc/eventWrapper';
|
|
@@ -22,7 +23,6 @@ export * from './misc/isDescendantOrSelf';
|
|
|
22
23
|
export * from './misc/isElementType';
|
|
23
24
|
export * from './misc/isVisible';
|
|
24
25
|
export * from './misc/isDisabled';
|
|
25
|
-
export * from './misc/isDocument';
|
|
26
26
|
export * from './misc/wait';
|
|
27
27
|
export * from './misc/hasPointerEvents';
|
|
28
28
|
export * from './misc/hasFormSubmit';
|
package/dist/utils/index.js
CHANGED
|
@@ -43,19 +43,6 @@ Object.keys(_calculateNewValue).forEach(function (key) {
|
|
|
43
43
|
});
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
var _cursorPosition = require("./edit/cursorPosition");
|
|
47
|
-
|
|
48
|
-
Object.keys(_cursorPosition).forEach(function (key) {
|
|
49
|
-
if (key === "default" || key === "__esModule") return;
|
|
50
|
-
if (key in exports && exports[key] === _cursorPosition[key]) return;
|
|
51
|
-
Object.defineProperty(exports, key, {
|
|
52
|
-
enumerable: true,
|
|
53
|
-
get: function () {
|
|
54
|
-
return _cursorPosition[key];
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
46
|
var _fireInputEvent = require("./edit/fireInputEvent");
|
|
60
47
|
|
|
61
48
|
Object.keys(_fireInputEvent).forEach(function (key) {
|
|
@@ -147,15 +134,15 @@ Object.keys(_maxLength).forEach(function (key) {
|
|
|
147
134
|
});
|
|
148
135
|
});
|
|
149
136
|
|
|
150
|
-
var
|
|
137
|
+
var _prepareInput = require("./edit/prepareInput");
|
|
151
138
|
|
|
152
|
-
Object.keys(
|
|
139
|
+
Object.keys(_prepareInput).forEach(function (key) {
|
|
153
140
|
if (key === "default" || key === "__esModule") return;
|
|
154
|
-
if (key in exports && exports[key] ===
|
|
141
|
+
if (key in exports && exports[key] === _prepareInput[key]) return;
|
|
155
142
|
Object.defineProperty(exports, key, {
|
|
156
143
|
enumerable: true,
|
|
157
144
|
get: function () {
|
|
158
|
-
return
|
|
145
|
+
return _prepareInput[key];
|
|
159
146
|
}
|
|
160
147
|
});
|
|
161
148
|
});
|
|
@@ -199,6 +186,19 @@ Object.keys(_getActiveElement).forEach(function (key) {
|
|
|
199
186
|
});
|
|
200
187
|
});
|
|
201
188
|
|
|
189
|
+
var _getTabDestination = require("./focus/getTabDestination");
|
|
190
|
+
|
|
191
|
+
Object.keys(_getTabDestination).forEach(function (key) {
|
|
192
|
+
if (key === "default" || key === "__esModule") return;
|
|
193
|
+
if (key in exports && exports[key] === _getTabDestination[key]) return;
|
|
194
|
+
Object.defineProperty(exports, key, {
|
|
195
|
+
enumerable: true,
|
|
196
|
+
get: function () {
|
|
197
|
+
return _getTabDestination[key];
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
202
|
var _isFocusable = require("./focus/isFocusable");
|
|
203
203
|
|
|
204
204
|
Object.keys(_isFocusable).forEach(function (key) {
|
|
@@ -212,6 +212,19 @@ Object.keys(_isFocusable).forEach(function (key) {
|
|
|
212
212
|
});
|
|
213
213
|
});
|
|
214
214
|
|
|
215
|
+
var _selection = require("./focus/selection");
|
|
216
|
+
|
|
217
|
+
Object.keys(_selection).forEach(function (key) {
|
|
218
|
+
if (key === "default" || key === "__esModule") return;
|
|
219
|
+
if (key in exports && exports[key] === _selection[key]) return;
|
|
220
|
+
Object.defineProperty(exports, key, {
|
|
221
|
+
enumerable: true,
|
|
222
|
+
get: function () {
|
|
223
|
+
return _selection[key];
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
215
228
|
var _selector = require("./focus/selector");
|
|
216
229
|
|
|
217
230
|
Object.keys(_selector).forEach(function (key) {
|
|
@@ -316,19 +329,6 @@ Object.keys(_isDisabled).forEach(function (key) {
|
|
|
316
329
|
});
|
|
317
330
|
});
|
|
318
331
|
|
|
319
|
-
var _isDocument = require("./misc/isDocument");
|
|
320
|
-
|
|
321
|
-
Object.keys(_isDocument).forEach(function (key) {
|
|
322
|
-
if (key === "default" || key === "__esModule") return;
|
|
323
|
-
if (key in exports && exports[key] === _isDocument[key]) return;
|
|
324
|
-
Object.defineProperty(exports, key, {
|
|
325
|
-
enumerable: true,
|
|
326
|
-
get: function () {
|
|
327
|
-
return _isDocument[key];
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
});
|
|
331
|
-
|
|
332
332
|
var _wait = require("./misc/wait");
|
|
333
333
|
|
|
334
334
|
Object.keys(_wait).forEach(function (key) {
|
package/package.json
CHANGED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* React tracks the changes on element properties.
|
|
3
|
-
* This workaround tries to alter the DOM element without React noticing,
|
|
4
|
-
* so that it later picks up the change.
|
|
5
|
-
*
|
|
6
|
-
* @see https://github.com/facebook/react/blob/148f8e497c7d37a3c7ab99f01dec2692427272b1/packages/react-dom/src/client/inputValueTracking.js#L51-L104
|
|
7
|
-
*/
|
|
8
|
-
export declare function applyNative<T extends Element, P extends keyof T>(element: T, propName: P, propValue: T[P]): void;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.applyNative = applyNative;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* React tracks the changes on element properties.
|
|
10
|
-
* This workaround tries to alter the DOM element without React noticing,
|
|
11
|
-
* so that it later picks up the change.
|
|
12
|
-
*
|
|
13
|
-
* @see https://github.com/facebook/react/blob/148f8e497c7d37a3c7ab99f01dec2692427272b1/packages/react-dom/src/client/inputValueTracking.js#L51-L104
|
|
14
|
-
*/
|
|
15
|
-
function applyNative(element, propName, propValue) {
|
|
16
|
-
const descriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
17
|
-
const nativeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
18
|
-
|
|
19
|
-
if (descriptor && nativeDescriptor) {
|
|
20
|
-
Object.defineProperty(element, propName, nativeDescriptor);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
element[propName] = propValue;
|
|
24
|
-
|
|
25
|
-
if (descriptor) {
|
|
26
|
-
Object.defineProperty(element, propName, descriptor);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -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,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getSelectionRange = getSelectionRange;
|
|
7
|
-
exports.setSelectionRange = setSelectionRange;
|
|
8
|
-
|
|
9
|
-
var _isElementType = require("../misc/isElementType");
|
|
10
|
-
|
|
11
|
-
var _document = require("../../document");
|
|
12
|
-
|
|
13
|
-
function getSelectionRange(element) {
|
|
14
|
-
if ((0, _isElementType.isElementType)(element, ['input', 'textarea'])) {
|
|
15
|
-
return (0, _document.getUISelection)(element);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const selection = element.ownerDocument.getSelection(); // there should be no editing if the focusNode is outside of element
|
|
19
|
-
// TODO: properly handle selection ranges
|
|
20
|
-
|
|
21
|
-
if (selection != null && selection.rangeCount && element.contains(selection.focusNode)) {
|
|
22
|
-
const range = selection.getRangeAt(0);
|
|
23
|
-
return {
|
|
24
|
-
selectionStart: range.startOffset,
|
|
25
|
-
selectionEnd: range.endOffset
|
|
26
|
-
};
|
|
27
|
-
} else {
|
|
28
|
-
return {
|
|
29
|
-
selectionStart: null,
|
|
30
|
-
selectionEnd: null
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function setSelectionRange(element, newSelectionStart, newSelectionEnd) {
|
|
36
|
-
if ((0, _isElementType.isElementType)(element, ['input', 'textarea'])) {
|
|
37
|
-
return (0, _document.setUISelection)(element, newSelectionStart, newSelectionEnd);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const {
|
|
41
|
-
selectionStart,
|
|
42
|
-
selectionEnd
|
|
43
|
-
} = getSelectionRange(element); // Prevent unnecessary select events
|
|
44
|
-
// istanbul ignore next
|
|
45
|
-
|
|
46
|
-
if (selectionStart === newSelectionStart && selectionEnd === newSelectionEnd) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const range = element.ownerDocument.createRange();
|
|
51
|
-
range.selectNodeContents(element); // istanbul ignore else
|
|
52
|
-
|
|
53
|
-
if (element.firstChild) {
|
|
54
|
-
range.setStart(element.firstChild, newSelectionStart);
|
|
55
|
-
range.setEnd(element.firstChild, newSelectionEnd);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const selection = element.ownerDocument.getSelection(); // istanbul ignore else
|
|
59
|
-
|
|
60
|
-
if (selection) {
|
|
61
|
-
selection.removeAllRanges();
|
|
62
|
-
selection.addRange(range);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isDocument(el: Document | Element): el is Document;
|