hi-tm 0.6.3 → 0.6.5

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,7 +112,6 @@ 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);
116
115
  return result;
117
116
  }, [getOptionLabel]);
118
117
  const deriveValue = (0, react_1.useCallback)((option) => {
@@ -121,7 +120,6 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
121
120
  const anyOption = option;
122
121
  const base = anyOption.value ?? anyOption.label ?? anyOption.content;
123
122
  const str = String(base ?? deriveLabel(option));
124
- console.log('deriveValue for option:', option, 'returning:', str);
125
123
  return str;
126
124
  }, [getOptionValue, deriveLabel]);
127
125
  const [isOpen, setIsOpen] = (0, react_1.useState)(false);
@@ -134,20 +132,26 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
134
132
  const [isUserInteracting, setIsUserInteracting] = (0, react_1.useState)(false);
135
133
  const containerRef = (0, react_1.useRef)(null);
136
134
  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]);
137
144
  // Sync external value prop with internal selectedValues state
138
145
  (0, react_1.useEffect)(() => {
139
146
  // Don't sync if user is actively interacting with the component
140
147
  if (isUserInteracting) {
141
- console.log('Skipping sync - user is interacting');
142
148
  return;
143
149
  }
144
- console.log('useEffect triggered with value:', value, 'isMultiSelect:', isMultiSelect);
145
150
  // Only sync if the external value is actually different from current selectedValues
146
- const currentValues = selectedValues;
151
+ const currentValues = selectedValuesRef.current;
147
152
  const externalValue = value;
148
153
  if (externalValue === null || externalValue === undefined) {
149
154
  if (currentValues.length > 0) {
150
- console.log('Setting selectedValues to empty array');
151
155
  setSelectedValues([]);
152
156
  }
153
157
  }
@@ -156,14 +160,12 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
156
160
  const externalArray = externalValue;
157
161
  // Only update if the arrays are actually different
158
162
  if (JSON.stringify(externalArray) !== JSON.stringify(currentValues)) {
159
- console.log('Setting selectedValues to array:', externalArray);
160
163
  setSelectedValues(externalArray);
161
164
  }
162
165
  }
163
166
  else {
164
167
  const firstItem = externalValue.length > 0 ? [externalValue[0]] : [];
165
168
  if (JSON.stringify(firstItem) !== JSON.stringify(currentValues)) {
166
- console.log('Setting selectedValues to first item of array:', firstItem);
167
169
  setSelectedValues(firstItem);
168
170
  }
169
171
  }
@@ -171,11 +173,10 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
171
173
  else {
172
174
  const singleItem = [externalValue];
173
175
  if (JSON.stringify(singleItem) !== JSON.stringify(currentValues)) {
174
- console.log('Setting selectedValues to single item:', singleItem);
175
176
  setSelectedValues(singleItem);
176
177
  }
177
178
  }
178
- }, [value, isMultiSelect, selectedValues, isUserInteracting]);
179
+ }, [value, isMultiSelect, isUserInteracting]);
179
180
  // Sync options into filtered list when not searching
180
181
  (0, react_1.useEffect)(() => {
181
182
  if (!hasSearched) {
@@ -206,6 +207,8 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
206
207
  setInputValue(next);
207
208
  setIsOpen(true);
208
209
  setIsUserInteracting(true);
210
+ // Reset the flag after a delay to allow for user interactions
211
+ setTimeout(() => setIsUserInteracting(false), 1000);
209
212
  if (onChange)
210
213
  onChange(e);
211
214
  if (fetchOptions && next.trim() !== '') {
@@ -323,11 +326,15 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
323
326
  emitSelection(next);
324
327
  }, [selectedValues, deriveValue, emitSelection]);
325
328
  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);
326
332
  if (isMultiSelect) {
327
333
  const next = [...selectedValues];
328
334
  if (!next.some((val) => deriveValue(val) === deriveValue(option))) {
329
335
  next.push(option);
330
336
  }
337
+ console.log('New selectedValues (multi):', next);
331
338
  setSelectedValues(next);
332
339
  emitSelection(next);
333
340
  // In multi-select mode, keep the input open and clear input for next search
@@ -337,6 +344,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
337
344
  }
338
345
  else {
339
346
  const next = [option];
347
+ console.log('New selectedValues (single):', next);
340
348
  setSelectedValues(next);
341
349
  emitSelection(next);
342
350
  setInputValue('');
@@ -362,18 +370,18 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
362
370
  react_1.default.createElement("button", { onClick: (e) => clearValue(e, val), className: styles.clearButton }, renderIcon(icons.clear, styles.icon))))),
363
371
  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() }))),
364
372
  react_1.default.createElement("div", { className: "flex-shrink-0 flex items-center gap-1 ml-2" },
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))),
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))),
367
375
  styles.separator && react_1.default.createElement("div", { className: styles.separator }),
368
376
  isOpen
369
- ? renderIcon(iconSrc.dropdownOpen, `${styles.icon} ${styles.spinAnimation || ''}`)
370
- : renderIcon(iconSrc.dropdownClosed, styles.icon))),
377
+ ? renderIcon(icons.dropdownOpen, `${styles.icon} ${styles.spinAnimation || ''}`)
378
+ : renderIcon(icons.dropdownClosed, styles.icon))),
371
379
  isOpen && (react_1.default.createElement("div", { className: styles.dropdown }, showLoading ? (react_1.default.createElement("div", { className: styles.loadingState },
372
- renderIcon(iconSrc.loading, `animate-spin mr-2 ${styles.icon}`),
380
+ renderIcon(icons.loading, `animate-spin mr-2 ${styles.icon}`),
373
381
  loadingMessage)) : (react_1.default.createElement(react_1.default.Fragment, null,
374
382
  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) },
375
383
  selectedValues.some((val) => deriveValue(val) === deriveValue(option)) &&
376
- renderIcon(iconSrc.checkmark, 'w-4 h-4 mr-2 text-blue-500'),
384
+ renderIcon(icons.checkmark, 'w-4 h-4 mr-2 text-blue-500'),
377
385
  react_1.default.createElement("span", { className: selectedValues.some((val) => deriveValue(val) === deriveValue(option))
378
386
  ? styles.selectedOption
379
387
  : '' }, deriveLabel(option) || deriveValue(option))))))),
@@ -381,11 +389,11 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
381
389
  filteredOptions.length === 0 &&
382
390
  inputValue &&
383
391
  hasSearched &&
384
- renderNoResults(noResultsFound, styles.noResults ?? '', iconSrc.create),
392
+ renderNoResults(noResultsFound, styles.noResults ?? '', icons.create),
385
393
  isCreatable &&
386
394
  inputValue &&
387
395
  !options?.some((o) => deriveLabel(o) === inputValue) && (react_1.default.createElement("div", { className: styles.createOption, onClick: handleCreateOption },
388
- renderIcon(iconSrc.create, styles.icon),
396
+ renderIcon(icons.create, styles.icon),
389
397
  react_1.default.createElement("span", null,
390
398
  createOptionMessage,
391
399
  ": ",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {