tldraw/state/commands/create-shape.ts
2021-05-19 10:35:00 +01:00

32 lines
777 B
TypeScript

import Command from "./command"
import history from "../history"
import { Data, Shape } from "types"
export default function createShapeCommand(data: Data, shape: Shape) {
const { currentPageId } = data
history.execute(
data,
new Command({
name: "translate_shapes",
category: "canvas",
do(data) {
const { shapes } = data.document.pages[currentPageId]
shapes[shape.id] = shape
data.selectedIds.clear()
data.pointedId = undefined
data.hoveredId = undefined
},
undo(data) {
const { shapes } = data.document.pages[currentPageId]
delete shapes[shape.id]
data.selectedIds.clear()
data.pointedId = undefined
data.hoveredId = undefined
},
})
)
}