hi-tm 0.2.1 → 0.2.2
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.
|
@@ -91,6 +91,49 @@ const TextInput = ({ label, required, value, placeholderText, autoComplete, auto
|
|
|
91
91
|
}
|
|
92
92
|
return 'unknown';
|
|
93
93
|
};
|
|
94
|
+
// Function to detect keyboard layout using multiple methods
|
|
95
|
+
const detectKeyboardLayout = () => {
|
|
96
|
+
try {
|
|
97
|
+
// Method 1: Try to get from navigator.languages (most reliable)
|
|
98
|
+
const languages = navigator.languages || [navigator.language];
|
|
99
|
+
for (const lang of languages) {
|
|
100
|
+
if (lang?.includes('fa') || lang?.includes('persian') || lang?.includes('ir'))
|
|
101
|
+
return 'fa';
|
|
102
|
+
if (lang?.includes('ar') || lang?.includes('arabic'))
|
|
103
|
+
return 'ar';
|
|
104
|
+
if (lang?.includes('en') || lang?.includes('english') || lang?.includes('us'))
|
|
105
|
+
return 'en';
|
|
106
|
+
}
|
|
107
|
+
// Method 2: Try to get from navigator.language
|
|
108
|
+
const browserLang = navigator.language;
|
|
109
|
+
if (browserLang?.includes('fa') ||
|
|
110
|
+
browserLang?.includes('persian') ||
|
|
111
|
+
browserLang?.includes('ir'))
|
|
112
|
+
return 'fa';
|
|
113
|
+
if (browserLang?.includes('ar') || browserLang?.includes('arabic'))
|
|
114
|
+
return 'ar';
|
|
115
|
+
if (browserLang?.includes('en') ||
|
|
116
|
+
browserLang?.includes('english') ||
|
|
117
|
+
browserLang?.includes('us'))
|
|
118
|
+
return 'en';
|
|
119
|
+
// Method 3: Try to get from user agent
|
|
120
|
+
const userAgent = navigator.userAgent.toLowerCase();
|
|
121
|
+
if (userAgent.includes('persian') ||
|
|
122
|
+
userAgent.includes('farsi') ||
|
|
123
|
+
userAgent.includes('iran'))
|
|
124
|
+
return 'fa';
|
|
125
|
+
if (userAgent.includes('arabic'))
|
|
126
|
+
return 'ar';
|
|
127
|
+
// Method 4: Try to get from timezone (Iran timezone might indicate Persian)
|
|
128
|
+
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
129
|
+
if (timezone?.includes('Tehran') || timezone?.includes('Iran'))
|
|
130
|
+
return 'fa';
|
|
131
|
+
return 'unknown';
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return 'unknown';
|
|
135
|
+
}
|
|
136
|
+
};
|
|
94
137
|
const handleInputChange = (e) => {
|
|
95
138
|
let newValue = e.target.value;
|
|
96
139
|
// Apply captcha validation if type is 'captcha'
|
|
@@ -127,6 +170,13 @@ const TextInput = ({ label, required, value, placeholderText, autoComplete, auto
|
|
|
127
170
|
if (onFocusHandler) {
|
|
128
171
|
onFocusHandler(e);
|
|
129
172
|
}
|
|
173
|
+
// Detect keyboard language on focus
|
|
174
|
+
if (detectKeyboardLanguage && onKeyboardLanguageChange) {
|
|
175
|
+
const detectedLanguage = detectKeyboardLayout();
|
|
176
|
+
if (detectedLanguage !== 'unknown') {
|
|
177
|
+
onKeyboardLanguageChange(detectedLanguage);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
130
180
|
if (inputRef.current && type === 'text') {
|
|
131
181
|
setTimeout(() => {
|
|
132
182
|
if (inputRef.current) {
|
|
@@ -139,6 +189,22 @@ const TextInput = ({ label, required, value, placeholderText, autoComplete, auto
|
|
|
139
189
|
const handleKeyDown = (e) => {
|
|
140
190
|
// Detect keyboard language on key press
|
|
141
191
|
if (detectKeyboardLanguage && onKeyboardLanguageChange) {
|
|
192
|
+
// Try to detect from the key pressed
|
|
193
|
+
const key = e.key;
|
|
194
|
+
const code = e.code;
|
|
195
|
+
// Log for debugging (you can remove this later)
|
|
196
|
+
console.log('Key pressed:', key, 'Code:', code, 'Event:', e.nativeEvent);
|
|
197
|
+
// Check if the key is a Persian character
|
|
198
|
+
if (/[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/.test(key)) {
|
|
199
|
+
onKeyboardLanguageChange('fa');
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
// Check if the key is an English character
|
|
203
|
+
if (/[a-zA-Z]/.test(key)) {
|
|
204
|
+
onKeyboardLanguageChange('en');
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
// Fallback to layout detection
|
|
142
208
|
const detectedLanguage = detectLanguage('', e);
|
|
143
209
|
if (detectedLanguage !== 'unknown') {
|
|
144
210
|
onKeyboardLanguageChange(detectedLanguage);
|
|
@@ -165,7 +231,7 @@ const TextInput = ({ label, required, value, placeholderText, autoComplete, auto
|
|
|
165
231
|
react_1.default.createElement("span", { className: `text-red-primary ${required ? 'opacity-100' : 'opacity-0'} ` }, "*")),
|
|
166
232
|
react_1.default.createElement("div", { className: "relative flex items-center" },
|
|
167
233
|
startContent && (react_1.default.createElement("div", { className: "absolute left-2 z-10", style: { ...startContentStyle } }, startContent)),
|
|
168
|
-
react_1.default.createElement("input", { ref: inputRef, type: type === 'captcha' ? 'tel' : type, id: label, disabled: disabled, value: value || inputValue, required: false, onChange: handleInputChange, onBlur: onBlurHandler ? onBlurHandler : () => { }, onFocus: handleFocus, onKeyDown: handleKeyDown, onKeyUp: onKeyUpHandler ? onKeyUpHandler : () => { }, placeholder: placeholderText, autoComplete: autoComplete ? 'on' : 'off', autoFocus: autoFocus, maxLength: type === 'captcha' ? 4 : maxLength, inputMode: type === 'captcha' ? 'numeric' : undefined, className: `input-style bg-inherit ${disabled ? 'cursor-not-allowed' : ''} text-gray-secondary ${textError === ''
|
|
234
|
+
react_1.default.createElement("input", { ref: inputRef, type: type === 'captcha' ? 'tel' : type, id: label, disabled: disabled, value: value || inputValue, required: false, onChange: handleInputChange, onBlur: onBlurHandler ? onBlurHandler : () => { }, onFocus: handleFocus, onKeyDown: handleKeyDown, onKeyUp: onKeyUpHandler ? onKeyUpHandler : () => { }, placeholder: placeholderText, autoComplete: autoComplete ? 'on' : 'off', autoFocus: autoFocus, maxLength: type === 'captcha' ? 4 : maxLength, inputMode: type === 'captcha' ? 'numeric' : undefined, lang: detectKeyboardLanguage ? detectKeyboardLayout() : undefined, className: `input-style bg-inherit ${disabled ? 'cursor-not-allowed' : ''} text-gray-secondary ${textError === ''
|
|
169
235
|
? 'border-[2px] border-solid border-gray-tertiary'
|
|
170
236
|
: ' border-[2.5px] border-solid border-red-primary'} ${startContent ? 'pl-12' : ''} placeholder-rtl`, style: computedInputStyle })),
|
|
171
237
|
react_1.default.createElement("span", { className: `absolute bottom-0 text-sm mr-1 text-nowrap font-normal text-red-primary ${showError() ? 'opacity-0' : 'opacity-100'}` }, textError?.trim()))));
|