-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: separate input devices from pointer/keyboard API (#1003)
feat: * **pointer**: dispatch `auxclick` events fix: * **keyboard**: switch modifier state of lock keys on the correct event * **keyboard**: remove platform-specific additional key events for `Control` on `AltGraph` * **pointer**: dispatch `contextmenu` events with `detail: 0` * **pointer**: always set `PointerEvent.isPrimary` * **pointer**: set `button` property on pointer events separately from legacy mouse events * **pointer**: click closest common ancestor if `mousedown` and `mouseup` happen on different elements * **pointer**: omit click event on release if another button is released first * **pointer**: dispatch `mouseover`, `mouseenter` and `mousemove` on disabled elements * **pointer**: prevent `mouse*` events per `pointerdown` event handler * **pointer**: dispatch `*out` and `*over` events when moving into / out of nested elements * **pointer**: dispatch `*enter` and `*leave` events on ancestors
- Loading branch information
1 parent
c6aafb7
commit 2852509
Showing
57 changed files
with
1,562 additions
and
1,304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export {userEvent as default} from './setup' | ||
export type {keyboardKey} from './keyboard' | ||
export type {pointerKey} from './pointer' | ||
export type {keyboardKey} from './system/keyboard' | ||
export type {pointerKey} from './system/pointer' | ||
export {PointerEventsCheckLevel} from './options' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,54 @@ | ||
import {Config, Instance} from '../setup' | ||
import {keyboardAction, KeyboardAction, releaseAllKeys} from './keyboardAction' | ||
import {keyboardKey} from '../system/keyboard' | ||
import {wait} from '../utils' | ||
import {parseKeyDef} from './parseKeyDef' | ||
import type {keyboardState, keyboardKey} from './types' | ||
|
||
export {releaseAllKeys} | ||
export type {keyboardKey, keyboardState} | ||
interface KeyboardAction { | ||
keyDef: keyboardKey | ||
releasePrevious: boolean | ||
releaseSelf: boolean | ||
repeat: number | ||
} | ||
|
||
export async function keyboard(this: Instance, text: string): Promise<void> { | ||
const actions: KeyboardAction[] = parseKeyDef(this[Config].keyboardMap, text) | ||
|
||
return keyboardAction(this[Config], actions) | ||
for (let i = 0; i < actions.length; i++) { | ||
await wait(this[Config]) | ||
|
||
await keyboardAction(this[Config], actions[i]) | ||
} | ||
} | ||
|
||
async function keyboardAction( | ||
config: Config, | ||
{keyDef, releasePrevious, releaseSelf, repeat}: KeyboardAction, | ||
) { | ||
const {system} = config | ||
|
||
// Release the key automatically if it was pressed before. | ||
if (system.keyboard.isKeyPressed(keyDef)) { | ||
await system.keyboard.keyup(config, keyDef) | ||
} | ||
|
||
if (!releasePrevious) { | ||
for (let i = 1; i <= repeat; i++) { | ||
await system.keyboard.keydown(config, keyDef) | ||
|
||
if (i < repeat) { | ||
await wait(config) | ||
} | ||
} | ||
|
||
// Release the key only on the last iteration on `state.repeatKey`. | ||
if (releaseSelf) { | ||
await system.keyboard.keyup(config, keyDef) | ||
} | ||
} | ||
} | ||
|
||
export function createKeyboardState(): keyboardState { | ||
return { | ||
activeElement: null, | ||
pressed: [], | ||
carryChar: '', | ||
modifiers: { | ||
Alt: false, | ||
AltGraph: false, | ||
Control: false, | ||
CapsLock: false, | ||
Fn: false, | ||
FnLock: false, | ||
Meta: false, | ||
NumLock: false, | ||
ScrollLock: false, | ||
Shift: false, | ||
Symbol: false, | ||
SymbolLock: false, | ||
}, | ||
modifierPhase: {}, | ||
export async function releaseAllKeys(config: Config) { | ||
for (const k of config.system.keyboard.getPressedKeys()) { | ||
await config.system.keyboard.keyup(config, k) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.