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-06-29 12:00:59 +00:00
|
|
|
import tld from 'utils/tld'
|
2021-05-31 19:13:43 +00:00
|
|
|
import { ArrowSnapshot } from 'state/sessions/arrow-session'
|
|
|
|
|
|
|
|
export default function arrowCommand(
|
|
|
|
data: Data,
|
|
|
|
before: ArrowSnapshot,
|
|
|
|
after: ArrowSnapshot
|
2021-06-21 21:35:28 +00:00
|
|
|
): void {
|
2021-05-31 19:13:43 +00:00
|
|
|
history.execute(
|
|
|
|
data,
|
|
|
|
new Command({
|
|
|
|
name: 'point_arrow',
|
|
|
|
category: 'canvas',
|
|
|
|
manualSelection: true,
|
|
|
|
do(data, isInitial) {
|
|
|
|
if (isInitial) return
|
|
|
|
|
2021-06-24 12:34:43 +00:00
|
|
|
const { initialShape } = after
|
2021-05-31 19:13:43 +00:00
|
|
|
|
2021-06-29 12:00:59 +00:00
|
|
|
const page = tld.getPage(data)
|
2021-06-05 06:36:39 +00:00
|
|
|
|
|
|
|
page.shapes[initialShape.id] = initialShape
|
2021-05-31 19:13:43 +00:00
|
|
|
|
2021-06-29 12:00:59 +00:00
|
|
|
const selectedIds = tld.getSelectedIds(data)
|
2021-06-07 11:18:50 +00:00
|
|
|
selectedIds.clear()
|
|
|
|
selectedIds.add(initialShape.id)
|
2021-05-31 19:13:43 +00:00
|
|
|
data.hoveredId = undefined
|
|
|
|
data.pointedId = undefined
|
|
|
|
},
|
|
|
|
undo(data) {
|
2021-06-24 12:34:43 +00:00
|
|
|
const { initialShape } = before
|
2021-06-29 12:00:59 +00:00
|
|
|
const shapes = tld.getPage(data).shapes
|
2021-05-31 19:13:43 +00:00
|
|
|
|
|
|
|
delete shapes[initialShape.id]
|
|
|
|
|
2021-06-29 12:00:59 +00:00
|
|
|
const selectedIds = tld.getSelectedIds(data)
|
2021-06-07 11:18:50 +00:00
|
|
|
selectedIds.clear()
|
2021-05-31 19:13:43 +00:00
|
|
|
data.hoveredId = undefined
|
|
|
|
data.pointedId = undefined
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|