feat: Provide an `isActionName` type guard.

feat-actionname-typeguard
Daniel J. Geiger 2 years ago
parent 1db078a3dc
commit 091123286b

@ -34,86 +34,92 @@ type ActionFn = (
export type UpdaterFn = (res: ActionResult) => void; export type UpdaterFn = (res: ActionResult) => void;
export type ActionFilterFn = (action: Action) => void; export type ActionFilterFn = (action: Action) => void;
export type ActionName = const actionNames = [
| "copy" "copy",
| "cut" "cut",
| "paste" "paste",
| "copyAsPng" "copyAsPng",
| "copyAsSvg" "copyAsSvg",
| "copyText" "copyText",
| "sendBackward" "sendBackward",
| "bringForward" "bringForward",
| "sendToBack" "sendToBack",
| "bringToFront" "bringToFront",
| "copyStyles" "copyStyles",
| "selectAll" "selectAll",
| "pasteStyles" "pasteStyles",
| "gridMode" "gridMode",
| "zenMode" "zenMode",
| "stats" "stats",
| "changeStrokeColor" "changeStrokeColor",
| "changeBackgroundColor" "changeBackgroundColor",
| "changeFillStyle" "changeFillStyle",
| "changeStrokeWidth" "changeStrokeWidth",
| "changeStrokeShape" "changeStrokeShape",
| "changeSloppiness" "changeSloppiness",
| "changeStrokeStyle" "changeStrokeStyle",
| "changeArrowhead" "changeArrowhead",
| "changeOpacity" "changeOpacity",
| "changeFontSize" "changeFontSize",
| "toggleCanvasMenu" "toggleCanvasMenu",
| "toggleEditMenu" "toggleEditMenu",
| "undo" "undo",
| "redo" "redo",
| "finalize" "finalize",
| "changeProjectName" "changeProjectName",
| "changeExportBackground" "changeExportBackground",
| "changeExportEmbedScene" "changeExportEmbedScene",
| "changeExportScale" "changeExportScale",
| "saveToActiveFile" "saveToActiveFile",
| "saveFileToDisk" "saveFileToDisk",
| "loadScene" "loadScene",
| "duplicateSelection" "duplicateSelection",
| "deleteSelectedElements" "deleteSelectedElements",
| "changeViewBackgroundColor" "changeViewBackgroundColor",
| "clearCanvas" "clearCanvas",
| "zoomIn" "zoomIn",
| "zoomOut" "zoomOut",
| "resetZoom" "resetZoom",
| "zoomToFit" "zoomToFit",
| "zoomToSelection" "zoomToSelection",
| "changeFontFamily" "changeFontFamily",
| "changeTextAlign" "changeTextAlign",
| "changeVerticalAlign" "changeVerticalAlign",
| "toggleFullScreen" "toggleFullScreen",
| "toggleShortcuts" "toggleShortcuts",
| "group" "group",
| "ungroup" "ungroup",
| "goToCollaborator" "goToCollaborator",
| "addToLibrary" "addToLibrary",
| "changeRoundness" "changeRoundness",
| "alignTop" "alignTop",
| "alignBottom" "alignBottom",
| "alignLeft" "alignLeft",
| "alignRight" "alignRight",
| "alignVerticallyCentered" "alignVerticallyCentered",
| "alignHorizontallyCentered" "alignHorizontallyCentered",
| "distributeHorizontally" "distributeHorizontally",
| "distributeVertically" "distributeVertically",
| "flipHorizontal" "flipHorizontal",
| "flipVertical" "flipVertical",
| "viewMode" "viewMode",
| "exportWithDarkMode" "exportWithDarkMode",
| "toggleTheme" "toggleTheme",
| "increaseFontSize" "increaseFontSize",
| "decreaseFontSize" "decreaseFontSize",
| "unbindText" "unbindText",
| "hyperlink" "hyperlink",
| "bindText" "bindText",
| "toggleLock" "toggleLock",
| "toggleLinearEditor" "toggleLinearEditor",
| "toggleEraserTool" "toggleEraserTool",
| "toggleHandTool"; "toggleHandTool",
] as const;
// So we can have the `isActionName` type guard
export type ActionName = typeof actionNames[number];
export const isActionName = (n: any): n is ActionName =>
actionNames.includes(n);
export type PanelComponentProps = { export type PanelComponentProps = {
elements: readonly ExcalidrawElement[]; elements: readonly ExcalidrawElement[];

Loading…
Cancel
Save