1
0
Fork 0

Added Statistics calculation

Statistics now show calculated values
This commit is contained in:
Techognito 2025-09-04 17:30:00 +02:00
parent fe87374e47
commit fc0f69dacb
2147 changed files with 141321 additions and 39 deletions

View file

@ -0,0 +1,11 @@
import { BaseDateValidationProps, BaseTimeValidationProps, DateTimeValidationProps, DayValidationProps, MonthValidationProps, TimeValidationProps, YearValidationProps } from "../internals/models/validation.js";
export declare const DATE_VALIDATION_PROP_NAMES: (keyof BaseDateValidationProps | keyof YearValidationProps | keyof MonthValidationProps | keyof DayValidationProps)[];
export declare const TIME_VALIDATION_PROP_NAMES: (keyof BaseTimeValidationProps | keyof TimeValidationProps | 'ampm')[];
export declare const DATE_TIME_VALIDATION_PROP_NAMES: (keyof DateTimeValidationProps)[];
/**
* Extract the validation props for the props received by a component.
* Limit the risk of forgetting some of them and reduce the bundle size.
*/
export declare const extractValidationProps: <Props extends {
[key: string]: any;
}>(props: Props) => Pick<Props, "maxDate" | "minDate" | "disablePast" | "disableFuture" | "shouldDisableYear" | "shouldDisableMonth" | "shouldDisableDate" | "minTime" | "maxTime" | "minutesStep" | "shouldDisableTime" | "disableIgnoringDatePartForTimeValidation" | "ampm" | "minDateTime" | "maxDateTime">;

View file

@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.extractValidationProps = exports.TIME_VALIDATION_PROP_NAMES = exports.DATE_VALIDATION_PROP_NAMES = exports.DATE_TIME_VALIDATION_PROP_NAMES = void 0;
const DATE_VALIDATION_PROP_NAMES = exports.DATE_VALIDATION_PROP_NAMES = ['disablePast', 'disableFuture', 'minDate', 'maxDate', 'shouldDisableDate', 'shouldDisableMonth', 'shouldDisableYear'];
const TIME_VALIDATION_PROP_NAMES = exports.TIME_VALIDATION_PROP_NAMES = ['disablePast', 'disableFuture', 'minTime', 'maxTime', 'shouldDisableTime', 'minutesStep', 'ampm', 'disableIgnoringDatePartForTimeValidation'];
const DATE_TIME_VALIDATION_PROP_NAMES = exports.DATE_TIME_VALIDATION_PROP_NAMES = ['minDateTime', 'maxDateTime'];
const VALIDATION_PROP_NAMES = [...DATE_VALIDATION_PROP_NAMES, ...TIME_VALIDATION_PROP_NAMES, ...DATE_TIME_VALIDATION_PROP_NAMES];
/**
* Extract the validation props for the props received by a component.
* Limit the risk of forgetting some of them and reduce the bundle size.
*/
const extractValidationProps = props => VALIDATION_PROP_NAMES.reduce((extractedProps, propName) => {
if (props.hasOwnProperty(propName)) {
extractedProps[propName] = props[propName];
}
return extractedProps;
}, {});
exports.extractValidationProps = extractValidationProps;

View file

@ -0,0 +1,9 @@
export { validateDate } from "./validateDate.js";
export type { ValidateDateProps } from "./validateDate.js";
export { validateTime } from "./validateTime.js";
export type { ValidateTimeProps } from "./validateTime.js";
export { validateDateTime } from "./validateDateTime.js";
export type { ValidateDateTimeProps } from "./validateDateTime.js";
export { extractValidationProps } from "./extractValidationProps.js";
export { useValidation } from "./useValidation.js";
export type { Validator, UseValidationReturnValue } from "./useValidation.js";

40
node_modules/@mui/x-date-pickers/validation/index.js generated vendored Normal file
View file

@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "extractValidationProps", {
enumerable: true,
get: function () {
return _extractValidationProps.extractValidationProps;
}
});
Object.defineProperty(exports, "useValidation", {
enumerable: true,
get: function () {
return _useValidation.useValidation;
}
});
Object.defineProperty(exports, "validateDate", {
enumerable: true,
get: function () {
return _validateDate.validateDate;
}
});
Object.defineProperty(exports, "validateDateTime", {
enumerable: true,
get: function () {
return _validateDateTime.validateDateTime;
}
});
Object.defineProperty(exports, "validateTime", {
enumerable: true,
get: function () {
return _validateTime.validateTime;
}
});
var _validateDate = require("./validateDate");
var _validateTime = require("./validateTime");
var _validateDateTime = require("./validateDateTime");
var _extractValidationProps = require("./extractValidationProps");
var _useValidation = require("./useValidation");

View file

@ -0,0 +1,67 @@
import { MuiPickersAdapter, OnErrorProps, PickersTimezone } from "../models/index.js";
import type { PickerValueManager } from "../internals/models/index.js";
import { PickerValidValue } from "../internals/models/index.js";
export type Validator<TValue extends PickerValidValue, TError, TValidationProps> = {
(params: {
adapter: MuiPickersAdapter;
value: TValue;
timezone: PickersTimezone;
props: TValidationProps;
}): TError;
valueManager: PickerValueManager<TValue, any>;
};
interface UseValidationOptions<TValue extends PickerValidValue, TError, TValidationProps extends {}> extends OnErrorProps<TValue, TError> {
/**
* The value to validate.
*/
value: TValue;
/**
* The timezone to use for the validation.
*/
timezone: PickersTimezone;
/**
* The validator function to use.
* They can be imported from `@mui/x-date-pickers/validation` and `@mui/x-date-pickers-pro/validation`.
* It is recommended to only use the validator exported by the MUI X packages,
* otherwise you may have inconsistent behaviors between the field and the views.
*/
validator: Validator<TValue, TError, TValidationProps>;
/**
* The validation props, they differ depending on the component.
* For example, the `validateTime` function supports `minTime`, `maxTime`, etc.
*/
props: TValidationProps;
}
export interface UseValidationReturnValue<TValue extends PickerValidValue, TError> {
/**
* The validation error associated to the value passed to the `useValidation` hook.
*/
validationError: TError;
/**
* `true` if the current error is not null.
* For single value components, it means that the value is invalid.
* For range components, it means that either start or end value is invalid.
*/
hasValidationError: boolean;
/**
* Get the validation error for a new value.
* This can be used to validate the value in a change handler before updating the state.
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
* @param {TValue} newValue The value to validate.
* @returns {TError} The validation error associated to the new value.
*/
getValidationErrorForNewValue: (newValue: TValue) => TError;
}
/**
* Utility hook to check if a given value is valid based on the provided validation props.
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
* @template TError The validation error type. It will be either `string` or a `null`. It can be in `[start, end]` format in case of range value.
* @param {UseValidationOptions<TValue, TError, TValidationProps>} options The options to configure the hook.
* @param {TValue} options.value The value to validate.
* @param {PickersTimezone} options.timezone The timezone to use for the validation.
* @param {Validator<TValue, TError, TValidationProps>} options.validator The validator function to use.
* @param {TValidationProps} options.props The validation props, they differ depending on the component.
* @param {(error: TError, value: TValue) => void} options.onError Callback fired when the error associated with the current value changes.
*/
export declare function useValidation<TValue extends PickerValidValue, TError, TValidationProps extends {}>(options: UseValidationOptions<TValue, TError, TValidationProps>): UseValidationReturnValue<TValue, TError>;
export {};

View file

@ -0,0 +1,60 @@
"use strict";
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useValidation = useValidation;
var React = _interopRequireWildcard(require("react"));
var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback"));
var _hooks = require("../hooks");
/**
* Utility hook to check if a given value is valid based on the provided validation props.
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
* @template TError The validation error type. It will be either `string` or a `null`. It can be in `[start, end]` format in case of range value.
* @param {UseValidationOptions<TValue, TError, TValidationProps>} options The options to configure the hook.
* @param {TValue} options.value The value to validate.
* @param {PickersTimezone} options.timezone The timezone to use for the validation.
* @param {Validator<TValue, TError, TValidationProps>} options.validator The validator function to use.
* @param {TValidationProps} options.props The validation props, they differ depending on the component.
* @param {(error: TError, value: TValue) => void} options.onError Callback fired when the error associated with the current value changes.
*/
function useValidation(options) {
const {
props,
validator,
value,
timezone,
onError
} = options;
const adapter = (0, _hooks.usePickerAdapter)();
const previousValidationErrorRef = React.useRef(validator.valueManager.defaultErrorState);
const validationError = validator({
adapter,
value,
timezone,
props
});
const hasValidationError = validator.valueManager.hasError(validationError);
React.useEffect(() => {
if (onError && !validator.valueManager.isSameError(validationError, previousValidationErrorRef.current)) {
onError(validationError, value);
}
previousValidationErrorRef.current = validationError;
}, [validator, onError, validationError, value]);
const getValidationErrorForNewValue = (0, _useEventCallback.default)(newValue => {
return validator({
adapter,
value: newValue,
timezone,
props
});
});
return {
validationError,
hasValidationError,
getValidationErrorForNewValue
};
}

View file

@ -0,0 +1,18 @@
import type { MakeRequired } from '@mui/x-internals/types';
import { Validator } from "./useValidation.js";
import { BaseDateValidationProps, DayValidationProps, MonthValidationProps, YearValidationProps } from "../internals/models/validation.js";
import { DateValidationError } from "../models/index.js";
import { PickerValue } from "../internals/models/index.js";
/**
* Validation props used by the Date Picker, Date Field and Date Calendar components.
*/
export interface ExportedValidateDateProps extends DayValidationProps, MonthValidationProps, YearValidationProps, BaseDateValidationProps {}
/**
* Validation props as received by the validateDate method.
*/
export interface ValidateDateProps extends MakeRequired<ExportedValidateDateProps, ValidateDatePropsToDefault> {}
/**
* Name of the props that should be defaulted before being passed to the validateDate method.
*/
export type ValidateDatePropsToDefault = keyof BaseDateValidationProps;
export declare const validateDate: Validator<PickerValue, DateValidationError, ValidateDateProps>;

View file

@ -0,0 +1,61 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.validateDate = void 0;
var _valueManagers = require("../internals/utils/valueManagers");
/**
* Validation props used by the Date Picker, Date Field and Date Calendar components.
*/
/**
* Validation props as received by the validateDate method.
*/
/**
* Name of the props that should be defaulted before being passed to the validateDate method.
*/
const validateDate = ({
props,
value,
timezone,
adapter
}) => {
if (value === null) {
return null;
}
const {
shouldDisableDate,
shouldDisableMonth,
shouldDisableYear,
disablePast,
disableFuture,
minDate,
maxDate
} = props;
const now = adapter.date(undefined, timezone);
switch (true) {
case !adapter.isValid(value):
return 'invalidDate';
case Boolean(shouldDisableDate && shouldDisableDate(value)):
return 'shouldDisableDate';
case Boolean(shouldDisableMonth && shouldDisableMonth(value)):
return 'shouldDisableMonth';
case Boolean(shouldDisableYear && shouldDisableYear(value)):
return 'shouldDisableYear';
case Boolean(disableFuture && adapter.isAfterDay(value, now)):
return 'disableFuture';
case Boolean(disablePast && adapter.isBeforeDay(value, now)):
return 'disablePast';
case Boolean(minDate && adapter.isBeforeDay(value, minDate)):
return 'minDate';
case Boolean(maxDate && adapter.isAfterDay(value, maxDate)):
return 'maxDate';
default:
return null;
}
};
exports.validateDate = validateDate;
validateDate.valueManager = _valueManagers.singleItemValueManager;

View file

@ -0,0 +1,19 @@
import { Validator } from "./useValidation.js";
import { ExportedValidateDateProps, ValidateDateProps, ValidateDatePropsToDefault } from "./validateDate.js";
import { ExportedValidateTimeProps, ValidateTimeProps, ValidateTimePropsToDefault } from "./validateTime.js";
import { DateTimeValidationError } from "../models/index.js";
import { DateTimeValidationProps } from "../internals/models/validation.js";
import { PickerValue } from "../internals/models/index.js";
/**
* Validation props used by the Date Time Picker and Date Time Field components.
*/
export interface ExportedValidateDateTimeProps extends ExportedValidateDateProps, ExportedValidateTimeProps, DateTimeValidationProps {}
/**
* Validation props as received by the validateDateTime method.
*/
export interface ValidateDateTimeProps extends ValidateDateProps, ValidateTimeProps {}
/**
* Name of the props that should be defaulted before being passed to the validateDateTime method.
*/
export type ValidateDateTimePropsToDefault = ValidateDatePropsToDefault | ValidateTimePropsToDefault;
export declare const validateDateTime: Validator<PickerValue, DateTimeValidationError, ValidateDateTimeProps>;

View file

@ -0,0 +1,45 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.validateDateTime = void 0;
var _validateDate = require("./validateDate");
var _validateTime = require("./validateTime");
var _valueManagers = require("../internals/utils/valueManagers");
/**
* Validation props used by the Date Time Picker and Date Time Field components.
*/
/**
* Validation props as received by the validateDateTime method.
*/
/**
* Name of the props that should be defaulted before being passed to the validateDateTime method.
*/
const validateDateTime = ({
adapter,
value,
timezone,
props
}) => {
const dateValidationResult = (0, _validateDate.validateDate)({
adapter,
value,
timezone,
props
});
if (dateValidationResult !== null) {
return dateValidationResult;
}
return (0, _validateTime.validateTime)({
adapter,
value,
timezone,
props
});
};
exports.validateDateTime = validateDateTime;
validateDateTime.valueManager = _valueManagers.singleItemValueManager;

View file

@ -0,0 +1,18 @@
import type { MakeRequired } from '@mui/x-internals/types';
import { Validator } from "./useValidation.js";
import { BaseTimeValidationProps, TimeValidationProps } from "../internals/models/validation.js";
import { TimeValidationError } from "../models/index.js";
import { PickerValue } from "../internals/models/index.js";
/**
* Validation props used by the Time Picker, Time Field and Clock components.
*/
export interface ExportedValidateTimeProps extends BaseTimeValidationProps, TimeValidationProps {}
/**
* Validation props as received by the validateTime method.
*/
export interface ValidateTimeProps extends MakeRequired<ExportedValidateTimeProps, ValidateTimePropsToDefault> {}
/**
* Name of the props that should be defaulted before being passed to the validateTime method.
*/
export type ValidateTimePropsToDefault = keyof BaseTimeValidationProps;
export declare const validateTime: Validator<PickerValue, TimeValidationError, ValidateTimeProps>;

View file

@ -0,0 +1,65 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.validateTime = void 0;
var _timeUtils = require("../internals/utils/time-utils");
var _valueManagers = require("../internals/utils/valueManagers");
/**
* Validation props used by the Time Picker, Time Field and Clock components.
*/
/**
* Validation props as received by the validateTime method.
*/
/**
* Name of the props that should be defaulted before being passed to the validateTime method.
*/
const validateTime = ({
adapter,
value,
timezone,
props
}) => {
if (value === null) {
return null;
}
const {
minTime,
maxTime,
minutesStep,
shouldDisableTime,
disableIgnoringDatePartForTimeValidation = false,
disablePast,
disableFuture
} = props;
const now = adapter.date(undefined, timezone);
const isAfter = (0, _timeUtils.createIsAfterIgnoreDatePart)(disableIgnoringDatePartForTimeValidation, adapter);
switch (true) {
case !adapter.isValid(value):
return 'invalidDate';
case Boolean(minTime && isAfter(minTime, value)):
return 'minTime';
case Boolean(maxTime && isAfter(value, maxTime)):
return 'maxTime';
case Boolean(disableFuture && adapter.isAfter(value, now)):
return 'disableFuture';
case Boolean(disablePast && adapter.isBefore(value, now)):
return 'disablePast';
case Boolean(shouldDisableTime && shouldDisableTime(value, 'hours')):
return 'shouldDisableTime-hours';
case Boolean(shouldDisableTime && shouldDisableTime(value, 'minutes')):
return 'shouldDisableTime-minutes';
case Boolean(shouldDisableTime && shouldDisableTime(value, 'seconds')):
return 'shouldDisableTime-seconds';
case Boolean(minutesStep && adapter.getMinutes(value) % minutesStep !== 0):
return 'minutesStep';
default:
return null;
}
};
exports.validateTime = validateTime;
validateTime.valueManager = _valueManagers.singleItemValueManager;