@nivaro/react 0.3.77 → 0.3.78

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.
@@ -1,222 +1,293 @@
1
- import { jsxs as m, jsx as s } from "react/jsx-runtime";
2
- import { useQueryClient as oe, useQuery as F } from "@tanstack/react-query";
3
- import { Search as ie, X as de, Check as U, ChevronsUpDown as ce } from "lucide-react";
4
- import { useState as L, useMemo as C } from "react";
5
- import { useNivaroClient as Y } from "../../context.js";
6
- import { get as Q, patch as M, del as A, post as X } from "../../lib/commands.js";
7
- import { userErrorMessage as ue } from "../../lib/safe-error.js";
8
- import { matchesAllTokens as Z, titleCase as G, cn as K } from "../../lib/utils.js";
9
- import { Popover as me, PopoverTrigger as pe, PopoverContent as be } from "../ui/popover.js";
10
- import { applyDisplayTemplate as he } from "./helpers.js";
11
- import { RelationCombobox as fe } from "./RelationCombobox.js";
12
- const xe = 10;
13
- async function P(t, l, p) {
14
- const b = [];
15
- for (let c = 1; c <= 50; c++) {
16
- const i = await t.request(Q(l, { ...p, limit: 1e3, page: c })).then((y) => y.data ?? []);
17
- if (b.push(...i), i.length < 1e3) break;
1
+ import { jsxs as f, jsx as n } from "react/jsx-runtime";
2
+ import { useQueryClient as ye, useQuery as K } from "@tanstack/react-query";
3
+ import { Search as ge, X as ve, Check as le, ChevronsUpDown as we } from "lucide-react";
4
+ import { useState as C, useMemo as _ } from "react";
5
+ import { useNivaroClient as ce } from "../../context.js";
6
+ import { get as Q, patch as ke, post as se, del as ne } from "../../lib/commands.js";
7
+ import { userErrorMessage as Ne } from "../../lib/safe-error.js";
8
+ import { matchesAllTokens as de, titleCase as O, cn as $ } from "../../lib/utils.js";
9
+ import { Popover as _e, PopoverTrigger as $e, PopoverContent as Se } from "../ui/popover.js";
10
+ import { applyDisplayTemplate as qe } from "./helpers.js";
11
+ import { RelationCombobox as Ce } from "./RelationCombobox.js";
12
+ const oe = (a, l) => `${a ?? ""}\0${l ?? ""}`;
13
+ function Le(a, l) {
14
+ const p = new Map(l.map((x) => [oe(x[0], x[1]), x])), i = /* @__PURE__ */ new Set(), o = [];
15
+ for (const x of a) {
16
+ const b = oe(x.value, x.value2);
17
+ p.has(b) && !i.has(b) ? i.add(b) : o.push(x.id);
18
18
  }
19
- return b;
19
+ const u = [], g = [];
20
+ for (const [x, b] of p) {
21
+ if (i.has(x)) continue;
22
+ const c = o.shift();
23
+ c !== void 0 ? u.push({ id: c, pair: b }) : g.push(b);
24
+ }
25
+ return { repoint: u, create: g, remove: o };
26
+ }
27
+ const Te = (a, l) => {
28
+ const p = a.size ? [...a] : [null], i = l.size ? [...l] : [null];
29
+ return p.flatMap((o) => i.map((u) => [o, u]));
30
+ }, Ke = 10;
31
+ async function A(a, l, p) {
32
+ const i = [];
33
+ for (let o = 1; o <= 50; o++) {
34
+ const u = await a.request(Q(l, { ...p, limit: 1e3, page: o })).then((g) => g.data ?? []);
35
+ if (i.push(...u), u.length < 1e3) break;
36
+ }
37
+ return i;
20
38
  }
21
- const ye = (t) => [...(t ?? "").matchAll(/\{\{([\w.]+)\}\}/g)].map((l) => l[1]);
22
- function W(t, l) {
23
- const p = Y(), { data: b } = F({
24
- queryKey: ["collection-display-meta", t],
25
- queryFn: () => p.request(Q(`/collections/${t}`)).then((n) => {
26
- var u;
27
- return { display_template: ((u = n.data) == null ? void 0 : u.display_template) ?? null };
39
+ const Me = (a) => [...(a ?? "").matchAll(/\{\{([\w.]+)\}\}/g)].map((l) => l[1]);
40
+ function P(a, l) {
41
+ const p = ce(), { data: i } = K({
42
+ queryKey: ["collection-display-meta", a],
43
+ queryFn: () => p.request(Q(`/collections/${a}`)).then((c) => {
44
+ var s;
45
+ return { display_template: ((s = c.data) == null ? void 0 : s.display_template) ?? null };
28
46
  }),
29
- enabled: !!t,
47
+ enabled: !!a,
30
48
  staleTime: 10 * 6e4
31
- }), c = (b == null ? void 0 : b.display_template) ?? null, i = l === "all" ? "all" : [...l].sort().join(","), { data: y = [], isLoading: N } = F({
32
- queryKey: ["membership-set-labels", t, c, i],
49
+ }), o = (i == null ? void 0 : i.display_template) ?? null, u = l === "all" ? "all" : [...l].sort().join(","), { data: g = [], isLoading: x } = K({
50
+ queryKey: ["membership-set-labels", a, o, u],
33
51
  queryFn: async () => {
34
- const n = ye(c), u = n.length ? { fields: ["id", ...n].join(",") } : {};
35
- if (l === "all") return P(p, `/items/${t}`, u);
36
- const h = [];
37
- for (let g = 0; g < l.length; g += 150)
38
- h.push(
39
- ...await P(p, `/items/${t}`, {
40
- ...u,
41
- filter: JSON.stringify({ id: { _in: l.slice(g, g + 150) } })
52
+ const c = Me(o), s = c.length ? { fields: ["id", ...c].join(",") } : {};
53
+ if (l === "all") return A(p, `/items/${a}`, s);
54
+ const y = [];
55
+ for (let w = 0; w < l.length; w += 150)
56
+ y.push(
57
+ ...await A(p, `/items/${a}`, {
58
+ ...s,
59
+ filter: JSON.stringify({ id: { _in: l.slice(w, w + 150) } })
42
60
  })
43
61
  );
44
- return h;
62
+ return y;
45
63
  },
46
- enabled: !!t && b !== void 0 && (l === "all" || l.length > 0),
64
+ enabled: !!a && i !== void 0 && (l === "all" || l.length > 0),
47
65
  staleTime: 6e4
48
66
  });
49
- return { labels: C(() => {
50
- const n = /* @__PURE__ */ new Map();
51
- for (const u of y) {
52
- const h = String(u.name ?? u.title ?? u.label ?? `#${u.id}`);
53
- n.set(String(u.id), (c ? he(c, u) : "").trim() || h);
67
+ return { labels: _(() => {
68
+ const c = /* @__PURE__ */ new Map();
69
+ for (const s of g) {
70
+ const y = String(s.name ?? s.title ?? s.label ?? `#${s.id}`);
71
+ c.set(String(s.id), (o ? qe(o, s) : "").trim() || y);
54
72
  }
55
- return n;
56
- }, [y, c]), isLoading: N };
73
+ return c;
74
+ }, [g, o]), isLoading: x };
57
75
  }
58
- function Te({
59
- relatedCollection: t,
76
+ function Je({
77
+ relatedCollection: a,
60
78
  manyField: l,
61
79
  parentId: p,
62
- config: b,
63
- readOnly: c
80
+ config: i,
81
+ readOnly: o
64
82
  }) {
65
- const i = Y(), y = oe(), N = p === "new", { key_field: f, value_field: n } = b, u = b.empty_label ?? "All", [h, g] = L(""), [q, o] = L(null), [$, O] = L(null), { data: I = [] } = F({
66
- queryKey: ["collection-relations", t],
67
- queryFn: () => i.request(Q(`/collections/${t}`)).then((e) => {
83
+ const u = ce(), g = ye(), x = p === "new", { key_field: b, value_field: c } = i, s = i.value_field_2 || null, y = i.empty_label ?? "All", w = i.empty_label_2 ?? y, [S, m] = C(""), [k, R] = C(null), [z, B] = C(null), { data: ue = [] } = K({
84
+ queryKey: ["collection-relations", a],
85
+ queryFn: () => u.request(Q(`/collections/${a}`)).then((e) => {
68
86
  var r;
69
87
  return ((r = e.data) == null ? void 0 : r.relations) ?? [];
70
88
  }),
71
89
  staleTime: 10 * 6e4
72
- }), R = (e) => {
90
+ }), M = (e) => {
73
91
  var r;
74
- return ((r = I.find((a) => a.many_collection === t && a.many_field === e)) == null ? void 0 : r.one_collection) ?? null;
75
- }, T = R(f), D = R(n), E = ["membership-set-rows", t, l, String(p)], { data: J = [], isLoading: ee } = F({
76
- queryKey: E,
77
- queryFn: async () => (await P(i, `/items/${t}`, {
78
- fields: `id,${f},${n}`,
92
+ return ((r = ue.find((t) => t.many_collection === a && t.many_field === e)) == null ? void 0 : r.one_collection) ?? null;
93
+ }, L = M(b), D = M(c), E = s ? M(s) : null, J = ["membership-set-rows", a, l, String(p)], { data: V = [], isLoading: me } = K({
94
+ queryKey: J,
95
+ queryFn: async () => (await A(u, `/items/${a}`, {
96
+ fields: ["id", b, c, ...s ? [s] : []].join(","),
79
97
  filter: JSON.stringify({ [l]: { _eq: p } })
80
- })).filter((e) => e[f] != null).map((e) => ({
98
+ })).filter((e) => e[b] != null).map((e) => ({
81
99
  id: e.id,
82
- key: String(e[f]),
83
- value: e[n] == null ? null : String(e[n])
100
+ key: String(e[b]),
101
+ value: e[c] == null ? null : String(e[c]),
102
+ value2: !s || e[s] == null ? null : String(e[s])
84
103
  })),
85
- enabled: !N,
104
+ enabled: !x,
86
105
  staleTime: 15e3
87
- }), k = C(() => {
106
+ }), N = _(() => {
88
107
  const e = /* @__PURE__ */ new Map();
89
- for (const r of J) e.set(r.key, [...e.get(r.key) ?? [], r]);
108
+ for (const r of V) e.set(r.key, [...e.get(r.key) ?? [], r]);
90
109
  return e;
91
- }, [J]), x = C(() => [...k.keys()], [k]), { labels: V } = W(T, x), { labels: z } = W(D, "all"), te = C(
92
- () => [...z.entries()].map(([e, r]) => ({ id: e, label: r })).sort((e, r) => e.label.localeCompare(r.label, void 0, { numeric: !0 })),
93
- [z]
94
- ), re = () => {
95
- y.invalidateQueries({ queryKey: E }), y.invalidateQueries({ queryKey: ["o2m-rows", t] });
110
+ }, [V]), v = _(() => [...N.keys()], [N]), { labels: H } = P(L, v), { labels: U } = P(D, "all"), { labels: X } = P(E, "all"), G = (e) => [...e.entries()].map(([r, t]) => ({ id: r, label: t })).sort((r, t) => r.label.localeCompare(t.label, void 0, { numeric: !0 })), pe = _(() => G(U), [U]), be = _(() => G(X), [X]), he = () => {
111
+ g.invalidateQueries({ queryKey: J }), g.invalidateQueries({ queryKey: ["o2m-rows", a] });
96
112
  }, j = async (e, r) => {
97
- o(e), O(null);
113
+ R(e), B(null);
98
114
  try {
99
115
  await r();
100
- } catch (a) {
101
- const d = a == null ? void 0 : a.response;
102
- O((d == null ? void 0 : d.error) ?? ue(a, "Could not save"));
116
+ } catch (t) {
117
+ const h = t == null ? void 0 : t.response;
118
+ B((h == null ? void 0 : h.error) ?? Ne(t, "Could not save"));
103
119
  } finally {
104
- o(null), re();
120
+ R(null), he();
105
121
  }
106
- }, ae = (e, r) => j(e, async () => {
107
- const a = k.get(e) ?? [], d = a.find((w) => w.value === r), S = a.find((w) => w.value === null);
108
- if (d) {
109
- a.filter((v) => v.value !== null && v.id !== d.id).length === 0 && !S ? await i.request(M(`/items/${t}/${d.id}`, { [n]: null })) : await i.request(A(`/items/${t}/${d.id}`));
110
- return;
111
- }
112
- S ? await i.request(
113
- M(`/items/${t}/${S.id}`, { [n]: r })
114
- ) : await i.request(
115
- X(`/items/${t}`, {
116
- [l]: p,
117
- [f]: e,
118
- [n]: r
119
- })
120
- );
121
- }), se = (e) => j(e, async () => {
122
- const r = k.get(e) ?? [], a = r.filter((v) => v.value !== null);
123
- if (a.length === 0) return;
124
- const [d, ...S] = a, w = r.find((v) => v.value === null);
125
- for (const v of w ? a : S)
126
- await i.request(A(`/items/${t}/${v.id}`));
127
- w || await i.request(M(`/items/${t}/${d.id}`, { [n]: null }));
128
- }), le = (e) => j(e, async () => {
129
- for (const r of k.get(e) ?? [])
130
- await i.request(A(`/items/${t}/${r.id}`));
131
- }), ne = (e) => {
132
- e == null || e === "" || k.has(String(e)) || j(
122
+ }, W = (e) => {
123
+ const r = N.get(e) ?? [];
124
+ return {
125
+ a: new Set(r.filter((t) => t.value !== null).map((t) => t.value)),
126
+ b: new Set(r.filter((t) => t.value2 !== null).map((t) => t.value2))
127
+ };
128
+ }, F = ([e, r]) => ({
129
+ [c]: e,
130
+ ...s ? { [s]: r } : {}
131
+ }), T = (e, r, t) => j(e, async () => {
132
+ const h = Le(N.get(e) ?? [], Te(r, t));
133
+ for (const d of h.repoint)
134
+ await u.request(ke(`/items/${a}/${d.id}`, F(d.pair)));
135
+ for (const d of h.create)
136
+ await u.request(
137
+ se(`/items/${a}`, {
138
+ [l]: p,
139
+ [b]: e,
140
+ ...F(d)
141
+ })
142
+ );
143
+ for (const d of h.remove) await u.request(ne(`/items/${a}/${d}`));
144
+ }), Y = (e, r) => {
145
+ const t = new Set(e);
146
+ return t.has(r) ? t.delete(r) : t.add(r), t;
147
+ }, Z = (e, r, t = 1) => {
148
+ const { a: h, b: d } = W(e);
149
+ return t === 1 ? T(e, Y(h, r), d) : T(e, h, Y(d, r));
150
+ }, I = (e, r = 1) => {
151
+ const { a: t, b: h } = W(e);
152
+ if ((r === 1 ? t : h).size !== 0)
153
+ return r === 1 ? T(e, /* @__PURE__ */ new Set(), h) : T(e, t, /* @__PURE__ */ new Set());
154
+ }, fe = (e) => j(e, async () => {
155
+ for (const r of N.get(e) ?? [])
156
+ await u.request(ne(`/items/${a}/${r.id}`));
157
+ }), xe = (e) => {
158
+ e == null || e === "" || N.has(String(e)) || j(
133
159
  String(e),
134
- () => i.request(
135
- X(`/items/${t}`, { [l]: p, [f]: e, [n]: null })
160
+ () => u.request(
161
+ se(`/items/${a}`, {
162
+ [l]: p,
163
+ [b]: e,
164
+ ...F([null, null])
165
+ })
136
166
  )
137
167
  );
138
- }, B = C(() => {
139
- const e = x.map((a) => ({ key: a, label: V.get(a) ?? `#${a}` })).sort((a, d) => a.label.localeCompare(d.label, void 0, { numeric: !0 })), r = h.trim();
140
- return r ? e.filter((a) => Z(a.label, r)) : e;
141
- }, [x, V, h]), _ = b.key_label ?? G(T ?? f), H = b.value_label ?? G(D ?? n);
142
- return N ? /* @__PURE__ */ m("p", { className: "rounded-lg border border-dashed border-slate-200 px-3 py-4 text-[12px] text-slate-500 dark:border-border dark:text-muted-foreground", children: [
168
+ }, ee = _(() => {
169
+ const e = v.map((t) => ({ key: t, label: H.get(t) ?? `#${t}` })).sort((t, h) => t.label.localeCompare(h.label, void 0, { numeric: !0 })), r = S.trim();
170
+ return r ? e.filter((t) => de(t.label, r)) : e;
171
+ }, [v, H, S]), q = i.key_label ?? O(L ?? b), te = i.value_label ?? O(D ?? c), re = s ? i.value_label_2 ?? O(E ?? s) : "", ae = s ? "grid-cols-[minmax(140px,1fr)_minmax(0,1.5fr)_minmax(0,1.5fr)_28px]" : "grid-cols-[minmax(140px,1fr)_minmax(0,2fr)_28px]";
172
+ return x ? /* @__PURE__ */ f("p", { className: "rounded-lg border border-dashed border-slate-200 px-3 py-4 text-[12px] text-slate-500 dark:border-border dark:text-muted-foreground", children: [
143
173
  "Save this record first, then add ",
144
- _.toLowerCase(),
174
+ q.toLowerCase(),
145
175
  " here."
146
- ] }) : /* @__PURE__ */ m("div", { "data-membership-set": `${t}:${l}`, className: "space-y-2", children: [
147
- !c && T && /* @__PURE__ */ m("div", { className: "flex flex-wrap items-center gap-2", children: [
148
- /* @__PURE__ */ s("div", { className: "w-[320px] max-w-full", children: /* @__PURE__ */ s(
149
- fe,
176
+ ] }) : /* @__PURE__ */ f("div", { "data-membership-set": `${a}:${l}`, className: "space-y-2", children: [
177
+ !o && L && /* @__PURE__ */ f("div", { className: "flex flex-wrap items-center gap-2", children: [
178
+ /* @__PURE__ */ n("div", { className: "w-[320px] max-w-full", children: /* @__PURE__ */ n(
179
+ Ce,
150
180
  {
151
- collection: T,
181
+ collection: L,
152
182
  value: null,
153
- onChange: ne,
154
- placeholder: `Add ${_.toLowerCase()}…`,
155
- extraFilter: x.length && x.length <= 400 ? { id: { _nin: x } } : void 0
183
+ onChange: xe,
184
+ placeholder: `Add ${q.toLowerCase()}…`,
185
+ extraFilter: v.length && v.length <= 400 ? { id: { _nin: v } } : void 0
156
186
  },
157
- x.length
187
+ v.length
158
188
  ) }),
159
- x.length > 8 && /* @__PURE__ */ m("label", { className: "relative ml-auto block w-[220px] max-w-full", children: [
160
- /* @__PURE__ */ s(ie, { className: "pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-slate-400" }),
161
- /* @__PURE__ */ s(
189
+ v.length > 8 && /* @__PURE__ */ f("label", { className: "relative ml-auto block w-[220px] max-w-full", children: [
190
+ /* @__PURE__ */ n(ge, { className: "pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-slate-400" }),
191
+ /* @__PURE__ */ n(
162
192
  "input",
163
193
  {
164
- value: h,
165
- onChange: (e) => g(e.target.value),
166
- placeholder: `Filter ${x.length}…`,
167
- "aria-label": `Filter ${_}`,
194
+ value: S,
195
+ onChange: (e) => m(e.target.value),
196
+ placeholder: `Filter ${v.length}…`,
197
+ "aria-label": `Filter ${q}`,
168
198
  className: "h-8 w-full rounded-md border border-slate-200 bg-background pl-7 pr-2 text-[12px] outline-none focus:border-nvr-cyan dark:border-border"
169
199
  }
170
200
  )
171
201
  ] })
172
202
  ] }),
173
- /* @__PURE__ */ m("div", { className: "overflow-hidden rounded-lg border border-slate-200 dark:border-border", children: [
174
- /* @__PURE__ */ m("div", { className: "grid grid-cols-[minmax(140px,1fr)_minmax(0,2fr)_28px] gap-3 border-b border-slate-200 bg-slate-50 px-3 py-1.5 text-[10.5px] font-medium uppercase tracking-wide text-slate-500 dark:border-border dark:bg-muted dark:text-muted-foreground", children: [
175
- /* @__PURE__ */ s("span", { children: _ }),
176
- /* @__PURE__ */ m("span", { children: [
177
- H,
178
- " ",
179
- /* @__PURE__ */ m("span", { className: "normal-case tracking-normal text-slate-400", children: [
180
- "· none picked = ",
181
- u.toLowerCase()
182
- ] })
183
- ] }),
184
- /* @__PURE__ */ s("span", {})
185
- ] }),
186
- ee ? /* @__PURE__ */ s("div", { className: "space-y-2 p-3", children: [0, 1, 2].map((e) => /* @__PURE__ */ s("div", { className: "h-6 animate-pulse rounded bg-[hsl(var(--nvr-skeleton))]" }, e)) }) : B.length === 0 ? /* @__PURE__ */ s("p", { className: "px-3 py-5 text-center text-[12px] text-slate-500 dark:text-muted-foreground", children: x.length ? "Nothing matches that filter." : `No ${_.toLowerCase()} yet.` }) : /* @__PURE__ */ s("ul", { className: "max-h-[480px] divide-y divide-slate-100 overflow-y-auto dark:divide-border", children: B.map((e) => {
187
- const r = k.get(e.key) ?? [], a = new Set(r.filter((d) => d.value !== null).map((d) => d.value));
188
- return /* @__PURE__ */ m(
203
+ /* @__PURE__ */ f("div", { className: "overflow-hidden rounded-lg border border-slate-200 dark:border-border", children: [
204
+ /* @__PURE__ */ f(
205
+ "div",
206
+ {
207
+ className: $(
208
+ ae,
209
+ "grid gap-3 border-b border-slate-200 bg-slate-50 px-3 py-1.5 text-[10.5px] font-medium uppercase tracking-wide text-slate-500 dark:border-border dark:bg-muted dark:text-muted-foreground"
210
+ ),
211
+ children: [
212
+ /* @__PURE__ */ n("span", { children: q }),
213
+ /* @__PURE__ */ f("span", { children: [
214
+ te,
215
+ " ",
216
+ /* @__PURE__ */ f("span", { className: "normal-case tracking-normal text-slate-400", children: [
217
+ "· none picked = ",
218
+ y.toLowerCase()
219
+ ] })
220
+ ] }),
221
+ s && /* @__PURE__ */ f("span", { children: [
222
+ re,
223
+ " ",
224
+ /* @__PURE__ */ f("span", { className: "normal-case tracking-normal text-slate-400", children: [
225
+ "· none picked = ",
226
+ w.toLowerCase()
227
+ ] })
228
+ ] }),
229
+ /* @__PURE__ */ n("span", {})
230
+ ]
231
+ }
232
+ ),
233
+ me ? /* @__PURE__ */ n("div", { className: "space-y-2 p-3", children: [0, 1, 2].map((e) => /* @__PURE__ */ n("div", { className: "h-6 animate-pulse rounded bg-[hsl(var(--nvr-skeleton))]" }, e)) }) : ee.length === 0 ? /* @__PURE__ */ n("p", { className: "px-3 py-5 text-center text-[12px] text-slate-500 dark:text-muted-foreground", children: v.length ? "Nothing matches that filter." : `No ${q.toLowerCase()} yet.` }) : /* @__PURE__ */ n("ul", { className: "max-h-[480px] divide-y divide-slate-100 overflow-y-auto dark:divide-border", children: ee.map((e) => {
234
+ const r = N.get(e.key) ?? [], t = new Set(
235
+ r.filter((d) => d.value !== null).map((d) => d.value)
236
+ ), h = new Set(
237
+ r.filter((d) => d.value2 !== null).map((d) => d.value2)
238
+ );
239
+ return /* @__PURE__ */ f(
189
240
  "li",
190
241
  {
191
242
  "data-membership-key": e.key,
192
- className: K(
193
- "grid grid-cols-[minmax(140px,1fr)_minmax(0,2fr)_28px] items-center gap-3 px-3 py-1.5 text-[12px]",
194
- q === e.key && "opacity-60"
243
+ className: $(
244
+ ae,
245
+ "grid items-center gap-3 px-3 py-1.5 text-[12px]",
246
+ k === e.key && "opacity-60"
195
247
  ),
196
248
  children: [
197
- /* @__PURE__ */ s("span", { className: "truncate font-medium text-slate-800 dark:text-foreground", "data-tip": e.label, children: e.label }),
198
- /* @__PURE__ */ s(
199
- ge,
249
+ /* @__PURE__ */ n(
250
+ "span",
251
+ {
252
+ className: "truncate font-medium text-slate-800 dark:text-foreground",
253
+ "data-tip": e.label,
254
+ children: e.label
255
+ }
256
+ ),
257
+ /* @__PURE__ */ n(
258
+ ie,
200
259
  {
201
- options: te,
202
- picked: a,
203
- emptyLabel: u,
204
- valueTitle: H,
205
- disabled: !!c || q === e.key,
206
- onToggle: (d) => ae(e.key, d),
207
- onClear: () => se(e.key)
260
+ options: pe,
261
+ picked: t,
262
+ emptyLabel: y,
263
+ valueTitle: te,
264
+ disabled: !!o || k === e.key,
265
+ onToggle: (d) => Z(e.key, d),
266
+ onClear: () => I(e.key)
208
267
  }
209
268
  ),
210
- c ? /* @__PURE__ */ s("span", {}) : /* @__PURE__ */ s(
269
+ s && /* @__PURE__ */ n(
270
+ ie,
271
+ {
272
+ options: be,
273
+ picked: h,
274
+ emptyLabel: w,
275
+ valueTitle: re,
276
+ disabled: !!o || k === e.key,
277
+ onToggle: (d) => Z(e.key, d, 2),
278
+ onClear: () => I(e.key, 2)
279
+ }
280
+ ),
281
+ o ? /* @__PURE__ */ n("span", {}) : /* @__PURE__ */ n(
211
282
  "button",
212
283
  {
213
284
  type: "button",
214
- onClick: () => le(e.key),
215
- disabled: q === e.key,
285
+ onClick: () => fe(e.key),
286
+ disabled: k === e.key,
216
287
  "aria-label": `Remove ${e.label}`,
217
288
  "data-tip": "Remove",
218
289
  className: "flex h-6 w-6 items-center justify-center rounded text-slate-400 hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-500/10",
219
- children: /* @__PURE__ */ s(de, { className: "h-3.5 w-3.5" })
290
+ children: /* @__PURE__ */ n(ve, { className: "h-3.5 w-3.5" })
220
291
  }
221
292
  )
222
293
  ]
@@ -225,97 +296,103 @@ function Te({
225
296
  );
226
297
  }) })
227
298
  ] }),
228
- $ && /* @__PURE__ */ s("p", { className: "text-[12px] text-red-600 dark:text-red-400", children: $ })
299
+ z && /* @__PURE__ */ n("p", { className: "text-[12px] text-red-600 dark:text-red-400", children: z })
229
300
  ] });
230
301
  }
231
- function ge({
232
- options: t,
302
+ function ie({
303
+ options: a,
233
304
  picked: l,
234
305
  emptyLabel: p,
235
- valueTitle: b,
236
- disabled: c,
237
- onToggle: i,
238
- onClear: y
306
+ valueTitle: i,
307
+ disabled: o,
308
+ onToggle: u,
309
+ onClear: g
239
310
  }) {
240
- const [N, f] = L(!1), [n, u] = L(""), h = l.size === 0;
241
- if (t.length <= xe)
242
- return /* @__PURE__ */ m("div", { className: "flex flex-wrap items-center gap-1", "data-membership-values": !0, children: [
243
- /* @__PURE__ */ s(
311
+ const [x, b] = C(!1), [c, s] = C(""), y = l.size === 0;
312
+ if (a.length <= Ke)
313
+ return /* @__PURE__ */ f("div", { className: "flex flex-wrap items-center gap-1", "data-membership-values": !0, children: [
314
+ /* @__PURE__ */ n(
244
315
  "button",
245
316
  {
246
317
  type: "button",
247
- disabled: c || h,
248
- "aria-pressed": h,
249
- onClick: y,
250
- className: K(
318
+ disabled: o || y,
319
+ "aria-pressed": y,
320
+ onClick: g,
321
+ className: $(
251
322
  "h-6 rounded-full border px-2 text-[11px] transition-colors",
252
- h ? "border-nvr-cyan/40 bg-nvr-cyan/10 font-medium text-slate-800 dark:text-foreground" : "border-slate-200 text-slate-500 hover:bg-muted dark:border-border dark:text-muted-foreground"
323
+ y ? "border-nvr-cyan/40 bg-nvr-cyan/10 font-medium text-slate-800 dark:text-foreground" : "border-slate-200 text-slate-500 hover:bg-muted dark:border-border dark:text-muted-foreground"
253
324
  ),
254
325
  children: p
255
326
  }
256
327
  ),
257
- t.map((o) => {
258
- const $ = l.has(o.id);
259
- return /* @__PURE__ */ m(
328
+ a.map((m) => {
329
+ const k = l.has(m.id);
330
+ return /* @__PURE__ */ f(
260
331
  "button",
261
332
  {
262
333
  type: "button",
263
- disabled: c,
264
- "aria-pressed": $,
265
- "data-membership-value": o.id,
266
- onClick: () => i(o.id),
267
- className: K(
334
+ disabled: o,
335
+ "aria-pressed": k,
336
+ "data-membership-value": m.id,
337
+ onClick: () => u(m.id),
338
+ className: $(
268
339
  "inline-flex h-6 items-center gap-1 rounded-full border px-2 text-[11px] transition-colors",
269
- $ ? "border-nvr-cyan/40 bg-nvr-cyan/10 font-medium text-slate-800 dark:text-foreground" : "border-slate-200 text-slate-500 hover:bg-muted dark:border-border dark:text-muted-foreground"
340
+ k ? "border-nvr-cyan/40 bg-nvr-cyan/10 font-medium text-slate-800 dark:text-foreground" : "border-slate-200 text-slate-500 hover:bg-muted dark:border-border dark:text-muted-foreground"
270
341
  ),
271
342
  children: [
272
- $ && /* @__PURE__ */ s(U, { className: "h-3 w-3" }),
273
- o.label
343
+ k && /* @__PURE__ */ n(le, { className: "h-3 w-3" }),
344
+ m.label
274
345
  ]
275
346
  },
276
- o.id
347
+ m.id
277
348
  );
278
349
  })
279
350
  ] });
280
- const g = n.trim() ? t.filter((o) => Z(o.label, n)) : t, q = h ? p : t.filter((o) => l.has(o.id)).map((o) => o.label).join(", ");
281
- return /* @__PURE__ */ m(me, { open: N, onOpenChange: f, children: [
282
- /* @__PURE__ */ s(pe, { asChild: !0, children: /* @__PURE__ */ m(
351
+ const w = c.trim() ? a.filter((m) => de(m.label, c)) : a, S = y ? p : a.filter((m) => l.has(m.id)).map((m) => m.label).join(", ");
352
+ return /* @__PURE__ */ f(_e, { open: x, onOpenChange: b, children: [
353
+ /* @__PURE__ */ n($e, { asChild: !0, children: /* @__PURE__ */ f(
283
354
  "button",
284
355
  {
285
356
  type: "button",
286
- disabled: c,
357
+ disabled: o,
287
358
  className: "flex h-7 w-full items-center justify-between gap-2 rounded-md border border-slate-200 bg-background px-2 text-left text-[12px] dark:border-border",
288
359
  children: [
289
- /* @__PURE__ */ s("span", { className: K("truncate", h && "text-slate-500 dark:text-muted-foreground"), children: q }),
290
- /* @__PURE__ */ s(ce, { className: "h-3.5 w-3.5 shrink-0 text-slate-400" })
360
+ /* @__PURE__ */ n("span", { className: $("truncate", y && "text-slate-500 dark:text-muted-foreground"), children: S }),
361
+ /* @__PURE__ */ n(we, { className: "h-3.5 w-3.5 shrink-0 text-slate-400" })
291
362
  ]
292
363
  }
293
364
  ) }),
294
- /* @__PURE__ */ m(be, { align: "start", className: "w-[260px] p-1", children: [
295
- /* @__PURE__ */ s(
365
+ /* @__PURE__ */ f(Se, { align: "start", className: "w-[260px] p-1", children: [
366
+ /* @__PURE__ */ n(
296
367
  "input",
297
368
  {
298
- value: n,
299
- onChange: (o) => u(o.target.value),
300
- placeholder: `Search ${b.toLowerCase()}…`,
369
+ value: c,
370
+ onChange: (m) => s(m.target.value),
371
+ placeholder: `Search ${i.toLowerCase()}…`,
301
372
  className: "mb-1 h-7 w-full rounded border border-slate-200 bg-background px-2 text-[12px] outline-none dark:border-border"
302
373
  }
303
374
  ),
304
- /* @__PURE__ */ s("ul", { className: "max-h-[240px] overflow-y-auto", children: g.map((o) => /* @__PURE__ */ s("li", { children: /* @__PURE__ */ m(
375
+ /* @__PURE__ */ n("ul", { className: "max-h-[240px] overflow-y-auto", children: w.map((m) => /* @__PURE__ */ n("li", { children: /* @__PURE__ */ f(
305
376
  "button",
306
377
  {
307
378
  type: "button",
308
- onClick: () => i(o.id),
379
+ onClick: () => u(m.id),
309
380
  className: "flex w-full items-center gap-2 rounded px-2 py-1 text-left text-[12px] hover:bg-muted",
310
381
  children: [
311
- /* @__PURE__ */ s(U, { className: K("h-3.5 w-3.5", l.has(o.id) ? "opacity-100" : "opacity-0") }),
312
- o.label
382
+ /* @__PURE__ */ n(
383
+ le,
384
+ {
385
+ className: $("h-3.5 w-3.5", l.has(m.id) ? "opacity-100" : "opacity-0")
386
+ }
387
+ ),
388
+ m.label
313
389
  ]
314
390
  }
315
- ) }, o.id)) })
391
+ ) }, m.id)) })
316
392
  ] })
317
393
  ] });
318
394
  }
319
395
  export {
320
- Te as MembershipSetField
396
+ Je as MembershipSetField,
397
+ Le as planMembershipRows
321
398
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivaro/react",
3
- "version": "0.3.77",
3
+ "version": "0.3.78",
4
4
  "description": "React hooks and components for Nivaro CMS forms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",