refactor(ui): fix prime menu positioning + cleanup (#1377)
This commit is contained in:
@@ -1,18 +0,0 @@
|
|||||||
export interface MenuItem {
|
|
||||||
readonly label: string;
|
|
||||||
readonly icon?: string;
|
|
||||||
readonly routerLink?: readonly string[];
|
|
||||||
readonly action?: () => void;
|
|
||||||
readonly disabled?: boolean;
|
|
||||||
readonly children?: readonly MenuEntry[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface MenuSeparator {
|
|
||||||
readonly separator: true;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type MenuEntry = MenuItem | MenuSeparator;
|
|
||||||
|
|
||||||
export function isMenuSeparator(entry: MenuEntry): entry is MenuSeparator {
|
|
||||||
return 'separator' in entry && entry.separator === true;
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
import type { ConnectedPosition } from '@angular/cdk/overlay';
|
|
||||||
|
|
||||||
export const ABOVE_ALIGN_LEFT: ConnectedPosition[] = [
|
|
||||||
{ originX: 'start', originY: 'top', overlayX: 'start', overlayY: 'bottom', offsetY: -8 },
|
|
||||||
{ originX: 'start', originY: 'bottom', overlayX: 'start', overlayY: 'top', offsetY: 8 },
|
|
||||||
];
|
|
||||||
|
|
||||||
export const BELOW_ALIGN_LEFT: ConnectedPosition[] = [
|
|
||||||
{ originX: 'start', originY: 'bottom', overlayX: 'start', overlayY: 'top', offsetY: 8 },
|
|
||||||
{ originX: 'start', originY: 'top', overlayX: 'start', overlayY: 'bottom', offsetY: -8 },
|
|
||||||
];
|
|
||||||
|
|
||||||
export const BESIDE_RIGHT_BOTTOM: ConnectedPosition[] = [
|
|
||||||
{ originX: 'end', originY: 'bottom', overlayX: 'start', overlayY: 'bottom', offsetX: 8 },
|
|
||||||
];
|
|
||||||
|
|
||||||
export const SUBMENU_RIGHT: ConnectedPosition[] = [
|
|
||||||
{ originX: 'end', originY: 'top', overlayX: 'start', overlayY: 'top', offsetX: 0 },
|
|
||||||
{ originX: 'start', originY: 'top', overlayX: 'end', overlayY: 'top', offsetX: 0 },
|
|
||||||
];
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
<ng-template
|
|
||||||
cdkConnectedOverlay
|
|
||||||
[cdkConnectedOverlayOrigin]="origin()"
|
|
||||||
[cdkConnectedOverlayOpen]="open()"
|
|
||||||
[cdkConnectedOverlayPositions]="positions()"
|
|
||||||
[cdkConnectedOverlayViewportMargin]="8"
|
|
||||||
[cdkConnectedOverlayPush]="true"
|
|
||||||
[cdkConnectedOverlayFlexibleDimensions]="true"
|
|
||||||
>
|
|
||||||
<div ngMenu #inner="ngMenu" class="menu-panel" (itemSelected)="onSelected($event)">
|
|
||||||
<ng-template ngMenuContent>
|
|
||||||
@for (entry of items(); track $index) {
|
|
||||||
@if (isSeparator(entry)) {
|
|
||||||
<div role="separator" class="menu-separator"></div>
|
|
||||||
} @else if (entry.children?.length) {
|
|
||||||
<button
|
|
||||||
ngMenuItem
|
|
||||||
#aria="ngMenuItem"
|
|
||||||
#subTrigger
|
|
||||||
type="button"
|
|
||||||
class="menu-item"
|
|
||||||
[value]="entry"
|
|
||||||
[submenu]="subMenu.menuRef()"
|
|
||||||
[disabled]="entry.disabled ?? false"
|
|
||||||
>
|
|
||||||
@if (entry.icon) { <i [class]="entry.icon" aria-hidden="true"></i> }
|
|
||||||
<span>{{ entry.label }}</span>
|
|
||||||
<i class="pi pi-chevron-right menu-chevron" aria-hidden="true"></i>
|
|
||||||
</button>
|
|
||||||
<app-menu
|
|
||||||
#subMenu="appMenu"
|
|
||||||
[origin]="subTrigger"
|
|
||||||
[open]="aria.expanded() ?? false"
|
|
||||||
[items]="entry.children ?? []"
|
|
||||||
[positions]="submenuPositions"
|
|
||||||
></app-menu>
|
|
||||||
} @else {
|
|
||||||
<button
|
|
||||||
ngMenuItem
|
|
||||||
type="button"
|
|
||||||
class="menu-item"
|
|
||||||
[value]="entry"
|
|
||||||
[disabled]="entry.disabled ?? false"
|
|
||||||
>
|
|
||||||
@if (entry.icon) { <i [class]="entry.icon" aria-hidden="true"></i> }
|
|
||||||
<span>{{ entry.label }}</span>
|
|
||||||
</button>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</ng-template>
|
|
||||||
</div>
|
|
||||||
</ng-template>
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
import { ChangeDetectionStrategy, Component, ElementRef, inject, input, viewChild } from '@angular/core';
|
|
||||||
import { Router } from '@angular/router';
|
|
||||||
import { CdkConnectedOverlay, ConnectedPosition } from '@angular/cdk/overlay';
|
|
||||||
import { Menu as AriaMenu, MenuContent, MenuItem as AriaMenuItem } from '@angular/aria/menu';
|
|
||||||
import { MenuEntry, MenuItem, isMenuSeparator } from './menu-item.model';
|
|
||||||
import { SUBMENU_RIGHT } from './menu-positions';
|
|
||||||
|
|
||||||
type OriginInput = HTMLElement | ElementRef;
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'app-menu',
|
|
||||||
exportAs: 'appMenu',
|
|
||||||
imports: [CdkConnectedOverlay, AriaMenu, AriaMenuItem, MenuContent],
|
|
||||||
styles: `:host { display: contents; }`,
|
|
||||||
templateUrl: './menu.component.html',
|
|
||||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
||||||
})
|
|
||||||
export class MenuComponent {
|
|
||||||
protected readonly submenuPositions = SUBMENU_RIGHT;
|
|
||||||
|
|
||||||
readonly origin = input.required<OriginInput>();
|
|
||||||
readonly open = input.required<boolean>();
|
|
||||||
readonly items = input.required<readonly MenuEntry[]>();
|
|
||||||
readonly positions = input.required<ConnectedPosition[]>();
|
|
||||||
|
|
||||||
readonly menuRef = viewChild<AriaMenu<MenuItem>>('inner');
|
|
||||||
|
|
||||||
private readonly router = inject(Router);
|
|
||||||
|
|
||||||
protected readonly isSeparator = isMenuSeparator;
|
|
||||||
|
|
||||||
protected onSelected(item: MenuItem): void {
|
|
||||||
if (item.routerLink) {
|
|
||||||
this.router.navigate(item.routerLink);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
item.action?.();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -90,7 +90,7 @@
|
|||||||
[popup]="true"
|
[popup]="true"
|
||||||
appendTo="body"
|
appendTo="body"
|
||||||
styleClass="sidebar-entity-menu"
|
styleClass="sidebar-entity-menu"
|
||||||
(onShow)="positionContextMenu(entitymenu)"
|
(onShow)="markContextMenuOpen()"
|
||||||
(onHide)="closeContextMenu()"
|
(onHide)="closeContextMenu()"
|
||||||
></p-menu>
|
></p-menu>
|
||||||
} @else if (currentItem.bookCount) {
|
} @else if (currentItem.bookCount) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ChangeDetectionStrategy, Component, Renderer2, RendererStyleFlags2, computed, inject, input, signal } from '@angular/core';
|
import { ChangeDetectionStrategy, Component, computed, inject, input, signal } from '@angular/core';
|
||||||
import { RouterLink } from '@angular/router';
|
import { RouterLink } from '@angular/router';
|
||||||
import { Menu } from 'primeng/menu';
|
import { Menu } from 'primeng/menu';
|
||||||
import { Tooltip } from 'primeng/tooltip';
|
import { Tooltip } from 'primeng/tooltip';
|
||||||
@@ -35,8 +35,6 @@ export class AppSidebarItemRowComponent {
|
|||||||
|
|
||||||
private readonly userService = inject(UserService);
|
private readonly userService = inject(UserService);
|
||||||
readonly layoutService = inject(LayoutService);
|
readonly layoutService = inject(LayoutService);
|
||||||
private readonly renderer = inject(Renderer2);
|
|
||||||
private contextMenuTrigger: HTMLElement | null = null;
|
|
||||||
|
|
||||||
readonly isRouteActive = computed(() => {
|
readonly isRouteActive = computed(() => {
|
||||||
const route = this.item().routerLink?.[0];
|
const route = this.item().routerLink?.[0];
|
||||||
@@ -58,43 +56,15 @@ export class AppSidebarItemRowComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
openContextMenu(event: Event, menu: Menu): void {
|
openContextMenu(event: Event, menu: Menu): void {
|
||||||
this.contextMenuTrigger = event.currentTarget instanceof HTMLElement
|
|
||||||
? event.currentTarget
|
|
||||||
: null;
|
|
||||||
menu.toggle(event);
|
menu.toggle(event);
|
||||||
event.stopPropagation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
positionContextMenu(menu: Menu): void {
|
markContextMenuOpen(): void {
|
||||||
this.menuOpen.set(true);
|
this.menuOpen.set(true);
|
||||||
if (this.layoutService.isDesktop()) return;
|
|
||||||
|
|
||||||
const trigger = this.contextMenuTrigger;
|
|
||||||
const panel = menu.container;
|
|
||||||
if (!trigger || !(panel instanceof HTMLElement)) return;
|
|
||||||
|
|
||||||
const gutter = 8;
|
|
||||||
const rect = trigger.getBoundingClientRect();
|
|
||||||
const panelWidth = panel.offsetWidth;
|
|
||||||
const panelHeight = panel.offsetHeight;
|
|
||||||
const spaceAbove = rect.top - gutter;
|
|
||||||
const spaceBelow = window.innerHeight - rect.bottom - gutter;
|
|
||||||
const placeBelow = spaceBelow >= panelHeight || spaceBelow >= spaceAbove;
|
|
||||||
const availableHeight = Math.max(placeBelow ? spaceBelow : spaceAbove, 0);
|
|
||||||
const left = Math.max(Math.min(rect.right + gutter, window.innerWidth - panelWidth - gutter), gutter);
|
|
||||||
const top = placeBelow
|
|
||||||
? rect.bottom + gutter
|
|
||||||
: rect.top - Math.min(panelHeight, availableHeight) - gutter;
|
|
||||||
|
|
||||||
const flags = RendererStyleFlags2.DashCase;
|
|
||||||
this.renderer.setStyle(panel, '--sidebar-popover-left', `${left}px`, flags);
|
|
||||||
this.renderer.setStyle(panel, '--sidebar-popover-top', `${Math.max(top, gutter)}px`, flags);
|
|
||||||
this.renderer.setStyle(panel, '--sidebar-popover-max-height', `${availableHeight}px`, flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
closeContextMenu(): void {
|
closeContextMenu(): void {
|
||||||
this.menuOpen.set(false);
|
this.menuOpen.set(false);
|
||||||
this.contextMenuTrigger = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getIconSelection(): IconSelection | null {
|
getIconSelection(): IconSelection | null {
|
||||||
|
|||||||
@@ -50,26 +50,27 @@
|
|||||||
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
ngMenuTrigger
|
|
||||||
#addMobileTrigger="ngMenuTrigger"
|
|
||||||
#addMobileOrigin
|
|
||||||
[menu]="addMobileMenu.menuRef()"
|
|
||||||
class="sidebar-icon-button sidebar-mobile-landscape-action"
|
class="sidebar-icon-button sidebar-mobile-landscape-action"
|
||||||
[pTooltip]="t('add')"
|
[pTooltip]="t('add')"
|
||||||
[tooltipDisabled]="!layoutService.isDesktop()"
|
[tooltipDisabled]="!layoutService.isDesktop()"
|
||||||
tooltipPosition="bottom"
|
tooltipPosition="bottom"
|
||||||
[attr.aria-label]="t('add')"
|
[attr.aria-label]="t('add')"
|
||||||
|
aria-haspopup="menu"
|
||||||
|
[attr.aria-expanded]="addMenuOpen() ? 'true' : 'false'"
|
||||||
|
(click)="toggleAddMenu($event, addMenu)"
|
||||||
>
|
>
|
||||||
<i class="pi pi-plus" aria-hidden="true"></i>
|
<i class="pi pi-plus" aria-hidden="true"></i>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<app-menu
|
<p-menu
|
||||||
#addMobileMenu="appMenu"
|
#addMenu
|
||||||
[origin]="addMobileOrigin"
|
[model]="addMenuItems()"
|
||||||
[open]="addMobileTrigger.expanded()"
|
[popup]="true"
|
||||||
[items]="addMenuItems()"
|
appendTo="body"
|
||||||
[positions]="mobileMenuPositions"
|
styleClass="sidebar-create-menu"
|
||||||
></app-menu>
|
(onShow)="addMenuOpen.set(true)"
|
||||||
|
(onHide)="addMenuOpen.set(false)"
|
||||||
|
></p-menu>
|
||||||
|
|
||||||
@if (canUploadBooks()) {
|
@if (canUploadBooks()) {
|
||||||
<button
|
<button
|
||||||
@@ -87,6 +88,8 @@
|
|||||||
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
cdkOverlayOrigin
|
||||||
|
#notificationsMobileOrigin="cdkOverlayOrigin"
|
||||||
class="sidebar-icon-button sidebar-mobile-landscape-action sidebar-notification-button"
|
class="sidebar-icon-button sidebar-mobile-landscape-action sidebar-notification-button"
|
||||||
[attr.aria-label]="t('notifications')"
|
[attr.aria-label]="t('notifications')"
|
||||||
[pTooltip]="t('notifications')"
|
[pTooltip]="t('notifications')"
|
||||||
@@ -94,7 +97,7 @@
|
|||||||
tooltipPosition="bottom"
|
tooltipPosition="bottom"
|
||||||
aria-haspopup="dialog"
|
aria-haspopup="dialog"
|
||||||
[attr.aria-expanded]="notificationsOpen() ? 'true' : 'false'"
|
[attr.aria-expanded]="notificationsOpen() ? 'true' : 'false'"
|
||||||
(click)="openSidebarOverlay($event, notificationsPopover, 'below')"
|
(click)="toggleHeaderNotificationsPopover(notificationsMobileOrigin)"
|
||||||
>
|
>
|
||||||
<span class="sidebar-notification-button-content">
|
<span class="sidebar-notification-button-content">
|
||||||
<i class="pi pi-bell" aria-hidden="true"></i>
|
<i class="pi pi-bell" aria-hidden="true"></i>
|
||||||
@@ -104,10 +107,6 @@
|
|||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<p-popover #notificationsPopover appendTo="body" styleClass="sidebar-flyout-popover" (onShow)="notificationsOpen.set(true); applySidebarOverlayPosition(notificationsPopover)" (onHide)="notificationsOpen.set(false)">
|
|
||||||
<app-unified-notification-popover-component></app-unified-notification-popover-component>
|
|
||||||
</p-popover>
|
|
||||||
|
|
||||||
@if (currentUser(); as user) {
|
@if (currentUser(); as user) {
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -160,28 +159,19 @@
|
|||||||
<div class="sidebar-footer-actions">
|
<div class="sidebar-footer-actions">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
ngMenuTrigger
|
|
||||||
#addFooterTrigger="ngMenuTrigger"
|
|
||||||
#addFooterOrigin
|
|
||||||
[menu]="addFooterMenu.menuRef()"
|
|
||||||
class="sidebar-action-link sidebar-footer-action sidebar-toolbar-button"
|
class="sidebar-action-link sidebar-footer-action sidebar-toolbar-button"
|
||||||
[pTooltip]="t('add')"
|
[pTooltip]="t('add')"
|
||||||
[tooltipDisabled]="!layoutService.isDesktop()"
|
[tooltipDisabled]="!layoutService.isDesktop()"
|
||||||
tooltipPosition="top"
|
tooltipPosition="top"
|
||||||
[attr.aria-label]="t('add')"
|
[attr.aria-label]="t('add')"
|
||||||
|
aria-haspopup="menu"
|
||||||
|
[attr.aria-expanded]="addMenuOpen() ? 'true' : 'false'"
|
||||||
|
(click)="toggleAddMenu($event, addMenu)"
|
||||||
>
|
>
|
||||||
<i class="pi pi-plus" aria-hidden="true"></i>
|
<i class="pi pi-plus" aria-hidden="true"></i>
|
||||||
<span class="sidebar-footer-action-label">{{ t('add') }}</span>
|
<span class="sidebar-footer-action-label">{{ t('add') }}</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<app-menu
|
|
||||||
#addFooterMenu="appMenu"
|
|
||||||
[origin]="addFooterOrigin"
|
|
||||||
[open]="addFooterTrigger.expanded()"
|
|
||||||
[items]="addMenuItems()"
|
|
||||||
[positions]="footerMenuPositions()"
|
|
||||||
></app-menu>
|
|
||||||
|
|
||||||
@if (canUploadBooks()) {
|
@if (canUploadBooks()) {
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -199,12 +189,16 @@
|
|||||||
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
cdkOverlayOrigin
|
||||||
|
#notificationsFooterOrigin="cdkOverlayOrigin"
|
||||||
class="sidebar-action-link sidebar-footer-action sidebar-notification-button"
|
class="sidebar-action-link sidebar-footer-action sidebar-notification-button"
|
||||||
[attr.aria-label]="t('notifications')"
|
[attr.aria-label]="t('notifications')"
|
||||||
[pTooltip]="t('notifications')"
|
[pTooltip]="t('notifications')"
|
||||||
[tooltipDisabled]="!layoutService.isDesktop()"
|
[tooltipDisabled]="!layoutService.isDesktop()"
|
||||||
tooltipPosition="top"
|
tooltipPosition="top"
|
||||||
(click)="openSidebarOverlay($event, notificationsPopover, layoutService.isDesktop() ? 'below' : 'above')"
|
aria-haspopup="dialog"
|
||||||
|
[attr.aria-expanded]="notificationsOpen() ? 'true' : 'false'"
|
||||||
|
(click)="toggleFooterNotificationsPopover(notificationsFooterOrigin)"
|
||||||
>
|
>
|
||||||
<span class="sidebar-notification-button-content">
|
<span class="sidebar-notification-button-content">
|
||||||
<i class="pi pi-bell" aria-hidden="true"></i>
|
<i class="pi pi-bell" aria-hidden="true"></i>
|
||||||
@@ -281,6 +275,36 @@
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@if (notificationPopoverOrigin(); as notificationsOrigin) {
|
||||||
|
<ng-template
|
||||||
|
cdkConnectedOverlay
|
||||||
|
[cdkConnectedOverlayOrigin]="notificationsOrigin"
|
||||||
|
[cdkConnectedOverlayOpen]="notificationsOpen()"
|
||||||
|
[cdkConnectedOverlayPositions]="notificationPopoverPositions()"
|
||||||
|
[cdkConnectedOverlayViewportMargin]="8"
|
||||||
|
[cdkConnectedOverlayPush]="true"
|
||||||
|
[cdkConnectedOverlayFlexibleDimensions]="true"
|
||||||
|
[cdkConnectedOverlayHasBackdrop]="true"
|
||||||
|
cdkConnectedOverlayBackdropClass="cdk-overlay-transparent-backdrop"
|
||||||
|
cdkConnectedOverlayPanelClass="sidebar-notification-popover-pane"
|
||||||
|
(backdropClick)="closeNotificationsPopover()"
|
||||||
|
(detach)="closeNotificationsPopover()"
|
||||||
|
>
|
||||||
|
<section
|
||||||
|
class="sidebar-notification-popover surface-page"
|
||||||
|
role="dialog"
|
||||||
|
aria-modal="true"
|
||||||
|
tabindex="-1"
|
||||||
|
cdkTrapFocus
|
||||||
|
cdkTrapFocusAutoCapture
|
||||||
|
[attr.aria-label]="t('notifications')"
|
||||||
|
(keydown)="onNotificationsPopoverKeydown($event)"
|
||||||
|
>
|
||||||
|
<app-unified-notification-popover-component></app-unified-notification-popover-component>
|
||||||
|
</section>
|
||||||
|
</ng-template>
|
||||||
|
}
|
||||||
|
|
||||||
@if (currentUser(); as user) {
|
@if (currentUser(); as user) {
|
||||||
@if (userPopoverOrigin(); as userOrigin) {
|
@if (userPopoverOrigin(); as userOrigin) {
|
||||||
<ng-template
|
<ng-template
|
||||||
|
|||||||
@@ -16,8 +16,7 @@
|
|||||||
margin-bottom: var(--sidebar-header-gap-after);
|
margin-bottom: var(--sidebar-header-gap-after);
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar-header > p-menu,
|
.sidebar-header > p-menu {
|
||||||
.sidebar-header > p-popover {
|
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { computed, signal, WritableSignal } from '@angular/core';
|
import { computed, signal, WritableSignal } from '@angular/core';
|
||||||
|
import { CdkOverlayOrigin } from '@angular/cdk/overlay';
|
||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { BehaviorSubject } from 'rxjs';
|
import { BehaviorSubject } from 'rxjs';
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||||
@@ -26,25 +27,6 @@ import { LayoutService } from '../layout.service';
|
|||||||
|
|
||||||
import { AppSidebarComponent } from './app.sidebar.component';
|
import { AppSidebarComponent } from './app.sidebar.component';
|
||||||
|
|
||||||
interface PopoverOverlay {
|
|
||||||
container: HTMLElement;
|
|
||||||
toggle: (event: MouseEvent) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createRect(top: number, bottom: number, left: number): DOMRect {
|
|
||||||
return {
|
|
||||||
x: left,
|
|
||||||
y: top,
|
|
||||||
top,
|
|
||||||
bottom,
|
|
||||||
left,
|
|
||||||
right: left + 40,
|
|
||||||
width: 40,
|
|
||||||
height: bottom - top,
|
|
||||||
toJSON: () => ({}),
|
|
||||||
} as DOMRect;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface TestUser {
|
interface TestUser {
|
||||||
name: string;
|
name: string;
|
||||||
username: string;
|
username: string;
|
||||||
@@ -131,10 +113,6 @@ describe('AppSidebarComponent', () => {
|
|||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
layoutService.isDesktop.set(true);
|
layoutService.isDesktop.set(true);
|
||||||
layoutService.closeMobileSidebar.mockReset();
|
layoutService.closeMobileSidebar.mockReset();
|
||||||
vi.spyOn(window, 'requestAnimationFrame').mockImplementation((callback: FrameRequestCallback): number => {
|
|
||||||
callback(0);
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -154,33 +132,33 @@ describe('AppSidebarComponent', () => {
|
|||||||
expect(layoutService.closeMobileSidebar).toHaveBeenCalled();
|
expect(layoutService.closeMobileSidebar).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('anchors above-placement overlays from the trigger top edge when the sidebar is expanded', () => {
|
it('opens the notifications overlay from the selected origin', () => {
|
||||||
const trigger = document.createElement('button');
|
const origin = {} as CdkOverlayOrigin;
|
||||||
vi.spyOn(trigger, 'getBoundingClientRect').mockReturnValue(createRect(100, 148, 40));
|
const sidebar = component as unknown as {
|
||||||
const container = document.createElement('div');
|
notificationsOpen: () => boolean;
|
||||||
const overlay = { container, toggle: vi.fn() };
|
notificationPopoverOrigin: () => CdkOverlayOrigin | null;
|
||||||
const popoverHarness = component as unknown as { applySidebarOverlayPosition(overlay: PopoverOverlay): void };
|
toggleFooterNotificationsPopover(origin: CdkOverlayOrigin): void;
|
||||||
|
};
|
||||||
|
|
||||||
component.openSidebarOverlay({ currentTarget: trigger } as unknown as MouseEvent, overlay as never, 'above');
|
sidebar.toggleFooterNotificationsPopover(origin);
|
||||||
popoverHarness.applySidebarOverlayPosition(overlay);
|
|
||||||
|
|
||||||
expect(overlay.toggle).toHaveBeenCalled();
|
expect(sidebar.notificationsOpen()).toBe(true);
|
||||||
expect(container.style.getPropertyValue('--sidebar-popover-top')).toBe('92px');
|
expect(sidebar.notificationPopoverOrigin()).toBe(origin);
|
||||||
expect(container.style.getPropertyValue('--sidebar-popover-left')).toBe('40px');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('anchors below-placement overlays from the trigger bottom edge', () => {
|
it('closes the notifications overlay when the same origin is toggled again', () => {
|
||||||
const trigger = document.createElement('button');
|
const origin = {} as CdkOverlayOrigin;
|
||||||
vi.spyOn(trigger, 'getBoundingClientRect').mockReturnValue(createRect(220, 260, 24));
|
const sidebar = component as unknown as {
|
||||||
const container = document.createElement('div');
|
notificationsOpen: () => boolean;
|
||||||
const overlay = { container, toggle: vi.fn() };
|
notificationPopoverOrigin: () => CdkOverlayOrigin | null;
|
||||||
const popoverHarness = component as unknown as { applySidebarOverlayPosition(overlay: PopoverOverlay): void };
|
toggleFooterNotificationsPopover(origin: CdkOverlayOrigin): void;
|
||||||
|
};
|
||||||
|
|
||||||
component.openSidebarOverlay({ currentTarget: trigger } as unknown as MouseEvent, overlay as never, 'below');
|
sidebar.toggleFooterNotificationsPopover(origin);
|
||||||
popoverHarness.applySidebarOverlayPosition(overlay);
|
sidebar.toggleFooterNotificationsPopover(origin);
|
||||||
|
|
||||||
expect(container.style.getPropertyValue('--sidebar-popover-top')).toBe('268px');
|
expect(sidebar.notificationsOpen()).toBe(false);
|
||||||
expect(container.style.getPropertyValue('--sidebar-popover-left')).toBe('');
|
expect(sidebar.notificationPopoverOrigin()).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('derives user initials from a multi-part display name', () => {
|
it('derives user initials from a multi-part display name', () => {
|
||||||
@@ -233,21 +211,40 @@ describe('AppSidebarComponent', () => {
|
|||||||
expect(sidebar.updateAvailable()).toBe(true);
|
expect(sidebar.updateAvailable()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('anchors notifications above the trigger and keeps them inside the viewport on mobile', () => {
|
it('moves the notifications overlay when another origin is selected', () => {
|
||||||
layoutService.isDesktop.set(false);
|
const firstOrigin = {} as CdkOverlayOrigin;
|
||||||
|
const secondOrigin = {} as CdkOverlayOrigin;
|
||||||
|
const sidebar = component as unknown as {
|
||||||
|
notificationsOpen: () => boolean;
|
||||||
|
notificationPopoverOrigin: () => CdkOverlayOrigin | null;
|
||||||
|
toggleFooterNotificationsPopover(origin: CdkOverlayOrigin): void;
|
||||||
|
toggleHeaderNotificationsPopover(origin: CdkOverlayOrigin): void;
|
||||||
|
};
|
||||||
|
|
||||||
const trigger = document.createElement('button');
|
sidebar.toggleFooterNotificationsPopover(firstOrigin);
|
||||||
vi.spyOn(trigger, 'getBoundingClientRect').mockReturnValue(createRect(220, 260, 980));
|
sidebar.toggleHeaderNotificationsPopover(secondOrigin);
|
||||||
const container = document.createElement('div');
|
|
||||||
Object.defineProperty(container, 'offsetWidth', { value: 120, configurable: true });
|
|
||||||
const overlay = { container, toggle: vi.fn() };
|
|
||||||
const popoverHarness = component as unknown as { applySidebarOverlayPosition(overlay: PopoverOverlay): void };
|
|
||||||
|
|
||||||
component.openSidebarOverlay({ currentTarget: trigger } as unknown as MouseEvent, overlay as never, 'above');
|
expect(sidebar.notificationsOpen()).toBe(true);
|
||||||
popoverHarness.applySidebarOverlayPosition(overlay);
|
expect(sidebar.notificationPopoverOrigin()).toBe(secondOrigin);
|
||||||
|
});
|
||||||
|
|
||||||
expect(container.style.getPropertyValue('--sidebar-popover-top')).toBe('212px');
|
it('closes the notifications overlay when Escape is pressed inside the dialog', () => {
|
||||||
expect(container.style.getPropertyValue('--sidebar-popover-left')).toBe(`${window.innerWidth - 128}px`);
|
const origin = {} as CdkOverlayOrigin;
|
||||||
|
const event = new KeyboardEvent('keydown', { key: 'Escape' });
|
||||||
|
const preventDefault = vi.spyOn(event, 'preventDefault');
|
||||||
|
const sidebar = component as unknown as {
|
||||||
|
notificationsOpen: () => boolean;
|
||||||
|
notificationPopoverOrigin: () => CdkOverlayOrigin | null;
|
||||||
|
toggleFooterNotificationsPopover(origin: CdkOverlayOrigin): void;
|
||||||
|
onNotificationsPopoverKeydown(event: KeyboardEvent): void;
|
||||||
|
};
|
||||||
|
|
||||||
|
sidebar.toggleFooterNotificationsPopover(origin);
|
||||||
|
sidebar.onNotificationsPopoverKeydown(event);
|
||||||
|
|
||||||
|
expect(preventDefault).toHaveBeenCalled();
|
||||||
|
expect(sidebar.notificationsOpen()).toBe(false);
|
||||||
|
expect(sidebar.notificationPopoverOrigin()).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('aggregates metadata tasks and pending bookdrop files into the sidebar badge count', () => {
|
it('aggregates metadata tasks and pending bookdrop files into the sidebar badge count', () => {
|
||||||
|
|||||||
@@ -1,20 +1,12 @@
|
|||||||
import { Component, DestroyRef, Renderer2, RendererStyleFlags2, computed, inject, signal } from '@angular/core';
|
import { Component, DestroyRef, computed, inject, signal } from '@angular/core';
|
||||||
import { Router, RouterLink } from '@angular/router';
|
import { Router, RouterLink } from '@angular/router';
|
||||||
import { AppSidebarSectionComponent } from './app.sidebar-section.component';
|
import { AppSidebarSectionComponent } from './app.sidebar-section.component';
|
||||||
import { MenuTrigger } from '@angular/aria/menu';
|
import { Menu } from 'primeng/menu';
|
||||||
import { Popover } from 'primeng/popover';
|
|
||||||
import { CdkTrapFocus } from '@angular/cdk/a11y';
|
import { CdkTrapFocus } from '@angular/cdk/a11y';
|
||||||
import { CdkConnectedOverlay, CdkOverlayOrigin } from '@angular/cdk/overlay';
|
import { CdkConnectedOverlay, CdkOverlayOrigin, ConnectedPosition } from '@angular/cdk/overlay';
|
||||||
import { BookDialogHelperService } from '../../../features/book/components/book-browser/book-dialog-helper.service';
|
import { BookDialogHelperService } from '../../../features/book/components/book-browser/book-dialog-helper.service';
|
||||||
import { UnifiedNotificationBoxComponent } from '../../components/unified-notification-popover/unified-notification-popover-component';
|
import { UnifiedNotificationBoxComponent } from '../../components/unified-notification-popover/unified-notification-popover-component';
|
||||||
import { AppButtonDirective } from '../../components/button/app-button.directive';
|
import { AppButtonDirective } from '../../components/button/app-button.directive';
|
||||||
import { MenuComponent } from '../../components/menu/menu.component';
|
|
||||||
import { MenuEntry } from '../../components/menu/menu-item.model';
|
|
||||||
import {
|
|
||||||
ABOVE_ALIGN_LEFT,
|
|
||||||
BELOW_ALIGN_LEFT,
|
|
||||||
BESIDE_RIGHT_BOTTOM,
|
|
||||||
} from '../../components/menu/menu-positions';
|
|
||||||
import { LibraryService } from '../../../features/book/service/library.service';
|
import { LibraryService } from '../../../features/book/service/library.service';
|
||||||
import { LibraryHealthService } from '../../../features/book/service/library-health.service';
|
import { LibraryHealthService } from '../../../features/book/service/library-health.service';
|
||||||
import { ShelfService } from '../../../features/book/service/shelf.service';
|
import { ShelfService } from '../../../features/book/service/shelf.service';
|
||||||
@@ -30,8 +22,7 @@ import { AuthService } from '../../service/auth.service';
|
|||||||
import { LayoutService } from '../layout.service';
|
import { LayoutService } from '../layout.service';
|
||||||
import { TranslocoDirective, TranslocoPipe, TranslocoService } from '@jsverse/transloco';
|
import { TranslocoDirective, TranslocoPipe, TranslocoService } from '@jsverse/transloco';
|
||||||
import { Tooltip } from 'primeng/tooltip';
|
import { Tooltip } from 'primeng/tooltip';
|
||||||
import { MessageService } from 'primeng/api';
|
import type { MenuItem } from 'primeng/api';
|
||||||
import { VersionService } from '../../service/version.service';
|
|
||||||
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
|
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
|
||||||
import { NavItem, SidebarSection } from '../navigation/nav-item.model';
|
import { NavItem, SidebarSection } from '../navigation/nav-item.model';
|
||||||
import { buildCreateActionNavItems } from '../navigation/nav-catalog';
|
import { buildCreateActionNavItems } from '../navigation/nav-catalog';
|
||||||
@@ -42,11 +33,30 @@ import {
|
|||||||
buildShelfSection,
|
buildShelfSection,
|
||||||
buildToolsSection,
|
buildToolsSection,
|
||||||
} from './sidebar-sections';
|
} from './sidebar-sections';
|
||||||
|
import { VersionService } from '../../service/version.service';
|
||||||
import { MetadataProgressService } from '../../service/metadata-progress.service';
|
import { MetadataProgressService } from '../../service/metadata-progress.service';
|
||||||
import { BookdropFileService } from '../../../features/bookdrop/service/bookdrop-file.service';
|
import { BookdropFileService } from '../../../features/bookdrop/service/bookdrop-file.service';
|
||||||
import { MetadataBatchProgressNotification, MetadataBatchStatus } from '../../model/metadata-batch-progress.model';
|
import { MetadataBatchProgressNotification, MetadataBatchStatus } from '../../model/metadata-batch-progress.model';
|
||||||
|
|
||||||
const DOCUMENTATION_URL = 'https://grimmory.org/docs/getting-started';
|
const DOCUMENTATION_URL = 'https://grimmory.org/docs/getting-started';
|
||||||
|
const ABOVE_ALIGN_LEFT: ConnectedPosition[] = [
|
||||||
|
{ originX: 'start', originY: 'top', overlayX: 'start', overlayY: 'bottom', offsetY: -8 },
|
||||||
|
{ originX: 'start', originY: 'bottom', overlayX: 'start', overlayY: 'top', offsetY: 8 },
|
||||||
|
];
|
||||||
|
const RIGHT_ALIGN_TOP: ConnectedPosition[] = [
|
||||||
|
{ originX: 'end', originY: 'top', overlayX: 'start', overlayY: 'top', offsetX: 8 },
|
||||||
|
{ originX: 'end', originY: 'bottom', overlayX: 'start', overlayY: 'bottom', offsetX: 8 },
|
||||||
|
{ originX: 'start', originY: 'top', overlayX: 'end', overlayY: 'top', offsetX: -8 },
|
||||||
|
{ originX: 'start', originY: 'bottom', overlayX: 'end', overlayY: 'bottom', offsetX: -8 },
|
||||||
|
];
|
||||||
|
const ABOVE_ALIGN_CENTER: ConnectedPosition[] = [
|
||||||
|
{ originX: 'center', originY: 'top', overlayX: 'center', overlayY: 'bottom', offsetY: -8 },
|
||||||
|
{ originX: 'center', originY: 'bottom', overlayX: 'center', overlayY: 'top', offsetY: 8 },
|
||||||
|
];
|
||||||
|
const BELOW_ALIGN_CENTER: ConnectedPosition[] = [
|
||||||
|
{ originX: 'center', originY: 'bottom', overlayX: 'center', overlayY: 'top', offsetY: 8 },
|
||||||
|
{ originX: 'center', originY: 'top', overlayX: 'center', overlayY: 'bottom', offsetY: -8 },
|
||||||
|
];
|
||||||
|
|
||||||
function computeInitials(name: string | null | undefined, username: string | null | undefined): string {
|
function computeInitials(name: string | null | undefined, username: string | null | undefined): string {
|
||||||
const source = (name?.trim() || username?.trim() || '').trim();
|
const source = (name?.trim() || username?.trim() || '').trim();
|
||||||
@@ -95,14 +105,12 @@ function isNewerVersion(latest: string | undefined, current: string | undefined)
|
|||||||
imports: [
|
imports: [
|
||||||
AppSidebarSectionComponent,
|
AppSidebarSectionComponent,
|
||||||
AppButtonDirective,
|
AppButtonDirective,
|
||||||
Popover,
|
Menu,
|
||||||
UnifiedNotificationBoxComponent,
|
UnifiedNotificationBoxComponent,
|
||||||
MenuComponent,
|
|
||||||
RouterLink,
|
RouterLink,
|
||||||
TranslocoDirective,
|
TranslocoDirective,
|
||||||
TranslocoPipe,
|
TranslocoPipe,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
MenuTrigger,
|
|
||||||
CdkTrapFocus,
|
CdkTrapFocus,
|
||||||
CdkConnectedOverlay,
|
CdkConnectedOverlay,
|
||||||
CdkOverlayOrigin,
|
CdkOverlayOrigin,
|
||||||
@@ -120,6 +128,7 @@ export class AppSidebarComponent {
|
|||||||
private readonly commandPaletteService = inject(CommandPaletteService);
|
private readonly commandPaletteService = inject(CommandPaletteService);
|
||||||
private readonly bookDialogHelperService = inject(BookDialogHelperService);
|
private readonly bookDialogHelperService = inject(BookDialogHelperService);
|
||||||
private readonly authService = inject(AuthService);
|
private readonly authService = inject(AuthService);
|
||||||
|
private readonly router = inject(Router);
|
||||||
readonly layoutService = inject(LayoutService);
|
readonly layoutService = inject(LayoutService);
|
||||||
private readonly userService = inject(UserService);
|
private readonly userService = inject(UserService);
|
||||||
private readonly versionService = inject(VersionService);
|
private readonly versionService = inject(VersionService);
|
||||||
@@ -127,12 +136,9 @@ export class AppSidebarComponent {
|
|||||||
private readonly seriesDataService = inject(SeriesDataService);
|
private readonly seriesDataService = inject(SeriesDataService);
|
||||||
private readonly authorService = inject(AuthorService);
|
private readonly authorService = inject(AuthorService);
|
||||||
private readonly t = inject(TranslocoService);
|
private readonly t = inject(TranslocoService);
|
||||||
private readonly renderer = inject(Renderer2);
|
private readonly destroyRef = inject(DestroyRef);
|
||||||
private readonly router = inject(Router);
|
private readonly metadataProgressService = inject(MetadataProgressService);
|
||||||
private readonly messageService = inject(MessageService);
|
private readonly bookdropFileService = inject(BookdropFileService);
|
||||||
private readonly destroyRef = inject(DestroyRef);
|
|
||||||
private readonly metadataProgressService = inject(MetadataProgressService);
|
|
||||||
private readonly bookdropFileService = inject(BookdropFileService);
|
|
||||||
|
|
||||||
readonly currentUser = this.userService.currentUser;
|
readonly currentUser = this.userService.currentUser;
|
||||||
private readonly allAuthors = this.authorService.allAuthors;
|
private readonly allAuthors = this.authorService.allAuthors;
|
||||||
@@ -195,7 +201,7 @@ private readonly bookdropFileService = inject(BookdropFileService);
|
|||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
readonly addMenuItems = computed<MenuEntry[]>(() => {
|
readonly addMenuItems = computed<MenuItem[]>(() => {
|
||||||
this.activeLang();
|
this.activeLang();
|
||||||
const user = this.currentUser();
|
const user = this.currentUser();
|
||||||
if (!user) return [];
|
if (!user) return [];
|
||||||
@@ -206,7 +212,7 @@ private readonly bookdropFileService = inject(BookdropFileService);
|
|||||||
createMagicShelf: () => void this.dialogLauncherService.openMagicShelfCreateDialog().catch(() => undefined),
|
createMagicShelf: () => void this.dialogLauncherService.openMagicShelfCreateDialog().catch(() => undefined),
|
||||||
uploadBook: () => void this.dialogLauncherService.openFileUploadDialog().catch(() => undefined),
|
uploadBook: () => void this.dialogLauncherService.openFileUploadDialog().catch(() => undefined),
|
||||||
});
|
});
|
||||||
return this.toMenuEntries(actions);
|
return this.toMenuItems(actions);
|
||||||
});
|
});
|
||||||
|
|
||||||
readonly userInitials = computed(() => {
|
readonly userInitials = computed(() => {
|
||||||
@@ -215,15 +221,17 @@ private readonly bookdropFileService = inject(BookdropFileService);
|
|||||||
});
|
});
|
||||||
|
|
||||||
protected readonly notificationsOpen = signal(false);
|
protected readonly notificationsOpen = signal(false);
|
||||||
|
protected readonly notificationPopoverOrigin = signal<CdkOverlayOrigin | null>(null);
|
||||||
|
private readonly notificationPopoverMobilePositions = signal<ConnectedPosition[]>(ABOVE_ALIGN_CENTER);
|
||||||
|
protected readonly addMenuOpen = signal(false);
|
||||||
|
protected readonly aboveMenuPositions = ABOVE_ALIGN_LEFT;
|
||||||
|
protected readonly notificationPopoverPositions = computed(() =>
|
||||||
|
this.layoutService.isDesktop() ? RIGHT_ALIGN_TOP : this.notificationPopoverMobilePositions()
|
||||||
|
);
|
||||||
protected progressHighlight = false;
|
protected progressHighlight = false;
|
||||||
protected completedTaskCount = 0;
|
protected completedTaskCount = 0;
|
||||||
protected hasPendingBookdropFiles = false;
|
protected hasPendingBookdropFiles = false;
|
||||||
|
|
||||||
protected readonly mobileMenuPositions = BELOW_ALIGN_LEFT;
|
|
||||||
protected readonly aboveMenuPositions = ABOVE_ALIGN_LEFT;
|
|
||||||
protected readonly footerMenuPositions = computed(() =>
|
|
||||||
this.layoutService.desktopSidebarCollapsed() ? BESIDE_RIGHT_BOTTOM : ABOVE_ALIGN_LEFT,
|
|
||||||
);
|
|
||||||
private readonly latestTasks: Record<string, MetadataBatchProgressNotification> = {};
|
private readonly latestTasks: Record<string, MetadataBatchProgressNotification> = {};
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -276,28 +284,29 @@ private readonly bookdropFileService = inject(BookdropFileService);
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected openAccountSettings(): void {
|
protected openAccountSettings(): void {
|
||||||
void this.dialogLauncherService.openUserProfileDialog().catch(() => undefined);
|
void this.dialogLauncherService.openUserProfileDialog().catch(() => undefined);
|
||||||
this.closeUserPopover();
|
this.closeUserPopover();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected openSettings(): void {
|
protected openSettings(): void {
|
||||||
this.router.navigate(['/settings']);
|
this.router.navigate(['/settings']);
|
||||||
this.closeUserPopover();
|
this.closeUserPopover();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected openChangelogDialog(): void {
|
protected openChangelogDialog(): void {
|
||||||
void this.dialogLauncherService.openVersionChangelogDialog().catch(() => undefined);
|
void this.dialogLauncherService.openVersionChangelogDialog().catch(() => undefined);
|
||||||
this.closeUserPopover();
|
this.closeUserPopover();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected openReadingStats(): void {
|
protected openReadingStats(): void {
|
||||||
this.router.navigate(['/reading-stats']);
|
this.router.navigate(['/reading-stats']);
|
||||||
this.closeUserPopover();
|
this.closeUserPopover();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected openUploadDialog(): void {
|
protected openUploadDialog(): void {
|
||||||
void this.dialogLauncherService.openFileUploadDialog().catch(() => undefined);
|
void this.dialogLauncherService.openFileUploadDialog().catch(() => undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected logout(): void {
|
protected logout(): void {
|
||||||
this.authService.logout();
|
this.authService.logout();
|
||||||
this.closeUserPopover();
|
this.closeUserPopover();
|
||||||
@@ -310,81 +319,70 @@ private readonly bookdropFileService = inject(BookdropFileService);
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly anchorByOverlay = new WeakMap<Popover, { trigger: HTMLElement; placement: 'above' | 'below' }>();
|
protected onNotificationsPopoverKeydown(event: KeyboardEvent): void {
|
||||||
|
if (event.key === 'Escape') {
|
||||||
protected applySidebarOverlayPosition(overlay: Popover): void {
|
event.preventDefault();
|
||||||
const anchor = this.anchorByOverlay.get(overlay);
|
this.closeNotificationsPopover();
|
||||||
const panel = overlay.container;
|
|
||||||
if (!anchor || !panel) return;
|
|
||||||
|
|
||||||
window.requestAnimationFrame(() => {
|
|
||||||
this.positionSidebarOverlay(anchor, panel);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private positionSidebarOverlay(
|
|
||||||
anchor: { trigger: HTMLElement; placement: 'above' | 'below' },
|
|
||||||
panel: HTMLElement,
|
|
||||||
): void {
|
|
||||||
const rect = anchor.trigger.getBoundingClientRect();
|
|
||||||
const panelWidth = panel.offsetWidth;
|
|
||||||
const panelHeight = panel.offsetHeight;
|
|
||||||
const left = Math.max(Math.min(rect.left, window.innerWidth - panelWidth - 8), 8);
|
|
||||||
const maxTop = Math.max(window.innerHeight - panelHeight - 8, 8);
|
|
||||||
|
|
||||||
const anchorAbove = anchor.placement === 'above' && !this.layoutService.desktopSidebarCollapsed();
|
|
||||||
const requestedTop = anchorAbove
|
|
||||||
? rect.top - panelHeight - 8
|
|
||||||
: rect.bottom + 8;
|
|
||||||
const top = Math.max(Math.min(requestedTop, maxTop), 8);
|
|
||||||
|
|
||||||
const flags = RendererStyleFlags2.DashCase;
|
|
||||||
this.renderer.setStyle(panel, '--sidebar-popover-top', `${top}px`, flags);
|
|
||||||
this.renderer.setStyle(panel, '--sidebar-popover-max-height', `${Math.max(window.innerHeight - top - 8, 0)}px`, flags);
|
|
||||||
|
|
||||||
if (anchorAbove || !this.layoutService.isDesktop()) {
|
|
||||||
this.renderer.setStyle(panel, '--sidebar-popover-left', `${left}px`, flags);
|
|
||||||
} else {
|
|
||||||
this.renderer.removeStyle(panel, '--sidebar-popover-left', flags);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private toMenuEntries(items: readonly (NavItem | null | undefined)[]): MenuEntry[] {
|
private toMenuItems(items: readonly (NavItem | null | undefined)[]): MenuItem[] {
|
||||||
return items.flatMap((item): MenuEntry[] =>
|
return items.flatMap((item): MenuItem[] =>
|
||||||
item ? [{
|
item ? [{
|
||||||
label: item.label,
|
label: item.label,
|
||||||
icon: item.icon ? `pi ${item.icon}` : undefined,
|
icon: item.icon ? `pi ${item.icon}` : undefined,
|
||||||
routerLink: item.routerLink,
|
routerLink: item.routerLink,
|
||||||
action: item.action,
|
command: item.action,
|
||||||
}] : []
|
}] : []
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
openSidebarOverlay(event: MouseEvent, overlay: Popover, placement: 'above' | 'below'): void {
|
protected toggleAddMenu(event: MouseEvent, menu: Menu): void {
|
||||||
if (event.currentTarget instanceof HTMLElement) {
|
menu.toggle(event);
|
||||||
this.anchorByOverlay.set(overlay, { trigger: event.currentTarget, placement });
|
}
|
||||||
|
|
||||||
|
protected toggleHeaderNotificationsPopover(origin: CdkOverlayOrigin): void {
|
||||||
|
this.toggleNotificationsPopover(origin, BELOW_ALIGN_CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected toggleFooterNotificationsPopover(origin: CdkOverlayOrigin): void {
|
||||||
|
this.toggleNotificationsPopover(origin, ABOVE_ALIGN_CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
private toggleNotificationsPopover(origin: CdkOverlayOrigin, mobilePositions = ABOVE_ALIGN_CENTER): void {
|
||||||
|
if (this.notificationsOpen() && this.notificationPopoverOrigin() === origin) {
|
||||||
|
this.closeNotificationsPopover();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
overlay.toggle(event);
|
|
||||||
|
this.notificationPopoverMobilePositions.set(mobilePositions);
|
||||||
|
this.notificationPopoverOrigin.set(origin);
|
||||||
|
this.notificationsOpen.set(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private subscribeToMetadataProgress(): void {
|
protected closeNotificationsPopover(): void {
|
||||||
this.metadataProgressService.progressUpdates$
|
this.notificationsOpen.set(false);
|
||||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
this.notificationPopoverOrigin.set(null);
|
||||||
.subscribe((progress) => {
|
|
||||||
this.progressHighlight = progress.status === MetadataBatchStatus.IN_PROGRESS;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private replaceLatestTasks(tasks: Record<string, MetadataBatchProgressNotification>): void {
|
|
||||||
for (const key of Object.keys(this.latestTasks)) {
|
|
||||||
delete this.latestTasks[key];
|
|
||||||
}
|
}
|
||||||
Object.assign(this.latestTasks, tasks);
|
|
||||||
}
|
|
||||||
|
|
||||||
private updateCompletedTaskCount(): void {
|
private subscribeToMetadataProgress(): void {
|
||||||
const metadataTaskCount = Object.keys(this.latestTasks).length;
|
this.metadataProgressService.progressUpdates$
|
||||||
const bookdropFileTaskCount = this.hasPendingBookdropFiles ? 1 : 0;
|
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||||
this.completedTaskCount = metadataTaskCount + bookdropFileTaskCount;
|
.subscribe((progress) => {
|
||||||
}
|
this.progressHighlight = progress.status === MetadataBatchStatus.IN_PROGRESS;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private replaceLatestTasks(tasks: Record<string, MetadataBatchProgressNotification>): void {
|
||||||
|
for (const key of Object.keys(this.latestTasks)) {
|
||||||
|
delete this.latestTasks[key];
|
||||||
|
}
|
||||||
|
Object.assign(this.latestTasks, tasks);
|
||||||
|
}
|
||||||
|
|
||||||
|
private updateCompletedTaskCount(): void {
|
||||||
|
const metadataTaskCount = Object.keys(this.latestTasks).length;
|
||||||
|
const bookdropFileTaskCount = this.hasPendingBookdropFiles ? 1 : 0;
|
||||||
|
this.completedTaskCount = metadataTaskCount + bookdropFileTaskCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,11 +22,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu-panel,
|
|
||||||
.user-account-popover {
|
.user-account-popover {
|
||||||
--menu-panel-padding: var(--space-1);
|
|
||||||
--menu-panel-gap: 1px;
|
|
||||||
--menu-panel-min-width: 12rem;
|
|
||||||
--menu-item-padding-block: 4px;
|
--menu-item-padding-block: 4px;
|
||||||
--menu-item-padding-inline: 10px;
|
--menu-item-padding-inline: 10px;
|
||||||
--menu-item-min-height: 28px;
|
--menu-item-min-height: 28px;
|
||||||
@@ -36,22 +32,6 @@
|
|||||||
--menu-item-danger-bg-hover: color-mix(in srgb, var(--p-red-500) 12%, transparent);
|
--menu-item-danger-bg-hover: color-mix(in srgb, var(--p-red-500) 12%, transparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu-panel {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: var(--menu-panel-gap);
|
|
||||||
min-width: var(--menu-panel-min-width);
|
|
||||||
padding: var(--menu-panel-padding);
|
|
||||||
background: var(--surface-page);
|
|
||||||
border: 1px solid var(--border-color);
|
|
||||||
border-radius: var(--control-radius);
|
|
||||||
box-shadow: 0 8px 24px rgb(0 0 0 / 18%);
|
|
||||||
color: var(--text-color);
|
|
||||||
font: inherit;
|
|
||||||
font-size: var(--text-base);
|
|
||||||
}
|
|
||||||
|
|
||||||
.menu-panel .menu-item,
|
|
||||||
.user-account-popover .menu-item {
|
.user-account-popover .menu-item {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -70,26 +50,22 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu-panel .menu-item:hover,
|
|
||||||
.user-account-popover .menu-item:hover {
|
.user-account-popover .menu-item:hover {
|
||||||
background-color: var(--surface-hover);
|
background-color: var(--surface-hover);
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu-panel .menu-item:focus-visible,
|
|
||||||
.user-account-popover .menu-item:focus-visible {
|
.user-account-popover .menu-item:focus-visible {
|
||||||
background-color: var(--surface-hover);
|
background-color: var(--surface-hover);
|
||||||
box-shadow: inset 0 0 0 1px var(--menu-item-focus-ring);
|
box-shadow: inset 0 0 0 1px var(--menu-item-focus-ring);
|
||||||
outline: none;
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu-panel .menu-item[aria-disabled="true"],
|
|
||||||
.user-account-popover .menu-item[aria-disabled="true"] {
|
.user-account-popover .menu-item[aria-disabled="true"] {
|
||||||
color: var(--text-color-secondary);
|
color: var(--text-color-secondary);
|
||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu-panel .menu-item i,
|
|
||||||
.user-account-popover .menu-item i {
|
.user-account-popover .menu-item i {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -101,16 +77,8 @@
|
|||||||
color: var(--surface-500);
|
color: var(--surface-500);
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu-panel .menu-separator {
|
|
||||||
margin: var(--menu-panel-padding) 0;
|
|
||||||
border-top: 1px solid var(--border-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
@media #{variables.$mobile-shell-media-query} {
|
@media #{variables.$mobile-shell-media-query} {
|
||||||
.menu-panel,
|
|
||||||
.user-account-popover {
|
.user-account-popover {
|
||||||
--menu-panel-padding: 6px;
|
|
||||||
--menu-panel-gap: 2px;
|
|
||||||
--menu-item-padding-block: 8px;
|
--menu-item-padding-block: 8px;
|
||||||
--menu-item-padding-inline: 12px;
|
--menu-item-padding-inline: 12px;
|
||||||
--menu-item-min-height: 40px;
|
--menu-item-min-height: 40px;
|
||||||
@@ -122,10 +90,13 @@
|
|||||||
pointer-events: auto;
|
pointer-events: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.cdk-overlay-pane.sidebar-notification-popover-pane {
|
||||||
|
pointer-events: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-notification-popover,
|
||||||
.user-account-popover {
|
.user-account-popover {
|
||||||
display: flex;
|
max-width: calc(100vw - 1rem);
|
||||||
flex-direction: column;
|
|
||||||
width: min(17.5rem, calc(100vw - 1rem));
|
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
border: 1px solid var(--border-color);
|
border: 1px solid var(--border-color);
|
||||||
border-radius: var(--control-radius);
|
border-radius: var(--control-radius);
|
||||||
@@ -136,6 +107,16 @@
|
|||||||
font: inherit;
|
font: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sidebar-notification-popover {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-account-popover {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
width: min(17.5rem, calc(100vw - 1rem));
|
||||||
|
}
|
||||||
|
|
||||||
.user-account-popover-header {
|
.user-account-popover-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|||||||
@@ -12,17 +12,6 @@
|
|||||||
* PrimeNG components can continue to use Prime's --p-* tokens.
|
* PrimeNG components can continue to use Prime's --p-* tokens.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@mixin sidebar-fixed-overlay {
|
|
||||||
position: fixed !important;
|
|
||||||
top: var(--sidebar-popover-top, 0.75rem) !important;
|
|
||||||
bottom: auto !important;
|
|
||||||
left: var(--sidebar-popover-left, calc(var(--sidebar-width, 225px) + 0.5rem)) !important;
|
|
||||||
max-height: var(--sidebar-popover-max-height, calc(100vh - 1rem)) !important;
|
|
||||||
margin: 0 !important;
|
|
||||||
overflow: auto !important;
|
|
||||||
transform: none !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.p-dialog {
|
.p-dialog {
|
||||||
--card-background: var(--surface-content);
|
--card-background: var(--surface-content);
|
||||||
|
|
||||||
@@ -166,50 +155,26 @@
|
|||||||
padding: 1rem 1.25rem !important;
|
padding: 1rem 1.25rem !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar-flyout-popover.p-popover {
|
.sidebar-create-menu.p-menu {
|
||||||
@include sidebar-fixed-overlay;
|
min-width: 12rem;
|
||||||
|
|
||||||
&::before,
|
|
||||||
&::after {
|
|
||||||
display: none !important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (width <= 991px) {
|
|
||||||
.sidebar-flyout-popover.p-popover {
|
|
||||||
max-width: calc(100vw - 1rem) !important;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media #{variables.$mobile-shell-media-query} {
|
@media #{variables.$mobile-shell-media-query} {
|
||||||
.sidebar-entity-menu.p-menu {
|
.p-menu {
|
||||||
@include sidebar-fixed-overlay;
|
--p-menu-list-padding: var(--space-2) 0;
|
||||||
|
--p-menu-item-padding: var(--space-3) var(--space-4);
|
||||||
.p-menu-submenu-label {
|
--p-menu-item-gap: var(--space-3);
|
||||||
display: none !important;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar-entity-menu.p-menu,
|
.p-tieredmenu {
|
||||||
.sidebar-more-menu.p-menu,
|
--p-tieredmenu-list-padding: var(--space-2) 0;
|
||||||
.sidebar-user-menu.p-menu,
|
--p-tieredmenu-item-padding: var(--space-3) var(--space-4);
|
||||||
.sidebar-flyout-popover.p-popover .p-menu,
|
--p-tieredmenu-item-gap: var(--space-3);
|
||||||
.sidebar-flyout-popover.p-popover .p-tieredmenu {
|
}
|
||||||
> .p-menu-list,
|
|
||||||
.p-menu-list,
|
|
||||||
> .p-tieredmenu-root-list,
|
|
||||||
.p-tieredmenu-root-list,
|
|
||||||
.p-tieredmenu-submenu {
|
|
||||||
padding-block: var(--space-2) !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.p-menu-item-content > .p-menu-item-link,
|
.sidebar-entity-menu.p-menu {
|
||||||
.p-menu-item-link,
|
.p-menu-submenu-label {
|
||||||
.p-tieredmenu-item-content > .p-tieredmenu-item-link,
|
display: none;
|
||||||
.p-tieredmenu-item-link {
|
|
||||||
min-height: 3rem !important;
|
|
||||||
padding: var(--space-3) var(--space-4) !important;
|
|
||||||
gap: var(--space-3) !important;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user