@testing-library/user-event 14.0.0-alpha.2 → 14.0.0-alpha.6
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 +2 -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 +0 -1
- package/dist/document/selection.js +22 -15
- package/dist/document/value.d.ts +4 -0
- package/dist/document/value.js +26 -5
- package/dist/keyboard/keyMap.js +4 -0
- package/dist/keyboard/keyboardImplementation.js +3 -1
- package/dist/keyboard/plugins/functional.js +17 -0
- package/dist/pointer/pointerAction.d.ts +2 -6
- package/dist/pointer/pointerAction.js +2 -26
- package/dist/pointer/pointerMove.d.ts +3 -3
- package/dist/pointer/pointerMove.js +38 -5
- package/dist/pointer/pointerPress.d.ts +3 -3
- package/dist/pointer/pointerPress.js +133 -29
- package/dist/pointer/resolveSelectionTarget.d.ts +5 -0
- package/dist/pointer/resolveSelectionTarget.js +74 -0
- package/dist/pointer/types.d.ts +18 -4
- 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/type.js +3 -19
- package/dist/utils/edit/fireInputEvent.js +20 -16
- package/dist/utils/edit/getValue.js +1 -3
- package/dist/utils/focus/getTabDestination.d.ts +1 -0
- package/dist/utils/focus/getTabDestination.js +71 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +13 -13
- package/dist/utils/pointer/fakeEvent.d.ts +7 -3
- package/dist/utils/pointer/fakeEvent.js +18 -9
- package/dist/utils/pointer/firePointerEvents.d.ts +2 -11
- package/package.json +1 -1
- package/dist/document/applyNative.d.ts +0 -8
- package/dist/document/applyNative.js +0 -28
- package/dist/utils/misc/isDocument.d.ts +0 -1
- package/dist/utils/misc/isDocument.js +0 -10
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
|
@@ -5,6 +5,5 @@ declare global {
|
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
7
|
export declare function prepareDocument(document: Document): void;
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export { getUISelection, hasUISelection, setUISelection } from './selection';
|
|
8
|
+
export { getUIValue, setUIValue, startTrackValue, endTrackValue } from './value';
|
|
9
|
+
export { getUISelection, setUISelection } from './selection';
|
package/dist/document/index.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "
|
|
6
|
+
Object.defineProperty(exports, "endTrackValue", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return
|
|
9
|
+
return _value.endTrackValue;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "getUISelection", {
|
|
@@ -21,12 +21,6 @@ Object.defineProperty(exports, "getUIValue", {
|
|
|
21
21
|
return _value.getUIValue;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
-
Object.defineProperty(exports, "hasUISelection", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function () {
|
|
27
|
-
return _selection.hasUISelection;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
24
|
exports.prepareDocument = prepareDocument;
|
|
31
25
|
Object.defineProperty(exports, "setUISelection", {
|
|
32
26
|
enumerable: true,
|
|
@@ -40,6 +34,12 @@ Object.defineProperty(exports, "setUIValue", {
|
|
|
40
34
|
return _value.setUIValue;
|
|
41
35
|
}
|
|
42
36
|
});
|
|
37
|
+
Object.defineProperty(exports, "startTrackValue", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () {
|
|
40
|
+
return _value.startTrackValue;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
43
|
|
|
44
44
|
var _dom = require("@testing-library/dom");
|
|
45
45
|
|
|
@@ -47,8 +47,6 @@ var _selection = require("./selection");
|
|
|
47
47
|
|
|
48
48
|
var _value = require("./value");
|
|
49
49
|
|
|
50
|
-
var _applyNative = require("./applyNative");
|
|
51
|
-
|
|
52
50
|
const isPrepared = Symbol('Node prepared with document state workarounds');
|
|
53
51
|
|
|
54
52
|
function prepareDocument(document) {
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
declare type anyFunc = (...a: any[]) => any;
|
|
2
2
|
declare type Params<Prop> = Prop extends anyFunc ? Parameters<Prop> : [Prop];
|
|
3
3
|
declare type ImplReturn<Prop> = Prop extends anyFunc ? Parameters<Prop> : Prop;
|
|
4
|
-
export declare function prepareInterceptor<ElementType extends
|
|
4
|
+
export declare function prepareInterceptor<ElementType extends Node, PropName extends keyof ElementType>(element: ElementType, propName: PropName, interceptorImpl: (this: ElementType, ...args: Params<ElementType[PropName]>) => {
|
|
5
|
+
/**
|
|
6
|
+
* React tracks the changes on element properties.
|
|
7
|
+
* This workaround tries to alter the DOM element without React noticing,
|
|
8
|
+
* so that it later picks up the change.
|
|
9
|
+
*
|
|
10
|
+
* @see https://github.com/facebook/react/blob/148f8e497c7d37a3c7ab99f01dec2692427272b1/packages/react-dom/src/client/inputValueTracking.js#L51-L104
|
|
11
|
+
*/
|
|
12
|
+
applyNative?: boolean;
|
|
13
|
+
realArgs?: ImplReturn<ElementType[PropName]>;
|
|
14
|
+
}): void;
|
|
5
15
|
export {};
|
|
@@ -8,16 +8,19 @@ const Interceptor = Symbol('Interceptor for programmatical calls');
|
|
|
8
8
|
|
|
9
9
|
function prepareInterceptor(element, propName, interceptorImpl) {
|
|
10
10
|
const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
11
|
+
const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
11
12
|
const target = prototypeDescriptor != null && prototypeDescriptor.set ? 'set' : 'value';
|
|
12
13
|
|
|
13
14
|
if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== 'function' || prototypeDescriptor[target][Interceptor]) {
|
|
14
15
|
return;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
const realFunc = prototypeDescriptor[target];
|
|
18
|
-
|
|
19
18
|
function intercept(...args) {
|
|
20
|
-
const
|
|
19
|
+
const {
|
|
20
|
+
applyNative = true,
|
|
21
|
+
realArgs
|
|
22
|
+
} = interceptorImpl.call(this, ...args);
|
|
23
|
+
const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
|
|
21
24
|
|
|
22
25
|
if (target === 'set') {
|
|
23
26
|
realFunc.call(this, realArgs);
|
|
@@ -28,7 +31,7 @@ function prepareInterceptor(element, propName, interceptorImpl) {
|
|
|
28
31
|
|
|
29
32
|
;
|
|
30
33
|
intercept[Interceptor] = Interceptor;
|
|
31
|
-
Object.defineProperty(element
|
|
34
|
+
Object.defineProperty(element, propName, { ...(objectDescriptor != null ? objectDescriptor : prototypeDescriptor),
|
|
32
35
|
[target]: intercept
|
|
33
36
|
});
|
|
34
37
|
}
|
|
@@ -14,5 +14,4 @@ export declare function getUISelection(element: HTMLInputElement | HTMLTextAreaE
|
|
|
14
14
|
selectionEnd: number | null;
|
|
15
15
|
};
|
|
16
16
|
export declare function clearUISelection(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
17
|
-
export declare function hasUISelection(element: HTMLInputElement | HTMLTextAreaElement): boolean;
|
|
18
17
|
export {};
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.clearUISelection = clearUISelection;
|
|
7
7
|
exports.getUISelection = getUISelection;
|
|
8
|
-
exports.hasUISelection = hasUISelection;
|
|
9
8
|
exports.prepareSelectionInterceptor = prepareSelectionInterceptor;
|
|
10
9
|
exports.setUISelection = setUISelection;
|
|
11
10
|
|
|
@@ -13,17 +12,29 @@ var _interceptor = require("./interceptor");
|
|
|
13
12
|
|
|
14
13
|
const UISelection = Symbol('Displayed selection in UI');
|
|
15
14
|
|
|
16
|
-
function setSelectionInterceptor(start, end, direction = 'none') {
|
|
17
|
-
const isUI = start && typeof start === 'object' && start[UISelection];
|
|
18
|
-
this[UISelection] = isUI ? {
|
|
19
|
-
start: start.valueOf(),
|
|
20
|
-
end: Number(end)
|
|
21
|
-
} : undefined;
|
|
22
|
-
return [Number(start), end, direction];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
15
|
function prepareSelectionInterceptor(element) {
|
|
26
|
-
(0, _interceptor.prepareInterceptor)(element, 'setSelectionRange',
|
|
16
|
+
(0, _interceptor.prepareInterceptor)(element, 'setSelectionRange', function interceptorImpl(start, end, direction = 'none') {
|
|
17
|
+
const isUI = start && typeof start === 'object' && start[UISelection];
|
|
18
|
+
this[UISelection] = isUI ? {
|
|
19
|
+
start: start.valueOf(),
|
|
20
|
+
end: Number(end)
|
|
21
|
+
} : undefined;
|
|
22
|
+
return {
|
|
23
|
+
realArgs: [Number(start), end, direction]
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
(0, _interceptor.prepareInterceptor)(element, 'selectionStart', function interceptorImpl(v) {
|
|
27
|
+
this[UISelection] = undefined;
|
|
28
|
+
return {
|
|
29
|
+
realArgs: v
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
(0, _interceptor.prepareInterceptor)(element, 'selectionEnd', function interceptorImpl(v) {
|
|
33
|
+
this[UISelection] = undefined;
|
|
34
|
+
return {
|
|
35
|
+
realArgs: v
|
|
36
|
+
};
|
|
37
|
+
});
|
|
27
38
|
}
|
|
28
39
|
|
|
29
40
|
function setUISelection(element, start, end) {
|
|
@@ -60,8 +71,4 @@ function getUISelection(element) {
|
|
|
60
71
|
|
|
61
72
|
function clearUISelection(element) {
|
|
62
73
|
element[UISelection] = undefined;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function hasUISelection(element) {
|
|
66
|
-
return Boolean(element[UISelection]);
|
|
67
74
|
}
|
package/dist/document/value.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
declare const UIValue: unique symbol;
|
|
2
2
|
declare const InitialValue: unique symbol;
|
|
3
|
+
declare const TrackChanges: unique symbol;
|
|
3
4
|
declare global {
|
|
4
5
|
interface Element {
|
|
5
6
|
[UIValue]?: string;
|
|
6
7
|
[InitialValue]?: string;
|
|
8
|
+
[TrackChanges]?: string[];
|
|
7
9
|
}
|
|
8
10
|
}
|
|
9
11
|
export declare function prepareValueInterceptor(element: HTMLInputElement): void;
|
|
@@ -11,4 +13,6 @@ export declare function setUIValue(element: HTMLInputElement | HTMLTextAreaEleme
|
|
|
11
13
|
export declare function getUIValue(element: HTMLInputElement | HTMLTextAreaElement): string | undefined;
|
|
12
14
|
export declare function setInitialValue(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
13
15
|
export declare function getInitialValue(element: HTMLInputElement | HTMLTextAreaElement): string | undefined;
|
|
16
|
+
export declare function startTrackValue(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
17
|
+
export declare function endTrackValue(element: HTMLInputElement | HTMLTextAreaElement): string[] | undefined;
|
|
14
18
|
export {};
|
package/dist/document/value.js
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.endTrackValue = endTrackValue;
|
|
6
7
|
exports.getInitialValue = getInitialValue;
|
|
7
8
|
exports.getUIValue = getUIValue;
|
|
8
9
|
exports.prepareValueInterceptor = prepareValueInterceptor;
|
|
9
10
|
exports.setInitialValue = setInitialValue;
|
|
10
11
|
exports.setUIValue = setUIValue;
|
|
11
|
-
|
|
12
|
-
var _applyNative = require("./applyNative");
|
|
12
|
+
exports.startTrackValue = startTrackValue;
|
|
13
13
|
|
|
14
14
|
var _interceptor = require("./interceptor");
|
|
15
15
|
|
|
@@ -17,19 +17,24 @@ var _selection = require("./selection");
|
|
|
17
17
|
|
|
18
18
|
const UIValue = Symbol('Displayed value in UI');
|
|
19
19
|
const InitialValue = Symbol('Initial value to compare on blur');
|
|
20
|
+
const TrackChanges = Symbol('Track programmatic changes for React workaround');
|
|
20
21
|
|
|
21
22
|
function valueInterceptor(v) {
|
|
22
23
|
const isUI = typeof v === 'object' && v[UIValue];
|
|
23
24
|
this[UIValue] = isUI ? String(v) : undefined;
|
|
24
25
|
|
|
25
26
|
if (!isUI) {
|
|
27
|
+
trackValue(this, String(v));
|
|
26
28
|
this[InitialValue] = String(v); // Programmatically setting the value property
|
|
27
29
|
// moves the cursor to the end of the input.
|
|
28
30
|
|
|
29
31
|
(0, _selection.clearUISelection)(this);
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
return
|
|
34
|
+
return {
|
|
35
|
+
applyNative: !!isUI,
|
|
36
|
+
realArgs: String(v)
|
|
37
|
+
};
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
function prepareValueInterceptor(element) {
|
|
@@ -37,10 +42,10 @@ function prepareValueInterceptor(element) {
|
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
function setUIValue(element, value) {
|
|
40
|
-
|
|
45
|
+
element.value = {
|
|
41
46
|
[UIValue]: UIValue,
|
|
42
47
|
toString: () => value
|
|
43
|
-
}
|
|
48
|
+
};
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
function getUIValue(element) {
|
|
@@ -53,4 +58,20 @@ function setInitialValue(element) {
|
|
|
53
58
|
|
|
54
59
|
function getInitialValue(element) {
|
|
55
60
|
return element[InitialValue];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function startTrackValue(element) {
|
|
64
|
+
element[TrackChanges] = [];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function trackValue(element, v) {
|
|
68
|
+
var _element$TrackChanges;
|
|
69
|
+
|
|
70
|
+
(_element$TrackChanges = element[TrackChanges]) == null ? void 0 : _element$TrackChanges.push(v);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function endTrackValue(element) {
|
|
74
|
+
const tracked = element[TrackChanges];
|
|
75
|
+
element[TrackChanges] = undefined;
|
|
76
|
+
return tracked;
|
|
56
77
|
}
|
package/dist/keyboard/keyMap.js
CHANGED
|
@@ -129,7 +129,9 @@ function keydown(keyDef, getCurrentElement, options, state) {
|
|
|
129
129
|
function keypress(keyDef, getCurrentElement, options, state) {
|
|
130
130
|
const element = getCurrentElement();
|
|
131
131
|
|
|
132
|
-
const unpreventedDefault = _dom.fireEvent.keyPress(element, (0, _getEventProps.getKeyEventProps)(keyDef, state)
|
|
132
|
+
const unpreventedDefault = _dom.fireEvent.keyPress(element, { ...(0, _getEventProps.getKeyEventProps)(keyDef, state),
|
|
133
|
+
charCode: keyDef.key === 'Enter' ? 13 : String(keyDef.key).charCodeAt(0)
|
|
134
|
+
});
|
|
133
135
|
|
|
134
136
|
if (unpreventedDefault) {
|
|
135
137
|
applyPlugins(plugins.keypressBehavior, keyDef, getCurrentElement(), options, state);
|
|
@@ -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");
|
|
@@ -65,6 +67,21 @@ const keydownBehavior = [{
|
|
|
65
67
|
}
|
|
66
68
|
});
|
|
67
69
|
}
|
|
70
|
+
}, {
|
|
71
|
+
matches: keyDef => keyDef.key === 'Tab',
|
|
72
|
+
handle: (keyDef, element, options, state) => {
|
|
73
|
+
const dest = (0, _utils.getTabDestination)(element, state.modifiers.shift);
|
|
74
|
+
|
|
75
|
+
if (dest === element.ownerDocument.body) {
|
|
76
|
+
(0, _utils.blur)(element);
|
|
77
|
+
} else {
|
|
78
|
+
(0, _utils.focus)(dest);
|
|
79
|
+
|
|
80
|
+
if ((0, _utils.isElementType)(dest, ['input', 'textarea'])) {
|
|
81
|
+
(0, _document.setUISelection)(dest, 0, dest.value.length);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
68
85
|
}];
|
|
69
86
|
exports.keydownBehavior = keydownBehavior;
|
|
70
87
|
const keypressBehavior = [{
|
|
@@ -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
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { inputDeviceState, PointerTarget } from './types';
|
|
2
|
-
export interface PointerMoveAction extends PointerTarget {
|
|
1
|
+
import { inputDeviceState, PointerTarget, SelectionTarget } from './types';
|
|
2
|
+
export interface PointerMoveAction extends PointerTarget, SelectionTarget {
|
|
3
3
|
pointerName?: string;
|
|
4
4
|
}
|
|
5
|
-
export declare function pointerMove({ pointerName, target, coords }: PointerMoveAction, { pointerState, keyboardState }: inputDeviceState): Promise<void>;
|
|
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,34 @@ async function pointerMove({
|
|
|
52
57
|
|
|
53
58
|
fireMove(target, coords);
|
|
54
59
|
|
|
60
|
+
if (selectionRange) {
|
|
61
|
+
const selectionFocus = (0, _resolveSelectionTarget.resolveSelectionTarget)({
|
|
62
|
+
target,
|
|
63
|
+
node,
|
|
64
|
+
offset
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
if ('node' in selectionRange && selectionFocus.node === selectionRange.node) {
|
|
68
|
+
(0, _document.setUISelection)(selectionRange.node, Math.min(selectionRange.start, selectionFocus.offset), Math.max(selectionRange.end, selectionFocus.offset));
|
|
69
|
+
} else
|
|
70
|
+
/* istanbul ignore else */
|
|
71
|
+
if ('setEnd' in selectionRange) {
|
|
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
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
const selection = target.ownerDocument.getSelection();
|
|
83
|
+
selection.removeAllRanges();
|
|
84
|
+
selection.addRange(range.cloneRange());
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
55
88
|
function fireMove(eventTarget, eventCoords) {
|
|
56
89
|
fire(eventTarget, 'pointermove', eventCoords);
|
|
57
90
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { inputDeviceState, pointerKey, PointerTarget } from './types';
|
|
2
|
-
export interface PointerPressAction extends PointerTarget {
|
|
1
|
+
import type { inputDeviceState, pointerKey, PointerTarget, SelectionTarget } from './types';
|
|
2
|
+
export interface PointerPressAction extends PointerTarget, SelectionTarget {
|
|
3
3
|
keyDef: pointerKey;
|
|
4
4
|
releasePrevious: boolean;
|
|
5
5
|
releaseSelf: boolean;
|
|
6
6
|
}
|
|
7
|
-
export declare function pointerPress(
|
|
7
|
+
export declare function pointerPress(action: PointerPressAction, state: inputDeviceState): Promise<void>;
|