react-core-ts 2.0.12 → 2.0.14

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,724 @@
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.autoDropdown, autoDropdown = _g === void 0 ? true : _g, _h = _a.insideOpen, insideOpen = _h === void 0 ? false : _h, _j = _a.isClose, isClose = _j === void 0 ? true : _j, _k = _a.noLocalFilter, noLocalFilter = _k === void 0 ? false : _k, _l = _a.isStaticList, isStaticList = _l === void 0 ? false : _l, _m = _a.isCustomPlaceholder, isCustomPlaceholder = _m === void 0 ? false : _m, checkParams = _a.checkParams, width = _a.width, hasParentError = _a.hasParentError, fromPrefix = _a.fromPrefix, labelTitle = _a.labelTitle, _o = _a.isModern, isModern = _o === void 0 ? true : _o, _p = _a.size, size = _p === void 0 ? "md" : _p, _q = _a.dropdownMinWidth, dropdownMinWidth = _q === void 0 ? 200 : _q, _r = _a.tableView, tableView = _r === void 0 ? false : _r, _s = _a.additionalColumns, additionalColumns = _s === void 0 ? [] : _s;
73
+ var _t = (0, react_1.useState)((_b = value === null || value === void 0 ? void 0 : value.name) !== null && _b !== void 0 ? _b : ""), inputValue = _t[0], setInputValue = _t[1];
74
+ var _u = (0, react_1.useState)(false), isHovered = _u[0], setIsHovered = _u[1];
75
+ var _v = (0, react_1.useState)(false), isLoading = _v[0], setIsLoading = _v[1];
76
+ var _w = (0, react_1.useState)(false), dropOpen = _w[0], setDropOpen = _w[1];
77
+ var _x = (0, react_1.useState)(disabled), isDisabled = _x[0], setIsDisabled = _x[1];
78
+ var _y = (0, react_1.useState)(false), showClose = _y[0], setShowClose = _y[1];
79
+ var _z = (0, react_1.useState)(false), showToolTip = _z[0], setShowTooltip = _z[1];
80
+ var _0 = (0, react_1.useState)(false), tooltipIsHovered = _0[0], setTooltipIsHovered = _0[1];
81
+ var _1 = (0, react_1.useState)([]), suggestions = _1[0], setSuggestions = _1[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 _2 = (0, react_1.useState)(0), selectedIndex = _2[0], setSelectedIndex = _2[1];
88
+ var itemRefs = (0, react_1.useRef)([]);
89
+ var scrollContainerRef = (0, react_1.useRef)(null);
90
+ var _3 = (0, react_1.useState)(false), refetchData = _3[0], setRefetchData = _3[1];
91
+ var _4 = (0, react_1.useState)({
92
+ top: 0,
93
+ left: 0,
94
+ bottom: 0,
95
+ right: 0,
96
+ }), dropPosition = _4[0], setDropPosition = _4[1];
97
+ var checkIncludes = function (mainString, subString, param1, param2, param3, param4) {
98
+ var checkIncludesIfExists = function (mainString, substring) {
99
+ return substring &&
100
+ mainString &&
101
+ typeof mainString === 'string' &&
102
+ typeof subString === 'string'
103
+ ? mainString
104
+ .toString()
105
+ .toLowerCase()
106
+ .startsWith(substring.toString().toLowerCase())
107
+ : false;
108
+ };
109
+ 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; };
110
+ return (checkIncludesIfExists(mainString, subString) ||
111
+ (!!checkParams &&
112
+ ((checkArrayContains(checkParams, 'param1') &&
113
+ checkIncludesIfExists(param1, subString)) ||
114
+ (checkArrayContains(checkParams, 'param2') &&
115
+ checkIncludesIfExists(param2, subString)) ||
116
+ (checkArrayContains(checkParams, 'param3') &&
117
+ checkIncludesIfExists(param3, subString)) ||
118
+ (checkArrayContains(checkParams, 'param4') &&
119
+ checkIncludesIfExists(param4, subString)))));
120
+ };
121
+ var getHeight = function () {
122
+ switch (size) {
123
+ case 'sm':
124
+ return ' h-[34px] ';
125
+ default:
126
+ return ' ';
127
+ }
128
+ };
129
+ var handleChange = function (event) {
130
+ var value = event.target.value;
131
+ timerRef.current = 0;
132
+ setInputValue(value);
133
+ handleValChange(value);
134
+ if (!value) {
135
+ setInputValue('');
136
+ onChange({ id: undefined, name: '', from: 2 });
137
+ }
138
+ };
139
+ var handleValChange = (0, react_1.useCallback)((0, debounce_1.debounce)(function (value) {
140
+ setDropOpen(true);
141
+ onChange({ id: undefined, name: '', from: 1 });
142
+ if (value.trim() === '' && type === 'auto_complete') {
143
+ setSuggestions([]);
144
+ if (autoFilter) {
145
+ handleDropData('*');
146
+ }
147
+ else {
148
+ setDropOpen(false);
149
+ }
150
+ }
151
+ else {
152
+ handleDropData(value);
153
+ }
154
+ setTimeout(function () {
155
+ timerRef.current = 1;
156
+ }, 200);
157
+ }, isStaticList ? 0 : 1000), []);
158
+ var handleDropData = function (value) {
159
+ if (type === 'auto_complete') {
160
+ if (isStaticList) {
161
+ loadStaticData();
162
+ var filteredData_1 = value && value !== '*'
163
+ ? data === null || data === void 0 ? void 0 : data.filter(function (item) {
164
+ return checkIncludes(item.name, value, item.param1, item.param2, item.param3);
165
+ })
166
+ : data;
167
+ setSuggestions(filteredData_1);
168
+ }
169
+ else {
170
+ handlePickSuggestions(value);
171
+ }
172
+ }
173
+ else if ((type === 'custom_select' || type === 'custom_search_select') &&
174
+ (!data || (data === null || data === void 0 ? void 0 : data.length) === 0)) {
175
+ handlePickSuggestions();
176
+ }
177
+ else if (type === 'custom_search_select' && data && (data === null || data === void 0 ? void 0 : data.length) > 0) {
178
+ var filteredData_2 = value && value !== '*'
179
+ ? data.filter(function (item) {
180
+ return checkIncludes(item.name, value, item.param1, item.param2, item.param3);
181
+ })
182
+ : data;
183
+ setSuggestions(filteredData_2);
184
+ }
185
+ };
186
+ var handlePickSuggestions = function (value) { return __awaiter(void 0, void 0, void 0, function () {
187
+ var fetchedSuggestions, error_1;
188
+ return __generator(this, function (_a) {
189
+ switch (_a.label) {
190
+ case 0:
191
+ if (!getData) return [3 /*break*/, 4];
192
+ setIsLoading(true);
193
+ _a.label = 1;
194
+ case 1:
195
+ _a.trys.push([1, 3, , 4]);
196
+ return [4 /*yield*/, (getData === null || getData === void 0 ? void 0 : getData(value))];
197
+ case 2:
198
+ fetchedSuggestions = _a.sent();
199
+ setSuggestions(fetchedSuggestions);
200
+ setIsLoading(false);
201
+ if (autoDropdown) {
202
+ setRefetchData(true);
203
+ }
204
+ return [3 /*break*/, 4];
205
+ case 3:
206
+ error_1 = _a.sent();
207
+ setIsLoading(false);
208
+ return [3 /*break*/, 4];
209
+ case 4: return [2 /*return*/];
210
+ }
211
+ });
212
+ }); };
213
+ var onLabelClick = function () {
214
+ var _a;
215
+ if (!isDisabled) {
216
+ (_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
217
+ if (autoFilter && inputValue === '') {
218
+ handleValChange('*');
219
+ }
220
+ else if ((type === 'custom_select' || type === 'custom_search_select') &&
221
+ data &&
222
+ (data === null || data === void 0 ? void 0 : data.length) > 0) {
223
+ handleDropData();
224
+ setDropOpen(true);
225
+ }
226
+ }
227
+ };
228
+ var handleClickOutside = function (event) {
229
+ if (dropdownref.current &&
230
+ !dropdownref.current.contains(event.target)) {
231
+ setDropOpen(false);
232
+ }
233
+ };
234
+ var checkIsEmptyField = function () {
235
+ var _a;
236
+ if (inputValue === undefined)
237
+ return true;
238
+ else
239
+ return ((_a = inputValue === null || inputValue === void 0 ? void 0 : inputValue.toString().length) !== null && _a !== void 0 ? _a : 0) <= 0 ? true : false;
240
+ };
241
+ var loadStaticData = function () { return __awaiter(void 0, void 0, void 0, function () {
242
+ var fetchedSuggestions, error_2;
243
+ return __generator(this, function (_a) {
244
+ switch (_a.label) {
245
+ case 0:
246
+ if (!(!data || (refetchData && autoDropdown && !isStaticList))) return [3 /*break*/, 4];
247
+ data = [];
248
+ if (!getData) return [3 /*break*/, 4];
249
+ _a.label = 1;
250
+ case 1:
251
+ _a.trys.push([1, 3, , 4]);
252
+ setIsLoading(true);
253
+ return [4 /*yield*/, (getData === null || getData === void 0 ? void 0 : getData('*'))];
254
+ case 2:
255
+ fetchedSuggestions = _a.sent();
256
+ fetchedSuggestions === null || fetchedSuggestions === void 0 ? void 0 : fetchedSuggestions.forEach(function (element) {
257
+ data === null || data === void 0 ? void 0 : data.push(element);
258
+ });
259
+ setSuggestions(fetchedSuggestions);
260
+ setIsLoading(false);
261
+ if (autoDropdown) {
262
+ setRefetchData(false);
263
+ timerRef.current = 1;
264
+ }
265
+ return [3 /*break*/, 4];
266
+ case 3:
267
+ error_2 = _a.sent();
268
+ setIsLoading(false);
269
+ return [3 /*break*/, 4];
270
+ case 4: return [2 /*return*/];
271
+ }
272
+ });
273
+ }); };
274
+ (0, react_1.useEffect)(function () {
275
+ document.addEventListener('click', handleClickOutside);
276
+ return function () {
277
+ document.removeEventListener('click', handleClickOutside);
278
+ };
279
+ }, []);
280
+ (0, react_1.useEffect)(function () {
281
+ if (autoFocus) {
282
+ onLabelClick();
283
+ }
284
+ }, [autoFocus]);
285
+ var onInputFocus = function () {
286
+ if (!isDisabled) {
287
+ if (autoFilter && inputValue === '') {
288
+ handleValChange('*');
289
+ }
290
+ else if ((type === 'custom_select' || type === 'custom_search_select') &&
291
+ data &&
292
+ (data === null || data === void 0 ? void 0 : data.length) > 0) {
293
+ handleDropData();
294
+ //if (insideOpen) setDropOpen(true) // commeted this code bcoz added onclick function inside
295
+ }
296
+ }
297
+ };
298
+ (0, react_1.useEffect)(function () {
299
+ setIsDisabled(disabled);
300
+ }, [disabled]);
301
+ var handleSuggestionClick = function (suggestion, index) {
302
+ 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 } : {})));
303
+ if (type !== 'custom_select')
304
+ setInputValue(suggestion.name);
305
+ setDropOpen(false);
306
+ setSelectedIndex(index);
307
+ };
308
+ var handleOpen = function (e) {
309
+ if (!suggestions || (suggestions === null || suggestions === void 0 ? void 0 : suggestions.length) === 0)
310
+ handleDropData();
311
+ if (!isLoading) {
312
+ setDropOpen(!dropOpen);
313
+ if (type !== 'custom_select')
314
+ setInputValue('');
315
+ }
316
+ };
317
+ var handleOpenDropdown = function (e) {
318
+ if (!suggestions || (suggestions === null || suggestions === void 0 ? void 0 : suggestions.length) === 0 || refetchData) {
319
+ if (autoDropdown && (inputValue === '' || inputValue.trim() === '')) {
320
+ setSuggestions([]);
321
+ loadStaticData();
322
+ }
323
+ else if (!refetchData) {
324
+ handleDropData();
325
+ }
326
+ }
327
+ if (!isLoading) {
328
+ setDropOpen(!dropOpen);
329
+ }
330
+ };
331
+ var handleScroll = function () {
332
+ setDropOpen(false);
333
+ };
334
+ (0, react_1.useEffect)(function () {
335
+ if (!insideOpen) {
336
+ setSelectedIndex(0);
337
+ window.addEventListener('scroll', handleScroll);
338
+ var mainElement = document.querySelector('main');
339
+ mainElement === null || mainElement === void 0 ? void 0 : mainElement.addEventListener('scroll', handleScroll);
340
+ var gridElements = document.querySelectorAll('.k-grid-content, .overflow-auto, .overflow-y-auto, .overflow-x-auto');
341
+ gridElements.forEach(function (gridElement) {
342
+ gridElement.addEventListener('scroll', handleScroll);
343
+ });
344
+ window.addEventListener('resize', getDropPosition);
345
+ getDropPosition();
346
+ return function () {
347
+ window.removeEventListener('scroll', handleScroll);
348
+ var mainElement = document.querySelector('main');
349
+ mainElement === null || mainElement === void 0 ? void 0 : mainElement.removeEventListener('scroll', handleScroll);
350
+ window.addEventListener('resize', getDropPosition);
351
+ var gridElements = document.querySelectorAll('.k-grid-content');
352
+ gridElements.forEach(function (gridElement) {
353
+ gridElement.removeEventListener('scroll', handleScroll);
354
+ });
355
+ };
356
+ }
357
+ }, [dropOpen]);
358
+ var handleClear = function () {
359
+ setDropOpen(false);
360
+ setInputValue('');
361
+ onChange({ id: undefined, name: '', from: 3 });
362
+ onLabelClick();
363
+ if (autoDropdown) {
364
+ setRefetchData(true);
365
+ }
366
+ };
367
+ (0, react_1.useEffect)(function () {
368
+ var _a;
369
+ setInputValue((_a = value === null || value === void 0 ? void 0 : value.name) !== null && _a !== void 0 ? _a : '');
370
+ }, [value === null || value === void 0 ? void 0 : value.name]);
371
+ (0, react_1.useEffect)(function () {
372
+ setSuggestions(data);
373
+ }, [data]);
374
+ var getErrors = function (err) {
375
+ var _a, _b, _c, _d;
376
+ var errMsg = '';
377
+ if (err.message) {
378
+ errMsg = err === null || err === void 0 ? void 0 : err.message;
379
+ }
380
+ else if ((_a = err === null || err === void 0 ? void 0 : err.id) === null || _a === void 0 ? void 0 : _a.message) {
381
+ errMsg = (_b = err === null || err === void 0 ? void 0 : err.id) === null || _b === void 0 ? void 0 : _b.message;
382
+ }
383
+ else if ((_c = err === null || err === void 0 ? void 0 : err.name) === null || _c === void 0 ? void 0 : _c.message) {
384
+ errMsg = (_d = err === null || err === void 0 ? void 0 : err.name) === null || _d === void 0 ? void 0 : _d.message;
385
+ }
386
+ return errMsg;
387
+ };
388
+ var generateClassName = function (type) {
389
+ var className = propsClassName;
390
+ switch (type) {
391
+ case 'input':
392
+ 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
393
+ ? 'placeholder-transparent'
394
+ : 'focus:placeholder-grey-secondary placeholder-input-label', " focus:placeholder-grey-secondary");
395
+ if (errors && errors[name]) {
396
+ className +=
397
+ ' border-[#FDA29B] focus:border-error-[#FDA29B] focus:ring-[#FDA29B] focus:ring-3 focus:outline-[#FDA29B] input-outline';
398
+ }
399
+ else {
400
+ className +=
401
+ ' text-grey-dark border-input-light focus:border-blue-navy focus:outline-none focus:ring-0';
402
+ }
403
+ className += getHeight();
404
+ break;
405
+ case 'label':
406
+ className += " flex modern-input-label-truncate peer-focus:modern-input-peer-focus-label-size \n ".concat(isDisabled
407
+ ? 'cursor-pointer'
408
+ : 'cursor-text peer-focus:cursor-pointer', " ").concat(isDisabled && !checkIsEmptyField()
409
+ ? 'disabled-input-label-bg'
410
+ : !isDisabled || !checkIsEmptyField()
411
+ ? 'active-input-label-bg'
412
+ : '', " 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
413
+ ? 'cursor-pointer'
414
+ : 'cursor-text peer-focus:cursor-pointer', "\n ").concat(checkIsEmptyField()
415
+ ? 'modern-input-label-size'
416
+ : 'modern-input-peer-focus-label-size');
417
+ if (errors && errors[name]) {
418
+ className += ' text-error-light ';
419
+ }
420
+ else {
421
+ className += ' text-grey-dark peer-focus:text-blue-navy';
422
+ }
423
+ break;
424
+ case 'message':
425
+ className = ' text-error-icon ';
426
+ break;
427
+ case 'adorement':
428
+ className += ' absolute right-0 adorement gap-1 flex items-center ';
429
+ break;
430
+ default:
431
+ break;
432
+ }
433
+ return className;
434
+ };
435
+ var handleClose = function () {
436
+ setTimeout(function () {
437
+ setDropOpen(false);
438
+ }, 500);
439
+ };
440
+ var handleClearInputValue = function () {
441
+ // setInputValue(value?.name ?? '')
442
+ };
443
+ var getInnerWidth = function () {
444
+ var innerwidth = adorementRef.current
445
+ ? adorementRef.current.offsetWidth
446
+ : 0;
447
+ return innerwidth;
448
+ };
449
+ // const getPosition = () => {
450
+ // return 'bottom'
451
+ // }
452
+ var filteredData = inputValue !== '*' &&
453
+ inputValue !== '' &&
454
+ type !== 'custom_select' &&
455
+ !noLocalFilter
456
+ ? suggestions === null || suggestions === void 0 ? void 0 : suggestions.filter(function (item) {
457
+ var _a, _b, _c, _d;
458
+ 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 : '');
459
+ })
460
+ : suggestions;
461
+ var handleError = function (data) {
462
+ var _a;
463
+ if (getErrors(data[name]) === 'required' ||
464
+ getErrors(data[name]) === 'Required') {
465
+ return "".concat(label !== null && label !== void 0 ? label : labelTitle, " is ").concat(getErrors(data[name]));
466
+ }
467
+ else {
468
+ return (_a = getErrors(data[name])) !== null && _a !== void 0 ? _a : '';
469
+ }
470
+ };
471
+ var getDropPosition = function () {
472
+ if (!insideOpen && (inputRef === null || inputRef === void 0 ? void 0 : inputRef.current)) {
473
+ var dropdownHeight = 200; // Assume the height of the dropdown is 200px, adjust as needed
474
+ var isMobile = window.innerWidth < 768; // Mobile breakpoint
475
+ var inputRect = inputRef.current.getBoundingClientRect();
476
+ var spaceBelow = window.innerHeight - (inputRect.bottom + window.scrollY);
477
+ var spaceAbove = inputRect.top + window.scrollY;
478
+ var top_1;
479
+ var bottom = void 0;
480
+ if (spaceBelow < dropdownHeight && spaceAbove > dropdownHeight) {
481
+ bottom = spaceBelow + 43;
482
+ }
483
+ else {
484
+ top_1 = inputRect.top + window.scrollY + inputRect.height + 2;
485
+ }
486
+ var left = inputRect.left + window.scrollX;
487
+ var width_1 = inputRect.width + dropdownMinWidth;
488
+ var viewportWidth = window.innerWidth;
489
+ var viewportRight = window.scrollX + viewportWidth;
490
+ var inputRight = inputRect.right + window.scrollX;
491
+ // Check if dropdown would overflow on the right side
492
+ var dropdownRight = left + width_1;
493
+ var wouldOverflowRight = dropdownRight > viewportRight;
494
+ // If dropdown would overflow on the right (last column scenario), align from right to left
495
+ if (wouldOverflowRight) {
496
+ // Align right edge of dropdown with right edge of input
497
+ // Dropdown extends to the left from the input's right edge
498
+ var padding = isMobile ? 8 : 0;
499
+ left = inputRight - width_1;
500
+ // Ensure dropdown doesn't go off the left edge
501
+ var viewportLeft = window.scrollX + (isMobile ? 8 : 0);
502
+ if (left < viewportLeft) {
503
+ left = viewportLeft;
504
+ // Adjust width to fit within viewport
505
+ width_1 = Math.min(width_1, inputRight - left - padding);
506
+ }
507
+ }
508
+ // Handle mobile view - additional constraints
509
+ if (isMobile) {
510
+ // On mobile, constrain width to viewport with some padding
511
+ var mobilePadding = 16; // 8px padding on each side
512
+ var maxWidth = viewportWidth - mobilePadding;
513
+ // Use the smaller of: calculated width or max mobile width
514
+ width_1 = Math.min(width_1, maxWidth);
515
+ // Adjust left position to prevent overflow
516
+ var rightEdge = left + width_1;
517
+ var mobileViewportRight = window.scrollX + viewportWidth - mobilePadding / 2;
518
+ if (rightEdge > mobileViewportRight) {
519
+ // Align to right edge with padding
520
+ left = mobileViewportRight - width_1;
521
+ }
522
+ // Ensure dropdown doesn't go off the left edge
523
+ var viewportLeft = window.scrollX + mobilePadding / 2;
524
+ if (left < viewportLeft) {
525
+ left = viewportLeft;
526
+ // Adjust width if needed to fit
527
+ width_1 = Math.min(width_1, mobileViewportRight - left);
528
+ }
529
+ }
530
+ setDropPosition({
531
+ left: left,
532
+ top: top_1,
533
+ bottom: bottom,
534
+ width: width_1,
535
+ });
536
+ }
537
+ return undefined;
538
+ };
539
+ var _5 = (0, react_1.useState)(false), showNoResults = _5[0], setShowNoResults = _5[1];
540
+ (0, react_1.useEffect)(function () {
541
+ if ((inputValue || autoDropdown) &&
542
+ (filteredData === null || filteredData === void 0 ? void 0 : filteredData.length) === 0 &&
543
+ !isLoading &&
544
+ timerRef.current === 1) {
545
+ var timer_1 = setTimeout(function () {
546
+ setShowNoResults(true);
547
+ }, 500); // Delay in milliseconds
548
+ return function () { return clearTimeout(timer_1); };
549
+ }
550
+ else {
551
+ setShowNoResults(false);
552
+ }
553
+ // Handle keyboard navigation
554
+ var handleKeyDown = function (e) {
555
+ if (!dropOpen)
556
+ return;
557
+ var nextIndex = e.key === 'ArrowDown'
558
+ ? (selectedIndex + 1) % filteredData.length
559
+ : e.key === 'ArrowUp'
560
+ ? (selectedIndex - 1 + filteredData.length) % filteredData.length
561
+ : selectedIndex;
562
+ switch (e.key) {
563
+ case 'ArrowDown':
564
+ case 'ArrowUp':
565
+ e.preventDefault();
566
+ // Update index first
567
+ setSelectedIndex(nextIndex);
568
+ // Wait for DOM update before scrolling
569
+ requestAnimationFrame(function () {
570
+ var el = itemRefs.current[nextIndex];
571
+ var container = scrollContainerRef.current;
572
+ if (el && container) {
573
+ var elTop = el.offsetTop;
574
+ var elBottom = elTop + el.offsetHeight;
575
+ var containerTop = container.scrollTop;
576
+ var containerBottom = containerTop + container.clientHeight;
577
+ if (elBottom > containerBottom) {
578
+ container.scrollTop = elBottom - container.clientHeight;
579
+ }
580
+ else if (elTop < containerTop) {
581
+ container.scrollTop = elTop;
582
+ }
583
+ }
584
+ });
585
+ break;
586
+ case 'Enter':
587
+ e.preventDefault();
588
+ handleSuggestionClick(filteredData[selectedIndex], selectedIndex);
589
+ break;
590
+ case 'Escape':
591
+ e.preventDefault();
592
+ setDropOpen(false);
593
+ break;
594
+ default:
595
+ break;
596
+ }
597
+ };
598
+ if ((filteredData === null || filteredData === void 0 ? void 0 : filteredData.length) > 0 && !isLoading) {
599
+ window.addEventListener('keydown', handleKeyDown);
600
+ return function () {
601
+ window.removeEventListener('keydown', handleKeyDown);
602
+ };
603
+ }
604
+ }, [
605
+ inputValue,
606
+ filteredData,
607
+ isLoading,
608
+ timerRef.current,
609
+ selectedIndex,
610
+ dropOpen,
611
+ ]);
612
+ var setDropDown = function () {
613
+ return (((filteredData === null || filteredData === void 0 ? void 0 : filteredData.length) > 0 || showNoResults) && ((0, jsx_runtime_1.jsx)("div", __assign({ style: dropPosition, className: "autocomplete-suggections autocomplete-suggections-tableview absolute bg-white shadow-gray-300 shadow-md border border-grey-light z-50 mt-9" }, { 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)
614
+ ? 'bg-blue-navy text-white'
615
+ : "".concat(index === selectedIndex ? 'is-selected' : '', " hover:bg-table-hover"), " cursor-pointer text-xxs qbs-autocomplete-suggections-items ").concat(tableView
616
+ ? "border-b border-grey-light last:border-b-0"
617
+ : "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 () {
618
+ // Sort columns by order if specified, otherwise maintain array order
619
+ var sortedColumns = additionalColumns
620
+ ? __spreadArray([], additionalColumns, true).sort(function (a, b) {
621
+ var orderA = a.order !== undefined ? a.order : Infinity;
622
+ var orderB = b.order !== undefined ? b.order : Infinity;
623
+ return orderA - orderB;
624
+ })
625
+ : [];
626
+ // Separate columns before first column (order < 0) and after (order >= 0 or undefined)
627
+ var columnsBefore = sortedColumns.filter(function (col) { return col.order !== undefined && col.order < 0; });
628
+ var columnsAfter = sortedColumns.filter(function (col) { return col.order === undefined || col.order >= 0; });
629
+ // Determine if first column needs a separator
630
+ var hasColumnsAfter = columnsAfter.length > 0;
631
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [columnsBefore.map(function (column, colIndex) {
632
+ var hasValue = suggestion === null || suggestion === void 0 ? void 0 : suggestion[column.key];
633
+ var isLastBefore = false;
634
+ 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;
635
+ }), (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) {
636
+ var hasValue = suggestion === null || suggestion === void 0 ? void 0 : suggestion[column.key];
637
+ var isLastColumn = colIndex === columnsAfter.length - 1;
638
+ 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;
639
+ })] }));
640
+ })() })) }), suggestion === null || suggestion === void 0 ? void 0 : suggestion.id)); }) })) : (showNoResults &&
641
+ !isLoading &&
642
+ 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" })))) })) }))));
643
+ };
644
+ var getBorderRight = function () {
645
+ if (fromPrefix) {
646
+ if ((hasParentError && Boolean(errors && errors[name])) ||
647
+ hasParentError) {
648
+ return 0;
649
+ }
650
+ else if (errors && errors[name]) {
651
+ return undefined;
652
+ }
653
+ }
654
+ return 0;
655
+ };
656
+ (0, react_1.useEffect)(function () {
657
+ (0, getPosition_1.applyPositionClass)(dropdownref, isHovered);
658
+ setDropOpen(false);
659
+ }, [isHovered]);
660
+ (0, react_1.useEffect)(function () {
661
+ var shouldShowClose = (value === null || value === void 0 ? void 0 : value.name) &&
662
+ ((value === null || value === void 0 ? void 0 : value.id) || String(value === null || value === void 0 ? void 0 : value.id) === '0') &&
663
+ !disabled &&
664
+ !readOnly &&
665
+ isClose;
666
+ if (showClose !== shouldShowClose) {
667
+ setShowClose(shouldShowClose);
668
+ }
669
+ }, [value, disabled, readOnly]);
670
+ (0, react_1.useEffect)(function () {
671
+ // Check if input content overflows
672
+ var checkOverflow = function () {
673
+ if (inputRef.current) {
674
+ var _a = inputRef.current, scrollWidth = _a.scrollWidth, clientWidth = _a.clientWidth, value_1 = _a.value;
675
+ // Check for overflow only when there's content
676
+ if (value_1.trim() !== '') {
677
+ setShowTooltip(scrollWidth > clientWidth + 2);
678
+ }
679
+ else {
680
+ setShowTooltip(false); // No tooltip for empty input
681
+ }
682
+ }
683
+ };
684
+ if (inputRef.current) {
685
+ inputRef.current.addEventListener('input', checkOverflow);
686
+ checkOverflow(); // Initial check
687
+ }
688
+ return function () {
689
+ if (inputRef.current) {
690
+ inputRef.current.removeEventListener('input', checkOverflow);
691
+ }
692
+ };
693
+ }, [inputValue]);
694
+ var handleMouseEnter = function () {
695
+ setTooltipIsHovered(true);
696
+ };
697
+ var handleMouseLeave = function () {
698
+ setTooltipIsHovered(false);
699
+ };
700
+ 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
701
+ ? {
702
+ borderRight: getBorderRight(),
703
+ borderTopRightRadius: 0,
704
+ borderBottomRightRadius: 0,
705
+ }
706
+ : {})), className: " ".concat(generateClassName('input')), onChange: handleChange, placeholder: type === 'auto_complete'
707
+ ? placeholder && isCustomPlaceholder
708
+ ? placeholder
709
+ : 'Type to search'
710
+ : placeholder !== null && placeholder !== void 0 ? placeholder : '--Select--', onFocus: onInputFocus, onClick: function (e) {
711
+ if (type === 'custom_select') {
712
+ setDropOpen(!dropOpen);
713
+ handleOpen(e);
714
+ }
715
+ else {
716
+ if (dropOpen || (filteredData === null || filteredData === void 0 ? void 0 : filteredData.length) > 0)
717
+ setDropOpen(!dropOpen);
718
+ }
719
+ } }), 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 autocomplete-adorement-wrapper" }, { children: (0, jsx_runtime_1.jsxs)("div", __assign({ ref: adorementRef, className: "".concat(generateClassName('adorement'), " qbs-autocomplete-adorement auto-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' || autoDropdown) &&
720
+ !disabled &&
721
+ !readOnly && ((0, jsx_runtime_1.jsx)("button", __assign({ disabled: disabled !== null && disabled !== void 0 ? disabled : readOnly, onClick: function (e) { return handleOpenDropdown(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 ? (autoDropdown ? ((0, jsx_runtime_1.jsx)(icons_1.AllDropArrow, { type: "down", uniqueId: "all-dropdow-arrow-icon", className: "all-dropdow-arrow-icon" })) : ((0, jsx_runtime_1.jsx)(icons_1.DropArrow, { uniqueDropArrowId: "drop-arrow-icon" }))) : autoDropdown ? ((0, jsx_runtime_1.jsx)(icons_1.AllDropArrow, { type: "up", uniqueId: "all-dropdow-arrow-icon", className: "all-dropdow-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() }) }))] }))] }))] })));
722
+ };
723
+ exports.default = ReactAutoCompleteTableView;
724
+ //# sourceMappingURL=ReactAutoCompleteTableView.js.map