trotl-filter 1.0.41 → 1.0.43

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.
package/dist/index.cjs.js CHANGED
@@ -9050,18 +9050,20 @@ function DateTimeInput({
9050
9050
  };
9051
9051
  }
9052
9052
  const paramKey = pushUrlParamObj || null;
9053
+ const isControlled = typeof controlledValue !== "undefined";
9054
+ const normalizedControlledValue = isControlled ? controlledValue ?? "" : undefined;
9053
9055
 
9054
9056
  // Refs to stabilize callbacks and prevent re-entrant URL updates
9055
9057
  const onChangeRef = React.useRef(onChange);
9056
- const controlledValueRef = React.useRef(controlledValue);
9058
+ const controlledValueRef = React.useRef(normalizedControlledValue);
9057
9059
  const isUpdatingFromComponentRef = React.useRef(false);
9058
9060
  const lastUrlValueRef = React.useRef(null);
9059
9061
  React.useEffect(() => {
9060
9062
  onChangeRef.current = onChange;
9061
9063
  }, [onChange]);
9062
9064
  React.useEffect(() => {
9063
- controlledValueRef.current = controlledValue;
9064
- }, [controlledValue]);
9065
+ controlledValueRef.current = normalizedControlledValue;
9066
+ }, [normalizedControlledValue]);
9065
9067
 
9066
9068
  // Helper: convert timestamp (number|string) to internal input string
9067
9069
  const toInputString = React.useCallback(ts => {
@@ -9087,7 +9089,7 @@ function DateTimeInput({
9087
9089
 
9088
9090
  // Initial value
9089
9091
  const [value, setValue] = React.useState(() => {
9090
- if (typeof controlledValue !== "undefined") return controlledValue;
9092
+ if (isControlled) return normalizedControlledValue;
9091
9093
  if (!paramKey) {
9092
9094
  let d = new Date();
9093
9095
  if (time && timeStart) {
@@ -9240,23 +9242,32 @@ function DateTimeInput({
9240
9242
  return new Date(d.getFullYear(), d.getMonth(), 1, 0, 0, 0, 0);
9241
9243
  });
9242
9244
  // Keep monthCursor in sync when selected date changes externally
9245
+ // Guard updates so changing references (e.g. PREDEFINED array identity) doesn't force state
9243
9246
  React.useEffect(() => {
9244
9247
  if (selectedDate) {
9245
- setMonthCursor(new Date(selectedDate.getFullYear(), selectedDate.getMonth(), 1));
9246
- }
9247
- // Match predefined
9248
- if (selectedDate) {
9248
+ const newMonth = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), 1);
9249
+ // only update monthCursor when month/year actually differ
9250
+ setMonthCursor(prev => {
9251
+ if (!prev || prev.getFullYear() !== newMonth.getFullYear() || prev.getMonth() !== newMonth.getMonth()) {
9252
+ return newMonth;
9253
+ }
9254
+ return prev;
9255
+ });
9256
+
9257
+ // Match predefined: set only when value actually changes
9249
9258
  const ts = selectedDate.getTime();
9259
+ let matched = false;
9250
9260
  for (let i = 0; i < PREDEFINED.length; i++) {
9251
9261
  const d = PREDEFINED[i].getDate();
9252
9262
  if (d.getTime() === ts) {
9253
- setSelectedPredefined(String(i));
9254
- return;
9263
+ setSelectedPredefined(prev => prev !== String(i) ? String(i) : prev);
9264
+ matched = true;
9265
+ break;
9255
9266
  }
9256
9267
  }
9257
- setSelectedPredefined("");
9268
+ if (!matched) setSelectedPredefined(prev => prev !== "" ? "" : prev);
9258
9269
  } else {
9259
- setSelectedPredefined("");
9270
+ setSelectedPredefined(prev => prev !== "" ? "" : prev);
9260
9271
  }
9261
9272
  }, [value, selectedDate, PREDEFINED]);
9262
9273
 
@@ -9346,8 +9357,10 @@ function DateTimeInput({
9346
9357
 
9347
9358
  // Controlled value sync
9348
9359
  React.useEffect(() => {
9349
- if (typeof controlledValue !== 'undefined') setValue(controlledValue);
9350
- }, [controlledValue]);
9360
+ if (isControlled) {
9361
+ setValue(prev => prev !== normalizedControlledValue ? normalizedControlledValue : prev);
9362
+ }
9363
+ }, [isControlled, normalizedControlledValue]);
9351
9364
 
9352
9365
  // Formatting display (similar to RangePicker)
9353
9366
  const formatDisplay = () => {
@@ -9376,7 +9389,7 @@ function DateTimeInput({
9376
9389
  dt.setHours(Number(h), Number(m), 0, 0);
9377
9390
  }
9378
9391
  const str = toInputString(dt.getTime());
9379
- if (typeof controlledValue === 'undefined') setValue(str);
9392
+ if (!isControlled) setValue(str);
9380
9393
  setUrlParam(str);
9381
9394
  onChange?.(str);
9382
9395
  };
@@ -9400,12 +9413,12 @@ function DateTimeInput({
9400
9413
  const [h, m] = t.split(":");
9401
9414
  d.setHours(Number(h), Number(m), 0, 0);
9402
9415
  const str = toInputString(d.getTime());
9403
- if (typeof controlledValue === 'undefined') setValue(str);
9416
+ if (!isControlled) setValue(str);
9404
9417
  setUrlParam(str);
9405
9418
  onChange?.(str);
9406
9419
  };
9407
9420
  const handleClear = () => {
9408
- if (typeof controlledValue === 'undefined') setValue("");
9421
+ if (!isControlled) setValue("");
9409
9422
  setUrlParam("");
9410
9423
  onChange?.("");
9411
9424
  };