@diegopluna/narvi 0.3.2 → 0.3.4

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 (133) 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/app-shell/AppShellMain.svelte +14 -2
  12. package/dist/components/app-shell/AppShellPanel.svelte +77 -12
  13. package/dist/components/app-shell/AppShellPanel.svelte.d.ts +11 -1
  14. package/dist/components/app-shell/AppShellSheet.svelte +11 -1
  15. package/dist/components/app-shell/context.d.ts +8 -0
  16. package/dist/components/app-shell/context.js +7 -0
  17. package/dist/components/approval/Approval.svelte +14 -1
  18. package/dist/components/approval/Approval.svelte.d.ts +5 -0
  19. package/dist/components/avatar/AvatarRoot.svelte +20 -7
  20. package/dist/components/avatar/AvatarRoot.svelte.d.ts +10 -3
  21. package/dist/components/badge/Badge.svelte +3 -1
  22. package/dist/components/badge/Badge.svelte.d.ts +1 -1
  23. package/dist/components/button/Button.svelte +28 -6
  24. package/dist/components/button/Button.svelte.d.ts +7 -0
  25. package/dist/components/composer/ComposerModelPicker.svelte +80 -13
  26. package/dist/components/composer/ComposerModelPicker.svelte.d.ts +23 -6
  27. package/dist/components/composer/ComposerRoot.svelte +51 -12
  28. package/dist/components/composer/ComposerRoot.svelte.d.ts +16 -0
  29. package/dist/components/composer/ComposerSubmit.svelte +19 -5
  30. package/dist/components/composer/ComposerSubmit.svelte.d.ts +3 -1
  31. package/dist/components/composer/ComposerToggle.svelte +18 -4
  32. package/dist/components/composer/ComposerToggle.svelte.d.ts +2 -0
  33. package/dist/components/composer/ComposerTray.svelte +17 -3
  34. package/dist/components/composer/ComposerTray.svelte.d.ts +5 -0
  35. package/dist/components/composer/context.d.ts +4 -1
  36. package/dist/components/dialog/DialogContent.svelte +22 -12
  37. package/dist/components/dialog/DialogContent.svelte.d.ts +10 -0
  38. package/dist/components/divider/Divider.svelte +56 -14
  39. package/dist/components/divider/Divider.svelte.d.ts +13 -3
  40. package/dist/components/empty-state/EmptyState.svelte +12 -2
  41. package/dist/components/empty-state/EmptyState.svelte.d.ts +6 -0
  42. package/dist/components/heading/Heading.svelte +15 -0
  43. package/dist/components/heading/Heading.svelte.d.ts +6 -0
  44. package/dist/components/hover-card/HoverCardContent.svelte +18 -2
  45. package/dist/components/hover-card/HoverCardContent.svelte.d.ts +8 -0
  46. package/dist/components/input/Input.svelte +13 -3
  47. package/dist/components/input/Input.svelte.d.ts +10 -2
  48. package/dist/components/markdown/Markdown.svelte +22 -2
  49. package/dist/components/markdown/MarkdownDiagram.svelte +33 -2
  50. package/dist/components/markdown/MarkdownFile.svelte +56 -10
  51. package/dist/components/markdown/MarkdownMath.svelte +6 -0
  52. package/dist/components/markdown/MarkdownTable.svelte +3 -4
  53. package/dist/components/markdown/context.d.ts +6 -0
  54. package/dist/components/markdown/labels.d.ts +7 -0
  55. package/dist/components/markdown/labels.js +2 -0
  56. package/dist/components/menu/MenuCheckboxItem.svelte +44 -7
  57. package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +12 -2
  58. package/dist/components/menu/MenuContent.svelte +10 -2
  59. package/dist/components/menu/MenuContent.svelte.d.ts +10 -0
  60. package/dist/components/menu/MenuItem.svelte +17 -2
  61. package/dist/components/menu/MenuItem.svelte.d.ts +8 -0
  62. package/dist/components/menu/MenuSubContent.svelte +10 -2
  63. package/dist/components/menu/MenuSubContent.svelte.d.ts +10 -0
  64. package/dist/components/menu/MenuSubTrigger.svelte +19 -2
  65. package/dist/components/menu/MenuSubTrigger.svelte.d.ts +6 -0
  66. package/dist/components/message/MessageBubble.svelte +40 -0
  67. package/dist/components/message/MessageBubble.svelte.d.ts +12 -0
  68. package/dist/components/message/MessageContent.svelte +23 -14
  69. package/dist/components/message/MessageContent.svelte.d.ts +6 -0
  70. package/dist/components/message/MessageCopy.svelte +27 -15
  71. package/dist/components/message/MessageCopy.svelte.d.ts +9 -2
  72. package/dist/components/message/MessageRoot.svelte +20 -3
  73. package/dist/components/message/MessageRoot.svelte.d.ts +6 -0
  74. package/dist/components/message/context.d.ts +2 -0
  75. package/dist/components/message/index.d.ts +4 -1
  76. package/dist/components/message/index.js +3 -2
  77. package/dist/components/message/styles.d.ts +30 -0
  78. package/dist/components/message/styles.js +24 -0
  79. package/dist/components/notice/Notice.svelte +3 -3
  80. package/dist/components/popover/PopoverContent.svelte +27 -3
  81. package/dist/components/popover/PopoverContent.svelte.d.ts +18 -0
  82. package/dist/components/questionnaire/Questionnaire.svelte +103 -19
  83. package/dist/components/questionnaire/Questionnaire.svelte.d.ts +13 -1
  84. package/dist/components/queued-message/QueuedMessage.svelte +44 -6
  85. package/dist/components/queued-message/QueuedMessage.svelte.d.ts +12 -1
  86. package/dist/components/segmented/SegmentedControl.svelte +12 -1
  87. package/dist/components/segmented/SegmentedControl.svelte.d.ts +3 -1
  88. package/dist/components/select/Select.svelte +43 -6
  89. package/dist/components/select/Select.svelte.d.ts +14 -0
  90. package/dist/components/settings-row/SettingsRow.svelte +87 -37
  91. package/dist/components/settings-row/SettingsRow.svelte.d.ts +13 -0
  92. package/dist/components/split-button/SplitButton.svelte +137 -0
  93. package/dist/components/split-button/SplitButton.svelte.d.ts +29 -0
  94. package/dist/components/tab-strip/TabStrip.svelte +337 -93
  95. package/dist/components/tab-strip/TabStrip.svelte.d.ts +36 -1
  96. package/dist/components/tab-strip/drag.svelte.d.ts +31 -0
  97. package/dist/components/tab-strip/drag.svelte.js +148 -0
  98. package/dist/components/toast/Toaster.svelte +1 -1
  99. package/dist/components/toggle/Toggle.svelte +12 -2
  100. package/dist/components/toggle/Toggle.svelte.d.ts +11 -1
  101. package/dist/components/toggle-group/ToggleGroupItem.svelte +10 -1
  102. package/dist/components/toggle-group/ToggleGroupRoot.svelte +7 -1
  103. package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +3 -1
  104. package/dist/components/toggle-group/context.d.ts +2 -1
  105. package/dist/components/tooltip/TooltipContent.svelte +13 -1
  106. package/dist/components/tooltip/TooltipContent.svelte.d.ts +10 -0
  107. package/dist/components/work-fold/WorkFold.svelte +13 -4
  108. package/dist/components/work-fold/WorkFold.svelte.d.ts +2 -1
  109. package/dist/focus-ring.d.ts +29 -0
  110. package/dist/focus-ring.js +42 -0
  111. package/dist/index.d.ts +8 -5
  112. package/dist/index.js +8 -2
  113. package/dist/internal/Collapse.svelte +15 -2
  114. package/dist/internal/Glyph.svelte +28 -0
  115. package/dist/internal/Glyph.svelte.d.ts +5 -0
  116. package/dist/internal/Tile.svelte +3 -2
  117. package/dist/internal/layer.d.ts +23 -0
  118. package/dist/internal/layer.js +19 -0
  119. package/dist/internal/toggle.d.ts +8 -1
  120. package/dist/internal/toggle.js +20 -2
  121. package/dist/markdown/file-paths.d.ts +7 -0
  122. package/dist/markdown/file-paths.js +29 -0
  123. package/dist/markdown/files.d.ts +22 -2
  124. package/dist/markdown/files.js +45 -14
  125. package/dist/tokens.stylex.d.ts +3 -0
  126. package/dist/tokens.stylex.js +5 -1
  127. package/package.json +1 -1
  128. package/skills/building-ui/SKILL.md +77 -5
  129. package/skills/building-ui/references/components.md +51 -50
  130. package/skills/markdown/SKILL.md +22 -6
  131. package/skills/setup/SKILL.md +1 -1
  132. package/skills/styling/SKILL.md +10 -3
  133. package/skills/theming/SKILL.md +11 -4
@@ -0,0 +1,29 @@
1
+ import type { Snippet } from 'svelte';
2
+ import { type Sx } from '../../internal/sx.js';
3
+ import { type ButtonProps } from '../button/Button.svelte';
4
+ export type SplitButtonProps = Omit<ButtonProps, 'variant' | 'iconOnly' | 'href' | 'shape' | 'pressed' | 'sx'> & {
5
+ /** `secondary`, an edge round both halves; `primary`, the one solid, with a line between them. */
6
+ variant?: 'primary' | 'secondary' | undefined;
7
+ /** Names the pair as a group, where the button's own words do not say it all: "Merge". */
8
+ label?: string | undefined;
9
+ /** Names the button that opens the menu: "Choose how to merge", "More for GitHub". */
10
+ menuLabel?: string | undefined;
11
+ /**
12
+ * The menu: Menu.Item, Menu.RadioGroup, Menu.CheckboxItem and the rest. Without it there
13
+ * is no second button.
14
+ */
15
+ menu?: Snippet | undefined;
16
+ /** Where the menu lines up with the pair. */
17
+ align?: 'start' | 'center' | 'end' | undefined;
18
+ /** A width of its own for the menu, such as `16rem`. */
19
+ menuWidth?: string | undefined;
20
+ /** Whether the menu is open. Bindable. */
21
+ open?: boolean | undefined;
22
+ /** On the group, which holds both halves. */
23
+ sx?: Sx | undefined;
24
+ /** The main button's label, and its icon if it has one. */
25
+ children?: Snippet | undefined;
26
+ };
27
+ declare const SplitButton: import("svelte").Component<SplitButtonProps, {}, "ref" | "open">;
28
+ type SplitButton = ReturnType<typeof SplitButton>;
29
+ export default SplitButton;
@@ -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,8 @@
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 { TabDragging, tabOffset } from './drag.svelte.js';
20
26
  import { attrs, type Sx } from '../../internal/sx.js';
21
27
  import { colors, font, motion, radius } from '../../tokens.stylex.js';
22
28
  import { media } from '../../media.stylex.js';
@@ -24,8 +30,16 @@
24
30
  export type TabStripTab = {
25
31
  id: string;
26
32
  label: string;
33
+ /** The tab's name in full, as a tooltip, where the label is short. Defaults to the label. */
34
+ title?: string | undefined;
27
35
  /** Shown in place of the close button until the pointer is on the tab: unsaved, or live. */
28
36
  mark?: 'unsaved' | 'live' | undefined;
37
+ /** The DOM id of the tab, for its panel's `aria-labelledby`. */
38
+ tabId?: string | undefined;
39
+ /** The id of this tab's own panel, in place of the strip's `controls`. */
40
+ panelId?: string | undefined;
41
+ /** With `onrename`, whether this tab can be renamed. Defaults to true. */
42
+ renamable?: boolean | undefined;
29
43
  };
30
44
 
31
45
  export type TabStripProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'onclose'> & {
@@ -45,6 +59,33 @@
45
59
  closeLabel?: ((tab: TabStripTab) => string) | undefined;
46
60
  /** Before a tab's label: an icon, or a StatusIndicator. */
47
61
  leading?: Snippet<[TabStripTab]> | undefined;
62
+ /**
63
+ * Buttons of a tab's own, after its label and before its close button: one that mutes a
64
+ * page, say. Keep them few and small: an `xs` or `micro` icon-only Button.
65
+ */
66
+ trailing?: Snippet<[TabStripTab]> | undefined;
67
+ /**
68
+ * A tab's menu, of Menu parts: Move left, Rename, Close. It opens on a right-click, on
69
+ * Shift+F10 or the menu key, and on a long press on a touch screen.
70
+ */
71
+ menu?: Snippet<[TabStripTab]> | undefined;
72
+ /**
73
+ * Called as a tab is dropped into another place, with its id and the index it goes to
74
+ * among the tabs. Without it the tabs cannot be dragged. Alt+Shift with an arrow moves
75
+ * the focused tab too.
76
+ */
77
+ onmove?: ((id: string, index: number) => void) | undefined;
78
+ /**
79
+ * 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.
81
+ */
82
+ onrename?: ((id: string, label: string) => void) | undefined;
83
+ /** The id of the tab being renamed. Bindable: set it from a menu's Rename. */
84
+ renaming?: string | undefined;
85
+ /** The name of a tab's field while it is renamed. */
86
+ renameLabel?: ((tab: TabStripTab) => string) | undefined;
87
+ /** The id of a tab shown beside the open one, as in a split view: it is lit, as under the pointer. */
88
+ beside?: string | undefined;
48
89
  sx?: Sx | undefined;
49
90
  };
50
91
 
@@ -90,10 +131,32 @@
90
131
  default: colors.textMuted,
91
132
  [HOVER]: { default: null, [media.hover]: colors.text }
92
133
  },
134
+ // Moved aside while another is dragged
135
+ translate: 'var(--narvi-tab-offset, 0px) 0',
93
136
  transitionProperty: 'background-color, color',
94
137
  transitionDuration: motion.fast,
95
138
  transitionTimingFunction: 'ease'
96
139
  },
140
+ // Beside the open one, in a split view: lit, as under the pointer
141
+ beside: { backgroundColor: colors.fillHover, color: colors.text },
142
+ // The others slide aside, and a dropped tab settles, quickly; the dragged one follows
143
+ // the pointer as it moves
144
+ sliding: {
145
+ transitionProperty: {
146
+ default: 'background-color, color',
147
+ [media.motion]: 'translate, background-color, color'
148
+ },
149
+ transitionDuration: motion.base,
150
+ transitionTimingFunction: motion.easeOut
151
+ },
152
+ // Picked up, it floats over the strip, so it takes the one shadow
153
+ lifted: {
154
+ zIndex: 10,
155
+ cursor: 'grabbing',
156
+ backgroundColor: { default: colors.bgRaised, [HOVER]: colors.bgRaised },
157
+ color: colors.text,
158
+ boxShadow: `inset 0 0 0 1px ${colors.border}, 0 4px 12px -2px ${colors.shadow}`
159
+ },
97
160
  // The open tab: a fill, as the open row of a list has
98
161
  selected: {
99
162
  backgroundColor: { default: colors.fillSelected, [HOVER]: colors.fillSelected },
@@ -128,6 +191,35 @@
128
191
  },
129
192
  // A tab that can be closed keeps room at its end for the button
130
193
  closable: { paddingInlineEnd: '1.625rem' },
194
+ // With buttons of its own, the room for the close button is kept after them
195
+ buttonBeforeTrailing: { paddingInlineEnd: '0.375rem' },
196
+ trailing: {
197
+ display: 'flex',
198
+ alignItems: 'center',
199
+ gap: '0.125rem',
200
+ flexShrink: 0,
201
+ paddingInlineEnd: '0.25rem'
202
+ },
203
+ trailingBeforeEnd: { paddingInlineEnd: '1.5rem' },
204
+ // The name, typed in place
205
+ rename: {
206
+ boxSizing: 'border-box',
207
+ flexGrow: 1,
208
+ width: '8rem',
209
+ minWidth: 0,
210
+ height: '1.25rem',
211
+ marginInline: '0.25rem',
212
+ paddingInline: '0.375rem',
213
+ borderWidth: 0,
214
+ borderRadius: radius.item,
215
+ backgroundColor: colors.bgRaised,
216
+ boxShadow: `inset 0 0 0 1px ${colors.focusRing}`,
217
+ color: colors.text,
218
+ fontFamily: 'inherit',
219
+ fontSize: font.sizeMeta,
220
+ fontWeight: font.weightRegular,
221
+ outlineStyle: 'none'
222
+ },
131
223
  text: { minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
132
224
  leading: { display: 'grid', flexShrink: 0 },
133
225
  // With a leading icon, the close button and a mark take the icon's place: the icon
@@ -265,6 +357,13 @@
265
357
  addLabel = 'New tab',
266
358
  closeLabel = (tab) => `Close ${tab.label}`,
267
359
  leading,
360
+ trailing,
361
+ menu,
362
+ onmove,
363
+ onrename,
364
+ renaming = $bindable(),
365
+ renameLabel = (tab) => `Name of ${tab.label}`,
366
+ beside,
268
367
  sx,
269
368
  class: className,
270
369
  ...rest
@@ -272,14 +371,35 @@
272
371
 
273
372
  let list = $state<HTMLElement | null>(null);
274
373
 
275
- // The open tab stays in view as tabs come, go and are chosen
374
+ const tabElements = () => [
375
+ ...(list?.querySelectorAll<HTMLElement>('[data-slot="tab-strip-tab"]') ?? [])
376
+ ];
377
+ const tabButton = (id: string) =>
378
+ tabElements()
379
+ .find((element) => element.dataset.tabId === id)
380
+ ?.querySelector<HTMLElement>('[role="tab"]') ?? null;
381
+
382
+ const dragging = new TabDragging(
383
+ tabElements,
384
+ () => list,
385
+ (from, to) => {
386
+ const tab = tabs[from];
387
+ if (tab) onmove?.(tab.id, to);
388
+ }
389
+ );
390
+ $effect(() => () => dragging.dispose());
391
+ const drag = $derived(dragging.drag);
392
+
393
+ // The open tab stays in view as tabs come, go and are chosen, and so does one being renamed
276
394
  $effect(() => {
277
395
  void value;
278
396
  void tabs.length;
397
+ const named = renaming;
279
398
  tick().then(() =>
280
- list
281
- ?.querySelector<HTMLElement>('[role="tab"][aria-selected="true"]')
282
- ?.scrollIntoView({ block: 'nearest', inline: 'nearest' })
399
+ (named
400
+ ? list?.querySelector<HTMLElement>('[data-renaming]')
401
+ : list?.querySelector<HTMLElement>('[role="tab"][aria-selected="true"]')
402
+ )?.scrollIntoView({ block: 'nearest', inline: 'nearest' })
283
403
  );
284
404
  });
285
405
 
@@ -294,111 +414,235 @@
294
414
  (buttons?.[Math.min(index, (buttons?.length ?? 1) - 1)] ?? null)?.focus();
295
415
  });
296
416
  }
417
+
418
+ // The menu's trigger would make the tab's frame focusable; the tab inside is what takes focus
419
+ function withoutTabStop(props: Record<string, unknown>) {
420
+ const { tabindex: _, ...others } = props;
421
+ void _;
422
+ return others;
423
+ }
424
+
425
+ const renamable = (tab: TabStripTab) => !!onrename && tab.renamable !== false;
426
+
427
+ function startRename(tab: TabStripTab) {
428
+ if (renamable(tab)) renaming = tab.id;
429
+ }
430
+
431
+ // Enter keeps the name typed; Escape, or leaving the field, keeps the old one
432
+ function endRename(tab: TabStripTab, name: string | null, refocus: boolean) {
433
+ if (renaming !== tab.id) return;
434
+ renaming = undefined;
435
+ const next = name?.trim();
436
+ if (next) onrename?.(tab.id, next);
437
+ if (refocus) tick().then(() => tabButton(tab.id)?.focus());
438
+ }
439
+
440
+ // The field takes the focus, with its words chosen, so typing replaces them
441
+ const selectAll = (input: HTMLInputElement) => {
442
+ input.focus();
443
+ input.select();
444
+ };
445
+
446
+ function moveByKey(tab: TabStripTab, event: KeyboardEvent) {
447
+ if (!onmove || !event.altKey || !event.shiftKey) return false;
448
+ if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') return false;
449
+ const rtl = list ? getComputedStyle(list).direction === 'rtl' : false;
450
+ const later = (event.key === 'ArrowRight') !== rtl;
451
+ const index = tabs.indexOf(tab);
452
+ const to = later ? index + 1 : index - 1;
453
+ event.preventDefault();
454
+ if (to < 0 || to >= tabs.length) return true;
455
+ onmove(tab.id, to);
456
+ // The tab keeps the focus in its new place
457
+ tick().then(() => tabButton(tab.id)?.focus());
458
+ return true;
459
+ }
297
460
  </script>
298
461
 
299
- <div data-slot="tab-strip" {...rest} {...attrs([styles.root, sx], className)}>
462
+ {#snippet tabView(tab: TabStripTab, index: number, trigger: Record<string, unknown>)}
463
+ {@const selected = tab.id === value}
464
+ {@const lifted = !!drag && drag.from === index && !drag.settling}
465
+ {@const editing = renaming === tab.id && renamable(tab)}
466
+ {@const { onpointerdown: menuPointerDown, ...triggerRest } = withoutTabStop(trigger)}
300
467
  <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' })}
468
+ {...triggerRest}
469
+ data-slot="tab-strip-tab"
470
+ data-tab-id={tab.id}
471
+ data-renaming={editing || undefined}
472
+ data-lifted={lifted || undefined}
473
+ style:--narvi-tab-offset={drag ? `${tabOffset(drag, index)}px` : undefined}
474
+ onpointerdown={(event) => {
475
+ // The menu's own, which opens it on a long press on a touch screen
476
+ if (typeof menuPointerDown === 'function') menuPointerDown(event);
477
+ if (onmove && !editing) dragging.press(index, event);
478
+ }}
479
+ {...stylex.attrs(
480
+ styles.tab,
481
+ tab.id === beside && !selected && styles.beside,
482
+ selected && styles.selected,
483
+ drag && !lifted && styles.sliding,
484
+ lifted && styles.lifted,
485
+ tabStripTabMarker
486
+ )}
307
487
  >
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)}
488
+ {#if editing}
489
+ <input
490
+ {@attach selectAll}
491
+ aria-label={renameLabel(tab)}
492
+ value={tab.label}
493
+ onkeydown={(event) => {
494
+ if (event.key !== 'Enter' && event.key !== 'Escape') return;
495
+ // Its own keys, not the strip's, a dialog's or the window's
496
+ event.preventDefault();
497
+ event.stopPropagation();
498
+ endRename(tab, event.key === 'Enter' ? event.currentTarget.value : null, true);
499
+ }}
500
+ onblur={() => endRename(tab, null, false)}
501
+ {...stylex.attrs(styles.rename)}
502
+ />
503
+ {:else}
504
+ <button
505
+ type="button"
506
+ role="tab"
507
+ id={tab.tabId}
508
+ aria-selected={selected}
509
+ aria-controls={tab.panelId ?? controls}
510
+ aria-current={selected ? 'true' : undefined}
511
+ title={tab.title ?? tab.label}
512
+ {...stylex.attrs(
513
+ styles.button,
514
+ onclose && !leading && !trailing && styles.closable,
515
+ trailing && styles.buttonBeforeTrailing
516
+ )}
517
+ onclick={() => (value = tab.id)}
518
+ ondblclick={() => startRename(tab)}
519
+ onauxclick={(event) => {
520
+ // The middle button closes, as it does in a browser
521
+ if (event.button === 1) close(tab);
522
+ }}
523
+ onkeydown={(event) => {
524
+ if (moveByKey(tab, event)) return;
525
+ if (event.key === 'F2' && renamable(tab)) {
526
+ event.preventDefault();
527
+ startRename(tab);
528
+ return;
529
+ }
530
+ if (!onclose || (event.key !== 'Delete' && event.key !== 'Backspace')) return;
531
+ event.preventDefault();
532
+ close(tab, true);
533
+ }}
534
+ >
535
+ {#if leading}
536
+ <span {...stylex.attrs(styles.leadCell)}>
537
+ {#if tab.mark}
538
+ <span
539
+ aria-hidden="true"
540
+ {...stylex.attrs(
541
+ styles.mark,
542
+ styles.markStill,
543
+ styles.leadMark,
544
+ tab.mark === 'live' && styles.live,
545
+ onclose && styles.leadIcon,
546
+ onclose && selected && styles.leadIconSelected
547
+ )}
548
+ ></span>
549
+ {:else}
550
+ <span
551
+ {...stylex.attrs(
552
+ styles.leading,
553
+ onclose && styles.leadIcon,
554
+ onclose && selected && styles.leadIconSelected
555
+ )}>{@render leading(tab)}</span
556
+ >
557
+ {/if}
558
+ </span>
559
+ {/if}
560
+ <span {...stylex.attrs(styles.text)}>{tab.label}</span>
561
+ {#if tab.mark}<span {...stylex.attrs(visuallyHidden)}
562
+ >, {tab.mark === 'live' ? 'working' : 'unsaved'}</span
563
+ >{/if}
564
+ </button>
565
+ {/if}
566
+ {#if trailing}
567
+ <span
568
+ {...stylex.attrs(
569
+ styles.trailing,
570
+ !leading && (onclose || tab.mark) && styles.trailingBeforeEnd
571
+ )}>{@render trailing(tab)}</span
313
572
  >
573
+ {/if}
574
+ {#if leading && onclose}
575
+ <span {...stylex.attrs(styles.start)}>
314
576
  <button
315
577
  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
- }}
578
+ tabindex="-1"
579
+ aria-label={closeLabel(tab)}
580
+ {...stylex.attrs(styles.close, selected ? styles.closeLeadSelected : styles.closeLead)}
581
+ onclick={() => close(tab)}
332
582
  >
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}
583
+ <Glyph name="close" size={12} />
362
584
  </button>
363
- {#if leading && onclose}
364
- <span {...stylex.attrs(styles.start)}>
585
+ </span>
586
+ {:else if onclose || tab.mark}
587
+ <span {...stylex.attrs(styles.end)}>
588
+ {#if tab.mark}
589
+ <span
590
+ aria-hidden="true"
591
+ {...stylex.attrs(styles.mark, tab.mark === 'live' && styles.live)}
592
+ ></span>
593
+ {/if}
594
+ {#if onclose}
595
+ <span {...stylex.attrs(styles.closeCell)}>
365
596
  <button
366
597
  type="button"
367
598
  tabindex="-1"
368
599
  aria-label={closeLabel(tab)}
369
- {...stylex.attrs(
370
- styles.close,
371
- selected ? styles.closeLeadSelected : styles.closeLead
372
- )}
600
+ {...stylex.attrs(styles.close, selected && !tab.mark && styles.closeShown)}
373
601
  onclick={() => close(tab)}
374
602
  >
375
603
  <Glyph name="close" size={12} />
376
604
  </button>
377
605
  </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
606
  {/if}
401
- </div>
607
+ </span>
608
+ {/if}
609
+ </div>
610
+ {/snippet}
611
+
612
+ <div
613
+ data-slot="tab-strip"
614
+ data-dragging={drag ? '' : undefined}
615
+ {...rest}
616
+ {...attrs([styles.root, sx], className)}
617
+ >
618
+ <div
619
+ bind:this={list}
620
+ role="tablist"
621
+ aria-label={label}
622
+ aria-orientation="horizontal"
623
+ {...stylex.attrs(styles.list)}
624
+ {@attach roving({ selector: '[role="tab"]', orientation: 'horizontal' })}
625
+ >
626
+ {#each tabs as tab, index (tab.id)}
627
+ {#if menu}
628
+ <ContextMenu.Root>
629
+ <ContextMenu.Trigger>
630
+ {#snippet child({ props })}{@render tabView(tab, index, props)}{/snippet}
631
+ </ContextMenu.Trigger>
632
+ <!-- Renaming from it, the field keeps the focus the menu would give back -->
633
+ <ContextMenu.Content
634
+ onCloseAutoFocus={(event) => {
635
+ if (renaming !== tab.id) return;
636
+ event.preventDefault();
637
+ list?.querySelector<HTMLInputElement>('[data-renaming] input')?.focus();
638
+ }}
639
+ >
640
+ {@render menu(tab)}
641
+ </ContextMenu.Content>
642
+ </ContextMenu.Root>
643
+ {:else}
644
+ {@render tabView(tab, index, {})}
645
+ {/if}
402
646
  {/each}
403
647
  </div>
404
648
  {#if onadd}
@@ -4,8 +4,16 @@ import { type Sx } from '../../internal/sx.js';
4
4
  export type TabStripTab = {
5
5
  id: string;
6
6
  label: string;
7
+ /** The tab's name in full, as a tooltip, where the label is short. Defaults to the label. */
8
+ title?: string | undefined;
7
9
  /** Shown in place of the close button until the pointer is on the tab: unsaved, or live. */
8
10
  mark?: 'unsaved' | 'live' | undefined;
11
+ /** The DOM id of the tab, for its panel's `aria-labelledby`. */
12
+ tabId?: string | undefined;
13
+ /** The id of this tab's own panel, in place of the strip's `controls`. */
14
+ panelId?: string | undefined;
15
+ /** With `onrename`, whether this tab can be renamed. Defaults to true. */
16
+ renamable?: boolean | undefined;
9
17
  };
10
18
  export type TabStripProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'onclose'> & {
11
19
  tabs: TabStripTab[];
@@ -24,8 +32,35 @@ export type TabStripProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'o
24
32
  closeLabel?: ((tab: TabStripTab) => string) | undefined;
25
33
  /** Before a tab's label: an icon, or a StatusIndicator. */
26
34
  leading?: Snippet<[TabStripTab]> | undefined;
35
+ /**
36
+ * Buttons of a tab's own, after its label and before its close button: one that mutes a
37
+ * page, say. Keep them few and small: an `xs` or `micro` icon-only Button.
38
+ */
39
+ trailing?: Snippet<[TabStripTab]> | undefined;
40
+ /**
41
+ * A tab's menu, of Menu parts: Move left, Rename, Close. It opens on a right-click, on
42
+ * Shift+F10 or the menu key, and on a long press on a touch screen.
43
+ */
44
+ menu?: Snippet<[TabStripTab]> | undefined;
45
+ /**
46
+ * Called as a tab is dropped into another place, with its id and the index it goes to
47
+ * among the tabs. Without it the tabs cannot be dragged. Alt+Shift with an arrow moves
48
+ * the focused tab too.
49
+ */
50
+ onmove?: ((id: string, index: number) => void) | undefined;
51
+ /**
52
+ * 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.
54
+ */
55
+ onrename?: ((id: string, label: string) => void) | undefined;
56
+ /** The id of the tab being renamed. Bindable: set it from a menu's Rename. */
57
+ renaming?: string | undefined;
58
+ /** The name of a tab's field while it is renamed. */
59
+ renameLabel?: ((tab: TabStripTab) => string) | undefined;
60
+ /** The id of a tab shown beside the open one, as in a split view: it is lit, as under the pointer. */
61
+ beside?: string | undefined;
27
62
  sx?: Sx | undefined;
28
63
  };
29
- declare const TabStrip: import("svelte").Component<TabStripProps, {}, "value">;
64
+ declare const TabStrip: import("svelte").Component<TabStripProps, {}, "value" | "renaming">;
30
65
  type TabStrip = ReturnType<typeof TabStrip>;
31
66
  export default TabStrip;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Dragging a tab along a TabStrip into another place: it follows the pointer, the others slide
3
+ * aside to make room, and let go, it settles into its place before the move is made. From
4
+ * Eregion's side panel (`tabDrag.svelte.ts`).
5
+ */
6
+ type Rect = {
7
+ readonly left: number;
8
+ readonly width: number;
9
+ };
10
+ export type TabDrag = {
11
+ /** The place of the tab being dragged, and the place it would drop into. */
12
+ readonly from: number;
13
+ readonly to: number;
14
+ /** How far it has moved, in pixels. */
15
+ readonly dx: number;
16
+ /** Let go, and moving into its place. */
17
+ readonly settling: boolean;
18
+ readonly rects: readonly Rect[];
19
+ };
20
+ /** How far the tab at `index` moves while another is dragged: aside, to make room, or not at all. */
21
+ export declare function tabOffset(drag: TabDrag | null, index: number): number;
22
+ export declare class TabDragging {
23
+ #private;
24
+ drag: TabDrag | null;
25
+ constructor(tabs: () => HTMLElement[], strip: () => HTMLElement | null, onmove: (from: number, to: number) => void);
26
+ /** A press on the tab at `index`, which becomes a drag once the pointer moves far enough. */
27
+ press(index: number, event: PointerEvent): void;
28
+ /** Stops a drop settling, as the strip goes. */
29
+ dispose(): void;
30
+ }
31
+ export {};