mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
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:
parent
1ed1529f96
commit
64d330a332
12 changed files with 210 additions and 51 deletions
29
src/utils.ts
29
src/utils.ts
|
@ -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 = "";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue