feat: box select frame & children to allow resizing at the same time (#9031)

* box select frame & children

* avoid selecting children twice to avoid double their moving

* do not show ele stats if frame and children selected together

* do not update frame membership if selected together

* do not group frame and its children

* comment and refactor code

* hide align altogether

* include frame children when selecting all

* simplify

---------

Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
This commit is contained in:
Ryan Di 2025-01-29 08:10:16 +11:00 committed by GitHub
parent 7028daa44a
commit 52eaf64591
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 122 additions and 44 deletions

View file

@ -51,6 +51,7 @@ import {
import { KEYS } from "../keys";
import { useTunnels } from "../context/tunnels";
import { CLASSES } from "../constants";
import { alignActionsPredicate } from "../actions/actionAlign";
export const canChangeStrokeColor = (
appState: UIAppState,
@ -90,10 +91,12 @@ export const SelectedShapeActions = ({
appState,
elementsMap,
renderAction,
app,
}: {
appState: UIAppState;
elementsMap: NonDeletedElementsMap | NonDeletedSceneElementsMap;
renderAction: ActionManager["renderAction"];
app: AppClassProperties;
}) => {
const targetElements = getTargetElements(elementsMap, appState);
@ -133,6 +136,9 @@ export const SelectedShapeActions = ({
targetElements.length === 1 &&
isImageElement(targetElements[0]);
const showAlignActions =
!isSingleElementBoundContainer && alignActionsPredicate(appState, app);
return (
<div className="panelColumn">
<div>
@ -200,7 +206,7 @@ export const SelectedShapeActions = ({
</div>
</fieldset>
{targetElements.length > 1 && !isSingleElementBoundContainer && (
{showAlignActions && !isSingleElementBoundContainer && (
<fieldset>
<legend>{t("labels.align")}</legend>
<div className="buttonList">

View file

@ -3235,7 +3235,12 @@ class App extends React.Component<AppProps, AppState> {
newElements,
topLayerFrame,
);
addElementsToFrame(nextElements, eligibleElements, topLayerFrame);
addElementsToFrame(
nextElements,
eligibleElements,
topLayerFrame,
this.state,
);
}
this.scene.replaceAllElements(nextElements);
@ -4326,10 +4331,14 @@ class App extends React.Component<AppProps, AppState> {
}
selectedElements.forEach((element) => {
mutateElement(element, {
x: element.x + offsetX,
y: element.y + offsetY,
});
mutateElement(
element,
{
x: element.x + offsetX,
y: element.y + offsetY,
},
false,
);
updateBoundElements(element, this.scene.getNonDeletedElementsMap(), {
simultaneouslyUpdated: selectedElements,
@ -4346,6 +4355,8 @@ class App extends React.Component<AppProps, AppState> {
),
});
this.scene.triggerUpdate();
event.preventDefault();
} else if (event.key === KEYS.ENTER) {
const selectedElements = this.scene.getSelectedElements(this.state);
@ -8586,6 +8597,7 @@ class App extends React.Component<AppProps, AppState> {
elements,
this.state.selectionElement,
this.scene.getNonDeletedElementsMap(),
false,
)
: [];
@ -9014,6 +9026,7 @@ class App extends React.Component<AppProps, AppState> {
this.scene.getElementsMapIncludingDeleted(),
elementsInsideFrame,
newElement,
this.state,
),
);
}
@ -9131,6 +9144,7 @@ class App extends React.Component<AppProps, AppState> {
nextElements,
elementsToAdd,
topLayerFrame,
this.state,
);
} else if (!topLayerFrame) {
if (this.state.editingGroupId) {

View file

@ -219,6 +219,7 @@ const LayerUI = ({
appState={appState}
elementsMap={app.scene.getNonDeletedElementsMap()}
renderAction={actionManager.renderAction}
app={app}
/>
</Island>
</Section>

View file

@ -179,6 +179,7 @@ export const MobileMenu = ({
appState={appState}
elementsMap={app.scene.getNonDeletedElementsMap()}
renderAction={actionManager.renderAction}
app={app}
/>
</Section>
) : null}

View file

@ -31,6 +31,7 @@ import "./Stats.scss";
import { isGridModeEnabled } from "../../snapping";
import { getUncroppedWidthAndHeight } from "../../element/cropElement";
import { round } from "../../../math";
import { frameAndChildrenSelectedTogether } from "../../frame";
interface StatsProps {
app: AppClassProperties;
@ -170,6 +171,10 @@ export const StatsInner = memo(
return getAtomicUnits(selectedElements, appState);
}, [selectedElements, appState]);
const _frameAndChildrenSelectedTogether = useMemo(() => {
return frameAndChildrenSelectedTogether(selectedElements);
}, [selectedElements]);
return (
<div className="exc-stats">
<Island padding={3}>
@ -226,7 +231,7 @@ export const StatsInner = memo(
{renderCustomStats?.(elements, appState)}
</Collapsible>
{selectedElements.length > 0 && (
{!_frameAndChildrenSelectedTogether && selectedElements.length > 0 && (
<div
id="elementStats"
style={{