fix: align angle with container if container non-arrow

This commit is contained in:
dwelle 2025-04-13 19:42:55 +02:00
parent ad2e892ae8
commit 735de7f8e6
7 changed files with 29 additions and 8 deletions

View file

@ -112,6 +112,7 @@ export const YOUTUBE_STATES = {
export const ENV = { export const ENV = {
TEST: "test", TEST: "test",
DEVELOPMENT: "development", DEVELOPMENT: "development",
PRODUCTION: "production",
}; };
export const CLASSES = { export const CLASSES = {

View file

@ -739,6 +739,8 @@ export const isTestEnv = () => import.meta.env.MODE === ENV.TEST;
export const isDevEnv = () => import.meta.env.MODE === ENV.DEVELOPMENT; export const isDevEnv = () => import.meta.env.MODE === ENV.DEVELOPMENT;
export const isProdEnv = () => import.meta.env.MODE === ENV.PRODUCTION;
export const isServerEnv = () => export const isServerEnv = () =>
typeof process !== "undefined" && !!process?.env?.NODE_ENV; typeof process !== "undefined" && !!process?.env?.NODE_ENV;

View file

@ -6,6 +6,8 @@ import {
TEXT_ALIGN, TEXT_ALIGN,
VERTICAL_ALIGN, VERTICAL_ALIGN,
getFontString, getFontString,
isProdEnv,
invariant,
} from "@excalidraw/common"; } from "@excalidraw/common";
import type { AppState } from "@excalidraw/excalidraw/types"; import type { AppState } from "@excalidraw/excalidraw/types";
@ -44,13 +46,25 @@ export const redrawTextBoundingBox = (
informMutation = true, informMutation = true,
) => { ) => {
let maxWidth = undefined; let maxWidth = undefined;
if (!isProdEnv()) {
invariant(
!container || !isArrowElement(container) || textElement.angle === 0,
"text element angle must be 0 if bound to arrow container",
);
}
const boundTextUpdates = { const boundTextUpdates = {
x: textElement.x, x: textElement.x,
y: textElement.y, y: textElement.y,
text: textElement.text, text: textElement.text,
width: textElement.width, width: textElement.width,
height: textElement.height, height: textElement.height,
angle: textElement.angle, angle: container
? isArrowElement(container)
? 0
: container.angle
: textElement.angle,
}; };
boundTextUpdates.text = textElement.text; boundTextUpdates.text = textElement.text;

View file

@ -21,6 +21,7 @@ import {
import { import {
hasBoundTextElement, hasBoundTextElement,
isArrowElement,
isTextBindableContainer, isTextBindableContainer,
isTextElement, isTextElement,
isUsingAdaptiveRadius, isUsingAdaptiveRadius,
@ -157,7 +158,7 @@ export const actionBindText = register({
verticalAlign: VERTICAL_ALIGN.MIDDLE, verticalAlign: VERTICAL_ALIGN.MIDDLE,
textAlign: TEXT_ALIGN.CENTER, textAlign: TEXT_ALIGN.CENTER,
autoResize: true, autoResize: true,
angle: 0 as Radians, angle: (isArrowElement(container) ? 0 : container?.angle ?? 0) as Radians,
}); });
mutateElement(container, { mutateElement(container, {
boundElements: (container.boundElements || []).concat({ boundElements: (container.boundElements || []).concat({

View file

@ -464,9 +464,9 @@ const repairBoundElement = (
? elementsMap.get(boundElement.containerId) ? elementsMap.get(boundElement.containerId)
: null; : null;
if (boundElement.angle) { (boundElement as Mutable<typeof boundElement>).angle = (
(boundElement as Mutable<typeof boundElement>).angle = 0 as Radians; isArrowElement(container) ? 0 : container?.angle ?? 0
} ) as Radians;
if (!container) { if (!container) {
boundElement.containerId = null; boundElement.containerId = null;

View file

@ -4735,10 +4735,12 @@ History {
"updated": Map { "updated": Map {
"id164" => Delta { "id164" => Delta {
"deleted": { "deleted": {
"angle": 0,
"x": 15, "x": 15,
"y": 15, "y": 15,
}, },
"inserted": { "inserted": {
"angle": 0,
"x": 15, "x": 15,
"y": 15, "y": 15,
}, },
@ -4907,7 +4909,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
exports[`history > multiplayer undo/redo > conflicts in bound text elements and their containers > should redraw remotely added bound text when it's container is updated through the history > [end of test] element 1 1`] = ` exports[`history > multiplayer undo/redo > conflicts in bound text elements and their containers > should redraw remotely added bound text when it's container is updated through the history > [end of test] element 1 1`] = `
{ {
"angle": 0, "angle": 90,
"autoResize": true, "autoResize": true,
"backgroundColor": "transparent", "backgroundColor": "transparent",
"boundElements": null, "boundElements": null,

View file

@ -4057,7 +4057,7 @@ describe("history", () => {
// text element got redrawn! // text element got redrawn!
x: 205, x: 205,
y: 205, y: 205,
angle: 0, angle: 90,
id: text.id, id: text.id,
containerId: container.id, containerId: container.id,
isDeleted: false, isDeleted: false,
@ -4101,7 +4101,7 @@ describe("history", () => {
...textProps, ...textProps,
x: 205, x: 205,
y: 205, y: 205,
angle: 0, angle: 90,
id: text.id, id: text.id,
containerId: container.id, containerId: container.id,
isDeleted: false, isDeleted: false,
@ -4123,6 +4123,7 @@ describe("history", () => {
newElementWith(h.elements[0], { newElementWith(h.elements[0], {
x: 205, x: 205,
y: 205, y: 205,
angle: 90 as Radians,
}), }),
], ],
captureUpdate: CaptureUpdateAction.IMMEDIATELY, captureUpdate: CaptureUpdateAction.IMMEDIATELY,