@object-ui/fields 3.1.5 → 3.3.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.
Files changed (183) hide show
  1. package/CHANGELOG.md +141 -0
  2. package/README.md +24 -0
  3. package/dist/LookupField-CiIjeL_i.cjs +1 -0
  4. package/dist/LookupField-De-GqsfT.js +903 -0
  5. package/dist/chunk-D-qHiVGv.cjs +1 -0
  6. package/dist/index.cjs +3 -3
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.js +704 -690
  9. package/dist/packages/fields/src/widgets/useFieldTranslation.d.ts +5 -0
  10. package/dist/rolldown-runtime-CAFD8bLK.js +11 -0
  11. package/dist/useFieldTranslation-BYPwtuNZ.cjs +1 -0
  12. package/dist/useFieldTranslation-Bv3oUVgb.js +9 -0
  13. package/package.json +35 -9
  14. package/src/__tests__/cell-renderers.test.tsx +39 -18
  15. package/src/__tests__/datetime-cell.test.tsx +2 -2
  16. package/src/__tests__/datetime-timezone.test.tsx +9 -9
  17. package/src/__tests__/validation-feedback.test.tsx +8 -8
  18. package/src/datetime-widgets.test.tsx +1 -1
  19. package/src/index.tsx +54 -28
  20. package/src/record-picker.test.tsx +30 -23
  21. package/src/remaining-widgets.test.tsx +1 -1
  22. package/src/widgets/AddressField.tsx +4 -3
  23. package/src/widgets/AutoNumberField.tsx +5 -3
  24. package/src/widgets/CodeField.tsx +2 -2
  25. package/src/widgets/ColorField.tsx +2 -2
  26. package/src/widgets/CurrencyField.tsx +2 -2
  27. package/src/widgets/DateField.tsx +2 -2
  28. package/src/widgets/DateTimeField.tsx +2 -2
  29. package/src/widgets/EmailField.tsx +2 -2
  30. package/src/widgets/FileField.tsx +2 -2
  31. package/src/widgets/FormulaField.tsx +14 -12
  32. package/src/widgets/GeolocationField.tsx +4 -3
  33. package/src/widgets/GridField.tsx +3 -3
  34. package/src/widgets/ImageField.tsx +2 -2
  35. package/src/widgets/LocationField.tsx +2 -2
  36. package/src/widgets/LookupField.tsx +8 -8
  37. package/src/widgets/NumberField.tsx +2 -2
  38. package/src/widgets/ObjectField.tsx +2 -2
  39. package/src/widgets/PercentField.tsx +2 -2
  40. package/src/widgets/PhoneField.tsx +2 -2
  41. package/src/widgets/QRCodeField.tsx +2 -2
  42. package/src/widgets/RichTextField.tsx +2 -2
  43. package/src/widgets/SelectField.tsx +12 -8
  44. package/src/widgets/SummaryField.tsx +12 -10
  45. package/src/widgets/TextAreaField.tsx +2 -2
  46. package/src/widgets/TextField.tsx +2 -2
  47. package/src/widgets/TimeField.tsx +2 -2
  48. package/src/widgets/UrlField.tsx +2 -2
  49. package/src/widgets/UserField.tsx +2 -2
  50. package/src/widgets/VectorField.tsx +2 -1
  51. package/src/widgets/useFieldTranslation.ts +17 -0
  52. package/dist/AddressField-B6fPb2Fs.js +0 -3
  53. package/dist/AddressField-Ctsxkj35.cjs +0 -1
  54. package/dist/AutoNumberField-DXIYJfiB.js +0 -3
  55. package/dist/AutoNumberField-f76XU1bR.cjs +0 -1
  56. package/dist/AvatarField-BHpex3Wa.js +0 -3
  57. package/dist/AvatarField-CXOdYavl.cjs +0 -1
  58. package/dist/BooleanField-Bs0urhsx.js +0 -3
  59. package/dist/BooleanField-DeexI_O2.cjs +0 -1
  60. package/dist/CodeField-DDOMH8E8.cjs +0 -1
  61. package/dist/CodeField-tRACqngO.js +0 -3
  62. package/dist/ColorField-Bar6bOJw.js +0 -3
  63. package/dist/ColorField-CM9CxZ9h.cjs +0 -1
  64. package/dist/CurrencyField-CezTX_rA.cjs +0 -1
  65. package/dist/CurrencyField-D4VwXI9k.js +0 -3
  66. package/dist/DateField-DDUllj7w.cjs +0 -1
  67. package/dist/DateField-DjGiK6BH.js +0 -3
  68. package/dist/DateTimeField-DBh-dYdR.js +0 -3
  69. package/dist/DateTimeField-DDqgVN3b.cjs +0 -1
  70. package/dist/EmailField-B-3nY8Pr.cjs +0 -1
  71. package/dist/EmailField-Cp6yJlpH.js +0 -3
  72. package/dist/FileField-C1bcL7tu.cjs +0 -1
  73. package/dist/FileField-DUgt6ai3.js +0 -3
  74. package/dist/FormulaField-BLV1KgkQ.js +0 -3
  75. package/dist/FormulaField-CsbQIZ7S.cjs +0 -1
  76. package/dist/GeolocationField-BbIRH51u.js +0 -3
  77. package/dist/GeolocationField-UFu9VR-x.cjs +0 -1
  78. package/dist/GridField-2m74haE0.cjs +0 -1
  79. package/dist/GridField-O3Jd1NuJ.js +0 -3
  80. package/dist/ImageField-Cna7g6KL.cjs +0 -1
  81. package/dist/ImageField-rc1Nzcvb.js +0 -3
  82. package/dist/LocationField-DpRe9QlH.cjs +0 -1
  83. package/dist/LocationField-QZPPYo0J.js +0 -3
  84. package/dist/LookupField-BX4sK8NG.js +0 -904
  85. package/dist/LookupField-C9rPrHi_.cjs +0 -1
  86. package/dist/MasterDetailField-BXncIT1s.js +0 -3
  87. package/dist/MasterDetailField-TNP2825Z.cjs +0 -1
  88. package/dist/NumberField-DCHTzmDG.js +0 -3
  89. package/dist/NumberField-SqRwbcY8.cjs +0 -1
  90. package/dist/ObjectField-BEUHpn_X.js +0 -3
  91. package/dist/ObjectField-BWZwaFIG.cjs +0 -1
  92. package/dist/PasswordField-BZ_OeQyw.js +0 -3
  93. package/dist/PasswordField-kLp-ZyPm.cjs +0 -1
  94. package/dist/PercentField-B2t2knlc.js +0 -3
  95. package/dist/PercentField-BzhD6tQm.cjs +0 -1
  96. package/dist/PhoneField-CirvuysP.cjs +0 -1
  97. package/dist/PhoneField-CkrCFmcO.js +0 -3
  98. package/dist/QRCodeField-C4OOLCbE.cjs +0 -1
  99. package/dist/QRCodeField-CQoGow8y.js +0 -3
  100. package/dist/RatingField-CZG8SgQ8.cjs +0 -1
  101. package/dist/RatingField-DecDJkou.js +0 -3
  102. package/dist/RichTextField-Bog2i4NN.cjs +0 -1
  103. package/dist/RichTextField-b-8QbNCJ.js +0 -3
  104. package/dist/SelectField-CAa6c0cB.cjs +0 -1
  105. package/dist/SelectField-DMy5IxRc.js +0 -3
  106. package/dist/SignatureField-BvTPE7Dn.js +0 -3
  107. package/dist/SignatureField-jsb-0AYp.cjs +0 -1
  108. package/dist/SliderField-B7WvKFv7.js +0 -3
  109. package/dist/SliderField-DRjEJSxK.cjs +0 -1
  110. package/dist/SummaryField-DA16Edq3.cjs +0 -1
  111. package/dist/SummaryField-DVSVfKmY.js +0 -3
  112. package/dist/TextAreaField--ut87UiB.js +0 -3
  113. package/dist/TextAreaField-Cxp3DFC6.cjs +0 -1
  114. package/dist/TextField-CkEDGbkQ.js +0 -3
  115. package/dist/TextField-aLAzBaLZ.cjs +0 -1
  116. package/dist/TimeField-D0lF0y_I.cjs +0 -1
  117. package/dist/TimeField-DA_S6lQV.js +0 -3
  118. package/dist/UrlField-D0ugmD3f.cjs +0 -1
  119. package/dist/UrlField-DCnXHR1A.js +0 -3
  120. package/dist/UserField-DGlorzyG.cjs +0 -1
  121. package/dist/UserField-V0GmvyGV.js +0 -3
  122. package/dist/VectorField-BSD85ntU.cjs +0 -1
  123. package/dist/VectorField-CVi5yrrc.js +0 -3
  124. package/dist/jsx-runtime-DHCF5ANT.cjs +0 -6
  125. package/dist/jsx-runtime-MxADXuRH.js +0 -189
  126. /package/dist/{fields → packages/fields}/src/__tests__/boolean-checkbox.test.d.ts +0 -0
  127. /package/dist/{fields → packages/fields}/src/__tests__/cell-renderers.test.d.ts +0 -0
  128. /package/dist/{fields → packages/fields}/src/__tests__/datetime-cell.test.d.ts +0 -0
  129. /package/dist/{fields → packages/fields}/src/__tests__/datetime-timezone.test.d.ts +0 -0
  130. /package/dist/{fields → packages/fields}/src/__tests__/extreme-inputs.test.d.ts +0 -0
  131. /package/dist/{fields → packages/fields}/src/__tests__/form-variants.test.d.ts +0 -0
  132. /package/dist/{fields → packages/fields}/src/__tests__/validation-feedback.test.d.ts +0 -0
  133. /package/dist/{fields → packages/fields}/src/complex-widgets.test.d.ts +0 -0
  134. /package/dist/{fields → packages/fields}/src/datetime-widgets.test.d.ts +0 -0
  135. /package/dist/{fields → packages/fields}/src/fields-edge-cases.stories.d.ts +0 -0
  136. /package/dist/{fields → packages/fields}/src/fields.stories.d.ts +0 -0
  137. /package/dist/{fields → packages/fields}/src/index.d.ts +0 -0
  138. /package/dist/{fields → packages/fields}/src/new-widgets.test.d.ts +0 -0
  139. /package/dist/{fields → packages/fields}/src/record-picker-dialog.stories.d.ts +0 -0
  140. /package/dist/{fields → packages/fields}/src/record-picker.test.d.ts +0 -0
  141. /package/dist/{fields → packages/fields}/src/remaining-widgets.test.d.ts +0 -0
  142. /package/dist/{fields → packages/fields}/src/standard-widgets.test.d.ts +0 -0
  143. /package/dist/{fields → packages/fields}/src/text-rich-widgets.test.d.ts +0 -0
  144. /package/dist/{fields → packages/fields}/src/visual-widgets.test.d.ts +0 -0
  145. /package/dist/{fields → packages/fields}/src/widgets/AddressField.d.ts +0 -0
  146. /package/dist/{fields → packages/fields}/src/widgets/AutoNumberField.d.ts +0 -0
  147. /package/dist/{fields → packages/fields}/src/widgets/AvatarField.d.ts +0 -0
  148. /package/dist/{fields → packages/fields}/src/widgets/BooleanField.d.ts +0 -0
  149. /package/dist/{fields → packages/fields}/src/widgets/CodeField.d.ts +0 -0
  150. /package/dist/{fields → packages/fields}/src/widgets/ColorField.d.ts +0 -0
  151. /package/dist/{fields → packages/fields}/src/widgets/CurrencyField.d.ts +0 -0
  152. /package/dist/{fields → packages/fields}/src/widgets/DateField.d.ts +0 -0
  153. /package/dist/{fields → packages/fields}/src/widgets/DateTimeField.d.ts +0 -0
  154. /package/dist/{fields → packages/fields}/src/widgets/EmailField.d.ts +0 -0
  155. /package/dist/{fields → packages/fields}/src/widgets/FileField.d.ts +0 -0
  156. /package/dist/{fields → packages/fields}/src/widgets/FormulaField.d.ts +0 -0
  157. /package/dist/{fields → packages/fields}/src/widgets/GeolocationField.d.ts +0 -0
  158. /package/dist/{fields → packages/fields}/src/widgets/GridField.d.ts +0 -0
  159. /package/dist/{fields → packages/fields}/src/widgets/ImageField.d.ts +0 -0
  160. /package/dist/{fields → packages/fields}/src/widgets/LocationField.d.ts +0 -0
  161. /package/dist/{fields → packages/fields}/src/widgets/LookupField.d.ts +0 -0
  162. /package/dist/{fields → packages/fields}/src/widgets/MasterDetailField.d.ts +0 -0
  163. /package/dist/{fields → packages/fields}/src/widgets/NumberField.d.ts +0 -0
  164. /package/dist/{fields → packages/fields}/src/widgets/ObjectField.d.ts +0 -0
  165. /package/dist/{fields → packages/fields}/src/widgets/PasswordField.d.ts +0 -0
  166. /package/dist/{fields → packages/fields}/src/widgets/PercentField.d.ts +0 -0
  167. /package/dist/{fields → packages/fields}/src/widgets/PhoneField.d.ts +0 -0
  168. /package/dist/{fields → packages/fields}/src/widgets/QRCodeField.d.ts +0 -0
  169. /package/dist/{fields → packages/fields}/src/widgets/RatingField.d.ts +0 -0
  170. /package/dist/{fields → packages/fields}/src/widgets/RecordPickerDialog.d.ts +0 -0
  171. /package/dist/{fields → packages/fields}/src/widgets/RichTextField.d.ts +0 -0
  172. /package/dist/{fields → packages/fields}/src/widgets/SelectField.d.ts +0 -0
  173. /package/dist/{fields → packages/fields}/src/widgets/SignatureField.d.ts +0 -0
  174. /package/dist/{fields → packages/fields}/src/widgets/SliderField.d.ts +0 -0
  175. /package/dist/{fields → packages/fields}/src/widgets/SummaryField.d.ts +0 -0
  176. /package/dist/{fields → packages/fields}/src/widgets/TextAreaField.d.ts +0 -0
  177. /package/dist/{fields → packages/fields}/src/widgets/TextField.d.ts +0 -0
  178. /package/dist/{fields → packages/fields}/src/widgets/TimeField.d.ts +0 -0
  179. /package/dist/{fields → packages/fields}/src/widgets/UrlField.d.ts +0 -0
  180. /package/dist/{fields → packages/fields}/src/widgets/UserField.d.ts +0 -0
  181. /package/dist/{fields → packages/fields}/src/widgets/VectorField.d.ts +0 -0
  182. /package/dist/{fields → packages/fields}/src/widgets/_cell-renderer-bridge.d.ts +0 -0
  183. /package/dist/{fields → packages/fields}/src/widgets/types.d.ts +0 -0
@@ -0,0 +1,903 @@
1
+ import { t as e } from "./rolldown-runtime-CAFD8bLK.js";
2
+ import { t } from "./useFieldTranslation-Bv3oUVgb.js";
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";
8
+ //#region src/widgets/RecordPickerDialog.tsx
9
+ var D = 10, Te = 60, O = 5;
10
+ function k(e) {
11
+ return typeof e == "string" ? { field: e } : e;
12
+ }
13
+ function A(e) {
14
+ return e.replace(/_/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").replace(/\b\w/g, (e) => e.toUpperCase());
15
+ }
16
+ function Ee(e) {
17
+ let t = {};
18
+ for (let n of e) switch (n.operator) {
19
+ case "eq":
20
+ t[n.field] = n.value;
21
+ break;
22
+ case "ne":
23
+ t[n.field] = { $ne: n.value };
24
+ break;
25
+ case "gt":
26
+ t[n.field] = { $gt: n.value };
27
+ break;
28
+ case "lt":
29
+ t[n.field] = { $lt: n.value };
30
+ break;
31
+ case "gte":
32
+ t[n.field] = { $gte: n.value };
33
+ break;
34
+ case "lte":
35
+ t[n.field] = { $lte: n.value };
36
+ break;
37
+ case "contains":
38
+ t[n.field] = { $contains: n.value };
39
+ break;
40
+ case "in":
41
+ t[n.field] = { $in: n.value };
42
+ break;
43
+ case "notIn":
44
+ t[n.field] = { $nin: n.value };
45
+ break;
46
+ }
47
+ return t;
48
+ }
49
+ function De(e, t) {
50
+ let n = {};
51
+ for (let r of t) {
52
+ let t = e[r.field];
53
+ t == null || t === "" || (r.type === "boolean" ? n[r.field] = !!t : r.type === "text" ? n[r.field] = { $contains: t } : n[r.field] = t);
54
+ }
55
+ return n;
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(() => {
62
+ if (P && P.length > 0) return P;
63
+ if (N && N.length > 0) return N.map((e) => {
64
+ let t = "text";
65
+ 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"), {
66
+ field: e.field,
67
+ label: A(e.field),
68
+ type: t,
69
+ ...Array.isArray(e.value) ? { options: e.value.map((e) => {
70
+ if (typeof e == "object" && e) {
71
+ let t = e;
72
+ return {
73
+ label: String(t.name || t.label || t.title || e),
74
+ value: e
75
+ };
76
+ }
77
+ return {
78
+ label: String(e),
79
+ value: e
80
+ };
81
+ }) } : {}
82
+ };
83
+ });
84
+ }, [P, N]), Je = a(() => {
85
+ let e = N?.length ? Ee(N) : {}, t = Z?.length ? De(Y, Z) : {}, n = {
86
+ ...e,
87
+ ...t
88
+ };
89
+ return Object.keys(n).length > 0 ? n : void 0;
90
+ }, [
91
+ N,
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);
97
+ try {
98
+ let i = {
99
+ $top: C,
100
+ $skip: (t - 1) * C
101
+ };
102
+ e && e.trim() && (i.$search = e.trim()), n && (i.$orderby = { [n.field]: n.direction });
103
+ let a = r === void 0 ? Je : r;
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);
107
+ } catch (e) {
108
+ z(e instanceof Error ? e.message : String(e)), je([]);
109
+ } finally {
110
+ L(!1);
111
+ }
112
+ }
113
+ }, [
114
+ ie,
115
+ ae,
116
+ C,
117
+ Je
118
+ ]), Xe = a(() => K ? {
119
+ field: K,
120
+ direction: q
121
+ } : null, [K, q]);
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());
124
+ }, [e]), i(() => {
125
+ e && Ye(H || void 0, U, Xe);
126
+ }, [
127
+ e,
128
+ U,
129
+ Xe,
130
+ Je
131
+ ]), i(() => {
132
+ e && c && Ie(new Set(Array.isArray(E) ? E : []));
133
+ }, [
134
+ e,
135
+ c,
136
+ E
137
+ ]);
138
+ let Ze = n((e) => {
139
+ Me(e), W(1), G.current && clearTimeout(G.current), G.current = setTimeout(() => {
140
+ Ye(e || void 0, 1, Xe);
141
+ }, 300);
142
+ }, [Ye, Xe]);
143
+ i(() => () => {
144
+ G.current && clearTimeout(G.current);
145
+ }, []);
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) => {
149
+ let t = $e(e);
150
+ return c ? Fe.has(t) : E === t;
151
+ }, [
152
+ c,
153
+ E,
154
+ Fe,
155
+ $e
156
+ ]), tt = n((e) => {
157
+ let n = $e(e);
158
+ c ? Ie((t) => {
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;
161
+ }) : (j(n), M?.([e]), t(!1));
162
+ }, [
163
+ c,
164
+ $e,
165
+ j,
166
+ M,
167
+ t
168
+ ]), nt = n(() => {
169
+ let e = Array.from(Fe);
170
+ j(e);
171
+ let n = e.map((e) => Le.current.get(e)).filter(Boolean);
172
+ M?.(n), t(!1);
173
+ }, [
174
+ Fe,
175
+ j,
176
+ M,
177
+ t
178
+ ]), rt = n(() => {
179
+ W((e) => Math.max(1, e - 1));
180
+ }, []), it = n(() => {
181
+ W((e) => Math.min(Q, e + 1));
182
+ }, [Q]), at = n((e) => {
183
+ if (e.key !== "Enter") return;
184
+ let t = parseInt(Ge, 10);
185
+ !isNaN(t) && t >= 1 && t <= Q && W(t), Ke("");
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])));
188
+ }, [
189
+ F,
190
+ J,
191
+ tt
192
+ ]);
193
+ i(() => {
194
+ if (J >= 0 && ze.current) {
195
+ let e = ze.current.querySelector(`[data-row-index="${J}"]`);
196
+ e && typeof e.scrollIntoView == "function" && e.scrollIntoView({ block: "nearest" });
197
+ }
198
+ }, [J]);
199
+ let st = n((e, t) => {
200
+ let n = e[t.field];
201
+ if (t.type && Oe) {
202
+ let e = Oe(t.type);
203
+ if (e) return /* @__PURE__ */ w(e, {
204
+ value: n,
205
+ field: {
206
+ name: t.field,
207
+ type: t.type
208
+ }
209
+ });
210
+ }
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 = {
214
+ field: t,
215
+ startX: e.clientX,
216
+ startWidth: n
217
+ };
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) => ({
222
+ ...e,
223
+ [X.current.field]: n
224
+ }));
225
+ }, i = () => {
226
+ X.current = null, document.removeEventListener("mousemove", r), document.removeEventListener("mouseup", i);
227
+ };
228
+ document.addEventListener("mousemove", r), document.addEventListener("mouseup", i);
229
+ }, []), $ = n((e, t) => {
230
+ He((n) => ({
231
+ ...n,
232
+ [e]: t
233
+ })), W(1);
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);
238
+ switch (e.type) {
239
+ case "select": return /* @__PURE__ */ T("div", {
240
+ className: "space-y-1",
241
+ children: [/* @__PURE__ */ w(p, {
242
+ className: "text-xs text-muted-foreground",
243
+ children: n
244
+ }), /* @__PURE__ */ T(ce, {
245
+ value: t == null ? "" : String(t),
246
+ onValueChange: (t) => $(e.field, t),
247
+ children: [/* @__PURE__ */ w(de, {
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, {
251
+ value: String(e.value),
252
+ children: e.label
253
+ }, String(e.value))) })]
254
+ })]
255
+ });
256
+ case "number": return /* @__PURE__ */ T("div", {
257
+ className: "space-y-1",
258
+ children: [/* @__PURE__ */ w(p, {
259
+ className: "text-xs text-muted-foreground",
260
+ children: n
261
+ }), /* @__PURE__ */ w(f, {
262
+ type: "number",
263
+ className: "h-8 text-xs",
264
+ value: t ?? "",
265
+ placeholder: `Filter ${n}`,
266
+ onChange: (t) => {
267
+ let n = t.target.value;
268
+ $(e.field, n === "" ? "" : Number(n));
269
+ }
270
+ })]
271
+ });
272
+ case "date": return /* @__PURE__ */ T("div", {
273
+ className: "space-y-1",
274
+ children: [/* @__PURE__ */ w(p, {
275
+ className: "text-xs text-muted-foreground",
276
+ children: n
277
+ }), /* @__PURE__ */ w(f, {
278
+ type: "date",
279
+ className: "h-8 text-xs",
280
+ value: t ?? "",
281
+ onChange: (t) => $(e.field, t.target.value)
282
+ })]
283
+ });
284
+ case "boolean": return /* @__PURE__ */ T("div", {
285
+ className: "space-y-1",
286
+ children: [/* @__PURE__ */ w(p, {
287
+ className: "text-xs text-muted-foreground",
288
+ children: n
289
+ }), /* @__PURE__ */ T("div", {
290
+ className: "flex items-center gap-2 h-8",
291
+ children: [/* @__PURE__ */ w(u, {
292
+ checked: !!t,
293
+ onCheckedChange: (t) => $(e.field, !!t)
294
+ }), /* @__PURE__ */ w("span", {
295
+ className: "text-xs text-muted-foreground",
296
+ children: "Yes"
297
+ })]
298
+ })]
299
+ });
300
+ default: return /* @__PURE__ */ T("div", {
301
+ className: "space-y-1",
302
+ children: [/* @__PURE__ */ w(p, {
303
+ className: "text-xs text-muted-foreground",
304
+ children: n
305
+ }), /* @__PURE__ */ w(f, {
306
+ className: "h-8 text-xs",
307
+ value: t ?? "",
308
+ placeholder: `Filter ${n}`,
309
+ onChange: (t) => $(e.field, t.target.value)
310
+ })]
311
+ });
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, {
315
+ open: e,
316
+ onOpenChange: t,
317
+ children: /* @__PURE__ */ T(te, {
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
+ "data-testid": "record-picker-dialog",
320
+ children: [
321
+ /* @__PURE__ */ w(re, { children: /* @__PURE__ */ T(d, { children: [r, c && /* @__PURE__ */ w("span", {
322
+ className: "sr-only",
323
+ children: " (multiple selection)"
324
+ })] }) }),
325
+ /* @__PURE__ */ T("div", {
326
+ className: "relative rounded-md border bg-muted/30 mb-3",
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, {
330
+ placeholder: "Search...",
331
+ value: H,
332
+ onChange: (e) => Ze(e.target.value),
333
+ className: "pl-9 border-0 bg-transparent shadow-none focus-visible:ring-0",
334
+ "data-testid": "record-picker-search"
335
+ }),
336
+ I && /* @__PURE__ */ w(ye, {
337
+ className: "absolute right-3 top-1/2 -translate-y-1/2 size-4 animate-spin text-muted-foreground",
338
+ "data-testid": "record-picker-loading-indicator"
339
+ })
340
+ ]
341
+ }),
342
+ Z && Z.length > 0 && /* @__PURE__ */ w("div", {
343
+ className: "py-2",
344
+ children: ke ? /* @__PURE__ */ w("div", {
345
+ "data-testid": "record-picker-filter-bar",
346
+ children: ke({
347
+ filterColumns: Z,
348
+ values: Y,
349
+ onChange: $,
350
+ onClear: ut,
351
+ activeCount: dt
352
+ })
353
+ }) : /* @__PURE__ */ T(we, { children: [/* @__PURE__ */ T("div", {
354
+ className: "flex items-center gap-2",
355
+ "data-testid": "record-picker-filter-bar",
356
+ children: [/* @__PURE__ */ T(l, {
357
+ type: "button",
358
+ variant: dt > 0 ? "secondary" : "outline",
359
+ size: "sm",
360
+ className: "gap-1.5 shrink-0",
361
+ onClick: () => Ve((e) => !e),
362
+ children: [
363
+ /* @__PURE__ */ w(Se, { className: "size-3.5" }),
364
+ "Filters",
365
+ dt > 0 && /* @__PURE__ */ w("span", {
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
+ children: dt
368
+ })
369
+ ]
370
+ }), dt > 0 && /* @__PURE__ */ T(l, {
371
+ type: "button",
372
+ variant: "ghost",
373
+ size: "sm",
374
+ className: "gap-1 text-xs",
375
+ onClick: ut,
376
+ children: [/* @__PURE__ */ w(Ce, { className: "size-3" }), "Clear"]
377
+ })]
378
+ }), Be && /* @__PURE__ */ w("div", {
379
+ className: "mt-2 grid gap-3 sm:grid-cols-2 lg:grid-cols-3 border rounded-md p-3 bg-muted/30",
380
+ "data-testid": "record-picker-filter-panel",
381
+ children: Z.map((e) => /* @__PURE__ */ w("div", { children: ft(e) }, e.field))
382
+ })] })
383
+ }),
384
+ R && /* @__PURE__ */ T("div", {
385
+ className: "flex flex-col items-center gap-2 py-4",
386
+ role: "alert",
387
+ children: [
388
+ /* @__PURE__ */ w(ge, { className: "size-5 text-destructive" }),
389
+ /* @__PURE__ */ w("p", {
390
+ className: "text-sm text-destructive",
391
+ children: R
392
+ }),
393
+ /* @__PURE__ */ w(l, {
394
+ variant: "outline",
395
+ size: "sm",
396
+ onClick: () => Ye(H || void 0, U, Xe),
397
+ type: "button",
398
+ children: "Retry"
399
+ })
400
+ ]
401
+ }),
402
+ Ae ? /* @__PURE__ */ w("div", {
403
+ className: "flex-1 min-h-0",
404
+ "data-testid": "record-picker-grid-slot",
405
+ children: Ae({
406
+ columns: qe,
407
+ records: F,
408
+ loading: I,
409
+ totalCount: B,
410
+ currentPage: U,
411
+ pageSize: C,
412
+ sortField: K,
413
+ sortDirection: q,
414
+ onSort: Qe,
415
+ onPageChange: W,
416
+ onRowClick: tt,
417
+ isSelected: et,
418
+ multiple: c,
419
+ idField: be,
420
+ cellRenderer: Oe
421
+ })
422
+ }) : /* @__PURE__ */ T(we, { children: [
423
+ I && F.length === 0 && !R && /* @__PURE__ */ w("div", {
424
+ className: "flex-1 overflow-hidden min-h-0 border rounded-md",
425
+ role: "status",
426
+ "aria-live": "polite",
427
+ "data-testid": "record-picker-skeleton",
428
+ children: /* @__PURE__ */ T(h, { children: [/* @__PURE__ */ w(_, { children: /* @__PURE__ */ T(v, {
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, {
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)) })] })
435
+ }),
436
+ !I && !R && F.length === 0 && /* @__PURE__ */ w("div", {
437
+ className: "py-8 text-center",
438
+ children: /* @__PURE__ */ w("p", {
439
+ className: "text-sm text-muted-foreground",
440
+ children: "No records found"
441
+ })
442
+ }),
443
+ !R && F.length > 0 && /* @__PURE__ */ T("div", {
444
+ className: "relative flex-1 overflow-auto min-h-0 border rounded-md",
445
+ tabIndex: 0,
446
+ onKeyDown: ot,
447
+ role: "grid",
448
+ "aria-label": "Records",
449
+ children: [I && /* @__PURE__ */ w("div", {
450
+ className: "absolute inset-0 z-10 flex items-center justify-center bg-background/60",
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(_, {
456
+ className: "sticky top-0 z-[5] bg-muted/50 [&_tr]:border-b",
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, {
461
+ style: t ? {
462
+ width: `${t}px`,
463
+ minWidth: `${t}px`
464
+ } : e.width ? { width: e.width } : void 0,
465
+ className: "cursor-pointer select-none relative group text-xs font-semibold uppercase tracking-wider",
466
+ onClick: () => Qe(e.field),
467
+ "aria-sort": K === e.field ? q === "asc" ? "ascending" : "descending" : "none",
468
+ children: [/* @__PURE__ */ T("span", {
469
+ className: "inline-flex items-center",
470
+ children: [e.label || A(e.field), ct(e.field)]
471
+ }), /* @__PURE__ */ w("span", {
472
+ role: "separator",
473
+ "aria-orientation": "vertical",
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",
475
+ onMouseDown: (t) => {
476
+ let n = t.currentTarget.parentElement?.getBoundingClientRect();
477
+ lt(t, e.field, n?.width ?? 100);
478
+ },
479
+ onClick: (e) => e.stopPropagation(),
480
+ "data-testid": `resize-handle-${e.field}`
481
+ })]
482
+ }, e.field);
483
+ })] })
484
+ }), /* @__PURE__ */ w(pe, {
485
+ ref: ze,
486
+ children: F.map((e, t) => {
487
+ let n = $e(e), r = et(e), i = t === J;
488
+ return /* @__PURE__ */ T(v, {
489
+ "data-row-index": t,
490
+ className: he("cursor-pointer transition-colors", pt(r, t), i && "ring-2 ring-primary ring-inset"),
491
+ onClick: () => tt(e),
492
+ "data-testid": `record-row-${n}`,
493
+ "aria-selected": r,
494
+ children: [c && /* @__PURE__ */ w(g, {
495
+ className: "w-10",
496
+ children: r && /* @__PURE__ */ w(b, { className: "size-4 text-primary" })
497
+ }), qe.map((t) => /* @__PURE__ */ w(g, {
498
+ className: "py-2.5",
499
+ children: st(e, t)
500
+ }, t.field))]
501
+ }, n ?? t);
502
+ })
503
+ })]
504
+ })]
505
+ }),
506
+ !R && B > 0 && /* @__PURE__ */ T("div", {
507
+ className: "flex items-center justify-between text-sm text-muted-foreground border-t pt-3 mt-2 px-1",
508
+ "data-testid": "record-picker-pagination",
509
+ children: [/* @__PURE__ */ T("span", { children: [
510
+ B,
511
+ " ",
512
+ B === 1 ? "record" : "records",
513
+ Q > 1 && ` · Page ${U} of ${Q}`
514
+ ] }), Q > 1 && /* @__PURE__ */ T("div", {
515
+ className: "flex items-center gap-1.5",
516
+ children: [
517
+ /* @__PURE__ */ w(l, {
518
+ variant: "outline",
519
+ size: "icon",
520
+ className: "size-7",
521
+ onClick: rt,
522
+ disabled: U <= 1,
523
+ type: "button",
524
+ "aria-label": "Previous page",
525
+ children: /* @__PURE__ */ w(x, { className: "size-4" })
526
+ }),
527
+ /* @__PURE__ */ w(f, {
528
+ className: "h-7 w-12 text-center text-xs px-1",
529
+ placeholder: String(U),
530
+ value: Ge,
531
+ onChange: (e) => Ke(e.target.value),
532
+ onKeyDown: at,
533
+ "aria-label": "Jump to page",
534
+ "data-testid": "record-picker-page-jump"
535
+ }),
536
+ /* @__PURE__ */ w(l, {
537
+ variant: "outline",
538
+ size: "icon",
539
+ className: "size-7",
540
+ onClick: it,
541
+ disabled: U >= Q,
542
+ type: "button",
543
+ "aria-label": "Next page",
544
+ children: /* @__PURE__ */ w(S, { className: "size-4" })
545
+ })
546
+ ]
547
+ })]
548
+ })
549
+ ] }),
550
+ c && /* @__PURE__ */ w(ne, { children: /* @__PURE__ */ T("div", {
551
+ className: "flex items-center gap-2 w-full justify-between",
552
+ children: [/* @__PURE__ */ T("span", {
553
+ className: "text-sm text-muted-foreground",
554
+ children: [Fe.size, " selected"]
555
+ }), /* @__PURE__ */ T("div", {
556
+ className: "flex gap-2",
557
+ children: [/* @__PURE__ */ w(l, {
558
+ variant: "outline",
559
+ type: "button",
560
+ onClick: () => t(!1),
561
+ children: "Cancel"
562
+ }), /* @__PURE__ */ w(l, {
563
+ type: "button",
564
+ onClick: nt,
565
+ children: "Confirm"
566
+ })]
567
+ })]
568
+ }) })
569
+ ]
570
+ })
571
+ });
572
+ }
573
+ //#endregion
574
+ //#region src/widgets/_cell-renderer-bridge.ts
575
+ var M;
576
+ function N(e) {
577
+ M = e;
578
+ }
579
+ function Oe() {
580
+ return M;
581
+ }
582
+ //#endregion
583
+ //#region src/widgets/LookupField.tsx
584
+ var P = /* @__PURE__ */ e({ LookupField: () => I }), ke = 50, Ae = E;
585
+ function F(e, t, n, r) {
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
+ return {
588
+ value: i,
589
+ label: String(a),
590
+ description: o,
591
+ ...e
592
+ };
593
+ }
594
+ function je(e) {
595
+ return {
596
+ text: "text",
597
+ number: "number",
598
+ currency: "number",
599
+ percent: "number",
600
+ select: "select",
601
+ status: "select",
602
+ date: "date",
603
+ datetime: "date",
604
+ boolean: "boolean"
605
+ }[e];
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(() => {
609
+ if (!A) return;
610
+ let e = [];
611
+ for (let t of A) if (typeof t == "object" && t.type) {
612
+ let n = je(t.type);
613
+ n && e.push({
614
+ field: t.field,
615
+ label: t.label,
616
+ type: n
617
+ });
618
+ }
619
+ 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));
624
+ }, [
625
+ I,
626
+ B,
627
+ p
628
+ ]);
629
+ i(() => {
630
+ _e(-1);
631
+ }, [V.length]);
632
+ let H = n(async (e) => {
633
+ if (!(!P || !k)) {
634
+ m(!0), pe(null);
635
+ try {
636
+ 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);
640
+ } catch (e) {
641
+ pe(e instanceof Error ? e.message : String(e)), de([]);
642
+ } finally {
643
+ m(!1);
644
+ }
645
+ }
646
+ }, [
647
+ P,
648
+ k,
649
+ D,
650
+ O,
651
+ Te
652
+ ]);
653
+ 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);
659
+ }, 300));
660
+ }, [I, H]);
661
+ i(() => () => {
662
+ _.current && clearTimeout(_.current);
663
+ }, []);
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) {
670
+ let n = Array.isArray(e) ? e : [];
671
+ n.includes(t.value) ? u(n.filter((e) => e !== t.value)) : u([...n, t.value]);
672
+ } else u(t.value), d(!1);
673
+ }, [
674
+ E,
675
+ e,
676
+ 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)));
681
+ }, [
682
+ D,
683
+ 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]));
687
+ }, [
688
+ V,
689
+ y,
690
+ G
691
+ ]);
692
+ 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", {
695
+ className: "flex flex-wrap gap-1",
696
+ children: W.map((e, t) => /* @__PURE__ */ w(c, {
697
+ variant: "outline",
698
+ children: e?.[D] || e?.label
699
+ }, t))
700
+ }) : /* @__PURE__ */ w("span", {
701
+ className: "text-sm",
702
+ children: W[0]?.[D] || W[0]?.label
703
+ }) : /* @__PURE__ */ w(ie, {}) : /* @__PURE__ */ T("div", {
704
+ className: "space-y-2",
705
+ children: [
706
+ W.length > 0 && /* @__PURE__ */ w("div", {
707
+ className: "flex flex-wrap gap-1",
708
+ children: W.map((e, t) => /* @__PURE__ */ T(c, {
709
+ variant: "outline",
710
+ className: "gap-1",
711
+ children: [e?.[D] || e?.label, /* @__PURE__ */ w("button", {
712
+ onClick: () => K(e?.value),
713
+ className: "ml-1 hover:text-destructive",
714
+ type: "button",
715
+ "aria-label": `Remove ${e?.[D] || e?.label}`,
716
+ children: /* @__PURE__ */ w(Ce, { className: "size-3" })
717
+ })]
718
+ }, t))
719
+ }),
720
+ /* @__PURE__ */ T("div", {
721
+ className: "flex items-center gap-1.5",
722
+ children: [/* @__PURE__ */ T(ae, {
723
+ open: re,
724
+ onOpenChange: d,
725
+ children: [/* @__PURE__ */ w(se, {
726
+ asChild: !0,
727
+ children: /* @__PURE__ */ T(l, {
728
+ variant: "outline",
729
+ className: "min-w-0 flex-1 justify-start text-left font-normal",
730
+ 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")]
732
+ })
733
+ }), /* @__PURE__ */ T(oe, {
734
+ className: "w-[var(--radix-popover-trigger-width)] p-0",
735
+ align: "start",
736
+ children: [
737
+ /* @__PURE__ */ w("div", {
738
+ className: "p-2",
739
+ children: /* @__PURE__ */ T("div", {
740
+ className: "relative",
741
+ 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,
748
+ className: "w-full pl-9 h-8 text-sm"
749
+ }),
750
+ fe && /* @__PURE__ */ w(ye, {
751
+ className: "absolute right-3 top-1/2 -translate-y-1/2 size-4 animate-spin text-muted-foreground",
752
+ "data-testid": "lookup-loading"
753
+ })
754
+ ]
755
+ })
756
+ }),
757
+ h && /* @__PURE__ */ T("div", {
758
+ className: "flex flex-col items-center gap-2 py-4 px-2",
759
+ role: "alert",
760
+ children: [
761
+ /* @__PURE__ */ w(ge, { className: "size-5 text-destructive" }),
762
+ /* @__PURE__ */ w("p", {
763
+ className: "text-sm text-destructive",
764
+ children: h
765
+ }),
766
+ /* @__PURE__ */ w(l, {
767
+ variant: "outline",
768
+ size: "sm",
769
+ onClick: () => H(p || void 0),
770
+ type: "button",
771
+ children: "Retry"
772
+ })
773
+ ]
774
+ }),
775
+ fe && V.length === 0 && !h && /* @__PURE__ */ T("div", {
776
+ className: "flex flex-col items-center gap-2 py-6",
777
+ role: "status",
778
+ "aria-live": "polite",
779
+ children: [/* @__PURE__ */ w(ye, { className: "size-6 animate-spin text-muted-foreground" }), /* @__PURE__ */ w("p", {
780
+ className: "text-sm text-muted-foreground",
781
+ children: "Loading…"
782
+ })]
783
+ }),
784
+ !h && !(fe && V.length === 0) && /* @__PURE__ */ w("div", {
785
+ ref: ve,
786
+ className: "max-h-64 overflow-y-auto px-1 pb-1",
787
+ role: "listbox",
788
+ children: V.length === 0 ? /* @__PURE__ */ T("div", {
789
+ className: "py-4 text-center",
790
+ children: [/* @__PURE__ */ w("p", {
791
+ className: "text-sm text-muted-foreground",
792
+ children: "No options found"
793
+ }), L && /* @__PURE__ */ T(l, {
794
+ variant: "ghost",
795
+ size: "sm",
796
+ className: "mt-2 gap-1",
797
+ type: "button",
798
+ onClick: () => {
799
+ L(p), d(!1);
800
+ },
801
+ children: [/* @__PURE__ */ w(be, { className: "size-4" }), "Create new"]
802
+ })]
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", {
807
+ "data-lookup-index": n,
808
+ role: "option",
809
+ "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" : ""}`,
812
+ type: "button",
813
+ children: [/* @__PURE__ */ T("div", {
814
+ className: "min-w-0 flex-1",
815
+ children: [/* @__PURE__ */ w("span", {
816
+ className: "block truncate",
817
+ children: t.label
818
+ }), t.description && /* @__PURE__ */ w("span", {
819
+ className: "block truncate text-xs text-muted-foreground",
820
+ children: t.description
821
+ })]
822
+ }), r && /* @__PURE__ */ w(c, {
823
+ variant: "default",
824
+ className: "ml-2 shrink-0",
825
+ children: "Selected"
826
+ })]
827
+ }, t.value);
828
+ }),
829
+ I && g > V.length && /* @__PURE__ */ T("p", {
830
+ className: "text-xs text-muted-foreground text-center py-2",
831
+ children: [
832
+ "Showing ",
833
+ V.length,
834
+ " of ",
835
+ g,
836
+ " results."
837
+ ]
838
+ }),
839
+ I && g > V.length && /* @__PURE__ */ T("button", {
840
+ type: "button",
841
+ 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
+ onClick: () => {
843
+ d(!1), z(!0);
844
+ },
845
+ "data-testid": "show-all-results",
846
+ children: [
847
+ /* @__PURE__ */ w(C, { className: "size-3.5" }),
848
+ "Show All Results (",
849
+ g,
850
+ ")"
851
+ ]
852
+ }),
853
+ L && /* @__PURE__ */ T("button", {
854
+ type: "button",
855
+ 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
+ onClick: () => {
857
+ L(p), d(!1);
858
+ },
859
+ children: [
860
+ /* @__PURE__ */ w(be, { className: "size-3.5" }),
861
+ "Create new",
862
+ p ? ` "${p}"` : ""
863
+ ]
864
+ })
865
+ ] })
866
+ })
867
+ ]
868
+ })]
869
+ }), I && /* @__PURE__ */ w(l, {
870
+ variant: "outline",
871
+ size: "icon",
872
+ className: "shrink-0",
873
+ type: "button",
874
+ onClick: () => z(!0),
875
+ "aria-label": "Browse all records",
876
+ title: "Browse all records",
877
+ "data-testid": "browse-all-records",
878
+ children: /* @__PURE__ */ w(C, { className: "size-4" })
879
+ })]
880
+ }),
881
+ I && P && k && /* @__PURE__ */ w(j, {
882
+ open: R,
883
+ onOpenChange: z,
884
+ title: b?.label || "Select",
885
+ multiple: E,
886
+ dataSource: P,
887
+ objectName: k,
888
+ columns: A,
889
+ displayField: D,
890
+ idField: O,
891
+ pageSize: Ee,
892
+ value: e,
893
+ onSelect: u,
894
+ onSelectRecords: Ne,
895
+ lookupFilters: De,
896
+ cellRenderer: Oe(),
897
+ filterColumns: M
898
+ })
899
+ ]
900
+ });
901
+ }
902
+ //#endregion
903
+ export { j as i, P as n, N as r, I as t };