Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import Command from './command'
  2. import history from '../history'
  3. import { Data, Shape } from 'types'
  4. import { getPage, getSelectedShapes } from 'utils'
  5. import { getShapeUtils } from 'state/shape-utils'
  6. import { PropsOfType } from 'types'
  7. export default function toggleCommand(
  8. data: Data,
  9. prop: PropsOfType<Shape>
  10. ): void {
  11. const selectedShapes = getSelectedShapes(data)
  12. const isAllToggled = selectedShapes.every((shape) => shape[prop])
  13. const initialShapes = Object.fromEntries(
  14. selectedShapes.map((shape) => [shape.id, shape[prop]])
  15. )
  16. history.execute(
  17. data,
  18. new Command({
  19. name: 'toggle_prop',
  20. category: 'canvas',
  21. do(data) {
  22. const { shapes } = getPage(data)
  23. for (const id in initialShapes) {
  24. const shape = shapes[id]
  25. getShapeUtils(shape).setProperty(
  26. shape,
  27. prop,
  28. isAllToggled ? false : true
  29. )
  30. }
  31. },
  32. undo(data) {
  33. const { shapes } = getPage(data)
  34. for (const id in initialShapes) {
  35. const shape = shapes[id]
  36. getShapeUtils(shape).setProperty(shape, prop, initialShapes[id])
  37. }
  38. },
  39. })
  40. )
  41. }