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

Add native ESM support #886

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,27 @@
"name": "react-calendar",
"version": "4.5.0",
"description": "Ultimate calendar for your React app.",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"source": "src/index.ts",
"types": "dist/cjs/index.d.ts",
"type": "module",
"sideEffects": [
"*.css"
],
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"source": "./src/index.ts",
"types": "./dist/cjs/index.d.ts",
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
},
"./dist/Calendar.css": "./dist/Calendar.css"
},
"scripts": {
"build": "yarn build-js && yarn copy-styles",
"build-js": "yarn build-js-esm && yarn build-js-cjs",
"build-js": "yarn build-js-esm && yarn build-js-cjs && yarn build-js-cjs-package",
"build-js-esm": "tsc --project tsconfig.build.json --outDir dist/esm --module esnext",
"build-js-cjs": "tsc --project tsconfig.build.json --outDir dist/cjs --module commonjs",
"build-js-cjs-package": "echo '{\n \"type\": \"commonjs\"\n}' > dist/cjs/package.json",
"clean": "rimraf dist",
"copy-styles": "cpy 'src/**/*.css' dist",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
Expand All @@ -23,7 +32,7 @@
"test": "yarn lint && yarn tsc && yarn prettier && yarn unit",
"tsc": "tsc --noEmit",
"unit": "vitest",
"watch": "yarn build-js-esm --watch & yarn build-js-cjs --watch & nodemon --watch src --ext css --exec \"yarn copy-styles\""
"watch": "yarn build-js-esm --watch & yarn build-js-cjs --watch & yarn build-js-cjs-package & nodemon --watch src --ext css --exec \"yarn copy-styles\""
},
"keywords": [
"calendar",
Expand Down
4 changes: 2 additions & 2 deletions src/Calendar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import React, { createRef } from 'react';
import { act, render } from '@testing-library/react';
import { getMonthStart } from '@wojtekmaj/date-utils';

import Calendar from './Calendar';
import Calendar from './Calendar.js';

import type { Action, Value, View } from './shared/types';
import type { Action, Value, View } from './shared/types.js';

type CalendarImperativeHandle = {
activeStartDate: Date;
Expand Down
20 changes: 10 additions & 10 deletions src/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import React, { forwardRef, useCallback, useImperativeHandle, useState } from 'r
import PropTypes from 'prop-types';
import clsx from 'clsx';

import Navigation from './Calendar/Navigation';
import CenturyView from './CenturyView';
import DecadeView from './DecadeView';
import YearView from './YearView';
import MonthView from './MonthView';
import Navigation from './Calendar/Navigation.js';
import CenturyView from './CenturyView.js';
import DecadeView from './DecadeView.js';
import YearView from './YearView.js';
import MonthView from './MonthView.js';

import { getBegin, getBeginNext, getEnd, getValueRange } from './shared/dates';
import { getBegin, getBeginNext, getEnd, getValueRange } from './shared/dates.js';
import {
isCalendarType,
isClassName,
Expand All @@ -19,8 +19,8 @@ import {
isRef,
isView,
rangeOf,
} from './shared/propTypes';
import { between } from './shared/utils';
} from './shared/propTypes.js';
import { between } from './shared/utils.js';

import type {
Action,
Expand All @@ -39,7 +39,7 @@ import type {
TileDisabledFunc,
Value,
View,
} from './shared/types';
} from './shared/types.js';

import type {
formatDay as defaultFormatDay,
Expand All @@ -49,7 +49,7 @@ import type {
formatShortWeekday as defaultFormatShortWeekday,
formatWeekday as defaultFormatWeekday,
formatYear as defaultFormatYear,
} from './shared/dateFormatter';
} from './shared/dateFormatter.js';

const baseClassName = 'react-calendar';
const allViews = ['century', 'decade', 'year', 'month'] as const;
Expand Down
2 changes: 1 addition & 1 deletion src/Calendar/Navigation.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
import React from 'react';
import { fireEvent, render } from '@testing-library/react';

import Navigation from './Navigation';
import Navigation from './Navigation.js';

const allViews = ['century', 'decade', 'year', 'month'];

Expand Down
6 changes: 3 additions & 3 deletions src/Calendar/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import {
getBeginPrevious2,
getEndPrevious,
getEndPrevious2,
} from '../shared/dates';
} from '../shared/dates.js';
import {
formatMonthYear as defaultFormatMonthYear,
formatYear as defaultFormatYear,
} from '../shared/dateFormatter';
} from '../shared/dateFormatter.js';

import type { Action, NavigationLabelFunc, RangeType } from '../shared/types';
import type { Action, NavigationLabelFunc, RangeType } from '../shared/types.js';

const className = 'react-calendar__navigation';

Expand Down
2 changes: 1 addition & 1 deletion src/CenturyView.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import { render } from '@testing-library/react';
import { getDecadeStart, getDecadeEnd } from '@wojtekmaj/date-utils';

import CenturyView from './CenturyView';
import CenturyView from './CenturyView.js';

describe('CenturyView', () => {
const defaultProps = {
Expand Down
4 changes: 2 additions & 2 deletions src/CenturyView.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';

import Decades from './CenturyView/Decades';
import Decades from './CenturyView/Decades.js';

import { tileGroupProps } from './shared/propTypes';
import { tileGroupProps } from './shared/propTypes.js';

type CenturyViewProps = React.ComponentProps<typeof Decades>;

Expand Down
2 changes: 1 addition & 1 deletion src/CenturyView/Decade.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, it, vi } from 'vitest';
import React from 'react';
import { fireEvent, render } from '@testing-library/react';

import Decade from './Decade';
import Decade from './Decade.js';

const tileProps = {
activeStartDate: new Date(2018, 0, 1),
Expand Down
6 changes: 3 additions & 3 deletions src/CenturyView/Decade.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import { getDecadeStart, getDecadeEnd } from '@wojtekmaj/date-utils';

import Tile from '../Tile';
import Tile from '../Tile.js';

import { getDecadeLabel } from '../shared/dates';
import { formatYear as defaultFormatYear } from '../shared/dateFormatter';
import { getDecadeLabel } from '../shared/dates.js';
import { formatYear as defaultFormatYear } from '../shared/dateFormatter.js';

const className = 'react-calendar__century-view__decades__decade';

Expand Down
6 changes: 3 additions & 3 deletions src/CenturyView/Decades.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import { getDecadeStart } from '@wojtekmaj/date-utils';

import TileGroup from '../TileGroup';
import Decade from './Decade';
import TileGroup from '../TileGroup.js';
import Decade from './Decade.js';

import { getBeginOfCenturyYear } from '../shared/dates';
import { getBeginOfCenturyYear } from '../shared/dates.js';

type DecadesProps = {
activeStartDate: Date;
Expand Down
2 changes: 1 addition & 1 deletion src/DecadeView.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest';
import React from 'react';
import { render } from '@testing-library/react';

import DecadeView from './DecadeView';
import DecadeView from './DecadeView.js';

describe('DecadeView', () => {
const defaultProps = {
Expand Down
4 changes: 2 additions & 2 deletions src/DecadeView.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';

import Years from './DecadeView/Years';
import Years from './DecadeView/Years.js';

import { tileGroupProps } from './shared/propTypes';
import { tileGroupProps } from './shared/propTypes.js';

type DecadeViewProps = React.ComponentProps<typeof Years>;

Expand Down
2 changes: 1 addition & 1 deletion src/DecadeView/Year.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, it, vi } from 'vitest';
import React from 'react';
import { fireEvent, render } from '@testing-library/react';

import Year from './Year';
import Year from './Year.js';

const tileProps = {
activeStartDate: new Date(2018, 0, 1),
Expand Down
4 changes: 2 additions & 2 deletions src/DecadeView/Year.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { getYearStart, getYearEnd } from '@wojtekmaj/date-utils';

import Tile from '../Tile';
import Tile from '../Tile.js';

import { formatYear as defaultFormatYear } from '../shared/dateFormatter';
import { formatYear as defaultFormatYear } from '../shared/dateFormatter.js';

const className = 'react-calendar__decade-view__years__year';

Expand Down
6 changes: 3 additions & 3 deletions src/DecadeView/Years.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import { getYearStart } from '@wojtekmaj/date-utils';

import TileGroup from '../TileGroup';
import Year from './Year';
import TileGroup from '../TileGroup.js';
import Year from './Year.js';

import { getBeginOfDecadeYear } from '../shared/dates';
import { getBeginOfDecadeYear } from '../shared/dates.js';

type YearsProps = {
activeStartDate: Date;
Expand Down
2 changes: 1 addition & 1 deletion src/Flex.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest';
import React from 'react';
import { render } from '@testing-library/react';

import Flex from './Flex';
import Flex from './Flex.js';

describe('Flex', () => {
it('styles itself properly with wrap flag set to false', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/MonthView.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { describe, expect, it } from 'vitest';
import React from 'react';
import { render } from '@testing-library/react';

import MonthView from './MonthView';
import { formatShortWeekday } from './shared/dateFormatter';
import MonthView from './MonthView.js';
import { formatShortWeekday } from './shared/dateFormatter.js';

const { format } = new Intl.DateTimeFormat('en-US', {
day: 'numeric',
Expand Down
12 changes: 6 additions & 6 deletions src/MonthView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';

import Days from './MonthView/Days';
import Weekdays from './MonthView/Weekdays';
import WeekNumbers from './MonthView/WeekNumbers';
import Days from './MonthView/Days.js';
import Weekdays from './MonthView/Weekdays.js';
import WeekNumbers from './MonthView/WeekNumbers.js';

import { CALENDAR_TYPES, CALENDAR_TYPE_LOCALES } from './shared/const';
import { isCalendarType, tileGroupProps } from './shared/propTypes';
import { CALENDAR_TYPES, CALENDAR_TYPE_LOCALES } from './shared/const.js';
import { isCalendarType, tileGroupProps } from './shared/propTypes.js';

import type { CalendarType } from './shared/types';
import type { CalendarType } from './shared/types.js';

function getCalendarTypeFromLocale(locale: string | undefined): CalendarType {
if (locale) {
Expand Down
2 changes: 1 addition & 1 deletion src/MonthView/Day.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, it, vi } from 'vitest';
import React from 'react';
import { fireEvent, render } from '@testing-library/react';

import Day from './Day';
import Day from './Day.js';

const tileProps = {
activeStartDate: new Date(2018, 0, 1),
Expand Down
10 changes: 5 additions & 5 deletions src/MonthView/Day.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React from 'react';
import { getDayStart, getDayEnd } from '@wojtekmaj/date-utils';

import Tile from '../Tile';
import Tile from '../Tile.js';

import { isWeekend } from '../shared/dates';
import { isWeekend } from '../shared/dates.js';
import {
formatDay as defaultFormatDay,
formatLongDate as defaultFormatLongDate,
} from '../shared/dateFormatter';
import { mapCalendarType } from '../shared/utils';
} from '../shared/dateFormatter.js';
import { mapCalendarType } from '../shared/utils.js';

import type { CalendarType, DeprecatedCalendarType } from '../shared/types';
import type { CalendarType, DeprecatedCalendarType } from '../shared/types.js';

const className = 'react-calendar__month-view__days__day';

Expand Down
10 changes: 5 additions & 5 deletions src/MonthView/Days.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react';
import { getYear, getMonth, getDaysInMonth, getDayStart } from '@wojtekmaj/date-utils';

import TileGroup from '../TileGroup';
import Day from './Day';
import TileGroup from '../TileGroup.js';
import Day from './Day.js';

import { getDayOfWeek } from '../shared/dates';
import { mapCalendarType } from '../shared/utils';
import { getDayOfWeek } from '../shared/dates.js';
import { mapCalendarType } from '../shared/utils.js';

import type { CalendarType, DeprecatedCalendarType } from '../shared/types';
import type { CalendarType, DeprecatedCalendarType } from '../shared/types.js';

type DaysProps = {
activeStartDate: Date;
Expand Down
2 changes: 1 addition & 1 deletion src/MonthView/WeekNumber.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest';
import React from 'react';
import { render } from '@testing-library/react';

import WeekNumber from './WeekNumber';
import WeekNumber from './WeekNumber.js';

describe('<WeekNumber /> component', () => {
const defaultProps = {
Expand Down
2 changes: 1 addition & 1 deletion src/MonthView/WeekNumber.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import type { OnClickWeekNumberFunc } from '../shared/types';
import type { OnClickWeekNumberFunc } from '../shared/types.js';

const className = 'react-calendar__tile';

Expand Down
2 changes: 1 addition & 1 deletion src/MonthView/WeekNumbers.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, it, vi } from 'vitest';
import React from 'react';
import { fireEvent, render } from '@testing-library/react';

import WeekNumbers from './WeekNumbers';
import WeekNumbers from './WeekNumbers.js';

describe('.react-calendar__month-view__weekNumbers', () => {
const defaultProps = {
Expand Down
14 changes: 9 additions & 5 deletions src/MonthView/WeekNumbers.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import React from 'react';
import { getYear, getMonth, getDate, getDaysInMonth } from '@wojtekmaj/date-utils';

import WeekNumber from './WeekNumber';
import Flex from '../Flex';
import WeekNumber from './WeekNumber.js';
import Flex from '../Flex.js';

import { getBeginOfWeek, getDayOfWeek, getWeekNumber } from '../shared/dates';
import { mapCalendarType } from '../shared/utils';
import { getBeginOfWeek, getDayOfWeek, getWeekNumber } from '../shared/dates.js';
import { mapCalendarType } from '../shared/utils.js';

import type { CalendarType, DeprecatedCalendarType, OnClickWeekNumberFunc } from '../shared/types';
import type {
CalendarType,
DeprecatedCalendarType,
OnClickWeekNumberFunc,
} from '../shared/types.js';

type WeekNumbersProps = {
activeStartDate: Date;
Expand Down
2 changes: 1 addition & 1 deletion src/MonthView/Weekdays.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest';
import React from 'react';
import { render } from '@testing-library/react';

import Weekdays from './Weekdays';
import Weekdays from './Weekdays.js';

describe('Weekdays', () => {
const defaultProps = {
Expand Down
Loading