react-core-ts 2.0.12 → 2.0.13

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.
@@ -0,0 +1,653 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
57
+ };
58
+ var __importDefault = (this && this.__importDefault) || function (mod) {
59
+ return (mod && mod.__esModule) ? mod : { "default": mod };
60
+ };
61
+ Object.defineProperty(exports, "__esModule", { value: true });
62
+ var jsx_runtime_1 = require("react/jsx-runtime");
63
+ var react_1 = require("react");
64
+ var customIcons_1 = __importDefault(require("./components/customIcons"));
65
+ var Spinner_1 = __importDefault(require("./components/loader/Spinner"));
66
+ var portal_1 = __importDefault(require("./components/portal"));
67
+ var debounce_1 = require("./utilities/debounce");
68
+ var getPosition_1 = require("./utilities/getPosition");
69
+ var icons_1 = require("./utilities/icons");
70
+ var ReactAutoCompleteTableView = function (_a) {
71
+ var _b;
72
+ var label = _a.label, onChange = _a.onChange, getData = _a.getData, data = _a.data, errors = _a.errors, _c = _a.required, required = _c === void 0 ? false : _c, autoFocus = _a.autoFocus, name = _a.name, fullWidth = _a.fullWidth, placeholder = _a.placeholder, id = _a.id, propsClassName = _a.className, _d = _a.type, type = _d === void 0 ? "custom_select" : _d, readOnly = _a.readOnly, _e = _a.disabled, disabled = _e === void 0 ? false : _e, value = _a.value, _f = _a.autoFilter, autoFilter = _f === void 0 ? false : _f, _g = _a.insideOpen, insideOpen = _g === void 0 ? false : _g, _h = _a.isClose, isClose = _h === void 0 ? true : _h, _j = _a.noLocalFilter, noLocalFilter = _j === void 0 ? false : _j, _k = _a.isStaticList, isStaticList = _k === void 0 ? false : _k, _l = _a.isCustomPlaceholder, isCustomPlaceholder = _l === void 0 ? false : _l, checkParams = _a.checkParams, width = _a.width, hasParentError = _a.hasParentError, fromPrefix = _a.fromPrefix, labelTitle = _a.labelTitle, _m = _a.isModern, isModern = _m === void 0 ? true : _m, _o = _a.size, size = _o === void 0 ? "md" : _o, _p = _a.dropdownMinWidth, dropdownMinWidth = _p === void 0 ? 200 : _p, _q = _a.tableView, tableView = _q === void 0 ? false : _q, _r = _a.additionalColumns, additionalColumns = _r === void 0 ? [] : _r;
73
+ var _s = (0, react_1.useState)((_b = value === null || value === void 0 ? void 0 : value.name) !== null && _b !== void 0 ? _b : ""), inputValue = _s[0], setInputValue = _s[1];
74
+ var _t = (0, react_1.useState)(false), isHovered = _t[0], setIsHovered = _t[1];
75
+ var _u = (0, react_1.useState)(false), isLoading = _u[0], setIsLoading = _u[1];
76
+ var _v = (0, react_1.useState)(false), dropOpen = _v[0], setDropOpen = _v[1];
77
+ var _w = (0, react_1.useState)(disabled), isDisabled = _w[0], setIsDisabled = _w[1];
78
+ var _x = (0, react_1.useState)(false), showClose = _x[0], setShowClose = _x[1];
79
+ var _y = (0, react_1.useState)(false), showToolTip = _y[0], setShowTooltip = _y[1];
80
+ var _z = (0, react_1.useState)(false), tooltipIsHovered = _z[0], setTooltipIsHovered = _z[1];
81
+ var _0 = (0, react_1.useState)([]), suggestions = _0[0], setSuggestions = _0[1];
82
+ var inputRef = (0, react_1.useRef)(null);
83
+ var adorementRef = (0, react_1.useRef)(null);
84
+ var dropdownref = (0, react_1.useRef)(null);
85
+ var dropBtnRef = (0, react_1.useRef)(null);
86
+ var timerRef = (0, react_1.useRef)(0); // To fix the no results found issue on second type
87
+ var _1 = (0, react_1.useState)(0), selectedIndex = _1[0], setSelectedIndex = _1[1];
88
+ var itemRefs = (0, react_1.useRef)([]);
89
+ var scrollContainerRef = (0, react_1.useRef)(null);
90
+ var _2 = (0, react_1.useState)({
91
+ top: 0,
92
+ left: 0,
93
+ bottom: 0,
94
+ right: 0,
95
+ }), dropPosition = _2[0], setDropPosition = _2[1];
96
+ var checkIncludes = function (mainString, subString, param1, param2, param3, param4) {
97
+ var checkIncludesIfExists = function (mainString, substring) {
98
+ return substring &&
99
+ mainString &&
100
+ typeof mainString === "string" &&
101
+ typeof subString === "string"
102
+ ? mainString
103
+ .toString()
104
+ .toLowerCase()
105
+ .startsWith(substring.toString().toLowerCase())
106
+ : false;
107
+ };
108
+ var checkArrayContains = function (strArray, param) { var _a; return (_a = strArray === null || strArray === void 0 ? void 0 : strArray.includes(param)) !== null && _a !== void 0 ? _a : false; };
109
+ return (checkIncludesIfExists(mainString, subString) ||
110
+ (!!checkParams &&
111
+ ((checkArrayContains(checkParams, "param1") &&
112
+ checkIncludesIfExists(param1, subString)) ||
113
+ (checkArrayContains(checkParams, "param2") &&
114
+ checkIncludesIfExists(param2, subString)) ||
115
+ (checkArrayContains(checkParams, "param3") &&
116
+ checkIncludesIfExists(param3, subString)) ||
117
+ (checkArrayContains(checkParams, "param4") &&
118
+ checkIncludesIfExists(param4, subString)))));
119
+ };
120
+ var getHeight = function () {
121
+ switch (size) {
122
+ case "sm":
123
+ return " h-[34px] ";
124
+ default:
125
+ return " ";
126
+ }
127
+ };
128
+ var handleChange = function (event) {
129
+ var value = event.target.value;
130
+ timerRef.current = 0;
131
+ setInputValue(value);
132
+ handleValChange(value);
133
+ if (!value) {
134
+ setInputValue("");
135
+ onChange({ id: undefined, name: "", from: 2 });
136
+ }
137
+ };
138
+ var handleValChange = (0, react_1.useCallback)((0, debounce_1.debounce)(function (value) {
139
+ setDropOpen(true);
140
+ onChange({ id: undefined, name: "", from: 1 });
141
+ if (value.trim() === "" && type === "auto_complete") {
142
+ setSuggestions([]);
143
+ if (autoFilter) {
144
+ handleDropData("*");
145
+ }
146
+ else {
147
+ setDropOpen(false);
148
+ }
149
+ }
150
+ else {
151
+ handleDropData(value);
152
+ }
153
+ setTimeout(function () {
154
+ timerRef.current = 1;
155
+ }, 200);
156
+ }, isStaticList ? 0 : 1000), []);
157
+ var handleDropData = function (value) {
158
+ if (type === "auto_complete") {
159
+ if (isStaticList) {
160
+ loadStaticData();
161
+ var filteredData_1 = value && value !== "*"
162
+ ? data === null || data === void 0 ? void 0 : data.filter(function (item) {
163
+ return checkIncludes(item.name, value, item.param1, item.param2, item.param3);
164
+ })
165
+ : data;
166
+ setSuggestions(filteredData_1);
167
+ }
168
+ else
169
+ handlePickSuggestions(value);
170
+ }
171
+ else if ((type === "custom_select" || type === "custom_search_select") &&
172
+ (!data || (data === null || data === void 0 ? void 0 : data.length) === 0)) {
173
+ handlePickSuggestions();
174
+ }
175
+ else if (type === "custom_search_select" && data && (data === null || data === void 0 ? void 0 : data.length) > 0) {
176
+ var filteredData_2 = value && value !== "*"
177
+ ? data.filter(function (item) {
178
+ return checkIncludes(item.name, value, item.param1, item.param2, item.param3);
179
+ })
180
+ : data;
181
+ setSuggestions(filteredData_2);
182
+ }
183
+ };
184
+ var handlePickSuggestions = function (value) { return __awaiter(void 0, void 0, void 0, function () {
185
+ var fetchedSuggestions, error_1;
186
+ return __generator(this, function (_a) {
187
+ switch (_a.label) {
188
+ case 0:
189
+ if (!getData) return [3 /*break*/, 4];
190
+ setIsLoading(true);
191
+ _a.label = 1;
192
+ case 1:
193
+ _a.trys.push([1, 3, , 4]);
194
+ return [4 /*yield*/, (getData === null || getData === void 0 ? void 0 : getData(value))];
195
+ case 2:
196
+ fetchedSuggestions = _a.sent();
197
+ setSuggestions(fetchedSuggestions);
198
+ setIsLoading(false);
199
+ return [3 /*break*/, 4];
200
+ case 3:
201
+ error_1 = _a.sent();
202
+ setIsLoading(false);
203
+ return [3 /*break*/, 4];
204
+ case 4: return [2 /*return*/];
205
+ }
206
+ });
207
+ }); };
208
+ var onLabelClick = function () {
209
+ var _a;
210
+ if (!isDisabled) {
211
+ (_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
212
+ if (autoFilter && inputValue === "") {
213
+ handleValChange("*");
214
+ }
215
+ else if ((type === "custom_select" || type === "custom_search_select") &&
216
+ data &&
217
+ (data === null || data === void 0 ? void 0 : data.length) > 0) {
218
+ handleDropData();
219
+ setDropOpen(true);
220
+ }
221
+ }
222
+ };
223
+ var handleClickOutside = function (event) {
224
+ if (dropdownref.current &&
225
+ !dropdownref.current.contains(event.target)) {
226
+ setDropOpen(false);
227
+ }
228
+ };
229
+ var checkIsEmptyField = function () {
230
+ var _a;
231
+ if (inputValue === undefined)
232
+ return true;
233
+ else
234
+ return ((_a = inputValue === null || inputValue === void 0 ? void 0 : inputValue.toString().length) !== null && _a !== void 0 ? _a : 0) <= 0 ? true : false;
235
+ };
236
+ var loadStaticData = function () { return __awaiter(void 0, void 0, void 0, function () {
237
+ var fetchedSuggestions, error_2;
238
+ return __generator(this, function (_a) {
239
+ switch (_a.label) {
240
+ case 0:
241
+ if (!!data) return [3 /*break*/, 4];
242
+ data = [];
243
+ if (!getData) return [3 /*break*/, 4];
244
+ _a.label = 1;
245
+ case 1:
246
+ _a.trys.push([1, 3, , 4]);
247
+ setIsLoading(true);
248
+ handlePickSuggestions("*");
249
+ return [4 /*yield*/, (getData === null || getData === void 0 ? void 0 : getData("*"))];
250
+ case 2:
251
+ fetchedSuggestions = _a.sent();
252
+ fetchedSuggestions === null || fetchedSuggestions === void 0 ? void 0 : fetchedSuggestions.forEach(function (element) {
253
+ data === null || data === void 0 ? void 0 : data.push(element);
254
+ });
255
+ setIsLoading(false);
256
+ return [3 /*break*/, 4];
257
+ case 3:
258
+ error_2 = _a.sent();
259
+ setIsLoading(false);
260
+ return [3 /*break*/, 4];
261
+ case 4: return [2 /*return*/];
262
+ }
263
+ });
264
+ }); };
265
+ (0, react_1.useEffect)(function () {
266
+ document.addEventListener("click", handleClickOutside);
267
+ return function () {
268
+ document.removeEventListener("click", handleClickOutside);
269
+ };
270
+ }, []);
271
+ (0, react_1.useEffect)(function () {
272
+ if (autoFocus) {
273
+ onLabelClick();
274
+ }
275
+ }, [autoFocus]);
276
+ var onInputFocus = function () {
277
+ if (!isDisabled) {
278
+ if (autoFilter && inputValue === "") {
279
+ handleValChange("*");
280
+ }
281
+ else if ((type === "custom_select" || type === "custom_search_select") &&
282
+ data &&
283
+ (data === null || data === void 0 ? void 0 : data.length) > 0) {
284
+ handleDropData();
285
+ //if (insideOpen) setDropOpen(true) // commeted this code bcoz added onclick function inside
286
+ }
287
+ }
288
+ };
289
+ (0, react_1.useEffect)(function () {
290
+ setIsDisabled(disabled);
291
+ }, [disabled]);
292
+ var handleSuggestionClick = function (suggestion, index) {
293
+ onChange(__assign(__assign(__assign({}, suggestion), { id: suggestion === null || suggestion === void 0 ? void 0 : suggestion.id, name: suggestion.name }), ((suggestion === null || suggestion === void 0 ? void 0 : suggestion.label) ? { label: suggestion === null || suggestion === void 0 ? void 0 : suggestion.label } : {})));
294
+ if (type !== "custom_select")
295
+ setInputValue(suggestion.name);
296
+ setDropOpen(false);
297
+ setSelectedIndex(index);
298
+ };
299
+ var handleOpen = function (e) {
300
+ if (!suggestions || (suggestions === null || suggestions === void 0 ? void 0 : suggestions.length) === 0) {
301
+ handleDropData();
302
+ return;
303
+ }
304
+ if (!isLoading) {
305
+ setDropOpen(!dropOpen);
306
+ if (type !== "custom_select")
307
+ setInputValue("");
308
+ }
309
+ };
310
+ var handleScroll = function () {
311
+ setDropOpen(false);
312
+ };
313
+ (0, react_1.useEffect)(function () {
314
+ if (!insideOpen) {
315
+ setSelectedIndex(0);
316
+ window.addEventListener("scroll", handleScroll);
317
+ var mainElement = document.querySelector("main");
318
+ mainElement === null || mainElement === void 0 ? void 0 : mainElement.addEventListener("scroll", handleScroll);
319
+ var gridElements = document.querySelectorAll(".k-grid-content, .overflow-auto, .overflow-y-auto, .overflow-x-auto");
320
+ gridElements.forEach(function (gridElement) {
321
+ gridElement.addEventListener("scroll", handleScroll);
322
+ });
323
+ window.addEventListener("resize", getDropPosition);
324
+ getDropPosition();
325
+ return function () {
326
+ window.removeEventListener("scroll", handleScroll);
327
+ var mainElement = document.querySelector("main");
328
+ mainElement === null || mainElement === void 0 ? void 0 : mainElement.removeEventListener("scroll", handleScroll);
329
+ window.addEventListener("resize", getDropPosition);
330
+ var gridElements = document.querySelectorAll(".k-grid-content");
331
+ gridElements.forEach(function (gridElement) {
332
+ gridElement.removeEventListener("scroll", handleScroll);
333
+ });
334
+ };
335
+ }
336
+ }, [dropOpen]);
337
+ var handleClear = function () {
338
+ setDropOpen(false);
339
+ setInputValue("");
340
+ onChange({ id: undefined, name: "", from: 3 });
341
+ onLabelClick();
342
+ };
343
+ (0, react_1.useEffect)(function () {
344
+ var _a;
345
+ setInputValue((_a = value === null || value === void 0 ? void 0 : value.name) !== null && _a !== void 0 ? _a : "");
346
+ }, [value === null || value === void 0 ? void 0 : value.name]);
347
+ (0, react_1.useEffect)(function () {
348
+ setSuggestions(data);
349
+ }, [data]);
350
+ var getErrors = function (err) {
351
+ var _a, _b, _c, _d;
352
+ var errMsg = "";
353
+ if (err.message) {
354
+ errMsg = err === null || err === void 0 ? void 0 : err.message;
355
+ }
356
+ else if ((_a = err === null || err === void 0 ? void 0 : err.id) === null || _a === void 0 ? void 0 : _a.message) {
357
+ errMsg = (_b = err === null || err === void 0 ? void 0 : err.id) === null || _b === void 0 ? void 0 : _b.message;
358
+ }
359
+ else if ((_c = err === null || err === void 0 ? void 0 : err.name) === null || _c === void 0 ? void 0 : _c.message) {
360
+ errMsg = (_d = err === null || err === void 0 ? void 0 : err.name) === null || _d === void 0 ? void 0 : _d.message;
361
+ }
362
+ return errMsg;
363
+ };
364
+ var generateClassName = function (type) {
365
+ var className = propsClassName;
366
+ switch (type) {
367
+ case "input":
368
+ className += " block text-common text-input-text font-normal px-3.5 w-full text-sm text-gray-900 bg-transparent border appearance-none peer h-10 rounded-[4px] disabled:text-input-disabled bg-white disabled:bg-disabled ".concat(label && isModern
369
+ ? "placeholder-transparent"
370
+ : "focus:placeholder-grey-secondary placeholder-input-label", " focus:placeholder-grey-secondary");
371
+ if (errors && errors[name]) {
372
+ className +=
373
+ " border-[#FDA29B] focus:border-error-[#FDA29B] focus:ring-[#FDA29B] focus:ring-3 focus:outline-[#FDA29B] input-outline";
374
+ }
375
+ else {
376
+ className +=
377
+ " text-grey-dark border-input-light focus:border-blue-navy focus:outline-none focus:ring-0";
378
+ }
379
+ className += getHeight();
380
+ break;
381
+ case "label":
382
+ className += " flex modern-input-label-truncate peer-focus:modern-input-peer-focus-label-size \n ".concat(isDisabled
383
+ ? "cursor-pointer"
384
+ : "cursor-text peer-focus:cursor-pointer", " ").concat(isDisabled && !checkIsEmptyField()
385
+ ? "disabled-input-label-bg"
386
+ : !isDisabled || !checkIsEmptyField()
387
+ ? "active-input-label-bg"
388
+ : "", " absolute duration-300 transform -translate-y-4 top-2 z-1 origin-[0] px-0 peer-placeholder-shown:-translate-y-1/2 peer-placeholder-shown:top-1/2 peer-focus:top-2 peer-focus:-translate-y-4 start-[14px] rtl:peer-focus:translate-x-1/4 rtl:peer-focus:left-auto ").concat(isDisabled
389
+ ? "cursor-pointer"
390
+ : "cursor-text peer-focus:cursor-pointer", "\n ").concat(checkIsEmptyField()
391
+ ? "modern-input-label-size"
392
+ : "modern-input-peer-focus-label-size");
393
+ if (errors && errors[name]) {
394
+ className += " text-error-light ";
395
+ }
396
+ else {
397
+ className += " text-grey-dark peer-focus:text-blue-navy";
398
+ }
399
+ break;
400
+ case "message":
401
+ className = " text-error-icon ";
402
+ break;
403
+ case "adorement":
404
+ className += " absolute right-0 adorement gap-1 flex items-center ";
405
+ break;
406
+ default:
407
+ break;
408
+ }
409
+ return className;
410
+ };
411
+ var handleClose = function () {
412
+ setTimeout(function () {
413
+ setDropOpen(false);
414
+ }, 500);
415
+ };
416
+ var handleClearInputValue = function () {
417
+ // setInputValue(value?.name ?? '')
418
+ };
419
+ var getInnerWidth = function () {
420
+ var innerwidth = adorementRef.current
421
+ ? adorementRef.current.offsetWidth
422
+ : 0;
423
+ return innerwidth;
424
+ };
425
+ // const getPosition = () => {
426
+ // return 'bottom'
427
+ // }
428
+ var filteredData = inputValue !== "*" &&
429
+ inputValue !== "" &&
430
+ type !== "custom_select" &&
431
+ !noLocalFilter
432
+ ? suggestions === null || suggestions === void 0 ? void 0 : suggestions.filter(function (item) {
433
+ var _a, _b, _c, _d;
434
+ return checkIncludes(item.name, inputValue, (_a = item.param1) !== null && _a !== void 0 ? _a : "", (_b = item.param2) !== null && _b !== void 0 ? _b : "", (_c = item.param3) !== null && _c !== void 0 ? _c : "", (_d = item.param4) !== null && _d !== void 0 ? _d : "");
435
+ })
436
+ : suggestions;
437
+ var handleError = function (data) {
438
+ var _a;
439
+ if (getErrors(data[name]) === "required" ||
440
+ getErrors(data[name]) === "Required") {
441
+ return "".concat(label !== null && label !== void 0 ? label : labelTitle, " is ").concat(getErrors(data[name]));
442
+ }
443
+ else {
444
+ return (_a = getErrors(data[name])) !== null && _a !== void 0 ? _a : "";
445
+ }
446
+ };
447
+ var getDropPosition = function () {
448
+ if (!insideOpen && (inputRef === null || inputRef === void 0 ? void 0 : inputRef.current)) {
449
+ var dropdownHeight = 200; // Assume the height of the dropdown is 200px, adjust as needed
450
+ var inputRect = inputRef.current.getBoundingClientRect();
451
+ var spaceBelow = window.innerHeight - (inputRect.bottom + window.scrollY);
452
+ var spaceAbove = inputRect.top + window.scrollY;
453
+ var top_1;
454
+ var bottom = void 0;
455
+ if (spaceBelow < dropdownHeight && spaceAbove > dropdownHeight) {
456
+ bottom = spaceBelow + 43;
457
+ }
458
+ else {
459
+ top_1 = inputRect.top + window.scrollY + inputRect.height + 2;
460
+ }
461
+ setDropPosition({
462
+ left: inputRect.left + window.scrollX,
463
+ top: top_1,
464
+ bottom: bottom,
465
+ width: inputRect.width + dropdownMinWidth,
466
+ });
467
+ }
468
+ return undefined;
469
+ };
470
+ var _3 = (0, react_1.useState)(false), showNoResults = _3[0], setShowNoResults = _3[1];
471
+ (0, react_1.useEffect)(function () {
472
+ if (inputValue &&
473
+ (filteredData === null || filteredData === void 0 ? void 0 : filteredData.length) === 0 &&
474
+ !isLoading &&
475
+ timerRef.current === 1) {
476
+ var timer_1 = setTimeout(function () {
477
+ setShowNoResults(true);
478
+ }, 500); // Delay in milliseconds
479
+ return function () { return clearTimeout(timer_1); };
480
+ }
481
+ else {
482
+ setShowNoResults(false);
483
+ }
484
+ // Handle keyboard navigation
485
+ var handleKeyDown = function (e) {
486
+ if (!dropOpen)
487
+ return;
488
+ var nextIndex = e.key === "ArrowDown"
489
+ ? (selectedIndex + 1) % filteredData.length
490
+ : e.key === "ArrowUp"
491
+ ? (selectedIndex - 1 + filteredData.length) % filteredData.length
492
+ : selectedIndex;
493
+ switch (e.key) {
494
+ case "ArrowDown":
495
+ case "ArrowUp":
496
+ e.preventDefault();
497
+ // Update index first
498
+ setSelectedIndex(nextIndex);
499
+ // Wait for DOM update before scrolling
500
+ requestAnimationFrame(function () {
501
+ var el = itemRefs.current[nextIndex];
502
+ var container = scrollContainerRef.current;
503
+ if (el && container) {
504
+ var elTop = el.offsetTop;
505
+ var elBottom = elTop + el.offsetHeight;
506
+ var containerTop = container.scrollTop;
507
+ var containerBottom = containerTop + container.clientHeight;
508
+ if (elBottom > containerBottom) {
509
+ container.scrollTop = elBottom - container.clientHeight;
510
+ }
511
+ else if (elTop < containerTop) {
512
+ container.scrollTop = elTop;
513
+ }
514
+ }
515
+ });
516
+ break;
517
+ case "Enter":
518
+ e.preventDefault();
519
+ handleSuggestionClick(filteredData[selectedIndex], selectedIndex);
520
+ break;
521
+ case "Escape":
522
+ e.preventDefault();
523
+ setDropOpen(false);
524
+ break;
525
+ default:
526
+ break;
527
+ }
528
+ };
529
+ if ((filteredData === null || filteredData === void 0 ? void 0 : filteredData.length) > 0 && !isLoading) {
530
+ window.addEventListener("keydown", handleKeyDown);
531
+ return function () {
532
+ window.removeEventListener("keydown", handleKeyDown);
533
+ };
534
+ }
535
+ }, [
536
+ inputValue,
537
+ filteredData,
538
+ isLoading,
539
+ timerRef.current,
540
+ selectedIndex,
541
+ dropOpen,
542
+ ]);
543
+ var setDropDown = function () {
544
+ return (((filteredData === null || filteredData === void 0 ? void 0 : filteredData.length) > 0 || showNoResults) && ((0, jsx_runtime_1.jsx)("div", __assign({ className: "autocomplete-suggections absolute bg-white shadow-gray-300 shadow-md border border-grey-light z-50 mt-9", style: dropPosition }, { children: (0, jsx_runtime_1.jsx)("ul", __assign({ className: "h-auto max-h-40 overflow-auto w-full ".concat(tableView ? '' : 'py-1.5'), ref: scrollContainerRef }, { children: (filteredData === null || filteredData === void 0 ? void 0 : filteredData.length) > 0 ? ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: filteredData.map(function (suggestion, index) { return ((0, jsx_runtime_1.jsx)("li", __assign({ className: "".concat((value === null || value === void 0 ? void 0 : value.id) === (suggestion === null || suggestion === void 0 ? void 0 : suggestion.id)
545
+ ? "bg-blue-navy text-white"
546
+ : "".concat(index === selectedIndex ? "is-selected" : "", " hover:bg-table-hover"), " cursor-pointer text-xxs qbs-autocomplete-suggections-items ").concat(tableView
547
+ ? "border-b border-grey-light last:border-b-0"
548
+ : "p-1 ps-3.5 pl-[10px]"), "data-testid": suggestion.name, onClick: function () { return handleSuggestionClick(suggestion, index); }, tabIndex: index, ref: function (el) { return (itemRefs.current[index] = el); } }, { children: (0, jsx_runtime_1.jsx)("ul", __assign({ className: "flex items-stretch w-full list-none p-0 m-0" }, { children: (function () {
549
+ // Sort columns by order if specified, otherwise maintain array order
550
+ var sortedColumns = additionalColumns
551
+ ? __spreadArray([], additionalColumns, true).sort(function (a, b) {
552
+ var orderA = a.order !== undefined ? a.order : Infinity;
553
+ var orderB = b.order !== undefined ? b.order : Infinity;
554
+ return orderA - orderB;
555
+ })
556
+ : [];
557
+ // Separate columns before first column (order < 0) and after (order >= 0 or undefined)
558
+ var columnsBefore = sortedColumns.filter(function (col) { return col.order !== undefined && col.order < 0; });
559
+ var columnsAfter = sortedColumns.filter(function (col) { return col.order === undefined || col.order >= 0; });
560
+ // Determine if first column needs a separator
561
+ var hasColumnsAfter = columnsAfter.length > 0;
562
+ var hasColumnsBefore = columnsBefore.length > 0;
563
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [columnsBefore.map(function (column, colIndex) {
564
+ var hasValue = suggestion === null || suggestion === void 0 ? void 0 : suggestion[column.key];
565
+ var isLastBefore = colIndex === columnsBefore.length - 1 && !hasColumnsAfter;
566
+ return hasValue ? ((0, jsx_runtime_1.jsx)("li", __assign({ className: "".concat(column.width ? 'flex-shrink-0' : 'flex-1', " min-w-0 px-3 ").concat(tableView ? 'py-2' : '', " ").concat(!isLastBefore ? 'border-r border-grey-light' : '', " break-words flex flex-col"), style: column.width ? { width: "".concat(column.width, "px") } : undefined }, { children: (0, jsx_runtime_1.jsx)("span", __assign({ className: "block whitespace-normal" }, { children: suggestion === null || suggestion === void 0 ? void 0 : suggestion[column.key] })) }), column.key)) : null;
567
+ }), (0, jsx_runtime_1.jsx)("li", __assign({ className: "flex-1 min-w-0 px-3 ".concat(tableView ? 'py-2' : '', " ").concat(hasColumnsAfter ? 'border-r border-grey-light' : '', " break-words flex flex-col") }, { children: (0, jsx_runtime_1.jsx)("span", __assign({ className: "block whitespace-normal" }, { children: (suggestion === null || suggestion === void 0 ? void 0 : suggestion.label) ? suggestion === null || suggestion === void 0 ? void 0 : suggestion.label : suggestion.name })) })), columnsAfter.map(function (column, colIndex) {
568
+ var hasValue = suggestion === null || suggestion === void 0 ? void 0 : suggestion[column.key];
569
+ var isLastColumn = colIndex === columnsAfter.length - 1;
570
+ return hasValue ? ((0, jsx_runtime_1.jsx)("li", __assign({ className: "".concat(column.width ? 'flex-shrink-0' : 'flex-1', " min-w-0 px-3 ").concat(tableView ? 'py-2' : '', " ").concat(!isLastColumn ? 'border-r border-grey-light' : '', " break-words flex flex-col"), style: column.width ? { width: "".concat(column.width, "px") } : undefined }, { children: (0, jsx_runtime_1.jsx)("span", __assign({ className: "block whitespace-normal" }, { children: suggestion === null || suggestion === void 0 ? void 0 : suggestion[column.key] })) }), column.key)) : null;
571
+ })] }));
572
+ })() })) }), suggestion === null || suggestion === void 0 ? void 0 : suggestion.id)); }) })) : (showNoResults &&
573
+ !isLoading &&
574
+ timerRef.current === 1 && ((0, jsx_runtime_1.jsx)("li", __assign({ className: "$ cursor-pointer p-1 rounded-sm text-xxs", onClick: handleClose }, { children: "No Results Found" })))) })) }))));
575
+ };
576
+ var getBorderRight = function () {
577
+ if (fromPrefix) {
578
+ if ((hasParentError && Boolean(errors && errors[name])) ||
579
+ hasParentError) {
580
+ return 0;
581
+ }
582
+ else if (errors && errors[name]) {
583
+ return undefined;
584
+ }
585
+ }
586
+ return 0;
587
+ };
588
+ (0, react_1.useEffect)(function () {
589
+ (0, getPosition_1.applyPositionClass)(dropdownref, isHovered);
590
+ setDropOpen(false);
591
+ }, [isHovered]);
592
+ (0, react_1.useEffect)(function () {
593
+ var shouldShowClose = (value === null || value === void 0 ? void 0 : value.name) &&
594
+ ((value === null || value === void 0 ? void 0 : value.id) || String(value === null || value === void 0 ? void 0 : value.id) === "0") &&
595
+ !disabled &&
596
+ !readOnly &&
597
+ isClose;
598
+ if (showClose !== shouldShowClose) {
599
+ setShowClose(shouldShowClose);
600
+ }
601
+ }, [value, disabled, readOnly]);
602
+ (0, react_1.useEffect)(function () {
603
+ // Check if input content overflows
604
+ var checkOverflow = function () {
605
+ if (inputRef.current) {
606
+ var _a = inputRef.current, scrollWidth = _a.scrollWidth, clientWidth = _a.clientWidth, value_1 = _a.value;
607
+ // Check for overflow only when there's content
608
+ if (value_1.trim() !== "") {
609
+ setShowTooltip(scrollWidth > clientWidth + 2);
610
+ }
611
+ else {
612
+ setShowTooltip(false); // No tooltip for empty input
613
+ }
614
+ }
615
+ };
616
+ if (inputRef.current) {
617
+ inputRef.current.addEventListener("input", checkOverflow);
618
+ checkOverflow(); // Initial check
619
+ }
620
+ return function () {
621
+ if (inputRef.current) {
622
+ inputRef.current.removeEventListener("input", checkOverflow);
623
+ }
624
+ };
625
+ }, [inputValue]);
626
+ var handleMouseEnter = function () {
627
+ setTooltipIsHovered(true);
628
+ };
629
+ var handleMouseLeave = function () {
630
+ setTooltipIsHovered(false);
631
+ };
632
+ return ((0, jsx_runtime_1.jsxs)("div", __assign({ id: id ? "autocomplete-container-".concat(id) : "autocomplete-container-".concat(name), className: " flex-grow ".concat(fullWidth ? "w-full" : "w-auto"), ref: dropdownref }, { children: [label && !isModern && ((0, jsx_runtime_1.jsx)("div", __assign({ className: "mb-3" }, { children: (0, jsx_runtime_1.jsxs)("label", __assign({ className: "text-xs font-medium" }, { children: [label, required ? (0, jsx_runtime_1.jsx)("span", __assign({ className: "text-error" }, { children: " *" })) : (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {})] })) }))), (0, jsx_runtime_1.jsxs)("div", __assign({ className: "tooltip-container" }, { children: [isHovered && errors && errors[name] && ((0, jsx_runtime_1.jsxs)("span", __assign({ className: "tooltip" }, { children: [handleError(errors), " "] }))), tooltipIsHovered && showToolTip && !dropOpen && inputValue && ((0, jsx_runtime_1.jsx)("div", __assign({ className: "tooltip-info" }, { children: inputValue }))), (0, jsx_runtime_1.jsxs)("div", __assign({ className: "flex relative ".concat(fullWidth ? "w-full" : "w-auto"), style: { width: width } }, { children: [(0, jsx_runtime_1.jsxs)("div", __assign({ className: "relative w-full", onMouseEnter: function () { return handleMouseEnter(); }, onMouseLeave: function () { return handleMouseLeave(); } }, { children: [(0, jsx_runtime_1.jsx)("input", { type: "text", readOnly: readOnly !== null && readOnly !== void 0 ? readOnly : type === "custom_select", value: inputValue ? inputValue : "", onBlur: handleClearInputValue, autoComplete: "off", disabled: disabled, ref: inputRef, id: id ? "custom-autocomplete-".concat(id) : "custom-autocomplete-".concat(name), "data-testid": "custom-autocomplete", "aria-describedby": id, style: __assign({ paddingRight: getInnerWidth() }, (fromPrefix
633
+ ? {
634
+ borderRight: getBorderRight(),
635
+ borderTopRightRadius: 0,
636
+ borderBottomRightRadius: 0,
637
+ }
638
+ : {})), className: " ".concat(generateClassName("input")), onChange: handleChange, placeholder: type === "auto_complete"
639
+ ? placeholder && isCustomPlaceholder
640
+ ? placeholder
641
+ : "Type to search"
642
+ : placeholder !== null && placeholder !== void 0 ? placeholder : "--Select--", onFocus: onInputFocus, onClick: function (e) {
643
+ if (type === "custom_select") {
644
+ setDropOpen(!dropOpen);
645
+ handleOpen(e);
646
+ }
647
+ else {
648
+ setDropOpen(!dropOpen);
649
+ }
650
+ } }), isModern && ((0, jsx_runtime_1.jsxs)("label", __assign({ htmlFor: id, onClick: function () { return onLabelClick(); }, className: generateClassName("label") }, { children: [label ? (0, jsx_runtime_1.jsx)("span", __assign({ className: "truncate" }, { children: label })) : "", required ? (0, jsx_runtime_1.jsx)("span", __assign({ className: "text-error" }, { children: " *" })) : (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {})] })))] })), (0, jsx_runtime_1.jsx)("div", __assign({ className: "flex items-center justify-center " }, { children: (0, jsx_runtime_1.jsxs)("div", __assign({ ref: adorementRef, className: "".concat(generateClassName("adorement"), " qbs-autocomplete-adorement custom-dorpdown-adorement mr-[1px] ").concat(isLoading ? "bg-white" : "") }, { children: [showClose && ((0, jsx_runtime_1.jsx)("button", __assign({ onClick: function () { return handleClear(); }, className: " text-table-bodyColor text-[#667085]", "aria-label": "close", type: "button", id: "autocomplete-close-icon" }, { children: (0, jsx_runtime_1.jsx)(customIcons_1.default, { name: "close", type: "large-m" }) }))), isLoading && (0, jsx_runtime_1.jsx)(Spinner_1.default, {}), type !== "auto_complete" && !disabled && !readOnly && ((0, jsx_runtime_1.jsx)("button", __assign({ disabled: disabled !== null && disabled !== void 0 ? disabled : readOnly, onClick: function (e) { return handleOpen(e); }, onBlur: handleClose, className: " text-[#667085] focus-visible:outline-slate-100", "data-testid": "drop-arrow", type: "button", id: "autocomplete-drop-icon", ref: dropBtnRef }, { children: !dropOpen ? ((0, jsx_runtime_1.jsx)(icons_1.DropArrow, { uniqueDropArrowId: "drop-arrow-icon" })) : ((0, jsx_runtime_1.jsx)(icons_1.DropArrow, { className: "rotate-180", uniqueDropArrowId: "drop-arrow-icon" })) }))), errors && errors[name] && ((0, jsx_runtime_1.jsx)("div", __assign({ className: " text-error-label relative cursor-pointer ".concat(generateClassName("message")), onMouseEnter: function () { return setIsHovered(true); }, onMouseLeave: function () { return setIsHovered(false); } }, { children: (0, jsx_runtime_1.jsx)(customIcons_1.default, { name: "alert", type: "medium" }) })))] })) })), dropOpen && (!isLoading || (filteredData === null || filteredData === void 0 ? void 0 : filteredData.length) > 0) && ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: insideOpen ? setDropDown() : (0, jsx_runtime_1.jsx)(portal_1.default, { children: setDropDown() }) }))] }))] }))] })));
651
+ };
652
+ exports.default = ReactAutoCompleteTableView;
653
+ //# sourceMappingURL=ReactAutoCompleteTableView.js.map