File tree 4 files changed +28
-2
lines changed
4 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export interface ImageBlockConfig {
10
10
uploadPlaceholderText : string
11
11
captionPlaceholderText : string
12
12
onUpload : ( file : File ) => Promise < string >
13
+ proxyDomURL ?: ( url : string ) => Promise < string > | string
13
14
}
14
15
15
16
export const defaultImageBlockConfig : ImageBlockConfig = {
Original file line number Diff line number Diff line change @@ -17,8 +17,20 @@ export const imageBlockView = $view(
17
17
'milkdown-image-block'
18
18
) as HTMLElement & ImageComponentProps
19
19
const config = ctx . get ( imageBlockConfig . key )
20
+ const proxyDomURL = config . proxyDomURL
20
21
const bindAttrs = ( node : Node ) => {
21
- dom . src = node . attrs . src
22
+ if ( ! proxyDomURL ) {
23
+ dom . src = node . attrs . src
24
+ } else {
25
+ const proxiedURL = proxyDomURL ( node . attrs . src )
26
+ if ( typeof proxiedURL === 'string' ) {
27
+ dom . src = proxiedURL
28
+ } else {
29
+ proxiedURL . then ( ( url ) => {
30
+ dom . src = url
31
+ } )
32
+ }
33
+ }
22
34
dom . ratio = node . attrs . ratio
23
35
dom . caption = node . attrs . caption
24
36
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ export interface InlineImageConfig {
8
8
confirmButton : ( ) => ReturnType < typeof html >
9
9
uploadPlaceholderText : string
10
10
onUpload : ( file : File ) => Promise < string >
11
+ proxyDomURL ?: ( url : string ) => Promise < string > | string
11
12
}
12
13
13
14
export const defaultInlineImageConfig : InlineImageConfig = {
Original file line number Diff line number Diff line change @@ -17,8 +17,20 @@ export const inlineImageView = $view(
17
17
'milkdown-image-inline'
18
18
) as HTMLElement & InlineImageComponentProps
19
19
const config = ctx . get ( inlineImageConfig . key )
20
+ const proxyDomURL = config . proxyDomURL
20
21
const bindAttrs = ( node : Node ) => {
21
- dom . src = node . attrs . src
22
+ if ( ! proxyDomURL ) {
23
+ dom . src = node . attrs . src
24
+ } else {
25
+ const proxiedURL = proxyDomURL ( node . attrs . src )
26
+ if ( typeof proxiedURL === 'string' ) {
27
+ dom . src = proxiedURL
28
+ } else {
29
+ proxiedURL . then ( ( url ) => {
30
+ dom . src = url
31
+ } )
32
+ }
33
+ }
22
34
dom . alt = node . attrs . alt
23
35
dom . title = node . attrs . title
24
36
}
You can’t perform that action at this time.
0 commit comments