@ngrdt/router 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
- import { ParamMapping, ParamTypeMap } from './utils';
1
+ import { Injector } from '@angular/core';
2
2
  import { Params } from '@angular/router';
3
3
  import { RdtAngularRoute } from './rdt-angular-route';
4
- import { Injector } from '@angular/core';
4
+ import { ParamMapping, ParamTypeMap, RdtReadonlyParameters } from './utils';
5
5
  export declare function ALWAYS_TRUE(): boolean;
6
6
  export declare class RdtRoute<T extends object = any> {
7
7
  protected orderedParams: string[];
@@ -18,33 +18,115 @@ export declare class RdtRoute<T extends object = any> {
18
18
  protected _entryDisabled: boolean;
19
19
  protected _canBeEntered: () => boolean;
20
20
  private _absoluteRegex?;
21
+ /**
22
+ * Map of parameters and their types.
23
+ */
21
24
  get paramMap(): Readonly<ParamTypeMap<T>>;
25
+ /**
26
+ * Human readable name for display in breadcrumbs, title, etc.
27
+ */
22
28
  get name(): string;
29
+ /**
30
+ * Path of the route relative to parent route.
31
+ */
23
32
  get path(): string;
33
+ /**
34
+ * Parent route.
35
+ */
24
36
  get parent(): RdtRoute<any> | null;
37
+ /**
38
+ * Child routes.
39
+ */
25
40
  get children(): RdtRoute<any>[];
41
+ /**
42
+ * Absolute path of parent route or '/' if there is no parent.
43
+ * Hostname excluded.
44
+ */
26
45
  get basePath(): string;
46
+ /**
47
+ * Absolute path of the route. Hostname excluded.
48
+ */
27
49
  get absolutePath(): string;
50
+ /**
51
+ * Regular expression route path relative to parent route.
52
+ * Hostname excluded.
53
+ */
28
54
  get regex(): RegExp;
55
+ /**
56
+ * Regular expression to match only this route (not children
57
+ * or parent routes). Hostname excluded.
58
+ */
29
59
  get absoluteRegex(): RegExp;
60
+ /**
61
+ * Denotes disabled route entry.
62
+ * If true, route should have no NgModule
63
+ * or component and only serves as virtual module
64
+ * for breadcrumb.
65
+ */
30
66
  get entryDisabled(): boolean;
67
+ /**
68
+ * Statically set state params used when navigating to this instance.
69
+ */
31
70
  get stateParams(): Params;
71
+ /**
72
+ * Statically set query params used when navigating to this instance.
73
+ */
32
74
  get queryParams(): Params;
75
+ /**
76
+ * @param url Absolute path to test.
77
+ * @returns True if url matches this route.
78
+ */
33
79
  testUrl(url: string): boolean;
80
+ /**
81
+ * Statically set parameters used when navigating to this instance.
82
+ */
34
83
  get staticParams(): Partial<T>;
35
84
  get hasCanBeEnteredGuard(): boolean;
85
+ /**
86
+ * Meta guard that is used by [rdtRouterLink] and RdtMenu
87
+ * to determine if route can be entered.
88
+ * @param injector Environment or custom injector.
89
+ * @returns True if route can be entered.
90
+ */
36
91
  canBeEntered(injector?: Injector): boolean;
37
- parseAbsoluteUrl(url: string): Record<string, any> | null;
92
+ /**
93
+ * Extracts url parameters from absolute path for this path and each parent.
94
+ */
95
+ parseAbsoluteUrl(url: string): RdtReadonlyParameters | null;
38
96
  private fill;
97
+ /**
98
+ * Fills parameters in path with values from paramMap.
99
+ * Use withStaticParams() beforehand in case parent paths contain parameters.
100
+ * @param paramMap Must contain all parameters for this route.
101
+ * @returns Absolute path.
102
+ */
39
103
  createAbsoluteUrl(paramMap?: Partial<T>): string;
40
104
  createRelativeUrl(paramMap?: Partial<T>): string;
41
105
  private createUrl;
42
106
  toAngularRoute(): RdtAngularRoute<T>;
107
+ /**
108
+ * Provides static mapping for parameter names tableName -> urlName.
109
+ * Returns new instance of RdtRoute<T> that is clone of
110
+ * this route and its parents (NOT children).
111
+ * @returns Clone of this route with mapped parameter names.
112
+ */
43
113
  withParamMappings(mappings: ParamMapping[]): RdtRoute<T>;
114
+ /**
115
+ * Sets static parameters for this route.
116
+ * @param params Static parameters for this route.
117
+ * @returns Clone of this with static parameters set.
118
+ */
44
119
  withStaticParams(params: T): RdtRoute<T>;
45
120
  withStaticParams<T2 extends object>(route: RdtRoute<T>, params: T2): RdtRoute<T>;
46
121
  withQueryParams(queryParams: Params): RdtRoute<T>;
47
122
  withStateParams(stateParams: Params): RdtRoute<T>;
123
+ /**
124
+ * @returns Partial of object that only contains properties necessary to create this route.
125
+ */
48
126
  extractRouteParams(row: T): Partial<T>;
127
+ /**
128
+ * @returns New instance of RdtRoute<T> that is clone of
129
+ * this route and its parents (NOT children).
130
+ */
49
131
  clone(): RdtRoute<T>;
50
132
  }
@@ -1,3 +1,4 @@
1
+ import { RdtRoute } from './rdt-route';
1
2
  export type ParamTypeMap<T> = {
2
3
  [key in keyof T]?: 'string' | 'number';
3
4
  };
@@ -8,3 +9,13 @@ export interface ParamMapping {
8
9
  export interface StaticRouteParams {
9
10
  [absolutePath: string]: object;
10
11
  }
12
+ export type RdtRedirectReturnType = string | void | undefined;
13
+ export type RdtRedirectFn = (currentPath: string, targetPath: string, targetRoute: RdtRoute) => RdtRedirectReturnType;
14
+ export declare class RdtReadonlyParameters {
15
+ protected readonly params: StaticRouteParams;
16
+ constructor(params?: StaticRouteParams);
17
+ get<T extends object>(route: RdtRoute<T>): Partial<T> | null;
18
+ }
19
+ export declare class RdtParameters extends RdtReadonlyParameters {
20
+ set<T extends object>(route: RdtRoute<T>, params: Partial<T>): void;
21
+ }
@@ -1,2 +1,7 @@
1
1
  import { InjectionToken } from '@angular/core';
2
- export declare const RDT_CANNOT_BE_ENTERED_PROVIDER: InjectionToken<string | false>;
2
+ import { RdtRedirectFn, RdtRedirectReturnType } from '../rdt-route/utils';
3
+ /**
4
+ * Injection token that defines behavior when route cannot be entered (canBeEntered returns false).
5
+ * If value is undefined, route will be redirected to ''.
6
+ */
7
+ export declare const RDT_CANNOT_BE_ENTERED_PROVIDER: InjectionToken<RdtRedirectFn | RdtRedirectReturnType>;
@@ -1,6 +1,7 @@
1
1
  import { NavigationEnd, Params } from '@angular/router';
2
2
  import { Observable } from 'rxjs';
3
3
  import { RdtRoute } from '../rdt-route/rdt-route';
4
+ import { RdtReadonlyParameters } from '../rdt-route/utils';
4
5
  import * as i0 from "@angular/core";
5
6
  export interface RdtNavigateParams {
6
7
  state?: Params;
@@ -17,11 +18,11 @@ export declare class RdtRouterService {
17
18
  get currentUrl(): string | null;
18
19
  parsePreviousUrl(): {
19
20
  route: RdtRoute<any>;
20
- params: Record<string, any>;
21
+ params: RdtReadonlyParameters;
21
22
  } | null;
22
23
  parseCurrentUrl(): {
23
24
  route: RdtRoute<any>;
24
- params: Record<string, any>;
25
+ params: RdtReadonlyParameters;
25
26
  } | null;
26
27
  readonly navigationEnd$: Observable<NavigationEnd>;
27
28
  readonly nextNavigationEnd$: Observable<NavigationEnd>;
@@ -30,10 +31,10 @@ export declare class RdtRouterService {
30
31
  navigateHome(params?: RdtNavigateParams): Promise<boolean>;
31
32
  parseAbsoluteUrl(url?: string): {
32
33
  route: RdtRoute<any>;
33
- params: Record<string, any>;
34
+ params: RdtReadonlyParameters;
34
35
  } | null;
35
36
  navigateBack(params?: RdtNavigateParams): Promise<boolean> | null;
36
- extractAllParams(currentRoute?: RdtRoute): Record<string, any> | null;
37
+ extractAllParams(currentRoute?: RdtRoute): RdtReadonlyParameters | null;
37
38
  isParentOfCurrentLocation(route: RdtRoute): boolean;
38
39
  removeQueryParams(...paramNames: string[]): void;
39
40
  static ɵfac: i0.ɵɵFactoryDeclaration<RdtRouterService, never>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngrdt/router",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "peerDependencies": {
5
5
  "@angular/common": "^18.2.0",
6
6
  "@angular/core": "^18.2.0",