mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
40 lines
1.1 KiB
TypeScript
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;
|
|
},
|
|
});
|