hi-tm 0.6.2 → 0.6.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.
@@ -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);
@@ -129,28 +131,39 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
129
131
  const [internalLoading, setInternalLoading] = (0, react_1.useState)(false);
130
132
  const [hasSearched, setHasSearched] = (0, react_1.useState)(false);
131
133
  const [selectedValues, setSelectedValues] = (0, react_1.useState)([]);
134
+ const [isUserInteracting, setIsUserInteracting] = (0, react_1.useState)(false);
132
135
  const containerRef = (0, react_1.useRef)(null);
133
136
  const inputRef = (0, react_1.useRef)(null);
134
137
  // Sync external value prop with internal selectedValues state
135
138
  (0, react_1.useEffect)(() => {
136
- // Only sync if the external value is different from current selectedValues
139
+ // Don't sync if user is actively interacting with the component
140
+ if (isUserInteracting) {
141
+ console.log('Skipping sync - user is interacting');
142
+ return;
143
+ }
144
+ console.log('useEffect triggered with value:', value, 'isMultiSelect:', isMultiSelect);
145
+ // Only sync if the external value is actually different from current selectedValues
137
146
  const currentValues = selectedValues;
138
147
  const externalValue = value;
139
148
  if (externalValue === null || externalValue === undefined) {
140
149
  if (currentValues.length > 0) {
150
+ console.log('Setting selectedValues to empty array');
141
151
  setSelectedValues([]);
142
152
  }
143
153
  }
144
154
  else if (Array.isArray(externalValue)) {
145
155
  if (isMultiSelect) {
146
156
  const externalArray = externalValue;
157
+ // Only update if the arrays are actually different
147
158
  if (JSON.stringify(externalArray) !== JSON.stringify(currentValues)) {
159
+ console.log('Setting selectedValues to array:', externalArray);
148
160
  setSelectedValues(externalArray);
149
161
  }
150
162
  }
151
163
  else {
152
164
  const firstItem = externalValue.length > 0 ? [externalValue[0]] : [];
153
165
  if (JSON.stringify(firstItem) !== JSON.stringify(currentValues)) {
166
+ console.log('Setting selectedValues to first item of array:', firstItem);
154
167
  setSelectedValues(firstItem);
155
168
  }
156
169
  }
@@ -158,10 +171,11 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
158
171
  else {
159
172
  const singleItem = [externalValue];
160
173
  if (JSON.stringify(singleItem) !== JSON.stringify(currentValues)) {
174
+ console.log('Setting selectedValues to single item:', singleItem);
161
175
  setSelectedValues(singleItem);
162
176
  }
163
177
  }
164
- }, [value, isMultiSelect, selectedValues]);
178
+ }, [value, isMultiSelect, selectedValues, isUserInteracting]);
165
179
  // Sync options into filtered list when not searching
166
180
  (0, react_1.useEffect)(() => {
167
181
  if (!hasSearched) {
@@ -191,6 +205,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
191
205
  const next = e.target.value;
192
206
  setInputValue(next);
193
207
  setIsOpen(true);
208
+ setIsUserInteracting(true);
194
209
  if (onChange)
195
210
  onChange(e);
196
211
  if (fetchOptions && next.trim() !== '') {
@@ -347,18 +362,18 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
347
362
  react_1.default.createElement("button", { onClick: (e) => clearValue(e, val), className: styles.clearButton }, renderIcon(icons.clear, styles.icon))))),
348
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() }))),
349
364
  react_1.default.createElement("div", { className: "flex-shrink-0 flex items-center gap-1 ml-2" },
350
- showLoading && renderIcon(icons.loading, `animate-spin ${styles.icon}`),
351
- icons.hasAdd && onAddClick !== undefined && (react_1.default.createElement("button", { onClick: handleAddIconClick, className: styles.clearButton }, renderIcon(icons.hasAdd, styles.icon))),
365
+ showLoading && renderIcon(iconSrc.loading, `animate-spin ${styles.icon}`),
366
+ iconSrc.hasAdd && (react_1.default.createElement("button", { onClick: handleAddIconClick, className: styles.clearButton }, renderIcon(iconSrc.hasAdd, styles.icon))),
352
367
  styles.separator && react_1.default.createElement("div", { className: styles.separator }),
353
368
  isOpen
354
- ? renderIcon(icons.dropdownOpen, `${styles.icon} ${styles.spinAnimation || ''}`)
355
- : renderIcon(icons.dropdownClosed, styles.icon))),
369
+ ? renderIcon(iconSrc.dropdownOpen, `${styles.icon} ${styles.spinAnimation || ''}`)
370
+ : renderIcon(iconSrc.dropdownClosed, styles.icon))),
356
371
  isOpen && (react_1.default.createElement("div", { className: styles.dropdown }, showLoading ? (react_1.default.createElement("div", { className: styles.loadingState },
357
- renderIcon(icons.loading, `animate-spin mr-2 ${styles.icon}`),
372
+ renderIcon(iconSrc.loading, `animate-spin mr-2 ${styles.icon}`),
358
373
  loadingMessage)) : (react_1.default.createElement(react_1.default.Fragment, null,
359
374
  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) },
360
375
  selectedValues.some((val) => deriveValue(val) === deriveValue(option)) &&
361
- renderIcon(icons.checkmark, 'w-4 h-4 mr-2 text-blue-500'),
376
+ renderIcon(iconSrc.checkmark, 'w-4 h-4 mr-2 text-blue-500'),
362
377
  react_1.default.createElement("span", { className: selectedValues.some((val) => deriveValue(val) === deriveValue(option))
363
378
  ? styles.selectedOption
364
379
  : '' }, deriveLabel(option) || deriveValue(option))))))),
@@ -366,11 +381,11 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
366
381
  filteredOptions.length === 0 &&
367
382
  inputValue &&
368
383
  hasSearched &&
369
- renderNoResults(noResultsFound, styles.noResults ?? '', icons.create),
384
+ renderNoResults(noResultsFound, styles.noResults ?? '', iconSrc.create),
370
385
  isCreatable &&
371
386
  inputValue &&
372
387
  !options?.some((o) => deriveLabel(o) === inputValue) && (react_1.default.createElement("div", { className: styles.createOption, onClick: handleCreateOption },
373
- renderIcon(icons.create, styles.icon),
388
+ renderIcon(iconSrc.create, styles.icon),
374
389
  react_1.default.createElement("span", null,
375
390
  createOptionMessage,
376
391
  ": ",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {