excalidraw/packages/excalidraw/actions/actionToggleShapeSwitch.tsx
2025-04-22 08:19:43 +10:00

40 lines
1.1 KiB
TypeScript

import { getSwitchableTypeFromElements } from "@excalidraw/element/typeChecks";
import type { ExcalidrawElement } from "@excalidraw/element/types";
import { shapeSwitchAtom } from "../components/ShapeSwitch";
import { editorJotaiStore } from "../editor-jotai";
import { CaptureUpdateAction } from "../store";
import { register } from "./register";
export const actionToggleShapeSwitch = register({
name: "toggleShapeSwitch",
label: "labels.shapeSwitch",
icon: () => null,
viewMode: true,
trackEvent: {
category: "shape_switch",
action: "toggle",
},
keywords: ["change", "switch", "swap"],
perform(elements, appState, _, app) {
editorJotaiStore.set(shapeSwitchAtom, {
type: "panel",
});
return {
appState,
commitToHistory: false,
captureUpdate: CaptureUpdateAction.NEVER,
};
},
checked: (appState) => appState.gridModeEnabled,
predicate: (elements, appState, props) => {
const { generic, linear } = getSwitchableTypeFromElements(
elements as ExcalidrawElement[],
);
return generic || linear;
},
});