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

refactor: lodash-es instead of lodash #570

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
14 changes: 12 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
'plugin:@typescript-eslint/recommended',
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'react-hooks', 'lodash'],
plugins: ['@typescript-eslint', 'react-hooks'],
env: {
browser: true,
node: true,
Expand Down Expand Up @@ -73,6 +73,16 @@ module.exports = {
'func-names': 'off',
'consistent-return': 'off',
'default-case': 'off',
'lodash/import-scope': [2, 'method'],
'no-restricted-imports': [
'error',
{
paths: [
{
name: 'lodash',
message: 'Please use lodash-es instead.',
},
],
},
],
},
};
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"@testing-library/jest-dom": "^5.16.2",
"@testing-library/react": "^12.1.4",
"@testing-library/user-event": "^13.5.0",
"@types/lodash": "^4.14.178",
"@types/lodash-es": "^4.17.12",
"@types/node": "^20.14.11",
"@types/react": "^17.0.2",
"@types/react-dom": "17.0.2",
Expand Down Expand Up @@ -119,7 +119,6 @@
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-lodash": "^7.4.0",
"eslint-plugin-react": "^7.27.1",
"eslint-plugin-react-hooks": "^4.3.0",
"find-node-modules": "^2.1.2",
Expand Down Expand Up @@ -167,7 +166,7 @@
"classnames": "^2.3.1",
"dayjs": "^1.11.13",
"hoist-non-react-statics": "^3.3.2",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"react-spring": "9.6.1",
"react-transition-group": "^4.4.2",
"smoothscroll-polyfill": "^0.4.4",
Expand Down
2 changes: 1 addition & 1 deletion script/generate-coverage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs');
const path = require('path');
const camelCase = require('lodash/camelCase');
const { camelCase } = require('lodash-es');

const DomParser = require('dom-parser');

Expand Down
4 changes: 2 additions & 2 deletions script/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ const umdConfig = {
banner,
format: 'umd',
exports: 'named',
globals: { react: 'React', lodash: '_' },
globals: { react: 'React' },
sourcemap: true,
file: `dist/${name}.js`,
},
Expand All @@ -235,7 +235,7 @@ const umdMinConfig = {
banner,
format: 'umd',
exports: 'named',
globals: { react: 'React', lodash: '_' },
globals: { react: 'React' },
sourcemap: true,
file: `dist/${name}.min.js`,
},
Expand Down
2 changes: 1 addition & 1 deletion src/_common
Submodule _common updated 63 files
+3 −0 .eslintrc.js
+20 −7 .github/workflows/pull-request.yml
+229 −0 .github/workflows/tdesign-component-repositories-ci.yml
+2 −1 .vscode/settings.json
+0 −6 babel.config.js
+21 −0 docs/mobile/api/color-picker.en-US.md
+21 −0 docs/mobile/api/color-picker.md
+4 −3 js/color-picker/color.ts
+2 −3 js/color-picker/gradient.ts
+8 −2 js/date-picker/format.ts
+2 −10 js/date-picker/utils.ts
+1 −3 js/input-number/large-number.ts
+1 −3 js/input-number/number.ts
+1 −1 js/loading/circle-adapter.ts
+9 −0 js/package.json
+1 −1 js/slider/utils.ts
+1 −3 js/table/tree-store.ts
+1 −3 js/table/utils.ts
+1 −5 js/tree-v1/tree-node-model.ts
+8 −7 js/tree-v1/tree-node.ts
+9 −9 js/tree-v1/tree-store.ts
+4 −7 js/tree/tree-node-model.ts
+5 −7 js/tree/tree-node.ts
+9 −9 js/tree/tree-store.ts
+1 −2 js/upload/main.ts
+1 −1 js/upload/utils.ts
+1 −1 js/upload/xhr.ts
+1 −1 js/utils/calcTextareaHeight.ts
+42 −0 js/utils/easing.ts
+16 −0 js/utils/general.ts
+20 −10 js/utils/helper.ts
+17 −0 js/utils/responsive.ts
+4 −1 js/utils/setStyle.ts
+9 −0 js/utils/stringTemplate.ts
+13 −0 js/utils/types.ts
+6 −8 package.json
+0 −1 style/mobile/.stylelintignore
+34 −1 style/mobile/components/calendar/v2/_index.less
+2 −0 style/mobile/components/calendar/v2/_var.less
+1 −4 style/mobile/components/cell/v2/_index.less
+19 −20 style/mobile/components/color-picker/_index.less
+20 −20 style/mobile/components/color-picker/_var.less
+16 −8 style/mobile/components/dialog/v2/_index.less
+1 −1 style/mobile/components/dialog/v2/_var.less
+1 −0 style/mobile/components/popup/v2/_index.less
+2 −1 style/mobile/components/popup/v2/_var.less
+3 −7 style/mobile/components/tabs/v2/_index.less
+0 −31 style/mobile/package.json
+23 −22 style/mobile/theme/_dark.less
+6 −0 style/mobile/theme/_index.less
+161 −0 style/mobile/theme/_light.less
+8 −0 style/mobile/theme/_radius.less
+9 −0 style/mobile/theme/_spacer.less
+0 −36 style/mobile/webpack.config.js
+6 −0 style/package.json
+0 −1 style/web/.stylelintignore
+1 −1 style/web/_global.less
+1 −0 style/web/components/date-picker/_index.less
+1 −0 style/web/components/tabs/_index.less
+0 −14 style/web/package.json
+2 −2 test/script/generate-demo-test.js
+1 −1 test/unit/date-picker/utils.test.js
+23 −12 tsconfig.json
2 changes: 1 addition & 1 deletion src/_util/convertUnit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isNumber from 'lodash/isNumber';
import { isNumber } from 'lodash-es';

export const convertUnit = (val: string | number | undefined) => {
if (val == null) return 0;
Expand Down
5 changes: 2 additions & 3 deletions src/_util/getContainer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import isFunction from 'lodash/isFunction';
import isString from 'lodash/isString';
import { isFunction, isString } from 'lodash-es';

import { ScrollContainerElement, ScrollContainer } from '../common'
import { ScrollContainerElement, ScrollContainer } from '../common';

export function resolveContainer(getContainer: ScrollContainerElement | ScrollContainer): ScrollContainerElement {
if (isString(getContainer)) {
Expand Down
2 changes: 1 addition & 1 deletion src/_util/nearest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isNumber from 'lodash/isNumber';
import { isNumber } from 'lodash-es';

export interface nearestParams {
items: number[]; // 一组数字
Expand Down
2 changes: 1 addition & 1 deletion src/_util/parseTNode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ReactElement, ReactNode } from 'react';
import isFunction from 'lodash/isFunction';
import { isFunction } from 'lodash-es';
import { TNode } from '../common';
import log from '../_common/js/log';

Expand Down
3 changes: 1 addition & 2 deletions src/_util/withNativeProps.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react';
import type { CSSProperties, ReactElement } from 'react';
import cls from 'classnames';
import keys from 'lodash/keys';
import assign from 'lodash/assign';
import { assign, keys } from 'lodash-es';

export interface NativeProps<S extends string = never> {
className?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/back-top/Backtop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useRef, useEffect } from 'react';
import classNames from 'classnames';
import { useScroll, useMount, useBoolean } from 'ahooks';
import smoothscroll from 'smoothscroll-polyfill';
import isString from 'lodash/isString';
import { isString } from 'lodash-es';
import { Icon } from 'tdesign-icons-react';
import withNativeProps, { NativeProps } from '../_util/withNativeProps';
import useConfig from '../_util/useConfig';
Expand Down
3 changes: 1 addition & 2 deletions src/badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { forwardRef, useMemo } from 'react';
import classNames from 'classnames';
import isNumber from 'lodash/isNumber';
import isString from 'lodash/isString';
import { isNumber, isString } from 'lodash-es';
import type { StyledProps } from '../common';
import type { TdBadgeProps } from './type';
import { badgeDefaultProps } from './defaultProps';
Expand Down
2 changes: 1 addition & 1 deletion src/cell/Cell.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useMemo, useCallback } from 'react';
import classnames from 'classnames';
import isString from 'lodash/isString';
import { isString } from 'lodash-es';
import { ChevronRightIcon } from 'tdesign-icons-react';

import parseTNode from '../_util/parseTNode';
Expand Down
2 changes: 1 addition & 1 deletion src/checkbox/CheckboxGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FC, ReactElement, useEffect, useMemo, useState } from 'react';
import isNumber from 'lodash/isNumber';
import { isNumber } from 'lodash-es';
import classNames from 'classnames';
import { CheckboxOption, CheckboxOptionObj, TdCheckboxGroupProps } from './type';
import { StyledProps } from '../common';
Expand Down
4 changes: 1 addition & 3 deletions src/grid/GridItem.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React, { FC, useContext, useMemo } from 'react';
import cls from 'classnames';
import isString from 'lodash/isString';
import isObject from 'lodash/isObject';
import isFunction from 'lodash/isFunction';
import { isFunction, isString, isObject } from 'lodash-es';
import useConfig from '../_util/useConfig';
import parseTNode from '../_util/parseTNode';
import useDefaultProps from '../hooks/useDefaultProps';
Expand Down
2 changes: 1 addition & 1 deletion src/guide/Guide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { TdGuideProps, GuideCrossProps } from './type';

import Portal from '../common/Portal';
import { SizeEnum, StyledProps } from '../common';
import setStyle from '../_common/js/utils/set-style';
import setStyle from '../_common/js/utils/setStyle';

import { usePrefixClass } from '../hooks/useClass';
import useDefault from '../_util/useDefault';
Expand Down
3 changes: 1 addition & 2 deletions src/guide/utils/dom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import isString from 'lodash/isString';
import isFunction from 'lodash/isFunction';
import { isFunction, isString } from 'lodash-es';
import { AttachNode } from '../../common';
import { elementInViewport, getWindowScroll, getWindowSize } from './shared';
/**
Expand Down
3 changes: 1 addition & 2 deletions src/guide/utils/shared.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import isFunction from 'lodash/isFunction';
import isString from 'lodash/isString';
import { isFunction, isString } from 'lodash-es';

const trim = (str: string): string => (str || '').replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, '');

Expand Down
2 changes: 1 addition & 1 deletion src/indexes/Indexes.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useRef, useEffect, useMemo } from 'react';
import throttle from 'lodash/throttle';
import { throttle } from 'lodash-es';
import cls from 'classnames';
import { TdIndexesProps } from './type';
import { StyledProps } from '../common';
Expand Down
2 changes: 1 addition & 1 deletion src/input/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
import type { FocusEvent, TouchEvent, CompositionEvent, FormEvent } from 'react';
import classNames from 'classnames';
import isFunction from 'lodash/isFunction';
import { isFunction } from 'lodash-es';
import { CloseCircleFilledIcon, BrowseOffIcon, BrowseIcon } from 'tdesign-icons-react';
import useDefault from '../_util/useDefault';
import parseTNode from '../_util/parseTNode';
Expand Down
2 changes: 1 addition & 1 deletion src/message/Message.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState, useRef } from 'react';
import classNames from 'classnames';
import { useTimeout } from 'ahooks';
import isObject from 'lodash/isObject';
import { isObject } from 'lodash-es';
import { CSSTransition } from 'react-transition-group';
import { Icon } from 'tdesign-icons-react';

Expand Down
1 change: 0 additions & 1 deletion src/message/hooks/useMessageCssTransition.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useRef } from 'react';
// import identity from 'lodash/identity';
import ReactDOM from 'react-dom';

interface UseMessageCssTransitionParams {
Expand Down
3 changes: 1 addition & 2 deletions src/notice-bar/NoticeBar.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { InfoCircleFilledIcon, CheckCircleFilledIcon } from 'tdesign-icons-react';
import classNames from 'classnames';
import isObject from 'lodash/isObject';
import isArray from 'lodash/isArray';
import { isArray, isObject } from 'lodash-es';
import parseTNode from '../_util/parseTNode';
import Swiper from '../swiper';
import SwiperItem from '../swiper/SwiperItem';
Expand Down
2 changes: 1 addition & 1 deletion src/picker/PickerItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FC, useRef, memo, useCallback, useContext, useMemo } from 'react';
import { useDebounceEffect } from 'ahooks';
import isUndefined from 'lodash/isUndefined';
import { isUndefined } from 'lodash-es';
import { useDrag } from '@use-gesture/react';
import { useSpring, animated } from '@react-spring/web';
import useConfig from '../_util/useConfig';
Expand Down
2 changes: 1 addition & 1 deletion src/picker/PickerView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FC, useMemo } from 'react';
import isUndefined from 'lodash/isUndefined';
import { isUndefined } from 'lodash-es';
import useConfig from '../_util/useConfig';
import useDefault from '../_util/useDefault';
import withNativeProps, { NativeProps } from '../_util/withNativeProps';
Expand Down
2 changes: 1 addition & 1 deletion src/picker/_example/base.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import isEmpty from 'lodash/isEmpty';
import { isEmpty } from 'lodash-es';
import { Picker, PickerItem, Cell } from 'tdesign-mobile-react';
import TDemoBlock from '../../../site/mobile/components/DemoBlock';
import './style/index.less';
Expand Down
2 changes: 1 addition & 1 deletion src/progress/Progress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
CloseCircleFilledIcon,
ErrorCircleFilledIcon,
} from 'tdesign-icons-react';
import isString from 'lodash/isString';
import { isString } from 'lodash-es';
import { StyledProps } from '../common';
import { TdProgressProps } from './type';
import useConfig from '../_util/useConfig';
Expand Down
3 changes: 1 addition & 2 deletions src/pull-down-refresh/PullDownRefresh.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useRef, useState, type ReactNode, useEffect, useMemo } from 'react';
import classNames from 'classnames';
import uniqueId from 'lodash/uniqueId';
import isBoolean from 'lodash/isBoolean';
import { uniqueId, isBoolean } from 'lodash-es';

import { useDebounceFn } from 'ahooks';
import Loading from '../loading';
Expand Down
3 changes: 1 addition & 2 deletions src/skeleton/Skeleton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useState, useEffect } from 'react';
import classNames from 'classnames';
import isNumber from 'lodash/isNumber';
import isArray from 'lodash/isArray';
import { isArray, isNumber } from 'lodash-es';
import { SkeletonRowCol, SkeletonRowColObj, TdSkeletonProps } from './type';
import { StyledProps, Styles } from '../common';
import { skeletonDefaultProps } from './defaultProps';
Expand Down
3 changes: 1 addition & 2 deletions src/slider/Slider.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, { FC, useEffect, useRef, useState } from 'react';
import type { MouseEvent, TouchEvent } from 'react';
import classNames from 'classnames';
import isFunction from 'lodash/isFunction';
import cloneDeep from 'lodash/cloneDeep';
import { cloneDeep, isFunction } from 'lodash-es';
import { usePrefixClass } from '../hooks/useClass';
import useDefaultProps from '../hooks/useDefaultProps';
import useDefault from '../_util/useDefault';
Expand Down
3 changes: 1 addition & 2 deletions src/swipe-cell/SwipeCell.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { forwardRef, useImperativeHandle, useRef, useMemo, useState } from 'react';
import type { ReactNode } from 'react';
import isArray from 'lodash/isArray';
import isBoolean from 'lodash/isBoolean';
import { isArray, isBoolean } from 'lodash-es';
import classNames from 'classnames';
import { useClickAway } from 'ahooks';
import { useDrag } from '@use-gesture/react';
Expand Down
2 changes: 1 addition & 1 deletion src/switch/Switch.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { forwardRef, useMemo } from 'react';
import classNames from 'classnames';
import isArray from 'lodash/isArray';
import { isArray } from 'lodash-es';
import Loading from '../loading';
import { TdSwitchProps, SwitchValue } from './type';
import { switchDefaultProps } from './defaultProps';
Expand Down
3 changes: 1 addition & 2 deletions src/table/BaseTable.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { forwardRef, useRef } from 'react';
import isFunction from 'lodash/isFunction';
import get from 'lodash/get';
import { get, isFunction } from 'lodash-es';
import cx from 'classnames';

import { StyledProps } from '../common';
Expand Down