@senvenli/react 0.3.3 → 0.3.4
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/dist/action/fab.d.ts +7 -0
- package/dist/action/fab.js +22 -3
- package/dist/action/fab.js.map +1 -1
- package/dist/collection/data-table.d.ts +1 -1
- package/dist/collection/data-table.js +2 -2
- package/dist/collection/data-table.js.map +1 -1
- package/dist/collection/table.d.ts +7 -2
- package/dist/collection/table.js +17 -7
- package/dist/collection/table.js.map +1 -1
- package/dist/i18n.d.ts +8 -0
- package/dist/i18n.js +18 -1
- package/dist/i18n.js.map +1 -1
- package/dist/navigation/index.d.ts +2 -2
- package/dist/navigation/index.js +1 -1
- package/dist/navigation/index.js.map +1 -1
- package/dist/navigation/sidebar.d.ts +18 -0
- package/dist/navigation/sidebar.js +26 -2
- package/dist/navigation/sidebar.js.map +1 -1
- package/dist/overlay/floating.js +4 -1
- package/dist/overlay/floating.js.map +1 -1
- package/dist/overlay/index.d.ts +2 -0
- package/dist/overlay/index.js +2 -1
- package/dist/overlay/index.js.map +1 -1
- package/dist/overlay/tour.d.ts +88 -0
- package/dist/overlay/tour.js +302 -0
- package/dist/overlay/tour.js.map +1 -0
- package/package.json +2 -2
- package/dist/action/files.d.ts +0 -70
- package/dist/action/files.js +0 -156
- package/dist/action/files.js.map +0 -1
- package/dist/action/theme-toggle.d.ts +0 -43
- package/dist/action/theme-toggle.js +0 -259
- package/dist/action/theme-toggle.js.map +0 -1
- package/dist/display/image-crop.d.ts +0 -106
- package/dist/display/image-crop.js +0 -117
- package/dist/display/image-crop.js.map +0 -1
- package/dist/display/image-cropper.d.ts +0 -68
- package/dist/display/image-cropper.js +0 -284
- package/dist/display/image-cropper.js.map +0 -1
- package/dist/display/lozenge.d.ts +0 -30
- package/dist/display/lozenge.js +0 -55
- package/dist/display/lozenge.js.map +0 -1
- package/dist/display/scroll-area.d.ts +0 -29
- package/dist/display/scroll-area.js +0 -95
- package/dist/display/scroll-area.js.map +0 -1
- package/dist/feedback/cooldown.d.ts +0 -17
- package/dist/feedback/cooldown.js +0 -59
- package/dist/feedback/cooldown.js.map +0 -1
- package/dist/feedback/status-dot.d.ts +0 -23
- package/dist/feedback/status-dot.js +0 -37
- package/dist/feedback/status-dot.js.map +0 -1
- package/dist/form/input-otp.d.ts +0 -35
- package/dist/form/input-otp.js +0 -83
- package/dist/form/input-otp.js.map +0 -1
- package/dist/layout/auth-form-layout.d.ts +0 -71
- package/dist/layout/auth-form-layout.js +0 -61
- package/dist/layout/auth-form-layout.js.map +0 -1
- package/dist/layout/auth-layout.d.ts +0 -59
- package/dist/layout/auth-layout.js +0 -26
- package/dist/layout/auth-layout.js.map +0 -1
- package/dist/layout/pressable.d.ts +0 -40
- package/dist/layout/pressable.js +0 -65
- package/dist/layout/pressable.js.map +0 -1
- package/dist/layout/reset-sent-card.d.ts +0 -39
- package/dist/layout/reset-sent-card.js +0 -22
- package/dist/layout/reset-sent-card.js.map +0 -1
- package/dist/navigation/dock.d.ts +0 -27
- package/dist/navigation/dock.js +0 -47
- package/dist/navigation/dock.js.map +0 -1
- package/dist/navigation/footer.d.ts +0 -43
- package/dist/navigation/footer.js +0 -43
- package/dist/navigation/footer.js.map +0 -1
- package/dist/navigation/language-names.d.ts +0 -19
- package/dist/navigation/language-names.js +0 -79
- package/dist/navigation/language-names.js.map +0 -1
- package/dist/navigation/language-switcher.d.ts +0 -55
- package/dist/navigation/language-switcher.js +0 -53
- package/dist/navigation/language-switcher.js.map +0 -1
- package/dist/navigation/panel-header.d.ts +0 -37
- package/dist/navigation/panel-header.js +0 -50
- package/dist/navigation/panel-header.js.map +0 -1
- package/dist/navigation/toolbar.d.ts +0 -37
- package/dist/navigation/toolbar.js +0 -334
- package/dist/navigation/toolbar.js.map +0 -1
- package/dist/overlay/command-palette.d.ts +0 -53
- package/dist/overlay/command-palette.js +0 -130
- package/dist/overlay/command-palette.js.map +0 -1
- package/dist/overlay/overlay.d.ts +0 -299
- package/dist/overlay/overlay.js +0 -558
- package/dist/overlay/overlay.js.map +0 -1
- package/dist/selection/radio-card.d.ts +0 -31
- package/dist/selection/radio-card.js +0 -29
- package/dist/selection/radio-card.js.map +0 -1
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
import { Toolbar as AriaToolbar, useLocale } from "react-aria-components";
|
|
5
|
-
import { Button } from "../action/button.js";
|
|
6
|
-
import { clearSelectionLabel, selectedCountLabel } from "../i18n.js";
|
|
7
|
-
/**
|
|
8
|
-
* Controls that act on the view below it. One Tab stop: arrow keys move between the controls (mirrored
|
|
9
|
-
* in RTL). Put a `ToolbarSpacer` before the view and export controls to push them to the end.
|
|
10
|
-
* A text-editing control inside (a SearchField's input, a DateField's segments) keeps ←/→ for its caret
|
|
11
|
-
* and segments; at its edge (the caret at the start or end, the first or last segment) the arrow moves on
|
|
12
|
-
* to the next control, so every control stays reachable by the arrows. Arrowing into a date or time field
|
|
13
|
-
* lands on the segment nearest the way in: in RTL the visually nearest one, whatever the DOM order of its
|
|
14
|
-
* segments. A raw `type="number"` or
|
|
15
|
-
* `type="email"` input with a value has no readable caret and keeps ←/→ (Tab leaves it); prefer NumberField,
|
|
16
|
-
* or TextField with `inputMode`, inside a toolbar.
|
|
17
|
-
*/
|
|
18
|
-
export function Toolbar({ children, "aria-label": label }) {
|
|
19
|
-
const ref = React.useRef(null);
|
|
20
|
-
const { toolbarProps } = useToolbarKeys(ref);
|
|
21
|
-
return (_jsx("div", { ref: ref, "data-slot": "toolbar", className: "flex flex-wrap items-center gap-ds-100 rounded-ds-large bg-ds-surface-raised px-ds-150 py-ds-100 shadow-ds-raised", "data-rac": "", "aria-label": label, ...toolbarProps, children: children }));
|
|
22
|
-
}
|
|
23
|
-
/*
|
|
24
|
-
* React Aria's Toolbar (react-aria-components) handles ←/→ in a capture listener on the toolbar and
|
|
25
|
-
* takes no key handler of its own, so it cannot leave the arrows to a text control inside it. This
|
|
26
|
-
* mirrors its useToolbar (horizontal): same role, arrows mirrored in RTL, no wrap, Tab leaving via the
|
|
27
|
-
* first/last control, focus restored on return. The one change: ←/→ on a text-editing target belong
|
|
28
|
-
* to that target until the caret or segment focus is at the target's edge in the arrow's direction.
|
|
29
|
-
*/
|
|
30
|
-
// React Aria's focusable-element selector (isFocusable), so the arrows reach the same controls.
|
|
31
|
-
const FOCUSABLE = [
|
|
32
|
-
"input:not([disabled]):not([type=hidden])",
|
|
33
|
-
"select:not([disabled])",
|
|
34
|
-
"textarea:not([disabled])",
|
|
35
|
-
"button:not([disabled])",
|
|
36
|
-
"a[href]",
|
|
37
|
-
"area[href]",
|
|
38
|
-
"summary",
|
|
39
|
-
"iframe",
|
|
40
|
-
"object",
|
|
41
|
-
"embed",
|
|
42
|
-
"audio[controls]",
|
|
43
|
-
"video[controls]",
|
|
44
|
-
'[contenteditable]:not([contenteditable^="false"])',
|
|
45
|
-
"permission",
|
|
46
|
-
]
|
|
47
|
-
.map((selector) => `${selector}:not([hidden])`)
|
|
48
|
-
.concat("[tabindex]:not([disabled]):not([hidden])")
|
|
49
|
-
.join(",");
|
|
50
|
-
/*
|
|
51
|
-
* React Aria's shadow-DOM-aware helpers (getActiveElement, nodeContains, getEventTarget in
|
|
52
|
-
* react-aria/private/utils/shadowdom) are not part of the public react-aria-components surface, and
|
|
53
|
-
* react-aria itself is not a dependency of this package, so they are mirrored here. React Aria only
|
|
54
|
-
* walks shadow roots when its shadowDOM flag is on; in the light DOM (the flag's default) these give
|
|
55
|
-
* exactly document.activeElement, Node.contains and event.target, as React Aria does.
|
|
56
|
-
*/
|
|
57
|
-
function getActiveElement(doc = document) {
|
|
58
|
-
let active = doc.activeElement;
|
|
59
|
-
while (active?.shadowRoot?.activeElement)
|
|
60
|
-
active = active.shadowRoot.activeElement;
|
|
61
|
-
return active;
|
|
62
|
-
}
|
|
63
|
-
function nodeContains(node, other) {
|
|
64
|
-
if (!node || !other)
|
|
65
|
-
return false;
|
|
66
|
-
for (let current = other; current;) {
|
|
67
|
-
if (current === node)
|
|
68
|
-
return true;
|
|
69
|
-
const slot = current.assignedSlot;
|
|
70
|
-
// A slotted element continues from its slot (a slot itself walks up as usual).
|
|
71
|
-
if (typeof current.assignedElements !== "function" && slot?.parentNode)
|
|
72
|
-
current = slot.parentNode;
|
|
73
|
-
else if (current instanceof ShadowRoot)
|
|
74
|
-
current = current.host;
|
|
75
|
-
else
|
|
76
|
-
current = current.parentNode;
|
|
77
|
-
}
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
function getEventTarget(e) {
|
|
81
|
-
const target = e.target;
|
|
82
|
-
if (target instanceof Element && target.shadowRoot) {
|
|
83
|
-
const inner = e.nativeEvent.composedPath?.()[0];
|
|
84
|
-
if (inner instanceof Element)
|
|
85
|
-
return inner;
|
|
86
|
-
}
|
|
87
|
-
return target;
|
|
88
|
-
}
|
|
89
|
-
// Inputs that do not use ←/→ themselves: the toolbar always takes the arrows from them.
|
|
90
|
-
const ARROWLESS_INPUTS = new Set(["button", "submit", "reset", "checkbox", "image", "file", "color"]);
|
|
91
|
-
/*
|
|
92
|
-
* Inputs whose value ←/→ change, so the arrows always stay with them: React Aria's RadioGroup moves the
|
|
93
|
-
* selection between its radios and its Slider moves the thumb with ←/→ (no caret, so no edge).
|
|
94
|
-
*/
|
|
95
|
-
const VALUE_ARROW_INPUTS = new Set(["radio", "range"]);
|
|
96
|
-
function isRtl(element, fallback) {
|
|
97
|
-
const computed = getComputedStyle(element).direction;
|
|
98
|
-
if (computed === "rtl" || computed === "ltr")
|
|
99
|
-
return computed === "rtl";
|
|
100
|
-
// jsdom resolves no `direction`; :dir() reads the dir attribute the same way the browser does.
|
|
101
|
-
try {
|
|
102
|
-
return element.matches(":dir(rtl)");
|
|
103
|
-
}
|
|
104
|
-
catch {
|
|
105
|
-
return fallback === "rtl";
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* The segment group (`role="group"`) of a date/time segment inside the toolbar, else undefined. Only
|
|
110
|
-
* segments step from their group: a text input is one element, and its group (the field frame) also holds
|
|
111
|
-
* controls of its own (a SearchField's clear button, InputActions) that the arrows should still reach.
|
|
112
|
-
*/
|
|
113
|
-
function segmentGroup(target, toolbar) {
|
|
114
|
-
if (target.getAttribute("role") !== "spinbutton")
|
|
115
|
-
return undefined;
|
|
116
|
-
const group = target.closest('[role="group"]');
|
|
117
|
-
return group && group !== toolbar && toolbar.contains(group) ? group : undefined;
|
|
118
|
-
}
|
|
119
|
-
function isTabbable(element) {
|
|
120
|
-
return element.tabIndex >= 0;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* True when the arrow key belongs to the target: a caret that can still move that way in a text input or
|
|
124
|
-
* textarea, a date/time segment with another segment that way, a radio or slider, or a contenteditable
|
|
125
|
-
* or textbox whose caret the toolbar cannot read. A non-collapsed selection always stays with the field.
|
|
126
|
-
* `direction` is the toolbar's (the locale's), as React Aria's date segments use it.
|
|
127
|
-
*/
|
|
128
|
-
function keepsArrows(target, key, direction) {
|
|
129
|
-
const tag = target.tagName;
|
|
130
|
-
if (tag === "INPUT" || tag === "TEXTAREA") {
|
|
131
|
-
const field = target;
|
|
132
|
-
if (tag === "INPUT" && ARROWLESS_INPUTS.has(field.type))
|
|
133
|
-
return false;
|
|
134
|
-
if (tag === "INPUT" && VALUE_ARROW_INPUTS.has(field.type))
|
|
135
|
-
return true;
|
|
136
|
-
let start;
|
|
137
|
-
let end;
|
|
138
|
-
try {
|
|
139
|
-
start = field.selectionStart;
|
|
140
|
-
end = field.selectionEnd;
|
|
141
|
-
}
|
|
142
|
-
catch {
|
|
143
|
-
start = end = null;
|
|
144
|
-
}
|
|
145
|
-
/*
|
|
146
|
-
* number, email…: the browser exposes no caret (selectionStart is null), so the toolbar cannot tell
|
|
147
|
-
* an edge. Empty, there is no caret to move and the arrows move on; with a value the field keeps them,
|
|
148
|
-
* since taking them would leave no way to move the caret. Tab leaves such a field. The DS's own
|
|
149
|
-
* fields avoid this: NumberField is a text input, and TextField takes `inputMode` for e-mail.
|
|
150
|
-
*/
|
|
151
|
-
if (start == null || end == null)
|
|
152
|
-
return field.value !== "";
|
|
153
|
-
if (start !== end)
|
|
154
|
-
return true;
|
|
155
|
-
// The caret's back key is ← in an LTR field and → in an RTL one: the field's own direction.
|
|
156
|
-
const back = isRtl(field, direction) ? key === "ArrowRight" : key === "ArrowLeft";
|
|
157
|
-
return back ? start > 0 : end < field.value.length;
|
|
158
|
-
}
|
|
159
|
-
const role = target.getAttribute("role");
|
|
160
|
-
if (role === "spinbutton") {
|
|
161
|
-
const group = target.closest('[role="group"]');
|
|
162
|
-
if (group)
|
|
163
|
-
return hasSegmentToward(group, target, key, direction);
|
|
164
|
-
return true;
|
|
165
|
-
}
|
|
166
|
-
if (role === "textbox" || role === "searchbox")
|
|
167
|
-
return true;
|
|
168
|
-
return target.closest('[contenteditable]:not([contenteditable^="false"])') != null;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Whether React Aria's date/time field would move to another segment for this arrow (useDatePickerGroup):
|
|
172
|
-
* in LTR the previous/next tabbable segment in DOM order; in RTL the nearest segment visually to that
|
|
173
|
-
* side (its bounding box), since RTL date and time segments are not laid out in DOM order.
|
|
174
|
-
*/
|
|
175
|
-
function hasSegmentToward(group, segment, key, direction) {
|
|
176
|
-
const segments = Array.from(group.querySelectorAll(FOCUSABLE)).filter((element) => isTabbable(element) && isVisible(element));
|
|
177
|
-
if (direction === "rtl") {
|
|
178
|
-
const from = segment.getBoundingClientRect().x;
|
|
179
|
-
const sign = key === "ArrowRight" ? 1 : -1;
|
|
180
|
-
return segments.some((element) => element !== segment && Math.sign(element.getBoundingClientRect().x - from) === sign);
|
|
181
|
-
}
|
|
182
|
-
const index = segments.indexOf(segment);
|
|
183
|
-
if (index === -1)
|
|
184
|
-
return true;
|
|
185
|
-
return key === "ArrowLeft" ? index > 0 : index < segments.length - 1;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* In RTL, the segment an arrow should land on when it moves INTO a date/time field: the one
|
|
189
|
-
* visually nearest the side focus enters from, by bounding box as `hasSegmentToward` reads it, since RTL
|
|
190
|
-
* segments need not be laid out in DOM order. A step toward the toolbar's end (`step` 1, ← in RTL) enters
|
|
191
|
-
* at the field's start side, the segment furthest toward the start; a step toward the start enters at its
|
|
192
|
-
* end side. Any other target, or segments without a layout (equal boxes), keep the DOM-order choice.
|
|
193
|
-
*/
|
|
194
|
-
function entrySegment(next, toolbar, step) {
|
|
195
|
-
const group = segmentGroup(next, toolbar);
|
|
196
|
-
if (!group)
|
|
197
|
-
return next;
|
|
198
|
-
const segments = Array.from(group.querySelectorAll(FOCUSABLE)).filter((element) => isTabbable(element) && isVisible(element));
|
|
199
|
-
// In RTL the start side is the larger x: a step of 1 enters the field at its start side (largest x), -1 at its end side.
|
|
200
|
-
const enterAtStartSide = step === 1;
|
|
201
|
-
let best = next;
|
|
202
|
-
let bestX = next.getBoundingClientRect().x;
|
|
203
|
-
for (const element of segments) {
|
|
204
|
-
const x = element.getBoundingClientRect().x;
|
|
205
|
-
if (enterAtStartSide ? x > bestX : x < bestX) {
|
|
206
|
-
best = element;
|
|
207
|
-
bestX = x;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return best;
|
|
211
|
-
}
|
|
212
|
-
function isVisible(element) {
|
|
213
|
-
if (typeof element.checkVisibility === "function") {
|
|
214
|
-
return element.checkVisibility({ visibilityProperty: true }) && !element.closest("[data-react-aria-prevent-focus]");
|
|
215
|
-
}
|
|
216
|
-
for (let node = element; node; node = node.parentElement) {
|
|
217
|
-
if (node.hasAttribute("hidden") || node.hasAttribute("data-react-aria-prevent-focus"))
|
|
218
|
-
return false;
|
|
219
|
-
const { display, visibility } = getComputedStyle(node);
|
|
220
|
-
if (display === "none" || visibility === "hidden" || visibility === "collapse")
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
return true;
|
|
224
|
-
}
|
|
225
|
-
function focusables(root) {
|
|
226
|
-
return Array.from(root.querySelectorAll(FOCUSABLE)).filter((element) => !element.closest("[inert]") && isVisible(element));
|
|
227
|
-
}
|
|
228
|
-
function useToolbarKeys(ref) {
|
|
229
|
-
const { direction } = useLocale();
|
|
230
|
-
const [isInToolbar, setInToolbar] = React.useState(false);
|
|
231
|
-
React.useLayoutEffect(() => {
|
|
232
|
-
setInToolbar(!!ref.current?.parentElement?.closest('[role="toolbar"]'));
|
|
233
|
-
});
|
|
234
|
-
const lastFocused = React.useRef(null);
|
|
235
|
-
/*
|
|
236
|
-
* Moves to the next/previous control in DOM order from `from` (the focused element by default). `from` is
|
|
237
|
-
* a whole segment group when the arrow leaves a date/time field: the step starts after (or before) the
|
|
238
|
-
* group, never at a sibling segment, since in RTL the visual edge segment need not be the DOM-order edge
|
|
239
|
-
* (an `ar` TimeField or a `he-IL` date keeps DOM order; an `ar` date is reversed). Arrowing INTO such a
|
|
240
|
-
* field in RTL lands on its segment visually nearest the way in (`entrySegment`); LTR keeps DOM order.
|
|
241
|
-
* Plain focus(), as React Aria's focus manager does: the control scrolls into view.
|
|
242
|
-
*/
|
|
243
|
-
const move = (step, from) => {
|
|
244
|
-
const root = ref.current;
|
|
245
|
-
if (!root)
|
|
246
|
-
return;
|
|
247
|
-
const all = focusables(root);
|
|
248
|
-
const active = from ?? getActiveElement();
|
|
249
|
-
let next;
|
|
250
|
-
if (!active || !nodeContains(root, active))
|
|
251
|
-
next = step === 1 ? all[0] : all[all.length - 1];
|
|
252
|
-
else if (step === 1) {
|
|
253
|
-
// FOLLOWING includes the group's own descendants: skip them.
|
|
254
|
-
next = all.find((el) => active.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_FOLLOWING && !active.contains(el));
|
|
255
|
-
}
|
|
256
|
-
else
|
|
257
|
-
next = all.filter((el) => active.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_PRECEDING).pop();
|
|
258
|
-
// Into a date/time field in RTL: the segment nearest the side the arrow enters from, not the DOM-first one.
|
|
259
|
-
if (next && direction === "rtl")
|
|
260
|
-
next = entrySegment(next, root, step);
|
|
261
|
-
next?.focus();
|
|
262
|
-
};
|
|
263
|
-
const edge = (end) => {
|
|
264
|
-
const all = ref.current ? focusables(ref.current) : [];
|
|
265
|
-
(end === "first" ? all[0] : all[all.length - 1])?.focus();
|
|
266
|
-
};
|
|
267
|
-
const onKeyDownCapture = (e) => {
|
|
268
|
-
const target = getEventTarget(e);
|
|
269
|
-
// Portalled content (a popover opened from a control) is not the toolbar's.
|
|
270
|
-
if (!nodeContains(e.currentTarget, target))
|
|
271
|
-
return;
|
|
272
|
-
if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
|
|
273
|
-
if (keepsArrows(target, e.key, direction))
|
|
274
|
-
return;
|
|
275
|
-
const forward = e.key === "ArrowRight" ? 1 : -1;
|
|
276
|
-
move(direction === "rtl" ? -forward : forward, segmentGroup(target, e.currentTarget));
|
|
277
|
-
}
|
|
278
|
-
else if (e.key === "Tab") {
|
|
279
|
-
// Focus the first/last control and let the browser's Tab carry focus out from there.
|
|
280
|
-
lastFocused.current = getActiveElement();
|
|
281
|
-
edge(e.shiftKey ? "first" : "last");
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
else
|
|
285
|
-
return;
|
|
286
|
-
// Keep nested action groups (and the field the arrow moved out of) from handling the arrows too.
|
|
287
|
-
e.stopPropagation();
|
|
288
|
-
e.preventDefault();
|
|
289
|
-
};
|
|
290
|
-
// Remember the control focus came from, and return to it when focus comes back into the toolbar.
|
|
291
|
-
const onBlurCapture = (e) => {
|
|
292
|
-
if (!nodeContains(e.currentTarget, e.relatedTarget) && !lastFocused.current)
|
|
293
|
-
lastFocused.current = getEventTarget(e);
|
|
294
|
-
};
|
|
295
|
-
const onFocusCapture = (e) => {
|
|
296
|
-
const last = lastFocused.current;
|
|
297
|
-
if (last && !nodeContains(e.currentTarget, e.relatedTarget) && nodeContains(ref.current, getEventTarget(e))) {
|
|
298
|
-
lastFocused.current = null;
|
|
299
|
-
last.focus?.();
|
|
300
|
-
}
|
|
301
|
-
};
|
|
302
|
-
return {
|
|
303
|
-
toolbarProps: {
|
|
304
|
-
role: isInToolbar ? "group" : "toolbar",
|
|
305
|
-
"aria-orientation": "horizontal",
|
|
306
|
-
"data-orientation": "horizontal",
|
|
307
|
-
onKeyDownCapture: isInToolbar ? undefined : onKeyDownCapture,
|
|
308
|
-
onFocusCapture: isInToolbar ? undefined : onFocusCapture,
|
|
309
|
-
onBlurCapture: isInToolbar ? undefined : onBlurCapture,
|
|
310
|
-
},
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
/** Pushes the controls after it to the toolbar's end. */
|
|
314
|
-
export function ToolbarSpacer() {
|
|
315
|
-
return _jsx("span", { "aria-hidden": true, "data-slot": "toolbar-spacer", className: "flex-1" });
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Replaces the toolbar while rows are selected: the count, the bulk actions and a clear button, on
|
|
319
|
-
* `ds-background-neutral-bold`. One Tab stop with arrow keys inside, like the toolbar. Buttons in the bar
|
|
320
|
-
* are drawn transparent with inverse text whatever their variant: pass default (not primary) actions.
|
|
321
|
-
*/
|
|
322
|
-
export function BulkBar({ selectedCount, actions, onClear, "aria-label": label }) {
|
|
323
|
-
const { locale } = useLocale();
|
|
324
|
-
const count = selectedCountLabel(locale, selectedCount);
|
|
325
|
-
const [spoken, setSpoken] = React.useState("");
|
|
326
|
-
React.useEffect(() => setSpoken(count), [count]);
|
|
327
|
-
return (_jsxs(AriaToolbar, { "aria-label": label, "data-slot": "bulk-bar", className: "flex flex-wrap items-center gap-ds-150 rounded-ds-large bg-ds-background-neutral-bold px-ds-150 py-ds-100 text-ds-text-inverse " +
|
|
328
|
-
// Buttons read on the dark bar: transparent with inverse text, the neutral pressed step on hover.
|
|
329
|
-
"[&_[data-slot=button]]:bg-transparent [&_[data-slot=button]]:text-ds-text-inverse " +
|
|
330
|
-
"[&_[data-slot=button][data-hovered]]:bg-ds-background-neutral-pressed [&_[data-slot=button][data-hovered]]:text-ds-text " +
|
|
331
|
-
"[&_[data-slot=button][data-pressed]]:bg-ds-background-neutral-pressed [&_[data-slot=button][data-pressed]]:text-ds-text " +
|
|
332
|
-
"[&_[data-slot=button][data-focus-visible]]:inset-ring-ds-text-inverse", children: [_jsx("span", { "data-slot": "bulk-bar-count", "aria-hidden": true, className: "text-body-strong tabular-nums", children: count }), _jsx("span", { "data-slot": "bulk-bar-announcer", role: "status", className: "sr-only", children: spoken }), actions, _jsx("span", { "aria-hidden": true, className: "flex-1" }), _jsx(Button, { size: "small", iconOnly: true, iconBefore: "x", "aria-label": clearSelectionLabel(locale), onPress: onClear })] }));
|
|
333
|
-
}
|
|
334
|
-
//# sourceMappingURL=toolbar.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toolbar.js","sourceRoot":"","sources":["../../src/navigation/toolbar.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAE1E,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AASlE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,OAAO,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAgB;IACrE,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAiB,IAAI,CAAC,CAAC;IAC/C,MAAM,EAAE,YAAY,EAAE,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;IAC7C,OAAO,CACL,cACE,GAAG,EAAE,GAAG,eACE,SAAS,EACnB,SAAS,EAAC,mHAAmH,cACpH,EAAE,gBACC,KAAK,KACb,YAAY,YAEf,QAA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KACF,CAAC;AACJ,CAAC;AAED,yDAAyD;AACzD,MAAM,UAAU,aAAa;IAC3B,OAAO,iDAA4B,gBAAgB,EAAC,SAAS,EAAC,QAAQ,GAAG,CAAC;AAC5E,CAAC;AAaD;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAgB;IAC5F,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,CAAC;IAC/B,MAAM,KAAK,GAAG,kBAAkB,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACxD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC/C,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IACjD,OAAO,CACL,MAAC,WAAW,kBACE,KAAK,eACP,UAAU,EACpB,SAAS,EACP,iIAAiI;YACjI,kGAAkG;YAClG,oFAAoF;YACpF,0HAA0H;YAC1H,0HAA0H;YAC1H,uEAAuE,aAGzE,4BAAgB,gBAAgB,uBAAa,SAAS,EAAC,+BAA+B,YACnF,KAAK,GACD,EAGP,4BAAgB,oBAAoB,EAAC,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,SAAS,YACnE,MAAM,GACF,EACN,OAAO,EACR,oCAAkB,SAAS,EAAC,QAAQ,GAAG,EACvC,KAAC,MAAM,IAAC,IAAI,EAAC,OAAO,EAAC,QAAQ,QAAC,UAAU,EAAC,GAAG,gBAAa,mBAAmB,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,OAAO,GAAI,IAC9F,CACf,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { Toolbar as AriaToolbar, useLocale } from \"react-aria-components\";\n\nimport { Button } from \"../action/button\";\nimport { clearSelectionLabel, selectedCountLabel } from \"../i18n\";\n\nexport type ToolbarProps = {\n /** Compact (32px) controls acting on the view below: search, filters, date range, view switch, export. */\n children: React.ReactNode;\n /** Names the toolbar (\"Order tools\"). */\n \"aria-label\": string;\n};\n\n/**\n * Controls that act on the view below it. One Tab stop: arrow keys move between the controls (mirrored\n * in RTL). Put a `ToolbarSpacer` before the view and export controls to push them to the end.\n * A text-editing control inside (a SearchField's input, a DateField's segments) keeps ←/→ for its caret\n * and segments; at its edge (the caret at the start or end, the first or last segment) the arrow moves on\n * to the next control, so every control stays reachable by the arrows. Arrowing into a date or time field\n * lands on the segment nearest the way in: in RTL the visually nearest one, whatever the DOM order of its\n * segments. A raw `type=\"number\"` or\n * `type=\"email\"` input with a value has no readable caret and keeps ←/→ (Tab leaves it); prefer NumberField,\n * or TextField with `inputMode`, inside a toolbar.\n */\nexport function Toolbar({ children, \"aria-label\": label }: ToolbarProps) {\n const ref = React.useRef<HTMLDivElement>(null);\n const { toolbarProps } = useToolbarKeys(ref);\n return (\n <div\n ref={ref}\n data-slot=\"toolbar\"\n className=\"flex flex-wrap items-center gap-ds-100 rounded-ds-large bg-ds-surface-raised px-ds-150 py-ds-100 shadow-ds-raised\"\n data-rac=\"\"\n aria-label={label}\n {...toolbarProps}\n >\n {children}\n </div>\n );\n}\n\n/*\n * React Aria's Toolbar (react-aria-components) handles ←/→ in a capture listener on the toolbar and\n * takes no key handler of its own, so it cannot leave the arrows to a text control inside it. This\n * mirrors its useToolbar (horizontal): same role, arrows mirrored in RTL, no wrap, Tab leaving via the\n * first/last control, focus restored on return. The one change: ←/→ on a text-editing target belong\n * to that target until the caret or segment focus is at the target's edge in the arrow's direction.\n */\n\n// React Aria's focusable-element selector (isFocusable), so the arrows reach the same controls.\nconst FOCUSABLE = [\n \"input:not([disabled]):not([type=hidden])\",\n \"select:not([disabled])\",\n \"textarea:not([disabled])\",\n \"button:not([disabled])\",\n \"a[href]\",\n \"area[href]\",\n \"summary\",\n \"iframe\",\n \"object\",\n \"embed\",\n \"audio[controls]\",\n \"video[controls]\",\n '[contenteditable]:not([contenteditable^=\"false\"])',\n \"permission\",\n]\n .map((selector) => `${selector}:not([hidden])`)\n .concat(\"[tabindex]:not([disabled]):not([hidden])\")\n .join(\",\");\n\n/*\n * React Aria's shadow-DOM-aware helpers (getActiveElement, nodeContains, getEventTarget in\n * react-aria/private/utils/shadowdom) are not part of the public react-aria-components surface, and\n * react-aria itself is not a dependency of this package, so they are mirrored here. React Aria only\n * walks shadow roots when its shadowDOM flag is on; in the light DOM (the flag's default) these give\n * exactly document.activeElement, Node.contains and event.target, as React Aria does.\n */\nfunction getActiveElement(doc: Document = document): Element | null {\n let active = doc.activeElement;\n while (active?.shadowRoot?.activeElement) active = active.shadowRoot.activeElement;\n return active;\n}\n\nfunction nodeContains(node: Node | null | undefined, other: Node | null | undefined): boolean {\n if (!node || !other) return false;\n for (let current: Node | null = other; current; ) {\n if (current === node) return true;\n const slot: HTMLSlotElement | null | undefined = (current as Element).assignedSlot;\n // A slotted element continues from its slot (a slot itself walks up as usual).\n if (typeof (current as HTMLSlotElement).assignedElements !== \"function\" && slot?.parentNode) current = slot.parentNode;\n else if (current instanceof ShadowRoot) current = current.host;\n else current = current.parentNode;\n }\n return false;\n}\n\nfunction getEventTarget(e: React.SyntheticEvent): Element {\n const target = e.target as Element;\n if (target instanceof Element && target.shadowRoot) {\n const inner = e.nativeEvent.composedPath?.()[0];\n if (inner instanceof Element) return inner;\n }\n return target;\n}\n\n// Inputs that do not use ←/→ themselves: the toolbar always takes the arrows from them.\nconst ARROWLESS_INPUTS = new Set([\"button\", \"submit\", \"reset\", \"checkbox\", \"image\", \"file\", \"color\"]);\n/*\n * Inputs whose value ←/→ change, so the arrows always stay with them: React Aria's RadioGroup moves the\n * selection between its radios and its Slider moves the thumb with ←/→ (no caret, so no edge).\n */\nconst VALUE_ARROW_INPUTS = new Set([\"radio\", \"range\"]);\n\nfunction isRtl(element: Element, fallback: \"ltr\" | \"rtl\") {\n const computed = getComputedStyle(element).direction;\n if (computed === \"rtl\" || computed === \"ltr\") return computed === \"rtl\";\n // jsdom resolves no `direction`; :dir() reads the dir attribute the same way the browser does.\n try {\n return element.matches(\":dir(rtl)\");\n } catch {\n return fallback === \"rtl\";\n }\n}\n\n/**\n * The segment group (`role=\"group\"`) of a date/time segment inside the toolbar, else undefined. Only\n * segments step from their group: a text input is one element, and its group (the field frame) also holds\n * controls of its own (a SearchField's clear button, InputActions) that the arrows should still reach.\n */\nfunction segmentGroup(target: Element, toolbar: Element): Element | undefined {\n if (target.getAttribute(\"role\") !== \"spinbutton\") return undefined;\n const group = target.closest('[role=\"group\"]');\n return group && group !== toolbar && toolbar.contains(group) ? group : undefined;\n}\n\nfunction isTabbable(element: HTMLElement) {\n return element.tabIndex >= 0;\n}\n\n/**\n * True when the arrow key belongs to the target: a caret that can still move that way in a text input or\n * textarea, a date/time segment with another segment that way, a radio or slider, or a contenteditable\n * or textbox whose caret the toolbar cannot read. A non-collapsed selection always stays with the field.\n * `direction` is the toolbar's (the locale's), as React Aria's date segments use it.\n */\nfunction keepsArrows(target: Element, key: \"ArrowLeft\" | \"ArrowRight\", direction: \"ltr\" | \"rtl\") {\n const tag = target.tagName;\n if (tag === \"INPUT\" || tag === \"TEXTAREA\") {\n const field = target as HTMLInputElement | HTMLTextAreaElement;\n if (tag === \"INPUT\" && ARROWLESS_INPUTS.has(field.type)) return false;\n if (tag === \"INPUT\" && VALUE_ARROW_INPUTS.has(field.type)) return true;\n let start: number | null;\n let end: number | null;\n try {\n start = field.selectionStart;\n end = field.selectionEnd;\n } catch {\n start = end = null;\n }\n /*\n * number, email…: the browser exposes no caret (selectionStart is null), so the toolbar cannot tell\n * an edge. Empty, there is no caret to move and the arrows move on; with a value the field keeps them,\n * since taking them would leave no way to move the caret. Tab leaves such a field. The DS's own\n * fields avoid this: NumberField is a text input, and TextField takes `inputMode` for e-mail.\n */\n if (start == null || end == null) return field.value !== \"\";\n if (start !== end) return true;\n // The caret's back key is ← in an LTR field and → in an RTL one: the field's own direction.\n const back = isRtl(field, direction) ? key === \"ArrowRight\" : key === \"ArrowLeft\";\n return back ? start > 0 : end < field.value.length;\n }\n const role = target.getAttribute(\"role\");\n if (role === \"spinbutton\") {\n const group = target.closest('[role=\"group\"]');\n if (group) return hasSegmentToward(group, target as HTMLElement, key, direction);\n return true;\n }\n if (role === \"textbox\" || role === \"searchbox\") return true;\n return target.closest('[contenteditable]:not([contenteditable^=\"false\"])') != null;\n}\n\n/**\n * Whether React Aria's date/time field would move to another segment for this arrow (useDatePickerGroup):\n * in LTR the previous/next tabbable segment in DOM order; in RTL the nearest segment visually to that\n * side (its bounding box), since RTL date and time segments are not laid out in DOM order.\n */\nfunction hasSegmentToward(group: Element, segment: HTMLElement, key: \"ArrowLeft\" | \"ArrowRight\", direction: \"ltr\" | \"rtl\") {\n const segments = Array.from(group.querySelectorAll<HTMLElement>(FOCUSABLE)).filter(\n (element) => isTabbable(element) && isVisible(element),\n );\n if (direction === \"rtl\") {\n const from = segment.getBoundingClientRect().x;\n const sign = key === \"ArrowRight\" ? 1 : -1;\n return segments.some((element) => element !== segment && Math.sign(element.getBoundingClientRect().x - from) === sign);\n }\n const index = segments.indexOf(segment);\n if (index === -1) return true;\n return key === \"ArrowLeft\" ? index > 0 : index < segments.length - 1;\n}\n\n/**\n * In RTL, the segment an arrow should land on when it moves INTO a date/time field: the one\n * visually nearest the side focus enters from, by bounding box as `hasSegmentToward` reads it, since RTL\n * segments need not be laid out in DOM order. A step toward the toolbar's end (`step` 1, ← in RTL) enters\n * at the field's start side, the segment furthest toward the start; a step toward the start enters at its\n * end side. Any other target, or segments without a layout (equal boxes), keep the DOM-order choice.\n */\nfunction entrySegment(next: HTMLElement, toolbar: Element, step: 1 | -1): HTMLElement {\n const group = segmentGroup(next, toolbar);\n if (!group) return next;\n const segments = Array.from(group.querySelectorAll<HTMLElement>(FOCUSABLE)).filter(\n (element) => isTabbable(element) && isVisible(element),\n );\n // In RTL the start side is the larger x: a step of 1 enters the field at its start side (largest x), -1 at its end side.\n const enterAtStartSide = step === 1;\n let best = next;\n let bestX = next.getBoundingClientRect().x;\n for (const element of segments) {\n const x = element.getBoundingClientRect().x;\n if (enterAtStartSide ? x > bestX : x < bestX) {\n best = element;\n bestX = x;\n }\n }\n return best;\n}\n\nfunction isVisible(element: Element): boolean {\n if (typeof element.checkVisibility === \"function\") {\n return element.checkVisibility({ visibilityProperty: true }) && !element.closest(\"[data-react-aria-prevent-focus]\");\n }\n for (let node: Element | null = element; node; node = node.parentElement) {\n if (node.hasAttribute(\"hidden\") || node.hasAttribute(\"data-react-aria-prevent-focus\")) return false;\n const { display, visibility } = getComputedStyle(node);\n if (display === \"none\" || visibility === \"hidden\" || visibility === \"collapse\") return false;\n }\n return true;\n}\n\nfunction focusables(root: HTMLElement) {\n return Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE)).filter(\n (element) => !element.closest(\"[inert]\") && isVisible(element),\n );\n}\n\nfunction useToolbarKeys(ref: React.RefObject<HTMLDivElement | null>) {\n const { direction } = useLocale();\n const [isInToolbar, setInToolbar] = React.useState(false);\n React.useLayoutEffect(() => {\n setInToolbar(!!ref.current?.parentElement?.closest('[role=\"toolbar\"]'));\n });\n const lastFocused = React.useRef<Element | null>(null);\n\n /*\n * Moves to the next/previous control in DOM order from `from` (the focused element by default). `from` is\n * a whole segment group when the arrow leaves a date/time field: the step starts after (or before) the\n * group, never at a sibling segment, since in RTL the visual edge segment need not be the DOM-order edge\n * (an `ar` TimeField or a `he-IL` date keeps DOM order; an `ar` date is reversed). Arrowing INTO such a\n * field in RTL lands on its segment visually nearest the way in (`entrySegment`); LTR keeps DOM order.\n * Plain focus(), as React Aria's focus manager does: the control scrolls into view.\n */\n const move = (step: 1 | -1, from?: Element) => {\n const root = ref.current;\n if (!root) return;\n const all = focusables(root);\n const active = from ?? getActiveElement();\n let next: HTMLElement | undefined;\n if (!active || !nodeContains(root, active)) next = step === 1 ? all[0] : all[all.length - 1];\n else if (step === 1) {\n // FOLLOWING includes the group's own descendants: skip them.\n next = all.find((el) => active.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_FOLLOWING && !active.contains(el));\n } else next = all.filter((el) => active.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_PRECEDING).pop();\n // Into a date/time field in RTL: the segment nearest the side the arrow enters from, not the DOM-first one.\n if (next && direction === \"rtl\") next = entrySegment(next, root, step);\n next?.focus();\n };\n const edge = (end: \"first\" | \"last\") => {\n const all = ref.current ? focusables(ref.current) : [];\n (end === \"first\" ? all[0] : all[all.length - 1])?.focus();\n };\n\n const onKeyDownCapture = (e: React.KeyboardEvent<HTMLDivElement>) => {\n const target = getEventTarget(e);\n // Portalled content (a popover opened from a control) is not the toolbar's.\n if (!nodeContains(e.currentTarget, target)) return;\n if (e.key === \"ArrowRight\" || e.key === \"ArrowLeft\") {\n if (keepsArrows(target, e.key, direction)) return;\n const forward = e.key === \"ArrowRight\" ? 1 : -1;\n move(direction === \"rtl\" ? (-forward as 1 | -1) : forward, segmentGroup(target, e.currentTarget));\n } else if (e.key === \"Tab\") {\n // Focus the first/last control and let the browser's Tab carry focus out from there.\n lastFocused.current = getActiveElement();\n edge(e.shiftKey ? \"first\" : \"last\");\n return;\n } else return;\n // Keep nested action groups (and the field the arrow moved out of) from handling the arrows too.\n e.stopPropagation();\n e.preventDefault();\n };\n // Remember the control focus came from, and return to it when focus comes back into the toolbar.\n const onBlurCapture = (e: React.FocusEvent<HTMLDivElement>) => {\n if (!nodeContains(e.currentTarget, e.relatedTarget) && !lastFocused.current) lastFocused.current = getEventTarget(e);\n };\n const onFocusCapture = (e: React.FocusEvent<HTMLDivElement>) => {\n const last = lastFocused.current;\n if (last && !nodeContains(e.currentTarget, e.relatedTarget) && nodeContains(ref.current, getEventTarget(e))) {\n lastFocused.current = null;\n (last as HTMLElement).focus?.();\n }\n };\n\n return {\n toolbarProps: {\n role: isInToolbar ? \"group\" : \"toolbar\",\n \"aria-orientation\": \"horizontal\" as const,\n \"data-orientation\": \"horizontal\",\n onKeyDownCapture: isInToolbar ? undefined : onKeyDownCapture,\n onFocusCapture: isInToolbar ? undefined : onFocusCapture,\n onBlurCapture: isInToolbar ? undefined : onBlurCapture,\n },\n };\n}\n\n/** Pushes the controls after it to the toolbar's end. */\nexport function ToolbarSpacer() {\n return <span aria-hidden data-slot=\"toolbar-spacer\" className=\"flex-1\" />;\n}\n\nexport type BulkBarProps = {\n /** How many rows are selected; announced as it changes. */\n selectedCount: number;\n /** The bulk actions (compact Buttons): \"Send reminder\", \"Export\". */\n actions: React.ReactNode;\n /** Clears the selection; the bar goes with it. */\n onClear: () => void;\n /** Names the bar (\"Selected orders\"). */\n \"aria-label\": string;\n};\n\n/**\n * Replaces the toolbar while rows are selected: the count, the bulk actions and a clear button, on\n * `ds-background-neutral-bold`. One Tab stop with arrow keys inside, like the toolbar. Buttons in the bar\n * are drawn transparent with inverse text whatever their variant: pass default (not primary) actions.\n */\nexport function BulkBar({ selectedCount, actions, onClear, \"aria-label\": label }: BulkBarProps) {\n const { locale } = useLocale();\n const count = selectedCountLabel(locale, selectedCount);\n const [spoken, setSpoken] = React.useState(\"\");\n React.useEffect(() => setSpoken(count), [count]);\n return (\n <AriaToolbar\n aria-label={label}\n data-slot=\"bulk-bar\"\n className={\n \"flex flex-wrap items-center gap-ds-150 rounded-ds-large bg-ds-background-neutral-bold px-ds-150 py-ds-100 text-ds-text-inverse \" +\n // Buttons read on the dark bar: transparent with inverse text, the neutral pressed step on hover.\n \"[&_[data-slot=button]]:bg-transparent [&_[data-slot=button]]:text-ds-text-inverse \" +\n \"[&_[data-slot=button][data-hovered]]:bg-ds-background-neutral-pressed [&_[data-slot=button][data-hovered]]:text-ds-text \" +\n \"[&_[data-slot=button][data-pressed]]:bg-ds-background-neutral-pressed [&_[data-slot=button][data-pressed]]:text-ds-text \" +\n \"[&_[data-slot=button][data-focus-visible]]:inset-ring-ds-text-inverse\"\n }\n >\n <span data-slot=\"bulk-bar-count\" aria-hidden className=\"text-body-strong tabular-nums\">\n {count}\n </span>\n {/* Mounted empty and filled after mount: a live region born with its text is usually not read, so the\n first count (0 → 1, the bar appearing) would go unannounced. */}\n <span data-slot=\"bulk-bar-announcer\" role=\"status\" className=\"sr-only\">\n {spoken}\n </span>\n {actions}\n <span aria-hidden className=\"flex-1\" />\n <Button size=\"small\" iconOnly iconBefore=\"x\" aria-label={clearSelectionLabel(locale)} onPress={onClear} />\n </AriaToolbar>\n );\n}\n"]}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { type IconName } from "../display/icon.js";
|
|
3
|
-
import { type LozengeTone } from "../display/lozenge.js";
|
|
4
|
-
export type CommandItem = {
|
|
5
|
-
id: string;
|
|
6
|
-
/** "Pro plan", "Create order". */
|
|
7
|
-
label: string;
|
|
8
|
-
/** Beside the label in mono: a code, an order number ("ORD-482"). */
|
|
9
|
-
detail?: string;
|
|
10
|
-
icon?: IconName;
|
|
11
|
-
/** A record's status ("Available", success). */
|
|
12
|
-
status?: {
|
|
13
|
-
label: string;
|
|
14
|
-
tone: LozengeTone;
|
|
15
|
-
};
|
|
16
|
-
/** An action's shortcut ("N"). */
|
|
17
|
-
shortcut?: string;
|
|
18
|
-
/** Extra words it is found by (a customer's phone number, an old name). */
|
|
19
|
-
keywords?: readonly string[];
|
|
20
|
-
/** Records come first, then actions, then pages; "action" items fill the "most used" list. */
|
|
21
|
-
kind?: "record" | "action" | "page";
|
|
22
|
-
};
|
|
23
|
-
export type CommandGroup = {
|
|
24
|
-
id: string;
|
|
25
|
-
title: string;
|
|
26
|
-
items: readonly CommandItem[];
|
|
27
|
-
};
|
|
28
|
-
export type CommandPaletteProps = {
|
|
29
|
-
isOpen?: boolean;
|
|
30
|
-
defaultOpen?: boolean;
|
|
31
|
-
onOpenChange?: (isOpen: boolean) => void;
|
|
32
|
-
/** Actions and pages, most used first; matched here, diacritic-insensitive. */
|
|
33
|
-
groups: readonly CommandGroup[];
|
|
34
|
-
/** Records found by the server (codes, order numbers, names, phones); shown before the groups. */
|
|
35
|
-
search?: (query: string, signal: AbortSignal) => Promise<readonly CommandGroup[]>;
|
|
36
|
-
/** Shown while the query is empty, above the five most used actions. */
|
|
37
|
-
recent?: readonly CommandItem[];
|
|
38
|
-
onSelect: (item: CommandItem) => void;
|
|
39
|
-
/** Bind ⌘K / Ctrl K to open and close it. */
|
|
40
|
-
shortcut?: boolean;
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* ⌘K / Ctrl K: find any record and run any action from the keyboard. 560px in the top third over the
|
|
44
|
-
* blanket; one field, results grouped (records, then actions, then pages), 40px rows, the active row on
|
|
45
|
-
* ds-background-selected, records with their status. Empty, it shows recent records and the five most used
|
|
46
|
-
* actions. Typing matches labels, codes and keywords without regard to case or accents ("durovic" finds
|
|
47
|
-
* "Đurović"), and asks `search` for records (the last answer stays while the next loads; a failed search says
|
|
48
|
-
* so). Arrows move, Enter opens, Esc closes and returns focus. Rows are keyed by group and id, so ids may repeat
|
|
49
|
-
* across groups. When records arrive after the actions, the active row stays where it was (React Aria's
|
|
50
|
-
* Autocomplete keeps its virtual focus); arrows reach the records first in the list.
|
|
51
|
-
* Everything here must also be reachable through visible UI.
|
|
52
|
-
*/
|
|
53
|
-
export declare function CommandPalette({ isOpen, defaultOpen, onOpenChange, groups, search, recent, onSelect, shortcut }: CommandPaletteProps): React.JSX.Element;
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
import { Autocomplete, Dialog as AriaDialog, Header, Input, ListBox, ListBoxItem, ListBoxSection, Modal, ModalOverlay, SearchField, useLocale, } from "react-aria-components";
|
|
5
|
-
import { cn } from "../utils.js";
|
|
6
|
-
import { IconGlyph } from "../display/icon.js";
|
|
7
|
-
import { Kbd } from "../display/kbd.js";
|
|
8
|
-
import { Lozenge } from "../display/lozenge.js";
|
|
9
|
-
import { actionFailedLabel, commandHints, commandPaletteLabel, commandSearchLabel, frequentActionsLabel, loadingLabel, noMatchLabel, recentRecordsLabel } from "../i18n.js";
|
|
10
|
-
import { Highlight, matchesQuery } from "../selection/match.js";
|
|
11
|
-
const SEARCH_DELAY = 150;
|
|
12
|
-
/** Records first, then actions, then pages; a group ranks by its highest kind; equal groups keep their order. */
|
|
13
|
-
function byKind(groups) {
|
|
14
|
-
const order = { record: 0, action: 1, page: 2 };
|
|
15
|
-
const rank = (group) => Math.min(...group.items.map((item) => order[item.kind ?? "action"]));
|
|
16
|
-
return [...groups].sort((a, b) => rank(a) - rank(b));
|
|
17
|
-
}
|
|
18
|
-
/** The server's results for a query, debounced and cancelled when the query moves on. */
|
|
19
|
-
function useSearch(query, search) {
|
|
20
|
-
const [state, setState] = React.useState({
|
|
21
|
-
query: "", groups: [], loading: false, failed: false,
|
|
22
|
-
});
|
|
23
|
-
React.useEffect(() => {
|
|
24
|
-
if (!search || !query.trim()) {
|
|
25
|
-
setState({ query, groups: [], loading: false, failed: false });
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const controller = new AbortController();
|
|
29
|
-
// The last answer stays (filtered by the caller) while the next one loads, so records do not flicker away.
|
|
30
|
-
setState((current) => ({ ...current, loading: true, failed: false }));
|
|
31
|
-
const timer = setTimeout(() => {
|
|
32
|
-
search(query, controller.signal).then((groups) => !controller.signal.aborted && setState({ query, groups, loading: false, failed: false }), () => !controller.signal.aborted && setState({ query, groups: [], loading: false, failed: true }));
|
|
33
|
-
}, SEARCH_DELAY);
|
|
34
|
-
return () => {
|
|
35
|
-
clearTimeout(timer);
|
|
36
|
-
controller.abort();
|
|
37
|
-
};
|
|
38
|
-
}, [query, search]);
|
|
39
|
-
return state;
|
|
40
|
-
}
|
|
41
|
-
/** A row's key: group and item, since ids repeat across groups (a product and an order both "12"). */
|
|
42
|
-
const rowKey = (group, item) => `${group.id}\u0000${item.id}`;
|
|
43
|
-
function Row({ item, query, rowId }) {
|
|
44
|
-
return (_jsxs(ListBoxItem, { id: rowId, textValue: item.detail ? `${item.label} ${item.detail}` : item.label, "data-slot": "command-item", "data-kind": item.kind, className: "flex min-h-10 cursor-default items-center gap-ds-150 rounded-ds-medium px-ds-150 text-body text-ds-text outline-hidden data-[focused]:bg-ds-background-selected data-[hovered]:bg-ds-background-neutral-subtle-hovered data-[focused]:data-[hovered]:bg-ds-background-selected", children: [item.icon && _jsx(IconGlyph, { name: item.icon, size: "small", "data-slot": "command-item-icon", className: "text-ds-icon-subtle" }), _jsxs("span", { "data-slot": "command-item-label", className: "min-w-0 flex-1 truncate", children: [_jsx(Highlight, { text: item.label, query: query }), item.detail && (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": true, children: " \u00B7 " }), _jsx("bdi", { "data-slot": "command-item-detail", className: "font-ds-mono text-code text-ds-text-subtle", children: _jsx(Highlight, { text: item.detail, query: query }) })] }))] }), item.status && _jsx(Lozenge, { tone: item.status.tone, children: item.status.label }), item.shortcut && _jsx(Kbd, { children: item.shortcut })] }));
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* ⌘K / Ctrl K: find any record and run any action from the keyboard. 560px in the top third over the
|
|
48
|
-
* blanket; one field, results grouped (records, then actions, then pages), 40px rows, the active row on
|
|
49
|
-
* ds-background-selected, records with their status. Empty, it shows recent records and the five most used
|
|
50
|
-
* actions. Typing matches labels, codes and keywords without regard to case or accents ("durovic" finds
|
|
51
|
-
* "Đurović"), and asks `search` for records (the last answer stays while the next loads; a failed search says
|
|
52
|
-
* so). Arrows move, Enter opens, Esc closes and returns focus. Rows are keyed by group and id, so ids may repeat
|
|
53
|
-
* across groups. When records arrive after the actions, the active row stays where it was (React Aria's
|
|
54
|
-
* Autocomplete keeps its virtual focus); arrows reach the records first in the list.
|
|
55
|
-
* Everything here must also be reachable through visible UI.
|
|
56
|
-
*/
|
|
57
|
-
export function CommandPalette({ isOpen, defaultOpen, onOpenChange, groups, search, recent = [], onSelect, shortcut }) {
|
|
58
|
-
const { locale } = useLocale();
|
|
59
|
-
const [own, setOwn] = React.useState(defaultOpen ?? false);
|
|
60
|
-
const open = isOpen ?? own;
|
|
61
|
-
const setOpen = (next) => {
|
|
62
|
-
if (isOpen === undefined)
|
|
63
|
-
setOwn(next);
|
|
64
|
-
onOpenChange?.(next);
|
|
65
|
-
};
|
|
66
|
-
const latest = React.useRef({ open, setOpen });
|
|
67
|
-
latest.current = { open, setOpen };
|
|
68
|
-
React.useEffect(() => {
|
|
69
|
-
if (!shortcut)
|
|
70
|
-
return;
|
|
71
|
-
// ⌘K on Apple platforms (Ctrl K there is "delete to end of line" in every field), Ctrl K elsewhere. The
|
|
72
|
-
// physical key counts too, for Cyrillic and Greek layouts; a key an editor already handled is left alone.
|
|
73
|
-
const apple = /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent);
|
|
74
|
-
const listener = (event) => {
|
|
75
|
-
if (event.defaultPrevented || event.isComposing || event.repeat || event.altKey || event.shiftKey)
|
|
76
|
-
return;
|
|
77
|
-
const modifier = apple ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey;
|
|
78
|
-
if (modifier && (event.key.toLowerCase() === "k" || event.code === "KeyK")) {
|
|
79
|
-
event.preventDefault();
|
|
80
|
-
latest.current.setOpen(!latest.current.open);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
document.addEventListener("keydown", listener);
|
|
84
|
-
return () => document.removeEventListener("keydown", listener);
|
|
85
|
-
}, [shortcut]);
|
|
86
|
-
const [query, setQuery] = React.useState("");
|
|
87
|
-
// A new opening starts from an empty query.
|
|
88
|
-
const [wasOpen, setWasOpen] = React.useState(open);
|
|
89
|
-
if (wasOpen !== open) {
|
|
90
|
-
setWasOpen(open);
|
|
91
|
-
if (open)
|
|
92
|
-
setQuery("");
|
|
93
|
-
}
|
|
94
|
-
const remote = useSearch(query, search);
|
|
95
|
-
const empty = !query.trim();
|
|
96
|
-
const shown = React.useMemo(() => {
|
|
97
|
-
if (empty) {
|
|
98
|
-
const actions = groups.flatMap((group) => group.items).filter((item) => (item.kind ?? "action") === "action").slice(0, 5);
|
|
99
|
-
return [
|
|
100
|
-
...(recent.length ? [{ id: "__recent", title: recentRecordsLabel(locale), items: recent }] : []),
|
|
101
|
-
...(actions.length ? [{ id: "__frequent", title: frequentActionsLabel(locale), items: actions }] : []),
|
|
102
|
-
];
|
|
103
|
-
}
|
|
104
|
-
const local = groups
|
|
105
|
-
.map((group) => ({ ...group, items: group.items.filter((item) => matchesQuery(query, item.label, item.detail, ...(item.keywords ?? []))) }))
|
|
106
|
-
.filter((group) => group.items.length);
|
|
107
|
-
// The newest answer, or the previous one (still matching the query) while the next one loads.
|
|
108
|
-
const found = (remote.query === query ? remote.groups : remote.groups.map((group) => ({ ...group, items: group.items.filter((item) => matchesQuery(query, item.label, item.detail, ...(item.keywords ?? []))) })))
|
|
109
|
-
.filter((group) => group.items.length);
|
|
110
|
-
return byKind([...found, ...local]);
|
|
111
|
-
}, [empty, groups, recent, locale, query, remote]);
|
|
112
|
-
const items = React.useMemo(() => new Map(shown.flatMap((group) => group.items.map((item) => [rowKey(group, item), item]))), [shown]);
|
|
113
|
-
const hints = commandHints(locale);
|
|
114
|
-
return (_jsx(ModalOverlay, { isOpen: open, onOpenChange: setOpen, isDismissable: true, "data-slot": "command-palette-overlay", className: "fixed inset-0 z-50 flex items-start justify-center bg-ds-blanket px-ds-200 pt-[15dvh] transition-opacity duration-(--ds-duration-medium) data-[entering]:opacity-0 data-[exiting]:opacity-0 motion-reduce:transition-none", children: _jsx(Modal, { "data-slot": "command-palette", className: "flex max-h-[70dvh] w-full max-w-140 flex-col overflow-hidden rounded-ds-xlarge bg-ds-surface-overlay text-ds-text shadow-ds-overlay outline-hidden", children: _jsx(AriaDialog, { "aria-label": commandPaletteLabel(locale), "data-slot": "command-palette-dialog", className: "flex min-h-0 flex-1 flex-col outline-hidden", children: _jsxs("div", { className: "flex min-h-0 flex-1 flex-col",
|
|
115
|
-
// Esc closes at once, as the footer says (the search field would otherwise clear itself first).
|
|
116
|
-
onKeyDownCapture: (event) => {
|
|
117
|
-
if (event.key === "Escape" && !event.nativeEvent.isComposing) {
|
|
118
|
-
event.preventDefault();
|
|
119
|
-
event.stopPropagation();
|
|
120
|
-
setOpen(false);
|
|
121
|
-
}
|
|
122
|
-
}, children: [_jsxs(Autocomplete, { inputValue: query, onInputChange: setQuery, children: [_jsxs(SearchField, { "aria-label": commandSearchLabel(locale), autoFocus: true, "data-slot": "command-palette-search", className: "flex min-h-13 items-center gap-ds-150 border-b border-ds-border px-ds-200", children: [_jsx(IconGlyph, { name: "search", className: "size-5 shrink-0 text-ds-icon-subtle" }), _jsx(Input, { placeholder: commandSearchLabel(locale), "data-slot": "command-palette-input", className: "min-w-0 flex-1 bg-transparent text-body text-ds-text outline-hidden placeholder:text-ds-text-subtlest [&::-webkit-search-cancel-button]:hidden" }), _jsx(Kbd, { children: "Esc" })] }), _jsx(ListBox, { "aria-label": commandPaletteLabel(locale), "data-slot": "command-palette-results", onAction: (key) => {
|
|
123
|
-
const item = items.get(String(key));
|
|
124
|
-
if (!item)
|
|
125
|
-
return;
|
|
126
|
-
setOpen(false);
|
|
127
|
-
onSelect(item);
|
|
128
|
-
}, renderEmptyState: () => (_jsx("div", { "data-slot": "command-palette-empty", className: "px-ds-200 py-ds-300 text-center text-body text-ds-text-subtle", children: remote.loading ? loadingLabel(locale) : remote.failed ? actionFailedLabel(locale) : empty ? null : noMatchLabel(locale, query.trim()) })), className: "min-h-0 flex-1 overflow-y-auto p-ds-100 outline-hidden", children: shown.map((group) => (_jsxs(ListBoxSection, { id: group.id, "data-slot": "command-palette-group", className: "flex flex-col", children: [_jsx(Header, { "data-slot": "command-palette-group-title", className: "px-ds-150 pt-ds-150 pb-ds-050 text-heading-xxsmall text-ds-text-subtle", children: group.title }), group.items.map((item) => _jsx(Row, { rowId: rowKey(group, item), item: item, query: empty ? "" : query }, rowKey(group, item)))] }, group.id))) }), _jsx("span", { "aria-live": "polite", className: "sr-only", "data-slot": "command-palette-status", children: remote.loading ? loadingLabel(locale) : "" })] }), _jsxs("div", { "data-slot": "command-palette-footer", className: "flex flex-wrap items-center gap-ds-300 border-t border-ds-border bg-ds-surface-sunken px-ds-200 py-ds-100 text-body-small text-ds-text-subtle", children: [_jsxs("span", { className: "flex items-center gap-ds-050", children: [_jsx(Kbd, { children: "\u2191" }), _jsx(Kbd, { children: "\u2193" }), hints.move] }), _jsxs("span", { className: "flex items-center gap-ds-050", children: [_jsx(Kbd, { children: "\u21B5" }), hints.open] }), _jsxs("span", { className: "flex items-center gap-ds-050", children: [_jsx(Kbd, { children: "Esc" }), hints.close] })] })] }) }) }) }));
|
|
129
|
-
}
|
|
130
|
-
//# sourceMappingURL=command-palette.js.map
|