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.

reset-bounds.ts 1.0KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import Command from './command'
  2. import history from '../history'
  3. import { Data } from 'types'
  4. import { getPage, getSelectedShapes, updateParents } from 'utils/utils'
  5. import { current } from 'immer'
  6. import { getShapeUtils } from 'state/shape-utils'
  7. export default function resetBoundsCommand(data: Data): void {
  8. const initialShapes = Object.fromEntries(
  9. getSelectedShapes(current(data)).map((shape) => [shape.id, shape])
  10. )
  11. history.execute(
  12. data,
  13. new Command({
  14. name: 'reset_bounds',
  15. category: 'canvas',
  16. do(data) {
  17. getSelectedShapes(data).forEach((shape) => {
  18. if (shape.isLocked) return
  19. getShapeUtils(shape).onBoundsReset(shape)
  20. })
  21. updateParents(data, Object.keys(initialShapes))
  22. },
  23. undo(data) {
  24. const page = getPage(data)
  25. getSelectedShapes(data).forEach((shape) => {
  26. if (shape.isLocked) return
  27. page.shapes[shape.id] = initialShapes[shape.id]
  28. })
  29. updateParents(data, Object.keys(initialShapes))
  30. },
  31. })
  32. )
  33. }