Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

mutate.ts 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import Command from './command'
  2. import history from '../history'
  3. import { Data, Shape } from 'types'
  4. import { getShapeUtils } from 'state/shape-utils'
  5. import { getPage, updateParents } from 'utils/utils'
  6. // Used when changing the properties of one or more shapes,
  7. // without changing selection or deleting any shapes.
  8. export default function mutateShapesCommand(
  9. data: Data,
  10. before: Shape[],
  11. after: Shape[],
  12. name = 'mutate_shapes'
  13. ): void {
  14. history.execute(
  15. data,
  16. new Command({
  17. name,
  18. category: 'canvas',
  19. do(data) {
  20. const { shapes } = getPage(data)
  21. after.forEach((shape) => {
  22. shapes[shape.id] = shape
  23. getShapeUtils(shape).onSessionComplete(shape)
  24. })
  25. // updateParents(
  26. // data,
  27. // after.map((shape) => shape.id)
  28. // )
  29. },
  30. undo(data) {
  31. const { shapes } = getPage(data)
  32. before.forEach((shape) => {
  33. shapes[shape.id] = shape
  34. getShapeUtils(shape).onSessionComplete(shape)
  35. })
  36. updateParents(
  37. data,
  38. before.map((shape) => shape.id)
  39. )
  40. },
  41. })
  42. )
  43. }