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,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Popover (DS-0197) — Popover.svelte's non-modal panel over the exact same DOM:
|
|
3
|
+
* `.ss-popover > .trigger[aria-expanded][aria-controls]` and `.panel[role=dialog]`. The
|
|
4
|
+
* behaviour itself comes from `../core/popover.js`, shared with the Svelte component: this file
|
|
5
|
+
* reads the state from the DOM, asks the core, and writes the result back. Opening moves focus
|
|
6
|
+
* into the panel (its first focusable element, else the panel); Escape closes and returns focus
|
|
7
|
+
* to the trigger; an outside pointerdown or tabbing out closes without pulling focus back. A
|
|
8
|
+
* closed panel is `inert`. Emits `ss:openchange` on the root with `{ open, reason }`. A panel
|
|
9
|
+
* with neither `aria-label` nor `aria-labelledby` gets `aria-labelledby` pointing at its
|
|
10
|
+
* trigger on first open (an id is minted if needed).
|
|
11
|
+
*/
|
|
12
|
+
import { on, emit, all, setAttrs } from './delegate.js';
|
|
13
|
+
import { FOCUSABLE_SELECTOR } from '../core/behaviors/focusable.js';
|
|
14
|
+
import { popoverClose, popoverFocusOut, popoverKey, popoverOpen, popoverOutsidePress, popoverPanelAttrs, popoverTriggerAttrs, popoverTriggerPress, } from '../core/popover.js';
|
|
15
|
+
const TRIGGER = '.ss-popover > .trigger';
|
|
16
|
+
const OPEN_TRIGGER = `${TRIGGER}[aria-expanded="true"]`;
|
|
17
|
+
function parts(el) {
|
|
18
|
+
const root = el.closest('.ss-popover');
|
|
19
|
+
const trigger = root?.querySelector(':scope > .trigger');
|
|
20
|
+
const panel = root?.querySelector(':scope > .panel');
|
|
21
|
+
return root && trigger && panel ? { root, trigger, panel } : null;
|
|
22
|
+
}
|
|
23
|
+
/** The popover's state, read from the DOM (the DOM is the store on the plain-HTML path). */
|
|
24
|
+
function read({ trigger }) {
|
|
25
|
+
return { open: trigger.getAttribute('aria-expanded') === 'true' };
|
|
26
|
+
}
|
|
27
|
+
let autoId = 0;
|
|
28
|
+
/** An unnamed `role="dialog"` panel is named by its trigger (mirrors Popover.svelte's fallback). */
|
|
29
|
+
function ensureName(trigger, panel) {
|
|
30
|
+
if (panel.hasAttribute('aria-label') || panel.hasAttribute('aria-labelledby'))
|
|
31
|
+
return;
|
|
32
|
+
if (!trigger.id)
|
|
33
|
+
trigger.id = `ss-popover-trigger-${++autoId}`;
|
|
34
|
+
panel.setAttribute('aria-labelledby', trigger.id);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Move focus into an opened panel: its first focusable element, else the panel itself. Shared
|
|
38
|
+
* with Popover.svelte. Focus lands on the panel first and is then handed to the target, retried
|
|
39
|
+
* over a few frames: a child with its own `visibility` transition (`transition: all`, as on
|
|
40
|
+
* `.ss-btn`) still computes as hidden — so refuses focus — until that transition has started.
|
|
41
|
+
*/
|
|
42
|
+
export function focusPopoverPanel(panel) {
|
|
43
|
+
const target = panel.querySelector(FOCUSABLE_SELECTOR);
|
|
44
|
+
panel.focus();
|
|
45
|
+
if (!target)
|
|
46
|
+
return;
|
|
47
|
+
let tries = 5;
|
|
48
|
+
const attempt = () => {
|
|
49
|
+
// Focus was moved on (or the popover closed) meanwhile: leave it where it is.
|
|
50
|
+
if (document.activeElement !== panel)
|
|
51
|
+
return;
|
|
52
|
+
target.focus();
|
|
53
|
+
if (document.activeElement !== target && tries-- > 0)
|
|
54
|
+
requestAnimationFrame(attempt);
|
|
55
|
+
};
|
|
56
|
+
attempt();
|
|
57
|
+
}
|
|
58
|
+
/** Apply a core action to the DOM. */
|
|
59
|
+
function run(p, action) {
|
|
60
|
+
if (!action)
|
|
61
|
+
return;
|
|
62
|
+
const { root, trigger, panel } = p;
|
|
63
|
+
const open = action.type === 'open';
|
|
64
|
+
if (open)
|
|
65
|
+
ensureName(trigger, panel);
|
|
66
|
+
setAttrs(trigger, popoverTriggerAttrs(open));
|
|
67
|
+
setAttrs(panel, popoverPanelAttrs());
|
|
68
|
+
panel.toggleAttribute('inert', !open);
|
|
69
|
+
panel.classList.toggle('open', open);
|
|
70
|
+
emit(root, 'ss:openchange', { open, reason: action.reason });
|
|
71
|
+
if (action.type === 'open') {
|
|
72
|
+
queueMicrotask(() => focusPopoverPanel(panel));
|
|
73
|
+
}
|
|
74
|
+
else if (action.returnFocus) {
|
|
75
|
+
trigger.focus();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export function openPopover(trigger) {
|
|
79
|
+
const p = parts(trigger);
|
|
80
|
+
if (p)
|
|
81
|
+
run(p, popoverOpen(read(p)));
|
|
82
|
+
}
|
|
83
|
+
export function closePopover(trigger, returnFocus = true) {
|
|
84
|
+
const p = parts(trigger);
|
|
85
|
+
if (p)
|
|
86
|
+
run(p, popoverClose(read(p), returnFocus));
|
|
87
|
+
}
|
|
88
|
+
/** Every open popover, as parts. */
|
|
89
|
+
function openPopovers() {
|
|
90
|
+
return all(document, OPEN_TRIGGER)
|
|
91
|
+
.map((t) => parts(t))
|
|
92
|
+
.filter((p) => p !== null);
|
|
93
|
+
}
|
|
94
|
+
export function installPopover() {
|
|
95
|
+
on('click', TRIGGER, (trigger) => {
|
|
96
|
+
const p = parts(trigger);
|
|
97
|
+
if (p)
|
|
98
|
+
run(p, popoverTriggerPress(read(p)));
|
|
99
|
+
});
|
|
100
|
+
on('keydown', '.ss-popover', (root, e) => {
|
|
101
|
+
// Something inside (a nested menu, say) already used this key.
|
|
102
|
+
if (e.defaultPrevented)
|
|
103
|
+
return;
|
|
104
|
+
const p = parts(root);
|
|
105
|
+
const result = p && popoverKey(read(p), e.key);
|
|
106
|
+
if (!p || !result)
|
|
107
|
+
return;
|
|
108
|
+
if (result.preventDefault)
|
|
109
|
+
e.preventDefault();
|
|
110
|
+
run(p, result.action);
|
|
111
|
+
});
|
|
112
|
+
document.addEventListener('focusout', (e) => {
|
|
113
|
+
const from = e.target;
|
|
114
|
+
const to = e.relatedTarget;
|
|
115
|
+
for (const p of openPopovers()) {
|
|
116
|
+
if (!from || !p.root.contains(from))
|
|
117
|
+
continue;
|
|
118
|
+
run(p, popoverFocusOut(read(p), !to ? 'nowhere' : p.root.contains(to) ? 'inside' : 'outside'));
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
document.addEventListener('pointerdown', (e) => {
|
|
122
|
+
const t = e.target;
|
|
123
|
+
for (const p of openPopovers()) {
|
|
124
|
+
if (t && p.root.contains(t))
|
|
125
|
+
continue;
|
|
126
|
+
run(p, popoverOutsidePress(read(p)));
|
|
127
|
+
}
|
|
128
|
+
}, true);
|
|
129
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RadioGroup (DS-0197) — `.ss-radio-group .input[type=radio]` are native radios sharing a
|
|
3
|
+
* `name`, so selection, arrow keys (wrapping, skipping disabled, mirrored under RTL), Space and
|
|
4
|
+
* form submission need no script. This module keeps the group's single tab stop where
|
|
5
|
+
* `../core/radio.js` says it belongs after the selection moves, and emits `ss:change` on the
|
|
6
|
+
* root with `{ value, index }`. No `reason`: the browser reports a press and an arrow key as the
|
|
7
|
+
* same `change` event. State is read from the DOM.
|
|
8
|
+
*/
|
|
9
|
+
import { on, emit, all, setAttrs } from './delegate.js';
|
|
10
|
+
import { radioEnabled, radioInputAttrs, radioPress, radioTabStop, } from '../core/radio.js';
|
|
11
|
+
const INPUT = '.ss-radio-group .input[type="radio"]';
|
|
12
|
+
function radios(root) {
|
|
13
|
+
return all(root, '.input[type="radio"]').filter((r) => r.closest('.ss-radio-group') === root);
|
|
14
|
+
}
|
|
15
|
+
/** The group's state, read from the DOM (the DOM is the store on the plain-HTML path). */
|
|
16
|
+
function read(root, list) {
|
|
17
|
+
return {
|
|
18
|
+
selected: list.findIndex((r) => r.checked),
|
|
19
|
+
enabled: radioEnabled(list.map((r) => r.disabled), root.getAttribute('aria-disabled') === 'true'),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** Apply a core action to the DOM. */
|
|
23
|
+
function run(root, list, action) {
|
|
24
|
+
if (!action)
|
|
25
|
+
return;
|
|
26
|
+
const radio = list[action.index];
|
|
27
|
+
if (!radio)
|
|
28
|
+
return;
|
|
29
|
+
radio.checked = true;
|
|
30
|
+
const tabStop = radioTabStop(read(root, list));
|
|
31
|
+
list.forEach((r, index) => setAttrs(r, radioInputAttrs(index, tabStop)));
|
|
32
|
+
if (action.changed)
|
|
33
|
+
emit(root, 'ss:change', { value: radio.value, index: action.index });
|
|
34
|
+
}
|
|
35
|
+
/** Select a radio from script, exactly as a press would (emits `ss:change` when it changes). */
|
|
36
|
+
export function selectRadio(radio) {
|
|
37
|
+
const root = radio.closest('.ss-radio-group');
|
|
38
|
+
if (!root)
|
|
39
|
+
return;
|
|
40
|
+
const list = radios(root);
|
|
41
|
+
run(root, list, radioPress(read(root, list), list.indexOf(radio)));
|
|
42
|
+
}
|
|
43
|
+
export function installRadio() {
|
|
44
|
+
on('change', INPUT, (el) => {
|
|
45
|
+
const root = el.closest('.ss-radio-group');
|
|
46
|
+
if (!root)
|
|
47
|
+
return;
|
|
48
|
+
const list = radios(root);
|
|
49
|
+
// The browser has already moved the selection, and a native `change` only fires when it
|
|
50
|
+
// did move — so the selection the core compares against is "some other option".
|
|
51
|
+
const before = { ...read(root, list), selected: -1 };
|
|
52
|
+
run(root, list, radioPress(before, list.indexOf(el)));
|
|
53
|
+
});
|
|
54
|
+
}
|
|
@@ -1,62 +1,69 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SegmentedControl (DS-0148) — radio-group selection over `.ss-segmented > .segment[role=radio]`
|
|
3
3
|
* with the same roving model as SegmentedControl.svelte (Arrow/Home/End select + focus,
|
|
4
|
-
* wrapping over enabled segments
|
|
5
|
-
*
|
|
4
|
+
* wrapping over enabled segments; Left/Right mirror under RTL). The behaviour itself comes from
|
|
5
|
+
* `../core/segmented.js`, shared with the Svelte component (DS-0197): this file reads the state
|
|
6
|
+
* from the DOM, asks the core, and writes the result back. Emits `ss:change` on the root with
|
|
7
|
+
* `{ value, index, reason }`; `value` is the segment's `data-value` (vanilla-only attribute) or
|
|
8
|
+
* its label text, `reason` is `'press'` or `'key'`.
|
|
6
9
|
*/
|
|
7
|
-
import { on, emit, all } from './delegate.js';
|
|
10
|
+
import { on, emit, all, setAttrs } from './delegate.js';
|
|
11
|
+
import { segmentedItemAttrs, segmentedKey, segmentedPress, segmentedTabStop, } from '../core/segmented.js';
|
|
12
|
+
const SEGMENT = '.ss-segmented .segment[role="radio"]';
|
|
8
13
|
function segments(root) {
|
|
9
14
|
return all(root, '.segment[role="radio"]').filter((s) => s.closest('.ss-segmented') === root);
|
|
10
15
|
}
|
|
16
|
+
/** The group's state, read from the DOM (the DOM is the store on the plain-HTML path). */
|
|
17
|
+
function read(root, list) {
|
|
18
|
+
const groupDisabled = root.getAttribute('aria-disabled') === 'true';
|
|
19
|
+
return {
|
|
20
|
+
selected: list.findIndex((s) => s.getAttribute('aria-checked') === 'true'),
|
|
21
|
+
enabled: groupDisabled
|
|
22
|
+
? []
|
|
23
|
+
: list.map((s, index) => (s.disabled ? -1 : index)).filter((index) => index >= 0),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** Apply a core action to the DOM. */
|
|
27
|
+
function run(root, list, action) {
|
|
28
|
+
if (!action)
|
|
29
|
+
return;
|
|
30
|
+
const segment = list[action.index];
|
|
31
|
+
if (!segment)
|
|
32
|
+
return;
|
|
33
|
+
const tabStop = segmentedTabStop({ ...read(root, list), selected: action.index });
|
|
34
|
+
list.forEach((s, index) => {
|
|
35
|
+
s.classList.toggle('selected', index === action.index);
|
|
36
|
+
setAttrs(s, segmentedItemAttrs(index, action.index, tabStop));
|
|
37
|
+
});
|
|
38
|
+
if (action.changed) {
|
|
39
|
+
const value = segment.dataset.value ?? segment.querySelector('.label')?.textContent?.trim() ?? '';
|
|
40
|
+
emit(root, 'ss:change', { value, index: action.index, reason: action.reason });
|
|
41
|
+
}
|
|
42
|
+
if (action.focus)
|
|
43
|
+
segment.focus();
|
|
44
|
+
}
|
|
11
45
|
export function selectSegment(segment) {
|
|
12
46
|
const root = segment.closest('.ss-segmented');
|
|
13
|
-
if (!root
|
|
47
|
+
if (!root)
|
|
14
48
|
return;
|
|
15
49
|
const list = segments(root);
|
|
16
|
-
|
|
17
|
-
for (const s of list) {
|
|
18
|
-
const on = s === segment;
|
|
19
|
-
s.classList.toggle('selected', on);
|
|
20
|
-
s.setAttribute('aria-checked', String(on));
|
|
21
|
-
s.tabIndex = on ? 0 : -1;
|
|
22
|
-
}
|
|
23
|
-
if (already)
|
|
24
|
-
return;
|
|
25
|
-
const value = segment.dataset.value ?? segment.querySelector('.label')?.textContent?.trim() ?? '';
|
|
26
|
-
emit(root, 'ss:change', { value, index: list.indexOf(segment) });
|
|
50
|
+
run(root, list, segmentedPress(read(root, list), list.indexOf(segment)));
|
|
27
51
|
}
|
|
28
52
|
export function installSegmented() {
|
|
29
|
-
on('click',
|
|
30
|
-
on('keydown',
|
|
53
|
+
on('click', SEGMENT, (s) => selectSegment(s));
|
|
54
|
+
on('keydown', SEGMENT, (segment, e) => {
|
|
31
55
|
const root = segment.closest('.ss-segmented');
|
|
32
56
|
if (!root)
|
|
33
57
|
return;
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
case 'ArrowDown':
|
|
41
|
-
target = ((pos < 0 ? -1 : pos) + 1 + n) % n;
|
|
42
|
-
break;
|
|
43
|
-
case 'ArrowLeft':
|
|
44
|
-
case 'ArrowUp':
|
|
45
|
-
target = ((pos < 0 ? 0 : pos) - 1 + n) % n;
|
|
46
|
-
break;
|
|
47
|
-
case 'Home':
|
|
48
|
-
target = 0;
|
|
49
|
-
break;
|
|
50
|
-
case 'End':
|
|
51
|
-
target = n - 1;
|
|
52
|
-
break;
|
|
53
|
-
default:
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (n === 0)
|
|
58
|
+
const list = segments(root);
|
|
59
|
+
// RTL: the row runs right-to-left, so ArrowLeft points at the NEXT segment. Read the
|
|
60
|
+
// inherited computed direction at keydown time and hand it to the core.
|
|
61
|
+
const rtl = getComputedStyle(segment).direction === 'rtl';
|
|
62
|
+
const result = segmentedKey(read(root, list), list.indexOf(segment), e.key, rtl);
|
|
63
|
+
if (!result)
|
|
57
64
|
return;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
65
|
+
if (result.preventDefault)
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
run(root, list, result.action);
|
|
61
68
|
});
|
|
62
69
|
}
|
package/dist/vanilla/switch.d.ts
CHANGED
package/dist/vanilla/switch.js
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Switch (DS-0148) — flips `aria-checked` + `.on` on `.ss-switch .track[role=switch]`; clicking
|
|
3
3
|
* the sibling `.label` toggles too (same target as the control, like Switch.svelte). Emits
|
|
4
|
-
* `ss:change` on the root with `{ checked }`.
|
|
4
|
+
* `ss:change` on the root with `{ checked, reason }`. The decision comes from
|
|
5
|
+
* `../core/switch.js`, shared with the Svelte component (DS-0198); state is read from the DOM.
|
|
5
6
|
*/
|
|
6
|
-
import { on, emit } from './delegate.js';
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
import { on, emit, setAttrs } from './delegate.js';
|
|
8
|
+
import { switchToggle, switchTrackAttrs } from '../core/switch.js';
|
|
9
|
+
export function toggleSwitch(track, reason = 'track') {
|
|
10
|
+
const next = switchToggle({
|
|
11
|
+
checked: track.getAttribute('aria-checked') === 'true',
|
|
12
|
+
disabled: track.disabled,
|
|
13
|
+
});
|
|
14
|
+
if (next === null)
|
|
9
15
|
return;
|
|
10
|
-
|
|
11
|
-
track.setAttribute('aria-checked', String(next));
|
|
16
|
+
setAttrs(track, switchTrackAttrs(next));
|
|
12
17
|
track.classList.toggle('on', next);
|
|
13
|
-
emit(track.closest('.ss-switch') ?? track, 'ss:change', { checked: next });
|
|
18
|
+
emit(track.closest('.ss-switch') ?? track, 'ss:change', { checked: next, reason });
|
|
14
19
|
}
|
|
15
20
|
export function installSwitch() {
|
|
16
21
|
on('click', '.ss-switch .track[role="switch"]', (track) => toggleSwitch(track));
|
|
17
22
|
on('click', '.ss-switch .label', (label) => {
|
|
18
23
|
const track = label.closest('.ss-switch')?.querySelector('.track');
|
|
19
24
|
if (track)
|
|
20
|
-
toggleSwitch(track);
|
|
25
|
+
toggleSwitch(track, 'label');
|
|
21
26
|
});
|
|
22
27
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tabs (DS-0197) — the WAI-ARIA tabs pattern over the exact DOM Tabs.svelte renders:
|
|
3
|
+
* `.ss-tabs > .list[role=tablist] > .tab[role=tab]` plus one `.panel[role=tabpanel]` per tab
|
|
4
|
+
* (each tab's `aria-controls` names its panel; without it the n-th tab owns the n-th panel).
|
|
5
|
+
* The behaviour itself comes from `../core/tabs.js`, shared with the Svelte component: this file
|
|
6
|
+
* reads the state from the DOM, asks the core, and writes the result back — the selected tab's
|
|
7
|
+
* panel is shown, the others get `hidden`. `data-activation="manual"` on the root makes the
|
|
8
|
+
* arrows move focus only (Enter / Space select). Emits `ss:change` on the root with
|
|
9
|
+
* `{ value, index, reason }`; `value` is the tab's `data-value` (vanilla-only attribute) or its
|
|
10
|
+
* label text, `reason` is `'press'` or `'key'`.
|
|
11
|
+
*/
|
|
12
|
+
import { on, emit, all, byId, setAttrs } from './delegate.js';
|
|
13
|
+
import { tabsKey, tabsPress, tabsTabAttrs, tabsTabStop, } from '../core/tabs.js';
|
|
14
|
+
const TAB = '.ss-tabs > .list[role="tablist"] > .tab[role="tab"]';
|
|
15
|
+
function parts(el) {
|
|
16
|
+
const root = el.closest('.ss-tabs');
|
|
17
|
+
if (!root)
|
|
18
|
+
return null;
|
|
19
|
+
const tabs = all(root, ':scope > .list > .tab[role="tab"]');
|
|
20
|
+
const own = all(root, ':scope > .panel');
|
|
21
|
+
const panels = tabs.map((t, i) => byId(t.getAttribute('aria-controls')) ?? own[i] ?? null);
|
|
22
|
+
return { root, tabs, panels };
|
|
23
|
+
}
|
|
24
|
+
/** The list's state, read from the DOM (the DOM is the store on the plain-HTML path). */
|
|
25
|
+
function read({ tabs }) {
|
|
26
|
+
return {
|
|
27
|
+
selected: tabs.findIndex((t) => t.getAttribute('aria-selected') === 'true'),
|
|
28
|
+
enabled: tabs
|
|
29
|
+
.map((t, index) => (t.disabled || t.getAttribute('aria-disabled') === 'true' ? -1 : index))
|
|
30
|
+
.filter((index) => index >= 0),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** Apply a core action to the DOM. */
|
|
34
|
+
function run(p, action) {
|
|
35
|
+
if (!action)
|
|
36
|
+
return;
|
|
37
|
+
const tab = p.tabs[action.index];
|
|
38
|
+
if (!tab)
|
|
39
|
+
return;
|
|
40
|
+
if (action.type === 'select') {
|
|
41
|
+
const tabStop = tabsTabStop({ ...read(p), selected: action.index });
|
|
42
|
+
p.tabs.forEach((t, index) => {
|
|
43
|
+
t.classList.toggle('selected', index === action.index);
|
|
44
|
+
setAttrs(t, {
|
|
45
|
+
...tabsTabAttrs({ index, selected: action.index, tabStop }),
|
|
46
|
+
// Authored wiring stays as it is.
|
|
47
|
+
'aria-controls': t.getAttribute('aria-controls') ?? undefined,
|
|
48
|
+
});
|
|
49
|
+
const panel = p.panels[index];
|
|
50
|
+
if (panel)
|
|
51
|
+
panel.hidden = index !== action.index;
|
|
52
|
+
});
|
|
53
|
+
if (action.changed) {
|
|
54
|
+
const value = tab.dataset.value ?? tab.querySelector('.label')?.textContent?.trim() ?? '';
|
|
55
|
+
emit(p.root, 'ss:change', { value, index: action.index, reason: action.reason });
|
|
56
|
+
}
|
|
57
|
+
if (!action.focus)
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
tab.focus();
|
|
61
|
+
}
|
|
62
|
+
export function selectTab(tab) {
|
|
63
|
+
const p = parts(tab);
|
|
64
|
+
if (p)
|
|
65
|
+
run(p, tabsPress(read(p), p.tabs.indexOf(tab)));
|
|
66
|
+
}
|
|
67
|
+
export function installTabs() {
|
|
68
|
+
on('click', TAB, (t) => selectTab(t));
|
|
69
|
+
on('keydown', TAB, (tab, e) => {
|
|
70
|
+
const p = parts(tab);
|
|
71
|
+
if (!p)
|
|
72
|
+
return;
|
|
73
|
+
// RTL: the list runs right-to-left, so ArrowLeft points at the NEXT tab. Read the inherited
|
|
74
|
+
// computed direction at keydown time and hand it to the core.
|
|
75
|
+
const rtl = getComputedStyle(tab).direction === 'rtl';
|
|
76
|
+
const activation = p.root.dataset.activation === 'manual' ? 'manual' : 'auto';
|
|
77
|
+
const result = tabsKey(read(p), p.tabs.indexOf(tab), e.key, {
|
|
78
|
+
rtl,
|
|
79
|
+
activation,
|
|
80
|
+
});
|
|
81
|
+
if (!result)
|
|
82
|
+
return;
|
|
83
|
+
if (result.preventDefault)
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
run(p, result.action);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type TierListPlacements, type TierListZones } from '../tierlist
|
|
1
|
+
import { type TierListPlacements, type TierListZones } from '../core/tierlist.js';
|
|
2
2
|
/** The zone map as the DOM currently has it. */
|
|
3
3
|
export declare function readZones(root: HTMLElement): TierListZones;
|
|
4
4
|
/** Public placements read from the DOM: every non-tray zone, in DOM order. */
|
package/dist/vanilla/tierlist.js
CHANGED
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
* TierList (DS-0159) — plain-HTML behaviour for the markup `TierList.svelte` renders: pointer
|
|
3
3
|
* drag between/within rows (Pointer Events, so touch works) and the keyboard path (Space picks
|
|
4
4
|
* a tile up, arrows move it, Space drops, Escape cancels) with a polite live region. The move
|
|
5
|
-
* math and the wording come from `../tierlist
|
|
6
|
-
* Emits `ss:change` on the root with `{ placements }` (tier id → item ids; the tray is
|
|
7
|
-
* implicit). `data-ss-readonly` on the root makes the list inert.
|
|
5
|
+
* math and the wording come from `../core/tierlist.js`, shared with the Svelte component.
|
|
6
|
+
* Emits `ss:change` on the root with `{ placements, reason }` (tier id → item ids; the tray is
|
|
7
|
+
* implicit; `reason` is `'pointer'` or `'keyboard'`). `data-ss-readonly` on the root makes the list inert.
|
|
8
8
|
*/
|
|
9
9
|
import { on, emit, all } from './delegate.js';
|
|
10
|
-
import { TRAY, announceText, insertionIndex, keyboardTarget, } from '../tierlist
|
|
10
|
+
import { TRAY, announceText, insertionIndex, keyboardTarget, tierListDragStarts, tierListPressArmsDrag, tierListTileKey, } from '../core/tierlist.js';
|
|
11
11
|
const ROOT = '.ss-tierlist';
|
|
12
12
|
const TILE = `${ROOT} .tile[data-item]`;
|
|
13
|
-
const DRAG_THRESHOLD = 4;
|
|
14
13
|
function rootOf(el) {
|
|
15
14
|
return el.closest(ROOT);
|
|
16
15
|
}
|
|
@@ -85,18 +84,14 @@ function describe(root, tile) {
|
|
|
85
84
|
count: cells.length,
|
|
86
85
|
};
|
|
87
86
|
}
|
|
88
|
-
function change(root) {
|
|
89
|
-
emit(root, 'ss:change', { placements: readPlacements(root) });
|
|
87
|
+
function change(root, reason) {
|
|
88
|
+
emit(root, 'ss:change', { placements: readPlacements(root), reason });
|
|
90
89
|
}
|
|
91
90
|
const grabs = new WeakMap();
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
ArrowDown: 'down',
|
|
97
|
-
Home: 'home',
|
|
98
|
-
End: 'end',
|
|
99
|
-
};
|
|
91
|
+
/** Read at event time: `dir` may sit on any ancestor and change after install. */
|
|
92
|
+
function isRtl(el) {
|
|
93
|
+
return getComputedStyle(el).direction === 'rtl';
|
|
94
|
+
}
|
|
100
95
|
function setGrabbed(root, tile) {
|
|
101
96
|
for (const t of all(root, '.tile[aria-pressed="true"]')) {
|
|
102
97
|
t.setAttribute('aria-pressed', 'false');
|
|
@@ -118,7 +113,7 @@ export function toggleGrab(tile) {
|
|
|
118
113
|
grabs.delete(root);
|
|
119
114
|
setGrabbed(root, null);
|
|
120
115
|
announce(root, announceText('drop', describe(root, tile)));
|
|
121
|
-
change(root);
|
|
116
|
+
change(root, 'keyboard');
|
|
122
117
|
return;
|
|
123
118
|
}
|
|
124
119
|
const d = describe(root, tile);
|
|
@@ -199,7 +194,7 @@ function moveDrag(d, x, y) {
|
|
|
199
194
|
const boxes = cellsOf(zone)
|
|
200
195
|
.filter((c) => c !== d.cell)
|
|
201
196
|
.map((c) => c.getBoundingClientRect());
|
|
202
|
-
placeCell(d.root, d.cell, zoneKey(zone), insertionIndex(boxes, x, y));
|
|
197
|
+
placeCell(d.root, d.cell, zoneKey(zone), insertionIndex(boxes, x, y, isRtl(zone)));
|
|
203
198
|
}
|
|
204
199
|
function endDrag(d, cancelled) {
|
|
205
200
|
d.ghost?.remove();
|
|
@@ -214,30 +209,32 @@ function endDrag(d, cancelled) {
|
|
|
214
209
|
const now = describe(d.root, d.tile);
|
|
215
210
|
if (zoneKey(d.cell.parentElement) !== d.zone || now.index !== d.index) {
|
|
216
211
|
announce(d.root, announceText('drop', now));
|
|
217
|
-
change(d.root);
|
|
212
|
+
change(d.root, 'pointer');
|
|
218
213
|
}
|
|
219
214
|
}
|
|
220
215
|
export function installTierlist() {
|
|
221
216
|
on('keydown', TILE, (tile, e) => {
|
|
222
217
|
const root = rootOf(tile);
|
|
223
|
-
if (!root
|
|
218
|
+
if (!root)
|
|
224
219
|
return;
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
220
|
+
const result = tierListTileKey({
|
|
221
|
+
readonly: isReadonly(root),
|
|
222
|
+
grabbed: grabs.get(root)?.tile === tile,
|
|
223
|
+
// An activatable tile keeps Enter for the host: its native click does the activating.
|
|
224
|
+
select: tile.hasAttribute('data-ss-activate') ? 'native' : 'none',
|
|
225
|
+
rtl: isRtl(tile),
|
|
226
|
+
}, e.key);
|
|
227
|
+
if (!result)
|
|
229
228
|
return;
|
|
230
|
-
|
|
231
|
-
if (e.key === 'Escape' && grab?.tile === tile) {
|
|
229
|
+
if (result.preventDefault)
|
|
232
230
|
e.preventDefault();
|
|
231
|
+
const { action } = result;
|
|
232
|
+
if (action.type === 'toggle')
|
|
233
|
+
toggleGrab(tile);
|
|
234
|
+
else if (action.type === 'cancel')
|
|
233
235
|
cancelGrab(root, true);
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const move = KEY_MOVES[e.key];
|
|
237
|
-
if (move && grab?.tile === tile) {
|
|
238
|
-
e.preventDefault();
|
|
239
|
-
keyMove(root, tile, move);
|
|
240
|
-
}
|
|
236
|
+
else if (action.type === 'move')
|
|
237
|
+
keyMove(root, tile, action.move);
|
|
241
238
|
});
|
|
242
239
|
// Cancel when focus has really left a grabbed tile — checked a beat later, because moving
|
|
243
240
|
// the node (a row change re-inserts it) blurs it in some browsers before it is re-focused.
|
|
@@ -254,7 +251,10 @@ export function installTierlist() {
|
|
|
254
251
|
});
|
|
255
252
|
on('pointerdown', TILE, (tile, e) => {
|
|
256
253
|
const root = rootOf(tile);
|
|
257
|
-
if (!root
|
|
254
|
+
if (!root)
|
|
255
|
+
return;
|
|
256
|
+
const press = { readonly: isReadonly(root), button: e.button, grabbing: grabs.has(root) };
|
|
257
|
+
if (!tierListPressArmsDrag(press))
|
|
258
258
|
return;
|
|
259
259
|
const cell = tile.closest('.cell');
|
|
260
260
|
const zone = cell.parentElement;
|
|
@@ -278,7 +278,7 @@ export function installTierlist() {
|
|
|
278
278
|
if (!drag)
|
|
279
279
|
return;
|
|
280
280
|
if (!drag.dragging) {
|
|
281
|
-
if (
|
|
281
|
+
if (!tierListDragStarts(e.clientX - drag.startX, e.clientY - drag.startY))
|
|
282
282
|
return;
|
|
283
283
|
startDrag(drag);
|
|
284
284
|
}
|
package/dist/vanilla/toast.d.ts
CHANGED
|
@@ -7,18 +7,26 @@
|
|
|
7
7
|
* toasts.dismiss(id) / clear() / update(id, patch) / max
|
|
8
8
|
*
|
|
9
9
|
* The stack lives in the first `.ss-toaster` on the page (author it to choose `data-position`
|
|
10
|
-
* / size) or in one auto-created under `<body>`. Hover/focus pause the timer
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* / size) or in one auto-created under `<body>`. Hover/focus pause the timer (it resumes only
|
|
11
|
+
* once the pointer has left AND focus is outside the toast), Escape and the × button dismiss,
|
|
12
|
+
* exit runs the `.leaving` CSS animation from vanilla.css. Dismissing the focused toast moves
|
|
13
|
+
* focus to a neighbouring toast, or back to where it came from. Swipe-to-dismiss is not ported.
|
|
14
|
+
*
|
|
15
|
+
* Announcements go through two persistent, visually hidden live regions inside the container
|
|
16
|
+
* (`.live[role=status]` polite, `.live[role=alert]` assertive — the same DOM Toaster.svelte
|
|
17
|
+
* renders; author them in the markup or they are added on DOM ready / first use). Each visible
|
|
18
|
+
* toast mirrors its message into one of them; the toasts themselves carry no live role.
|
|
13
19
|
*/
|
|
14
|
-
import { type Toast, type ToastKind, type ToastOptions, type ToastPatch, type PromiseMessages } from '../toast
|
|
15
|
-
export type { Toast, ToastKind, ToastOptions, ToastPatch, ToastAction, PromiseMessages, } from '../toast
|
|
20
|
+
import { type Toast, type ToastKind, type ToastOptions, type ToastPatch, type PromiseMessages } from '../core/toast.js';
|
|
21
|
+
export type { Toast, ToastKind, ToastOptions, ToastPatch, ToastAction, PromiseMessages, } from '../core/toast.js';
|
|
16
22
|
declare class VanillaToastStore {
|
|
17
23
|
#private;
|
|
18
24
|
max: number;
|
|
19
25
|
/** Visible toasts (read-only snapshot). */
|
|
20
26
|
get items(): Toast[];
|
|
21
27
|
get container(): HTMLElement;
|
|
28
|
+
/** Prepare the live regions of an author-placed container ahead of the first toast. */
|
|
29
|
+
prepare(): void;
|
|
22
30
|
push(kind: ToastKind, message: string, opts?: ToastOptions | number): number;
|
|
23
31
|
update(id: number, patch: ToastPatch): boolean;
|
|
24
32
|
pause(id: number): void;
|