mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
clean switch of arrows using app state
This commit is contained in:
parent
67793860b4
commit
c90cdb7b74
2 changed files with 50 additions and 9 deletions
|
@ -38,6 +38,7 @@ export const mutateElement = <TElement extends Mutable<ExcalidrawElement>>(
|
||||||
// If true, the elbow arrow tries to bind to the nearest element. If false
|
// If true, the elbow arrow tries to bind to the nearest element. If false
|
||||||
// it tries to keep the same bound element, if any.
|
// it tries to keep the same bound element, if any.
|
||||||
isDragging?: boolean;
|
isDragging?: boolean;
|
||||||
|
propertiesToDrop?: string[];
|
||||||
},
|
},
|
||||||
): TElement => {
|
): TElement => {
|
||||||
let didChange = false;
|
let didChange = false;
|
||||||
|
@ -128,6 +129,12 @@ export const mutateElement = <TElement extends Mutable<ExcalidrawElement>>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options?.propertiesToDrop?.includes(key)) {
|
||||||
|
delete (element as any)[key];
|
||||||
|
didChange = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
(element as any)[key] = value;
|
(element as any)[key] = value;
|
||||||
didChange = true;
|
didChange = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
ElementsMap,
|
ElementsMap,
|
||||||
|
ExcalidrawArrowElement,
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
ExcalidrawLinearElement,
|
ExcalidrawLinearElement,
|
||||||
ExcalidrawTextContainer,
|
ExcalidrawTextContainer,
|
||||||
|
@ -432,15 +433,48 @@ export const switchShapes = (
|
||||||
selectedLinearSwitchableElements.forEach((element) => {
|
selectedLinearSwitchableElements.forEach((element) => {
|
||||||
ShapeCache.delete(element);
|
ShapeCache.delete(element);
|
||||||
|
|
||||||
mutateElement(
|
// TODO: maybe add a separate function for safe type conversion
|
||||||
element as ExcalidrawLinearElement,
|
// without overloading mutateElement
|
||||||
{
|
if (nextType === "arrow") {
|
||||||
type: nextType as LinearSwitchableToolType,
|
mutateElement(
|
||||||
startArrowhead: null,
|
element as ExcalidrawArrowElement,
|
||||||
endArrowhead: nextType === "arrow" ? "arrow" : null,
|
{
|
||||||
},
|
type: "arrow",
|
||||||
false,
|
startArrowhead: app.state.currentItemStartArrowhead,
|
||||||
);
|
endArrowhead: app.state.currentItemEndArrowhead,
|
||||||
|
startBinding: null,
|
||||||
|
endBinding: null,
|
||||||
|
...(app.state.currentItemArrowType === "elbow"
|
||||||
|
? { elbowed: true }
|
||||||
|
: {}),
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nextType === "line") {
|
||||||
|
if (isElbowArrow(element)) {
|
||||||
|
mutateElement(
|
||||||
|
element as ExcalidrawLinearElement,
|
||||||
|
{
|
||||||
|
type: "line",
|
||||||
|
startArrowhead: null,
|
||||||
|
endArrowhead: null,
|
||||||
|
startBinding: null,
|
||||||
|
endBinding: null,
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
{
|
||||||
|
propertiesToDrop: [
|
||||||
|
"elbowed",
|
||||||
|
"startIsSpecial",
|
||||||
|
"endIsSpecial",
|
||||||
|
"fixedSegments",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isElbowArrow(element)) {
|
if (isElbowArrow(element)) {
|
||||||
const nextPoints = convertLineToElbow(element);
|
const nextPoints = convertLineToElbow(element);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue