forked from jsx-eslint/eslint-plugin-jsx-a11y
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.d.ts
246 lines (234 loc) · 8.37 KB
/
types.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
declare module 'jsx-ast-utils' {
import type * as ESTree from 'estree';
import type * as ESTreeJSX from 'estree-jsx';
export interface GetPropOptions {
/**
* Ignores casing differences in the prop name. Enabled by default.
* @default true
*/
ignoreCase: boolean;
}
export interface HasPropOptions extends GetPropOptions {
/**
* Assumes target property is not in a spread expression applied
* to the element. For example `<div {...props} />` looking for
* specific prop here will return false if `spreadStrict` is true.
* Enabled by default.
* @default true
*/
spreadStrict: boolean;
}
/** Contains a flat list of common event handler props used in JSX to attach behaviors to DOM events. */
export const eventHandlers: Array<
| 'onCopy'
| 'onCut'
| 'onPaste'
| 'onCompositionEnd'
| 'onCompositionStart'
| 'onCompositionUpdate'
| 'onKeyDown'
| 'onKeyPress'
| 'onKeyUp'
| 'onFocus'
| 'onBlur'
| 'onChange'
| 'onInput'
| 'onSubmit'
| 'onClick'
| 'onContextMenu'
| 'onDblClick'
| 'onDoubleClick'
| 'onDrag'
| 'onDragEnd'
| 'onDragEnter'
| 'onDragExit'
| 'onDragLeave'
| 'onDragOver'
| 'onDragStart'
| 'onDrop'
| 'onMouseDown'
| 'onMouseEnter'
| 'onMouseLeave'
| 'onMouseMove'
| 'onMouseOut'
| 'onMouseOver'
| 'onMouseUp'
| 'onSelect'
| 'onTouchCancel'
| 'onTouchEnd'
| 'onTouchMove'
| 'onTouchStart'
| 'onScroll'
| 'onWheel'
| 'onAbort'
| 'onCanPlay'
| 'onCanPlayThrough'
| 'onDurationChange'
| 'onEmptied'
| 'onEncrypted'
| 'onEnded'
| 'onError'
| 'onLoadedData'
| 'onLoadedMetadata'
| 'onLoadStart'
| 'onPause'
| 'onPlay'
| 'onPlaying'
| 'onProgress'
| 'onRateChange'
| 'onSeeked'
| 'onSeeking'
| 'onStalled'
| 'onSuspend'
| 'onTimeUpdate'
| 'onVolumeChange'
| 'onWaiting'
| 'onLoad'
| 'onError'
| 'onAnimationStart'
| 'onAnimationEnd'
| 'onAnimationIteration'
| 'onTransitionEnd'
>;
/** Contains a list of common event handler props, grouped into types. */
export const eventHandlersByType: {
animation: Array<'onAnimationStart' | 'onAnimationEnd' | 'onAnimationIteration'>;
clipboard: Array<'onCopy' | 'onCut' | 'onPaste'>;
composition: Array<'onCompositionEnd' | 'onCompositionStart' | 'onCompositionUpdate'>;
focus: Array<'onFocus' | 'onBlur'>;
form: Array<'onChange' | 'onInput' | 'onSubmit'>;
image: Array<'onLoad' | 'onError'>;
keyboard: Array<'onKeyDown' | 'onKeyPress' | 'onKeyUp'>;
media: Array<
| 'onAbort'
| 'onCanPlay'
| 'onCanPlayThrough'
| 'onDurationChange'
| 'onEmptied'
| 'onEncrypted'
| 'onEnded'
| 'onError'
| 'onLoadedData'
| 'onLoadedMetadata'
| 'onLoadStart'
| 'onPause'
| 'onPlay'
| 'onPlaying'
| 'onProgress'
| 'onRateChange'
| 'onSeeked'
| 'onSeeking'
| 'onStalled'
| 'onSuspend'
| 'onTimeUpdate'
| 'onVolumeChange'
| 'onWaiting'
>;
mouse: Array<
| 'onClick'
| 'onContextMenu'
| 'onDblClick'
| 'onDoubleClick'
| 'onDrag'
| 'onDragEnd'
| 'onDragEnter'
| 'onDragExit'
| 'onDragLeave'
| 'onDragOver'
| 'onDragStart'
| 'onDrop'
| 'onMouseDown'
| 'onMouseEnter'
| 'onMouseLeave'
| 'onMouseMove'
| 'onMouseOut'
| 'onMouseOver'
| 'onMouseUp'
>;
selection: Array<'onSelect'>;
touch: Array<'onTouchCancel' | 'onTouchEnd' | 'onTouchMove' | 'onTouchStart'>;
transition: Array<'onTransitionEnd'>;
ui: Array<'onScroll'>;
wheel: Array<'onWheel'>;
};
/**
* Returns the tag name associated with a JSXOpeningElement.
* @param node The visited JSXOpeningElement node object.
* @returns The element's tag name.
*/
export function elementType(node: ESTreeJSX.JSXOpeningElement | ESTreeJSX.JSXOpeningFragment): string;
/**
* Returns the value of a given attribute. Different types of attributes have
* their associated values in different properties on the object. This function
* should return a value only if we can extract a literal value from its
* attribute (i.e. values that have generic types in JavaScript including
* strings, numbers, booleans, etc.)
* @param prop The JSXAttribute collected by AST parser.
* @returns The value of the prop.
*/
export function getLiteralPropValue(prop: ESTreeJSX.JSXAttribute): ESTree.Literal['value'];
/**
* Returns the JSXAttribute itself or `undefined`, indicating the prop is not
* present on the JSXOpeningElement.
* @param props The attributes on the visited node (Usually node.attributes).
* @param prop A string representation of the prop you want to retrieve.
* @param options An object representing options for existence checking.
* @returns The JSXAttribute if found, otherwise `undefined`.
*/
export function getProp(
props: ESTreeJSX.JSXOpeningElement['attributes'],
prop: string,
options?: GetPropOptions,
): ESTreeJSX.JSXAttribute | undefined;
/**
* Returns the value of a given attribute. Different types of attributes have
* their associated values in different properties on the object. This function
* should return the most closely associated value with the intention of the JSX.
* @param prop The JSXAttribute collected by AST parser.
* @returns The value of the prop.
*/
export function getPropValue(prop: ESTreeJSX.JSXAttribute): unknown;
/**
* Returns a boolean indicating if ANY of props in prop argument exist on the node.
* @param props The attributes on the visited node (Usually node.attributes).
* @param prop An array of strings representing the props you want to check for existence.
* @param options An object representing options for existence checking.
* @returns A boolean asserting the existence of some of the props.
*/
export function hasAnyProp(
props: ESTreeJSX.JSXOpeningElement['attributes'],
prop: string[],
options?: HasPropOptions,
): boolean;
/**
* Returns a boolean indicating if ALL of props in prop argument exist on the node.
* @param props The attributes on the visited node (Usually node.attributes).
* @param prop An array of strings representing the props you want to check for existence.
* @param options An object representing options for existence checking.
* @returns A boolean asserting the existence of all of the props.
*/
export function hasEveryProp(
props: ESTreeJSX.JSXOpeningElement['attributes'],
prop: string[],
options?: HasPropOptions,
): boolean;
/**
* Returns boolean indicating whether an prop exists as an attribute on a JSX element node.
* @param props The attributes on the visited node (Usually node.attributes).
* @param prop A string representation of the prop you want to check for existence.
* @param options An object representing options for existence checking.
* @returns A boolean asserting the existence of the prop.
*/
export function hasProp(
props: ESTreeJSX.JSXOpeningElement['attributes'],
prop: string,
options?: HasPropOptions,
): boolean;
/**
* Returns the name associated with a JSXAttribute. For example, given `<div foo="bar" />`
* and the JSXAttribute for foo, this will return the string "foo".
* @param prop The JSXAttribute collected by AST parser.
* @returns The name of the attribute.
*/
export function propName(prop: ESTreeJSX.JSXAttribute): string;
}