2022-11-01 17:29:58 +01:00
|
|
|
import { HamburgerMenuIcon, HelpIcon, palette } from "../components/icons";
|
2020-03-01 14:39:03 -05:00
|
|
|
import { ToolButton } from "../components/ToolButton";
|
|
|
|
import { t } from "../i18n";
|
2020-04-08 09:49:52 -07:00
|
|
|
import { showSelectedShapeActions, getNonDeletedElements } from "../element";
|
2020-03-07 10:20:38 -05:00
|
|
|
import { register } from "./register";
|
2020-04-06 03:17:13 +05:30
|
|
|
import { allowFullScreen, exitFullScreen, isFullScreen } from "../utils";
|
2022-10-20 21:01:26 +02:00
|
|
|
import { KEYS } from "../keys";
|
2022-11-01 17:29:58 +01:00
|
|
|
import { HelpButton } from "../components/HelpButton";
|
|
|
|
import MenuItem from "../components/MenuItem";
|
2020-03-01 14:39:03 -05:00
|
|
|
|
2020-03-07 10:20:38 -05:00
|
|
|
export const actionToggleCanvasMenu = register({
|
2020-03-01 14:39:03 -05:00
|
|
|
name: "toggleCanvasMenu",
|
2022-03-28 14:46:40 +02:00
|
|
|
trackEvent: { category: "menu" },
|
2020-03-01 14:39:03 -05:00
|
|
|
perform: (_, appState) => ({
|
|
|
|
appState: {
|
|
|
|
...appState,
|
|
|
|
openMenu: appState.openMenu === "canvas" ? null : "canvas",
|
|
|
|
},
|
2020-03-19 14:51:05 +01:00
|
|
|
commitToHistory: false,
|
2020-03-01 14:39:03 -05:00
|
|
|
}),
|
|
|
|
PanelComponent: ({ appState, updateData }) => (
|
|
|
|
<ToolButton
|
|
|
|
type="button"
|
2022-11-01 17:29:58 +01:00
|
|
|
icon={HamburgerMenuIcon}
|
2020-03-01 14:39:03 -05:00
|
|
|
aria-label={t("buttons.menu")}
|
|
|
|
onClick={updateData}
|
|
|
|
selected={appState.openMenu === "canvas"}
|
|
|
|
/>
|
|
|
|
),
|
2020-03-07 10:20:38 -05:00
|
|
|
});
|
2020-03-01 14:39:03 -05:00
|
|
|
|
2020-03-07 10:20:38 -05:00
|
|
|
export const actionToggleEditMenu = register({
|
2020-03-01 14:39:03 -05:00
|
|
|
name: "toggleEditMenu",
|
2022-03-28 14:46:40 +02:00
|
|
|
trackEvent: { category: "menu" },
|
2020-03-01 14:39:03 -05:00
|
|
|
perform: (_elements, appState) => ({
|
|
|
|
appState: {
|
|
|
|
...appState,
|
|
|
|
openMenu: appState.openMenu === "shape" ? null : "shape",
|
|
|
|
},
|
2020-03-19 14:51:05 +01:00
|
|
|
commitToHistory: false,
|
2020-03-01 14:39:03 -05:00
|
|
|
}),
|
|
|
|
PanelComponent: ({ elements, appState, updateData }) => (
|
|
|
|
<ToolButton
|
2020-04-08 09:49:52 -07:00
|
|
|
visible={showSelectedShapeActions(
|
|
|
|
appState,
|
|
|
|
getNonDeletedElements(elements),
|
|
|
|
)}
|
2020-03-01 14:39:03 -05:00
|
|
|
type="button"
|
|
|
|
icon={palette}
|
|
|
|
aria-label={t("buttons.edit")}
|
|
|
|
onClick={updateData}
|
|
|
|
selected={appState.openMenu === "shape"}
|
|
|
|
/>
|
|
|
|
),
|
2020-03-07 10:20:38 -05:00
|
|
|
});
|
2020-04-06 03:17:13 +05:30
|
|
|
|
|
|
|
export const actionFullScreen = register({
|
|
|
|
name: "toggleFullScreen",
|
2022-12-11 22:57:03 +01:00
|
|
|
viewMode: true,
|
2022-03-28 14:46:40 +02:00
|
|
|
trackEvent: { category: "canvas", predicate: (appState) => !isFullScreen() },
|
2020-04-06 03:17:13 +05:30
|
|
|
perform: () => {
|
|
|
|
if (!isFullScreen()) {
|
|
|
|
allowFullScreen();
|
|
|
|
}
|
|
|
|
if (isFullScreen()) {
|
|
|
|
exitFullScreen();
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
commitToHistory: false,
|
|
|
|
};
|
|
|
|
},
|
2022-10-20 21:01:26 +02:00
|
|
|
keyTest: (event) => event.key === KEYS.F && !event[KEYS.CTRL_OR_CMD],
|
2020-04-06 03:17:13 +05:30
|
|
|
});
|
2020-04-07 16:12:10 +05:30
|
|
|
|
|
|
|
export const actionShortcuts = register({
|
|
|
|
name: "toggleShortcuts",
|
2022-12-11 22:57:03 +01:00
|
|
|
viewMode: true,
|
2022-03-28 14:46:40 +02:00
|
|
|
trackEvent: { category: "menu", action: "toggleHelpDialog" },
|
2021-04-13 01:29:25 +05:30
|
|
|
perform: (_elements, appState, _, { focusContainer }) => {
|
2022-11-01 17:29:58 +01:00
|
|
|
if (appState.openDialog === "help") {
|
2021-04-13 01:29:25 +05:30
|
|
|
focusContainer();
|
|
|
|
}
|
2020-04-07 16:12:10 +05:30
|
|
|
return {
|
|
|
|
appState: {
|
|
|
|
...appState,
|
2022-11-01 17:29:58 +01:00
|
|
|
openDialog: appState.openDialog === "help" ? null : "help",
|
2020-04-07 16:12:10 +05:30
|
|
|
},
|
|
|
|
commitToHistory: false,
|
|
|
|
};
|
|
|
|
},
|
2022-11-01 17:29:58 +01:00
|
|
|
PanelComponent: ({ updateData, isInHamburgerMenu }) =>
|
|
|
|
isInHamburgerMenu ? (
|
|
|
|
<MenuItem
|
|
|
|
label={t("helpDialog.title")}
|
|
|
|
dataTestId="help-menu-item"
|
|
|
|
icon={HelpIcon}
|
|
|
|
onClick={updateData}
|
|
|
|
shortcut="?"
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<HelpButton title={t("helpDialog.title")} onClick={updateData} />
|
|
|
|
),
|
2020-04-07 16:12:10 +05:30
|
|
|
keyTest: (event) => event.key === KEYS.QUESTION_MARK,
|
|
|
|
});
|