@nivaro/react 0.3.125 → 0.3.126

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,5 +1,5 @@
1
- const $ = "$step", V = "Pipeline step";
2
- const D = (e) => e.id != null && (e.action === "create" || e.action === "update" || e.action === "delete" || e.action === "restore"), f = (e) => e.timestamp ? new Date(e.timestamp).getTime() : 0, x = (e, o) => {
1
+ const j = "$step", B = "Pipeline step";
2
+ const M = (e) => e.id != null && (e.action === "create" || e.action === "update" || e.action === "delete" || e.action === "restore"), f = (e) => e.timestamp ? new Date(e.timestamp).getTime() : 0, V = (e, o) => {
3
3
  const a = (t) => t == null || t === "" ? "" : typeof t == "object" ? JSON.stringify(t) : String(t);
4
4
  return a(e) === a(o);
5
5
  };
@@ -7,40 +7,40 @@ function F(e) {
7
7
  return [e.first_name, e.last_name].filter(Boolean).join(" ").trim() || e.user_email || (e.user_id ? "Someone" : "System");
8
8
  }
9
9
  function K(e, o = {}) {
10
- var v, M;
11
- const a = o.name ?? F, t = [...e].sort((n, i) => f(i) - f(n)), s = t.filter(D), c = t.filter((n) => /^o2m-/.test(String(n.action ?? "")) && n.o2m), l = t.filter((n) => n.event && !n.event.addendum && n.event.to_label).sort((n, i) => f(n) - f(i)), r = (n) => {
12
- var d;
13
- let i = null;
14
- for (const h of l) {
15
- if (f(h) > n) break;
16
- i = ((d = h.event) == null ? void 0 : d.to_label) ?? i;
10
+ var p, k;
11
+ const a = o.name ?? F, t = [...e].sort((n, u) => f(u) - f(n)), s = t.filter(M), l = t.filter((n) => /^o2m-/.test(String(n.action ?? "")) && n.o2m), i = t.filter((n) => n.event && !n.event.addendum && n.event.to_label).sort((n, u) => f(n) - f(u)), c = (n) => {
12
+ var m;
13
+ let u = null;
14
+ for (const b of i) {
15
+ if (f(b) > n) break;
16
+ u = ((m = b.event) == null ? void 0 : m.to_label) ?? u;
17
17
  }
18
- return i;
19
- }, u = s.map((n, i) => {
20
- const d = s[i + 1], h = n.data ?? {}, w = n.action === "create" ? "created" : n.action === "delete" ? "deleted" : n.action === "restore" ? "restored" : "changed", k = /* @__PURE__ */ new Set(), I = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Map();
21
- if (d && w !== "created") {
22
- const T = d.data ?? {}, R = new Set(Object.keys(n.delta ?? {}));
23
- for (const p of /* @__PURE__ */ new Set([...Object.keys(T), ...Object.keys(h)])) {
24
- if (p === "id" || x(T[p], h[p]) || !(p in T) && !R.has(p)) continue;
25
- if (R.has(p)) {
26
- k.add(p);
18
+ return u;
19
+ }, r = s.map((n, u) => {
20
+ const m = s[u + 1], b = n.data ?? {}, y = n.action === "create" ? "created" : n.action === "delete" ? "deleted" : n.action === "restore" ? "restored" : "changed", A = /* @__PURE__ */ new Set(), I = /* @__PURE__ */ new Set(), h = /* @__PURE__ */ new Map();
21
+ if (m && y !== "created") {
22
+ const T = m.data ?? {}, R = new Set(Object.keys(n.delta ?? {}));
23
+ for (const w of /* @__PURE__ */ new Set([...Object.keys(T), ...Object.keys(b)])) {
24
+ if (w === "id" || V(T[w], b[w]) || !(w in T) && !R.has(w)) continue;
25
+ if (R.has(w)) {
26
+ A.add(w);
27
27
  continue;
28
28
  }
29
- I.add(p);
30
- const G = f(d), P = f(n), N = c.filter((_) => {
31
- var A;
32
- const j = f(_);
33
- return j > G && j <= P && (((A = _.o2m) == null ? void 0 : A.totals) ?? []).some((O) => O.field === p);
34
- }).map((_) => {
35
- var j, A, O, W;
29
+ I.add(w);
30
+ const G = f(m), P = f(n), C = l.filter(($) => {
31
+ var O;
32
+ const v = f($);
33
+ return v > G && v <= P && (((O = $.o2m) == null ? void 0 : O.totals) ?? []).some((D) => D.field === w);
34
+ }).map(($) => {
35
+ var v, O, D, N;
36
36
  return {
37
- name: a(_),
38
- userId: _.user_id ?? null,
39
- row: ((j = _.o2m) == null ? void 0 : j.row_label) || ((A = _.o2m) == null ? void 0 : A.collection_label) || "a related row",
40
- delta: ((W = (((O = _.o2m) == null ? void 0 : O.totals) ?? []).find((B) => B.field === p)) == null ? void 0 : W.delta) ?? 0
37
+ name: a($),
38
+ userId: $.user_id ?? null,
39
+ row: ((v = $.o2m) == null ? void 0 : v.row_label) || ((O = $.o2m) == null ? void 0 : O.collection_label) || "a related row",
40
+ delta: ((N = (((D = $.o2m) == null ? void 0 : D.totals) ?? []).find((x) => x.field === w)) == null ? void 0 : N.delta) ?? 0
41
41
  };
42
42
  }).reverse();
43
- N.length && g.set(p, N);
43
+ C.length && h.set(w, C);
44
44
  }
45
45
  }
46
46
  return {
@@ -48,56 +48,56 @@ function K(e, o = {}) {
48
48
  timestamp: n.timestamp,
49
49
  who: a(n),
50
50
  userId: n.user_id ?? null,
51
- action: w,
52
- values: l.length ? { ...h, [$]: r(f(n)) } : h,
53
- changed: k,
51
+ action: y,
52
+ values: i.length ? { ...b, [j]: c(f(n)) } : b,
53
+ changed: A,
54
54
  recalculated: I,
55
- via: g
55
+ via: h
56
56
  };
57
57
  });
58
- if (!o.withMoves || l.length === 0) return u;
59
- const m = t.filter((n) => n.user_id && (D(n) || n.event || n.o2m)), b = l.map((n) => {
60
- var k, I;
61
- const i = f(n), d = u.find((g) => (g.timestamp ? new Date(g.timestamp).getTime() : 0) <= i), h = !n.user_id, w = h ? m.filter((g) => g !== n && f(g) <= i + 2e3 && i - f(g) <= 15e3).sort((g, T) => Math.abs(i - f(g)) - Math.abs(i - f(T)))[0] : void 0;
58
+ if (!o.withMoves || i.length === 0) return r;
59
+ const d = t.filter((n) => n.user_id && (M(n) || n.event || n.o2m)), g = i.map((n) => {
60
+ var A, I;
61
+ const u = f(n), m = r.find((h) => (h.timestamp ? new Date(h.timestamp).getTime() : 0) <= u), b = !n.user_id, y = b ? d.filter((h) => h !== n && f(h) <= u + 2e3 && u - f(h) <= 15e3).sort((h, T) => Math.abs(u - f(h)) - Math.abs(u - f(T)))[0] : void 0;
62
62
  return {
63
- key: `move|${n.timestamp ?? ""}|${((k = n.event) == null ? void 0 : k.to_label) ?? ""}`,
63
+ key: `move|${n.timestamp ?? ""}|${((A = n.event) == null ? void 0 : A.to_label) ?? ""}`,
64
64
  timestamp: n.timestamp,
65
- who: h ? "Automatic" : a(n),
65
+ who: b ? "Automatic" : a(n),
66
66
  userId: n.user_id ?? null,
67
- trigger: w ? { name: a(w), userId: w.user_id ?? null } : null,
68
- linkedTo: w && D(w) ? `${w.id}|${w.timestamp ?? ""}` : null,
67
+ trigger: y ? { name: a(y), userId: y.user_id ?? null } : null,
68
+ linkedTo: y && M(y) ? `${y.id}|${y.timestamp ?? ""}` : null,
69
69
  action: "moved",
70
- values: { ...(d == null ? void 0 : d.values) ?? {}, [$]: ((I = n.event) == null ? void 0 : I.to_label) ?? null },
71
- changed: /* @__PURE__ */ new Set([$]),
70
+ values: { ...(m == null ? void 0 : m.values) ?? {}, [j]: ((I = n.event) == null ? void 0 : I.to_label) ?? null },
71
+ changed: /* @__PURE__ */ new Set([j]),
72
72
  recalculated: /* @__PURE__ */ new Set(),
73
73
  via: /* @__PURE__ */ new Map()
74
74
  };
75
- }), y = new Map(u.map((n) => [n.key, n])), S = [];
76
- for (const [n, i] of b.entries()) {
77
- const d = i.linkedTo ? y.get(i.linkedTo) : void 0;
78
- if (!d) {
79
- S.push(i);
75
+ }), _ = new Map(r.map((n) => [n.key, n])), S = [];
76
+ for (const [n, u] of g.entries()) {
77
+ const m = u.linkedTo ? _.get(u.linkedTo) : void 0;
78
+ if (!m) {
79
+ S.push(u);
80
80
  continue;
81
81
  }
82
- d.values = { ...d.values, [$]: i.values[$] ?? null }, d.changed = /* @__PURE__ */ new Set([...d.changed, $]), d.autoMove = {
83
- from: ((v = l[n].event) == null ? void 0 : v.from_label) ?? null,
84
- to: ((M = l[n].event) == null ? void 0 : M.to_label) ?? null
82
+ m.values = { ...m.values, [j]: u.values[j] ?? null }, m.changed = /* @__PURE__ */ new Set([...m.changed, j]), m.autoMove = {
83
+ from: ((p = i[n].event) == null ? void 0 : p.from_label) ?? null,
84
+ to: ((k = i[n].event) == null ? void 0 : k.to_label) ?? null
85
85
  };
86
86
  }
87
- return [...u, ...S].sort(
88
- (n, i) => (i.timestamp ? new Date(i.timestamp).getTime() : 0) - (n.timestamp ? new Date(n.timestamp).getTime() : 0)
87
+ return [...r, ...S].sort(
88
+ (n, u) => (u.timestamp ? new Date(u.timestamp).getTime() : 0) - (n.timestamp ? new Date(n.timestamp).getTime() : 0)
89
89
  );
90
90
  }
91
91
  function Z(e, o) {
92
92
  const a = /* @__PURE__ */ new Map();
93
93
  for (const s of e) {
94
- for (const c of Object.keys(s.values)) a.has(c) || a.set(c, 0);
95
- for (const c of [...s.changed, ...s.recalculated]) a.set(c, (a.get(c) ?? 0) + 1);
94
+ for (const l of Object.keys(s.values)) a.has(l) || a.set(l, 0);
95
+ for (const l of [...s.changed, ...s.recalculated]) a.set(l, (a.get(l) ?? 0) + 1);
96
96
  }
97
- const t = (s) => s === $ ? { label: V, system: !1, order: -1 } : o(s);
98
- return [...a].filter(([s]) => s !== "id" && !t(s).system).map(([s, c]) => ({ field: s, label: t(s).label, changes: c })).sort((s, c) => {
99
- const l = t(s.field).order ?? Number.POSITIVE_INFINITY, r = t(c.field).order ?? Number.POSITIVE_INFINITY;
100
- return l - r || s.label.localeCompare(c.label);
97
+ const t = (s) => s === j ? { label: B, system: !1, order: -1 } : o(s);
98
+ return [...a].filter(([s]) => s !== "id" && !t(s).system).map(([s, l]) => ({ field: s, label: t(s).label, changes: l })).sort((s, l) => {
99
+ const i = t(s.field).order ?? Number.POSITIVE_INFINITY, c = t(l.field).order ?? Number.POSITIVE_INFINITY;
100
+ return i - c || s.label.localeCompare(l.label);
101
101
  });
102
102
  }
103
103
  function q(e, o) {
@@ -105,12 +105,12 @@ function q(e, o) {
105
105
  (a) => a.action !== "changed" && a.action !== "moved" || o.some((t) => a.changed.has(t) || a.recalculated.has(t))
106
106
  );
107
107
  }
108
- function L(e) {
108
+ function E(e) {
109
109
  const o = Math.abs(e).toLocaleString("en-US", { maximumFractionDigits: 2 });
110
110
  return `${e > 0 ? "+" : e < 0 ? "−" : ""}${o}`;
111
111
  }
112
112
  function J(e) {
113
- return e != null && e.length ? `Recalculated after ${e.map((o) => `${o.name} · ${o.row} ${L(o.delta)}`).join(", ")}` : "Recalculated";
113
+ return e != null && e.length ? `Recalculated after ${e.map((o) => `${o.name} · ${o.row} ${E(o.delta)}`).join(", ")}` : "Recalculated";
114
114
  }
115
115
  const U = {
116
116
  created: "Created",
@@ -124,30 +124,30 @@ function z(e) {
124
124
  return /^[=+\-@\t\r]/.test(o) && !/^-?\d[\d,]*(\.\d+)?$/.test(o) && (o = `'${o}`), /[",\n\r]/.test(o) ? `"${o.replace(/"/g, '""')}"` : o;
125
125
  }
126
126
  function Q(e, o, a, t) {
127
- const s = z, l = [["When", "Changed by", "Action", ...o.map((r) => r.label), "Recalculated"].map(s).join(",")];
128
- for (const r of e) {
129
- const u = [...r.recalculated].filter((m) => o.some((b) => b.field === m)).map((m) => {
127
+ const s = z, i = [["When", "Changed by", "Action", ...o.map((c) => c.label), "Recalculated"].map(s).join(",")];
128
+ for (const c of e) {
129
+ const r = [...c.recalculated].filter((d) => o.some((g) => g.field === d)).map((d) => {
130
130
  var S;
131
- const b = ((S = o.find((v) => v.field === m)) == null ? void 0 : S.label) ?? m;
132
- if (!t) return `${b}: ${J(r.via.get(m))}`;
133
- const y = t(m, r);
134
- return `${b}: ${y.why}${y.because ? ` — ${y.because}` : ""}`;
131
+ const g = ((S = o.find((p) => p.field === d)) == null ? void 0 : S.label) ?? d;
132
+ if (!t) return `${g}: ${J(c.via.get(d))}`;
133
+ const _ = t(d, c);
134
+ return `${g}: ${_.why}${_.because ? ` — ${_.because}` : ""}`;
135
135
  }).join("; ");
136
- l.push(
136
+ i.push(
137
137
  [
138
- r.timestamp ? new Date(r.timestamp).toLocaleString("en-US") : "",
139
- r.who,
140
- Y(r.action),
141
- ...o.map((m) => a(m.field, r.values[m.field])),
142
- u
143
- ].map((m) => s(String(m ?? ""))).join(",")
138
+ c.timestamp ? new Date(c.timestamp).toLocaleString("en-US") : "",
139
+ c.who,
140
+ Y(c.action),
141
+ ...o.map((d) => a(d.field, c.values[d.field])),
142
+ r
143
+ ].map((d) => s(String(d ?? ""))).join(",")
144
144
  );
145
145
  }
146
- return `${l.join(`\r
146
+ return `${i.join(`\r
147
147
  `)}\r
148
148
  `;
149
149
  }
150
- const C = (e) => {
150
+ const W = (e) => {
151
151
  if (e && typeof e == "object" && !Array.isArray(e)) return e;
152
152
  if (typeof e != "string" || !e.trim()) return null;
153
153
  try {
@@ -160,16 +160,16 @@ const C = (e) => {
160
160
  function X(e, o) {
161
161
  const a = String(e ?? "");
162
162
  if (a === "rollup") {
163
- const t = C(o), c = (Array.isArray(t == null ? void 0 : t.sources) ? t == null ? void 0 : t.sources : []).filter((l) => typeof l.related_collection == "string").map((l) => ({
164
- collection: String(l.related_collection),
165
- field: String(l.value_field ?? ""),
166
- aggregate: String(l.aggregate ?? "sum"),
167
- filtered: !!l.filter && Object.keys(l.filter).length > 0
163
+ const t = W(o), l = (Array.isArray(t == null ? void 0 : t.sources) ? t == null ? void 0 : t.sources : []).filter((i) => typeof i.related_collection == "string").map((i) => ({
164
+ collection: String(i.related_collection),
165
+ field: String(i.value_field ?? ""),
166
+ aggregate: String(i.aggregate ?? "sum"),
167
+ filtered: !!i.filter && Object.keys(i.filter).length > 0
168
168
  }));
169
- return c.length ? { kind: "rollup", sources: c } : null;
169
+ return l.length ? { kind: "rollup", sources: l } : null;
170
170
  }
171
171
  if (a === "lookup") {
172
- const t = C(o);
172
+ const t = W(o);
173
173
  return !(t != null && t.fk_field) || !(t != null && t.source_field) ? null : { kind: "lookup", fk: String(t.fk_field), source: String(t.source_field) };
174
174
  }
175
175
  return a === "write" || a === "read" ? { kind: "formula", inputs: [
@@ -187,22 +187,22 @@ const H = {
187
187
  median: "Median",
188
188
  distinct_count: "Distinct count",
189
189
  weighted_avg: "Weighted average"
190
- }, E = (e) => e.length <= 1 ? e[0] ?? "" : `${e.slice(0, -1).join(", ")} and ${e[e.length - 1]}`;
191
- function ee(e, o, a, t, s = L) {
192
- const c = o.via.get(e), l = c != null && c.length ? c.map((r) => `${r.name} changed ${r.row} (${s(r.delta)})`).join("; ") : void 0;
190
+ }, L = (e) => e.length <= 1 ? e[0] ?? "" : `${e.slice(0, -1).join(", ")} and ${e[e.length - 1]}`;
191
+ function ee(e, o, a, t, s = E) {
192
+ const l = o.via.get(e), i = l != null && l.length ? l.map((c) => `${c.name} changed ${c.row} (${s(c.delta)})`).join("; ") : void 0;
193
193
  if ((a == null ? void 0 : a.kind) === "rollup")
194
194
  return {
195
- why: a.sources.map((u) => {
196
- const m = H[u.aggregate] ?? "Total", b = u.aggregate === "count" ? t(u.collection) : `${t(u.collection)} · ${t(u.collection, u.field)}`;
197
- return `${m} of ${b}${u.filtered ? " (filtered)" : ""}`;
195
+ why: a.sources.map((r) => {
196
+ const d = H[r.aggregate] ?? "Total", g = r.aggregate === "count" ? t(r.collection) : `${t(r.collection)} · ${t(r.collection, r.field)}`;
197
+ return `${d} of ${g}${r.filtered ? " (filtered)" : ""}`;
198
198
  }).join(" + "),
199
- because: l ?? "Its rows changed between these two saves"
199
+ because: i ?? "Its rows changed between these two saves"
200
200
  };
201
201
  if ((a == null ? void 0 : a.kind) === "formula") {
202
- const r = a.inputs.filter((u) => o.changed.has(u) || o.recalculated.has(u));
202
+ const c = a.inputs.filter((r) => o.changed.has(r) || o.recalculated.has(r));
203
203
  return {
204
- why: a.inputs.length ? `Worked out from ${E(a.inputs.map((u) => t(null, u)))}` : "Worked out by a formula",
205
- because: r.length ? `${E(r.map((u) => t(null, u)))} changed` : l ?? void 0
204
+ why: a.inputs.length ? `Worked out from ${L(a.inputs.map((r) => t(null, r)))}` : "Worked out by a formula",
205
+ because: c.length ? `${L(c.map((r) => t(null, r)))} changed` : i ?? void 0
206
206
  };
207
207
  }
208
208
  return (a == null ? void 0 : a.kind) === "lookup" ? {
@@ -210,7 +210,7 @@ function ee(e, o, a, t, s = L) {
210
210
  because: o.changed.has(a.fk) ? `${t(null, a.fk)} changed` : void 0
211
211
  } : {
212
212
  why: "Set automatically (rule, job or integration)",
213
- because: l
213
+ because: i
214
214
  };
215
215
  }
216
216
  function te(e, o) {
@@ -223,9 +223,30 @@ function te(e, o) {
223
223
  }
224
224
  return t;
225
225
  }
226
+ function ne(e, o) {
227
+ const a = (o == null ? void 0 : o.fields) ?? {}, t = Object.keys(a);
228
+ return t.length === 0 ? e : e.map((s) => {
229
+ if (!s.data) return s;
230
+ let l = null;
231
+ for (const i of t) {
232
+ const c = s.data[i];
233
+ if (!Array.isArray(c)) continue;
234
+ const r = a[i], d = [];
235
+ let g = 0;
236
+ for (const p of c) {
237
+ const k = p && typeof p == "object" ? p.id : p, n = k == null ? void 0 : r[String(k)];
238
+ n ? d.push(n.label) : g++;
239
+ }
240
+ d.sort((p, k) => p.localeCompare(k));
241
+ const _ = g === 0 ? [] : d.length === 0 ? [`${g} linked`] : [`+${g} more`], S = [...new Set(d), ..._].join(", ");
242
+ l = l ?? { ...s.data }, l[i] = c.length === 0 ? null : S;
243
+ }
244
+ return l ? { ...s, data: l } : s;
245
+ });
246
+ }
226
247
  export {
227
- $ as STEP_FIELD,
228
- V as STEP_LABEL,
248
+ j as STEP_FIELD,
249
+ B as STEP_LABEL,
229
250
  K as buildSaveRows,
230
251
  z as csvCell,
231
252
  X as deriveOf,
@@ -234,9 +255,10 @@ export {
234
255
  F as personName,
235
256
  ee as recalcReason,
236
257
  q as rowsChanging,
237
- x as sameValue,
258
+ V as sameValue,
238
259
  Y as saveActionLabel,
239
- L as signedAmount,
260
+ E as signedAmount,
240
261
  te as valueAt,
241
- J as viaText
262
+ J as viaText,
263
+ ne as withLinkLabels
242
264
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivaro/react",
3
- "version": "0.3.125",
3
+ "version": "0.3.126",
4
4
  "description": "React hooks and components for Nivaro CMS forms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",