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.

translate.ts 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import Command from "./command"
  2. import history from "../history"
  3. import { TranslateSnapshot } from "state/sessions/translate-session"
  4. import { Data } from "types"
  5. import { getPage } from "utils/utils"
  6. import { getShapeUtils } from "lib/shape-utils"
  7. export default function translateCommand(
  8. data: Data,
  9. before: TranslateSnapshot,
  10. after: TranslateSnapshot,
  11. isCloning: boolean
  12. ) {
  13. history.execute(
  14. data,
  15. new Command({
  16. name: isCloning ? "clone_shapes" : "translate_shapes",
  17. category: "canvas",
  18. manualSelection: true,
  19. do(data, initial) {
  20. if (initial) return
  21. const { initialShapes, currentPageId } = after
  22. const { shapes } = getPage(data, currentPageId)
  23. const { clones } = before // !
  24. data.selectedIds.clear()
  25. if (isCloning) {
  26. for (const clone of clones) {
  27. shapes[clone.id] = clone
  28. }
  29. }
  30. for (const { id, point } of initialShapes) {
  31. const shape = shapes[id]
  32. getShapeUtils(shape).translateTo(shape, point)
  33. data.selectedIds.add(id)
  34. }
  35. },
  36. undo(data) {
  37. const { initialShapes, clones, currentPageId } = before
  38. const { shapes } = getPage(data, currentPageId)
  39. data.selectedIds.clear()
  40. if (isCloning) {
  41. for (const { id } of clones) {
  42. delete shapes[id]
  43. }
  44. }
  45. for (const { id, point } of initialShapes) {
  46. const shape = shapes[id]
  47. getShapeUtils(shape).translateTo(shape, point)
  48. data.selectedIds.add(id)
  49. }
  50. },
  51. })
  52. )
  53. }