@nivaro/react 0.3.115 → 0.3.116

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,326 @@
1
+ import { jsxs as k, jsx as p, Fragment as me } from "react/jsx-runtime";
2
+ import { MoreHorizontal as fe, ChevronDown as he, Check as ye } from "lucide-react";
3
+ import { useRef as v, useState as _, useCallback as S, useMemo as X, useLayoutEffect as C } from "react";
4
+ import { RailMenuContext as be } from "../lib/rail-menu-context.js";
5
+ import { useBelowMd as ge } from "../lib/use-below-md.js";
6
+ import { cn as z } from "../lib/utils.js";
7
+ import { Popover as ve, PopoverTrigger as we, PopoverContent as xe } from "./ui/popover.js";
8
+ function ke(r) {
9
+ return {
10
+ filters: r.filter((o) => o.kind === "filter"),
11
+ actions: r.filter((o) => o.kind !== "filter")
12
+ };
13
+ }
14
+ function _e(r) {
15
+ let o = "";
16
+ const d = (n) => {
17
+ if (n.nodeType === 3) {
18
+ o += n.textContent ?? "";
19
+ return;
20
+ }
21
+ if (n.nodeType !== 1) return;
22
+ const i = n;
23
+ if (!(i.classList.contains("sr-only") || i.hasAttribute("hidden")) && i.getAttribute("aria-hidden") !== "true")
24
+ for (const f of Array.from(i.childNodes)) d(f);
25
+ };
26
+ return d(r), o.trim();
27
+ }
28
+ const Ae = 'button, a[href], [role="button"], input, select, textarea';
29
+ function D(r, o) {
30
+ for (const d of Array.from(r.querySelectorAll("[data-rail-row]"))) {
31
+ const n = Array.from(d.querySelectorAll(Ae)).find(
32
+ (y) => !y.closest("[hidden]")
33
+ );
34
+ if (!n) continue;
35
+ n.hasAttribute("data-rail-primary") || n.setAttribute("data-rail-primary", "");
36
+ const i = n.parentElement;
37
+ i && i !== d && i.parentElement === d && i.setAttribute("data-rail-wrap", "");
38
+ const f = d.getAttribute("data-rail-item") ?? "", c = _e(n) === "" ? o.get(f) ?? n.getAttribute("aria-label") ?? n.getAttribute("data-tip") ?? n.getAttribute("title") ?? "" : "";
39
+ c ? n.getAttribute("data-rail-label") !== c && n.setAttribute("data-rail-label", c) : n.hasAttribute("data-rail-label") && n.removeAttribute("data-rail-label");
40
+ }
41
+ }
42
+ function Y(r) {
43
+ return Array.from(r.querySelectorAll("[data-rail-primary]")).filter(
44
+ (o) => !o.disabled
45
+ );
46
+ }
47
+ const Me = 0.55;
48
+ function Ne(r) {
49
+ const o = Number.parseFloat(
50
+ getComputedStyle(r).getPropertyValue("--radix-popover-content-available-height")
51
+ );
52
+ if (!Number.isFinite(o) || o <= 0 || r.scrollHeight <= o + 1) {
53
+ r.style.removeProperty("--nvr-rail-menu-cut");
54
+ return;
55
+ }
56
+ const d = r.getBoundingClientRect(), n = r.offsetHeight - r.clientHeight;
57
+ let i = 0;
58
+ for (const f of r.querySelectorAll("[data-rail-row]")) {
59
+ const c = f.getBoundingClientRect();
60
+ if (c.height <= 0) continue;
61
+ const y = c.top - d.top + r.scrollTop + c.height * Me + n;
62
+ if (y > o) break;
63
+ i = y;
64
+ }
65
+ i > 0 ? r.style.setProperty("--nvr-rail-menu-cut", `${Math.floor(i)}px`) : r.style.removeProperty("--nvr-rail-menu-cut");
66
+ }
67
+ const Oe = z(
68
+ "[&_[data-rail-wrap]]:flex [&_[data-rail-wrap]]:w-full [&_[data-rail-wrap]]:max-w-none [&_[data-rail-wrap]]:items-center [&_[data-rail-wrap]]:gap-1",
69
+ "[&_[data-rail-primary]]:flex [&_[data-rail-primary]]:h-9 [&_[data-rail-primary]]:w-full [&_[data-rail-primary]]:min-w-0 [&_[data-rail-primary]]:flex-1 [&_[data-rail-primary]]:items-center [&_[data-rail-primary]]:justify-start [&_[data-rail-primary]]:gap-2 [&_[data-rail-primary]]:whitespace-nowrap [&_[data-rail-primary]]:rounded-md [&_[data-rail-primary]]:!border-transparent [&_[data-rail-primary]]:px-2.5 [&_[data-rail-primary]]:text-left [&_[data-rail-primary]]:text-[12.5px] [&_[data-rail-primary]]:font-medium [&_[data-rail-primary]]:!shadow-none",
70
+ // `!`: the hosts' dark sheet re-points bg-white / border-slate-200 with !important.
71
+ "[&_[data-rail-primary]:not([aria-pressed=true]):not([aria-expanded=true])]:!bg-transparent [&_[data-rail-primary]:not([aria-pressed=true])]:!text-slate-700 dark:[&_[data-rail-primary]:not([aria-pressed=true])]:!text-slate-200",
72
+ "[&_[data-rail-primary]:not([aria-pressed=true]):not(:disabled):hover]:!bg-slate-100 dark:[&_[data-rail-primary]:not([aria-pressed=true]):not(:disabled):hover]:!bg-muted [&_[data-rail-primary][aria-expanded=true]]:!bg-slate-100 dark:[&_[data-rail-primary][aria-expanded=true]]:!bg-muted",
73
+ "[&_[data-rail-primary]:focus-visible]:outline-none [&_[data-rail-primary]:focus-visible]:ring-2 [&_[data-rail-primary]:focus-visible]:ring-inset [&_[data-rail-primary]:focus-visible]:ring-nvr-cyan/60",
74
+ "[&_[data-rail-primary]_svg]:h-3.5 [&_[data-rail-primary]_svg]:w-3.5 [&_[data-rail-primary]_svg]:shrink-0 [&_[data-rail-primary]:not([aria-pressed=true])_svg]:text-slate-500 dark:[&_[data-rail-primary]:not([aria-pressed=true])_svg]:text-slate-400",
75
+ "[&_[data-rail-label]]:after:content-[attr(data-rail-label)]",
76
+ // A colour dot (8 px) leading a row takes an icon's 14 px, so every label starts in line.
77
+ "[&_[data-rail-primary]>span:first-child:empty]:mx-[3px]",
78
+ // A control with a wrapper (an active chip with its ×, Focus mode with its minutes): the
79
+ // wrapper is the row, the control fills it.
80
+ "[&_[data-rail-wrap]]:h-9 [&_[data-rail-wrap]]:rounded-md [&_[data-rail-wrap]]:pl-0 [&_[data-rail-wrap]_[data-rail-primary]]:h-full",
81
+ // A toggle that is on says so with a check at the row's end, not only a tint.
82
+ "[&_[data-rail-row]:has([data-rail-primary][aria-pressed=true])_[data-rail-check]]:block"
83
+ ), Ee = 96, Z = 32;
84
+ function Re(r, o, d, n) {
85
+ const i = (s) => o.get(s) ?? Ee, f = (s) => {
86
+ const u = s.filter((x) => i(x) > 0);
87
+ return u.reduce((x, P) => x + i(P), 0) + n * u.length;
88
+ }, c = r.map((s) => s.key);
89
+ if (f(c) <= d) return /* @__PURE__ */ new Set();
90
+ const y = [...r].map((s, u) => ({ ...s, idx: u })).sort((s, u) => s.priority - u.priority || u.idx - s.idx), w = /* @__PURE__ */ new Set();
91
+ for (const s of y) {
92
+ if (f(c.filter((u) => !w.has(u))) + Z + n <= d) break;
93
+ i(s.key) !== 0 && w.add(s.key);
94
+ }
95
+ return w;
96
+ }
97
+ function De({
98
+ items: r,
99
+ lead: o,
100
+ trail: d,
101
+ leadMinWidth: n = 304,
102
+ moreLabel: i = "More actions",
103
+ className: f
104
+ }) {
105
+ const c = v(null), y = v(null), w = v(null), s = v(/* @__PURE__ */ new Map()), u = v(/* @__PURE__ */ new Map()), [x, P] = _(() => /* @__PURE__ */ new Set()), [M, ee] = _(!1), [B, te] = _(!1), j = v(r);
106
+ j.current = r;
107
+ const T = ge(), [re, U] = _(0), q = S((e) => U((t) => Math.max(0, t + e)), []), ae = X(
108
+ () => ({
109
+ nested: q,
110
+ compact: T,
111
+ // Popovers from the menu stay inside the page's own area, clear of the app sidebar.
112
+ boundary: () => {
113
+ var e;
114
+ return ((e = c.current) == null ? void 0 : e.closest("main")) ?? null;
115
+ }
116
+ }),
117
+ [q, T]
118
+ ), N = v(null), [ne, ie] = _(null), oe = S((e) => {
119
+ N.current = e, ie(e);
120
+ }, []), [le, se] = _(!1), O = S(() => {
121
+ const e = N.current;
122
+ e && Ne(e);
123
+ const t = !!e && e.scrollHeight - e.scrollTop - e.clientHeight > 4;
124
+ se((a) => a === t ? a : t);
125
+ }, []), de = r.map((e) => `${e.key}=${e.label ?? ""}`).join(""), F = X(
126
+ () => new Map(r.filter((e) => e.label).map((e) => [e.key, e.label])),
127
+ [de]
128
+ ), H = S(() => {
129
+ var J, Q;
130
+ const e = c.current, t = e == null ? void 0 : e.parentElement;
131
+ if (!e || !t) return;
132
+ for (const [m, b] of u.current) s.current.set(m, b.offsetWidth);
133
+ const a = getComputedStyle(t), l = t.clientWidth - (Number.parseFloat(a.paddingLeft) || 0) - (Number.parseFloat(a.paddingRight) || 0), h = Number.parseFloat(a.columnGap) || 8, g = Number.parseFloat(getComputedStyle(e).columnGap) || 8, L = ((J = w.current) == null ? void 0 : J.offsetWidth) ?? 0, $ = ((Q = y.current) == null ? void 0 : Q.offsetWidth) ?? 0, G = $ + (L > 0 ? L + g : 0);
134
+ let A = 0;
135
+ if (n === "siblings") {
136
+ for (let m = e.previousElementSibling; m; m = m.previousElementSibling) {
137
+ const b = m.offsetWidth;
138
+ b > 0 && (A += b + h);
139
+ }
140
+ A = Math.max(0, A - h);
141
+ } else A = n;
142
+ const K = l - Math.min(A, l) - h, I = K < G + Z + g, V = (I ? l : K) - G, W = Re(
143
+ j.current.map(({ key: m, priority: b }) => ({ key: m, priority: b })),
144
+ s.current,
145
+ // The trail's own leading gap is part of the items' gaps (one per real item / the ⋯).
146
+ $ > 0 ? V : V + g,
147
+ g
148
+ );
149
+ P(
150
+ (m) => m.size === W.size && [...W].every((b) => m.has(b)) ? m : W
151
+ ), te(I);
152
+ }, [n]);
153
+ C(() => {
154
+ H();
155
+ }), C(() => {
156
+ const e = c.current, t = e == null ? void 0 : e.parentElement;
157
+ if (!e || !t || typeof ResizeObserver > "u") return;
158
+ const a = new ResizeObserver(() => H());
159
+ return a.observe(t), a.observe(e), () => a.disconnect();
160
+ }, [H]), C(() => {
161
+ const e = ne;
162
+ if (!M || !e) return;
163
+ D(e, F), O();
164
+ const t = typeof ResizeObserver > "u" ? null : new ResizeObserver(() => requestAnimationFrame(O));
165
+ t == null || t.observe(e);
166
+ const a = setTimeout(O, 250), l = typeof MutationObserver > "u" ? null : new MutationObserver(() => D(e, F));
167
+ return l == null || l.observe(e, { childList: !0, subtree: !0 }), () => {
168
+ clearTimeout(a), l == null || l.disconnect(), t == null || t.disconnect();
169
+ };
170
+ }), C(() => {
171
+ M || U(0);
172
+ }, [M]);
173
+ const ce = (e) => {
174
+ const t = N.current;
175
+ if (!(t != null && t.contains(e.target)) || e.target.closest('input, textarea, select, [contenteditable="true"]'))
176
+ return;
177
+ const a = Y(t);
178
+ if (a.length === 0) return;
179
+ const l = a.findIndex(
180
+ (g) => g === document.activeElement || g.contains(document.activeElement)
181
+ );
182
+ let h = -1;
183
+ e.key === "ArrowDown" ? h = l < 0 ? 0 : (l + 1) % a.length : e.key === "ArrowUp" ? h = l < 0 ? a.length - 1 : (l - 1 + a.length) % a.length : e.key === "Home" ? h = 0 : e.key === "End" && (h = a.length - 1), !(h < 0) && (e.preventDefault(), a[h].focus());
184
+ }, ue = (e) => (t) => {
185
+ t ? u.current.set(e, t) : u.current.delete(e);
186
+ }, pe = r.filter((e) => !x.has(e.key)), E = r.filter((e) => x.has(e.key)), R = E.some((e) => e.active);
187
+ return /* @__PURE__ */ k(
188
+ "div",
189
+ {
190
+ ref: c,
191
+ "data-overflow-rail": "",
192
+ "data-rail-own-line": B ? "" : void 0,
193
+ className: z(
194
+ "ml-auto flex shrink-0 flex-nowrap items-center gap-2",
195
+ B && "w-full",
196
+ f
197
+ ),
198
+ children: [
199
+ o != null && /* @__PURE__ */ p(
200
+ "div",
201
+ {
202
+ ref: w,
203
+ "data-rail-lead": "",
204
+ className: "flex shrink-0 items-center gap-2 empty:hidden",
205
+ children: o
206
+ }
207
+ ),
208
+ pe.map((e) => /* @__PURE__ */ p(
209
+ "div",
210
+ {
211
+ ref: ue(e.key),
212
+ "data-rail-item": e.key,
213
+ className: "flex shrink-0 items-center gap-2 empty:hidden",
214
+ children: e.node
215
+ },
216
+ e.key
217
+ )),
218
+ E.length > 0 && /* @__PURE__ */ k(ve, { open: M, onOpenChange: ee, children: [
219
+ /* @__PURE__ */ p(we, { asChild: !0, children: /* @__PURE__ */ k(
220
+ "button",
221
+ {
222
+ type: "button",
223
+ "aria-label": R ? `${i} (some are on)` : i,
224
+ "data-tip": R ? `${i} — some are on` : i,
225
+ "data-rail-more": E.length,
226
+ "data-rail-more-active": R ? "" : void 0,
227
+ className: "relative flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-slate-200 text-slate-500 hover:bg-slate-100 hover:text-slate-700 dark:border-slate-700 dark:text-slate-400 dark:hover:bg-slate-800 dark:hover:text-slate-200",
228
+ children: [
229
+ /* @__PURE__ */ p(fe, { className: "h-4 w-4" }),
230
+ R && /* @__PURE__ */ p(
231
+ "span",
232
+ {
233
+ "aria-hidden": !0,
234
+ className: "absolute -right-0.5 -top-0.5 h-2 w-2 rounded-full bg-nvr-cyan ring-2 ring-white dark:ring-background"
235
+ }
236
+ )
237
+ ]
238
+ }
239
+ ) }),
240
+ /* @__PURE__ */ p(
241
+ xe,
242
+ {
243
+ ref: oe,
244
+ align: "end",
245
+ collisionPadding: 16,
246
+ "aria-label": i,
247
+ onOpenAutoFocus: (e) => {
248
+ var a;
249
+ e.preventDefault();
250
+ const t = N.current;
251
+ t && (D(t, F), (a = Y(t)[0]) == null || a.focus());
252
+ },
253
+ onKeyDown: ce,
254
+ onScroll: O,
255
+ className: z(
256
+ "flex w-64 max-w-[calc(100vw-2rem)] flex-col gap-px overflow-y-auto overscroll-contain p-1",
257
+ // The peek cut (fitMenuPeek) only ever shortens the space Radix gives.
258
+ "max-h-[min(var(--radix-popover-content-available-height),var(--nvr-rail-menu-cut,100000px))]",
259
+ Oe,
260
+ T && re > 0 && "pointer-events-none opacity-0"
261
+ ),
262
+ "data-rail-menu": "",
263
+ children: /* @__PURE__ */ p(be.Provider, { value: ae, children: (() => {
264
+ const { filters: e, actions: t } = ke(E), a = (l) => /* @__PURE__ */ k(
265
+ "div",
266
+ {
267
+ "data-rail-item": l.key,
268
+ "data-rail-row": "",
269
+ "data-rail-kind": l.kind ?? "action",
270
+ className: "relative flex min-w-0 items-center gap-1 empty:hidden",
271
+ children: [
272
+ l.node,
273
+ /* @__PURE__ */ p(
274
+ ye,
275
+ {
276
+ "aria-hidden": !0,
277
+ "data-rail-check": "",
278
+ className: "pointer-events-none absolute right-2.5 top-1/2 hidden h-3.5 w-3.5 -translate-y-1/2 text-[#007a99] dark:text-nvr-cyan"
279
+ }
280
+ )
281
+ ]
282
+ },
283
+ l.key
284
+ );
285
+ return /* @__PURE__ */ k(me, { children: [
286
+ e.length > 0 && /* @__PURE__ */ p("p", { className: "px-2.5 pb-1 pt-1.5 text-[11px] font-medium text-slate-500 dark:text-slate-400", children: "Show only" }),
287
+ e.map(a),
288
+ e.length > 0 && t.length > 0 && /* @__PURE__ */ p(
289
+ "hr",
290
+ {
291
+ "data-rail-divider": "",
292
+ className: "mx-1 my-1 h-px shrink-0 border-0 bg-slate-100 dark:bg-border"
293
+ }
294
+ ),
295
+ t.map(a),
296
+ le && // A short fade (the peeking row stays readable) and a tag at the
297
+ // corner, clear of the row's icon and words.
298
+ /* @__PURE__ */ p(
299
+ "div",
300
+ {
301
+ "aria-hidden": !0,
302
+ "data-rail-more-below": "",
303
+ className: "pointer-events-none sticky -bottom-1 -mt-2.5 flex h-2.5 shrink-0 items-end justify-end bg-gradient-to-t from-popover to-transparent",
304
+ children: /* @__PURE__ */ k("span", { className: "mb-1.5 mr-1 inline-flex items-center gap-0.5 rounded-full border border-slate-200 bg-popover py-0.5 pl-2 pr-1.5 text-[11px] font-medium text-slate-600 shadow-sm dark:border-border dark:text-slate-300", children: [
305
+ "More",
306
+ /* @__PURE__ */ p(he, { className: "h-3 w-3" })
307
+ ] })
308
+ }
309
+ )
310
+ ] });
311
+ })() })
312
+ }
313
+ )
314
+ ] }),
315
+ d != null && /* @__PURE__ */ p("div", { ref: y, className: "ml-auto flex shrink-0 items-center gap-2 empty:hidden", children: d })
316
+ ]
317
+ }
318
+ );
319
+ }
320
+ export {
321
+ De as OverflowRail,
322
+ Ne as fitMenuPeek,
323
+ D as markRailMenu,
324
+ ke as railMenuGroups,
325
+ Re as railOverflow
326
+ };
@@ -1,13 +1,13 @@
1
1
  import { jsx as L } from "react/jsx-runtime";
2
2
  import { useState as x, useRef as y, useEffect as b, useLayoutEffect as E } from "react";
3
3
  import { createPortal as M } from "react-dom";
4
- const a = [], O = '[data-nvr-header-menu-panel], [role="menu"]', g = 6;
4
+ const l = [], O = '[data-nvr-header-menu-panel], [role="menu"], [data-rail-menu]', g = 6;
5
5
  function W() {
6
- const [t, h] = x(null), [r, l] = x(!1), p = y(null);
7
- return b(() => (a.push(l), a[0] === l && l(!0), () => {
6
+ const [t, h] = x(null), [r, a] = x(!1), p = y(null);
7
+ return b(() => (l.push(a), l[0] === a && a(!0), () => {
8
8
  var e;
9
- const c = a.indexOf(l);
10
- c < 0 || (a.splice(c, 1), c === 0 && ((e = a[0]) == null || e.call(a, !0)));
9
+ const c = l.indexOf(a);
10
+ c < 0 || (l.splice(c, 1), c === 0 && ((e = l[0]) == null || e.call(l, !0)));
11
11
  }), []), b(() => {
12
12
  if (!r) return;
13
13
  const c = (n) => {
@@ -82,11 +82,11 @@ function T(t) {
82
82
  return E(() => {
83
83
  const r = h.current;
84
84
  if (!r) return;
85
- const l = () => {
85
+ const a = () => {
86
86
  (r.scrollWidth > r.clientWidth + 1 || r.scrollHeight > r.clientHeight + 1) && t ? r.setAttribute("data-tip", t) : r.removeAttribute("data-tip");
87
87
  };
88
- if (l(), typeof ResizeObserver > "u") return;
89
- const p = new ResizeObserver(l);
88
+ if (a(), typeof ResizeObserver > "u") return;
89
+ const p = new ResizeObserver(a);
90
90
  return p.observe(r), () => p.disconnect();
91
91
  }, [t]), h;
92
92
  }