@mui/x-date-pickers
Version:
The community edition of the Date and Time Picker components (MUI X).
52 lines • 2.34 kB
JavaScript
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["value", "referenceDate"];
import { areDatesEqual, getTodayDate, replaceInvalidDateByNull } from "./date-utils.js";
import { getDefaultReferenceDate } from "./getDefaultReferenceDate.js";
import { createDateStrForV7HiddenInputFromSections, createDateStrForV6InputFromSections } from "../hooks/useField/useField.utils.js";
export const singleItemValueManager = {
emptyValue: null,
getTodayValue: getTodayDate,
getInitialReferenceValue: _ref => {
let {
value,
referenceDate
} = _ref,
params = _objectWithoutPropertiesLoose(_ref, _excluded);
if (value != null && params.utils.isValid(value)) {
return value;
}
if (referenceDate != null) {
return referenceDate;
}
return getDefaultReferenceDate(params);
},
cleanValue: replaceInvalidDateByNull,
areValuesEqual: areDatesEqual,
isSameError: (a, b) => a === b,
hasError: error => error != null,
defaultErrorState: null,
getTimezone: (utils, value) => value == null || !utils.isValid(value) ? null : utils.getTimezone(value),
setTimezone: (utils, timezone, value) => value == null ? null : utils.setTimezone(value, timezone)
};
export const singleItemFieldValueManager = {
updateReferenceValue: (utils, value, prevReferenceValue) => value == null || !utils.isValid(value) ? prevReferenceValue : value,
getSectionsFromValue: (utils, date, prevSections, getSectionsFromDate) => {
const shouldReUsePrevDateSections = !utils.isValid(date) && !!prevSections;
if (shouldReUsePrevDateSections) {
return prevSections;
}
return getSectionsFromDate(date);
},
getV7HiddenInputValueFromSections: createDateStrForV7HiddenInputFromSections,
getV6InputValueFromSections: createDateStrForV6InputFromSections,
getActiveDateManager: (utils, state) => ({
date: state.value,
referenceDate: state.referenceValue,
getSections: sections => sections,
getNewValuesFromNewActiveDate: newActiveDate => ({
value: newActiveDate,
referenceValue: newActiveDate == null || !utils.isValid(newActiveDate) ? state.referenceValue : newActiveDate
})
}),
parseValueStr: (valueStr, referenceValue, parseDate) => parseDate(valueStr.trim(), referenceValue)
};