@diegopluna/narvi 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/activity/ActivityIcon.svelte +54 -0
- package/dist/components/activity/ActivityIcon.svelte.d.ts +24 -0
- package/dist/components/activity/ActivityStep.svelte +47 -13
- package/dist/components/activity/ActivityStep.svelte.d.ts +13 -4
- package/dist/components/activity/ActivityThought.svelte +24 -5
- package/dist/components/activity/ActivityThought.svelte.d.ts +12 -2
- package/dist/components/activity/index.d.ts +3 -1
- package/dist/components/activity/index.js +2 -1
- package/dist/components/app-shell/AppShellHeader.svelte +18 -4
- package/dist/components/app-shell/AppShellHeader.svelte.d.ts +5 -0
- package/dist/components/app-shell/AppShellMain.svelte +5 -1
- package/dist/components/approval/Approval.svelte +14 -1
- package/dist/components/approval/Approval.svelte.d.ts +5 -0
- package/dist/components/badge/Badge.svelte +19 -2
- package/dist/components/badge/Badge.svelte.d.ts +4 -1
- package/dist/components/button/Button.svelte +63 -13
- package/dist/components/composer/ComposerModelPicker.svelte +80 -13
- package/dist/components/composer/ComposerModelPicker.svelte.d.ts +23 -6
- package/dist/components/composer/ComposerRoot.svelte +51 -12
- package/dist/components/composer/ComposerRoot.svelte.d.ts +16 -0
- package/dist/components/composer/ComposerSubmit.svelte +19 -5
- package/dist/components/composer/ComposerSubmit.svelte.d.ts +3 -1
- package/dist/components/composer/ComposerToggle.svelte +18 -4
- package/dist/components/composer/ComposerToggle.svelte.d.ts +2 -0
- package/dist/components/composer/ComposerTray.svelte +17 -3
- package/dist/components/composer/ComposerTray.svelte.d.ts +5 -0
- package/dist/components/composer/context.d.ts +4 -1
- package/dist/components/dialog/DialogContent.svelte +22 -12
- package/dist/components/dialog/DialogContent.svelte.d.ts +10 -0
- package/dist/components/divider/Divider.svelte +56 -14
- package/dist/components/divider/Divider.svelte.d.ts +13 -3
- package/dist/components/empty-state/EmptyState.svelte +12 -2
- package/dist/components/empty-state/EmptyState.svelte.d.ts +6 -0
- package/dist/components/heading/Heading.svelte +15 -0
- package/dist/components/heading/Heading.svelte.d.ts +6 -0
- package/dist/components/hover-card/HoverCardContent.svelte +19 -3
- package/dist/components/hover-card/HoverCardContent.svelte.d.ts +8 -0
- package/dist/components/input/Input.svelte +13 -3
- package/dist/components/input/Input.svelte.d.ts +10 -2
- package/dist/components/markdown/Markdown.svelte +22 -2
- package/dist/components/markdown/MarkdownDiagram.svelte +33 -2
- package/dist/components/markdown/MarkdownFile.svelte +56 -10
- package/dist/components/markdown/MarkdownMath.svelte +6 -0
- package/dist/components/markdown/MarkdownTable.svelte +3 -4
- package/dist/components/markdown/context.d.ts +6 -0
- package/dist/components/markdown/labels.d.ts +7 -0
- package/dist/components/markdown/labels.js +2 -0
- package/dist/components/menu/ContextMenuTrigger.svelte +14 -2
- package/dist/components/menu/ContextMenuTrigger.svelte.d.ts +10 -0
- package/dist/components/menu/MenuCheckboxItem.svelte +50 -7
- package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +16 -0
- package/dist/components/menu/MenuContent.svelte +10 -2
- package/dist/components/menu/MenuContent.svelte.d.ts +10 -0
- package/dist/components/menu/MenuGroup.svelte +16 -0
- package/dist/components/menu/MenuGroup.svelte.d.ts +6 -0
- package/dist/components/menu/MenuItem.svelte +17 -2
- package/dist/components/menu/MenuItem.svelte.d.ts +8 -0
- package/dist/components/menu/MenuLabel.svelte +22 -8
- package/dist/components/menu/MenuRadioGroup.svelte +16 -0
- package/dist/components/menu/MenuRadioGroup.svelte.d.ts +6 -0
- package/dist/components/menu/MenuSubContent.svelte +10 -2
- package/dist/components/menu/MenuSubContent.svelte.d.ts +10 -0
- package/dist/components/menu/MenuSubTrigger.svelte +19 -2
- package/dist/components/menu/MenuSubTrigger.svelte.d.ts +6 -0
- package/dist/components/menu/group.d.ts +2 -0
- package/dist/components/menu/group.js +9 -0
- package/dist/components/menu/index.d.ts +4 -2
- package/dist/components/menu/index.js +2 -2
- package/dist/components/message/MessageBubble.svelte +40 -0
- package/dist/components/message/MessageBubble.svelte.d.ts +12 -0
- package/dist/components/message/MessageContent.svelte +23 -14
- package/dist/components/message/MessageContent.svelte.d.ts +6 -0
- package/dist/components/message/MessageCopy.svelte +27 -15
- package/dist/components/message/MessageCopy.svelte.d.ts +9 -2
- package/dist/components/message/MessageRoot.svelte +20 -3
- package/dist/components/message/MessageRoot.svelte.d.ts +6 -0
- package/dist/components/message/context.d.ts +2 -0
- package/dist/components/message/index.d.ts +4 -1
- package/dist/components/message/index.js +3 -2
- package/dist/components/message/styles.d.ts +30 -0
- package/dist/components/message/styles.js +24 -0
- package/dist/components/notice/Notice.svelte +3 -3
- package/dist/components/popover/PopoverContent.svelte +27 -3
- package/dist/components/popover/PopoverContent.svelte.d.ts +18 -0
- package/dist/components/questionnaire/Questionnaire.svelte +103 -19
- package/dist/components/questionnaire/Questionnaire.svelte.d.ts +13 -1
- package/dist/components/queued-message/QueuedMessage.svelte +44 -6
- package/dist/components/queued-message/QueuedMessage.svelte.d.ts +12 -1
- package/dist/components/select/Select.svelte +18 -2
- package/dist/components/select/Select.svelte.d.ts +7 -0
- package/dist/components/sidebar/SidebarContent.svelte +59 -13
- package/dist/components/sidebar/SidebarContent.svelte.d.ts +6 -0
- package/dist/components/sidebar/SidebarFolder.svelte +29 -2
- package/dist/components/sidebar/SidebarGroup.svelte +50 -7
- package/dist/components/sidebar/SidebarGroup.svelte.d.ts +10 -1
- package/dist/components/sidebar/SidebarItem.svelte +136 -21
- package/dist/components/sidebar/SidebarItem.svelte.d.ts +22 -2
- package/dist/components/sidebar/SidebarSwitcher.svelte +18 -2
- package/dist/components/sidebar/SidebarSwitcher.svelte.d.ts +2 -0
- package/dist/components/sidebar/fold.d.ts +12 -0
- package/dist/components/sidebar/fold.js +8 -0
- package/dist/components/status-indicator/StatusDot.svelte +90 -0
- package/dist/components/status-indicator/StatusDot.svelte.d.ts +18 -0
- package/dist/components/toast/Toaster.svelte +1 -1
- package/dist/components/toggle/Toggle.svelte +12 -2
- package/dist/components/toggle/Toggle.svelte.d.ts +11 -1
- package/dist/components/toggle-group/ToggleGroupItem.svelte +10 -1
- package/dist/components/toggle-group/ToggleGroupRoot.svelte +7 -1
- package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +3 -1
- package/dist/components/toggle-group/context.d.ts +2 -1
- package/dist/components/tooltip/TooltipContent.svelte +13 -1
- package/dist/components/tooltip/TooltipContent.svelte.d.ts +10 -0
- package/dist/components/work-fold/WorkFold.svelte +13 -4
- package/dist/components/work-fold/WorkFold.svelte.d.ts +2 -1
- package/dist/focus-ring.d.ts +29 -0
- package/dist/focus-ring.js +42 -0
- package/dist/index.d.ts +9 -6
- package/dist/index.js +8 -2
- package/dist/internal/Collapse.svelte +15 -2
- package/dist/internal/Glyph.svelte +28 -0
- package/dist/internal/Glyph.svelte.d.ts +5 -0
- package/dist/internal/Tile.svelte +3 -2
- package/dist/internal/layer.d.ts +23 -0
- package/dist/internal/layer.js +19 -0
- package/dist/internal/toggle.d.ts +8 -1
- package/dist/internal/toggle.js +20 -2
- package/dist/markdown/file-paths.d.ts +7 -0
- package/dist/markdown/file-paths.js +29 -0
- package/dist/markdown/files.d.ts +22 -2
- package/dist/markdown/files.js +45 -14
- package/dist/tokens.stylex.d.ts +3 -0
- package/dist/tokens.stylex.js +5 -1
- package/package.json +1 -1
- package/skills/building-ui/SKILL.md +87 -8
- package/skills/building-ui/references/components.md +39 -38
- package/skills/markdown/SKILL.md +22 -6
- package/skills/setup/SKILL.md +1 -1
- package/skills/styling/SKILL.md +10 -3
- package/skills/theming/SKILL.md +11 -4
|
@@ -55,6 +55,10 @@
|
|
|
55
55
|
|
|
56
56
|
// One key for every hover, so the catalog can show it without a pointer
|
|
57
57
|
const HOVER = ':is(:hover, [data-preview~="hover"])';
|
|
58
|
+
// The trigger of a menu, a popover or a select while what it opened is showing. bits-ui
|
|
59
|
+
// marks it with `aria-expanded`, which a disclosure's trigger carries too: only a popup's
|
|
60
|
+
// (`aria-haspopup`) is held in its open look.
|
|
61
|
+
const OPEN = ':is([aria-haspopup]:not([aria-haspopup="false"])[aria-expanded="true"])';
|
|
58
62
|
|
|
59
63
|
const styles = stylex.create({
|
|
60
64
|
base: {
|
|
@@ -138,11 +142,49 @@
|
|
|
138
142
|
borderRadius: radius.panel,
|
|
139
143
|
fontSize: font.sizeReading
|
|
140
144
|
},
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
145
|
+
// Square. Last in a slot that lines its controls up by their marks (one that sets
|
|
146
|
+
// `--narvi-icon-flush: 1`, as a sidebar group's actions do), the button reaches out by the
|
|
147
|
+
// room around its icon, so the icon, not the box, ends on the line.
|
|
148
|
+
iconMicro: {
|
|
149
|
+
width: '1.25rem',
|
|
150
|
+
paddingInline: 0,
|
|
151
|
+
marginInlineEnd: {
|
|
152
|
+
default: null,
|
|
153
|
+
':last-child': 'calc(var(--narvi-icon-flush, 0) * (0.75rem - 1.25rem) / 2)'
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
iconXs: {
|
|
157
|
+
width: '1.5rem',
|
|
158
|
+
paddingInline: 0,
|
|
159
|
+
marginInlineEnd: {
|
|
160
|
+
default: null,
|
|
161
|
+
':last-child': 'calc(var(--narvi-icon-flush, 0) * (0.875rem - 1.5rem) / 2)'
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
iconSm: {
|
|
165
|
+
width: '1.75rem',
|
|
166
|
+
paddingInline: 0,
|
|
167
|
+
marginInlineEnd: {
|
|
168
|
+
default: null,
|
|
169
|
+
':last-child': 'calc(var(--narvi-icon-flush, 0) * (0.875rem - 1.75rem) / 2)'
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
iconMd: {
|
|
173
|
+
width: '2rem',
|
|
174
|
+
paddingInline: 0,
|
|
175
|
+
marginInlineEnd: {
|
|
176
|
+
default: null,
|
|
177
|
+
':last-child': 'calc(var(--narvi-icon-flush, 0) * (1rem - 2rem) / 2)'
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
iconLg: {
|
|
181
|
+
width: '2.5rem',
|
|
182
|
+
paddingInline: 0,
|
|
183
|
+
marginInlineEnd: {
|
|
184
|
+
default: null,
|
|
185
|
+
':last-child': 'calc(var(--narvi-icon-flush, 0) * (1.125rem - 2.5rem) / 2)'
|
|
186
|
+
}
|
|
187
|
+
},
|
|
146
188
|
|
|
147
189
|
pill: { borderRadius: radius.pill },
|
|
148
190
|
|
|
@@ -156,7 +198,8 @@
|
|
|
156
198
|
color: colors.text,
|
|
157
199
|
backgroundColor: {
|
|
158
200
|
default: 'transparent',
|
|
159
|
-
[HOVER]: { default: null, [media.hover]: colors.fillHover }
|
|
201
|
+
[HOVER]: { default: null, [media.hover]: colors.fillHover },
|
|
202
|
+
[OPEN]: colors.fillSelected
|
|
160
203
|
},
|
|
161
204
|
boxShadow: `inset 0 0 0 1px ${colors.borderStrong}`
|
|
162
205
|
},
|
|
@@ -167,21 +210,25 @@
|
|
|
167
210
|
[HOVER]: { default: null, [media.hover]: colors.focusHalo }
|
|
168
211
|
}
|
|
169
212
|
},
|
|
213
|
+
// Open, it holds the fill of what is chosen while its menu shows, a step past a hover
|
|
170
214
|
ghost: {
|
|
171
215
|
color: {
|
|
172
216
|
default: colors.textMuted,
|
|
173
|
-
[HOVER]: { default: null, [media.hover]: colors.text }
|
|
217
|
+
[HOVER]: { default: null, [media.hover]: colors.text },
|
|
218
|
+
[OPEN]: colors.text
|
|
174
219
|
},
|
|
175
220
|
backgroundColor: {
|
|
176
221
|
default: 'transparent',
|
|
177
|
-
[HOVER]: { default: null, [media.hover]: colors.fillHover }
|
|
222
|
+
[HOVER]: { default: null, [media.hover]: colors.fillHover },
|
|
223
|
+
[OPEN]: colors.fillSelected
|
|
178
224
|
}
|
|
179
225
|
},
|
|
180
226
|
// No surface in any state: for a control on a shape that already frames it
|
|
181
227
|
bare: {
|
|
182
228
|
color: {
|
|
183
229
|
default: colors.textMuted,
|
|
184
|
-
[HOVER]: { default: null, [media.hover]: colors.text }
|
|
230
|
+
[HOVER]: { default: null, [media.hover]: colors.text },
|
|
231
|
+
[OPEN]: colors.text
|
|
185
232
|
},
|
|
186
233
|
backgroundColor: 'transparent'
|
|
187
234
|
},
|
|
@@ -205,7 +252,8 @@
|
|
|
205
252
|
floating: {
|
|
206
253
|
color: {
|
|
207
254
|
default: colors.textMuted,
|
|
208
|
-
[HOVER]: { default: null, [media.hover]: colors.text }
|
|
255
|
+
[HOVER]: { default: null, [media.hover]: colors.text },
|
|
256
|
+
[OPEN]: colors.text
|
|
209
257
|
},
|
|
210
258
|
backgroundColor: colors.bgRaised,
|
|
211
259
|
boxShadow: {
|
|
@@ -213,7 +261,8 @@
|
|
|
213
261
|
[HOVER]: {
|
|
214
262
|
default: null,
|
|
215
263
|
[media.hover]: `inset 0 0 0 1px ${colors.borderStrong}, 0 6px 16px -6px ${colors.shadow}`
|
|
216
|
-
}
|
|
264
|
+
},
|
|
265
|
+
[OPEN]: `inset 0 0 0 1px ${colors.borderStrong}, 0 6px 16px -6px ${colors.shadow}`
|
|
217
266
|
}
|
|
218
267
|
},
|
|
219
268
|
// What cannot be undone, as a solid: the one press a dialog is asking for
|
|
@@ -382,7 +431,8 @@
|
|
|
382
431
|
}
|
|
383
432
|
const contentClass = classes(styles.content);
|
|
384
433
|
|
|
385
|
-
// The spinner beside a loading label, as large as an icon in a
|
|
434
|
+
// The spinner, beside a loading label or in place of the content, as large as an icon in a
|
|
435
|
+
// button of that size
|
|
386
436
|
const SPINNER = { micro: 12, xs: 14, sm: 14, md: 16, lg: 18 } as const;
|
|
387
437
|
</script>
|
|
388
438
|
|
|
@@ -437,7 +487,7 @@
|
|
|
437
487
|
{/if}
|
|
438
488
|
{#if loading && !loadingLabel}
|
|
439
489
|
<span {...stylex.attrs(styles.spinner)}>
|
|
440
|
-
<Spinner size={
|
|
490
|
+
<Spinner size={SPINNER[size]} label="Loading" />
|
|
441
491
|
</span>
|
|
442
492
|
{/if}
|
|
443
493
|
{/snippet}
|
|
@@ -20,18 +20,40 @@
|
|
|
20
20
|
disabled?: boolean | undefined;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
type PickerBase = Omit<HTMLButtonAttributes, 'children' | 'value' | 'onchange'> & {
|
|
24
24
|
models: ComposerModel[];
|
|
25
|
-
/** The chosen model's value. Bindable. Defaults to the first model. */
|
|
26
|
-
value?: string | undefined;
|
|
27
25
|
/** What is being chosen. Names the list, and is read before the model on the button. */
|
|
28
26
|
label?: string | undefined;
|
|
29
|
-
/**
|
|
30
|
-
|
|
27
|
+
/** Whether the list is showing. Bindable. */
|
|
28
|
+
open?: boolean | undefined;
|
|
29
|
+
/** Called when the list opens or closes. */
|
|
30
|
+
onopenchange?: ((open: boolean) => void) | undefined;
|
|
31
31
|
sx?: Sx | undefined;
|
|
32
32
|
ref?: HTMLButtonElement | null | undefined;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
export type ComposerModelPickerProps = PickerBase &
|
|
36
|
+
(
|
|
37
|
+
| {
|
|
38
|
+
/** Lets several models be chosen, such as to run one prompt on each. */
|
|
39
|
+
multiple?: false | undefined;
|
|
40
|
+
/** The chosen model's value. Bindable. Defaults to the first model. */
|
|
41
|
+
value?: string | undefined;
|
|
42
|
+
/** Called when the person picks a model. */
|
|
43
|
+
onchange?: ((value: string) => void) | undefined;
|
|
44
|
+
placeholder?: undefined;
|
|
45
|
+
}
|
|
46
|
+
| {
|
|
47
|
+
multiple: true;
|
|
48
|
+
/** The chosen models' values, in the order of `models`. Bindable. */
|
|
49
|
+
value?: string[] | undefined;
|
|
50
|
+
/** Called with every chosen model's value when the person picks or drops one. */
|
|
51
|
+
onchange?: ((value: string[]) => void) | undefined;
|
|
52
|
+
/** What the button says while none is chosen. */
|
|
53
|
+
placeholder?: string | undefined;
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
|
|
35
57
|
const GAP = 6;
|
|
36
58
|
const MARGIN = 8;
|
|
37
59
|
|
|
@@ -76,6 +98,7 @@
|
|
|
76
98
|
overflow: 'hidden',
|
|
77
99
|
textOverflow: 'ellipsis'
|
|
78
100
|
},
|
|
101
|
+
more: { flexShrink: 0, color: colors.textSubtle, fontVariantNumeric: 'tabular-nums' },
|
|
79
102
|
selector: { display: 'grid', flexShrink: 0, opacity: 0.7 },
|
|
80
103
|
|
|
81
104
|
// The list floats in the top layer, placed beside the button by script.
|
|
@@ -216,10 +239,16 @@
|
|
|
216
239
|
</script>
|
|
217
240
|
|
|
218
241
|
<script lang="ts">
|
|
242
|
+
import { untrack } from 'svelte';
|
|
243
|
+
|
|
219
244
|
let {
|
|
220
245
|
models,
|
|
221
246
|
value = $bindable(),
|
|
222
247
|
label = 'Model',
|
|
248
|
+
multiple = false,
|
|
249
|
+
placeholder = 'Choose models',
|
|
250
|
+
open = $bindable(false),
|
|
251
|
+
onopenchange,
|
|
223
252
|
onchange,
|
|
224
253
|
disabled,
|
|
225
254
|
sx,
|
|
@@ -235,14 +264,26 @@
|
|
|
235
264
|
|
|
236
265
|
let popover = $state<HTMLDivElement | null>(null);
|
|
237
266
|
let list = $state<HTMLDivElement | null>(null);
|
|
238
|
-
let open = $state(false);
|
|
239
267
|
let active = $state<string>();
|
|
240
268
|
|
|
241
269
|
const groups = $derived(groupModels(models));
|
|
242
270
|
const enabled = $derived(models.filter((model) => !model.disabled));
|
|
243
|
-
|
|
271
|
+
// The chosen models, in the list's order. One at most, and the first by default, unless several may be.
|
|
272
|
+
const chosen = $derived.by((): ComposerModel[] => {
|
|
273
|
+
if (multiple) {
|
|
274
|
+
const values = Array.isArray(value) ? value : [];
|
|
275
|
+
return models.filter((model) => values.includes(model.value));
|
|
276
|
+
}
|
|
277
|
+
const one = models.find((model) => model.value === value) ?? models[0];
|
|
278
|
+
return one ? [one] : [];
|
|
279
|
+
});
|
|
280
|
+
const selected = $derived(chosen[0]);
|
|
281
|
+
const isChosen = (model: ComposerModel) => chosen.includes(model);
|
|
244
282
|
const optionId = (model: ComposerModel) => `${uid}-option-${models.indexOf(model)}`;
|
|
245
283
|
const activeModel = $derived(models.find((model) => model.value === active));
|
|
284
|
+
const said = $derived(
|
|
285
|
+
chosen.length ? chosen.map((model) => model.label).join(', ') : multiple ? placeholder : ''
|
|
286
|
+
);
|
|
246
287
|
|
|
247
288
|
function show() {
|
|
248
289
|
active = selected && !selected.disabled ? selected.value : enabled[0]?.value;
|
|
@@ -260,8 +301,17 @@
|
|
|
260
301
|
|
|
261
302
|
function choose(model: ComposerModel) {
|
|
262
303
|
if (model.disabled) return;
|
|
304
|
+
if (multiple) {
|
|
305
|
+
// Several may be chosen: the list stays open to choose the next
|
|
306
|
+
const values = isChosen(model)
|
|
307
|
+
? chosen.filter((m) => m !== model).map((m) => m.value)
|
|
308
|
+
: models.filter((m) => m === model || isChosen(m)).map((m) => m.value);
|
|
309
|
+
value = values;
|
|
310
|
+
(onchange as ((value: string[]) => void) | undefined)?.(values);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
263
313
|
value = model.value;
|
|
264
|
-
onchange?.(model.value);
|
|
314
|
+
(onchange as ((value: string) => void) | undefined)?.(model.value);
|
|
265
315
|
hide();
|
|
266
316
|
}
|
|
267
317
|
|
|
@@ -291,13 +341,28 @@
|
|
|
291
341
|
}
|
|
292
342
|
|
|
293
343
|
function ontoggle(event: ToggleEvent) {
|
|
294
|
-
|
|
295
|
-
if (
|
|
344
|
+
const next = event.newState === 'open';
|
|
345
|
+
if (next !== open) {
|
|
346
|
+
open = next;
|
|
347
|
+
onopenchange?.(next);
|
|
348
|
+
}
|
|
349
|
+
if (!next && popover?.contains(document.activeElement)) {
|
|
296
350
|
// Closed by Escape or a click outside while the list had focus
|
|
297
351
|
ref?.focus();
|
|
298
352
|
}
|
|
299
353
|
}
|
|
300
354
|
|
|
355
|
+
// `open`, set from outside: the list follows it
|
|
356
|
+
$effect(() => {
|
|
357
|
+
const want = open;
|
|
358
|
+
if (!popover) return;
|
|
359
|
+
untrack(() => {
|
|
360
|
+
const shown = popover!.matches(':popover-open');
|
|
361
|
+
if (want && !shown) show();
|
|
362
|
+
else if (!want && shown) hide(popover!.contains(document.activeElement));
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
|
|
301
366
|
$effect(() => {
|
|
302
367
|
if (!open) return;
|
|
303
368
|
const reposition = () => place();
|
|
@@ -392,7 +457,7 @@
|
|
|
392
457
|
aria-haspopup="listbox"
|
|
393
458
|
aria-expanded={open}
|
|
394
459
|
aria-controls="{uid}-popover"
|
|
395
|
-
aria-label="{label}: {
|
|
460
|
+
aria-label="{label}: {said}"
|
|
396
461
|
disabled={disabled ?? composer?.disabled}
|
|
397
462
|
data-slot="composer-model-picker"
|
|
398
463
|
{...rest}
|
|
@@ -405,7 +470,8 @@
|
|
|
405
470
|
}}
|
|
406
471
|
onkeydown={onTriggerKeydown}
|
|
407
472
|
>
|
|
408
|
-
<span {...stylex.attrs(styles.triggerText)}>{selected?.label}</span>
|
|
473
|
+
<span {...stylex.attrs(styles.triggerText)}>{selected?.label ?? said}</span>
|
|
474
|
+
{#if chosen.length > 1}<span {...stylex.attrs(styles.more)}>+{chosen.length - 1}</span>{/if}
|
|
409
475
|
<span {...stylex.attrs(styles.selector)}><Glyph name="selector" size={14} /></span>
|
|
410
476
|
</button>
|
|
411
477
|
|
|
@@ -422,6 +488,7 @@
|
|
|
422
488
|
role="listbox"
|
|
423
489
|
tabindex="-1"
|
|
424
490
|
aria-label={label}
|
|
491
|
+
aria-multiselectable={multiple || undefined}
|
|
425
492
|
aria-activedescendant={activeModel ? optionId(activeModel) : undefined}
|
|
426
493
|
{...stylex.attrs(styles.list)}
|
|
427
494
|
onkeydown={onListKeydown}
|
|
@@ -436,7 +503,7 @@
|
|
|
436
503
|
<div id="{uid}-group-{g}" {...stylex.attrs(styles.groupLabel)}>{group.name}</div>
|
|
437
504
|
{/if}
|
|
438
505
|
{#each group.models as model (model.value)}
|
|
439
|
-
{@const isSelected = model
|
|
506
|
+
{@const isSelected = isChosen(model)}
|
|
440
507
|
<!-- The list handles the keyboard for every option; this click is for the pointer -->
|
|
441
508
|
<div
|
|
442
509
|
id={optionId(model)}
|
|
@@ -11,17 +11,34 @@ export type ComposerModel = {
|
|
|
11
11
|
badge?: string | undefined;
|
|
12
12
|
disabled?: boolean | undefined;
|
|
13
13
|
};
|
|
14
|
-
|
|
14
|
+
type PickerBase = Omit<HTMLButtonAttributes, 'children' | 'value' | 'onchange'> & {
|
|
15
15
|
models: ComposerModel[];
|
|
16
|
-
/** The chosen model's value. Bindable. Defaults to the first model. */
|
|
17
|
-
value?: string | undefined;
|
|
18
16
|
/** What is being chosen. Names the list, and is read before the model on the button. */
|
|
19
17
|
label?: string | undefined;
|
|
20
|
-
/**
|
|
21
|
-
|
|
18
|
+
/** Whether the list is showing. Bindable. */
|
|
19
|
+
open?: boolean | undefined;
|
|
20
|
+
/** Called when the list opens or closes. */
|
|
21
|
+
onopenchange?: ((open: boolean) => void) | undefined;
|
|
22
22
|
sx?: Sx | undefined;
|
|
23
23
|
ref?: HTMLButtonElement | null | undefined;
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
export type ComposerModelPickerProps = PickerBase & ({
|
|
26
|
+
/** Lets several models be chosen, such as to run one prompt on each. */
|
|
27
|
+
multiple?: false | undefined;
|
|
28
|
+
/** The chosen model's value. Bindable. Defaults to the first model. */
|
|
29
|
+
value?: string | undefined;
|
|
30
|
+
/** Called when the person picks a model. */
|
|
31
|
+
onchange?: ((value: string) => void) | undefined;
|
|
32
|
+
placeholder?: undefined;
|
|
33
|
+
} | {
|
|
34
|
+
multiple: true;
|
|
35
|
+
/** The chosen models' values, in the order of `models`. Bindable. */
|
|
36
|
+
value?: string[] | undefined;
|
|
37
|
+
/** Called with every chosen model's value when the person picks or drops one. */
|
|
38
|
+
onchange?: ((value: string[]) => void) | undefined;
|
|
39
|
+
/** What the button says while none is chosen. */
|
|
40
|
+
placeholder?: string | undefined;
|
|
41
|
+
});
|
|
42
|
+
declare const ComposerModelPicker: import("svelte").Component<ComposerModelPickerProps, {}, "value" | "ref" | "open">;
|
|
26
43
|
type ComposerModelPicker = ReturnType<typeof ComposerModelPicker>;
|
|
27
44
|
export default ComposerModelPicker;
|
|
@@ -21,6 +21,16 @@
|
|
|
21
21
|
/** The files attached so far. Bindable. */
|
|
22
22
|
files?: File[] | undefined;
|
|
23
23
|
status?: ComposerStatus | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Set while a message is on its way and cannot be stopped yet. Nothing more is sent
|
|
26
|
+
* meanwhile, and Composer.Submit shows a spinner in place of its arrow.
|
|
27
|
+
*/
|
|
28
|
+
sending?: boolean | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Whether there is something to send. Narvi works it out from `value` and `files`; set
|
|
31
|
+
* it when the text is kept by an editor of your own, put where Composer.Textarea would go.
|
|
32
|
+
*/
|
|
33
|
+
hasContent?: boolean | undefined;
|
|
24
34
|
disabled?: boolean | undefined;
|
|
25
35
|
/** File types to take, as in an input's `accept`, such as `image/*,.pdf`. */
|
|
26
36
|
accept?: string | undefined;
|
|
@@ -43,6 +53,12 @@
|
|
|
43
53
|
* queued with a QueuedMessage; the composer is cleared unless this returns `false`.
|
|
44
54
|
*/
|
|
45
55
|
onqueue?: ((message: ComposerMessage, event: SubmitEvent) => unknown) | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Called with the files the person attaches, by picking, dropping or pasting, once the
|
|
58
|
+
* ones the composer does not accept are turned away. They join `files` unless this
|
|
59
|
+
* returns `false`: return it to keep them on a list of your own.
|
|
60
|
+
*/
|
|
61
|
+
onfiles?: ((files: File[]) => unknown) | undefined;
|
|
46
62
|
/** Called with the files that were turned away, and why. */
|
|
47
63
|
onreject?: ((rejections: ComposerRejection[]) => void) | undefined;
|
|
48
64
|
sx?: Sx | undefined;
|
|
@@ -51,6 +67,18 @@
|
|
|
51
67
|
children?: Snippet | undefined;
|
|
52
68
|
};
|
|
53
69
|
|
|
70
|
+
const EDITABLE = '[contenteditable]:not([contenteditable="false"])';
|
|
71
|
+
const FIELD_FOCUS = `:has(textarea:focus-visible, ${EDITABLE}:focus-visible, [data-composer-field]:focus-within)`;
|
|
72
|
+
|
|
73
|
+
/** The text field: the composer's textarea, or an editor of the app's own put in its place. */
|
|
74
|
+
function findField(form: HTMLFormElement | null): HTMLElement | null {
|
|
75
|
+
if (!form) return null;
|
|
76
|
+
const marked = form.querySelector<HTMLElement>('[data-composer-field]');
|
|
77
|
+
if (marked && !marked.matches(EDITABLE) && marked.tabIndex < 0)
|
|
78
|
+
return marked.querySelector<HTMLElement>(`textarea, ${EDITABLE}`) ?? marked;
|
|
79
|
+
return marked ?? form.querySelector<HTMLElement>(EDITABLE);
|
|
80
|
+
}
|
|
81
|
+
|
|
54
82
|
const styles = stylex.create({
|
|
55
83
|
root: {
|
|
56
84
|
position: 'relative',
|
|
@@ -69,10 +97,11 @@
|
|
|
69
97
|
fontFamily: font.body,
|
|
70
98
|
cursor: 'text',
|
|
71
99
|
// Focus in the text field is shown as on every text field: the ring and its halo.
|
|
72
|
-
// Not for the buttons inside, which show their own.
|
|
100
|
+
// Not for the buttons inside, which show their own. An editor of your own shows it too,
|
|
101
|
+
// when it is editable content or is marked `data-composer-field`.
|
|
73
102
|
boxShadow: {
|
|
74
103
|
default: `inset 0 0 0 1px ${colors.border}`,
|
|
75
|
-
|
|
104
|
+
[FIELD_FOCUS]: `inset 0 0 0 1px ${colors.focusRing}, 0 0 0 3px ${colors.focusHalo}`
|
|
76
105
|
},
|
|
77
106
|
// In forced colours the shadow is gone; the outline is the edge, and thickens with focus
|
|
78
107
|
outlineWidth: {
|
|
@@ -118,6 +147,8 @@
|
|
|
118
147
|
value = $bindable(''),
|
|
119
148
|
files = $bindable([]),
|
|
120
149
|
status = 'ready',
|
|
150
|
+
sending = false,
|
|
151
|
+
hasContent,
|
|
121
152
|
disabled = false,
|
|
122
153
|
accept,
|
|
123
154
|
maxFiles,
|
|
@@ -126,6 +157,7 @@
|
|
|
126
157
|
onsubmit,
|
|
127
158
|
onstop,
|
|
128
159
|
onqueue,
|
|
160
|
+
onfiles,
|
|
129
161
|
onreject,
|
|
130
162
|
sx,
|
|
131
163
|
class: className,
|
|
@@ -144,6 +176,11 @@
|
|
|
144
176
|
|
|
145
177
|
const busy = $derived(status === 'submitted' || status === 'streaming');
|
|
146
178
|
const attachable = $derived(attachments > 0 && !disabled);
|
|
179
|
+
const filled = $derived(hasContent ?? (value.trim().length > 0 || files.length > 0));
|
|
180
|
+
|
|
181
|
+
function focusField() {
|
|
182
|
+
(textarea ?? findField(ref))?.focus();
|
|
183
|
+
}
|
|
147
184
|
|
|
148
185
|
function addFiles(incoming: Iterable<File>) {
|
|
149
186
|
const taken: File[] = [];
|
|
@@ -157,7 +194,7 @@
|
|
|
157
194
|
else taken.push(file);
|
|
158
195
|
}
|
|
159
196
|
if (taken.length) {
|
|
160
|
-
files = [...files, ...taken];
|
|
197
|
+
if (onfiles?.(taken) !== false) files = [...files, ...taken];
|
|
161
198
|
announcement =
|
|
162
199
|
taken.length === 1 ? `Attached ${taken[0].name}` : `Attached ${taken.length} files`;
|
|
163
200
|
}
|
|
@@ -166,9 +203,9 @@
|
|
|
166
203
|
|
|
167
204
|
function handleSubmit(event: SubmitEvent) {
|
|
168
205
|
event.preventDefault();
|
|
169
|
-
if (disabled) return;
|
|
206
|
+
if (disabled || sending) return;
|
|
170
207
|
const text = value.trim();
|
|
171
|
-
const empty = !
|
|
208
|
+
const empty = !filled;
|
|
172
209
|
if (busy) {
|
|
173
210
|
// The Stop button stops; Enter in the text, with something written, queues
|
|
174
211
|
const stopping = !!(event.submitter as HTMLElement | null)?.closest(
|
|
@@ -212,9 +249,11 @@
|
|
|
212
249
|
get busy() {
|
|
213
250
|
return busy;
|
|
214
251
|
},
|
|
252
|
+
get sending() {
|
|
253
|
+
return sending;
|
|
254
|
+
},
|
|
215
255
|
get canSend() {
|
|
216
|
-
|
|
217
|
-
return !disabled && something && (!busy || !!onqueue);
|
|
256
|
+
return !disabled && !sending && filled && (!busy || !!onqueue);
|
|
218
257
|
},
|
|
219
258
|
get attachable() {
|
|
220
259
|
return attachable;
|
|
@@ -230,7 +269,7 @@
|
|
|
230
269
|
picker?.click();
|
|
231
270
|
},
|
|
232
271
|
focus() {
|
|
233
|
-
|
|
272
|
+
focusField();
|
|
234
273
|
},
|
|
235
274
|
announce(message) {
|
|
236
275
|
announcement = message;
|
|
@@ -250,6 +289,7 @@
|
|
|
250
289
|
bind:this={ref}
|
|
251
290
|
data-slot="composer"
|
|
252
291
|
data-status={status}
|
|
292
|
+
data-sending={sending || undefined}
|
|
253
293
|
data-disabled={disabled || undefined}
|
|
254
294
|
data-dragging={depth > 0 || undefined}
|
|
255
295
|
{...rest}
|
|
@@ -259,8 +299,7 @@
|
|
|
259
299
|
onclick?.(event);
|
|
260
300
|
// A click on the frame, not on a control inside it, goes to the text
|
|
261
301
|
const target = event.target as HTMLElement;
|
|
262
|
-
if (target === event.currentTarget || target.dataset.slot === 'composer-toolbar')
|
|
263
|
-
textarea?.focus();
|
|
302
|
+
if (target === event.currentTarget || target.dataset.slot === 'composer-toolbar') focusField();
|
|
264
303
|
}}
|
|
265
304
|
ondragenter={(event) => {
|
|
266
305
|
if (!attachable || !carriesFiles(event)) return;
|
|
@@ -280,7 +319,7 @@
|
|
|
280
319
|
event.preventDefault();
|
|
281
320
|
depth = 0;
|
|
282
321
|
addFiles(event.dataTransfer?.files ?? []);
|
|
283
|
-
|
|
322
|
+
focusField();
|
|
284
323
|
}}
|
|
285
324
|
>
|
|
286
325
|
{@render children?.()}
|
|
@@ -298,7 +337,7 @@
|
|
|
298
337
|
const input = event.currentTarget;
|
|
299
338
|
addFiles(input.files ?? []);
|
|
300
339
|
input.value = '';
|
|
301
|
-
|
|
340
|
+
focusField();
|
|
302
341
|
}}
|
|
303
342
|
/>
|
|
304
343
|
|
|
@@ -8,6 +8,16 @@ export type ComposerRootProps = Omit<HTMLFormAttributes, 'children' | 'onsubmit'
|
|
|
8
8
|
/** The files attached so far. Bindable. */
|
|
9
9
|
files?: File[] | undefined;
|
|
10
10
|
status?: ComposerStatus | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Set while a message is on its way and cannot be stopped yet. Nothing more is sent
|
|
13
|
+
* meanwhile, and Composer.Submit shows a spinner in place of its arrow.
|
|
14
|
+
*/
|
|
15
|
+
sending?: boolean | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Whether there is something to send. Narvi works it out from `value` and `files`; set
|
|
18
|
+
* it when the text is kept by an editor of your own, put where Composer.Textarea would go.
|
|
19
|
+
*/
|
|
20
|
+
hasContent?: boolean | undefined;
|
|
11
21
|
disabled?: boolean | undefined;
|
|
12
22
|
/** File types to take, as in an input's `accept`, such as `image/*,.pdf`. */
|
|
13
23
|
accept?: string | undefined;
|
|
@@ -30,6 +40,12 @@ export type ComposerRootProps = Omit<HTMLFormAttributes, 'children' | 'onsubmit'
|
|
|
30
40
|
* queued with a QueuedMessage; the composer is cleared unless this returns `false`.
|
|
31
41
|
*/
|
|
32
42
|
onqueue?: ((message: ComposerMessage, event: SubmitEvent) => unknown) | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Called with the files the person attaches, by picking, dropping or pasting, once the
|
|
45
|
+
* ones the composer does not accept are turned away. They join `files` unless this
|
|
46
|
+
* returns `false`: return it to keep them on a list of your own.
|
|
47
|
+
*/
|
|
48
|
+
onfiles?: ((files: File[]) => unknown) | undefined;
|
|
33
49
|
/** Called with the files that were turned away, and why. */
|
|
34
50
|
onreject?: ((rejections: ComposerRejection[]) => void) | undefined;
|
|
35
51
|
sx?: Sx | undefined;
|
|
@@ -11,12 +11,22 @@
|
|
|
11
11
|
|
|
12
12
|
export type ComposerSubmitProps = Omit<
|
|
13
13
|
ButtonProps,
|
|
14
|
-
|
|
14
|
+
| 'children'
|
|
15
|
+
| 'type'
|
|
16
|
+
| 'variant'
|
|
17
|
+
| 'iconOnly'
|
|
18
|
+
| 'href'
|
|
19
|
+
| 'ref'
|
|
20
|
+
| 'sx'
|
|
21
|
+
| 'loading'
|
|
22
|
+
| 'loadingLabel'
|
|
15
23
|
> & {
|
|
16
24
|
/** Accessible name while it sends. */
|
|
17
25
|
sendLabel?: string | undefined;
|
|
18
26
|
/** Accessible name while a reply is on its way and pressing it stops the reply. */
|
|
19
27
|
stopLabel?: string | undefined;
|
|
28
|
+
/** Accessible name while the composer is `sending`: the message is on its way and cannot be stopped. */
|
|
29
|
+
sendingLabel?: string | undefined;
|
|
20
30
|
sx?: Sx | undefined;
|
|
21
31
|
ref?: HTMLButtonElement | null | undefined;
|
|
22
32
|
};
|
|
@@ -69,6 +79,7 @@
|
|
|
69
79
|
let {
|
|
70
80
|
sendLabel = 'Send',
|
|
71
81
|
stopLabel = 'Stop',
|
|
82
|
+
sendingLabel = 'Sending',
|
|
72
83
|
disabled,
|
|
73
84
|
sx,
|
|
74
85
|
ref = $bindable(null),
|
|
@@ -76,8 +87,9 @@
|
|
|
76
87
|
}: ComposerSubmitProps = $props();
|
|
77
88
|
|
|
78
89
|
const composer = useComposer('Submit');
|
|
79
|
-
const
|
|
80
|
-
const
|
|
90
|
+
const sending = $derived(composer.sending);
|
|
91
|
+
const busy = $derived(composer.busy && !sending);
|
|
92
|
+
const idle = $derived(!busy && !sending && !composer.canSend);
|
|
81
93
|
</script>
|
|
82
94
|
|
|
83
95
|
<Button
|
|
@@ -85,10 +97,12 @@
|
|
|
85
97
|
type="submit"
|
|
86
98
|
variant="primary"
|
|
87
99
|
iconOnly
|
|
88
|
-
aria-label={busy ? stopLabel : sendLabel}
|
|
89
|
-
disabled={disabled ?? (composer.disabled || (!busy && !composer.canSend))}
|
|
100
|
+
aria-label={sending ? sendingLabel : busy ? stopLabel : sendLabel}
|
|
101
|
+
disabled={disabled ?? (composer.disabled || (!busy && !sending && !composer.canSend))}
|
|
102
|
+
loading={sending}
|
|
90
103
|
data-slot="composer-submit"
|
|
91
104
|
data-status={composer.status}
|
|
105
|
+
data-sending={sending || undefined}
|
|
92
106
|
{...rest}
|
|
93
107
|
sx={[styles.button, idle && styles.idle, sx]}
|
|
94
108
|
>
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { Sx } from '../../internal/sx.js';
|
|
2
2
|
import { type ButtonProps } from '../button/Button.svelte';
|
|
3
|
-
export type ComposerSubmitProps = Omit<ButtonProps, 'children' | 'type' | 'variant' | 'iconOnly' | 'href' | 'ref' | 'sx'> & {
|
|
3
|
+
export type ComposerSubmitProps = Omit<ButtonProps, 'children' | 'type' | 'variant' | 'iconOnly' | 'href' | 'ref' | 'sx' | 'loading' | 'loadingLabel'> & {
|
|
4
4
|
/** Accessible name while it sends. */
|
|
5
5
|
sendLabel?: string | undefined;
|
|
6
6
|
/** Accessible name while a reply is on its way and pressing it stops the reply. */
|
|
7
7
|
stopLabel?: string | undefined;
|
|
8
|
+
/** Accessible name while the composer is `sending`: the message is on its way and cannot be stopped. */
|
|
9
|
+
sendingLabel?: string | undefined;
|
|
8
10
|
sx?: Sx | undefined;
|
|
9
11
|
ref?: HTMLButtonElement | null | undefined;
|
|
10
12
|
};
|