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

arrow.ts 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import Command from './command'
  2. import history from '../history'
  3. import { Data } from 'types'
  4. import { getPage, getSelectedIds } from 'utils/utils'
  5. import { ArrowSnapshot } from 'state/sessions/arrow-session'
  6. export default function arrowCommand(
  7. data: Data,
  8. before: ArrowSnapshot,
  9. after: ArrowSnapshot
  10. ): void {
  11. history.execute(
  12. data,
  13. new Command({
  14. name: 'point_arrow',
  15. category: 'canvas',
  16. manualSelection: true,
  17. do(data, isInitial) {
  18. if (isInitial) return
  19. const { initialShape, currentPageId } = after
  20. const page = getPage(data, currentPageId)
  21. page.shapes[initialShape.id] = initialShape
  22. const selectedIds = getSelectedIds(data)
  23. selectedIds.clear()
  24. selectedIds.add(initialShape.id)
  25. data.hoveredId = undefined
  26. data.pointedId = undefined
  27. },
  28. undo(data) {
  29. const { initialShape, currentPageId } = before
  30. const shapes = getPage(data, currentPageId).shapes
  31. delete shapes[initialShape.id]
  32. const selectedIds = getSelectedIds(data)
  33. selectedIds.clear()
  34. data.hoveredId = undefined
  35. data.pointedId = undefined
  36. },
  37. })
  38. )
  39. }