Rename to getContainerMaxWidth and getContainerMaxHeight

This commit is contained in:
Aakansha Doshi 2023-02-28 13:51:49 +05:30
parent a05db6864e
commit 91f6e87317
6 changed files with 37 additions and 37 deletions

View File

@ -28,7 +28,7 @@ import {
measureText,
normalizeText,
wrapText,
getMaxContainerWidth,
getContainerMaxWidth,
} from "./textElement";
import { VERTICAL_ALIGN } from "../constants";
import { isArrowElement } from "./typeChecks";
@ -260,7 +260,7 @@ export const refreshTextDimensions = (
text = wrapText(
text,
getFontString(textElement),
getMaxContainerWidth(container),
getContainerMaxWidth(container),
);
}
const dimensions = getAdjustedDimensions(textElement, text);

View File

@ -45,7 +45,7 @@ import {
getBoundTextElementId,
getContainerElement,
handleBindTextResize,
getMaxContainerWidth,
getContainerMaxWidth,
} from "./textElement";
export const normalizeAngle = (angle: number): number => {
@ -201,7 +201,7 @@ const measureFontSizeFromWidth = (
if (hasContainer) {
const container = getContainerElement(element);
if (container) {
width = getMaxContainerWidth(container);
width = getContainerMaxWidth(container);
}
}
const nextFontSize = element.fontSize * (nextWidth / width);
@ -423,7 +423,7 @@ export const resizeSingleElement = (
const nextFontSize = measureFontSizeFromWidth(
boundTextElement,
getMaxContainerWidth(updatedElement),
getContainerMaxWidth(updatedElement),
);
if (nextFontSize === null) {
return;
@ -693,7 +693,7 @@ const resizeMultipleElements = (
};
const fontSize = measureFontSizeFromWidth(
boundTextElement ?? (element.orig as ExcalidrawTextElement),
getMaxContainerWidth(updatedElement),
getContainerMaxWidth(updatedElement),
);
if (!fontSize) {

View File

@ -3,8 +3,8 @@ import { API } from "../tests/helpers/api";
import {
computeContainerHeightForBoundText,
getContainerCoords,
getMaxContainerWidth,
getMaxContainerHeight,
getContainerMaxWidth,
getContainerMaxHeight,
wrapText,
} from "./textElement";
import { ExcalidrawTextElementWithContainer, FontString } from "./types";
@ -245,7 +245,7 @@ describe("Test measureText", () => {
});
});
describe("Test getMaxContainerWidth", () => {
describe("Test getContainerMaxWidth", () => {
const params = {
width: 178,
height: 194,
@ -253,17 +253,17 @@ describe("Test measureText", () => {
it("should return max width when container is rectangle", () => {
const container = API.createElement({ type: "rectangle", ...params });
expect(getMaxContainerWidth(container)).toBe(168);
expect(getContainerMaxWidth(container)).toBe(168);
});
it("should return max width when container is ellipse", () => {
const container = API.createElement({ type: "ellipse", ...params });
expect(getMaxContainerWidth(container)).toBe(116);
expect(getContainerMaxWidth(container)).toBe(116);
});
it("should return max width when container is diamond", () => {
const container = API.createElement({ type: "diamond", ...params });
expect(getMaxContainerWidth(container)).toBe(79);
expect(getContainerMaxWidth(container)).toBe(79);
});
it("should return max width when container is arrow", () => {
@ -271,11 +271,11 @@ describe("Test measureText", () => {
type: "arrow",
...params,
});
expect(getMaxContainerWidth(container)).toBe(220);
expect(getContainerMaxWidth(container)).toBe(220);
});
});
describe("Test getMaxContainerHeight", () => {
describe("Test getContainerMaxHeight", () => {
const params = {
width: 178,
height: 194,
@ -299,17 +299,17 @@ describe("Test measureText", () => {
it("should return max height when container is rectangle", () => {
const container = API.createElement({ type: "rectangle", ...params });
expect(getMaxContainerHeight(container, boundTextElement)).toBe(184);
expect(getContainerMaxHeight(container, boundTextElement)).toBe(184);
});
it("should return max height when container is ellipse", () => {
const container = API.createElement({ type: "ellipse", ...params });
expect(getMaxContainerHeight(container, boundTextElement)).toBe(127);
expect(getContainerMaxHeight(container, boundTextElement)).toBe(127);
});
it("should return max height when container is diamond", () => {
const container = API.createElement({ type: "diamond", ...params });
expect(getMaxContainerHeight(container, boundTextElement)).toBe(87);
expect(getContainerMaxHeight(container, boundTextElement)).toBe(87);
});
it("should return max height when container is arrow", () => {
@ -317,7 +317,7 @@ describe("Test measureText", () => {
type: "arrow",
...params,
});
expect(getMaxContainerHeight(container, boundTextElement)).toBe(194);
expect(getContainerMaxHeight(container, boundTextElement)).toBe(194);
});
it("should return max height when container is arrow and height is less than threshold", () => {
@ -328,7 +328,7 @@ describe("Test measureText", () => {
boundElements: [{ type: "text", id: "text-id" }],
});
expect(getMaxContainerHeight(container, boundTextElement)).toBe(
expect(getContainerMaxHeight(container, boundTextElement)).toBe(
boundTextElement.height,
);
});

View File

@ -53,7 +53,7 @@ export const redrawTextBoundingBox = (
};
if (container) {
maxWidth = getMaxContainerWidth(container);
maxWidth = getContainerMaxWidth(container);
boundTextUpdates.text = wrapText(
textElement.originalText,
getFontString(textElement),
@ -71,7 +71,7 @@ export const redrawTextBoundingBox = (
if (container) {
const containerDims = getContainerDims(container);
const maxContainerHeight = getMaxContainerHeight(
const maxContainerHeight = getContainerMaxHeight(
container,
textElement as ExcalidrawTextElementWithContainer,
);
@ -164,8 +164,8 @@ export const handleBindTextResize = (
let nextHeight = textElement.height;
let nextWidth = textElement.width;
const containerDims = getContainerDims(container);
const maxWidth = getMaxContainerWidth(container);
const maxHeight = getMaxContainerHeight(
const maxWidth = getContainerMaxWidth(container);
const maxHeight = getContainerMaxHeight(
container,
textElement as ExcalidrawTextElementWithContainer,
);
@ -227,8 +227,8 @@ export const computeBoundTextPosition = (
boundTextElement: ExcalidrawTextElementWithContainer,
) => {
const containerCoords = getContainerCoords(container);
const maxContainerHeight = getMaxContainerHeight(container, boundTextElement);
const maxContainerWidth = getMaxContainerWidth(container);
const maxContainerHeight = getContainerMaxHeight(container, boundTextElement);
const maxContainerWidth = getContainerMaxWidth(container);
let x;
let y;
@ -732,7 +732,7 @@ export const computeContainerHeightForBoundText = (
return boundTextElementHeight + BOUND_TEXT_PADDING * 2;
};
export const getMaxContainerWidth = (container: ExcalidrawElement) => {
export const getContainerMaxWidth = (container: ExcalidrawElement) => {
const width = getContainerDims(container).width;
if (isArrowElement(container)) {
return width - BOUND_TEXT_PADDING * 8 * 2;
@ -752,7 +752,7 @@ export const getMaxContainerWidth = (container: ExcalidrawElement) => {
return width - BOUND_TEXT_PADDING * 2;
};
export const getMaxContainerHeight = (
export const getContainerMaxHeight = (
container: ExcalidrawElement,
boundTextElement: ExcalidrawTextElementWithContainer,
) => {

View File

@ -32,8 +32,8 @@ import {
normalizeText,
redrawTextBoundingBox,
wrapText,
getMaxContainerHeight,
getMaxContainerWidth,
getContainerMaxHeight,
getContainerMaxWidth,
computeBoundTextPosition,
getTextHeight,
} from "./textElement";
@ -203,8 +203,8 @@ export const textWysiwyg = ({
}
}
maxWidth = getMaxContainerWidth(container);
maxHeight = getMaxContainerHeight(
maxWidth = getContainerMaxWidth(container);
maxHeight = getContainerMaxHeight(
container,
updatedTextElement as ExcalidrawTextElementWithContainer,
);
@ -360,7 +360,7 @@ export const textWysiwyg = ({
const wrappedText = wrapText(
`${editable.value}${data}`,
font,
getMaxContainerWidth(container),
getContainerMaxWidth(container),
);
const width = getTextWidth(wrappedText, font);
editable.style.width = `${width}px`;
@ -377,7 +377,7 @@ export const textWysiwyg = ({
const wrappedText = wrapText(
normalizeText(editable.value),
font,
getMaxContainerWidth(container!),
getContainerMaxWidth(container!),
);
const { width, height } = measureText(wrappedText, font);
editable.style.width = `${width}px`;

View File

@ -17,7 +17,7 @@ import { KEYS } from "../keys";
import { LinearElementEditor } from "../element/linearElementEditor";
import { queryByTestId, queryByText } from "@testing-library/react";
import { resize, rotate } from "./utils";
import { wrapText, getMaxContainerWidth } from "../element/textElement";
import { wrapText, getContainerMaxWidth } from "../element/textElement";
import * as textElementUtils from "../element/textElement";
import { ROUNDNESS } from "../constants";
@ -725,7 +725,7 @@ describe("Test Linear Elements", () => {
type: "text",
x: 0,
y: 0,
text: wrapText(text, font, getMaxContainerWidth(container)),
text: wrapText(text, font, getContainerMaxWidth(container)),
containerId: container.id,
width: 30,
height: 20,
@ -1151,7 +1151,7 @@ describe("Test Linear Elements", () => {
expect(rect.x).toBe(400);
expect(rect.y).toBe(0);
expect(
wrapText(textElement.originalText, font, getMaxContainerWidth(arrow)),
wrapText(textElement.originalText, font, getContainerMaxWidth(arrow)),
).toMatchInlineSnapshot(`
"Online whiteboard collaboration
made easy"
@ -1174,7 +1174,7 @@ describe("Test Linear Elements", () => {
false,
);
expect(
wrapText(textElement.originalText, font, getMaxContainerWidth(arrow)),
wrapText(textElement.originalText, font, getContainerMaxWidth(arrow)),
).toMatchInlineSnapshot(`
"Online whiteboard
collaboration made