fix: editor preview auto-scrolls to blocks area on load
This commit is contained in:
@@ -431,7 +431,7 @@ const Studio={
|
||||
try{
|
||||
const doc=await api(`/api/sites/${siteId}/pages/${page}/editor-preview`,{...req('POST',{blocks,page_template:kind,layout_mode:layoutMode,site_design:siteDesignPreview}),signal:previewController.signal});
|
||||
if(!editorTools.shouldAcceptPreview(page,seq,pageId,previewRequest))return;
|
||||
frame.onload=()=>Studio.highlightCanvas();frame.srcdoc=doc;$('#previewState').textContent='实时预览 · 已更新';$('#previewDot').classList.remove('loading','error');
|
||||
frame.onload=()=>{try{frame.contentWindow.postMessage({source:'siteforge-studio-host',action:'scroll-to-blocks'},'*')}catch(e){} Studio.highlightCanvas()};frame.srcdoc=doc;$('#previewState').textContent='实时预览 · 已更新';$('#previewDot').classList.remove('loading','error');
|
||||
}catch(e){
|
||||
if(!editorTools.shouldAcceptPreview(page,seq,pageId,previewRequest)||e.name==='AbortError')return;
|
||||
$('#previewState').textContent='预览更新失败';$('#previewDot').classList.remove('loading');$('#previewDot').classList.add('error');toast('预览失败:'+e.message,true);
|
||||
|
||||
@@ -142,6 +142,10 @@
|
||||
}
|
||||
window.addEventListener('message',event=>{
|
||||
if(event.source!==parent||event.data?.source!=='siteforge-studio-host')return;
|
||||
if(event.data.action==='scroll-to-blocks'){
|
||||
const main=document.querySelector('#main-content');
|
||||
if(main&&main.children.length>0){main.scrollIntoView({behavior:'auto',block:'start'})}
|
||||
}
|
||||
if(event.data.action==='highlight'&&typeof event.data.blockId==='string'){activate(event.data.blockId,false);for(const n of nested)n.classList.toggle('sf-canvas-child-selected',n.dataset.block===event.data.childId);}
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user