hi-tm 0.7.3 → 0.7.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);
@@ -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,9 @@ 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.preventDefault();
281
+ e.stopPropagation();
293
282
  if (!isDisabled) {
294
283
  setIsOpen((prev) => !prev);
295
284
  if (!isOpen && inputRef.current) {
@@ -298,6 +287,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
298
287
  }
299
288
  }, [isDisabled, isOpen]);
300
289
  const clearValue = (0, react_1.useCallback)((e, option) => {
290
+ e.preventDefault();
301
291
  e.stopPropagation();
302
292
  const next = selectedValues.filter((val) => deriveValue(val) !== deriveValue(option));
303
293
  setSelectedValues(next);
@@ -327,28 +317,35 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
327
317
  }, [isMultiSelect, selectedValues, deriveValue, emitSelection]);
328
318
  const showLoading = isLoading || internalLoading;
329
319
  const handleAddIconClick = (0, react_1.useCallback)((e) => {
320
+ e.preventDefault();
330
321
  e.stopPropagation();
331
322
  if (onAddClick) {
332
323
  onAddClick(true);
333
324
  }
334
325
  }, [onAddClick]);
326
+ const handleTriggerClick = (0, react_1.useCallback)((e) => {
327
+ e.preventDefault();
328
+ if (!isDisabled) {
329
+ setIsOpen((prev) => !prev);
330
+ if (!isOpen && inputRef.current) {
331
+ inputRef.current.focus();
332
+ }
333
+ }
334
+ }, [isDisabled, isOpen]);
335
335
  return (react_1.default.createElement("div", { ref: containerRef, className: `relative w-full ${className} ${styles.container}`, onKeyDown: handleKeyDown },
336
336
  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 },
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: handleTriggerClick },
338
338
  react_1.default.createElement("div", { className: "flex-grow flex items-center overflow-x-auto no-scrollbar" },
339
339
  react_1.default.createElement("div", { className: "flex items-center gap-2 flex-nowrap" },
340
340
  selectedValues.length > 0 &&
341
341
  selectedValues.map((val) => (react_1.default.createElement("div", { key: deriveValue(val), className: "flex-shrink-0 flex items-center bg-gray-200 rounded-md px-2 py-1" },
342
342
  react_1.default.createElement("span", { className: "truncate" }, deriveLabel(val)),
343
- react_1.default.createElement("button", { onClick: (e) => clearValue(e, val), className: styles.clearButton }, renderIcon(icons.clear, styles.icon))))),
343
+ react_1.default.createElement("button", { type: "button", onClick: (e) => clearValue(e, val), className: styles.clearButton }, renderIcon(icons.clear, styles.icon))))),
344
344
  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() }))),
345
345
  react_1.default.createElement("div", { className: "flex-shrink-0 flex items-center gap-1 ml-2" },
346
- iconSrc.hasAdd && (react_1.default.createElement("button", { onClick: handleAddIconClick, className: styles.clearButton }, renderIcon(iconSrc.hasAdd, styles.icon))),
346
+ iconSrc.hasAdd && (react_1.default.createElement("button", { type: "button", onClick: handleAddIconClick, className: styles.clearButton }, renderIcon(iconSrc.hasAdd, styles.icon))),
347
347
  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
348
+ react_1.default.createElement("button", { type: "button", onClick: toggleDropdown }, isOpen
352
349
  ? renderIcon(iconSrc.dropdownOpen, `${styles.icon} ${styles.spinAnimation || ''}`)
353
350
  : renderIcon(iconSrc.dropdownClosed, styles.icon)))),
354
351
  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.5",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {