@ac-kit/ui-common 0.0.0-stage → 0.2.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 +244 -0
- package/LICENSE +28 -0
- package/README.md +633 -2
- package/dist/anchored/anchored.d.ts +19 -0
- package/dist/anchored/anchored.d.ts.map +1 -0
- package/dist/anchored/anchored.js +2 -0
- package/dist/anchored/anchored.js.map +1 -0
- 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/focus/typeahead.d.ts +112 -0
- package/dist/focus/typeahead.d.ts.map +1 -0
- package/dist/focus/typeahead.js +178 -0
- package/dist/focus/typeahead.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -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/menu/menu.d.ts +157 -0
- package/dist/menu/menu.d.ts.map +1 -0
- package/dist/menu/menu.js +162 -0
- package/dist/menu/menu.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/_anchor.d.ts +13 -0
- package/dist/preact/_anchor.d.ts.map +1 -0
- package/dist/preact/_anchor.js +39 -0
- package/dist/preact/_anchor.js.map +1 -0
- package/dist/preact/_dom.d.ts +14 -0
- package/dist/preact/_dom.d.ts.map +1 -0
- package/dist/preact/_dom.js +31 -0
- package/dist/preact/_dom.js.map +1 -0
- package/dist/preact/_live-announcer.d.ts +26 -0
- package/dist/preact/_live-announcer.d.ts.map +1 -0
- package/dist/preact/_live-announcer.js +101 -0
- package/dist/preact/_live-announcer.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 +20 -0
- package/dist/preact/index.d.ts.map +1 -0
- package/dist/preact/index.js +20 -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 +144 -0
- package/dist/preact/knob.js.map +1 -0
- package/dist/preact/menu-button.d.ts +117 -0
- package/dist/preact/menu-button.d.ts.map +1 -0
- package/dist/preact/menu-button.js +330 -0
- package/dist/preact/menu-button.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/progress-ring.d.ts +42 -0
- package/dist/preact/progress-ring.d.ts.map +1 -0
- package/dist/preact/progress-ring.js +26 -0
- package/dist/preact/progress-ring.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 +164 -0
- package/dist/preact/slider.js.map +1 -0
- package/dist/preact/spin-button.d.ts +67 -0
- package/dist/preact/spin-button.d.ts.map +1 -0
- package/dist/preact/spin-button.js +132 -0
- package/dist/preact/spin-button.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/tabs.d.ts +97 -0
- package/dist/preact/tabs.d.ts.map +1 -0
- package/dist/preact/tabs.js +264 -0
- package/dist/preact/tabs.js.map +1 -0
- package/dist/preact/toaster.d.ts +43 -0
- package/dist/preact/toaster.d.ts.map +1 -0
- package/dist/preact/toaster.js +356 -0
- package/dist/preact/toaster.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 +142 -0
- package/dist/preact/toolbar.js.map +1 -0
- package/dist/preact/tooltip.d.ts +67 -0
- package/dist/preact/tooltip.d.ts.map +1 -0
- package/dist/preact/tooltip.js +165 -0
- package/dist/preact/tooltip.js.map +1 -0
- package/dist/preact/tree.d.ts +93 -0
- package/dist/preact/tree.d.ts.map +1 -0
- package/dist/preact/tree.js +399 -0
- package/dist/preact/tree.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/progress/progress.d.ts +51 -0
- package/dist/progress/progress.d.ts.map +1 -0
- package/dist/progress/progress.js +43 -0
- package/dist/progress/progress.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/spin-button/spin-button.d.ts +110 -0
- package/dist/spin-button/spin-button.d.ts.map +1 -0
- package/dist/spin-button/spin-button.js +179 -0
- package/dist/spin-button/spin-button.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/tabs/tabs.d.ts +157 -0
- package/dist/tabs/tabs.d.ts.map +1 -0
- package/dist/tabs/tabs.js +120 -0
- package/dist/tabs/tabs.js.map +1 -0
- package/dist/toast/toast-queue.d.ts +212 -0
- package/dist/toast/toast-queue.d.ts.map +1 -0
- package/dist/toast/toast-queue.js +290 -0
- package/dist/toast/toast-queue.js.map +1 -0
- package/dist/toast/toasts-obscure.d.ts +25 -0
- package/dist/toast/toasts-obscure.d.ts.map +1 -0
- package/dist/toast/toasts-obscure.js +30 -0
- package/dist/toast/toasts-obscure.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/dist/tooltip/tooltip.d.ts +183 -0
- package/dist/tooltip/tooltip.d.ts.map +1 -0
- package/dist/tooltip/tooltip.js +185 -0
- package/dist/tooltip/tooltip.js.map +1 -0
- package/dist/tree/tree.d.ts +302 -0
- package/dist/tree/tree.d.ts.map +1 -0
- package/dist/tree/tree.js +439 -0
- package/dist/tree/tree.js.map +1 -0
- package/package.json +110 -3
- package/styles.css +1883 -0
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { Component } from "preact";
|
|
3
|
+
import { useCallback, useLayoutEffect, useMemo, useRef, useState, } from "preact/hooks";
|
|
4
|
+
import { Typeahead } from "../focus/typeahead.js";
|
|
5
|
+
import { expandTreeSiblings, nextTreeSelection, treeAttributes, treeItemAttributes, treeKeyAction, treePath, treeTabStop, visibleTreeRows, } from "../tree/tree.js";
|
|
6
|
+
import { directionOf_, localesOf_ } from "./_dom.js";
|
|
7
|
+
import { joinClasses } from "./join-classes.js";
|
|
8
|
+
import { useLatest } from "./use-element-binding.js";
|
|
9
|
+
const ITEM_SELECTOR_ = '[role="treeitem"]';
|
|
10
|
+
const NO_SELECTION_ = new Set();
|
|
11
|
+
function chevron_() {
|
|
12
|
+
return (_jsx("svg", { viewBox: "0 0 16 16", focusable: "false", children: _jsx("path", { d: "M6 4l4 4-4 4" }) }));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* One row. A class for `shouldComponentUpdate`: a focus move draws again only
|
|
16
|
+
* the two rows whose tab stop or selection changed, not every row.
|
|
17
|
+
*/
|
|
18
|
+
class TreeItem_ extends Component {
|
|
19
|
+
shouldComponentUpdate(next) {
|
|
20
|
+
const current = this.props;
|
|
21
|
+
const { rows, index } = current;
|
|
22
|
+
return (next.node !== current.node ||
|
|
23
|
+
next.selectionMode !== current.selectionMode ||
|
|
24
|
+
next.isSelected !== current.isSelected ||
|
|
25
|
+
next.isTabStop !== current.isTabStop ||
|
|
26
|
+
next.isDisabled !== current.isDisabled ||
|
|
27
|
+
next.textValueOf !== current.textValueOf ||
|
|
28
|
+
next.renderItem !== current.renderItem ||
|
|
29
|
+
next.register !== current.register ||
|
|
30
|
+
next.rows.levelAt(next.index) !== rows.levelAt(index) ||
|
|
31
|
+
next.rows.positionAt(next.index) !== rows.positionAt(index) ||
|
|
32
|
+
next.rows.setSizeAt(next.index) !== rows.setSizeAt(index) ||
|
|
33
|
+
next.rows.isBranchAt(next.index) !== rows.isBranchAt(index) ||
|
|
34
|
+
next.rows.isExpandedAt(next.index) !== rows.isExpandedAt(index) ||
|
|
35
|
+
next.rows.isLoadingAt(next.index) !== rows.isLoadingAt(index));
|
|
36
|
+
}
|
|
37
|
+
render() {
|
|
38
|
+
const { rows, index, node, selectionMode, isSelected, isTabStop, isDisabled, textValueOf, renderItem, register, } = this.props;
|
|
39
|
+
const level = rows.levelAt(index);
|
|
40
|
+
const isBranch = rows.isBranchAt(index);
|
|
41
|
+
const state = {
|
|
42
|
+
level,
|
|
43
|
+
isBranch,
|
|
44
|
+
isExpanded: rows.isExpandedAt(index),
|
|
45
|
+
isSelected,
|
|
46
|
+
isDisabled,
|
|
47
|
+
isLoading: rows.isLoadingAt(index),
|
|
48
|
+
};
|
|
49
|
+
return (_jsxs("li", { ...treeItemAttributes({
|
|
50
|
+
rows,
|
|
51
|
+
index,
|
|
52
|
+
selectionMode,
|
|
53
|
+
isSelected,
|
|
54
|
+
isTabStop,
|
|
55
|
+
isDisabled,
|
|
56
|
+
}), ref: (element) => {
|
|
57
|
+
register(element, node);
|
|
58
|
+
}, class: "ack-tree-item", "data-selected": isSelected ? "" : undefined, style: { "--ack-tree-level": level }, children: [_jsx("span", { class: "ack-tree-item-toggle", "aria-hidden": "true", "data-loading": state.isLoading ? "" : undefined, children: isBranch && chevron_() }), _jsx("span", { class: "ack-tree-item-content", children: renderItem === undefined
|
|
59
|
+
? textValueOf(node)
|
|
60
|
+
: renderItem(node, state) })] }));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A hierarchy of nodes to browse, expand and select (WAI-ARIA tree view
|
|
65
|
+
* pattern), such as a file tree or the elements of a document. One tab stop, on
|
|
66
|
+
* the focused node (at first the first selected node, else the first); Arrow
|
|
67
|
+
* Down and Up move through the shown rows, Home and End to the ends; Arrow
|
|
68
|
+
* Right expands a branch, then moves to its first child; Arrow Left collapses
|
|
69
|
+
* it, or moves to the parent; `*` expands every branch beside the focused one;
|
|
70
|
+
* typing a name moves to it; Enter activates a node, or expands or collapses a
|
|
71
|
+
* branch with no action. Right to left, Arrow Right and Left swap.
|
|
72
|
+
*
|
|
73
|
+
* In single selection, Space or a click selects a node; with
|
|
74
|
+
* `selectionFollowsFocus`, moving focus does. In multiple selection, Space or
|
|
75
|
+
* Ctrl (Cmd) click flips a node, Shift Arrow Down and Up move and flip, Shift
|
|
76
|
+
* Space and Shift click select from the last node selected, Ctrl (Cmd) Shift
|
|
77
|
+
* Home and End to the first and last row, Ctrl (Cmd) A selects every node or
|
|
78
|
+
* none. A click on the expand mark, or a double click on a branch, expands or
|
|
79
|
+
* collapses it. Disabled nodes take focus and expand, but are never selected or
|
|
80
|
+
* activated.
|
|
81
|
+
*
|
|
82
|
+
* The rows are one flat list stating each item's level, position and set size,
|
|
83
|
+
* so a branch's children load lazily: an expanded branch whose children are
|
|
84
|
+
* `undefined` shows as busy until they come. When the focused row goes away
|
|
85
|
+
* (its branch collapsed, its node removed), focus moves to the nearest row
|
|
86
|
+
* still shown. Expansion and selection are the caller's.
|
|
87
|
+
*/
|
|
88
|
+
export function Tree(props) {
|
|
89
|
+
const { roots, childrenOf, isBranch, textValueOf, renderItem, expanded, onExpandedChange, selectionMode = "single", selected = NO_SELECTION_, onSelectedChange, selectionFollowsFocus = false, onActivate, isDisabled, id, } = props;
|
|
90
|
+
const nameInput = props.label === undefined
|
|
91
|
+
? { labelledBy: props.labelledBy }
|
|
92
|
+
: { label: props.label };
|
|
93
|
+
const source = useMemo(() => ({ roots, childrenOf, isBranch }), [roots, childrenOf, isBranch]);
|
|
94
|
+
const rows = useMemo(() => visibleTreeRows(source, (node) => expanded.has(node)), [source, expanded]);
|
|
95
|
+
const [focusedPath, setFocusedPath] = useState([]);
|
|
96
|
+
const tabStop = treeTabStop(rows, focusedPath, selected);
|
|
97
|
+
const tree = useRef(null);
|
|
98
|
+
const nodes = useRef(new WeakMap());
|
|
99
|
+
const typeahead = useRef(new Typeahead());
|
|
100
|
+
const anchor = useRef(undefined);
|
|
101
|
+
const labels = useRef(undefined);
|
|
102
|
+
// The row focus was last on, until focus leaves the tree for another place.
|
|
103
|
+
const focusedRow = useRef(null);
|
|
104
|
+
// What was last reported, until the next render brings the caller's answer:
|
|
105
|
+
// two changes in one event build on each other.
|
|
106
|
+
const reportedSelection = useRef(undefined);
|
|
107
|
+
reportedSelection.current = undefined;
|
|
108
|
+
const latest = useLatest({
|
|
109
|
+
rows,
|
|
110
|
+
source,
|
|
111
|
+
expanded,
|
|
112
|
+
selected,
|
|
113
|
+
selectionMode,
|
|
114
|
+
selectionFollowsFocus,
|
|
115
|
+
isDisabled,
|
|
116
|
+
onExpandedChange,
|
|
117
|
+
onSelectedChange,
|
|
118
|
+
onActivate,
|
|
119
|
+
focusedPath,
|
|
120
|
+
});
|
|
121
|
+
const register = useCallback((element, node) => {
|
|
122
|
+
if (element !== null) {
|
|
123
|
+
nodes.current.set(element, node);
|
|
124
|
+
}
|
|
125
|
+
}, []);
|
|
126
|
+
// Focus on a row that went away moves to the tab stop, the nearest row left.
|
|
127
|
+
useLayoutEffect(() => {
|
|
128
|
+
const element = tree.current;
|
|
129
|
+
const row = focusedRow.current;
|
|
130
|
+
if (element === null || row === null || row.isConnected) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const active = document.activeElement;
|
|
134
|
+
if (active !== null && active !== document.body) {
|
|
135
|
+
focusedRow.current = null;
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const stop = element.children[tabStop];
|
|
139
|
+
if (stop instanceof HTMLElement) {
|
|
140
|
+
stop.focus({ preventScroll: true });
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
focusedRow.current = null;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
const rowElementAt = (index) => {
|
|
147
|
+
const row = tree.current?.children[index];
|
|
148
|
+
return row instanceof HTMLElement ? row : undefined;
|
|
149
|
+
};
|
|
150
|
+
const isNodeDisabled = (node) => latest.current.isDisabled?.(node) === true;
|
|
151
|
+
const changeSelection = (change) => {
|
|
152
|
+
const current = latest.current;
|
|
153
|
+
if (current.selectionMode === "none") {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const base = reportedSelection.current ?? current.selected;
|
|
157
|
+
const next = nextTreeSelection(base, change, {
|
|
158
|
+
source: current.source,
|
|
159
|
+
rows: current.rows,
|
|
160
|
+
isDisabled: current.isDisabled,
|
|
161
|
+
});
|
|
162
|
+
if (next !== base) {
|
|
163
|
+
reportedSelection.current = next;
|
|
164
|
+
current.onSelectedChange?.(next);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const setExpanded = (node, isExpanded) => {
|
|
168
|
+
const current = latest.current.expanded;
|
|
169
|
+
if (current.has(node) === isExpanded) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const next = new Set(current);
|
|
173
|
+
if (isExpanded) {
|
|
174
|
+
next.add(node);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
next.delete(node);
|
|
178
|
+
}
|
|
179
|
+
latest.current.onExpandedChange(next);
|
|
180
|
+
};
|
|
181
|
+
const rowOf = (target) => {
|
|
182
|
+
const row = target instanceof Element
|
|
183
|
+
? target.closest(ITEM_SELECTOR_)
|
|
184
|
+
: null;
|
|
185
|
+
return row !== null && row.parentElement === tree.current ? row : null;
|
|
186
|
+
};
|
|
187
|
+
const indexOfRow = (row) => {
|
|
188
|
+
const node = nodes.current.get(row);
|
|
189
|
+
return node === undefined ? -1 : latest.current.rows.indexOf(node);
|
|
190
|
+
};
|
|
191
|
+
const activate = (index) => {
|
|
192
|
+
const { rows: currentRows, onActivate: action } = latest.current;
|
|
193
|
+
const node = currentRows.nodeAt(index);
|
|
194
|
+
if (action !== undefined) {
|
|
195
|
+
if (!isNodeDisabled(node)) {
|
|
196
|
+
action(node);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else if (currentRows.isBranchAt(index)) {
|
|
200
|
+
setExpanded(node, !currentRows.isExpandedAt(index));
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
return (_jsx("ul", { ...treeAttributes({ ...nameInput, selectionMode }), id: id, ref: tree, class: joinClasses("ack-control ack-tree", props.class), onFocusIn: (event) => {
|
|
204
|
+
const row = rowOf(event.target);
|
|
205
|
+
if (row === null) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
focusedRow.current = row;
|
|
209
|
+
const index = indexOfRow(row);
|
|
210
|
+
if (index === -1) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const current = latest.current;
|
|
214
|
+
const node = current.rows.nodeAt(index);
|
|
215
|
+
if (current.focusedPath.at(-1) !== node) {
|
|
216
|
+
setFocusedPath(treePath(current.rows, index));
|
|
217
|
+
}
|
|
218
|
+
if (current.selectionFollowsFocus &&
|
|
219
|
+
current.selectionMode === "single") {
|
|
220
|
+
changeSelection({ kind: "replace", index });
|
|
221
|
+
}
|
|
222
|
+
}, onFocusOut: (event) => {
|
|
223
|
+
const row = rowOf(event.target);
|
|
224
|
+
const next = event.relatedTarget;
|
|
225
|
+
if (row === null ||
|
|
226
|
+
(next instanceof Node && tree.current?.contains(next) === true)) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
// A row removed while focused may report its blur before it is
|
|
230
|
+
// detached (Chromium): decide once the removal is done, keeping a
|
|
231
|
+
// removed row so its focus is restored.
|
|
232
|
+
queueMicrotask(() => {
|
|
233
|
+
if (focusedRow.current === row && row.isConnected) {
|
|
234
|
+
focusedRow.current = null;
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}, onKeyDown: (event) => {
|
|
238
|
+
const row = rowOf(event.target);
|
|
239
|
+
if (row === null) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const current = indexOfRow(row);
|
|
243
|
+
if (current === -1) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const state = latest.current;
|
|
247
|
+
const action = treeKeyAction({
|
|
248
|
+
key: event.key,
|
|
249
|
+
shiftKey: event.shiftKey,
|
|
250
|
+
ctrlKey: event.ctrlKey,
|
|
251
|
+
altKey: event.altKey,
|
|
252
|
+
metaKey: event.metaKey,
|
|
253
|
+
current,
|
|
254
|
+
rows: state.rows,
|
|
255
|
+
direction: directionOf_(event.currentTarget),
|
|
256
|
+
selectionMode: state.selectionMode,
|
|
257
|
+
isTypingAhead: typeahead.current.isActive(event.timeStamp),
|
|
258
|
+
});
|
|
259
|
+
if (action === undefined) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
event.preventDefault();
|
|
263
|
+
switch (action.kind) {
|
|
264
|
+
case "focus":
|
|
265
|
+
rowElementAt(action.index)?.focus();
|
|
266
|
+
if (action.toggles) {
|
|
267
|
+
anchor.current = state.rows.nodeAt(action.index);
|
|
268
|
+
changeSelection({ kind: "toggle", index: action.index });
|
|
269
|
+
}
|
|
270
|
+
break;
|
|
271
|
+
case "expand":
|
|
272
|
+
setExpanded(state.rows.nodeAt(action.index), true);
|
|
273
|
+
break;
|
|
274
|
+
case "collapse":
|
|
275
|
+
setExpanded(state.rows.nodeAt(action.index), false);
|
|
276
|
+
break;
|
|
277
|
+
case "expandSiblings": {
|
|
278
|
+
const next = expandTreeSiblings(state.source, state.rows, action.index, state.expanded);
|
|
279
|
+
if (next !== state.expanded) {
|
|
280
|
+
state.onExpandedChange(next);
|
|
281
|
+
}
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
case "activate":
|
|
285
|
+
activate(action.index);
|
|
286
|
+
break;
|
|
287
|
+
case "select":
|
|
288
|
+
anchor.current = state.rows.nodeAt(action.index);
|
|
289
|
+
changeSelection({
|
|
290
|
+
kind: state.selectionMode === "multiple" ? "toggle" : "replace",
|
|
291
|
+
index: action.index,
|
|
292
|
+
});
|
|
293
|
+
break;
|
|
294
|
+
case "selectRange": {
|
|
295
|
+
const anchorIndex = anchor.current === undefined
|
|
296
|
+
? -1
|
|
297
|
+
: state.rows.indexOf(anchor.current);
|
|
298
|
+
const from = action.from === "anchor"
|
|
299
|
+
? anchorIndex === -1
|
|
300
|
+
? current
|
|
301
|
+
: anchorIndex
|
|
302
|
+
: action.from;
|
|
303
|
+
changeSelection({
|
|
304
|
+
kind: "range",
|
|
305
|
+
from,
|
|
306
|
+
to: action.to,
|
|
307
|
+
isAdded: true,
|
|
308
|
+
});
|
|
309
|
+
rowElementAt(action.focus)?.focus();
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
case "selectAll":
|
|
313
|
+
changeSelection({ kind: "all" });
|
|
314
|
+
break;
|
|
315
|
+
case "typeahead": {
|
|
316
|
+
let cached = labels.current;
|
|
317
|
+
if (cached?.rows !== state.rows ||
|
|
318
|
+
cached.textValueOf !== textValueOf) {
|
|
319
|
+
const all = [];
|
|
320
|
+
for (let index = 0; index < state.rows.count; index += 1) {
|
|
321
|
+
all.push(textValueOf(state.rows.nodeAt(index)));
|
|
322
|
+
}
|
|
323
|
+
cached = { rows: state.rows, textValueOf, labels: all };
|
|
324
|
+
labels.current = cached;
|
|
325
|
+
}
|
|
326
|
+
const next = typeahead.current.find(action.character, event.timeStamp, cached.labels, current, { locales: localesOf_(event.currentTarget) });
|
|
327
|
+
if (next !== undefined) {
|
|
328
|
+
rowElementAt(next)?.focus();
|
|
329
|
+
}
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}, onClick: (event) => {
|
|
334
|
+
const row = rowOf(event.target);
|
|
335
|
+
if (row === null) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const index = indexOfRow(row);
|
|
339
|
+
if (index === -1) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
const state = latest.current;
|
|
343
|
+
if (document.activeElement !== row) {
|
|
344
|
+
row.focus({ preventScroll: true });
|
|
345
|
+
}
|
|
346
|
+
const isToggle = event.target instanceof Element &&
|
|
347
|
+
event.target.closest(".ack-tree-item-toggle") !== null;
|
|
348
|
+
if (isToggle) {
|
|
349
|
+
if (state.rows.isBranchAt(index)) {
|
|
350
|
+
setExpanded(state.rows.nodeAt(index), !state.rows.isExpandedAt(index));
|
|
351
|
+
}
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
const node = state.rows.nodeAt(index);
|
|
355
|
+
const command = event.ctrlKey || event.metaKey;
|
|
356
|
+
if (state.selectionMode === "multiple" && (command || event.shiftKey)) {
|
|
357
|
+
if (event.shiftKey) {
|
|
358
|
+
const anchorIndex = anchor.current === undefined
|
|
359
|
+
? -1
|
|
360
|
+
: state.rows.indexOf(anchor.current);
|
|
361
|
+
changeSelection({
|
|
362
|
+
kind: "range",
|
|
363
|
+
from: anchorIndex === -1 ? index : anchorIndex,
|
|
364
|
+
to: index,
|
|
365
|
+
isAdded: command,
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
anchor.current = node;
|
|
370
|
+
changeSelection({ kind: "toggle", index });
|
|
371
|
+
}
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
anchor.current = node;
|
|
375
|
+
changeSelection({ kind: "replace", index });
|
|
376
|
+
if (!event.altKey && !event.shiftKey && !command) {
|
|
377
|
+
const action = state.onActivate;
|
|
378
|
+
if (action !== undefined && !isNodeDisabled(node)) {
|
|
379
|
+
action(node);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}, onDblClick: (event) => {
|
|
383
|
+
const row = rowOf(event.target);
|
|
384
|
+
if (row === null ||
|
|
385
|
+
(event.target instanceof Element &&
|
|
386
|
+
event.target.closest(".ack-tree-item-toggle") !== null)) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
const index = indexOfRow(row);
|
|
390
|
+
const state = latest.current;
|
|
391
|
+
if (index !== -1 && state.rows.isBranchAt(index)) {
|
|
392
|
+
setExpanded(state.rows.nodeAt(index), !state.rows.isExpandedAt(index));
|
|
393
|
+
}
|
|
394
|
+
}, children: Array.from({ length: rows.count }, (_unused, index) => {
|
|
395
|
+
const node = rows.nodeAt(index);
|
|
396
|
+
return (_jsx(TreeItem_, { rows: rows, index: index, node: node, selectionMode: selectionMode, isSelected: selected.has(node), isTabStop: index === tabStop, isDisabled: isDisabled?.(node) === true, textValueOf: textValueOf, renderItem: renderItem, register: register }, node));
|
|
397
|
+
}) }));
|
|
398
|
+
}
|
|
399
|
+
//# sourceMappingURL=tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../../src/preact/tree.tsx"],"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AI,EACV,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAC9B,SAAS,EAAE,KAAK,KAAK,OAAO,EAC5B,UAAU,EAAE,UAAU,EAAE,CAAC,IAAI,CAAC,KAAK,IAAI,EACvC,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,QAAQ,IAVb,IAAI,CAWR,CACF,CAAC;QACH,CAAC,CAAC,GACE,CACL,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"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useCallback, useLayoutEffect, useRef, useState } from "preact/hooks";
|
|
2
|
+
/**
|
|
3
|
+
* Runs `bind` on an element once it is mounted, and again when `deps` change or
|
|
4
|
+
* the element is replaced; before each re-run and at unmount it aborts the
|
|
5
|
+
* signal it passed and disposes what `bind` returned. For `ui-gesture/dom`
|
|
6
|
+
* bindings in this package's components, `ui-music`'s and the caller's.
|
|
7
|
+
*
|
|
8
|
+
* Returns the callback ref to put on the element, which is how the hook sees an
|
|
9
|
+
* element mounted late or swapped for another with the dependencies unchanged.
|
|
10
|
+
* The binding is made in the render that follows the element's mount, so a
|
|
11
|
+
* `touch-action` it sets comes right after the first paint; the stylesheet sets
|
|
12
|
+
* the same ones for the first press.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const root = useElementBinding<HTMLDivElement>(
|
|
16
|
+
* (element, signal) => bindPointers(element, handlers, { signal }),
|
|
17
|
+
* [],
|
|
18
|
+
* );
|
|
19
|
+
* return <div ref={root} />;
|
|
20
|
+
*/
|
|
21
|
+
export function useElementBinding(bind, deps) {
|
|
22
|
+
const [element, setElement] = useState(null);
|
|
23
|
+
const attach = useCallback((node) => {
|
|
24
|
+
setElement(node);
|
|
25
|
+
}, []);
|
|
26
|
+
const latestBind = useRef(bind);
|
|
27
|
+
latestBind.current = bind;
|
|
28
|
+
useLayoutEffect(() => {
|
|
29
|
+
if (element === null) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const controller = new AbortController();
|
|
33
|
+
const binding = latestBind.current(element, controller.signal);
|
|
34
|
+
return () => {
|
|
35
|
+
controller.abort();
|
|
36
|
+
binding?.[Symbol.dispose]();
|
|
37
|
+
};
|
|
38
|
+
}, [element, ...deps]);
|
|
39
|
+
return attach;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A ref whose `current` is always the latest `value`, for handlers a binding
|
|
43
|
+
* reads at each call. It is written during render, so a handler that runs
|
|
44
|
+
* between a render and its commit sees the newer value.
|
|
45
|
+
*/
|
|
46
|
+
export function useLatest(value) {
|
|
47
|
+
const ref = useRef(value);
|
|
48
|
+
ref.current = value;
|
|
49
|
+
return ref;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=use-element-binding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-element-binding.js","sourceRoot":"","sources":["../../src/preact/use-element-binding.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE9E;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,iBAAiB,CAChC,IAGC,EACD,IAA4B;IAE5B,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAG,WAAW,CAAC,CAAC,IAAmB,EAAE,EAAE;QAClD,UAAU,CAAC,IAAI,CAAC,CAAC;IAClB,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAChC,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;IAC1B,eAAe,CAAC,GAAG,EAAE;QACpB,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACtB,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;QAE/D,OAAO,GAAG,EAAE;YACX,UAAU,CAAC,KAAK,EAAE,CAAC;YACnB,OAAO,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;IAEvB,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAQ,KAAY;IAC5C,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1B,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;IAEpB,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ARIA attributes of a progress indicator (WAI-ARIA `progressbar` role).
|
|
3
|
+
* `aria-valuenow` is absent while the progress is indeterminate.
|
|
4
|
+
*/
|
|
5
|
+
export type ProgressAttributes = {
|
|
6
|
+
role: "progressbar";
|
|
7
|
+
"aria-label"?: string;
|
|
8
|
+
"aria-valuemin": number;
|
|
9
|
+
"aria-valuemax": number;
|
|
10
|
+
"aria-valuenow"?: number;
|
|
11
|
+
"aria-valuetext"?: string;
|
|
12
|
+
};
|
|
13
|
+
/** Input of {@link progressAttributes}. */
|
|
14
|
+
export type ProgressAttributesInput = {
|
|
15
|
+
/** Its accessible name; omit when another element names it. */
|
|
16
|
+
label?: string;
|
|
17
|
+
/**
|
|
18
|
+
* How far the task has gone, clamped to [min, max] for `aria-valuenow`; `NaN`
|
|
19
|
+
* reads as `min`. `undefined` while it cannot be told (indeterminate).
|
|
20
|
+
*/
|
|
21
|
+
value: number | undefined;
|
|
22
|
+
/** Defaults to 0. */
|
|
23
|
+
min?: number;
|
|
24
|
+
/** Defaults to 100. */
|
|
25
|
+
max?: number;
|
|
26
|
+
/**
|
|
27
|
+
* What a person reads: `"3 of 12 files"`. Omit to have the percentage read;
|
|
28
|
+
* while indeterminate, a word such as `"Loading"` may be given.
|
|
29
|
+
*/
|
|
30
|
+
valueText?: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The attributes of a progress indicator: the `progressbar` role with its
|
|
34
|
+
* range, its value kept inside the range or absent while indeterminate, and an
|
|
35
|
+
* optional text for what a person reads.
|
|
36
|
+
*
|
|
37
|
+
* Time complexity: O(1). Memory: O(1).
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* progressAttributes({ label: "Upload", value: 40 });
|
|
41
|
+
* // { role: "progressbar", "aria-label": "Upload", "aria-valuemin": 0,
|
|
42
|
+
* // "aria-valuemax": 100, "aria-valuenow": 40 }
|
|
43
|
+
* progressAttributes({ label: "Upload", value: undefined });
|
|
44
|
+
* // { role: "progressbar", "aria-label": "Upload", "aria-valuemin": 0,
|
|
45
|
+
* // "aria-valuemax": 100 }
|
|
46
|
+
*
|
|
47
|
+
* @throws {RangeError} When `min` or `max` is not finite, or `max` is not above
|
|
48
|
+
* `min`.
|
|
49
|
+
*/
|
|
50
|
+
export declare function progressAttributes(input: ProgressAttributesInput): ProgressAttributes;
|
|
51
|
+
//# sourceMappingURL=progress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../src/progress/progress.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAChC,IAAI,EAAE,aAAa,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,2CAA2C;AAC3C,MAAM,MAAM,uBAAuB,GAAG;IACrC,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,qBAAqB;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,uBAAuB;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,uBAAuB,GAC5B,kBAAkB,CAyBpB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { clamp, describeValue } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* The attributes of a progress indicator: the `progressbar` role with its
|
|
4
|
+
* range, its value kept inside the range or absent while indeterminate, and an
|
|
5
|
+
* optional text for what a person reads.
|
|
6
|
+
*
|
|
7
|
+
* Time complexity: O(1). Memory: O(1).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* progressAttributes({ label: "Upload", value: 40 });
|
|
11
|
+
* // { role: "progressbar", "aria-label": "Upload", "aria-valuemin": 0,
|
|
12
|
+
* // "aria-valuemax": 100, "aria-valuenow": 40 }
|
|
13
|
+
* progressAttributes({ label: "Upload", value: undefined });
|
|
14
|
+
* // { role: "progressbar", "aria-label": "Upload", "aria-valuemin": 0,
|
|
15
|
+
* // "aria-valuemax": 100 }
|
|
16
|
+
*
|
|
17
|
+
* @throws {RangeError} When `min` or `max` is not finite, or `max` is not above
|
|
18
|
+
* `min`.
|
|
19
|
+
*/
|
|
20
|
+
export function progressAttributes(input) {
|
|
21
|
+
const { label, value, min = 0, max = 100, valueText } = input;
|
|
22
|
+
if (!(Number.isFinite(min) && Number.isFinite(max) && max > min)) {
|
|
23
|
+
throw new RangeError(`A progress indicator's bounds must be finite with max above min, got min ${describeValue(min)} and max ${describeValue(max)}.`);
|
|
24
|
+
}
|
|
25
|
+
const attributes = {
|
|
26
|
+
role: "progressbar",
|
|
27
|
+
"aria-valuemin": min,
|
|
28
|
+
"aria-valuemax": max,
|
|
29
|
+
};
|
|
30
|
+
if (label !== undefined) {
|
|
31
|
+
attributes["aria-label"] = label;
|
|
32
|
+
}
|
|
33
|
+
if (value !== undefined) {
|
|
34
|
+
attributes["aria-valuenow"] = Number.isNaN(value)
|
|
35
|
+
? min
|
|
36
|
+
: clamp(value, min, max);
|
|
37
|
+
}
|
|
38
|
+
if (valueText !== undefined) {
|
|
39
|
+
attributes["aria-valuetext"] = valueText;
|
|
40
|
+
}
|
|
41
|
+
return attributes;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=progress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress.js","sourceRoot":"","sources":["../../src/progress/progress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAmCpD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,kBAAkB,CACjC,KAA8B;IAE9B,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IAC9D,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,GAAG,CAAC,EAAE,CAAC;QAClE,MAAM,IAAI,UAAU,CACnB,4EAA4E,aAAa,CAAC,GAAG,CAAC,YAAY,aAAa,CAAC,GAAG,CAAC,GAAG,CAC/H,CAAC;IACH,CAAC;IACD,MAAM,UAAU,GAAuB;QACtC,IAAI,EAAE,aAAa;QACnB,eAAe,EAAE,GAAG;QACpB,eAAe,EAAE,GAAG;KACpB,CAAC;IACF,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,UAAU,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC;IAClC,CAAC;IACD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,UAAU,CAAC,eAAe,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC;YAChD,CAAC,CAAC,GAAG;YACL,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAC3B,CAAC;IACD,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC7B,UAAU,CAAC,gBAAgB,CAAC,GAAG,SAAS,CAAC;IAC1C,CAAC;IAED,OAAO,UAAU,CAAC;AACnB,CAAC"}
|