dssoca 0.19.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/components/Accordion.svelte +30 -54
- package/dist/components/Badge.svelte +12 -7
- package/dist/components/Badge.svelte.d.ts +2 -1
- package/dist/components/BottomNav.svelte +18 -28
- package/dist/components/BoxPlot.svelte +34 -7
- package/dist/components/BumpChart.svelte +65 -26
- package/dist/components/Button.svelte +23 -1
- package/dist/components/Button.svelte.d.ts +5 -1
- package/dist/components/Card.svelte +32 -14
- package/dist/components/Card.svelte.d.ts +4 -1
- package/dist/components/Chart.svelte +166 -32
- package/dist/components/Chart.svelte.d.ts +13 -1
- package/dist/components/Checkbox.svelte +210 -0
- package/dist/components/Checkbox.svelte.d.ts +38 -0
- package/dist/components/DateField.svelte +1 -1
- package/dist/components/FileDrop.svelte +113 -77
- package/dist/components/FileDrop.svelte.d.ts +12 -2
- package/dist/components/Heatmap.svelte +128 -50
- package/dist/components/Heatmap.svelte.d.ts +2 -1
- package/dist/components/Icon.svelte +12 -3
- package/dist/components/Icon.svelte.d.ts +4 -0
- package/dist/components/Image.svelte +44 -44
- package/dist/components/Input.svelte +11 -6
- package/dist/components/Link.svelte +25 -14
- package/dist/components/LogStream.svelte +48 -33
- package/dist/components/Menu.svelte +81 -102
- package/dist/components/Menu.svelte.d.ts +8 -2
- package/dist/components/MetricTile.svelte +11 -1
- package/dist/components/MetricTile.svelte.d.ts +6 -0
- package/dist/components/Modal.svelte +108 -21
- package/dist/components/Modal.svelte.d.ts +18 -5
- package/dist/components/NumberField.svelte +44 -22
- package/dist/components/Pagination.svelte +54 -41
- package/dist/components/Pagination.svelte.d.ts +6 -2
- package/dist/components/Popover.svelte +247 -0
- package/dist/components/Popover.svelte.d.ts +36 -0
- package/dist/components/RadioGroup.svelte +227 -0
- package/dist/components/RadioGroup.svelte.d.ts +42 -0
- package/dist/components/ScatterPlot.svelte +42 -7
- package/dist/components/SearchPalette.svelte +216 -136
- package/dist/components/SearchPalette.svelte.d.ts +11 -4
- package/dist/components/SegmentedControl.svelte +47 -59
- package/dist/components/SegmentedControl.svelte.d.ts +7 -2
- package/dist/components/Select.svelte +3 -4
- package/dist/components/ServiceCard.svelte +105 -68
- package/dist/components/ServiceCard.svelte.d.ts +8 -3
- package/dist/components/ShortcutsHelp.svelte +49 -48
- package/dist/components/Sidebar.svelte +88 -117
- package/dist/components/Switch.svelte +24 -18
- package/dist/components/Switch.svelte.d.ts +6 -2
- package/dist/components/Table.svelte +29 -44
- package/dist/components/Table.svelte.d.ts +6 -2
- package/dist/components/Tabs.svelte +223 -0
- package/dist/components/Tabs.svelte.d.ts +51 -0
- package/dist/components/Textarea.svelte +1 -1
- package/dist/components/TierList.svelte +45 -49
- package/dist/components/TierList.svelte.d.ts +7 -3
- package/dist/components/Toaster.svelte +154 -32
- package/dist/components/Tooltip.svelte +122 -18
- package/dist/components/Tooltip.svelte.d.ts +1 -1
- package/dist/components/Topbar.svelte +29 -49
- package/dist/core/accordion.d.ts +32 -0
- package/dist/core/accordion.js +53 -0
- package/dist/core/behaviors/focusable.d.ts +5 -0
- package/dist/core/behaviors/focusable.js +14 -0
- package/dist/core/behaviors/roving.d.ts +13 -0
- package/dist/core/behaviors/roving.js +29 -0
- package/dist/core/bottom-nav.d.ts +36 -0
- package/dist/core/bottom-nav.js +33 -0
- package/dist/core/chart-nav.d.ts +53 -0
- package/dist/core/chart-nav.js +62 -0
- package/dist/core/checkbox.d.ts +36 -0
- package/dist/core/checkbox.js +29 -0
- package/dist/core/file-drop.d.ts +75 -0
- package/dist/core/file-drop.js +101 -0
- package/dist/core/image.d.ts +59 -0
- package/dist/core/image.js +64 -0
- package/dist/core/input.d.ts +21 -0
- package/dist/core/input.js +17 -0
- package/dist/core/log-stream.d.ts +51 -0
- package/dist/core/log-stream.js +50 -0
- package/dist/core/menu.d.ts +70 -0
- package/dist/core/menu.js +84 -0
- package/dist/core/modal.d.ts +59 -0
- package/dist/core/modal.js +44 -0
- package/dist/core/number-field.d.ts +47 -0
- package/dist/core/number-field.js +64 -0
- package/dist/core/pagination.d.ts +59 -0
- package/dist/core/pagination.js +65 -0
- package/dist/core/popover.d.ts +68 -0
- package/dist/core/popover.js +55 -0
- package/dist/core/radio.d.ts +36 -0
- package/dist/core/radio.js +48 -0
- package/dist/core/search-palette.d.ts +124 -0
- package/dist/core/search-palette.js +149 -0
- package/dist/core/segmented.d.ts +46 -0
- package/dist/core/segmented.js +66 -0
- package/dist/core/shortcuts-help.d.ts +56 -0
- package/dist/core/shortcuts-help.js +50 -0
- package/dist/core/sidebar.d.ts +63 -0
- package/dist/core/sidebar.js +84 -0
- package/dist/core/switch.d.ts +19 -0
- package/dist/core/switch.js +11 -0
- package/dist/core/table.d.ts +40 -0
- package/dist/core/table.js +57 -0
- package/dist/core/tabs.d.ts +84 -0
- package/dist/core/tabs.js +90 -0
- package/dist/{tierlist-core.d.ts → core/tierlist.d.ts} +77 -5
- package/dist/{tierlist-core.js → core/tierlist.js} +64 -7
- package/dist/core/toast.d.ts +112 -0
- package/dist/{toast-core.js → core/toast.js} +48 -2
- package/dist/core/tooltip.d.ts +47 -0
- package/dist/core/tooltip.js +51 -0
- package/dist/core/topbar.d.ts +41 -0
- package/dist/core/topbar.js +52 -0
- package/dist/dssoca.config.d.ts +1 -1
- package/dist/dssoca.config.js +4 -0
- package/dist/icons.d.ts +19 -2
- package/dist/icons.js +42 -3
- package/dist/index.d.ts +15 -2
- package/dist/index.js +10 -2
- package/dist/theme.css +47 -0
- package/dist/toast.svelte.d.ts +2 -2
- package/dist/toast.svelte.js +1 -1
- package/dist/tokens.css +47 -0
- package/dist/vanilla/accordion.js +35 -32
- package/dist/vanilla/checkbox.d.ts +8 -0
- package/dist/vanilla/checkbox.js +43 -0
- package/dist/vanilla/delegate.d.ts +2 -0
- package/dist/vanilla/delegate.js +9 -0
- package/dist/vanilla/fields.js +46 -28
- package/dist/vanilla/index.d.ts +5 -1
- package/dist/vanilla/index.js +17 -4
- package/dist/vanilla/menu.js +101 -84
- package/dist/vanilla/modal.d.ts +7 -1
- package/dist/vanilla/modal.js +120 -15
- package/dist/vanilla/popover.d.ts +10 -0
- package/dist/vanilla/popover.js +129 -0
- package/dist/vanilla/radio.d.ts +3 -0
- package/dist/vanilla/radio.js +54 -0
- package/dist/vanilla/segmented.js +50 -43
- package/dist/vanilla/switch.d.ts +2 -1
- package/dist/vanilla/switch.js +13 -8
- package/dist/vanilla/tabs.d.ts +2 -0
- package/dist/vanilla/tabs.js +87 -0
- package/dist/vanilla/tierlist.d.ts +1 -1
- package/dist/vanilla/tierlist.js +34 -34
- package/dist/vanilla/toast.d.ts +13 -5
- package/dist/vanilla/toast.js +132 -16
- package/dist/vanilla/tooltip.d.ts +5 -1
- package/dist/vanilla/tooltip.js +78 -19
- package/dist/vanilla.css +675 -160
- package/package.json +1 -1
- package/dist/toast-core.d.ts +0 -61
|
@@ -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
|
+
}
|
|
@@ -52,9 +52,18 @@ export declare function moveItem(zones: TierListZones, itemId: string, toZone: s
|
|
|
52
52
|
/** The public placements: tiers only, in the given tier order; the tray is implicit. */
|
|
53
53
|
export declare function placementsOf(zones: TierListZones, tiers: readonly TierListTier[]): TierListPlacements;
|
|
54
54
|
export declare function zonesEqual(a: TierListZones, b: TierListZones): boolean;
|
|
55
|
-
export type TierListKeyMove = 'left' | 'right' | 'up' | 'down' | 'home' | 'end';
|
|
56
55
|
/**
|
|
57
|
-
*
|
|
56
|
+
* A keyboard sorting step. `prev`/`next` are positions in the row's reading order, not screen
|
|
57
|
+
* directions — {@link keyMoveFor} maps the physical arrow keys onto them per writing direction.
|
|
58
|
+
*/
|
|
59
|
+
export type TierListKeyMove = 'prev' | 'next' | 'up' | 'down' | 'home' | 'end';
|
|
60
|
+
/**
|
|
61
|
+
* The sorting step a key stands for, or `undefined` for any other key. In a right-to-left
|
|
62
|
+
* layout the row reads right to left, so ArrowLeft steps *forward* and ArrowRight back.
|
|
63
|
+
*/
|
|
64
|
+
export declare function keyMoveFor(key: string, rtl?: boolean): TierListKeyMove | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Keyboard sorting target: prev/next step within the zone (wrapping is deliberately off —
|
|
58
67
|
* the edges are meaningful), home/end jump within it, up/down move to the neighbouring zone
|
|
59
68
|
* keeping the same position (clamped). `zoneOrder` is the visual order, tray last.
|
|
60
69
|
* Returns `null` when the move is impossible (already at the edge).
|
|
@@ -63,6 +72,68 @@ export declare function keyboardTarget(zones: TierListZones, zoneOrder: readonly
|
|
|
63
72
|
zone: string;
|
|
64
73
|
index: number;
|
|
65
74
|
} | null;
|
|
75
|
+
/** What committed the new order; passed to `onchange` / `ss:change`. */
|
|
76
|
+
export type TierListChangeReason = 'pointer' | 'keyboard';
|
|
77
|
+
export interface TierListChangeDetails {
|
|
78
|
+
reason: TierListChangeReason;
|
|
79
|
+
}
|
|
80
|
+
export interface TierListTileState {
|
|
81
|
+
/** The list is display only. */
|
|
82
|
+
readonly: boolean;
|
|
83
|
+
/** This tile is the one picked up with the keyboard. */
|
|
84
|
+
grabbed: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* How Enter activates a tile. `'callback'`: the caller runs its select handler. `'native'`:
|
|
87
|
+
* the key is left alone so the button's own click reaches the host. `'none'`: there is
|
|
88
|
+
* nothing to activate, so Enter picks the tile up like Space.
|
|
89
|
+
*/
|
|
90
|
+
select: 'callback' | 'native' | 'none';
|
|
91
|
+
/** The tile sits in a right-to-left layout (read from the DOM by the caller). */
|
|
92
|
+
rtl: boolean;
|
|
93
|
+
}
|
|
94
|
+
export type TierListKeyAction =
|
|
95
|
+
/** Pick the tile up, or drop it when it is the one picked up. */
|
|
96
|
+
{
|
|
97
|
+
type: 'toggle';
|
|
98
|
+
}
|
|
99
|
+
/** Activate the tile (a details view). */
|
|
100
|
+
| {
|
|
101
|
+
type: 'select';
|
|
102
|
+
}
|
|
103
|
+
/** Put the picked-up tile back where it came from, keeping focus on it. */
|
|
104
|
+
| {
|
|
105
|
+
type: 'cancel';
|
|
106
|
+
}
|
|
107
|
+
/** Step the picked-up tile; see {@link keyboardTarget} for where it lands. */
|
|
108
|
+
| {
|
|
109
|
+
type: 'move';
|
|
110
|
+
move: TierListKeyMove;
|
|
111
|
+
};
|
|
112
|
+
/** A key the tile handles: its action, and whether the browser default must be cancelled. */
|
|
113
|
+
export interface TierListKeyResult {
|
|
114
|
+
action: TierListKeyAction;
|
|
115
|
+
preventDefault: boolean;
|
|
116
|
+
}
|
|
117
|
+
/** A key on a tile. `null` = not a tier-list key (or a read-only list), let it through. */
|
|
118
|
+
export declare function tierListTileKey(state: TierListTileState, key: string): TierListKeyResult | null;
|
|
119
|
+
/** Pointer travel, in px, before a press on a tile becomes a drag. */
|
|
120
|
+
export declare const DRAG_THRESHOLD = 4;
|
|
121
|
+
export interface TierListPressState {
|
|
122
|
+
readonly: boolean;
|
|
123
|
+
/** `PointerEvent.button`; only the primary button drags. */
|
|
124
|
+
button: number;
|
|
125
|
+
/** A tile is picked up with the keyboard; the pointer must not start a second sort. */
|
|
126
|
+
grabbing: boolean;
|
|
127
|
+
}
|
|
128
|
+
/** Whether a press on a tile may turn into a drag. */
|
|
129
|
+
export declare function tierListPressArmsDrag(state: TierListPressState): boolean;
|
|
130
|
+
/** Whether the pointer has travelled far enough from the press for it to count as a drag. */
|
|
131
|
+
export declare function tierListDragStarts(dx: number, dy: number): boolean;
|
|
132
|
+
/** Whether a click on a tile activates it: not in a read-only list, not the click that ends a drag. */
|
|
133
|
+
export declare function tierListClickSelects(state: {
|
|
134
|
+
readonly: boolean;
|
|
135
|
+
afterDrag: boolean;
|
|
136
|
+
}): boolean;
|
|
66
137
|
/** Axis-aligned box, as `getBoundingClientRect()` gives it. */
|
|
67
138
|
export interface Box {
|
|
68
139
|
left: number;
|
|
@@ -72,10 +143,11 @@ export interface Box {
|
|
|
72
143
|
}
|
|
73
144
|
/**
|
|
74
145
|
* Insertion index for a pointer at (x, y) among wrapped tiles: every tile whose row ends above
|
|
75
|
-
* the pointer counts as "before", and on the pointer's own row every tile whose centre is
|
|
76
|
-
* of it
|
|
146
|
+
* the pointer counts as "before", and on the pointer's own row every tile whose centre is
|
|
147
|
+
* before it in reading order — left of it, or right of it when `rtl` (the row then flows right
|
|
148
|
+
* to left). The dragged tile's own box must not be in `cells`.
|
|
77
149
|
*/
|
|
78
|
-
export declare function insertionIndex(cells: readonly Box[], x: number, y: number): number;
|
|
150
|
+
export declare function insertionIndex(cells: readonly Box[], x: number, y: number, rtl?: boolean): number;
|
|
79
151
|
/** Copy for the polite live region — one sentence per step, position 1-based. */
|
|
80
152
|
export declare function announceText(kind: 'grab' | 'move' | 'drop' | 'cancel', d: {
|
|
81
153
|
label: string;
|
|
@@ -121,7 +121,28 @@ export function zonesEqual(a, b) {
|
|
|
121
121
|
return true;
|
|
122
122
|
}
|
|
123
123
|
/**
|
|
124
|
-
*
|
|
124
|
+
* The sorting step a key stands for, or `undefined` for any other key. In a right-to-left
|
|
125
|
+
* layout the row reads right to left, so ArrowLeft steps *forward* and ArrowRight back.
|
|
126
|
+
*/
|
|
127
|
+
export function keyMoveFor(key, rtl = false) {
|
|
128
|
+
switch (key) {
|
|
129
|
+
case 'ArrowLeft':
|
|
130
|
+
return rtl ? 'next' : 'prev';
|
|
131
|
+
case 'ArrowRight':
|
|
132
|
+
return rtl ? 'prev' : 'next';
|
|
133
|
+
case 'ArrowUp':
|
|
134
|
+
return 'up';
|
|
135
|
+
case 'ArrowDown':
|
|
136
|
+
return 'down';
|
|
137
|
+
case 'Home':
|
|
138
|
+
return 'home';
|
|
139
|
+
case 'End':
|
|
140
|
+
return 'end';
|
|
141
|
+
}
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Keyboard sorting target: prev/next step within the zone (wrapping is deliberately off —
|
|
125
146
|
* the edges are meaningful), home/end jump within it, up/down move to the neighbouring zone
|
|
126
147
|
* keeping the same position (clamped). `zoneOrder` is the visual order, tray last.
|
|
127
148
|
* Returns `null` when the move is impossible (already at the edge).
|
|
@@ -133,9 +154,9 @@ export function keyboardTarget(zones, zoneOrder, itemId, move) {
|
|
|
133
154
|
const len = zones[at.zone].length;
|
|
134
155
|
const zi = zoneOrder.indexOf(at.zone);
|
|
135
156
|
switch (move) {
|
|
136
|
-
case '
|
|
157
|
+
case 'prev':
|
|
137
158
|
return at.index > 0 ? { zone: at.zone, index: at.index - 1 } : null;
|
|
138
|
-
case '
|
|
159
|
+
case 'next':
|
|
139
160
|
return at.index < len - 1 ? { zone: at.zone, index: at.index + 1 } : null;
|
|
140
161
|
case 'home':
|
|
141
162
|
return at.index > 0 ? { zone: at.zone, index: 0 } : null;
|
|
@@ -150,17 +171,53 @@ export function keyboardTarget(zones, zoneOrder, itemId, move) {
|
|
|
150
171
|
}
|
|
151
172
|
}
|
|
152
173
|
}
|
|
174
|
+
/** A key on a tile. `null` = not a tier-list key (or a read-only list), let it through. */
|
|
175
|
+
export function tierListTileKey(state, key) {
|
|
176
|
+
if (state.readonly)
|
|
177
|
+
return null;
|
|
178
|
+
const act = (action) => ({ action, preventDefault: true });
|
|
179
|
+
if (key === ' ')
|
|
180
|
+
return act({ type: 'toggle' });
|
|
181
|
+
if (key === 'Enter') {
|
|
182
|
+
if (state.select === 'none')
|
|
183
|
+
return act({ type: 'toggle' });
|
|
184
|
+
return state.select === 'callback' ? act({ type: 'select' }) : null;
|
|
185
|
+
}
|
|
186
|
+
// Everything below only means something while this tile is picked up.
|
|
187
|
+
if (!state.grabbed)
|
|
188
|
+
return null;
|
|
189
|
+
if (key === 'Escape')
|
|
190
|
+
return act({ type: 'cancel' });
|
|
191
|
+
const move = keyMoveFor(key, state.rtl);
|
|
192
|
+
return move ? act({ type: 'move', move }) : null;
|
|
193
|
+
}
|
|
194
|
+
/** Pointer travel, in px, before a press on a tile becomes a drag. */
|
|
195
|
+
export const DRAG_THRESHOLD = 4;
|
|
196
|
+
/** Whether a press on a tile may turn into a drag. */
|
|
197
|
+
export function tierListPressArmsDrag(state) {
|
|
198
|
+
return !state.readonly && state.button === 0 && !state.grabbing;
|
|
199
|
+
}
|
|
200
|
+
/** Whether the pointer has travelled far enough from the press for it to count as a drag. */
|
|
201
|
+
export function tierListDragStarts(dx, dy) {
|
|
202
|
+
return Math.hypot(dx, dy) >= DRAG_THRESHOLD;
|
|
203
|
+
}
|
|
204
|
+
/** Whether a click on a tile activates it: not in a read-only list, not the click that ends a drag. */
|
|
205
|
+
export function tierListClickSelects(state) {
|
|
206
|
+
return !state.readonly && !state.afterDrag;
|
|
207
|
+
}
|
|
153
208
|
/**
|
|
154
209
|
* Insertion index for a pointer at (x, y) among wrapped tiles: every tile whose row ends above
|
|
155
|
-
* the pointer counts as "before", and on the pointer's own row every tile whose centre is
|
|
156
|
-
* of it
|
|
210
|
+
* the pointer counts as "before", and on the pointer's own row every tile whose centre is
|
|
211
|
+
* before it in reading order — left of it, or right of it when `rtl` (the row then flows right
|
|
212
|
+
* to left). The dragged tile's own box must not be in `cells`.
|
|
157
213
|
*/
|
|
158
|
-
export function insertionIndex(cells, x, y) {
|
|
214
|
+
export function insertionIndex(cells, x, y, rtl = false) {
|
|
159
215
|
let index = 0;
|
|
160
216
|
for (const c of cells) {
|
|
217
|
+
const centre = (c.left + c.right) / 2;
|
|
161
218
|
if (c.bottom <= y)
|
|
162
219
|
index++;
|
|
163
|
-
else if (c.top <= y && (
|
|
220
|
+
else if (c.top <= y && (rtl ? centre >= x : centre <= x))
|
|
164
221
|
index++;
|
|
165
222
|
}
|
|
166
223
|
return index;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-free core of the toast system (DS-0148): types, per-kind defaults, the
|
|
3
|
+
* pause/resume timer and the decisions (dismiss key, hold, swipe, focus handover; DS-0197). Shared by the Svelte-runes store (`toast.svelte.ts`) and the vanilla
|
|
4
|
+
* DOM store (`vanilla/toast.ts`) so the two can never disagree on semantics.
|
|
5
|
+
*/
|
|
6
|
+
export type ToastKind = 'success' | 'error' | 'info' | 'loading';
|
|
7
|
+
/** An optional inline action rendered as a button inside the toast. */
|
|
8
|
+
export interface ToastAction {
|
|
9
|
+
label: string;
|
|
10
|
+
/**
|
|
11
|
+
* Invoked on click. Return `false` to keep the toast open (e.g. an async
|
|
12
|
+
* action that wants to swap itself for a result toast); any other return
|
|
13
|
+
* value dismisses the toast.
|
|
14
|
+
*/
|
|
15
|
+
onClick: () => void | false;
|
|
16
|
+
}
|
|
17
|
+
export interface Toast {
|
|
18
|
+
id: number;
|
|
19
|
+
kind: ToastKind;
|
|
20
|
+
message: string;
|
|
21
|
+
/** Effective auto-dismiss duration in ms; <= 0 / Infinity means sticky. */
|
|
22
|
+
timeout: number;
|
|
23
|
+
action?: ToastAction;
|
|
24
|
+
}
|
|
25
|
+
/** Fields a caller may set when pushing; the store fills in the rest. */
|
|
26
|
+
export interface ToastOptions {
|
|
27
|
+
timeout?: number;
|
|
28
|
+
action?: ToastAction;
|
|
29
|
+
}
|
|
30
|
+
/** A subset of a toast a caller may patch in-place via `update`. */
|
|
31
|
+
export type ToastPatch = Partial<Pick<Toast, 'kind' | 'message' | 'timeout' | 'action'>>;
|
|
32
|
+
/** Options for `toast.promise`. */
|
|
33
|
+
export interface PromiseMessages<T> {
|
|
34
|
+
loading: string;
|
|
35
|
+
success: string | ((value: T) => string);
|
|
36
|
+
error: string | ((err: unknown) => string);
|
|
37
|
+
}
|
|
38
|
+
/** Default auto-dismiss per kind. Errors linger; loading is sticky. */
|
|
39
|
+
export declare const DEFAULT_TIMEOUT: Record<ToastKind, number>;
|
|
40
|
+
/** Toasts carrying an action default to sticky so the action stays reachable. */
|
|
41
|
+
export declare const ACTION_TIMEOUT = 0;
|
|
42
|
+
/** Treat <= 0 or non-finite as sticky (never auto-dismiss). */
|
|
43
|
+
export declare function isSticky(timeout: number): boolean;
|
|
44
|
+
/** Effective timeout for a push: explicit > action-sticky > per-kind default. */
|
|
45
|
+
export declare function resolveTimeout(kind: ToastKind, opts?: ToastOptions): number;
|
|
46
|
+
/** Back-compat: the old push signature accepted a bare `timeout` number. */
|
|
47
|
+
export declare function normalizeOptions(opts?: ToastOptions | number): ToastOptions | undefined;
|
|
48
|
+
/** What a key on a toast does. */
|
|
49
|
+
export type ToastKeyAction = {
|
|
50
|
+
type: 'dismiss';
|
|
51
|
+
};
|
|
52
|
+
/** A key the toast handles, and whether it must stop there instead of reaching the page. */
|
|
53
|
+
export interface ToastKeyResult {
|
|
54
|
+
action: ToastKeyAction;
|
|
55
|
+
stopPropagation: boolean;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A key on a toast (or on a control inside it). Escape dismisses it and is kept from the
|
|
59
|
+
* surfaces behind (an open dialog must not close on the same press). `null` = let it through.
|
|
60
|
+
*/
|
|
61
|
+
export declare function toastKey(key: string): ToastKeyResult | null;
|
|
62
|
+
/** What currently holds a toast open. */
|
|
63
|
+
export interface ToastHoldState {
|
|
64
|
+
/** The pointer is over the toast. */
|
|
65
|
+
hovered: boolean;
|
|
66
|
+
/** Focus is on the toast or inside it. */
|
|
67
|
+
focused: boolean;
|
|
68
|
+
/** The toast is being swiped. */
|
|
69
|
+
dragging?: boolean;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Whether the auto-dismiss timer may run again. Hover, keyboard focus and a swipe each hold
|
|
73
|
+
* it: a pointer leaving must not restart the clock under a keyboard user, and vice versa.
|
|
74
|
+
*/
|
|
75
|
+
export declare function toastShouldResume(state: ToastHoldState): boolean;
|
|
76
|
+
/** Whether the toast goes away after its action ran: yes, unless the handler returned `false`. */
|
|
77
|
+
export declare function toastActionDismisses(result: void | false): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Where focus goes when the toast holding it is dismissed, so it never falls to `<body>`: the
|
|
80
|
+
* next toast in the stack, else the nearest one before it. `order` is the stack as it was with
|
|
81
|
+
* the dismissed toast still in it; `canTake` filters out toasts that cannot receive focus
|
|
82
|
+
* (already gone, not rendered). `null` = no toast left, hand focus back to where it came from.
|
|
83
|
+
*/
|
|
84
|
+
export declare function toastFocusAfterDismiss(order: readonly number[], id: number, canTake?: (id: number) => boolean): number | null;
|
|
85
|
+
/** Horizontal travel, in px, past which releasing a swiped toast dismisses it. */
|
|
86
|
+
export declare const SWIPE_THRESHOLD = 64;
|
|
87
|
+
export interface ToastPressState {
|
|
88
|
+
/** `PointerEvent.button`; only the primary button swipes. */
|
|
89
|
+
button: number;
|
|
90
|
+
/** The press landed on a button inside the toast (buttons own their clicks). */
|
|
91
|
+
onControl: boolean;
|
|
92
|
+
/** The user prefers reduced motion: no swipe, the buttons are the way to dismiss. */
|
|
93
|
+
reducedMotion: boolean;
|
|
94
|
+
}
|
|
95
|
+
/** Whether a press on a toast starts a swipe. */
|
|
96
|
+
export declare function toastPressStartsSwipe(state: ToastPressState): boolean;
|
|
97
|
+
/** Whether a swipe released after travelling `dx` px dismisses the toast (either direction). */
|
|
98
|
+
export declare function toastSwipeDismisses(dx: number): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Per-toast auto-dismiss controller. Tracks remaining time so the timer can be
|
|
101
|
+
* paused (on hover/focus) and resumed without losing or resetting the budget.
|
|
102
|
+
*/
|
|
103
|
+
export declare class ToastTimer {
|
|
104
|
+
#private;
|
|
105
|
+
constructor(timeout: number, fire: () => void);
|
|
106
|
+
get sticky(): boolean;
|
|
107
|
+
resume(): void;
|
|
108
|
+
pause(): void;
|
|
109
|
+
/** Re-arm with a fresh budget (used by `update`). */
|
|
110
|
+
reset(timeout: number): void;
|
|
111
|
+
cancel(): void;
|
|
112
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Framework-free core of the toast system (DS-0148): types, per-kind defaults
|
|
3
|
-
* pause/resume timer. Shared by the Svelte-runes store (`toast.svelte.ts`) and the vanilla
|
|
2
|
+
* Framework-free core of the toast system (DS-0148): types, per-kind defaults, the
|
|
3
|
+
* pause/resume timer and the decisions (dismiss key, hold, swipe, focus handover; DS-0197). Shared by the Svelte-runes store (`toast.svelte.ts`) and the vanilla
|
|
4
4
|
* DOM store (`vanilla/toast.ts`) so the two can never disagree on semantics.
|
|
5
5
|
*/
|
|
6
6
|
/** Default auto-dismiss per kind. Errors linger; loading is sticky. */
|
|
@@ -28,6 +28,52 @@ export function resolveTimeout(kind, opts) {
|
|
|
28
28
|
export function normalizeOptions(opts) {
|
|
29
29
|
return typeof opts === 'number' ? { timeout: opts } : opts;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* A key on a toast (or on a control inside it). Escape dismisses it and is kept from the
|
|
33
|
+
* surfaces behind (an open dialog must not close on the same press). `null` = let it through.
|
|
34
|
+
*/
|
|
35
|
+
export function toastKey(key) {
|
|
36
|
+
return key === 'Escape' ? { action: { type: 'dismiss' }, stopPropagation: true } : null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Whether the auto-dismiss timer may run again. Hover, keyboard focus and a swipe each hold
|
|
40
|
+
* it: a pointer leaving must not restart the clock under a keyboard user, and vice versa.
|
|
41
|
+
*/
|
|
42
|
+
export function toastShouldResume(state) {
|
|
43
|
+
return !state.hovered && !state.focused && !state.dragging;
|
|
44
|
+
}
|
|
45
|
+
/** Whether the toast goes away after its action ran: yes, unless the handler returned `false`. */
|
|
46
|
+
export function toastActionDismisses(result) {
|
|
47
|
+
return result !== false;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Where focus goes when the toast holding it is dismissed, so it never falls to `<body>`: the
|
|
51
|
+
* next toast in the stack, else the nearest one before it. `order` is the stack as it was with
|
|
52
|
+
* the dismissed toast still in it; `canTake` filters out toasts that cannot receive focus
|
|
53
|
+
* (already gone, not rendered). `null` = no toast left, hand focus back to where it came from.
|
|
54
|
+
*/
|
|
55
|
+
export function toastFocusAfterDismiss(order, id, canTake = () => true) {
|
|
56
|
+
const i = order.indexOf(id);
|
|
57
|
+
if (i === -1)
|
|
58
|
+
return null;
|
|
59
|
+
for (let n = i + 1; n < order.length; n++)
|
|
60
|
+
if (canTake(order[n]))
|
|
61
|
+
return order[n];
|
|
62
|
+
for (let n = i - 1; n >= 0; n--)
|
|
63
|
+
if (canTake(order[n]))
|
|
64
|
+
return order[n];
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
/** Horizontal travel, in px, past which releasing a swiped toast dismisses it. */
|
|
68
|
+
export const SWIPE_THRESHOLD = 64;
|
|
69
|
+
/** Whether a press on a toast starts a swipe. */
|
|
70
|
+
export function toastPressStartsSwipe(state) {
|
|
71
|
+
return !state.reducedMotion && state.button === 0 && !state.onControl;
|
|
72
|
+
}
|
|
73
|
+
/** Whether a swipe released after travelling `dx` px dismisses the toast (either direction). */
|
|
74
|
+
export function toastSwipeDismisses(dx) {
|
|
75
|
+
return Math.abs(dx) >= SWIPE_THRESHOLD;
|
|
76
|
+
}
|
|
31
77
|
const hasWindow = typeof window !== 'undefined';
|
|
32
78
|
/**
|
|
33
79
|
* Per-toast auto-dismiss controller. Tracks remaining time so the timer can be
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tooltip core (DS-0197) — which event shows or hides the tip, shared by Tooltip.svelte and
|
|
3
|
+
* `vanilla/tooltip.ts`. It encodes WCAG 1.4.13 (Content on Hover or Focus):
|
|
4
|
+
*
|
|
5
|
+
* - dismissable: Escape hides an open tip wherever focus is;
|
|
6
|
+
* - hoverable: the tip is part of the tooltip root, so a pointer or focus move that stays
|
|
7
|
+
* `within` the root never hides it;
|
|
8
|
+
* - persistent: nothing here hides on a timer; the tip stays until the pointer leaves, focus
|
|
9
|
+
* leaves or Escape is pressed.
|
|
10
|
+
*
|
|
11
|
+
* Positioning and the DOM writes stay in the adapters. No DOM, no Svelte.
|
|
12
|
+
*/
|
|
13
|
+
export interface TooltipState {
|
|
14
|
+
open: boolean;
|
|
15
|
+
}
|
|
16
|
+
export type TooltipAction = {
|
|
17
|
+
type: 'show';
|
|
18
|
+
} | {
|
|
19
|
+
type: 'hide';
|
|
20
|
+
};
|
|
21
|
+
/** Where the pointer or focus came from / is going to. */
|
|
22
|
+
export interface TooltipMove {
|
|
23
|
+
/** The other end of the move is inside the tooltip root (trigger or tip). */
|
|
24
|
+
within: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The pointer entered the root. Shows even when already open, so the adapter re-resolves which
|
|
28
|
+
* element the tip describes.
|
|
29
|
+
*/
|
|
30
|
+
export declare function tooltipPointerEnter(_state: TooltipState, from?: TooltipMove): TooltipAction | null;
|
|
31
|
+
/** The pointer left the root. Moving between the trigger and the tip is not leaving. */
|
|
32
|
+
export declare function tooltipPointerLeave(state: TooltipState, to?: TooltipMove): TooltipAction | null;
|
|
33
|
+
/** Focus landed inside the root: show, describing the element that took focus. */
|
|
34
|
+
export declare function tooltipFocusIn(_state: TooltipState): TooltipAction | null;
|
|
35
|
+
/** Focus left an element of the root. Moving to another element inside it is not leaving. */
|
|
36
|
+
export declare function tooltipFocusOut(state: TooltipState, to?: TooltipMove): TooltipAction | null;
|
|
37
|
+
/**
|
|
38
|
+
* A key pressed anywhere in the document. Escape hides an open tip; the event is left alone
|
|
39
|
+
* (never cancelled), so an enclosing dialog or menu still sees it. `null` = not a tooltip key.
|
|
40
|
+
*/
|
|
41
|
+
export declare function tooltipKey(state: TooltipState, key: string): TooltipAction | null;
|
|
42
|
+
/**
|
|
43
|
+
* The `aria-describedby` value of the described element: the tip id is added as one token while
|
|
44
|
+
* open and removed while closed, keeping any description the element already has. `undefined` =
|
|
45
|
+
* remove the attribute.
|
|
46
|
+
*/
|
|
47
|
+
export declare function tooltipDescribedBy(current: string | null | undefined, tipId: string, open: boolean): string | undefined;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tooltip core (DS-0197) — which event shows or hides the tip, shared by Tooltip.svelte and
|
|
3
|
+
* `vanilla/tooltip.ts`. It encodes WCAG 1.4.13 (Content on Hover or Focus):
|
|
4
|
+
*
|
|
5
|
+
* - dismissable: Escape hides an open tip wherever focus is;
|
|
6
|
+
* - hoverable: the tip is part of the tooltip root, so a pointer or focus move that stays
|
|
7
|
+
* `within` the root never hides it;
|
|
8
|
+
* - persistent: nothing here hides on a timer; the tip stays until the pointer leaves, focus
|
|
9
|
+
* leaves or Escape is pressed.
|
|
10
|
+
*
|
|
11
|
+
* Positioning and the DOM writes stay in the adapters. No DOM, no Svelte.
|
|
12
|
+
*/
|
|
13
|
+
const OUTSIDE = { within: false };
|
|
14
|
+
const hide = (state) => (state.open ? { type: 'hide' } : null);
|
|
15
|
+
/**
|
|
16
|
+
* The pointer entered the root. Shows even when already open, so the adapter re-resolves which
|
|
17
|
+
* element the tip describes.
|
|
18
|
+
*/
|
|
19
|
+
export function tooltipPointerEnter(_state, from = OUTSIDE) {
|
|
20
|
+
return from.within ? null : { type: 'show' };
|
|
21
|
+
}
|
|
22
|
+
/** The pointer left the root. Moving between the trigger and the tip is not leaving. */
|
|
23
|
+
export function tooltipPointerLeave(state, to = OUTSIDE) {
|
|
24
|
+
return to.within ? null : hide(state);
|
|
25
|
+
}
|
|
26
|
+
/** Focus landed inside the root: show, describing the element that took focus. */
|
|
27
|
+
export function tooltipFocusIn(_state) {
|
|
28
|
+
return { type: 'show' };
|
|
29
|
+
}
|
|
30
|
+
/** Focus left an element of the root. Moving to another element inside it is not leaving. */
|
|
31
|
+
export function tooltipFocusOut(state, to = OUTSIDE) {
|
|
32
|
+
return to.within ? null : hide(state);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A key pressed anywhere in the document. Escape hides an open tip; the event is left alone
|
|
36
|
+
* (never cancelled), so an enclosing dialog or menu still sees it. `null` = not a tooltip key.
|
|
37
|
+
*/
|
|
38
|
+
export function tooltipKey(state, key) {
|
|
39
|
+
return key === 'Escape' ? hide(state) : null;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The `aria-describedby` value of the described element: the tip id is added as one token while
|
|
43
|
+
* open and removed while closed, keeping any description the element already has. `undefined` =
|
|
44
|
+
* remove the attribute.
|
|
45
|
+
*/
|
|
46
|
+
export function tooltipDescribedBy(current, tipId, open) {
|
|
47
|
+
const ids = (current ?? '').split(/\s+/).filter((id) => id && id !== tipId);
|
|
48
|
+
if (open)
|
|
49
|
+
ids.push(tipId);
|
|
50
|
+
return ids.length ? ids.join(' ') : undefined;
|
|
51
|
+
}
|