@ac-kit/ui-common 0.1.0 → 0.3.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 +210 -0
- package/README.md +383 -9
- package/dist/adapter/_anchor.d.ts +13 -0
- package/dist/adapter/_anchor.d.ts.map +1 -0
- package/dist/adapter/_anchor.js +39 -0
- package/dist/adapter/_anchor.js.map +1 -0
- package/dist/adapter/_dom.d.ts +14 -0
- package/dist/adapter/_dom.d.ts.map +1 -0
- package/dist/adapter/_dom.js +31 -0
- package/dist/adapter/_dom.js.map +1 -0
- package/dist/adapter/_live-announcer.d.ts +26 -0
- package/dist/adapter/_live-announcer.d.ts.map +1 -0
- package/dist/adapter/_live-announcer.js +101 -0
- package/dist/adapter/_live-announcer.js.map +1 -0
- package/dist/adapter/join-classes.d.ts.map +1 -0
- package/dist/adapter/join-classes.js.map +1 -0
- 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/bit-grid/bit-grid.d.ts +151 -0
- package/dist/bit-grid/bit-grid.d.ts.map +1 -0
- package/dist/bit-grid/bit-grid.js +201 -0
- package/dist/bit-grid/bit-grid.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 +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -1
- 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/preact/bit-grid.d.ts +39 -0
- package/dist/preact/bit-grid.d.ts.map +1 -0
- package/dist/preact/bit-grid.js +72 -0
- package/dist/preact/bit-grid.js.map +1 -0
- package/dist/preact/button.d.ts.map +1 -1
- package/dist/preact/button.js +1 -1
- package/dist/preact/button.js.map +1 -1
- package/dist/preact/dialog.d.ts.map +1 -1
- package/dist/preact/dialog.js +1 -1
- package/dist/preact/dialog.js.map +1 -1
- package/dist/preact/index.d.ts +10 -1
- package/dist/preact/index.d.ts.map +1 -1
- package/dist/preact/index.js +10 -1
- package/dist/preact/index.js.map +1 -1
- package/dist/preact/knob.d.ts.map +1 -1
- package/dist/preact/knob.js +6 -14
- package/dist/preact/knob.js.map +1 -1
- 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.map +1 -1
- package/dist/preact/meter.js +1 -1
- package/dist/preact/meter.js.map +1 -1
- 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.map +1 -1
- package/dist/preact/radio-group.js +1 -1
- package/dist/preact/radio-group.js.map +1 -1
- package/dist/preact/readout.d.ts.map +1 -1
- package/dist/preact/readout.js +1 -1
- package/dist/preact/readout.js.map +1 -1
- package/dist/preact/slider.d.ts.map +1 -1
- package/dist/preact/slider.js +7 -5
- package/dist/preact/slider.js.map +1 -1
- 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/swatch-strip.d.ts +30 -0
- package/dist/preact/swatch-strip.d.ts.map +1 -0
- package/dist/preact/swatch-strip.js +17 -0
- package/dist/preact/swatch-strip.js.map +1 -0
- package/dist/preact/switch.js +1 -1
- package/dist/preact/switch.js.map +1 -1
- 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.map +1 -1
- package/dist/preact/toggle-button.js +1 -1
- package/dist/preact/toggle-button.js.map +1 -1
- package/dist/preact/toolbar.d.ts.map +1 -1
- package/dist/preact/toolbar.js +3 -9
- package/dist/preact/toolbar.js.map +1 -1
- 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/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/react/_props.d.ts +22 -0
- package/dist/react/_props.d.ts.map +1 -0
- package/dist/react/_props.js +14 -0
- package/dist/react/_props.js.map +1 -0
- package/dist/react/bit-grid.d.ts +40 -0
- package/dist/react/bit-grid.d.ts.map +1 -0
- package/dist/react/bit-grid.js +71 -0
- package/dist/react/bit-grid.js.map +1 -0
- package/dist/react/button.d.ts +60 -0
- package/dist/react/button.d.ts.map +1 -0
- package/dist/react/button.js +34 -0
- package/dist/react/button.js.map +1 -0
- package/dist/react/dialog.d.ts +44 -0
- package/dist/react/dialog.d.ts.map +1 -0
- package/dist/react/dialog.js +91 -0
- package/dist/react/dialog.js.map +1 -0
- package/dist/react/index.d.ts +22 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +22 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/knob.d.ts +55 -0
- package/dist/react/knob.d.ts.map +1 -0
- package/dist/react/knob.js +144 -0
- package/dist/react/knob.js.map +1 -0
- package/dist/react/menu-button.d.ts +147 -0
- package/dist/react/menu-button.d.ts.map +1 -0
- package/dist/react/menu-button.js +342 -0
- package/dist/react/menu-button.js.map +1 -0
- package/dist/react/meter.d.ts +34 -0
- package/dist/react/meter.d.ts.map +1 -0
- package/dist/react/meter.js +23 -0
- package/dist/react/meter.js.map +1 -0
- package/dist/react/progress-ring.d.ts +42 -0
- package/dist/react/progress-ring.d.ts.map +1 -0
- package/dist/react/progress-ring.js +28 -0
- package/dist/react/progress-ring.js.map +1 -0
- package/dist/react/radio-group.d.ts +52 -0
- package/dist/react/radio-group.d.ts.map +1 -0
- package/dist/react/radio-group.js +30 -0
- package/dist/react/radio-group.js.map +1 -0
- package/dist/react/readout.d.ts +23 -0
- package/dist/react/readout.d.ts.map +1 -0
- package/dist/react/readout.js +13 -0
- package/dist/react/readout.js.map +1 -0
- package/dist/react/slider.d.ts +44 -0
- package/dist/react/slider.d.ts.map +1 -0
- package/dist/react/slider.js +167 -0
- package/dist/react/slider.js.map +1 -0
- package/dist/react/spin-button.d.ts +71 -0
- package/dist/react/spin-button.d.ts.map +1 -0
- package/dist/react/spin-button.js +132 -0
- package/dist/react/spin-button.js.map +1 -0
- package/dist/react/swatch-strip.d.ts +31 -0
- package/dist/react/swatch-strip.d.ts.map +1 -0
- package/dist/react/swatch-strip.js +17 -0
- package/dist/react/swatch-strip.js.map +1 -0
- package/dist/react/switch.d.ts +26 -0
- package/dist/react/switch.d.ts.map +1 -0
- package/dist/react/switch.js +19 -0
- package/dist/react/switch.js.map +1 -0
- package/dist/react/tabs.d.ts +95 -0
- package/dist/react/tabs.d.ts.map +1 -0
- package/dist/react/tabs.js +274 -0
- package/dist/react/tabs.js.map +1 -0
- package/dist/react/toaster.d.ts +43 -0
- package/dist/react/toaster.d.ts.map +1 -0
- package/dist/react/toaster.js +368 -0
- package/dist/react/toaster.js.map +1 -0
- package/dist/react/toggle-button.d.ts +37 -0
- package/dist/react/toggle-button.d.ts.map +1 -0
- package/dist/react/toggle-button.js +22 -0
- package/dist/react/toggle-button.js.map +1 -0
- package/dist/react/toolbar.d.ts +25 -0
- package/dist/react/toolbar.d.ts.map +1 -0
- package/dist/react/toolbar.js +143 -0
- package/dist/react/toolbar.js.map +1 -0
- package/dist/react/tooltip.d.ts +68 -0
- package/dist/react/tooltip.d.ts.map +1 -0
- package/dist/react/tooltip.js +165 -0
- package/dist/react/tooltip.js.map +1 -0
- package/dist/react/tree.d.ts +94 -0
- package/dist/react/tree.d.ts.map +1 -0
- package/dist/react/tree.js +422 -0
- package/dist/react/tree.js.map +1 -0
- package/dist/react/use-element-binding.d.ts +35 -0
- package/dist/react/use-element-binding.d.ts.map +1 -0
- package/dist/react/use-element-binding.js +51 -0
- package/dist/react/use-element-binding.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/swatch-strip/swatch-strip.d.ts +60 -0
- package/dist/swatch-strip/swatch-strip.d.ts.map +1 -0
- package/dist/swatch-strip/swatch-strip.js +60 -0
- package/dist/swatch-strip/swatch-strip.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/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 +47 -14
- package/styles.css +1084 -3
- package/dist/preact/join-classes.d.ts.map +0 -1
- package/dist/preact/join-classes.js.map +0 -1
- /package/dist/{preact → adapter}/join-classes.d.ts +0 -0
- /package/dist/{preact → adapter}/join-classes.js +0 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { type CallableNoArgs } from "@ac-kit/core";
|
|
2
|
+
import type { AnchoredAlign, AnchoredAttributes, AnchoredSide } from "../anchored/anchored.js";
|
|
3
|
+
/** The attributes of a tooltip, keyed by their HTML attribute names. */
|
|
4
|
+
export type TooltipAttributes = AnchoredAttributes & {
|
|
5
|
+
role: "tooltip";
|
|
6
|
+
};
|
|
7
|
+
/** Input of {@link tooltipAttributes}. */
|
|
8
|
+
export type TooltipAttributesInput = {
|
|
9
|
+
/** Defaults to `block-start`: above the trigger. */
|
|
10
|
+
side?: AnchoredSide;
|
|
11
|
+
/** Defaults to `center`. */
|
|
12
|
+
align?: AnchoredAlign;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The attributes of a tooltip (WAI-ARIA tooltip pattern): the `tooltip` role,
|
|
16
|
+
* and where the stylesheet places it against its trigger.
|
|
17
|
+
*
|
|
18
|
+
* Time complexity: O(1). Memory: O(1).
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* tooltipAttributes(); // { role: "tooltip", "data-side": "block-start", "data-align": "center" }
|
|
22
|
+
*/
|
|
23
|
+
export declare function tooltipAttributes(input?: TooltipAttributesInput): TooltipAttributes;
|
|
24
|
+
/**
|
|
25
|
+
* What a tooltip is to its trigger: a `description` read after the trigger's
|
|
26
|
+
* name (the default), or its `label`, the name itself, for a control drawn as
|
|
27
|
+
* an icon alone.
|
|
28
|
+
*/
|
|
29
|
+
export type TooltipRelation = "description" | "label";
|
|
30
|
+
/**
|
|
31
|
+
* The attributes a tooltip's trigger takes, keyed by their HTML attribute
|
|
32
|
+
* names.
|
|
33
|
+
*/
|
|
34
|
+
export type TooltipTriggerAttributes = {
|
|
35
|
+
"aria-describedby": string;
|
|
36
|
+
} | {
|
|
37
|
+
"aria-labelledby": string;
|
|
38
|
+
};
|
|
39
|
+
/** Input of {@link tooltipTriggerAttributes}. */
|
|
40
|
+
export type TooltipTriggerAttributesInput = {
|
|
41
|
+
/** The tooltip's id. */
|
|
42
|
+
tooltipId: string;
|
|
43
|
+
/** Defaults to `description`. */
|
|
44
|
+
relation?: TooltipRelation;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The attribute linking a trigger to its tooltip, so assistive technology reads
|
|
48
|
+
* the tooltip whether it is shown or not: `aria-describedby`, or
|
|
49
|
+
* `aria-labelledby` when the tooltip names the trigger (it then wins over an
|
|
50
|
+
* `aria-label`).
|
|
51
|
+
*
|
|
52
|
+
* Time complexity: O(1). Memory: O(1).
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* tooltipTriggerAttributes({ tooltipId: "t", relation: "label" });
|
|
56
|
+
* // { "aria-labelledby": "t" }
|
|
57
|
+
*/
|
|
58
|
+
export declare function tooltipTriggerAttributes(input: TooltipTriggerAttributesInput): TooltipTriggerAttributes;
|
|
59
|
+
/**
|
|
60
|
+
* Where a tooltip stands: whether it is open and, when a change is pending,
|
|
61
|
+
* when it is due. The other members record what is hovered and focused; treat
|
|
62
|
+
* the state as opaque and pass it back to {@link tooltipStep}.
|
|
63
|
+
*/
|
|
64
|
+
export type TooltipState = {
|
|
65
|
+
readonly isOpen: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* When the pending change is due, in the caller's clock: an opening while
|
|
68
|
+
* closed, a closing while open. `undefined` when none is pending; call
|
|
69
|
+
* {@link tooltipStep} with a `time` input then.
|
|
70
|
+
*/
|
|
71
|
+
readonly deadline: number | undefined;
|
|
72
|
+
readonly isTriggerHovered: boolean;
|
|
73
|
+
readonly isTooltipHovered: boolean;
|
|
74
|
+
readonly isFocused: boolean;
|
|
75
|
+
/** Dismissed or pressed: closed until hover and focus have both ended. */
|
|
76
|
+
readonly isSuppressed: boolean;
|
|
77
|
+
};
|
|
78
|
+
/** A tooltip closed, nothing hovered nor focused: where every one starts. */
|
|
79
|
+
export declare const TOOLTIP_CLOSED: TooltipState;
|
|
80
|
+
/**
|
|
81
|
+
* What happens to a tooltip:
|
|
82
|
+
*
|
|
83
|
+
* - `hover` — a mouse or pen starts or stops hovering the trigger or the open
|
|
84
|
+
* tooltip (touch does not hover);
|
|
85
|
+
* - `focus` — the trigger gains or loses a focus the browser shows
|
|
86
|
+
* (`:focus-visible`, from the keyboard), not the focus a click gives;
|
|
87
|
+
* - `press` — the trigger is pressed;
|
|
88
|
+
* - `dismiss` — Escape;
|
|
89
|
+
* - `time` — the clock reached the state's `deadline`.
|
|
90
|
+
*/
|
|
91
|
+
export type TooltipInput = {
|
|
92
|
+
readonly kind: "hover";
|
|
93
|
+
readonly part: "trigger" | "tooltip";
|
|
94
|
+
readonly isHovered: boolean;
|
|
95
|
+
} | {
|
|
96
|
+
readonly kind: "focus";
|
|
97
|
+
readonly isFocused: boolean;
|
|
98
|
+
} | {
|
|
99
|
+
readonly kind: "press";
|
|
100
|
+
} | {
|
|
101
|
+
readonly kind: "dismiss";
|
|
102
|
+
} | {
|
|
103
|
+
readonly kind: "time";
|
|
104
|
+
};
|
|
105
|
+
/** Timing of {@link tooltipStep}. */
|
|
106
|
+
export type TooltipTiming = {
|
|
107
|
+
/** From the start of a hover to the opening, in ms. Defaults to 500. */
|
|
108
|
+
readonly showDelayMs?: number;
|
|
109
|
+
/**
|
|
110
|
+
* From the end of a hover to the closing, in ms, the time a pointer has to
|
|
111
|
+
* cross from the trigger to the tooltip. Defaults to 200.
|
|
112
|
+
*/
|
|
113
|
+
readonly hideDelayMs?: number;
|
|
114
|
+
/**
|
|
115
|
+
* Whether another tooltip of the group is open or just closed, so a hover
|
|
116
|
+
* opens this one at once ({@link TooltipGroup.isWarm}). Defaults to false.
|
|
117
|
+
*/
|
|
118
|
+
readonly isWarm?: boolean;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* The next state of a tooltip after `input` at `time` (ms), following the
|
|
122
|
+
* WAI-ARIA tooltip pattern and WCAG 2.2 success criterion 1.4.13 (content on
|
|
123
|
+
* hover or focus):
|
|
124
|
+
*
|
|
125
|
+
* - A hover opens it after `showDelayMs`, at once when the group is warm; a
|
|
126
|
+
* visible focus opens it at once;
|
|
127
|
+
* - It stays open while the trigger or the tooltip itself is hovered or the
|
|
128
|
+
* trigger focused (hoverable, persistent), the end of a hover closing it
|
|
129
|
+
* after `hideDelayMs`, the loss of focus at once;
|
|
130
|
+
* - Escape (dismissible) and a press of the trigger close it at once, and it
|
|
131
|
+
* stays closed until hover and focus have both ended.
|
|
132
|
+
*
|
|
133
|
+
* Returns `state` itself when nothing changes. The caller runs a timer to the
|
|
134
|
+
* returned `deadline` and passes a `time` input then.
|
|
135
|
+
*
|
|
136
|
+
* Time complexity: O(1). Memory: O(1).
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* let state = tooltipStep(
|
|
140
|
+
* TOOLTIP_CLOSED,
|
|
141
|
+
* { kind: "hover", part: "trigger", isHovered: true },
|
|
142
|
+
* 0,
|
|
143
|
+
* ); // { isOpen: false, deadline: 500, … }
|
|
144
|
+
* state = tooltipStep(state, { kind: "time" }, 500); // { isOpen: true, … }
|
|
145
|
+
*
|
|
146
|
+
* @throws {RangeError} When `time` is not finite, or a delay is negative or not
|
|
147
|
+
* finite.
|
|
148
|
+
*/
|
|
149
|
+
export declare function tooltipStep(state: TooltipState, input: TooltipInput, time: number, timing?: TooltipTiming): TooltipState;
|
|
150
|
+
/** Options of {@link TooltipGroup}. */
|
|
151
|
+
export type TooltipGroupOptions = {
|
|
152
|
+
/**
|
|
153
|
+
* How long after a tooltip of the group closes the next one still opens at
|
|
154
|
+
* once on hover, in ms, so a pointer running along a toolbar reads each one
|
|
155
|
+
* without waiting again. Defaults to 300.
|
|
156
|
+
*/
|
|
157
|
+
readonly skipDelayMs?: number;
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* The tooltips that show one at a time: opening one closes the one open before,
|
|
161
|
+
* and while one is open or just closed, the next opens without its show delay.
|
|
162
|
+
* Each tooltip is known by its close callback.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* const group = new TooltipGroup();
|
|
166
|
+
* group.opened(closeFirst);
|
|
167
|
+
* group.opened(closeSecond); // calls closeFirst
|
|
168
|
+
* group.isWarm(now); // true
|
|
169
|
+
*/
|
|
170
|
+
export declare class TooltipGroup {
|
|
171
|
+
private readonly skipDelayMs_;
|
|
172
|
+
private open_;
|
|
173
|
+
private closedAt_;
|
|
174
|
+
/** @throws {RangeError} When `skipDelayMs` is negative or not finite. */
|
|
175
|
+
constructor(options?: TooltipGroupOptions);
|
|
176
|
+
/** Whether a tooltip is open, or one closed less than the skip delay ago. */
|
|
177
|
+
isWarm(time: number): boolean;
|
|
178
|
+
/** A tooltip opened: the one open before is closed through its callback. */
|
|
179
|
+
opened(close: CallableNoArgs): void;
|
|
180
|
+
/** A tooltip closed at `time`; ignored unless it is the open one. */
|
|
181
|
+
closed(close: CallableNoArgs, time: number): void;
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=tooltip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../src/tooltip/tooltip.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EACX,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,MAAM,yBAAyB,CAAC;AAEjC,wEAAwE;AACxE,MAAM,MAAM,iBAAiB,GAAG,kBAAkB,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAEzE,0CAA0C;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E,cAAc,GAAG,IAAI,CAMlC;IAED,qEAAqE;IACrE,MAAM,CAAC,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAMhD;CACD"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { assertFinite, assertNonNegative, } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* The attributes of a tooltip (WAI-ARIA tooltip pattern): the `tooltip` role,
|
|
4
|
+
* and where the stylesheet places it against its trigger.
|
|
5
|
+
*
|
|
6
|
+
* Time complexity: O(1). Memory: O(1).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* tooltipAttributes(); // { role: "tooltip", "data-side": "block-start", "data-align": "center" }
|
|
10
|
+
*/
|
|
11
|
+
export function tooltipAttributes(input = {}) {
|
|
12
|
+
const { side = "block-start", align = "center" } = input;
|
|
13
|
+
return { role: "tooltip", "data-side": side, "data-align": align };
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The attribute linking a trigger to its tooltip, so assistive technology reads
|
|
17
|
+
* the tooltip whether it is shown or not: `aria-describedby`, or
|
|
18
|
+
* `aria-labelledby` when the tooltip names the trigger (it then wins over an
|
|
19
|
+
* `aria-label`).
|
|
20
|
+
*
|
|
21
|
+
* Time complexity: O(1). Memory: O(1).
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* tooltipTriggerAttributes({ tooltipId: "t", relation: "label" });
|
|
25
|
+
* // { "aria-labelledby": "t" }
|
|
26
|
+
*/
|
|
27
|
+
export function tooltipTriggerAttributes(input) {
|
|
28
|
+
return input.relation === "label"
|
|
29
|
+
? { "aria-labelledby": input.tooltipId }
|
|
30
|
+
: { "aria-describedby": input.tooltipId };
|
|
31
|
+
}
|
|
32
|
+
/** A tooltip closed, nothing hovered nor focused: where every one starts. */
|
|
33
|
+
export const TOOLTIP_CLOSED = Object.freeze({
|
|
34
|
+
isOpen: false,
|
|
35
|
+
deadline: undefined,
|
|
36
|
+
isTriggerHovered: false,
|
|
37
|
+
isTooltipHovered: false,
|
|
38
|
+
isFocused: false,
|
|
39
|
+
isSuppressed: false,
|
|
40
|
+
});
|
|
41
|
+
/**
|
|
42
|
+
* The next state of a tooltip after `input` at `time` (ms), following the
|
|
43
|
+
* WAI-ARIA tooltip pattern and WCAG 2.2 success criterion 1.4.13 (content on
|
|
44
|
+
* hover or focus):
|
|
45
|
+
*
|
|
46
|
+
* - A hover opens it after `showDelayMs`, at once when the group is warm; a
|
|
47
|
+
* visible focus opens it at once;
|
|
48
|
+
* - It stays open while the trigger or the tooltip itself is hovered or the
|
|
49
|
+
* trigger focused (hoverable, persistent), the end of a hover closing it
|
|
50
|
+
* after `hideDelayMs`, the loss of focus at once;
|
|
51
|
+
* - Escape (dismissible) and a press of the trigger close it at once, and it
|
|
52
|
+
* stays closed until hover and focus have both ended.
|
|
53
|
+
*
|
|
54
|
+
* Returns `state` itself when nothing changes. The caller runs a timer to the
|
|
55
|
+
* returned `deadline` and passes a `time` input then.
|
|
56
|
+
*
|
|
57
|
+
* Time complexity: O(1). Memory: O(1).
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* let state = tooltipStep(
|
|
61
|
+
* TOOLTIP_CLOSED,
|
|
62
|
+
* { kind: "hover", part: "trigger", isHovered: true },
|
|
63
|
+
* 0,
|
|
64
|
+
* ); // { isOpen: false, deadline: 500, … }
|
|
65
|
+
* state = tooltipStep(state, { kind: "time" }, 500); // { isOpen: true, … }
|
|
66
|
+
*
|
|
67
|
+
* @throws {RangeError} When `time` is not finite, or a delay is negative or not
|
|
68
|
+
* finite.
|
|
69
|
+
*/
|
|
70
|
+
export function tooltipStep(state, input, time, timing = {}) {
|
|
71
|
+
const { showDelayMs = 500, hideDelayMs = 200, isWarm = false } = timing;
|
|
72
|
+
assertFinite(time, "time");
|
|
73
|
+
assertNonNegative(showDelayMs, "showDelayMs");
|
|
74
|
+
assertNonNegative(hideDelayMs, "hideDelayMs");
|
|
75
|
+
if (input.kind === "time") {
|
|
76
|
+
if (state.deadline === undefined || time < state.deadline) {
|
|
77
|
+
return state;
|
|
78
|
+
}
|
|
79
|
+
// A closed tooltip is hovered no more, whatever events its hiding lost.
|
|
80
|
+
return {
|
|
81
|
+
...state,
|
|
82
|
+
isOpen: !state.isOpen,
|
|
83
|
+
deadline: undefined,
|
|
84
|
+
isTooltipHovered: false,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
let { isOpen, deadline, isTriggerHovered, isTooltipHovered, isFocused, isSuppressed, } = state;
|
|
88
|
+
switch (input.kind) {
|
|
89
|
+
case "hover":
|
|
90
|
+
if (input.part === "trigger") {
|
|
91
|
+
isTriggerHovered = input.isHovered;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
isTooltipHovered = input.isHovered && isOpen;
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
case "focus":
|
|
98
|
+
isFocused = input.isFocused;
|
|
99
|
+
break;
|
|
100
|
+
case "press":
|
|
101
|
+
case "dismiss":
|
|
102
|
+
isSuppressed = true;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
const isHovered = isTriggerHovered || isTooltipHovered;
|
|
106
|
+
if (!isHovered && !isFocused) {
|
|
107
|
+
isSuppressed = false;
|
|
108
|
+
}
|
|
109
|
+
const isWanted = (isHovered || isFocused) && !isSuppressed;
|
|
110
|
+
if (isWanted) {
|
|
111
|
+
if (isOpen) {
|
|
112
|
+
deadline = undefined;
|
|
113
|
+
}
|
|
114
|
+
else if ((input.kind === "focus" && isFocused) ||
|
|
115
|
+
isWarm ||
|
|
116
|
+
showDelayMs === 0) {
|
|
117
|
+
isOpen = true;
|
|
118
|
+
deadline = undefined;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
deadline ??= time + showDelayMs;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else if (!isOpen) {
|
|
125
|
+
deadline = undefined;
|
|
126
|
+
}
|
|
127
|
+
else if (input.kind === "hover" && hideDelayMs > 0) {
|
|
128
|
+
deadline ??= time + hideDelayMs;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
isOpen = false;
|
|
132
|
+
deadline = undefined;
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
isOpen,
|
|
136
|
+
deadline,
|
|
137
|
+
isTriggerHovered,
|
|
138
|
+
isTooltipHovered: isOpen && isTooltipHovered,
|
|
139
|
+
isFocused,
|
|
140
|
+
isSuppressed,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* The tooltips that show one at a time: opening one closes the one open before,
|
|
145
|
+
* and while one is open or just closed, the next opens without its show delay.
|
|
146
|
+
* Each tooltip is known by its close callback.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* const group = new TooltipGroup();
|
|
150
|
+
* group.opened(closeFirst);
|
|
151
|
+
* group.opened(closeSecond); // calls closeFirst
|
|
152
|
+
* group.isWarm(now); // true
|
|
153
|
+
*/
|
|
154
|
+
export class TooltipGroup {
|
|
155
|
+
skipDelayMs_;
|
|
156
|
+
open_;
|
|
157
|
+
closedAt_ = Number.NEGATIVE_INFINITY;
|
|
158
|
+
/** @throws {RangeError} When `skipDelayMs` is negative or not finite. */
|
|
159
|
+
constructor(options = {}) {
|
|
160
|
+
const { skipDelayMs = 300 } = options;
|
|
161
|
+
assertNonNegative(skipDelayMs, "skipDelayMs");
|
|
162
|
+
this.skipDelayMs_ = skipDelayMs;
|
|
163
|
+
}
|
|
164
|
+
/** Whether a tooltip is open, or one closed less than the skip delay ago. */
|
|
165
|
+
isWarm(time) {
|
|
166
|
+
return (this.open_ !== undefined || time - this.closedAt_ < this.skipDelayMs_);
|
|
167
|
+
}
|
|
168
|
+
/** A tooltip opened: the one open before is closed through its callback. */
|
|
169
|
+
opened(close) {
|
|
170
|
+
const previous = this.open_;
|
|
171
|
+
this.open_ = close;
|
|
172
|
+
if (previous !== undefined && previous !== close) {
|
|
173
|
+
previous();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/** A tooltip closed at `time`; ignored unless it is the open one. */
|
|
177
|
+
closed(close, time) {
|
|
178
|
+
if (this.open_ !== close) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
this.open_ = undefined;
|
|
182
|
+
this.closedAt_ = time;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=tooltip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip.js","sourceRoot":"","sources":["../../src/tooltip/tooltip.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,EACZ,iBAAiB,GAEjB,MAAM,cAAc,CAAC;AAmBtB;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAChC,KAAK,GAA2B,EAAE;IAElC,MAAM,EAAE,IAAI,GAAG,aAAa,EAAE,KAAK,GAAG,QAAQ,EAAE,GAAG,KAAK,CAAC;IAEzD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;AACpE,CAAC;AAyBD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,wBAAwB,CACvC,KAAoC;IAEpC,OAAO,KAAK,CAAC,QAAQ,KAAK,OAAO;QAChC,CAAC,CAAC,EAAE,iBAAiB,EAAE,KAAK,CAAC,SAAS,EAAE;QACxC,CAAC,CAAC,EAAE,kBAAkB,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;AAC5C,CAAC;AAsBD,6EAA6E;AAC7E,MAAM,CAAC,MAAM,cAAc,GAAiB,MAAM,CAAC,MAAM,CAAC;IACzD,MAAM,EAAE,KAAK;IACb,QAAQ,EAAE,SAAS;IACnB,gBAAgB,EAAE,KAAK;IACvB,gBAAgB,EAAE,KAAK;IACvB,SAAS,EAAE,KAAK;IAChB,YAAY,EAAE,KAAK;CACnB,CAAC,CAAC;AAwCH;;;;;;;;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MAAM,EAAE,WAAW,GAAG,GAAG,EAAE,GAAG,OAAO,CAAC;QACtC,iBAAiB,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;QAC9C,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IACjC,CAAC;IAED,6EAA6E;IAC7E,MAAM,CAAC,IAAY;QAClB,OAAO,CACN,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,IAAI,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,YAAY,CACrE,CAAC;IACH,CAAC;IAED,4EAA4E;IAC5E,MAAM,CAAC,KAAqB;QAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC;QAC5B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,KAAK,EAAE,CAAC;YAClD,QAAQ,EAAE,CAAC;QACZ,CAAC;IACF,CAAC;IAED,qEAAqE;IACrE,MAAM,CAAC,KAAqB,EAAE,IAAY;QACzC,IAAI,IAAI,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;YAC1B,OAAO;QACR,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACvB,CAAC;CACD"}
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { type Predicate } from "@ac-kit/core";
|
|
2
|
+
import type { KeyInput } from "@ac-kit/ui-gesture";
|
|
3
|
+
/**
|
|
4
|
+
* A tree's shape, as a tree view reads it: its roots, each node's children, and
|
|
5
|
+
* which nodes are branches. Nodes are compared by identity, so a node appears
|
|
6
|
+
* once.
|
|
7
|
+
*/
|
|
8
|
+
export type TreeSource<Node> = {
|
|
9
|
+
readonly roots: readonly Node[];
|
|
10
|
+
/**
|
|
11
|
+
* A branch's children; `undefined` for a leaf, or for a branch whose children
|
|
12
|
+
* are not loaded yet (a lazy tree loads them once the branch is expanded).
|
|
13
|
+
*/
|
|
14
|
+
readonly childrenOf: (node: Node) => readonly Node[] | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Whether a node is a branch, that can be expanded. Defaults to having at
|
|
17
|
+
* least one child: give it for a lazy tree, whose unloaded branches have no
|
|
18
|
+
* children yet.
|
|
19
|
+
*/
|
|
20
|
+
readonly isBranch?: Predicate<[node: Node]>;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The rows a tree view shows: every root, and the children of each expanded
|
|
24
|
+
* branch, in document order, with what WAI-ARIA states of each (`aria-level`,
|
|
25
|
+
* `aria-posinset`, `aria-setsize`, `aria-expanded`). Indices are row numbers,
|
|
26
|
+
* from 0.
|
|
27
|
+
*/
|
|
28
|
+
export type TreeRows<Node> = {
|
|
29
|
+
readonly count: number;
|
|
30
|
+
nodeAt(index: number): Node;
|
|
31
|
+
/** From 1 for a root, as `aria-level`. */
|
|
32
|
+
levelAt(index: number): number;
|
|
33
|
+
/** From 1 among its siblings, as `aria-posinset`. */
|
|
34
|
+
positionAt(index: number): number;
|
|
35
|
+
/** How many siblings it has, itself included, as `aria-setsize`. */
|
|
36
|
+
setSizeAt(index: number): number;
|
|
37
|
+
/** The row of its parent; -1 for a root. */
|
|
38
|
+
parentAt(index: number): number;
|
|
39
|
+
isBranchAt(index: number): boolean;
|
|
40
|
+
isExpandedAt(index: number): boolean;
|
|
41
|
+
/** An expanded branch whose children are not loaded yet. */
|
|
42
|
+
isLoadingAt(index: number): boolean;
|
|
43
|
+
/** The row showing `node`; -1 when it is not shown. O(1). */
|
|
44
|
+
indexOf(node: Node): number;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The rows of a tree view: {@link TreeRows}. A branch shows its children while
|
|
48
|
+
* `isExpanded` holds for it; an expanded branch whose children are `undefined`
|
|
49
|
+
* shows as loading. The walk is iterative (`@ac-kit/algo`'s `walkTree`), so a
|
|
50
|
+
* deep tree cannot overflow the stack, and it reads only what is shown:
|
|
51
|
+
* `childrenOf` is called for the expanded branches and, without `isBranch`, for
|
|
52
|
+
* every row.
|
|
53
|
+
*
|
|
54
|
+
* Time complexity: O(r) for r rows shown. Memory: O(r).
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* const source = {
|
|
58
|
+
* roots: [root],
|
|
59
|
+
* childrenOf: (node) => node.children,
|
|
60
|
+
* };
|
|
61
|
+
* const rows = visibleTreeRows(source, (node) => expanded.has(node));
|
|
62
|
+
* rows.levelAt(0); // 1
|
|
63
|
+
*
|
|
64
|
+
* @throws {Error} When a node is shown twice: the tree is not a tree (a node
|
|
65
|
+
* with two parents, or a cycle through an expanded branch).
|
|
66
|
+
*/
|
|
67
|
+
export declare function visibleTreeRows<Node>(source: TreeSource<Node>, isExpanded: Predicate<[node: Node]>): TreeRows<Node>;
|
|
68
|
+
/**
|
|
69
|
+
* The nodes from a root down to the node of row `index`, that row's included:
|
|
70
|
+
* what a tree view keeps of its focused row, to find the nearest one still
|
|
71
|
+
* shown once its branch closes ({@link treeTabStop}).
|
|
72
|
+
*
|
|
73
|
+
* Time complexity: O(depth). Memory: O(depth).
|
|
74
|
+
*
|
|
75
|
+
* @throws {RangeError} When `index` is not a row of `rows`.
|
|
76
|
+
*/
|
|
77
|
+
export declare function treePath<Node>(rows: TreeRows<Node>, index: number): Node[];
|
|
78
|
+
/**
|
|
79
|
+
* The row that holds a tree view's tab stop: the deepest node of `focusedPath`
|
|
80
|
+
* still shown (the focused row, or its nearest ancestor once a branch around it
|
|
81
|
+
* closed); before anything was focused (`focusedPath` empty), or when none of
|
|
82
|
+
* it is shown any more, the first row selected, else the first row, as the
|
|
83
|
+
* WAI-ARIA tree view pattern sets. -1 for no rows.
|
|
84
|
+
*
|
|
85
|
+
* Time complexity: O(p + s), p nodes in the path and s selected. Memory: O(1).
|
|
86
|
+
*/
|
|
87
|
+
export declare function treeTabStop<Node>(rows: TreeRows<Node>, focusedPath: readonly Node[], selected: ReadonlySet<Node>): number;
|
|
88
|
+
/**
|
|
89
|
+
* How a tree view lets nodes be selected: one at a time, several, or none (a
|
|
90
|
+
* navigation tree, whose nodes are only activated).
|
|
91
|
+
*/
|
|
92
|
+
export type TreeSelectionMode = "single" | "multiple" | "none";
|
|
93
|
+
/** The attributes of a tree view, keyed by their HTML attribute names. */
|
|
94
|
+
export type TreeAttributes = {
|
|
95
|
+
role: "tree";
|
|
96
|
+
"aria-label"?: string;
|
|
97
|
+
"aria-labelledby"?: string;
|
|
98
|
+
"aria-multiselectable"?: "true";
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Input of {@link treeAttributes}: its accessible name, as text or as the id of
|
|
102
|
+
* the element naming it, and how it selects.
|
|
103
|
+
*/
|
|
104
|
+
export type TreeAttributesInput = ({
|
|
105
|
+
label: string;
|
|
106
|
+
labelledBy?: undefined;
|
|
107
|
+
} | {
|
|
108
|
+
label?: undefined;
|
|
109
|
+
labelledBy: string;
|
|
110
|
+
}) & {
|
|
111
|
+
/** Defaults to `single`. */
|
|
112
|
+
selectionMode?: TreeSelectionMode;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* The attributes of a tree view (WAI-ARIA tree view pattern): the `tree` role,
|
|
116
|
+
* named, multi-selectable when several nodes can be selected.
|
|
117
|
+
*
|
|
118
|
+
* Time complexity: O(1). Memory: O(1).
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* treeAttributes({ labelledBy: "structure", selectionMode: "multiple" });
|
|
122
|
+
* // { role: "tree", "aria-labelledby": "structure",
|
|
123
|
+
* // "aria-multiselectable": "true" }
|
|
124
|
+
*/
|
|
125
|
+
export declare function treeAttributes(input: TreeAttributesInput): TreeAttributes;
|
|
126
|
+
/** The attributes of a tree item, keyed by their HTML attribute names. */
|
|
127
|
+
export type TreeItemAttributes = {
|
|
128
|
+
role: "treeitem";
|
|
129
|
+
"aria-level": number;
|
|
130
|
+
"aria-posinset": number;
|
|
131
|
+
"aria-setsize": number;
|
|
132
|
+
tabindex: 0 | -1;
|
|
133
|
+
"aria-expanded"?: "true" | "false";
|
|
134
|
+
"aria-selected"?: "true" | "false";
|
|
135
|
+
"aria-disabled"?: "true";
|
|
136
|
+
"aria-busy"?: "true";
|
|
137
|
+
};
|
|
138
|
+
/** Input of {@link treeItemAttributes}. */
|
|
139
|
+
export type TreeItemAttributesInput = {
|
|
140
|
+
rows: TreeRows<unknown>;
|
|
141
|
+
index: number;
|
|
142
|
+
/** Defaults to `single`. */
|
|
143
|
+
selectionMode?: TreeSelectionMode;
|
|
144
|
+
isSelected: boolean;
|
|
145
|
+
/** Whether it holds the tree's tab stop ({@link treeTabStop}). */
|
|
146
|
+
isTabStop: boolean;
|
|
147
|
+
isDisabled?: boolean;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* The attributes of the tree item of row `index`: its level, position and set
|
|
151
|
+
* size (every row states them, so a tree drawn as one flat list, or only in
|
|
152
|
+
* part, reads as nested), expanded or not for a branch, busy while its children
|
|
153
|
+
* load, and in the tab order only as the tree's tab stop. Selection is stated
|
|
154
|
+
* on every item when several can be selected, and only on the selected one
|
|
155
|
+
* otherwise, so a screen reader does not say "not selected" on each row. A
|
|
156
|
+
* disabled item stays focusable, as the WAI-ARIA practices advise for the items
|
|
157
|
+
* of a composite widget.
|
|
158
|
+
*
|
|
159
|
+
* Time complexity: O(1). Memory: O(1).
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* treeItemAttributes({ rows, index: 0, isSelected: true, isTabStop: true });
|
|
163
|
+
* // { role: "treeitem", "aria-level": 1, "aria-posinset": 1,
|
|
164
|
+
* // "aria-setsize": 1, tabindex: 0, "aria-expanded": "true",
|
|
165
|
+
* // "aria-selected": "true" } for an expanded root branch
|
|
166
|
+
*
|
|
167
|
+
* @throws {RangeError} When `index` is not a row of `rows`.
|
|
168
|
+
*/
|
|
169
|
+
export declare function treeItemAttributes(input: TreeItemAttributesInput): TreeItemAttributes;
|
|
170
|
+
/** Input of {@link treeKeyAction}: the key and the rows around focus. */
|
|
171
|
+
export type TreeKeyInput = KeyInput & {
|
|
172
|
+
/** The focused row. */
|
|
173
|
+
current: number;
|
|
174
|
+
rows: TreeRows<unknown>;
|
|
175
|
+
/** `rtl` swaps Left and Right. Defaults to `ltr`. */
|
|
176
|
+
direction?: "ltr" | "rtl";
|
|
177
|
+
/** Defaults to `single`. */
|
|
178
|
+
selectionMode?: TreeSelectionMode;
|
|
179
|
+
/** Whether a typeahead query is in progress, so Space extends it. */
|
|
180
|
+
isTypingAhead?: boolean;
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* What a key does in a tree view (WAI-ARIA tree view pattern):
|
|
184
|
+
*
|
|
185
|
+
* - `focus` a row: Arrow Down and Up to the next and previous row, Home and End
|
|
186
|
+
* to the first and last; Arrow Right to a branch's first child once it is
|
|
187
|
+
* expanded, Arrow Left to the parent. At an end, or where a key has nowhere
|
|
188
|
+
* to go, the focused row itself: consume the key, change nothing. `toggles`
|
|
189
|
+
* for Shift Arrow Down and Up when several nodes can be selected: the row
|
|
190
|
+
* reached flips its selection;
|
|
191
|
+
* - `expand` a collapsed branch (Arrow Right), `collapse` an expanded one (Arrow
|
|
192
|
+
* Left);
|
|
193
|
+
* - `expandSiblings`: `*` expands every branch beside the focused row;
|
|
194
|
+
* - `activate` the focused row: Enter (its default action; for a branch with
|
|
195
|
+
* none, expanding or collapsing it);
|
|
196
|
+
* - `select`: Space, the focused row alone in single selection, flipping it in
|
|
197
|
+
* multiple selection;
|
|
198
|
+
* - `selectRange` from the most recently selected row (`"anchor"`) or the focused
|
|
199
|
+
* one to `to`, focus moving to `focus`: Shift Space, and Ctrl Shift Home and
|
|
200
|
+
* End (to the first and last rows);
|
|
201
|
+
* - `selectAll`: Ctrl A, or Cmd A;
|
|
202
|
+
* - `typeahead` a character, Space included while a query is in progress.
|
|
203
|
+
*/
|
|
204
|
+
export type TreeKeyAction = {
|
|
205
|
+
readonly kind: "focus";
|
|
206
|
+
readonly index: number;
|
|
207
|
+
readonly toggles: boolean;
|
|
208
|
+
} | {
|
|
209
|
+
readonly kind: "expand";
|
|
210
|
+
readonly index: number;
|
|
211
|
+
} | {
|
|
212
|
+
readonly kind: "collapse";
|
|
213
|
+
readonly index: number;
|
|
214
|
+
} | {
|
|
215
|
+
readonly kind: "expandSiblings";
|
|
216
|
+
readonly index: number;
|
|
217
|
+
} | {
|
|
218
|
+
readonly kind: "activate";
|
|
219
|
+
readonly index: number;
|
|
220
|
+
} | {
|
|
221
|
+
readonly kind: "select";
|
|
222
|
+
readonly index: number;
|
|
223
|
+
} | {
|
|
224
|
+
readonly kind: "selectRange";
|
|
225
|
+
readonly from: number | "anchor";
|
|
226
|
+
readonly to: number;
|
|
227
|
+
readonly focus: number;
|
|
228
|
+
} | {
|
|
229
|
+
readonly kind: "selectAll";
|
|
230
|
+
} | {
|
|
231
|
+
readonly kind: "typeahead";
|
|
232
|
+
readonly character: string;
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* The action of a key on a tree view's focused row, {@link TreeKeyAction}.
|
|
236
|
+
* `undefined` for a key the tree does not use, or with a modifier it does not
|
|
237
|
+
* take (Alt always; Ctrl or Cmd outside the selection shortcuts). Disabled
|
|
238
|
+
* nodes take focus like the others, so the caller checks them before activating
|
|
239
|
+
* or selecting one. Right-to-left, Arrow Right and Left swap.
|
|
240
|
+
*
|
|
241
|
+
* Time complexity: O(1). Memory: O(1).
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* treeKeyAction({ key: "ArrowRight", current: 0, rows });
|
|
245
|
+
* // { kind: "expand", index: 0 } on a collapsed branch
|
|
246
|
+
*
|
|
247
|
+
* @throws {RangeError} When `current` is not a row of `rows`.
|
|
248
|
+
*/
|
|
249
|
+
export declare function treeKeyAction(input: TreeKeyInput): TreeKeyAction | undefined;
|
|
250
|
+
/**
|
|
251
|
+
* A change to a tree view's selection:
|
|
252
|
+
*
|
|
253
|
+
* - `replace` it with the node of row `index` alone (a click, single selection);
|
|
254
|
+
* - `toggle` that node in or out;
|
|
255
|
+
* - `range`: the nodes of the rows from `from` to `to`, both included, added to
|
|
256
|
+
* the selection (`isAdded`) or replacing it;
|
|
257
|
+
* - `all`: every node, or none when every node is already selected.
|
|
258
|
+
*/
|
|
259
|
+
export type TreeSelectionChange = {
|
|
260
|
+
readonly kind: "replace";
|
|
261
|
+
readonly index: number;
|
|
262
|
+
} | {
|
|
263
|
+
readonly kind: "toggle";
|
|
264
|
+
readonly index: number;
|
|
265
|
+
} | {
|
|
266
|
+
readonly kind: "range";
|
|
267
|
+
readonly from: number;
|
|
268
|
+
readonly to: number;
|
|
269
|
+
readonly isAdded: boolean;
|
|
270
|
+
} | {
|
|
271
|
+
readonly kind: "all";
|
|
272
|
+
};
|
|
273
|
+
/** Context of {@link nextTreeSelection}. */
|
|
274
|
+
export type TreeSelectionContext<Node> = {
|
|
275
|
+
readonly source: TreeSource<Node>;
|
|
276
|
+
readonly rows: TreeRows<Node>;
|
|
277
|
+
/** Nodes never selected. Defaults to none. */
|
|
278
|
+
readonly isDisabled?: Predicate<[node: Node]>;
|
|
279
|
+
};
|
|
280
|
+
/**
|
|
281
|
+
* The selection after `change`: a new set, or `selected` itself when nothing
|
|
282
|
+
* changes, so a caller reports only real changes. Disabled nodes are never
|
|
283
|
+
* added; a range or `all` keeps the disabled nodes already selected. `all`
|
|
284
|
+
* takes every node of the tree whose children are loaded, shown or not.
|
|
285
|
+
*
|
|
286
|
+
* Time complexity: O(s + k), s selected and k nodes the change covers (every
|
|
287
|
+
* loaded node for `all`). Memory: O(s + k).
|
|
288
|
+
*
|
|
289
|
+
* @throws {RangeError} When an index is not a row of `context.rows`.
|
|
290
|
+
*/
|
|
291
|
+
export declare function nextTreeSelection<Node>(selected: ReadonlySet<Node>, change: TreeSelectionChange, context: TreeSelectionContext<Node>): ReadonlySet<Node>;
|
|
292
|
+
/**
|
|
293
|
+
* The expanded set once every branch beside the node of row `index` (its
|
|
294
|
+
* siblings, itself included) is expanded: what `*` does. `expanded` itself when
|
|
295
|
+
* they all already are.
|
|
296
|
+
*
|
|
297
|
+
* Time complexity: O(e + s), e expanded and s siblings. Memory: O(e + s).
|
|
298
|
+
*
|
|
299
|
+
* @throws {RangeError} When `index` is not a row of `rows`.
|
|
300
|
+
*/
|
|
301
|
+
export declare function expandTreeSiblings<Node>(source: TreeSource<Node>, rows: TreeRows<Node>, index: number, expanded: ReadonlySet<Node>): ReadonlySet<Node>;
|
|
302
|
+
//# sourceMappingURL=tree.d.ts.map
|