@kws3/ui 4.0.3 → 4.1.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.
- package/CHANGELOG.mdx +7 -1
- package/helpers/InfiniteList.svelte +136 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +2 -2
package/CHANGELOG.mdx
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
# 4.1.0
|
|
2
|
+
- New component `InfiniteList` Added
|
|
3
|
+
|
|
1
4
|
# 4.0.3
|
|
2
5
|
- `ScrollableList` - bugfixes, and add support for removing items without affecting scroll position
|
|
3
6
|
|
|
@@ -11,7 +14,10 @@
|
|
|
11
14
|
- add svelte 4 compatibility
|
|
12
15
|
|
|
13
16
|
--------------
|
|
14
|
-
# 2.
|
|
17
|
+
# 2.3.0
|
|
18
|
+
- New component `InfiniteList` Added
|
|
19
|
+
|
|
20
|
+
# 2.2.5
|
|
15
21
|
- `ScrollableList` - bugfixes, and add support for removing items without affecting scroll position
|
|
16
22
|
|
|
17
23
|
# 2.2.4
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
|
|
4
|
+
|
|
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`
|
|
7
|
+
@param {string} [height="100%"] - Height of the wrapper, CSS String, Default: `"100%"`
|
|
8
|
+
@param {number} [end_offset=400] - `end` event will be fired when the scroll position reaches this many pixels from the end of the list., Default: `400`
|
|
9
|
+
@param {string} [style=""] - Inline CSS for scroller container, Default: `""`
|
|
10
|
+
@param {string} [class=""] - CSS classes for scroller container, Default: `""`
|
|
11
|
+
|
|
12
|
+
### Events
|
|
13
|
+
- `end` - Fired when the scroll position reaches `end_offset` pixels from the end of the list.
|
|
14
|
+
|
|
15
|
+
### Slots
|
|
16
|
+
- `<slot name="default" {item} {index} />` - Default slot for list view items
|
|
17
|
+
- `<slot name="loader" />` - Optional slot to display a loading graphic at the bottom of the list
|
|
18
|
+
while more items are loading
|
|
19
|
+
|
|
20
|
+
-->
|
|
21
|
+
{#if hasResizeObserver}
|
|
22
|
+
<div
|
|
23
|
+
bind:this={viewport}
|
|
24
|
+
class="kws-scrollable-list kws-infinite-list with-resize-observer {klass}"
|
|
25
|
+
on:scroll={handle_scroll}
|
|
26
|
+
style="height:{height};{style}"
|
|
27
|
+
use:resizeObserver
|
|
28
|
+
on:resize={resize}>
|
|
29
|
+
<div bind:this={contents}>
|
|
30
|
+
{#each visible as item (item.index)}
|
|
31
|
+
<div class="row">
|
|
32
|
+
<!--Default slot for list view items-->
|
|
33
|
+
<slot item={item.data} index={item.index} />
|
|
34
|
+
</div>
|
|
35
|
+
{/each}
|
|
36
|
+
<!--Optional slot to display a loading graphic at the bottom of the list
|
|
37
|
+
while more items are loading-->
|
|
38
|
+
<slot name="loader" />
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
{:else}
|
|
42
|
+
<div
|
|
43
|
+
bind:this={viewport}
|
|
44
|
+
class="kws-scrollable-list kws-infinite-list {klass}"
|
|
45
|
+
on:scroll={handle_scroll}
|
|
46
|
+
style="height:{height};{style}"
|
|
47
|
+
bind:offsetHeight={viewport_height}>
|
|
48
|
+
<div bind:this={contents}>
|
|
49
|
+
{#each visible as item (item.index)}
|
|
50
|
+
<div class="row">
|
|
51
|
+
<!--Default slot for list view items-->
|
|
52
|
+
<slot item={item.data} index={item.index} />
|
|
53
|
+
</div>
|
|
54
|
+
{/each}
|
|
55
|
+
<!--Optional slot to display a loading graphic at the bottom of the list
|
|
56
|
+
while more items are loading-->
|
|
57
|
+
<slot name="loader" />
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
{/if}
|
|
61
|
+
|
|
62
|
+
<style>
|
|
63
|
+
.kws-infinite-list {
|
|
64
|
+
overflow: auto;
|
|
65
|
+
-webkit-overflow-scrolling: touch;
|
|
66
|
+
position: relative;
|
|
67
|
+
height: 100%;
|
|
68
|
+
}
|
|
69
|
+
</style>
|
|
70
|
+
|
|
71
|
+
<script>
|
|
72
|
+
import { hasResizeObserver, resizeObserver } from "@kws3/ui/resizeObserver";
|
|
73
|
+
import { createEventDispatcher } from "svelte";
|
|
74
|
+
|
|
75
|
+
const fire = createEventDispatcher();
|
|
76
|
+
/**
|
|
77
|
+
* Array of items
|
|
78
|
+
*/
|
|
79
|
+
export let items = [],
|
|
80
|
+
/**
|
|
81
|
+
* Iteration key - by default it uses the index of the array inside the keyed each block
|
|
82
|
+
*/
|
|
83
|
+
iteration_key = null,
|
|
84
|
+
/**
|
|
85
|
+
* Height of the wrapper, CSS String
|
|
86
|
+
*/
|
|
87
|
+
height = "100%",
|
|
88
|
+
/**
|
|
89
|
+
* `end` event will be fired when the scroll position reaches this many pixels from the end of the list.
|
|
90
|
+
*/
|
|
91
|
+
end_offset = 400,
|
|
92
|
+
/**
|
|
93
|
+
* Inline CSS for scroller container
|
|
94
|
+
*/
|
|
95
|
+
style = "";
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* CSS classes for scroller container
|
|
99
|
+
*/
|
|
100
|
+
let klass = "";
|
|
101
|
+
export { klass as class };
|
|
102
|
+
|
|
103
|
+
// local state
|
|
104
|
+
let viewport,
|
|
105
|
+
contents,
|
|
106
|
+
viewport_height = 0,
|
|
107
|
+
visible,
|
|
108
|
+
fired = false;
|
|
109
|
+
|
|
110
|
+
$: visible = items.slice().map((data, i) => ({
|
|
111
|
+
index: iteration_key ? data[iteration_key] : i,
|
|
112
|
+
data,
|
|
113
|
+
}));
|
|
114
|
+
|
|
115
|
+
function handle_scroll() {
|
|
116
|
+
const { scrollTop, scrollHeight } = viewport;
|
|
117
|
+
let offset = scrollHeight - viewport_height - scrollTop;
|
|
118
|
+
// fire on:end event if we scrolled past the end_offset
|
|
119
|
+
if (offset <= end_offset) {
|
|
120
|
+
if (!fired) {
|
|
121
|
+
/**
|
|
122
|
+
* Fired when the scroll position reaches `end_offset` pixels from the end of the list.
|
|
123
|
+
*/
|
|
124
|
+
fire("end");
|
|
125
|
+
}
|
|
126
|
+
fired = true;
|
|
127
|
+
} else {
|
|
128
|
+
fired = false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const resize = () => {
|
|
133
|
+
viewport_height = viewport.offsetHeight;
|
|
134
|
+
handle_scroll();
|
|
135
|
+
};
|
|
136
|
+
</script>
|
package/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export { default as TimelineHeader } from "./helpers/Timeline/TimelineHeader.sve
|
|
|
16
16
|
export { default as Nl2br } from "./helpers/Nl2br.svelte";
|
|
17
17
|
export { default as ClipboardCopier } from "./helpers/ClipboardCopier.svelte";
|
|
18
18
|
export { default as ScrollableList } from "./helpers/ScrollableList.svelte";
|
|
19
|
+
export { default as InfiniteList } from "./helpers/InfiniteList.svelte";
|
|
19
20
|
export { default as FloatingUIOutput } from "./helpers/FloatingUI/FloatingUIOutput.svelte";
|
|
20
21
|
export { default as Floatie } from "./helpers/FloatingUI/Floatie.svelte";
|
|
21
22
|
export { default as ConfirmButton } from "./buttons/ConfirmButton.svelte";
|
package/index.js
CHANGED
|
@@ -18,6 +18,7 @@ export { default as TimelineHeader } from "./helpers/Timeline/TimelineHeader.sve
|
|
|
18
18
|
export { default as Nl2br } from "./helpers/Nl2br.svelte";
|
|
19
19
|
export { default as ClipboardCopier } from "./helpers/ClipboardCopier.svelte";
|
|
20
20
|
export { default as ScrollableList } from "./helpers/ScrollableList.svelte";
|
|
21
|
+
export { default as InfiniteList } from "./helpers/InfiniteList.svelte";
|
|
21
22
|
export {
|
|
22
23
|
alert,
|
|
23
24
|
confirm,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kws3/ui",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
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": "d56d77bed1162551c0dcd4a82aefe4c392e6f716"
|
|
39
39
|
}
|