File tree Expand file tree Collapse file tree 4 files changed +28
-2
lines changed Expand file tree Collapse file tree 4 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export interface ImageBlockConfig {
1010 uploadPlaceholderText : string
1111 captionPlaceholderText : string
1212 onUpload : ( file : File ) => Promise < string >
13+ proxyDomURL ?: ( url : string ) => Promise < string > | string
1314}
1415
1516export const defaultImageBlockConfig : ImageBlockConfig = {
Original file line number Diff line number Diff line change @@ -17,8 +17,20 @@ export const imageBlockView = $view(
1717 'milkdown-image-block'
1818 ) as HTMLElement & ImageComponentProps
1919 const config = ctx . get ( imageBlockConfig . key )
20+ const proxyDomURL = config . proxyDomURL
2021 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+ }
2234 dom . ratio = node . attrs . ratio
2335 dom . caption = node . attrs . caption
2436
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ export interface InlineImageConfig {
88 confirmButton : ( ) => ReturnType < typeof html >
99 uploadPlaceholderText : string
1010 onUpload : ( file : File ) => Promise < string >
11+ proxyDomURL ?: ( url : string ) => Promise < string > | string
1112}
1213
1314export const defaultInlineImageConfig : InlineImageConfig = {
Original file line number Diff line number Diff line change @@ -17,8 +17,20 @@ export const inlineImageView = $view(
1717 'milkdown-image-inline'
1818 ) as HTMLElement & InlineImageComponentProps
1919 const config = ctx . get ( inlineImageConfig . key )
20+ const proxyDomURL = config . proxyDomURL
2021 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+ }
2234 dom . alt = node . attrs . alt
2335 dom . title = node . attrs . title
2436 }
You can’t perform that action at this time.
0 commit comments