1
- // Type definitions for phoenix_live_view 0.14
1
+ // Type definitions for phoenix_live_view 0.15
2
2
// Project: https://github.com/phoenixframework/phoenix_live_view
3
3
// Definitions by: Peter Zingg <https://github.com/pzingg>
4
4
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
5
6
+ // Version 0.15.4 added options and interfaces for LiveView uploads
7
+ // See: https://hexdocs.pm/phoenix_live_view/uploads.html
8
+
6
9
import { Socket , SocketConnectOption } from 'phoenix' ;
7
10
8
11
export interface Defaults {
@@ -32,6 +35,7 @@ export interface SocketOptions {
32
35
hooks ?: object ;
33
36
loaderTimeout ?: number ;
34
37
params ?: object ;
38
+ uploaders ?: object ;
35
39
viewLogger ?: ViewLogger ;
36
40
}
37
41
@@ -42,7 +46,6 @@ export class LiveSocket {
42
46
constructor ( url : string , phxSocket : any , opts : SocketOptions ) ;
43
47
44
48
// public
45
-
46
49
connect ( ) : void ;
47
50
disableDebug ( ) : void ;
48
51
disableLatencySim ( ) : void ;
@@ -54,67 +57,66 @@ export class LiveSocket {
54
57
getLatencySim ( ) : number | null ;
55
58
getSocket ( ) : Socket ;
56
59
isDebugEnabled ( ) : boolean ;
57
- isPhxView ( el : HTMLElement ) : boolean ;
58
60
isProfileEnabled ( ) : boolean ;
59
61
60
62
// private
61
-
62
- // channel(topic: string, params: any): Channel;
63
- // binding(kind: any): string;
64
- // bind(events: any[], callback: BindCallback): void;
63
+ // bind(events: string[], callback: BindCallback): void;
64
+ // bindClick(eventName: string, bindingName: string, capture: boolean): void;
65
65
// bindClicks(): void;
66
66
// bindForms(): void;
67
+ // binding(kind: string): string;
67
68
// bindNav(): void;
68
69
// bindTopLevelEvents(): void;
69
70
// blurActiveElement(): void;
71
+ // channel(topic: string, params: any): Channel;
70
72
// commitPendingLink(linkRef: number): boolean;
71
- // debounce(el: HTMLElement, event: string , callback: any): void;
73
+ // debounce(el: HTMLElement, event: Event , callback: any): void;
72
74
// destroyAllViews(): void;
73
75
// destroyViewByEl(el: HTMLElement): void;
74
76
// dropActiveElement(view: View): void;
75
- // eventMeta(eventName: string, e: any , targetEl: HTMLElement): object;
76
- // getActiveElement(): HTMLElement ;
77
+ // eventMeta(eventName: string, e: Event , targetEl: HTMLElement): object;
78
+ // getActiveElement(): Element ;
77
79
// getBindingPrefix(): string;
78
80
// getHookCallbacks(hookName: string): any;
79
81
// getHref(): string;
80
82
// getRootById(id: string): any;
81
83
// getViewByEl(el: HTMLElement): any;
82
84
// hasPendingLink(): boolean;
83
- // historyPatch(href: string, linkState: any ): void;
84
- // historyRedirect(href: string, linkState: any , flash: any ): void;
85
+ // historyPatch(href: string, linkState: string ): void;
86
+ // historyRedirect(href: string, linkState: string , flash: string ): void;
85
87
// isConnected(): boolean;
88
+ // isPhxView(el: HTMLElement): boolean;
86
89
// isUnloaded(): boolean;
87
- // joinRootView(el: HTMLElement, href: string, flash: any , callback: any ): View;
90
+ // joinRootView(el: HTMLElement, href: string, flash: string , callback: (view: View, joinCount: number) => void ): View;
88
91
// joinRootViews(): boolean;
89
92
// log(view: View, kind: string, msgCallback: () => [any, any]): void;
90
93
// on(event: string, callback: (e: Event) => void): void;
91
- // onChannel(channel: any , event: any , cb: (data: any) => void): void;
94
+ // onChannel(channel: Channel , event: string , cb: (data: any) => void): void;
92
95
// owner(childEl: HTMLElement, callback: (view: View) => void): void;
93
96
// pushHistoryPatch(href: string, linkState: any, targetEl: HTMLElement): void;
94
- // redirect(to: string, flash: any ): void;
97
+ // redirect(to: string, flash: string ): void;
95
98
// registerNewLocation(newLocation: Location): boolean;
96
- // reloadWithJitter(view: any ): void;
97
- // replaceMain(href: string, flash: any , callback?: any, linkRef?: any ): void;
99
+ // reloadWithJitter(view: View ): void;
100
+ // replaceMain(href: string, flash: string , callback?: any, linkRef?: number ): void;
98
101
// replaceRootHistory(): void;
99
102
// restorePreviouslyActiveFocus(): void;
100
- // setActiveElement(target: HTMLElement ): void;
103
+ // setActiveElement(target: Element ): void;
101
104
// setPendingLink(href: string): number;
102
105
// silenceEvents(callback: () => void): void;
103
106
// time(name: string, func: () => any): any;
104
107
// triggerDOM(kind: string, args: any): void;
105
108
// withinOwners(childEl: HTMLElement, callback: (view: View, el: HTMLElement) => void): void;
106
109
// withPageLoading(info: Event, callback: any): any;
107
- // wrapPush(push: any): any;
110
+ // wrapPush(view: View, opts: any, push: () => any): any;
108
111
}
109
112
110
113
export class Rendered {
111
114
constructor ( viewId : string , rendered : any ) ;
112
115
113
116
// public
114
-
115
117
componentCIDs ( diff : any ) : number [ ] ;
116
118
componentToString ( cid : number ) : string ;
117
- expandStatics ( diff : any ) : void ;
119
+ doRecursiveMerge ( target : any , source : any ) : void ;
118
120
getComponent ( diff : any , cid : number ) : any ;
119
121
isComponentOnlyDiff ( diff : any ) : boolean ;
120
122
mergeDiff ( diff : any ) : void ;
@@ -125,7 +127,6 @@ export class Rendered {
125
127
toString ( onlyCids ?: number [ ] ) : string ;
126
128
127
129
// private
128
-
129
130
// comprehensionToBuffer(rendered: any, output: any): void;
130
131
// createSpan(text: string, cid: number): HTMLSpanElement;
131
132
// dynamicToBuffer(rendered: any, output: any): void;
@@ -135,7 +136,7 @@ export class Rendered {
135
136
// toOutputBuffer(rendered: any, output: object): any;
136
137
}
137
138
138
- export interface ViewHookInterface {
139
+ export interface ViewHook {
139
140
el : HTMLElement ;
140
141
viewName : string ;
141
142
pushEvent ( event : string , payload : object , onReply ?: ( reply : any , ref : number ) => any ) : void ;
@@ -153,77 +154,112 @@ export interface ViewHookInterface {
153
154
}
154
155
155
156
export class View {
156
- constructor ( el : HTMLElement , liveSocket : LiveSocket , parentView : View , href : string , o : any ) ;
157
+ constructor ( el : HTMLElement , liveSocket : LiveSocket , parentView : View , href : string , flash : string ) ;
157
158
158
- ackJoin ( child : any ) : void ;
159
+ // public?
160
+ ackJoin ( child : View ) : void ;
159
161
addHook ( el : HTMLElement ) : void ;
160
- applyJoinPatch ( live_patch : any , html : any , events : Array < [ string , object ] > ) : void ;
162
+ applyDiff ( type : string , rawDiff : any , callback : any ) : any ;
163
+ applyJoinPatch ( live_patch : any , html : string , events : Array < [ string , object ] > ) : void ;
161
164
applyPendingUpdates ( ) : void ;
162
165
attachTrueDocEl ( ) : void ;
163
166
bindChannel ( ) : void ;
164
167
binding ( kind : string ) : any ;
168
+ cancelSubmit ( formEl : HTMLElement ) : void ;
165
169
closestComponentID ( targetCtx : object | null ) : number | null ;
166
170
componentID ( el : HTMLElement ) : number | null ;
167
171
componentPatch ( diff : any , cid : number ) : boolean ;
168
172
connectParams ( ) : object ;
169
173
destroy ( callback ?: ( ) => void ) : void ;
170
174
destroyAllChildren ( ) : void ;
171
175
destroyDescendent ( id : string ) : any ;
172
- destroyHook ( hook : ViewHookInterface ) : void ;
173
- displayError ( ) : void ;
176
+ destroyHook ( hook : ViewHook ) : void ;
174
177
dispatchEvents ( events : Array < [ string , object ] > ) : void ;
178
+ displayError ( ) : void ;
175
179
dropPendingRefs ( ) : void ;
176
180
expandURL ( to : string ) : string ;
177
181
extractMeta ( el : HTMLElement , meta : object ) : object ;
178
182
formsForRecovery ( html : string ) : HTMLElement [ ] ;
179
183
getChildById ( id : string ) : any ;
180
184
getDescendentByEl ( el : HTMLElement ) : any ;
181
- getHook ( el : HTMLElement ) : ViewHookInterface ;
182
- getSession ( ) : string ;
185
+ getHook ( el : HTMLElement ) : ViewHook ;
186
+ getScheduledSubmit ( formEl : HTMLElement ) : any ;
187
+ getSession ( ) : any ;
183
188
getStatic ( ) : string | null ;
184
189
hideLoader ( ) : void ;
185
190
isConnected ( ) : boolean ;
186
191
isDestroyed ( ) : boolean ;
187
192
isJoinPending ( ) : boolean ;
188
193
isLoading ( ) : boolean ;
189
194
isMain ( ) : boolean ;
190
- join ( callback ?: ( view : View , joinCount : number ) => void ) : any ;
195
+ join ( callback : any ) : void ;
191
196
joinChild ( el : HTMLElement ) : any ;
192
197
joinNewChildren ( ) : void ;
193
198
log ( kind : string , msgCallback : any ) : void ;
194
199
maybePushComponentsDestroyed ( destroyedCIDs : number [ ] ) : any ;
195
200
name ( ) : string ;
196
201
onAllChildJoinsComplete ( ) : void ;
197
202
onChannel ( event : string , cb : ( resp : any ) => void ) : void ;
198
- onClose ( ) : void ;
199
- onError ( reason : any ) : void ;
203
+ onClose ( reason : string ) : void ;
204
+ onError ( reason : string ) : void ;
200
205
onJoin ( resp : object ) : void ;
201
- onJoinComplete ( resp : object , html : any , events : Array < [ string , object ] > ) : void ;
206
+ onJoinComplete ( resp : object , html : string , events : Array < [ string , object ] > ) : void ;
202
207
onJoinError ( resp : object ) : void ;
203
208
onLivePatch ( redir : object ) : void ;
204
209
onLiveRedirect ( redir : object ) : void ;
205
210
onRedirect ( redir : object ) : void ;
206
211
ownsElement ( el : HTMLElement ) : boolean ;
207
212
performPatch ( patch : any , pruneCids : boolean ) : boolean ;
208
213
pushEvent ( type : string , el : HTMLElement , targetCtx : object | null , phxEvent : string , meta : object ) : void ;
214
+ pushFileProgress ( fileEl : HTMLElement , entryRef : string , progress : number , onReply ?: ( ) => void ) : void ;
209
215
pushFormRecovery ( form : HTMLElement , callback : any ) : void ;
210
- pushFormSubmit ( inputEl : HTMLElement , targetCtx : object | null , kind : string , phxEvent : string , onReply : any ) : void ;
211
- pushHookEvent ( targetCtx : object | null , event : string , payload : object ) : void ;
212
- pushInput ( inputEl : HTMLElement , targetCtx : object | null , kind : string , phxEvent : string , callback : any ) : void ;
216
+ pushFormSubmit ( formEl : HTMLElement , targetCtx : object | null , phxEvent : string , onReply : any ) : void ;
217
+ pushHookEvent ( targetCtx : object | null , event : string , payload : object , onReply : any ) : void ;
218
+ pushInput ( inputEl : HTMLElement , targetCtx : object | null , phxEvent : string , callback : any ) : void ;
213
219
pushKey ( keyElement : HTMLElement , targetCtx : object | null , kind : string , phxEvent : string , meta : object ) : void ;
214
220
pushLinkPatch ( href : string , targetEl : HTMLElement , callback : any ) : void ;
215
- pushWithReply ( refGenerator : any , event : string , payload : object , onReply : any ) : any ;
221
+ pushWithReply ( refGenerator : any , event : string , payload : object , onReply ?: ( ) => void ) : any ;
216
222
putRef ( elements : HTMLElement [ ] , event : string ) : [ number , HTMLElement [ ] ] ;
217
223
renderContainer ( diff : any , kind : string ) : string ;
218
- setContainerClasses ( ...classes : any [ ] ) : void ;
224
+ scheduleSubmit ( formEl : HTMLElement , ref : number , callback : any ) : boolean ;
225
+ setContainerClasses ( ...classes : string [ ] ) : void ;
219
226
showLoader ( timeout ?: number ) : void ;
220
227
submitForm ( form : HTMLElement , targetCtx : object | null , phxEvent : string ) : void ;
221
228
targetComponentID ( target : HTMLElement , targetCtx ?: object ) : number | null ;
222
- triggerBeforeUpdate ( fromEl : HTMLElement , toEl : HTMLElement ) : any ;
229
+ triggerAwaitingSubmit ( formEl : HTMLElement ) : void ;
230
+ triggerBeforeUpdateHook ( fromEl : HTMLElement , toEl : HTMLElement ) : any ;
223
231
triggerReconnected ( ) : void ;
224
- triggerUpdatedHook ( hook : any ) : void ;
225
- update ( diff : any , events : Array < [ string , object ] > ) : void ;
226
232
undoRefs ( ref : number ) : void ;
233
+ update ( diff : any , events : Array < [ string , object ] > ) : void ;
234
+ uploadFiles ( formEl : HTMLElement , targetCtx : object | null , ref : number , cid : number , onComplete : any ) : void ;
235
+ withinTargets ( phxTarget : string , callback : any ) : void ;
236
+ }
237
+
238
+ export interface LiveViewFile extends File {
239
+ _phxRef ?: string ;
240
+ }
241
+
242
+ export class UploadEntry {
243
+ constructor ( fileEl : HTMLInputElement , file : LiveViewFile , view : View ) ;
244
+
245
+ fileEl : HTMLInputElement ;
246
+ file : LiveViewFile ;
247
+ view : View ;
248
+ meta : object | null ;
249
+ metadata : ( ) => object | null ;
250
+ progress : ( progress : number ) => void ;
251
+ cancel : ( ) => void ;
252
+ isDone : ( ) => boolean ;
253
+ error : ( reason : string ) => void ;
254
+ }
255
+
256
+ export interface LiveViewUploaderMeta {
257
+ path : string ;
258
+ ref : string ;
259
+ name : string ;
260
+ type : string ;
261
+ size : number ;
262
+ last_modified ?: number ;
227
263
}
228
264
229
265
export function debug ( view : View , kind : string , msg : object , obj : object ) : void ;
@@ -233,43 +269,55 @@ export namespace Browser {
233
269
function dropLocal ( namespace : string , subkey : string ) : any ;
234
270
function fetchPage ( href : string , callback : ( status : number , resp ?: string ) => any ) : any ;
235
271
function getCookie ( name : string ) : string ;
236
- function getHashTargetEl ( hash : any ) : HTMLElement | null ;
272
+ function getHashTargetEl ( maybeHash : any ) : HTMLElement | null ;
237
273
function getLocal ( namespace : string , subkey : string ) : any ;
238
274
function localKey ( namespace : string , subkey : string ) : string ;
239
- function pushState ( kind : any , meta : any , to : string ) : void ;
240
- function redirect ( toURL : string , flash : any ) : void ;
275
+ function pushState ( kind : string , meta : object , to : string ) : void ;
276
+ function redirect ( toURL : string , flash : string ) : void ;
241
277
function setCookie ( name : string , value : string ) : void ;
278
+ function updateCurrentState ( callback : any ) : void ;
242
279
function updateLocal ( namespace : string , subkey : string , initial : any , func : ( current : any ) => any ) : any ;
243
280
}
244
281
245
282
export namespace DOM {
246
283
function all ( node : Node , query : string , callback : ( el : HTMLElement ) => HTMLElement ) : HTMLElement [ ] ;
247
284
function byId ( id : string ) : HTMLElement | void ;
248
- function cleanChildNodes ( container : any , phxUpdate : any ) : void ;
249
- function cloneNode ( node : Node , html : any ) : Node ;
285
+ function childNodeLength ( html : string ) : number ;
286
+ function cleanChildNodes ( container : Node , phxUpdate : string ) : void ;
287
+ function cloneNode ( node : Node , html : string ) : Node ;
250
288
function copyPrivates ( target : HTMLElement , source : HTMLElement ) : void ;
251
289
function debounce ( el : HTMLElement , event : Event , phxDebounce : string , defaultDebounce : string | null , phxThrottle : string , defaultThrottle : string | null , callback : ( ) => any ) : any ;
252
290
function deletePrivate ( el : HTMLElement , key : string ) : void ;
253
- function discardError ( container : HTMLElement , el : HTMLElement , phxFeedbackFor : string ) : void ;
291
+ function discardError ( container : Node , el : HTMLElement , phxFeedbackFor : string ) : void ;
254
292
function dispatchEvent ( target : Node , eventString : string , detail ?: object ) : void ;
293
+ function filterWithinSameLiveView ( nodes : Node [ ] , parent : any ) : any ;
255
294
function findComponentNode ( node : Node , cid : number ) : HTMLElement [ ] ;
256
295
function findParentCIDs ( node : Node , cids : number [ ] ) : Set < number > ;
257
296
function findPhxChildren ( el : HTMLElement , parentId : string ) : HTMLElement [ ] ;
258
297
function findPhxChildrenInFragment ( html : string , parentId : string ) : HTMLElement [ ] ;
298
+ function findUploadInputs ( node : Node ) : void | any [ ] ;
299
+ function hasSelectionRange ( el : HTMLElement ) : boolean ;
259
300
function incCycle ( el : HTMLElement , key : string , trigger ?: any ) : number ;
260
301
function isFormInput ( el : HTMLElement ) : boolean ;
302
+ function isIgnored ( el : HTMLElement , phxUpdate : string ) : boolean ;
261
303
function isNowTriggerFormExternal ( el : HTMLElement , phxTriggerExternal : string ) : boolean ;
262
- function isPhxChild ( el : HTMLElement ) : boolean ;
263
- function isPhxUpdate ( el : HTMLElement , phxUpdate : any , updateTypes : string [ ] ) : boolean ;
304
+ function isPhxChild ( el : Node ) : boolean ;
305
+ function isPhxDestroyed ( node : Node ) : boolean ;
306
+ function isPhxUpdate ( el : Node , phxUpdate : string , updateTypes : string [ ] ) : boolean ;
264
307
function isTextualInput ( el : HTMLElement ) : boolean ;
308
+ function isUploadInput ( el : HTMLElement ) : boolean ;
309
+ function markPhxChildDestroyed ( el : HTMLElement ) : void ;
265
310
function mergeAttrs ( target : HTMLElement , source : HTMLElement , exclude ?: string [ ] ) : void ;
266
311
function mergeFocusedInput ( target : HTMLElement , source : HTMLElement ) : void ;
267
312
function once ( el : HTMLElement , key : string ) : boolean ;
313
+ function private ( el : HTMLElement , key : string ) : any ;
268
314
function putPrivate ( el : HTMLElement , key : string , value : any ) : void ;
269
315
function putTitle ( str : string ) : void ;
270
316
function removeClass ( el : HTMLElement , className : string ) : void ;
271
317
function restoreFocus ( focused : HTMLElement , selectionStart : number , selectionEnd : number ) : void ;
318
+ function showError ( inputEl : HTMLElement , phxFeedbackFor : string ) : void ;
272
319
function syncAttrsToProps ( el : HTMLElement ) : void ;
273
- function syncPendingRef ( ref : number | null , fromEl : HTMLElement , toEl : HTMLElement ) : boolean ;
320
+ function syncPendingRef ( fromEl : HTMLElement , toEl : HTMLElement , disableWith : string ) : boolean ;
274
321
function triggerCycle ( el : HTMLElement , key : string , currentCycle ?: number ) : void ;
322
+ function withinSameLiveView ( node : Node , parent : Node ) : boolean ;
275
323
}
0 commit comments