Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

toggle.ts 1.2KB

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