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

View File

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