This commit is contained in:
dwelle 2025-04-30 15:57:11 +02:00
parent fa2713197a
commit 8cf726b8f9

View file

@ -30,6 +30,7 @@ import {
import { wrapText } from "@excalidraw/element/textWrapping"; import { wrapText } from "@excalidraw/element/textWrapping";
import { import {
assertNever,
CLASSES, CLASSES,
getFontString, getFontString,
isProdEnv, isProdEnv,
@ -937,25 +938,14 @@ const convertElementType = <
return element; return element;
} }
const origType = isSharpArrow(element)
? "sharpArrow"
: isCurvedArrow(element)
? "curvedArrow"
: isElbowArrow(element)
? "elbowArrow"
: element.type;
if (element.type === targetType) { if (element.type === targetType) {
return element; return element;
} }
ShapeCache.delete(element); ShapeCache.delete(element);
if ( if (isConvertibleGenericType(targetType)) {
isConvertibleGenericType(origType) && return bumpVersion(
isConvertibleGenericType(targetType)
) {
const nextElement = bumpVersion(
newElement({ newElement({
...element, ...element,
type: targetType, type: targetType,
@ -969,42 +959,33 @@ const convertElementType = <
: element.roundness, : element.roundness,
}), }),
); );
switch (nextElement.type) {
case "rectangle":
return nextElement as ExcalidrawRectangleElement;
case "diamond":
return nextElement as ExcalidrawDiamondElement;
case "ellipse":
return nextElement as ExcalidrawEllipseElement;
}
} }
if (isConvertibleLinearType(element.type)) { if (isConvertibleLinearType(targetType)) {
if (targetType === "line") { switch (targetType) {
const nextElement = newLinearElement({ case "line": {
return bumpVersion(
newLinearElement({
...element, ...element,
type: "line", type: "line",
}); }),
);
return bumpVersion(nextElement);
} }
case "sharpArrow": {
if (targetType === "sharpArrow") { return bumpVersion(
const nextElement = newArrowElement({ newArrowElement({
...element, ...element,
type: "arrow", type: "arrow",
elbowed: false, elbowed: false,
roundness: null, roundness: null,
startArrowhead: app.state.currentItemStartArrowhead, startArrowhead: app.state.currentItemStartArrowhead,
endArrowhead: app.state.currentItemEndArrowhead, endArrowhead: app.state.currentItemEndArrowhead,
}); }),
);
return bumpVersion(nextElement);
} }
case "curvedArrow": {
if (targetType === "curvedArrow") { return bumpVersion(
const nextElement = newArrowElement({ newArrowElement({
...element, ...element,
type: "arrow", type: "arrow",
elbowed: false, elbowed: false,
@ -1013,23 +994,24 @@ const convertElementType = <
}, },
startArrowhead: app.state.currentItemStartArrowhead, startArrowhead: app.state.currentItemStartArrowhead,
endArrowhead: app.state.currentItemEndArrowhead, endArrowhead: app.state.currentItemEndArrowhead,
}); }),
);
return bumpVersion(nextElement);
} }
case "elbowArrow": {
if (targetType === "elbowArrow") { return bumpVersion(
const nextElement = newArrowElement({ newArrowElement({
...element, ...element,
type: "arrow", type: "arrow",
elbowed: true, elbowed: true,
fixedSegments: null, fixedSegments: null,
roundness: null, roundness: null,
}); }),
);
}
}
}
return bumpVersion(nextElement); assertNever(targetType, `unhandled conversion type: ${targetType}`);
}
}
return element; return element;
}; };