@nivaro/react 0.3.106 → 0.3.108

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.
@@ -0,0 +1,287 @@
1
+ import { jsxs as l, jsx as a } from "react/jsx-runtime";
2
+ import { Search as j, Rows3 as K, LayoutGrid as T } from "lucide-react";
3
+ import { useRef as L, useEffect as z } from "react";
4
+ import { cn as c } from "../../lib/utils.js";
5
+ import { Input as B } from "../ui/input.js";
6
+ import { Switch as S } from "../ui/switch.js";
7
+ const G = [
8
+ { key: "folders", label: "Folders" },
9
+ { key: "az", label: "A–Z" },
10
+ { key: "recent", label: "Recently changed", adminOnly: !0 },
11
+ { key: "records", label: "Most records", adminOnly: !0 },
12
+ { key: "used", label: "Most used by you" }
13
+ ], P = [
14
+ { key: "has_records", label: "Has records", stat: !0 },
15
+ { key: "empty", label: "Empty", stat: !0 },
16
+ { key: "hidden", label: "Hidden" },
17
+ { key: "link", label: "Link tables" },
18
+ { key: "virtual", label: "Virtual" },
19
+ { key: "singleton", label: "Singleton" },
20
+ { key: "pipeline", label: "Has pipeline", stat: !0 },
21
+ { key: "form", label: "Has form", stat: !0 }
22
+ ], d = "inline-flex h-7 items-center gap-1.5 rounded-md px-2.5 text-[12px] font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan", h = "text-slate-600 hover:bg-slate-100 dark:text-slate-300 dark:hover:bg-white/10", u = "bg-nvr-cyan/10 text-cyan-700 dark:bg-nvr-cyan/15 dark:text-nvr-cyan";
23
+ function $({
24
+ state: t,
25
+ onChange: s,
26
+ filter: H,
27
+ onFilterChange: F,
28
+ filterRef: m,
29
+ counts: i,
30
+ isAdmin: b,
31
+ selectedCount: g,
32
+ onMoveSelected: D,
33
+ onClearSelection: R,
34
+ adminActions: y,
35
+ title: A = "Collections",
36
+ canArrange: f = !0,
37
+ canSelect: x = !0
38
+ }) {
39
+ const E = L(null), w = L(null);
40
+ z(() => {
41
+ const e = w.current, r = e == null ? void 0 : e.querySelector('[aria-checked="true"]');
42
+ if (!e || !r) return;
43
+ const n = r.offsetLeft, o = n + r.offsetWidth;
44
+ n < e.scrollLeft ? e.scrollLeft = Math.max(0, n - 4) : o > e.scrollLeft + e.clientWidth && (e.scrollLeft = o - e.clientWidth + 24);
45
+ }, [t.view]);
46
+ const I = (e) => {
47
+ E.current = e, typeof m == "function" ? m(e) : m && (m.current = e);
48
+ }, p = G.filter((e) => b || !e.adminOnly), M = P.filter((e) => (b || !e.stat) && (i.chip[e.key] ?? 0) > 0), O = t.chips.length > 0, V = (e) => s({
49
+ ...t,
50
+ chips: t.chips.includes(e) ? t.chips.filter((r) => r !== e) : [...t.chips, e]
51
+ }), v = (e) => s({ ...t, view: e }), N = (e) => s({ ...t, density: e }), W = (e, r) => {
52
+ const n = e.key === "ArrowRight" || e.key === "ArrowDown" ? 1 : e.key === "ArrowLeft" || e.key === "ArrowUp" ? -1 : 0;
53
+ if (!n) return;
54
+ e.preventDefault();
55
+ const o = p[(r + n + p.length) % p.length];
56
+ v(o.key);
57
+ const k = e.currentTarget.parentElement;
58
+ requestAnimationFrame(
59
+ () => {
60
+ var C;
61
+ return (C = k == null ? void 0 : k.querySelectorAll("[role=radio]")[p.indexOf(o)]) == null ? void 0 : C.focus();
62
+ }
63
+ );
64
+ }, q = () => s(
65
+ t.arranging ? { ...t, arranging: !1 } : { ...t, arranging: !0, selecting: !1, view: "folders" }
66
+ ), _ = () => s(
67
+ t.selecting ? { ...t, selecting: !1 } : { ...t, selecting: !0, arranging: !1 }
68
+ );
69
+ return /* @__PURE__ */ l(
70
+ "div",
71
+ {
72
+ className: "border-b border-slate-200 bg-white px-4 py-3 dark:border-white/[0.08] dark:bg-[#0f1923] md:[&[data-cdr]]:px-8 md:[&[data-cdr]]:py-4",
73
+ "data-cdr": "",
74
+ children: [
75
+ /* @__PURE__ */ l("div", { className: "flex flex-wrap items-center gap-x-4 gap-y-2", children: [
76
+ /* @__PURE__ */ l("div", { className: "flex items-center gap-2", children: [
77
+ /* @__PURE__ */ a("h1", { className: "text-[18px] font-semibold text-slate-900 dark:text-slate-100", children: A }),
78
+ /* @__PURE__ */ a("span", { className: "rounded-full bg-slate-100 px-2 py-0.5 text-[11px] font-semibold tabular-nums text-slate-500 dark:bg-white/10 dark:text-slate-400", children: i.total })
79
+ ] }),
80
+ /* @__PURE__ */ l("div", { "data-cdr": "", className: "relative w-full md:[&[data-cdr]]:w-auto", children: [
81
+ /* @__PURE__ */ a(j, { className: "pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-slate-400" }),
82
+ /* @__PURE__ */ a(
83
+ B,
84
+ {
85
+ ref: I,
86
+ value: H,
87
+ onChange: (e) => F(e.target.value),
88
+ placeholder: "Filter collections",
89
+ "aria-label": "Filter collections",
90
+ "data-cdr": "",
91
+ className: "h-8 w-full border-slate-200 md:[&[data-cdr]]:w-56 bg-slate-50 pl-8 text-[13px] placeholder:text-slate-400 focus-visible:ring-nvr-cyan dark:border-white/[0.08] dark:bg-white/[0.05] dark:text-slate-200 dark:placeholder:text-slate-500"
92
+ }
93
+ )
94
+ ] }),
95
+ /* @__PURE__ */ a(
96
+ "div",
97
+ {
98
+ ref: w,
99
+ role: "radiogroup",
100
+ "aria-label": "View",
101
+ "data-cdr": "",
102
+ className: "relative flex max-w-full items-center gap-0.5 overflow-x-auto rounded-lg bg-slate-100 p-0.5 [mask-image:linear-gradient(to_right,#000_calc(100%-24px),transparent)] [scrollbar-width:none] md:[&[data-cdr]]:[mask-image:none] dark:bg-white/[0.06]",
103
+ children: p.map((e, r) => {
104
+ const n = t.view === e.key;
105
+ return (
106
+ // biome-ignore lint/a11y/useSemanticElements: segmented control with roving tabindex
107
+ /* @__PURE__ */ a(
108
+ "button",
109
+ {
110
+ type: "button",
111
+ role: "radio",
112
+ "aria-checked": n,
113
+ tabIndex: n ? 0 : -1,
114
+ disabled: t.arranging && e.key !== "folders",
115
+ onClick: () => v(e.key),
116
+ onKeyDown: (o) => W(o, r),
117
+ className: c(
118
+ d,
119
+ "shrink-0 whitespace-nowrap disabled:cursor-not-allowed disabled:opacity-40",
120
+ n ? "bg-white text-slate-900 shadow-sm dark:bg-white/15 dark:text-slate-100" : h
121
+ ),
122
+ children: e.label
123
+ },
124
+ e.key
125
+ )
126
+ );
127
+ })
128
+ }
129
+ ),
130
+ /* @__PURE__ */ l("div", { className: "flex items-center gap-0.5 rounded-lg bg-slate-100 p-0.5 dark:bg-white/[0.06]", children: [
131
+ /* @__PURE__ */ a(
132
+ "button",
133
+ {
134
+ type: "button",
135
+ "aria-pressed": t.density === "compact",
136
+ "aria-label": "Compact density",
137
+ "data-tip": "Compact",
138
+ onClick: () => N("compact"),
139
+ className: c(d, "px-2", t.density === "compact" ? u : h),
140
+ children: /* @__PURE__ */ a(K, { className: "h-3.5 w-3.5" })
141
+ }
142
+ ),
143
+ /* @__PURE__ */ a(
144
+ "button",
145
+ {
146
+ type: "button",
147
+ "aria-pressed": t.density === "comfortable",
148
+ "aria-label": "Comfortable density",
149
+ "data-tip": "Comfortable",
150
+ onClick: () => N("comfortable"),
151
+ className: c(d, "px-2", t.density === "comfortable" ? u : h),
152
+ children: /* @__PURE__ */ a(T, { className: "h-3.5 w-3.5" })
153
+ }
154
+ )
155
+ ] }),
156
+ b && (y || f || x) && /* @__PURE__ */ l("div", { className: "ml-auto flex items-center gap-1", children: [
157
+ y,
158
+ f && /* @__PURE__ */ a(
159
+ "button",
160
+ {
161
+ type: "button",
162
+ "aria-pressed": t.arranging,
163
+ onClick: q,
164
+ className: c(d, t.arranging ? u : h),
165
+ children: t.arranging ? "Done arranging" : "Arrange"
166
+ }
167
+ ),
168
+ x && /* @__PURE__ */ a(
169
+ "button",
170
+ {
171
+ type: "button",
172
+ "aria-pressed": t.selecting,
173
+ onClick: _,
174
+ className: c(d, t.selecting ? u : h),
175
+ children: "Select"
176
+ }
177
+ )
178
+ ] })
179
+ ] }),
180
+ /* @__PURE__ */ l("div", { className: "mt-2 flex flex-wrap items-center gap-x-1.5 gap-y-1.5", children: [
181
+ M.map((e) => {
182
+ const r = t.chips.includes(e.key);
183
+ return /* @__PURE__ */ l(
184
+ "button",
185
+ {
186
+ type: "button",
187
+ "aria-pressed": r,
188
+ onClick: () => V(e.key),
189
+ className: c(
190
+ d,
191
+ "h-6 border px-2 text-[11.5px]",
192
+ r ? "border-nvr-cyan/30 bg-nvr-cyan/10 text-cyan-700 dark:text-nvr-cyan" : "border-slate-200 text-slate-600 hover:bg-slate-50 dark:border-white/[0.08] dark:text-slate-300 dark:hover:bg-white/10"
193
+ ),
194
+ children: [
195
+ e.label,
196
+ /* @__PURE__ */ a("span", { className: "tabular-nums text-slate-400 dark:text-slate-500", children: i.chip[e.key] })
197
+ ]
198
+ },
199
+ e.key
200
+ );
201
+ }),
202
+ O && /* @__PURE__ */ a(
203
+ "button",
204
+ {
205
+ type: "button",
206
+ onClick: () => s({ ...t, chips: [] }),
207
+ className: "px-1.5 text-[11.5px] text-slate-500 underline-offset-2 hover:underline dark:text-slate-400",
208
+ children: "Clear"
209
+ }
210
+ ),
211
+ /* @__PURE__ */ l("div", { className: "ml-auto flex flex-wrap items-center gap-x-4 gap-y-1", children: [
212
+ i.hidden > 0 && /* @__PURE__ */ l(
213
+ "label",
214
+ {
215
+ htmlFor: "coll-show-hidden",
216
+ className: "flex cursor-pointer items-center gap-1.5 text-[11.5px] text-slate-500 dark:text-slate-400",
217
+ children: [
218
+ /* @__PURE__ */ a(
219
+ S,
220
+ {
221
+ checked: t.showHidden,
222
+ onCheckedChange: (e) => s({ ...t, showHidden: e }),
223
+ id: "coll-show-hidden",
224
+ className: "h-4 w-7 data-[state=checked]:bg-nvr-cyan [&>span]:h-3 [&>span]:w-3 [&>span]:data-[state=checked]:translate-x-3"
225
+ }
226
+ ),
227
+ "Show hidden collections (",
228
+ i.hidden,
229
+ ")"
230
+ ]
231
+ }
232
+ ),
233
+ i.links > 0 && /* @__PURE__ */ l(
234
+ "label",
235
+ {
236
+ htmlFor: "coll-show-links",
237
+ className: "flex cursor-pointer items-center gap-1.5 text-[11.5px] text-slate-500 dark:text-slate-400",
238
+ children: [
239
+ /* @__PURE__ */ a(
240
+ S,
241
+ {
242
+ checked: t.showLinks,
243
+ onCheckedChange: (e) => s({ ...t, showLinks: e }),
244
+ id: "coll-show-links",
245
+ className: "h-4 w-7 data-[state=checked]:bg-nvr-cyan [&>span]:h-3 [&>span]:w-3 [&>span]:data-[state=checked]:translate-x-3"
246
+ }
247
+ ),
248
+ "Show link tables (",
249
+ i.links,
250
+ ")"
251
+ ]
252
+ }
253
+ )
254
+ ] })
255
+ ] }),
256
+ b && x && t.selecting && /* @__PURE__ */ l("div", { className: "mt-2 flex items-center gap-3 rounded-md bg-nvr-cyan/10 px-3 py-1.5 text-[12px] text-slate-700 dark:text-slate-200", children: [
257
+ /* @__PURE__ */ l("span", { className: "font-medium tabular-nums", children: [
258
+ g,
259
+ " selected"
260
+ ] }),
261
+ /* @__PURE__ */ a(
262
+ "button",
263
+ {
264
+ type: "button",
265
+ onClick: D,
266
+ disabled: g === 0,
267
+ className: "font-medium text-cyan-700 hover:underline disabled:opacity-40 dark:text-nvr-cyan",
268
+ children: "Move to folder…"
269
+ }
270
+ ),
271
+ /* @__PURE__ */ a(
272
+ "button",
273
+ {
274
+ type: "button",
275
+ onClick: R,
276
+ className: "text-slate-500 hover:underline dark:text-slate-400",
277
+ children: "Clear"
278
+ }
279
+ )
280
+ ] })
281
+ ]
282
+ }
283
+ );
284
+ }
285
+ export {
286
+ $ as CollectionsToolbar
287
+ };
@@ -0,0 +1,97 @@
1
+ import { jsx as e, jsxs as c } from "react/jsx-runtime";
2
+ import { useSensors as D, useSensor as x, PointerSensor as E, KeyboardSensor as O, DndContext as _, closestCenter as M } from "@dnd-kit/core";
3
+ import { sortableKeyboardCoordinates as H, SortableContext as K, verticalListSortingStrategy as j, arrayMove as y } from "@dnd-kit/sortable";
4
+ import { Pin as u, MoreHorizontal as F } from "lucide-react";
5
+ import { ErrorNotice as L } from "../ErrorNotice.js";
6
+ import { Skeleton as g } from "../ui/skeleton.js";
7
+ import { label as z } from "./page-model.js";
8
+ import { SortableRow as G, Section as I, FolderHeader as T } from "./sections.js";
9
+ const U = "__pinned__", V = ({ transform: t }) => ({ ...t, x: 0 });
10
+ function $({
11
+ cols: t,
12
+ isAdmin: s,
13
+ status: l,
14
+ error: b,
15
+ onRetry: N,
16
+ onReorder: h,
17
+ collapsed: w,
18
+ onToggle: S,
19
+ renderRow: m,
20
+ sectionId: k
21
+ }) {
22
+ const P = D(
23
+ x(E, { activationConstraint: { distance: 8 } }),
24
+ x(O, { coordinateGetter: H })
25
+ );
26
+ if (l === "loading" && !s || l === "ready" && t.length === 0 && !s) return null;
27
+ const r = t.map((n) => n.collection), p = (n, o) => {
28
+ const i = r.indexOf(n), d = i + o;
29
+ i === -1 || d < 0 || d >= r.length || h(y(r, i, d));
30
+ }, C = (n) => {
31
+ const { active: o, over: i } = n;
32
+ if (!i || o.id === i.id) return;
33
+ const d = r.indexOf(String(o.id)), v = r.indexOf(String(i.id));
34
+ d === -1 || v === -1 || h(y(r, d, v));
35
+ };
36
+ let a;
37
+ l === "loading" ? a = /* @__PURE__ */ e("div", { role: "status", "aria-busy": "true", "aria-label": "Loading pinned collections", children: [0, 1].map((n) => /* @__PURE__ */ c(
38
+ "div",
39
+ {
40
+ className: "flex h-7 items-center gap-2.5 border-b border-slate-100 px-4 last:border-0 dark:border-white/[0.05]",
41
+ children: [
42
+ /* @__PURE__ */ e(g, { className: "h-5 w-5 rounded" }),
43
+ /* @__PURE__ */ e(g, { className: "h-3 w-40" })
44
+ ]
45
+ },
46
+ n
47
+ )) }) : l === "error" ? a = /* @__PURE__ */ e("div", { className: "px-4 py-3", children: /* @__PURE__ */ e(L, { error: b, what: "the pinned collections", onRetry: N }) }) : t.length === 0 ? a = /* @__PURE__ */ c("div", { className: "px-4 py-3", children: [
48
+ /* @__PURE__ */ e("p", { className: "text-[12.5px] font-medium text-slate-700 dark:text-slate-200", children: "Pin collections everyone should see first" }),
49
+ /* @__PURE__ */ c("p", { className: "mt-1 text-[12px] leading-relaxed text-slate-500 dark:text-slate-400", children: [
50
+ "Open a row’s",
51
+ /* @__PURE__ */ e(F, { className: "mx-1 inline h-3 w-3 -translate-y-px", "aria-hidden": "true" }),
52
+ "menu and choose Pin for everyone, or use the",
53
+ /* @__PURE__ */ e(u, { className: "mx-1 inline h-3 w-3 -translate-y-px", "aria-hidden": "true" }),
54
+ "that shows when you point at a row. Everyone sees them here in your order — only the ones they can open. Only administrators can change this list."
55
+ ] })
56
+ ] }) : s ? a = /* @__PURE__ */ e(
57
+ _,
58
+ {
59
+ sensors: P,
60
+ collisionDetection: M,
61
+ modifiers: [V],
62
+ onDragEnd: C,
63
+ children: /* @__PURE__ */ e(K, { items: r, strategy: j, children: /* @__PURE__ */ e("div", { className: "divide-y divide-slate-100 dark:divide-white/[0.05]", children: t.map((n, o) => /* @__PURE__ */ e(G, { id: n.collection, label: z(n), children: (i) => m(n, {
64
+ handle: i,
65
+ onMoveUp: o > 0 ? () => p(n.collection, -1) : void 0,
66
+ onMoveDown: o < t.length - 1 ? () => p(n.collection, 1) : void 0
67
+ }) }, n.collection)) }) })
68
+ }
69
+ ) : a = /* @__PURE__ */ e("div", { className: "divide-y divide-slate-100 dark:divide-white/[0.05]", children: t.map((n) => /* @__PURE__ */ e("div", { children: m(n, {}) }, n.collection)) });
70
+ const f = !w;
71
+ return /* @__PURE__ */ e("div", { "data-collections-pinned": !0, children: /* @__PURE__ */ c(I, { id: k ?? "cl-section-pinned", children: [
72
+ /* @__PURE__ */ e(
73
+ T,
74
+ {
75
+ folder: { key: U, label: "Pinned", color: "#64748b" },
76
+ icon: /* @__PURE__ */ e(
77
+ u,
78
+ {
79
+ className: "h-3 w-3 fill-slate-500 text-slate-500 dark:fill-slate-300 dark:text-slate-300",
80
+ "aria-hidden": "true"
81
+ }
82
+ ),
83
+ hint: "For everyone",
84
+ dragHandle: s && l === "ready" && t.length > 0 ? /* @__PURE__ */ e("span", { className: "w-9 shrink-0" }) : void 0,
85
+ count: l === "ready" && t.length > 0 ? t.length : null,
86
+ hiddenCount: 0,
87
+ collapsed: !f,
88
+ onToggle: S
89
+ }
90
+ ),
91
+ f && a
92
+ ] }) });
93
+ }
94
+ export {
95
+ U as PINNED_KEY,
96
+ $ as PinnedSection
97
+ };
@@ -0,0 +1,159 @@
1
+ import { useQueryClient as I, useQuery as m } from "@tanstack/react-query";
2
+ import { useRef as O, useMemo as R, useCallback as E, useState as F } from "react";
3
+ import { toast as u } from "sonner";
4
+ import { useNivaroClient as y } from "../../context.js";
5
+ import { get as f, patch as w } from "../../lib/commands.js";
6
+ const h = {
7
+ collections: ["collections"],
8
+ stats: ["collections-overview-stats"],
9
+ summary: (t) => ["collection-summary", t]
10
+ };
11
+ function J() {
12
+ const t = y();
13
+ return m({
14
+ queryKey: h.collections,
15
+ queryFn: () => t.request(f("/collections")).then((e) => e.data ?? [])
16
+ });
17
+ }
18
+ function P(t) {
19
+ const e = y();
20
+ return m({
21
+ queryKey: h.stats,
22
+ queryFn: () => e.request(f("/collections/overview-stats")).then((o) => o.data ?? {}),
23
+ enabled: t,
24
+ staleTime: 6e4,
25
+ retry: !1
26
+ });
27
+ }
28
+ function x(t, e) {
29
+ const o = y();
30
+ return m({
31
+ queryKey: h.summary(t),
32
+ queryFn: () => o.request(
33
+ f(`/collections/${encodeURIComponent(t)}/summary`)
34
+ ).then((r) => r.data),
35
+ enabled: e,
36
+ staleTime: 6e4,
37
+ retry: !1
38
+ });
39
+ }
40
+ const q = "nvr_collections_usage", K = 12;
41
+ function _() {
42
+ try {
43
+ const t = JSON.parse(localStorage.getItem(q) ?? "null");
44
+ if (t && Array.isArray(t.recent) && t.counts && typeof t.counts == "object")
45
+ return { recent: t.recent.map(String), counts: t.counts };
46
+ } catch {
47
+ }
48
+ return { recent: [], counts: {} };
49
+ }
50
+ function M(t) {
51
+ const e = _(), o = [t, ...e.recent.filter((s) => s !== t)].slice(0, K), r = { ...e.counts, [t]: (e.counts[t] ?? 0) + 1 };
52
+ try {
53
+ localStorage.setItem(q, JSON.stringify({ recent: o, counts: r }));
54
+ } catch {
55
+ }
56
+ }
57
+ function L() {
58
+ const [t] = F(_);
59
+ return t;
60
+ }
61
+ function V(t, e) {
62
+ try {
63
+ const o = localStorage.getItem(t);
64
+ return o == null ? e : JSON.parse(o);
65
+ } catch {
66
+ return e;
67
+ }
68
+ }
69
+ function X(t, e) {
70
+ try {
71
+ localStorage.setItem(t, JSON.stringify(e));
72
+ } catch {
73
+ }
74
+ }
75
+ const l = ["nvr-nav-favorites"], S = 60, N = (t) => `/collections/${encodeURIComponent(t)}`;
76
+ function T(t) {
77
+ const e = /* @__PURE__ */ new Set();
78
+ for (const o of t) {
79
+ const r = /^\/collections\/([^/?#]+)$/.exec(o.path);
80
+ if (r)
81
+ try {
82
+ e.add(decodeURIComponent(r[1]));
83
+ } catch {
84
+ }
85
+ }
86
+ return e;
87
+ }
88
+ function U(t) {
89
+ const e = (Array.isArray(t == null ? void 0 : t.nav_favorite_groups) ? t.nav_favorite_groups : []).filter((r) => typeof r == "string" && r.trim() !== "").map((r) => r.trim()), o = [];
90
+ for (const r of Array.isArray(t == null ? void 0 : t.nav_favorites) ? t.nav_favorites : [])
91
+ !r || typeof r.path != "string" || typeof r.label != "string" || o.some((s) => s.path === r.path) || o.push({
92
+ label: r.label,
93
+ path: r.path,
94
+ group: typeof r.group == "string" && e.includes(r.group) ? r.group : null
95
+ });
96
+ return { items: o, groups: e };
97
+ }
98
+ function j(t = !0) {
99
+ const e = y(), o = I(), r = m({
100
+ queryKey: l,
101
+ queryFn: () => e.request(f("/users/me")).then((a) => {
102
+ var c;
103
+ return U(((c = a.data) == null ? void 0 : c.preferences) ?? {});
104
+ }),
105
+ enabled: t,
106
+ staleTime: 3e4
107
+ }), s = O(Promise.resolve()), C = R(() => {
108
+ var a;
109
+ return T(((a = r.data) == null ? void 0 : a.items) ?? []);
110
+ }, [r.data]), A = E(
111
+ (a, c) => {
112
+ const i = o.getQueryData(l);
113
+ if (!i)
114
+ return u.error("Your favorites are still loading — try again in a moment"), Promise.resolve();
115
+ const v = N(a), p = i.items.some((n) => n.path === v);
116
+ if (!p && i.items.length >= S)
117
+ return u.error(`Favorites hold up to ${S} pages — remove one first`), Promise.resolve();
118
+ const g = {
119
+ ...i,
120
+ items: p ? i.items.filter((n) => n.path !== v) : [...i.items, { label: c, path: v, group: null }]
121
+ };
122
+ o.setQueryData(l, g);
123
+ const d = s.current.then(async () => {
124
+ try {
125
+ await e.request(
126
+ w("/users/me/preferences", {
127
+ nav_favorites: g.items.map((n) => ({
128
+ label: n.label,
129
+ path: n.path,
130
+ ...n.group ? { group: n.group } : {}
131
+ })),
132
+ nav_favorite_groups: g.groups
133
+ })
134
+ ), u.success(
135
+ p ? `Removed ${c} from your favorites` : `Added ${c} to your favorites`
136
+ );
137
+ } catch {
138
+ u.error("Could not save favorites"), o.invalidateQueries({ queryKey: l });
139
+ }
140
+ });
141
+ return s.current = d, d;
142
+ },
143
+ [e, o]
144
+ );
145
+ return { favorite: C, toggle: A };
146
+ }
147
+ export {
148
+ h as DIRECTORY_KEYS,
149
+ T as favoriteCollectionsOf,
150
+ N as favoritePath,
151
+ V as readLocal,
152
+ M as recordCollectionOpen,
153
+ x as useCollectionSummary,
154
+ L as useCollectionUsage,
155
+ J as useDirectoryCollections,
156
+ j as useNavFavoriteCollections,
157
+ P as useOverviewStats,
158
+ X as writeLocal
159
+ };
@@ -0,0 +1,122 @@
1
+ import { titleCase as S } from "../../lib/utils.js";
2
+ const p = (i) => i.display_name ?? S(i.collection);
3
+ function I(i, t) {
4
+ if (!t) return !0;
5
+ const n = t.trim().toLowerCase();
6
+ return n ? i.collection.toLowerCase().includes(n) || p(i).toLowerCase().includes(n) : !0;
7
+ }
8
+ function H(i, t, n) {
9
+ switch (t) {
10
+ case "has_records":
11
+ return ((n == null ? void 0 : n.rows) ?? 0) > 0;
12
+ case "empty":
13
+ return (n == null ? void 0 : n.rows) === 0;
14
+ case "hidden":
15
+ return !!i.hidden && !(n != null && n.link);
16
+ case "link":
17
+ return !!(n != null && n.link);
18
+ case "virtual":
19
+ return !!(n != null && n.virtual) || !!i.is_virtual;
20
+ case "singleton":
21
+ return !!i.singleton;
22
+ case "pipeline":
23
+ return !!(n != null && n.pipeline);
24
+ case "form":
25
+ return ((n == null ? void 0 : n.forms) ?? 0) > 0;
26
+ }
27
+ }
28
+ const N = [
29
+ "has_records",
30
+ "empty",
31
+ "hidden",
32
+ "link",
33
+ "virtual",
34
+ "singleton",
35
+ "pipeline",
36
+ "form"
37
+ ];
38
+ function q(i, t, n, s, h) {
39
+ const u = new Set(i.map((e) => e.group).filter((e) => !!e)), r = new Map(
40
+ i.filter((e) => u.has(e.collection)).map((e) => [e.collection, e])
41
+ ), l = i.filter((e) => !u.has(e.collection)), d = (e) => t == null ? void 0 : t[e.collection], k = [...u].map((e) => {
42
+ const o = r.get(e);
43
+ return { key: e, label: o ? p(o) : S(e), color: (o == null ? void 0 : o.color) ?? null };
44
+ }).sort((e, o) => {
45
+ var w, C;
46
+ const c = ((w = r.get(e.key)) == null ? void 0 : w.sort) ?? 9999, m = ((C = r.get(o.key)) == null ? void 0 : C.sort) ?? 9999;
47
+ return c !== m ? c - m : e.label.localeCompare(o.label);
48
+ }), _ = (e) => n.chips.includes(e), b = n.showHidden || _("hidden"), L = n.showLinks || _("link"), a = (e) => {
49
+ var o;
50
+ return !!((o = d(e)) != null && o.link);
51
+ }, M = (e) => !!e.hidden && !a(e), P = {
52
+ total: l.length,
53
+ hidden: l.filter(M).length,
54
+ links: l.filter(a).length,
55
+ chip: Object.fromEntries(
56
+ N.map((e) => [e, l.filter((o) => H(o, e, d(o))).length])
57
+ )
58
+ }, j = (e) => n.chips.every((o) => H(e, o, d(e))), v = l.filter((e) => I(e, s) && j(e)), D = {
59
+ hidden: b ? [] : v.filter(M),
60
+ links: L ? [] : v.filter(a)
61
+ }, O = (e) => a(e) ? L : b || !e.hidden, y = v.filter(O), x = L ? [] : v.filter(a).sort((e, o) => p(e).localeCompare(p(o))), f = (e, o) => p(e).localeCompare(p(o)), z = (e, o) => (e.sort ?? 9999) - (o.sort ?? 9999) || f(e, o), A = !!s.trim() || n.chips.length > 0, E = k.map((e) => {
62
+ var o;
63
+ return {
64
+ folder: e,
65
+ sort: ((o = r.get(e.key)) == null ? void 0 : o.sort) ?? 9999,
66
+ cols: y.filter((c) => c.group === e.key).sort(z),
67
+ hiddenCount: b ? 0 : l.filter((c) => c.group === e.key && M(c)).length
68
+ };
69
+ }).filter((e) => e.cols.length > 0 || !A && e.hiddenCount > 0), F = y.filter((e) => !e.group || !u.has(e.group)).sort(f);
70
+ let g = [];
71
+ return n.view !== "folders" && (g = [...y], n.view === "az" ? g.sort(f) : n.view === "recent" ? g.sort((e, o) => {
72
+ var w, C;
73
+ const c = Date.parse(((w = d(e)) == null ? void 0 : w.changed_at) ?? "") || 0;
74
+ return (Date.parse(((C = d(o)) == null ? void 0 : C.changed_at) ?? "") || 0) - c || f(e, o);
75
+ }) : n.view === "records" ? g.sort((e, o) => {
76
+ var c, m;
77
+ return (((c = d(o)) == null ? void 0 : c.rows) ?? -1) - (((m = d(e)) == null ? void 0 : m.rows) ?? -1) || f(e, o);
78
+ }) : n.view === "used" && g.sort(
79
+ (e, o) => (h.counts[o.collection] ?? 0) - (h.counts[e.collection] ?? 0) || f(e, o)
80
+ )), {
81
+ folders: k,
82
+ real: l,
83
+ sections: E,
84
+ loose: F,
85
+ linkTables: x,
86
+ flat: g,
87
+ shownCount: y.length,
88
+ counts: P,
89
+ foldedMatches: D
90
+ };
91
+ }
92
+ function R(i, t, n = 4) {
93
+ if (Math.abs(i.length - t.length) > n) return n + 1;
94
+ const s = Array.from({ length: t.length + 1 }, (h, u) => u);
95
+ for (let h = 1; h <= i.length; h++) {
96
+ let u = s[0];
97
+ s[0] = h;
98
+ let r = s[0];
99
+ for (let l = 1; l <= t.length; l++) {
100
+ const d = s[l];
101
+ s[l] = Math.min(s[l] + 1, s[l - 1] + 1, u + (i[h - 1] === t[l - 1] ? 0 : 1)), u = d, r = Math.min(r, s[l]);
102
+ }
103
+ if (r > n) return n + 1;
104
+ }
105
+ return s[t.length];
106
+ }
107
+ function B(i, t, n = 3) {
108
+ const s = i.trim().toLowerCase();
109
+ if (s.length < 3) return [];
110
+ const h = s.length <= 5 ? 2 : 3;
111
+ return t.map((r) => {
112
+ const l = [r.collection, p(r), ...r.collection.split("_"), ...p(r).split(/\s+/)], d = Math.min(...l.map((k) => R(s, k.toLowerCase(), h)));
113
+ return { c: r, best: d };
114
+ }).filter((r) => r.best <= h).sort((r, l) => r.best - l.best || p(r.c).localeCompare(p(l.c))).slice(0, n).map((r) => r.c);
115
+ }
116
+ export {
117
+ q as buildPageModel,
118
+ p as label,
119
+ H as matchesChip,
120
+ I as matchesFilter,
121
+ B as nearSpellings
122
+ };