hi-tm 0.2.1 → 0.2.3
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,19 @@ 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
|
+
// Check if the key is a Persian character
|
|
195
|
+
if (/[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/.test(key)) {
|
|
196
|
+
onKeyboardLanguageChange('fa');
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
// Check if the key is an English character
|
|
200
|
+
if (/[a-zA-Z]/.test(key)) {
|
|
201
|
+
onKeyboardLanguageChange('en');
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
// Fallback to layout detection
|
|
142
205
|
const detectedLanguage = detectLanguage('', e);
|
|
143
206
|
if (detectedLanguage !== 'unknown') {
|
|
144
207
|
onKeyboardLanguageChange(detectedLanguage);
|
|
@@ -165,7 +228,7 @@ const TextInput = ({ label, required, value, placeholderText, autoComplete, auto
|
|
|
165
228
|
react_1.default.createElement("span", { className: `text-red-primary ${required ? 'opacity-100' : 'opacity-0'} ` }, "*")),
|
|
166
229
|
react_1.default.createElement("div", { className: "relative flex items-center" },
|
|
167
230
|
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 === ''
|
|
231
|
+
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
232
|
? 'border-[2px] border-solid border-gray-tertiary'
|
|
170
233
|
: ' border-[2.5px] border-solid border-red-primary'} ${startContent ? 'pl-12' : ''} placeholder-rtl`, style: computedInputStyle })),
|
|
171
234
|
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()))));
|
|
@@ -203,7 +203,7 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
203
203
|
if (item.onClick) {
|
|
204
204
|
item.onClick(item.id);
|
|
205
205
|
}
|
|
206
|
-
}, className: "flex items-center gap-2 w-full" }, item.hasImage ? (react_1.default.createElement("div", { className: "flex items-center gap-2 w-full" },
|
|
206
|
+
}, className: "flex items-center gap-2 w-full" }, item.hasImage && item.imageUrl !== null ? (react_1.default.createElement("div", { className: "flex items-center gap-2 w-full" },
|
|
207
207
|
react_1.default.createElement(SafeImage_1.default, { src: item.imageUrl || '/defaultImage.jpg', alt: item.value?.toString() || 'Table item', width: item.imageWidth || 24, height: item.imageHeight || 24, className: item.imageClass || 'h-6 w-6 object-cover' }),
|
|
208
208
|
react_1.default.createElement("p", { className: `${item.contentClass || 'text-start'} text-sm w-full truncate ` }, item.value))) : (react_1.default.createElement("p", { className: `${item.contentClass || 'text-start'} text-sm mr-[5px] w-full truncate`, title: item.value?.toString() || '' }, item.value))));
|
|
209
209
|
}
|