@nivaro/react 0.3.124 → 0.3.125

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