Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

selected.tsx 1.8KB

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