Skip to content

Commit e875753

Browse files
committed
refactor: first beta
1 parent cec6387 commit e875753

File tree

16 files changed

+73
-1041
lines changed

16 files changed

+73
-1041
lines changed

KNOWN-ISSUES.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22

33
For now it breaks Svelte preview REPL as it can't compile ts on the fly
44

5-
[ ] Problem with focus positioning on the edge size

src/comp/RTLToggle.svelte

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
import ToggleButton from './ToggleButton.svelte';
33
44
let { isRTL = $bindable() }: { isRTL: boolean } = $props();
5+
6+
function clicked() {
7+
document.documentElement.dir = isRTL ? 'rtl' : 'ltr';
8+
}
59
</script>
610

711
<div class="input-output-toggle">
812
Direction:
913
<span aria-hidden="true">LTR</span>
10-
<ToggleButton bind:pressed={isRTL} label="RTL direction" />
14+
<ToggleButton bind:pressed={isRTL} label="RTL direction" onclick={clicked} />
1115
<span aria-hidden="true">RTL</span>
1216
</div>
1317

src/comp/ToggleButton.svelte

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
<script lang="ts">
22
let {
33
pressed = $bindable(),
4-
label
4+
label,
5+
onclick
56
}: {
67
pressed: boolean;
78
label: string;
9+
onclick?: Function;
810
} = $props();
11+
12+
function clicked() {
13+
pressed = !pressed;
14+
onclick?.();
15+
}
916
</script>
1017

11-
<button aria-pressed={pressed ? 'true' : 'false'} onclick={() => (pressed = !pressed)}>
18+
<button aria-pressed={pressed ? 'true' : 'false'} onclick={clicked}>
1219
<span style="display: none;">{label}</span>
1320
</button>
1421

src/lib/new/NewPositionManager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ export default class SizeAndPositionManager {
237237
const maxOffset = offset + containerSize;
238238
let startIdx = this.findNearestItem(offset);
239239

240-
if (startIdx === undefined) {
241-
throw Error(`Invalid offset ${offset} specified`);
242-
}
240+
// if (startIdx === undefined) {
241+
// throw Error(`Invalid offset ${offset} specified`);
242+
// }
243243

244244
const datum = this.getSizeAndPositionForIndex(startIdx);
245245
offset = datum.offset + datum.size;

src/lib/new/VirtualListNew.svelte

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
let clientWidth: number = $state(0);
150150
151151
// viewport overfetch trigger in px
152-
let overfetchBufferInPx: number = 100;
152+
// let overfetchBufferInPx: number = 100;
153153
154154
let itemKey: 'index' | ((item: any, index: number) => any);
155155
@@ -270,8 +270,12 @@
270270
271271
$effect(() => {
272272
console.log('onVisibleRangeUpdate');
273-
// const vr = getVisibleRange(isHorizontal ? clientWidth : clientHeight, offset);
274-
onVisibleRangeUpdate?.({ start: startIdx, end: endIdx });
273+
274+
if (onVisibleRangeUpdate) {
275+
const vr = getVisibleRange(isHorizontal ? clientWidth : clientHeight, curState.offset);
276+
//onVisibleRangeUpdate({ start: startIdx, end: endIdx });
277+
onVisibleRangeUpdate(vr);
278+
}
275279
});
276280
277281
//TODO see if effect.pre not a better option
@@ -361,8 +365,6 @@
361365
//resetItem
362366
lastMeasuredIndex = Math.min(lastMeasuredIndex, startIndex - 1);
363367
refreshOffsets();
364-
// const vr = getVisibleRange(isHorizontal ? clientWidth : clientHeight, offset);
365-
// onVisibleRangeUpdate?.({ start: vr.start, end: vr.end });
366368
}
367369
368370
function onscroll(event: Event): void {
@@ -386,22 +388,22 @@
386388
}
387389
388390
// return the index of the starting boundary
389-
function getStart(): number {
390-
const startPosition =
391-
getScroll(listContainer) - getPaddingStart(listContainer) - overfetchBufferInPx;
392-
return findNearestItem(startPosition);
393-
}
391+
// function getStart(): number {
392+
// const startPosition =
393+
// getScroll(listContainer) - getPaddingStart(listContainer) - overfetchBufferInPx;
394+
// return findNearestItem(startPosition);
395+
// }
394396
395397
// return the index of the closing boundary
396-
function getEnd() {
397-
const endPosition =
398-
getScroll(listContainer) -
399-
getPaddingStart(listContainer) +
400-
getClientSize(listContainer) +
401-
overfetchBufferInPx;
402-
403-
return findNearestItem(endPosition);
404-
}
398+
// function getEnd() {
399+
// const endPosition =
400+
// getScroll(listContainer) -
401+
// getPaddingStart(listContainer) +
402+
// getClientSize(listContainer) +
403+
// overfetchBufferInPx;
404+
405+
// return findNearestItem(endPosition);
406+
// }
405407
406408
function getOffsetForIndex(
407409
index: number,
@@ -546,8 +548,10 @@
546548
avgSizeInPx = getAvgSize();
547549
}
548550
549-
startIdx = getStart();
550-
endIdx = getEnd();
551+
const vr = getVisibleRange(isHorizontal ? clientWidth : clientHeight, curState.offset,3);
552+
553+
startIdx = vr.start;
554+
endIdx = vr.end;
551555
552556
let vi0 = 0;
553557
@@ -617,7 +621,11 @@
617621
}
618622
619623
// returns an index range
620-
function getVisibleRange(containerSize: number = 0, scrollbarOffset: number) {
624+
function getVisibleRange(
625+
containerSize: number = 0,
626+
scrollbarOffset: number,
627+
windowOverPaddingCount: number = 0
628+
) {
621629
const totalSize = totalViewportSize;
622630
623631
if (totalSize === 0) return { start: 0, end: 0 };
@@ -637,6 +645,11 @@
637645
offset += sizes[endIdx];
638646
}
639647
648+
if (windowOverPaddingCount > 0) {
649+
startIdx = Math.max(0, startIdx - windowOverPaddingCount);
650+
endIdx = Math.min(endIdx + windowOverPaddingCount, items.length - 1);
651+
}
652+
640653
return {
641654
start: startIdx,
642655
end: endIdx

0 commit comments

Comments
 (0)