@nivaro/react 0.3.38 → 0.3.40

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,55 @@
1
+ import { useQueries as _ } from "@tanstack/react-query";
2
+ import { useMemo as c, useCallback as x } from "react";
3
+ import { useNivaroClient as f } from "../context.js";
4
+ import { post as g } from "../lib/commands.js";
5
+ const m = "picker-exclusions-page";
6
+ function S(a, d) {
7
+ const l = f(), o = c(() => {
8
+ const e = /* @__PURE__ */ new Map();
9
+ for (const t of a) {
10
+ if (!t.collection || t.id == null) continue;
11
+ const n = e.get(t.collection) ?? [];
12
+ n.push(String(t.id)), e.set(t.collection, n);
13
+ }
14
+ return [...e.entries()].map(([t, n]) => ({
15
+ collection: t,
16
+ ids: [...new Set(n)].sort()
17
+ }));
18
+ }, [a]), s = _({
19
+ queries: o.map(({ collection: e, ids: t }) => ({
20
+ queryKey: [m, e, t.join(",")],
21
+ queryFn: () => l.request(
22
+ g("/picker-exclusions/batch-status", { collection: e, ids: t })
23
+ ).then((n) => {
24
+ var r;
25
+ return ((r = n.data) == null ? void 0 : r.excluded) ?? [];
26
+ }),
27
+ enabled: d && t.length > 0,
28
+ staleTime: 6e4,
29
+ retry: !1
30
+ }))
31
+ }), p = s.map((e) => (e.data ?? []).join(",")).join("|"), i = c(() => {
32
+ const e = /* @__PURE__ */ new Set();
33
+ return o.forEach(({ collection: t }, n) => {
34
+ var r;
35
+ for (const u of ((r = s[n]) == null ? void 0 : r.data) ?? []) e.add(`${t}|${String(u).toUpperCase()}`);
36
+ }), e;
37
+ }, [o, p]);
38
+ return x(
39
+ (e, t) => i.has(`${e}|${String(t).toUpperCase()}`),
40
+ [i]
41
+ );
42
+ }
43
+ const y = "Excluded from pickers — not offered in any dropdown. Actions → Include in pickers to offer it again.", h = [
44
+ "[&>td]:italic [&>td_*]:italic",
45
+ "[&>td]:!text-slate-500 [&>td_a]:!text-slate-500 [&>td_button]:!text-slate-500",
46
+ "dark:[&>td]:!text-slate-400 dark:[&>td_a]:!text-slate-400 dark:[&>td_button]:!text-slate-400",
47
+ "[&>td]:bg-[repeating-linear-gradient(135deg,rgb(100_116_139/0.09)_0_1px,transparent_1px_6px)]",
48
+ "dark:[&>td]:bg-[repeating-linear-gradient(135deg,rgb(148_163_184/0.10)_0_1px,transparent_1px_6px)]"
49
+ ].join(" ");
50
+ export {
51
+ h as PICKER_EXCLUDED_ROW_CLASS,
52
+ y as PICKER_EXCLUDED_TITLE,
53
+ m as PICKER_EXCLUSIONS_PAGE_KEY,
54
+ S as usePickerExcludedRows
55
+ };
@@ -1,86 +1,93 @@
1
1
  import { jsxs as n, jsx as t } from "react/jsx-runtime";
2
- import { useQueryClient as D, useQuery as j, useMutation as F } from "@tanstack/react-query";
3
- import { Loader2 as I, EyeOff as L, CalendarClock as Q, ChevronsUpDown as R, Check as B } from "lucide-react";
4
- import { useState as c, useId as K, useMemo as M } from "react";
5
- import { toast as f } from "sonner";
6
- import { useNivaroClient as $ } from "../../context.js";
7
- import { get as V, post as q } from "../../lib/commands.js";
8
- import { titleCase as W, cn as z } from "../../lib/utils.js";
9
- import { Button as w } from "../ui/button.js";
10
- import { Command as A, CommandInput as H, CommandList as U, CommandEmpty as G, CommandItem as J } from "../ui/command.js";
11
- import { Input as S } from "../ui/input.js";
12
- import { Popover as _, PopoverTrigger as E, PopoverContent as P } from "../ui/popover.js";
13
- function O(l, r) {
14
- return l instanceof Error && l.message ? l.message : r;
2
+ import { useQueryClient as D, useQuery as I, useMutation as q } from "@tanstack/react-query";
3
+ import { Loader2 as K, EyeOff as L, CalendarClock as Q, ChevronsUpDown as R, Check as j } from "lucide-react";
4
+ import { useState as m, useId as A, useMemo as B } from "react";
5
+ import { toast as g } from "sonner";
6
+ import { useNivaroClient as F } from "../../context.js";
7
+ import { get as M, post as O } from "../../lib/commands.js";
8
+ import { titleCase as U, cn as V } from "../../lib/utils.js";
9
+ import { PICKER_EXCLUSIONS_PAGE_KEY as W } from "../PickerExcludedRows.js";
10
+ import { Button as S } from "../ui/button.js";
11
+ import { Command as z, CommandInput as G, CommandList as H, CommandEmpty as X, CommandItem as Y } from "../ui/command.js";
12
+ import { Input as w } from "../ui/input.js";
13
+ import { Popover as E, PopoverTrigger as _, PopoverContent as P } from "../ui/popover.js";
14
+ function $(a, r) {
15
+ return a instanceof Error && a.message ? a.message : r;
15
16
  }
16
- function ce({
17
- collection: l,
18
- itemId: r,
19
- layoutSlug: d
20
- }) {
21
- const u = $(), x = D(), m = ["picker-exclusion", l, r], { data: s } = j({
22
- queryKey: m,
23
- queryFn: () => u.request(
24
- V(`/picker-exclusions/status/${l}/${r}`)
25
- ).then((a) => a.data),
17
+ function J(a, r, l = {}) {
18
+ const s = F(), o = D(), h = ["picker-exclusion", a, r], { data: c, isLoading: p } = I({
19
+ queryKey: h,
20
+ queryFn: () => s.request(
21
+ M(`/picker-exclusions/status/${a}/${r}`)
22
+ ).then((i) => i.data),
23
+ enabled: l.enabled ?? !0,
26
24
  staleTime: 6e4
27
- }), i = (s == null ? void 0 : s.excluded) ?? !1, o = F({
25
+ }), d = (c == null ? void 0 : c.excluded) ?? !1, u = q({
28
26
  mutationFn: () => {
29
- const a = { collection: l, item_id: r, layout: d ?? null };
30
- return u.request(
31
- i ? { _method: "DELETE", _path: "/picker-exclusions", _body: a } : q("/picker-exclusions", a)
27
+ const i = { collection: a, item_id: r, layout: l.layoutSlug ?? null };
28
+ return s.request(
29
+ d ? { _method: "DELETE", _path: "/picker-exclusions", _body: i } : O("/picker-exclusions", i)
32
30
  );
33
31
  },
34
32
  onSuccess: () => {
35
- x.invalidateQueries({ queryKey: m }), f.success(i ? "Record re-enabled in pickers" : "Record excluded from pickers");
33
+ var i;
34
+ o.invalidateQueries({ queryKey: h }), o.invalidateQueries({ queryKey: [W, a] }), g.success(d ? "Record re-enabled in pickers" : "Record excluded from pickers"), (i = l.onDone) == null || i.call(l);
36
35
  },
37
- onError: (a) => f.error(O(a, "Could not change picker visibility"))
36
+ onError: (i) => g.error($(i, "Could not change picker visibility"))
38
37
  });
38
+ return { excluded: d, isLoading: p, toggle: u };
39
+ }
40
+ function me({
41
+ collection: a,
42
+ itemId: r,
43
+ layoutSlug: l
44
+ }) {
45
+ const { excluded: s, toggle: o } = J(a, r, { layoutSlug: l });
39
46
  return /* @__PURE__ */ n(
40
47
  "button",
41
48
  {
42
49
  type: "button",
43
50
  "data-record-picker-exclusion": !0,
44
- "data-excluded": i ? "true" : "false",
51
+ "data-excluded": s ? "true" : "false",
45
52
  disabled: o.isPending,
46
53
  onClick: () => o.mutate(),
47
- "data-tip": i ? "This record is hidden from pickers — click to offer it again" : "Hide this record from every picker that would offer it",
54
+ "data-tip": s ? "This record is hidden from pickers — click to offer it again" : "Hide this record from every picker that would offer it",
48
55
  className: "inline-flex items-center",
49
56
  children: [
50
- o.isPending ? /* @__PURE__ */ t(I, { className: "animate-spin" }) : /* @__PURE__ */ t(L, {}),
51
- i ? "Re-enable in pickers" : "Disable in pickers"
57
+ o.isPending ? /* @__PURE__ */ t(K, { className: "animate-spin" }) : /* @__PURE__ */ t(L, {}),
58
+ s ? "Re-enable in pickers" : "Disable in pickers"
52
59
  ]
53
60
  }
54
61
  );
55
62
  }
56
- function de({
57
- collection: l,
63
+ function he({
64
+ collection: a,
58
65
  itemId: r,
59
- fields: d,
60
- layoutSlug: u
66
+ fields: l,
67
+ layoutSlug: s
61
68
  }) {
62
- const x = $(), [m, s] = c(!1), [i, o] = c(!1), [a, N] = c(""), [g, v] = c(""), [p, C] = c(""), h = K(), k = M(
63
- () => d.filter((e) => !e.field.startsWith("__") && !e.field.includes(".")).map((e) => ({ field: e.field, label: e.label || W(e.field) })),
64
- [d]
65
- ), b = k.find((e) => e.field === a), y = F({
66
- mutationFn: () => x.request(
67
- q("/scheduled-changes", {
68
- collection: l,
69
+ const o = F(), [h, c] = m(!1), [p, d] = m(!1), [u, i] = m(""), [b, N] = m(""), [f, C] = m(""), x = A(), k = B(
70
+ () => l.filter((e) => !e.field.startsWith("__") && !e.field.includes(".")).map((e) => ({ field: e.field, label: e.label || U(e.field) })),
71
+ [l]
72
+ ), y = k.find((e) => e.field === u), v = q({
73
+ mutationFn: () => o.request(
74
+ O("/scheduled-changes", {
75
+ collection: a,
69
76
  item_id: r,
70
77
  change_type: "field_update",
71
- changes: { [a]: g },
78
+ changes: { [u]: b },
72
79
  // datetime-local is the viewer's local time; the API stores UTC.
73
- scheduled_at: new Date(p).toISOString(),
74
- layout: u ?? null
80
+ scheduled_at: new Date(f).toISOString(),
81
+ layout: s ?? null
75
82
  })
76
83
  ),
77
84
  onSuccess: () => {
78
- s(!1), N(""), v(""), C(""), f.success("Change scheduled");
85
+ c(!1), i(""), N(""), C(""), g.success("Change scheduled");
79
86
  },
80
- onError: (e) => f.error(O(e, "Could not schedule the change"))
81
- }), T = p !== "" && !Number.isNaN(new Date(p).getTime());
82
- return /* @__PURE__ */ n(_, { open: m, onOpenChange: s, children: [
83
- /* @__PURE__ */ t(E, { asChild: !0, children: /* @__PURE__ */ n(
87
+ onError: (e) => g.error($(e, "Could not schedule the change"))
88
+ }), T = f !== "" && !Number.isNaN(new Date(f).getTime());
89
+ return /* @__PURE__ */ n(E, { open: h, onOpenChange: c, children: [
90
+ /* @__PURE__ */ t(_, { asChild: !0, children: /* @__PURE__ */ n(
84
91
  "button",
85
92
  {
86
93
  type: "button",
@@ -98,41 +105,41 @@ function de({
98
105
  /* @__PURE__ */ n("div", { className: "space-y-3", children: [
99
106
  /* @__PURE__ */ n("div", { children: [
100
107
  /* @__PURE__ */ t("span", { className: "mb-1 block text-[11px] font-medium text-muted-foreground", children: "Field" }),
101
- /* @__PURE__ */ n(_, { open: i, onOpenChange: o, children: [
102
- /* @__PURE__ */ t(E, { asChild: !0, children: /* @__PURE__ */ n(
103
- w,
108
+ /* @__PURE__ */ n(E, { open: p, onOpenChange: d, children: [
109
+ /* @__PURE__ */ t(_, { asChild: !0, children: /* @__PURE__ */ n(
110
+ S,
104
111
  {
105
112
  type: "button",
106
113
  variant: "outline",
107
114
  role: "combobox",
108
- "aria-expanded": i,
115
+ "aria-expanded": p,
109
116
  "aria-label": "Field",
110
117
  className: "h-8 w-full justify-between text-[12px] font-normal",
111
118
  children: [
112
- /* @__PURE__ */ t("span", { className: "truncate", children: (b == null ? void 0 : b.label) ?? "Select a field…" }),
119
+ /* @__PURE__ */ t("span", { className: "truncate", children: (y == null ? void 0 : y.label) ?? "Select a field…" }),
113
120
  /* @__PURE__ */ t(R, { className: "ml-1 h-3 w-3 shrink-0 opacity-50" })
114
121
  ]
115
122
  }
116
123
  ) }),
117
- /* @__PURE__ */ t(P, { className: "w-[--radix-popover-trigger-width] p-0", align: "start", children: /* @__PURE__ */ n(A, { children: [
118
- /* @__PURE__ */ t(H, { placeholder: "Search fields…", className: "h-8 text-[12px]" }),
119
- /* @__PURE__ */ n(U, { children: [
120
- /* @__PURE__ */ t(G, { className: "py-3 text-center text-[12px] text-muted-foreground", children: "No field matches" }),
124
+ /* @__PURE__ */ t(P, { className: "w-[--radix-popover-trigger-width] p-0", align: "start", children: /* @__PURE__ */ n(z, { children: [
125
+ /* @__PURE__ */ t(G, { placeholder: "Search fields…", className: "h-8 text-[12px]" }),
126
+ /* @__PURE__ */ n(H, { children: [
127
+ /* @__PURE__ */ t(X, { className: "py-3 text-center text-[12px] text-muted-foreground", children: "No field matches" }),
121
128
  k.map((e) => /* @__PURE__ */ n(
122
- J,
129
+ Y,
123
130
  {
124
131
  value: `${e.label} ${e.field}`,
125
132
  onSelect: () => {
126
- N(e.field), o(!1);
133
+ i(e.field), d(!1);
127
134
  },
128
135
  className: "text-[12px]",
129
136
  children: [
130
137
  /* @__PURE__ */ t(
131
- B,
138
+ j,
132
139
  {
133
- className: z(
140
+ className: V(
134
141
  "mr-2 h-3.5 w-3.5",
135
- a === e.field ? "opacity-100" : "opacity-0"
142
+ u === e.field ? "opacity-100" : "opacity-0"
136
143
  )
137
144
  }
138
145
  ),
@@ -150,17 +157,17 @@ function de({
150
157
  /* @__PURE__ */ t(
151
158
  "label",
152
159
  {
153
- htmlFor: `${h}-value`,
160
+ htmlFor: `${x}-value`,
154
161
  className: "mb-1 block text-[11px] font-medium text-muted-foreground",
155
162
  children: "New value"
156
163
  }
157
164
  ),
158
165
  /* @__PURE__ */ t(
159
- S,
166
+ w,
160
167
  {
161
- id: `${h}-value`,
162
- value: g,
163
- onChange: (e) => v(e.target.value),
168
+ id: `${x}-value`,
169
+ value: b,
170
+ onChange: (e) => N(e.target.value),
164
171
  className: "h-8 text-[12px]"
165
172
  }
166
173
  )
@@ -169,31 +176,31 @@ function de({
169
176
  /* @__PURE__ */ t(
170
177
  "label",
171
178
  {
172
- htmlFor: `${h}-at`,
179
+ htmlFor: `${x}-at`,
173
180
  className: "mb-1 block text-[11px] font-medium text-muted-foreground",
174
181
  children: "When"
175
182
  }
176
183
  ),
177
184
  /* @__PURE__ */ t(
178
- S,
185
+ w,
179
186
  {
180
- id: `${h}-at`,
187
+ id: `${x}-at`,
181
188
  type: "datetime-local",
182
- value: p,
189
+ value: f,
183
190
  onChange: (e) => C(e.target.value),
184
191
  className: "h-8 text-[12px]"
185
192
  }
186
193
  )
187
194
  ] }),
188
195
  /* @__PURE__ */ t(
189
- w,
196
+ S,
190
197
  {
191
198
  type: "button",
192
199
  size: "sm",
193
200
  className: "h-8 w-full bg-nvr-cyan text-[12px] text-white hover:bg-nvr-cyan/90",
194
- disabled: !a || !g || !T || y.isPending,
195
- onClick: () => y.mutate(),
196
- children: y.isPending ? "Scheduling…" : "Schedule change"
201
+ disabled: !u || !b || !T || v.isPending,
202
+ onClick: () => v.mutate(),
203
+ children: v.isPending ? "Scheduling…" : "Schedule change"
197
204
  }
198
205
  )
199
206
  ] })
@@ -201,6 +208,7 @@ function de({
201
208
  ] });
202
209
  }
203
210
  export {
204
- ce as PickerExclusionToggle,
205
- de as ScheduleChangeButton
211
+ me as PickerExclusionToggle,
212
+ he as ScheduleChangeButton,
213
+ J as usePickerExclusion
206
214
  };