@object-ui/fields 3.3.2 → 3.4.0

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,12 +1,12 @@
1
1
  import { t as e } from "./rolldown-runtime-CAFD8bLK.js";
2
2
  import { t } from "./useFieldTranslation-Bv3oUVgb.js";
3
3
  import { useCallback as n, useContext as r, useEffect as i, useMemo as a, useRef as o, useState as s } from "react";
4
- import { Badge as c, Button as l, Checkbox as u, Dialog as ee, DialogContent as te, DialogFooter as ne, DialogHeader as re, DialogTitle as d, EmptyValue as ie, Input as f, Label as p, Popover as ae, PopoverContent as oe, PopoverTrigger as se, Select as ce, SelectContent as le, SelectItem as ue, SelectTrigger as de, SelectValue as fe, Skeleton as m, Table as h, TableBody as pe, TableCell as g, TableHead as me, TableHeader as _, TableRow as v, cn as he } from "@object-ui/components";
5
- import { AlertCircle as ge, ArrowDown as y, ArrowUp as _e, ArrowUpDown as ve, Check as b, ChevronLeft as x, ChevronRight as S, Loader2 as ye, Plus as be, Search as xe, SlidersHorizontal as Se, TableProperties as C, X as Ce } from "lucide-react";
6
- import { Fragment as we, jsx as w, jsxs as T } from "react/jsx-runtime";
7
- import { SchemaRendererContext as E } from "@object-ui/react";
4
+ import { Badge as c, Button as l, Checkbox as u, Dialog as ee, DialogContent as te, DialogFooter as d, DialogHeader as f, DialogTitle as p, EmptyValue as ne, Input as m, Label as h, Popover as re, PopoverContent as ie, PopoverTrigger as ae, Select as oe, SelectContent as se, SelectItem as ce, SelectTrigger as le, SelectValue as ue, Skeleton as de, Table as fe, TableBody as pe, TableCell as g, TableHead as _, TableHeader as v, TableRow as y, cn as me } from "@object-ui/components";
5
+ import { AlertCircle as he, ArrowDown as b, ArrowUp as ge, ArrowUpDown as _e, Check as x, ChevronLeft as S, ChevronRight as C, Loader2 as ve, Plus as ye, Search as be, SlidersHorizontal as xe, TableProperties as w, X as Se } from "lucide-react";
6
+ import { Fragment as Ce, jsx as T, jsxs as E } from "react/jsx-runtime";
7
+ import { SchemaRendererContext as D } from "@object-ui/react";
8
8
  //#region src/widgets/RecordPickerDialog.tsx
9
- var D = 10, Te = 60, O = 5;
9
+ var O = 10, we = 60, Te = 5;
10
10
  function k(e) {
11
11
  return typeof e == "string" ? { field: e } : e;
12
12
  }
@@ -54,11 +54,11 @@ function De(e, t) {
54
54
  }
55
55
  return n;
56
56
  }
57
- function j({ open: e, onOpenChange: t, title: r = "Select Record", multiple: c = !1, dataSource: ie, objectName: ae, columns: oe, displayField: se = "name", idField: be = "id", pageSize: C = D, value: E, onSelect: j, onSelectRecords: M, lookupFilters: N, cellRenderer: Oe, filterColumns: P, renderFilterBar: ke, renderGrid: Ae }) {
58
- let [F, je] = s([]), [I, L] = s(!1), [R, z] = s(null), [B, V] = s(0), [H, Me] = s(""), [U, W] = s(1), G = o(null), [K, Ne] = s(null), [q, Pe] = s("asc"), [Fe, Ie] = s(/* @__PURE__ */ new Set()), Le = o(/* @__PURE__ */ new Map()), [J, Re] = s(-1), ze = o(null), [Be, Ve] = s(!1), [Y, He] = s({}), [Ue, We] = s({}), X = o(null), [Ge, Ke] = s(""), qe = a(() => oe && oe.length > 0 ? oe.map(k) : [{
59
- field: se,
60
- label: A(se)
61
- }], [oe, se]), Z = a(() => {
57
+ function j({ open: e, onOpenChange: t, title: r = "Select Record", multiple: c = !1, dataSource: ne, objectName: re, columns: ie, displayField: ae = "name", idField: ye = "id", pageSize: w = O, value: D, onSelect: j, onSelectRecords: M, lookupFilters: N, cellRenderer: Oe, filterColumns: P, renderFilterBar: ke, renderGrid: Ae }) {
58
+ let [F, je] = s([]), [I, Me] = s(!1), [L, R] = s(null), [z, B] = s(0), [V, Ne] = s(""), [H, U] = s(1), W = o(null), [G, Pe] = s(null), [K, q] = s("asc"), [J, Fe] = s(/* @__PURE__ */ new Set()), Ie = o(/* @__PURE__ */ new Map()), [Y, Le] = s(-1), Re = o(null), [ze, Be] = s(!1), [X, Ve] = s({}), [He, Ue] = s({}), We = o(null), [Ge, Ke] = s(""), qe = a(() => ie && ie.length > 0 ? ie.map(k) : [{
59
+ field: ae,
60
+ label: A(ae)
61
+ }], [ie, ae]), Z = a(() => {
62
62
  if (P && P.length > 0) return P;
63
63
  if (N && N.length > 0) return N.map((e) => {
64
64
  let t = "text";
@@ -82,7 +82,7 @@ function j({ open: e, onOpenChange: t, title: r = "Select Record", multiple: c =
82
82
  };
83
83
  });
84
84
  }, [P, N]), Je = a(() => {
85
- let e = N?.length ? Ee(N) : {}, t = Z?.length ? De(Y, Z) : {}, n = {
85
+ let e = N?.length ? Ee(N) : {}, t = Z?.length ? De(X, Z) : {}, n = {
86
86
  ...e,
87
87
  ...t
88
88
  };
@@ -90,74 +90,74 @@ function j({ open: e, onOpenChange: t, title: r = "Select Record", multiple: c =
90
90
  }, [
91
91
  N,
92
92
  Z,
93
- Y
94
- ]), Q = Math.max(1, Math.ceil(B / C)), Ye = n(async (e, t = 1, n, r) => {
95
- if (!(!ie || !ae)) {
96
- L(!0), z(null);
93
+ X
94
+ ]), Q = Math.max(1, Math.ceil(z / w)), Ye = n(async (e, t = 1, n, r) => {
95
+ if (!(!ne || !re)) {
96
+ Me(!0), R(null);
97
97
  try {
98
98
  let i = {
99
- $top: C,
100
- $skip: (t - 1) * C
99
+ $top: w,
100
+ $skip: (t - 1) * w
101
101
  };
102
102
  e && e.trim() && (i.$search = e.trim()), n && (i.$orderby = { [n.field]: n.direction });
103
103
  let a = r === void 0 ? Je : r;
104
104
  a && Object.keys(a).length > 0 && (i.$filter = a);
105
- let o = await ie.find(ae, i), s = o?.data ?? o ?? [];
106
- je(s), V(o?.total ?? s.length), Re(-1);
105
+ let o = await ne.find(re, i), s = o?.data ?? o ?? [];
106
+ je(s), B(o?.total ?? s.length), Le(-1);
107
107
  } catch (e) {
108
- z(e instanceof Error ? e.message : String(e)), je([]);
108
+ R(e instanceof Error ? e.message : String(e)), je([]);
109
109
  } finally {
110
- L(!1);
110
+ Me(!1);
111
111
  }
112
112
  }
113
113
  }, [
114
- ie,
115
- ae,
116
- C,
114
+ ne,
115
+ re,
116
+ w,
117
117
  Je
118
- ]), Xe = a(() => K ? {
119
- field: K,
120
- direction: q
121
- } : null, [K, q]);
118
+ ]), Xe = a(() => G ? {
119
+ field: G,
120
+ direction: K
121
+ } : null, [G, K]);
122
122
  i(() => {
123
- e || (Me(""), W(1), z(null), je([]), Ne(null), Pe("asc"), Re(-1), Ve(!1), He({}), We({}), Ke(""), Ie(new Set(c && Array.isArray(E) ? E : [])), Le.current.clear());
123
+ e || (Ne(""), U(1), R(null), je([]), Pe(null), q("asc"), Le(-1), Be(!1), Ve({}), Ue({}), Ke(""), Fe(new Set(c && Array.isArray(D) ? D : [])), Ie.current.clear());
124
124
  }, [e]), i(() => {
125
- e && Ye(H || void 0, U, Xe);
125
+ e && Ye(V || void 0, H, Xe);
126
126
  }, [
127
127
  e,
128
- U,
128
+ H,
129
129
  Xe,
130
130
  Je
131
131
  ]), i(() => {
132
- e && c && Ie(new Set(Array.isArray(E) ? E : []));
132
+ e && c && Fe(new Set(Array.isArray(D) ? D : []));
133
133
  }, [
134
134
  e,
135
135
  c,
136
- E
136
+ D
137
137
  ]);
138
138
  let Ze = n((e) => {
139
- Me(e), W(1), G.current && clearTimeout(G.current), G.current = setTimeout(() => {
139
+ Ne(e), U(1), W.current && clearTimeout(W.current), W.current = setTimeout(() => {
140
140
  Ye(e || void 0, 1, Xe);
141
141
  }, 300);
142
142
  }, [Ye, Xe]);
143
143
  i(() => () => {
144
- G.current && clearTimeout(G.current);
144
+ W.current && clearTimeout(W.current);
145
145
  }, []);
146
146
  let Qe = n((e) => {
147
- Ne((t) => t === e ? (Pe((e) => e === "asc" ? "desc" : "asc"), e) : (Pe("asc"), e)), W(1);
148
- }, []), $e = n((e) => e[be] ?? e.id ?? e._id, [be]), et = n((e) => {
147
+ Pe((t) => t === e ? (q((e) => e === "asc" ? "desc" : "asc"), e) : (q("asc"), e)), U(1);
148
+ }, []), $e = n((e) => e[ye] ?? e.id ?? e._id, [ye]), et = n((e) => {
149
149
  let t = $e(e);
150
- return c ? Fe.has(t) : E === t;
150
+ return c ? J.has(t) : D === t;
151
151
  }, [
152
152
  c,
153
- E,
154
- Fe,
153
+ D,
154
+ J,
155
155
  $e
156
156
  ]), tt = n((e) => {
157
157
  let n = $e(e);
158
- c ? Ie((t) => {
158
+ c ? Fe((t) => {
159
159
  let r = new Set(t);
160
- return r.has(n) ? (r.delete(n), Le.current.delete(n)) : (r.add(n), Le.current.set(n, e)), r;
160
+ return r.has(n) ? (r.delete(n), Ie.current.delete(n)) : (r.add(n), Ie.current.set(n, e)), r;
161
161
  }) : (j(n), M?.([e]), t(!1));
162
162
  }, [
163
163
  c,
@@ -166,41 +166,41 @@ function j({ open: e, onOpenChange: t, title: r = "Select Record", multiple: c =
166
166
  M,
167
167
  t
168
168
  ]), nt = n(() => {
169
- let e = Array.from(Fe);
169
+ let e = Array.from(J);
170
170
  j(e);
171
- let n = e.map((e) => Le.current.get(e)).filter(Boolean);
171
+ let n = e.map((e) => Ie.current.get(e)).filter(Boolean);
172
172
  M?.(n), t(!1);
173
173
  }, [
174
- Fe,
174
+ J,
175
175
  j,
176
176
  M,
177
177
  t
178
178
  ]), rt = n(() => {
179
- W((e) => Math.max(1, e - 1));
179
+ U((e) => Math.max(1, e - 1));
180
180
  }, []), it = n(() => {
181
- W((e) => Math.min(Q, e + 1));
181
+ U((e) => Math.min(Q, e + 1));
182
182
  }, [Q]), at = n((e) => {
183
183
  if (e.key !== "Enter") return;
184
184
  let t = parseInt(Ge, 10);
185
- !isNaN(t) && t >= 1 && t <= Q && W(t), Ke("");
185
+ !isNaN(t) && t >= 1 && t <= Q && U(t), Ke("");
186
186
  }, [Ge, Q]), ot = n((e) => {
187
- F.length !== 0 && (e.key === "ArrowDown" ? (e.preventDefault(), Re((e) => Math.min(e + 1, F.length - 1))) : e.key === "ArrowUp" ? (e.preventDefault(), Re((e) => Math.max(e - 1, 0))) : (e.key === "Enter" || e.key === " ") && (e.preventDefault(), J >= 0 && J < F.length && tt(F[J])));
187
+ F.length !== 0 && (e.key === "ArrowDown" ? (e.preventDefault(), Le((e) => Math.min(e + 1, F.length - 1))) : e.key === "ArrowUp" ? (e.preventDefault(), Le((e) => Math.max(e - 1, 0))) : (e.key === "Enter" || e.key === " ") && (e.preventDefault(), Y >= 0 && Y < F.length && tt(F[Y])));
188
188
  }, [
189
189
  F,
190
- J,
190
+ Y,
191
191
  tt
192
192
  ]);
193
193
  i(() => {
194
- if (J >= 0 && ze.current) {
195
- let e = ze.current.querySelector(`[data-row-index="${J}"]`);
194
+ if (Y >= 0 && Re.current) {
195
+ let e = Re.current.querySelector(`[data-row-index="${Y}"]`);
196
196
  e && typeof e.scrollIntoView == "function" && e.scrollIntoView({ block: "nearest" });
197
197
  }
198
- }, [J]);
198
+ }, [Y]);
199
199
  let st = n((e, t) => {
200
200
  let n = e[t.field];
201
201
  if (t.type && Oe) {
202
202
  let e = Oe(t.type);
203
- if (e) return /* @__PURE__ */ w(e, {
203
+ if (e) return /* @__PURE__ */ T(e, {
204
204
  value: n,
205
205
  field: {
206
206
  name: t.field,
@@ -209,56 +209,56 @@ function j({ open: e, onOpenChange: t, title: r = "Select Record", multiple: c =
209
209
  });
210
210
  }
211
211
  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);
212
- }, [Oe]), ct = n((e) => K === e ? w(q === "asc" ? _e : y, { className: "ml-1 size-3" }) : /* @__PURE__ */ w(ve, { className: "ml-1 size-3 opacity-40" }), [K, q]), lt = n((e, t, n) => {
213
- e.preventDefault(), e.stopPropagation(), X.current = {
212
+ }, [Oe]), ct = n((e) => G === e ? T(K === "asc" ? ge : b, { className: "ml-1 size-3" }) : /* @__PURE__ */ T(_e, { className: "ml-1 size-3 opacity-40" }), [G, K]), lt = n((e, t, n) => {
213
+ e.preventDefault(), e.stopPropagation(), We.current = {
214
214
  field: t,
215
215
  startX: e.clientX,
216
216
  startWidth: n
217
217
  };
218
218
  let r = (e) => {
219
- if (!X.current) return;
220
- let t = e.clientX - X.current.startX, n = Math.max(Te, X.current.startWidth + t);
221
- We((e) => ({
219
+ if (!We.current) return;
220
+ let t = e.clientX - We.current.startX, n = Math.max(we, We.current.startWidth + t);
221
+ Ue((e) => ({
222
222
  ...e,
223
- [X.current.field]: n
223
+ [We.current.field]: n
224
224
  }));
225
225
  }, i = () => {
226
- X.current = null, document.removeEventListener("mousemove", r), document.removeEventListener("mouseup", i);
226
+ We.current = null, document.removeEventListener("mousemove", r), document.removeEventListener("mouseup", i);
227
227
  };
228
228
  document.addEventListener("mousemove", r), document.addEventListener("mouseup", i);
229
229
  }, []), $ = n((e, t) => {
230
- He((n) => ({
230
+ Ve((n) => ({
231
231
  ...n,
232
232
  [e]: t
233
- })), W(1);
233
+ })), U(1);
234
234
  }, []), ut = n(() => {
235
- He({}), W(1);
236
- }, []), dt = a(() => Object.values(Y).filter((e) => e != null && e !== "").length, [Y]), ft = n((e) => {
237
- let t = Y[e.field], n = e.label || A(e.field);
235
+ Ve({}), U(1);
236
+ }, []), dt = a(() => Object.values(X).filter((e) => e != null && e !== "").length, [X]), ft = n((e) => {
237
+ let t = X[e.field], n = e.label || A(e.field);
238
238
  switch (e.type) {
239
- case "select": return /* @__PURE__ */ T("div", {
239
+ case "select": return /* @__PURE__ */ E("div", {
240
240
  className: "space-y-1",
241
- children: [/* @__PURE__ */ w(p, {
241
+ children: [/* @__PURE__ */ T(h, {
242
242
  className: "text-xs text-muted-foreground",
243
243
  children: n
244
- }), /* @__PURE__ */ T(ce, {
244
+ }), /* @__PURE__ */ E(oe, {
245
245
  value: t == null ? "" : String(t),
246
246
  onValueChange: (t) => $(e.field, t),
247
- children: [/* @__PURE__ */ w(de, {
247
+ children: [/* @__PURE__ */ T(le, {
248
248
  className: "h-8 text-xs",
249
- children: /* @__PURE__ */ w(fe, { placeholder: `Filter ${n}` })
250
- }), /* @__PURE__ */ w(le, { children: e.options?.map((e) => /* @__PURE__ */ w(ue, {
249
+ children: /* @__PURE__ */ T(ue, { placeholder: `Filter ${n}` })
250
+ }), /* @__PURE__ */ T(se, { children: e.options?.map((e) => /* @__PURE__ */ T(ce, {
251
251
  value: String(e.value),
252
252
  children: e.label
253
253
  }, String(e.value))) })]
254
254
  })]
255
255
  });
256
- case "number": return /* @__PURE__ */ T("div", {
256
+ case "number": return /* @__PURE__ */ E("div", {
257
257
  className: "space-y-1",
258
- children: [/* @__PURE__ */ w(p, {
258
+ children: [/* @__PURE__ */ T(h, {
259
259
  className: "text-xs text-muted-foreground",
260
260
  children: n
261
- }), /* @__PURE__ */ w(f, {
261
+ }), /* @__PURE__ */ T(m, {
262
262
  type: "number",
263
263
  className: "h-8 text-xs",
264
264
  value: t ?? "",
@@ -269,40 +269,40 @@ function j({ open: e, onOpenChange: t, title: r = "Select Record", multiple: c =
269
269
  }
270
270
  })]
271
271
  });
272
- case "date": return /* @__PURE__ */ T("div", {
272
+ case "date": return /* @__PURE__ */ E("div", {
273
273
  className: "space-y-1",
274
- children: [/* @__PURE__ */ w(p, {
274
+ children: [/* @__PURE__ */ T(h, {
275
275
  className: "text-xs text-muted-foreground",
276
276
  children: n
277
- }), /* @__PURE__ */ w(f, {
277
+ }), /* @__PURE__ */ T(m, {
278
278
  type: "date",
279
279
  className: "h-8 text-xs",
280
280
  value: t ?? "",
281
281
  onChange: (t) => $(e.field, t.target.value)
282
282
  })]
283
283
  });
284
- case "boolean": return /* @__PURE__ */ T("div", {
284
+ case "boolean": return /* @__PURE__ */ E("div", {
285
285
  className: "space-y-1",
286
- children: [/* @__PURE__ */ w(p, {
286
+ children: [/* @__PURE__ */ T(h, {
287
287
  className: "text-xs text-muted-foreground",
288
288
  children: n
289
- }), /* @__PURE__ */ T("div", {
289
+ }), /* @__PURE__ */ E("div", {
290
290
  className: "flex items-center gap-2 h-8",
291
- children: [/* @__PURE__ */ w(u, {
291
+ children: [/* @__PURE__ */ T(u, {
292
292
  checked: !!t,
293
293
  onCheckedChange: (t) => $(e.field, !!t)
294
- }), /* @__PURE__ */ w("span", {
294
+ }), /* @__PURE__ */ T("span", {
295
295
  className: "text-xs text-muted-foreground",
296
296
  children: "Yes"
297
297
  })]
298
298
  })]
299
299
  });
300
- default: return /* @__PURE__ */ T("div", {
300
+ default: return /* @__PURE__ */ E("div", {
301
301
  className: "space-y-1",
302
- children: [/* @__PURE__ */ w(p, {
302
+ children: [/* @__PURE__ */ T(h, {
303
303
  className: "text-xs text-muted-foreground",
304
304
  children: n
305
- }), /* @__PURE__ */ w(f, {
305
+ }), /* @__PURE__ */ T(m, {
306
306
  className: "h-8 text-xs",
307
307
  value: t ?? "",
308
308
  placeholder: `Filter ${n}`,
@@ -310,165 +310,165 @@ function j({ open: e, onOpenChange: t, title: r = "Select Record", multiple: c =
310
310
  })]
311
311
  });
312
312
  }
313
- }, [Y, $]), pt = n((e, t) => e ? "bg-primary/5 hover:bg-primary/10" : t % 2 == 1 ? "bg-muted/20 hover:bg-accent/30" : "hover:bg-accent/30", []);
314
- return /* @__PURE__ */ w(ee, {
313
+ }, [X, $]), pt = n((e, t) => e ? "bg-primary/5 hover:bg-primary/10" : t % 2 == 1 ? "bg-muted/20 hover:bg-accent/30" : "hover:bg-accent/30", []);
314
+ return /* @__PURE__ */ T(ee, {
315
315
  open: e,
316
316
  onOpenChange: t,
317
- children: /* @__PURE__ */ T(te, {
317
+ children: /* @__PURE__ */ E(te, {
318
318
  className: "w-[95vw] sm:max-w-3xl lg:max-w-5xl max-h-[85vh] sm:max-h-[80vh] flex flex-col gap-0",
319
319
  "data-testid": "record-picker-dialog",
320
320
  children: [
321
- /* @__PURE__ */ w(re, { children: /* @__PURE__ */ T(d, { children: [r, c && /* @__PURE__ */ w("span", {
321
+ /* @__PURE__ */ T(f, { children: /* @__PURE__ */ E(p, { children: [r, c && /* @__PURE__ */ T("span", {
322
322
  className: "sr-only",
323
323
  children: " (multiple selection)"
324
324
  })] }) }),
325
- /* @__PURE__ */ T("div", {
325
+ /* @__PURE__ */ E("div", {
326
326
  className: "relative rounded-md border bg-muted/30 mb-3",
327
327
  children: [
328
- /* @__PURE__ */ w(xe, { className: "absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground" }),
329
- /* @__PURE__ */ w(f, {
328
+ /* @__PURE__ */ T(be, { className: "absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground" }),
329
+ /* @__PURE__ */ T(m, {
330
330
  placeholder: "Search...",
331
- value: H,
331
+ value: V,
332
332
  onChange: (e) => Ze(e.target.value),
333
333
  className: "pl-9 border-0 bg-transparent shadow-none focus-visible:ring-0",
334
334
  "data-testid": "record-picker-search"
335
335
  }),
336
- I && /* @__PURE__ */ w(ye, {
336
+ I && /* @__PURE__ */ T(ve, {
337
337
  className: "absolute right-3 top-1/2 -translate-y-1/2 size-4 animate-spin text-muted-foreground",
338
338
  "data-testid": "record-picker-loading-indicator"
339
339
  })
340
340
  ]
341
341
  }),
342
- Z && Z.length > 0 && /* @__PURE__ */ w("div", {
342
+ Z && Z.length > 0 && /* @__PURE__ */ T("div", {
343
343
  className: "py-2",
344
- children: ke ? /* @__PURE__ */ w("div", {
344
+ children: ke ? /* @__PURE__ */ T("div", {
345
345
  "data-testid": "record-picker-filter-bar",
346
346
  children: ke({
347
347
  filterColumns: Z,
348
- values: Y,
348
+ values: X,
349
349
  onChange: $,
350
350
  onClear: ut,
351
351
  activeCount: dt
352
352
  })
353
- }) : /* @__PURE__ */ T(we, { children: [/* @__PURE__ */ T("div", {
353
+ }) : /* @__PURE__ */ E(Ce, { children: [/* @__PURE__ */ E("div", {
354
354
  className: "flex items-center gap-2",
355
355
  "data-testid": "record-picker-filter-bar",
356
- children: [/* @__PURE__ */ T(l, {
356
+ children: [/* @__PURE__ */ E(l, {
357
357
  type: "button",
358
358
  variant: dt > 0 ? "secondary" : "outline",
359
359
  size: "sm",
360
360
  className: "gap-1.5 shrink-0",
361
- onClick: () => Ve((e) => !e),
361
+ onClick: () => Be((e) => !e),
362
362
  children: [
363
- /* @__PURE__ */ w(Se, { className: "size-3.5" }),
363
+ /* @__PURE__ */ T(xe, { className: "size-3.5" }),
364
364
  "Filters",
365
- dt > 0 && /* @__PURE__ */ w("span", {
365
+ dt > 0 && /* @__PURE__ */ T("span", {
366
366
  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",
367
367
  children: dt
368
368
  })
369
369
  ]
370
- }), dt > 0 && /* @__PURE__ */ T(l, {
370
+ }), dt > 0 && /* @__PURE__ */ E(l, {
371
371
  type: "button",
372
372
  variant: "ghost",
373
373
  size: "sm",
374
374
  className: "gap-1 text-xs",
375
375
  onClick: ut,
376
- children: [/* @__PURE__ */ w(Ce, { className: "size-3" }), "Clear"]
376
+ children: [/* @__PURE__ */ T(Se, { className: "size-3" }), "Clear"]
377
377
  })]
378
- }), Be && /* @__PURE__ */ w("div", {
378
+ }), ze && /* @__PURE__ */ T("div", {
379
379
  className: "mt-2 grid gap-3 sm:grid-cols-2 lg:grid-cols-3 border rounded-md p-3 bg-muted/30",
380
380
  "data-testid": "record-picker-filter-panel",
381
- children: Z.map((e) => /* @__PURE__ */ w("div", { children: ft(e) }, e.field))
381
+ children: Z.map((e) => /* @__PURE__ */ T("div", { children: ft(e) }, e.field))
382
382
  })] })
383
383
  }),
384
- R && /* @__PURE__ */ T("div", {
384
+ L && /* @__PURE__ */ E("div", {
385
385
  className: "flex flex-col items-center gap-2 py-4",
386
386
  role: "alert",
387
387
  children: [
388
- /* @__PURE__ */ w(ge, { className: "size-5 text-destructive" }),
389
- /* @__PURE__ */ w("p", {
388
+ /* @__PURE__ */ T(he, { className: "size-5 text-destructive" }),
389
+ /* @__PURE__ */ T("p", {
390
390
  className: "text-sm text-destructive",
391
- children: R
391
+ children: L
392
392
  }),
393
- /* @__PURE__ */ w(l, {
393
+ /* @__PURE__ */ T(l, {
394
394
  variant: "outline",
395
395
  size: "sm",
396
- onClick: () => Ye(H || void 0, U, Xe),
396
+ onClick: () => Ye(V || void 0, H, Xe),
397
397
  type: "button",
398
398
  children: "Retry"
399
399
  })
400
400
  ]
401
401
  }),
402
- Ae ? /* @__PURE__ */ w("div", {
402
+ Ae ? /* @__PURE__ */ T("div", {
403
403
  className: "flex-1 min-h-0",
404
404
  "data-testid": "record-picker-grid-slot",
405
405
  children: Ae({
406
406
  columns: qe,
407
407
  records: F,
408
408
  loading: I,
409
- totalCount: B,
410
- currentPage: U,
411
- pageSize: C,
412
- sortField: K,
413
- sortDirection: q,
409
+ totalCount: z,
410
+ currentPage: H,
411
+ pageSize: w,
412
+ sortField: G,
413
+ sortDirection: K,
414
414
  onSort: Qe,
415
- onPageChange: W,
415
+ onPageChange: U,
416
416
  onRowClick: tt,
417
417
  isSelected: et,
418
418
  multiple: c,
419
- idField: be,
419
+ idField: ye,
420
420
  cellRenderer: Oe
421
421
  })
422
- }) : /* @__PURE__ */ T(we, { children: [
423
- I && F.length === 0 && !R && /* @__PURE__ */ w("div", {
422
+ }) : /* @__PURE__ */ E(Ce, { children: [
423
+ I && F.length === 0 && !L && /* @__PURE__ */ T("div", {
424
424
  className: "flex-1 overflow-hidden min-h-0 border rounded-md",
425
425
  role: "status",
426
426
  "aria-live": "polite",
427
427
  "data-testid": "record-picker-skeleton",
428
- children: /* @__PURE__ */ T(h, { children: [/* @__PURE__ */ w(_, { children: /* @__PURE__ */ T(v, {
428
+ children: /* @__PURE__ */ E(fe, { children: [/* @__PURE__ */ T(v, { children: /* @__PURE__ */ E(y, {
429
429
  className: "bg-muted/40",
430
- children: [c && /* @__PURE__ */ w(me, { className: "w-10" }), qe.map((e) => /* @__PURE__ */ w(me, { children: /* @__PURE__ */ w(m, { className: "h-4 w-20" }) }, e.field))]
431
- }) }), /* @__PURE__ */ w(pe, { children: Array.from({ length: O }, (e, t) => /* @__PURE__ */ T(v, { children: [c && /* @__PURE__ */ w(g, {
430
+ children: [c && /* @__PURE__ */ T(_, { className: "w-10" }), qe.map((e) => /* @__PURE__ */ T(_, { children: /* @__PURE__ */ T(de, { className: "h-4 w-20" }) }, e.field))]
431
+ }) }), /* @__PURE__ */ T(pe, { children: Array.from({ length: Te }, (e, t) => /* @__PURE__ */ E(y, { children: [c && /* @__PURE__ */ T(g, {
432
432
  className: "w-10",
433
- children: /* @__PURE__ */ w(m, { className: "size-4 rounded" })
434
- }), qe.map((e) => /* @__PURE__ */ w(g, { children: /* @__PURE__ */ w(m, { className: "h-4 w-full" }) }, e.field))] }, t)) })] })
433
+ children: /* @__PURE__ */ T(de, { className: "size-4 rounded" })
434
+ }), qe.map((e) => /* @__PURE__ */ T(g, { children: /* @__PURE__ */ T(de, { className: "h-4 w-full" }) }, e.field))] }, t)) })] })
435
435
  }),
436
- !I && !R && F.length === 0 && /* @__PURE__ */ w("div", {
436
+ !I && !L && F.length === 0 && /* @__PURE__ */ T("div", {
437
437
  className: "py-8 text-center",
438
- children: /* @__PURE__ */ w("p", {
438
+ children: /* @__PURE__ */ T("p", {
439
439
  className: "text-sm text-muted-foreground",
440
440
  children: "No records found"
441
441
  })
442
442
  }),
443
- !R && F.length > 0 && /* @__PURE__ */ T("div", {
443
+ !L && F.length > 0 && /* @__PURE__ */ E("div", {
444
444
  className: "relative flex-1 overflow-auto min-h-0 border rounded-md",
445
445
  tabIndex: 0,
446
446
  onKeyDown: ot,
447
447
  role: "grid",
448
448
  "aria-label": "Records",
449
- children: [I && /* @__PURE__ */ w("div", {
449
+ children: [I && /* @__PURE__ */ T("div", {
450
450
  className: "absolute inset-0 z-10 flex items-center justify-center bg-background/60",
451
451
  "data-testid": "record-picker-loading-overlay",
452
- children: /* @__PURE__ */ w(ye, { className: "size-6 animate-spin text-muted-foreground" })
453
- }), /* @__PURE__ */ T(h, {
454
- style: Object.keys(Ue).length > 0 ? { tableLayout: "fixed" } : void 0,
455
- children: [/* @__PURE__ */ w(_, {
452
+ children: /* @__PURE__ */ T(ve, { className: "size-6 animate-spin text-muted-foreground" })
453
+ }), /* @__PURE__ */ E(fe, {
454
+ style: Object.keys(He).length > 0 ? { tableLayout: "fixed" } : void 0,
455
+ children: [/* @__PURE__ */ T(v, {
456
456
  className: "sticky top-0 z-[5] bg-muted/50 [&_tr]:border-b",
457
457
  "data-testid": "record-picker-sticky-header",
458
- children: /* @__PURE__ */ T(v, { children: [c && /* @__PURE__ */ w(me, { className: "w-10" }), qe.map((e) => {
459
- let t = Ue[e.field];
460
- return /* @__PURE__ */ T(me, {
458
+ children: /* @__PURE__ */ E(y, { children: [c && /* @__PURE__ */ T(_, { className: "w-10" }), qe.map((e) => {
459
+ let t = He[e.field];
460
+ return /* @__PURE__ */ E(_, {
461
461
  style: t ? {
462
462
  width: `${t}px`,
463
463
  minWidth: `${t}px`
464
464
  } : e.width ? { width: e.width } : void 0,
465
465
  className: "cursor-pointer select-none relative group text-xs font-semibold uppercase tracking-wider",
466
466
  onClick: () => Qe(e.field),
467
- "aria-sort": K === e.field ? q === "asc" ? "ascending" : "descending" : "none",
468
- children: [/* @__PURE__ */ T("span", {
467
+ "aria-sort": G === e.field ? K === "asc" ? "ascending" : "descending" : "none",
468
+ children: [/* @__PURE__ */ E("span", {
469
469
  className: "inline-flex items-center",
470
470
  children: [e.label || A(e.field), ct(e.field)]
471
- }), /* @__PURE__ */ w("span", {
471
+ }), /* @__PURE__ */ T("span", {
472
472
  role: "separator",
473
473
  "aria-orientation": "vertical",
474
474
  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",
@@ -481,20 +481,20 @@ function j({ open: e, onOpenChange: t, title: r = "Select Record", multiple: c =
481
481
  })]
482
482
  }, e.field);
483
483
  })] })
484
- }), /* @__PURE__ */ w(pe, {
485
- ref: ze,
484
+ }), /* @__PURE__ */ T(pe, {
485
+ ref: Re,
486
486
  children: F.map((e, t) => {
487
- let n = $e(e), r = et(e), i = t === J;
488
- return /* @__PURE__ */ T(v, {
487
+ let n = $e(e), r = et(e), i = t === Y;
488
+ return /* @__PURE__ */ E(y, {
489
489
  "data-row-index": t,
490
- className: he("cursor-pointer transition-colors", pt(r, t), i && "ring-2 ring-primary ring-inset"),
490
+ className: me("cursor-pointer transition-colors", pt(r, t), i && "ring-2 ring-primary ring-inset"),
491
491
  onClick: () => tt(e),
492
492
  "data-testid": `record-row-${n}`,
493
493
  "aria-selected": r,
494
- children: [c && /* @__PURE__ */ w(g, {
494
+ children: [c && /* @__PURE__ */ T(g, {
495
495
  className: "w-10",
496
- children: r && /* @__PURE__ */ w(b, { className: "size-4 text-primary" })
497
- }), qe.map((t) => /* @__PURE__ */ w(g, {
496
+ children: r && /* @__PURE__ */ T(x, { className: "size-4 text-primary" })
497
+ }), qe.map((t) => /* @__PURE__ */ T(g, {
498
498
  className: "py-2.5",
499
499
  children: st(e, t)
500
500
  }, t.field))]
@@ -503,63 +503,63 @@ function j({ open: e, onOpenChange: t, title: r = "Select Record", multiple: c =
503
503
  })]
504
504
  })]
505
505
  }),
506
- !R && B > 0 && /* @__PURE__ */ T("div", {
506
+ !L && z > 0 && /* @__PURE__ */ E("div", {
507
507
  className: "flex items-center justify-between text-sm text-muted-foreground border-t pt-3 mt-2 px-1",
508
508
  "data-testid": "record-picker-pagination",
509
- children: [/* @__PURE__ */ T("span", { children: [
510
- B,
509
+ children: [/* @__PURE__ */ E("span", { children: [
510
+ z,
511
511
  " ",
512
- B === 1 ? "record" : "records",
513
- Q > 1 && ` · Page ${U} of ${Q}`
514
- ] }), Q > 1 && /* @__PURE__ */ T("div", {
512
+ z === 1 ? "record" : "records",
513
+ Q > 1 && ` · Page ${H} of ${Q}`
514
+ ] }), Q > 1 && /* @__PURE__ */ E("div", {
515
515
  className: "flex items-center gap-1.5",
516
516
  children: [
517
- /* @__PURE__ */ w(l, {
517
+ /* @__PURE__ */ T(l, {
518
518
  variant: "outline",
519
519
  size: "icon",
520
520
  className: "size-7",
521
521
  onClick: rt,
522
- disabled: U <= 1,
522
+ disabled: H <= 1,
523
523
  type: "button",
524
524
  "aria-label": "Previous page",
525
- children: /* @__PURE__ */ w(x, { className: "size-4" })
525
+ children: /* @__PURE__ */ T(S, { className: "size-4" })
526
526
  }),
527
- /* @__PURE__ */ w(f, {
527
+ /* @__PURE__ */ T(m, {
528
528
  className: "h-7 w-12 text-center text-xs px-1",
529
- placeholder: String(U),
529
+ placeholder: String(H),
530
530
  value: Ge,
531
531
  onChange: (e) => Ke(e.target.value),
532
532
  onKeyDown: at,
533
533
  "aria-label": "Jump to page",
534
534
  "data-testid": "record-picker-page-jump"
535
535
  }),
536
- /* @__PURE__ */ w(l, {
536
+ /* @__PURE__ */ T(l, {
537
537
  variant: "outline",
538
538
  size: "icon",
539
539
  className: "size-7",
540
540
  onClick: it,
541
- disabled: U >= Q,
541
+ disabled: H >= Q,
542
542
  type: "button",
543
543
  "aria-label": "Next page",
544
- children: /* @__PURE__ */ w(S, { className: "size-4" })
544
+ children: /* @__PURE__ */ T(C, { className: "size-4" })
545
545
  })
546
546
  ]
547
547
  })]
548
548
  })
549
549
  ] }),
550
- c && /* @__PURE__ */ w(ne, { children: /* @__PURE__ */ T("div", {
550
+ c && /* @__PURE__ */ T(d, { children: /* @__PURE__ */ E("div", {
551
551
  className: "flex items-center gap-2 w-full justify-between",
552
- children: [/* @__PURE__ */ T("span", {
552
+ children: [/* @__PURE__ */ E("span", {
553
553
  className: "text-sm text-muted-foreground",
554
- children: [Fe.size, " selected"]
555
- }), /* @__PURE__ */ T("div", {
554
+ children: [J.size, " selected"]
555
+ }), /* @__PURE__ */ E("div", {
556
556
  className: "flex gap-2",
557
- children: [/* @__PURE__ */ w(l, {
557
+ children: [/* @__PURE__ */ T(l, {
558
558
  variant: "outline",
559
559
  type: "button",
560
560
  onClick: () => t(!1),
561
561
  children: "Cancel"
562
- }), /* @__PURE__ */ w(l, {
562
+ }), /* @__PURE__ */ T(l, {
563
563
  type: "button",
564
564
  onClick: nt,
565
565
  children: "Confirm"
@@ -581,7 +581,7 @@ function Oe() {
581
581
  }
582
582
  //#endregion
583
583
  //#region src/widgets/LookupField.tsx
584
- var P = /* @__PURE__ */ e({ LookupField: () => I }), ke = 50, Ae = E;
584
+ var P = /* @__PURE__ */ e({ LookupField: () => I }), ke = 50, Ae = D;
585
585
  function F(e, t, n, r) {
586
586
  let i = e[n] ?? e.id ?? e._id, a = e[t] ?? e.label ?? e.name ?? String(i), o = r ? e[r] : void 0;
587
587
  return {
@@ -604,8 +604,17 @@ function je(e) {
604
604
  boolean: "boolean"
605
605
  }[e];
606
606
  }
607
- function I({ value: e, onChange: u, field: ee, readonly: te, ...ne }) {
608
- let [re, d] = s(!1), [p, ce] = s(""), { t: le } = t(), [ue, de] = s([]), [fe, m] = s(!1), [h, pe] = s(null), [g, me] = s(0), _ = o(null), [v, he] = s([]), [y, _e] = s(-1), ve = o(null), b = ee || ne.schema, x = b?.field, S = x && typeof x == "object" && ("reference_to" in x || "reference" in x || "type" in x) ? x : b, Se = S?.options || [], E = S?.multiple || !1, D = S?.display_field || S?.reference_field || "name", Te = S?.description_field, O = S?.id_field || "id", k = S?.reference_to || S?.reference, A = S?.lookup_columns, Ee = S?.lookup_page_size, De = S?.lookup_filters, M = a(() => {
607
+ function I({ value: e, onChange: u, field: ee, readonly: te, ...d }) {
608
+ let [f, p] = s(!1), [h, oe] = s(""), { t: se } = t(), [ce, le] = s([]), [ue, de] = s(!1), [fe, pe] = s(null), [g, _] = s(0), v = o(null), [y, me] = s([]), [b, ge] = s(-1), _e = o(null), x = ee || d.schema, S = x?.field, C = S && typeof S == "object" && ("reference_to" in S || "reference" in S || "type" in S) ? S : x, xe = C?.options || [], D = C?.multiple || !1, O = C?.display_field || C?.reference_field || "name", we = C?.description_field, Te = C?.id_field || "id", k = C?.reference_to || C?.reference, A = C?.lookup_columns, Ee = C?.lookup_page_size, De = C?.lookup_filters, M = a(() => {
609
+ let e = C?.depends_on ?? C?.dependsOn;
610
+ return e && Array.isArray(e) ? e.map((e) => typeof e == "string" ? {
611
+ field: e,
612
+ param: e
613
+ } : {
614
+ field: e.field,
615
+ param: e.param ?? e.field
616
+ }) : [];
617
+ }, [C?.depends_on, C?.dependsOn]), N = d.dependentValues, P = a(() => {
609
618
  if (!A) return;
610
619
  let e = [];
611
620
  for (let t of A) if (typeof t == "object" && t.type) {
@@ -617,284 +626,310 @@ function I({ value: e, onChange: u, field: ee, readonly: te, ...ne }) {
617
626
  });
618
627
  }
619
628
  return e.length > 0 ? e : void 0;
620
- }, [A]), N = r(Ae)?.dataSource ?? null, P = ne.dataSource ?? b?.dataSource ?? S?.dataSource ?? N, I = P != null && typeof P.find == "function" && !!k, L = ne.onCreateNew ?? b?.onCreateNew, [R, z] = s(!1), B = I ? ue : Se, V = a(() => {
621
- if (I || !p) return B;
622
- let e = p.toLowerCase();
623
- return B.filter((t) => t.label.toLowerCase().includes(e) || t.description && t.description.toLowerCase().includes(e));
629
+ }, [A]), I = r(Ae), Me = I?.dataSource ?? null, L = d.dataSource ?? x?.dataSource ?? C?.dataSource ?? Me, R = a(() => N || (I?.formValues ?? I?.data ?? {}), [
630
+ N,
631
+ I?.formValues,
632
+ I?.data
633
+ ]), z = a(() => M.length === 0 ? !1 : M.some(({ field: e }) => {
634
+ let t = R[e];
635
+ return t == null || t === "" || Array.isArray(t) && t.length === 0;
636
+ }), [M, R]), B = L != null && typeof L.find == "function" && !!k, V = d.onCreateNew ?? x?.onCreateNew, [Ne, H] = s(!1), U = B ? ce : xe, W = a(() => {
637
+ if (B || !h) return U;
638
+ let e = h.toLowerCase();
639
+ return U.filter((t) => t.label.toLowerCase().includes(e) || t.description && t.description.toLowerCase().includes(e));
624
640
  }, [
625
- I,
626
641
  B,
627
- p
642
+ U,
643
+ h
628
644
  ]);
629
645
  i(() => {
630
- _e(-1);
631
- }, [V.length]);
632
- let H = n(async (e) => {
633
- if (!(!P || !k)) {
634
- m(!0), pe(null);
646
+ ge(-1);
647
+ }, [W.length]);
648
+ let G = n(async (e) => {
649
+ if (!(!L || !k)) {
650
+ if (z) {
651
+ le([]), _(0);
652
+ return;
653
+ }
654
+ de(!0), pe(null);
635
655
  try {
636
656
  let t = { $top: ke };
637
- e && e.trim() && (t.$search = e.trim());
638
- let n = await P.find(k, t), r = n?.data ?? n ?? [];
639
- de(r.map((e) => F(e, D, O, Te))), me(n?.total ?? r.length);
657
+ if (e && e.trim() && (t.$search = e.trim()), M.length > 0) {
658
+ let e = {};
659
+ for (let { field: t, param: n } of M) {
660
+ let r = R[t];
661
+ r == null || r === "" || (e[n] = typeof r == "number" ? r : String(r));
662
+ }
663
+ Object.keys(e).length > 0 && (t.$filter = e);
664
+ }
665
+ let n = await L.find(k, t), r = n?.data ?? n ?? [];
666
+ le(r.map((e) => F(e, O, Te, we))), _(n?.total ?? r.length);
640
667
  } catch (e) {
641
- pe(e instanceof Error ? e.message : String(e)), de([]);
668
+ pe(e instanceof Error ? e.message : String(e)), le([]);
642
669
  } finally {
643
- m(!1);
670
+ de(!1);
644
671
  }
645
672
  }
646
673
  }, [
647
- P,
674
+ L,
648
675
  k,
649
- D,
650
676
  O,
651
- Te
677
+ Te,
678
+ we,
679
+ z,
680
+ M,
681
+ R
652
682
  ]);
653
683
  i(() => {
654
- re && I && H(p || void 0), re || (ce(""), pe(null), _e(-1));
655
- }, [re]);
656
- let Me = n((e) => {
657
- ce(e), I && (_.current && clearTimeout(_.current), _.current = setTimeout(() => {
658
- H(e || void 0);
684
+ f && B && M.length > 0 && G(h || void 0);
685
+ }, [a(() => M.map((e) => `${e.param}=${R[e.field] ?? ""}`).join("|"), [M, R])]), i(() => {
686
+ f && B && G(h || void 0), f || (oe(""), pe(null), ge(-1));
687
+ }, [f]);
688
+ let Pe = n((e) => {
689
+ oe(e), B && (v.current && clearTimeout(v.current), v.current = setTimeout(() => {
690
+ G(e || void 0);
659
691
  }, 300));
660
- }, [I, H]);
692
+ }, [B, G]);
661
693
  i(() => () => {
662
- _.current && clearTimeout(_.current);
694
+ v.current && clearTimeout(v.current);
663
695
  }, []);
664
- let U = n((e) => Se.find((t) => t.value === e) ?? ue.find((t) => t.value === e) ?? v.find((t) => t.value === e), [
665
- Se,
666
- ue,
667
- v
668
- ]), W = E ? (Array.isArray(e) ? e : []).map(U).filter(Boolean) : e ? [U(e)].filter(Boolean) : [], G = n((t) => {
669
- if (E) {
696
+ let K = n((e) => xe.find((t) => t.value === e) ?? ce.find((t) => t.value === e) ?? y.find((t) => t.value === e), [
697
+ xe,
698
+ ce,
699
+ y
700
+ ]), q = D ? (Array.isArray(e) ? e : []).map(K).filter(Boolean) : e ? [K(e)].filter(Boolean) : [], J = n((t) => {
701
+ if (D) {
670
702
  let n = Array.isArray(e) ? e : [];
671
703
  n.includes(t.value) ? u(n.filter((e) => e !== t.value)) : u([...n, t.value]);
672
- } else u(t.value), d(!1);
704
+ } else u(t.value), p(!1);
673
705
  }, [
674
- E,
706
+ D,
675
707
  e,
676
708
  u
677
- ]), K = (t) => {
678
- u(E ? (Array.isArray(e) ? e : []).filter((e) => e !== t) : null);
679
- }, Ne = n((e) => {
680
- he(e.map((e) => F(e, D, O, Te)));
709
+ ]), Fe = (t) => {
710
+ u(D ? (Array.isArray(e) ? e : []).filter((e) => e !== t) : null);
711
+ }, Ie = n((e) => {
712
+ me(e.map((e) => F(e, O, Te, we)));
681
713
  }, [
682
- D,
683
714
  O,
684
- Te
685
- ]), q = n((e) => {
686
- e.key === "ArrowDown" ? (e.preventDefault(), _e((e) => e < V.length - 1 ? e + 1 : e)) : e.key === "ArrowUp" ? (e.preventDefault(), _e((e) => e > 0 ? e - 1 : 0)) : e.key === "Enter" && (e.preventDefault(), y >= 0 && y < V.length && G(V[y]));
715
+ Te,
716
+ we
717
+ ]), Y = n((e) => {
718
+ e.key === "ArrowDown" ? (e.preventDefault(), ge((e) => e < W.length - 1 ? e + 1 : e)) : e.key === "ArrowUp" ? (e.preventDefault(), ge((e) => e > 0 ? e - 1 : 0)) : e.key === "Enter" && (e.preventDefault(), b >= 0 && b < W.length && J(W[b]));
687
719
  }, [
688
- V,
689
- y,
690
- G
720
+ W,
721
+ b,
722
+ J
691
723
  ]);
692
724
  return i(() => {
693
- y >= 0 && ve.current && ve.current.querySelector(`[data-lookup-index="${y}"]`)?.scrollIntoView({ block: "nearest" });
694
- }, [y]), te ? W.length ? E ? /* @__PURE__ */ w("div", {
725
+ b >= 0 && _e.current && _e.current.querySelector(`[data-lookup-index="${b}"]`)?.scrollIntoView({ block: "nearest" });
726
+ }, [b]), te ? q.length ? D ? /* @__PURE__ */ T("div", {
695
727
  className: "flex flex-wrap gap-1",
696
- children: W.map((e, t) => /* @__PURE__ */ w(c, {
728
+ children: q.map((e, t) => /* @__PURE__ */ T(c, {
697
729
  variant: "outline",
698
- children: e?.[D] || e?.label
730
+ children: e?.[O] || e?.label
699
731
  }, t))
700
- }) : /* @__PURE__ */ w("span", {
732
+ }) : /* @__PURE__ */ T("span", {
701
733
  className: "text-sm",
702
- children: W[0]?.[D] || W[0]?.label
703
- }) : /* @__PURE__ */ w(ie, {}) : /* @__PURE__ */ T("div", {
734
+ children: q[0]?.[O] || q[0]?.label
735
+ }) : /* @__PURE__ */ T(ne, {}) : /* @__PURE__ */ E("div", {
704
736
  className: "space-y-2",
705
737
  children: [
706
- W.length > 0 && /* @__PURE__ */ w("div", {
738
+ q.length > 0 && /* @__PURE__ */ T("div", {
707
739
  className: "flex flex-wrap gap-1",
708
- children: W.map((e, t) => /* @__PURE__ */ T(c, {
740
+ children: q.map((e, t) => /* @__PURE__ */ E(c, {
709
741
  variant: "outline",
710
742
  className: "gap-1",
711
- children: [e?.[D] || e?.label, /* @__PURE__ */ w("button", {
712
- onClick: () => K(e?.value),
743
+ children: [e?.[O] || e?.label, /* @__PURE__ */ T("button", {
744
+ onClick: () => Fe(e?.value),
713
745
  className: "ml-1 hover:text-destructive",
714
746
  type: "button",
715
- "aria-label": `Remove ${e?.[D] || e?.label}`,
716
- children: /* @__PURE__ */ w(Ce, { className: "size-3" })
747
+ "aria-label": `Remove ${e?.[O] || e?.label}`,
748
+ children: /* @__PURE__ */ T(Se, { className: "size-3" })
717
749
  })]
718
750
  }, t))
719
751
  }),
720
- /* @__PURE__ */ T("div", {
752
+ /* @__PURE__ */ E("div", {
721
753
  className: "flex items-center gap-1.5",
722
- children: [/* @__PURE__ */ T(ae, {
723
- open: re,
724
- onOpenChange: d,
725
- children: [/* @__PURE__ */ w(se, {
754
+ children: [/* @__PURE__ */ E(re, {
755
+ open: f,
756
+ onOpenChange: (e) => !z && p(e),
757
+ children: [/* @__PURE__ */ T(ae, {
726
758
  asChild: !0,
727
- children: /* @__PURE__ */ T(l, {
759
+ children: /* @__PURE__ */ E(l, {
728
760
  variant: "outline",
729
761
  className: "min-w-0 flex-1 justify-start text-left font-normal",
730
762
  type: "button",
731
- children: [/* @__PURE__ */ w(xe, { className: "mr-2 size-4" }), W.length === 0 ? b?.placeholder || le("common.select") : E ? le("table.selected", { count: W.length }) : le("common.select")]
763
+ disabled: z || d.disabled,
764
+ "data-testid": z ? "lookup-trigger-gated" : void 0,
765
+ title: z ? `Select ${M.map((e) => e.field).join(", ")} first` : void 0,
766
+ children: [/* @__PURE__ */ T(be, { className: "mr-2 size-4" }), z ? `Select ${M.map((e) => e.field).join(", ")} first` : q.length === 0 ? x?.placeholder || se("common.select") : D ? se("table.selected", { count: q.length }) : se("common.select")]
732
767
  })
733
- }), /* @__PURE__ */ T(oe, {
768
+ }), /* @__PURE__ */ E(ie, {
734
769
  className: "w-[var(--radix-popover-trigger-width)] p-0",
735
770
  align: "start",
736
771
  children: [
737
- /* @__PURE__ */ w("div", {
772
+ /* @__PURE__ */ T("div", {
738
773
  className: "p-2",
739
- children: /* @__PURE__ */ T("div", {
774
+ children: /* @__PURE__ */ E("div", {
740
775
  className: "relative",
741
776
  children: [
742
- /* @__PURE__ */ w(xe, { className: "absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground" }),
743
- /* @__PURE__ */ w(f, {
744
- placeholder: le("common.search") + "...",
745
- value: p,
746
- onChange: (e) => Me(e.target.value),
747
- onKeyDown: q,
777
+ /* @__PURE__ */ T(be, { className: "absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground" }),
778
+ /* @__PURE__ */ T(m, {
779
+ placeholder: se("common.search") + "...",
780
+ value: h,
781
+ onChange: (e) => Pe(e.target.value),
782
+ onKeyDown: Y,
748
783
  className: "w-full pl-9 h-8 text-sm"
749
784
  }),
750
- fe && /* @__PURE__ */ w(ye, {
785
+ ue && /* @__PURE__ */ T(ve, {
751
786
  className: "absolute right-3 top-1/2 -translate-y-1/2 size-4 animate-spin text-muted-foreground",
752
787
  "data-testid": "lookup-loading"
753
788
  })
754
789
  ]
755
790
  })
756
791
  }),
757
- h && /* @__PURE__ */ T("div", {
792
+ fe && /* @__PURE__ */ E("div", {
758
793
  className: "flex flex-col items-center gap-2 py-4 px-2",
759
794
  role: "alert",
760
795
  children: [
761
- /* @__PURE__ */ w(ge, { className: "size-5 text-destructive" }),
762
- /* @__PURE__ */ w("p", {
796
+ /* @__PURE__ */ T(he, { className: "size-5 text-destructive" }),
797
+ /* @__PURE__ */ T("p", {
763
798
  className: "text-sm text-destructive",
764
- children: h
799
+ children: fe
765
800
  }),
766
- /* @__PURE__ */ w(l, {
801
+ /* @__PURE__ */ T(l, {
767
802
  variant: "outline",
768
803
  size: "sm",
769
- onClick: () => H(p || void 0),
804
+ onClick: () => G(h || void 0),
770
805
  type: "button",
771
806
  children: "Retry"
772
807
  })
773
808
  ]
774
809
  }),
775
- fe && V.length === 0 && !h && /* @__PURE__ */ T("div", {
810
+ ue && W.length === 0 && !fe && /* @__PURE__ */ E("div", {
776
811
  className: "flex flex-col items-center gap-2 py-6",
777
812
  role: "status",
778
813
  "aria-live": "polite",
779
- children: [/* @__PURE__ */ w(ye, { className: "size-6 animate-spin text-muted-foreground" }), /* @__PURE__ */ w("p", {
814
+ children: [/* @__PURE__ */ T(ve, { className: "size-6 animate-spin text-muted-foreground" }), /* @__PURE__ */ T("p", {
780
815
  className: "text-sm text-muted-foreground",
781
816
  children: "Loading…"
782
817
  })]
783
818
  }),
784
- !h && !(fe && V.length === 0) && /* @__PURE__ */ w("div", {
785
- ref: ve,
819
+ !fe && !(ue && W.length === 0) && /* @__PURE__ */ T("div", {
820
+ ref: _e,
786
821
  className: "max-h-64 overflow-y-auto px-1 pb-1",
787
822
  role: "listbox",
788
- children: V.length === 0 ? /* @__PURE__ */ T("div", {
823
+ children: W.length === 0 ? /* @__PURE__ */ E("div", {
789
824
  className: "py-4 text-center",
790
- children: [/* @__PURE__ */ w("p", {
825
+ children: [/* @__PURE__ */ T("p", {
791
826
  className: "text-sm text-muted-foreground",
792
827
  children: "No options found"
793
- }), L && /* @__PURE__ */ T(l, {
828
+ }), V && /* @__PURE__ */ E(l, {
794
829
  variant: "ghost",
795
830
  size: "sm",
796
831
  className: "mt-2 gap-1",
797
832
  type: "button",
798
833
  onClick: () => {
799
- L(p), d(!1);
834
+ V(h), p(!1);
800
835
  },
801
- children: [/* @__PURE__ */ w(be, { className: "size-4" }), "Create new"]
836
+ children: [/* @__PURE__ */ T(ye, { className: "size-4" }), "Create new"]
802
837
  })]
803
- }) : /* @__PURE__ */ T(we, { children: [
804
- V.map((t, n) => {
805
- let r = E ? (Array.isArray(e) ? e : []).includes(t.value) : e === t.value;
806
- return /* @__PURE__ */ T("button", {
838
+ }) : /* @__PURE__ */ E(Ce, { children: [
839
+ W.map((t, n) => {
840
+ let r = D ? (Array.isArray(e) ? e : []).includes(t.value) : e === t.value;
841
+ return /* @__PURE__ */ E("button", {
807
842
  "data-lookup-index": n,
808
843
  role: "option",
809
844
  "aria-selected": r,
810
- onClick: () => G(t),
811
- className: `w-full text-left px-3 py-2 rounded-md text-sm hover:bg-accent flex items-center justify-between ${n === y ? "bg-accent text-accent-foreground" : r ? "bg-accent/50 text-accent-foreground" : ""}`,
845
+ onClick: () => J(t),
846
+ className: `w-full text-left px-3 py-2 rounded-md text-sm hover:bg-accent flex items-center justify-between ${n === b ? "bg-accent text-accent-foreground" : r ? "bg-accent/50 text-accent-foreground" : ""}`,
812
847
  type: "button",
813
- children: [/* @__PURE__ */ T("div", {
848
+ children: [/* @__PURE__ */ E("div", {
814
849
  className: "min-w-0 flex-1",
815
- children: [/* @__PURE__ */ w("span", {
850
+ children: [/* @__PURE__ */ T("span", {
816
851
  className: "block truncate",
817
852
  children: t.label
818
- }), t.description && /* @__PURE__ */ w("span", {
853
+ }), t.description && /* @__PURE__ */ T("span", {
819
854
  className: "block truncate text-xs text-muted-foreground",
820
855
  children: t.description
821
856
  })]
822
- }), r && /* @__PURE__ */ w(c, {
857
+ }), r && /* @__PURE__ */ T(c, {
823
858
  variant: "default",
824
859
  className: "ml-2 shrink-0",
825
860
  children: "Selected"
826
861
  })]
827
862
  }, t.value);
828
863
  }),
829
- I && g > V.length && /* @__PURE__ */ T("p", {
864
+ B && g > W.length && /* @__PURE__ */ E("p", {
830
865
  className: "text-xs text-muted-foreground text-center py-2",
831
866
  children: [
832
867
  "Showing ",
833
- V.length,
868
+ W.length,
834
869
  " of ",
835
870
  g,
836
871
  " results."
837
872
  ]
838
873
  }),
839
- I && g > V.length && /* @__PURE__ */ T("button", {
874
+ B && g > W.length && /* @__PURE__ */ E("button", {
840
875
  type: "button",
841
876
  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",
842
877
  onClick: () => {
843
- d(!1), z(!0);
878
+ p(!1), H(!0);
844
879
  },
845
880
  "data-testid": "show-all-results",
846
881
  children: [
847
- /* @__PURE__ */ w(C, { className: "size-3.5" }),
882
+ /* @__PURE__ */ T(w, { className: "size-3.5" }),
848
883
  "Show All Results (",
849
884
  g,
850
885
  ")"
851
886
  ]
852
887
  }),
853
- L && /* @__PURE__ */ T("button", {
888
+ V && /* @__PURE__ */ E("button", {
854
889
  type: "button",
855
890
  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",
856
891
  onClick: () => {
857
- L(p), d(!1);
892
+ V(h), p(!1);
858
893
  },
859
894
  children: [
860
- /* @__PURE__ */ w(be, { className: "size-3.5" }),
895
+ /* @__PURE__ */ T(ye, { className: "size-3.5" }),
861
896
  "Create new",
862
- p ? ` "${p}"` : ""
897
+ h ? ` "${h}"` : ""
863
898
  ]
864
899
  })
865
900
  ] })
866
901
  })
867
902
  ]
868
903
  })]
869
- }), I && /* @__PURE__ */ w(l, {
904
+ }), B && /* @__PURE__ */ T(l, {
870
905
  variant: "outline",
871
906
  size: "icon",
872
907
  className: "shrink-0",
873
908
  type: "button",
874
- onClick: () => z(!0),
909
+ onClick: () => H(!0),
875
910
  "aria-label": "Browse all records",
876
911
  title: "Browse all records",
877
912
  "data-testid": "browse-all-records",
878
- children: /* @__PURE__ */ w(C, { className: "size-4" })
913
+ children: /* @__PURE__ */ T(w, { className: "size-4" })
879
914
  })]
880
915
  }),
881
- I && P && k && /* @__PURE__ */ w(j, {
882
- open: R,
883
- onOpenChange: z,
884
- title: b?.label || "Select",
885
- multiple: E,
886
- dataSource: P,
916
+ B && L && k && /* @__PURE__ */ T(j, {
917
+ open: Ne,
918
+ onOpenChange: H,
919
+ title: x?.label || "Select",
920
+ multiple: D,
921
+ dataSource: L,
887
922
  objectName: k,
888
923
  columns: A,
889
- displayField: D,
890
- idField: O,
924
+ displayField: O,
925
+ idField: Te,
891
926
  pageSize: Ee,
892
927
  value: e,
893
928
  onSelect: u,
894
- onSelectRecords: Ne,
929
+ onSelectRecords: Ie,
895
930
  lookupFilters: De,
896
931
  cellRenderer: Oe(),
897
- filterColumns: M
932
+ filterColumns: P
898
933
  })
899
934
  ]
900
935
  });