2021-05-28 20:30:27 +00:00
|
|
|
import Command from './command'
|
|
|
|
import history from '../history'
|
2021-06-19 17:22:46 +00:00
|
|
|
import { Data } from 'types'
|
2021-05-28 20:30:27 +00:00
|
|
|
import { current } from 'immer'
|
|
|
|
import { TransformSingleSnapshot } from 'state/sessions/transform-single-session'
|
2021-06-24 08:18:14 +00:00
|
|
|
import { getPage, setSelectedIds, updateParents } from 'utils'
|
2021-05-19 09:35:00 +00:00
|
|
|
|
|
|
|
export default function transformSingleCommand(
|
|
|
|
data: Data,
|
|
|
|
before: TransformSingleSnapshot,
|
|
|
|
after: TransformSingleSnapshot,
|
2021-05-19 21:24:41 +00:00
|
|
|
isCreating: boolean
|
2021-06-21 21:35:28 +00:00
|
|
|
): void {
|
2021-06-24 12:34:43 +00:00
|
|
|
const shape = current(getPage(data).shapes[after.id])
|
2021-05-19 21:24:41 +00:00
|
|
|
|
2021-05-19 09:35:00 +00:00
|
|
|
history.execute(
|
|
|
|
data,
|
|
|
|
new Command({
|
2021-05-28 20:30:27 +00:00
|
|
|
name: 'transform_single_shape',
|
|
|
|
category: 'canvas',
|
2021-05-19 21:24:41 +00:00
|
|
|
manualSelection: true,
|
2021-05-19 09:35:00 +00:00
|
|
|
do(data) {
|
2021-06-03 12:06:39 +00:00
|
|
|
const { id } = after
|
2021-05-22 15:45:24 +00:00
|
|
|
|
2021-06-24 12:34:43 +00:00
|
|
|
const { shapes } = getPage(data)
|
2021-05-19 09:35:00 +00:00
|
|
|
|
2021-06-07 11:18:50 +00:00
|
|
|
setSelectedIds(data, [id])
|
2021-05-19 09:35:00 +00:00
|
|
|
|
2021-06-03 12:06:39 +00:00
|
|
|
shapes[id] = shape
|
2021-06-04 16:08:43 +00:00
|
|
|
|
|
|
|
updateParents(data, [id])
|
2021-05-19 09:35:00 +00:00
|
|
|
},
|
|
|
|
undo(data) {
|
2021-06-05 19:36:46 +00:00
|
|
|
const { id, initialShape } = before
|
2021-05-22 15:45:24 +00:00
|
|
|
|
2021-06-24 12:34:43 +00:00
|
|
|
const { shapes } = getPage(data)
|
2021-05-19 21:24:41 +00:00
|
|
|
|
|
|
|
if (isCreating) {
|
2021-06-07 11:18:50 +00:00
|
|
|
setSelectedIds(data, [])
|
2021-05-22 15:45:24 +00:00
|
|
|
delete shapes[id]
|
2021-05-19 21:24:41 +00:00
|
|
|
} else {
|
2021-06-05 19:36:46 +00:00
|
|
|
const page = getPage(data)
|
|
|
|
page.shapes[id] = initialShape
|
2021-06-04 16:08:43 +00:00
|
|
|
updateParents(data, [id])
|
2021-06-07 11:18:50 +00:00
|
|
|
setSelectedIds(data, [id])
|
2021-05-19 21:24:41 +00:00
|
|
|
}
|
2021-05-19 09:35:00 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|