@filip.mazev/blocks 1.2.11 → 1.2.13
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.
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { InjectionToken, inject, signal, computed, Injectable } from '@angular/core';
|
|
3
|
+
import { Router, NavigationEnd } from '@angular/router';
|
|
4
|
+
import { filter } from 'rxjs';
|
|
5
|
+
|
|
6
|
+
const NAVIGATION_CONFIG = new InjectionToken('NAVIGATION_CONFIG');
|
|
7
|
+
|
|
8
|
+
const NAVIGATION_I18N = new InjectionToken('NAVIGATION_I18N');
|
|
9
|
+
|
|
10
|
+
const NAVIGATION_ACCESS_ADAPTER = new InjectionToken('NAVIGATION_ACCESS_ADAPTER');
|
|
11
|
+
|
|
12
|
+
class NavigationService {
|
|
13
|
+
router = inject(Router);
|
|
14
|
+
config = inject(NAVIGATION_CONFIG, { optional: true });
|
|
15
|
+
i18n = inject(NAVIGATION_I18N, { optional: true });
|
|
16
|
+
accessAdapter = inject(NAVIGATION_ACCESS_ADAPTER, { optional: true });
|
|
17
|
+
_current = signal({ breadcrumbs: [] }, ...(ngDevMode ? [{ debugName: "_current" }] : /* istanbul ignore next */ []));
|
|
18
|
+
current = this._current.asReadonly();
|
|
19
|
+
routeBase = computed(() => {
|
|
20
|
+
return this.accessAdapter?.resolveBaseRoute();
|
|
21
|
+
}, ...(ngDevMode ? [{ debugName: "routeBase" }] : /* istanbul ignore next */ []));
|
|
22
|
+
routes = computed(() => {
|
|
23
|
+
this.i18n?.version?.();
|
|
24
|
+
return this.extractRoutes(this.router.config);
|
|
25
|
+
}, ...(ngDevMode ? [{ debugName: "routes" }] : /* istanbul ignore next */ []));
|
|
26
|
+
menu = computed(() => this.buildMenu(this.routes()), ...(ngDevMode ? [{ debugName: "menu" }] : /* istanbul ignore next */ []));
|
|
27
|
+
sections = computed(() => {
|
|
28
|
+
const sections = this.config?.sections ?? [];
|
|
29
|
+
const menu = this.menu();
|
|
30
|
+
if (!sections.length) {
|
|
31
|
+
return [{ id: 'default', items: menu }];
|
|
32
|
+
}
|
|
33
|
+
return sections
|
|
34
|
+
.map(section => ({
|
|
35
|
+
...section,
|
|
36
|
+
items: menu.filter(item => (item.section ?? 'default') === section.id),
|
|
37
|
+
}))
|
|
38
|
+
.filter(section => section.items.length > 0)
|
|
39
|
+
.sort((a, b) => (a.order ?? Number.POSITIVE_INFINITY) - (b.order ?? Number.POSITIVE_INFINITY));
|
|
40
|
+
}, ...(ngDevMode ? [{ debugName: "sections" }] : /* istanbul ignore next */ []));
|
|
41
|
+
constructor() {
|
|
42
|
+
this.updateCurrent();
|
|
43
|
+
this.router.events
|
|
44
|
+
.pipe(filter((e) => e instanceof NavigationEnd))
|
|
45
|
+
.subscribe(() => this.updateCurrent());
|
|
46
|
+
}
|
|
47
|
+
navigateBack() {
|
|
48
|
+
const breadcrumbs = this.current().breadcrumbs;
|
|
49
|
+
if (breadcrumbs.length > 1) {
|
|
50
|
+
const previousBreadcrumb = breadcrumbs[breadcrumbs.length - 2];
|
|
51
|
+
this.router.navigateByUrl(previousBreadcrumb.route);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
this.router.navigateByUrl(this.routeBase() ?? '/');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//#region Helpers
|
|
58
|
+
updateCurrent() {
|
|
59
|
+
this._current.set(this.resolveCurrent(this.router.routerState.snapshot.root));
|
|
60
|
+
}
|
|
61
|
+
extractRoutes(routes, parentSegment = []) {
|
|
62
|
+
const items = [];
|
|
63
|
+
for (const route of routes) {
|
|
64
|
+
if (route.redirectTo)
|
|
65
|
+
continue;
|
|
66
|
+
if (this.accessAdapter && !this.accessAdapter.canAccessMenu(route.data ?? {})) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const ownPath = route.path ?? '';
|
|
70
|
+
const fullSegments = ownPath
|
|
71
|
+
? [...parentSegment, ownPath]
|
|
72
|
+
: [...parentSegment];
|
|
73
|
+
const fullRoute = '/' + fullSegments.filter(Boolean).join('/');
|
|
74
|
+
const children = route.children?.length
|
|
75
|
+
? this.extractRoutes(route.children, fullSegments)
|
|
76
|
+
: [];
|
|
77
|
+
const nav = route.data?.['nav'];
|
|
78
|
+
if (!nav) {
|
|
79
|
+
items.push(...children);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const item = {
|
|
83
|
+
id: fullRoute,
|
|
84
|
+
route: fullRoute,
|
|
85
|
+
label: this.resolveNavText(nav, 'label') ?? '',
|
|
86
|
+
icon: nav.icon,
|
|
87
|
+
section: nav.section,
|
|
88
|
+
visible: nav.visible ? nav.visible() : true,
|
|
89
|
+
data: nav
|
|
90
|
+
};
|
|
91
|
+
items.push(item);
|
|
92
|
+
}
|
|
93
|
+
return this.sortNavigationItems(items);
|
|
94
|
+
}
|
|
95
|
+
resolveCurrent(root) {
|
|
96
|
+
const breadcrumbs = [];
|
|
97
|
+
let currentNode = root;
|
|
98
|
+
let current;
|
|
99
|
+
while (currentNode) {
|
|
100
|
+
const next = currentNode.children.find(child => child.outlet === 'primary') ?? null;
|
|
101
|
+
if (!next)
|
|
102
|
+
break;
|
|
103
|
+
const nav = next.routeConfig?.data?.['nav'];
|
|
104
|
+
const url = this.urlFromSnapshot(next);
|
|
105
|
+
if (nav && !nav.hidden) {
|
|
106
|
+
const breadcrumbLabel = this.resolveNavText(nav, 'breadcrumb', next) ?? this.resolveNavText(nav, 'label', next);
|
|
107
|
+
if (breadcrumbLabel) {
|
|
108
|
+
breadcrumbs.push({ label: breadcrumbLabel, route: url });
|
|
109
|
+
}
|
|
110
|
+
current = {
|
|
111
|
+
id: url,
|
|
112
|
+
route: url,
|
|
113
|
+
label: this.resolveNavText(nav, 'label', next) ?? '',
|
|
114
|
+
icon: nav.icon,
|
|
115
|
+
section: nav.section,
|
|
116
|
+
visible: nav.visible ? nav.visible() : true,
|
|
117
|
+
data: nav
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
currentNode = next;
|
|
121
|
+
}
|
|
122
|
+
return { current, breadcrumbs };
|
|
123
|
+
}
|
|
124
|
+
buildMenu(items) {
|
|
125
|
+
return items
|
|
126
|
+
.map((item) => {
|
|
127
|
+
const children = this.buildMenu(item.children ?? []);
|
|
128
|
+
const includeSelf = item.visible && item.data?.menu !== false;
|
|
129
|
+
if (!includeSelf && !children.length) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
...item,
|
|
134
|
+
children
|
|
135
|
+
};
|
|
136
|
+
})
|
|
137
|
+
.filter((item) => item !== null);
|
|
138
|
+
}
|
|
139
|
+
sortNavigationItems(items) {
|
|
140
|
+
const customSort = this.config?.sortItems;
|
|
141
|
+
return [...items].sort((a, b) => {
|
|
142
|
+
if (customSort) {
|
|
143
|
+
return customSort(a, b);
|
|
144
|
+
}
|
|
145
|
+
const orderA = a.data?.order ?? Number.POSITIVE_INFINITY;
|
|
146
|
+
const orderB = b.data?.order ?? Number.POSITIVE_INFINITY;
|
|
147
|
+
if (orderA !== orderB)
|
|
148
|
+
return orderA - orderB;
|
|
149
|
+
return a.label.localeCompare(b.label);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
resolveNavText(nav, kind, snapshot) {
|
|
153
|
+
const directValue = kind === 'label' ? nav.label : nav.breadcrumb;
|
|
154
|
+
const key = kind === 'label' ? nav.labelKey : nav.breadcrumbKey;
|
|
155
|
+
if (directValue) {
|
|
156
|
+
return typeof directValue === 'function'
|
|
157
|
+
? directValue({ snapshot: snapshot })
|
|
158
|
+
: directValue;
|
|
159
|
+
}
|
|
160
|
+
if (key) {
|
|
161
|
+
return this.i18n?.translate(key, { route: snapshot });
|
|
162
|
+
}
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
urlFromSnapshot(snapshot) {
|
|
166
|
+
return ('/' +
|
|
167
|
+
snapshot.pathFromRoot
|
|
168
|
+
.flatMap(s => s.url.map(u => u.path))
|
|
169
|
+
.filter(Boolean)
|
|
170
|
+
.join('/'));
|
|
171
|
+
}
|
|
172
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NavigationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
173
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NavigationService, providedIn: 'root' });
|
|
174
|
+
}
|
|
175
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NavigationService, decorators: [{
|
|
176
|
+
type: Injectable,
|
|
177
|
+
args: [{ providedIn: 'root' }]
|
|
178
|
+
}], ctorParameters: () => [] });
|
|
179
|
+
|
|
180
|
+
function provideNavigation(config) {
|
|
181
|
+
return [
|
|
182
|
+
{
|
|
183
|
+
provide: NAVIGATION_CONFIG,
|
|
184
|
+
useValue: config
|
|
185
|
+
}
|
|
186
|
+
];
|
|
187
|
+
}
|
|
188
|
+
;
|
|
189
|
+
function withNav(route, nav) {
|
|
190
|
+
const existingNav = route.data?.['nav'] ?? {};
|
|
191
|
+
return {
|
|
192
|
+
...route,
|
|
193
|
+
data: {
|
|
194
|
+
...(route.data ?? {}),
|
|
195
|
+
nav: {
|
|
196
|
+
...existingNav,
|
|
197
|
+
...nav
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/*
|
|
204
|
+
* Public API Surface of modal
|
|
205
|
+
*/
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Generated bundle index. Do not edit.
|
|
209
|
+
*/
|
|
210
|
+
|
|
211
|
+
export { NAVIGATION_CONFIG, NAVIGATION_I18N, NavigationService, provideNavigation, withNav };
|
|
212
|
+
//# sourceMappingURL=filip.mazev-blocks-navigation.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filip.mazev-blocks-navigation.mjs","sources":["../../../projects/blocks/navigation/tokens/navigation-config.token.ts","../../../projects/blocks/navigation/tokens/navigation-i18n.token.ts","../../../projects/blocks/navigation/tokens/navigation-access-adapter.token.ts","../../../projects/blocks/navigation/services/navigation.service.ts","../../../projects/blocks/navigation/helpers/navigation-functions.ts","../../../projects/blocks/navigation/public-api.ts","../../../projects/blocks/navigation/filip.mazev-blocks-navigation.ts"],"sourcesContent":["import { InjectionToken } from \"@angular/core\";\nimport { INavigationConfig } from \"../interfaces/inavigation-config.interface\";\n\nexport const NAVIGATION_CONFIG = new InjectionToken<INavigationConfig>('NAVIGATION_CONFIG');","import { InjectionToken } from \"@angular/core\";\nimport { INavigationI18nAdapter } from \"../interfaces/inavigation-i18n-adapter.interface\";\n\nexport const NAVIGATION_I18N = new InjectionToken<INavigationI18nAdapter>('NAVIGATION_I18N');","import { InjectionToken } from \"@angular/core\";\nimport { INavigationAccessAdapter } from \"../interfaces/inavigation-access-adapter.interface\";\n\nexport const NAVIGATION_ACCESS_ADAPTER = new InjectionToken<INavigationAccessAdapter>('NAVIGATION_ACCESS_ADAPTER');","import { computed, inject, Injectable, Signal, signal } from \"@angular/core\";\nimport { ActivatedRouteSnapshot, NavigationEnd, Router, Routes } from \"@angular/router\";\nimport { NAVIGATION_CONFIG } from \"../tokens/navigation-config.token\";\nimport { IResolvedNavigation } from \"../interfaces/iresolved-navigation.interface\";\nimport { filter } from \"rxjs\";\nimport { IBreadcrumbItem } from \"../interfaces/ibreadcrumb-item.interface\";\nimport { INavMeta } from \"../interfaces/inav-meta.interface\";\nimport { INavigationItem } from \"../interfaces/inavigation-item.interface\";\nimport { NAVIGATION_I18N } from \"../tokens/navigation-i18n.token\";\nimport { NAVIGATION_ACCESS_ADAPTER } from \"../tokens/navigation-access-adapter.token\";\n\n@Injectable({ providedIn: 'root' })\nexport class NavigationService {\n private readonly router = inject(Router);\n private readonly config = inject(NAVIGATION_CONFIG, { optional: true });\n private readonly i18n = inject(NAVIGATION_I18N, { optional: true });\n private readonly accessAdapter = inject(NAVIGATION_ACCESS_ADAPTER, { optional: true });\n\n private readonly _current = signal<IResolvedNavigation>({ breadcrumbs: [] });\n public readonly current = this._current.asReadonly();\n\n public readonly routeBase = computed<string | undefined>(() => {\n return this.accessAdapter?.resolveBaseRoute();\n });\n\n public readonly routes: Signal<INavigationItem[]> = computed(() => {\n this.i18n?.version?.();\n return this.extractRoutes(this.router.config);\n });\n\n public readonly menu = computed(() => this.buildMenu(this.routes()));\n\n public readonly sections = computed(() => {\n const sections = this.config?.sections ?? [];\n const menu = this.menu();\n\n if(!sections.length) {\n return [{ id: 'default', items: menu }];\n }\n\n return sections\n .map(section => ({\n ...section,\n items: menu.filter(item => (item.section ?? 'default') === section.id),\n }))\n .filter(section => section.items.length > 0)\n .sort((a, b) => (a.order ?? Number.POSITIVE_INFINITY) - (b.order ?? Number.POSITIVE_INFINITY));\n });\n\n constructor() {\n this.updateCurrent();\n\n this.router.events\n .pipe(filter((e): e is NavigationEnd => e instanceof NavigationEnd))\n .subscribe(() => this.updateCurrent());\n }\n\n public navigateBack(): void {\n const breadcrumbs = this.current().breadcrumbs;\n \n if (breadcrumbs.length > 1) {\n const previousBreadcrumb = breadcrumbs[breadcrumbs.length - 2];\n this.router.navigateByUrl(previousBreadcrumb.route);\n } else {\n this.router.navigateByUrl(this.routeBase() ?? '/');\n }\n }\n\n //#region Helpers\n\n private updateCurrent(): void {\n this._current.set(\n this.resolveCurrent(this.router.routerState.snapshot.root)\n );\n }\n\n private extractRoutes(routes: Routes, parentSegment: string[] = []): INavigationItem[] {\n const items: INavigationItem[] = [];\n\n for(const route of routes) {\n if(route.redirectTo) continue;\n\n if (this.accessAdapter && !this.accessAdapter.canAccessMenu(route.data ?? {})) {\n continue;\n }\n\n const ownPath = route.path ?? '';\n \n const fullSegments = ownPath \n ? [...parentSegment, ownPath] \n : [...parentSegment];\n\n const fullRoute = '/' + fullSegments.filter(Boolean).join('/');\n\n const children = route.children?.length\n ? this.extractRoutes(route.children, fullSegments)\n : [];\n \n const nav = route.data?.['nav'] as INavMeta | undefined;\n\n if(!nav) {\n items.push(...children);\n continue;\n }\n\n const item = {\n id: fullRoute,\n route: fullRoute,\n label: this.resolveNavText(nav, 'label') ?? '',\n icon: nav.icon,\n section: nav.section,\n visible: nav.visible ? nav.visible() : true,\n data: nav\n };\n\n items.push(item);\n }\n\n return this.sortNavigationItems(items);\n }\n\n private resolveCurrent(root: ActivatedRouteSnapshot): IResolvedNavigation {\n const breadcrumbs: IBreadcrumbItem[] = [];\n let currentNode: ActivatedRouteSnapshot | null = root;\n let current: INavigationItem | undefined;\n\n while (currentNode) {\n const next: ActivatedRouteSnapshot | null = currentNode.children.find(child => child.outlet === 'primary') ?? null;\n if(!next) break;\n\n const nav = next.routeConfig?.data?.['nav'] as INavMeta | undefined;\n const url = this.urlFromSnapshot(next);\n\n if(nav && !nav.hidden) {\n const breadcrumbLabel = this.resolveNavText(nav, 'breadcrumb', next) ?? this.resolveNavText(nav, 'label', next);\n if(breadcrumbLabel) {\n breadcrumbs.push({ label: breadcrumbLabel, route: url });\n }\n\n current = {\n id: url,\n route: url,\n label: this.resolveNavText(nav, 'label', next) ?? '',\n icon: nav.icon,\n section: nav.section,\n visible: nav.visible ? nav.visible() : true,\n data: nav\n }\n }\n\n currentNode = next;\n }\n\n return { current, breadcrumbs };\n }\n\n private buildMenu(items: INavigationItem[]): INavigationItem[] {\n return items\n .map((item): INavigationItem | null => {\n const children = this.buildMenu(item.children ?? []);\n const includeSelf = item.visible && item.data?.menu !== false;\n\n if (!includeSelf && !children.length) {\n return null;\n }\n\n return {\n ...item,\n children\n };\n }) \n .filter((item): item is INavigationItem => item !== null);\n }\n\n private sortNavigationItems(items: INavigationItem[]): INavigationItem[] {\n const customSort = this.config?.sortItems;\n\n return [...items].sort((a, b) => {\n if(customSort) {\n return customSort(a, b);\n }\n\n const orderA = a.data?.order ?? Number.POSITIVE_INFINITY;\n const orderB = b.data?.order ?? Number.POSITIVE_INFINITY;\n\n if(orderA !== orderB) return orderA - orderB;\n return a.label.localeCompare(b.label);\n });\n }\n\n private resolveNavText(\n nav: INavMeta,\n kind: 'label' | 'breadcrumb',\n snapshot?: ActivatedRouteSnapshot\n ): string | undefined {\n const directValue = kind === 'label' ? nav.label : nav.breadcrumb;\n const key = kind === 'label' ? nav.labelKey : nav.breadcrumbKey;\n\n if(directValue) {\n return typeof directValue === 'function'\n ? directValue({ snapshot: snapshot! })\n : directValue;\n }\n\n if(key) {\n return this.i18n?.translate(key, { route: snapshot });\n }\n\n return undefined;\n }\n\n private urlFromSnapshot(snapshot: ActivatedRouteSnapshot): string {\n return (\n '/' +\n snapshot.pathFromRoot\n .flatMap(s => s.url.map(u => u.path))\n .filter(Boolean)\n .join('/')\n );\n }\n\n //#endregion\n}","import { INavMeta } from \"@navigation/interfaces/inav-meta.interface\";\nimport { INavigationConfig } from \"../interfaces/inavigation-config.interface\";\nimport { NAVIGATION_CONFIG } from \"../tokens/navigation-config.token\";\nimport { Route } from \"@angular/router\";\n\nexport function provideNavigation(config: INavigationConfig) {\n return [\n {\n provide: NAVIGATION_CONFIG,\n useValue: config\n }\n ];\n};\n\nexport function withNav(route: Route, nav: INavMeta): Route {\n const existingNav = (route.data?.['nav'] as INavMeta | undefined) ?? {};\n\n return {\n ...route,\n data: {\n ...(route.data ?? {}),\n nav: {\n ...existingNav,\n ...nav\n }\n }\n };\n}","/*\n * Public API Surface of modal\n */\n\nexport * from './services/navigation.service';\n\nexport * from './interfaces/ibreadcrumb-item.interface';\nexport * from './interfaces/inav-context.interface';\nexport * from './interfaces/inav-meta.interface';\nexport * from './interfaces/inav-route-data.interface';\nexport * from './interfaces/inavigation-config.interface';\nexport * from './interfaces/inavigation-i18n-adapter.interface';\nexport * from './interfaces/inavigation-item.interface';\nexport * from './interfaces/inavigation-section-config.interface';\nexport * from './interfaces/iresolved-navigation.interface';\n\nexport * from './tokens/navigation-config.token';\nexport * from './tokens/navigation-i18n.token';\n\nexport * from './helpers/navigation-functions';","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;MAGa,iBAAiB,GAAG,IAAI,cAAc,CAAoB,mBAAmB;;MCA7E,eAAe,GAAG,IAAI,cAAc,CAAyB,iBAAiB;;ACApF,MAAM,yBAAyB,GAAG,IAAI,cAAc,CAA2B,2BAA2B,CAAC;;MCSrG,iBAAiB,CAAA;AACX,IAAA,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IACvB,MAAM,GAAG,MAAM,CAAC,iBAAiB,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACtD,IAAI,GAAG,MAAM,CAAC,eAAe,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAClD,aAAa,GAAG,MAAM,CAAC,yBAAyB,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAErE,QAAQ,GAAG,MAAM,CAAsB,EAAE,WAAW,EAAE,EAAE,EAAE,EAAA,IAAA,SAAA,GAAA,CAAA,EAAA,SAAA,EAAA,UAAA,EAAA,CAAA,8BAAA,EAAA,CAAA,CAAC;AAC5D,IAAA,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE;AAEpC,IAAA,SAAS,GAAG,QAAQ,CAAqB,MAAK;AAC5D,QAAA,OAAO,IAAI,CAAC,aAAa,EAAE,gBAAgB,EAAE;AAC/C,IAAA,CAAC,gFAAC;AAEc,IAAA,MAAM,GAA8B,QAAQ,CAAC,MAAK;AAChE,QAAA,IAAI,CAAC,IAAI,EAAE,OAAO,IAAI;QACtB,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;AAC/C,IAAA,CAAC,6EAAC;AAEc,IAAA,IAAI,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,2EAAC;AAEpD,IAAA,QAA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A,eAAA,CAAA,UAAA,EAAA,CAAA;AAAjB,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,iBAAiB,cADJ,MAAM,EAAA,CAAA;;2FACnB,iBAAiB,EAAA,UAAA,EAAA,CAAA;kBAD7B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;ACN5B,SAAU,iBAAiB,CAAC,MAAyB,EAAA;IACzD,OAAO;AACL,QAAA;AACE,YAAA,OAAO,EAAE,iBAAiB;AAC1B,YAAA,QAAQ,EAAE;AACX;KACF;AACH;AAAC;AAEK,SAAU,OAAO,CAAC,KAAY,EAAE,GAAa,EAAA;IACjD,MAAM,WAAW,GAAI,KAAK,CAAC,IAAI,GAAG,KAAK,CAA0B,IAAI,EAAE;IAEvE,OAAO;AACL,QAAA,GAAG,KAAK;AACR,QAAA,IAAI,EAAE;AACJ,YAAA,IAAI,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;AACrB,YAAA,GAAG,EAAE;AACH,gBAAA,GAAG,WAAW;AACd,gBAAA,GAAG;AACJ;AACF;KACF;AACH;;AC3BA;;AAEG;;ACFH;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@filip.mazev/blocks",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.13",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"schematics": "./schematics/collection.json",
|
|
6
6
|
"exports": {
|
|
@@ -35,6 +35,10 @@
|
|
|
35
35
|
"types": "./types/filip.mazev-blocks-modal.d.ts",
|
|
36
36
|
"default": "./fesm2022/filip.mazev-blocks-modal.mjs"
|
|
37
37
|
},
|
|
38
|
+
"./navigation": {
|
|
39
|
+
"types": "./types/filip.mazev-blocks-navigation.d.ts",
|
|
40
|
+
"default": "./fesm2022/filip.mazev-blocks-navigation.mjs"
|
|
41
|
+
},
|
|
38
42
|
"./toastr": {
|
|
39
43
|
"types": "./types/filip.mazev-blocks-toastr.d.ts",
|
|
40
44
|
"default": "./fesm2022/filip.mazev-blocks-toastr.mjs"
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Signal, InjectionToken } from '@angular/core';
|
|
3
|
+
import { IconData } from '@filip.mazev/blocks/icons';
|
|
4
|
+
import { ActivatedRouteSnapshot, Route } from '@angular/router';
|
|
5
|
+
import { INavMeta as INavMeta$1 } from '@navigation/interfaces/inav-meta.interface';
|
|
6
|
+
|
|
7
|
+
interface IBreadcrumbItem {
|
|
8
|
+
label: string;
|
|
9
|
+
route: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface INavContext {
|
|
13
|
+
snapshot: ActivatedRouteSnapshot;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface INavMeta {
|
|
17
|
+
label?: string | ((ctx: INavContext) => string);
|
|
18
|
+
breadcrumb?: string | ((ctx: INavContext) => string);
|
|
19
|
+
labelKey?: string;
|
|
20
|
+
breadcrumbKey?: string;
|
|
21
|
+
icon?: IconData;
|
|
22
|
+
section?: string;
|
|
23
|
+
menu?: boolean;
|
|
24
|
+
hidden?: boolean;
|
|
25
|
+
order?: number;
|
|
26
|
+
root?: boolean;
|
|
27
|
+
visible?: () => boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface INavigationItem {
|
|
31
|
+
id: string;
|
|
32
|
+
route: string;
|
|
33
|
+
label: string;
|
|
34
|
+
icon?: IconData;
|
|
35
|
+
section?: string;
|
|
36
|
+
visible: boolean;
|
|
37
|
+
children?: INavigationItem[];
|
|
38
|
+
data?: INavMeta;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface IResolvedNavigation {
|
|
42
|
+
current?: INavigationItem;
|
|
43
|
+
breadcrumbs: IBreadcrumbItem[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
declare class NavigationService {
|
|
47
|
+
private readonly router;
|
|
48
|
+
private readonly config;
|
|
49
|
+
private readonly i18n;
|
|
50
|
+
private readonly accessAdapter;
|
|
51
|
+
private readonly _current;
|
|
52
|
+
readonly current: Signal<IResolvedNavigation>;
|
|
53
|
+
readonly routeBase: Signal<string | undefined>;
|
|
54
|
+
readonly routes: Signal<INavigationItem[]>;
|
|
55
|
+
readonly menu: Signal<INavigationItem[]>;
|
|
56
|
+
readonly sections: Signal<{
|
|
57
|
+
items: INavigationItem[];
|
|
58
|
+
id: string;
|
|
59
|
+
title?: string;
|
|
60
|
+
order?: number;
|
|
61
|
+
}[]>;
|
|
62
|
+
constructor();
|
|
63
|
+
navigateBack(): void;
|
|
64
|
+
private updateCurrent;
|
|
65
|
+
private extractRoutes;
|
|
66
|
+
private resolveCurrent;
|
|
67
|
+
private buildMenu;
|
|
68
|
+
private sortNavigationItems;
|
|
69
|
+
private resolveNavText;
|
|
70
|
+
private urlFromSnapshot;
|
|
71
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NavigationService, never>;
|
|
72
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<NavigationService>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
interface INavRouteData {
|
|
76
|
+
nav?: INavMeta;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
interface INavigationSectionConfig {
|
|
80
|
+
id: string;
|
|
81
|
+
title?: string;
|
|
82
|
+
order?: number;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
interface INavigationConfig {
|
|
86
|
+
sections?: INavigationSectionConfig[];
|
|
87
|
+
includeHiddenInBreadcrumbs?: boolean;
|
|
88
|
+
sortItems?: (a: INavigationItem, b: INavigationItem) => number;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface INavigationI18nAdapter {
|
|
92
|
+
translate(key: string, params?: Record<string, unknown>): string;
|
|
93
|
+
version?: Signal<number>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
declare const NAVIGATION_CONFIG: InjectionToken<INavigationConfig>;
|
|
97
|
+
|
|
98
|
+
declare const NAVIGATION_I18N: InjectionToken<INavigationI18nAdapter>;
|
|
99
|
+
|
|
100
|
+
declare function provideNavigation(config: INavigationConfig): {
|
|
101
|
+
provide: i0.InjectionToken<INavigationConfig>;
|
|
102
|
+
useValue: INavigationConfig;
|
|
103
|
+
}[];
|
|
104
|
+
declare function withNav(route: Route, nav: INavMeta$1): Route;
|
|
105
|
+
|
|
106
|
+
export { NAVIGATION_CONFIG, NAVIGATION_I18N, NavigationService, provideNavigation, withNav };
|
|
107
|
+
export type { IBreadcrumbItem, INavContext, INavMeta, INavRouteData, INavigationConfig, INavigationI18nAdapter, INavigationItem, INavigationSectionConfig, IResolvedNavigation };
|