hi-tm 0.6.5 → 0.6.6

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.
@@ -70,7 +70,7 @@ const renderNoResults = (noResults, className, searchIcon) => {
70
70
  if (!noResults) {
71
71
  return (react_1.default.createElement("div", { className: className },
72
72
  renderIcon(searchIcon, 'w-6 h-6 mb-1'),
73
- react_1.default.createElement("span", null, "No results found")));
73
+ react_1.default.createElement("span", null, "\u0645\u0648\u0631\u062F\u06CC \u06CC\u0627\u0641\u062A \u0646\u0634\u062F")));
74
74
  }
75
75
  if (typeof noResults === 'string') {
76
76
  return react_1.default.createElement("div", { className: className }, noResults);
@@ -87,7 +87,7 @@ const renderNoResults = (noResults, className, searchIcon) => {
87
87
  return noResults;
88
88
  }
89
89
  };
90
- function CreatableSelect({ options = [], value, onChange, onClick, onValueChange, onCreateOption, placeholder = 'Select...', isLoading = false, isDisabled = false, isCreatable = true, isMultiSelect = false, noOptionsMessage = 'No options available', noResultsFound, loadingMessage = 'Loading...', createOptionMessage = 'Create option', className = '', tailwindStyle = {}, iconSrc = {}, fetchOptions, label, onAddClick, getOptionLabel, getOptionValue, }) {
90
+ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange, onCreateOption, placeholder = 'جست‌وجو', isLoading = false, isDisabled = false, isCreatable = true, isMultiSelect = false, noOptionsMessage = 'مقدار پیشفرضی وجود ندارد', noResultsFound, loadingMessage = 'در حال بارگذاری...', createOptionMessage = 'ایجاد ', className = '', tailwindStyle = {}, iconSrc = {}, fetchOptions, label, onAddClick, getOptionLabel, getOptionValue, }) {
91
91
  // Default icons
92
92
  const defaultIcons = {
93
93
  dropdownOpen: '▼',
@@ -112,6 +112,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
112
112
  const anyOption = option;
113
113
  const label = anyOption.label ?? anyOption.content ?? anyOption.value;
114
114
  const result = String(label ?? '');
115
+ console.log('deriveLabel for option:', option, 'returning:', result);
115
116
  return result;
116
117
  }, [getOptionLabel]);
117
118
  const deriveValue = (0, react_1.useCallback)((option) => {
@@ -120,6 +121,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
120
121
  const anyOption = option;
121
122
  const base = anyOption.value ?? anyOption.label ?? anyOption.content;
122
123
  const str = String(base ?? deriveLabel(option));
124
+ console.log('deriveValue for option:', option, 'returning:', str);
123
125
  return str;
124
126
  }, [getOptionValue, deriveLabel]);
125
127
  const [isOpen, setIsOpen] = (0, react_1.useState)(false);
@@ -132,26 +134,20 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
132
134
  const [isUserInteracting, setIsUserInteracting] = (0, react_1.useState)(false);
133
135
  const containerRef = (0, react_1.useRef)(null);
134
136
  const inputRef = (0, react_1.useRef)(null);
135
- const selectedValuesRef = (0, react_1.useRef)([]);
136
- // Keep ref in sync with state
137
- (0, react_1.useEffect)(() => {
138
- selectedValuesRef.current = selectedValues;
139
- }, [selectedValues]);
140
- // Debug: Log when selectedValues changes
141
- (0, react_1.useEffect)(() => {
142
- console.log('selectedValues changed to:', selectedValues);
143
- }, [selectedValues]);
144
137
  // Sync external value prop with internal selectedValues state
145
138
  (0, react_1.useEffect)(() => {
146
139
  // Don't sync if user is actively interacting with the component
147
140
  if (isUserInteracting) {
141
+ console.log('Skipping sync - user is interacting');
148
142
  return;
149
143
  }
144
+ console.log('useEffect triggered with value:', value, 'isMultiSelect:', isMultiSelect);
150
145
  // Only sync if the external value is actually different from current selectedValues
151
- const currentValues = selectedValuesRef.current;
146
+ const currentValues = selectedValues;
152
147
  const externalValue = value;
153
148
  if (externalValue === null || externalValue === undefined) {
154
149
  if (currentValues.length > 0) {
150
+ console.log('Setting selectedValues to empty array');
155
151
  setSelectedValues([]);
156
152
  }
157
153
  }
@@ -160,12 +156,14 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
160
156
  const externalArray = externalValue;
161
157
  // Only update if the arrays are actually different
162
158
  if (JSON.stringify(externalArray) !== JSON.stringify(currentValues)) {
159
+ console.log('Setting selectedValues to array:', externalArray);
163
160
  setSelectedValues(externalArray);
164
161
  }
165
162
  }
166
163
  else {
167
164
  const firstItem = externalValue.length > 0 ? [externalValue[0]] : [];
168
165
  if (JSON.stringify(firstItem) !== JSON.stringify(currentValues)) {
166
+ console.log('Setting selectedValues to first item of array:', firstItem);
169
167
  setSelectedValues(firstItem);
170
168
  }
171
169
  }
@@ -173,10 +171,11 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
173
171
  else {
174
172
  const singleItem = [externalValue];
175
173
  if (JSON.stringify(singleItem) !== JSON.stringify(currentValues)) {
174
+ console.log('Setting selectedValues to single item:', singleItem);
176
175
  setSelectedValues(singleItem);
177
176
  }
178
177
  }
179
- }, [value, isMultiSelect, isUserInteracting]);
178
+ }, [value, isMultiSelect, selectedValues, isUserInteracting]);
180
179
  // Sync options into filtered list when not searching
181
180
  (0, react_1.useEffect)(() => {
182
181
  if (!hasSearched) {
@@ -207,8 +206,6 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
207
206
  setInputValue(next);
208
207
  setIsOpen(true);
209
208
  setIsUserInteracting(true);
210
- // Reset the flag after a delay to allow for user interactions
211
- setTimeout(() => setIsUserInteracting(false), 1000);
212
209
  if (onChange)
213
210
  onChange(e);
214
211
  if (fetchOptions && next.trim() !== '') {
@@ -326,15 +323,11 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
326
323
  emitSelection(next);
327
324
  }, [selectedValues, deriveValue, emitSelection]);
328
325
  const selectOption = (0, react_1.useCallback)((option) => {
329
- console.log('selectOption called with:', option);
330
- console.log('Current selectedValues:', selectedValues);
331
- console.log('isMultiSelect:', isMultiSelect);
332
326
  if (isMultiSelect) {
333
327
  const next = [...selectedValues];
334
328
  if (!next.some((val) => deriveValue(val) === deriveValue(option))) {
335
329
  next.push(option);
336
330
  }
337
- console.log('New selectedValues (multi):', next);
338
331
  setSelectedValues(next);
339
332
  emitSelection(next);
340
333
  // In multi-select mode, keep the input open and clear input for next search
@@ -344,7 +337,6 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
344
337
  }
345
338
  else {
346
339
  const next = [option];
347
- console.log('New selectedValues (single):', next);
348
340
  setSelectedValues(next);
349
341
  emitSelection(next);
350
342
  setInputValue('');
@@ -370,18 +362,17 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
370
362
  react_1.default.createElement("button", { onClick: (e) => clearValue(e, val), className: styles.clearButton }, renderIcon(icons.clear, styles.icon))))),
371
363
  react_1.default.createElement("input", { ref: inputRef, type: "text", className: `${styles.input} ${isDisabled ? 'bg-gray-100' : ''} min-w-[80px] flex-shrink-0`, placeholder: selectedValues.length > 0 ? '' : placeholder, value: inputValue, onChange: handleInputChange, disabled: isDisabled, onClick: (e) => e.stopPropagation() }))),
372
364
  react_1.default.createElement("div", { className: "flex-shrink-0 flex items-center gap-1 ml-2" },
373
- showLoading && renderIcon(icons.loading, `animate-spin ${styles.icon}`),
374
- icons.hasAdd && onAddClick !== undefined && (react_1.default.createElement("button", { onClick: handleAddIconClick, className: styles.clearButton }, renderIcon(icons.hasAdd, styles.icon))),
365
+ iconSrc.hasAdd && (react_1.default.createElement("button", { onClick: handleAddIconClick, className: styles.clearButton }, renderIcon(iconSrc.hasAdd, styles.icon))),
375
366
  styles.separator && react_1.default.createElement("div", { className: styles.separator }),
376
367
  isOpen
377
- ? renderIcon(icons.dropdownOpen, `${styles.icon} ${styles.spinAnimation || ''}`)
378
- : renderIcon(icons.dropdownClosed, styles.icon))),
368
+ ? renderIcon(iconSrc.dropdownOpen, `${styles.icon} ${styles.spinAnimation || ''}`)
369
+ : renderIcon(iconSrc.dropdownClosed, styles.icon))),
379
370
  isOpen && (react_1.default.createElement("div", { className: styles.dropdown }, showLoading ? (react_1.default.createElement("div", { className: styles.loadingState },
380
- renderIcon(icons.loading, `animate-spin mr-2 ${styles.icon}`),
371
+ renderIcon(iconSrc.loading, `animate-spin mr-2 ${styles.icon}`),
381
372
  loadingMessage)) : (react_1.default.createElement(react_1.default.Fragment, null,
382
373
  filteredOptions.length > 0 && (react_1.default.createElement(react_1.default.Fragment, null, filteredOptions.map((option, index) => (react_1.default.createElement("div", { key: deriveValue(option), className: `${styles.option} ${index === highlightedIndex ? styles.highlightedOption : 'hover:bg-gray-50'}`, onClick: () => selectOption(option), onMouseEnter: () => setHighlightedIndex(index) },
383
374
  selectedValues.some((val) => deriveValue(val) === deriveValue(option)) &&
384
- renderIcon(icons.checkmark, 'w-4 h-4 mr-2 text-blue-500'),
375
+ renderIcon(iconSrc.checkmark, 'w-4 h-4 mr-2 text-blue-500'),
385
376
  react_1.default.createElement("span", { className: selectedValues.some((val) => deriveValue(val) === deriveValue(option))
386
377
  ? styles.selectedOption
387
378
  : '' }, deriveLabel(option) || deriveValue(option))))))),
@@ -389,11 +380,11 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
389
380
  filteredOptions.length === 0 &&
390
381
  inputValue &&
391
382
  hasSearched &&
392
- renderNoResults(noResultsFound, styles.noResults ?? '', icons.create),
383
+ renderNoResults(noResultsFound, styles.noResults ?? '', iconSrc.create),
393
384
  isCreatable &&
394
385
  inputValue &&
395
386
  !options?.some((o) => deriveLabel(o) === inputValue) && (react_1.default.createElement("div", { className: styles.createOption, onClick: handleCreateOption },
396
- renderIcon(icons.create, styles.icon),
387
+ renderIcon(iconSrc.create, styles.icon),
397
388
  react_1.default.createElement("span", null,
398
389
  createOptionMessage,
399
390
  ": ",
@@ -67,7 +67,7 @@ export type CreatableSelectProps<T = SelectOption> = {
67
67
  label?: string;
68
68
  iconSrc?: IconSourceProps;
69
69
  fetchOptions?: (inputValue: string) => Promise<T[]>;
70
- onAddClick?: (e: boolean) => void;
70
+ onAddClick: (e: boolean) => void;
71
71
  isMultiSelect?: boolean;
72
72
  getOptionLabel?: OptionLabelGetter<T>;
73
73
  getOptionValue?: OptionValueGetter<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.6.5",
3
+ "version": "0.6.6",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {