@diegopluna/narvi 0.3.4 → 0.3.5

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.
Files changed (52) hide show
  1. package/dist/components/app-shell/AppShellPanel.svelte +35 -4
  2. package/dist/components/badge/Badge.svelte +13 -1
  3. package/dist/components/badge/Badge.svelte.d.ts +6 -0
  4. package/dist/components/button/Button.svelte +60 -32
  5. package/dist/components/button/Button.svelte.d.ts +6 -0
  6. package/dist/components/command/CommandDialog.svelte +24 -2
  7. package/dist/components/command/CommandDialog.svelte.d.ts +12 -0
  8. package/dist/components/command/CommandItem.svelte +15 -4
  9. package/dist/components/command/CommandItem.svelte.d.ts +20 -4
  10. package/dist/components/command/CommandRoot.svelte +57 -2
  11. package/dist/components/command/CommandRoot.svelte.d.ts +25 -1
  12. package/dist/components/composer/ComposerModelPicker.svelte +608 -53
  13. package/dist/components/composer/ComposerModelPicker.svelte.d.ts +56 -1
  14. package/dist/components/composer/ComposerRoot.svelte.d.ts +1 -1
  15. package/dist/components/composer/ComposerSubmit.svelte +12 -2
  16. package/dist/components/composer/ComposerSubmit.svelte.d.ts +6 -0
  17. package/dist/components/composer/index.d.ts +1 -1
  18. package/dist/components/input/Input.svelte.d.ts +1 -1
  19. package/dist/components/menu/MenuCheckboxItem.svelte +14 -5
  20. package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +15 -4
  21. package/dist/components/menu/MenuItem.svelte +9 -3
  22. package/dist/components/menu/MenuItem.svelte.d.ts +11 -4
  23. package/dist/components/menu/MenuRadioItem.svelte +18 -9
  24. package/dist/components/menu/MenuRadioItem.svelte.d.ts +15 -4
  25. package/dist/components/menu/MenuSubTrigger.svelte +9 -3
  26. package/dist/components/menu/MenuSubTrigger.svelte.d.ts +11 -4
  27. package/dist/components/questionnaire/Questionnaire.svelte +100 -9
  28. package/dist/components/questionnaire/Questionnaire.svelte.d.ts +11 -0
  29. package/dist/components/select/Select.svelte +11 -1
  30. package/dist/components/select/Select.svelte.d.ts +5 -0
  31. package/dist/components/slider/Slider.svelte.d.ts +2 -2
  32. package/dist/components/split-button/SplitButton.svelte +11 -1
  33. package/dist/components/split-button/SplitButton.svelte.d.ts +7 -0
  34. package/dist/components/tab-strip/TabStrip.svelte +77 -20
  35. package/dist/components/tab-strip/TabStrip.svelte.d.ts +16 -3
  36. package/dist/components/textarea/Textarea.svelte.d.ts +1 -1
  37. package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +1 -1
  38. package/dist/index.d.ts +1 -1
  39. package/dist/internal/ItemDescription.svelte +34 -0
  40. package/dist/internal/ItemDescription.svelte.d.ts +10 -0
  41. package/dist/internal/roving.d.ts +3 -1
  42. package/dist/internal/roving.js +6 -3
  43. package/dist/media.stylex.d.ts +6 -0
  44. package/dist/media.stylex.js +6 -0
  45. package/dist/vite.js +4 -0
  46. package/package.json +20 -1
  47. package/skills/building-ui/SKILL.md +30 -22
  48. package/skills/building-ui/references/components.md +22 -22
  49. package/skills/markdown/SKILL.md +1 -1
  50. package/skills/setup/SKILL.md +1 -1
  51. package/skills/styling/SKILL.md +11 -2
  52. package/skills/theming/SKILL.md +1 -1
@@ -5,6 +5,11 @@
5
5
  Where its row has no room for it beside the page (the row's width less the
6
6
  sidebar's, not the window's), it takes the page's place under the page's
7
7
  header. Maximized, it takes the page's place whole, header and all.
8
+
9
+ It can also stand in a row of your own inside AppShell.Main, beside a thread
10
+ rather than beside the page: a flex row with `position: relative`. It then
11
+ measures that row, and narrow or maximized it lies over the row, whose other
12
+ children are inert underneath.
8
13
  -->
9
14
  <script lang="ts" module>
10
15
  import * as stylex from '@stylexjs/stylex';
@@ -70,6 +75,8 @@
70
75
  },
71
76
  // Under the page's header, which stays in reach with the sidebar's toggle
72
77
  narrow: { insetBlockStart: '3rem' },
78
+ // In a row of the caller's own, over the whole row: its header is the panel's
79
+ inRow: { insetBlockStart: 0, insetInlineStart: 0 },
73
80
  // Over all of the page. Where the page's header kept room for the traffic lights, the
74
81
  // panel's own header keeps it now.
75
82
  maximized: { insetBlockStart: 0, '--narvi-inset-page': 'inherit' },
@@ -97,6 +104,8 @@
97
104
  // The room the row gives the page and the panel together, and where that room starts
98
105
  let row = $state(Infinity);
99
106
  let start = $state(0);
107
+ // Placed straight in the sheet, beside the page; otherwise in a row of the caller's own
108
+ let inSheet = $state(true);
100
109
 
101
110
  const sidebarOf = (sheet: Element | null | undefined) =>
102
111
  sheet?.querySelector<HTMLElement>(':scope > [data-slot="app-shell-sidebar"]') ?? null;
@@ -105,10 +114,11 @@
105
114
  $effect(() => {
106
115
  const sheet = element?.parentElement;
107
116
  if (!sheet) return;
117
+ inSheet = sheet.dataset.slot === 'app-shell-sheet';
108
118
  const measure = () => {
109
119
  const sidebar = sidebarOf(sheet);
110
120
  // A drawer is over the page, not beside it
111
- const beside = shell.narrow ? 0 : (sidebar?.offsetWidth ?? 0);
121
+ const beside = shell.narrow && inSheet ? 0 : (sidebar?.offsetWidth ?? 0);
112
122
  row = sheet.clientWidth - beside;
113
123
  start = beside;
114
124
  };
@@ -120,16 +130,31 @@
120
130
  return () => observer.disconnect();
121
131
  });
122
132
 
123
- const narrow = $derived(shell.narrow || row < minWidth + Math.max(mainMinWidth, 0));
133
+ const narrow = $derived((inSheet && shell.narrow) || row < minWidth + Math.max(mainMinWidth, 0));
124
134
  const over = $derived(maximized || narrow);
125
135
 
126
136
  // The page steps out of view under a maximized panel
127
137
  $effect(() => {
128
- if (!sheetContext || !maximized) return;
138
+ if (!sheetContext || !maximized || !inSheet) return;
129
139
  sheetContext.setCovered(true);
130
140
  return () => sheetContext.setCovered(false);
131
141
  });
132
142
 
143
+ // In a row of the caller's own, what the panel lies over is out of reach underneath:
144
+ // its siblings are inert, and come back as they were
145
+ $effect(() => {
146
+ const parent = element?.parentElement;
147
+ if (inSheet || !over || !parent || !element) return;
148
+ const covered = [...parent.children].filter(
149
+ (child): child is HTMLElement =>
150
+ child instanceof HTMLElement && child !== element && !child.inert
151
+ );
152
+ for (const child of covered) child.inert = true;
153
+ return () => {
154
+ for (const child of covered) child.inert = false;
155
+ };
156
+ });
157
+
133
158
  // It never takes so much that the main area falls below its minimum
134
159
  const largest = () => {
135
160
  // On the server there is no window to measure: no limit yet
@@ -166,7 +191,13 @@
166
191
  style:--narvi-panel-start="{start}px"
167
192
  {...rest}
168
193
  {...attrs(
169
- [styles.panel, over && styles.over, maximized ? styles.maximized : narrow && styles.narrow, sx],
194
+ [
195
+ styles.panel,
196
+ over && styles.over,
197
+ maximized ? styles.maximized : narrow && styles.narrow,
198
+ over && !inSheet && styles.inRow,
199
+ sx
200
+ ],
170
201
  className
171
202
  )}
172
203
  >
@@ -12,6 +12,12 @@
12
12
  export type BadgeProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children'> & {
13
13
  /** Colour of the dot. The words stay in the text colour, so they are always readable. */
14
14
  tone?: BadgeTone | undefined;
15
+ /**
16
+ * The dot in a colour of its own, any CSS colour, in place of a tone's: a label's colour
17
+ * as its owner chose it, such as a GitHub label's `#d73a4a`. Only the dot takes it, so the
18
+ * words stay readable whatever the colour.
19
+ */
20
+ color?: string | undefined;
15
21
  /**
16
22
  * Hides the dot, for a plain label or a count. A tone then colours the words, in its
17
23
  * text colour, which holds its contrast on a badge's own surface.
@@ -79,6 +85,7 @@
79
85
  <script lang="ts">
80
86
  let {
81
87
  tone = 'neutral',
88
+ color,
82
89
  plain = false,
83
90
  size = 'md',
84
91
  sx,
@@ -104,7 +111,12 @@
104
111
  )}
105
112
  >
106
113
  {#if !plain}
107
- <span aria-hidden="true" {...stylex.attrs(styles.dot, dots[tone])}></span>
114
+ <!-- A colour of the caller's own is set on the dot itself; forced colours keep it, as a tone's -->
115
+ <span
116
+ aria-hidden="true"
117
+ {...stylex.attrs(styles.dot, !color && dots[tone])}
118
+ style:background-color={color}
119
+ ></span>
108
120
  {/if}
109
121
  {@render children?.()}
110
122
  </span>
@@ -6,6 +6,12 @@ export type BadgeTone = 'neutral' | 'accent' | 'info' | 'success' | 'warning' |
6
6
  export type BadgeProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children'> & {
7
7
  /** Colour of the dot. The words stay in the text colour, so they are always readable. */
8
8
  tone?: BadgeTone | undefined;
9
+ /**
10
+ * The dot in a colour of its own, any CSS colour, in place of a tone's: a label's colour
11
+ * as its owner chose it, such as a GitHub label's `#d73a4a`. Only the dot takes it, so the
12
+ * words stay readable whatever the colour.
13
+ */
14
+ color?: string | undefined;
9
15
  /**
10
16
  * Hides the dot, for a plain label or a count. A tone then colours the words, in its
11
17
  * text colour, which holds its contrast on a badge's own surface.
@@ -7,6 +7,8 @@
7
7
  import { colors, font, motion, radius } from '../../tokens.stylex.js';
8
8
  import { media } from '../../media.stylex.js';
9
9
  import Spinner from '../spinner/Spinner.svelte';
10
+ import * as Tooltip from '../tooltip/index.js';
11
+ import { mergeProps } from 'bits-ui';
10
12
  import '../../internal/icons.css';
11
13
 
12
14
  /**
@@ -53,6 +55,12 @@
53
55
  pressed?: boolean | undefined;
54
56
  /** Square button for a single icon. Give it an `aria-label`. */
55
57
  iconOnly?: boolean | undefined;
58
+ /**
59
+ * A tooltip, shown as the pointer rests on it or the keyboard reaches it: words, or a
60
+ * snippet for words with a shortcut. It says more than the button's name, which stays as
61
+ * it is. It waits 400ms, as Narvi's other parts' tooltips do.
62
+ */
63
+ tooltip?: string | Snippet | undefined;
56
64
  /** Renders a link styled as a button. */
57
65
  href?: string | undefined;
58
66
  sx?: Sx | undefined;
@@ -455,6 +463,7 @@
455
463
  disabled = false,
456
464
  pressed,
457
465
  iconOnly = false,
466
+ tooltip,
458
467
  href,
459
468
  type = 'button',
460
469
  sx,
@@ -502,37 +511,56 @@
502
511
  {/if}
503
512
  {/snippet}
504
513
 
505
- {#if href !== undefined}
506
- <a
507
- bind:this={ref}
508
- data-icons
509
- href={inert ? undefined : href}
510
- role={inert ? 'link' : undefined}
511
- aria-disabled={inert ? true : undefined}
512
- aria-busy={loading ? true : undefined}
513
- {...rest}
514
- {...rootAttrs}
515
- >
516
- {@render content()}
517
- </a>
514
+ <!-- The element, with a tooltip trigger's props when it has a tooltip -->
515
+ {#snippet control(trigger: Record<string, unknown>)}
516
+ {@const own = Object.keys(trigger).length ? mergeProps(rest, trigger) : rest}
517
+ {#if href !== undefined}
518
+ <a
519
+ bind:this={ref}
520
+ data-icons
521
+ href={inert ? undefined : href}
522
+ role={inert ? 'link' : undefined}
523
+ aria-disabled={inert ? true : undefined}
524
+ aria-busy={loading ? true : undefined}
525
+ {...own}
526
+ {...rootAttrs}
527
+ >
528
+ {@render content()}
529
+ </a>
530
+ {:else}
531
+ <button
532
+ bind:this={ref}
533
+ data-icons
534
+ {type}
535
+ disabled={disabled || undefined}
536
+ aria-pressed={pressed}
537
+ aria-disabled={loading ? true : undefined}
538
+ aria-busy={loading ? true : undefined}
539
+ {...own}
540
+ {...rootAttrs}
541
+ onclick={loading
542
+ ? (event: MouseEvent) => {
543
+ event.preventDefault();
544
+ event.stopPropagation();
545
+ }
546
+ : (own.onclick as HTMLButtonAttributes['onclick'])}
547
+ >
548
+ {@render content()}
549
+ </button>
550
+ {/if}
551
+ {/snippet}
552
+
553
+ {#if tooltip}
554
+ <Tooltip.Provider delayDuration={400}>
555
+ <Tooltip.Root>
556
+ <Tooltip.Trigger>
557
+ {#snippet child({ props })}{@render control(props)}{/snippet}
558
+ </Tooltip.Trigger>
559
+ <Tooltip.Content>
560
+ {#if typeof tooltip === 'function'}{@render tooltip()}{:else}{tooltip}{/if}
561
+ </Tooltip.Content>
562
+ </Tooltip.Root>
563
+ </Tooltip.Provider>
518
564
  {:else}
519
- <button
520
- bind:this={ref}
521
- data-icons
522
- {type}
523
- disabled={disabled || undefined}
524
- aria-pressed={pressed}
525
- aria-disabled={loading ? true : undefined}
526
- aria-busy={loading ? true : undefined}
527
- {...rest}
528
- {...rootAttrs}
529
- onclick={loading
530
- ? (event) => {
531
- event.preventDefault();
532
- event.stopPropagation();
533
- }
534
- : rest.onclick}
535
- >
536
- {@render content()}
537
- </button>
565
+ {@render control({})}
538
566
  {/if}
@@ -33,6 +33,12 @@ export type ButtonProps = Omit<HTMLButtonAttributes & HTMLAnchorAttributes, 'chi
33
33
  pressed?: boolean | undefined;
34
34
  /** Square button for a single icon. Give it an `aria-label`. */
35
35
  iconOnly?: boolean | undefined;
36
+ /**
37
+ * A tooltip, shown as the pointer rests on it or the keyboard reaches it: words, or a
38
+ * snippet for words with a shortcut. It says more than the button's name, which stays as
39
+ * it is. It waits 400ms, as Narvi's other parts' tooltips do.
40
+ */
41
+ tooltip?: string | Snippet | undefined;
36
42
  /** Renders a link styled as a button. */
37
43
  href?: string | undefined;
38
44
  sx?: Sx | undefined;
@@ -11,6 +11,18 @@
11
11
  export type CommandDialogProps = {
12
12
  /** Whether it is open. Bindable. */
13
13
  open?: boolean | undefined;
14
+ /** Called as it opens or closes. */
15
+ onopenchange?: ((open: boolean) => void) | undefined;
16
+ /**
17
+ * Called as Escape is pressed. Call `event.preventDefault()` to keep it open: to go back
18
+ * a step of a palette that has several, or to wait while something is on its way.
19
+ */
20
+ onescape?: ((event: KeyboardEvent) => void) | undefined;
21
+ /**
22
+ * Whether focus goes back where it was as it closes. Pass `false` after a command that
23
+ * put the focus somewhere of its own, such as a thread it opened.
24
+ */
25
+ restoreFocus?: boolean | undefined;
14
26
  /** What the palette is, for assistive technology. */
15
27
  label?: string | undefined;
16
28
  /** A Command.Root with its Input, List and Footer. */
@@ -22,14 +34,24 @@
22
34
  let {
23
35
  open = $bindable(false),
24
36
  label = 'Command palette',
37
+ onopenchange,
38
+ onescape,
39
+ restoreFocus = true,
25
40
  children
26
41
  }: CommandDialogProps = $props();
27
42
  </script>
28
43
 
29
- <Dialog.Root bind:open>
44
+ <Dialog.Root bind:open onOpenChange={onopenchange}>
30
45
  <Dialog.Portal>
31
46
  <Dialog.Overlay {...stylex.attrs(command.overlay)} />
32
- <Dialog.Content data-slot="command-dialog" {...stylex.attrs(command.dialog)}>
47
+ <Dialog.Content
48
+ data-slot="command-dialog"
49
+ onEscapeKeydown={onescape}
50
+ onCloseAutoFocus={(event) => {
51
+ if (!restoreFocus) event.preventDefault();
52
+ }}
53
+ {...stylex.attrs(command.dialog)}
54
+ >
33
55
  <Dialog.Title {...stylex.attrs(command.hidden)}>{label}</Dialog.Title>
34
56
  {@render children?.()}
35
57
  </Dialog.Content>
@@ -2,6 +2,18 @@ import type { Snippet } from 'svelte';
2
2
  export type CommandDialogProps = {
3
3
  /** Whether it is open. Bindable. */
4
4
  open?: boolean | undefined;
5
+ /** Called as it opens or closes. */
6
+ onopenchange?: ((open: boolean) => void) | undefined;
7
+ /**
8
+ * Called as Escape is pressed. Call `event.preventDefault()` to keep it open: to go back
9
+ * a step of a palette that has several, or to wait while something is on its way.
10
+ */
11
+ onescape?: ((event: KeyboardEvent) => void) | undefined;
12
+ /**
13
+ * Whether focus goes back where it was as it closes. Pass `false` after a command that
14
+ * put the focus somewhere of its own, such as a thread it opened.
15
+ */
16
+ restoreFocus?: boolean | undefined;
5
17
  /** What the palette is, for assistive technology. */
6
18
  label?: string | undefined;
7
19
  /** A Command.Root with its Input, List and Footer. */
@@ -12,8 +12,16 @@
12
12
  Omit<Command.ItemProps, 'children' | 'child'> & {
13
13
  /** A 16px icon before the label. */
14
14
  icon?: Snippet | undefined;
15
- /** A quieter note after the label, such as where a thread lives. */
16
- detail?: string | undefined;
15
+ /**
16
+ * A quieter note after the label, such as where a thread lives: words, or a snippet,
17
+ * such as one with the words that match the search marked.
18
+ */
19
+ detail?: string | Snippet | undefined;
20
+ /**
21
+ * What the key cap on the highlighted item says Enter does. `↵` by default; words such
22
+ * as "Open" for an item that does something of its own, or `null` for none.
23
+ */
24
+ hint?: string | null | undefined;
17
25
  /** The keys that do the same from anywhere, such as "⌘N". */
18
26
  shortcut?: string | undefined;
19
27
  sx?: Sx | undefined;
@@ -27,6 +35,7 @@
27
35
  icon,
28
36
  detail,
29
37
  shortcut,
38
+ hint = '↵',
30
39
  sx,
31
40
  class: className,
32
41
  children,
@@ -40,12 +49,14 @@
40
49
  {#if icon}<span data-icons {...stylex.attrs(layer.icon)}>{@render icon()}</span>{/if}
41
50
  <span {...stylex.attrs(layer.label)}>
42
51
  {@render children?.()}
43
- {#if detail}<span {...stylex.attrs(command.detail)}>{detail}</span>{/if}
52
+ {#if detail}<span {...stylex.attrs(command.detail)}
53
+ >{#if typeof detail === 'function'}{@render detail()}{:else}{detail}{/if}</span
54
+ >{/if}
44
55
  </span>
45
56
  <span {...stylex.attrs(layer.trailing)}>
46
57
  {#if shortcut}{shortcut}{/if}
47
58
  <!-- Enter is the way to choose, shown only on the highlighted row -->
48
- {#if props['data-selected'] !== undefined}<Kbd>↵</Kbd>{/if}
59
+ {#if hint !== null && props['data-selected'] !== undefined}<Kbd>{hint}</Kbd>{/if}
49
60
  </span>
50
61
  </div>
51
62
  {/snippet}
@@ -5,8 +5,16 @@ import { type Sx } from '../../internal/sx.js';
5
5
  export type CommandItemProps = Loose<Omit<Command.ItemProps, 'children' | 'child'> & {
6
6
  /** A 16px icon before the label. */
7
7
  icon?: Snippet | undefined;
8
- /** A quieter note after the label, such as where a thread lives. */
9
- detail?: string | undefined;
8
+ /**
9
+ * A quieter note after the label, such as where a thread lives: words, or a snippet,
10
+ * such as one with the words that match the search marked.
11
+ */
12
+ detail?: string | Snippet | undefined;
13
+ /**
14
+ * What the key cap on the highlighted item says Enter does. `↵` by default; words such
15
+ * as "Open" for an item that does something of its own, or `null` for none.
16
+ */
17
+ hint?: string | null | undefined;
10
18
  /** The keys that do the same from anywhere, such as "⌘N". */
11
19
  shortcut?: string | undefined;
12
20
  sx?: Sx | undefined;
@@ -15,8 +23,16 @@ export type CommandItemProps = Loose<Omit<Command.ItemProps, 'children' | 'child
15
23
  declare const CommandItem: import("svelte").Component<Loose<Omit<Command.ItemProps, "children" | "child"> & {
16
24
  /** A 16px icon before the label. */
17
25
  icon?: Snippet | undefined;
18
- /** A quieter note after the label, such as where a thread lives. */
19
- detail?: string | undefined;
26
+ /**
27
+ * A quieter note after the label, such as where a thread lives: words, or a snippet,
28
+ * such as one with the words that match the search marked.
29
+ */
30
+ detail?: string | Snippet | undefined;
31
+ /**
32
+ * What the key cap on the highlighted item says Enter does. `↵` by default; words such
33
+ * as "Open" for an item that does something of its own, or `null` for none.
34
+ */
35
+ hint?: string | null | undefined;
20
36
  /** The keys that do the same from anywhere, such as "⌘N". */
21
37
  shortcut?: string | undefined;
22
38
  sx?: Sx | undefined;
@@ -7,17 +7,72 @@
7
7
 
8
8
  export type CommandRootProps = Loose<
9
9
  Omit<Command.RootProps, 'children' | 'child'> & {
10
+ /**
11
+ * The value of the highlighted item. Bindable: set it to move the highlight from
12
+ * outside, such as back to the first result as the app's own results change.
13
+ */
14
+ value?: string | undefined;
15
+ /**
16
+ * Whether it filters and sorts the items itself, as the search changes. Pass `false`
17
+ * to rank them yourself and list only those that match: results from a server, say.
18
+ */
19
+ shouldFilter?: boolean | undefined;
10
20
  sx?: Sx | undefined;
11
21
  /** A Command.Input, a Command.List and, if you like, a Command.Footer. */
12
22
  children?: Snippet | undefined;
13
23
  }
14
24
  >;
25
+
26
+ // Page Up and Page Down move the highlight this many items
27
+ const PAGE = 8;
15
28
  </script>
16
29
 
17
30
  <script lang="ts">
18
- let { loop = true, sx, class: className, children, ...rest }: CommandRootProps = $props();
31
+ let {
32
+ value = $bindable(''),
33
+ loop = true,
34
+ sx,
35
+ class: className,
36
+ children,
37
+ onkeydown,
38
+ ...rest
39
+ }: CommandRootProps = $props();
40
+
41
+ let root = $state<ReturnType<typeof Command.Root> | null>(null);
42
+
43
+ /** The items that can be highlighted, in order: not disabled, and not filtered out. */
44
+ export function getValidItems(): HTMLElement[] {
45
+ return root?.getValidItems() ?? [];
46
+ }
47
+
48
+ /** Highlights the item at `index` among the valid items. */
49
+ export function highlight(index: number): void {
50
+ root?.updateSelectedToIndex(index);
51
+ }
52
+
53
+ /** Moves the highlight by `step` items, stopping at the ends. */
54
+ export function move(step: number): void {
55
+ const items = getValidItems();
56
+ if (!items.length) return;
57
+ const at = items.findIndex((item) => item.hasAttribute('data-selected'));
58
+ highlight(Math.min(Math.max((at === -1 ? 0 : at) + step, 0), items.length - 1));
59
+ }
19
60
  </script>
20
61
 
21
- <Command.Root {loop} data-slot="command" {...rest} {...attrs([command.root, sx], className)}>
62
+ <Command.Root
63
+ bind:this={root}
64
+ bind:value
65
+ {loop}
66
+ data-slot="command"
67
+ {...rest}
68
+ onkeydown={(event: KeyboardEvent & { currentTarget: HTMLDivElement }) => {
69
+ onkeydown?.(event);
70
+ if (event.defaultPrevented || event.isComposing) return;
71
+ if (event.key !== 'PageDown' && event.key !== 'PageUp') return;
72
+ event.preventDefault();
73
+ move(event.key === 'PageDown' ? PAGE : -PAGE);
74
+ }}
75
+ {...attrs([command.root, sx], className)}
76
+ >
22
77
  {@render children?.()}
23
78
  </Command.Root>
@@ -3,14 +3,38 @@ import { Command } from 'bits-ui';
3
3
  import type { Snippet } from 'svelte';
4
4
  import { type Sx } from '../../internal/sx.js';
5
5
  export type CommandRootProps = Loose<Omit<Command.RootProps, 'children' | 'child'> & {
6
+ /**
7
+ * The value of the highlighted item. Bindable: set it to move the highlight from
8
+ * outside, such as back to the first result as the app's own results change.
9
+ */
10
+ value?: string | undefined;
11
+ /**
12
+ * Whether it filters and sorts the items itself, as the search changes. Pass `false`
13
+ * to rank them yourself and list only those that match: results from a server, say.
14
+ */
15
+ shouldFilter?: boolean | undefined;
6
16
  sx?: Sx | undefined;
7
17
  /** A Command.Input, a Command.List and, if you like, a Command.Footer. */
8
18
  children?: Snippet | undefined;
9
19
  }>;
10
20
  declare const CommandRoot: import("svelte").Component<Loose<Omit<Command.RootProps, "children" | "child"> & {
21
+ /**
22
+ * The value of the highlighted item. Bindable: set it to move the highlight from
23
+ * outside, such as back to the first result as the app's own results change.
24
+ */
25
+ value?: string | undefined;
26
+ /**
27
+ * Whether it filters and sorts the items itself, as the search changes. Pass `false`
28
+ * to rank them yourself and list only those that match: results from a server, say.
29
+ */
30
+ shouldFilter?: boolean | undefined;
11
31
  sx?: Sx | undefined;
12
32
  /** A Command.Input, a Command.List and, if you like, a Command.Footer. */
13
33
  children?: Snippet | undefined;
14
- }>, {}, "">;
34
+ }>, {
35
+ getValidItems: () => HTMLElement[];
36
+ highlight: (index: number) => void;
37
+ move: (step: number) => void;
38
+ }, "value">;
15
39
  type CommandRoot = ReturnType<typeof CommandRoot>;
16
40
  export default CommandRoot;