forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ractive.d.ts
476 lines (385 loc) · 13.1 KB
/
ractive.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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
// Type definitions for Ractive 0.7.1
// Project: http://ractivejs.org
// Definitions by: Han Lin Yap <http://yap.nu>
// Definitions: https://github.com/codler/Ractive-TypeScript-Definition
// Version: 0.7.1-1+2015-03-21
declare type _RactiveEvent = Event;
declare namespace Ractive {
export interface Node extends HTMLElement {
_ractive: any;
}
// It's functionally identical to the ES6 promise (as currently spec'd) except that Promise.race and Promise.cast are not currently implemented.
export interface Promise extends Object {
// TODO: Implement interface or wait until typescript include native Promise definition.
}
export interface AnimationPromise extends Promise {
stop(): void; // TODO: void?
}
export interface AdaptorPlugin extends Object {
// TODO:
}
export interface ComponentPlugin extends Static {
// TODO:
}
export interface DecoratorPlugin {
(node: HTMLElement, ...args: any[]): {
// TODO: undocumented GH-429
update?: (...args: any[]) => void;
teardown: () => void;
}
}
export interface EventPlugin extends Function {
// TODO:
}
export interface TransitionPlugin {
(t: Transition, params: Object): void;
}
export interface AdaptorPlugins {
[key: string]: AdaptorPlugin;
}
export interface ComponentPlugins {
[key: string]: ComponentPlugin;
}
export interface DecoratorPlugins {
[key: string]: DecoratorPlugin;
}
export interface EventPlugins {
[key: string]: EventPlugin;
}
export interface TransitionPlugins {
[key: string]: TransitionPlugin;
}
export interface Event {
context: any;
component?: Ractive;
index: { [key: string]: number };
keypath: string;
// Since 0.6.0
name: string;
node: HTMLElement;
original: _RactiveEvent;
}
// Since 0.7.1
export interface NodeInfo {
ractive: Ractive;
keypath: string;
index: { [key: string]: number };
}
// Return value in ractive.observe and ractive.on
export interface Observe {
cancel(): void;
}
// Comes as first parameter in RactiveTransitionPlugin
export interface Transition {
isIntro: boolean;
name: string;
node: HTMLElement;
animateStyle(prop: string, value: any, options: TransitionAnimateOptions, complete: Function): void;
animateStyle(props: Object, options: TransitionAnimateOptions, complete: Function): void;
// Default false
complete(noReset?: boolean): void;
getStyle(prop: string): string;
getStyle(props: string[]): Object;
processParams(params: any, defaults?: Object): Object;
resetStyle(): void;
setStyle(prop: string, value: any): Transition;
setStyle(props: Object): Transition;
}
export interface TransitionAnimateOptions {
// TODO: Do it have default value?
duration: number;
// Any valid CSS timing function
// Default 'linear'
easing?: string;
// TODO: Do it have default value?
delay: number;
}
export interface AnimateOptions {
duration?: number;
easing?: string | Function;
// TODO: number as type correct?
step?: (t: number, value: number) => void; // TODO: void?
// TODO: number as type correct?
complate?: (t: number, value: number) => void; // TODO: void?
}
export interface ObserveOptions extends ObserveOnceOptions {
// Default true
init?: boolean;
}
// Since 0.7.1
export interface ObserveOnceOptions {
// Default Ractive
context?: any;
// Default false
defer?: boolean;
}
// Used in Ractive.parse options
export interface ParseOptions {
preserveWhitespace: boolean;
sanitize: any;
}
// Used in Initialisation options
export interface SanitizeOptions {
elements: string[];
// TODO: Undocumented what default value is, but probably false
eventAttributes?: boolean;
}
export interface NewOptions {
/*
* @type List of mixed string or Adaptor
*/
adapt?: (string | AdaptorPlugin)[];
adaptors?: AdaptorPlugins;
/**
* Default false
* @type boolean or any type that option `el` accepts (HTMLElement or String or jQuery-like collection)
*/
append?: boolean | any;
complete?: Function;
components?: ComponentPlugins;
computed?: Object;
// Since 0.5.5
// TODO: unclear in documantation, should this be in ExtendOptions instead?
css?: string;
/**
* @type Object or Function
*/
// TODO: undocumented type Function
data?: Object | Function;
decorators?: DecoratorPlugins;
/**
* @type [open, close]
*/
delimiters?: string[];
// TODO: unsure
easing?: string | Function;
/**
* @type HTMLElement or String or jQuery-like collection
*/
el?: string | HTMLElement | any;
// TODO: undocumented in Initialisation options page
events?: EventPlugins;
// Since 0.5.5
// TODO: unclear in documantation
interpolators?: { [key: string]: any; };
// Since 0.6.0
// TODO: undocumented arguments
onchange?: (options: NewOptions) => void; // TODO: void?
// Since 0.6.0
// TODO: undocumented arguments
oncomplete?: () => void; // TODO: void?
// Since 0.6.0
// TODO: undocumented arguments
onconfig?: () => void; // TODO: void?
// Since 0.6.0
// TODO: undocumented arguments
onconstruct?: (options: NewOptions) => void; // TODO: void?
// Since 0.6.0
// TODO: undocumented arguments
ondetach?: () => void; // TODO: void?
// Since 0.6.0
// TODO: undocumented arguments
oninit?: () => void; // TODO: void?
// Since 0.6.0
// TODO: undocumented arguments
oninsert?: () => void; // TODO: void?
// Since 0.6.0
// TODO: undocumented arguments
onrender?: () => void; // TODO: void?
// Since 0.6.0
// TODO: undocumented arguments
onunrender?: () => void; // TODO: void?
// Since 0.6.0
// TODO: undocumented arguments
onupdate?: () => void; // TODO: void?
// Since 0.6.0
// TODO: undocumented arguments
onteardown?: () => void; // TODO: void?
/**
* any is same type as template
*/
partials?: { [key: string]: any; };
/**
* Default false
*/
sanitize?: boolean | SanitizeOptions;
/**
* Default ['[[', ']]']
* @type [open, close]
*/
staticDelimiters?: string[];
/**
* Default ['[[[', ']]]']
* @type [open, close]
*/
staticTripleDelimiters?: string[];
/**
* @type String or (if preparsing "Ractive.parse") Array or Object
*/
template?: any;
transitions?: TransitionPlugins;
/**
* @type [open, close]
*/
tripleDelimiters?: string[];
// Default false
lazy?: boolean;
// Default false
magic?: boolean;
// Default true
modifyArrays?: boolean;
// Since 0.5.5
// TODO: unclear in documentation
// Default false
noCSSTransform?: boolean;
// Default false
noIntro?: boolean;
// Default false
preserveWhitespace?: boolean;
// Since 0.5.5
// Default true
stripComments?: boolean;
// Since 0.7.1
// Default true
transitionsEnabled?: boolean;
// Default true
twoway?: boolean;
}
export interface ExtendOptions extends NewOptions {
/**
* @deprecated
*/
beforeInit?: (options: ExtendOptions) => void;
/**
* @deprecated
*/
init?: (options: ExtendOptions) => void;
// Default false, inherit from Ractive.defaults
isolated?: boolean;
}
// See ractive change log "All configuration options, except plugin registries, can be specified on Ractive.defaults and Component.defaults"
export interface DefaultsOptions extends ExtendOptions {
/**
* @deprecated since 0.7.1
*/
// Default false
debug?: boolean;
}
/**
* Static members of Ractive
*/
export interface Static {
new (options: NewOptions): Ractive;
extend(options: ExtendOptions): Static;
// Since 0.7.1
getNodeInfo(node: HTMLElement): NodeInfo;
parse(template: string, options?: ParseOptions): any;
// TODO: undocumented
adaptors: AdaptorPlugins;
// TODO: undocumented
components: ComponentPlugins;
// Since 0.7.1
DEBUG: boolean;
defaults: DefaultsOptions;
// TODO: undocumented
decorators: DecoratorPlugins;
easing: { [key: string]: (x: number) => number; };
// TODO: undocumented
events: EventPlugins;
// TODO: missing static properties documentation
partials: { [key: string]: any; };
// Undocumented method
Promise: Promise;
// TODO: missing static properties documentation
transitions: TransitionPlugins;
}
/**
* The Ractive instance members
*/
export interface Ractive {
add(keypath: string, number?: number): Promise;
animate(keypath: string, value: any, options?: AnimateOptions): AnimationPromise;
animate(map: Object, options?: AnimateOptions): AnimationPromise;
detach(): DocumentFragment;
find(selector: string): HTMLElement;
// live default false
findAll(selector: string, options?: { live: boolean }): HTMLElement[];
// live default false
findAllComponents(name: string, options?: { live: boolean }): Ractive[];
// TODO: maybe exist, in that case it is undocumented
// findAllComponents(): Ractive[]
findComponent(name?: string): Ractive;
// Since 0.7.1
findContainer(name: string): Ractive; // TODO: Ractive?
// Since 0.7.1
findParent(name: string): Ractive; // TODO: Ractive?
fire(eventName: string, ...args: any[]): void; // TODO: void?
get(keypath: string): any;
get(): Object; // TODO: Object?
// target - Node or String or jQuery (see Valid selectors)
// anchor - Node or String or jQuery
insert(target: any, anchor?: any): void; // TODO: void?
merge(keypath: string, value: any[], options?: { compare: boolean | string | Function }): Promise;
// callback context Ractive
observe(keypath: string, callback: (newValue: any, oldValue: any, keypath: string) => void, options?: ObserveOptions): Observe;
observe(map: Object, options?: ObserveOptions): Observe;
// Since 0.7.1
observeOnce(keypath: string, callback: (newValue: any, oldValue: any, keypath: string) => void, options?: ObserveOnceOptions): Observe;
// handler context Ractive
off(eventName?: string, handler?: (event?: Ractive.Event | any, ...args: any[]) => any): Ractive;
on(eventName: string, handler: (event?: Ractive.Event | any, ...args: any[]) => any): Observe;
on(map: { [eventName: string]: (event?: Ractive.Event | any, ...args: any[]) => any }): Observe;
// Since 0.7.1
once(eventName: string, handler: (event?: Ractive.Event | any, ...args: any[]) => any): Observe;
// Since 0.5.5
pop(keypath: string): Promise;
// Since 0.5.5
push(keypath: string, value: any): Promise;
// target - Node or String or jQuery (see Valid selectors)
render(target: any): void; // TODO: void?
// Default {}
reset(data?: Object): Promise;
// Since 0.7.1
resetPartial(name: string, partial: any): Promise;
// Since 0.5.5
// TODO: undocumented, mentioned in ractive change log
// https://github.com/ractivejs/docs.ractivejs.org/issues/188
resetTemplate(): void; // TODO: void?
set(keypath: string, value: any): Promise;
set(map: Object): Promise;
// Since 0.5.5
shift(keypath: string): Promise;
// Since 0.5.5
splice(keypath: string, index: number, removeCount: number, ...add: any[]): Promise;
subtract(keypath: string, number?: number): Promise;
teardown(): Promise;
toggle(keypath: string): Promise;
toHTML(): string;
// Since 0.6.0
unrender(): void; // TODO: void?
// Since 0.5.5
unshift(keypath: string, value: any): Promise;
update(keypath?: string): Promise;
/**
* Update out of sync two-way bindings
* @param keypath A string
* @param cascade A boolean with default false
*/
updateModel(keypath?: string, cascade?: boolean): Promise;
// Properties
// Since 0.7.1
container: Ractive; // TODO: Ractive?
nodes: Object;
partials: Object;
// Since 0.7.1
parent: Ractive; // TODO: Ractive?
// Since 0.7.1
root: Ractive; // TODO: Ractive?
transitions: Object;
}
}
// used for require()
declare module "ractive" {
export = Ractive;
}
declare var Ractive: Ractive.Static;