mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: Unify binding update options for updateBoundElements()
(#8832)
Fix insonsistent naming for option newSize/oldSize for updateBoundElements()
This commit is contained in:
parent
0927431d0d
commit
2db5bbcb29
8 changed files with 17 additions and 22 deletions
|
@ -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,
|
||||||
},
|
},
|
||||||
|
|
|
@ -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)) {
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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]);
|
||||||
|
|
|
@ -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(
|
||||||
|
|
|
@ -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,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue