diff --git a/src/actions/actionCanvas.tsx b/src/actions/actionCanvas.tsx index 1572cbefe..0a83be530 100644 --- a/src/actions/actionCanvas.tsx +++ b/src/actions/actionCanvas.tsx @@ -90,6 +90,7 @@ export const actionClearCanvas = register({ export const actionZoomIn = register({ name: "zoomIn", + viewMode: true, trackEvent: { category: "canvas" }, perform: (_elements, appState, _, app) => { return { @@ -126,6 +127,7 @@ export const actionZoomIn = register({ export const actionZoomOut = register({ name: "zoomOut", + viewMode: true, trackEvent: { category: "canvas" }, perform: (_elements, appState, _, app) => { return { @@ -162,6 +164,7 @@ export const actionZoomOut = register({ export const actionResetZoom = register({ name: "resetZoom", + viewMode: true, trackEvent: { category: "canvas" }, perform: (_elements, appState, _, app) => { return { @@ -271,6 +274,7 @@ export const actionZoomToSelected = register({ export const actionZoomToFit = register({ name: "zoomToFit", + viewMode: true, trackEvent: { category: "canvas" }, perform: (elements, appState) => zoomToFitElements(elements, appState, false), keyTest: (event) => @@ -282,6 +286,7 @@ export const actionZoomToFit = register({ export const actionToggleTheme = register({ name: "toggleTheme", + viewMode: true, trackEvent: { category: "canvas" }, perform: (_, appState, value) => { return { diff --git a/src/actions/actionExport.tsx b/src/actions/actionExport.tsx index 2c2bec08c..fc91425d1 100644 --- a/src/actions/actionExport.tsx +++ b/src/actions/actionExport.tsx @@ -179,6 +179,7 @@ export const actionSaveToActiveFile = register({ export const actionSaveFileToDisk = register({ name: "saveFileToDisk", + viewMode: true, trackEvent: { category: "export" }, perform: async (elements, appState, value, app) => { try { diff --git a/src/actions/actionMenu.tsx b/src/actions/actionMenu.tsx index 3ba11a5a7..769fd06d3 100644 --- a/src/actions/actionMenu.tsx +++ b/src/actions/actionMenu.tsx @@ -56,6 +56,7 @@ export const actionToggleEditMenu = register({ export const actionFullScreen = register({ name: "toggleFullScreen", + viewMode: true, trackEvent: { category: "canvas", predicate: (appState) => !isFullScreen() }, perform: () => { if (!isFullScreen()) { @@ -73,6 +74,7 @@ export const actionFullScreen = register({ export const actionShortcuts = register({ name: "toggleShortcuts", + viewMode: true, trackEvent: { category: "menu", action: "toggleHelpDialog" }, perform: (_elements, appState, _, { focusContainer }) => { if (appState.openDialog === "help") { diff --git a/src/actions/actionNavigate.tsx b/src/actions/actionNavigate.tsx index 26ce7bdbf..1b808e4a7 100644 --- a/src/actions/actionNavigate.tsx +++ b/src/actions/actionNavigate.tsx @@ -6,6 +6,7 @@ import { register } from "./register"; export const actionGoToCollaborator = register({ name: "goToCollaborator", + viewMode: true, trackEvent: { category: "collab" }, perform: (_elements, appState, value) => { const point = value as Collaborator["pointer"]; diff --git a/src/actions/actionToggleGridMode.tsx b/src/actions/actionToggleGridMode.tsx index a86cdb960..c3617398b 100644 --- a/src/actions/actionToggleGridMode.tsx +++ b/src/actions/actionToggleGridMode.tsx @@ -5,6 +5,7 @@ import { AppState } from "../types"; export const actionToggleGridMode = register({ name: "gridMode", + viewMode: true, trackEvent: { category: "canvas", predicate: (appState) => !appState.gridSize, diff --git a/src/actions/actionToggleStats.tsx b/src/actions/actionToggleStats.tsx index 08b74dd8a..71ba6bef1 100644 --- a/src/actions/actionToggleStats.tsx +++ b/src/actions/actionToggleStats.tsx @@ -3,6 +3,7 @@ import { CODES, KEYS } from "../keys"; export const actionToggleStats = register({ name: "stats", + viewMode: true, trackEvent: { category: "menu" }, perform(elements, appState) { return { diff --git a/src/actions/actionToggleViewMode.tsx b/src/actions/actionToggleViewMode.tsx index be88f563f..4b1adf476 100644 --- a/src/actions/actionToggleViewMode.tsx +++ b/src/actions/actionToggleViewMode.tsx @@ -3,6 +3,7 @@ import { register } from "./register"; export const actionToggleViewMode = register({ name: "viewMode", + viewMode: true, trackEvent: { category: "canvas", predicate: (appState) => !appState.viewModeEnabled, diff --git a/src/actions/actionToggleZenMode.tsx b/src/actions/actionToggleZenMode.tsx index 22266b035..5ed191eba 100644 --- a/src/actions/actionToggleZenMode.tsx +++ b/src/actions/actionToggleZenMode.tsx @@ -3,6 +3,7 @@ import { register } from "./register"; export const actionToggleZenMode = register({ name: "zenMode", + viewMode: true, trackEvent: { category: "canvas", predicate: (appState) => !appState.zenModeEnabled, diff --git a/src/actions/manager.tsx b/src/actions/manager.tsx index c003422f2..6c87aa037 100644 --- a/src/actions/manager.tsx +++ b/src/actions/manager.tsx @@ -9,7 +9,6 @@ import { } from "./types"; import { ExcalidrawElement } from "../element/types"; import { AppClassProperties, AppState } from "../types"; -import { MODES } from "../constants"; import { trackEvent } from "../analytics"; const trackAction = ( @@ -103,11 +102,8 @@ export class ActionManager { const action = data[0]; - const { viewModeEnabled } = this.getAppState(); - if (viewModeEnabled) { - if (!Object.values(MODES).includes(data[0].name)) { - return false; - } + if (this.getAppState().viewModeEnabled && action.viewMode !== true) { + return false; } const elements = this.getElementsIncludingDeleted(); diff --git a/src/actions/types.ts b/src/actions/types.ts index 45c222548..0ec27ec5c 100644 --- a/src/actions/types.ts +++ b/src/actions/types.ts @@ -164,4 +164,7 @@ export interface Action { value: any, ) => boolean; }; + /** if set to `true`, allow action to be performed in viewMode. + * Defaults to `false` */ + viewMode?: boolean; } diff --git a/src/constants.ts b/src/constants.ts index 38261a1d2..c492f27f6 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -130,12 +130,6 @@ export const IDLE_THRESHOLD = 60_000; // Report a user active each ACTIVE_THRESHOLD milliseconds export const ACTIVE_THRESHOLD = 3_000; -export const MODES = { - VIEW: "viewMode", - ZEN: "zenMode", - GRID: "gridMode", -}; - export const THEME_FILTER = cssVariables.themeFilter; export const URL_QUERY_KEYS = {