@pdanpdan/virtual-scroll 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -125,6 +125,7 @@ const virtualScrollProps = computed(() => {
125
125
  const pStart = props.scrollPaddingStart;
126
126
  const pEnd = props.scrollPaddingEnd;
127
127
 
128
+ /* v8 ignore start -- @preserve */
128
129
  const startX = typeof pStart === 'object'
129
130
  ? (pStart.x || 0)
130
131
  : (props.direction === 'horizontal' ? (pStart || 0) : 0);
@@ -138,6 +139,7 @@ const virtualScrollProps = computed(() => {
138
139
  const endY = typeof pEnd === 'object'
139
140
  ? (pEnd.y || 0)
140
141
  : (props.direction !== 'horizontal' ? (pEnd || 0) : 0);
142
+ /* v8 ignore stop -- @preserve */
141
143
 
142
144
  return {
143
145
  items: props.items,
@@ -233,6 +235,7 @@ watch(scrollDetails, (details, oldDetails) => {
233
235
  });
234
236
 
235
237
  watch(isHydrated, (hydrated) => {
238
+ /* v8 ignore else -- @preserve */
236
239
  if (hydrated) {
237
240
  emit('visibleRangeChange', {
238
241
  start: scrollDetails.value.range.start,
@@ -243,10 +246,12 @@ watch(isHydrated, (hydrated) => {
243
246
  }
244
247
  }, { once: true });
245
248
 
249
+ /* v8 ignore next 2 -- @preserve */
246
250
  const hostResizeObserver = typeof window === 'undefined'
247
251
  ? null
248
252
  : new ResizeObserver(updateHostOffset);
249
253
 
254
+ /* v8 ignore next 2 -- @preserve */
250
255
  const itemResizeObserver = typeof window === 'undefined'
251
256
  ? null
252
257
  : new ResizeObserver((entries) => {
@@ -278,11 +283,13 @@ const itemResizeObserver = typeof window === 'undefined'
278
283
  }
279
284
  }
280
285
 
286
+ /* v8 ignore else -- @preserve */
281
287
  if (updates.length > 0) {
282
288
  updateItemSizes(updates);
283
289
  }
284
290
  });
285
291
 
292
+ /* v8 ignore next 2 -- @preserve */
286
293
  const extraResizeObserver = typeof window === 'undefined'
287
294
  ? null
288
295
  : new ResizeObserver(() => {
@@ -292,6 +299,7 @@ const extraResizeObserver = typeof window === 'undefined'
292
299
  });
293
300
 
294
301
  watch(headerRef, (newEl, oldEl) => {
302
+ /* v8 ignore if -- @preserve */
295
303
  if (oldEl) {
296
304
  extraResizeObserver?.unobserve(oldEl);
297
305
  }
@@ -301,6 +309,7 @@ watch(headerRef, (newEl, oldEl) => {
301
309
  }, { immediate: true });
302
310
 
303
311
  watch(footerRef, (newEl, oldEl) => {
312
+ /* v8 ignore if -- @preserve */
304
313
  if (oldEl) {
305
314
  extraResizeObserver?.unobserve(oldEl);
306
315
  }
@@ -310,9 +319,9 @@ watch(footerRef, (newEl, oldEl) => {
310
319
  }, { immediate: true });
311
320
 
312
321
  const firstRenderedIndex = computed(() => renderedItems.value[ 0 ]?.index);
313
-
314
322
  watch(firstRenderedIndex, (newIdx, oldIdx) => {
315
323
  if (props.direction === 'both') {
324
+ /* v8 ignore else -- @preserve */
316
325
  if (oldIdx !== undefined) {
317
326
  const oldEl = itemRefs.get(oldIdx);
318
327
  if (oldEl) {
@@ -321,6 +330,7 @@ watch(firstRenderedIndex, (newIdx, oldIdx) => {
321
330
  }
322
331
  if (newIdx !== undefined) {
323
332
  const newEl = itemRefs.get(newIdx);
333
+ /* v8 ignore else -- @preserve */
324
334
  if (newEl) {
325
335
  newEl.querySelectorAll('[data-col-index]').forEach((c) => itemResizeObserver?.observe(c));
326
336
  }
@@ -329,6 +339,7 @@ watch(firstRenderedIndex, (newIdx, oldIdx) => {
329
339
  }, { flush: 'post' });
330
340
 
331
341
  onMounted(() => {
342
+ /* v8 ignore else -- @preserve */
332
343
  if (hostRef.value) {
333
344
  hostResizeObserver?.observe(hostRef.value);
334
345
  }
@@ -339,8 +350,10 @@ onMounted(() => {
339
350
  }
340
351
 
341
352
  // Observe cells of the first rendered item
353
+ /* v8 ignore else -- @preserve */
342
354
  if (firstRenderedIndex.value !== undefined) {
343
355
  const el = itemRefs.get(firstRenderedIndex.value);
356
+ /* v8 ignore else -- @preserve */
344
357
  if (el) {
345
358
  el.querySelectorAll('[data-col-index]').forEach((c) => itemResizeObserver?.observe(c));
346
359
  }
@@ -362,6 +375,7 @@ function setItemRef(el: unknown, index: number) {
362
375
  itemResizeObserver?.observe(el as HTMLElement);
363
376
  } else {
364
377
  const oldEl = itemRefs.get(index);
378
+ /* v8 ignore else -- @preserve */
365
379
  if (oldEl) {
366
380
  itemResizeObserver?.unobserve(oldEl);
367
381
  itemRefs.delete(index);
@@ -385,10 +399,14 @@ function handleKeyDown(event: KeyboardEvent) {
385
399
  const lastItemIndex = props.items.length - 1;
386
400
  const lastColIndex = (props.columnCount || 0) > 0 ? props.columnCount - 1 : 0;
387
401
 
388
- if (isHorizontal && isVertical) {
389
- scrollToIndex(lastItemIndex, lastColIndex, 'end');
402
+ if (isHorizontal) {
403
+ if (isVertical) {
404
+ scrollToIndex(lastItemIndex, lastColIndex, 'end');
405
+ } else {
406
+ scrollToIndex(0, lastItemIndex, 'end');
407
+ }
390
408
  } else {
391
- scrollToIndex(0, lastItemIndex, 'end');
409
+ scrollToIndex(lastItemIndex, 0, 'end');
392
410
  }
393
411
  return;
394
412
  }
@@ -415,7 +433,7 @@ function handleKeyDown(event: KeyboardEvent) {
415
433
  if (event.key === 'PageUp') {
416
434
  event.preventDefault();
417
435
  scrollToOffset(
418
- isHorizontal ? scrollOffset.x - viewportSize.width : null,
436
+ !isVertical && isHorizontal ? scrollOffset.x - viewportSize.width : null,
419
437
  isVertical ? scrollOffset.y - viewportSize.height : null,
420
438
  );
421
439
  return;
@@ -423,7 +441,7 @@ function handleKeyDown(event: KeyboardEvent) {
423
441
  if (event.key === 'PageDown') {
424
442
  event.preventDefault();
425
443
  scrollToOffset(
426
- isHorizontal ? scrollOffset.x + viewportSize.width : null,
444
+ !isVertical && isHorizontal ? scrollOffset.x + viewportSize.width : null,
427
445
  isVertical ? scrollOffset.y + viewportSize.height : null,
428
446
  );
429
447
  }