From 10072608ca97a746f6d9da1a1cdff3febb4a381c Mon Sep 17 00:00:00 2001 From: STetsing <41009393+STetsing@users.noreply.github.com> Date: Mon, 6 Jan 2025 16:05:20 +0100 Subject: [PATCH] overrided the nlux clipboard button --- .../remix-ai/src/lib/components/Default.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/libs/remix-ui/remix-ai/src/lib/components/Default.tsx b/libs/remix-ui/remix-ai/src/lib/components/Default.tsx index 50a50d1e3d..2d36e01e86 100644 --- a/libs/remix-ui/remix-ai/src/lib/components/Default.tsx +++ b/libs/remix-ui/remix-ai/src/lib/components/Default.tsx @@ -1,9 +1,8 @@ import React from 'react' import '../remix-ai.css' -import { DefaultModels, GenerationParams, ChatHistory, HandleStreamResponse, HandleSimpleResponse } from '@remix/remix-ai-core'; +import { DefaultModels, GenerationParams, ChatHistory, HandleStreamResponse } from '@remix/remix-ai-core'; import { ConversationStarter, StreamSend, StreamingAdapterObserver, useAiChatApi } from '@nlux/react'; import { AiChat, useAsStreamAdapter, ChatItem } from '@nlux/react'; -import { JsonStreamParser } from '@remix/remix-ai-core'; import { user, assistantAvatar } from './personas'; import { highlighter } from '@nlux/highlighter' import './color.css' @@ -32,6 +31,18 @@ export const Default = (props) => { observer.next(' ') // Add a space to flush the last message ChatHistory.pushHistory(prompt, result) observer.complete() + const codeBlocks = document.getElementsByClassName('code-block') + + // override copy button functionality + Array.from(codeBlocks).forEach((block) => { + // only 1 copy button per code block + const copyButton = document.getElementsByClassName('nlux-comp-copyButton') + copyButton[0].addEventListener('click', async () => { + console.log('nlux copy button clicked'); + const text = block.textContent; //|| block.innerText; + await navigator.clipboard.writeText(block.textContent); + }); + }) } ) else { @@ -73,7 +84,7 @@ export const Default = (props) => { submitShortcut: 'Enter', hideStopButton: false, }} - messageOptions={{ showCodeBlockCopyButton: false, + messageOptions={{ showCodeBlockCopyButton: true, editableUserMessages: true, streamingAnimationSpeed: 2, waitTimeBeforeStreamCompletion: 1000,