11/* eslint-disable no-unsafe-optional-chaining */
22/* eslint-disable @typescript-eslint/no-unsafe-call */
33/* eslint-disable @typescript-eslint/no-unsafe-member-access */
4- import React , { useEffect , useState } from ' react' ;
4+ import { useEffect , useState } from " react" ;
55
6- import { Button , IconComponent , Input , Label , Switch } from ' @/components' ;
7- import { useLocale } from ' @/locales' ;
6+ import { Button , IconComponent , Input , Label , Switch } from " @/components" ;
7+ import { useLocale } from " @/locales" ;
88
99interface IPropsLinkEditBlock {
10- editor : any
11- onSetLink : ( link : string , text ?: string , openInNewTab ?: boolean ) => void
10+ editor : any ;
11+ onSetLink : ( link : string , text ?: string , openInNewTab ?: boolean ) => void ;
1212}
1313
1414function LinkEditBlock ( props : IPropsLinkEditBlock ) {
1515 const { t } = useLocale ( ) ;
1616
1717 const [ form , setForm ] = useState ( {
18- text : '' ,
19- link : '' ,
18+ text : "" ,
19+ link : "" ,
2020 } ) ;
2121 const [ openInNewTab , setOpenInNewTab ] = useState < boolean > ( false ) ;
2222
2323 useEffect ( ( ) => {
2424 if ( props ?. editor ) {
25- const { href : link , target } = props . editor ?. getAttributes ( ' link' ) ;
25+ const { href : link , target } = props . editor ?. getAttributes ( " link" ) ;
2626
2727 const { from, to } = props . editor . state . selection ;
28- const text = props . editor . state . doc . textBetween ( from , to , ' ' ) ;
28+ const text = props . editor . state . doc . textBetween ( from , to , " " ) ;
2929 setForm ( {
30- link : link || '' ,
30+ link : link || "" ,
3131 text,
3232 } ) ;
33- setOpenInNewTab ( target === ' _blank' ) ;
33+ setOpenInNewTab ( target === " _blank" ) ;
3434 }
3535 } , [ props ?. editor ] ) ;
3636
3737 function handleSubmit ( event : any ) {
3838 event . preventDefault ( ) ;
3939 event . stopPropagation ( ) ;
4040 props ?. onSetLink ( form . link , form . text , openInNewTab ) ;
41+ setForm ( { text : "" , link : "" } ) ;
4142 }
4243
4344 return (
4445 < div className = "border-neutral-200 richtext-rounded-lg !richtext-border richtext-bg-white richtext-p-2 richtext-shadow-sm dark:richtext-border-neutral-800 dark:richtext-bg-black" >
45- < form className = "richtext-flex richtext-flex-col richtext-gap-2"
46- onSubmit = { handleSubmit }
47- >
48- < Label className = "mb-[6px]" >
49- { t ( 'editor.link.dialog.text' ) }
50- </ Label >
46+ < div className = "richtext-flex richtext-flex-col richtext-gap-2" >
47+ < Label className = "mb-[6px]" > { t ( "editor.link.dialog.text" ) } </ Label >
5148
5249 < div className = "richtext-mb-[10px] richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5" >
5350 < div className = "richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center" >
5451 < Input
5552 className = "richtext-w-80"
56- onChange = { e => setForm ( { ...form , text : e . target . value } ) }
53+ onChange = { ( e ) => setForm ( { ...form , text : e . target . value } ) }
5754 placeholder = "Text"
5855 required
5956 type = "text"
@@ -62,32 +59,29 @@ function LinkEditBlock(props: IPropsLinkEditBlock) {
6259 </ div >
6360 </ div >
6461
65- < Label className = "mb-[6px]" >
66- { t ( 'editor.link.dialog.link' ) }
67- </ Label >
62+ < Label className = "mb-[6px]" > { t ( "editor.link.dialog.link" ) } </ Label >
6863
6964 < div className = "richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5" >
7065 < div className = "richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center" >
7166 < Input
7267 className = "richtext-pl-10"
73- onChange = { e => setForm ( { ...form , link : e . target . value } ) }
68+ onChange = { ( e ) => setForm ( { ...form , link : e . target . value } ) }
7469 required
7570 type = "url"
7671 value = { form . link }
7772 />
7873
7974 < span className = "richtext-absolute richtext-inset-y-0 richtext-start-0 richtext-flex richtext-items-center richtext-justify-center richtext-px-2" >
80- < IconComponent className = "richtext-size-5 richtext-text-muted-foreground"
75+ < IconComponent
76+ className = "richtext-size-5 richtext-text-muted-foreground"
8177 name = "Link"
8278 />
8379 </ span >
8480 </ div >
8581 </ div >
8682
8783 < div className = "richtext-flex richtext-items-center richtext-space-x-2" >
88- < Label >
89- { t ( 'editor.link.dialog.openInNewTab' ) }
90- </ Label >
84+ < Label > { t ( "editor.link.dialog.openInNewTab" ) } </ Label >
9185
9286 < Switch
9387 checked = { openInNewTab }
@@ -97,12 +91,13 @@ function LinkEditBlock(props: IPropsLinkEditBlock) {
9791 />
9892 </ div >
9993
100- < Button className = "richtext-mt-2 richtext-self-end"
101- type = "submit"
94+ < Button
95+ className = "richtext-mt-2 richtext-self-end"
96+ onClick = { handleSubmit }
10297 >
103- { t ( ' editor.link.dialog.button.apply' ) }
98+ { t ( " editor.link.dialog.button.apply" ) }
10499 </ Button >
105- </ form >
100+ </ div >
106101 </ div >
107102 ) ;
108103}
0 commit comments