您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

reset-bounds.ts 979B

1234567891011121314151617181920212223242526272829303132333435
  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 'lib/shape-utils'
  7. export default function resetBoundsCommand(data: Data) {
  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. getShapeUtils(shape).onBoundsReset(shape)
  19. })
  20. updateParents(data, Object.keys(initialShapes))
  21. },
  22. undo(data) {
  23. const page = getPage(data)
  24. getSelectedShapes(data).forEach((shape) => {
  25. page.shapes[shape.id] = initialShapes[shape.id]
  26. })
  27. updateParents(data, Object.keys(initialShapes))
  28. },
  29. })
  30. )
  31. }