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,67 +959,59 @@ const convertElementType = <
: element.roundness, : element.roundness,
}), }),
); );
}
switch (nextElement.type) { if (isConvertibleLinearType(targetType)) {
case "rectangle": switch (targetType) {
return nextElement as ExcalidrawRectangleElement; case "line": {
case "diamond": return bumpVersion(
return nextElement as ExcalidrawDiamondElement; newLinearElement({
case "ellipse": ...element,
return nextElement as ExcalidrawEllipseElement; type: "line",
}),
);
}
case "sharpArrow": {
return bumpVersion(
newArrowElement({
...element,
type: "arrow",
elbowed: false,
roundness: null,
startArrowhead: app.state.currentItemStartArrowhead,
endArrowhead: app.state.currentItemEndArrowhead,
}),
);
}
case "curvedArrow": {
return bumpVersion(
newArrowElement({
...element,
type: "arrow",
elbowed: false,
roundness: {
type: ROUNDNESS.PROPORTIONAL_RADIUS,
},
startArrowhead: app.state.currentItemStartArrowhead,
endArrowhead: app.state.currentItemEndArrowhead,
}),
);
}
case "elbowArrow": {
return bumpVersion(
newArrowElement({
...element,
type: "arrow",
elbowed: true,
fixedSegments: null,
roundness: null,
}),
);
}
} }
} }
if (isConvertibleLinearType(element.type)) { assertNever(targetType, `unhandled conversion type: ${targetType}`);
if (targetType === "line") {
const nextElement = newLinearElement({
...element,
type: "line",
});
return bumpVersion(nextElement);
}
if (targetType === "sharpArrow") {
const nextElement = newArrowElement({
...element,
type: "arrow",
elbowed: false,
roundness: null,
startArrowhead: app.state.currentItemStartArrowhead,
endArrowhead: app.state.currentItemEndArrowhead,
});
return bumpVersion(nextElement);
}
if (targetType === "curvedArrow") {
const nextElement = newArrowElement({
...element,
type: "arrow",
elbowed: false,
roundness: {
type: ROUNDNESS.PROPORTIONAL_RADIUS,
},
startArrowhead: app.state.currentItemStartArrowhead,
endArrowhead: app.state.currentItemEndArrowhead,
});
return bumpVersion(nextElement);
}
if (targetType === "elbowArrow") {
const nextElement = newArrowElement({
...element,
type: "arrow",
elbowed: true,
fixedSegments: null,
roundness: null,
});
return bumpVersion(nextElement);
}
}
return element; return element;
}; };