@nivaro/react 0.3.39 → 0.3.41

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