chore: add cancel query model

This commit is contained in:
jialin
2024-08-21 18:09:13 +08:00
parent ba1670e56d
commit abb87e71ed
23 changed files with 523 additions and 179 deletions
+11 -10
View File
@@ -1,5 +1,6 @@
import hljs from 'highlight.js';
import 'highlight.js/styles/atom-one-dark.css';
import { memo, useMemo } from 'react';
import CopyButton from '../copy-button';
import { escapeHtml } from './utils';
@@ -19,7 +20,7 @@ const CodeViewer: React.FC<CodeViewerProps> = (props) => {
copyable = true
} = props || {};
const renderCode = () => {
const highlightedCode = useMemo(() => {
const autodetectLang = autodetect && !lang;
const cannotDetectLanguage = !autodetectLang && !hljs.getLanguage(lang);
let className = '';
@@ -52,9 +53,7 @@ const CodeViewer: React.FC<CodeViewerProps> = (props) => {
value: result.value,
className: className
};
};
const highlightedCode = renderCode();
}, [code, lang, autodetect, ignoreIllegals]);
return (
<pre className="code-pre">
@@ -64,13 +63,15 @@ const CodeViewer: React.FC<CodeViewerProps> = (props) => {
__html: highlightedCode.value
}}
></code>
<CopyButton
text={code}
size="small"
style={{ color: '#abb2bf' }}
></CopyButton>
{copyable && (
<CopyButton
text={code}
size="small"
style={{ color: '#abb2bf' }}
></CopyButton>
)}
</pre>
);
};
export default CodeViewer;
export default memo(CodeViewer);
+3 -2
View File
@@ -4,12 +4,13 @@ import './style.less';
const HighlightCode: React.FC<{
code: string;
lang?: string;
copyable?: boolean;
}> = (props) => {
const { code, lang = 'bash' } = props;
const { code, lang = 'bash', copyable = true } = props;
return (
<div className="high-light-wrapper">
<CodeViewer lang={lang} code={code} />
<CodeViewer lang={lang} code={code} copyable={copyable} />
</div>
);
};