actionToggleGridMode.tsx 699 B

123456789101112131415161718192021222324
  1. import { CODES, KEYS } from "../keys";
  2. import { register } from "./register";
  3. import { GRID_SIZE } from "../constants";
  4. import { AppState } from "../types";
  5. export const actionToggleGridMode = register({
  6. name: "gridMode",
  7. trackEvent: {
  8. category: "canvas",
  9. predicate: (appState) => !appState.gridSize,
  10. },
  11. perform(elements, appState) {
  12. return {
  13. appState: {
  14. ...appState,
  15. gridSize: this.checked!(appState) ? null : GRID_SIZE,
  16. },
  17. commitToHistory: false,
  18. };
  19. },
  20. checked: (appState: AppState) => appState.gridSize !== null,
  21. contextItemLabel: "labels.showGrid",
  22. keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.code === CODES.QUOTE,
  23. });