@streamscloud/kit 0.95.0 → 0.95.2

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.
@@ -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 = () => {
@@ -16,7 +17,7 @@ const cancelTimers = () => {
16
17
  const scheduleOpen = () => {
17
18
  cancelTimers();
18
19
  openTimer = setTimeout(() => {
19
- popover?.open();
20
+ popover?.open({ moveFocus: false });
20
21
  openTimer = undefined;
21
22
  }, openDelay);
22
23
  };
@@ -27,6 +28,12 @@ const scheduleClose = () => {
27
28
  closeTimer = undefined;
28
29
  }, closeDelay);
29
30
  };
31
+ const isInsideRoot = (node) => node instanceof Node && !!rootEl?.contains(node);
32
+ const handleFocusOut = (event) => {
33
+ if (!isInsideRoot(event.relatedTarget)) {
34
+ scheduleClose();
35
+ }
36
+ };
30
37
  /** Imperative API — bind:this on HoverPopover to access. */
31
38
  export const open = () => popover?.open();
32
39
  export const close = () => popover?.close();
@@ -36,16 +43,16 @@ $effect(() => {
36
43
  });
37
44
  </script>
38
45
 
39
- <span class="hover-popover" role="presentation" onmouseenter={scheduleOpen} onmouseleave={scheduleClose} onfocusin={scheduleOpen} onfocusout={scheduleClose}>
46
+ <span bind:this={rootEl} class="hover-popover" role="presentation" onmouseenter={scheduleOpen} onmouseleave={scheduleClose} onfocusout={handleFocusOut}>
40
47
  <Popover bind:this={popover} {...rest} />
41
48
  </span>
42
49
 
43
50
  <!--
44
51
  @component
45
- HoverPopover — thin wrapper around Popover that opens on hover/focus instead of click.
46
- Content is rendered as a DOM descendant of the wrapper, so moving the cursor from trigger
47
- to content stays "inside" the hover zone (no close fires). The `closeDelay` covers the
48
- small visual gap between trigger and content.
52
+ HoverPopover — thin wrapper around Popover that also opens on hover. Hover leaves focus where it is; from the keyboard the
53
+ trigger opens like a Popover's (Enter / Space toggles and moves focus into the content), and focus leaving the trigger and
54
+ content closes it. Content is a DOM descendant of the wrapper, so moving the cursor from trigger to content stays inside
55
+ the hover zone; `closeDelay` covers the gap between them. Nested in another popover's content it makes a submenu.
49
56
 
50
57
  `bind:this` on HoverPopover forwards `open() / close() / toggle()` from the inner Popover.
51
58
  -->
@@ -18,7 +18,10 @@ type Props = {
18
18
  opened?: () => void;
19
19
  closed?: () => void;
20
20
  };
21
- trigger?: Snippet;
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;
@@ -26,10 +29,10 @@ type Props = {
26
29
  closeDelay?: number;
27
30
  };
28
31
  /**
29
- * HoverPopover — thin wrapper around Popover that opens on hover/focus instead of click.
30
- * Content is rendered as a DOM descendant of the wrapper, so moving the cursor from trigger
31
- * to content stays "inside" the hover zone (no close fires). The `closeDelay` covers the
32
- * small visual gap between trigger and content.
32
+ * HoverPopover — thin wrapper around Popover that also opens on hover. Hover leaves focus where it is; from the keyboard the
33
+ * trigger opens like a Popover's (Enter / Space toggles and moves focus into the content), and focus leaving the trigger and
34
+ * content closes it. Content is a DOM descendant of the wrapper, so moving the cursor from trigger to content stays inside
35
+ * the hover zone; `closeDelay` covers the gap between them. 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,11 +20,14 @@ let backdropEl = $state.raw(undefined);
16
20
  let resolvedPlacement = $state(position);
17
21
  let previouslyFocused = null;
18
22
  let closedByEscape = false;
23
+ let moveFocusOnOpen = true;
24
+ const openPopoverEntry = Symbol();
19
25
  /** Imperative API — bind:this on the component to access. */
20
- export const open = () => {
26
+ export const open = ({ moveFocus = true } = {}) => {
21
27
  if (disabled || opened) {
22
28
  return;
23
29
  }
30
+ moveFocusOnOpen = moveFocus;
24
31
  opened = true;
25
32
  on?.opened?.();
26
33
  };
@@ -107,7 +114,9 @@ $effect(() => {
107
114
  }
108
115
  previouslyFocused = document.activeElement instanceof HTMLElement ? document.activeElement : null;
109
116
  closedByEscape = false;
110
- void focusFirstFocusable();
117
+ if (moveFocusOnOpen) {
118
+ void focusFirstFocusable();
119
+ }
111
120
  return () => {
112
121
  // Only Escape: returning focus on any close flashes the trigger's focus ring when a dialog opened from an item closes.
113
122
  if (closedByEscape) {
@@ -132,6 +141,10 @@ $effect(() => {
132
141
  close();
133
142
  };
134
143
  const handleKey = (e) => {
144
+ // Every open popover listens on document: without this, Escape in a submenu closes the parent menu too.
145
+ if (openPopovers.at(-1) !== openPopoverEntry) {
146
+ return;
147
+ }
135
148
  if (e.key === 'Escape') {
136
149
  e.preventDefault();
137
150
  closedByEscape = true;
@@ -156,9 +169,11 @@ $effect(() => {
156
169
  }
157
170
  }
158
171
  };
172
+ openPopovers.push(openPopoverEntry);
159
173
  window.addEventListener('pointerdown', handleOutsidePointerDown, true);
160
174
  document.addEventListener('keydown', handleKey, true);
161
175
  return () => {
176
+ openPopovers.splice(openPopovers.indexOf(openPopoverEntry), 1);
162
177
  window.removeEventListener('pointerdown', handleOutsidePointerDown, true);
163
178
  document.removeEventListener('keydown', handleKey, true);
164
179
  };
@@ -94,7 +94,9 @@ type Props = {
94
94
  * - `use:popoverIgnore={true}` action: block close for clicks anywhere in the marked sub-tree.
95
95
  */
96
96
  declare const Cmp: import("svelte").Component<Props, {
97
- /** Imperative API — bind:this on the component to access. */ open: () => void;
97
+ /** Imperative API — bind:this on the component to access. */ open: ({ moveFocus }?: {
98
+ moveFocus?: boolean;
99
+ }) => void;
98
100
  close: () => void;
99
101
  toggle: () => void;
100
102
  }, "">;
@@ -4,7 +4,10 @@ export { default as HoverPopover } from './cmp.hover-popover.svelte';
4
4
  export { popoverIgnore } from './popover-ignore';
5
5
  /** Imperative API exposed via `bind:this={instance}` on `<Popover>`. */
6
6
  export type PopoverInstance = {
7
- open: () => void;
7
+ /** `moveFocus: false` opens without focusing the first focusable in the content. */
8
+ open: (options?: {
9
+ moveFocus?: boolean;
10
+ }) => void;
8
11
  close: () => void;
9
12
  toggle: () => void;
10
13
  };
@@ -263,7 +263,7 @@ const handlePickRow = (row) => {
263
263
  {/if}
264
264
 
265
265
  <SelectListbox
266
- triggerEl={rootEl}
266
+ anchor={rootEl}
267
267
  isOpen={isPanelOpen}
268
268
  size={size}
269
269
  rows={rows}
@@ -140,7 +140,7 @@ const showClear = $derived(mode.clearable && hasValue && isInteractive && !core.
140
140
  {/if}
141
141
 
142
142
  <SelectListbox
143
- triggerEl={rootEl}
143
+ anchor={rootEl}
144
144
  isOpen={core.isOpen}
145
145
  size={size}
146
146
  rows={core.rows}
@@ -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';
@@ -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';
@@ -262,7 +262,7 @@ const handleDndFinalize = (e) => {
262
262
  {/if}
263
263
 
264
264
  <SelectListbox
265
- triggerEl={rootEl}
265
+ anchor={rootEl}
266
266
  isOpen={core.isOpen}
267
267
  size={size}
268
268
  rows={core.rows}
@@ -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 { triggerEl, isOpen, rows, highlight, loading = false, size = 'md', listboxId, matchTriggerWidth = true, selectedDisplay = 'checkmark', optionSnippet, headerSnippet, bodySnippet, hideCreateRows = false, createPrefix, suppressEmpty = false, on } = $props();
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 || !triggerEl || !panelEl) {
24
+ if (!isOpen || !anchor || !panelEl) {
24
25
  return;
25
26
  }
26
- const trigger = triggerEl;
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(trigger, panel, {
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 (bodySnippet) {
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(trigger, panel, update);
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 (triggerEl?.contains(target) || panelEl?.contains(target) || isInsideLabelOf(target, triggerEl)) {
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
- /** Anchor element — listbox positions itself below this. */
6
- triggerEl: HTMLElement | undefined;
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). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamscloud/kit",
3
- "version": "0.95.0",
3
+ "version": "0.95.2",
4
4
  "author": "StreamsCloud",
5
5
  "repository": {
6
6
  "type": "git",