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.

draw.ts 982B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import Command from "./command"
  2. import history from "../history"
  3. import { Data } from "types"
  4. import { getPage } from "utils/utils"
  5. import { getShapeUtils } from "lib/shape-utils"
  6. import { current } from "immer"
  7. export default function drawCommand(
  8. data: Data,
  9. id: string,
  10. before: number[][],
  11. after: number[][]
  12. ) {
  13. const selectedIds = Array.from(data.selectedIds.values())
  14. const restoreShape = current(getPage(data).shapes[id])
  15. getShapeUtils(restoreShape).setPoints!(restoreShape, after)
  16. history.execute(
  17. data,
  18. new Command({
  19. name: "set_points",
  20. category: "canvas",
  21. manualSelection: true,
  22. do(data, initial) {
  23. if (!initial) {
  24. getPage(data).shapes[id] = restoreShape
  25. }
  26. data.selectedIds.clear()
  27. },
  28. undo(data) {
  29. delete getPage(data).shapes[id]
  30. data.selectedIds.clear()
  31. for (let id of selectedIds) {
  32. data.selectedIds.add(id)
  33. }
  34. },
  35. })
  36. )
  37. }