@nivaro/react 0.3.31 → 0.3.33
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/index.d.ts +10 -3
- package/dist/index.js +99 -98
- package/dist/shared/components/ForceReloadBanner.js +56 -46
- package/dist/shared/components/ItemEditForm.js +1985 -1982
- package/dist/shared/components/item-edit/CatalogPickerField.js +1061 -968
- package/dist/shared/components/item-edit/catalog-columns.js +175 -0
- package/dist/shared/lib/unsaved-work.js +86 -38
- package/package.json +1 -1
|
@@ -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
|
+
};
|
|
@@ -1,62 +1,110 @@
|
|
|
1
|
-
import { useEffect as
|
|
2
|
-
import { subscribeRecordOutbox as
|
|
3
|
-
const
|
|
4
|
-
let
|
|
5
|
-
function
|
|
6
|
-
for (const
|
|
1
|
+
import { useRef as d, useEffect as v } from "react";
|
|
2
|
+
import { subscribeRecordOutbox as h, getRecordOutbox as p } from "./record-outbox.js";
|
|
3
|
+
const a = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Set();
|
|
4
|
+
let b = 0;
|
|
5
|
+
function c() {
|
|
6
|
+
for (const t of [...u])
|
|
7
7
|
try {
|
|
8
|
-
|
|
8
|
+
t();
|
|
9
9
|
} catch {
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
const
|
|
14
|
-
return
|
|
15
|
-
|
|
12
|
+
function g(t, n, r = {}) {
|
|
13
|
+
const e = ++b;
|
|
14
|
+
return a.set(e, { label: t, dirty: n, saveForReload: r.saveForReload }), c(), () => {
|
|
15
|
+
a.delete(e) && c();
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
function l() {
|
|
19
19
|
try {
|
|
20
|
-
return
|
|
20
|
+
return p().length;
|
|
21
21
|
} catch {
|
|
22
22
|
return 0;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
function
|
|
26
|
-
const
|
|
27
|
-
for (const
|
|
28
|
-
let
|
|
25
|
+
function m() {
|
|
26
|
+
const t = [];
|
|
27
|
+
for (const r of a.values()) {
|
|
28
|
+
let e = !1;
|
|
29
29
|
try {
|
|
30
|
-
|
|
30
|
+
e = r.dirty();
|
|
31
31
|
} catch {
|
|
32
|
-
|
|
32
|
+
e = !1;
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
e && !t.includes(r.label) && t.push(r.label);
|
|
35
35
|
}
|
|
36
|
-
const
|
|
37
|
-
return
|
|
36
|
+
const n = l();
|
|
37
|
+
return n && t.push(`${n} save${n === 1 ? "" : "s"} waiting to be sent`), t;
|
|
38
38
|
}
|
|
39
|
-
function
|
|
40
|
-
return
|
|
39
|
+
function w() {
|
|
40
|
+
return m().length > 0;
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const t =
|
|
42
|
+
const y = 3e3;
|
|
43
|
+
async function F() {
|
|
44
|
+
const t = await Promise.all(
|
|
45
|
+
[...a.values()].map(async (e) => {
|
|
46
|
+
let o = !1;
|
|
47
|
+
try {
|
|
48
|
+
o = e.dirty();
|
|
49
|
+
} catch {
|
|
50
|
+
o = !1;
|
|
51
|
+
}
|
|
52
|
+
if (!o) return null;
|
|
53
|
+
let s = !1;
|
|
54
|
+
if (e.saveForReload)
|
|
55
|
+
try {
|
|
56
|
+
s = await Promise.race([
|
|
57
|
+
Promise.resolve(e.saveForReload()),
|
|
58
|
+
new Promise((f) => setTimeout(() => f(!1), y))
|
|
59
|
+
]);
|
|
60
|
+
} catch {
|
|
61
|
+
s = !1;
|
|
62
|
+
}
|
|
63
|
+
return s ? null : e.label;
|
|
64
|
+
})
|
|
65
|
+
), n = [...new Set(t.filter((e) => e != null))], r = l();
|
|
66
|
+
return r && n.push(`${r} save${r === 1 ? "" : "s"} waiting to be sent`), n;
|
|
67
|
+
}
|
|
68
|
+
let i = !1;
|
|
69
|
+
function k() {
|
|
70
|
+
i = !0, setTimeout(() => {
|
|
71
|
+
i = !1;
|
|
72
|
+
}, 5e3);
|
|
73
|
+
}
|
|
74
|
+
function O() {
|
|
75
|
+
return i;
|
|
76
|
+
}
|
|
77
|
+
function W(t) {
|
|
78
|
+
u.add(t);
|
|
79
|
+
const n = h(t);
|
|
45
80
|
return () => {
|
|
46
|
-
|
|
81
|
+
u.delete(t), n();
|
|
47
82
|
};
|
|
48
83
|
}
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
84
|
+
function x(t, n = "Unsaved changes", r) {
|
|
85
|
+
const e = d(r);
|
|
86
|
+
e.current = r;
|
|
87
|
+
const o = !!r;
|
|
88
|
+
v(() => {
|
|
89
|
+
if (t)
|
|
90
|
+
return g(
|
|
91
|
+
n,
|
|
92
|
+
() => !0,
|
|
93
|
+
o ? { saveForReload: () => {
|
|
94
|
+
var s;
|
|
95
|
+
return ((s = e.current) == null ? void 0 : s.call(e)) ?? !1;
|
|
96
|
+
} } : {}
|
|
97
|
+
);
|
|
98
|
+
}, [t, n, o]);
|
|
54
99
|
}
|
|
55
100
|
export {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
101
|
+
k as beginReloadForUpdate,
|
|
102
|
+
w as hasUnsavedWork,
|
|
103
|
+
O as isReloadingForUpdate,
|
|
104
|
+
c as notifyUnsavedWorkChanged,
|
|
105
|
+
F as prepareForReload,
|
|
106
|
+
g as registerUnsavedWork,
|
|
107
|
+
W as subscribeUnsavedWork,
|
|
108
|
+
m as unsavedWorkLabels,
|
|
109
|
+
x as useUnsavedWork
|
|
62
110
|
};
|