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.

generate.ts 977B

1234567891011121314151617181920212223242526272829303132333435
  1. import Command from './command'
  2. import history from '../history'
  3. import { Data, Shape } from 'types'
  4. import { deepClone } from 'utils'
  5. import tld from 'utils/tld'
  6. export default function generateCommand(
  7. data: Data,
  8. generatedShapes: Shape[]
  9. ): void {
  10. const initialShapes = tld
  11. .getShapes(data)
  12. .filter((shape) => shape.isGenerated)
  13. .map(deepClone)
  14. history.execute(
  15. data,
  16. new Command({
  17. name: 'generate_shapes',
  18. category: 'canvas',
  19. do(data) {
  20. const { shapes } = tld.getPage(data)
  21. initialShapes.forEach((shape) => delete shapes[shape.id])
  22. generatedShapes.forEach((shape) => (shapes[shape.id] = shape))
  23. tld.setSelectedIds(data, [])
  24. },
  25. undo(data) {
  26. const { shapes } = tld.getPage(data)
  27. generatedShapes.forEach((shape) => delete shapes[shape.id])
  28. initialShapes.forEach((shape) => (shapes[shape.id] = shape))
  29. tld.setSelectedIds(data, [])
  30. },
  31. })
  32. )
  33. }