2021-05-28 20:30:27 +00:00
|
|
|
import Command from './command'
|
|
|
|
import history from '../history'
|
|
|
|
import { Data, Corner, Edge } from 'types'
|
|
|
|
import { getShapeUtils } from 'lib/shape-utils'
|
|
|
|
import { current } from 'immer'
|
|
|
|
import { TransformSingleSnapshot } from 'state/sessions/transform-single-session'
|
2021-06-04 16:08:43 +00:00
|
|
|
import { getPage, updateParents } from 'utils/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-05-19 09:35:00 +00:00
|
|
|
) {
|
2021-05-28 20:30:27 +00:00
|
|
|
const shape = current(getPage(data, after.currentPageId).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
|
|
|
|
|
|
|
const { shapes } = getPage(data, after.currentPageId)
|
2021-05-19 09:35:00 +00:00
|
|
|
|
2021-05-19 21:24:41 +00:00
|
|
|
data.selectedIds.clear()
|
|
|
|
data.selectedIds.add(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
|
|
|
|
|
|
|
const { shapes } = getPage(data, before.currentPageId)
|
2021-05-19 21:24:41 +00:00
|
|
|
|
|
|
|
if (isCreating) {
|
2021-06-05 19:36:46 +00:00
|
|
|
data.selectedIds.clear()
|
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-05 19:36:46 +00:00
|
|
|
data.selectedIds = new Set([id])
|
2021-05-19 21:24:41 +00:00
|
|
|
}
|
2021-05-19 09:35:00 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|