pull/5601/head
STetsing 4 weeks ago committed by Aniket
parent de65e44d3a
commit cb474c1fe4
  1. 28
      libs/remix-ui/remix-ai/src/lib/components/Default.tsx

@ -11,6 +11,19 @@ import '@nlux/themes/unstyled.css';
export let ChatApi = null export let ChatApi = null
export const Default = (props) => { export const Default = (props) => {
const HandleCopyToClipboard = () => {
const codeBlocks = document.getElementsByClassName('code-block')
Array.from(codeBlocks).forEach((block) => {
const copyButtons = block.getElementsByClassName('nlux-comp-copyButton')
Array.from(copyButtons).forEach((cp_btn) => {
cp_btn.removeEventListener('click', () => {})
cp_btn.addEventListener('click', async () => {
await navigator.clipboard.writeText(block.textContent)
})
})
})
}
const send: StreamSend = async ( const send: StreamSend = async (
prompt: string, prompt: string,
observer: StreamingAdapterObserver, observer: StreamingAdapterObserver,
@ -31,24 +44,13 @@ export const Default = (props) => {
observer.next(' ') // Add a space to flush the last message observer.next(' ') // Add a space to flush the last message
ChatHistory.pushHistory(prompt, result) ChatHistory.pushHistory(prompt, result)
observer.complete() observer.complete()
const codeBlocks = document.getElementsByClassName('code-block') HandleCopyToClipboard()
Array.from(codeBlocks).forEach((block) => {
const copyButtons = block.getElementsByClassName('nlux-comp-copyButton');
Array.from(copyButtons).forEach((cp_btn) => {
// remove click event listener if existing
cp_btn.removeEventListener('click', () => {});
cp_btn.addEventListener('click', async () => {
await navigator.clipboard.writeText(block.textContent);
});
})
})
} }
) )
else { else {
observer.next(response) observer.next(response)
observer.complete() observer.complete()
HandleCopyToClipboard()
} }
}; };

Loading…
Cancel
Save