@@ -14,27 +14,27 @@ import {
14
14
useRuleOfThirds ,
15
15
useCircularCrop ,
16
16
useDisabled ,
17
- useResponsiveAppScaling ,
18
17
useCropToBase64 ,
19
18
useKeepSelection ,
20
19
useRotation ,
21
20
useScaling ,
22
- useImageLoaded
21
+ useImageLoaded ,
22
+ useDefaultCrop
23
23
} from "../hooks" ;
24
- import { getDefaultCrop , useDefaultCrop } from "../hooks/useDefaultCrop" ;
25
24
import CropWrapper from "./imageCropWrapper" ;
26
25
27
26
const ImageCropControl : React . FC < IImageCropControlProps > = ( props ) => {
27
+ // Get the PCF context using the custom hook
28
28
const pcfContext = usePcfContext ( ) ;
29
+ // State to hold the completed crop object, initialized as undefined
29
30
const [ completedCrop , setCompletedCrop ] = React . useState < PixelCrop > ( )
31
+ // Crop state for the image, initialized as undefined
30
32
const [ crop , setCrop ] = React . useState < Crop > ( ) ;
31
-
32
33
// Image loaded state (modular)
33
34
const [ imageLoaded , handleImageLoad , handleImageError , handleImageSrcChange ] = useImageLoaded ( ) ;
34
-
35
+ // Reference to the image element for scaling and cropping
35
36
const imgRef = React . useRef < HTMLImageElement > ( null ) as React . RefObject < HTMLImageElement > ;
36
- const appScaling = useResponsiveAppScaling ( pcfContext . context , imgRef ) ;
37
-
37
+ //const appScaling = useResponsiveAppScaling(pcfContext.context, imgRef);
38
38
// Get the locked property from PCF context
39
39
const locked = useLocked ( pcfContext . context ) ;
40
40
// Get the disabled property from PCF context
@@ -49,7 +49,7 @@ const ImageCropControl: React.FC<IImageCropControlProps> = (props) => {
49
49
const minHeight = useMinHeight ( pcfContext . context ) ;
50
50
const maxHeight = useMaxHeight ( pcfContext . context ) ;
51
51
// Get the aspect ratio from PCF context and helper to center crop
52
- const [ aspect , centerCropIfNeeded ] = useAspect ( pcfContext . context , imgRef , setCrop ) ;
52
+ const [ aspect ] = useAspect ( pcfContext . context , imgRef , setCrop ) ;
53
53
// Get the keepSelection property from PCF context
54
54
const keepSelection = useKeepSelection ( pcfContext . context ) ;
55
55
// Get the image from the PCF context property (should be base64)
@@ -58,9 +58,10 @@ const ImageCropControl: React.FC<IImageCropControlProps> = (props) => {
58
58
const rotation = useRotation ( pcfContext . context ) ;
59
59
// Get the scaling property from PCF context
60
60
const scaling = useScaling ( pcfContext . context ) ;
61
-
62
61
// Get the default crop object (not a hook)
63
62
const defaultCrop = useDefaultCrop ( pcfContext . context ) ;
63
+ // Use custom hook to handle crop-to-base64 conversion and callback
64
+ useCropToBase64 ( imgRef , completedCrop , props . onCropComplete , rotation , scaling , circularCrop ) ;
64
65
65
66
// Reset imageLoaded state and crop when imageSrc changes
66
67
React . useEffect ( ( ) => {
@@ -76,11 +77,8 @@ const ImageCropControl: React.FC<IImageCropControlProps> = (props) => {
76
77
}
77
78
} , [ imageLoaded ] ) ;
78
79
79
- // Use custom hook to handle crop-to-base64 conversion and callback
80
- useCropToBase64 ( imgRef , completedCrop , props . onCropComplete , rotation , scaling , circularCrop ) ;
81
-
82
80
return (
83
- < CropWrapper
81
+ < CropWrapper
84
82
crop = { crop }
85
83
onChange = { ( c : Crop ) => setCrop ( c ) }
86
84
onDragStart = { ( e : PointerEvent ) => props . onDragStart ( e ) }
@@ -96,7 +94,7 @@ const ImageCropControl: React.FC<IImageCropControlProps> = (props) => {
96
94
maxHeight = { maxHeight }
97
95
aspect = { aspect }
98
96
keepSelection = { keepSelection }
99
- style = { { display : imageSrc && pcfContext . isVisible ( ) ? 'block' : 'none' , } }
97
+ style = { { display : imageSrc && pcfContext . isVisible ( ) ? 'block' : 'none' , } }
100
98
>
101
99
< img
102
100
ref = { imgRef }
@@ -106,9 +104,9 @@ const ImageCropControl: React.FC<IImageCropControlProps> = (props) => {
106
104
onError = { handleImageError }
107
105
style = { {
108
106
maxWidth : '100%' ,
109
- maxHeight : '100%' ,
107
+ maxHeight : '100%' ,
110
108
transform : `rotate(${ rotation } deg) scale(${ scaling } )`
111
- } }
109
+ } }
112
110
/>
113
111
</ CropWrapper >
114
112
) ;
0 commit comments