generated from Tinkoff/angular-open-source-starter
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e216691
commit c4481b3
Showing
5 changed files
with
57 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,45 @@ | ||
export const enum HotkeyModifier { | ||
CTRL = 1 << 0, | ||
ALT = 1 << 1, | ||
SHIFT = 1 << 2, | ||
META = 1 << 3, | ||
} | ||
export const HotkeyModifier = { | ||
CTRL: 1 << 0, | ||
ALT: 1 << 1, | ||
SHIFT: 1 << 2, | ||
META: 1 << 3, | ||
} as const; | ||
|
||
// TODO add variants that can be processed correctly | ||
export const enum HotkeyCode { | ||
Y = 89, | ||
Z = 90, | ||
} | ||
export const HotkeyCode = { | ||
Y: 89, | ||
Z: 90, | ||
} as const; | ||
|
||
/** | ||
* Checks if the passed keyboard event match the required hotkey. | ||
* | ||
* We intentionally use legacy {@link KeyboardEvent#keyCode `keyCode`} property. It is more | ||
* "keyboard-layout"-independent than {@link KeyboardEvent#key `key`} or {@link KeyboardEvent#code `code`} properties. | ||
* | ||
* @example | ||
* input.addEventListener('keydown', (event) => { | ||
* if (isHotkey(event, HotkeyModifier.CTRL | HotkeyModifier.SHIFT, HotkeyCode.Z)) { | ||
* // redo hotkey pressed | ||
* } | ||
* }) | ||
* | ||
* @see {@link https://github.com/taiga-family/maskito/issues/315 `KeyboardEvent#code` issue} | ||
* | ||
* @return will return `true` only if the {@link HotkeyCode} matches and only the necessary | ||
* {@link HotkeyModifier modifiers} have been pressed | ||
*/ | ||
export function isHotkey( | ||
event: KeyboardEvent, | ||
modifiers: HotkeyModifier, | ||
hotkeyCode: HotkeyCode, | ||
modifiers: (typeof HotkeyModifier)[keyof typeof HotkeyModifier], | ||
hotkeyCode: (typeof HotkeyCode)[keyof typeof HotkeyCode], | ||
): boolean { | ||
return ( | ||
event.ctrlKey === !!(modifiers & HotkeyModifier.CTRL) && | ||
event.altKey === !!(modifiers & HotkeyModifier.ALT) && | ||
event.shiftKey === !!(modifiers & HotkeyModifier.SHIFT) && | ||
event.metaKey === !!(modifiers & HotkeyModifier.META) && | ||
/** | ||
* We intentionally use legacy {@link KeyboardEvent#keyCode `keyCode`} property. It is more | ||
* "keyboard-layout"-independent than {@link KeyboardEvent#key `key`} or {@link KeyboardEvent#code `code`} properties. | ||
* @see {@link https://github.com/taiga-family/maskito/issues/315 `KeyboardEvent#code` issue} | ||
*/ | ||
// eslint-disable-next-line sonar/deprecation | ||
event.keyCode === hotkeyCode | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
export const enum DemoPath { | ||
WhatIsMaskito = 'getting-started/what-is-maskito', | ||
MaskitoLibraries = 'getting-started/maskito-libraries', | ||
CoreConceptsOverview = 'core-concepts/overview', | ||
MaskExpression = 'core-concepts/mask-expression', | ||
ElementState = 'core-concepts/element-state', | ||
Processors = 'core-concepts/processors', | ||
Plugins = 'core-concepts/plugins', | ||
OverwriteMode = 'core-concepts/overwrite-mode', | ||
Transformer = 'core-concepts/transformer', | ||
Angular = 'frameworks/angular', | ||
React = 'frameworks/react', | ||
Vue = 'frameworks/vue', | ||
Number = 'kit/number', | ||
Time = 'kit/time', | ||
Date = 'kit/date', | ||
DateRange = 'kit/date-range', | ||
DateTime = 'kit/date-time', | ||
PhonePackage = 'addons/phone', | ||
Card = 'recipes/card', | ||
Phone = 'recipes/phone', | ||
Textarea = 'recipes/textarea', | ||
Prefix = 'recipes/prefix', | ||
Postfix = 'recipes/postfix', | ||
Placeholder = 'recipes/placeholder', | ||
BrowserSupport = 'browser-support', | ||
Changelog = 'changelog', | ||
Stackblitz = 'stackblitz', | ||
Cypress = 'cypress', | ||
} | ||
export const DemoPath = { | ||
WhatIsMaskito: 'getting-started/what-is-maskito', | ||
MaskitoLibraries: 'getting-started/maskito-libraries', | ||
CoreConceptsOverview: 'core-concepts/overview', | ||
MaskExpression: 'core-concepts/mask-expression', | ||
ElementState: 'core-concepts/element-state', | ||
Processors: 'core-concepts/processors', | ||
Plugins: 'core-concepts/plugins', | ||
OverwriteMode: 'core-concepts/overwrite-mode', | ||
Transformer: 'core-concepts/transformer', | ||
Angular: 'frameworks/angular', | ||
React: 'frameworks/react', | ||
Vue: 'frameworks/vue', | ||
Number: 'kit/number', | ||
Time: 'kit/time', | ||
Date: 'kit/date', | ||
DateRange: 'kit/date-range', | ||
DateTime: 'kit/date-time', | ||
PhonePackage: 'addons/phone', | ||
Card: 'recipes/card', | ||
Phone: 'recipes/phone', | ||
Textarea: 'recipes/textarea', | ||
Prefix: 'recipes/prefix', | ||
Postfix: 'recipes/postfix', | ||
Placeholder: 'recipes/placeholder', | ||
BrowserSupport: 'browser-support', | ||
Changelog: 'changelog', | ||
Stackblitz: 'stackblitz', | ||
Cypress: 'cypress', | ||
} as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
export enum DocExamplePrimaryTab { | ||
MaskitoOptions = 'mask', | ||
JavaScript = 'JavaScript', | ||
Angular = 'Angular', | ||
React = 'React', | ||
Vue = 'Vue', | ||
} | ||
export const DocExamplePrimaryTab = { | ||
MaskitoOptions: 'mask', | ||
JavaScript: 'JavaScript', | ||
Angular: 'Angular', | ||
React: 'React', | ||
Vue: 'Vue', | ||
} as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters