add protocol to link without it (#132)
* add protocol to link without it * refactoing * refactoring * refactoring
This commit is contained in:
parent
b059f1024e
commit
f86108ba20
|
@ -15,6 +15,15 @@ type BubbleMenuProps = {
|
|||
ref: (el: HTMLDivElement) => void
|
||||
}
|
||||
|
||||
const checkUrl = (url) => {
|
||||
try {
|
||||
new URL(url)
|
||||
return url
|
||||
} catch {
|
||||
return `https://${url}`
|
||||
}
|
||||
}
|
||||
|
||||
export const TextBubbleMenu = (props: BubbleMenuProps) => {
|
||||
const { t } = useLocalize()
|
||||
const [textSizeBubbleOpen, setTextSizeBubbleOpen] = createSignal<boolean>(false)
|
||||
|
@ -59,7 +68,11 @@ export const TextBubbleMenu = (props: BubbleMenuProps) => {
|
|||
}
|
||||
|
||||
const handleLinkFormSubmit = (value: string) => {
|
||||
props.editor.chain().focus().setLink({ href: value }).run()
|
||||
props.editor
|
||||
.chain()
|
||||
.focus()
|
||||
.setLink({ href: checkUrl(value) })
|
||||
.run()
|
||||
}
|
||||
|
||||
const currentUrl = createEditorTransaction(
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
export const validateUrl = (value: string) => {
|
||||
return /^((http|https):\/\/)?[^ "]+$/.test(value)
|
||||
return value.includes('.') && !value.includes(' ')
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user