MCPcopy Create free account
hub / github.com/Noumena-Network/code / computeVirtualScrollClampBounds

Function computeVirtualScrollClampBounds

src/hooks/useVirtualScroll.ts:390–430  ·  view source on GitHub ↗
({
  clampEnabled,
  rangeStart,
  rangeEnd,
  itemCount,
  viewportHeight,
  mountedStartTop,
  mountedEndBottom,
}: VirtualScrollClampBoundsInput)

Source from the content-addressed store, hash-verified

388}
389
390export function computeVirtualScrollClampBounds({
391 clampEnabled,
392 rangeStart,
393 rangeEnd,
394 itemCount,
395 viewportHeight,
396 mountedStartTop,
397 mountedEndBottom,
398}: VirtualScrollClampBoundsInput): VirtualScrollClampBounds {
399 if (!clampEnabled || rangeEnd <= rangeStart || itemCount === 0) {
400 return {
401 clampMin: undefined,
402 clampMax: undefined,
403 }
404 }
405
406 if (rangeStart > 0 && mountedStartTop === undefined) {
407 return {
408 clampMin: undefined,
409 clampMax: undefined,
410 }
411 }
412
413 if (rangeEnd < itemCount && mountedEndBottom === undefined) {
414 return {
415 clampMin: undefined,
416 clampMax: undefined,
417 }
418 }
419
420 const clampMin = rangeStart === 0 ? 0 : mountedStartTop!
421 const clampMax =
422 rangeEnd === itemCount
423 ? Infinity
424 : Math.max(clampMin, mountedEndBottom! - viewportHeight)
425
426 return {
427 clampMin,
428 clampMax,
429 }
430}
431
432export type VirtualScrollResult = {
433 /** [startIndex, endIndex) half-open slice of items to render. */

Callers 2

useVirtualScrollFunction · 0.85

Calls 1

maxMethod · 0.80

Tested by

no test coverage detected