@ng-doc/ui-kit
Version:
<!-- PROJECT LOGO --> <br /> <div align="center"> <a href="https://github.com/ng-doc/ng-doc"> <img src="https://ng-doc.com/assets/images/ng-doc.svg?raw=true" alt="Logo" height="150px"> </a>
52 lines (48 loc) • 2.52 kB
JavaScript
import * as i0 from '@angular/core';
import { inject, NgZone, EventEmitter, DestroyRef, afterNextRender, Output, Input, Directive } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { isKeyboardEvent } from '@ng-doc/core/helpers/is-keyboard-event';
import { objectKeys } from '@ng-doc/core/helpers/object-keys';
import { ngDocZoneOptimize } from '@ng-doc/ui-kit/observables';
import { fromEvent } from 'rxjs';
import { filter } from 'rxjs/operators';
class NgDocHotkeyDirective {
constructor() {
this.ngZone = inject(NgZone);
this.callback = new EventEmitter();
const destroyRef = inject(DestroyRef);
afterNextRender(() => {
fromEvent(document, 'keyup')
.pipe(filter(isKeyboardEvent), filter((event) => objectKeys(this.hotkey ?? {}).every((key) => this.hotkey && this.hotkey[key] === event[key])), filter((event) => {
if (event.target instanceof HTMLElement) {
return !['input', 'textarea', 'select'].includes(event.target.tagName.toLowerCase());
}
return true;
}), ngDocZoneOptimize(this.ngZone), takeUntilDestroyed(destroyRef))
.subscribe((event) => {
event.preventDefault();
this.callback.emit();
});
});
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: NgDocHotkeyDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.0.6", type: NgDocHotkeyDirective, isStandalone: true, selector: "[ngDocHotkey]", inputs: { hotkey: ["ngDocHotkey", "hotkey"] }, outputs: { callback: "ngDocHotkey" }, ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: NgDocHotkeyDirective, decorators: [{
type: Directive,
args: [{
selector: '[ngDocHotkey]',
standalone: true,
}]
}], ctorParameters: () => [], propDecorators: { hotkey: [{
type: Input,
args: ['ngDocHotkey']
}], callback: [{
type: Output,
args: ['ngDocHotkey']
}] } });
/**
* Generated bundle index. Do not edit.
*/
export { NgDocHotkeyDirective };
//# sourceMappingURL=ng-doc-ui-kit-directives-hotkey.mjs.map