mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Fix lint issues
This commit is contained in:
parent
820a8540b1
commit
af428d472c
9 changed files with 146 additions and 136 deletions
|
@ -12,7 +12,12 @@ import type Scene from "@excalidraw/element/Scene";
|
||||||
import { angleIcon } from "../icons";
|
import { angleIcon } from "../icons";
|
||||||
|
|
||||||
import DragInput from "./DragInput";
|
import DragInput from "./DragInput";
|
||||||
import { DragInputCallbackType, getStepSizedValue, isPropertyEditable, updateBindings } from "./utils";
|
import {
|
||||||
|
type DragInputCallbackType,
|
||||||
|
getStepSizedValue,
|
||||||
|
isPropertyEditable,
|
||||||
|
updateBindings,
|
||||||
|
} from "./utils";
|
||||||
|
|
||||||
import type { AppState } from "../../types";
|
import type { AppState } from "../../types";
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,11 @@ import type { ExcalidrawElement } from "@excalidraw/element/types";
|
||||||
import type Scene from "@excalidraw/element/Scene";
|
import type Scene from "@excalidraw/element/Scene";
|
||||||
|
|
||||||
import DragInput from "./DragInput";
|
import DragInput from "./DragInput";
|
||||||
import { DragInputCallbackType, getStepSizedValue, isPropertyEditable } from "./utils";
|
import {
|
||||||
|
type DragInputCallbackType,
|
||||||
|
getStepSizedValue,
|
||||||
|
isPropertyEditable,
|
||||||
|
} from "./utils";
|
||||||
|
|
||||||
import type { AppState } from "../../types";
|
import type { AppState } from "../../types";
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import { CaptureUpdateAction } from "../../store";
|
||||||
import { useApp } from "../App";
|
import { useApp } from "../App";
|
||||||
import { InlineIcon } from "../InlineIcon";
|
import { InlineIcon } from "../InlineIcon";
|
||||||
|
|
||||||
import { DragInputCallbackType, SMALLEST_DELTA } from "./utils";
|
import { type DragInputCallbackType, SMALLEST_DELTA } from "./utils";
|
||||||
|
|
||||||
import "./DragInput.scss";
|
import "./DragInput.scss";
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ import type Scene from "@excalidraw/element/Scene";
|
||||||
import { fontSizeIcon } from "../icons";
|
import { fontSizeIcon } from "../icons";
|
||||||
|
|
||||||
import StatsDragInput from "./DragInput";
|
import StatsDragInput from "./DragInput";
|
||||||
import { DragInputCallbackType, getStepSizedValue } from "./utils";
|
import { type DragInputCallbackType, getStepSizedValue } from "./utils";
|
||||||
|
|
||||||
import type { AppState } from "../../types";
|
import type { AppState } from "../../types";
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,11 @@ import type Scene from "@excalidraw/element/Scene";
|
||||||
import { angleIcon } from "../icons";
|
import { angleIcon } from "../icons";
|
||||||
|
|
||||||
import DragInput from "./DragInput";
|
import DragInput from "./DragInput";
|
||||||
import { DragInputCallbackType, getStepSizedValue, isPropertyEditable } from "./utils";
|
import {
|
||||||
|
type DragInputCallbackType,
|
||||||
|
getStepSizedValue,
|
||||||
|
isPropertyEditable,
|
||||||
|
} from "./utils";
|
||||||
|
|
||||||
import type { AppState } from "../../types";
|
import type { AppState } from "../../types";
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ import type Scene from "@excalidraw/element/Scene";
|
||||||
|
|
||||||
import DragInput from "./DragInput";
|
import DragInput from "./DragInput";
|
||||||
import { getAtomicUnits, getStepSizedValue, isPropertyEditable } from "./utils";
|
import { getAtomicUnits, getStepSizedValue, isPropertyEditable } from "./utils";
|
||||||
import { DragInputCallbackType, getElementsInAtomicUnit } from "./utils";
|
import { type DragInputCallbackType, getElementsInAtomicUnit } from "./utils";
|
||||||
|
|
||||||
import type { AtomicUnit } from "./utils";
|
import type { AtomicUnit } from "./utils";
|
||||||
import type { AppState } from "../../types";
|
import type { AppState } from "../../types";
|
||||||
|
|
|
@ -10,10 +10,8 @@ import type Scene from "@excalidraw/element/Scene";
|
||||||
import StatsDragInput from "./DragInput";
|
import StatsDragInput from "./DragInput";
|
||||||
import { handlePositionChange } from "./utils";
|
import { handlePositionChange } from "./utils";
|
||||||
|
|
||||||
import type { AtomicUnit } from "./utils";
|
|
||||||
import type { AppState } from "../../types";
|
import type { AppState } from "../../types";
|
||||||
import { getFrameChildren } from "@excalidraw/element/frame";
|
import type { AtomicUnit } from "./utils";
|
||||||
import { isFrameLikeElement } from "@excalidraw/element/typeChecks";
|
|
||||||
|
|
||||||
interface MultiPositionProps {
|
interface MultiPositionProps {
|
||||||
property: "x" | "y";
|
property: "x" | "y";
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
import { pointFrom, pointRotateRads, round } from "@excalidraw/math";
|
import { pointFrom, pointRotateRads, round } from "@excalidraw/math";
|
||||||
|
|
||||||
import {
|
import { getFlipAdjustedCropPosition } from "@excalidraw/element/cropElement";
|
||||||
getFlipAdjustedCropPosition,
|
import { isImageElement } from "@excalidraw/element/typeChecks";
|
||||||
} from "@excalidraw/element/cropElement";
|
|
||||||
import { isFrameLikeElement, isImageElement } from "@excalidraw/element/typeChecks";
|
|
||||||
|
|
||||||
import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";
|
import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";
|
||||||
|
|
||||||
|
@ -13,7 +11,6 @@ import StatsDragInput from "./DragInput";
|
||||||
import { handlePositionChange } from "./utils";
|
import { handlePositionChange } from "./utils";
|
||||||
|
|
||||||
import type { AppState } from "../../types";
|
import type { AppState } from "../../types";
|
||||||
import { getFrameChildren } from "@excalidraw/element/frame";
|
|
||||||
|
|
||||||
interface PositionProps {
|
interface PositionProps {
|
||||||
property: "x" | "y";
|
property: "x" | "y";
|
||||||
|
|
|
@ -7,7 +7,6 @@ import {
|
||||||
import { getBoundTextElement } from "@excalidraw/element/textElement";
|
import { getBoundTextElement } from "@excalidraw/element/textElement";
|
||||||
import { getCommonBounds } from "@excalidraw/element/bounds";
|
import { getCommonBounds } from "@excalidraw/element/bounds";
|
||||||
import {
|
import {
|
||||||
isFrameChildElement,
|
|
||||||
isFrameLikeElement,
|
isFrameLikeElement,
|
||||||
isLinearElement,
|
isLinearElement,
|
||||||
isTextElement,
|
isTextElement,
|
||||||
|
@ -19,6 +18,8 @@ import {
|
||||||
isInGroup,
|
isInGroup,
|
||||||
} from "@excalidraw/element/groups";
|
} from "@excalidraw/element/groups";
|
||||||
|
|
||||||
|
import { getFrameChildren } from "@excalidraw/element/frame";
|
||||||
|
|
||||||
import type { Radians } from "@excalidraw/math";
|
import type { Radians } from "@excalidraw/math";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
|
@ -30,7 +31,6 @@ import type {
|
||||||
import type Scene from "@excalidraw/element/Scene";
|
import type Scene from "@excalidraw/element/Scene";
|
||||||
|
|
||||||
import type { AppState } from "../../types";
|
import type { AppState } from "../../types";
|
||||||
import { getFrameChildren } from "@excalidraw/element/frame";
|
|
||||||
|
|
||||||
export type StatsInputProperty =
|
export type StatsInputProperty =
|
||||||
| "x"
|
| "x"
|
||||||
|
@ -93,9 +93,9 @@ export const getElementsInAtomicUnit = (
|
||||||
latest: elementsMap.get(id),
|
latest: elementsMap.get(id),
|
||||||
}))
|
}))
|
||||||
.filter((el) => el.original !== undefined && el.latest !== undefined) as {
|
.filter((el) => el.original !== undefined && el.latest !== undefined) as {
|
||||||
original: NonDeletedExcalidrawElement;
|
original: NonDeletedExcalidrawElement;
|
||||||
latest: NonDeletedExcalidrawElement;
|
latest: NonDeletedExcalidrawElement;
|
||||||
}[];
|
}[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const newOrigin = (
|
export const newOrigin = (
|
||||||
|
@ -194,57 +194,61 @@ export const moveElement = (
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFrameLikeElement(originalElement)) {
|
if (isFrameLikeElement(originalElement)) {
|
||||||
getFrameChildren(originalElementsMap, originalElement.id).forEach(child => {
|
getFrameChildren(originalElementsMap, originalElement.id).forEach(
|
||||||
const latestChildElement = elementsMap.get(child.id);
|
(child) => {
|
||||||
|
const latestChildElement = elementsMap.get(child.id);
|
||||||
|
|
||||||
if (!latestChildElement) return;
|
if (!latestChildElement) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const [childCX, childCY] = [
|
const [childCX, childCY] = [
|
||||||
child.x + child.width / 2,
|
child.x + child.width / 2,
|
||||||
child.y + child.height / 2,
|
child.y + child.height / 2,
|
||||||
];
|
];
|
||||||
const [childTopLeftX, childTopLeftY] = pointRotateRads(
|
const [childTopLeftX, childTopLeftY] = pointRotateRads(
|
||||||
pointFrom(child.x, child.y),
|
pointFrom(child.x, child.y),
|
||||||
pointFrom(childCX, childCY),
|
pointFrom(childCX, childCY),
|
||||||
child.angle,
|
child.angle,
|
||||||
);
|
);
|
||||||
|
|
||||||
const childNewTopLeftX = Math.round(childTopLeftX + changeInX);
|
const childNewTopLeftX = Math.round(childTopLeftX + changeInX);
|
||||||
const childNewTopLeftY = Math.round(childTopLeftY + changeInY);
|
const childNewTopLeftY = Math.round(childTopLeftY + changeInY);
|
||||||
|
|
||||||
const [childX, childY] = pointRotateRads(
|
const [childX, childY] = pointRotateRads(
|
||||||
pointFrom(childNewTopLeftX, childNewTopLeftY),
|
pointFrom(childNewTopLeftX, childNewTopLeftY),
|
||||||
pointFrom(childCX + changeInX, childCY + changeInY),
|
pointFrom(childCX + changeInX, childCY + changeInY),
|
||||||
-child.angle as Radians,
|
-child.angle as Radians,
|
||||||
);
|
);
|
||||||
|
|
||||||
scene.mutateElement(
|
scene.mutateElement(
|
||||||
latestChildElement,
|
latestChildElement,
|
||||||
{
|
{
|
||||||
x: childX,
|
x: childX,
|
||||||
y: childY,
|
y: childY,
|
||||||
},
|
},
|
||||||
{ informMutation: shouldInformMutation, isDragging: false },
|
{ informMutation: shouldInformMutation, isDragging: false },
|
||||||
);
|
);
|
||||||
updateBindings(latestChildElement, scene);
|
updateBindings(latestChildElement, scene);
|
||||||
|
|
||||||
const boundTextElement = getBoundTextElement(
|
const boundTextElement = getBoundTextElement(
|
||||||
latestChildElement,
|
latestChildElement,
|
||||||
originalElementsMap,
|
originalElementsMap,
|
||||||
);
|
);
|
||||||
if (boundTextElement) {
|
if (boundTextElement) {
|
||||||
const latestBoundTextElement = elementsMap.get(boundTextElement.id);
|
const latestBoundTextElement = elementsMap.get(boundTextElement.id);
|
||||||
latestBoundTextElement &&
|
latestBoundTextElement &&
|
||||||
scene.mutateElement(
|
scene.mutateElement(
|
||||||
latestBoundTextElement,
|
latestBoundTextElement,
|
||||||
{
|
{
|
||||||
x: boundTextElement.x + changeInX,
|
x: boundTextElement.x + changeInX,
|
||||||
y: boundTextElement.y + changeInY,
|
y: boundTextElement.y + changeInY,
|
||||||
},
|
},
|
||||||
{ informMutation: shouldInformMutation, isDragging: false },
|
{ informMutation: shouldInformMutation, isDragging: false },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
})
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -368,9 +372,7 @@ export const updateBindings = (
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const handlePositionChange: DragInputCallbackType<
|
export const handlePositionChange: DragInputCallbackType<"x" | "y"> = ({
|
||||||
"x" | "y"
|
|
||||||
> = ({
|
|
||||||
accumulatedChange,
|
accumulatedChange,
|
||||||
originalElements,
|
originalElements,
|
||||||
originalElementsMap,
|
originalElementsMap,
|
||||||
|
@ -380,86 +382,86 @@ export const handlePositionChange: DragInputCallbackType<
|
||||||
scene,
|
scene,
|
||||||
originalAppState,
|
originalAppState,
|
||||||
}) => {
|
}) => {
|
||||||
const STEP_SIZE = 10;
|
const STEP_SIZE = 10;
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
|
|
||||||
if (nextValue !== undefined) {
|
if (nextValue !== undefined) {
|
||||||
for (const atomicUnit of getAtomicUnits(
|
for (const atomicUnit of getAtomicUnits(
|
||||||
originalElements,
|
originalElements,
|
||||||
originalAppState,
|
originalAppState,
|
||||||
)) {
|
)) {
|
||||||
const elementsInUnit = getElementsInAtomicUnit(
|
const elementsInUnit = getElementsInAtomicUnit(
|
||||||
atomicUnit,
|
atomicUnit,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
originalElementsMap,
|
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) {
|
moveGroup(
|
||||||
const [x1, y1, ,] = getCommonBounds(
|
newTopLeftX,
|
||||||
elementsInUnit.map((el) => el.latest!),
|
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,
|
newTopLeftX,
|
||||||
newTopLeftY,
|
newTopLeftY,
|
||||||
elementsInUnit.map((el) => el.original),
|
origElement,
|
||||||
originalElementsMap,
|
|
||||||
scene,
|
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();
|
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();
|
||||||
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue