Skip to content

Commit

Permalink
refactor: move dayjs into @univerjs/core
Browse files Browse the repository at this point in the history
  • Loading branch information
jikkai committed Nov 15, 2024
1 parent d3085e2 commit a3473b3
Show file tree
Hide file tree
Showing 23 changed files with 845 additions and 1,657 deletions.
22 changes: 11 additions & 11 deletions common/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@
"build:storybook": "storybook build"
},
"dependencies": {
"@chromatic-com/storybook": "^3.2.1",
"@storybook/addon-essentials": "^8.3.6",
"@storybook/addon-interactions": "^8.3.6",
"@storybook/addon-links": "^8.3.6",
"@storybook/addon-styling-webpack": "^1.0.0",
"@chromatic-com/storybook": "^3.2.2",
"@storybook/addon-essentials": "^8.4.4",
"@storybook/addon-interactions": "^8.4.4",
"@storybook/addon-links": "^8.4.4",
"@storybook/addon-styling-webpack": "^1.0.1",
"@storybook/addon-webpack5-compiler-swc": "^1.0.5",
"@storybook/blocks": "^8.3.6",
"@storybook/blocks": "^8.4.4",
"@storybook/icons": "^1.2.12",
"@storybook/react": "^8.3.6",
"@storybook/react-webpack5": "^8.3.6",
"@storybook/types": "^8.3.6",
"@storybook/react": "^8.4.4",
"@storybook/react-webpack5": "^8.4.4",
"@storybook/types": "^8.4.4",
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/ui": "workspace:*",
"css-loader": "^7.1.2",
"less-loader": "^12.2.0",
"storybook": "^8.3.6",
"storybook": "^8.4.4",
"storybook-addon-swc": "^1.2.0",
"style-loader": "^4.0.0",
"tsconfig-paths-webpack-plugin": "^4.1.0",
"tsconfig-paths-webpack-plugin": "^4.2.0",
"typescript": "^5.6.3"
},
"devDependencies": {
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@
"release": "release-it"
},
"devDependencies": {
"@antfu/eslint-config": "3.8.0",
"@antfu/eslint-config": "3.9.1",
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@eslint-react/eslint-plugin": "^1.15.2",
"@playwright/test": "^1.48.0",
"@eslint-react/eslint-plugin": "^1.16.1",
"@playwright/test": "^1.48.2",
"@release-it-plugins/workspaces": "^4.2.0",
"@release-it/conventional-changelog": "^9.0.2",
"@storybook/react": "8.3.5",
"@types/node": "^22.8.4",
"@release-it/conventional-changelog": "^9.0.3",
"@storybook/react": "8.4.4",
"@types/node": "^22.9.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@univerjs-infra/shared": "workspace:*",
"@univerjs/design": "workspace:*",
"@vitejs/plugin-react": "^4.3.3",
"eslint": "9.13.0",
"eslint": "9.14.0",
"eslint-plugin-format": "^0.1.2",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-no-barrel-import": "^0.0.2",
Expand All @@ -72,7 +72,7 @@
"release-it": "^17.10.0",
"serve": "^14.2.4",
"tsx": "^4.19.2",
"turbo": "^2.2.3",
"turbo": "^2.3.0",
"typescript": "^5.6.3"
},
"lint-staged": {
Expand Down
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"dependencies": {
"@univerjs/protocol": "0.1.39-alpha.45",
"@wendellhu/redi": "0.16.1",
"dayjs": "^1.11.13",
"fast-diff": "1.3.0",
"kdbush": "^4.0.2",
"lodash-es": "^4.17.21",
Expand Down
34 changes: 34 additions & 0 deletions packages/core/src/shared/dayjs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright 2023-present DreamNum Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import dayjs from 'dayjs';
import advancedFormat from 'dayjs/plugin/advancedFormat';
import customParseFormat from 'dayjs/plugin/customParseFormat';
import localeData from 'dayjs/plugin/localeData';
import utc from 'dayjs/plugin/utc';
import weekday from 'dayjs/plugin/weekday';
import weekOfYear from 'dayjs/plugin/weekOfYear';
import weekYear from 'dayjs/plugin/weekYear';

dayjs.extend(customParseFormat);
dayjs.extend(advancedFormat);
dayjs.extend(weekday);
dayjs.extend(localeData);
dayjs.extend(weekOfYear);
dayjs.extend(weekYear);
dayjs.extend(utc);

export { dayjs };
1 change: 1 addition & 0 deletions packages/core/src/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export { ColorKit, COLORS, type IRgbColor, RGB_PAREN, RGBA_PAREN } from './color
export * from './command-enum';
export * from './common';
export * from './compare';
export * from './dayjs';
export * from './doc-tool';
export * from './generate';
export * from './hash-algorithm';
Expand Down
2 changes: 1 addition & 1 deletion packages/design/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"@rc-component/color-picker": "^2.0.1",
"@rc-component/trigger": "^2.2.5",
"@types/react-mentions": "^4.4.0",
"@univerjs/core": "workspace:*",
"@univerjs/icons": "^0.2.5",
"clsx": "^2.1.1",
"dayjs": "^1.11.13",
Expand All @@ -92,7 +93,6 @@
"react-transition-group": "^4.4.5"
},
"devDependencies": {
"@testing-library/react": "^16.0.1",
"@types/react-grid-layout": "^1.3.5",
"@types/react-transition-group": "^4.4.11",
"@univerjs-infra/shared": "workspace:*",
Expand Down
8 changes: 4 additions & 4 deletions packages/design/src/components/date-picker/DatePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* limitations under the License.
*/

import React, { useContext } from 'react';
import type { Dayjs } from 'dayjs';
import generateConfig from 'rc-picker/lib/generate/dayjs';
import type { dayjs } from '@univerjs/core';
import type { BasePickerPanelProps } from 'rc-picker';
import { PickerPanel } from 'rc-picker';
import generateConfig from 'rc-picker/lib/generate/dayjs';
import React, { useContext } from 'react';
import { ConfigContext } from '../config-provider';
import styles from './index.module.less';

export type IDatePanelProps = Omit<BasePickerPanelProps<Dayjs>, 'prefixCls' | 'locale' | 'generateConfig'>;
export type IDatePanelProps = Omit<BasePickerPanelProps<dayjs.Dayjs>, 'prefixCls' | 'locale' | 'generateConfig'>;

export const DatePanel = (props: IDatePanelProps) => {
const { locale } = useContext(ConfigContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/

import type { Meta } from '@storybook/react';
import React, { useState } from 'react';
import { dayjs } from '@univerjs/core';

import Dayjs from 'dayjs';
import React, { useState } from 'react';
import { DatePicker } from './DatePicker';

const meta: Meta<typeof DatePicker> = {
Expand All @@ -33,12 +33,10 @@ export default meta;

export const DatePickerBasic = {
render() {
const [value, setValue] = useState<Dayjs.Dayjs>(Dayjs());
const [value, setValue] = useState<dayjs.Dayjs>(dayjs());

return (
<>
<DatePicker value={value} onChange={setValue} />
</>
<DatePicker value={value} onChange={setValue} />
);
},
};
16 changes: 8 additions & 8 deletions packages/design/src/components/date-picker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,40 @@
* limitations under the License.
*/

import React, { useContext } from 'react';
import type { dayjs } from '@univerjs/core';
import type { PickerProps } from 'rc-picker';
import { CalendarSingle } from '@univerjs/icons';
import RcPicker from 'rc-picker';
import generateConfig from 'rc-picker/lib/generate/dayjs';
import { CalendarSingle } from '@univerjs/icons';
import type { Dayjs } from 'dayjs';
import React, { useContext } from 'react';
import { ConfigContext } from '../config-provider/ConfigProvider';
import styles from './index.module.less';

export interface IDatePickerProps extends Omit<PickerProps<Dayjs>, 'value' | 'onChange' | 'locale' | 'generateConfig' | 'prefixCls'> {
export interface IDatePickerProps extends Omit<PickerProps<dayjs.Dayjs>, 'value' | 'onChange' | 'locale' | 'generateConfig' | 'prefixCls'> {
/**
* The value of the date picker.
*/
value: Dayjs;
value: dayjs.Dayjs;

/**
* Callback when the value of the date picker changes.
*/
onChange: (date: Dayjs, dateString: string) => void;
onChange: (date: dayjs.Dayjs, dateString: string) => void;
}

export function DatePicker(props: IDatePickerProps) {
const { value, onChange, ...ext } = props;

const { locale } = useContext(ConfigContext);

function handleChange(date: Dayjs | Dayjs[], dateString: string | string[]) {
function handleChange(date: dayjs.Dayjs | dayjs.Dayjs[], dateString: string | string[]) {
if (!Array.isArray(date) && !Array.isArray(dateString)) {
onChange(date, dateString);
}
}

return (
<RcPicker<Dayjs>
<RcPicker<dayjs.Dayjs>
{...ext}
value={value}
prefixCls={styles.datePicker}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
*/

import type { Meta } from '@storybook/react';
import React, { useState } from 'react';

import type { Dayjs } from 'dayjs';
import dayjs from 'dayjs';
import type { NoUndefinedRangeValueType } from 'rc-picker/lib/PickerInput/RangePicker';
import { dayjs } from '@univerjs/core';
import React, { useState } from 'react';
import { DateRangePicker } from './DateRangePicker';

const meta: Meta<typeof DateRangePicker> = {
Expand All @@ -35,12 +34,10 @@ export default meta;

export const DateRangePickerBasic = {
render() {
const [value, setValue] = useState<NoUndefinedRangeValueType<Dayjs>>([dayjs(), dayjs().add(7, 'day')]);
const [value, setValue] = useState<NoUndefinedRangeValueType<dayjs.Dayjs>>([dayjs(), dayjs().add(7, 'day')]);

return (
<>
<DateRangePicker value={value} onChange={setValue} />
</>
<DateRangePicker value={value} onChange={setValue} />
);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,40 @@
* limitations under the License.
*/

import React, { useContext } from 'react';
import type { dayjs } from '@univerjs/core';
import type { NoUndefinedRangeValueType } from 'rc-picker/lib/PickerInput/RangePicker';
import { CalendarSingle, GuideSingle } from '@univerjs/icons';
import { RangePicker } from 'rc-picker';
import generateConfig from 'rc-picker/lib/generate/dayjs';
import { CalendarSingle, GuideSingle } from '@univerjs/icons';
import type { Dayjs } from 'dayjs';
import type { NoUndefinedRangeValueType } from 'rc-picker/lib/PickerInput/RangePicker';
import React, { useContext } from 'react';
import { ConfigContext } from '../config-provider/ConfigProvider';
import styles from './index.module.less';

export interface IDateRangePickerProps {
/**
* The value of the date picker.
*/
value: NoUndefinedRangeValueType<Dayjs>;
value: NoUndefinedRangeValueType<dayjs.Dayjs>;

/**
* Callback when the value of the date picker changes.
*/
onChange: (date: NoUndefinedRangeValueType<Dayjs>, dateString: [string, string]) => void;
onChange: (date: NoUndefinedRangeValueType<dayjs.Dayjs>, dateString: [string, string]) => void;
}

export function DateRangePicker(props: IDateRangePickerProps) {
const { value, onChange } = props;

const { locale } = useContext(ConfigContext);

function handleChange(date: NoUndefinedRangeValueType<Dayjs> | null, dateString: [string, string]) {
function handleChange(date: NoUndefinedRangeValueType<dayjs.Dayjs> | null, dateString: [string, string]) {
if (Array.isArray(date) && Array.isArray(dateString)) {
onChange(date, dateString);
}
}

return (
<RangePicker<Dayjs>
<RangePicker<dayjs.Dayjs>
value={value}
prefixCls={styles.dateRangePicker}
generateConfig={generateConfig}
Expand Down
15 changes: 0 additions & 15 deletions packages/design/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@
* limitations under the License.
*/

import dayjs from 'dayjs';
import advancedFormat from 'dayjs/plugin/advancedFormat';
import customParseFormat from 'dayjs/plugin/customParseFormat';
import localeData from 'dayjs/plugin/localeData';
import weekday from 'dayjs/plugin/weekday';
import weekOfYear from 'dayjs/plugin/weekOfYear';
import weekYear from 'dayjs/plugin/weekYear';

dayjs.extend(customParseFormat);
dayjs.extend(advancedFormat);
dayjs.extend(weekday);
dayjs.extend(localeData);
dayjs.extend(weekOfYear);
dayjs.extend(weekYear);

export { Avatar, type IAvatarProps } from './components/avatar';
export { Button, type ButtonSize, type ButtonType, type IButtonProps } from './components/button';
export { CascaderList, type ICascaderListProps } from './components/cascader-list';
Expand Down
3 changes: 1 addition & 2 deletions packages/sheets-conditional-formatting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/protocol": "0.1.39-alpha.45",
"@univerjs/sheets": "workspace:*",
"dayjs": "^1.11.13"
"@univerjs/sheets": "workspace:*"
},
"devDependencies": {
"@univerjs-infra/shared": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
import type { IStyleBase } from '@univerjs/core';
import type { IAverageHighlightCell, IConditionFormattingRule, IFormulaHighlightCell, IHighlightCell, INumberHighlightCell, IRankHighlightCell, ITextHighlightCell, ITimePeriodHighlightCell } from '../../models/type';
import type { ICalculateUnit } from './type';
import { CellValueType, ObjectMatrix, Range } from '@univerjs/core';
import { CellValueType, dayjs, ObjectMatrix, Range } from '@univerjs/core';
import { ERROR_TYPE_SET } from '@univerjs/engine-formula';
import dayjs from 'dayjs';
import { CFNumberOperator, CFRuleType, CFSubRuleType, CFTextOperator, CFTimePeriodOperator } from '../../base/const';
import { ConditionalFormattingFormulaService, FormulaResultStatus } from '../conditional-formatting-formula.service';
import { EMPTY_STYLE } from './type';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
import type { CellValue, ICellData, IObjectMatrixPrimitiveType, IRange, Nullable } from '@univerjs/core';
import type { IConditionFormattingRule, IValueConfig } from '../../models/type';
import type { IContext } from './type';
import { BooleanNumber, CellValueType, ColorKit, ObjectMatrix, Range } from '@univerjs/core';
import { BooleanNumber, CellValueType, ColorKit, dayjs, ObjectMatrix, Range } from '@univerjs/core';
import { BooleanValue } from '@univerjs/engine-formula';
import dayjs from 'dayjs';
import { CFNumberOperator, CFValueType } from '../../base/const';
import { ConditionalFormattingViewModel } from '../../models/conditional-formatting-view-model';
import { ConditionalFormattingFormulaService, FormulaResultStatus } from '../conditional-formatting-formula.service';
Expand Down
3 changes: 1 addition & 2 deletions packages/sheets-data-validation-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@
"@univerjs/sheets-numfmt": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
"@univerjs/ui": "workspace:*",
"clsx": "^2.1.1",
"dayjs": "^1.11.13"
"clsx": "^2.1.1"
},
"devDependencies": {
"@univerjs-infra/shared": "workspace:*",
Expand Down
Loading

0 comments on commit a3473b3

Please sign in to comment.