Fix lint issues

This commit is contained in:
Mark Tolmacs 2025-05-02 13:57:08 +02:00
parent 820a8540b1
commit af428d472c
No known key found for this signature in database
9 changed files with 146 additions and 136 deletions

View file

@ -12,7 +12,12 @@ import type Scene from "@excalidraw/element/Scene";
import { angleIcon } from "../icons";
import DragInput from "./DragInput";
import { DragInputCallbackType, getStepSizedValue, isPropertyEditable, updateBindings } from "./utils";
import {
type DragInputCallbackType,
getStepSizedValue,
isPropertyEditable,
updateBindings,
} from "./utils";
import type { AppState } from "../../types";

View file

@ -13,7 +13,11 @@ import type { ExcalidrawElement } from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import DragInput from "./DragInput";
import { DragInputCallbackType, getStepSizedValue, isPropertyEditable } from "./utils";
import {
type DragInputCallbackType,
getStepSizedValue,
isPropertyEditable,
} from "./utils";
import type { AppState } from "../../types";

View file

@ -13,7 +13,7 @@ import { CaptureUpdateAction } from "../../store";
import { useApp } from "../App";
import { InlineIcon } from "../InlineIcon";
import { DragInputCallbackType, SMALLEST_DELTA } from "./utils";
import { type DragInputCallbackType, SMALLEST_DELTA } from "./utils";
import "./DragInput.scss";

View file

@ -17,7 +17,7 @@ import type Scene from "@excalidraw/element/Scene";
import { fontSizeIcon } from "../icons";
import StatsDragInput from "./DragInput";
import { DragInputCallbackType, getStepSizedValue } from "./utils";
import { type DragInputCallbackType, getStepSizedValue } from "./utils";
import type { AppState } from "../../types";

View file

@ -14,7 +14,11 @@ import type Scene from "@excalidraw/element/Scene";
import { angleIcon } from "../icons";
import DragInput from "./DragInput";
import { DragInputCallbackType, getStepSizedValue, isPropertyEditable } from "./utils";
import {
type DragInputCallbackType,
getStepSizedValue,
isPropertyEditable,
} from "./utils";
import type { AppState } from "../../types";

View file

@ -26,7 +26,7 @@ import type Scene from "@excalidraw/element/Scene";
import DragInput from "./DragInput";
import { getAtomicUnits, getStepSizedValue, isPropertyEditable } from "./utils";
import { DragInputCallbackType, getElementsInAtomicUnit } from "./utils";
import { type DragInputCallbackType, getElementsInAtomicUnit } from "./utils";
import type { AtomicUnit } from "./utils";
import type { AppState } from "../../types";

View file

@ -10,10 +10,8 @@ import type Scene from "@excalidraw/element/Scene";
import StatsDragInput from "./DragInput";
import { handlePositionChange } from "./utils";
import type { AtomicUnit } from "./utils";
import type { AppState } from "../../types";
import { getFrameChildren } from "@excalidraw/element/frame";
import { isFrameLikeElement } from "@excalidraw/element/typeChecks";
import type { AtomicUnit } from "./utils";
interface MultiPositionProps {
property: "x" | "y";

View file

@ -1,9 +1,7 @@
import { pointFrom, pointRotateRads, round } from "@excalidraw/math";
import {
getFlipAdjustedCropPosition,
} from "@excalidraw/element/cropElement";
import { isFrameLikeElement, isImageElement } from "@excalidraw/element/typeChecks";
import { getFlipAdjustedCropPosition } from "@excalidraw/element/cropElement";
import { isImageElement } from "@excalidraw/element/typeChecks";
import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";
@ -13,7 +11,6 @@ import StatsDragInput from "./DragInput";
import { handlePositionChange } from "./utils";
import type { AppState } from "../../types";
import { getFrameChildren } from "@excalidraw/element/frame";
interface PositionProps {
property: "x" | "y";

View file

@ -7,7 +7,6 @@ import {
import { getBoundTextElement } from "@excalidraw/element/textElement";
import { getCommonBounds } from "@excalidraw/element/bounds";
import {
isFrameChildElement,
isFrameLikeElement,
isLinearElement,
isTextElement,
@ -19,6 +18,8 @@ import {
isInGroup,
} from "@excalidraw/element/groups";
import { getFrameChildren } from "@excalidraw/element/frame";
import type { Radians } from "@excalidraw/math";
import type {
@ -30,7 +31,6 @@ import type {
import type Scene from "@excalidraw/element/Scene";
import type { AppState } from "../../types";
import { getFrameChildren } from "@excalidraw/element/frame";
export type StatsInputProperty =
| "x"
@ -93,9 +93,9 @@ export const getElementsInAtomicUnit = (
latest: elementsMap.get(id),
}))
.filter((el) => el.original !== undefined && el.latest !== undefined) as {
original: NonDeletedExcalidrawElement;
latest: NonDeletedExcalidrawElement;
}[];
original: NonDeletedExcalidrawElement;
latest: NonDeletedExcalidrawElement;
}[];
};
export const newOrigin = (
@ -194,57 +194,61 @@ export const moveElement = (
}
if (isFrameLikeElement(originalElement)) {
getFrameChildren(originalElementsMap, originalElement.id).forEach(child => {
const latestChildElement = elementsMap.get(child.id);
getFrameChildren(originalElementsMap, originalElement.id).forEach(
(child) => {
const latestChildElement = elementsMap.get(child.id);
if (!latestChildElement) return;
if (!latestChildElement) {
return;
}
const [childCX, childCY] = [
child.x + child.width / 2,
child.y + child.height / 2,
];
const [childTopLeftX, childTopLeftY] = pointRotateRads(
pointFrom(child.x, child.y),
pointFrom(childCX, childCY),
child.angle,
);
const [childCX, childCY] = [
child.x + child.width / 2,
child.y + child.height / 2,
];
const [childTopLeftX, childTopLeftY] = pointRotateRads(
pointFrom(child.x, child.y),
pointFrom(childCX, childCY),
child.angle,
);
const childNewTopLeftX = Math.round(childTopLeftX + changeInX);
const childNewTopLeftY = Math.round(childTopLeftY + changeInY);
const childNewTopLeftX = Math.round(childTopLeftX + changeInX);
const childNewTopLeftY = Math.round(childTopLeftY + changeInY);
const [childX, childY] = pointRotateRads(
pointFrom(childNewTopLeftX, childNewTopLeftY),
pointFrom(childCX + changeInX, childCY + changeInY),
-child.angle as Radians,
);
const [childX, childY] = pointRotateRads(
pointFrom(childNewTopLeftX, childNewTopLeftY),
pointFrom(childCX + changeInX, childCY + changeInY),
-child.angle as Radians,
);
scene.mutateElement(
latestChildElement,
{
x: childX,
y: childY,
},
{ informMutation: shouldInformMutation, isDragging: false },
);
updateBindings(latestChildElement, scene);
scene.mutateElement(
latestChildElement,
{
x: childX,
y: childY,
},
{ informMutation: shouldInformMutation, isDragging: false },
);
updateBindings(latestChildElement, scene);
const boundTextElement = getBoundTextElement(
latestChildElement,
originalElementsMap,
);
if (boundTextElement) {
const latestBoundTextElement = elementsMap.get(boundTextElement.id);
latestBoundTextElement &&
scene.mutateElement(
latestBoundTextElement,
{
x: boundTextElement.x + changeInX,
y: boundTextElement.y + changeInY,
},
{ informMutation: shouldInformMutation, isDragging: false },
);
}
})
const boundTextElement = getBoundTextElement(
latestChildElement,
originalElementsMap,
);
if (boundTextElement) {
const latestBoundTextElement = elementsMap.get(boundTextElement.id);
latestBoundTextElement &&
scene.mutateElement(
latestBoundTextElement,
{
x: boundTextElement.x + changeInX,
y: boundTextElement.y + changeInY,
},
{ informMutation: shouldInformMutation, isDragging: false },
);
}
},
);
}
};
@ -368,9 +372,7 @@ export const updateBindings = (
}
};
export const handlePositionChange: DragInputCallbackType<
"x" | "y"
> = ({
export const handlePositionChange: DragInputCallbackType<"x" | "y"> = ({
accumulatedChange,
originalElements,
originalElementsMap,
@ -380,86 +382,86 @@ export const handlePositionChange: DragInputCallbackType<
scene,
originalAppState,
}) => {
const STEP_SIZE = 10;
const elementsMap = scene.getNonDeletedElementsMap();
const STEP_SIZE = 10;
const elementsMap = scene.getNonDeletedElementsMap();
if (nextValue !== undefined) {
for (const atomicUnit of getAtomicUnits(
originalElements,
originalAppState,
)) {
const elementsInUnit = getElementsInAtomicUnit(
atomicUnit,
elementsMap,
originalElementsMap,
if (nextValue !== undefined) {
for (const atomicUnit of getAtomicUnits(
originalElements,
originalAppState,
)) {
const elementsInUnit = getElementsInAtomicUnit(
atomicUnit,
elementsMap,
originalElementsMap,
);
if (elementsInUnit.length > 1) {
const [x1, y1, ,] = getCommonBounds(
elementsInUnit.map((el) => el.latest!),
);
const newTopLeftX = property === "x" ? nextValue : x1;
const newTopLeftY = property === "y" ? nextValue : y1;
if (elementsInUnit.length > 1) {
const [x1, y1, ,] = getCommonBounds(
elementsInUnit.map((el) => el.latest!),
moveGroup(
newTopLeftX,
newTopLeftY,
elementsInUnit.map((el) => el.original),
originalElementsMap,
scene,
);
} else {
const origElement = elementsInUnit[0]?.original;
const latestElement = elementsInUnit[0]?.latest;
if (
origElement &&
latestElement &&
isPropertyEditable(latestElement, property)
) {
const [cx, cy] = [
origElement.x + origElement.width / 2,
origElement.y + origElement.height / 2,
];
const [topLeftX, topLeftY] = pointRotateRads(
pointFrom(origElement.x, origElement.y),
pointFrom(cx, cy),
origElement.angle,
);
const newTopLeftX = property === "x" ? nextValue : x1;
const newTopLeftY = property === "y" ? nextValue : y1;
moveGroup(
const newTopLeftX = property === "x" ? nextValue : topLeftX;
const newTopLeftY = property === "y" ? nextValue : topLeftY;
moveElement(
newTopLeftX,
newTopLeftY,
elementsInUnit.map((el) => el.original),
originalElementsMap,
origElement,
scene,
originalElementsMap,
false,
);
} else {
const origElement = elementsInUnit[0]?.original;
const latestElement = elementsInUnit[0]?.latest;
if (
origElement &&
latestElement &&
isPropertyEditable(latestElement, property)
) {
const [cx, cy] = [
origElement.x + origElement.width / 2,
origElement.y + origElement.height / 2,
];
const [topLeftX, topLeftY] = pointRotateRads(
pointFrom(origElement.x, origElement.y),
pointFrom(cx, cy),
origElement.angle,
);
const newTopLeftX = property === "x" ? nextValue : topLeftX;
const newTopLeftY = property === "y" ? nextValue : topLeftY;
moveElement(
newTopLeftX,
newTopLeftY,
origElement,
scene,
originalElementsMap,
false,
);
}
}
}
scene.triggerUpdate();
return;
}
const change = shouldChangeByStepSize
? getStepSizedValue(accumulatedChange, STEP_SIZE)
: accumulatedChange;
const changeInTopX = property === "x" ? change : 0;
const changeInTopY = property === "y" ? change : 0;
moveElements(
property,
changeInTopX,
changeInTopY,
originalElements,
originalElementsMap,
scene,
);
scene.triggerUpdate();
};
return;
}
const change = shouldChangeByStepSize
? getStepSizedValue(accumulatedChange, STEP_SIZE)
: accumulatedChange;
const changeInTopX = property === "x" ? change : 0;
const changeInTopY = property === "y" ? change : 0;
moveElements(
property,
changeInTopX,
changeInTopY,
originalElements,
originalElementsMap,
scene,
);
scene.triggerUpdate();
};