funuicss 3.4.6 → 3.4.8

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.4.6",
2
+ "version": "3.4.8",
3
3
  "name": "funuicss",
4
4
  "description": "React and Next.js component UI Library for creating Easy and good looking websites with fewer lines of code. Elevate your web development experience with our cutting-edge React/Next.js component UI Library. Craft stunning websites effortlessly, boasting both seamless functionality and aesthetic appeal—all achieved with minimal lines of code. Unleash the power of simplicity and style in your projects!",
5
5
  "main": "index.js",
@@ -22,6 +22,7 @@ interface CustomSelectProps {
22
22
  status?: 'success' | 'warning' | 'danger' | '';
23
23
  className?: string;
24
24
  funcss?: string;
25
+ searchAutoFocus?: boolean;
25
26
  style?: React.CSSProperties;
26
27
  }
27
28
  declare const Select: React.FC<CustomSelectProps>;
@@ -35,12 +35,12 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  var react_1 = __importStar(require("react"));
37
37
  var Select = function (_a) {
38
- var id = _a.id, name = _a.name, value = _a.value, defaultValue = _a.defaultValue, _b = _a.placeholder, placeholder = _b === void 0 ? 'Select an option' : _b, _c = _a.options, options = _c === void 0 ? [] : _c, onChange = _a.onChange, onBlur = _a.onBlur, _d = _a.searchable, searchable = _d === void 0 ? true : _d, _e = _a.disabled, disabled = _e === void 0 ? false : _e, _f = _a.bordered, bordered = _f === void 0 ? false : _f, _g = _a.borderless, borderless = _g === void 0 ? false : _g, _h = _a.rounded, rounded = _h === void 0 ? false : _h, _j = _a.flat, flat = _j === void 0 ? false : _j, _k = _a.fullWidth, fullWidth = _k === void 0 ? false : _k, _l = _a.status, status = _l === void 0 ? '' : _l, _m = _a.className, className = _m === void 0 ? '' : _m, _o = _a.funcss, funcss = _o === void 0 ? '' : _o, _p = _a.style, style = _p === void 0 ? {} : _p;
39
- var _q = (0, react_1.useState)(false), isOpen = _q[0], setIsOpen = _q[1];
40
- var _r = (0, react_1.useState)(null), selectedOption = _r[0], setSelectedOption = _r[1];
41
- var _s = (0, react_1.useState)(''), searchQuery = _s[0], setSearchQuery = _s[1];
42
- var _t = (0, react_1.useState)(-1), focusedIndex = _t[0], setFocusedIndex = _t[1];
43
- var _u = (0, react_1.useState)(options), filteredOptions = _u[0], setFilteredOptions = _u[1];
38
+ var id = _a.id, name = _a.name, value = _a.value, defaultValue = _a.defaultValue, _b = _a.placeholder, placeholder = _b === void 0 ? 'Select an option' : _b, _c = _a.options, options = _c === void 0 ? [] : _c, onChange = _a.onChange, onBlur = _a.onBlur, _d = _a.searchable, searchable = _d === void 0 ? true : _d, _e = _a.disabled, disabled = _e === void 0 ? false : _e, _f = _a.bordered, bordered = _f === void 0 ? false : _f, _g = _a.borderless, borderless = _g === void 0 ? false : _g, _h = _a.rounded, rounded = _h === void 0 ? false : _h, _j = _a.flat, flat = _j === void 0 ? false : _j, _k = _a.fullWidth, fullWidth = _k === void 0 ? false : _k, _l = _a.status, status = _l === void 0 ? '' : _l, _m = _a.className, className = _m === void 0 ? '' : _m, _o = _a.funcss, funcss = _o === void 0 ? '' : _o, _p = _a.style, style = _p === void 0 ? {} : _p, _q = _a.searchAutoFocus, searchAutoFocus = _q === void 0 ? false : _q;
39
+ var _r = (0, react_1.useState)(false), isOpen = _r[0], setIsOpen = _r[1];
40
+ var _s = (0, react_1.useState)(null), selectedOption = _s[0], setSelectedOption = _s[1];
41
+ var _t = (0, react_1.useState)(''), searchQuery = _t[0], setSearchQuery = _t[1];
42
+ var _u = (0, react_1.useState)(-1), focusedIndex = _u[0], setFocusedIndex = _u[1];
43
+ var _v = (0, react_1.useState)(options), filteredOptions = _v[0], setFilteredOptions = _v[1];
44
44
  var containerRef = (0, react_1.useRef)(null);
45
45
  var triggerRef = (0, react_1.useRef)(null);
46
46
  var searchInputRef = (0, react_1.useRef)(null);
@@ -85,7 +85,9 @@ var Select = function (_a) {
85
85
  return;
86
86
  setIsOpen(true);
87
87
  if (searchable && searchInputRef.current) {
88
- setTimeout(function () { var _a; return (_a = searchInputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); }, 100);
88
+ if (searchAutoFocus) {
89
+ setTimeout(function () { var _a; return (_a = searchInputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); }, 100);
90
+ }
89
91
  }
90
92
  else if (selectedOption) {
91
93
  var index = filteredOptions.findIndex(function (opt) { return opt.value === selectedOption.value; });
@@ -0,0 +1,7 @@
1
+ interface DataConfig {
2
+ fields: string[];
3
+ }
4
+ type GetNestedValueFunction = (obj: any, path: string) => any;
5
+ export declare const getAdvancedFilteredData: <T = any>(filteredData: T[], searchQuery: string, data: DataConfig, getNestedValue: GetNestedValueFunction) => T[];
6
+ export declare const getFilteredAndPaginatedData: <T = any>(filteredData: T[], searchQuery: string, data: DataConfig, getNestedValue: GetNestedValueFunction, startIndex?: number, endIndex?: number) => T[];
7
+ export {};
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFilteredAndPaginatedData = exports.getAdvancedFilteredData = void 0;
4
+ // Simple Levenshtein distance function for fuzzy matching
5
+ var levenshteinDistance = function (str1, str2) {
6
+ var matrix = Array(str2.length + 1).fill(null).map(function () {
7
+ return Array(str1.length + 1).fill(null);
8
+ });
9
+ for (var i = 0; i <= str1.length; i++)
10
+ matrix[0][i] = i;
11
+ for (var j = 0; j <= str2.length; j++)
12
+ matrix[j][0] = j;
13
+ for (var j = 1; j <= str2.length; j++) {
14
+ for (var i = 1; i <= str1.length; i++) {
15
+ var indicator = str1[i - 1] === str2[j - 1] ? 0 : 1;
16
+ matrix[j][i] = Math.min(matrix[j][i - 1] + 1, // deletion
17
+ matrix[j - 1][i] + 1, // insertion
18
+ matrix[j - 1][i - 1] + indicator // substitution
19
+ );
20
+ }
21
+ }
22
+ return matrix[str2.length][str1.length];
23
+ };
24
+ // Define various search strategies
25
+ var searchStrategies = [
26
+ // 1. Exact substring match (your original method)
27
+ function (value, query, terms) {
28
+ return value.includes(query);
29
+ },
30
+ // 2. All terms must be present (AND search)
31
+ function (value, query, terms) {
32
+ return terms.every(function (term) { return value.includes(term); });
33
+ },
34
+ // 3. Any term must be present (OR search)
35
+ function (value, query, terms) {
36
+ return terms.some(function (term) { return value.includes(term); });
37
+ },
38
+ // 4. Alphanumeric-only search (ignores special chars)
39
+ function (value, query, terms) {
40
+ var cleanValue = value.replace(/[^a-z0-9]/g, '');
41
+ var cleanQuery = query.replace(/[^a-z0-9]/g, '');
42
+ return cleanValue.includes(cleanQuery);
43
+ },
44
+ // 5. Number extraction and matching
45
+ function (value, query, terms) {
46
+ var valueNumbers = value.match(/\d+/g) || [];
47
+ var queryNumbers = query.match(/\d+/g) || [];
48
+ return queryNumbers.some(function (queryNum) {
49
+ return valueNumbers.some(function (valueNum) { return valueNum.includes(queryNum); });
50
+ });
51
+ },
52
+ // 6. Word boundary matching (whole words)
53
+ function (value, query, terms) {
54
+ try {
55
+ var regex = new RegExp("\\b".concat(query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), "\\b"), 'i');
56
+ return regex.test(value);
57
+ }
58
+ catch (_a) {
59
+ return false;
60
+ }
61
+ },
62
+ // 7. Fuzzy matching for typos (simple Levenshtein-based)
63
+ function (value, query, terms) {
64
+ if (query.length < 3)
65
+ return false; // Skip fuzzy for very short queries
66
+ var words = value.split(/\s+/);
67
+ return words.some(function (word) {
68
+ if (Math.abs(word.length - query.length) > 2)
69
+ return false;
70
+ return levenshteinDistance(word, query) <= Math.floor(query.length * 0.3);
71
+ });
72
+ },
73
+ // 8. Prefix matching (starts with)
74
+ function (value, query, terms) {
75
+ var words = value.split(/[\s-._]+/);
76
+ return (words.some(function (word) { return word.startsWith(query); }) ||
77
+ terms.some(function (term) { return words.some(function (word) { return word.startsWith(term); }); }));
78
+ },
79
+ // 9. Suffix matching (ends with)
80
+ function (value, query, terms) {
81
+ var words = value.split(/[\s-._]+/);
82
+ return (words.some(function (word) { return word.endsWith(query); }) ||
83
+ terms.some(function (term) { return words.some(function (word) { return word.endsWith(term); }); }));
84
+ },
85
+ // 10. Pattern matching (handles common separators)
86
+ function (value, query, terms) {
87
+ // Split on common separators and search in parts
88
+ var valueParts = value.split(/[-._\s\/\\]/);
89
+ var queryParts = query.split(/[-._\s\/\\]/);
90
+ return queryParts.every(function (queryPart) {
91
+ return valueParts.some(function (valuePart) { return valuePart.includes(queryPart); });
92
+ });
93
+ },
94
+ ];
95
+ // MAIN FUNCTION: Direct replacement for your original code
96
+ var getAdvancedFilteredData = function (filteredData, searchQuery, data, getNestedValue) {
97
+ return filteredData.filter(function (mdoc, index) {
98
+ if (searchQuery) {
99
+ // Convert search query to lowercase for case-insensitive search
100
+ var query_1 = searchQuery.toLowerCase().trim();
101
+ if (!query_1)
102
+ return true; // If empty query after trim, show all
103
+ // Split query into multiple terms for multi-term search
104
+ var queryTerms_1 = query_1.split(/\s+/).filter(function (term) { return term.length > 0; });
105
+ // Search through all fields defined in data.fields
106
+ return data.fields.some(function (field) {
107
+ try {
108
+ // Get the value using the same getNestedValue function used for display
109
+ var value = getNestedValue(mdoc, field);
110
+ // Convert value to string and search
111
+ if (value !== null && value !== undefined) {
112
+ var stringValue_1 = String(value).toLowerCase();
113
+ // Use advanced search strategies instead of just includes
114
+ return searchStrategies.some(function (strategy) {
115
+ return strategy(stringValue_1, query_1, queryTerms_1);
116
+ });
117
+ }
118
+ return false;
119
+ }
120
+ catch (error) {
121
+ // Handle any errors in accessing nested values
122
+ console.warn("Error accessing field ".concat(field, ":"), error);
123
+ return false;
124
+ }
125
+ });
126
+ }
127
+ else {
128
+ return true; // If no search query, return all items
129
+ }
130
+ });
131
+ };
132
+ exports.getAdvancedFilteredData = getAdvancedFilteredData;
133
+ // Optional: Simplified version with pagination built-in
134
+ var getFilteredAndPaginatedData = function (filteredData, searchQuery, data, getNestedValue, startIndex, endIndex) {
135
+ if (startIndex === void 0) { startIndex = 0; }
136
+ var filtered = (0, exports.getAdvancedFilteredData)(filteredData, searchQuery, data, getNestedValue);
137
+ return endIndex !== undefined ? filtered.slice(startIndex, endIndex) : filtered.slice(startIndex);
138
+ };
139
+ exports.getFilteredAndPaginatedData = getFilteredAndPaginatedData;
package/ui/table/Table.js CHANGED
@@ -90,6 +90,7 @@ var Tip_1 = __importDefault(require("../tooltip/Tip"));
90
90
  var Flex_1 = __importDefault(require("../flex/Flex"));
91
91
  var ci_1 = require("react-icons/ci");
92
92
  var io5_1 = require("react-icons/io5");
93
+ var Query_1 = require("./Query");
93
94
  function Table(_a) {
94
95
  var _b, _c;
95
96
  var children = _a.children, funcss = _a.funcss, bordered = _a.bordered, noStripped = _a.noStripped, hoverable = _a.hoverable, _d = _a.title, title = _d === void 0 ? "" : _d, showTotal = _a.showTotal, light = _a.light, dark = _a.dark, head = _a.head, body = _a.body, data = _a.data, _e = _a.isLoading, isLoading = _e === void 0 ? false : _e, right = _a.right, hideExport = _a.hideExport, height = _a.height, _f = _a.pageSize, pageSize = _f === void 0 ? data ? 10 : 0 : _f, // Default page size,
@@ -202,7 +203,7 @@ function Table(_a) {
202
203
  React.createElement("div", null,
203
204
  React.createElement(Flex_1.default, { width: '100%', wrap: 'nowrap', alignItems: 'center', gap: 0.7 },
204
205
  !selectedField && !showSearch && filterableFields &&
205
- React.createElement("div", { className: '' },
206
+ React.createElement("div", { className: 'animated slide-up' },
206
207
  React.createElement(Select_1.default, { fullWidth: true, searchable: true, funcss: 'min-w-300 w-full', rounded: true, value: selectedField || '', onChange: function (e) { return handleFieldChange(e); }, options: __spreadArray([
207
208
  { text: '🔍 Filter', value: '' },
208
209
  { text: 'All*', value: '' }
@@ -236,7 +237,7 @@ function Table(_a) {
236
237
  React.createElement("div", { className: 'animated fade-in' },
237
238
  React.createElement("div", { onClick: function () { return setshowSearch(false); } },
238
239
  React.createElement(ToolTip_1.default, null,
239
- filterableFields ? React.createElement(io5_1.IoFilterOutline, null)
240
+ filterableFields ? React.createElement(io5_1.IoFilterOutline, { className: 'pointer' })
240
241
  :
241
242
  React.createElement(pi_1.PiXThin, { className: 'pointer', size: 23, onClick: function () { return setshowSearch(false); } }),
242
243
  React.createElement(Tip_1.default, { tip: "bottom", animation: "Opacity", duration: 1, content: filterableFields ? "Filter" : "Close Search" })))))
@@ -268,35 +269,33 @@ function Table(_a) {
268
269
  head && React.createElement(Head_1.default, null, head),
269
270
  body && React.createElement(Body_1.default, null, body),
270
271
  data &&
271
- filteredData.filter(function (mdoc, index) {
272
- if (searchQuery) {
273
- // Convert search query to lowercase for case-insensitive search
274
- var query_1 = searchQuery.toLowerCase().trim();
275
- if (!query_1)
276
- return true; // If empty query after trim, show all
277
- // Search through all fields defined in data.fields
278
- return data.fields.some(function (field) {
279
- try {
280
- // Get the value using the same getNestedValue function used for display
281
- var value = getNestedValue(mdoc, field);
282
- // Convert value to string and search
283
- if (value !== null && value !== undefined) {
284
- var stringValue = String(value).toLowerCase();
285
- return stringValue.includes(query_1);
286
- }
287
- return false;
288
- }
289
- catch (error) {
290
- // Handle any errors in accessing nested values
291
- console.warn("Error accessing field ".concat(field, ":"), error);
292
- return false;
293
- }
294
- });
295
- }
296
- else {
297
- return true; // If no search query, return all items
298
- }
299
- }).slice(startIndex, endIndex).map(function (mdoc, index) { return (React.createElement("tr", { className: 'animated slide-up', key: index },
272
+ // filteredData.filter((mdoc, index) => {
273
+ // if(searchQuery){
274
+ // // Convert search query to lowercase for case-insensitive search
275
+ // const query = searchQuery.toLowerCase().trim();
276
+ // if (!query) return true; // If empty query after trim, show all
277
+ // // Search through all fields defined in data.fields
278
+ // return data.fields.some(field => {
279
+ // try {
280
+ // // Get the value using the same getNestedValue function used for display
281
+ // const value = getNestedValue(mdoc, field);
282
+ // // Convert value to string and search
283
+ // if (value !== null && value !== undefined) {
284
+ // const stringValue = String(value).toLowerCase();
285
+ // return stringValue.includes(query);
286
+ // }
287
+ // return false;
288
+ // } catch (error) {
289
+ // // Handle any errors in accessing nested values
290
+ // console.warn(`Error accessing field ${field}:`, error);
291
+ // return false;
292
+ // }
293
+ // });
294
+ // } else {
295
+ // return true; // If no search query, return all items
296
+ // }
297
+ // })
298
+ (0, Query_1.getAdvancedFilteredData)(filteredData, searchQuery, data, getNestedValue).slice(startIndex, endIndex).map(function (mdoc, index) { return (React.createElement("tr", { className: 'animated slide-up', key: index },
300
299
  data.fields.map(function (fdoc, findex) {
301
300
  var _a;
302
301
  return (React.createElement(Data_1.default, { key: fdoc, funcss: data.funcss ? ((_a = data === null || data === void 0 ? void 0 : data.funcss) === null || _a === void 0 ? void 0 : _a[findex]) || '' : '' }, getNestedValue(mdoc, fdoc)));