hi-tm 0.7.3 → 0.7.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.
@@ -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);
@@ -133,31 +131,20 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
133
131
  const [selectedValues, setSelectedValues] = (0, react_1.useState)([]);
134
132
  const containerRef = (0, react_1.useRef)(null);
135
133
  const inputRef = (0, react_1.useRef)(null);
136
- const prevExternalIdsRef = (0, react_1.useRef)(null);
137
- const mountedRef = (0, react_1.useRef)(false);
138
134
  // Sync external value prop with internal selectedValues state
139
135
  (0, react_1.useEffect)(() => {
140
- mountedRef.current = true;
141
- // Do not clear on transient null/undefined values
142
- if (value === null || value === undefined) {
136
+ if (value === undefined || value === null) {
137
+ setSelectedValues([]);
143
138
  return;
144
139
  }
145
- const arrayValue = Array.isArray(value) ? value : [value];
146
- const normalizedArray = isMultiSelect
147
- ? arrayValue
148
- : arrayValue.length > 0
149
- ? [arrayValue[0]]
150
- : [];
151
- const externalIds = normalizedArray.map((opt) => deriveValue(opt));
152
- const prevIds = prevExternalIdsRef.current;
153
- const hasChanged = !prevIds ||
154
- prevIds.length !== externalIds.length ||
155
- externalIds.some((id, idx) => id !== prevIds[idx]);
156
- if (hasChanged) {
157
- setSelectedValues(normalizedArray);
158
- prevExternalIdsRef.current = externalIds;
140
+ const externalValues = Array.isArray(value) ? value : [value];
141
+ // Only update if values are actually different
142
+ const currentValuesString = JSON.stringify(selectedValues.map(deriveValue));
143
+ const externalValuesString = JSON.stringify(externalValues.map(deriveValue));
144
+ if (currentValuesString !== externalValuesString) {
145
+ setSelectedValues(externalValues);
159
146
  }
160
- }, [value, isMultiSelect, deriveValue]);
147
+ }, [value, deriveValue]);
161
148
  // Sync options into filtered list when not searching
162
149
  (0, react_1.useEffect)(() => {
163
150
  if (!hasSearched) {
@@ -289,7 +276,8 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
289
276
  setInternalLoading(false);
290
277
  }
291
278
  }, [inputValue, isCreatable, onCreateOption]);
292
- const toggleDropdown = (0, react_1.useCallback)(() => {
279
+ const toggleDropdown = (0, react_1.useCallback)((e) => {
280
+ e.stopPropagation();
293
281
  if (!isDisabled) {
294
282
  setIsOpen((prev) => !prev);
295
283
  if (!isOpen && inputRef.current) {
@@ -332,9 +320,17 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
332
320
  onAddClick(true);
333
321
  }
334
322
  }, [onAddClick]);
323
+ const handleTriggerClick = (0, react_1.useCallback)(() => {
324
+ if (!isDisabled) {
325
+ setIsOpen((prev) => !prev);
326
+ if (!isOpen && inputRef.current) {
327
+ inputRef.current.focus();
328
+ }
329
+ }
330
+ }, [isDisabled, isOpen]);
335
331
  return (react_1.default.createElement("div", { ref: containerRef, className: `relative w-full ${className} ${styles.container}`, onKeyDown: handleKeyDown },
336
332
  label && react_1.default.createElement("label", { className: "block text-sm font-medium text-gray-700 mb-1" }, label),
337
- react_1.default.createElement("div", { className: `${styles.trigger} ${isDisabled ? 'bg-gray-100 cursor-not-allowed' : ''} ${isOpen ? 'border-blue-500 ring-2 ring-blue-100' : 'border-gray-300'}`, onClick: toggleDropdown },
333
+ react_1.default.createElement("div", { className: `${styles.trigger} ${isDisabled ? 'bg-gray-100 cursor-not-allowed' : ''} ${isOpen ? 'border-blue-500 ring-2 ring-blue-100' : 'border-gray-300'}`, onClick: handleTriggerClick },
338
334
  react_1.default.createElement("div", { className: "flex-grow flex items-center overflow-x-auto no-scrollbar" },
339
335
  react_1.default.createElement("div", { className: "flex items-center gap-2 flex-nowrap" },
340
336
  selectedValues.length > 0 &&
@@ -345,10 +341,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
345
341
  react_1.default.createElement("div", { className: "flex-shrink-0 flex items-center gap-1 ml-2" },
346
342
  iconSrc.hasAdd && (react_1.default.createElement("button", { onClick: handleAddIconClick, className: styles.clearButton }, renderIcon(iconSrc.hasAdd, styles.icon))),
347
343
  styles.separator && react_1.default.createElement("div", { className: styles.separator }),
348
- react_1.default.createElement("button", { type: "button", onMouseDown: (e) => e.preventDefault(), onClick: (e) => {
349
- e.stopPropagation();
350
- toggleDropdown();
351
- }, className: styles.clearButton }, isOpen
344
+ react_1.default.createElement("button", { onClick: toggleDropdown }, isOpen
352
345
  ? renderIcon(iconSrc.dropdownOpen, `${styles.icon} ${styles.spinAnimation || ''}`)
353
346
  : renderIcon(iconSrc.dropdownClosed, styles.icon)))),
354
347
  isOpen && (react_1.default.createElement("div", { className: styles.dropdown }, showLoading ? (react_1.default.createElement("div", { className: styles.loadingState },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {