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

handle.ts 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import Command from './command'
  2. import history from '../history'
  3. import { Data } from 'types'
  4. import { getPage } from 'utils/utils'
  5. import { HandleSnapshot } from 'state/sessions/handle-session'
  6. import { getShapeUtils } from 'lib/shape-utils'
  7. import vec from 'utils/vec'
  8. export default function handleCommand(
  9. data: Data,
  10. before: HandleSnapshot,
  11. after: HandleSnapshot
  12. ) {
  13. history.execute(
  14. data,
  15. new Command({
  16. name: 'moved_handle',
  17. category: 'canvas',
  18. do(data, isInitial) {
  19. // if (isInitial) return
  20. const { initialShape, currentPageId } = after
  21. const page = getPage(data, currentPageId)
  22. const shape = page.shapes[initialShape.id]
  23. getShapeUtils(shape)
  24. .onHandleChange(shape, initialShape.handles)
  25. .onSessionComplete(shape)
  26. // const bounds = getShapeUtils(shape).getBounds(shape)
  27. // const offset = vec.sub([bounds.minX, bounds.minY], shape.point)
  28. // getShapeUtils(shape).translateTo(shape, vec.add(shape.point, offset))
  29. // const { start, end, bend } = page.shapes[initialShape.id].handles
  30. // start.point = vec.sub(start.point, offset)
  31. // end.point = vec.sub(end.point, offset)
  32. // bend.point = vec.sub(bend.point, offset)
  33. },
  34. undo(data) {
  35. const { initialShape, currentPageId } = before
  36. const page = getPage(data, currentPageId)
  37. page.shapes[initialShape.id] = initialShape
  38. },
  39. })
  40. )
  41. }