| 12345678910111213141516171819202122232425262728293031323334353637 |
- import Command from './command'
- import history from '../history'
- import { DirectionSnapshot } from 'state/sessions/direction-session'
- import { Data, LineShape, RayShape } from 'types'
- import { getPage } from 'utils/utils'
-
- export default function directCommand(
- data: Data,
- before: DirectionSnapshot,
- after: DirectionSnapshot
- ): void {
- history.execute(
- data,
- new Command({
- name: 'set_direction',
- category: 'canvas',
- do(data) {
- const { shapes } = getPage(data)
-
- for (const { id, direction } of after.shapes) {
- const shape = shapes[id] as RayShape | LineShape
-
- shape.direction = direction
- }
- },
- undo(data) {
- const { shapes } = getPage(data, before.currentPageId)
-
- for (const { id, direction } of after.shapes) {
- const shape = shapes[id] as RayShape | LineShape
-
- shape.direction = direction
- }
- },
- })
- )
- }
|