@testing-library/user-event 14.0.0-alpha.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/dist/{src/clear.d.ts → clear.d.ts} +0 -0
- package/dist/clear.js +14 -27
- package/dist/{src/click.d.ts → click.d.ts} +1 -0
- package/dist/click.js +17 -0
- package/dist/document/index.d.ts +10 -0
- package/dist/document/index.js +8 -10
- package/dist/document/interceptor.d.ts +15 -0
- package/dist/document/interceptor.js +7 -4
- package/dist/document/selection.d.ts +27 -0
- package/dist/document/selection.js +51 -28
- package/dist/{src/document → document}/value.d.ts +5 -1
- package/dist/document/value.js +27 -6
- package/dist/{src/hover.d.ts → hover.d.ts} +0 -0
- package/dist/{src/index.d.ts → index.d.ts} +0 -0
- package/dist/{src/keyboard → keyboard}/getEventProps.d.ts +0 -0
- package/dist/{src/keyboard → keyboard}/getNextKeyDef.d.ts +0 -0
- package/dist/{src/keyboard → keyboard}/index.d.ts +0 -0
- package/dist/{src/keyboard → keyboard}/keyMap.d.ts +0 -0
- package/dist/keyboard/keyMap.js +4 -0
- package/dist/{src/keyboard → keyboard}/keyboardImplementation.d.ts +0 -0
- package/dist/keyboard/keyboardImplementation.js +3 -1
- package/dist/{src/keyboard → keyboard}/plugins/arrow.d.ts +0 -0
- package/dist/keyboard/plugins/arrow.js +7 -12
- package/dist/{src/keyboard → keyboard}/plugins/character.d.ts +0 -0
- package/dist/keyboard/plugins/character.js +27 -45
- package/dist/keyboard/plugins/combination.d.ts +5 -0
- package/dist/keyboard/plugins/combination.js +17 -0
- package/dist/{src/keyboard → keyboard}/plugins/control.d.ts +0 -0
- package/dist/keyboard/plugins/control.js +4 -12
- package/dist/{src/keyboard → keyboard}/plugins/functional.d.ts +0 -0
- package/dist/keyboard/plugins/functional.js +23 -11
- package/dist/{src/keyboard → keyboard}/plugins/index.d.ts +0 -0
- package/dist/keyboard/plugins/index.js +3 -1
- package/dist/{src/keyboard → keyboard}/shared/fireChangeForInputTimeIfValid.d.ts +0 -0
- package/dist/{src/keyboard → keyboard}/shared/index.d.ts +0 -0
- package/dist/{src/keyboard → keyboard}/specialCharMap.d.ts +0 -0
- package/dist/{src/keyboard → keyboard}/types.d.ts +0 -0
- package/dist/{src/paste.d.ts → paste.d.ts} +0 -0
- package/dist/paste.js +8 -15
- package/dist/{src/pointer → pointer}/index.d.ts +0 -0
- package/dist/{src/pointer → pointer}/keyMap.d.ts +0 -0
- package/dist/{src/pointer → pointer}/parseKeyDef.d.ts +0 -0
- package/dist/{src/pointer → pointer}/pointerAction.d.ts +2 -6
- package/dist/pointer/pointerAction.js +2 -26
- package/dist/pointer/pointerMove.d.ts +5 -0
- package/dist/pointer/pointerMove.js +49 -5
- package/dist/pointer/pointerPress.d.ts +7 -0
- package/dist/pointer/pointerPress.js +135 -29
- package/dist/pointer/resolveSelectionTarget.d.ts +5 -0
- package/dist/pointer/resolveSelectionTarget.js +75 -0
- package/dist/{src/pointer → pointer}/types.d.ts +18 -4
- package/dist/{src/selectOptions.d.ts → selectOptions.d.ts} +0 -0
- package/dist/{src/setup.d.ts → setup.d.ts} +5 -2
- package/dist/setup.js +4 -7
- package/dist/tab.d.ts +5 -0
- package/dist/tab.js +3 -132
- package/dist/{src/type.d.ts → type.d.ts} +0 -0
- package/dist/type.js +3 -19
- package/dist/{src/upload.d.ts → upload.d.ts} +0 -0
- package/dist/{src/utils → utils}/click/isClickableInput.d.ts +0 -0
- package/dist/{src/utils → utils}/edit/buildTimeValue.d.ts +0 -0
- package/dist/utils/edit/calculateNewValue.d.ts +14 -0
- 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/{src/utils → utils}/edit/getValue.d.ts +0 -0
- package/dist/utils/edit/getValue.js +1 -3
- package/dist/utils/edit/isContentEditable.d.ts +7 -0
- package/dist/utils/edit/isContentEditable.js +14 -0
- package/dist/{src/utils → utils}/edit/isEditable.d.ts +1 -0
- package/dist/{src/utils → utils}/edit/isValidDateValue.d.ts +0 -0
- package/dist/{src/utils → utils}/edit/isValidInputTimeValue.d.ts +0 -0
- package/dist/{src/utils → utils}/edit/maxLength.d.ts +0 -0
- package/dist/utils/edit/prepareInput.d.ts +7 -0
- package/dist/utils/edit/prepareInput.js +77 -0
- package/dist/{src/utils → utils}/focus/blur.d.ts +0 -0
- package/dist/{src/utils → utils}/focus/focus.d.ts +0 -0
- package/dist/utils/focus/focus.js +3 -0
- package/dist/{src/utils → utils}/focus/getActiveElement.d.ts +0 -0
- package/dist/utils/focus/getTabDestination.d.ts +1 -0
- package/dist/utils/focus/getTabDestination.js +71 -0
- package/dist/{src/utils → utils}/focus/isFocusable.d.ts +0 -0
- 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/{src/utils → utils}/focus/selector.d.ts +0 -0
- package/dist/{src/utils → utils}/index.d.ts +5 -5
- package/dist/utils/index.js +47 -47
- package/dist/{src/utils → utils}/keyDef/readNextDescriptor.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/eventWrapper.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/findClosest.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/hasFormSubmit.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/hasPointerEvents.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/isDescendantOrSelf.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/isDisabled.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/isElementType.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/isVisible.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/wait.d.ts +0 -0
- package/dist/{src/utils → utils}/pointer/firePointerEvents.d.ts +13 -11
- package/dist/utils/pointer/firePointerEvents.js +62 -5
- package/dist/{src/utils → utils}/pointer/mouseButtons.d.ts +0 -0
- package/package.json +2 -2
- package/dist/document/applyNative.js +0 -28
- package/dist/src/document/applyNative.d.ts +0 -8
- package/dist/src/document/index.d.ts +0 -10
- package/dist/src/document/interceptor.d.ts +0 -5
- package/dist/src/document/selection.d.ts +0 -18
- package/dist/src/pointer/pointerMove.d.ts +0 -5
- package/dist/src/pointer/pointerPress.d.ts +0 -7
- package/dist/src/tab.d.ts +0 -6
- package/dist/src/utils/edit/calculateNewValue.d.ts +0 -7
- package/dist/src/utils/edit/cursorPosition.d.ts +0 -2
- package/dist/src/utils/edit/fireInputEvent.d.ts +0 -8
- package/dist/src/utils/edit/isContentEditable.d.ts +0 -3
- package/dist/src/utils/edit/selectionRange.d.ts +0 -5
- package/dist/src/utils/misc/isDocument.d.ts +0 -1
- package/dist/src/utils/pointer/fakeEvent.d.ts +0 -16
- package/dist/tests/_helpers/custom-element.d.ts +0 -8
- package/dist/tests/_helpers/utils.d.ts +0 -73
- package/dist/tests/_setup-env.d.ts +0 -1
- package/dist/tests/clear.d.ts +0 -1
- package/dist/tests/click/click.d.ts +0 -1
- package/dist/tests/click/dblclick.d.ts +0 -1
- package/dist/tests/document/index.d.ts +0 -1
- package/dist/tests/document/selectionRange.d.ts +0 -1
- package/dist/tests/hover/hover.d.ts +0 -1
- package/dist/tests/hover/unhover.d.ts +0 -1
- package/dist/tests/keyboard/getNextKeyDef.d.ts +0 -1
- package/dist/tests/keyboard/index.d.ts +0 -1
- package/dist/tests/keyboard/keyboardImplementation.d.ts +0 -1
- package/dist/tests/keyboard/plugin/arrow.d.ts +0 -1
- package/dist/tests/keyboard/plugin/character.d.ts +0 -1
- package/dist/tests/keyboard/plugin/control.d.ts +0 -1
- package/dist/tests/keyboard/plugin/functional.d.ts +0 -1
- package/dist/tests/keyboard/shared/fireInputEvent.d.ts +0 -1
- package/dist/tests/paste.d.ts +0 -1
- package/dist/tests/pointer/index.d.ts +0 -1
- package/dist/tests/react/keyboard.d.ts +0 -1
- package/dist/tests/react/type.d.ts +0 -1
- package/dist/tests/selectOptions/deselect.d.ts +0 -1
- package/dist/tests/selectOptions/select.d.ts +0 -1
- package/dist/tests/setup.d.ts +0 -10
- package/dist/tests/tab.d.ts +0 -1
- package/dist/tests/type/index.d.ts +0 -1
- package/dist/tests/type/modifiers.d.ts +0 -1
- package/dist/tests/upload.d.ts +0 -1
- package/dist/tests/utils/edit/calculateNewValue.d.ts +0 -1
- package/dist/tests/utils/edit/isContentEditable.d.ts +0 -1
- package/dist/tests/utils/focus/blur.d.ts +0 -1
- package/dist/tests/utils/focus/focus.d.ts +0 -1
- package/dist/tests/utils/misc/hasPointerEvents.d.ts +0 -1
- package/dist/tests/utils/misc/isDescendantOrSelf.d.ts +0 -1
- package/dist/tests/utils/misc/isElementType.d.ts +0 -1
- package/dist/tests/utils/misc/isVisible.d.ts +0 -1
- package/dist/utils/edit/cursorPosition.js +0 -35
- package/dist/utils/edit/fireInputEvent.js +0 -55
- package/dist/utils/edit/selectionRange.js +0 -64
- package/dist/utils/misc/dom-helpers.d.ts +0 -3
- package/dist/utils/misc/isDocument.js +0 -10
- package/dist/utils/pointer/fakeEvent.js +0 -82
|
@@ -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;
|
|
File without changes
|
|
@@ -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;
|
|
File without changes
|
|
@@ -7,6 +7,8 @@ exports.preKeyupBehavior = exports.preKeydownBehavior = exports.postKeyupBehavio
|
|
|
7
7
|
|
|
8
8
|
var _dom = require("@testing-library/dom");
|
|
9
9
|
|
|
10
|
+
var _document = require("../../document");
|
|
11
|
+
|
|
10
12
|
var _utils = require("../../utils");
|
|
11
13
|
|
|
12
14
|
var _getEventProps = require("../getEventProps");
|
|
@@ -51,19 +53,29 @@ const keydownBehavior = [{
|
|
|
51
53
|
state.modifiers.caps = !state.modifiers.caps;
|
|
52
54
|
}
|
|
53
55
|
}, {
|
|
54
|
-
matches: (keyDef, element) => keyDef.key === 'Backspace' && (0, _utils.isEditable)(element)
|
|
56
|
+
matches: (keyDef, element) => keyDef.key === 'Backspace' && (0, _utils.isEditable)(element),
|
|
55
57
|
handle: (keyDef, element) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
var _prepareInput;
|
|
59
|
+
|
|
60
|
+
(_prepareInput = (0, _utils.prepareInput)('', element, 'deleteContentBackward')) == null ? void 0 : _prepareInput.commit();
|
|
61
|
+
}
|
|
62
|
+
}, {
|
|
63
|
+
matches: keyDef => keyDef.key === 'Tab',
|
|
64
|
+
handle: (keyDef, element, options, state) => {
|
|
65
|
+
const dest = (0, _utils.getTabDestination)(element, state.modifiers.shift);
|
|
66
|
+
|
|
67
|
+
if (dest === element.ownerDocument.body) {
|
|
68
|
+
(0, _utils.blur)(element);
|
|
69
|
+
} else {
|
|
70
|
+
(0, _utils.focus)(dest);
|
|
71
|
+
|
|
72
|
+
if ((0, _utils.isElementType)(dest, ['input', 'textarea'])) {
|
|
73
|
+
(0, _document.setUISelection)(dest, {
|
|
74
|
+
anchorOffset: 0,
|
|
75
|
+
focusOffset: dest.value.length
|
|
76
|
+
});
|
|
65
77
|
}
|
|
66
|
-
}
|
|
78
|
+
}
|
|
67
79
|
}
|
|
68
80
|
}];
|
|
69
81
|
exports.keydownBehavior = keydownBehavior;
|
|
File without changes
|
|
@@ -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;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
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
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { Coords } from '../utils';
|
|
2
1
|
import { PointerMoveAction } from './pointerMove';
|
|
3
2
|
import { PointerPressAction } from './pointerPress';
|
|
4
|
-
import { inputDeviceState, pointerOptions } from './types';
|
|
5
|
-
export declare type PointerActionTarget =
|
|
6
|
-
target?: Element;
|
|
7
|
-
coords?: Partial<Coords>;
|
|
8
|
-
};
|
|
3
|
+
import { inputDeviceState, pointerOptions, PointerTarget, SelectionTarget } from './types';
|
|
4
|
+
export declare type PointerActionTarget = Partial<PointerTarget> & Partial<SelectionTarget>;
|
|
9
5
|
export declare type PointerAction = PointerActionTarget & (Omit<PointerPressAction, 'target' | 'coords'> | Omit<PointerMoveAction, 'target' | 'coords'>);
|
|
10
6
|
export declare function pointerAction(actions: PointerAction[], options: pointerOptions, state: inputDeviceState): Promise<unknown[]>;
|
|
@@ -15,14 +15,12 @@ async function pointerAction(actions, options, state) {
|
|
|
15
15
|
const ret = [];
|
|
16
16
|
|
|
17
17
|
for (let i = 0; i < actions.length; i++) {
|
|
18
|
-
var _action$target;
|
|
18
|
+
var _action$target, _action$coords;
|
|
19
19
|
|
|
20
20
|
const action = actions[i];
|
|
21
21
|
const pointerName = 'pointerName' in action && action.pointerName ? action.pointerName : 'keyDef' in action ? action.keyDef.pointerType === 'touch' ? action.keyDef.name : action.keyDef.pointerType : 'mouse';
|
|
22
22
|
const target = (_action$target = action.target) != null ? _action$target : getPrevTarget(pointerName, state.pointerState);
|
|
23
|
-
const coords =
|
|
24
|
-
...action.coords
|
|
25
|
-
});
|
|
23
|
+
const coords = (_action$coords = action.coords) != null ? _action$coords : pointerName in state.pointerState.position ? state.pointerState.position[pointerName].coords : undefined;
|
|
26
24
|
const promise = 'keyDef' in action ? (0, _pointerPress.pointerPress)({ ...action,
|
|
27
25
|
target,
|
|
28
26
|
coords
|
|
@@ -51,26 +49,4 @@ function getPrevTarget(pointerName, state) {
|
|
|
51
49
|
}
|
|
52
50
|
|
|
53
51
|
return state.position[pointerName].target;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function completeCoords({
|
|
57
|
-
x = 0,
|
|
58
|
-
y = 0,
|
|
59
|
-
clientX = x,
|
|
60
|
-
clientY = y,
|
|
61
|
-
offsetX = x,
|
|
62
|
-
offsetY = y,
|
|
63
|
-
pageX = clientX,
|
|
64
|
-
pageY = clientY
|
|
65
|
-
}) {
|
|
66
|
-
return {
|
|
67
|
-
x,
|
|
68
|
-
y,
|
|
69
|
-
clientX,
|
|
70
|
-
clientY,
|
|
71
|
-
offsetX,
|
|
72
|
-
offsetY,
|
|
73
|
-
pageX,
|
|
74
|
-
pageY
|
|
75
|
-
};
|
|
76
52
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { inputDeviceState, PointerTarget, SelectionTarget } from './types';
|
|
2
|
+
export interface PointerMoveAction extends PointerTarget, SelectionTarget {
|
|
3
|
+
pointerName?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function pointerMove({ pointerName, target, coords, node, offset }: PointerMoveAction, { pointerState, keyboardState }: inputDeviceState): Promise<void>;
|
|
@@ -5,12 +5,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.pointerMove = pointerMove;
|
|
7
7
|
|
|
8
|
+
var _document = require("../document");
|
|
9
|
+
|
|
8
10
|
var _utils = require("../utils");
|
|
9
11
|
|
|
12
|
+
var _resolveSelectionTarget = require("./resolveSelectionTarget");
|
|
13
|
+
|
|
10
14
|
async function pointerMove({
|
|
11
15
|
pointerName = 'mouse',
|
|
12
16
|
target,
|
|
13
|
-
coords
|
|
17
|
+
coords,
|
|
18
|
+
node,
|
|
19
|
+
offset
|
|
14
20
|
}, {
|
|
15
21
|
pointerState,
|
|
16
22
|
keyboardState
|
|
@@ -23,7 +29,8 @@ async function pointerMove({
|
|
|
23
29
|
pointerId,
|
|
24
30
|
pointerType,
|
|
25
31
|
target: prevTarget,
|
|
26
|
-
coords: prevCoords
|
|
32
|
+
coords: prevCoords,
|
|
33
|
+
selectionRange
|
|
27
34
|
} = pointerState.position[pointerName];
|
|
28
35
|
|
|
29
36
|
if (prevTarget && prevTarget !== target) {
|
|
@@ -35,9 +42,7 @@ async function pointerMove({
|
|
|
35
42
|
}
|
|
36
43
|
}
|
|
37
44
|
|
|
38
|
-
pointerState.position[pointerName] = {
|
|
39
|
-
pointerId,
|
|
40
|
-
pointerType,
|
|
45
|
+
pointerState.position[pointerName] = { ...pointerState.position[pointerName],
|
|
41
46
|
target,
|
|
42
47
|
coords
|
|
43
48
|
};
|
|
@@ -52,6 +57,45 @@ async function pointerMove({
|
|
|
52
57
|
|
|
53
58
|
fireMove(target, coords);
|
|
54
59
|
|
|
60
|
+
if (selectionRange) {
|
|
61
|
+
// TODO: support extending range (shift)
|
|
62
|
+
const selectionFocus = (0, _resolveSelectionTarget.resolveSelectionTarget)({
|
|
63
|
+
target,
|
|
64
|
+
node,
|
|
65
|
+
offset
|
|
66
|
+
});
|
|
67
|
+
|
|
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
|
|
73
|
+
|
|
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
|
+
});
|
|
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
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
55
99
|
function fireMove(eventTarget, eventCoords) {
|
|
56
100
|
fire(eventTarget, 'pointermove', eventCoords);
|
|
57
101
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { inputDeviceState, pointerKey, PointerTarget, SelectionTarget } from './types';
|
|
2
|
+
export interface PointerPressAction extends PointerTarget, SelectionTarget {
|
|
3
|
+
keyDef: pointerKey;
|
|
4
|
+
releasePrevious: boolean;
|
|
5
|
+
releaseSelf: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function pointerPress(action: PointerPressAction, state: inputDeviceState): Promise<void>;
|
|
@@ -9,27 +9,31 @@ var _dom = require("@testing-library/dom");
|
|
|
9
9
|
|
|
10
10
|
var _utils = require("../utils");
|
|
11
11
|
|
|
12
|
+
var _document = require("../document");
|
|
13
|
+
|
|
14
|
+
var _resolveSelectionTarget = require("./resolveSelectionTarget");
|
|
15
|
+
|
|
12
16
|
/* eslint-disable complexity */
|
|
13
|
-
async function pointerPress({
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
17
|
+
async function pointerPress(action, state) {
|
|
18
|
+
const {
|
|
19
|
+
keyDef,
|
|
20
|
+
target,
|
|
21
|
+
releasePrevious,
|
|
22
|
+
releaseSelf
|
|
23
|
+
} = action;
|
|
20
24
|
const previous = state.pointerState.pressed.find(p => p.keyDef === keyDef);
|
|
21
25
|
const pointerName = keyDef.pointerType === 'touch' ? keyDef.name : keyDef.pointerType;
|
|
22
26
|
const targetIsDisabled = (0, _utils.isDisabled)(target);
|
|
23
27
|
|
|
24
28
|
if (previous) {
|
|
25
|
-
up(state, pointerName,
|
|
29
|
+
up(state, pointerName, action, previous, targetIsDisabled);
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
if (!releasePrevious) {
|
|
29
|
-
const press = down(state, pointerName,
|
|
33
|
+
const press = down(state, pointerName, action, targetIsDisabled);
|
|
30
34
|
|
|
31
35
|
if (releaseSelf) {
|
|
32
|
-
up(state, pointerName,
|
|
36
|
+
up(state, pointerName, action, press, targetIsDisabled);
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
}
|
|
@@ -42,7 +46,13 @@ function getNextPointerId(state) {
|
|
|
42
46
|
function down({
|
|
43
47
|
pointerState,
|
|
44
48
|
keyboardState
|
|
45
|
-
}, pointerName,
|
|
49
|
+
}, pointerName, {
|
|
50
|
+
keyDef,
|
|
51
|
+
node,
|
|
52
|
+
offset,
|
|
53
|
+
target,
|
|
54
|
+
coords
|
|
55
|
+
}, targetIsDisabled) {
|
|
46
56
|
var _pointerState$activeC, _pointerState$activeC2, _pointerState$activeC3;
|
|
47
57
|
|
|
48
58
|
const {
|
|
@@ -51,7 +61,7 @@ function down({
|
|
|
51
61
|
button
|
|
52
62
|
} = keyDef;
|
|
53
63
|
const pointerId = pointerType === 'mouse' ? 1 : getNextPointerId(pointerState);
|
|
54
|
-
pointerState.position[pointerName] = {
|
|
64
|
+
pointerState.position[pointerName] = { ...pointerState.position[pointerName],
|
|
55
65
|
pointerId,
|
|
56
66
|
pointerType,
|
|
57
67
|
target,
|
|
@@ -106,9 +116,14 @@ function down({
|
|
|
106
116
|
}
|
|
107
117
|
|
|
108
118
|
if (pointerType === 'mouse' && pressObj.unpreventedDefault) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
119
|
+
mousedownDefaultBehavior({
|
|
120
|
+
target,
|
|
121
|
+
targetIsDisabled,
|
|
122
|
+
clickCount,
|
|
123
|
+
position: pointerState.position[pointerName],
|
|
124
|
+
node,
|
|
125
|
+
offset
|
|
126
|
+
});
|
|
112
127
|
}
|
|
113
128
|
|
|
114
129
|
return pressObj;
|
|
@@ -131,9 +146,15 @@ function up({
|
|
|
131
146
|
pointerState,
|
|
132
147
|
keyboardState
|
|
133
148
|
}, pointerName, {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
149
|
+
keyDef: {
|
|
150
|
+
pointerType,
|
|
151
|
+
button
|
|
152
|
+
},
|
|
153
|
+
target,
|
|
154
|
+
coords,
|
|
155
|
+
node,
|
|
156
|
+
offset
|
|
157
|
+
}, pressed, targetIsDisabled) {
|
|
137
158
|
pointerState.pressed = pointerState.pressed.filter(p => p !== pressed);
|
|
138
159
|
const {
|
|
139
160
|
isMultiTouch,
|
|
@@ -144,9 +165,7 @@ function up({
|
|
|
144
165
|
let {
|
|
145
166
|
unpreventedDefault
|
|
146
167
|
} = pressed;
|
|
147
|
-
pointerState.position[pointerName] = {
|
|
148
|
-
pointerId,
|
|
149
|
-
pointerType,
|
|
168
|
+
pointerState.position[pointerName] = { ...pointerState.position[pointerName],
|
|
150
169
|
target,
|
|
151
170
|
coords
|
|
152
171
|
}; // TODO: pointerleave for touch device
|
|
@@ -173,14 +192,18 @@ function up({
|
|
|
173
192
|
}
|
|
174
193
|
|
|
175
194
|
if (unpreventedDefault && pointerType !== 'mouse' && !isMultiTouch) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
195
|
+
mousedownDefaultBehavior({
|
|
196
|
+
target,
|
|
197
|
+
targetIsDisabled,
|
|
198
|
+
clickCount,
|
|
199
|
+
position: pointerState.position[pointerName],
|
|
200
|
+
node,
|
|
201
|
+
offset
|
|
202
|
+
});
|
|
182
203
|
}
|
|
183
204
|
|
|
205
|
+
delete pointerState.position[pointerName].selectionRange;
|
|
206
|
+
|
|
184
207
|
if (!targetIsDisabled) {
|
|
185
208
|
if (pointerType === 'mouse' || !isMultiTouch) {
|
|
186
209
|
unpreventedDefault = fire('mouseup') && unpreventedDefault;
|
|
@@ -197,9 +220,9 @@ function up({
|
|
|
197
220
|
const label = target.closest('label');
|
|
198
221
|
|
|
199
222
|
if (label != null && label.control) {
|
|
200
|
-
var
|
|
223
|
+
var _findClosest;
|
|
201
224
|
|
|
202
|
-
(0, _utils.focus)((
|
|
225
|
+
(0, _utils.focus)((_findClosest = (0, _utils.findClosest)(label.control, _utils.isFocusable)) != null ? _findClosest : target.ownerDocument.body);
|
|
203
226
|
}
|
|
204
227
|
}
|
|
205
228
|
|
|
@@ -221,4 +244,87 @@ function up({
|
|
|
221
244
|
pointerType
|
|
222
245
|
});
|
|
223
246
|
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function mousedownDefaultBehavior({
|
|
250
|
+
position,
|
|
251
|
+
target,
|
|
252
|
+
targetIsDisabled,
|
|
253
|
+
clickCount,
|
|
254
|
+
node,
|
|
255
|
+
offset
|
|
256
|
+
}) {
|
|
257
|
+
var _findClosest2;
|
|
258
|
+
|
|
259
|
+
// The closest focusable element is focused when a `mousedown` would have been fired.
|
|
260
|
+
// Even if there was no `mousedown` because the element was disabled.
|
|
261
|
+
// A `mousedown` that preventsDefault cancels this though.
|
|
262
|
+
(0, _utils.focus)((_findClosest2 = (0, _utils.findClosest)(target, _utils.isFocusable)) != null ? _findClosest2 : target.ownerDocument.body); // TODO: What happens if a focus event handler interfers?
|
|
263
|
+
// An unprevented mousedown moves the cursor to the closest character.
|
|
264
|
+
// We try to approximate the behavior for a no-layout environment.
|
|
265
|
+
|
|
266
|
+
if (!targetIsDisabled) {
|
|
267
|
+
const hasValue = (0, _utils.isElementType)(target, ['input', 'textarea']); // On non-input elements the text selection per multiple click
|
|
268
|
+
// can extend beyond the target boundaries.
|
|
269
|
+
// The exact mechanism what is considered in the same line is unclear.
|
|
270
|
+
// Looks it might be every inline element.
|
|
271
|
+
// TODO: Check what might be considered part of the same line of text.
|
|
272
|
+
|
|
273
|
+
const text = String(hasValue ? (0, _document.getUIValue)(target) : target.textContent);
|
|
274
|
+
const [start, end] = node ? // As offset is describing a DOMOffset it is non-trivial to determine
|
|
275
|
+
// which elements might be considered in the same line of text.
|
|
276
|
+
// TODO: support expanding initial range on multiple clicks if node is given
|
|
277
|
+
[offset, offset] : getTextRange(text, offset, clickCount); // TODO: implement modifying selection per shift/ctrl+mouse
|
|
278
|
+
|
|
279
|
+
if (hasValue) {
|
|
280
|
+
(0, _document.setUISelection)(target, {
|
|
281
|
+
anchorOffset: start != null ? start : text.length,
|
|
282
|
+
focusOffset: end != null ? end : text.length
|
|
283
|
+
});
|
|
284
|
+
position.selectionRange = {
|
|
285
|
+
node: target,
|
|
286
|
+
start: start != null ? start : 0,
|
|
287
|
+
end: end != null ? end : text.length
|
|
288
|
+
};
|
|
289
|
+
} else {
|
|
290
|
+
const {
|
|
291
|
+
node: startNode,
|
|
292
|
+
offset: startOffset
|
|
293
|
+
} = (0, _resolveSelectionTarget.resolveSelectionTarget)({
|
|
294
|
+
target,
|
|
295
|
+
node,
|
|
296
|
+
offset: start
|
|
297
|
+
});
|
|
298
|
+
const {
|
|
299
|
+
node: endNode,
|
|
300
|
+
offset: endOffset
|
|
301
|
+
} = (0, _resolveSelectionTarget.resolveSelectionTarget)({
|
|
302
|
+
target,
|
|
303
|
+
node,
|
|
304
|
+
offset: end
|
|
305
|
+
});
|
|
306
|
+
const range = new Range();
|
|
307
|
+
range.setStart(startNode, startOffset);
|
|
308
|
+
range.setEnd(endNode, endOffset);
|
|
309
|
+
position.selectionRange = range;
|
|
310
|
+
const selection = target.ownerDocument.getSelection();
|
|
311
|
+
selection.removeAllRanges();
|
|
312
|
+
selection.addRange(range.cloneRange());
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function getTextRange(text, pos, clickCount) {
|
|
318
|
+
if (clickCount % 3 === 1 || text.length === 0) {
|
|
319
|
+
return [pos, pos];
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const textPos = pos != null ? pos : text.length;
|
|
323
|
+
|
|
324
|
+
if (clickCount % 3 === 2) {
|
|
325
|
+
return [textPos - text.substr(0, pos).match(/(\w+|\s+|\W)?$/)[0].length, pos === undefined ? pos : pos + text.substr(pos).match(/^(\w+|\s+|\W)?/)[0].length];
|
|
326
|
+
} // triple click
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
return [textPos - text.substr(0, pos).match(/[^\r\n]*$/)[0].length, pos === undefined ? pos : pos + text.substr(pos).match(/^[^\r\n]*/)[0].length];
|
|
224
330
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.resolveSelectionTarget = resolveSelectionTarget;
|
|
7
|
+
|
|
8
|
+
var _document = require("../document");
|
|
9
|
+
|
|
10
|
+
var _utils = require("../utils");
|
|
11
|
+
|
|
12
|
+
function resolveSelectionTarget({
|
|
13
|
+
target,
|
|
14
|
+
node,
|
|
15
|
+
offset
|
|
16
|
+
}) {
|
|
17
|
+
if ((0, _utils.isElementType)(target, ['input', 'textarea'])) {
|
|
18
|
+
return {
|
|
19
|
+
node: target,
|
|
20
|
+
offset: offset != null ? offset : (0, _document.getUIValue)(target).length
|
|
21
|
+
};
|
|
22
|
+
} else if (node) {
|
|
23
|
+
return {
|
|
24
|
+
node,
|
|
25
|
+
offset: offset != null ? offset : node.nodeType === 3 ? node.nodeValue.length : node.childNodes.length
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return findNodeAtTextOffset(target, offset);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function findNodeAtTextOffset(node, offset, isRoot = true) {
|
|
33
|
+
// When clicking after the content the browser behavior can be complicated:
|
|
34
|
+
// 1. If there is textContent after the last element child,
|
|
35
|
+
// the cursor is moved there.
|
|
36
|
+
// 2. If there is textContent in the last element child,
|
|
37
|
+
// the browser moves the cursor to the last non-empty text node inside this element.
|
|
38
|
+
// 3. Otherwise the cursor is moved to the end of the target.
|
|
39
|
+
let i = offset === undefined ? node.childNodes.length - 1 : 0;
|
|
40
|
+
const step = offset === undefined ? -1 : +1;
|
|
41
|
+
|
|
42
|
+
while (offset === undefined ? i >= (isRoot ? Math.max(node.childNodes.length - 1, 0) : 0) : i <= node.childNodes.length) {
|
|
43
|
+
const c = node.childNodes.item(i);
|
|
44
|
+
const text = String(c.textContent);
|
|
45
|
+
|
|
46
|
+
if (text.length) {
|
|
47
|
+
if (offset !== undefined && text.length < offset) {
|
|
48
|
+
offset -= text.length;
|
|
49
|
+
} else if (c.nodeType === 1) {
|
|
50
|
+
return findNodeAtTextOffset(c, offset, false);
|
|
51
|
+
} else {
|
|
52
|
+
// The pre-commit hooks keeps changing this
|
|
53
|
+
// See https://github.com/kentcdodds/kcd-scripts/issues/218
|
|
54
|
+
|
|
55
|
+
/* istanbul ignore else */
|
|
56
|
+
// eslint-disable-next-line no-lonely-if
|
|
57
|
+
if (c.nodeType === 3) {
|
|
58
|
+
var _offset;
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
node: c,
|
|
62
|
+
offset: (_offset = offset) != null ? _offset : c.nodeValue.length
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
i += step;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
node,
|
|
73
|
+
offset: node.childNodes.length
|
|
74
|
+
};
|
|
75
|
+
}
|