indicator-ui 0.0.133 → 0.0.134
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.js
CHANGED
|
@@ -9263,26 +9263,26 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
9263
9263
|
|
|
9264
9264
|
|
|
9265
9265
|
function DateTimeField({ value, fieldConfig = 'datetime', onChange, dateFormat = 'dd.MM.yyyy', timeFormat = 'HH:mm', outFormat = 'iso-8601', additionStyle, datePlaceholder, timePlaceholder, timeZone = 'Z', ...props }) {
|
|
9266
|
-
const
|
|
9266
|
+
const getValueInDate = () => {
|
|
9267
9267
|
if (value === undefined)
|
|
9268
9268
|
return undefined;
|
|
9269
9269
|
let resFormat = outFormat === 'iso-8601' ? _consts__WEBPACK_IMPORTED_MODULE_4__.ISO_FORMAT : outFormat;
|
|
9270
9270
|
return (0,_lib__WEBPACK_IMPORTED_MODULE_3__.saveParseDate)(value, { from: resFormat, fromTimeZone: timeZone });
|
|
9271
9271
|
};
|
|
9272
|
-
const
|
|
9272
|
+
const getDateFromValue = () => {
|
|
9273
9273
|
if (fieldConfig === 'time' || value === undefined)
|
|
9274
9274
|
return undefined;
|
|
9275
|
-
const curDate =
|
|
9275
|
+
const curDate = getValueInDate();
|
|
9276
9276
|
return (0,_lib__WEBPACK_IMPORTED_MODULE_3__.saveFormatDate)(curDate, {
|
|
9277
9277
|
to: dateFormat,
|
|
9278
9278
|
errorNull: true,
|
|
9279
9279
|
toTimeZone: timeZone,
|
|
9280
9280
|
}) ?? undefined;
|
|
9281
9281
|
};
|
|
9282
|
-
const
|
|
9282
|
+
const getTimeFromValue = () => {
|
|
9283
9283
|
if (fieldConfig === 'date' || value === undefined)
|
|
9284
9284
|
return undefined;
|
|
9285
|
-
const curDate =
|
|
9285
|
+
const curDate = getValueInDate();
|
|
9286
9286
|
return (0,_lib__WEBPACK_IMPORTED_MODULE_3__.saveFormatDate)(curDate, {
|
|
9287
9287
|
to: timeFormat,
|
|
9288
9288
|
errorNull: true,
|
|
@@ -9306,26 +9306,64 @@ function DateTimeField({ value, fieldConfig = 'datetime', onChange, dateFormat =
|
|
|
9306
9306
|
res.setDate(dateTime.getDate());
|
|
9307
9307
|
}
|
|
9308
9308
|
};
|
|
9309
|
-
const
|
|
9309
|
+
const getDateTimeFormatValue = (newValue) => {
|
|
9310
|
+
if (newValue == null)
|
|
9311
|
+
return null;
|
|
9312
|
+
let dateFormat = '';
|
|
9313
|
+
if (outFormat === 'iso-8601') {
|
|
9314
|
+
dateFormat = _consts__WEBPACK_IMPORTED_MODULE_4__.ISO_FORMAT;
|
|
9315
|
+
}
|
|
9316
|
+
else {
|
|
9317
|
+
dateFormat = outFormat;
|
|
9318
|
+
}
|
|
9319
|
+
const res = (0,_lib__WEBPACK_IMPORTED_MODULE_3__.saveFormatDate)(newValue, {
|
|
9320
|
+
to: dateFormat,
|
|
9321
|
+
toTimeZone: timeZone,
|
|
9322
|
+
});
|
|
9323
|
+
if (typeof res === 'string') {
|
|
9324
|
+
return res;
|
|
9325
|
+
}
|
|
9326
|
+
return null;
|
|
9327
|
+
};
|
|
9328
|
+
const getDateTimeValue = () => {
|
|
9329
|
+
let resDate = new Date();
|
|
9330
|
+
switch (fieldConfig) {
|
|
9331
|
+
case 'datetime':
|
|
9332
|
+
if (time && date) {
|
|
9333
|
+
setDateInDate(resDate, date);
|
|
9334
|
+
setTimeInDate(resDate, time);
|
|
9335
|
+
}
|
|
9336
|
+
break;
|
|
9337
|
+
case 'date':
|
|
9338
|
+
if (date) {
|
|
9339
|
+
setDateInDate(resDate, date);
|
|
9340
|
+
}
|
|
9341
|
+
break;
|
|
9342
|
+
case 'time':
|
|
9343
|
+
if (time) {
|
|
9344
|
+
setTimeInDate(resDate, time);
|
|
9345
|
+
}
|
|
9346
|
+
break;
|
|
9347
|
+
}
|
|
9348
|
+
return resDate;
|
|
9349
|
+
};
|
|
9350
|
+
const changeValue = (newValue) => {
|
|
9310
9351
|
if (onChange && newValue) {
|
|
9311
|
-
|
|
9312
|
-
if (
|
|
9313
|
-
|
|
9314
|
-
}
|
|
9315
|
-
else {
|
|
9316
|
-
dateFormat = outFormat;
|
|
9317
|
-
}
|
|
9318
|
-
const res = (0,_lib__WEBPACK_IMPORTED_MODULE_3__.saveFormatDate)(newValue, {
|
|
9319
|
-
to: dateFormat,
|
|
9320
|
-
toTimeZone: timeZone,
|
|
9321
|
-
});
|
|
9322
|
-
if (res != null && typeof res === 'string') {
|
|
9323
|
-
onChange(res);
|
|
9352
|
+
const formatValue = getDateTimeFormatValue(newValue);
|
|
9353
|
+
if (formatValue != null) {
|
|
9354
|
+
onChange(formatValue);
|
|
9324
9355
|
}
|
|
9325
9356
|
}
|
|
9326
9357
|
};
|
|
9327
|
-
const [time, setTime] = (0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(
|
|
9328
|
-
const [date, setDate] = (0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(
|
|
9358
|
+
const [time, setTime] = (0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(getTimeFromValue());
|
|
9359
|
+
const [date, setDate] = (0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(getDateFromValue());
|
|
9360
|
+
(0,react__WEBPACK_IMPORTED_MODULE_1__.useEffect)(() => {
|
|
9361
|
+
const curValue = getDateTimeFormatValue(getDateTimeValue());
|
|
9362
|
+
if (value !== curValue) {
|
|
9363
|
+
setTime(getTimeFromValue());
|
|
9364
|
+
setDate(getDateFromValue());
|
|
9365
|
+
}
|
|
9366
|
+
}, [value]);
|
|
9329
9367
|
(0,react__WEBPACK_IMPORTED_MODULE_1__.useEffect)(() => {
|
|
9330
9368
|
if (
|
|
9331
9369
|
// Проверка пустого значения
|
|
@@ -9335,26 +9373,8 @@ function DateTimeField({ value, fieldConfig = 'datetime', onChange, dateFormat =
|
|
|
9335
9373
|
onChange('');
|
|
9336
9374
|
}
|
|
9337
9375
|
else if (time || date) {
|
|
9338
|
-
|
|
9339
|
-
|
|
9340
|
-
case 'datetime':
|
|
9341
|
-
if (time && date) {
|
|
9342
|
-
setDateInDate(resDate, date);
|
|
9343
|
-
setTimeInDate(resDate, time);
|
|
9344
|
-
}
|
|
9345
|
-
break;
|
|
9346
|
-
case 'date':
|
|
9347
|
-
if (date) {
|
|
9348
|
-
setDateInDate(resDate, date);
|
|
9349
|
-
}
|
|
9350
|
-
break;
|
|
9351
|
-
case 'time':
|
|
9352
|
-
if (time) {
|
|
9353
|
-
setTimeInDate(resDate, time);
|
|
9354
|
-
}
|
|
9355
|
-
break;
|
|
9356
|
-
}
|
|
9357
|
-
setDateValue(resDate);
|
|
9376
|
+
const resDate = getDateTimeValue();
|
|
9377
|
+
changeValue(resDate);
|
|
9358
9378
|
}
|
|
9359
9379
|
}, [time, date]);
|
|
9360
9380
|
const getTimeContent = () => {
|