优化块编辑器大纲导航栏

This commit is contained in:
jingrow 2026-06-04 18:20:10 +08:00
parent 906312fc39
commit 46d863dd75
2 changed files with 36 additions and 16 deletions

View File

@ -395,14 +395,6 @@ onBeforeUnmount(() => {
z-index: 10;
}
.blockeditor-container .n-affix--affixed ~ .blockeditor-outline-rail-wrapper {
position: fixed;
top: calc(64px + 100px);
bottom: 12px;
left: calc(var(--be-container-left) + var(--be-container-width) - 30px);
right: auto;
}
/* ── ProseMirror ── */
.blockeditor-mount .ProseMirror { outline: none; min-height: 120px; padding-left: 48px; padding-right: 36px; }
.blockeditor-mount .ProseMirror > * + * { margin-top: 0.5em; }

View File

@ -113,9 +113,9 @@ function syncActive() {
return
}
// heading线 15%
// heading线 scrollToBlock 8px
const contentTop = getContentTop()
const triggerY = contentTop + (window.innerHeight - contentTop) * 0.15
const triggerY = contentTop + 8
let closest: BlockInfo | null = null
let minDist = Infinity
@ -222,16 +222,46 @@ function updateRailPosition() {
if (!container) return
const editorRect = container.getBoundingClientRect()
const rail = railRef.value
// rail
if (editorRect.bottom < 0 || editorRect.top > window.innerHeight) {
railRef.value.style.opacity = '0'
railRef.value.style.pointerEvents = 'none'
rail.style.opacity = '0'
rail.style.pointerEvents = 'none'
return
}
railRef.value.style.opacity = '1'
railRef.value.style.pointerEvents = 'auto'
rail.style.opacity = '1'
rail.style.pointerEvents = 'auto'
// JS-driven position:fixed
// position:sticky position:absolute
// JS fixed
const stickyTop = getContentTop()
if (editorRect.top < stickyTop) {
// rail
const wrapper = container.querySelector('.blockeditor-outline-rail-wrapper') as HTMLElement | null
if (!wrapper) return
const wrapperRect = wrapper.getBoundingClientRect()
rail.style.position = 'fixed'
rail.style.top = `${stickyTop + 8}px`
rail.style.left = `${wrapperRect.left}px`
rail.style.width = `${wrapperRect.width}px`
rail.style.bottom = ''
rail.style.right = ''
rail.style.zIndex = '10'
} else {
// absolute
rail.style.position = ''
rail.style.top = ''
rail.style.left = ''
rail.style.width = ''
rail.style.bottom = ''
rail.style.right = ''
rail.style.zIndex = ''
}
}
function onRailEnter() {
@ -426,8 +456,6 @@ onBeforeUnmount(() => {
<style scoped>
/* 导航条容器 */
.block-outline-rail {
position: sticky;
top: 64px; /* 页面导航栏底部 */
width: 16px;
margin-left: auto; /* 推至编辑器右侧 */
pointer-events: auto;