@kws3/ui 4.0.2 → 4.0.3

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 CHANGED
@@ -1,3 +1,6 @@
1
+ # 4.0.3
2
+ - `ScrollableList` - bugfixes, and add support for removing items without affecting scroll position
3
+
1
4
  # 4.0.2
2
5
  - `ToggleButtons` - add support for count tags, and fix css not applying
3
6
 
@@ -8,6 +11,9 @@
8
11
  - add svelte 4 compatibility
9
12
 
10
13
  --------------
14
+ # 2.2.3
15
+ - `ScrollableList` - bugfixes, and add support for removing items without affecting scroll position
16
+
11
17
  # 2.2.4
12
18
  - `ToggleButtons` - add support for count tags, and fix css not applying
13
19
 
@@ -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 { onMount, tick } from "svelte";
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
- top =
195
- y > row_height * padding_threshold
196
- ? y - row_height * padding_threshold
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 (!items.length || items.length < items_count) {
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": "4.0.2",
3
+ "version": "4.0.3",
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": "b9f2d8484c24cc6665b3802eb738000b9205ec72"
38
+ "gitHead": "2c6e15b414cc4891bd0c018e76dfeecd4f80d171"
39
39
  }