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.
@@ -29,8 +29,11 @@ interface Props {
29
29
  tabs?: Array<string | TopbarTab>;
30
30
  /** Fired with the tab id when a tab is activated (also for `href` tabs). */
31
31
  onTab?: (tab: string) => void;
32
- /** Fired when the command menu is opened (chip click or Cmd/Ctrl+K).
33
- * The ⌘K chip and the shortcut only exist when this handler is provided. */
32
+ /** Fired when the command menu is opened (chip click or mod+K — Cmd+K on
33
+ * Apple platforms, Ctrl+K elsewhere). Registered through the shortcut
34
+ * registry as `ss:topbar-command` (DS-0139), so it lists in ShortcutsHelp
35
+ * and obeys `setEnabled`/`remap`. The ⌘K chip and the shortcut only
36
+ * exist when this handler is provided. */
34
37
  onCommand?: () => void;
35
38
  /** Fired when the user chip is activated (when no `userMenu` snippet given). */
36
39
  onUser?: () => void;
@@ -81,7 +81,7 @@ export interface Palette {
81
81
  /** Size axis values — derived from the manifest (`'sm' | 'md' | 'lg'`). */
82
82
  export type Size = (typeof dssocaConfig)['size']['values'][number];
83
83
  /** Names of the components that accept a `size` prop / `componentsSize` entry. */
84
- export declare const COMPONENT_NAMES: readonly ["Accordion", "Avatar", "Badge", "BottomNav", "Button", "Card", "Chart", "Container", "DateField", "EmptyState", "FileDrop", "Heading", "Icon", "Image", "Input", "Link", "LogStream", "Menu", "MetricTile", "Modal", "NumberField", "Pagination", "SegmentedControl", "Select", "ServiceCard", "Sidebar", "Sparkline", "Spinner", "Switch", "Table", "Textarea", "Toaster", "Tooltip", "Topbar"];
84
+ export declare const COMPONENT_NAMES: readonly ["Accordion", "Avatar", "Badge", "BottomNav", "Button", "Card", "Chart", "Container", "DateField", "EmptyState", "FileDrop", "Heading", "Icon", "Image", "Input", "Kbd", "Link", "LogStream", "Menu", "MetricTile", "Modal", "NumberField", "Pagination", "SearchPalette", "SegmentedControl", "Select", "ServiceCard", "Sidebar", "Sparkline", "Spinner", "Switch", "Table", "Textarea", "Toaster", "Tooltip", "Topbar"];
85
85
  export type ComponentName = (typeof COMPONENT_NAMES)[number];
86
86
  /** Per-component default sizes; any omitted component inherits `sizeVariant`. */
87
87
  export type ComponentsSize = Partial<Record<ComponentName, Size>>;
@@ -85,6 +85,7 @@ export const COMPONENT_NAMES = [
85
85
  'Icon',
86
86
  'Image',
87
87
  'Input',
88
+ 'Kbd',
88
89
  'Link',
89
90
  'LogStream',
90
91
  'Menu',
@@ -92,6 +93,7 @@ export const COMPONENT_NAMES = [
92
93
  'Modal',
93
94
  'NumberField',
94
95
  'Pagination',
96
+ 'SearchPalette',
95
97
  'SegmentedControl',
96
98
  'Select',
97
99
  'ServiceCard',
package/dist/index.d.ts CHANGED
@@ -39,8 +39,12 @@ export { default as Tooltip } from './components/Tooltip.svelte';
39
39
  export { default as Avatar } from './components/Avatar.svelte';
40
40
  export { default as Pagination } from './components/Pagination.svelte';
41
41
  export { default as Switch } from './components/Switch.svelte';
42
+ export { default as SearchPalette, type SearchPaletteItem } from './components/SearchPalette.svelte';
42
43
  export { default as ScatterPlot, type ScatterPoint } from './components/ScatterPlot.svelte';
43
44
  export { default as BoxPlot, type BoxGroup } from './components/BoxPlot.svelte';
44
45
  export { default as BumpChart, type BumpSeries } from './components/BumpChart.svelte';
45
46
  export { default as Heatmap } from './components/Heatmap.svelte';
47
+ export { default as Kbd } from './components/Kbd.svelte';
48
+ export { default as ShortcutsHelp } from './components/ShortcutsHelp.svelte';
49
+ export { shortcuts, shortcut, formatShortcut, ariaKeyshortcuts, type ShortcutOptions, type ShortcutInfo, type ShortcutOverride, type ShortcutOverrides, type ShortcutScope, type ShortcutPlatform, type ShortcutFormat, type FormatShortcutOptions, } from './shortcuts.svelte.js';
46
50
  export { toast, toasts, type Toast, type ToastKind, type ToastAction, type ToastOptions, type ToastPatch, type PromiseMessages, } from './toast.svelte.js';
package/dist/index.js CHANGED
@@ -43,9 +43,14 @@ export { default as Tooltip } from './components/Tooltip.svelte';
43
43
  export { default as Avatar } from './components/Avatar.svelte';
44
44
  export { default as Pagination } from './components/Pagination.svelte';
45
45
  export { default as Switch } from './components/Switch.svelte';
46
+ export { default as SearchPalette } from './components/SearchPalette.svelte';
46
47
  // geossoca stats-dashboard charts (DS-0102).
47
48
  export { default as ScatterPlot } from './components/ScatterPlot.svelte';
48
49
  export { default as BoxPlot } from './components/BoxPlot.svelte';
49
50
  export { default as BumpChart } from './components/BumpChart.svelte';
50
51
  export { default as Heatmap } from './components/Heatmap.svelte';
52
+ // Keyboard-shortcuts feature (DS-0135): registry core + display chip.
53
+ export { default as Kbd } from './components/Kbd.svelte';
54
+ export { default as ShortcutsHelp } from './components/ShortcutsHelp.svelte';
55
+ export { shortcuts, shortcut, formatShortcut, ariaKeyshortcuts, } from './shortcuts.svelte.js';
51
56
  export { toast, toasts, } from './toast.svelte.js';
@@ -0,0 +1,192 @@
1
+ import type { Attachment } from 'svelte/attachments';
2
+ /** Where a shortcut listens: everywhere, or only while focus is inside the attached element. */
3
+ export type ShortcutScope = 'global' | 'focus';
4
+ /** Modifier rendering family: Apple (⌘/⌥) vs everything else (Ctrl/Alt). */
5
+ export type ShortcutPlatform = 'apple' | 'other';
6
+ /** Presentation style for `formatShortcut`. */
7
+ export type ShortcutFormat = 'glyph' | 'label';
8
+ export interface ShortcutOptions {
9
+ /**
10
+ * Stable unique identifier — the handle for `setEnabled` / `remap` and the
11
+ * key under which overrides persist. dssoca-owned shortcuts use the `ss:*`
12
+ * namespace; apps should pick their own prefix.
13
+ */
14
+ id: string;
15
+ /** Human-readable action name (shown by ShortcutsHelp, read by AT). */
16
+ label: string;
17
+ /**
18
+ * Key combo(s): `+`-joined modifiers (`mod`|`ctrl`|`alt`|`shift`|`meta`)
19
+ * plus exactly one key (lowercased `event.key`: `k`, `?`, `escape`,
20
+ * `arrowup`, `f1`). `mod` resolves to `meta` on Apple platforms and `ctrl`
21
+ * elsewhere. Comma separates alternatives (`'?, mod+/'`). Space is
22
+ * reserved (sequences are a parse error). Malformed input throws at
23
+ * registration time.
24
+ */
25
+ keys: string;
26
+ /** Invoked when the shortcut fires (after `preventDefault` unless opted out). */
27
+ onPress: (event: KeyboardEvent) => void;
28
+ /** Optional grouping label for display (ShortcutsHelp sections). */
29
+ group?: string;
30
+ /**
31
+ * `'global'` (default) listens on `window`; `'focus'` only fires while the
32
+ * event target is inside the attached element — use via the `shortcut()`
33
+ * attachment (a focus-scoped shortcut without an element never fires).
34
+ */
35
+ scope?: ShortcutScope;
36
+ /**
37
+ * Contextual availability gate owned by the registering code. A user-level
38
+ * `setEnabled(id, false)` override additionally silences the shortcut; the
39
+ * shortcut fires only when *both* agree.
40
+ */
41
+ enabled?: boolean | (() => boolean);
42
+ /** Fire even when typing in inputs/textareas/selects/contenteditable. */
43
+ allowInInputs?: boolean;
44
+ /** Fire on held-key auto-repeat events. */
45
+ allowRepeat?: boolean;
46
+ /** Call `event.preventDefault()` before `onPress`. Default `true`. */
47
+ preventDefault?: boolean;
48
+ }
49
+ /** Read-only view of a registered shortcut (feeds ShortcutsHelp). */
50
+ export interface ShortcutInfo {
51
+ id: string;
52
+ label: string;
53
+ group?: string;
54
+ scope: ShortcutScope;
55
+ /** Effective canonical combo — the remap override when one is set. */
56
+ keys: string;
57
+ /** Canonical combo as registered (what `remap(id, null)` restores). */
58
+ defaultKeys: string;
59
+ /** Effective state: user override AND the registration's own `enabled`. */
60
+ enabled: boolean;
61
+ }
62
+ /** Per-shortcut user override (both fields optional and independent). */
63
+ export interface ShortcutOverride {
64
+ enabled?: boolean;
65
+ /** Canonical remapped combo string. */
66
+ keys?: string;
67
+ }
68
+ /**
69
+ * Serializable snapshot of every user-facing shortcut setting — including the
70
+ * global `enabled` / `characterKeys` toggles (WCAG 2.1.4 compliance that
71
+ * resets every visit isn't compliance). Persist it wherever your app keeps
72
+ * preferences and feed it back through `applyOverrides`.
73
+ */
74
+ export interface ShortcutOverrides {
75
+ enabled?: boolean;
76
+ characterKeys?: boolean;
77
+ shortcuts?: Record<string, ShortcutOverride>;
78
+ }
79
+ export interface FormatShortcutOptions {
80
+ /** `'glyph'` (default): `⌘K` / `Ctrl+K`. `'label'`: `Command+K` / `Ctrl+K`. */
81
+ format?: ShortcutFormat;
82
+ /** Defaults to the detected platform. */
83
+ platform?: ShortcutPlatform;
84
+ }
85
+ /**
86
+ * Canonical combo string for a captured keydown — feeds the editable
87
+ * ShortcutsHelp recorder. Modifier-only presses return `null` (the user is
88
+ * mid-chord; keep waiting). Shifted printables keep the produced character
89
+ * (`?`, never `shift+/`), matching the matcher's shift rule. The result may
90
+ * still fail `parseKeys` (e.g. the space key) — recorders validate via
91
+ * `remap`. File-level export — not part of the public barrel surface.
92
+ */
93
+ export declare function comboFromEvent(event: KeyboardEvent): string | null;
94
+ /**
95
+ * Whether any alternative in `keys` is a combo the browser/OS reserves for
96
+ * tab/window control. Registration merely dev-warns (`warnReservedCombos`);
97
+ * the ShortcutsHelp recorder rejects these outright. Accepts the literal
98
+ * `ctrl+`/`meta+` forms a recorded event produces as well as `mod+`
99
+ * spellings. Throws on malformed input (same grammar as registration).
100
+ * File-level export — not part of the public barrel surface.
101
+ */
102
+ export declare function isReservedCombo(keys: string): boolean;
103
+ /**
104
+ * Detected modifier-rendering platform. File-level export for `<Kbd>`'s
105
+ * client-side correction effect — not part of the public barrel surface.
106
+ */
107
+ export declare function detectPlatform(): ShortcutPlatform;
108
+ /**
109
+ * Module-singleton keyboard-shortcut registry (Svelte 5 runes; house pattern
110
+ * of `toast.svelte.ts`). One lazy `window` keydown listener (bubble phase)
111
+ * serves every registration: attached on the first browser-side `add()`,
112
+ * detached when the registry empties. Exactly one shortcut fires per event —
113
+ * focus-scoped beats global, last-registered wins within a tier.
114
+ *
115
+ * The class is intentionally NOT exported: a second instance would break the
116
+ * "exactly one fires" guarantee. Use the `shortcuts` singleton.
117
+ */
118
+ declare class ShortcutRegistry {
119
+ #private;
120
+ /** Global kill switch (WCAG 2.1.4 "turn off"). */
121
+ enabled: boolean;
122
+ /**
123
+ * When `false`, modifier-less ("character key") bindings never fire — the
124
+ * GitHub-style WCAG 2.1.4 switch. `mod+`/`ctrl+`/`alt+` combos are unaffected.
125
+ */
126
+ characterKeys: boolean;
127
+ /** Reactive read-only list of registered shortcuts, registration order. */
128
+ readonly items: readonly ShortcutInfo[];
129
+ /**
130
+ * Register a shortcut; returns an idempotent disposer. Throws on a
131
+ * malformed `keys` string. On the server (no `window`) this is a full
132
+ * no-op that returns a working noop disposer.
133
+ *
134
+ * The optional `element` is supplied by the `shortcut()` attachment and
135
+ * anchors `scope: 'focus'` registrations.
136
+ */
137
+ add(options: ShortcutOptions, element?: Element): () => void;
138
+ /** User-level enable/disable override for one shortcut (persists in overrides). */
139
+ setEnabled(id: string, enabled: boolean): void;
140
+ /**
141
+ * Rebind a shortcut to new keys (parsed/validated immediately — throws on
142
+ * malformed input). `remap(id, null)` removes the override, restoring the
143
+ * registered default.
144
+ */
145
+ remap(id: string, keys: string | null): void;
146
+ /** Serializable snapshot of the global toggles + every per-id override. */
147
+ getOverrides(): ShortcutOverrides;
148
+ /**
149
+ * Merge a persisted overrides snapshot back in. Overrides for ids that are
150
+ * not (yet) registered are kept and take effect when the shortcut mounts.
151
+ * Malformed persisted combos are skipped with a dev warning (stale storage
152
+ * must not crash the app).
153
+ */
154
+ applyOverrides(overrides: ShortcutOverrides): void;
155
+ /** Clear every per-id override and restore the global toggles to defaults. */
156
+ resetOverrides(): void;
157
+ }
158
+ /** The one app-wide shortcut registry. */
159
+ export declare const shortcuts: ShortcutRegistry;
160
+ /**
161
+ * `{@attach}` sugar over `shortcuts.add()`: registers on mount, cleans up on
162
+ * unmount, and re-registers reactively when a thunk's dependencies change.
163
+ * The attached element anchors `scope: 'focus'` shortcuts (they only fire
164
+ * while the event target is inside it).
165
+ *
166
+ * ```svelte
167
+ * <section {@attach shortcut(() => ({ id: 'app:save', label: 'Save', keys: 'mod+s', onPress: save }))}>
168
+ * ```
169
+ */
170
+ export declare function shortcut(options: ShortcutOptions | (() => ShortcutOptions)): Attachment;
171
+ /**
172
+ * Structured form behind `formatShortcut`: one keycap-string array per
173
+ * comma-alternative (`'?, mod+/'` on other → `[['?'], ['Ctrl', '/']]`).
174
+ * File-level export so `<Kbd>` can render one `<kbd>` per key without
175
+ * re-deriving the glyph/label tables — not part of the public barrel surface.
176
+ * Throws on malformed input (same grammar as registration).
177
+ */
178
+ export declare function formatShortcutParts(keys: string, options?: FormatShortcutOptions): string[][];
179
+ /**
180
+ * Human-readable rendering of a combo string, for `<Kbd>`-style display.
181
+ * Alternatives are joined with ` / `. Apple glyphs concatenate (`⌘K`, the
182
+ * macOS convention); everything else joins with `+` (`Ctrl+K`). Throws on
183
+ * malformed input (same grammar as registration).
184
+ */
185
+ export declare function formatShortcut(keys: string, options?: FormatShortcutOptions): string;
186
+ /**
187
+ * The combo in `aria-keyshortcuts` spec syntax (`Meta+K`), with `mod`
188
+ * resolved for the given (default: detected) platform. Alternatives are
189
+ * space-separated per the spec. Throws on malformed input.
190
+ */
191
+ export declare function ariaKeyshortcuts(keys: string, platform?: ShortcutPlatform): string;
192
+ export {};