2020-03-09 15:06:35 +02:00
|
|
|
export const isDarwin = /Mac|iPod|iPhone|iPad/.test(window.navigator.platform);
|
|
|
|
|
2020-04-14 12:30:58 +03:00
|
|
|
export const KEYS = {
|
|
|
|
ARROW_LEFT: "ArrowLeft",
|
|
|
|
ARROW_RIGHT: "ArrowRight",
|
|
|
|
ARROW_DOWN: "ArrowDown",
|
|
|
|
ARROW_UP: "ArrowUp",
|
|
|
|
ENTER: "Enter",
|
|
|
|
ESCAPE: "Escape",
|
|
|
|
DELETE: "Delete",
|
|
|
|
BACKSPACE: "Backspace",
|
|
|
|
CTRL_OR_CMD: isDarwin ? "metaKey" : "ctrlKey",
|
|
|
|
TAB: "Tab",
|
|
|
|
SPACE: " ",
|
|
|
|
QUESTION_MARK: "?",
|
|
|
|
F_KEY_CODE: 70,
|
2020-04-22 16:57:17 +01:00
|
|
|
ALT_KEY_CODE: 18,
|
2020-04-25 18:43:02 +05:30
|
|
|
Z_KEY_CODE: 90,
|
2020-06-24 00:24:52 +09:00
|
|
|
GRID_KEY_CODE: 222,
|
2020-05-26 13:07:46 -07:00
|
|
|
G_KEY_CODE: 71,
|
2020-07-07 20:22:23 +02:00
|
|
|
C_KEY_CODE: 67,
|
|
|
|
V_KEY_CODE: 86,
|
2020-04-14 12:30:58 +03:00
|
|
|
} as const;
|
2020-01-09 02:00:59 +04:00
|
|
|
|
2020-03-23 16:38:41 -07:00
|
|
|
export type Key = keyof typeof KEYS;
|
|
|
|
|
2020-05-20 16:21:37 +03:00
|
|
|
export const isArrowKey = (keyCode: string) =>
|
|
|
|
keyCode === KEYS.ARROW_LEFT ||
|
|
|
|
keyCode === KEYS.ARROW_RIGHT ||
|
|
|
|
keyCode === KEYS.ARROW_DOWN ||
|
|
|
|
keyCode === KEYS.ARROW_UP;
|
2020-04-22 16:57:17 +01:00
|
|
|
|
|
|
|
export const getResizeCenterPointKey = (event: MouseEvent | KeyboardEvent) =>
|
|
|
|
event.altKey || event.which === KEYS.ALT_KEY_CODE;
|
2020-05-20 16:21:37 +03:00
|
|
|
|
2020-04-22 16:57:17 +01:00
|
|
|
export const getResizeWithSidesSameLengthKey = (event: MouseEvent) =>
|
|
|
|
event.shiftKey;
|
2020-06-24 00:24:52 +09:00
|
|
|
|
|
|
|
export const getRotateWithDiscreteAngleKey = (event: MouseEvent) =>
|
|
|
|
event.shiftKey;
|