mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-05-16 06:28:18 +08:00

Co-authored-by: NFish <douxc512@gmail.com> Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: twwu <twwu@dify.ai> Co-authored-by: jZonG <jzongcode@gmail.com>
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { useChatContext } from '@/app/components/base/chat/chat/context'
|
|
import Button from '@/app/components/base/button'
|
|
import cn from '@/utils/classnames'
|
|
|
|
const MarkdownButton = ({ node }: any) => {
|
|
const { onSend } = useChatContext()
|
|
const variant = node.properties.dataVariant
|
|
const message = node.properties.dataMessage
|
|
const link = node.properties.dataLink
|
|
const size = node.properties.dataSize
|
|
|
|
function is_valid_url(url: string): boolean {
|
|
try {
|
|
const parsed_url = new URL(url)
|
|
return ['http:', 'https:'].includes(parsed_url.protocol)
|
|
}
|
|
catch {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return <Button
|
|
variant={variant}
|
|
size={size}
|
|
className={cn('!h-8 select-none !px-3')}
|
|
onClick={() => {
|
|
if (is_valid_url(link)) {
|
|
window.open(link, '_blank')
|
|
return
|
|
}
|
|
onSend?.(message)
|
|
}}
|
|
>
|
|
<span className='text-[13px]'>{node.children[0]?.value || ''}</span>
|
|
</Button>
|
|
}
|
|
MarkdownButton.displayName = 'MarkdownButton'
|
|
|
|
export default MarkdownButton
|