forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnavigation.d.ts
847 lines (825 loc) · 28.5 KB
/
navigation.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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
// Type definitions for Navigation 1.0
// Project: http://grahammendick.github.io/navigation/
// Definitions by: Graham Mendick <https://github.com/grahammendick>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module 'navigation' {
export = Navigation;
}
declare module Navigation {
/**
* Defines a contract a class must implement in order to represent a
* logical grouping of child State elements. Navigating across different
* dialogs will initialise the crumb trail
*/
interface IDialog<TState, TStates> {
/**
* Gets the State children
*/
states: TStates;
/**
* Gets the state to navigate to if the Key is passed as an action
* parameter to the StateController
*/
initial: TState;
/**
* Gets the key, unique across dialogs, which is passed as the action
* parameter to the StateController when navigating
*/
key: string;
/**
* Gets the textual description of the dialog
*/
title?: string;
}
/**
* Defines a contract a class must implement in order to configure state
* information. A child of a Dialog element, it represents the endpoint of
* a navigation
*/
interface IState<TTransitions> {
/**
* Gets the Transition children
*/
transitions?: TTransitions;
/**
* Gets the key, unique within a Parent, used by Dialog and Transition
* elements to specify navigation configuration
*/
key: string;
/**
* Gets the default NavigationData for this State
*/
defaults?: any;
/**
* Gets the default NavigationData Types for this State
*/
defaultTypes?: any;
/**
* Gets the textual description of the state
*/
title?: string;
/**
* Gets the route Url pattern
*/
route: string;
/**
* Gets a value that indicates whether to maintain crumb trail
* information e.g PreviousState. This can be used together with Route
* to produce user friendly Urls
*/
trackCrumbTrail?: boolean;
}
/**
* Defines a contract a class must implement in order to configure
* transition information. A child of a State element it represents a
* possible navigation from its Parent to a sibling State
*/
interface ITransition<TState> {
/**
* Gets the state to navigate to if the Key is passed as an action
* parameter to the StateController
*/
to: TState;
/**
* Gets the key, unique within a Parent, which is passed as the action
* parameter to the StateController when navigating
*/
key: string;
}
/**
* Configures dialog information. Represents a logical grouping of child
* State elements. Navigating across different dialogs will initialise the
* crumb trail
*/
class Dialog implements IDialog<State, { [index: string]: State; }> {
/**
* Gets the State children by index
*/
_states: State[];
/**
* Gets the State children
*/
states: {
[index: string]: State;
};
/**
* Gets the number of the dialog
*/
index: number;
/**
* Gets the state to navigate to if the Key is passed as an action
* parameter to the StateController
*/
initial: State;
/**
* Gets the key, unique across dialogs, which is passed as the action
* parameter to the StateController when navigating
*/
key: string;
/**
* Gets the textual description of the dialog
*/
title: string;
}
/**
* Configures state information. A child of a Dialog element, it
* represents the endpoint of a navigation
*/
class State implements IState<{ [index: string]: Transition; }> {
/**
* Gets the Transition children by index
*/
_transitions: Transition[];
/**
* Gets the Transition children
*/
transitions: {
[index: string]: Transition;
};
/**
* Gets the parent Dialog configuration item
*/
parent: Dialog;
/**
* Gets the number of the state within its Parent
*/
index: number;
/**
* Gets the unique identifier for this State
*/
id: string;
/**
* Gets the key, unique within a Parent, used by Dialog and Transition
* elements to specify navigation configuration
*/
key: string;
/**
* Gets the default NavigationData for this State
*/
defaults: any;
/**
* Gets the default NavigationData Types for this State
*/
defaultTypes: any;
/**
* Gets the formatted default NavigationData for this State
*/
formattedDefaults: any;
/**
* Gets the textual description of the state
*/
title: string;
/**
* Gets the route Url pattern
*/
route: string;
/**
* Gets a value that indicates whether to maintain crumb trail
* information e.g PreviousState. This can be used together with Route
* to produce user friendly Urls
*/
trackCrumbTrail: boolean;
/**
* Gets or sets the IStateHandler responsible for building and parsing
* avigation links to this State
*/
stateHandler: IStateHandler;
/**
* Called on the old State (this is not the same as the previous
* State) after navigating to a different State
*/
dispose: () => void;
/**
* Called on the current State after navigating to it
* @param data The current NavigationData
*/
navigated: (data: any) => void;
/**
* Called on the new State before navigating to it
* @param data The new NavigationData
* @param url The new target location
* @param navigate The function to call to continue to navigate
*/
navigating: (data: any, url: string, navigate: () => void) => void;
}
/**
* Configures transition information. A child of a State element it
* represents a possible navigation from its Parent to a sibling State
*/
class Transition implements ITransition<State> {
/**
* Gets the state to navigate to if the Key is passed as an action
* parameter to the StateController
*/
to: State;
/**
* Gets the parent State configuration item
*/
parent: State;
/**
* Gets the number of the transition within its Parent
*/
index: number;
/**
* Gets the key, unique within a Parent, which is passed as the action
* parameter to the StateController when navigating
*/
key: string;
}
/**
* Provides static access to the Dialog, State and Transition configuration
*/
class StateInfoConfig {
/**
* Gets a collection of Dialog information, by index, with their child
* State information and grandchild Transition information
*/
static _dialogs: Dialog[];
/**
* Gets a collection of Dialog information with their child State
* information and grandchild Transition information
*/
static dialogs: {
[index: string]: Dialog;
};
/**
* Builds the Dialog, State and Transition configuration
* @param dialogs A collection of Dialog information with their child
* State information and grandchild Transition information
*/
static build(dialogs: IDialog<string, IState<ITransition<string>[]>[]>[]): void;
}
/**
* Defines a contract a class must implement in order to manage the browser
* Url
*/
interface IHistoryManager {
/**
* Gets or sets a value indicating whether to disable browser history
*/
disabled: boolean;
/**
* Registers browser history event listeners
*/
init(): any;
/**
* Adds browser history
* @param state The State navigated to
* @param url The current url
*/
addHistory(state: State, url: string): void;
/**
* Gets the current location
*/
getCurrentUrl(): string;
/**
* Gets an Href from the url
*/
getHref(url: string): string;
/**
* Gets a Url from the anchor
*/
getUrl(anchor: HTMLAnchorElement): string;
}
/**
* Manages history using the browser Url's hash. If used in a browser
* without the hashchange event or outside of a browser environment, then
* history is disabled
*/
class HashHistoryManager implements IHistoryManager {
/**
* Gets or sets a value indicating whether to disable browser history.
* Set to true if used in a browser without the hashchange event or
* outside of a browser environment
*/
disabled: boolean;
/**
* Gets or sets a value indicating whether to use '#' in place of '?'
* in Urls. Set to true for Internet explorer 6 and 7 support
*/
replaceQueryIdentifier: boolean;
/**
* Registers a listener for the hashchange event
*/
init(): void;
/**
* Sets the browser Url's hash to the url
* @param state The State navigated to
* @param url The current url
*/
addHistory(state: State, url: string): void;
/**
* Gets the current location
*/
getCurrentUrl(): string;
/**
* Gets an Href from the url
*/
getHref(url: string): string;
/**
* Gets a Url from the anchor
*/
getUrl(anchor: HTMLAnchorElement): string;
}
/**
* Manages history using the HTML5 history api. If used in a browser
* without the HTML5 history api or outside of a browser environment, then
* history is disabled
*/
class HTML5HistoryManager implements IHistoryManager {
/**
* Gets or sets a value indicating whether to disable browser history.
* Set to true if used in a browser without the HTML5 history api or
* outside of a browser environment
*/
disabled: boolean;
/**
* Registers a listener for the popstate event
*/
init(): void;
/**
* Sets the browser Url to the url using pushState
* @param state The State navigated to
* @param url The current url
*/
addHistory(state: State, url: string): void;
/**
* Gets the current location
*/
getCurrentUrl(): string;
/**
* Gets an Href from the url
*/
getHref(url: string): string;
/**
* Gets a Url from the anchor
*/
getUrl(anchor: HTMLAnchorElement): string;
}
/**
* Defines a contract a class must implement in order to build and parse
* navigation links
*/
interface IStateHandler {
/**
* Gets a link that navigates to the state passing the data
* @param state The State to navigate to
* @param data The data to pass when navigating
* @returns The navigation link
*/
getNavigationLink(state: State, data: any): string;
/**
* Navigates to the url
* @param oldState The current State
* @param state The State to navigate to
* @param url The target location
*/
navigateLink(oldState: State, state: State, url: string): void;
/**
* Gets the data parsed from the url
* @param state The State navigated to
* @param url The current url
* @returns The navigation data
*/
getNavigationData(state: State, url: string): any;
/**
* Truncates the crumb trail
* @param The State navigated to
* @param The Crumb collection representing the crumb trail
* @returns Truncated crumb trail
*/
truncateCrumbTrail(state: State, crumbs: Crumb[]): Crumb[];
}
/**
* Represents one piece of the crumb trail and holds the information need
* to return to and recreate the State as previously visited. In a single
* crumb trail no two crumbs can have the same State but all must have the
* same Dialog
*/
class Crumb {
/**
* Gets the Context Data held at the time of navigating away from this
* State
*/
data: any;
/**
* Gets the configuration information associated with this navigation
*/
state: State;
/**
* Gets a value indicating whether the Crumb is the last in the crumb
* trail
*/
last: boolean;
/**
* Gets the State Title
*/
title: string;
/**
* Gets the hyperlink navigation to return to the State and pass the
* associated Data
*/
navigationLink: string;
/**
* Initializes a new instance of the Crumb class
*/
constructor(data: any, state: State, link: string, last: boolean);
}
/**
* Provides access to the Navigation Settings configuration
*/
class NavigationSettings {
router: IRouter;
historyManager: IHistoryManager;
/**
* Gets or sets the key that identifies the StateId
*/
stateIdKey: string;
/**
* Gets or sets the key that identifies the PreviousStateId
*/
previousStateIdKey: string;
/**
* Gets or sets the key that identifies the ReturnData
*/
returnDataKey: string;
/**
* Gets or sets the key that identifies the CrumbTrail
*/
crumbTrailKey: string;
/**
* Gets or sets the application path
*/
applicationPath: string;
}
/**
* Provides static properties for accessing context sensitive navigation
* information. Holds the current State and NavigationData. Also holds the
* previous State (this is not the same as the previous Crumb)
*/
class StateContext {
/**
* Gets the State navigated away from to reach the current State
*/
static previousState: State;
/**
* Gets the parent of the PreviousState property
*/
static previousDialog: Dialog;
/**
* Gets the current State
*/
static state: State;
/**
* Gets the parent of the State property
*/
static dialog: Dialog;
/**
* Gets the NavigationData for the current State. It can be accessed.
* Will become the data stored in a Crumb when part of a crumb trail
*/
static data: any;
/**
* Gets the current Url
*/
static url: string;
/**
* Combines the data with all the current NavigationData
* @param The data to add to the current NavigationData
* @returns The combined data
*/
static includeCurrentData(data: any): any;
/**
* Combines the data with a subset of the current NavigationData
* @param The data to add to the current NavigationData
* @returns The combined data
*/
static includeCurrentData(data: any, keys: string[]): any;
/**
* Removes all items from the NavigationData
*/
static clear(): void;
/**
* Removes a single item from the NavigationData
* @param The key of the item to remove
*/
static clear(key: string): void;
}
/**
* Manages all navigation. These can be forward using an action parameter;
* backward via a Crumb; or refreshing the current State
*/
class StateController {
/**
* Gets a Crumb collection representing the crumb trail, ordered oldest
* Crumb first
*/
static crumbs: Crumb[];
/**
* Sets the Context Data with the data returned from the current
* State's IStateHandler
* @param state The current State
* @param url The current Url
*/
static setStateContext(state: State, url: string): void;
/**
* Registers a navigate event listener
* @param handler The navigate event listener
*/
static onNavigate(handler: (oldState: State, state: State, data: any) => void): void;
/**
* Unregisters a navigate event listener
* @param handler The navigate event listener
*/
static offNavigate(handler: (oldState: State, state: State, data: any) => void): void;
/**
* Navigates to a State. Depending on the action will either navigate
* to the 'to' State of a Transition or the 'initial' State of a
* Dialog. It passes no NavigationData
* @param action The key of a child Transition or the key of a Dialog
* @throws action does not match the key of a child Transition or the
* key of a Dialog; or there is NavigationData that cannot be converted
* to a String
* @throws A mandatory route parameter has not been supplied a value
*/
static navigate(action: string): void;
/**
* Navigates to a State. Depending on the action will either navigate
* to the 'to' State of a Transition or the 'initial' State of a
* Dialog
* @param action The key of a child Transition or the key of a Dialog
* @param toData The NavigationData to be passed to the next State and
* stored in the StateContext
* @throws action does not match the key of a child Transition or the
* key of a Dialog; or there is NavigationData that cannot be converted
* to a String
* @throws A mandatory route parameter has not been supplied a value
*/
static navigate(action: string, toData: any): void;
/**
* Gets a Url to navigate to a State. Depending on the action will
* either navigate to the 'to' State of a Transition or the 'initial'
* State of a Dialog. It passes no NavigationData
* @param action The key of a child Transition or the key of a Dialog
* @returns Url that will navigate to State specified in the action
* @throws action does not match the key of a child Transition or the
* key of a Dialog; or there is NavigationData that cannot be converted
* to a String
*/
static getNavigationLink(action: string): string;
/**
* Gets a Url to navigate to a State. Depending on the action will
* either navigate to the 'to' State of a Transition or the 'initial'
* State of a Dialog
* @param action The key of a child Transition or the key of a Dialog
* @param toData The NavigationData to be passed to the next State and
* stored in the StateContext
* @returns Url that will navigate to State specified in the action
* @throws action does not match the key of a child Transition or the
* key of a Dialog; or there is NavigationData that cannot be converted
* to a String
*/
static getNavigationLink(action: string, toData: any): string;
/**
* Determines if the distance specified is within the bounds of the
* crumb trail represented by the Crumbs collection
*/
static canNavigateBack(distance: number): boolean;
/**
* Navigates back to the Crumb contained in the crumb trail,
* represented by the Crumbs collection, as specified by the distance.
* In the crumb trail no two crumbs can have the same State but all
* must have the same Dialog
* @param distance Starting at 1, the number of Crumb steps to go back
* @throws canNavigateBack returns false for this distance
* @throws A mandatory route parameter has not been supplied a value
*/
static navigateBack(distance: number): void;
/**
* Gets a Url to navigate to a Crumb contained in the crumb trail,
* represented by the Crumbs collection, as specified by the distance.
* In the crumb trail no two crumbs can have the same State but all
* must have the same Dialog
* @param distance Starting at 1, the number of Crumb steps to go back
* @throws canNavigateBack returns false for this distance
*/
static getNavigationBackLink(distance: number): string;
/**
* Navigates to the current State passing no NavigationData
* @throws A mandatory route parameter has not been supplied a value
*/
static refresh(): void;
/**
* Navigates to the current State
* @param toData The NavigationData to be passed to the current State
* and stored in the StateContext
* @throws There is NavigationData that cannot be converted to a String
* @throws A mandatory route parameter has not been supplied a value
*/
static refresh(toData: any): void;
/**
* Gets a Url to navigate to the current State passing no
* NavigationData
*/
static getRefreshLink(): string;
/**
* Gets a Url to navigate to the current State
* @param toData The NavigationData to be passed to the current State
* and stored in the StateContext
* @returns Url that will navigate to the current State
* @throws There is NavigationData that cannot be converted to a String
*/
static getRefreshLink(toData: any): string;
/**
* Navigates to the url
* @param url The target location
*/
static navigateLink(url: string): void;
/**
* Gets the next State. Depending on the action will either return the
* 'to' State of a Transition or the 'initial' State of a Dialog
* @param action The key of a child Transition or the key of a Dialog
* @throws action does not match the key of a child Transition or the
* key of a Dialog
*/
static getNextState(action: string): State;
}
/**
* Implementation of IStateHandler that builds and parses navigation links
*/
class StateHandler implements IStateHandler {
/**
* Gets a link that navigates to the state passing the data
* @param state The State to navigate to
* @param data The data to pass when navigating
* @returns The navigation link
*/
getNavigationLink(state: State, data: any): string;
/**
* Navigates to the url
* @param oldState The current State
* @param state The State to navigate to
* @param url The target location
*/
navigateLink(oldState: State, state: State, url: string): void;
/**
* Gets the data parsed from the url
* @param state The State navigated to
* @param url The current url
* @returns The navigation data
*/
getNavigationData(state: State, url: string): any;
/**
* Truncates the crumb trail whenever a repeated or initial State is
* encountered
* @param The State navigated to
* @param The Crumb collection representing the crumb trail
* @returns Truncated crumb trail
*/
truncateCrumbTrail(state: State, crumbs: Crumb[]): Crumb[];
}
/**
* Defines a contract a class must implement in order build and parse
* State routes
*/
interface IRouter {
/**
* Gets the matching State and data for the route
* @param route The route to match
* @returns The matched State and data
*/
getData(route: string): { state: State; data: any; };
/**
* Gets the matching route and data for the state and data
* @param The state to match
* @param The data to match
* @returns The matched route and data
*/
getRoute(state: State, data: any): { route: string; data: any; };
/**
* Gets or sets a value indicating whether the route matching supports
* default parameter values
*/
supportsDefaults: boolean;
/**
* Registers all route configuration information
* @param dialogs Collection of Dialogs with their child State route
* information
*/
addRoutes(dialogs: Dialog[]): void;
}
/**
* Implementation of IRouter that builds and parses State routes using the
* Navigation Router
*/
class StateRouter implements IRouter {
/**
* Gets the underlying Navigation Router
*/
router: Router;
/**
* Gets true, indicating the underlying Navigation Router supports
* defaults
*/
supportsDefaults: boolean;
/**
* Gets the matching State and data for the route
* @param route The route to match
* @returns The matched State and data
*/
getData(route: string): { state: State; data: any; };
/**
* Gets the matching route and data for the state and data
* @param The state to match
* @param The data to match
* @returns The matched route and data
*/
getRoute(state: State, data: any): { route: string; data: any; };
/**
* Registers all route configuration information with the underlying
* Navigation Router
* @param dialogs Collection of Dialogs with their child State route
* information
*/
addRoutes(dialogs: Dialog[]): void;
}
/**
* Holds information about a route
*/
class Route {
/**
* Gets the path pattern of a route
*/
path: string;
/**
* Gets the default parameter values
*/
defaults: any;
/**
* Gets the list of parameters
*/
params: { name: string; optional: boolean; }[];
/**
* Initializes a new instance of the Route class
* @param path The route pattern
*/
constructor(path: string);
/**
* Initializes a new instance of the Route class
* @param path The route pattern
* @param defaults The default parameter values
*/
constructor(path: string, defaults: any);
/**
* Gets the matching data for the path
* @param path The path to match
* @returns The matched data or null if there's no match
*/
match(path: string): any;
/**
* Gets the route populated with default values
* @returns The built route
*/
build(): string;
/**
* Gets the route populated with data and default values
* @param The data for the route parameters
* @returns The built route
*/
build(data: any): string;
}
/**
* The default Navigation router implementation
*/
class Router {
/**
* Registers a route
* @param path The route path
* @returns The parsed Route
*/
addRoute(path: string): Route;
/**
* Registers a route with default parameters
* @param path The route path
* @param defaults The route parameter defaults
* @returns The parsed Route
*/
addRoute(path: string, defaults: any): Route;
/**
* Gets the matching route and data for the path
* @param route The path to match
* @returns The matched route and data
*/
match(path: string): { route: Route; data: any; };
}
/**
* Gets the Navigation settings
*/
export var settings: NavigationSettings;
/**
* Initializes the history manager and navigates to the current location.
* If used outside of a browser environment, pass in the Url to navigate to
* @param url If used outside of a browser, the url to navigate to
*/
export var start: (url?: string) => void;
}