Skip to content

Commit feb7940

Browse files
committed
Fix eslint errors and run prettier
1 parent 539f8b8 commit feb7940

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

src/Elastic.Documentation.Site/Assets/copybutton.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,6 @@ if (!iconCopy) {
9898

9999
const codeCellId = (index: number, prefix: string) => `${prefix}${index}`
100100

101-
// Clears selected text since ClipboardJS will select the text when copying
102-
const clearSelection = () => {
103-
if (window.getSelection) {
104-
window.getSelection().removeAllRanges()
105-
} else if ('selection' in document) {
106-
;(document.selection as Selection).empty()
107-
}
108-
}
109-
110101
// Changes tooltip text for a moment, then changes it back
111102
// We want the timeout of our `success` class to be a bit shorter than the
112103
// tooltip and icon change, so that we can hide the icon before changing back.
@@ -130,7 +121,11 @@ const temporarilyChangeIcon = (el) => {
130121
}, timeoutIcon)
131122
}
132123

133-
const addCopyButtonToCodeCells = (selector: string, baseElement: ParentNode, prefix: string) => {
124+
const addCopyButtonToCodeCells = (
125+
selector: string,
126+
baseElement: ParentNode,
127+
prefix: string
128+
) => {
134129
// If ClipboardJS hasn't loaded, wait a bit and try again. This
135130
// happens because we load ClipboardJS asynchronously.
136131

@@ -148,11 +143,10 @@ const addCopyButtonToCodeCells = (selector: string, baseElement: ParentNode, pre
148143
clipboardButton.setAttribute('data-tooltip', messages[locale]['copy'])
149144
clipboardButton.setAttribute('data-clipboard-target', `#${id}`)
150145
clipboardButton.innerHTML = iconCopy
151-
clipboardButton.onclick = async (event) => {
146+
clipboardButton.onclick = async () => {
152147
try {
153148
const text = copyTargetText(clipboardButton, baseElement)
154149
await navigator.clipboard.writeText(text)
155-
156150
temporarilyChangeTooltip(
157151
clipboardButton,
158152
messages[locale]['copy'],
@@ -163,7 +157,7 @@ const addCopyButtonToCodeCells = (selector: string, baseElement: ParentNode, pre
163157
console.error(error)
164158
}
165159
}
166-
160+
167161
codeCell.insertAdjacentElement('afterend', clipboardButton)
168162
})
169163

@@ -277,6 +271,10 @@ const addCopyButtonToCodeCells = (selector: string, baseElement: ParentNode, pre
277271
// })
278272
}
279273

280-
export function initCopyButton(selector: string = '.highlight pre', baseElement: ParentNode = document, prefix: string = 'markdown-content-codecell-') {
274+
export function initCopyButton(
275+
selector: string = '.highlight pre',
276+
baseElement: ParentNode = document,
277+
prefix: string = 'markdown-content-codecell-'
278+
) {
281279
addCopyButtonToCodeCells(selector, baseElement, prefix)
282280
}

src/Elastic.Documentation.Site/Assets/web-components/SearchOrAskAi/AskAi/ChatMessage.tsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { initCopyButton } from '../../../copybutton'
12
import { ChatMessage as ChatMessageType } from './chat.store'
23
import { LlmGatewayMessage } from './useLlmGateway'
34
import {
@@ -21,9 +22,8 @@ import DOMPurify from 'dompurify'
2122
import hljs from 'highlight.js/lib/core'
2223
import { marked } from 'marked'
2324
import * as React from 'react'
24-
import {$, $$} from 'select-dom'
25-
import {initCopyButton} from "../../../copybutton";
26-
import {useEffect} from "react";
25+
import { useEffect } from 'react'
26+
import { $, $$ } from 'select-dom'
2727

2828
interface ChatMessageProps {
2929
message: ChatMessageType
@@ -162,36 +162,40 @@ export const ChatMessage = ({
162162
const sanitized = DOMPurify.sanitize(html as string)
163163
const tempDiv = document.createElement('div')
164164
tempDiv.innerHTML = sanitized
165-
165+
166166
// Add highlight wrappers and highlight code blocks
167-
$$('pre', tempDiv).forEach((preEl => {
167+
$$('pre', tempDiv).forEach((preEl) => {
168168
const wrapper = document.createElement('div')
169-
wrapper.className = 'highlight';
170-
preEl.parentNode?.insertBefore(wrapper, preEl);
171-
wrapper.appendChild(preEl);
169+
wrapper.className = 'highlight'
170+
preEl.parentNode?.insertBefore(wrapper, preEl)
171+
wrapper.appendChild(preEl)
172172
const codeEl = $('code', preEl)
173173
if (codeEl) {
174-
hljs.highlightElement(codeEl);
174+
hljs.highlightElement(codeEl)
175175
}
176-
}))
177-
176+
})
177+
178178
const parsed = tempDiv.innerHTML
179-
const ref = React.useRef<HTMLDivElement>(null);
180-
179+
const ref = React.useRef<HTMLDivElement>(null)
180+
181181
// Initialize copy buttons after DOM is updated
182182
useEffect(() => {
183183
if (isComplete && ref.current) {
184184
const timer = setTimeout(() => {
185185
try {
186186
// Use the modified initCopyButton with scoped element
187-
initCopyButton('.highlight pre', ref.current!, 'ai-message-codecell-');
187+
initCopyButton(
188+
'.highlight pre',
189+
ref.current!,
190+
'ai-message-codecell-'
191+
)
188192
} catch (error) {
189-
console.error('Failed to initialize copy buttons:', error);
193+
console.error('Failed to initialize copy buttons:', error)
190194
}
191-
}, 100);
192-
return () => clearTimeout(timer);
195+
}, 100)
196+
return () => clearTimeout(timer)
193197
}
194-
}, [parsed, isComplete]);
198+
}, [parsed, isComplete])
195199

196200
return (
197201
<EuiFlexGroup

0 commit comments

Comments
 (0)