1- import { Transformation , Util } from ' cloudinary-core' ;
2-
3- const CLOUDINARY_REACT_PROPS = { includeOwnBody : true } ;
1+ import { Transformation , Util } from " cloudinary-core" ;
2+ // props passed to cloudinary-core but should not be rendered as dom attributes
3+ const CLOUDINARY_REACT_PROPS = [ 'accessibility' , 'breakpoints' , 'dataSrc' , 'placeholder' , 'publicId' , 'signature' ] ;
44
5+ // props passed to cloudinary-core for dom elements attributes generation
56// Map Cloudinary props from array to object for efficient lookup
6- const CLOUDINARY_PROPS = Transformation . PARAM_NAMES . map ( Util . camelCase ) . concat ( [ 'publicId' , 'breakpoints' ] ) . reduce (
7+ const CLOUDINARY_PROPS = [ ... Transformation . PARAM_NAMES , ... CLOUDINARY_REACT_PROPS ] . map ( Util . camelCase ) . reduce (
78 ( accumulator , cloudinaryPropName ) => {
89 accumulator [ cloudinaryPropName ] = true ;
910 return accumulator ;
1011 } ,
1112 { }
1213) ;
1314
14- const isDefined = ( props , key ) => {
15- return ( props [ key ] !== undefined && props [ key ] !== null ) ;
16- } ;
17-
1815/**
1916 * Extracts cloudinaryProps and nonCloudinaryProps from given props
2017 *
2118 * @param props
2219 * @returns {{children: *, cloudinaryReactProps: {}, cloudinaryProps: {}, nonCloudinaryProps: {}} }
2320 */
24- export default ( { children, ...props } ) => {
21+ const extractCloudinaryProps = ( { children, ...props } ) => {
2522 let result = {
2623 children,
2724 cloudinaryProps : { } ,
@@ -35,10 +32,10 @@ export default ({children, ...props}) => {
3532
3633 //if valid and defined add to cloudinaryProps
3734 if ( CLOUDINARY_PROPS [ camelKey ] ) {
38- if ( isDefined ( props , key ) ) {
35+ if ( props [ key ] !== undefined && props [ key ] !== null ) {
3936 result . cloudinaryProps [ camelKey ] = value ;
4037 }
41- } else if ( CLOUDINARY_REACT_PROPS [ camelKey ] ) { //cloudinary-react spesific prop
38+ } else if ( camelKey === 'includeOwnBody' ) { //cloudinary-react specific prop
4239 result . cloudinaryReactProps [ camelKey ] = value ;
4340 } else { //not valid so add to nonCloudinaryProps
4441 result . nonCloudinaryProps [ key ] = value ;
@@ -47,3 +44,8 @@ export default ({children, ...props}) => {
4744
4845 return result ;
4946} ;
47+
48+ export {
49+ CLOUDINARY_REACT_PROPS ,
50+ extractCloudinaryProps
51+ } ;
0 commit comments