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.

style.ts 1.0KB

123456789101112131415161718192021222324252627282930313233343536
  1. import Command from "./command"
  2. import history from "../history"
  3. import { Data, ShapeStyles } from "types"
  4. import { getPage, getSelectedShapes } from "utils/utils"
  5. import { getShapeUtils } from "lib/shape-utils"
  6. import { current } from "immer"
  7. export default function styleCommand(data: Data, styles: ShapeStyles) {
  8. const { currentPageId } = data
  9. const initialShapes = getSelectedShapes(current(data))
  10. history.execute(
  11. data,
  12. new Command({
  13. name: "changed_style",
  14. category: "canvas",
  15. manualSelection: true,
  16. do(data) {
  17. const { shapes } = getPage(data, currentPageId)
  18. for (const { id } of initialShapes) {
  19. const shape = shapes[id]
  20. getShapeUtils(shape).applyStyles(shape, styles)
  21. }
  22. },
  23. undo(data) {
  24. const { shapes } = getPage(data, currentPageId)
  25. for (const { id, style } of initialShapes) {
  26. const shape = shapes[id]
  27. getShapeUtils(shape).applyStyles(shape, style)
  28. }
  29. },
  30. })
  31. )
  32. }