@protobase/ui 0.12.11 → 0.12.13
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/app/displays/display-controls.js +21 -9
- package/dist/app/list-page.js +71 -53
- package/dist/app/list-search.js +4 -3
- package/dist/app-shell/page-header.js +14 -8
- package/dist/filter-panel/combobox-options.js +12 -0
- package/dist/filter-panel/facet-combobox.js +131 -0
- package/dist/filter-panel/facet-group.js +1 -1
- package/dist/filter-panel/filter-menu.js +7 -2
- package/dist/filter-panel/filter-panel.js +34 -24
- package/dist/filter-panel/filter-state.js +23 -11
- package/dist/filter-panel/range-filter.js +3 -3
- package/dist/index.js +1 -1
- package/dist/live/filter-string.js +18 -9
- package/dist/live/reference-options.js +14 -0
- package/dist/live/use-filter-config.js +64 -37
- package/dist/live/use-reference-search.js +53 -0
- package/dist/live/view-fields.js +31 -14
- package/dist/package.js +1 -1
- package/dist/primitives/menu-keys.js +14 -0
- package/dist/primitives/menu-select.js +88 -0
- package/dist/shell/assets/app-Cn69QiC_.js +65 -0
- package/dist/shell/assets/{index-B7XSEKuk.js → index-Cog2ukQk.js} +1 -1
- package/dist/shell/assets/index-Crnlycqw.css +2 -0
- package/dist/shell/assets/{shared-protobase-ui-DhQ8wFhe.js → shared-protobase-ui-DzJvhCVz.js} +1 -1
- package/dist/shell/index.html +4 -4
- package/dist/shell/protobase.shell.json +1 -1
- package/package.json +4 -4
- package/dist/shell/assets/app-B2rZN97s.js +0 -65
- package/dist/shell/assets/index-otHceRXj.css +0 -2
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { cn } from "../../lib/cn.js";
|
|
1
2
|
import { humanize } from "../../live/naming.js";
|
|
2
3
|
import { displayChoices, sortFields } from "./list-displays.js";
|
|
3
4
|
import { parseSort } from "../list-order.js";
|
|
5
|
+
import { MenuSelect } from "../../primitives/menu-select.js";
|
|
4
6
|
import { Segmented } from "../../primitives/segmented.js";
|
|
5
7
|
import { Calendar, Columns3, LayoutGrid, List, SquareKanban, Table2 } from "lucide-react";
|
|
6
8
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -14,25 +16,35 @@ const icons = {
|
|
|
14
16
|
list: List,
|
|
15
17
|
calendar: Calendar
|
|
16
18
|
};
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
+
/**
|
|
20
|
+
* The list page's switch between the table and the view's displays, as buttons or, on a phone, as a menu; nothing for a
|
|
21
|
+
* list with only its table.
|
|
22
|
+
*/
|
|
23
|
+
const DisplaySwitch = ({ view, value, onChange, menu = false }) => {
|
|
19
24
|
const choices = displayChoices(view);
|
|
20
25
|
if (choices.length < 2) return null;
|
|
26
|
+
const options = choices.map((choice) => ({
|
|
27
|
+
value: choice.name,
|
|
28
|
+
label: choice.label,
|
|
29
|
+
icon: choice.icon === void 0 ? void 0 : icons[choice.icon]
|
|
30
|
+
}));
|
|
31
|
+
if (menu) return /* @__PURE__ */ jsx(MenuSelect, {
|
|
32
|
+
label: "Display",
|
|
33
|
+
value,
|
|
34
|
+
onChange,
|
|
35
|
+
options
|
|
36
|
+
});
|
|
21
37
|
return /* @__PURE__ */ jsx(Segmented, {
|
|
22
38
|
label: "Display",
|
|
23
39
|
size: "md",
|
|
24
40
|
value,
|
|
25
41
|
onChange,
|
|
26
|
-
options
|
|
27
|
-
value: choice.name,
|
|
28
|
-
label: choice.label,
|
|
29
|
-
icon: choice.icon === void 0 ? void 0 : icons[choice.icon]
|
|
30
|
-
}))
|
|
42
|
+
options
|
|
31
43
|
});
|
|
32
44
|
};
|
|
33
45
|
const directions = [["asc", "ascending"], ["desc", "descending"]];
|
|
34
46
|
/** The order of a display without column headers, over the sortable fields it shows and the order the list has now. */
|
|
35
|
-
const SortMenu = ({ model, view, display, orderBy, onChange }) => {
|
|
47
|
+
const SortMenu = ({ model, view, display, orderBy, onChange, className }) => {
|
|
36
48
|
const current = parseSort(orderBy);
|
|
37
49
|
const fields = sortFields(model, view, display);
|
|
38
50
|
const names = fields.includes(current.columnId) ? fields : [current.columnId, ...fields];
|
|
@@ -41,7 +53,7 @@ const SortMenu = ({ model, view, display, orderBy, onChange }) => {
|
|
|
41
53
|
"aria-label": "Sort",
|
|
42
54
|
value: `${current.columnId} ${current.direction}`,
|
|
43
55
|
onChange: (event) => onChange(event.target.value),
|
|
44
|
-
className: "h-8 rounded-md border border-border-strong bg-background px-2.5 text-[13px] shadow-sm focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/20",
|
|
56
|
+
className: cn("h-8 rounded-md border border-border-strong bg-background px-2.5 text-[13px] shadow-sm focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/20", className),
|
|
45
57
|
children: names.flatMap((name) => directions.map(([direction, word]) => /* @__PURE__ */ jsxs("option", {
|
|
46
58
|
value: `${name} ${direction}`,
|
|
47
59
|
children: [
|
package/dist/app/list-page.js
CHANGED
|
@@ -15,6 +15,7 @@ import { pinnedStorageKey } from "../data-grid/pinned-storage.js";
|
|
|
15
15
|
import { DataGrid } from "../data-grid/data-grid.js";
|
|
16
16
|
import { ActiveFilterChips } from "../filter-panel/active-filter-chips.js";
|
|
17
17
|
import { activeChips, emptyFilterState, removeChip } from "../filter-panel/filter-state.js";
|
|
18
|
+
import { FilterSection } from "../filter-panel/filter-section.js";
|
|
18
19
|
import { ToolbarRow } from "../filter-panel/toolbar-row.js";
|
|
19
20
|
import { FilterPanel } from "../filter-panel/filter-panel.js";
|
|
20
21
|
import { columnsFromModel } from "../live/columns-from-model.js";
|
|
@@ -135,14 +136,15 @@ const LoadedList = ({ model, address }) => {
|
|
|
135
136
|
const searchBox = model.search?.length ? /* @__PURE__ */ jsx(ListSearch, {
|
|
136
137
|
value: search?.kind === "search" ? search.text : "",
|
|
137
138
|
onCommit: commitSearch,
|
|
138
|
-
placeholder: `Search ${plural.toLowerCase()}
|
|
139
|
+
placeholder: `Search ${plural.toLowerCase()}`,
|
|
140
|
+
className: desktop ? void 0 : "min-h-11"
|
|
139
141
|
}) : null;
|
|
140
142
|
const panel = /* @__PURE__ */ jsx(FilterPanel, {
|
|
141
143
|
layout,
|
|
142
144
|
config,
|
|
143
145
|
value: state,
|
|
144
146
|
onChange: setFilter,
|
|
145
|
-
leading: sortMenu,
|
|
147
|
+
leading: layout === "bar" ? sortMenu : void 0,
|
|
146
148
|
trailing: searchBox
|
|
147
149
|
});
|
|
148
150
|
const desktopToolbar = layout === "bar" ? panel : /* @__PURE__ */ jsx(ToolbarRow, {
|
|
@@ -150,40 +152,75 @@ const LoadedList = ({ model, address }) => {
|
|
|
150
152
|
trailing: searchBox
|
|
151
153
|
});
|
|
152
154
|
const chips = activeChips(config, state);
|
|
155
|
+
const chipsRow = /* @__PURE__ */ jsx(ActiveFilterChips, {
|
|
156
|
+
scroll: true,
|
|
157
|
+
chips,
|
|
158
|
+
onRemove: (key) => setFilter(removeChip(state, key)),
|
|
159
|
+
onClear: () => setFilter(emptyFilterState)
|
|
160
|
+
});
|
|
161
|
+
const phoneSort = display && /* @__PURE__ */ jsx(FilterSection, {
|
|
162
|
+
title: "Sort",
|
|
163
|
+
children: /* @__PURE__ */ jsx(SortMenu, {
|
|
164
|
+
model,
|
|
165
|
+
view,
|
|
166
|
+
display,
|
|
167
|
+
orderBy,
|
|
168
|
+
onChange: (next) => set({ orderBy: next }),
|
|
169
|
+
className: "min-h-11 w-full"
|
|
170
|
+
})
|
|
171
|
+
});
|
|
153
172
|
const phoneFilters = /* @__PURE__ */ jsxs("div", {
|
|
154
173
|
className: "flex flex-col gap-2",
|
|
155
|
-
children: [
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
174
|
+
children: [
|
|
175
|
+
/* @__PURE__ */ jsxs("div", {
|
|
176
|
+
className: "flex items-center gap-2",
|
|
177
|
+
children: [/* @__PURE__ */ jsxs(Button, {
|
|
178
|
+
className: "min-h-11",
|
|
179
|
+
onClick: () => setSheetOpen(true),
|
|
180
|
+
"aria-haspopup": "dialog",
|
|
181
|
+
children: [
|
|
182
|
+
/* @__PURE__ */ jsx(SlidersHorizontal, { className: "size-3.5" }),
|
|
183
|
+
"Filters",
|
|
184
|
+
chips.length > 0 && ` (${chips.length})`
|
|
185
|
+
]
|
|
186
|
+
}), searchBox ?? /* @__PURE__ */ jsx("div", {
|
|
187
|
+
className: "min-w-0 flex-1",
|
|
188
|
+
children: chipsRow
|
|
189
|
+
})]
|
|
190
|
+
}),
|
|
191
|
+
searchBox && chipsRow,
|
|
192
|
+
/* @__PURE__ */ jsx(Sheet, {
|
|
193
|
+
title: "Filters",
|
|
194
|
+
open: sheetOpen,
|
|
195
|
+
onClose: () => setSheetOpen(false),
|
|
196
|
+
children: /* @__PURE__ */ jsx(FilterPanel, {
|
|
197
|
+
layout: "panel",
|
|
198
|
+
fullWidth: true,
|
|
199
|
+
config,
|
|
200
|
+
value: state,
|
|
201
|
+
onChange: setFilter,
|
|
202
|
+
leading: phoneSort
|
|
173
203
|
})
|
|
174
|
-
})]
|
|
175
|
-
}), /* @__PURE__ */ jsx(Sheet, {
|
|
176
|
-
title: "Filters",
|
|
177
|
-
open: sheetOpen,
|
|
178
|
-
onClose: () => setSheetOpen(false),
|
|
179
|
-
children: /* @__PURE__ */ jsx(FilterPanel, {
|
|
180
|
-
layout: "panel",
|
|
181
|
-
fullWidth: true,
|
|
182
|
-
config,
|
|
183
|
-
value: state,
|
|
184
|
-
onChange: setFilter
|
|
185
204
|
})
|
|
186
|
-
|
|
205
|
+
]
|
|
206
|
+
});
|
|
207
|
+
const createButton = can(permissions, "create") && /* @__PURE__ */ jsxs(Button, {
|
|
208
|
+
variant: "primary",
|
|
209
|
+
onClick: () => go({
|
|
210
|
+
kind: "create",
|
|
211
|
+
resource
|
|
212
|
+
}),
|
|
213
|
+
children: [
|
|
214
|
+
/* @__PURE__ */ jsx(Plus, { className: "size-3.5" }),
|
|
215
|
+
"New ",
|
|
216
|
+
singular.toLowerCase()
|
|
217
|
+
]
|
|
218
|
+
});
|
|
219
|
+
const displaySwitch = (menu) => /* @__PURE__ */ jsx(DisplaySwitch, {
|
|
220
|
+
view,
|
|
221
|
+
value: display?.name ?? tableDisplay,
|
|
222
|
+
onChange: (name) => set({ display: name }),
|
|
223
|
+
menu
|
|
187
224
|
});
|
|
188
225
|
const openRecord = (row) => go({
|
|
189
226
|
kind: "record",
|
|
@@ -230,27 +267,8 @@ const LoadedList = ({ model, address }) => {
|
|
|
230
267
|
/* @__PURE__ */ jsx(PageHeader, {
|
|
231
268
|
title: plural,
|
|
232
269
|
subtitle: view?.help,
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
view,
|
|
236
|
-
value: display?.name ?? tableDisplay,
|
|
237
|
-
onChange: (name) => set({ display: name })
|
|
238
|
-
}),
|
|
239
|
-
!desktop && sortMenu,
|
|
240
|
-
!desktop && searchBox,
|
|
241
|
-
can(permissions, "create") && /* @__PURE__ */ jsxs(Button, {
|
|
242
|
-
variant: "primary",
|
|
243
|
-
onClick: () => go({
|
|
244
|
-
kind: "create",
|
|
245
|
-
resource
|
|
246
|
-
}),
|
|
247
|
-
children: [
|
|
248
|
-
/* @__PURE__ */ jsx(Plus, { className: "size-3.5" }),
|
|
249
|
-
"New ",
|
|
250
|
-
singular.toLowerCase()
|
|
251
|
-
]
|
|
252
|
-
})
|
|
253
|
-
] })
|
|
270
|
+
aside: !desktop && displaySwitch(true),
|
|
271
|
+
actions: desktop ? /* @__PURE__ */ jsxs(Fragment$1, { children: [displaySwitch(false), createButton] }) : createButton
|
|
254
272
|
}),
|
|
255
273
|
!parsed.ok && /* @__PURE__ */ jsx(ErrorBanner, {
|
|
256
274
|
title: "The filter in the address could not be read",
|
package/dist/app/list-search.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { cn } from "../lib/cn.js";
|
|
1
2
|
import { Input } from "../primitives/input.js";
|
|
2
3
|
import { useEffect, useState } from "react";
|
|
3
4
|
import { Search } from "lucide-react";
|
|
4
5
|
import { jsx } from "react/jsx-runtime";
|
|
5
6
|
//#region src/app/list-search.tsx
|
|
6
|
-
/** A search box that commits after a short pause or on Enter. */
|
|
7
|
-
const ListSearch = ({ value, onCommit, placeholder }) => {
|
|
7
|
+
/** A search box that commits after a short pause or on Enter; `className` goes on its frame. */
|
|
8
|
+
const ListSearch = ({ value, onCommit, placeholder, className }) => {
|
|
8
9
|
const [text, setText] = useState(value);
|
|
9
10
|
useEffect(() => setText(value), [value]);
|
|
10
11
|
useEffect(() => {
|
|
@@ -17,7 +18,7 @@ const ListSearch = ({ value, onCommit, placeholder }) => {
|
|
|
17
18
|
onCommit
|
|
18
19
|
]);
|
|
19
20
|
return /* @__PURE__ */ jsx(Input, {
|
|
20
|
-
wrapperClassName: "min-w-0 flex-1 sm:w-72 sm:flex-initial",
|
|
21
|
+
wrapperClassName: cn("min-w-0 flex-1 sm:w-72 sm:flex-initial", className),
|
|
21
22
|
leading: /* @__PURE__ */ jsx(Search, { className: "size-4" }),
|
|
22
23
|
placeholder,
|
|
23
24
|
"aria-label": "Search",
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
//#region src/app-shell/page-header.tsx
|
|
3
|
-
const PageHeader = ({ title, subtitle, actions }) =>
|
|
4
|
-
|
|
5
|
-
children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h1", {
|
|
3
|
+
const PageHeader = ({ title, subtitle, aside, actions }) => {
|
|
4
|
+
const heading = /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h1", {
|
|
6
5
|
className: "text-xl font-semibold tracking-tight",
|
|
7
6
|
children: title
|
|
8
7
|
}), subtitle && /* @__PURE__ */ jsx("p", {
|
|
9
8
|
className: "text-[13px] text-muted-foreground",
|
|
10
9
|
children: subtitle
|
|
11
|
-
})] })
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
})] });
|
|
11
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
12
|
+
className: "flex flex-wrap items-end justify-between gap-x-4 gap-y-2",
|
|
13
|
+
children: [aside ? /* @__PURE__ */ jsxs("div", {
|
|
14
|
+
className: "flex min-w-0 flex-1 items-center justify-between gap-3",
|
|
15
|
+
children: [heading, aside]
|
|
16
|
+
}) : heading, actions && /* @__PURE__ */ jsx("div", {
|
|
17
|
+
className: "flex w-full flex-wrap items-center gap-2 sm:w-auto",
|
|
18
|
+
children: actions
|
|
19
|
+
})]
|
|
20
|
+
});
|
|
21
|
+
};
|
|
16
22
|
//#endregion
|
|
17
23
|
export { PageHeader };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { matchesSearch } from "./filter-state.js";
|
|
2
|
+
//#region src/filter-panel/combobox-options.ts
|
|
3
|
+
/** The options a combobox lists for its search text: as given when the group searches itself, else those whose name matches. */
|
|
4
|
+
const comboboxOptions = (group, query) => group.onSearch ? group.options : group.options.filter((option) => matchesSearch(option.label, query));
|
|
5
|
+
/** The option the arrow keys move to, wrapping around at either end; -1 when there are none. */
|
|
6
|
+
const moveActive = (active, count, key) => {
|
|
7
|
+
if (count === 0) return -1;
|
|
8
|
+
if (key === "ArrowDown") return active < 0 ? 0 : (active + 1) % count;
|
|
9
|
+
return active < 0 ? count - 1 : (active - 1 + count) % count;
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { comboboxOptions, moveActive };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { cn } from "../lib/cn.js";
|
|
2
|
+
import { formatInt } from "../format/number.js";
|
|
3
|
+
import { facetLabel } from "./filter-state.js";
|
|
4
|
+
import { comboboxOptions, moveActive } from "./combobox-options.js";
|
|
5
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
6
|
+
import { Check, Search, X } from "lucide-react";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
//#region src/filter-panel/facet-combobox.tsx
|
|
9
|
+
/** Chooses several values of a facet: the choices sit in the box as removable tokens, typing searches the options. */
|
|
10
|
+
const FacetCombobox = ({ config, selected, onToggle, inline = false }) => {
|
|
11
|
+
const id = useId();
|
|
12
|
+
const input = useRef(null);
|
|
13
|
+
const [query, setQuery] = useState("");
|
|
14
|
+
const [focused, setFocused] = useState(false);
|
|
15
|
+
const [active, setActive] = useState(-1);
|
|
16
|
+
const open = inline || focused;
|
|
17
|
+
const options = comboboxOptions(config, query);
|
|
18
|
+
const onSearch = useRef(config.onSearch);
|
|
19
|
+
onSearch.current = config.onSearch;
|
|
20
|
+
useEffect(() => () => onSearch.current?.(""), []);
|
|
21
|
+
const search = (text) => {
|
|
22
|
+
setQuery(text);
|
|
23
|
+
setActive(-1);
|
|
24
|
+
config.onSearch?.(text);
|
|
25
|
+
};
|
|
26
|
+
const onKeyDown = (event) => {
|
|
27
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
28
|
+
event.preventDefault();
|
|
29
|
+
setActive(moveActive(active, options.length, event.key));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (event.key === "Enter" && options[active]) {
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
onToggle(options[active].value);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (event.key === "Backspace" && query === "" && selected.length > 0) {
|
|
38
|
+
onToggle(selected[selected.length - 1]);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (event.key === "Escape" && query !== "") {
|
|
42
|
+
event.stopPropagation();
|
|
43
|
+
search("");
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
47
|
+
className: "flex flex-col gap-1",
|
|
48
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
49
|
+
className: "flex min-h-8 cursor-text flex-wrap items-center gap-1 rounded-md border border-border-strong bg-background px-2 py-1 shadow-sm focus-within:border-primary focus-within:ring-2 focus-within:ring-primary/20",
|
|
50
|
+
onClick: () => input.current?.focus(),
|
|
51
|
+
children: [
|
|
52
|
+
/* @__PURE__ */ jsx(Search, { className: "size-3.5 shrink-0 text-muted-foreground" }),
|
|
53
|
+
selected.map((value) => /* @__PURE__ */ jsxs("span", {
|
|
54
|
+
className: "inline-flex h-5 max-w-full items-center gap-0.5 rounded bg-primary-soft pl-1.5 pr-0.5 text-xs font-medium text-primary-text",
|
|
55
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
56
|
+
className: "truncate",
|
|
57
|
+
children: facetLabel(config, value)
|
|
58
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
59
|
+
type: "button",
|
|
60
|
+
"aria-label": `Remove ${facetLabel(config, value)}`,
|
|
61
|
+
className: "rounded p-0.5 hover:bg-primary-border/60",
|
|
62
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
63
|
+
onClick: () => onToggle(value),
|
|
64
|
+
children: /* @__PURE__ */ jsx(X, { className: "size-3" })
|
|
65
|
+
})]
|
|
66
|
+
}, value)),
|
|
67
|
+
/* @__PURE__ */ jsx("input", {
|
|
68
|
+
ref: input,
|
|
69
|
+
autoFocus: inline,
|
|
70
|
+
role: "combobox",
|
|
71
|
+
"aria-label": config.label,
|
|
72
|
+
"aria-expanded": open,
|
|
73
|
+
"aria-controls": `${id}-options`,
|
|
74
|
+
"aria-autocomplete": "list",
|
|
75
|
+
"aria-activedescendant": options[active] ? `${id}-${active}` : void 0,
|
|
76
|
+
placeholder: selected.length > 0 ? "" : `Search ${config.label.toLowerCase()}`,
|
|
77
|
+
className: "h-6 min-w-16 flex-1 bg-transparent text-[13px] text-foreground outline-none placeholder:text-faint-foreground",
|
|
78
|
+
value: query,
|
|
79
|
+
onChange: (event) => search(event.target.value),
|
|
80
|
+
onKeyDown,
|
|
81
|
+
onFocus: () => setFocused(true),
|
|
82
|
+
onBlur: () => {
|
|
83
|
+
setFocused(false);
|
|
84
|
+
setActive(-1);
|
|
85
|
+
if (!inline && query !== "") search("");
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
]
|
|
89
|
+
}), open && /* @__PURE__ */ jsxs("ul", {
|
|
90
|
+
id: `${id}-options`,
|
|
91
|
+
role: "listbox",
|
|
92
|
+
"aria-label": config.label,
|
|
93
|
+
"aria-multiselectable": true,
|
|
94
|
+
className: cn("flex max-h-60 flex-col gap-px overflow-y-auto", !inline && "rounded-md border bg-background p-1 shadow-sm"),
|
|
95
|
+
children: [options.map((option, index) => {
|
|
96
|
+
const chosen = selected.includes(option.value);
|
|
97
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
98
|
+
id: `${id}-${index}`,
|
|
99
|
+
role: "option",
|
|
100
|
+
"aria-selected": chosen,
|
|
101
|
+
tabIndex: -1,
|
|
102
|
+
className: cn("flex cursor-pointer items-center gap-2 rounded px-1.5 py-1 hover:bg-muted", index === active && "bg-muted"),
|
|
103
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
104
|
+
onClick: () => onToggle(option.value),
|
|
105
|
+
children: [
|
|
106
|
+
/* @__PURE__ */ jsx("span", {
|
|
107
|
+
className: cn("inline-flex size-4 shrink-0 items-center justify-center rounded border", chosen ? "border-primary bg-primary text-primary-foreground" : "border-border-strong bg-background"),
|
|
108
|
+
children: chosen && /* @__PURE__ */ jsx(Check, {
|
|
109
|
+
className: "size-3",
|
|
110
|
+
strokeWidth: 3
|
|
111
|
+
})
|
|
112
|
+
}),
|
|
113
|
+
/* @__PURE__ */ jsx("span", {
|
|
114
|
+
className: "flex-1 truncate",
|
|
115
|
+
children: option.label
|
|
116
|
+
}),
|
|
117
|
+
option.count !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
118
|
+
className: "text-xs tabular-nums text-faint-foreground",
|
|
119
|
+
children: formatInt(option.count)
|
|
120
|
+
})
|
|
121
|
+
]
|
|
122
|
+
}, option.value);
|
|
123
|
+
}), options.length === 0 && /* @__PURE__ */ jsx("li", {
|
|
124
|
+
className: "px-1.5 py-1 text-xs text-faint-foreground",
|
|
125
|
+
children: "No matches"
|
|
126
|
+
})]
|
|
127
|
+
})]
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
//#endregion
|
|
131
|
+
export { FacetCombobox };
|
|
@@ -31,7 +31,7 @@ const FacetGroup = ({ config, selected, onToggle }) => {
|
|
|
31
31
|
className: "flex-1 truncate",
|
|
32
32
|
children: option.label
|
|
33
33
|
}),
|
|
34
|
-
/* @__PURE__ */ jsx("span", {
|
|
34
|
+
option.count !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
35
35
|
className: "text-xs tabular-nums text-faint-foreground",
|
|
36
36
|
children: formatInt(option.count)
|
|
37
37
|
})
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { cn } from "../lib/cn.js";
|
|
2
|
-
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
3
3
|
import { ChevronDown } from "lucide-react";
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
//#region src/filter-panel/filter-menu.tsx
|
|
6
6
|
const FilterMenu = ({ label, activeCount, width = 240, defaultOpen = false, children }) => {
|
|
7
7
|
const [open, setOpen] = useState(defaultOpen);
|
|
8
|
+
const [alignEnd, setAlignEnd] = useState(false);
|
|
8
9
|
const root = useRef(null);
|
|
10
|
+
useLayoutEffect(() => {
|
|
11
|
+
if (!open || !root.current) return;
|
|
12
|
+
setAlignEnd(root.current.getBoundingClientRect().left + width > document.documentElement.clientWidth);
|
|
13
|
+
}, [open, width]);
|
|
9
14
|
useEffect(() => {
|
|
10
15
|
if (!open) return;
|
|
11
16
|
const close = (event) => {
|
|
@@ -31,7 +36,7 @@ const FilterMenu = ({ label, activeCount, width = 240, defaultOpen = false, chil
|
|
|
31
36
|
/* @__PURE__ */ jsx(ChevronDown, { className: "size-3.5 text-muted-foreground" })
|
|
32
37
|
]
|
|
33
38
|
}), open && /* @__PURE__ */ jsx("div", {
|
|
34
|
-
className: "absolute
|
|
39
|
+
className: cn("absolute top-full z-30 mt-1.5 rounded-lg border bg-background p-3 shadow-pop", alignEnd ? "right-0" : "left-0"),
|
|
35
40
|
style: { width },
|
|
36
41
|
children
|
|
37
42
|
})]
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ActiveFilterChips } from "./active-filter-chips.js";
|
|
2
2
|
import { DatePresets } from "./date-presets.js";
|
|
3
|
-
import { activeChips, emptyFilterState, removeChip, toggleFacetValue, toggleFlag } from "./filter-state.js";
|
|
3
|
+
import { activeChips, emptyFilterState, removeChip, setRange, toggleFacetValue, toggleFlag } from "./filter-state.js";
|
|
4
|
+
import { FacetCombobox } from "./facet-combobox.js";
|
|
4
5
|
import { FacetGroup } from "./facet-group.js";
|
|
5
6
|
import { FilterMenu } from "./filter-menu.js";
|
|
6
7
|
import { FilterSection } from "./filter-section.js";
|
|
@@ -20,18 +21,25 @@ const FilterPanel = ({ config, layout, value, defaultValue, onChange, lockedLabe
|
|
|
20
21
|
onRemove: (key) => setState(removeChip(state, key)),
|
|
21
22
|
onClear: () => setState(emptyFilterState)
|
|
22
23
|
});
|
|
23
|
-
const facetView = (group
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
const facetView = (group, inline = false) => {
|
|
25
|
+
const selected = state.facets[group.id] ?? [];
|
|
26
|
+
const onToggle = (option) => setState(toggleFacetValue(state, group.id, option));
|
|
27
|
+
return group.combobox ? /* @__PURE__ */ jsx(FacetCombobox, {
|
|
28
|
+
config: group,
|
|
29
|
+
selected,
|
|
30
|
+
onToggle,
|
|
31
|
+
inline
|
|
32
|
+
}) : /* @__PURE__ */ jsx(FacetGroup, {
|
|
33
|
+
config: group,
|
|
34
|
+
selected,
|
|
35
|
+
onToggle
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
const ranges = config.ranges ?? [];
|
|
39
|
+
const rangeView = (range) => /* @__PURE__ */ jsx(RangeFilter, {
|
|
40
|
+
config: range,
|
|
41
|
+
value: state.ranges?.[range.id],
|
|
42
|
+
onChange: (span) => setState(setRange(state, range.id, span))
|
|
35
43
|
});
|
|
36
44
|
const dateView = config.datePresets && /* @__PURE__ */ jsx(DatePresets, {
|
|
37
45
|
value: state.date,
|
|
@@ -60,14 +68,15 @@ const FilterPanel = ({ config, layout, value, defaultValue, onChange, lockedLabe
|
|
|
60
68
|
className: "border-b pb-3",
|
|
61
69
|
children: chipsView
|
|
62
70
|
}),
|
|
71
|
+
leading,
|
|
63
72
|
config.facets.map((group) => /* @__PURE__ */ jsx(FilterSection, {
|
|
64
73
|
title: group.label,
|
|
65
74
|
children: facetView(group)
|
|
66
75
|
}, group.id)),
|
|
67
|
-
|
|
68
|
-
title:
|
|
69
|
-
children: rangeView
|
|
70
|
-
}),
|
|
76
|
+
ranges.map((range) => /* @__PURE__ */ jsx(FilterSection, {
|
|
77
|
+
title: range.label,
|
|
78
|
+
children: rangeView(range)
|
|
79
|
+
}, range.id)),
|
|
71
80
|
dateView && /* @__PURE__ */ jsx(FilterSection, {
|
|
72
81
|
title: "Date",
|
|
73
82
|
children: dateView
|
|
@@ -82,16 +91,17 @@ const FilterPanel = ({ config, layout, value, defaultValue, onChange, lockedLabe
|
|
|
82
91
|
...config.facets.map((group) => /* @__PURE__ */ jsx(FilterMenu, {
|
|
83
92
|
label: group.label,
|
|
84
93
|
activeCount: (state.facets[group.id] ?? []).length,
|
|
94
|
+
width: group.combobox ? 280 : void 0,
|
|
85
95
|
defaultOpen: defaultOpenMenu === group.id,
|
|
86
|
-
children: facetView(group)
|
|
96
|
+
children: facetView(group, true)
|
|
87
97
|
}, group.id)),
|
|
88
|
-
...
|
|
89
|
-
label:
|
|
90
|
-
activeCount: state.range ? 1 : 0,
|
|
98
|
+
...ranges.map((range) => /* @__PURE__ */ jsx(FilterMenu, {
|
|
99
|
+
label: range.label,
|
|
100
|
+
activeCount: state.ranges?.[range.id] ? 1 : 0,
|
|
91
101
|
width: 280,
|
|
92
|
-
defaultOpen: defaultOpenMenu ===
|
|
93
|
-
children: rangeView
|
|
94
|
-
},
|
|
102
|
+
defaultOpen: defaultOpenMenu === range.id,
|
|
103
|
+
children: rangeView(range)
|
|
104
|
+
}, `range:${range.id}`)),
|
|
95
105
|
...dateView ? [/* @__PURE__ */ jsx(Fragment, { children: dateView }, "date")] : []
|
|
96
106
|
];
|
|
97
107
|
const toggles = (config.toggles ?? []).map((toggle) => /* @__PURE__ */ jsx("div", {
|
|
@@ -19,16 +19,31 @@ const toggleFlag = (state, id) => ({
|
|
|
19
19
|
...state,
|
|
20
20
|
toggles: state.toggles.includes(id) ? state.toggles.filter((entry) => entry !== id) : [...state.toggles, id]
|
|
21
21
|
});
|
|
22
|
+
/** Sets or, with `undefined`, clears the span of one range. */
|
|
23
|
+
const setRange = (state, id, value) => {
|
|
24
|
+
const { [id]: _, ...others } = state.ranges ?? {};
|
|
25
|
+
return {
|
|
26
|
+
...state,
|
|
27
|
+
ranges: value ? {
|
|
28
|
+
...others,
|
|
29
|
+
[id]: value
|
|
30
|
+
} : others
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
/** A facet value's name: its option's label, else a name the group knows for it, else the value itself. */
|
|
34
|
+
const facetLabel = (group, value) => group.options.find((option) => option.value === value)?.label ?? group.labels?.[value] ?? value;
|
|
22
35
|
const activeChips = (config, state) => {
|
|
23
36
|
const facetChips = config.facets.flatMap((group) => (state.facets[group.id] ?? []).map((value) => ({
|
|
24
37
|
key: `facet:${group.id}:${value}`,
|
|
25
|
-
label: `${group.label}: ${group
|
|
38
|
+
label: `${group.label}: ${facetLabel(group, value)}`
|
|
26
39
|
})));
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
40
|
+
const rangeChips = (config.ranges ?? []).flatMap((range) => {
|
|
41
|
+
const span = state.ranges?.[range.id];
|
|
42
|
+
return span ? [{
|
|
43
|
+
key: `range:${range.id}`,
|
|
44
|
+
label: `${range.label}: ${range.format(span[0])} – ${range.format(span[1])}`
|
|
45
|
+
}] : [];
|
|
46
|
+
});
|
|
32
47
|
const dateChips = state.date ? [{
|
|
33
48
|
key: "date",
|
|
34
49
|
label: datePresetLabels[state.date] ?? state.date
|
|
@@ -45,19 +60,16 @@ const activeChips = (config, state) => {
|
|
|
45
60
|
];
|
|
46
61
|
};
|
|
47
62
|
const removeChip = (state, key) => {
|
|
48
|
-
if (key === "range") return {
|
|
49
|
-
...state,
|
|
50
|
-
range: void 0
|
|
51
|
-
};
|
|
52
63
|
if (key === "date") return {
|
|
53
64
|
...state,
|
|
54
65
|
date: void 0
|
|
55
66
|
};
|
|
56
67
|
const [kind, group, value] = key.split(":");
|
|
68
|
+
if (kind === "range") return setRange(state, group, void 0);
|
|
57
69
|
if (kind === "toggle") return toggleFlag(state, group);
|
|
58
70
|
if (kind === "facet") return toggleFacetValue(state, group, value);
|
|
59
71
|
throw new Error(`Unknown filter chip key: ${key}`);
|
|
60
72
|
};
|
|
61
73
|
const matchesSearch = (label, query) => label.toLowerCase().includes(query.trim().toLowerCase());
|
|
62
74
|
//#endregion
|
|
63
|
-
export { activeChips, emptyFilterState, matchesSearch, removeChip, toggleFacetValue, toggleFlag };
|
|
75
|
+
export { activeChips, emptyFilterState, facetLabel, matchesSearch, removeChip, setRange, toggleFacetValue, toggleFlag };
|
|
@@ -13,14 +13,14 @@ const RangeFilter = ({ config, value, onChange }) => {
|
|
|
13
13
|
children: [
|
|
14
14
|
/* @__PURE__ */ jsxs("div", {
|
|
15
15
|
className: "px-[7px]",
|
|
16
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
17
|
-
className: "flex h-12 items-end gap-0.5",
|
|
16
|
+
children: [histogram.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
17
|
+
className: "mb-1 flex h-12 items-end gap-0.5",
|
|
18
18
|
children: histogram.map((count, index) => /* @__PURE__ */ jsx("span", {
|
|
19
19
|
className: cn("flex-1 rounded-t-sm", barInRange(index, histogram.length, min, max, selected) ? "bg-primary/70" : "bg-border"),
|
|
20
20
|
style: { height: `${Math.max(6, count / peak * 100)}%` }
|
|
21
21
|
}, index))
|
|
22
22
|
}), /* @__PURE__ */ jsxs("div", {
|
|
23
|
-
className: "relative
|
|
23
|
+
className: "relative h-4",
|
|
24
24
|
children: [/* @__PURE__ */ jsx("span", { className: "absolute inset-x-0 top-1/2 h-1 -translate-y-1/2 rounded-full bg-border" }), /* @__PURE__ */ jsx("span", {
|
|
25
25
|
className: "absolute top-1/2 h-1 -translate-y-1/2 rounded-full bg-primary",
|
|
26
26
|
style: {
|
package/dist/index.js
CHANGED
|
@@ -19,8 +19,8 @@ import { useAssistant } from "./assistant-dock/use-assistant.js";
|
|
|
19
19
|
import { useAssistantClient } from "./assistant-dock/use-assistant-client.js";
|
|
20
20
|
import { useMeta } from "./data/use-meta.js";
|
|
21
21
|
import { AppLink, useAppAddress } from "./app/use-app-address.js";
|
|
22
|
-
import { useFacets, useHistogram, useSeries } from "./data/use-aggregates.js";
|
|
23
22
|
import { useListDisplay } from "./app/displays/display-context.js";
|
|
23
|
+
import { useFacets, useHistogram, useSeries } from "./data/use-aggregates.js";
|
|
24
24
|
import { useLayoutRecord } from "./app/pages/record-scope.js";
|
|
25
25
|
import { uiFromModule } from "./app/pages/ui-from-module.js";
|
|
26
26
|
import { mergeUi } from "./app/pages/merge-ui.js";
|