hi-tm 0.6.4 → 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, "
|
|
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 = '
|
|
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,22 +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
137
|
// Sync external value prop with internal selectedValues state
|
|
141
138
|
(0, react_1.useEffect)(() => {
|
|
142
139
|
// Don't sync if user is actively interacting with the component
|
|
143
140
|
if (isUserInteracting) {
|
|
141
|
+
console.log('Skipping sync - user is interacting');
|
|
144
142
|
return;
|
|
145
143
|
}
|
|
144
|
+
console.log('useEffect triggered with value:', value, 'isMultiSelect:', isMultiSelect);
|
|
146
145
|
// Only sync if the external value is actually different from current selectedValues
|
|
147
|
-
const currentValues =
|
|
146
|
+
const currentValues = selectedValues;
|
|
148
147
|
const externalValue = value;
|
|
149
148
|
if (externalValue === null || externalValue === undefined) {
|
|
150
149
|
if (currentValues.length > 0) {
|
|
150
|
+
console.log('Setting selectedValues to empty array');
|
|
151
151
|
setSelectedValues([]);
|
|
152
152
|
}
|
|
153
153
|
}
|
|
@@ -156,12 +156,14 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
156
156
|
const externalArray = externalValue;
|
|
157
157
|
// Only update if the arrays are actually different
|
|
158
158
|
if (JSON.stringify(externalArray) !== JSON.stringify(currentValues)) {
|
|
159
|
+
console.log('Setting selectedValues to array:', externalArray);
|
|
159
160
|
setSelectedValues(externalArray);
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
163
|
else {
|
|
163
164
|
const firstItem = externalValue.length > 0 ? [externalValue[0]] : [];
|
|
164
165
|
if (JSON.stringify(firstItem) !== JSON.stringify(currentValues)) {
|
|
166
|
+
console.log('Setting selectedValues to first item of array:', firstItem);
|
|
165
167
|
setSelectedValues(firstItem);
|
|
166
168
|
}
|
|
167
169
|
}
|
|
@@ -169,10 +171,11 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
169
171
|
else {
|
|
170
172
|
const singleItem = [externalValue];
|
|
171
173
|
if (JSON.stringify(singleItem) !== JSON.stringify(currentValues)) {
|
|
174
|
+
console.log('Setting selectedValues to single item:', singleItem);
|
|
172
175
|
setSelectedValues(singleItem);
|
|
173
176
|
}
|
|
174
177
|
}
|
|
175
|
-
}, [value, isMultiSelect, isUserInteracting]);
|
|
178
|
+
}, [value, isMultiSelect, selectedValues, isUserInteracting]);
|
|
176
179
|
// Sync options into filtered list when not searching
|
|
177
180
|
(0, react_1.useEffect)(() => {
|
|
178
181
|
if (!hasSearched) {
|
|
@@ -203,8 +206,6 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
203
206
|
setInputValue(next);
|
|
204
207
|
setIsOpen(true);
|
|
205
208
|
setIsUserInteracting(true);
|
|
206
|
-
// Reset the flag after a delay to allow for user interactions
|
|
207
|
-
setTimeout(() => setIsUserInteracting(false), 1000);
|
|
208
209
|
if (onChange)
|
|
209
210
|
onChange(e);
|
|
210
211
|
if (fetchOptions && next.trim() !== '') {
|
|
@@ -361,7 +362,6 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
361
362
|
react_1.default.createElement("button", { onClick: (e) => clearValue(e, val), className: styles.clearButton }, renderIcon(icons.clear, styles.icon))))),
|
|
362
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() }))),
|
|
363
364
|
react_1.default.createElement("div", { className: "flex-shrink-0 flex items-center gap-1 ml-2" },
|
|
364
|
-
showLoading && renderIcon(iconSrc.loading, `animate-spin ${styles.icon}`),
|
|
365
365
|
iconSrc.hasAdd && (react_1.default.createElement("button", { onClick: handleAddIconClick, className: styles.clearButton }, renderIcon(iconSrc.hasAdd, styles.icon))),
|
|
366
366
|
styles.separator && react_1.default.createElement("div", { className: styles.separator }),
|
|
367
367
|
isOpen
|
|
@@ -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
|
|
70
|
+
onAddClick: (e: boolean) => void;
|
|
71
71
|
isMultiSelect?: boolean;
|
|
72
72
|
getOptionLabel?: OptionLabelGetter<T>;
|
|
73
73
|
getOptionValue?: OptionValueGetter<T>;
|