Skip to content

Commit

Permalink
feat: add image proxy for crepe
Browse files Browse the repository at this point in the history
  • Loading branch information
Saul-Mirone committed Dec 15, 2024
1 parent 4862bf1 commit 3f3e8c5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/components/src/image-block/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface ImageBlockConfig {
uploadPlaceholderText: string
captionPlaceholderText: string
onUpload: (file: File) => Promise<string>
proxyDomURL?: (url: string) => Promise<string>
}

export const defaultImageBlockConfig: ImageBlockConfig = {
Expand Down
9 changes: 8 additions & 1 deletion packages/components/src/image-block/view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ export const imageBlockView = $view(
'milkdown-image-block'
) as HTMLElement & ImageComponentProps
const config = ctx.get(imageBlockConfig.key)
const proxyDomURL = config.proxyDomURL
const bindAttrs = (node: Node) => {
dom.src = node.attrs.src
if (!proxyDomURL) {
dom.src = node.attrs.src
} else {
proxyDomURL(node.attrs.src).then((url) => {
dom.src = url
})
}
dom.ratio = node.attrs.ratio
dom.caption = node.attrs.caption

Expand Down
1 change: 1 addition & 0 deletions packages/components/src/image-inline/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface InlineImageConfig {
confirmButton: () => ReturnType<typeof html>
uploadPlaceholderText: string
onUpload: (file: File) => Promise<string>
proxyDomURL?: (url: string) => Promise<string>
}

export const defaultInlineImageConfig: InlineImageConfig = {
Expand Down
9 changes: 8 additions & 1 deletion packages/components/src/image-inline/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ export const inlineImageView = $view(
'milkdown-image-inline'
) as HTMLElement & InlineImageComponentProps
const config = ctx.get(inlineImageConfig.key)
const proxyDomURL = config.proxyDomURL
const bindAttrs = (node: Node) => {
dom.src = node.attrs.src
if (!proxyDomURL) {
dom.src = node.attrs.src
} else {
proxyDomURL(node.attrs.src).then((url) => {
dom.src = url
})
}
dom.alt = node.attrs.alt
dom.title = node.attrs.title
}
Expand Down

0 comments on commit 3f3e8c5

Please sign in to comment.