@ac-kit/ui-common 0.0.0-stage → 0.1.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/CHANGELOG.md +89 -0
- package/LICENSE +28 -0
- package/README.md +315 -2
- package/dist/button/button.d.ts +35 -0
- package/dist/button/button.d.ts.map +1 -0
- package/dist/button/button.js +22 -0
- package/dist/button/button.js.map +1 -0
- package/dist/dialog/dialog.d.ts +33 -0
- package/dist/dialog/dialog.d.ts.map +1 -0
- package/dist/dialog/dialog.js +23 -0
- package/dist/dialog/dialog.js.map +1 -0
- package/dist/focus/owns-arrow-keys.d.ts +31 -0
- package/dist/focus/owns-arrow-keys.d.ts.map +1 -0
- package/dist/focus/owns-arrow-keys.js +64 -0
- package/dist/focus/owns-arrow-keys.js.map +1 -0
- package/dist/focus/roving-focus.d.ts +34 -0
- package/dist/focus/roving-focus.d.ts.map +1 -0
- package/dist/focus/roving-focus.js +72 -0
- package/dist/focus/roving-focus.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/knob/knob.d.ts +106 -0
- package/dist/knob/knob.d.ts.map +1 -0
- package/dist/knob/knob.js +116 -0
- package/dist/knob/knob.js.map +1 -0
- package/dist/meter/meter.d.ts +63 -0
- package/dist/meter/meter.d.ts.map +1 -0
- package/dist/meter/meter.js +57 -0
- package/dist/meter/meter.js.map +1 -0
- package/dist/preact/button.d.ts +40 -0
- package/dist/preact/button.d.ts.map +1 -0
- package/dist/preact/button.js +22 -0
- package/dist/preact/button.js.map +1 -0
- package/dist/preact/dialog.d.ts +43 -0
- package/dist/preact/dialog.d.ts.map +1 -0
- package/dist/preact/dialog.js +89 -0
- package/dist/preact/dialog.js.map +1 -0
- package/dist/preact/index.d.ts +13 -0
- package/dist/preact/index.d.ts.map +1 -0
- package/dist/preact/index.js +13 -0
- package/dist/preact/index.js.map +1 -0
- package/dist/preact/join-classes.d.ts +10 -0
- package/dist/preact/join-classes.d.ts.map +1 -0
- package/dist/preact/join-classes.js +12 -0
- package/dist/preact/join-classes.js.map +1 -0
- package/dist/preact/knob.d.ts +51 -0
- package/dist/preact/knob.d.ts.map +1 -0
- package/dist/preact/knob.js +152 -0
- package/dist/preact/knob.js.map +1 -0
- package/dist/preact/meter.d.ts +34 -0
- package/dist/preact/meter.d.ts.map +1 -0
- package/dist/preact/meter.js +21 -0
- package/dist/preact/meter.js.map +1 -0
- package/dist/preact/radio-group.d.ts +50 -0
- package/dist/preact/radio-group.d.ts.map +1 -0
- package/dist/preact/radio-group.js +42 -0
- package/dist/preact/radio-group.js.map +1 -0
- package/dist/preact/readout.d.ts +22 -0
- package/dist/preact/readout.d.ts.map +1 -0
- package/dist/preact/readout.js +13 -0
- package/dist/preact/readout.js.map +1 -0
- package/dist/preact/slider.d.ts +40 -0
- package/dist/preact/slider.d.ts.map +1 -0
- package/dist/preact/slider.js +162 -0
- package/dist/preact/slider.js.map +1 -0
- package/dist/preact/switch.d.ts +25 -0
- package/dist/preact/switch.d.ts.map +1 -0
- package/dist/preact/switch.js +19 -0
- package/dist/preact/switch.js.map +1 -0
- package/dist/preact/toggle-button.d.ts +26 -0
- package/dist/preact/toggle-button.d.ts.map +1 -0
- package/dist/preact/toggle-button.js +16 -0
- package/dist/preact/toggle-button.js.map +1 -0
- package/dist/preact/toolbar.d.ts +24 -0
- package/dist/preact/toolbar.d.ts.map +1 -0
- package/dist/preact/toolbar.js +148 -0
- package/dist/preact/toolbar.js.map +1 -0
- package/dist/preact/use-element-binding.d.ts +32 -0
- package/dist/preact/use-element-binding.d.ts.map +1 -0
- package/dist/preact/use-element-binding.js +51 -0
- package/dist/preact/use-element-binding.js.map +1 -0
- package/dist/readout/readout.d.ts +41 -0
- package/dist/readout/readout.d.ts.map +1 -0
- package/dist/readout/readout.js +26 -0
- package/dist/readout/readout.js.map +1 -0
- package/dist/slider/_clamped-value.d.ts +7 -0
- package/dist/slider/_clamped-value.d.ts.map +1 -0
- package/dist/slider/_clamped-value.js +9 -0
- package/dist/slider/_clamped-value.js.map +1 -0
- package/dist/slider/slider-attributes.d.ts +50 -0
- package/dist/slider/slider-attributes.d.ts.map +1 -0
- package/dist/slider/slider-attributes.js +38 -0
- package/dist/slider/slider-attributes.js.map +1 -0
- package/dist/slider/slider-range.d.ts +59 -0
- package/dist/slider/slider-range.d.ts.map +1 -0
- package/dist/slider/slider-range.js +73 -0
- package/dist/slider/slider-range.js.map +1 -0
- package/dist/slider/slider-track.d.ts +37 -0
- package/dist/slider/slider-track.d.ts.map +1 -0
- package/dist/slider/slider-track.js +35 -0
- package/dist/slider/slider-track.js.map +1 -0
- package/dist/slider/stepped-value.d.ts +31 -0
- package/dist/slider/stepped-value.d.ts.map +1 -0
- package/dist/slider/stepped-value.js +55 -0
- package/dist/slider/stepped-value.js.map +1 -0
- package/dist/switch/switch.d.ts +30 -0
- package/dist/switch/switch.d.ts.map +1 -0
- package/dist/switch/switch.js +26 -0
- package/dist/switch/switch.js.map +1 -0
- package/dist/toggle-button/toggle-button.d.ts +44 -0
- package/dist/toggle-button/toggle-button.d.ts.map +1 -0
- package/dist/toggle-button/toggle-button.js +31 -0
- package/dist/toggle-button/toggle-button.js.map +1 -0
- package/dist/tone.d.ts +8 -0
- package/dist/tone.d.ts.map +1 -0
- package/dist/tone.js +2 -0
- package/dist/tone.js.map +1 -0
- package/dist/toolbar/toolbar.d.ts +35 -0
- package/dist/toolbar/toolbar.d.ts.map +1 -0
- package/dist/toolbar/toolbar.js +23 -0
- package/dist/toolbar/toolbar.js.map +1 -0
- package/package.json +100 -3
- package/styles.css +992 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"radio-group.js","sourceRoot":"","sources":["../../src/preact/radio-group.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,EAAE,WAAW,EAAE,MAAM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,KAAK,CAqCV,CACR,CAAC;YACH,CAAC,CAAC,IACQ,CACX,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ComponentChildren, JSX } from "preact";
|
|
2
|
+
import { type ReadoutLive } from "../readout/readout.js";
|
|
3
|
+
import type { ControlTone } from "../tone.js";
|
|
4
|
+
/** Props of {@link Readout}. */
|
|
5
|
+
export type ReadoutProps = {
|
|
6
|
+
/** What the value is, drawn as its caption and naming it. */
|
|
7
|
+
label: string;
|
|
8
|
+
tone?: ControlTone;
|
|
9
|
+
/** Defaults to `off`: changes are not announced. */
|
|
10
|
+
live?: ReadoutLive;
|
|
11
|
+
/** The value, as text. */
|
|
12
|
+
children: ComponentChildren;
|
|
13
|
+
id?: string;
|
|
14
|
+
class?: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* A lit value under a small caption, like a hardware display's: a tempo, a bar
|
|
18
|
+
* number, a program. Read-only; for a value the person sets, use a `Knob` or a
|
|
19
|
+
* `Slider`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function Readout(props: ReadoutProps): JSX.Element;
|
|
22
|
+
//# sourceMappingURL=readout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readout.d.ts","sourceRoot":"","sources":["../../src/preact/readout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAErD,OAAO,EAAE,KAAK,WAAW,EAAqB,MAAM,uBAAuB,CAAC;AAC5E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG9C,gCAAgC;AAChC,MAAM,MAAM,YAAY,GAAG;IAC1B,6DAA6D;IAC7D,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,oDAAoD;IACpD,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,0BAA0B;IAC1B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,GAAG,CAAC,OAAO,CAexD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { readoutAttributes } from "../readout/readout.js";
|
|
3
|
+
import { joinClasses } from "./join-classes.js";
|
|
4
|
+
/**
|
|
5
|
+
* A lit value under a small caption, like a hardware display's: a tempo, a bar
|
|
6
|
+
* number, a program. Read-only; for a value the person sets, use a `Knob` or a
|
|
7
|
+
* `Slider`.
|
|
8
|
+
*/
|
|
9
|
+
export function Readout(props) {
|
|
10
|
+
const { label, tone, live, children, id } = props;
|
|
11
|
+
return (_jsxs("div", { ...readoutAttributes({ label, tone, live }), id: id, class: joinClasses("ack-control ack-readout", props.class), children: [_jsx("span", { class: "ack-readout-label", "aria-hidden": "true", children: label }), _jsx("span", { class: "ack-readout-value", children: children })] }));
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=readout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readout.js","sourceRoot":"","sources":["../../src/preact/readout.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAoB,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE5E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAehD;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,KAAmB;IAC1C,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC;IAElD,OAAO,CACN,kBACK,iBAAiB,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAC5C,EAAE,EAAE,EAAE,EACN,KAAK,EAAE,WAAW,CAAC,yBAAyB,EAAE,KAAK,CAAC,KAAK,CAAC,aAE1D,eAAM,KAAK,EAAC,mBAAmB,iBAAa,MAAM,YAChD,KAAK,GACA,EACP,eAAM,KAAK,EAAC,mBAAmB,YAAE,QAAQ,GAAQ,IAC5C,CACN,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Callable } from "@ac-kit/core";
|
|
2
|
+
import type { JSX } from "preact";
|
|
3
|
+
import { type SliderOrientation } from "../slider/slider-track.js";
|
|
4
|
+
import type { ControlTone } from "../tone.js";
|
|
5
|
+
/** Props of {@link Slider}. */
|
|
6
|
+
export type SliderProps = {
|
|
7
|
+
/** Its accessible name, also drawn above it. */
|
|
8
|
+
label: string;
|
|
9
|
+
value: number;
|
|
10
|
+
min: number;
|
|
11
|
+
max: number;
|
|
12
|
+
/** Defaults to 1. */
|
|
13
|
+
step?: number;
|
|
14
|
+
/** Defaults to `horizontal`. */
|
|
15
|
+
orientation?: SliderOrientation;
|
|
16
|
+
tone?: ControlTone;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
/** The value as a person reads it, shown and announced. Defaults to `String`. */
|
|
19
|
+
format?: Callable<[value: number], string>;
|
|
20
|
+
/** A new value, once per gesture: at a drag's end, or a key. */
|
|
21
|
+
onChange: Callable<[value: number]>;
|
|
22
|
+
/** The value following a drag, before it is committed through `onChange`. */
|
|
23
|
+
onInput?: Callable<[value: number]>;
|
|
24
|
+
id?: string;
|
|
25
|
+
class?: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A linear slider, horizontal or vertical as on a mixing desk, its value shown
|
|
29
|
+
* beside its label. Pressing anywhere on the track jumps the thumb there; it
|
|
30
|
+
* follows the pointer and reports a value once let go, at the point it was let
|
|
31
|
+
* go. A drag never ends in a click. Focused, the arrow keys step it, Page Up
|
|
32
|
+
* and Page Down by ten steps, Home and End to the ends. The page still scrolls
|
|
33
|
+
* across it: a press that turns into a scroll is cancelled and reports
|
|
34
|
+
* nothing.
|
|
35
|
+
*
|
|
36
|
+
* For a setting with room to spare, or the large entry surface a `Knob` opens;
|
|
37
|
+
* where space is short, prefer a `Knob`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function Slider(props: SliderProps): JSX.Element;
|
|
40
|
+
//# sourceMappingURL=slider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slider.d.ts","sourceRoot":"","sources":["../../src/preact/slider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAMlC,OAAO,EACN,KAAK,iBAAiB,EAGtB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI9C,+BAA+B;AAC/B,MAAM,MAAM,WAAW,GAAG;IACzB,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,qBAAqB;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iFAAiF;IACjF,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;IAC3C,gEAAgE;IAChE,QAAQ,EAAE,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IACpC,6EAA6E;IAC7E,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IACpC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AASF;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,CAAC,OAAO,CA+MtD"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { bindPointers } from "@ac-kit/ui-gesture/dom";
|
|
3
|
+
import { useEffect, useId, useRef, useState } from "preact/hooks";
|
|
4
|
+
import { clampedSliderValue_ } from "../slider/_clamped-value.js";
|
|
5
|
+
import { sliderAttributes } from "../slider/slider-attributes.js";
|
|
6
|
+
import { sliderFraction } from "../slider/slider-range.js";
|
|
7
|
+
import { sliderTrackValueAt, } from "../slider/slider-track.js";
|
|
8
|
+
import { steppedValue } from "../slider/stepped-value.js";
|
|
9
|
+
import { joinClasses } from "./join-classes.js";
|
|
10
|
+
import { useElementBinding, useLatest } from "./use-element-binding.js";
|
|
11
|
+
/**
|
|
12
|
+
* A linear slider, horizontal or vertical as on a mixing desk, its value shown
|
|
13
|
+
* beside its label. Pressing anywhere on the track jumps the thumb there; it
|
|
14
|
+
* follows the pointer and reports a value once let go, at the point it was let
|
|
15
|
+
* go. A drag never ends in a click. Focused, the arrow keys step it, Page Up
|
|
16
|
+
* and Page Down by ten steps, Home and End to the ends. The page still scrolls
|
|
17
|
+
* across it: a press that turns into a scroll is cancelled and reports
|
|
18
|
+
* nothing.
|
|
19
|
+
*
|
|
20
|
+
* For a setting with room to spare, or the large entry surface a `Knob` opens;
|
|
21
|
+
* where space is short, prefer a `Knob`.
|
|
22
|
+
*/
|
|
23
|
+
export function Slider(props) {
|
|
24
|
+
const { label, value, min, max, step = 1, orientation = "horizontal", tone, disabled = false, format = String, onChange, onInput, id, } = props;
|
|
25
|
+
const range = { min, max, step };
|
|
26
|
+
const labelId = useId();
|
|
27
|
+
const [dragged, setDragged] = useState(undefined);
|
|
28
|
+
const drag = useRef(undefined);
|
|
29
|
+
const binding = useRef(undefined);
|
|
30
|
+
const isClickSuppressed = useRef(false);
|
|
31
|
+
const thumb = useRef(null);
|
|
32
|
+
const latest = useLatest({ range, value, disabled, onChange, onInput });
|
|
33
|
+
const shown = clampedSliderValue_(dragged ?? value, range);
|
|
34
|
+
const isVertical = orientation === "vertical";
|
|
35
|
+
const endDrag = () => {
|
|
36
|
+
drag.current = undefined;
|
|
37
|
+
setDragged(undefined);
|
|
38
|
+
};
|
|
39
|
+
const control = useElementBinding((element, signal) => {
|
|
40
|
+
const valueAt = (current, point) => sliderTrackValueAt(isVertical ? point.y : point.x, current.track, latest.current.range, orientation);
|
|
41
|
+
const follow = (current, next) => {
|
|
42
|
+
if (next !== current.value) {
|
|
43
|
+
latest.current.onInput?.(next);
|
|
44
|
+
}
|
|
45
|
+
current.value = next;
|
|
46
|
+
setDragged(next);
|
|
47
|
+
};
|
|
48
|
+
const bound = bindPointers(element, {
|
|
49
|
+
onDown: (down) => {
|
|
50
|
+
const box = bound.box ?? element.getBoundingClientRect();
|
|
51
|
+
const thumbBox = thumb.current?.getBoundingClientRect();
|
|
52
|
+
// The pointer's coordinates are the control's own, so the track
|
|
53
|
+
// starts at 0.
|
|
54
|
+
const track = isVertical
|
|
55
|
+
? {
|
|
56
|
+
start: 0,
|
|
57
|
+
length: box.height,
|
|
58
|
+
thumbLength: thumbBox?.height ?? 0,
|
|
59
|
+
}
|
|
60
|
+
: {
|
|
61
|
+
start: 0,
|
|
62
|
+
length: box.width,
|
|
63
|
+
thumbLength: thumbBox?.width ?? 0,
|
|
64
|
+
};
|
|
65
|
+
const current = {
|
|
66
|
+
pointerId: down.pointerId,
|
|
67
|
+
track,
|
|
68
|
+
value: latest.current.value,
|
|
69
|
+
hasMoved: false,
|
|
70
|
+
};
|
|
71
|
+
drag.current = current;
|
|
72
|
+
isClickSuppressed.current = false;
|
|
73
|
+
thumb.current?.focus();
|
|
74
|
+
follow(current, valueAt(current, down));
|
|
75
|
+
},
|
|
76
|
+
onMove: (sample) => {
|
|
77
|
+
const current = drag.current;
|
|
78
|
+
if (current?.pointerId === sample.pointerId) {
|
|
79
|
+
current.hasMoved = true;
|
|
80
|
+
follow(current, valueAt(current, sample));
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
onUp: (sample) => {
|
|
84
|
+
const current = drag.current;
|
|
85
|
+
if (current?.pointerId !== sample.pointerId) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
endDrag();
|
|
89
|
+
if (latest.current.disabled) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
// The release point decides, not the last move.
|
|
93
|
+
const next = valueAt(current, sample);
|
|
94
|
+
if (next !== current.value) {
|
|
95
|
+
latest.current.onInput?.(next);
|
|
96
|
+
}
|
|
97
|
+
isClickSuppressed.current = current.hasMoved;
|
|
98
|
+
if (next !== latest.current.value) {
|
|
99
|
+
latest.current.onChange(next);
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
onCancel: (pointerId) => {
|
|
103
|
+
if (drag.current?.pointerId === pointerId) {
|
|
104
|
+
endDrag();
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
}, {
|
|
108
|
+
// One pointer at a time: a second one is never tracked, so it cannot
|
|
109
|
+
// keep the first's box for the next drag.
|
|
110
|
+
accept: (event) => event.button === 0 &&
|
|
111
|
+
!latest.current.disabled &&
|
|
112
|
+
drag.current === undefined,
|
|
113
|
+
// The page still scrolls across the slider; the browser's take-over
|
|
114
|
+
// cancels the press.
|
|
115
|
+
touchAction: isVertical ? "pan-x pinch-zoom" : "pan-y pinch-zoom",
|
|
116
|
+
signal,
|
|
117
|
+
});
|
|
118
|
+
binding.current = bound;
|
|
119
|
+
// The click that follows a drag is not a press of anything under it.
|
|
120
|
+
element.addEventListener("click", (event) => {
|
|
121
|
+
if (isClickSuppressed.current && event.detail !== 0) {
|
|
122
|
+
isClickSuppressed.current = false;
|
|
123
|
+
event.preventDefault();
|
|
124
|
+
event.stopImmediatePropagation();
|
|
125
|
+
}
|
|
126
|
+
}, { capture: true, signal });
|
|
127
|
+
return {
|
|
128
|
+
[Symbol.dispose]() {
|
|
129
|
+
bound[Symbol.dispose]();
|
|
130
|
+
binding.current = undefined;
|
|
131
|
+
endDrag();
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}, [isVertical]);
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
if (disabled) {
|
|
137
|
+
binding.current?.cancel();
|
|
138
|
+
endDrag();
|
|
139
|
+
}
|
|
140
|
+
}, [disabled]);
|
|
141
|
+
const onKeyDown = (event) => {
|
|
142
|
+
if (disabled) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const next = steppedValue(value, event.key, range);
|
|
146
|
+
if (next === undefined) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
event.preventDefault();
|
|
150
|
+
if (next !== value) {
|
|
151
|
+
onChange(next);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
return (_jsxs("div", { id: id, class: joinClasses("ack-control ack-slider", props.class), "data-orientation": orientation, "data-tone": tone, "data-dragging": dragged === undefined ? undefined : "", "data-disabled": disabled ? "" : undefined, style: { "--ack-slider-fraction": sliderFraction(shown, range) }, children: [_jsxs("div", { class: "ack-slider-header", children: [_jsx("span", { class: "ack-slider-label", id: labelId, children: label }), _jsx("span", { class: "ack-slider-value", "aria-hidden": "true", children: format(shown) })] }), _jsxs("div", { ref: control, class: "ack-slider-control", children: [_jsx("div", { class: "ack-slider-track", children: _jsx("div", { class: "ack-slider-range" }) }), _jsx("div", { ...sliderAttributes({
|
|
155
|
+
value: shown,
|
|
156
|
+
range,
|
|
157
|
+
valueText: format(shown),
|
|
158
|
+
orientation,
|
|
159
|
+
disabled,
|
|
160
|
+
}), ref: thumb, class: "ack-slider-thumb", "aria-labelledby": labelId, tabIndex: disabled ? -1 : 0, onKeyDown: onKeyDown })] })] }));
|
|
161
|
+
}
|
|
162
|
+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KAAK,CAAC,sBACvC,WAAW,eAClB,IAAI,mBACA,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,mBACtC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,EACxC,KAAK,EAAE,EAAE,uBAAuB,EAAE,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,aAEhE,eAAK,KAAK,EAAC,mBAAmB,aAC7B,eAAM,KAAK,EAAC,kBAAkB,EAAC,EAAE,EAAE,OAAO,YACxC,KAAK,GACA,EACP,eAAM,KAAK,EAAC,kBAAkB,iBAAa,MAAM,YAC/C,MAAM,CAAC,KAAK,CAAC,GACR,IACF,EACN,eAAK,GAAG,EAAE,OAAO,EAAE,KAAK,EAAC,oBAAoB,aAC5C,cAAK,KAAK,EAAC,kBAAkB,YAC5B,cAAK,KAAK,EAAC,kBAAkB,GAAG,GAC3B,EACN,iBACK,gBAAgB,CAAC;4BACpB,KAAK,EAAE,KAAK;4BACZ,KAAK;4BACL,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC;4BACxB,WAAW;4BACX,QAAQ;yBACR,CAAC,EACF,GAAG,EAAE,KAAK,EACV,KAAK,EAAC,kBAAkB,qBACP,OAAO,EACxB,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAC3B,SAAS,EAAE,SAAS,GACnB,IACG,IACD,CACN,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Callable } from "@ac-kit/core";
|
|
2
|
+
import type { JSX } from "preact";
|
|
3
|
+
/** Props of {@link Switch}. */
|
|
4
|
+
export type SwitchProps = {
|
|
5
|
+
/** Its accessible name, drawn beside it. */
|
|
6
|
+
label: string;
|
|
7
|
+
/** A sentence under the label, linked by `aria-describedby`. */
|
|
8
|
+
description?: string;
|
|
9
|
+
isOn: boolean;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
/** Activated: the state it asks for, `!isOn`. Pass it back as `isOn`. */
|
|
12
|
+
onToggle: Callable<[isOn: boolean]>;
|
|
13
|
+
id?: string;
|
|
14
|
+
class?: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* An on/off setting that takes effect as soon as it is flipped, like a phone's
|
|
18
|
+
* airplane-mode switch. A native button announced as a switch, so it takes
|
|
19
|
+
* focus and flips with Space and Enter.
|
|
20
|
+
*
|
|
21
|
+
* For a choice confirmed later with a form, use a checkbox; for a state shown
|
|
22
|
+
* on a hardware-style button, a `ToggleButton`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function Switch(props: SwitchProps): JSX.Element;
|
|
25
|
+
//# sourceMappingURL=switch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.d.ts","sourceRoot":"","sources":["../../src/preact/switch.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAMlC,+BAA+B;AAC/B,MAAM,MAAM,WAAW,GAAG;IACzB,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,yEAAyE;IACzE,QAAQ,EAAE,QAAQ,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IACpC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,CAAC,OAAO,CA+BtD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { useId } from "preact/hooks";
|
|
3
|
+
import { switchAttributes } from "../switch/switch.js";
|
|
4
|
+
import { joinClasses } from "./join-classes.js";
|
|
5
|
+
/**
|
|
6
|
+
* An on/off setting that takes effect as soon as it is flipped, like a phone's
|
|
7
|
+
* airplane-mode switch. A native button announced as a switch, so it takes
|
|
8
|
+
* focus and flips with Space and Enter.
|
|
9
|
+
*
|
|
10
|
+
* For a choice confirmed later with a form, use a checkbox; for a state shown
|
|
11
|
+
* on a hardware-style button, a `ToggleButton`.
|
|
12
|
+
*/
|
|
13
|
+
export function Switch(props) {
|
|
14
|
+
const { label, description, isOn, disabled = false, onToggle, id } = props;
|
|
15
|
+
const labelId = useId();
|
|
16
|
+
const descriptionId = useId();
|
|
17
|
+
return (_jsxs("button", { ...switchAttributes({ isOn, disabled }), type: "button", id: id, disabled: disabled, "aria-labelledby": labelId, "aria-describedby": description === undefined ? undefined : descriptionId, class: joinClasses("ack-control ack-switch", props.class), onClick: () => onToggle(!isOn), children: [_jsxs("span", { class: "ack-switch-text", children: [_jsx("span", { id: labelId, class: "ack-switch-label", children: label }), description !== undefined && (_jsx("span", { id: descriptionId, class: "ack-switch-description", children: description }))] }), _jsx("span", { class: "ack-switch-track", "aria-hidden": "true", children: _jsx("span", { class: "ack-switch-thumb" }) })] }));
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=switch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.js","sourceRoot":"","sources":["../../src/preact/switch.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAgBhD;;;;;;;GAOG;AACH,MAAM,UAAU,MAAM,CAAC,KAAkB;IACxC,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,GAAG,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC;IAC3E,MAAM,OAAO,GAAG,KAAK,EAAE,CAAC;IACxB,MAAM,aAAa,GAAG,KAAK,EAAE,CAAC;IAE9B,OAAO,CACN,qBACK,gBAAgB,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,EACxC,IAAI,EAAC,QAAQ,EACb,EAAE,EAAE,EAAE,EACN,QAAQ,EAAE,QAAQ,qBACD,OAAO,sBACN,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,EACvE,KAAK,EAAE,WAAW,CAAC,wBAAwB,EAAE,KAAK,CAAC,KAAK,CAAC,EACzD,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,aAE9B,gBAAM,KAAK,EAAC,iBAAiB,aAC5B,eAAM,EAAE,EAAE,OAAO,EAAE,KAAK,EAAC,kBAAkB,YACzC,KAAK,GACA,EACN,WAAW,KAAK,SAAS,IAAI,CAC7B,eAAM,EAAE,EAAE,aAAa,EAAE,KAAK,EAAC,wBAAwB,YACrD,WAAW,GACN,CACP,IACK,EACP,eAAM,KAAK,EAAC,kBAAkB,iBAAa,MAAM,YAChD,eAAM,KAAK,EAAC,kBAAkB,GAAG,GAC3B,IACC,CACT,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Callable } from "@ac-kit/core";
|
|
2
|
+
import type { ButtonHTMLAttributes, ComponentChildren, JSX } from "preact";
|
|
3
|
+
import { type ToggleButtonIndicator } from "../toggle-button/toggle-button.js";
|
|
4
|
+
import type { ControlTone } from "../tone.js";
|
|
5
|
+
/** Props of {@link ToggleButton}: its own, then any other `<button>` attribute. */
|
|
6
|
+
export type ToggleButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, "class" | "className" | "type" | "onClick" | "aria-pressed" | "children"> & {
|
|
7
|
+
isOn: boolean;
|
|
8
|
+
tone?: ControlTone;
|
|
9
|
+
/** Whether it draws a light before its label. Defaults to `none`. */
|
|
10
|
+
indicator?: ToggleButtonIndicator;
|
|
11
|
+
/** Activated: the state it asks for, `!isOn`. Pass it back as `isOn`. */
|
|
12
|
+
onToggle: Callable<[isOn: boolean]>;
|
|
13
|
+
/** Its label: text, an icon with an `aria-label`, or both. */
|
|
14
|
+
children: ComponentChildren;
|
|
15
|
+
class?: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* A latching button, like a hardware mute, loop or metronome button: plain
|
|
19
|
+
* while off, filled in its tone while on, with a light when `indicator` asks
|
|
20
|
+
* for one. A native button, so it takes focus and toggles with Space and Enter;
|
|
21
|
+
* announced as a toggle button, pressed or not.
|
|
22
|
+
*
|
|
23
|
+
* For a state that stays on; for a one-off action, use a plain button.
|
|
24
|
+
*/
|
|
25
|
+
export declare function ToggleButton(props: ToggleButtonProps): JSX.Element;
|
|
26
|
+
//# sourceMappingURL=toggle-button.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toggle-button.d.ts","sourceRoot":"","sources":["../../src/preact/toggle-button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE3E,OAAO,EACN,KAAK,qBAAqB,EAE1B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG9C,mFAAmF;AACnF,MAAM,MAAM,iBAAiB,GAAG,IAAI,CACnC,oBAAoB,CAAC,iBAAiB,CAAC,EACvC,OAAO,GAAG,WAAW,GAAG,MAAM,GAAG,SAAS,GAAG,cAAc,GAAG,UAAU,CACxE,GAAG;IACH,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,qEAAqE;IACrE,SAAS,CAAC,EAAE,qBAAqB,CAAC;IAClC,yEAAyE;IACzE,QAAQ,EAAE,QAAQ,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IACpC,8DAA8D;IAC9D,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,GAAG,CAAC,OAAO,CAyBlE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { toggleButtonAttributes, } from "../toggle-button/toggle-button.js";
|
|
3
|
+
import { joinClasses } from "./join-classes.js";
|
|
4
|
+
/**
|
|
5
|
+
* A latching button, like a hardware mute, loop or metronome button: plain
|
|
6
|
+
* while off, filled in its tone while on, with a light when `indicator` asks
|
|
7
|
+
* for one. A native button, so it takes focus and toggles with Space and Enter;
|
|
8
|
+
* announced as a toggle button, pressed or not.
|
|
9
|
+
*
|
|
10
|
+
* For a state that stays on; for a one-off action, use a plain button.
|
|
11
|
+
*/
|
|
12
|
+
export function ToggleButton(props) {
|
|
13
|
+
const { isOn, tone, indicator = "none", onToggle, children, class: extra, ...rest } = props;
|
|
14
|
+
return (_jsxs("button", { ...rest, ...toggleButtonAttributes({ isOn, tone, indicator }), type: "button", class: joinClasses("ack-control ack-toggle-button", extra), onClick: () => onToggle(!isOn), children: [indicator === "light" && (_jsx("span", { class: "ack-toggle-button-light", "aria-hidden": "true" })), children] }));
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=toggle-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toggle-button.js","sourceRoot":"","sources":["../../src/preact/toggle-button.tsx"],"names":[],"mappings":";AAGA,OAAO,EAEN,sBAAsB,GACtB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAkBhD;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,KAAwB;IACpD,MAAM,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,GAAG,MAAM,EAClB,QAAQ,EACR,QAAQ,EACR,KAAK,EAAE,KAAK,EACZ,GAAG,IAAI,EACP,GAAG,KAAK,CAAC;IAEV,OAAO,CACN,qBACK,IAAI,KACJ,sBAAsB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,EACrD,IAAI,EAAC,QAAQ,EACb,KAAK,EAAE,WAAW,CAAC,+BAA+B,EAAE,KAAK,CAAC,EAC1D,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,aAE7B,SAAS,KAAK,OAAO,IAAI,CACzB,eAAM,KAAK,EAAC,yBAAyB,iBAAa,MAAM,GAAG,CAC3D,EACA,QAAQ,IACD,CACT,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ComponentChildren, JSX } from "preact";
|
|
2
|
+
import { type ToolbarOrientation } from "../toolbar/toolbar.js";
|
|
3
|
+
/** Props of {@link Toolbar}. */
|
|
4
|
+
export type ToolbarProps = {
|
|
5
|
+
/** Its accessible name. */
|
|
6
|
+
label: string;
|
|
7
|
+
/** Defaults to `horizontal`. */
|
|
8
|
+
orientation?: ToolbarOrientation;
|
|
9
|
+
/** Buttons and other controls; arrow keys move between those focusable. */
|
|
10
|
+
children: ComponentChildren;
|
|
11
|
+
id?: string;
|
|
12
|
+
class?: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A row of controls with one tab stop, the arrow keys moving between them, Home
|
|
16
|
+
* and End to the first and last (Up and Down when vertical). The control
|
|
17
|
+
* focused last keeps the tab stop, so Tab returns to it.
|
|
18
|
+
*
|
|
19
|
+
* A control that owns the arrow keys itself keeps them: a radio group, a slider
|
|
20
|
+
* or knob, a text field. The toolbar leaves those events alone, so their arrows
|
|
21
|
+
* step their value and only Tab leaves them.
|
|
22
|
+
*/
|
|
23
|
+
export declare function Toolbar(props: ToolbarProps): JSX.Element;
|
|
24
|
+
//# sourceMappingURL=toolbar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolbar.d.ts","sourceRoot":"","sources":["../../src/preact/toolbar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAKrD,OAAO,EACN,KAAK,kBAAkB,EAEvB,MAAM,uBAAuB,CAAC;AAI/B,gCAAgC;AAChC,MAAM,MAAM,YAAY,GAAG;IAC1B,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,2EAA2E;IAC3E,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAsEF;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,GAAG,CAAC,OAAO,CA+GxD"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
|
+
import { useLayoutEffect, useRef } from "preact/hooks";
|
|
3
|
+
import { ownsArrowKeys } from "../focus/owns-arrow-keys.js";
|
|
4
|
+
import { rovingFocusIndex } from "../focus/roving-focus.js";
|
|
5
|
+
import { toolbarAttributes, } from "../toolbar/toolbar.js";
|
|
6
|
+
import { joinClasses } from "./join-classes.js";
|
|
7
|
+
import { useElementBinding } from "./use-element-binding.js";
|
|
8
|
+
const FOCUSABLE_SELECTOR_ = 'button, a[href], input:not([type="hidden"]), select, textarea, [tabindex], [contenteditable]:not([contenteditable="false"])';
|
|
9
|
+
function isFocusable_(element) {
|
|
10
|
+
return (!element.matches(":disabled") &&
|
|
11
|
+
element.getAttribute("aria-disabled") !== "true" &&
|
|
12
|
+
element.closest("[inert]") === null &&
|
|
13
|
+
element.checkVisibility({ visibilityProperty: true }));
|
|
14
|
+
}
|
|
15
|
+
function isSameRadioGroup_(first, second) {
|
|
16
|
+
return (first.type === "radio" &&
|
|
17
|
+
second.type === "radio" &&
|
|
18
|
+
first.name !== "" &&
|
|
19
|
+
first.name === second.name &&
|
|
20
|
+
first.form === second.form);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The toolbar's tab stops, in document order: each focusable descendant, a
|
|
24
|
+
* radio group counting as one stop, its checked radio or else its first. The
|
|
25
|
+
* other radios of a group are pushed to `others`, which stay out of the tab
|
|
26
|
+
* order.
|
|
27
|
+
*/
|
|
28
|
+
function tabStops_(toolbar, others = []) {
|
|
29
|
+
const stops = [];
|
|
30
|
+
const radioGroups = [];
|
|
31
|
+
for (const element of toolbar.querySelectorAll(FOCUSABLE_SELECTOR_)) {
|
|
32
|
+
if (!isFocusable_(element)) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (element instanceof HTMLInputElement && element.type === "radio") {
|
|
36
|
+
const index = radioGroups.findIndex((candidate) => isSameRadioGroup_(candidate, element));
|
|
37
|
+
const representative = radioGroups[index];
|
|
38
|
+
if (representative !== undefined) {
|
|
39
|
+
if (element.checked && !representative.checked) {
|
|
40
|
+
radioGroups[index] = element;
|
|
41
|
+
stops[stops.indexOf(representative)] = element;
|
|
42
|
+
others.push(representative);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
others.push(element);
|
|
46
|
+
}
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (element.name !== "") {
|
|
50
|
+
radioGroups.push(element);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
stops.push(element);
|
|
54
|
+
}
|
|
55
|
+
return stops;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A row of controls with one tab stop, the arrow keys moving between them, Home
|
|
59
|
+
* and End to the first and last (Up and Down when vertical). The control
|
|
60
|
+
* focused last keeps the tab stop, so Tab returns to it.
|
|
61
|
+
*
|
|
62
|
+
* A control that owns the arrow keys itself keeps them: a radio group, a slider
|
|
63
|
+
* or knob, a text field. The toolbar leaves those events alone, so their arrows
|
|
64
|
+
* step their value and only Tab leaves them.
|
|
65
|
+
*/
|
|
66
|
+
export function Toolbar(props) {
|
|
67
|
+
const { label, orientation = "horizontal", children, id } = props;
|
|
68
|
+
const sync = useRef(undefined);
|
|
69
|
+
const root = useElementBinding((toolbar, signal) => {
|
|
70
|
+
let current;
|
|
71
|
+
const refresh = () => {
|
|
72
|
+
const others = [];
|
|
73
|
+
const stops = tabStops_(toolbar, others);
|
|
74
|
+
for (const other of others) {
|
|
75
|
+
other.tabIndex = -1;
|
|
76
|
+
}
|
|
77
|
+
if (current === undefined || !stops.includes(current)) {
|
|
78
|
+
current = stops.find((stop) => stop.tabIndex === 0) ?? stops[0];
|
|
79
|
+
}
|
|
80
|
+
for (const stop of stops) {
|
|
81
|
+
stop.tabIndex = stop === current ? 0 : -1;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
sync.current = refresh;
|
|
85
|
+
refresh();
|
|
86
|
+
toolbar.addEventListener("focusin", (event) => {
|
|
87
|
+
const stop = tabStops_(toolbar).find((candidate) => candidate === event.target ||
|
|
88
|
+
(candidate instanceof HTMLInputElement &&
|
|
89
|
+
event.target instanceof HTMLInputElement &&
|
|
90
|
+
isSameRadioGroup_(candidate, event.target)));
|
|
91
|
+
if (stop !== undefined) {
|
|
92
|
+
current = stop;
|
|
93
|
+
refresh();
|
|
94
|
+
}
|
|
95
|
+
}, { signal });
|
|
96
|
+
toolbar.addEventListener("change", refresh, { signal });
|
|
97
|
+
toolbar.addEventListener("keydown", (event) => {
|
|
98
|
+
const { target } = event;
|
|
99
|
+
if (event.defaultPrevented ||
|
|
100
|
+
event.ctrlKey ||
|
|
101
|
+
event.altKey ||
|
|
102
|
+
event.metaKey ||
|
|
103
|
+
!(target instanceof HTMLElement) ||
|
|
104
|
+
ownsArrowKeys({
|
|
105
|
+
tagName: target.tagName,
|
|
106
|
+
type: target.type,
|
|
107
|
+
role: target.getAttribute("role") ?? undefined,
|
|
108
|
+
isContentEditable: target.isContentEditable,
|
|
109
|
+
})) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const stops = tabStops_(toolbar);
|
|
113
|
+
const index = stops.indexOf(target);
|
|
114
|
+
if (index === -1) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const next = rovingFocusIndex(index, event.key, stops.length, {
|
|
118
|
+
orientation: orientation === "vertical" ? "vertical" : "horizontal",
|
|
119
|
+
direction: getComputedStyle(toolbar).direction === "rtl" ? "rtl" : "ltr",
|
|
120
|
+
});
|
|
121
|
+
if (next === undefined) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
current = stops[next];
|
|
126
|
+
refresh();
|
|
127
|
+
current?.focus();
|
|
128
|
+
}, { signal });
|
|
129
|
+
const observer = new MutationObserver(refresh);
|
|
130
|
+
observer.observe(toolbar, {
|
|
131
|
+
childList: true,
|
|
132
|
+
subtree: true,
|
|
133
|
+
attributes: true,
|
|
134
|
+
attributeFilter: ["disabled", "aria-disabled", "hidden", "inert"],
|
|
135
|
+
});
|
|
136
|
+
return {
|
|
137
|
+
[Symbol.dispose]() {
|
|
138
|
+
observer.disconnect();
|
|
139
|
+
sync.current = undefined;
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}, [orientation]);
|
|
143
|
+
useLayoutEffect(() => {
|
|
144
|
+
sync.current?.();
|
|
145
|
+
});
|
|
146
|
+
return (_jsx("div", { ...toolbarAttributes({ label, orientation }), id: id, ref: root, class: joinClasses("ack-toolbar", props.class), children: children }));
|
|
147
|
+
}
|
|
148
|
+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aAC9D,CAAC,CAAC;YACH,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO;YACR,CAAC;YACD,KAAK,CAAC,cAAc,EAAE,CAAC;YACvB,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;YACtB,OAAO,EAAE,CAAC;YACV,OAAO,EAAE,KAAK,EAAE,CAAC;QAClB,CAAC,EACD,EAAE,MAAM,EAAE,CACV,CAAC;QAEF,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAC/C,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE;YACzB,SAAS,EAAE,IAAI;YACf,OAAO,EAAE,IAAI;YACb,UAAU,EAAE,IAAI;YAChB,eAAe,EAAE,CAAC,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,OAAO,CAAC;SACjE,CAAC,CAAC;QAEH,OAAO;YACN,CAAC,MAAM,CAAC,OAAO,CAAC;gBACf,QAAQ,CAAC,UAAU,EAAE,CAAC;gBACtB,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;YAC1B,CAAC;SACD,CAAC;IACH,CAAC,EACD,CAAC,WAAW,CAAC,CACb,CAAC;IACF,eAAe,CAAC,GAAG,EAAE;QACpB,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,OAAO,CACN,iBACK,iBAAiB,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,EAC7C,EAAE,EAAE,EAAE,EACN,GAAG,EAAE,IAAI,EACT,KAAK,EAAE,WAAW,CAAC,aAAa,EAAE,KAAK,CAAC,KAAK,CAAC,YAE7C,QAAQ,GACJ,CACN,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Callable } from "@ac-kit/core";
|
|
2
|
+
import type { RefCallback, RefObject } from "preact";
|
|
3
|
+
/**
|
|
4
|
+
* Runs `bind` on an element once it is mounted, and again when `deps` change or
|
|
5
|
+
* the element is replaced; before each re-run and at unmount it aborts the
|
|
6
|
+
* signal it passed and disposes what `bind` returned. For `ui-gesture/dom`
|
|
7
|
+
* bindings in this package's components, `ui-music`'s and the caller's.
|
|
8
|
+
*
|
|
9
|
+
* Returns the callback ref to put on the element, which is how the hook sees an
|
|
10
|
+
* element mounted late or swapped for another with the dependencies unchanged.
|
|
11
|
+
* The binding is made in the render that follows the element's mount, so a
|
|
12
|
+
* `touch-action` it sets comes right after the first paint; the stylesheet sets
|
|
13
|
+
* the same ones for the first press.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const root = useElementBinding<HTMLDivElement>(
|
|
17
|
+
* (element, signal) => bindPointers(element, handlers, { signal }),
|
|
18
|
+
* [],
|
|
19
|
+
* );
|
|
20
|
+
* return <div ref={root} />;
|
|
21
|
+
*/
|
|
22
|
+
export declare function useElementBinding<Target extends Element>(bind: Callable<[
|
|
23
|
+
element: Target,
|
|
24
|
+
signal: AbortSignal
|
|
25
|
+
], Disposable | undefined>, deps: ReadonlyArray<unknown>): RefCallback<Target>;
|
|
26
|
+
/**
|
|
27
|
+
* A ref whose `current` is always the latest `value`, for handlers a binding
|
|
28
|
+
* reads at each call. It is written during render, so a handler that runs
|
|
29
|
+
* between a render and its commit sees the newer value.
|
|
30
|
+
*/
|
|
31
|
+
export declare function useLatest<Value>(value: Value): Readonly<RefObject<Value>>;
|
|
32
|
+
//# sourceMappingURL=use-element-binding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-element-binding.d.ts","sourceRoot":"","sources":["../../src/preact/use-element-binding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGrD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,SAAS,OAAO,EACvD,IAAI,EAAE,QAAQ,CACb;IAAC,OAAO,EAAE,MAAM;IAAE,MAAM,EAAE,WAAW;CAAC,EACtC,UAAU,GAAG,SAAS,CACtB,EACD,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,GAC1B,WAAW,CAAC,MAAM,CAAC,CAqBrB;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAKzE"}
|