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'> & {
19
19
onSuccessUpload ?: ( res : BatchUploadResult ) => void ;
20
20
hide : ( ) => void ;
21
21
anchorElement : HTMLElement | null ;
22
- } & Pick < ImageFormProps , 'onSubmit' > ;
22
+ } & Pick < ImageFormProps , 'onSubmit' | 'imageTitle' > ;
23
23
24
24
export const ToolbarImagePopup : React . FC < ToolbarImagePopuProps > = ( {
25
25
className,
@@ -30,6 +30,7 @@ export const ToolbarImagePopup: React.FC<ToolbarImagePopuProps> = ({
30
30
onClick,
31
31
uploadImages,
32
32
onSuccessUpload,
33
+ imageTitle,
33
34
} ) => {
34
35
const toaster = useToaster ( ) ;
35
36
const [ loading , showLoading , hideLoading ] = useBooleanState ( false ) ;
@@ -79,6 +80,7 @@ export const ToolbarImagePopup: React.FC<ToolbarImagePopuProps> = ({
79
80
onClick ?.( 'addImage' ) ;
80
81
} }
81
82
loading = { loading }
83
+ imageTitle = { imageTitle }
82
84
/>
83
85
</ Popup >
84
86
) ;
Original file line number Diff line number Diff line change
1
+ import { useMemo } from 'react' ;
2
+
1
3
import isNumber from 'is-number' ;
2
4
3
5
import { IMG_MAX_HEIGHT , type ImageItem , getImageDimensions , insertImages } from '../../../markup' ;
@@ -26,8 +28,16 @@ export const MToolbarImagePopup: React.FC<MToolbarImagePopupProps> = ({
26
28
} ) => {
27
29
const { uploadHandler, needToSetDimensionsForUploadedImages} = useMarkupToolbarContext ( ) ;
28
30
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
+
29
38
return (
30
39
< ToolbarImagePopup
40
+ imageTitle = { selectedString }
31
41
hide = { hide }
32
42
anchorElement = { anchorElement }
33
43
focus = { focus }
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ export type ImageFormProps = ClassNameProps & {
35
35
onCancel ( ) : void ;
36
36
onAttach ?: ( files : File [ ] ) => void ;
37
37
loading ?: boolean ;
38
+ imageTitle ?: string ;
38
39
} ;
39
40
40
41
export const ImageForm : React . FC < ImageFormProps > = ( {
@@ -44,12 +45,13 @@ export const ImageForm: React.FC<ImageFormProps> = ({
44
45
onSubmit,
45
46
onAttach,
46
47
loading,
48
+ imageTitle : providedName ,
47
49
} ) => {
48
50
const [ tabId , setTabId ] = useState < string > ( ( ) =>
49
51
isFunction ( onAttach ) ? ImageTabId . Attach : ImageTabId . Link ,
50
52
) ;
51
53
const [ url , setUrl ] = useState ( '' ) ;
52
- const [ name , setName ] = useState ( '' ) ;
54
+ const [ name , setName ] = useState ( providedName ?? '' ) ;
53
55
const [ alt , setAlt ] = useState ( '' ) ;
54
56
const [ width , setWidth ] = useState < number | undefined > ( ) ;
55
57
const [ height , setHeight ] = useState < number | undefined > ( ) ;
You can’t perform that action at this time.
0 commit comments