@nivaro/react 0.3.29 → 0.3.30

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,67 +1,68 @@
1
- import { jsx as c, jsxs as d } from "react/jsx-runtime";
2
- import { useQuery as m } from "@tanstack/react-query";
3
- import { useNivaroClient as u } from "../../context.js";
4
- import { get as f } from "../../lib/commands.js";
5
- import { useAfterIdle as h } from "../../lib/defer.js";
6
- import { formatRelative as l, formatDateTime as s } from "../../lib/utils.js";
7
- import { InboundRequestPopover as p } from "../integrations/InboundRequest.js";
8
- function x(r, t, n) {
9
- const i = u(), a = [...n].sort().join(","), e = h(1500);
10
- return m({
11
- queryKey: ["field-touch", r, t, a],
12
- queryFn: () => i.request(
13
- f("/revisions/field-touch", { collection: r, item: t, fields: a })
14
- ).then((o) => o.data ?? {}),
15
- enabled: e && !!t && t !== "new" && n.length > 0,
1
+ import { jsx as o } from "react/jsx-runtime";
2
+ import { useQuery as b } from "@tanstack/react-query";
3
+ import { Info as f } from "lucide-react";
4
+ import { useNivaroClient as v } from "../../context.js";
5
+ import { get as x } from "../../lib/commands.js";
6
+ import { useAfterIdle as $ } from "../../lib/defer.js";
7
+ import { cn as p, formatDateTime as d, formatRelative as h } from "../../lib/utils.js";
8
+ import { InboundRequestPopover as g } from "../integrations/InboundRequest.js";
9
+ function k(a, t, i) {
10
+ const s = v(), n = [...i].sort().join(","), r = $(1500);
11
+ return b({
12
+ queryKey: ["field-touch", a, t, n],
13
+ queryFn: () => s.request(
14
+ x("/revisions/field-touch", { collection: a, item: t, fields: n })
15
+ ).then((e) => e.data ?? {}),
16
+ enabled: r && !!t && t !== "new" && i.length > 0,
16
17
  staleTime: 6e4
17
18
  });
18
19
  }
19
- function $({
20
- collection: r,
20
+ function _({
21
+ collection: a,
21
22
  itemId: t,
22
- field: n,
23
- fields: i
23
+ field: i,
24
+ fields: s,
25
+ className: n
24
26
  }) {
25
- const { data: a } = x(r, t, i), e = a == null ? void 0 : a[n];
27
+ const { data: r } = k(a, t, s), e = r == null ? void 0 : r[i];
26
28
  if (!e) return null;
27
- const o = e.via !== "user";
28
- return e.caller && e.activity_id ? /* @__PURE__ */ c(
29
- p,
30
- {
31
- activityId: e.activity_id,
32
- callerName: e.caller.name,
33
- collection: r,
34
- itemId: t,
35
- children: /* @__PURE__ */ d(
36
- "button",
37
- {
38
- type: "button",
39
- "data-copy-skip": !0,
40
- "data-field-touch-caller": e.caller.key,
41
- className: "mt-0.5 block max-w-full truncate text-left text-[10px] leading-none text-amber-700/80 underline decoration-dotted underline-offset-2 hover:text-amber-800 dark:text-amber-300/80 dark:hover:text-amber-200 [[data-header-dense]_&]:hidden",
42
- "data-tip": `${e.caller.name} · ${s(e.at)} — click for the request`,
43
- children: [
44
- e.caller.name,
45
- " · ",
46
- l(e.at)
47
- ]
48
- }
49
- )
50
- }
51
- ) : /* @__PURE__ */ d(
52
- "span",
53
- {
54
- "data-copy-skip": !0,
55
- className: o ? "mt-0.5 block truncate text-[10px] leading-none text-amber-700/80 dark:text-amber-300/80 [[data-header-dense]_&]:hidden" : "mt-0.5 block truncate text-[10px] leading-none text-slate-400 dark:text-slate-500 [[data-header-dense]_&]:hidden",
56
- "data-tip": `${e.who} · ${s(e.at)}`,
57
- children: [
58
- l(e.at),
59
- o ? ` · ${e.via === "import" ? e.who : e.via}` : ""
60
- ]
61
- }
29
+ const c = e.via !== "user", l = p(
30
+ "h-3 w-3",
31
+ c ? "text-amber-600/80 dark:text-amber-300/80" : "text-slate-400 dark:text-slate-500"
32
+ ), u = p(
33
+ "flex h-3 w-3 items-center justify-center rounded-sm opacity-70 hover:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan",
34
+ n
35
+ );
36
+ if (e.caller && e.activity_id)
37
+ return /* @__PURE__ */ o(
38
+ g,
39
+ {
40
+ activityId: e.activity_id,
41
+ callerName: e.caller.name,
42
+ collection: a,
43
+ itemId: t,
44
+ children: /* @__PURE__ */ o(
45
+ "button",
46
+ {
47
+ type: "button",
48
+ "data-copy-skip": !0,
49
+ "data-field-touch-caller": e.caller.key,
50
+ "aria-label": `Changed by ${e.caller.name} ${h(e.at)} — open the request`,
51
+ className: u,
52
+ "data-tip": `${e.caller.name} · ${d(e.at)} — click for the request`,
53
+ onClick: (y) => y.stopPropagation(),
54
+ children: /* @__PURE__ */ o(f, { className: l })
55
+ }
56
+ )
57
+ }
58
+ );
59
+ const m = `Changed by ${c && e.via !== "import" ? `${e.who} (${e.via})` : e.who} · ${d(e.at)} (${h(e.at)})`;
60
+ return (
61
+ // biome-ignore lint/a11y/noNoninteractiveTabindex: focusable so keyboard users get the tip
62
+ /* @__PURE__ */ o("span", { "data-copy-skip": !0, tabIndex: 0, role: "img", "aria-label": m, "data-tip": m, className: u, children: /* @__PURE__ */ o(f, { className: l }) })
62
63
  );
63
64
  }
64
65
  export {
65
- $ as HeaderFreshness,
66
- x as useFieldTouches
66
+ _ as HeaderFreshness,
67
+ k as useFieldTouches
67
68
  };
@@ -1,11 +1,11 @@
1
1
  import { jsxs as p, jsx as e } from "react/jsx-runtime";
2
- import { X as O } from "lucide-react";
3
- import { useState as x, useEffect as w } from "react";
2
+ import { X as x } from "lucide-react";
3
+ import { useState as O, useEffect as w } from "react";
4
4
  import { cn as v } from "../../../lib/utils.js";
5
- import { effectText as f, inputBase as L, tintCard as T } from "../panel-style.js";
6
- import { useInspectorEnv as A, Setting as c, TextInput as N, Choice as _, Segmented as k, AddButton as E, Section as J, JsonInput as R } from "./kit.js";
7
- import { bindingValue as h, withStaticBinding as H } from "./model.js";
8
- const P = [
5
+ import { effectText as _, inputBase as L, tintCard as T } from "../panel-style.js";
6
+ import { useInspectorEnv as A, Setting as c, TextInput as N, Choice as b, Segmented as k, AddButton as R, Section as E, JsonInput as J } from "./kit.js";
7
+ import { bindingValue as h, withStaticBinding as $ } from "./model.js";
8
+ const H = [
9
9
  { value: "text", label: "Text" },
10
10
  { value: "currency", label: "Currency ($)" },
11
11
  { value: "integer", label: "Whole number" },
@@ -21,7 +21,7 @@ const P = [
21
21
  { value: "amber", label: "Amber" },
22
22
  { value: "red", label: "Red" },
23
23
  { value: "purple", label: "Purple" }
24
- ], $ = [
24
+ ], P = [
25
25
  { value: "", label: "Normal" },
26
26
  { value: "medium", label: "Medium" },
27
27
  { value: "semibold", label: "Semibold" },
@@ -34,8 +34,8 @@ const P = [
34
34
  function I(t) {
35
35
  if (!Array.isArray(t)) return 'Needs a list like [{ "op": "gt", "value": 0, "color": "red" }]';
36
36
  for (const l of t) {
37
- const o = l;
38
- if (!o || !S.has(o.op ?? "") || o.value == null || !o.color)
37
+ const r = l;
38
+ if (!r || !S.has(r.op ?? "") || r.value == null || !r.color)
39
39
  return "Each needs op (lt, lte, gt, gte, eq), value and color";
40
40
  }
41
41
  return null;
@@ -47,11 +47,11 @@ const d = (t) => typeof t == "string" ? t : "", B = [
47
47
  { value: "gte", label: "is at least" },
48
48
  { value: "eq", label: "equals" }
49
49
  ], g = (t) => Array.isArray(t) ? t.map((l) => {
50
- const o = l ?? {};
50
+ const r = l ?? {};
51
51
  return {
52
- op: o.op ?? "gt",
53
- value: o.value == null ? "" : String(o.value),
54
- color: o.color ?? ""
52
+ op: r.op ?? "gt",
53
+ value: r.value == null ? "" : String(r.value),
54
+ color: r.color ?? ""
55
55
  };
56
56
  }) : [], y = (t) => t.filter((l) => S.has(l.op) && l.value.trim() !== "" && l.color).map((l) => ({
57
57
  op: l.op,
@@ -62,28 +62,28 @@ function q({
62
62
  value: t,
63
63
  onChange: l
64
64
  }) {
65
- const o = JSON.stringify(y(g(t))), [u, s] = x(() => g(t));
65
+ const r = JSON.stringify(y(g(t))), [u, s] = O(() => g(t));
66
66
  w(() => {
67
67
  s(
68
- (r) => JSON.stringify(y(r)) === o ? r : g(JSON.parse(o))
68
+ (o) => JSON.stringify(y(o)) === r ? o : g(JSON.parse(r))
69
69
  );
70
- }, [o]);
71
- const m = (r) => {
72
- s(r);
73
- const n = y(r);
74
- JSON.stringify(n) !== o && l(n.length ? n : null);
75
- }, a = (r, n) => m(u.map((i, b) => b === r ? { ...i, ...n } : i));
70
+ }, [r]);
71
+ const m = (o) => {
72
+ s(o);
73
+ const n = y(o);
74
+ JSON.stringify(n) !== r && l(n.length ? n : null);
75
+ }, a = (o, n) => m(u.map((i, f) => f === o ? { ...i, ...n } : i));
76
76
  return /* @__PURE__ */ p("div", { className: "space-y-2", children: [
77
- u.length === 0 ? /* @__PURE__ */ e("p", { className: f, children: "No rules: the value keeps the colour above." }) : /* @__PURE__ */ e("ul", { className: "space-y-2", children: u.map((r, n) => (
77
+ u.length === 0 ? /* @__PURE__ */ e("p", { className: _, children: "No rules: the value keeps the colour above." }) : /* @__PURE__ */ e("ul", { className: "space-y-2", children: u.map((o, n) => (
78
78
  // biome-ignore lint/suspicious/noArrayIndexKey: rules are positional
79
79
  /* @__PURE__ */ p("li", { className: v(T, "space-y-1.5 p-2.5"), "data-threshold-row": "", children: [
80
80
  /* @__PURE__ */ p("div", { className: "flex items-center gap-1.5", children: [
81
- /* @__PURE__ */ e("span", { className: v(f, "shrink-0"), children: "When it" }),
81
+ /* @__PURE__ */ e("span", { className: v(_, "shrink-0"), children: "When it" }),
82
82
  /* @__PURE__ */ e("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ e(
83
- _,
83
+ b,
84
84
  {
85
85
  ariaLabel: "Comparison",
86
- value: r.op,
86
+ value: o.op,
87
87
  options: B,
88
88
  onChange: (i) => a(n, { op: i })
89
89
  }
@@ -94,9 +94,9 @@ function q({
94
94
  type: "button",
95
95
  "aria-label": "Remove rule",
96
96
  "data-tip": "Remove rule",
97
- onClick: () => m(u.filter((i, b) => b !== n)),
97
+ onClick: () => m(u.filter((i, f) => f !== n)),
98
98
  className: "inline-flex h-7 w-7 shrink-0 items-center justify-center rounded text-slate-500 transition-colors hover:bg-slate-100 hover:text-red-600 dark:hover:bg-muted dark:hover:text-red-400",
99
- children: /* @__PURE__ */ e(O, { className: "h-3.5 w-3.5" })
99
+ children: /* @__PURE__ */ e(x, { className: "h-3.5 w-3.5" })
100
100
  }
101
101
  )
102
102
  ] }),
@@ -105,18 +105,18 @@ function q({
105
105
  "input",
106
106
  {
107
107
  "aria-label": "Value",
108
- value: r.value,
108
+ value: o.value,
109
109
  placeholder: "0",
110
110
  onChange: (i) => a(n, { value: i.target.value }),
111
111
  className: v(L, "w-24 shrink-0")
112
112
  }
113
113
  ),
114
- /* @__PURE__ */ e("span", { className: v(f, "shrink-0"), children: "show it" }),
114
+ /* @__PURE__ */ e("span", { className: v(_, "shrink-0"), children: "show it" }),
115
115
  /* @__PURE__ */ e("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ e(
116
- _,
116
+ b,
117
117
  {
118
118
  ariaLabel: "Colour",
119
- value: r.color,
119
+ value: o.color,
120
120
  options: [{ value: "", label: "Pick a colour…" }, ...C.slice(1)],
121
121
  onChange: (i) => a(n, { color: i })
122
122
  }
@@ -124,27 +124,27 @@ function q({
124
124
  ] })
125
125
  ] }, n)
126
126
  )) }),
127
- /* @__PURE__ */ e(E, { onClick: () => s([...u, { op: "gt", value: "", color: "" }]), children: "+ Add a colour rule" }),
128
- /* @__PURE__ */ e(J, { title: "Edit as JSON", collapsible: !0, className: "border-t-0 pt-1", children: /* @__PURE__ */ e(
129
- R,
127
+ /* @__PURE__ */ e(R, { onClick: () => s([...u, { op: "gt", value: "", color: "" }]), children: "+ Add a colour rule" }),
128
+ /* @__PURE__ */ e(E, { title: "Edit as JSON", collapsible: !0, className: "border-t-0 pt-1", children: /* @__PURE__ */ e(
129
+ J,
130
130
  {
131
131
  ariaLabel: "Colour by value as JSON",
132
132
  rows: 3,
133
- value: o === "[]" ? null : JSON.parse(o),
133
+ value: r === "[]" ? null : JSON.parse(r),
134
134
  placeholder: '[{ "op": "gt", "value": 0, "color": "red" }]',
135
135
  validate: I,
136
- onCommit: (r) => l(Array.isArray(r) && r.length ? r : null)
136
+ onCommit: (o) => l(Array.isArray(o) && o.length ? o : null)
137
137
  }
138
138
  ) })
139
139
  ] });
140
140
  }
141
141
  function Y({ row: t, label: l }) {
142
- const o = A(), u = { field: t.field, group_key: t.group_key }, s = (a, r, n, i) => o.apply(
142
+ const r = A(), u = { field: t.field, group_key: t.group_key }, s = (a, o, n, i) => r.apply(
143
143
  [
144
144
  {
145
145
  op: "update_placement",
146
146
  at: u,
147
- patch: { input_bindings: H(t, a, r) }
147
+ patch: { input_bindings: $(t, a, o) }
148
148
  }
149
149
  ],
150
150
  { label: n, text: i }
@@ -164,7 +164,7 @@ function Y({ row: t, label: l }) {
164
164
  ariaLabel: "Label",
165
165
  value: t.label_override ?? "",
166
166
  placeholder: l,
167
- onChange: (a) => o.apply([{ op: "update_placement", at: u, patch: { label_override: a || null } }], {
167
+ onChange: (a) => r.apply([{ op: "update_placement", at: u, patch: { label_override: a || null } }], {
168
168
  label: `Rename ${l} in the header`,
169
169
  text: !0
170
170
  })
@@ -177,18 +177,18 @@ function Y({ row: t, label: l }) {
177
177
  label: "Format",
178
178
  effect: "How the value is written in the header.",
179
179
  children: /* @__PURE__ */ e(
180
- _,
180
+ b,
181
181
  {
182
182
  ariaLabel: "Format",
183
183
  value: d(h(t, "__display_format__")) || "text",
184
- options: P,
184
+ options: H,
185
185
  onChange: (a) => s("__display_format__", a === "text" ? null : a, `Change the format of ${l}`)
186
186
  }
187
187
  )
188
188
  }
189
189
  ),
190
190
  /* @__PURE__ */ e(c, { k: "header.color", label: "Colour", effect: "The colour of the value in the header.", children: /* @__PURE__ */ e(
191
- _,
191
+ b,
192
192
  {
193
193
  ariaLabel: "Colour",
194
194
  value: d(h(t, "__color__")),
@@ -200,7 +200,7 @@ function Y({ row: t, label: l }) {
200
200
  k,
201
201
  {
202
202
  value: d(h(t, "__weight__")),
203
- options: $,
203
+ options: P,
204
204
  onChange: (a) => s("__weight__", a || null, `Change the weight of ${l}`)
205
205
  }
206
206
  ) }),
@@ -256,13 +256,23 @@ function Y({ row: t, label: l }) {
256
256
  }
257
257
  )
258
258
  }
259
- )
259
+ ),
260
+ /* @__PURE__ */ e("div", { className: "border-t border-slate-200 pt-3 dark:border-border", children: /* @__PURE__ */ e(
261
+ "button",
262
+ {
263
+ type: "button",
264
+ "data-header-remove": !0,
265
+ onClick: () => r.apply([{ op: "remove", at: u }], { label: `Remove ${l} from the header` }),
266
+ className: "text-[12px] text-red-600 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan dark:text-red-400",
267
+ children: "Remove from header"
268
+ }
269
+ ) })
260
270
  ] });
261
271
  }
262
272
  export {
263
273
  C as COLORS,
264
274
  D as DISPLAY_AS,
265
- P as HEADER_FORMATS,
275
+ H as HEADER_FORMATS,
266
276
  Y as HeaderItemInspector,
267
- $ as WEIGHTS
277
+ P as WEIGHTS
268
278
  };