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