kiban-design-system 1.1.8 → 1.1.9
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 +109 -38
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +109 -38
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -16191,10 +16191,43 @@ const AlphaInputDate = ({
|
|
|
16191
16191
|
year: reference.getFullYear()
|
|
16192
16192
|
};
|
|
16193
16193
|
});
|
|
16194
|
-
const
|
|
16194
|
+
const initialDateState = (() => {
|
|
16195
|
+
if (value) {
|
|
16196
|
+
const validDate = getValidDate(value);
|
|
16197
|
+
if (validDate) {
|
|
16198
|
+
const normalizedDate = normalizeDate(validDate.start);
|
|
16199
|
+
return {
|
|
16200
|
+
selectedDate: {
|
|
16201
|
+
start: normalizedDate,
|
|
16202
|
+
end: normalizedDate
|
|
16203
|
+
},
|
|
16204
|
+
inputValue: formatDate(normalizedDate) || ""
|
|
16205
|
+
};
|
|
16206
|
+
}
|
|
16207
|
+
}
|
|
16208
|
+
return {
|
|
16209
|
+
selectedDate: null,
|
|
16210
|
+
inputValue: undefined
|
|
16211
|
+
};
|
|
16212
|
+
})();
|
|
16213
|
+
const [inputValue, setInputValue] = React2.useState(initialDateState.inputValue);
|
|
16195
16214
|
const [isErrorTooltipActive, setIsErrorTooltipActive] = React2.useState(false);
|
|
16196
|
-
const [selectedDate, setSelectedDate] = React2.useState();
|
|
16215
|
+
const [selectedDate, setSelectedDate] = React2.useState(initialDateState.selectedDate);
|
|
16197
16216
|
const inputRef = React2.useRef(null);
|
|
16217
|
+
const isInternalUpdateRef = React2.useRef(false);
|
|
16218
|
+
const lastValueRef = React2.useRef(initialDateState.inputValue || value);
|
|
16219
|
+
const onChangeRef = React2.useRef(onChange);
|
|
16220
|
+
const isMountedRef = React2.useRef(false);
|
|
16221
|
+
|
|
16222
|
+
// Actualizar la referencia de onChange cuando cambia
|
|
16223
|
+
React2.useEffect(() => {
|
|
16224
|
+
onChangeRef.current = onChange;
|
|
16225
|
+
}, [onChange]);
|
|
16226
|
+
|
|
16227
|
+
// Marcar que el componente está montado después del primer render
|
|
16228
|
+
React2.useEffect(() => {
|
|
16229
|
+
isMountedRef.current = true;
|
|
16230
|
+
}, []);
|
|
16198
16231
|
const className = cssClassName(COMPONENT_NAME$s);
|
|
16199
16232
|
const normalizedMinDate = React2.useMemo(() => minDate ? normalizeDate(minDate) : undefined, [minDate]);
|
|
16200
16233
|
const normalizedMaxDate = React2.useMemo(() => maxDate ? normalizeDate(maxDate) : undefined, [maxDate]);
|
|
@@ -16205,13 +16238,22 @@ const AlphaInputDate = ({
|
|
|
16205
16238
|
});
|
|
16206
16239
|
};
|
|
16207
16240
|
const handleDateChange = date => {
|
|
16208
|
-
|
|
16209
|
-
|
|
16210
|
-
}
|
|
16241
|
+
const normalizedDate = normalizeDate(date.start);
|
|
16242
|
+
isInternalUpdateRef.current = true;
|
|
16211
16243
|
setSelectedDate({
|
|
16212
|
-
start:
|
|
16213
|
-
end:
|
|
16244
|
+
start: normalizedDate,
|
|
16245
|
+
end: normalizedDate
|
|
16246
|
+
});
|
|
16247
|
+
setInputValue(formatDate(normalizedDate) || "");
|
|
16248
|
+
setDate({
|
|
16249
|
+
month: normalizedDate.getMonth(),
|
|
16250
|
+
year: normalizedDate.getFullYear()
|
|
16214
16251
|
});
|
|
16252
|
+
lastValueRef.current = formatDate(normalizedDate) || undefined;
|
|
16253
|
+
if (onChangeRef.current && isMountedRef.current) {
|
|
16254
|
+
onChangeRef.current(normalizedDate);
|
|
16255
|
+
}
|
|
16256
|
+
isInternalUpdateRef.current = false;
|
|
16215
16257
|
setIsPopoverActive(false);
|
|
16216
16258
|
};
|
|
16217
16259
|
const handlePaste = e => {
|
|
@@ -16257,20 +16299,39 @@ const AlphaInputDate = ({
|
|
|
16257
16299
|
onBlur();
|
|
16258
16300
|
}
|
|
16259
16301
|
};
|
|
16302
|
+
|
|
16303
|
+
// Sincronizar value externo con selectedDate (solo cuando value cambia externamente)
|
|
16260
16304
|
React2.useEffect(() => {
|
|
16261
|
-
if (
|
|
16262
|
-
|
|
16263
|
-
setSelectedDate(validDate || null);
|
|
16305
|
+
if (isInternalUpdateRef.current) {
|
|
16306
|
+
return;
|
|
16264
16307
|
}
|
|
16265
|
-
if (
|
|
16266
|
-
|
|
16267
|
-
|
|
16268
|
-
|
|
16269
|
-
|
|
16270
|
-
|
|
16271
|
-
|
|
16308
|
+
if (value !== lastValueRef.current) {
|
|
16309
|
+
lastValueRef.current = value;
|
|
16310
|
+
if (value !== undefined && value !== null && value !== "") {
|
|
16311
|
+
const validDate = getValidDate(value);
|
|
16312
|
+
if (validDate) {
|
|
16313
|
+
const normalizedDate = normalizeDate(validDate.start);
|
|
16314
|
+
setSelectedDate({
|
|
16315
|
+
start: normalizedDate,
|
|
16316
|
+
end: normalizedDate
|
|
16317
|
+
});
|
|
16318
|
+
setInputValue(formatDate(normalizedDate) || "");
|
|
16319
|
+
setDate({
|
|
16320
|
+
month: normalizedDate.getMonth(),
|
|
16321
|
+
year: normalizedDate.getFullYear()
|
|
16322
|
+
});
|
|
16323
|
+
}
|
|
16324
|
+
} else if (!value) {
|
|
16325
|
+
const fallback = normalizedMaxDate ?? normalizeDate();
|
|
16326
|
+
setDate({
|
|
16327
|
+
month: fallback.getMonth(),
|
|
16328
|
+
year: fallback.getFullYear()
|
|
16329
|
+
});
|
|
16330
|
+
setSelectedDate(null);
|
|
16331
|
+
setInputValue("");
|
|
16332
|
+
}
|
|
16272
16333
|
}
|
|
16273
|
-
}, [value,
|
|
16334
|
+
}, [value, normalizedMaxDate]);
|
|
16274
16335
|
React2.useEffect(() => {
|
|
16275
16336
|
if (inputRef.current) {
|
|
16276
16337
|
inputRef.current.querySelector("input")?.addEventListener("paste", handlePaste);
|
|
@@ -16281,33 +16342,43 @@ const AlphaInputDate = ({
|
|
|
16281
16342
|
}
|
|
16282
16343
|
};
|
|
16283
16344
|
}, []);
|
|
16345
|
+
|
|
16346
|
+
// Sincronizar inputValue con selectedDate cuando el usuario escribe
|
|
16284
16347
|
React2.useEffect(() => {
|
|
16285
|
-
if (inputValue
|
|
16286
|
-
|
|
16287
|
-
if (validDate) {
|
|
16288
|
-
setSelectedDate(validDate);
|
|
16289
|
-
} else {
|
|
16290
|
-
setSelectedDate(null);
|
|
16291
|
-
}
|
|
16348
|
+
if (isInternalUpdateRef.current || inputValue === undefined || !isMountedRef.current) {
|
|
16349
|
+
return;
|
|
16292
16350
|
}
|
|
16293
|
-
|
|
16294
|
-
|
|
16295
|
-
|
|
16296
|
-
|
|
16297
|
-
|
|
16351
|
+
const validDate = getValidDate(inputValue);
|
|
16352
|
+
if (validDate) {
|
|
16353
|
+
const normalizedDate = normalizeDate(validDate.start);
|
|
16354
|
+
const formattedDate = formatDate(normalizedDate) || undefined;
|
|
16355
|
+
// Solo actualizar si el valor formateado es diferente al último valor conocido
|
|
16356
|
+
if (formattedDate !== lastValueRef.current) {
|
|
16357
|
+
isInternalUpdateRef.current = true;
|
|
16358
|
+
setSelectedDate({
|
|
16359
|
+
start: normalizedDate,
|
|
16360
|
+
end: normalizedDate
|
|
16361
|
+
});
|
|
16298
16362
|
setDate({
|
|
16299
|
-
month:
|
|
16300
|
-
year:
|
|
16363
|
+
month: normalizedDate.getMonth(),
|
|
16364
|
+
year: normalizedDate.getFullYear()
|
|
16301
16365
|
});
|
|
16302
|
-
|
|
16303
|
-
if (
|
|
16304
|
-
|
|
16366
|
+
lastValueRef.current = formattedDate;
|
|
16367
|
+
if (onChangeRef.current) {
|
|
16368
|
+
onChangeRef.current(normalizedDate);
|
|
16305
16369
|
}
|
|
16306
|
-
|
|
16307
|
-
onChange(null);
|
|
16370
|
+
isInternalUpdateRef.current = false;
|
|
16308
16371
|
}
|
|
16372
|
+
} else if (inputValue === "" && lastValueRef.current !== undefined) {
|
|
16373
|
+
isInternalUpdateRef.current = true;
|
|
16374
|
+
setSelectedDate(null);
|
|
16375
|
+
lastValueRef.current = undefined;
|
|
16376
|
+
if (onChangeRef.current) {
|
|
16377
|
+
onChangeRef.current(null);
|
|
16378
|
+
}
|
|
16379
|
+
isInternalUpdateRef.current = false;
|
|
16309
16380
|
}
|
|
16310
|
-
}, [
|
|
16381
|
+
}, [inputValue]);
|
|
16311
16382
|
React2.useEffect(() => {
|
|
16312
16383
|
if (!selectedDate && normalizedMaxDate) {
|
|
16313
16384
|
setDate(prevDate => {
|