File tree 2 files changed +12
-7
lines changed
packages/components/src/image-inline
2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ type Attrs = {
14
14
export type MilkdownImageInlineProps = {
15
15
selected : Ref < boolean >
16
16
readonly : Ref < boolean >
17
- setLink : ( link : string ) => void
17
+ setAttr : < T extends keyof Attrs > ( attr : T , value : Attrs [ T ] ) => void
18
18
config : InlineImageConfig
19
19
} & {
20
20
[ P in keyof Attrs ] : Ref < Attrs [ P ] | undefined >
@@ -42,7 +42,7 @@ export const MilkdownImageInline = defineComponent<MilkdownImageInlineProps>({
42
42
type : Object ,
43
43
required : true ,
44
44
} ,
45
- setLink : {
45
+ setAttr : {
46
46
type : Function ,
47
47
required : true ,
48
48
} ,
@@ -60,7 +60,7 @@ export const MilkdownImageInline = defineComponent<MilkdownImageInlineProps>({
60
60
src = { props . src }
61
61
selected = { props . selected }
62
62
readonly = { props . readonly }
63
- setLink = { props . setLink }
63
+ setLink = { ( link ) => props . setAttr ( 'src' , link ) }
64
64
imageIcon = { props . config . imageIcon ( ) }
65
65
uploadButton = { props . config . uploadButton ( ) }
66
66
confirmButton = { props . config . confirmButton ( ) }
Original file line number Diff line number Diff line change @@ -18,11 +18,16 @@ export const inlineImageView = $view(
18
18
const title = ref ( initialNode . attrs . title )
19
19
const selected = ref ( false )
20
20
const readonly = ref ( ! view . editable )
21
- const setLink = ( link : string ) => {
21
+ const setAttr = ( attr : string , value : unknown ) => {
22
22
const pos = getPos ( )
23
23
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
+ )
26
31
}
27
32
28
33
const config = ctx . get ( inlineImageConfig . key )
@@ -32,7 +37,7 @@ export const inlineImageView = $view(
32
37
title,
33
38
selected,
34
39
readonly,
35
- setLink ,
40
+ setAttr ,
36
41
config,
37
42
} )
38
43
const dom = document . createElement ( 'span' )
You can’t perform that action at this time.
0 commit comments