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 854B

1234567891011121314151617181920212223242526272829303132333435
  1. import Command from './command'
  2. import history from '../history'
  3. import { Data, DrawShape } 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. points: number[][]
  11. ) {
  12. const restoreShape = current(getPage(data)).shapes[id] as DrawShape
  13. getShapeUtils(restoreShape).setProperty(restoreShape, 'points', points)
  14. history.execute(
  15. data,
  16. new Command({
  17. name: 'set_points',
  18. category: 'canvas',
  19. manualSelection: true,
  20. do(data, initial) {
  21. if (!initial) {
  22. getPage(data).shapes[id] = restoreShape
  23. }
  24. data.selectedIds.clear()
  25. },
  26. undo(data) {
  27. delete getPage(data).shapes[id]
  28. data.selectedIds.clear()
  29. },
  30. })
  31. )
  32. }