@sincpro/web-ui 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/activity/Activity.d.ts +13 -14
- package/dist/components/activity/Activity.js +1 -1
- package/dist/components/activity/Messages.d.ts +5 -5
- package/dist/components/activity/Messages.js +8 -8
- package/dist/components/form/Form.js +6 -6
- package/dist/components/form/index.js +2 -2
- package/dist/components/frame/FrameView.d.ts +5 -5
- package/dist/components/frame/FrameView.js +4 -4
- package/dist/components/listing/GroupingLevels.d.ts +22 -22
- package/dist/components/listing/GroupingLevels.js +9 -9
- package/dist/components/listing/Listing.d.ts +11 -11
- package/dist/components/listing/Listing.js +11 -11
- package/dist/components/listing/ListingBar.js +11 -11
- package/dist/components/listing/Row.d.ts +19 -19
- package/dist/components/listing/Row.js +25 -25
- package/dist/components/listing/SortMenu.d.ts +36 -36
- package/dist/components/listing/SortMenu.js +6 -6
- package/dist/components/listing/grouping.d.ts +16 -16
- package/dist/components/listing/grouping.js +6 -6
- package/dist/components/listing/index.js +1 -1
- package/dist/components/listing/modelColumns.d.ts +25 -25
- package/dist/components/listing/modelColumns.js +24 -24
- package/dist/components/listing/pages.js +4 -4
- package/dist/components/listing/set.d.ts +18 -18
- package/dist/components/navigation/index.js +2 -2
- package/dist/components/record/RecordSkeleton.js +7 -7
- package/dist/components/search/CriteriaBuilder.d.ts +22 -22
- package/dist/components/search/CriteriaBuilder.js +31 -31
- package/dist/components/search/CriteriaChips.d.ts +9 -9
- package/dist/components/search/CriteriaChips.js +12 -12
- package/dist/components/search/FilterBuilder.d.ts +67 -67
- package/dist/components/search/FilterBuilder.js +104 -104
- package/dist/components/search/JoinWord.d.ts +1 -1
- package/dist/components/search/JoinWord.js +14 -14
- package/dist/components/search/JsonEditor.d.ts +8 -8
- package/dist/components/search/JsonEditor.js +16 -16
- package/dist/components/search/SearchBar.d.ts +34 -34
- package/dist/components/search/SearchBar.js +110 -110
- package/dist/components/search/criteria.d.ts +61 -61
- package/dist/components/search/criteria.js +39 -39
- package/dist/components/search/datePeriods.d.ts +47 -48
- package/dist/components/search/datePeriods.js +29 -29
- package/dist/components/search/dateRanges.d.ts +27 -27
- package/dist/components/search/dateRanges.js +16 -16
- package/dist/components/search/index.js +13 -13
- package/dist/components/search/model.d.ts +28 -28
- package/dist/components/search/model.js +21 -21
- package/dist/components/search/query.d.ts +71 -71
- package/dist/components/search/query.js +119 -119
- package/dist/components/shell/AppFrame.js +3 -3
- package/dist/components/shell/index.js +1 -1
- package/dist/foundations/calendar.d.ts +27 -27
- package/dist/foundations/calendar.js +72 -72
- package/dist/foundations/chart.d.ts +57 -57
- package/dist/foundations/chart.js +27 -27
- package/dist/foundations/copy.d.ts +96 -94
- package/dist/foundations/copy.es.js +1 -0
- package/dist/foundations/copy.js +1 -0
- package/dist/foundations/grouping.d.ts +175 -175
- package/dist/foundations/grouping.js +0 -0
- package/dist/foundations/index.d.ts +1 -1
- package/dist/foundations/index.js +21 -21
- package/dist/foundations/pivot.d.ts +133 -131
- package/dist/foundations/pivot.js +54 -54
- package/dist/foundations/pivotSheet.d.ts +36 -36
- package/dist/foundations/pivotSheet.js +0 -0
- package/dist/foundations/slots.d.ts +38 -38
- package/dist/foundations/slots.js +18 -18
- package/dist/foundations/sticky.d.ts +28 -28
- package/dist/foundations/sticky.js +59 -59
- package/dist/foundations/xlsx.d.ts +47 -47
- package/dist/foundations/xlsx.js +0 -0
- package/dist/primitives/block/Line.d.ts +4 -4
- package/dist/primitives/block/Line.js +28 -28
- package/dist/primitives/block/index.js +2 -2
- package/dist/primitives/cell/index.js +2 -2
- package/dist/primitives/choice/index.js +3 -3
- package/dist/primitives/date/Calendar.d.ts +7 -1
- package/dist/primitives/date/Calendar.js +13 -3
- package/dist/primitives/date/DatePicker.d.ts +4 -1
- package/dist/primitives/date/DatePicker.js +2 -2
- package/dist/primitives/date/index.js +3 -3
- package/dist/primitives/disclosure/index.js +1 -1
- package/dist/primitives/menu/Menu.d.ts +3 -3
- package/dist/primitives/notice/Callout.d.ts +30 -30
- package/dist/primitives/notice/Callout.js +6 -6
- package/dist/primitives/overlay/index.js +3 -3
- package/dist/primitives/picker/Picker.d.ts +6 -0
- package/dist/primitives/picker/Picker.js +27 -4
- package/dist/primitives/picker/index.js +2 -2
- package/dist/primitives/table/DataTable.d.ts +32 -32
- package/dist/primitives/table/DataTable.js +24 -24
- package/dist/primitives/table/EditableTable.d.ts +10 -10
- package/dist/primitives/table/EditableTable.js +9 -9
- package/dist/primitives/table/ReportTable.js +7 -7
- package/dist/primitives/table/SheetTable.d.ts +13 -13
- package/dist/primitives/table/SheetTable.js +14 -14
- package/dist/primitives/table/Table.js +8 -8
- package/dist/primitives/tabs/Tabs.d.ts +46 -46
- package/dist/primitives/tabs/Tabs.js +7 -7
- package/dist/primitives/tag/index.js +2 -2
- package/dist/primitives/toolbar/index.js +1 -1
- package/dist/primitives/value/Copyable.d.ts +22 -22
- package/dist/primitives/value/Copyable.js +9 -9
- package/dist/tokens.css +17 -17
- package/dist/views/list/List.d.ts +36 -36
- package/dist/views/list/List.js +19 -19
- package/dist/views/list/ListView.js +74 -74
- package/dist/views/list/columns.d.ts +10 -10
- package/dist/views/list/columns.js +10 -10
- package/dist/views/list/derive.d.ts +30 -30
- package/dist/views/list/derive.js +49 -49
- package/dist/views/list/index.js +2 -2
- package/dist/views/list/presentations.js +3 -3
- package/dist/views/list/types.d.ts +109 -109
- package/dist/views/record/Record.d.ts +14 -14
- package/dist/views/record/Record.js +24 -24
- package/dist/views/record/index.js +1 -1
- package/package.json +1 -1
|
@@ -3,71 +3,71 @@ import type { ModelDefinition } from "./model.js";
|
|
|
3
3
|
import type { Surface } from "../../foundations/types.js";
|
|
4
4
|
import type { MenuGroup } from "../../primitives/menu/Menu.js";
|
|
5
5
|
import { type ReactNode } from "react";
|
|
6
|
-
/**
|
|
6
|
+
/** Where you can search. The domain declares it, not this piece. */
|
|
7
7
|
export interface SearchFacet {
|
|
8
8
|
id: string;
|
|
9
|
-
/**
|
|
9
|
+
/** How it reads in the suggestion and on the chip: «nombre», «columnas». */
|
|
10
10
|
label: string;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* The CONJUNCTION between two cuts: «y» or «o».
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
* mes»
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
15
|
+
* With `onToggle` it can be touched, and that is no ornament: «vencidas Y de este
|
|
16
|
+
* mes» and «vencidas O de este mes» are two completely different lists, and
|
|
17
|
+
* until now which of the two it was was decided inside and could not be changed
|
|
18
|
+
* without opening the builder. Without `onToggle` it is a word and nothing more — which is
|
|
19
|
+
* right between two axes, where AND is not an option.
|
|
20
20
|
*/
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
22
|
+
* What the bar needs. It is apart from the function because it is the contract: what
|
|
23
|
+
* a list has to give it for the bar to ask, and nothing more.
|
|
24
24
|
*/
|
|
25
25
|
export type SearchBarProps = {
|
|
26
26
|
facets: readonly SearchFacet[];
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
28
|
+
* The model, when the list has it.
|
|
29
29
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
30
|
+
* It is what turns the bar from «search a text in a field» into «ask a
|
|
31
|
+
* question»: from here come each field's type —and with it what can be
|
|
32
|
+
* written to it—, the operators it accepts, its possible values if it is an enum, and
|
|
33
|
+
* by which column a relational is searched. Without this, `facets` keeps working
|
|
34
|
+
* as always: each facet is a text field.
|
|
35
35
|
*/
|
|
36
36
|
model?: ModelDefinition;
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
38
|
+
* EVERYTHING the bar has set: the grouping levels and the filters, in
|
|
39
|
+
* a single list of instances.
|
|
40
40
|
*
|
|
41
|
-
*
|
|
42
|
-
* `criteria.ts`—:
|
|
43
|
-
*
|
|
44
|
-
*
|
|
41
|
+
* A single one and not three because they are the same with different kinds —see
|
|
42
|
+
* `criteria.ts`—: what enters through the hash sign, what is written by hand, what
|
|
43
|
+
* a declared filter brings with a name and what comes out of the builder are
|
|
44
|
+
* all instances, and that is why they are all read, touched and removed the same.
|
|
45
45
|
*/
|
|
46
46
|
criteria: readonly SearchCriteria[];
|
|
47
47
|
onCriteriaChange: (next: SearchCriteria[]) => void;
|
|
48
48
|
placeholder?: string;
|
|
49
|
-
/**
|
|
49
|
+
/** What the panel OFFERS. What is set does not come from here: it comes from `criteria`. */
|
|
50
50
|
filters?: readonly MenuGroup[];
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
52
|
+
* The grouping levels editor: `<GroupingLevels …/>`.
|
|
53
53
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
54
|
+
* It goes in the SAME panel column where the filters are, because it is the same
|
|
55
|
+
* question —«which part of this am I looking at»— and separating them forces opening two
|
|
56
|
+
* things to build a cut without being able to see both states at once.
|
|
57
57
|
*/
|
|
58
58
|
grouping?: ReactNode;
|
|
59
59
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
60
|
+
* Somebody wrote `#and`, `#or` or `#not` and the bar opened a node: this says
|
|
61
|
+
* which, in case whoever composes wants to do something more with it.
|
|
62
62
|
*/
|
|
63
63
|
onOpenGroup?: (join: CriteriaJoin) => void;
|
|
64
64
|
favorites?: readonly MenuGroup[];
|
|
65
65
|
onFilterSelect?: (id: string) => void;
|
|
66
66
|
onFavoriteSelect?: (id: string) => void;
|
|
67
67
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
68
|
+
* Opens the builder. It receives the PATH of the instance that was touched, when one
|
|
69
|
+
* was touched: the builder opens there, instead of opening on the first rule and
|
|
70
|
+
* forcing you to search for the one you were looking at among twelve.
|
|
71
71
|
*/
|
|
72
72
|
onOpenBuilder?: (path?: CriteriaPath) => void;
|
|
73
73
|
/**
|
|
@@ -80,12 +80,12 @@ export type SearchBarProps = {
|
|
|
80
80
|
* enum's value, a number a numeric field answers): then that goes first and this after it.
|
|
81
81
|
*/
|
|
82
82
|
literal?: (text: string) => BuiltCondition | BuiltFilter | null;
|
|
83
|
-
/**
|
|
83
|
+
/** What goes stuck to the field, on its right. */
|
|
84
84
|
trailing?: ReactNode;
|
|
85
85
|
/** How many facets the bar shows before folding the rest into «+N»; the grouping chain
|
|
86
86
|
* counts as one. On a narrow bar only the first shows. `Infinity` never folds. */
|
|
87
87
|
collapseAfter?: number;
|
|
88
|
-
/**
|
|
88
|
+
/** By default it inherits it from the surface that wraps it. */
|
|
89
89
|
surface?: Surface;
|
|
90
90
|
};
|
|
91
91
|
export declare function SearchBar({ facets, model, criteria, onCriteriaChange, placeholder, filters, grouping, onOpenGroup, favorites, onFilterSelect, onFavoriteSelect, onOpenBuilder, literal, trailing, collapseAfter, surface, }: SearchBarProps): import("react").JSX.Element;
|
|
@@ -13,18 +13,18 @@ function Option({ o, onSelect }) {
|
|
|
13
13
|
const Icon = o.icon;
|
|
14
14
|
return (_jsxs("button", { type: "button", disabled: o.disabled, onClick: () => onSelect?.(o.id), className: `flex w-full items-start gap-2 rounded-control px-1.5 py-1 text-left transition-colors duration-(--duration-instant) disabled:pointer-events-none disabled:opacity-45 hover:bg-primary/8 ${o.checked === true ? "bg-primary/6" : ""}`, children: [_jsx("span", { className: "mt-0.5 flex size-(--size-icon-sm) shrink-0 items-center justify-center", children: o.checked === true ? (_jsx("span", { className: "size-1.5 rounded-pill bg-primary" })) : Icon !== undefined ? (_jsx(Icon, { className: "size-(--size-icon-sm) text-muted", strokeWidth: 2 })) : (_jsx("span", { className: "size-3 rounded-pill border border-line-strong" })) }), _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 block truncate text-micro text-muted", children: o.hint }))] })] }));
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
/** A panel group. Collapsible when it asks —a date, which brings eleven
|
|
17
|
+
* options— and open from the start if it already has something ticked: otherwise what is set
|
|
18
|
+
* stays hidden behind a chevron and you have to guess where it is. */
|
|
19
19
|
function Group({ group, first, onSelect, }) {
|
|
20
20
|
const active = group.options.some((o) => o.checked === true);
|
|
21
21
|
const [open, setOpen] = useState(active);
|
|
22
22
|
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, onSelect: onSelect })] }, o.id))) }));
|
|
23
23
|
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 ? (
|
|
24
|
-
/*
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
/* The group's label goes in the TEXT column, not the edge one.
|
|
25
|
+
The column's band is already the title (medium, over the line). This
|
|
26
|
+
one is a step down: normal weight, and the same gap as the mark
|
|
27
|
+
so that «mostrar sólo» starts where «traídos» starts. */
|
|
28
28
|
_jsxs("div", { className: "flex items-center gap-2 px-1.5 pt-1 pb-0.5 text-micro text-muted", children: [_jsx("span", { className: "size-(--size-icon-sm) shrink-0", "aria-hidden": true }), group.label] })) : (_jsxs("button", { type: "button", onClick: () => setOpen(!open), "aria-expanded": open, className: "flex items-center gap-2 rounded-control px-1.5 py-1 text-left transition-colors duration-(--duration-instant) hover:bg-primary/8", children: [_jsx(ChevronRight, { className: `size-(--size-icon-sm) shrink-0 text-muted transition-transform duration-(--duration-instant) ${open ? "rotate-90" : ""}`, strokeWidth: 2, "aria-hidden": true }), _jsx("span", { className: `min-w-0 flex-1 truncate text-meta ${active ? "font-medium text-ink" : "text-ink"}`, children: group.label }), !active ? null : (_jsx("span", { className: "inline-flex shrink-0 items-center rounded-pill border border-accent/40 bg-accent/18 px-2 py-0.5 text-micro tabular-nums text-ink", children: group.options.filter((o) => o.checked === true).length }))] })), group.collapsible === true && !open ? null : (_jsx("div", { className: group.collapsible === true
|
|
29
29
|
? "flex flex-col gap-0.5 pl-(--spacing-indent)"
|
|
30
30
|
: "flex flex-col gap-0.5", children: options }))] }));
|
|
@@ -34,32 +34,32 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
34
34
|
const sup = useSurface(surface);
|
|
35
35
|
const [text, setText] = useState("");
|
|
36
36
|
const [panel, setPanel] = useState(false);
|
|
37
|
-
/**
|
|
38
|
-
*
|
|
37
|
+
/** The step the question being written is at: no field, with a field, or
|
|
38
|
+
* with a field and operator. */
|
|
39
39
|
const [step, setStep] = useState({});
|
|
40
|
-
/**
|
|
41
|
-
* Enter
|
|
40
|
+
/** Which of the offered is marked. It starts on the first, which is the one
|
|
41
|
+
* Enter takes without going down even once. */
|
|
42
42
|
const [active, setActive] = useState(0);
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
44
|
+
* The OPEN group: where the next thing written lands.
|
|
45
45
|
*
|
|
46
|
-
* `null`
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
46
|
+
* `null` is «at the end of the list», which is the normal case. It is opened with `#and` and
|
|
47
|
+
* closed with Escape or by choosing another — a group that cannot be closed is a
|
|
48
|
+
* trap in which everything written afterwards ends up inside without anybody
|
|
49
|
+
* having asked for it.
|
|
50
50
|
*/
|
|
51
51
|
const [openGroup, setOpenGroup] = useState(null);
|
|
52
|
-
/*
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
/* Which node is open is DERIVED from the path and the tree, and is not stored
|
|
53
|
+
apart: stored, the day somebody changes its conjunction from the chip
|
|
54
|
+
there are two truths about the same thing. */
|
|
55
55
|
const openNode = openGroup === null ? undefined : at(criteria, openGroup);
|
|
56
56
|
const openJoin = openNode?.kind === "join" ? openNode.join : undefined;
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
58
|
+
* Close the open node: what follows lands outside again.
|
|
59
59
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
60
|
+
* If it was left EMPTY it is removed. Opening it and putting nothing leaves a bracket that does not
|
|
61
|
+
* group anything, and somebody would have to discover that it is removed with the × of a
|
|
62
|
+
* chip that says nothing inside.
|
|
63
63
|
*/
|
|
64
64
|
function closeGroup() {
|
|
65
65
|
if (openGroup !== null && openNode?.kind === "join" && openNode.of.length === 0) {
|
|
@@ -68,9 +68,9 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
68
68
|
setOpenGroup(null);
|
|
69
69
|
input.current?.focus();
|
|
70
70
|
}
|
|
71
|
-
/*
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
/* How many things are set, for the funnel's number. The ones on TOP are counted and not the leaves:
|
|
72
|
+
«three» has to be what is seen in the bar, and what
|
|
73
|
+
is seen is a group, not its two conditions. */
|
|
74
74
|
const puestos = criteria.length;
|
|
75
75
|
const input = useRef(null);
|
|
76
76
|
const box = useRef(null);
|
|
@@ -83,50 +83,50 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
83
83
|
const listId = useId();
|
|
84
84
|
const optionId = (at) => `${listId}-${at}`;
|
|
85
85
|
/**
|
|
86
|
-
*
|
|
86
|
+
* The fields that can be asked about.
|
|
87
87
|
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
88
|
+
* With a model, they come from it with their type, their operators and their relations —and
|
|
89
|
+
* then the bar knows that «total» accepts «menor que» and «estado» only
|
|
90
|
+
* three values. Without a model, a facet is a text field and nothing more: it is
|
|
91
|
+
* exactly what a list could declare until now, drawn through the
|
|
92
|
+
* same path. Two paths would be two bars.
|
|
93
93
|
*/
|
|
94
94
|
const fields = model === undefined
|
|
95
95
|
? facets.map((facet) => ({
|
|
96
96
|
field: facet.id,
|
|
97
97
|
label: facet.label,
|
|
98
98
|
kind: "text",
|
|
99
|
-
/*
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
99
|
+
/* The three that can be asked of a text without knowing anything more about
|
|
100
|
+
it. With only one —«contiene»— the comparison step offered a
|
|
101
|
+
button and nothing to choose, which is worse than not having the step. A model
|
|
102
|
+
publishes its own and these are not used. */
|
|
103
103
|
ops: ["like", "=", "!="],
|
|
104
104
|
}))
|
|
105
105
|
: queryFields(model, copy.locale);
|
|
106
|
-
/*
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
/* What is marked goes back to the first when what is offered changes: leaving the mark on the
|
|
107
|
+
fourth row while you keep writing makes Enter take something that is no
|
|
108
|
+
longer what the screen says. */
|
|
109
109
|
const suggestions = suggest({
|
|
110
110
|
...(step.field === undefined ? {} : { field: step.field }),
|
|
111
111
|
...(step.op === undefined ? {} : { op: step.op }),
|
|
112
112
|
text,
|
|
113
113
|
}, fields, { literal: literal !== undefined });
|
|
114
|
-
/*
|
|
115
|
-
|
|
114
|
+
/* What was typed, already read: needed here to know whether an
|
|
115
|
+
ATTRIBUTE is being chosen —what starts with `#`— and to draw chips instead of rows. */
|
|
116
116
|
const asked = readTyped(text);
|
|
117
|
-
/*
|
|
118
|
-
|
|
117
|
+
/* It opens when there is something to offer AND somebody has started: typing, or
|
|
118
|
+
choosing a field, which is already having started. */
|
|
119
119
|
const open = suggestions.length > 0 && (text.trim() !== "" || step.field !== undefined);
|
|
120
|
-
/*
|
|
121
|
-
|
|
120
|
+
/* CHIPS are chosen when what is chosen is an attribute or a comparison, and
|
|
121
|
+
rows when what is chosen is a whole question. */
|
|
122
122
|
const asTags = asked.attribute === true || (step.field !== undefined && step.op === undefined);
|
|
123
123
|
const shown = suggestions.map((one) => one.id).join("\u0000");
|
|
124
124
|
useEffect(() => {
|
|
125
125
|
setActive(0);
|
|
126
126
|
}, [shown]);
|
|
127
|
-
/**
|
|
128
|
-
* panel
|
|
129
|
-
* no
|
|
127
|
+
/** A column with no options is not a column: the trigger would appear and the
|
|
128
|
+
* panel would open blank. Passing `[]` is what whoever has a list that
|
|
129
|
+
* declares no cut does, and it has to read the same as passing nothing. */
|
|
130
130
|
const withOptions = (groups) => groups.some((group) => group.options.length > 0);
|
|
131
131
|
const columns = [
|
|
132
132
|
...(filters === undefined || !withOptions(filters)
|
|
@@ -173,11 +173,11 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
173
173
|
toolsButton.current?.focus();
|
|
174
174
|
};
|
|
175
175
|
/**
|
|
176
|
-
*
|
|
176
|
+
* A WHOLE QUESTION enters as an instance, and the bar goes back to the start.
|
|
177
177
|
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
178
|
+
* It lands inside the OPEN group if there is one —what `#and` does— and at the end of
|
|
179
|
+
* the list if not. It is the only thing the bar decides about where things go:
|
|
180
|
+
* the rest is decided by whoever has the list.
|
|
181
181
|
*/
|
|
182
182
|
/** A finished instance, where the next one goes: the end, or the group left open. */
|
|
183
183
|
function put(one) {
|
|
@@ -190,13 +190,13 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
190
190
|
}
|
|
191
191
|
function commit(field, op, value) {
|
|
192
192
|
const one = filterCriteria(
|
|
193
|
-
/*
|
|
194
|
-
«está vacío»:
|
|
195
|
-
|
|
193
|
+
/* The one that takes no value travels with `true`, which is what the engine expects of
|
|
194
|
+
«está vacío»: sending it the empty string would be asking for the field that
|
|
195
|
+
is "". */
|
|
196
196
|
{ field: field.field, operator: op, value: withoutValue(op) ? true : value }, describeCondition(field, op, value));
|
|
197
197
|
put(one);
|
|
198
198
|
}
|
|
199
|
-
/**
|
|
199
|
+
/** What was chosen in the dropdown, depending on what kind it is. */
|
|
200
200
|
function pick(suggestion) {
|
|
201
201
|
if (suggestion.kind === "field") {
|
|
202
202
|
setStep({ field: suggestion.field });
|
|
@@ -210,10 +210,10 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
210
210
|
return;
|
|
211
211
|
}
|
|
212
212
|
if (suggestion.kind === "group") {
|
|
213
|
-
/*
|
|
214
|
-
|
|
215
|
-
`#and`
|
|
216
|
-
|
|
213
|
+
/* Opening a group is putting an EMPTY node and remembering that what comes lands
|
|
214
|
+
inside. Empty and not with the previous stuff forced in: whoever writes
|
|
215
|
+
`#and` is saying «what follows goes together», not «group what I already
|
|
216
|
+
put». */
|
|
217
217
|
const node = {
|
|
218
218
|
id: criteriaId("n"),
|
|
219
219
|
kind: "join",
|
|
@@ -235,7 +235,7 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
235
235
|
}
|
|
236
236
|
commit(suggestion.field, suggestion.op, suggestion.value);
|
|
237
237
|
}
|
|
238
|
-
/**
|
|
238
|
+
/** The node with one more instance inside. */
|
|
239
239
|
function addTo(node, one) {
|
|
240
240
|
return node === undefined || node.kind !== "join"
|
|
241
241
|
? one
|
|
@@ -247,12 +247,12 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
247
247
|
magnifier, a word of input and the buttons; a narrower container scrolls, it does
|
|
248
248
|
not stack controls on top of each other. */
|
|
249
249
|
className: "relative flex min-w-48 items-center gap-2", children: [_jsxs("div", { className: `@container/bar flex min-h-(--size-control-md) w-full min-w-0 items-start rounded-box border transition-colors duration-(--duration-instant) ${bySurface(sup, "border-line-strong bg-surface focus-within:border-primary/60",
|
|
250
|
-
/*
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
1.4.11
|
|
250
|
+
/* On the chrome what defines the field is the BORDER, not the fill. The
|
|
251
|
+
blue is already almost black, so sinking it gives no contrast (1.05:1) and
|
|
252
|
+
raising it gives 1.21:1 — in both cases the field does not read as a
|
|
253
|
+
field, which was «it does not draw attention». Ink at 45 % is the first
|
|
254
|
+
border that passes 3:1 against the fill AND against the chrome, which is what
|
|
255
|
+
1.4.11 asks of a control. */
|
|
256
256
|
"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) => {
|
|
257
257
|
/* From the deepest index up, so each removal leaves the next path valid. */
|
|
258
258
|
const sorted = [...paths].sort((a, b) => (b[0] ?? 0) - (a[0] ?? 0));
|
|
@@ -264,17 +264,17 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
264
264
|
onCriteriaChange(replaceAt(criteria, path, { ...node, join }));
|
|
265
265
|
}, onRemove: (path) => {
|
|
266
266
|
onCriteriaChange(removeAt(criteria, path));
|
|
267
|
-
/*
|
|
268
|
-
|
|
267
|
+
/* If what was removed was the open group, it stops being so: writing
|
|
268
|
+
inside something that no longer exists is writing into the air. */
|
|
269
269
|
if (openGroup !== null && path.join(".") === openGroup.join(".")) {
|
|
270
270
|
setOpenGroup(null);
|
|
271
271
|
}
|
|
272
272
|
} }), _jsx(Tags, { surface: sup, items: [
|
|
273
|
-
/*
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
273
|
+
/* INSIDE WHAT is being written, first: it is what wraps
|
|
274
|
+
the rest of the draft, and it is the only chip that is removed to
|
|
275
|
+
CLOSE rather than to undo a step. Without it, `#and` opened
|
|
276
|
+
a group and the only thing that said so was that the next question
|
|
277
|
+
appeared in a place nobody chose by looking. */
|
|
278
278
|
...(openJoin === undefined
|
|
279
279
|
? []
|
|
280
280
|
: [
|
|
@@ -322,50 +322,50 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
322
322
|
] }), _jsx("input", { ref: input, "aria-label": copy.choice.search, role: "combobox", "aria-autocomplete": "list", "aria-expanded": open, ...(open ? { "aria-controls": listId } : {}), ...(open && !asTags && suggestions[active] !== undefined
|
|
323
323
|
? { "aria-activedescendant": optionId(active) }
|
|
324
324
|
: {}), value: text, onChange: (e) => setText(e.target.value), onKeyDown: (e) => {
|
|
325
|
-
/*
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
325
|
+
/* Backspace with the field empty removes the LAST instance: the gesture
|
|
326
|
+
that already exists in any chip field and the only one that is
|
|
327
|
+
discovered without anybody explaining it. The last and not the last of
|
|
328
|
+
its kind — now they are a single list, so there is no order of
|
|
329
|
+
preference to remember. */
|
|
330
330
|
if (e.key === "Backspace" && text === "") {
|
|
331
331
|
if (criteria.length > 0) {
|
|
332
332
|
onCriteriaChange(removeAt(criteria, [criteria.length - 1]));
|
|
333
333
|
}
|
|
334
334
|
return;
|
|
335
335
|
}
|
|
336
|
-
/*
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
336
|
+
/* The arrows TRAVERSE what is offered and Enter takes what is
|
|
337
|
+
marked. Without this, typing «#nom» and going down did nothing: the
|
|
338
|
+
list was seen and could not be touched without the mouse, which is
|
|
339
|
+
precisely what a search bar cannot ask for. */
|
|
340
340
|
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
341
341
|
if (suggestions.length === 0)
|
|
342
342
|
return;
|
|
343
343
|
e.preventDefault();
|
|
344
344
|
setActive((current) => {
|
|
345
345
|
const next = e.key === "ArrowDown" ? current + 1 : current - 1;
|
|
346
|
-
/*
|
|
347
|
-
|
|
346
|
+
/* It wraps around: with five fields, going down six times returns to the
|
|
347
|
+
first instead of getting stuck on the last. */
|
|
348
348
|
return (next + suggestions.length) % suggestions.length;
|
|
349
349
|
});
|
|
350
350
|
return;
|
|
351
351
|
}
|
|
352
|
-
/* Enter
|
|
353
|
-
|
|
354
|
-
|
|
352
|
+
/* Enter takes what is MARKED, which starts out being the first — and the
|
|
353
|
+
first is the most likely: with «test» the first text field,
|
|
354
|
+
with «<= 100» the only one that can answer it. */
|
|
355
355
|
if (e.key === "Enter") {
|
|
356
356
|
e.preventDefault();
|
|
357
357
|
const chosen = suggestions[active] ?? suggestions[0];
|
|
358
358
|
if (chosen !== undefined)
|
|
359
359
|
pick(chosen);
|
|
360
360
|
}
|
|
361
|
-
/* Escape
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
361
|
+
/* Escape UNDOES, one step at a time and always the last: first what is
|
|
362
|
+
written, then the comparison, then the field. Whoever
|
|
363
|
+
got the field wrong wants to change it, not start over — and
|
|
364
|
+
whoever is not building anything does not expect anything to happen.
|
|
365
365
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
366
|
+
Before, it only dismantled the step when a field had already been chosen,
|
|
367
|
+
so with «vent» half-written it did nothing: the key that
|
|
368
|
+
everybody presses to undo did not undo. */
|
|
369
369
|
if (e.key === "Escape") {
|
|
370
370
|
if (text !== "") {
|
|
371
371
|
e.preventDefault();
|
|
@@ -385,8 +385,8 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
385
385
|
setStep({});
|
|
386
386
|
return;
|
|
387
387
|
}
|
|
388
|
-
/*
|
|
389
|
-
|
|
388
|
+
/* And at the end, the group: the last thing opened is the last thing
|
|
389
|
+
undone. */
|
|
390
390
|
if (openGroup !== null) {
|
|
391
391
|
e.preventDefault();
|
|
392
392
|
e.stopPropagation();
|
|
@@ -399,17 +399,17 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
399
399
|
: criteria.length === 0
|
|
400
400
|
? (placeholder ?? copy.search.placeholder)
|
|
401
401
|
: "",
|
|
402
|
-
/*
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
402
|
+
/* WITH A FIELD CHOSEN, what is written is the VALUE — and it is drawn
|
|
403
|
+
as the chip it will become, behind the other two. It is not an
|
|
404
|
+
ornament: the draft is read whole —«nombre · contiene · vent▌»—
|
|
405
|
+
before existing as a cut, so you see what it will end up as
|
|
406
|
+
before it ends up. And it is still the input: nothing is duplicated, and
|
|
407
|
+
nothing becomes a filter until somebody presses Enter or
|
|
408
|
+
chooses from the list.
|
|
409
409
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
410
|
+
The width is asked for by the CONTENT —`field-sizing`— so the chip
|
|
411
|
+
grows with what is written instead of reserving an empty band. Where it
|
|
412
|
+
is not available, the input stretches as always. */
|
|
413
413
|
style: step.field === undefined ? undefined : { fieldSizing: "content" }, className: step.field === undefined
|
|
414
414
|
? `h-7 ${criteria.length === 0 ? "min-w-24" : "min-w-16"} flex-1 bg-transparent text-meta outline-none ${bySurface(sup, "text-ink placeholder:text-muted", "text-chrome-ink placeholder:text-chrome-muted")}`
|
|
415
415
|
: `min-w-16 rounded-pill px-2 py-0.5 text-micro outline-none ${bySurface(sup, "bg-accent/18 text-ink placeholder:text-muted", "bg-chrome-link/20 text-chrome-ink placeholder:text-chrome-muted")}` })] }), puestos === 0 ? null : (_jsx("button", { type: "button", onClick: () => {
|
|
@@ -424,9 +424,9 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
424
424
|
}), 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
|
|
425
425
|
? bySurface(sup, "border-accent/40 bg-accent/18 text-ink", "border-chrome-link/35 bg-chrome-link/15 text-chrome-link")
|
|
426
426
|
: 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", { className: `absolute top-full z-30 mt-1 overflow-hidden rounded-panel border border-line-strong bg-surface shadow-float ${asTags ? "left-0 w-max max-w-full" : "right-0 left-0"}`, 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 border border-accent/40 bg-accent/18 px-1.5 text-ink", children: copy.search.joins[openJoin === "not" ? "none" : openJoin] })] })), asTags ? (
|
|
427
|
-
/*
|
|
428
|
-
|
|
429
|
-
|
|
427
|
+
/* A LIST, not a strip. You are CHOOSING: the eye goes down a
|
|
428
|
+
column and so does the keyboard. Twelve attributes folded into three
|
|
429
|
+
rows are twelve things to sweep in zigzag to find one. */
|
|
430
430
|
_jsx("div", { id: listId, className: "max-h-72 overflow-y-auto p-1", children: _jsx(Tags, { stack: true, surface: "canvas", label: step.field !== undefined ? copy.search.askOp : copy.search.askAttribute, items: suggestions.map((one, at) => ({
|
|
431
431
|
id: one.id,
|
|
432
432
|
label: one.label,
|