hi-tm 0.7.0 → 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
@@ -155,15 +156,25 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
155
156
  }, [filteredOptions.length]);
156
157
  // Sync external value prop with internal selectedValues state
157
158
  (0, react_1.useEffect)(() => {
159
+ console.log('=== useEffect sync triggered ===');
160
+ console.log('isUserInteracting:', isUserInteracting);
161
+ console.log('external value:', value);
162
+ console.log('current selectedValues:', selectedValues);
163
+ console.log('isMultiSelect:', isMultiSelect);
158
164
  // Don't sync if user is actively interacting with the component
159
165
  if (isUserInteracting) {
160
166
  console.log('Skipping sync - user is interacting');
161
167
  return;
162
168
  }
163
- console.log('useEffect triggered with value:', value, 'isMultiSelect:', isMultiSelect);
169
+ console.log('Proceeding with sync...');
164
170
  // Only sync if the external value is actually different from current selectedValues
165
171
  const currentValues = selectedValues;
166
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
+ }
167
178
  if (externalValue === null || externalValue === undefined) {
168
179
  if (currentValues.length > 0) {
169
180
  console.log('Setting selectedValues to empty array');
@@ -173,27 +184,21 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
173
184
  else if (Array.isArray(externalValue)) {
174
185
  if (isMultiSelect) {
175
186
  const externalArray = externalValue;
176
- // Only update if the arrays are actually different
177
- if (JSON.stringify(externalArray) !== JSON.stringify(currentValues)) {
178
- console.log('Setting selectedValues to array:', externalArray);
179
- setSelectedValues(externalArray);
180
- }
187
+ console.log('Setting selectedValues to array:', externalArray);
188
+ setSelectedValues(externalArray);
181
189
  }
182
190
  else {
183
191
  const firstItem = externalValue.length > 0 ? [externalValue[0]] : [];
184
- if (JSON.stringify(firstItem) !== JSON.stringify(currentValues)) {
185
- console.log('Setting selectedValues to first item of array:', firstItem);
186
- setSelectedValues(firstItem);
187
- }
192
+ console.log('Setting selectedValues to first item of array:', firstItem);
193
+ setSelectedValues(firstItem);
188
194
  }
189
195
  }
190
196
  else {
191
197
  const singleItem = [externalValue];
192
- if (JSON.stringify(singleItem) !== JSON.stringify(currentValues)) {
193
- console.log('Setting selectedValues to single item:', singleItem);
194
- setSelectedValues(singleItem);
195
- }
198
+ console.log('Setting selectedValues to single item:', singleItem);
199
+ setSelectedValues(singleItem);
196
200
  }
201
+ console.log('=== useEffect sync completed ===');
197
202
  }, [value, isMultiSelect, isUserInteracting]);
198
203
  // Sync options into filtered list when not searching
199
204
  (0, react_1.useEffect)(() => {
@@ -208,6 +213,12 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
208
213
  setHasSearched(false);
209
214
  }
210
215
  }, [options, inputValue]);
216
+ // Debug: Log when selectedValues changes
217
+ (0, react_1.useEffect)(() => {
218
+ console.log('=== selectedValues changed ===');
219
+ console.log('New selectedValues:', selectedValues);
220
+ console.log('Stack trace:', new Error().stack);
221
+ }, [selectedValues]);
211
222
  // Close on outside click
212
223
  (0, react_1.useEffect)(() => {
213
224
  const handler = (e) => {
@@ -252,10 +263,21 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
252
263
  }
253
264
  }, [onChange, fetchOptions, options, deriveLabel]);
254
265
  const handleKeyDown = (0, react_1.useCallback)((e) => {
266
+ console.log('=== handleKeyDown called ===');
267
+ console.log('key:', e.key);
268
+ console.log('isDisabled:', isDisabled);
269
+ console.log('current selectedValues:', selectedValues);
255
270
  if (isDisabled)
256
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
+ }
257
277
  // Set user interaction flag for all keyboard events
278
+ console.log('Setting isUserInteracting to true');
258
279
  setIsUserInteracting(true);
280
+ isProcessingRef.current = true;
259
281
  switch (e.key) {
260
282
  case 'Enter':
261
283
  e.preventDefault();
@@ -297,10 +319,12 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
297
319
  }
298
320
  break;
299
321
  }
300
- // Reset the flag after a delay
322
+ // Reset the flags after a delay
301
323
  setTimeout(() => {
324
+ console.log('Resetting isUserInteracting to false');
302
325
  setIsUserInteracting(false);
303
- }, 1000);
326
+ isProcessingRef.current = false;
327
+ }, 2000); // Increased to 2 seconds
304
328
  }, [
305
329
  isDisabled,
306
330
  isOpen,
@@ -309,6 +333,7 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
309
333
  deriveLabel,
310
334
  handleKeyboardNavigation,
311
335
  isCreatable,
336
+ selectedValues,
312
337
  ]);
313
338
  const emitSelection = (0, react_1.useCallback)((next) => {
314
339
  // Backward-compatible callback
@@ -343,18 +368,31 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
343
368
  }
344
369
  }, [inputValue, isCreatable, onCreateOption]);
345
370
  const toggleDropdown = (0, react_1.useCallback)(() => {
371
+ console.log('=== toggleDropdown called ===');
372
+ console.log('isDisabled:', isDisabled);
373
+ console.log('current isOpen:', isOpen);
374
+ console.log('current selectedValues:', selectedValues);
346
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
+ }
381
+ console.log('Setting isUserInteracting to true');
347
382
  setIsUserInteracting(true);
383
+ isProcessingRef.current = true;
348
384
  setIsOpen((prev) => !prev);
349
385
  if (!isOpen && inputRef.current) {
350
386
  inputRef.current.focus();
351
387
  }
352
- // Reset the flag after a delay
388
+ // Reset the flags after a longer delay to prevent conflicts
353
389
  setTimeout(() => {
390
+ console.log('Resetting isUserInteracting to false');
354
391
  setIsUserInteracting(false);
355
- }, 1000);
392
+ isProcessingRef.current = false;
393
+ }, 2000); // Increased to 2 seconds
356
394
  }
357
- }, [isDisabled, isOpen]);
395
+ }, [isDisabled, isOpen, selectedValues]);
358
396
  const clearValue = (0, react_1.useCallback)((e, option) => {
359
397
  e.stopPropagation();
360
398
  const next = selectedValues.filter((val) => deriveValue(val) !== deriveValue(option));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {