@object-ui/plugin-aggrid 3.3.2 → 4.0.1
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/CHANGELOG.md +37 -0
- package/dist/{AvatarField-CpFxJRdO.js → AvatarField-DuaF__ns.js} +2 -2
- package/dist/FileField-DtvoWRK-.js +214 -0
- package/dist/{GeolocationField-BfhC7QLw.js → GeolocationField-CyzG2dqR.js} +1 -1
- package/dist/ImageCropperDialog-BFlbM7vO.js +153 -0
- package/dist/ImageField-DoXNtXV_.js +145 -0
- package/dist/LookupField-DXGCnQ3q.js +1063 -0
- package/dist/{MasterDetailField-DGUmvg2f.js → MasterDetailField-JpmMudRV.js} +3 -3
- package/dist/{ObjectAgGridImpl-yiHlXYgp.js → ObjectAgGridImpl-Bz5whFec.js} +110 -108
- package/dist/{PasswordField-BJboeBJY.js → PasswordField-40E439oE.js} +1 -1
- package/dist/{QRCodeField-COLyc5iQ.js → QRCodeField-CrRsA1vB.js} +1 -1
- package/dist/{RatingField-B2momIna.js → RatingField-BVkroiQ4.js} +1 -1
- package/dist/{SelectField-oo6vnNhQ.js → SelectField-K-xoVDss.js} +1 -1
- package/dist/{SignatureField-DUgoK09r.js → SignatureField-D0nUx3Cb.js} +1 -1
- package/dist/TextAreaField-j4eJQ66C.js +125 -0
- package/dist/{UserField-eT5njHwQ.js → UserField-LrhYdvnz.js} +1 -1
- package/dist/check-CBAnx5TO.js +7 -0
- package/dist/{createLucideIcon-C_5JZ35b.js → createLucideIcon-BtZxPlua.js} +1 -1
- package/dist/crop-2wjrXKXD.js +10 -0
- package/dist/dist-BcXWTU-8.js +54 -0
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +79 -79
- package/dist/loader-circle-Cxg-xF4u.js +7 -0
- package/dist/{plus-bvZ2f9T_.js → plus-COkdZ2Fh.js} +1 -1
- package/dist/{upload-BdzwEMeV.js → upload-DWhfIa3Y.js} +1 -1
- package/dist/{x-98xe-fYG.js → x-BDi_yYx9.js} +1 -1
- package/package.json +8 -8
- package/dist/FileField-D3mZIrJ1.js +0 -158
- package/dist/ImageField-BZfSFwmJ.js +0 -75
- package/dist/LookupField-Cms1Cu_l.js +0 -1032
- package/dist/TextAreaField-CLzzmPce.js +0 -37
- package/dist/image-DmzU2ETO.js +0 -24
- /package/dist/{AgGridImpl-DJWnS8p3.js → AgGridImpl-DiTsK8F6.js} +0 -0
- /package/dist/{BooleanField-Chphr8cB.js → BooleanField-0QUz5DOy.js} +0 -0
- /package/dist/{CodeField-BWngVIw1.js → CodeField-iTabv7wS.js} +0 -0
- /package/dist/{ColorField-GygyYArR.js → ColorField-R7ZmLj1V.js} +0 -0
- /package/dist/{CurrencyField-O8Pn59RO.js → CurrencyField-CEu2SjEj.js} +0 -0
- /package/dist/{DateField-u6U8wmvI.js → DateField-DoaPu9GV.js} +0 -0
- /package/dist/{DateTimeField-D1z1Ovvy.js → DateTimeField-DcKX54zr.js} +0 -0
- /package/dist/{EmailField-IOcDmGjJ.js → EmailField-eYfpFAtE.js} +0 -0
- /package/dist/{FormulaField-MuyWzQx0.js → FormulaField-DF6-4u2b.js} +0 -0
- /package/dist/{GridField-gN34gk4b.js → GridField-BFlgbp8W.js} +0 -0
- /package/dist/{LocationField-B-zwfw3h.js → LocationField-BeYK6K9V.js} +0 -0
- /package/dist/{NumberField-BV5sKwZ7.js → NumberField-BYuCxbmU.js} +0 -0
- /package/dist/{ObjectField-DJ5s3ciA.js → ObjectField-Dlf_yrMC.js} +0 -0
- /package/dist/{PercentField-DO3be_bL.js → PercentField-BvdQEcfn.js} +0 -0
- /package/dist/{PhoneField-CT6XcO6O.js → PhoneField-CBuoC-vs.js} +0 -0
- /package/dist/{RichTextField-C7qzDPJy.js → RichTextField-DEYNcokk.js} +0 -0
- /package/dist/{SliderField-DrggtBSX.js → SliderField-C2EpGbj8.js} +0 -0
- /package/dist/{SummaryField-DuMsFoY5.js → SummaryField-S6Gt7IDC.js} +0 -0
- /package/dist/{TextField-CZE7SzK4.js → TextField-DccUZtd7.js} +0 -0
- /package/dist/{TimeField-Bha4cayv.js → TimeField-CWbpycPt.js} +0 -0
- /package/dist/{UrlField-Dff4WLlN.js → UrlField-BkPyImh9.js} +0 -0
- /package/dist/{VectorField-BHe8lDOH.js → VectorField-Baa_mHsO.js} +0 -0
- /package/dist/{useFieldTranslation-CfXaJRC4.js → useFieldTranslation-DtLNhrx3.js} +0 -0
|
@@ -0,0 +1,1063 @@
|
|
|
1
|
+
import { n as e } from "./rolldown-runtime-CkxV0rQ3.js";
|
|
2
|
+
import { t } from "./jsx-runtime-CXSCp6pT.js";
|
|
3
|
+
import { t as n } from "./createLucideIcon-BtZxPlua.js";
|
|
4
|
+
import { t as r } from "./check-CBAnx5TO.js";
|
|
5
|
+
import { t as i } from "./loader-circle-Cxg-xF4u.js";
|
|
6
|
+
import { t as a } from "./plus-COkdZ2Fh.js";
|
|
7
|
+
import { t as o } from "./x-BDi_yYx9.js";
|
|
8
|
+
import { t as ee } from "./useFieldTranslation-DtLNhrx3.js";
|
|
9
|
+
import { useCallback as s, useContext as te, useEffect as c, useMemo as l, useRef as ne, useState as u } from "react";
|
|
10
|
+
import { Badge as d, Button as f, Checkbox as p, Dialog as m, DialogContent as h, DialogFooter as g, DialogHeader as re, DialogTitle as ie, EmptyValue as ae, Input as oe, Label as _, Popover as se, PopoverContent as ce, PopoverTrigger as v, Select as le, SelectContent as ue, SelectItem as de, SelectTrigger as fe, SelectValue as pe, Skeleton as y, Table as me, TableBody as b, TableCell as he, TableHead as ge, TableHeader as x, TableRow as S, cn as _e } from "@object-ui/components";
|
|
11
|
+
import { SchemaRendererContext as C } from "@object-ui/react";
|
|
12
|
+
var w = n("arrow-down", [["path", {
|
|
13
|
+
d: "M12 5v14",
|
|
14
|
+
key: "s699le"
|
|
15
|
+
}], ["path", {
|
|
16
|
+
d: "m19 12-7 7-7-7",
|
|
17
|
+
key: "1idqje"
|
|
18
|
+
}]]), T = n("arrow-up-down", [
|
|
19
|
+
["path", {
|
|
20
|
+
d: "m21 16-4 4-4-4",
|
|
21
|
+
key: "f6ql7i"
|
|
22
|
+
}],
|
|
23
|
+
["path", {
|
|
24
|
+
d: "M17 20V4",
|
|
25
|
+
key: "1ejh1v"
|
|
26
|
+
}],
|
|
27
|
+
["path", {
|
|
28
|
+
d: "m3 8 4-4 4 4",
|
|
29
|
+
key: "11wl7u"
|
|
30
|
+
}],
|
|
31
|
+
["path", {
|
|
32
|
+
d: "M7 4v16",
|
|
33
|
+
key: "1glfcx"
|
|
34
|
+
}]
|
|
35
|
+
]), ve = n("arrow-up", [["path", {
|
|
36
|
+
d: "m5 12 7-7 7 7",
|
|
37
|
+
key: "hav0vg"
|
|
38
|
+
}], ["path", {
|
|
39
|
+
d: "M12 19V5",
|
|
40
|
+
key: "x0mq9r"
|
|
41
|
+
}]]), E = n("chevron-left", [["path", {
|
|
42
|
+
d: "m15 18-6-6 6-6",
|
|
43
|
+
key: "1wnfg3"
|
|
44
|
+
}]]), D = n("chevron-right", [["path", {
|
|
45
|
+
d: "m9 18 6-6-6-6",
|
|
46
|
+
key: "mthhwq"
|
|
47
|
+
}]]), ye = n("circle-alert", [
|
|
48
|
+
["circle", {
|
|
49
|
+
cx: "12",
|
|
50
|
+
cy: "12",
|
|
51
|
+
r: "10",
|
|
52
|
+
key: "1mglay"
|
|
53
|
+
}],
|
|
54
|
+
["line", {
|
|
55
|
+
x1: "12",
|
|
56
|
+
x2: "12",
|
|
57
|
+
y1: "8",
|
|
58
|
+
y2: "12",
|
|
59
|
+
key: "1pkeuh"
|
|
60
|
+
}],
|
|
61
|
+
["line", {
|
|
62
|
+
x1: "12",
|
|
63
|
+
x2: "12.01",
|
|
64
|
+
y1: "16",
|
|
65
|
+
y2: "16",
|
|
66
|
+
key: "4dfq90"
|
|
67
|
+
}]
|
|
68
|
+
]), be = n("search", [["path", {
|
|
69
|
+
d: "m21 21-4.34-4.34",
|
|
70
|
+
key: "14j7rj"
|
|
71
|
+
}], ["circle", {
|
|
72
|
+
cx: "11",
|
|
73
|
+
cy: "11",
|
|
74
|
+
r: "8",
|
|
75
|
+
key: "4ej97u"
|
|
76
|
+
}]]), xe = n("sliders-horizontal", [
|
|
77
|
+
["path", {
|
|
78
|
+
d: "M10 5H3",
|
|
79
|
+
key: "1qgfaw"
|
|
80
|
+
}],
|
|
81
|
+
["path", {
|
|
82
|
+
d: "M12 19H3",
|
|
83
|
+
key: "yhmn1j"
|
|
84
|
+
}],
|
|
85
|
+
["path", {
|
|
86
|
+
d: "M14 3v4",
|
|
87
|
+
key: "1sua03"
|
|
88
|
+
}],
|
|
89
|
+
["path", {
|
|
90
|
+
d: "M16 17v4",
|
|
91
|
+
key: "1q0r14"
|
|
92
|
+
}],
|
|
93
|
+
["path", {
|
|
94
|
+
d: "M21 12h-9",
|
|
95
|
+
key: "1o4lsq"
|
|
96
|
+
}],
|
|
97
|
+
["path", {
|
|
98
|
+
d: "M21 19h-5",
|
|
99
|
+
key: "1rlt1p"
|
|
100
|
+
}],
|
|
101
|
+
["path", {
|
|
102
|
+
d: "M21 5h-7",
|
|
103
|
+
key: "1oszz2"
|
|
104
|
+
}],
|
|
105
|
+
["path", {
|
|
106
|
+
d: "M8 10v4",
|
|
107
|
+
key: "tgpxqk"
|
|
108
|
+
}],
|
|
109
|
+
["path", {
|
|
110
|
+
d: "M8 12H3",
|
|
111
|
+
key: "a7s4jb"
|
|
112
|
+
}]
|
|
113
|
+
]), O = n("table-properties", [
|
|
114
|
+
["path", {
|
|
115
|
+
d: "M15 3v18",
|
|
116
|
+
key: "14nvp0"
|
|
117
|
+
}],
|
|
118
|
+
["rect", {
|
|
119
|
+
width: "18",
|
|
120
|
+
height: "18",
|
|
121
|
+
x: "3",
|
|
122
|
+
y: "3",
|
|
123
|
+
rx: "2",
|
|
124
|
+
key: "afitv7"
|
|
125
|
+
}],
|
|
126
|
+
["path", {
|
|
127
|
+
d: "M21 9H3",
|
|
128
|
+
key: "1338ky"
|
|
129
|
+
}],
|
|
130
|
+
["path", {
|
|
131
|
+
d: "M21 15H3",
|
|
132
|
+
key: "9uk58r"
|
|
133
|
+
}]
|
|
134
|
+
]), k = t(), Se = 10, A = 60, Ce = 5;
|
|
135
|
+
function we(e) {
|
|
136
|
+
return typeof e == "string" ? { field: e } : e;
|
|
137
|
+
}
|
|
138
|
+
function Te(e) {
|
|
139
|
+
return e.replace(/_/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").replace(/\b\w/g, (e) => e.toUpperCase());
|
|
140
|
+
}
|
|
141
|
+
function j(e) {
|
|
142
|
+
let t = {};
|
|
143
|
+
for (let n of e) switch (n.operator) {
|
|
144
|
+
case "eq":
|
|
145
|
+
t[n.field] = n.value;
|
|
146
|
+
break;
|
|
147
|
+
case "ne":
|
|
148
|
+
t[n.field] = { $ne: n.value };
|
|
149
|
+
break;
|
|
150
|
+
case "gt":
|
|
151
|
+
t[n.field] = { $gt: n.value };
|
|
152
|
+
break;
|
|
153
|
+
case "lt":
|
|
154
|
+
t[n.field] = { $lt: n.value };
|
|
155
|
+
break;
|
|
156
|
+
case "gte":
|
|
157
|
+
t[n.field] = { $gte: n.value };
|
|
158
|
+
break;
|
|
159
|
+
case "lte":
|
|
160
|
+
t[n.field] = { $lte: n.value };
|
|
161
|
+
break;
|
|
162
|
+
case "contains":
|
|
163
|
+
t[n.field] = { $contains: n.value };
|
|
164
|
+
break;
|
|
165
|
+
case "in":
|
|
166
|
+
t[n.field] = { $in: n.value };
|
|
167
|
+
break;
|
|
168
|
+
case "notIn":
|
|
169
|
+
t[n.field] = { $nin: n.value };
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
return t;
|
|
173
|
+
}
|
|
174
|
+
function Ee(e, t) {
|
|
175
|
+
let n = {};
|
|
176
|
+
for (let r of t) {
|
|
177
|
+
let t = e[r.field];
|
|
178
|
+
t == null || t === "" || (r.type === "boolean" ? n[r.field] = !!t : r.type === "text" ? n[r.field] = { $contains: t } : n[r.field] = t);
|
|
179
|
+
}
|
|
180
|
+
return n;
|
|
181
|
+
}
|
|
182
|
+
function M({ open: e, onOpenChange: t, title: n = "Select Record", multiple: a = !1, dataSource: ee, objectName: te, columns: d, displayField: ae = "name", idField: se = "id", pageSize: ce = Se, value: v, onSelect: C, onSelectRecords: O, lookupFilters: M, cellRenderer: N, filterColumns: P, renderFilterBar: De, renderGrid: Oe }) {
|
|
183
|
+
let [F, ke] = u([]), [I, Ae] = u(!1), [L, R] = u(null), [z, B] = u(0), [V, je] = u(""), [H, U] = u(1), W = ne(null), [G, Me] = u(null), [K, q] = u("asc"), [J, Ne] = u(/* @__PURE__ */ new Set()), Pe = ne(/* @__PURE__ */ new Map()), [Y, Fe] = u(-1), Ie = ne(null), [Le, Re] = u(!1), [X, ze] = u({}), [Be, Ve] = u({}), He = ne(null), [Ue, We] = u(""), Ge = l(() => d && d.length > 0 ? d.map(we) : [{
|
|
184
|
+
field: ae,
|
|
185
|
+
label: Te(ae)
|
|
186
|
+
}], [d, ae]), Z = l(() => {
|
|
187
|
+
if (P && P.length > 0) return P;
|
|
188
|
+
if (M && M.length > 0) return M.map((e) => {
|
|
189
|
+
let t = "text";
|
|
190
|
+
return typeof e.value == "boolean" ? t = "boolean" : Array.isArray(e.value) ? t = "select" : typeof e.value == "number" || e.operator === "gt" || e.operator === "lt" || e.operator === "gte" || e.operator === "lte" ? t = "number" : (e.operator === "in" || e.operator === "notIn") && (t = "select"), {
|
|
191
|
+
field: e.field,
|
|
192
|
+
label: Te(e.field),
|
|
193
|
+
type: t,
|
|
194
|
+
...Array.isArray(e.value) ? { options: e.value.map((e) => {
|
|
195
|
+
if (typeof e == "object" && e) {
|
|
196
|
+
let t = e;
|
|
197
|
+
return {
|
|
198
|
+
label: String(t.name || t.label || t.title || e),
|
|
199
|
+
value: e
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
label: String(e),
|
|
204
|
+
value: e
|
|
205
|
+
};
|
|
206
|
+
}) } : {}
|
|
207
|
+
};
|
|
208
|
+
});
|
|
209
|
+
}, [P, M]), Ke = l(() => {
|
|
210
|
+
let e = M?.length ? j(M) : {}, t = Z?.length ? Ee(X, Z) : {}, n = {
|
|
211
|
+
...e,
|
|
212
|
+
...t
|
|
213
|
+
};
|
|
214
|
+
return Object.keys(n).length > 0 ? n : void 0;
|
|
215
|
+
}, [
|
|
216
|
+
M,
|
|
217
|
+
Z,
|
|
218
|
+
X
|
|
219
|
+
]), Q = Math.max(1, Math.ceil(z / ce)), qe = s(async (e, t = 1, n, r) => {
|
|
220
|
+
if (!(!ee || !te)) {
|
|
221
|
+
Ae(!0), R(null);
|
|
222
|
+
try {
|
|
223
|
+
let i = {
|
|
224
|
+
$top: ce,
|
|
225
|
+
$skip: (t - 1) * ce
|
|
226
|
+
};
|
|
227
|
+
e && e.trim() && (i.$search = e.trim()), n && (i.$orderby = { [n.field]: n.direction });
|
|
228
|
+
let a = r === void 0 ? Ke : r;
|
|
229
|
+
a && Object.keys(a).length > 0 && (i.$filter = a);
|
|
230
|
+
let o = await ee.find(te, i), s = o?.data ?? o ?? [];
|
|
231
|
+
ke(s), B(o?.total ?? s.length), Fe(-1);
|
|
232
|
+
} catch (e) {
|
|
233
|
+
R(e instanceof Error ? e.message : String(e)), ke([]);
|
|
234
|
+
} finally {
|
|
235
|
+
Ae(!1);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}, [
|
|
239
|
+
ee,
|
|
240
|
+
te,
|
|
241
|
+
ce,
|
|
242
|
+
Ke
|
|
243
|
+
]), Je = l(() => G ? {
|
|
244
|
+
field: G,
|
|
245
|
+
direction: K
|
|
246
|
+
} : null, [G, K]);
|
|
247
|
+
c(() => {
|
|
248
|
+
e || (je(""), U(1), R(null), ke([]), Me(null), q("asc"), Fe(-1), Re(!1), ze({}), Ve({}), We(""), Ne(new Set(a && Array.isArray(v) ? v : [])), Pe.current.clear());
|
|
249
|
+
}, [e]), c(() => {
|
|
250
|
+
e && qe(V || void 0, H, Je);
|
|
251
|
+
}, [
|
|
252
|
+
e,
|
|
253
|
+
H,
|
|
254
|
+
Je,
|
|
255
|
+
Ke
|
|
256
|
+
]), c(() => {
|
|
257
|
+
e && a && Ne(new Set(Array.isArray(v) ? v : []));
|
|
258
|
+
}, [
|
|
259
|
+
e,
|
|
260
|
+
a,
|
|
261
|
+
v
|
|
262
|
+
]);
|
|
263
|
+
let Ye = s((e) => {
|
|
264
|
+
je(e), U(1), W.current && clearTimeout(W.current), W.current = setTimeout(() => {
|
|
265
|
+
qe(e || void 0, 1, Je);
|
|
266
|
+
}, 300);
|
|
267
|
+
}, [qe, Je]);
|
|
268
|
+
c(() => () => {
|
|
269
|
+
W.current && clearTimeout(W.current);
|
|
270
|
+
}, []);
|
|
271
|
+
let Xe = s((e) => {
|
|
272
|
+
Me((t) => t === e ? (q((e) => e === "asc" ? "desc" : "asc"), e) : (q("asc"), e)), U(1);
|
|
273
|
+
}, []), Ze = s((e) => e[se] ?? e.id ?? e._id, [se]), Qe = s((e) => {
|
|
274
|
+
let t = Ze(e);
|
|
275
|
+
return a ? J.has(t) : v === t;
|
|
276
|
+
}, [
|
|
277
|
+
a,
|
|
278
|
+
v,
|
|
279
|
+
J,
|
|
280
|
+
Ze
|
|
281
|
+
]), $e = s((e) => {
|
|
282
|
+
let n = Ze(e);
|
|
283
|
+
a ? Ne((t) => {
|
|
284
|
+
let r = new Set(t);
|
|
285
|
+
return r.has(n) ? (r.delete(n), Pe.current.delete(n)) : (r.add(n), Pe.current.set(n, e)), r;
|
|
286
|
+
}) : (C(n), O?.([e]), t(!1));
|
|
287
|
+
}, [
|
|
288
|
+
a,
|
|
289
|
+
Ze,
|
|
290
|
+
C,
|
|
291
|
+
O,
|
|
292
|
+
t
|
|
293
|
+
]), et = s(() => {
|
|
294
|
+
let e = Array.from(J);
|
|
295
|
+
C(e);
|
|
296
|
+
let n = e.map((e) => Pe.current.get(e)).filter(Boolean);
|
|
297
|
+
O?.(n), t(!1);
|
|
298
|
+
}, [
|
|
299
|
+
J,
|
|
300
|
+
C,
|
|
301
|
+
O,
|
|
302
|
+
t
|
|
303
|
+
]), tt = s(() => {
|
|
304
|
+
U((e) => Math.max(1, e - 1));
|
|
305
|
+
}, []), nt = s(() => {
|
|
306
|
+
U((e) => Math.min(Q, e + 1));
|
|
307
|
+
}, [Q]), rt = s((e) => {
|
|
308
|
+
if (e.key !== "Enter") return;
|
|
309
|
+
let t = parseInt(Ue, 10);
|
|
310
|
+
!isNaN(t) && t >= 1 && t <= Q && U(t), We("");
|
|
311
|
+
}, [Ue, Q]), it = s((e) => {
|
|
312
|
+
F.length !== 0 && (e.key === "ArrowDown" ? (e.preventDefault(), Fe((e) => Math.min(e + 1, F.length - 1))) : e.key === "ArrowUp" ? (e.preventDefault(), Fe((e) => Math.max(e - 1, 0))) : (e.key === "Enter" || e.key === " ") && (e.preventDefault(), Y >= 0 && Y < F.length && $e(F[Y])));
|
|
313
|
+
}, [
|
|
314
|
+
F,
|
|
315
|
+
Y,
|
|
316
|
+
$e
|
|
317
|
+
]);
|
|
318
|
+
c(() => {
|
|
319
|
+
if (Y >= 0 && Ie.current) {
|
|
320
|
+
let e = Ie.current.querySelector(`[data-row-index="${Y}"]`);
|
|
321
|
+
e && typeof e.scrollIntoView == "function" && e.scrollIntoView({ block: "nearest" });
|
|
322
|
+
}
|
|
323
|
+
}, [Y]);
|
|
324
|
+
let at = s((e, t) => {
|
|
325
|
+
let n = e[t.field];
|
|
326
|
+
if (t.type && N) {
|
|
327
|
+
let e = N(t.type);
|
|
328
|
+
if (e) return /* @__PURE__ */ (0, k.jsx)(e, {
|
|
329
|
+
value: n,
|
|
330
|
+
field: {
|
|
331
|
+
name: t.field,
|
|
332
|
+
type: t.type
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
return n == null ? "" : typeof n == "object" ? n.$numberDecimal ? String(Number(n.$numberDecimal)) : n.$oid ? String(n.$oid) : n.$date ? new Date(n.$date).toLocaleDateString() : n.name || n.label ? String(n.name || n.label) : JSON.stringify(n) : typeof n == "boolean" ? n ? "Yes" : "No" : String(n);
|
|
337
|
+
}, [N]), ot = s((e) => G === e ? K === "asc" ? /* @__PURE__ */ (0, k.jsx)(ve, { className: "ml-1 size-3" }) : /* @__PURE__ */ (0, k.jsx)(w, { className: "ml-1 size-3" }) : /* @__PURE__ */ (0, k.jsx)(T, { className: "ml-1 size-3 opacity-40" }), [G, K]), st = s((e, t, n) => {
|
|
338
|
+
e.preventDefault(), e.stopPropagation(), He.current = {
|
|
339
|
+
field: t,
|
|
340
|
+
startX: e.clientX,
|
|
341
|
+
startWidth: n
|
|
342
|
+
};
|
|
343
|
+
let r = (e) => {
|
|
344
|
+
if (!He.current) return;
|
|
345
|
+
let t = e.clientX - He.current.startX, n = Math.max(A, He.current.startWidth + t);
|
|
346
|
+
Ve((e) => ({
|
|
347
|
+
...e,
|
|
348
|
+
[He.current.field]: n
|
|
349
|
+
}));
|
|
350
|
+
}, i = () => {
|
|
351
|
+
He.current = null, document.removeEventListener("mousemove", r), document.removeEventListener("mouseup", i);
|
|
352
|
+
};
|
|
353
|
+
document.addEventListener("mousemove", r), document.addEventListener("mouseup", i);
|
|
354
|
+
}, []), $ = s((e, t) => {
|
|
355
|
+
ze((n) => ({
|
|
356
|
+
...n,
|
|
357
|
+
[e]: t
|
|
358
|
+
})), U(1);
|
|
359
|
+
}, []), ct = s(() => {
|
|
360
|
+
ze({}), U(1);
|
|
361
|
+
}, []), lt = l(() => Object.values(X).filter((e) => e != null && e !== "").length, [X]), ut = s((e) => {
|
|
362
|
+
let t = X[e.field], n = e.label || Te(e.field);
|
|
363
|
+
switch (e.type) {
|
|
364
|
+
case "select": return /* @__PURE__ */ (0, k.jsxs)("div", {
|
|
365
|
+
className: "space-y-1",
|
|
366
|
+
children: [/* @__PURE__ */ (0, k.jsx)(_, {
|
|
367
|
+
className: "text-xs text-muted-foreground",
|
|
368
|
+
children: n
|
|
369
|
+
}), /* @__PURE__ */ (0, k.jsxs)(le, {
|
|
370
|
+
value: t == null ? "" : String(t),
|
|
371
|
+
onValueChange: (t) => $(e.field, t),
|
|
372
|
+
children: [/* @__PURE__ */ (0, k.jsx)(fe, {
|
|
373
|
+
className: "h-8 text-xs",
|
|
374
|
+
children: /* @__PURE__ */ (0, k.jsx)(pe, { placeholder: `Filter ${n}` })
|
|
375
|
+
}), /* @__PURE__ */ (0, k.jsx)(ue, { children: e.options?.map((e) => /* @__PURE__ */ (0, k.jsx)(de, {
|
|
376
|
+
value: String(e.value),
|
|
377
|
+
children: e.label
|
|
378
|
+
}, String(e.value))) })]
|
|
379
|
+
})]
|
|
380
|
+
});
|
|
381
|
+
case "number": return /* @__PURE__ */ (0, k.jsxs)("div", {
|
|
382
|
+
className: "space-y-1",
|
|
383
|
+
children: [/* @__PURE__ */ (0, k.jsx)(_, {
|
|
384
|
+
className: "text-xs text-muted-foreground",
|
|
385
|
+
children: n
|
|
386
|
+
}), /* @__PURE__ */ (0, k.jsx)(oe, {
|
|
387
|
+
type: "number",
|
|
388
|
+
className: "h-8 text-xs",
|
|
389
|
+
value: t ?? "",
|
|
390
|
+
placeholder: `Filter ${n}`,
|
|
391
|
+
onChange: (t) => {
|
|
392
|
+
let n = t.target.value;
|
|
393
|
+
$(e.field, n === "" ? "" : Number(n));
|
|
394
|
+
}
|
|
395
|
+
})]
|
|
396
|
+
});
|
|
397
|
+
case "date": return /* @__PURE__ */ (0, k.jsxs)("div", {
|
|
398
|
+
className: "space-y-1",
|
|
399
|
+
children: [/* @__PURE__ */ (0, k.jsx)(_, {
|
|
400
|
+
className: "text-xs text-muted-foreground",
|
|
401
|
+
children: n
|
|
402
|
+
}), /* @__PURE__ */ (0, k.jsx)(oe, {
|
|
403
|
+
type: "date",
|
|
404
|
+
className: "h-8 text-xs",
|
|
405
|
+
value: t ?? "",
|
|
406
|
+
onChange: (t) => $(e.field, t.target.value)
|
|
407
|
+
})]
|
|
408
|
+
});
|
|
409
|
+
case "boolean": return /* @__PURE__ */ (0, k.jsxs)("div", {
|
|
410
|
+
className: "space-y-1",
|
|
411
|
+
children: [/* @__PURE__ */ (0, k.jsx)(_, {
|
|
412
|
+
className: "text-xs text-muted-foreground",
|
|
413
|
+
children: n
|
|
414
|
+
}), /* @__PURE__ */ (0, k.jsxs)("div", {
|
|
415
|
+
className: "flex items-center gap-2 h-8",
|
|
416
|
+
children: [/* @__PURE__ */ (0, k.jsx)(p, {
|
|
417
|
+
checked: !!t,
|
|
418
|
+
onCheckedChange: (t) => $(e.field, !!t)
|
|
419
|
+
}), /* @__PURE__ */ (0, k.jsx)("span", {
|
|
420
|
+
className: "text-xs text-muted-foreground",
|
|
421
|
+
children: "Yes"
|
|
422
|
+
})]
|
|
423
|
+
})]
|
|
424
|
+
});
|
|
425
|
+
default: return /* @__PURE__ */ (0, k.jsxs)("div", {
|
|
426
|
+
className: "space-y-1",
|
|
427
|
+
children: [/* @__PURE__ */ (0, k.jsx)(_, {
|
|
428
|
+
className: "text-xs text-muted-foreground",
|
|
429
|
+
children: n
|
|
430
|
+
}), /* @__PURE__ */ (0, k.jsx)(oe, {
|
|
431
|
+
className: "h-8 text-xs",
|
|
432
|
+
value: t ?? "",
|
|
433
|
+
placeholder: `Filter ${n}`,
|
|
434
|
+
onChange: (t) => $(e.field, t.target.value)
|
|
435
|
+
})]
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
}, [X, $]), dt = s((e, t) => e ? "bg-primary/5 hover:bg-primary/10" : t % 2 == 1 ? "bg-muted/20 hover:bg-accent/30" : "hover:bg-accent/30", []);
|
|
439
|
+
return /* @__PURE__ */ (0, k.jsx)(m, {
|
|
440
|
+
open: e,
|
|
441
|
+
onOpenChange: t,
|
|
442
|
+
children: /* @__PURE__ */ (0, k.jsxs)(h, {
|
|
443
|
+
className: "w-[95vw] sm:max-w-3xl lg:max-w-5xl max-h-[85vh] sm:max-h-[80vh] flex flex-col gap-0",
|
|
444
|
+
"data-testid": "record-picker-dialog",
|
|
445
|
+
children: [
|
|
446
|
+
/* @__PURE__ */ (0, k.jsx)(re, { children: /* @__PURE__ */ (0, k.jsxs)(ie, { children: [n, a && /* @__PURE__ */ (0, k.jsx)("span", {
|
|
447
|
+
className: "sr-only",
|
|
448
|
+
children: " (multiple selection)"
|
|
449
|
+
})] }) }),
|
|
450
|
+
/* @__PURE__ */ (0, k.jsxs)("div", {
|
|
451
|
+
className: "relative rounded-md border bg-muted/30 mb-3",
|
|
452
|
+
children: [
|
|
453
|
+
/* @__PURE__ */ (0, k.jsx)(be, { className: "absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground" }),
|
|
454
|
+
/* @__PURE__ */ (0, k.jsx)(oe, {
|
|
455
|
+
placeholder: "Search...",
|
|
456
|
+
value: V,
|
|
457
|
+
onChange: (e) => Ye(e.target.value),
|
|
458
|
+
className: "pl-9 border-0 bg-transparent shadow-none focus-visible:ring-0",
|
|
459
|
+
"data-testid": "record-picker-search"
|
|
460
|
+
}),
|
|
461
|
+
I && /* @__PURE__ */ (0, k.jsx)(i, {
|
|
462
|
+
className: "absolute right-3 top-1/2 -translate-y-1/2 size-4 animate-spin text-muted-foreground",
|
|
463
|
+
"data-testid": "record-picker-loading-indicator"
|
|
464
|
+
})
|
|
465
|
+
]
|
|
466
|
+
}),
|
|
467
|
+
Z && Z.length > 0 && /* @__PURE__ */ (0, k.jsx)("div", {
|
|
468
|
+
className: "py-2",
|
|
469
|
+
children: De ? /* @__PURE__ */ (0, k.jsx)("div", {
|
|
470
|
+
"data-testid": "record-picker-filter-bar",
|
|
471
|
+
children: De({
|
|
472
|
+
filterColumns: Z,
|
|
473
|
+
values: X,
|
|
474
|
+
onChange: $,
|
|
475
|
+
onClear: ct,
|
|
476
|
+
activeCount: lt
|
|
477
|
+
})
|
|
478
|
+
}) : /* @__PURE__ */ (0, k.jsxs)(k.Fragment, { children: [/* @__PURE__ */ (0, k.jsxs)("div", {
|
|
479
|
+
className: "flex items-center gap-2",
|
|
480
|
+
"data-testid": "record-picker-filter-bar",
|
|
481
|
+
children: [/* @__PURE__ */ (0, k.jsxs)(f, {
|
|
482
|
+
type: "button",
|
|
483
|
+
variant: lt > 0 ? "secondary" : "outline",
|
|
484
|
+
size: "sm",
|
|
485
|
+
className: "gap-1.5 shrink-0",
|
|
486
|
+
onClick: () => Re((e) => !e),
|
|
487
|
+
children: [
|
|
488
|
+
/* @__PURE__ */ (0, k.jsx)(xe, { className: "size-3.5" }),
|
|
489
|
+
"Filters",
|
|
490
|
+
lt > 0 && /* @__PURE__ */ (0, k.jsx)("span", {
|
|
491
|
+
className: "inline-flex h-5 min-w-[20px] items-center justify-center rounded-full bg-primary/10 px-1 text-xs font-medium text-primary",
|
|
492
|
+
children: lt
|
|
493
|
+
})
|
|
494
|
+
]
|
|
495
|
+
}), lt > 0 && /* @__PURE__ */ (0, k.jsxs)(f, {
|
|
496
|
+
type: "button",
|
|
497
|
+
variant: "ghost",
|
|
498
|
+
size: "sm",
|
|
499
|
+
className: "gap-1 text-xs",
|
|
500
|
+
onClick: ct,
|
|
501
|
+
children: [/* @__PURE__ */ (0, k.jsx)(o, { className: "size-3" }), "Clear"]
|
|
502
|
+
})]
|
|
503
|
+
}), Le && /* @__PURE__ */ (0, k.jsx)("div", {
|
|
504
|
+
className: "mt-2 grid gap-3 sm:grid-cols-2 lg:grid-cols-3 border rounded-md p-3 bg-muted/30",
|
|
505
|
+
"data-testid": "record-picker-filter-panel",
|
|
506
|
+
children: Z.map((e) => /* @__PURE__ */ (0, k.jsx)("div", { children: ut(e) }, e.field))
|
|
507
|
+
})] })
|
|
508
|
+
}),
|
|
509
|
+
L && /* @__PURE__ */ (0, k.jsxs)("div", {
|
|
510
|
+
className: "flex flex-col items-center gap-2 py-4",
|
|
511
|
+
role: "alert",
|
|
512
|
+
children: [
|
|
513
|
+
/* @__PURE__ */ (0, k.jsx)(ye, { className: "size-5 text-destructive" }),
|
|
514
|
+
/* @__PURE__ */ (0, k.jsx)("p", {
|
|
515
|
+
className: "text-sm text-destructive",
|
|
516
|
+
children: L
|
|
517
|
+
}),
|
|
518
|
+
/* @__PURE__ */ (0, k.jsx)(f, {
|
|
519
|
+
variant: "outline",
|
|
520
|
+
size: "sm",
|
|
521
|
+
onClick: () => qe(V || void 0, H, Je),
|
|
522
|
+
type: "button",
|
|
523
|
+
children: "Retry"
|
|
524
|
+
})
|
|
525
|
+
]
|
|
526
|
+
}),
|
|
527
|
+
Oe ? /* @__PURE__ */ (0, k.jsx)("div", {
|
|
528
|
+
className: "flex-1 min-h-0",
|
|
529
|
+
"data-testid": "record-picker-grid-slot",
|
|
530
|
+
children: Oe({
|
|
531
|
+
columns: Ge,
|
|
532
|
+
records: F,
|
|
533
|
+
loading: I,
|
|
534
|
+
totalCount: z,
|
|
535
|
+
currentPage: H,
|
|
536
|
+
pageSize: ce,
|
|
537
|
+
sortField: G,
|
|
538
|
+
sortDirection: K,
|
|
539
|
+
onSort: Xe,
|
|
540
|
+
onPageChange: U,
|
|
541
|
+
onRowClick: $e,
|
|
542
|
+
isSelected: Qe,
|
|
543
|
+
multiple: a,
|
|
544
|
+
idField: se,
|
|
545
|
+
cellRenderer: N
|
|
546
|
+
})
|
|
547
|
+
}) : /* @__PURE__ */ (0, k.jsxs)(k.Fragment, { children: [
|
|
548
|
+
I && F.length === 0 && !L && /* @__PURE__ */ (0, k.jsx)("div", {
|
|
549
|
+
className: "flex-1 overflow-hidden min-h-0 border rounded-md",
|
|
550
|
+
role: "status",
|
|
551
|
+
"aria-live": "polite",
|
|
552
|
+
"data-testid": "record-picker-skeleton",
|
|
553
|
+
children: /* @__PURE__ */ (0, k.jsxs)(me, { children: [/* @__PURE__ */ (0, k.jsx)(x, { children: /* @__PURE__ */ (0, k.jsxs)(S, {
|
|
554
|
+
className: "bg-muted/40",
|
|
555
|
+
children: [a && /* @__PURE__ */ (0, k.jsx)(ge, { className: "w-10" }), Ge.map((e) => /* @__PURE__ */ (0, k.jsx)(ge, { children: /* @__PURE__ */ (0, k.jsx)(y, { className: "h-4 w-20" }) }, e.field))]
|
|
556
|
+
}) }), /* @__PURE__ */ (0, k.jsx)(b, { children: Array.from({ length: Ce }, (e, t) => /* @__PURE__ */ (0, k.jsxs)(S, { children: [a && /* @__PURE__ */ (0, k.jsx)(he, {
|
|
557
|
+
className: "w-10",
|
|
558
|
+
children: /* @__PURE__ */ (0, k.jsx)(y, { className: "size-4 rounded" })
|
|
559
|
+
}), Ge.map((e) => /* @__PURE__ */ (0, k.jsx)(he, { children: /* @__PURE__ */ (0, k.jsx)(y, { className: "h-4 w-full" }) }, e.field))] }, t)) })] })
|
|
560
|
+
}),
|
|
561
|
+
!I && !L && F.length === 0 && /* @__PURE__ */ (0, k.jsx)("div", {
|
|
562
|
+
className: "py-8 text-center",
|
|
563
|
+
children: /* @__PURE__ */ (0, k.jsx)("p", {
|
|
564
|
+
className: "text-sm text-muted-foreground",
|
|
565
|
+
children: "No records found"
|
|
566
|
+
})
|
|
567
|
+
}),
|
|
568
|
+
!L && F.length > 0 && /* @__PURE__ */ (0, k.jsxs)("div", {
|
|
569
|
+
className: "relative flex-1 overflow-auto min-h-0 border rounded-md",
|
|
570
|
+
tabIndex: 0,
|
|
571
|
+
onKeyDown: it,
|
|
572
|
+
role: "grid",
|
|
573
|
+
"aria-label": "Records",
|
|
574
|
+
children: [I && /* @__PURE__ */ (0, k.jsx)("div", {
|
|
575
|
+
className: "absolute inset-0 z-10 flex items-center justify-center bg-background/60",
|
|
576
|
+
"data-testid": "record-picker-loading-overlay",
|
|
577
|
+
children: /* @__PURE__ */ (0, k.jsx)(i, { className: "size-6 animate-spin text-muted-foreground" })
|
|
578
|
+
}), /* @__PURE__ */ (0, k.jsxs)(me, {
|
|
579
|
+
style: Object.keys(Be).length > 0 ? { tableLayout: "fixed" } : void 0,
|
|
580
|
+
children: [/* @__PURE__ */ (0, k.jsx)(x, {
|
|
581
|
+
className: "sticky top-0 z-[5] bg-muted/50 [&_tr]:border-b",
|
|
582
|
+
"data-testid": "record-picker-sticky-header",
|
|
583
|
+
children: /* @__PURE__ */ (0, k.jsxs)(S, { children: [a && /* @__PURE__ */ (0, k.jsx)(ge, { className: "w-10" }), Ge.map((e) => {
|
|
584
|
+
let t = Be[e.field];
|
|
585
|
+
return /* @__PURE__ */ (0, k.jsxs)(ge, {
|
|
586
|
+
style: t ? {
|
|
587
|
+
width: `${t}px`,
|
|
588
|
+
minWidth: `${t}px`
|
|
589
|
+
} : e.width ? { width: e.width } : void 0,
|
|
590
|
+
className: "cursor-pointer select-none relative group text-xs font-semibold uppercase tracking-wider",
|
|
591
|
+
onClick: () => Xe(e.field),
|
|
592
|
+
"aria-sort": G === e.field ? K === "asc" ? "ascending" : "descending" : "none",
|
|
593
|
+
children: [/* @__PURE__ */ (0, k.jsxs)("span", {
|
|
594
|
+
className: "inline-flex items-center",
|
|
595
|
+
children: [e.label || Te(e.field), ot(e.field)]
|
|
596
|
+
}), /* @__PURE__ */ (0, k.jsx)("span", {
|
|
597
|
+
role: "separator",
|
|
598
|
+
"aria-orientation": "vertical",
|
|
599
|
+
className: "absolute right-0 top-0 bottom-0 w-1 cursor-col-resize opacity-0 group-hover:opacity-100 bg-border hover:bg-primary/50 transition-opacity",
|
|
600
|
+
onMouseDown: (t) => {
|
|
601
|
+
let n = t.currentTarget.parentElement?.getBoundingClientRect();
|
|
602
|
+
st(t, e.field, n?.width ?? 100);
|
|
603
|
+
},
|
|
604
|
+
onClick: (e) => e.stopPropagation(),
|
|
605
|
+
"data-testid": `resize-handle-${e.field}`
|
|
606
|
+
})]
|
|
607
|
+
}, e.field);
|
|
608
|
+
})] })
|
|
609
|
+
}), /* @__PURE__ */ (0, k.jsx)(b, {
|
|
610
|
+
ref: Ie,
|
|
611
|
+
children: F.map((e, t) => {
|
|
612
|
+
let n = Ze(e), i = Qe(e), o = t === Y;
|
|
613
|
+
return /* @__PURE__ */ (0, k.jsxs)(S, {
|
|
614
|
+
"data-row-index": t,
|
|
615
|
+
className: _e("cursor-pointer transition-colors", dt(i, t), o && "ring-2 ring-primary ring-inset"),
|
|
616
|
+
onClick: () => $e(e),
|
|
617
|
+
"data-testid": `record-row-${n}`,
|
|
618
|
+
"aria-selected": i,
|
|
619
|
+
children: [a && /* @__PURE__ */ (0, k.jsx)(he, {
|
|
620
|
+
className: "w-10",
|
|
621
|
+
children: i && /* @__PURE__ */ (0, k.jsx)(r, { className: "size-4 text-primary" })
|
|
622
|
+
}), Ge.map((t) => /* @__PURE__ */ (0, k.jsx)(he, {
|
|
623
|
+
className: "py-2.5",
|
|
624
|
+
children: at(e, t)
|
|
625
|
+
}, t.field))]
|
|
626
|
+
}, n ?? t);
|
|
627
|
+
})
|
|
628
|
+
})]
|
|
629
|
+
})]
|
|
630
|
+
}),
|
|
631
|
+
!L && z > 0 && /* @__PURE__ */ (0, k.jsxs)("div", {
|
|
632
|
+
className: "flex items-center justify-between text-sm text-muted-foreground border-t pt-3 mt-2 px-1",
|
|
633
|
+
"data-testid": "record-picker-pagination",
|
|
634
|
+
children: [/* @__PURE__ */ (0, k.jsxs)("span", { children: [
|
|
635
|
+
z,
|
|
636
|
+
" ",
|
|
637
|
+
z === 1 ? "record" : "records",
|
|
638
|
+
Q > 1 && ` · Page ${H} of ${Q}`
|
|
639
|
+
] }), Q > 1 && /* @__PURE__ */ (0, k.jsxs)("div", {
|
|
640
|
+
className: "flex items-center gap-1.5",
|
|
641
|
+
children: [
|
|
642
|
+
/* @__PURE__ */ (0, k.jsx)(f, {
|
|
643
|
+
variant: "outline",
|
|
644
|
+
size: "icon",
|
|
645
|
+
className: "size-7",
|
|
646
|
+
onClick: tt,
|
|
647
|
+
disabled: H <= 1,
|
|
648
|
+
type: "button",
|
|
649
|
+
"aria-label": "Previous page",
|
|
650
|
+
children: /* @__PURE__ */ (0, k.jsx)(E, { className: "size-4" })
|
|
651
|
+
}),
|
|
652
|
+
/* @__PURE__ */ (0, k.jsx)(oe, {
|
|
653
|
+
className: "h-7 w-12 text-center text-xs px-1",
|
|
654
|
+
placeholder: String(H),
|
|
655
|
+
value: Ue,
|
|
656
|
+
onChange: (e) => We(e.target.value),
|
|
657
|
+
onKeyDown: rt,
|
|
658
|
+
"aria-label": "Jump to page",
|
|
659
|
+
"data-testid": "record-picker-page-jump"
|
|
660
|
+
}),
|
|
661
|
+
/* @__PURE__ */ (0, k.jsx)(f, {
|
|
662
|
+
variant: "outline",
|
|
663
|
+
size: "icon",
|
|
664
|
+
className: "size-7",
|
|
665
|
+
onClick: nt,
|
|
666
|
+
disabled: H >= Q,
|
|
667
|
+
type: "button",
|
|
668
|
+
"aria-label": "Next page",
|
|
669
|
+
children: /* @__PURE__ */ (0, k.jsx)(D, { className: "size-4" })
|
|
670
|
+
})
|
|
671
|
+
]
|
|
672
|
+
})]
|
|
673
|
+
})
|
|
674
|
+
] }),
|
|
675
|
+
a && /* @__PURE__ */ (0, k.jsx)(g, { children: /* @__PURE__ */ (0, k.jsxs)("div", {
|
|
676
|
+
className: "flex items-center gap-2 w-full justify-between",
|
|
677
|
+
children: [/* @__PURE__ */ (0, k.jsxs)("span", {
|
|
678
|
+
className: "text-sm text-muted-foreground",
|
|
679
|
+
children: [J.size, " selected"]
|
|
680
|
+
}), /* @__PURE__ */ (0, k.jsxs)("div", {
|
|
681
|
+
className: "flex gap-2",
|
|
682
|
+
children: [/* @__PURE__ */ (0, k.jsx)(f, {
|
|
683
|
+
variant: "outline",
|
|
684
|
+
type: "button",
|
|
685
|
+
onClick: () => t(!1),
|
|
686
|
+
children: "Cancel"
|
|
687
|
+
}), /* @__PURE__ */ (0, k.jsx)(f, {
|
|
688
|
+
type: "button",
|
|
689
|
+
onClick: et,
|
|
690
|
+
children: "Confirm"
|
|
691
|
+
})]
|
|
692
|
+
})]
|
|
693
|
+
}) })
|
|
694
|
+
]
|
|
695
|
+
})
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
//#endregion
|
|
699
|
+
//#region ../fields/src/widgets/_cell-renderer-bridge.ts
|
|
700
|
+
var N;
|
|
701
|
+
function P(e) {
|
|
702
|
+
N = e;
|
|
703
|
+
}
|
|
704
|
+
function De() {
|
|
705
|
+
return N;
|
|
706
|
+
}
|
|
707
|
+
//#endregion
|
|
708
|
+
//#region ../fields/src/widgets/LookupField.tsx
|
|
709
|
+
var Oe = /* @__PURE__ */ e({ LookupField: () => L }), F = 50, ke = C;
|
|
710
|
+
function I(e, t, n, r) {
|
|
711
|
+
let i = e[n] ?? e.id ?? e._id, a = e[t] ?? e.label ?? e.name ?? String(i), o = r ? e[r] : void 0;
|
|
712
|
+
return {
|
|
713
|
+
value: i,
|
|
714
|
+
label: String(a),
|
|
715
|
+
description: o,
|
|
716
|
+
...e
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
function Ae(e) {
|
|
720
|
+
return {
|
|
721
|
+
text: "text",
|
|
722
|
+
number: "number",
|
|
723
|
+
currency: "number",
|
|
724
|
+
percent: "number",
|
|
725
|
+
select: "select",
|
|
726
|
+
status: "select",
|
|
727
|
+
date: "date",
|
|
728
|
+
datetime: "date",
|
|
729
|
+
boolean: "boolean"
|
|
730
|
+
}[e];
|
|
731
|
+
}
|
|
732
|
+
function L({ value: e, onChange: t, field: n, readonly: r, ...p }) {
|
|
733
|
+
let [m, h] = u(!1), [g, re] = u(""), { t: ie } = ee(), [_, le] = u([]), [ue, de] = u(!1), [fe, pe] = u(null), [y, me] = u(0), b = ne(null), [he, ge] = u([]), [x, S] = u(-1), _e = ne(null), C = n || p.schema, w = C?.field, T = w && typeof w == "object" && ("reference_to" in w || "reference" in w || "type" in w) ? w : C, ve = T?.options || [], E = T?.multiple || !1, D = T?.display_field || T?.reference_field || "name", xe = T?.description_field, Se = T?.id_field || "id", A = T?.reference_to || T?.reference, Ce = T?.lookup_columns, we = T?.lookup_page_size, Te = T?.lookup_filters, j = l(() => {
|
|
734
|
+
let e = T?.depends_on ?? T?.dependsOn;
|
|
735
|
+
return e && Array.isArray(e) ? e.map((e) => typeof e == "string" ? {
|
|
736
|
+
field: e,
|
|
737
|
+
param: e
|
|
738
|
+
} : {
|
|
739
|
+
field: e.field,
|
|
740
|
+
param: e.param ?? e.field
|
|
741
|
+
}) : [];
|
|
742
|
+
}, [T?.depends_on, T?.dependsOn]), Ee = p.dependentValues, N = l(() => {
|
|
743
|
+
if (!Ce) return;
|
|
744
|
+
let e = [];
|
|
745
|
+
for (let t of Ce) if (typeof t == "object" && t.type) {
|
|
746
|
+
let n = Ae(t.type);
|
|
747
|
+
n && e.push({
|
|
748
|
+
field: t.field,
|
|
749
|
+
label: t.label,
|
|
750
|
+
type: n
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
return e.length > 0 ? e : void 0;
|
|
754
|
+
}, [Ce]), P = te(ke), Oe = P?.dataSource ?? null, L = p.dataSource ?? C?.dataSource ?? T?.dataSource ?? Oe, R = l(() => Ee || (P?.formValues ?? P?.data ?? {}), [
|
|
755
|
+
Ee,
|
|
756
|
+
P?.formValues,
|
|
757
|
+
P?.data
|
|
758
|
+
]), z = l(() => j.length === 0 ? !1 : j.some(({ field: e }) => {
|
|
759
|
+
let t = R[e];
|
|
760
|
+
return t == null || t === "" || Array.isArray(t) && t.length === 0;
|
|
761
|
+
}), [j, R]), B = L != null && typeof L.find == "function" && !!A, V = p.onCreateNew ?? C?.onCreateNew, [je, H] = u(!1), U = B ? _ : ve, W = l(() => {
|
|
762
|
+
if (B || !g) return U;
|
|
763
|
+
let e = g.toLowerCase();
|
|
764
|
+
return U.filter((t) => t.label.toLowerCase().includes(e) || t.description && t.description.toLowerCase().includes(e));
|
|
765
|
+
}, [
|
|
766
|
+
B,
|
|
767
|
+
U,
|
|
768
|
+
g
|
|
769
|
+
]);
|
|
770
|
+
c(() => {
|
|
771
|
+
S(-1);
|
|
772
|
+
}, [W.length]);
|
|
773
|
+
let G = s(async (e) => {
|
|
774
|
+
if (!(!L || !A)) {
|
|
775
|
+
if (z) {
|
|
776
|
+
le([]), me(0);
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
de(!0), pe(null);
|
|
780
|
+
try {
|
|
781
|
+
let t = { $top: F };
|
|
782
|
+
if (e && e.trim() && (t.$search = e.trim()), j.length > 0) {
|
|
783
|
+
let e = {};
|
|
784
|
+
for (let { field: t, param: n } of j) {
|
|
785
|
+
let r = R[t];
|
|
786
|
+
r == null || r === "" || (e[n] = typeof r == "number" ? r : String(r));
|
|
787
|
+
}
|
|
788
|
+
Object.keys(e).length > 0 && (t.$filter = e);
|
|
789
|
+
}
|
|
790
|
+
let n = await L.find(A, t), r = n?.data ?? n ?? [];
|
|
791
|
+
le(r.map((e) => I(e, D, Se, xe))), me(n?.total ?? r.length);
|
|
792
|
+
} catch (e) {
|
|
793
|
+
pe(e instanceof Error ? e.message : String(e)), le([]);
|
|
794
|
+
} finally {
|
|
795
|
+
de(!1);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
}, [
|
|
799
|
+
L,
|
|
800
|
+
A,
|
|
801
|
+
D,
|
|
802
|
+
Se,
|
|
803
|
+
xe,
|
|
804
|
+
z,
|
|
805
|
+
j,
|
|
806
|
+
R
|
|
807
|
+
]);
|
|
808
|
+
c(() => {
|
|
809
|
+
m && B && j.length > 0 && G(g || void 0);
|
|
810
|
+
}, [l(() => j.map((e) => `${e.param}=${R[e.field] ?? ""}`).join("|"), [j, R])]), c(() => {
|
|
811
|
+
m && B && G(g || void 0), m || (re(""), pe(null), S(-1));
|
|
812
|
+
}, [m]);
|
|
813
|
+
let Me = s((e) => {
|
|
814
|
+
re(e), B && (b.current && clearTimeout(b.current), b.current = setTimeout(() => {
|
|
815
|
+
G(e || void 0);
|
|
816
|
+
}, 300));
|
|
817
|
+
}, [B, G]);
|
|
818
|
+
c(() => () => {
|
|
819
|
+
b.current && clearTimeout(b.current);
|
|
820
|
+
}, []);
|
|
821
|
+
let K = s((e) => ve.find((t) => t.value === e) ?? _.find((t) => t.value === e) ?? he.find((t) => t.value === e), [
|
|
822
|
+
ve,
|
|
823
|
+
_,
|
|
824
|
+
he
|
|
825
|
+
]), q = E ? (Array.isArray(e) ? e : []).map(K).filter(Boolean) : e ? [K(e)].filter(Boolean) : [], J = s((n) => {
|
|
826
|
+
if (E) {
|
|
827
|
+
let r = Array.isArray(e) ? e : [];
|
|
828
|
+
r.includes(n.value) ? t(r.filter((e) => e !== n.value)) : t([...r, n.value]);
|
|
829
|
+
} else t(n.value), h(!1);
|
|
830
|
+
}, [
|
|
831
|
+
E,
|
|
832
|
+
e,
|
|
833
|
+
t
|
|
834
|
+
]), Ne = (n) => {
|
|
835
|
+
t(E ? (Array.isArray(e) ? e : []).filter((e) => e !== n) : null);
|
|
836
|
+
}, Pe = s((e) => {
|
|
837
|
+
ge(e.map((e) => I(e, D, Se, xe)));
|
|
838
|
+
}, [
|
|
839
|
+
D,
|
|
840
|
+
Se,
|
|
841
|
+
xe
|
|
842
|
+
]), Y = s((e) => {
|
|
843
|
+
e.key === "ArrowDown" ? (e.preventDefault(), S((e) => e < W.length - 1 ? e + 1 : e)) : e.key === "ArrowUp" ? (e.preventDefault(), S((e) => e > 0 ? e - 1 : 0)) : e.key === "Enter" && (e.preventDefault(), x >= 0 && x < W.length && J(W[x]));
|
|
844
|
+
}, [
|
|
845
|
+
W,
|
|
846
|
+
x,
|
|
847
|
+
J
|
|
848
|
+
]);
|
|
849
|
+
return c(() => {
|
|
850
|
+
x >= 0 && _e.current && _e.current.querySelector(`[data-lookup-index="${x}"]`)?.scrollIntoView({ block: "nearest" });
|
|
851
|
+
}, [x]), r ? q.length ? E ? /* @__PURE__ */ (0, k.jsx)("div", {
|
|
852
|
+
className: "flex flex-wrap gap-1",
|
|
853
|
+
children: q.map((e, t) => /* @__PURE__ */ (0, k.jsx)(d, {
|
|
854
|
+
variant: "outline",
|
|
855
|
+
children: e?.[D] || e?.label
|
|
856
|
+
}, t))
|
|
857
|
+
}) : /* @__PURE__ */ (0, k.jsx)("span", {
|
|
858
|
+
className: "text-sm",
|
|
859
|
+
children: q[0]?.[D] || q[0]?.label
|
|
860
|
+
}) : /* @__PURE__ */ (0, k.jsx)(ae, {}) : /* @__PURE__ */ (0, k.jsxs)("div", {
|
|
861
|
+
className: "space-y-2",
|
|
862
|
+
children: [
|
|
863
|
+
q.length > 0 && /* @__PURE__ */ (0, k.jsx)("div", {
|
|
864
|
+
className: "flex flex-wrap gap-1",
|
|
865
|
+
children: q.map((e, t) => /* @__PURE__ */ (0, k.jsxs)(d, {
|
|
866
|
+
variant: "outline",
|
|
867
|
+
className: "gap-1",
|
|
868
|
+
children: [e?.[D] || e?.label, /* @__PURE__ */ (0, k.jsx)("button", {
|
|
869
|
+
onClick: () => Ne(e?.value),
|
|
870
|
+
className: "ml-1 hover:text-destructive",
|
|
871
|
+
type: "button",
|
|
872
|
+
"aria-label": `Remove ${e?.[D] || e?.label}`,
|
|
873
|
+
children: /* @__PURE__ */ (0, k.jsx)(o, { className: "size-3" })
|
|
874
|
+
})]
|
|
875
|
+
}, t))
|
|
876
|
+
}),
|
|
877
|
+
/* @__PURE__ */ (0, k.jsxs)("div", {
|
|
878
|
+
className: "flex items-center gap-1.5",
|
|
879
|
+
children: [/* @__PURE__ */ (0, k.jsxs)(se, {
|
|
880
|
+
open: m,
|
|
881
|
+
onOpenChange: (e) => !z && h(e),
|
|
882
|
+
children: [/* @__PURE__ */ (0, k.jsx)(v, {
|
|
883
|
+
asChild: !0,
|
|
884
|
+
children: /* @__PURE__ */ (0, k.jsxs)(f, {
|
|
885
|
+
variant: "outline",
|
|
886
|
+
className: "min-w-0 flex-1 justify-start text-left font-normal",
|
|
887
|
+
type: "button",
|
|
888
|
+
disabled: z || p.disabled,
|
|
889
|
+
"data-testid": z ? "lookup-trigger-gated" : void 0,
|
|
890
|
+
title: z ? `Select ${j.map((e) => e.field).join(", ")} first` : void 0,
|
|
891
|
+
children: [/* @__PURE__ */ (0, k.jsx)(be, { className: "mr-2 size-4" }), z ? `Select ${j.map((e) => e.field).join(", ")} first` : q.length === 0 ? C?.placeholder || ie("common.select") : E ? ie("table.selected", { count: q.length }) : ie("common.select")]
|
|
892
|
+
})
|
|
893
|
+
}), /* @__PURE__ */ (0, k.jsxs)(ce, {
|
|
894
|
+
className: "w-[var(--radix-popover-trigger-width)] p-0",
|
|
895
|
+
align: "start",
|
|
896
|
+
children: [
|
|
897
|
+
/* @__PURE__ */ (0, k.jsx)("div", {
|
|
898
|
+
className: "p-2",
|
|
899
|
+
children: /* @__PURE__ */ (0, k.jsxs)("div", {
|
|
900
|
+
className: "relative",
|
|
901
|
+
children: [
|
|
902
|
+
/* @__PURE__ */ (0, k.jsx)(be, { className: "absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground" }),
|
|
903
|
+
/* @__PURE__ */ (0, k.jsx)(oe, {
|
|
904
|
+
placeholder: ie("common.search") + "...",
|
|
905
|
+
value: g,
|
|
906
|
+
onChange: (e) => Me(e.target.value),
|
|
907
|
+
onKeyDown: Y,
|
|
908
|
+
className: "w-full pl-9 h-8 text-sm"
|
|
909
|
+
}),
|
|
910
|
+
ue && /* @__PURE__ */ (0, k.jsx)(i, {
|
|
911
|
+
className: "absolute right-3 top-1/2 -translate-y-1/2 size-4 animate-spin text-muted-foreground",
|
|
912
|
+
"data-testid": "lookup-loading"
|
|
913
|
+
})
|
|
914
|
+
]
|
|
915
|
+
})
|
|
916
|
+
}),
|
|
917
|
+
fe && /* @__PURE__ */ (0, k.jsxs)("div", {
|
|
918
|
+
className: "flex flex-col items-center gap-2 py-4 px-2",
|
|
919
|
+
role: "alert",
|
|
920
|
+
children: [
|
|
921
|
+
/* @__PURE__ */ (0, k.jsx)(ye, { className: "size-5 text-destructive" }),
|
|
922
|
+
/* @__PURE__ */ (0, k.jsx)("p", {
|
|
923
|
+
className: "text-sm text-destructive",
|
|
924
|
+
children: fe
|
|
925
|
+
}),
|
|
926
|
+
/* @__PURE__ */ (0, k.jsx)(f, {
|
|
927
|
+
variant: "outline",
|
|
928
|
+
size: "sm",
|
|
929
|
+
onClick: () => G(g || void 0),
|
|
930
|
+
type: "button",
|
|
931
|
+
children: "Retry"
|
|
932
|
+
})
|
|
933
|
+
]
|
|
934
|
+
}),
|
|
935
|
+
ue && W.length === 0 && !fe && /* @__PURE__ */ (0, k.jsxs)("div", {
|
|
936
|
+
className: "flex flex-col items-center gap-2 py-6",
|
|
937
|
+
role: "status",
|
|
938
|
+
"aria-live": "polite",
|
|
939
|
+
children: [/* @__PURE__ */ (0, k.jsx)(i, { className: "size-6 animate-spin text-muted-foreground" }), /* @__PURE__ */ (0, k.jsx)("p", {
|
|
940
|
+
className: "text-sm text-muted-foreground",
|
|
941
|
+
children: "Loading…"
|
|
942
|
+
})]
|
|
943
|
+
}),
|
|
944
|
+
!fe && !(ue && W.length === 0) && /* @__PURE__ */ (0, k.jsx)("div", {
|
|
945
|
+
ref: _e,
|
|
946
|
+
className: "max-h-64 overflow-y-auto px-1 pb-1",
|
|
947
|
+
role: "listbox",
|
|
948
|
+
children: W.length === 0 ? /* @__PURE__ */ (0, k.jsxs)("div", {
|
|
949
|
+
className: "py-4 text-center",
|
|
950
|
+
children: [/* @__PURE__ */ (0, k.jsx)("p", {
|
|
951
|
+
className: "text-sm text-muted-foreground",
|
|
952
|
+
children: "No options found"
|
|
953
|
+
}), V && /* @__PURE__ */ (0, k.jsxs)(f, {
|
|
954
|
+
variant: "ghost",
|
|
955
|
+
size: "sm",
|
|
956
|
+
className: "mt-2 gap-1",
|
|
957
|
+
type: "button",
|
|
958
|
+
onClick: () => {
|
|
959
|
+
V(g), h(!1);
|
|
960
|
+
},
|
|
961
|
+
children: [/* @__PURE__ */ (0, k.jsx)(a, { className: "size-4" }), "Create new"]
|
|
962
|
+
})]
|
|
963
|
+
}) : /* @__PURE__ */ (0, k.jsxs)(k.Fragment, { children: [
|
|
964
|
+
W.map((t, n) => {
|
|
965
|
+
let r = E ? (Array.isArray(e) ? e : []).includes(t.value) : e === t.value;
|
|
966
|
+
return /* @__PURE__ */ (0, k.jsxs)("button", {
|
|
967
|
+
"data-lookup-index": n,
|
|
968
|
+
role: "option",
|
|
969
|
+
"aria-selected": r,
|
|
970
|
+
onClick: () => J(t),
|
|
971
|
+
className: `w-full text-left px-3 py-2 rounded-md text-sm hover:bg-accent flex items-center justify-between ${n === x ? "bg-accent text-accent-foreground" : r ? "bg-accent/50 text-accent-foreground" : ""}`,
|
|
972
|
+
type: "button",
|
|
973
|
+
children: [/* @__PURE__ */ (0, k.jsxs)("div", {
|
|
974
|
+
className: "min-w-0 flex-1",
|
|
975
|
+
children: [/* @__PURE__ */ (0, k.jsx)("span", {
|
|
976
|
+
className: "block truncate",
|
|
977
|
+
children: t.label
|
|
978
|
+
}), t.description && /* @__PURE__ */ (0, k.jsx)("span", {
|
|
979
|
+
className: "block truncate text-xs text-muted-foreground",
|
|
980
|
+
children: t.description
|
|
981
|
+
})]
|
|
982
|
+
}), r && /* @__PURE__ */ (0, k.jsx)(d, {
|
|
983
|
+
variant: "default",
|
|
984
|
+
className: "ml-2 shrink-0",
|
|
985
|
+
children: "Selected"
|
|
986
|
+
})]
|
|
987
|
+
}, t.value);
|
|
988
|
+
}),
|
|
989
|
+
B && y > W.length && /* @__PURE__ */ (0, k.jsxs)("p", {
|
|
990
|
+
className: "text-xs text-muted-foreground text-center py-2",
|
|
991
|
+
children: [
|
|
992
|
+
"Showing ",
|
|
993
|
+
W.length,
|
|
994
|
+
" of ",
|
|
995
|
+
y,
|
|
996
|
+
" results."
|
|
997
|
+
]
|
|
998
|
+
}),
|
|
999
|
+
B && y > W.length && /* @__PURE__ */ (0, k.jsxs)("button", {
|
|
1000
|
+
type: "button",
|
|
1001
|
+
className: "w-full text-center px-3 py-2 rounded-md text-sm font-medium text-primary hover:bg-accent flex items-center justify-center gap-1.5",
|
|
1002
|
+
onClick: () => {
|
|
1003
|
+
h(!1), H(!0);
|
|
1004
|
+
},
|
|
1005
|
+
"data-testid": "show-all-results",
|
|
1006
|
+
children: [
|
|
1007
|
+
/* @__PURE__ */ (0, k.jsx)(O, { className: "size-3.5" }),
|
|
1008
|
+
"Show All Results (",
|
|
1009
|
+
y,
|
|
1010
|
+
")"
|
|
1011
|
+
]
|
|
1012
|
+
}),
|
|
1013
|
+
V && /* @__PURE__ */ (0, k.jsxs)("button", {
|
|
1014
|
+
type: "button",
|
|
1015
|
+
className: "w-full text-left px-3 py-2 rounded-md text-sm hover:bg-accent flex items-center gap-1.5 text-muted-foreground",
|
|
1016
|
+
onClick: () => {
|
|
1017
|
+
V(g), h(!1);
|
|
1018
|
+
},
|
|
1019
|
+
children: [
|
|
1020
|
+
/* @__PURE__ */ (0, k.jsx)(a, { className: "size-3.5" }),
|
|
1021
|
+
"Create new",
|
|
1022
|
+
g ? ` "${g}"` : ""
|
|
1023
|
+
]
|
|
1024
|
+
})
|
|
1025
|
+
] })
|
|
1026
|
+
})
|
|
1027
|
+
]
|
|
1028
|
+
})]
|
|
1029
|
+
}), B && /* @__PURE__ */ (0, k.jsx)(f, {
|
|
1030
|
+
variant: "outline",
|
|
1031
|
+
size: "icon",
|
|
1032
|
+
className: "shrink-0",
|
|
1033
|
+
type: "button",
|
|
1034
|
+
onClick: () => H(!0),
|
|
1035
|
+
"aria-label": "Browse all records",
|
|
1036
|
+
title: "Browse all records",
|
|
1037
|
+
"data-testid": "browse-all-records",
|
|
1038
|
+
children: /* @__PURE__ */ (0, k.jsx)(O, { className: "size-4" })
|
|
1039
|
+
})]
|
|
1040
|
+
}),
|
|
1041
|
+
B && L && A && /* @__PURE__ */ (0, k.jsx)(M, {
|
|
1042
|
+
open: je,
|
|
1043
|
+
onOpenChange: H,
|
|
1044
|
+
title: C?.label || "Select",
|
|
1045
|
+
multiple: E,
|
|
1046
|
+
dataSource: L,
|
|
1047
|
+
objectName: A,
|
|
1048
|
+
columns: Ce,
|
|
1049
|
+
displayField: D,
|
|
1050
|
+
idField: Se,
|
|
1051
|
+
pageSize: we,
|
|
1052
|
+
value: e,
|
|
1053
|
+
onSelect: t,
|
|
1054
|
+
onSelectRecords: Pe,
|
|
1055
|
+
lookupFilters: Te,
|
|
1056
|
+
cellRenderer: De(),
|
|
1057
|
+
filterColumns: N
|
|
1058
|
+
})
|
|
1059
|
+
]
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
//#endregion
|
|
1063
|
+
export { Oe as n, P as r, L as t };
|