@diegopluna/narvi 0.4.1 → 0.5.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.
Files changed (180) hide show
  1. package/README.md +3 -1
  2. package/dist/base.css +3 -0
  3. package/dist/components/app-shell/AppShellPanel.svelte +3 -2
  4. package/dist/components/button/Button.svelte +29 -17
  5. package/dist/components/checkbox/Checkbox.svelte +106 -54
  6. package/dist/components/checkbox/Checkbox.svelte.d.ts +22 -8
  7. package/dist/components/choice-cards/ChoiceCards.svelte +68 -39
  8. package/dist/components/choice-cards/ChoiceCards.svelte.d.ts +12 -8
  9. package/dist/components/collapsible/CollapsibleContent.svelte +71 -17
  10. package/dist/components/collapsible/CollapsibleContent.svelte.d.ts +14 -10
  11. package/dist/components/collapsible/CollapsibleRoot.svelte +13 -9
  12. package/dist/components/collapsible/CollapsibleRoot.svelte.d.ts +8 -9
  13. package/dist/components/collapsible/CollapsibleTrigger.svelte +24 -15
  14. package/dist/components/collapsible/CollapsibleTrigger.svelte.d.ts +10 -14
  15. package/dist/components/color-field/ColorField.svelte +13 -7
  16. package/dist/components/command/CommandDialog.svelte +30 -20
  17. package/dist/components/command/CommandDialog.svelte.d.ts +4 -3
  18. package/dist/components/command/CommandEmpty.svelte +11 -9
  19. package/dist/components/command/CommandEmpty.svelte.d.ts +6 -17
  20. package/dist/components/command/CommandGroup.svelte +32 -11
  21. package/dist/components/command/CommandGroup.svelte.d.ts +7 -11
  22. package/dist/components/command/CommandInput.svelte +25 -10
  23. package/dist/components/command/CommandInput.svelte.d.ts +8 -12
  24. package/dist/components/command/CommandItem.svelte +67 -29
  25. package/dist/components/command/CommandItem.svelte.d.ts +6 -32
  26. package/dist/components/command/CommandList.svelte +8 -10
  27. package/dist/components/command/CommandList.svelte.d.ts +6 -8
  28. package/dist/components/command/CommandRoot.svelte +247 -57
  29. package/dist/components/command/CommandRoot.svelte.d.ts +14 -28
  30. package/dist/components/command/CommandSeparator.svelte +18 -0
  31. package/dist/components/command/CommandSeparator.svelte.d.ts +7 -0
  32. package/dist/components/command/context.d.ts +27 -0
  33. package/dist/components/command/context.js +16 -0
  34. package/dist/components/command/index.d.ts +6 -4
  35. package/dist/components/command/index.js +5 -4
  36. package/dist/components/command/score.d.ts +27 -0
  37. package/dist/components/command/score.js +77 -0
  38. package/dist/components/command/styles.d.ts +32 -9
  39. package/dist/components/command/styles.js +42 -14
  40. package/dist/components/composer/ComposerModelPicker.svelte +350 -346
  41. package/dist/components/composer/ComposerModelPicker.svelte.d.ts +6 -3
  42. package/dist/components/composer/ComposerRoot.svelte.d.ts +1 -1
  43. package/dist/components/dialog/ConfirmDialog.svelte +73 -53
  44. package/dist/components/dialog/DialogClose.svelte +17 -0
  45. package/dist/components/dialog/DialogClose.svelte.d.ts +10 -0
  46. package/dist/components/dialog/DialogContent.svelte +35 -33
  47. package/dist/components/dialog/DialogContent.svelte.d.ts +6 -20
  48. package/dist/components/dialog/DialogDescription.svelte +9 -12
  49. package/dist/components/dialog/DialogDescription.svelte.d.ts +6 -8
  50. package/dist/components/dialog/DialogRoot.svelte +20 -0
  51. package/dist/components/dialog/DialogRoot.svelte.d.ts +7 -0
  52. package/dist/components/dialog/DialogTitle.svelte +12 -8
  53. package/dist/components/dialog/DialogTitle.svelte.d.ts +8 -8
  54. package/dist/components/dialog/DialogTrigger.svelte +17 -0
  55. package/dist/components/dialog/DialogTrigger.svelte.d.ts +10 -0
  56. package/dist/components/dialog/index.d.ts +6 -5
  57. package/dist/components/dialog/index.js +3 -6
  58. package/dist/components/dialog/styles.d.ts +1 -2
  59. package/dist/components/dialog/styles.js +11 -8
  60. package/dist/components/hover-card/HoverCardContent.svelte +35 -29
  61. package/dist/components/hover-card/HoverCardContent.svelte.d.ts +8 -12
  62. package/dist/components/hover-card/HoverCardRoot.svelte +7 -7
  63. package/dist/components/hover-card/HoverCardRoot.svelte.d.ts +5 -4
  64. package/dist/components/hover-card/HoverCardTrigger.svelte +18 -0
  65. package/dist/components/hover-card/HoverCardTrigger.svelte.d.ts +10 -0
  66. package/dist/components/hover-card/index.d.ts +2 -3
  67. package/dist/components/hover-card/index.js +1 -5
  68. package/dist/components/input/Input.svelte.d.ts +1 -1
  69. package/dist/components/markdown/MarkdownBlock.svelte +6 -3
  70. package/dist/components/markdown/MarkdownTable.svelte +15 -7
  71. package/dist/components/menu/ContextMenuContent.svelte +15 -15
  72. package/dist/components/menu/ContextMenuContent.svelte.d.ts +6 -9
  73. package/dist/components/menu/ContextMenuTrigger.svelte +14 -16
  74. package/dist/components/menu/ContextMenuTrigger.svelte.d.ts +8 -14
  75. package/dist/components/menu/MenuCheckboxItem.svelte +22 -11
  76. package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +8 -22
  77. package/dist/components/menu/MenuContent.svelte +16 -18
  78. package/dist/components/menu/MenuContent.svelte.d.ts +6 -18
  79. package/dist/components/menu/MenuGroup.svelte +4 -4
  80. package/dist/components/menu/MenuGroup.svelte.d.ts +5 -4
  81. package/dist/components/menu/MenuItem.svelte +25 -12
  82. package/dist/components/menu/MenuItem.svelte.d.ts +6 -21
  83. package/dist/components/menu/MenuLabel.svelte +7 -11
  84. package/dist/components/menu/MenuLabel.svelte.d.ts +6 -8
  85. package/dist/components/menu/MenuRadioGroup.svelte +4 -4
  86. package/dist/components/menu/MenuRadioGroup.svelte.d.ts +5 -4
  87. package/dist/components/menu/MenuRadioItem.svelte +16 -14
  88. package/dist/components/menu/MenuRadioItem.svelte.d.ts +6 -19
  89. package/dist/components/menu/MenuSeparator.svelte +6 -10
  90. package/dist/components/menu/MenuSeparator.svelte.d.ts +6 -7
  91. package/dist/components/menu/MenuSubContent.svelte +22 -19
  92. package/dist/components/menu/MenuSubContent.svelte.d.ts +8 -15
  93. package/dist/components/menu/MenuSubTrigger.svelte +7 -11
  94. package/dist/components/menu/MenuSubTrigger.svelte.d.ts +6 -15
  95. package/dist/components/menu/MenuTrigger.svelte +17 -0
  96. package/dist/components/menu/MenuTrigger.svelte.d.ts +10 -0
  97. package/dist/components/menu/context-menu.d.ts +2 -2
  98. package/dist/components/menu/context-menu.js +3 -2
  99. package/dist/components/menu/group.js +1 -1
  100. package/dist/components/menu/index.d.ts +5 -4
  101. package/dist/components/menu/index.js +5 -5
  102. package/dist/components/menu/row.d.ts +20 -0
  103. package/dist/components/menu/row.js +12 -0
  104. package/dist/components/popover/PopoverClose.svelte +17 -0
  105. package/dist/components/popover/PopoverClose.svelte.d.ts +10 -0
  106. package/dist/components/popover/PopoverContent.svelte +30 -29
  107. package/dist/components/popover/PopoverContent.svelte.d.ts +6 -17
  108. package/dist/components/popover/PopoverTrigger.svelte +17 -0
  109. package/dist/components/popover/PopoverTrigger.svelte.d.ts +10 -0
  110. package/dist/components/popover/index.d.ts +6 -4
  111. package/dist/components/popover/index.js +6 -5
  112. package/dist/components/progress/Progress.svelte +16 -22
  113. package/dist/components/progress/Progress.svelte.d.ts +6 -5
  114. package/dist/components/reasoning/ReasoningRoot.svelte.d.ts +1 -1
  115. package/dist/components/resize-handle/ResizeHandle.svelte +80 -14
  116. package/dist/components/resize-handle/ResizeHandle.svelte.d.ts +15 -1
  117. package/dist/components/segmented/SegmentedControl.svelte +100 -91
  118. package/dist/components/segmented/SegmentedControl.svelte.d.ts +6 -4
  119. package/dist/components/select/Select.svelte +97 -59
  120. package/dist/components/select/Select.svelte.d.ts +3 -2
  121. package/dist/components/sheet/SheetContent.svelte +31 -38
  122. package/dist/components/sheet/SheetContent.svelte.d.ts +7 -22
  123. package/dist/components/sheet/index.d.ts +3 -5
  124. package/dist/components/sheet/index.js +3 -5
  125. package/dist/components/sheet/styles.js +26 -5
  126. package/dist/components/sidebar/SidebarItem.svelte +2 -3
  127. package/dist/components/slider/Slider.svelte +86 -65
  128. package/dist/components/slider/Slider.svelte.d.ts +9 -8
  129. package/dist/components/split-button/SplitButton.svelte +20 -3
  130. package/dist/components/split-button/SplitButton.svelte.d.ts +1 -1
  131. package/dist/components/switch/Switch.svelte +77 -49
  132. package/dist/components/switch/Switch.svelte.d.ts +15 -8
  133. package/dist/components/tab-strip/TabStrip.svelte +87 -68
  134. package/dist/components/tabs/Tabs.svelte +129 -99
  135. package/dist/components/tabs/Tabs.svelte.d.ts +6 -4
  136. package/dist/components/textarea/Textarea.svelte.d.ts +1 -1
  137. package/dist/components/toast/Toaster.svelte +132 -115
  138. package/dist/components/toast/Toaster.svelte.d.ts +5 -0
  139. package/dist/components/toast/toasts.svelte.d.ts +10 -23
  140. package/dist/components/toast/toasts.svelte.js +62 -40
  141. package/dist/components/toggle/Toggle.svelte +15 -9
  142. package/dist/components/toggle/Toggle.svelte.d.ts +8 -17
  143. package/dist/components/toggle-group/ToggleGroupItem.svelte +20 -9
  144. package/dist/components/toggle-group/ToggleGroupItem.svelte.d.ts +10 -10
  145. package/dist/components/toggle-group/ToggleGroupRoot.svelte +33 -18
  146. package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +4 -4
  147. package/dist/components/tool/ToolRoot.svelte.d.ts +1 -1
  148. package/dist/components/tooltip/TooltipContent.svelte +38 -28
  149. package/dist/components/tooltip/TooltipContent.svelte.d.ts +6 -15
  150. package/dist/components/tooltip/TooltipProvider.svelte +34 -10
  151. package/dist/components/tooltip/TooltipProvider.svelte.d.ts +18 -4
  152. package/dist/components/tooltip/TooltipRoot.svelte +52 -23
  153. package/dist/components/tooltip/TooltipRoot.svelte.d.ts +10 -10
  154. package/dist/components/tooltip/TooltipTrigger.svelte +14 -17
  155. package/dist/components/tooltip/TooltipTrigger.svelte.d.ts +10 -4
  156. package/dist/components/tooltip/index.d.ts +1 -1
  157. package/dist/components/tooltip/index.js +1 -1
  158. package/dist/components/work-fold/WorkFold.svelte +14 -5
  159. package/dist/index.d.ts +5 -5
  160. package/dist/index.js +1 -1
  161. package/dist/internal/TooltipScope.svelte +4 -4
  162. package/dist/internal/layer.d.ts +11 -9
  163. package/dist/internal/layer.js +21 -15
  164. package/dist/internal/loose.d.ts +30 -5
  165. package/dist/internal/loose.js +1 -1
  166. package/dist/internal/markers.stylex.d.ts +0 -4
  167. package/dist/internal/markers.stylex.js +0 -2
  168. package/dist/internal/toggle.d.ts +3 -0
  169. package/dist/internal/toggle.js +6 -2
  170. package/dist/internal/tooltip-trigger.d.ts +7 -6
  171. package/dist/internal/tooltip-trigger.js +9 -12
  172. package/dist/vite.d.ts +7 -1
  173. package/dist/vite.js +20 -5
  174. package/package.json +3 -2
  175. package/skills/building-ui/SKILL.md +22 -22
  176. package/skills/building-ui/references/components.md +30 -4
  177. package/skills/markdown/SKILL.md +1 -1
  178. package/skills/setup/SKILL.md +4 -8
  179. package/skills/styling/SKILL.md +1 -1
  180. package/skills/theming/SKILL.md +3 -7
@@ -1,4 +1,19 @@
1
+ <!--
2
+ The composer's choice of model: a select-only combobox on ui-sdk's Select, whose list can
3
+ have a rail of providers beside it, a search field over it, stars, a fold of older models,
4
+ and models chosen beside the one picked.
5
+ -->
1
6
  <script lang="ts" module>
7
+ import {
8
+ Select as UiSelect,
9
+ SelectContent,
10
+ SelectGroup,
11
+ SelectGroupLabel,
12
+ SelectInput,
13
+ SelectItem,
14
+ SelectList,
15
+ SelectTrigger
16
+ } from '@ui-sdk/svelte/select';
2
17
  import * as stylex from '@stylexjs/stylex';
3
18
  import type { Snippet } from 'svelte';
4
19
  import type { HTMLButtonAttributes } from 'svelte/elements';
@@ -73,10 +88,16 @@
73
88
  starred?: string[] | undefined;
74
89
  /** Called as a model is starred or unstarred. */
75
90
  onstar?: ((value: string, starred: boolean) => void) | undefined;
76
- /** Its words: the search field's name, what no match says, and a star's two states. */
91
+ /**
92
+ * Its words: the search field's name, what no match says, a star's two states, and what the
93
+ * button says with no models to choose from (`none`).
94
+ */
77
95
  labels?:
78
96
  | Partial<
79
- Record<'search' | 'noMatch' | 'starred' | 'unstarred' | 'older' | 'alsoHint', string>
97
+ Record<
98
+ 'search' | 'noMatch' | 'starred' | 'unstarred' | 'older' | 'alsoHint' | 'none',
99
+ string
100
+ >
80
101
  >
81
102
  | undefined;
82
103
  sx?: Sx | undefined;
@@ -115,9 +136,14 @@
115
136
  }
116
137
  );
117
138
 
139
+ // The gap between the button and the list, and the room the list keeps from the window's edges
118
140
  const GAP = 6;
119
141
  const MARGIN = 8;
120
142
 
143
+ const STARTING = ':is([data-starting-style])';
144
+ const CLOSED = ':is([data-ending-style])';
145
+ const HIGHLIGHTED = ':is([data-highlighted])';
146
+
121
147
  /** A length at the window's density (`density` in the tokens). */
122
148
  const d = (rem: string) => `calc(${rem} * ${density.factor})`;
123
149
 
@@ -128,6 +154,9 @@
128
154
  flexShrink: 1,
129
155
  gap: '0.25rem',
130
156
  minWidth: 0,
157
+ // Never wider than what holds it: a long name is cut short with an ellipsis, as when a
158
+ // toolbar squeezes it
159
+ maxWidth: '100%',
131
160
  height: d('1.75rem'),
132
161
  margin: 0,
133
162
  paddingInlineStart: d('0.625rem'),
@@ -165,21 +194,23 @@
165
194
  more: { flexShrink: 0, color: colors.textSubtle, fontVariantNumeric: 'tabular-nums' },
166
195
  selector: { display: 'grid', flexShrink: 0, opacity: 0.7 },
167
196
 
168
- // The list floats in the top layer, placed beside the button by script.
169
- // It grows out of the button, and goes a little faster than it came.
197
+ // The list floats in the top layer, placed by ui-sdk below the button, or above it when
198
+ // there is no room below, as for a composer at the foot of the page. It grows out of the
199
+ // button, and goes a little faster than it came. ui-sdk shows it as a popover without
200
+ // undoing the browser's popover styles: the border and the margin are undone here.
170
201
  popover: {
171
- position: 'fixed',
172
- inset: 'auto',
173
202
  boxSizing: 'border-box',
174
203
  width: 'max-content',
175
204
  minWidth: '15rem',
176
205
  maxWidth: 'min(320px, calc(100vw - 16px))',
177
- maxHeight: 'min(360px, var(--narvi-picker-room, 360px))',
206
+ // ui-sdk's room is not inherited; the rail reads it through a property of Narvi's
207
+ '--narvi-picker-room': 'min(360px, var(--available-height, 360px))',
208
+ maxHeight: 'var(--narvi-picker-room)',
178
209
  margin: 0,
179
210
  padding: d('0.25rem'),
180
211
  overflowY: 'auto',
181
212
  overscrollBehavior: 'contain',
182
- borderWidth: 0,
213
+ borderStyle: 'none',
183
214
  // Inner items are 8px round with 4px of padding: 12px outside, at the default density
184
215
  borderRadius: radius.card,
185
216
  backgroundColor: colors.bgRaised,
@@ -189,18 +220,14 @@
189
220
  outlineStyle: 'solid',
190
221
  outlineWidth: { default: 0, [media.forcedColors]: '1px' },
191
222
  outlineColor: 'CanvasText',
192
- transformOrigin: 'var(--narvi-picker-origin, top left)',
193
- opacity: { default: 0, ':popover-open': { default: 1, '@starting-style': 0 } },
223
+ transformOrigin: 'var(--transform-origin, top left)',
224
+ opacity: { default: 1, '@starting-style': 0, [STARTING]: 0, [CLOSED]: 0 },
194
225
  scale: {
195
226
  default: null,
196
- [media.motion]: { default: 0.97, ':popover-open': { default: 1, '@starting-style': 0.97 } }
227
+ [media.motion]: { default: 1, '@starting-style': 0.97, [STARTING]: 0.97, [CLOSED]: 0.97 }
197
228
  },
198
- transitionProperty: {
199
- default: 'opacity, display, overlay',
200
- [media.motion]: 'opacity, scale, display, overlay'
201
- },
202
- transitionBehavior: 'allow-discrete',
203
- transitionDuration: { default: '100ms', ':popover-open': '160ms' },
229
+ transitionProperty: { default: 'opacity', [media.motion]: 'opacity, scale' },
230
+ transitionDuration: { default: '160ms', [CLOSED]: '100ms' },
204
231
  transitionTimingFunction: motion.easeOut
205
232
  },
206
233
  // With a rail, a little wider, for the rail's column
@@ -220,7 +247,13 @@
220
247
  display: 'flex',
221
248
  flexDirection: 'column',
222
249
  gap: d('0.125rem'),
223
- flexShrink: 0
250
+ flexShrink: 0,
251
+ // Many providers scroll in the rail, which stays in the popup's room while the list
252
+ // scrolls beside it
253
+ maxHeight: `calc(var(--narvi-picker-room, 360px) - 2 * ${d('0.25rem')})`,
254
+ overflowY: 'auto',
255
+ overscrollBehavior: 'contain',
256
+ scrollbarWidth: 'none'
224
257
  },
225
258
  divider: {
226
259
  alignSelf: 'stretch',
@@ -233,6 +266,8 @@
233
266
  '--narvi-icon-size': '1rem',
234
267
  display: 'grid',
235
268
  placeItems: 'center',
269
+ // Its full size in a rail that scrolls, rather than squeezed to fit
270
+ flexShrink: 0,
236
271
  width: d('2rem'),
237
272
  height: d('2rem'),
238
273
  margin: 0,
@@ -288,14 +323,19 @@
288
323
  borderRadius: radius.control,
289
324
  cursor: 'pointer',
290
325
  userSelect: 'none',
291
- WebkitTapHighlightColor: 'transparent'
292
- },
293
- // The option the keyboard or pointer is on. No transition: it follows the
294
- // arrow keys, which are pressed many times in a row.
295
- active: {
296
- backgroundColor: { default: colors.fillHover, [media.forcedColors]: 'Highlight' },
297
- color: { default: null, [media.forcedColors]: 'HighlightText' },
298
- forcedColorAdjust: 'none'
326
+ outlineStyle: 'none',
327
+ WebkitTapHighlightColor: 'transparent',
328
+ // The option the keyboard or pointer is on, which ui-sdk marks. No transition: it
329
+ // follows the arrow keys, which are pressed many times in a row.
330
+ backgroundColor: {
331
+ default: null,
332
+ [HIGHLIGHTED]: { default: colors.fillHover, [media.forcedColors]: 'Highlight' }
333
+ },
334
+ color: {
335
+ default: null,
336
+ [HIGHLIGHTED]: { default: null, [media.forcedColors]: 'HighlightText' }
337
+ },
338
+ forcedColorAdjust: { default: null, [HIGHLIGHTED]: 'none' }
299
339
  },
300
340
  optionDisabled: {
301
341
  opacity: 0.45,
@@ -433,6 +473,7 @@
433
473
  },
434
474
  railRule: {
435
475
  alignSelf: 'stretch',
476
+ flexShrink: 0,
436
477
  height: '1px',
437
478
  marginBlock: d('0.125rem'),
438
479
  backgroundColor: colors.border
@@ -464,7 +505,8 @@
464
505
  starred: 'Starred',
465
506
  unstarred: 'Not starred',
466
507
  older: 'Older models',
467
- alsoHint: 'Shift-click or ⌘-click a model to send to it too.'
508
+ alsoHint: 'Shift-click or ⌘-click a model to send to it too.',
509
+ none: 'No models'
468
510
  };
469
511
 
470
512
  // The row that folds older models away, among the options the keyboard goes through
@@ -484,7 +526,7 @@
484
526
  </script>
485
527
 
486
528
  <script lang="ts">
487
- import { untrack } from 'svelte';
529
+ import { tick, untrack } from 'svelte';
488
530
 
489
531
  let {
490
532
  models,
@@ -508,26 +550,60 @@
508
550
  sx,
509
551
  class: className,
510
552
  ref = $bindable(null),
511
- onclick,
512
- onkeydown,
513
553
  ...rest
514
554
  }: ComposerModelPickerProps = $props();
515
555
 
556
+ /** What ui-sdk's change callbacks are given, as much of it as the picker reads. */
557
+ type Details = { reason: string; event?: Event | undefined; cancel: () => void };
558
+
516
559
  const composer = getComposerContext();
517
- const uid = $props.id();
518
560
 
519
- let popover = $state<HTMLDivElement | null>(null);
520
- let list = $state<HTMLDivElement | null>(null);
561
+ let content = $state<HTMLElement | null>(null);
521
562
  let field = $state<HTMLInputElement | null>(null);
563
+ // The model, or the row of older models, that ui-sdk has highlighted
522
564
  let active = $state<string>();
523
565
  let query = $state('');
524
566
  let announcement = $state('');
567
+ // From opening until the list has gone, its exit included: until then it keeps what it shows
568
+ let live = $state(false);
525
569
 
526
570
  const word = $derived({ ...LABELS, ...labels });
527
571
  const starrable = $derived(starred !== undefined || !!onstar);
528
572
  const starredModels = $derived(models.filter((model) => starred?.includes(model.value)));
529
573
  const isStarred = (model: ComposerModel) => !!starred?.includes(model.value);
530
574
 
575
+ // Models beside the chosen one, in the list's order
576
+ const besideable = $derived(!multiple && (also !== undefined || !!onalso));
577
+ const alsoModels = $derived(
578
+ besideable ? models.filter((model) => also?.includes(model.value)) : []
579
+ );
580
+ // The chosen models, in the list's order. One at most, and the first by default, unless several may be.
581
+ const chosen = $derived.by((): ComposerModel[] => {
582
+ if (multiple) {
583
+ const values = Array.isArray(value) ? value : [];
584
+ return models.filter((model) => values.includes(model.value));
585
+ }
586
+ const one = models.find((model) => model.value === value) ?? models[0];
587
+ return one ? [one, ...alsoModels.filter((model) => model !== one)] : [];
588
+ });
589
+ const selected = $derived(chosen[0]);
590
+ const isChosen = (model: ComposerModel) => chosen.includes(model);
591
+ // With no models there is nothing to open: the button says so and can't be pressed
592
+ const empty = $derived(models.length === 0);
593
+ const said = $derived(
594
+ chosen.length
595
+ ? chosen.map((model) => model.label).join(', ')
596
+ : empty
597
+ ? word.none
598
+ : multiple
599
+ ? placeholder
600
+ : ''
601
+ );
602
+ // ui-sdk holds several values while more than one model can be marked chosen. Then a pick
603
+ // leaves the list open, and the list is marked as one that takes several.
604
+ const several = $derived(multiple || besideable);
605
+ const picked = $derived(several ? chosen.map((model) => model.value) : (selected?.value ?? null));
606
+
531
607
  // With more than one provider, the list shows the models of the one chosen in the rail.
532
608
  // Starred models, from every provider, come first, while there are any.
533
609
  const railed = $derived(!!providers && providers.length > 1);
@@ -536,10 +612,15 @@
536
612
  ? [...(starrable && starredModels.length ? [STARRED] : []), ...providers!.map((p) => p.value)]
537
613
  : []
538
614
  );
615
+ // Where the list opens: on the chosen model's provider
616
+ const home = $derived(railed ? (selected?.provider ?? providers![0].value) : undefined);
539
617
  let shown = $state<string>();
540
- const current = $derived(
541
- railed ? (railItems.includes(shown!) ? shown! : railItems[0]) : undefined
542
- );
618
+ const current = $derived.by(() => {
619
+ if (!railed) return undefined;
620
+ // Closed, it is ready on the chosen model's, so it opens on what it shows
621
+ const want = live ? shown : home;
622
+ return railItems.includes(want!) ? want! : railItems[0];
623
+ });
543
624
  const provider = $derived(railed ? providers!.find((p) => p.value === current) : undefined);
544
625
  const providerName = (model: ComposerModel) =>
545
626
  providers?.find((p) => p.value === model.provider)?.label ?? '';
@@ -569,8 +650,10 @@
569
650
  : []
570
651
  );
571
652
  const searching = $derived(words.length > 0);
572
- // Older models fold into one row at the end, until it is opened
573
- let showOlder = $state(false);
653
+ // Older models fold into one row at the end, until it is opened. Closed, the fold is open
654
+ // only if the chosen model is an older one, so the choice is in view as the list opens.
655
+ let unfolded = $state(false);
656
+ const showOlder = $derived(live ? unfolded : !!selected?.older);
574
657
  const base = $derived.by((): ComposerModel[] => {
575
658
  if (searching) {
576
659
  return models
@@ -593,64 +676,103 @@
593
676
  const heading = $derived(
594
677
  searching ? undefined : current === STARRED ? word.starred : provider?.label
595
678
  );
596
- const enabled = $derived(listed.filter((model) => !model.disabled));
597
679
  // What the keyboard goes through, in order: the models, and the row that folds the older ones
598
680
  const entries = $derived([
599
681
  ...fresh.filter((model) => !model.disabled).map((model) => model.value),
600
682
  ...(foldable ? [OLDER] : []),
601
683
  ...(showOlder ? old.filter((model) => !model.disabled).map((model) => model.value) : [])
602
684
  ]);
603
- // Models beside the chosen one, in the list's order
604
- const besideable = $derived(!multiple && (also !== undefined || !!onalso));
605
- const alsoModels = $derived(
606
- besideable ? models.filter((model) => also?.includes(model.value)) : []
607
- );
608
- // The chosen models, in the list's order. One at most, and the first by default, unless several may be.
609
- const chosen = $derived.by((): ComposerModel[] => {
610
- if (multiple) {
611
- const values = Array.isArray(value) ? value : [];
612
- return models.filter((model) => values.includes(model.value));
613
- }
614
- const one = models.find((model) => model.value === value) ?? models[0];
615
- return one ? [one, ...alsoModels.filter((model) => model !== one)] : [];
616
- });
617
- const selected = $derived(chosen[0]);
618
- const isChosen = (model: ComposerModel) => chosen.includes(model);
619
- const optionId = (model: ComposerModel) => `${uid}-option-${models.indexOf(model)}`;
620
685
  const activeModel = $derived(listed.find((model) => model.value === active));
621
- const activeId = $derived(
622
- active === OLDER ? `${uid}-older` : activeModel ? optionId(activeModel) : undefined
623
- );
624
- const said = $derived(
625
- chosen.length ? chosen.map((model) => model.label).join(', ') : multiple ? placeholder : ''
626
- );
627
686
 
628
- // Where the keyboard is while the list shows: the search field, or the list itself
629
- const focusList = () => (searchable ? field : list)?.focus();
630
687
  // The first model it can choose of those listed: one that is chosen, if any
631
688
  const firstActive = () =>
632
689
  chosen.find((model) => listed.includes(model) && !model.disabled)?.value ?? entries[0];
633
690
 
634
- function show() {
691
+ /**
692
+ * Highlights an option, as the pointer moving onto it does: ui-sdk has no other way in for
693
+ * it. With focus in the list, the option takes it; from the search field, the field keeps it.
694
+ */
695
+ function highlight(item: string | undefined) {
696
+ if (item === undefined || !content) return;
697
+ const option = content.querySelector(`[data-model="${CSS.escape(item)}"]`);
698
+ option?.dispatchEvent(new PointerEvent('pointermove', { bubbles: true, pointerType: 'mouse' }));
699
+ }
700
+
701
+ // When the list changes under the highlight, as when the last starred model is unstarred
702
+ // from the starred list, the highlight, and with it the focus, moves to the first it can
703
+ // choose there, and is not lost with the option it was on
704
+ $effect(() => {
705
+ const list = entries;
706
+ if (!open) return;
707
+ untrack(() => {
708
+ if (active === undefined || !list.includes(active)) highlight(firstActive());
709
+ });
710
+ });
711
+
712
+ // Each opening starts on the chosen model's provider, with nothing typed
713
+ function opening() {
714
+ shown = home;
715
+ unfolded = !!selected?.older;
635
716
  query = '';
636
- if (railed) shown = selected?.provider ?? providers![0].value;
637
- // Folded, unless the chosen model is one of the older ones
638
- showOlder = !!selected?.older;
639
- active = firstActive();
640
- popover?.showPopover();
641
- // Placed and focused at once, so a key pressed straight after opening is not lost
642
- place();
643
- focusList();
644
- list?.querySelector('[aria-selected="true"]')?.scrollIntoView({ block: 'nearest' });
717
+ live = true;
718
+ }
719
+
720
+ function setOpen(next: boolean) {
721
+ if (next === open) return;
722
+ if (next) opening();
723
+ open = next;
724
+ onopenchange?.(next);
725
+ }
726
+
727
+ // `open`, set from outside: the list is made ready the same way
728
+ let wasOpen = false;
729
+ $effect.pre(() => {
730
+ const now = open;
731
+ untrack(() => {
732
+ if (now && !wasOpen) opening();
733
+ wasOpen = now;
734
+ });
735
+ });
736
+
737
+ // Set as a pick that leaves the list open is handled, for the close ui-sdk asks for next
738
+ let keepOpen = false;
739
+
740
+ function onOpenChange(next: boolean, details: Details) {
741
+ if (!next && keepOpen && details.reason === 'item-press') details.cancel();
742
+ keepOpen = false;
743
+ }
744
+
745
+ function onOpenChangeComplete(next: boolean) {
746
+ if (next) return;
747
+ live = false;
748
+ announcement = '';
645
749
  }
646
750
 
647
- function hide(refocus = true) {
648
- popover?.hidePopover();
649
- if (refocus) ref?.focus();
751
+ // ui-sdk asks to change the value; the picker decides what a pick does, and holds the value
752
+ function onValueChange(next: string | string[] | null, details: Details) {
753
+ details.cancel();
754
+ keepOpen = false;
755
+ // Typing on the closed button would pick by first letter, as a native select does: the
756
+ // model is left as it is, as it was before the list was on ui-sdk
757
+ if (details.reason !== 'item-press') return;
758
+ const was = Array.isArray(picked) ? picked : [];
759
+ const item = Array.isArray(next)
760
+ ? ([...next.filter((v) => !was.includes(v)), ...was.filter((v) => !next.includes(v))][0] ??
761
+ null)
762
+ : next;
763
+ if (item === OLDER) {
764
+ unfolded = !unfolded;
765
+ keepOpen = true;
766
+ return;
767
+ }
768
+ const model = models.find((m) => m.value === item);
769
+ if (!model) return;
770
+ const event = details.event as Partial<MouseEvent & KeyboardEvent> | undefined;
771
+ choose(model, !!event && !!(event.shiftKey || event.metaKey || event.ctrlKey));
650
772
  }
651
773
 
652
774
  // Shift, ⌘ or Ctrl adds a model beside the chosen one, or takes it off
653
- function choose(model: ComposerModel, beside = false) {
775
+ function choose(model: ComposerModel, beside: boolean) {
654
776
  if (model.disabled) return;
655
777
  if (beside && besideable && model !== selected) {
656
778
  const on = !alsoModels.includes(model);
@@ -659,6 +781,7 @@
659
781
  .map((m) => m.value);
660
782
  also = values;
661
783
  onalso?.(values);
784
+ keepOpen = true;
662
785
  return;
663
786
  }
664
787
  if (multiple) {
@@ -668,6 +791,7 @@
668
791
  : models.filter((m) => m === model || isChosen(m)).map((m) => m.value);
669
792
  value = values;
670
793
  (onchange as ((value: string[]) => void) | undefined)?.(values);
794
+ keepOpen = true;
671
795
  return;
672
796
  }
673
797
  value = model.value;
@@ -677,7 +801,8 @@
677
801
  also = alsoModels.filter((m) => m !== model).map((m) => m.value);
678
802
  onalso?.(also);
679
803
  }
680
- hide();
804
+ // ui-sdk closes a list of one value itself; one of several is closed here
805
+ if (several) setOpen(false);
681
806
  }
682
807
 
683
808
  function toggleStar(model: ComposerModel) {
@@ -688,80 +813,12 @@
688
813
  announcement = `${model.label}, ${on ? word.starred : word.unstarred}`;
689
814
  }
690
815
 
691
- // Beside the button: below it when there is room, otherwise above, which is
692
- // usually the case for a composer at the foot of the page.
693
- function place() {
694
- if (!ref || !popover) return;
695
- const button = ref.getBoundingClientRect();
696
- const below = innerHeight - button.bottom - GAP - MARGIN;
697
- const above = button.top - GAP - MARGIN;
698
- const height = popover.scrollHeight;
699
- const up = height > below && above > below;
700
- const rtl = getComputedStyle(ref).direction === 'rtl';
701
- const width = popover.offsetWidth;
702
-
703
- let left = rtl ? button.right - width : button.left;
704
- left = Math.min(Math.max(left, MARGIN), innerWidth - width - MARGIN);
705
-
706
- popover.style.left = `${left}px`;
707
- popover.style.top = up ? 'auto' : `${button.bottom + GAP}px`;
708
- popover.style.bottom = up ? `${innerHeight - button.top + GAP}px` : 'auto';
709
- popover.style.setProperty('--narvi-picker-room', `${Math.max(up ? above : below, 120)}px`);
710
- popover.style.setProperty(
711
- '--narvi-picker-origin',
712
- `${up ? 'bottom' : 'top'} ${rtl ? 'right' : 'left'}`
713
- );
714
- }
715
-
716
- function ontoggle(event: ToggleEvent) {
717
- const next = event.newState === 'open';
718
- if (next !== open) {
719
- open = next;
720
- onopenchange?.(next);
721
- }
722
- if (!next) announcement = '';
723
- if (!next && popover?.contains(document.activeElement)) {
724
- // Closed by Escape or a click outside while the list had focus
725
- ref?.focus();
726
- }
727
- }
728
-
729
- // `open`, set from outside: the list follows it
730
- $effect(() => {
731
- const want = open;
732
- if (!popover) return;
733
- untrack(() => {
734
- const shown = popover!.matches(':popover-open');
735
- if (want && !shown) show();
736
- else if (!want && shown) hide(popover!.contains(document.activeElement));
737
- });
738
- });
739
-
740
- $effect(() => {
741
- if (!open) return;
742
- const reposition = () => place();
743
- addEventListener('resize', reposition);
744
- addEventListener('scroll', reposition, { capture: true, passive: true });
745
- return () => {
746
- removeEventListener('resize', reposition);
747
- removeEventListener('scroll', reposition, { capture: true });
748
- };
749
- });
750
-
751
- // Keep the active option in view as the keyboard moves through the list
752
- $effect(() => {
753
- if (!open || !activeModel || !list) return;
754
- list
755
- .querySelector(`#${CSS.escape(optionId(activeModel))}`)
756
- ?.scrollIntoView({ block: 'nearest' });
757
- });
758
-
759
816
  // Shows the models of another place in the rail, on the first it can choose
760
- function showProvider(item: string) {
817
+ async function showProvider(item: string) {
761
818
  shown = item;
762
819
  query = '';
763
- active = firstActive();
764
- focusList();
820
+ await tick();
821
+ highlight(firstActive());
765
822
  }
766
823
 
767
824
  function cycleProvider(step: number) {
@@ -769,42 +826,24 @@
769
826
  showProvider(railItems[(at + step + railItems.length) % railItems.length]);
770
827
  }
771
828
 
772
- function onsearch(event: Event & { currentTarget: HTMLInputElement }) {
773
- query = event.currentTarget.value;
774
- // A new search starts on its best match
775
- active = entries[0];
829
+ // A new search starts on its best match, once the list shows what it found
830
+ async function onQueryChange(next: string, details: Details) {
831
+ if (details.reason !== 'input-change') return;
832
+ await tick();
833
+ highlight(entries[0]);
776
834
  }
777
835
 
836
+ // Page Up and Page Down move a few models, and stop at the ends
778
837
  function move(step: number) {
779
838
  if (!entries.length) return;
780
839
  const index = entries.indexOf(active!);
781
840
  const next = index === -1 ? (step > 0 ? 0 : entries.length - 1) : index + step;
782
- active = entries[Math.min(Math.max(next, 0), entries.length - 1)];
841
+ highlight(entries[Math.min(Math.max(next, 0), entries.length - 1)]);
783
842
  }
784
843
 
785
- function toggleOlder() {
786
- showOlder = !showOlder;
787
- active = OLDER;
788
- }
789
-
790
- // Typing a letter or two jumps to the model whose name starts with them
791
- let typed = '';
792
- let typedTimer: ReturnType<typeof setTimeout> | undefined;
793
- function typeahead(char: string) {
794
- clearTimeout(typedTimer);
795
- typed += char.toLowerCase();
796
- typedTimer = setTimeout(() => (typed = ''), 600);
797
- const start = enabled.findIndex((model) => model.value === active);
798
- const ordered = [...enabled.slice(start + 1), ...enabled.slice(0, start + 1)];
799
- const pool =
800
- typed.length === 1 ? ordered : [...enabled.slice(start), ...enabled.slice(0, start)];
801
- const match = pool.find((model) => model.label.toLowerCase().startsWith(typed));
802
- if (match) active = match.value;
803
- }
804
-
805
- // The keys of the list, from the list or from the search field. In the field, keys that
806
- // type or move the caret are left to it.
807
- function onListKeydown(event: KeyboardEvent) {
844
+ // The keys ui-sdk's list has none for, from the list or from the search field. They come
845
+ // before its own, which a key handled here skips.
846
+ function onContentKeydown(event: KeyboardEvent) {
808
847
  if (event.isComposing) return;
809
848
  const inField = event.target === field;
810
849
  const mod = event.metaKey || event.ctrlKey;
@@ -816,140 +855,130 @@
816
855
  return;
817
856
  }
818
857
  switch (event.key) {
819
- case 'ArrowDown':
820
- move(1);
821
- break;
822
- case 'ArrowUp':
823
- move(-1);
824
- break;
825
858
  case 'PageDown':
826
- move(PAGE);
827
- break;
828
859
  case 'PageUp':
829
- move(-PAGE);
830
- break;
831
- case 'Home':
832
- case 'End':
833
- if (inField) return;
834
- active = event.key === 'Home' ? entries[0] : entries.at(-1);
835
- break;
836
- case 'Enter':
837
- if (active === OLDER) toggleOlder();
838
- else if (activeModel) choose(activeModel, event.shiftKey || mod);
839
- break;
840
- case ' ':
841
- if (inField) return;
842
- if (typed) typeahead(' ');
843
- else if (active === OLDER) toggleOlder();
844
- else if (activeModel) choose(activeModel, event.shiftKey);
860
+ move(event.key === 'PageDown' ? PAGE : -PAGE);
845
861
  break;
846
862
  case 'ArrowLeft':
847
863
  case 'ArrowRight': {
848
864
  // Left and right go through the rail, mirrored right to left, unless words are typed
849
865
  if (!railed || (inField && query !== '')) return;
850
- const rtl = !!list && getComputedStyle(list).direction === 'rtl';
866
+ const rtl = !!content && getComputedStyle(content).direction === 'rtl';
851
867
  cycleProvider((event.key === 'ArrowRight') !== rtl ? 1 : -1);
852
868
  break;
853
869
  }
854
- case 'Tab':
855
- hide();
856
- break;
857
870
  default:
858
- if (!inField && event.key.length === 1 && !mod && !event.altKey) {
859
- typeahead(event.key);
860
- break;
861
- }
862
871
  return;
863
872
  }
864
873
  event.preventDefault();
865
874
  }
866
875
 
867
- function onTriggerKeydown(event: KeyboardEvent & { currentTarget: HTMLButtonElement }) {
868
- onkeydown?.(event);
869
- if (event.defaultPrevented) return;
870
- if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
871
- event.preventDefault();
872
- show();
873
- }
874
- }
875
-
876
- $effect(() => () => clearTimeout(typedTimer));
876
+ // A press on the rail or on a star leaves focus where it is: on an option, or in the field
877
+ const keepFocus = (event: MouseEvent) => event.preventDefault();
877
878
  </script>
878
879
 
879
- <button
880
- bind:this={ref}
881
- type="button"
882
- aria-haspopup="listbox"
883
- aria-expanded={open}
884
- aria-controls="{uid}-popover"
885
- aria-label="{label}: {said}"
886
- disabled={disabled ?? composer?.disabled}
887
- data-slot="composer-model-picker"
888
- {...rest}
889
- {...attrs([styles.trigger, shared.focusable, open && styles.triggerOpen, sx], className)}
890
- onclick={(event) => {
891
- onclick?.(event);
892
- if (event.defaultPrevented) return;
893
- if (open) hide();
894
- else show();
895
- }}
896
- onkeydown={onTriggerKeydown}
880
+ <!--
881
+ The picker lists what a search finds itself, best matches first, so ui-sdk keeps every item
882
+ it is given. The arrows stop at the ends. ui-sdk's count of results is said in English only;
883
+ what the picker says, no match among it, is in `labels`.
884
+ -->
885
+ <UiSelect
886
+ multiple={several}
887
+ value={picked}
888
+ bind:open={() => open && !empty, setOpen}
889
+ bind:query
890
+ filter={false}
891
+ loop={false}
892
+ announcement={() => null}
893
+ disabled={empty || (disabled ?? composer?.disabled)}
894
+ {onValueChange}
895
+ {onOpenChange}
896
+ {onOpenChangeComplete}
897
+ {onQueryChange}
898
+ onHighlight={(item) => (active = item ?? undefined)}
897
899
  >
898
- <span {...stylex.attrs(styles.triggerText)}>{selected?.label ?? said}</span>
899
- {#if chosen.length > 1}<span {...stylex.attrs(styles.more)}>+{chosen.length - 1}</span>{/if}
900
- <span {...stylex.attrs(styles.selector)}><Glyph name="selector" size={14} /></span>
901
- </button>
900
+ <SelectTrigger
901
+ aria-label="{label}: {said}"
902
+ {...rest}
903
+ {...attrs([styles.trigger, shared.focusable, open && styles.triggerOpen, sx], className)}
904
+ {@attach (element: HTMLButtonElement) => {
905
+ ref = element;
906
+ return () => (ref = null);
907
+ }}
908
+ >
909
+ <span {...stylex.attrs(styles.triggerText)}>{selected?.label ?? said}</span>
910
+ {#if chosen.length > 1}<span {...stylex.attrs(styles.more)}>+{chosen.length - 1}</span>{/if}
911
+ <span {...stylex.attrs(styles.selector)}><Glyph name="selector" size={14} /></span>
912
+ </SelectTrigger>
902
913
 
903
- <div
904
- bind:this={popover}
905
- id="{uid}-popover"
906
- popover="auto"
907
- data-slot="composer-model-list"
908
- {...stylex.attrs(styles.popover, railed && styles.popoverRailed)}
909
- {ontoggle}
910
- >
911
- {#if railed}
912
- <div {...stylex.attrs(styles.frame)}>
913
- <!-- For the pointer: from the list, the left and right arrows go through it -->
914
- <div role="group" aria-label={providersLabel} {...stylex.attrs(styles.rail)}>
915
- {#each railItems as item (item)}
916
- {@const entry = providers!.find((p) => p.value === item)}
917
- {@const name = entry?.label ?? word.starred}
918
- {@const pressed = !searching && item === current}
919
- <button
920
- type="button"
921
- tabindex="-1"
922
- aria-pressed={pressed}
923
- aria-label={name}
924
- title={name}
925
- data-icons
926
- {...stylex.attrs(styles.provider, pressed && styles.providerPressed)}
927
- onclick={() => showProvider(item)}
928
- >
929
- {#if !entry}{@render starGlyph(true)}{:else if providerIcon}{@render providerIcon(
930
- entry
931
- )}{:else if entry.icon}<entry.icon aria-hidden="true" />{:else}<span
932
- aria-hidden="true">{[...entry.label][0]?.toUpperCase()}</span
933
- >{/if}
934
- </button>
935
- {#if !entry}<span aria-hidden="true" {...stylex.attrs(styles.railRule)}></span>{/if}
936
- {/each}
937
- </div>
938
- <span aria-hidden="true" {...stylex.attrs(styles.divider)}></span>
939
- <div {...stylex.attrs(styles.frameList)}>
940
- {@render search()}
941
- {#if heading}
942
- <div aria-hidden="true" {...stylex.attrs(styles.groupLabel)}>{heading}</div>
943
- {/if}
944
- {@render options()}
914
+ <SelectContent
915
+ side="bottom"
916
+ align="start"
917
+ sideOffset={GAP}
918
+ collisionPadding={MARGIN}
919
+ {...stylex.attrs(styles.popover, railed && styles.popoverRailed)}
920
+ onkeydown={onContentKeydown}
921
+ {@attach (element: HTMLElement) => {
922
+ content = element;
923
+ return () => (content = null);
924
+ }}
925
+ >
926
+ {#if railed}
927
+ <div {...stylex.attrs(styles.frame)}>
928
+ <!-- For the pointer: from the list, the left and right arrows go through it -->
929
+ <div
930
+ role="group"
931
+ aria-label={providersLabel}
932
+ {...stylex.attrs(styles.rail)}
933
+ {@attach (rail: HTMLElement) => {
934
+ // The pressed provider stays in view as the arrows move through a rail that scrolls
935
+ void current;
936
+ void searching;
937
+ rail
938
+ .querySelector<HTMLElement>('[aria-pressed="true"]')
939
+ ?.scrollIntoView({ block: 'nearest' });
940
+ }}
941
+ >
942
+ {#each railItems as item (item)}
943
+ {@const entry = providers!.find((p) => p.value === item)}
944
+ {@const name = entry?.label ?? word.starred}
945
+ {@const pressed = !searching && item === current}
946
+ <button
947
+ type="button"
948
+ tabindex="-1"
949
+ aria-pressed={pressed}
950
+ aria-label={name}
951
+ title={name}
952
+ data-icons
953
+ {...stylex.attrs(styles.provider, pressed && styles.providerPressed)}
954
+ onmousedown={keepFocus}
955
+ onclick={() => showProvider(item)}
956
+ >
957
+ {#if !entry}{@render starGlyph(true)}{:else if providerIcon}{@render providerIcon(
958
+ entry
959
+ )}{:else if entry.icon}<entry.icon aria-hidden="true" />{:else}<span
960
+ aria-hidden="true">{[...entry.label][0]?.toUpperCase()}</span
961
+ >{/if}
962
+ </button>
963
+ {#if !entry}<span aria-hidden="true" {...stylex.attrs(styles.railRule)}></span>{/if}
964
+ {/each}
965
+ </div>
966
+ <span aria-hidden="true" {...stylex.attrs(styles.divider)}></span>
967
+ <div {...stylex.attrs(styles.frameList)}>
968
+ {@render search()}
969
+ {#if heading}
970
+ <div aria-hidden="true" {...stylex.attrs(styles.groupLabel)}>{heading}</div>
971
+ {/if}
972
+ {@render options()}
973
+ </div>
945
974
  </div>
946
- </div>
947
- {:else}
948
- {@render search()}
949
- {@render options()}
950
- {/if}
951
- <span role="status" {...stylex.attrs(visuallyHidden)}>{announcement}</span>
952
- </div>
975
+ {:else}
976
+ {@render search()}
977
+ {@render options()}
978
+ {/if}
979
+ <span role="status" {...stylex.attrs(visuallyHidden)}>{announcement}</span>
980
+ </SelectContent>
981
+ </UiSelect>
953
982
 
954
983
  {#snippet starGlyph(filled: boolean)}
955
984
  <svg data-glyph="" width="14" height="14" viewBox="0 0 16 16" aria-hidden="true">
@@ -967,22 +996,14 @@
967
996
  {#if searchable}
968
997
  <div {...stylex.attrs(styles.search)}>
969
998
  <Glyph name="search" size={14} />
970
- <input
971
- bind:this={field}
972
- type="text"
973
- role="combobox"
974
- aria-expanded="true"
975
- aria-autocomplete="list"
976
- aria-controls="{uid}-listbox"
977
- aria-activedescendant={activeId}
999
+ <SelectInput
978
1000
  aria-label={word.search}
979
1001
  placeholder="{word.search}…"
980
- autocomplete="off"
981
- spellcheck={false}
982
- value={query}
983
- oninput={onsearch}
984
- onkeydown={onListKeydown}
985
1002
  {...stylex.attrs(styles.searchField)}
1003
+ {@attach (element: HTMLInputElement) => {
1004
+ field = element;
1005
+ return () => (field = null);
1006
+ }}
986
1007
  />
987
1008
  </div>
988
1009
  {/if}
@@ -996,42 +1017,26 @@
996
1017
  {/snippet}
997
1018
 
998
1019
  {#snippet listbox()}
999
- <div
1000
- bind:this={list}
1001
- id="{uid}-listbox"
1002
- role="listbox"
1003
- tabindex="-1"
1004
- aria-label={heading ? `${label}: ${heading}` : label}
1005
- aria-multiselectable={multiple || besideable || undefined}
1006
- aria-activedescendant={!searchable ? activeId : undefined}
1007
- {...stylex.attrs(styles.list)}
1008
- onkeydown={onListKeydown}
1009
- >
1020
+ <SelectList aria-label={heading ? `${label}: ${heading}` : label} {...stylex.attrs(styles.list)}>
1010
1021
  {#each groups as group, g (g)}
1011
- <div
1012
- role="group"
1013
- aria-labelledby={group.name ? `${uid}-group-${g}` : undefined}
1014
- {...stylex.attrs(g > 0 && styles.group)}
1015
- >
1022
+ <SelectGroup {...stylex.attrs(g > 0 && styles.group)}>
1016
1023
  {#if group.name}
1017
- <div id="{uid}-group-{g}" {...stylex.attrs(styles.groupLabel)}>{group.name}</div>
1024
+ <SelectGroupLabel {...stylex.attrs(styles.groupLabel)}>{group.name}</SelectGroupLabel>
1018
1025
  {/if}
1019
1026
  {#each group.models as model (model.value)}
1020
1027
  {@render option(model)}
1021
1028
  {/each}
1022
- </div>
1029
+ </SelectGroup>
1023
1030
  {/each}
1024
1031
  {#if foldable}
1025
1032
  {@const count = old.length}
1026
- <!-- Opens or folds the older models; Enter does the same from the keyboard -->
1027
- <div
1028
- id="{uid}-older"
1029
- role="option"
1030
- aria-selected="false"
1033
+ <!-- Opens or folds the older models: ui-sdk picks it as an option, and the picker folds -->
1034
+ <SelectItem
1035
+ value={OLDER}
1036
+ label={word.older}
1031
1037
  aria-label="{word.older}, {count}"
1032
- {...stylex.attrs(styles.option, styles.olderRow, active === OLDER && styles.active)}
1033
- onpointermove={() => (active = OLDER)}
1034
- onclick={toggleOlder}
1038
+ data-model={OLDER}
1039
+ {...stylex.attrs(styles.option, styles.olderRow)}
1035
1040
  >
1036
1041
  <span {...stylex.attrs(styles.name, styles.olderName)}>
1037
1042
  <span {...stylex.attrs(styles.nameText)}>{word.older}</span>
@@ -1040,14 +1045,14 @@
1040
1045
  <span {...stylex.attrs(styles.olderChevron, showOlder && styles.olderOpen)}
1041
1046
  ><Glyph name="chevron" size={14} /></span
1042
1047
  >
1043
- </div>
1048
+ </SelectItem>
1044
1049
  {#if showOlder}
1045
1050
  {#each old as model (model.value)}
1046
1051
  {@render option(model)}
1047
1052
  {/each}
1048
1053
  {/if}
1049
1054
  {/if}
1050
- </div>
1055
+ </SelectList>
1051
1056
  {#if besideable}
1052
1057
  <p {...stylex.attrs(styles.hint)}>{word.alsoHint}</p>
1053
1058
  {/if}
@@ -1056,23 +1061,17 @@
1056
1061
  {#snippet option(model: ComposerModel)}
1057
1062
  {@const isSelected = isChosen(model)}
1058
1063
  {@const star = isStarred(model)}
1059
- <!-- The list handles the keyboard for every option; this click is for the pointer -->
1060
- <div
1061
- id={optionId(model)}
1062
- role="option"
1064
+ <SelectItem
1065
+ value={model.value}
1066
+ label={model.label}
1067
+ disabled={model.disabled}
1063
1068
  aria-label={optionName(model, star)}
1064
- aria-selected={isSelected}
1065
- aria-disabled={model.disabled || undefined}
1069
+ data-model={model.value}
1066
1070
  {...stylex.attrs(
1067
1071
  styles.option,
1068
1072
  starrable && styles.optionStarrable,
1069
- model.value === active && styles.active,
1070
1073
  model.disabled && styles.optionDisabled
1071
1074
  )}
1072
- onpointermove={() => {
1073
- if (!model.disabled) active = model.value;
1074
- }}
1075
- onclick={(event) => choose(model, event.shiftKey || event.metaKey || event.ctrlKey)}
1076
1075
  >
1077
1076
  <span {...stylex.attrs(styles.name)}>
1078
1077
  <span {...stylex.attrs(styles.nameText)}>{model.label}</span>
@@ -1085,7 +1084,10 @@
1085
1084
  <span {...stylex.attrs(styles.check)}><Glyph name="check" stroke={1.75} /></span>
1086
1085
  {/if}
1087
1086
  {#if starrable}
1088
- <!-- For the pointer: ⌘D stars the model the keyboard is on -->
1087
+ <!--
1088
+ For the pointer: ⌘D stars the model the keyboard is on. Its press is not a pick: it is
1089
+ taken on the way down, before the option's own listener, which a delegated one is not.
1090
+ -->
1089
1091
  <button
1090
1092
  type="button"
1091
1093
  tabindex="-1"
@@ -1094,7 +1096,9 @@
1094
1096
  styles.star,
1095
1097
  star ? styles.starOn : model.value !== active && styles.starHidden
1096
1098
  )}
1097
- onclick={(event) => {
1099
+ onmousedown={keepFocus}
1100
+ onclickcapture={(event) => {
1101
+ event.preventDefault();
1098
1102
  event.stopPropagation();
1099
1103
  toggleStar(model);
1100
1104
  }}
@@ -1105,5 +1109,5 @@
1105
1109
  {#if model.description}
1106
1110
  <span {...stylex.attrs(styles.description)}>{model.description}</span>
1107
1111
  {/if}
1108
- </div>
1112
+ </SelectItem>
1109
1113
  {/snippet}