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"
|
| "copyElementLink"
|
||||||
| "linkToElement"
|
| "linkToElement"
|
||||||
| "cropEditor"
|
| "cropEditor"
|
||||||
| "wrapSelectionInFrame";
|
| "wrapSelectionInFrame"
|
||||||
|
| "toggleShapeSwitch";
|
||||||
|
|
||||||
export type PanelComponentProps = {
|
export type PanelComponentProps = {
|
||||||
elements: readonly ExcalidrawElement[];
|
elements: readonly ExcalidrawElement[];
|
||||||
|
@ -194,7 +195,8 @@ export interface Action {
|
||||||
| "menu"
|
| "menu"
|
||||||
| "collab"
|
| "collab"
|
||||||
| "hyperlink"
|
| "hyperlink"
|
||||||
| "search_menu";
|
| "search_menu"
|
||||||
|
| "shape_switch";
|
||||||
action?: string;
|
action?: string;
|
||||||
predicate?: (
|
predicate?: (
|
||||||
appState: Readonly<AppState>,
|
appState: Readonly<AppState>,
|
||||||
|
|
|
@ -11,6 +11,8 @@ import {
|
||||||
isWritableElement,
|
isWritableElement,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
|
import { actionToggleShapeSwitch } from "@excalidraw/excalidraw/actions/actionToggleShapeSwitch";
|
||||||
|
|
||||||
import type { MarkRequired } from "@excalidraw/common/utility-types";
|
import type { MarkRequired } from "@excalidraw/common/utility-types";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -409,6 +411,14 @@ function CommandPaletteInner({
|
||||||
actionManager.executeAction(actionToggleSearchMenu);
|
actionManager.executeAction(actionToggleSearchMenu);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: t("labels.shapeSwitch"),
|
||||||
|
category: DEFAULT_CATEGORIES.elements,
|
||||||
|
icon: boltIcon,
|
||||||
|
perform: () => {
|
||||||
|
actionManager.executeAction(actionToggleShapeSwitch);
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: t("labels.changeStroke"),
|
label: t("labels.changeStroke"),
|
||||||
keywords: ["color", "outline"],
|
keywords: ["color", "outline"],
|
||||||
|
|
|
@ -166,7 +166,8 @@
|
||||||
"copyElementLink": "Copy link to object",
|
"copyElementLink": "Copy link to object",
|
||||||
"linkToElement": "Link to object",
|
"linkToElement": "Link to object",
|
||||||
"wrapSelectionInFrame": "Wrap selection in frame",
|
"wrapSelectionInFrame": "Wrap selection in frame",
|
||||||
"tab": "Tab"
|
"tab": "Tab",
|
||||||
|
"shapeSwitch": "Switch shape"
|
||||||
},
|
},
|
||||||
"elementLink": {
|
"elementLink": {
|
||||||
"title": "Link to object",
|
"title": "Link to object",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue