feat: commentaire ancré sur la SÉLECTION de texte (pas le bloc) + retrait du bouton bleu « 💬 Comment » (v7.65.0)
- commentBlock() : l'ancre est la sélection vivante dans le bloc (repli : la plage mémorisée par la toolbar de sélection, qui survit au clic du bouton), sinon tout le bloc ; offsets via _srcOffset() → anchor_start/anchor_end exacts dans le texte source, l'ancre jaune ne couvre que le texte choisi. - Suppression de #_commentSelBtn (bouton bleu flottant « 💬 Comment » au-dessus de la sélection), de showCommentBtn()/hideCommentBtn() et du listener mousedown associé ; déclencheurs restants : 💬 de la toolbar de sélection, menu de bloc, Ctrl+⇧+M. - toggleComments() remet _commentSel à zéro à la fermeture du tiroir : un brouillon abandonné ne peut plus ancrer le commentaire suivant ailleurs. - e2e v764_comments_reactions : sous-sélection « reaction a un » → ancre = la plage seule (avant/après reload), #_commentSelBtn absent. Tests: pytest tests/ -q -n auto → 1383 passed ; ruff check app tests → OK ; e2e v764/v762/v763/v7641/regression_editor_mount → 5 passed sur :8081.
This commit is contained in:
@@ -1865,11 +1865,24 @@ replaceBlock(idx,type){const b=this.blocks[idx];if(!b)return;this.sync();this.pu
|
||||
setBlockColor(idx,key,val){if(idx<0||idx>=this.blocks.length)return;const targets=this._blockTargets(idx);const v=(!val||val==='default')?null:val;this.sync();this.pushHistory();targets.forEach(i=>{const b=this.blocks[i];if(!b)return;if(!b.style)b.style={};if(v==null)delete b.style[key];else b.style[key]=v;});if(v!=null){try{localStorage.setItem('fdLastBlockColor',key+'|'+v);}catch(e){}}this.dirty=true;this.autoSave();this.render();_rtSync();_selClear();},
|
||||
// ── v7.61 : actions du menu contextuel de bloc ──
|
||||
commentBlock(idx){
|
||||
// L'ancre est la SÉLECTION de texte si elle vit dans ce bloc (la
|
||||
// sélection de la toolbar aussi : le clic sur le bouton peut l'avoir
|
||||
// fait disparaître du DOM), sinon tout le bloc.
|
||||
const b=this.blocks[idx];if(!b)return;const el=this.getEl(b.id);if(!el)return;
|
||||
const r=document.createRange();r.selectNodeContents(el);
|
||||
const s=window.getSelection();s.removeAllRanges();s.addRange(r);
|
||||
this.showCommentBtn();
|
||||
if(!this._commentSel||!this._commentSel.range){this.showToast('Sélectionnez du texte pour commenter','error');return;}
|
||||
let r=null;const s=window.getSelection();
|
||||
if(s&&s.rangeCount&&!s.isCollapsed){
|
||||
const rr=s.getRangeAt(0);
|
||||
if(el.contains(rr.startContainer)&&el.contains(rr.endContainer))r=rr.cloneRange();
|
||||
}
|
||||
if(!r&&this._sel&&this._sel.range&&this._sel.idx===idx
|
||||
&&el.contains(this._sel.range.startContainer)&&el.contains(this._sel.range.endContainer)){
|
||||
r=this._sel.range.cloneRange();
|
||||
}
|
||||
if(!r){r=document.createRange();r.selectNodeContents(el);}
|
||||
const start=_srcOffset(el,r.startContainer,r.startOffset);
|
||||
const end=_srcOffset(el,r.endContainer,r.endOffset);
|
||||
if(!(end>start)){this.showToast('Sélectionnez du texte pour commenter','error');return;}
|
||||
this._commentSel={range:r,bid:el.dataset.bid,start:start,end:end};
|
||||
this.commentOnSelection();
|
||||
},
|
||||
// v7.62 : renommé — « askAI() » (sans argument, plus bas) l'écrasait,
|
||||
@@ -2607,7 +2620,7 @@ applyAIBlocks(text){
|
||||
});
|
||||
},
|
||||
// ── v4.9.0: Collaboration — comments & mentions ──
|
||||
toggleComments(){this.commentsOpen=!this.commentsOpen;if(this.commentsOpen)this.loadComments();},
|
||||
toggleComments(){if(this.commentsOpen){this.commentsOpen=false;this._commentSel={range:null,bid:null,start:0,end:0};return;}this.commentsOpen=true;this.loadComments();},
|
||||
async loadComments(){
|
||||
try{const r=await fetch('/api/pages/'+this.pid+'/comments',{credentials:'same-origin'});const d=await r.json();
|
||||
this.comments=d.comments||[];this.commentCount=this.comments.length;}
|
||||
@@ -2630,7 +2643,7 @@ applyAIBlocks(text){
|
||||
headers:{'Content-Type':'application/json','X-CSRF-Token':this.csrfTok()},
|
||||
body:JSON.stringify({body:text,anchor_block_id:sel.bid||null,anchor_start:sel.bid?sel.start:null,anchor_end:sel.bid?sel.end:null})});
|
||||
const d=await r.json();
|
||||
if(d.status==='created'){this.commentDraft='';this._commentSel={range:null,bid:null,start:0,end:0};this.hideCommentBtn();await this.loadComments();this.showToast('Comment added');}
|
||||
if(d.status==='created'){this.commentDraft='';this._commentSel={range:null,bid:null,start:0,end:0};await this.loadComments();this.showToast('Comment added');}
|
||||
else{this.showToast(d.detail||'Failed to add comment');}
|
||||
}catch(e){this.showToast('Failed to add comment');}
|
||||
},
|
||||
@@ -2724,32 +2737,9 @@ applyAIBlocks(text){
|
||||
},
|
||||
commentOnSelection(){
|
||||
const sel=this._commentSel;if(!sel.range)return;
|
||||
const bid=sel.bid||'';this.commentsOpen=true;this.commentDraft='';
|
||||
const btn=document.getElementById('_commentSelBtn');if(btn)btn.style.display='none';
|
||||
this.commentsOpen=true;this.commentDraft='';
|
||||
this.$nextTick(()=>{const ta=document.querySelector('.comments-drawer textarea');if(ta)ta.focus();});
|
||||
},
|
||||
showCommentBtn(){
|
||||
const s=window.getSelection();if(!s||s.isCollapsed)return;
|
||||
const ct=document.getElementById('_blocksCt');if(!ct||!ct.contains(s.anchorNode))return;
|
||||
// ancre = nœud texte ou élément (comme showFmt depuis v7.62)
|
||||
const anEl=s.anchorNode?(s.anchorNode.nodeType===1?s.anchorNode:s.anchorNode.parentElement):null;
|
||||
const bel=anEl?anEl.closest('[data-bid]'):null;
|
||||
if(!bel)return;
|
||||
const bid=bel.dataset.bid;
|
||||
const span0=this._selSpan(bel,s.getRangeAt(0));
|
||||
const start=span0.start;
|
||||
const end=span0.end;
|
||||
if(end<=start)return;
|
||||
this._commentSel={range:s.getRangeAt(0).cloneRange(),bid:bid,start:start,end:end};
|
||||
const r=s.getRangeAt(0).getBoundingClientRect();
|
||||
const btn=document.getElementById('_commentSelBtn');if(!btn)return;
|
||||
btn.style.display='block';
|
||||
const bw=btn.offsetWidth||110,bh=btn.offsetHeight||34;
|
||||
let x=r.left+r.width/2-bw/2,y=r.top-bh-8;
|
||||
x=Math.min(Math.max(8,x),window.innerWidth-bw-8);if(y<8)y=r.bottom+8;
|
||||
btn.style.left=x+'px';btn.style.top=y+'px';
|
||||
},
|
||||
hideCommentBtn(){const btn=document.getElementById('_commentSelBtn');if(btn)btn.style.display='none';},
|
||||
// ── @mention autocomplete (v4.9.0 users + v5.11.0 pages & dates) ──
|
||||
mentionOpen:false,mentionQuery:'',mentionResults:[],mentionPages:[],mentionEl:null,
|
||||
openMention(el){
|
||||
@@ -3074,7 +3064,7 @@ applyAIBlocks(text){
|
||||
};
|
||||
}
|
||||
// v7.62 : data Alpine du wrapper éditeur — Alpine v3 n'expose plus __x
|
||||
// (l'ancien accès rendait muets showFmt/hideCommentBtn/mentions).
|
||||
// (l'ancien accès rendait muets showFmt/mentions).
|
||||
function _xed(el){ if(!el) return null; if(el.__x&&el.__x.$data) return el.__x.$data;
|
||||
return (el._x_dataStack&&el._x_dataStack[0])||null; }
|
||||
// v7.64 : clic sur une ancre jaune → ouvre et centre le fil de discussion ;
|
||||
@@ -3114,9 +3104,8 @@ applyAIBlocks(text){
|
||||
if(!ct?.contains(s.anchorNode)){d.fmt.open=false;d._sel=null;return;}
|
||||
const bel0=s.anchorNode&&(s.anchorNode.nodeType===1?s.anchorNode:s.anchorNode.parentElement);
|
||||
const bel=bel0?bel0.closest('[data-bid]'):null;
|
||||
if(bel){const idx=d.getIdx(bel.dataset.bid);if(idx>=0)d.showFmt(idx);d.showCommentBtn();}else{d.hideCommentBtn();}
|
||||
if(bel){const idx=d.getIdx(bel.dataset.bid);if(idx>=0)d.showFmt(idx);}
|
||||
},80);});
|
||||
document.addEventListener('mousedown',()=>{setTimeout(()=>{const d=_xed(document.querySelector('.page-editor-wrapper'));if(d)d.hideCommentBtn();},10);});
|
||||
document.addEventListener('keyup',(e)=>{
|
||||
const d=_xed(document.querySelector('.page-editor-wrapper'));if(!d)return;
|
||||
if(!d.mentionOpen){if(e.key!=='@')return;}
|
||||
|
||||
Reference in New Issue
Block a user