fix: Unify binding update options for updateBoundElements() (#8832)

Fix insonsistent naming for option newSize/oldSize for updateBoundElements()
This commit is contained in:
Márk Tolmács 2024-11-20 11:46:45 +01:00 committed by GitHub
parent 0927431d0d
commit 2db5bbcb29
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 17 additions and 22 deletions

View file

@ -10237,7 +10237,7 @@ class App extends React.Component<AppProps, AppState> {
croppingElement, croppingElement,
this.scene.getNonDeletedElementsMap(), this.scene.getNonDeletedElementsMap(),
{ {
oldSize: { newSize: {
width: croppingElement.width, width: croppingElement.width,
height: croppingElement.height, height: croppingElement.height,
}, },

View file

@ -69,7 +69,6 @@ const resizeElementInGroup = (
originalElementsMap: ElementsMap, originalElementsMap: ElementsMap,
) => { ) => {
const updates = getResizedUpdates(anchorX, anchorY, scale, origElement); const updates = getResizedUpdates(anchorX, anchorY, scale, origElement);
const { width: oldWidth, height: oldHeight } = latestElement;
mutateElement(latestElement, updates, false); mutateElement(latestElement, updates, false);
const boundTextElement = getBoundTextElement( const boundTextElement = getBoundTextElement(
@ -79,7 +78,7 @@ const resizeElementInGroup = (
if (boundTextElement) { if (boundTextElement) {
const newFontSize = boundTextElement.fontSize * scale; const newFontSize = boundTextElement.fontSize * scale;
updateBoundElements(latestElement, elementsMap, { updateBoundElements(latestElement, elementsMap, {
oldSize: { width: oldWidth, height: oldHeight }, newSize: { width: updates.width, height: updates.height },
}); });
const latestBoundTextElement = elementsMap.get(boundTextElement.id); const latestBoundTextElement = elementsMap.get(boundTextElement.id);
if (latestBoundTextElement && isTextElement(latestBoundTextElement)) { if (latestBoundTextElement && isTextElement(latestBoundTextElement)) {

View file

@ -151,8 +151,6 @@ export const resizeElement = (
nextHeight = Math.max(nextHeight, minHeight); nextHeight = Math.max(nextHeight, minHeight);
} }
const { width: oldWidth, height: oldHeight } = latestElement;
mutateElement( mutateElement(
latestElement, latestElement,
{ {
@ -201,7 +199,7 @@ export const resizeElement = (
} }
updateBoundElements(latestElement, elementsMap, { updateBoundElements(latestElement, elementsMap, {
oldSize: { width: oldWidth, height: oldHeight }, newSize: { width: nextWidth, height: nextHeight },
}); });
if (boundTextElement && boundTextFont) { if (boundTextElement && boundTextFont) {

View file

@ -576,11 +576,11 @@ export const updateBoundElements = (
elementsMap: NonDeletedSceneElementsMap | SceneElementsMap, elementsMap: NonDeletedSceneElementsMap | SceneElementsMap,
options?: { options?: {
simultaneouslyUpdated?: readonly ExcalidrawElement[]; simultaneouslyUpdated?: readonly ExcalidrawElement[];
oldSize?: { width: number; height: number }; newSize?: { width: number; height: number };
changedElements?: Map<string, OrderedExcalidrawElement>; changedElements?: Map<string, OrderedExcalidrawElement>;
}, },
) => { ) => {
const { oldSize, simultaneouslyUpdated, changedElements } = options ?? {}; const { newSize, simultaneouslyUpdated, changedElements } = options ?? {};
const simultaneouslyUpdatedElementIds = getSimultaneouslyUpdatedElementIds( const simultaneouslyUpdatedElementIds = getSimultaneouslyUpdatedElementIds(
simultaneouslyUpdated, simultaneouslyUpdated,
); );
@ -603,12 +603,12 @@ export const updateBoundElements = (
startBinding: maybeCalculateNewGapWhenScaling( startBinding: maybeCalculateNewGapWhenScaling(
changedElement, changedElement,
element.startBinding, element.startBinding,
oldSize, newSize,
), ),
endBinding: maybeCalculateNewGapWhenScaling( endBinding: maybeCalculateNewGapWhenScaling(
changedElement, changedElement,
element.endBinding, element.endBinding,
oldSize, newSize,
), ),
}; };

View file

@ -739,9 +739,9 @@ export const resizeSingleElement = (
mutateElement(element, resizedElement); mutateElement(element, resizedElement);
updateBoundElements(element, elementsMap, { updateBoundElements(element, elementsMap, {
oldSize: { newSize: {
width: stateAtResizeStart.width, width: resizedElement.width,
height: stateAtResizeStart.height, height: resizedElement.height,
}, },
}); });
@ -999,14 +999,13 @@ export const resizeMultipleElements = (
element, element,
update: { boundTextFontSize, ...update }, update: { boundTextFontSize, ...update },
} of elementsAndUpdates) { } of elementsAndUpdates) {
const { angle } = update; const { angle, width: newWidth, height: newHeight } = update;
const { width: oldWidth, height: oldHeight } = element;
mutateElement(element, update, false); mutateElement(element, update, false);
updateBoundElements(element, elementsMap, { updateBoundElements(element, elementsMap, {
simultaneouslyUpdated: elementsToUpdate, simultaneouslyUpdated: elementsToUpdate,
oldSize: { width: oldWidth, height: oldHeight }, newSize: { width: newWidth, height: newHeight },
}); });
const boundTextElement = getBoundTextElement(element, elementsMap); const boundTextElement = getBoundTextElement(element, elementsMap);

View file

@ -156,8 +156,8 @@ describe("Crop an image", () => {
[-initialWidth / 3, 0], [-initialWidth / 3, 0],
true, true,
); );
expect(image.width).toBe(resizedWidth); expect(image.width).toBeCloseTo(resizedWidth, 10);
expect(image.height).toBe(resizedHeight); expect(image.height).toBeCloseTo(resizedHeight, 10);
// re-crop to initial state // re-crop to initial state
UI.crop(image, "w", naturalWidth, naturalHeight, [-initialWidth / 3, 0]); UI.crop(image, "w", naturalWidth, naturalHeight, [-initialWidth / 3, 0]);

View file

@ -1235,8 +1235,7 @@ describe("Test Linear Elements", () => {
mouse.downAt(rect.x, rect.y); mouse.downAt(rect.x, rect.y);
mouse.moveTo(200, 0); mouse.moveTo(200, 0);
mouse.upAt(200, 0); mouse.upAt(200, 0);
expect(arrow.width).toBe(200);
expect(arrow.width).toBe(205);
expect(rect.x).toBe(200); expect(rect.x).toBe(200);
expect(rect.y).toBe(0); expect(rect.y).toBe(0);
expect(handleBindTextResizeSpy).toHaveBeenCalledWith( expect(handleBindTextResizeSpy).toHaveBeenCalledWith(

View file

@ -882,11 +882,11 @@ describe("multiple selection", () => {
expect(leftBoundArrow.x).toBeCloseTo(-110); expect(leftBoundArrow.x).toBeCloseTo(-110);
expect(leftBoundArrow.y).toBeCloseTo(50); expect(leftBoundArrow.y).toBeCloseTo(50);
expect(leftBoundArrow.width).toBeCloseTo(137.5, 0); expect(leftBoundArrow.width).toBeCloseTo(140, 0);
expect(leftBoundArrow.height).toBeCloseTo(7, 0); expect(leftBoundArrow.height).toBeCloseTo(7, 0);
expect(leftBoundArrow.angle).toEqual(0); expect(leftBoundArrow.angle).toEqual(0);
expect(leftBoundArrow.startBinding).toBeNull(); expect(leftBoundArrow.startBinding).toBeNull();
expect(leftBoundArrow.endBinding?.gap).toBeCloseTo(12.352); expect(leftBoundArrow.endBinding?.gap).toBeCloseTo(10);
expect(leftBoundArrow.endBinding?.elementId).toBe( expect(leftBoundArrow.endBinding?.elementId).toBe(
leftArrowBinding.elementId, leftArrowBinding.elementId,
); );