@arsedizioni/ars-utils 22.7.4 → 22.7.6
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/fesm2022/arsedizioni-ars-utils-clipper.common.mjs.map +1 -1
- package/fesm2022/arsedizioni-ars-utils-clipper.ui.mjs +8 -5
- package/fesm2022/arsedizioni-ars-utils-clipper.ui.mjs.map +1 -1
- package/fesm2022/arsedizioni-ars-utils-ui.navigation.mjs +29 -8
- package/fesm2022/arsedizioni-ars-utils-ui.navigation.mjs.map +1 -1
- package/package.json +1 -1
- package/types/arsedizioni-ars-utils-ui.navigation.d.ts +31 -2
|
@@ -8,7 +8,7 @@ import * as i1 from "@angular/material/icon";
|
|
|
8
8
|
import { MatIconModule } from "@angular/material/icon";
|
|
9
9
|
import * as i2 from "@angular/material/tooltip";
|
|
10
10
|
import { MatTooltipModule } from "@angular/material/tooltip";
|
|
11
|
-
import { NavigationEnd, Router } from "@angular/router";
|
|
11
|
+
import { NavigationCancel, NavigationEnd, NavigationError, NavigationSkipped, Router } from "@angular/router";
|
|
12
12
|
import { EMPTY, distinctUntilChanged, filter, map } from "rxjs";
|
|
13
13
|
import { ThemeService } from "@arsedizioni/ars-utils/core";
|
|
14
14
|
import { MediaObserver } from "@arsedizioni/ars-utils/ui";
|
|
@@ -132,6 +132,7 @@ var NavigationBarComponent = class NavigationBarComponent {
|
|
|
132
132
|
this.itemElements = viewChildren("navItem", ...ngDevMode ? [{ debugName: "itemElements" }] : /* istanbul ignore next */ []);
|
|
133
133
|
this.panelElements = viewChildren("panelItem", ...ngDevMode ? [{ debugName: "panelElements" }] : /* istanbul ignore next */ []);
|
|
134
134
|
this.routerUrl = signal(void 0, ...ngDevMode ? [{ debugName: "routerUrl" }] : /* istanbul ignore next */ []);
|
|
135
|
+
this.pendingId = signal(void 0, ...ngDevMode ? [{ debugName: "pendingId" }] : /* istanbul ignore next */ []);
|
|
135
136
|
this.themeChanged = toSignal(this.themeService?.changed ?? EMPTY, { initialValue: void 0 });
|
|
136
137
|
this.isDark = computed(() => {
|
|
137
138
|
this.themeChanged();
|
|
@@ -283,18 +284,29 @@ var NavigationBarComponent = class NavigationBarComponent {
|
|
|
283
284
|
});
|
|
284
285
|
return groups;
|
|
285
286
|
}, ...ngDevMode ? [{ debugName: "renderGroups" }] : /* istanbul ignore next */ []);
|
|
287
|
+
this.routerDriven = computed(() => this.routerSync() && !!this.router, ...ngDevMode ? [{ debugName: "routerDriven" }] : /* istanbul ignore next */ []);
|
|
288
|
+
this.routedTargets = computed(() => {
|
|
289
|
+
const result = [];
|
|
290
|
+
const hrefs = this.hrefs();
|
|
291
|
+
for (const item of this.allItems()) {
|
|
292
|
+
if (item.href || item.route === void 0) continue;
|
|
293
|
+
const href = hrefs.get(item.id);
|
|
294
|
+
if (href) result.push({
|
|
295
|
+
item,
|
|
296
|
+
href
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
return result;
|
|
300
|
+
}, ...ngDevMode ? [{ debugName: "routedTargets" }] : /* istanbul ignore next */ []);
|
|
301
|
+
this.routedIds = computed(() => new Set(this.routedTargets().map((t) => t.item.id)), ...ngDevMode ? [{ debugName: "routedIds" }] : /* istanbul ignore next */ []);
|
|
286
302
|
this.routerActiveId = computed(() => {
|
|
287
|
-
if (!this.
|
|
303
|
+
if (!this.routerDriven()) return void 0;
|
|
288
304
|
const url = this.routerUrl();
|
|
289
305
|
if (!url) return void 0;
|
|
290
306
|
const path = NavigationBarComponent.pathOf(url);
|
|
291
|
-
const hrefs = this.hrefs();
|
|
292
307
|
let best;
|
|
293
308
|
let bestLength = -1;
|
|
294
|
-
for (const item of this.
|
|
295
|
-
if (item.href || item.route === void 0) continue;
|
|
296
|
-
const href = hrefs.get(item.id);
|
|
297
|
-
if (!href) continue;
|
|
309
|
+
for (const { item, href } of this.routedTargets()) {
|
|
298
310
|
const target = NavigationBarComponent.pathOf(href);
|
|
299
311
|
if ((item.exact ? path === target : path === target || path.startsWith(target.endsWith("/") ? target : `${target}/`)) && target.length > bestLength) {
|
|
300
312
|
best = item.id;
|
|
@@ -303,7 +315,14 @@ var NavigationBarComponent = class NavigationBarComponent {
|
|
|
303
315
|
}
|
|
304
316
|
return best;
|
|
305
317
|
}, ...ngDevMode ? [{ debugName: "routerActiveId" }] : /* istanbul ignore next */ []);
|
|
306
|
-
this.activeId = computed(() =>
|
|
318
|
+
this.activeId = computed(() => {
|
|
319
|
+
const pending = this.pendingId();
|
|
320
|
+
if (pending !== void 0) return pending;
|
|
321
|
+
const routed = this.routerActiveId();
|
|
322
|
+
if (routed !== void 0) return routed;
|
|
323
|
+
const selected = this.selectedId();
|
|
324
|
+
return selected !== void 0 && this.routerDriven() && this.routedIds().has(selected) ? void 0 : selected;
|
|
325
|
+
}, ...ngDevMode ? [{ debugName: "activeId" }] : /* istanbul ignore next */ []);
|
|
307
326
|
this.defaultExpandedIds = computed(() => {
|
|
308
327
|
const result = /* @__PURE__ */ new Set();
|
|
309
328
|
for (const item of this.allItems()) if (item.expanded) result.add(item.id);
|
|
@@ -452,6 +471,7 @@ var NavigationBarComponent = class NavigationBarComponent {
|
|
|
452
471
|
if (router) {
|
|
453
472
|
this.routerUrl.set(router.url);
|
|
454
473
|
router.events.pipe(filter((e) => e instanceof NavigationEnd), map((e) => e.urlAfterRedirects), distinctUntilChanged(), takeUntilDestroyed(this.destroyRef)).subscribe((url) => this.routerUrl.set(url));
|
|
474
|
+
router.events.pipe(filter((e) => e instanceof NavigationEnd || e instanceof NavigationCancel || e instanceof NavigationError || e instanceof NavigationSkipped), takeUntilDestroyed(this.destroyRef)).subscribe(() => this.pendingId.set(void 0));
|
|
455
475
|
}
|
|
456
476
|
}
|
|
457
477
|
select(render, event) {
|
|
@@ -470,6 +490,7 @@ var NavigationBarComponent = class NavigationBarComponent {
|
|
|
470
490
|
if (render.href && (mouse.ctrlKey || mouse.metaKey || mouse.shiftKey || mouse.button === 1)) return;
|
|
471
491
|
if (render.routed && render.href) {
|
|
472
492
|
event.preventDefault();
|
|
493
|
+
if (this.routerDriven()) this.pendingId.set(item.id);
|
|
473
494
|
this.router?.navigateByUrl(render.href);
|
|
474
495
|
}
|
|
475
496
|
this.selectedId.set(item.id);
|