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
package/dist/vanilla/fields.js
CHANGED
|
@@ -4,63 +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
|
+
* `aria-disabled` no-op (still focusable, so focus never drops to <body>); it is natively
|
|
9
|
+
* `disabled` only when the input is disabled/readonly. Each nudge writes the new value to
|
|
10
|
+
* the field's polite `.live` region.
|
|
8
11
|
* - Textarea autosize: `.ss-textarea .field.autosize` grows with content. Browsers with
|
|
9
12
|
* `field-sizing: content` do it in CSS; the JS `scrollHeight` sync is the fallback.
|
|
10
13
|
*/
|
|
11
|
-
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';
|
|
12
17
|
const fire = (el, type) => el.dispatchEvent(new Event(type, { bubbles: true }));
|
|
13
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
|
+
});
|
|
14
25
|
function syncClear(input) {
|
|
15
26
|
const btn = input.closest('.control')?.querySelector('.clear');
|
|
16
27
|
if (btn)
|
|
17
|
-
btn.hidden = !input
|
|
28
|
+
btn.hidden = !inputShowClear(clearState(input));
|
|
18
29
|
}
|
|
19
30
|
export function clearInput(btn) {
|
|
20
31
|
const input = btn.closest('.control')?.querySelector('.ss-input');
|
|
21
32
|
if (!input)
|
|
22
33
|
return;
|
|
23
|
-
|
|
34
|
+
const result = inputClear(clearState(input));
|
|
35
|
+
if (!result)
|
|
36
|
+
return;
|
|
37
|
+
input.value = result.value;
|
|
24
38
|
fire(input, 'input');
|
|
25
39
|
syncClear(input);
|
|
26
|
-
|
|
40
|
+
if (result.focusInput)
|
|
41
|
+
input.focus();
|
|
27
42
|
}
|
|
28
43
|
// ── NumberField steppers ───────────────────────────────────────────────────
|
|
29
|
-
|
|
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
|
+
});
|
|
30
53
|
function syncSteppers(input) {
|
|
31
54
|
const control = input.closest('.control');
|
|
32
55
|
if (!control)
|
|
33
56
|
return;
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
57
|
+
const state = numberState(input);
|
|
58
|
+
const apply = (btn, dir) => {
|
|
59
|
+
if (!btn)
|
|
60
|
+
return;
|
|
61
|
+
const { disabled, ...aria } = numberFieldStepperAttrs(state, dir);
|
|
62
|
+
btn.disabled = disabled;
|
|
63
|
+
setAttrs(btn, aria);
|
|
64
|
+
};
|
|
65
|
+
apply(control.querySelector('.step.dec'), -1);
|
|
66
|
+
apply(control.querySelector('.step.inc'), 1);
|
|
44
67
|
}
|
|
45
68
|
export function nudgeNumber(btn) {
|
|
46
69
|
const input = btn.closest('.control')?.querySelector('.ss-input');
|
|
47
|
-
if (!input || btn.disabled)
|
|
70
|
+
if (!input || btn.disabled || btn.getAttribute('aria-disabled') === 'true')
|
|
71
|
+
return;
|
|
72
|
+
const next = numberFieldStep(numberState(input), btn.classList.contains('inc') ? 1 : -1);
|
|
73
|
+
if (next === null)
|
|
48
74
|
return;
|
|
49
|
-
const dir = btn.classList.contains('inc') ? 1 : -1;
|
|
50
|
-
const min = num(input.getAttribute('min'));
|
|
51
|
-
const max = num(input.getAttribute('max'));
|
|
52
|
-
const step = num(input.getAttribute('step')) ?? 1;
|
|
53
|
-
const current = input.value === '' || Number.isNaN(input.valueAsNumber) ? null : input.valueAsNumber;
|
|
54
|
-
const base = current ?? (dir > 0 ? (min ?? 0) : (max ?? 0));
|
|
55
|
-
let next = base + dir * step;
|
|
56
|
-
if (min != null && next < min)
|
|
57
|
-
next = min;
|
|
58
|
-
if (max != null && next > max)
|
|
59
|
-
next = max;
|
|
60
75
|
input.value = String(next);
|
|
61
76
|
fire(input, 'input');
|
|
62
77
|
fire(input, 'change');
|
|
63
78
|
syncSteppers(input);
|
|
79
|
+
const live = input.closest('.ss-numberfield')?.querySelector('.live');
|
|
80
|
+
if (live)
|
|
81
|
+
live.textContent = numberFieldAnnouncement(next);
|
|
64
82
|
}
|
|
65
83
|
// ── Textarea autosize ──────────────────────────────────────────────────────
|
|
66
84
|
export const supportsFieldSizing = typeof CSS !== 'undefined' &&
|
package/dist/vanilla/index.d.ts
CHANGED
|
@@ -2,14 +2,18 @@ export { toast, toasts } from './toast.js';
|
|
|
2
2
|
export type { Toast, ToastKind, ToastOptions, ToastPatch, ToastAction, PromiseMessages, } from './toast.js';
|
|
3
3
|
export { iconSvg, hydrateIcons, type IconOptions } from './icons.js';
|
|
4
4
|
export { registerIcon, type IconName } from '../icons.js';
|
|
5
|
-
export { openModal, closeModal } from './modal.js';
|
|
5
|
+
export { openModal, closeModal, lockScroll, unlockScroll } from './modal.js';
|
|
6
6
|
export { toggleAccordion } from './accordion.js';
|
|
7
7
|
export { openMenu, closeMenu } from './menu.js';
|
|
8
8
|
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,24 +17,33 @@ 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';
|
|
24
28
|
export { registerIcon } from '../icons.js';
|
|
25
|
-
export { openModal, closeModal } from './modal.js';
|
|
29
|
+
export { openModal, closeModal, lockScroll, unlockScroll } from './modal.js';
|
|
26
30
|
export { toggleAccordion } from './accordion.js';
|
|
27
31
|
export { openMenu, closeMenu } from './menu.js';
|
|
28
32
|
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,64 +1,115 @@
|
|
|
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.
|
|
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).
|
|
8
12
|
*/
|
|
9
|
-
import { on, emit, all } from './delegate.js';
|
|
13
|
+
import { on, emit, all, setAttrs } from './delegate.js';
|
|
10
14
|
import { iconSvg } from './icons.js';
|
|
15
|
+
import { menuClose, menuItemPress, menuOpen, menuOutsidePress, menuPanelAttrs, menuPanelKey, menuTriggerAttrs, menuTriggerKey, menuTriggerPress, } from '../core/menu.js';
|
|
11
16
|
const TRIGGER = '.ss-menu > .trigger';
|
|
12
17
|
const PANEL = '.ss-menu > .panel[role="menu"]';
|
|
13
18
|
function parts(el) {
|
|
14
19
|
const root = el.closest('.ss-menu');
|
|
15
|
-
const trigger = root?.querySelector(':scope > .trigger')
|
|
16
|
-
const panel = root?.querySelector(':scope > .panel')
|
|
17
|
-
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;
|
|
18
23
|
}
|
|
19
24
|
function items(panel) {
|
|
20
25
|
return all(panel, '.item').filter((i) => i.closest('.panel') === panel);
|
|
21
26
|
}
|
|
22
|
-
|
|
23
|
-
|
|
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
|
+
};
|
|
24
37
|
}
|
|
25
|
-
function focusItem(panel,
|
|
38
|
+
function focusItem(panel, index) {
|
|
39
|
+
const list = items(panel);
|
|
40
|
+
const item = list[index];
|
|
26
41
|
if (!item)
|
|
27
42
|
return;
|
|
28
|
-
for (const i of
|
|
43
|
+
for (const i of list)
|
|
29
44
|
i.tabIndex = i === item ? 0 : -1;
|
|
30
45
|
item.focus();
|
|
31
46
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
47
|
+
let autoId = 0;
|
|
48
|
+
/** An unnamed `role="menu"` panel is named by its trigger (mirrors Menu.svelte's fallback). */
|
|
49
|
+
function ensureName(trigger, panel) {
|
|
50
|
+
if (panel.hasAttribute('aria-label') || panel.hasAttribute('aria-labelledby'))
|
|
35
51
|
return;
|
|
36
|
-
trigger.
|
|
37
|
-
|
|
38
|
-
panel.setAttribute('aria-
|
|
39
|
-
queueMicrotask(() => {
|
|
40
|
-
const list = enabled(panel);
|
|
41
|
-
focusItem(panel, focus === 'first' ? list[0] : list[list.length - 1]);
|
|
42
|
-
});
|
|
52
|
+
if (!trigger.id)
|
|
53
|
+
trigger.id = `ss-menu-trigger-${++autoId}`;
|
|
54
|
+
panel.setAttribute('aria-labelledby', trigger.id);
|
|
43
55
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (!
|
|
56
|
+
/** Apply a core action to the DOM. */
|
|
57
|
+
function run(p, action) {
|
|
58
|
+
if (!action)
|
|
47
59
|
return;
|
|
48
|
-
trigger
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function onKey(p, result, e) {
|
|
86
|
+
if (!result)
|
|
87
|
+
return;
|
|
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));
|
|
55
101
|
}
|
|
56
102
|
function activate(item) {
|
|
57
|
-
const
|
|
58
|
-
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)
|
|
59
110
|
return;
|
|
60
111
|
if (item.getAttribute('role') === 'menuitemradio') {
|
|
61
|
-
for (const i of
|
|
112
|
+
for (const i of list) {
|
|
62
113
|
const on = i === item;
|
|
63
114
|
i.classList.toggle('selected', on);
|
|
64
115
|
i.setAttribute('aria-checked', String(on));
|
|
@@ -67,67 +118,33 @@ function activate(item) {
|
|
|
67
118
|
marker.innerHTML = on ? iconSvg('check') : '';
|
|
68
119
|
}
|
|
69
120
|
}
|
|
70
|
-
emit(root, 'ss:select', { index
|
|
71
|
-
|
|
121
|
+
emit(p.root, 'ss:select', { index, value: item.dataset.value });
|
|
122
|
+
run(p, result.action);
|
|
72
123
|
}
|
|
73
124
|
export function installMenu() {
|
|
74
125
|
on('click', TRIGGER, (trigger) => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
openMenu(trigger, 'first');
|
|
126
|
+
const p = parts(trigger);
|
|
127
|
+
if (p)
|
|
128
|
+
run(p, menuTriggerPress(read(p)));
|
|
79
129
|
});
|
|
80
130
|
on('keydown', TRIGGER, (trigger, e) => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
else if (e.key === 'ArrowUp') {
|
|
86
|
-
e.preventDefault();
|
|
87
|
-
openMenu(trigger, 'last');
|
|
88
|
-
}
|
|
131
|
+
const p = parts(trigger);
|
|
132
|
+
if (p)
|
|
133
|
+
onKey(p, menuTriggerKey(read(p), e.key), e);
|
|
89
134
|
});
|
|
90
135
|
on('keydown', PANEL, (panel, e) => {
|
|
91
|
-
const
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
const list = enabled(panel);
|
|
95
|
-
const active = list.findIndex((i) => i === document.activeElement);
|
|
96
|
-
const pick = (i) => focusItem(panel, list[((i % list.length) + list.length) % list.length]);
|
|
97
|
-
switch (e.key) {
|
|
98
|
-
case 'ArrowDown':
|
|
99
|
-
e.preventDefault();
|
|
100
|
-
pick(active < 0 ? 0 : active + 1);
|
|
101
|
-
break;
|
|
102
|
-
case 'ArrowUp':
|
|
103
|
-
e.preventDefault();
|
|
104
|
-
pick(active < 0 ? list.length - 1 : active - 1);
|
|
105
|
-
break;
|
|
106
|
-
case 'Home':
|
|
107
|
-
e.preventDefault();
|
|
108
|
-
pick(0);
|
|
109
|
-
break;
|
|
110
|
-
case 'End':
|
|
111
|
-
e.preventDefault();
|
|
112
|
-
pick(list.length - 1);
|
|
113
|
-
break;
|
|
114
|
-
case 'Escape':
|
|
115
|
-
e.preventDefault();
|
|
116
|
-
closeMenu(trigger);
|
|
117
|
-
break;
|
|
118
|
-
case 'Tab':
|
|
119
|
-
closeMenu(trigger, false);
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
136
|
+
const p = parts(panel);
|
|
137
|
+
if (p)
|
|
138
|
+
onKey(p, menuPanelKey(read(p), e.key), e);
|
|
122
139
|
});
|
|
123
140
|
on('click', `${PANEL} .item`, (item) => activate(item));
|
|
124
141
|
document.addEventListener('pointerdown', (e) => {
|
|
125
142
|
const t = e.target;
|
|
126
143
|
for (const trigger of all(document, `${TRIGGER}[aria-expanded="true"]`)) {
|
|
127
|
-
const
|
|
128
|
-
if (
|
|
144
|
+
const p = parts(trigger);
|
|
145
|
+
if (!p || (t && p.root.contains(t)))
|
|
129
146
|
continue;
|
|
130
|
-
|
|
147
|
+
run(p, menuOutsidePress(read(p)));
|
|
131
148
|
}
|
|
132
149
|
}, true);
|
|
133
150
|
}
|
package/dist/vanilla/modal.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { type ModalReason } from '../core/modal.js';
|
|
2
|
+
/** Lock page scrolling on `<html>` (ref-counted). Pair every call with `unlockScroll()`. */
|
|
3
|
+
export declare function lockScroll(): void;
|
|
4
|
+
/** Release one `lockScroll()`; the last release restores `<html>`'s previous `overflow`. */
|
|
5
|
+
export declare function unlockScroll(): void;
|
|
1
6
|
export declare function openModal(dialog: HTMLDialogElement): void;
|
|
2
|
-
|
|
7
|
+
/** Close `dialog`; `reason` is reported on its `ss:close` event. */
|
|
8
|
+
export declare function closeModal(dialog: HTMLDialogElement, reason?: ModalReason): void;
|
|
3
9
|
export declare function installModal(): void;
|
package/dist/vanilla/modal.js
CHANGED
|
@@ -5,17 +5,92 @@
|
|
|
5
5
|
* <button data-ss-modal="#confirm">Open</button>
|
|
6
6
|
* <dialog class="ss-modal" id="confirm"> … <button class="close" data-ss-dismiss>×</button>
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* when it carries `data-ss-no-esc` (mirrors `closeOnBackdrop` / `closeOnEsc`).
|
|
8
|
+
* A backdrop click closes unless the dialog carries `data-ss-static`; Escape is blocked
|
|
9
|
+
* when it carries `data-ss-no-esc` (mirrors `closeOnBackdrop` / `closeOnEsc`). Those decisions
|
|
10
|
+
* come from `core/modal.ts`, the same functions Modal.svelte calls. Every close emits `ss:close`
|
|
11
|
+
* on the dialog with `{ reason }` (escape · backdrop · button · programmatic).
|
|
12
|
+
*
|
|
13
|
+
* While a modal is open the page behind it must not scroll (DS-0178): `lockScroll()` sets
|
|
14
|
+
* `overflow: hidden` on `<html>` and `unlockScroll()` restores it. The lock is ref-counted on
|
|
15
|
+
* `<html data-ss-scroll-lock>` so stacked dialogs, and the Svelte component sharing this helper
|
|
16
|
+
* from a separate bundle, release it only when the last one closes.
|
|
10
17
|
*/
|
|
11
|
-
import { on, byId } from './delegate.js';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
import { on, byId, emit } from './delegate.js';
|
|
19
|
+
import { modalBackdropPress, modalCancel, modalClosed, modalDismissPress, modalOpenerPress, } from '../core/modal.js';
|
|
20
|
+
const COUNT = 'ssScrollLock';
|
|
21
|
+
const PREV = 'ssScrollLockPrev';
|
|
22
|
+
/** Lock page scrolling on `<html>` (ref-counted). Pair every call with `unlockScroll()`. */
|
|
23
|
+
export function lockScroll() {
|
|
24
|
+
if (typeof document === 'undefined')
|
|
25
|
+
return;
|
|
26
|
+
const root = document.documentElement;
|
|
27
|
+
const n = Number(root.dataset[COUNT] ?? 0) || 0;
|
|
28
|
+
if (n === 0) {
|
|
29
|
+
root.dataset[PREV] = root.style.overflow;
|
|
30
|
+
root.style.overflow = 'hidden';
|
|
31
|
+
}
|
|
32
|
+
root.dataset[COUNT] = String(n + 1);
|
|
33
|
+
}
|
|
34
|
+
/** Release one `lockScroll()`; the last release restores `<html>`'s previous `overflow`. */
|
|
35
|
+
export function unlockScroll() {
|
|
36
|
+
if (typeof document === 'undefined')
|
|
37
|
+
return;
|
|
38
|
+
const root = document.documentElement;
|
|
39
|
+
const n = Number(root.dataset[COUNT] ?? 0) || 0;
|
|
40
|
+
if (n <= 0)
|
|
41
|
+
return;
|
|
42
|
+
if (n > 1) {
|
|
43
|
+
root.dataset[COUNT] = String(n - 1);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
root.style.overflow = root.dataset[PREV] ?? '';
|
|
47
|
+
delete root.dataset[COUNT];
|
|
48
|
+
delete root.dataset[PREV];
|
|
49
|
+
}
|
|
50
|
+
// Dialogs that currently hold a scroll lock (so a lock is taken and released exactly once).
|
|
51
|
+
const locked = new WeakSet();
|
|
52
|
+
function release(dialog) {
|
|
53
|
+
if (!locked.has(dialog))
|
|
54
|
+
return;
|
|
55
|
+
locked.delete(dialog);
|
|
56
|
+
unlockScroll();
|
|
15
57
|
}
|
|
16
|
-
|
|
58
|
+
// Why a dialog is about to close, kept from the action (or the cancel) until its native `close`.
|
|
59
|
+
const pending = new WeakMap();
|
|
60
|
+
/** The core's state, read from the DOM. */
|
|
61
|
+
function stateOf(dialog) {
|
|
62
|
+
return {
|
|
63
|
+
open: dialog.open,
|
|
64
|
+
closeOnEsc: !dialog.hasAttribute('data-ss-no-esc'),
|
|
65
|
+
closeOnBackdrop: !dialog.hasAttribute('data-ss-static'),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export function openModal(dialog) {
|
|
17
69
|
if (dialog.open)
|
|
70
|
+
return;
|
|
71
|
+
pending.delete(dialog);
|
|
72
|
+
dialog.showModal();
|
|
73
|
+
if (!locked.has(dialog)) {
|
|
74
|
+
locked.add(dialog);
|
|
75
|
+
lockScroll();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** Close `dialog`; `reason` is reported on its `ss:close` event. */
|
|
79
|
+
export function closeModal(dialog, reason = 'programmatic') {
|
|
80
|
+
if (dialog.open) {
|
|
81
|
+
pending.set(dialog, reason);
|
|
18
82
|
dialog.close();
|
|
83
|
+
}
|
|
84
|
+
release(dialog);
|
|
85
|
+
}
|
|
86
|
+
/** Apply a core action to the DOM. */
|
|
87
|
+
function run(dialog, action) {
|
|
88
|
+
if (!action)
|
|
89
|
+
return;
|
|
90
|
+
if (action.type === 'open')
|
|
91
|
+
openModal(dialog);
|
|
92
|
+
else
|
|
93
|
+
closeModal(dialog, action.reason);
|
|
19
94
|
}
|
|
20
95
|
export function installModal() {
|
|
21
96
|
on('click', '[data-ss-modal]', (opener, e) => {
|
|
@@ -23,20 +98,50 @@ export function installModal() {
|
|
|
23
98
|
if (!(target instanceof HTMLDialogElement))
|
|
24
99
|
return;
|
|
25
100
|
e.preventDefault();
|
|
26
|
-
|
|
101
|
+
run(target, modalOpenerPress(stateOf(target)));
|
|
27
102
|
});
|
|
28
103
|
on('click', 'dialog.ss-modal [data-ss-dismiss]', (btn) => {
|
|
29
104
|
const dialog = btn.closest('dialog.ss-modal');
|
|
30
105
|
if (dialog instanceof HTMLDialogElement)
|
|
31
|
-
|
|
106
|
+
run(dialog, modalDismissPress(stateOf(dialog)));
|
|
107
|
+
});
|
|
108
|
+
// A press that starts on the dialog itself is a backdrop hit; the dialog closes on the click
|
|
109
|
+
// that follows. Closing on the pointerdown would return focus to the opener and then let the
|
|
110
|
+
// same gesture's mousedown blur it, dropping focus on <body>. Remembering where the press
|
|
111
|
+
// began keeps a drag from inside the panel to the backdrop from closing.
|
|
112
|
+
let pressed = null;
|
|
113
|
+
document.addEventListener('pointerdown', (e) => {
|
|
114
|
+
const t = e.target;
|
|
115
|
+
pressed = t instanceof HTMLDialogElement && t.matches('dialog.ss-modal') ? t : null;
|
|
32
116
|
});
|
|
33
|
-
on('
|
|
34
|
-
|
|
117
|
+
on('click', 'dialog.ss-modal', (dialog, e) => {
|
|
118
|
+
const hit = pressed === dialog && e.target === dialog;
|
|
119
|
+
pressed = null;
|
|
120
|
+
if (!(dialog instanceof HTMLDialogElement))
|
|
35
121
|
return;
|
|
36
|
-
|
|
122
|
+
run(dialog, modalBackdropPress(stateOf(dialog), hit));
|
|
37
123
|
});
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
124
|
+
// Native closes (Escape, `<form method="dialog">`, a direct `.close()`) release the scroll
|
|
125
|
+
// lock too. `close` does not bubble — capture it.
|
|
126
|
+
on('close', 'dialog.ss-modal', (dialog) => {
|
|
127
|
+
if (!(dialog instanceof HTMLDialogElement))
|
|
128
|
+
return;
|
|
129
|
+
const details = modalClosed(pending.get(dialog));
|
|
130
|
+
pending.delete(dialog);
|
|
131
|
+
release(dialog);
|
|
132
|
+
emit(dialog, 'ss:close', details);
|
|
133
|
+
}, { capture: true });
|
|
134
|
+
// Escape fires `cancel` before the browser closes the dialog. `cancel` does not bubble —
|
|
135
|
+
// capture it.
|
|
136
|
+
on('cancel', 'dialog.ss-modal', (dialog, e) => {
|
|
137
|
+
if (!(dialog instanceof HTMLDialogElement))
|
|
138
|
+
return;
|
|
139
|
+
const result = modalCancel(stateOf(dialog), e.cancelable);
|
|
140
|
+
if (result.preventDefault)
|
|
141
|
+
e.preventDefault();
|
|
142
|
+
if (result.reason)
|
|
143
|
+
pending.set(dialog, result.reason);
|
|
144
|
+
else
|
|
145
|
+
pending.delete(dialog);
|
|
41
146
|
}, { capture: true });
|
|
42
147
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Move focus into an opened panel: its first focusable element, else the panel itself. Shared
|
|
3
|
+
* with Popover.svelte. Focus lands on the panel first and is then handed to the target, retried
|
|
4
|
+
* over a few frames: a child with its own `visibility` transition (`transition: all`, as on
|
|
5
|
+
* `.ss-btn`) still computes as hidden — so refuses focus — until that transition has started.
|
|
6
|
+
*/
|
|
7
|
+
export declare function focusPopoverPanel(panel: HTMLElement): void;
|
|
8
|
+
export declare function openPopover(trigger: HTMLElement): void;
|
|
9
|
+
export declare function closePopover(trigger: HTMLElement, returnFocus?: boolean): void;
|
|
10
|
+
export declare function installPopover(): void;
|