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
package/dist/tokens.css
CHANGED
|
@@ -620,3 +620,50 @@
|
|
|
620
620
|
--ss-tier-label-font: var(--ss-size-h3);
|
|
621
621
|
--ss-tier-gap: var(--ss-s-2);
|
|
622
622
|
}
|
|
623
|
+
|
|
624
|
+
:root,
|
|
625
|
+
[data-size-variant=md] {
|
|
626
|
+
--ss-tabs-font: var(--ss-ui-md);
|
|
627
|
+
--ss-tabs-py: 9px;
|
|
628
|
+
--ss-tabs-px: 14px;
|
|
629
|
+
--ss-tabs-gap: 8px;
|
|
630
|
+
--ss-tabs-panel-py: 16px;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
[data-size-variant=sm] {
|
|
634
|
+
--ss-tabs-font: var(--ss-ui-sm);
|
|
635
|
+
--ss-tabs-py: 5px;
|
|
636
|
+
--ss-tabs-px: 10px;
|
|
637
|
+
--ss-tabs-gap: 6px;
|
|
638
|
+
--ss-tabs-panel-py: 10px;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
[data-size-variant=lg] {
|
|
642
|
+
--ss-tabs-font: var(--ss-ui-lg);
|
|
643
|
+
--ss-tabs-py: 12px;
|
|
644
|
+
--ss-tabs-px: 18px;
|
|
645
|
+
--ss-tabs-gap: 10px;
|
|
646
|
+
--ss-tabs-panel-py: 20px;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
:root,
|
|
650
|
+
[data-size-variant=md] {
|
|
651
|
+
--ss-popover-pad: 14px;
|
|
652
|
+
--ss-popover-min-w: 200px;
|
|
653
|
+
--ss-popover-max-w: 340px;
|
|
654
|
+
--ss-popover-offset: 6px;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
[data-size-variant=sm] {
|
|
658
|
+
--ss-popover-pad: 10px;
|
|
659
|
+
--ss-popover-min-w: 160px;
|
|
660
|
+
--ss-popover-max-w: 280px;
|
|
661
|
+
--ss-popover-offset: 5px;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
[data-size-variant=lg] {
|
|
665
|
+
--ss-popover-pad: 18px;
|
|
666
|
+
--ss-popover-min-w: 240px;
|
|
667
|
+
--ss-popover-max-w: 400px;
|
|
668
|
+
--ss-popover-offset: 8px;
|
|
669
|
+
}
|
|
@@ -3,11 +3,21 @@
|
|
|
3
3
|
* `aria-controls`, mirroring Accordion.svelte: single-open by default (opening one closes the
|
|
4
4
|
* others), `data-ss-multiple` on the root allows several, Arrow/Home/End rove between headers.
|
|
5
5
|
* Emits `ss:change` on the root with `{ value }` (open ids: string | string[] | undefined).
|
|
6
|
+
* The behaviour itself comes from `../core/accordion.js`, shared with the Svelte component
|
|
7
|
+
* (DS-0197): this file reads the state from the DOM, asks the core, and writes the result back.
|
|
6
8
|
*/
|
|
7
|
-
import { on, emit,
|
|
9
|
+
import { on, emit, all, byId } from './delegate.js';
|
|
10
|
+
import { accordionHeaderAttrs, accordionHeaderKey, accordionToggle, accordionValue, } from '../core/accordion.js';
|
|
8
11
|
const HEAD = '.ss-accordion .head[aria-controls]';
|
|
12
|
+
/** The root's own headers (not those of a nested accordion), in DOM order. */
|
|
13
|
+
function heads(root) {
|
|
14
|
+
return all(root, '.head[aria-controls]').filter((h) => h.closest('.ss-accordion') === root);
|
|
15
|
+
}
|
|
16
|
+
const isOpen = (head) => head.getAttribute('aria-expanded') === 'true';
|
|
17
|
+
/** A section's id on the plain-HTML path is its panel id (`aria-controls`). */
|
|
18
|
+
const idOf = (head) => head.getAttribute('aria-controls');
|
|
9
19
|
function setOpen(head, open) {
|
|
10
|
-
head.setAttribute('aria-expanded',
|
|
20
|
+
head.setAttribute('aria-expanded', accordionHeaderAttrs(open)['aria-expanded']);
|
|
11
21
|
head.closest('.item')?.classList.toggle('open', open);
|
|
12
22
|
const panel = byId(head.getAttribute('aria-controls'));
|
|
13
23
|
if (!panel)
|
|
@@ -18,23 +28,20 @@ function setOpen(head, open) {
|
|
|
18
28
|
panel.toggleAttribute('inert', !open);
|
|
19
29
|
}
|
|
20
30
|
export function toggleAccordion(head) {
|
|
21
|
-
if (head.getAttribute('aria-disabled') === 'true')
|
|
22
|
-
return;
|
|
23
31
|
const root = head.closest('.ss-accordion');
|
|
24
32
|
if (!root)
|
|
25
33
|
return;
|
|
26
34
|
const multiple = root.hasAttribute('data-ss-multiple');
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
emit(root, 'ss:change', { value: multiple ? openIds : openIds[0] });
|
|
35
|
+
const list = heads(root);
|
|
36
|
+
// The DOM is the store: read the open ids, ask the core, write the result back.
|
|
37
|
+
const next = accordionToggle({ open: list.filter(isOpen).map(idOf), multiple }, idOf(head), head.getAttribute('aria-disabled') === 'true');
|
|
38
|
+
if (!next)
|
|
39
|
+
return;
|
|
40
|
+
for (const h of list)
|
|
41
|
+
setOpen(h, next.includes(idOf(h)));
|
|
42
|
+
// Reported in DOM order, whatever order the sections were opened in.
|
|
43
|
+
const openIds = list.map(idOf).filter((id) => next.includes(id));
|
|
44
|
+
emit(root, 'ss:change', { value: accordionValue(openIds, multiple) });
|
|
38
45
|
}
|
|
39
46
|
export function installAccordion() {
|
|
40
47
|
on('click', HEAD, (head) => toggleAccordion(head));
|
|
@@ -42,20 +49,12 @@ export function installAccordion() {
|
|
|
42
49
|
const root = head.closest('.ss-accordion');
|
|
43
50
|
if (!root)
|
|
44
51
|
return;
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
if (e.key === 'ArrowDown')
|
|
49
|
-
target = wrap(i + 1, heads.length);
|
|
50
|
-
else if (e.key === 'ArrowUp')
|
|
51
|
-
target = wrap(i - 1, heads.length);
|
|
52
|
-
else if (e.key === 'Home')
|
|
53
|
-
target = 0;
|
|
54
|
-
else if (e.key === 'End')
|
|
55
|
-
target = heads.length - 1;
|
|
56
|
-
if (target < 0)
|
|
52
|
+
const list = heads(root);
|
|
53
|
+
const result = accordionHeaderKey(list.length, list.indexOf(head), e.key);
|
|
54
|
+
if (!result)
|
|
57
55
|
return;
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
if (result.preventDefault)
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
list[result.focus]?.focus();
|
|
60
59
|
});
|
|
61
60
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Write a state to a checkbox (property + `data-indeterminate`). Emits nothing. */
|
|
2
|
+
export declare function setCheckbox(input: HTMLInputElement, state: {
|
|
3
|
+
checked?: boolean;
|
|
4
|
+
indeterminate?: boolean;
|
|
5
|
+
}): void;
|
|
6
|
+
/** Copy `data-indeterminate="true"` onto the `indeterminate` property under `root`. */
|
|
7
|
+
export declare function mountCheckboxes(root?: ParentNode): void;
|
|
8
|
+
export declare function installCheckbox(): void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checkbox (DS-0197) — `.ss-checkbox .input[type=checkbox]` is a native checkbox, so toggling,
|
|
3
|
+
* Space, label presses and form submission need no script. This module adds what HTML cannot
|
|
4
|
+
* express: the mixed state (`data-indeterminate="true"` on the input → the `indeterminate`
|
|
5
|
+
* property, applied by `mount()`), the shared rule that a mixed checkbox toggles to checked, and
|
|
6
|
+
* an `ss:change` event on the root with `{ checked }`. No `reason`: the browser reports a press
|
|
7
|
+
* on the box, on the label and Space as the same `change` event. The decision comes from
|
|
8
|
+
* `../core/checkbox.js`, shared with the Svelte component; state is read from the DOM.
|
|
9
|
+
*/
|
|
10
|
+
import { on, emit, all, setAttrs } from './delegate.js';
|
|
11
|
+
import { checkboxInputAttrs, checkboxToggle } from '../core/checkbox.js';
|
|
12
|
+
const INPUT = '.ss-checkbox .input[type="checkbox"]';
|
|
13
|
+
/** Write a state to a checkbox (property + `data-indeterminate`). Emits nothing. */
|
|
14
|
+
export function setCheckbox(input, state) {
|
|
15
|
+
if (state.checked !== undefined)
|
|
16
|
+
input.checked = state.checked;
|
|
17
|
+
if (state.indeterminate !== undefined) {
|
|
18
|
+
input.indeterminate = state.indeterminate;
|
|
19
|
+
setAttrs(input, checkboxInputAttrs(state.indeterminate));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Copy `data-indeterminate="true"` onto the `indeterminate` property under `root`. */
|
|
23
|
+
export function mountCheckboxes(root = document) {
|
|
24
|
+
for (const input of all(root, `${INPUT}[data-indeterminate="true"]`)) {
|
|
25
|
+
input.indeterminate = true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export function installCheckbox() {
|
|
29
|
+
on('change', INPUT, (el) => {
|
|
30
|
+
const input = el;
|
|
31
|
+
// The browser has already flipped `checked` and cleared `indeterminate`; the state from
|
|
32
|
+
// before the press is the inverse value plus the attribute the markup still carries.
|
|
33
|
+
const next = checkboxToggle({
|
|
34
|
+
checked: !input.checked,
|
|
35
|
+
indeterminate: input.dataset.indeterminate === 'true',
|
|
36
|
+
disabled: input.disabled,
|
|
37
|
+
});
|
|
38
|
+
if (!next)
|
|
39
|
+
return;
|
|
40
|
+
setCheckbox(input, next);
|
|
41
|
+
emit(input.closest('.ss-checkbox') ?? input, 'ss:change', { checked: next.checked });
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -13,4 +13,6 @@ export declare function wrap(i: number, n: number): number;
|
|
|
13
13
|
export declare function all<E extends Element = HTMLElement>(root: ParentNode, selector: string): E[];
|
|
14
14
|
/** Resolve an `aria-controls` / `#id` reference, preferring the nearest root. */
|
|
15
15
|
export declare function byId(id: string | null): HTMLElement | null;
|
|
16
|
+
/** Write a core's attribute bag onto an element; `undefined` removes the attribute. */
|
|
17
|
+
export declare function setAttrs(el: Element, attrs: Record<string, string | number | undefined>): void;
|
|
16
18
|
export {};
|
package/dist/vanilla/delegate.js
CHANGED
|
@@ -31,3 +31,12 @@ export function byId(id) {
|
|
|
31
31
|
return null;
|
|
32
32
|
return document.getElementById(id.startsWith('#') ? id.slice(1) : id);
|
|
33
33
|
}
|
|
34
|
+
/** Write a core's attribute bag onto an element; `undefined` removes the attribute. */
|
|
35
|
+
export function setAttrs(el, attrs) {
|
|
36
|
+
for (const [name, value] of Object.entries(attrs)) {
|
|
37
|
+
if (value === undefined)
|
|
38
|
+
el.removeAttribute(name);
|
|
39
|
+
else
|
|
40
|
+
el.setAttribute(name, String(value));
|
|
41
|
+
}
|
|
42
|
+
}
|
package/dist/vanilla/fields.js
CHANGED
|
@@ -4,76 +4,81 @@
|
|
|
4
4
|
* - Input `clearable`: `.ss-field .clear` empties `.ss-input`, refocuses it and hides itself;
|
|
5
5
|
* typing shows it again (Input.svelte removes the button entirely — vanilla toggles `hidden`).
|
|
6
6
|
* - NumberField steppers: `.ss-numberfield .step.dec/.inc` nudge by `step`, clamped to
|
|
7
|
-
* `min`/`max` (
|
|
7
|
+
* `min`/`max` (decided in `core/number-field.ts`, like the component). At a bound a stepper becomes an
|
|
8
8
|
* `aria-disabled` no-op (still focusable, so focus never drops to <body>); it is natively
|
|
9
9
|
* `disabled` only when the input is disabled/readonly. Each nudge writes the new value to
|
|
10
10
|
* the field's polite `.live` region.
|
|
11
11
|
* - Textarea autosize: `.ss-textarea .field.autosize` grows with content. Browsers with
|
|
12
12
|
* `field-sizing: content` do it in CSS; the JS `scrollHeight` sync is the fallback.
|
|
13
13
|
*/
|
|
14
|
-
import { on, all } from './delegate.js';
|
|
14
|
+
import { on, all, setAttrs } from './delegate.js';
|
|
15
|
+
import { inputClear, inputShowClear } from '../core/input.js';
|
|
16
|
+
import { numberFieldAnnouncement, numberFieldOption, numberFieldParse, numberFieldStep, numberFieldStepperAttrs, } from '../core/number-field.js';
|
|
15
17
|
const fire = (el, type) => el.dispatchEvent(new Event(type, { bubbles: true }));
|
|
16
18
|
// ── Input clearable ─────────────────────────────────────────────────────────
|
|
19
|
+
// The decisions come from `../core/input.js`, shared with Input.svelte; state is read from the DOM.
|
|
20
|
+
const clearState = (input) => ({
|
|
21
|
+
value: input.value,
|
|
22
|
+
readonly: input.readOnly,
|
|
23
|
+
disabled: input.disabled,
|
|
24
|
+
});
|
|
17
25
|
function syncClear(input) {
|
|
18
26
|
const btn = input.closest('.control')?.querySelector('.clear');
|
|
19
27
|
if (btn)
|
|
20
|
-
btn.hidden = !input
|
|
28
|
+
btn.hidden = !inputShowClear(clearState(input));
|
|
21
29
|
}
|
|
22
30
|
export function clearInput(btn) {
|
|
23
31
|
const input = btn.closest('.control')?.querySelector('.ss-input');
|
|
24
32
|
if (!input)
|
|
25
33
|
return;
|
|
26
|
-
|
|
34
|
+
const result = inputClear(clearState(input));
|
|
35
|
+
if (!result)
|
|
36
|
+
return;
|
|
37
|
+
input.value = result.value;
|
|
27
38
|
fire(input, 'input');
|
|
28
39
|
syncClear(input);
|
|
29
|
-
|
|
40
|
+
if (result.focusInput)
|
|
41
|
+
input.focus();
|
|
30
42
|
}
|
|
31
43
|
// ── NumberField steppers ───────────────────────────────────────────────────
|
|
32
|
-
|
|
44
|
+
// Parsing, clamping, stepping and the stepper state come from `../core/number-field.js`,
|
|
45
|
+
// shared with NumberField.svelte; this side only reads the input and writes the result back.
|
|
46
|
+
const numberState = (input) => ({
|
|
47
|
+
value: numberFieldParse(input.value, input.valueAsNumber),
|
|
48
|
+
min: numberFieldOption(input.getAttribute('min')),
|
|
49
|
+
max: numberFieldOption(input.getAttribute('max')),
|
|
50
|
+
step: numberFieldOption(input.getAttribute('step')),
|
|
51
|
+
locked: input.disabled || input.readOnly,
|
|
52
|
+
});
|
|
33
53
|
function syncSteppers(input) {
|
|
34
54
|
const control = input.closest('.control');
|
|
35
55
|
if (!control)
|
|
36
56
|
return;
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const max = num(input.getAttribute('max'));
|
|
40
|
-
const locked = input.disabled || input.readOnly;
|
|
41
|
-
const dec = control.querySelector('.step.dec');
|
|
42
|
-
const inc = control.querySelector('.step.inc');
|
|
43
|
-
const bound = (btn, atBound) => {
|
|
57
|
+
const state = numberState(input);
|
|
58
|
+
const apply = (btn, dir) => {
|
|
44
59
|
if (!btn)
|
|
45
60
|
return;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
else
|
|
50
|
-
btn.removeAttribute('aria-disabled');
|
|
61
|
+
const { disabled, ...aria } = numberFieldStepperAttrs(state, dir);
|
|
62
|
+
btn.disabled = disabled;
|
|
63
|
+
setAttrs(btn, aria);
|
|
51
64
|
};
|
|
52
|
-
|
|
53
|
-
|
|
65
|
+
apply(control.querySelector('.step.dec'), -1);
|
|
66
|
+
apply(control.querySelector('.step.inc'), 1);
|
|
54
67
|
}
|
|
55
68
|
export function nudgeNumber(btn) {
|
|
56
69
|
const input = btn.closest('.control')?.querySelector('.ss-input');
|
|
57
70
|
if (!input || btn.disabled || btn.getAttribute('aria-disabled') === 'true')
|
|
58
71
|
return;
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const step = num(input.getAttribute('step')) ?? 1;
|
|
63
|
-
const current = input.value === '' || Number.isNaN(input.valueAsNumber) ? null : input.valueAsNumber;
|
|
64
|
-
const base = current ?? (dir > 0 ? (min ?? 0) : (max ?? 0));
|
|
65
|
-
let next = base + dir * step;
|
|
66
|
-
if (min != null && next < min)
|
|
67
|
-
next = min;
|
|
68
|
-
if (max != null && next > max)
|
|
69
|
-
next = max;
|
|
72
|
+
const next = numberFieldStep(numberState(input), btn.classList.contains('inc') ? 1 : -1);
|
|
73
|
+
if (next === null)
|
|
74
|
+
return;
|
|
70
75
|
input.value = String(next);
|
|
71
76
|
fire(input, 'input');
|
|
72
77
|
fire(input, 'change');
|
|
73
78
|
syncSteppers(input);
|
|
74
79
|
const live = input.closest('.ss-numberfield')?.querySelector('.live');
|
|
75
80
|
if (live)
|
|
76
|
-
live.textContent =
|
|
81
|
+
live.textContent = numberFieldAnnouncement(next);
|
|
77
82
|
}
|
|
78
83
|
// ── Textarea autosize ──────────────────────────────────────────────────────
|
|
79
84
|
export const supportsFieldSizing = typeof CSS !== 'undefined' &&
|
package/dist/vanilla/index.d.ts
CHANGED
|
@@ -9,7 +9,11 @@ export { showTooltip, hideTooltip } from './tooltip.js';
|
|
|
9
9
|
export { toggleSwitch } from './switch.js';
|
|
10
10
|
export { selectSegment } from './segmented.js';
|
|
11
11
|
export { toggleGrab, readPlacements } from './tierlist.js';
|
|
12
|
+
export { selectTab } from './tabs.js';
|
|
13
|
+
export { openPopover, closePopover } from './popover.js';
|
|
12
14
|
export { clearInput, nudgeNumber, autosize } from './fields.js';
|
|
15
|
+
export { setCheckbox } from './checkbox.js';
|
|
16
|
+
export { selectRadio } from './radio.js';
|
|
13
17
|
export { applyDesignConfig, designAttributes, getDesignConfig, paletteToCss, type DesignConfig, type ColorTheme, type Size, } from '../config.js';
|
|
14
18
|
/** Hydrate icon placeholders and initialise setup-type behaviours under `root`. */
|
|
15
19
|
export declare function mount(root?: ParentNode): void;
|
package/dist/vanilla/index.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* consumption path. Importing this module wires every behaviour once via document-level event
|
|
4
4
|
* delegation (so markup added later just works) and runs `mount()` when the DOM is ready.
|
|
5
5
|
*
|
|
6
|
-
* <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dssoca@0.
|
|
7
|
-
* <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dssoca@0.
|
|
8
|
-
* <script type="module" src="https://cdn.jsdelivr.net/npm/dssoca@0.
|
|
6
|
+
* <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dssoca@0.21/dist/theme.css">
|
|
7
|
+
* <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dssoca@0.21/dist/vanilla.css">
|
|
8
|
+
* <script type="module" src="https://cdn.jsdelivr.net/npm/dssoca@0.21/dist/vanilla/index.js"></script>
|
|
9
9
|
*
|
|
10
10
|
* Call `mount(root)` after injecting HTML that contains `[data-ss-icon]` placeholders or
|
|
11
11
|
* autosizing textareas. Nothing here imports Svelte or a `.svelte` module.
|
|
@@ -17,7 +17,11 @@ import { installTooltip } from './tooltip.js';
|
|
|
17
17
|
import { installSwitch } from './switch.js';
|
|
18
18
|
import { installSegmented } from './segmented.js';
|
|
19
19
|
import { installTierlist } from './tierlist.js';
|
|
20
|
+
import { installTabs } from './tabs.js';
|
|
21
|
+
import { installPopover } from './popover.js';
|
|
20
22
|
import { installFields, mountFields } from './fields.js';
|
|
23
|
+
import { installCheckbox, mountCheckboxes } from './checkbox.js';
|
|
24
|
+
import { installRadio } from './radio.js';
|
|
21
25
|
import { hydrateIcons } from './icons.js';
|
|
22
26
|
export { toast, toasts } from './toast.js';
|
|
23
27
|
export { iconSvg, hydrateIcons } from './icons.js';
|
|
@@ -29,12 +33,17 @@ export { showTooltip, hideTooltip } from './tooltip.js';
|
|
|
29
33
|
export { toggleSwitch } from './switch.js';
|
|
30
34
|
export { selectSegment } from './segmented.js';
|
|
31
35
|
export { toggleGrab, readPlacements } from './tierlist.js';
|
|
36
|
+
export { selectTab } from './tabs.js';
|
|
37
|
+
export { openPopover, closePopover } from './popover.js';
|
|
32
38
|
export { clearInput, nudgeNumber, autosize } from './fields.js';
|
|
39
|
+
export { setCheckbox } from './checkbox.js';
|
|
40
|
+
export { selectRadio } from './radio.js';
|
|
33
41
|
export { applyDesignConfig, designAttributes, getDesignConfig, paletteToCss, } from '../config.js';
|
|
34
42
|
/** Hydrate icon placeholders and initialise setup-type behaviours under `root`. */
|
|
35
43
|
export function mount(root = document) {
|
|
36
44
|
hydrateIcons(root);
|
|
37
45
|
mountFields(root);
|
|
46
|
+
mountCheckboxes(root);
|
|
38
47
|
}
|
|
39
48
|
const FLAG = '__dssocaVanilla';
|
|
40
49
|
/** Register every delegated behaviour once per document. Safe to call repeatedly. */
|
|
@@ -52,7 +61,11 @@ export function install() {
|
|
|
52
61
|
installSwitch();
|
|
53
62
|
installSegmented();
|
|
54
63
|
installTierlist();
|
|
64
|
+
installTabs();
|
|
65
|
+
installPopover();
|
|
55
66
|
installFields();
|
|
67
|
+
installCheckbox();
|
|
68
|
+
installRadio();
|
|
56
69
|
if (document.readyState === 'loading') {
|
|
57
70
|
document.addEventListener('DOMContentLoaded', () => mount(), { once: true });
|
|
58
71
|
}
|
package/dist/vanilla/menu.js
CHANGED
|
@@ -1,32 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Menu (DS-0148) —
|
|
3
|
-
*
|
|
2
|
+
* Menu (DS-0148) — Menu.svelte's open/close + roving-focus model over the exact same DOM:
|
|
3
|
+
* `.ss-menu > .trigger[aria-expanded][aria-controls]` and `.panel[role=menu] > .item`.
|
|
4
|
+
* The behaviour itself comes from `../core/menu.js`, shared with the Svelte component
|
|
5
|
+
* (DS-0198): this file reads the state from the DOM, asks the core, and writes the result back.
|
|
4
6
|
* Outside pointerdown closes without returning focus; Escape / item activation return focus
|
|
5
|
-
* to the trigger. Emits `ss:select`
|
|
6
|
-
* item's `data-value`, when authored)
|
|
7
|
-
* the activated item. A panel with neither
|
|
8
|
-
* `aria-labelledby` pointing at its trigger on first
|
|
7
|
+
* to the trigger. Emits on the root: `ss:select` with `{ index, value }` (`value` is the
|
|
8
|
+
* item's `data-value`, when authored) and `ss:openchange` with `{ open, reason }`. For
|
|
9
|
+
* `menuitemradio` items the check marker moves to the activated item. A panel with neither
|
|
10
|
+
* `aria-label` nor `aria-labelledby` gets `aria-labelledby` pointing at its trigger on first
|
|
11
|
+
* open (an id is minted if needed).
|
|
9
12
|
*/
|
|
10
|
-
import { on, emit, all } from './delegate.js';
|
|
13
|
+
import { on, emit, all, setAttrs } from './delegate.js';
|
|
11
14
|
import { iconSvg } from './icons.js';
|
|
15
|
+
import { menuClose, menuItemPress, menuOpen, menuOutsidePress, menuPanelAttrs, menuPanelKey, menuTriggerAttrs, menuTriggerKey, menuTriggerPress, } from '../core/menu.js';
|
|
12
16
|
const TRIGGER = '.ss-menu > .trigger';
|
|
13
17
|
const PANEL = '.ss-menu > .panel[role="menu"]';
|
|
14
18
|
function parts(el) {
|
|
15
19
|
const root = el.closest('.ss-menu');
|
|
16
|
-
const trigger = root?.querySelector(':scope > .trigger')
|
|
17
|
-
const panel = root?.querySelector(':scope > .panel')
|
|
18
|
-
return { root, trigger, panel };
|
|
20
|
+
const trigger = root?.querySelector(':scope > .trigger');
|
|
21
|
+
const panel = root?.querySelector(':scope > .panel');
|
|
22
|
+
return root && trigger && panel ? { root, trigger, panel } : null;
|
|
19
23
|
}
|
|
20
24
|
function items(panel) {
|
|
21
25
|
return all(panel, '.item').filter((i) => i.closest('.panel') === panel);
|
|
22
26
|
}
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
/** The menu's state, read from the DOM (the DOM is the store on the plain-HTML path). */
|
|
28
|
+
function read({ trigger, panel }) {
|
|
29
|
+
const list = items(panel);
|
|
30
|
+
return {
|
|
31
|
+
open: trigger.getAttribute('aria-expanded') === 'true',
|
|
32
|
+
active: list.indexOf(document.activeElement),
|
|
33
|
+
enabled: list
|
|
34
|
+
.map((i, index) => (i.disabled || i.getAttribute('aria-disabled') === 'true' ? -1 : index))
|
|
35
|
+
.filter((index) => index >= 0),
|
|
36
|
+
};
|
|
25
37
|
}
|
|
26
|
-
function focusItem(panel,
|
|
38
|
+
function focusItem(panel, index) {
|
|
39
|
+
const list = items(panel);
|
|
40
|
+
const item = list[index];
|
|
27
41
|
if (!item)
|
|
28
42
|
return;
|
|
29
|
-
for (const i of
|
|
43
|
+
for (const i of list)
|
|
30
44
|
i.tabIndex = i === item ? 0 : -1;
|
|
31
45
|
item.focus();
|
|
32
46
|
}
|
|
@@ -39,37 +53,63 @@ function ensureName(trigger, panel) {
|
|
|
39
53
|
trigger.id = `ss-menu-trigger-${++autoId}`;
|
|
40
54
|
panel.setAttribute('aria-labelledby', trigger.id);
|
|
41
55
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (!
|
|
56
|
+
/** Apply a core action to the DOM. */
|
|
57
|
+
function run(p, action) {
|
|
58
|
+
if (!action)
|
|
45
59
|
return;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
const { root, trigger, panel } = p;
|
|
61
|
+
switch (action.type) {
|
|
62
|
+
case 'open':
|
|
63
|
+
ensureName(trigger, panel);
|
|
64
|
+
setAttrs(trigger, menuTriggerAttrs(true));
|
|
65
|
+
setAttrs(panel, menuPanelAttrs(true));
|
|
66
|
+
panel.classList.add('open');
|
|
67
|
+
emit(root, 'ss:openchange', { open: true, reason: action.reason });
|
|
68
|
+
queueMicrotask(() => focusItem(panel, action.focus));
|
|
69
|
+
break;
|
|
70
|
+
case 'close':
|
|
71
|
+
setAttrs(trigger, menuTriggerAttrs(false));
|
|
72
|
+
setAttrs(panel, menuPanelAttrs(false));
|
|
73
|
+
panel.classList.remove('open');
|
|
74
|
+
for (const i of items(panel))
|
|
75
|
+
i.tabIndex = -1;
|
|
76
|
+
emit(root, 'ss:openchange', { open: false, reason: action.reason });
|
|
77
|
+
if (action.returnFocus)
|
|
78
|
+
trigger.focus();
|
|
79
|
+
break;
|
|
80
|
+
case 'focus':
|
|
81
|
+
focusItem(panel, action.index);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
54
84
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (!panel || trigger.getAttribute('aria-expanded') !== 'true')
|
|
85
|
+
function onKey(p, result, e) {
|
|
86
|
+
if (!result)
|
|
58
87
|
return;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
88
|
+
if (result.preventDefault)
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
run(p, result.action);
|
|
91
|
+
}
|
|
92
|
+
export function openMenu(trigger, focus = 'first') {
|
|
93
|
+
const p = parts(trigger);
|
|
94
|
+
if (p)
|
|
95
|
+
run(p, menuOpen(read(p), focus));
|
|
96
|
+
}
|
|
97
|
+
export function closeMenu(trigger, returnFocus = true) {
|
|
98
|
+
const p = parts(trigger);
|
|
99
|
+
if (p)
|
|
100
|
+
run(p, menuClose(read(p), returnFocus));
|
|
66
101
|
}
|
|
67
102
|
function activate(item) {
|
|
68
|
-
const
|
|
69
|
-
if (!
|
|
103
|
+
const p = parts(item);
|
|
104
|
+
if (!p)
|
|
105
|
+
return;
|
|
106
|
+
const list = items(p.panel);
|
|
107
|
+
const index = list.indexOf(item);
|
|
108
|
+
const result = menuItemPress(read(p), index);
|
|
109
|
+
if (!result)
|
|
70
110
|
return;
|
|
71
111
|
if (item.getAttribute('role') === 'menuitemradio') {
|
|
72
|
-
for (const i of
|
|
112
|
+
for (const i of list) {
|
|
73
113
|
const on = i === item;
|
|
74
114
|
i.classList.toggle('selected', on);
|
|
75
115
|
i.setAttribute('aria-checked', String(on));
|
|
@@ -78,67 +118,33 @@ function activate(item) {
|
|
|
78
118
|
marker.innerHTML = on ? iconSvg('check') : '';
|
|
79
119
|
}
|
|
80
120
|
}
|
|
81
|
-
emit(root, 'ss:select', { index
|
|
82
|
-
|
|
121
|
+
emit(p.root, 'ss:select', { index, value: item.dataset.value });
|
|
122
|
+
run(p, result.action);
|
|
83
123
|
}
|
|
84
124
|
export function installMenu() {
|
|
85
125
|
on('click', TRIGGER, (trigger) => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
openMenu(trigger, 'first');
|
|
126
|
+
const p = parts(trigger);
|
|
127
|
+
if (p)
|
|
128
|
+
run(p, menuTriggerPress(read(p)));
|
|
90
129
|
});
|
|
91
130
|
on('keydown', TRIGGER, (trigger, e) => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
else if (e.key === 'ArrowUp') {
|
|
97
|
-
e.preventDefault();
|
|
98
|
-
openMenu(trigger, 'last');
|
|
99
|
-
}
|
|
131
|
+
const p = parts(trigger);
|
|
132
|
+
if (p)
|
|
133
|
+
onKey(p, menuTriggerKey(read(p), e.key), e);
|
|
100
134
|
});
|
|
101
135
|
on('keydown', PANEL, (panel, e) => {
|
|
102
|
-
const
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
const list = enabled(panel);
|
|
106
|
-
const active = list.findIndex((i) => i === document.activeElement);
|
|
107
|
-
const pick = (i) => focusItem(panel, list[((i % list.length) + list.length) % list.length]);
|
|
108
|
-
switch (e.key) {
|
|
109
|
-
case 'ArrowDown':
|
|
110
|
-
e.preventDefault();
|
|
111
|
-
pick(active < 0 ? 0 : active + 1);
|
|
112
|
-
break;
|
|
113
|
-
case 'ArrowUp':
|
|
114
|
-
e.preventDefault();
|
|
115
|
-
pick(active < 0 ? list.length - 1 : active - 1);
|
|
116
|
-
break;
|
|
117
|
-
case 'Home':
|
|
118
|
-
e.preventDefault();
|
|
119
|
-
pick(0);
|
|
120
|
-
break;
|
|
121
|
-
case 'End':
|
|
122
|
-
e.preventDefault();
|
|
123
|
-
pick(list.length - 1);
|
|
124
|
-
break;
|
|
125
|
-
case 'Escape':
|
|
126
|
-
e.preventDefault();
|
|
127
|
-
closeMenu(trigger);
|
|
128
|
-
break;
|
|
129
|
-
case 'Tab':
|
|
130
|
-
closeMenu(trigger, false);
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
136
|
+
const p = parts(panel);
|
|
137
|
+
if (p)
|
|
138
|
+
onKey(p, menuPanelKey(read(p), e.key), e);
|
|
133
139
|
});
|
|
134
140
|
on('click', `${PANEL} .item`, (item) => activate(item));
|
|
135
141
|
document.addEventListener('pointerdown', (e) => {
|
|
136
142
|
const t = e.target;
|
|
137
143
|
for (const trigger of all(document, `${TRIGGER}[aria-expanded="true"]`)) {
|
|
138
|
-
const
|
|
139
|
-
if (
|
|
144
|
+
const p = parts(trigger);
|
|
145
|
+
if (!p || (t && p.root.contains(t)))
|
|
140
146
|
continue;
|
|
141
|
-
|
|
147
|
+
run(p, menuOutsidePress(read(p)));
|
|
142
148
|
}
|
|
143
149
|
}, true);
|
|
144
150
|
}
|
package/dist/vanilla/modal.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { type ModalReason } from '../core/modal.js';
|
|
1
2
|
/** Lock page scrolling on `<html>` (ref-counted). Pair every call with `unlockScroll()`. */
|
|
2
3
|
export declare function lockScroll(): void;
|
|
3
4
|
/** Release one `lockScroll()`; the last release restores `<html>`'s previous `overflow`. */
|
|
4
5
|
export declare function unlockScroll(): void;
|
|
5
6
|
export declare function openModal(dialog: HTMLDialogElement): void;
|
|
6
|
-
|
|
7
|
+
/** Close `dialog`; `reason` is reported on its `ss:close` event. */
|
|
8
|
+
export declare function closeModal(dialog: HTMLDialogElement, reason?: ModalReason): void;
|
|
7
9
|
export declare function installModal(): void;
|