1
1
/* eslint-disable complexity */
2
2
3
3
import {
4
+ ApiLevel ,
5
+ assertPointerEvents ,
4
6
findClosest ,
5
7
firePointerEvent ,
6
8
focus ,
7
9
isDisabled ,
8
10
isElementType ,
9
11
isFocusable ,
12
+ setLevelRef ,
10
13
} from '../utils'
11
14
import { getUIValue , setUISelection } from '../document'
12
- import { inputDeviceState } from '../setup'
15
+ import { Config } from '../setup'
13
16
import type {
14
17
pointerKey ,
15
18
pointerState ,
@@ -25,26 +28,26 @@ export interface PointerPressAction extends PointerTarget, SelectionTarget {
25
28
}
26
29
27
30
export async function pointerPress (
31
+ config : Config ,
28
32
action : PointerPressAction ,
29
- state : inputDeviceState ,
30
33
) : Promise < void > {
31
34
const { keyDef, target, releasePrevious, releaseSelf} = action
32
- const previous = state . pointerState . pressed . find ( p => p . keyDef === keyDef )
35
+ const previous = config . pointerState . pressed . find ( p => p . keyDef === keyDef )
33
36
34
37
const pointerName =
35
38
keyDef . pointerType === 'touch' ? keyDef . name : keyDef . pointerType
36
39
37
40
const targetIsDisabled = isDisabled ( target )
38
41
39
42
if ( previous ) {
40
- up ( state , pointerName , action , previous , targetIsDisabled )
43
+ up ( config , pointerName , action , previous , targetIsDisabled )
41
44
}
42
45
43
46
if ( ! releasePrevious ) {
44
- const press = down ( state , pointerName , action , targetIsDisabled )
47
+ const press = down ( config , pointerName , action , targetIsDisabled )
45
48
46
49
if ( releaseSelf ) {
47
- up ( state , pointerName , action , press , targetIsDisabled )
50
+ up ( config , pointerName , action , press , targetIsDisabled )
48
51
}
49
52
}
50
53
}
@@ -55,11 +58,15 @@ function getNextPointerId(state: pointerState) {
55
58
}
56
59
57
60
function down (
58
- { pointerState , keyboardState } : inputDeviceState ,
61
+ config : Config ,
59
62
pointerName : string ,
60
63
{ keyDef, node, offset, target, coords} : PointerPressAction ,
61
64
targetIsDisabled : boolean ,
62
65
) {
66
+ setLevelRef ( config , ApiLevel . Trigger )
67
+ assertPointerEvents ( config , target )
68
+
69
+ const { pointerState, keyboardState} = config
63
70
const { name, pointerType, button} = keyDef
64
71
const pointerId = pointerType === 'mouse' ? 1 : getNextPointerId ( pointerState )
65
72
@@ -155,7 +162,7 @@ function down(
155
162
}
156
163
157
164
function up (
158
- { pointerState , keyboardState } : inputDeviceState ,
165
+ config : Config ,
159
166
pointerName : string ,
160
167
{
161
168
keyDef : { pointerType, button} ,
@@ -167,6 +174,10 @@ function up(
167
174
pressed : pointerState [ 'pressed' ] [ number ] ,
168
175
targetIsDisabled : boolean ,
169
176
) {
177
+ setLevelRef ( config , ApiLevel . Trigger )
178
+ assertPointerEvents ( config , target )
179
+
180
+ const { pointerState, keyboardState} = config
170
181
pointerState . pressed = pointerState . pressed . filter ( p => p !== pressed )
171
182
172
183
const { isMultiTouch, isPrimary, pointerId, clickCount} = pressed
0 commit comments