flattening: use correct id for asset (#3968)

Describe what your pull request does. If appropriate, add GIFs or images
showing the before and after.

### Change Type

<!--  Please select a 'Scope' label ️ -->

- [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

<!--  Please select a 'Type' label ️ -->

- [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
This commit is contained in:
Mime Čuvalo 2024-06-18 12:27:50 +01:00 committed by GitHub
parent 9638935519
commit 87b5ef4a56
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,5 +1,4 @@
import { import {
AssetRecordType,
Box, Box,
Editor, Editor,
IndexKey, IndexKey,
@ -120,8 +119,6 @@ export async function flattenShapesToImages(
const { asset, bounds, shapes } = group const { asset, bounds, shapes } = group
if (!asset) continue if (!asset) continue
const assetId = AssetRecordType.createId()
const commonAncestorId = editor.findCommonAncestor(shapes) ?? editor.getCurrentPageId() const commonAncestorId = editor.findCommonAncestor(shapes) ?? editor.getCurrentPageId()
if (!commonAncestorId) continue if (!commonAncestorId) continue
@ -164,7 +161,7 @@ export async function flattenShapesToImages(
editor.deleteShapes(shapes) editor.deleteShapes(shapes)
// create the asset // create the asset
editor.createAssets([{ ...asset, id: assetId }]) editor.createAssets([{ ...asset, id: asset.id }])
const shapeId = createShapeId() const shapeId = createShapeId()
@ -178,7 +175,7 @@ export async function flattenShapesToImages(
y, y,
rotation: -rotation, rotation: -rotation,
props: { props: {
assetId, assetId: asset.id,
w: bounds.w + padding * 2, w: bounds.w + padding * 2,
h: bounds.h + padding * 2, h: bounds.h + padding * 2,
}, },