@@ -10,7 +10,7 @@ import {imageType, normalizeUrlFactory} from '../../../markdown';
10
10
import { ImgSizeAttr } from '../../../specs' ;
11
11
import { ImagesUploadProcess } from '../ImagePaste/upload' ;
12
12
13
- import { FilePlaceholder , type FilePlaceholderProps } from './view' ;
13
+ import { ImagePlaceholder , type ImagePlaceholderProps , type RenderImageWidgetFormFn } from './view' ;
14
14
15
15
export const addWidget = (
16
16
tr : Transaction ,
@@ -26,6 +26,7 @@ export type ImageWidgetDescriptorOpts = {
26
26
needToSetDimensionsForUploadedImages : boolean ;
27
27
uploadImages ?: FileUploadHandler ;
28
28
enableNewImageSizeCalculation ?: boolean ;
29
+ renderImageForm ?: RenderImageWidgetFormFn ;
29
30
} ;
30
31
31
32
class ImageWidgetDescriptor extends ReactWidgetDescriptor {
@@ -34,6 +35,7 @@ class ImageWidgetDescriptor extends ReactWidgetDescriptor {
34
35
private readonly uploadImages ;
35
36
private readonly needToSetDimensionsForUploadedImages : boolean ;
36
37
private readonly enableNewImageSizeCalculation ?: boolean ;
38
+ private readonly renderImageForm : RenderImageWidgetFormFn | undefined ;
37
39
38
40
private widgetHandler : ImageWidgetHandler | null = null ;
39
41
@@ -42,6 +44,7 @@ class ImageWidgetDescriptor extends ReactWidgetDescriptor {
42
44
this . domElem = document . createElement ( 'span' ) ;
43
45
this . deps = deps ;
44
46
this . uploadImages = opts . uploadImages ;
47
+ this . renderImageForm = opts . renderImageForm ;
45
48
this . needToSetDimensionsForUploadedImages = opts . needToSetDimensionsForUploadedImages ;
46
49
this . enableNewImageSizeCalculation = opts . enableNewImageSizeCalculation ;
47
50
}
@@ -54,6 +57,7 @@ class ImageWidgetDescriptor extends ReactWidgetDescriptor {
54
57
getPos,
55
58
decoId : this . id ,
56
59
uploadImages : this . uploadImages ,
60
+ renderImageForm : this . renderImageForm ,
57
61
needToSetDimensionsForUploadedImages : this . needToSetDimensionsForUploadedImages ,
58
62
enableNewImageSizeCalculation : this . enableNewImageSizeCalculation ,
59
63
} ,
@@ -83,6 +87,7 @@ type ImageWidgetHandlerProps = {
83
87
view : EditorView ;
84
88
getPos : ( ) => number ;
85
89
uploadImages ?: FileUploadHandler ;
90
+ renderImageForm ?: RenderImageWidgetFormFn ;
86
91
needToSetDimensionsForUploadedImages : boolean ;
87
92
enableNewImageSizeCalculation ?: boolean ;
88
93
} ;
@@ -96,6 +101,7 @@ class ImageWidgetHandler {
96
101
private readonly normalizeUrl ;
97
102
private readonly needToSetDimensionsForUploadedImages : boolean ;
98
103
private readonly enableNewImageSizeCalculation ?: boolean ;
104
+ private readonly renderImageForm : RenderImageWidgetFormFn | undefined ;
99
105
100
106
private cancelled = false ;
101
107
@@ -105,6 +111,7 @@ class ImageWidgetHandler {
105
111
view,
106
112
getPos,
107
113
uploadImages,
114
+ renderImageForm,
108
115
needToSetDimensionsForUploadedImages,
109
116
enableNewImageSizeCalculation,
110
117
} : ImageWidgetHandlerProps ,
@@ -115,6 +122,7 @@ class ImageWidgetHandler {
115
122
this . getPos = getPos ;
116
123
this . uploadImages = uploadImages ;
117
124
this . normalizeUrl = normalizeUrlFactory ( deps ) ;
125
+ this . renderImageForm = renderImageForm ;
118
126
this . needToSetDimensionsForUploadedImages = needToSetDimensionsForUploadedImages ;
119
127
this . enableNewImageSizeCalculation = enableNewImageSizeCalculation ;
120
128
}
@@ -127,21 +135,22 @@ class ImageWidgetHandler {
127
135
this . view = view ;
128
136
this . getPos = getPos ;
129
137
return (
130
- < FilePlaceholder
138
+ < ImagePlaceholder
131
139
onCancel = { this . onCancel }
132
140
onSubmit = { this . onSubmit }
133
141
onAttach = { this . uploadImages && this . onAttach }
142
+ renderForm = { this . renderImageForm }
134
143
/>
135
144
) ;
136
145
}
137
146
138
- private onCancel : FilePlaceholderProps [ 'onCancel' ] = ( ) => {
147
+ private onCancel : ImagePlaceholderProps [ 'onCancel' ] = ( ) => {
139
148
this . cancelled = true ;
140
149
this . view . dispatch ( removeDecoration ( this . view . state . tr , this . decoId ) ) ;
141
150
this . view . focus ( ) ;
142
151
} ;
143
152
144
- private onSubmit : FilePlaceholderProps [ 'onSubmit' ] = ( params ) => {
153
+ private onSubmit : ImagePlaceholderProps [ 'onSubmit' ] = ( params ) => {
145
154
if ( this . cancelled ) return ;
146
155
147
156
const url = this . normalizeUrl ( params . url ) ?. url ;
@@ -159,7 +168,7 @@ class ImageWidgetHandler {
159
168
this . insertNodes ( [ node ] ) ;
160
169
} ;
161
170
162
- private onAttach : FilePlaceholderProps [ 'onAttach' ] = async ( files ) => {
171
+ private onAttach : ImagePlaceholderProps [ 'onAttach' ] = async ( files ) => {
163
172
if ( this . cancelled || ! this . uploadImages ) return ;
164
173
165
174
const { view} = this ;
0 commit comments