@nivaro/react 0.3.30 → 0.3.32
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.
- package/dist/full.css +1 -1
- package/dist/hooks/useSessionRecorder.js +1 -1
- package/dist/shared/components/ItemEditForm.js +2 -2
- package/dist/shared/components/item-edit/CatalogPickerField.js +1175 -1032
- package/dist/shared/components/item-edit/RecordHeaderActions.js +36 -31
- package/dist/shared/components/item-edit/catalog-columns.js +175 -0
- package/package.json +1 -1
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { jsx as i, Fragment as
|
|
2
|
-
import { useQuery as
|
|
1
|
+
import { jsx as i, Fragment as x, jsxs as f } from "react/jsx-runtime";
|
|
2
|
+
import { useQuery as w, useQueryClient as q, useMutation as R } from "@tanstack/react-query";
|
|
3
3
|
import { Play as C, Pause as N, Zap as $ } from "lucide-react";
|
|
4
|
-
import { useMemo as
|
|
4
|
+
import { useMemo as y, useState as F } from "react";
|
|
5
5
|
import { toast as p } from "sonner";
|
|
6
|
-
import { useNivaroClient as
|
|
7
|
-
import { get as j, post as
|
|
6
|
+
import { useNivaroClient as v } from "../../context.js";
|
|
7
|
+
import { get as j, post as k } from "../../lib/commands.js";
|
|
8
8
|
import { userErrorMessage as A } from "../../lib/safe-error.js";
|
|
9
9
|
import { cn as S } from "../../lib/utils.js";
|
|
10
10
|
import { useAvailableBulkActions as B, guardMatches as P } from "../bulk/BulkActionButtons.js";
|
|
11
|
-
import { Button as
|
|
11
|
+
import { Button as b } from "../ui/button.js";
|
|
12
12
|
import { Dialog as T, DialogContent as D, DialogHeader as H, DialogTitle as M, DialogDescription as Q, DialogBody as _, DialogFooter as E } from "../ui/dialog.js";
|
|
13
13
|
import { Textarea as J } from "../ui/textarea.js";
|
|
14
14
|
import { invalidateRecordQueries as K } from "./RecordLiveSync.js";
|
|
15
15
|
function ie(e, n, t) {
|
|
16
|
-
const h =
|
|
16
|
+
const h = v(), m = !!n && n !== "new", { data: u } = B(m ? [e] : []), d = y(
|
|
17
17
|
() => ((u == null ? void 0 : u[e]) ?? []).filter(
|
|
18
18
|
(o) => o.header === !0 && (o.kind === "update_fields" || o.kind === "transition")
|
|
19
19
|
),
|
|
20
20
|
[u, e]
|
|
21
|
-
), s =
|
|
21
|
+
), s = y(() => {
|
|
22
22
|
const o = /* @__PURE__ */ new Set();
|
|
23
23
|
for (const a of d)
|
|
24
24
|
for (const r of a.guard ?? [])
|
|
25
25
|
r && typeof r.field == "string" && !(t && r.field in t) && o.add(r.field);
|
|
26
26
|
return [...o].sort();
|
|
27
|
-
}, [d, t]), { data: l } =
|
|
27
|
+
}, [d, t]), { data: l } = w({
|
|
28
28
|
queryKey: ["record-header-action-guard", e, String(n), s.join(",")],
|
|
29
29
|
queryFn: () => h.request(
|
|
30
30
|
j(`/items/${encodeURIComponent(e)}/${encodeURIComponent(String(n))}`, {
|
|
@@ -34,7 +34,7 @@ function ie(e, n, t) {
|
|
|
34
34
|
enabled: m && s.length > 0,
|
|
35
35
|
staleTime: 0
|
|
36
36
|
});
|
|
37
|
-
return
|
|
37
|
+
return y(() => {
|
|
38
38
|
if (s.length > 0 && !l) return d.filter((a) => {
|
|
39
39
|
var r;
|
|
40
40
|
return !((r = a.guard) != null && r.length);
|
|
@@ -54,23 +54,28 @@ function ae({
|
|
|
54
54
|
actions: e,
|
|
55
55
|
onPick: n
|
|
56
56
|
}) {
|
|
57
|
-
return e.length === 0 ? null : /* @__PURE__ */ i(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
57
|
+
return e.length === 0 ? null : /* @__PURE__ */ i(x, { children: e.map((t) => (
|
|
58
|
+
// Same Button, size and type as the pipeline's transition buttons beside them.
|
|
59
|
+
/* @__PURE__ */ f(
|
|
60
|
+
b,
|
|
61
|
+
{
|
|
62
|
+
type: "button",
|
|
63
|
+
size: "sm",
|
|
64
|
+
variant: "outline",
|
|
65
|
+
"data-record-header-action": t.key,
|
|
66
|
+
"data-tip": W(t),
|
|
67
|
+
onClick: () => n(t),
|
|
68
|
+
className: S(
|
|
69
|
+
"shrink-0 gap-1.5 text-[12px]",
|
|
70
|
+
t.variant === "danger" && "border-red-300 text-red-600 hover:bg-red-50 hover:text-red-700 dark:border-red-500/40 dark:text-red-400 dark:hover:bg-red-500/10"
|
|
71
|
+
),
|
|
72
|
+
children: [
|
|
73
|
+
U(t),
|
|
74
|
+
t.label
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
`${t.source}:${t.key}`
|
|
78
|
+
)
|
|
74
79
|
)) });
|
|
75
80
|
}
|
|
76
81
|
function se({
|
|
@@ -80,9 +85,9 @@ function se({
|
|
|
80
85
|
onClose: h,
|
|
81
86
|
onDone: m
|
|
82
87
|
}) {
|
|
83
|
-
const u =
|
|
88
|
+
const u = v(), d = q(), [s, l] = F(""), o = !!(e != null && e.require_reason), a = R({
|
|
84
89
|
mutationFn: async (r) => {
|
|
85
|
-
const c = { collection: n, ids: [t], reason: s.trim() || null }, g = r.source === "db" ? await u.request(
|
|
90
|
+
const c = { collection: n, ids: [t], reason: s.trim() || null }, g = r.source === "db" ? await u.request(k("/bulk-actions/run", { ...c, key: r.key })) : await u.request(k(`/bulk-actions/${r.key}/execute`, c));
|
|
86
91
|
return { a: r, result: g.data ?? {} };
|
|
87
92
|
},
|
|
88
93
|
onSuccess: ({ a: r, result: c }) => {
|
|
@@ -118,9 +123,9 @@ function se({
|
|
|
118
123
|
)
|
|
119
124
|
] }),
|
|
120
125
|
/* @__PURE__ */ f(E, { children: [
|
|
121
|
-
/* @__PURE__ */ i(
|
|
126
|
+
/* @__PURE__ */ i(b, { variant: "outline", onClick: h, disabled: a.isPending, children: "Cancel" }),
|
|
122
127
|
/* @__PURE__ */ i(
|
|
123
|
-
|
|
128
|
+
b,
|
|
124
129
|
{
|
|
125
130
|
onClick: () => e && a.mutate(e),
|
|
126
131
|
disabled: !e || a.isPending || o && !s.trim(),
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { jsx as v } from "react/jsx-runtime";
|
|
2
|
+
import { RotateCcw as N } from "lucide-react";
|
|
3
|
+
import { useState as y, useRef as b, useEffect as R, useCallback as w } from "react";
|
|
4
|
+
import { cn as m } from "../../lib/utils.js";
|
|
5
|
+
const C = 48, P = 800, k = "nvr:catalog-cols:v1:", z = (e, r = C) => Math.round(Math.min(P, Math.max(r, e)));
|
|
6
|
+
function T(e) {
|
|
7
|
+
if (!e) return {};
|
|
8
|
+
try {
|
|
9
|
+
const r = localStorage.getItem(k + e), o = r ? JSON.parse(r) : null;
|
|
10
|
+
if (!o || typeof o != "object") return {};
|
|
11
|
+
const n = {};
|
|
12
|
+
for (const [c, i] of Object.entries(o))
|
|
13
|
+
typeof i == "number" && Number.isFinite(i) && (n[c] = z(i));
|
|
14
|
+
return n;
|
|
15
|
+
} catch {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function x(e, r) {
|
|
20
|
+
if (e)
|
|
21
|
+
try {
|
|
22
|
+
Object.keys(r).length === 0 ? localStorage.removeItem(k + e) : localStorage.setItem(k + e, JSON.stringify(r));
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function j(e) {
|
|
27
|
+
const [r, o] = y(() => T(e)), n = b(e);
|
|
28
|
+
R(() => {
|
|
29
|
+
n.current !== e && (n.current = e, o(T(e)));
|
|
30
|
+
}, [e]);
|
|
31
|
+
const c = b(null), i = b(r);
|
|
32
|
+
i.current = r, R(
|
|
33
|
+
() => () => {
|
|
34
|
+
c.current && (clearTimeout(c.current), x(n.current, i.current));
|
|
35
|
+
},
|
|
36
|
+
[]
|
|
37
|
+
);
|
|
38
|
+
const d = w(
|
|
39
|
+
(a, p, f) => o((s) => {
|
|
40
|
+
const g = { ...s, [a]: z(p, f) };
|
|
41
|
+
c.current && clearTimeout(c.current);
|
|
42
|
+
const t = n.current;
|
|
43
|
+
return c.current = setTimeout(() => {
|
|
44
|
+
c.current = null, x(t, g);
|
|
45
|
+
}, 250), g;
|
|
46
|
+
}),
|
|
47
|
+
[]
|
|
48
|
+
), l = w(() => {
|
|
49
|
+
c.current && clearTimeout(c.current), c.current = null, x(n.current, {}), o({});
|
|
50
|
+
}, []), u = w(
|
|
51
|
+
(a, p, f) => {
|
|
52
|
+
const s = r[a];
|
|
53
|
+
return {
|
|
54
|
+
"data-cpf-col": a,
|
|
55
|
+
// A set width still gives way when the row runs out of room (the card never
|
|
56
|
+
// spills), down to the minimum.
|
|
57
|
+
className: s != null ? m("shrink grow-0", f) : m(p, f),
|
|
58
|
+
style: s != null ? { width: s, minWidth: Math.min(s, C) } : void 0
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
[r]
|
|
62
|
+
);
|
|
63
|
+
return { widths: r, setWidth: d, reset: l, box: u, customized: Object.keys(r).length > 0 };
|
|
64
|
+
}
|
|
65
|
+
function E(e, r) {
|
|
66
|
+
if (!e) return null;
|
|
67
|
+
let o = 0;
|
|
68
|
+
for (const n of e.querySelectorAll(
|
|
69
|
+
`[data-cpf-col="${r.replace(/["\\]/g, "\\$&")}"]`
|
|
70
|
+
)) {
|
|
71
|
+
const c = [...n.querySelectorAll("[data-cpf-fit]")], i = c.length > 0 ? c.reduce((d, l) => d + l.scrollWidth, 0) + (c.length - 1) * 6 : n.scrollWidth;
|
|
72
|
+
o = Math.max(o, i + (n.offsetWidth - n.clientWidth));
|
|
73
|
+
}
|
|
74
|
+
return o > 0 ? z(o + 6) : null;
|
|
75
|
+
}
|
|
76
|
+
function A({
|
|
77
|
+
label: e,
|
|
78
|
+
onResize: r,
|
|
79
|
+
onFit: o,
|
|
80
|
+
min: n = C
|
|
81
|
+
}) {
|
|
82
|
+
const [c, i] = y(!1), [d, l] = y(0), u = b(null), a = (t) => {
|
|
83
|
+
var h;
|
|
84
|
+
return ((h = t.parentElement) == null ? void 0 : h.getBoundingClientRect().width) ?? 0;
|
|
85
|
+
}, p = (t) => {
|
|
86
|
+
t.button === 0 && (t.preventDefault(), t.stopPropagation(), u.current = { x: t.clientX, w: a(t.currentTarget) }, t.currentTarget.setPointerCapture(t.pointerId), document.documentElement.style.cursor = "col-resize", i(!0));
|
|
87
|
+
}, f = (t) => {
|
|
88
|
+
u.current && r(Math.max(n, u.current.w + t.clientX - u.current.x));
|
|
89
|
+
}, s = (t) => {
|
|
90
|
+
u.current && (u.current = null, document.documentElement.style.cursor = "", i(!1), t.currentTarget.hasPointerCapture(t.pointerId) && t.currentTarget.releasePointerCapture(t.pointerId));
|
|
91
|
+
}, g = (t) => {
|
|
92
|
+
const h = t.shiftKey ? 32 : 8;
|
|
93
|
+
if (t.key === "ArrowLeft" || t.key === "ArrowRight") {
|
|
94
|
+
t.preventDefault();
|
|
95
|
+
const S = a(t.currentTarget), M = Math.max(n, S + (t.key === "ArrowRight" ? h : -h));
|
|
96
|
+
l(Math.round(M)), r(M);
|
|
97
|
+
} else t.key === "Enter" && (t.preventDefault(), o());
|
|
98
|
+
};
|
|
99
|
+
return (
|
|
100
|
+
// biome-ignore lint/a11y/useSemanticElements: an interactive splitter has no native element
|
|
101
|
+
/* @__PURE__ */ v(
|
|
102
|
+
"span",
|
|
103
|
+
{
|
|
104
|
+
role: "separator",
|
|
105
|
+
"aria-orientation": "vertical",
|
|
106
|
+
"aria-label": `Resize ${e}`,
|
|
107
|
+
"aria-valuenow": d || void 0,
|
|
108
|
+
"aria-valuemin": n,
|
|
109
|
+
"aria-valuemax": P,
|
|
110
|
+
tabIndex: 0,
|
|
111
|
+
onFocus: (t) => l(Math.round(a(t.currentTarget))),
|
|
112
|
+
"data-cpf-resize": !0,
|
|
113
|
+
"data-tip": `${e}: drag to resize · double-click to fit`,
|
|
114
|
+
onPointerDown: p,
|
|
115
|
+
onPointerMove: f,
|
|
116
|
+
onPointerUp: s,
|
|
117
|
+
onPointerCancel: s,
|
|
118
|
+
onDoubleClick: (t) => {
|
|
119
|
+
t.preventDefault(), o();
|
|
120
|
+
},
|
|
121
|
+
onKeyDown: g,
|
|
122
|
+
onClick: (t) => t.stopPropagation(),
|
|
123
|
+
className: m(
|
|
124
|
+
// Centred in the 16px gap after the cell (rows and headers use gap-4), so the
|
|
125
|
+
// rule sits 8px clear of any label, right-aligned ones (On-Hand, Price) too,
|
|
126
|
+
// and the cell's own width is unchanged.
|
|
127
|
+
"group/resize absolute -top-1 -right-[14px] -bottom-1 z-[1] flex w-3 cursor-col-resize touch-none select-none justify-center rounded-sm focus-visible:bg-nvr-cyan/10 focus-visible:outline-none"
|
|
128
|
+
),
|
|
129
|
+
children: /* @__PURE__ */ v(
|
|
130
|
+
"span",
|
|
131
|
+
{
|
|
132
|
+
className: m(
|
|
133
|
+
"my-1.5 w-px rounded-full transition-colors duration-150 group-focus-visible/resize:w-0.5",
|
|
134
|
+
c ? "bg-nvr-cyan" : (
|
|
135
|
+
// Always a faint rule so the column's edge is visible; stronger on hover.
|
|
136
|
+
"bg-slate-300 group-hover/resize:bg-slate-400 group-focus-visible/resize:bg-nvr-cyan dark:bg-white/10 dark:group-hover/resize:bg-slate-500"
|
|
137
|
+
)
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
)
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
function X({
|
|
146
|
+
show: e,
|
|
147
|
+
onReset: r,
|
|
148
|
+
className: o
|
|
149
|
+
}) {
|
|
150
|
+
return e ? /* @__PURE__ */ v(
|
|
151
|
+
"button",
|
|
152
|
+
{
|
|
153
|
+
type: "button",
|
|
154
|
+
"data-cpf-reset": !0,
|
|
155
|
+
"aria-label": "Reset column widths",
|
|
156
|
+
"data-tip": "Reset column widths",
|
|
157
|
+
onClick: (n) => {
|
|
158
|
+
n.stopPropagation(), r();
|
|
159
|
+
},
|
|
160
|
+
className: m(
|
|
161
|
+
"flex h-5 w-5 shrink-0 items-center justify-center rounded text-slate-500 transition-colors dark:text-slate-400 hover:bg-slate-200/70 hover:text-slate-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan dark:hover:bg-white/10 dark:hover:text-slate-200",
|
|
162
|
+
o
|
|
163
|
+
),
|
|
164
|
+
children: /* @__PURE__ */ v(N, { className: "h-3 w-3" })
|
|
165
|
+
}
|
|
166
|
+
) : null;
|
|
167
|
+
}
|
|
168
|
+
export {
|
|
169
|
+
P as COL_MAX,
|
|
170
|
+
C as COL_MIN,
|
|
171
|
+
A as ColResizeHandle,
|
|
172
|
+
X as ResetColumnsButton,
|
|
173
|
+
E as fitWidth,
|
|
174
|
+
j as useColumnWidths
|
|
175
|
+
};
|