dssoca 0.12.0 → 0.13.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/dist/components/Kbd.svelte +120 -0
- package/dist/components/Kbd.svelte.d.ts +30 -0
- package/dist/components/SearchPalette.svelte +526 -0
- package/dist/components/SearchPalette.svelte.d.ts +82 -0
- package/dist/components/ShortcutsHelp.svelte +365 -0
- package/dist/components/ShortcutsHelp.svelte.d.ts +34 -0
- package/dist/components/Switch.svelte +32 -2
- package/dist/components/Switch.svelte.d.ts +5 -0
- package/dist/components/Topbar.svelte +39 -24
- package/dist/components/Topbar.svelte.d.ts +5 -2
- package/dist/dssoca.config.d.ts +1 -1
- package/dist/dssoca.config.js +2 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/shortcuts.svelte.d.ts +192 -0
- package/dist/shortcuts.svelte.js +633 -0
- package/package.json +2 -2
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export interface SearchPaletteItem {
|
|
2
|
+
/** Stable unique id (keys the option and its DOM id). */
|
|
3
|
+
id: string;
|
|
4
|
+
/** Primary text; also the default filter haystack. */
|
|
5
|
+
label: string;
|
|
6
|
+
/** Secondary muted line under the label (default row rendering). */
|
|
7
|
+
hint?: string;
|
|
8
|
+
/** When set, the option renders as a real <a>; Enter clicks it so routing stays native. */
|
|
9
|
+
href?: string;
|
|
10
|
+
/** Group heading; groups render in first-appearance order, ungrouped items first. */
|
|
11
|
+
group?: string;
|
|
12
|
+
/** Extra strings matched by the internal filter. */
|
|
13
|
+
keywords?: string[];
|
|
14
|
+
/** Rendered but not selectable; skipped by keyboard navigation. */
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
}
|
|
17
|
+
import { type Snippet } from 'svelte';
|
|
18
|
+
import { type Size } from '../config.js';
|
|
19
|
+
declare function $$render<T extends SearchPaletteItem>(): {
|
|
20
|
+
props: {
|
|
21
|
+
/** Whether the palette is shown. Bindable — sync it from caller state. */
|
|
22
|
+
open?: boolean;
|
|
23
|
+
/** Entries to show. With external filtering, pass the already-filtered list. */
|
|
24
|
+
items: T[];
|
|
25
|
+
/** Search text. Bindable — bind it when you own filtering (`filter={false}`). */
|
|
26
|
+
query?: string;
|
|
27
|
+
/** Internal substring filter over label+keywords. Set false when the consumer filters. @default true */
|
|
28
|
+
filter?: boolean;
|
|
29
|
+
/** Global toggle shortcut, registered through the shortcut registry as
|
|
30
|
+
* `ss:search-palette` (DS-0139) — listed in ShortcutsHelp, obeys
|
|
31
|
+
* `setEnabled`/`remap`. 'mod+k' = Cmd+K on mac, Ctrl+K elsewhere
|
|
32
|
+
* (platform modifier only); false disables. @default 'mod+k' */
|
|
33
|
+
shortcut?: "mod+k" | false;
|
|
34
|
+
/** Input placeholder. @default 'Search…' */
|
|
35
|
+
placeholder?: string;
|
|
36
|
+
/** Accessible name for the dialog, input and listbox. @default 'Search' */
|
|
37
|
+
'aria-label'?: string;
|
|
38
|
+
/** No-results text (used when the `empty` snippet is absent). @default 'No results' */
|
|
39
|
+
emptyText?: string;
|
|
40
|
+
/** Footer hint row; false hides it. A `footer` snippet replaces it. @default '↑↓ navigate · ↵ open · esc close' */
|
|
41
|
+
footerText?: string | false;
|
|
42
|
+
/** Clear the query and selection when the palette closes. @default true */
|
|
43
|
+
resetOnClose?: boolean;
|
|
44
|
+
/** Token size (sm|md|lg); controls the panel width. Inherits the global size when unset. */
|
|
45
|
+
size?: Size;
|
|
46
|
+
/** Called with the chosen item on Enter/click. Return false to keep the palette open. */
|
|
47
|
+
onselect?: (item: T) => void | boolean;
|
|
48
|
+
/** Called after the palette opens. */
|
|
49
|
+
onopen?: () => void;
|
|
50
|
+
/** Called after the palette closes (Esc, backdrop, selection). */
|
|
51
|
+
onclose?: () => void;
|
|
52
|
+
/** Replaces the default option row body (label + hint). */
|
|
53
|
+
item?: Snippet<[T, {
|
|
54
|
+
active: boolean;
|
|
55
|
+
}]>;
|
|
56
|
+
/** Replaces the default no-results state; receives the current query. */
|
|
57
|
+
empty?: Snippet<[string]>;
|
|
58
|
+
/** Replaces the footer text row. */
|
|
59
|
+
footer?: Snippet;
|
|
60
|
+
};
|
|
61
|
+
exports: {};
|
|
62
|
+
bindings: "open" | "query";
|
|
63
|
+
slots: {};
|
|
64
|
+
events: {};
|
|
65
|
+
};
|
|
66
|
+
declare class __sveltets_Render<T extends SearchPaletteItem> {
|
|
67
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
68
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
69
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
70
|
+
bindings(): "open" | "query";
|
|
71
|
+
exports(): {};
|
|
72
|
+
}
|
|
73
|
+
interface $$IsomorphicComponent {
|
|
74
|
+
new <T extends SearchPaletteItem>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
75
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
76
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
77
|
+
<T extends SearchPaletteItem>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
78
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
79
|
+
}
|
|
80
|
+
declare const SearchPalette: $$IsomorphicComponent;
|
|
81
|
+
type SearchPalette<T extends SearchPaletteItem> = InstanceType<typeof SearchPalette<T>>;
|
|
82
|
+
export default SearchPalette;
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
3
|
+
// ShortcutsHelp (DS-0138). The GitHub/Slack/Linear "?" discovery overlay.
|
|
4
|
+
// Composes Modal — the native <dialog> hands us the focus trap, Esc-close,
|
|
5
|
+
// backdrop and focus return (SC 2.1.2 / 2.4.3) — and renders the LIVE
|
|
6
|
+
// registry state: groups, labels, effective bindings after remaps, and
|
|
7
|
+
// disabled shortcuts struck through with a visible "(off)" (SC 2.1.4 truth,
|
|
8
|
+
// never hidden).
|
|
9
|
+
//
|
|
10
|
+
// Its own hotkey goes through the registry like any consumer shortcut
|
|
11
|
+
// (id `ss:shortcuts-help`), so it lists itself and is disable-able and
|
|
12
|
+
// remappable. The default `'?, mod+/'` keeps discovery alive when the
|
|
13
|
+
// `characterKeys` kill switch is off ('?' dies, mod+/ survives) and under
|
|
14
|
+
// screen-reader browse mode.
|
|
15
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
16
|
+
import type { Snippet } from 'svelte'
|
|
17
|
+
import Modal from './Modal.svelte'
|
|
18
|
+
import Kbd from './Kbd.svelte'
|
|
19
|
+
import Button from './Button.svelte'
|
|
20
|
+
import Switch from './Switch.svelte'
|
|
21
|
+
import EmptyState from './EmptyState.svelte'
|
|
22
|
+
import {
|
|
23
|
+
shortcuts,
|
|
24
|
+
comboFromEvent,
|
|
25
|
+
isReservedCombo,
|
|
26
|
+
formatShortcut,
|
|
27
|
+
type ShortcutInfo,
|
|
28
|
+
} from '../shortcuts.svelte.js'
|
|
29
|
+
|
|
30
|
+
interface Props {
|
|
31
|
+
/** Whether the overlay is shown. Bindable — control it, or let the hotkey manage it. */
|
|
32
|
+
open?: boolean
|
|
33
|
+
/** Dialog title (wires the dialog's accessible name). @default 'Keyboard shortcuts' */
|
|
34
|
+
title?: string
|
|
35
|
+
/**
|
|
36
|
+
* Combo(s) that open the overlay, self-registered through the registry
|
|
37
|
+
* (id `ss:shortcuts-help`, group "General") — it appears in its own list
|
|
38
|
+
* and is itself disable-able/remappable. `null` registers nothing
|
|
39
|
+
* (wire your own visible trigger). @default '?, mod+/'
|
|
40
|
+
*/
|
|
41
|
+
hotkey?: string | null
|
|
42
|
+
/**
|
|
43
|
+
* Explicit section order (group names). Unlisted groups follow in
|
|
44
|
+
* registration order; by default "General" (also the bucket for
|
|
45
|
+
* ungrouped shortcuts) comes last.
|
|
46
|
+
*/
|
|
47
|
+
groupOrder?: string[]
|
|
48
|
+
/**
|
|
49
|
+
* Built-in WCAG 2.1.4 settings UI: every row gains an enable Switch
|
|
50
|
+
* (`setEnabled`), a Change button that records the next keydown as the
|
|
51
|
+
* new binding (`remap`; Esc cancels), and a Reset once remapped
|
|
52
|
+
* (`remap(id, null)`); a footer adds the global single-key kill switch
|
|
53
|
+
* (`characterKeys`) and Restore defaults (`resetOverrides`). Persistence
|
|
54
|
+
* stays app policy — see `getOverrides`/`applyOverrides`. @default false
|
|
55
|
+
*/
|
|
56
|
+
editable?: boolean
|
|
57
|
+
/** Extra content rendered below the shortcut list. */
|
|
58
|
+
children?: Snippet
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let {
|
|
62
|
+
open = $bindable(false),
|
|
63
|
+
title = 'Keyboard shortcuts',
|
|
64
|
+
hotkey = '?, mod+/',
|
|
65
|
+
groupOrder,
|
|
66
|
+
editable = false,
|
|
67
|
+
children,
|
|
68
|
+
}: Props = $props()
|
|
69
|
+
|
|
70
|
+
const FALLBACK_GROUP = 'General'
|
|
71
|
+
|
|
72
|
+
// Self-registration. `add()` returns the disposer, which doubles as the
|
|
73
|
+
// effect's cleanup: unmount unregisters, a `hotkey` change re-registers.
|
|
74
|
+
// Effects never run on the server, so SSR stays registration-free.
|
|
75
|
+
$effect(() => {
|
|
76
|
+
if (hotkey === null) return
|
|
77
|
+
return shortcuts.add({
|
|
78
|
+
id: 'ss:shortcuts-help',
|
|
79
|
+
label: 'Show keyboard shortcuts',
|
|
80
|
+
group: FALLBACK_GROUP,
|
|
81
|
+
keys: hotkey,
|
|
82
|
+
onPress: () => {
|
|
83
|
+
open = true
|
|
84
|
+
},
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
interface Group {
|
|
89
|
+
name: string
|
|
90
|
+
items: ShortcutInfo[]
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Live grouping of the registry: buckets in first-appearance order with
|
|
94
|
+
// "General" forced last; an explicit `groupOrder` lists its named groups
|
|
95
|
+
// first and the rest keep the default order.
|
|
96
|
+
const groups: Group[] = $derived.by(() => {
|
|
97
|
+
const buckets: Group[] = []
|
|
98
|
+
for (const item of shortcuts.items) {
|
|
99
|
+
const name = item.group ?? FALLBACK_GROUP
|
|
100
|
+
const bucket = buckets.find((g) => g.name === name)
|
|
101
|
+
if (bucket) bucket.items.push(item)
|
|
102
|
+
else buckets.push({ name, items: [item] })
|
|
103
|
+
}
|
|
104
|
+
let ordered = buckets.filter((g) => g.name !== FALLBACK_GROUP)
|
|
105
|
+
const general = buckets.find((g) => g.name === FALLBACK_GROUP)
|
|
106
|
+
if (general) ordered.push(general)
|
|
107
|
+
if (groupOrder?.length) {
|
|
108
|
+
const explicit = groupOrder
|
|
109
|
+
.map((n) => ordered.find((g) => g.name === n))
|
|
110
|
+
.filter((g): g is Group => g !== undefined)
|
|
111
|
+
ordered = [...explicit, ...ordered.filter((g) => !explicit.includes(g))]
|
|
112
|
+
}
|
|
113
|
+
return ordered
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
// ── Editable mode (DS-0141) — remap recorder + live announcements ────────
|
|
117
|
+
// One shortcut records at a time; `status` feeds the visible role="status"
|
|
118
|
+
// line, so prompts, results and rejections are both shown and announced.
|
|
119
|
+
let recordingId = $state<string | null>(null)
|
|
120
|
+
let status = $state('')
|
|
121
|
+
|
|
122
|
+
// Announcement-friendly words ("Control+Shift+S"), not glyphs.
|
|
123
|
+
const spoken = (keys: string) => formatShortcut(keys, { format: 'label' })
|
|
124
|
+
|
|
125
|
+
function startRecording(item: ShortcutInfo) {
|
|
126
|
+
recordingId = item.id
|
|
127
|
+
status = `Press the new shortcut for "${item.label}" — Escape cancels.`
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function cancelRecording() {
|
|
131
|
+
recordingId = null
|
|
132
|
+
status = 'Shortcut change cancelled.'
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function resetRow(item: ShortcutInfo) {
|
|
136
|
+
shortcuts.remap(item.id, null)
|
|
137
|
+
status = `"${item.label}" restored to ${spoken(item.defaultKeys)}.`
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function restoreDefaults() {
|
|
141
|
+
recordingId = null
|
|
142
|
+
shortcuts.resetOverrides()
|
|
143
|
+
status = 'All shortcuts restored to their defaults.'
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// While recording, a window-capture listener owns every keydown: it runs
|
|
147
|
+
// before anything else for keys pressed inside the dialog, and its
|
|
148
|
+
// preventDefault doubles as registry suppression (the matcher skips
|
|
149
|
+
// defaultPrevented events; the open modal already suppresses globals —
|
|
150
|
+
// SC 2.1.2). Modifier-only presses are a chord in progress; bare Escape
|
|
151
|
+
// cancels; everything else is validated through the registry parser via
|
|
152
|
+
// `remap` — reserved browser combos and unparseable keys are rejected with
|
|
153
|
+
// feedback and recording stays live for another try.
|
|
154
|
+
$effect(() => {
|
|
155
|
+
if (recordingId === null) return
|
|
156
|
+
const id = recordingId
|
|
157
|
+
const onKeydown = (event: KeyboardEvent) => {
|
|
158
|
+
event.preventDefault()
|
|
159
|
+
event.stopPropagation()
|
|
160
|
+
const combo = comboFromEvent(event)
|
|
161
|
+
if (combo === null) return
|
|
162
|
+
if (combo === 'escape') {
|
|
163
|
+
cancelRecording()
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
const label = shortcuts.items.find((i) => i.id === id)?.label ?? id
|
|
167
|
+
let reserved: boolean
|
|
168
|
+
try {
|
|
169
|
+
reserved = isReservedCombo(combo)
|
|
170
|
+
} catch {
|
|
171
|
+
status = 'That key cannot be used — try another combination.'
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
if (reserved) {
|
|
175
|
+
status = `${spoken(combo)} is reserved by the browser — try another combination.`
|
|
176
|
+
return
|
|
177
|
+
}
|
|
178
|
+
shortcuts.remap(id, combo)
|
|
179
|
+
recordingId = null
|
|
180
|
+
status = `"${label}" is now ${spoken(combo)}.`
|
|
181
|
+
}
|
|
182
|
+
window.addEventListener('keydown', onKeydown, true)
|
|
183
|
+
return () => window.removeEventListener('keydown', onKeydown, true)
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
// Closing the dialog (Esc, backdrop, trigger) abandons any recording and
|
|
187
|
+
// clears the status line so a reopen starts clean.
|
|
188
|
+
$effect(() => {
|
|
189
|
+
if (open) return
|
|
190
|
+
recordingId = null
|
|
191
|
+
status = ''
|
|
192
|
+
})
|
|
193
|
+
</script>
|
|
194
|
+
|
|
195
|
+
<Modal bind:open {title}>
|
|
196
|
+
<div class="ss-shortcuts-help">
|
|
197
|
+
{#if groups.length === 0}
|
|
198
|
+
<EmptyState
|
|
199
|
+
compact
|
|
200
|
+
icon="⌨"
|
|
201
|
+
headingLevel={3}
|
|
202
|
+
title="No shortcuts registered"
|
|
203
|
+
message="Shortcuts added through the dssoca registry will show up here."
|
|
204
|
+
/>
|
|
205
|
+
{:else}
|
|
206
|
+
{#each groups as group (group.name)}
|
|
207
|
+
<section class="group">
|
|
208
|
+
<h3 class="gname">{group.name}</h3>
|
|
209
|
+
<dl class="rows">
|
|
210
|
+
<!-- Key by position too: duplicate ids are a dev warning in the
|
|
211
|
+
registry, not a render crash here. -->
|
|
212
|
+
{#each group.items as item, i (`${item.id}:${i}`)}
|
|
213
|
+
<div class="row" class:off={!item.enabled} class:recording={recordingId === item.id}>
|
|
214
|
+
<dt class="label">
|
|
215
|
+
<span class="txt">{item.label}</span>
|
|
216
|
+
{#if !item.enabled}<span class="off-tag">(off)</span>{/if}
|
|
217
|
+
</dt>
|
|
218
|
+
<dd class="keys">
|
|
219
|
+
{#if recordingId === item.id}
|
|
220
|
+
<span class="prompt">Press keys…</span>
|
|
221
|
+
{:else}
|
|
222
|
+
<Kbd keys={item.keys} />
|
|
223
|
+
{/if}
|
|
224
|
+
</dd>
|
|
225
|
+
{#if editable}
|
|
226
|
+
<dd class="controls">
|
|
227
|
+
{#if item.keys !== item.defaultKeys}
|
|
228
|
+
<Button
|
|
229
|
+
variant="ghost"
|
|
230
|
+
size="sm"
|
|
231
|
+
aria-label={`Reset the shortcut for "${item.label}" to its default`}
|
|
232
|
+
onclick={() => resetRow(item)}>Reset</Button
|
|
233
|
+
>
|
|
234
|
+
{/if}
|
|
235
|
+
<Button
|
|
236
|
+
variant="ghost"
|
|
237
|
+
size="sm"
|
|
238
|
+
aria-label={recordingId === item.id
|
|
239
|
+
? `Recording a new shortcut for "${item.label}" — press keys, Escape cancels`
|
|
240
|
+
: `Change the shortcut for "${item.label}"`}
|
|
241
|
+
onclick={() =>
|
|
242
|
+
recordingId === item.id ? cancelRecording() : startRecording(item)}
|
|
243
|
+
>
|
|
244
|
+
{recordingId === item.id ? 'Cancel' : 'Change'}
|
|
245
|
+
</Button>
|
|
246
|
+
<Switch
|
|
247
|
+
size="sm"
|
|
248
|
+
labelHidden
|
|
249
|
+
label={`Enable the "${item.label}" shortcut`}
|
|
250
|
+
checked={item.enabled}
|
|
251
|
+
onchange={(on) => shortcuts.setEnabled(item.id, on)}
|
|
252
|
+
/>
|
|
253
|
+
</dd>
|
|
254
|
+
{/if}
|
|
255
|
+
</div>
|
|
256
|
+
{/each}
|
|
257
|
+
</dl>
|
|
258
|
+
</section>
|
|
259
|
+
{/each}
|
|
260
|
+
{/if}
|
|
261
|
+
{#if editable}
|
|
262
|
+
<!-- WCAG 2.1.4 global remedies: the character-key kill switch and a
|
|
263
|
+
one-click way back. Persistence stays app policy (getOverrides). -->
|
|
264
|
+
<div class="globals">
|
|
265
|
+
<Switch
|
|
266
|
+
size="sm"
|
|
267
|
+
label="Single-key shortcuts"
|
|
268
|
+
checked={shortcuts.characterKeys}
|
|
269
|
+
onchange={(on) => (shortcuts.characterKeys = on)}
|
|
270
|
+
/>
|
|
271
|
+
<Button variant="ghost" size="sm" onclick={restoreDefaults}>Restore defaults</Button>
|
|
272
|
+
</div>
|
|
273
|
+
<!-- Always-rendered live region: recording prompts, results and
|
|
274
|
+
rejections are announced as well as shown. -->
|
|
275
|
+
<p class="status" role="status">{status}</p>
|
|
276
|
+
{/if}
|
|
277
|
+
{#if children}
|
|
278
|
+
<div class="extra">{@render children()}</div>
|
|
279
|
+
{/if}
|
|
280
|
+
</div>
|
|
281
|
+
</Modal>
|
|
282
|
+
|
|
283
|
+
<style>.ss-shortcuts-help {
|
|
284
|
+
display: flex;
|
|
285
|
+
flex-direction: column;
|
|
286
|
+
gap: var(--ss-gap-sm);
|
|
287
|
+
font-size: var(--ss-size-sm);
|
|
288
|
+
}
|
|
289
|
+
.ss-shortcuts-help .group {
|
|
290
|
+
min-width: 0;
|
|
291
|
+
}
|
|
292
|
+
.ss-shortcuts-help .gname {
|
|
293
|
+
margin: 0;
|
|
294
|
+
font-family: var(--ss-font-mono);
|
|
295
|
+
font-size: var(--ss-ui-sm);
|
|
296
|
+
font-weight: 400;
|
|
297
|
+
color: var(--ss-fg-faint);
|
|
298
|
+
text-transform: uppercase;
|
|
299
|
+
letter-spacing: 0.06em;
|
|
300
|
+
}
|
|
301
|
+
.ss-shortcuts-help .rows {
|
|
302
|
+
margin: 0;
|
|
303
|
+
}
|
|
304
|
+
.ss-shortcuts-help .row {
|
|
305
|
+
display: flex;
|
|
306
|
+
align-items: center;
|
|
307
|
+
justify-content: space-between;
|
|
308
|
+
gap: var(--ss-gap-sm);
|
|
309
|
+
padding: var(--ss-s-2) 0;
|
|
310
|
+
border-bottom: 1px solid var(--ss-line);
|
|
311
|
+
}
|
|
312
|
+
.ss-shortcuts-help .row:last-child {
|
|
313
|
+
border-bottom: 0;
|
|
314
|
+
}
|
|
315
|
+
.ss-shortcuts-help .label {
|
|
316
|
+
margin: 0;
|
|
317
|
+
min-width: 0;
|
|
318
|
+
color: var(--ss-fg);
|
|
319
|
+
}
|
|
320
|
+
.ss-shortcuts-help .keys {
|
|
321
|
+
margin: 0;
|
|
322
|
+
flex: none;
|
|
323
|
+
}
|
|
324
|
+
.ss-shortcuts-help .controls {
|
|
325
|
+
margin: 0;
|
|
326
|
+
flex: none;
|
|
327
|
+
display: flex;
|
|
328
|
+
align-items: center;
|
|
329
|
+
gap: var(--ss-s-1);
|
|
330
|
+
}
|
|
331
|
+
.ss-shortcuts-help .row.recording {
|
|
332
|
+
background: var(--ss-primary-soft);
|
|
333
|
+
}
|
|
334
|
+
.ss-shortcuts-help .prompt {
|
|
335
|
+
font-family: var(--ss-font-mono);
|
|
336
|
+
font-size: var(--ss-ui-sm);
|
|
337
|
+
color: var(--ss-primary);
|
|
338
|
+
}
|
|
339
|
+
.ss-shortcuts-help .row.off .label {
|
|
340
|
+
color: var(--ss-fg-muted);
|
|
341
|
+
}
|
|
342
|
+
.ss-shortcuts-help .row.off .txt {
|
|
343
|
+
text-decoration: line-through;
|
|
344
|
+
}
|
|
345
|
+
.ss-shortcuts-help .off-tag {
|
|
346
|
+
margin-left: var(--ss-s-1);
|
|
347
|
+
color: var(--ss-fg-muted);
|
|
348
|
+
}
|
|
349
|
+
.ss-shortcuts-help .extra {
|
|
350
|
+
color: var(--ss-fg-muted);
|
|
351
|
+
}
|
|
352
|
+
.ss-shortcuts-help .globals {
|
|
353
|
+
display: flex;
|
|
354
|
+
align-items: center;
|
|
355
|
+
justify-content: space-between;
|
|
356
|
+
gap: var(--ss-gap-sm);
|
|
357
|
+
padding-top: var(--ss-s-2);
|
|
358
|
+
border-top: 1px solid var(--ss-line);
|
|
359
|
+
}
|
|
360
|
+
.ss-shortcuts-help .status {
|
|
361
|
+
margin: 0;
|
|
362
|
+
min-height: 1.4em;
|
|
363
|
+
font-size: var(--ss-ui-sm);
|
|
364
|
+
color: var(--ss-fg-muted);
|
|
365
|
+
}</style>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** Whether the overlay is shown. Bindable — control it, or let the hotkey manage it. */
|
|
4
|
+
open?: boolean;
|
|
5
|
+
/** Dialog title (wires the dialog's accessible name). @default 'Keyboard shortcuts' */
|
|
6
|
+
title?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Combo(s) that open the overlay, self-registered through the registry
|
|
9
|
+
* (id `ss:shortcuts-help`, group "General") — it appears in its own list
|
|
10
|
+
* and is itself disable-able/remappable. `null` registers nothing
|
|
11
|
+
* (wire your own visible trigger). @default '?, mod+/'
|
|
12
|
+
*/
|
|
13
|
+
hotkey?: string | null;
|
|
14
|
+
/**
|
|
15
|
+
* Explicit section order (group names). Unlisted groups follow in
|
|
16
|
+
* registration order; by default "General" (also the bucket for
|
|
17
|
+
* ungrouped shortcuts) comes last.
|
|
18
|
+
*/
|
|
19
|
+
groupOrder?: string[];
|
|
20
|
+
/**
|
|
21
|
+
* Built-in WCAG 2.1.4 settings UI: every row gains an enable Switch
|
|
22
|
+
* (`setEnabled`), a Change button that records the next keydown as the
|
|
23
|
+
* new binding (`remap`; Esc cancels), and a Reset once remapped
|
|
24
|
+
* (`remap(id, null)`); a footer adds the global single-key kill switch
|
|
25
|
+
* (`characterKeys`) and Restore defaults (`resetOverrides`). Persistence
|
|
26
|
+
* stays app policy — see `getOverrides`/`applyOverrides`. @default false
|
|
27
|
+
*/
|
|
28
|
+
editable?: boolean;
|
|
29
|
+
/** Extra content rendered below the shortcut list. */
|
|
30
|
+
children?: Snippet;
|
|
31
|
+
}
|
|
32
|
+
declare const ShortcutsHelp: import("svelte").Component<Props, {}, "open">;
|
|
33
|
+
type ShortcutsHelp = ReturnType<typeof ShortcutsHelp>;
|
|
34
|
+
export default ShortcutsHelp;
|
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
checked?: boolean
|
|
15
15
|
/** Visible label rendered adjacent to the track; becomes the accessible name. */
|
|
16
16
|
label?: string
|
|
17
|
+
/**
|
|
18
|
+
* Visually hide the label while keeping it as the accessible name — for
|
|
19
|
+
* dense rows (settings lists) where the visible context sits elsewhere.
|
|
20
|
+
*/
|
|
21
|
+
labelHidden?: boolean
|
|
17
22
|
/** Id for the underlying button (label `for`-style association uses it). */
|
|
18
23
|
id?: string
|
|
19
24
|
/** Form field name (mirrored onto a data attribute for form integration). */
|
|
@@ -31,6 +36,7 @@
|
|
|
31
36
|
let {
|
|
32
37
|
checked = $bindable(false),
|
|
33
38
|
label,
|
|
39
|
+
labelHidden = false,
|
|
34
40
|
id,
|
|
35
41
|
name,
|
|
36
42
|
disabled = false,
|
|
@@ -55,7 +61,11 @@
|
|
|
55
61
|
const sizeAttr = $derived(resolveComponentSize('Switch', size))
|
|
56
62
|
</script>
|
|
57
63
|
|
|
58
|
-
<span
|
|
64
|
+
<span
|
|
65
|
+
class="ss-switch"
|
|
66
|
+
class:has-label={label != null && !labelHidden}
|
|
67
|
+
data-size-variant={sizeAttr}
|
|
68
|
+
>
|
|
59
69
|
<button
|
|
60
70
|
id={buttonId}
|
|
61
71
|
type="button"
|
|
@@ -73,13 +83,22 @@
|
|
|
73
83
|
</button>
|
|
74
84
|
{#if label != null}
|
|
75
85
|
<!-- Clicking the label toggles the switch (a11y: same target as the control). -->
|
|
76
|
-
<span
|
|
86
|
+
<span
|
|
87
|
+
id={labelId}
|
|
88
|
+
class="label"
|
|
89
|
+
class:sr-only={labelHidden}
|
|
90
|
+
onclick={toggle}
|
|
91
|
+
role="presentation">{label}</span
|
|
92
|
+
>
|
|
77
93
|
{/if}
|
|
78
94
|
</span>
|
|
79
95
|
|
|
80
96
|
<style>.ss-switch {
|
|
97
|
+
position: relative;
|
|
81
98
|
display: inline-flex;
|
|
82
99
|
align-items: center;
|
|
100
|
+
}
|
|
101
|
+
.ss-switch.has-label {
|
|
83
102
|
gap: var(--ss-switch-gap, var(--ss-gap-sm));
|
|
84
103
|
}
|
|
85
104
|
.ss-switch .track {
|
|
@@ -131,6 +150,17 @@
|
|
|
131
150
|
cursor: pointer;
|
|
132
151
|
user-select: none;
|
|
133
152
|
}
|
|
153
|
+
.ss-switch .label.sr-only {
|
|
154
|
+
position: absolute;
|
|
155
|
+
width: 1px;
|
|
156
|
+
height: 1px;
|
|
157
|
+
padding: 0;
|
|
158
|
+
margin: -1px;
|
|
159
|
+
overflow: hidden;
|
|
160
|
+
clip: rect(0, 0, 0, 0);
|
|
161
|
+
white-space: nowrap;
|
|
162
|
+
border: 0;
|
|
163
|
+
}
|
|
134
164
|
.ss-switch:has(.track:disabled) .label {
|
|
135
165
|
cursor: not-allowed;
|
|
136
166
|
opacity: 0.45;
|
|
@@ -4,6 +4,11 @@ interface Props {
|
|
|
4
4
|
checked?: boolean;
|
|
5
5
|
/** Visible label rendered adjacent to the track; becomes the accessible name. */
|
|
6
6
|
label?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Visually hide the label while keeping it as the accessible name — for
|
|
9
|
+
* dense rows (settings lists) where the visible context sits elsewhere.
|
|
10
|
+
*/
|
|
11
|
+
labelHidden?: boolean;
|
|
7
12
|
/** Id for the underlying button (label `for`-style association uses it). */
|
|
8
13
|
id?: string;
|
|
9
14
|
/** Form field name (mirrored onto a data attribute for form integration). */
|
|
@@ -22,6 +22,13 @@
|
|
|
22
22
|
<script lang="ts">
|
|
23
23
|
import type { Snippet } from 'svelte'
|
|
24
24
|
import { resolveComponentSize, type Size } from '../config.js'
|
|
25
|
+
import {
|
|
26
|
+
ariaKeyshortcuts,
|
|
27
|
+
detectPlatform,
|
|
28
|
+
shortcuts,
|
|
29
|
+
type ShortcutPlatform,
|
|
30
|
+
} from '../shortcuts.svelte.js'
|
|
31
|
+
import Kbd from './Kbd.svelte'
|
|
25
32
|
|
|
26
33
|
interface Stat {
|
|
27
34
|
key: string
|
|
@@ -36,8 +43,11 @@
|
|
|
36
43
|
tabs?: Array<string | TopbarTab>
|
|
37
44
|
/** Fired with the tab id when a tab is activated (also for `href` tabs). */
|
|
38
45
|
onTab?: (tab: string) => void
|
|
39
|
-
/** Fired when the command menu is opened (chip click or Cmd
|
|
40
|
-
*
|
|
46
|
+
/** Fired when the command menu is opened (chip click or mod+K — Cmd+K on
|
|
47
|
+
* Apple platforms, Ctrl+K elsewhere). Registered through the shortcut
|
|
48
|
+
* registry as `ss:topbar-command` (DS-0139), so it lists in ShortcutsHelp
|
|
49
|
+
* and obeys `setEnabled`/`remap`. The ⌘K chip and the shortcut only
|
|
50
|
+
* exist when this handler is provided. */
|
|
41
51
|
onCommand?: () => void
|
|
42
52
|
/** Fired when the user chip is activated (when no `userMenu` snippet given). */
|
|
43
53
|
onUser?: () => void
|
|
@@ -88,10 +98,14 @@
|
|
|
88
98
|
size,
|
|
89
99
|
}: Props = $props()
|
|
90
100
|
|
|
91
|
-
//
|
|
92
|
-
//
|
|
93
|
-
// and
|
|
94
|
-
|
|
101
|
+
// Platform detection mirrors Kbd's hydration posture (DS-0139): 'other' on
|
|
102
|
+
// the server and the first client render, corrected in an effect so server
|
|
103
|
+
// and client first paints agree.
|
|
104
|
+
let platform = $state<ShortcutPlatform>('other')
|
|
105
|
+
$effect(() => {
|
|
106
|
+
// not a writable $derived: detection must NOT run during hydration render
|
|
107
|
+
if (platform === 'other') platform = detectPlatform()
|
|
108
|
+
})
|
|
95
109
|
|
|
96
110
|
// DS-0080: normalize both tab shapes to one internal form. `string` tabs
|
|
97
111
|
// keep id === label; object tabs default `label` to `id`.
|
|
@@ -122,18 +136,23 @@
|
|
|
122
136
|
time = nowStr()
|
|
123
137
|
}, 1000)
|
|
124
138
|
: undefined
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
139
|
+
// DS-0139: the shortcut goes through the registry (id `ss:topbar-command`)
|
|
140
|
+
// instead of a hand-rolled window listener — discoverable in ShortcutsHelp,
|
|
141
|
+
// disable/remap-able (WCAG 2.1.4), deterministic on collision. Only claim
|
|
142
|
+
// mod+k when a command handler exists (DS-0081) — otherwise leave the
|
|
143
|
+
// browser's default alone. `add()` is SSR-safe (no-op without `window`).
|
|
144
|
+
const dispose = onCommand
|
|
145
|
+
? shortcuts.add({
|
|
146
|
+
id: 'ss:topbar-command',
|
|
147
|
+
label: 'Open command menu',
|
|
148
|
+
keys: 'mod+k',
|
|
149
|
+
allowInInputs: true, // chorded — safe while typing, like Slack/GitHub
|
|
150
|
+
onPress: () => onCommand?.(),
|
|
151
|
+
})
|
|
152
|
+
: undefined
|
|
134
153
|
return () => {
|
|
135
154
|
if (t) clearInterval(t)
|
|
136
|
-
|
|
155
|
+
dispose?.()
|
|
137
156
|
}
|
|
138
157
|
})
|
|
139
158
|
|
|
@@ -248,11 +267,11 @@
|
|
|
248
267
|
{#if onCommand}
|
|
249
268
|
<button
|
|
250
269
|
class="seg right click cmd"
|
|
251
|
-
aria-keyshortcuts=
|
|
270
|
+
aria-keyshortcuts={ariaKeyshortcuts('mod+k', platform)}
|
|
252
271
|
aria-label="Open command menu"
|
|
253
272
|
onclick={() => onCommand?.()}
|
|
254
273
|
>
|
|
255
|
-
<span class="kbd" aria-hidden="true"
|
|
274
|
+
<span class="kbd" aria-hidden="true"><Kbd keys="mod+k" {platform} {size} /></span>
|
|
256
275
|
</button>
|
|
257
276
|
{/if}
|
|
258
277
|
|
|
@@ -417,12 +436,8 @@
|
|
|
417
436
|
margin: 0 2px;
|
|
418
437
|
}
|
|
419
438
|
.ss-topbar .kbd {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
color: var(--ss-fg-muted);
|
|
423
|
-
border: 1px solid var(--ss-line);
|
|
424
|
-
padding: 2px 5px;
|
|
425
|
-
line-height: 1;
|
|
439
|
+
display: inline-flex;
|
|
440
|
+
align-items: center;
|
|
426
441
|
}
|
|
427
442
|
@media (max-width: 720px) {
|
|
428
443
|
.ss-topbar .collapsible {
|