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.

common.ts 766B

1234567891011121314151617181920212223242526272829303132333435
  1. export const isMac = () => {
  2. return navigator.userAgent.toUpperCase().includes('MAC')
  3. }
  4. const specialKeysNameMap: Record<string, string | undefined> = {
  5. ctrl: '⌘',
  6. alt: '⌥',
  7. shift: '⇧',
  8. }
  9. export const getKeyboardKeyNameBySystem = (key: string) => {
  10. if (isMac())
  11. return specialKeysNameMap[key] || key
  12. return key
  13. }
  14. const specialKeysCodeMap: Record<string, string | undefined> = {
  15. ctrl: 'meta',
  16. }
  17. export const getKeyboardKeyCodeBySystem = (key: string) => {
  18. if (isMac())
  19. return specialKeysCodeMap[key] || key
  20. return key
  21. }
  22. export const isEventTargetInputArea = (target: HTMLElement) => {
  23. if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA')
  24. return true
  25. if (target.contentEditable === 'true')
  26. return true
  27. }