Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pickers] Move the adapters interfaces to our repository #8412

Merged
merged 8 commits into from Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,6 +1,6 @@
import * as React from 'react';
import useEventCallback from '@mui/utils/useEventCallback';
import { MuiPickersAdapter } from '@mui/x-date-pickers/internals';
import { MuiPickersAdapter } from '@mui/x-date-pickers/models';
import { DateRangePosition } from './DateRangeCalendar.types';
import { DateRange } from '../internal/models';
import { isEndOfRange, isStartOfRange } from '../internal/utils/date-utils';
Expand Down
@@ -1,4 +1,4 @@
import { MuiPickersAdapter } from '@mui/x-date-pickers/internals';
import { MuiPickersAdapter } from '@mui/x-date-pickers/models';
import { DateRange, RangePosition } from '../models/range';

interface CalculateRangeChangeOptions<TDate> {
Expand Down
@@ -1,4 +1,4 @@
import { MuiPickersAdapter } from '@mui/x-date-pickers/internals';
import { MuiPickersAdapter } from '@mui/x-date-pickers/models';
import { DateRange, NonEmptyDateRange } from '../models/range';

export const isRangeValid = <TDate>(
Expand Down
2 changes: 1 addition & 1 deletion packages/x-date-pickers/src/AdapterDateFns/index.ts
Expand Up @@ -3,7 +3,7 @@ import defaultLocale from 'date-fns/locale/en-US';
// @ts-ignore
import longFormatters from 'date-fns/_lib/format/longFormatters';
import getWeek from 'date-fns/getWeek';
import { FieldFormatTokenMap, MuiPickersAdapter } from '../internals/models';
import { FieldFormatTokenMap, MuiPickersAdapter } from '../models';

const formatTokenMap: FieldFormatTokenMap = {
// Year
Expand Down
2 changes: 1 addition & 1 deletion packages/x-date-pickers/src/AdapterDateFnsJalali/index.ts
Expand Up @@ -3,7 +3,7 @@ import defaultLocale from 'date-fns-jalali/locale/fa-IR';
import getWeek from 'date-fns-jalali/getWeek';
// @ts-ignore
import longFormatters from 'date-fns-jalali/_lib/format/longFormatters';
import { FieldFormatTokenMap, MuiPickersAdapter } from '../internals/models';
import { FieldFormatTokenMap, MuiPickersAdapter } from '../models';

const formatTokenMap: FieldFormatTokenMap = {
// Year
Expand Down
5 changes: 2 additions & 3 deletions packages/x-date-pickers/src/AdapterDayjs/index.ts
Expand Up @@ -2,8 +2,7 @@
import defaultDayjs, { Dayjs } from 'dayjs';
import weekOfYear from 'dayjs/plugin/weekOfYear';
import BaseAdapterDayjs from '@date-io/dayjs';
import { DateIOFormats } from '@date-io/core/IUtils';
import { FieldFormatTokenMap, MuiPickersAdapter } from '../internals/models';
import { FieldFormatTokenMap, MuiPickersAdapter, AdapterFormats } from '../models';
import { buildWarning } from '../internals/utils/warning';

const localeNotFoundWarning = buildWarning([
Expand Down Expand Up @@ -58,7 +57,7 @@ interface Opts {
locale?: string;
/** Make sure that your dayjs instance extends customParseFormat and advancedFormat */
instance?: typeof defaultDayjs;
formats?: Partial<DateIOFormats>;
formats?: Partial<AdapterFormats>;
}

export class AdapterDayjs extends BaseAdapterDayjs implements MuiPickersAdapter<Dayjs> {
Expand Down
4 changes: 2 additions & 2 deletions packages/x-date-pickers/src/AdapterLuxon/index.ts
@@ -1,7 +1,7 @@
/* eslint-disable class-methods-use-this */
import { DateTime } from 'luxon';
import BaseAdapterLuxon from '@date-io/luxon';
import { FieldFormatTokenMap, MuiPickersAdapter } from '../internals/models';
import { FieldFormatTokenMap, MuiPickersAdapter } from '../models';

const formatTokenMap: FieldFormatTokenMap = {
// Year
Expand Down Expand Up @@ -64,7 +64,7 @@ export class AdapterLuxon extends BaseAdapterLuxon implements MuiPickersAdapter<
'Your luxon version does not support `expandFormat`. Consider upgrading it to v3.0.2',
);
}
// Extract escaped section to avoid entending them
// Extract escaped section to avoid extending them
const longFormatRegexp = /''|'(''|[^'])+('|$)|[^']*/g;
return (
format
Expand Down
2 changes: 1 addition & 1 deletion packages/x-date-pickers/src/AdapterMoment/index.ts
@@ -1,7 +1,7 @@
/* eslint-disable class-methods-use-this */
import defaultMoment, { LongDateFormatKey } from 'moment';
import BaseAdapterMoment from '@date-io/moment';
import { FieldFormatTokenMap, MuiPickersAdapter } from '../internals/models';
import { FieldFormatTokenMap, MuiPickersAdapter } from '../models';

// From https://momentjs.com/docs/#/displaying/format/
const formatTokenMap: FieldFormatTokenMap = {
Expand Down
2 changes: 1 addition & 1 deletion packages/x-date-pickers/src/AdapterMomentHijri/index.ts
Expand Up @@ -2,7 +2,7 @@
import BaseAdapterMomentHijri from '@date-io/hijri';
// @ts-ignore
import defaultMoment, { LongDateFormatKey } from 'moment-hijri';
import { FieldFormatTokenMap, MuiPickersAdapter } from '../internals/models';
import { FieldFormatTokenMap, MuiPickersAdapter } from '../models';

// From https://momentjs.com/docs/#/displaying/format/
const formatTokenMap: FieldFormatTokenMap = {
Expand Down
2 changes: 1 addition & 1 deletion packages/x-date-pickers/src/AdapterMomentJalaali/index.ts
@@ -1,7 +1,7 @@
/* eslint-disable class-methods-use-this */
import BaseAdapterMomentJalaali from '@date-io/jalaali';
import defaultMoment, { LongDateFormatKey } from 'moment-jalaali';
import { FieldFormatTokenMap, MuiPickersAdapter } from '../internals/models';
import { FieldFormatTokenMap, MuiPickersAdapter } from '../models';

type Moment = defaultMoment.Moment;

Expand Down
Expand Up @@ -3,7 +3,7 @@ import useEventCallback from '@mui/utils/useEventCallback';
import { SlideDirection } from './PickersSlideTransition';
import { useIsDateDisabled } from '../internals/hooks/validation/useDateValidation';
import { useUtils, useNow } from '../internals/hooks/useUtils';
import { MuiPickersAdapter } from '../internals/models';
import { MuiPickersAdapter } from '../models';
import { clamp } from '../internals/utils/date-utils';
import { DateCalendarDefaultizedProps } from './DateCalendar.types';

Expand Down
4 changes: 2 additions & 2 deletions packages/x-date-pickers/src/DatePicker/shared.tsx
Expand Up @@ -12,10 +12,10 @@ import {
isYearAndMonthViews,
isYearOnlyView,
} from '../internals/utils/views';
import { DateValidationError, DateView } from '../models';
import { DateValidationError, DateView, MuiPickersAdapter } from '../models';
import { BasePickerInputProps } from '../internals/models/props/basePickerProps';
import { applyDefaultDate } from '../internals/utils/date-utils';
import { BaseDateValidationProps, MuiPickersAdapter, UncapitalizeObjectKeys } from '../internals';
import { BaseDateValidationProps, UncapitalizeObjectKeys } from '../internals';
import { LocalizedComponent, PickersInputLocaleText } from '../locales/utils/pickersLocaleTextApi';
import {
DatePickerToolbar,
Expand Down
@@ -1,8 +1,7 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { DateIOFormats } from '@date-io/core/IUtils';
import { useThemeProps } from '@mui/material/styles';
import { MuiPickersAdapter } from '../internals/models';
import { AdapterFormats, MuiPickersAdapter } from '../models';
import { PickersInputLocaleText } from '../locales';

export interface MuiPickersAdapterContextValue<TDate> {
Expand Down Expand Up @@ -34,7 +33,7 @@ export interface LocalizationProviderProps<TDate> {
*/
dateAdapter?: new (...args: any) => MuiPickersAdapter<TDate>;
/** Formats that are used for any child pickers */
dateFormats?: Partial<DateIOFormats>;
dateFormats?: Partial<AdapterFormats>;
/**
* Date library instance you are using, if it has some global overrides
* ```jsx
Expand Down
2 changes: 1 addition & 1 deletion packages/x-date-pickers/src/TimeClock/ClockNumbers.tsx
@@ -1,6 +1,6 @@
import * as React from 'react';
import { ClockNumber } from './ClockNumber';
import { MuiPickersAdapter } from '../internals/models';
import { MuiPickersAdapter } from '../models';
import type { PickerSelectionState } from '../internals/hooks/usePicker';

interface GetHourNumbersOptions<TDate> {
Expand Down
Expand Up @@ -3,7 +3,6 @@ import IconButton, { IconButtonProps } from '@mui/material/IconButton';
import { InputAdornmentProps } from '@mui/material/InputAdornment';
import TextField, { TextFieldProps } from '@mui/material/TextField';
import { SlotComponentProps } from '@mui/base/utils';
import { MuiPickersAdapter } from '../../models';
import {
BaseNonStaticPickerProps,
BasePickerProps,
Expand All @@ -14,7 +13,12 @@ import {
PickersPopperSlotsComponentsProps,
} from '../../components/PickersPopper';
import { UsePickerParams, UsePickerProps } from '../usePicker';
import { BaseSingleInputFieldProps, FieldSection, DateOrTimeView } from '../../../models';
import {
BaseSingleInputFieldProps,
FieldSection,
DateOrTimeView,
MuiPickersAdapter,
} from '../../../models';
import {
ExportedPickersLayoutSlotsComponent,
ExportedPickersLayoutSlotsComponentsProps,
Expand Down
@@ -1,6 +1,10 @@
import * as React from 'react';
import { MuiPickersAdapter } from '../../models';
import { FieldSectionType, FieldSection, FieldSelectedSections } from '../../../models';
import {
FieldSectionType,
FieldSection,
FieldSelectedSections,
MuiPickersAdapter,
} from '../../../models';
import type { PickerValueManager } from '../usePicker';
import { InferError, Validator } from '../validation/useValidation';

Expand Down
Expand Up @@ -7,8 +7,7 @@ import {
FieldSectionWithoutPosition,
FieldSectionValueBoundaries,
} from './useField.types';
import { MuiPickersAdapter } from '../../models';
import { FieldSectionType, FieldSection } from '../../../models';
import { FieldSectionType, FieldSection, MuiPickersAdapter } from '../../../models';
import { PickersLocaleText } from '../../../locales/utils/pickersLocaleTextApi';

export const getDateSectionConfigFromFormatToken = <TDate>(
Expand Down
@@ -1,7 +1,6 @@
import * as React from 'react';
import TextField, { TextFieldProps } from '@mui/material/TextField';
import { SlotComponentProps } from '@mui/base/utils';
import { MuiPickersAdapter } from '../../models';
import {
BaseNonStaticPickerProps,
BasePickerProps,
Expand All @@ -12,7 +11,12 @@ import {
PickersModalDialogSlotsComponentsProps,
} from '../../components/PickersModalDialog';
import { UsePickerParams, UsePickerProps } from '../usePicker';
import { BaseSingleInputFieldProps, FieldSection, DateOrTimeView } from '../../../models';
import {
BaseSingleInputFieldProps,
FieldSection,
DateOrTimeView,
MuiPickersAdapter,
} from '../../../models';
import {
ExportedPickersLayoutSlotsComponent,
ExportedPickersLayoutSlotsComponentsProps,
Expand Down
Expand Up @@ -7,8 +7,7 @@ import { FieldChangeHandlerContext, UseFieldInternalProps } from '../useField';
import { InferError, useValidation, Validator } from '../validation/useValidation';
import { UseFieldValidationProps } from '../useField/useField.types';
import { WrapperVariant } from '../../models/common';
import { MuiPickersAdapter } from '../../models/muiPickersAdapter';
import { FieldSection, FieldSelectedSections } from '../../../models';
import { FieldSection, FieldSelectedSections, MuiPickersAdapter } from '../../../models';

export interface PickerValueManager<TValue, TDate, TError> {
/**
Expand Down
1 change: 0 additions & 1 deletion packages/x-date-pickers/src/internals/index.ts
Expand Up @@ -120,7 +120,6 @@ export type {
BaseNonStaticPickerProps,
} from './models/props/basePickerProps';
export type { BaseToolbarProps, ExportedBaseToolbarProps } from './models/props/toolbar';
export type { MuiPickersAdapter } from './models/muiPickersAdapter';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an idea: yes, it is our internals and we do not endorse using them externally as well as do not guarantee its API stability, but still, this could impact users, who have built their custom adapters. 🤔
Maybe releasing it (or keeping PR open until we see the need for a minor) with at least a minor bump would make more sense? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which part of this PR is impacting people who build their own adapter or use our adapters externally ?

If it's just the import path of the model MuiPickersAdapter, then it's in internals so I don't think we should care 👼

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, yes, only the export location changes, it's internals, so, shouldn't be a big deal, but was just nitpicking that, as per semver suggestions, such change should be released at least as a minor. If not for the exclusion of internal export, then for the addition of new imports.
But in any case, it's just food for thought and just to consider, I'm not saying that we shouldn't or can't do whatever we see best. 👌

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can merge this PR for v6.1, with the 1st real feature that the pickers or the grid has 👍

export type { DefaultizedProps, MakeOptional } from './models/helpers';
export type { WrapperVariant } from './models/common';

Expand Down
1 change: 0 additions & 1 deletion packages/x-date-pickers/src/internals/models/index.ts
@@ -1,2 +1 @@
export * from './fields';
export * from './muiPickersAdapter';

This file was deleted.

2 changes: 1 addition & 1 deletion packages/x-date-pickers/src/internals/utils/date-utils.ts
@@ -1,4 +1,4 @@
import { MuiPickersAdapter } from '../models';
import { MuiPickersAdapter } from '../../models';

interface FindClosestDateParams<TDate> {
date: TDate;
Expand Down
3 changes: 1 addition & 2 deletions packages/x-date-pickers/src/internals/utils/time-utils.ts
@@ -1,5 +1,4 @@
import { MuiPickersAdapter } from '../models';
import { DateOrTimeView } from '../../models';
import { DateOrTimeView, MuiPickersAdapter } from '../../models';

export const isTimeView = (view: DateOrTimeView) => ['hours', 'minutes', 'seconds'].includes(view);

Expand Down
@@ -1,5 +1,4 @@
import { MuiPickersAdapter } from '../../internals/models';
import { DateView, TimeView } from '../../models';
import { DateView, TimeView, MuiPickersAdapter } from '../../models';

export interface PickersComponentSpecificLocaleText {
/**
Expand Down