@sincpro/web-ui 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -0
- 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/attachments/Attachments.d.ts +7 -1
- package/dist/components/attachments/Attachments.js +8 -2
- package/dist/components/board/Board.d.ts +32 -2
- package/dist/components/board/Board.js +27 -4
- package/dist/components/board/index.d.ts +1 -1
- package/dist/components/board/index.js +2 -1
- 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 +27 -27
- 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/NavigationTree.js +2 -2
- 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 +140 -117
- 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.d.ts +9 -2
- package/dist/components/shell/AppFrame.js +102 -14
- package/dist/components/shell/Sidebar.d.ts +34 -0
- package/dist/components/shell/Sidebar.js +32 -0
- package/dist/components/shell/TopBar.d.ts +2 -0
- package/dist/components/shell/TopBar.js +13 -9
- package/dist/components/shell/index.d.ts +2 -0
- package/dist/components/shell/index.js +5 -1
- package/dist/components/shell/sidebarDrawer.d.ts +26 -0
- package/dist/components/shell/sidebarDrawer.js +22 -0
- 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 +109 -94
- package/dist/foundations/copy.es.js +10 -2
- package/dist/foundations/copy.js +10 -2
- 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/field/DropZone.d.ts +22 -3
- package/dist/primitives/field/DropZone.js +33 -12
- package/dist/primitives/menu/Menu.d.ts +10 -6
- package/dist/primitives/menu/Menu.js +4 -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 +4 -30
- package/dist/primitives/tag/Count.d.ts +23 -0
- package/dist/primitives/tag/Count.js +59 -0
- package/dist/primitives/tag/index.d.ts +1 -0
- package/dist/primitives/tag/index.js +5 -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/primitives/value/Metric.d.ts +7 -2
- package/dist/primitives/value/Metric.js +12 -4
- package/dist/tokens.css +164 -57
- 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
|
@@ -8,23 +8,23 @@ import { bySurface, useSurface } from "../../foundations/surface.js";
|
|
|
8
8
|
import { Tags } from "../../primitives/tag/Tags.js";
|
|
9
9
|
import { ChevronRight, CornerDownRight, ListFilter, Search, SlidersHorizontal, X, } from "lucide-react";
|
|
10
10
|
import { Fragment, useEffect, useId, useRef, useState } from "react";
|
|
11
|
-
import { useOverlay } from "react-aria";
|
|
11
|
+
import { mergeProps, Overlay, useOverlay, useOverlayPosition } from "react-aria";
|
|
12
12
|
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,36 @@ 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
|
+
/* Which edge of the field the panel hangs from. It is wider than the field when the
|
|
38
|
+
field is narrow, so it opens toward the side of the screen with room: from the start
|
|
39
|
+
of a field on the left of a page, from its end on the right. */
|
|
40
|
+
const [panelSide, setPanelSide] = useState("end");
|
|
41
|
+
/** The step the question being written is at: no field, with a field, or
|
|
42
|
+
* with a field and operator. */
|
|
39
43
|
const [step, setStep] = useState({});
|
|
40
|
-
/**
|
|
41
|
-
* Enter
|
|
44
|
+
/** Which of the offered is marked. It starts on the first, which is the one
|
|
45
|
+
* Enter takes without going down even once. */
|
|
42
46
|
const [active, setActive] = useState(0);
|
|
43
47
|
/**
|
|
44
|
-
*
|
|
48
|
+
* The OPEN group: where the next thing written lands.
|
|
45
49
|
*
|
|
46
|
-
* `null`
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
+
* `null` is «at the end of the list», which is the normal case. It is opened with `#and` and
|
|
51
|
+
* closed with Escape or by choosing another — a group that cannot be closed is a
|
|
52
|
+
* trap in which everything written afterwards ends up inside without anybody
|
|
53
|
+
* having asked for it.
|
|
50
54
|
*/
|
|
51
55
|
const [openGroup, setOpenGroup] = useState(null);
|
|
52
|
-
/*
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
/* Which node is open is DERIVED from the path and the tree, and is not stored
|
|
57
|
+
apart: stored, the day somebody changes its conjunction from the chip
|
|
58
|
+
there are two truths about the same thing. */
|
|
55
59
|
const openNode = openGroup === null ? undefined : at(criteria, openGroup);
|
|
56
60
|
const openJoin = openNode?.kind === "join" ? openNode.join : undefined;
|
|
57
61
|
/**
|
|
58
|
-
*
|
|
62
|
+
* Close the open node: what follows lands outside again.
|
|
59
63
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
64
|
+
* If it was left EMPTY it is removed. Opening it and putting nothing leaves a bracket that does not
|
|
65
|
+
* group anything, and somebody would have to discover that it is removed with the × of a
|
|
66
|
+
* chip that says nothing inside.
|
|
63
67
|
*/
|
|
64
68
|
function closeGroup() {
|
|
65
69
|
if (openGroup !== null && openNode?.kind === "join" && openNode.of.length === 0) {
|
|
@@ -68,9 +72,9 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
68
72
|
setOpenGroup(null);
|
|
69
73
|
input.current?.focus();
|
|
70
74
|
}
|
|
71
|
-
/*
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
/* How many things are set, for the funnel's number. The ones on TOP are counted and not the leaves:
|
|
76
|
+
«three» has to be what is seen in the bar, and what
|
|
77
|
+
is seen is a group, not its two conditions. */
|
|
74
78
|
const puestos = criteria.length;
|
|
75
79
|
const input = useRef(null);
|
|
76
80
|
const box = useRef(null);
|
|
@@ -83,50 +87,50 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
83
87
|
const listId = useId();
|
|
84
88
|
const optionId = (at) => `${listId}-${at}`;
|
|
85
89
|
/**
|
|
86
|
-
*
|
|
90
|
+
* The fields that can be asked about.
|
|
87
91
|
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
92
|
+
* With a model, they come from it with their type, their operators and their relations —and
|
|
93
|
+
* then the bar knows that «total» accepts «menor que» and «estado» only
|
|
94
|
+
* three values. Without a model, a facet is a text field and nothing more: it is
|
|
95
|
+
* exactly what a list could declare until now, drawn through the
|
|
96
|
+
* same path. Two paths would be two bars.
|
|
93
97
|
*/
|
|
94
98
|
const fields = model === undefined
|
|
95
99
|
? facets.map((facet) => ({
|
|
96
100
|
field: facet.id,
|
|
97
101
|
label: facet.label,
|
|
98
102
|
kind: "text",
|
|
99
|
-
/*
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
/* The three that can be asked of a text without knowing anything more about
|
|
104
|
+
it. With only one —«contiene»— the comparison step offered a
|
|
105
|
+
button and nothing to choose, which is worse than not having the step. A model
|
|
106
|
+
publishes its own and these are not used. */
|
|
103
107
|
ops: ["like", "=", "!="],
|
|
104
108
|
}))
|
|
105
109
|
: queryFields(model, copy.locale);
|
|
106
|
-
/*
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
/* What is marked goes back to the first when what is offered changes: leaving the mark on the
|
|
111
|
+
fourth row while you keep writing makes Enter take something that is no
|
|
112
|
+
longer what the screen says. */
|
|
109
113
|
const suggestions = suggest({
|
|
110
114
|
...(step.field === undefined ? {} : { field: step.field }),
|
|
111
115
|
...(step.op === undefined ? {} : { op: step.op }),
|
|
112
116
|
text,
|
|
113
117
|
}, fields, { literal: literal !== undefined });
|
|
114
|
-
/*
|
|
115
|
-
|
|
118
|
+
/* What was typed, already read: needed here to know whether an
|
|
119
|
+
ATTRIBUTE is being chosen —what starts with `#`— and to draw chips instead of rows. */
|
|
116
120
|
const asked = readTyped(text);
|
|
117
|
-
/*
|
|
118
|
-
|
|
121
|
+
/* It opens when there is something to offer AND somebody has started: typing, or
|
|
122
|
+
choosing a field, which is already having started. */
|
|
119
123
|
const open = suggestions.length > 0 && (text.trim() !== "" || step.field !== undefined);
|
|
120
|
-
/*
|
|
121
|
-
|
|
124
|
+
/* CHIPS are chosen when what is chosen is an attribute or a comparison, and
|
|
125
|
+
rows when what is chosen is a whole question. */
|
|
122
126
|
const asTags = asked.attribute === true || (step.field !== undefined && step.op === undefined);
|
|
123
127
|
const shown = suggestions.map((one) => one.id).join("\u0000");
|
|
124
128
|
useEffect(() => {
|
|
125
129
|
setActive(0);
|
|
126
130
|
}, [shown]);
|
|
127
|
-
/**
|
|
128
|
-
* panel
|
|
129
|
-
* no
|
|
131
|
+
/** A column with no options is not a column: the trigger would appear and the
|
|
132
|
+
* panel would open blank. Passing `[]` is what whoever has a list that
|
|
133
|
+
* declares no cut does, and it has to read the same as passing nothing. */
|
|
130
134
|
const withOptions = (groups) => groups.some((group) => group.options.length > 0);
|
|
131
135
|
const columns = [
|
|
132
136
|
...(filters === undefined || !withOptions(filters)
|
|
@@ -161,6 +165,20 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
161
165
|
isDismissable: true,
|
|
162
166
|
shouldCloseOnInteractOutside: (element) => box.current?.contains(element) !== true,
|
|
163
167
|
}, panelBox);
|
|
168
|
+
/* The panel floats in the page's overlay layer (`Overlay`, a portal React Aria stacks with
|
|
169
|
+
dialogs), placed against the field: a list's bar clips its search box sideways
|
|
170
|
+
(`ListingBar`, so the field never paints over «1–80») and a page may clip its card, and a
|
|
171
|
+
panel drawn inside them was cut wherever it outgrew the field. Placed this way it is as
|
|
172
|
+
wide as `--container-cuts`, inside the screen, toward the side with room. */
|
|
173
|
+
const { overlayProps: positionProps } = useOverlayPosition({
|
|
174
|
+
targetRef: box,
|
|
175
|
+
overlayRef: panelBox,
|
|
176
|
+
placement: panelSide === "start" ? "bottom start" : "bottom end",
|
|
177
|
+
offset: 4,
|
|
178
|
+
containerPadding: 16,
|
|
179
|
+
shouldFlip: false,
|
|
180
|
+
isOpen: panel,
|
|
181
|
+
});
|
|
164
182
|
/* With the focus still in the bar (the input, the button) and the panel open, Escape is
|
|
165
183
|
the panel's too — used up the same way, so it does not reach the dialog either. With the
|
|
166
184
|
panel closed, Escape is not the bar's and goes on to whoever owns it. */
|
|
@@ -173,11 +191,11 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
173
191
|
toolsButton.current?.focus();
|
|
174
192
|
};
|
|
175
193
|
/**
|
|
176
|
-
*
|
|
194
|
+
* A WHOLE QUESTION enters as an instance, and the bar goes back to the start.
|
|
177
195
|
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
196
|
+
* It lands inside the OPEN group if there is one —what `#and` does— and at the end of
|
|
197
|
+
* the list if not. It is the only thing the bar decides about where things go:
|
|
198
|
+
* the rest is decided by whoever has the list.
|
|
181
199
|
*/
|
|
182
200
|
/** A finished instance, where the next one goes: the end, or the group left open. */
|
|
183
201
|
function put(one) {
|
|
@@ -190,13 +208,13 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
190
208
|
}
|
|
191
209
|
function commit(field, op, value) {
|
|
192
210
|
const one = filterCriteria(
|
|
193
|
-
/*
|
|
194
|
-
«está vacío»:
|
|
195
|
-
|
|
211
|
+
/* The one that takes no value travels with `true`, which is what the engine expects of
|
|
212
|
+
«está vacío»: sending it the empty string would be asking for the field that
|
|
213
|
+
is "". */
|
|
196
214
|
{ field: field.field, operator: op, value: withoutValue(op) ? true : value }, describeCondition(field, op, value));
|
|
197
215
|
put(one);
|
|
198
216
|
}
|
|
199
|
-
/**
|
|
217
|
+
/** What was chosen in the dropdown, depending on what kind it is. */
|
|
200
218
|
function pick(suggestion) {
|
|
201
219
|
if (suggestion.kind === "field") {
|
|
202
220
|
setStep({ field: suggestion.field });
|
|
@@ -210,10 +228,10 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
210
228
|
return;
|
|
211
229
|
}
|
|
212
230
|
if (suggestion.kind === "group") {
|
|
213
|
-
/*
|
|
214
|
-
|
|
215
|
-
`#and`
|
|
216
|
-
|
|
231
|
+
/* Opening a group is putting an EMPTY node and remembering that what comes lands
|
|
232
|
+
inside. Empty and not with the previous stuff forced in: whoever writes
|
|
233
|
+
`#and` is saying «what follows goes together», not «group what I already
|
|
234
|
+
put». */
|
|
217
235
|
const node = {
|
|
218
236
|
id: criteriaId("n"),
|
|
219
237
|
kind: "join",
|
|
@@ -235,7 +253,7 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
235
253
|
}
|
|
236
254
|
commit(suggestion.field, suggestion.op, suggestion.value);
|
|
237
255
|
}
|
|
238
|
-
/**
|
|
256
|
+
/** The node with one more instance inside. */
|
|
239
257
|
function addTo(node, one) {
|
|
240
258
|
return node === undefined || node.kind !== "join"
|
|
241
259
|
? one
|
|
@@ -247,12 +265,12 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
247
265
|
magnifier, a word of input and the buttons; a narrower container scrolls, it does
|
|
248
266
|
not stack controls on top of each other. */
|
|
249
267
|
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
|
|
268
|
+
/* On the chrome what defines the field is the BORDER, not the fill. The
|
|
269
|
+
blue is already almost black, so sinking it gives no contrast (1.05:1) and
|
|
270
|
+
raising it gives 1.21:1 — in both cases the field does not read as a
|
|
271
|
+
field, which was «it does not draw attention». Ink at 45 % is the first
|
|
272
|
+
border that passes 3:1 against the fill AND against the chrome, which is what
|
|
273
|
+
1.4.11 asks of a control. */
|
|
256
274
|
"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
275
|
/* From the deepest index up, so each removal leaves the next path valid. */
|
|
258
276
|
const sorted = [...paths].sort((a, b) => (b[0] ?? 0) - (a[0] ?? 0));
|
|
@@ -264,17 +282,17 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
264
282
|
onCriteriaChange(replaceAt(criteria, path, { ...node, join }));
|
|
265
283
|
}, onRemove: (path) => {
|
|
266
284
|
onCriteriaChange(removeAt(criteria, path));
|
|
267
|
-
/*
|
|
268
|
-
|
|
285
|
+
/* If what was removed was the open group, it stops being so: writing
|
|
286
|
+
inside something that no longer exists is writing into the air. */
|
|
269
287
|
if (openGroup !== null && path.join(".") === openGroup.join(".")) {
|
|
270
288
|
setOpenGroup(null);
|
|
271
289
|
}
|
|
272
290
|
} }), _jsx(Tags, { surface: sup, items: [
|
|
273
|
-
/*
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
291
|
+
/* INSIDE WHAT is being written, first: it is what wraps
|
|
292
|
+
the rest of the draft, and it is the only chip that is removed to
|
|
293
|
+
CLOSE rather than to undo a step. Without it, `#and` opened
|
|
294
|
+
a group and the only thing that said so was that the next question
|
|
295
|
+
appeared in a place nobody chose by looking. */
|
|
278
296
|
...(openJoin === undefined
|
|
279
297
|
? []
|
|
280
298
|
: [
|
|
@@ -322,50 +340,50 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
322
340
|
] }), _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
341
|
? { "aria-activedescendant": optionId(active) }
|
|
324
342
|
: {}), value: text, onChange: (e) => setText(e.target.value), onKeyDown: (e) => {
|
|
325
|
-
/*
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
343
|
+
/* Backspace with the field empty removes the LAST instance: the gesture
|
|
344
|
+
that already exists in any chip field and the only one that is
|
|
345
|
+
discovered without anybody explaining it. The last and not the last of
|
|
346
|
+
its kind — now they are a single list, so there is no order of
|
|
347
|
+
preference to remember. */
|
|
330
348
|
if (e.key === "Backspace" && text === "") {
|
|
331
349
|
if (criteria.length > 0) {
|
|
332
350
|
onCriteriaChange(removeAt(criteria, [criteria.length - 1]));
|
|
333
351
|
}
|
|
334
352
|
return;
|
|
335
353
|
}
|
|
336
|
-
/*
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
354
|
+
/* The arrows TRAVERSE what is offered and Enter takes what is
|
|
355
|
+
marked. Without this, typing «#nom» and going down did nothing: the
|
|
356
|
+
list was seen and could not be touched without the mouse, which is
|
|
357
|
+
precisely what a search bar cannot ask for. */
|
|
340
358
|
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
341
359
|
if (suggestions.length === 0)
|
|
342
360
|
return;
|
|
343
361
|
e.preventDefault();
|
|
344
362
|
setActive((current) => {
|
|
345
363
|
const next = e.key === "ArrowDown" ? current + 1 : current - 1;
|
|
346
|
-
/*
|
|
347
|
-
|
|
364
|
+
/* It wraps around: with five fields, going down six times returns to the
|
|
365
|
+
first instead of getting stuck on the last. */
|
|
348
366
|
return (next + suggestions.length) % suggestions.length;
|
|
349
367
|
});
|
|
350
368
|
return;
|
|
351
369
|
}
|
|
352
|
-
/* Enter
|
|
353
|
-
|
|
354
|
-
|
|
370
|
+
/* Enter takes what is MARKED, which starts out being the first — and the
|
|
371
|
+
first is the most likely: with «test» the first text field,
|
|
372
|
+
with «<= 100» the only one that can answer it. */
|
|
355
373
|
if (e.key === "Enter") {
|
|
356
374
|
e.preventDefault();
|
|
357
375
|
const chosen = suggestions[active] ?? suggestions[0];
|
|
358
376
|
if (chosen !== undefined)
|
|
359
377
|
pick(chosen);
|
|
360
378
|
}
|
|
361
|
-
/* Escape
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
379
|
+
/* Escape UNDOES, one step at a time and always the last: first what is
|
|
380
|
+
written, then the comparison, then the field. Whoever
|
|
381
|
+
got the field wrong wants to change it, not start over — and
|
|
382
|
+
whoever is not building anything does not expect anything to happen.
|
|
365
383
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
384
|
+
Before, it only dismantled the step when a field had already been chosen,
|
|
385
|
+
so with «vent» half-written it did nothing: the key that
|
|
386
|
+
everybody presses to undo did not undo. */
|
|
369
387
|
if (e.key === "Escape") {
|
|
370
388
|
if (text !== "") {
|
|
371
389
|
e.preventDefault();
|
|
@@ -385,8 +403,8 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
385
403
|
setStep({});
|
|
386
404
|
return;
|
|
387
405
|
}
|
|
388
|
-
/*
|
|
389
|
-
|
|
406
|
+
/* And at the end, the group: the last thing opened is the last thing
|
|
407
|
+
undone. */
|
|
390
408
|
if (openGroup !== null) {
|
|
391
409
|
e.preventDefault();
|
|
392
410
|
e.stopPropagation();
|
|
@@ -399,24 +417,29 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
399
417
|
: criteria.length === 0
|
|
400
418
|
? (placeholder ?? copy.search.placeholder)
|
|
401
419
|
: "",
|
|
402
|
-
/*
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
420
|
+
/* WITH A FIELD CHOSEN, what is written is the VALUE — and it is drawn
|
|
421
|
+
as the chip it will become, behind the other two. It is not an
|
|
422
|
+
ornament: the draft is read whole —«nombre · contiene · vent▌»—
|
|
423
|
+
before existing as a cut, so you see what it will end up as
|
|
424
|
+
before it ends up. And it is still the input: nothing is duplicated, and
|
|
425
|
+
nothing becomes a filter until somebody presses Enter or
|
|
426
|
+
chooses from the list.
|
|
409
427
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
428
|
+
The width is asked for by the CONTENT —`field-sizing`— so the chip
|
|
429
|
+
grows with what is written instead of reserving an empty band. Where it
|
|
430
|
+
is not available, the input stretches as always. */
|
|
413
431
|
style: step.field === undefined ? undefined : { fieldSizing: "content" }, className: step.field === undefined
|
|
414
432
|
? `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
433
|
: `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: () => {
|
|
416
434
|
onCriteriaChange([]);
|
|
417
435
|
setOpenGroup(null);
|
|
418
436
|
input.current?.focus();
|
|
419
|
-
}, "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: () =>
|
|
437
|
+
}, "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: () => {
|
|
438
|
+
const rect = box.current?.getBoundingClientRect();
|
|
439
|
+
if (!panel && rect !== undefined)
|
|
440
|
+
setPanelSide(window.innerWidth - rect.left >= rect.right ? "start" : "end");
|
|
441
|
+
setPanel((v) => !v);
|
|
442
|
+
}, "aria-expanded": panel, "aria-controls": panel ? id : undefined, "aria-label": puestos === 0
|
|
420
443
|
? copy.search.tools
|
|
421
444
|
: fillCopy(puestos === 1 ? copy.search.toolsSetOne : copy.search.toolsSetMany, {
|
|
422
445
|
label: copy.search.tools,
|
|
@@ -424,9 +447,9 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
424
447
|
}), 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
448
|
? bySurface(sup, "border-accent/40 bg-accent/18 text-ink", "border-chrome-link/35 bg-chrome-link/15 text-chrome-link")
|
|
426
449
|
: 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
|
-
|
|
450
|
+
/* A LIST, not a strip. You are CHOOSING: the eye goes down a
|
|
451
|
+
column and so does the keyboard. Twelve attributes folded into three
|
|
452
|
+
rows are twelve things to sweep in zigzag to find one. */
|
|
430
453
|
_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
454
|
id: one.id,
|
|
432
455
|
label: one.label,
|
|
@@ -439,9 +462,9 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
439
462
|
onSelect: () => pick(one),
|
|
440
463
|
})) }) })) : (_jsx("div", { id: listId, role: "listbox", "aria-label": copy.search.suggestions, className: "p-1", children: suggestions.map((one, at) => (_jsxs("div", { id: optionId(at), role: "option", "aria-selected": at === active,
|
|
441
464
|
/* The input keeps the focus: pressing an option must not take it. */
|
|
442
|
-
onMouseDown: (event) => event.preventDefault(), onClick: () => pick(one), onMouseEnter: () => setActive(at), className: `flex w-full cursor-pointer items-baseline gap-1.5 rounded-control px-2 py-1.5 text-left text-meta transition-colors duration-(--duration-instant) ${at === active ? "bg-primary/8" : "hover:bg-ink/4"}`, children: [_jsx("span", { className: "shrink-0 font-medium text-ink", children: one.label }), one.kind === "condition" || one.kind === "literal" ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "shrink-0 text-muted", children: ":" }), _jsx("span", { className: "min-w-0 truncate font-mono text-micro text-ink", children: one.hint })] })) : one.kind === "field" && one.hint !== undefined ? (_jsx("span", { className: "inline-flex shrink-0 items-center rounded-pill border border-line-strong bg-ink/5 px-2 py-0.5 text-micro text-muted", children: one.hint })) : null] }, one.id))) }))] })) : null, panel && (columns.length > 0 || onOpenBuilder !== undefined) ? (_jsxs("div", { ...overlayProps, ref: panelBox, id: id,
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
465
|
+
onMouseDown: (event) => event.preventDefault(), onClick: () => pick(one), onMouseEnter: () => setActive(at), className: `flex w-full cursor-pointer items-baseline gap-1.5 rounded-control px-2 py-1.5 text-left text-meta transition-colors duration-(--duration-instant) ${at === active ? "bg-primary/8" : "hover:bg-ink/4"}`, children: [_jsx("span", { className: "shrink-0 font-medium text-ink", children: one.label }), one.kind === "condition" || one.kind === "literal" ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "shrink-0 text-muted", children: ":" }), _jsx("span", { className: "min-w-0 truncate font-mono text-micro text-ink", children: one.hint })] })) : one.kind === "field" && one.hint !== undefined ? (_jsx("span", { className: "inline-flex shrink-0 items-center rounded-pill border border-line-strong bg-ink/5 px-2 py-0.5 text-micro text-muted", children: one.hint })) : null] }, one.id))) }))] })) : null, panel && (columns.length > 0 || onOpenBuilder !== undefined) ? (_jsx(Overlay, { children: _jsxs("div", { ...mergeProps(overlayProps, positionProps), ref: panelBox, id: id, "data-react-aria-top-layer": "", className: "z-30 flex w-max max-w-(--container-cuts) flex-wrap overflow-hidden rounded-panel border border-line-strong bg-surface shadow-float", children: [columns.map((c, i) => (_jsxs("div", { className: `flex min-w-48 flex-1 flex-col ${i === 0 ? "" : "border-t border-line sm:border-t-0 sm:border-l"}`, children: [_jsx("div", { className: "border-b border-line px-2.5 py-1.5 text-micro font-medium text-muted", children: c.title }), _jsx("div", { className: "flex max-h-96 flex-col gap-0.5 overflow-y-auto p-1", children: c.content ??
|
|
466
|
+
c.groups?.map((g, gi) => (_jsx(Group, { group: g, first: gi === 0, onSelect: c.onSelect }, g.label ?? gi))) })] }, c.title))), onOpenBuilder === undefined ? null : (_jsx("div", { className: "w-full border-t border-line p-1", children: _jsxs("button", { type: "button", onClick: () => {
|
|
467
|
+
onOpenBuilder();
|
|
468
|
+
setPanel(false);
|
|
469
|
+
}, className: "flex w-full items-center gap-2 rounded-control px-1.5 py-1 text-left text-meta text-ink 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 }), copy.search.openBuilder] }) }))] }) })) : null] }));
|
|
447
470
|
}
|