UNPKG

@progress/kendo-angular-buttons

Version:
112 lines (111 loc) 4.74 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { Injectable, Inject, EventEmitter } from '@angular/core'; import { isPresent } from './../util'; import { KeyEvents } from './key-events'; import { Keys } from '@progress/kendo-angular-common'; import { NavigationAction } from './navigation-action'; import { NAVIGATION_CONFIG } from './navigation-config'; import * as i0 from "@angular/core"; /** * @hidden */ export class NavigationService { navigate = new EventEmitter(); open = new EventEmitter(); close = new EventEmitter(); enter = new EventEmitter(); enterpress = new EventEmitter(); enterup = new EventEmitter(); tab = new EventEmitter(); esc = new EventEmitter(); useLeftRightArrows; constructor(config) { this.useLeftRightArrows = config.useLeftRightArrows; } process(args) { const keyCode = args.keyCode; const keyEvent = args.keyEvent; let index; let action = NavigationAction.Undefined; if (keyEvent === KeyEvents.keyup) { if (this.isEnterOrSpace(keyCode)) { action = NavigationAction.EnterUp; } } else { if (args.altKey && keyCode === Keys.ArrowDown) { action = NavigationAction.Open; } else if (args.altKey && keyCode === Keys.ArrowUp) { action = NavigationAction.Close; } else if (this.isEnterOrSpace(keyCode)) { action = NavigationAction.Enter; } else if (keyCode === Keys.Escape) { action = NavigationAction.Esc; } else if (keyCode === Keys.Tab) { action = NavigationAction.Tab; } else if (keyCode === Keys.ArrowUp || (this.useLeftRightArrows && keyCode === Keys.ArrowLeft)) { const step = args.flipNavigation ? 1 : -1; const start = args.flipNavigation ? args.min : args.max; const end = args.flipNavigation ? args.max : args.min; index = this.next({ current: args.current, start: start, end: end, step: step }); action = NavigationAction.Navigate; } else if (keyCode === Keys.ArrowDown || (this.useLeftRightArrows && keyCode === Keys.ArrowRight)) { const step = args.flipNavigation ? -1 : 1; const start = args.flipNavigation ? args.max : args.min; const end = args.flipNavigation ? args.min : args.max; index = this.next({ current: args.current, start: start, end: end, step: step }); action = NavigationAction.Navigate; } else if (keyCode === Keys.Home) { index = args.min; action = NavigationAction.Navigate; } else if (keyCode === Keys.End) { index = args.max; action = NavigationAction.Navigate; } } if (action !== NavigationAction.Undefined) { this[NavigationAction[action].toLowerCase()].emit({ index, target: args.target, esc: action === NavigationAction.Esc }); } return action; } isEnterOrSpace(keyCode) { return keyCode === Keys.Enter || keyCode === Keys.Space; } next(args) { if (!isPresent(args.current)) { return args.start; } else { return args.current !== args.end ? args.current + args.step : args.end; } } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NavigationService, deps: [{ token: NAVIGATION_CONFIG }], target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NavigationService }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NavigationService, decorators: [{ type: Injectable }], ctorParameters: function () { return [{ type: undefined, decorators: [{ type: Inject, args: [NAVIGATION_CONFIG] }] }]; } });