virtua 0.50.2 → 0.50.3

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.
@@ -7,8 +7,10 @@
7
7
  UPDATE_SCROLL_END_EVENT,
8
8
  UPDATE_SCROLL_EVENT,
9
9
  UPDATE_VIRTUAL_STATE,
10
- createResizer,
11
- createScroller,
10
+ createContainerDriver,
11
+ scrollTo as _scrollTo,
12
+ scrollBy as _scrollBy,
13
+ scrollToIndex as _scrollToIndex,
12
14
  createVirtualStore,
13
15
  getScrollSize as _getScrollSize,
14
16
  sort,
@@ -49,8 +51,7 @@
49
51
  cache,
50
52
  !itemSize,
51
53
  );
52
- const resizer = createResizer(store, horizontal);
53
- const scroller = createScroller(store, horizontal);
54
+ const driver = createContainerDriver(store, horizontal);
54
55
  store.$subscribe(UPDATE_VIRTUAL_STATE, () => {
55
56
  stateVersion = store.$getStateVersion();
56
57
  });
@@ -70,7 +71,7 @@
70
71
  let range = $derived(stateVersion && store.$getRange(bufferSize));
71
72
  let isScrolling = $derived(stateVersion && store.$isScrolling());
72
73
  let totalSize = $derived(stateVersion && store.$getTotalSize());
73
- let negative = $derived(stateVersion && scroller.$isNegative());
74
+ let negative = $derived(stateVersion && driver.$isNegative());
74
75
 
75
76
  let indexes = $derived.by(() => {
76
77
  // https://github.com/inokawa/virtua/pull/847
@@ -107,15 +108,7 @@
107
108
  tick().then(() => {
108
109
  // https://github.com/inokawa/virtua/pull/914
109
110
  if (unmounted) return;
110
- const assignRef = (scrollable: HTMLElement) => {
111
- resizer.$observeRoot(scrollable);
112
- scroller.$observe(container, scrollable);
113
- };
114
- if (scrollRef) {
115
- assignRef(scrollRef);
116
- } else {
117
- assignRef(container.parentElement!);
118
- }
111
+ driver.$observe(container, scrollRef);
119
112
  });
120
113
  return () => {
121
114
  unmounted = true;
@@ -123,8 +116,7 @@
123
116
  });
124
117
  onDestroy(() => {
125
118
  store.$dispose();
126
- resizer.$dispose();
127
- scroller.$dispose();
119
+ driver.$dispose();
128
120
  });
129
121
 
130
122
  $effect.pre(() => {
@@ -143,7 +135,7 @@
143
135
  $effect(() => {
144
136
  if (prevStateVersion === stateVersion) return;
145
137
  prevStateVersion = stateVersion;
146
- scroller.$fixScrollJump();
138
+ driver.$fixScrollJump();
147
139
  });
148
140
 
149
141
  export const getCache =
@@ -162,12 +154,14 @@
162
154
  store.$getItemOffset satisfies VirtualizerHandle["getItemOffset"] as VirtualizerHandle["getItemOffset"];
163
155
  export const getItemSize =
164
156
  store.$getItemSize satisfies VirtualizerHandle["getItemSize"] as VirtualizerHandle["getItemSize"];
165
- export const scrollToIndex =
166
- scroller.$scrollToIndex satisfies VirtualizerHandle["scrollToIndex"] as VirtualizerHandle["scrollToIndex"];
167
- export const scrollTo =
168
- scroller.$scrollTo satisfies VirtualizerHandle["scrollTo"] as VirtualizerHandle["scrollTo"];
169
- export const scrollBy =
170
- scroller.$scrollBy satisfies VirtualizerHandle["scrollBy"] as VirtualizerHandle["scrollBy"];
157
+ export const scrollToIndex: VirtualizerHandle["scrollToIndex"] = (
158
+ index,
159
+ opts,
160
+ ) => _scrollToIndex(driver, store, index, opts);
161
+ export const scrollTo: VirtualizerHandle["scrollTo"] = (offset) =>
162
+ _scrollTo(driver, offset);
163
+ export const scrollBy: VirtualizerHandle["scrollBy"] = (offset) =>
164
+ _scrollBy(driver, store, offset);
171
165
 
172
166
  let containerStyle = $derived(
173
167
  styleToString({
@@ -198,7 +192,7 @@
198
192
  hide={stateVersion && store.$isUnmeasuredItem(index)}
199
193
  {horizontal}
200
194
  {isSSR}
201
- resizer={resizer.$observeItem}
195
+ resizer={driver.$observeItem}
202
196
  itemProps={itemProps?.({ item, index })}
203
197
  />
204
198
  {/each}
@@ -8,8 +8,8 @@
8
8
  UPDATE_VIRTUAL_STATE,
9
9
  createVirtualStore,
10
10
  getScrollSize as _getScrollSize,
11
- createWindowResizer,
12
- createWindowScroller,
11
+ createWindowDriver,
12
+ scrollToIndex as _scrollToIndex,
13
13
  } from "../core/index.js";
14
14
  import { defaultGetKey, styleToString } from "./utils.js";
15
15
  import ListItem from "./ListItem.svelte";
@@ -40,8 +40,7 @@
40
40
  cache,
41
41
  !itemSize,
42
42
  );
43
- const resizer = createWindowResizer(store, horizontal);
44
- const scroller = createWindowScroller(store, horizontal);
43
+ const driver = createWindowDriver(store, horizontal);
45
44
  store.$subscribe(UPDATE_VIRTUAL_STATE, () => {
46
45
  stateVersion = store.$getStateVersion();
47
46
  });
@@ -60,7 +59,7 @@
60
59
  let range = $derived(stateVersion && store.$getRange(bufferSize));
61
60
  let isScrolling = $derived(stateVersion && store.$isScrolling());
62
61
  let totalSize = $derived(stateVersion && store.$getTotalSize());
63
- let negative = $derived(stateVersion && scroller.$isNegative());
62
+ let negative = $derived(stateVersion && driver.$isNegative());
64
63
 
65
64
  let indexes = $derived.by(() => {
66
65
  // https://github.com/inokawa/virtua/pull/847
@@ -77,13 +76,11 @@
77
76
  });
78
77
 
79
78
  onMount(() => {
80
- resizer.$observeRoot(containerRef!);
81
- scroller.$observe(containerRef!);
79
+ driver.$observe(containerRef!);
82
80
  });
83
81
  onDestroy(() => {
84
82
  store.$dispose();
85
- resizer.$dispose();
86
- scroller.$dispose();
83
+ driver.$dispose();
87
84
  });
88
85
 
89
86
  $effect.pre(() => {
@@ -96,7 +93,7 @@
96
93
  $effect(() => {
97
94
  if (prevStateVersion === stateVersion) return;
98
95
  prevStateVersion = stateVersion;
99
- scroller.$fixScrollJump();
96
+ driver.$fixScrollJump();
100
97
  });
101
98
 
102
99
  export const getCache =
@@ -111,8 +108,10 @@
111
108
  store.$getItemOffset satisfies WindowVirtualizerHandle["getItemOffset"] as WindowVirtualizerHandle["getItemOffset"];
112
109
  export const getItemSize =
113
110
  store.$getItemSize satisfies WindowVirtualizerHandle["getItemSize"] as WindowVirtualizerHandle["getItemSize"];
114
- export const scrollToIndex =
115
- scroller.$scrollToIndex satisfies WindowVirtualizerHandle["scrollToIndex"] as WindowVirtualizerHandle["scrollToIndex"];
111
+ export const scrollToIndex: WindowVirtualizerHandle["scrollToIndex"] = (
112
+ index,
113
+ opts,
114
+ ) => _scrollToIndex(driver, store, index, opts);
116
115
 
117
116
  let containerStyle = $derived(
118
117
  styleToString({
@@ -142,7 +141,7 @@
142
141
  offset={stateVersion && store.$getItemOffset(index, negative)}
143
142
  hide={stateVersion && store.$isUnmeasuredItem(index)}
144
143
  {horizontal}
145
- resizer={resizer.$observeItem}
144
+ resizer={driver.$observeItem}
146
145
  />
147
146
  {/each}
148
147
  </div>