enables transforms for groups

This commit is contained in:
Steve Ruiz 2021-09-03 11:15:03 +01:00
parent 625c819817
commit 9f8f56db7e
2 changed files with 37 additions and 2 deletions

View file

@ -186,4 +186,35 @@ describe('Transform session', () => {
describe('when transforming from the left edge', () => {
// Todo
})
describe('when transforming a group', () => {
it('transforms the groups children', () => {
const tlstate = new TLDrawState()
tlstate
.loadDocument(mockDocument)
.group(['rect1', 'rect2'], 'groupA')
.select('groupA')
.startTransformSession([0, 0], TLBoundsCorner.TopLeft)
.updateTransformSession([10, 10])
.completeSession()
expect(getShapeBounds(tlstate, 'rect1')).toMatchObject({
minX: 10,
minY: 10,
maxX: 105,
maxY: 105,
width: 95,
height: 95,
})
expect(getShapeBounds(tlstate, 'rect2')).toMatchObject({
minX: 105,
minY: 105,
maxX: 200,
maxY: 200,
width: 95,
height: 95,
})
})
})
})

View file

@ -249,7 +249,7 @@ export class TLDrawState extends StateManager<Data> {
children
.map((id) => page.shapes[id])
.filter(Boolean)
.map((shape) => TLDR.getBounds(shape))
.map((shape) => TLDR.getRotatedBounds(shape))
)
page.shapes[group.id] = {
@ -1423,7 +1423,11 @@ export class TLDrawState extends StateManager<Data> {
return this.startSession(new Sessions.RotateSession(this.state, point))
}
if (this.selectedIds.length === 1) {
const idsToTransform = selectedIds.flatMap((id) =>
TLDR.getDocumentBranch(this.state, id, this.currentPageId)
)
if (idsToTransform.length === 1) {
return this.startSession(
new Sessions.TransformSingleSession(this.state, point, this.pointedBoundsHandle, commandId)
)