优化块编辑器大纲导航栏
This commit is contained in:
parent
906312fc39
commit
46d863dd75
@ -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; }
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user