@veeyem/react-transfer-list 1.0.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 (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +206 -0
  3. package/dist/components/FilterPanel/FilterPanel.d.ts +4 -0
  4. package/dist/components/FilterPanel/FilterPanel.d.ts.map +1 -0
  5. package/dist/components/ListPanel/ListPanel.d.ts +23 -0
  6. package/dist/components/ListPanel/ListPanel.d.ts.map +1 -0
  7. package/dist/components/RemoteAutoComplete/RemoteAutoComplete.d.ts +9 -0
  8. package/dist/components/RemoteAutoComplete/RemoteAutoComplete.d.ts.map +1 -0
  9. package/dist/components/RemoteSelect/RemoteSelect.d.ts +9 -0
  10. package/dist/components/RemoteSelect/RemoteSelect.d.ts.map +1 -0
  11. package/dist/components/TransferList/TransferList.d.ts +5 -0
  12. package/dist/components/TransferList/TransferList.d.ts.map +1 -0
  13. package/dist/components/filter/FilterField.d.ts +11 -0
  14. package/dist/components/filter/FilterField.d.ts.map +1 -0
  15. package/dist/components/filter/FloatingDropdown.d.ts +11 -0
  16. package/dist/components/filter/FloatingDropdown.d.ts.map +1 -0
  17. package/dist/components/filter/MultiSelect.d.ts +31 -0
  18. package/dist/components/filter/MultiSelect.d.ts.map +1 -0
  19. package/dist/components/filter/fieldStyles.d.ts +2 -0
  20. package/dist/components/filter/fieldStyles.d.ts.map +1 -0
  21. package/dist/hooks/index.d.ts +4 -0
  22. package/dist/hooks/index.d.ts.map +1 -0
  23. package/dist/hooks/useDebouncedValue.d.ts +2 -0
  24. package/dist/hooks/useDebouncedValue.d.ts.map +1 -0
  25. package/dist/hooks/useRemoteListOptions.d.ts +24 -0
  26. package/dist/hooks/useRemoteListOptions.d.ts.map +1 -0
  27. package/dist/hooks/useTransferData.d.ts +18 -0
  28. package/dist/hooks/useTransferData.d.ts.map +1 -0
  29. package/dist/icons/index.d.ts +22 -0
  30. package/dist/icons/index.d.ts.map +1 -0
  31. package/dist/index.cjs.js +2116 -0
  32. package/dist/index.d.ts +6 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.esm.js +2083 -0
  35. package/dist/styles/componentStyles.d.ts +2 -0
  36. package/dist/styles/componentStyles.d.ts.map +1 -0
  37. package/dist/styles/index.d.ts +4 -0
  38. package/dist/styles/index.d.ts.map +1 -0
  39. package/dist/styles/injectStyles.d.ts +2 -0
  40. package/dist/styles/injectStyles.d.ts.map +1 -0
  41. package/dist/styles/tokens.d.ts +31 -0
  42. package/dist/styles/tokens.d.ts.map +1 -0
  43. package/dist/types/index.d.ts +61 -0
  44. package/dist/types/index.d.ts.map +1 -0
  45. package/dist/utils/clipboard.d.ts +5 -0
  46. package/dist/utils/clipboard.d.ts.map +1 -0
  47. package/dist/utils/fetch.d.ts +3 -0
  48. package/dist/utils/fetch.d.ts.map +1 -0
  49. package/dist/utils/filters.d.ts +5 -0
  50. package/dist/utils/filters.d.ts.map +1 -0
  51. package/dist/utils/index.d.ts +6 -0
  52. package/dist/utils/index.d.ts.map +1 -0
  53. package/dist/utils/items.d.ts +7 -0
  54. package/dist/utils/items.d.ts.map +1 -0
  55. package/dist/utils/listFetch.d.ts +7 -0
  56. package/dist/utils/listFetch.d.ts.map +1 -0
  57. package/package.json +81 -0
@@ -0,0 +1,2116 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+ var reactDom = require('react-dom');
7
+
8
+ function _interopNamespaceDefault(e) {
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () { return e[k]; }
17
+ });
18
+ }
19
+ });
20
+ }
21
+ n.default = e;
22
+ return Object.freeze(n);
23
+ }
24
+
25
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
26
+
27
+ function FilterToggleIcon({ open, size = 14 }) {
28
+ return (React__namespace.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: size, height: size, viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true" },
29
+ React__namespace.createElement("polyline", { points: open ? "6 15 12 9 18 15" : "6 9 12 15 18 9" })));
30
+ }
31
+ function FilterPanelIcon({ size = 16 }) {
32
+ return (React__namespace.createElement("svg", { width: size, height: size, viewBox: "0 0 20 20", fill: "none", "aria-hidden": "true" },
33
+ React__namespace.createElement("path", { d: "M3 5h14M5 10h10M7 15h6", stroke: "currentColor", strokeWidth: "1.75", strokeLinecap: "round" })));
34
+ }
35
+ function ResetIcon({ size = 15 }) {
36
+ return (React__namespace.createElement("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true" },
37
+ React__namespace.createElement("path", { d: "M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" }),
38
+ React__namespace.createElement("path", { d: "M3 3v5h5" })));
39
+ }
40
+ function ApplyIcon({ size = 14 }) {
41
+ return (React__namespace.createElement("svg", { width: size, height: size, viewBox: "0 0 20 20", fill: "none", "aria-hidden": "true" },
42
+ React__namespace.createElement("path", { d: "M5 10.5l3 3 7-7", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })));
43
+ }
44
+ function ChevronDoubleRightIcon({ size = 16 }) {
45
+ return (React__namespace.createElement("svg", { width: size, height: size, fill: "currentColor", viewBox: "0 0 20 20", "aria-hidden": "true" },
46
+ React__namespace.createElement("path", { fillRule: "evenodd", d: "M10.293 15.707a1 1 0 010-1.414L14.586 10l-4.293-4.293a1 1 0 111.414-1.414l5 5a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0z", clipRule: "evenodd" }),
47
+ React__namespace.createElement("path", { fillRule: "evenodd", d: "M4.293 15.707a1 1 0 010-1.414L8.586 10 4.293 5.707a1 1 0 011.414-1.414l5 5a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0z", clipRule: "evenodd" })));
48
+ }
49
+ function XMarkIcon({ size = 16 }) {
50
+ return (React__namespace.createElement("svg", { width: size, height: size, fill: "currentColor", viewBox: "0 0 20 20", "aria-hidden": "true" },
51
+ React__namespace.createElement("path", { fillRule: "evenodd", d: "M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z", clipRule: "evenodd" })));
52
+ }
53
+ function SearchIcon({ size = 15 }) {
54
+ return (React__namespace.createElement("svg", { width: size, height: size, viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true" },
55
+ React__namespace.createElement("circle", { cx: "9", cy: "9", r: "5.5" }),
56
+ React__namespace.createElement("path", { d: "M14 14l3 3" })));
57
+ }
58
+ function CopyIcon({ size = 14 }) {
59
+ return (React__namespace.createElement("svg", { width: size, height: size, viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "1.75", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true" },
60
+ React__namespace.createElement("rect", { x: "7", y: "7", width: "10", height: "10", rx: "1.5" }),
61
+ React__namespace.createElement("path", { d: "M5 13H4a1.5 1.5 0 01-1.5-1.5V4A1.5 1.5 0 014 2.5h7.5A1.5 1.5 0 0113 4v1" })));
62
+ }
63
+ function PasteIcon({ size = 14 }) {
64
+ return (React__namespace.createElement("svg", { width: size, height: size, viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "1.75", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true" },
65
+ React__namespace.createElement("path", { d: "M7 3.5h6l1 2H6l1-2z" }),
66
+ React__namespace.createElement("rect", { x: "5", y: "5.5", width: "10", height: "11", rx: "1.5" })));
67
+ }
68
+ function ExcludedPanelIcon({ size = 14 }) {
69
+ return (React__namespace.createElement("svg", { width: size, height: size, viewBox: "0 0 20 20", fill: "none", "aria-hidden": "true" },
70
+ React__namespace.createElement("rect", { x: "3.5", y: "4.5", width: "13", height: "11", rx: "2", stroke: "currentColor", strokeWidth: "1.75" }),
71
+ React__namespace.createElement("path", { d: "M3.5 8.5h13", stroke: "currentColor", strokeWidth: "1.75", strokeLinecap: "round" }),
72
+ React__namespace.createElement("path", { d: "M7.5 12h5", stroke: "currentColor", strokeWidth: "1.75", strokeLinecap: "round" })));
73
+ }
74
+ function IncludedPanelIcon({ size = 14 }) {
75
+ return (React__namespace.createElement("svg", { width: size, height: size, viewBox: "0 0 20 20", fill: "none", "aria-hidden": "true" },
76
+ React__namespace.createElement("circle", { cx: "10", cy: "10", r: "6.75", stroke: "currentColor", strokeWidth: "1.75" }),
77
+ React__namespace.createElement("path", { d: "M7 10l2.25 2.25L13 8.5", stroke: "currentColor", strokeWidth: "1.75", strokeLinecap: "round", strokeLinejoin: "round" })));
78
+ }
79
+ function CheckIcon({ size = 14 }) {
80
+ return (React__namespace.createElement("svg", { width: size, height: size, viewBox: "0 0 20 20", fill: "currentColor", "aria-hidden": "true" },
81
+ React__namespace.createElement("path", { fillRule: "evenodd", d: "M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z", clipRule: "evenodd" })));
82
+ }
83
+ function ChevronDownIcon({ size = 14 }) {
84
+ return (React__namespace.createElement("svg", { width: size, height: size, viewBox: "0 0 20 20", fill: "currentColor", "aria-hidden": "true" },
85
+ React__namespace.createElement("path", { fillRule: "evenodd", d: "M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z", clipRule: "evenodd" })));
86
+ }
87
+
88
+ function dedupeById(items) {
89
+ const seen = new Set();
90
+ return items.filter((item) => {
91
+ if (seen.has(item.id))
92
+ return false;
93
+ seen.add(item.id);
94
+ return true;
95
+ });
96
+ }
97
+ function filterBySearch(items, search) {
98
+ if (!search.trim())
99
+ return items;
100
+ const lower = search.toLowerCase();
101
+ return items.filter((item) => { var _a; return (_a = item.text) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().includes(lower); });
102
+ }
103
+ function excludeByIds(items, excluded) {
104
+ const excludedIds = new Set(excluded.map((item) => item.id));
105
+ return items.filter((item) => !excludedIds.has(item.id));
106
+ }
107
+ function isValidTransferItem(item) {
108
+ if (!item || typeof item !== "object")
109
+ return false;
110
+ const candidate = item;
111
+ return candidate.id != null && typeof candidate.text === "string";
112
+ }
113
+ function parseTransferItems(data) {
114
+ if (!Array.isArray(data))
115
+ return [];
116
+ return dedupeById(data.filter(isValidTransferItem));
117
+ }
118
+
119
+ function buildFilterArray(filterValues, filters) {
120
+ return Object.entries(filterValues)
121
+ .filter(([, val]) => {
122
+ if (val == null)
123
+ return false;
124
+ if (val === "")
125
+ return false;
126
+ if (val === false)
127
+ return false;
128
+ if (Array.isArray(val) && val.length === 0)
129
+ return false;
130
+ return true;
131
+ })
132
+ .map(([key, val]) => {
133
+ const config = filters.find((f) => f.key === key);
134
+ if ((config === null || config === void 0 ? void 0 : config.type) === "autocomplete" && Array.isArray(val)) {
135
+ return {
136
+ [key]: val.map((option) => option.value),
137
+ };
138
+ }
139
+ return { [key]: val };
140
+ });
141
+ }
142
+ function getDefaultFilterValues(filters) {
143
+ const defaults = {};
144
+ filters.forEach((filter) => {
145
+ if (filter.defaultValue !== undefined) {
146
+ defaults[filter.key] = filter.defaultValue;
147
+ }
148
+ });
149
+ return defaults;
150
+ }
151
+ function getChipLabel(filterObj, filters, filterValues) {
152
+ var _a, _b, _c;
153
+ const key = Object.keys(filterObj)[0];
154
+ const val = filterObj[key];
155
+ const config = filters.find((f) => f.key === key);
156
+ const displayKey = (_a = config === null || config === void 0 ? void 0 : config.label) !== null && _a !== void 0 ? _a : key;
157
+ if ((config === null || config === void 0 ? void 0 : config.type) === "autocomplete") {
158
+ const selected = filterValues[key];
159
+ if (Array.isArray(selected)) {
160
+ const labels = selected
161
+ .map((option) => option.label)
162
+ .join(", ");
163
+ return `${displayKey}: ${labels}`;
164
+ }
165
+ }
166
+ if ((config === null || config === void 0 ? void 0 : config.options) &&
167
+ (config.type === "select" ||
168
+ config.type === "radio" ||
169
+ (config.type === "chip" && !config.multiple)) &&
170
+ typeof val === "string") {
171
+ const label = (_c = (_b = config.options.find((o) => o.value === val)) === null || _b === void 0 ? void 0 : _b.label) !== null && _c !== void 0 ? _c : val;
172
+ return `${displayKey}: ${label}`;
173
+ }
174
+ if ((config === null || config === void 0 ? void 0 : config.type) === "chip" && config.multiple && Array.isArray(val)) {
175
+ const labels = val
176
+ .map((v) => { var _a, _b, _c; return (_c = (_b = (_a = config.options) === null || _a === void 0 ? void 0 : _a.find((o) => o.value === v)) === null || _b === void 0 ? void 0 : _b.label) !== null && _c !== void 0 ? _c : v; })
177
+ .join(", ");
178
+ return `${displayKey}: ${labels}`;
179
+ }
180
+ if ((config === null || config === void 0 ? void 0 : config.type) === "switch") {
181
+ return `${displayKey}: ${val ? "Yes" : "No"}`;
182
+ }
183
+ if ((config === null || config === void 0 ? void 0 : config.type) === "color" && typeof val === "string") {
184
+ return `${displayKey}: ${val}`;
185
+ }
186
+ if ((config === null || config === void 0 ? void 0 : config.type) === "checkbox" && Array.isArray(val)) {
187
+ const labels = val
188
+ .map((v) => { var _a, _b, _c; return (_c = (_b = (_a = config.options) === null || _a === void 0 ? void 0 : _a.find((o) => o.value === v)) === null || _b === void 0 ? void 0 : _b.label) !== null && _c !== void 0 ? _c : v; })
189
+ .join(", ");
190
+ return `${displayKey}: ${labels}`;
191
+ }
192
+ const displayVal = Array.isArray(val) ? val.join(", ") : String(val !== null && val !== void 0 ? val : "");
193
+ return `${displayKey}: ${displayVal}`;
194
+ }
195
+
196
+ const defaultFetchFn = async (url, { search, filter }) => {
197
+ const filterParams = new URLSearchParams();
198
+ filterParams.append("search", search !== null && search !== void 0 ? search : "");
199
+ filterParams.append("filter", JSON.stringify(filter !== null && filter !== void 0 ? filter : []));
200
+ const response = await fetch(`${url}?${filterParams.toString()}`, {
201
+ method: "GET",
202
+ headers: { "Content-Type": "application/json" },
203
+ });
204
+ if (!response.ok) {
205
+ throw new Error(`HTTP error! status: ${response.status}`);
206
+ }
207
+ const result = await response.json();
208
+ if (Array.isArray(result))
209
+ return result;
210
+ if (Array.isArray(result === null || result === void 0 ? void 0 : result.data))
211
+ return result.data;
212
+ return [];
213
+ };
214
+
215
+ /** Shared across TransferList instances on the same page for one-click paste. */
216
+ let transferListClipboard = null;
217
+ function setTransferListClipboard(items) {
218
+ transferListClipboard = dedupeById([...items]);
219
+ }
220
+ function getTransferListClipboard() {
221
+ return transferListClipboard;
222
+ }
223
+ async function copyToClipboard(text) {
224
+ if (navigator.clipboard && window.isSecureContext) {
225
+ return navigator.clipboard.writeText(text);
226
+ }
227
+ const textarea = document.createElement("textarea");
228
+ textarea.value = text;
229
+ textarea.style.position = "fixed";
230
+ textarea.style.left = "-99999px";
231
+ document.body.appendChild(textarea);
232
+ textarea.select();
233
+ document.execCommand("copy");
234
+ document.body.removeChild(textarea);
235
+ }
236
+
237
+ /** Maps `{ id, text }` or `{ label, value }` API rows to FilterOption */
238
+ function mapToFilterOptions(data) {
239
+ if (!Array.isArray(data))
240
+ return [];
241
+ return data
242
+ .map((item) => {
243
+ if (!item || typeof item !== "object")
244
+ return null;
245
+ const record = item;
246
+ if (record.value != null && record.label != null) {
247
+ return {
248
+ value: String(record.value),
249
+ label: String(record.label),
250
+ };
251
+ }
252
+ if (record.id != null && record.text != null) {
253
+ return {
254
+ value: String(record.id),
255
+ label: String(record.text),
256
+ };
257
+ }
258
+ return null;
259
+ })
260
+ .filter((item) => item != null);
261
+ }
262
+ function mergeFilterOptions(...groups) {
263
+ const seen = new Set();
264
+ const merged = [];
265
+ for (const group of groups) {
266
+ for (const option of group) {
267
+ if (seen.has(option.value))
268
+ continue;
269
+ seen.add(option.value);
270
+ merged.push(option);
271
+ }
272
+ }
273
+ return merged;
274
+ }
275
+ /** Default fetch for paginated `/list` endpoints */
276
+ const defaultAutocompleteFetchFn = async (url, params = {}) => {
277
+ var _a, _b, _c;
278
+ const query = new URLSearchParams();
279
+ const search = (_b = (_a = params.search) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : "";
280
+ if (search)
281
+ query.append("search", search);
282
+ query.append("limit", String((_c = params.limit) !== null && _c !== void 0 ? _c : 50));
283
+ if (params.page && params.page > 1) {
284
+ query.append("page", String(params.page));
285
+ }
286
+ const qs = query.toString();
287
+ const response = await fetch(qs ? `${url}?${qs}` : url, {
288
+ method: "GET",
289
+ headers: { "Content-Type": "application/json" },
290
+ });
291
+ if (!response.ok) {
292
+ throw new Error(`HTTP error! status: ${response.status}`);
293
+ }
294
+ const result = await response.json();
295
+ if (Array.isArray(result))
296
+ return mapToFilterOptions(result);
297
+ if (Array.isArray(result === null || result === void 0 ? void 0 : result.data))
298
+ return mapToFilterOptions(result.data);
299
+ return [];
300
+ };
301
+
302
+ function useDebouncedValue(value, delayMs = 300) {
303
+ const [debounced, setDebounced] = React__namespace.useState(value);
304
+ React__namespace.useEffect(() => {
305
+ const timer = setTimeout(() => setDebounced(value), delayMs);
306
+ return () => clearTimeout(timer);
307
+ }, [value, delayMs]);
308
+ return debounced;
309
+ }
310
+
311
+ function useTransferData({ remoteUrl, fetchFn, search, filter, dataRight, }) {
312
+ const [dataLeft, setDataLeft] = React__namespace.useState([]);
313
+ const [loading, setLoading] = React__namespace.useState(false);
314
+ const [error, setError] = React__namespace.useState(null);
315
+ const fetchData = React__namespace.useCallback(async () => {
316
+ setLoading(true);
317
+ setError(null);
318
+ try {
319
+ if (Array.isArray(remoteUrl)) {
320
+ const available = excludeByIds(remoteUrl, dataRight);
321
+ setDataLeft(filterBySearch(available, search));
322
+ return;
323
+ }
324
+ const queryFilter = [...filter];
325
+ const rightItemIds = dataRight.map((item) => item.id);
326
+ if (rightItemIds.length > 0) {
327
+ queryFilter.push({ selectedIds: rightItemIds });
328
+ }
329
+ const result = await fetchFn(remoteUrl, {
330
+ search,
331
+ filter: queryFilter,
332
+ });
333
+ const data = Array.isArray(result) ? result : [];
334
+ setDataLeft(excludeByIds(data, dataRight));
335
+ }
336
+ catch (err) {
337
+ const message = err instanceof Error ? err.message : "Failed to fetch data";
338
+ setError(message);
339
+ setDataLeft([]);
340
+ }
341
+ finally {
342
+ setLoading(false);
343
+ }
344
+ }, [remoteUrl, fetchFn, search, filter, dataRight]);
345
+ React__namespace.useEffect(() => {
346
+ fetchData();
347
+ }, [fetchData]);
348
+ return { dataLeft, setDataLeft, loading, error, refetch: fetchData };
349
+ }
350
+
351
+ function useRemoteListOptions({ remoteUrl, staticOptions = [], fetchFn = defaultAutocompleteFetchFn, search = "", limit = 50, enabled = true, selected = [], }) {
352
+ const [options, setOptions] = React__namespace.useState(staticOptions);
353
+ const [loading, setLoading] = React__namespace.useState(false);
354
+ const [loadingMore, setLoadingMore] = React__namespace.useState(false);
355
+ const [page, setPage] = React__namespace.useState(1);
356
+ const [hasMore, setHasMore] = React__namespace.useState(false);
357
+ const [error, setError] = React__namespace.useState(null);
358
+ const abortRef = React__namespace.useRef(null);
359
+ const selectedRef = React__namespace.useRef(selected);
360
+ const debouncedSearch = useDebouncedValue(search, 300);
361
+ React__namespace.useEffect(() => {
362
+ selectedRef.current = selected;
363
+ }, [selected]);
364
+ const fetchPage = React__namespace.useCallback(async (pageNum, append) => {
365
+ var _a;
366
+ if (!remoteUrl || !enabled)
367
+ return;
368
+ (_a = abortRef.current) === null || _a === void 0 ? void 0 : _a.abort();
369
+ const controller = new AbortController();
370
+ abortRef.current = controller;
371
+ if (append)
372
+ setLoadingMore(true);
373
+ else
374
+ setLoading(true);
375
+ setError(null);
376
+ try {
377
+ const result = await fetchFn(remoteUrl, {
378
+ search: debouncedSearch,
379
+ limit,
380
+ page: pageNum,
381
+ });
382
+ if (controller.signal.aborted)
383
+ return;
384
+ setOptions((prev) => mergeFilterOptions(append ? prev : [], result, selectedRef.current));
385
+ setHasMore(result.length >= limit);
386
+ setPage(pageNum);
387
+ }
388
+ catch (err) {
389
+ if (controller.signal.aborted)
390
+ return;
391
+ const message = err instanceof Error ? err.message : "Failed to load options";
392
+ setError(message);
393
+ if (!append) {
394
+ setOptions(mergeFilterOptions(selectedRef.current));
395
+ }
396
+ }
397
+ finally {
398
+ if (!controller.signal.aborted) {
399
+ setLoading(false);
400
+ setLoadingMore(false);
401
+ }
402
+ }
403
+ }, [remoteUrl, enabled, fetchFn, debouncedSearch, limit]);
404
+ React__namespace.useEffect(() => {
405
+ if (!remoteUrl)
406
+ return;
407
+ fetchPage(1, false);
408
+ }, [remoteUrl, debouncedSearch, limit, enabled, fetchPage]);
409
+ const loadMore = React__namespace.useCallback(() => {
410
+ if (!hasMore || loading || loadingMore)
411
+ return;
412
+ fetchPage(page + 1, true);
413
+ }, [hasMore, loading, loadingMore, fetchPage, page]);
414
+ const refresh = React__namespace.useCallback(() => {
415
+ setPage(1);
416
+ fetchPage(1, false);
417
+ }, [fetchPage]);
418
+ React__namespace.useEffect(() => {
419
+ return () => { var _a; return (_a = abortRef.current) === null || _a === void 0 ? void 0 : _a.abort(); };
420
+ }, []);
421
+ return {
422
+ options: remoteUrl ? options : staticOptions,
423
+ loading,
424
+ loadingMore,
425
+ hasMore: remoteUrl ? hasMore : false,
426
+ error,
427
+ loadMore,
428
+ refresh,
429
+ };
430
+ }
431
+ function getListLimit(config) {
432
+ var _a;
433
+ return (_a = config.limit) !== null && _a !== void 0 ? _a : 50;
434
+ }
435
+
436
+ const colors = {
437
+ primaryLight: "#e0f2fe",
438
+ primaryBorder: "#bae6fd",
439
+ primaryText: "#0369a1",
440
+ slate900: "#0f172a",
441
+ slate700: "#334155",
442
+ slate300: "#cbd5e1",
443
+ white: "#ffffff",
444
+ };
445
+ const inputStyle = {
446
+ width: "100%",
447
+ boxSizing: "border-box",
448
+ padding: "9px 12px",
449
+ borderRadius: 8,
450
+ border: `1px solid ${colors.slate300}`,
451
+ background: colors.white,
452
+ fontSize: 13,
453
+ color: colors.slate900,
454
+ outline: "none",
455
+ transition: "border-color 0.15s, box-shadow 0.15s",
456
+ };
457
+ const labelStyle = {
458
+ fontSize: 12,
459
+ fontWeight: 650,
460
+ color: colors.slate700,
461
+ marginBottom: 8,
462
+ display: "block",
463
+ letterSpacing: "0.01em",
464
+ };
465
+ const fieldWrapStyle = {
466
+ display: "flex",
467
+ flexDirection: "column",
468
+ minWidth: 0,
469
+ width: "100%",
470
+ };
471
+ const inlineSearchStyle = {
472
+ flex: "1 1 80px",
473
+ minWidth: 60,
474
+ border: "none",
475
+ outline: "none",
476
+ background: "transparent",
477
+ fontSize: 13,
478
+ color: "#111827",
479
+ padding: "2px 4px",
480
+ };
481
+ const chipStyle = {
482
+ display: "inline-flex",
483
+ alignItems: "center",
484
+ gap: 4,
485
+ padding: "4px 8px",
486
+ borderRadius: 6,
487
+ background: colors.primaryLight,
488
+ border: `1px solid ${colors.primaryBorder}`,
489
+ color: colors.primaryText,
490
+ fontSize: 12,
491
+ fontWeight: 500,
492
+ lineHeight: 1.2,
493
+ maxWidth: "100%",
494
+ };
495
+ function focusInput(el) {
496
+ el.style.borderColor = "#93c5fd";
497
+ el.style.boxShadow = "0 0 0 3px rgba(59,130,246,0.12)";
498
+ }
499
+ function blurInput(el) {
500
+ el.style.borderColor = colors.slate300;
501
+ el.style.boxShadow = "none";
502
+ }
503
+
504
+ function SelectionChip({ label, onRemove, }) {
505
+ return (React__namespace.createElement("span", { style: chipStyle },
506
+ React__namespace.createElement("span", { style: {
507
+ overflow: "hidden",
508
+ textOverflow: "ellipsis",
509
+ whiteSpace: "nowrap",
510
+ } }, label),
511
+ React__namespace.createElement("button", { type: "button", "aria-label": `Remove ${label}`, onClick: (e) => {
512
+ e.stopPropagation();
513
+ onRemove();
514
+ }, style: {
515
+ border: "none",
516
+ background: "#bae6fd",
517
+ color: "#0369a1",
518
+ borderRadius: "50%",
519
+ width: 16,
520
+ height: 16,
521
+ fontSize: 12,
522
+ lineHeight: 1,
523
+ cursor: "pointer",
524
+ display: "flex",
525
+ alignItems: "center",
526
+ justifyContent: "center",
527
+ flexShrink: 0,
528
+ padding: 0,
529
+ } }, "\u00D7")));
530
+ }
531
+ function MultiSelectBox({ children, focused = false, onClick, minHeight = 40, }) {
532
+ return (React__namespace.createElement("div", { onClick: onClick, style: {
533
+ display: "flex",
534
+ flexWrap: "wrap",
535
+ alignItems: "center",
536
+ gap: 6,
537
+ padding: "6px 8px",
538
+ minHeight,
539
+ borderRadius: 8,
540
+ border: `1px solid ${focused ? "#60a5fa" : "#cbd5e1"}`,
541
+ background: "#fff",
542
+ boxShadow: focused ? "0 0 0 3px rgba(59,130,246,0.14)" : "none",
543
+ cursor: "text",
544
+ transition: "border-color 0.15s, box-shadow 0.15s",
545
+ } }, children));
546
+ }
547
+ function MultiSelectToolbar({ selectedCount, totalCount, onSelectAll, onClear, }) {
548
+ return (React__namespace.createElement("div", { style: {
549
+ display: "flex",
550
+ alignItems: "center",
551
+ justifyContent: "space-between",
552
+ flexWrap: "wrap",
553
+ gap: "6px 12px",
554
+ marginBottom: 10,
555
+ } },
556
+ React__namespace.createElement("span", { style: { fontSize: 11, color: "#64748b", fontWeight: 500 } }, selectedCount > 0
557
+ ? `${selectedCount} of ${totalCount} selected`
558
+ : `${totalCount} options`),
559
+ React__namespace.createElement("div", { style: { display: "flex", gap: 10 } },
560
+ React__namespace.createElement("button", { type: "button", onClick: onSelectAll, disabled: selectedCount === totalCount, style: {
561
+ border: "none",
562
+ background: "transparent",
563
+ color: selectedCount === totalCount ? "#9ca3af" : "#0baae9",
564
+ fontSize: 11,
565
+ fontWeight: 600,
566
+ cursor: selectedCount === totalCount ? "default" : "pointer",
567
+ padding: 0,
568
+ } }, "Select all"),
569
+ React__namespace.createElement("button", { type: "button", onClick: onClear, disabled: selectedCount === 0, style: {
570
+ border: "none",
571
+ background: "transparent",
572
+ color: selectedCount === 0 ? "#9ca3af" : "#dc2626",
573
+ fontSize: 11,
574
+ fontWeight: 600,
575
+ cursor: selectedCount === 0 ? "default" : "pointer",
576
+ padding: 0,
577
+ } }, "Clear"))));
578
+ }
579
+ function ToggleOptionPill({ label, selected, onClick, }) {
580
+ return (React__namespace.createElement("button", { type: "button", onClick: onClick, style: {
581
+ display: "inline-flex",
582
+ alignItems: "center",
583
+ gap: 6,
584
+ padding: "7px 12px",
585
+ borderRadius: 8,
586
+ border: selected ? "1px solid #0baae9" : "1px solid #cbd5e1",
587
+ background: selected
588
+ ? "linear-gradient(180deg, #e0f2fe 0%, #f0f9ff 100%)"
589
+ : "#fff",
590
+ color: selected ? "#0369a1" : "#334155",
591
+ fontSize: 13,
592
+ fontWeight: selected ? 600 : 500,
593
+ cursor: "pointer",
594
+ transition: "all 0.15s",
595
+ boxShadow: selected ? "0 1px 2px rgba(11,170,233,0.15)" : "none",
596
+ } },
597
+ React__namespace.createElement("span", { style: {
598
+ width: 16,
599
+ height: 16,
600
+ borderRadius: 4,
601
+ border: selected ? "none" : "1.5px solid #d1d5db",
602
+ background: selected ? "#0baae9" : "#fff",
603
+ display: "flex",
604
+ alignItems: "center",
605
+ justifyContent: "center",
606
+ color: "#fff",
607
+ flexShrink: 0,
608
+ } }, selected && React__namespace.createElement(CheckIcon, { size: 11 })),
609
+ label));
610
+ }
611
+ function DropdownOptionRow({ label, selected, onClick, }) {
612
+ return (React__namespace.createElement("button", { type: "button", onClick: onClick, style: {
613
+ width: "100%",
614
+ display: "flex",
615
+ alignItems: "center",
616
+ gap: 10,
617
+ padding: "8px 10px",
618
+ border: "none",
619
+ borderBottom: "1px solid #f3f4f6",
620
+ background: selected ? "#f0f9ff" : "#fff",
621
+ color: selected ? "#0369a1" : "#374151",
622
+ fontSize: 13,
623
+ textAlign: "left",
624
+ cursor: "pointer",
625
+ transition: "background 0.1s",
626
+ }, onMouseEnter: (e) => {
627
+ if (!selected)
628
+ e.currentTarget.style.background = "#f9fafb";
629
+ }, onMouseLeave: (e) => {
630
+ e.currentTarget.style.background = selected ? "#f0f9ff" : "#fff";
631
+ } },
632
+ React__namespace.createElement("span", { style: {
633
+ width: 18,
634
+ height: 18,
635
+ borderRadius: 4,
636
+ border: selected ? "none" : "1.5px solid #d1d5db",
637
+ background: selected ? "#0baae9" : "#fff",
638
+ display: "flex",
639
+ alignItems: "center",
640
+ justifyContent: "center",
641
+ color: "#fff",
642
+ flexShrink: 0,
643
+ } }, selected && React__namespace.createElement(CheckIcon, { size: 12 })),
644
+ React__namespace.createElement("span", { style: { flex: 1 } }, label)));
645
+ }
646
+
647
+ function FloatingDropdown({ anchorRef, open, children, estimatedHeight = 280, dropdownRef, }) {
648
+ const [coords, setCoords] = React__namespace.useState(null);
649
+ const updatePosition = React__namespace.useCallback(() => {
650
+ const anchor = anchorRef.current;
651
+ if (!anchor)
652
+ return;
653
+ const rect = anchor.getBoundingClientRect();
654
+ const spaceBelow = window.innerHeight - rect.bottom;
655
+ const openUp = spaceBelow < estimatedHeight && rect.top > spaceBelow;
656
+ setCoords({
657
+ left: rect.left,
658
+ width: rect.width,
659
+ top: openUp ? undefined : rect.bottom + 4,
660
+ bottom: openUp ? window.innerHeight - rect.top + 4 : undefined,
661
+ });
662
+ }, [anchorRef, estimatedHeight]);
663
+ React__namespace.useLayoutEffect(() => {
664
+ if (!open)
665
+ return;
666
+ updatePosition();
667
+ window.addEventListener("scroll", updatePosition, true);
668
+ window.addEventListener("resize", updatePosition);
669
+ return () => {
670
+ window.removeEventListener("scroll", updatePosition, true);
671
+ window.removeEventListener("resize", updatePosition);
672
+ };
673
+ }, [open, updatePosition]);
674
+ if (!open || !coords)
675
+ return null;
676
+ return reactDom.createPortal(React__namespace.createElement("div", { ref: dropdownRef, style: {
677
+ position: "fixed",
678
+ left: coords.left,
679
+ width: coords.width,
680
+ top: coords.top,
681
+ bottom: coords.bottom,
682
+ zIndex: 10000,
683
+ } }, children), document.body);
684
+ }
685
+
686
+ function RemoteAutocomplete({ config, value, onChange, autocompleteFetchFn = defaultAutocompleteFetchFn, }) {
687
+ var _a, _b;
688
+ const [inputValue, setInputValue] = React__namespace.useState("");
689
+ const [open, setOpen] = React__namespace.useState(false);
690
+ const [focused, setFocused] = React__namespace.useState(false);
691
+ const containerRef = React__namespace.useRef(null);
692
+ const dropdownRef = React__namespace.useRef(null);
693
+ const inputRef = React__namespace.useRef(null);
694
+ const listRef = React__namespace.useRef(null);
695
+ const limit = getListLimit(config);
696
+ const { options, loading, loadingMore, hasMore, error, loadMore } = useRemoteListOptions({
697
+ remoteUrl: config.remoteUrl,
698
+ staticOptions: (_a = config.options) !== null && _a !== void 0 ? _a : [],
699
+ fetchFn: autocompleteFetchFn,
700
+ search: config.remoteUrl ? inputValue : "",
701
+ limit,
702
+ enabled: open,
703
+ selected: value,
704
+ });
705
+ const filteredOptions = config.remoteUrl
706
+ ? options
707
+ : options.filter((opt) => opt.label.toLowerCase().includes(inputValue.toLowerCase()));
708
+ React__namespace.useEffect(() => {
709
+ const handleClickOutside = (event) => {
710
+ var _a, _b;
711
+ const target = event.target;
712
+ if (((_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.contains(target)) ||
713
+ ((_b = dropdownRef.current) === null || _b === void 0 ? void 0 : _b.contains(target))) {
714
+ return;
715
+ }
716
+ setOpen(false);
717
+ setFocused(false);
718
+ };
719
+ document.addEventListener("mousedown", handleClickOutside);
720
+ return () => document.removeEventListener("mousedown", handleClickOutside);
721
+ }, []);
722
+ const toggleOption = (option) => {
723
+ const exists = value.some((v) => v.value === option.value);
724
+ onChange(exists ? value.filter((v) => v.value !== option.value) : [...value, option]);
725
+ };
726
+ const selectAll = () => onChange([...filteredOptions]);
727
+ const clearAll = () => onChange([]);
728
+ const handleListScroll = () => {
729
+ const el = listRef.current;
730
+ if (!el || !hasMore || loadingMore)
731
+ return;
732
+ if (el.scrollTop + el.clientHeight >= el.scrollHeight - 24) {
733
+ loadMore();
734
+ }
735
+ };
736
+ return (React__namespace.createElement("div", { ref: containerRef, style: { position: "relative", width: "100%" } },
737
+ React__namespace.createElement(MultiSelectBox, { focused: focused || open, onClick: () => {
738
+ var _a;
739
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
740
+ setOpen(true);
741
+ } },
742
+ value.map((v) => (React__namespace.createElement(SelectionChip, { key: v.value, label: v.label, onRemove: () => onChange(value.filter((item) => item.value !== v.value)) }))),
743
+ React__namespace.createElement("input", { ref: inputRef, type: "text", value: inputValue, placeholder: value.length === 0
744
+ ? ((_b = config.placeholder) !== null && _b !== void 0 ? _b : `Search ${config.label.toLowerCase()}...`)
745
+ : "", style: inlineSearchStyle, onChange: (e) => {
746
+ setInputValue(e.target.value);
747
+ setOpen(true);
748
+ }, onFocus: () => {
749
+ setFocused(true);
750
+ setOpen(true);
751
+ }, onBlur: () => setFocused(false) }),
752
+ React__namespace.createElement("button", { type: "button", "aria-label": "Toggle options", onClick: (e) => {
753
+ var _a;
754
+ e.stopPropagation();
755
+ setOpen((v) => !v);
756
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
757
+ }, style: {
758
+ border: "none",
759
+ background: "transparent",
760
+ color: "#9ca3af",
761
+ cursor: "pointer",
762
+ display: "flex",
763
+ padding: 2,
764
+ marginLeft: "auto",
765
+ flexShrink: 0,
766
+ transform: open ? "rotate(180deg)" : "none",
767
+ transition: "transform 0.15s",
768
+ } },
769
+ React__namespace.createElement(ChevronDownIcon, null))),
770
+ React__namespace.createElement(FloatingDropdown, { anchorRef: containerRef, dropdownRef: dropdownRef, open: open },
771
+ React__namespace.createElement("div", { style: {
772
+ border: "1px solid #cbd5e1",
773
+ borderRadius: 10,
774
+ background: "#fff",
775
+ boxShadow: "0 8px 24px rgba(15, 23, 42, 0.12)",
776
+ overflow: "hidden",
777
+ } },
778
+ filteredOptions.length > 0 && (React__namespace.createElement("div", { style: {
779
+ padding: "8px 10px 0",
780
+ borderBottom: "1px solid #f3f4f6",
781
+ } },
782
+ React__namespace.createElement(MultiSelectToolbar, { selectedCount: value.length, totalCount: filteredOptions.length, onSelectAll: selectAll, onClear: clearAll }))),
783
+ error && (React__namespace.createElement("div", { style: {
784
+ padding: "8px 12px",
785
+ fontSize: 12,
786
+ color: "#dc2626",
787
+ background: "#fef2f2",
788
+ } }, error)),
789
+ React__namespace.createElement("div", { ref: listRef, onScroll: handleListScroll, style: {
790
+ maxHeight: 220,
791
+ overflowY: "auto",
792
+ scrollbarWidth: "thin",
793
+ } },
794
+ loading && filteredOptions.length === 0 ? (React__namespace.createElement("div", { style: {
795
+ padding: 16,
796
+ textAlign: "center",
797
+ fontSize: 13,
798
+ color: "#6b7280",
799
+ } }, "Loading...")) : filteredOptions.length === 0 ? (React__namespace.createElement("div", { style: {
800
+ padding: 16,
801
+ textAlign: "center",
802
+ fontSize: 13,
803
+ color: "#9ca3af",
804
+ } }, "No options found")) : (filteredOptions.map((opt) => (React__namespace.createElement(DropdownOptionRow, { key: opt.value, label: opt.label, selected: value.some((v) => v.value === opt.value), onClick: () => toggleOption(opt) })))),
805
+ loadingMore && (React__namespace.createElement("div", { style: {
806
+ padding: 10,
807
+ textAlign: "center",
808
+ fontSize: 12,
809
+ color: "#6b7280",
810
+ } }, "Loading more...")),
811
+ hasMore && !loadingMore && filteredOptions.length > 0 && (React__namespace.createElement("button", { type: "button", onClick: loadMore, style: {
812
+ width: "100%",
813
+ padding: "8px 12px",
814
+ border: "none",
815
+ borderTop: "1px solid #f3f4f6",
816
+ background: "#fafafa",
817
+ color: "#0baae9",
818
+ fontSize: 12,
819
+ fontWeight: 600,
820
+ cursor: "pointer",
821
+ } }, "Load more")))))));
822
+ }
823
+
824
+ function RemoteSelect({ config, value, onChange, autocompleteFetchFn = defaultAutocompleteFetchFn, }) {
825
+ var _a, _b, _c, _d, _e;
826
+ const [inputValue, setInputValue] = React__namespace.useState("");
827
+ const [open, setOpen] = React__namespace.useState(false);
828
+ const [focused, setFocused] = React__namespace.useState(false);
829
+ const containerRef = React__namespace.useRef(null);
830
+ const dropdownRef = React__namespace.useRef(null);
831
+ const listRef = React__namespace.useRef(null);
832
+ const selectedOption = React__namespace.useMemo(() => {
833
+ var _a, _b;
834
+ if (!value)
835
+ return null;
836
+ return ((_b = ((_a = config.options) !== null && _a !== void 0 ? _a : []).find((o) => o.value === value)) !== null && _b !== void 0 ? _b : {
837
+ value,
838
+ label: value,
839
+ });
840
+ }, [value, config.options]);
841
+ const selectedForMerge = selectedOption ? [selectedOption] : [];
842
+ const { options, loading, loadingMore, hasMore, error, loadMore } = useRemoteListOptions({
843
+ remoteUrl: config.remoteUrl,
844
+ staticOptions: (_a = config.options) !== null && _a !== void 0 ? _a : [],
845
+ fetchFn: autocompleteFetchFn,
846
+ search: config.remoteUrl ? inputValue : "",
847
+ limit: getListLimit(config),
848
+ enabled: open,
849
+ selected: selectedForMerge,
850
+ });
851
+ const displayLabel = (_d = (_c = (_b = options.find((o) => o.value === value)) === null || _b === void 0 ? void 0 : _b.label) !== null && _c !== void 0 ? _c : selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label) !== null && _d !== void 0 ? _d : "";
852
+ const filteredOptions = config.remoteUrl
853
+ ? options
854
+ : options.filter((opt) => opt.label.toLowerCase().includes(inputValue.toLowerCase()));
855
+ React__namespace.useEffect(() => {
856
+ const handleClickOutside = (event) => {
857
+ var _a, _b;
858
+ const target = event.target;
859
+ if (((_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.contains(target)) ||
860
+ ((_b = dropdownRef.current) === null || _b === void 0 ? void 0 : _b.contains(target))) {
861
+ return;
862
+ }
863
+ setOpen(false);
864
+ setFocused(false);
865
+ };
866
+ document.addEventListener("mousedown", handleClickOutside);
867
+ return () => document.removeEventListener("mousedown", handleClickOutside);
868
+ }, []);
869
+ const handleListScroll = () => {
870
+ const el = listRef.current;
871
+ if (!el || !hasMore || loadingMore)
872
+ return;
873
+ if (el.scrollTop + el.clientHeight >= el.scrollHeight - 24) {
874
+ loadMore();
875
+ }
876
+ };
877
+ return (React__namespace.createElement("div", { ref: containerRef, style: { position: "relative", width: "100%" } },
878
+ React__namespace.createElement("button", { type: "button", onClick: () => {
879
+ setOpen((v) => !v);
880
+ setFocused(true);
881
+ }, style: {
882
+ ...inputStyle,
883
+ display: "flex",
884
+ alignItems: "center",
885
+ justifyContent: "space-between",
886
+ cursor: "pointer",
887
+ textAlign: "left",
888
+ borderColor: focused || open ? "#60a5fa" : "#cbd5e1",
889
+ boxShadow: focused || open ? "0 0 0 3px rgba(59,130,246,0.14)" : "none",
890
+ color: value ? "#111827" : "#9ca3af",
891
+ } },
892
+ React__namespace.createElement("span", { style: {
893
+ overflow: "hidden",
894
+ textOverflow: "ellipsis",
895
+ whiteSpace: "nowrap",
896
+ } }, value ? displayLabel : ((_e = config.placeholder) !== null && _e !== void 0 ? _e : `Select ${config.label}`)),
897
+ React__namespace.createElement("span", { style: {
898
+ color: "#9ca3af",
899
+ transform: open ? "rotate(180deg)" : "none",
900
+ transition: "transform 0.15s",
901
+ display: "flex",
902
+ } },
903
+ React__namespace.createElement(ChevronDownIcon, null))),
904
+ React__namespace.createElement(FloatingDropdown, { anchorRef: containerRef, dropdownRef: dropdownRef, open: open },
905
+ React__namespace.createElement("div", { style: {
906
+ border: "1px solid #cbd5e1",
907
+ borderRadius: 10,
908
+ background: "#fff",
909
+ boxShadow: "0 8px 24px rgba(15, 23, 42, 0.12)",
910
+ overflow: "hidden",
911
+ } },
912
+ React__namespace.createElement("div", { style: { padding: 8 } },
913
+ React__namespace.createElement("input", { type: "text", value: inputValue, placeholder: "Search...", style: { ...inputStyle, width: "100%" }, onChange: (e) => setInputValue(e.target.value), autoFocus: true })),
914
+ error && (React__namespace.createElement("div", { style: {
915
+ padding: "8px 12px",
916
+ fontSize: 12,
917
+ color: "#dc2626",
918
+ background: "#fef2f2",
919
+ } }, error)),
920
+ React__namespace.createElement("div", { ref: listRef, onScroll: handleListScroll, style: { maxHeight: 220, overflowY: "auto" } },
921
+ React__namespace.createElement(DropdownOptionRow, { label: "\u2014 None \u2014", selected: !value, onClick: () => {
922
+ onChange("");
923
+ setOpen(false);
924
+ } }),
925
+ loading && filteredOptions.length === 0 ? (React__namespace.createElement("div", { style: {
926
+ padding: 16,
927
+ textAlign: "center",
928
+ fontSize: 13,
929
+ color: "#6b7280",
930
+ } }, "Loading...")) : (filteredOptions.map((opt) => (React__namespace.createElement(DropdownOptionRow, { key: opt.value, label: opt.label, selected: value === opt.value, onClick: () => {
931
+ onChange(opt.value);
932
+ setOpen(false);
933
+ } })))),
934
+ loadingMore && (React__namespace.createElement("div", { style: {
935
+ padding: 10,
936
+ textAlign: "center",
937
+ fontSize: 12,
938
+ color: "#6b7280",
939
+ } }, "Loading more...")),
940
+ hasMore && !loadingMore && filteredOptions.length > 0 && (React__namespace.createElement("button", { type: "button", onClick: loadMore, style: {
941
+ width: "100%",
942
+ padding: "8px 12px",
943
+ border: "none",
944
+ borderTop: "1px solid #f3f4f6",
945
+ background: "#fafafa",
946
+ color: "#0baae9",
947
+ fontSize: 12,
948
+ fontWeight: 600,
949
+ cursor: "pointer",
950
+ } }, "Load more")))))));
951
+ }
952
+
953
+ function TagsInput({ value, onChange, placeholder, }) {
954
+ const [draft, setDraft] = React__namespace.useState("");
955
+ const [focused, setFocused] = React__namespace.useState(false);
956
+ const inputRef = React__namespace.useRef(null);
957
+ const addTag = (raw) => {
958
+ const tag = raw.trim();
959
+ if (!tag || value.includes(tag))
960
+ return;
961
+ onChange([...value, tag]);
962
+ setDraft("");
963
+ };
964
+ return (React__namespace.createElement(MultiSelectBox, { focused: focused, onClick: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); }, minHeight: 44 },
965
+ value.map((tag) => (React__namespace.createElement(SelectionChip, { key: tag, label: tag, onRemove: () => onChange(value.filter((t) => t !== tag)) }))),
966
+ React__namespace.createElement("input", { ref: inputRef, type: "text", value: draft, placeholder: value.length === 0 ? (placeholder !== null && placeholder !== void 0 ? placeholder : "Type and press Enter") : "Add more...", style: inlineSearchStyle, onChange: (e) => setDraft(e.target.value), onKeyDown: (e) => {
967
+ if (e.key === "Enter" || e.key === ",") {
968
+ e.preventDefault();
969
+ addTag(draft);
970
+ }
971
+ if (e.key === "Backspace" && !draft && value.length > 0) {
972
+ onChange(value.slice(0, -1));
973
+ }
974
+ }, onBlur: () => {
975
+ addTag(draft);
976
+ setFocused(false);
977
+ }, onFocus: () => {
978
+ setFocused(true);
979
+ } })));
980
+ }
981
+ function CheckboxGroup({ options, value, onChange, loading = false, }) {
982
+ const toggle = (optValue) => {
983
+ onChange(value.includes(optValue)
984
+ ? value.filter((v) => v !== optValue)
985
+ : [...value, optValue]);
986
+ };
987
+ return (React__namespace.createElement("div", null, loading && options.length === 0 ? (React__namespace.createElement("div", { style: { fontSize: 13, color: "#6b7280", padding: "8px 0" } }, "Loading options...")) : (React__namespace.createElement(React__namespace.Fragment, null,
988
+ React__namespace.createElement(MultiSelectToolbar, { selectedCount: value.length, totalCount: options.length, onSelectAll: () => onChange(options.map((o) => o.value)), onClear: () => onChange([]) }),
989
+ React__namespace.createElement("div", { style: {
990
+ display: "flex",
991
+ flexWrap: "wrap",
992
+ gap: 8,
993
+ } }, options.map((opt) => (React__namespace.createElement(ToggleOptionPill, { key: opt.value, label: opt.label, selected: value.includes(opt.value), onClick: () => toggle(opt.value) }))))))));
994
+ }
995
+ function ChipGroup({ options, value, onChange, multiple = false, loading = false, }) {
996
+ if (multiple) {
997
+ const selected = Array.isArray(value) ? value : [];
998
+ const toggle = (optValue) => {
999
+ onChange(selected.includes(optValue)
1000
+ ? selected.filter((v) => v !== optValue)
1001
+ : [...selected, optValue]);
1002
+ };
1003
+ return (React__namespace.createElement("div", null, loading && options.length === 0 ? (React__namespace.createElement("div", { style: { fontSize: 13, color: "#6b7280", padding: "8px 0" } }, "Loading options...")) : (React__namespace.createElement(React__namespace.Fragment, null,
1004
+ React__namespace.createElement(MultiSelectToolbar, { selectedCount: selected.length, totalCount: options.length, onSelectAll: () => onChange(options.map((o) => o.value)), onClear: () => onChange([]) }),
1005
+ React__namespace.createElement("div", { style: { display: "flex", flexWrap: "wrap", gap: 8 } }, options.map((opt) => (React__namespace.createElement(ToggleOptionPill, { key: opt.value, label: opt.label, selected: selected.includes(opt.value), onClick: () => toggle(opt.value) }))))))));
1006
+ }
1007
+ const single = typeof value === "string" ? value : "";
1008
+ return (React__namespace.createElement("div", { style: { display: "flex", flexWrap: "wrap", gap: 8 } }, options.map((opt) => {
1009
+ const isSelected = single === opt.value;
1010
+ return (React__namespace.createElement("button", { key: opt.value, type: "button", onClick: () => onChange(isSelected ? "" : opt.value), style: {
1011
+ padding: "7px 14px",
1012
+ borderRadius: 8,
1013
+ border: isSelected ? "1px solid #0baae9" : "1px solid #e5e7eb",
1014
+ background: isSelected ? "#e0f2fe" : "#fff",
1015
+ color: isSelected ? "#0369a1" : "#374151",
1016
+ fontSize: 13,
1017
+ fontWeight: isSelected ? 600 : 500,
1018
+ cursor: "pointer",
1019
+ transition: "all 0.15s",
1020
+ } }, opt.label));
1021
+ })));
1022
+ }
1023
+ function useFieldOptions(config, autocompleteFetchFn) {
1024
+ var _a;
1025
+ return useRemoteListOptions({
1026
+ remoteUrl: config.remoteUrl,
1027
+ staticOptions: (_a = config.options) !== null && _a !== void 0 ? _a : [],
1028
+ fetchFn: autocompleteFetchFn !== null && autocompleteFetchFn !== void 0 ? autocompleteFetchFn : defaultAutocompleteFetchFn,
1029
+ limit: getListLimit(config),
1030
+ enabled: !!config.remoteUrl,
1031
+ });
1032
+ }
1033
+ function FilterField({ config, value, onChange, autocompleteFetchFn, }) {
1034
+ var _a;
1035
+ const remoteOptions = useFieldOptions(config, autocompleteFetchFn);
1036
+ const resolvedOptions = config.remoteUrl
1037
+ ? remoteOptions.options
1038
+ : ((_a = config.options) !== null && _a !== void 0 ? _a : []);
1039
+ const inputHandlers = {
1040
+ onFocus: (e) => focusInput(e.currentTarget),
1041
+ onBlur: (e) => blurInput(e.currentTarget),
1042
+ };
1043
+ const renderControl = () => {
1044
+ var _a, _b, _c, _d, _e, _f, _g;
1045
+ switch (config.type) {
1046
+ case "text":
1047
+ return (React__namespace.createElement("input", { type: "text", value: typeof value === "string" ? value : "", placeholder: (_a = config.placeholder) !== null && _a !== void 0 ? _a : config.label, style: inputStyle, onChange: (e) => onChange(e.target.value), ...inputHandlers }));
1048
+ case "number":
1049
+ return (React__namespace.createElement("input", { type: "number", value: value === "" || value == null ? "" : Number(value), placeholder: config.placeholder, min: config.min, max: config.max, step: config.step, style: inputStyle, onChange: (e) => onChange(e.target.value === "" ? "" : Number(e.target.value)), ...inputHandlers }));
1050
+ case "textarea":
1051
+ return (React__namespace.createElement("textarea", { value: typeof value === "string" ? value : "", placeholder: (_b = config.placeholder) !== null && _b !== void 0 ? _b : config.label, rows: (_c = config.rows) !== null && _c !== void 0 ? _c : 3, style: { ...inputStyle, resize: "vertical", minHeight: 72 }, onChange: (e) => onChange(e.target.value), ...inputHandlers }));
1052
+ case "select":
1053
+ if (config.remoteUrl) {
1054
+ return (React__namespace.createElement(RemoteSelect, { config: config, value: typeof value === "string" ? value : "", onChange: onChange, autocompleteFetchFn: autocompleteFetchFn }));
1055
+ }
1056
+ return (React__namespace.createElement("select", { value: typeof value === "string" ? value : "", style: { ...inputStyle, cursor: "pointer" }, onChange: (e) => onChange(e.target.value), ...inputHandlers },
1057
+ React__namespace.createElement("option", { value: "" }, "\u2014 Select \u2014"),
1058
+ resolvedOptions.map((opt) => (React__namespace.createElement("option", { key: opt.value, value: opt.value }, opt.label)))));
1059
+ case "autocomplete":
1060
+ return (React__namespace.createElement(RemoteAutocomplete, { config: config, value: Array.isArray(value) ? value : [], onChange: onChange, autocompleteFetchFn: autocompleteFetchFn }));
1061
+ case "checkbox":
1062
+ return (React__namespace.createElement(CheckboxGroup, { options: resolvedOptions, value: Array.isArray(value) ? value : [], onChange: onChange, loading: config.remoteUrl ? remoteOptions.loading : false }));
1063
+ case "switch":
1064
+ return (React__namespace.createElement("button", { type: "button", role: "switch", "aria-checked": !!value, onClick: () => onChange(!value), style: {
1065
+ display: "inline-flex",
1066
+ alignItems: "center",
1067
+ gap: 10,
1068
+ border: "none",
1069
+ background: "transparent",
1070
+ cursor: "pointer",
1071
+ padding: 0,
1072
+ } },
1073
+ React__namespace.createElement("span", { style: {
1074
+ position: "relative",
1075
+ width: 40,
1076
+ height: 22,
1077
+ borderRadius: 999,
1078
+ background: value ? "#0baae9" : "#d1d5db",
1079
+ transition: "background 0.2s",
1080
+ flexShrink: 0,
1081
+ } },
1082
+ React__namespace.createElement("span", { style: {
1083
+ position: "absolute",
1084
+ top: 2,
1085
+ left: value ? 20 : 2,
1086
+ width: 18,
1087
+ height: 18,
1088
+ borderRadius: "50%",
1089
+ background: "#fff",
1090
+ transition: "left 0.2s",
1091
+ boxShadow: "0 1px 3px rgba(0,0,0,0.2)",
1092
+ } })),
1093
+ React__namespace.createElement("span", { style: { fontSize: 13, color: "#374151" } }, value ? "Yes" : "No")));
1094
+ case "radio":
1095
+ return (React__namespace.createElement("div", { style: { display: "flex", flexWrap: "wrap", gap: "10px 18px" } }, (_d = config.options) === null || _d === void 0 ? void 0 : _d.map((opt) => (React__namespace.createElement("label", { key: opt.value, style: {
1096
+ display: "inline-flex",
1097
+ alignItems: "center",
1098
+ gap: 6,
1099
+ cursor: "pointer",
1100
+ fontSize: 13,
1101
+ color: "#374151",
1102
+ } },
1103
+ React__namespace.createElement("input", { type: "radio", name: config.key, value: opt.value, checked: value === opt.value, onChange: () => onChange(opt.value), style: { accentColor: "#0baae9" } }),
1104
+ opt.label)))));
1105
+ case "date":
1106
+ return (React__namespace.createElement("input", { type: "date", value: typeof value === "string" ? value : "", style: inputStyle, onChange: (e) => onChange(e.target.value), ...inputHandlers }));
1107
+ case "time":
1108
+ return (React__namespace.createElement("input", { type: "time", value: typeof value === "string" ? value : "", style: inputStyle, onChange: (e) => onChange(e.target.value), ...inputHandlers }));
1109
+ case "datetime":
1110
+ return (React__namespace.createElement("input", { type: "datetime-local", value: typeof value === "string" ? value : "", style: inputStyle, onChange: (e) => onChange(e.target.value), ...inputHandlers }));
1111
+ case "slider": {
1112
+ const min = (_e = config.min) !== null && _e !== void 0 ? _e : 0;
1113
+ const max = (_f = config.max) !== null && _f !== void 0 ? _f : 100;
1114
+ const step = (_g = config.step) !== null && _g !== void 0 ? _g : 1;
1115
+ const num = typeof value === "number" ? value : min;
1116
+ return (React__namespace.createElement("div", null,
1117
+ React__namespace.createElement("div", { style: {
1118
+ display: "flex",
1119
+ justifyContent: "space-between",
1120
+ fontSize: 12,
1121
+ color: "#6b7280",
1122
+ marginBottom: 6,
1123
+ } },
1124
+ React__namespace.createElement("span", null, min),
1125
+ React__namespace.createElement("span", { style: { fontWeight: 600, color: "#0baae9" } }, num),
1126
+ React__namespace.createElement("span", null, max)),
1127
+ React__namespace.createElement("input", { type: "range", min: min, max: max, step: step, value: num, onChange: (e) => onChange(Number(e.target.value)), style: { width: "100%", accentColor: "#0baae9" } })));
1128
+ }
1129
+ case "tags":
1130
+ return (React__namespace.createElement(TagsInput, { value: Array.isArray(value) ? value : [], onChange: onChange, placeholder: config.placeholder }));
1131
+ case "color":
1132
+ return (React__namespace.createElement("div", { style: { display: "flex", alignItems: "center", gap: 10 } },
1133
+ React__namespace.createElement("input", { type: "color", value: typeof value === "string" && value ? value : "#000000", onChange: (e) => onChange(e.target.value), style: {
1134
+ width: 40,
1135
+ height: 36,
1136
+ padding: 2,
1137
+ border: "1px solid #e5e7eb",
1138
+ borderRadius: 8,
1139
+ cursor: "pointer",
1140
+ background: "#fff",
1141
+ } }),
1142
+ React__namespace.createElement("input", { type: "text", value: typeof value === "string" ? value : "", placeholder: "#000000", style: { ...inputStyle, flex: 1 }, onChange: (e) => onChange(e.target.value), ...inputHandlers })));
1143
+ case "chip":
1144
+ return (React__namespace.createElement(ChipGroup, { options: resolvedOptions, value: config.multiple
1145
+ ? Array.isArray(value)
1146
+ ? value
1147
+ : []
1148
+ : typeof value === "string"
1149
+ ? value
1150
+ : "", onChange: onChange, multiple: config.multiple, loading: config.remoteUrl ? remoteOptions.loading : false }));
1151
+ default:
1152
+ return null;
1153
+ }
1154
+ };
1155
+ return (React__namespace.createElement("div", { style: fieldWrapStyle },
1156
+ React__namespace.createElement("label", { style: labelStyle }, config.label),
1157
+ renderControl()));
1158
+ }
1159
+
1160
+ function hasFilterValue(val) {
1161
+ if (val == null)
1162
+ return false;
1163
+ if (val === "")
1164
+ return false;
1165
+ if (Array.isArray(val) && val.length === 0)
1166
+ return false;
1167
+ if (typeof val === "boolean")
1168
+ return val;
1169
+ return true;
1170
+ }
1171
+ function FilterPanel({ filters, filterValues, onChange, onApply, onReset, autocompleteFetchFn, }) {
1172
+ const hasAnyFilter = filters.some((f) => hasFilterValue(filterValues[f.key]));
1173
+ const activeCount = filters.filter((f) => hasFilterValue(filterValues[f.key])).length;
1174
+ return (React__namespace.createElement("div", { className: "stl-filter-panel" },
1175
+ React__namespace.createElement("div", { className: "stl-filter-panel__header" },
1176
+ React__namespace.createElement("div", { className: "stl-filter-panel__title" },
1177
+ React__namespace.createElement("span", { className: "stl-filter-panel__icon" },
1178
+ React__namespace.createElement(FilterPanelIcon, null)),
1179
+ React__namespace.createElement("span", null, "Filters"),
1180
+ activeCount > 0 && (React__namespace.createElement("span", { className: "stl-filter-panel__active-badge" },
1181
+ activeCount,
1182
+ " active"))),
1183
+ React__namespace.createElement("span", { className: "stl-filter-panel__meta" },
1184
+ filters.length,
1185
+ " field",
1186
+ filters.length !== 1 ? "s" : "")),
1187
+ React__namespace.createElement("div", { className: "stl-filter-scroll" },
1188
+ React__namespace.createElement("div", { className: "stl-filter-grid" }, filters.map((config) => {
1189
+ const isActive = hasFilterValue(filterValues[config.key]);
1190
+ return (React__namespace.createElement("div", { key: config.key, className: `stl-filter-field${config.colSpan === 2 ? " stl-filter-field--wide" : ""}${isActive ? " stl-filter-field--active" : ""}` },
1191
+ React__namespace.createElement(FilterField, { config: config, value: filterValues[config.key], onChange: (val) => onChange(config.key, val), autocompleteFetchFn: autocompleteFetchFn })));
1192
+ }))),
1193
+ React__namespace.createElement("div", { className: "stl-filter-panel__footer" },
1194
+ React__namespace.createElement("p", { className: "stl-filter-panel__footer-hint" }, hasAnyFilter
1195
+ ? `${activeCount} filter${activeCount !== 1 ? "s" : ""} ready to apply`
1196
+ : "Set filter values, then apply to update results"),
1197
+ React__namespace.createElement("div", { className: "stl-filter-panel__footer-actions" },
1198
+ React__namespace.createElement("button", { type: "button", className: "stl-filter-btn stl-filter-btn--reset", onClick: onReset },
1199
+ React__namespace.createElement(ResetIcon, null),
1200
+ "Reset all"),
1201
+ React__namespace.createElement("button", { type: "button", className: "stl-filter-btn stl-filter-btn--apply", disabled: !hasAnyFilter, onClick: onApply },
1202
+ React__namespace.createElement(ApplyIcon, null),
1203
+ "Apply filters")))));
1204
+ }
1205
+
1206
+ function ListPanel({ items, title, count, totalCount, showCount, isRight = false, onToggleItem, onMoveAll, loading = false, error = null, search, onSearchChange, searchPlaceholder = "Search...", onCopy, onPaste, copyPasteMessage, }) {
1207
+ var _a;
1208
+ const moveAllDisabled = (totalCount !== null && totalCount !== void 0 ? totalCount : count) === 0;
1209
+ const displayCount = showCount && totalCount != null && totalCount !== count
1210
+ ? `${count} / ${totalCount}`
1211
+ : showCount
1212
+ ? String(count)
1213
+ : null;
1214
+ const hasToolbar = Boolean(onSearchChange || onCopy || onPaste);
1215
+ const copyPasteFailed = (_a = copyPasteMessage === null || copyPasteMessage === void 0 ? void 0 : copyPasteMessage.toLowerCase().includes("fail")) !== null && _a !== void 0 ? _a : false;
1216
+ return (React__namespace.createElement("div", { className: `stl-list-panel${isRight ? " stl-list-panel--right" : " stl-list-panel--left"}` },
1217
+ React__namespace.createElement("div", { className: "stl-list-panel__header" },
1218
+ React__namespace.createElement("div", { className: `stl-list-panel__header-row${hasToolbar ? " stl-list-panel__header-row--with-toolbar" : ""}` },
1219
+ React__namespace.createElement("div", { className: "stl-list-panel__title" },
1220
+ React__namespace.createElement("span", { className: `stl-list-panel__badge${isRight ? " stl-list-panel__badge--right" : ""}` }, isRight ? React__namespace.createElement(IncludedPanelIcon, null) : React__namespace.createElement(ExcludedPanelIcon, null)),
1221
+ React__namespace.createElement("span", null,
1222
+ title,
1223
+ displayCount != null && (React__namespace.createElement("span", { className: "stl-list-panel__count" },
1224
+ "(",
1225
+ displayCount,
1226
+ ")")))),
1227
+ React__namespace.createElement("button", { type: "button", className: `stl-list-panel__move-all${isRight ? " stl-list-panel__move-all--remove" : ""}`, onClick: onMoveAll, disabled: moveAllDisabled },
1228
+ isRight ? "Remove all" : "Move all",
1229
+ isRight ? React__namespace.createElement(XMarkIcon, null) : React__namespace.createElement(ChevronDoubleRightIcon, null))),
1230
+ hasToolbar && (React__namespace.createElement("div", { className: "stl-list-panel__toolbar-row" },
1231
+ onSearchChange && (React__namespace.createElement("div", { className: "stl-list-panel__search-wrap" },
1232
+ React__namespace.createElement("span", { className: "stl-list-panel__search-icon" },
1233
+ React__namespace.createElement(SearchIcon, null)),
1234
+ React__namespace.createElement("input", { type: "text", placeholder: searchPlaceholder, value: search !== null && search !== void 0 ? search : "", onChange: (e) => onSearchChange(e.target.value), className: "stl-list-panel__search" }),
1235
+ search && (React__namespace.createElement("button", { type: "button", "aria-label": "Clear search", onClick: () => onSearchChange(""), className: "stl-list-panel__search-clear" }, "\u00D7")))),
1236
+ (onCopy || onPaste) && (React__namespace.createElement("div", { className: "stl-list-panel__toolbar" },
1237
+ onCopy && (React__namespace.createElement("button", { type: "button", onClick: onCopy, title: "Copy selected items as JSON", className: "stl-toolbar-btn" },
1238
+ React__namespace.createElement(CopyIcon, null),
1239
+ "Copy")),
1240
+ onPaste && (React__namespace.createElement("button", { type: "button", onClick: onPaste, title: "Paste items from clipboard JSON", className: "stl-toolbar-btn stl-toolbar-btn--paste" },
1241
+ React__namespace.createElement(PasteIcon, null),
1242
+ "Paste")))))),
1243
+ copyPasteMessage && (React__namespace.createElement("div", { className: `stl-copy-paste-message${copyPasteFailed ? " stl-copy-paste-message--error" : " stl-copy-paste-message--success"}` }, copyPasteMessage))),
1244
+ error && React__namespace.createElement("div", { className: "stl-list-panel__error" }, error),
1245
+ React__namespace.createElement("div", { className: "stl-list-scroll stl-list-panel__body" }, loading ? (React__namespace.createElement("div", { className: "stl-list-panel__empty" }, "Loading...")) : items.length === 0 ? (React__namespace.createElement("div", { className: "stl-list-panel__empty stl-list-panel__empty--muted" }, isRight
1246
+ ? search
1247
+ ? "No matching items"
1248
+ : "No items selected"
1249
+ : search
1250
+ ? "No matching items"
1251
+ : "No items available")) : (React__namespace.createElement("div", null, items.map((item) => {
1252
+ var _a;
1253
+ return (React__namespace.createElement("div", { key: item.id, className: `stl-list-panel__row${isRight ? " stl-list-panel__row--right" : ""}`, onClick: () => onToggleItem(item) },
1254
+ item.media ? (React__namespace.createElement("img", { src: item.media, alt: item.text, className: "stl-list-panel__avatar" })) : (React__namespace.createElement("div", { className: `stl-list-panel__avatar-fallback${isRight ? " stl-list-panel__avatar-fallback--right" : ""}` }, (_a = item.text) === null || _a === void 0 ? void 0 : _a.charAt(0).toUpperCase())),
1255
+ React__namespace.createElement("div", { className: "stl-list-panel__item-text" }, item.text),
1256
+ React__namespace.createElement("div", { className: `stl-list-panel__row-action${isRight ? " stl-list-panel__row-action--remove" : ""}` }, isRight ? React__namespace.createElement(XMarkIcon, null) : React__namespace.createElement(ChevronDoubleRightIcon, null))));
1257
+ }))))));
1258
+ }
1259
+
1260
+ const componentStyles = `
1261
+ .stl-root {
1262
+ width: 100%;
1263
+ padding: 20px;
1264
+ }
1265
+
1266
+ .stl-filter-toggle-wrap {
1267
+ margin-bottom: 12px;
1268
+ }
1269
+
1270
+ .stl-filter-toggle {
1271
+ padding: 8px 14px;
1272
+ border-radius: 8px;
1273
+ border: 1px solid #cbd5e1;
1274
+ background: #fff;
1275
+ color: #334155;
1276
+ cursor: pointer;
1277
+ display: inline-flex;
1278
+ align-items: center;
1279
+ gap: 8px;
1280
+ font-size: 13px;
1281
+ font-weight: 600;
1282
+ transition: all 0.15s;
1283
+ box-shadow: none;
1284
+ }
1285
+
1286
+ .stl-filter-toggle--open {
1287
+ border-color: #0baae9;
1288
+ background: linear-gradient(180deg, #e0f2fe 0%, #f0f9ff 100%);
1289
+ color: #0369a1;
1290
+ box-shadow: 0 2px 8px rgba(11, 170, 233, 0.15);
1291
+ }
1292
+
1293
+ .stl-filter-toggle-badge {
1294
+ background: #0baae9;
1295
+ color: #fff;
1296
+ border-radius: 999px;
1297
+ padding: 1px 7px;
1298
+ font-size: 11px;
1299
+ font-weight: 600;
1300
+ }
1301
+
1302
+ .stl-chips {
1303
+ display: flex;
1304
+ flex-wrap: wrap;
1305
+ gap: 8px;
1306
+ margin: 0 0 12px;
1307
+ align-items: center;
1308
+ }
1309
+
1310
+ .stl-chip {
1311
+ padding: 5px 10px;
1312
+ background: #f0f9ff;
1313
+ color: #0369a1;
1314
+ border: 1px solid #bae6fd;
1315
+ border-radius: 999px;
1316
+ font-size: 12px;
1317
+ font-weight: 500;
1318
+ display: inline-flex;
1319
+ align-items: center;
1320
+ gap: 6px;
1321
+ }
1322
+
1323
+ .stl-chip-remove {
1324
+ border: none;
1325
+ background: #bae6fd;
1326
+ color: #0369a1;
1327
+ border-radius: 50%;
1328
+ width: 18px;
1329
+ height: 18px;
1330
+ cursor: pointer;
1331
+ font-size: 12px;
1332
+ line-height: 1;
1333
+ padding: 0;
1334
+ display: flex;
1335
+ align-items: center;
1336
+ justify-content: center;
1337
+ }
1338
+
1339
+ .stl-clear-all {
1340
+ border: none;
1341
+ background: transparent;
1342
+ color: #dc2626;
1343
+ cursor: pointer;
1344
+ font-size: 12px;
1345
+ font-weight: 500;
1346
+ padding: 4px 8px;
1347
+ }
1348
+
1349
+ .stl-panels {
1350
+ display: flex;
1351
+ gap: 12px;
1352
+ margin-top: 16px;
1353
+ align-items: stretch;
1354
+ min-height: 320px;
1355
+ }
1356
+
1357
+ .stl-filter-panel {
1358
+ margin-top: 12px;
1359
+ margin-bottom: 12px;
1360
+ border: 1px solid #dbeafe;
1361
+ border-radius: 12px;
1362
+ background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
1363
+ box-shadow:
1364
+ 0 1px 2px rgba(15, 23, 42, 0.04),
1365
+ 0 8px 24px rgba(11, 170, 233, 0.08);
1366
+ }
1367
+
1368
+ .stl-filter-panel__header {
1369
+ padding: 14px 18px;
1370
+ border-bottom: 1px solid #e0f2fe;
1371
+ background: linear-gradient(90deg, #f0f9ff 0%, #ffffff 100%);
1372
+ display: flex;
1373
+ align-items: center;
1374
+ justify-content: space-between;
1375
+ gap: 12px;
1376
+ border-radius: 12px 12px 0 0;
1377
+ }
1378
+
1379
+ .stl-filter-panel__title {
1380
+ display: flex;
1381
+ align-items: center;
1382
+ gap: 10px;
1383
+ font-weight: 650;
1384
+ font-size: 14px;
1385
+ color: #0f172a;
1386
+ letter-spacing: -0.01em;
1387
+ }
1388
+
1389
+ .stl-filter-panel__icon {
1390
+ display: inline-flex;
1391
+ align-items: center;
1392
+ justify-content: center;
1393
+ width: 28px;
1394
+ height: 28px;
1395
+ border-radius: 8px;
1396
+ background: linear-gradient(135deg, #0baae9 0%, #0284c7 100%);
1397
+ color: #fff;
1398
+ box-shadow: 0 2px 6px rgba(11, 170, 233, 0.35);
1399
+ }
1400
+
1401
+ .stl-filter-panel__active-badge {
1402
+ font-size: 11px;
1403
+ font-weight: 600;
1404
+ color: #0369a1;
1405
+ background: #e0f2fe;
1406
+ border: 1px solid #bae6fd;
1407
+ border-radius: 999px;
1408
+ padding: 2px 8px;
1409
+ }
1410
+
1411
+ .stl-filter-panel__meta {
1412
+ font-size: 12px;
1413
+ color: #64748b;
1414
+ white-space: nowrap;
1415
+ }
1416
+
1417
+ .stl-filter-scroll {
1418
+ max-height: 420px;
1419
+ overflow-y: auto;
1420
+ overflow-x: hidden;
1421
+ padding: 18px;
1422
+ scrollbar-width: thin;
1423
+ scrollbar-color: #93c5fd transparent;
1424
+ }
1425
+
1426
+ .stl-filter-scroll::-webkit-scrollbar { width: 6px; }
1427
+ .stl-filter-scroll::-webkit-scrollbar-track { background: transparent; }
1428
+ .stl-filter-scroll::-webkit-scrollbar-thumb {
1429
+ background: #93c5fd;
1430
+ border-radius: 999px;
1431
+ }
1432
+
1433
+ .stl-filter-grid {
1434
+ display: grid;
1435
+ grid-template-columns: repeat(2, minmax(0, 1fr));
1436
+ gap: 14px;
1437
+ }
1438
+
1439
+ .stl-filter-field {
1440
+ min-width: 0;
1441
+ padding: 14px;
1442
+ border-radius: 10px;
1443
+ border: 1px solid #e2e8f0;
1444
+ background: #fff;
1445
+ transition: border-color 0.15s, box-shadow 0.15s;
1446
+ }
1447
+
1448
+ .stl-filter-field:hover {
1449
+ border-color: #bae6fd;
1450
+ box-shadow: 0 2px 8px rgba(11, 170, 233, 0.06);
1451
+ }
1452
+
1453
+ .stl-filter-field--active {
1454
+ border-color: #7dd3fc;
1455
+ background: linear-gradient(180deg, #ffffff 0%, #f0f9ff 100%);
1456
+ box-shadow: inset 0 0 0 1px rgba(11, 170, 233, 0.08);
1457
+ }
1458
+
1459
+ .stl-filter-field--wide {
1460
+ grid-column: 1 / -1;
1461
+ }
1462
+
1463
+ .stl-filter-panel__footer {
1464
+ padding: 14px 18px;
1465
+ border-top: 1px solid #e0f2fe;
1466
+ background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
1467
+ display: flex;
1468
+ align-items: center;
1469
+ justify-content: space-between;
1470
+ gap: 16px;
1471
+ flex-wrap: wrap;
1472
+ border-radius: 0 0 12px 12px;
1473
+ }
1474
+
1475
+ .stl-filter-panel__footer-hint {
1476
+ margin: 0;
1477
+ font-size: 12px;
1478
+ color: #64748b;
1479
+ line-height: 1.4;
1480
+ }
1481
+
1482
+ .stl-filter-panel__footer-actions {
1483
+ display: flex;
1484
+ align-items: center;
1485
+ gap: 10px;
1486
+ margin-left: auto;
1487
+ }
1488
+
1489
+ .stl-filter-btn {
1490
+ display: inline-flex;
1491
+ align-items: center;
1492
+ justify-content: center;
1493
+ gap: 7px;
1494
+ padding: 9px 16px;
1495
+ border-radius: 9px;
1496
+ font-size: 13px;
1497
+ font-weight: 600;
1498
+ cursor: pointer;
1499
+ transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.1s, color 0.15s;
1500
+ }
1501
+
1502
+ .stl-filter-btn:active:not(:disabled) {
1503
+ transform: translateY(1px);
1504
+ }
1505
+
1506
+ .stl-filter-btn--reset {
1507
+ border: 1px solid #cbd5e1;
1508
+ background: #fff;
1509
+ color: #64748b;
1510
+ }
1511
+
1512
+ .stl-filter-btn--reset:hover {
1513
+ border-color: #94a3b8;
1514
+ color: #475569;
1515
+ background: #fff;
1516
+ box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
1517
+ }
1518
+
1519
+ .stl-filter-btn--apply {
1520
+ border: none;
1521
+ background: linear-gradient(135deg, #0baae9 0%, #0284c7 100%);
1522
+ color: #fff;
1523
+ min-width: 132px;
1524
+ box-shadow:
1525
+ 0 1px 2px rgba(2, 132, 199, 0.2),
1526
+ 0 4px 14px rgba(11, 170, 233, 0.35);
1527
+ }
1528
+
1529
+ .stl-filter-btn--apply:hover:not(:disabled) {
1530
+ background: linear-gradient(135deg, #22bff5 0%, #0baae9 100%);
1531
+ box-shadow:
1532
+ 0 2px 4px rgba(2, 132, 199, 0.25),
1533
+ 0 6px 18px rgba(11, 170, 233, 0.4);
1534
+ }
1535
+
1536
+ .stl-filter-btn--apply:disabled {
1537
+ background: #e2e8f0;
1538
+ color: #94a3b8;
1539
+ box-shadow: none;
1540
+ cursor: not-allowed;
1541
+ }
1542
+
1543
+ .stl-list-panel {
1544
+ width: 100%;
1545
+ max-height: 500px;
1546
+ display: flex;
1547
+ flex-direction: column;
1548
+ border-radius: 12px;
1549
+ overflow: hidden;
1550
+ background: #fff;
1551
+ }
1552
+
1553
+ .stl-list-panel--left {
1554
+ border: 1px solid #dbeafe;
1555
+ box-shadow:
1556
+ 0 1px 2px rgba(15, 23, 42, 0.04),
1557
+ 0 6px 20px rgba(11, 170, 233, 0.07);
1558
+ }
1559
+
1560
+ .stl-list-panel--right {
1561
+ border: 1px solid #bbf7d0;
1562
+ box-shadow:
1563
+ 0 1px 2px rgba(15, 23, 42, 0.04),
1564
+ 0 6px 20px rgba(16, 185, 129, 0.08);
1565
+ }
1566
+
1567
+ .stl-list-panel__header {
1568
+ flex-shrink: 0;
1569
+ padding: 14px 16px;
1570
+ border-bottom: 1px solid #e0f2fe;
1571
+ }
1572
+
1573
+ .stl-list-panel--left .stl-list-panel__header {
1574
+ background: linear-gradient(90deg, #f0f9ff 0%, #ffffff 100%);
1575
+ }
1576
+
1577
+ .stl-list-panel--right .stl-list-panel__header {
1578
+ border-bottom-color: #d1fae5;
1579
+ background: linear-gradient(90deg, #ecfdf5 0%, #ffffff 100%);
1580
+ }
1581
+
1582
+ .stl-list-panel__header-row {
1583
+ display: flex;
1584
+ justify-content: space-between;
1585
+ align-items: center;
1586
+ gap: 8px;
1587
+ }
1588
+
1589
+ .stl-list-panel__header-row--with-toolbar {
1590
+ margin-bottom: 10px;
1591
+ }
1592
+
1593
+ .stl-list-panel__title {
1594
+ display: flex;
1595
+ align-items: center;
1596
+ gap: 10px;
1597
+ font-weight: 650;
1598
+ font-size: 14px;
1599
+ color: #0f172a;
1600
+ letter-spacing: -0.01em;
1601
+ }
1602
+
1603
+ .stl-list-panel__badge {
1604
+ display: inline-flex;
1605
+ align-items: center;
1606
+ justify-content: center;
1607
+ width: 26px;
1608
+ height: 26px;
1609
+ border-radius: 7px;
1610
+ background: linear-gradient(135deg, #0baae9 0%, #0284c7 100%);
1611
+ color: #fff;
1612
+ box-shadow: 0 2px 5px rgba(11, 170, 233, 0.3);
1613
+ flex-shrink: 0;
1614
+ }
1615
+
1616
+ .stl-list-panel__badge--right {
1617
+ background: linear-gradient(135deg, #10b981 0%, #059669 100%);
1618
+ box-shadow: 0 2px 5px rgba(16, 185, 129, 0.3);
1619
+ }
1620
+
1621
+ .stl-list-panel__count {
1622
+ font-weight: 500;
1623
+ color: #64748b;
1624
+ margin-left: 4px;
1625
+ }
1626
+
1627
+ .stl-list-panel__move-all {
1628
+ border: none;
1629
+ background: transparent;
1630
+ cursor: pointer;
1631
+ color: #0284c7;
1632
+ display: flex;
1633
+ align-items: center;
1634
+ gap: 5px;
1635
+ font-size: 12px;
1636
+ font-weight: 600;
1637
+ padding: 4px 8px;
1638
+ border-radius: 6px;
1639
+ white-space: nowrap;
1640
+ transition: background 0.15s, color 0.15s;
1641
+ }
1642
+
1643
+ .stl-list-panel__move-all:hover:not(:disabled) {
1644
+ background: #e0f2fe;
1645
+ }
1646
+
1647
+ .stl-list-panel__move-all--remove {
1648
+ color: #dc2626;
1649
+ }
1650
+
1651
+ .stl-list-panel__move-all--remove:hover:not(:disabled) {
1652
+ background: #fef2f2;
1653
+ }
1654
+
1655
+ .stl-list-panel__move-all:disabled {
1656
+ cursor: not-allowed;
1657
+ opacity: 0.45;
1658
+ }
1659
+
1660
+ .stl-list-panel__toolbar-row {
1661
+ display: flex;
1662
+ align-items: center;
1663
+ gap: 8px;
1664
+ flex-wrap: wrap;
1665
+ }
1666
+
1667
+ .stl-list-panel__search-wrap {
1668
+ position: relative;
1669
+ flex: 1 1 140px;
1670
+ min-width: 120px;
1671
+ }
1672
+
1673
+ .stl-list-panel__search-icon {
1674
+ position: absolute;
1675
+ left: 10px;
1676
+ top: 50%;
1677
+ transform: translateY(-50%);
1678
+ color: #9ca3af;
1679
+ display: flex;
1680
+ pointer-events: none;
1681
+ }
1682
+
1683
+ .stl-list-panel__search {
1684
+ width: 100%;
1685
+ box-sizing: border-box;
1686
+ padding: 8px 30px 8px 32px;
1687
+ border-radius: 8px;
1688
+ border: 1px solid #cbd5e1;
1689
+ background: #fff;
1690
+ font-size: 13px;
1691
+ color: #0f172a;
1692
+ outline: none;
1693
+ transition: border-color 0.15s, box-shadow 0.15s;
1694
+ }
1695
+
1696
+ .stl-list-panel__search:focus {
1697
+ border-color: #60a5fa;
1698
+ box-shadow: 0 0 0 3px rgba(59,130,246,0.14);
1699
+ }
1700
+
1701
+ .stl-list-panel__search-clear {
1702
+ position: absolute;
1703
+ right: 6px;
1704
+ top: 50%;
1705
+ transform: translateY(-50%);
1706
+ border: none;
1707
+ background: #e0f2fe;
1708
+ color: #0369a1;
1709
+ border-radius: 50%;
1710
+ width: 18px;
1711
+ height: 18px;
1712
+ font-size: 12px;
1713
+ line-height: 1;
1714
+ cursor: pointer;
1715
+ display: flex;
1716
+ align-items: center;
1717
+ justify-content: center;
1718
+ padding: 0;
1719
+ }
1720
+
1721
+ .stl-list-panel__toolbar {
1722
+ display: flex;
1723
+ gap: 4px;
1724
+ flex-shrink: 0;
1725
+ padding: 2px;
1726
+ border-radius: 8px;
1727
+ background: #fff;
1728
+ border: 1px solid #cbd5e1;
1729
+ }
1730
+
1731
+ .stl-toolbar-btn {
1732
+ display: inline-flex;
1733
+ align-items: center;
1734
+ gap: 5px;
1735
+ padding: 5px 10px;
1736
+ border-radius: 6px;
1737
+ border: 1px solid #cbd5e1;
1738
+ background: #fff;
1739
+ color: #334155;
1740
+ font-size: 12px;
1741
+ font-weight: 500;
1742
+ cursor: pointer;
1743
+ transition: background 0.15s, border-color 0.15s, color 0.15s;
1744
+ line-height: 1.2;
1745
+ }
1746
+
1747
+ .stl-toolbar-btn:hover {
1748
+ background: #f0f9ff;
1749
+ border-color: #bae6fd;
1750
+ color: #0369a1;
1751
+ }
1752
+
1753
+ .stl-toolbar-btn--paste {
1754
+ border: none;
1755
+ }
1756
+
1757
+ .stl-toolbar-btn--paste:hover {
1758
+ background: #f0fdf4;
1759
+ color: #15803d;
1760
+ }
1761
+
1762
+ .stl-copy-paste-message {
1763
+ margin-top: 8px;
1764
+ font-size: 12px;
1765
+ padding: 4px 8px;
1766
+ border-radius: 6px;
1767
+ }
1768
+
1769
+ .stl-copy-paste-message--success {
1770
+ color: #059669;
1771
+ background: #ecfdf5;
1772
+ }
1773
+
1774
+ .stl-copy-paste-message--error {
1775
+ color: #dc2626;
1776
+ background: #fef2f2;
1777
+ }
1778
+
1779
+ .stl-list-panel__error {
1780
+ flex-shrink: 0;
1781
+ padding: 10px 14px;
1782
+ font-size: 13px;
1783
+ color: #dc2626;
1784
+ background: #fef2f2;
1785
+ border-bottom: 1px solid #fecaca;
1786
+ }
1787
+
1788
+ .stl-list-panel__body {
1789
+ flex: 1;
1790
+ min-height: 0;
1791
+ overflow-y: auto;
1792
+ overflow-x: hidden;
1793
+ background: #fff;
1794
+ scrollbar-width: thin;
1795
+ scrollbar-color: #93c5fd transparent;
1796
+ }
1797
+
1798
+ .stl-list-panel--right .stl-list-panel__body {
1799
+ scrollbar-color: #6ee7b7 transparent;
1800
+ }
1801
+
1802
+ .stl-list-panel__empty {
1803
+ padding: 40px;
1804
+ text-align: center;
1805
+ font-size: 14px;
1806
+ color: #475569;
1807
+ }
1808
+
1809
+ .stl-list-panel__empty--muted {
1810
+ color: #64748b;
1811
+ }
1812
+
1813
+ .stl-list-panel__row {
1814
+ display: flex;
1815
+ align-items: center;
1816
+ gap: 12px;
1817
+ padding: 10px 16px;
1818
+ border-bottom: 1px solid #f1f5f9;
1819
+ cursor: pointer;
1820
+ background: #fff;
1821
+ transition: background 0.15s, box-shadow 0.15s;
1822
+ }
1823
+
1824
+ .stl-list-panel__row:hover {
1825
+ background: #f0f9ff;
1826
+ }
1827
+
1828
+ .stl-list-panel__row--right:hover {
1829
+ background: #ecfdf5;
1830
+ }
1831
+
1832
+ .stl-list-panel__avatar {
1833
+ width: 34px;
1834
+ height: 34px;
1835
+ border-radius: 50%;
1836
+ object-fit: cover;
1837
+ flex-shrink: 0;
1838
+ border: 2px solid #e0f2fe;
1839
+ }
1840
+
1841
+ .stl-list-panel__row--right .stl-list-panel__avatar {
1842
+ border-color: #d1fae5;
1843
+ }
1844
+
1845
+ .stl-list-panel__avatar-fallback {
1846
+ width: 34px;
1847
+ height: 34px;
1848
+ border-radius: 50%;
1849
+ background: linear-gradient(135deg, #e0f2fe 0%, #bae6fd 100%);
1850
+ display: flex;
1851
+ align-items: center;
1852
+ justify-content: center;
1853
+ font-weight: 700;
1854
+ font-size: 12px;
1855
+ color: #0369a1;
1856
+ flex-shrink: 0;
1857
+ border: 2px solid #fff;
1858
+ box-shadow: 0 0 0 1px #bae6fd;
1859
+ }
1860
+
1861
+ .stl-list-panel__avatar-fallback--right {
1862
+ background: linear-gradient(135deg, #d1fae5 0%, #6ee7b7 100%);
1863
+ color: #047857;
1864
+ box-shadow: 0 0 0 1px #6ee7b7;
1865
+ }
1866
+
1867
+ .stl-list-panel__item-text {
1868
+ flex: 1;
1869
+ font-size: 14px;
1870
+ color: #0f172a;
1871
+ overflow: hidden;
1872
+ text-overflow: ellipsis;
1873
+ white-space: nowrap;
1874
+ }
1875
+
1876
+ .stl-list-panel__row-action {
1877
+ color: #0baae9;
1878
+ display: flex;
1879
+ flex-shrink: 0;
1880
+ opacity: 0.7;
1881
+ transition: opacity 0.15s;
1882
+ }
1883
+
1884
+ .stl-list-panel__row:hover .stl-list-panel__row-action {
1885
+ opacity: 1;
1886
+ }
1887
+
1888
+ .stl-list-panel__row-action--remove {
1889
+ color: #ef4444;
1890
+ }
1891
+
1892
+ .stl-list-scroll::-webkit-scrollbar {
1893
+ width: 6px;
1894
+ }
1895
+ .stl-list-scroll::-webkit-scrollbar-track {
1896
+ background: transparent;
1897
+ }
1898
+ .stl-list-scroll::-webkit-scrollbar-thumb {
1899
+ background: #93c5fd;
1900
+ border-radius: 999px;
1901
+ }
1902
+ .stl-list-panel--right .stl-list-scroll::-webkit-scrollbar-thumb {
1903
+ background: #6ee7b7;
1904
+ }
1905
+ .stl-list-scroll::-webkit-scrollbar-thumb:hover {
1906
+ background: #60a5fa;
1907
+ }
1908
+ .stl-list-panel--right .stl-list-scroll::-webkit-scrollbar-thumb:hover {
1909
+ background: #34d399;
1910
+ }
1911
+
1912
+ @media (max-width: 640px) {
1913
+ .stl-filter-grid {
1914
+ grid-template-columns: 1fr;
1915
+ }
1916
+
1917
+ .stl-filter-panel__footer-actions {
1918
+ width: 100%;
1919
+ }
1920
+
1921
+ .stl-filter-btn {
1922
+ flex: 1;
1923
+ }
1924
+ }
1925
+ `;
1926
+
1927
+ let injected = false;
1928
+ function injectStyles() {
1929
+ if (injected || typeof document === "undefined")
1930
+ return;
1931
+ injected = true;
1932
+ const style = document.createElement("style");
1933
+ style.setAttribute("data-stl", "transfer-list");
1934
+ style.textContent = componentStyles;
1935
+ document.head.appendChild(style);
1936
+ }
1937
+
1938
+ function TransferList({ label, remoteUrl, fetchFn = defaultFetchFn, value, onChange, filters = [], autocompleteFetchFn = defaultAutocompleteFetchFn, className, isFilter = true, }) {
1939
+ const defaultFilterValues = React__namespace.useMemo(() => getDefaultFilterValues(filters), [filters]);
1940
+ const [leftSearch, setLeftSearch] = React__namespace.useState("");
1941
+ const [rightSearch, setRightSearch] = React__namespace.useState("");
1942
+ const [showFilters, setShowFilters] = React__namespace.useState(false);
1943
+ const [filterValues, setFilterValues] = React__namespace.useState(defaultFilterValues);
1944
+ const [appliedFilter, setAppliedFilter] = React__namespace.useState(() => isFilter ? buildFilterArray(defaultFilterValues, filters) : []);
1945
+ const [dataRight, setDataRight] = React__namespace.useState(() => dedupeById(value !== null && value !== void 0 ? value : []));
1946
+ const [copyPasteMessage, setCopyPasteMessage] = React__namespace.useState(null);
1947
+ const initialized = React__namespace.useRef(false);
1948
+ const didMount = React__namespace.useRef(false);
1949
+ React__namespace.useEffect(() => {
1950
+ injectStyles();
1951
+ }, []);
1952
+ React__namespace.useEffect(() => {
1953
+ if (!initialized.current && Array.isArray(value) && value.length > 0) {
1954
+ initialized.current = true;
1955
+ setDataRight(dedupeById(value));
1956
+ }
1957
+ }, [value]);
1958
+ React__namespace.useEffect(() => {
1959
+ if (didMount.current) {
1960
+ onChange === null || onChange === void 0 ? void 0 : onChange(dataRight);
1961
+ }
1962
+ else {
1963
+ didMount.current = true;
1964
+ }
1965
+ }, [dataRight, onChange]);
1966
+ const prevLeftSearch = React__namespace.useRef(leftSearch);
1967
+ React__namespace.useEffect(() => {
1968
+ if (!isFilter)
1969
+ return;
1970
+ if (prevLeftSearch.current && !leftSearch) {
1971
+ const defaults = getDefaultFilterValues(filters);
1972
+ setFilterValues(defaults);
1973
+ setAppliedFilter(buildFilterArray(defaults, filters));
1974
+ }
1975
+ prevLeftSearch.current = leftSearch;
1976
+ }, [leftSearch, isFilter, filters]);
1977
+ const { dataLeft, setDataLeft, loading, error } = useTransferData({
1978
+ remoteUrl,
1979
+ fetchFn,
1980
+ search: leftSearch,
1981
+ filter: appliedFilter,
1982
+ dataRight,
1983
+ });
1984
+ const filteredRight = React__namespace.useMemo(() => filterBySearch(dataRight, rightSearch), [dataRight, rightSearch]);
1985
+ const updateRight = React__namespace.useCallback((updater) => {
1986
+ setDataRight((prev) => dedupeById(updater(prev)));
1987
+ }, []);
1988
+ const handleToggle = (item) => {
1989
+ const isInRight = dataRight.some((r) => r.id === item.id);
1990
+ if (isInRight) {
1991
+ updateRight((prev) => prev.filter((e) => e.id !== item.id));
1992
+ setDataLeft((prev) => dedupeById([...prev, item]));
1993
+ }
1994
+ else {
1995
+ updateRight((prev) => [...prev, item]);
1996
+ setDataLeft((prev) => prev.filter((e) => e.id !== item.id));
1997
+ }
1998
+ };
1999
+ const handleAllRight = () => {
2000
+ updateRight((prev) => [...prev, ...dataLeft]);
2001
+ setDataLeft([]);
2002
+ };
2003
+ const handleAllLeft = () => {
2004
+ setDataLeft((prev) => dedupeById([...prev, ...dataRight]));
2005
+ updateRight(() => []);
2006
+ };
2007
+ const handleFilterChange = (key, val) => {
2008
+ setFilterValues((prev) => ({ ...prev, [key]: val }));
2009
+ };
2010
+ const handleApplyFilters = () => {
2011
+ setAppliedFilter(buildFilterArray(filterValues, filters));
2012
+ setShowFilters(false);
2013
+ };
2014
+ const handleDeleteFilterChip = (key) => {
2015
+ const next = { ...filterValues };
2016
+ delete next[key];
2017
+ setFilterValues(next);
2018
+ setAppliedFilter(buildFilterArray(next, filters));
2019
+ };
2020
+ const handleClearAll = () => {
2021
+ setFilterValues({});
2022
+ setAppliedFilter([]);
2023
+ };
2024
+ const handleResetFilters = () => {
2025
+ const defaults = getDefaultFilterValues(filters);
2026
+ setFilterValues(defaults);
2027
+ };
2028
+ const showCopyPasteMessage = (message) => {
2029
+ setCopyPasteMessage(message);
2030
+ setTimeout(() => setCopyPasteMessage(null), 2500);
2031
+ };
2032
+ const applyPastedItems = (items) => {
2033
+ const parsed = dedupeById(items);
2034
+ if (parsed.length === 0)
2035
+ return null;
2036
+ const pastedIds = new Set(parsed.map((item) => item.id));
2037
+ updateRight((prev) => [...prev, ...parsed]);
2038
+ setDataLeft((prev) => prev.filter((item) => !pastedIds.has(item.id)));
2039
+ return parsed.length;
2040
+ };
2041
+ const handleCopyRight = async () => {
2042
+ const text = JSON.stringify(dataRight, null, 2);
2043
+ setTransferListClipboard(dataRight);
2044
+ try {
2045
+ await copyToClipboard(text);
2046
+ showCopyPasteMessage(`Copied ${dataRight.length} item(s)`);
2047
+ }
2048
+ catch (_a) {
2049
+ showCopyPasteMessage(`Copied ${dataRight.length} item(s)`);
2050
+ }
2051
+ };
2052
+ const handlePasteRight = async () => {
2053
+ const fromMemory = getTransferListClipboard();
2054
+ if (fromMemory === null || fromMemory === void 0 ? void 0 : fromMemory.length) {
2055
+ const count = applyPastedItems(fromMemory);
2056
+ if (count != null) {
2057
+ showCopyPasteMessage(`Pasted ${count} item(s)`);
2058
+ return;
2059
+ }
2060
+ }
2061
+ try {
2062
+ const text = await navigator.clipboard.readText();
2063
+ const parsed = parseTransferItems(JSON.parse(text));
2064
+ if (parsed.length === 0) {
2065
+ showCopyPasteMessage("No valid items in clipboard");
2066
+ return;
2067
+ }
2068
+ const count = applyPastedItems(parsed);
2069
+ if (count != null) {
2070
+ showCopyPasteMessage(`Pasted ${count} item(s)`);
2071
+ }
2072
+ }
2073
+ catch (_a) {
2074
+ showCopyPasteMessage("Failed to paste — copy from another list first, or ensure clipboard has valid JSON");
2075
+ }
2076
+ };
2077
+ const activeChips = appliedFilter.filter((f) => {
2078
+ const key = Object.keys(f)[0];
2079
+ const val = f[key];
2080
+ if (key === "selectedIds")
2081
+ return false;
2082
+ if (Array.isArray(val) && val.length === 0)
2083
+ return false;
2084
+ return val != null && val !== "";
2085
+ });
2086
+ return (React__namespace.createElement("div", { className: className ? `${className} stl-root` : "stl-root" },
2087
+ isFilter && filters.length > 0 && (React__namespace.createElement("div", { className: "stl-filter-toggle-wrap" },
2088
+ React__namespace.createElement("button", { type: "button", onClick: () => setShowFilters((v) => !v), className: `stl-filter-toggle${showFilters ? " stl-filter-toggle--open" : ""}` },
2089
+ React__namespace.createElement(FilterToggleIcon, { open: showFilters }),
2090
+ showFilters ? "Hide Filters" : "Show Filters",
2091
+ activeChips.length > 0 && (React__namespace.createElement("span", { className: "stl-filter-toggle-badge" }, activeChips.length))))),
2092
+ isFilter && showFilters && (React__namespace.createElement(FilterPanel, { filters: filters, filterValues: filterValues, onChange: handleFilterChange, onApply: handleApplyFilters, onReset: handleResetFilters, autocompleteFetchFn: autocompleteFetchFn })),
2093
+ isFilter && activeChips.length > 0 && (React__namespace.createElement("div", { className: "stl-chips" },
2094
+ activeChips.map((f) => {
2095
+ const key = Object.keys(f)[0];
2096
+ return (React__namespace.createElement("div", { key: key, className: "stl-chip" },
2097
+ getChipLabel(f, filters, filterValues),
2098
+ React__namespace.createElement("button", { type: "button", onClick: () => handleDeleteFilterChip(key), className: "stl-chip-remove" }, "\u00D7")));
2099
+ }),
2100
+ React__namespace.createElement("button", { type: "button", onClick: handleClearAll, className: "stl-clear-all" }, "Clear all"))),
2101
+ React__namespace.createElement("div", { className: "stl-panels" },
2102
+ React__namespace.createElement(ListPanel, { items: dataLeft, title: `${label} excluded`, count: dataLeft.length, isRight: false, onToggleItem: handleToggle, onMoveAll: handleAllRight, loading: loading, error: error, search: leftSearch, onSearchChange: setLeftSearch, searchPlaceholder: "Search available..." }),
2103
+ React__namespace.createElement(ListPanel, { items: filteredRight, title: `${label} included`, count: filteredRight.length, totalCount: dataRight.length, showCount: true, isRight: true, onToggleItem: handleToggle, onMoveAll: handleAllLeft, search: rightSearch, onSearchChange: setRightSearch, searchPlaceholder: "Search selected...", onCopy: handleCopyRight, onPaste: handlePasteRight, copyPasteMessage: copyPasteMessage }))));
2104
+ }
2105
+
2106
+ exports.TransferList = TransferList;
2107
+ exports.buildFilterArray = buildFilterArray;
2108
+ exports.copyToClipboard = copyToClipboard;
2109
+ exports.dedupeById = dedupeById;
2110
+ exports.default = TransferList;
2111
+ exports.defaultAutocompleteFetchFn = defaultAutocompleteFetchFn;
2112
+ exports.defaultFetchFn = defaultFetchFn;
2113
+ exports.getTransferListClipboard = getTransferListClipboard;
2114
+ exports.mapToFilterOptions = mapToFilterOptions;
2115
+ exports.parseTransferItems = parseTransferItems;
2116
+ exports.setTransferListClipboard = setTransferListClipboard;