$1')
+ .replace(/\*\*([^*]+)\*\*/g,'$1')
+ .replace(/\*([^*]+)\*/g,'$1')
+ .replace(/~~([^~]+)~~/g,'const x = 1;');
+ case 'table': return p('| A | B |
| 1 | 2 |
$1').replace(/\*\*([^*]+)\*\*/g,'$1').replace(/\*([^*]+)\*/g,'$1').replace(/\[([^\]]+)\]\((https?:[^)\s]+)\)/g,'$1');};
+ while(i'+inline(s.replace(/^> /,''))+''); i++; continue; } + out.push('
'+inline(s)+'
'); i++; + } + return out.join(''); }, + paint(){ const self=this; const h=this.ROOT; + if(this._stage==='input'){ + h.innerHTML='⚠ '+esc(msg)+'
'; this._stage='result'; this.paint(); }, + insert(){ const E=window.E; if(!E||typeof E.applyAIBlocks!=='function')return; E.sync(); + const result=this._resultText(); if(!result)return; E.applyAIBlocks(result); E.dirty=true; E.autoSave(); this.close(); }, + _resultText(){ const el=this.ROOT&&this.ROOT.querySelector('.aici-result'); if(!el)return ''; const r=document.createRange();r.selectNodeContents(el);return r.toString(); }, + toast(m){ if(window.showToast)window.showToast(m,'info'); } + }; + window.AIC=AIC; + + // ═══════════ AI Autocomplete (v5.9.0) ═══════════ + // After a short idle while typing in a text block, ask the AI for a short + // continuation and surface it as a "Tab to accept" pill anchored to the + // block. Tab inserts the suggestion; Escape dismisses it. + const AIAC={_timer:null,_sug:'',_bid:null,_busy:false,_enabled:true,_req:0, + ROOT:null, + _allowed:function(b){ if(!b)return false; return ['paragraph','heading_1','heading_2','heading_3','heading_4','bulleted_list','numbered_list','quote','callout','to_do'].indexOf(b.type)>=0; }, + mk(){ if(this.ROOT)return this.ROOT; const d=document.createElement('div'); d.id='_aiAC'; d.style.cssText='position:fixed;z-index:1150;display:none;max-width:min(520px,90vw)'; document.body.appendChild(d); this.ROOT=d; + document.addEventListener('mousedown',function(ev){ if(AIAC.ROOT&&!AIAC.ROOT.contains(ev.target))AIAC.clear(); }); + return d; }, + schedule(bid){ if(!this._enabled)return; const E=window.E; if(!E)return; const idx=E.getIdx(bid); const b=idx>=0?E.blocks[idx]:null; if(!this._allowed(b))return this.clear(); + clearTimeout(this._timer); const self=this; this._timer=setTimeout(function(){ self.fetch(bid); },900); }, + fetch(bid){ const E=window.E; if(!E)return; const idx=E.getIdx(bid); const b=idx>=0?E.blocks[idx]:null; if(!this._allowed(b))return this.clear(); + const el=E.getEl(bid); const prefix=((el&&el.textContent)||b.content||'').trim(); if(prefix.length<8)return this.clear(); + const ctx=(typeof window.fdGetPageContext==='function')?String(window.fdGetPageContext()||''):''; + const req=++this._req; this._busy=true; const self=this; const csrf=(E.csrfTok?E.csrfTok():''); + fetch('/api/agent/writing',{method:'POST',headers:{'Content-Type':'application/json','X-CSRF-Token':csrf},body:JSON.stringify({action:'autocomplete',prefix:prefix,context:ctx})}) + .then(function(r){return r.json();}) + .then(function(d){ self._busy=false; if(req!==self._req)return; if(d&&d.ok&&d.text){ self.show(bid,d.text); } else { self.clear(); } }) + .catch(function(){ self._busy=false; if(req===self._req)self.clear(); }); + }, + show(bid,text){ text=(text||'').trim(); if(!text){return this.clear();} const E=window.E; const el=E&&E.getEl(bid); if(!el)return; + this._sug=text; this._bid=bid; this.mk(); const r=el.getBoundingClientRect(); + this.ROOT.innerHTML='${mdEsc(b.content)}`;
+ else if(b.type==='callout')inner=`