dssoca 0.19.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.
- package/README.md +3 -3
- package/dist/components/Accordion.svelte +30 -54
- package/dist/components/Badge.svelte +12 -7
- package/dist/components/Badge.svelte.d.ts +2 -1
- package/dist/components/BottomNav.svelte +18 -28
- package/dist/components/BoxPlot.svelte +34 -7
- package/dist/components/BumpChart.svelte +65 -26
- package/dist/components/Button.svelte +23 -1
- package/dist/components/Button.svelte.d.ts +5 -1
- package/dist/components/Card.svelte +32 -14
- package/dist/components/Card.svelte.d.ts +4 -1
- package/dist/components/Chart.svelte +166 -32
- package/dist/components/Chart.svelte.d.ts +13 -1
- package/dist/components/Checkbox.svelte +210 -0
- package/dist/components/Checkbox.svelte.d.ts +38 -0
- package/dist/components/DateField.svelte +1 -1
- package/dist/components/FileDrop.svelte +113 -77
- package/dist/components/FileDrop.svelte.d.ts +12 -2
- package/dist/components/Heatmap.svelte +128 -50
- package/dist/components/Heatmap.svelte.d.ts +2 -1
- package/dist/components/Icon.svelte +12 -3
- package/dist/components/Icon.svelte.d.ts +4 -0
- package/dist/components/Image.svelte +44 -44
- package/dist/components/Input.svelte +11 -6
- package/dist/components/Link.svelte +25 -14
- package/dist/components/LogStream.svelte +48 -33
- package/dist/components/Menu.svelte +81 -102
- package/dist/components/Menu.svelte.d.ts +8 -2
- package/dist/components/MetricTile.svelte +11 -1
- package/dist/components/MetricTile.svelte.d.ts +6 -0
- package/dist/components/Modal.svelte +108 -21
- package/dist/components/Modal.svelte.d.ts +18 -5
- package/dist/components/NumberField.svelte +44 -22
- package/dist/components/Pagination.svelte +54 -41
- package/dist/components/Pagination.svelte.d.ts +6 -2
- package/dist/components/Popover.svelte +247 -0
- package/dist/components/Popover.svelte.d.ts +36 -0
- package/dist/components/RadioGroup.svelte +227 -0
- package/dist/components/RadioGroup.svelte.d.ts +42 -0
- package/dist/components/ScatterPlot.svelte +42 -7
- package/dist/components/SearchPalette.svelte +216 -136
- package/dist/components/SearchPalette.svelte.d.ts +11 -4
- package/dist/components/SegmentedControl.svelte +47 -59
- package/dist/components/SegmentedControl.svelte.d.ts +7 -2
- package/dist/components/Select.svelte +3 -4
- package/dist/components/ServiceCard.svelte +105 -68
- package/dist/components/ServiceCard.svelte.d.ts +8 -3
- package/dist/components/ShortcutsHelp.svelte +49 -48
- package/dist/components/Sidebar.svelte +88 -117
- package/dist/components/Switch.svelte +24 -18
- package/dist/components/Switch.svelte.d.ts +6 -2
- package/dist/components/Table.svelte +29 -44
- package/dist/components/Table.svelte.d.ts +6 -2
- package/dist/components/Tabs.svelte +223 -0
- package/dist/components/Tabs.svelte.d.ts +51 -0
- package/dist/components/Textarea.svelte +1 -1
- package/dist/components/TierList.svelte +45 -49
- package/dist/components/TierList.svelte.d.ts +7 -3
- package/dist/components/Toaster.svelte +154 -32
- package/dist/components/Tooltip.svelte +122 -18
- package/dist/components/Tooltip.svelte.d.ts +1 -1
- package/dist/components/Topbar.svelte +29 -49
- package/dist/core/accordion.d.ts +32 -0
- package/dist/core/accordion.js +53 -0
- package/dist/core/behaviors/focusable.d.ts +5 -0
- package/dist/core/behaviors/focusable.js +14 -0
- package/dist/core/behaviors/roving.d.ts +13 -0
- package/dist/core/behaviors/roving.js +29 -0
- package/dist/core/bottom-nav.d.ts +36 -0
- package/dist/core/bottom-nav.js +33 -0
- package/dist/core/chart-nav.d.ts +53 -0
- package/dist/core/chart-nav.js +62 -0
- package/dist/core/checkbox.d.ts +36 -0
- package/dist/core/checkbox.js +29 -0
- package/dist/core/file-drop.d.ts +75 -0
- package/dist/core/file-drop.js +101 -0
- package/dist/core/image.d.ts +59 -0
- package/dist/core/image.js +64 -0
- package/dist/core/input.d.ts +21 -0
- package/dist/core/input.js +17 -0
- package/dist/core/log-stream.d.ts +51 -0
- package/dist/core/log-stream.js +50 -0
- package/dist/core/menu.d.ts +70 -0
- package/dist/core/menu.js +84 -0
- package/dist/core/modal.d.ts +59 -0
- package/dist/core/modal.js +44 -0
- package/dist/core/number-field.d.ts +47 -0
- package/dist/core/number-field.js +64 -0
- package/dist/core/pagination.d.ts +59 -0
- package/dist/core/pagination.js +65 -0
- package/dist/core/popover.d.ts +68 -0
- package/dist/core/popover.js +55 -0
- package/dist/core/radio.d.ts +36 -0
- package/dist/core/radio.js +48 -0
- package/dist/core/search-palette.d.ts +124 -0
- package/dist/core/search-palette.js +149 -0
- package/dist/core/segmented.d.ts +46 -0
- package/dist/core/segmented.js +66 -0
- package/dist/core/shortcuts-help.d.ts +56 -0
- package/dist/core/shortcuts-help.js +50 -0
- package/dist/core/sidebar.d.ts +63 -0
- package/dist/core/sidebar.js +84 -0
- package/dist/core/switch.d.ts +19 -0
- package/dist/core/switch.js +11 -0
- package/dist/core/table.d.ts +40 -0
- package/dist/core/table.js +57 -0
- package/dist/core/tabs.d.ts +84 -0
- package/dist/core/tabs.js +90 -0
- package/dist/{tierlist-core.d.ts → core/tierlist.d.ts} +77 -5
- package/dist/{tierlist-core.js → core/tierlist.js} +64 -7
- package/dist/core/toast.d.ts +112 -0
- package/dist/{toast-core.js → core/toast.js} +48 -2
- package/dist/core/tooltip.d.ts +47 -0
- package/dist/core/tooltip.js +51 -0
- package/dist/core/topbar.d.ts +41 -0
- package/dist/core/topbar.js +52 -0
- package/dist/dssoca.config.d.ts +1 -1
- package/dist/dssoca.config.js +4 -0
- package/dist/icons.d.ts +19 -2
- package/dist/icons.js +42 -3
- package/dist/index.d.ts +15 -2
- package/dist/index.js +10 -2
- package/dist/theme.css +47 -0
- package/dist/toast.svelte.d.ts +2 -2
- package/dist/toast.svelte.js +1 -1
- package/dist/tokens.css +47 -0
- package/dist/vanilla/accordion.js +35 -32
- package/dist/vanilla/checkbox.d.ts +8 -0
- package/dist/vanilla/checkbox.js +43 -0
- package/dist/vanilla/delegate.d.ts +2 -0
- package/dist/vanilla/delegate.js +9 -0
- package/dist/vanilla/fields.js +46 -28
- package/dist/vanilla/index.d.ts +5 -1
- package/dist/vanilla/index.js +17 -4
- package/dist/vanilla/menu.js +101 -84
- package/dist/vanilla/modal.d.ts +7 -1
- package/dist/vanilla/modal.js +120 -15
- package/dist/vanilla/popover.d.ts +10 -0
- package/dist/vanilla/popover.js +129 -0
- package/dist/vanilla/radio.d.ts +3 -0
- package/dist/vanilla/radio.js +54 -0
- package/dist/vanilla/segmented.js +50 -43
- package/dist/vanilla/switch.d.ts +2 -1
- package/dist/vanilla/switch.js +13 -8
- package/dist/vanilla/tabs.d.ts +2 -0
- package/dist/vanilla/tabs.js +87 -0
- package/dist/vanilla/tierlist.d.ts +1 -1
- package/dist/vanilla/tierlist.js +34 -34
- package/dist/vanilla/toast.d.ts +13 -5
- package/dist/vanilla/toast.js +132 -16
- package/dist/vanilla/tooltip.d.ts +5 -1
- package/dist/vanilla/tooltip.js +78 -19
- package/dist/vanilla.css +675 -160
- package/package.json +1 -1
- package/dist/toast-core.d.ts +0 -61
|
@@ -12,8 +12,12 @@ export interface TableColumn {
|
|
|
12
12
|
key: string;
|
|
13
13
|
/** Header text. */
|
|
14
14
|
label: string;
|
|
15
|
-
/**
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Text alignment of the header and body cells. Logical: `start`/`end` follow the
|
|
17
|
+
* writing direction (so they flip in RTL). `left`/`right` are accepted for backward
|
|
18
|
+
* compatibility and map to `start`/`end`. Numeric columns default to `end`.
|
|
19
|
+
*/
|
|
20
|
+
align?: 'start' | 'end' | 'left' | 'right' | 'center';
|
|
17
21
|
/** Allow clicking the header to sort by this column. */
|
|
18
22
|
sortable?: boolean;
|
|
19
23
|
/** Treat values as numbers — right-aligns, uses the mono font, sorts numerically. */
|
|
@@ -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
|
|
9
|
+
} from '../core/tierlist.js'
|
|
10
10
|
export type TierListTier = CoreTier
|
|
11
11
|
export type TierListItem = CoreItem
|
|
12
12
|
export type TierListPlacements = CorePlacements
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
// ─────────────────────────────────────────────────────────────────────────
|
|
35
35
|
import { tick, untrack, type Snippet } from 'svelte'
|
|
36
36
|
import { flip } from 'svelte/animate'
|
|
37
|
+
import { prefersReducedMotion } from 'svelte/motion'
|
|
37
38
|
import { resolveComponentSize, type Size } from '../config.js'
|
|
38
39
|
import {
|
|
39
40
|
DEFAULT_TIERS,
|
|
@@ -47,10 +48,15 @@
|
|
|
47
48
|
moveItem,
|
|
48
49
|
placementsOf,
|
|
49
50
|
tierColor,
|
|
51
|
+
tierListClickSelects,
|
|
52
|
+
tierListDragStarts,
|
|
53
|
+
tierListPressArmsDrag,
|
|
54
|
+
tierListTileKey,
|
|
50
55
|
zonesEqual,
|
|
51
|
-
type
|
|
56
|
+
type TierListChangeDetails,
|
|
57
|
+
type TierListChangeReason,
|
|
52
58
|
type TierListZones,
|
|
53
|
-
} from '../tierlist
|
|
59
|
+
} from '../core/tierlist.js'
|
|
54
60
|
|
|
55
61
|
interface Props {
|
|
56
62
|
/** The rows, top to bottom. Defaults to S / A / B / C / D. */
|
|
@@ -62,8 +68,11 @@
|
|
|
62
68
|
* order itself; the tray is never part of it.
|
|
63
69
|
*/
|
|
64
70
|
placements?: TierListPlacements
|
|
65
|
-
/**
|
|
66
|
-
|
|
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
|
|
67
76
|
/**
|
|
68
77
|
* Activation (Enter, or a click that isn't a drag) — e.g. open a details view.
|
|
69
78
|
* When omitted, Enter picks the tile up like Space.
|
|
@@ -119,11 +128,11 @@
|
|
|
119
128
|
return it ? [it] : []
|
|
120
129
|
})
|
|
121
130
|
|
|
122
|
-
function commit(next: TierListZones) {
|
|
131
|
+
function commit(next: TierListZones, reason: TierListChangeReason) {
|
|
123
132
|
zones = next
|
|
124
133
|
const p = placementsOf(next, tiers)
|
|
125
134
|
if (placements !== undefined) placements = p
|
|
126
|
-
onchange?.(p)
|
|
135
|
+
onchange?.(p, { reason })
|
|
127
136
|
}
|
|
128
137
|
|
|
129
138
|
function describe(id: string) {
|
|
@@ -142,21 +151,15 @@
|
|
|
142
151
|
|
|
143
152
|
// --- keyboard sorting ----------------------------------------------------
|
|
144
153
|
let grabbed = $state<{ id: string; origin: TierListZones } | null>(null)
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
ArrowRight: 'right',
|
|
148
|
-
ArrowUp: 'up',
|
|
149
|
-
ArrowDown: 'down',
|
|
150
|
-
Home: 'home',
|
|
151
|
-
End: 'end',
|
|
152
|
-
}
|
|
154
|
+
// Read at event time, not once: `dir` may be set on any ancestor and change later.
|
|
155
|
+
const isRtl = (el: Element) => getComputedStyle(el).direction === 'rtl'
|
|
153
156
|
|
|
154
157
|
function toggleGrab(id: string) {
|
|
155
158
|
if (grabbed?.id === id) {
|
|
156
159
|
const origin = grabbed.origin
|
|
157
160
|
grabbed = null
|
|
158
161
|
announce(announceText('drop', describe(id)))
|
|
159
|
-
if (!zonesEqual(origin, zones)) commit(zones)
|
|
162
|
+
if (!zonesEqual(origin, zones)) commit(zones, 'keyboard')
|
|
160
163
|
return
|
|
161
164
|
}
|
|
162
165
|
grabbed = { id, origin: zones }
|
|
@@ -186,27 +189,22 @@
|
|
|
186
189
|
}
|
|
187
190
|
|
|
188
191
|
function onTileKeydown(e: KeyboardEvent, item: TierListItem) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
e.
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
if (
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
const move = KEY_MOVES[e.key]
|
|
207
|
-
if (!move) return
|
|
208
|
-
e.preventDefault()
|
|
209
|
-
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)
|
|
210
208
|
if (!target) return
|
|
211
209
|
zones = moveItem(zones, item.id, target.zone, target.index)
|
|
212
210
|
announce(announceText('move', describe(item.id)))
|
|
@@ -245,7 +243,6 @@
|
|
|
245
243
|
}
|
|
246
244
|
let drag = $state<Drag | null>(null)
|
|
247
245
|
let root: HTMLElement | undefined = $state()
|
|
248
|
-
const DRAG_THRESHOLD = 4
|
|
249
246
|
let suppressClick = false
|
|
250
247
|
|
|
251
248
|
// The drag listens on `window`, not the tile: the live preview moves the
|
|
@@ -264,7 +261,7 @@
|
|
|
264
261
|
$effect(() => unlisten)
|
|
265
262
|
|
|
266
263
|
function onPointerDown(e: PointerEvent, item: TierListItem) {
|
|
267
|
-
if (readonly
|
|
264
|
+
if (!tierListPressArmsDrag({ readonly, button: e.button, grabbing: grabbed !== null })) return
|
|
268
265
|
const tileEl = e.currentTarget as HTMLElement
|
|
269
266
|
const rect = tileEl.getBoundingClientRect()
|
|
270
267
|
listen()
|
|
@@ -298,7 +295,7 @@
|
|
|
298
295
|
function onPointerMove(e: PointerEvent) {
|
|
299
296
|
if (!drag) return
|
|
300
297
|
if (!drag.active) {
|
|
301
|
-
if (
|
|
298
|
+
if (!tierListDragStarts(e.clientX - drag.startX, e.clientY - drag.startY)) return
|
|
302
299
|
drag.active = true
|
|
303
300
|
}
|
|
304
301
|
e.preventDefault()
|
|
@@ -314,7 +311,8 @@
|
|
|
314
311
|
const boxes = Array.from(zoneEl.querySelectorAll<HTMLElement>(':scope > .cell'))
|
|
315
312
|
.filter((c) => c.dataset.item !== drag!.id)
|
|
316
313
|
.map((c) => c.getBoundingClientRect())
|
|
317
|
-
const
|
|
314
|
+
const index = insertionIndex(boxes, e.clientX, e.clientY, isRtl(zoneEl))
|
|
315
|
+
const next = moveItem(zones, drag.id, zone, index)
|
|
318
316
|
if (next !== zones) zones = next
|
|
319
317
|
}
|
|
320
318
|
|
|
@@ -327,7 +325,7 @@
|
|
|
327
325
|
suppressClick = true
|
|
328
326
|
if (zonesEqual(d.origin, zones)) return
|
|
329
327
|
announce(announceText('drop', describe(d.id)))
|
|
330
|
-
commit(zones)
|
|
328
|
+
commit(zones, 'pointer')
|
|
331
329
|
}
|
|
332
330
|
|
|
333
331
|
function onPointerCancel() {
|
|
@@ -339,11 +337,9 @@
|
|
|
339
337
|
}
|
|
340
338
|
|
|
341
339
|
function onTileClick(item: TierListItem) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
}
|
|
346
|
-
if (!readonly) onselect?.(item)
|
|
340
|
+
const afterDrag = suppressClick
|
|
341
|
+
suppressClick = false
|
|
342
|
+
if (tierListClickSelects({ readonly, afterDrag })) onselect?.(item)
|
|
347
343
|
}
|
|
348
344
|
|
|
349
345
|
const draggedItem = $derived(drag?.active ? byId.get(drag.id) : undefined)
|
|
@@ -373,7 +369,7 @@
|
|
|
373
369
|
class:shadow={drag?.active && drag.id === item.id}
|
|
374
370
|
class:grabbed={grabbed?.id === item.id}
|
|
375
371
|
data-item={item.id}
|
|
376
|
-
animate:flip={{ duration: 150 }}
|
|
372
|
+
animate:flip={{ duration: prefersReducedMotion.current ? 0 : 150 }}
|
|
377
373
|
>
|
|
378
374
|
{#if readonly}
|
|
379
375
|
<div class="tile" data-item={item.id} aria-label={item.label} role="img">
|
|
@@ -526,7 +522,7 @@
|
|
|
526
522
|
background: var(--ss-bg-inset);
|
|
527
523
|
color: inherit;
|
|
528
524
|
font: inherit;
|
|
529
|
-
text-align:
|
|
525
|
+
text-align: start;
|
|
530
526
|
overflow: hidden;
|
|
531
527
|
cursor: grab;
|
|
532
528
|
touch-action: none;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { TierListTier as CoreTier, TierListItem as CoreItem, TierListPlacements as CorePlacements } from '../tierlist
|
|
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
|
-
/**
|
|
18
|
-
|
|
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.
|