Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

transform-single.ts 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import Command from './command'
  2. import history from '../history'
  3. import { Data, Corner, Edge } from 'types'
  4. import { getShapeUtils } from 'lib/shape-utils'
  5. import { current } from 'immer'
  6. import { TransformSingleSnapshot } from 'state/sessions/transform-single-session'
  7. import { getPage, updateParents } from 'utils/utils'
  8. export default function transformSingleCommand(
  9. data: Data,
  10. before: TransformSingleSnapshot,
  11. after: TransformSingleSnapshot,
  12. isCreating: boolean
  13. ) {
  14. const shape = current(getPage(data, after.currentPageId).shapes[after.id])
  15. history.execute(
  16. data,
  17. new Command({
  18. name: 'transform_single_shape',
  19. category: 'canvas',
  20. manualSelection: true,
  21. do(data) {
  22. const { id } = after
  23. const { shapes } = getPage(data, after.currentPageId)
  24. data.selectedIds.clear()
  25. data.selectedIds.add(id)
  26. shapes[id] = shape
  27. updateParents(data, [id])
  28. },
  29. undo(data) {
  30. const { id, type, initialShapeBounds } = before
  31. const { shapes } = getPage(data, before.currentPageId)
  32. data.selectedIds.clear()
  33. if (isCreating) {
  34. delete shapes[id]
  35. } else {
  36. const shape = shapes[id]
  37. data.selectedIds.add(id)
  38. getShapeUtils(shape).transform(shape, initialShapeBounds, {
  39. type,
  40. initialShape: after.initialShape,
  41. scaleX: 1,
  42. scaleY: 1,
  43. transformOrigin: [0.5, 0.5],
  44. })
  45. updateParents(data, [id])
  46. }
  47. },
  48. })
  49. )
  50. }