tldraw/state/commands/change-page.ts

27 lines
699 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'
import storage from 'state/storage'
2021-06-03 12:06:39 +00:00
export default function changePage(data: Data, toPageId: string) {
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
2021-06-03 12:06:39 +00:00
},
undo(data) {
storage.loadPage(data, data.document.id, fromPageId)
data.currentPageId = fromPageId
2021-06-03 12:06:39 +00:00
},
})
)
}