mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
remove hint
This commit is contained in:
parent
6c2f3afa4e
commit
1c4b3cc0b1
2 changed files with 5 additions and 110 deletions
|
@ -4763,11 +4763,6 @@ class App extends React.Component<AppProps, AppState> {
|
||||||
canvasOffsets: this.getEditorUIOffsets(),
|
canvasOffsets: this.getEditorUIOffsets(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
editorJotaiStore.set(shapeSwitchAtom, {
|
|
||||||
type: "hint",
|
|
||||||
id: firstNode.id,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.flowChartCreator.clear();
|
this.flowChartCreator.clear();
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import { type ReactNode, useEffect, useMemo, useRef } from "react";
|
import { type ReactNode, useEffect, useMemo, useRef } from "react";
|
||||||
|
|
||||||
import clsx from "clsx";
|
|
||||||
|
|
||||||
import { pointFrom, pointRotateRads } from "@excalidraw/math";
|
import { pointFrom, pointRotateRads } from "@excalidraw/math";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -38,7 +36,6 @@ import type {
|
||||||
} from "@excalidraw/element/types";
|
} from "@excalidraw/element/types";
|
||||||
|
|
||||||
import { mutateElement, ROUNDNESS, sceneCoordsToViewportCoords } from "..";
|
import { mutateElement, ROUNDNESS, sceneCoordsToViewportCoords } from "..";
|
||||||
import { t } from "../i18n";
|
|
||||||
import { getSelectedElements } from "../scene";
|
import { getSelectedElements } from "../scene";
|
||||||
import { trackEvent } from "../analytics";
|
import { trackEvent } from "../analytics";
|
||||||
import { atom, editorJotaiStore, useAtom } from "../editor-jotai";
|
import { atom, editorJotaiStore, useAtom } from "../editor-jotai";
|
||||||
|
@ -62,16 +59,10 @@ export const GENERIC_SWITCHABLE_SHAPES = ["rectangle", "diamond", "ellipse"];
|
||||||
|
|
||||||
export const LINEAR_SWITCHABLE_SHAPES = ["line", "arrow"];
|
export const LINEAR_SWITCHABLE_SHAPES = ["line", "arrow"];
|
||||||
|
|
||||||
export const shapeSwitchAtom = atom<
|
export const shapeSwitchAtom = atom<{
|
||||||
| {
|
type: "panel";
|
||||||
type: "hint";
|
} | null>(null);
|
||||||
id: string;
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
type: "panel";
|
|
||||||
}
|
|
||||||
| null
|
|
||||||
>(null);
|
|
||||||
export const shapeSwitchFontSizeAtom = atom<{
|
export const shapeSwitchFontSizeAtom = atom<{
|
||||||
[id: string]: {
|
[id: string]: {
|
||||||
fontSize: number;
|
fontSize: number;
|
||||||
|
@ -112,103 +103,12 @@ const ShapeSwitch = ({ app }: { app: App }) => {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear if hint target no longer matches
|
|
||||||
if (
|
|
||||||
shapeSwitch.type === "hint" &&
|
|
||||||
selectedElements[0]?.id !== shapeSwitch.id
|
|
||||||
) {
|
|
||||||
setShapeSwitch(null);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selectedElements.length === 0) {
|
if (selectedElements.length === 0) {
|
||||||
setShapeSwitch(null);
|
setShapeSwitch(null);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = { app, elements: selectedElements };
|
return <Panel app={app} elements={selectedElements} />;
|
||||||
|
|
||||||
switch (shapeSwitch.type) {
|
|
||||||
case "hint":
|
|
||||||
return <Hint {...props} />;
|
|
||||||
case "panel":
|
|
||||||
return <Panel {...props} />;
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const Hint = ({
|
|
||||||
app,
|
|
||||||
elements,
|
|
||||||
}: {
|
|
||||||
app: App;
|
|
||||||
elements: ExcalidrawElement[];
|
|
||||||
}) => {
|
|
||||||
const [, setShapeSwitch] = useAtom(shapeSwitchAtom);
|
|
||||||
const hintRef = useRef<HTMLDivElement>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const hint = hintRef.current;
|
|
||||||
if (!hint) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleAnimationEnd = () => {
|
|
||||||
hint.classList.remove("animation");
|
|
||||||
setShapeSwitch(null);
|
|
||||||
};
|
|
||||||
|
|
||||||
hint.addEventListener("animationend", handleAnimationEnd, { once: true });
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
hint.removeEventListener("animationend", handleAnimationEnd);
|
|
||||||
};
|
|
||||||
}, [setShapeSwitch]);
|
|
||||||
|
|
||||||
const [x1, y1, , , cx, cy] = getElementAbsoluteCoords(
|
|
||||||
elements[0],
|
|
||||||
app.scene.getNonDeletedElementsMap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
const rotatedTopLeft = pointRotateRads(
|
|
||||||
pointFrom(x1, y1),
|
|
||||||
pointFrom(cx, cy),
|
|
||||||
elements[0].angle,
|
|
||||||
);
|
|
||||||
|
|
||||||
const { x, y } = sceneCoordsToViewportCoords(
|
|
||||||
{
|
|
||||||
sceneX: rotatedTopLeft[0],
|
|
||||||
sceneY: rotatedTopLeft[1],
|
|
||||||
},
|
|
||||||
app.state,
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
ref={hintRef}
|
|
||||||
// key={element.id}
|
|
||||||
style={{
|
|
||||||
position: "absolute",
|
|
||||||
bottom: `${
|
|
||||||
app.state.height +
|
|
||||||
GAP_VERTICAL * app.state.zoom.value -
|
|
||||||
y -
|
|
||||||
app.state.offsetTop
|
|
||||||
}px`,
|
|
||||||
left: `${x - app.state.offsetLeft - GAP_HORIZONTAL}px`,
|
|
||||||
zIndex: 2,
|
|
||||||
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "row",
|
|
||||||
}}
|
|
||||||
className={clsx("ShapeSwitch__Hint", "animation")}
|
|
||||||
>
|
|
||||||
<div className="key">/</div>
|
|
||||||
<div className="text">{t("labels.tab")}</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const Panel = ({
|
const Panel = ({
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue