virtua 0.50.1 → 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
  });
@@ -61,6 +62,8 @@
61
62
  onscrollend && onscrollend();
62
63
  });
63
64
 
65
+ let isSSR = $state(!!ssrCount);
66
+
64
67
  let containerRef: HTMLDivElement | undefined = $state();
65
68
 
66
69
  let stateVersion: StateVersion = $state(store.$getStateVersion());
@@ -68,7 +71,7 @@
68
71
  let range = $derived(stateVersion && store.$getRange(bufferSize));
69
72
  let isScrolling = $derived(stateVersion && store.$isScrolling());
70
73
  let totalSize = $derived(stateVersion && store.$getTotalSize());
71
- let negative = $derived(stateVersion && scroller.$isNegative());
74
+ let negative = $derived(stateVersion && driver.$isNegative());
72
75
 
73
76
  let indexes = $derived.by(() => {
74
77
  // https://github.com/inokawa/virtua/pull/847
@@ -97,21 +100,15 @@
97
100
  });
98
101
 
99
102
  onMount(() => {
103
+ isSSR = false;
104
+
100
105
  let unmounted = false;
101
106
  const container = containerRef!;
102
107
  // parent's ref may not exist on mount https://github.com/inokawa/virtua/issues/603 https://github.com/inokawa/virtua/issues/690
103
108
  tick().then(() => {
104
109
  // https://github.com/inokawa/virtua/pull/914
105
110
  if (unmounted) return;
106
- const assignRef = (scrollable: HTMLElement) => {
107
- resizer.$observeRoot(scrollable);
108
- scroller.$observe(container, scrollable);
109
- };
110
- if (scrollRef) {
111
- assignRef(scrollRef);
112
- } else {
113
- assignRef(container.parentElement!);
114
- }
111
+ driver.$observe(container, scrollRef);
115
112
  });
116
113
  return () => {
117
114
  unmounted = true;
@@ -119,8 +116,7 @@
119
116
  });
120
117
  onDestroy(() => {
121
118
  store.$dispose();
122
- resizer.$dispose();
123
- scroller.$dispose();
119
+ driver.$dispose();
124
120
  });
125
121
 
126
122
  $effect.pre(() => {
@@ -139,7 +135,7 @@
139
135
  $effect(() => {
140
136
  if (prevStateVersion === stateVersion) return;
141
137
  prevStateVersion = stateVersion;
142
- scroller.$fixScrollJump();
138
+ driver.$fixScrollJump();
143
139
  });
144
140
 
145
141
  export const getCache =
@@ -158,12 +154,14 @@
158
154
  store.$getItemOffset satisfies VirtualizerHandle["getItemOffset"] as VirtualizerHandle["getItemOffset"];
159
155
  export const getItemSize =
160
156
  store.$getItemSize satisfies VirtualizerHandle["getItemSize"] as VirtualizerHandle["getItemSize"];
161
- export const scrollToIndex =
162
- scroller.$scrollToIndex satisfies VirtualizerHandle["scrollToIndex"] as VirtualizerHandle["scrollToIndex"];
163
- export const scrollTo =
164
- scroller.$scrollTo satisfies VirtualizerHandle["scrollTo"] as VirtualizerHandle["scrollTo"];
165
- export const scrollBy =
166
- 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);
167
165
 
168
166
  let containerStyle = $derived(
169
167
  styleToString({
@@ -193,7 +191,8 @@
193
191
  offset={stateVersion && store.$getItemOffset(index, negative)}
194
192
  hide={stateVersion && store.$isUnmeasuredItem(index)}
195
193
  {horizontal}
196
- resizer={resizer.$observeItem}
194
+ {isSSR}
195
+ resizer={driver.$observeItem}
197
196
  itemProps={itemProps?.({ item, index })}
198
197
  />
199
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>
@@ -6,4 +6,4 @@ export type { VListProps, VListHandle } from './VList.type.js';
6
6
  export { default as Virtualizer } from './Virtualizer.svelte';
7
7
  export type { VirtualizerProps, VirtualizerHandle, } from './Virtualizer.type.js';
8
8
  export { default as WindowVirtualizer } from './WindowVirtualizer.svelte';
9
- export type { WindowVirtualizerProps } from './WindowVirtualizer.type.js';
9
+ export type { WindowVirtualizerProps, WindowVirtualizerHandle, } from './WindowVirtualizer.type.js';