forked from jupyterlab/jupyter-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use @jupyterlab/rendermime for in-chat markdown rendering (jupyterlab…
…#564) * create markdown widget and component * add rendermime * add rendermime registry requrement, activation to plugin * update var naming * use rendermime directrly in the react component * use css to emulate code styling * add @types/react-dom * create CopyButton component based on chat-code-view.tsx by @dlqqq * add CopyButton and styling * remoev unsused code * add min width to the button * omit units for 0 * use RendermimeMarkdown for ChatSettings model help * remove react-markdown dependency * revert CopyButton styling * remove comments * memoize RendermimeMarkdown (10% faster) * Update packages/jupyter-ai/src/components/copy-button.tsx Co-authored-by: Jason Weill <[email protected]> * remove copying status * update yarn.lock * detect mimetype, render latex * set latexTypesetter * MathJax typeset redered md * use rmRegistry typesetter * remove MathJaxTypesetter import * Modify CHAT_SYSTEM_PROMPT, use $ and $$ style LaTeX delimiters only * remove @jupyterlab/mathjax-extension dependency * remove @jupyterlab/builder dependency * Update packages/jupyter-ai/src/index.ts Co-authored-by: Michał Krassowski <[email protected]> * render content after attaching buttons per @krassowski * remove duplicate rmRegistry per @krassowski * update snapshots * Remove unused react-syntax-highlighter, rehype-katex, remark-math dependencies * move @types/react-dom dependency from root to packages/jupyter-ai per @krassowski * Update packages/jupyter-ai/package.json Co-authored-by: Michał Krassowski <[email protected]> * update yarn.lock * Escale LaTeX delimeters with regex instead of prompt engineering * add .jp-ai-rendermime-markdown mjx-container styling to match jlab * update escapeLatexDelimiters comment * update lockfile * update lockfile * move escapeLatexDelimiters outside of RendermimeMarkdownBase to avoid redefinitions on every rerender * adjust escapeLatexDelimiters parameter naming * Rename escapeLatexDelimiters argument from str to text * Update packages/jupyter-ai/src/components/rendermime-markdown.tsx Co-authored-by: david qiu <[email protected]> * Update escapeLatexDelimiters docstring per @dlqqq * bump react-dom version per @dlqqq * add @jupyterlab/rendermime as a direct dependenct per @dlqqq to avoid potential build errors --------- Co-authored-by: Jason Weill <[email protected]> Co-authored-by: Michał Krassowski <[email protected]> Co-authored-by: david qiu <[email protected]>
- Loading branch information
1 parent
04ef454
commit a229a43
Showing
14 changed files
with
2,425 additions
and
3,110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React, { useState, useCallback } from 'react'; | ||
|
||
import { Box, Button } from '@mui/material'; | ||
|
||
enum CopyStatus { | ||
None, | ||
Copied | ||
} | ||
|
||
const COPYBTN_TEXT_BY_STATUS: Record<CopyStatus, string> = { | ||
[CopyStatus.None]: 'Copy to Clipboard', | ||
[CopyStatus.Copied]: 'Copied!' | ||
}; | ||
|
||
type CopyButtonProps = { | ||
value: string; | ||
}; | ||
|
||
export function CopyButton(props: CopyButtonProps): JSX.Element { | ||
const [copyStatus, setCopyStatus] = useState<CopyStatus>(CopyStatus.None); | ||
|
||
const copy = useCallback(async () => { | ||
try { | ||
await navigator.clipboard.writeText(props.value); | ||
} catch (err) { | ||
console.error('Failed to copy text: ', err); | ||
setCopyStatus(CopyStatus.None); | ||
return; | ||
} | ||
|
||
setCopyStatus(CopyStatus.Copied); | ||
setTimeout(() => setCopyStatus(CopyStatus.None), 1000); | ||
}, [props.value]); | ||
|
||
return ( | ||
<Box sx={{ display: 'flex', flexDirection: 'column' }}> | ||
<Button | ||
onClick={copy} | ||
disabled={copyStatus !== CopyStatus.None} | ||
aria-label="Copy To Clipboard" | ||
sx={{ | ||
alignSelf: 'flex-end', | ||
textTransform: 'none' | ||
}} | ||
> | ||
{COPYBTN_TEXT_BY_STATUS[copyStatus]} | ||
</Button> | ||
</Box> | ||
); | ||
} |
Oops, something went wrong.