@sincpro/web-ui 2.13.0 → 2.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -6
- package/dist/components/gallery/Gallery.d.ts +29 -0
- package/dist/components/gallery/Gallery.js +78 -0
- package/dist/components/gallery/Lightbox.d.ts +28 -0
- package/dist/components/gallery/Lightbox.js +59 -0
- package/dist/components/gallery/index.d.ts +2 -0
- package/dist/components/gallery/index.js +3 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +2 -0
- package/dist/components/listing/ColumnsMenu.js +4 -2
- package/dist/components/listing/columns.d.ts +3 -0
- package/dist/components/listing/columns.js +4 -0
- package/dist/components/plans/PlanCard.d.ts +43 -0
- package/dist/components/plans/PlanCard.js +35 -0
- package/dist/components/plans/index.d.ts +1 -0
- package/dist/components/plans/index.js +2 -0
- package/dist/components/search/CriteriaChips.d.ts +14 -1
- package/dist/components/search/CriteriaChips.js +131 -14
- package/dist/components/search/JoinWord.js +8 -14
- package/dist/components/search/SearchBar.d.ts +10 -1
- package/dist/components/search/SearchBar.js +715 -176
- package/dist/components/search/WordChoice.d.ts +19 -0
- package/dist/components/search/WordChoice.js +8 -0
- package/dist/components/search/criteria.d.ts +47 -4
- package/dist/components/search/criteria.js +75 -2
- package/dist/components/search/index.d.ts +2 -2
- package/dist/components/search/index.js +2 -2
- package/dist/components/search/query.d.ts +24 -0
- package/dist/components/search/query.js +29 -0
- package/dist/components/shell/AppFrame.d.ts +4 -0
- package/dist/components/shell/AppFrame.js +4 -1
- package/dist/components/shell/Inbox.d.ts +53 -0
- package/dist/components/shell/Inbox.js +55 -0
- package/dist/components/shell/SearchEntry.js +2 -3
- package/dist/components/shell/TopBar.d.ts +4 -2
- package/dist/components/shell/TopBar.js +3 -3
- package/dist/components/shell/index.d.ts +1 -0
- package/dist/components/shell/index.js +3 -0
- package/dist/foundations/copy.es.js +60 -1
- package/dist/foundations/form.d.ts +7 -0
- package/dist/foundations/form.js +1 -0
- package/dist/foundations/uiCopy.d.ts +85 -2
- package/dist/foundations/uiCopy.js +60 -1
- package/dist/primitives/choice/RadioGroup.d.ts +1 -1
- package/dist/primitives/choice/RadioGroup.js +29 -0
- package/dist/primitives/choice/Rating.d.ts +32 -0
- package/dist/primitives/choice/Rating.js +75 -0
- package/dist/primitives/choice/Slider.d.ts +19 -0
- package/dist/primitives/choice/Slider.js +27 -2
- package/dist/primitives/choice/index.d.ts +2 -1
- package/dist/primitives/choice/index.js +4 -1
- package/dist/primitives/choice/options.d.ts +4 -0
- package/dist/primitives/field/Field.js +1 -0
- package/dist/primitives/hint/Kbd.d.ts +23 -0
- package/dist/primitives/hint/Kbd.js +23 -0
- package/dist/primitives/hint/index.d.ts +1 -0
- package/dist/primitives/hint/index.js +2 -0
- package/dist/primitives/menu/ContextMenu.d.ts +29 -0
- package/dist/primitives/menu/ContextMenu.js +74 -0
- package/dist/primitives/menu/Menu.d.ts +4 -1
- package/dist/primitives/menu/Menu.js +2 -2
- package/dist/primitives/menu/index.d.ts +1 -0
- package/dist/primitives/menu/index.js +2 -0
- package/dist/primitives/notice/Banner.d.ts +27 -0
- package/dist/primitives/notice/Banner.js +21 -0
- package/dist/primitives/notice/Callout.d.ts +4 -4
- package/dist/primitives/notice/Callout.js +8 -19
- package/dist/primitives/notice/Notice.d.ts +38 -10
- package/dist/primitives/notice/Notice.js +48 -9
- package/dist/primitives/notice/index.d.ts +3 -1
- package/dist/primitives/notice/index.js +3 -0
- package/dist/primitives/notice/tones.d.ts +8 -0
- package/dist/primitives/notice/tones.js +22 -0
- package/dist/primitives/table/DataTable.js +2 -1
- package/dist/primitives/table/index.d.ts +1 -0
- package/dist/primitives/table/index.js +1 -0
- package/dist/primitives/table/levels.d.ts +13 -0
- package/dist/primitives/table/levels.js +11 -0
- package/dist/primitives/value/Price.d.ts +31 -0
- package/dist/primitives/value/Price.js +32 -0
- package/dist/primitives/value/QrCode.d.ts +32 -0
- package/dist/primitives/value/QrCode.js +53 -0
- package/dist/primitives/value/index.d.ts +3 -0
- package/dist/primitives/value/index.js +6 -0
- package/dist/primitives/value/priceFormat.d.ts +12 -0
- package/dist/primitives/value/priceFormat.js +22 -0
- package/dist/tokens.css +39 -0
- package/dist/views/list/ListView.js +24 -4
- package/dist/views/list/derive.js +3 -2
- package/dist/views/list/types.d.ts +8 -0
- package/package.json +3 -2
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { useSearchSettings } from "./context.js";
|
|
4
|
-
import { at, criteriaId, filterCriteria, removeAt, replaceAt, } from "./criteria.js";
|
|
4
|
+
import { at, criteriaId, facetPaths, filterCriteria, removeAt, replaceAt, restoreRemoval, } from "./criteria.js";
|
|
5
5
|
import { CriteriaChips } from "./CriteriaChips.js";
|
|
6
|
-
import { choiceValues, conditionCriteria, fieldKey, opLabel, queryFields, readTyped, suggest, withValue, } from "./query.js";
|
|
6
|
+
import { chipParts, choiceValues, conditionCriteria, fieldKey, opLabel, queryFields, readTyped, suggest, valuesCriteria, withoutValue, withValue, } from "./query.js";
|
|
7
7
|
import { fillCopy, useUiCopy } from "../../foundations/copy.js";
|
|
8
|
+
import { keysLabel } from "../../foundations/keys.js";
|
|
9
|
+
import { useKeyboardPlatform } from "../../foundations/shortcut.js";
|
|
8
10
|
import { bySurface, useSurface } from "../../foundations/surface.js";
|
|
9
11
|
import { CheckMark } from "../../primitives/field/Checks.js";
|
|
12
|
+
import { Kbd } from "../../primitives/hint/Kbd.js";
|
|
13
|
+
import { useToastIfAny } from "../../primitives/notice/Toast.js";
|
|
10
14
|
import { MatchedText } from "../../primitives/picker/MatchedText.js";
|
|
11
15
|
import { Count } from "../../primitives/tag/Count.js";
|
|
12
16
|
import { chosenTone } from "../../primitives/tag/Tag.js";
|
|
13
17
|
import { Tags } from "../../primitives/tag/Tags.js";
|
|
14
|
-
import { CalendarDays, ChevronRight, CornerDownRight, Hash, Layers, Link2, List, ListFilter, Search, SlidersHorizontal, Star, ToggleLeft, Type, X, } from "lucide-react";
|
|
18
|
+
import { CalendarDays, ChevronRight, CornerDownRight, Hash, History, Layers, Link2, List, ListFilter, Search, SlidersHorizontal, Star, ToggleLeft, Type, Undo2, X, } from "lucide-react";
|
|
15
19
|
import { Fragment, useEffect, useId, useRef, useState } from "react";
|
|
16
20
|
import { mergeProps, Overlay, useOverlay, useOverlayPosition } from "react-aria";
|
|
17
21
|
/** What kind of field a row asks about, at a glance: its icon. */
|
|
@@ -26,9 +30,69 @@ const KIND_ICON = {
|
|
|
26
30
|
/** How long the bar waits for the typing to stop before searching records: every key would
|
|
27
31
|
* be a request, and the answer to «a», «an», «and» is thrown away anyway. */
|
|
28
32
|
const RECORDS_DELAY = 200;
|
|
33
|
+
/** How many searches the bar remembers. Five is what fits above the fields without pushing them
|
|
34
|
+
* out of sight, and past five a «recent» is a history nobody reads. */
|
|
35
|
+
const RECENT_MAX = 5;
|
|
36
|
+
/** A column of the panel longer than this gets a box to narrow it — and the keyboard a letter. */
|
|
37
|
+
const FIND_AFTER = 8;
|
|
38
|
+
/** Two words are the same for the eye whatever their case and accents: «Fecha» is «fecha». */
|
|
39
|
+
function fold(text) {
|
|
40
|
+
return text
|
|
41
|
+
.normalize("NFD")
|
|
42
|
+
.replace(/\p{Diacritic}/gu, "")
|
|
43
|
+
.toLowerCase();
|
|
44
|
+
}
|
|
45
|
+
/** A search remembered in the browser, read back only if it still has the shape of one. */
|
|
46
|
+
function recentFromStorage(raw) {
|
|
47
|
+
if (raw === null)
|
|
48
|
+
return [];
|
|
49
|
+
const parsed = JSON.parse(raw);
|
|
50
|
+
if (!Array.isArray(parsed))
|
|
51
|
+
return [];
|
|
52
|
+
return parsed
|
|
53
|
+
.filter((one) => typeof one === "object" &&
|
|
54
|
+
one !== null &&
|
|
55
|
+
one.kind === "filter" &&
|
|
56
|
+
typeof one.id === "string" &&
|
|
57
|
+
typeof one.label === "string")
|
|
58
|
+
.slice(0, RECENT_MAX);
|
|
59
|
+
}
|
|
60
|
+
/* «/» goes to the search — GitHub's key, Gmail's, Linear's. With several bars on screen (a
|
|
61
|
+
reconciliation's panes, a chooser over a list) the last mounted that is SEEN answers, the
|
|
62
|
+
way shortcuts stack. Its own listener and not `useShortcuts`: on a Spanish keyboard «/» is
|
|
63
|
+
Shift+7, and a combination there matches its modifiers exactly. */
|
|
64
|
+
const slashBars = [];
|
|
65
|
+
function typingIn(target) {
|
|
66
|
+
return (target instanceof HTMLElement &&
|
|
67
|
+
(target.isContentEditable ||
|
|
68
|
+
target.tagName === "INPUT" ||
|
|
69
|
+
target.tagName === "TEXTAREA" ||
|
|
70
|
+
target.tagName === "SELECT"));
|
|
71
|
+
}
|
|
72
|
+
function onSlash(event) {
|
|
73
|
+
if (event.key !== "/" ||
|
|
74
|
+
event.defaultPrevented ||
|
|
75
|
+
event.isComposing ||
|
|
76
|
+
event.ctrlKey ||
|
|
77
|
+
event.metaKey ||
|
|
78
|
+
event.altKey ||
|
|
79
|
+
typingIn(event.target))
|
|
80
|
+
return;
|
|
81
|
+
for (let at = slashBars.length - 1; at >= 0; at--) {
|
|
82
|
+
const field = slashBars[at].current;
|
|
83
|
+
/* Seen and not behind a modal: a bar under an open dialog is not where «/» should land. */
|
|
84
|
+
if (field !== null &&
|
|
85
|
+
field.getClientRects().length > 0 &&
|
|
86
|
+
field.closest("[aria-hidden='true'], [inert]") === null) {
|
|
87
|
+
event.preventDefault();
|
|
88
|
+
field.focus();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
29
93
|
/** A row the keyboard and the pointer stop on — every one but a status. */
|
|
30
94
|
function selectable(item) {
|
|
31
|
-
return item.kind !== "status";
|
|
95
|
+
return item.kind !== "status" && item.kind !== "heading";
|
|
32
96
|
}
|
|
33
97
|
/** A row that opens what is under it with → (or its ▸). */
|
|
34
98
|
function unfoldable(item) {
|
|
@@ -37,6 +101,12 @@ function unfoldable(item) {
|
|
|
37
101
|
const one = item.suggestion;
|
|
38
102
|
return one.kind === "unfold" || (one.kind === "condition" && one.unfolds === true);
|
|
39
103
|
}
|
|
104
|
+
/** The keys of the dropdown, each drawn as a key beside its word. */
|
|
105
|
+
function KeysHint({ keys }) {
|
|
106
|
+
return (_jsx("p", { "data-ui": "search.keys", className: "hidden flex-wrap items-center gap-x-3 gap-y-1 border-t border-line px-3 py-1.5 text-micro text-muted sm:flex", children: keys.map(([caps, word]) => (_jsxs("span", { className: "inline-flex items-center gap-1", children: [caps.map((cap) => (
|
|
107
|
+
/* The dropdown is paper even under a bar on the chrome: the context would say chrome. */
|
|
108
|
+
_jsx(Kbd, { surface: "canvas", children: cap }, cap))), _jsx("span", { children: word })] }, word))) }));
|
|
109
|
+
}
|
|
40
110
|
/**
|
|
41
111
|
* What one row of the dropdown says. The row around it —its role, its mark, what pressing it
|
|
42
112
|
* does— is the bar's; this is only its content, so every kind reads the same way:
|
|
@@ -59,6 +129,12 @@ function SuggestionRow({ item, open, onToggle, renderRecord, }) {
|
|
|
59
129
|
if (item.kind === "advanced") {
|
|
60
130
|
return (_jsxs("span", { className: "-mx-2 -my-1.5 flex w-full min-w-0 items-center gap-2 border-t border-line px-2 pt-2 pb-1.5 font-medium text-primary", children: [_jsx(SlidersHorizontal, { className: "size-(--size-icon-sm) shrink-0", strokeWidth: 2, "aria-hidden": true }), copy.search.advanced] }));
|
|
61
131
|
}
|
|
132
|
+
if (item.kind === "heading") {
|
|
133
|
+
return (_jsx("span", { className: "min-w-0 truncate text-micro font-medium text-muted", children: item.text }));
|
|
134
|
+
}
|
|
135
|
+
if (item.kind === "recent") {
|
|
136
|
+
return (_jsxs(_Fragment, { children: [_jsx(History, { className: "size-(--size-icon-sm) shrink-0 text-muted", strokeWidth: 2, "aria-hidden": true }), _jsx("span", { className: "min-w-0 flex-1 truncate text-ink", children: item.criteria.label })] }));
|
|
137
|
+
}
|
|
62
138
|
const one = item.suggestion;
|
|
63
139
|
/* A VALUE under its row: the record's name with what was typed marked —it says why it is
|
|
64
140
|
listed—, and what tells two of the same name apart on the right. */
|
|
@@ -83,14 +159,15 @@ function SuggestionRow({ item, open, onToggle, renderRecord, }) {
|
|
|
83
159
|
function Option({ o, checks, onSelect, }) {
|
|
84
160
|
const Icon = o.icon;
|
|
85
161
|
const toggles = checks || o.checked !== undefined;
|
|
86
|
-
return (_jsxs("button", { type: "button", disabled: o.disabled, onClick: () => onSelect?.(o.id), ...(toggles ? { "aria-pressed": o.checked === true } : {}), className: "flex w-full items-start gap-2 rounded-ui-option px-1.5 py-1 text-left transition-colors duration-(--duration-instant) disabled:pointer-events-none disabled:opacity-45 hover:bg-ui-option-active", children: [_jsx("span", { className: "mt-0.5 flex size-(--size-icon-sm) shrink-0 items-center justify-center", children: toggles ? (_jsx(CheckMark, { on: o.checked === true })) : Icon === undefined ? null : (_jsx(Icon, { className: "size-(--size-icon-sm) text-muted", strokeWidth: 2, "aria-hidden": true })) }), _jsxs("span", { className: "min-w-0 flex-1", children: [_jsxs("span", { className: "flex items-center gap-1.5", children: [_jsx("span", { className: `truncate text-meta ${o.checked === true ? "font-medium text-ink" : "text-ink"}`, children: o.label }), o.badge === undefined ? null : (_jsx("span", { className: "inline-flex shrink-0 items-center rounded-pill border border-warn/30 bg-warn/10 px-2 py-0.5 text-micro text-warn", children: o.badge }))] }), o.hint === undefined ? null : (_jsx("span", { className: "mt-0.5
|
|
162
|
+
return (_jsxs("button", { type: "button", disabled: o.disabled, onClick: () => onSelect?.(o.id), ...(toggles ? { "aria-pressed": o.checked === true } : {}), className: "flex w-full items-start gap-2 rounded-ui-option px-1.5 py-1 text-left transition-colors duration-(--duration-instant) disabled:pointer-events-none disabled:opacity-45 hover:bg-ui-option-active", children: [_jsx("span", { className: "mt-0.5 flex size-(--size-icon-sm) shrink-0 items-center justify-center", children: toggles ? (_jsx(CheckMark, { on: o.checked === true })) : Icon === undefined ? null : (_jsx(Icon, { className: "size-(--size-icon-sm) text-muted", strokeWidth: 2, "aria-hidden": true })) }), _jsxs("span", { className: "min-w-0 flex-1", children: [_jsxs("span", { className: "flex items-center gap-1.5", children: [_jsx("span", { className: `truncate text-meta ${o.checked === true ? "font-medium text-ink" : "text-ink"}`, children: o.label }), o.badge === undefined ? null : (_jsx("span", { className: "inline-flex shrink-0 items-center rounded-pill border border-warn/30 bg-warn/10 px-2 py-0.5 text-micro text-warn", children: o.badge }))] }), o.hint === undefined ? null : (_jsx("span", { className: "mt-0.5 line-clamp-2 text-micro text-muted", title: o.hint, children: o.hint }))] })] }));
|
|
87
163
|
}
|
|
88
164
|
/** A panel group. Collapsible when it asks —a date, which brings eleven
|
|
89
165
|
* options— and open from the start if it already has something ticked: otherwise what is set
|
|
90
166
|
* stays hidden behind a chevron and you have to guess where it is. */
|
|
91
|
-
function Group({ group, first, checks, onSelect, }) {
|
|
167
|
+
function Group({ group, first, checks, onSelect, forceOpen = false, }) {
|
|
92
168
|
const active = group.options.some((o) => o.checked === true);
|
|
93
|
-
const [
|
|
169
|
+
const [unfolded, setOpen] = useState(active);
|
|
170
|
+
const open = unfolded || forceOpen;
|
|
94
171
|
const options = (_jsx(_Fragment, { children: group.options.map((o) => (_jsxs(Fragment, { children: [o.divider === true ? _jsx("div", { className: "my-1 h-px bg-line", role: "separator" }) : null, _jsx(Option, { o: o, checks: checks, onSelect: onSelect })] }, o.id))) }));
|
|
95
172
|
return (_jsxs("div", { className: "flex flex-col gap-0.5", children: [first ? null : _jsx("div", { className: "my-1 h-px bg-line", role: "separator" }), group.label === undefined ? null : group.collapsible !== true ? (
|
|
96
173
|
/* The group's label goes in the TEXT column, not the edge one. The column's title
|
|
@@ -101,9 +178,11 @@ function Group({ group, first, checks, onSelect, }) {
|
|
|
101
178
|
? "flex flex-col gap-0.5 pl-(--spacing-indent)"
|
|
102
179
|
: "flex flex-col gap-0.5", children: options }))] }));
|
|
103
180
|
}
|
|
104
|
-
export function SearchBar({ facets, model, criteria, onCriteriaChange, placeholder, filters, grouping, onOpenGroup, favorites, onFilterSelect, onFavoriteSelect, onOpenBuilder, literal, searchRecords: ownSearchRecords, browseRecords: ownBrowseRecords, renderRecord, trailing, collapseAfter, surface, }) {
|
|
181
|
+
export function SearchBar({ facets, model, criteria, onCriteriaChange, placeholder, filters, grouping, onOpenGroup, favorites, onFilterSelect, onFavoriteSelect, onOpenBuilder, literal, searchRecords: ownSearchRecords, browseRecords: ownBrowseRecords, renderRecord, trailing, collapseAfter, recentKey, focusOnSlash = true, surface, }) {
|
|
105
182
|
const copy = useUiCopy();
|
|
106
183
|
const sup = useSurface(surface);
|
|
184
|
+
const platform = useKeyboardPlatform();
|
|
185
|
+
const toasts = useToastIfAny();
|
|
107
186
|
/* Its own, or the application's (`SearchProvider`): wired once for every bar. */
|
|
108
187
|
const { searchRecords, browseRecords } = useSearchSettings({
|
|
109
188
|
...(ownSearchRecords === undefined ? {} : { searchRecords: ownSearchRecords }),
|
|
@@ -111,10 +190,25 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
111
190
|
});
|
|
112
191
|
const [text, setText] = useState("");
|
|
113
192
|
const [panel, setPanel] = useState(false);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
193
|
+
/** The panel was opened from the keyboard (Alt+↓, or Enter on the funnel): its first option
|
|
194
|
+
* takes the focus, or the keys that opened it would have nothing to move through. */
|
|
195
|
+
const panelFromKeys = useRef(false);
|
|
196
|
+
/** What a long column of the panel is narrowed to, by the column's title. */
|
|
197
|
+
const [find, setFind] = useState({});
|
|
198
|
+
/** The focus is somewhere in the bar. What is offered closes when it leaves: a dropdown that
|
|
199
|
+
* stays open over the list after a click elsewhere covers what the person went to look at. */
|
|
200
|
+
const [focused, setFocused] = useState(false);
|
|
201
|
+
/** The empty bar offers — recent searches, the fields — once it takes the focus, and stops
|
|
202
|
+
* after something is set or Escape, until the next time it is entered or ↓ asks again. */
|
|
203
|
+
const [starter, setStarter] = useState(false);
|
|
204
|
+
/** The piece marked from the keyboard, by its place in `facetPaths`. */
|
|
205
|
+
const [marked, setMarked] = useState(null);
|
|
206
|
+
/** The piece whose value is being edited in place. */
|
|
207
|
+
const [editing, setEditing] = useState(null);
|
|
208
|
+
/** The last removal, offered back in the bar when there is no notice stack to offer it. */
|
|
209
|
+
const [undo, setUndo] = useState(null);
|
|
210
|
+
const lastRemoval = useRef(null);
|
|
211
|
+
const [recent, setRecent] = useState([]);
|
|
118
212
|
/** The step the question being written is at: no field, with a field, or
|
|
119
213
|
* with a field and operator. */
|
|
120
214
|
const [step, setStep] = useState({});
|
|
@@ -158,6 +252,13 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
158
252
|
«three» has to be what is seen in the bar, and what
|
|
159
253
|
is seen is a group, not its two conditions. */
|
|
160
254
|
const puestos = criteria.length;
|
|
255
|
+
const pieces = facetPaths(criteria);
|
|
256
|
+
/* The list as it is NOW, for an «undo» pressed in a notice long after it was offered: the
|
|
257
|
+
notice keeps the closure of the moment it was shown. */
|
|
258
|
+
const criteriaNow = useRef(criteria);
|
|
259
|
+
useEffect(() => {
|
|
260
|
+
criteriaNow.current = criteria;
|
|
261
|
+
});
|
|
161
262
|
const input = useRef(null);
|
|
162
263
|
const box = useRef(null);
|
|
163
264
|
const toolsButton = useRef(null);
|
|
@@ -319,7 +420,27 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
319
420
|
query,
|
|
320
421
|
}));
|
|
321
422
|
}
|
|
423
|
+
/* THE EMPTY BAR OFFERS. Focused with nothing typed, it said nothing until a letter was
|
|
424
|
+
pressed — and a person who does not know what can be searched does not know what to
|
|
425
|
+
type. Now it shows what was searched lately and the fields it can search by: the second
|
|
426
|
+
search of the day is one Enter, and the first one starts by reading. */
|
|
427
|
+
const starting = starter &&
|
|
428
|
+
focused &&
|
|
429
|
+
text === "" &&
|
|
430
|
+
step.field === undefined &&
|
|
431
|
+
marked === null &&
|
|
432
|
+
editing === null;
|
|
322
433
|
const items = [];
|
|
434
|
+
if (starting) {
|
|
435
|
+
const again = recent.filter((one) => !criteria.some((each) => each.kind !== "join" && each.label === one.label));
|
|
436
|
+
if (again.length > 0) {
|
|
437
|
+
items.push({ kind: "heading", id: "h:recent", text: copy.search.recent });
|
|
438
|
+
for (const one of again)
|
|
439
|
+
items.push({ kind: "recent", id: `rc:${one.label}`, criteria: one });
|
|
440
|
+
}
|
|
441
|
+
if (suggestions.length > 0)
|
|
442
|
+
items.push({ kind: "heading", id: "h:by", text: copy.search.searchBy });
|
|
443
|
+
}
|
|
323
444
|
for (const one of suggestions) {
|
|
324
445
|
items.push({ kind: "suggestion", id: one.id, suggestion: one });
|
|
325
446
|
if (one.id === unfoldedRow?.id)
|
|
@@ -330,16 +451,28 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
330
451
|
}
|
|
331
452
|
/* It opens when there is something to offer AND somebody has started: typing, or
|
|
332
453
|
choosing a field, which is already having started. */
|
|
333
|
-
const open =
|
|
454
|
+
const open = focused &&
|
|
455
|
+
items.some(selectable) &&
|
|
456
|
+
(text.trim() !== "" || step.field !== undefined || starting);
|
|
334
457
|
/* THE WAY INTO THE BUILDER, under what is offered: whoever typed a question the bar cannot
|
|
335
458
|
write —a range, a group of three, «ninguna línea con…»— is looking at this list when they
|
|
336
459
|
find out. It was only at the foot of the panel, behind another button. */
|
|
337
460
|
if (open && onOpenBuilder !== undefined && !asTags && step.field === undefined) {
|
|
338
461
|
items.push({ kind: "advanced", id: "a:advanced" });
|
|
339
462
|
}
|
|
463
|
+
/* THE COMPLETION, in grey after the caret: «cli» shows «ente» and Tab takes «cliente» as
|
|
464
|
+
the field. Only for a name being written —no operator, no value shape— and only when a
|
|
465
|
+
field's name STARTS with it: completing from the middle of a word is guessing. */
|
|
466
|
+
const typedName = text.startsWith("#") ? text.slice(1) : text;
|
|
467
|
+
const completion = open && step.field === undefined && /^[\p{L}\p{N}_][\p{L}\p{N}_ ]*$/u.test(typedName)
|
|
468
|
+
? suggestions.find((one) => one.kind === "field" &&
|
|
469
|
+
one.label.length > typedName.length &&
|
|
470
|
+
fold(one.label).startsWith(fold(typedName)))
|
|
471
|
+
: undefined;
|
|
472
|
+
const ghost = completion?.label.slice(typedName.length);
|
|
340
473
|
const firstSelectable = items.findIndex(selectable);
|
|
341
|
-
const
|
|
342
|
-
const active =
|
|
474
|
+
const markedRow = items.findIndex((one) => one.id === activeId && selectable(one));
|
|
475
|
+
const active = markedRow >= 0 ? markedRow : firstSelectable;
|
|
343
476
|
const activeItem = items[active];
|
|
344
477
|
/* What is marked goes back to the first when what is offered changes: leaving the mark on the
|
|
345
478
|
fourth row while you keep writing makes Enter take something that is no
|
|
@@ -421,10 +554,13 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
421
554
|
(`ListingBar`, so the field never paints over «1–80») and a page may clip its card, and a
|
|
422
555
|
panel drawn inside them was cut wherever it outgrew the field. Placed this way it is as
|
|
423
556
|
wide as `--container-cuts`, inside the screen, toward the side with room. */
|
|
557
|
+
/* It hangs from the FUNNEL that opened it, its end on the funnel's end: hung from the field's
|
|
558
|
+
edge, a bar as wide as the page opened it a screen away from the hand that asked. Near the
|
|
559
|
+
left edge, React Aria slides it back inside the screen. */
|
|
424
560
|
const { overlayProps: positionProps } = useOverlayPosition({
|
|
425
|
-
targetRef:
|
|
561
|
+
targetRef: toolsButton,
|
|
426
562
|
overlayRef: panelBox,
|
|
427
|
-
placement:
|
|
563
|
+
placement: "bottom end",
|
|
428
564
|
offset: 4,
|
|
429
565
|
containerPadding: 16,
|
|
430
566
|
shouldFlip: false,
|
|
@@ -433,6 +569,62 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
433
569
|
/* With the focus still in the bar (the input, the button) and the panel open, Escape is
|
|
434
570
|
the panel's too — used up the same way, so it does not reach the dialog either. With the
|
|
435
571
|
panel closed, Escape is not the bar's and goes on to whoever owns it. */
|
|
572
|
+
/**
|
|
573
|
+
* THE PANEL FROM THE KEYBOARD. ↑ ↓ go through a column's options (and wrap), ← → jump to the
|
|
574
|
+
* next column at the same height, Home / End to its ends, a letter to the next option that
|
|
575
|
+
* starts with it, Space ticks — it is a button. Tab still goes through everything, in order.
|
|
576
|
+
* It was Tab, option by option, through three columns: forty presses to reach a favourite.
|
|
577
|
+
*/
|
|
578
|
+
const walkPanel = (e) => {
|
|
579
|
+
if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey)
|
|
580
|
+
return;
|
|
581
|
+
const here = e.target;
|
|
582
|
+
const columnsNow = [
|
|
583
|
+
...e.currentTarget.querySelectorAll("[data-cuts-column]"),
|
|
584
|
+
];
|
|
585
|
+
const stops = (column) => [...column.querySelectorAll("button:not([disabled])")].filter((one) => one.getClientRects().length > 0);
|
|
586
|
+
const column = here.closest("[data-cuts-column]");
|
|
587
|
+
if (column === null)
|
|
588
|
+
return;
|
|
589
|
+
/* In a column's box only ↓ is the panel's: the rest is writing. */
|
|
590
|
+
if (here.tagName === "INPUT") {
|
|
591
|
+
if (e.key === "ArrowDown") {
|
|
592
|
+
e.preventDefault();
|
|
593
|
+
stops(column)[0]?.focus();
|
|
594
|
+
}
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
if (here.tagName !== "BUTTON")
|
|
598
|
+
return;
|
|
599
|
+
const list = stops(column);
|
|
600
|
+
const at = list.indexOf(here);
|
|
601
|
+
const go = (one) => {
|
|
602
|
+
if (one === undefined)
|
|
603
|
+
return;
|
|
604
|
+
e.preventDefault();
|
|
605
|
+
one.focus();
|
|
606
|
+
};
|
|
607
|
+
if (e.key === "ArrowDown")
|
|
608
|
+
go(list[(at + 1) % list.length]);
|
|
609
|
+
else if (e.key === "ArrowUp")
|
|
610
|
+
go(list[(at - 1 + list.length) % list.length]);
|
|
611
|
+
else if (e.key === "Home")
|
|
612
|
+
go(list[0]);
|
|
613
|
+
else if (e.key === "End")
|
|
614
|
+
go(list[list.length - 1]);
|
|
615
|
+
else if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
|
|
616
|
+
const next = columnsNow[columnsNow.indexOf(column) + (e.key === "ArrowRight" ? 1 : -1)];
|
|
617
|
+
if (next === undefined)
|
|
618
|
+
return;
|
|
619
|
+
const there = stops(next);
|
|
620
|
+
go(there[Math.min(Math.max(at, 0), there.length - 1)]);
|
|
621
|
+
}
|
|
622
|
+
else if (e.key.length === 1 && e.key !== " ") {
|
|
623
|
+
const letter = fold(e.key);
|
|
624
|
+
const after = [...list.slice(at + 1), ...list.slice(0, at + 1)];
|
|
625
|
+
go(after.find((one) => fold(one.textContent?.trim() ?? "").startsWith(letter)));
|
|
626
|
+
}
|
|
627
|
+
};
|
|
436
628
|
const closePanelOnEscape = (e) => {
|
|
437
629
|
if (e.key !== "Escape" || !panel || e.defaultPrevented)
|
|
438
630
|
return;
|
|
@@ -453,11 +645,176 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
453
645
|
onCriteriaChange(openGroup === null
|
|
454
646
|
? [...criteria, one]
|
|
455
647
|
: replaceAt(criteria, openGroup, addTo(at(criteria, openGroup), one)));
|
|
648
|
+
remember(one);
|
|
649
|
+
settle();
|
|
650
|
+
}
|
|
651
|
+
/** Back to the start once something is set: no draft, nothing offered until asked. */
|
|
652
|
+
function settle() {
|
|
456
653
|
setText("");
|
|
457
654
|
setStep({});
|
|
458
655
|
setUnfolded(null);
|
|
656
|
+
setStarter(false);
|
|
657
|
+
input.current?.focus();
|
|
658
|
+
}
|
|
659
|
+
/* ── WHAT WAS SEARCHED LATELY ─────────────────────────────────────
|
|
660
|
+
Only with `recentKey`, and only in this browser: a list's recent searches are the
|
|
661
|
+
person's habit on this screen, not data of the application. Read after mounting — the
|
|
662
|
+
server has no storage — and every read and write survives a private window that refuses
|
|
663
|
+
it. */
|
|
664
|
+
const recentStore = recentKey === undefined ? undefined : `sincpro-web-ui:search-recent:${recentKey}`;
|
|
665
|
+
useEffect(() => {
|
|
666
|
+
if (recentStore === undefined)
|
|
667
|
+
return;
|
|
668
|
+
try {
|
|
669
|
+
setRecent(recentFromStorage(window.localStorage.getItem(recentStore)));
|
|
670
|
+
}
|
|
671
|
+
catch {
|
|
672
|
+
/* No storage, or something that is not ours under the name: nothing remembered. */
|
|
673
|
+
}
|
|
674
|
+
}, [recentStore]);
|
|
675
|
+
function remember(one) {
|
|
676
|
+
if (recentStore === undefined || one.kind !== "filter")
|
|
677
|
+
return;
|
|
678
|
+
const kept = one;
|
|
679
|
+
setRecent((before) => {
|
|
680
|
+
const next = [kept, ...before.filter((each) => each.label !== kept.label)].slice(0, RECENT_MAX);
|
|
681
|
+
try {
|
|
682
|
+
window.localStorage.setItem(recentStore, JSON.stringify(next));
|
|
683
|
+
}
|
|
684
|
+
catch {
|
|
685
|
+
/* Remembered for this visit only. */
|
|
686
|
+
}
|
|
687
|
+
return next;
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
/** A recent search, set again: a chip of values goes back into its field's chip; any other
|
|
691
|
+
* enters as a new instance. */
|
|
692
|
+
function putRecent(one) {
|
|
693
|
+
if (one.id.startsWith("v:")) {
|
|
694
|
+
const there = criteria.findIndex((each) => each.id === one.id);
|
|
695
|
+
onCriteriaChange(there < 0 ? [...criteria, one] : replaceAt(criteria, [there], one));
|
|
696
|
+
remember(one);
|
|
697
|
+
settle();
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
put({ ...one, id: criteriaId("f") });
|
|
701
|
+
}
|
|
702
|
+
/* ── REMOVING, AND TAKING IT BACK ──────────────────────────────────
|
|
703
|
+
Undo over confirm (PRINCIPLES): a chip goes at once —its ×, Delete on a marked chip, the
|
|
704
|
+
× that clears everything— and the bar offers it back. In the screen's notice stack when
|
|
705
|
+
there is one (`ToastProvider`), in the bar itself when not. */
|
|
706
|
+
function removeWithUndo(paths, label) {
|
|
707
|
+
const removed = paths.flatMap((path) => {
|
|
708
|
+
const node = at(criteria, path);
|
|
709
|
+
return node === undefined ? [] : [{ path, node }];
|
|
710
|
+
});
|
|
711
|
+
if (removed.length === 0)
|
|
712
|
+
return;
|
|
713
|
+
/* The deepest and the last first, so each removal leaves the next path valid. */
|
|
714
|
+
const ordered = [...paths].sort((a, b) => {
|
|
715
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
716
|
+
const diff = (b[i] ?? -1) - (a[i] ?? -1);
|
|
717
|
+
if (diff !== 0)
|
|
718
|
+
return diff;
|
|
719
|
+
}
|
|
720
|
+
return 0;
|
|
721
|
+
});
|
|
722
|
+
const next = ordered.reduce((left, path) => removeAt(left, path), [...criteria]);
|
|
723
|
+
onCriteriaChange(next);
|
|
724
|
+
/* If what was removed held the open group, it stops being so: writing inside something
|
|
725
|
+
that no longer exists is writing into the air. */
|
|
726
|
+
if (openGroup !== null &&
|
|
727
|
+
(paths.some((path) => openGroup.join(".").startsWith(path.join("."))) ||
|
|
728
|
+
at(next, openGroup)?.kind !== "join"))
|
|
729
|
+
setOpenGroup(null);
|
|
730
|
+
const removal = { label, removed, before: criteria, after: next };
|
|
731
|
+
lastRemoval.current = removal;
|
|
732
|
+
if (toasts === null) {
|
|
733
|
+
setUndo(removal);
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
toasts.show({
|
|
737
|
+
key: `search-undo-${id}`,
|
|
738
|
+
message: fillCopy(copy.search.removed, { label }),
|
|
739
|
+
action: { label: copy.search.undo, onSelect: () => takeBack(removal) },
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
function takeBack(removal = lastRemoval.current) {
|
|
743
|
+
if (removal === null)
|
|
744
|
+
return;
|
|
745
|
+
const next = restoreRemoval(criteriaNow.current, removal);
|
|
746
|
+
if (next !== null)
|
|
747
|
+
onCriteriaChange(next);
|
|
748
|
+
lastRemoval.current = null;
|
|
749
|
+
setUndo(null);
|
|
459
750
|
input.current?.focus();
|
|
460
751
|
}
|
|
752
|
+
/* The offer in the bar lasts what a notice lasts: long enough to change one's mind, not so
|
|
753
|
+
long that «Deshacer» undoes something nobody remembers. */
|
|
754
|
+
useEffect(() => {
|
|
755
|
+
if (undo === null)
|
|
756
|
+
return;
|
|
757
|
+
const timer = window.setTimeout(() => setUndo(null), 8000);
|
|
758
|
+
return () => window.clearTimeout(timer);
|
|
759
|
+
}, [undo]);
|
|
760
|
+
/** How a piece reads when it is named — marked, removed. */
|
|
761
|
+
function facetLabel(paths) {
|
|
762
|
+
return paths
|
|
763
|
+
.map((path) => {
|
|
764
|
+
const node = at(criteria, path);
|
|
765
|
+
if (node === undefined)
|
|
766
|
+
return "";
|
|
767
|
+
if (node.kind !== "join")
|
|
768
|
+
return node.label;
|
|
769
|
+
return `${copy.search.joins[node.join === "not" ? "none" : node.join]} (${node.of.length})`;
|
|
770
|
+
})
|
|
771
|
+
.join(" › ");
|
|
772
|
+
}
|
|
773
|
+
/* A mark on a piece that is no longer there marks nothing. */
|
|
774
|
+
useEffect(() => {
|
|
775
|
+
if (marked !== null && marked >= pieces.length)
|
|
776
|
+
setMarked(null);
|
|
777
|
+
}, [marked, pieces.length]);
|
|
778
|
+
/* «/» from anywhere that is not a field. */
|
|
779
|
+
useEffect(() => {
|
|
780
|
+
if (!focusOnSlash)
|
|
781
|
+
return;
|
|
782
|
+
const entry = input;
|
|
783
|
+
slashBars.push(entry);
|
|
784
|
+
if (slashBars.length === 1)
|
|
785
|
+
window.addEventListener("keydown", onSlash);
|
|
786
|
+
return () => {
|
|
787
|
+
const where = slashBars.indexOf(entry);
|
|
788
|
+
if (where >= 0)
|
|
789
|
+
slashBars.splice(where, 1);
|
|
790
|
+
if (slashBars.length === 0)
|
|
791
|
+
window.removeEventListener("keydown", onSlash);
|
|
792
|
+
};
|
|
793
|
+
}, [focusOnSlash]);
|
|
794
|
+
/** The edit in place ended. From the keyboard the bar takes the focus back at once — the
|
|
795
|
+
* keys go on writing —; after a click elsewhere the focus stays where it went. */
|
|
796
|
+
function edited(giveBack) {
|
|
797
|
+
setEditing(null);
|
|
798
|
+
setMarked(null);
|
|
799
|
+
if (giveBack)
|
|
800
|
+
input.current?.focus();
|
|
801
|
+
}
|
|
802
|
+
/** The panel, opened from the keyboard: its first option takes the focus. */
|
|
803
|
+
function openPanelFromKeys() {
|
|
804
|
+
panelFromKeys.current = true;
|
|
805
|
+
setPanel(true);
|
|
806
|
+
}
|
|
807
|
+
useEffect(() => {
|
|
808
|
+
if (!panel || !panelFromKeys.current)
|
|
809
|
+
return;
|
|
810
|
+
panelFromKeys.current = false;
|
|
811
|
+
const frame = window.requestAnimationFrame(() => {
|
|
812
|
+
panelBox.current
|
|
813
|
+
?.querySelector("[data-cuts-column] button:not([disabled]), [data-cuts-column] input, button:not([disabled])")
|
|
814
|
+
?.focus();
|
|
815
|
+
});
|
|
816
|
+
return () => window.cancelAnimationFrame(frame);
|
|
817
|
+
}, [panel]);
|
|
461
818
|
function commit(field, op, value) {
|
|
462
819
|
put(conditionCriteria(field, op, value));
|
|
463
820
|
}
|
|
@@ -474,10 +831,8 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
474
831
|
else {
|
|
475
832
|
onCriteriaChange(withValue(criteria, field, option));
|
|
476
833
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
setUnfolded(null);
|
|
480
|
-
input.current?.focus();
|
|
834
|
+
remember(valuesCriteria(field, [option]));
|
|
835
|
+
settle();
|
|
481
836
|
}
|
|
482
837
|
/** Several values of a field at once —what a chooser answers—, into the same chip. */
|
|
483
838
|
function putValues(field, options) {
|
|
@@ -491,10 +846,7 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
491
846
|
else {
|
|
492
847
|
onCriteriaChange(into(criteria));
|
|
493
848
|
}
|
|
494
|
-
|
|
495
|
-
setStep({});
|
|
496
|
-
setUnfolded(null);
|
|
497
|
-
input.current?.focus();
|
|
849
|
+
settle();
|
|
498
850
|
}
|
|
499
851
|
/** «Buscar más…»: the application's chooser over the relation, on what was typed. What is
|
|
500
852
|
* already in the relation's chip is said, so a chooser of many leaves it out. */
|
|
@@ -573,6 +925,8 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
573
925
|
return;
|
|
574
926
|
if (item.kind === "suggestion")
|
|
575
927
|
pick(item.suggestion);
|
|
928
|
+
else if (item.kind === "recent")
|
|
929
|
+
putRecent(item.criteria);
|
|
576
930
|
else if (item.kind === "more")
|
|
577
931
|
browse(item.field, item.text);
|
|
578
932
|
else if (item.kind === "advanced") {
|
|
@@ -597,30 +951,38 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
597
951
|
? one
|
|
598
952
|
: { ...node, of: [...node.of, one] };
|
|
599
953
|
}
|
|
600
|
-
return (_jsxs("div", { ref: box, onKeyDown: closePanelOnEscape,
|
|
954
|
+
return (_jsxs("div", { ref: box, onKeyDown: closePanelOnEscape, onFocus: () => setFocused(true), onBlur: (event) => {
|
|
955
|
+
/* Out of the bar —and not into its panel, which floats elsewhere in the DOM—: what is
|
|
956
|
+
offered closes, and a mark on a chip is let go. */
|
|
957
|
+
const next = event.relatedTarget;
|
|
958
|
+
if (next instanceof Node &&
|
|
959
|
+
(box.current?.contains(next) === true || panelBox.current?.contains(next) === true))
|
|
960
|
+
return;
|
|
961
|
+
setFocused(false);
|
|
962
|
+
setStarter(false);
|
|
963
|
+
setMarked(null);
|
|
964
|
+
}, "data-ui": "search", className: "relative flex min-w-48 items-center gap-2", children: [_jsxs("div", { "data-ui": "search.field",
|
|
965
|
+
/* A press on the field's own padding —not on a chip, not on a button— writes: the whole
|
|
966
|
+
field reads as one input, so the whole field has to answer as one. */
|
|
967
|
+
onMouseDown: (event) => {
|
|
968
|
+
if (event.target === event.currentTarget) {
|
|
969
|
+
event.preventDefault();
|
|
970
|
+
input.current?.focus();
|
|
971
|
+
setStarter(true);
|
|
972
|
+
}
|
|
973
|
+
}, className: `@container/bar flex min-h-(--size-control-md) w-full min-w-0 items-start rounded-ui-search border transition-colors duration-(--duration-instant) ${bySurface(sup, "border-ui-control-border bg-ui-control focus-within:border-primary/60",
|
|
601
974
|
/* On the chrome what defines the field is the BORDER, not the fill. The
|
|
602
975
|
blue is already almost black, so sinking it gives no contrast (1.05:1) and
|
|
603
976
|
raising it gives 1.21:1 — in both cases the field does not read as a
|
|
604
977
|
field, which was «it does not draw attention». Ink at 45 % is the first
|
|
605
978
|
border that passes 3:1 against the fill AND against the chrome, which is what
|
|
606
979
|
1.4.11 asks of a control. */
|
|
607
|
-
"border-chrome-ink/45 bg-chrome-ink/8 focus-within:border-chrome-link")}`, children: [_jsx("span", { className: "mt-0.75 flex h-7 shrink-0 items-center pr-1.5 pl-2.5", children: _jsx(Search, { className: "size-(--size-icon-md) shrink-0 text-muted", strokeWidth: 2, "aria-hidden": true }) }), _jsxs("div", { className: "flex min-w-24 flex-1 flex-wrap items-center gap-1 py-0.75", children: [_jsx(CriteriaChips, { criteria: criteria, surface: sup, ...(openGroup === null ? {} : { open: openGroup }), ...(onOpenBuilder === undefined ? {} : { onOpen: onOpenBuilder }), ...(collapseAfter === undefined ? {} : { collapseAfter }), onRemoveMany: (paths) => {
|
|
608
|
-
/* From the deepest index up, so each removal leaves the next path valid. */
|
|
609
|
-
const sorted = [...paths].sort((a, b) => (b[0] ?? 0) - (a[0] ?? 0));
|
|
610
|
-
onCriteriaChange(sorted.reduce((left, path) => removeAt(left, path), [...criteria]));
|
|
611
|
-
}, onJoin: (path, join) => {
|
|
980
|
+
"border-chrome-ink/45 bg-chrome-ink/8 focus-within:border-chrome-link")}`, children: [_jsx("span", { className: "mt-0.75 flex h-7 shrink-0 items-center pr-1.5 pl-2.5", children: _jsx(Search, { className: "size-(--size-icon-md) shrink-0 text-muted", strokeWidth: 2, "aria-hidden": true }) }), _jsxs("div", { className: "flex min-w-24 flex-1 flex-wrap items-center gap-1 py-0.75", children: [_jsx(CriteriaChips, { criteria: criteria, surface: sup, fields: fields, ...(marked === null ? {} : { marked }), ...(editing === null ? {} : { editing }), onEdited: edited, onReplace: (path, next) => onCriteriaChange(replaceAt(criteria, path, next)), ...(openGroup === null ? {} : { open: openGroup }), ...(onOpenBuilder === undefined ? {} : { onOpen: onOpenBuilder }), ...(collapseAfter === undefined ? {} : { collapseAfter }), onRemoveMany: (paths) => removeWithUndo(paths, facetLabel(paths)), onJoin: (path, join) => {
|
|
612
981
|
const node = at(criteria, path);
|
|
613
982
|
if (node?.kind !== "join")
|
|
614
983
|
return;
|
|
615
984
|
onCriteriaChange(replaceAt(criteria, path, { ...node, join }));
|
|
616
|
-
}, onRemove: (path) => {
|
|
617
|
-
onCriteriaChange(removeAt(criteria, path));
|
|
618
|
-
/* If what was removed was the open group, it stops being so: writing
|
|
619
|
-
inside something that no longer exists is writing into the air. */
|
|
620
|
-
if (openGroup !== null && path.join(".") === openGroup.join(".")) {
|
|
621
|
-
setOpenGroup(null);
|
|
622
|
-
}
|
|
623
|
-
} }), _jsx(Tags, { surface: sup, items: [
|
|
985
|
+
}, onRemove: (path) => removeWithUndo([path], facetLabel([path])) }), _jsx(Tags, { surface: sup, items: [
|
|
624
986
|
/* INSIDE WHAT is being written, first: it is what wraps
|
|
625
987
|
the rest of the draft, and it is the only chip that is removed to
|
|
626
988
|
CLOSE rather than to undo a step. Without it, `#and` opened
|
|
@@ -670,138 +1032,264 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
670
1032
|
removeLabel: copy.search.dropOp,
|
|
671
1033
|
},
|
|
672
1034
|
]),
|
|
673
|
-
] }),
|
|
674
|
-
? { "
|
|
675
|
-
:
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
1035
|
+
] }), _jsxs("span", { className: step.field === undefined
|
|
1036
|
+
? `relative flex h-7 ${criteria.length === 0 ? "min-w-24" : "min-w-16"} flex-1 items-center`
|
|
1037
|
+
: "contents", children: [_jsx("input", { ref: input, ...(focusOnSlash ? { "aria-keyshortcuts": "/" } : {}), onFocus: (event) => {
|
|
1038
|
+
/* Entered from outside the bar: it offers. Coming back from a chip of its own,
|
|
1039
|
+
it does not — the person is working on what is set. */
|
|
1040
|
+
const from = event.relatedTarget;
|
|
1041
|
+
if (!(from instanceof Node && box.current?.contains(from) === true))
|
|
1042
|
+
setStarter(true);
|
|
1043
|
+
}, "aria-label": copy.choice.search, role: "combobox", "aria-autocomplete": "list", "aria-expanded": open, ...(open ? { "aria-controls": listId } : {}), ...(open && !asTags && activeItem !== undefined
|
|
1044
|
+
? { "aria-activedescendant": optionId(active) }
|
|
1045
|
+
: {}), value: text, onChange: (e) => {
|
|
1046
|
+
setText(e.target.value);
|
|
1047
|
+
setMarked(null);
|
|
1048
|
+
setStarter(true);
|
|
1049
|
+
}, onKeyDown: (e) => {
|
|
1050
|
+
const mod = e.metaKey || e.ctrlKey;
|
|
1051
|
+
/* THE BAR'S OWN KEYS, before anything is read as text.
|
|
1052
|
+
Mod+Enter: the advanced search, from where the hands already are.
|
|
1053
|
+
Alt+↓: the panel, its first option focused — the combobox's «open the list».
|
|
1054
|
+
Mod+Z on the empty bar: the last removal, back. */
|
|
1055
|
+
if (e.key === "Enter" && mod && onOpenBuilder !== undefined) {
|
|
1056
|
+
e.preventDefault();
|
|
1057
|
+
setText("");
|
|
1058
|
+
setStep({});
|
|
1059
|
+
setUnfolded(null);
|
|
1060
|
+
onOpenBuilder();
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
if (e.key === "ArrowDown" &&
|
|
1064
|
+
e.altKey &&
|
|
1065
|
+
columns.length + (onOpenBuilder ? 1 : 0) > 0) {
|
|
1066
|
+
e.preventDefault();
|
|
1067
|
+
openPanelFromKeys();
|
|
1068
|
+
return;
|
|
1069
|
+
}
|
|
1070
|
+
if (e.code === "KeyZ" &&
|
|
1071
|
+
mod &&
|
|
1072
|
+
!e.shiftKey &&
|
|
1073
|
+
text === "" &&
|
|
1074
|
+
lastRemoval.current) {
|
|
1075
|
+
e.preventDefault();
|
|
1076
|
+
takeBack();
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
/* A PIECE MARKED. ← on the empty bar marks the last one; ← → walk them, Delete or
|
|
1080
|
+
Backspace removes the marked one (with its «Deshacer»), Enter edits it —its value
|
|
1081
|
+
in place when it has one, the builder otherwise— and Escape lets it go.
|
|
1082
|
+
Backspace used to remove the last chip at once: one key too many on an empty
|
|
1083
|
+
bar and a filter was gone without a word. Now the first press shows what the
|
|
1084
|
+
second one will take. */
|
|
1085
|
+
if (marked !== null) {
|
|
1086
|
+
const piece = pieces[marked];
|
|
1087
|
+
if (e.key === "ArrowLeft") {
|
|
1088
|
+
e.preventDefault();
|
|
1089
|
+
setMarked(Math.max(0, marked - 1));
|
|
1090
|
+
return;
|
|
1091
|
+
}
|
|
1092
|
+
if (e.key === "ArrowRight") {
|
|
1093
|
+
e.preventDefault();
|
|
1094
|
+
setMarked(marked + 1 < pieces.length ? marked + 1 : null);
|
|
1095
|
+
return;
|
|
1096
|
+
}
|
|
1097
|
+
if ((e.key === "Backspace" || e.key === "Delete") && piece !== undefined) {
|
|
1098
|
+
e.preventDefault();
|
|
1099
|
+
setMarked(null);
|
|
1100
|
+
removeWithUndo(piece, facetLabel(piece));
|
|
1101
|
+
return;
|
|
1102
|
+
}
|
|
1103
|
+
if (e.key === "Enter" && piece !== undefined) {
|
|
1104
|
+
e.preventDefault();
|
|
1105
|
+
const path = piece[0];
|
|
1106
|
+
const node = at(criteria, path);
|
|
1107
|
+
const parts = node === undefined ? undefined : chipParts(node, fields);
|
|
1108
|
+
if (piece.length === 1 &&
|
|
1109
|
+
parts?.kind === "condition" &&
|
|
1110
|
+
(parts.field.choices ?? []).length === 0 &&
|
|
1111
|
+
!withoutValue(parts.op)) {
|
|
1112
|
+
setEditing(marked);
|
|
1113
|
+
}
|
|
1114
|
+
else {
|
|
1115
|
+
setMarked(null);
|
|
1116
|
+
onOpenBuilder?.(path);
|
|
1117
|
+
}
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1120
|
+
if (e.key === "Escape") {
|
|
1121
|
+
e.preventDefault();
|
|
1122
|
+
e.stopPropagation();
|
|
1123
|
+
setMarked(null);
|
|
1124
|
+
return;
|
|
1125
|
+
}
|
|
1126
|
+
/* Any other key goes back to writing. */
|
|
1127
|
+
setMarked(null);
|
|
1128
|
+
}
|
|
1129
|
+
if ((e.key === "ArrowLeft" || e.key === "Backspace") &&
|
|
1130
|
+
text === "" &&
|
|
1131
|
+
step.field === undefined &&
|
|
1132
|
+
pieces.length > 0) {
|
|
1133
|
+
e.preventDefault();
|
|
1134
|
+
setMarked(pieces.length - 1);
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
/* Backspace on an empty draft goes back one step: the comparison, then the field. */
|
|
1138
|
+
if (e.key === "Backspace" && text === "" && step.field !== undefined) {
|
|
1139
|
+
e.preventDefault();
|
|
1140
|
+
setStep(step.op !== undefined && !(records && step.field.relation !== undefined)
|
|
1141
|
+
? { field: step.field }
|
|
1142
|
+
: {});
|
|
1143
|
+
return;
|
|
1144
|
+
}
|
|
1145
|
+
/* Tab TAKES the completion drawn in grey: «cli» + Tab is «cliente», chosen as the
|
|
1146
|
+
field, the way a terminal completes. Without a completion Tab is Tab. */
|
|
1147
|
+
if (e.key === "Tab" &&
|
|
1148
|
+
!e.shiftKey &&
|
|
1149
|
+
completion !== undefined &&
|
|
1150
|
+
e.currentTarget.selectionStart === text.length) {
|
|
1151
|
+
e.preventDefault();
|
|
1152
|
+
pick(completion);
|
|
1153
|
+
return;
|
|
1154
|
+
}
|
|
1155
|
+
/* The arrows TRAVERSE what is offered and Enter takes what is
|
|
1156
|
+
marked. Without this, typing «#nom» and going down did nothing: the
|
|
1157
|
+
list was seen and could not be touched without the mouse, which is
|
|
1158
|
+
precisely what a search bar cannot ask for. ↓ on the closed empty bar
|
|
1159
|
+
opens what it offers. */
|
|
1160
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
1161
|
+
if (!open) {
|
|
1162
|
+
if (e.key === "ArrowDown" && text === "" && step.field === undefined) {
|
|
1163
|
+
e.preventDefault();
|
|
1164
|
+
setStarter(true);
|
|
1165
|
+
}
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1168
|
+
e.preventDefault();
|
|
1169
|
+
move(e.key === "ArrowDown" ? 1 : -1);
|
|
1170
|
+
return;
|
|
1171
|
+
}
|
|
1172
|
+
/* → OPENS what is under the marked row —a relation's records, an enum's values—
|
|
1173
|
+
and ← closes it and goes back to the row, the way a tree and Odoo's bar do.
|
|
1174
|
+
Only with the caret at the end: in the middle of the text the arrows are still
|
|
1175
|
+
the text's. */
|
|
1176
|
+
const atEnd = e.currentTarget.selectionStart === text.length;
|
|
1177
|
+
if (e.key === "ArrowRight" && atEnd && open && unfoldable(activeItem)) {
|
|
1178
|
+
if (activeItem !== undefined && activeItem.id !== unfolded) {
|
|
1179
|
+
e.preventDefault();
|
|
1180
|
+
toggle(activeItem.id);
|
|
1181
|
+
}
|
|
1182
|
+
return;
|
|
1183
|
+
}
|
|
1184
|
+
if (e.key === "ArrowLeft" && atEnd && open && unfolded !== null) {
|
|
1185
|
+
const parent = activeItem?.kind === "suggestion" &&
|
|
1186
|
+
activeItem.suggestion.kind === "value"
|
|
1187
|
+
? activeItem.suggestion.under
|
|
1188
|
+
: activeItem?.kind === "status" || activeItem?.kind === "more"
|
|
1189
|
+
? unfolded
|
|
1190
|
+
: activeItem?.id === unfolded
|
|
1191
|
+
? unfolded
|
|
1192
|
+
: undefined;
|
|
1193
|
+
if (parent !== undefined) {
|
|
1194
|
+
e.preventDefault();
|
|
1195
|
+
setUnfolded(null);
|
|
1196
|
+
setActiveId(parent);
|
|
1197
|
+
}
|
|
1198
|
+
return;
|
|
1199
|
+
}
|
|
1200
|
+
/* Enter takes what is MARKED, which starts out being the first — and the
|
|
1201
|
+
first is the most likely: with «test» the first text field,
|
|
1202
|
+
with «<= 100» the only one that can answer it. */
|
|
1203
|
+
if (e.key === "Enter") {
|
|
1204
|
+
e.preventDefault();
|
|
1205
|
+
if (open)
|
|
1206
|
+
choose(activeItem);
|
|
1207
|
+
}
|
|
1208
|
+
/* Escape UNDOES, one step at a time and always the last: first what is
|
|
1209
|
+
unfolded, then what is written, then the comparison, then the field. Whoever
|
|
1210
|
+
got the field wrong wants to change it, not start over — and
|
|
1211
|
+
whoever is not building anything does not expect anything to happen.
|
|
1212
|
+
|
|
1213
|
+
Before, it only dismantled the step when a field had already been chosen,
|
|
1214
|
+
so with «vent» half-written it did nothing: the key that
|
|
1215
|
+
everybody presses to undo did not undo. */
|
|
1216
|
+
if (e.key === "Escape" && unfolded !== null && open) {
|
|
1217
|
+
e.preventDefault();
|
|
1218
|
+
e.stopPropagation();
|
|
1219
|
+
setActiveId(unfolded);
|
|
1220
|
+
setUnfolded(null);
|
|
1221
|
+
return;
|
|
1222
|
+
}
|
|
1223
|
+
if (e.key === "Escape") {
|
|
1224
|
+
if (text !== "") {
|
|
1225
|
+
e.preventDefault();
|
|
1226
|
+
e.stopPropagation();
|
|
1227
|
+
setText("");
|
|
1228
|
+
return;
|
|
1229
|
+
}
|
|
1230
|
+
if (step.op !== undefined) {
|
|
1231
|
+
e.preventDefault();
|
|
1232
|
+
e.stopPropagation();
|
|
1233
|
+
/* A relation searched by its records skipped the comparison: undoing goes
|
|
1234
|
+
back to choosing the field, not to a step it never showed. */
|
|
1235
|
+
setStep(records && step.field?.relation !== undefined
|
|
1236
|
+
? {}
|
|
1237
|
+
: { field: step.field });
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1240
|
+
if (step.field !== undefined) {
|
|
1241
|
+
e.preventDefault();
|
|
1242
|
+
e.stopPropagation();
|
|
1243
|
+
setStep({});
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1246
|
+
/* And at the end, the group: the last thing opened is the last thing
|
|
1247
|
+
undone. */
|
|
1248
|
+
if (openGroup !== null) {
|
|
1249
|
+
e.preventDefault();
|
|
1250
|
+
e.stopPropagation();
|
|
1251
|
+
closeGroup();
|
|
1252
|
+
return;
|
|
1253
|
+
}
|
|
1254
|
+
/* Nothing left to undo but what the empty bar offers: it closes. With nothing
|
|
1255
|
+
open, Escape is not the bar's and goes on to whoever owns it. */
|
|
1256
|
+
if (open) {
|
|
1257
|
+
e.preventDefault();
|
|
1258
|
+
e.stopPropagation();
|
|
1259
|
+
setStarter(false);
|
|
1260
|
+
}
|
|
1261
|
+
return;
|
|
1262
|
+
}
|
|
1263
|
+
}, placeholder: step.field !== undefined
|
|
1264
|
+
? copy.search.typeValue
|
|
1265
|
+
: criteria.length === 0
|
|
1266
|
+
? (placeholder ?? copy.search.placeholder)
|
|
1267
|
+
: "",
|
|
1268
|
+
/* WITH A FIELD CHOSEN, what is written is the VALUE — and it is drawn
|
|
1269
|
+
as the chip it will become, behind the other two. It is not an
|
|
1270
|
+
ornament: the draft is read whole —«nombre · contiene · vent▌»—
|
|
1271
|
+
before existing as a cut, so you see what it will end up as
|
|
1272
|
+
before it ends up. And it is still the input: nothing is duplicated, and
|
|
1273
|
+
nothing becomes a filter until somebody presses Enter or
|
|
1274
|
+
chooses from the list.
|
|
1275
|
+
|
|
1276
|
+
The width is asked for by the CONTENT —`field-sizing`— so the chip
|
|
1277
|
+
grows with what is written instead of reserving an empty band. Where it
|
|
1278
|
+
is not available, the input stretches as always. */
|
|
1279
|
+
style: step.field === undefined ? undefined : { fieldSizing: "content" }, className: step.field === undefined
|
|
1280
|
+
? `h-7 w-full min-w-0 bg-transparent text-meta outline-none ${bySurface(sup, "text-ink placeholder:text-muted", "text-chrome-ink placeholder:text-chrome-muted")}`
|
|
1281
|
+
: `min-w-16 rounded-pill px-2 py-0.5 text-micro outline-none ${bySurface(sup, "bg-primary/8 text-ink placeholder:text-muted", "bg-chrome-link/20 text-chrome-ink placeholder:text-chrome-muted")}` }), ghost === undefined || step.field !== undefined ? null : (_jsxs("span", { "aria-hidden": true, "data-ui": "search.completion", className: "pointer-events-none absolute inset-y-0 left-0 flex max-w-full items-center overflow-hidden text-meta whitespace-pre", children: [_jsx("span", { className: "invisible", children: text }), _jsx("span", { className: bySurface(sup, "text-muted", "text-chrome-muted"), children: ghost }), _jsx("span", { className: "ml-1.5 inline-flex", children: _jsx(Kbd, { surface: sup, children: "Tab" }) })] }))] })] }), _jsx("span", { role: "status", className: "sr-only", children: marked !== null && pieces[marked] !== undefined
|
|
1282
|
+
? fillCopy(copy.search.chipMarked, { label: facetLabel(pieces[marked]) })
|
|
1283
|
+
: undo !== null
|
|
1284
|
+
? fillCopy(copy.search.removed, { label: undo.label })
|
|
1285
|
+
: "" }), undo === null ? null : (_jsxs("button", { type: "button", "data-ui": "search.undo", onClick: () => takeBack(undo), title: fillCopy(copy.search.removed, { label: undo.label }), className: `my-0.5 inline-flex h-(--size-control-sm) shrink-0 items-center gap-1 rounded-control px-1.5 text-micro font-medium transition-colors duration-(--duration-instant) motion-safe:animate-chip-in focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary ${bySurface(sup, "text-primary hover:bg-primary/8", "text-chrome-link hover:bg-chrome-link/15")}`, children: [_jsx(Undo2, { className: "size-(--size-icon-sm)", strokeWidth: 2, "aria-hidden": true }), copy.search.undo] })), !focusOnSlash || focused || text !== "" || puestos > 0 || undo !== null ? null : (_jsx("span", { "aria-hidden": true, "data-ui": "search.slash", className: "my-0.5 mr-1 inline-flex h-(--size-control-sm) shrink-0 items-center touch:hidden max-sm:hidden", children: _jsx(Kbd, { surface: sup, children: "/" }) })), puestos === 0 ? null : (_jsx("button", { type: "button", onClick: () => {
|
|
1286
|
+
removeWithUndo(criteria.map((_, index) => [index]), pieces.map((piece) => facetLabel(piece)).join(", "));
|
|
799
1287
|
setOpenGroup(null);
|
|
800
1288
|
input.current?.focus();
|
|
801
|
-
}, "aria-label": copy.search.clearAll, title: copy.search.clearAll, className: `my-0.5 inline-flex h-(--size-control-sm) shrink-0 items-center rounded-control px-1.5 transition-colors duration-(--duration-instant) focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary ${bySurface(sup, "text-muted hover:bg-ink/5 hover:text-ink", "text-chrome-muted hover:bg-chrome-ink/10 hover:text-chrome-ink")}`, children: _jsx(X, { className: "size-(--size-icon-sm)", strokeWidth: 2, "aria-hidden": true }) })), columns.length === 0 && onOpenBuilder === undefined ? null : (_jsxs("button", { ref: toolsButton, type: "button", onClick: () => {
|
|
802
|
-
|
|
803
|
-
if (!panel &&
|
|
804
|
-
|
|
1289
|
+
}, "aria-label": copy.search.clearAll, title: copy.search.clearAll, className: `my-0.5 inline-flex h-(--size-control-sm) shrink-0 items-center rounded-control px-1.5 transition-colors duration-(--duration-instant) focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary ${bySurface(sup, "text-muted hover:bg-ink/5 hover:text-ink", "text-chrome-muted hover:bg-chrome-ink/10 hover:text-chrome-ink")}`, children: _jsx(X, { className: "size-(--size-icon-sm)", strokeWidth: 2, "aria-hidden": true }) })), columns.length === 0 && onOpenBuilder === undefined ? null : (_jsxs("button", { ref: toolsButton, type: "button", onClick: (event) => {
|
|
1290
|
+
/* Opened with Enter or Space (no pointer, `detail` 0): the keys go on inside it. */
|
|
1291
|
+
if (!panel && event.detail === 0)
|
|
1292
|
+
panelFromKeys.current = true;
|
|
805
1293
|
setPanel((v) => !v);
|
|
806
1294
|
}, "aria-expanded": panel, "aria-controls": panel ? id : undefined, "aria-label": puestos === 0
|
|
807
1295
|
? copy.search.tools
|
|
@@ -810,7 +1298,12 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
810
1298
|
count: puestos.toLocaleString(copy.locale),
|
|
811
1299
|
}), title: copy.search.tools, className: `my-0.5 mr-0.5 inline-flex h-(--size-control-sm) shrink-0 items-center gap-1 rounded-control border px-2 text-micro transition-colors duration-(--duration-instant) focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary ${puestos > 0 || panel
|
|
812
1300
|
? bySurface(sup, "border-primary/30 bg-primary/8 text-primary", "border-chrome-link/35 bg-chrome-link/15 text-chrome-link")
|
|
813
|
-
: bySurface(sup, "border-transparent text-muted hover:bg-ink/5 hover:text-ink", "border-transparent text-chrome-muted hover:bg-chrome-ink/10 hover:text-chrome-ink")}`, children: [_jsx(ListFilter, { className: "size-(--size-icon-sm)", strokeWidth: 2, "aria-hidden": true }), puestos > 0 ? _jsx("span", { className: "text-micro tabular-nums", children: puestos }) : null] }))] }), trailing, open ? (_jsxs("div", { "data-ui": "search.suggestions", className: `absolute top-full z-30 mt-1 overflow-hidden rounded-ui-popover border border-ui-popover-border bg-ui-popover shadow-ui-popover ${
|
|
1301
|
+
: bySurface(sup, "border-transparent text-muted hover:bg-ink/5 hover:text-ink", "border-transparent text-chrome-muted hover:bg-chrome-ink/10 hover:text-chrome-ink")}`, children: [_jsx(ListFilter, { className: "size-(--size-icon-sm)", strokeWidth: 2, "aria-hidden": true }), puestos > 0 ? _jsx("span", { className: "text-micro tabular-nums", children: puestos }) : null] }))] }), trailing, open ? (_jsxs("div", { "data-ui": "search.suggestions", className: `absolute top-full z-30 mt-1 overflow-hidden rounded-ui-popover border border-ui-popover-border bg-ui-popover shadow-ui-popover ${
|
|
1302
|
+
/* As wide as what it offers, up to a reading width: two short rows stretched over a
|
|
1303
|
+
bar as wide as the page are two words lost in a band. */
|
|
1304
|
+
asTags
|
|
1305
|
+
? "left-0 w-max max-w-full"
|
|
1306
|
+
: "left-0 w-full max-w-(--container-suggestions)"}`, children: [openJoin === undefined ? null : (_jsxs("div", { className: "flex items-center gap-1.5 border-line border-b px-3 py-1.5 text-micro text-muted", children: [_jsx(CornerDownRight, { className: "size-3 shrink-0", strokeWidth: 2, "aria-hidden": true }), _jsx("span", { className: "min-w-0 truncate", children: copy.search.landsHere }), _jsx("span", { className: `shrink-0 rounded-pill px-1.5 ${chosenTone("canvas")}`, children: copy.search.joins[openJoin === "not" ? "none" : openJoin] })] })), asTags ? (
|
|
814
1307
|
/* A LIST, not a strip. You are CHOOSING: the eye goes down a
|
|
815
1308
|
column and so does the keyboard. Twelve attributes folded into three
|
|
816
1309
|
rows are twelve things to sweep in zigzag to find one. */
|
|
@@ -824,11 +1317,16 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
824
1317
|
: {}),
|
|
825
1318
|
active: at === active,
|
|
826
1319
|
onSelect: () => pick(one),
|
|
827
|
-
})) }) })) : (_jsxs(_Fragment, { children: [_jsx("div", { id: listId, role: "listbox", "aria-label": copy.search.suggestions, className: "max-h-96 overflow-y-auto p-1", children: items.map((item, at) =>
|
|
1320
|
+
})) }) })) : (_jsxs(_Fragment, { children: [_jsx("div", { id: listId, role: "listbox", "aria-label": copy.search.suggestions, className: "max-h-96 overflow-y-auto p-1", children: items.map((item, at) => item.kind === "heading" ? (
|
|
1321
|
+
/* A block's title is not an option: the keys skip it, a reader hears it as
|
|
1322
|
+
the group's start. */
|
|
1323
|
+
_jsx("div", { role: "presentation", className: "px-2 pt-2 pb-0.5 first:pt-1", children: _jsx(SuggestionRow, { item: item, open: false, onToggle: () => { } }) }, item.id)) : (_jsx("div", { id: optionId(at), role: "option", "aria-selected": at === active, ...(item.kind === "status" ? { "aria-disabled": true } : {}), "data-ui": item.kind === "advanced"
|
|
828
1324
|
? "search.advanced"
|
|
829
|
-
: item.kind === "
|
|
830
|
-
? "search.
|
|
831
|
-
:
|
|
1325
|
+
: item.kind === "recent"
|
|
1326
|
+
? "search.recent"
|
|
1327
|
+
: item.kind === "suggestion" && item.child !== true
|
|
1328
|
+
? "search.suggestion"
|
|
1329
|
+
: "search.record",
|
|
832
1330
|
/* The input keeps the focus: pressing an option must not take it. */
|
|
833
1331
|
onMouseDown: (event) => event.preventDefault(), onClick: () => {
|
|
834
1332
|
if (item.kind === "suggestion" && item.suggestion.kind === "unfold") {
|
|
@@ -836,8 +1334,49 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
836
1334
|
}
|
|
837
1335
|
else
|
|
838
1336
|
choose(item);
|
|
839
|
-
}, onMouseEnter: selectable(item) ? () => setActiveId(item.id) : undefined, className: `flex w-full items-center gap-2 rounded-ui-option px-2 py-1.5 text-left text-meta transition-colors duration-(--duration-instant) ${item.kind === "status" ? "cursor-default" : "cursor-pointer"} ${item.kind === "advanced" ? "mt-1" : ""} ${at === active ? "bg-ui-option-active" : selectable(item) ? "hover:bg-ink/4" : ""}`, children: _jsx(SuggestionRow, { item: item, open: item.id === unfoldedRow?.id, onToggle: () => toggle(item.id), ...(renderRecord === undefined ? {} : { renderRecord }) }) }, item.id))) }), _jsx(
|
|
840
|
-
|
|
1337
|
+
}, onMouseEnter: selectable(item) ? () => setActiveId(item.id) : undefined, className: `flex w-full items-center gap-2 rounded-ui-option px-2 py-1.5 text-left text-meta transition-colors duration-(--duration-instant) ${item.kind === "status" ? "cursor-default" : "cursor-pointer"} ${item.kind === "advanced" ? "mt-1" : ""} ${at === active ? "bg-ui-option-active" : selectable(item) ? "hover:bg-ink/4" : ""}`, children: _jsx(SuggestionRow, { item: item, open: item.id === unfoldedRow?.id, onToggle: () => toggle(item.id), ...(renderRecord === undefined ? {} : { renderRecord }) }) }, item.id))) }), _jsx(KeysHint, { keys: [
|
|
1338
|
+
[["↑", "↓"], copy.search.keys.move],
|
|
1339
|
+
[[keysLabel("Enter", platform)], copy.search.keys.put],
|
|
1340
|
+
[["→"], copy.search.keys.open],
|
|
1341
|
+
...(ghost === undefined
|
|
1342
|
+
? []
|
|
1343
|
+
: [[["Tab"], copy.search.keys.complete]]),
|
|
1344
|
+
[[keysLabel("Escape", platform)], copy.search.keys.undo],
|
|
1345
|
+
...(columns.length === 0 && onOpenBuilder === undefined
|
|
1346
|
+
? []
|
|
1347
|
+
: [
|
|
1348
|
+
[
|
|
1349
|
+
[keysLabel("Alt+ArrowDown", platform)],
|
|
1350
|
+
copy.search.keys.panel,
|
|
1351
|
+
],
|
|
1352
|
+
]),
|
|
1353
|
+
...(onOpenBuilder === undefined
|
|
1354
|
+
? []
|
|
1355
|
+
: [
|
|
1356
|
+
[
|
|
1357
|
+
[keysLabel("Mod+Enter", platform)],
|
|
1358
|
+
copy.search.keys.advanced,
|
|
1359
|
+
],
|
|
1360
|
+
]),
|
|
1361
|
+
] })] }))] })) : null, panel && (columns.length > 0 || onOpenBuilder !== undefined) ? (_jsx(Overlay, { children: _jsxs("div", { ...mergeProps(overlayProps, positionProps), ref: panelBox, id: id, "data-react-aria-top-layer": "", "data-ui": "search.panel", onKeyDown: walkPanel, className: "z-30 flex w-max max-w-(--container-cuts) flex-wrap overflow-hidden rounded-ui-popover border border-ui-popover-border bg-ui-popover shadow-ui-popover", children: [columns.map((c, i) => {
|
|
1362
|
+
const total = c.groups?.reduce((n, g) => n + g.options.length, 0) ?? 0;
|
|
1363
|
+
const query = find[c.title] ?? "";
|
|
1364
|
+
const needle = fold(query.trim());
|
|
1365
|
+
const shown = needle === ""
|
|
1366
|
+
? c.groups
|
|
1367
|
+
: c.groups
|
|
1368
|
+
?.map((g) => ({
|
|
1369
|
+
...g,
|
|
1370
|
+
options: g.options.filter((o) => fold(`${o.label} ${o.hint ?? ""}`).includes(needle)),
|
|
1371
|
+
}))
|
|
1372
|
+
.filter((g) => g.options.length > 0);
|
|
1373
|
+
return (_jsxs("div", { "data-cuts-column": "", className: `flex min-w-48 flex-1 flex-col ${i === 0 ? "" : "border-t border-line sm:border-t-0 sm:border-l"}`, children: [_jsxs("div", { className: "flex items-center gap-2 px-2.5 pt-2.5 pb-1 text-meta font-semibold text-ink", children: [_jsx(c.icon, { className: "size-(--size-icon-sm) shrink-0 text-muted", strokeWidth: 2, "aria-hidden": true }), c.title] }), c.content !== undefined || total <= FIND_AFTER ? null : (_jsx("div", { className: "px-2 pb-1", children: _jsx("input", { type: "search", value: query, onChange: (event) => setFind((before) => ({ ...before, [c.title]: event.target.value })), placeholder: fillCopy(copy.search.findIn, {
|
|
1374
|
+
column: c.title.toLowerCase(),
|
|
1375
|
+
}), "aria-label": fillCopy(copy.search.findIn, {
|
|
1376
|
+
column: c.title.toLowerCase(),
|
|
1377
|
+
}), className: "h-(--size-control-sm) w-full rounded-control border border-ui-control-border bg-ui-control px-2 text-micro text-ink outline-none placeholder:text-muted focus:border-primary/60" }) })), _jsx("div", { className: "flex max-h-96 flex-col gap-0.5 overflow-y-auto p-1", children: c.content ??
|
|
1378
|
+
(shown === undefined || shown.length === 0 ? (_jsx("p", { className: "px-1.5 py-1 text-micro text-muted", children: copy.menu.empty })) : (shown.map((g, gi) => (_jsx(Group, { group: g, first: gi === 0, checks: c.checks === true, onSelect: c.onSelect, forceOpen: needle !== "" }, g.label ?? gi))))) })] }, c.title));
|
|
1379
|
+
}), onOpenBuilder === undefined ? null : (_jsx("div", { className: "w-full border-t border-line p-1.5", children: _jsxs("button", { type: "button", "data-ui": "search.advanced", title: copy.search.openBuilder, onClick: () => {
|
|
841
1380
|
onOpenBuilder();
|
|
842
1381
|
setPanel(false);
|
|
843
1382
|
}, className: "flex w-full items-center gap-2 rounded-ui-option px-2 py-1.5 text-left text-meta font-medium text-primary transition-colors duration-(--duration-instant) hover:bg-primary/8 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary", children: [_jsx(SlidersHorizontal, { className: "size-(--size-icon-sm)", strokeWidth: 2, "aria-hidden": true }), copy.search.advanced] }) }))] }) })) : null] }));
|