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.

align.ts 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import Command from "./command"
  2. import history from "../history"
  3. import { AlignType, Data } from "types"
  4. import { getPage } from "utils/utils"
  5. import { getShapeUtils } from "lib/shape-utils"
  6. export default function alignCommand(data: Data, type: AlignType) {
  7. const { currentPageId } = data
  8. const initialPoints = Object.fromEntries(
  9. Object.entries(getPage(data).shapes).map(([id, shape]) => [
  10. id,
  11. [...shape.point],
  12. ])
  13. )
  14. history.execute(
  15. data,
  16. new Command({
  17. name: "aligned",
  18. category: "canvas",
  19. do(data) {
  20. const { shapes } = getPage(data, currentPageId)
  21. switch (type) {
  22. case AlignType.Top: {
  23. break
  24. }
  25. case AlignType.CenterVertical: {
  26. break
  27. }
  28. case AlignType.Bottom: {
  29. break
  30. }
  31. case AlignType.Left: {
  32. break
  33. }
  34. case AlignType.CenterHorizontal: {
  35. break
  36. }
  37. case AlignType.Right: {
  38. break
  39. }
  40. }
  41. },
  42. undo(data) {
  43. const { shapes } = getPage(data, currentPageId)
  44. for (let id in initialPoints) {
  45. const shape = shapes[id]
  46. getShapeUtils(shape).translateTo(shape, initialPoints[id])
  47. }
  48. },
  49. })
  50. )
  51. }