funuicss 3.4.7 → 3.4.9
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 +1 -1
- package/ui/table/Query.d.ts +7 -0
- package/ui/table/Query.js +139 -0
- package/ui/table/Table.js +30 -31
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "3.4.
|
|
2
|
+
"version": "3.4.9",
|
|
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",
|
|
@@ -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",
|
|
206
|
+
React.createElement("div", null,
|
|
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,
|
|
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(
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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)));
|