@diegopluna/narvi 0.3.2 → 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.
Files changed (114) hide show
  1. package/dist/components/activity/ActivityIcon.svelte +54 -0
  2. package/dist/components/activity/ActivityIcon.svelte.d.ts +24 -0
  3. package/dist/components/activity/ActivityStep.svelte +47 -13
  4. package/dist/components/activity/ActivityStep.svelte.d.ts +13 -4
  5. package/dist/components/activity/ActivityThought.svelte +24 -5
  6. package/dist/components/activity/ActivityThought.svelte.d.ts +12 -2
  7. package/dist/components/activity/index.d.ts +3 -1
  8. package/dist/components/activity/index.js +2 -1
  9. package/dist/components/app-shell/AppShellHeader.svelte +18 -4
  10. package/dist/components/app-shell/AppShellHeader.svelte.d.ts +5 -0
  11. package/dist/components/approval/Approval.svelte +14 -1
  12. package/dist/components/approval/Approval.svelte.d.ts +5 -0
  13. package/dist/components/badge/Badge.svelte +3 -1
  14. package/dist/components/badge/Badge.svelte.d.ts +1 -1
  15. package/dist/components/button/Button.svelte +17 -6
  16. package/dist/components/composer/ComposerModelPicker.svelte +80 -13
  17. package/dist/components/composer/ComposerModelPicker.svelte.d.ts +23 -6
  18. package/dist/components/composer/ComposerRoot.svelte +51 -12
  19. package/dist/components/composer/ComposerRoot.svelte.d.ts +16 -0
  20. package/dist/components/composer/ComposerSubmit.svelte +19 -5
  21. package/dist/components/composer/ComposerSubmit.svelte.d.ts +3 -1
  22. package/dist/components/composer/ComposerToggle.svelte +18 -4
  23. package/dist/components/composer/ComposerToggle.svelte.d.ts +2 -0
  24. package/dist/components/composer/ComposerTray.svelte +17 -3
  25. package/dist/components/composer/ComposerTray.svelte.d.ts +5 -0
  26. package/dist/components/composer/context.d.ts +4 -1
  27. package/dist/components/dialog/DialogContent.svelte +22 -12
  28. package/dist/components/dialog/DialogContent.svelte.d.ts +10 -0
  29. package/dist/components/divider/Divider.svelte +56 -14
  30. package/dist/components/divider/Divider.svelte.d.ts +13 -3
  31. package/dist/components/empty-state/EmptyState.svelte +12 -2
  32. package/dist/components/empty-state/EmptyState.svelte.d.ts +6 -0
  33. package/dist/components/heading/Heading.svelte +15 -0
  34. package/dist/components/heading/Heading.svelte.d.ts +6 -0
  35. package/dist/components/hover-card/HoverCardContent.svelte +18 -2
  36. package/dist/components/hover-card/HoverCardContent.svelte.d.ts +8 -0
  37. package/dist/components/input/Input.svelte +13 -3
  38. package/dist/components/input/Input.svelte.d.ts +10 -2
  39. package/dist/components/markdown/Markdown.svelte +22 -2
  40. package/dist/components/markdown/MarkdownDiagram.svelte +33 -2
  41. package/dist/components/markdown/MarkdownFile.svelte +56 -10
  42. package/dist/components/markdown/MarkdownMath.svelte +6 -0
  43. package/dist/components/markdown/MarkdownTable.svelte +3 -4
  44. package/dist/components/markdown/context.d.ts +6 -0
  45. package/dist/components/markdown/labels.d.ts +7 -0
  46. package/dist/components/markdown/labels.js +2 -0
  47. package/dist/components/menu/MenuCheckboxItem.svelte +44 -7
  48. package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +12 -2
  49. package/dist/components/menu/MenuContent.svelte +10 -2
  50. package/dist/components/menu/MenuContent.svelte.d.ts +10 -0
  51. package/dist/components/menu/MenuItem.svelte +17 -2
  52. package/dist/components/menu/MenuItem.svelte.d.ts +8 -0
  53. package/dist/components/menu/MenuSubContent.svelte +10 -2
  54. package/dist/components/menu/MenuSubContent.svelte.d.ts +10 -0
  55. package/dist/components/menu/MenuSubTrigger.svelte +19 -2
  56. package/dist/components/menu/MenuSubTrigger.svelte.d.ts +6 -0
  57. package/dist/components/message/MessageBubble.svelte +40 -0
  58. package/dist/components/message/MessageBubble.svelte.d.ts +12 -0
  59. package/dist/components/message/MessageContent.svelte +23 -14
  60. package/dist/components/message/MessageContent.svelte.d.ts +6 -0
  61. package/dist/components/message/MessageCopy.svelte +27 -15
  62. package/dist/components/message/MessageCopy.svelte.d.ts +9 -2
  63. package/dist/components/message/MessageRoot.svelte +20 -3
  64. package/dist/components/message/MessageRoot.svelte.d.ts +6 -0
  65. package/dist/components/message/context.d.ts +2 -0
  66. package/dist/components/message/index.d.ts +4 -1
  67. package/dist/components/message/index.js +3 -2
  68. package/dist/components/message/styles.d.ts +30 -0
  69. package/dist/components/message/styles.js +24 -0
  70. package/dist/components/notice/Notice.svelte +3 -3
  71. package/dist/components/popover/PopoverContent.svelte +27 -3
  72. package/dist/components/popover/PopoverContent.svelte.d.ts +18 -0
  73. package/dist/components/questionnaire/Questionnaire.svelte +103 -19
  74. package/dist/components/questionnaire/Questionnaire.svelte.d.ts +13 -1
  75. package/dist/components/queued-message/QueuedMessage.svelte +44 -6
  76. package/dist/components/queued-message/QueuedMessage.svelte.d.ts +12 -1
  77. package/dist/components/select/Select.svelte +18 -2
  78. package/dist/components/select/Select.svelte.d.ts +7 -0
  79. package/dist/components/toast/Toaster.svelte +1 -1
  80. package/dist/components/toggle/Toggle.svelte +12 -2
  81. package/dist/components/toggle/Toggle.svelte.d.ts +11 -1
  82. package/dist/components/toggle-group/ToggleGroupItem.svelte +10 -1
  83. package/dist/components/toggle-group/ToggleGroupRoot.svelte +7 -1
  84. package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +3 -1
  85. package/dist/components/toggle-group/context.d.ts +2 -1
  86. package/dist/components/tooltip/TooltipContent.svelte +13 -1
  87. package/dist/components/tooltip/TooltipContent.svelte.d.ts +10 -0
  88. package/dist/components/work-fold/WorkFold.svelte +13 -4
  89. package/dist/components/work-fold/WorkFold.svelte.d.ts +2 -1
  90. package/dist/focus-ring.d.ts +29 -0
  91. package/dist/focus-ring.js +42 -0
  92. package/dist/index.d.ts +6 -5
  93. package/dist/index.js +7 -2
  94. package/dist/internal/Collapse.svelte +15 -2
  95. package/dist/internal/Glyph.svelte +28 -0
  96. package/dist/internal/Glyph.svelte.d.ts +5 -0
  97. package/dist/internal/Tile.svelte +3 -2
  98. package/dist/internal/layer.d.ts +23 -0
  99. package/dist/internal/layer.js +19 -0
  100. package/dist/internal/toggle.d.ts +8 -1
  101. package/dist/internal/toggle.js +20 -2
  102. package/dist/markdown/file-paths.d.ts +7 -0
  103. package/dist/markdown/file-paths.js +29 -0
  104. package/dist/markdown/files.d.ts +22 -2
  105. package/dist/markdown/files.js +45 -14
  106. package/dist/tokens.stylex.d.ts +3 -0
  107. package/dist/tokens.stylex.js +5 -1
  108. package/package.json +1 -1
  109. package/skills/building-ui/SKILL.md +55 -3
  110. package/skills/building-ui/references/components.md +33 -33
  111. package/skills/markdown/SKILL.md +22 -6
  112. package/skills/setup/SKILL.md +1 -1
  113. package/skills/styling/SKILL.md +10 -3
  114. package/skills/theming/SKILL.md +11 -4
@@ -20,18 +20,40 @@
20
20
  disabled?: boolean | undefined;
21
21
  };
22
22
 
23
- export type ComposerModelPickerProps = Omit<HTMLButtonAttributes, 'children' | 'value'> & {
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
- /** Called when the person picks a model. */
30
- onchange?: ((value: string) => void) | undefined;
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
- const selected = $derived(models.find((model) => model.value === value) ?? models[0]);
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
- open = event.newState === 'open';
295
- if (!open && popover?.contains(document.activeElement)) {
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}: {selected?.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.value === selected?.value}
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
- export type ComposerModelPickerProps = Omit<HTMLButtonAttributes, 'children' | 'value'> & {
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
- /** Called when the person picks a model. */
21
- onchange?: ((value: string) => void) | undefined;
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
- declare const ComposerModelPicker: import("svelte").Component<ComposerModelPickerProps, {}, "value" | "ref">;
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
- ':has(textarea:focus-visible)': `inset 0 0 0 1px ${colors.focusRing}, 0 0 0 3px ${colors.focusHalo}`
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 = !text && files.length === 0;
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
- const something = value.trim().length > 0 || files.length > 0;
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
- textarea?.focus();
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
- textarea?.focus();
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
- textarea?.focus();
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
- 'children' | 'type' | 'variant' | 'iconOnly' | 'href' | 'ref' | 'sx'
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 busy = $derived(composer.busy);
80
- const idle = $derived(!busy && !composer.canSend);
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
  };
@@ -6,11 +6,13 @@
6
6
  import { attrs, type Sx } from '../../internal/sx.js';
7
7
  import { colors, font, motion, radius } from '../../tokens.stylex.js';
8
8
  import { media } from '../../media.stylex.js';
9
- import { useComposer } from './context.js';
9
+ import { getComposerContext } from './context.js';
10
10
 
11
11
  export type ComposerToggleProps = Omit<HTMLButtonAttributes, 'children'> & {
12
12
  /** Whether it is on. Bindable. */
13
13
  pressed?: boolean | undefined;
14
+ /** How it shows it is on: lit in the `accent`, or `neutral`, in the fill of what is chosen. */
15
+ tone?: 'accent' | 'neutral' | undefined;
14
16
  sx?: Sx | undefined;
15
17
  ref?: HTMLButtonElement | null | undefined;
16
18
  /** A 16px icon and a short label, such as "Search". */
@@ -64,6 +66,10 @@
64
66
  ':hover': { default: null, [media.hover]: colors.focusHalo }
65
67
  },
66
68
  color: { default: colors.accent, ':hover': colors.accent, [media.forcedColors]: 'Highlight' }
69
+ },
70
+ onNeutral: {
71
+ backgroundColor: colors.fillSelected,
72
+ color: { default: colors.text, [media.forcedColors]: 'Highlight' }
67
73
  }
68
74
  });
69
75
  </script>
@@ -71,6 +77,7 @@
71
77
  <script lang="ts">
72
78
  let {
73
79
  pressed = $bindable(false),
80
+ tone = 'accent',
74
81
  disabled,
75
82
  sx,
76
83
  class: className,
@@ -80,19 +87,26 @@
80
87
  ...rest
81
88
  }: ComposerToggleProps = $props();
82
89
 
83
- const composer = useComposer('Toggle');
90
+ // Works outside a Composer.Root too, such as in a toolbar of the app's own
91
+ const composer = getComposerContext();
84
92
  </script>
85
93
 
86
94
  <button
87
95
  bind:this={ref}
88
96
  type="button"
89
97
  aria-pressed={pressed}
90
- disabled={disabled ?? composer.disabled}
98
+ disabled={disabled ?? composer?.disabled}
91
99
  data-slot="composer-toggle"
92
100
  data-state={pressed ? 'on' : 'off'}
93
101
  {...rest}
94
102
  {...attrs(
95
- [styles.toggle, shared.focusable, styles.withIcon, pressed && styles.on, sx],
103
+ [
104
+ styles.toggle,
105
+ shared.focusable,
106
+ styles.withIcon,
107
+ pressed && (tone === 'neutral' ? styles.onNeutral : styles.on),
108
+ sx
109
+ ],
96
110
  className
97
111
  )}
98
112
  onclick={(event) => {
@@ -4,6 +4,8 @@ import { type Sx } from '../../internal/sx.js';
4
4
  export type ComposerToggleProps = Omit<HTMLButtonAttributes, 'children'> & {
5
5
  /** Whether it is on. Bindable. */
6
6
  pressed?: boolean | undefined;
7
+ /** How it shows it is on: lit in the `accent`, or `neutral`, in the fill of what is chosen. */
8
+ tone?: 'accent' | 'neutral' | undefined;
7
9
  sx?: Sx | undefined;
8
10
  ref?: HTMLButtonElement | null | undefined;
9
11
  /** A 16px icon and a short label, such as "Search". */
@@ -19,6 +19,11 @@
19
19
  label?: string | undefined;
20
20
  /** What is waiting on the person: an Approval, a Questionnaire, QueuedMessages. */
21
21
  pending?: Snippet | undefined;
22
+ /**
23
+ * Whether anything is waiting. Narvi shows the shelf while `pending` puts an element in
24
+ * it with something inside; set this when what is inside hides itself some other way.
25
+ */
26
+ waiting?: boolean | undefined;
22
27
  sx?: Sx | undefined;
23
28
  /** The Composer.Root. */
24
29
  children?: Snippet | undefined;
@@ -27,9 +32,10 @@
27
32
  const styles = stylex.create({
28
33
  tray: { display: 'flex', flexDirection: 'column', minWidth: 0 },
29
34
  // A flat fill whose foot tucks in behind the composer by the composer's own radius, so
30
- // the two read as one piece. It is there only while something is in it.
35
+ // the two read as one piece. It is there only while something is in it: an element
36
+ // that holds something and is not hidden.
31
37
  pending: {
32
- display: { default: 'none', ':has(> *)': 'flex' },
38
+ display: { default: 'none', ':has(> :not(:empty, [hidden], template))': 'flex' },
33
39
  flexDirection: 'column',
34
40
  gap: '0.375rem',
35
41
  padding: '0.375rem',
@@ -43,6 +49,8 @@
43
49
  outlineColor: 'transparent',
44
50
  outlineOffset: '-1px'
45
51
  },
52
+ shown: { display: 'flex' },
53
+ gone: { display: 'none' },
46
54
  // The composer stands in front of the shelf
47
55
  front: {
48
56
  position: 'relative',
@@ -58,6 +66,7 @@
58
66
  let {
59
67
  label = 'Waiting for you',
60
68
  pending,
69
+ waiting,
61
70
  sx,
62
71
  class: className,
63
72
  children,
@@ -70,7 +79,12 @@
70
79
  role="group"
71
80
  aria-label={label}
72
81
  data-slot="composer-tray-pending"
73
- {...stylex.attrs(styles.pending)}
82
+ data-waiting={waiting}
83
+ {...stylex.attrs(
84
+ styles.pending,
85
+ waiting === true && styles.shown,
86
+ waiting === false && styles.gone
87
+ )}
74
88
  >
75
89
  {@render pending?.()}
76
90
  </div>
@@ -6,6 +6,11 @@ export type ComposerTrayProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'>
6
6
  label?: string | undefined;
7
7
  /** What is waiting on the person: an Approval, a Questionnaire, QueuedMessages. */
8
8
  pending?: Snippet | undefined;
9
+ /**
10
+ * Whether anything is waiting. Narvi shows the shelf while `pending` puts an element in
11
+ * it with something inside; set this when what is inside hides itself some other way.
12
+ */
13
+ waiting?: boolean | undefined;
9
14
  sx?: Sx | undefined;
10
15
  /** The Composer.Root. */
11
16
  children?: Snippet | undefined;
@@ -23,8 +23,10 @@ export type ComposerContext = {
23
23
  readonly disabled: boolean;
24
24
  /** True while a reply is on its way. Submitting stops it instead of sending. */
25
25
  readonly busy: boolean;
26
+ /** True while a message is on its way and cannot be stopped: nothing can be sent or stopped. */
27
+ readonly sending: boolean;
26
28
  /**
27
- * Something to send, text or files, and nothing in the way of sending it.
29
+ * Something to send, text or files (or `hasContent`), and nothing in the way of sending it.
28
30
  * While a reply is under way, true only if the composer can queue.
29
31
  */
30
32
  readonly canSend: boolean;
@@ -37,6 +39,7 @@ export type ComposerContext = {
37
39
  browse(): void;
38
40
  /** True once a Composer.Attachments is placed: only then are dropped or pasted files taken. */
39
41
  readonly attachable: boolean;
42
+ /** Focuses the text field: the textarea, or an editor of your own marked `data-composer-field`. */
40
43
  focus(): void;
41
44
  /** Reads a short message out to assistive technology, such as "Attached report.pdf". */
42
45
  announce(message: string): void;