2022-05-30 14:38:52 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { ComponentType, useEffect, useState } from 'react';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { EditorBlock } from './types';
|
|
|
|
|
|
|
|
interface EditingImageRequiredProps {
|
|
|
|
isSelected: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
type EditingImageProps< T extends EditorBlock< T > > = T &
|
|
|
|
EditingImageRequiredProps;
|
|
|
|
|
2022-06-15 09:56:52 +00:00
|
|
|
export const withEditingImage =
|
|
|
|
< T extends EditorBlock< T > >( Component: ComponentType< T > ) =>
|
|
|
|
( props: EditingImageProps< T > ) => {
|
|
|
|
const [ isEditingImage, setIsEditingImage ] = useState( false );
|
|
|
|
const { isSelected } = props;
|
2022-05-30 14:38:52 +00:00
|
|
|
|
2022-06-15 09:56:52 +00:00
|
|
|
useEffect( () => {
|
|
|
|
setIsEditingImage( false );
|
|
|
|
}, [ isSelected ] );
|
2022-05-30 14:38:52 +00:00
|
|
|
|
2022-06-15 09:56:52 +00:00
|
|
|
return (
|
|
|
|
<Component
|
|
|
|
{ ...props }
|
|
|
|
useEditingImage={ [ isEditingImage, setIsEditingImage ] }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|