@nivaro/react 0.3.49 → 0.3.50

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.
Files changed (32) hide show
  1. package/dist/components/InlineGridField.js +166 -105
  2. package/dist/full.css +1 -1
  3. package/dist/hooks/useSessionRecorder.js +1 -1
  4. package/dist/index.d.ts +25 -1
  5. package/dist/shared/components/ItemEditForm.js +4676 -4579
  6. package/dist/shared/components/QueryTable.js +461 -332
  7. package/dist/shared/components/item-edit/CatalogPickerField.js +1144 -1127
  8. package/dist/shared/components/item-edit/CloneDialog.js +192 -142
  9. package/dist/shared/components/item-edit/FieldRenderer.js +127 -126
  10. package/dist/shared/components/item-edit/FieldRow.js +236 -226
  11. package/dist/shared/components/item-edit/InlineGridField.js +92 -90
  12. package/dist/shared/components/item-edit/InlineTableField.js +3088 -2945
  13. package/dist/shared/components/item-edit/MidairCollisionDialog.js +175 -0
  14. package/dist/shared/components/item-edit/PlanGrid.js +162 -162
  15. package/dist/shared/components/item-edit/PolishFields.js +169 -162
  16. package/dist/shared/components/item-edit/RelationCombobox.js +186 -181
  17. package/dist/shared/components/item-edit/SummaryPanel.js +148 -135
  18. package/dist/shared/components/item-edit/ValidationSummary.js +64 -47
  19. package/dist/shared/components/item-edit/helpers.js +181 -155
  20. package/dist/shared/components/item-edit/line-midair.js +201 -0
  21. package/dist/shared/components/item-edit/soft-rules.js +27 -0
  22. package/dist/shared/components/layout-editor/parity-keys.json.js +1 -1
  23. package/dist/shared/components/panels/ItemLockBanner.js +414 -358
  24. package/dist/shared/components/panels/PipelinePanel.js +1157 -963
  25. package/dist/shared/components/panels/RecordIntegrityBanner.js +1 -1
  26. package/dist/shared/components/queue/QueueWorklist.js +870 -827
  27. package/dist/shared/components/queue/column-chooser.js +21 -0
  28. package/dist/shared/components/queue/live-state-aspect.js +6 -0
  29. package/dist/shared/components/ui/number-draft-input.js +93 -0
  30. package/dist/shared/components/widgets/ReviewListWidget.js +191 -166
  31. package/dist/shared/lib/error-hints.js +1 -0
  32. package/package.json +1 -1
@@ -1,164 +1,223 @@
1
- import { jsx as e, jsxs as c } from "react/jsx-runtime";
2
- import { useState as C, useRef as L, useEffect as k, useCallback as O } from "react";
3
- import { get as j, del as P, post as W, patch as B } from "../lib/commands.js";
4
- import { useOptionalNivaroClient as H, useGridFlush as Q } from "../shared/context.js";
5
- function z(g) {
6
- return g.replace(/_/g, " ").replace(/\b\w/g, (s) => s.toUpperCase());
1
+ import { jsx as r, jsxs as p } from "react/jsx-runtime";
2
+ import { useState as v, useRef as L, useEffect as _, useCallback as z } from "react";
3
+ import { get as M, del as W, post as H, patch as Q } from "../lib/commands.js";
4
+ import { useOptionalNivaroClient as T, useGridFlush as X } from "../shared/context.js";
5
+ function Y({
6
+ value: o,
7
+ onValue: d,
8
+ placeholder: l
9
+ }) {
10
+ const [m, f] = v(null), i = o == null ? "" : String(o);
11
+ return /* @__PURE__ */ r(
12
+ "input",
13
+ {
14
+ type: "number",
15
+ value: m ?? i,
16
+ onChange: (c) => {
17
+ var $;
18
+ const g = c.target.value;
19
+ if (g === "" && (($ = c.target.validity) != null && $.badInput)) {
20
+ f("");
21
+ return;
22
+ }
23
+ if (f(g), g.trim() === "") return d(null);
24
+ const w = Number(g);
25
+ Number.isFinite(w) && d(w);
26
+ },
27
+ onBlur: () => f(null),
28
+ placeholder: l,
29
+ "data-nf-grid-cell": !0
30
+ }
31
+ );
32
+ }
33
+ async function A(o, d, l) {
34
+ const m = /* @__PURE__ */ new Map(), f = [...new Set(l)].filter((i) => i && i !== "new");
35
+ for (let i = 0; i < f.length; i += 500)
36
+ try {
37
+ const c = await o.request(
38
+ M("/revisions/latest", {
39
+ collection: d,
40
+ items: f.slice(i, i + 500).join(",")
41
+ })
42
+ );
43
+ for (const [g, w] of Object.entries((c == null ? void 0 : c.data) ?? {}))
44
+ m.set(g, typeof w == "number" && Number.isFinite(w) ? w : null);
45
+ } catch {
46
+ }
47
+ return m;
48
+ }
49
+ function Z(o) {
50
+ var l;
51
+ const d = o == null ? void 0 : o.response;
52
+ return (((l = d == null ? void 0 : d.data) == null ? void 0 : l.code) ?? (d == null ? void 0 : d.code)) === "MIDAIR_COLLISION";
7
53
  }
8
- function tt({
9
- field: g,
10
- itemId: s
54
+ function V(o) {
55
+ return o.replace(/_/g, " ").replace(/\b\w/g, (d) => d.toUpperCase());
56
+ }
57
+ function it({
58
+ field: o,
59
+ itemId: d
11
60
  }) {
12
- const d = H(), h = Q(), m = g.relation, l = (m == null ? void 0 : m.relatedCollection) ?? "", f = (m == null ? void 0 : m.manyField) ?? "", [p, G] = C([]), [I, q] = C([]), [b, _] = C(/* @__PURE__ */ new Map()), [w, $] = C([]), [y, x] = C(/* @__PURE__ */ new Set()), v = L(!0);
13
- k(() => (v.current = !0, () => {
14
- v.current = !1;
61
+ const l = T(), m = X(), f = o.relation, i = (f == null ? void 0 : f.relatedCollection) ?? "", c = (f == null ? void 0 : f.manyField) ?? "", [g, w] = v([]), [$, x] = v([]), [S, O] = v(/* @__PURE__ */ new Map()), [b, k] = v([]), [C, F] = v(/* @__PURE__ */ new Set()), y = L(!0);
62
+ _(() => (y.current = !0, () => {
63
+ y.current = !1;
15
64
  }), []);
16
- const V = b.size > 0 || w.length > 0 || y.size > 0, N = O(async () => {
17
- if (!(!d || !s || !l || !f))
65
+ const B = S.size > 0 || b.length > 0 || C.size > 0, D = L(/* @__PURE__ */ new Map()), N = z(async () => {
66
+ if (!(!l || !d || !i || !c))
18
67
  try {
19
- const t = await d.request(
20
- j(`/items/${l}`, {
21
- filter: JSON.stringify({ [f]: { _eq: s } }),
68
+ const n = (await l.request(
69
+ M(`/items/${i}`, {
70
+ filter: JSON.stringify({ [c]: { _eq: d } }),
22
71
  limit: 200,
23
72
  fields: "*"
24
73
  })
25
- );
26
- v.current && q(t.data ?? []);
74
+ )).data ?? [];
75
+ D.current = await A(
76
+ l,
77
+ i,
78
+ n.map((e) => String(e.id))
79
+ ), y.current && x(n);
27
80
  } catch {
28
- v.current && q([]);
81
+ y.current && x([]);
29
82
  }
30
- }, [d, s, l, f]);
31
- k(() => {
32
- !d || !l || d.request(j(`/field-config/${l}`)).then((t) => {
33
- if (!v.current) return;
83
+ }, [l, d, i, c]);
84
+ _(() => {
85
+ !l || !i || l.request(M(`/field-config/${i}`)).then((t) => {
86
+ if (!y.current) return;
34
87
  const n = (t.data ?? []).filter(
35
- (r) => !r.field.startsWith("_") && r.field !== "id" && r.field !== f
88
+ (e) => !e.field.startsWith("_") && e.field !== "id" && e.field !== c
36
89
  );
37
- G(n);
90
+ w(n);
38
91
  }).catch(() => {
39
92
  });
40
- }, [d, l, f]), k(() => {
93
+ }, [l, i, c]), _(() => {
41
94
  N();
42
95
  }, [N]);
43
- const U = O(async () => {
44
- if (d) {
45
- for (const t of y)
46
- await d.request(P(`/items/${l}/${t}`));
47
- for (const t of w)
48
- await d.request(W(`/items/${l}`, { ...t, [f]: s }));
49
- for (const [t, n] of b)
50
- y.has(t) || await d.request(B(`/items/${l}/${t}`, n));
51
- v.current && (_(/* @__PURE__ */ new Map()), $([]), x(/* @__PURE__ */ new Set()), await N());
96
+ const j = z(async () => {
97
+ if (!l) return;
98
+ for (const e of C)
99
+ await l.request(W(`/items/${i}/${e}`));
100
+ for (const e of b)
101
+ await l.request(H(`/items/${i}`, { ...e, [c]: d }));
102
+ const t = [...S].filter(([e]) => !C.has(e)), n = t.map(([e]) => e).filter((e) => !((D.current.get(e) ?? 0) > 0));
103
+ if (n.length > 0) {
104
+ const e = await A(l, i, n);
105
+ for (const [s, a] of e) D.current.set(s, a);
52
106
  }
53
- }, [d, l, f, s, y, w, b, N]), D = `inline-grid:${l}:${f}`;
54
- k(() => (h == null || h.register(D, U), () => h == null ? void 0 : h.unregister(D)), [h, D, U]);
55
- function A(t, n, r, o) {
56
- var i, u;
57
- return r ? ((i = w[o]) == null ? void 0 : i[n]) ?? "" : ((u = b.get(String(t.id))) == null ? void 0 : u[n]) ?? t[n] ?? "";
107
+ for (const [e, s] of t) {
108
+ const a = D.current.get(e);
109
+ try {
110
+ await l.request(
111
+ Q(
112
+ `/items/${i}/${e}`,
113
+ typeof a == "number" && a > 0 ? { ...s, _base_revision: a } : s
114
+ )
115
+ );
116
+ } catch (h) {
117
+ throw Z(h) && await N(), h;
118
+ }
119
+ }
120
+ y.current && (O(/* @__PURE__ */ new Map()), k([]), F(/* @__PURE__ */ new Set()), await N());
121
+ }, [l, i, c, d, C, b, S, N]), I = `inline-grid:${i}:${c}`;
122
+ _(() => (m == null || m.register(I, j), () => m == null ? void 0 : m.unregister(I)), [m, I, j]);
123
+ function J(t, n, e, s) {
124
+ var a, h;
125
+ return e ? ((a = b[s]) == null ? void 0 : a[n]) ?? "" : ((h = S.get(String(t.id))) == null ? void 0 : h[n]) ?? t[n] ?? "";
58
126
  }
59
- function J(t, n, r, o, i) {
60
- if (o) {
61
- $((S) => S.map((a, K) => K === i ? { ...a, [n]: r } : a));
127
+ function K(t, n, e, s, a) {
128
+ if (s) {
129
+ k((R) => R.map((u, P) => P === a ? { ...u, [n]: e } : u));
62
130
  return;
63
131
  }
64
- const u = String(t.id);
65
- _((S) => {
66
- const a = new Map(S);
67
- return a.set(u, { ...a.get(u) ?? {}, [n]: r }), a;
132
+ const h = String(t.id);
133
+ O((R) => {
134
+ const u = new Map(R);
135
+ return u.set(h, { ...u.get(h) ?? {}, [n]: e }), u;
68
136
  });
69
137
  }
70
- function E(t, n, r, o) {
71
- const i = A(n, t.field, r, o), u = (a) => J(n, t.field, a, r, o), S = ["integer", "bigInteger", "float", "decimal", "numeric"].includes(t.type);
72
- return t.type === "boolean" ? /* @__PURE__ */ e(
138
+ function U(t, n, e, s) {
139
+ const a = J(n, t.field, e, s), h = (u) => K(n, t.field, u, e, s), R = ["integer", "bigInteger", "float", "decimal", "numeric"].includes(t.type);
140
+ return t.type === "boolean" ? /* @__PURE__ */ r(
73
141
  "input",
74
142
  {
75
143
  type: "checkbox",
76
- checked: !!i,
77
- onChange: (a) => u(a.target.checked),
144
+ checked: !!a,
145
+ onChange: (u) => h(u.target.checked),
78
146
  "data-nf-grid-cell-checkbox": !0
79
147
  }
80
- ) : S ? /* @__PURE__ */ e(
81
- "input",
82
- {
83
- type: "number",
84
- value: i == null ? "" : String(i),
85
- onChange: (a) => u(a.target.value === "" ? null : Number(a.target.value)),
86
- placeholder: t.note ?? void 0,
87
- "data-nf-grid-cell": !0
88
- }
89
- ) : t.type === "datetime" || t.interface === "datetime" ? /* @__PURE__ */ e(
148
+ ) : R ? /* @__PURE__ */ r(Y, { value: a, onValue: h, placeholder: t.note ?? void 0 }) : t.type === "datetime" || t.interface === "datetime" ? /* @__PURE__ */ r(
90
149
  "input",
91
150
  {
92
151
  type: "datetime-local",
93
- value: i ? String(i).slice(0, 16) : "",
94
- onChange: (a) => u(a.target.value ? new Date(a.target.value).toISOString() : null),
152
+ value: a ? String(a).slice(0, 16) : "",
153
+ onChange: (u) => h(u.target.value ? new Date(u.target.value).toISOString() : null),
95
154
  "data-nf-grid-cell": !0
96
155
  }
97
- ) : /* @__PURE__ */ e(
156
+ ) : /* @__PURE__ */ r(
98
157
  "input",
99
158
  {
100
159
  type: "text",
101
- value: i == null ? "" : String(i),
102
- onChange: (a) => u(a.target.value || null),
160
+ value: a == null ? "" : String(a),
161
+ onChange: (u) => h(u.target.value || null),
103
162
  placeholder: t.note ?? void 0,
104
163
  "data-nf-grid-cell": !0
105
164
  }
106
165
  );
107
166
  }
108
- if (!s)
109
- return /* @__PURE__ */ e("div", { "data-nf-inline-grid": !0, "data-nf-inline-grid-empty": !0, children: /* @__PURE__ */ e("p", { "data-nf-empty": !0, children: "Save the record first to manage related rows." }) });
110
- const F = I.filter((t) => !y.has(String(t.id))), R = [
111
- ...F.map((t) => ({ ...t, ...b.get(String(t.id)) ?? {} })),
112
- ...w
113
- ], M = p.filter(
167
+ if (!d)
168
+ return /* @__PURE__ */ r("div", { "data-nf-inline-grid": !0, "data-nf-inline-grid-empty": !0, children: /* @__PURE__ */ r("p", { "data-nf-empty": !0, children: "Save the record first to manage related rows." }) });
169
+ const E = $.filter((t) => !C.has(String(t.id))), q = [
170
+ ...E.map((t) => ({ ...t, ...S.get(String(t.id)) ?? {} })),
171
+ ...b
172
+ ], G = g.filter(
114
173
  (t) => ["integer", "bigInteger", "float", "decimal", "numeric"].includes(t.type)
115
174
  );
116
- return /* @__PURE__ */ c("div", { "data-nf-inline-grid": !0, children: [
117
- /* @__PURE__ */ c("span", { "data-nf-inline-grid-label": !0, children: [
118
- g.label ?? z(g.field),
119
- g.note ? /* @__PURE__ */ c("span", { "data-nf-inline-grid-note": !0, title: g.note, children: [
175
+ return /* @__PURE__ */ p("div", { "data-nf-inline-grid": !0, children: [
176
+ /* @__PURE__ */ p("span", { "data-nf-inline-grid-label": !0, children: [
177
+ o.label ?? V(o.field),
178
+ o.note ? /* @__PURE__ */ p("span", { "data-nf-inline-grid-note": !0, title: o.note, children: [
120
179
  " ",
121
180
  "?"
122
181
  ] }) : null
123
182
  ] }),
124
- V && /* @__PURE__ */ e("div", { "data-nf-inline-grid-pending": !0, children: "Unsaved changes — will save with the record" }),
125
- /* @__PURE__ */ c("div", { "data-nf-inline-grid-wrap": !0, children: [
126
- /* @__PURE__ */ e("div", { "data-nf-inline-grid-scroll": !0, children: /* @__PURE__ */ c("table", { "data-nf-inline-grid-table": !0, children: [
127
- /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ c("tr", { children: [
128
- p.map((t) => /* @__PURE__ */ e("th", { "data-nf-grid-th": !0, children: t.label ?? z(t.field) }, t.field)),
129
- /* @__PURE__ */ e("th", { "data-nf-grid-th-action": !0 })
183
+ B && /* @__PURE__ */ r("div", { "data-nf-inline-grid-pending": !0, children: "Unsaved changes — will save with the record" }),
184
+ /* @__PURE__ */ p("div", { "data-nf-inline-grid-wrap": !0, children: [
185
+ /* @__PURE__ */ r("div", { "data-nf-inline-grid-scroll": !0, children: /* @__PURE__ */ p("table", { "data-nf-inline-grid-table": !0, children: [
186
+ /* @__PURE__ */ r("thead", { children: /* @__PURE__ */ p("tr", { children: [
187
+ g.map((t) => /* @__PURE__ */ r("th", { "data-nf-grid-th": !0, children: t.label ?? V(t.field) }, t.field)),
188
+ /* @__PURE__ */ r("th", { "data-nf-grid-th-action": !0 })
130
189
  ] }) }),
131
- /* @__PURE__ */ c("tbody", { children: [
132
- F.map((t) => /* @__PURE__ */ c("tr", { "data-nf-grid-row": !0, children: [
133
- p.map((n) => /* @__PURE__ */ e("td", { "data-nf-grid-td": !0, children: E(n, t, !1, -1) }, n.field)),
134
- /* @__PURE__ */ e("td", { "data-nf-grid-td-action": !0, children: /* @__PURE__ */ e(
190
+ /* @__PURE__ */ p("tbody", { children: [
191
+ E.map((t) => /* @__PURE__ */ p("tr", { "data-nf-grid-row": !0, children: [
192
+ g.map((n) => /* @__PURE__ */ r("td", { "data-nf-grid-td": !0, children: U(n, t, !1, -1) }, n.field)),
193
+ /* @__PURE__ */ r("td", { "data-nf-grid-td-action": !0, children: /* @__PURE__ */ r(
135
194
  "button",
136
195
  {
137
196
  type: "button",
138
197
  "data-nf-grid-delete": !0,
139
198
  "aria-label": "Delete row",
140
- onClick: () => x((n) => {
141
- const r = new Set(n);
142
- return r.add(String(t.id)), r;
199
+ onClick: () => F((n) => {
200
+ const e = new Set(n);
201
+ return e.add(String(t.id)), e;
143
202
  }),
144
203
  children: "×"
145
204
  }
146
205
  ) })
147
206
  ] }, String(t.id))),
148
- w.map((t, n) => /* @__PURE__ */ c(
207
+ b.map((t, n) => /* @__PURE__ */ p(
149
208
  "tr",
150
209
  {
151
210
  "data-nf-grid-row": !0,
152
211
  "data-nf-grid-row-new": !0,
153
212
  children: [
154
- p.map((r) => /* @__PURE__ */ e("td", { "data-nf-grid-td": !0, children: E(r, t, !0, n) }, r.field)),
155
- /* @__PURE__ */ e("td", { "data-nf-grid-td-action": !0, children: /* @__PURE__ */ e(
213
+ g.map((e) => /* @__PURE__ */ r("td", { "data-nf-grid-td": !0, children: U(e, t, !0, n) }, e.field)),
214
+ /* @__PURE__ */ r("td", { "data-nf-grid-td-action": !0, children: /* @__PURE__ */ r(
156
215
  "button",
157
216
  {
158
217
  type: "button",
159
218
  "data-nf-grid-delete": !0,
160
219
  "aria-label": "Remove new row",
161
- onClick: () => $((r) => r.filter((o, i) => i !== n)),
220
+ onClick: () => k((e) => e.filter((s, a) => a !== n)),
162
221
  children: "×"
163
222
  }
164
223
  ) })
@@ -166,26 +225,26 @@ function tt({
166
225
  },
167
226
  t._rowId ?? `new-${n}`
168
227
  )),
169
- R.length === 0 && /* @__PURE__ */ e("tr", { children: /* @__PURE__ */ e("td", { colSpan: p.length + 1, "data-nf-grid-empty-row": !0, children: "No rows yet" }) })
228
+ q.length === 0 && /* @__PURE__ */ r("tr", { children: /* @__PURE__ */ r("td", { colSpan: g.length + 1, "data-nf-grid-empty-row": !0, children: "No rows yet" }) })
170
229
  ] }),
171
- M.length > 0 && R.length > 0 && /* @__PURE__ */ e("tfoot", { children: /* @__PURE__ */ c("tr", { "data-nf-grid-totals": !0, children: [
172
- p.map((t) => {
173
- if (!M.some((o) => o.field === t.field)) return /* @__PURE__ */ e("td", { "data-nf-grid-total-cell": !0 }, t.field);
174
- const r = R.reduce((o, i) => o + (Number(i[t.field]) || 0), 0);
175
- return /* @__PURE__ */ e("td", { "data-nf-grid-total-cell": !0, "data-nf-grid-total-num": !0, children: r.toLocaleString(void 0, {
230
+ G.length > 0 && q.length > 0 && /* @__PURE__ */ r("tfoot", { children: /* @__PURE__ */ p("tr", { "data-nf-grid-totals": !0, children: [
231
+ g.map((t) => {
232
+ if (!G.some((s) => s.field === t.field)) return /* @__PURE__ */ r("td", { "data-nf-grid-total-cell": !0 }, t.field);
233
+ const e = q.reduce((s, a) => s + (Number(a[t.field]) || 0), 0);
234
+ return /* @__PURE__ */ r("td", { "data-nf-grid-total-cell": !0, "data-nf-grid-total-num": !0, children: e.toLocaleString(void 0, {
176
235
  minimumFractionDigits: 2,
177
236
  maximumFractionDigits: 2
178
237
  }) }, t.field);
179
238
  }),
180
- /* @__PURE__ */ e("td", { "data-nf-grid-total-cell": !0 })
239
+ /* @__PURE__ */ r("td", { "data-nf-grid-total-cell": !0 })
181
240
  ] }) })
182
241
  ] }) }),
183
- /* @__PURE__ */ e("div", { "data-nf-inline-grid-footer": !0, children: /* @__PURE__ */ e(
242
+ /* @__PURE__ */ r("div", { "data-nf-inline-grid-footer": !0, children: /* @__PURE__ */ r(
184
243
  "button",
185
244
  {
186
245
  type: "button",
187
246
  "data-nf-grid-add": !0,
188
- onClick: () => $((t) => [...t, { _rowId: crypto.randomUUID() }]),
247
+ onClick: () => k((t) => [...t, { _rowId: crypto.randomUUID() }]),
189
248
  children: "+ Add row"
190
249
  }
191
250
  ) })
@@ -193,5 +252,7 @@ function tt({
193
252
  ] });
194
253
  }
195
254
  export {
196
- tt as InlineGridField
255
+ Y as GridNumberInput,
256
+ it as InlineGridField,
257
+ A as latestRevisions
197
258
  };