diff --git a/app/static/editor.js b/app/static/editor.js index d11f2ea..df15bd4 100644 --- a/app/static/editor.js +++ b/app/static/editor.js @@ -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); diff --git a/app/static/studio-canvas-bridge.js b/app/static/studio-canvas-bridge.js index bf5cc9a..b7eab53 100644 --- a/app/static/studio-canvas-bridge.js +++ b/app/static/studio-canvas-bridge.js @@ -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);} }); })();