From 627fa3b8ff2f71748f8be4b263315157284eae5b 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 12:21:49 +0800 Subject: [PATCH] fix: avoid rc package deep imports --- package.json | 6 +++--- src/BaseSelect/index.tsx | 7 +++---- src/OptionList.tsx | 9 ++------- src/Select.tsx | 4 +--- src/SelectInput/Content/index.tsx | 2 +- src/SelectInput/Input.tsx | 3 +-- src/SelectInput/index.tsx | 6 +----- src/SelectTrigger.tsx | 7 +++++-- src/index.ts | 29 ++++++++++++++++++++++++++--- src/utils/keyUtil.ts | 2 +- src/utils/legacyUtil.ts | 2 +- src/utils/valueUtil.ts | 2 +- src/utils/warningPropsUtil.ts | 3 +-- tests/Accessibility.test.tsx | 2 +- tests/Combobox.test.tsx | 3 +-- tests/Multiple.test.tsx | 2 +- tests/OptionList.test.tsx | 3 +-- tests/Select.test.tsx | 6 ++---- tests/Tags.test.tsx | 2 +- tests/shared/focusTest.tsx | 2 +- tests/shared/removeSelectedTest.tsx | 2 +- tests/shared/throwOptionValue.tsx | 2 +- typings/index.d.ts | 2 -- 23 files changed, 57 insertions(+), 51 deletions(-) diff --git a/package.json b/package.json index 60612fdfc..f64f85095 100644 --- a/package.json +++ b/package.json @@ -51,12 +51,12 @@ "dependencies": { "@rc-component/overflow": "^1.0.0", "@rc-component/trigger": "^3.0.0", - "@rc-component/util": "^1.3.0", - "@rc-component/virtual-list": "^1.0.1", + "@rc-component/util": "^1.11.1", + "@rc-component/virtual-list": "^1.2.0", "clsx": "^2.1.1" }, "devDependencies": { - "@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.4.5", "@testing-library/react": "^15.0.6", diff --git a/src/BaseSelect/index.tsx b/src/BaseSelect/index.tsx index 534143f8b..7e6f1ac82 100644 --- a/src/BaseSelect/index.tsx +++ b/src/BaseSelect/index.tsx @@ -1,7 +1,7 @@ -import type { AlignType, BuildInPlacements } from '@rc-component/trigger/lib/interface'; +import type { AlignType, BuildInPlacements } from '@rc-component/trigger'; import { clsx } from 'clsx'; -import { getDOM } from '@rc-component/util/lib/Dom/findDOMNode'; -import type { ScrollConfig, ScrollTo } from '@rc-component/virtual-list/lib/List'; +import { getDOM, useEvent } from '@rc-component/util'; +import type { ScrollConfig, ScrollTo } from '@rc-component/virtual-list'; import * as React from 'react'; import { useAllowClear } from '../hooks/useAllowClear'; import { BaseSelectContext } from '../hooks/useBaseProps'; @@ -22,7 +22,6 @@ import SelectTrigger from '../SelectTrigger'; import { getSeparatedContent, isValidCount } from '../utils/valueUtil'; import Polite from './Polite'; import useOpen, { macroTask } from '../hooks/useOpen'; -import { useEvent } from '@rc-component/util'; import type { SelectInputRef } from '../SelectInput'; import SelectInput from '../SelectInput'; import type { ComponentsConfig } from '../hooks/useComponents'; diff --git a/src/OptionList.tsx b/src/OptionList.tsx index f0245077b..21e693083 100644 --- a/src/OptionList.tsx +++ b/src/OptionList.tsx @@ -1,11 +1,6 @@ import { clsx } from 'clsx'; -import KeyCode from '@rc-component/util/lib/KeyCode'; -import useMemo from '@rc-component/util/lib/hooks/useMemo'; -import omit from '@rc-component/util/lib/omit'; -import pickAttrs from '@rc-component/util/lib/pickAttrs'; -import type { ListRef } from '@rc-component/virtual-list'; -import List from '@rc-component/virtual-list'; -import type { ScrollConfig } from '@rc-component/virtual-list/lib/List'; +import { KeyCode, omit, pickAttrs, useMemo } from '@rc-component/util'; +import List, { type ListRef, type ScrollConfig } from '@rc-component/virtual-list'; import * as React from 'react'; import { useEffect } from 'react'; import type { BaseOptionType, RawValueType } from './Select'; diff --git a/src/Select.tsx b/src/Select.tsx index 26fbbd000..e8c6d5ccb 100644 --- a/src/Select.tsx +++ b/src/Select.tsx @@ -29,8 +29,7 @@ * - `combobox` mode not support `optionLabelProp` */ -import useControlledState from '@rc-component/util/lib/hooks/useControlledState'; -import warning from '@rc-component/util/lib/warning'; +import { useControlledState, useId, warning } from '@rc-component/util'; import * as React from 'react'; import type { BaseSelectProps, @@ -49,7 +48,6 @@ import SelectContext from './SelectContext'; import type { SelectContextProps } from './SelectContext'; import useCache from './hooks/useCache'; import useFilterOptions from './hooks/useFilterOptions'; -import useId from '@rc-component/util/lib/hooks/useId'; import useOptions from './hooks/useOptions'; import useRefFunc from './hooks/useRefFunc'; import type { FlattenOptionData } from './interface'; diff --git a/src/SelectInput/Content/index.tsx b/src/SelectInput/Content/index.tsx index fc56d19a5..a9423dd04 100644 --- a/src/SelectInput/Content/index.tsx +++ b/src/SelectInput/Content/index.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import pickAttrs from '@rc-component/util/lib/pickAttrs'; +import { pickAttrs } from '@rc-component/util'; import SingleContent from './SingleContent'; import MultipleContent from './MultipleContent'; import { useSelectInputContext } from '../context'; diff --git a/src/SelectInput/Input.tsx b/src/SelectInput/Input.tsx index 8c12606ac..6ab1383dd 100644 --- a/src/SelectInput/Input.tsx +++ b/src/SelectInput/Input.tsx @@ -1,9 +1,8 @@ import * as React from 'react'; import { clsx } from 'clsx'; import { useSelectInputContext } from './context'; -import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect'; +import { composeRef, useLayoutEffect } from '@rc-component/util'; import useBaseProps from '../hooks/useBaseProps'; -import { composeRef } from '@rc-component/util/lib/ref'; export interface InputProps { id?: string; diff --git a/src/SelectInput/index.tsx b/src/SelectInput/index.tsx index a0bcee14e..70f0d3490 100644 --- a/src/SelectInput/index.tsx +++ b/src/SelectInput/index.tsx @@ -4,14 +4,10 @@ import SelectContent from './Content'; import SelectInputContext from './context'; import type { DisplayValueType, Mode, RenderNode } from '../interface'; import useBaseProps from '../hooks/useBaseProps'; -import { omit, useEvent } from '@rc-component/util'; -import KeyCode from '@rc-component/util/lib/KeyCode'; +import { composeRef, getDOM, KeyCode, omit, pickAttrs, useEvent } from '@rc-component/util'; import { isValidateOpenKey } from '../utils/keyUtil'; import { clsx } from 'clsx'; import type { ComponentsConfig } from '../hooks/useComponents'; -import { getDOM } from '@rc-component/util/lib/Dom/findDOMNode'; -import { composeRef } from '@rc-component/util/lib/ref'; -import pickAttrs from '@rc-component/util/lib/pickAttrs'; export interface SelectInputRef { focus: (options?: FocusOptions) => void; diff --git a/src/SelectTrigger.tsx b/src/SelectTrigger.tsx index bbf719fa7..c9ca542d6 100644 --- a/src/SelectTrigger.tsx +++ b/src/SelectTrigger.tsx @@ -1,5 +1,8 @@ -import Trigger, { type TriggerRef } from '@rc-component/trigger'; -import type { AlignType, BuildInPlacements } from '@rc-component/trigger/lib/interface'; +import Trigger, { + type AlignType, + type BuildInPlacements, + type TriggerRef, +} from '@rc-component/trigger'; import { clsx } from 'clsx'; import * as React from 'react'; import type { Placement, RenderDOMFunc } from './BaseSelect'; diff --git a/src/index.ts b/src/index.ts index 9f0885d47..0fc8d4b7e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,35 @@ import Select from './Select'; import Option from './Option'; import OptGroup from './OptGroup'; -import type { SelectProps } from './Select'; +import type { BaseOptionType, DefaultOptionType, SearchConfig, SelectProps } from './Select'; import BaseSelect from './BaseSelect'; -import type { BaseSelectProps, BaseSelectRef, BaseSelectPropsWithoutPrivate } from './BaseSelect'; +import type { + BaseSelectProps, + BaseSelectPropsWithoutPrivate, + BaseSelectRef, + BaseSelectSemanticName, + DisplayValueType, + RefOptionListProps, +} from './BaseSelect'; import useBaseProps from './hooks/useBaseProps'; +import type { OptionFC, OptionProps } from './Option'; +import type { Placement } from './interface'; export { Option, OptGroup, BaseSelect, useBaseProps }; -export type { SelectProps, BaseSelectProps, BaseSelectRef, BaseSelectPropsWithoutPrivate }; +export type { + BaseOptionType, + BaseSelectProps, + BaseSelectPropsWithoutPrivate, + BaseSelectRef, + BaseSelectSemanticName, + DefaultOptionType, + DisplayValueType, + OptionFC, + OptionProps, + Placement, + RefOptionListProps, + SearchConfig, + SelectProps, +}; export default Select; diff --git a/src/utils/keyUtil.ts b/src/utils/keyUtil.ts index 6d1e68b59..e63253744 100644 --- a/src/utils/keyUtil.ts +++ b/src/utils/keyUtil.ts @@ -1,4 +1,4 @@ -import KeyCode from '@rc-component/util/lib/KeyCode'; +import { KeyCode } from '@rc-component/util'; /** keyCode Judgment function */ export function isValidateOpenKey(currentKeyCode: number): boolean { diff --git a/src/utils/legacyUtil.ts b/src/utils/legacyUtil.ts index 96a40b642..3e9a449ad 100644 --- a/src/utils/legacyUtil.ts +++ b/src/utils/legacyUtil.ts @@ -1,5 +1,5 @@ import * as React from 'react'; -import toArray from '@rc-component/util/lib/Children/toArray'; +import { toArray } from '@rc-component/util'; import type { BaseOptionType, DefaultOptionType } from '../Select'; function convertNodeToOption( diff --git a/src/utils/valueUtil.ts b/src/utils/valueUtil.ts index 0350e4803..f69b7e718 100644 --- a/src/utils/valueUtil.ts +++ b/src/utils/valueUtil.ts @@ -1,5 +1,5 @@ import type { BaseOptionType, DefaultOptionType } from '../Select'; -import warning from '@rc-component/util/lib/warning'; +import { warning } from '@rc-component/util'; import type { RawValueType, FieldNames } from '../Select'; import type { FlattenOptionData } from '../interface'; diff --git a/src/utils/warningPropsUtil.ts b/src/utils/warningPropsUtil.ts index 74f228e0d..c55608947 100644 --- a/src/utils/warningPropsUtil.ts +++ b/src/utils/warningPropsUtil.ts @@ -1,5 +1,4 @@ -import toNodeArray from '@rc-component/util/lib/Children/toArray'; -import warning, { noteOnce } from '@rc-component/util/lib/warning'; +import { noteOnce, toArray as toNodeArray, warning as warning } from '@rc-component/util'; import * as React from 'react'; import { isMultiple } from '../BaseSelect'; import type { diff --git a/tests/Accessibility.test.tsx b/tests/Accessibility.test.tsx index 978ddd9d6..3688c96c3 100644 --- a/tests/Accessibility.test.tsx +++ b/tests/Accessibility.test.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import KeyCode from '@rc-component/util/lib/KeyCode'; +import { KeyCode } from '@rc-component/util'; import Select from '../src'; import { injectRunAllTimers, expectOpen, keyDown } from './utils/common'; import { act, fireEvent, render } from '@testing-library/react'; diff --git a/tests/Combobox.test.tsx b/tests/Combobox.test.tsx index 35a8b64a5..9b93fafce 100644 --- a/tests/Combobox.test.tsx +++ b/tests/Combobox.test.tsx @@ -2,8 +2,7 @@ import '@testing-library/jest-dom'; import { createEvent, fireEvent, render } from '@testing-library/react'; -import KeyCode from '@rc-component/util/lib/KeyCode'; -import { resetWarned } from '@rc-component/util/lib/warning'; +import { KeyCode, resetWarned } from '@rc-component/util'; import React, { act } from 'react'; import type { SelectProps } from '../src'; import Select, { Option } from '../src'; diff --git a/tests/Multiple.test.tsx b/tests/Multiple.test.tsx index d5aa0f5e0..e1da7151d 100644 --- a/tests/Multiple.test.tsx +++ b/tests/Multiple.test.tsx @@ -1,4 +1,4 @@ -import KeyCode from '@rc-component/util/lib/KeyCode'; +import { KeyCode } from '@rc-component/util'; import React from 'react'; import Select, { Option, OptGroup } from '../src'; import focusTest from './shared/focusTest'; diff --git a/tests/OptionList.test.tsx b/tests/OptionList.test.tsx index 8ff40d1c3..745ca8720 100644 --- a/tests/OptionList.test.tsx +++ b/tests/OptionList.test.tsx @@ -1,4 +1,4 @@ -import KeyCode from '@rc-component/util/lib/KeyCode'; +import { KeyCode, spyElementPrototypes } from '@rc-component/util'; import React, { act } from 'react'; import { BaseSelectContext } from '../src/hooks/useBaseProps'; import type { RefOptionListProps } from '../src/OptionList'; @@ -8,7 +8,6 @@ import { fillFieldNames, flattenOptions } from '../src/utils/valueUtil'; import { injectRunAllTimers } from './utils/common'; import { createEvent, fireEvent, render, waitFor } from '@testing-library/react'; import Select from '../src'; -import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook'; jest.mock('../src/utils/platformUtil'); diff --git a/tests/Select.test.tsx b/tests/Select.test.tsx index 3cdf61287..4e96d4606 100644 --- a/tests/Select.test.tsx +++ b/tests/Select.test.tsx @@ -6,10 +6,8 @@ import { render as testingRender, act, } from '@testing-library/react'; -import KeyCode from '@rc-component/util/lib/KeyCode'; -import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook'; -import { resetWarned } from '@rc-component/util/lib/warning'; -import type { ScrollConfig } from '@rc-component/virtual-list/lib/List'; +import { KeyCode, resetWarned, spyElementPrototypes } from '@rc-component/util'; +import type { ScrollConfig } from '@rc-component/virtual-list'; import React, { StrictMode } from 'react'; import type { SelectProps } from '../src'; import Select, { OptGroup, Option, useBaseProps } from '../src'; diff --git a/tests/Tags.test.tsx b/tests/Tags.test.tsx index 4c9db925c..cfee62b39 100644 --- a/tests/Tags.test.tsx +++ b/tests/Tags.test.tsx @@ -1,5 +1,5 @@ import { createEvent, fireEvent, render } from '@testing-library/react'; -import KeyCode from '@rc-component/util/lib/KeyCode'; +import { KeyCode } from '@rc-component/util'; import { clsx } from 'clsx'; import * as React from 'react'; import Select, { BaseSelect, OptGroup, Option } from '../src'; diff --git a/tests/shared/focusTest.tsx b/tests/shared/focusTest.tsx index 231ffad12..a61dfcd38 100644 --- a/tests/shared/focusTest.tsx +++ b/tests/shared/focusTest.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { resetWarned } from '@rc-component/util/lib/warning'; +import { resetWarned } from '@rc-component/util'; import Option from '../../src/Option'; import Select from '../../src/Select'; import { render } from '@testing-library/react'; diff --git a/tests/shared/removeSelectedTest.tsx b/tests/shared/removeSelectedTest.tsx index fe4737e0f..7bb28ed7d 100644 --- a/tests/shared/removeSelectedTest.tsx +++ b/tests/shared/removeSelectedTest.tsx @@ -1,4 +1,4 @@ -import KeyCode from '@rc-component/util/lib/KeyCode'; +import { KeyCode } from '@rc-component/util'; import React from 'react'; import Select, { Option } from '../../src'; import { removeSelection, toggleOpen, selectItem, keyDown } from '../utils/common'; diff --git a/tests/shared/throwOptionValue.tsx b/tests/shared/throwOptionValue.tsx index 45a44a1f0..fc5c12577 100644 --- a/tests/shared/throwOptionValue.tsx +++ b/tests/shared/throwOptionValue.tsx @@ -1,6 +1,6 @@ import React from 'react'; import Select, { Option } from '../../src'; -import { resetWarned } from '@rc-component/util/lib/warning'; +import { resetWarned } from '@rc-component/util'; import { render } from '@testing-library/react'; export default function throwOptionValue(mode: any) { diff --git a/typings/index.d.ts b/typings/index.d.ts index 485b6881d..772aeef58 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -4,6 +4,4 @@ declare module 'component-classes'; declare module 'rc-menu'; -declare module '@rc-component/util/lib/Children/toArray'; - declare module 'dom-scroll-into-view';