You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

transform-single.ts 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import Command from './command'
  2. import history from '../history'
  3. import { Data } from 'types'
  4. import { current } from 'immer'
  5. import { TransformSingleSnapshot } from 'state/sessions/transform-single-session'
  6. import { getPage, setSelectedIds, updateParents } from 'utils/utils'
  7. export default function transformSingleCommand(
  8. data: Data,
  9. before: TransformSingleSnapshot,
  10. after: TransformSingleSnapshot,
  11. isCreating: boolean
  12. ): void {
  13. const shape = current(getPage(data, after.currentPageId).shapes[after.id])
  14. history.execute(
  15. data,
  16. new Command({
  17. name: 'transform_single_shape',
  18. category: 'canvas',
  19. manualSelection: true,
  20. do(data) {
  21. const { id } = after
  22. const { shapes } = getPage(data, after.currentPageId)
  23. setSelectedIds(data, [id])
  24. shapes[id] = shape
  25. updateParents(data, [id])
  26. },
  27. undo(data) {
  28. const { id, initialShape } = before
  29. const { shapes } = getPage(data, before.currentPageId)
  30. if (isCreating) {
  31. setSelectedIds(data, [])
  32. delete shapes[id]
  33. } else {
  34. const page = getPage(data)
  35. page.shapes[id] = initialShape
  36. updateParents(data, [id])
  37. setSelectedIds(data, [id])
  38. }
  39. },
  40. })
  41. )
  42. }