您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

toggle.command.ts 889B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import type { TLDrawShape, Data, TLDrawCommand } from '~types'
  2. import { TLDR } from '~state/tldr'
  3. export function toggle(data: Data, ids: string[], prop: keyof TLDrawShape): TLDrawCommand {
  4. const { currentPageId } = data.appState
  5. const initialShapes = ids.map((id) => TLDR.getShape(data, id, currentPageId))
  6. const isAllToggled = initialShapes.every((shape) => shape[prop])
  7. const { before, after } = TLDR.mutateShapes(
  8. data,
  9. TLDR.getSelectedIds(data, currentPageId),
  10. () => ({
  11. [prop]: !isAllToggled,
  12. }),
  13. currentPageId
  14. )
  15. return {
  16. id: 'toggle_shapes',
  17. before: {
  18. document: {
  19. pages: {
  20. [currentPageId]: {
  21. shapes: before,
  22. },
  23. },
  24. },
  25. },
  26. after: {
  27. document: {
  28. pages: {
  29. [currentPageId]: {
  30. shapes: after,
  31. },
  32. },
  33. },
  34. },
  35. }
  36. }