Implémentation copie des messages
This commit is contained in:
parent
c12f9c9639
commit
fdc76685da
@ -1,6 +1,6 @@
|
|||||||
<script>
|
<script>
|
||||||
import { beforeUpdate, afterUpdate } from 'svelte';
|
import { beforeUpdate, afterUpdate, createEventDispatcher} from 'svelte';
|
||||||
import { createEventDispatcher } from 'svelte';
|
import { copyToClipboard } from './lib/clipboard.js';
|
||||||
|
|
||||||
export let message;
|
export let message;
|
||||||
export let container;
|
export let container;
|
||||||
@ -56,6 +56,11 @@
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function handleCopy() {
|
||||||
|
copyToClipboard(message.content)
|
||||||
|
.then(() => alert('Text copied successfully!'))
|
||||||
|
.catch(err => alert(`Failed to copy text: ${err.message}`));
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@ -86,7 +91,7 @@
|
|||||||
<span class="icon-edit"></span>
|
<span class="icon-edit"></span>
|
||||||
</button>
|
</button>
|
||||||
{:else if message.role == 'assistant'}
|
{:else if message.role == 'assistant'}
|
||||||
<button class="btn btn-primary btn-sm" title="Copier"><span class="icon-content_copy"></span></button>
|
<button class="btn btn-primary btn-sm" title="Copier" on:click={handleCopy}><span class="icon-content_copy"></span></button>
|
||||||
<button class="btn btn-primary btn-sm" title="Régénérer"><span class="icon-loop"></span></button>
|
<button class="btn btn-primary btn-sm" title="Régénérer"><span class="icon-loop"></span></button>
|
||||||
<button class="btn btn-primary btn-sm" title="Supprimer le message"><span class="icon-delete"></span></button>
|
<button class="btn btn-primary btn-sm" title="Supprimer le message"><span class="icon-delete"></span></button>
|
||||||
{/if}
|
{/if}
|
||||||
|
36
vite/src/lib/clipboard.js
Normal file
36
vite/src/lib/clipboard.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// src/lib/clipboard.js
|
||||||
|
|
||||||
|
export async function copyToClipboard(text) {
|
||||||
|
if (navigator.clipboard) {
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(text);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Failed to copy text:', err);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return fallbackCopyToClipboard(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function fallbackCopyToClipboard(text) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const textArea = document.createElement("textarea");
|
||||||
|
textArea.value = text;
|
||||||
|
|
||||||
|
// Éviter le scrolling vers le bas
|
||||||
|
textArea.style.position = "fixed";
|
||||||
|
textArea.style.top = "-9999px";
|
||||||
|
|
||||||
|
document.body.appendChild(textArea);
|
||||||
|
textArea.focus();
|
||||||
|
textArea.select();
|
||||||
|
|
||||||
|
if (document.execCommand('copy')) {
|
||||||
|
resolve();
|
||||||
|
} else {
|
||||||
|
reject(new Error('Fallback: Copy command was unsuccessful'));
|
||||||
|
}
|
||||||
|
|
||||||
|
document.body.removeChild(textArea);
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user