From 87b5ef4a563f18b0254f55739c161b09e55d044e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mime=20=C4=8Cuvalo?= Date: Tue, 18 Jun 2024 12:27:50 +0100 Subject: [PATCH] flattening: use correct id for asset (#3968) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Describe what your pull request does. If appropriate, add GIFs or images showing the before and after. ### Change Type - [x] `sdk` — Changes the tldraw SDK - [ ] `dotcom` — Changes the tldraw.com web app - [ ] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [ ] `internal` — Does not affect user-facing stuff - [x] `bugfix` — Bug fix - [ ] `feature` — New feature - [ ] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know --- packages/tldraw/src/lib/ui/hooks/useFlatten.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/tldraw/src/lib/ui/hooks/useFlatten.ts b/packages/tldraw/src/lib/ui/hooks/useFlatten.ts index ea8ca123b..86c5a640a 100644 --- a/packages/tldraw/src/lib/ui/hooks/useFlatten.ts +++ b/packages/tldraw/src/lib/ui/hooks/useFlatten.ts @@ -1,5 +1,4 @@ import { - AssetRecordType, Box, Editor, IndexKey, @@ -120,8 +119,6 @@ export async function flattenShapesToImages( const { asset, bounds, shapes } = group if (!asset) continue - const assetId = AssetRecordType.createId() - const commonAncestorId = editor.findCommonAncestor(shapes) ?? editor.getCurrentPageId() if (!commonAncestorId) continue @@ -164,7 +161,7 @@ export async function flattenShapesToImages( editor.deleteShapes(shapes) // create the asset - editor.createAssets([{ ...asset, id: assetId }]) + editor.createAssets([{ ...asset, id: asset.id }]) const shapeId = createShapeId() @@ -178,7 +175,7 @@ export async function flattenShapesToImages( y, rotation: -rotation, props: { - assetId, + assetId: asset.id, w: bounds.w + padding * 2, h: bounds.h + padding * 2, },