dssoca 0.20.0 → 0.21.0

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/README.md +3 -3
  2. package/dist/components/Accordion.svelte +23 -52
  3. package/dist/components/BottomNav.svelte +18 -28
  4. package/dist/components/BoxPlot.svelte +7 -6
  5. package/dist/components/BumpChart.svelte +9 -12
  6. package/dist/components/Chart.svelte +9 -12
  7. package/dist/components/Checkbox.svelte +210 -0
  8. package/dist/components/Checkbox.svelte.d.ts +38 -0
  9. package/dist/components/FileDrop.svelte +52 -83
  10. package/dist/components/FileDrop.svelte.d.ts +6 -2
  11. package/dist/components/Heatmap.svelte +8 -8
  12. package/dist/components/Image.svelte +44 -44
  13. package/dist/components/Input.svelte +8 -3
  14. package/dist/components/LogStream.svelte +15 -25
  15. package/dist/components/Menu.svelte +69 -94
  16. package/dist/components/Menu.svelte.d.ts +6 -0
  17. package/dist/components/Modal.svelte +61 -14
  18. package/dist/components/Modal.svelte.d.ts +7 -2
  19. package/dist/components/NumberField.svelte +18 -19
  20. package/dist/components/Pagination.svelte +47 -37
  21. package/dist/components/Pagination.svelte.d.ts +6 -2
  22. package/dist/components/Popover.svelte +247 -0
  23. package/dist/components/Popover.svelte.d.ts +36 -0
  24. package/dist/components/RadioGroup.svelte +227 -0
  25. package/dist/components/RadioGroup.svelte.d.ts +42 -0
  26. package/dist/components/ScatterPlot.svelte +11 -13
  27. package/dist/components/SearchPalette.svelte +124 -120
  28. package/dist/components/SearchPalette.svelte.d.ts +6 -4
  29. package/dist/components/SegmentedControl.svelte +41 -62
  30. package/dist/components/SegmentedControl.svelte.d.ts +7 -2
  31. package/dist/components/ShortcutsHelp.svelte +48 -47
  32. package/dist/components/Sidebar.svelte +48 -60
  33. package/dist/components/Switch.svelte +20 -10
  34. package/dist/components/Switch.svelte.d.ts +6 -2
  35. package/dist/components/Table.svelte +15 -37
  36. package/dist/components/Tabs.svelte +223 -0
  37. package/dist/components/Tabs.svelte.d.ts +51 -0
  38. package/dist/components/TierList.svelte +38 -38
  39. package/dist/components/TierList.svelte.d.ts +7 -3
  40. package/dist/components/Toaster.svelte +29 -29
  41. package/dist/components/Tooltip.svelte +37 -21
  42. package/dist/components/Topbar.svelte +13 -38
  43. package/dist/core/accordion.d.ts +32 -0
  44. package/dist/core/accordion.js +53 -0
  45. package/dist/core/behaviors/focusable.d.ts +5 -0
  46. package/dist/core/behaviors/focusable.js +14 -0
  47. package/dist/core/behaviors/roving.d.ts +13 -0
  48. package/dist/core/behaviors/roving.js +29 -0
  49. package/dist/core/bottom-nav.d.ts +36 -0
  50. package/dist/core/bottom-nav.js +33 -0
  51. package/dist/core/chart-nav.d.ts +53 -0
  52. package/dist/{chart-nav.js → core/chart-nav.js} +27 -0
  53. package/dist/core/checkbox.d.ts +36 -0
  54. package/dist/core/checkbox.js +29 -0
  55. package/dist/core/file-drop.d.ts +75 -0
  56. package/dist/core/file-drop.js +101 -0
  57. package/dist/core/image.d.ts +59 -0
  58. package/dist/core/image.js +64 -0
  59. package/dist/core/input.d.ts +21 -0
  60. package/dist/core/input.js +17 -0
  61. package/dist/core/log-stream.d.ts +51 -0
  62. package/dist/core/log-stream.js +50 -0
  63. package/dist/core/menu.d.ts +70 -0
  64. package/dist/core/menu.js +84 -0
  65. package/dist/core/modal.d.ts +59 -0
  66. package/dist/core/modal.js +44 -0
  67. package/dist/core/number-field.d.ts +47 -0
  68. package/dist/core/number-field.js +64 -0
  69. package/dist/core/pagination.d.ts +59 -0
  70. package/dist/core/pagination.js +65 -0
  71. package/dist/core/popover.d.ts +68 -0
  72. package/dist/core/popover.js +55 -0
  73. package/dist/core/radio.d.ts +36 -0
  74. package/dist/core/radio.js +48 -0
  75. package/dist/core/search-palette.d.ts +124 -0
  76. package/dist/core/search-palette.js +149 -0
  77. package/dist/core/segmented.d.ts +46 -0
  78. package/dist/core/segmented.js +66 -0
  79. package/dist/core/shortcuts-help.d.ts +56 -0
  80. package/dist/core/shortcuts-help.js +50 -0
  81. package/dist/core/sidebar.d.ts +63 -0
  82. package/dist/core/sidebar.js +84 -0
  83. package/dist/core/switch.d.ts +19 -0
  84. package/dist/core/switch.js +11 -0
  85. package/dist/core/table.d.ts +40 -0
  86. package/dist/core/table.js +57 -0
  87. package/dist/core/tabs.d.ts +84 -0
  88. package/dist/core/tabs.js +90 -0
  89. package/dist/{tierlist-core.d.ts → core/tierlist.d.ts} +62 -0
  90. package/dist/{tierlist-core.js → core/tierlist.js} +34 -0
  91. package/dist/core/toast.d.ts +112 -0
  92. package/dist/{toast-core.js → core/toast.js} +48 -2
  93. package/dist/core/tooltip.d.ts +47 -0
  94. package/dist/core/tooltip.js +51 -0
  95. package/dist/core/topbar.d.ts +41 -0
  96. package/dist/core/topbar.js +52 -0
  97. package/dist/dssoca.config.d.ts +1 -1
  98. package/dist/dssoca.config.js +4 -0
  99. package/dist/index.d.ts +14 -1
  100. package/dist/index.js +9 -1
  101. package/dist/theme.css +47 -0
  102. package/dist/toast.svelte.d.ts +2 -2
  103. package/dist/toast.svelte.js +1 -1
  104. package/dist/tokens.css +47 -0
  105. package/dist/vanilla/accordion.js +28 -29
  106. package/dist/vanilla/checkbox.d.ts +8 -0
  107. package/dist/vanilla/checkbox.js +43 -0
  108. package/dist/vanilla/delegate.d.ts +2 -0
  109. package/dist/vanilla/delegate.js +9 -0
  110. package/dist/vanilla/fields.js +37 -32
  111. package/dist/vanilla/index.d.ts +4 -0
  112. package/dist/vanilla/index.js +16 -3
  113. package/dist/vanilla/menu.js +92 -86
  114. package/dist/vanilla/modal.d.ts +3 -1
  115. package/dist/vanilla/modal.js +65 -15
  116. package/dist/vanilla/popover.d.ts +10 -0
  117. package/dist/vanilla/popover.js +129 -0
  118. package/dist/vanilla/radio.d.ts +3 -0
  119. package/dist/vanilla/radio.js +54 -0
  120. package/dist/vanilla/segmented.js +49 -51
  121. package/dist/vanilla/switch.d.ts +2 -1
  122. package/dist/vanilla/switch.js +13 -8
  123. package/dist/vanilla/tabs.d.ts +2 -0
  124. package/dist/vanilla/tabs.js +87 -0
  125. package/dist/vanilla/tierlist.d.ts +1 -1
  126. package/dist/vanilla/tierlist.js +29 -25
  127. package/dist/vanilla/toast.d.ts +2 -2
  128. package/dist/vanilla/toast.js +16 -14
  129. package/dist/vanilla/tooltip.js +35 -23
  130. package/dist/vanilla.css +349 -42
  131. package/package.json +1 -1
  132. package/dist/chart-nav.d.ts +0 -13
  133. package/dist/toast-core.d.ts +0 -61
@@ -0,0 +1,223 @@
1
+ <script module lang="ts">
2
+ import type { IconName } from './Icon.svelte'
3
+
4
+ /** One tab in a {@link Tabs} list. */
5
+ export interface TabItem {
6
+ /** Stable identifier — matched against `value` and passed to `onChange`. */
7
+ id: string
8
+ /** Tab text (also its accessible name, and the name of its panel). */
9
+ label: string
10
+ /** Optional leading glyph. */
11
+ icon?: IconName
12
+ /** Disabled tabs are skipped by keyboard navigation and not selectable. */
13
+ disabled?: boolean
14
+ }
15
+ </script>
16
+
17
+ <script lang="ts">
18
+ // ─────────────────────────────────────────────────────────────────────────
19
+ // Tabs — DS-0197. The WAI-ARIA tabs pattern: a `role="tablist"` that is ONE
20
+ // tab stop (roving tabindex; arrows / Home / End, mirrored under RTL) over a
21
+ // set of `role="tabpanel"` regions, one per tab, of which only the selected
22
+ // one is shown. Every decision is made in `core/tabs.ts`, shared with
23
+ // vanilla/tabs.ts.
24
+ // ─────────────────────────────────────────────────────────────────────────
25
+ import type { Snippet } from 'svelte'
26
+ import Icon from './Icon.svelte'
27
+ import { resolveComponentSize, type Size } from '../config.js'
28
+ import {
29
+ tabsKey,
30
+ tabsListAttrs,
31
+ tabsPanelAttrs,
32
+ tabsPress,
33
+ tabsSelected,
34
+ tabsTabAttrs,
35
+ tabsTabStop,
36
+ type TabsAction,
37
+ type TabsActivation,
38
+ type TabsChangeDetails,
39
+ type TabsState,
40
+ } from '../core/tabs.js'
41
+
42
+ interface Props {
43
+ /** The tabs, in order: { id, label, icon?, disabled? }. */
44
+ tabs?: TabItem[]
45
+ /**
46
+ * Id of the selected tab (bindable). When it matches no tab, the first
47
+ * enabled tab is shown.
48
+ */
49
+ value?: string
50
+ /**
51
+ * Fired when the selection changes (after `value` updates). `details.reason`
52
+ * says what moved it: `'press'` (a tab was clicked) or `'key'` (arrows /
53
+ * Home / End, or Enter / Space with manual activation).
54
+ */
55
+ onChange?: (value: string, details: TabsChangeDetails) => void
56
+ /**
57
+ * How the keyboard selects. `'auto'` (default): the tab that takes focus is
58
+ * selected. `'manual'`: arrows only move focus, Enter / Space select — use
59
+ * it when showing a panel is expensive.
60
+ */
61
+ activation?: TabsActivation
62
+ /**
63
+ * Accessible name for the tab list. Required (WCAG 2.2 AA): an unnamed
64
+ * tablist leaves AT users without context for the choice.
65
+ */
66
+ label: string
67
+ /** Token size (sm|md|lg); inherits the global size when unset. */
68
+ size?: Size
69
+ /**
70
+ * Content of the selected tab's panel; receives the active tab.
71
+ * {#snippet panel(tab)} … {/snippet}
72
+ */
73
+ panel?: Snippet<[TabItem]>
74
+ }
75
+
76
+ let {
77
+ tabs = [],
78
+ value = $bindable(),
79
+ onChange,
80
+ activation = 'auto',
81
+ label,
82
+ size,
83
+ panel,
84
+ }: Props = $props()
85
+
86
+ const uid = $props.id()
87
+ const tabId = (i: number) => `${uid}-tab-${i}`
88
+ const panelId = (i: number) => `${uid}-panel-${i}`
89
+
90
+ let tabEls = $state<(HTMLButtonElement | undefined)[]>([])
91
+
92
+ const enabled = $derived(tabs.map((t, i) => (t.disabled ? -1 : i)).filter((i) => i >= 0))
93
+
94
+ // The list's state as `core/tabs.ts` sees it.
95
+ const list = $derived<TabsState>({
96
+ selected: tabsSelected(
97
+ tabs.findIndex((t) => t.id === value),
98
+ enabled,
99
+ ),
100
+ enabled,
101
+ })
102
+
103
+ const tabStop = $derived(tabsTabStop(list))
104
+
105
+ /** Apply a core action: move the selection and / or the focus. */
106
+ function run(action: TabsAction | null) {
107
+ if (!action) return
108
+ if (action.type === 'select') {
109
+ const tab = tabs[action.index]
110
+ if (action.changed && tab) {
111
+ value = tab.id
112
+ onChange?.(tab.id, { reason: action.reason })
113
+ }
114
+ if (!action.focus) return
115
+ }
116
+ tabEls[action.index]?.focus()
117
+ }
118
+
119
+ function onKeydown(e: KeyboardEvent, index: number) {
120
+ // RTL: the list is laid out right-to-left, so ArrowLeft points at the NEXT
121
+ // tab. Read the computed direction at keydown time (it inherits from any
122
+ // ancestor `dir`) and hand it to the core, which stays DOM-free.
123
+ const rtl = getComputedStyle(e.currentTarget as Element).direction === 'rtl'
124
+ const result = tabsKey(list, index, e.key, { rtl, activation })
125
+ if (!result) return
126
+ if (result.preventDefault) e.preventDefault()
127
+ run(result.action)
128
+ }
129
+
130
+ const sizeAttr = $derived(resolveComponentSize('Tabs', size))
131
+ </script>
132
+
133
+ <div class="ss-tabs" data-size-variant={sizeAttr} data-activation={activation}>
134
+ <div class="list" aria-label={label} {...tabsListAttrs()}>
135
+ {#each tabs as tab, i (tab.id)}
136
+ <button
137
+ bind:this={tabEls[i]}
138
+ id={tabId(i)}
139
+ type="button"
140
+ class="tab"
141
+ class:selected={i === list.selected}
142
+ {...tabsTabAttrs({
143
+ index: i,
144
+ selected: list.selected,
145
+ tabStop,
146
+ panelId: panelId(i),
147
+ })}
148
+ disabled={tab.disabled}
149
+ onclick={() => run(tabsPress(list, i))}
150
+ onkeydown={(e) => onKeydown(e, i)}
151
+ >
152
+ {#if tab.icon}<Icon name={tab.icon} size={sizeAttr} />{/if}
153
+ <span class="label">{tab.label}</span>
154
+ </button>
155
+ {/each}
156
+ </div>
157
+
158
+ <!-- One panel per tab (the plain-HTML contract); only the selected one is shown and filled. -->
159
+ {#each tabs as tab, i (tab.id)}
160
+ {@const active = i === list.selected}
161
+ <div id={panelId(i)} class="panel" {...tabsPanelAttrs(tabId(i))} hidden={!active}>
162
+ {#if active}{@render panel?.(tab)}{/if}
163
+ </div>
164
+ {/each}
165
+ </div>
166
+
167
+ <style>.ss-tabs {
168
+ display: flex;
169
+ flex-direction: column;
170
+ min-width: 0;
171
+ }
172
+
173
+ .list {
174
+ display: flex;
175
+ align-items: stretch;
176
+ min-width: 0;
177
+ overflow-x: auto;
178
+ scrollbar-width: thin;
179
+ box-shadow: inset 0 -1px 0 var(--ss-line);
180
+ }
181
+
182
+ .tab {
183
+ display: inline-flex;
184
+ align-items: center;
185
+ flex: none;
186
+ gap: var(--ss-tabs-gap);
187
+ min-block-size: var(--ss-s-6);
188
+ padding: var(--ss-tabs-py) var(--ss-tabs-px);
189
+ font: 500 var(--ss-tabs-font) var(--ss-font-mono);
190
+ white-space: nowrap;
191
+ color: var(--ss-fg-muted);
192
+ background: transparent;
193
+ border: 0;
194
+ cursor: pointer;
195
+ transition: color var(--ss-dur-fast) var(--ss-ease), background var(--ss-dur-fast) var(--ss-ease), box-shadow var(--ss-dur-fast) var(--ss-ease);
196
+ }
197
+ .tab:hover:not(:disabled) {
198
+ color: var(--ss-fg);
199
+ background: var(--ss-hover);
200
+ }
201
+ .tab.selected {
202
+ color: var(--ss-fg);
203
+ background: color-mix(in srgb, var(--ss-accent) 6%, transparent);
204
+ box-shadow: inset 0 -2px 0 var(--ss-primary);
205
+ }
206
+ .tab:focus-visible {
207
+ outline-offset: -2px;
208
+ }
209
+ .tab:disabled {
210
+ color: var(--ss-fg-faint);
211
+ cursor: not-allowed;
212
+ }
213
+
214
+ .panel {
215
+ padding-block: var(--ss-tabs-panel-py);
216
+ min-width: 0;
217
+ }
218
+ .panel[hidden] {
219
+ display: none;
220
+ }
221
+ .panel:focus-visible {
222
+ outline-offset: -2px;
223
+ }</style>
@@ -0,0 +1,51 @@
1
+ import type { IconName } from './Icon.svelte';
2
+ /** One tab in a {@link Tabs} list. */
3
+ export interface TabItem {
4
+ /** Stable identifier — matched against `value` and passed to `onChange`. */
5
+ id: string;
6
+ /** Tab text (also its accessible name, and the name of its panel). */
7
+ label: string;
8
+ /** Optional leading glyph. */
9
+ icon?: IconName;
10
+ /** Disabled tabs are skipped by keyboard navigation and not selectable. */
11
+ disabled?: boolean;
12
+ }
13
+ import type { Snippet } from 'svelte';
14
+ import { type Size } from '../config.js';
15
+ import { type TabsActivation, type TabsChangeDetails } from '../core/tabs.js';
16
+ interface Props {
17
+ /** The tabs, in order: { id, label, icon?, disabled? }. */
18
+ tabs?: TabItem[];
19
+ /**
20
+ * Id of the selected tab (bindable). When it matches no tab, the first
21
+ * enabled tab is shown.
22
+ */
23
+ value?: string;
24
+ /**
25
+ * Fired when the selection changes (after `value` updates). `details.reason`
26
+ * says what moved it: `'press'` (a tab was clicked) or `'key'` (arrows /
27
+ * Home / End, or Enter / Space with manual activation).
28
+ */
29
+ onChange?: (value: string, details: TabsChangeDetails) => void;
30
+ /**
31
+ * How the keyboard selects. `'auto'` (default): the tab that takes focus is
32
+ * selected. `'manual'`: arrows only move focus, Enter / Space select — use
33
+ * it when showing a panel is expensive.
34
+ */
35
+ activation?: TabsActivation;
36
+ /**
37
+ * Accessible name for the tab list. Required (WCAG 2.2 AA): an unnamed
38
+ * tablist leaves AT users without context for the choice.
39
+ */
40
+ label: string;
41
+ /** Token size (sm|md|lg); inherits the global size when unset. */
42
+ size?: Size;
43
+ /**
44
+ * Content of the selected tab's panel; receives the active tab.
45
+ * {#snippet panel(tab)} … {/snippet}
46
+ */
47
+ panel?: Snippet<[TabItem]>;
48
+ }
49
+ declare const Tabs: import("svelte").Component<Props, {}, "value">;
50
+ type Tabs = ReturnType<typeof Tabs>;
51
+ export default Tabs;
@@ -6,7 +6,7 @@
6
6
  TierListTier as CoreTier,
7
7
  TierListItem as CoreItem,
8
8
  TierListPlacements as CorePlacements,
9
- } from '../tierlist-core.js'
9
+ } from '../core/tierlist.js'
10
10
  export type TierListTier = CoreTier
11
11
  export type TierListItem = CoreItem
12
12
  export type TierListPlacements = CorePlacements
@@ -43,15 +43,20 @@
43
43
  announceText,
44
44
  buildZones,
45
45
  insertionIndex,
46
- keyMoveFor,
47
46
  keyboardTarget,
48
47
  locate,
49
48
  moveItem,
50
49
  placementsOf,
51
50
  tierColor,
51
+ tierListClickSelects,
52
+ tierListDragStarts,
53
+ tierListPressArmsDrag,
54
+ tierListTileKey,
52
55
  zonesEqual,
56
+ type TierListChangeDetails,
57
+ type TierListChangeReason,
53
58
  type TierListZones,
54
- } from '../tierlist-core.js'
59
+ } from '../core/tierlist.js'
55
60
 
56
61
  interface Props {
57
62
  /** The rows, top to bottom. Defaults to S / A / B / C / D. */
@@ -63,8 +68,11 @@
63
68
  * order itself; the tray is never part of it.
64
69
  */
65
70
  placements?: TierListPlacements
66
- /** Fired after every drop / keyboard drop with the new placements. */
67
- onchange?: (placements: TierListPlacements) => void
71
+ /**
72
+ * Fired after every drop / keyboard drop with the new placements. `details.reason` says
73
+ * what committed it: `'pointer'` (a drag) or `'keyboard'` (Space / Enter drop).
74
+ */
75
+ onchange?: (placements: TierListPlacements, details: TierListChangeDetails) => void
68
76
  /**
69
77
  * Activation (Enter, or a click that isn't a drag) — e.g. open a details view.
70
78
  * When omitted, Enter picks the tile up like Space.
@@ -120,11 +128,11 @@
120
128
  return it ? [it] : []
121
129
  })
122
130
 
123
- function commit(next: TierListZones) {
131
+ function commit(next: TierListZones, reason: TierListChangeReason) {
124
132
  zones = next
125
133
  const p = placementsOf(next, tiers)
126
134
  if (placements !== undefined) placements = p
127
- onchange?.(p)
135
+ onchange?.(p, { reason })
128
136
  }
129
137
 
130
138
  function describe(id: string) {
@@ -151,7 +159,7 @@
151
159
  const origin = grabbed.origin
152
160
  grabbed = null
153
161
  announce(announceText('drop', describe(id)))
154
- if (!zonesEqual(origin, zones)) commit(zones)
162
+ if (!zonesEqual(origin, zones)) commit(zones, 'keyboard')
155
163
  return
156
164
  }
157
165
  grabbed = { id, origin: zones }
@@ -181,27 +189,22 @@
181
189
  }
182
190
 
183
191
  function onTileKeydown(e: KeyboardEvent, item: TierListItem) {
184
- if (readonly) return
185
- if (e.key === ' ' || (e.key === 'Enter' && !onselect)) {
186
- e.preventDefault()
187
- toggleGrab(item.id)
188
- return
189
- }
190
- if (e.key === 'Enter') {
191
- e.preventDefault()
192
- onselect?.(item)
193
- return
194
- }
195
- if (grabbed?.id !== item.id) return
196
- if (e.key === 'Escape') {
197
- e.preventDefault()
198
- cancelGrab(true)
199
- return
200
- }
201
- const move = keyMoveFor(e.key, isRtl(e.currentTarget as Element))
202
- if (!move) return
203
- e.preventDefault()
204
- const target = keyboardTarget(zones, zoneOrder, item.id, move)
192
+ const result = tierListTileKey(
193
+ {
194
+ readonly,
195
+ grabbed: grabbed?.id === item.id,
196
+ select: onselect ? 'callback' : 'none',
197
+ rtl: isRtl(e.currentTarget as Element),
198
+ },
199
+ e.key,
200
+ )
201
+ if (!result) return
202
+ if (result.preventDefault) e.preventDefault()
203
+ const { action } = result
204
+ if (action.type === 'toggle') return toggleGrab(item.id)
205
+ if (action.type === 'select') return onselect?.(item)
206
+ if (action.type === 'cancel') return cancelGrab(true)
207
+ const target = keyboardTarget(zones, zoneOrder, item.id, action.move)
205
208
  if (!target) return
206
209
  zones = moveItem(zones, item.id, target.zone, target.index)
207
210
  announce(announceText('move', describe(item.id)))
@@ -240,7 +243,6 @@
240
243
  }
241
244
  let drag = $state<Drag | null>(null)
242
245
  let root: HTMLElement | undefined = $state()
243
- const DRAG_THRESHOLD = 4
244
246
  let suppressClick = false
245
247
 
246
248
  // The drag listens on `window`, not the tile: the live preview moves the
@@ -259,7 +261,7 @@
259
261
  $effect(() => unlisten)
260
262
 
261
263
  function onPointerDown(e: PointerEvent, item: TierListItem) {
262
- if (readonly || e.button !== 0 || grabbed) return
264
+ if (!tierListPressArmsDrag({ readonly, button: e.button, grabbing: grabbed !== null })) return
263
265
  const tileEl = e.currentTarget as HTMLElement
264
266
  const rect = tileEl.getBoundingClientRect()
265
267
  listen()
@@ -293,7 +295,7 @@
293
295
  function onPointerMove(e: PointerEvent) {
294
296
  if (!drag) return
295
297
  if (!drag.active) {
296
- if (Math.hypot(e.clientX - drag.startX, e.clientY - drag.startY) < DRAG_THRESHOLD) return
298
+ if (!tierListDragStarts(e.clientX - drag.startX, e.clientY - drag.startY)) return
297
299
  drag.active = true
298
300
  }
299
301
  e.preventDefault()
@@ -323,7 +325,7 @@
323
325
  suppressClick = true
324
326
  if (zonesEqual(d.origin, zones)) return
325
327
  announce(announceText('drop', describe(d.id)))
326
- commit(zones)
328
+ commit(zones, 'pointer')
327
329
  }
328
330
 
329
331
  function onPointerCancel() {
@@ -335,11 +337,9 @@
335
337
  }
336
338
 
337
339
  function onTileClick(item: TierListItem) {
338
- if (suppressClick) {
339
- suppressClick = false
340
- return
341
- }
342
- if (!readonly) onselect?.(item)
340
+ const afterDrag = suppressClick
341
+ suppressClick = false
342
+ if (tierListClickSelects({ readonly, afterDrag })) onselect?.(item)
343
343
  }
344
344
 
345
345
  const draggedItem = $derived(drag?.active ? byId.get(drag.id) : undefined)
@@ -1,9 +1,10 @@
1
- import type { TierListTier as CoreTier, TierListItem as CoreItem, TierListPlacements as CorePlacements } from '../tierlist-core.js';
1
+ import type { TierListTier as CoreTier, TierListItem as CoreItem, TierListPlacements as CorePlacements } from '../core/tierlist.js';
2
2
  export type TierListTier = CoreTier;
3
3
  export type TierListItem = CoreItem;
4
4
  export type TierListPlacements = CorePlacements;
5
5
  import { type Snippet } from 'svelte';
6
6
  import { type Size } from '../config.js';
7
+ import { type TierListChangeDetails } from '../core/tierlist.js';
7
8
  interface Props {
8
9
  /** The rows, top to bottom. Defaults to S / A / B / C / D. */
9
10
  tiers?: readonly TierListTier[];
@@ -14,8 +15,11 @@ interface Props {
14
15
  * order itself; the tray is never part of it.
15
16
  */
16
17
  placements?: TierListPlacements;
17
- /** Fired after every drop / keyboard drop with the new placements. */
18
- onchange?: (placements: TierListPlacements) => void;
18
+ /**
19
+ * Fired after every drop / keyboard drop with the new placements. `details.reason` says
20
+ * what committed it: `'pointer'` (a drag) or `'keyboard'` (Space / Enter drop).
21
+ */
22
+ onchange?: (placements: TierListPlacements, details: TierListChangeDetails) => void;
19
23
  /**
20
24
  * Activation (Enter, or a click that isn't a drag) — e.g. open a details view.
21
25
  * When omitted, Enter picks the tile up like Space.
@@ -4,6 +4,14 @@
4
4
  import { untrack } from 'svelte'
5
5
  import { toasts, type Toast, type ToastKind } from '../toast.svelte.js'
6
6
  import { resolveComponentSize, type Size } from '../config.js'
7
+ import {
8
+ toastActionDismisses,
9
+ toastFocusAfterDismiss,
10
+ toastKey,
11
+ toastPressStartsSwipe,
12
+ toastShouldResume,
13
+ toastSwipeDismisses,
14
+ } from '../core/toast.js'
7
15
 
8
16
  type Position =
9
17
  | 'top-right'
@@ -63,12 +71,9 @@
63
71
  let dragStartX = 0
64
72
  let dragPointer: number | null = null
65
73
 
66
- const SWIPE_THRESHOLD = 64
67
-
68
74
  function onPointerDown(e: PointerEvent, t: Toast) {
69
- if (reduce || e.button !== 0) return
70
- // Ignore drags that start on the controls (buttons own their clicks).
71
- if ((e.target as HTMLElement).closest('button')) return
75
+ const onControl = (e.target as HTMLElement).closest('button') !== null
76
+ if (!toastPressStartsSwipe({ button: e.button, onControl, reducedMotion: reduce })) return
72
77
  dragId = t.id
73
78
  dragDx = 0
74
79
  dragStartX = e.clientX
@@ -84,27 +89,25 @@
84
89
 
85
90
  function endDrag(e: PointerEvent, t: Toast) {
86
91
  if (dragId !== t.id || e.pointerId !== dragPointer) return
87
- const passed = Math.abs(dragDx) >= SWIPE_THRESHOLD
92
+ const passed = toastSwipeDismisses(dragDx)
88
93
  dragId = null
89
94
  dragPointer = null
90
95
  if (passed) toasts.dismiss(t.id)
91
96
  else {
92
97
  dragDx = 0
93
- const el = e.currentTarget as HTMLElement
94
- if (hoverId !== t.id && !el.contains(document.activeElement)) toasts.resume(t.id)
98
+ resumeIfFree(t, holdsFocus(e.currentTarget as HTMLElement))
95
99
  }
96
100
  }
97
101
 
98
102
  function runAction(t: Toast) {
99
- const keep = t.action?.onClick() === false
100
- if (!keep) toasts.dismiss(t.id)
103
+ if (toastActionDismisses(t.action?.onClick())) toasts.dismiss(t.id)
101
104
  }
102
105
 
103
106
  function onKeydown(e: KeyboardEvent, t: Toast) {
104
- if (e.key === 'Escape') {
105
- e.stopPropagation()
106
- toasts.dismiss(t.id)
107
- }
107
+ const result = toastKey(e.key)
108
+ if (!result) return
109
+ if (result.stopPropagation) e.stopPropagation()
110
+ toasts.dismiss(t.id)
108
111
  }
109
112
 
110
113
  // ── pause / resume ────────────────────────────────────────────────
@@ -113,6 +116,13 @@
113
116
  // restart the clock under a keyboard user, and vice versa).
114
117
  let hoverId: number | null = null
115
118
 
119
+ const holdsFocus = (el: HTMLElement) => el.contains(document.activeElement)
120
+
121
+ function resumeIfFree(t: Toast, focused: boolean) {
122
+ const hold = { hovered: hoverId === t.id, focused, dragging: dragId === t.id }
123
+ if (toastShouldResume(hold)) toasts.resume(t.id)
124
+ }
125
+
116
126
  function onPointerEnter(t: Toast) {
117
127
  hoverId = t.id
118
128
  toasts.pause(t.id)
@@ -120,17 +130,13 @@
120
130
 
121
131
  function onPointerLeave(e: PointerEvent, t: Toast) {
122
132
  if (hoverId === t.id) hoverId = null
123
- if (dragId === t.id) return
124
- const el = e.currentTarget as HTMLElement
125
- if (el.contains(document.activeElement)) return
126
- toasts.resume(t.id)
133
+ resumeIfFree(t, holdsFocus(e.currentTarget as HTMLElement))
127
134
  }
128
135
 
129
136
  function onFocusOut(e: FocusEvent, t: Toast) {
130
137
  const el = e.currentTarget as HTMLElement
131
- if (el.contains(e.relatedTarget as Node | null)) return
132
- if (hoverId === t.id || dragId === t.id) return
133
- toasts.resume(t.id)
138
+ // Focus is only leaving when it lands outside the toast.
139
+ resumeIfFree(t, el.contains(e.relatedTarget as Node | null))
134
140
  }
135
141
 
136
142
  // ── focus management ──────────────────────────────────────────────
@@ -171,14 +177,8 @@
171
177
  })
172
178
 
173
179
  function moveFocusFrom(id: number, alive: Set<number>) {
174
- const i = order.indexOf(id)
175
- const after = order.slice(i + 1).find((n) => alive.has(n) && toastEls.has(n))
176
- const before = order
177
- .slice(0, i)
178
- .reverse()
179
- .find((n) => alive.has(n) && toastEls.has(n))
180
- const next = after ?? before
181
- if (next !== undefined) {
180
+ const next = toastFocusAfterDismiss(order, id, (n) => alive.has(n) && toastEls.has(n))
181
+ if (next !== null) {
182
182
  toastEls.get(next)!.focus()
183
183
  } else if (returnFocus?.isConnected) {
184
184
  returnFocus.focus()
@@ -1,6 +1,15 @@
1
1
  <script lang="ts">
2
2
  import type { Snippet } from 'svelte'
3
3
  import { resolveComponentSize, type Size } from '../config.js'
4
+ import {
5
+ tooltipDescribedBy,
6
+ tooltipFocusIn,
7
+ tooltipFocusOut,
8
+ tooltipKey,
9
+ tooltipPointerEnter,
10
+ tooltipPointerLeave,
11
+ type TooltipAction,
12
+ } from '../core/tooltip.js'
4
13
 
5
14
  /** Side the tooltip attaches to relative to the trigger. */
6
15
  type Placement = 'top' | 'bottom' | 'left' | 'right'
@@ -37,6 +46,7 @@
37
46
  const tipId = $props.id()
38
47
 
39
48
  let open = $state(false)
49
+ let rootEl = $state<HTMLElement | undefined>()
40
50
  let triggerEl = $state<HTMLElement | undefined>()
41
51
  let tipEl = $state<HTMLElement | undefined>()
42
52
 
@@ -74,37 +84,42 @@
74
84
  if (describedEl === el) return
75
85
  undescribe()
76
86
  if (!el) return
77
- const ids = (el.getAttribute('aria-describedby') ?? '').split(/\s+/).filter(Boolean)
78
- if (!ids.includes(tipId)) el.setAttribute('aria-describedby', [...ids, tipId].join(' '))
87
+ setDescribedBy(el, true)
79
88
  describedEl = el
80
89
  }
81
90
  function undescribe() {
82
91
  const el = describedEl
83
92
  describedEl = null
84
93
  if (!el) return
85
- const ids = (el.getAttribute('aria-describedby') ?? '')
86
- .split(/\s+/)
87
- .filter((id) => id && id !== tipId)
88
- if (ids.length) el.setAttribute('aria-describedby', ids.join(' '))
89
- else el.removeAttribute('aria-describedby')
94
+ setDescribedBy(el, false)
90
95
  }
91
-
92
- function show(e?: Event) {
93
- open = true
94
- describe(describedTarget(e?.target))
96
+ function setDescribedBy(el: HTMLElement, described: boolean) {
97
+ const value = tooltipDescribedBy(el.getAttribute('aria-describedby'), tipId, described)
98
+ if (value === undefined) el.removeAttribute('aria-describedby')
99
+ else el.setAttribute('aria-describedby', value)
95
100
  }
96
- function hide() {
97
- open = false
98
- undescribe()
101
+
102
+ // Which event shows or hides the tip is decided in core/tooltip.ts; this applies the action.
103
+ function run(action: TooltipAction | null, e?: Event) {
104
+ if (!action) return
105
+ if (action.type === 'show') {
106
+ open = true
107
+ describe(describedTarget(e?.target))
108
+ } else {
109
+ open = false
110
+ undescribe()
111
+ }
99
112
  }
100
113
 
114
+ /** The other end of a focus move is still inside the tooltip. */
115
+ const within = (node: EventTarget | null) =>
116
+ node instanceof Node && Boolean(rootEl?.contains(node))
117
+
101
118
  // Escape dismisses the tooltip wherever focus is (WCAG 1.4.13, WAI-ARIA tooltip
102
119
  // pattern): a document-level listener while open, so a hover-opened tip closes too.
103
120
  $effect(() => {
104
121
  if (!open) return
105
- const onKeydown = (e: KeyboardEvent) => {
106
- if (e.key === 'Escape') hide()
107
- }
122
+ const onKeydown = (e: KeyboardEvent) => run(tooltipKey({ open }, e.key))
108
123
  document.addEventListener('keydown', onKeydown)
109
124
  return () => document.removeEventListener('keydown', onKeydown)
110
125
  })
@@ -246,10 +261,11 @@
246
261
  class="ss-tooltip"
247
262
  data-size-variant={sizeAttr}
248
263
  data-placement={resolved}
249
- onmouseenter={show}
250
- onmouseleave={hide}
251
- onfocusin={show}
252
- onfocusout={hide}
264
+ bind:this={rootEl}
265
+ onmouseenter={(e) => run(tooltipPointerEnter({ open }), e)}
266
+ onmouseleave={() => run(tooltipPointerLeave({ open }))}
267
+ onfocusin={(e) => run(tooltipFocusIn({ open }), e)}
268
+ onfocusout={(e) => run(tooltipFocusOut({ open }, { within: within(e.relatedTarget) }))}
253
269
  >
254
270
  <span class="trigger" bind:this={triggerEl}>{@render children()}</span>
255
271
  <span