hi-tm 0.2.0 → 0.2.1

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.
@@ -42,11 +42,35 @@ const TextInput = ({ label, required, value, placeholderText, autoComplete, auto
42
42
  const [inputValue, setInputValue] = (0, react_1.useState)('');
43
43
  const inputRef = (0, react_1.useRef)(null);
44
44
  // Function to detect keyboard language
45
- const detectLanguage = (text) => {
46
- if (!text.trim())
45
+ const detectLanguage = (text, event) => {
46
+ // Try to detect from keyboard event first
47
+ if (event) {
48
+ // Check if the event has language information
49
+ const nativeEvent = event.nativeEvent;
50
+ const locale = nativeEvent.locale;
51
+ if (locale) {
52
+ if (locale.includes('fa') || locale.includes('persian'))
53
+ return 'fa';
54
+ if (locale.includes('en') || locale.includes('english'))
55
+ return 'en';
56
+ if (locale.includes('ar') || locale.includes('arabic'))
57
+ return 'ar';
58
+ }
59
+ }
60
+ // Fallback to character analysis
61
+ if (!text.trim()) {
62
+ // Check browser language as fallback
63
+ const browserLang = navigator.language || navigator.languages?.[0];
64
+ if (browserLang?.includes('fa'))
65
+ return 'fa';
66
+ if (browserLang?.includes('ar'))
67
+ return 'ar';
68
+ if (browserLang?.includes('en'))
69
+ return 'en';
47
70
  return 'unknown';
48
- // Persian/Farsi detection
49
- const persianRegex = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;
71
+ }
72
+ // Persian/Farsi detection - improved regex
73
+ const persianRegex = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF\u2000-\u206F]/;
50
74
  if (persianRegex.test(text)) {
51
75
  return 'fa';
52
76
  }
@@ -112,6 +136,18 @@ const TextInput = ({ label, required, value, placeholderText, autoComplete, auto
112
136
  }, 0);
113
137
  }
114
138
  };
139
+ const handleKeyDown = (e) => {
140
+ // Detect keyboard language on key press
141
+ if (detectKeyboardLanguage && onKeyboardLanguageChange) {
142
+ const detectedLanguage = detectLanguage('', e);
143
+ if (detectedLanguage !== 'unknown') {
144
+ onKeyboardLanguageChange(detectedLanguage);
145
+ }
146
+ }
147
+ if (onKeyDownHandler) {
148
+ onKeyDownHandler(e);
149
+ }
150
+ };
115
151
  const showError = () => {
116
152
  return textError === '' || textError === null || textError.trim() === '';
117
153
  };
@@ -129,7 +165,7 @@ const TextInput = ({ label, required, value, placeholderText, autoComplete, auto
129
165
  react_1.default.createElement("span", { className: `text-red-primary ${required ? 'opacity-100' : 'opacity-0'} ` }, "*")),
130
166
  react_1.default.createElement("div", { className: "relative flex items-center" },
131
167
  startContent && (react_1.default.createElement("div", { className: "absolute left-2 z-10", style: { ...startContentStyle } }, startContent)),
132
- 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: onKeyDownHandler ? onKeyDownHandler : () => { }, 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 === ''
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 === ''
133
169
  ? 'border-[2px] border-solid border-gray-tertiary'
134
170
  : ' border-[2.5px] border-solid border-red-primary'} ${startContent ? 'pl-12' : ''} placeholder-rtl`, style: computedInputStyle })),
135
171
  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()))));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {