feat: support customType in activeTool (#5144)

* feat: support customType in activeTool

* fix

* rewrite types and handling

* tweaks

* fix

Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
Aakansha Doshi 2022-05-06 18:21:22 +05:30 committed by GitHub
parent 1ed1529f96
commit 64d330a332
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 210 additions and 51 deletions

View file

@ -11,9 +11,10 @@ import {
WINDOWS_EMOJI_FALLBACK_FONT,
} from "./constants";
import { FontFamilyValues, FontString } from "./element/types";
import { AppState, DataURL, Zoom } from "./types";
import { AppState, DataURL, LastActiveToolBeforeEraser, Zoom } from "./types";
import { unstable_batchedUpdates } from "react-dom";
import { isDarwin } from "./keys";
import { SHAPES } from "./shapes";
let mockDateTime: string | null = null;
@ -207,6 +208,32 @@ export const removeSelection = () => {
export const distance = (x: number, y: number) => Math.abs(x - y);
export const updateActiveTool = (
appState: Pick<AppState, "activeTool">,
data: (
| { type: typeof SHAPES[number]["value"] | "eraser" }
| { type: "custom"; customType: string }
) & { lastActiveToolBeforeEraser?: LastActiveToolBeforeEraser },
): AppState["activeTool"] => {
if (data.type === "custom") {
return {
...appState.activeTool,
type: "custom",
customType: data.customType,
};
}
return {
...appState.activeTool,
lastActiveToolBeforeEraser:
data.lastActiveToolBeforeEraser === undefined
? appState.activeTool.lastActiveToolBeforeEraser
: data.lastActiveToolBeforeEraser,
type: data.type,
customType: null,
};
};
export const resetCursor = (canvas: HTMLCanvasElement | null) => {
if (canvas) {
canvas.style.cursor = "";