Merge branch 'master' into VM/RED-3982
This commit is contained in:
commit
ea3c8b7f32
@ -1,4 +1,5 @@
|
||||
module.exports = {
|
||||
/* eslint-disable */
|
||||
export default {
|
||||
displayName: 'common-ui',
|
||||
preset: '../../jest.preset.js',
|
||||
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
|
||||
@ -1,3 +1,3 @@
|
||||
<div (click)="countActions()">
|
||||
<div (click)="countActions($event)">
|
||||
<ng-content></ng-content>
|
||||
</div>
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
|
||||
import { ChangeDetectionStrategy, Component, EventEmitter, HostListener, Input, Output } from '@angular/core';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'iqser-hidden-action',
|
||||
@ -9,18 +10,38 @@ import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from
|
||||
export class HiddenActionComponent {
|
||||
@Input() requiredClicks = 4;
|
||||
@Output() readonly action = new EventEmitter();
|
||||
private _clickCount = 0;
|
||||
private _clickCountTimeout?: ReturnType<typeof setTimeout>;
|
||||
#dPressed = new BehaviorSubject(false);
|
||||
#clickCount = 0;
|
||||
#clickCountTimeout?: ReturnType<typeof setTimeout>;
|
||||
|
||||
countActions(): void {
|
||||
this._clickCount += 1;
|
||||
if (this._clickCount === this.requiredClicks) {
|
||||
this._clickCount = 0;
|
||||
@HostListener('window:keydown.D', ['$event'])
|
||||
onKeydownD() {
|
||||
this.#dPressed.next(true);
|
||||
}
|
||||
|
||||
@HostListener('window:keyup.D', ['$event'])
|
||||
onKeyupD() {
|
||||
this.#dPressed.next(false);
|
||||
}
|
||||
|
||||
countActions($event: MouseEvent): void {
|
||||
if (!this.#dPressed.value) {
|
||||
this.#clickCount = 0;
|
||||
clearTimeout(this.#clickCountTimeout);
|
||||
return;
|
||||
}
|
||||
|
||||
$event.stopPropagation();
|
||||
$event.preventDefault();
|
||||
|
||||
this.#clickCount += 1;
|
||||
if (this.#clickCount === this.requiredClicks) {
|
||||
this.#clickCount = 0;
|
||||
this.action.emit();
|
||||
}
|
||||
clearTimeout(this._clickCountTimeout);
|
||||
this._clickCountTimeout = setTimeout(() => {
|
||||
this._clickCount = 0;
|
||||
clearTimeout(this.#clickCountTimeout);
|
||||
this.#clickCountTimeout = setTimeout(() => {
|
||||
this.#clickCount = 0;
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,3 +113,20 @@ export function deepDiffObj(base: Record<string, unknown>, object: Record<string
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
export function bool(value: unknown): boolean {
|
||||
if (typeof value !== 'string') {
|
||||
return Boolean(value);
|
||||
}
|
||||
|
||||
const _value = value.toLowerCase().trim();
|
||||
if (_value === 'true') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_value === 'false') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Boolean(_value);
|
||||
}
|
||||
|
||||
@ -11,6 +11,6 @@
|
||||
"lib": ["dom", "es2018"],
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"exclude": ["src/test-setup.ts", "**/*.spec.ts"],
|
||||
"exclude": ["src/test-setup.ts", "**/*.spec.ts", "jest.config.ts"],
|
||||
"include": ["**/*.ts"]
|
||||
}
|
||||
|
||||
@ -6,5 +6,5 @@
|
||||
"types": ["jest", "node"]
|
||||
},
|
||||
"files": ["src/test-setup.ts"],
|
||||
"include": ["**/*.spec.ts", "**/*.d.ts"]
|
||||
"include": ["**/*.spec.ts", "**/*.d.ts", "jest.config.ts"]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user