tldraw/state/commands/change-page.ts

27 lines
649 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
2021-06-03 13:10:54 +00:00
export default function changePage(data: Data, pageId: string) {
2021-06-03 12:06:39 +00:00
const { currentPageId: prevPageId } = data
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, prevPageId)
2021-06-03 12:06:39 +00:00
data.currentPageId = pageId
storage.loadPage(data)
2021-06-03 12:06:39 +00:00
},
undo(data) {
data.currentPageId = prevPageId
storage.loadPage(data, prevPageId)
2021-06-03 12:06:39 +00:00
},
})
)
}