@kws3/ui 2.2.1 → 2.2.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 +6 -0
- package/helpers/ScrollableList.svelte +18 -7
- package/package.json +2 -2
package/CHANGELOG.mdx
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
# 2.2.3
|
|
2
|
+
- `ScrollableList` - add support for custom iteration key for keyed each block
|
|
3
|
+
|
|
4
|
+
# 2.2.2
|
|
5
|
+
- `ScrollableList` - fix jumping issue when edge of scrollable regions are reached
|
|
6
|
+
|
|
1
7
|
# 2.2.1
|
|
2
8
|
- `Icon` fix icon sizes when line-awesome icons are loaded
|
|
3
9
|
- `Icon` fix material icons when icon family is set globally
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
@param {array} [items=[]] - Array of items, Default: `[]`
|
|
6
|
+
@param {object} [iteration_key=null] - Iteration key - by default it uses the index of the array inside the keyed each block, Default: `null`
|
|
6
7
|
@param {string} [height="100%"] - Height of the wrapper, CSS String, Default: `"100%"`
|
|
7
8
|
@param {number | null} [item_height=null] - Height of each list item. If not set, height will be calculated automatically based on each item's offsetHeight, Default: `null`
|
|
8
9
|
@param {number} [start=0] - First item index rendered inside viewport - readonly, Default: `0`
|
|
@@ -54,7 +55,9 @@ while more items are loading
|
|
|
54
55
|
bind:offsetHeight={viewport_height}>
|
|
55
56
|
<div
|
|
56
57
|
bind:this={contents}
|
|
57
|
-
style="padding-top: {
|
|
58
|
+
style="padding-top: {start === 0
|
|
59
|
+
? 0
|
|
60
|
+
: top}px; padding-bottom: {bottom}px;">
|
|
58
61
|
{#each visible as item (item.index)}
|
|
59
62
|
<div class="row">
|
|
60
63
|
<!--Default slot for list view items-->
|
|
@@ -87,6 +90,10 @@ while more items are loading
|
|
|
87
90
|
* Array of items
|
|
88
91
|
*/
|
|
89
92
|
export let items = [],
|
|
93
|
+
/**
|
|
94
|
+
* Iteration key - by default it uses the index of the array inside the keyed each block
|
|
95
|
+
*/
|
|
96
|
+
iteration_key = null,
|
|
90
97
|
/**
|
|
91
98
|
* Height of the wrapper, CSS String
|
|
92
99
|
*/
|
|
@@ -138,9 +145,10 @@ while more items are loading
|
|
|
138
145
|
|
|
139
146
|
$: padStart = start > padding_threshold ? start - padding_threshold : start;
|
|
140
147
|
$: padEnd = end + padding_threshold;
|
|
141
|
-
$: visible = items
|
|
142
|
-
|
|
143
|
-
|
|
148
|
+
$: visible = items.slice(padStart, padEnd).map((data, i) => ({
|
|
149
|
+
index: iteration_key ? data[iteration_key] : i + padStart,
|
|
150
|
+
data,
|
|
151
|
+
}));
|
|
144
152
|
|
|
145
153
|
// whenever `items` changes, invalidate the current heightmap
|
|
146
154
|
$: items, viewport_height, item_height, mounted, refresh();
|
|
@@ -148,7 +156,7 @@ while more items are loading
|
|
|
148
156
|
|
|
149
157
|
async function refresh() {
|
|
150
158
|
if (!mounted) return;
|
|
151
|
-
const scrollTop = viewport
|
|
159
|
+
const { scrollTop } = viewport;
|
|
152
160
|
await tick(); // wait until the DOM is up to date
|
|
153
161
|
let content_height = top - scrollTop;
|
|
154
162
|
let i = start;
|
|
@@ -172,7 +180,7 @@ while more items are loading
|
|
|
172
180
|
}
|
|
173
181
|
|
|
174
182
|
async function handle_scroll() {
|
|
175
|
-
const scrollTop = viewport
|
|
183
|
+
const { scrollTop } = viewport;
|
|
176
184
|
const old_start = start;
|
|
177
185
|
for (let v = 0; v < rows.length; v += 1) {
|
|
178
186
|
height_map[start + v] = item_height || rows[v].offsetHeight;
|
|
@@ -183,7 +191,10 @@ while more items are loading
|
|
|
183
191
|
const row_height = height_map[i] || average_height;
|
|
184
192
|
if (y + row_height > scrollTop) {
|
|
185
193
|
start = i;
|
|
186
|
-
top =
|
|
194
|
+
top =
|
|
195
|
+
y > row_height * padding_threshold
|
|
196
|
+
? y - row_height * padding_threshold
|
|
197
|
+
: y;
|
|
187
198
|
break;
|
|
188
199
|
}
|
|
189
200
|
y += row_height;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kws3/ui",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.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": "
|
|
38
|
+
"gitHead": "77b76e0e8ecbd1d9f282c67b62d944efafa5949b"
|
|
39
39
|
}
|