| 
									
										
										
										
											2024-10-29 13:32:50 +08:00
										 |  |  | import { useChatContext } from '@/app/components/base/chat/chat/context' | 
					
						
							|  |  |  | import Button from '@/app/components/base/button' | 
					
						
							|  |  |  | import cn from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2025-06-04 15:56:29 +08:00
										 |  |  | import { isValidUrl } from './utils' | 
					
						
							| 
									
										
										
										
											2024-10-29 13:32:50 +08:00
										 |  |  | const MarkdownButton = ({ node }: any) => { | 
					
						
							|  |  |  |   const { onSend } = useChatContext() | 
					
						
							|  |  |  |   const variant = node.properties.dataVariant | 
					
						
							|  |  |  |   const message = node.properties.dataMessage | 
					
						
							| 
									
										
										
										
											2024-12-30 22:27:25 +08:00
										 |  |  |   const link = node.properties.dataLink | 
					
						
							| 
									
										
										
										
											2024-10-29 13:32:50 +08:00
										 |  |  |   const size = node.properties.dataSize | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return <Button | 
					
						
							|  |  |  |     variant={variant} | 
					
						
							|  |  |  |     size={size} | 
					
						
							| 
									
										
										
										
											2025-05-08 22:50:55 +08:00
										 |  |  |     className={cn('!h-auto min-h-8 select-none whitespace-normal !px-3')} | 
					
						
							| 
									
										
										
										
											2024-12-30 22:27:25 +08:00
										 |  |  |     onClick={() => { | 
					
						
							| 
									
										
										
										
											2025-06-12 14:18:15 +08:00
										 |  |  |       if (link && isValidUrl(link)) { | 
					
						
							| 
									
										
										
										
											2024-12-30 22:27:25 +08:00
										 |  |  |         window.open(link, '_blank') | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2025-06-04 15:56:29 +08:00
										 |  |  |       if(!message) | 
					
						
							|  |  |  |         return | 
					
						
							| 
									
										
										
										
											2024-12-30 22:27:25 +08:00
										 |  |  |       onSend?.(message) | 
					
						
							|  |  |  |     }} | 
					
						
							| 
									
										
										
										
											2024-10-29 13:32:50 +08:00
										 |  |  |   > | 
					
						
							|  |  |  |     <span className='text-[13px]'>{node.children[0]?.value || ''}</span> | 
					
						
							|  |  |  |   </Button> | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | MarkdownButton.displayName = 'MarkdownButton' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default MarkdownButton |