@streamscloud/kit 0.94.9 → 0.95.0

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,10 +1,11 @@
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', direction = 'down', children, showLoading = false, loading, retry } = $props();
4
+ let { loadMore, container = null, rootMargin = '200px', 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);
8
+ let root = $state(null);
8
9
  let paginationTrigger = $state(null);
9
10
  let itemsContainer = $state(null);
10
11
  $effect(() => {
@@ -20,7 +21,7 @@ $effect(() => {
20
21
  void onLoadMore();
21
22
  }
22
23
  }, {
23
- root: container,
24
+ root: container === 'self' ? root : container,
24
25
  rootMargin
25
26
  });
26
27
  // Re-observe trigger on container resize to force IntersectionObserver
@@ -52,13 +53,17 @@ const onRetry = () => {
52
53
  };
53
54
  </script>
54
55
 
55
- {#snippet loadingEnd()}
56
+ <div class="infinite-scroll" bind:this={root}>
57
+ <div class="infinite-scroll__items" bind:this={itemsContainer}>
58
+ {@render children()}
59
+ </div>
60
+
56
61
  <div class="infinite-scroll__pagination-trigger" bind:this={paginationTrigger}></div>
57
62
  {#if isLoading}
58
63
  {#if loading}
59
64
  {@render loading()}
60
65
  {:else if showLoading}
61
- <div class="infinite-scroll__loading-container" class:infinite-scroll__loading-container--up={direction === 'up'}>
66
+ <div class="infinite-scroll__loading-container">
62
67
  <Spinner timeout={500} />
63
68
  </div>
64
69
  {/if}
@@ -71,20 +76,6 @@ const onRetry = () => {
71
76
  </div>
72
77
  {/if}
73
78
  {/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}
88
79
  </div>
89
80
 
90
81
  <!--
@@ -95,31 +86,30 @@ Pairs with `core/data-loaders` (`CursorDataLoader`, `PageDataLoader`, `CursorDat
95
86
 
96
87
  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.
97
88
 
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.
89
+ A history that loads upward (a chat) makes the component its own scroller laid out bottom-up: `display: flex`, `flex-direction: column-reverse`, `overflow-y: auto` through the properties below, with `container="self"`. The sentinel then sits at the top, the list opens at its end, older batches keep the view in place, and a reader at the end follows new items. The children keep their own order — lay them out bottom-up too to pass them newest first. The built-in `showLoading` spinner stays at the bottom edge; pass a `loading` snippet instead, which sits next to the sentinel.
99
90
 
100
91
  ### CSS Custom Properties
101
92
  | Property | Description | Default |
102
93
  |---|---|---|
103
94
  | `--sc-kit--infinite-scroll--display` | Display mode for root and items container | `block` |
104
- | `--sc-kit--infinite-scroll--flex` | Flex shorthand for root and items container | `initial`; `none` with `direction="up"` |
95
+ | `--sc-kit--infinite-scroll--flex` | Flex shorthand for root and items container | `initial` |
96
+ | `--sc-kit--infinite-scroll--flex-direction` | Flex direction of the root (`column-reverse` puts the sentinel on top) | `column` |
105
97
  | `--sc-kit--infinite-scroll--overflow-y` | Vertical overflow behavior | `initial` |
106
98
  -->
107
99
 
108
100
  <style>.infinite-scroll {
109
101
  --_infinite-scroll--display: var(--sc-kit--infinite-scroll--display, block);
110
102
  --_infinite-scroll--flex: var(--sc-kit--infinite-scroll--flex, initial);
103
+ --_infinite-scroll--flex-direction: var(--sc-kit--infinite-scroll--flex-direction, column);
111
104
  --_infinite-scroll--overflow-y: var(--sc-kit--infinite-scroll--overflow-y, initial);
112
105
  display: var(--_infinite-scroll--display);
113
- flex-direction: column;
106
+ flex-direction: var(--_infinite-scroll--flex-direction);
114
107
  flex: var(--_infinite-scroll--flex);
115
108
  overflow-y: var(--_infinite-scroll--overflow-y);
116
109
  min-height: 2.625em;
117
110
  position: relative;
118
111
  width: 100%;
119
112
  }
120
- .infinite-scroll--up {
121
- --_infinite-scroll--flex: var(--sc-kit--infinite-scroll--flex, none);
122
- }
123
113
  .infinite-scroll__items {
124
114
  display: var(--_infinite-scroll--display);
125
115
  flex-direction: column;
@@ -134,10 +124,6 @@ The component never reorders anything: it renders `children` as given and only d
134
124
  left: 50%;
135
125
  transform: translateX(-50%);
136
126
  }
137
- .infinite-scroll__loading-container--up {
138
- top: 0.3125em;
139
- bottom: auto;
140
- }
141
127
  .infinite-scroll__retry {
142
128
  display: flex;
143
129
  justify-content: center;
@@ -11,18 +11,19 @@ type Props = {
11
11
  * and leaves the sentinel armed through every failure.
12
12
  */
13
13
  loadMore: LoadMoreSource;
14
- /** Scroll ancestor used as the IntersectionObserver root. Required when the viewport differs from the scrolling container. */
15
- container?: HTMLElement | null;
16
- /** IntersectionObserver `rootMargin`. Default `'200px'` — fires the load that far before the reader reaches the loading end. */
17
- rootMargin?: string;
18
14
  /**
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'
15
+ * The scrolling element `rootMargin` is measured against: a scroll ancestor, `'self'` when this component scrolls on its own
16
+ * (`--sc-kit--infinite-scroll--overflow-y`), or `null` for the viewport.
17
+ * @default null
22
18
  */
23
- direction?: 'down' | 'up';
19
+ container?: HTMLElement | 'self' | null;
20
+ /** IntersectionObserver `rootMargin`. Default `'200px'` — fires the load that far before the reader reaches the sentinel. */
21
+ rootMargin?: string;
24
22
  children: Snippet;
25
- /** Shows the kit `Spinner` while a batch loads. Off by default — the list owner usually renders its own loading state. */
23
+ /**
24
+ * Shows the kit `Spinner` while a batch loads, pinned to the root's bottom edge whatever the flex direction — a list loading at the top passes
25
+ * `loading` instead. Off by default — the list owner usually renders its own loading state.
26
+ */
26
27
  showLoading?: boolean;
27
28
  /** Custom loading indicator snippet. Passing it turns the indicator on regardless of `showLoading`. */
28
29
  loading?: Snippet;
@@ -36,13 +37,14 @@ type Props = {
36
37
  *
37
38
  * 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.
38
39
  *
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
+ * A history that loads upward (a chat) makes the component its own scroller laid out bottom-up: `display: flex`, `flex-direction: column-reverse`, `overflow-y: auto` through the properties below, with `container="self"`. The sentinel then sits at the top, the list opens at its end, older batches keep the view in place, and a reader at the end follows new items. The children keep their own order — lay them out bottom-up too to pass them newest first. The built-in `showLoading` spinner stays at the bottom edge; pass a `loading` snippet instead, which sits next to the sentinel.
40
41
  *
41
42
  * ### CSS Custom Properties
42
43
  * | Property | Description | Default |
43
44
  * |---|---|---|
44
45
  * | `--sc-kit--infinite-scroll--display` | Display mode for root and items container | `block` |
45
- * | `--sc-kit--infinite-scroll--flex` | Flex shorthand for root and items container | `initial`; `none` with `direction="up"` |
46
+ * | `--sc-kit--infinite-scroll--flex` | Flex shorthand for root and items container | `initial` |
47
+ * | `--sc-kit--infinite-scroll--flex-direction` | Flex direction of the root (`column-reverse` puts the sentinel on top) | `column` |
46
48
  * | `--sc-kit--infinite-scroll--overflow-y` | Vertical overflow behavior | `initial` |
47
49
  */
48
50
  declare const Cmp: import("svelte").Component<Props, {}, "">;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamscloud/kit",
3
- "version": "0.94.9",
3
+ "version": "0.95.0",
4
4
  "author": "StreamsCloud",
5
5
  "repository": {
6
6
  "type": "git",