瀏覽代碼

enables transforms for groups

main
Steve Ruiz 4 年之前
父節點
當前提交
9f8f56db7e

+ 31
- 0
packages/tldraw/src/state/session/sessions/transform/transform.session.spec.ts 查看文件

@@ -186,4 +186,35 @@ describe('Transform session', () => {
186 186
   describe('when transforming from the left edge', () => {
187 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 查看文件

@@ -249,7 +249,7 @@ export class TLDrawState extends StateManager<Data> {
249 249
               children
250 250
                 .map((id) => page.shapes[id])
251 251
                 .filter(Boolean)
252
-                .map((shape) => TLDR.getBounds(shape))
252
+                .map((shape) => TLDR.getRotatedBounds(shape))
253 253
             )
254 254
 
255 255
             page.shapes[group.id] = {
@@ -1423,7 +1423,11 @@ export class TLDrawState extends StateManager<Data> {
1423 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 1431
       return this.startSession(
1428 1432
         new Sessions.TransformSingleSession(this.state, point, this.pointedBoundsHandle, commandId)
1429 1433
       )

Loading…
取消
儲存