@mmstack/router-core 19.3.13 → 19.3.15
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.
- package/README.md +352 -206
- package/fesm2022/mmstack-router-core.mjs +309 -31
- package/fesm2022/mmstack-router-core.mjs.map +1 -1
- package/index.d.ts +1 -0
- package/lib/breadcrumb/breadcrumb-resolver.d.ts +13 -11
- package/lib/breadcrumb/public_api.d.ts +3 -2
- package/lib/link.d.ts +33 -1
- package/lib/nav/nav-config.d.ts +26 -0
- package/lib/nav/nav-resolver.d.ts +24 -0
- package/lib/nav/nav-store.d.ts +42 -0
- package/lib/nav/nav.d.ts +88 -0
- package/lib/nav/public_api.d.ts +4 -0
- package/lib/query-param.d.ts +0 -1
- package/lib/title/title-config.d.ts +7 -0
- package/lib/title/title-store.d.ts +4 -6
- package/lib/url.d.ts +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Signal } from '@angular/core';
|
|
2
|
+
import { type InternalNavItem, type NavItem } from './nav';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
/** @internal */
|
|
5
|
+
export declare const DEFAULT_NAV_SCOPE: unique symbol;
|
|
6
|
+
type ScopeName = string | typeof DEFAULT_NAV_SCOPE;
|
|
7
|
+
type AnyInternalNavItem = InternalNavItem<unknown>;
|
|
8
|
+
export declare class NavStore {
|
|
9
|
+
private readonly map;
|
|
10
|
+
private readonly leafRoutes;
|
|
11
|
+
/** @internal */
|
|
12
|
+
register(scope: ScopeName, routePath: string, items: AnyInternalNavItem[]): void;
|
|
13
|
+
/** @internal */
|
|
14
|
+
scope<TMeta = Record<string, unknown>>(name: ScopeName): Signal<NavItem<TMeta>[]>;
|
|
15
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NavStore, never>;
|
|
16
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<NavStore>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Returns a reactive list of nav items for the requested scope.
|
|
20
|
+
*
|
|
21
|
+
* The returned signal reflects the nearest active ancestor route that registered items
|
|
22
|
+
* for `name` via `createNavItems`. Hidden items are filtered out.
|
|
23
|
+
*
|
|
24
|
+
* @typeParam TMeta The shape of `NavItem.meta` for the consuming code. Untyped at the
|
|
25
|
+
* registration site — this is a consumer-side assertion.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* @Component({
|
|
30
|
+
* template: `
|
|
31
|
+
* @for (item of items(); track item) {
|
|
32
|
+
* <a [href]="item.link()" [class.active]="item.active()">{{ item.label() }}</a>
|
|
33
|
+
* }
|
|
34
|
+
* `,
|
|
35
|
+
* })
|
|
36
|
+
* export class TopBar {
|
|
37
|
+
* protected readonly items = injectNavItems();
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function injectNavItems<TMeta = Record<string, unknown>>(name?: string): Signal<NavItem<TMeta>[]>;
|
|
42
|
+
export {};
|
package/lib/nav/nav.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { type Signal } from '@angular/core';
|
|
2
|
+
import { type ActivatedRouteSnapshot, type IsActiveMatchOptions, type Router } from '@angular/router';
|
|
3
|
+
/**
|
|
4
|
+
* Description of a single navigation item.
|
|
5
|
+
*
|
|
6
|
+
* Reactive fields accept either a static value or a zero-arg function — the function
|
|
7
|
+
* form is wrapped in a `computed` so reading signals inside it produces a reactive value.
|
|
8
|
+
*
|
|
9
|
+
* @typeParam TMeta Arbitrary consumer-defined metadata round-tripped to {@link NavItem.meta}.
|
|
10
|
+
*
|
|
11
|
+
* @see createNavItems
|
|
12
|
+
* @see NavItem
|
|
13
|
+
*/
|
|
14
|
+
export type CreateNavItem<TMeta = Record<string, unknown>> = {
|
|
15
|
+
/** Visible text. */
|
|
16
|
+
label: string | (() => string);
|
|
17
|
+
/**
|
|
18
|
+
* The navigation target. Resolved relative to the route the resolver is attached to —
|
|
19
|
+
* the same convention as Angular's `routerLink`:
|
|
20
|
+
*
|
|
21
|
+
* - `'a'` / `'a/b'` / `['a', 'b']` — relative segments, resolve to `${mount}/a` etc.
|
|
22
|
+
* - `'/foo'` / `['/foo', 'bar']` — absolute, leading-slash escape hatch.
|
|
23
|
+
* - A pre-built `UrlTree` is passed through unchanged.
|
|
24
|
+
*
|
|
25
|
+
* Omit (or return `null`) for a pure grouping header — `active` will then fall through
|
|
26
|
+
* to the children-active check.
|
|
27
|
+
*/
|
|
28
|
+
link?: string | any[] | (() => string | any[] | null) | null;
|
|
29
|
+
/** Accessible label. Defaults to `label`. */
|
|
30
|
+
ariaLabel?: string | (() => string);
|
|
31
|
+
/** When true, the item is rendered but non-interactive. Cascades to descendants. */
|
|
32
|
+
disabled?: boolean | (() => boolean);
|
|
33
|
+
/** When true, the item (and its subtree) is filtered out of the consumer-facing array. */
|
|
34
|
+
hidden?: boolean | (() => boolean);
|
|
35
|
+
/** Arbitrary metadata round-tripped on the resulting `NavItem`. */
|
|
36
|
+
meta?: TMeta | (() => TMeta);
|
|
37
|
+
/**
|
|
38
|
+
* Override the match options used to compute `active`. Merged on top of the global default
|
|
39
|
+
* from `provideNavConfig`, which is in turn merged on top of `@angular/router`'s
|
|
40
|
+
* `subsetMatchOptions` defaults.
|
|
41
|
+
*
|
|
42
|
+
* Setting this also implicitly disables the default child-active OR — see
|
|
43
|
+
* {@link matchesWhenChildActive} to opt back in.
|
|
44
|
+
*/
|
|
45
|
+
activeMatch?: Partial<IsActiveMatchOptions>;
|
|
46
|
+
/**
|
|
47
|
+
* Controls whether `active` ORs with descendant `active`.
|
|
48
|
+
*
|
|
49
|
+
* Default: `true` when `activeMatch` is omitted, `false` when `activeMatch` is set.
|
|
50
|
+
* Explicit values override the default.
|
|
51
|
+
*/
|
|
52
|
+
matchesWhenChildActive?: boolean;
|
|
53
|
+
/** Optional stable id. Defaults to the serialized link when present. */
|
|
54
|
+
id?: string | (() => string);
|
|
55
|
+
/** Nested items. */
|
|
56
|
+
children?: CreateNavItem<TMeta>[];
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* A navigation item exposed by `injectNavItems`. All fields are signals so consumers can
|
|
60
|
+
* read reactively without caring whether the source was static or signal-derived.
|
|
61
|
+
*
|
|
62
|
+
* @typeParam TMeta Same as the corresponding {@link CreateNavItem}.
|
|
63
|
+
*/
|
|
64
|
+
export type NavItem<TMeta = Record<string, unknown>> = {
|
|
65
|
+
id: Signal<string>;
|
|
66
|
+
label: Signal<string>;
|
|
67
|
+
ariaLabel: Signal<string>;
|
|
68
|
+
/** Serialized URL, or `null` for pure grouping items with no link. */
|
|
69
|
+
link: Signal<string | null>;
|
|
70
|
+
active: Signal<boolean>;
|
|
71
|
+
disabled: Signal<boolean>;
|
|
72
|
+
meta: Signal<TMeta>;
|
|
73
|
+
/** Children that survive the hidden filter. */
|
|
74
|
+
children: Signal<NavItem<TMeta>[]>;
|
|
75
|
+
};
|
|
76
|
+
/** @internal */
|
|
77
|
+
export type InternalNavItem<TMeta = Record<string, unknown>> = NavItem<TMeta> & {
|
|
78
|
+
hidden: Signal<boolean>;
|
|
79
|
+
};
|
|
80
|
+
/** @internal */
|
|
81
|
+
export declare const NEVER_TRUE: Signal<boolean>;
|
|
82
|
+
/**
|
|
83
|
+
* @internal
|
|
84
|
+
* Recursively builds an {@link InternalNavItem} tree from {@link CreateNavItem} input.
|
|
85
|
+
* Cascades parent `disabled`/`hidden` to descendants and computes `active` against the
|
|
86
|
+
* current router URL using `Router.isActive`.
|
|
87
|
+
*/
|
|
88
|
+
export declare function createInternalNavItem<TMeta = Record<string, unknown>>(input: CreateNavItem<TMeta>, router: Router, relativeTo: ActivatedRouteSnapshot, configActiveMatch: Partial<IsActiveMatchOptions> | undefined, parentDisabled: Signal<boolean>, parentHidden: Signal<boolean>, fallbackId: string): InternalNavItem<TMeta>;
|
package/lib/query-param.d.ts
CHANGED
|
@@ -5,6 +5,12 @@ import { Provider } from '@angular/core';
|
|
|
5
5
|
* @see {createTitle}
|
|
6
6
|
*/
|
|
7
7
|
export type TitleConfig = {
|
|
8
|
+
/**
|
|
9
|
+
* The base title to fallback to, by default Title.getTitle() is called on instantiation and that is used as a fallback,
|
|
10
|
+
* which in most cases should resolve to what is in index.html, unless you specifically call Title.setTitle() before any routes,
|
|
11
|
+
* are initialized.
|
|
12
|
+
*/
|
|
13
|
+
initialTitle?: string;
|
|
8
14
|
/**
|
|
9
15
|
* The title to be used when no title is set.
|
|
10
16
|
* If not provided it defaults to an empty string
|
|
@@ -21,6 +27,7 @@ export type TitleConfig = {
|
|
|
21
27
|
* @internal
|
|
22
28
|
*/
|
|
23
29
|
export type InternalTitleConfig = {
|
|
30
|
+
initialTitle: string;
|
|
24
31
|
parser: (title: string) => string;
|
|
25
32
|
keepLastKnown: boolean;
|
|
26
33
|
};
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { Signal } from '@angular/core';
|
|
1
|
+
import { type Signal } from '@angular/core';
|
|
2
2
|
import { ResolveFn } from '@angular/router';
|
|
3
3
|
import * as i0 from "@angular/core";
|
|
4
4
|
export declare class TitleStore {
|
|
5
|
-
private readonly title;
|
|
6
5
|
private readonly map;
|
|
7
|
-
private readonly leafRoutes;
|
|
8
6
|
constructor();
|
|
9
7
|
register(id: string, titleFn: Signal<string>): void;
|
|
10
8
|
static ɵfac: i0.ɵɵFactoryDeclaration<TitleStore, never>;
|
|
@@ -14,10 +12,10 @@ export declare class TitleStore {
|
|
|
14
12
|
*
|
|
15
13
|
* Creates a title resolver function that can be used in Angular's router.
|
|
16
14
|
*
|
|
17
|
-
* @param
|
|
18
|
-
* A function that returns a string or a Signal<string> representing the title.
|
|
15
|
+
* @param factoryOrValue
|
|
16
|
+
* A function that returns a string or a Signal<string> representing the title or just the string directly.
|
|
19
17
|
* @param awaitValue
|
|
20
18
|
* If `true`, the resolver will wait until the title signal has a value before resolving.
|
|
21
19
|
* Defaults to `false`.
|
|
22
20
|
*/
|
|
23
|
-
export declare function createTitle(
|
|
21
|
+
export declare function createTitle(factoryOrValue: (() => string | (() => string)) | string, awaitValue?: boolean): ResolveFn<string>;
|
package/lib/url.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Signal } from '@angular/core';
|
|
2
|
+
import { Router } from '@angular/router';
|
|
2
3
|
/**
|
|
3
4
|
* Creates a Signal that tracks the current router URL.
|
|
4
5
|
*
|
|
@@ -29,4 +30,4 @@ import { type Signal } from '@angular/core';
|
|
|
29
30
|
* }
|
|
30
31
|
* ```
|
|
31
32
|
*/
|
|
32
|
-
export declare function url(): Signal<string>;
|
|
33
|
+
export declare function url(router?: Router): Signal<string>;
|