From 54fb5effefcd0f95ccb8648359c68180ccbb071c Mon Sep 17 00:00:00 2001 From: Peng Xiao Date: Sun, 18 Dec 2022 20:28:54 +0800 Subject: [PATCH] fix: pasting group shape issue --- tldraw/packages/core/src/lib/TLApi/TLApi.ts | 24 +++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tldraw/packages/core/src/lib/TLApi/TLApi.ts b/tldraw/packages/core/src/lib/TLApi/TLApi.ts index 117160c835..d863660a98 100644 --- a/tldraw/packages/core/src/lib/TLApi/TLApi.ts +++ b/tldraw/packages/core/src/lib/TLApi/TLApi.ts @@ -219,14 +219,16 @@ export class TLApi }) => { const commonBounds = BoundsUtils.getCommonBounds( - shapes.map(shape => ({ - minX: shape.point?.[0] ?? point[0], - minY: shape.point?.[1] ?? point[1], - width: shape.size?.[0] ?? 4, - height: shape.size?.[1] ?? 4, - maxX: (shape.point?.[0] ?? point[0]) + (shape.size?.[0] ?? 4), - maxY: (shape.point?.[1] ?? point[1]) + (shape.size?.[1] ?? 4), - })) + shapes + .filter(s => s.type !== 'group') + .map(shape => ({ + minX: shape.point?.[0] ?? point[0], + minY: shape.point?.[1] ?? point[1], + width: shape.size?.[0] ?? 4, + height: shape.size?.[1] ?? 4, + maxX: (shape.point?.[0] ?? point[0]) + (shape.size?.[0] ?? 4), + maxY: (shape.point?.[1] ?? point[1]) + (shape.size?.[1] ?? 4), + })) ) const clonedShapes = shapes.map(shape => { @@ -242,9 +244,9 @@ export class TLApi { if (s.children && s.children?.length > 0) { - s.children = s.children.map(oldId => { - return clonedShapes[shapes.findIndex(s => s.id === oldId)].id - }) + s.children = s.children + .map(oldId => clonedShapes[shapes.findIndex(s => s.id === oldId)]?.id) + .filter(isNonNullable) } })