2021-05-31 19:13:43 +00:00
|
|
|
import Command from './command'
|
|
|
|
import history from '../history'
|
2021-06-05 07:42:17 +00:00
|
|
|
import { Data } from 'types'
|
2021-05-31 19:13:43 +00:00
|
|
|
import { getPage } from 'utils/utils'
|
|
|
|
import { ArrowSnapshot } from 'state/sessions/arrow-session'
|
|
|
|
|
|
|
|
export default function arrowCommand(
|
|
|
|
data: Data,
|
|
|
|
before: ArrowSnapshot,
|
|
|
|
after: ArrowSnapshot
|
|
|
|
) {
|
|
|
|
history.execute(
|
|
|
|
data,
|
|
|
|
new Command({
|
|
|
|
name: 'point_arrow',
|
|
|
|
category: 'canvas',
|
|
|
|
manualSelection: true,
|
|
|
|
do(data, isInitial) {
|
|
|
|
if (isInitial) return
|
|
|
|
|
|
|
|
const { initialShape, currentPageId } = after
|
|
|
|
|
2021-06-05 06:36:39 +00:00
|
|
|
const page = getPage(data, currentPageId)
|
|
|
|
|
|
|
|
page.shapes[initialShape.id] = initialShape
|
2021-05-31 19:13:43 +00:00
|
|
|
|
|
|
|
data.selectedIds.clear()
|
|
|
|
data.selectedIds.add(initialShape.id)
|
|
|
|
data.hoveredId = undefined
|
|
|
|
data.pointedId = undefined
|
|
|
|
},
|
|
|
|
undo(data) {
|
|
|
|
const { initialShape, currentPageId } = before
|
|
|
|
const shapes = getPage(data, currentPageId).shapes
|
|
|
|
|
|
|
|
delete shapes[initialShape.id]
|
|
|
|
|
|
|
|
data.selectedIds.clear()
|
|
|
|
data.hoveredId = undefined
|
|
|
|
data.pointedId = undefined
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|