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.

selected.tsx 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import styled from 'styles'
  2. import { useSelector } from 'state'
  3. import {
  4. deepCompareArrays,
  5. getPage,
  6. getSelectedIds,
  7. setToArray,
  8. } from 'utils/utils'
  9. import { getShapeUtils } from 'state/shape-utils'
  10. import { memo } from 'react'
  11. export default function Selected(): JSX.Element {
  12. const currentSelectedShapeIds = useSelector(
  13. ({ data }) => setToArray(getSelectedIds(data)),
  14. deepCompareArrays
  15. )
  16. const isSelecting = useSelector((s) => s.isIn('selecting'))
  17. if (!isSelecting) return null
  18. return (
  19. <g>
  20. {currentSelectedShapeIds.map((id) => (
  21. <ShapeOutline key={id} id={id} />
  22. ))}
  23. </g>
  24. )
  25. }
  26. export const ShapeOutline = memo(function ShapeOutline({ id }: { id: string }) {
  27. // const rIndicator = useRef<SVGUseElement>(null)
  28. const shape = useSelector((s) => getPage(s.data).shapes[id])
  29. // const events = useShapeEvents(id, shape?.type === ShapeType.Group, rIndicator)
  30. if (!shape) return null
  31. // This needs computation from state, similar to bounds, in order
  32. // to handle parent rotation.
  33. const center = getShapeUtils(shape).getCenter(shape)
  34. const transform = `
  35. rotate(${shape.rotation * (180 / Math.PI)}, ${center})
  36. translate(${shape.point})
  37. `
  38. return (
  39. <SelectIndicator
  40. // ref={rIndicator}
  41. as="use"
  42. href={'#' + id}
  43. transform={transform}
  44. isLocked={shape.isLocked}
  45. // {...events}
  46. />
  47. )
  48. })
  49. const SelectIndicator = styled('path', {
  50. // zStrokeWidth: 2,
  51. strokeLineCap: 'round',
  52. strokeLinejoin: 'round',
  53. stroke: 'red',
  54. strokeWidth: '10',
  55. pointerEvents: 'none',
  56. fill: 'red',
  57. variants: {
  58. isLocked: {
  59. true: {
  60. zDash: 2,
  61. },
  62. false: {},
  63. },
  64. variant: {},
  65. },
  66. })