mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.4 KiB
58 lines
1.4 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
|
|
*/
|
|
|
|
import { ChangeDetectorRef, Component, EventEmitter, Input, NgZone, OnDestroy, OnInit, Output } from '@angular/core';
|
|
import { ShortcutService, StatefulComponent } from '@app/framework/internal';
|
|
|
|
@Component({
|
|
selector: 'sqx-shortcut',
|
|
template: ''
|
|
})
|
|
export class ShortcutComponent extends StatefulComponent implements OnDestroy, OnInit {
|
|
private lastKeys: string;
|
|
|
|
@Output()
|
|
public trigger = new EventEmitter();
|
|
|
|
@Input()
|
|
public keys: string;
|
|
|
|
@Input()
|
|
public disabled: boolean;
|
|
|
|
constructor(
|
|
changeDetector: ChangeDetectorRef,
|
|
private readonly shortcutService: ShortcutService,
|
|
private readonly zone: NgZone
|
|
) {
|
|
super(changeDetector, {});
|
|
|
|
changeDetector.detach();
|
|
}
|
|
|
|
public ngOnDestroy() {
|
|
if (this.lastKeys) {
|
|
this.shortcutService.off(this.lastKeys);
|
|
}
|
|
}
|
|
|
|
public ngOnInit() {
|
|
this.lastKeys = this.keys;
|
|
|
|
if (this.lastKeys) {
|
|
this.shortcutService.on(this.lastKeys, () => {
|
|
if (!this.disabled) {
|
|
this.zone.run(() => {
|
|
this.trigger.next();
|
|
});
|
|
}
|
|
|
|
return false;
|
|
});
|
|
}
|
|
}
|
|
}
|