ui: measure editor sidebar height
This commit is contained in:
@@ -90,6 +90,7 @@ let editorLoadToken = 0
|
||||
const boardEl = ref(null)
|
||||
const exportBoardEl = ref(null)
|
||||
const groupListEl = ref(null)
|
||||
const sidebarEl = ref(null)
|
||||
const poolEl = ref(null)
|
||||
const groupDropEls = ref({})
|
||||
const fileEl = ref(null)
|
||||
@@ -97,6 +98,8 @@ const thumbnailFileEl = ref(null)
|
||||
const groupSortable = ref(null)
|
||||
const poolSortable = ref(null)
|
||||
const dropSortables = ref([])
|
||||
const editorSidebarMaxHeight = ref('')
|
||||
let editorSidebarMeasureFrame = 0
|
||||
|
||||
const isNewTierList = computed(() => tierListId.value === 'new')
|
||||
const isOwnTierList = computed(() => !!auth.user && !!ownerId.value && ownerId.value === auth.user.id)
|
||||
@@ -364,6 +367,25 @@ function scrollWorkspaceBodyToTop() {
|
||||
workspaceBody?.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||
}
|
||||
|
||||
function updateEditorSidebarMaxHeight() {
|
||||
if (typeof window === 'undefined' || !sidebarEl.value) return
|
||||
const bottomGap = 14
|
||||
const stickyTop = 14
|
||||
const minHeight = 260
|
||||
const sidebarTop = Math.max(sidebarEl.value.getBoundingClientRect().top, stickyTop)
|
||||
const nextHeight = Math.max(minHeight, Math.floor(window.innerHeight - sidebarTop - bottomGap))
|
||||
editorSidebarMaxHeight.value = `${nextHeight}px`
|
||||
}
|
||||
|
||||
function scheduleEditorSidebarMeasure() {
|
||||
if (typeof window === 'undefined') return
|
||||
if (editorSidebarMeasureFrame) return
|
||||
editorSidebarMeasureFrame = window.requestAnimationFrame(() => {
|
||||
editorSidebarMeasureFrame = 0
|
||||
updateEditorSidebarMaxHeight()
|
||||
})
|
||||
}
|
||||
|
||||
function openItemContextMenu(itemId, event) {
|
||||
if (!canEdit.value || !itemId || !itemsById.value[itemId] || shouldIgnoreItemClick()) return
|
||||
selectedItemId.value = itemId
|
||||
@@ -1355,6 +1377,7 @@ async function loadEditorState() {
|
||||
if (loadToken !== editorLoadToken) return
|
||||
|
||||
syncSavedEditorSnapshot()
|
||||
scheduleEditorSidebarMeasure()
|
||||
if (canEdit.value) {
|
||||
await initSortables()
|
||||
}
|
||||
@@ -1374,6 +1397,9 @@ onMounted(() => {
|
||||
window.addEventListener('contextmenu', handleGlobalContextMenu, true)
|
||||
window.addEventListener('blur', closeItemContextMenu)
|
||||
window.addEventListener('scroll', closeItemContextMenu, true)
|
||||
window.addEventListener('resize', scheduleEditorSidebarMeasure)
|
||||
window.addEventListener('scroll', scheduleEditorSidebarMeasure, true)
|
||||
nextTick(() => scheduleEditorSidebarMeasure())
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
@@ -1382,6 +1408,12 @@ onUnmounted(() => {
|
||||
window.removeEventListener('contextmenu', handleGlobalContextMenu, true)
|
||||
window.removeEventListener('blur', closeItemContextMenu)
|
||||
window.removeEventListener('scroll', closeItemContextMenu, true)
|
||||
window.removeEventListener('resize', scheduleEditorSidebarMeasure)
|
||||
window.removeEventListener('scroll', scheduleEditorSidebarMeasure, true)
|
||||
if (editorSidebarMeasureFrame) {
|
||||
window.cancelAnimationFrame(editorSidebarMeasureFrame)
|
||||
editorSidebarMeasureFrame = 0
|
||||
}
|
||||
}
|
||||
if (thumbnailPreviewUrl.value) URL.revokeObjectURL(thumbnailPreviewUrl.value)
|
||||
destroySortables()
|
||||
@@ -1769,7 +1801,7 @@ onUnmounted(() => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sidebar">
|
||||
<div ref="sidebarEl" class="sidebar" :style="{ '--editor-sidebar-max-height': editorSidebarMaxHeight || undefined }">
|
||||
<div class="sidebar__titleRow">
|
||||
<div class="sidebar__title">아이템</div>
|
||||
<div class="sidebar__count">{{ visiblePoolCount }} / {{ pool.length }}</div>
|
||||
@@ -2774,7 +2806,6 @@ onUnmounted(() => {
|
||||
object-fit: cover;
|
||||
}
|
||||
.sidebar {
|
||||
--editor-sidebar-visible-offset: 136px;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -2785,7 +2816,7 @@ onUnmounted(() => {
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
|
||||
position: sticky;
|
||||
top: 14px;
|
||||
max-height: calc(100dvh - var(--editor-sidebar-visible-offset));
|
||||
max-height: var(--editor-sidebar-max-height, calc(100dvh - 136px));
|
||||
overflow: hidden;
|
||||
overscroll-behavior: contain;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user