2021-05-13 06:44:52 +00:00
|
|
|
import Command from "./command"
|
2021-05-13 08:34:56 +00:00
|
|
|
import history from "../history"
|
2021-05-13 06:44:52 +00:00
|
|
|
import { TranslateSnapshot } from "state/sessions/translate-session"
|
|
|
|
import { Data } from "types"
|
|
|
|
|
|
|
|
export default function translateCommand(
|
|
|
|
data: Data,
|
|
|
|
before: TranslateSnapshot,
|
2021-05-19 21:24:41 +00:00
|
|
|
after: TranslateSnapshot,
|
|
|
|
isCloning: boolean
|
2021-05-13 06:44:52 +00:00
|
|
|
) {
|
|
|
|
history.execute(
|
|
|
|
data,
|
|
|
|
new Command({
|
2021-05-19 21:24:41 +00:00
|
|
|
name: isCloning ? "clone_shapes" : "translate_shapes",
|
2021-05-13 06:44:52 +00:00
|
|
|
category: "canvas",
|
2021-05-19 21:24:41 +00:00
|
|
|
manualSelection: true,
|
|
|
|
do(data, initial) {
|
|
|
|
if (initial) return
|
|
|
|
|
2021-05-13 06:44:52 +00:00
|
|
|
const { shapes } = data.document.pages[after.currentPageId]
|
2021-05-20 08:19:13 +00:00
|
|
|
const { initialShapes } = after
|
|
|
|
const { clones } = before // !
|
2021-05-19 21:24:41 +00:00
|
|
|
|
|
|
|
data.selectedIds.clear()
|
2021-05-13 06:44:52 +00:00
|
|
|
|
2021-05-20 09:25:14 +00:00
|
|
|
if (isCloning) {
|
|
|
|
for (const clone of clones) {
|
|
|
|
shapes[clone.id] = clone
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const { id, point } of initialShapes) {
|
|
|
|
shapes[id].point = point
|
2021-05-19 21:24:41 +00:00
|
|
|
data.selectedIds.add(id)
|
2021-05-13 06:44:52 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
undo(data) {
|
|
|
|
const { shapes } = data.document.pages[before.currentPageId]
|
2021-05-19 21:24:41 +00:00
|
|
|
const { initialShapes, clones } = before
|
|
|
|
|
|
|
|
data.selectedIds.clear()
|
|
|
|
|
2021-05-20 09:25:14 +00:00
|
|
|
if (isCloning) {
|
|
|
|
for (const { id } of clones) {
|
|
|
|
delete shapes[id]
|
2021-05-19 21:24:41 +00:00
|
|
|
}
|
2021-05-13 06:44:52 +00:00
|
|
|
}
|
2021-05-20 09:25:14 +00:00
|
|
|
|
|
|
|
for (const { id, point } of initialShapes) {
|
|
|
|
shapes[id].point = point
|
|
|
|
data.selectedIds.add(id)
|
|
|
|
}
|
2021-05-13 06:44:52 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|