virtua 0.53.0 → 0.53.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.
@@ -15,6 +15,7 @@
15
15
  scrollTo as _scrollTo,
16
16
  scrollBy as _scrollBy,
17
17
  scrollToIndex as _scrollToIndex,
18
+ sort,
18
19
  } from "../core/index.js";
19
20
  import { defaultGetKey, isSameRange, styleToString } from "./utils.js";
20
21
  import MasonryItem from "./MasonryItem.svelte";
@@ -32,6 +33,7 @@
32
33
  gap: gapProp,
33
34
  itemSize,
34
35
  bufferSize,
36
+ keepMounted,
35
37
  cache,
36
38
  children,
37
39
  onscroll,
@@ -82,11 +84,23 @@
82
84
  const len = data.length;
83
85
  const [start, end] = range;
84
86
  const arr: number[] = [];
85
- for (let i = start; i <= end; i++) {
86
- // Guard for experimental.async: true, which runs the each block before $effect.pre
87
- // https://github.com/inokawa/virtua/pull/847
88
- if (i < len) {
89
- arr.push(i);
87
+ if (keepMounted) {
88
+ const mounted = new Set(keepMounted);
89
+ for (let i = start; i <= end; i++) {
90
+ mounted.add(i);
91
+ }
92
+ for (const index of sort([...mounted])) {
93
+ if (index < len) {
94
+ arr.push(index);
95
+ }
96
+ }
97
+ } else {
98
+ for (let i = start; i <= end; i++) {
99
+ // Guard for experimental.async: true, which runs the each block before $effect.pre
100
+ // https://github.com/inokawa/virtua/pull/847
101
+ if (i < len) {
102
+ arr.push(i);
103
+ }
90
104
  }
91
105
  }
92
106
  return arr;
@@ -39,6 +39,10 @@ export interface VMasonryProps<T> extends ViewportComponentAttributes {
39
39
  * @defaultValue 200
40
40
  */
41
41
  bufferSize?: number;
42
+ /**
43
+ * List of indexes that should be always mounted, even when off screen.
44
+ */
45
+ keepMounted?: readonly number[];
42
46
  /**
43
47
  * You can restore cache by passing a {@link CacheSnapshot} on mount. This is useful when you want to restore scroll position after navigation. The snapshot can be obtained from {@link VMasonryHandle.getCache}.
44
48
  *
@@ -76,6 +76,10 @@ export interface VMasonryProps<T> extends PublicProps {
76
76
  * @defaultValue 200
77
77
  */
78
78
  bufferSize?: number;
79
+ /**
80
+ * List of indexes that should be always mounted, even when off screen.
81
+ */
82
+ keepMounted?: readonly number[];
79
83
  /**
80
84
  * You can restore cache by passing a {@link CacheSnapshot} on mount. This is useful when you want to restore scroll position after navigation. The snapshot can be obtained from {@link VMasonryHandle.cache}.
81
85
  *
package/lib/vue/index.cjs CHANGED
@@ -1282,6 +1282,7 @@ e.defineComponent)(t => {
1282
1282
  gap: Number,
1283
1283
  itemSize: Number,
1284
1284
  bufferSize: Number,
1285
+ keepMounted: Array,
1285
1286
  cache: Object
1286
1287
  },
1287
1288
  emits: [ "scroll", "scrollEnd" ],
@@ -1408,14 +1409,13 @@ e.defineComponent)(t => {
1408
1409
  scrollTo: e => C(f, e),
1409
1410
  scrollBy: e => j(f, a, e)
1410
1411
  }), () => {
1411
- const o = _.value, r = [];
1412
- for (let [o, n] = p.value; o <= n; o++) {
1413
- const n = l.default({
1412
+ const o = _.value, r = [], n = o => {
1413
+ const r = l.default({
1414
1414
  item: t.data[o],
1415
1415
  index: o
1416
1416
  });
1417
- r.push((0, e.createVNode)(K, {
1418
- key: V(n, o),
1417
+ return (0, e.createVNode)(K, {
1418
+ key: V(r, o),
1419
1419
  ne: d,
1420
1420
  se: a,
1421
1421
  Be: u,
@@ -1423,8 +1423,15 @@ e.defineComponent)(t => {
1423
1423
  ce: t.data[o],
1424
1424
  ue: f.ee,
1425
1425
  le: o
1426
- }, null, 8, [ "ne", "se", "Be", "ie", "ce", "ue", "le" ]));
1427
- }
1426
+ }, null, 8, [ "ne", "se", "Be", "ie", "ce", "ue", "le" ]);
1427
+ };
1428
+ if (t.keepMounted) {
1429
+ const e = t.data.length, o = new Set(t.keepMounted);
1430
+ for (let [e, t] = p.value; e <= t; e++) o.add(e);
1431
+ c([ ...o ]).forEach(t => {
1432
+ t < e && r.push(n(t));
1433
+ });
1434
+ } else for (let [e, t] = p.value; e <= t; e++) r.push(n(e));
1428
1435
  return (0, e.createVNode)("div", {
1429
1436
  style: {
1430
1437
  display: "block",