mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
add shape switch to command palette
This commit is contained in:
parent
8e9e0e2709
commit
6c2f3afa4e
4 changed files with 56 additions and 3 deletions
40
packages/excalidraw/actions/actionToggleShapeSwitch.tsx
Normal file
40
packages/excalidraw/actions/actionToggleShapeSwitch.tsx
Normal file
|
@ -0,0 +1,40 @@
|
|||
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;
|
||||
},
|
||||
});
|
|
@ -139,7 +139,8 @@ export type ActionName =
|
|||
| "copyElementLink"
|
||||
| "linkToElement"
|
||||
| "cropEditor"
|
||||
| "wrapSelectionInFrame";
|
||||
| "wrapSelectionInFrame"
|
||||
| "toggleShapeSwitch";
|
||||
|
||||
export type PanelComponentProps = {
|
||||
elements: readonly ExcalidrawElement[];
|
||||
|
@ -194,7 +195,8 @@ export interface Action {
|
|||
| "menu"
|
||||
| "collab"
|
||||
| "hyperlink"
|
||||
| "search_menu";
|
||||
| "search_menu"
|
||||
| "shape_switch";
|
||||
action?: string;
|
||||
predicate?: (
|
||||
appState: Readonly<AppState>,
|
||||
|
|
|
@ -11,6 +11,8 @@ import {
|
|||
isWritableElement,
|
||||
} from "@excalidraw/common";
|
||||
|
||||
import { actionToggleShapeSwitch } from "@excalidraw/excalidraw/actions/actionToggleShapeSwitch";
|
||||
|
||||
import type { MarkRequired } from "@excalidraw/common/utility-types";
|
||||
|
||||
import {
|
||||
|
@ -409,6 +411,14 @@ function CommandPaletteInner({
|
|||
actionManager.executeAction(actionToggleSearchMenu);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("labels.shapeSwitch"),
|
||||
category: DEFAULT_CATEGORIES.elements,
|
||||
icon: boltIcon,
|
||||
perform: () => {
|
||||
actionManager.executeAction(actionToggleShapeSwitch);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("labels.changeStroke"),
|
||||
keywords: ["color", "outline"],
|
||||
|
|
|
@ -166,7 +166,8 @@
|
|||
"copyElementLink": "Copy link to object",
|
||||
"linkToElement": "Link to object",
|
||||
"wrapSelectionInFrame": "Wrap selection in frame",
|
||||
"tab": "Tab"
|
||||
"tab": "Tab",
|
||||
"shapeSwitch": "Switch shape"
|
||||
},
|
||||
"elementLink": {
|
||||
"title": "Link to object",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue