-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtypes.ts
217 lines (189 loc) · 6.5 KB
/
types.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
import { NavigationAdapterInterface } from "src/navigationAdapter"
export type Locateable = URL | string
export type AddOrRemoveListeners = 'addEventListener' | 'removeEventListener'
export type Submitter = HTMLInputElement | HTMLButtonElement | null | undefined
export interface EventQueryInterface {
event: string
selectors: SelectorType[]
}
export interface AjaxEvent extends CustomEvent, Event {
detail: AjaxEventDetail
}
export interface AjaxEventDetail {
element: HTMLFormElement
fetchRequest: FetchRequestInterface
request: Request
fetchResponse?: FetchResponseInterface
response?: Response
submitter?: Submitter
error?: Error
}
export interface QuerySelectorInterface {
remoteSelector: SelectorType
linkClickSelector: SelectorType
buttonClickSelector: SelectorType
inputChangeSelector: SelectorType
formSubmitSelector: SelectorType
formInputClickSelector: SelectorType
formDisableSelector: SelectorType
formEnableSelector: SelectorType
linkDisableSelector: SelectorType
buttonDisableSelector: SelectorType
fileInputSelector: SelectorType
}
export interface SelectorInterface {
selector: string
exclude: string
}
export type SelectorType = string | SelectorInterface
export interface CustomMimeTypeInterface {
shortcut: string
header: string
}
export interface MimeTypeInterface {
[key: string]: string
}
export interface MrujsPluginInterface {
name: string
initialize?: () => void
connect?: () => void
disconnect?: () => void
observerCallback?: (addedNodes: Node[]) => void
queries?: EventQueryInterface[]
callbacks?: Function[]
}
export interface SnapshotCacheInterface {
size: number
keys: string[]
snapshots: Record<string, unknown>
put: (location: URL, snapshot: string) => void
has: (location: URL) => boolean
[key: string]: unknown
}
export interface ExtendedRequestInit extends RequestInit {
element?: HTMLElement
submitter?: HTMLElement
dispatchEvents?: boolean
}
export interface MrujsInterface extends QuerySelectorInterface {
// From Rails-UJS
['$']: (selector: string) => Element[]
csrfToken: () => string | undefined
csrfParam: () => string | undefined
CSRFProtection: (request: Request) => void
cspNonce: () => string | undefined
disableElement: (event: Event | HTMLFormElement | Submitter) => void
delegate: (element: Element, selector: SelectorType, eventType: string, handler: Function) => void
fire: (element: EventTarget, name: string, options: CustomEventInit) => boolean
enableElement: (trigger: Event | HTMLElement) => void
enableFormElements: (element: HTMLFormElement) => void
enableFormElement: (element: HTMLFormElement) => void
stopEverything: (event: Event) => void
start: (this: MrujsInterface, config?: Partial<MrujsInterface>) => MrujsInterface
confirm: (message: string) => boolean
preventInsignificantClick: (event: MouseEvent) => void
handleConfirm: (event: Event) => void
handleDisabledElement: (this: HTMLFormElement, event: Event) => void
handleMethod: (event: Event) => void
refreshCSRFTokens: () => void
formElements: (form: HTMLElement, selector: SelectorType) => HTMLFormElement[]
matches: (element: Node | Element, selector: SelectorType) => boolean
toArray: <T> (value: any) => T[]
// New fields
FetchResponse: (response: Response) => FetchResponseInterface
FetchRequest: (input: Request | Locateable, options: RequestInit) => FetchRequestInterface
maskLinkMethods: boolean
mimeTypes: MimeTypeInterface
connected: boolean
findSubmitter: (event: ExtendedSubmitEvent) => Submitter | undefined
errorRenderer: ErrorRenderer
corePlugins: MrujsPluginInterface[]
plugins: MrujsPluginInterface[]
allPlugins: MrujsPluginInterface[]
// Core Plugins
addedNodesObserver: MrujsPluginInterface
remoteWatcher: MrujsPluginInterface
elementEnabler: MrujsPluginInterface
elementDisabler: MrujsPluginInterface
disabledElementChecker: MrujsPluginInterface
navigationAdapter: MrujsPluginInterface & NavigationAdapterInterface
clickHandler: MrujsPluginInterface
confirmClass: MrujsPluginInterface
csrf: MrujsPluginInterface
method: MrujsPluginInterface
formSubmitDispatcher: MrujsPluginInterface
// Functions
stop: () => void
fetch: (input: Request | Locateable, options?: ExtendedRequestInit) => undefined | Promise<Response>
prefetch: (url: Locateable) => Promise<void>
restart: () => void
urlEncodeFormData: (formData: FormData) => URLSearchParams
registerMimeTypes: (mimeTypes: CustomMimeTypeInterface[]) => MimeTypeInterface
addListeners: (conditions: EventQueryInterface[], callbacks: EventListener[]) => void
removeListeners: (conditions: EventQueryInterface[], callbacks: EventListener[]) => void
attachObserverCallback: (conditions: EventQueryInterface[], nodeList: Node[], callbacks: EventListener[]) => void
expandUrl: (locateable: Locateable) => URL
dispatch: (this: Node | EventTarget, name: string, options: CustomEventInit) => CustomEvent
}
export interface FetchResponseInterface {
succeeded: boolean
failed: boolean
redirected: boolean
clientError: boolean
serverError: boolean
status: number
location: URL
contentType: string | null
isHtml: boolean
isJson: boolean
response: Response
getHeader: (name: string) => string | null
text: () => Promise<string>
html: () => Promise<string>
json: () => Promise<Record<string, unknown>>
}
export type RequestInfo = Request | string | URL
// https://developer.mozilla.org/en-US/docs/Web/API/Request
export type FetchRequestBody = Blob | BufferSource | FormData | URLSearchParams | ReadableStream | undefined
export interface FetchRequestInterface {
request: Request
method: string
url: URL
body: FetchRequestBody
params: URLSearchParams
abortController: AbortController
abortSignal: AbortSignal
isGetRequest: boolean
cancel: (event?: CustomEvent) => void
headers: Headers
}
export interface Adapter {
visit: (location: Locateable, { action }: { action: VisitAction }) => void
clearCache: () => void
// Turbolinks
supported?: boolean
Snapshot: {
wrap: (str: string) => string
}
controller: {
cache: SnapshotCacheInterface
}
// Turbo
PageSnapshot?: {
fromHTMLString: (str: string) => string
}
navigator: {
view: {
snapshotCache: SnapshotCacheInterface
renderError: (snapshot: string) => string
}
}
}
export type VisitAction = 'advance' | 'replace' | 'restore'
export interface ExtendedSubmitEvent extends CustomEvent {
submitter: Submitter
detail: {
submitter?: Submitter
}
}
export type ErrorRenderer = "turbo" | "morphdom"