From 0f1fcadf6e6dec77f9f9bf0f2d79292b30c2c5b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E8=89=B3=E5=85=B5?= Date: Fri, 22 May 2026 08:54:49 +0800 Subject: [PATCH] fix: avoid rc package deep imports --- package.json | 4 ++-- src/Drawer.tsx | 2 +- src/DrawerPanel.tsx | 3 +-- src/DrawerPopup.tsx | 3 +-- src/hooks/useFocusable.ts | 2 +- src/index.ts | 3 ++- src/util.ts | 3 +-- tests/focus.spec.tsx | 4 ++-- tests/index.spec.tsx | 2 +- typings/custom.d.ts | 15 --------------- 10 files changed, 12 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index 078865a7..332ac61b 100644 --- a/package.json +++ b/package.json @@ -45,12 +45,12 @@ "dependencies": { "@rc-component/motion": "^1.1.4", "@rc-component/portal": "^2.1.3", - "@rc-component/util": "^1.9.0", + "@rc-component/util": "^1.11.1", "clsx": "^2.1.1" }, "devDependencies": { "@ant-design/icons": "^5.3.0", - "@rc-component/father-plugin": "^2.0.2", + "@rc-component/father-plugin": "^2.2.0", "@rc-component/np": "^1.0.0", "@testing-library/jest-dom": "^6.2.0", "@testing-library/react": "^16.3.0", diff --git a/src/Drawer.tsx b/src/Drawer.tsx index afdd3035..47155982 100644 --- a/src/Drawer.tsx +++ b/src/Drawer.tsx @@ -1,6 +1,6 @@ import type { PortalProps } from '@rc-component/portal'; import Portal from '@rc-component/portal'; -import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect'; +import { useLayoutEffect } from '@rc-component/util'; import * as React from 'react'; import { RefContext } from './context'; import type { diff --git a/src/DrawerPanel.tsx b/src/DrawerPanel.tsx index 90662815..310fa37f 100644 --- a/src/DrawerPanel.tsx +++ b/src/DrawerPanel.tsx @@ -1,8 +1,7 @@ import { clsx } from 'clsx'; import * as React from 'react'; import { RefContext } from './context'; -import pickAttrs from '@rc-component/util/lib/pickAttrs'; -import { useComposeRef } from '@rc-component/util/lib/ref'; +import { pickAttrs, useComposeRef } from '@rc-component/util'; export interface DrawerPanelRef { focus: VoidFunction; diff --git a/src/DrawerPopup.tsx b/src/DrawerPopup.tsx index eeb39e57..01beea4f 100644 --- a/src/DrawerPopup.tsx +++ b/src/DrawerPopup.tsx @@ -1,7 +1,7 @@ import { clsx } from 'clsx'; import type { CSSMotionProps } from '@rc-component/motion'; import CSSMotion from '@rc-component/motion'; -import pickAttrs from '@rc-component/util/lib/pickAttrs'; +import { pickAttrs, useEvent } from '@rc-component/util'; import * as React from 'react'; import type { DrawerContextProps } from './context'; import DrawerContext from './context'; @@ -13,7 +13,6 @@ import DrawerPanel from './DrawerPanel'; import useDrag from './hooks/useDrag'; import { parseWidthHeight } from './util'; import type { DrawerClassNames, DrawerStyles } from './inter'; -import { useEvent } from '@rc-component/util'; import useFocusable from './hooks/useFocusable'; export type Placement = 'left' | 'right' | 'top' | 'bottom'; diff --git a/src/hooks/useFocusable.ts b/src/hooks/useFocusable.ts index 9a4b8d8e..cd38d9aa 100644 --- a/src/hooks/useFocusable.ts +++ b/src/hooks/useFocusable.ts @@ -1,5 +1,5 @@ import React from 'react'; -import { useLockFocus } from '@rc-component/util/lib/Dom/focus'; +import { useLockFocus } from '@rc-component/util'; export default function useFocusable( getContainer: () => HTMLElement, diff --git a/src/index.ts b/src/index.ts index ae3d3a68..3384ca5e 100755 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,8 @@ // export this package's api import Drawer from './Drawer'; import type { DrawerProps, Placement } from './Drawer'; +import type { DrawerPopupProps } from './DrawerPopup'; -export type { DrawerProps, Placement }; +export type { DrawerProps, DrawerPopupProps, Placement }; export default Drawer; diff --git a/src/util.ts b/src/util.ts index dbfdce1e..862e83c1 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,5 +1,4 @@ -import warning from '@rc-component/util/lib/warning'; -import canUseDom from '@rc-component/util/lib/Dom/canUseDom'; +import { canUseDom, warning } from '@rc-component/util'; import type { DrawerProps } from './Drawer'; export function parseWidthHeight(value?: number | string) { diff --git a/tests/focus.spec.tsx b/tests/focus.spec.tsx index 0847e85f..a7259d71 100644 --- a/tests/focus.spec.tsx +++ b/tests/focus.spec.tsx @@ -4,8 +4,8 @@ import ReactDOM from 'react-dom'; import Drawer from '../src'; // Mock useLockFocus to track calls -jest.mock('@rc-component/util/lib/Dom/focus', () => { - const actual = jest.requireActual('@rc-component/util/lib/Dom/focus'); +jest.mock('@rc-component/util', () => { + const actual = jest.requireActual('@rc-component/util'); const useLockFocus = (visible: boolean, ...rest: any[]) => { (globalThis as any).__useLockFocusVisible = visible; diff --git a/tests/index.spec.tsx b/tests/index.spec.tsx index 1725495e..026e3e66 100755 --- a/tests/index.spec.tsx +++ b/tests/index.spec.tsx @@ -1,5 +1,5 @@ import { cleanup, fireEvent, render, act } from '@testing-library/react'; -import { resetWarned } from '@rc-component/util/lib/warning'; +import { resetWarned } from '@rc-component/util'; import React from 'react'; import type { DrawerProps } from '../src'; import Drawer from '../src'; diff --git a/typings/custom.d.ts b/typings/custom.d.ts index 5a5dd686..283e577a 100644 --- a/typings/custom.d.ts +++ b/typings/custom.d.ts @@ -1,16 +1 @@ -declare module '@rc-component/util/lib/KeyCode' { - const Ret: { ESC: any; TAB: any }; - export default Ret; -} - -declare module '@rc-component/util/lib/getScrollBarSize' { - const Ret: (b: boolean) => number; - export default Ret; -} - -declare module '@rc-component/util/lib/*' { - const Ret: any; - export default Ret; -} - declare module 'raf';