Compare commits

...

8 Commits

Author SHA1 Message Date
Ryan Di
ae88ea555c simplify code 2023-11-22 17:35:44 +08:00
Ryan Di
14eecf651f merge with master 2023-11-22 17:23:13 +08:00
Ryan Di
c951a001f7 keep resizing logic in sync with master 2023-11-22 17:21:13 +08:00
Barnabás Molnár
7c9cf30909 fix: make zoomToFit fitToViewport account for sidebar (#7298) 2023-11-17 15:56:19 +01:00
David Luzar
1e37dbd60e feat: change frame resizing behavior (#7307) 2023-11-17 14:37:43 +01:00
David Luzar
f8d5c2a1b6 build: allow a range of major node versions (#7306) 2023-11-17 14:23:19 +01:00
Ryan Di
25ab75cb9b wip: resizing multiple frames resizes frame children 2023-11-17 19:50:15 +08:00
Aakansha Doshi
23b24ea5c3 build: use caret for specifying node version to avoid major upgrades automatically (#7297) 2023-11-16 16:18:38 +05:30
3 changed files with 36 additions and 68 deletions

View File

@@ -96,7 +96,7 @@
"vitest-canvas-mock": "0.3.2" "vitest-canvas-mock": "0.3.2"
}, },
"engines": { "engines": {
"node": ">=18.0.0" "node": "18.0.0 - 20.x.x"
}, },
"homepage": ".", "homepage": ".",
"name": "excalidraw", "name": "excalidraw",

View File

@@ -265,7 +265,21 @@ export const zoomToFit = ({
30.0, 30.0,
) as NormalizedZoomValue; ) as NormalizedZoomValue;
scrollX = (appState.width / 2) * (1 / newZoomValue) - centerX; let appStateWidth = appState.width;
if (appState.openSidebar) {
const sidebarDOMElem = document.querySelector(
".sidebar",
) as HTMLElement | null;
const sidebarWidth = sidebarDOMElem?.offsetWidth ?? 0;
const isRTL = document.documentElement.getAttribute("dir") === "rtl";
appStateWidth = !isRTL
? appState.width - sidebarWidth
: appState.width + sidebarWidth;
}
scrollX = (appStateWidth / 2) * (1 / newZoomValue) - centerX;
scrollY = (appState.height / 2) * (1 / newZoomValue) - centerY; scrollY = (appState.height / 2) * (1 / newZoomValue) - centerY;
} else { } else {
newZoomValue = zoomValueToFitBoundsOnViewport(commonBounds, { newZoomValue = zoomValueToFitBoundsOnViewport(commonBounds, {

View File

@@ -8238,27 +8238,8 @@ class App extends React.Component<AppProps, AppState> {
event[KEYS.CTRL_OR_CMD] ? null : this.state.gridSize, event[KEYS.CTRL_OR_CMD] ? null : this.state.gridSize,
); );
const frameElementsOffsetsMap = new Map< const resizingSingleFrameOnly =
string, selectedElements.length === 1 && selectedFrames.length === 1;
{
x: number;
y: number;
}
>();
selectedFrames.forEach((frame) => {
const elementsInFrame = getFrameChildren(
this.scene.getNonDeletedElements(),
frame.id,
);
elementsInFrame.forEach((element) => {
frameElementsOffsetsMap.set(frame.id + element.id, {
x: element.x - frame.x,
y: element.y - frame.y,
});
});
});
// check needed for avoiding flickering when a key gets pressed // check needed for avoiding flickering when a key gets pressed
// during dragging // during dragging
@@ -8299,7 +8280,12 @@ class App extends React.Component<AppProps, AppState> {
transformElements( transformElements(
pointerDownState, pointerDownState,
transformHandleType, transformHandleType,
selectedElements, resizingSingleFrameOnly
? selectedElements
: this.scene.getSelectedElements({
selectedElementIds: this.state.selectedElementIds,
includeElementsInFrames: true,
}),
pointerDownState.resize.arrowDirection, pointerDownState.resize.arrowDirection,
shouldRotateWithDiscreteAngle(event), shouldRotateWithDiscreteAngle(event),
shouldResizeFromCenter(event), shouldResizeFromCenter(event),
@@ -8315,51 +8301,19 @@ class App extends React.Component<AppProps, AppState> {
) { ) {
this.maybeSuggestBindingForAll(selectedElements); this.maybeSuggestBindingForAll(selectedElements);
const elementsToHighlight = new Set<ExcalidrawElement>(); // highlight frame children ONLY when resizing a single frame
selectedFrames.forEach((frame) => { if (resizingSingleFrameOnly) {
const elementsInFrame = getFrameChildren( const selectedFrame = selectedFrames[0];
this.scene.getNonDeletedElements(), if (selectedFrame) {
frame.id, this.setState({
); elementsToHighlight: getElementsInResizingFrame(
this.scene.getNonDeletedElements(),
// keep elements' positions relative to their frames on frames resizing selectedFrame,
if (transformHandleType) { this.state,
if (transformHandleType.includes("w")) { ),
elementsInFrame.forEach((element) => { });
mutateElement(element, {
x:
frame.x +
(frameElementsOffsetsMap.get(frame.id + element.id)?.x || 0),
y:
frame.y +
(frameElementsOffsetsMap.get(frame.id + element.id)?.y || 0),
});
});
}
if (transformHandleType.includes("n")) {
elementsInFrame.forEach((element) => {
mutateElement(element, {
x:
frame.x +
(frameElementsOffsetsMap.get(frame.id + element.id)?.x || 0),
y:
frame.y +
(frameElementsOffsetsMap.get(frame.id + element.id)?.y || 0),
});
});
}
} }
}
getElementsInResizingFrame(
this.scene.getNonDeletedElements(),
frame,
this.state,
).forEach((element) => elementsToHighlight.add(element));
});
this.setState({
elementsToHighlight: [...elementsToHighlight],
});
return true; return true;
} }