Skip to content

Commit 66490ba

Browse files
authored
♻️ cleanup: replace omit.js & remove some duplicate util (#8965)
* ♻️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: ​ <​>
1 parent 5bfd5ca commit 66490ba

File tree

34 files changed

+55
-102
lines changed

34 files changed

+55
-102
lines changed

packages/card/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"@ant-design/pro-utils": "2.16.3",
4141
"@babel/runtime": "^7.18.0",
4242
"classnames": "^2.3.2",
43-
"omit.js": "^2.0.2",
4443
"rc-resize-observer": "^1.0.0",
4544
"rc-util": "^5.4.0"
4645
},

packages/card/src/components/Card/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ConfigProvider, Tabs } from 'antd';
44

55
import useBreakpoint from 'antd/es/grid/hooks/useBreakpoint';
66
import classNames from 'classnames';
7-
import omit from 'omit.js';
7+
import omit from 'rc-util/lib/omit';
88
import useMergedState from 'rc-util/lib/hooks/useMergedState';
99
import React, { useContext } from 'react';
1010
import type { Breakpoint, CardProps, Gutter } from '../../typing';

packages/card/src/components/CheckCard/Group.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ConfigProvider, Skeleton } from 'antd';
44
import { RightOutlined } from '@ant-design/icons';
55
import { ProConfigProvider, proTheme } from '@ant-design/pro-provider';
66
import classNames from 'classnames';
7-
import omit from 'omit.js';
7+
import omit from 'rc-util/lib/omit';
88
import React, {
99
createContext,
1010
useCallback,

packages/field/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"dayjs": "^1.11.10",
3939
"lodash": "^4.17.21",
4040
"lodash-es": "^4.17.21",
41-
"omit.js": "^2.0.2",
4241
"rc-util": "^5.4.0",
4342
"swr": "^2.0.0"
4443
},

packages/field/src/components/Digit/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isNil } from '@ant-design/pro-utils';
22
import { InputNumber } from 'antd';
3-
import omit from 'omit.js';
3+
import omit from 'rc-util/lib/omit';
44
import React, { useCallback } from 'react';
55
import type { ProFieldFC } from '../../index';
66

packages/field/src/components/Money/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { intlMap as allIntlMap, useIntl } from '@ant-design/pro-provider';
22
import type { InputNumberProps } from 'antd';
33
import { InputNumber, Popover } from 'antd';
4-
import omit from 'omit.js';
4+
import omit from 'rc-util/lib/omit';
55
import useMergedState from 'rc-util/lib/hooks/useMergedState';
66
import React, { useCallback, useMemo } from 'react';
77
import type { ProFieldFC } from '../../index';

packages/field/src/components/Percent/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useIntl } from '@ant-design/pro-provider';
22
import { InputNumber } from 'antd';
3-
import toNumber from 'lodash-es/toNumber';
3+
import { toNumber } from './util';
44
import type { ReactNode } from 'react';
55
import React, { Fragment, useMemo } from 'react';
66
import type { ProFieldFC } from '../../index';

packages/field/src/components/Percent/util.ts

+12
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,15 @@ export function getRealTextWithPrecision(
2424
) {
2525
return precision >= 0 ? realValue?.toFixed(precision) : realValue;
2626
}
27+
28+
/**
29+
* 转化为数字
30+
* @copy from https://github.com/toss/es-toolkit/blob/32a183828c244d675f46810935e45dfefec81a54/src/compat/util/toNumber.ts#L19
31+
*/
32+
export function toNumber(value: any): number {
33+
if (typeof value === 'symbol' || value instanceof Symbol) {
34+
return NaN;
35+
}
36+
37+
return Number(value);
38+
}

packages/field/src/components/Progress/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useIntl } from '@ant-design/pro-provider';
22
import { InputNumber, Progress } from 'antd';
3-
import toNumber from 'lodash-es/toNumber';
3+
import { toNumber } from '../Percent/util';
44
import React, { useMemo } from 'react';
55
import type { ProFieldFC } from '../../index';
66

packages/field/src/components/Segmented/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Segmented, Spin } from 'antd';
2-
import omit from 'omit.js';
2+
import omit from 'rc-util/lib/omit';
33
import React, { useImperativeHandle, useRef } from 'react';
44
import type { ProFieldFC } from '../../index';
55
import type { FieldSelectProps } from '../Select';

packages/field/src/components/Switch/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useIntl } from '@ant-design/pro-provider';
22
import type { SwitchProps } from 'antd';
33
import { Switch } from 'antd';
4-
import Omit from 'omit.js';
4+
import omit from 'rc-util/lib/omit';
55
import React, { useMemo } from 'react';
66
import type { ProFieldFC } from '../../index';
77

@@ -40,7 +40,7 @@ const FieldSwitch: ProFieldFC<{ text: boolean; fieldProps?: SwitchProps }> = (
4040
<Switch
4141
ref={ref}
4242
size={light ? 'small' : undefined}
43-
{...Omit(fieldProps, ['value'])}
43+
{...omit(fieldProps, ['value'])}
4444
checked={fieldProps?.checked ?? fieldProps?.value}
4545
/>
4646
);

packages/field/src/components/TextArea/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useIntl } from '@ant-design/pro-provider';
22
import { Input } from 'antd';
3-
import omit from 'omit.js';
3+
import omit from 'rc-util/lib/omit';
44
import React from 'react';
55
import type { ProFieldFC } from '../../index';
66
import FieldTextAreaReadonly from './readonly';

packages/field/src/components/TextArea/readonly.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { ProFieldFC } from '../../index';
66

77
// 兼容代码-----------
88
import 'antd/lib/input/style';
9-
import omit from 'lodash-es/omit';
9+
import omit from 'rc-util/lib/omit';
1010
//------------
1111

1212
/**

packages/form/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"dayjs": "^1.11.10",
4646
"lodash": "^4.17.21",
4747
"lodash-es": "^4.17.21",
48-
"omit.js": "^2.0.2",
4948
"rc-resize-observer": "^1.1.0",
5049
"rc-util": "^5.0.6"
5150
},

packages/form/src/BaseForm/BaseForm.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { ConfigProvider, Form, Spin } from 'antd';
2727
import type { NamePath } from 'antd/lib/form/interface';
2828
import classNames from 'classnames';
2929
import type dayjs from 'dayjs';
30-
import omit from 'omit.js';
30+
import omit from 'rc-util/lib/omit';
3131
import get from 'rc-util/lib/utils/get';
3232
import { default as namePathSet, default as set } from 'rc-util/lib/utils/set';
3333
import { noteOnce } from 'rc-util/lib/warning';

packages/form/src/components/FormItem/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import type { FormItemProps } from 'antd';
1111
import { ConfigProvider, Form } from 'antd';
1212
import type { NamePath } from 'antd/lib/form/interface';
13-
import omit from 'omit.js';
13+
import omit from 'rc-util/lib/omit';
1414
import React, { useContext, useEffect, useMemo } from 'react';
1515
import type { LightWrapperProps } from '../../BaseForm';
1616
import { LightWrapper } from '../../BaseForm';

packages/form/src/components/List/ListContainer.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { ProProvider, useIntl } from '@ant-design/pro-provider';
33
import { nanoid, runFunction } from '@ant-design/pro-utils';
44
import { Button } from 'antd';
5-
import omit from 'omit.js';
5+
import omit from 'rc-util/lib/omit';
66
import type { CSSProperties } from 'react';
77
import { useContext, useMemo, useRef, useState } from 'react';
88
import { EditOrReadOnlyContext } from '../../BaseForm/EditOrReadOnlyContext';

packages/form/src/components/SchemaForm/valueType/field.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { omitUndefined } from '@ant-design/pro-utils';
2-
import omit from 'omit.js';
2+
import omit from 'rc-util/lib/omit';
33
import React from 'react';
44
import ProFormDependency from '../../Dependency';
55
import type { ProFormFieldProps } from '../../Field';

packages/form/src/components/Submitter/index.tsx

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { proTheme, useIntl } from '@ant-design/pro-provider';
22
import type { ButtonProps } from 'antd';
33
import { Button, Form } from 'antd';
4-
import omit from 'omit.js';
4+
import omit from 'rc-util/lib/omit';
55
import React from 'react';
66

77
/** @name 用于配置操作栏 */
@@ -25,15 +25,15 @@ export type SubmitterProps<T = Record<string, any>> = {
2525
resetButtonProps?: false | (ButtonProps & { preventDefault?: boolean });
2626
/** @name 自定义操作的渲染 */
2727
render?:
28-
| ((
29-
props: SubmitterProps &
30-
T & {
31-
submit: () => void;
32-
reset: () => void;
33-
},
34-
dom: JSX.Element[],
35-
) => React.ReactNode[] | React.ReactNode | false)
36-
| false;
28+
| ((
29+
props: SubmitterProps &
30+
T & {
31+
submit: () => void;
32+
reset: () => void;
33+
},
34+
dom: JSX.Element[],
35+
) => React.ReactNode[] | React.ReactNode | false)
36+
| false;
3737
};
3838

3939
/**
@@ -80,7 +80,7 @@ const Submitter: React.FC<SubmitterProps> = (props) => {
8080
if (resetButtonProps !== false) {
8181
dom.push(
8282
<Button
83-
{...omit(resetButtonProps, ['preventDefault'] as any)}
83+
{...omit(resetButtonProps ?? {}, ['preventDefault'] as any)}
8484
key="rest"
8585
onClick={(e) => {
8686
if (!resetButtonProps?.preventDefault) reset();

packages/form/src/components/Text/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useMountMergeState } from '@ant-design/pro-utils';
22
import { Form, Popover, PopoverProps, type InputProps } from 'antd';
33
import type { InputRef, PasswordProps } from 'antd/lib/input';
4-
import omit from 'omit.js';
4+
import omit from 'rc-util/lib/omit';
55
import React, { useState } from 'react';
66
import type { ProFormFieldItemProps } from '../../typing';
77
import ProField from '../Field';

packages/form/src/layouts/DrawerForm/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import type { DrawerProps, FormProps } from 'antd';
88
import { ConfigProvider, Drawer } from 'antd';
99
import classNames from 'classnames';
10-
import merge from 'lodash-es/merge';
10+
import { merge } from 'rc-util/lib/utils/set';
1111
import useMergedState from 'rc-util/lib/hooks/useMergedState';
1212
import { noteOnce } from 'rc-util/lib/warning';
1313
import React, {
@@ -112,7 +112,7 @@ function DrawerForm<T = Record<string, any>, U = Record<string, any>>({
112112
);
113113
const resizeInfo: CustomizeResizeType = React.useMemo(() => {
114114
const defaultResize: CustomizeResizeType = {
115-
onResize: () => {},
115+
onResize: () => { },
116116
maxWidth: isBrowser() ? window.innerWidth * 0.8 : undefined,
117117
minWidth: 300,
118118
};
@@ -230,7 +230,7 @@ function DrawerForm<T = Record<string, any>, U = Record<string, any>>({
230230
},
231231
},
232232
} as SubmitterProps,
233-
rest.submitter,
233+
rest.submitter ?? {},
234234
);
235235
}, [
236236
rest.submitter,

packages/form/src/layouts/LightFilter/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ConfigProvider } from 'antd';
77
import type { SizeType } from 'antd/lib/config-provider/SizeContext';
88
import type { TooltipPlacement } from 'antd/lib/tooltip';
99
import classNames from 'classnames';
10-
import omit from 'omit.js';
10+
import omit from 'rc-util/lib/omit';
1111
import React, {
1212
useContext,
1313
useEffect,

packages/form/src/layouts/ModalForm/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { openVisibleCompatible } from '@ant-design/pro-utils';
22
import type { FormProps, ModalProps } from 'antd';
33
import { ConfigProvider, Modal } from 'antd';
4-
import merge from 'lodash-es/merge';
4+
import { merge } from 'rc-util/lib/utils/set';
55
import useMergedState from 'rc-util/lib/hooks/useMergedState';
66
import { noteOnce } from 'rc-util/lib/warning';
77
import React, {
@@ -179,7 +179,7 @@ function ModalForm<T = Record<string, any>, U = Record<string, any>>({
179179
},
180180
},
181181
} as SubmitterProps,
182-
rest.submitter,
182+
rest.submitter ?? {},
183183
);
184184
}, [
185185
context.locale?.Modal?.cancelText,

packages/form/src/layouts/StepsForm/StepForm.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { FormInstance, FormProps } from 'antd';
2-
import omit from 'omit.js';
2+
import omit from 'rc-util/lib/omit';
33
import type { StepProps } from 'rc-steps/lib/Step';
44
import { noteOnce } from 'rc-util/lib/warning';
55
import { useContext, useEffect, useImperativeHandle, useRef } from 'react';

packages/layout/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
"classnames": "^2.3.2",
4545
"lodash": "^4.17.21",
4646
"lodash-es": "^4.17.21",
47-
"omit.js": "^2.0.2",
4847
"path-to-regexp": "8.2.0",
4948
"rc-resize-observer": "^1.1.0",
5049
"rc-util": "^5.0.6",

packages/layout/src/ProLayout.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { ConfigProvider, Layout } from 'antd';
1717
import type { AnyObject } from 'antd/es/_util/type';
1818
import type { ItemType } from 'antd/es/breadcrumb/Breadcrumb';
1919
import classNames from 'classnames';
20-
import Omit from 'omit.js';
20+
import omit from 'rc-util/lib/omit';
2121
import useMergedState from 'rc-util/lib/hooks/useMergedState';
2222
import warning from 'rc-util/lib/warning';
2323
import type { CSSProperties } from 'react';
@@ -600,7 +600,7 @@ const BaseProLayout: React.FC<ProLayoutProps> = (props) => {
600600
);
601601

602602
// Splicing parameters, adding menuData and formatMessage in props
603-
const defaultProps = Omit(
603+
const defaultProps = omit(
604604
{
605605
prefixCls,
606606
...props,

packages/layout/src/components/FooterToolbar/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { GenerateStyle } from '@ant-design/pro-provider';
33
import { isBrowser } from '@ant-design/pro-utils';
44
import { ConfigProvider } from 'antd';
55
import classNames from 'classnames';
6-
import omit from 'omit.js';
6+
import omit from 'rc-util/lib/omit';
77
import type { ReactNode } from 'react';
88
import React, { useContext, useEffect, useMemo } from 'react';
99
import { createPortal } from 'react-dom';

packages/layout/src/components/SettingDrawer/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
message,
2424
version,
2525
} from 'antd';
26-
import omit from 'omit.js';
26+
import omit from 'rc-util/lib/omit';
2727
import useMergedState from 'rc-util/lib/hooks/useMergedState';
2828
import React, { useEffect, useRef, useState } from 'react';
2929
import type { ProSettings } from '../../defaultSettings';

packages/layout/src/components/SiderMenu/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ProProvider } from '@ant-design/pro-provider';
22
import { openVisibleCompatible } from '@ant-design/pro-utils';
33
import { ConfigProvider, Drawer } from 'antd';
44
import classNames from 'classnames';
5-
import Omit from 'omit.js';
5+
import omit from 'rc-util/lib/omit';
66
import React, { useContext, useEffect } from 'react';
77
import type { PrivateSiderMenuProps, SiderMenuProps } from './SiderMenu';
88
import { SiderMenu } from './SiderMenu';
@@ -32,7 +32,7 @@ const SiderMenuWrapper: React.FC<SiderMenuProps & PrivateSiderMenuProps> = (
3232
// eslint-disable-next-line react-hooks/exhaustive-deps
3333
}, [isMobile]);
3434

35-
const omitProps = Omit(props, ['className', 'style']);
35+
const omitProps = omit(props, ['className', 'style']);
3636

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

packages/table/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
"dayjs": "^1.11.10",
5151
"lodash": "^4.17.21",
5252
"lodash-es": "^4.17.21",
53-
"omit.js": "^2.0.2",
5453
"rc-resize-observer": "^1.0.0",
5554
"rc-util": "^5.0.1"
5655
},

packages/table/src/components/ColumnSetting/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
import type { CheckboxChangeEvent } from 'antd/lib/checkbox';
2020
import type { DataNode } from 'antd/lib/tree';
2121
import classNames from 'classnames';
22-
import omit from 'omit.js';
22+
import omit from 'rc-util/lib/omit';
2323
import React, { useContext, useEffect, useMemo, useRef } from 'react';
2424
import type { ColumnsState } from '../../Store/Provide';
2525
import { TableContext } from '../../Store/Provide';

packages/table/src/components/Form/FormRender.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { ProSchemaComponentTypes } from '@ant-design/pro-utils';
99
import type { FormItemProps } from 'antd';
1010
import { ConfigProvider, Table } from 'antd';
1111
import classNames from 'classnames';
12-
import omit from 'omit.js';
12+
import omit from 'rc-util/lib/omit';
1313
import React, { useContext, useMemo } from 'react';
1414
import type { ActionType, ProColumns, ProTableProps } from '../../typing';
1515

packages/table/src/components/Form/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isDeepEqualReact, omitUndefined } from '@ant-design/pro-utils';
22
import type { TablePaginationConfig } from 'antd';
3-
import omit from 'omit.js';
3+
import omit from 'rc-util/lib/omit';
44
import React from 'react';
55
import type { ActionType, ProTableProps } from '../../typing';
66
import { isBordered } from '../../utils/index';

0 commit comments

Comments
 (0)