Browse Source

enables transforms for groups

main
Steve Ruiz 4 years ago
parent
commit
9f8f56db7e

+ 31
- 0
packages/tldraw/src/state/session/sessions/transform/transform.session.spec.ts View File

186
   describe('when transforming from the left edge', () => {
186
   describe('when transforming from the left edge', () => {
187
     // Todo
187
     // Todo
188
   })
188
   })
189
+
190
+  describe('when transforming a group', () => {
191
+    it('transforms the groups children', () => {
192
+      const tlstate = new TLDrawState()
193
+      tlstate
194
+        .loadDocument(mockDocument)
195
+        .group(['rect1', 'rect2'], 'groupA')
196
+        .select('groupA')
197
+        .startTransformSession([0, 0], TLBoundsCorner.TopLeft)
198
+        .updateTransformSession([10, 10])
199
+        .completeSession()
200
+
201
+      expect(getShapeBounds(tlstate, 'rect1')).toMatchObject({
202
+        minX: 10,
203
+        minY: 10,
204
+        maxX: 105,
205
+        maxY: 105,
206
+        width: 95,
207
+        height: 95,
208
+      })
209
+
210
+      expect(getShapeBounds(tlstate, 'rect2')).toMatchObject({
211
+        minX: 105,
212
+        minY: 105,
213
+        maxX: 200,
214
+        maxY: 200,
215
+        width: 95,
216
+        height: 95,
217
+      })
218
+    })
219
+  })
189
 })
220
 })

+ 6
- 2
packages/tldraw/src/state/tlstate.ts View File

249
               children
249
               children
250
                 .map((id) => page.shapes[id])
250
                 .map((id) => page.shapes[id])
251
                 .filter(Boolean)
251
                 .filter(Boolean)
252
-                .map((shape) => TLDR.getBounds(shape))
252
+                .map((shape) => TLDR.getRotatedBounds(shape))
253
             )
253
             )
254
 
254
 
255
             page.shapes[group.id] = {
255
             page.shapes[group.id] = {
1423
       return this.startSession(new Sessions.RotateSession(this.state, point))
1423
       return this.startSession(new Sessions.RotateSession(this.state, point))
1424
     }
1424
     }
1425
 
1425
 
1426
-    if (this.selectedIds.length === 1) {
1426
+    const idsToTransform = selectedIds.flatMap((id) =>
1427
+      TLDR.getDocumentBranch(this.state, id, this.currentPageId)
1428
+    )
1429
+
1430
+    if (idsToTransform.length === 1) {
1427
       return this.startSession(
1431
       return this.startSession(
1428
         new Sessions.TransformSingleSession(this.state, point, this.pointedBoundsHandle, commandId)
1432
         new Sessions.TransformSingleSession(this.state, point, this.pointedBoundsHandle, commandId)
1429
       )
1433
       )

Loading…
Cancel
Save