@diegopluna/narvi 0.3.4 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/app-shell/AppShellPanel.svelte +35 -4
- package/dist/components/badge/Badge.svelte +13 -1
- package/dist/components/badge/Badge.svelte.d.ts +6 -0
- package/dist/components/button/Button.svelte +60 -32
- package/dist/components/button/Button.svelte.d.ts +6 -0
- package/dist/components/command/CommandDialog.svelte +24 -2
- package/dist/components/command/CommandDialog.svelte.d.ts +12 -0
- package/dist/components/command/CommandItem.svelte +15 -4
- package/dist/components/command/CommandItem.svelte.d.ts +20 -4
- package/dist/components/command/CommandRoot.svelte +57 -2
- package/dist/components/command/CommandRoot.svelte.d.ts +25 -1
- package/dist/components/composer/ComposerModelPicker.svelte +608 -53
- package/dist/components/composer/ComposerModelPicker.svelte.d.ts +56 -1
- package/dist/components/composer/ComposerRoot.svelte.d.ts +1 -1
- package/dist/components/composer/ComposerSubmit.svelte +12 -2
- package/dist/components/composer/ComposerSubmit.svelte.d.ts +6 -0
- package/dist/components/composer/index.d.ts +1 -1
- package/dist/components/input/Input.svelte.d.ts +1 -1
- package/dist/components/menu/MenuCheckboxItem.svelte +14 -5
- package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +15 -4
- package/dist/components/menu/MenuItem.svelte +9 -3
- package/dist/components/menu/MenuItem.svelte.d.ts +11 -4
- package/dist/components/menu/MenuRadioItem.svelte +18 -9
- package/dist/components/menu/MenuRadioItem.svelte.d.ts +15 -4
- package/dist/components/menu/MenuSubTrigger.svelte +9 -3
- package/dist/components/menu/MenuSubTrigger.svelte.d.ts +11 -4
- package/dist/components/questionnaire/Questionnaire.svelte +100 -9
- package/dist/components/questionnaire/Questionnaire.svelte.d.ts +11 -0
- package/dist/components/select/Select.svelte +11 -1
- package/dist/components/select/Select.svelte.d.ts +5 -0
- package/dist/components/slider/Slider.svelte.d.ts +2 -2
- package/dist/components/split-button/SplitButton.svelte +11 -1
- package/dist/components/split-button/SplitButton.svelte.d.ts +7 -0
- package/dist/components/tab-strip/TabStrip.svelte +77 -20
- package/dist/components/tab-strip/TabStrip.svelte.d.ts +16 -3
- package/dist/components/textarea/Textarea.svelte.d.ts +1 -1
- package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/internal/ItemDescription.svelte +34 -0
- package/dist/internal/ItemDescription.svelte.d.ts +10 -0
- package/dist/internal/roving.d.ts +3 -1
- package/dist/internal/roving.js +6 -3
- package/dist/media.stylex.d.ts +6 -0
- package/dist/media.stylex.js +6 -0
- package/dist/vite.js +4 -0
- package/package.json +20 -1
- package/skills/building-ui/SKILL.md +30 -22
- package/skills/building-ui/references/components.md +22 -22
- package/skills/markdown/SKILL.md +1 -1
- package/skills/setup/SKILL.md +1 -1
- package/skills/styling/SKILL.md +11 -2
- package/skills/theming/SKILL.md +1 -1
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
The agent asks the person questions, one at a time. Keys 1 to 9 pick an
|
|
3
|
-
answer,
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
answer, the up and down arrows move between the answers and the field for
|
|
4
|
+
one's own, the left and right arrows go back and on, Enter goes on, and
|
|
5
|
+
⌘Enter sends them all once each is answered or skipped. Each question's
|
|
6
|
+
prompt takes focus as it arrives, so it is read out. Once answered, it folds
|
|
7
|
+
into what was said, a secret answer hidden.
|
|
6
8
|
-->
|
|
7
9
|
<script lang="ts" module>
|
|
8
10
|
import * as stylex from '@stylexjs/stylex';
|
|
9
|
-
import { tick } from 'svelte';
|
|
11
|
+
import { tick, type Snippet } from 'svelte';
|
|
10
12
|
import { shared } from '../../internal/shared.js';
|
|
11
13
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
12
14
|
import { colors, font, radius, space } from '../../tokens.stylex.js';
|
|
@@ -53,6 +55,16 @@
|
|
|
53
55
|
* pressed or changed.
|
|
54
56
|
*/
|
|
55
57
|
busy?: boolean | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* What the questions are about, at the start of the top row, with "Question 2 of 3" at
|
|
60
|
+
* its end: an icon and the agent's title for them, say.
|
|
61
|
+
*/
|
|
62
|
+
heading?: Snippet | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Leaves out the card's fill, edge and padding, for questions put in a card of your own,
|
|
65
|
+
* such as the one an agent's turn shows what waits on the person in.
|
|
66
|
+
*/
|
|
67
|
+
bare?: boolean | undefined;
|
|
56
68
|
labels?:
|
|
57
69
|
| Partial<
|
|
58
70
|
Record<
|
|
@@ -95,7 +107,27 @@
|
|
|
95
107
|
backgroundColor: colors.bgRaised,
|
|
96
108
|
boxShadow: `inset 0 0 0 1px color-mix(in oklab, ${colors.accent} 35%, transparent)`
|
|
97
109
|
},
|
|
110
|
+
// No card of its own: what holds it draws one
|
|
111
|
+
bare: { padding: 0, borderRadius: 0, backgroundColor: 'transparent', boxShadow: 'none' },
|
|
98
112
|
head: { display: 'flex', flexDirection: 'column', gap: '0.5rem' },
|
|
113
|
+
// The heading at the start, the count at the end, on one line while they fit
|
|
114
|
+
headRow: {
|
|
115
|
+
display: 'flex',
|
|
116
|
+
flexWrap: 'wrap',
|
|
117
|
+
alignItems: 'center',
|
|
118
|
+
justifyContent: 'space-between',
|
|
119
|
+
columnGap: space.x3,
|
|
120
|
+
rowGap: '0.25rem',
|
|
121
|
+
minWidth: 0
|
|
122
|
+
},
|
|
123
|
+
heading: {
|
|
124
|
+
'--narvi-icon-size': '1rem',
|
|
125
|
+
display: 'flex',
|
|
126
|
+
alignItems: 'center',
|
|
127
|
+
gap: '0.5rem',
|
|
128
|
+
minWidth: 0,
|
|
129
|
+
fontWeight: font.weightMedium
|
|
130
|
+
},
|
|
99
131
|
count: { color: colors.accent },
|
|
100
132
|
prompt: {
|
|
101
133
|
margin: 0,
|
|
@@ -183,6 +215,8 @@
|
|
|
183
215
|
ondecline,
|
|
184
216
|
answered,
|
|
185
217
|
busy = false,
|
|
218
|
+
heading,
|
|
219
|
+
bare = false,
|
|
186
220
|
labels,
|
|
187
221
|
sx,
|
|
188
222
|
class: className
|
|
@@ -194,6 +228,7 @@
|
|
|
194
228
|
let answers = $state<QuestionnaireAnswers>({});
|
|
195
229
|
let error = $state('');
|
|
196
230
|
let prompt = $state<HTMLElement | null>(null);
|
|
231
|
+
let card = $state<HTMLElement | null>(null);
|
|
197
232
|
|
|
198
233
|
const question = $derived(questions[index]);
|
|
199
234
|
const answer = $derived(answers[question?.id] ?? { choices: [] });
|
|
@@ -252,8 +287,22 @@
|
|
|
252
287
|
error = word.unanswered;
|
|
253
288
|
}
|
|
254
289
|
|
|
290
|
+
// The up and down arrows go through the answers as they are shown: each choice, then the
|
|
291
|
+
// field for one's own. On a radio, arriving picks it, as a radio group's own arrows do.
|
|
292
|
+
function moveAnswer(from: HTMLElement, step: number) {
|
|
293
|
+
const all = [...(card?.querySelectorAll<HTMLElement>('[data-answer]') ?? [])];
|
|
294
|
+
const at = all.indexOf(from);
|
|
295
|
+
if (at === -1 || all.length < 2) return false;
|
|
296
|
+
const to = all[(at + step + all.length) % all.length];
|
|
297
|
+
to.focus();
|
|
298
|
+
if (to instanceof HTMLInputElement && to.type === 'radio' && to.dataset.answer) {
|
|
299
|
+
pick(to.dataset.answer);
|
|
300
|
+
}
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
|
|
255
304
|
function onkeydown(event: KeyboardEvent) {
|
|
256
|
-
if (event.isComposing) return;
|
|
305
|
+
if (event.isComposing || event.defaultPrevented) return;
|
|
257
306
|
if (busy) {
|
|
258
307
|
if (event.key === 'Enter') event.preventDefault();
|
|
259
308
|
return;
|
|
@@ -263,6 +312,33 @@
|
|
|
263
312
|
const field =
|
|
264
313
|
target instanceof HTMLInputElement && target.type !== 'radio' && target.type !== 'checkbox';
|
|
265
314
|
const typing = target instanceof HTMLTextAreaElement || field;
|
|
315
|
+
const radio = target instanceof HTMLInputElement && target.type === 'radio';
|
|
316
|
+
const plain = !event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey;
|
|
317
|
+
if (
|
|
318
|
+
plain &&
|
|
319
|
+
(event.key === 'ArrowDown' || event.key === 'ArrowUp') &&
|
|
320
|
+
target instanceof HTMLElement &&
|
|
321
|
+
target.hasAttribute('data-answer') &&
|
|
322
|
+
// In a field with words in it, the arrows move through the words
|
|
323
|
+
!(typing && (target as HTMLInputElement | HTMLTextAreaElement).value)
|
|
324
|
+
) {
|
|
325
|
+
if (moveAnswer(target, event.key === 'ArrowDown' ? 1 : -1)) event.preventDefault();
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
// Left and right go back and on, except where they move through words or a radio group.
|
|
329
|
+
// On goes only past a question answered or skipped; right to left, the two trade places.
|
|
330
|
+
if (plain && !typing && !radio && (event.key === 'ArrowLeft' || event.key === 'ArrowRight')) {
|
|
331
|
+
const rtl = !!card && getComputedStyle(card).direction === 'rtl';
|
|
332
|
+
const back = (event.key === 'ArrowLeft') !== rtl;
|
|
333
|
+
if (back && index > 0) {
|
|
334
|
+
event.preventDefault();
|
|
335
|
+
go(index - 1);
|
|
336
|
+
} else if (!back && !last && given(answers[question.id])) {
|
|
337
|
+
event.preventDefault();
|
|
338
|
+
go(index + 1);
|
|
339
|
+
}
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
266
342
|
if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {
|
|
267
343
|
event.preventDefault();
|
|
268
344
|
sendAll();
|
|
@@ -307,13 +383,25 @@
|
|
|
307
383
|
aria-labelledby="{uid}-prompt"
|
|
308
384
|
data-slot="questionnaire"
|
|
309
385
|
aria-busy={busy || undefined}
|
|
310
|
-
{
|
|
386
|
+
bind:this={card}
|
|
387
|
+
{...attrs([styles.card, bare && styles.bare, sx], className)}
|
|
311
388
|
{onkeydown}
|
|
312
389
|
>
|
|
313
390
|
<div {...stylex.attrs(styles.head)}>
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
391
|
+
{#if heading}
|
|
392
|
+
<div {...stylex.attrs(styles.headRow)}>
|
|
393
|
+
<div data-icons {...stylex.attrs(styles.heading)}>{@render heading()}</div>
|
|
394
|
+
{#if questions.length > 1}
|
|
395
|
+
<span {...stylex.attrs(shared.eyebrow, styles.count)}
|
|
396
|
+
>Question {index + 1} of {questions.length}</span
|
|
397
|
+
>
|
|
398
|
+
{/if}
|
|
399
|
+
</div>
|
|
400
|
+
{:else}
|
|
401
|
+
<span {...stylex.attrs(shared.eyebrow, styles.count)}
|
|
402
|
+
>Question {index + 1} of {questions.length}</span
|
|
403
|
+
>
|
|
404
|
+
{/if}
|
|
317
405
|
{#if questions.length > 1}
|
|
318
406
|
<Progress
|
|
319
407
|
value={index + 1}
|
|
@@ -342,6 +430,7 @@
|
|
|
342
430
|
type={question.multiple ? 'checkbox' : 'radio'}
|
|
343
431
|
name="{uid}-{question.id}"
|
|
344
432
|
checked={answer.choices.includes(choice.label)}
|
|
433
|
+
data-answer={choice.label}
|
|
345
434
|
onchange={() => pick(choice.label)}
|
|
346
435
|
{...stylex.attrs(styles.input, question.multiple && styles.box)}
|
|
347
436
|
/>
|
|
@@ -367,6 +456,7 @@
|
|
|
367
456
|
aria-label={typeof question.other === 'string' ? question.other : 'Your answer'}
|
|
368
457
|
aria-describedby={question.description ? `${uid}-about` : undefined}
|
|
369
458
|
placeholder={typeof question.other === 'string' ? question.other : 'Your answer'}
|
|
459
|
+
data-answer=""
|
|
370
460
|
value={answer.other ?? ''}
|
|
371
461
|
oninput={(event) => set({ ...answer, skipped: false, other: event.currentTarget.value })}
|
|
372
462
|
/>
|
|
@@ -378,6 +468,7 @@
|
|
|
378
468
|
rows={2}
|
|
379
469
|
aria-label={typeof question.other === 'string' ? question.other : 'Your answer'}
|
|
380
470
|
placeholder={typeof question.other === 'string' ? question.other : 'Your answer'}
|
|
471
|
+
data-answer=""
|
|
381
472
|
value={answer.other ?? ''}
|
|
382
473
|
oninput={(event) => set({ ...answer, skipped: false, other: event.currentTarget.value })}
|
|
383
474
|
/>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
1
2
|
import { type Sx } from '../../internal/sx.js';
|
|
2
3
|
export type Question = {
|
|
3
4
|
id: string;
|
|
@@ -36,6 +37,16 @@ export type QuestionnaireProps = {
|
|
|
36
37
|
* pressed or changed.
|
|
37
38
|
*/
|
|
38
39
|
busy?: boolean | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* What the questions are about, at the start of the top row, with "Question 2 of 3" at
|
|
42
|
+
* its end: an icon and the agent's title for them, say.
|
|
43
|
+
*/
|
|
44
|
+
heading?: Snippet | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Leaves out the card's fill, edge and padding, for questions put in a card of your own,
|
|
47
|
+
* such as the one an agent's turn shows what waits on the person in.
|
|
48
|
+
*/
|
|
49
|
+
bare?: boolean | undefined;
|
|
39
50
|
labels?: Partial<Record<'next' | 'back' | 'skip' | 'send' | 'decline' | 'required' | 'unanswered' | 'skipped' | 'hidden', string>> | undefined;
|
|
40
51
|
sx?: Sx | undefined;
|
|
41
52
|
class?: string | undefined;
|
|
@@ -40,6 +40,11 @@
|
|
|
40
40
|
value?: string | undefined;
|
|
41
41
|
/** Shown while nothing is chosen. */
|
|
42
42
|
placeholder?: string | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Words on the trigger before the chosen option, muted, that say what it sets: "Text size"
|
|
45
|
+
* before "Default". They are part of its name, so it needs no `aria-label`.
|
|
46
|
+
*/
|
|
47
|
+
prefix?: string | undefined;
|
|
43
48
|
/**
|
|
44
49
|
* Draws each option's icon, in the list and on the trigger, in place of `option.icon`:
|
|
45
50
|
* for an icon that takes props, such as a provider's mark in its colours, or a dot.
|
|
@@ -77,6 +82,7 @@
|
|
|
77
82
|
whiteSpace: 'nowrap'
|
|
78
83
|
},
|
|
79
84
|
placeholder: { color: colors.textSubtle },
|
|
85
|
+
prefix: { flexShrink: 0, color: colors.textMuted },
|
|
80
86
|
// The chosen option's icon, on the trigger
|
|
81
87
|
icon: {
|
|
82
88
|
'--narvi-icon-size': '1rem',
|
|
@@ -113,6 +119,7 @@
|
|
|
113
119
|
options,
|
|
114
120
|
value = $bindable(),
|
|
115
121
|
placeholder = 'Choose…',
|
|
122
|
+
prefix,
|
|
116
123
|
optionIcon,
|
|
117
124
|
size = 'md',
|
|
118
125
|
align = 'start',
|
|
@@ -142,7 +149,7 @@
|
|
|
142
149
|
>
|
|
143
150
|
<Select.Trigger
|
|
144
151
|
id={id ?? field?.id}
|
|
145
|
-
aria-label={label}
|
|
152
|
+
aria-label={label ?? (prefix ? `${prefix} ${selected?.label ?? placeholder}` : undefined)}
|
|
146
153
|
aria-describedby={describedBy ?? field?.describedBy}
|
|
147
154
|
data-slot="select"
|
|
148
155
|
{...attrs([control.base, control[size], styles.trigger, sx], className)}
|
|
@@ -154,6 +161,7 @@
|
|
|
154
161
|
{:else if selected?.icon}
|
|
155
162
|
<span data-icons {...stylex.attrs(styles.icon)}><selected.icon aria-hidden="true" /></span>
|
|
156
163
|
{/if}
|
|
164
|
+
{#if prefix}<span {...stylex.attrs(styles.prefix)}>{prefix}</span>{/if}
|
|
157
165
|
<span {...stylex.attrs(styles.value, !selected && styles.placeholder)}>
|
|
158
166
|
{selected?.label ?? placeholder}
|
|
159
167
|
</span>
|
|
@@ -163,6 +171,8 @@
|
|
|
163
171
|
<Select.Content {align} sideOffset={6} collisionPadding={8} {...stylex.attrs(layer.surface)}>
|
|
164
172
|
<Select.Viewport>
|
|
165
173
|
{#each groups as group, index (index)}
|
|
174
|
+
<!-- A hairline between groups, as a menu draws between its parts -->
|
|
175
|
+
{#if index > 0}<div aria-hidden="true" {...stylex.attrs(layer.separator)}></div>{/if}
|
|
166
176
|
<Select.Group>
|
|
167
177
|
{#if group.name}
|
|
168
178
|
<Select.GroupHeading {...stylex.attrs(layer.heading)}
|
|
@@ -28,6 +28,11 @@ export type SelectProps = {
|
|
|
28
28
|
value?: string | undefined;
|
|
29
29
|
/** Shown while nothing is chosen. */
|
|
30
30
|
placeholder?: string | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Words on the trigger before the chosen option, muted, that say what it sets: "Text size"
|
|
33
|
+
* before "Default". They are part of its name, so it needs no `aria-label`.
|
|
34
|
+
*/
|
|
35
|
+
prefix?: string | undefined;
|
|
31
36
|
/**
|
|
32
37
|
* Draws each option's icon, in the list and on the trigger, in place of `option.icon`:
|
|
33
38
|
* for an icon that takes props, such as a provider's mark in its colours, or a dot.
|
|
@@ -32,7 +32,7 @@ export type SliderProps<T extends number | number[] = number> = Omit<HTMLAttribu
|
|
|
32
32
|
declare function $$render<T extends number | number[] = number>(): {
|
|
33
33
|
props: SliderProps<T>;
|
|
34
34
|
exports: {};
|
|
35
|
-
bindings: "
|
|
35
|
+
bindings: "ref" | "value";
|
|
36
36
|
slots: {};
|
|
37
37
|
events: {};
|
|
38
38
|
};
|
|
@@ -40,7 +40,7 @@ declare class __sveltets_Render<T extends number | number[] = number> {
|
|
|
40
40
|
props(): ReturnType<typeof $$render<T>>['props'];
|
|
41
41
|
events(): ReturnType<typeof $$render<T>>['events'];
|
|
42
42
|
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
43
|
-
bindings(): "
|
|
43
|
+
bindings(): "ref" | "value";
|
|
44
44
|
exports(): {};
|
|
45
45
|
}
|
|
46
46
|
interface $$IsomorphicComponent {
|
|
@@ -33,6 +33,13 @@
|
|
|
33
33
|
menuWidth?: string | undefined;
|
|
34
34
|
/** Whether the menu is open. Bindable. */
|
|
35
35
|
open?: boolean | undefined;
|
|
36
|
+
/** Called as the menu opens or closes: to fetch what it lists as it opens, say. */
|
|
37
|
+
onopenchange?: ((open: boolean) => void) | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* A tooltip on the button that opens the menu, as `tooltip` is on the main one: words, or a
|
|
40
|
+
* snippet with a shortcut.
|
|
41
|
+
*/
|
|
42
|
+
menuTooltip?: string | Snippet | undefined;
|
|
36
43
|
/** On the group, which holds both halves. */
|
|
37
44
|
sx?: Sx | undefined;
|
|
38
45
|
/** The main button's label, and its icon if it has one. */
|
|
@@ -79,6 +86,8 @@
|
|
|
79
86
|
align = 'end',
|
|
80
87
|
menuWidth,
|
|
81
88
|
open = $bindable(false),
|
|
89
|
+
onopenchange,
|
|
90
|
+
menuTooltip,
|
|
82
91
|
disabled = false,
|
|
83
92
|
loading = false,
|
|
84
93
|
sx,
|
|
@@ -109,7 +118,7 @@
|
|
|
109
118
|
{@render children?.()}
|
|
110
119
|
</Button>
|
|
111
120
|
{#if menu}
|
|
112
|
-
<Menu.Root bind:open>
|
|
121
|
+
<Menu.Root bind:open onOpenChange={onopenchange}>
|
|
113
122
|
<Menu.Trigger disabled={disabled || loading}>
|
|
114
123
|
{#snippet child({ props })}
|
|
115
124
|
<Button
|
|
@@ -118,6 +127,7 @@
|
|
|
118
127
|
{size}
|
|
119
128
|
disabled={disabled || loading}
|
|
120
129
|
aria-label={menuLabel}
|
|
130
|
+
tooltip={menuTooltip}
|
|
121
131
|
sx={[
|
|
122
132
|
styles.half,
|
|
123
133
|
styles.more,
|
|
@@ -19,6 +19,13 @@ export type SplitButtonProps = Omit<ButtonProps, 'variant' | 'iconOnly' | 'href'
|
|
|
19
19
|
menuWidth?: string | undefined;
|
|
20
20
|
/** Whether the menu is open. Bindable. */
|
|
21
21
|
open?: boolean | undefined;
|
|
22
|
+
/** Called as the menu opens or closes: to fetch what it lists as it opens, say. */
|
|
23
|
+
onopenchange?: ((open: boolean) => void) | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* A tooltip on the button that opens the menu, as `tooltip` is on the main one: words, or a
|
|
26
|
+
* snippet with a shortcut.
|
|
27
|
+
*/
|
|
28
|
+
menuTooltip?: string | Snippet | undefined;
|
|
22
29
|
/** On the group, which holds both halves. */
|
|
23
30
|
sx?: Sx | undefined;
|
|
24
31
|
/** The main button's label, and its icon if it has one. */
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
import { tabStripTabMarker } from '../../internal/markers.stylex.js';
|
|
23
23
|
import { roving } from '../../internal/roving.js';
|
|
24
24
|
import * as ContextMenu from '../menu/context-menu.js';
|
|
25
|
+
import * as Menu from '../menu/index.js';
|
|
25
26
|
import { TabDragging, tabOffset } from './drag.svelte.js';
|
|
26
27
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
27
28
|
import { colors, font, motion, radius } from '../../tokens.stylex.js';
|
|
@@ -42,18 +43,33 @@
|
|
|
42
43
|
renamable?: boolean | undefined;
|
|
43
44
|
};
|
|
44
45
|
|
|
45
|
-
export type TabStripProps = Omit<
|
|
46
|
+
export type TabStripProps = Omit<
|
|
47
|
+
HTMLAttributes<HTMLDivElement>,
|
|
48
|
+
'children' | 'onclose' | 'onchange'
|
|
49
|
+
> & {
|
|
46
50
|
tabs: TabStripTab[];
|
|
47
51
|
/** The id of the open tab. Bindable. */
|
|
48
52
|
value?: string | undefined;
|
|
53
|
+
/** Called as a tab is opened: clicked, or reached with the arrow keys. */
|
|
54
|
+
onchange?: ((id: string) => void) | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* `automatic` opens the tab the arrow keys reach, as a browser's tabs do; `manual` only moves
|
|
57
|
+
* the focus, and Enter or Space opens it, for tabs slow to show.
|
|
58
|
+
*/
|
|
59
|
+
activation?: 'automatic' | 'manual' | undefined;
|
|
49
60
|
/** Names the strip: "Open threads". */
|
|
50
61
|
label: string;
|
|
51
62
|
/** The id of the panel the tabs show. */
|
|
52
63
|
controls?: string | undefined;
|
|
53
64
|
/** Called to close a tab. Without it the tabs cannot be closed. */
|
|
54
65
|
onclose?: ((id: string) => void) | undefined;
|
|
55
|
-
/** Called to add one. Without it there is no button to add. */
|
|
66
|
+
/** Called to add one. Without it, or `addMenu`, there is no button to add. */
|
|
56
67
|
onadd?: (() => void) | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* What can be added, as Menu parts: the button to add opens them, in place of calling
|
|
70
|
+
* `onadd`. For a strip that opens several kinds of tab: a file, a page, a terminal.
|
|
71
|
+
*/
|
|
72
|
+
addMenu?: Snippet | undefined;
|
|
57
73
|
addLabel?: string | undefined;
|
|
58
74
|
/** The name of a tab's close button. */
|
|
59
75
|
closeLabel?: ((tab: TabStripTab) => string) | undefined;
|
|
@@ -77,7 +93,8 @@
|
|
|
77
93
|
onmove?: ((id: string, index: number) => void) | undefined;
|
|
78
94
|
/**
|
|
79
95
|
* Called with a tab's new name, as Enter is pressed. Without it the tabs cannot be
|
|
80
|
-
* renamed. Renaming starts on a double-click, on F2, or as `renaming` is set.
|
|
96
|
+
* renamed. Renaming starts on a double-click, on F2, or as `renaming` is set. A name
|
|
97
|
+
* cleared is passed as `''`, for the tab to take back a name of its own.
|
|
81
98
|
*/
|
|
82
99
|
onrename?: ((id: string, label: string) => void) | undefined;
|
|
83
100
|
/** The id of the tab being renamed. Bindable: set it from a menu's Rename. */
|
|
@@ -354,7 +371,10 @@
|
|
|
354
371
|
controls,
|
|
355
372
|
onclose,
|
|
356
373
|
onadd,
|
|
374
|
+
addMenu,
|
|
357
375
|
addLabel = 'New tab',
|
|
376
|
+
onchange,
|
|
377
|
+
activation = 'automatic',
|
|
358
378
|
closeLabel = (tab) => `Close ${tab.label}`,
|
|
359
379
|
leading,
|
|
360
380
|
trailing,
|
|
@@ -432,8 +452,9 @@
|
|
|
432
452
|
function endRename(tab: TabStripTab, name: string | null, refocus: boolean) {
|
|
433
453
|
if (renaming !== tab.id) return;
|
|
434
454
|
renaming = undefined;
|
|
455
|
+
// Cleared, the name goes as '': the app gives the tab back a name of its own
|
|
435
456
|
const next = name?.trim();
|
|
436
|
-
if (next) onrename?.(tab.id, next);
|
|
457
|
+
if (next !== undefined && next !== tab.label) onrename?.(tab.id, next);
|
|
437
458
|
if (refocus) tick().then(() => tabButton(tab.id)?.focus());
|
|
438
459
|
}
|
|
439
460
|
|
|
@@ -443,6 +464,24 @@
|
|
|
443
464
|
input.select();
|
|
444
465
|
};
|
|
445
466
|
|
|
467
|
+
function open(tab: TabStripTab) {
|
|
468
|
+
if (value === tab.id) return;
|
|
469
|
+
value = tab.id;
|
|
470
|
+
onchange?.(tab.id);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// The arrow keys, Home and End move the focus to a tab; with automatic activation, the tab
|
|
474
|
+
// they reach opens. A tab focused any other way, such as as its menu closes, stays as it is.
|
|
475
|
+
let arrowed = false;
|
|
476
|
+
function onListKeydownCapture(event: KeyboardEvent) {
|
|
477
|
+
if (event.altKey || event.metaKey || event.ctrlKey || event.shiftKey) return;
|
|
478
|
+
if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
|
|
479
|
+
if (!(event.target instanceof HTMLElement) || event.target.getAttribute('role') !== 'tab')
|
|
480
|
+
return;
|
|
481
|
+
arrowed = true;
|
|
482
|
+
setTimeout(() => (arrowed = false));
|
|
483
|
+
}
|
|
484
|
+
|
|
446
485
|
function moveByKey(tab: TabStripTab, event: KeyboardEvent) {
|
|
447
486
|
if (!onmove || !event.altKey || !event.shiftKey) return false;
|
|
448
487
|
if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') return false;
|
|
@@ -514,7 +553,10 @@
|
|
|
514
553
|
onclose && !leading && !trailing && styles.closable,
|
|
515
554
|
trailing && styles.buttonBeforeTrailing
|
|
516
555
|
)}
|
|
517
|
-
onclick={() => (
|
|
556
|
+
onclick={() => open(tab)}
|
|
557
|
+
onfocus={() => {
|
|
558
|
+
if (arrowed && activation === 'automatic') open(tab);
|
|
559
|
+
}}
|
|
518
560
|
ondblclick={() => startRename(tab)}
|
|
519
561
|
onauxclick={(event) => {
|
|
520
562
|
// The middle button closes, as it does in a browser
|
|
@@ -621,7 +663,8 @@
|
|
|
621
663
|
aria-label={label}
|
|
622
664
|
aria-orientation="horizontal"
|
|
623
665
|
{...stylex.attrs(styles.list)}
|
|
624
|
-
{@attach roving({ selector: '[role="tab"]', orientation: 'horizontal' })}
|
|
666
|
+
{@attach roving({ selector: '[role="tab"]', orientation: 'horizontal', wrap: true })}
|
|
667
|
+
onkeydowncapture={onListKeydownCapture}
|
|
625
668
|
>
|
|
626
669
|
{#each tabs as tab, index (tab.id)}
|
|
627
670
|
{#if menu}
|
|
@@ -645,21 +688,35 @@
|
|
|
645
688
|
{/if}
|
|
646
689
|
{/each}
|
|
647
690
|
</div>
|
|
648
|
-
{#
|
|
691
|
+
{#snippet plus()}
|
|
692
|
+
<svg
|
|
693
|
+
data-glyph=""
|
|
694
|
+
width="14"
|
|
695
|
+
height="14"
|
|
696
|
+
viewBox="0 0 16 16"
|
|
697
|
+
fill="none"
|
|
698
|
+
stroke="currentColor"
|
|
699
|
+
stroke-width="1.5"
|
|
700
|
+
stroke-linecap="round"
|
|
701
|
+
aria-hidden="true"
|
|
702
|
+
>
|
|
703
|
+
<path d="M8 3.5v9M3.5 8h9" />
|
|
704
|
+
</svg>
|
|
705
|
+
{/snippet}
|
|
706
|
+
{#if addMenu}
|
|
707
|
+
<Menu.Root>
|
|
708
|
+
<Menu.Trigger>
|
|
709
|
+
{#snippet child({ props })}
|
|
710
|
+
<button type="button" aria-label={addLabel} {...props} {...stylex.attrs(styles.add)}>
|
|
711
|
+
{@render plus()}
|
|
712
|
+
</button>
|
|
713
|
+
{/snippet}
|
|
714
|
+
</Menu.Trigger>
|
|
715
|
+
<Menu.Content align="end">{@render addMenu()}</Menu.Content>
|
|
716
|
+
</Menu.Root>
|
|
717
|
+
{:else if onadd}
|
|
649
718
|
<button type="button" aria-label={addLabel} {...stylex.attrs(styles.add)} onclick={onadd}>
|
|
650
|
-
|
|
651
|
-
data-glyph=""
|
|
652
|
-
width="14"
|
|
653
|
-
height="14"
|
|
654
|
-
viewBox="0 0 16 16"
|
|
655
|
-
fill="none"
|
|
656
|
-
stroke="currentColor"
|
|
657
|
-
stroke-width="1.5"
|
|
658
|
-
stroke-linecap="round"
|
|
659
|
-
aria-hidden="true"
|
|
660
|
-
>
|
|
661
|
-
<path d="M8 3.5v9M3.5 8h9" />
|
|
662
|
-
</svg>
|
|
719
|
+
{@render plus()}
|
|
663
720
|
</button>
|
|
664
721
|
{/if}
|
|
665
722
|
</div>
|
|
@@ -15,18 +15,30 @@ export type TabStripTab = {
|
|
|
15
15
|
/** With `onrename`, whether this tab can be renamed. Defaults to true. */
|
|
16
16
|
renamable?: boolean | undefined;
|
|
17
17
|
};
|
|
18
|
-
export type TabStripProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'onclose'> & {
|
|
18
|
+
export type TabStripProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'onclose' | 'onchange'> & {
|
|
19
19
|
tabs: TabStripTab[];
|
|
20
20
|
/** The id of the open tab. Bindable. */
|
|
21
21
|
value?: string | undefined;
|
|
22
|
+
/** Called as a tab is opened: clicked, or reached with the arrow keys. */
|
|
23
|
+
onchange?: ((id: string) => void) | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* `automatic` opens the tab the arrow keys reach, as a browser's tabs do; `manual` only moves
|
|
26
|
+
* the focus, and Enter or Space opens it, for tabs slow to show.
|
|
27
|
+
*/
|
|
28
|
+
activation?: 'automatic' | 'manual' | undefined;
|
|
22
29
|
/** Names the strip: "Open threads". */
|
|
23
30
|
label: string;
|
|
24
31
|
/** The id of the panel the tabs show. */
|
|
25
32
|
controls?: string | undefined;
|
|
26
33
|
/** Called to close a tab. Without it the tabs cannot be closed. */
|
|
27
34
|
onclose?: ((id: string) => void) | undefined;
|
|
28
|
-
/** Called to add one. Without it there is no button to add. */
|
|
35
|
+
/** Called to add one. Without it, or `addMenu`, there is no button to add. */
|
|
29
36
|
onadd?: (() => void) | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* What can be added, as Menu parts: the button to add opens them, in place of calling
|
|
39
|
+
* `onadd`. For a strip that opens several kinds of tab: a file, a page, a terminal.
|
|
40
|
+
*/
|
|
41
|
+
addMenu?: Snippet | undefined;
|
|
30
42
|
addLabel?: string | undefined;
|
|
31
43
|
/** The name of a tab's close button. */
|
|
32
44
|
closeLabel?: ((tab: TabStripTab) => string) | undefined;
|
|
@@ -50,7 +62,8 @@ export type TabStripProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'o
|
|
|
50
62
|
onmove?: ((id: string, index: number) => void) | undefined;
|
|
51
63
|
/**
|
|
52
64
|
* Called with a tab's new name, as Enter is pressed. Without it the tabs cannot be
|
|
53
|
-
* renamed. Renaming starts on a double-click, on F2, or as `renaming` is set.
|
|
65
|
+
* renamed. Renaming starts on a double-click, on F2, or as `renaming` is set. A name
|
|
66
|
+
* cleared is passed as `''`, for the tab to take back a name of its own.
|
|
54
67
|
*/
|
|
55
68
|
onrename?: ((id: string, label: string) => void) | undefined;
|
|
56
69
|
/** The id of the tab being renamed. Bindable: set it from a menu's Rename. */
|
|
@@ -8,6 +8,6 @@ export type TextareaProps = Omit<HTMLTextareaAttributes, 'children'> & {
|
|
|
8
8
|
sx?: Sx | undefined;
|
|
9
9
|
ref?: HTMLTextAreaElement | null | undefined;
|
|
10
10
|
};
|
|
11
|
-
declare const Textarea: import("svelte").Component<TextareaProps, {}, "
|
|
11
|
+
declare const Textarea: import("svelte").Component<TextareaProps, {}, "ref" | "value">;
|
|
12
12
|
type Textarea = ReturnType<typeof Textarea>;
|
|
13
13
|
export default Textarea;
|
|
@@ -31,6 +31,6 @@ export type ToggleGroupRootProps = Html & Base & ({
|
|
|
31
31
|
value?: string[] | undefined;
|
|
32
32
|
onValueChange?: ((value: string[]) => void) | undefined;
|
|
33
33
|
});
|
|
34
|
-
declare const ToggleGroupRoot: import("svelte").Component<ToggleGroupRootProps, {}, "
|
|
34
|
+
declare const ToggleGroupRoot: import("svelte").Component<ToggleGroupRootProps, {}, "ref" | "value">;
|
|
35
35
|
type ToggleGroupRoot = ReturnType<typeof ToggleGroupRoot>;
|
|
36
36
|
export default ToggleGroupRoot;
|
package/dist/index.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export * as Command from './components/command/index.js';
|
|
|
31
31
|
export type { CommandDialogProps, CommandEmptyProps, CommandFooterProps, CommandGroupProps, CommandInputProps, CommandItemProps, CommandListProps, CommandRootProps } from './components/command/index.js';
|
|
32
32
|
export * as Composer from './components/composer/index.js';
|
|
33
33
|
export { getComposerContext } from './components/composer/index.js';
|
|
34
|
-
export type { ComposerAttachButtonProps, ComposerAttachmentProps, ComposerAttachmentsProps, ComposerContext, ComposerMessage, ComposerModel, ComposerModelPickerProps, ComposerRejection, ComposerRootProps, ComposerStatus, ComposerSubmitProps, ComposerTextareaProps, ComposerToggleProps, ComposerToolbarProps, ComposerTrayProps } from './components/composer/index.js';
|
|
34
|
+
export type { ComposerAttachButtonProps, ComposerAttachmentProps, ComposerAttachmentsProps, ComposerContext, ComposerMessage, ComposerModel, ComposerModelPickerProps, ComposerModelProvider, ComposerRejection, ComposerRootProps, ComposerStatus, ComposerSubmitProps, ComposerTextareaProps, ComposerToggleProps, ComposerToolbarProps, ComposerTrayProps } from './components/composer/index.js';
|
|
35
35
|
export * as ContextMenu from './components/menu/context-menu.js';
|
|
36
36
|
export type { ContextMenuContentProps, ContextMenuTriggerProps } from './components/menu/context-menu.js';
|
|
37
37
|
export * as Conversation from './components/conversation/index.js';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The line under an item's label in a menu: words, or a snippet of words with an
|
|
3
|
+
icon in them, such as a branch's icon and its name. An icon put in it is 12px
|
|
4
|
+
and lies in the line, rather than breaking it as an svg's block would.
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts" module>
|
|
7
|
+
import * as stylex from '@stylexjs/stylex';
|
|
8
|
+
import type { Snippet } from 'svelte';
|
|
9
|
+
import { layer } from './layer.js';
|
|
10
|
+
import './icons.css';
|
|
11
|
+
|
|
12
|
+
/** A line under an item's label: words, or a snippet that may hold an icon. */
|
|
13
|
+
export type ItemDescriptionContent = string | Snippet;
|
|
14
|
+
|
|
15
|
+
const styles = stylex.create({
|
|
16
|
+
rich: {
|
|
17
|
+
'--narvi-icon-size': '0.75rem',
|
|
18
|
+
display: 'flex',
|
|
19
|
+
alignItems: 'center',
|
|
20
|
+
gap: '0.25rem',
|
|
21
|
+
minWidth: 0
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<script lang="ts">
|
|
27
|
+
let { description }: { description: ItemDescriptionContent } = $props();
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
{#if typeof description === 'function'}
|
|
31
|
+
<span data-icons {...stylex.attrs(layer.description, styles.rich)}>{@render description()}</span>
|
|
32
|
+
{:else}
|
|
33
|
+
<span {...stylex.attrs(layer.description)}>{description}</span>
|
|
34
|
+
{/if}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import './icons.css';
|
|
3
|
+
/** A line under an item's label: words, or a snippet that may hold an icon. */
|
|
4
|
+
export type ItemDescriptionContent = string | Snippet;
|
|
5
|
+
type $$ComponentProps = {
|
|
6
|
+
description: ItemDescriptionContent;
|
|
7
|
+
};
|
|
8
|
+
declare const ItemDescription: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
9
|
+
type ItemDescription = ReturnType<typeof ItemDescription>;
|
|
10
|
+
export default ItemDescription;
|
|
@@ -13,5 +13,7 @@ export type RovingOptions = {
|
|
|
13
13
|
selector: string;
|
|
14
14
|
/** Which arrow keys move: up and down, or left and right. */
|
|
15
15
|
orientation?: 'vertical' | 'horizontal' | undefined;
|
|
16
|
+
/** Past the last item, the arrows go on to the first, and back from the first to the last, as tabs do. */
|
|
17
|
+
wrap?: boolean | undefined;
|
|
16
18
|
};
|
|
17
|
-
export declare function roving({ selector, orientation }: RovingOptions): Attachment<HTMLElement>;
|
|
19
|
+
export declare function roving({ selector, orientation, wrap }: RovingOptions): Attachment<HTMLElement>;
|