tldraw/state/commands/change-page.ts

34 lines
935 B
TypeScript
Raw Normal View History

2021-06-03 12:06:39 +00:00
import Command from './command'
import history from '../history'
import { Data } from 'types'
2021-07-09 18:42:43 +00:00
import tld from 'utils/tld'
import storage from 'state/storage'
2021-06-03 12:06:39 +00:00
2021-06-21 21:35:28 +00:00
export default function changePage(data: Data, toPageId: string): void {
const { currentPageId: fromPageId } = data
2021-06-03 12:06:39 +00:00
history.execute(
data,
new Command({
name: 'change_page',
category: 'canvas',
manualSelection: true,
2021-06-03 12:06:39 +00:00
do(data) {
storage.savePage(data, data.document.id, fromPageId)
storage.loadPage(data, data.document.id, toPageId)
data.currentPageId = toPageId
data.currentParentId = toPageId
2021-07-09 18:42:43 +00:00
tld.setZoomCSS(tld.getPageState(data).camera.zoom)
2021-06-03 12:06:39 +00:00
},
undo(data) {
storage.loadPage(data, data.document.id, fromPageId)
data.currentPageId = fromPageId
data.currentParentId = fromPageId
2021-07-09 18:42:43 +00:00
tld.setZoomCSS(tld.getPageState(data).camera.zoom)
2021-06-03 12:06:39 +00:00
},
})
)
}