Skip to content

Commit

Permalink
♻️ cleanup: replace omit.js & remove some duplicate util (#8965)
Browse files Browse the repository at this point in the history
* ♻️refactor: cleanup duplicate util

* deps: remove omit.js

* chore: update pnpm-lock.yaml

* ♻️refactor: replace part of the `merge` util

* ♻️refactor: replace lodash/toNumber

* chore: update pnpm-lock.ymal

* ​

---------

Co-authored-by: ​ <​>
  • Loading branch information
Wxh16144 authored Jan 16, 2025
1 parent 5bfd5ca commit 66490ba
Show file tree
Hide file tree
Showing 34 changed files with 55 additions and 102 deletions.
1 change: 0 additions & 1 deletion packages/card/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"@ant-design/pro-utils": "2.16.3",
"@babel/runtime": "^7.18.0",
"classnames": "^2.3.2",
"omit.js": "^2.0.2",
"rc-resize-observer": "^1.0.0",
"rc-util": "^5.4.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/card/src/components/Card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ConfigProvider, Tabs } from 'antd';

import useBreakpoint from 'antd/es/grid/hooks/useBreakpoint';
import classNames from 'classnames';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import React, { useContext } from 'react';
import type { Breakpoint, CardProps, Gutter } from '../../typing';
Expand Down
2 changes: 1 addition & 1 deletion packages/card/src/components/CheckCard/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ConfigProvider, Skeleton } from 'antd';
import { RightOutlined } from '@ant-design/icons';
import { ProConfigProvider, proTheme } from '@ant-design/pro-provider';
import classNames from 'classnames';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import React, {
createContext,
useCallback,
Expand Down
1 change: 0 additions & 1 deletion packages/field/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"dayjs": "^1.11.10",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"omit.js": "^2.0.2",
"rc-util": "^5.4.0",
"swr": "^2.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/field/src/components/Digit/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isNil } from '@ant-design/pro-utils';
import { InputNumber } from 'antd';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import React, { useCallback } from 'react';
import type { ProFieldFC } from '../../index';

Expand Down
2 changes: 1 addition & 1 deletion packages/field/src/components/Money/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { intlMap as allIntlMap, useIntl } from '@ant-design/pro-provider';
import type { InputNumberProps } from 'antd';
import { InputNumber, Popover } from 'antd';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import React, { useCallback, useMemo } from 'react';
import type { ProFieldFC } from '../../index';
Expand Down
2 changes: 1 addition & 1 deletion packages/field/src/components/Percent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useIntl } from '@ant-design/pro-provider';
import { InputNumber } from 'antd';
import toNumber from 'lodash-es/toNumber';
import { toNumber } from './util';
import type { ReactNode } from 'react';
import React, { Fragment, useMemo } from 'react';
import type { ProFieldFC } from '../../index';
Expand Down
12 changes: 12 additions & 0 deletions packages/field/src/components/Percent/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,15 @@ export function getRealTextWithPrecision(
) {
return precision >= 0 ? realValue?.toFixed(precision) : realValue;
}

/**
* 转化为数字
* @copy from https://github.com/toss/es-toolkit/blob/32a183828c244d675f46810935e45dfefec81a54/src/compat/util/toNumber.ts#L19
*/
export function toNumber(value: any): number {
if (typeof value === 'symbol' || value instanceof Symbol) {
return NaN;
}

return Number(value);
}
2 changes: 1 addition & 1 deletion packages/field/src/components/Progress/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useIntl } from '@ant-design/pro-provider';
import { InputNumber, Progress } from 'antd';
import toNumber from 'lodash-es/toNumber';
import { toNumber } from '../Percent/util';
import React, { useMemo } from 'react';
import type { ProFieldFC } from '../../index';

Expand Down
2 changes: 1 addition & 1 deletion packages/field/src/components/Segmented/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Segmented, Spin } from 'antd';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import React, { useImperativeHandle, useRef } from 'react';
import type { ProFieldFC } from '../../index';
import type { FieldSelectProps } from '../Select';
Expand Down
4 changes: 2 additions & 2 deletions packages/field/src/components/Switch/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useIntl } from '@ant-design/pro-provider';
import type { SwitchProps } from 'antd';
import { Switch } from 'antd';
import Omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import React, { useMemo } from 'react';
import type { ProFieldFC } from '../../index';

Expand Down Expand Up @@ -40,7 +40,7 @@ const FieldSwitch: ProFieldFC<{ text: boolean; fieldProps?: SwitchProps }> = (
<Switch
ref={ref}
size={light ? 'small' : undefined}
{...Omit(fieldProps, ['value'])}
{...omit(fieldProps, ['value'])}
checked={fieldProps?.checked ?? fieldProps?.value}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/field/src/components/TextArea/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useIntl } from '@ant-design/pro-provider';
import { Input } from 'antd';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import React from 'react';
import type { ProFieldFC } from '../../index';
import FieldTextAreaReadonly from './readonly';
Expand Down
2 changes: 1 addition & 1 deletion packages/field/src/components/TextArea/readonly.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { ProFieldFC } from '../../index';

// 兼容代码-----------
import 'antd/lib/input/style';
import omit from 'lodash-es/omit';
import omit from 'rc-util/lib/omit';
//------------

/**
Expand Down
1 change: 0 additions & 1 deletion packages/form/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"dayjs": "^1.11.10",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"omit.js": "^2.0.2",
"rc-resize-observer": "^1.1.0",
"rc-util": "^5.0.6"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/form/src/BaseForm/BaseForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { ConfigProvider, Form, Spin } from 'antd';
import type { NamePath } from 'antd/lib/form/interface';
import classNames from 'classnames';
import type dayjs from 'dayjs';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import get from 'rc-util/lib/utils/get';
import { default as namePathSet, default as set } from 'rc-util/lib/utils/set';
import { noteOnce } from 'rc-util/lib/warning';
Expand Down
2 changes: 1 addition & 1 deletion packages/form/src/components/FormItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import type { FormItemProps } from 'antd';
import { ConfigProvider, Form } from 'antd';
import type { NamePath } from 'antd/lib/form/interface';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import React, { useContext, useEffect, useMemo } from 'react';
import type { LightWrapperProps } from '../../BaseForm';
import { LightWrapper } from '../../BaseForm';
Expand Down
2 changes: 1 addition & 1 deletion packages/form/src/components/List/ListContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { ProProvider, useIntl } from '@ant-design/pro-provider';
import { nanoid, runFunction } from '@ant-design/pro-utils';
import { Button } from 'antd';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import type { CSSProperties } from 'react';
import { useContext, useMemo, useRef, useState } from 'react';
import { EditOrReadOnlyContext } from '../../BaseForm/EditOrReadOnlyContext';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { omitUndefined } from '@ant-design/pro-utils';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import React from 'react';
import ProFormDependency from '../../Dependency';
import type { ProFormFieldProps } from '../../Field';
Expand Down
22 changes: 11 additions & 11 deletions packages/form/src/components/Submitter/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { proTheme, useIntl } from '@ant-design/pro-provider';
import type { ButtonProps } from 'antd';
import { Button, Form } from 'antd';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import React from 'react';

/** @name 用于配置操作栏 */
Expand All @@ -25,15 +25,15 @@ export type SubmitterProps<T = Record<string, any>> = {
resetButtonProps?: false | (ButtonProps & { preventDefault?: boolean });
/** @name 自定义操作的渲染 */
render?:
| ((
props: SubmitterProps &
T & {
submit: () => void;
reset: () => void;
},
dom: JSX.Element[],
) => React.ReactNode[] | React.ReactNode | false)
| false;
| ((
props: SubmitterProps &
T & {
submit: () => void;
reset: () => void;
},
dom: JSX.Element[],
) => React.ReactNode[] | React.ReactNode | false)
| false;
};

/**
Expand Down Expand Up @@ -80,7 +80,7 @@ const Submitter: React.FC<SubmitterProps> = (props) => {
if (resetButtonProps !== false) {
dom.push(
<Button
{...omit(resetButtonProps, ['preventDefault'] as any)}
{...omit(resetButtonProps ?? {}, ['preventDefault'] as any)}
key="rest"
onClick={(e) => {
if (!resetButtonProps?.preventDefault) reset();
Expand Down
2 changes: 1 addition & 1 deletion packages/form/src/components/Text/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMountMergeState } from '@ant-design/pro-utils';
import { Form, Popover, PopoverProps, type InputProps } from 'antd';
import type { InputRef, PasswordProps } from 'antd/lib/input';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import React, { useState } from 'react';
import type { ProFormFieldItemProps } from '../../typing';
import ProField from '../Field';
Expand Down
6 changes: 3 additions & 3 deletions packages/form/src/layouts/DrawerForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import type { DrawerProps, FormProps } from 'antd';
import { ConfigProvider, Drawer } from 'antd';
import classNames from 'classnames';
import merge from 'lodash-es/merge';
import { merge } from 'rc-util/lib/utils/set';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import { noteOnce } from 'rc-util/lib/warning';
import React, {
Expand Down Expand Up @@ -112,7 +112,7 @@ function DrawerForm<T = Record<string, any>, U = Record<string, any>>({
);
const resizeInfo: CustomizeResizeType = React.useMemo(() => {
const defaultResize: CustomizeResizeType = {
onResize: () => {},
onResize: () => { },
maxWidth: isBrowser() ? window.innerWidth * 0.8 : undefined,
minWidth: 300,
};
Expand Down Expand Up @@ -230,7 +230,7 @@ function DrawerForm<T = Record<string, any>, U = Record<string, any>>({
},
},
} as SubmitterProps,
rest.submitter,
rest.submitter ?? {},
);
}, [
rest.submitter,
Expand Down
2 changes: 1 addition & 1 deletion packages/form/src/layouts/LightFilter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ConfigProvider } from 'antd';
import type { SizeType } from 'antd/lib/config-provider/SizeContext';
import type { TooltipPlacement } from 'antd/lib/tooltip';
import classNames from 'classnames';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import React, {
useContext,
useEffect,
Expand Down
4 changes: 2 additions & 2 deletions packages/form/src/layouts/ModalForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { openVisibleCompatible } from '@ant-design/pro-utils';
import type { FormProps, ModalProps } from 'antd';
import { ConfigProvider, Modal } from 'antd';
import merge from 'lodash-es/merge';
import { merge } from 'rc-util/lib/utils/set';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import { noteOnce } from 'rc-util/lib/warning';
import React, {
Expand Down Expand Up @@ -179,7 +179,7 @@ function ModalForm<T = Record<string, any>, U = Record<string, any>>({
},
},
} as SubmitterProps,
rest.submitter,
rest.submitter ?? {},
);
}, [
context.locale?.Modal?.cancelText,
Expand Down
2 changes: 1 addition & 1 deletion packages/form/src/layouts/StepsForm/StepForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FormInstance, FormProps } from 'antd';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import type { StepProps } from 'rc-steps/lib/Step';
import { noteOnce } from 'rc-util/lib/warning';
import { useContext, useEffect, useImperativeHandle, useRef } from 'react';
Expand Down
1 change: 0 additions & 1 deletion packages/layout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"classnames": "^2.3.2",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"omit.js": "^2.0.2",
"path-to-regexp": "8.2.0",
"rc-resize-observer": "^1.1.0",
"rc-util": "^5.0.6",
Expand Down
4 changes: 2 additions & 2 deletions packages/layout/src/ProLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ConfigProvider, Layout } from 'antd';
import type { AnyObject } from 'antd/es/_util/type';
import type { ItemType } from 'antd/es/breadcrumb/Breadcrumb';
import classNames from 'classnames';
import Omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import warning from 'rc-util/lib/warning';
import type { CSSProperties } from 'react';
Expand Down Expand Up @@ -600,7 +600,7 @@ const BaseProLayout: React.FC<ProLayoutProps> = (props) => {
);

// Splicing parameters, adding menuData and formatMessage in props
const defaultProps = Omit(
const defaultProps = omit(
{
prefixCls,
...props,
Expand Down
2 changes: 1 addition & 1 deletion packages/layout/src/components/FooterToolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { GenerateStyle } from '@ant-design/pro-provider';
import { isBrowser } from '@ant-design/pro-utils';
import { ConfigProvider } from 'antd';
import classNames from 'classnames';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import type { ReactNode } from 'react';
import React, { useContext, useEffect, useMemo } from 'react';
import { createPortal } from 'react-dom';
Expand Down
2 changes: 1 addition & 1 deletion packages/layout/src/components/SettingDrawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
message,
version,
} from 'antd';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import React, { useEffect, useRef, useState } from 'react';
import type { ProSettings } from '../../defaultSettings';
Expand Down
4 changes: 2 additions & 2 deletions packages/layout/src/components/SiderMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ProProvider } from '@ant-design/pro-provider';
import { openVisibleCompatible } from '@ant-design/pro-utils';
import { ConfigProvider, Drawer } from 'antd';
import classNames from 'classnames';
import Omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import React, { useContext, useEffect } from 'react';
import type { PrivateSiderMenuProps, SiderMenuProps } from './SiderMenu';
import { SiderMenu } from './SiderMenu';
Expand Down Expand Up @@ -32,7 +32,7 @@ const SiderMenuWrapper: React.FC<SiderMenuProps & PrivateSiderMenuProps> = (
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isMobile]);

const omitProps = Omit(props, ['className', 'style']);
const omitProps = omit(props, ['className', 'style']);

const { direction } = React.useContext(ConfigProvider.ConfigContext);

Expand Down
1 change: 0 additions & 1 deletion packages/table/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"dayjs": "^1.11.10",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"omit.js": "^2.0.2",
"rc-resize-observer": "^1.0.0",
"rc-util": "^5.0.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/table/src/components/ColumnSetting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import type { CheckboxChangeEvent } from 'antd/lib/checkbox';
import type { DataNode } from 'antd/lib/tree';
import classNames from 'classnames';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import React, { useContext, useEffect, useMemo, useRef } from 'react';
import type { ColumnsState } from '../../Store/Provide';
import { TableContext } from '../../Store/Provide';
Expand Down
2 changes: 1 addition & 1 deletion packages/table/src/components/Form/FormRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { ProSchemaComponentTypes } from '@ant-design/pro-utils';
import type { FormItemProps } from 'antd';
import { ConfigProvider, Table } from 'antd';
import classNames from 'classnames';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import React, { useContext, useMemo } from 'react';
import type { ActionType, ProColumns, ProTableProps } from '../../typing';

Expand Down
2 changes: 1 addition & 1 deletion packages/table/src/components/Form/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isDeepEqualReact, omitUndefined } from '@ant-design/pro-utils';
import type { TablePaginationConfig } from 'antd';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import React from 'react';
import type { ActionType, ProTableProps } from '../../typing';
import { isBordered } from '../../utils/index';
Expand Down
Loading

0 comments on commit 66490ba

Please sign in to comment.