hi-tm 0.1.9 → 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.
@@ -5,6 +5,8 @@ interface TextInputProps extends TextInputPropsType {
5
5
  maxLength?: number;
6
6
  onlyFaChars?: boolean;
7
7
  onlyEnChars?: boolean;
8
+ detectKeyboardLanguage?: boolean;
9
+ onKeyboardLanguageChange?: (language: string) => void;
8
10
  }
9
- declare const TextInput: ({ label, required, value, placeholderText, autoComplete, autoFocus, textError, onChangeValueHandler, onBlurHandler, onFocusHandler, onKeyUpHandler, onKeyDownHandler, disabled, type, style, startContent, startContentStyle, placeHolderDirection, applyConditionalStyles, maxLength, onlyFaChars, onlyEnChars, }: TextInputProps) => React.JSX.Element;
11
+ declare const TextInput: ({ label, required, value, placeholderText, autoComplete, autoFocus, textError, onChangeValueHandler, onBlurHandler, onFocusHandler, onKeyUpHandler, onKeyDownHandler, disabled, type, style, startContent, startContentStyle, placeHolderDirection, applyConditionalStyles, maxLength, onlyFaChars, onlyEnChars, detectKeyboardLanguage, onKeyboardLanguageChange, }: TextInputProps) => React.JSX.Element;
10
12
  export default TextInput;
@@ -38,9 +38,59 @@ const react_1 = __importStar(require("react"));
38
38
  const TextInput = ({ label, required, value, placeholderText, autoComplete, autoFocus, textError, onChangeValueHandler, onBlurHandler, onFocusHandler, onKeyUpHandler, onKeyDownHandler, disabled = false, type = 'text', style = {
39
39
  margin: 'mt-[-6px]',
40
40
  width: 'w-full',
41
- }, startContent, startContentStyle, placeHolderDirection = 'ltr', applyConditionalStyles = false, maxLength, onlyFaChars = false, onlyEnChars = false, }) => {
41
+ }, startContent, startContentStyle, placeHolderDirection = 'ltr', applyConditionalStyles = false, maxLength, onlyFaChars = false, onlyEnChars = false, detectKeyboardLanguage = false, onKeyboardLanguageChange, }) => {
42
42
  const [inputValue, setInputValue] = (0, react_1.useState)('');
43
43
  const inputRef = (0, react_1.useRef)(null);
44
+ // Function to detect keyboard language
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';
70
+ return 'unknown';
71
+ }
72
+ // Persian/Farsi detection - improved regex
73
+ const persianRegex = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF\u2000-\u206F]/;
74
+ if (persianRegex.test(text)) {
75
+ return 'fa';
76
+ }
77
+ // English detection
78
+ const englishRegex = /[a-zA-Z]/;
79
+ if (englishRegex.test(text)) {
80
+ return 'en';
81
+ }
82
+ // Arabic detection
83
+ const arabicRegex = /[\u0600-\u06FF\u0750-\u077F]/;
84
+ if (arabicRegex.test(text)) {
85
+ return 'ar';
86
+ }
87
+ // Number detection
88
+ const numberRegex = /[0-9]/;
89
+ if (numberRegex.test(text)) {
90
+ return 'number';
91
+ }
92
+ return 'unknown';
93
+ };
44
94
  const handleInputChange = (e) => {
45
95
  let newValue = e.target.value;
46
96
  // Apply captcha validation if type is 'captcha'
@@ -67,6 +117,11 @@ const TextInput = ({ label, required, value, placeholderText, autoComplete, auto
67
117
  }
68
118
  setInputValue(newValue);
69
119
  onChangeValueHandler(e);
120
+ // Detect keyboard language if enabled
121
+ if (detectKeyboardLanguage && onKeyboardLanguageChange) {
122
+ const detectedLanguage = detectLanguage(newValue);
123
+ onKeyboardLanguageChange(detectedLanguage);
124
+ }
70
125
  };
71
126
  const handleFocus = (e) => {
72
127
  if (onFocusHandler) {
@@ -81,6 +136,18 @@ const TextInput = ({ label, required, value, placeholderText, autoComplete, auto
81
136
  }, 0);
82
137
  }
83
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
+ };
84
151
  const showError = () => {
85
152
  return textError === '' || textError === null || textError.trim() === '';
86
153
  };
@@ -98,7 +165,7 @@ const TextInput = ({ label, required, value, placeholderText, autoComplete, auto
98
165
  react_1.default.createElement("span", { className: `text-red-primary ${required ? 'opacity-100' : 'opacity-0'} ` }, "*")),
99
166
  react_1.default.createElement("div", { className: "relative flex items-center" },
100
167
  startContent && (react_1.default.createElement("div", { className: "absolute left-2 z-10", style: { ...startContentStyle } }, startContent)),
101
- 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 === ''
102
169
  ? 'border-[2px] border-solid border-gray-tertiary'
103
170
  : ' border-[2.5px] border-solid border-red-primary'} ${startContent ? 'pl-12' : ''} placeholder-rtl`, style: computedInputStyle })),
104
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()))));
@@ -21,4 +21,6 @@ export interface TextInputPropsType {
21
21
  maxLength?: number;
22
22
  onlyFaChars?: boolean;
23
23
  onlyEnChars?: boolean;
24
+ detectKeyboardLanguage?: boolean;
25
+ onKeyboardLanguageChange?: (language: string) => void;
24
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.1.9",
3
+ "version": "0.2.1",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {