This commit is contained in:
Vadim
2021-09-10 20:21:28 +03:00
parent 4250d2956b
commit f03a6d0cbe
2 changed files with 21 additions and 16 deletions

View File

@@ -17,18 +17,20 @@
applyParticleSizes,
getCurrentPageIndex,
getPartialPageSize,
getPagesCount,
getPagesCountByParticlesCount,
getParticleIndexByPageIndex,
} from '../../utils/page'
import {
getClones,
applyClones,
getPagesCountWithoutClones,
getClonesCount,
} from '../../utils/clones'
import {
getAdjacentIndexes,
} from '../../utils/lazy'
import {
getValueInRange,
} from '../../utils/math'
import { get } from '../../utils/object'
import { ProgressManager } from '../../utils/ProgressManager'
import { wait } from '../../utils/interval'
@@ -164,10 +166,10 @@
$: dispatch('pageChange', currentPageIndex)
let particlesCount = 0
let pagesCountWithoutClones = 1
$: pagesCount = getPagesCount({
let particlesCountWithoutClones = 1
$: pagesCount = getPagesCountByParticlesCount({
infinite,
pagesCountWithoutClones,
particlesCountWithoutClones,
particlesToScroll,
})
@@ -203,7 +205,7 @@
infinite,
pageIndex: currentPageIndex,
pagesCount,
particlesCount: pagesCountWithoutClones,
particlesCount: particlesCountWithoutClones,
particlesToShow,
particlesToScroll,
}).particleIndexes
@@ -271,18 +273,21 @@
}))
cleanupFns.push(() => progressManager.reset())
if (particlesContainer && pageWindowElement) {
pagesCountWithoutClones = particlesContainer.children.length
particlesCountWithoutClones = particlesContainer.children.length
particlesToShow = getValueInRange(1, particlesToShow, particlesCountWithoutClones)
particlesToScroll = getValueInRange(1, particlesToScroll, particlesCountWithoutClones)
initialPageIndex = getValueInRange(0, initialPageIndex, particlesCountWithoutClones - 1)
partialPageSize = getPartialPageSize({
particlesToScroll,
particlesToShow,
pagesCountWithoutClones,
particlesCountWithoutClones,
})
await tick()
infinite && addClones()
// TODO: validate initialPageIndex
store.init(getParticleIndexByPageIndex({
infinite,
pageIndex: initialPageIndex,
@@ -482,7 +487,7 @@
<slot
name="dots"
currentPageIndex={currentPageIndex}
pagesCount={pagesCountWithoutClones}
pagesCount={pagesCount}
showPage={handlePageChange}
>
<Dots

View File

@@ -101,13 +101,13 @@ export function getCurrentPageIndex({
export function getPartialPageSize({
particlesToScroll,
particlesToShow,
pagesCountWithoutClones, // TODO: rename
particlesCountWithoutClones,
}) {
const overlap = particlesToScroll - particlesToShow
let particlesCount = particlesToShow
while(true) {
const diff = pagesCountWithoutClones - particlesCount - overlap
const diff = particlesCountWithoutClones - particlesCount - overlap
if (diff < particlesToShow) {
return diff
}
@@ -115,14 +115,14 @@ export function getPartialPageSize({
}
}
export function getPagesCount({
export function getPagesCountByParticlesCount({
infinite,
pagesCountWithoutClones,
particlesCountWithoutClones,
particlesToScroll,
}) {
return infinite
? Math.ceil(pagesCountWithoutClones / particlesToScroll)
: Math.round(pagesCountWithoutClones / particlesToScroll)
? Math.ceil(particlesCountWithoutClones / particlesToScroll)
: Math.round(particlesCountWithoutClones / particlesToScroll)
}
export function getParticleIndexByPageIndex({