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

View File

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

View File

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

View File

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

View File

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

View File

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