keys.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. export const isDarwin = /Mac|iPod|iPhone|iPad/.test(window.navigator.platform);
  2. export const KEYS = {
  3. ARROW_LEFT: "ArrowLeft",
  4. ARROW_RIGHT: "ArrowRight",
  5. ARROW_DOWN: "ArrowDown",
  6. ARROW_UP: "ArrowUp",
  7. ENTER: "Enter",
  8. ESCAPE: "Escape",
  9. DELETE: "Delete",
  10. BACKSPACE: "Backspace",
  11. CTRL_OR_CMD: isDarwin ? "metaKey" : "ctrlKey",
  12. TAB: "Tab",
  13. SPACE: " ",
  14. QUESTION_MARK: "?",
  15. F_KEY_CODE: 70,
  16. ALT_KEY_CODE: 18,
  17. Z_KEY_CODE: 90,
  18. GRID_KEY_CODE: 222,
  19. G_KEY_CODE: 71,
  20. C_KEY_CODE: 67,
  21. V_KEY_CODE: 86,
  22. } as const;
  23. export type Key = keyof typeof KEYS;
  24. export const isArrowKey = (keyCode: string) =>
  25. keyCode === KEYS.ARROW_LEFT ||
  26. keyCode === KEYS.ARROW_RIGHT ||
  27. keyCode === KEYS.ARROW_DOWN ||
  28. keyCode === KEYS.ARROW_UP;
  29. export const getResizeCenterPointKey = (event: MouseEvent | KeyboardEvent) =>
  30. event.altKey || event.which === KEYS.ALT_KEY_CODE;
  31. export const getResizeWithSidesSameLengthKey = (event: MouseEvent) =>
  32. event.shiftKey;
  33. export const getRotateWithDiscreteAngleKey = (event: MouseEvent) =>
  34. event.shiftKey;