Skip to content

Commit 546215d

Browse files
committed
chore: adjust
1 parent f7fa217 commit 546215d

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

Diff for: packages/components/src/image-inline/components/image-inline.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type Attrs = {
1414
export type MilkdownImageInlineProps = {
1515
selected: Ref<boolean>
1616
readonly: Ref<boolean>
17-
setLink: (link: string) => void
17+
setAttr: <T extends keyof Attrs>(attr: T, value: Attrs[T]) => void
1818
config: InlineImageConfig
1919
} & {
2020
[P in keyof Attrs]: Ref<Attrs[P] | undefined>
@@ -42,7 +42,7 @@ export const MilkdownImageInline = defineComponent<MilkdownImageInlineProps>({
4242
type: Object,
4343
required: true,
4444
},
45-
setLink: {
45+
setAttr: {
4646
type: Function,
4747
required: true,
4848
},
@@ -60,7 +60,7 @@ export const MilkdownImageInline = defineComponent<MilkdownImageInlineProps>({
6060
src={props.src}
6161
selected={props.selected}
6262
readonly={props.readonly}
63-
setLink={props.setLink}
63+
setLink={(link) => props.setAttr('src', link)}
6464
imageIcon={props.config.imageIcon()}
6565
uploadButton={props.config.uploadButton()}
6666
confirmButton={props.config.confirmButton()}

Diff for: packages/components/src/image-inline/view.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,16 @@ export const inlineImageView = $view(
1818
const title = ref(initialNode.attrs.title)
1919
const selected = ref(false)
2020
const readonly = ref(!view.editable)
21-
const setLink = (link: string) => {
21+
const setAttr = (attr: string, value: unknown) => {
2222
const pos = getPos()
2323
if (pos == null) return
24-
const url = DOMPurify.sanitize(link)
25-
view.dispatch(view.state.tr.setNodeAttribute(pos, 'src', url))
24+
view.dispatch(
25+
view.state.tr.setNodeAttribute(
26+
pos,
27+
attr,
28+
attr === 'src' ? DOMPurify.sanitize(value as string) : value
29+
)
30+
)
2631
}
2732

2833
const config = ctx.get(inlineImageConfig.key)
@@ -32,7 +37,7 @@ export const inlineImageView = $view(
3237
title,
3338
selected,
3439
readonly,
35-
setLink,
40+
setAttr,
3641
config,
3742
})
3843
const dom = document.createElement('span')

0 commit comments

Comments
 (0)