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.
- package/README.md +3 -3
- package/dist/components/Accordion.svelte +23 -52
- package/dist/components/BottomNav.svelte +18 -28
- package/dist/components/BoxPlot.svelte +7 -6
- package/dist/components/BumpChart.svelte +9 -12
- package/dist/components/Chart.svelte +9 -12
- package/dist/components/Checkbox.svelte +210 -0
- package/dist/components/Checkbox.svelte.d.ts +38 -0
- package/dist/components/FileDrop.svelte +52 -83
- package/dist/components/FileDrop.svelte.d.ts +6 -2
- package/dist/components/Heatmap.svelte +8 -8
- package/dist/components/Image.svelte +44 -44
- package/dist/components/Input.svelte +8 -3
- package/dist/components/LogStream.svelte +15 -25
- package/dist/components/Menu.svelte +69 -94
- package/dist/components/Menu.svelte.d.ts +6 -0
- package/dist/components/Modal.svelte +61 -14
- package/dist/components/Modal.svelte.d.ts +7 -2
- package/dist/components/NumberField.svelte +18 -19
- package/dist/components/Pagination.svelte +47 -37
- 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 +11 -13
- package/dist/components/SearchPalette.svelte +124 -120
- package/dist/components/SearchPalette.svelte.d.ts +6 -4
- package/dist/components/SegmentedControl.svelte +41 -62
- package/dist/components/SegmentedControl.svelte.d.ts +7 -2
- package/dist/components/ShortcutsHelp.svelte +48 -47
- package/dist/components/Sidebar.svelte +48 -60
- package/dist/components/Switch.svelte +20 -10
- package/dist/components/Switch.svelte.d.ts +6 -2
- package/dist/components/Table.svelte +15 -37
- package/dist/components/Tabs.svelte +223 -0
- package/dist/components/Tabs.svelte.d.ts +51 -0
- package/dist/components/TierList.svelte +38 -38
- package/dist/components/TierList.svelte.d.ts +7 -3
- package/dist/components/Toaster.svelte +29 -29
- package/dist/components/Tooltip.svelte +37 -21
- package/dist/components/Topbar.svelte +13 -38
- 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/{chart-nav.js → core/chart-nav.js} +27 -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} +62 -0
- package/dist/{tierlist-core.js → core/tierlist.js} +34 -0
- 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/index.d.ts +14 -1
- package/dist/index.js +9 -1
- 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 +28 -29
- 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 +37 -32
- package/dist/vanilla/index.d.ts +4 -0
- package/dist/vanilla/index.js +16 -3
- package/dist/vanilla/menu.js +92 -86
- package/dist/vanilla/modal.d.ts +3 -1
- package/dist/vanilla/modal.js +65 -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 +49 -51
- 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 +29 -25
- package/dist/vanilla/toast.d.ts +2 -2
- package/dist/vanilla/toast.js +16 -14
- package/dist/vanilla/tooltip.js +35 -23
- package/dist/vanilla.css +349 -42
- package/package.json +1 -1
- package/dist/chart-nav.d.ts +0 -13
- package/dist/toast-core.d.ts +0 -61
|
@@ -40,6 +40,20 @@
|
|
|
40
40
|
<script lang="ts">
|
|
41
41
|
import Icon from './Icon.svelte'
|
|
42
42
|
import { resolveComponentSize, type Size } from '../config.js'
|
|
43
|
+
import {
|
|
44
|
+
menuItemAttrs,
|
|
45
|
+
menuItemPress,
|
|
46
|
+
menuOutsidePress,
|
|
47
|
+
menuPanelAttrs,
|
|
48
|
+
menuPanelKey,
|
|
49
|
+
menuTriggerAttrs,
|
|
50
|
+
menuTriggerKey,
|
|
51
|
+
menuTriggerPress,
|
|
52
|
+
type MenuAction,
|
|
53
|
+
type MenuKeyResult,
|
|
54
|
+
type MenuOpenChangeDetails,
|
|
55
|
+
type MenuState,
|
|
56
|
+
} from '../core/menu.js'
|
|
43
57
|
|
|
44
58
|
/** Where the panel attaches relative to the trigger. */
|
|
45
59
|
type Align = 'start' | 'end'
|
|
@@ -55,6 +69,11 @@
|
|
|
55
69
|
open?: boolean
|
|
56
70
|
/** Fired when an item is activated, with its `id` (after `item.onSelect`). */
|
|
57
71
|
onSelect?: (id: string) => void
|
|
72
|
+
/**
|
|
73
|
+
* Fired when the menu opens or closes itself, with the new state and why
|
|
74
|
+
* (`details.reason`: trigger · key · escape · tab · outside · item).
|
|
75
|
+
*/
|
|
76
|
+
onOpenChange?: (open: boolean, details: MenuOpenChangeDetails) => void
|
|
58
77
|
/** Horizontal edge the panel aligns to. */
|
|
59
78
|
align?: Align
|
|
60
79
|
/** Vertical side the panel opens toward. */
|
|
@@ -74,6 +93,7 @@
|
|
|
74
93
|
items = [],
|
|
75
94
|
open = $bindable(false),
|
|
76
95
|
onSelect,
|
|
96
|
+
onOpenChange,
|
|
77
97
|
align = 'start',
|
|
78
98
|
side = 'bottom',
|
|
79
99
|
label,
|
|
@@ -92,12 +112,16 @@
|
|
|
92
112
|
|
|
93
113
|
let triggerEl = $state<HTMLButtonElement>()
|
|
94
114
|
let panelEl = $state<HTMLElement>()
|
|
95
|
-
// The roving focus index into the
|
|
115
|
+
// The roving focus index into the items; -1 when none focused yet.
|
|
96
116
|
let activeIndex = $state(-1)
|
|
97
117
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
118
|
+
// Behaviour lives in `core/menu.ts` (shared with vanilla/menu.ts): events go in, a
|
|
119
|
+
// MenuAction comes out, and `run` applies it to this component's state.
|
|
120
|
+
const menu = $derived<MenuState>({
|
|
121
|
+
open,
|
|
122
|
+
active: activeIndex,
|
|
123
|
+
enabled: items.map((it, i) => (it.disabled ? -1 : i)).filter((i) => i >= 0),
|
|
124
|
+
})
|
|
101
125
|
|
|
102
126
|
function focusItem(domIndex: number) {
|
|
103
127
|
activeIndex = domIndex
|
|
@@ -105,99 +129,50 @@
|
|
|
105
129
|
el?.focus()
|
|
106
130
|
}
|
|
107
131
|
|
|
108
|
-
function
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
queueMicrotask(() => focusItem(focus === 'first' ? firstEnabled() : lastEnabled()))
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function closeMenu(returnFocus = true) {
|
|
131
|
-
if (!open) return
|
|
132
|
-
open = false
|
|
133
|
-
activeIndex = -1
|
|
134
|
-
if (returnFocus) triggerEl?.focus()
|
|
132
|
+
function run(action: MenuAction | null) {
|
|
133
|
+
if (!action) return
|
|
134
|
+
switch (action.type) {
|
|
135
|
+
case 'open':
|
|
136
|
+
open = true
|
|
137
|
+
onOpenChange?.(true, { reason: action.reason })
|
|
138
|
+
// Defer focus until the panel renders.
|
|
139
|
+
queueMicrotask(() => focusItem(action.focus))
|
|
140
|
+
break
|
|
141
|
+
case 'close':
|
|
142
|
+
open = false
|
|
143
|
+
activeIndex = -1
|
|
144
|
+
onOpenChange?.(false, { reason: action.reason })
|
|
145
|
+
if (action.returnFocus) triggerEl?.focus()
|
|
146
|
+
break
|
|
147
|
+
case 'focus':
|
|
148
|
+
focusItem(action.index)
|
|
149
|
+
break
|
|
150
|
+
}
|
|
135
151
|
}
|
|
136
152
|
|
|
137
|
-
function
|
|
138
|
-
if (
|
|
139
|
-
|
|
153
|
+
function onKey(result: MenuKeyResult | null, e: KeyboardEvent) {
|
|
154
|
+
if (!result) return
|
|
155
|
+
if (result.preventDefault) e.preventDefault()
|
|
156
|
+
run(result.action)
|
|
140
157
|
}
|
|
141
158
|
|
|
142
|
-
function activate(item: MenuItem) {
|
|
143
|
-
|
|
159
|
+
function activate(item: MenuItem, index: number) {
|
|
160
|
+
const result = menuItemPress(menu, index)
|
|
161
|
+
if (!result) return
|
|
144
162
|
item.onSelect?.(item.id)
|
|
145
163
|
onSelect?.(item.id)
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function onTriggerKeydown(e: KeyboardEvent) {
|
|
150
|
-
if (e.key === 'ArrowDown') {
|
|
151
|
-
e.preventDefault()
|
|
152
|
-
openMenu('first')
|
|
153
|
-
} else if (e.key === 'ArrowUp') {
|
|
154
|
-
e.preventDefault()
|
|
155
|
-
openMenu('last')
|
|
156
|
-
} else if (e.key === 'Enter' || e.key === ' ') {
|
|
157
|
-
e.preventDefault()
|
|
158
|
-
openMenu('first')
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function onPanelKeydown(e: KeyboardEvent) {
|
|
163
|
-
switch (e.key) {
|
|
164
|
-
case 'ArrowDown':
|
|
165
|
-
e.preventDefault()
|
|
166
|
-
focusItem(activeIndex < 0 ? firstEnabled() : nextEnabled(activeIndex))
|
|
167
|
-
break
|
|
168
|
-
case 'ArrowUp':
|
|
169
|
-
e.preventDefault()
|
|
170
|
-
focusItem(activeIndex < 0 ? lastEnabled() : prevEnabled(activeIndex))
|
|
171
|
-
break
|
|
172
|
-
case 'Home':
|
|
173
|
-
e.preventDefault()
|
|
174
|
-
focusItem(firstEnabled())
|
|
175
|
-
break
|
|
176
|
-
case 'End':
|
|
177
|
-
e.preventDefault()
|
|
178
|
-
focusItem(lastEnabled())
|
|
179
|
-
break
|
|
180
|
-
case 'Escape':
|
|
181
|
-
e.preventDefault()
|
|
182
|
-
closeMenu()
|
|
183
|
-
break
|
|
184
|
-
case 'Tab':
|
|
185
|
-
// Tabbing out dismisses the menu (focus moves naturally; don't trap).
|
|
186
|
-
closeMenu(false)
|
|
187
|
-
break
|
|
188
|
-
}
|
|
164
|
+
run(result.action)
|
|
189
165
|
}
|
|
190
166
|
|
|
191
167
|
// Pointer-down outside the root closes the menu (click would fire after the
|
|
192
168
|
// outside target already handled the event; pointerdown matches the website).
|
|
193
169
|
function onDocPointerDown(e: PointerEvent) {
|
|
194
|
-
if (!open) return
|
|
195
170
|
const t = e.target as Node
|
|
196
171
|
// DS-0067 / DS-0078: triggerEl/panelEl may be unbound (pre-mount, SSR-ish
|
|
197
172
|
// eager evaluation) — null-check before .contains().
|
|
198
173
|
if (triggerEl && triggerEl.contains(t)) return
|
|
199
174
|
if (panelEl && panelEl.contains(t)) return
|
|
200
|
-
|
|
175
|
+
run(menuOutsidePress(menu))
|
|
201
176
|
}
|
|
202
177
|
|
|
203
178
|
// SSR safety (DS-0067): same guard pattern as toast.svelte.ts — effects
|
|
@@ -220,11 +195,10 @@
|
|
|
220
195
|
id={triggerId}
|
|
221
196
|
type="button"
|
|
222
197
|
class="trigger"
|
|
223
|
-
|
|
224
|
-
aria-expanded={open}
|
|
198
|
+
{...menuTriggerAttrs(open)}
|
|
225
199
|
aria-controls={panelId}
|
|
226
|
-
onclick={
|
|
227
|
-
onkeydown={
|
|
200
|
+
onclick={() => run(menuTriggerPress(menu))}
|
|
201
|
+
onkeydown={(e) => onKey(menuTriggerKey(menu, e.key), e)}
|
|
228
202
|
>
|
|
229
203
|
{@render children?.()}
|
|
230
204
|
</button>
|
|
@@ -234,12 +208,10 @@
|
|
|
234
208
|
id={panelId}
|
|
235
209
|
class="panel"
|
|
236
210
|
class:open
|
|
237
|
-
role="menu"
|
|
238
211
|
aria-label={label || undefined}
|
|
239
212
|
aria-labelledby={label ? undefined : triggerId}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
onkeydown={onPanelKeydown}
|
|
213
|
+
{...menuPanelAttrs(open)}
|
|
214
|
+
onkeydown={(e) => onKey(menuPanelKey(menu, e.key), e)}
|
|
243
215
|
>
|
|
244
216
|
{#each items as item, i (item.id)}
|
|
245
217
|
<button
|
|
@@ -247,12 +219,15 @@
|
|
|
247
219
|
class="item"
|
|
248
220
|
class:selected={item.selected}
|
|
249
221
|
data-mi={i}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
222
|
+
{...menuItemAttrs({
|
|
223
|
+
index: i,
|
|
224
|
+
active: activeIndex,
|
|
225
|
+
selectable,
|
|
226
|
+
selected: item.selected,
|
|
227
|
+
disabled: item.disabled,
|
|
228
|
+
})}
|
|
253
229
|
disabled={item.disabled}
|
|
254
|
-
|
|
255
|
-
onclick={() => activate(item)}
|
|
230
|
+
onclick={() => activate(item, i)}
|
|
256
231
|
>
|
|
257
232
|
{#if item.leading}
|
|
258
233
|
<span class="lead" aria-hidden="true">{@render item.leading()}</span>
|
|
@@ -34,6 +34,7 @@ export interface MenuItem {
|
|
|
34
34
|
onSelect?: (id: string) => void;
|
|
35
35
|
}
|
|
36
36
|
import { type Size } from '../config.js';
|
|
37
|
+
import { type MenuOpenChangeDetails } from '../core/menu.js';
|
|
37
38
|
/** Where the panel attaches relative to the trigger. */
|
|
38
39
|
type Align = 'start' | 'end';
|
|
39
40
|
type Side = 'bottom' | 'top';
|
|
@@ -47,6 +48,11 @@ interface Props {
|
|
|
47
48
|
open?: boolean;
|
|
48
49
|
/** Fired when an item is activated, with its `id` (after `item.onSelect`). */
|
|
49
50
|
onSelect?: (id: string) => void;
|
|
51
|
+
/**
|
|
52
|
+
* Fired when the menu opens or closes itself, with the new state and why
|
|
53
|
+
* (`details.reason`: trigger · key · escape · tab · outside · item).
|
|
54
|
+
*/
|
|
55
|
+
onOpenChange?: (open: boolean, details: MenuOpenChangeDetails) => void;
|
|
50
56
|
/** Horizontal edge the panel aligns to. */
|
|
51
57
|
align?: Align;
|
|
52
58
|
/** Vertical side the panel opens toward. */
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
// showModal()/close(). The dialog's native `close` event syncs `open` back
|
|
8
8
|
// to false and fires `onclose`. Esc is native; when `closeOnEsc` is false we
|
|
9
9
|
// intercept the `cancel` event and preventDefault(). Backdrop click closes
|
|
10
|
-
// when `closeOnBackdrop
|
|
11
|
-
//
|
|
12
|
-
//
|
|
10
|
+
// when `closeOnBackdrop`: a press that starts on the dialog itself (the inner
|
|
11
|
+
// .panel covers the dialog's content box, so any hit on the dialog element is
|
|
12
|
+
// the surrounding backdrop area) closes it on the click that follows.
|
|
13
13
|
//
|
|
14
14
|
// Naming (DS-0178): a custom `header` snippet receives the title id so it can
|
|
15
15
|
// put `id={titleId}` on its heading; the dialog stays aria-labelledby that id.
|
|
@@ -23,6 +23,16 @@
|
|
|
23
23
|
import type { Snippet } from 'svelte'
|
|
24
24
|
import { resolveComponentSize, type Size } from '../config.js'
|
|
25
25
|
import { lockScroll, unlockScroll } from '../vanilla/modal.js'
|
|
26
|
+
import {
|
|
27
|
+
modalBackdropPress,
|
|
28
|
+
modalCancel,
|
|
29
|
+
modalClosed,
|
|
30
|
+
modalDismissPress,
|
|
31
|
+
type ModalAction,
|
|
32
|
+
type ModalCloseDetails,
|
|
33
|
+
type ModalReason,
|
|
34
|
+
type ModalState,
|
|
35
|
+
} from '../core/modal.js'
|
|
26
36
|
|
|
27
37
|
interface Props {
|
|
28
38
|
/** Whether the modal is shown. Bindable — sync it from caller state. */
|
|
@@ -51,8 +61,12 @@
|
|
|
51
61
|
danger?: boolean
|
|
52
62
|
/** Accessible name when no `title` is set (maps to aria-label on the dialog). */
|
|
53
63
|
'aria-label'?: string
|
|
54
|
-
/**
|
|
55
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Called after the dialog has closed, with why (`details.reason`: escape · backdrop ·
|
|
66
|
+
* button · programmatic — the last one covers the `open` prop, a direct `.close()` and a
|
|
67
|
+
* `<form method="dialog">`).
|
|
68
|
+
*/
|
|
69
|
+
onclose?: (details: ModalCloseDetails) => void
|
|
56
70
|
/**
|
|
57
71
|
* Header content; replaces the default title row when provided. Receives the id the
|
|
58
72
|
* dialog's `aria-labelledby` points at — put it on your heading (`id={titleId}`) so the
|
|
@@ -120,23 +134,52 @@
|
|
|
120
134
|
else if (!open && el.open) el.close()
|
|
121
135
|
})
|
|
122
136
|
|
|
137
|
+
// The decisions (what closes the modal, and why) come from core/modal.ts; this file applies
|
|
138
|
+
// them. `pending` remembers the reason between the action and the native `close` it causes.
|
|
139
|
+
const modal = $derived<ModalState>({ open, closeOnEsc, closeOnBackdrop })
|
|
140
|
+
let pending: ModalReason | null = null
|
|
141
|
+
|
|
142
|
+
function run(action: ModalAction | null) {
|
|
143
|
+
if (action?.type !== 'close') return
|
|
144
|
+
pending = action.reason
|
|
145
|
+
open = false
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// A reason left over from a close that never happened must not label the next one.
|
|
149
|
+
$effect(() => {
|
|
150
|
+
if (open) pending = null
|
|
151
|
+
})
|
|
152
|
+
|
|
123
153
|
// Native `close` (Esc, form method=dialog, .close()) → sync state + notify.
|
|
124
154
|
function onDialogClose() {
|
|
155
|
+
const details = modalClosed(pending)
|
|
156
|
+
pending = null
|
|
125
157
|
if (open) open = false
|
|
126
|
-
onclose?.()
|
|
158
|
+
onclose?.(details)
|
|
127
159
|
}
|
|
128
160
|
|
|
129
161
|
// Esc dispatches `cancel` before `close`; swallow it when Esc is disabled.
|
|
130
162
|
function onCancel(e: Event) {
|
|
131
|
-
|
|
163
|
+
const result = modalCancel(modal, e.cancelable)
|
|
164
|
+
if (result.preventDefault) e.preventDefault()
|
|
165
|
+
pending = result.reason
|
|
132
166
|
}
|
|
133
167
|
|
|
134
|
-
// A
|
|
135
|
-
// backdrop hit.
|
|
136
|
-
// the panel and released on the backdrop.
|
|
168
|
+
// A press that starts on the <dialog> itself (not the inner .panel) is a
|
|
169
|
+
// backdrop hit. Remembering where the press began avoids closing on a drag that
|
|
170
|
+
// started inside the panel and was released on the backdrop.
|
|
171
|
+
//
|
|
172
|
+
// The dialog closes on the `click`, not on the pointerdown: closing hands focus
|
|
173
|
+
// back to the opener, and if that happened on pointerdown the same gesture's
|
|
174
|
+
// mousedown would then land on the page and blur it, leaving focus on <body>.
|
|
175
|
+
let pressedBackdrop = false
|
|
137
176
|
function onPointerDown(e: PointerEvent) {
|
|
138
|
-
|
|
139
|
-
|
|
177
|
+
pressedBackdrop = e.target === dialog
|
|
178
|
+
}
|
|
179
|
+
function onClick(e: MouseEvent) {
|
|
180
|
+
const hit = pressedBackdrop && e.target === dialog
|
|
181
|
+
pressedBackdrop = false
|
|
182
|
+
run(modalBackdropPress(modal, hit))
|
|
140
183
|
}
|
|
141
184
|
</script>
|
|
142
185
|
|
|
@@ -151,6 +194,7 @@
|
|
|
151
194
|
onclose={onDialogClose}
|
|
152
195
|
oncancel={onCancel}
|
|
153
196
|
onpointerdown={onPointerDown}
|
|
197
|
+
onclick={onClick}
|
|
154
198
|
>
|
|
155
199
|
<div class="panel">
|
|
156
200
|
<header class="head">
|
|
@@ -159,8 +203,11 @@
|
|
|
159
203
|
{:else if title}
|
|
160
204
|
<h2 class="title" id={titleId}>{title}</h2>
|
|
161
205
|
{/if}
|
|
162
|
-
<button
|
|
163
|
-
|
|
206
|
+
<button
|
|
207
|
+
type="button"
|
|
208
|
+
class="close"
|
|
209
|
+
aria-label="Close"
|
|
210
|
+
onclick={() => run(modalDismissPress(modal))}>×</button
|
|
164
211
|
>
|
|
165
212
|
</header>
|
|
166
213
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import { type Size } from '../config.js';
|
|
3
|
+
import { type ModalCloseDetails } from '../core/modal.js';
|
|
3
4
|
interface Props {
|
|
4
5
|
/** Whether the modal is shown. Bindable — sync it from caller state. */
|
|
5
6
|
open?: boolean;
|
|
@@ -27,8 +28,12 @@ interface Props {
|
|
|
27
28
|
danger?: boolean;
|
|
28
29
|
/** Accessible name when no `title` is set (maps to aria-label on the dialog). */
|
|
29
30
|
'aria-label'?: string;
|
|
30
|
-
/**
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Called after the dialog has closed, with why (`details.reason`: escape · backdrop ·
|
|
33
|
+
* button · programmatic — the last one covers the `open` prop, a direct `.close()` and a
|
|
34
|
+
* `<form method="dialog">`).
|
|
35
|
+
*/
|
|
36
|
+
onclose?: (details: ModalCloseDetails) => void;
|
|
32
37
|
/**
|
|
33
38
|
* Header content; replaces the default title row when provided. Receives the id the
|
|
34
39
|
* dialog's `aria-labelledby` points at — put it on your heading (`id={titleId}`) so the
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { resolveComponentSize, type Size } from '../config.js'
|
|
3
|
+
import {
|
|
4
|
+
numberFieldAnnouncement,
|
|
5
|
+
numberFieldParse,
|
|
6
|
+
numberFieldStep,
|
|
7
|
+
numberFieldStepperAttrs,
|
|
8
|
+
} from '../core/number-field.js'
|
|
3
9
|
|
|
4
10
|
interface Props {
|
|
5
11
|
label?: string
|
|
@@ -68,31 +74,26 @@
|
|
|
68
74
|
// Steppers are natively disabled only when the whole field can't be edited. At a bound
|
|
69
75
|
// they stay focusable and become `aria-disabled` no-ops, so a keyboard user who presses
|
|
70
76
|
// − down to `min` keeps focus on the button instead of dropping to <body>.
|
|
77
|
+
// Parsing, stepping and that stepper state are decided in core/number-field.ts (shared with
|
|
78
|
+
// vanilla.js); this file holds the value and applies the result.
|
|
71
79
|
const locked = $derived(disabled || readonly)
|
|
72
|
-
const
|
|
73
|
-
const
|
|
80
|
+
const field = $derived({ value, min, max, step, locked })
|
|
81
|
+
const decAttrs = $derived(numberFieldStepperAttrs(field, -1))
|
|
82
|
+
const incAttrs = $derived(numberFieldStepperAttrs(field, 1))
|
|
74
83
|
|
|
75
84
|
// Polite live region text: set only by the steppers (typing in the input is already
|
|
76
85
|
// voiced by AT). The region itself is always rendered so updates are announced.
|
|
77
86
|
let announcement = $state('')
|
|
78
87
|
|
|
79
|
-
function clamp(n: number): number {
|
|
80
|
-
if (min != null && n < min) return min
|
|
81
|
-
if (max != null && n > max) return max
|
|
82
|
-
return n
|
|
83
|
-
}
|
|
84
|
-
|
|
85
88
|
function onInput(e: Event & { currentTarget: HTMLInputElement }) {
|
|
86
|
-
|
|
87
|
-
value = raw === '' ? null : e.currentTarget.valueAsNumber
|
|
88
|
-
if (value != null && Number.isNaN(value)) value = null
|
|
89
|
+
value = numberFieldParse(e.currentTarget.value, e.currentTarget.valueAsNumber)
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
function nudge(dir: 1 | -1) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
value =
|
|
95
|
-
announcement =
|
|
93
|
+
const next = numberFieldStep(field, dir)
|
|
94
|
+
if (next === null) return
|
|
95
|
+
value = next
|
|
96
|
+
announcement = numberFieldAnnouncement(next)
|
|
96
97
|
}
|
|
97
98
|
</script>
|
|
98
99
|
|
|
@@ -115,8 +116,7 @@
|
|
|
115
116
|
class="step dec"
|
|
116
117
|
aria-label="Decrease"
|
|
117
118
|
aria-controls={inputId}
|
|
118
|
-
|
|
119
|
-
aria-disabled={!locked && atMin ? 'true' : undefined}
|
|
119
|
+
{...decAttrs}
|
|
120
120
|
onclick={() => nudge(-1)}
|
|
121
121
|
>
|
|
122
122
|
−
|
|
@@ -146,8 +146,7 @@
|
|
|
146
146
|
class="step inc"
|
|
147
147
|
aria-label="Increase"
|
|
148
148
|
aria-controls={inputId}
|
|
149
|
-
|
|
150
|
-
aria-disabled={!locked && atMax ? 'true' : undefined}
|
|
149
|
+
{...incAttrs}
|
|
151
150
|
onclick={() => nudge(1)}
|
|
152
151
|
>
|
|
153
152
|
+
|
|
@@ -7,7 +7,21 @@
|
|
|
7
7
|
// density. The current page is `aria-current="page"`, visually active and
|
|
8
8
|
// inert (re-clicking it never re-fires). WCAG 2.2 AA.
|
|
9
9
|
// ─────────────────────────────────────────────────────────────────────────
|
|
10
|
+
import { tick } from 'svelte'
|
|
10
11
|
import { resolveComponentSize, type Size } from '../config.js'
|
|
12
|
+
import {
|
|
13
|
+
paginationClamp,
|
|
14
|
+
paginationIsGap,
|
|
15
|
+
paginationPageAttrs,
|
|
16
|
+
paginationPageCount,
|
|
17
|
+
paginationPagePress,
|
|
18
|
+
paginationSlots,
|
|
19
|
+
paginationStep,
|
|
20
|
+
paginationStepperDisabled,
|
|
21
|
+
type PaginationChange,
|
|
22
|
+
type PaginationChangeDetails,
|
|
23
|
+
type PaginationState,
|
|
24
|
+
} from '../core/pagination.js'
|
|
11
25
|
|
|
12
26
|
interface Props {
|
|
13
27
|
/** Current page, 1-based (bindable). */
|
|
@@ -24,8 +38,11 @@
|
|
|
24
38
|
disabled?: boolean
|
|
25
39
|
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
26
40
|
size?: Size
|
|
27
|
-
/**
|
|
28
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Fired when the page changes (after `page` updates), with the new page and what changed
|
|
43
|
+
* it (`details.reason`: page · prev · next).
|
|
44
|
+
*/
|
|
45
|
+
onchange?: (page: number, details: PaginationChangeDetails) => void
|
|
29
46
|
}
|
|
30
47
|
|
|
31
48
|
let {
|
|
@@ -39,46 +56,40 @@
|
|
|
39
56
|
onchange,
|
|
40
57
|
}: Props = $props()
|
|
41
58
|
|
|
59
|
+
// Behaviour lives in `core/pagination.ts`: the page window, the bounds and what a press
|
|
60
|
+
// does are decided there; this file holds the state and applies the result.
|
|
61
|
+
|
|
42
62
|
// Total number of pages — explicit `pageCount` wins, else derived from the
|
|
43
63
|
// item count. Always at least 1 so the control never renders empty.
|
|
44
|
-
const pages = $derived(pageCount
|
|
64
|
+
const pages = $derived(paginationPageCount({ pageCount, total, pageSize }))
|
|
45
65
|
|
|
46
66
|
// Clamp the active page into [1, pages] for all rendering/decisions.
|
|
47
|
-
const current = $derived(
|
|
48
|
-
|
|
49
|
-
type Slot = number | 'gap-start' | 'gap-end'
|
|
67
|
+
const current = $derived(paginationClamp(page, pages))
|
|
50
68
|
|
|
51
69
|
// Windowed list of slots: first page, last page, the sibling window around
|
|
52
70
|
// the current page, and an ellipsis marker wherever a run of pages is hidden.
|
|
53
|
-
const slots = $derived
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const out: Slot[] = [1]
|
|
57
|
-
// A single hidden page is cheaper to show than an ellipsis — only collapse
|
|
58
|
-
// a run into `…` when it hides more than one page.
|
|
59
|
-
if (start > 3) out.push('gap-start')
|
|
60
|
-
else if (start === 3) out.push(2)
|
|
61
|
-
for (let p = start; p <= end; p++) out.push(p)
|
|
62
|
-
if (end < pages - 2) out.push('gap-end')
|
|
63
|
-
else if (end === pages - 2) out.push(pages - 1)
|
|
64
|
-
if (pages > 1) out.push(pages)
|
|
65
|
-
return out
|
|
66
|
-
})
|
|
71
|
+
const slots = $derived(paginationSlots(current, pages, siblingCount))
|
|
72
|
+
|
|
73
|
+
const pagination = $derived<PaginationState>({ current, pages, disabled })
|
|
67
74
|
|
|
68
|
-
|
|
69
|
-
const atLast = $derived(current >= pages)
|
|
75
|
+
let navEl = $state<HTMLElement>()
|
|
70
76
|
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
page
|
|
75
|
-
|
|
77
|
+
async function apply(change: PaginationChange | null) {
|
|
78
|
+
if (!change) return
|
|
79
|
+
page = change.page
|
|
80
|
+
onchange?.(change.page, { reason: change.reason })
|
|
81
|
+
if (change.focus === 'current') {
|
|
82
|
+
// The stepper just became disabled under the focus: hand it to the current page.
|
|
83
|
+
await tick()
|
|
84
|
+
navEl?.querySelector<HTMLElement>('[aria-current="page"]')?.focus()
|
|
85
|
+
}
|
|
76
86
|
}
|
|
77
87
|
|
|
78
88
|
const sizeAttr = $derived(resolveComponentSize('Pagination', size))
|
|
79
89
|
</script>
|
|
80
90
|
|
|
81
91
|
<nav
|
|
92
|
+
bind:this={navEl}
|
|
82
93
|
class="ss-pagination"
|
|
83
94
|
aria-label="Pagination"
|
|
84
95
|
data-size-variant={sizeAttr}
|
|
@@ -88,8 +99,8 @@
|
|
|
88
99
|
type="button"
|
|
89
100
|
class="page nav-btn"
|
|
90
101
|
aria-label="Previous page"
|
|
91
|
-
disabled={
|
|
92
|
-
onclick={() =>
|
|
102
|
+
disabled={paginationStepperDisabled(pagination, 'prev')}
|
|
103
|
+
onclick={() => apply(paginationStep(pagination, 'prev'))}
|
|
93
104
|
>
|
|
94
105
|
<!-- ‹ › are Bidi_Mirrored (UAX #9, rule L4): in an RTL context the browser
|
|
95
106
|
already draws them flipped, so no transform is needed (one would
|
|
@@ -98,18 +109,17 @@
|
|
|
98
109
|
</button>
|
|
99
110
|
|
|
100
111
|
{#each slots as slot (slot)}
|
|
101
|
-
{#if slot
|
|
112
|
+
{#if paginationIsGap(slot)}
|
|
102
113
|
<span class="ellipsis" aria-hidden="true">…</span>
|
|
103
114
|
{:else}
|
|
104
|
-
{@const
|
|
115
|
+
{@const attrs = paginationPageAttrs(slot, current)}
|
|
105
116
|
<button
|
|
106
117
|
type="button"
|
|
107
118
|
class="page"
|
|
108
|
-
class:active={
|
|
109
|
-
|
|
110
|
-
aria-label={`Page ${slot}`}
|
|
119
|
+
class:active={attrs['aria-current'] === 'page'}
|
|
120
|
+
{...attrs}
|
|
111
121
|
{disabled}
|
|
112
|
-
onclick={() =>
|
|
122
|
+
onclick={() => apply(paginationPagePress(pagination, slot))}
|
|
113
123
|
>
|
|
114
124
|
{slot}
|
|
115
125
|
</button>
|
|
@@ -120,8 +130,8 @@
|
|
|
120
130
|
type="button"
|
|
121
131
|
class="page nav-btn"
|
|
122
132
|
aria-label="Next page"
|
|
123
|
-
disabled={
|
|
124
|
-
onclick={() =>
|
|
133
|
+
disabled={paginationStepperDisabled(pagination, 'next')}
|
|
134
|
+
onclick={() => apply(paginationStep(pagination, 'next'))}
|
|
125
135
|
>
|
|
126
136
|
<span aria-hidden="true">›</span>
|
|
127
137
|
</button>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Size } from '../config.js';
|
|
2
|
+
import { type PaginationChangeDetails } from '../core/pagination.js';
|
|
2
3
|
interface Props {
|
|
3
4
|
/** Current page, 1-based (bindable). */
|
|
4
5
|
page?: number;
|
|
@@ -14,8 +15,11 @@ interface Props {
|
|
|
14
15
|
disabled?: boolean;
|
|
15
16
|
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
16
17
|
size?: Size;
|
|
17
|
-
/**
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Fired when the page changes (after `page` updates), with the new page and what changed
|
|
20
|
+
* it (`details.reason`: page · prev · next).
|
|
21
|
+
*/
|
|
22
|
+
onchange?: (page: number, details: PaginationChangeDetails) => void;
|
|
19
23
|
}
|
|
20
24
|
declare const Pagination: import("svelte").Component<Props, {}, "page">;
|
|
21
25
|
type Pagination = ReturnType<typeof Pagination>;
|