nucleus-core-ts 0.8.6 → 0.8.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/dist/client.js +1 -1
- package/dist/dist/index.d.ts +475 -12
- package/dist/fe/components/AbstractAnimatedBackground/index.js +437 -0
- package/dist/fe/components/AuthorizationPage/components/AuthorizationPage.js +841 -0
- package/dist/fe/components/AuthorizationPage/components/ClaimList.js +100 -0
- package/dist/fe/components/AuthorizationPage/components/RoleClaimEditor.js +232 -0
- package/dist/fe/components/AuthorizationPage/components/RoleList.js +115 -0
- package/dist/fe/components/AuthorizationPage/index.js +6 -0
- package/dist/fe/components/AuthorizationPage/store/index.js +117 -0
- package/dist/fe/components/AuthorizationPage/theme/index.js +137 -0
- package/dist/fe/components/AuthorizationPage/types/index.js +1 -0
- package/dist/fe/components/Button/components/Button.js +158 -0
- package/dist/fe/components/Button/components/ButtonSpinner.js +52 -0
- package/dist/fe/components/Button/index.js +3 -0
- package/dist/fe/components/Button/theme/index.js +186 -0
- package/dist/fe/components/Button/types/index.js +1 -0
- package/dist/fe/components/Button/utils/cn.js +5 -0
- package/dist/fe/components/Captcha/components/Captcha.js +311 -0
- package/dist/fe/components/Captcha/index.js +2 -0
- package/dist/fe/components/Captcha/theme.js +52 -0
- package/dist/fe/components/Captcha/types.js +1 -0
- package/dist/fe/components/ChangePasswordPage/components/ChangePasswordForm.js +242 -0
- package/dist/fe/components/ChangePasswordPage/components/ChangePasswordHeader.js +39 -0
- package/dist/fe/components/ChangePasswordPage/components/ChangePasswordPage.js +60 -0
- package/dist/fe/components/ChangePasswordPage/index.js +5 -0
- package/dist/fe/components/ChangePasswordPage/store/index.js +44 -0
- package/dist/fe/components/ChangePasswordPage/theme/index.js +87 -0
- package/dist/fe/components/ChangePasswordPage/types/index.js +1 -0
- package/dist/fe/components/Checkbox/components/Checkbox.js +115 -0
- package/dist/fe/components/Checkbox/components/CheckboxIcon.js +119 -0
- package/dist/fe/components/Checkbox/components/SwitchTrack.js +178 -0
- package/dist/fe/components/Checkbox/index.js +4 -0
- package/dist/fe/components/Checkbox/theme/index.js +221 -0
- package/dist/fe/components/Checkbox/types/index.js +1 -0
- package/dist/fe/components/Checkbox/utils/cn.js +5 -0
- package/dist/fe/components/DataTable/DataTable.js +225 -0
- package/dist/fe/components/DataTable/components/ActionCell.js +26 -0
- package/dist/fe/components/DataTable/components/DataCell.js +76 -0
- package/dist/fe/components/DataTable/components/EditableCell.js +221 -0
- package/dist/fe/components/DataTable/components/EmptyState.js +29 -0
- package/dist/fe/components/DataTable/components/HeaderCell.js +64 -0
- package/dist/fe/components/DataTable/components/InfiniteScrollTrigger.js +66 -0
- package/dist/fe/components/DataTable/components/LoadingSpinner.js +19 -0
- package/dist/fe/components/DataTable/components/ResizeHandle.js +41 -0
- package/dist/fe/components/DataTable/components/SelectionCell.js +105 -0
- package/dist/fe/components/DataTable/components/SkeletonRow.js +56 -0
- package/dist/fe/components/DataTable/components/SkeletonTable.js +83 -0
- package/dist/fe/components/DataTable/components/SortIcon.js +39 -0
- package/dist/fe/components/DataTable/components/TableHeader.js +49 -0
- package/dist/fe/components/DataTable/components/TableRow.js +118 -0
- package/dist/fe/components/DataTable/components/index.js +14 -0
- package/dist/fe/components/DataTable/hooks/index.js +2 -0
- package/dist/fe/components/DataTable/hooks/useAutoFitColumn.js +23 -0
- package/dist/fe/components/DataTable/hooks/useResizeColumn.js +122 -0
- package/dist/fe/components/DataTable/index.js +3 -0
- package/dist/fe/components/DataTable/store/index.js +97 -0
- package/dist/fe/components/DataTable/theme/index.js +144 -0
- package/dist/fe/components/DataTable/types/index.js +1 -0
- package/dist/fe/components/DataTable/utils/cn.js +5 -0
- package/dist/fe/components/DatePicker/components/CalendarGrid.js +95 -0
- package/dist/fe/components/DatePicker/components/CalendarHeader.js +152 -0
- package/dist/fe/components/DatePicker/components/DatePicker.js +381 -0
- package/dist/fe/components/DatePicker/components/MonthYearSelector.js +93 -0
- package/dist/fe/components/DatePicker/index.js +7 -0
- package/dist/fe/components/DatePicker/locales/index.js +1113 -0
- package/dist/fe/components/DatePicker/theme/index.js +315 -0
- package/dist/fe/components/DatePicker/types/index.js +1 -0
- package/dist/fe/components/DatePicker/utils/cn.js +5 -0
- package/dist/fe/components/DatePicker/utils/date.js +132 -0
- package/dist/fe/components/DevicesPage/components/DeviceCard.js +251 -0
- package/dist/fe/components/DevicesPage/components/DevicesHeader.js +42 -0
- package/dist/fe/components/DevicesPage/components/DevicesPage.js +450 -0
- package/dist/fe/components/DevicesPage/index.js +5 -0
- package/dist/fe/components/DevicesPage/store/index.js +55 -0
- package/dist/fe/components/DevicesPage/theme/index.js +131 -0
- package/dist/fe/components/DevicesPage/types/index.js +1 -0
- package/dist/fe/components/ForgotPasswordPage/components/ForgotPasswordForm.js +214 -0
- package/dist/fe/components/ForgotPasswordPage/components/ForgotPasswordHeader.js +42 -0
- package/dist/fe/components/ForgotPasswordPage/components/ForgotPasswordPage.js +59 -0
- package/dist/fe/components/ForgotPasswordPage/index.js +5 -0
- package/dist/fe/components/ForgotPasswordPage/store/index.js +28 -0
- package/dist/fe/components/ForgotPasswordPage/theme/index.js +87 -0
- package/dist/fe/components/ForgotPasswordPage/types/index.js +1 -0
- package/dist/fe/components/FormBuilder/components/FormBuilder.js +156 -0
- package/dist/fe/components/FormBuilder/components/FormField.js +218 -0
- package/dist/fe/components/FormBuilder/hooks/useFormBuilder.js +152 -0
- package/dist/fe/components/FormBuilder/index.js +4 -0
- package/dist/fe/components/FormBuilder/theme/index.js +134 -0
- package/dist/fe/components/FormBuilder/types/index.js +1 -0
- package/dist/fe/components/FormBuilder/utils/cn.js +5 -0
- package/dist/fe/components/FormBuilder/utils/fieldMapping.js +216 -0
- package/dist/fe/components/FormBuilder/utils/validation.js +78 -0
- package/dist/fe/components/LoginPage/components/LoginForm.js +214 -0
- package/dist/fe/components/LoginPage/components/LoginHeader.js +24 -0
- package/dist/fe/components/LoginPage/components/LoginPage.js +138 -0
- package/dist/fe/components/LoginPage/index.js +5 -0
- package/dist/fe/components/LoginPage/store/index.js +59 -0
- package/dist/fe/components/LoginPage/theme/index.js +98 -0
- package/dist/fe/components/LoginPage/types/index.js +1 -0
- package/dist/fe/components/MagicLinkVerifyPage/components/MagicLinkVerifyPage.js +200 -0
- package/dist/fe/components/MagicLinkVerifyPage/index.js +3 -0
- package/dist/fe/components/MagicLinkVerifyPage/store.js +20 -0
- package/dist/fe/components/MagicLinkVerifyPage/theme.js +36 -0
- package/dist/fe/components/MagicLinkVerifyPage/types.js +1 -0
- package/dist/fe/components/NucleusEntityShowcase.js +1409 -0
- package/dist/fe/components/NucleusTextInput/components/FloatingLabel.js +56 -0
- package/dist/fe/components/NucleusTextInput/components/InputIcons.js +258 -0
- package/dist/fe/components/NucleusTextInput/components/NucleusTextInput.js +321 -0
- package/dist/fe/components/NucleusTextInput/components/PasswordStrengthIndicator.js +104 -0
- package/dist/fe/components/NucleusTextInput/components/TypewriterText.js +56 -0
- package/dist/fe/components/NucleusTextInput/index.js +7 -0
- package/dist/fe/components/NucleusTextInput/theme/index.js +121 -0
- package/dist/fe/components/NucleusTextInput/types/index.js +1 -0
- package/dist/fe/components/NucleusTextInput/utils/cn.js +5 -0
- package/dist/fe/components/NucleusTextInput/utils/format.js +62 -0
- package/dist/fe/components/NucleusTextInput/utils/validation.js +191 -0
- package/dist/fe/components/ProfilePage/components/AddressCard.js +196 -0
- package/dist/fe/components/ProfilePage/components/PhoneCard.js +206 -0
- package/dist/fe/components/ProfilePage/components/ProfileHeader.js +150 -0
- package/dist/fe/components/ProfilePage/components/ProfilePage.js +1336 -0
- package/dist/fe/components/ProfilePage/index.js +6 -0
- package/dist/fe/components/ProfilePage/store/index.js +115 -0
- package/dist/fe/components/ProfilePage/theme/index.js +168 -0
- package/dist/fe/components/ProfilePage/types/index.js +1 -0
- package/dist/fe/components/RangePicker/components/RangePicker.js +338 -0
- package/dist/fe/components/RangePicker/components/RangeThumb.js +68 -0
- package/dist/fe/components/RangePicker/components/RangeTooltip.js +45 -0
- package/dist/fe/components/RangePicker/components/RangeTrack.js +32 -0
- package/dist/fe/components/RangePicker/index.js +5 -0
- package/dist/fe/components/RangePicker/theme/index.js +88 -0
- package/dist/fe/components/RangePicker/types/index.js +1 -0
- package/dist/fe/components/RangePicker/utils/cn.js +3 -0
- package/dist/fe/components/RegisterPage/components/PasswordStrengthIndicator.js +107 -0
- package/dist/fe/components/RegisterPage/components/RegisterForm.js +322 -0
- package/dist/fe/components/RegisterPage/components/RegisterHeader.js +23 -0
- package/dist/fe/components/RegisterPage/components/RegisterPage.js +85 -0
- package/dist/fe/components/RegisterPage/index.js +6 -0
- package/dist/fe/components/RegisterPage/store/index.js +106 -0
- package/dist/fe/components/RegisterPage/theme/index.js +128 -0
- package/dist/fe/components/RegisterPage/types/index.js +1 -0
- package/dist/fe/components/ResetPasswordPage/components/ResetPasswordForm.js +347 -0
- package/dist/fe/components/ResetPasswordPage/components/ResetPasswordHeader.js +42 -0
- package/dist/fe/components/ResetPasswordPage/components/ResetPasswordPage.js +61 -0
- package/dist/fe/components/ResetPasswordPage/index.js +5 -0
- package/dist/fe/components/ResetPasswordPage/store/index.js +36 -0
- package/dist/fe/components/ResetPasswordPage/theme/index.js +99 -0
- package/dist/fe/components/ResetPasswordPage/types/index.js +1 -0
- package/dist/fe/components/SearchBox/components/SearchBox.js +271 -0
- package/dist/fe/components/SearchBox/components/SearchBoxDropdown.js +87 -0
- package/dist/fe/components/SearchBox/index.js +5 -0
- package/dist/fe/components/SearchBox/theme/index.js +184 -0
- package/dist/fe/components/SearchBox/types/index.js +1 -0
- package/dist/fe/components/SearchBox/utils/cn.js +5 -0
- package/dist/fe/components/SearchBox/utils/debounce.js +22 -0
- package/dist/fe/components/SearchBox/utils/sanitize.js +48 -0
- package/dist/fe/components/SelectBox/components/SelectBox.js +364 -0
- package/dist/fe/components/SelectBox/components/SelectDropdown.js +92 -0
- package/dist/fe/components/SelectBox/components/SelectOptionItem.js +43 -0
- package/dist/fe/components/SelectBox/components/SelectTrigger.js +22 -0
- package/dist/fe/components/SelectBox/index.js +5 -0
- package/dist/fe/components/SelectBox/theme/index.js +98 -0
- package/dist/fe/components/SelectBox/types/index.js +1 -0
- package/dist/fe/components/SelectBox/utils/cn.js +3 -0
- package/dist/fe/components/SetPasswordPage/components/PasswordStrengthIndicator.js +107 -0
- package/dist/fe/components/SetPasswordPage/components/SetPasswordForm.js +142 -0
- package/dist/fe/components/SetPasswordPage/components/SetPasswordHeader.js +23 -0
- package/dist/fe/components/SetPasswordPage/components/SetPasswordPage.js +263 -0
- package/dist/fe/components/SetPasswordPage/index.js +7 -0
- package/dist/fe/components/SetPasswordPage/store/index.js +79 -0
- package/dist/fe/components/SetPasswordPage/theme/index.js +98 -0
- package/dist/fe/components/SetPasswordPage/types/index.js +12 -0
- package/dist/fe/components/UsersPage/components/InviteUserModal.js +262 -0
- package/dist/fe/components/UsersPage/components/Pagination.js +147 -0
- package/dist/fe/components/UsersPage/components/RoleAssignmentModal.js +186 -0
- package/dist/fe/components/UsersPage/components/StatsCards.js +124 -0
- package/dist/fe/components/UsersPage/components/UserDetailDrawer.js +444 -0
- package/dist/fe/components/UsersPage/components/UserFilters.js +142 -0
- package/dist/fe/components/UsersPage/components/UserListItem.js +125 -0
- package/dist/fe/components/UsersPage/components/UserListSkeleton.js +40 -0
- package/dist/fe/components/UsersPage/components/UsersPage.js +556 -0
- package/dist/fe/components/UsersPage/index.js +10 -0
- package/dist/fe/components/UsersPage/store/index.js +151 -0
- package/dist/fe/components/UsersPage/theme/index.js +231 -0
- package/dist/fe/components/UsersPage/types/index.js +1 -0
- package/dist/fe/components/VerifyEmailPage/components/VerifyEmailPage.js +290 -0
- package/dist/fe/components/VerifyEmailPage/index.js +3 -0
- package/dist/fe/components/VerifyEmailPage/store/index.js +45 -0
- package/dist/fe/components/VerifyEmailPage/theme/index.js +52 -0
- package/dist/fe/components/VerifyEmailPage/types/index.js +1 -0
- package/dist/fe/hooks/useNucleusEntity.js +247 -0
- package/dist/fe/index.js +28 -110
- package/dist/fe/types/index.js +1 -0
- package/dist/fe/utils/cn.js +5 -0
- package/dist/fe/utils/columnUtils.js +189 -0
- package/dist/fe/utils/endpointKeys.js +44 -0
- package/dist/index.js +1 -1
- package/dist/nucleus.config.d.ts +3 -0
- package/dist/src/Client/Proxy/httpProxy.js +1 -0
- package/dist/src/Client/Proxy/index.js +1 -1
- package/dist/src/Client/Proxy/server.js +1 -0
- package/dist/src/Client/Proxy/types.js +1 -0
- package/dist/src/Client/Proxy/utils.js +1 -0
- package/dist/src/Client/Proxy/wsProxy.js +1 -0
- package/package.json +1 -1
- package/scripts/build.ts +78 -8
- package/dist/dist/index-0yyw12k6.d.ts +0 -8
- package/dist/dist/index-tv67j5qd.d.ts +0 -488
- package/dist/index-0yyw12k6.js +0 -1
- package/dist/index-tv67j5qd.js +0 -1
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useGSAP } from "@gsap/react";
|
|
4
|
+
import gsap from "gsap";
|
|
5
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
6
|
+
import { searchBoxTheme } from "../theme";
|
|
7
|
+
import { cn } from "../utils/cn";
|
|
8
|
+
import { debounce } from "../utils/debounce";
|
|
9
|
+
import { sanitizeSearchQuery } from "../utils/sanitize";
|
|
10
|
+
import { SearchBoxDropdown } from "./SearchBoxDropdown";
|
|
11
|
+
gsap.registerPlugin(useGSAP);
|
|
12
|
+
export function SearchBox({ value, onChange, onSearch, results, renderItem, onSelect, placeholder = "Search...", label, debounceMs = 300, minSearchLength = 1, disabled = false, loading = false, emptyMessage = "No results found", className, inputClassName, dropdownClassName, itemClassName, showClearButton = true, leftIcon, rightIcon, disableDropdown = false, showSearchIcon = true, maxLength = 200, sanitize = true, trimOnSearch = true, preventXSS = true }) {
|
|
13
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
14
|
+
const [activeIndex, setActiveIndex] = useState(-1);
|
|
15
|
+
const [dropdownPosition, setDropdownPosition] = useState("bottom");
|
|
16
|
+
const inputRef = useRef(null);
|
|
17
|
+
const wrapperRef = useRef(null);
|
|
18
|
+
const containerRef = useRef(null);
|
|
19
|
+
const debounceRef = useRef(null);
|
|
20
|
+
const onSearchRef = useRef(onSearch);
|
|
21
|
+
const inputId = useId();
|
|
22
|
+
onSearchRef.current = onSearch;
|
|
23
|
+
const theme = searchBoxTheme;
|
|
24
|
+
const showDropdown = !disableDropdown && isFocused && results !== undefined && results.length >= 0 && value.length >= minSearchLength;
|
|
25
|
+
const { contextSafe } = useGSAP({
|
|
26
|
+
scope: wrapperRef
|
|
27
|
+
});
|
|
28
|
+
useEffect(()=>{
|
|
29
|
+
debounceRef.current = debounce((query)=>{
|
|
30
|
+
if (query.length >= minSearchLength || query.length === 0) {
|
|
31
|
+
const sanitizedQuery = sanitize ? sanitizeSearchQuery(query, {
|
|
32
|
+
trim: trimOnSearch,
|
|
33
|
+
escapeHtml: preventXSS,
|
|
34
|
+
maxLength,
|
|
35
|
+
removeScripts: true
|
|
36
|
+
}) : query;
|
|
37
|
+
onSearchRef.current(sanitizedQuery);
|
|
38
|
+
}
|
|
39
|
+
}, debounceMs);
|
|
40
|
+
return ()=>{
|
|
41
|
+
debounceRef.current?.cancel();
|
|
42
|
+
};
|
|
43
|
+
}, [
|
|
44
|
+
debounceMs,
|
|
45
|
+
minSearchLength,
|
|
46
|
+
sanitize,
|
|
47
|
+
trimOnSearch,
|
|
48
|
+
preventXSS,
|
|
49
|
+
maxLength
|
|
50
|
+
]);
|
|
51
|
+
useEffect(()=>{
|
|
52
|
+
if (!showDropdown) return;
|
|
53
|
+
const updatePosition = ()=>{
|
|
54
|
+
if (!containerRef.current) return;
|
|
55
|
+
const rect = containerRef.current.getBoundingClientRect();
|
|
56
|
+
const spaceBelow = window.innerHeight - rect.bottom;
|
|
57
|
+
const spaceAbove = rect.top;
|
|
58
|
+
const dropdownHeight = 256;
|
|
59
|
+
if (spaceBelow < dropdownHeight && spaceAbove > spaceBelow) {
|
|
60
|
+
setDropdownPosition("top");
|
|
61
|
+
} else {
|
|
62
|
+
setDropdownPosition("bottom");
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
updatePosition();
|
|
66
|
+
window.addEventListener("scroll", updatePosition, true);
|
|
67
|
+
window.addEventListener("resize", updatePosition);
|
|
68
|
+
return ()=>{
|
|
69
|
+
window.removeEventListener("scroll", updatePosition, true);
|
|
70
|
+
window.removeEventListener("resize", updatePosition);
|
|
71
|
+
};
|
|
72
|
+
}, [
|
|
73
|
+
showDropdown
|
|
74
|
+
]);
|
|
75
|
+
useEffect(()=>{
|
|
76
|
+
setActiveIndex(-1);
|
|
77
|
+
}, [
|
|
78
|
+
results
|
|
79
|
+
]);
|
|
80
|
+
const handleFocus = contextSafe(()=>{
|
|
81
|
+
if (disabled) return;
|
|
82
|
+
setIsFocused(true);
|
|
83
|
+
if (wrapperRef.current) {
|
|
84
|
+
gsap.to(wrapperRef.current, {
|
|
85
|
+
scale: 1.01,
|
|
86
|
+
duration: 0.15,
|
|
87
|
+
ease: "power2.out"
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
const handleBlur = contextSafe(()=>{
|
|
92
|
+
setTimeout(()=>{
|
|
93
|
+
setIsFocused(false);
|
|
94
|
+
setActiveIndex(-1);
|
|
95
|
+
}, 150);
|
|
96
|
+
if (wrapperRef.current) {
|
|
97
|
+
gsap.to(wrapperRef.current, {
|
|
98
|
+
scale: 1,
|
|
99
|
+
duration: 0.15,
|
|
100
|
+
ease: "power2.out"
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
const handleChange = (e)=>{
|
|
105
|
+
const newValue = e.target.value;
|
|
106
|
+
onChange(newValue);
|
|
107
|
+
debounceRef.current?.call(newValue);
|
|
108
|
+
};
|
|
109
|
+
const handleClear = contextSafe(()=>{
|
|
110
|
+
onChange("");
|
|
111
|
+
debounceRef.current?.call("");
|
|
112
|
+
inputRef.current?.focus();
|
|
113
|
+
if (wrapperRef.current) {
|
|
114
|
+
gsap.fromTo(wrapperRef.current, {
|
|
115
|
+
scale: 0.98
|
|
116
|
+
}, {
|
|
117
|
+
scale: 1,
|
|
118
|
+
duration: 0.2,
|
|
119
|
+
ease: "elastic.out(1, 0.5)"
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
const handleKeyDown = (e)=>{
|
|
124
|
+
if (!results || results.length === 0) return;
|
|
125
|
+
switch(e.key){
|
|
126
|
+
case "ArrowDown":
|
|
127
|
+
e.preventDefault();
|
|
128
|
+
setActiveIndex((prev)=>prev < results.length - 1 ? prev + 1 : 0);
|
|
129
|
+
break;
|
|
130
|
+
case "ArrowUp":
|
|
131
|
+
e.preventDefault();
|
|
132
|
+
setActiveIndex((prev)=>prev > 0 ? prev - 1 : results.length - 1);
|
|
133
|
+
break;
|
|
134
|
+
case "Enter":
|
|
135
|
+
{
|
|
136
|
+
e.preventDefault();
|
|
137
|
+
const selectedItem = results[activeIndex];
|
|
138
|
+
if (activeIndex >= 0 && activeIndex < results.length && selectedItem) {
|
|
139
|
+
handleSelect(selectedItem);
|
|
140
|
+
}
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
case "Escape":
|
|
144
|
+
e.preventDefault();
|
|
145
|
+
setIsFocused(false);
|
|
146
|
+
inputRef.current?.blur();
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
const handleSelect = (item)=>{
|
|
151
|
+
onSelect?.(item);
|
|
152
|
+
setIsFocused(false);
|
|
153
|
+
setActiveIndex(-1);
|
|
154
|
+
};
|
|
155
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
156
|
+
ref: containerRef,
|
|
157
|
+
className: cn(theme.container.base, theme.container.spacing, className),
|
|
158
|
+
children: [
|
|
159
|
+
label && /*#__PURE__*/ _jsx("label", {
|
|
160
|
+
htmlFor: inputId,
|
|
161
|
+
className: cn(theme.label.base, theme.label.text.size, theme.label.text.color.light, theme.label.text.color.dark, theme.label.spacing),
|
|
162
|
+
children: label
|
|
163
|
+
}),
|
|
164
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
165
|
+
className: "relative",
|
|
166
|
+
children: [
|
|
167
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
168
|
+
ref: wrapperRef,
|
|
169
|
+
className: cn(theme.wrapper.base, theme.wrapper.border.base, theme.wrapper.background.light, theme.wrapper.background.dark, theme.wrapper.padding.md, theme.wrapper.rounded, theme.wrapper.shadow, theme.wrapper.transition, isFocused && theme.wrapper.border.focused, disabled && theme.wrapper.border.disabled),
|
|
170
|
+
children: [
|
|
171
|
+
(leftIcon || showSearchIcon) && /*#__PURE__*/ _jsx("span", {
|
|
172
|
+
className: cn(theme.icon.base, theme.icon.size.md, theme.icon.color.light, theme.icon.color.dark, theme.icon.spacing.left, isFocused && theme.icon.color.focused),
|
|
173
|
+
children: leftIcon || /*#__PURE__*/ _jsxs("svg", {
|
|
174
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
175
|
+
viewBox: "0 0 24 24",
|
|
176
|
+
fill: "none",
|
|
177
|
+
stroke: "currentColor",
|
|
178
|
+
strokeWidth: "2",
|
|
179
|
+
strokeLinecap: "round",
|
|
180
|
+
strokeLinejoin: "round",
|
|
181
|
+
className: "w-full h-full",
|
|
182
|
+
"aria-hidden": "true",
|
|
183
|
+
children: [
|
|
184
|
+
/*#__PURE__*/ _jsx("circle", {
|
|
185
|
+
cx: "11",
|
|
186
|
+
cy: "11",
|
|
187
|
+
r: "8"
|
|
188
|
+
}),
|
|
189
|
+
/*#__PURE__*/ _jsx("path", {
|
|
190
|
+
d: "m21 21-4.3-4.3"
|
|
191
|
+
})
|
|
192
|
+
]
|
|
193
|
+
})
|
|
194
|
+
}),
|
|
195
|
+
/*#__PURE__*/ _jsx("input", {
|
|
196
|
+
ref: inputRef,
|
|
197
|
+
id: inputId,
|
|
198
|
+
type: "text",
|
|
199
|
+
value: value,
|
|
200
|
+
onChange: handleChange,
|
|
201
|
+
onFocus: handleFocus,
|
|
202
|
+
onBlur: handleBlur,
|
|
203
|
+
onKeyDown: handleKeyDown,
|
|
204
|
+
disabled: disabled,
|
|
205
|
+
placeholder: placeholder,
|
|
206
|
+
maxLength: maxLength,
|
|
207
|
+
autoComplete: "off",
|
|
208
|
+
spellCheck: false,
|
|
209
|
+
autoCapitalize: "off",
|
|
210
|
+
autoCorrect: "off",
|
|
211
|
+
"aria-label": label || placeholder,
|
|
212
|
+
role: "combobox",
|
|
213
|
+
"aria-expanded": showDropdown,
|
|
214
|
+
"aria-autocomplete": "list",
|
|
215
|
+
"aria-haspopup": "listbox",
|
|
216
|
+
className: cn(theme.input.base, theme.input.text.size, theme.input.text.color.light, theme.input.text.color.dark, theme.input.placeholder.light, theme.input.placeholder.dark, inputClassName)
|
|
217
|
+
}),
|
|
218
|
+
showClearButton && value && /*#__PURE__*/ _jsx("button", {
|
|
219
|
+
type: "button",
|
|
220
|
+
onClick: handleClear,
|
|
221
|
+
className: cn(theme.clearButton.base, theme.clearButton.size, theme.clearButton.color.light, theme.clearButton.color.dark, theme.clearButton.color.hover, theme.clearButton.transition),
|
|
222
|
+
"aria-label": "Clear search",
|
|
223
|
+
children: /*#__PURE__*/ _jsxs("svg", {
|
|
224
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
225
|
+
viewBox: "0 0 24 24",
|
|
226
|
+
fill: "none",
|
|
227
|
+
stroke: "currentColor",
|
|
228
|
+
strokeWidth: "2",
|
|
229
|
+
strokeLinecap: "round",
|
|
230
|
+
strokeLinejoin: "round",
|
|
231
|
+
className: "w-full h-full",
|
|
232
|
+
"aria-hidden": "true",
|
|
233
|
+
children: [
|
|
234
|
+
/*#__PURE__*/ _jsx("line", {
|
|
235
|
+
x1: "18",
|
|
236
|
+
y1: "6",
|
|
237
|
+
x2: "6",
|
|
238
|
+
y2: "18"
|
|
239
|
+
}),
|
|
240
|
+
/*#__PURE__*/ _jsx("line", {
|
|
241
|
+
x1: "6",
|
|
242
|
+
y1: "6",
|
|
243
|
+
x2: "18",
|
|
244
|
+
y2: "18"
|
|
245
|
+
})
|
|
246
|
+
]
|
|
247
|
+
})
|
|
248
|
+
}),
|
|
249
|
+
rightIcon && /*#__PURE__*/ _jsx("span", {
|
|
250
|
+
className: cn(theme.icon.base, theme.icon.size.md, theme.icon.color.light, theme.icon.color.dark, theme.icon.spacing.right, isFocused && theme.icon.color.focused),
|
|
251
|
+
children: rightIcon
|
|
252
|
+
})
|
|
253
|
+
]
|
|
254
|
+
}),
|
|
255
|
+
showDropdown && /*#__PURE__*/ _jsx(SearchBoxDropdown, {
|
|
256
|
+
results: results,
|
|
257
|
+
renderItem: renderItem,
|
|
258
|
+
onSelect: handleSelect,
|
|
259
|
+
loading: loading,
|
|
260
|
+
emptyMessage: emptyMessage,
|
|
261
|
+
className: dropdownClassName,
|
|
262
|
+
itemClassName: itemClassName,
|
|
263
|
+
position: dropdownPosition,
|
|
264
|
+
activeIndex: activeIndex,
|
|
265
|
+
onActiveIndexChange: setActiveIndex
|
|
266
|
+
})
|
|
267
|
+
]
|
|
268
|
+
})
|
|
269
|
+
]
|
|
270
|
+
});
|
|
271
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useGSAP } from "@gsap/react";
|
|
4
|
+
import gsap from "gsap";
|
|
5
|
+
import { useRef } from "react";
|
|
6
|
+
import { searchBoxTheme } from "../theme";
|
|
7
|
+
import { cn } from "../utils/cn";
|
|
8
|
+
gsap.registerPlugin(useGSAP);
|
|
9
|
+
export function SearchBoxDropdown({ results, renderItem, onSelect, loading = false, emptyMessage = "No results found", className, itemClassName, position, activeIndex, onActiveIndexChange }) {
|
|
10
|
+
const dropdownRef = useRef(null);
|
|
11
|
+
const theme = searchBoxTheme;
|
|
12
|
+
useGSAP(()=>{
|
|
13
|
+
if (!dropdownRef.current) return;
|
|
14
|
+
gsap.fromTo(dropdownRef.current, {
|
|
15
|
+
opacity: 0,
|
|
16
|
+
y: position === "bottom" ? -8 : 8,
|
|
17
|
+
scale: 0.98
|
|
18
|
+
}, {
|
|
19
|
+
opacity: 1,
|
|
20
|
+
y: 0,
|
|
21
|
+
scale: 1,
|
|
22
|
+
duration: 0.2,
|
|
23
|
+
ease: "power2.out"
|
|
24
|
+
});
|
|
25
|
+
}, [
|
|
26
|
+
position
|
|
27
|
+
]);
|
|
28
|
+
const handleItemClick = (item)=>{
|
|
29
|
+
onSelect?.(item);
|
|
30
|
+
};
|
|
31
|
+
const handleItemMouseEnter = (index)=>{
|
|
32
|
+
onActiveIndexChange(index);
|
|
33
|
+
};
|
|
34
|
+
const defaultRenderItem = (item)=>/*#__PURE__*/ _jsx("span", {
|
|
35
|
+
children: String(item.data)
|
|
36
|
+
});
|
|
37
|
+
if (loading) {
|
|
38
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
39
|
+
className: cn(theme.dropdown.base, theme.dropdown.background.light, theme.dropdown.background.dark, theme.dropdown.border.light, theme.dropdown.border.dark, theme.dropdown.rounded, theme.dropdown.shadow, position === "top" && theme.dropdown.position.top, position === "top" && theme.dropdown.spacing.top, position === "bottom" && theme.dropdown.position.bottom, position === "bottom" && theme.dropdown.spacing.bottom, className),
|
|
40
|
+
children: /*#__PURE__*/ _jsx("div", {
|
|
41
|
+
className: theme.loading.base,
|
|
42
|
+
children: /*#__PURE__*/ _jsxs("svg", {
|
|
43
|
+
className: cn(theme.loading.size, theme.loading.color, "animate-spin"),
|
|
44
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
45
|
+
fill: "none",
|
|
46
|
+
viewBox: "0 0 24 24",
|
|
47
|
+
"aria-hidden": "true",
|
|
48
|
+
children: [
|
|
49
|
+
/*#__PURE__*/ _jsx("circle", {
|
|
50
|
+
className: "opacity-25",
|
|
51
|
+
cx: "12",
|
|
52
|
+
cy: "12",
|
|
53
|
+
r: "10",
|
|
54
|
+
stroke: "currentColor",
|
|
55
|
+
strokeWidth: "4"
|
|
56
|
+
}),
|
|
57
|
+
/*#__PURE__*/ _jsx("path", {
|
|
58
|
+
className: "opacity-75",
|
|
59
|
+
fill: "currentColor",
|
|
60
|
+
d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
|
61
|
+
})
|
|
62
|
+
]
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (results.length === 0) {
|
|
68
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
69
|
+
className: cn(theme.dropdown.base, theme.dropdown.background.light, theme.dropdown.background.dark, theme.dropdown.border.light, theme.dropdown.border.dark, theme.dropdown.rounded, theme.dropdown.shadow, position === "top" && theme.dropdown.position.top, position === "top" && theme.dropdown.spacing.top, position === "bottom" && theme.dropdown.position.bottom, position === "bottom" && theme.dropdown.spacing.bottom, className),
|
|
70
|
+
children: /*#__PURE__*/ _jsx("div", {
|
|
71
|
+
className: cn(theme.empty.base, theme.empty.text.size, theme.empty.text.color.light, theme.empty.text.color.dark, theme.empty.padding),
|
|
72
|
+
children: emptyMessage
|
|
73
|
+
})
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
77
|
+
ref: dropdownRef,
|
|
78
|
+
className: cn(theme.dropdown.base, theme.dropdown.background.light, theme.dropdown.background.dark, theme.dropdown.border.light, theme.dropdown.border.dark, theme.dropdown.rounded, theme.dropdown.shadow, theme.dropdown.maxHeight, position === "top" && theme.dropdown.position.top, position === "top" && theme.dropdown.spacing.top, position === "bottom" && theme.dropdown.position.bottom, position === "bottom" && theme.dropdown.spacing.bottom, className),
|
|
79
|
+
children: results.map((item, index)=>/*#__PURE__*/ _jsx("button", {
|
|
80
|
+
type: "button",
|
|
81
|
+
onClick: ()=>handleItemClick(item),
|
|
82
|
+
onMouseEnter: ()=>handleItemMouseEnter(index),
|
|
83
|
+
className: cn("w-full text-left", theme.item.base, theme.item.padding, theme.item.text.size, theme.item.text.color.light, theme.item.text.color.dark, theme.item.hover.light, theme.item.hover.dark, theme.item.transition, theme.item.rounded, activeIndex === index && theme.item.active.light, activeIndex === index && theme.item.active.dark, itemClassName),
|
|
84
|
+
children: renderItem ? renderItem(item, index) : defaultRenderItem(item)
|
|
85
|
+
}, item.id))
|
|
86
|
+
});
|
|
87
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { SearchBox } from "./components/SearchBox";
|
|
2
|
+
export { SearchBoxDropdown } from "./components/SearchBoxDropdown";
|
|
3
|
+
export { extendSearchBoxTheme, searchBoxTheme } from "./theme";
|
|
4
|
+
export { debounce } from "./utils/debounce";
|
|
5
|
+
export { escapeHtml, sanitizeInput, sanitizeSearchQuery } from "./utils/sanitize";
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
export const searchBoxTheme = {
|
|
2
|
+
container: {
|
|
3
|
+
base: "relative flex flex-col",
|
|
4
|
+
spacing: "gap-1"
|
|
5
|
+
},
|
|
6
|
+
wrapper: {
|
|
7
|
+
base: "relative flex items-center w-full",
|
|
8
|
+
border: {
|
|
9
|
+
base: "border border-gray-300 dark:border-gray-600",
|
|
10
|
+
focused: "border-blue-500 dark:border-blue-400 ring-2 ring-blue-500/20",
|
|
11
|
+
error: "border-red-500 dark:border-red-400",
|
|
12
|
+
disabled: "border-gray-200 dark:border-gray-700"
|
|
13
|
+
},
|
|
14
|
+
background: {
|
|
15
|
+
light: "bg-white",
|
|
16
|
+
dark: "dark:bg-gray-800"
|
|
17
|
+
},
|
|
18
|
+
padding: {
|
|
19
|
+
sm: "px-3 py-2",
|
|
20
|
+
md: "px-4 py-3",
|
|
21
|
+
lg: "px-5 py-4"
|
|
22
|
+
},
|
|
23
|
+
rounded: "rounded-lg",
|
|
24
|
+
shadow: "shadow-sm",
|
|
25
|
+
transition: "transition-all duration-200 ease-out"
|
|
26
|
+
},
|
|
27
|
+
input: {
|
|
28
|
+
base: "flex-1 bg-transparent border-none outline-none w-full",
|
|
29
|
+
text: {
|
|
30
|
+
size: "text-base",
|
|
31
|
+
color: {
|
|
32
|
+
light: "text-gray-900",
|
|
33
|
+
dark: "dark:text-white"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
placeholder: {
|
|
37
|
+
light: "placeholder:text-gray-400",
|
|
38
|
+
dark: "dark:placeholder:text-gray-500"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
label: {
|
|
42
|
+
base: "block",
|
|
43
|
+
text: {
|
|
44
|
+
size: "text-sm font-medium",
|
|
45
|
+
color: {
|
|
46
|
+
light: "text-gray-700",
|
|
47
|
+
dark: "dark:text-gray-300"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
spacing: "mb-1.5"
|
|
51
|
+
},
|
|
52
|
+
icon: {
|
|
53
|
+
base: "flex items-center justify-center flex-shrink-0",
|
|
54
|
+
size: {
|
|
55
|
+
sm: "w-4 h-4",
|
|
56
|
+
md: "w-5 h-5",
|
|
57
|
+
lg: "w-6 h-6"
|
|
58
|
+
},
|
|
59
|
+
color: {
|
|
60
|
+
light: "text-gray-400",
|
|
61
|
+
dark: "dark:text-gray-500",
|
|
62
|
+
focused: "text-blue-500 dark:text-blue-400"
|
|
63
|
+
},
|
|
64
|
+
spacing: {
|
|
65
|
+
left: "mr-3",
|
|
66
|
+
right: "ml-3"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
clearButton: {
|
|
70
|
+
base: "flex items-center justify-center cursor-pointer",
|
|
71
|
+
size: "w-5 h-5",
|
|
72
|
+
color: {
|
|
73
|
+
light: "text-gray-400",
|
|
74
|
+
dark: "dark:text-gray-500",
|
|
75
|
+
hover: "hover:text-gray-600 dark:hover:text-gray-300"
|
|
76
|
+
},
|
|
77
|
+
transition: "transition-colors duration-150"
|
|
78
|
+
},
|
|
79
|
+
dropdown: {
|
|
80
|
+
base: "absolute left-0 right-0 z-50 overflow-hidden",
|
|
81
|
+
background: {
|
|
82
|
+
light: "bg-white",
|
|
83
|
+
dark: "dark:bg-gray-800"
|
|
84
|
+
},
|
|
85
|
+
border: {
|
|
86
|
+
light: "border border-gray-200",
|
|
87
|
+
dark: "dark:border-gray-700"
|
|
88
|
+
},
|
|
89
|
+
rounded: "rounded-lg",
|
|
90
|
+
shadow: "shadow-lg",
|
|
91
|
+
maxHeight: "max-h-64 overflow-y-auto",
|
|
92
|
+
spacing: {
|
|
93
|
+
top: "mb-2",
|
|
94
|
+
bottom: "mt-2"
|
|
95
|
+
},
|
|
96
|
+
position: {
|
|
97
|
+
top: "bottom-full",
|
|
98
|
+
bottom: "top-full"
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
item: {
|
|
102
|
+
base: "cursor-pointer",
|
|
103
|
+
padding: "px-4 py-3",
|
|
104
|
+
text: {
|
|
105
|
+
size: "text-base",
|
|
106
|
+
color: {
|
|
107
|
+
light: "text-gray-900",
|
|
108
|
+
dark: "dark:text-white"
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
hover: {
|
|
112
|
+
light: "hover:bg-gray-50",
|
|
113
|
+
dark: "dark:hover:bg-gray-700"
|
|
114
|
+
},
|
|
115
|
+
active: {
|
|
116
|
+
light: "bg-blue-50",
|
|
117
|
+
dark: "dark:bg-blue-900/30"
|
|
118
|
+
},
|
|
119
|
+
transition: "transition-colors duration-150",
|
|
120
|
+
rounded: ""
|
|
121
|
+
},
|
|
122
|
+
loading: {
|
|
123
|
+
base: "flex items-center justify-center py-4",
|
|
124
|
+
size: "w-6 h-6",
|
|
125
|
+
color: "text-blue-500"
|
|
126
|
+
},
|
|
127
|
+
empty: {
|
|
128
|
+
base: "flex items-center justify-center",
|
|
129
|
+
text: {
|
|
130
|
+
size: "text-sm",
|
|
131
|
+
color: {
|
|
132
|
+
light: "text-gray-500",
|
|
133
|
+
dark: "dark:text-gray-400"
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
padding: "py-4 px-4"
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
export function extendSearchBoxTheme(overrides) {
|
|
140
|
+
return {
|
|
141
|
+
...searchBoxTheme,
|
|
142
|
+
...overrides,
|
|
143
|
+
container: {
|
|
144
|
+
...searchBoxTheme.container,
|
|
145
|
+
...overrides.container
|
|
146
|
+
},
|
|
147
|
+
wrapper: {
|
|
148
|
+
...searchBoxTheme.wrapper,
|
|
149
|
+
...overrides.wrapper
|
|
150
|
+
},
|
|
151
|
+
input: {
|
|
152
|
+
...searchBoxTheme.input,
|
|
153
|
+
...overrides.input
|
|
154
|
+
},
|
|
155
|
+
label: {
|
|
156
|
+
...searchBoxTheme.label,
|
|
157
|
+
...overrides.label
|
|
158
|
+
},
|
|
159
|
+
icon: {
|
|
160
|
+
...searchBoxTheme.icon,
|
|
161
|
+
...overrides.icon
|
|
162
|
+
},
|
|
163
|
+
clearButton: {
|
|
164
|
+
...searchBoxTheme.clearButton,
|
|
165
|
+
...overrides.clearButton
|
|
166
|
+
},
|
|
167
|
+
dropdown: {
|
|
168
|
+
...searchBoxTheme.dropdown,
|
|
169
|
+
...overrides.dropdown
|
|
170
|
+
},
|
|
171
|
+
item: {
|
|
172
|
+
...searchBoxTheme.item,
|
|
173
|
+
...overrides.item
|
|
174
|
+
},
|
|
175
|
+
loading: {
|
|
176
|
+
...searchBoxTheme.loading,
|
|
177
|
+
...overrides.loading
|
|
178
|
+
},
|
|
179
|
+
empty: {
|
|
180
|
+
...searchBoxTheme.empty,
|
|
181
|
+
...overrides.empty
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function debounce(fn, delay) {
|
|
2
|
+
let timeoutId = null;
|
|
3
|
+
const call = (...args)=>{
|
|
4
|
+
if (timeoutId) {
|
|
5
|
+
clearTimeout(timeoutId);
|
|
6
|
+
}
|
|
7
|
+
timeoutId = setTimeout(()=>{
|
|
8
|
+
fn(...args);
|
|
9
|
+
timeoutId = null;
|
|
10
|
+
}, delay);
|
|
11
|
+
};
|
|
12
|
+
const cancel = ()=>{
|
|
13
|
+
if (timeoutId) {
|
|
14
|
+
clearTimeout(timeoutId);
|
|
15
|
+
timeoutId = null;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
call,
|
|
20
|
+
cancel
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const DANGEROUS_PATTERNS = [
|
|
2
|
+
/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
|
|
3
|
+
/javascript:/gi,
|
|
4
|
+
/on\w+\s*=/gi,
|
|
5
|
+
/<iframe/gi,
|
|
6
|
+
/<object/gi,
|
|
7
|
+
/<embed/gi,
|
|
8
|
+
/<link/gi,
|
|
9
|
+
/data:/gi,
|
|
10
|
+
/vbscript:/gi
|
|
11
|
+
];
|
|
12
|
+
const HTML_ENTITIES = {
|
|
13
|
+
"&": "&",
|
|
14
|
+
"<": "<",
|
|
15
|
+
">": ">",
|
|
16
|
+
'"': """,
|
|
17
|
+
"'": "'",
|
|
18
|
+
"/": "/",
|
|
19
|
+
"`": "`",
|
|
20
|
+
"=": "="
|
|
21
|
+
};
|
|
22
|
+
export function sanitizeInput(input) {
|
|
23
|
+
let sanitized = input;
|
|
24
|
+
for (const pattern of DANGEROUS_PATTERNS){
|
|
25
|
+
sanitized = sanitized.replace(pattern, "");
|
|
26
|
+
}
|
|
27
|
+
return sanitized;
|
|
28
|
+
}
|
|
29
|
+
export function escapeHtml(input) {
|
|
30
|
+
return input.replace(/[&<>"'`=/]/g, (char)=>HTML_ENTITIES[char] || char);
|
|
31
|
+
}
|
|
32
|
+
export function sanitizeSearchQuery(query, options = {}) {
|
|
33
|
+
const { trim = true, escapeHtml: shouldEscape = false, maxLength, removeScripts = true } = options;
|
|
34
|
+
let result = query;
|
|
35
|
+
if (removeScripts) {
|
|
36
|
+
result = sanitizeInput(result);
|
|
37
|
+
}
|
|
38
|
+
if (trim) {
|
|
39
|
+
result = result.trim();
|
|
40
|
+
}
|
|
41
|
+
if (shouldEscape) {
|
|
42
|
+
result = escapeHtml(result);
|
|
43
|
+
}
|
|
44
|
+
if (maxLength && result.length > maxLength) {
|
|
45
|
+
result = result.slice(0, maxLength);
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|