에디터 미디어 페이지 계산 로직 분리

This commit is contained in:
2026-07-24 18:07:22 +09:00
parent e3f98cb820
commit 1ec71cc985
7 changed files with 147 additions and 47 deletions

View File

@@ -22,6 +22,8 @@ import {
getEditorHistoryEntryValue
} from '../../lib/markdown-editor-history.js'
import {
buildMediaPickerPageItems,
buildMediaPickerRangeLabel,
createMediaBlockMarkdown,
findUploadSizeLimitError,
getGallerySelectionOrder as getGallerySelectionOrderFromSelection,
@@ -3075,52 +3077,19 @@ const filteredMediaItems = computed(() => mediaItems.value.filter(isMediaItemSel
const mediaPickerPageCount = computed(() => Math.max(1, Number(mediaPickerPagination.value.pageCount) || 1))
const mediaPickerRangeLabel = computed(() => {
const total = Number(mediaPickerPagination.value.total) || 0
if (total <= 0) {
return '0개'
}
const page = Math.min(Math.max(Number(mediaPickerPagination.value.page) || mediaPickerPage.value, 1), mediaPickerPageCount.value)
const pageSize = Number(mediaPickerPagination.value.pageSize) || mediaPickerPageSize
const start = ((page - 1) * pageSize) + 1
const end = Math.min(start + pageSize - 1, total)
return `${total}개 중 ${start}-${end}개`
return buildMediaPickerRangeLabel({
pagination: mediaPickerPagination.value,
currentPage: mediaPickerPage.value,
pageCount: mediaPickerPageCount.value,
defaultPageSize: mediaPickerPageSize
})
})
const mediaPickerPageItems = computed(() => {
const total = mediaPickerPageCount.value
const current = Math.min(Math.max(Number(mediaPickerPage.value) || 1, 1), total)
const pages = new Set([1, total, current])
for (let page = current - 2; page <= current + 2; page += 1) {
pages.add(page)
}
if (current <= 3) {
pages.add(2)
pages.add(3)
pages.add(4)
}
if (current >= total - 2) {
pages.add(total - 3)
pages.add(total - 2)
pages.add(total - 1)
}
const orderedPages = [...pages].filter((page) => page >= 1 && page <= total).sort((left, right) => left - right)
return orderedPages.reduce((items, page, index) => {
const previousPage = orderedPages[index - 1]
if (previousPage && page - previousPage > 1) {
items.push(`ellipsis-${previousPage}-${page}`)
}
items.push(page)
return items
}, [])
return buildMediaPickerPageItems({
currentPage: mediaPickerPage.value,
pageCount: mediaPickerPageCount.value
})
})
/**