ui: try to save text with formatting in secure contexts
This commit is contained in:
parent
20cab5b104
commit
4aa75ce14b
2 changed files with 25 additions and 4 deletions
|
|
@ -102,7 +102,7 @@ export function ChatMsg({
|
|||
<IconButton tooltip="Dislike this answer" onClick={() => onFeedback('dislike', messageId)}>
|
||||
<ThumbsDown size={16} />
|
||||
</IconButton>
|
||||
<CopyButton content={text} isIcon />
|
||||
<CopyButton content={() => bodyRef.current?.innerHTML} isIcon format={'text/html'} />
|
||||
<IconButton processing={isProcessing} tooltip="Export as PDF" onClick={onExport}>
|
||||
<FileDown size={16} />
|
||||
</IconButton>
|
||||
|
|
|
|||
|
|
@ -10,15 +10,36 @@ function CopyButton({
|
|||
btnText = 'copy',
|
||||
size = 'small',
|
||||
isIcon = false,
|
||||
format = 'text/plain',
|
||||
}) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
|
||||
const copyHandler = () => {
|
||||
setCopied(true);
|
||||
copy(content);
|
||||
const reset = () => {
|
||||
setTimeout(() => {
|
||||
setCopied(false);
|
||||
}, 1000);
|
||||
}
|
||||
const copyHandler = () => {
|
||||
setCopied(true);
|
||||
const contentIsGetter = typeof content === 'function'
|
||||
const textContent = contentIsGetter ? content() : content;
|
||||
const isHttps = window.location.protocol === 'https:';
|
||||
if (!isHttps) {
|
||||
copy(textContent);
|
||||
reset();
|
||||
return;
|
||||
}
|
||||
const blob = new Blob([textContent], { type: format });
|
||||
const cbItem = new ClipboardItem({
|
||||
[format]: blob
|
||||
})
|
||||
navigator.clipboard.write([cbItem])
|
||||
.catch(e => {
|
||||
copy(textContent);
|
||||
})
|
||||
.finally(() => {
|
||||
reset()
|
||||
})
|
||||
};
|
||||
|
||||
if (isIcon) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue