mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-08-26 11:47:00 +02:00
Compare commits
1 Commits
mrazator/c
...
dwelle/sta
Author | SHA1 | Date | |
---|---|---|---|
![]() |
b9fee5cf9c |
@@ -34,13 +34,9 @@
|
|||||||
<a href="https://discord.gg/UexuTaE">
|
<a href="https://discord.gg/UexuTaE">
|
||||||
<img alt="Chat on Discord" src="https://img.shields.io/discord/723672430744174682?color=738ad6&label=Chat%20on%20Discord&logo=discord&logoColor=ffffff&widge=false"/>
|
<img alt="Chat on Discord" src="https://img.shields.io/discord/723672430744174682?color=738ad6&label=Chat%20on%20Discord&logo=discord&logoColor=ffffff&widge=false"/>
|
||||||
</a>
|
</a>
|
||||||
<a href="https://deepwiki.com/excalidraw/excalidraw">
|
|
||||||
<img alt="Ask DeepWiki" src="https://deepwiki.com/badge.svg" />
|
|
||||||
</a>
|
|
||||||
<a href="https://twitter.com/excalidraw">
|
<a href="https://twitter.com/excalidraw">
|
||||||
<img alt="Follow Excalidraw on Twitter" src="https://img.shields.io/twitter/follow/excalidraw.svg?label=follow+@excalidraw&style=social&logo=twitter"/>
|
<img alt="Follow Excalidraw on Twitter" src="https://img.shields.io/twitter/follow/excalidraw.svg?label=follow+@excalidraw&style=social&logo=twitter"/>
|
||||||
</a>
|
</a>
|
||||||
<img alt"CodeRabbit Reviews" src="https://img.shields.io/coderabbit/prs/github/excalidraw/excalidraw?utm_source=oss&utm_medium=github&utm_campaign=excalidraw%2Fexcalidraw&labelColor=171717&color=FF570A&link=https%3A%2F%2Fcoderabbit.ai&label=CodeRabbit+Reviews"/>
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div align="center">
|
<div align="center">
|
||||||
|
@@ -974,25 +974,6 @@ export const updateElbowArrowPoints = (
|
|||||||
),
|
),
|
||||||
"Elbow arrow segments must be either horizontal or vertical",
|
"Elbow arrow segments must be either horizontal or vertical",
|
||||||
);
|
);
|
||||||
|
|
||||||
invariant(
|
|
||||||
updates.fixedSegments?.find(
|
|
||||||
(segment) =>
|
|
||||||
segment.index === 1 &&
|
|
||||||
pointsEqual(segment.start, (updates.points ?? arrow.points)[0]),
|
|
||||||
) == null &&
|
|
||||||
updates.fixedSegments?.find(
|
|
||||||
(segment) =>
|
|
||||||
segment.index === (updates.points ?? arrow.points).length - 1 &&
|
|
||||||
pointsEqual(
|
|
||||||
segment.end,
|
|
||||||
(updates.points ?? arrow.points)[
|
|
||||||
(updates.points ?? arrow.points).length - 1
|
|
||||||
],
|
|
||||||
),
|
|
||||||
) == null,
|
|
||||||
"The first and last segments cannot be fixed",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const fixedSegments = updates.fixedSegments ?? arrow.fixedSegments ?? [];
|
const fixedSegments = updates.fixedSegments ?? arrow.fixedSegments ?? [];
|
||||||
|
@@ -1483,13 +1483,13 @@ const getArrowheadOptions = (flip: boolean) => {
|
|||||||
value: "crowfoot_one",
|
value: "crowfoot_one",
|
||||||
text: t("labels.arrowhead_crowfoot_one"),
|
text: t("labels.arrowhead_crowfoot_one"),
|
||||||
icon: <ArrowheadCrowfootOneIcon flip={flip} />,
|
icon: <ArrowheadCrowfootOneIcon flip={flip} />,
|
||||||
keyBinding: "x",
|
keyBinding: "c",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "crowfoot_many",
|
value: "crowfoot_many",
|
||||||
text: t("labels.arrowhead_crowfoot_many"),
|
text: t("labels.arrowhead_crowfoot_many"),
|
||||||
icon: <ArrowheadCrowfootIcon flip={flip} />,
|
icon: <ArrowheadCrowfootIcon flip={flip} />,
|
||||||
keyBinding: "c",
|
keyBinding: "x",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "crowfoot_one_or_many",
|
value: "crowfoot_one_or_many",
|
||||||
|
@@ -564,7 +564,7 @@ export const convertElementTypes = (
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const fixedSegments: FixedSegment[] = [];
|
const fixedSegments: FixedSegment[] = [];
|
||||||
for (let i = 1; i < nextPoints.length - 2; i++) {
|
for (let i = 0; i < nextPoints.length - 1; i++) {
|
||||||
fixedSegments.push({
|
fixedSegments.push({
|
||||||
start: nextPoints[i],
|
start: nextPoints[i],
|
||||||
end: nextPoints[i + 1],
|
end: nextPoints[i + 1],
|
||||||
@@ -581,7 +581,6 @@ export const convertElementTypes = (
|
|||||||
);
|
);
|
||||||
mutateElement(element, app.scene.getNonDeletedElementsMap(), {
|
mutateElement(element, app.scene.getNonDeletedElementsMap(), {
|
||||||
...updates,
|
...updates,
|
||||||
endArrowhead: "arrow",
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// if we're converting to non-elbow linear element, check if
|
// if we're converting to non-elbow linear element, check if
|
||||||
|
@@ -39,6 +39,7 @@ const handleDimensionChange: DragInputCallbackType<
|
|||||||
shouldKeepAspectRatio,
|
shouldKeepAspectRatio,
|
||||||
shouldChangeByStepSize,
|
shouldChangeByStepSize,
|
||||||
nextValue,
|
nextValue,
|
||||||
|
ratio,
|
||||||
property,
|
property,
|
||||||
originalAppState,
|
originalAppState,
|
||||||
instantChange,
|
instantChange,
|
||||||
@@ -154,6 +155,12 @@ const handleDimensionChange: DragInputCallbackType<
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (nextValue !== undefined) {
|
if (nextValue !== undefined) {
|
||||||
|
if (ratio) {
|
||||||
|
ratio = property === "width" ? ratio : [ratio[1], ratio[0]];
|
||||||
|
nextValue = (origElement[property] / ratio[0]) * ratio[1];
|
||||||
|
property = property === "width" ? "height" : "width";
|
||||||
|
}
|
||||||
|
|
||||||
const nextWidth = Math.max(
|
const nextWidth = Math.max(
|
||||||
property === "width"
|
property === "width"
|
||||||
? nextValue
|
? nextValue
|
||||||
|
@@ -33,6 +33,7 @@ export type DragInputCallbackType<
|
|||||||
shouldChangeByStepSize: boolean;
|
shouldChangeByStepSize: boolean;
|
||||||
scene: Scene;
|
scene: Scene;
|
||||||
nextValue?: number;
|
nextValue?: number;
|
||||||
|
ratio?: [number, number] | null;
|
||||||
property: P;
|
property: P;
|
||||||
originalAppState: AppState;
|
originalAppState: AppState;
|
||||||
setInputValue: (value: number) => void;
|
setInputValue: (value: number) => void;
|
||||||
@@ -109,10 +110,21 @@ const StatsDragInput = <
|
|||||||
}
|
}
|
||||||
stateRef.current.updatePending = false;
|
stateRef.current.updatePending = false;
|
||||||
|
|
||||||
|
const ratioMatch = updatedValue
|
||||||
|
.trim()
|
||||||
|
.match(/^(\d+(?:\.\d+)?):(\d+(?:\.\d+)?)$/);
|
||||||
|
|
||||||
|
let ratio: [number, number] | null = null;
|
||||||
|
if (ratioMatch) {
|
||||||
|
ratio = [Number(ratioMatch[1]), Number(ratioMatch[2])];
|
||||||
|
}
|
||||||
|
|
||||||
const parsed = Number(updatedValue);
|
const parsed = Number(updatedValue);
|
||||||
if (isNaN(parsed)) {
|
if (isNaN(parsed)) {
|
||||||
setInputValue(value.toString());
|
setInputValue(value.toString());
|
||||||
return;
|
if (!ratio) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const rounded = Number(parsed.toFixed(2));
|
const rounded = Number(parsed.toFixed(2));
|
||||||
@@ -123,7 +135,11 @@ const StatsDragInput = <
|
|||||||
// 2. original was not "Mixed" and the difference between a new value and previous value is greater
|
// 2. original was not "Mixed" and the difference between a new value and previous value is greater
|
||||||
// than the smallest delta allowed, which is 0.01
|
// than the smallest delta allowed, which is 0.01
|
||||||
// reason: idempotent to avoid unnecessary
|
// reason: idempotent to avoid unnecessary
|
||||||
if (isNaN(original) || Math.abs(rounded - original) >= SMALLEST_DELTA) {
|
if (
|
||||||
|
isNaN(original) ||
|
||||||
|
ratio ||
|
||||||
|
Math.abs(rounded - original) >= SMALLEST_DELTA
|
||||||
|
) {
|
||||||
stateRef.current.lastUpdatedValue = updatedValue;
|
stateRef.current.lastUpdatedValue = updatedValue;
|
||||||
dragInputCallback({
|
dragInputCallback({
|
||||||
accumulatedChange: 0,
|
accumulatedChange: 0,
|
||||||
@@ -134,6 +150,7 @@ const StatsDragInput = <
|
|||||||
shouldChangeByStepSize: false,
|
shouldChangeByStepSize: false,
|
||||||
scene,
|
scene,
|
||||||
nextValue: rounded,
|
nextValue: rounded,
|
||||||
|
ratio,
|
||||||
property,
|
property,
|
||||||
originalAppState: appState,
|
originalAppState: appState,
|
||||||
setInputValue: (value) => setInputValue(String(value)),
|
setInputValue: (value) => setInputValue(String(value)),
|
||||||
|
@@ -151,6 +151,7 @@ const handleDimensionChange: DragInputCallbackType<
|
|||||||
originalAppState,
|
originalAppState,
|
||||||
shouldChangeByStepSize,
|
shouldChangeByStepSize,
|
||||||
nextValue,
|
nextValue,
|
||||||
|
ratio,
|
||||||
scene,
|
scene,
|
||||||
property,
|
property,
|
||||||
}) => {
|
}) => {
|
||||||
@@ -202,9 +203,22 @@ const handleDimensionChange: DragInputCallbackType<
|
|||||||
origElement &&
|
origElement &&
|
||||||
isPropertyEditable(latestElement, property)
|
isPropertyEditable(latestElement, property)
|
||||||
) {
|
) {
|
||||||
|
let _nextValue = nextValue;
|
||||||
|
let _property = property;
|
||||||
|
if (ratio) {
|
||||||
|
let _ratio = ratio;
|
||||||
|
if (ratio) {
|
||||||
|
_ratio = _property === "width" ? _ratio : [_ratio[1], _ratio[0]];
|
||||||
|
_nextValue = (origElement[_property] / _ratio[0]) * _ratio[1];
|
||||||
|
_property = _property === "width" ? "height" : "width";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let nextWidth =
|
let nextWidth =
|
||||||
property === "width" ? Math.max(0, nextValue) : latestElement.width;
|
_property === "width"
|
||||||
if (property === "width") {
|
? Math.max(0, _nextValue)
|
||||||
|
: latestElement.width;
|
||||||
|
if (_property === "width") {
|
||||||
if (shouldChangeByStepSize) {
|
if (shouldChangeByStepSize) {
|
||||||
nextWidth = getStepSizedValue(nextWidth, STEP_SIZE);
|
nextWidth = getStepSizedValue(nextWidth, STEP_SIZE);
|
||||||
} else {
|
} else {
|
||||||
@@ -213,10 +227,10 @@ const handleDimensionChange: DragInputCallbackType<
|
|||||||
}
|
}
|
||||||
|
|
||||||
let nextHeight =
|
let nextHeight =
|
||||||
property === "height"
|
_property === "height"
|
||||||
? Math.max(0, nextValue)
|
? Math.max(0, _nextValue)
|
||||||
: latestElement.height;
|
: latestElement.height;
|
||||||
if (property === "height") {
|
if (_property === "height") {
|
||||||
if (shouldChangeByStepSize) {
|
if (shouldChangeByStepSize) {
|
||||||
nextHeight = getStepSizedValue(nextHeight, STEP_SIZE);
|
nextHeight = getStepSizedValue(nextHeight, STEP_SIZE);
|
||||||
} else {
|
} else {
|
||||||
@@ -234,7 +248,7 @@ const handleDimensionChange: DragInputCallbackType<
|
|||||||
origElement,
|
origElement,
|
||||||
originalElementsMap,
|
originalElementsMap,
|
||||||
scene,
|
scene,
|
||||||
property === "width" ? "e" : "s",
|
_property === "width" ? "e" : "s",
|
||||||
{
|
{
|
||||||
shouldInformMutation: false,
|
shouldInformMutation: false,
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user