@streamscloud/kit 0.94.9 → 0.95.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/dist/ui/infinite-scroll/cmp.infinite-scroll.svelte +14 -28
- package/dist/ui/infinite-scroll/cmp.infinite-scroll.svelte.d.ts +13 -11
- package/dist/ui/popover/cmp.hover-popover.svelte +22 -2
- package/dist/ui/popover/cmp.hover-popover.svelte.d.ts +5 -2
- package/dist/ui/popover/cmp.popover.svelte +11 -0
- package/dist/ui/select/cmp.input-suggest.svelte +1 -1
- package/dist/ui/select/cmp.singleselect-async.svelte +1 -1
- package/dist/ui/select/cmp.suggestion-list.svelte +61 -0
- package/dist/ui/select/cmp.suggestion-list.svelte.d.ts +67 -0
- package/dist/ui/select/index.d.ts +2 -1
- package/dist/ui/select/index.js +1 -0
- package/dist/ui/select/multiselect-base.svelte +1 -1
- package/dist/ui/select/select-listbox.svelte +9 -9
- package/dist/ui/select/select-listbox.svelte.d.ts +3 -3
- package/dist/ui/select/types.d.ts +5 -0
- package/package.json +1 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
<script lang="ts">import { Button } from '../button';
|
|
2
2
|
import { Spinner } from '../spinner';
|
|
3
3
|
import { InfiniteScrollLocalization } from './infinite-scroll-localization';
|
|
4
|
-
let { loadMore, container = null, rootMargin = '200px',
|
|
4
|
+
let { loadMore, container = null, rootMargin = '200px', children, showLoading = false, loading, retry } = $props();
|
|
5
5
|
const localization = new InfiniteScrollLocalization();
|
|
6
6
|
const source = $derived(typeof loadMore === 'function' ? { loadMore, failed: false, canLoadMore: true } : loadMore);
|
|
7
7
|
let isLoading = $state(false);
|
|
8
|
+
let root = $state(null);
|
|
8
9
|
let paginationTrigger = $state(null);
|
|
9
10
|
let itemsContainer = $state(null);
|
|
10
11
|
$effect(() => {
|
|
@@ -20,7 +21,7 @@ $effect(() => {
|
|
|
20
21
|
void onLoadMore();
|
|
21
22
|
}
|
|
22
23
|
}, {
|
|
23
|
-
root: container,
|
|
24
|
+
root: container === 'self' ? root : container,
|
|
24
25
|
rootMargin
|
|
25
26
|
});
|
|
26
27
|
// Re-observe trigger on container resize to force IntersectionObserver
|
|
@@ -52,13 +53,17 @@ const onRetry = () => {
|
|
|
52
53
|
};
|
|
53
54
|
</script>
|
|
54
55
|
|
|
55
|
-
{
|
|
56
|
+
<div class="infinite-scroll" bind:this={root}>
|
|
57
|
+
<div class="infinite-scroll__items" bind:this={itemsContainer}>
|
|
58
|
+
{@render children()}
|
|
59
|
+
</div>
|
|
60
|
+
|
|
56
61
|
<div class="infinite-scroll__pagination-trigger" bind:this={paginationTrigger}></div>
|
|
57
62
|
{#if isLoading}
|
|
58
63
|
{#if loading}
|
|
59
64
|
{@render loading()}
|
|
60
65
|
{:else if showLoading}
|
|
61
|
-
<div class="infinite-scroll__loading-container"
|
|
66
|
+
<div class="infinite-scroll__loading-container">
|
|
62
67
|
<Spinner timeout={500} />
|
|
63
68
|
</div>
|
|
64
69
|
{/if}
|
|
@@ -71,20 +76,6 @@ const onRetry = () => {
|
|
|
71
76
|
</div>
|
|
72
77
|
{/if}
|
|
73
78
|
{/if}
|
|
74
|
-
{/snippet}
|
|
75
|
-
|
|
76
|
-
<div class="infinite-scroll" class:infinite-scroll--up={direction === 'up'}>
|
|
77
|
-
{#if direction === 'up'}
|
|
78
|
-
{@render loadingEnd()}
|
|
79
|
-
{/if}
|
|
80
|
-
|
|
81
|
-
<div class="infinite-scroll__items" bind:this={itemsContainer}>
|
|
82
|
-
{@render children()}
|
|
83
|
-
</div>
|
|
84
|
-
|
|
85
|
-
{#if direction === 'down'}
|
|
86
|
-
{@render loadingEnd()}
|
|
87
|
-
{/if}
|
|
88
79
|
</div>
|
|
89
80
|
|
|
90
81
|
<!--
|
|
@@ -95,31 +86,30 @@ Pairs with `core/data-loaders` (`CursorDataLoader`, `PageDataLoader`, `CursorDat
|
|
|
95
86
|
|
|
96
87
|
Passing the loader itself — `loadMore={loader}` instead of `loadMore={loader.loadMore}` — disarms the sentinel while the loader reports `failed`, so a failing backend is not asked again on its own and the already-loaded list is kept. The manual continue appears only when the loader can still continue (`resumeAfterFailure`); a loader that closed its list on the failure ends silently, as it does at the natural end. A successful retry re-arms the sentinel on its own.
|
|
97
88
|
|
|
98
|
-
|
|
89
|
+
A history that loads upward (a chat) makes the component its own scroller laid out bottom-up: `display: flex`, `flex-direction: column-reverse`, `overflow-y: auto` through the properties below, with `container="self"`. The sentinel then sits at the top, the list opens at its end, older batches keep the view in place, and a reader at the end follows new items. The children keep their own order — lay them out bottom-up too to pass them newest first. The built-in `showLoading` spinner stays at the bottom edge; pass a `loading` snippet instead, which sits next to the sentinel.
|
|
99
90
|
|
|
100
91
|
### CSS Custom Properties
|
|
101
92
|
| Property | Description | Default |
|
|
102
93
|
|---|---|---|
|
|
103
94
|
| `--sc-kit--infinite-scroll--display` | Display mode for root and items container | `block` |
|
|
104
|
-
| `--sc-kit--infinite-scroll--flex` | Flex shorthand for root and items container | `initial
|
|
95
|
+
| `--sc-kit--infinite-scroll--flex` | Flex shorthand for root and items container | `initial` |
|
|
96
|
+
| `--sc-kit--infinite-scroll--flex-direction` | Flex direction of the root (`column-reverse` puts the sentinel on top) | `column` |
|
|
105
97
|
| `--sc-kit--infinite-scroll--overflow-y` | Vertical overflow behavior | `initial` |
|
|
106
98
|
-->
|
|
107
99
|
|
|
108
100
|
<style>.infinite-scroll {
|
|
109
101
|
--_infinite-scroll--display: var(--sc-kit--infinite-scroll--display, block);
|
|
110
102
|
--_infinite-scroll--flex: var(--sc-kit--infinite-scroll--flex, initial);
|
|
103
|
+
--_infinite-scroll--flex-direction: var(--sc-kit--infinite-scroll--flex-direction, column);
|
|
111
104
|
--_infinite-scroll--overflow-y: var(--sc-kit--infinite-scroll--overflow-y, initial);
|
|
112
105
|
display: var(--_infinite-scroll--display);
|
|
113
|
-
flex-direction:
|
|
106
|
+
flex-direction: var(--_infinite-scroll--flex-direction);
|
|
114
107
|
flex: var(--_infinite-scroll--flex);
|
|
115
108
|
overflow-y: var(--_infinite-scroll--overflow-y);
|
|
116
109
|
min-height: 2.625em;
|
|
117
110
|
position: relative;
|
|
118
111
|
width: 100%;
|
|
119
112
|
}
|
|
120
|
-
.infinite-scroll--up {
|
|
121
|
-
--_infinite-scroll--flex: var(--sc-kit--infinite-scroll--flex, none);
|
|
122
|
-
}
|
|
123
113
|
.infinite-scroll__items {
|
|
124
114
|
display: var(--_infinite-scroll--display);
|
|
125
115
|
flex-direction: column;
|
|
@@ -134,10 +124,6 @@ The component never reorders anything: it renders `children` as given and only d
|
|
|
134
124
|
left: 50%;
|
|
135
125
|
transform: translateX(-50%);
|
|
136
126
|
}
|
|
137
|
-
.infinite-scroll__loading-container--up {
|
|
138
|
-
top: 0.3125em;
|
|
139
|
-
bottom: auto;
|
|
140
|
-
}
|
|
141
127
|
.infinite-scroll__retry {
|
|
142
128
|
display: flex;
|
|
143
129
|
justify-content: center;
|
|
@@ -11,18 +11,19 @@ type Props = {
|
|
|
11
11
|
* and leaves the sentinel armed through every failure.
|
|
12
12
|
*/
|
|
13
13
|
loadMore: LoadMoreSource;
|
|
14
|
-
/** Scroll ancestor used as the IntersectionObserver root. Required when the viewport differs from the scrolling container. */
|
|
15
|
-
container?: HTMLElement | null;
|
|
16
|
-
/** IntersectionObserver `rootMargin`. Default `'200px'` — fires the load that far before the reader reaches the loading end. */
|
|
17
|
-
rootMargin?: string;
|
|
18
14
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @default
|
|
15
|
+
* The scrolling element `rootMargin` is measured against: a scroll ancestor, `'self'` when this component scrolls on its own
|
|
16
|
+
* (`--sc-kit--infinite-scroll--overflow-y`), or `null` for the viewport.
|
|
17
|
+
* @default null
|
|
22
18
|
*/
|
|
23
|
-
|
|
19
|
+
container?: HTMLElement | 'self' | null;
|
|
20
|
+
/** IntersectionObserver `rootMargin`. Default `'200px'` — fires the load that far before the reader reaches the sentinel. */
|
|
21
|
+
rootMargin?: string;
|
|
24
22
|
children: Snippet;
|
|
25
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Shows the kit `Spinner` while a batch loads, pinned to the root's bottom edge whatever the flex direction — a list loading at the top passes
|
|
25
|
+
* `loading` instead. Off by default — the list owner usually renders its own loading state.
|
|
26
|
+
*/
|
|
26
27
|
showLoading?: boolean;
|
|
27
28
|
/** Custom loading indicator snippet. Passing it turns the indicator on regardless of `showLoading`. */
|
|
28
29
|
loading?: Snippet;
|
|
@@ -36,13 +37,14 @@ type Props = {
|
|
|
36
37
|
*
|
|
37
38
|
* Passing the loader itself — `loadMore={loader}` instead of `loadMore={loader.loadMore}` — disarms the sentinel while the loader reports `failed`, so a failing backend is not asked again on its own and the already-loaded list is kept. The manual continue appears only when the loader can still continue (`resumeAfterFailure`); a loader that closed its list on the failure ends silently, as it does at the natural end. A successful retry re-arms the sentinel on its own.
|
|
38
39
|
*
|
|
39
|
-
*
|
|
40
|
+
* A history that loads upward (a chat) makes the component its own scroller laid out bottom-up: `display: flex`, `flex-direction: column-reverse`, `overflow-y: auto` through the properties below, with `container="self"`. The sentinel then sits at the top, the list opens at its end, older batches keep the view in place, and a reader at the end follows new items. The children keep their own order — lay them out bottom-up too to pass them newest first. The built-in `showLoading` spinner stays at the bottom edge; pass a `loading` snippet instead, which sits next to the sentinel.
|
|
40
41
|
*
|
|
41
42
|
* ### CSS Custom Properties
|
|
42
43
|
* | Property | Description | Default |
|
|
43
44
|
* |---|---|---|
|
|
44
45
|
* | `--sc-kit--infinite-scroll--display` | Display mode for root and items container | `block` |
|
|
45
|
-
* | `--sc-kit--infinite-scroll--flex` | Flex shorthand for root and items container | `initial
|
|
46
|
+
* | `--sc-kit--infinite-scroll--flex` | Flex shorthand for root and items container | `initial` |
|
|
47
|
+
* | `--sc-kit--infinite-scroll--flex-direction` | Flex direction of the root (`column-reverse` puts the sentinel on top) | `column` |
|
|
46
48
|
* | `--sc-kit--infinite-scroll--overflow-y` | Vertical overflow behavior | `initial` |
|
|
47
49
|
*/
|
|
48
50
|
declare const Cmp: import("svelte").Component<Props, {}, "">;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script lang="ts">import Popover from './cmp.popover.svelte';
|
|
2
2
|
const { openDelay = 100, closeDelay = 200, ...rest } = $props();
|
|
3
3
|
let popover = $state.raw(undefined);
|
|
4
|
+
let rootEl = $state.raw(undefined);
|
|
4
5
|
let openTimer;
|
|
5
6
|
let closeTimer;
|
|
6
7
|
const cancelTimers = () => {
|
|
@@ -27,6 +28,18 @@ const scheduleClose = () => {
|
|
|
27
28
|
closeTimer = undefined;
|
|
28
29
|
}, closeDelay);
|
|
29
30
|
};
|
|
31
|
+
const isInsideRoot = (node) => node instanceof Node && !!rootEl?.contains(node);
|
|
32
|
+
// Without the zone check, Escape returning focus to the trigger reopens the popover.
|
|
33
|
+
const handleFocusIn = (event) => {
|
|
34
|
+
if (!isInsideRoot(event.relatedTarget)) {
|
|
35
|
+
scheduleOpen();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const handleFocusOut = (event) => {
|
|
39
|
+
if (!isInsideRoot(event.relatedTarget)) {
|
|
40
|
+
scheduleClose();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
30
43
|
/** Imperative API — bind:this on HoverPopover to access. */
|
|
31
44
|
export const open = () => popover?.open();
|
|
32
45
|
export const close = () => popover?.close();
|
|
@@ -36,7 +49,14 @@ $effect(() => {
|
|
|
36
49
|
});
|
|
37
50
|
</script>
|
|
38
51
|
|
|
39
|
-
<span
|
|
52
|
+
<span
|
|
53
|
+
bind:this={rootEl}
|
|
54
|
+
class="hover-popover"
|
|
55
|
+
role="presentation"
|
|
56
|
+
onmouseenter={scheduleOpen}
|
|
57
|
+
onmouseleave={scheduleClose}
|
|
58
|
+
onfocusin={handleFocusIn}
|
|
59
|
+
onfocusout={handleFocusOut}>
|
|
40
60
|
<Popover bind:this={popover} {...rest} />
|
|
41
61
|
</span>
|
|
42
62
|
|
|
@@ -45,7 +65,7 @@ $effect(() => {
|
|
|
45
65
|
HoverPopover — thin wrapper around Popover that opens on hover/focus instead of click.
|
|
46
66
|
Content is rendered as a DOM descendant of the wrapper, so moving the cursor from trigger
|
|
47
67
|
to content stays "inside" the hover zone (no close fires). The `closeDelay` covers the
|
|
48
|
-
small visual gap between trigger and content.
|
|
68
|
+
small visual gap between trigger and content. A click on the trigger still toggles; nested in another popover's content it makes a submenu.
|
|
49
69
|
|
|
50
70
|
`bind:this` on HoverPopover forwards `open() / close() / toggle()` from the inner Popover.
|
|
51
71
|
-->
|
|
@@ -18,7 +18,10 @@ type Props = {
|
|
|
18
18
|
opened?: () => void;
|
|
19
19
|
closed?: () => void;
|
|
20
20
|
};
|
|
21
|
-
trigger
|
|
21
|
+
/** Same as Popover's `trigger` — a snippet inside the trigger `<button>`, or `{ custom }` for the consumer's own control (e.g. an interactive `PopoverItem` that opens a submenu). */
|
|
22
|
+
trigger?: Snippet | {
|
|
23
|
+
custom: Snippet;
|
|
24
|
+
};
|
|
22
25
|
children: Snippet;
|
|
23
26
|
/** ms before hover-open fires (debounce against accidental hovers). @default 100 */
|
|
24
27
|
openDelay?: number;
|
|
@@ -29,7 +32,7 @@ type Props = {
|
|
|
29
32
|
* HoverPopover — thin wrapper around Popover that opens on hover/focus instead of click.
|
|
30
33
|
* Content is rendered as a DOM descendant of the wrapper, so moving the cursor from trigger
|
|
31
34
|
* to content stays "inside" the hover zone (no close fires). The `closeDelay` covers the
|
|
32
|
-
* small visual gap between trigger and content.
|
|
35
|
+
* small visual gap between trigger and content. A click on the trigger still toggles; nested in another popover's content it makes a submenu.
|
|
33
36
|
*
|
|
34
37
|
* `bind:this` on HoverPopover forwards `open() / close() / toggle()` from the inner Popover.
|
|
35
38
|
*/
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
<script lang="ts" module>"use strict";
|
|
2
|
+
const openPopovers = [];
|
|
3
|
+
</script>
|
|
4
|
+
|
|
1
5
|
<script lang="ts">import { isInsideLabelOf } from '../_internal/form-field-label-context';
|
|
2
6
|
import { showInTopLayer } from '../_internal/top-layer';
|
|
3
7
|
import { Icon } from '../icon';
|
|
@@ -16,6 +20,7 @@ let backdropEl = $state.raw(undefined);
|
|
|
16
20
|
let resolvedPlacement = $state(position);
|
|
17
21
|
let previouslyFocused = null;
|
|
18
22
|
let closedByEscape = false;
|
|
23
|
+
const openPopoverEntry = Symbol();
|
|
19
24
|
/** Imperative API — bind:this on the component to access. */
|
|
20
25
|
export const open = () => {
|
|
21
26
|
if (disabled || opened) {
|
|
@@ -132,6 +137,10 @@ $effect(() => {
|
|
|
132
137
|
close();
|
|
133
138
|
};
|
|
134
139
|
const handleKey = (e) => {
|
|
140
|
+
// Every open popover listens on document: without this, Escape in a submenu closes the parent menu too.
|
|
141
|
+
if (openPopovers.at(-1) !== openPopoverEntry) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
135
144
|
if (e.key === 'Escape') {
|
|
136
145
|
e.preventDefault();
|
|
137
146
|
closedByEscape = true;
|
|
@@ -156,9 +165,11 @@ $effect(() => {
|
|
|
156
165
|
}
|
|
157
166
|
}
|
|
158
167
|
};
|
|
168
|
+
openPopovers.push(openPopoverEntry);
|
|
159
169
|
window.addEventListener('pointerdown', handleOutsidePointerDown, true);
|
|
160
170
|
document.addEventListener('keydown', handleKey, true);
|
|
161
171
|
return () => {
|
|
172
|
+
openPopovers.splice(openPopovers.indexOf(openPopoverEntry), 1);
|
|
162
173
|
window.removeEventListener('pointerdown', handleOutsidePointerDown, true);
|
|
163
174
|
document.removeEventListener('keydown', handleKey, true);
|
|
164
175
|
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<script lang="ts" generics="T">import { default as SelectListbox } from './select-listbox.svelte';
|
|
2
|
+
const { anchor, open, items, size = 'md', highlight, id, item, on } = $props();
|
|
3
|
+
const rows = $derived(items.map((value) => ({
|
|
4
|
+
kind: 'option',
|
|
5
|
+
option: { label: '', value },
|
|
6
|
+
indent: false,
|
|
7
|
+
selected: false
|
|
8
|
+
})));
|
|
9
|
+
const handlePickRow = (row) => {
|
|
10
|
+
if (row.kind === 'option') {
|
|
11
|
+
on.pick(row.option.value);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
// Capture phase: the listbox panel stops mousedown propagation, and a row press must not pull focus out of the field.
|
|
15
|
+
const keepFocusInAnchor = (event) => {
|
|
16
|
+
event.preventDefault();
|
|
17
|
+
};
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
{#snippet row({ option }: { option: SelectOption<T> })}
|
|
21
|
+
{@render item({ item: option.value })}
|
|
22
|
+
{/snippet}
|
|
23
|
+
|
|
24
|
+
<div class="suggestion-list" role="none" onmousedowncapture={keepFocusInAnchor}>
|
|
25
|
+
<SelectListbox
|
|
26
|
+
anchor={anchor}
|
|
27
|
+
isOpen={open}
|
|
28
|
+
rows={rows}
|
|
29
|
+
size={size}
|
|
30
|
+
highlight={highlight}
|
|
31
|
+
listboxId={id}
|
|
32
|
+
optionSnippet={row}
|
|
33
|
+
suppressEmpty
|
|
34
|
+
on={{ pickRow: handlePickRow, hoverRow: on.hover, dismiss: on.dismiss }} />
|
|
35
|
+
</div>
|
|
36
|
+
|
|
37
|
+
<!--
|
|
38
|
+
@component
|
|
39
|
+
SuggestionList — a listbox a text field drives: the field keeps focus and owns the open state, the filtering and the keyboard, while
|
|
40
|
+
the list positions itself under `anchor`, renders `items` (nothing while empty) and reports pick / hover / dismiss. For a field that
|
|
41
|
+
suggests whole values, use `InputSuggest` instead.
|
|
42
|
+
|
|
43
|
+
### CSS Custom Properties
|
|
44
|
+
| Property | Description | Default |
|
|
45
|
+
|---|---|---|
|
|
46
|
+
| `--sc-kit--select--panel--background` | Panel background | `var(--sc-kit--color--bg--panel)` |
|
|
47
|
+
| `--sc-kit--select--panel--border-color` | Panel border | `var(--sc-kit--color--border)` |
|
|
48
|
+
| `--sc-kit--select--panel--border-radius` | Panel radius | `var(--sc-kit--radius--md)` |
|
|
49
|
+
| `--sc-kit--select--panel--box-shadow` | Panel shadow | `var(--sc-kit--shadow--lg)` |
|
|
50
|
+
| `--sc-kit--select--panel--font-size` | Row text size | per size — `var(--sc-kit--font-size--{sm,md,lg})` |
|
|
51
|
+
| `--sc-kit--select--panel--max-height` | Panel max height | `18rem` |
|
|
52
|
+
| `--sc-kit--select--panel--padding` | Panel inner padding | `var(--sc-kit--space--1)` |
|
|
53
|
+
| `--sc-kit--select--option--height` | Row height — `auto` for a two-line `item` | per size — `var(--sc-kit--field--height--{sm,md,lg})` |
|
|
54
|
+
| `--sc-kit--select--option--padding-inline` | Row horizontal padding | `var(--sc-kit--space--3)` |
|
|
55
|
+
| `--sc-kit--select--option--color` | Row text color | `var(--sc-kit--color--text--primary)` |
|
|
56
|
+
| `--sc-kit--select--option--background--active` | Highlighted row background | `var(--sc-kit--color--accent--softer)` |
|
|
57
|
+
-->
|
|
58
|
+
|
|
59
|
+
<style>.suggestion-list {
|
|
60
|
+
display: contents;
|
|
61
|
+
}</style>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { RectAnchor } from './types';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
declare function $$render<T>(): {
|
|
4
|
+
props: {
|
|
5
|
+
/** The field (the list matches its width), or a `RectAnchor` inside it — the trigger character, the caret — the list then sizes to its content and re-reads the rect on scroll and resize, not on typing. */
|
|
6
|
+
anchor: HTMLElement | RectAnchor | undefined;
|
|
7
|
+
open: boolean;
|
|
8
|
+
items: T[];
|
|
9
|
+
/** Row height and font size, matching the field sizes. @default 'md' */
|
|
10
|
+
size?: "sm" | "md" | "lg";
|
|
11
|
+
/** Index into `items` of the highlighted row, `-1` for none — the field's keyboard handling moves it. */
|
|
12
|
+
highlight: number;
|
|
13
|
+
/** Listbox id for the field's `aria-controls`. Row `i` carries the id `{id}-row-{i}` for `aria-activedescendant`. */
|
|
14
|
+
id: string;
|
|
15
|
+
item: Snippet<[{
|
|
16
|
+
item: T;
|
|
17
|
+
}]>;
|
|
18
|
+
on: {
|
|
19
|
+
pick: (item: T) => void;
|
|
20
|
+
/** Fires when the pointer enters a row — feed it back into `highlight`. */
|
|
21
|
+
hover: (index: number) => void;
|
|
22
|
+
/** Fires on Escape and on a press outside both the anchor and the list. */
|
|
23
|
+
dismiss: () => void;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
exports: {};
|
|
27
|
+
bindings: "";
|
|
28
|
+
slots: {};
|
|
29
|
+
events: {};
|
|
30
|
+
};
|
|
31
|
+
declare class __sveltets_Render<T> {
|
|
32
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
33
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
34
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
35
|
+
bindings(): "";
|
|
36
|
+
exports(): {};
|
|
37
|
+
}
|
|
38
|
+
interface $$IsomorphicComponent {
|
|
39
|
+
new <T>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
40
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
41
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
42
|
+
<T>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
43
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* SuggestionList — a listbox a text field drives: the field keeps focus and owns the open state, the filtering and the keyboard, while
|
|
47
|
+
* the list positions itself under `anchor`, renders `items` (nothing while empty) and reports pick / hover / dismiss. For a field that
|
|
48
|
+
* suggests whole values, use `InputSuggest` instead.
|
|
49
|
+
*
|
|
50
|
+
* ### CSS Custom Properties
|
|
51
|
+
* | Property | Description | Default |
|
|
52
|
+
* |---|---|---|
|
|
53
|
+
* | `--sc-kit--select--panel--background` | Panel background | `var(--sc-kit--color--bg--panel)` |
|
|
54
|
+
* | `--sc-kit--select--panel--border-color` | Panel border | `var(--sc-kit--color--border)` |
|
|
55
|
+
* | `--sc-kit--select--panel--border-radius` | Panel radius | `var(--sc-kit--radius--md)` |
|
|
56
|
+
* | `--sc-kit--select--panel--box-shadow` | Panel shadow | `var(--sc-kit--shadow--lg)` |
|
|
57
|
+
* | `--sc-kit--select--panel--font-size` | Row text size | per size — `var(--sc-kit--font-size--{sm,md,lg})` |
|
|
58
|
+
* | `--sc-kit--select--panel--max-height` | Panel max height | `18rem` |
|
|
59
|
+
* | `--sc-kit--select--panel--padding` | Panel inner padding | `var(--sc-kit--space--1)` |
|
|
60
|
+
* | `--sc-kit--select--option--height` | Row height — `auto` for a two-line `item` | per size — `var(--sc-kit--field--height--{sm,md,lg})` |
|
|
61
|
+
* | `--sc-kit--select--option--padding-inline` | Row horizontal padding | `var(--sc-kit--space--3)` |
|
|
62
|
+
* | `--sc-kit--select--option--color` | Row text color | `var(--sc-kit--color--text--primary)` |
|
|
63
|
+
* | `--sc-kit--select--option--background--active` | Highlighted row background | `var(--sc-kit--color--accent--softer)` |
|
|
64
|
+
*/
|
|
65
|
+
declare const Cmp: $$IsomorphicComponent;
|
|
66
|
+
type Cmp<T> = InstanceType<typeof Cmp<T>>;
|
|
67
|
+
export default Cmp;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { default as InputSuggest } from './cmp.input-suggest.svelte';
|
|
2
2
|
export type { InputSuggestInstance } from './cmp.input-suggest.svelte';
|
|
3
|
+
export { default as SuggestionList } from './cmp.suggestion-list.svelte';
|
|
3
4
|
export { default as Singleselect } from './cmp.singleselect.svelte';
|
|
4
5
|
export type { SingleselectInstance } from './cmp.singleselect.svelte';
|
|
5
6
|
export { default as SingleselectAsync } from './cmp.singleselect-async.svelte';
|
|
@@ -11,4 +12,4 @@ export type { MultiselectAsyncInstance } from './cmp.multiselect-async.svelte';
|
|
|
11
12
|
export { default as MultiselectTree } from './cmp.multiselect-tree.svelte';
|
|
12
13
|
export type { MultiselectTreeInstance } from './cmp.multiselect-tree.svelte';
|
|
13
14
|
export { isSelectGroup } from './types';
|
|
14
|
-
export type { InputSuggestion, SelectCreateOptions, SelectItem, SelectOption, SelectOptionGroup } from './types';
|
|
15
|
+
export type { InputSuggestion, RectAnchor, SelectCreateOptions, SelectItem, SelectOption, SelectOptionGroup } from './types';
|
package/dist/ui/select/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { default as InputSuggest } from './cmp.input-suggest.svelte';
|
|
2
|
+
export { default as SuggestionList } from './cmp.suggestion-list.svelte';
|
|
2
3
|
export { default as Singleselect } from './cmp.singleselect.svelte';
|
|
3
4
|
export { default as SingleselectAsync } from './cmp.singleselect-async.svelte';
|
|
4
5
|
export { default as Multiselect } from './cmp.multiselect.svelte';
|
|
@@ -8,7 +8,7 @@ import IconCheckboxChecked from '@fluentui/svg-icons/icons/checkbox_checked_16_f
|
|
|
8
8
|
import IconCheckboxIndeterminate from '@fluentui/svg-icons/icons/checkbox_indeterminate_16_filled.svg?raw';
|
|
9
9
|
import IconCheckboxUnchecked from '@fluentui/svg-icons/icons/checkbox_unchecked_16_regular.svg?raw';
|
|
10
10
|
import IconCheckmark from '@fluentui/svg-icons/icons/checkmark_16_regular.svg?raw';
|
|
11
|
-
let {
|
|
11
|
+
let { anchor, isOpen, rows, highlight, loading = false, size = 'md', listboxId, matchTriggerWidth = true, selectedDisplay = 'checkmark', optionSnippet, headerSnippet, bodySnippet, hideCreateRows = false, createPrefix, suppressEmpty = false, on } = $props();
|
|
12
12
|
const localization = new SelectListboxLocalization();
|
|
13
13
|
// rows keep their index into the full `rows` array — `highlight` and row ids are core-side indices,
|
|
14
14
|
// so filtering without preserving them shifts every row by one and Enter acts on the wrong row
|
|
@@ -18,17 +18,19 @@ const showEmpty = $derived(!hasRows && !loading && !suppressEmpty);
|
|
|
18
18
|
const isHighlightMode = $derived(selectedDisplay === 'highlight');
|
|
19
19
|
let panelEl = $state.raw(undefined);
|
|
20
20
|
let triggerWidth = $state(undefined);
|
|
21
|
+
const anchorElement = $derived(anchor instanceof HTMLElement ? anchor : anchor?.contextElement);
|
|
21
22
|
// Floating UI: position when open, autoUpdate on scroll/resize, cleanup on close.
|
|
22
23
|
$effect(() => {
|
|
23
|
-
if (!isOpen || !
|
|
24
|
+
if (!isOpen || !anchor || !panelEl) {
|
|
24
25
|
return;
|
|
25
26
|
}
|
|
26
|
-
const
|
|
27
|
+
const reference = anchor;
|
|
27
28
|
const panel = panelEl;
|
|
29
|
+
const sizesToContent = !!bodySnippet || !(reference instanceof HTMLElement);
|
|
28
30
|
showInTopLayer(panel);
|
|
29
31
|
const update = async () => {
|
|
30
32
|
showInTopLayer(panel);
|
|
31
|
-
const result = await computePosition(
|
|
33
|
+
const result = await computePosition(reference, panel, {
|
|
32
34
|
strategy: 'fixed',
|
|
33
35
|
placement: 'bottom-start',
|
|
34
36
|
middleware: [
|
|
@@ -37,9 +39,7 @@ $effect(() => {
|
|
|
37
39
|
floatingSize({
|
|
38
40
|
apply: ({ rects, elements }) => {
|
|
39
41
|
triggerWidth = rects.reference.width;
|
|
40
|
-
if (
|
|
41
|
-
// Custom listbox body — caller decides sizing. We expose `triggerWidth` via snippet args
|
|
42
|
-
// if the consumer wants to stretch/shrink, but we don't impose any width/min-width here.
|
|
42
|
+
if (sizesToContent) {
|
|
43
43
|
elements.floating.style.width = '';
|
|
44
44
|
elements.floating.style.minWidth = '';
|
|
45
45
|
}
|
|
@@ -61,7 +61,7 @@ $effect(() => {
|
|
|
61
61
|
visibility: result.middlewareData.hide?.referenceHidden ? 'hidden' : ''
|
|
62
62
|
});
|
|
63
63
|
};
|
|
64
|
-
return autoUpdate(
|
|
64
|
+
return autoUpdate(reference, panel, update);
|
|
65
65
|
});
|
|
66
66
|
// Dismiss listeners — only mounted while open.
|
|
67
67
|
$effect(() => {
|
|
@@ -73,7 +73,7 @@ $effect(() => {
|
|
|
73
73
|
if (!target) {
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
|
-
if (
|
|
76
|
+
if (anchorElement?.contains(target) || panelEl?.contains(target) || isInsideLabelOf(target, anchorElement)) {
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
79
|
on.dismiss();
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { SelectOption, SelectRow } from './types';
|
|
1
|
+
import type { RectAnchor, SelectOption, SelectRow } from './types';
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
declare function $$render<T>(): {
|
|
4
4
|
props: {
|
|
5
|
-
/**
|
|
6
|
-
|
|
5
|
+
/** The listbox positions itself below it. A `RectAnchor` drops the trigger width and leaves sizing to the content. */
|
|
6
|
+
anchor: HTMLElement | RectAnchor | undefined;
|
|
7
7
|
isOpen: boolean;
|
|
8
8
|
rows: SelectRow<T>[];
|
|
9
9
|
/** Index into `rows` — highlighted row gets the active background and scrolls into view. */
|
|
@@ -57,6 +57,11 @@ export type InputSuggestion = {
|
|
|
57
57
|
/** Secondary line rendered under the value in a muted tone. */
|
|
58
58
|
description?: string;
|
|
59
59
|
};
|
|
60
|
+
/** A point inside an element to anchor floating content to — e.g. the caret in a field. `contextElement` is the element it lives in: its scroll ancestors move the content, and presses inside it count as inside. */
|
|
61
|
+
export type RectAnchor = {
|
|
62
|
+
getBoundingClientRect: () => DOMRect;
|
|
63
|
+
contextElement: HTMLElement;
|
|
64
|
+
};
|
|
60
65
|
/** Creatable mode — passing this object to a select enables the create UI. */
|
|
61
66
|
export type SelectCreateOptions = {
|
|
62
67
|
/** Validates each query, trimmed — the same string the create row shows and `on.create` receives. Only when it returns true does the create UI appear (and the query isn't a duplicate of an existing label). */
|