@diegopluna/narvi 0.3.3 → 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.
Files changed (66) hide show
  1. package/dist/components/app-shell/AppShellMain.svelte +14 -2
  2. package/dist/components/app-shell/AppShellPanel.svelte +108 -12
  3. package/dist/components/app-shell/AppShellPanel.svelte.d.ts +11 -1
  4. package/dist/components/app-shell/AppShellSheet.svelte +11 -1
  5. package/dist/components/app-shell/context.d.ts +8 -0
  6. package/dist/components/app-shell/context.js +7 -0
  7. package/dist/components/avatar/AvatarRoot.svelte +20 -7
  8. package/dist/components/avatar/AvatarRoot.svelte.d.ts +10 -3
  9. package/dist/components/badge/Badge.svelte +13 -1
  10. package/dist/components/badge/Badge.svelte.d.ts +6 -0
  11. package/dist/components/button/Button.svelte +71 -32
  12. package/dist/components/button/Button.svelte.d.ts +13 -0
  13. package/dist/components/command/CommandDialog.svelte +24 -2
  14. package/dist/components/command/CommandDialog.svelte.d.ts +12 -0
  15. package/dist/components/command/CommandItem.svelte +15 -4
  16. package/dist/components/command/CommandItem.svelte.d.ts +20 -4
  17. package/dist/components/command/CommandRoot.svelte +57 -2
  18. package/dist/components/command/CommandRoot.svelte.d.ts +25 -1
  19. package/dist/components/composer/ComposerModelPicker.svelte +608 -53
  20. package/dist/components/composer/ComposerModelPicker.svelte.d.ts +56 -1
  21. package/dist/components/composer/ComposerRoot.svelte.d.ts +1 -1
  22. package/dist/components/composer/ComposerSubmit.svelte +12 -2
  23. package/dist/components/composer/ComposerSubmit.svelte.d.ts +6 -0
  24. package/dist/components/composer/index.d.ts +1 -1
  25. package/dist/components/input/Input.svelte.d.ts +1 -1
  26. package/dist/components/menu/MenuCheckboxItem.svelte +14 -5
  27. package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +15 -4
  28. package/dist/components/menu/MenuItem.svelte +9 -3
  29. package/dist/components/menu/MenuItem.svelte.d.ts +11 -4
  30. package/dist/components/menu/MenuRadioItem.svelte +18 -9
  31. package/dist/components/menu/MenuRadioItem.svelte.d.ts +15 -4
  32. package/dist/components/menu/MenuSubTrigger.svelte +9 -3
  33. package/dist/components/menu/MenuSubTrigger.svelte.d.ts +11 -4
  34. package/dist/components/questionnaire/Questionnaire.svelte +100 -9
  35. package/dist/components/questionnaire/Questionnaire.svelte.d.ts +11 -0
  36. package/dist/components/segmented/SegmentedControl.svelte +12 -1
  37. package/dist/components/segmented/SegmentedControl.svelte.d.ts +3 -1
  38. package/dist/components/select/Select.svelte +36 -5
  39. package/dist/components/select/Select.svelte.d.ts +12 -0
  40. package/dist/components/settings-row/SettingsRow.svelte +87 -37
  41. package/dist/components/settings-row/SettingsRow.svelte.d.ts +13 -0
  42. package/dist/components/slider/Slider.svelte.d.ts +2 -2
  43. package/dist/components/split-button/SplitButton.svelte +147 -0
  44. package/dist/components/split-button/SplitButton.svelte.d.ts +36 -0
  45. package/dist/components/tab-strip/TabStrip.svelte +410 -109
  46. package/dist/components/tab-strip/TabStrip.svelte.d.ts +51 -3
  47. package/dist/components/tab-strip/drag.svelte.d.ts +31 -0
  48. package/dist/components/tab-strip/drag.svelte.js +148 -0
  49. package/dist/components/textarea/Textarea.svelte.d.ts +1 -1
  50. package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +1 -1
  51. package/dist/index.d.ts +3 -1
  52. package/dist/index.js +1 -0
  53. package/dist/internal/ItemDescription.svelte +34 -0
  54. package/dist/internal/ItemDescription.svelte.d.ts +10 -0
  55. package/dist/internal/roving.d.ts +3 -1
  56. package/dist/internal/roving.js +6 -3
  57. package/dist/media.stylex.d.ts +6 -0
  58. package/dist/media.stylex.js +6 -0
  59. package/dist/vite.js +4 -0
  60. package/package.json +20 -1
  61. package/skills/building-ui/SKILL.md +48 -20
  62. package/skills/building-ui/references/components.md +43 -42
  63. package/skills/markdown/SKILL.md +1 -1
  64. package/skills/setup/SKILL.md +1 -1
  65. package/skills/styling/SKILL.md +11 -2
  66. package/skills/theming/SKILL.md +1 -1
@@ -5,9 +5,13 @@
5
5
  sideways, and keeps the open one in view. A tab with a leading icon shows its
6
6
  close button in the icon's place, so no room is kept at its end.
7
7
 
8
- It names the tabs and says which is open. The panel under it is yours: give
9
- it `role="tabpanel"` and the id passed as `controls`. For a fixed set of
10
- sections that own their panel, use Tabs.
8
+ A tab can carry a menu (a right-click, the menu key or a long press), be
9
+ dragged into another place, be renamed where it stands, and hold buttons of
10
+ its own. Each is offered only when its callback or snippet is given.
11
+
12
+ It names the tabs and says which is open. The panels are yours: give each
13
+ `role="tabpanel"` and the id passed as `controls`, or one per tab, with its
14
+ own `panelId`. For a fixed set of sections that own their panel, use Tabs.
11
15
  -->
12
16
  <script lang="ts" module>
13
17
  import { visuallyHidden } from '../../visually-hidden.js';
@@ -17,6 +21,9 @@
17
21
  import Glyph from '../../internal/Glyph.svelte';
18
22
  import { tabStripTabMarker } from '../../internal/markers.stylex.js';
19
23
  import { roving } from '../../internal/roving.js';
24
+ import * as ContextMenu from '../menu/context-menu.js';
25
+ import * as Menu from '../menu/index.js';
26
+ import { TabDragging, tabOffset } from './drag.svelte.js';
20
27
  import { attrs, type Sx } from '../../internal/sx.js';
21
28
  import { colors, font, motion, radius } from '../../tokens.stylex.js';
22
29
  import { media } from '../../media.stylex.js';
@@ -24,27 +31,78 @@
24
31
  export type TabStripTab = {
25
32
  id: string;
26
33
  label: string;
34
+ /** The tab's name in full, as a tooltip, where the label is short. Defaults to the label. */
35
+ title?: string | undefined;
27
36
  /** Shown in place of the close button until the pointer is on the tab: unsaved, or live. */
28
37
  mark?: 'unsaved' | 'live' | undefined;
38
+ /** The DOM id of the tab, for its panel's `aria-labelledby`. */
39
+ tabId?: string | undefined;
40
+ /** The id of this tab's own panel, in place of the strip's `controls`. */
41
+ panelId?: string | undefined;
42
+ /** With `onrename`, whether this tab can be renamed. Defaults to true. */
43
+ renamable?: boolean | undefined;
29
44
  };
30
45
 
31
- export type TabStripProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'onclose'> & {
46
+ export type TabStripProps = Omit<
47
+ HTMLAttributes<HTMLDivElement>,
48
+ 'children' | 'onclose' | 'onchange'
49
+ > & {
32
50
  tabs: TabStripTab[];
33
51
  /** The id of the open tab. Bindable. */
34
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;
35
60
  /** Names the strip: "Open threads". */
36
61
  label: string;
37
62
  /** The id of the panel the tabs show. */
38
63
  controls?: string | undefined;
39
64
  /** Called to close a tab. Without it the tabs cannot be closed. */
40
65
  onclose?: ((id: string) => void) | undefined;
41
- /** 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. */
42
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;
43
73
  addLabel?: string | undefined;
44
74
  /** The name of a tab's close button. */
45
75
  closeLabel?: ((tab: TabStripTab) => string) | undefined;
46
76
  /** Before a tab's label: an icon, or a StatusIndicator. */
47
77
  leading?: Snippet<[TabStripTab]> | undefined;
78
+ /**
79
+ * Buttons of a tab's own, after its label and before its close button: one that mutes a
80
+ * page, say. Keep them few and small: an `xs` or `micro` icon-only Button.
81
+ */
82
+ trailing?: Snippet<[TabStripTab]> | undefined;
83
+ /**
84
+ * A tab's menu, of Menu parts: Move left, Rename, Close. It opens on a right-click, on
85
+ * Shift+F10 or the menu key, and on a long press on a touch screen.
86
+ */
87
+ menu?: Snippet<[TabStripTab]> | undefined;
88
+ /**
89
+ * Called as a tab is dropped into another place, with its id and the index it goes to
90
+ * among the tabs. Without it the tabs cannot be dragged. Alt+Shift with an arrow moves
91
+ * the focused tab too.
92
+ */
93
+ onmove?: ((id: string, index: number) => void) | undefined;
94
+ /**
95
+ * Called with a tab's new name, as Enter is pressed. Without it the tabs cannot be
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.
98
+ */
99
+ onrename?: ((id: string, label: string) => void) | undefined;
100
+ /** The id of the tab being renamed. Bindable: set it from a menu's Rename. */
101
+ renaming?: string | undefined;
102
+ /** The name of a tab's field while it is renamed. */
103
+ renameLabel?: ((tab: TabStripTab) => string) | undefined;
104
+ /** The id of a tab shown beside the open one, as in a split view: it is lit, as under the pointer. */
105
+ beside?: string | undefined;
48
106
  sx?: Sx | undefined;
49
107
  };
50
108
 
@@ -90,10 +148,32 @@
90
148
  default: colors.textMuted,
91
149
  [HOVER]: { default: null, [media.hover]: colors.text }
92
150
  },
151
+ // Moved aside while another is dragged
152
+ translate: 'var(--narvi-tab-offset, 0px) 0',
93
153
  transitionProperty: 'background-color, color',
94
154
  transitionDuration: motion.fast,
95
155
  transitionTimingFunction: 'ease'
96
156
  },
157
+ // Beside the open one, in a split view: lit, as under the pointer
158
+ beside: { backgroundColor: colors.fillHover, color: colors.text },
159
+ // The others slide aside, and a dropped tab settles, quickly; the dragged one follows
160
+ // the pointer as it moves
161
+ sliding: {
162
+ transitionProperty: {
163
+ default: 'background-color, color',
164
+ [media.motion]: 'translate, background-color, color'
165
+ },
166
+ transitionDuration: motion.base,
167
+ transitionTimingFunction: motion.easeOut
168
+ },
169
+ // Picked up, it floats over the strip, so it takes the one shadow
170
+ lifted: {
171
+ zIndex: 10,
172
+ cursor: 'grabbing',
173
+ backgroundColor: { default: colors.bgRaised, [HOVER]: colors.bgRaised },
174
+ color: colors.text,
175
+ boxShadow: `inset 0 0 0 1px ${colors.border}, 0 4px 12px -2px ${colors.shadow}`
176
+ },
97
177
  // The open tab: a fill, as the open row of a list has
98
178
  selected: {
99
179
  backgroundColor: { default: colors.fillSelected, [HOVER]: colors.fillSelected },
@@ -128,6 +208,35 @@
128
208
  },
129
209
  // A tab that can be closed keeps room at its end for the button
130
210
  closable: { paddingInlineEnd: '1.625rem' },
211
+ // With buttons of its own, the room for the close button is kept after them
212
+ buttonBeforeTrailing: { paddingInlineEnd: '0.375rem' },
213
+ trailing: {
214
+ display: 'flex',
215
+ alignItems: 'center',
216
+ gap: '0.125rem',
217
+ flexShrink: 0,
218
+ paddingInlineEnd: '0.25rem'
219
+ },
220
+ trailingBeforeEnd: { paddingInlineEnd: '1.5rem' },
221
+ // The name, typed in place
222
+ rename: {
223
+ boxSizing: 'border-box',
224
+ flexGrow: 1,
225
+ width: '8rem',
226
+ minWidth: 0,
227
+ height: '1.25rem',
228
+ marginInline: '0.25rem',
229
+ paddingInline: '0.375rem',
230
+ borderWidth: 0,
231
+ borderRadius: radius.item,
232
+ backgroundColor: colors.bgRaised,
233
+ boxShadow: `inset 0 0 0 1px ${colors.focusRing}`,
234
+ color: colors.text,
235
+ fontFamily: 'inherit',
236
+ fontSize: font.sizeMeta,
237
+ fontWeight: font.weightRegular,
238
+ outlineStyle: 'none'
239
+ },
131
240
  text: { minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
132
241
  leading: { display: 'grid', flexShrink: 0 },
133
242
  // With a leading icon, the close button and a mark take the icon's place: the icon
@@ -262,9 +371,19 @@
262
371
  controls,
263
372
  onclose,
264
373
  onadd,
374
+ addMenu,
265
375
  addLabel = 'New tab',
376
+ onchange,
377
+ activation = 'automatic',
266
378
  closeLabel = (tab) => `Close ${tab.label}`,
267
379
  leading,
380
+ trailing,
381
+ menu,
382
+ onmove,
383
+ onrename,
384
+ renaming = $bindable(),
385
+ renameLabel = (tab) => `Name of ${tab.label}`,
386
+ beside,
268
387
  sx,
269
388
  class: className,
270
389
  ...rest
@@ -272,14 +391,35 @@
272
391
 
273
392
  let list = $state<HTMLElement | null>(null);
274
393
 
275
- // The open tab stays in view as tabs come, go and are chosen
394
+ const tabElements = () => [
395
+ ...(list?.querySelectorAll<HTMLElement>('[data-slot="tab-strip-tab"]') ?? [])
396
+ ];
397
+ const tabButton = (id: string) =>
398
+ tabElements()
399
+ .find((element) => element.dataset.tabId === id)
400
+ ?.querySelector<HTMLElement>('[role="tab"]') ?? null;
401
+
402
+ const dragging = new TabDragging(
403
+ tabElements,
404
+ () => list,
405
+ (from, to) => {
406
+ const tab = tabs[from];
407
+ if (tab) onmove?.(tab.id, to);
408
+ }
409
+ );
410
+ $effect(() => () => dragging.dispose());
411
+ const drag = $derived(dragging.drag);
412
+
413
+ // The open tab stays in view as tabs come, go and are chosen, and so does one being renamed
276
414
  $effect(() => {
277
415
  void value;
278
416
  void tabs.length;
417
+ const named = renaming;
279
418
  tick().then(() =>
280
- list
281
- ?.querySelector<HTMLElement>('[role="tab"][aria-selected="true"]')
282
- ?.scrollIntoView({ block: 'nearest', inline: 'nearest' })
419
+ (named
420
+ ? list?.querySelector<HTMLElement>('[data-renaming]')
421
+ : list?.querySelector<HTMLElement>('[role="tab"][aria-selected="true"]')
422
+ )?.scrollIntoView({ block: 'nearest', inline: 'nearest' })
283
423
  );
284
424
  });
285
425
 
@@ -294,128 +434,289 @@
294
434
  (buttons?.[Math.min(index, (buttons?.length ?? 1) - 1)] ?? null)?.focus();
295
435
  });
296
436
  }
437
+
438
+ // The menu's trigger would make the tab's frame focusable; the tab inside is what takes focus
439
+ function withoutTabStop(props: Record<string, unknown>) {
440
+ const { tabindex: _, ...others } = props;
441
+ void _;
442
+ return others;
443
+ }
444
+
445
+ const renamable = (tab: TabStripTab) => !!onrename && tab.renamable !== false;
446
+
447
+ function startRename(tab: TabStripTab) {
448
+ if (renamable(tab)) renaming = tab.id;
449
+ }
450
+
451
+ // Enter keeps the name typed; Escape, or leaving the field, keeps the old one
452
+ function endRename(tab: TabStripTab, name: string | null, refocus: boolean) {
453
+ if (renaming !== tab.id) return;
454
+ renaming = undefined;
455
+ // Cleared, the name goes as '': the app gives the tab back a name of its own
456
+ const next = name?.trim();
457
+ if (next !== undefined && next !== tab.label) onrename?.(tab.id, next);
458
+ if (refocus) tick().then(() => tabButton(tab.id)?.focus());
459
+ }
460
+
461
+ // The field takes the focus, with its words chosen, so typing replaces them
462
+ const selectAll = (input: HTMLInputElement) => {
463
+ input.focus();
464
+ input.select();
465
+ };
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
+
485
+ function moveByKey(tab: TabStripTab, event: KeyboardEvent) {
486
+ if (!onmove || !event.altKey || !event.shiftKey) return false;
487
+ if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') return false;
488
+ const rtl = list ? getComputedStyle(list).direction === 'rtl' : false;
489
+ const later = (event.key === 'ArrowRight') !== rtl;
490
+ const index = tabs.indexOf(tab);
491
+ const to = later ? index + 1 : index - 1;
492
+ event.preventDefault();
493
+ if (to < 0 || to >= tabs.length) return true;
494
+ onmove(tab.id, to);
495
+ // The tab keeps the focus in its new place
496
+ tick().then(() => tabButton(tab.id)?.focus());
497
+ return true;
498
+ }
297
499
  </script>
298
500
 
299
- <div data-slot="tab-strip" {...rest} {...attrs([styles.root, sx], className)}>
501
+ {#snippet tabView(tab: TabStripTab, index: number, trigger: Record<string, unknown>)}
502
+ {@const selected = tab.id === value}
503
+ {@const lifted = !!drag && drag.from === index && !drag.settling}
504
+ {@const editing = renaming === tab.id && renamable(tab)}
505
+ {@const { onpointerdown: menuPointerDown, ...triggerRest } = withoutTabStop(trigger)}
300
506
  <div
301
- bind:this={list}
302
- role="tablist"
303
- aria-label={label}
304
- aria-orientation="horizontal"
305
- {...stylex.attrs(styles.list)}
306
- {@attach roving({ selector: '[role="tab"]', orientation: 'horizontal' })}
507
+ {...triggerRest}
508
+ data-slot="tab-strip-tab"
509
+ data-tab-id={tab.id}
510
+ data-renaming={editing || undefined}
511
+ data-lifted={lifted || undefined}
512
+ style:--narvi-tab-offset={drag ? `${tabOffset(drag, index)}px` : undefined}
513
+ onpointerdown={(event) => {
514
+ // The menu's own, which opens it on a long press on a touch screen
515
+ if (typeof menuPointerDown === 'function') menuPointerDown(event);
516
+ if (onmove && !editing) dragging.press(index, event);
517
+ }}
518
+ {...stylex.attrs(
519
+ styles.tab,
520
+ tab.id === beside && !selected && styles.beside,
521
+ selected && styles.selected,
522
+ drag && !lifted && styles.sliding,
523
+ lifted && styles.lifted,
524
+ tabStripTabMarker
525
+ )}
307
526
  >
308
- {#each tabs as tab (tab.id)}
309
- {@const selected = tab.id === value}
310
- <div
311
- data-slot="tab-strip-tab"
312
- {...stylex.attrs(styles.tab, selected && styles.selected, tabStripTabMarker)}
527
+ {#if editing}
528
+ <input
529
+ {@attach selectAll}
530
+ aria-label={renameLabel(tab)}
531
+ value={tab.label}
532
+ onkeydown={(event) => {
533
+ if (event.key !== 'Enter' && event.key !== 'Escape') return;
534
+ // Its own keys, not the strip's, a dialog's or the window's
535
+ event.preventDefault();
536
+ event.stopPropagation();
537
+ endRename(tab, event.key === 'Enter' ? event.currentTarget.value : null, true);
538
+ }}
539
+ onblur={() => endRename(tab, null, false)}
540
+ {...stylex.attrs(styles.rename)}
541
+ />
542
+ {:else}
543
+ <button
544
+ type="button"
545
+ role="tab"
546
+ id={tab.tabId}
547
+ aria-selected={selected}
548
+ aria-controls={tab.panelId ?? controls}
549
+ aria-current={selected ? 'true' : undefined}
550
+ title={tab.title ?? tab.label}
551
+ {...stylex.attrs(
552
+ styles.button,
553
+ onclose && !leading && !trailing && styles.closable,
554
+ trailing && styles.buttonBeforeTrailing
555
+ )}
556
+ onclick={() => open(tab)}
557
+ onfocus={() => {
558
+ if (arrowed && activation === 'automatic') open(tab);
559
+ }}
560
+ ondblclick={() => startRename(tab)}
561
+ onauxclick={(event) => {
562
+ // The middle button closes, as it does in a browser
563
+ if (event.button === 1) close(tab);
564
+ }}
565
+ onkeydown={(event) => {
566
+ if (moveByKey(tab, event)) return;
567
+ if (event.key === 'F2' && renamable(tab)) {
568
+ event.preventDefault();
569
+ startRename(tab);
570
+ return;
571
+ }
572
+ if (!onclose || (event.key !== 'Delete' && event.key !== 'Backspace')) return;
573
+ event.preventDefault();
574
+ close(tab, true);
575
+ }}
313
576
  >
577
+ {#if leading}
578
+ <span {...stylex.attrs(styles.leadCell)}>
579
+ {#if tab.mark}
580
+ <span
581
+ aria-hidden="true"
582
+ {...stylex.attrs(
583
+ styles.mark,
584
+ styles.markStill,
585
+ styles.leadMark,
586
+ tab.mark === 'live' && styles.live,
587
+ onclose && styles.leadIcon,
588
+ onclose && selected && styles.leadIconSelected
589
+ )}
590
+ ></span>
591
+ {:else}
592
+ <span
593
+ {...stylex.attrs(
594
+ styles.leading,
595
+ onclose && styles.leadIcon,
596
+ onclose && selected && styles.leadIconSelected
597
+ )}>{@render leading(tab)}</span
598
+ >
599
+ {/if}
600
+ </span>
601
+ {/if}
602
+ <span {...stylex.attrs(styles.text)}>{tab.label}</span>
603
+ {#if tab.mark}<span {...stylex.attrs(visuallyHidden)}
604
+ >, {tab.mark === 'live' ? 'working' : 'unsaved'}</span
605
+ >{/if}
606
+ </button>
607
+ {/if}
608
+ {#if trailing}
609
+ <span
610
+ {...stylex.attrs(
611
+ styles.trailing,
612
+ !leading && (onclose || tab.mark) && styles.trailingBeforeEnd
613
+ )}>{@render trailing(tab)}</span
614
+ >
615
+ {/if}
616
+ {#if leading && onclose}
617
+ <span {...stylex.attrs(styles.start)}>
314
618
  <button
315
619
  type="button"
316
- role="tab"
317
- aria-selected={selected}
318
- aria-controls={controls}
319
- aria-current={selected ? 'true' : undefined}
320
- title={tab.label}
321
- {...stylex.attrs(styles.button, onclose && !leading && styles.closable)}
322
- onclick={() => (value = tab.id)}
323
- onauxclick={(event) => {
324
- // The middle button closes, as it does in a browser
325
- if (event.button === 1) close(tab);
326
- }}
327
- onkeydown={(event) => {
328
- if (!onclose || (event.key !== 'Delete' && event.key !== 'Backspace')) return;
329
- event.preventDefault();
330
- close(tab, true);
331
- }}
620
+ tabindex="-1"
621
+ aria-label={closeLabel(tab)}
622
+ {...stylex.attrs(styles.close, selected ? styles.closeLeadSelected : styles.closeLead)}
623
+ onclick={() => close(tab)}
332
624
  >
333
- {#if leading}
334
- <span {...stylex.attrs(styles.leadCell)}>
335
- {#if tab.mark}
336
- <span
337
- aria-hidden="true"
338
- {...stylex.attrs(
339
- styles.mark,
340
- styles.markStill,
341
- styles.leadMark,
342
- tab.mark === 'live' && styles.live,
343
- onclose && styles.leadIcon,
344
- onclose && selected && styles.leadIconSelected
345
- )}
346
- ></span>
347
- {:else}
348
- <span
349
- {...stylex.attrs(
350
- styles.leading,
351
- onclose && styles.leadIcon,
352
- onclose && selected && styles.leadIconSelected
353
- )}>{@render leading(tab)}</span
354
- >
355
- {/if}
356
- </span>
357
- {/if}
358
- <span {...stylex.attrs(styles.text)}>{tab.label}</span>
359
- {#if tab.mark}<span {...stylex.attrs(visuallyHidden)}
360
- >, {tab.mark === 'live' ? 'working' : 'unsaved'}</span
361
- >{/if}
625
+ <Glyph name="close" size={12} />
362
626
  </button>
363
- {#if leading && onclose}
364
- <span {...stylex.attrs(styles.start)}>
627
+ </span>
628
+ {:else if onclose || tab.mark}
629
+ <span {...stylex.attrs(styles.end)}>
630
+ {#if tab.mark}
631
+ <span
632
+ aria-hidden="true"
633
+ {...stylex.attrs(styles.mark, tab.mark === 'live' && styles.live)}
634
+ ></span>
635
+ {/if}
636
+ {#if onclose}
637
+ <span {...stylex.attrs(styles.closeCell)}>
365
638
  <button
366
639
  type="button"
367
640
  tabindex="-1"
368
641
  aria-label={closeLabel(tab)}
369
- {...stylex.attrs(
370
- styles.close,
371
- selected ? styles.closeLeadSelected : styles.closeLead
372
- )}
642
+ {...stylex.attrs(styles.close, selected && !tab.mark && styles.closeShown)}
373
643
  onclick={() => close(tab)}
374
644
  >
375
645
  <Glyph name="close" size={12} />
376
646
  </button>
377
647
  </span>
378
- {:else if onclose || tab.mark}
379
- <span {...stylex.attrs(styles.end)}>
380
- {#if tab.mark}
381
- <span
382
- aria-hidden="true"
383
- {...stylex.attrs(styles.mark, tab.mark === 'live' && styles.live)}
384
- ></span>
385
- {/if}
386
- {#if onclose}
387
- <span {...stylex.attrs(styles.closeCell)}>
388
- <button
389
- type="button"
390
- tabindex="-1"
391
- aria-label={closeLabel(tab)}
392
- {...stylex.attrs(styles.close, selected && !tab.mark && styles.closeShown)}
393
- onclick={() => close(tab)}
394
- >
395
- <Glyph name="close" size={12} />
396
- </button>
397
- </span>
398
- {/if}
399
- </span>
400
648
  {/if}
401
- </div>
649
+ </span>
650
+ {/if}
651
+ </div>
652
+ {/snippet}
653
+
654
+ <div
655
+ data-slot="tab-strip"
656
+ data-dragging={drag ? '' : undefined}
657
+ {...rest}
658
+ {...attrs([styles.root, sx], className)}
659
+ >
660
+ <div
661
+ bind:this={list}
662
+ role="tablist"
663
+ aria-label={label}
664
+ aria-orientation="horizontal"
665
+ {...stylex.attrs(styles.list)}
666
+ {@attach roving({ selector: '[role="tab"]', orientation: 'horizontal', wrap: true })}
667
+ onkeydowncapture={onListKeydownCapture}
668
+ >
669
+ {#each tabs as tab, index (tab.id)}
670
+ {#if menu}
671
+ <ContextMenu.Root>
672
+ <ContextMenu.Trigger>
673
+ {#snippet child({ props })}{@render tabView(tab, index, props)}{/snippet}
674
+ </ContextMenu.Trigger>
675
+ <!-- Renaming from it, the field keeps the focus the menu would give back -->
676
+ <ContextMenu.Content
677
+ onCloseAutoFocus={(event) => {
678
+ if (renaming !== tab.id) return;
679
+ event.preventDefault();
680
+ list?.querySelector<HTMLInputElement>('[data-renaming] input')?.focus();
681
+ }}
682
+ >
683
+ {@render menu(tab)}
684
+ </ContextMenu.Content>
685
+ </ContextMenu.Root>
686
+ {:else}
687
+ {@render tabView(tab, index, {})}
688
+ {/if}
402
689
  {/each}
403
690
  </div>
404
- {#if onadd}
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}
405
718
  <button type="button" aria-label={addLabel} {...stylex.attrs(styles.add)} onclick={onadd}>
406
- <svg
407
- data-glyph=""
408
- width="14"
409
- height="14"
410
- viewBox="0 0 16 16"
411
- fill="none"
412
- stroke="currentColor"
413
- stroke-width="1.5"
414
- stroke-linecap="round"
415
- aria-hidden="true"
416
- >
417
- <path d="M8 3.5v9M3.5 8h9" />
418
- </svg>
719
+ {@render plus()}
419
720
  </button>
420
721
  {/if}
421
722
  </div>