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
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SegmentedControl core (DS-0197) — the radiogroup's behaviour, decided once for
|
|
3
|
+
* SegmentedControl.svelte and `vanilla/segmented.ts`: what a press or a key selects, which
|
|
4
|
+
* segment owns the tab stop, and the state attributes. Pure functions: no DOM, no Svelte. The
|
|
5
|
+
* reading direction is read by the caller and passed in as `rtl`.
|
|
6
|
+
*/
|
|
7
|
+
import { rovingStep, rovingTabindex } from './behaviors/roving.js';
|
|
8
|
+
const select = (state, index, focus, reason) => state.enabled.includes(index)
|
|
9
|
+
? { type: 'select', index, changed: index !== state.selected, focus, reason }
|
|
10
|
+
: null;
|
|
11
|
+
/** A segment was pressed. `null` when it (or the group) is disabled. */
|
|
12
|
+
export function segmentedPress(state, index) {
|
|
13
|
+
return select(state, index, false, 'press');
|
|
14
|
+
}
|
|
15
|
+
function moveFor(key, rtl) {
|
|
16
|
+
switch (key) {
|
|
17
|
+
// Left/Right follow the visual order: under RTL the row runs right-to-left, so ArrowLeft
|
|
18
|
+
// points at the NEXT segment. Up/Down stay logical.
|
|
19
|
+
case 'ArrowRight':
|
|
20
|
+
return rtl ? 'prev' : 'next';
|
|
21
|
+
case 'ArrowLeft':
|
|
22
|
+
return rtl ? 'next' : 'prev';
|
|
23
|
+
case 'ArrowDown':
|
|
24
|
+
return 'next';
|
|
25
|
+
case 'ArrowUp':
|
|
26
|
+
return 'prev';
|
|
27
|
+
case 'Home':
|
|
28
|
+
return 'first';
|
|
29
|
+
case 'End':
|
|
30
|
+
return 'last';
|
|
31
|
+
default:
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A key on segment `index`. Arrows / Home / End move over the enabled segments (wrapping) and
|
|
37
|
+
* select the target. `null` = not a group key, or nothing is enabled: let it through.
|
|
38
|
+
*/
|
|
39
|
+
export function segmentedKey(state, index, key, rtl = false) {
|
|
40
|
+
const move = moveFor(key, rtl);
|
|
41
|
+
if (!move)
|
|
42
|
+
return null;
|
|
43
|
+
// A segment that is not enabled is no position to step from: fall back to an edge.
|
|
44
|
+
const from = state.enabled.includes(index) ? index : -1;
|
|
45
|
+
const action = select(state, rovingStep(state.enabled, from, move), true, 'key');
|
|
46
|
+
return action && { action, preventDefault: true };
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The index that owns the group's single tab stop: the selected segment when it is enabled,
|
|
50
|
+
* otherwise the first enabled one; `-1` when nothing is enabled.
|
|
51
|
+
*/
|
|
52
|
+
export function segmentedTabStop(state) {
|
|
53
|
+
return state.enabled.includes(state.selected) ? state.selected : (state.enabled[0] ?? -1);
|
|
54
|
+
}
|
|
55
|
+
// --- attributes ---------------------------------------------------------------
|
|
56
|
+
// Strings, not booleans, so the Svelte spread and the vanilla `setAttribute` write the same DOM.
|
|
57
|
+
export function segmentedGroupAttrs(disabled) {
|
|
58
|
+
return { role: 'radiogroup', 'aria-disabled': disabled ? 'true' : undefined };
|
|
59
|
+
}
|
|
60
|
+
export function segmentedItemAttrs(index, selected, tabStop) {
|
|
61
|
+
return {
|
|
62
|
+
role: 'radio',
|
|
63
|
+
'aria-checked': index === selected ? 'true' : 'false',
|
|
64
|
+
tabindex: rovingTabindex(index, tabStop),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ShortcutsHelp core (DS-0197) — what the overlay decides beyond the shortcut registry itself:
|
|
3
|
+
* how the registered shortcuts are sectioned, and what a key pressed while recording a new
|
|
4
|
+
* binding does. Pure functions; ShortcutsHelp.svelte reads the registry and applies the result.
|
|
5
|
+
* No DOM, no Svelte.
|
|
6
|
+
*/
|
|
7
|
+
/** The bucket for ungrouped shortcuts; sorted last by default. */
|
|
8
|
+
export declare const SHORTCUTS_FALLBACK_GROUP = "General";
|
|
9
|
+
export interface ShortcutsHelpGroup<T> {
|
|
10
|
+
name: string;
|
|
11
|
+
items: T[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Section the shortcuts: buckets in first-appearance order with "General" forced last; an
|
|
15
|
+
* explicit `groupOrder` lists its named groups first and the rest keep the default order.
|
|
16
|
+
*/
|
|
17
|
+
export declare function shortcutsHelpGroups<T extends {
|
|
18
|
+
group?: string;
|
|
19
|
+
}>(items: readonly T[], groupOrder?: readonly string[]): ShortcutsHelpGroup<T>[];
|
|
20
|
+
/** The row's Change / Cancel button: start recording that shortcut, or cancel if it already is. */
|
|
21
|
+
export declare function shortcutsHelpRecordPress(recordingId: string | null, id: string): {
|
|
22
|
+
type: 'start';
|
|
23
|
+
id: string;
|
|
24
|
+
} | {
|
|
25
|
+
type: 'cancel';
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* How the registry judged a pressed combo: usable, reserved by the browser, or not parseable
|
|
29
|
+
* as a binding at all.
|
|
30
|
+
*/
|
|
31
|
+
export type ShortcutComboVerdict = 'ok' | 'reserved' | 'invalid';
|
|
32
|
+
export type ShortcutsHelpRecordAction =
|
|
33
|
+
/** Modifier-only press: a chord in progress, keep listening. */
|
|
34
|
+
{
|
|
35
|
+
type: 'wait';
|
|
36
|
+
}
|
|
37
|
+
/** Bare Escape: abandon the recording. */
|
|
38
|
+
| {
|
|
39
|
+
type: 'cancel';
|
|
40
|
+
}
|
|
41
|
+
/** The combo cannot be bound; recording stays live for another try. */
|
|
42
|
+
| {
|
|
43
|
+
type: 'reject';
|
|
44
|
+
why: 'reserved' | 'invalid';
|
|
45
|
+
combo: string;
|
|
46
|
+
}
|
|
47
|
+
/** Bind the combo and stop recording. */
|
|
48
|
+
| {
|
|
49
|
+
type: 'remap';
|
|
50
|
+
combo: string;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* A keydown while recording. `combo` is the registry's normalized combo for the event (`null`
|
|
54
|
+
* for a modifier-only press); `verdict` is only asked for when the combo is a candidate.
|
|
55
|
+
*/
|
|
56
|
+
export declare function shortcutsHelpRecordKey(combo: string | null, verdict: (combo: string) => ShortcutComboVerdict): ShortcutsHelpRecordAction;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ShortcutsHelp core (DS-0197) — what the overlay decides beyond the shortcut registry itself:
|
|
3
|
+
* how the registered shortcuts are sectioned, and what a key pressed while recording a new
|
|
4
|
+
* binding does. Pure functions; ShortcutsHelp.svelte reads the registry and applies the result.
|
|
5
|
+
* No DOM, no Svelte.
|
|
6
|
+
*/
|
|
7
|
+
/** The bucket for ungrouped shortcuts; sorted last by default. */
|
|
8
|
+
export const SHORTCUTS_FALLBACK_GROUP = 'General';
|
|
9
|
+
/**
|
|
10
|
+
* Section the shortcuts: buckets in first-appearance order with "General" forced last; an
|
|
11
|
+
* explicit `groupOrder` lists its named groups first and the rest keep the default order.
|
|
12
|
+
*/
|
|
13
|
+
export function shortcutsHelpGroups(items, groupOrder) {
|
|
14
|
+
const buckets = [];
|
|
15
|
+
for (const item of items) {
|
|
16
|
+
const name = item.group ?? SHORTCUTS_FALLBACK_GROUP;
|
|
17
|
+
const bucket = buckets.find((g) => g.name === name);
|
|
18
|
+
if (bucket)
|
|
19
|
+
bucket.items.push(item);
|
|
20
|
+
else
|
|
21
|
+
buckets.push({ name, items: [item] });
|
|
22
|
+
}
|
|
23
|
+
let ordered = buckets.filter((g) => g.name !== SHORTCUTS_FALLBACK_GROUP);
|
|
24
|
+
const general = buckets.find((g) => g.name === SHORTCUTS_FALLBACK_GROUP);
|
|
25
|
+
if (general)
|
|
26
|
+
ordered.push(general);
|
|
27
|
+
if (groupOrder?.length) {
|
|
28
|
+
const explicit = groupOrder
|
|
29
|
+
.map((n) => ordered.find((g) => g.name === n))
|
|
30
|
+
.filter((g) => g !== undefined);
|
|
31
|
+
ordered = [...explicit, ...ordered.filter((g) => !explicit.includes(g))];
|
|
32
|
+
}
|
|
33
|
+
return ordered;
|
|
34
|
+
}
|
|
35
|
+
/** The row's Change / Cancel button: start recording that shortcut, or cancel if it already is. */
|
|
36
|
+
export function shortcutsHelpRecordPress(recordingId, id) {
|
|
37
|
+
return recordingId === id ? { type: 'cancel' } : { type: 'start', id };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A keydown while recording. `combo` is the registry's normalized combo for the event (`null`
|
|
41
|
+
* for a modifier-only press); `verdict` is only asked for when the combo is a candidate.
|
|
42
|
+
*/
|
|
43
|
+
export function shortcutsHelpRecordKey(combo, verdict) {
|
|
44
|
+
if (combo === null)
|
|
45
|
+
return { type: 'wait' };
|
|
46
|
+
if (combo === 'escape')
|
|
47
|
+
return { type: 'cancel' };
|
|
48
|
+
const judged = verdict(combo);
|
|
49
|
+
return judged === 'ok' ? { type: 'remap', combo } : { type: 'reject', why: judged, combo };
|
|
50
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sidebar core (DS-0197) — the decisions behind the nav rail: which item is active, whether a
|
|
3
|
+
* disclosure is open, what a key on a button-like item does, what the collapse toggle reports
|
|
4
|
+
* and how an item is named when the rail is icon-only. Pure functions; Sidebar.svelte holds the
|
|
5
|
+
* state and applies the result. No DOM, no Svelte.
|
|
6
|
+
*/
|
|
7
|
+
export type SidebarStatus = 'up' | 'deg' | 'down';
|
|
8
|
+
/** The fields of a nav item the core reads. */
|
|
9
|
+
export interface SidebarItemLike {
|
|
10
|
+
id: string;
|
|
11
|
+
label: string;
|
|
12
|
+
status?: SidebarStatus;
|
|
13
|
+
external?: boolean;
|
|
14
|
+
badge?: string | number;
|
|
15
|
+
children?: readonly SidebarItemLike[];
|
|
16
|
+
}
|
|
17
|
+
/** The word announced next to a status dot; empty for `up` (the quiet default). */
|
|
18
|
+
export declare const SIDEBAR_STATUS_WORD: Record<SidebarStatus, string>;
|
|
19
|
+
/** Whether a badge value renders at all (`0` does, an empty string does not). */
|
|
20
|
+
export declare function sidebarHasBadge(badge: string | number | undefined | null): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The accessible name of an item in the collapsed (icon-only) rail: the label plus the
|
|
23
|
+
* degraded/down status, the badge and the new-tab hint, so nothing the expanded row shows is lost.
|
|
24
|
+
*/
|
|
25
|
+
export declare function sidebarItemName(item: SidebarItemLike): string;
|
|
26
|
+
export declare function sidebarIsActive(item: SidebarItemLike, active: string | undefined): boolean;
|
|
27
|
+
/** A parent disclosure is "active-within" when it or any of its children is active. */
|
|
28
|
+
export declare function sidebarActiveWithin(item: SidebarItemLike, active: string | undefined): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Whether a disclosure is open. `toggled` is the user's own choice for it (`undefined` until
|
|
31
|
+
* they press it): before that it follows the active item, afterwards the choice wins.
|
|
32
|
+
*/
|
|
33
|
+
export declare function sidebarDisclosureOpen(item: SidebarItemLike, active: string | undefined, toggled: boolean | undefined): boolean;
|
|
34
|
+
/** The disclosure button was pressed: the next value of its `toggled` choice. */
|
|
35
|
+
export declare function sidebarDisclosurePress(item: SidebarItemLike, active: string | undefined, toggled: boolean | undefined): boolean;
|
|
36
|
+
/** The collapse toggle was pressed: the `collapsed` value to report. */
|
|
37
|
+
export declare function sidebarCollapsePress(collapsed: boolean): boolean;
|
|
38
|
+
/** A key the sidebar handles: what it does, and whether the browser default must be cancelled. */
|
|
39
|
+
export interface SidebarKeyResult {
|
|
40
|
+
action: {
|
|
41
|
+
type: 'select';
|
|
42
|
+
};
|
|
43
|
+
preventDefault: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A key on a button-like item (`role="button"`, no `href`): Enter and Space select it, like a
|
|
47
|
+
* native button. `null` = not a sidebar key, let it through.
|
|
48
|
+
*/
|
|
49
|
+
export declare function sidebarItemKey(key: string): SidebarKeyResult | null;
|
|
50
|
+
/** The collapse toggle: expanded is the opposite of collapsed. */
|
|
51
|
+
export declare function sidebarToggleAttrs(collapsed: boolean): {
|
|
52
|
+
readonly 'aria-expanded': "true" | "false";
|
|
53
|
+
};
|
|
54
|
+
export declare function sidebarDisclosureAttrs(open: boolean, panelId: string): {
|
|
55
|
+
readonly 'aria-expanded': "true" | "false";
|
|
56
|
+
readonly 'aria-controls': string;
|
|
57
|
+
};
|
|
58
|
+
/** State of a link / button-like item; the name is only forced in the collapsed rail. */
|
|
59
|
+
export declare function sidebarItemAttrs(item: SidebarItemLike, active: string | undefined, collapsed: boolean): {
|
|
60
|
+
readonly 'aria-current': "page" | undefined;
|
|
61
|
+
readonly 'aria-label': string | undefined;
|
|
62
|
+
readonly title: string | undefined;
|
|
63
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sidebar core (DS-0197) — the decisions behind the nav rail: which item is active, whether a
|
|
3
|
+
* disclosure is open, what a key on a button-like item does, what the collapse toggle reports
|
|
4
|
+
* and how an item is named when the rail is icon-only. Pure functions; Sidebar.svelte holds the
|
|
5
|
+
* state and applies the result. No DOM, no Svelte.
|
|
6
|
+
*/
|
|
7
|
+
/** The word announced next to a status dot; empty for `up` (the quiet default). */
|
|
8
|
+
export const SIDEBAR_STATUS_WORD = {
|
|
9
|
+
up: '',
|
|
10
|
+
deg: 'degraded',
|
|
11
|
+
down: 'down',
|
|
12
|
+
};
|
|
13
|
+
/** Whether a badge value renders at all (`0` does, an empty string does not). */
|
|
14
|
+
export function sidebarHasBadge(badge) {
|
|
15
|
+
return badge != null && badge !== '';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The accessible name of an item in the collapsed (icon-only) rail: the label plus the
|
|
19
|
+
* degraded/down status, the badge and the new-tab hint, so nothing the expanded row shows is lost.
|
|
20
|
+
*/
|
|
21
|
+
export function sidebarItemName(item) {
|
|
22
|
+
const parts = [item.label];
|
|
23
|
+
if (item.status && SIDEBAR_STATUS_WORD[item.status])
|
|
24
|
+
parts.push(SIDEBAR_STATUS_WORD[item.status]);
|
|
25
|
+
if (sidebarHasBadge(item.badge))
|
|
26
|
+
parts.push(`${item.badge}`);
|
|
27
|
+
if (item.external)
|
|
28
|
+
parts.push('opens in a new tab');
|
|
29
|
+
return parts.join(', ');
|
|
30
|
+
}
|
|
31
|
+
export function sidebarIsActive(item, active) {
|
|
32
|
+
return item.id === active;
|
|
33
|
+
}
|
|
34
|
+
/** A parent disclosure is "active-within" when it or any of its children is active. */
|
|
35
|
+
export function sidebarActiveWithin(item, active) {
|
|
36
|
+
return sidebarIsActive(item, active) || !!item.children?.some((c) => sidebarIsActive(c, active));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Whether a disclosure is open. `toggled` is the user's own choice for it (`undefined` until
|
|
40
|
+
* they press it): before that it follows the active item, afterwards the choice wins.
|
|
41
|
+
*/
|
|
42
|
+
export function sidebarDisclosureOpen(item, active, toggled) {
|
|
43
|
+
return toggled ?? sidebarActiveWithin(item, active);
|
|
44
|
+
}
|
|
45
|
+
/** The disclosure button was pressed: the next value of its `toggled` choice. */
|
|
46
|
+
export function sidebarDisclosurePress(item, active, toggled) {
|
|
47
|
+
return !sidebarDisclosureOpen(item, active, toggled);
|
|
48
|
+
}
|
|
49
|
+
/** The collapse toggle was pressed: the `collapsed` value to report. */
|
|
50
|
+
export function sidebarCollapsePress(collapsed) {
|
|
51
|
+
return !collapsed;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A key on a button-like item (`role="button"`, no `href`): Enter and Space select it, like a
|
|
55
|
+
* native button. `null` = not a sidebar key, let it through.
|
|
56
|
+
*/
|
|
57
|
+
export function sidebarItemKey(key) {
|
|
58
|
+
switch (key) {
|
|
59
|
+
case 'Enter':
|
|
60
|
+
case ' ':
|
|
61
|
+
return { action: { type: 'select' }, preventDefault: true };
|
|
62
|
+
default:
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// --- attributes ---------------------------------------------------------------
|
|
67
|
+
// Strings, not booleans, so a spread writes the same DOM everywhere.
|
|
68
|
+
const bool = (value) => (value ? 'true' : 'false');
|
|
69
|
+
/** The collapse toggle: expanded is the opposite of collapsed. */
|
|
70
|
+
export function sidebarToggleAttrs(collapsed) {
|
|
71
|
+
return { 'aria-expanded': bool(!collapsed) };
|
|
72
|
+
}
|
|
73
|
+
export function sidebarDisclosureAttrs(open, panelId) {
|
|
74
|
+
return { 'aria-expanded': bool(open), 'aria-controls': panelId };
|
|
75
|
+
}
|
|
76
|
+
/** State of a link / button-like item; the name is only forced in the collapsed rail. */
|
|
77
|
+
export function sidebarItemAttrs(item, active, collapsed) {
|
|
78
|
+
const name = collapsed ? sidebarItemName(item) : undefined;
|
|
79
|
+
return {
|
|
80
|
+
'aria-current': sidebarIsActive(item, active) ? 'page' : undefined,
|
|
81
|
+
'aria-label': name,
|
|
82
|
+
title: name,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Switch core (DS-0198) — the toggle decision and the state attributes, shared by Switch.svelte
|
|
3
|
+
* and `vanilla/switch.ts`. No DOM, no Svelte.
|
|
4
|
+
*/
|
|
5
|
+
/** What flipped the switch; passed to `onchange` / `ss:change`. */
|
|
6
|
+
export type SwitchReason = 'track' | 'label';
|
|
7
|
+
export interface SwitchChangeDetails {
|
|
8
|
+
reason: SwitchReason;
|
|
9
|
+
}
|
|
10
|
+
export interface SwitchState {
|
|
11
|
+
checked: boolean;
|
|
12
|
+
disabled: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** The next `checked` value, or `null` when the switch is disabled and must not change. */
|
|
15
|
+
export declare function switchToggle(state: SwitchState): boolean | null;
|
|
16
|
+
export declare function switchTrackAttrs(checked: boolean): {
|
|
17
|
+
readonly role: "switch";
|
|
18
|
+
readonly 'aria-checked': "true" | "false";
|
|
19
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Switch core (DS-0198) — the toggle decision and the state attributes, shared by Switch.svelte
|
|
3
|
+
* and `vanilla/switch.ts`. No DOM, no Svelte.
|
|
4
|
+
*/
|
|
5
|
+
/** The next `checked` value, or `null` when the switch is disabled and must not change. */
|
|
6
|
+
export function switchToggle(state) {
|
|
7
|
+
return state.disabled ? null : !state.checked;
|
|
8
|
+
}
|
|
9
|
+
export function switchTrackAttrs(checked) {
|
|
10
|
+
return { role: 'switch', 'aria-checked': checked ? 'true' : 'false' };
|
|
11
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Table core (DS-0197) — sorting: what a press on a sortable header does, the order of the rows
|
|
3
|
+
* and the attributes that reflect the sort. Pure functions; Table.svelte holds the bound `sort`
|
|
4
|
+
* and applies the result. No DOM, no Svelte.
|
|
5
|
+
*/
|
|
6
|
+
export type TableSortDir = 'asc' | 'desc';
|
|
7
|
+
/** The active sort: a column key and a direction. */
|
|
8
|
+
export interface TableSortState {
|
|
9
|
+
key: string;
|
|
10
|
+
dir: TableSortDir;
|
|
11
|
+
}
|
|
12
|
+
/** What the sort needs to know about a column. */
|
|
13
|
+
export interface TableSortColumn {
|
|
14
|
+
key: string;
|
|
15
|
+
/** Compare the values as numbers rather than as strings. */
|
|
16
|
+
numeric?: boolean;
|
|
17
|
+
}
|
|
18
|
+
type Sort = TableSortState | undefined | null;
|
|
19
|
+
/** A sortable header was pressed: the same column flips direction, a new one starts ascending. */
|
|
20
|
+
export declare function tableToggleSort(sort: Sort, key: string): TableSortState;
|
|
21
|
+
/** `aria-sort` of a sortable column header. */
|
|
22
|
+
export declare function tableAriaSort(sort: Sort, key: string): 'ascending' | 'descending' | 'none';
|
|
23
|
+
/** The glyph in a sortable header: the active direction, or the "sortable" double arrow. */
|
|
24
|
+
export declare function tableSortIndicator(sort: Sort, key: string): '↑' | '↓' | '↕';
|
|
25
|
+
/**
|
|
26
|
+
* The rows in display order. Returns `rows` itself when there is no sort or it names an unknown
|
|
27
|
+
* column; otherwise a sorted copy (numeric columns compare as numbers, the rest as
|
|
28
|
+
* locale-aware strings with nullish values as `''`).
|
|
29
|
+
*/
|
|
30
|
+
export declare function tableSortRows<Row>(rows: readonly Row[], columns: readonly TableSortColumn[], sort: Sort): readonly Row[];
|
|
31
|
+
export type TableAlign = 'start' | 'end' | 'left' | 'right' | 'center';
|
|
32
|
+
/**
|
|
33
|
+
* Logical alignment of a column: legacy `left` / `right` map to `start` / `end` so RTL mirrors,
|
|
34
|
+
* and a numeric column defaults to `end`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function tableColumnAlign(column: {
|
|
37
|
+
align?: TableAlign;
|
|
38
|
+
numeric?: boolean;
|
|
39
|
+
}): 'start' | 'end' | 'center';
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Table core (DS-0197) — sorting: what a press on a sortable header does, the order of the rows
|
|
3
|
+
* and the attributes that reflect the sort. Pure functions; Table.svelte holds the bound `sort`
|
|
4
|
+
* and applies the result. No DOM, no Svelte.
|
|
5
|
+
*/
|
|
6
|
+
const sortsBy = (sort, key) => sort != null && sort.key === key;
|
|
7
|
+
/** A sortable header was pressed: the same column flips direction, a new one starts ascending. */
|
|
8
|
+
export function tableToggleSort(sort, key) {
|
|
9
|
+
return sortsBy(sort, key)
|
|
10
|
+
? { key, dir: sort.dir === 'asc' ? 'desc' : 'asc' }
|
|
11
|
+
: { key, dir: 'asc' };
|
|
12
|
+
}
|
|
13
|
+
/** `aria-sort` of a sortable column header. */
|
|
14
|
+
export function tableAriaSort(sort, key) {
|
|
15
|
+
if (!sortsBy(sort, key))
|
|
16
|
+
return 'none';
|
|
17
|
+
return sort.dir === 'asc' ? 'ascending' : 'descending';
|
|
18
|
+
}
|
|
19
|
+
/** The glyph in a sortable header: the active direction, or the "sortable" double arrow. */
|
|
20
|
+
export function tableSortIndicator(sort, key) {
|
|
21
|
+
if (!sortsBy(sort, key))
|
|
22
|
+
return '↕';
|
|
23
|
+
return sort.dir === 'asc' ? '↑' : '↓';
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The rows in display order. Returns `rows` itself when there is no sort or it names an unknown
|
|
27
|
+
* column; otherwise a sorted copy (numeric columns compare as numbers, the rest as
|
|
28
|
+
* locale-aware strings with nullish values as `''`).
|
|
29
|
+
*/
|
|
30
|
+
export function tableSortRows(rows, columns, sort) {
|
|
31
|
+
if (!sort)
|
|
32
|
+
return rows;
|
|
33
|
+
const col = columns.find((c) => c.key === sort.key);
|
|
34
|
+
if (!col)
|
|
35
|
+
return rows;
|
|
36
|
+
const dir = sort.dir === 'desc' ? -1 : 1;
|
|
37
|
+
const value = (row) => row?.[sort.key];
|
|
38
|
+
return [...rows].sort((a, b) => {
|
|
39
|
+
const av = value(a);
|
|
40
|
+
const bv = value(b);
|
|
41
|
+
if (col.numeric)
|
|
42
|
+
return (Number(av) - Number(bv)) * dir;
|
|
43
|
+
return String(av ?? '').localeCompare(String(bv ?? '')) * dir;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Logical alignment of a column: legacy `left` / `right` map to `start` / `end` so RTL mirrors,
|
|
48
|
+
* and a numeric column defaults to `end`.
|
|
49
|
+
*/
|
|
50
|
+
export function tableColumnAlign(column) {
|
|
51
|
+
const align = column.align ?? (column.numeric ? 'end' : 'start');
|
|
52
|
+
if (align === 'left')
|
|
53
|
+
return 'start';
|
|
54
|
+
if (align === 'right')
|
|
55
|
+
return 'end';
|
|
56
|
+
return align;
|
|
57
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/** What moved the selection; passed to `onChange` / `ss:change`. */
|
|
2
|
+
export type TabsReason = 'press' | 'key';
|
|
3
|
+
/**
|
|
4
|
+
* How the keyboard selects. `'auto'`: moving focus with the arrows selects the tab it lands on.
|
|
5
|
+
* `'manual'`: the arrows only move focus, Enter / Space select the focused tab.
|
|
6
|
+
*/
|
|
7
|
+
export type TabsActivation = 'auto' | 'manual';
|
|
8
|
+
export interface TabsChangeDetails {
|
|
9
|
+
reason: TabsReason;
|
|
10
|
+
}
|
|
11
|
+
export interface TabsState {
|
|
12
|
+
/** Index of the selected tab, `-1` when none. */
|
|
13
|
+
selected: number;
|
|
14
|
+
/** Indexes of the enabled tabs, in DOM order. */
|
|
15
|
+
enabled: readonly number[];
|
|
16
|
+
}
|
|
17
|
+
export type TabsAction = {
|
|
18
|
+
/** Select tab `index`. `changed` is false when it already was the selection (no event). */
|
|
19
|
+
type: 'select';
|
|
20
|
+
index: number;
|
|
21
|
+
changed: boolean;
|
|
22
|
+
/** Move DOM focus to the tab too (keyboard, automatic activation). */
|
|
23
|
+
focus: boolean;
|
|
24
|
+
reason: TabsReason;
|
|
25
|
+
}
|
|
26
|
+
/** Move DOM focus only (keyboard, manual activation). */
|
|
27
|
+
| {
|
|
28
|
+
type: 'focus';
|
|
29
|
+
index: number;
|
|
30
|
+
};
|
|
31
|
+
/** A key the tab list handles: its action, and whether the browser default must be cancelled. */
|
|
32
|
+
export interface TabsKeyResult {
|
|
33
|
+
action: TabsAction;
|
|
34
|
+
preventDefault: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface TabsKeyOptions {
|
|
37
|
+
/** The tab list runs right-to-left: ArrowLeft points at the NEXT tab. */
|
|
38
|
+
rtl?: boolean;
|
|
39
|
+
activation?: TabsActivation;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The tab to show: the one the consumer's value points at, or — when it points at nothing — the
|
|
43
|
+
* first enabled tab, so a panel is always visible. `-1` when there is neither.
|
|
44
|
+
*/
|
|
45
|
+
export declare function tabsSelected(index: number, enabled: readonly number[]): number;
|
|
46
|
+
/** A tab was pressed. `null` when it is disabled. */
|
|
47
|
+
export declare function tabsPress(state: TabsState, index: number): TabsAction | null;
|
|
48
|
+
/**
|
|
49
|
+
* A key on tab `index`. Arrows / Home / End move over the enabled tabs (wrapping): with
|
|
50
|
+
* automatic activation the target is selected as it takes focus, with manual activation it only
|
|
51
|
+
* takes focus and Enter / Space select it. `null` = not a tab-list key, or nothing is enabled:
|
|
52
|
+
* let it through.
|
|
53
|
+
*/
|
|
54
|
+
export declare function tabsKey(state: TabsState, index: number, key: string, { rtl, activation }?: TabsKeyOptions): TabsKeyResult | null;
|
|
55
|
+
/**
|
|
56
|
+
* The index that owns the list's single tab stop: the selected tab when it is enabled, otherwise
|
|
57
|
+
* the first enabled one; `-1` when nothing is enabled.
|
|
58
|
+
*/
|
|
59
|
+
export declare function tabsTabStop(state: TabsState): number;
|
|
60
|
+
export declare function tabsListAttrs(): {
|
|
61
|
+
readonly role: "tablist";
|
|
62
|
+
};
|
|
63
|
+
export interface TabsTabAttrsInput {
|
|
64
|
+
index: number;
|
|
65
|
+
selected: number;
|
|
66
|
+
tabStop: number;
|
|
67
|
+
/** Id of the panel this tab controls. */
|
|
68
|
+
panelId?: string;
|
|
69
|
+
}
|
|
70
|
+
export declare function tabsTabAttrs(tab: TabsTabAttrsInput): {
|
|
71
|
+
readonly role: "tab";
|
|
72
|
+
readonly 'aria-selected': "true" | "false";
|
|
73
|
+
readonly 'aria-controls': string | undefined;
|
|
74
|
+
readonly tabindex: 0 | -1;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* The panel of a tab: named by its tab, and focusable so its content is reachable by Tab even
|
|
78
|
+
* when it holds nothing focusable. Visibility (`hidden`) is written by the caller.
|
|
79
|
+
*/
|
|
80
|
+
export declare function tabsPanelAttrs(tabId?: string): {
|
|
81
|
+
readonly role: "tabpanel";
|
|
82
|
+
readonly 'aria-labelledby': string | undefined;
|
|
83
|
+
readonly tabindex: 0;
|
|
84
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tabs core (DS-0197) — the WAI-ARIA tabs pattern, decided once for Tabs.svelte and
|
|
3
|
+
* `vanilla/tabs.ts`: what a press or a key selects, where a key moves focus, which tab owns the
|
|
4
|
+
* tab stop, and the state attributes. Pure functions: no DOM, no Svelte. The reading direction
|
|
5
|
+
* is read by the caller and passed in as `rtl`.
|
|
6
|
+
*/
|
|
7
|
+
import { rovingStep, rovingTabindex } from './behaviors/roving.js';
|
|
8
|
+
const select = (state, index, focus, reason) => state.enabled.includes(index)
|
|
9
|
+
? { type: 'select', index, changed: index !== state.selected, focus, reason }
|
|
10
|
+
: null;
|
|
11
|
+
/**
|
|
12
|
+
* The tab to show: the one the consumer's value points at, or — when it points at nothing — the
|
|
13
|
+
* first enabled tab, so a panel is always visible. `-1` when there is neither.
|
|
14
|
+
*/
|
|
15
|
+
export function tabsSelected(index, enabled) {
|
|
16
|
+
return index >= 0 ? index : (enabled[0] ?? -1);
|
|
17
|
+
}
|
|
18
|
+
/** A tab was pressed. `null` when it is disabled. */
|
|
19
|
+
export function tabsPress(state, index) {
|
|
20
|
+
return select(state, index, false, 'press');
|
|
21
|
+
}
|
|
22
|
+
function moveFor(key, rtl) {
|
|
23
|
+
switch (key) {
|
|
24
|
+
// Left/Right follow the visual order: under RTL the list runs right-to-left, so ArrowLeft
|
|
25
|
+
// points at the NEXT tab. Up/Down are left to the page (a horizontal tab list).
|
|
26
|
+
case 'ArrowRight':
|
|
27
|
+
return rtl ? 'prev' : 'next';
|
|
28
|
+
case 'ArrowLeft':
|
|
29
|
+
return rtl ? 'next' : 'prev';
|
|
30
|
+
case 'Home':
|
|
31
|
+
return 'first';
|
|
32
|
+
case 'End':
|
|
33
|
+
return 'last';
|
|
34
|
+
default:
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A key on tab `index`. Arrows / Home / End move over the enabled tabs (wrapping): with
|
|
40
|
+
* automatic activation the target is selected as it takes focus, with manual activation it only
|
|
41
|
+
* takes focus and Enter / Space select it. `null` = not a tab-list key, or nothing is enabled:
|
|
42
|
+
* let it through.
|
|
43
|
+
*/
|
|
44
|
+
export function tabsKey(state, index, key, { rtl = false, activation = 'auto' } = {}) {
|
|
45
|
+
if (key === 'Enter' || key === ' ') {
|
|
46
|
+
// Automatic activation: the focused tab already is the selection, and the native button
|
|
47
|
+
// click covers the rest. Manual: select here so the change is reported as a key.
|
|
48
|
+
if (activation !== 'manual')
|
|
49
|
+
return null;
|
|
50
|
+
const action = select(state, index, false, 'key');
|
|
51
|
+
return action && { action, preventDefault: true };
|
|
52
|
+
}
|
|
53
|
+
const move = moveFor(key, rtl);
|
|
54
|
+
if (!move)
|
|
55
|
+
return null;
|
|
56
|
+
// A tab that is not enabled is no position to step from: fall back to an edge.
|
|
57
|
+
const from = state.enabled.includes(index) ? index : -1;
|
|
58
|
+
const target = rovingStep(state.enabled, from, move);
|
|
59
|
+
if (target < 0)
|
|
60
|
+
return null;
|
|
61
|
+
const action = activation === 'manual' ? { type: 'focus', index: target } : select(state, target, true, 'key');
|
|
62
|
+
return action && { action, preventDefault: true };
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The index that owns the list's single tab stop: the selected tab when it is enabled, otherwise
|
|
66
|
+
* the first enabled one; `-1` when nothing is enabled.
|
|
67
|
+
*/
|
|
68
|
+
export function tabsTabStop(state) {
|
|
69
|
+
return state.enabled.includes(state.selected) ? state.selected : (state.enabled[0] ?? -1);
|
|
70
|
+
}
|
|
71
|
+
// --- attributes ---------------------------------------------------------------
|
|
72
|
+
// Strings, not booleans, so the Svelte spread and the vanilla `setAttribute` write the same DOM.
|
|
73
|
+
export function tabsListAttrs() {
|
|
74
|
+
return { role: 'tablist' };
|
|
75
|
+
}
|
|
76
|
+
export function tabsTabAttrs(tab) {
|
|
77
|
+
return {
|
|
78
|
+
role: 'tab',
|
|
79
|
+
'aria-selected': tab.index === tab.selected ? 'true' : 'false',
|
|
80
|
+
'aria-controls': tab.panelId,
|
|
81
|
+
tabindex: rovingTabindex(tab.index, tab.tabStop),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The panel of a tab: named by its tab, and focusable so its content is reachable by Tab even
|
|
86
|
+
* when it holds nothing focusable. Visibility (`hidden`) is written by the caller.
|
|
87
|
+
*/
|
|
88
|
+
export function tabsPanelAttrs(tabId) {
|
|
89
|
+
return { role: 'tabpanel', 'aria-labelledby': tabId, tabindex: 0 };
|
|
90
|
+
}
|