appState.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import oc from "open-color";
  2. import { AppState, FlooredNumber } from "./types";
  3. import { getDateTime } from "./utils";
  4. import { t } from "./i18n";
  5. import {
  6. DEFAULT_FONT_SIZE,
  7. DEFAULT_FONT_FAMILY,
  8. DEFAULT_TEXT_ALIGN,
  9. } from "./constants";
  10. export const getDefaultAppState = (): AppState => {
  11. return {
  12. isLoading: false,
  13. errorMessage: null,
  14. draggingElement: null,
  15. resizingElement: null,
  16. multiElement: null,
  17. editingElement: null,
  18. editingLinearElement: null,
  19. elementType: "selection",
  20. elementLocked: false,
  21. exportBackground: true,
  22. shouldAddWatermark: false,
  23. currentItemStrokeColor: oc.black,
  24. currentItemBackgroundColor: "transparent",
  25. currentItemFillStyle: "hachure",
  26. currentItemStrokeWidth: 1,
  27. currentItemStrokeStyle: "solid",
  28. currentItemRoughness: 1,
  29. currentItemOpacity: 100,
  30. currentItemFontSize: DEFAULT_FONT_SIZE,
  31. currentItemFontFamily: DEFAULT_FONT_FAMILY,
  32. currentItemTextAlign: DEFAULT_TEXT_ALIGN,
  33. viewBackgroundColor: oc.white,
  34. scrollX: 0 as FlooredNumber,
  35. scrollY: 0 as FlooredNumber,
  36. cursorX: 0,
  37. cursorY: 0,
  38. cursorButton: "up",
  39. scrolledOutside: false,
  40. name: `${t("labels.untitled")}-${getDateTime()}`,
  41. username: "",
  42. isCollaborating: false,
  43. isResizing: false,
  44. isRotating: false,
  45. selectionElement: null,
  46. zoom: 1,
  47. openMenu: null,
  48. lastPointerDownWith: "mouse",
  49. selectedElementIds: {},
  50. previousSelectedElementIds: {},
  51. collaborators: new Map(),
  52. shouldCacheIgnoreZoom: false,
  53. showShortcutsDialog: false,
  54. zenModeEnabled: false,
  55. gridSize: null,
  56. editingGroupId: null,
  57. selectedGroupIds: {},
  58. };
  59. };
  60. export const clearAppStateForLocalStorage = (appState: AppState) => {
  61. const {
  62. draggingElement,
  63. resizingElement,
  64. multiElement,
  65. editingElement,
  66. selectionElement,
  67. isResizing,
  68. isRotating,
  69. collaborators,
  70. isCollaborating,
  71. isLoading,
  72. errorMessage,
  73. showShortcutsDialog,
  74. editingLinearElement,
  75. ...exportedState
  76. } = appState;
  77. return exportedState;
  78. };
  79. export const cleanAppStateForExport = (appState: AppState) => {
  80. return {
  81. viewBackgroundColor: appState.viewBackgroundColor,
  82. gridSize: appState.gridSize,
  83. };
  84. };