@testing-library/user-event 14.0.0-alpha.5 → 14.0.0-alpha.9
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 +1 -0
- package/dist/document/selection.d.ts +17 -7
- package/dist/document/selection.js +33 -17
- package/dist/document/value.d.ts +1 -1
- package/dist/document/value.js +1 -1
- package/dist/keyboard/plugins/arrow.js +7 -12
- package/dist/keyboard/plugins/character.js +23 -42
- package/dist/keyboard/plugins/combination.d.ts +5 -0
- package/dist/keyboard/plugins/combination.js +17 -0
- package/dist/keyboard/plugins/control.js +4 -12
- package/dist/keyboard/plugins/functional.js +8 -13
- package/dist/keyboard/plugins/index.js +3 -1
- 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 +4 -1
- package/dist/setup.js +4 -0
- 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 +17 -11
- 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/selectAll.d.ts +4 -0
- package/dist/utils/focus/selectAll.js +38 -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/dist/utils/pointer/firePointerEvents.d.ts +12 -1
- package/dist/utils/pointer/firePointerEvents.js +62 -5
- package/package.json +1 -1
- 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/pointer/fakeEvent.d.ts +0 -20
- package/dist/utils/pointer/fakeEvent.js +0 -91
package/dist/click.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export declare interface clickOptions {
|
|
|
6
6
|
}
|
|
7
7
|
export declare function click(this: UserEvent, element: Element, init?: MouseEventInit, { skipHover, skipPointerEventsCheck, }?: clickOptions & PointerOptions): void;
|
|
8
8
|
export declare function dblClick(this: UserEvent, element: Element, init?: MouseEventInit, { skipPointerEventsCheck }?: clickOptions & PointerOptions): void;
|
|
9
|
+
export declare function tripleClick(this: UserEvent, element: Element, init?: MouseEventInit, { skipPointerEventsCheck }?: clickOptions & PointerOptions): void;
|
package/dist/click.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.click = click;
|
|
7
7
|
exports.dblClick = dblClick;
|
|
8
|
+
exports.tripleClick = tripleClick;
|
|
8
9
|
|
|
9
10
|
var _utils = require("./utils");
|
|
10
11
|
|
|
@@ -42,4 +43,20 @@ function dblClick(element, init, {
|
|
|
42
43
|
keys: '[MouseLeft][MouseLeft]',
|
|
43
44
|
target: element
|
|
44
45
|
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function tripleClick(element, init, {
|
|
49
|
+
skipPointerEventsCheck = false
|
|
50
|
+
} = {}) {
|
|
51
|
+
if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
|
|
52
|
+
throw new Error('unable to triple-click element as it has or inherits pointer-events set to "none".');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this.hover(element, init, {
|
|
56
|
+
skipPointerEventsCheck: true
|
|
57
|
+
});
|
|
58
|
+
this.pointer({
|
|
59
|
+
keys: '[MouseLeft][MouseLeft][MouseLeft]',
|
|
60
|
+
target: element
|
|
61
|
+
});
|
|
45
62
|
}
|
package/dist/document/index.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ declare global {
|
|
|
7
7
|
export declare function prepareDocument(document: Document): void;
|
|
8
8
|
export { getUIValue, setUIValue, startTrackValue, endTrackValue } from './value';
|
|
9
9
|
export { getUISelection, setUISelection } from './selection';
|
|
10
|
+
export type { UISelectionRange } from './selection';
|
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
declare const UISelection: unique symbol;
|
|
2
|
+
export interface UISelectionRange {
|
|
3
|
+
startOffset: number;
|
|
4
|
+
endOffset: number;
|
|
5
|
+
}
|
|
6
|
+
export interface UISelection {
|
|
7
|
+
anchorOffset: number;
|
|
8
|
+
focusOffset: number;
|
|
9
|
+
}
|
|
2
10
|
declare global {
|
|
3
11
|
interface Element {
|
|
4
|
-
[UISelection]?:
|
|
5
|
-
start: number;
|
|
6
|
-
end: number;
|
|
7
|
-
};
|
|
12
|
+
[UISelection]?: UISelection;
|
|
8
13
|
}
|
|
9
14
|
}
|
|
10
15
|
export declare function prepareSelectionInterceptor(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
11
|
-
export declare function setUISelection(element: HTMLInputElement | HTMLTextAreaElement,
|
|
16
|
+
export declare function setUISelection(element: HTMLInputElement | HTMLTextAreaElement, { focusOffset: focusOffsetParam, anchorOffset: anchorOffsetParam, }: {
|
|
17
|
+
anchorOffset?: number;
|
|
18
|
+
focusOffset: number;
|
|
19
|
+
}, mode?: 'replace' | 'modify'): void;
|
|
12
20
|
export declare function getUISelection(element: HTMLInputElement | HTMLTextAreaElement): {
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
startOffset: number;
|
|
22
|
+
endOffset: number;
|
|
23
|
+
anchorOffset: number;
|
|
24
|
+
focusOffset: number;
|
|
15
25
|
};
|
|
16
26
|
export declare function clearUISelection(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
17
27
|
export {};
|
|
@@ -8,6 +8,8 @@ exports.getUISelection = getUISelection;
|
|
|
8
8
|
exports.prepareSelectionInterceptor = prepareSelectionInterceptor;
|
|
9
9
|
exports.setUISelection = setUISelection;
|
|
10
10
|
|
|
11
|
+
var _ = require(".");
|
|
12
|
+
|
|
11
13
|
var _interceptor = require("./interceptor");
|
|
12
14
|
|
|
13
15
|
const UISelection = Symbol('Displayed selection in UI');
|
|
@@ -15,10 +17,11 @@ const UISelection = Symbol('Displayed selection in UI');
|
|
|
15
17
|
function prepareSelectionInterceptor(element) {
|
|
16
18
|
(0, _interceptor.prepareInterceptor)(element, 'setSelectionRange', function interceptorImpl(start, end, direction = 'none') {
|
|
17
19
|
const isUI = start && typeof start === 'object' && start[UISelection];
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
20
|
+
|
|
21
|
+
if (!isUI) {
|
|
22
|
+
this[UISelection] = undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
22
25
|
return {
|
|
23
26
|
realArgs: [Number(start), end, direction]
|
|
24
27
|
};
|
|
@@ -37,35 +40,48 @@ function prepareSelectionInterceptor(element) {
|
|
|
37
40
|
});
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
function setUISelection(element,
|
|
43
|
+
function setUISelection(element, {
|
|
44
|
+
focusOffset: focusOffsetParam,
|
|
45
|
+
anchorOffset: anchorOffsetParam = focusOffsetParam
|
|
46
|
+
}, mode = 'replace') {
|
|
47
|
+
const valueLength = (0, _.getUIValue)(element).length;
|
|
48
|
+
|
|
49
|
+
const sanitizeOffset = o => Math.max(0, Math.min(valueLength, o));
|
|
50
|
+
|
|
51
|
+
const anchorOffset = mode === 'replace' || element[UISelection] === undefined ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
|
|
52
|
+
const focusOffset = sanitizeOffset(focusOffsetParam);
|
|
53
|
+
const startOffset = Math.min(anchorOffset, focusOffset);
|
|
54
|
+
const endOffset = Math.max(anchorOffset, focusOffset);
|
|
41
55
|
element[UISelection] = {
|
|
42
|
-
|
|
43
|
-
|
|
56
|
+
anchorOffset,
|
|
57
|
+
focusOffset
|
|
44
58
|
};
|
|
45
59
|
|
|
46
|
-
if (element.selectionStart ===
|
|
60
|
+
if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
|
|
47
61
|
return;
|
|
48
62
|
} // eslint-disable-next-line no-new-wrappers
|
|
49
63
|
|
|
50
64
|
|
|
51
|
-
const startObj = new Number(
|
|
65
|
+
const startObj = new Number(startOffset);
|
|
52
66
|
startObj[UISelection] = UISelection;
|
|
53
67
|
|
|
54
68
|
try {
|
|
55
|
-
element.setSelectionRange(startObj,
|
|
69
|
+
element.setSelectionRange(startObj, endOffset);
|
|
56
70
|
} catch {// DOMException for invalid state is expected when calling this
|
|
57
71
|
// on an element without support for setSelectionRange
|
|
58
72
|
}
|
|
59
73
|
}
|
|
60
74
|
|
|
61
75
|
function getUISelection(element) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
76
|
+
var _element$UISelection, _element$selectionSta, _element$selectionEnd;
|
|
77
|
+
|
|
78
|
+
const sel = (_element$UISelection = element[UISelection]) != null ? _element$UISelection : {
|
|
79
|
+
anchorOffset: (_element$selectionSta = element.selectionStart) != null ? _element$selectionSta : 0,
|
|
80
|
+
focusOffset: (_element$selectionEnd = element.selectionEnd) != null ? _element$selectionEnd : 0
|
|
81
|
+
};
|
|
82
|
+
return { ...sel,
|
|
83
|
+
startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
|
|
84
|
+
endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
|
|
69
85
|
};
|
|
70
86
|
}
|
|
71
87
|
|
package/dist/document/value.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ declare global {
|
|
|
10
10
|
}
|
|
11
11
|
export declare function prepareValueInterceptor(element: HTMLInputElement): void;
|
|
12
12
|
export declare function setUIValue(element: HTMLInputElement | HTMLTextAreaElement, value: string): void;
|
|
13
|
-
export declare function getUIValue(element: HTMLInputElement | HTMLTextAreaElement): string
|
|
13
|
+
export declare function getUIValue(element: HTMLInputElement | HTMLTextAreaElement): string;
|
|
14
14
|
export declare function setInitialValue(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
15
15
|
export declare function getInitialValue(element: HTMLInputElement | HTMLTextAreaElement): string | undefined;
|
|
16
16
|
export declare function startTrackValue(element: HTMLInputElement | HTMLTextAreaElement): void;
|
package/dist/document/value.js
CHANGED
|
@@ -49,7 +49,7 @@ function setUIValue(element, value) {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
function getUIValue(element) {
|
|
52
|
-
return element[UIValue] === undefined ? element.value : element[UIValue];
|
|
52
|
+
return element[UIValue] === undefined ? element.value : String(element[UIValue]);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
function setInitialValue(element) {
|
|
@@ -7,6 +7,8 @@ exports.keydownBehavior = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _utils = require("../../utils");
|
|
9
9
|
|
|
10
|
+
var _document = require("../../document");
|
|
11
|
+
|
|
10
12
|
/**
|
|
11
13
|
* This file should contain behavior for arrow keys as described here:
|
|
12
14
|
* https://w3c.github.io/uievents-code/#key-arrowpad-section
|
|
@@ -15,19 +17,12 @@ const keydownBehavior = [{
|
|
|
15
17
|
// TODO: implement for contentEditable
|
|
16
18
|
matches: (keyDef, element) => (keyDef.key === 'ArrowLeft' || keyDef.key === 'ArrowRight') && (0, _utils.isElementType)(element, ['input', 'textarea']),
|
|
17
19
|
handle: (keyDef, element) => {
|
|
18
|
-
|
|
20
|
+
const selection = (0, _document.getUISelection)(element); // TODO: implement shift/ctrl
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
const direction = keyDef.key === 'ArrowLeft' ? -1 : 1;
|
|
25
|
-
const newPos = (_ref = selectionStart === selectionEnd ? (selectionStart != null ? selectionStart :
|
|
26
|
-
/* istanbul ignore next */
|
|
27
|
-
0) + direction : direction < 0 ? selectionStart : selectionEnd) != null ? _ref :
|
|
28
|
-
/* istanbul ignore next */
|
|
29
|
-
0;
|
|
30
|
-
(0, _utils.setSelectionRange)(element, newPos, newPos);
|
|
22
|
+
(0, _utils.setSelection)({
|
|
23
|
+
focusNode: element,
|
|
24
|
+
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + (keyDef.key === 'ArrowLeft' ? -1 : 1) : keyDef.key === 'ArrowLeft' ? selection.startOffset : selection.endOffset
|
|
25
|
+
});
|
|
31
26
|
}
|
|
32
27
|
}];
|
|
33
28
|
exports.keydownBehavior = keydownBehavior;
|
|
@@ -36,15 +36,18 @@ const keypressBehavior = [{
|
|
|
36
36
|
|
|
37
37
|
const {
|
|
38
38
|
newValue,
|
|
39
|
-
|
|
40
|
-
} = (0, _utils.calculateNewValue)(newEntry, element);
|
|
39
|
+
newOffset
|
|
40
|
+
} = (0, _utils.calculateNewValue)(newEntry, element, (0, _utils.getInputRange)(element));
|
|
41
41
|
const prevValue = (0, _utils.getValue)(element); // this check was provided by fireInputEventIfNeeded
|
|
42
42
|
// TODO: verify if it is even needed by this handler
|
|
43
43
|
|
|
44
44
|
if (prevValue !== newValue) {
|
|
45
45
|
(0, _utils.fireInputEvent)(element, {
|
|
46
46
|
newValue,
|
|
47
|
-
|
|
47
|
+
newSelection: {
|
|
48
|
+
node: element,
|
|
49
|
+
offset: newOffset
|
|
50
|
+
},
|
|
48
51
|
eventOverrides: {
|
|
49
52
|
data: keyDef.key,
|
|
50
53
|
inputType: 'insertText'
|
|
@@ -77,15 +80,18 @@ const keypressBehavior = [{
|
|
|
77
80
|
|
|
78
81
|
const {
|
|
79
82
|
newValue,
|
|
80
|
-
|
|
81
|
-
} = (0, _utils.calculateNewValue)(newEntry, element);
|
|
83
|
+
newOffset
|
|
84
|
+
} = (0, _utils.calculateNewValue)(newEntry, element, (0, _utils.getInputRange)(element));
|
|
82
85
|
const prevValue = (0, _utils.getValue)(element); // this check was provided by fireInputEventIfNeeded
|
|
83
86
|
// TODO: verify if it is even needed by this handler
|
|
84
87
|
|
|
85
88
|
if (prevValue !== newValue) {
|
|
86
89
|
(0, _utils.fireInputEvent)(element, {
|
|
87
90
|
newValue,
|
|
88
|
-
|
|
91
|
+
newSelection: {
|
|
92
|
+
node: element,
|
|
93
|
+
offset: newOffset
|
|
94
|
+
},
|
|
89
95
|
eventOverrides: {
|
|
90
96
|
data: keyDef.key,
|
|
91
97
|
inputType: 'insertText'
|
|
@@ -121,8 +127,8 @@ const keypressBehavior = [{
|
|
|
121
127
|
|
|
122
128
|
const {
|
|
123
129
|
newValue,
|
|
124
|
-
|
|
125
|
-
} = (0, _utils.
|
|
130
|
+
commit
|
|
131
|
+
} = (0, _utils.prepareInput)(keyDef.key, element); // the browser allows some invalid input but not others
|
|
126
132
|
// it allows up to two '-' at any place before any 'e' or one directly following 'e'
|
|
127
133
|
// it allows one '.' at any place before e
|
|
128
134
|
|
|
@@ -132,54 +138,29 @@ const keypressBehavior = [{
|
|
|
132
138
|
return;
|
|
133
139
|
}
|
|
134
140
|
|
|
135
|
-
(
|
|
136
|
-
newValue,
|
|
137
|
-
newSelectionStart,
|
|
138
|
-
eventOverrides: {
|
|
139
|
-
data: keyDef.key,
|
|
140
|
-
inputType: 'insertText'
|
|
141
|
-
}
|
|
142
|
-
});
|
|
141
|
+
commit();
|
|
143
142
|
}
|
|
144
143
|
}, {
|
|
145
144
|
matches: (keyDef, element) => {
|
|
146
145
|
var _keyDef$key4;
|
|
147
146
|
|
|
148
|
-
return ((_keyDef$key4 = keyDef.key) == null ? void 0 : _keyDef$key4.length) === 1 && ((0, _utils.
|
|
147
|
+
return ((_keyDef$key4 = keyDef.key) == null ? void 0 : _keyDef$key4.length) === 1 && ((0, _utils.isEditableInput)(element) || (0, _utils.isElementType)(element, 'textarea', {
|
|
149
148
|
readOnly: false
|
|
150
|
-
})
|
|
149
|
+
}) || (0, _utils.isContentEditable)(element)) && (0, _utils.getSpaceUntilMaxLength)(element) !== 0;
|
|
151
150
|
},
|
|
152
151
|
handle: (keyDef, element) => {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
} = (0, _utils.calculateNewValue)(keyDef.key, element);
|
|
157
|
-
(0, _utils.fireInputEvent)(element, {
|
|
158
|
-
newValue,
|
|
159
|
-
newSelectionStart,
|
|
160
|
-
eventOverrides: {
|
|
161
|
-
data: keyDef.key,
|
|
162
|
-
inputType: 'insertText'
|
|
163
|
-
}
|
|
164
|
-
});
|
|
152
|
+
var _prepareInput;
|
|
153
|
+
|
|
154
|
+
(_prepareInput = (0, _utils.prepareInput)(keyDef.key, element)) == null ? void 0 : _prepareInput.commit();
|
|
165
155
|
}
|
|
166
156
|
}, {
|
|
167
157
|
matches: (keyDef, element) => keyDef.key === 'Enter' && ((0, _utils.isElementType)(element, 'textarea', {
|
|
168
158
|
readOnly: false
|
|
169
159
|
}) || (0, _utils.isContentEditable)(element)) && (0, _utils.getSpaceUntilMaxLength)(element) !== 0,
|
|
170
160
|
handle: (keyDef, element, options, state) => {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
} = (0, _utils.calculateNewValue)('\n', element);
|
|
175
|
-
const inputType = (0, _utils.isContentEditable)(element) && !state.modifiers.shift ? 'insertParagraph' : 'insertLineBreak';
|
|
176
|
-
(0, _utils.fireInputEvent)(element, {
|
|
177
|
-
newValue,
|
|
178
|
-
newSelectionStart,
|
|
179
|
-
eventOverrides: {
|
|
180
|
-
inputType
|
|
181
|
-
}
|
|
182
|
-
});
|
|
161
|
+
var _prepareInput2;
|
|
162
|
+
|
|
163
|
+
(_prepareInput2 = (0, _utils.prepareInput)('\n', element, (0, _utils.isContentEditable)(element) && !state.modifiers.shift ? 'insertParagraph' : 'insertLineBreak')) == null ? void 0 : _prepareInput2.commit();
|
|
183
164
|
}
|
|
184
165
|
}];
|
|
185
166
|
exports.keypressBehavior = keypressBehavior;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.keydownBehavior = void 0;
|
|
7
|
+
|
|
8
|
+
var _utils = require("../../utils");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Default behavior for key combinations
|
|
12
|
+
*/
|
|
13
|
+
const keydownBehavior = [{
|
|
14
|
+
matches: (keyDef, element, options, state) => keyDef.code === 'KeyA' && state.modifiers.ctrl,
|
|
15
|
+
handle: (keyDef, element) => (0, _utils.selectAll)(element)
|
|
16
|
+
}];
|
|
17
|
+
exports.keydownBehavior = keydownBehavior;
|
|
@@ -42,19 +42,11 @@ const keydownBehavior = [{
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}, {
|
|
45
|
-
matches: (keyDef, element) => keyDef.key === 'Delete' && (0, _utils.isEditable)(element)
|
|
45
|
+
matches: (keyDef, element) => keyDef.key === 'Delete' && (0, _utils.isEditable)(element),
|
|
46
46
|
handle: (keDef, element) => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
} = (0, _utils.calculateNewValue)('', element, undefined, undefined, 'forward');
|
|
51
|
-
(0, _utils.fireInputEvent)(element, {
|
|
52
|
-
newValue,
|
|
53
|
-
newSelectionStart,
|
|
54
|
-
eventOverrides: {
|
|
55
|
-
inputType: 'deleteContentForward'
|
|
56
|
-
}
|
|
57
|
-
});
|
|
47
|
+
var _prepareInput;
|
|
48
|
+
|
|
49
|
+
(_prepareInput = (0, _utils.prepareInput)('', element, 'deleteContentForward')) == null ? void 0 : _prepareInput.commit();
|
|
58
50
|
}
|
|
59
51
|
}];
|
|
60
52
|
exports.keydownBehavior = keydownBehavior;
|
|
@@ -53,19 +53,11 @@ const keydownBehavior = [{
|
|
|
53
53
|
state.modifiers.caps = !state.modifiers.caps;
|
|
54
54
|
}
|
|
55
55
|
}, {
|
|
56
|
-
matches: (keyDef, element) => keyDef.key === 'Backspace' && (0, _utils.isEditable)(element)
|
|
56
|
+
matches: (keyDef, element) => keyDef.key === 'Backspace' && (0, _utils.isEditable)(element),
|
|
57
57
|
handle: (keyDef, element) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
} = (0, _utils.calculateNewValue)('', element, undefined, undefined, 'backward');
|
|
62
|
-
(0, _utils.fireInputEvent)(element, {
|
|
63
|
-
newValue,
|
|
64
|
-
newSelectionStart,
|
|
65
|
-
eventOverrides: {
|
|
66
|
-
inputType: 'deleteContentBackward'
|
|
67
|
-
}
|
|
68
|
-
});
|
|
58
|
+
var _prepareInput;
|
|
59
|
+
|
|
60
|
+
(_prepareInput = (0, _utils.prepareInput)('', element, 'deleteContentBackward')) == null ? void 0 : _prepareInput.commit();
|
|
69
61
|
}
|
|
70
62
|
}, {
|
|
71
63
|
matches: keyDef => keyDef.key === 'Tab',
|
|
@@ -78,7 +70,10 @@ const keydownBehavior = [{
|
|
|
78
70
|
(0, _utils.focus)(dest);
|
|
79
71
|
|
|
80
72
|
if ((0, _utils.isElementType)(dest, ['input', 'textarea'])) {
|
|
81
|
-
(0, _document.setUISelection)(dest,
|
|
73
|
+
(0, _document.setUISelection)(dest, {
|
|
74
|
+
anchorOffset: 0,
|
|
75
|
+
focusOffset: dest.value.length
|
|
76
|
+
});
|
|
82
77
|
}
|
|
83
78
|
}
|
|
84
79
|
}
|
|
@@ -15,6 +15,8 @@ var characterKeys = _interopRequireWildcard(require("./character"));
|
|
|
15
15
|
|
|
16
16
|
var functionalKeys = _interopRequireWildcard(require("./functional"));
|
|
17
17
|
|
|
18
|
+
var combination = _interopRequireWildcard(require("./combination"));
|
|
19
|
+
|
|
18
20
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
21
|
|
|
20
22
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -28,7 +30,7 @@ const replaceBehavior = [{
|
|
|
28
30
|
exports.replaceBehavior = replaceBehavior;
|
|
29
31
|
const preKeydownBehavior = [...functionalKeys.preKeydownBehavior];
|
|
30
32
|
exports.preKeydownBehavior = preKeydownBehavior;
|
|
31
|
-
const keydownBehavior = [...arrowKeys.keydownBehavior, ...controlKeys.keydownBehavior, ...functionalKeys.keydownBehavior];
|
|
33
|
+
const keydownBehavior = [...arrowKeys.keydownBehavior, ...controlKeys.keydownBehavior, ...functionalKeys.keydownBehavior, ...combination.keydownBehavior];
|
|
32
34
|
exports.keydownBehavior = keydownBehavior;
|
|
33
35
|
const keypressBehavior = [...functionalKeys.keypressBehavior, ...characterKeys.keypressBehavior];
|
|
34
36
|
exports.keypressBehavior = keypressBehavior;
|
package/dist/paste.js
CHANGED
|
@@ -17,6 +17,8 @@ function paste(element, text, init, {
|
|
|
17
17
|
initialSelectionStart,
|
|
18
18
|
initialSelectionEnd
|
|
19
19
|
} = {}) {
|
|
20
|
+
var _prepareInput;
|
|
21
|
+
|
|
20
22
|
// TODO: implement for contenteditable
|
|
21
23
|
if (!isSupportedElement(element)) {
|
|
22
24
|
throw new TypeError(`The given ${element.tagName} element is currently unsupported.
|
|
@@ -47,21 +49,12 @@ function paste(element, text, init, {
|
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
text = text.substr(0, (0, _utils.getSpaceUntilMaxLength)(element));
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
newSelectionStart
|
|
53
|
-
} = (0, _utils.calculateNewValue)(text, element);
|
|
52
|
+
const inputRange = (0, _utils.getInputRange)(element);
|
|
53
|
+
/* istanbul ignore if */
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
value: newValue
|
|
59
|
-
}
|
|
60
|
-
});
|
|
55
|
+
if (!inputRange) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
61
58
|
|
|
62
|
-
(0, _utils.
|
|
63
|
-
{
|
|
64
|
-
newSelectionStart,
|
|
65
|
-
selectionEnd: newSelectionStart
|
|
66
|
-
}, {});
|
|
59
|
+
(_prepareInput = (0, _utils.prepareInput)(text, element, 'insertFromPaste')) == null ? void 0 : _prepareInput.commit();
|
|
67
60
|
}
|
|
@@ -58,31 +58,42 @@ async function pointerMove({
|
|
|
58
58
|
fireMove(target, coords);
|
|
59
59
|
|
|
60
60
|
if (selectionRange) {
|
|
61
|
+
// TODO: support extending range (shift)
|
|
61
62
|
const selectionFocus = (0, _resolveSelectionTarget.resolveSelectionTarget)({
|
|
62
63
|
target,
|
|
63
64
|
node,
|
|
64
65
|
offset
|
|
65
66
|
});
|
|
66
67
|
|
|
67
|
-
if ('node' in selectionRange
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const range = selectionRange.cloneRange();
|
|
73
|
-
const cmp = selectionRange.comparePoint(selectionFocus.node, selectionFocus.offset);
|
|
74
|
-
|
|
75
|
-
if (cmp < 0) {
|
|
76
|
-
range.setStart(selectionFocus.node, selectionFocus.offset);
|
|
77
|
-
} else if (cmp > 0) {
|
|
78
|
-
range.setEnd(selectionFocus.node, selectionFocus.offset);
|
|
79
|
-
} // TODO: support multiple ranges
|
|
68
|
+
if ('node' in selectionRange) {
|
|
69
|
+
// When the mouse is dragged outside of an input/textarea,
|
|
70
|
+
// the selection is extended to the beginning or end of the input
|
|
71
|
+
// depending on pointer position.
|
|
72
|
+
// TODO: extend selection according to pointer position
|
|
80
73
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
74
|
+
/* istanbul ignore else */
|
|
75
|
+
if (selectionFocus.node === selectionRange.node) {
|
|
76
|
+
const anchorOffset = selectionFocus.offset < selectionRange.start ? selectionRange.end : selectionRange.start;
|
|
77
|
+
const focusOffset = selectionFocus.offset > selectionRange.end || selectionFocus.offset < selectionRange.start ? selectionFocus.offset : selectionRange.end;
|
|
78
|
+
(0, _document.setUISelection)(selectionRange.node, {
|
|
79
|
+
anchorOffset,
|
|
80
|
+
focusOffset
|
|
81
|
+
});
|
|
85
82
|
}
|
|
83
|
+
} else {
|
|
84
|
+
const range = selectionRange.cloneRange();
|
|
85
|
+
const cmp = range.comparePoint(selectionFocus.node, selectionFocus.offset);
|
|
86
|
+
|
|
87
|
+
if (cmp < 0) {
|
|
88
|
+
range.setStart(selectionFocus.node, selectionFocus.offset);
|
|
89
|
+
} else if (cmp > 0) {
|
|
90
|
+
range.setEnd(selectionFocus.node, selectionFocus.offset);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const selection = target.ownerDocument.getSelection();
|
|
94
|
+
selection.removeAllRanges();
|
|
95
|
+
selection.addRange(range.cloneRange());
|
|
96
|
+
}
|
|
86
97
|
}
|
|
87
98
|
|
|
88
99
|
function fireMove(eventTarget, eventCoords) {
|
|
@@ -274,10 +274,13 @@ function mousedownDefaultBehavior({
|
|
|
274
274
|
const [start, end] = node ? // As offset is describing a DOMOffset it is non-trivial to determine
|
|
275
275
|
// which elements might be considered in the same line of text.
|
|
276
276
|
// TODO: support expanding initial range on multiple clicks if node is given
|
|
277
|
-
[offset, offset] : getTextRange(text, offset, clickCount);
|
|
277
|
+
[offset, offset] : getTextRange(text, offset, clickCount); // TODO: implement modifying selection per shift/ctrl+mouse
|
|
278
278
|
|
|
279
279
|
if (hasValue) {
|
|
280
|
-
(0, _document.setUISelection)(target,
|
|
280
|
+
(0, _document.setUISelection)(target, {
|
|
281
|
+
anchorOffset: start != null ? start : text.length,
|
|
282
|
+
focusOffset: end != null ? end : text.length
|
|
283
|
+
});
|
|
281
284
|
position.selectionRange = {
|
|
282
285
|
node: target,
|
|
283
286
|
start: start != null ? start : 0,
|
|
@@ -303,8 +306,7 @@ function mousedownDefaultBehavior({
|
|
|
303
306
|
const range = new Range();
|
|
304
307
|
range.setStart(startNode, startOffset);
|
|
305
308
|
range.setEnd(endNode, endOffset);
|
|
306
|
-
position.selectionRange = range;
|
|
307
|
-
|
|
309
|
+
position.selectionRange = range;
|
|
308
310
|
const selection = target.ownerDocument.getSelection();
|
|
309
311
|
selection.removeAllRanges();
|
|
310
312
|
selection.addRange(range.cloneRange());
|
|
@@ -15,13 +15,9 @@ function resolveSelectionTarget({
|
|
|
15
15
|
offset
|
|
16
16
|
}) {
|
|
17
17
|
if ((0, _utils.isElementType)(target, ['input', 'textarea'])) {
|
|
18
|
-
var _getUIValue;
|
|
19
|
-
|
|
20
18
|
return {
|
|
21
19
|
node: target,
|
|
22
|
-
offset: offset != null ? offset : (
|
|
23
|
-
/* istanbul ignore next */
|
|
24
|
-
'').length
|
|
20
|
+
offset: offset != null ? offset : (0, _document.getUIValue)(target).length
|
|
25
21
|
};
|
|
26
22
|
} else if (node) {
|
|
27
23
|
return {
|
|
@@ -52,8 +48,12 @@ function findNodeAtTextOffset(node, offset, isRoot = true) {
|
|
|
52
48
|
offset -= text.length;
|
|
53
49
|
} else if (c.nodeType === 1) {
|
|
54
50
|
return findNodeAtTextOffset(c, offset, false);
|
|
55
|
-
} else
|
|
51
|
+
} else {
|
|
52
|
+
// The pre-commit hooks keeps changing this
|
|
53
|
+
// See https://github.com/kentcdodds/kcd-scripts/issues/218
|
|
54
|
+
|
|
56
55
|
/* istanbul ignore else */
|
|
56
|
+
// eslint-disable-next-line no-lonely-if
|
|
57
57
|
if (c.nodeType === 3) {
|
|
58
58
|
var _offset;
|
|
59
59
|
|
|
@@ -62,6 +62,7 @@ function findNodeAtTextOffset(node, offset, isRoot = true) {
|
|
|
62
62
|
offset: (_offset = offset) != null ? _offset : c.nodeValue.length
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
+
}
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
i += step;
|
package/dist/setup.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { clear } from './clear';
|
|
2
|
-
import { click, clickOptions, dblClick } from './click';
|
|
2
|
+
import { click, clickOptions, dblClick, tripleClick } from './click';
|
|
3
3
|
import { hover, unhover } from './hover';
|
|
4
4
|
import { keyboard, keyboardOptions } from './keyboard';
|
|
5
5
|
import type { keyboardState } from './keyboard/types';
|
|
@@ -22,6 +22,7 @@ export declare const userEventApis: {
|
|
|
22
22
|
pointer: typeof pointer;
|
|
23
23
|
selectOptions: typeof selectOptions;
|
|
24
24
|
tab: typeof tab;
|
|
25
|
+
tripleClick: typeof tripleClick;
|
|
25
26
|
type: typeof type;
|
|
26
27
|
unhover: typeof unhover;
|
|
27
28
|
upload: typeof upload;
|
|
@@ -54,6 +55,7 @@ export declare function setup(options?: SetupOptions): {
|
|
|
54
55
|
pointer: typeof pointer;
|
|
55
56
|
selectOptions: typeof selectOptions;
|
|
56
57
|
tab: typeof tab;
|
|
58
|
+
tripleClick: typeof tripleClick;
|
|
57
59
|
type: typeof type;
|
|
58
60
|
unhover: typeof unhover;
|
|
59
61
|
upload: typeof upload;
|
|
@@ -72,6 +74,7 @@ export declare function setup(options?: SetupOptions): {
|
|
|
72
74
|
pointer: typeof pointer;
|
|
73
75
|
selectOptions: typeof selectOptions;
|
|
74
76
|
tab: typeof tab;
|
|
77
|
+
tripleClick: typeof tripleClick;
|
|
75
78
|
type: typeof type;
|
|
76
79
|
unhover: typeof unhover;
|
|
77
80
|
upload: typeof upload;
|
package/dist/setup.js
CHANGED
|
@@ -39,6 +39,7 @@ const userEventApis = {
|
|
|
39
39
|
pointer: _pointer.pointer,
|
|
40
40
|
selectOptions: _selectOptions.selectOptions,
|
|
41
41
|
tab: _tab.tab,
|
|
42
|
+
tripleClick: _click.tripleClick,
|
|
42
43
|
type: _type.type,
|
|
43
44
|
unhover: _hover.unhover,
|
|
44
45
|
upload: _upload.upload
|
|
@@ -175,6 +176,9 @@ function _setup({
|
|
|
175
176
|
tab: (...args) => {
|
|
176
177
|
return _tab.tab.call(userEvent, ...args);
|
|
177
178
|
},
|
|
179
|
+
tripleClick: (...args) => {
|
|
180
|
+
return _click.tripleClick.call(userEvent, ...args);
|
|
181
|
+
},
|
|
178
182
|
// type needs typecasting because of the overloading
|
|
179
183
|
type: (...args) => {
|
|
180
184
|
args[2] = { ...typeDefaults,
|