fix: shape parent id on duplicate page (#920)

This commit is contained in:
Judicael 2022-08-21 11:49:45 +03:00 committed by GitHub
parent ae4a1b6fbe
commit 49fc0a261e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,13 +3,15 @@ import type { TldrawApp } from '~state/TldrawApp'
import type { TldrawCommand } from '~types' import type { TldrawCommand } from '~types'
export function duplicatePage(app: TldrawApp, pageId: string): TldrawCommand { export function duplicatePage(app: TldrawApp, pageId: string): TldrawCommand {
const newId = Utils.uniqueId()
const { const {
currentPageId, currentPageId,
page,
pageState: { camera }, pageState: { camera },
} = app } = app
const page = app.document.pages[pageId]
const newId = Utils.uniqueId()
const nextPage = { const nextPage = {
...page, ...page,
id: newId, id: newId,
@ -20,7 +22,7 @@ export function duplicatePage(app: TldrawApp, pageId: string): TldrawCommand {
id, id,
{ {
...shape, ...shape,
parentId: shape.parentId === pageId ? newId : shape.parentId, parentId: shape.parentId === page.id ? newId : shape.parentId,
}, },
] ]
}) })