From 91f6e87317802a109c8ad8683d680405a971f3fc Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Tue, 28 Feb 2023 13:51:49 +0530 Subject: [PATCH] Rename to getContainerMaxWidth and getContainerMaxHeight --- src/element/newElement.ts | 4 ++-- src/element/resizeElements.ts | 8 ++++---- src/element/textElement.test.ts | 26 +++++++++++++------------- src/element/textElement.ts | 16 ++++++++-------- src/element/textWysiwyg.tsx | 12 ++++++------ src/tests/linearElementEditor.test.tsx | 8 ++++---- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/element/newElement.ts b/src/element/newElement.ts index 0c7c90d2b..5a2c1b54f 100644 --- a/src/element/newElement.ts +++ b/src/element/newElement.ts @@ -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); diff --git a/src/element/resizeElements.ts b/src/element/resizeElements.ts index 0c0337ed7..cca49427c 100644 --- a/src/element/resizeElements.ts +++ b/src/element/resizeElements.ts @@ -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) { diff --git a/src/element/textElement.test.ts b/src/element/textElement.test.ts index 00f1d5a31..b75f978f1 100644 --- a/src/element/textElement.test.ts +++ b/src/element/textElement.test.ts @@ -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, ); }); diff --git a/src/element/textElement.ts b/src/element/textElement.ts index 71a3ce246..567e37943 100644 --- a/src/element/textElement.ts +++ b/src/element/textElement.ts @@ -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, ) => { diff --git a/src/element/textWysiwyg.tsx b/src/element/textWysiwyg.tsx index 0cd9ae674..d35c40aab 100644 --- a/src/element/textWysiwyg.tsx +++ b/src/element/textWysiwyg.tsx @@ -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`; diff --git a/src/tests/linearElementEditor.test.tsx b/src/tests/linearElementEditor.test.tsx index f5660bbcb..f3543c41b 100644 --- a/src/tests/linearElementEditor.test.tsx +++ b/src/tests/linearElementEditor.test.tsx @@ -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