hi-tm 0.6.2 → 0.6.4

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.
@@ -129,12 +129,22 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
129
129
  const [internalLoading, setInternalLoading] = (0, react_1.useState)(false);
130
130
  const [hasSearched, setHasSearched] = (0, react_1.useState)(false);
131
131
  const [selectedValues, setSelectedValues] = (0, react_1.useState)([]);
132
+ const [isUserInteracting, setIsUserInteracting] = (0, react_1.useState)(false);
132
133
  const containerRef = (0, react_1.useRef)(null);
133
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]);
134
140
  // Sync external value prop with internal selectedValues state
135
141
  (0, react_1.useEffect)(() => {
136
- // Only sync if the external value is different from current selectedValues
137
- const currentValues = selectedValues;
142
+ // Don't sync if user is actively interacting with the component
143
+ if (isUserInteracting) {
144
+ return;
145
+ }
146
+ // Only sync if the external value is actually different from current selectedValues
147
+ const currentValues = selectedValuesRef.current;
138
148
  const externalValue = value;
139
149
  if (externalValue === null || externalValue === undefined) {
140
150
  if (currentValues.length > 0) {
@@ -144,6 +154,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
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)) {
148
159
  setSelectedValues(externalArray);
149
160
  }
@@ -161,7 +172,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
161
172
  setSelectedValues(singleItem);
162
173
  }
163
174
  }
164
- }, [value, isMultiSelect, selectedValues]);
175
+ }, [value, isMultiSelect, isUserInteracting]);
165
176
  // Sync options into filtered list when not searching
166
177
  (0, react_1.useEffect)(() => {
167
178
  if (!hasSearched) {
@@ -191,6 +202,9 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
191
202
  const next = e.target.value;
192
203
  setInputValue(next);
193
204
  setIsOpen(true);
205
+ setIsUserInteracting(true);
206
+ // Reset the flag after a delay to allow for user interactions
207
+ setTimeout(() => setIsUserInteracting(false), 1000);
194
208
  if (onChange)
195
209
  onChange(e);
196
210
  if (fetchOptions && next.trim() !== '') {
@@ -347,18 +361,18 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
347
361
  react_1.default.createElement("button", { onClick: (e) => clearValue(e, val), className: styles.clearButton }, renderIcon(icons.clear, styles.icon))))),
348
362
  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
363
  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))),
364
+ showLoading && renderIcon(iconSrc.loading, `animate-spin ${styles.icon}`),
365
+ iconSrc.hasAdd && (react_1.default.createElement("button", { onClick: handleAddIconClick, className: styles.clearButton }, renderIcon(iconSrc.hasAdd, styles.icon))),
352
366
  styles.separator && react_1.default.createElement("div", { className: styles.separator }),
353
367
  isOpen
354
- ? renderIcon(icons.dropdownOpen, `${styles.icon} ${styles.spinAnimation || ''}`)
355
- : renderIcon(icons.dropdownClosed, styles.icon))),
368
+ ? renderIcon(iconSrc.dropdownOpen, `${styles.icon} ${styles.spinAnimation || ''}`)
369
+ : renderIcon(iconSrc.dropdownClosed, styles.icon))),
356
370
  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}`),
371
+ renderIcon(iconSrc.loading, `animate-spin mr-2 ${styles.icon}`),
358
372
  loadingMessage)) : (react_1.default.createElement(react_1.default.Fragment, null,
359
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) },
360
374
  selectedValues.some((val) => deriveValue(val) === deriveValue(option)) &&
361
- 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'),
362
376
  react_1.default.createElement("span", { className: selectedValues.some((val) => deriveValue(val) === deriveValue(option))
363
377
  ? styles.selectedOption
364
378
  : '' }, deriveLabel(option) || deriveValue(option))))))),
@@ -366,11 +380,11 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
366
380
  filteredOptions.length === 0 &&
367
381
  inputValue &&
368
382
  hasSearched &&
369
- renderNoResults(noResultsFound, styles.noResults ?? '', icons.create),
383
+ renderNoResults(noResultsFound, styles.noResults ?? '', iconSrc.create),
370
384
  isCreatable &&
371
385
  inputValue &&
372
386
  !options?.some((o) => deriveLabel(o) === inputValue) && (react_1.default.createElement("div", { className: styles.createOption, onClick: handleCreateOption },
373
- renderIcon(icons.create, styles.icon),
387
+ renderIcon(iconSrc.create, styles.icon),
374
388
  react_1.default.createElement("span", null,
375
389
  createOptionMessage,
376
390
  ": ",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {