@testing-library/user-event 14.0.0-alpha.8 → 14.0.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -192
- package/dist/index.cjs +2864 -0
- package/dist/index.mjs +2935 -0
- package/dist/types/clipboard/copy.d.ts +2 -0
- package/dist/types/clipboard/cut.d.ts +2 -0
- package/dist/types/clipboard/index.d.ts +3 -0
- package/dist/types/clipboard/paste.d.ts +2 -0
- package/dist/types/convenience/click.d.ts +4 -0
- package/dist/types/convenience/hover.d.ts +3 -0
- package/dist/types/convenience/index.d.ts +3 -0
- package/dist/types/convenience/tab.d.ts +4 -0
- package/dist/{document → types/document}/index.d.ts +0 -0
- package/dist/{document → types/document}/interceptor.d.ts +0 -0
- package/dist/{document → types/document}/selection.d.ts +0 -0
- package/dist/{document → types/document}/value.d.ts +0 -0
- package/dist/types/event/behavior/click.d.ts +1 -0
- package/dist/types/event/behavior/index.d.ts +6 -0
- package/dist/types/event/behavior/keydown.d.ts +1 -0
- package/dist/types/event/behavior/keypress.d.ts +1 -0
- package/dist/types/event/behavior/keyup.d.ts +1 -0
- package/dist/types/event/behavior/registry.d.ts +9 -0
- package/dist/types/event/createEvent.d.ts +8 -0
- package/dist/types/event/dispatchEvent.d.ts +2 -0
- package/dist/types/event/eventMap.d.ts +342 -0
- package/dist/types/event/eventTypes.d.ts +2 -0
- package/dist/types/event/index.d.ts +6 -0
- package/dist/types/event/types.d.ts +13 -0
- package/dist/types/event/wrapEvent.d.ts +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/keyboard/index.d.ts +7 -0
- package/dist/{keyboard → types/keyboard}/keyMap.d.ts +0 -0
- package/dist/types/keyboard/keyboardAction.d.ts +10 -0
- package/dist/types/keyboard/modifiers.d.ts +9 -0
- package/dist/{keyboard/getNextKeyDef.d.ts → types/keyboard/parseKeyDef.d.ts} +4 -6
- package/dist/{keyboard → types/keyboard}/types.d.ts +19 -26
- package/dist/types/options.d.ts +117 -0
- package/dist/types/pointer/firePointerEvents.d.ts +11 -0
- package/dist/types/pointer/index.d.ts +10 -0
- package/dist/{pointer → types/pointer}/keyMap.d.ts +0 -0
- package/dist/types/pointer/parseKeyDef.d.ts +6 -0
- package/dist/{pointer → types/pointer}/pointerAction.d.ts +3 -2
- package/dist/types/pointer/pointerMove.d.ts +6 -0
- package/dist/types/pointer/pointerPress.d.ts +8 -0
- package/dist/{pointer → types/pointer}/resolveSelectionTarget.d.ts +0 -0
- package/dist/{pointer → types/pointer}/types.d.ts +2 -12
- package/dist/types/setup/api.d.ts +5 -0
- package/dist/types/setup/config.d.ts +10 -0
- package/dist/types/setup/directApi.d.ts +19 -0
- package/dist/types/setup/index.d.ts +36 -0
- package/dist/types/setup/setup.d.ts +20 -0
- package/dist/types/setup/wrapAsync.d.ts +4 -0
- package/dist/types/utility/clear.d.ts +2 -0
- package/dist/types/utility/index.d.ts +4 -0
- package/dist/types/utility/selectOptions.d.ts +3 -0
- package/dist/types/utility/type.d.ts +9 -0
- package/dist/types/utility/upload.d.ts +5 -0
- package/dist/{utils → types/utils}/click/isClickableInput.d.ts +0 -0
- package/dist/types/utils/dataTransfer/Blob.d.ts +1 -0
- package/dist/types/utils/dataTransfer/Clipboard.d.ts +9 -0
- package/dist/types/utils/dataTransfer/DataTransfer.d.ts +2 -0
- package/dist/types/utils/dataTransfer/FileList.d.ts +1 -0
- package/dist/{utils → types/utils}/edit/buildTimeValue.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/getValue.d.ts +0 -0
- package/dist/types/utils/edit/input.d.ts +2 -0
- package/dist/{utils → types/utils}/edit/isContentEditable.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/isEditable.d.ts +0 -0
- package/dist/types/utils/edit/isValidDateOrTimeValue.d.ts +3 -0
- package/dist/{utils → types/utils}/edit/maxLength.d.ts +0 -0
- package/dist/types/utils/edit/setFiles.d.ts +12 -0
- package/dist/{utils → types/utils}/focus/blur.d.ts +0 -0
- package/dist/types/utils/focus/copySelection.d.ts +1 -0
- package/dist/types/utils/focus/cursor.d.ts +9 -0
- package/dist/{utils → types/utils}/focus/focus.d.ts +3 -0
- package/dist/{utils → types/utils}/focus/getActiveElement.d.ts +0 -0
- package/dist/{utils → types/utils}/focus/getTabDestination.d.ts +0 -0
- package/dist/{utils → types/utils}/focus/isFocusable.d.ts +0 -0
- package/dist/{utils → types/utils}/focus/selectAll.d.ts +1 -0
- package/dist/{utils → types/utils}/focus/selection.d.ts +4 -0
- package/dist/{utils → types/utils}/focus/selector.d.ts +0 -0
- package/dist/{utils → types/utils}/index.d.ts +14 -11
- package/dist/{utils → types/utils}/keyDef/readNextDescriptor.d.ts +0 -0
- package/dist/types/utils/keyboard/getKeyEventProps.d.ts +5 -0
- package/dist/types/utils/keyboard/getUIEventModifiers.d.ts +15 -0
- package/dist/types/utils/misc/cloneEvent.d.ts +1 -0
- package/dist/{utils → types/utils}/misc/eventWrapper.d.ts +0 -0
- package/dist/types/utils/misc/findClosest.d.ts +1 -0
- package/dist/types/utils/misc/getDocumentFromNode.d.ts +1 -0
- package/dist/{utils → types/utils}/misc/isDescendantOrSelf.d.ts +0 -0
- package/dist/{utils → types/utils}/misc/isDisabled.d.ts +0 -0
- package/dist/{utils → types/utils}/misc/isElementType.d.ts +0 -0
- package/dist/{utils → types/utils}/misc/isVisible.d.ts +0 -0
- package/dist/types/utils/misc/level.d.ts +17 -0
- package/dist/{utils → types/utils}/misc/wait.d.ts +0 -0
- package/dist/types/utils/pointer/cssPointerEvents.d.ts +15 -0
- package/dist/{utils → types/utils}/pointer/mouseButtons.d.ts +0 -0
- package/package.json +13 -30
- package/CHANGELOG.md +0 -5
- package/dist/clear.d.ts +0 -2
- package/dist/clear.js +0 -46
- package/dist/click.d.ts +0 -9
- package/dist/click.js +0 -62
- package/dist/document/index.js +0 -100
- package/dist/document/interceptor.js +0 -37
- package/dist/document/selection.js +0 -90
- package/dist/document/value.js +0 -77
- package/dist/hover.d.ts +0 -4
- package/dist/hover.js +0 -43
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -22
- package/dist/keyboard/getEventProps.d.ts +0 -17
- package/dist/keyboard/getEventProps.js +0 -33
- package/dist/keyboard/getNextKeyDef.js +0 -85
- package/dist/keyboard/index.d.ts +0 -19
- package/dist/keyboard/index.js +0 -78
- package/dist/keyboard/keyMap.js +0 -143
- package/dist/keyboard/keyboardImplementation.d.ts +0 -3
- package/dist/keyboard/keyboardImplementation.js +0 -169
- package/dist/keyboard/plugins/arrow.d.ts +0 -6
- package/dist/keyboard/plugins/arrow.js +0 -28
- package/dist/keyboard/plugins/character.d.ts +0 -5
- package/dist/keyboard/plugins/character.js +0 -166
- package/dist/keyboard/plugins/combination.d.ts +0 -5
- package/dist/keyboard/plugins/combination.js +0 -17
- package/dist/keyboard/plugins/control.d.ts +0 -6
- package/dist/keyboard/plugins/control.js +0 -52
- package/dist/keyboard/plugins/functional.d.ts +0 -11
- package/dist/keyboard/plugins/functional.js +0 -140
- package/dist/keyboard/plugins/index.d.ts +0 -8
- package/dist/keyboard/plugins/index.js +0 -42
- package/dist/keyboard/shared/fireChangeForInputTimeIfValid.d.ts +0 -3
- package/dist/keyboard/shared/fireChangeForInputTimeIfValid.js +0 -20
- package/dist/keyboard/shared/index.d.ts +0 -1
- package/dist/keyboard/shared/index.js +0 -18
- package/dist/keyboard/specialCharMap.d.ts +0 -22
- package/dist/keyboard/specialCharMap.js +0 -30
- package/dist/keyboard/types.js +0 -19
- package/dist/paste.d.ts +0 -7
- package/dist/paste.js +0 -60
- package/dist/pointer/index.d.ts +0 -18
- package/dist/pointer/index.js +0 -90
- package/dist/pointer/keyMap.js +0 -29
- package/dist/pointer/parseKeyDef.d.ts +0 -6
- package/dist/pointer/parseKeyDef.js +0 -36
- package/dist/pointer/pointerAction.js +0 -52
- package/dist/pointer/pointerMove.d.ts +0 -5
- package/dist/pointer/pointerMove.js +0 -136
- package/dist/pointer/pointerPress.d.ts +0 -7
- package/dist/pointer/pointerPress.js +0 -330
- package/dist/pointer/resolveSelectionTarget.js +0 -75
- package/dist/pointer/types.js +0 -1
- package/dist/selectOptions.d.ts +0 -4
- package/dist/selectOptions.js +0 -142
- package/dist/setup.d.ts +0 -92
- package/dist/setup.js +0 -203
- package/dist/tab.d.ts +0 -5
- package/dist/tab.js +0 -12
- package/dist/type.d.ts +0 -14
- package/dist/type.js +0 -74
- package/dist/upload.d.ts +0 -10
- package/dist/upload.js +0 -92
- package/dist/utils/click/isClickableInput.js +0 -14
- package/dist/utils/edit/buildTimeValue.js +0 -44
- package/dist/utils/edit/calculateNewValue.d.ts +0 -16
- package/dist/utils/edit/calculateNewValue.js +0 -50
- package/dist/utils/edit/fireInputEvent.d.ts +0 -11
- package/dist/utils/edit/fireInputEvent.js +0 -65
- package/dist/utils/edit/getValue.js +0 -23
- package/dist/utils/edit/isContentEditable.js +0 -25
- package/dist/utils/edit/isEditable.js +0 -42
- package/dist/utils/edit/isValidDateValue.d.ts +0 -3
- package/dist/utils/edit/isValidDateValue.js +0 -12
- package/dist/utils/edit/isValidInputTimeValue.d.ts +0 -3
- package/dist/utils/edit/isValidInputTimeValue.js +0 -12
- package/dist/utils/edit/maxLength.js +0 -50
- package/dist/utils/edit/prepareInput.d.ts +0 -4
- package/dist/utils/edit/prepareInput.js +0 -60
- package/dist/utils/focus/blur.js +0 -19
- package/dist/utils/focus/focus.js +0 -22
- package/dist/utils/focus/getActiveElement.js +0 -26
- package/dist/utils/focus/getTabDestination.js +0 -71
- package/dist/utils/focus/isFocusable.js +0 -12
- package/dist/utils/focus/selectAll.js +0 -38
- package/dist/utils/focus/selection.js +0 -190
- package/dist/utils/focus/selector.js +0 -8
- package/dist/utils/index.js +0 -421
- package/dist/utils/keyDef/readNextDescriptor.js +0 -102
- package/dist/utils/misc/eventWrapper.js +0 -16
- package/dist/utils/misc/findClosest.d.ts +0 -1
- package/dist/utils/misc/findClosest.js +0 -20
- package/dist/utils/misc/hasFormSubmit.d.ts +0 -1
- package/dist/utils/misc/hasFormSubmit.js +0 -10
- package/dist/utils/misc/hasPointerEvents.d.ts +0 -15
- package/dist/utils/misc/hasPointerEvents.js +0 -24
- package/dist/utils/misc/isDescendantOrSelf.js +0 -20
- package/dist/utils/misc/isDisabled.js +0 -12
- package/dist/utils/misc/isElementType.js +0 -24
- package/dist/utils/misc/isVisible.js +0 -24
- package/dist/utils/misc/wait.js +0 -10
- package/dist/utils/pointer/fakeEvent.d.ts +0 -20
- package/dist/utils/pointer/fakeEvent.js +0 -91
- package/dist/utils/pointer/firePointerEvents.d.ts +0 -14
- package/dist/utils/pointer/firePointerEvents.js +0 -55
- package/dist/utils/pointer/mouseButtons.js +0 -45
package/dist/pointer/index.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createPointerState = createPointerState;
|
|
7
|
-
exports.pointer = pointer;
|
|
8
|
-
exports.pointerImplementationWrapper = pointerImplementationWrapper;
|
|
9
|
-
|
|
10
|
-
var _dom = require("@testing-library/dom");
|
|
11
|
-
|
|
12
|
-
var _keyboard = require("../keyboard");
|
|
13
|
-
|
|
14
|
-
var _parseKeyDef = require("./parseKeyDef");
|
|
15
|
-
|
|
16
|
-
var _keyMap = require("./keyMap");
|
|
17
|
-
|
|
18
|
-
var _pointerAction = require("./pointerAction");
|
|
19
|
-
|
|
20
|
-
function pointer(input, options = {}) {
|
|
21
|
-
var _options$delay;
|
|
22
|
-
|
|
23
|
-
const {
|
|
24
|
-
promise,
|
|
25
|
-
pointerState
|
|
26
|
-
} = pointerImplementationWrapper(input, options);
|
|
27
|
-
|
|
28
|
-
if (((_options$delay = options.delay) != null ? _options$delay : 0) > 0) {
|
|
29
|
-
return (0, _dom.getConfig)().asyncWrapper(() => promise.then(() => pointerState));
|
|
30
|
-
} else {
|
|
31
|
-
// prevent users from dealing with UnhandledPromiseRejectionWarning in sync call
|
|
32
|
-
promise.catch(console.error);
|
|
33
|
-
return pointerState;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function pointerImplementationWrapper(input, config) {
|
|
38
|
-
const {
|
|
39
|
-
pointerState = createPointerState(),
|
|
40
|
-
keyboardState = (0, _keyboard.createKeyboardState)(),
|
|
41
|
-
delay = 0,
|
|
42
|
-
pointerMap = _keyMap.defaultKeyMap
|
|
43
|
-
} = config;
|
|
44
|
-
const options = {
|
|
45
|
-
delay,
|
|
46
|
-
pointerMap
|
|
47
|
-
};
|
|
48
|
-
const actions = [];
|
|
49
|
-
(Array.isArray(input) ? input : [input]).forEach(actionInput => {
|
|
50
|
-
if (typeof actionInput === 'string') {
|
|
51
|
-
actions.push(...(0, _parseKeyDef.parseKeyDef)(actionInput, options));
|
|
52
|
-
} else if ('keys' in actionInput) {
|
|
53
|
-
actions.push(...(0, _parseKeyDef.parseKeyDef)(actionInput.keys, options).map(i => ({ ...actionInput,
|
|
54
|
-
...i
|
|
55
|
-
})));
|
|
56
|
-
} else {
|
|
57
|
-
actions.push(actionInput);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
return {
|
|
61
|
-
promise: (0, _pointerAction.pointerAction)(actions, options, {
|
|
62
|
-
pointerState,
|
|
63
|
-
keyboardState
|
|
64
|
-
}),
|
|
65
|
-
pointerState
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function createPointerState() {
|
|
70
|
-
return {
|
|
71
|
-
pointerId: 1,
|
|
72
|
-
position: {
|
|
73
|
-
mouse: {
|
|
74
|
-
pointerType: 'mouse',
|
|
75
|
-
pointerId: 1,
|
|
76
|
-
coords: {
|
|
77
|
-
clientX: 0,
|
|
78
|
-
clientY: 0,
|
|
79
|
-
offsetX: 0,
|
|
80
|
-
offsetY: 0,
|
|
81
|
-
pageX: 0,
|
|
82
|
-
pageY: 0,
|
|
83
|
-
x: 0,
|
|
84
|
-
y: 0
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
pressed: []
|
|
89
|
-
};
|
|
90
|
-
}
|
package/dist/pointer/keyMap.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.defaultKeyMap = void 0;
|
|
7
|
-
const defaultKeyMap = [{
|
|
8
|
-
name: 'MouseLeft',
|
|
9
|
-
pointerType: 'mouse',
|
|
10
|
-
button: 'primary'
|
|
11
|
-
}, {
|
|
12
|
-
name: 'MouseRight',
|
|
13
|
-
pointerType: 'mouse',
|
|
14
|
-
button: 'secondary'
|
|
15
|
-
}, {
|
|
16
|
-
name: 'MouseMiddle',
|
|
17
|
-
pointerType: 'mouse',
|
|
18
|
-
button: 'auxiliary'
|
|
19
|
-
}, {
|
|
20
|
-
name: 'TouchA',
|
|
21
|
-
pointerType: 'touch'
|
|
22
|
-
}, {
|
|
23
|
-
name: 'TouchB',
|
|
24
|
-
pointerType: 'touch'
|
|
25
|
-
}, {
|
|
26
|
-
name: 'TouchC',
|
|
27
|
-
pointerType: 'touch'
|
|
28
|
-
}];
|
|
29
|
-
exports.defaultKeyMap = defaultKeyMap;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.parseKeyDef = parseKeyDef;
|
|
7
|
-
|
|
8
|
-
var _utils = require("../utils");
|
|
9
|
-
|
|
10
|
-
function parseKeyDef(keys, {
|
|
11
|
-
pointerMap
|
|
12
|
-
}) {
|
|
13
|
-
const defs = [];
|
|
14
|
-
|
|
15
|
-
do {
|
|
16
|
-
const {
|
|
17
|
-
descriptor,
|
|
18
|
-
consumedLength,
|
|
19
|
-
releasePrevious,
|
|
20
|
-
releaseSelf = true
|
|
21
|
-
} = (0, _utils.readNextDescriptor)(keys);
|
|
22
|
-
const keyDef = pointerMap.find(p => p.name === descriptor);
|
|
23
|
-
|
|
24
|
-
if (keyDef) {
|
|
25
|
-
defs.push({
|
|
26
|
-
keyDef,
|
|
27
|
-
releasePrevious,
|
|
28
|
-
releaseSelf
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
keys = keys.slice(consumedLength);
|
|
33
|
-
} while (keys);
|
|
34
|
-
|
|
35
|
-
return defs;
|
|
36
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.pointerAction = pointerAction;
|
|
7
|
-
|
|
8
|
-
var _utils = require("../utils");
|
|
9
|
-
|
|
10
|
-
var _pointerMove = require("./pointerMove");
|
|
11
|
-
|
|
12
|
-
var _pointerPress = require("./pointerPress");
|
|
13
|
-
|
|
14
|
-
async function pointerAction(actions, options, state) {
|
|
15
|
-
const ret = [];
|
|
16
|
-
|
|
17
|
-
for (let i = 0; i < actions.length; i++) {
|
|
18
|
-
var _action$target, _action$coords;
|
|
19
|
-
|
|
20
|
-
const action = actions[i];
|
|
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
|
-
const target = (_action$target = action.target) != null ? _action$target : getPrevTarget(pointerName, state.pointerState);
|
|
23
|
-
const coords = (_action$coords = action.coords) != null ? _action$coords : pointerName in state.pointerState.position ? state.pointerState.position[pointerName].coords : undefined;
|
|
24
|
-
const promise = 'keyDef' in action ? (0, _pointerPress.pointerPress)({ ...action,
|
|
25
|
-
target,
|
|
26
|
-
coords
|
|
27
|
-
}, state) : (0, _pointerMove.pointerMove)({ ...action,
|
|
28
|
-
target,
|
|
29
|
-
coords
|
|
30
|
-
}, state);
|
|
31
|
-
ret.push(promise);
|
|
32
|
-
|
|
33
|
-
if (options.delay > 0) {
|
|
34
|
-
await promise;
|
|
35
|
-
|
|
36
|
-
if (i < actions.length - 1) {
|
|
37
|
-
await (0, _utils.wait)(options.delay);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
delete state.pointerState.activeClickCount;
|
|
43
|
-
return Promise.all(ret);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function getPrevTarget(pointerName, state) {
|
|
47
|
-
if (!(pointerName in state.position) || !state.position[pointerName].target) {
|
|
48
|
-
throw new Error('This pointer has no previous position. Provide a target property!');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return state.position[pointerName].target;
|
|
52
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
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>;
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.pointerMove = pointerMove;
|
|
7
|
-
|
|
8
|
-
var _document = require("../document");
|
|
9
|
-
|
|
10
|
-
var _utils = require("../utils");
|
|
11
|
-
|
|
12
|
-
var _resolveSelectionTarget = require("./resolveSelectionTarget");
|
|
13
|
-
|
|
14
|
-
async function pointerMove({
|
|
15
|
-
pointerName = 'mouse',
|
|
16
|
-
target,
|
|
17
|
-
coords,
|
|
18
|
-
node,
|
|
19
|
-
offset
|
|
20
|
-
}, {
|
|
21
|
-
pointerState,
|
|
22
|
-
keyboardState
|
|
23
|
-
}) {
|
|
24
|
-
if (!(pointerName in pointerState.position)) {
|
|
25
|
-
throw new Error(`Trying to move pointer "${pointerName}" which does not exist.`);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const {
|
|
29
|
-
pointerId,
|
|
30
|
-
pointerType,
|
|
31
|
-
target: prevTarget,
|
|
32
|
-
coords: prevCoords,
|
|
33
|
-
selectionRange
|
|
34
|
-
} = pointerState.position[pointerName];
|
|
35
|
-
|
|
36
|
-
if (prevTarget && prevTarget !== target) {
|
|
37
|
-
// Here we could probably calculate a few coords to a fake boundary(?)
|
|
38
|
-
fireMove(prevTarget, prevCoords);
|
|
39
|
-
|
|
40
|
-
if (!(0, _utils.isDescendantOrSelf)(target, prevTarget)) {
|
|
41
|
-
fireLeave(prevTarget, prevCoords);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
pointerState.position[pointerName] = { ...pointerState.position[pointerName],
|
|
46
|
-
target,
|
|
47
|
-
coords
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
if (prevTarget !== target) {
|
|
51
|
-
if (!prevTarget || !(0, _utils.isDescendantOrSelf)(prevTarget, target)) {
|
|
52
|
-
fireEnter(target, coords);
|
|
53
|
-
}
|
|
54
|
-
} // TODO: drag if the target didn't change?
|
|
55
|
-
// Here we could probably calculate a few coords leading up to the final position
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
fireMove(target, coords);
|
|
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
|
-
|
|
99
|
-
function fireMove(eventTarget, eventCoords) {
|
|
100
|
-
fire(eventTarget, 'pointermove', eventCoords);
|
|
101
|
-
|
|
102
|
-
if (pointerType === 'mouse' && !(0, _utils.isDisabled)(eventTarget)) {
|
|
103
|
-
fire(eventTarget, 'mousemove', eventCoords);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function fireLeave(eventTarget, eventCoords) {
|
|
108
|
-
fire(eventTarget, 'pointerout', eventCoords);
|
|
109
|
-
fire(eventTarget, 'pointerleave', eventCoords);
|
|
110
|
-
|
|
111
|
-
if (pointerType === 'mouse' && !(0, _utils.isDisabled)(eventTarget)) {
|
|
112
|
-
fire(eventTarget, 'mouseout', eventCoords);
|
|
113
|
-
fire(eventTarget, 'mouseleave', eventCoords);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function fireEnter(eventTarget, eventCoords) {
|
|
118
|
-
fire(eventTarget, 'pointerover', eventCoords);
|
|
119
|
-
fire(eventTarget, 'pointerenter', eventCoords);
|
|
120
|
-
|
|
121
|
-
if (pointerType === 'mouse' && !(0, _utils.isDisabled)(eventTarget)) {
|
|
122
|
-
fire(eventTarget, 'mouseover', eventCoords);
|
|
123
|
-
fire(eventTarget, 'mouseenter', eventCoords);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function fire(eventTarget, type, eventCoords) {
|
|
128
|
-
return (0, _utils.firePointerEvent)(eventTarget, type, {
|
|
129
|
-
pointerState,
|
|
130
|
-
keyboardState,
|
|
131
|
-
coords: eventCoords,
|
|
132
|
-
pointerId,
|
|
133
|
-
pointerType
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
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>;
|
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.pointerPress = pointerPress;
|
|
7
|
-
|
|
8
|
-
var _dom = require("@testing-library/dom");
|
|
9
|
-
|
|
10
|
-
var _utils = require("../utils");
|
|
11
|
-
|
|
12
|
-
var _document = require("../document");
|
|
13
|
-
|
|
14
|
-
var _resolveSelectionTarget = require("./resolveSelectionTarget");
|
|
15
|
-
|
|
16
|
-
/* eslint-disable complexity */
|
|
17
|
-
async function pointerPress(action, state) {
|
|
18
|
-
const {
|
|
19
|
-
keyDef,
|
|
20
|
-
target,
|
|
21
|
-
releasePrevious,
|
|
22
|
-
releaseSelf
|
|
23
|
-
} = action;
|
|
24
|
-
const previous = state.pointerState.pressed.find(p => p.keyDef === keyDef);
|
|
25
|
-
const pointerName = keyDef.pointerType === 'touch' ? keyDef.name : keyDef.pointerType;
|
|
26
|
-
const targetIsDisabled = (0, _utils.isDisabled)(target);
|
|
27
|
-
|
|
28
|
-
if (previous) {
|
|
29
|
-
up(state, pointerName, action, previous, targetIsDisabled);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (!releasePrevious) {
|
|
33
|
-
const press = down(state, pointerName, action, targetIsDisabled);
|
|
34
|
-
|
|
35
|
-
if (releaseSelf) {
|
|
36
|
-
up(state, pointerName, action, press, targetIsDisabled);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function getNextPointerId(state) {
|
|
42
|
-
state.pointerId = state.pointerId + 1;
|
|
43
|
-
return state.pointerId;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function down({
|
|
47
|
-
pointerState,
|
|
48
|
-
keyboardState
|
|
49
|
-
}, pointerName, {
|
|
50
|
-
keyDef,
|
|
51
|
-
node,
|
|
52
|
-
offset,
|
|
53
|
-
target,
|
|
54
|
-
coords
|
|
55
|
-
}, targetIsDisabled) {
|
|
56
|
-
var _pointerState$activeC, _pointerState$activeC2, _pointerState$activeC3;
|
|
57
|
-
|
|
58
|
-
const {
|
|
59
|
-
name,
|
|
60
|
-
pointerType,
|
|
61
|
-
button
|
|
62
|
-
} = keyDef;
|
|
63
|
-
const pointerId = pointerType === 'mouse' ? 1 : getNextPointerId(pointerState);
|
|
64
|
-
pointerState.position[pointerName] = { ...pointerState.position[pointerName],
|
|
65
|
-
pointerId,
|
|
66
|
-
pointerType,
|
|
67
|
-
target,
|
|
68
|
-
coords
|
|
69
|
-
};
|
|
70
|
-
let isMultiTouch = false;
|
|
71
|
-
let isPrimary = true;
|
|
72
|
-
|
|
73
|
-
if (pointerType !== 'mouse') {
|
|
74
|
-
for (const obj of pointerState.pressed) {
|
|
75
|
-
// TODO: test multi device input across browsers
|
|
76
|
-
// istanbul ignore else
|
|
77
|
-
if (obj.keyDef.pointerType === pointerType) {
|
|
78
|
-
obj.isMultiTouch = true;
|
|
79
|
-
isMultiTouch = true;
|
|
80
|
-
isPrimary = false;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (((_pointerState$activeC = pointerState.activeClickCount) == null ? void 0 : _pointerState$activeC[0]) !== name) {
|
|
86
|
-
delete pointerState.activeClickCount;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const clickCount = Number((_pointerState$activeC2 = (_pointerState$activeC3 = pointerState.activeClickCount) == null ? void 0 : _pointerState$activeC3[1]) != null ? _pointerState$activeC2 : 0) + 1;
|
|
90
|
-
pointerState.activeClickCount = [name, clickCount];
|
|
91
|
-
const pressObj = {
|
|
92
|
-
keyDef,
|
|
93
|
-
downTarget: target,
|
|
94
|
-
pointerId,
|
|
95
|
-
unpreventedDefault: true,
|
|
96
|
-
isMultiTouch,
|
|
97
|
-
isPrimary,
|
|
98
|
-
clickCount
|
|
99
|
-
};
|
|
100
|
-
pointerState.pressed.push(pressObj);
|
|
101
|
-
|
|
102
|
-
if (!targetIsDisabled) {
|
|
103
|
-
if (pointerType !== 'mouse') {
|
|
104
|
-
fire('pointerover');
|
|
105
|
-
fire('pointerenter');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (pointerType !== 'mouse' || !pointerState.pressed.some(p => p.keyDef !== keyDef && p.keyDef.pointerType === pointerType)) {
|
|
109
|
-
fire('pointerdown');
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (pointerType === 'mouse') {
|
|
113
|
-
pressObj.unpreventedDefault = fire('mousedown');
|
|
114
|
-
} // TODO: touch...
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (pointerType === 'mouse' && pressObj.unpreventedDefault) {
|
|
119
|
-
mousedownDefaultBehavior({
|
|
120
|
-
target,
|
|
121
|
-
targetIsDisabled,
|
|
122
|
-
clickCount,
|
|
123
|
-
position: pointerState.position[pointerName],
|
|
124
|
-
node,
|
|
125
|
-
offset
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return pressObj;
|
|
130
|
-
|
|
131
|
-
function fire(type) {
|
|
132
|
-
return (0, _utils.firePointerEvent)(target, type, {
|
|
133
|
-
pointerState,
|
|
134
|
-
keyboardState,
|
|
135
|
-
button,
|
|
136
|
-
clickCount,
|
|
137
|
-
coords,
|
|
138
|
-
isPrimary,
|
|
139
|
-
pointerId,
|
|
140
|
-
pointerType
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function up({
|
|
146
|
-
pointerState,
|
|
147
|
-
keyboardState
|
|
148
|
-
}, pointerName, {
|
|
149
|
-
keyDef: {
|
|
150
|
-
pointerType,
|
|
151
|
-
button
|
|
152
|
-
},
|
|
153
|
-
target,
|
|
154
|
-
coords,
|
|
155
|
-
node,
|
|
156
|
-
offset
|
|
157
|
-
}, pressed, targetIsDisabled) {
|
|
158
|
-
pointerState.pressed = pointerState.pressed.filter(p => p !== pressed);
|
|
159
|
-
const {
|
|
160
|
-
isMultiTouch,
|
|
161
|
-
isPrimary,
|
|
162
|
-
pointerId,
|
|
163
|
-
clickCount
|
|
164
|
-
} = pressed;
|
|
165
|
-
let {
|
|
166
|
-
unpreventedDefault
|
|
167
|
-
} = pressed;
|
|
168
|
-
pointerState.position[pointerName] = { ...pointerState.position[pointerName],
|
|
169
|
-
target,
|
|
170
|
-
coords
|
|
171
|
-
}; // TODO: pointerleave for touch device
|
|
172
|
-
|
|
173
|
-
if (!targetIsDisabled) {
|
|
174
|
-
if (pointerType !== 'mouse' || !pointerState.pressed.filter(p => p.keyDef.pointerType === pointerType).length) {
|
|
175
|
-
fire('pointerup');
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (pointerType !== 'mouse') {
|
|
179
|
-
fire('pointerout');
|
|
180
|
-
fire('pointerleave');
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (pointerType !== 'mouse' && !isMultiTouch) {
|
|
184
|
-
if (clickCount === 1) {
|
|
185
|
-
fire('mouseover');
|
|
186
|
-
fire('mouseenter');
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
fire('mousemove');
|
|
190
|
-
unpreventedDefault = fire('mousedown') && unpreventedDefault;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (unpreventedDefault && pointerType !== 'mouse' && !isMultiTouch) {
|
|
195
|
-
mousedownDefaultBehavior({
|
|
196
|
-
target,
|
|
197
|
-
targetIsDisabled,
|
|
198
|
-
clickCount,
|
|
199
|
-
position: pointerState.position[pointerName],
|
|
200
|
-
node,
|
|
201
|
-
offset
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
delete pointerState.position[pointerName].selectionRange;
|
|
206
|
-
|
|
207
|
-
if (!targetIsDisabled) {
|
|
208
|
-
if (pointerType === 'mouse' || !isMultiTouch) {
|
|
209
|
-
unpreventedDefault = fire('mouseup') && unpreventedDefault;
|
|
210
|
-
const canClick = pointerType !== 'mouse' || button === 'primary';
|
|
211
|
-
|
|
212
|
-
if (canClick && target === pressed.downTarget) {
|
|
213
|
-
fire('click');
|
|
214
|
-
|
|
215
|
-
if (clickCount === 2) {
|
|
216
|
-
fire('dblclick');
|
|
217
|
-
} // If the click happens inside a `label` with a control, the control (or closes focusable) is focused.
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const label = target.closest('label');
|
|
221
|
-
|
|
222
|
-
if (label != null && label.control) {
|
|
223
|
-
var _findClosest;
|
|
224
|
-
|
|
225
|
-
(0, _utils.focus)((_findClosest = (0, _utils.findClosest)(label.control, _utils.isFocusable)) != null ? _findClosest : target.ownerDocument.body);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
if (pointerType === 'mouse' && button === 'secondary') {
|
|
230
|
-
_dom.fireEvent.contextMenu(target);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function fire(type) {
|
|
236
|
-
return (0, _utils.firePointerEvent)(target, type, {
|
|
237
|
-
pointerState,
|
|
238
|
-
keyboardState,
|
|
239
|
-
button,
|
|
240
|
-
clickCount,
|
|
241
|
-
coords,
|
|
242
|
-
isPrimary,
|
|
243
|
-
pointerId,
|
|
244
|
-
pointerType
|
|
245
|
-
});
|
|
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];
|
|
330
|
-
}
|