Skip to content

Commit 0cbe659

Browse files
committed
fix: avoid rc package deep imports
1 parent 59b659d commit 0cbe659

21 files changed

Lines changed: 78 additions & 75 deletions

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@
4444
"@rc-component/motion": "^1.1.4",
4545
"@rc-component/portal": "^2.2.0",
4646
"@rc-component/resize-observer": "^1.1.1",
47-
"@rc-component/util": "^1.2.1",
47+
"@rc-component/util": "^1.11.1",
4848
"clsx": "^2.1.1"
4949
},
5050
"devDependencies": {
51-
"@rc-component/father-plugin": "^2.0.0",
51+
"@rc-component/father-plugin": "^2.2.0",
5252
"@rc-component/np": "^1.0.3",
5353
"@testing-library/jest-dom": "^6.1.4",
5454
"@testing-library/react": "^16.0.0",

src/Popup/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ import CSSMotion from '@rc-component/motion';
44
import ResizeObserver, {
55
type ResizeObserverProps,
66
} from '@rc-component/resize-observer';
7-
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
8-
import { composeRef } from '@rc-component/util/lib/ref';
7+
import { composeRef, useEvent, useLayoutEffect } from '@rc-component/util';
98
import * as React from 'react';
109
import type { TriggerProps } from '../';
1110
import type { AlignType, ArrowPos, ArrowTypeOuter } from '../interface';
1211
import Arrow from './Arrow';
1312
import Mask from './Mask';
1413
import PopupContent from './PopupContent';
1514
import useOffsetStyle from '../hooks/useOffsetStyle';
16-
import { useEvent } from '@rc-component/util';
1715
import type { PortalProps } from '@rc-component/portal';
1816

1917
export interface MobileConfig {

src/UniqueProvider/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ import TriggerContext, {
99
import useDelay from '../hooks/useDelay';
1010
import useAlign from '../hooks/useAlign';
1111
import Popup from '../Popup';
12-
import { useEvent } from '@rc-component/util';
12+
import { isDOM, useEvent } from '@rc-component/util';
1313
import useTargetState from './useTargetState';
14-
import { isDOM } from '@rc-component/util/lib/Dom/findDOMNode';
1514
import UniqueContainer from './UniqueContainer';
1615
import { clsx } from 'clsx';
1716
import { getAlignPopupClassName } from '../util';

src/hooks/useAlign.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { isDOM } from '@rc-component/util/lib/Dom/findDOMNode';
2-
import isVisible from '@rc-component/util/lib/Dom/isVisible';
3-
import useEvent from '@rc-component/util/lib/hooks/useEvent';
4-
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
1+
import {
2+
isDOM,
3+
isVisible,
4+
useEvent,
5+
useLayoutEffect,
6+
} from '@rc-component/util';
57
import * as React from 'react';
68
import type { TriggerProps } from '..';
79
import type {

src/hooks/useWatch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
1+
import { useLayoutEffect } from '@rc-component/util';
22
import { collectScroller, getWin } from '../util';
33

44
export default function useWatch(

src/hooks/useWinClick.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { getShadowRoot } from '@rc-component/util/lib/Dom/shadow';
2-
import { warning } from '@rc-component/util/lib/warning';
1+
import { getShadowRoot, warning } from '@rc-component/util';
32
import * as React from 'react';
43
import { getWin } from '../util';
54

src/index.tsx

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@ import Portal from '@rc-component/portal';
22
import { clsx } from 'clsx';
33
import type { CSSMotionProps } from '@rc-component/motion';
44
import { useResizeObserver } from '@rc-component/resize-observer';
5-
import { getDOM, isDOM } from '@rc-component/util/lib/Dom/findDOMNode';
6-
import { getShadowRoot } from '@rc-component/util/lib/Dom/shadow';
7-
import { getNodeRef, useComposeRef } from '@rc-component/util/lib/ref';
8-
import useEvent from '@rc-component/util/lib/hooks/useEvent';
9-
import useId from '@rc-component/util/lib/hooks/useId';
10-
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
5+
import {
6+
getDOM,
7+
getNodeRef,
8+
getShadowRoot,
9+
isDOM,
10+
supportRef,
11+
useComposeRef,
12+
useControlledState,
13+
useEvent,
14+
useId,
15+
useLayoutEffect,
16+
} from '@rc-component/util';
1117
import * as React from 'react';
1218
import Popup, { type MobileConfig } from './Popup';
1319
import type { TriggerContextProps } from './context';
@@ -22,6 +28,7 @@ import type { PortalProps } from '@rc-component/portal';
2228
import type {
2329
ActionType,
2430
AlignType,
31+
AnimationType,
2532
ArrowPos,
2633
ArrowTypeOuter,
2734
BuildInPlacements,
@@ -31,12 +38,12 @@ import { getAlignPopupClassName } from './util';
3138
export type {
3239
ActionType,
3340
AlignType,
41+
AnimationType,
3442
ArrowTypeOuter as ArrowType,
3543
BuildInPlacements,
3644
};
3745

3846
import UniqueProvider, { type UniqueProviderProps } from './UniqueProvider';
39-
import { useControlledState } from '@rc-component/util';
4047
import { flushSync } from 'react-dom';
4148

4249
export { UniqueProvider };
@@ -791,13 +798,17 @@ export function generateTrigger(
791798
useResizeObserver(mergedOpen, targetEle, onTargetResize);
792799

793800
// Compose refs
794-
const mergedRef = useComposeRef(setTargetRef, getNodeRef(child));
801+
const childSupportRef = supportRef(child);
802+
const mergedRef = useComposeRef(
803+
setTargetRef,
804+
childSupportRef ? getNodeRef(child) : null,
805+
);
795806

796807
// Child Node
797808
const triggerNode = React.cloneElement(child, {
798809
...mergedChildrenProps,
799810
...passedProps,
800-
ref: mergedRef,
811+
ref: childSupportRef ? mergedRef : undefined,
801812
});
802813

803814
// Render
@@ -869,4 +880,36 @@ export function generateTrigger(
869880
return Trigger;
870881
}
871882

883+
interface MockPortalProps {
884+
open?: boolean;
885+
autoDestroy?: boolean;
886+
children: React.ReactElement<any>;
887+
getContainer?: () => HTMLElement;
888+
}
889+
890+
const MockPortal: React.FC<MockPortalProps> = ({
891+
open,
892+
autoDestroy,
893+
children,
894+
getContainer,
895+
}) => {
896+
const [visible, setVisible] = React.useState(open);
897+
898+
React.useEffect(() => {
899+
getContainer?.();
900+
});
901+
902+
React.useEffect(() => {
903+
if (open) {
904+
setVisible(true);
905+
} else if (autoDestroy) {
906+
setVisible(false);
907+
}
908+
}, [open, autoDestroy]);
909+
910+
return visible ? children : null;
911+
};
912+
913+
export const MockTrigger = generateTrigger(MockPortal);
914+
872915
export default generateTrigger(Portal);

src/mock.tsx

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1 @@
1-
import * as React from 'react';
2-
import { generateTrigger, UniqueProvider } from './index';
3-
4-
interface MockPortalProps {
5-
open?: boolean;
6-
autoDestroy?: boolean;
7-
children: React.ReactElement<any>;
8-
getContainer?: () => HTMLElement;
9-
}
10-
11-
const MockPortal: React.FC<MockPortalProps> = ({
12-
open,
13-
autoDestroy,
14-
children,
15-
getContainer,
16-
}) => {
17-
const [visible, setVisible] = React.useState(open);
18-
19-
React.useEffect(() => {
20-
getContainer?.();
21-
});
22-
23-
React.useEffect(() => {
24-
if (open) {
25-
setVisible(true);
26-
} else if (autoDestroy) {
27-
setVisible(false);
28-
}
29-
}, [open, autoDestroy]);
30-
31-
return visible ? children : null;
32-
};
33-
34-
export default generateTrigger(MockPortal);
35-
36-
export { UniqueProvider };
1+
export { MockTrigger as default, UniqueProvider } from './index';

tests/align.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { act, cleanup, fireEvent, render } from '@testing-library/react';
2-
import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook';
2+
import { spyElementPrototypes } from '@rc-component/util';
33
import React from 'react';
44
import type { TriggerProps, TriggerRef } from '../src';
55
import Trigger from '../src';

tests/arrow.test.jsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
/* eslint-disable max-classes-per-file */
22

33
import { act, cleanup, render } from '@testing-library/react';
4-
import {
5-
spyElementPrototype,
6-
spyElementPrototypes,
7-
} from '@rc-component/util/lib/test/domHook';
4+
import { spyElementPrototype, spyElementPrototypes } from '@rc-component/util';
85
import Trigger from '../src';
96

107
describe('Trigger.Arrow', () => {

0 commit comments

Comments
 (0)