mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-03 07:37:04 +02:00

* feat: Add Eraser 🎉
* Eraser working
* remove unused state
* fix
* toggle eraser
* Support deselect with Alt/Option
* rename actionDelete -> actionErase
* Add util isEraserActive
* show eraser in mobile
* render eraser conditionally in mobile
* use selection if eraser in local storage state
* Add sampling to erase accurately
* use pointerDownState
* set eraser to false in AllowedExcalidrawElementTypes
* rename/reword fixes
* don't use updateScene
* handle bound text when erasing
* fix hover state in mobile
* consider all hitElements instead of a single
* code improvements
* revert to select if eraser active and elements selected
* show eraser in zenmode
* erase element when clicked on element while eraser active
* set groupIds to empty when eraser active
* fix test
* remove dragged distance
128 lines
3.1 KiB
TypeScript
128 lines
3.1 KiB
TypeScript
import { t } from "../i18n";
|
|
import { NonDeletedExcalidrawElement } from "../element/types";
|
|
import { getSelectedElements } from "../scene";
|
|
|
|
import "./HintViewer.scss";
|
|
import { AppState } from "../types";
|
|
import {
|
|
isImageElement,
|
|
isLinearElement,
|
|
isTextBindableContainer,
|
|
isTextElement,
|
|
} from "../element/typeChecks";
|
|
import { getShortcutKey } from "../utils";
|
|
import { isEraserActive } from "../appState";
|
|
|
|
interface HintViewerProps {
|
|
appState: AppState;
|
|
elements: readonly NonDeletedExcalidrawElement[];
|
|
isMobile: boolean;
|
|
}
|
|
|
|
const getHints = ({ appState, elements, isMobile }: HintViewerProps) => {
|
|
const { elementType, isResizing, isRotating, lastPointerDownWith } = appState;
|
|
const multiMode = appState.multiElement !== null;
|
|
|
|
if (isEraserActive(appState)) {
|
|
return t("hints.eraserRevert");
|
|
}
|
|
if (elementType === "arrow" || elementType === "line") {
|
|
if (!multiMode) {
|
|
return t("hints.linearElement");
|
|
}
|
|
return t("hints.linearElementMulti");
|
|
}
|
|
|
|
if (elementType === "freedraw") {
|
|
return t("hints.freeDraw");
|
|
}
|
|
|
|
if (elementType === "text") {
|
|
return t("hints.text");
|
|
}
|
|
|
|
if (appState.elementType === "image" && appState.pendingImageElement) {
|
|
return t("hints.placeImage");
|
|
}
|
|
|
|
const selectedElements = getSelectedElements(elements, appState);
|
|
|
|
if (
|
|
isResizing &&
|
|
lastPointerDownWith === "mouse" &&
|
|
selectedElements.length === 1
|
|
) {
|
|
const targetElement = selectedElements[0];
|
|
if (isLinearElement(targetElement) && targetElement.points.length === 2) {
|
|
return t("hints.lockAngle");
|
|
}
|
|
return isImageElement(targetElement)
|
|
? t("hints.resizeImage")
|
|
: t("hints.resize");
|
|
}
|
|
|
|
if (isRotating && lastPointerDownWith === "mouse") {
|
|
return t("hints.rotate");
|
|
}
|
|
|
|
if (selectedElements.length === 1 && isTextElement(selectedElements[0])) {
|
|
return t("hints.text_selected");
|
|
}
|
|
|
|
if (appState.editingElement && isTextElement(appState.editingElement)) {
|
|
return t("hints.text_editing");
|
|
}
|
|
|
|
if (elementType === "selection") {
|
|
if (
|
|
appState.draggingElement?.type === "selection" &&
|
|
!appState.editingElement &&
|
|
!appState.editingLinearElement
|
|
) {
|
|
return t("hints.deepBoxSelect");
|
|
}
|
|
if (!selectedElements.length && !isMobile) {
|
|
return t("hints.canvasPanning");
|
|
}
|
|
}
|
|
|
|
if (selectedElements.length === 1) {
|
|
if (isLinearElement(selectedElements[0])) {
|
|
if (appState.editingLinearElement) {
|
|
return appState.editingLinearElement.selectedPointsIndices
|
|
? t("hints.lineEditor_pointSelected")
|
|
: t("hints.lineEditor_nothingSelected");
|
|
}
|
|
return t("hints.lineEditor_info");
|
|
}
|
|
if (isTextBindableContainer(selectedElements[0])) {
|
|
return t("hints.bindTextToElement");
|
|
}
|
|
}
|
|
|
|
return null;
|
|
};
|
|
|
|
export const HintViewer = ({
|
|
appState,
|
|
elements,
|
|
isMobile,
|
|
}: HintViewerProps) => {
|
|
let hint = getHints({
|
|
appState,
|
|
elements,
|
|
isMobile,
|
|
});
|
|
if (!hint) {
|
|
return null;
|
|
}
|
|
|
|
hint = getShortcutKey(hint);
|
|
|
|
return (
|
|
<div className="HintViewer">
|
|
<span>{hint}</span>
|
|
</div>
|
|
);
|
|
};
|