This commit is contained in:
Eugene Pankov
2017-01-18 22:13:38 +01:00
parent deadbed74f
commit 24f28bba06
7 changed files with 56 additions and 34 deletions

View File

@@ -1,7 +1,7 @@
.stroke(*ngFor='let stroke of model') .stroke(*ngFor='let stroke of model')
.key-container( .key-container(
*ngFor='let key of splitKeys(stroke); let isLast = last; trackBy: key', *ngFor='let key of splitKeys(stroke); let isLast = last; trackBy: key',
@animateKey [@animateKey]='animate ? "in" : ""'
) )
.key {{key}} .key {{key}}
.plus(*ngIf='!isLast') + .plus(*ngIf='!isLast') +

View File

@@ -8,21 +8,24 @@ import { Component, Input, ChangeDetectionStrategy, trigger, style, animate, tra
//changeDetection: ChangeDetectionStrategy.OnPush, //changeDetection: ChangeDetectionStrategy.OnPush,
animations: [ animations: [
trigger('animateKey', [ trigger('animateKey', [
state('in', style({ transition('void => in', [
'transform': 'translateX(0)',
'opacity': '1',
})),
transition(':enter', [
style({ style({
'transform': 'translateX(25px)', transform: 'translateX(25px)',
'opacity': '0', opacity: '0',
}), }),
animate('250ms ease-out') animate('250ms ease-out', style({
transform: 'translateX(0)',
opacity: '1',
}))
]), ]),
transition(':leave', [ transition('in => void', [
style({
transform: 'translateX(0)',
opacity: '1',
}),
animate('250ms ease-in', style({ animate('250ms ease-in', style({
'transform': 'translateX(25px)', transform: 'translateX(25px)',
'opacity': '0', opacity: '0',
})) }))
]) ])
]) ])
@@ -34,4 +37,5 @@ export class HotkeyDisplayComponent {
} }
@Input() model: string[] @Input() model: string[]
@Input() animate = false
} }

View File

@@ -1,6 +1,6 @@
:host { :host {
display: inline-block; display: inline-block;
padding: 5px 10px; padding: 5px;
transition: 0.125s all; transition: 0.125s all;

View File

@@ -1,7 +1,7 @@
div.modal-body div.modal-body
label Press the key now label Press the key now
.input .input
hotkey-display([model]='value') hotkey-display([model]='value', [animate]='true')
.timeout .timeout
div([style.width]='timeoutProgress + "%"') div([style.width]='timeoutProgress + "%"')

View File

@@ -44,9 +44,11 @@ export class HotkeyInputModalComponent {
this.modalInstance.close(this.value) this.modalInstance.close(this.value)
} }
}, 25) }, 25)
this.hotkeys.disable()
} }
ngOnDestroy () { ngOnDestroy () {
this.hotkeys.enable()
clearInterval(this.keyTimeoutInterval) clearInterval(this.keyTimeoutInterval)
} }

View File

@@ -57,6 +57,7 @@ export class HotkeysService {
matchedHotkey = new EventEmitter<string>() matchedHotkey = new EventEmitter<string>()
globalHotkey = new EventEmitter() globalHotkey = new EventEmitter()
private currentKeystrokes: EventBufferEntry[] = [] private currentKeystrokes: EventBufferEntry[] = []
private disabledLevel = 0
constructor( constructor(
private zone: NgZone, private zone: NgZone,
@@ -98,12 +99,14 @@ export class HotkeysService {
this.currentKeystrokes.push({ event: nativeEvent, time: performance.now() }) this.currentKeystrokes.push({ event: nativeEvent, time: performance.now() })
this.zone.run(() => { this.zone.run(() => {
if (this.isEnabled()) {
let matched = this.getCurrentFullyMatchedHotkey() let matched = this.getCurrentFullyMatchedHotkey()
if (matched) { if (matched) {
console.log('Matched hotkey', matched) console.log('Matched hotkey', matched)
this.matchedHotkey.emit(matched) this.matchedHotkey.emit(matched)
this.clearCurrentKeystrokes() this.clearCurrentKeystrokes()
} }
}
this.key.emit(nativeEvent) this.key.emit(nativeEvent)
}) })
} }
@@ -179,4 +182,17 @@ export class HotkeysService {
getHotkeyDescription (id: string) : HotkeyDescription { getHotkeyDescription (id: string) : HotkeyDescription {
return HOTKEYS.filter((x) => x.id == id)[0] return HOTKEYS.filter((x) => x.id == id)[0]
} }
enable () {
this.disabledLevel--
}
disable () {
this.disabledLevel++
}
isEnabled () {
return this.disabledLevel == 0
}
} }

View File

@@ -25,7 +25,7 @@
"typings": "2.0.0", "typings": "2.0.0",
"url-loader": "^0.5.7", "url-loader": "^0.5.7",
"val-loader": "^0.5.0", "val-loader": "^0.5.0",
"webpack": "2.2.0-rc.0" "webpack": "2.2.0-rc.4"
}, },
"build": { "build": {
"appId": "com.elements.benchmark", "appId": "com.elements.benchmark",