@diegopluna/narvi 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/base.css +3 -0
- package/dist/components/button/Button.svelte +29 -17
- package/dist/components/checkbox/Checkbox.svelte +106 -54
- package/dist/components/checkbox/Checkbox.svelte.d.ts +22 -8
- package/dist/components/choice-cards/ChoiceCards.svelte +68 -39
- package/dist/components/choice-cards/ChoiceCards.svelte.d.ts +12 -8
- package/dist/components/collapsible/CollapsibleContent.svelte +71 -17
- package/dist/components/collapsible/CollapsibleContent.svelte.d.ts +14 -10
- package/dist/components/collapsible/CollapsibleRoot.svelte +13 -9
- package/dist/components/collapsible/CollapsibleRoot.svelte.d.ts +8 -9
- package/dist/components/collapsible/CollapsibleTrigger.svelte +24 -15
- package/dist/components/collapsible/CollapsibleTrigger.svelte.d.ts +10 -14
- package/dist/components/color-field/ColorField.svelte +13 -7
- package/dist/components/command/CommandDialog.svelte +30 -20
- package/dist/components/command/CommandDialog.svelte.d.ts +4 -3
- package/dist/components/command/CommandEmpty.svelte +11 -9
- package/dist/components/command/CommandEmpty.svelte.d.ts +6 -17
- package/dist/components/command/CommandGroup.svelte +32 -11
- package/dist/components/command/CommandGroup.svelte.d.ts +7 -11
- package/dist/components/command/CommandInput.svelte +25 -10
- package/dist/components/command/CommandInput.svelte.d.ts +8 -12
- package/dist/components/command/CommandItem.svelte +67 -29
- package/dist/components/command/CommandItem.svelte.d.ts +6 -32
- package/dist/components/command/CommandList.svelte +8 -10
- package/dist/components/command/CommandList.svelte.d.ts +6 -8
- package/dist/components/command/CommandRoot.svelte +247 -57
- package/dist/components/command/CommandRoot.svelte.d.ts +14 -28
- package/dist/components/command/CommandSeparator.svelte +18 -0
- package/dist/components/command/CommandSeparator.svelte.d.ts +7 -0
- package/dist/components/command/context.d.ts +27 -0
- package/dist/components/command/context.js +16 -0
- package/dist/components/command/index.d.ts +6 -4
- package/dist/components/command/index.js +5 -4
- package/dist/components/command/score.d.ts +27 -0
- package/dist/components/command/score.js +77 -0
- package/dist/components/command/styles.d.ts +32 -9
- package/dist/components/command/styles.js +42 -14
- package/dist/components/composer/ComposerModelPicker.svelte +365 -347
- package/dist/components/composer/ComposerModelPicker.svelte.d.ts +6 -3
- package/dist/components/composer/ComposerRoot.svelte.d.ts +1 -1
- package/dist/components/dialog/ConfirmDialog.svelte +73 -53
- package/dist/components/dialog/DialogClose.svelte +17 -0
- package/dist/components/dialog/DialogClose.svelte.d.ts +10 -0
- package/dist/components/dialog/DialogContent.svelte +35 -33
- package/dist/components/dialog/DialogContent.svelte.d.ts +6 -20
- package/dist/components/dialog/DialogDescription.svelte +9 -12
- package/dist/components/dialog/DialogDescription.svelte.d.ts +6 -8
- package/dist/components/dialog/DialogRoot.svelte +20 -0
- package/dist/components/dialog/DialogRoot.svelte.d.ts +7 -0
- package/dist/components/dialog/DialogTitle.svelte +12 -8
- package/dist/components/dialog/DialogTitle.svelte.d.ts +8 -8
- package/dist/components/dialog/DialogTrigger.svelte +17 -0
- package/dist/components/dialog/DialogTrigger.svelte.d.ts +10 -0
- package/dist/components/dialog/index.d.ts +6 -5
- package/dist/components/dialog/index.js +3 -6
- package/dist/components/dialog/styles.d.ts +1 -2
- package/dist/components/dialog/styles.js +11 -8
- package/dist/components/hover-card/HoverCardContent.svelte +35 -29
- package/dist/components/hover-card/HoverCardContent.svelte.d.ts +8 -12
- package/dist/components/hover-card/HoverCardRoot.svelte +7 -7
- package/dist/components/hover-card/HoverCardRoot.svelte.d.ts +5 -4
- package/dist/components/hover-card/HoverCardTrigger.svelte +18 -0
- package/dist/components/hover-card/HoverCardTrigger.svelte.d.ts +10 -0
- package/dist/components/hover-card/index.d.ts +2 -3
- package/dist/components/hover-card/index.js +1 -5
- package/dist/components/input/Input.svelte.d.ts +1 -1
- package/dist/components/markdown/MarkdownBlock.svelte +6 -3
- package/dist/components/markdown/MarkdownTable.svelte +15 -7
- package/dist/components/menu/ContextMenuContent.svelte +15 -15
- package/dist/components/menu/ContextMenuContent.svelte.d.ts +6 -9
- package/dist/components/menu/ContextMenuTrigger.svelte +14 -16
- package/dist/components/menu/ContextMenuTrigger.svelte.d.ts +8 -14
- package/dist/components/menu/MenuCheckboxItem.svelte +22 -11
- package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +8 -22
- package/dist/components/menu/MenuContent.svelte +16 -18
- package/dist/components/menu/MenuContent.svelte.d.ts +6 -18
- package/dist/components/menu/MenuGroup.svelte +4 -4
- package/dist/components/menu/MenuGroup.svelte.d.ts +5 -4
- package/dist/components/menu/MenuItem.svelte +25 -12
- package/dist/components/menu/MenuItem.svelte.d.ts +6 -21
- package/dist/components/menu/MenuLabel.svelte +7 -11
- package/dist/components/menu/MenuLabel.svelte.d.ts +6 -8
- package/dist/components/menu/MenuRadioGroup.svelte +4 -4
- package/dist/components/menu/MenuRadioGroup.svelte.d.ts +5 -4
- package/dist/components/menu/MenuRadioItem.svelte +16 -14
- package/dist/components/menu/MenuRadioItem.svelte.d.ts +6 -19
- package/dist/components/menu/MenuSeparator.svelte +6 -10
- package/dist/components/menu/MenuSeparator.svelte.d.ts +6 -7
- package/dist/components/menu/MenuSubContent.svelte +22 -19
- package/dist/components/menu/MenuSubContent.svelte.d.ts +8 -15
- package/dist/components/menu/MenuSubTrigger.svelte +7 -11
- package/dist/components/menu/MenuSubTrigger.svelte.d.ts +6 -15
- package/dist/components/menu/MenuTrigger.svelte +17 -0
- package/dist/components/menu/MenuTrigger.svelte.d.ts +10 -0
- package/dist/components/menu/context-menu.d.ts +2 -2
- package/dist/components/menu/context-menu.js +3 -2
- package/dist/components/menu/group.js +1 -1
- package/dist/components/menu/index.d.ts +5 -4
- package/dist/components/menu/index.js +5 -5
- package/dist/components/menu/row.d.ts +20 -0
- package/dist/components/menu/row.js +12 -0
- package/dist/components/popover/PopoverClose.svelte +17 -0
- package/dist/components/popover/PopoverClose.svelte.d.ts +10 -0
- package/dist/components/popover/PopoverContent.svelte +30 -29
- package/dist/components/popover/PopoverContent.svelte.d.ts +6 -17
- package/dist/components/popover/PopoverTrigger.svelte +17 -0
- package/dist/components/popover/PopoverTrigger.svelte.d.ts +10 -0
- package/dist/components/popover/index.d.ts +6 -4
- package/dist/components/popover/index.js +6 -5
- package/dist/components/progress/Progress.svelte +16 -22
- package/dist/components/progress/Progress.svelte.d.ts +6 -5
- package/dist/components/queued-message/QueuedMessage.svelte +10 -3
- package/dist/components/queued-message/QueuedMessage.svelte.d.ts +2 -1
- package/dist/components/rail/RailItem.svelte +20 -6
- package/dist/components/reasoning/ReasoningRoot.svelte.d.ts +1 -1
- package/dist/components/segmented/SegmentedControl.svelte +100 -91
- package/dist/components/segmented/SegmentedControl.svelte.d.ts +6 -4
- package/dist/components/select/Select.svelte +97 -59
- package/dist/components/select/Select.svelte.d.ts +3 -2
- package/dist/components/sheet/SheetContent.svelte +31 -38
- package/dist/components/sheet/SheetContent.svelte.d.ts +7 -22
- package/dist/components/sheet/index.d.ts +3 -5
- package/dist/components/sheet/index.js +3 -5
- package/dist/components/sheet/styles.js +26 -5
- package/dist/components/sidebar/SidebarItem.svelte +10 -6
- package/dist/components/slider/Slider.svelte +86 -65
- package/dist/components/slider/Slider.svelte.d.ts +9 -8
- package/dist/components/split-button/SplitButton.svelte +20 -3
- package/dist/components/split-button/SplitButton.svelte.d.ts +1 -1
- package/dist/components/switch/Switch.svelte +77 -49
- package/dist/components/switch/Switch.svelte.d.ts +15 -8
- package/dist/components/tab-strip/TabStrip.svelte +110 -76
- package/dist/components/tab-strip/TabStrip.svelte.d.ts +7 -2
- package/dist/components/tabs/Tabs.svelte +129 -99
- package/dist/components/tabs/Tabs.svelte.d.ts +6 -4
- package/dist/components/textarea/Textarea.svelte.d.ts +1 -1
- package/dist/components/toast/Toaster.svelte +132 -115
- package/dist/components/toast/Toaster.svelte.d.ts +5 -0
- package/dist/components/toast/toasts.svelte.d.ts +10 -23
- package/dist/components/toast/toasts.svelte.js +62 -40
- package/dist/components/toggle/Toggle.svelte +15 -9
- package/dist/components/toggle/Toggle.svelte.d.ts +8 -17
- package/dist/components/toggle-group/ToggleGroupItem.svelte +20 -9
- package/dist/components/toggle-group/ToggleGroupItem.svelte.d.ts +10 -10
- package/dist/components/toggle-group/ToggleGroupRoot.svelte +33 -18
- package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +4 -4
- package/dist/components/tool/ToolRoot.svelte.d.ts +1 -1
- package/dist/components/tooltip/TooltipContent.svelte +38 -28
- package/dist/components/tooltip/TooltipContent.svelte.d.ts +6 -15
- package/dist/components/tooltip/TooltipProvider.svelte +34 -10
- package/dist/components/tooltip/TooltipProvider.svelte.d.ts +18 -4
- package/dist/components/tooltip/TooltipRoot.svelte +52 -23
- package/dist/components/tooltip/TooltipRoot.svelte.d.ts +10 -10
- package/dist/components/tooltip/TooltipTrigger.svelte +14 -17
- package/dist/components/tooltip/TooltipTrigger.svelte.d.ts +10 -4
- package/dist/components/tooltip/index.d.ts +1 -1
- package/dist/components/tooltip/index.js +1 -1
- package/dist/components/work-fold/WorkFold.svelte +14 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1 -1
- package/dist/internal/TooltipScope.svelte +4 -4
- package/dist/internal/layer.d.ts +11 -9
- package/dist/internal/layer.js +21 -15
- package/dist/internal/loose.d.ts +30 -5
- package/dist/internal/loose.js +1 -1
- package/dist/internal/markers.stylex.d.ts +0 -4
- package/dist/internal/markers.stylex.js +0 -2
- package/dist/internal/toggle.d.ts +3 -0
- package/dist/internal/toggle.js +6 -2
- package/dist/internal/tooltip-trigger.d.ts +7 -6
- package/dist/internal/tooltip-trigger.js +9 -12
- package/dist/typography.d.ts +5 -0
- package/dist/typography.js +5 -0
- package/dist/vite.d.ts +7 -1
- package/dist/vite.js +20 -5
- package/package.json +3 -2
- package/skills/building-ui/SKILL.md +21 -21
- package/skills/building-ui/references/components.md +22 -7
- package/skills/markdown/SKILL.md +1 -1
- package/skills/setup/SKILL.md +4 -8
- package/skills/styling/SKILL.md +4 -2
- 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
|
-
/**
|
|
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<
|
|
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
|
|
169
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
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(--
|
|
193
|
-
opacity: { default:
|
|
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:
|
|
227
|
+
[media.motion]: { default: 1, '@starting-style': 0.97, [STARTING]: 0.97, [CLOSED]: 0.97 }
|
|
197
228
|
},
|
|
198
|
-
transitionProperty: {
|
|
199
|
-
|
|
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
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
|
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,14 +612,33 @@
|
|
|
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
|
-
|
|
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 ?? '';
|
|
546
627
|
|
|
628
|
+
// An option is named in full, as it reads: its name, badge and provider, then "Starred" after
|
|
629
|
+
// a comma. Not by a word hidden inside it, which is a box of its own and is read with a space
|
|
630
|
+
// each side, as "Ithil 2 , Starred"
|
|
631
|
+
const optionName = (model: ComposerModel, star: boolean) => {
|
|
632
|
+
const shown = [
|
|
633
|
+
model.label,
|
|
634
|
+
model.badge,
|
|
635
|
+
mixed && railed && model.provider ? providerName(model) : undefined
|
|
636
|
+
]
|
|
637
|
+
.filter(Boolean)
|
|
638
|
+
.join(' ');
|
|
639
|
+
return star ? `${shown}, ${word.starred}` : shown;
|
|
640
|
+
};
|
|
641
|
+
|
|
547
642
|
// A search looks past the rail, through every model
|
|
548
643
|
const words = $derived(
|
|
549
644
|
searchable
|
|
@@ -555,8 +650,10 @@
|
|
|
555
650
|
: []
|
|
556
651
|
);
|
|
557
652
|
const searching = $derived(words.length > 0);
|
|
558
|
-
// Older models fold into one row at the end, until it is opened
|
|
559
|
-
|
|
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);
|
|
560
657
|
const base = $derived.by((): ComposerModel[] => {
|
|
561
658
|
if (searching) {
|
|
562
659
|
return models
|
|
@@ -579,64 +676,103 @@
|
|
|
579
676
|
const heading = $derived(
|
|
580
677
|
searching ? undefined : current === STARRED ? word.starred : provider?.label
|
|
581
678
|
);
|
|
582
|
-
const enabled = $derived(listed.filter((model) => !model.disabled));
|
|
583
679
|
// What the keyboard goes through, in order: the models, and the row that folds the older ones
|
|
584
680
|
const entries = $derived([
|
|
585
681
|
...fresh.filter((model) => !model.disabled).map((model) => model.value),
|
|
586
682
|
...(foldable ? [OLDER] : []),
|
|
587
683
|
...(showOlder ? old.filter((model) => !model.disabled).map((model) => model.value) : [])
|
|
588
684
|
]);
|
|
589
|
-
// Models beside the chosen one, in the list's order
|
|
590
|
-
const besideable = $derived(!multiple && (also !== undefined || !!onalso));
|
|
591
|
-
const alsoModels = $derived(
|
|
592
|
-
besideable ? models.filter((model) => also?.includes(model.value)) : []
|
|
593
|
-
);
|
|
594
|
-
// The chosen models, in the list's order. One at most, and the first by default, unless several may be.
|
|
595
|
-
const chosen = $derived.by((): ComposerModel[] => {
|
|
596
|
-
if (multiple) {
|
|
597
|
-
const values = Array.isArray(value) ? value : [];
|
|
598
|
-
return models.filter((model) => values.includes(model.value));
|
|
599
|
-
}
|
|
600
|
-
const one = models.find((model) => model.value === value) ?? models[0];
|
|
601
|
-
return one ? [one, ...alsoModels.filter((model) => model !== one)] : [];
|
|
602
|
-
});
|
|
603
|
-
const selected = $derived(chosen[0]);
|
|
604
|
-
const isChosen = (model: ComposerModel) => chosen.includes(model);
|
|
605
|
-
const optionId = (model: ComposerModel) => `${uid}-option-${models.indexOf(model)}`;
|
|
606
685
|
const activeModel = $derived(listed.find((model) => model.value === active));
|
|
607
|
-
const activeId = $derived(
|
|
608
|
-
active === OLDER ? `${uid}-older` : activeModel ? optionId(activeModel) : undefined
|
|
609
|
-
);
|
|
610
|
-
const said = $derived(
|
|
611
|
-
chosen.length ? chosen.map((model) => model.label).join(', ') : multiple ? placeholder : ''
|
|
612
|
-
);
|
|
613
686
|
|
|
614
|
-
// Where the keyboard is while the list shows: the search field, or the list itself
|
|
615
|
-
const focusList = () => (searchable ? field : list)?.focus();
|
|
616
687
|
// The first model it can choose of those listed: one that is chosen, if any
|
|
617
688
|
const firstActive = () =>
|
|
618
689
|
chosen.find((model) => listed.includes(model) && !model.disabled)?.value ?? entries[0];
|
|
619
690
|
|
|
620
|
-
|
|
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;
|
|
621
716
|
query = '';
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
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;
|
|
631
743
|
}
|
|
632
744
|
|
|
633
|
-
function
|
|
634
|
-
|
|
635
|
-
|
|
745
|
+
function onOpenChangeComplete(next: boolean) {
|
|
746
|
+
if (next) return;
|
|
747
|
+
live = false;
|
|
748
|
+
announcement = '';
|
|
749
|
+
}
|
|
750
|
+
|
|
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));
|
|
636
772
|
}
|
|
637
773
|
|
|
638
774
|
// Shift, ⌘ or Ctrl adds a model beside the chosen one, or takes it off
|
|
639
|
-
function choose(model: ComposerModel, beside
|
|
775
|
+
function choose(model: ComposerModel, beside: boolean) {
|
|
640
776
|
if (model.disabled) return;
|
|
641
777
|
if (beside && besideable && model !== selected) {
|
|
642
778
|
const on = !alsoModels.includes(model);
|
|
@@ -645,6 +781,7 @@
|
|
|
645
781
|
.map((m) => m.value);
|
|
646
782
|
also = values;
|
|
647
783
|
onalso?.(values);
|
|
784
|
+
keepOpen = true;
|
|
648
785
|
return;
|
|
649
786
|
}
|
|
650
787
|
if (multiple) {
|
|
@@ -654,6 +791,7 @@
|
|
|
654
791
|
: models.filter((m) => m === model || isChosen(m)).map((m) => m.value);
|
|
655
792
|
value = values;
|
|
656
793
|
(onchange as ((value: string[]) => void) | undefined)?.(values);
|
|
794
|
+
keepOpen = true;
|
|
657
795
|
return;
|
|
658
796
|
}
|
|
659
797
|
value = model.value;
|
|
@@ -663,7 +801,8 @@
|
|
|
663
801
|
also = alsoModels.filter((m) => m !== model).map((m) => m.value);
|
|
664
802
|
onalso?.(also);
|
|
665
803
|
}
|
|
666
|
-
|
|
804
|
+
// ui-sdk closes a list of one value itself; one of several is closed here
|
|
805
|
+
if (several) setOpen(false);
|
|
667
806
|
}
|
|
668
807
|
|
|
669
808
|
function toggleStar(model: ComposerModel) {
|
|
@@ -674,80 +813,12 @@
|
|
|
674
813
|
announcement = `${model.label}, ${on ? word.starred : word.unstarred}`;
|
|
675
814
|
}
|
|
676
815
|
|
|
677
|
-
// Beside the button: below it when there is room, otherwise above, which is
|
|
678
|
-
// usually the case for a composer at the foot of the page.
|
|
679
|
-
function place() {
|
|
680
|
-
if (!ref || !popover) return;
|
|
681
|
-
const button = ref.getBoundingClientRect();
|
|
682
|
-
const below = innerHeight - button.bottom - GAP - MARGIN;
|
|
683
|
-
const above = button.top - GAP - MARGIN;
|
|
684
|
-
const height = popover.scrollHeight;
|
|
685
|
-
const up = height > below && above > below;
|
|
686
|
-
const rtl = getComputedStyle(ref).direction === 'rtl';
|
|
687
|
-
const width = popover.offsetWidth;
|
|
688
|
-
|
|
689
|
-
let left = rtl ? button.right - width : button.left;
|
|
690
|
-
left = Math.min(Math.max(left, MARGIN), innerWidth - width - MARGIN);
|
|
691
|
-
|
|
692
|
-
popover.style.left = `${left}px`;
|
|
693
|
-
popover.style.top = up ? 'auto' : `${button.bottom + GAP}px`;
|
|
694
|
-
popover.style.bottom = up ? `${innerHeight - button.top + GAP}px` : 'auto';
|
|
695
|
-
popover.style.setProperty('--narvi-picker-room', `${Math.max(up ? above : below, 120)}px`);
|
|
696
|
-
popover.style.setProperty(
|
|
697
|
-
'--narvi-picker-origin',
|
|
698
|
-
`${up ? 'bottom' : 'top'} ${rtl ? 'right' : 'left'}`
|
|
699
|
-
);
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
function ontoggle(event: ToggleEvent) {
|
|
703
|
-
const next = event.newState === 'open';
|
|
704
|
-
if (next !== open) {
|
|
705
|
-
open = next;
|
|
706
|
-
onopenchange?.(next);
|
|
707
|
-
}
|
|
708
|
-
if (!next) announcement = '';
|
|
709
|
-
if (!next && popover?.contains(document.activeElement)) {
|
|
710
|
-
// Closed by Escape or a click outside while the list had focus
|
|
711
|
-
ref?.focus();
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
// `open`, set from outside: the list follows it
|
|
716
|
-
$effect(() => {
|
|
717
|
-
const want = open;
|
|
718
|
-
if (!popover) return;
|
|
719
|
-
untrack(() => {
|
|
720
|
-
const shown = popover!.matches(':popover-open');
|
|
721
|
-
if (want && !shown) show();
|
|
722
|
-
else if (!want && shown) hide(popover!.contains(document.activeElement));
|
|
723
|
-
});
|
|
724
|
-
});
|
|
725
|
-
|
|
726
|
-
$effect(() => {
|
|
727
|
-
if (!open) return;
|
|
728
|
-
const reposition = () => place();
|
|
729
|
-
addEventListener('resize', reposition);
|
|
730
|
-
addEventListener('scroll', reposition, { capture: true, passive: true });
|
|
731
|
-
return () => {
|
|
732
|
-
removeEventListener('resize', reposition);
|
|
733
|
-
removeEventListener('scroll', reposition, { capture: true });
|
|
734
|
-
};
|
|
735
|
-
});
|
|
736
|
-
|
|
737
|
-
// Keep the active option in view as the keyboard moves through the list
|
|
738
|
-
$effect(() => {
|
|
739
|
-
if (!open || !activeModel || !list) return;
|
|
740
|
-
list
|
|
741
|
-
.querySelector(`#${CSS.escape(optionId(activeModel))}`)
|
|
742
|
-
?.scrollIntoView({ block: 'nearest' });
|
|
743
|
-
});
|
|
744
|
-
|
|
745
816
|
// Shows the models of another place in the rail, on the first it can choose
|
|
746
|
-
function showProvider(item: string) {
|
|
817
|
+
async function showProvider(item: string) {
|
|
747
818
|
shown = item;
|
|
748
819
|
query = '';
|
|
749
|
-
|
|
750
|
-
|
|
820
|
+
await tick();
|
|
821
|
+
highlight(firstActive());
|
|
751
822
|
}
|
|
752
823
|
|
|
753
824
|
function cycleProvider(step: number) {
|
|
@@ -755,42 +826,24 @@
|
|
|
755
826
|
showProvider(railItems[(at + step + railItems.length) % railItems.length]);
|
|
756
827
|
}
|
|
757
828
|
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
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]);
|
|
762
834
|
}
|
|
763
835
|
|
|
836
|
+
// Page Up and Page Down move a few models, and stop at the ends
|
|
764
837
|
function move(step: number) {
|
|
765
838
|
if (!entries.length) return;
|
|
766
839
|
const index = entries.indexOf(active!);
|
|
767
840
|
const next = index === -1 ? (step > 0 ? 0 : entries.length - 1) : index + step;
|
|
768
|
-
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
function toggleOlder() {
|
|
772
|
-
showOlder = !showOlder;
|
|
773
|
-
active = OLDER;
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
// Typing a letter or two jumps to the model whose name starts with them
|
|
777
|
-
let typed = '';
|
|
778
|
-
let typedTimer: ReturnType<typeof setTimeout> | undefined;
|
|
779
|
-
function typeahead(char: string) {
|
|
780
|
-
clearTimeout(typedTimer);
|
|
781
|
-
typed += char.toLowerCase();
|
|
782
|
-
typedTimer = setTimeout(() => (typed = ''), 600);
|
|
783
|
-
const start = enabled.findIndex((model) => model.value === active);
|
|
784
|
-
const ordered = [...enabled.slice(start + 1), ...enabled.slice(0, start + 1)];
|
|
785
|
-
const pool =
|
|
786
|
-
typed.length === 1 ? ordered : [...enabled.slice(start), ...enabled.slice(0, start)];
|
|
787
|
-
const match = pool.find((model) => model.label.toLowerCase().startsWith(typed));
|
|
788
|
-
if (match) active = match.value;
|
|
841
|
+
highlight(entries[Math.min(Math.max(next, 0), entries.length - 1)]);
|
|
789
842
|
}
|
|
790
843
|
|
|
791
|
-
// The keys
|
|
792
|
-
//
|
|
793
|
-
function
|
|
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) {
|
|
794
847
|
if (event.isComposing) return;
|
|
795
848
|
const inField = event.target === field;
|
|
796
849
|
const mod = event.metaKey || event.ctrlKey;
|
|
@@ -802,140 +855,130 @@
|
|
|
802
855
|
return;
|
|
803
856
|
}
|
|
804
857
|
switch (event.key) {
|
|
805
|
-
case 'ArrowDown':
|
|
806
|
-
move(1);
|
|
807
|
-
break;
|
|
808
|
-
case 'ArrowUp':
|
|
809
|
-
move(-1);
|
|
810
|
-
break;
|
|
811
858
|
case 'PageDown':
|
|
812
|
-
move(PAGE);
|
|
813
|
-
break;
|
|
814
859
|
case 'PageUp':
|
|
815
|
-
move(-PAGE);
|
|
816
|
-
break;
|
|
817
|
-
case 'Home':
|
|
818
|
-
case 'End':
|
|
819
|
-
if (inField) return;
|
|
820
|
-
active = event.key === 'Home' ? entries[0] : entries.at(-1);
|
|
821
|
-
break;
|
|
822
|
-
case 'Enter':
|
|
823
|
-
if (active === OLDER) toggleOlder();
|
|
824
|
-
else if (activeModel) choose(activeModel, event.shiftKey || mod);
|
|
825
|
-
break;
|
|
826
|
-
case ' ':
|
|
827
|
-
if (inField) return;
|
|
828
|
-
if (typed) typeahead(' ');
|
|
829
|
-
else if (active === OLDER) toggleOlder();
|
|
830
|
-
else if (activeModel) choose(activeModel, event.shiftKey);
|
|
860
|
+
move(event.key === 'PageDown' ? PAGE : -PAGE);
|
|
831
861
|
break;
|
|
832
862
|
case 'ArrowLeft':
|
|
833
863
|
case 'ArrowRight': {
|
|
834
864
|
// Left and right go through the rail, mirrored right to left, unless words are typed
|
|
835
865
|
if (!railed || (inField && query !== '')) return;
|
|
836
|
-
const rtl = !!
|
|
866
|
+
const rtl = !!content && getComputedStyle(content).direction === 'rtl';
|
|
837
867
|
cycleProvider((event.key === 'ArrowRight') !== rtl ? 1 : -1);
|
|
838
868
|
break;
|
|
839
869
|
}
|
|
840
|
-
case 'Tab':
|
|
841
|
-
hide();
|
|
842
|
-
break;
|
|
843
870
|
default:
|
|
844
|
-
if (!inField && event.key.length === 1 && !mod && !event.altKey) {
|
|
845
|
-
typeahead(event.key);
|
|
846
|
-
break;
|
|
847
|
-
}
|
|
848
871
|
return;
|
|
849
872
|
}
|
|
850
873
|
event.preventDefault();
|
|
851
874
|
}
|
|
852
875
|
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
if (event.defaultPrevented) return;
|
|
856
|
-
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
857
|
-
event.preventDefault();
|
|
858
|
-
show();
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
$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();
|
|
863
878
|
</script>
|
|
864
879
|
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
{
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
}
|
|
882
|
-
|
|
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)}
|
|
883
899
|
>
|
|
884
|
-
<
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
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>
|
|
888
913
|
|
|
889
|
-
<
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
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>
|
|
931
974
|
</div>
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
{
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
</
|
|
975
|
+
{:else}
|
|
976
|
+
{@render search()}
|
|
977
|
+
{@render options()}
|
|
978
|
+
{/if}
|
|
979
|
+
<span role="status" {...stylex.attrs(visuallyHidden)}>{announcement}</span>
|
|
980
|
+
</SelectContent>
|
|
981
|
+
</UiSelect>
|
|
939
982
|
|
|
940
983
|
{#snippet starGlyph(filled: boolean)}
|
|
941
984
|
<svg data-glyph="" width="14" height="14" viewBox="0 0 16 16" aria-hidden="true">
|
|
@@ -953,22 +996,14 @@
|
|
|
953
996
|
{#if searchable}
|
|
954
997
|
<div {...stylex.attrs(styles.search)}>
|
|
955
998
|
<Glyph name="search" size={14} />
|
|
956
|
-
<
|
|
957
|
-
bind:this={field}
|
|
958
|
-
type="text"
|
|
959
|
-
role="combobox"
|
|
960
|
-
aria-expanded="true"
|
|
961
|
-
aria-autocomplete="list"
|
|
962
|
-
aria-controls="{uid}-listbox"
|
|
963
|
-
aria-activedescendant={activeId}
|
|
999
|
+
<SelectInput
|
|
964
1000
|
aria-label={word.search}
|
|
965
1001
|
placeholder="{word.search}…"
|
|
966
|
-
autocomplete="off"
|
|
967
|
-
spellcheck={false}
|
|
968
|
-
value={query}
|
|
969
|
-
oninput={onsearch}
|
|
970
|
-
onkeydown={onListKeydown}
|
|
971
1002
|
{...stylex.attrs(styles.searchField)}
|
|
1003
|
+
{@attach (element: HTMLInputElement) => {
|
|
1004
|
+
field = element;
|
|
1005
|
+
return () => (field = null);
|
|
1006
|
+
}}
|
|
972
1007
|
/>
|
|
973
1008
|
</div>
|
|
974
1009
|
{/if}
|
|
@@ -982,42 +1017,26 @@
|
|
|
982
1017
|
{/snippet}
|
|
983
1018
|
|
|
984
1019
|
{#snippet listbox()}
|
|
985
|
-
<
|
|
986
|
-
bind:this={list}
|
|
987
|
-
id="{uid}-listbox"
|
|
988
|
-
role="listbox"
|
|
989
|
-
tabindex="-1"
|
|
990
|
-
aria-label={heading ? `${label}: ${heading}` : label}
|
|
991
|
-
aria-multiselectable={multiple || besideable || undefined}
|
|
992
|
-
aria-activedescendant={!searchable ? activeId : undefined}
|
|
993
|
-
{...stylex.attrs(styles.list)}
|
|
994
|
-
onkeydown={onListKeydown}
|
|
995
|
-
>
|
|
1020
|
+
<SelectList aria-label={heading ? `${label}: ${heading}` : label} {...stylex.attrs(styles.list)}>
|
|
996
1021
|
{#each groups as group, g (g)}
|
|
997
|
-
<
|
|
998
|
-
role="group"
|
|
999
|
-
aria-labelledby={group.name ? `${uid}-group-${g}` : undefined}
|
|
1000
|
-
{...stylex.attrs(g > 0 && styles.group)}
|
|
1001
|
-
>
|
|
1022
|
+
<SelectGroup {...stylex.attrs(g > 0 && styles.group)}>
|
|
1002
1023
|
{#if group.name}
|
|
1003
|
-
<
|
|
1024
|
+
<SelectGroupLabel {...stylex.attrs(styles.groupLabel)}>{group.name}</SelectGroupLabel>
|
|
1004
1025
|
{/if}
|
|
1005
1026
|
{#each group.models as model (model.value)}
|
|
1006
1027
|
{@render option(model)}
|
|
1007
1028
|
{/each}
|
|
1008
|
-
</
|
|
1029
|
+
</SelectGroup>
|
|
1009
1030
|
{/each}
|
|
1010
1031
|
{#if foldable}
|
|
1011
1032
|
{@const count = old.length}
|
|
1012
|
-
<!-- Opens or folds the older models
|
|
1013
|
-
<
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
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}
|
|
1017
1037
|
aria-label="{word.older}, {count}"
|
|
1018
|
-
{
|
|
1019
|
-
|
|
1020
|
-
onclick={toggleOlder}
|
|
1038
|
+
data-model={OLDER}
|
|
1039
|
+
{...stylex.attrs(styles.option, styles.olderRow)}
|
|
1021
1040
|
>
|
|
1022
1041
|
<span {...stylex.attrs(styles.name, styles.olderName)}>
|
|
1023
1042
|
<span {...stylex.attrs(styles.nameText)}>{word.older}</span>
|
|
@@ -1026,14 +1045,14 @@
|
|
|
1026
1045
|
<span {...stylex.attrs(styles.olderChevron, showOlder && styles.olderOpen)}
|
|
1027
1046
|
><Glyph name="chevron" size={14} /></span
|
|
1028
1047
|
>
|
|
1029
|
-
</
|
|
1048
|
+
</SelectItem>
|
|
1030
1049
|
{#if showOlder}
|
|
1031
1050
|
{#each old as model (model.value)}
|
|
1032
1051
|
{@render option(model)}
|
|
1033
1052
|
{/each}
|
|
1034
1053
|
{/if}
|
|
1035
1054
|
{/if}
|
|
1036
|
-
</
|
|
1055
|
+
</SelectList>
|
|
1037
1056
|
{#if besideable}
|
|
1038
1057
|
<p {...stylex.attrs(styles.hint)}>{word.alsoHint}</p>
|
|
1039
1058
|
{/if}
|
|
@@ -1042,22 +1061,17 @@
|
|
|
1042
1061
|
{#snippet option(model: ComposerModel)}
|
|
1043
1062
|
{@const isSelected = isChosen(model)}
|
|
1044
1063
|
{@const star = isStarred(model)}
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
aria-
|
|
1050
|
-
|
|
1064
|
+
<SelectItem
|
|
1065
|
+
value={model.value}
|
|
1066
|
+
label={model.label}
|
|
1067
|
+
disabled={model.disabled}
|
|
1068
|
+
aria-label={optionName(model, star)}
|
|
1069
|
+
data-model={model.value}
|
|
1051
1070
|
{...stylex.attrs(
|
|
1052
1071
|
styles.option,
|
|
1053
1072
|
starrable && styles.optionStarrable,
|
|
1054
|
-
model.value === active && styles.active,
|
|
1055
1073
|
model.disabled && styles.optionDisabled
|
|
1056
1074
|
)}
|
|
1057
|
-
onpointermove={() => {
|
|
1058
|
-
if (!model.disabled) active = model.value;
|
|
1059
|
-
}}
|
|
1060
|
-
onclick={(event) => choose(model, event.shiftKey || event.metaKey || event.ctrlKey)}
|
|
1061
1075
|
>
|
|
1062
1076
|
<span {...stylex.attrs(styles.name)}>
|
|
1063
1077
|
<span {...stylex.attrs(styles.nameText)}>{model.label}</span>
|
|
@@ -1065,13 +1079,15 @@
|
|
|
1065
1079
|
{#if mixed && railed && model.provider}
|
|
1066
1080
|
<span {...stylex.attrs(styles.from)}>{providerName(model)}</span>
|
|
1067
1081
|
{/if}
|
|
1068
|
-
{#if star}<span {...stylex.attrs(visuallyHidden)}>, {word.starred}</span>{/if}
|
|
1069
1082
|
</span>
|
|
1070
1083
|
{#if isSelected}
|
|
1071
1084
|
<span {...stylex.attrs(styles.check)}><Glyph name="check" stroke={1.75} /></span>
|
|
1072
1085
|
{/if}
|
|
1073
1086
|
{#if starrable}
|
|
1074
|
-
<!--
|
|
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
|
+
-->
|
|
1075
1091
|
<button
|
|
1076
1092
|
type="button"
|
|
1077
1093
|
tabindex="-1"
|
|
@@ -1080,7 +1096,9 @@
|
|
|
1080
1096
|
styles.star,
|
|
1081
1097
|
star ? styles.starOn : model.value !== active && styles.starHidden
|
|
1082
1098
|
)}
|
|
1083
|
-
|
|
1099
|
+
onmousedown={keepFocus}
|
|
1100
|
+
onclickcapture={(event) => {
|
|
1101
|
+
event.preventDefault();
|
|
1084
1102
|
event.stopPropagation();
|
|
1085
1103
|
toggleStar(model);
|
|
1086
1104
|
}}
|
|
@@ -1091,5 +1109,5 @@
|
|
|
1091
1109
|
{#if model.description}
|
|
1092
1110
|
<span {...stylex.attrs(styles.description)}>{model.description}</span>
|
|
1093
1111
|
{/if}
|
|
1094
|
-
</
|
|
1112
|
+
</SelectItem>
|
|
1095
1113
|
{/snippet}
|