Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import styled from 'styles'
  2. import { useSelector } from 'state'
  3. import { deepCompareArrays, getPage } from 'utils/utils'
  4. import { getShapeUtils } from 'lib/shape-utils'
  5. import useShapeEvents from 'hooks/useShapeEvents'
  6. import { useRef } from 'react'
  7. export default function Selected() {
  8. const currentPageShapeIds = useSelector(({ data }) => {
  9. return Array.from(data.selectedIds.values())
  10. }, deepCompareArrays)
  11. const isSelecting = useSelector((s) => s.isIn('selecting'))
  12. if (!isSelecting) return null
  13. return (
  14. <g>
  15. {currentPageShapeIds.map((id) => (
  16. <ShapeOutline key={id} id={id} />
  17. ))}
  18. </g>
  19. )
  20. }
  21. export function ShapeOutline({ id }: { id: string }) {
  22. const rIndicator = useRef<SVGUseElement>(null)
  23. const shape = useSelector(({ data }) => getPage(data).shapes[id])
  24. const events = useShapeEvents(id, rIndicator)
  25. if (!shape) return null
  26. const transform = `
  27. rotate(${shape.rotation * (180 / Math.PI)},
  28. ${getShapeUtils(shape).getCenter(shape)})
  29. translate(${shape.point})`
  30. return (
  31. <Indicator
  32. ref={rIndicator}
  33. as="use"
  34. href={'#' + id}
  35. transform={transform}
  36. {...events}
  37. />
  38. )
  39. }
  40. const Indicator = styled('path', {
  41. zStrokeWidth: 1,
  42. strokeLineCap: 'round',
  43. strokeLinejoin: 'round',
  44. stroke: '$selected',
  45. fill: 'transparent',
  46. pointerEvents: 'all',
  47. })