@nivaro/react 0.3.140 → 0.3.141

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,40 +1,41 @@
1
- import { jsx as t, jsxs as c, Fragment as x } from "react/jsx-runtime";
2
- import { useQuery as y } from "@tanstack/react-query";
3
- import { ChevronRight as v, ArrowRight as N } from "lucide-react";
4
- import { useState as g, useId as b } from "react";
5
- import { useNivaroClient as k } from "../../context.js";
6
- import { get as w } from "../../lib/commands.js";
7
- import { compareValueText as C } from "../../lib/compare-value.js";
8
- import { formatDateTime as R, cn as m } from "../../lib/utils.js";
9
- import { ErrorNotice as _ } from "../ErrorNotice.js";
10
- import { RelativeTime as S } from "../RelativeTime.js";
11
- import { UserAvatar as T } from "../UserAvatar.js";
12
- import { Skeleton as p } from "../ui/skeleton.js";
13
- function f(e, a, r) {
1
+ import { jsxs as o, jsx as t, Fragment as b } from "react/jsx-runtime";
2
+ import { useQuery as N } from "@tanstack/react-query";
3
+ import { ChevronRight as g, ArrowRight as k } from "lucide-react";
4
+ import { useState as w, useId as R } from "react";
5
+ import { useNivaroClient as C } from "../../context.js";
6
+ import { get as T } from "../../lib/commands.js";
7
+ import { compareValueText as _ } from "../../lib/compare-value.js";
8
+ import { useRelativeText as S } from "../../lib/relative-ticker.js";
9
+ import { formatDateTime as p, cn as h } from "../../lib/utils.js";
10
+ import { ErrorNotice as $ } from "../ErrorNotice.js";
11
+ import { RelativeTime as j } from "../RelativeTime.js";
12
+ import { UserAvatar as A } from "../UserAvatar.js";
13
+ import { Skeleton as u } from "../ui/skeleton.js";
14
+ function x(e, a, r) {
14
15
  if (a !== void 0) return a;
15
16
  if (e == null || e === "" || Array.isArray(e) && e.length === 0) return null;
16
- const i = r ? {
17
+ const l = r ? {
17
18
  type: r.type,
18
19
  interface: r.interface,
19
20
  options: r.options,
20
21
  display_options: r.options
21
- } : void 0, n = C(e, i);
22
+ } : void 0, n = _(e, l);
22
23
  return n === "—" ? null : n;
23
24
  }
24
- function $(e, a) {
25
+ function q(e, a) {
25
26
  var n;
26
- const r = [], i = [];
27
- for (const s of e) ((n = a[s.field]) != null && n.system ? i : r).push(s);
28
- return { main: r, system: i };
27
+ const r = [], l = [];
28
+ for (const i of e) ((n = a[i.field]) != null && n.system ? l : r).push(i);
29
+ return { main: r, system: l };
29
30
  }
30
- function j(e) {
31
+ function I(e) {
31
32
  return e.split(/\s+/).map((a) => a[0]).filter(Boolean).slice(0, 2).join("").toUpperCase() || "·";
32
33
  }
33
- function h({ text: e, strong: a }) {
34
+ function y({ text: e, strong: a }) {
34
35
  return e == null ? /* @__PURE__ */ t("span", { className: "italic text-slate-400 dark:text-slate-500", children: "Empty" }) : /* @__PURE__ */ t(
35
36
  "span",
36
37
  {
37
- className: m(
38
+ className: h(
38
39
  "break-words [overflow-wrap:anywhere]",
39
40
  a ? "font-medium text-slate-900 dark:text-slate-100" : "text-slate-500 dark:text-slate-400"
40
41
  ),
@@ -42,19 +43,19 @@ function h({ text: e, strong: a }) {
42
43
  }
43
44
  );
44
45
  }
45
- function u({
46
+ function v({
46
47
  change: e,
47
48
  meta: a,
48
49
  muted: r
49
50
  }) {
50
- const i = (a == null ? void 0 : a.label) ?? e.field, n = f(e.before, e.before_text, a), s = f(e.after, e.after_text, a);
51
- return /* @__PURE__ */ c("li", { className: m("relative py-1.5", r && "opacity-75"), "data-recap-change": e.field, children: [
52
- /* @__PURE__ */ t("div", { className: "text-[11.5px] font-medium text-slate-500 dark:text-slate-400", children: i }),
53
- /* @__PURE__ */ c("div", { className: "mt-0.5 flex flex-wrap items-baseline gap-x-1.5 gap-y-0.5 text-[12.5px] leading-snug", children: [
54
- e.has_before ? /* @__PURE__ */ c(x, { children: [
55
- /* @__PURE__ */ t(h, { text: n }),
51
+ const l = (a == null ? void 0 : a.label) ?? e.field, n = x(e.before, e.before_text, a), i = x(e.after, e.after_text, a);
52
+ return /* @__PURE__ */ o("li", { className: h("relative py-1.5", r && "opacity-75"), "data-recap-change": e.field, children: [
53
+ /* @__PURE__ */ t("div", { className: "text-[11.5px] font-medium text-slate-500 dark:text-slate-400", children: l }),
54
+ /* @__PURE__ */ o("div", { className: "mt-0.5 flex flex-wrap items-baseline gap-x-1.5 gap-y-0.5 text-[12.5px] leading-snug", children: [
55
+ e.has_before ? /* @__PURE__ */ o(b, { children: [
56
+ /* @__PURE__ */ t(y, { text: n }),
56
57
  /* @__PURE__ */ t(
57
- N,
58
+ k,
58
59
  {
59
60
  "aria-hidden": !0,
60
61
  className: "h-3 w-3 shrink-0 self-center text-slate-400 dark:text-slate-500"
@@ -62,51 +63,51 @@ function u({
62
63
  ),
63
64
  /* @__PURE__ */ t("span", { className: "sr-only", children: "changed to" })
64
65
  ] }) : /* @__PURE__ */ t("span", { className: "sr-only", children: "now" }),
65
- /* @__PURE__ */ t(h, { text: s, strong: !r })
66
+ /* @__PURE__ */ t(y, { text: i, strong: !r })
66
67
  ] })
67
68
  ] });
68
69
  }
69
- function q({ group: e, fields: a }) {
70
- const [r, i] = g(!1), n = b(), { main: s, system: o } = $(e.changes, a), l = e.last_at;
71
- return /* @__PURE__ */ c("section", { className: "py-2.5 first:pt-1", "aria-label": `Changed by ${e.name}`, children: [
72
- /* @__PURE__ */ c("header", { className: "flex items-center gap-2", children: [
70
+ function E({ group: e, fields: a }) {
71
+ const [r, l] = w(!1), n = R(), { main: i, system: d } = q(e.changes, a), c = e.last_at;
72
+ return /* @__PURE__ */ o("section", { className: "py-2.5 first:pt-1", "aria-label": `Changed by ${e.name}`, children: [
73
+ /* @__PURE__ */ o("header", { className: "flex items-center gap-2", children: [
73
74
  /* @__PURE__ */ t(
74
- T,
75
+ A,
75
76
  {
76
77
  userId: e.user_id,
77
78
  className: "h-5 w-5 rounded-full",
78
- fallback: /* @__PURE__ */ t("span", { className: "flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-nvr-cyan/10 text-[9px] font-semibold text-nvr-navy dark:text-nvr-cyan", children: j(e.name) })
79
+ fallback: /* @__PURE__ */ t("span", { className: "flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-nvr-cyan/10 text-[9px] font-semibold text-nvr-navy dark:text-nvr-cyan", children: I(e.name) })
79
80
  }
80
81
  ),
81
82
  /* @__PURE__ */ t("span", { className: "min-w-0 truncate text-[12.5px] font-semibold text-slate-800 dark:text-slate-100", children: e.name }),
82
- l && /* @__PURE__ */ t("span", { className: "ml-auto shrink-0 text-[11.5px] text-slate-400 dark:text-slate-500", children: /* @__PURE__ */ t(S, { value: l, title: R(l) }) })
83
+ c && /* @__PURE__ */ t("span", { className: "ml-auto shrink-0 text-[11.5px] text-slate-400 dark:text-slate-500", children: /* @__PURE__ */ t(j, { value: c, title: p(c) }) })
83
84
  ] }),
84
- s.length > 0 && /* @__PURE__ */ t("ul", { className: "mt-1 divide-y divide-slate-100 pl-7 dark:divide-border/60", children: s.map((d) => /* @__PURE__ */ t(u, { change: d, meta: a[d.field] }, d.field)) }),
85
- o.length > 0 && /* @__PURE__ */ c("div", { className: "pl-7", children: [
86
- /* @__PURE__ */ c(
85
+ i.length > 0 && /* @__PURE__ */ t("ul", { className: "mt-1 divide-y divide-slate-100 pl-7 dark:divide-border/60", children: i.map((s) => /* @__PURE__ */ t(v, { change: s, meta: a[s.field] }, s.field)) }),
86
+ d.length > 0 && /* @__PURE__ */ o("div", { className: "pl-7", children: [
87
+ /* @__PURE__ */ o(
87
88
  "button",
88
89
  {
89
90
  type: "button",
90
91
  "aria-expanded": r,
91
92
  "aria-controls": n,
92
- onClick: () => i((d) => !d),
93
+ onClick: () => l((s) => !s),
93
94
  className: "mt-1 inline-flex items-center gap-1 rounded text-[11.5px] text-slate-400 hover:text-slate-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/50 dark:text-slate-500 dark:hover:text-slate-300",
94
95
  "data-recap-system-toggle": !0,
95
96
  children: [
96
97
  /* @__PURE__ */ t(
97
- v,
98
+ g,
98
99
  {
99
100
  "aria-hidden": !0,
100
- className: m(
101
+ className: h(
101
102
  "h-3 w-3 transition-transform duration-150 motion-reduce:transition-none",
102
103
  r && "rotate-90"
103
104
  )
104
105
  }
105
106
  ),
106
- s.length > 0 ? "and " : "",
107
- o.length,
107
+ i.length > 0 ? "and " : "",
108
+ d.length,
108
109
  " system field",
109
- o.length === 1 ? "" : "s"
110
+ d.length === 1 ? "" : "s"
110
111
  ]
111
112
  }
112
113
  ),
@@ -116,51 +117,92 @@ function q({ group: e, fields: a }) {
116
117
  id: n,
117
118
  hidden: !r,
118
119
  className: "divide-y divide-slate-100 dark:divide-border/60",
119
- children: o.map((d) => /* @__PURE__ */ t(u, { change: d, meta: a[d.field], muted: !0 }, d.field))
120
+ children: d.map((s) => /* @__PURE__ */ t(v, { change: s, meta: a[s.field], muted: !0 }, s.field))
120
121
  }
121
122
  )
122
123
  ] })
123
124
  ] });
124
125
  }
125
- function z({
126
+ function U({
126
127
  collection: e,
127
128
  itemId: a,
128
129
  since: r,
129
- everyone: i
130
+ everyone: l,
131
+ emptyText: n
130
132
  }) {
131
- const n = k(), s = y({
132
- queryKey: ["record-recap-changes", e, a, r, !!i],
133
- queryFn: () => n.request(
134
- w(`/record-views/${e}/${encodeURIComponent(a)}/changes`, {
133
+ const i = C(), d = N({
134
+ queryKey: ["record-recap-changes", e, a, r, !!l],
135
+ queryFn: () => i.request(
136
+ T(`/record-views/${e}/${encodeURIComponent(a)}/changes`, {
135
137
  since: r,
136
- ...i ? { everyone: "1" } : {}
138
+ ...l ? { everyone: "1" } : {}
137
139
  })
138
- ).then((l) => l.data),
140
+ ).then((s) => s.data),
139
141
  staleTime: 3e4,
140
142
  retry: !1
141
143
  });
142
- if (s.isLoading)
143
- return /* @__PURE__ */ t("div", { className: "space-y-3 py-2", "aria-busy": "true", children: [0, 1, 2].map((l) => /* @__PURE__ */ c("div", { className: "space-y-1.5", children: [
144
- /* @__PURE__ */ t(p, { className: "h-3 w-24" }),
145
- /* @__PURE__ */ t(p, { className: "h-4 w-56 max-w-full" })
146
- ] }, l)) });
147
- if (s.isError)
148
- return /* @__PURE__ */ t("div", { className: "py-2", children: /* @__PURE__ */ t(_, { error: s.error, what: "the changes", onRetry: () => void s.refetch() }) });
149
- const o = s.data;
150
- return !o || o.groups.length === 0 ? /* @__PURE__ */ t("p", { className: "py-3 text-[12.5px] text-slate-500 dark:text-slate-400", children: "No field changes to show — the values are back to what you last saw." }) : /* @__PURE__ */ c("div", { "data-recap-changes": !0, children: [
151
- /* @__PURE__ */ t("div", { className: "divide-y divide-slate-200/70 dark:divide-border", children: o.groups.map((l) => /* @__PURE__ */ t(
152
- q,
144
+ if (d.isLoading)
145
+ return /* @__PURE__ */ t("div", { className: "space-y-3 py-2", "aria-busy": "true", children: [0, 1, 2].map((s) => /* @__PURE__ */ o("div", { className: "space-y-1.5", children: [
146
+ /* @__PURE__ */ t(u, { className: "h-3 w-24" }),
147
+ /* @__PURE__ */ t(u, { className: "h-4 w-56 max-w-full" })
148
+ ] }, s)) });
149
+ if (d.isError)
150
+ return /* @__PURE__ */ t("div", { className: "py-2", children: /* @__PURE__ */ t($, { error: d.error, what: "the changes", onRetry: () => void d.refetch() }) });
151
+ const c = d.data;
152
+ return !c || c.groups.length === 0 ? /* @__PURE__ */ t("p", { className: "py-3 text-[12.5px] text-slate-500 dark:text-slate-400", children: n ?? "No field changes to show — the values are back to what you last saw." }) : /* @__PURE__ */ o("div", { "data-recap-changes": !0, children: [
153
+ /* @__PURE__ */ t("div", { className: "divide-y divide-slate-200/70 dark:divide-border", children: c.groups.map((s) => /* @__PURE__ */ t(
154
+ E,
153
155
  {
154
- group: l,
155
- fields: o.fields
156
+ group: s,
157
+ fields: c.fields
156
158
  },
157
- `${l.user_id ?? "system"}|${l.first_at}`
159
+ `${s.user_id ?? "system"}|${s.first_at}`
158
160
  )) }),
159
- o.truncated && /* @__PURE__ */ t("p", { className: "pt-2 text-[11.5px] text-slate-400 dark:text-slate-500", children: "Showing the first 300 saves — the full history has the rest." })
161
+ c.truncated && /* @__PURE__ */ t("p", { className: "pt-2 text-[11.5px] text-slate-400 dark:text-slate-500", children: "Showing the first 300 saves — the full history has the rest." })
162
+ ] });
163
+ }
164
+ function O({
165
+ collection: e,
166
+ itemId: a,
167
+ since: r,
168
+ everyone: l,
169
+ title: n,
170
+ extras: i,
171
+ emptyText: d,
172
+ footer: c,
173
+ bodyRef: s,
174
+ sinceLabel: f
175
+ }) {
176
+ const m = S(r);
177
+ return /* @__PURE__ */ o("div", { ref: s, tabIndex: -1, className: "outline-none", children: [
178
+ /* @__PURE__ */ o("div", { className: "border-b border-slate-200/80 px-4 pb-2 pt-3 dark:border-border", children: [
179
+ /* @__PURE__ */ t("p", { className: "text-[13px] font-semibold text-slate-900 dark:text-slate-100", children: n }),
180
+ /* @__PURE__ */ o("p", { className: "mt-0.5 text-[11.5px] text-slate-500 dark:text-slate-400", children: [
181
+ f ? `${f} ` : "",
182
+ /* @__PURE__ */ t("time", { dateTime: r, children: p(r) }),
183
+ m && m !== p(r) ? ` · ${m}` : null
184
+ ] })
185
+ ] }),
186
+ /* @__PURE__ */ t("div", { className: "max-h-[min(60vh,420px)] overflow-y-auto overscroll-contain px-4 py-1", children: /* @__PURE__ */ t(
187
+ U,
188
+ {
189
+ collection: e,
190
+ itemId: a,
191
+ since: r,
192
+ everyone: l,
193
+ emptyText: d
194
+ }
195
+ ) }),
196
+ i && /* @__PURE__ */ o("p", { className: "border-t border-slate-200/80 px-4 py-2 text-[11.5px] text-slate-500 dark:border-border dark:text-slate-400", children: [
197
+ "Also ",
198
+ i
199
+ ] }),
200
+ c && /* @__PURE__ */ t("div", { className: "flex items-center justify-between gap-2 border-t border-slate-200/80 px-4 py-2 dark:border-border", children: c })
160
201
  ] });
161
202
  }
162
203
  export {
163
- z as RecordRecapChangesList,
164
- f as recapValueText,
165
- $ as splitSystem
204
+ O as RecapChangesPanel,
205
+ U as RecordRecapChangesList,
206
+ x as recapValueText,
207
+ q as splitSystem
166
208
  };