File tree Expand file tree Collapse file tree 3 files changed +16
-2
lines changed
Expand file tree Collapse file tree 3 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ export type ToolbarImagePopuProps = Omit<ToolbarBaseProps<never>, 'editor'> & {
1919 onSuccessUpload ?: ( res : BatchUploadResult ) => void ;
2020 hide : ( ) => void ;
2121 anchorElement : HTMLElement | null ;
22- } & Pick < ImageFormProps , 'onSubmit' > ;
22+ } & Pick < ImageFormProps , 'onSubmit' | 'imageTitle' > ;
2323
2424export const ToolbarImagePopup : React . FC < ToolbarImagePopuProps > = ( {
2525 className,
@@ -30,6 +30,7 @@ export const ToolbarImagePopup: React.FC<ToolbarImagePopuProps> = ({
3030 onClick,
3131 uploadImages,
3232 onSuccessUpload,
33+ imageTitle,
3334} ) => {
3435 const toaster = useToaster ( ) ;
3536 const [ loading , showLoading , hideLoading ] = useBooleanState ( false ) ;
@@ -79,6 +80,7 @@ export const ToolbarImagePopup: React.FC<ToolbarImagePopuProps> = ({
7980 onClick ?.( 'addImage' ) ;
8081 } }
8182 loading = { loading }
83+ imageTitle = { imageTitle }
8284 />
8385 </ Popup >
8486 ) ;
Original file line number Diff line number Diff line change 1+ import { useMemo } from 'react' ;
2+
13import isNumber from 'is-number' ;
24
35import { IMG_MAX_HEIGHT , type ImageItem , getImageDimensions , insertImages } from '../../../markup' ;
@@ -26,8 +28,16 @@ export const MToolbarImagePopup: React.FC<MToolbarImagePopupProps> = ({
2628} ) => {
2729 const { uploadHandler, needToSetDimensionsForUploadedImages} = useMarkupToolbarContext ( ) ;
2830
31+ const selectedString = useMemo ( ( ) => {
32+ const { from, to} = editor . cm . state . selection . main ;
33+ return editor . cm . state . doc . sliceString ( from , to ) ;
34+ // we need to calculate the selection only once
35+ // eslint-disable-next-line react-hooks/exhaustive-deps
36+ } , [ ] ) ;
37+
2938 return (
3039 < ToolbarImagePopup
40+ imageTitle = { selectedString }
3141 hide = { hide }
3242 anchorElement = { anchorElement }
3343 focus = { focus }
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ export type ImageFormProps = ClassNameProps & {
3535 onCancel ( ) : void ;
3636 onAttach ?: ( files : File [ ] ) => void ;
3737 loading ?: boolean ;
38+ imageTitle ?: string ;
3839} ;
3940
4041export const ImageForm : React . FC < ImageFormProps > = ( {
@@ -44,12 +45,13 @@ export const ImageForm: React.FC<ImageFormProps> = ({
4445 onSubmit,
4546 onAttach,
4647 loading,
48+ imageTitle : providedName ,
4749} ) => {
4850 const [ tabId , setTabId ] = useState < string > ( ( ) =>
4951 isFunction ( onAttach ) ? ImageTabId . Attach : ImageTabId . Link ,
5052 ) ;
5153 const [ url , setUrl ] = useState ( '' ) ;
52- const [ name , setName ] = useState ( '' ) ;
54+ const [ name , setName ] = useState ( providedName ?? '' ) ;
5355 const [ alt , setAlt ] = useState ( '' ) ;
5456 const [ width , setWidth ] = useState < number | undefined > ( ) ;
5557 const [ height , setHeight ] = useState < number | undefined > ( ) ;
You can’t perform that action at this time.
0 commit comments