hi-tm 0.7.1 → 0.7.2

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.
@@ -135,6 +135,7 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
135
135
  const containerRef = (0, react_1.useRef)(null);
136
136
  const inputRef = (0, react_1.useRef)(null);
137
137
  const scrollContainerRef = (0, react_1.useRef)(null);
138
+ const isProcessingRef = (0, react_1.useRef)(false);
138
139
  // Prevent scroll jumping by maintaining position during keyboard navigation
139
140
  const handleKeyboardNavigation = (0, react_1.useCallback)((direction) => {
140
141
  // Set user interaction flag to prevent external sync
@@ -169,6 +170,11 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
169
170
  // Only sync if the external value is actually different from current selectedValues
170
171
  const currentValues = selectedValues;
171
172
  const externalValue = value;
173
+ // Early return if values are already the same
174
+ if (JSON.stringify(externalValue) === JSON.stringify(currentValues)) {
175
+ console.log('Values are already the same, skipping sync');
176
+ return;
177
+ }
172
178
  if (externalValue === null || externalValue === undefined) {
173
179
  if (currentValues.length > 0) {
174
180
  console.log('Setting selectedValues to empty array');
@@ -178,26 +184,19 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
178
184
  else if (Array.isArray(externalValue)) {
179
185
  if (isMultiSelect) {
180
186
  const externalArray = externalValue;
181
- // Only update if the arrays are actually different
182
- if (JSON.stringify(externalArray) !== JSON.stringify(currentValues)) {
183
- console.log('Setting selectedValues to array:', externalArray);
184
- setSelectedValues(externalArray);
185
- }
187
+ console.log('Setting selectedValues to array:', externalArray);
188
+ setSelectedValues(externalArray);
186
189
  }
187
190
  else {
188
191
  const firstItem = externalValue.length > 0 ? [externalValue[0]] : [];
189
- if (JSON.stringify(firstItem) !== JSON.stringify(currentValues)) {
190
- console.log('Setting selectedValues to first item of array:', firstItem);
191
- setSelectedValues(firstItem);
192
- }
192
+ console.log('Setting selectedValues to first item of array:', firstItem);
193
+ setSelectedValues(firstItem);
193
194
  }
194
195
  }
195
196
  else {
196
197
  const singleItem = [externalValue];
197
- if (JSON.stringify(singleItem) !== JSON.stringify(currentValues)) {
198
- console.log('Setting selectedValues to single item:', singleItem);
199
- setSelectedValues(singleItem);
200
- }
198
+ console.log('Setting selectedValues to single item:', singleItem);
199
+ setSelectedValues(singleItem);
201
200
  }
202
201
  console.log('=== useEffect sync completed ===');
203
202
  }, [value, isMultiSelect, isUserInteracting]);
@@ -270,9 +269,15 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
270
269
  console.log('current selectedValues:', selectedValues);
271
270
  if (isDisabled)
272
271
  return;
272
+ // Prevent double calls by checking if we're already processing
273
+ if (isProcessingRef.current) {
274
+ console.log('Already processing keyboard event, skipping...');
275
+ return;
276
+ }
273
277
  // Set user interaction flag for all keyboard events
274
278
  console.log('Setting isUserInteracting to true');
275
279
  setIsUserInteracting(true);
280
+ isProcessingRef.current = true;
276
281
  switch (e.key) {
277
282
  case 'Enter':
278
283
  e.preventDefault();
@@ -314,11 +319,12 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
314
319
  }
315
320
  break;
316
321
  }
317
- // Reset the flag after a delay
322
+ // Reset the flags after a delay
318
323
  setTimeout(() => {
319
324
  console.log('Resetting isUserInteracting to false');
320
325
  setIsUserInteracting(false);
321
- }, 1000);
326
+ isProcessingRef.current = false;
327
+ }, 2000); // Increased to 2 seconds
322
328
  }, [
323
329
  isDisabled,
324
330
  isOpen,
@@ -367,17 +373,24 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
367
373
  console.log('current isOpen:', isOpen);
368
374
  console.log('current selectedValues:', selectedValues);
369
375
  if (!isDisabled) {
376
+ // Prevent double calls by checking if we're already processing
377
+ if (isProcessingRef.current) {
378
+ console.log('Already processing, skipping...');
379
+ return;
380
+ }
370
381
  console.log('Setting isUserInteracting to true');
371
382
  setIsUserInteracting(true);
383
+ isProcessingRef.current = true;
372
384
  setIsOpen((prev) => !prev);
373
385
  if (!isOpen && inputRef.current) {
374
386
  inputRef.current.focus();
375
387
  }
376
- // Reset the flag after a delay
388
+ // Reset the flags after a longer delay to prevent conflicts
377
389
  setTimeout(() => {
378
390
  console.log('Resetting isUserInteracting to false');
379
391
  setIsUserInteracting(false);
380
- }, 1000);
392
+ isProcessingRef.current = false;
393
+ }, 2000); // Increased to 2 seconds
381
394
  }
382
395
  }, [isDisabled, isOpen, selectedValues]);
383
396
  const clearValue = (0, react_1.useCallback)((e, option) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {