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.

edit.ts 989B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import Command from './command'
  2. import history from '../history'
  3. import { Data } from 'types'
  4. import { getPage } from 'utils/utils'
  5. import { EditSnapshot } from 'state/sessions/edit-session'
  6. import { getShapeUtils } from 'lib/shape-utils'
  7. export default function editCommand(
  8. data: Data,
  9. before: EditSnapshot,
  10. after: EditSnapshot
  11. ) {
  12. history.execute(
  13. data,
  14. new Command({
  15. name: 'edit_shape',
  16. category: 'canvas',
  17. do(data) {
  18. const { initialShape, currentPageId } = after
  19. const page = getPage(data, currentPageId)
  20. page.shapes[initialShape.id] = initialShape
  21. const shape = page.shapes[initialShape.id]
  22. if (getShapeUtils(shape).shouldDelete(shape)) {
  23. delete page.shapes[initialShape.id]
  24. }
  25. },
  26. undo(data) {
  27. const { initialShape, currentPageId } = before
  28. const page = getPage(data, currentPageId)
  29. page.shapes[initialShape.id] = initialShape
  30. },
  31. })
  32. )
  33. }