From deb5485c4752ef241a1508364853e67f7a8663d0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E8=B1=AA?= <1844749591@qq.com>
Date: Sun, 23 Feb 2025 17:41:14 +0800
Subject: [PATCH 1/6] chore: update dependencies and import paths to
@rc-component packages dependencies
---
README.md | 6 ++--
docs/examples/antd.tsx | 2 +-
docs/examples/debug.tsx | 2 +-
docs/examples/rtl-antd.tsx | 6 ++--
package.json | 13 ++++----
src/Menu.tsx | 8 ++---
src/MenuItem.tsx | 8 ++---
src/MenuItemGroup.tsx | 2 +-
src/SubMenu/InlineSubMenuList.tsx | 11 ++-----
src/SubMenu/PopupTrigger.tsx | 4 +--
src/SubMenu/index.tsx | 2 +-
src/context/MenuContext.tsx | 6 ++--
src/hooks/useAccessibility.ts | 41 ++++++-----------------
src/hooks/useKeyRecords.ts | 2 +-
src/hooks/useUUID.ts | 6 ++--
src/utils/commonUtil.ts | 55 +++++++++++++++----------------
src/utils/motionUtil.ts | 2 +-
src/utils/warnUtil.ts | 2 +-
tests/Focus.spec.tsx | 2 +-
tests/Keyboard.spec.tsx | 4 +--
tests/Menu.spec.tsx | 10 +++---
tests/MenuItem.spec.tsx | 2 +-
tests/Responsive.spec.tsx | 4 +--
tests/SubMenu.spec.tsx | 2 +-
24 files changed, 85 insertions(+), 117 deletions(-)
diff --git a/README.md b/README.md
index e2f81ccf..a826091b 100644
--- a/README.md
+++ b/README.md
@@ -55,8 +55,8 @@ ReactDOM.render(
## Compatibility
| [
](http://godban.github.io/browsers-support-badges/)
IE / Edge | [
](http://godban.github.io/browsers-support-badges/)
Firefox | [
](http://godban.github.io/browsers-support-badges/)
Chrome | [
](http://godban.github.io/browsers-support-badges/)
Safari | [
](http://godban.github.io/browsers-support-badges/)
Electron |
-| --- | --- | --- | --- | --- |
-| IE11, Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
+| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| IE11, Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
## API
@@ -172,7 +172,7 @@ ReactDOM.render(
openAnimation |
{enter:function,leave:function}|String |
|
- animate when sub menu open or close. see rc-motion for object type. |
+ animate when sub menu open or close. see @rc-component/motion for object type. |
openTransition |
diff --git a/docs/examples/antd.tsx b/docs/examples/antd.tsx
index f5bd0bba..7dac7ffd 100644
--- a/docs/examples/antd.tsx
+++ b/docs/examples/antd.tsx
@@ -1,7 +1,7 @@
/* eslint-disable no-console, react/require-default-props, no-param-reassign */
import React from 'react';
-import type { CSSMotionProps } from 'rc-motion';
+import type { CSSMotionProps } from '@rc-component/motion';
import Menu, { SubMenu, Item as MenuItem, Divider, MenuProps } from '../../src';
import '../../assets/index.less';
diff --git a/docs/examples/debug.tsx b/docs/examples/debug.tsx
index a9db1e87..0fca53ab 100644
--- a/docs/examples/debug.tsx
+++ b/docs/examples/debug.tsx
@@ -1,7 +1,7 @@
/* eslint no-console:0 */
import React, { useRef } from 'react';
-import type { CSSMotionProps } from 'rc-motion';
+import type { CSSMotionProps } from '@rc-component/motion';
import Menu, { ItemGroup as MenuItemGroup, MenuItem } from '../../src';
import type { MenuProps } from '../../src';
import '../../assets/index.less';
diff --git a/docs/examples/rtl-antd.tsx b/docs/examples/rtl-antd.tsx
index 91984cf7..7ba5bdd1 100644
--- a/docs/examples/rtl-antd.tsx
+++ b/docs/examples/rtl-antd.tsx
@@ -1,7 +1,7 @@
/* eslint-disable no-console, react/require-default-props, no-param-reassign */
import React from 'react';
-import type { CSSMotionProps } from 'rc-motion';
+import type { CSSMotionProps } from '@rc-component/motion';
import Menu, { SubMenu, Item as MenuItem, Divider, MenuProps } from 'rc-menu';
import '../../assets/index.less';
@@ -122,8 +122,8 @@ const children2 = [
const customizeIndicator = Add More Items;
interface CommonMenuState {
- children: React.ReactNode;
- overflowedIndicator?: React.ReactNode;
+ children: React.ReactNode;
+ overflowedIndicator?: React.ReactNode;
}
class CommonMenu extends React.Component {
diff --git a/package.json b/package.json
index 4301b3ba..c3d8103d 100644
--- a/package.json
+++ b/package.json
@@ -37,22 +37,22 @@
"docs:deploy": "gh-pages -d .doc",
"lint": "eslint src/ --ext .tsx,.ts,.jsx,.js",
"now-build": "npm run build",
- "prepublishOnly": "npm run compile && np --yolo --no-publish",
+ "prepublishOnly": "npm run compile && rc-np",
"postpublish": "tnpm sync rc-menu",
"start": "dumi dev",
"test": "rc-test",
"prepare": "husky && dumi setup"
},
"dependencies": {
- "@babel/runtime": "^7.10.1",
- "@rc-component/trigger": "^2.0.0",
+ "@rc-component/motion": "^1.1.4",
+ "@rc-component/trigger": "^3.0.0",
+ "@rc-component/util": "^1.0.0",
"classnames": "2.x",
- "rc-motion": "^2.4.3",
- "rc-overflow": "^1.3.1",
- "rc-util": "^5.27.0"
+ "rc-overflow": "^1.3.1"
},
"devDependencies": {
"@rc-component/father-plugin": "^1.0.0",
+ "@rc-component/np": "^1.0.3",
"@testing-library/jest-dom": "^6.1.5",
"@testing-library/react": "^16.0.0",
"@types/jest": "^29.5.2",
@@ -70,7 +70,6 @@
"husky": "^9.1.6",
"less": "^4.1.3",
"lint-staged": "^15.2.10",
- "np": "^10.0.5",
"prettier": "^3.3.3",
"rc-test": "^7.0.14",
"react": "^18.3.1",
diff --git a/src/Menu.tsx b/src/Menu.tsx
index edad0c5b..b5dfdaf9 100644
--- a/src/Menu.tsx
+++ b/src/Menu.tsx
@@ -1,9 +1,9 @@
import classNames from 'classnames';
-import type { CSSMotionProps } from 'rc-motion';
+import type { CSSMotionProps } from '@rc-component/motion';
import Overflow from 'rc-overflow';
-import useMergedState from 'rc-util/lib/hooks/useMergedState';
-import isEqual from 'rc-util/lib/isEqual';
-import warning from 'rc-util/lib/warning';
+import useMergedState from '@rc-component/util/lib/hooks/useMergedState';
+import isEqual from '@rc-component/util/lib/isEqual';
+import warning from '@rc-component/util/lib/warning';
import * as React from 'react';
import { useImperativeHandle } from 'react';
import { flushSync } from 'react-dom';
diff --git a/src/MenuItem.tsx b/src/MenuItem.tsx
index fb83fece..a806bdea 100644
--- a/src/MenuItem.tsx
+++ b/src/MenuItem.tsx
@@ -1,9 +1,9 @@
import classNames from 'classnames';
import Overflow from 'rc-overflow';
-import KeyCode from 'rc-util/lib/KeyCode';
-import omit from 'rc-util/lib/omit';
-import { useComposeRef } from 'rc-util/lib/ref';
-import warning from 'rc-util/lib/warning';
+import KeyCode from '@rc-component/util/lib/KeyCode';
+import omit from '@rc-component/util/lib/omit';
+import { useComposeRef } from '@rc-component/util/lib/ref';
+import warning from '@rc-component/util/lib/warning';
import * as React from 'react';
import { useMenuId } from './context/IdContext';
import { MenuContext } from './context/MenuContext';
diff --git a/src/MenuItemGroup.tsx b/src/MenuItemGroup.tsx
index c41bd7f3..dfe8b30f 100644
--- a/src/MenuItemGroup.tsx
+++ b/src/MenuItemGroup.tsx
@@ -1,5 +1,5 @@
import classNames from 'classnames';
-import omit from 'rc-util/lib/omit';
+import omit from '@rc-component/util/lib/omit';
import * as React from 'react';
import { MenuContext } from './context/MenuContext';
import { useFullPath, useMeasure } from './context/PathContext';
diff --git a/src/SubMenu/InlineSubMenuList.tsx b/src/SubMenu/InlineSubMenuList.tsx
index b5f48b8d..26de7633 100644
--- a/src/SubMenu/InlineSubMenuList.tsx
+++ b/src/SubMenu/InlineSubMenuList.tsx
@@ -1,5 +1,5 @@
import * as React from 'react';
-import CSSMotion from 'rc-motion';
+import CSSMotion from '@rc-component/motion';
import { getMotion } from '../utils/motionUtil';
import MenuContextProvider, { MenuContext } from '../context/MenuContext';
import SubMenuList from './SubMenuList';
@@ -20,13 +20,8 @@ export default function InlineSubMenuList({
}: InlineSubMenuListProps) {
const fixedMode: MenuMode = 'inline';
- const {
- prefixCls,
- forceSubMenuRender,
- motion,
- defaultMotions,
- mode,
- } = React.useContext(MenuContext);
+ const { prefixCls, forceSubMenuRender, motion, defaultMotions, mode } =
+ React.useContext(MenuContext);
// Always use latest mode check
const sameModeRef = React.useRef(false);
diff --git a/src/SubMenu/PopupTrigger.tsx b/src/SubMenu/PopupTrigger.tsx
index e915ad12..cd4f46bc 100644
--- a/src/SubMenu/PopupTrigger.tsx
+++ b/src/SubMenu/PopupTrigger.tsx
@@ -1,8 +1,8 @@
import * as React from 'react';
import Trigger from '@rc-component/trigger';
import classNames from 'classnames';
-import raf from 'rc-util/lib/raf';
-import type { CSSMotionProps } from 'rc-motion';
+import raf from '@rc-component/util/lib/raf';
+import type { CSSMotionProps } from '@rc-component/motion';
import { MenuContext } from '../context/MenuContext';
import { placements, placementsRtl } from '../placements';
import type { MenuMode } from '../interface';
diff --git a/src/SubMenu/index.tsx b/src/SubMenu/index.tsx
index 3703918d..59ace838 100644
--- a/src/SubMenu/index.tsx
+++ b/src/SubMenu/index.tsx
@@ -1,7 +1,7 @@
import * as React from 'react';
import classNames from 'classnames';
import Overflow from 'rc-overflow';
-import warning from 'rc-util/lib/warning';
+import warning from '@rc-component/util/lib/warning';
import SubMenuList from './SubMenuList';
import { parseChildren } from '../utils/commonUtil';
import type { MenuInfo, SubMenuType } from '../interface';
diff --git a/src/context/MenuContext.tsx b/src/context/MenuContext.tsx
index c34c4bdf..5327910d 100644
--- a/src/context/MenuContext.tsx
+++ b/src/context/MenuContext.tsx
@@ -1,7 +1,7 @@
import * as React from 'react';
-import type { CSSMotionProps } from 'rc-motion';
-import useMemo from 'rc-util/lib/hooks/useMemo';
-import isEqual from 'rc-util/lib/isEqual';
+import type { CSSMotionProps } from '@rc-component/motion';
+import useMemo from '@rc-component/util/lib/hooks/useMemo';
+import isEqual from '@rc-component/util/lib/isEqual';
import type {
BuiltinPlacements,
MenuClickEventHandler,
diff --git a/src/hooks/useAccessibility.ts b/src/hooks/useAccessibility.ts
index 5cd58e20..d4c18658 100644
--- a/src/hooks/useAccessibility.ts
+++ b/src/hooks/useAccessibility.ts
@@ -1,6 +1,6 @@
-import { getFocusNodeList } from 'rc-util/lib/Dom/focus';
-import KeyCode from 'rc-util/lib/KeyCode';
-import raf from 'rc-util/lib/raf';
+import { getFocusNodeList } from '@rc-component/util/lib/Dom/focus';
+import KeyCode from '@rc-component/util/lib/KeyCode';
+import raf from '@rc-component/util/lib/raf';
import * as React from 'react';
import { getMenuId } from '../context/IdContext';
import type { MenuMode } from '../interface';
@@ -15,11 +15,7 @@ function getOffset(
isRootLevel: boolean,
isRtl: boolean,
which: number,
-): {
- offset?: number;
- sibling?: boolean;
- inlineTrigger?: boolean;
-} {
+): { offset?: number; sibling?: boolean; inlineTrigger?: boolean } {
const prev = 'prev' as const;
const next = 'next' as const;
const children = 'children' as const;
@@ -27,16 +23,11 @@ function getOffset(
// Inline enter is special that we use unique operation
if (mode === 'inline' && which === ENTER) {
- return {
- inlineTrigger: true,
- };
+ return { inlineTrigger: true };
}
type OffsetMap = Record;
- const inline: OffsetMap = {
- [UP]: prev,
- [DOWN]: next,
- };
+ const inline: OffsetMap = { [UP]: prev, [DOWN]: next };
const horizontal: OffsetMap = {
[LEFT]: isRtl ? next : prev,
[RIGHT]: isRtl ? prev : next,
@@ -68,28 +59,16 @@ function getOffset(
switch (type) {
case prev:
- return {
- offset: -1,
- sibling: true,
- };
+ return { offset: -1, sibling: true };
case next:
- return {
- offset: 1,
- sibling: true,
- };
+ return { offset: 1, sibling: true };
case parent:
- return {
- offset: -1,
- sibling: false,
- };
+ return { offset: -1, sibling: false };
case children:
- return {
- offset: 1,
- sibling: false,
- };
+ return { offset: 1, sibling: false };
default:
return null;
diff --git a/src/hooks/useKeyRecords.ts b/src/hooks/useKeyRecords.ts
index c4c884e9..f9dda910 100644
--- a/src/hooks/useKeyRecords.ts
+++ b/src/hooks/useKeyRecords.ts
@@ -1,6 +1,6 @@
import * as React from 'react';
import { useRef, useCallback } from 'react';
-import warning from 'rc-util/lib/warning';
+import warning from '@rc-component/util/lib/warning';
import { nextSlice } from '../utils/timeUtil';
const PATH_SPLIT = '__RC_UTIL_PATH_SPLIT__';
diff --git a/src/hooks/useUUID.ts b/src/hooks/useUUID.ts
index cce514ee..45c8a0cd 100644
--- a/src/hooks/useUUID.ts
+++ b/src/hooks/useUUID.ts
@@ -1,14 +1,12 @@
import * as React from 'react';
-import useMergedState from 'rc-util/lib/hooks/useMergedState';
+import useMergedState from '@rc-component/util/lib/hooks/useMergedState';
const uniquePrefix = Math.random().toFixed(5).toString().slice(2);
let internalId = 0;
export default function useUUID(id?: string) {
- const [uuid, setUUID] = useMergedState(id, {
- value: id,
- });
+ const [uuid, setUUID] = useMergedState(id, { value: id });
React.useEffect(() => {
internalId += 1;
diff --git a/src/utils/commonUtil.ts b/src/utils/commonUtil.ts
index 116ffc79..99da70fa 100644
--- a/src/utils/commonUtil.ts
+++ b/src/utils/commonUtil.ts
@@ -1,33 +1,30 @@
-import toArray from "rc-util/lib/Children/toArray";
+import toArray from '@rc-component/util/lib/Children/toArray';
import * as React from 'react';
export function parseChildren(
- children: React.ReactNode | undefined,
- keyPath: string[],
- ) {
- return toArray(children).map((child, index) => {
- if (React.isValidElement(child)) {
- const { key } = child;
- let eventKey = (child.props as any)?.eventKey ?? key;
-
- const emptyKey = eventKey === null || eventKey === undefined;
-
- if (emptyKey) {
- eventKey = `tmp_key-${[...keyPath, index].join('-')}`;
- }
-
- const cloneProps = {
- key: eventKey,
- eventKey,
- } as any;
-
- if (process.env.NODE_ENV !== 'production' && emptyKey) {
- cloneProps.warnKey = true;
- }
-
- return React.cloneElement(child, cloneProps);
+ children: React.ReactNode | undefined,
+ keyPath: string[],
+) {
+ return toArray(children).map((child, index) => {
+ if (React.isValidElement(child)) {
+ const { key } = child;
+ let eventKey = (child.props as any)?.eventKey ?? key;
+
+ const emptyKey = eventKey === null || eventKey === undefined;
+
+ if (emptyKey) {
+ eventKey = `tmp_key-${[...keyPath, index].join('-')}`;
}
-
- return child;
- });
- }
\ No newline at end of file
+
+ const cloneProps = { key: eventKey, eventKey } as any;
+
+ if (process.env.NODE_ENV !== 'production' && emptyKey) {
+ cloneProps.warnKey = true;
+ }
+
+ return React.cloneElement(child, cloneProps);
+ }
+
+ return child;
+ });
+}
diff --git a/src/utils/motionUtil.ts b/src/utils/motionUtil.ts
index 09042d07..c09e8f34 100644
--- a/src/utils/motionUtil.ts
+++ b/src/utils/motionUtil.ts
@@ -1,4 +1,4 @@
-import type { CSSMotionProps } from 'rc-motion';
+import type { CSSMotionProps } from '@rc-component/motion';
export function getMotion(
mode: string,
diff --git a/src/utils/warnUtil.ts b/src/utils/warnUtil.ts
index afd5c3cf..5cf99b36 100644
--- a/src/utils/warnUtil.ts
+++ b/src/utils/warnUtil.ts
@@ -1,4 +1,4 @@
-import warning from 'rc-util/lib/warning';
+import warning from '@rc-component/util/lib/warning';
/**
* `onClick` event return `info.item` which point to react node directly.
diff --git a/tests/Focus.spec.tsx b/tests/Focus.spec.tsx
index 5457895f..0b299e75 100644
--- a/tests/Focus.spec.tsx
+++ b/tests/Focus.spec.tsx
@@ -1,6 +1,6 @@
/* eslint-disable no-undef */
import { act, fireEvent, render } from '@testing-library/react';
-import { spyElementPrototypes } from 'rc-util/lib/test/domHook';
+import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook';
import React from 'react';
import Menu, { MenuItem, MenuItemGroup, MenuRef, SubMenu } from '../src';
diff --git a/tests/Keyboard.spec.tsx b/tests/Keyboard.spec.tsx
index 73544b0f..68a4a372 100644
--- a/tests/Keyboard.spec.tsx
+++ b/tests/Keyboard.spec.tsx
@@ -1,7 +1,7 @@
/* eslint-disable no-undef, react/no-multi-comp, react/jsx-curly-brace-presence, max-classes-per-file */
import { fireEvent, render } from '@testing-library/react';
-import KeyCode from 'rc-util/lib/KeyCode';
-import { spyElementPrototypes } from 'rc-util/lib/test/domHook';
+import KeyCode from '@rc-component/util/lib/KeyCode';
+import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook';
import React from 'react';
import { act } from 'react-dom/test-utils';
import Menu, { MenuItem, SubMenu } from '../src';
diff --git a/tests/Menu.spec.tsx b/tests/Menu.spec.tsx
index fc7326ef..f0ee8c99 100644
--- a/tests/Menu.spec.tsx
+++ b/tests/Menu.spec.tsx
@@ -1,8 +1,8 @@
/* eslint-disable no-undef, react/no-multi-comp, react/jsx-curly-brace-presence, max-classes-per-file */
import type { MenuMode } from '@/interface';
import { fireEvent, render } from '@testing-library/react';
-import KeyCode from 'rc-util/lib/KeyCode';
-import { resetWarned } from 'rc-util/lib/warning';
+import KeyCode from '@rc-component/util/lib/KeyCode';
+import { resetWarned } from '@rc-component/util/lib/warning';
import React from 'react';
import { act } from 'react-dom/test-utils';
import type { MenuRef } from '../src';
@@ -20,9 +20,9 @@ jest.mock('@rc-component/trigger', () => {
});
});
-jest.mock('rc-motion', () => {
+jest.mock('@rc-component/motion', () => {
const react = require('react');
- let Motion = jest.requireActual('rc-motion');
+ let Motion = jest.requireActual('@rc-component/motion');
Motion = Motion.default || Motion;
return react.forwardRef((props, ref) => {
@@ -333,7 +333,7 @@ describe('Menu', () => {
// don't use selectedKeys as string
// it is a compatible feature for https://github.com/ant-design/ant-design/issues/29429
const { container } = render(
-