Add security remove paste text in editor

Fix design for mobile formule product
This commit is contained in:
Serreau Jovann
2026-01-30 09:13:01 +01:00
parent e644dc4b85
commit 4873c24bb2
12 changed files with 343 additions and 145 deletions

View File

@@ -3,7 +3,7 @@ export class CrmEditor extends HTMLTextAreaElement {
this.style.display = 'none';
this.editorContainer = document.createElement('div');
this.editorContainer.className = "w-full rounded-2xl overflow-hidden ring-1 ring-white/20 bg-slate-950/40 backdrop-blur-2xl shadow-2xl transition-all duration-300 focus-within:ring-blue-500/50 my-4";
this.editorContainer.className = "w-full rounded-2xl overflow-hidden ring-1 ring-white/20 bg-slate-950/40 backdrop-blur-2xl shadow-2xl transition-all duration-300 focus-within:ring-blue-500/50 my-4 relative";
this.editorContainer.innerHTML = `
<div class="flex items-center gap-1.5 p-3 border-b border-white/10 bg-black/40">
@@ -37,6 +37,11 @@ export class CrmEditor extends HTMLTextAreaElement {
</button>
</div>
<!-- Toast de sécurité -->
<div id="paste-error" class="absolute top-16 left-1/2 -translate-x-1/2 bg-red-500 text-white px-4 py-2 rounded-full text-xs font-bold shadow-xl opacity-0 transition-all duration-300 pointer-events-none z-50">
Copie impossible
</div>
<div id="wysiwyg-area"
contenteditable="true"
class="p-6 min-h-[300px] max-h-[600px] overflow-y-auto focus:outline-none bg-white text-slate-900 prose prose-slate max-w-none shadow-inner break-words w-full">
@@ -55,12 +60,19 @@ export class CrmEditor extends HTMLTextAreaElement {
this.wysiwyg = this.editorContainer.querySelector('#wysiwyg-area');
this.colorInput = this.editorContainer.querySelector('#text-color-input');
this.colorBar = this.editorContainer.querySelector('#color-bar');
this.pasteError = this.editorContainer.querySelector('#paste-error');
this.initEvents();
this.updateStats();
}
initEvents() {
// Sécurité anti-collage
this.wysiwyg.addEventListener('paste', (e) => {
e.preventDefault();
this.showPasteWarning();
});
// Boutons standards
const buttons = this.editorContainer.querySelectorAll('button[data-cmd]');
buttons.forEach(btn => {
@@ -90,6 +102,16 @@ export class CrmEditor extends HTMLTextAreaElement {
});
}
showPasteWarning() {
this.pasteError.classList.remove('opacity-0', 'scale-90');
this.pasteError.classList.add('opacity-100', 'scale-100');
setTimeout(() => {
this.pasteError.classList.add('opacity-0', 'scale-90');
this.pasteError.classList.remove('opacity-100', 'scale-100');
}, 2000);
}
updateStats() {
const text = this.wysiwyg.innerText || "";
const count = text.trim().length;

View File

@@ -201,6 +201,7 @@ const initBackToTop = () => {
const initMobileMenu = () => {
const btn = document.getElementById('menu-button');
const menu = document.getElementById('mobile-menu');
console.log(btn,menu)
if (!btn || !menu) return;
btn.onclick = () => {
const open = menu.classList.toggle('hidden');