@bazariodev/scrollback 0.0.0-stage → 1.0.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.
- package/CHANGELOG.md +24 -0
- package/LICENSE +21 -0
- package/README.md +226 -2
- package/dist/constants.d.cts +61 -0
- package/dist/constants.d.ts +61 -0
- package/dist/index.cjs +3931 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +214 -0
- package/dist/index.d.ts +214 -0
- package/dist/index.js +3929 -0
- package/dist/index.js.map +1 -0
- package/package.json +71 -3
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import type { NAVIGATION_OUTCOME, NAVIGATION_TRIGGER } from "./constants.cjs";
|
|
2
|
+
|
|
3
|
+
type ValueOf<Values> = Values[keyof Values];
|
|
4
|
+
|
|
5
|
+
/** A mutable ref object. It is compatible with the `ref` prop of a React element. */
|
|
6
|
+
export interface ScrollbackRef<Value> {
|
|
7
|
+
current: Value;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** The minimum shape of a timeline item. */
|
|
11
|
+
export interface ScrollbackItem {
|
|
12
|
+
/** A unique, stable identifier. */
|
|
13
|
+
readonly id: string;
|
|
14
|
+
/** The item time. A larger value is newer. */
|
|
15
|
+
readonly time: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** The identifier type of an item type. */
|
|
19
|
+
export type ItemIdOf<Item extends ScrollbackItem> = Item['id'];
|
|
20
|
+
|
|
21
|
+
/** The scroll state that a consumer can store and give back later. */
|
|
22
|
+
export interface ScrollbackMemory<Id extends string = string> {
|
|
23
|
+
/** The scroll offset of the container. */
|
|
24
|
+
scrollTop: number;
|
|
25
|
+
/** True while the reader follows the end of the timeline. */
|
|
26
|
+
atBottom: boolean;
|
|
27
|
+
/** The item that held the reading position. */
|
|
28
|
+
anchorItemId?: Id;
|
|
29
|
+
/** The distance from the top of the viewport to the anchor item. */
|
|
30
|
+
anchorOffsetFromViewportTop?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Size limits for the render window. Each value replaces its default. Each
|
|
35
|
+
* value must be a positive integer, or a `RangeError` is thrown. The first window
|
|
36
|
+
* is capped at `maxRenderedItems`. The reveal step is capped at half of `maxRenderedItems`.
|
|
37
|
+
*/
|
|
38
|
+
export interface ScrollbackLimits {
|
|
39
|
+
/** The number of items in one reveal step or server page. Capped at half of `maxRenderedItems`. Default: 30. */
|
|
40
|
+
pageSize?: number;
|
|
41
|
+
/** The number of items in the first window. Default: 60. */
|
|
42
|
+
initialPageSize?: number;
|
|
43
|
+
/** The maximum number of rendered items. Default: 150. */
|
|
44
|
+
maxRenderedItems?: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Distances in pixels. Each value replaces its default. */
|
|
48
|
+
export interface ScrollbackThresholds {
|
|
49
|
+
/** How close to the end counts as "at the bottom". Default: 56. */
|
|
50
|
+
atBottom?: number;
|
|
51
|
+
/** The smallest distance from a page boundary that starts a page load. Default: 480. */
|
|
52
|
+
prefetchMin?: number;
|
|
53
|
+
/** The largest distance from a page boundary that starts a page load. Default: 1200. */
|
|
54
|
+
prefetchMax?: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Settings for `navigateTo` and the initial target. Each value replaces its default. */
|
|
58
|
+
export interface ScrollbackNavigationSettings {
|
|
59
|
+
/** The number of older pages that a navigation without `time` searches. Default: 5. */
|
|
60
|
+
maxOlderPages?: number;
|
|
61
|
+
/** How long a navigated item stays highlighted, in milliseconds. Default: 1400. */
|
|
62
|
+
highlightDuration?: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Browser services that the engine can share with the rest of the page. */
|
|
66
|
+
export interface ScrollbackPlatform {
|
|
67
|
+
/** Watches the size of an element. Returns a stop function, or `null` when unsupported. */
|
|
68
|
+
observeResize?: (
|
|
69
|
+
element: Element,
|
|
70
|
+
listener: () => void,
|
|
71
|
+
) => (() => void) | null;
|
|
72
|
+
/** Schedules a keyed measurement. `read` returns the write function. Returns a cancel function. */
|
|
73
|
+
scheduleMeasurement?: (key: object, read: () => () => void) => () => void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The reason for a navigation. */
|
|
77
|
+
export type ScrollbackNavigationTrigger = ValueOf<typeof NAVIGATION_TRIGGER>;
|
|
78
|
+
|
|
79
|
+
/** The result of a navigation that finished. */
|
|
80
|
+
export type ScrollbackNavigationOutcome = Exclude<
|
|
81
|
+
ValueOf<typeof NAVIGATION_OUTCOME>,
|
|
82
|
+
typeof NAVIGATION_OUTCOME.SUPERSEDED
|
|
83
|
+
>;
|
|
84
|
+
|
|
85
|
+
/** A navigation that just started. */
|
|
86
|
+
export interface ScrollbackNavigation<Id extends string = string> {
|
|
87
|
+
/** The reason for the navigation. */
|
|
88
|
+
trigger: ScrollbackNavigationTrigger;
|
|
89
|
+
/** The target item identifier. */
|
|
90
|
+
id: Id;
|
|
91
|
+
/** The target item time, when the caller knows it. */
|
|
92
|
+
time?: number;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Options for `scrollToBottom`. */
|
|
96
|
+
export interface ScrollToBottomOptions {
|
|
97
|
+
/** The scroll behavior. Default: an instant jump. Use `'smooth'` to animate. */
|
|
98
|
+
behavior?: ScrollBehavior;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Options for `useScrollback`. */
|
|
102
|
+
export interface UseScrollbackOptions<Item extends ScrollbackItem> {
|
|
103
|
+
/** The cached history and the paging controls. */
|
|
104
|
+
source: {
|
|
105
|
+
/** The full cached history, oldest first. */
|
|
106
|
+
items: readonly Item[];
|
|
107
|
+
/** True while the first load runs. Default: `false`. */
|
|
108
|
+
isLoading?: boolean;
|
|
109
|
+
/** Paging controls for items older than the cache. */
|
|
110
|
+
older: {
|
|
111
|
+
/** True when the server has more older items. */
|
|
112
|
+
hasMore: boolean;
|
|
113
|
+
/** True while an older page loads. */
|
|
114
|
+
isLoading: boolean;
|
|
115
|
+
/** A number that changes each time an older page arrives. Any change counts. */
|
|
116
|
+
version: number;
|
|
117
|
+
/** Loads one older page. Resolves true when it added items. */
|
|
118
|
+
load: () => Promise<boolean>;
|
|
119
|
+
};
|
|
120
|
+
/** Loads history until the target is in the cache. Resolves true when found. */
|
|
121
|
+
loadThrough?: (target: Pick<Item, 'id' | 'time'>) => Promise<boolean>;
|
|
122
|
+
};
|
|
123
|
+
/** Items that the timeline must reach or keep rendered. */
|
|
124
|
+
targets?: {
|
|
125
|
+
/** Opens the timeline at this item. The engine anchors the window, scrolls, and highlights it. */
|
|
126
|
+
initialId?: Item['id'];
|
|
127
|
+
/** The time of `initialId`. It lets the engine load an uncached target. */
|
|
128
|
+
initialTime?: number;
|
|
129
|
+
/**
|
|
130
|
+
* Opens the window around this item when it is cached. The engine does not scroll to it.
|
|
131
|
+
* When the item is not cached, the window that exists stays as it is, and
|
|
132
|
+
* when no window exists, the default window opens.
|
|
133
|
+
*/
|
|
134
|
+
focusId?: Item['id'];
|
|
135
|
+
/** The item for read reporting. See `isReadTargetReached`. */
|
|
136
|
+
readId?: Item['id'];
|
|
137
|
+
};
|
|
138
|
+
/** Scroll memory input and output. */
|
|
139
|
+
memory?: {
|
|
140
|
+
/** The scroll state to restore on the first render. */
|
|
141
|
+
initial?: ScrollbackMemory<Item['id']>;
|
|
142
|
+
/** Called when the scroll state changes. */
|
|
143
|
+
onChange?: (memory: ScrollbackMemory<Item['id']>) => void;
|
|
144
|
+
};
|
|
145
|
+
/** Layout input. */
|
|
146
|
+
layout?: {
|
|
147
|
+
/** The height that an overlay covers at the end of the container. A change keeps a pinned tail in view. */
|
|
148
|
+
bottomInset?: number;
|
|
149
|
+
};
|
|
150
|
+
/** Returns true for a new last item that the view must follow, even when the reader is not pinned. */
|
|
151
|
+
followsAppend?: (item: Item) => boolean;
|
|
152
|
+
/** Size limits for the render window. */
|
|
153
|
+
limits?: ScrollbackLimits;
|
|
154
|
+
/** Distances for the bottom check and the page prefetch. */
|
|
155
|
+
thresholds?: ScrollbackThresholds;
|
|
156
|
+
/** Settings for navigation and highlight. */
|
|
157
|
+
navigation?: ScrollbackNavigationSettings;
|
|
158
|
+
/** Replacements for the shared browser services. */
|
|
159
|
+
platform?: ScrollbackPlatform;
|
|
160
|
+
/**
|
|
161
|
+
* Called when a navigation starts. The returned function, if any, is called once
|
|
162
|
+
* when the navigation ends. It is not called for a replaced navigation.
|
|
163
|
+
*/
|
|
164
|
+
onNavigation?: (
|
|
165
|
+
navigation: ScrollbackNavigation<Item['id']>,
|
|
166
|
+
) => ((outcome: ScrollbackNavigationOutcome) => void) | void;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** The value that `useScrollback` returns. */
|
|
170
|
+
export interface UseScrollbackResult<Item extends ScrollbackItem> {
|
|
171
|
+
/** The rendered window of items, oldest first. */
|
|
172
|
+
items: readonly Item[];
|
|
173
|
+
/** True while the engine waits for `targets.initialId`. */
|
|
174
|
+
isWaitingForInitialItem: boolean;
|
|
175
|
+
/** True while an older page loads. */
|
|
176
|
+
isLoadingOlder: boolean;
|
|
177
|
+
/** True when more older items exist, in the cache or on the server. */
|
|
178
|
+
hasMoreOlder: boolean;
|
|
179
|
+
/** True when newer items exist outside the rendered window. */
|
|
180
|
+
hasMoreNewer: boolean;
|
|
181
|
+
/**
|
|
182
|
+
* True while the reader follows the end of the timeline. Reader scrolling and
|
|
183
|
+
* commands set it. Layout changes keep it. It ends when newer items are outside
|
|
184
|
+
* the rendered window.
|
|
185
|
+
*/
|
|
186
|
+
isAtBottom: boolean;
|
|
187
|
+
/** True when the reader scrolled to the read target, or when the target is older than the rendered window. */
|
|
188
|
+
isReadTargetReached: boolean;
|
|
189
|
+
/** True while the initial target is not yet shown. */
|
|
190
|
+
isInitialTargetPending: boolean;
|
|
191
|
+
/** The identifier of the item that a navigation highlights. */
|
|
192
|
+
highlightedId: Item['id'] | undefined;
|
|
193
|
+
/** Attach to the scroll container. */
|
|
194
|
+
scrollContainerRef: ScrollbackRef<HTMLDivElement | null>;
|
|
195
|
+
/** Attach to the element that holds the item rows. */
|
|
196
|
+
itemListRef: ScrollbackRef<HTMLDivElement | null>;
|
|
197
|
+
/** Attach to an element before the list. It triggers older page loads. */
|
|
198
|
+
olderSentinelRef: ScrollbackRef<HTMLDivElement | null>;
|
|
199
|
+
/** Attach to an element after the list. It triggers newer reveals. */
|
|
200
|
+
newerSentinelRef: ScrollbackRef<HTMLDivElement | null>;
|
|
201
|
+
/** Give to the `onScroll` prop of the scroll container. */
|
|
202
|
+
onScroll: () => void;
|
|
203
|
+
/** Register the element of a row. Call it with `null` when the row unmounts. */
|
|
204
|
+
registerItemElement: (id: Item['id'], element: HTMLElement | null) => void;
|
|
205
|
+
/** Scrolls to an item. Add `time` to allow a history load. The engine waits for the loaded item and its row. A later `navigateTo` or `scrollToBottom` ends it. */
|
|
206
|
+
navigateTo: (target: { id: Item['id']; time?: number }) => void;
|
|
207
|
+
/** Scrolls to the end of the timeline. Like `navigateTo`, it ends an earlier command that still waits. */
|
|
208
|
+
scrollToBottom: (options?: ScrollToBottomOptions) => void;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Controls a bounded, paged, end-anchored timeline for one scroll container. */
|
|
212
|
+
export declare function useScrollback<Item extends ScrollbackItem>(
|
|
213
|
+
options: UseScrollbackOptions<Item>,
|
|
214
|
+
): UseScrollbackResult<Item>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import type { NAVIGATION_OUTCOME, NAVIGATION_TRIGGER } from './constants.js';
|
|
2
|
+
|
|
3
|
+
type ValueOf<Values> = Values[keyof Values];
|
|
4
|
+
|
|
5
|
+
/** A mutable ref object. It is compatible with the `ref` prop of a React element. */
|
|
6
|
+
export interface ScrollbackRef<Value> {
|
|
7
|
+
current: Value;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** The minimum shape of a timeline item. */
|
|
11
|
+
export interface ScrollbackItem {
|
|
12
|
+
/** A unique, stable identifier. */
|
|
13
|
+
readonly id: string;
|
|
14
|
+
/** The item time. A larger value is newer. */
|
|
15
|
+
readonly time: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** The identifier type of an item type. */
|
|
19
|
+
export type ItemIdOf<Item extends ScrollbackItem> = Item['id'];
|
|
20
|
+
|
|
21
|
+
/** The scroll state that a consumer can store and give back later. */
|
|
22
|
+
export interface ScrollbackMemory<Id extends string = string> {
|
|
23
|
+
/** The scroll offset of the container. */
|
|
24
|
+
scrollTop: number;
|
|
25
|
+
/** True while the reader follows the end of the timeline. */
|
|
26
|
+
atBottom: boolean;
|
|
27
|
+
/** The item that held the reading position. */
|
|
28
|
+
anchorItemId?: Id;
|
|
29
|
+
/** The distance from the top of the viewport to the anchor item. */
|
|
30
|
+
anchorOffsetFromViewportTop?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Size limits for the render window. Each value replaces its default. Each
|
|
35
|
+
* value must be a positive integer, or a `RangeError` is thrown. The first window
|
|
36
|
+
* is capped at `maxRenderedItems`. The reveal step is capped at half of `maxRenderedItems`.
|
|
37
|
+
*/
|
|
38
|
+
export interface ScrollbackLimits {
|
|
39
|
+
/** The number of items in one reveal step or server page. Capped at half of `maxRenderedItems`. Default: 30. */
|
|
40
|
+
pageSize?: number;
|
|
41
|
+
/** The number of items in the first window. Default: 60. */
|
|
42
|
+
initialPageSize?: number;
|
|
43
|
+
/** The maximum number of rendered items. Default: 150. */
|
|
44
|
+
maxRenderedItems?: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Distances in pixels. Each value replaces its default. */
|
|
48
|
+
export interface ScrollbackThresholds {
|
|
49
|
+
/** How close to the end counts as "at the bottom". Default: 56. */
|
|
50
|
+
atBottom?: number;
|
|
51
|
+
/** The smallest distance from a page boundary that starts a page load. Default: 480. */
|
|
52
|
+
prefetchMin?: number;
|
|
53
|
+
/** The largest distance from a page boundary that starts a page load. Default: 1200. */
|
|
54
|
+
prefetchMax?: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Settings for `navigateTo` and the initial target. Each value replaces its default. */
|
|
58
|
+
export interface ScrollbackNavigationSettings {
|
|
59
|
+
/** The number of older pages that a navigation without `time` searches. Default: 5. */
|
|
60
|
+
maxOlderPages?: number;
|
|
61
|
+
/** How long a navigated item stays highlighted, in milliseconds. Default: 1400. */
|
|
62
|
+
highlightDuration?: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Browser services that the engine can share with the rest of the page. */
|
|
66
|
+
export interface ScrollbackPlatform {
|
|
67
|
+
/** Watches the size of an element. Returns a stop function, or `null` when unsupported. */
|
|
68
|
+
observeResize?: (
|
|
69
|
+
element: Element,
|
|
70
|
+
listener: () => void,
|
|
71
|
+
) => (() => void) | null;
|
|
72
|
+
/** Schedules a keyed measurement. `read` returns the write function. Returns a cancel function. */
|
|
73
|
+
scheduleMeasurement?: (key: object, read: () => () => void) => () => void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The reason for a navigation. */
|
|
77
|
+
export type ScrollbackNavigationTrigger = ValueOf<typeof NAVIGATION_TRIGGER>;
|
|
78
|
+
|
|
79
|
+
/** The result of a navigation that finished. */
|
|
80
|
+
export type ScrollbackNavigationOutcome = Exclude<
|
|
81
|
+
ValueOf<typeof NAVIGATION_OUTCOME>,
|
|
82
|
+
typeof NAVIGATION_OUTCOME.SUPERSEDED
|
|
83
|
+
>;
|
|
84
|
+
|
|
85
|
+
/** A navigation that just started. */
|
|
86
|
+
export interface ScrollbackNavigation<Id extends string = string> {
|
|
87
|
+
/** The reason for the navigation. */
|
|
88
|
+
trigger: ScrollbackNavigationTrigger;
|
|
89
|
+
/** The target item identifier. */
|
|
90
|
+
id: Id;
|
|
91
|
+
/** The target item time, when the caller knows it. */
|
|
92
|
+
time?: number;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Options for `scrollToBottom`. */
|
|
96
|
+
export interface ScrollToBottomOptions {
|
|
97
|
+
/** The scroll behavior. Default: an instant jump. Use `'smooth'` to animate. */
|
|
98
|
+
behavior?: ScrollBehavior;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Options for `useScrollback`. */
|
|
102
|
+
export interface UseScrollbackOptions<Item extends ScrollbackItem> {
|
|
103
|
+
/** The cached history and the paging controls. */
|
|
104
|
+
source: {
|
|
105
|
+
/** The full cached history, oldest first. */
|
|
106
|
+
items: readonly Item[];
|
|
107
|
+
/** True while the first load runs. Default: `false`. */
|
|
108
|
+
isLoading?: boolean;
|
|
109
|
+
/** Paging controls for items older than the cache. */
|
|
110
|
+
older: {
|
|
111
|
+
/** True when the server has more older items. */
|
|
112
|
+
hasMore: boolean;
|
|
113
|
+
/** True while an older page loads. */
|
|
114
|
+
isLoading: boolean;
|
|
115
|
+
/** A number that changes each time an older page arrives. Any change counts. */
|
|
116
|
+
version: number;
|
|
117
|
+
/** Loads one older page. Resolves true when it added items. */
|
|
118
|
+
load: () => Promise<boolean>;
|
|
119
|
+
};
|
|
120
|
+
/** Loads history until the target is in the cache. Resolves true when found. */
|
|
121
|
+
loadThrough?: (target: Pick<Item, 'id' | 'time'>) => Promise<boolean>;
|
|
122
|
+
};
|
|
123
|
+
/** Items that the timeline must reach or keep rendered. */
|
|
124
|
+
targets?: {
|
|
125
|
+
/** Opens the timeline at this item. The engine anchors the window, scrolls, and highlights it. */
|
|
126
|
+
initialId?: Item['id'];
|
|
127
|
+
/** The time of `initialId`. It lets the engine load an uncached target. */
|
|
128
|
+
initialTime?: number;
|
|
129
|
+
/**
|
|
130
|
+
* Opens the window around this item when it is cached. The engine does not scroll to it.
|
|
131
|
+
* When the item is not cached, the window that exists stays as it is, and
|
|
132
|
+
* when no window exists, the default window opens.
|
|
133
|
+
*/
|
|
134
|
+
focusId?: Item['id'];
|
|
135
|
+
/** The item for read reporting. See `isReadTargetReached`. */
|
|
136
|
+
readId?: Item['id'];
|
|
137
|
+
};
|
|
138
|
+
/** Scroll memory input and output. */
|
|
139
|
+
memory?: {
|
|
140
|
+
/** The scroll state to restore on the first render. */
|
|
141
|
+
initial?: ScrollbackMemory<Item['id']>;
|
|
142
|
+
/** Called when the scroll state changes. */
|
|
143
|
+
onChange?: (memory: ScrollbackMemory<Item['id']>) => void;
|
|
144
|
+
};
|
|
145
|
+
/** Layout input. */
|
|
146
|
+
layout?: {
|
|
147
|
+
/** The height that an overlay covers at the end of the container. A change keeps a pinned tail in view. */
|
|
148
|
+
bottomInset?: number;
|
|
149
|
+
};
|
|
150
|
+
/** Returns true for a new last item that the view must follow, even when the reader is not pinned. */
|
|
151
|
+
followsAppend?: (item: Item) => boolean;
|
|
152
|
+
/** Size limits for the render window. */
|
|
153
|
+
limits?: ScrollbackLimits;
|
|
154
|
+
/** Distances for the bottom check and the page prefetch. */
|
|
155
|
+
thresholds?: ScrollbackThresholds;
|
|
156
|
+
/** Settings for navigation and highlight. */
|
|
157
|
+
navigation?: ScrollbackNavigationSettings;
|
|
158
|
+
/** Replacements for the shared browser services. */
|
|
159
|
+
platform?: ScrollbackPlatform;
|
|
160
|
+
/**
|
|
161
|
+
* Called when a navigation starts. The returned function, if any, is called once
|
|
162
|
+
* when the navigation ends. It is not called for a replaced navigation.
|
|
163
|
+
*/
|
|
164
|
+
onNavigation?: (
|
|
165
|
+
navigation: ScrollbackNavigation<Item['id']>,
|
|
166
|
+
) => ((outcome: ScrollbackNavigationOutcome) => void) | void;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** The value that `useScrollback` returns. */
|
|
170
|
+
export interface UseScrollbackResult<Item extends ScrollbackItem> {
|
|
171
|
+
/** The rendered window of items, oldest first. */
|
|
172
|
+
items: readonly Item[];
|
|
173
|
+
/** True while the engine waits for `targets.initialId`. */
|
|
174
|
+
isWaitingForInitialItem: boolean;
|
|
175
|
+
/** True while an older page loads. */
|
|
176
|
+
isLoadingOlder: boolean;
|
|
177
|
+
/** True when more older items exist, in the cache or on the server. */
|
|
178
|
+
hasMoreOlder: boolean;
|
|
179
|
+
/** True when newer items exist outside the rendered window. */
|
|
180
|
+
hasMoreNewer: boolean;
|
|
181
|
+
/**
|
|
182
|
+
* True while the reader follows the end of the timeline. Reader scrolling and
|
|
183
|
+
* commands set it. Layout changes keep it. It ends when newer items are outside
|
|
184
|
+
* the rendered window.
|
|
185
|
+
*/
|
|
186
|
+
isAtBottom: boolean;
|
|
187
|
+
/** True when the reader scrolled to the read target, or when the target is older than the rendered window. */
|
|
188
|
+
isReadTargetReached: boolean;
|
|
189
|
+
/** True while the initial target is not yet shown. */
|
|
190
|
+
isInitialTargetPending: boolean;
|
|
191
|
+
/** The identifier of the item that a navigation highlights. */
|
|
192
|
+
highlightedId: Item['id'] | undefined;
|
|
193
|
+
/** Attach to the scroll container. */
|
|
194
|
+
scrollContainerRef: ScrollbackRef<HTMLDivElement | null>;
|
|
195
|
+
/** Attach to the element that holds the item rows. */
|
|
196
|
+
itemListRef: ScrollbackRef<HTMLDivElement | null>;
|
|
197
|
+
/** Attach to an element before the list. It triggers older page loads. */
|
|
198
|
+
olderSentinelRef: ScrollbackRef<HTMLDivElement | null>;
|
|
199
|
+
/** Attach to an element after the list. It triggers newer reveals. */
|
|
200
|
+
newerSentinelRef: ScrollbackRef<HTMLDivElement | null>;
|
|
201
|
+
/** Give to the `onScroll` prop of the scroll container. */
|
|
202
|
+
onScroll: () => void;
|
|
203
|
+
/** Register the element of a row. Call it with `null` when the row unmounts. */
|
|
204
|
+
registerItemElement: (id: Item['id'], element: HTMLElement | null) => void;
|
|
205
|
+
/** Scrolls to an item. Add `time` to allow a history load. The engine waits for the loaded item and its row. A later `navigateTo` or `scrollToBottom` ends it. */
|
|
206
|
+
navigateTo: (target: { id: Item['id']; time?: number }) => void;
|
|
207
|
+
/** Scrolls to the end of the timeline. Like `navigateTo`, it ends an earlier command that still waits. */
|
|
208
|
+
scrollToBottom: (options?: ScrollToBottomOptions) => void;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Controls a bounded, paged, end-anchored timeline for one scroll container. */
|
|
212
|
+
export declare function useScrollback<Item extends ScrollbackItem>(
|
|
213
|
+
options: UseScrollbackOptions<Item>,
|
|
214
|
+
): UseScrollbackResult<Item>;
|