Feature description
This is a follow-up issue for ampproject/amp-wp#3798.
Also to consider: keypress events for resizing, rotating, dragging. That's on hold though until we have information about the best practices using keyboard for doing that.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- It's possible to resize, drag, rotate multiple selected elements at once.
Implementation brief
When more than one element is selected, one additional Moveable will be displayed which has all the selected elements as targets in an array (target={ arrayOfTargets }
). Moveable displays an outline around the selected elements by default:
For dragging, resizing, and rotating, we will need to set the initial values to the frames
as an array of objects, e.g.
const frames = [
{
translate: [ 0, 0 ],
rotate: rotationAngle1,
},
{
translate: [ 0, 0 ],
rotate: rotationAngle2,
},
];
where rotation angle should be the respective initial rotation angle of each element.
Dragging
Based on the documentation, this should work for updating the style for all the elements while dragging in onDragGroup
(tested and it does work):
events.forEach( ( { target, beforeTranslate }, i ) => {
const frame = frames[ i ];
frame.translate = beforeTranslate;
target.style.transform = `translate(${ beforeTranslate[ 0 ] }px, ${ beforeTranslate[ 1 ] }px)`;
} );
Then, in onDragGroupEnd
we can update the x
and y
params of all the elements by adding the translate
values to the original x
and y
.
Rotating
Rotation works in a similar way with a difference that once we finish rotating, we can just set the rotation angle directly from the frames
values as the updated element property since it already considers the initial rotation angle as well.
Resizing
Resizing works in a similar way as resizing for a single element with the difference of having to loop through the targets to assign the values to each target separately.
Within this issue, in all three cases, the element values in the state are updated only when ending the activity, within onResizeGroupEnd
, onDragGroupEnd
and onRotateGroupEnd
.
The selected elements should remain selected.
For simplicity, this implementation of this issue will not "care" about the following:
- Boundaries
- Resizing limits
- Keyboard events (common practices TBD by UX)
- Content within the elements
QA testing instructions
Demo
Changelog entry