@streamscloud/kit 0.94.8 → 0.94.9
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts">import { Button } from '../button';
|
|
2
2
|
import { Spinner } from '../spinner';
|
|
3
3
|
import { InfiniteScrollLocalization } from './infinite-scroll-localization';
|
|
4
|
-
let { loadMore, container = null, rootMargin = '200px', children, showLoading = false, loading, retry } = $props();
|
|
4
|
+
let { loadMore, container = null, rootMargin = '200px', direction = 'down', children, showLoading = false, loading, retry } = $props();
|
|
5
5
|
const localization = new InfiniteScrollLocalization();
|
|
6
6
|
const source = $derived(typeof loadMore === 'function' ? { loadMore, failed: false, canLoadMore: true } : loadMore);
|
|
7
7
|
let isLoading = $state(false);
|
|
@@ -52,17 +52,13 @@ const onRetry = () => {
|
|
|
52
52
|
};
|
|
53
53
|
</script>
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
<div class="infinite-scroll__items" bind:this={itemsContainer}>
|
|
57
|
-
{@render children()}
|
|
58
|
-
</div>
|
|
59
|
-
|
|
55
|
+
{#snippet loadingEnd()}
|
|
60
56
|
<div class="infinite-scroll__pagination-trigger" bind:this={paginationTrigger}></div>
|
|
61
57
|
{#if isLoading}
|
|
62
58
|
{#if loading}
|
|
63
59
|
{@render loading()}
|
|
64
60
|
{:else if showLoading}
|
|
65
|
-
<div class="infinite-scroll__loading-container">
|
|
61
|
+
<div class="infinite-scroll__loading-container" class:infinite-scroll__loading-container--up={direction === 'up'}>
|
|
66
62
|
<Spinner timeout={500} />
|
|
67
63
|
</div>
|
|
68
64
|
{/if}
|
|
@@ -75,6 +71,20 @@ const onRetry = () => {
|
|
|
75
71
|
</div>
|
|
76
72
|
{/if}
|
|
77
73
|
{/if}
|
|
74
|
+
{/snippet}
|
|
75
|
+
|
|
76
|
+
<div class="infinite-scroll" class:infinite-scroll--up={direction === 'up'}>
|
|
77
|
+
{#if direction === 'up'}
|
|
78
|
+
{@render loadingEnd()}
|
|
79
|
+
{/if}
|
|
80
|
+
|
|
81
|
+
<div class="infinite-scroll__items" bind:this={itemsContainer}>
|
|
82
|
+
{@render children()}
|
|
83
|
+
</div>
|
|
84
|
+
|
|
85
|
+
{#if direction === 'down'}
|
|
86
|
+
{@render loadingEnd()}
|
|
87
|
+
{/if}
|
|
78
88
|
</div>
|
|
79
89
|
|
|
80
90
|
<!--
|
|
@@ -85,11 +95,13 @@ Pairs with `core/data-loaders` (`CursorDataLoader`, `PageDataLoader`, `CursorDat
|
|
|
85
95
|
|
|
86
96
|
Passing the loader itself — `loadMore={loader}` instead of `loadMore={loader.loadMore}` — disarms the sentinel while the loader reports `failed`, so a failing backend is not asked again on its own and the already-loaded list is kept. The manual continue appears only when the loader can still continue (`resumeAfterFailure`); a loader that closed its list on the failure ends silently, as it does at the natural end. A successful retry re-arms the sentinel on its own.
|
|
87
97
|
|
|
98
|
+
The component never reorders anything: it renders `children` as given and only decides on which side of them the sentinel sits. With `direction="up"` the consumer renders oldest → newest (a newest-first loader's items reversed) inside a scroll container set to `display: flex; flex-direction: column-reverse` with this component as its only child. Such a container scrolls from the bottom, so the list opens at its end, batches added above leave the view where it was, and a reader at the end keeps seeing new items appended below.
|
|
99
|
+
|
|
88
100
|
### CSS Custom Properties
|
|
89
101
|
| Property | Description | Default |
|
|
90
102
|
|---|---|---|
|
|
91
103
|
| `--sc-kit--infinite-scroll--display` | Display mode for root and items container | `block` |
|
|
92
|
-
| `--sc-kit--infinite-scroll--flex` | Flex shorthand for root and items container | `initial` |
|
|
104
|
+
| `--sc-kit--infinite-scroll--flex` | Flex shorthand for root and items container | `initial`; `none` with `direction="up"` |
|
|
93
105
|
| `--sc-kit--infinite-scroll--overflow-y` | Vertical overflow behavior | `initial` |
|
|
94
106
|
-->
|
|
95
107
|
|
|
@@ -105,6 +117,9 @@ Passing the loader itself — `loadMore={loader}` instead of `loadMore={loader.l
|
|
|
105
117
|
position: relative;
|
|
106
118
|
width: 100%;
|
|
107
119
|
}
|
|
120
|
+
.infinite-scroll--up {
|
|
121
|
+
--_infinite-scroll--flex: var(--sc-kit--infinite-scroll--flex, none);
|
|
122
|
+
}
|
|
108
123
|
.infinite-scroll__items {
|
|
109
124
|
display: var(--_infinite-scroll--display);
|
|
110
125
|
flex-direction: column;
|
|
@@ -119,6 +134,10 @@ Passing the loader itself — `loadMore={loader}` instead of `loadMore={loader.l
|
|
|
119
134
|
left: 50%;
|
|
120
135
|
transform: translateX(-50%);
|
|
121
136
|
}
|
|
137
|
+
.infinite-scroll__loading-container--up {
|
|
138
|
+
top: 0.3125em;
|
|
139
|
+
bottom: auto;
|
|
140
|
+
}
|
|
122
141
|
.infinite-scroll__retry {
|
|
123
142
|
display: flex;
|
|
124
143
|
justify-content: center;
|
|
@@ -13,8 +13,14 @@ type Props = {
|
|
|
13
13
|
loadMore: LoadMoreSource;
|
|
14
14
|
/** Scroll ancestor used as the IntersectionObserver root. Required when the viewport differs from the scrolling container. */
|
|
15
15
|
container?: HTMLElement | null;
|
|
16
|
-
/** IntersectionObserver `rootMargin`. Default `'200px'` — fires the load
|
|
16
|
+
/** IntersectionObserver `rootMargin`. Default `'200px'` — fires the load that far before the reader reaches the loading end. */
|
|
17
17
|
rootMargin?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Which end of the list loads more. `'up'` puts the sentinel above the items for a newest-at-the-bottom history; the scroll container must be a
|
|
20
|
+
* `column-reverse` flex box with this component as its only child, so it starts at the end and keeps the view in place as batches land above.
|
|
21
|
+
* @default 'down'
|
|
22
|
+
*/
|
|
23
|
+
direction?: 'down' | 'up';
|
|
18
24
|
children: Snippet;
|
|
19
25
|
/** Shows the kit `Spinner` while a batch loads. Off by default — the list owner usually renders its own loading state. */
|
|
20
26
|
showLoading?: boolean;
|
|
@@ -30,11 +36,13 @@ type Props = {
|
|
|
30
36
|
*
|
|
31
37
|
* Passing the loader itself — `loadMore={loader}` instead of `loadMore={loader.loadMore}` — disarms the sentinel while the loader reports `failed`, so a failing backend is not asked again on its own and the already-loaded list is kept. The manual continue appears only when the loader can still continue (`resumeAfterFailure`); a loader that closed its list on the failure ends silently, as it does at the natural end. A successful retry re-arms the sentinel on its own.
|
|
32
38
|
*
|
|
39
|
+
* The component never reorders anything: it renders `children` as given and only decides on which side of them the sentinel sits. With `direction="up"` the consumer renders oldest → newest (a newest-first loader's items reversed) inside a scroll container set to `display: flex; flex-direction: column-reverse` with this component as its only child. Such a container scrolls from the bottom, so the list opens at its end, batches added above leave the view where it was, and a reader at the end keeps seeing new items appended below.
|
|
40
|
+
*
|
|
33
41
|
* ### CSS Custom Properties
|
|
34
42
|
* | Property | Description | Default |
|
|
35
43
|
* |---|---|---|
|
|
36
44
|
* | `--sc-kit--infinite-scroll--display` | Display mode for root and items container | `block` |
|
|
37
|
-
* | `--sc-kit--infinite-scroll--flex` | Flex shorthand for root and items container | `initial` |
|
|
45
|
+
* | `--sc-kit--infinite-scroll--flex` | Flex shorthand for root and items container | `initial`; `none` with `direction="up"` |
|
|
38
46
|
* | `--sc-kit--infinite-scroll--overflow-y` | Vertical overflow behavior | `initial` |
|
|
39
47
|
*/
|
|
40
48
|
declare const Cmp: import("svelte").Component<Props, {}, "">;
|