@object-ui/fields 3.1.5 → 3.3.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.
Files changed (181) hide show
  1. package/dist/AddressField-Do46PdqT.cjs +1 -0
  2. package/dist/AutoNumberField-cS2tsxd-.cjs +1 -0
  3. package/dist/AvatarField-CxhGS3wF.cjs +1 -0
  4. package/dist/BooleanField-BgkbTHPY.cjs +1 -0
  5. package/dist/CodeField-DE3dLruS.cjs +1 -0
  6. package/dist/ColorField-DBTFFYpv.cjs +1 -0
  7. package/dist/CurrencyField-C28LkJts.cjs +1 -0
  8. package/dist/DateField-WGWwddDF.cjs +1 -0
  9. package/dist/DateTimeField-BYsZs8f7.cjs +1 -0
  10. package/dist/EmailField-1PW03WW8.cjs +1 -0
  11. package/dist/FileField-BqZkp1O6.cjs +1 -0
  12. package/dist/FormulaField-MZ9le4RE.cjs +1 -0
  13. package/dist/GeolocationField-onbAOdIe.cjs +1 -0
  14. package/dist/GridField-D4OWfaU4.cjs +1 -0
  15. package/dist/ImageField-BZf-AL2e.cjs +1 -0
  16. package/dist/LocationField-DhGJtUzZ.cjs +1 -0
  17. package/dist/LookupField-B6MOSQVJ.js +906 -0
  18. package/dist/LookupField-BHr7uTX1.cjs +1 -0
  19. package/dist/MasterDetailField-YTAU1hzg.cjs +1 -0
  20. package/dist/NumberField-BCk42NjA.cjs +1 -0
  21. package/dist/ObjectField-iYK5eab_.cjs +1 -0
  22. package/dist/PasswordField-BAReSDz7.cjs +1 -0
  23. package/dist/PercentField-nzACEXtC.cjs +1 -0
  24. package/dist/PhoneField-CvbkGpN3.cjs +1 -0
  25. package/dist/QRCodeField-D8fov03S.cjs +1 -0
  26. package/dist/RatingField-DBgj9cgE.cjs +1 -0
  27. package/dist/RichTextField-7VwN6GcU.cjs +1 -0
  28. package/dist/SelectField-BUOTiYaS.cjs +1 -0
  29. package/dist/SignatureField-DW_Cz6t9.cjs +1 -0
  30. package/dist/SliderField-Bgi3-TAD.cjs +1 -0
  31. package/dist/SummaryField-Ed2wJBvs.cjs +1 -0
  32. package/dist/TextAreaField-O503xJff.cjs +1 -0
  33. package/dist/TextField-BrwtPIQC.cjs +1 -0
  34. package/dist/TimeField-Bhoxv2yp.cjs +1 -0
  35. package/dist/UrlField-VFO089Gr.cjs +1 -0
  36. package/dist/UserField-BRe9SCCk.cjs +1 -0
  37. package/dist/VectorField-ByrWkiud.cjs +1 -0
  38. package/dist/chunk-D-qHiVGv.cjs +1 -0
  39. package/dist/index.cjs +3 -3
  40. package/dist/index.d.ts +1 -1
  41. package/dist/index.js +629 -593
  42. package/dist/packages/fields/src/widgets/useFieldTranslation.d.ts +5 -0
  43. package/dist/rolldown-runtime-CAFD8bLK.js +11 -0
  44. package/dist/useFieldTranslation-BiQad4ar.cjs +1 -0
  45. package/dist/useFieldTranslation-Bv3oUVgb.js +9 -0
  46. package/package.json +9 -8
  47. package/src/widgets/LookupField.tsx +5 -3
  48. package/src/widgets/SelectField.tsx +3 -1
  49. package/src/widgets/useFieldTranslation.ts +17 -0
  50. package/dist/AddressField-B6fPb2Fs.js +0 -3
  51. package/dist/AddressField-Ctsxkj35.cjs +0 -1
  52. package/dist/AutoNumberField-DXIYJfiB.js +0 -3
  53. package/dist/AutoNumberField-f76XU1bR.cjs +0 -1
  54. package/dist/AvatarField-BHpex3Wa.js +0 -3
  55. package/dist/AvatarField-CXOdYavl.cjs +0 -1
  56. package/dist/BooleanField-Bs0urhsx.js +0 -3
  57. package/dist/BooleanField-DeexI_O2.cjs +0 -1
  58. package/dist/CodeField-DDOMH8E8.cjs +0 -1
  59. package/dist/CodeField-tRACqngO.js +0 -3
  60. package/dist/ColorField-Bar6bOJw.js +0 -3
  61. package/dist/ColorField-CM9CxZ9h.cjs +0 -1
  62. package/dist/CurrencyField-CezTX_rA.cjs +0 -1
  63. package/dist/CurrencyField-D4VwXI9k.js +0 -3
  64. package/dist/DateField-DDUllj7w.cjs +0 -1
  65. package/dist/DateField-DjGiK6BH.js +0 -3
  66. package/dist/DateTimeField-DBh-dYdR.js +0 -3
  67. package/dist/DateTimeField-DDqgVN3b.cjs +0 -1
  68. package/dist/EmailField-B-3nY8Pr.cjs +0 -1
  69. package/dist/EmailField-Cp6yJlpH.js +0 -3
  70. package/dist/FileField-C1bcL7tu.cjs +0 -1
  71. package/dist/FileField-DUgt6ai3.js +0 -3
  72. package/dist/FormulaField-BLV1KgkQ.js +0 -3
  73. package/dist/FormulaField-CsbQIZ7S.cjs +0 -1
  74. package/dist/GeolocationField-BbIRH51u.js +0 -3
  75. package/dist/GeolocationField-UFu9VR-x.cjs +0 -1
  76. package/dist/GridField-2m74haE0.cjs +0 -1
  77. package/dist/GridField-O3Jd1NuJ.js +0 -3
  78. package/dist/ImageField-Cna7g6KL.cjs +0 -1
  79. package/dist/ImageField-rc1Nzcvb.js +0 -3
  80. package/dist/LocationField-DpRe9QlH.cjs +0 -1
  81. package/dist/LocationField-QZPPYo0J.js +0 -3
  82. package/dist/LookupField-BX4sK8NG.js +0 -904
  83. package/dist/LookupField-C9rPrHi_.cjs +0 -1
  84. package/dist/MasterDetailField-BXncIT1s.js +0 -3
  85. package/dist/MasterDetailField-TNP2825Z.cjs +0 -1
  86. package/dist/NumberField-DCHTzmDG.js +0 -3
  87. package/dist/NumberField-SqRwbcY8.cjs +0 -1
  88. package/dist/ObjectField-BEUHpn_X.js +0 -3
  89. package/dist/ObjectField-BWZwaFIG.cjs +0 -1
  90. package/dist/PasswordField-BZ_OeQyw.js +0 -3
  91. package/dist/PasswordField-kLp-ZyPm.cjs +0 -1
  92. package/dist/PercentField-B2t2knlc.js +0 -3
  93. package/dist/PercentField-BzhD6tQm.cjs +0 -1
  94. package/dist/PhoneField-CirvuysP.cjs +0 -1
  95. package/dist/PhoneField-CkrCFmcO.js +0 -3
  96. package/dist/QRCodeField-C4OOLCbE.cjs +0 -1
  97. package/dist/QRCodeField-CQoGow8y.js +0 -3
  98. package/dist/RatingField-CZG8SgQ8.cjs +0 -1
  99. package/dist/RatingField-DecDJkou.js +0 -3
  100. package/dist/RichTextField-Bog2i4NN.cjs +0 -1
  101. package/dist/RichTextField-b-8QbNCJ.js +0 -3
  102. package/dist/SelectField-CAa6c0cB.cjs +0 -1
  103. package/dist/SelectField-DMy5IxRc.js +0 -3
  104. package/dist/SignatureField-BvTPE7Dn.js +0 -3
  105. package/dist/SignatureField-jsb-0AYp.cjs +0 -1
  106. package/dist/SliderField-B7WvKFv7.js +0 -3
  107. package/dist/SliderField-DRjEJSxK.cjs +0 -1
  108. package/dist/SummaryField-DA16Edq3.cjs +0 -1
  109. package/dist/SummaryField-DVSVfKmY.js +0 -3
  110. package/dist/TextAreaField--ut87UiB.js +0 -3
  111. package/dist/TextAreaField-Cxp3DFC6.cjs +0 -1
  112. package/dist/TextField-CkEDGbkQ.js +0 -3
  113. package/dist/TextField-aLAzBaLZ.cjs +0 -1
  114. package/dist/TimeField-D0lF0y_I.cjs +0 -1
  115. package/dist/TimeField-DA_S6lQV.js +0 -3
  116. package/dist/UrlField-D0ugmD3f.cjs +0 -1
  117. package/dist/UrlField-DCnXHR1A.js +0 -3
  118. package/dist/UserField-DGlorzyG.cjs +0 -1
  119. package/dist/UserField-V0GmvyGV.js +0 -3
  120. package/dist/VectorField-BSD85ntU.cjs +0 -1
  121. package/dist/VectorField-CVi5yrrc.js +0 -3
  122. package/dist/jsx-runtime-DHCF5ANT.cjs +0 -6
  123. package/dist/jsx-runtime-MxADXuRH.js +0 -189
  124. /package/dist/{fields → packages/fields}/src/__tests__/boolean-checkbox.test.d.ts +0 -0
  125. /package/dist/{fields → packages/fields}/src/__tests__/cell-renderers.test.d.ts +0 -0
  126. /package/dist/{fields → packages/fields}/src/__tests__/datetime-cell.test.d.ts +0 -0
  127. /package/dist/{fields → packages/fields}/src/__tests__/datetime-timezone.test.d.ts +0 -0
  128. /package/dist/{fields → packages/fields}/src/__tests__/extreme-inputs.test.d.ts +0 -0
  129. /package/dist/{fields → packages/fields}/src/__tests__/form-variants.test.d.ts +0 -0
  130. /package/dist/{fields → packages/fields}/src/__tests__/validation-feedback.test.d.ts +0 -0
  131. /package/dist/{fields → packages/fields}/src/complex-widgets.test.d.ts +0 -0
  132. /package/dist/{fields → packages/fields}/src/datetime-widgets.test.d.ts +0 -0
  133. /package/dist/{fields → packages/fields}/src/fields-edge-cases.stories.d.ts +0 -0
  134. /package/dist/{fields → packages/fields}/src/fields.stories.d.ts +0 -0
  135. /package/dist/{fields → packages/fields}/src/index.d.ts +0 -0
  136. /package/dist/{fields → packages/fields}/src/new-widgets.test.d.ts +0 -0
  137. /package/dist/{fields → packages/fields}/src/record-picker-dialog.stories.d.ts +0 -0
  138. /package/dist/{fields → packages/fields}/src/record-picker.test.d.ts +0 -0
  139. /package/dist/{fields → packages/fields}/src/remaining-widgets.test.d.ts +0 -0
  140. /package/dist/{fields → packages/fields}/src/standard-widgets.test.d.ts +0 -0
  141. /package/dist/{fields → packages/fields}/src/text-rich-widgets.test.d.ts +0 -0
  142. /package/dist/{fields → packages/fields}/src/visual-widgets.test.d.ts +0 -0
  143. /package/dist/{fields → packages/fields}/src/widgets/AddressField.d.ts +0 -0
  144. /package/dist/{fields → packages/fields}/src/widgets/AutoNumberField.d.ts +0 -0
  145. /package/dist/{fields → packages/fields}/src/widgets/AvatarField.d.ts +0 -0
  146. /package/dist/{fields → packages/fields}/src/widgets/BooleanField.d.ts +0 -0
  147. /package/dist/{fields → packages/fields}/src/widgets/CodeField.d.ts +0 -0
  148. /package/dist/{fields → packages/fields}/src/widgets/ColorField.d.ts +0 -0
  149. /package/dist/{fields → packages/fields}/src/widgets/CurrencyField.d.ts +0 -0
  150. /package/dist/{fields → packages/fields}/src/widgets/DateField.d.ts +0 -0
  151. /package/dist/{fields → packages/fields}/src/widgets/DateTimeField.d.ts +0 -0
  152. /package/dist/{fields → packages/fields}/src/widgets/EmailField.d.ts +0 -0
  153. /package/dist/{fields → packages/fields}/src/widgets/FileField.d.ts +0 -0
  154. /package/dist/{fields → packages/fields}/src/widgets/FormulaField.d.ts +0 -0
  155. /package/dist/{fields → packages/fields}/src/widgets/GeolocationField.d.ts +0 -0
  156. /package/dist/{fields → packages/fields}/src/widgets/GridField.d.ts +0 -0
  157. /package/dist/{fields → packages/fields}/src/widgets/ImageField.d.ts +0 -0
  158. /package/dist/{fields → packages/fields}/src/widgets/LocationField.d.ts +0 -0
  159. /package/dist/{fields → packages/fields}/src/widgets/LookupField.d.ts +0 -0
  160. /package/dist/{fields → packages/fields}/src/widgets/MasterDetailField.d.ts +0 -0
  161. /package/dist/{fields → packages/fields}/src/widgets/NumberField.d.ts +0 -0
  162. /package/dist/{fields → packages/fields}/src/widgets/ObjectField.d.ts +0 -0
  163. /package/dist/{fields → packages/fields}/src/widgets/PasswordField.d.ts +0 -0
  164. /package/dist/{fields → packages/fields}/src/widgets/PercentField.d.ts +0 -0
  165. /package/dist/{fields → packages/fields}/src/widgets/PhoneField.d.ts +0 -0
  166. /package/dist/{fields → packages/fields}/src/widgets/QRCodeField.d.ts +0 -0
  167. /package/dist/{fields → packages/fields}/src/widgets/RatingField.d.ts +0 -0
  168. /package/dist/{fields → packages/fields}/src/widgets/RecordPickerDialog.d.ts +0 -0
  169. /package/dist/{fields → packages/fields}/src/widgets/RichTextField.d.ts +0 -0
  170. /package/dist/{fields → packages/fields}/src/widgets/SelectField.d.ts +0 -0
  171. /package/dist/{fields → packages/fields}/src/widgets/SignatureField.d.ts +0 -0
  172. /package/dist/{fields → packages/fields}/src/widgets/SliderField.d.ts +0 -0
  173. /package/dist/{fields → packages/fields}/src/widgets/SummaryField.d.ts +0 -0
  174. /package/dist/{fields → packages/fields}/src/widgets/TextAreaField.d.ts +0 -0
  175. /package/dist/{fields → packages/fields}/src/widgets/TextField.d.ts +0 -0
  176. /package/dist/{fields → packages/fields}/src/widgets/TimeField.d.ts +0 -0
  177. /package/dist/{fields → packages/fields}/src/widgets/UrlField.d.ts +0 -0
  178. /package/dist/{fields → packages/fields}/src/widgets/UserField.d.ts +0 -0
  179. /package/dist/{fields → packages/fields}/src/widgets/VectorField.d.ts +0 -0
  180. /package/dist/{fields → packages/fields}/src/widgets/_cell-renderer-bridge.d.ts +0 -0
  181. /package/dist/{fields → packages/fields}/src/widgets/types.d.ts +0 -0
@@ -0,0 +1,906 @@
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, Input as f, Label as p, Popover as ie, PopoverContent as ae, PopoverTrigger as oe, Select as se, SelectContent as ce, SelectItem as le, SelectTrigger as ue, SelectValue as de, Skeleton as m, Table as h, TableBody as g, TableCell as _, TableHead as fe, TableHeader as v, TableRow as y, cn as pe } from "@object-ui/components";
5
+ import { AlertCircle as me, ArrowDown as b, ArrowUp as he, ArrowUpDown as ge, Check as x, ChevronLeft as S, ChevronRight as C, Loader2 as _e, Plus as ve, Search as ye, SlidersHorizontal as be, TableProperties as xe, X as Se } from "lucide-react";
6
+ import { Fragment as Ce, 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, we = 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 Te(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 Ee(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: ve = "name", idField: xe = "id", pageSize: E = D, value: j, onSelect: M, onSelectRecords: N, lookupFilters: P, cellRenderer: F, filterColumns: De, renderFilterBar: Oe, renderGrid: ke }) {
58
+ let [I, L] = s([]), [R, Ae] = s(!1), [z, B] = s(null), [V, H] = s(0), [je, 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: ve,
60
+ label: A(ve)
61
+ }], [oe, ve]), Z = a(() => {
62
+ if (De && De.length > 0) return De;
63
+ if (P && P.length > 0) return P.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
+ }, [De, P]), Je = a(() => {
85
+ let e = P?.length ? Te(P) : {}, t = Z?.length ? Ee(Y, Z) : {}, n = {
86
+ ...e,
87
+ ...t
88
+ };
89
+ return Object.keys(n).length > 0 ? n : void 0;
90
+ }, [
91
+ P,
92
+ Z,
93
+ Y
94
+ ]), Q = Math.max(1, Math.ceil(V / E)), Ye = n(async (e, t = 1, n, r) => {
95
+ if (!(!ie || !ae)) {
96
+ Ae(!0), B(null);
97
+ try {
98
+ let i = {
99
+ $top: E,
100
+ $skip: (t - 1) * E
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
+ L(s), H(o?.total ?? s.length), Re(-1);
107
+ } catch (e) {
108
+ B(e instanceof Error ? e.message : String(e)), L([]);
109
+ } finally {
110
+ Ae(!1);
111
+ }
112
+ }
113
+ }, [
114
+ ie,
115
+ ae,
116
+ E,
117
+ Je
118
+ ]), Xe = a(() => K ? {
119
+ field: K,
120
+ direction: q
121
+ } : null, [K, q]);
122
+ i(() => {
123
+ e || (Me(""), W(1), B(null), L([]), Ne(null), Pe("asc"), Re(-1), Ve(!1), He({}), We({}), Ke(""), Ie(new Set(c && Array.isArray(j) ? j : [])), Le.current.clear());
124
+ }, [e]), i(() => {
125
+ e && Ye(je || void 0, U, Xe);
126
+ }, [
127
+ e,
128
+ U,
129
+ Xe,
130
+ Je
131
+ ]), i(() => {
132
+ e && c && Ie(new Set(Array.isArray(j) ? j : []));
133
+ }, [
134
+ e,
135
+ c,
136
+ j
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[xe] ?? e.id ?? e._id, [xe]), et = n((e) => {
149
+ let t = $e(e);
150
+ return c ? Fe.has(t) : j === t;
151
+ }, [
152
+ c,
153
+ j,
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
+ }) : (M(n), N?.([e]), t(!1));
162
+ }, [
163
+ c,
164
+ $e,
165
+ M,
166
+ N,
167
+ t
168
+ ]), nt = n(() => {
169
+ let e = Array.from(Fe);
170
+ M(e);
171
+ let n = e.map((e) => Le.current.get(e)).filter(Boolean);
172
+ N?.(n), t(!1);
173
+ }, [
174
+ Fe,
175
+ M,
176
+ N,
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
+ I.length !== 0 && (e.key === "ArrowDown" ? (e.preventDefault(), Re((e) => Math.min(e + 1, I.length - 1))) : e.key === "ArrowUp" ? (e.preventDefault(), Re((e) => Math.max(e - 1, 0))) : (e.key === "Enter" || e.key === " ") && (e.preventDefault(), J >= 0 && J < I.length && tt(I[J])));
188
+ }, [
189
+ I,
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 && F) {
202
+ let e = F(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
+ }, [F]), ct = n((e) => K === e ? w(q === "asc" ? he : b, { className: "ml-1 size-3" }) : /* @__PURE__ */ w(ge, { 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(we, 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(se, {
245
+ value: t == null ? "" : String(t),
246
+ onValueChange: (t) => $(e.field, t),
247
+ children: [/* @__PURE__ */ w(ue, {
248
+ className: "h-8 text-xs",
249
+ children: /* @__PURE__ */ w(de, { placeholder: `Filter ${n}` })
250
+ }), /* @__PURE__ */ w(ce, { children: e.options?.map((e) => /* @__PURE__ */ w(le, {
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(ye, { 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: je,
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
+ R && /* @__PURE__ */ w(_e, {
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: Oe ? /* @__PURE__ */ w("div", {
345
+ "data-testid": "record-picker-filter-bar",
346
+ children: Oe({
347
+ filterColumns: Z,
348
+ values: Y,
349
+ onChange: $,
350
+ onClear: ut,
351
+ activeCount: dt
352
+ })
353
+ }) : /* @__PURE__ */ T(Ce, { 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(be, { 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(Se, { 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
+ z && /* @__PURE__ */ T("div", {
385
+ className: "flex flex-col items-center gap-2 py-4",
386
+ role: "alert",
387
+ children: [
388
+ /* @__PURE__ */ w(me, { className: "size-5 text-destructive" }),
389
+ /* @__PURE__ */ w("p", {
390
+ className: "text-sm text-destructive",
391
+ children: z
392
+ }),
393
+ /* @__PURE__ */ w(l, {
394
+ variant: "outline",
395
+ size: "sm",
396
+ onClick: () => Ye(je || void 0, U, Xe),
397
+ type: "button",
398
+ children: "Retry"
399
+ })
400
+ ]
401
+ }),
402
+ ke ? /* @__PURE__ */ w("div", {
403
+ className: "flex-1 min-h-0",
404
+ "data-testid": "record-picker-grid-slot",
405
+ children: ke({
406
+ columns: qe,
407
+ records: I,
408
+ loading: R,
409
+ totalCount: V,
410
+ currentPage: U,
411
+ pageSize: E,
412
+ sortField: K,
413
+ sortDirection: q,
414
+ onSort: Qe,
415
+ onPageChange: W,
416
+ onRowClick: tt,
417
+ isSelected: et,
418
+ multiple: c,
419
+ idField: xe,
420
+ cellRenderer: F
421
+ })
422
+ }) : /* @__PURE__ */ T(Ce, { children: [
423
+ R && I.length === 0 && !z && /* @__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(v, { children: /* @__PURE__ */ T(y, {
429
+ className: "bg-muted/40",
430
+ children: [c && /* @__PURE__ */ w(fe, { className: "w-10" }), qe.map((e) => /* @__PURE__ */ w(fe, { children: /* @__PURE__ */ w(m, { className: "h-4 w-20" }) }, e.field))]
431
+ }) }), /* @__PURE__ */ w(g, { children: Array.from({ length: O }, (e, t) => /* @__PURE__ */ T(y, { children: [c && /* @__PURE__ */ w(_, {
432
+ className: "w-10",
433
+ children: /* @__PURE__ */ w(m, { className: "size-4 rounded" })
434
+ }), qe.map((e) => /* @__PURE__ */ w(_, { children: /* @__PURE__ */ w(m, { className: "h-4 w-full" }) }, e.field))] }, t)) })] })
435
+ }),
436
+ !R && !z && I.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
+ !z && I.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: [R && /* @__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(_e, { 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(v, {
456
+ className: "sticky top-0 z-[5] bg-muted/50 [&_tr]:border-b",
457
+ "data-testid": "record-picker-sticky-header",
458
+ children: /* @__PURE__ */ T(y, { children: [c && /* @__PURE__ */ w(fe, { className: "w-10" }), qe.map((e) => {
459
+ let t = Ue[e.field];
460
+ return /* @__PURE__ */ T(fe, {
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(g, {
485
+ ref: ze,
486
+ children: I.map((e, t) => {
487
+ let n = $e(e), r = et(e), i = t === J;
488
+ return /* @__PURE__ */ T(y, {
489
+ "data-row-index": t,
490
+ className: pe("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(_, {
495
+ className: "w-10",
496
+ children: r && /* @__PURE__ */ w(x, { className: "size-4 text-primary" })
497
+ }), qe.map((t) => /* @__PURE__ */ w(_, {
498
+ className: "py-2.5",
499
+ children: st(e, t)
500
+ }, t.field))]
501
+ }, n ?? t);
502
+ })
503
+ })]
504
+ })]
505
+ }),
506
+ !z && V > 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
+ V,
511
+ " ",
512
+ V === 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(S, { 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(C, { 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 P() {
580
+ return M;
581
+ }
582
+ //#endregion
583
+ //#region src/widgets/LookupField.tsx
584
+ var F = /* @__PURE__ */ e({ LookupField: () => L }), De = 50, Oe = E;
585
+ function ke(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 I(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 L({ value: e, onChange: u, field: ee, readonly: te, ...ne }) {
608
+ let [re, d] = s(!1), [p, se] = s(""), { t: ce } = t(), [le, ue] = s([]), [de, m] = s(!1), [h, g] = s(null), [_, fe] = s(0), v = o(null), [y, pe] = s([]), [b, he] = s(-1), ge = o(null), x = ee || ne.schema, S = x?.field, C = S && typeof S == "object" && ("reference_to" in S || "reference" in S || "type" in S) ? S : x, be = C?.options || [], E = C?.multiple || !1, D = C?.display_field || C?.reference_field || "name", we = C?.description_field, O = C?.id_field || "id", k = C?.reference_to || C?.reference, A = C?.lookup_columns, Te = C?.lookup_page_size, Ee = C?.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 = I(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(Oe)?.dataSource ?? null, F = ne.dataSource ?? x?.dataSource ?? C?.dataSource ?? N, L = F != null && typeof F.find == "function" && !!k, R = ne.onCreateNew ?? x?.onCreateNew, [Ae, z] = s(!1), B = L ? le : be, V = a(() => {
621
+ if (L || !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
+ L,
626
+ B,
627
+ p
628
+ ]);
629
+ i(() => {
630
+ he(-1);
631
+ }, [V.length]);
632
+ let H = n(async (e) => {
633
+ if (!(!F || !k)) {
634
+ m(!0), g(null);
635
+ try {
636
+ let t = { $top: De };
637
+ e && e.trim() && (t.$search = e.trim());
638
+ let n = await F.find(k, t), r = n?.data ?? n ?? [];
639
+ ue(r.map((e) => ke(e, D, O, we))), fe(n?.total ?? r.length);
640
+ } catch (e) {
641
+ g(e instanceof Error ? e.message : String(e)), ue([]);
642
+ } finally {
643
+ m(!1);
644
+ }
645
+ }
646
+ }, [
647
+ F,
648
+ k,
649
+ D,
650
+ O,
651
+ we
652
+ ]);
653
+ i(() => {
654
+ re && L && H(p || void 0), re || (se(""), g(null), he(-1));
655
+ }, [re]);
656
+ let je = n((e) => {
657
+ se(e), L && (v.current && clearTimeout(v.current), v.current = setTimeout(() => {
658
+ H(e || void 0);
659
+ }, 300));
660
+ }, [L, H]);
661
+ i(() => () => {
662
+ v.current && clearTimeout(v.current);
663
+ }, []);
664
+ let Me = n((e) => be.find((t) => t.value === e) ?? le.find((t) => t.value === e) ?? y.find((t) => t.value === e), [
665
+ be,
666
+ le,
667
+ y
668
+ ]), U = E ? (Array.isArray(e) ? e : []).map(Me).filter(Boolean) : e ? [Me(e)].filter(Boolean) : [], W = 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
+ ]), G = (t) => {
678
+ u(E ? (Array.isArray(e) ? e : []).filter((e) => e !== t) : null);
679
+ }, K = n((e) => {
680
+ pe(e.map((e) => ke(e, D, O, we)));
681
+ }, [
682
+ D,
683
+ O,
684
+ we
685
+ ]), Ne = n((e) => {
686
+ e.key === "ArrowDown" ? (e.preventDefault(), he((e) => e < V.length - 1 ? e + 1 : e)) : e.key === "ArrowUp" ? (e.preventDefault(), he((e) => e > 0 ? e - 1 : 0)) : e.key === "Enter" && (e.preventDefault(), b >= 0 && b < V.length && W(V[b]));
687
+ }, [
688
+ V,
689
+ b,
690
+ W
691
+ ]);
692
+ return i(() => {
693
+ b >= 0 && ge.current && ge.current.querySelector(`[data-lookup-index="${b}"]`)?.scrollIntoView({ block: "nearest" });
694
+ }, [b]), te ? U.length ? E ? /* @__PURE__ */ w("div", {
695
+ className: "flex flex-wrap gap-1",
696
+ children: U.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: U[0]?.[D] || U[0]?.label
703
+ }) : /* @__PURE__ */ w("span", {
704
+ className: "text-sm",
705
+ children: "-"
706
+ }) : /* @__PURE__ */ T("div", {
707
+ className: "space-y-2",
708
+ children: [
709
+ U.length > 0 && /* @__PURE__ */ w("div", {
710
+ className: "flex flex-wrap gap-1",
711
+ children: U.map((e, t) => /* @__PURE__ */ T(c, {
712
+ variant: "outline",
713
+ className: "gap-1",
714
+ children: [e?.[D] || e?.label, /* @__PURE__ */ w("button", {
715
+ onClick: () => G(e?.value),
716
+ className: "ml-1 hover:text-destructive",
717
+ type: "button",
718
+ "aria-label": `Remove ${e?.[D] || e?.label}`,
719
+ children: /* @__PURE__ */ w(Se, { className: "size-3" })
720
+ })]
721
+ }, t))
722
+ }),
723
+ /* @__PURE__ */ T("div", {
724
+ className: "flex items-center gap-1.5",
725
+ children: [/* @__PURE__ */ T(ie, {
726
+ open: re,
727
+ onOpenChange: d,
728
+ children: [/* @__PURE__ */ w(oe, {
729
+ asChild: !0,
730
+ children: /* @__PURE__ */ T(l, {
731
+ variant: "outline",
732
+ className: "min-w-0 flex-1 justify-start text-left font-normal",
733
+ type: "button",
734
+ children: [/* @__PURE__ */ w(ye, { className: "mr-2 size-4" }), U.length === 0 ? x?.placeholder || ce("common.select") : E ? ce("table.selected", { count: U.length }) : ce("common.select")]
735
+ })
736
+ }), /* @__PURE__ */ T(ae, {
737
+ className: "w-[var(--radix-popover-trigger-width)] p-0",
738
+ align: "start",
739
+ children: [
740
+ /* @__PURE__ */ w("div", {
741
+ className: "p-2",
742
+ children: /* @__PURE__ */ T("div", {
743
+ className: "relative",
744
+ children: [
745
+ /* @__PURE__ */ w(ye, { className: "absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground" }),
746
+ /* @__PURE__ */ w(f, {
747
+ placeholder: ce("common.search") + "...",
748
+ value: p,
749
+ onChange: (e) => je(e.target.value),
750
+ onKeyDown: Ne,
751
+ className: "w-full pl-9 h-8 text-sm"
752
+ }),
753
+ de && /* @__PURE__ */ w(_e, {
754
+ className: "absolute right-3 top-1/2 -translate-y-1/2 size-4 animate-spin text-muted-foreground",
755
+ "data-testid": "lookup-loading"
756
+ })
757
+ ]
758
+ })
759
+ }),
760
+ h && /* @__PURE__ */ T("div", {
761
+ className: "flex flex-col items-center gap-2 py-4 px-2",
762
+ role: "alert",
763
+ children: [
764
+ /* @__PURE__ */ w(me, { className: "size-5 text-destructive" }),
765
+ /* @__PURE__ */ w("p", {
766
+ className: "text-sm text-destructive",
767
+ children: h
768
+ }),
769
+ /* @__PURE__ */ w(l, {
770
+ variant: "outline",
771
+ size: "sm",
772
+ onClick: () => H(p || void 0),
773
+ type: "button",
774
+ children: "Retry"
775
+ })
776
+ ]
777
+ }),
778
+ de && V.length === 0 && !h && /* @__PURE__ */ T("div", {
779
+ className: "flex flex-col items-center gap-2 py-6",
780
+ role: "status",
781
+ "aria-live": "polite",
782
+ children: [/* @__PURE__ */ w(_e, { className: "size-6 animate-spin text-muted-foreground" }), /* @__PURE__ */ w("p", {
783
+ className: "text-sm text-muted-foreground",
784
+ children: "Loading…"
785
+ })]
786
+ }),
787
+ !h && !(de && V.length === 0) && /* @__PURE__ */ w("div", {
788
+ ref: ge,
789
+ className: "max-h-64 overflow-y-auto px-1 pb-1",
790
+ role: "listbox",
791
+ children: V.length === 0 ? /* @__PURE__ */ T("div", {
792
+ className: "py-4 text-center",
793
+ children: [/* @__PURE__ */ w("p", {
794
+ className: "text-sm text-muted-foreground",
795
+ children: "No options found"
796
+ }), R && /* @__PURE__ */ T(l, {
797
+ variant: "ghost",
798
+ size: "sm",
799
+ className: "mt-2 gap-1",
800
+ type: "button",
801
+ onClick: () => {
802
+ R(p), d(!1);
803
+ },
804
+ children: [/* @__PURE__ */ w(ve, { className: "size-4" }), "Create new"]
805
+ })]
806
+ }) : /* @__PURE__ */ T(Ce, { children: [
807
+ V.map((t, n) => {
808
+ let r = E ? (Array.isArray(e) ? e : []).includes(t.value) : e === t.value;
809
+ return /* @__PURE__ */ T("button", {
810
+ "data-lookup-index": n,
811
+ role: "option",
812
+ "aria-selected": r,
813
+ onClick: () => W(t),
814
+ 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" : ""}`,
815
+ type: "button",
816
+ children: [/* @__PURE__ */ T("div", {
817
+ className: "min-w-0 flex-1",
818
+ children: [/* @__PURE__ */ w("span", {
819
+ className: "block truncate",
820
+ children: t.label
821
+ }), t.description && /* @__PURE__ */ w("span", {
822
+ className: "block truncate text-xs text-muted-foreground",
823
+ children: t.description
824
+ })]
825
+ }), r && /* @__PURE__ */ w(c, {
826
+ variant: "default",
827
+ className: "ml-2 shrink-0",
828
+ children: "Selected"
829
+ })]
830
+ }, t.value);
831
+ }),
832
+ L && _ > V.length && /* @__PURE__ */ T("p", {
833
+ className: "text-xs text-muted-foreground text-center py-2",
834
+ children: [
835
+ "Showing ",
836
+ V.length,
837
+ " of ",
838
+ _,
839
+ " results."
840
+ ]
841
+ }),
842
+ L && _ > V.length && /* @__PURE__ */ T("button", {
843
+ type: "button",
844
+ 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",
845
+ onClick: () => {
846
+ d(!1), z(!0);
847
+ },
848
+ "data-testid": "show-all-results",
849
+ children: [
850
+ /* @__PURE__ */ w(xe, { className: "size-3.5" }),
851
+ "Show All Results (",
852
+ _,
853
+ ")"
854
+ ]
855
+ }),
856
+ R && /* @__PURE__ */ T("button", {
857
+ type: "button",
858
+ 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",
859
+ onClick: () => {
860
+ R(p), d(!1);
861
+ },
862
+ children: [
863
+ /* @__PURE__ */ w(ve, { className: "size-3.5" }),
864
+ "Create new",
865
+ p ? ` "${p}"` : ""
866
+ ]
867
+ })
868
+ ] })
869
+ })
870
+ ]
871
+ })]
872
+ }), L && /* @__PURE__ */ w(l, {
873
+ variant: "outline",
874
+ size: "icon",
875
+ className: "shrink-0",
876
+ type: "button",
877
+ onClick: () => z(!0),
878
+ "aria-label": "Browse all records",
879
+ title: "Browse all records",
880
+ "data-testid": "browse-all-records",
881
+ children: /* @__PURE__ */ w(xe, { className: "size-4" })
882
+ })]
883
+ }),
884
+ L && F && k && /* @__PURE__ */ w(j, {
885
+ open: Ae,
886
+ onOpenChange: z,
887
+ title: x?.label || "Select",
888
+ multiple: E,
889
+ dataSource: F,
890
+ objectName: k,
891
+ columns: A,
892
+ displayField: D,
893
+ idField: O,
894
+ pageSize: Te,
895
+ value: e,
896
+ onSelect: u,
897
+ onSelectRecords: K,
898
+ lookupFilters: Ee,
899
+ cellRenderer: P(),
900
+ filterColumns: M
901
+ })
902
+ ]
903
+ });
904
+ }
905
+ //#endregion
906
+ export { j as i, F as n, N as r, L as t };