Skip to content

Commit f1d2034

Browse files
authored
fix: avoid rc package deep imports (#656)
1 parent 34b4676 commit f1d2034

27 files changed

Lines changed: 690 additions & 628 deletions

jest.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
module.exports = {
22
setupFiles: ['./tests/setup.js'],
3-
snapshotSerializers: [require.resolve('enzyme-to-json/serializer')],
4-
};
3+
};

package.json

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,27 @@
4343
"*": "prettier --write --ignore-unknown"
4444
},
4545
"dependencies": {
46-
"@rc-component/select": "~1.7.0",
47-
"@rc-component/tree": "~1.3.0",
48-
"@rc-component/util": "^1.4.0",
46+
"@rc-component/select": "~1.7.1",
47+
"@rc-component/tree": "~1.3.2",
48+
"@rc-component/util": "^1.11.1",
4949
"clsx": "^2.1.1"
5050
},
5151
"devDependencies": {
5252
"@rc-component/dialog": "^1.2.0",
53-
"@rc-component/father-plugin": "^2.0.2",
53+
"@rc-component/father-plugin": "^2.2.0",
5454
"@rc-component/form": "^1.4.0",
5555
"@rc-component/np": "^1.0.3",
5656
"@rc-component/trigger": "^3.0.0",
5757
"@rc-component/virtual-list": "^1.0.1",
58-
"@testing-library/react": "^12.1.5",
58+
"@testing-library/react": "^16.0.0",
5959
"@types/jest": "^29.5.13",
6060
"@types/node": "^22.7.5",
6161
"@types/react": "^18.3.11",
62-
"@types/react-dom": "^19.0.1",
62+
"@types/react-dom": "^18.0.0",
6363
"@types/warning": "^3.0.3",
6464
"@umijs/fabric": "^4.0.1",
65-
"cheerio": "1.0.0-rc.12",
6665
"cross-env": "^7.0.3",
6766
"dumi": "^2.4.12",
68-
"enzyme": "^3.11.0",
69-
"enzyme-adapter-react-16": "^1.15.8",
70-
"enzyme-to-json": "^3.6.2",
7167
"eslint": "^8.57.1",
7268
"eslint-plugin-jest": "^28.10.0",
7369
"eslint-plugin-unicorn": "^56.0.0",
@@ -77,8 +73,8 @@
7773
"lint-staged": "^15.2.10",
7874
"prettier": "^3.3.3",
7975
"rc-test": "^7.1.1",
80-
"react": "^16.0.0",
81-
"react-dom": "^16.0.0",
76+
"react": "^18.0.0",
77+
"react-dom": "^18.0.0",
8278
"typescript": "^5.6.3"
8379
},
8480
"peerDependencies": {

src/LegacyContext.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
2-
import type { DataEntity, IconType } from '@rc-component/tree/lib/interface';
3-
import type { LegacyDataNode, SafeKey, Key } from './interface';
2+
import type { LegacyDataNode, SafeKey, Key, IconType } from './interface';
3+
import type { DataEntity } from './hooks/useDataEntities';
44

55
interface LegacyContextProps {
66
checkable: boolean | React.ReactNode;
@@ -20,7 +20,7 @@ interface LegacyContextProps {
2020
loadData: (treeNode: LegacyDataNode) => Promise<unknown>;
2121
onTreeLoad: (loadedKeys: Key[]) => void;
2222

23-
keyEntities: Record<SafeKey, DataEntity<any>>;
23+
keyEntities: Record<SafeKey, DataEntity>;
2424
}
2525

2626
const LegacySelectContext = React.createContext<LegacyContextProps>(null);

src/OptionList.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import { useBaseProps } from '@rc-component/select';
2-
import type { RefOptionListProps } from '@rc-component/select/lib/OptionList';
32
import type { TreeProps } from '@rc-component/tree';
43
import Tree from '@rc-component/tree';
54
import { UnstableContext } from '@rc-component/tree';
6-
import type { EventDataNode, ScrollTo } from '@rc-component/tree/lib/interface';
7-
import KeyCode from '@rc-component/util/lib/KeyCode';
8-
import useMemo from '@rc-component/util/lib/hooks/useMemo';
5+
import type { EventDataNode } from '@rc-component/tree';
6+
import { KeyCode, useEvent, useMemo } from '@rc-component/util';
97
import * as React from 'react';
108
import LegacyContext from './LegacyContext';
119
import TreeSelectContext from './TreeSelectContext';
1210
import type { DataNode, Key, SafeKey } from './interface';
1311
import { getAllKeys, isCheckDisabled } from './utils/valueUtil';
14-
import { useEvent } from '@rc-component/util';
1512

1613
const HIDDEN_STYLE = {
1714
width: 0,
@@ -30,6 +27,14 @@ interface TreeEventInfo {
3027
checked?: boolean;
3128
}
3229

30+
interface RefOptionListProps {
31+
onKeyDown: React.KeyboardEventHandler;
32+
onKeyUp: React.KeyboardEventHandler;
33+
scrollTo?: (args: unknown) => void;
34+
}
35+
36+
type ScrollTo = NonNullable<React.ComponentRef<typeof Tree>['scrollTo']>;
37+
3338
type ReviseRefOptionListProps = Omit<RefOptionListProps, 'scrollTo'> & { scrollTo: ScrollTo };
3439

3540
const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_, ref) => {

src/TreeSelect.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import type { BaseSelectPropsWithoutPrivate, BaseSelectRef } from '@rc-component/select';
2-
import type { BaseSelectSemanticName } from '@rc-component/select/lib/BaseSelect';
32
import { BaseSelect } from '@rc-component/select';
4-
import useId from '@rc-component/util/lib/hooks/useId';
5-
import type { IconType } from '@rc-component/tree/lib/interface';
6-
import type { ExpandAction } from '@rc-component/tree/lib/Tree';
7-
import { conductCheck } from '@rc-component/tree/lib/utils/conductUtil';
8-
import useControlledState from '@rc-component/util/lib/hooks/useControlledState';
3+
import { conductCheck } from '@rc-component/tree';
4+
import { useControlledState, useId } from '@rc-component/util';
95
import * as React from 'react';
106
import useCache from './hooks/useCache';
117
import useCheckedKeys from './hooks/useCheckedKeys';
@@ -28,6 +24,8 @@ import type {
2824
SafeKey,
2925
Key,
3026
DataNode,
27+
ExpandAction,
28+
IconType,
3129
SimpleModeConfig,
3230
ChangeEventExtra,
3331
SelectSource,
@@ -37,7 +35,7 @@ import type {
3735
} from './interface';
3836
import useSearchConfig from './hooks/useSearchConfig';
3937

40-
export type SemanticName = BaseSelectSemanticName;
38+
export type SemanticName = keyof NonNullable<BaseSelectPropsWithoutPrivate['classNames']>;
4139
export type PopupSemantic = 'item' | 'itemTitle';
4240
export interface SearchConfig {
4341
searchValue?: string;
@@ -46,8 +44,10 @@ export interface SearchConfig {
4644
filterTreeNode?: boolean | ((inputValue: string, treeNode: DataNode) => boolean);
4745
treeNodeFilterProp?: string;
4846
}
49-
export interface TreeSelectProps<ValueType = any, OptionType extends DataNode = DataNode>
50-
extends Omit<BaseSelectPropsWithoutPrivate, 'mode' | 'classNames' | 'styles' | 'showSearch'> {
47+
export interface TreeSelectProps<
48+
ValueType = any,
49+
OptionType extends DataNode = DataNode,
50+
> extends Omit<BaseSelectPropsWithoutPrivate, 'mode' | 'classNames' | 'styles' | 'showSearch'> {
5151
prefixCls?: string;
5252
id?: string;
5353
children?: React.ReactNode;

src/TreeSelectContext.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import * as React from 'react';
2-
import type { ExpandAction } from '@rc-component/tree/lib/Tree';
3-
import type { DataNode, FieldNames, Key } from './interface';
2+
import type { DataNode, FieldNames, Key, ExpandAction } from './interface';
43
import type useDataEntities from './hooks/useDataEntities';
5-
import { TreeSelectProps } from './TreeSelect';
4+
import type { TreeSelectProps } from './TreeSelect';
65

76
export interface TreeSelectContextProps {
87
virtual?: boolean;

src/hooks/useCheckedKeys.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
2-
import type { DataEntity } from '@rc-component/tree/lib/interface';
3-
import { conductCheck } from '@rc-component/tree/lib/utils/conductUtil';
2+
import { conductCheck } from '@rc-component/tree';
43
import type { LabeledValueType, SafeKey, Key } from '../interface';
4+
import type { DataEntity } from './useDataEntities';
55

66
const useCheckedKeys = (
77
rawLabeledValues: LabeledValueType[],

src/hooks/useDataEntities.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import * as React from 'react';
2-
import { convertDataToEntities } from '@rc-component/tree/lib/utils/treeUtil';
3-
import type { DataEntity } from '@rc-component/tree/lib/interface';
2+
import { convertDataToEntities } from '@rc-component/tree';
43
import type { SafeKey, FieldNames } from '../interface';
5-
import warning from '@rc-component/util/lib/warning';
4+
import { warning } from '@rc-component/util';
65
import { isNil } from '../utils/valueUtil';
76

7+
export type DataEntity = ReturnType<typeof convertDataToEntities>['keyEntities'][string];
8+
89
export default (treeData: any, fieldNames: FieldNames) =>
910
React.useMemo<{
1011
valueEntities: Map<SafeKey, DataEntity>;

src/interface.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import type * as React from 'react';
2-
import type { SafeKey, Key, DataNode as TreeDataNode } from '@rc-component/tree/lib/interface';
2+
import type { DataNode as TreeDataNode, TreeProps } from '@rc-component/tree';
33

4-
export type { SafeKey, Key };
4+
export type Key = React.Key;
5+
6+
export type SafeKey = Exclude<Key, bigint>;
7+
8+
export type ExpandAction = TreeProps['expandAction'];
9+
10+
export type IconType = TreeProps['icon'];
511

612
export interface DataNode extends Record<string, any>, Omit<TreeDataNode, 'key' | 'children'> {
713
key?: Key;

src/utils/legacyUtil.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as React from 'react';
2-
import toArray from '@rc-component/util/lib/Children/toArray';
3-
import warning from '@rc-component/util/lib/warning';
2+
import { toArray, warning } from '@rc-component/util';
43
import type {
54
DataNode,
65
ChangeEventExtra,

0 commit comments

Comments
 (0)