@kws3/ui 2.2.4 → 2.2.5
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.mdx +3 -0
- package/helpers/ScrollableList.svelte +18 -8
- package/package.json +2 -2
package/CHANGELOG.mdx
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
@param {number} [end=0] - Last item index rendered inside viewport - readonly, Default: `0`
|
|
11
11
|
@param {number} [end_threshold=10] - `end` event will be fired when the list reaches this many items before the end of the list., Default: `10`
|
|
12
12
|
@param {number} [padding_threshold=5] - render 'n' number of items on outside the viewport (top and bottom) to avoid visible glitches on scrolling., Default: `5`
|
|
13
|
+
@param {number} [mutation_threshold=5] - Number of items that can be spliced in or out, before the scroll position resets, helpful for adding/removing list items in-place, Default: `5`
|
|
13
14
|
@param {string} [style=""] - Inline CSS for scroller container, Default: `""`
|
|
14
15
|
@param {string} [class=""] - CSS classes for scroller container, Default: `""`
|
|
15
16
|
|
|
@@ -81,9 +82,8 @@ while more items are loading
|
|
|
81
82
|
</style>
|
|
82
83
|
|
|
83
84
|
<script>
|
|
84
|
-
import {
|
|
85
|
-
import { createEventDispatcher } from "svelte";
|
|
86
|
-
import { resizeObserver, hasResizeObserver } from "@kws3/ui/resizeObserver";
|
|
85
|
+
import { hasResizeObserver, resizeObserver } from "@kws3/ui/resizeObserver";
|
|
86
|
+
import { createEventDispatcher, onMount, tick } from "svelte";
|
|
87
87
|
|
|
88
88
|
const fire = createEventDispatcher();
|
|
89
89
|
/**
|
|
@@ -119,6 +119,10 @@ while more items are loading
|
|
|
119
119
|
* render 'n' number of items on outside the viewport (top and bottom) to avoid visible glitches on scrolling.
|
|
120
120
|
*/
|
|
121
121
|
padding_threshold = 5,
|
|
122
|
+
/**
|
|
123
|
+
* Number of items that can be spliced in or out, before the scroll position resets, helpful for adding/removing list items in-place
|
|
124
|
+
*/
|
|
125
|
+
mutation_threshold = 5,
|
|
122
126
|
/**
|
|
123
127
|
* Inline CSS for scroller container
|
|
124
128
|
*/
|
|
@@ -191,15 +195,16 @@ while more items are loading
|
|
|
191
195
|
const row_height = height_map[i] || average_height;
|
|
192
196
|
if (y + row_height > scrollTop) {
|
|
193
197
|
start = i;
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
: y;
|
|
198
|
+
let rhpt = row_height * padding_threshold;
|
|
199
|
+
let diff = y - rhpt;
|
|
200
|
+
top = y > rhpt && diff > i ? diff : y;
|
|
198
201
|
break;
|
|
199
202
|
}
|
|
200
203
|
y += row_height;
|
|
201
204
|
i += 1;
|
|
202
205
|
}
|
|
206
|
+
i = 0;
|
|
207
|
+
y = 0;
|
|
203
208
|
while (i < items.length) {
|
|
204
209
|
y += height_map[i] || average_height;
|
|
205
210
|
i += 1;
|
|
@@ -210,6 +215,7 @@ while more items are loading
|
|
|
210
215
|
average_height = y / end;
|
|
211
216
|
while (i < items.length) height_map[i++] = average_height;
|
|
212
217
|
bottom = remaining * average_height;
|
|
218
|
+
|
|
213
219
|
// prevent jumping if we scrolled up into unknown territory
|
|
214
220
|
if (start < old_start) {
|
|
215
221
|
await tick();
|
|
@@ -249,7 +255,11 @@ while more items are loading
|
|
|
249
255
|
|
|
250
256
|
function reset() {
|
|
251
257
|
if (!mounted) return;
|
|
252
|
-
if (
|
|
258
|
+
if (
|
|
259
|
+
!items.length ||
|
|
260
|
+
(items.length < items_count &&
|
|
261
|
+
items_count - items.length > mutation_threshold)
|
|
262
|
+
) {
|
|
253
263
|
item_height = null;
|
|
254
264
|
start = 0;
|
|
255
265
|
end = 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kws3/ui",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.5",
|
|
4
4
|
"description": "UI components for use with Svelte v3 applications.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"svelte": "index.js",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"typescript": "^5.0.4"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "7a85c9f2d6e4021ac05477ccda398d54064a4c13"
|
|
39
39
|
}
|