11import React from 'react' ;
2- import * as uuid from 'uuid ' ;
2+ import classNames from 'classnames ' ;
33import DecoratedDrawingPath from './DecoratedDrawingPath' ;
44import DrawingList from './DrawingList' ;
55import DrawingCreator from './DrawingCreator' ;
66import DrawingPathGroup from './DrawingPathGroup' ;
77import DrawingSVG , { DrawingSVGRef } from './DrawingSVG' ;
8+ import DrawingSVGGroup from './DrawingSVGGroup' ;
9+ import PopupDrawingToolbar from '../components/Popups/PopupDrawingToolbar' ;
810import { AnnotationDrawing , PathGroup } from '../@types' ;
9- import { CreatorStatus } from '../store' ;
11+ import { CreatorItemDrawing , CreatorStatus } from '../store' ;
1012import './DrawingAnnotations.scss' ;
1113
1214export type Props = {
1315 activeAnnotationId : string | null ;
1416 addDrawingPathGroup : ( pathGroup : PathGroup ) => void ;
1517 annotations : AnnotationDrawing [ ] ;
18+ canShowPopupToolbar : boolean ;
1619 drawnPathGroups : Array < PathGroup > ;
1720 isCreating : boolean ;
1821 location : number ;
22+ resetDrawing : ( ) => void ;
1923 setActiveAnnotationId : ( annotationId : string | null ) => void ;
20- setDrawingLocation : ( location : number ) => void ;
24+ setReferenceId : ( uuid : string ) => void ;
25+ setStaged : ( staged : CreatorItemDrawing | null ) => void ;
2126 setStatus : ( status : CreatorStatus ) => void ;
27+ setupDrawing : ( location : number ) => void ;
2228} ;
2329
2430const DrawingAnnotations = ( props : Props ) : JSX . Element => {
2531 const {
2632 activeAnnotationId,
2733 addDrawingPathGroup,
2834 annotations,
35+ canShowPopupToolbar,
2936 drawnPathGroups,
3037 isCreating,
3138 location,
39+ resetDrawing,
3240 setActiveAnnotationId,
33- setDrawingLocation,
41+ setReferenceId,
42+ setStaged,
3443 setStatus,
44+ setupDrawing,
3545 } = props ;
46+ const [ isDrawing , setIsDrawing ] = React . useState < boolean > ( false ) ;
3647 const [ stagedRootEl , setStagedRootEl ] = React . useState < DrawingSVGRef | null > ( null ) ;
3748 const hasDrawnPathGroups = drawnPathGroups . length > 0 ;
38- const uuidRef = React . useRef < string > ( uuid . v4 ( ) ) ;
49+ const stagedGroupRef = React . useRef < SVGGElement > ( null ) ;
50+ const { current : drawingSVGGroup } = stagedGroupRef ;
3951
4052 const handleAnnotationActive = ( annotationId : string | null ) : void => {
4153 setActiveAnnotationId ( annotationId ) ;
4254 } ;
55+ const handleDelete = ( ) : void => {
56+ resetDrawing ( ) ;
57+ } ;
58+ const handleDrawingMount = ( uuid : string ) : void => {
59+ setReferenceId ( uuid ) ;
60+ } ;
61+ const handleReply = ( ) : void => {
62+ setStaged ( { location, pathGroups : drawnPathGroups } ) ;
63+ setStatus ( CreatorStatus . staged ) ;
64+ } ;
4365 const handleStart = ( ) : void => {
66+ setupDrawing ( location ) ;
4467 setStatus ( CreatorStatus . started ) ;
45- setDrawingLocation ( location ) ;
68+ setIsDrawing ( true ) ;
4669 } ;
4770 const handleStop = ( pathGroup : PathGroup ) : void => {
4871 addDrawingPathGroup ( pathGroup ) ;
72+ setIsDrawing ( false ) ;
4973 } ;
5074
5175 return (
@@ -60,7 +84,7 @@ const DrawingAnnotations = (props: Props): JSX.Element => {
6084 { hasDrawnPathGroups && (
6185 < DrawingSVG ref = { setStagedRootEl } className = "ba-DrawingAnnotations-target" >
6286 { /* Group element to capture the bounding box around the drawn path groups */ }
63- < g data-ba-reference-id = { uuidRef . current } >
87+ < DrawingSVGGroup ref = { stagedGroupRef } onMount = { handleDrawingMount } >
6488 { drawnPathGroups . map ( ( { clientId : pathGroupClientId , paths, stroke } ) => (
6589 < DrawingPathGroup key = { pathGroupClientId } rootEl = { stagedRootEl } stroke = { stroke } >
6690 { /* Use the children render function to pass down the calculated strokeWidthWithBorder value */ }
@@ -76,13 +100,22 @@ const DrawingAnnotations = (props: Props): JSX.Element => {
76100 }
77101 </ DrawingPathGroup >
78102 ) ) }
79- </ g >
103+ </ DrawingSVGGroup >
80104 </ DrawingSVG >
81105 ) }
82106
83107 { isCreating && (
84108 < DrawingCreator className = "ba-DrawingAnnotations-creator" onStart = { handleStart } onStop = { handleStop } />
85109 ) }
110+
111+ { isCreating && hasDrawnPathGroups && drawingSVGGroup && canShowPopupToolbar && (
112+ < PopupDrawingToolbar
113+ className = { classNames ( 'ba-DrawingAnnotations-toolbar' , { 'ba-is-drawing' : isDrawing } ) }
114+ onDelete = { handleDelete }
115+ onReply = { handleReply }
116+ reference = { drawingSVGGroup }
117+ />
118+ ) }
86119 </ >
87120 ) ;
88121} ;
0 commit comments